<?php
session_start();
require_once 'config.php';

// Cek login
if (!isset($_SESSION['loggedin']) || $_SESSION['loggedin'] !== true) {
    header('Location: login.php');
    exit;
}

// Ambil semua admin
$stmt = $db->prepare("SELECT * FROM admin_users ORDER BY id DESC");
$stmt->execute();
$admins = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Kelola Admin - SOLOPOOLS</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css">
</head>
<body>
    <?php include 'navbar.php'; ?>

    
    <div class="container">
        <h2>Kelola Admin</h2>
        <a href="add_admin.php" class="btn btn-primary mb-3">+ Tambah Admin</a>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Username</th>
                    <th>Dibuat Pada</th>
                    <th>Aksi</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($admins as $admin): ?>
                    <tr>
                        <td><?= $admin['id'] ?></td>
                        <td><?= htmlspecialchars($admin['username']) ?></td>
                        <td><?= $admin['created_at'] ?></td>
                        <td>
                            <a href="edit_admin.php?id=<?= $admin['id'] ?>" class="btn btn-warning btn-sm">Edit</a>
                            <a href="delete_admin.php?id=<?= $admin['id'] ?>" class="btn btn-danger btn-sm" onclick="return confirm('Yakin ingin hapus admin ini?')">Hapus</a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <a href="index.php" class="btn btn-secondary">Kembali ke Dashboard</a>
    </div>
</body>
</html>
