<?php
require __DIR__ . '/security_headers.php';

session_start();
if (!empty($_SESSION['user'])) {
  header('Location: dashboard.php');
  exit;
}

$errors = $_GET['e'] ?? null;
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Student Login</title>
  <link rel="icon" type="image/svg+xml" href="/public/img/umis_logo.svg">


  <!-- Styles -->
  <link rel="stylesheet" href="public/css/styles.css">
  <link rel="stylesheet" href="public/css/admin.css"><!-- for pw-eye styles -->
</head>
<body>
  <main class="split">
    <section class="panel form-panel">
      <div class="form-wrap">
        <div class="brand">
          <img src="public/img/umis_logo.svg" alt="logo">
          <div class="brand-sub">University Management<br>Information System</div>
        </div>

        <?php if ($errors): ?>
          <div class="alert" role="alert" aria-live="polite">
            <?php echo htmlspecialchars($errors, ENT_QUOTES, 'UTF-8'); ?>
          </div>
        <?php endif; ?>

        <form action="auth.php" method="post" class="login-form" novalidate>
          <label for="email">E-Mail</label>
          <input type="email" id="email" name="email" autocomplete="username" required placeholder="you@example.com">

          <div class="field" style="margin-top:12px">
            <label for="password">Password</label>
            <div class="pw-wrap">
              <input type="password" id="password" name="password" autocomplete="current-password" required placeholder="••••••••">
              <button type="button" class="pw-eye" aria-label="Show password" data-target="password" title="Show password">
                <!-- eye -->
                <svg class="icon-eye" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                  <path d="M1 12s4-7 11-7 11 7 11 7-4 7-11 7S1 12 1 12Z"/>
                  <circle cx="12" cy="12" r="3"/>
                </svg>
                <!-- eye-off -->
                <svg class="icon-eye-off" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
                  <path d="M17.94 17.94A10.94 10.94 0 0 1 12 19c-7 0-11-7-11-7a21.91 21.91 0 0 1 5.06-5.94M9.9 4.24A10.94 10.94 0 0 1 12 4c7 0 11 7 11 7a21.83 21.83 0 0 1-3.17 4.33"/>
                  <line x1="1" y1="1" x2="23" y2="23"/>
                </svg>
              </button>
            </div>
          </div>

          <button type="submit" class="btn-primary" style="margin-top:16px">Login</button>

          <!-- Avoid inline JS (CSP). Link to a help page or mailto. -->
          <!--<a class="link-muted" href="mailto:admin@example.com?subject=Password%20reset%20request">I forgot my password</a>-->
        </form>

        <div class="locale">
          <!--<a href="#" aria-disabled="true">TÜRKÇE</a>-->
        </div>
      </div>
    </section>

    <section class="panel hero-panel">
      <img src="public/img/hero.jpg" alt="" class="hero-img" />
    </section>
  </main>

  <!-- Scripts (defer to satisfy CSP; no inline JS) -->
  <script src="public/js/app.js" defer></script>
  <script src="public/js/pw-toggle.js" defer></script>
</body>
</html>
