<?php
/**
 * Admin Login Page
 * Converted from Falcon/pages/authentication/simple/login.html
 */

// Redirect if already logged in as admin
require_once __DIR__ . '/../includes/init.php';
if ($auth->isAdmin()) {
    header('Location: /admin');
    exit;
}

// Handle login
$error = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $email = $_POST['email'] ?? '';
    $password = $_POST['password'] ?? '';
    
    if ($auth->login($email, $password, true)) {
        header('Location: /admin');
        exit;
    } else {
        $error = 'Invalid email or password';
    }
}
?>
<!DOCTYPE html>
<html data-bs-theme="light" lang="en-US" dir="ltr">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Falcon | Admin Login</title>
    <link rel="apple-touch-icon" sizes="180x180" href="../Falcon/assets/img/favicons/apple-touch-icon.png">
    <link rel="icon" type="image/png" sizes="32x32" href="../Falcon/assets/img/favicons/favicon-32x32.png">
    <link rel="icon" type="image/png" sizes="16x16" href="../Falcon/assets/img/favicons/favicon-16x16.png">
    <link rel="shortcut icon" type="image/x-icon" href="../Falcon/assets/img/favicons/favicon.ico">
    <link rel="manifest" href="../Falcon/assets/img/favicons/manifest.json">
    <meta name="msapplication-TileImage" content="../Falcon/assets/img/favicons/mstile-150x150.png">
    <meta name="theme-color" content="#ffffff">
    <script src="../Falcon/assets/js/config.js"></script>
    <script src="../Falcon/vendors/simplebar/simplebar.min.js"></script>
    <link rel="preconnect" href="https://fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,500,600,700%7cPoppins:300,400,500,600,700,800,900&amp;display=swap" rel="stylesheet">
    <link href="../Falcon/vendors/simplebar/simplebar.min.css" rel="stylesheet">
    <link href="../Falcon/assets/css/theme-rtl.css" rel="stylesheet" id="style-rtl">
    <link href="../Falcon/assets/css/theme.css" rel="stylesheet" id="style-default">
    <link href="../Falcon/assets/css/user-rtl.css" rel="stylesheet" id="user-style-rtl">
    <link href="../Falcon/assets/css/user.css" rel="stylesheet" id="user-style-default">
    <script>
      var isRTL = JSON.parse(localStorage.getItem('isRTL'));
      if (isRTL) {
        var linkDefault = document.getElementById('style-default');
        var userLinkDefault = document.getElementById('user-style-default');
        linkDefault.setAttribute('disabled', true);
        userLinkDefault.setAttribute('disabled', true);
        document.querySelector('html').setAttribute('dir', 'rtl');
      } else {
        var linkRTL = document.getElementById('style-rtl');
        var userLinkRTL = document.getElementById('user-style-rtl');
        linkRTL.setAttribute('disabled', true);
        userLinkRTL.setAttribute('disabled', true);
      }
    </script>
  </head>
  <body>
    <main class="main" id="top">
      <div class="container" data-layout="container">
        <script>
          var isFluid = JSON.parse(localStorage.getItem('isFluid'));
          if (isFluid) {
            var container = document.querySelector('[data-layout]');
            container.classList.remove('container');
            container.classList.add('container-fluid');
          }
        </script>
        <div class="row flex-center min-vh-100 py-6">
          <div class="col-sm-10 col-md-8 col-lg-6 col-xl-5 col-xxl-4">
            <a class="d-flex flex-center mb-4" href="/admin">
              <img class="me-2" src="../Falcon/assets/img/icons/spot-illustrations/falcon.png" alt="" width="58" />
              <span class="font-sans-serif text-primary fw-bolder fs-4 d-inline-block">falcon</span>
            </a>
            <div class="card">
              <div class="card-body p-4 p-sm-5">
                <div class="row flex-between-center mb-2">
                  <div class="col-auto">
                    <h5>Log in</h5>
                  </div>
                  <div class="col-auto fs-10 text-600">
                    <span class="mb-0 undefined">Admin Panel</span>
                  </div>
                </div>
                
                <?php if ($error): ?>
                <div class="alert alert-danger" role="alert">
                  <?php echo htmlspecialchars($error); ?>
                </div>
                <?php endif; ?>
                
                <form method="POST">
                  <div class="mb-3">
                    <input class="form-control" type="email" name="email" placeholder="Email address" required />
                  </div>
                  <div class="mb-3">
                    <input class="form-control" type="password" name="password" placeholder="Password" required />
                  </div>
                  <div class="row flex-between-center">
                    <div class="col-auto">
                      <div class="form-check mb-0">
                        <input class="form-check-input" type="checkbox" id="basic-checkbox" name="remember" checked="checked" />
                        <label class="form-check-label mb-0" for="basic-checkbox">Remember me</label>
                      </div>
                    </div>
                  </div>
                  <div class="mb-3">
                    <button class="btn btn-primary d-block w-100 mt-3" type="submit" name="submit">Log in</button>
                  </div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
    <script src="../Falcon/vendors/popper/popper.min.js"></script>
    <script src="../Falcon/vendors/bootstrap/bootstrap.min.js"></script>
    <script src="../Falcon/vendors/anchorjs/anchor.min.js"></script>
    <script src="../Falcon/vendors/is/is.min.js"></script>
    <script src="../Falcon/vendors/fontawesome/all.min.js"></script>
    <script src="../Falcon/vendors/lodash/lodash.min.js"></script>
    <script src="../Falcon/vendors/list.js/list.min.js"></script>
    <script src="../Falcon/assets/js/theme.js"></script>
  </body>
</html>

