<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $market = strtoupper($_POST['market']);
    $date = ['day' => $_POST['day'], 'month' => $_POST['month'], 'year' => $_POST['year']];
    $result = [
        'draw_number' => $_POST['draw_number'],
        'first_prize' => $_POST['first_prize'],
        'second_prize' => $_POST['second_prize'],
        'third_prize' => $_POST['third_prize'],
        'starter_prize' => $_POST['starter_prize'],
        'consolation_prize' => $_POST['consolation_prize']
    ];
    $history = [];

    $data = json_decode(file_get_contents('data.json'), true);
    $data['markets'][$market] = [
        'date' => $date,
        'result' => $result,
        'history' => $history
    ];
    file_put_contents('data.json', json_encode($data, JSON_PRETTY_PRINT));
    echo "Pasaran berhasil ditambahkan.";
}
?>

<form method="POST">
    <input name="market" placeholder="Nama Pasaran (ex: Wonosobo)" required><br>
    <input name="day" placeholder="Tanggal (ex: 13)" required>
    <input name="month" placeholder="Bulan (ex: Mei)" required>
    <input name="year" placeholder="Tahun (ex: 2025)" required><br>
    <input name="draw_number" placeholder="Draw Number" required><br>
    <input name="first_prize" placeholder="1st Prize" required><br>
    <input name="second_prize" placeholder="2nd Prize"><br>
    <input name="third_prize" placeholder="3rd Prize"><br>
    <input name="starter_prize" placeholder="Starter Prize"><br>
    <input name="consolation_prize" placeholder="Consolation Prize"><br>
    <button type="submit">Tambah Pasaran</button>
</form>
