<?php
/**
 * Remove one configuration from a project folder.
 * POST: config_id, folder_id, admin_base_path (optional)
 */
require __DIR__ . '/config.php';
require_once __DIR__ . '/admin_config_helpers.php';

header_remove('X-Frame-Options');
header('Content-Security-Policy: frame-ancestors https://admin.shopify.com https://*.myshopify.com');

if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    header('Location: folders.php');
    exit;
}

$config_id = (int)($_POST['config_id'] ?? 0);
$folder_id = (int)($_POST['folder_id'] ?? 0);
$admin_base_path = admin_normalize_web_path(
    (string)($_POST['admin_base_path'] ?? dirname($_SERVER['SCRIPT_NAME'] ?? ''))
);

if ($config_id > 0 && $folder_id > 0) {
    admin_remove_configuration($pdo, $config_id, $folder_id);
}

header('Location: ' . admin_page_url('folder_detail.php', ['id' => $folder_id], $admin_base_path));
exit;
