<?php

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// Jika sudah login sebagai admin
if (
    isset($_SESSION['user_id']) &&
    isset($_SESSION['role']) &&
    $_SESSION['role'] === 'admin'
) {
    header("Location: dashboard.php");
    exit;
}

$error = "";

if (isset($_GET['error'])) {
    $error = "Username atau password salah.";
}

?>

<!DOCTYPE html>
<html lang="id">

<head>
    <link rel="icon"
        type="image/png"
        href="/website-dispussip/assets/img/logo.PNG">
    <meta charset="UTF-8">

    <meta name="viewport"
        content="width=device-width, initial-scale=1.0">

    <title>Login Admin - DISPUSIP Banyuwangi</title>

    <link
        href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css"
        rel="stylesheet">

    <style>
        body {
            background: #f5f7fb;
            min-height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .login-card {
            width: 420px;
            border: none;
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, .1);
        }

        .login-header {
            background: #07357e;
            color: white;
            padding: 25px;
            text-align: center;
        }

        .login-header img {
            width: 220px;
            margin-bottom: 15px;
        }

        .login-body {
            padding: 30px;
            background: white;
        }

        .btn-primary {
            background-color: #07357e !important;
            border-color: #07357e !important;
        }
    </style>

</head>

<body>

    <div class="card login-card">

        <div class="login-header">

            <img
                src="/website-dispussip/assets/img/logo dispussip.png"
                alt="Logo DISPUSIP">

            <h3>LOGIN ADMIN</h3>

        </div>

        <div class="login-body">

            <?php if ($error != ""): ?>

                <div class="alert alert-danger">

                    <?= $error; ?>

                </div>

            <?php endif; ?>

            <form
                action="proses-login.php"
                method="POST">

                <div class="mb-3">

                    <label class="form-label">

                        Username

                    </label>

                    <input
                        type="text"
                        name="username"
                        class="form-control"
                        required>

                </div>

                <div class="mb-3">

                    <label class="form-label">

                        Password

                    </label>

                    <input
                        type="password"
                        name="password"
                        class="form-control"
                        required>

                </div>

                <button
                    class="btn btn-primary w-100">

                    Login

                </button>

            </form>

            <div class="text-center mt-3">

                <a href="../index.php">

                    ← Kembali ke Website

                </a>

            </div>

        </div>

    </div>

</body>

</html>