<?php
session_start();
require_once "../config/db.php";

// Hanya superadmin boleh hapus user
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'superadmin') {
    header("Location: ../pages/users.php?error=unauthorized");
    exit;
}

$id = $_GET['id'];

// Tidak boleh hapus akun sendiri
if ($id == $_SESSION['user']['id']) {
    header("Location: ../pages/users.php?error=cannot_delete_self");
    exit;
}

$stmt = $pdo->prepare("DELETE FROM users WHERE id = :id");
$stmt->execute([':id' => $id]);

header("Location: ../pages/users.php?delete=1");
exit;
