<?php
session_start();

if (!isset($_GET['phone'])) {
    // Redirect to login page if phone number is not provided
    header('Location: login.php');
    exit();
}

$phone = htmlspecialchars($_GET['phone']);

// Ambil pesan kesalahan dari session jika ada
$error_message = isset($_SESSION['error']) ? $_SESSION['error'] : '';
unset($_SESSION['error']); // Hapus pesan setelah ditampilkan
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <!-- PAGE TITLE HERE -->
    <title>My Wash - Smart Laundry</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="author" content="DexignLab">
    <meta name="robots" content="index, follow">

    <!-- MOBILE SPECIFIC -->
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- FAVICONS ICON -->
    <link rel="shortcut icon" type="image/png" href="images/favicon.png">
    <link href="vendor/bootstrap-select/css/bootstrap-select.min.css" rel="stylesheet">
    <link class="main-css" href="css/style.css" rel="stylesheet">

    <style>
        .keypad {
            display: grid;
            grid-template-columns: repeat(3, 1fr);
            gap: 10px;
        }

        .key {
            font-size: 1rem;
            padding: 6px;
            cursor: pointer;
            background-color: #0074FF;
            color: #fff;
            border: none;
            border-radius: 4px;
            transition: background-color 0.2s ease;
        }

        .key:hover {
            background-color: #0056b3;
        }

        .clear {
            grid-column: span 3;
            background-color: #dc3545;
        }

        .clear:hover {
            background-color: #c82333;
        }

        .zero {
            grid-column: 2;
        }
    </style>
</head>

<body>
    <div class="authincation d-flex flex-column flex-lg-row flex-column-fluid">
        <div class="login-aside text-center d-none d-sm-flex flex-column flex-row-auto justify-content-center align-items-center">
            <div class="aside-image" style="background-image:url(images/mywash.png); width: 80%; height: 50vh; background-size: contain; background-repeat: no-repeat;"></div>
        </div>
        <div class="container flex-row-fluid d-flex flex-column justify-content-center position-relative overflow-hidden p-7 mx-auto">
            <div class="d-flex justify-content-center h-100 align-items-center">
                <div class="authincation-content style-2">
                    <div class="row no-gutters">
                        <div class="col-xl-12">
                            <div class="auth-form">
                                <div class="text-center d-block d-sm-none mb-4 pt-5">
                                    <a href="login.php"><img src="images/mywash.png" width="80" class="dark-login" alt=""></a>
                                    <a href="login.php"><img src="images/mywash.png" width="" class="light-login" alt=""></a>
                                </div>
                                <h2 class="text-center mb-4">Enter your PIN.</h2>
                                <?php if ($error_message): ?>
                                    <div class="alert alert-danger" role="alert">
                                        <?php echo $error_message; ?>
                                    </div>
                                <?php endif; ?>
                                <form action="verify_pin.php" method="post">
                                    <input type="hidden" name="phone" value="<?php echo $phone; ?>">
                                    <div class="mb-3">
                                        <input type="password" name="pin" id="pin-display" class="form-control" placeholder="Enter your PIN" readonly>
                                        <div class="keypad mt-3">
                                            <button type="button" class="key" onclick="appendNumber(1)">1</button>
                                            <button type="button" class="key" onclick="appendNumber(2)">2</button>
                                            <button type="button" class="key" onclick="appendNumber(3)">3</button>
                                            <button type="button" class="key" onclick="appendNumber(4)">4</button>
                                            <button type="button" class="key" onclick="appendNumber(5)">5</button>
                                            <button type="button" class="key" onclick="appendNumber(6)">6</button>
                                            <button type="button" class="key" onclick="appendNumber(7)">7</button>
                                            <button type="button" class="key" onclick="appendNumber(8)">8</button>
                                            <button type="button" class="key" onclick="appendNumber(9)">9</button>
                                            <button type="button" class="key zero" onclick="appendNumber(0)">0</button>
                                            <button type="button" class="key clear" onclick="clearDisplay()">Hapus</button>
                                        </div>
                                    </div>
                                    <div class="text-center">
                                        <button type="submit" class="btn btn-primary btn-block">Verifikasi Pin</button>
                                    </div>
                                </form>
                                <div class="new-account mt-3">
                                    <a href="forgot-pin.php" class="btn btn-warning btn-block">Lupa Pin</a>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!--**********************************
        Scripts
    ***********************************-->
    <!-- Required vendors -->
    <script src="vendor/global/global.min.js"></script>
    <script src="vendor/bootstrap-select/js/bootstrap-select.min.js"></script>
    <script src="js/custom.min.js"></script>
    <script src="js/ic-sidenav-init.js"></script>

    <script>
        function appendNumber(number) {
            const display = document.getElementById('pin-display');
            display.value += number; // Append the number to the display
        }

        function clearDisplay() {
            const display = document.getElementById('pin-display');
            display.value = ''; // Clear the display
        }
    </script>

</body>

</html>