<?php
require_once __DIR__ . "/../../app/config/auth.php";
require_login();
require_once __DIR__ . "/../../app/config/koneksi.php";

// Validasi ID
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header("Location: kritiksaran_admin.php");
    exit;
}

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

// Hapus data
$sql = $koneksi->prepare("DELETE FROM kritik_saran WHERE id = ?");
$sql->bind_param("i", $id);

if ($sql->execute()) {
    $pesan = "Pesan berhasil dihapus";
} else {
    $pesan = "Gagal menghapus data";
}

// Kembali otomatis ke halaman sebelumnya
$back = $_SERVER['HTTP_REFERER'] ?? "kritiksaran_admin.php";
header("Location: $back?status=" . urlencode($pesan));
exit;
