<?php
 
 
 
 

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

$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($channel['logo'])): ?>
            <?php $logoUrl = str_starts_with($channel['logo'], 'http') ? $channel['logo'] : '/uploads/channels/' . $channel['logo']; ?>
            <img src="<?php echo htmlspecialchars($logoUrl); ?>" alt="<?php echo htmlspecialchars($channelName); ?>" class="performer-profile__photo">
        <?php else: ?>
            <div class="performer-profile__photo performer-profile__photo--placeholder">
                <i class="fa-solid fa-clapperboard"></i>
            </div>
        <?php endif; ?>
    </div>

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

        <?php if (!empty($channel['description'])): ?>
            <p class="performer-profile__bio"><?php echo nl2br(htmlspecialchars($channel['description'])); ?></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($channel['country'])): ?>
            <div class="performer-profile__stat">
                <i class="fa-solid fa-globe"></i>
                <span><?php echo htmlspecialchars($channel['country']); ?></span>
            </div>
            <?php endif; ?>
        </div>

        <?php if (!empty($channel['website'])): ?>
        <div class="performer-profile__links">
            <a href="<?php echo htmlspecialchars($channel['website']); ?>" 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($channel['website'], PHP_URL_HOST) ?: $channel['website']); ?>
            </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>
