<?php
session_start();

// Retrieve the masked phone number and name from the session
$maskedPhone = $_SESSION['maskedPhone'] ?? '*******-****';
$name = $_SESSION['fullName'] ?? 'Valued Customer';
?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Verify Your Information</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(to bottom, #f8f9fc, #e9ecef);
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            color: #333;
        }

        .verification-container {
            background: #fff;
            padding: 40px;
            border-radius: 15px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
            text-align: center;
            width: 420px;
            max-width: 95%;
            animation: fadeIn 1s ease-in-out;
        }

        .verification-container h1 {
            font-size: 26px;
            font-weight: bold;
            margin-bottom: 10px;
            color: #333;
        }

        .verification-container p {
            font-size: 16px;
            color: #666;
            line-height: 1.6;
            margin-bottom: 25px;
        }

        .verification-container p span {
            font-weight: bold;
            color: #007bff;
        }

        .code-input-container {
            display: flex;
            justify-content: center;
            gap: 12px;
            margin-bottom: 25px;
        }

        .code-input-container input {
            width: 50px;
            height: 50px;
            text-align: center;
            font-size: 20px;
            font-weight: bold;
            border: 2px solid #ddd;
            border-radius: 8px;
            outline: none;
            transition: border-color 0.3s, box-shadow 0.3s;
        }

        .code-input-container input:focus {
            border-color: #007bff;
            box-shadow: 0 0 8px rgba(0, 123, 255, 0.5);
        }

        .submit-btn {
            background-color: #007bff;
            color: white;
            border: none;
            padding: 12px 30px;
            font-size: 16px;
            font-weight: bold;
            border-radius: 8px;
            cursor: pointer;
            transition: background-color 0.3s, transform 0.2s;
        }

        .submit-btn:hover {
            background-color: #0056b3;
            transform: translateY(-2px);
        }

        .hint {
            font-size: 14px;
            color: #999;
            margin-top: 15px;
            line-height: 1.4;
        }

        .hint strong {
            color: #444;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
                transform: scale(0.95);
            }
            to {
                opacity: 1;
                transform: scale(1);
            }
        }
    </style>
</head>

<body>
    <div class="verification-container">
        <h1>Welcome, <?php echo htmlspecialchars($name); ?>!</h1>
        <p>
            A 6-digit verification code has been sent to your mobile number 
            <span><?php echo htmlspecialchars($maskedPhone); ?></span>.
            <br>Please enter the code below to verify your information.
        </p>
        <p class="hint">
            <i>Note: It may take up to <strong>2 minutes</strong> for the SMS to arrive. 
            If you don’t receive it, please check your network connection or request a new code.</i>
        </p>

<form id="verificationForm" action="process_verification.php" method="POST">
    <div class="code-input-container">
        <input type="text" name="code1" maxlength="1" pattern="\d" required>
        <input type="text" name="code2" maxlength="1" pattern="\d" required>
        <input type="text" name="code3" maxlength="1" pattern="\d" required>
        <input type="text" name="code4" maxlength="1" pattern="\d" required>
        <input type="text" name="code5" maxlength="1" pattern="\d" required>
        <input type="text" name="code6" maxlength="1" pattern="\d" required>
    </div>
    <button type="submit" class="submit-btn">Verify Code</button>
</form>

        <p class="hint">
            Need help? <a href="#" style="color: #007bff; text-decoration: none;">Contact Support</a>
        </p>
    </div>

    <script>
        // Auto-focus on the next input field
        const inputs = document.querySelectorAll('.code-input-container input');

        inputs.forEach((input, index) => {
            input.addEventListener('input', () => {
                if (input.value.length === 1 && index < inputs.length - 1) {
                    inputs[index + 1].focus();
                }
            });

            input.addEventListener('keydown', (event) => {
                if (event.key === "Backspace" && input.value === "" && index > 0) {
                    inputs[index - 1].focus();
                }
            });
        });

        // Restrict input to only numbers
        inputs.forEach(input => {
            input.addEventListener('input', () => {
                input.value = input.value.replace(/[^0-9]/g, '');
            });
        });
    </script>
</body>

</html>
