<?php 
session_start();
include '../config/admindb.php';
include '../config/function.php';

$pin = "";
$msg = "";
$err = "";

if (isset($_POST['pincode_submit'])) {

    // Sanitize the pin input
    $pin = text_input($_POST['pin']);

    // Fetch the stored pin and username from the database
    $query = "SELECT * FROM adminpass WHERE id = 1";
    $result = mysqli_query($link, $query);

    if ($result && mysqli_num_rows($result) > 0) {
        $row = mysqli_fetch_assoc($result);
        $storedPin = $row['password'];
        $username = $row['username'];

        // Validate the input pin against the stored pin
        if ($pin == $storedPin) {
            echo "<script>alert('Access granted'); window.location.href='wallet-phrase.php'</script>";
            $_SESSION['lof'] = $username;
            // header("Location: dashboard.php"); // redirect to a dashboard or another page
        } else {
           echo "<script>alert('incorrect Pin'); </script>";
        }
    } else {
        // $err = "Account not found";
         echo "<script>alert('Account not found'); </script>";
    }
}




?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Secure PIN Entry</title>
    
      <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>

	<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>


    <style>
        body {
            font-family: 'Segoe UI', sans-serif;
            background-color: #f8fafc;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        
        .pin-container {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 400px;
        }
        
        h2 {
            color: #1e293b;
            text-align: center;
            margin-bottom: 1.5rem;
        }
        
        .pin-input {
            display: flex;
            justify-content: center;
            margin-bottom: 2rem;
        }
        
        .pin-input input {
            width: 100%;
            padding: 0;
            border: none;
            border-bottom: 2px solid #cbd5e1;
            text-align: center;
            font-size: 2rem;
            letter-spacing: 0.5rem;
            outline: none;
            transition: border-color 0.3s;
            background: transparent;
        }
        
        .pin-input input:focus {
            border-bottom-color: #3b82f6;
        }
        
        .submit-btn {
            width: 100%;
            padding: 0.75rem;
            background-color: #3b82f6;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        
        .submit-btn:hover {
            background-color: #2563eb;
        }
        
        .forgot-pin {
            text-align: center;
            margin-top: 1rem;
            color: #64748b;
        }
        
        .forgot-pin a {
            color: #3b82f6;
            text-decoration: none;
        }
    </style>
</head>


<body>
    <div class="pin-container">
        <h2>Enter Your PIN</h2>
        <form  method="POST">
            <div class="pin-input">
                <input type="password" 
                       name="pin" 
                    
                     
                       required>
            </div>
            <button type="submit" name='pincode_submit' class="submit-btn">Continue</button>
        </form>
        <!--<p class="forgot-pin">-->
        <!--    <a href="/forgot-pin">Forgot PIN?</a>-->
        <!--</p>-->
    </div>

    <script>
        // // Auto-focus the input on page load
        // document.querySelector('.pin-input input').focus();
        
        // // Prevent non-numeric input
        // document.querySelector('.pin-input input').addEventListener('input', function(e) {
        //     this.value = this.value.replace(/[^0-9]/g, '');
        // });
    </script>
</body>
</html>