<?php use function App\Core\e; $section = 'muzikler'; ?>
<div class="panel zpanel zpanel-app">
    <?php require BASE_PATH . '/app/Views/zpanel/_sidebar.php'; ?>
    <section class="panel-body zpanel-main" data-zpanel-page data-csrf="<?= e($csrfToken ?? '') ?>">
        <div class="zpanel-head"><div><p class="eyebrow">ZPanel</p><h1>Muzikler</h1><p class="muted">Muzik inceleme, onay, ret ve one cikarma akisi.</p></div></div>
        <form class="zpanel-filters" method="get">
            <input name="q" value="<?= e($_GET['q'] ?? '') ?>" placeholder="Muzik, sanatci veya slug ara">
            <select name="genre_slug"><option value="">Tum turler</option><?php foreach (($genres ?? []) as $genre): ?><option value="<?= e($genre['slug'] ?? '') ?>" <?= ($_GET['genre_slug'] ?? '') === ($genre['slug'] ?? '') ? 'selected' : '' ?>><?= e($genre['name'] ?? '') ?></option><?php endforeach; ?></select>
            <select name="status"><option value="">Aktif kayitlar</option><?php foreach (['pending','draft','published','pending_review','rejected','blocked','archived'] as $status): ?><option value="<?= e($status) ?>" <?= ($_GET['status'] ?? '') === $status ? 'selected' : '' ?>><?= e($status) ?></option><?php endforeach; ?></select>
            <select name="premium"><option value="">Premium/free</option><option value="premium" <?= ($_GET['premium'] ?? '') === 'premium' ? 'selected' : '' ?>>premium</option><option value="free" <?= ($_GET['premium'] ?? '') === 'free' ? 'selected' : '' ?>>free</option></select>
            <button class="pill primary">Filtrele</button>
        </form>
        <section class="zpanel-card"><div class="table-scroll"><table class="zpanel-table">
            <thead><tr><th>Muzik</th><th>Sanatci</th><th>Tur</th><th>Status</th><th>Erisim</th><th>Dinlenme</th><th>Aksiyon</th></tr></thead><tbody>
            <?php foreach (($tracks ?? []) as $track): ?>
                <tr>
                    <td><strong><?= e($track['title'] ?? '-') ?></strong><span class="muted block"><?= e($track['slug'] ?? '') ?></span></td>
                    <td><?= e($track['artist_name'] ?? '-') ?></td>
                    <td><?= e($track['genre_names'] ?? $track['category_name'] ?? '-') ?></td>
                    <td><span class="status-pill status-<?= e($track['status'] ?? '') ?>"><?= e($track['status'] ?? '-') ?></span></td>
                    <td><?= !empty($track['is_premium']) ? 'premium' : 'free' ?></td>
                    <td><?= e((string) ($track['play_count'] ?? 0)) ?></td>
                    <td class="action-row">
                        <?php foreach ([['/api/zpanel/music/approve','Onayla'],['/api/zpanel/music/reject','Reddet'],['/api/zpanel/music/unpublish','Yayindan kaldir'],['/api/zpanel/music/copyright-review','Telif incele'],['/api/zpanel/music/delete','Sil'],[!empty($track['featured']) ? '/api/zpanel/music/unfeature' : '/api/zpanel/music/feature', !empty($track['featured']) ? 'One cikarma' : 'One cikar']] as $action): ?>
                            <form data-zpanel-form action="<?= e($action[0]) ?>" method="post" data-confirm="<?= e($action[1]) ?>?"><input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>"><input type="hidden" name="id" value="<?= e($track['id'] ?? '') ?>"><button type="submit"><?= e($action[1]) ?></button></form>
                        <?php endforeach; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($tracks)): ?><tr><td colspan="7">Muzik bulunamadi.</td></tr><?php endif; ?>
            </tbody></table></div></section>
    </section>
</div>
