<?php
session_start();
header('Content-Type: application/json');

require_once __DIR__ . '/../../classes/DB.php';

/* ADMIN CHECK */
if (!isset($_SESSION['is_admin']) || $_SESSION['is_admin'] !== true) {
    echo json_encode(["ok" => false, "error" => "Not admin"]);
    exit;
}

$imageId = $_POST['image_id'] ?? null;
$disabled = $_POST['disabled'] ?? null;

if (!$imageId || $disabled === null) {
    echo json_encode(["ok" => false, "error" => "Missing fields"]);
    exit;
}

$disabled = (int)$disabled; // 1 = disable, 0 = enable

$db = DB::get();

$db->prepare("UPDATE images SET is_disabled = ? WHERE id = ?")
   ->execute([$disabled, $imageId]);

echo json_encode([
    "ok" => true,
    "image_id" => $imageId,
    "disabled" => $disabled
]);