<?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";

$sql = "
    SELECT
        id,
        user_id,
        username,
        role,
        aksi,
        target,
        keterangan,
        ip_address,
        created_at
    FROM audit_log
    ORDER BY id DESC
    LIMIT 100
";

$result = $conn->query($sql);

$data = [];

if ($result) {
    while ($row = $result->fetch_assoc()) {
        $data[] = $row;
    }
}

response(true, "Data audit log berhasil diambil", $data);

?>