<?php
require_once '../includes/include_all.inc.php';
require_once '../includes/debug_mode.php';

header('Content-Type: application/json');

$mode = $_POST['mode'] ?? '';

if ($mode !== 'on' && $mode !== 'off') {
    echo json_encode(['success' => false, 'message' => 'Invalid mode']);
    exit();
}

$enabled = ($mode === 'on');

if (setDebugMode($enabled)) {
    echo json_encode(['success' => true, 'mode' => $mode]);
} else {
    echo json_encode(['success' => false, 'message' => 'Failed to set debug mode']);
}
?>