<?php include '../config/koneksi.php'; session_start(); ?>
<!DOCTYPE html>
<html>
<head>
    <title>Login - Ang Mansion</title>
    <link rel="stylesheet" type="text/css" href="../assets/style_user.css">
</head>
<body>
<div class="header">
    <div class="logo">
        <img src="../assets/images/LogoAngMansion-Putih.png" alt="Logo" /> AngMansion
    </div>
    <div class="navbar">
        <a href="index.php">Beranda</a>
        <a href="kamar.php">Kamar</a>
        <a href="register.php">Daftar</a>
        <a href="login.php" class="active">Login</a>
    </div>
</div>
<div class="form-auth-container">
    <h2 class="text-center mb-4" style="color:#1e2a78;font-weight:700;">Login User</h2>
    <?php
    if(isset($_GET['register']) && $_GET['register'] == 'success'){
        echo '<div class="alert alert-success text-center">Registrasi berhasil! Silakan login.</div>';
    }
    if(isset($_POST['login'])){
        $email = mysqli_real_escape_string($conn, $_POST['email']);
        $password = $_POST['password'];
        $q = mysqli_query($conn, "SELECT * FROM user WHERE email='$email'");
        if($u = mysqli_fetch_assoc($q)){
            if(password_verify($password, $u['password'])){
                $_SESSION['user_id'] = $u['id'];
                $_SESSION['user_nama'] = $u['nama'];
                header('Location: index.php');
                exit;
            } else {
                echo '<div class="alert alert-danger">Password salah!</div>';
            }
        } else {
            echo '<div class="alert alert-danger">Email tidak ditemukan!</div>';
        }
    }
    ?>
    <form method="post">
        <div class="form-auth-row">
            <label for="email" class="form-label">Email</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email" required>
        </div>
        <div class="form-auth-row">
            <label for="password" class="form-label">Password</label>
            <input type="password" class="form-control" id="password" name="password" placeholder="Password" required>
        </div>
        <button type="submit" class="btn btn-primary w-100" name="login">Login</button>
    </form>
    <div style="background:#e3f0ff;color:#1e2a78;font-weight:600;padding:12px 18px;border-radius:8px;margin-top:22px;text-align:center;font-size:1.08em;box-shadow:0 2px 8px rgba(30,42,120,0.07);">
        Belum punya akun? Silakan klik tab <b>Daftar</b> di pojok kanan atas untuk melakukan registrasi.
    </div>
</div>
</body>
</html> 