<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json");

$dataFile = "data.json";

if (!isset($_GET['id'])) {
    echo json_encode(["error" => "ID tidak diberikan"]);
    exit;
}

$id = (int) $_GET['id'];

$data = file_exists($dataFile) ? json_decode(file_get_contents($dataFile), true) : [];

if (!isset($data[$id])) {
    echo json_encode(["error" => "ID tidak valid"]);
    exit;
}

array_splice($data, $id, 1);
file_put_contents($dataFile, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));

echo json_encode(["message" => "Informasi berhasil dihapus"]);
?>
