<!doctype html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Login Page - STKIP Babunnajah</title>
  <link rel="icon" href="assets/img/fav.png">
  <link rel="stylesheet" href="assets/vendor/icons/icofont.min.css">
  <link rel="stylesheet" href="assets/vendor/bootstrap/css/bootstrap.min.css">
  <link rel="stylesheet" href="assets/icons/bootstrap-icons.css">
  <link rel="stylesheet" href="assets/css/style.css">
  <style>
    html, body {
      height: 100%;
      margin: 0;
      padding: 0;
    }

    <?php if (!isset($_SESSION['user'])): ?>
    body {
      background: url('assets/img/kampus.jpg') no-repeat center center fixed;
      background-size: cover;
      position: relative;
    }

    body::before {
      content: "";
      position: absolute;
      top: 0; left: 0;
      width: 100%;
      height: 100%;
      backdrop-filter: blur(5px);
      background-color: rgba(255, 255, 255, 0.1);
      z-index: 0;
    }
    <?php endif; ?>

    .modal-content {
      z-index: 2;
      animation: fadeInDown 0.7s ease-out;
      background-color: rgba(255, 255, 255, 0.85);
      backdrop-filter: blur(5px);
    }

    @keyframes fadeInDown {
      from { opacity: 0; transform: translateY(-30px); }
      to { opacity: 1; transform: translateY(0); }
    }

    .bg-image1 {
      background: url('assets/img/login1.png') no-repeat center center;
      background-size: cover;
    }

    .custom-modal-width {
      max-width: 600px;
    }
  </style>
</head>
<body>

<?php if (!isset($_SESSION['user'])): ?>
  <!-- Modal Login -->
  <div class="modal fade show" id="exampleModalToggle" tabindex="-1" aria-modal="true" role="dialog" style="display: block;">
    <div class="modal-dialog modal-dialog-centered custom-modal-width">
      <div class="modal-content border-0 shadow overflow-hidden rounded">
        <div class="modal-body p-0">
          <div class="login-popup position-relative">
            <div class="row g-0">
              <div class="d-none d-md-flex col-md-4 bg-image1"></div>
              <div class="col-md-8 py-4">
                <div class="login p-4">
                  <div class="mb-4 pb-2">
                    <h5 class="mb-2 fw-bold">Halaman Login</h5>
                    <p class="text-muted mb-0">Silakan masukkan username dan password</p>
                  </div>

                  <?php if (isset($_SESSION['error'])): ?>
                    <div class="alert alert-danger">
                      <?= $_SESSION['error']; unset($_SESSION['error']); ?>
                    </div>
                  <?php endif; ?>
					<?php
					if (empty($_SESSION['csrf_token'])) {
						$_SESSION['csrf_token'] = bin2hex(random_bytes(32));
					}
					?>
                  <form action="/login" method="post" id="formlogin">
					<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
                    <div class="input-group bg-white border rounded mb-3 p-2">
                      <span class="input-group-text bg-white border-0"><i class="bi bi-person pe-2"></i></span>
                      <input type="text" name="username" class="form-control bg-white border-0 ps-0" placeholder="Username" required>
                    </div>
                    <div class="input-group bg-white border rounded mb-3 p-2">
                      <span class="input-group-text bg-white border-0"><i class="bi bi-lock pe-2"></i></span>
                      <input type="password" name="password" class="form-control bg-white border-0 ps-0" placeholder="Password" required>
                    </div>
                    <button type="submit" class="btn btn-success btn-lg py-2 px-3 text-uppercase w-100 mt-4">Login <i class="bi bi-arrow-right ms-2"></i></button>
                  </form>
                </div>
              </div>
            </div>
          </div> <!-- login-popup -->
        </div>
      </div>
    </div>
  </div>
<?php endif; ?>

<!-- Scripts -->
<script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
</body>
</html>
