<?php
require __DIR__ . '/../../app/bootstrap.php';
require __DIR__ . '/../../app/database.php';
require_login();

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: /admin/template-pack/list.php?tab=modules');
    exit;
}

require_csrf();

$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
$status = 'error';

if ($id > 0) {
    try {
        if (delete_module($id)) {
            $status = 'success';
        }
    } catch (Exception $e) {
        $status = 'error';
    }
}

header('Location: /admin/component/list.php?delete_status=' . $status);
exit;
