<?php
session_start();
if (!isset($_SESSION['id_admin']) || ($_SESSION['jenis_admin'] ?? '') != 'utama') {
    die("Akses ditolak! Hanya admin utama boleh padam admin.");
}

include 'includes/config.php';

$id = $_GET['id'] ?? 0;
if (!$id) {
    die("ID admin tidak sah.");
}

// Jangan padam admin utama
$stmt = mysqli_prepare($conn, "SELECT jenis_admin FROM admin WHERE id = ?");
mysqli_stmt_bind_param($stmt, 'i', $id);
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
$admin = mysqli_fetch_assoc($result);

if (!$admin) {
    die("Admin tidak ditemui.");
}
if ($admin['jenis_admin'] == 'utama') {
    die("Admin utama tidak boleh dipadam.");
}

// Padam admin
$stmt = mysqli_prepare($conn, "DELETE FROM admin WHERE id = ?");
mysqli_stmt_bind_param($stmt, 'i', $id);
if (mysqli_stmt_execute($stmt)) {
    header('Location: senarai_admin.php');
    exit;
} else {
    die("Gagal memadam admin.");
}
