<?php

header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Content-Type");
header("Access-Control-Allow-Methods: GET, OPTIONS");
header("Content-Type: application/json");

if ($_SERVER["REQUEST_METHOD"] === "OPTIONS") {
    exit;
}

require "../../config/database.php";
require "../../helpers/response.php";

$id = isset($_GET["id"]) ? (int) $_GET["id"] : 0;

if ($id <= 0) {
    response(false, "ID SPPG tidak valid", null);
}

$sql = "
    SELECT 
        id,
        nama,
        provinsi,
        kabupaten,
        alamat,
        total_dana,
        jumlah_siswa,
        status,
        created_at
    FROM sppg
    WHERE id = ?
    LIMIT 1
";

$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $id);
$stmt->execute();

$result = $stmt->get_result();

if ($result->num_rows === 0) {
    response(false, "Data SPPG tidak ditemukan", null);
}

$data = $result->fetch_assoc();

response(true, "Detail SPPG berhasil diambil", $data);

?>