<?php
session_start();
error_reporting(0);
include('includes/config.php');

if ($_SESSION['alogin'] != '') {
    $_SESSION['alogin'] = '';
}

if (isset($_POST['login'])) {
    $username = $_POST['username'];
    $password = md5($_POST['password']);

    $sql = "SELECT UserName, Password FROM admin WHERE UserName = :username AND Password = :password";
    $query = $dbh->prepare($sql);
    $query->bindParam(':username', $username, PDO::PARAM_STR);
    $query->bindParam(':password', $password, PDO::PARAM_STR);
    $query->execute();

    if ($query->rowCount() > 0) {
        $_SESSION['alogin'] = $username;
        echo "<script type='text/javascript'>document.location = 'admin/dashboard.php';</script>";
    } else {
        echo "<script>alert('Invalid login details');</script>";
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Admin Login | Library</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" type="image/x-icon" href="<?php echo $_SESSION['logo']; ?>">

  <!-- Bootstrap 5 -->
  <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
  <!-- Font Awesome -->
  <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" rel="stylesheet">

  <style>
    body {
      /* background: #ffffff; */
        background: #fffcffff;
      font-family: 'Segoe UI', sans-serif;
    }
    .login-wrapper {
      min-height: 100vh;
      display: flex;
      align-items: center;
      justify-content: center;
      padding: 20px;
    }
    .login-box {
      background: #fff;
      border-radius: 15px;
      /* box-shadow: 0 8px 20px rgba(0,0,0,0.1); */
       box-shadow: 0 8px 20px #b63f78ff;
      overflow: hidden;
      width: 100%;
      max-width: 800px;
      display: flex;
      flex-direction: row;
    }
    .promo-side {
      flex: 1;
      overflow: hidden;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .promo-side img {
      width: 100%;
      height: 100%;
      object-fit: cover;
      display: block;
    }
    .form-side {
      padding: 40px 30px;
      flex: 1;
    }
    .form-side h3 {
      font-weight: bold;
      /* color: #5e60e9; */
 color: #e95ea1;
      margin-bottom: 25px;
      text-align: center;
    }
    .btn-login {
      width: 100%;
      border-radius: 25px;
    }
    @media (max-width: 768px) {
      .login-box {
        flex-direction: column;
        max-width: 90%;
      }
      .promo-side {
        padding: 20px;
      }
      .form-side {
        padding: 25px;
      }
    }
  </style>
</head>

<body>
<div class="container-fluid login-wrapper">
  <div class="login-box">
    <!-- Left Side Image -->
    <div class="promo-side p-0">
      <img src="assets/img/lms_img5.jpg" alt="Admin Login Image">
    </div>

    <!-- Right Side Login Form -->
    <div class="form-side">
      <h3><i class="fas fa-user-shield me-2"></i>Admin Login</h3>
      <form method="post">
        <div class="mb-3">
          <label for="username" class="form-label">Username</label>
          <input type="text" class="form-control" name="username" required autocomplete="off">
        </div>

        <div class="mb-3">
          <label for="password" class="form-label">Password</label>
          <input type="password" class="form-control" name="password" required autocomplete="off">
        </div>

        <button type="submit" name="login" class="btn btn-primary btn-login mt-3">
          Login <i class="fas fa-sign-in-alt ms-2"></i>
        </button>
      </form>
    </div>
  </div>
</div>

<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
