<?php
$pageTitle = "Contact Admin";
require_once 'sidebar.php';

$uid = $_SESSION['user_id'];

$adminRes = mysqli_query($conn, "SELECT id FROM users WHERE role='admin' LIMIT 1");
$admin = mysqli_fetch_assoc($adminRes);
$adminId = $admin['id'] ?? 0;

if ($_SERVER['REQUEST_METHOD'] === 'POST' && $adminId) {
    $subject = clean($conn, $_POST['subject']);
    $message = clean($conn, $_POST['message']);
    
    if ($subject && $message) {
        mysqli_query($conn, "INSERT INTO messages (sender_id, receiver_id, subject, message) 
                             VALUES ($uid, $adminId, '$subject', '$message')");
        redirect(BASE_URL.'/user/contact-admin.php', 'Message sent to admin. You will get a reply soon.');
    } else {
        $error = "Please fill all fields.";
    }
}

$prefillSubject = '';
if (isset($_GET['hall_id'])) {
    $hid = (int)$_GET['hall_id'];
    $h = mysqli_query($conn, "SELECT hall_name FROM halls WHERE id=$hid");
    if ($row = mysqli_fetch_assoc($h)) {
        $prefillSubject = "Inquiry about " . $row['hall_name'];
    }
}
?>

<div class="page-header">
    <h1>Contact Super Admin</h1>
</div>

<?php showFlash(); ?>
<?php if (!empty($error)): ?>
    <div class="alert alert-danger"><?php echo $error; ?></div>
<?php endif; ?>

<div class="alert alert-info">
    <div>
        <strong>Direct Contact:</strong> Send your inquiry, booking help requests, or special requirements directly to the Super Admin. 
        You'll receive a reply through the messaging system.
    </div>
</div>

<div class="split-layout narrow">
    <div class="dashboard-card">
        <h2 class="full">📨 Send Message</h2>
        <form method="POST">
            <div class="form-group">
                <label>Subject *</label>
                <input type="text" name="subject" required value="<?php echo htmlspecialchars($prefillSubject); ?>" placeholder="Booking inquiry, Hall question, etc.">
            </div>
            <div class="form-group">
                <label>Your Message *</label>
                <textarea name="message" rows="8" required placeholder="Type your message here..."></textarea>
            </div>
            <button type="submit" class="btn" style="width:100%;">Send Message to Admin</button>
        </form>
    </div>
    
    <div class="dashboard-card">
        <h2 class="full">Why Contact Admin?</h2>
        <ul style="list-style:none; padding:0;">
            <li style="padding:12px 0; border-bottom:1px solid var(--cream-dark); display:flex; align-items:center; gap:10px;">
                <span style="color:var(--bronze); font-size:18px;">✦</span> Booking assistance
            </li>
            <li style="padding:12px 0; border-bottom:1px solid var(--cream-dark); display:flex; align-items:center; gap:10px;">
                <span style="color:var(--bronze); font-size:18px;">✦</span> Hall availability questions
            </li>
            <li style="padding:12px 0; border-bottom:1px solid var(--cream-dark); display:flex; align-items:center; gap:10px;">
                <span style="color:var(--bronze); font-size:18px;">✦</span> Pricing &amp; payment info
            </li>
            <li style="padding:12px 0; border-bottom:1px solid var(--cream-dark); display:flex; align-items:center; gap:10px;">
                <span style="color:var(--bronze); font-size:18px;">✦</span> Dish customization
            </li>
            <li style="padding:12px 0; display:flex; align-items:center; gap:10px;">
                <span style="color:var(--bronze); font-size:18px;">✦</span> Complaints &amp; suggestions
            </li>
        </ul>
        <div style="background:var(--cream); padding:18px; border-radius:4px; margin-top:20px; border-left:3px solid var(--bronze);">
            <p style="font-size:13px; color:#666; font-style:italic;">
                "The Super Admin handles all final bookings. Vendors only manage their hall data (dishes, dates, images)."
            </p>
        </div>
    </div>
</div>

</main></div></body></html>
