<?php
require_once __DIR__ . "/../../app/config/koneksi.php";

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

    $nama  = trim($_POST['nama']);
    $no_hp = trim($_POST['no_hp']);
    $pesan = trim($_POST['pesan']);

    // Pisahkan tanggal dan jam
    $tanggal = date("Y-m-d");
    $jam     = date("H:i:s");

    if (!$koneksi) {
        die("Koneksi database gagal!");
    }

    $stmt = $koneksi->prepare("INSERT INTO kritik_saran (nama, no_hp, pesan, tanggal, jam, status) VALUES (?, ?, ?, ?, ?, 'baru')");
    $stmt->bind_param("sssss", $nama, $no_hp, $pesan, $tanggal, $jam);

    if ($stmt->execute()) {
        header("Location: terima_kasih.php");
        exit;
    } else {
        echo "Gagal menyimpan data: " . $koneksi->error;
    }
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Kritik & Saran Masjid</title>

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="css/mobile-style.css?ver=500">
</head>
<body class="night-stars fade-in">

    <!-- Bulan -->
    <div id="moon"></div>

    <!-- Bintang -->
    <div class="stars"></div>
    <div class="stars2"></div>
    <div class="stars3"></div>

    <!-- Shooting Stars -->
    <div class="shooting-star" style="left: 75%; animation-delay: 2.5s;"></div>
    <div class="shooting-star" style="left: 55%; animation-delay: 8s;"></div>

    <!-- Fireflies -->
    <div class="firefly"></div>
    <div class="firefly"></div>
    <div class="firefly"></div>
    <div class="firefly"></div>
    <div class="firefly"></div>

    <div class="container">
        <div class="card-mobile">
            
            <div class="text-center mb-3">
                <img src="https://cdn-icons-png.flaticon.com/512/3176/3176403.png" width="55">
                <h5 class="fw-bold text-white mt-2">Kritik & Saran</h5>
                <small class="text-white-50">Masukan Anda sangat berarti bagi kami ✨</small>
            </div>

            <form method="POST">

                <div class="form-group mb-3">
                    <label class="form-label">Nama</label>
                    <input type="text" name="nama" class="form-control" required>
                </div>

                <div class="form-group mb-3">
                    <label class="form-label">Nomor HP</label>
                    <input type="text" name="no_hp" class="form-control" required>
                </div>

                <div class="form-group mb-3">
                    <label class="form-label">Kritik / Saran</label>
                    <textarea name="pesan" class="form-control" rows="4" required></textarea>
                </div>

                <button class="btn-success w-100 mt-2">Kirim</button>

            </form>

        </div>
    </div>

    <script src="js/mobile-script.js?ver=500"></script>

</body>
</html>
