<?php
 
 
 

$perfName = mb_ucfirst($performer['name']);
$vc = (int)($performer['video_count'] ?? 0);
$totalViews = (int)($performer['total_views'] ?? 0);

 
$socialData = [];
if (!empty($performer['social_links'])) {
    $socialData = json_decode($performer['social_links'], true) ?: [];
}
$linkUrl = $socialData['link'] ?? '';
?>

<div class="performer-profile">
    <div class="performer-profile__photo-wrap">
        <?php if (!empty($performer['photo'])): ?>
            <?php $photoUrl = str_starts_with($performer['photo'], 'http') ? $performer['photo'] : '/uploads/performers/' . $performer['photo']; ?>
            <img src="<?php echo htmlspecialchars($photoUrl); ?>" alt="<?php echo htmlspecialchars($perfName); ?>" class="performer-profile__photo">
        <?php elseif (!empty($performer['_fallback_photo'])): ?>
            <img src="<?php echo htmlspecialchars($performer['_fallback_photo']); ?>" alt="<?php echo htmlspecialchars($perfName); ?>" class="performer-profile__photo">
        <?php else: ?>
            <div class="performer-profile__photo performer-profile__photo--placeholder">
                <i class="fa-solid fa-user"></i>
            </div>
        <?php endif; ?>
    </div>

    <div class="performer-profile__info">
        <h1 class="performer-profile__name"><?php echo htmlspecialchars($perfName); ?></h1>

        <?php if (!empty($performer['bio'])): ?>
            <p class="performer-profile__bio"><?php echo nl2br(htmlspecialchars($performer['bio'])); ?></p>
        <?php endif; ?>

        <div class="performer-profile__stats">
            <div class="performer-profile__stat">
                <i class="fa-solid fa-film"></i>
                <span><?php echo $vc !== 1 ? __('video_count_plural', [':count' => Format::number($vc)]) : __('video_count', [':count' => Format::number($vc)]); ?></span>
            </div>
            <div class="performer-profile__stat">
                <i class="fa-solid fa-eye"></i>
                <span><?php echo Format::number($totalViews); ?> <?php echo __('views'); ?></span>
            </div>
            <?php if (!empty($performer['country'])): ?>
            <div class="performer-profile__stat">
                <i class="fa-solid fa-globe"></i>
                <span><?php echo htmlspecialchars($performer['country']); ?></span>
            </div>
            <?php endif; ?>
        </div>

        <?php if ($linkUrl !== ''): ?>
        <div class="performer-profile__links">
            <a href="<?php echo htmlspecialchars($linkUrl); ?>" target="_blank" rel="noopener noreferrer" class="performer-profile__link">
                <i class="fa-solid fa-arrow-up-right-from-square"></i>
                <?php echo htmlspecialchars(parse_url($linkUrl, PHP_URL_HOST) ?: $linkUrl); ?>
            </a>
        </div>
        <?php endif; ?>
    </div>
</div>

<?php echo simplySortTabs($sort ?? 'newest'); ?>

<?php if (!empty($videos)) Ads::zone('performer_top'); ?>
<div class="video-grid">
    <?php foreach ($videos as $video): ?>
        <?php echo simplyVideoCard($video); ?>
        <?php Ads::betweenGrid('performer_between', 10); ?>
    <?php endforeach; ?>
</div>
<?php if (!empty($videos)) Ads::zone('performer_bottom'); ?>

<?php if (empty($videos)): ?>
    <div class="empty-state">
        <div class="empty-state__icon"><i class="fa-light fa-video-slash"></i></div>
        <p class="empty-state__text"><?php echo __('no_videos_pornstar'); ?></p>
    </div>
<?php endif; ?>

<?php echo simplyPagination($pagination); ?>
