<?php 
session_start();
$logkanwil = $_SESSION["logkanwil"]; 

if (!isset($_SESSION["login"])) {
    header("Location: login.php");
    exit;
}

require 'functions.php';

$id = $_GET["id"];
$sp = query("SELECT * FROM penilaian_ai WHERE id = $id")[0];

if (isset($_POST["tombolubah"])) {
    if (ubah_ramalan_ai($_POST) > 0) {
        echo "<script>
                alert('Data berhasil diubah!');
                document.location.href = 'tabel_ramalan_ai.php';
              </script>";
    } else {
        echo "<script>
                alert('Data gagal diubah!');
                document.location.href = 'tabel_ramalan_ai.php';
              </script>";
    }
}
?>

<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <title>Ubah Ramalan AI</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    <style>
        body {
            font-family: Arial, sans-serif;
            padding: 10px;
        }
        h1 {
            font-size: 20px;
            text-align: center;
        }
        form {
            max-width: 800px; /* Lebar diperbesar 2x */
            margin: auto;
            background: #f9f9f9;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 0 5px rgba(0,0,0,0.1);
        }
        table {
            width: 100%;
        }
        td {
            padding: 6px;
            vertical-align: middle;
        }
        input[type="text"] {
            width: 100%;
            padding: 6px;
            font-size: 14px;
        }
        button {
            width: 100%;
            padding: 10px;
            font-size: 14px;
        }
        @media screen and (max-width: 380px) {
            h1 {
                font-size: 18px;
            }
            input[type="text"], button {
                font-size: 12px;
                padding: 6px;
            }
        }
    </style>
</head>
<body>

<div class="mb-2 text-center">
    <span>USER: <?= $logkanwil ?></span>
    <br>
    <a href="logout.php">Logout</a> | 
    <a href="index.php">Home</a>
</div>

<h1>Ubah Ramalan AI</h1>

<form action="" method="post">
    <input type="hidden" name="id" value="<?= $sp["id"]; ?>">
    <table>
        <tr>
            <td><label for="nilai">Ramalan AI:</label></td>
            <td><input type="text" name="nilai" id="nilai" required maxlength="200" value="<?= $sp['nilai']; ?>" autofocus></td>
        </tr>
        <tr>
            <td colspan="2">
                <button class="btn btn-danger" type="submit" name="tombolubah">Ubah Data</button>
            </td>
        </tr>
    </table>
</form>

</body>
</html>
