<?php
session_start();

$users = json_decode(file_get_contents('users.json'), true);
$error = '';
$success = '';
if (isset($_SESSION['success_message'])) {
    $success = $_SESSION['success_message'];
    unset($_SESSION['success_message']);
}


if (isset($_SESSION['username'])) {
    header("Location: ultimate.php");
    exit;
}

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $username = strtolower(trim($_POST['liff44'] ?? ''));
    $password = $_POST['repan'] ?? '';

    if (isset($users[$username]) && password_verify($password, $users[$username])) {
        $_SESSION['username'] = $username;
        $_SESSION['logged_in'] = true;
        header("Location: ultimate.php");
        exit;
    } else {
        $error = "Username atau password salah!";
    }
}
?>
<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Login akses</title>
  <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@600&family=Poppins&display=swap" rel="stylesheet">
  <style>
    body {
      margin: 0;
      padding: 0;
      height: 100vh;
      background: url('https://files.catbox.moe/2o9lgh.jpg') no-repeat center center fixed;
      background-size: cover;
      display: flex;
      justify-content: center;
      align-items: center;
      font-family: 'Poppins', sans-serif;
    }
    .container {
      background: rgba(0, 0, 0, 0.75);
      padding: 40px;
      border-radius: 20px;
      box-shadow: 0 0 25px #0ff;
      text-align: center;
      width: 100%;
      max-width: 400px;
    }
    .container img {
      width: 80px;
      margin-bottom: 20px;
    }
    h2 {
      font-family: 'Orbitron', sans-serif;
      color: #0ff;
      margin-bottom: 10px;
    }
    .by {
      font-weight: bold;
      margin-bottom: 30px;
      color: #fff;
    }
    input {
      width: 100%;
      padding: 12px;
      margin: 10px 0;
      border: none;
      border-radius: 10px;
      background: #222;
      color: white;
    }
    button {
      width: 100%;
      padding: 12px;
      background: #00f0ff;
      border: none;
      color: black;
      font-weight: bold;
      border-radius: 10px;
      box-shadow: 0 0 10px #0ff, 0 0 20px #0ff inset;
      cursor: pointer;
      transition: 0.3s;
    }
    button:hover {
      background: #0ff;
    }
    .error {
      color: red;
      margin-bottom: 15px;
    }
    .register {
      margin-top: 20px;
    }
    .register a {
      color: #0ff;
      text-decoration: none;
    }
  </style>
</head>
<body>
<?php if ($success): ?>
  <div style="background-color: #d4edda; color: #155724; padding: 10px; margin: 15px auto; width: 90%%; max-width: 400px; border-radius: 5px; text-align: center;">
    <?= htmlspecialchars($success) ?>
  </div>
<?php endif; ?>

  <form method="post" class="container">
    <img src="https://files.catbox.moe/2o9lgh.jpg" alt="icon">
    <h2>Login Panel</h2>
    <div class="by"LIFFXPAN</div>
    <?php if ($error): ?>
      <div class="error"><?= $error ?></div>
    <?php endif; ?>
    <input type="text" name="username" placeholder="Username" required>
    <input type="password" name="password" placeholder="Password" required>
    <button type="submit">Login</button>
    <div class="register">Belum punya akun? <a href="https://wa.me//6283165646254">Chat admin liffstore.id</a></div>
  </form>
</body>
</html>
