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

$section = 'artist';
$artist = $artist ?? null;
$status = (string) ($artist['status'] ?? (!empty($artist['verified']) ? 'approved' : 'missing'));
?>
<div class="panel creator-shell">
    <?php require BASE_PATH . '/app/Views/partials/studio-sidebar.php'; ?>
    <section class="panel-body artist-connect-page">
        <header class="studio-section-head">
            <div>
                <p class="eyebrow">Zalorox Artist Connect</p>
                <h1>Sanatci Profili</h1>
                <p>Muzik yuklemek icin onayli bir Artist Connect profili gerekir.</p>
            </div>
            <a class="pill" href="<?= e(url('/studyo/muzik-yukle')) ?>">Muzik Yukle</a>
        </header>

        <?php if (!empty($loadError)): ?><div class="dev-alert"><?= e($loadError) ?></div><?php endif; ?>

        <div class="artist-connect-grid">
            <section class="studio-card artist-status-card">
                <div class="studio-card-head">
                    <div>
                        <h2>Basvuru Durumu</h2>
                        <p>ZPanel onayindan sonra muzik yukleme acilir.</p>
                    </div>
                    <span class="status-pill status-<?= e($status) ?>"><?= e($status === 'missing' ? 'profil yok' : $status) ?></span>
                </div>
                <?php if ($artist): ?>
                    <div class="artist-preview-mini">
                        <?php if (!empty($artist['cover_image'])): ?><img class="artist-preview-cover" src="<?= e($artist['cover_image']) ?>" alt=""><?php endif; ?>
                        <?php if (!empty($artist['avatar'])): ?><img class="artist-preview-avatar" src="<?= e($artist['avatar']) ?>" alt=""><?php endif; ?>
                        <strong><?= e($artist['artist_name'] ?? '') ?></strong>
                        <span>@<?= e($artist['slug'] ?? '') ?></span>
                        <p><?= e($artist['bio'] ?? '') ?></p>
                    </div>
                    <?php if ($status === 'rejected'): ?><p class="dev-alert"><?= e($artist['rejection_reason'] ?? 'Basvuru reddedildi.') ?></p><?php endif; ?>
                <?php else: ?>
                    <div class="empty-state small"><strong>Artist profili yok</strong><p>Asagidaki form ile ilk basvurunu olustur.</p></div>
                <?php endif; ?>
            </section>

            <form class="studio-card artist-connect-form" action="<?= e(url('/api/studio/artist/apply')) ?>" method="post" data-studio-account-form>
                <input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>">
                <div class="studio-card-head"><div><h2>Basvuru Formu</h2><p>Hak sahipligi onayi zorunludur.</p></div></div>
                <div class="form-grid">
                    <label>Sanatci adi<input name="artist_name" required maxlength="160" value="<?= e($artist['artist_name'] ?? '') ?>"><span class="field-error" data-error-for="artist_name"></span></label>
                    <label>Slug<input name="slug" required maxlength="180" value="<?= e($artist['slug'] ?? '') ?>"><span class="field-error" data-error-for="slug"></span></label>
                </div>
                <label>Bio<textarea name="bio" rows="6" required><?= e($artist['bio'] ?? '') ?></textarea><span class="field-error" data-error-for="bio"></span></label>
                <div class="form-grid">
                    <label>Avatar yolu<input name="avatar" maxlength="255" value="<?= e($artist['avatar'] ?? '') ?>" placeholder="/uploads/artists/avatar.png"></label>
                    <label>Kapak yolu<input name="cover_image" maxlength="255" value="<?= e($artist['cover_image'] ?? '') ?>" placeholder="/uploads/artists/cover.jpg"></label>
                </div>
                <div class="form-grid">
                    <label>YouTube<input type="url" name="youtube_url" value="<?= e($artist['youtube_url'] ?? '') ?>"></label>
                    <label>Spotify<input type="url" name="spotify_url" value="<?= e($artist['spotify_url'] ?? '') ?>"></label>
                    <label>Apple Music<input type="url" name="apple_music_url" value="<?= e($artist['apple_music_url'] ?? '') ?>"></label>
                    <label>Instagram<input type="url" name="instagram_url" value="<?= e($artist['instagram_url'] ?? '') ?>"></label>
                </div>
                <label class="check-row artist-rights-check">
                    <input type="checkbox" name="rights_confirmed" value="1" <?= !empty($artist['rights_confirmed_at']) ? 'checked' : '' ?> required>
                    Yukledigim muziklerin bana ait oldugunu veya gerekli yayin haklarina sahip oldugumu onayliyorum.
                </label>
                <button class="pill primary" type="submit">Basvuruyu Gonder</button>
            </form>
        </div>
    </section>
</div>
