<?php
session_start();

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $username = $_POST['username'];
    $password = $_POST['password'];

    $admin_data = json_decode(file_get_contents('../data/admin.json'), true);

    $admin_found = false;
    foreach ($admin_data as $admin) {
        if ($admin['username'] === $username && $admin['password'] === $password) {
            $_SESSION['admin_logged_in'] = true;
            header('Location: ../public/admin_view.php');
            exit;
        }
    }

    echo "Username atau password salah.";
}
