<?php
 
 
 
 

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

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

$albumTabs = [
    'newest'      => __('sort_newest'),
    'popular'     => __('sort_most_viewed'),
    'most_images' => __('sort_most_images'),
];
$albumTabs = HookSystem::applyFilter('front.album_sort_tabs', $albumTabs);
?>

<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" loading="lazy">
        <?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-images"></i>
                <span><?php echo Format::number($ac) . ' ' . __('albums'); ?></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 hentaiAlbumBrowseBar(Album::activeType()); ?>

<div class="album-body">
    <?php echo hentaiAlbumSidebar(Album::activeType()); ?>
    <main class="album-main">
        <div class="section-title-row">
            <h2 class="section-title" style="text-transform:uppercase;"><?php echo __('albums'); ?></h2>
            <?php if (!empty($albums)): ?>
                <?php echo hentaiSortDropdown($sort ?? 'newest', '', $albumTabs); ?>
            <?php endif; ?>
        </div>
        <?php if (!empty($albums)): ?>
        <?php Ads::zone('album_listing_top'); ?>
        <div class="album-grid<?php echo hentaiAlbumGridClass(); ?>">
            <?php foreach ($albums as $album): ?>
                <?php echo hentaiAlbumCard($album); ?>
                <?php Ads::betweenGrid('album_listing_between', 10); ?>
            <?php endforeach; ?>
        </div>
        <?php Ads::zone('album_listing_bottom'); ?>
        <?php else: ?>
        <div class="empty-state">
            <div class="empty-state__icon"><i class="fa-light fa-images"></i></div>
            <p class="empty-state__text"><?php echo __('no_albums'); ?></p>
        </div>
        <?php endif; ?>
        <?php echo hentaiPagination($pagination); ?>
    </main>
</div>
