<?php
session_start();
include "../config/koneksi.php";

if(isset($_POST['login'])){
    $user = mysqli_real_escape_string($conn, $_POST['username']);
    $pass = md5($_POST['password']);

    $cek = mysqli_query($conn,"SELECT * FROM admin WHERE username='$user' AND password='$pass'");
    if(mysqli_num_rows($cek)>0){
        $_SESSION['admin'] = true;
        header("Location: index.php");
        exit;
    } else {
        $error = "Username atau Password salah!";
    }
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Login Admin MTCNA</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

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

<style>
body {
    height: 100vh;
    background: linear-gradient(rgba(13,110,253,0.7), rgba(0,198,255,0.7)),
                url('../assets/lab.jpeg');
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Card Login */
.login-box {
    width: 350px;
    padding: 30px;
    border-radius: 15px;
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    color: white;
    box-shadow: 0 8px 32px rgba(0,0,0,0.3);
}

/* Logo */
.logo {
    width: 80px;
    margin-bottom: 10px;
}

/* Input */
.form-control {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
}

.form-control::placeholder {
    color: #ddd;
}

/* Button */
.btn-login {
    background: #0d6efd;
    border: none;
}

.btn-login:hover {
    background: #0b5ed7;
}
</style>

</head>

<body>

<div class="login-box text-center">

    <img src="../assets/logo.png" class="logo">

    <h4 class="mb-3">Admin MTCNA</h4>

    <?php if(isset($error)) { ?>
        <div class="alert alert-danger"><?= $error ?></div>
    <?php } ?>

    <form method="POST">
        <input type="text" name="username" class="form-control mb-3" placeholder="Username" required>
        <input type="password" name="password" class="form-control mb-3" placeholder="Password" required>

        <button name="login" class="btn btn-login w-100">Login</button>
    </form>

    <small class="d-block mt-3">SMK Yadika Natar</small>

</div>

</body>
</html>