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

if(isset($_POST['login'])){

    $username = mysqli_real_escape_string($conn,$_POST['username']);
    $password = md5($_POST['password']);

    $cek = mysqli_query($conn,"SELECT * FROM admin 
    WHERE username='$username' 
    AND password='$password'");

    if(mysqli_num_rows($cek) > 0){

        $_SESSION['admin'] = true;
        $_SESSION['username'] = $username;

        echo "
        <script>
        alert('Login berhasil');
        window.location='admin/dashboard.php';
        </script>
        ";

    }else{

        echo "
        <script>
        alert('Username atau Password salah');
        </script>
        ";

    }

}
?>

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

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

<title>Login Admin</title>

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

<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css">

<style>

body{
    background:#f4f6f9;
    font-family:'Segoe UI',sans-serif;
}

/* Navbar */
.navbar{
    background:linear-gradient(45deg,#0d6efd,#0b5ed7);
}

/* Hero */
.hero{
    min-height:100vh;
    display:flex;
    align-items:center;
    padding:50px 0;
}

.login-card{
    background:white;
    border:none;
    border-radius:25px;
    overflow:hidden;
    box-shadow:0 10px 30px rgba(0,0,0,0.1);
}

.left-side{
    background:linear-gradient(135deg,#0d6efd,#0b5ed7);
    color:white;
    padding:50px;
    height:100%;
    display:flex;
    flex-direction:column;
    justify-content:center;
}

.left-side h1{
    font-weight:700;
    line-height:1.3;
}

.left-side p{
    opacity:0.9;
}

.right-side{
    padding:50px;
}

.form-control{
    height:50px;
    border-radius:12px;
}

.btn-login{
    height:50px;
    border-radius:12px;
    font-weight:600;
    font-size:16px;
}

.logo-school{
    width:90px;
    margin-bottom:20px;
}

.back-home{
    text-decoration:none;
    color:white;
}

.back-home:hover{
    color:#ddd;
}

@media(max-width:768px){

    .left-side{
        display:none;
    }

    .right-side{
        padding:30px;
    }

}

</style>

</head>
<body>

<!-- Navbar -->
<nav class="navbar navbar-dark shadow-sm">
<div class="container">

<a class="navbar-brand fw-bold" href="index.php">
SPMB 2026-2027
</a>

<a href="index.php" class="back-home">
<i class="fa fa-arrow-left"></i> Kembali
</a>

</div>
</nav>

<!-- Hero -->
<section class="hero">

<div class="container">

<div class="row justify-content-center">

<div class="col-lg-10">

<div class="card login-card">

<div class="row g-0">

<!-- Left -->
<div class="col-md-6">

<div class="left-side">

<h5>🎓 Selamat Datang</h5>

<h1>
Portal SPMB<br>
SMKN 1 CIKAUM
</h1>

<p class="mt-3">
Silahkan login untuk mengakses dashboard admin
dan mengelola data pendaftaran peserta didik baru.
</p>

<div class="mt-4">

<h6>
<i class="fa fa-school"></i>
SMKN 1 CIKAUM
</h6>

<p class="small">
Mewujudkan generasi unggul dan siap kerja.
</p>

</div>

</div>

</div>

<!-- Right -->
<div class="col-md-6">

<div class="right-side">

<div class="text-center mb-4">

<img src="assets/img/logo.png"
class="logo-school"
alt="Logo">

<h3 class="fw-bold">
Login Admin
</h3>

<p class="text-muted">
Masukkan username dan password
</p>

</div>

<form method="POST">

<div class="mb-3">

<label class="form-label">
Username
</label>

<div class="input-group">

<span class="input-group-text">
<i class="fa fa-user"></i>
</span>

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

</div>

</div>

<div class="mb-4">

<label class="form-label">
Password
</label>

<div class="input-group">

<span class="input-group-text">
<i class="fa fa-lock"></i>
</span>

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

</div>

</div>

<button type="submit"
name="login"
class="btn btn-primary w-100 btn-login shadow">

<i class="fa fa-sign-in-alt"></i>
Login Sekarang

</button>

</form>

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

<a href="index.php"
class="text-decoration-none">

← Kembali ke halaman utama

</a>

</div>

</div>

</div>

</div>

</div>

</div>

</div>

</section>

</body>
</html>