<?php
$pageTitle = "My Bookings";
require_once 'sidebar.php';

if (!$myHall) {
    redirect(BASE_URL.'/vendor/my-hall.php', 'Please add your hall first.', 'info');
}

$hid = $myHall['id'];
$bookings = mysqli_query($conn, "SELECT b.*, u.name as user_name, u.phone as user_phone, u.email as user_email 
                                  FROM bookings b JOIN users u ON b.user_id=u.id 
                                  WHERE b.hall_id=$hid ORDER BY b.created_at DESC");
?>

<div class="page-header">
    <h1>My Hall Bookings</h1>
    <p style="color:#888; font-size:14px;"><?php echo mysqli_num_rows($bookings); ?> total bookings</p>
</div>

<?php showFlash(); ?>

<div class="alert alert-info">
    <div>
        <strong>Note:</strong> All bookings are managed (confirmed/cancelled) by the Super Admin. 
        You can view all bookings for your hall here.
    </div>
</div>

<div class="table-wrapper">
    <table>
        <thead>
            <tr>
                <th>#</th>
                <th>User</th>
                <th>Contact</th>
                <th>Booking Date</th>
                <th>Guests</th>
                <th>Amount</th>
                <th>Status</th>
                <th>Booked On</th>
            </tr>
        </thead>
        <tbody>
            <?php if (mysqli_num_rows($bookings) > 0): ?>
                <?php while ($b = mysqli_fetch_assoc($bookings)): ?>
                    <tr>
                        <td>#<?php echo $b['id']; ?></td>
                        <td><strong><?php echo htmlspecialchars($b['user_name']); ?></strong></td>
                        <td><small><?php echo htmlspecialchars($b['user_email']); ?><br>
                            <?php echo htmlspecialchars($b['user_phone']); ?></small></td>
                        <td style="font-family:var(--font-display); color:var(--maroon);"><?php echo date('d M Y', strtotime($b['booking_date'])); ?></td>
                        <td style="text-align:center;"><?php echo $b['guests']; ?></td>
                        <td style="color:var(--bronze); font-weight:600;">Rs. <?php echo number_format($b['total_amount']); ?></td>
                        <td><span class="badge badge-<?php echo $b['status']; ?>"><?php echo ucfirst($b['status']); ?></span></td>
                        <td><small><?php echo date('d M Y', strtotime($b['created_at'])); ?></small></td>
                    </tr>
                <?php endwhile; ?>
            <?php else: ?>
                <tr><td colspan="8" style="text-align:center; padding:40px; color:#888;">
                    <div style="font-size:40px; color:var(--bronze); margin-bottom:10px;">❦</div>
                    No bookings yet.
                </td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

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