<?php
session_start();
require '../includes/db.php';

// 🔒 OPTIONAL ADMIN CHECK
// if (!isset($_SESSION['admin'])) {
//     die("Access denied");
// }

if (isset($_GET['id'])) {

    $id = intval($_GET['id']);

    // OPTIONAL: check if exists
    $check = $conn->prepare("SELECT id FROM withdrawals WHERE id=?");
    $check->bind_param("i", $id);
    $check->execute();
    $result = $check->get_result();

    if ($result->num_rows == 0) {
        die("Withdrawal not found");
    }

    // DELETE
    $stmt = $conn->prepare("DELETE FROM withdrawals WHERE id=?");
    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        header("Location: withdrawals.php?msg=deleted");
        exit;
    } else {
        echo "Error deleting record";
    }

} else {
    header("Location: withdrawals.php");
    exit;
}