<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: DELETE");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

require_once '../db.php';

$id = isset($_GET['id']) ? intval($_GET['id']) : 0;

if ($id > 0) {
    // Optional: Check if ID exists first
    $stmt = $conn->prepare("DELETE FROM contact_messages WHERE id = ?");
    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        http_response_code(200);
        echo json_encode(["message" => "Contact message deleted successfully."]);
    } else {
        http_response_code(503);
        echo json_encode(["message" => "Unable to delete contact message."]);
    }
    $stmt->close();
} else {
    http_response_code(400);
    echo json_encode(["message" => "Invalid ID."]);
}

$conn->close();
?>
