<?php
require 'config.php';
if (!is_admin()) {
    die("Akses ditolak!");
}

if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];

    // pastikan bukan admin yang dihapus
    $stmt = $pdo->prepare("SELECT role FROM users WHERE id = ?");
    $stmt->execute([$id]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($user && $user['role'] !== 'admin') {
        $stmt = $pdo->prepare("DELETE FROM users WHERE id = ?");
        $stmt->execute([$id]);
    }
}

header("Location: index.php");
exit;
