<?php
session_start();
$login_error = false;

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $user = $_POST['username'];
    $pass = $_POST['password'];

    if ($user === '用户名' && $pass === '密码') {
        $_SESSION['logged_in'] = true;
        header("Location: index.php");
        exit;
    } else {
        $login_error = true;
    }
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>登录 - 账单管理系统</title>
  <link href="assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/sweetalert2.min.css" rel="stylesheet">
    <script src="assets/js/sweetalert2.all.min.js"></script>
  <style>
    body {
      background-color: #042975;
      min-height: 100vh;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .login-card {
      max-width: 400px;
      width: 100%;
    }
  </style>
</head>
<body>
<div class="card login-card shadow-lg p-4">
  <h3 class="text-center mb-4">账单管理系统</h3>
  <form method="post">
    <div class="mb-3">
      <label class="form-label">用户名</label>
      <input type="text" name="username" class="form-control" required>
    </div>
    <div class="mb-3">
      <label class="form-label">密码</label>
      <input type="password" name="password" class="form-control" required>
    </div>
    <div class="d-grid">
      <button type="submit" class="btn btn-primary">登录</button>
    </div>
  </form>
  <div class="text-center mt-3 text-muted">
    <!--<small>默认账号：etotakeo / ng057720</small><br>-->
    <small>© <?= date('Y') ?> </small>
  </div>
</div>

<?php if ($login_error): ?>
<script>
  Swal.fire({
    icon: 'error',
    title: '登录失败',
    text: '用户名或密码错误，请重试',
    confirmButtonText: '确定'
  });
</script>
<?php endif; ?>

</body>
</html>
