<?php
session_start();

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

require_once '../db/config.php';

if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header('Location: users.php');
    exit();
}

$user_id = $_GET['id'];

$pdo = db();
$stmt = $pdo->prepare('DELETE FROM users WHERE id = ?');
if ($stmt->execute([$user_id])) {
    header('Location: users.php?deleted=true');
    exit;
} else {
    header('Location: users.php?error=true');
    exit;
}
