<?php
header("Content-Type: application/json");
require("../includes/config.php");

$data = json_decode(file_get_contents("php://input"), true);

$id     = $data['id'] ?? 0;
$status = $data['status'] ?? 0;

if (!$id) {
    echo json_encode(["status"=>"error","message"=>"Invalid chapter"]);
    exit;
}

$stmt = $pdo->prepare("
    UPDATE chapters 
    SET status = :status 
    WHERE id = :id
");

$stmt->execute([
    ":status" => $status,
    ":id" => $id
]);

echo json_encode(["status"=>"success","message"=>"Status updated"]);
?>