<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <title><?= esc($title ?? 'Login') ?></title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
  <style>
    * {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background-color: #a6c9f2;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  overflow-x: hidden;
}

input[type="checkbox"] {
  display: none;
}

.login-container {
  width: 90vw;
  max-width: 360px;
  position: relative;
  z-index: 10;
}

.step-box {
  background: #fff;
  border-radius: 6px;
  padding: 20px;
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
  position: absolute;
  width: 100%;
  transition: transform 0.5s ease-in-out, opacity 0.5s ease-in-out;
}

.step-box input {
  border: none;
  border-bottom: 2px solid #007bff;
  outline: none;
  width: 100%;
  padding: 10px 5px;
  font-size: 16px;
}

.step-box span.prompt {
  display: block;
  margin-bottom: 10px;
  font-weight: 500;
}

.step-box.password-step {
  transform: translateX(100%);
  opacity: 0;
  pointer-events: none;
}

#step2:checked ~ .login-container .username-step {
  transform: translateX(-100%);
  pointer-events: none;
  opacity: 0;
}

#step2:checked ~ .login-container .password-step {
  transform: translateX(0);
  pointer-events: auto;
  opacity: 1;
}

.btn-login,
.btn-next {
  width: 100%;
  margin-top: 15px;
}

.display-username {
  font-weight: 600;
  color: #007bff;
  text-align: center;
  margin-bottom: 10px;
}

.btn-back {
  background: none;
  border: none;
  color: #007bff;
  text-decoration: none;
  padding: 0;
  margin-bottom: 10px;
  font-size: 14px;
}

.btn-back:hover {
  text-decoration: underline;
}

/* Responsiveness untuk layar kecil */
@media (max-width: 480px) {
  .step-box {
    padding: 15px;
  }

  .step-box input {
    font-size: 14px;
  }

  .btn-login,
  .btn-next {
    font-size: 14px;
    padding: 10px;
  }

  .btn-back {
    font-size: 13px;
  }

  .prompt {
    font-size: 14px;
  }
}


  </style>
</head>
<body>

  <!-- Hidden checkboxes for step control -->
  <input type="checkbox" id="step1" checked>
  <input type="checkbox" id="step2">

  <div class="login-container">

    <?php if (session()->getFlashdata('error')): ?>
      <div class="alert alert-danger">
        <?= session()->getFlashdata('error') ?>
      </div>
    <?php endif; ?>

    <form action="<?= base_url('login/auth') ?>" method="post" id="loginForm">

      <!-- Step 1: Username -->
      <div class="step-box username-step">
        <span class="prompt">Masukkan Username Anda</span>
        <input type="text" name="username" id="usernameInput" placeholder="Username" required>
        <!-- Tombol Lanjut sebagai pengganti panah -->
        <button type="button" class="btn btn-primary btn-next" onclick="handleNext()">Lanjut</button>
      </div>

      <!-- Step 2: Password -->
      <div class="step-box password-step">
        <!-- Tombol kembali ke Username -->
        <button type="button" class="btn-back" onclick="kembaliKeUsername()">← Kembali</button>

        <!-- Tambahan: Username ditampilkan di sini -->
        <div class="display-username" id="showUsername"></div>
        <span class="prompt">Masukkan Password Anda</span>
        <input type="password" name="password" placeholder="Password" required>
        <button type="submit" class="btn btn-primary btn-login">Login</button>
      </div>

    </form>
  </div>

  <!-- Tambahan JavaScript -->
  <script>
    document.getElementById('usernameInput').addEventListener('keydown', function(e) {
  if (e.key === 'Enter') {
    e.preventDefault(); 
    handleNext();       
  }
});

    function handleNext() {
      const input = document.getElementById('usernameInput');
      const tampil = document.getElementById('showUsername');
      const step2 = document.getElementById('step2');

      if (input.value.trim() === '') {
        alert('Username wajib diisi');
        input.focus();
        return;
      }

      tampil.innerText = input.value;
      step2.checked = true;
    }

    function kembaliKeUsername() {
      document.getElementById('step2').checked = false;

    }
  </script>

</body>
</html>
