<?php use function App\Core\e; $section = 'kullanicilar'; ?>
<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>Kullanicilar</h1><p class="muted">Role ve durum yonetimi, ban/pasif akisi ve guvenli admin onaylari.</p></div></div>
        <form class="zpanel-filters" method="get">
            <input name="q" value="<?= e($_GET['q'] ?? '') ?>" placeholder="Kullanici, email veya ad ara">
            <select name="role"><option value="">Tum roller</option><?php foreach (['user','creator','moderator','admin'] as $role): ?><option value="<?= e($role) ?>" <?= ($_GET['role'] ?? '') === $role ? 'selected' : '' ?>><?= e($role) ?></option><?php endforeach; ?></select>
            <select name="status"><option value="">Tum durumlar</option><?php foreach (['active','pending','suspended','deleted'] as $status): ?><option value="<?= e($status) ?>" <?= ($_GET['status'] ?? '') === $status ? 'selected' : '' ?>><?= e($status) ?></option><?php endforeach; ?></select>
            <button class="pill primary">Filtrele</button>
        </form>
        <section class="zpanel-card">
            <div class="table-scroll"><table class="zpanel-table">
                <thead><tr><th>Kullanici</th><th>Email</th><th>Role</th><th>Status</th><th>Icerik</th><th>Son giris</th><th>Aksiyon</th></tr></thead>
                <tbody>
                <?php foreach (($users ?? []) as $user): ?>
                    <tr>
                        <td><strong><?= e($user['display_name'] ?? $user['username'] ?? '-') ?></strong><span class="muted block">@<?= e($user['username'] ?? '-') ?></span></td>
                        <td><?= e($user['email'] ?? '-') ?></td>
                        <td><span class="status-pill"><?= e($user['role'] ?? '-') ?></span></td>
                        <td><span class="status-pill status-<?= e($user['status'] ?? '') ?>"><?= e($user['status'] ?? '-') ?></span></td>
                        <td><?= e((string) ($user['mod_count'] ?? 0)) ?> mod / <?= e((string) ($user['music_count'] ?? 0)) ?> muzik</td>
                        <td><?= e($user['last_login_at'] ?? '-') ?></td>
                        <td>
                            <form class="inline-admin-form" data-zpanel-form action="/api/zpanel/users/update-role" method="post" data-confirm="<?= ($user['role'] ?? '') === 'admin' ? 'Admin rolunu degistirmek istiyor musun?' : 'Kullanici rolunu guncelle?' ?>">
                                <input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>"><input type="hidden" name="id" value="<?= e($user['id'] ?? '') ?>">
                                <select name="role"><?php foreach (['user','creator','moderator','admin'] as $role): ?><option value="<?= e($role) ?>" <?= ($user['role'] ?? '') === $role ? 'selected' : '' ?>><?= e($role) ?></option><?php endforeach; ?></select>
                                <button type="submit">Rol</button>
                            </form>
                            <form class="inline-admin-form" data-zpanel-form action="/api/zpanel/users/update-status" method="post" data-confirm="Kullanici durumunu guncelle?">
                                <input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>"><input type="hidden" name="id" value="<?= e($user['id'] ?? '') ?>">
                                <select name="status"><?php foreach (['active','pending','suspended','deleted'] as $status): ?><option value="<?= e($status) ?>" <?= ($user['status'] ?? '') === $status ? 'selected' : '' ?>><?= e($status) ?></option><?php endforeach; ?></select>
                                <button type="submit">Durum</button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
                <?php if (empty($users)): ?><tr><td colspan="7">Kullanici bulunamadi.</td></tr><?php endif; ?>
                </tbody>
            </table></div>
        </section>
    </section>
</div>
