<?php
require __DIR__ . '/_auth.php';
require_admin();

if (!verify_csrf_token((string) (isset($_GET['csrf_token']) ? $_GET['csrf_token'] : ''))) {
    admin_redirect('products.php');
}

$pdo = db();
$id = isset($_GET['id']) ? trim((string) $_GET['id']) : '';

if ($pdo && $id !== '') {
    $stmt = $pdo->prepare('DELETE FROM products WHERE id = ? LIMIT 1');
    $stmt->execute(array($id));
}

admin_redirect('products.php');
