<?php
session_start();

if (!isset($_SESSION['user_id'])) {
    http_response_code(403);
    exit;
}

$file = __DIR__ . "/data/islemler.json";

if (!file_exists($file)) {
    exit;
}

$id = $_POST["id"] ?? "";
if ($id === "") {
    exit;
}

$data = json_decode(file_get_contents($file), true);
if (!$data || !isset($data["kayitlar"])) {
    exit;
}

$data["kayitlar"] = array_values(array_filter(
    $data["kayitlar"],
    function($k) use ($id){
        return isset($k["id"]) && $k["id"] !== $id;
    }
));

file_put_contents(
    $file,
    json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
);
