<?php
use function App\Core\{e, url};

$artist = $artist ?? [];
$tracks = $tracks ?? [];
$name = (string) (($artist['artist_name'] ?? '') ?: 'Sanatci');
$avatar = (string) ($artist['avatar'] ?? '');
$cover = (string) ($artist['cover_image'] ?? '');
$bio = (string) ($artist['bio'] ?? '');
$links = array_filter([
    'Spotify' => (string) ($artist['spotify_url'] ?? ''),
    'YouTube' => (string) ($artist['youtube_url'] ?? ''),
    'Apple Music' => (string) ($artist['apple_music_url'] ?? ''),
], static fn (string $value): bool => filter_var($value, FILTER_VALIDATE_URL) !== false);
?>
<section class="artist-hero">
    <div class="container">
        <div class="artist-cover" <?= $cover !== '' ? 'style="background-image: linear-gradient(180deg, rgba(12,12,12,.08), rgba(12,12,12,.88)), url(' . e(url($cover)) . ')"' : '' ?>>
            <div class="artist-identity">
                <?php if ($avatar !== ''): ?>
                    <img src="<?= e(url($avatar)) ?>" alt="<?= e($name) ?>">
                <?php else: ?>
                    <span class="artist-avatar-fallback"><?= e(strtoupper(substr($name, 0, 1) ?: 'Z')) ?></span>
                <?php endif; ?>
                <div>
                    <p class="eyebrow">Sanatci<?= !empty($artist['verified']) ? ' / Verified' : '' ?></p>
                    <h1><?= e($name) ?><?= !empty($artist['verified']) ? ' *' : '' ?></h1>
                    <p><?= e($bio !== '' ? $bio : 'Bu sanatci profili icin bio daha sonra eklenecek.') ?></p>
                    <div class="music-detail-stats">
                        <span><?= number_format((int) ($artist['track_count'] ?? 0), 0, ',', '.') ?> sarki</span>
                        <span><?= number_format((int) ($artist['play_count'] ?? 0), 0, ',', '.') ?> dinlenme</span>
                        <span><?= number_format((int) ($artist['like_count'] ?? 0), 0, ',', '.') ?> begeni</span>
                    </div>
                    <?php if ($links !== []): ?>
                        <div class="artist-links">
                            <?php foreach ($links as $label => $href): ?>
                                <a class="pill" href="<?= e($href) ?>" target="_blank" rel="noopener"><?= e($label) ?></a>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</section>

<section class="container section music-section">
    <div class="section-head">
        <div>
            <p class="eyebrow">Diskografi</p>
            <h2>Sarkilar</h2>
        </div>
        <a class="section-link" href="<?= url('/music/arama?q=' . rawurlencode($name)) ?>">Ara</a>
    </div>

    <?php if ($tracks === []): ?>
        <div class="empty-state"><strong>Sarki yok.</strong><p>Bu sanatciya bagli yayinlanmis sarki bulunmuyor.</p></div>
    <?php else: ?>
        <div class="grid music-grid">
            <?php foreach ($tracks as $track): ?>
                <?php require BASE_PATH . '/app/Views/partials/music-card.php'; ?>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
</section>
