<?php
 
 
 

$channelName = mb_ucfirst($channel['name']);
$vc = (int)($channel['video_count'] ?? 0);
$totalViews = (int)($channel['total_views'] ?? 0);
?>

<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 elseif (!empty($channel['_fallback_logo'])): ?>
            <img src="<?php echo htmlspecialchars($channel['_fallback_logo']); ?>" 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-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($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 simplySortTabs($sort ?? 'newest'); ?>

<div class="video-grid">
    <?php foreach ($videos as $video): ?>
        <?php echo simplyVideoCard($video); ?>
    <?php endforeach; ?>
</div>

<?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_channel'); ?></p>
    </div>
<?php endif; ?>

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