<?php
session_start();
require_once __DIR__ . '/../../db/config.php';

if (!isset($_SESSION["user_id"]) || $_SESSION["role"] !== 'admin') {
    header("Location: ../../login.php");
    exit();
}

$id = $_GET['id'] ?? null;
if ($id) {
    try {
        $stmt = db()->prepare("DELETE FROM products WHERE id = ?");
        $stmt->execute([$id]);
    } catch (PDOException $e) {
        // Optional: handle error, e.g., log it or show a message
    }
}

header("Location: index.php");
exit();
