<?php
require_once '../init.php';

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    Helper::redirect('index.php');
}

$productId = intval($_POST['id'] ?? 0);

if (!$productId) {
    Helper::redirect('index.php');
}

$prod = $product->get($productId, $_SESSION['user_id']);

if (!$prod) {
    Helper::redirect('index.php');
}

$result = $product->delete($productId, $_SESSION['user_id']);

if ($result) {
    $_SESSION['success'] = 'Produk berhasil dihapus';
} else {
    $_SESSION['error'] = 'Gagal menghapus produk';
}

Helper::redirect('index.php');
