<?php
// 1. टाइमज़ोन सेट करें
date_default_timezone_set('Asia/Kolkata');
$current_time = date('M d, Y, g:i:s A', time());

// 2. कॉन्फ़िगरेशन फ़ाइल शामिल करें
include('includes/config.php');

$error_script = "";

// 3. बैकएंड रजिस्ट्रेशन प्रोसेसिंग
if (isset($_POST['reg']) && $_POST['reg'] == "ahkweb") {
  
  $name = mysqli_real_escape_string($conn, $_POST['name']);
  $mobile = mysqli_real_escape_string($conn, $_POST['mobile']);
  $email = mysqli_real_escape_string($conn, $_POST['email']);
  $password = mysqli_real_escape_string($conn, $_POST['password']);
  $cpassword = mysqli_real_escape_string($conn, $_POST['cpassword']);

  if (!empty($password) && !empty($cpassword) && $mobile != "ADMIN" && $email != "ADMIN") {
    if ($password == $cpassword) {

      $fpassword = password_hash($cpassword, PASSWORD_DEFAULT);
      $checksql = mysqli_query($conn, "SELECT * FROM usertable WHERE emailid='$email' OR phone='$mobile'");
      
      if (!empty($name) && !empty($mobile) && !empty($email) && !empty($password) && !empty($cpassword)) {
        if (mysqli_num_rows($checksql) == 0) {
    
          $sql = "INSERT INTO `usertable` (`phone`, `emailid`, `name`, `password`, `city`, `state`, `userid`, `status`, `profilepic`, `createdby`, `joineddate`, `joinedtime`, `usertype`, `walletamount`,`otp`) VALUES ('$mobile', '$email', '$name', '$fpassword', 'cc', 'sdds', '$mobile', 'verified', '', NULL, '', '', 'OPERATER', '0','');";
          $res = mysqli_query($conn, $sql);
          
          if($res){
            $error_script = "
                Swal.fire({
                    icon: 'success',
                    title: 'Success',
                    text: 'Registered Successfully! You can Login now.',
                    timer: 1500,
                    showConfirmButton: false
                }).then(() => {
                    window.location.href = 'index.php';
                });
            ";
          } else {
            $error_script = "
                Swal.fire({
                    icon: 'error',
                    title: 'Oops!',
                    text: 'Internal Server Error, Please Try Again Later!'
                });
            ";
          }
        } else {
          $error_script = "
              Swal.fire({
                  icon: 'error',
                  title: 'Oops!',
                  text: 'Your email or phone already exists!'
              }).then(() => {
                  window.location.href = 'index.php';
              });
          ";
        }
      } else {
        $error_script = "
            Swal.fire({
                icon: 'error',
                title: 'Oops!',
                text: 'Please Fill All Data!'
            });
        ";
      }
    } else {
      $error_script = "
          Swal.fire({
              icon: 'error',
              title: 'Oops!',
              text: 'Confirm Password Does Not Match!'
          });
      ";
    }
  } else {
    $error_script = "
        Swal.fire({
            icon: 'error',
            title: 'WOW trying to Cheat!!!',
            text: 'You Are A Cheater, GET OUT!'
        });
    ";
  }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Create Professional Account</title>
	<script disable-devtool-auto src="https://cdn.jsdelivr.net/npm/disable-devtool@latest"></script>

    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.css">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Poppins', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 40px 20px;
        }

        .login-container {
            background: rgba(255, 255, 255, 0.08);
            backdrop-filter: blur(12px);
            -webkit-backdrop-filter: blur(12px);
            border: 1px solid rgba(255, 255, 255, 0.15);
            padding: 40px;
            width: 100%;
            max-width: 500px;
            border-radius: 20px;
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
            color: #fff;
        }

        .login-header {
            text-align: center;
            margin-bottom: 30px;
        }

        .login-header .logo-icon {
            font-size: 3rem;
            color: #00f2fe;
            margin-bottom: 10px;
            text-shadow: 0 0 15px rgba(0, 242, 254, 0.5);
        }

        .login-header h2 {
            font-size: 1.8rem;
            font-weight: 600;
            letter-spacing: 0.5px;
            margin-bottom: 5px;
        }

        .login-header p {
            font-size: 0.85rem;
            color: #cbd5e1;
        }

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

        .form-group i.input-icon {
            position: absolute;
            left: 15px;
            top: 50%;
            transform: translateY(-50%);
            color: #cbd5e1;
            font-size: 1.1rem;
            transition: 0.3s;
        }

        .form-control {
            width: 100%;
            padding: 14px 45px 14px 45px;
            background: rgba(255, 255, 255, 0.1);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 10px;
            outline: none;
            color: #fff;
            font-size: 0.95rem;
            transition: all 0.3s ease;
        }

        .form-control:focus {
            background: rgba(255, 255, 255, 0.15);
            border-color: #00f2fe;
            box-shadow: 0 0 10px rgba(0, 242, 254, 0.2);
        }

        .form-control::placeholder {
            color: #94a3b8;
        }

        .form-control:focus ~ i.input-icon {
            color: #00f2fe;
        }

        .password-toggle {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #cbd5e1;
            transition: 0.3s;
        }

        .password-toggle:hover {
            color: #00f2fe;
        }

        .login-btn {
            width: 100%;
            padding: 15px;
            background: linear-gradient(135deg, #00f2fe 0%, #4facfe 100%);
            border: none;
            border-radius: 10px;
            color: #fff;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s ease;
            box-shadow: 0 5px 15px rgba(79, 172, 254, 0.4);
            margin-top: 10px;
        }

        .login-btn:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 242, 254, 0.6);
            background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
        }

        .form-footer {
            text-align: center;
            margin-top: 25px;
            font-size: 0.85rem;
            color: #cbd5e1;
        }

        .form-footer a {
            color: #00f2fe;
            text-decoration: none;
            font-weight: 500;
        }

        .form-footer a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>

    <div class="login-container">
        <div class="login-header">
            <div class="logo-icon"><i class="fa-solid fa-user-plus"></i></div>
            <h2>Create Account</h2>
            <p>Join us to manage your operator portal</p>
        </div>

        <form action="" method="POST" autocomplete="off">
            <input type="hidden" name="reg" value="ahkweb">

            <div class="form-group">
                <i class="fa-solid fa-user input-icon"></i>
                <input type="text" name="name" class="form-control" placeholder="Full Name" required>
            </div>

            <div class="form-group">
                <i class="fa-solid fa-phone input-icon"></i>
                <input type="text" name="mobile" class="form-control" placeholder="Mobile Number" required>
            </div>

            <div class="form-group">
                <i class="fa-solid fa-envelope input-icon"></i>
                <input type="email" name="email" class="form-control" placeholder="Email Address" required>
            </div>

            <div class="form-group">
                <i class="fa-solid fa-lock input-icon"></i>
                <input type="password" id="password" name="password" class="form-control" placeholder="Password" required>
                <i class="fa-solid fa-eye password-toggle" id="togglePassword"></i>
            </div>

            <div class="form-group">
                <i class="fa-solid fa-lock-open input-icon"></i>
                <input type="password" id="cpassword" name="cpassword" class="form-control" placeholder="Confirm Password" required>
                <i class="fa-solid fa-eye password-toggle" id="toggleCPassword"></i>
            </div>

            <button type="submit" class="login-btn">Register Now</button>
        </form>

        <div class="form-footer">
            <p>Already have an account? <a href="index.php">Sign In</a></p>
        </div>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <script>
        // 1. मुख्य पासवर्ड शो/हाइड स्क्रिप्ट
        const togglePassword = document.querySelector('#togglePassword');
        const password = document.querySelector('#password');
        togglePassword.addEventListener('click', function () {
            const type = password.getAttribute('type') === 'password' ? 'text' : 'password';
            password.setAttribute('type', type);
            this.classList.toggle('fa-eye-slash');
        });

        // 2. कन्फर्म पासवर्ड शो/हाइड स्क्रिप्ट
        const toggleCPassword = document.querySelector('#toggleCPassword');
        const cpassword = document.querySelector('#cpassword');
        toggleCPassword.addEventListener('click', function () {
            const type = cpassword.getAttribute('type') === 'password' ? 'text' : 'password';
            cpassword.setAttribute('type', type);
            this.classList.toggle('fa-eye-slash');
        });

        // 3. PHP बैकएंड संदेशों के लिए SweetAlert ट्रिगर
        $(document).ready(function() {
            <?php echo $error_script; ?>
        });
    </script>
</body>
</html>