<?php
// Proses ketika form disubmit
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Ambil data user dan password dari form
    $user = $_POST['user'];
    $pass = $_POST['pass'];

    // Tulis data ke dalam file config.user.php
    $configContent = "<?php\n";
    $configContent .= "\$user = \"$user\";\n";
    $configContent .= "\$pass = \"$pass\";\n";
    $configContent .= "return [\n";
    $configContent .= "    \"ADMIN_USER_NAME\" => \$user,\n";
    $configContent .= "    \"ADMIN_PASSWORD\" => \$pass,\n";
    $configContent .= "];\n";

    // Simpan data ke config.user.php
    file_put_contents('config.user.php', $configContent);

    // Feedback untuk pengguna setelah berhasil
    echo "<div class='container alert alert-success  mt-5'>Data berhasil disimpan!</div>";
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Pendaftaran User</title>
    <!-- Menyertakan CSS Bootstrap -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
</head>

<body>
    <div class="container-fluid mt-5">
        <div class="row justify-content-center">
            <div class="col-md-6">
                <div class="card">
                    <div class="card-header text-center bg-primary text-white">
                        <h4>Pendaftaran User</h4>
                    </div>
                    <div class="card-body">
                        <!-- Form untuk mengambil username dan password -->
                        <form method="POST" action="user.php">
                            <div class="mb-3">
                                <label for="user" class="form-label">Username</label>
                                <input type="text" id="user" name="user" class="form-control" required>
                            </div>

                            <div class="mb-3">
                                <label for="pass" class="form-label">Password</label>
                                <input type="password" id="pass" name="pass" class="form-control" required>
                            </div>

                            <div class="d-grid gap-2">
                                <button type="submit" class="btn btn-primary">Daftar</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Menyertakan JavaScript Bootstrap -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
</body>

</html>