<?php
$pageName  = "Deleting";
include($_SERVER['DOCUMENT_ROOT'] . "/admin/layout/header.php");

$id = $_GET['id'] ?? '';

if (empty($id)) {
    header("Location: ./cards.php");
    exit();
}

// DELETE directly by seria_key
$sql = "DELETE FROM card WHERE seria_key = :seria_key";
$stmt = $conn->prepare($sql);
$stmt->execute([':seria_key' => $id]);

if ($stmt->rowCount() > 0) {
    $msg1 = "
        <div class='alert alert-warning'>
            <script type='text/javascript'>
                function Redirect() {
                    window.location='./cards.php';
                }
                setTimeout('Redirect()', 3000);
            </script>
            <center><img src='../assets/images/loading.gif' width='180px' /></center>
            <center><strong style='color:black;'>Deleted! Please wait while we redirect you...</strong></center>
        </div>
    ";
} else {
    $msg1 = "<div class='alert alert-danger'>Card not found or already deleted.</div>";
}
?>

<div class="row">
    <?php if (isset($msg1)) echo $msg1; ?>
</div>