<?php $pageTitle = 'Login'; ?>
<?php
$cfg = require ROOT . '/config/app.php';
$recaptchaSite = $cfg['recaptcha_site'] ?? '';
?>
<?php if($recaptchaSite): ?>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<?php endif; ?>
<div class="auth-card">
  <div class="auth-logo">
    <div class="logo">E</div>
    <h1>EduSmart SMS</h1>
    <p>School Management System</p>
  </div>

  <?php if(($_GET['reason'] ?? '') === 'timeout'): ?>
  <div class="alert alert-danger" style="display:flex;align-items:center;gap:10px">
    <span style="font-size:20px">⏱️</span>
    <div><strong>Session Expired</strong><br>You were inactive for 15 minutes and have been logged out. Please login again.</div>
  </div>
  <?php endif; ?>

  <?php $err = \Core\Session::getFlash('errors'); if($err): ?>
  <div class="alert alert-danger">
    <?php foreach($err as $msg): ?>
      <div><?= htmlspecialchars(is_array($msg) ? $msg[0] : $msg) ?></div>
    <?php endforeach; ?>
  </div>
  <?php endif; ?>

  <form method="POST" action="<?= \Core\View::url('login') ?>">
    <?= \Core\View::csrf() ?>
    <div class="form-group">
      <label>Email / Assessment Number</label>
      <div class="input-wrap">
        <i class="bi bi-person"></i>
        <input type="text" name="email" value="<?= \Core\View::old('email') ?>" placeholder="admin@school.ac.ke or 2025/001" required autofocus>
      </div>
    </div>
    <div class="form-group">
      <label>Password</label>
      <div class="input-wrap">
        <i class="bi bi-lock"></i>
        <input type="password" name="password" placeholder="••••••••" required minlength="8">
      </div>
    </div>
    <div class="form-check">
      <input type="checkbox" name="remember" id="remember">
      <label for="remember">Remember me</label>
    </div>
    <?php if($recaptchaSite): ?>
    <div class="g-recaptcha" data-sitekey="<?= htmlspecialchars($recaptchaSite) ?>" style="margin-bottom:14px"></div>
    <?php endif; ?>
    <button type="submit" class="btn-login">Sign In &rarr;</button>
  </form>
</div>
