<?php
session_start();
include '../config/koneksi.php';
$isLogin = isset($_SESSION['user_id']);
$user = null;
$userNama = '';
if($isLogin){
    $userId = $_SESSION['user_id'];
    $userNama = $_SESSION['user_nama'];
    $q = mysqli_query($conn, "SELECT * FROM user WHERE id=$userId");
    $user = mysqli_fetch_assoc($q);
}
$activePage = 'kontak';
include 'header.php';
// Ambil data user
// Proses kirim pesan
if(isset($_POST['kirim'])){
    $pesan = mysqli_real_escape_string($conn, $_POST['pesan']);
    if($pesan != ''){
        mysqli_query($conn, "INSERT INTO kontak (id_user, nama_user, pesan) VALUES ($userId, '$userNama', '$pesan')");
        echo '<div class=\'alert\' style=\'background:#d4edda;color:#155724;\'>Pesan terkirim!</div><meta http-equiv=\'refresh\' content=\'1;url=kontak.php\' />';
    }
}
?>
<!DOCTYPE html>
<html>
<head>
    <title>Hubungi Kami - Ang Mansion</title>
    <link rel="stylesheet" type="text/css" href="../assets/style_user.css">
</head>
<body>

<div class="section" style="max-width:700px;margin:0 auto 24px auto;">
    <div style="background:#fff;border-radius:12px;padding:18px 24px;box-shadow:0 2px 12px rgba(30,42,120,0.08);margin-bottom:18px;display:flex;flex-direction:column;align-items:center;gap:18px;">
        <div style="font-size:1.5em;font-weight:800;color:#1e2a78;margin-bottom:8px;">Kontak Kami</div>
        <div style="display:flex;align-items:center;gap:32px;flex-wrap:wrap;justify-content:center;width:100%;">
            <div style="font-size:1.1em;color:#1e2a78;font-weight:700;">
                <span style="display:inline-block;width:110px;">Email</span>: <a href="https://mail.google.com/mail/?view=cm&to=Angmansion@gmail.com" target="_blank" style="color:#3a5eff;text-decoration:none;font-weight:800;">Angmansion@gmail.com</a>
            </div>
            <div style="font-size:1.1em;color:#1e2a78;font-weight:700;">
                <span style="display:inline-block;width:110px;">No Telp</span>: <a href="https://wa.me/081229250157" style="color:#3a5eff;text-decoration:none;font-weight:800;">081229250157</a>
            </div>
        </div>
    </div>
</div>

<div class="section">
    <form method="post" style="max-width:700px;margin:0 auto;">
        <textarea name="pesan" placeholder="Ketikkan Pesan..." style="width:100%;height:80px;padding:12px;border-radius:8px;border:1px solid #b0b0b0;font-size:1.1em;resize:vertical;" required></textarea>
        <div style="text-align:right;margin-top:10px;">
            <button type="submit" name="kirim" class="btn">Kirim</button>
        </div>
    </form>
</div>

<div class="section">
    <div class="section-title">Riwayat Pesan Anda</div>
    <div style="max-width:700px;margin:0 auto;">
    <?php
    $q = mysqli_query($conn, "SELECT * FROM kontak WHERE id_user=$userId ORDER BY id DESC");
    while($k = mysqli_fetch_assoc($q)){
        echo '<div style="margin-bottom:18px;padding:12px 18px;border-radius:8px;background:#fff;box-shadow:0 1px 6px rgba(30,42,120,0.07);">';
        echo '<div style="color:#1e2a78;font-weight:700;">Anda:</div>';
        echo '<div style="margin-bottom:6px;color:#333;font-style:italic;">'.htmlspecialchars($k['pesan']).'</div>';
        if($k['balasan']){
            echo '<div style="color:#c00;font-weight:700;">Admin:</div>';
            echo '<div style="color:#1e2a78;">'.htmlspecialchars($k['balasan']).'</div>';
        }
        echo '<div style="font-size:0.9em;color:#888;text-align:right;margin-top:4px;">'.date('d/m/Y H:i', strtotime($k['tanggal'])).'</div>';
        echo '</div>';
    }
    ?>
    </div>
</div>

<div class="footer">
    Copyright &copy; 2025 | Ang Mansion
</div>
</body>
</html> 