<?php use function App\Core\e; $section = 'modlar'; ?>
<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>Modlar</h1><p class="muted">Inceleme, onay, ret, yayindan kaldirma ve one cikarma.</p></div></div>
        <form class="zpanel-filters" method="get">
            <input name="q" value="<?= e($_GET['q'] ?? '') ?>" placeholder="Mod ara">
            <select name="category_id"><option value="">Tum kategoriler</option><?php foreach (($categories ?? []) as $category): ?><option value="<?= e($category['id'] ?? '') ?>" <?= (string) ($_GET['category_id'] ?? '') === (string) ($category['id'] ?? '') ? 'selected' : '' ?>><?= e($category['name'] ?? '') ?></option><?php endforeach; ?></select>
            <select name="status"><option value="">Aktif kayitlar</option><?php foreach (['pending','draft','published','rejected','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>Mod</th><th>Creator</th><th>Kategori</th><th>Status</th><th>Erisim</th><th>Risk</th><th>Aksiyon</th></tr></thead><tbody>
            <?php foreach (($mods ?? []) as $mod): ?>
                <tr>
                    <td><strong><?= e($mod['title'] ?? '-') ?></strong><span class="muted block"><?= e($mod['slug'] ?? '') ?></span></td>
                    <td><?= e($mod['author_name'] ?? $mod['creator_username'] ?? '-') ?></td>
                    <td><?= e($mod['category_name'] ?? '-') ?></td>
                    <td><span class="status-pill status-<?= e($mod['status'] ?? '') ?>"><?= e($mod['status'] ?? '-') ?></span></td>
                    <td><?= !empty($mod['is_premium']) ? 'premium' : 'free' ?></td>
                    <td><span class="risk-score"><?= e((string) ($mod['external_link_risk_score'] ?? 0)) ?></span></td>
                    <td class="action-row">
                        <?php foreach ([['/api/zpanel/mod/approve','Onayla'],['/api/zpanel/mod/reject','Reddet'],['/api/zpanel/mod/unpublish','Yayindan kaldir'],['/api/zpanel/mod/delete','Sil'],[!empty($mod['featured']) ? '/api/zpanel/mod/unfeature' : '/api/zpanel/mod/feature', !empty($mod['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($mod['id'] ?? '') ?>"><button type="submit"><?= e($action[1]) ?></button></form>
                        <?php endforeach; ?>
                    </td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($mods)): ?><tr><td colspan="7">Mod bulunamadi.</td></tr><?php endif; ?>
            </tbody></table></div></section>
    </section>
</div>
