<?php
require_once __DIR__ . '/config/session.php';
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/config/helpers.php';

// Check if user is logged in
if (!isLoggedIn()) {
    header("Location: login.php");
    exit();
}

$userId = getCurrentUserId();
$currentUser = getCurrentUser();
$dbHelper = new DBHelper($conn);

// Get user details
$userDetails = $dbHelper->getUserById($userId);

// Get user reservations from database
$userReservations = [];
try {
    $userReservations = $dbHelper->getUserReservations($userId);
    if (!is_array($userReservations)) {
        $userReservations = [];
    }
} catch (Exception $e) {
    error_log("Error fetching reservations: " . $e->getMessage());
    $userReservations = [];
}

// Get user service reservations
$serviceReservations = [];
try {
    $sql = "SELECT sr.id, sr.user_id, sr.facility_id, sr.service_start_date, sr.service_end_date, 
                   sr.number_of_guests, sr.service_price, sr.total_price, sr.status, sr.special_requests,
                   sr.created_at, sr.updated_at,
                   f.id as facility_id_check, f.name as facility_name, f.icon, f.description, f.image_url
            FROM service_reservations sr
            JOIN facilities f ON sr.facility_id = f.id
            WHERE sr.user_id = ?
            ORDER BY sr.service_start_date DESC";
    $stmt = $conn->prepare($sql);
    if (!$stmt) {
        throw new Exception("Prepare failed: " . $conn->error);
    }
    $stmt->bind_param('i', $userId);
    $stmt->execute();
    $result = $stmt->get_result();
    $serviceReservations = $result ? $result->fetch_all(MYSQLI_ASSOC) : [];
} catch (Exception $e) {
    error_log("Error fetching service reservations: " . $e->getMessage());
    $serviceReservations = [];
}

// Get dashboard statistics from actual data
$totalReservations = is_array($userReservations) ? count($userReservations) : 0;
$activeReservations = 0;
$totalSpent = 0;

if (is_array($userReservations) && count($userReservations) > 0) {
    foreach ($userReservations as $res) {
        // Count active reservations
        if (isset($res['status']) && in_array($res['status'], ['pending', 'confirmed', 'checked_in'])) {
            $activeReservations++;
        }
        // Calculate total spent
        if (isset($res['total_price']) && (is_null($res['status']) || $res['status'] !== 'cancelled')) {
            $totalSpent += (float)$res['total_price'];
        }
    }
}

$totalServices = is_array($serviceReservations) ? count($serviceReservations) : 0;

// Only display room reservations that have essential reservation + room data.
$displayRoomReservations = [];
if (is_array($userReservations) && !empty($userReservations)) {
    $displayRoomReservations = array_values(array_filter($userReservations, function ($res) {
        return !empty($res['id'])
            && !empty($res['check_in_date'])
            && !empty($res['check_out_date'])
            && !empty($res['room_type'])
            && !empty($res['room_number']);
    }));
}

// Determine active section (default to overview)
$activeSection = isset($_GET['section']) ? htmlspecialchars($_GET['section']) : 'overview';

// Ensure data is always available
if (empty($userReservations)) {
    $userReservations = [];
}
if (empty($serviceReservations)) {
    $serviceReservations = [];
}
?>

<!DOCTYPE html>
<html lang="en">

<head>
    <title>My Dashboard - Almaris Hotel Booking</title>
    <link rel="icon" href="images/icon.webp" type="image/gif" sizes="16x16">
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
    <meta content="Customer Dashboard - Manage bookings and reservations" name="description">
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="css/plugins.css" rel="stylesheet" type="text/css">
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <link href="css/coloring.css" rel="stylesheet" type="text/css">
    <link id="colors" href="css/colors/scheme-01.css" rel="stylesheet" type="text/css">
    <link href="css/dashboard.css" rel="stylesheet" type="text/css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
    </style>
</head>

<body>

    <div class="dashboard-container">
        <!-- Sidebar Navigation -->
        <aside class="dashboard-sidebar">
            <div class="sidebar-header">
                <button class="sidebar-toggle d-lg-none" id="sidebarToggle">
                    <i class="fas fa-times"></i>
                </button>
                <h5 class="sidebar-title">Menu</h5>
            </div>

            <nav class="sidebar-nav">
                <ul class="nav-list">
                    <li class="nav-item">
                        <a href="?section=overview" class="nav-link <?php echo $activeSection === 'overview' ? 'active' : ''; ?>">
                            <i class="fas fa-chart-pie"></i>
                            <span>Overview</span>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="?section=reservations" class="nav-link <?php echo $activeSection === 'reservations' ? 'active' : ''; ?>">
                            <i class="fas fa-door-open"></i>
                            <span>Room Reservations</span>
                            <?php if ($activeReservations > 0): ?>
                                <span class="badge-count"><?php echo $activeReservations; ?></span>
                            <?php endif; ?>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="?section=services" class="nav-link <?php echo $activeSection === 'services' ? 'active' : ''; ?>">
                            <i class="fas fa-concierge-bell"></i>
                            <span>Service Reservations</span>
                            <?php if ($totalServices > 0): ?>
                                <span class="badge-count"><?php echo $totalServices; ?></span>
                            <?php endif; ?>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="?section=profile" class="nav-link <?php echo $activeSection === 'profile' ? 'active' : ''; ?>">
                            <i class="fas fa-user-circle"></i>
                            <span>My Profile</span>
                        </a>
                    </li>
                </ul>
            </nav>

            <div class="sidebar-footer">
                <a href="logout.php" class="btn-logout">
                    <i class="fas fa-sign-out-alt"></i>
                    <span>Logout</span>
                </a>
            </div>
        </aside>

        <!-- Sidebar Overlay (Mobile) -->
        <div class="sidebar-overlay" id="sidebarOverlay"></div>

        <!-- Main Content -->
        <main class="dashboard-content">
            <!-- Header -->
            <div class="dashboard-header">
                <div class="header-top">
                    <button class="toggle-sidebar d-lg-none" id="toggleSidebar">
                        <i class="fas fa-bars"></i>
                    </button>
                    <h1 class="page-title">
                        <?php 
                        switch ($activeSection) {
                            case 'overview': echo 'Dashboard Overview'; break;
                            case 'reservations': echo 'Room Reservations'; break;
                            case 'services': echo 'Service Reservations'; break;
                            case 'profile': echo 'My Profile'; break;
                            default: echo 'Dashboard';
                        }
                        ?>
                    </h1>
                    <div class="user-welcome">
                        <p>Welcome, <strong><?php echo htmlspecialchars($userDetails['first_name']); ?></strong>!</p>
                    </div>
                </div>
            </div>

            <!-- Content Sections -->
            <div class="content-wrapper">

                <!-- OVERVIEW SECTION -->
                <?php if ($activeSection === 'overview'): ?>
                <section class="dashboard-section overview-section">
                    <!-- Statistics Cards -->
                    <div class="stats-grid">
                        <div class="stat-card">
                            <div class="stat-icon bg-primary">
                                <i class="fas fa-door-open"></i>
                            </div>
                            <div class="stat-content">
                                <p class="stat-label">Total Reservations</p>
                                <h3 class="stat-value"><?php echo $totalReservations; ?></h3>
                            </div>
                        </div>

                        <div class="stat-card">
                            <div class="stat-icon bg-success">
                                <i class="fas fa-check-circle"></i>
                            </div>
                            <div class="stat-content">
                                <p class="stat-label">Active Bookings</p>
                                <h3 class="stat-value"><?php echo $activeReservations; ?></h3>
                            </div>
                        </div>

                        <div class="stat-card">
                            <div class="stat-icon bg-info">
                                <i class="fas fa-concierge-bell"></i>
                            </div>
                            <div class="stat-content">
                                <p class="stat-label">Service Bookings</p>
                                <h3 class="stat-value"><?php echo $totalServices; ?></h3>
                            </div>
                        </div>

                        <div class="stat-card">
                            <div class="stat-icon bg-warning">
                                <i class="fas fa-wallet"></i>
                            </div>
                            <div class="stat-content">
                                <p class="stat-label">Total Spent</p>
                                <h3 class="stat-value">$<?php echo number_format($totalSpent, 2); ?></h3>
                            </div>
                        </div>
                    </div>

                    <!-- Quick Actions -->
                    <div class="quick-actions">
                        <h3>Quick Actions</h3>
                        <div class="actions-grid">
                            <a href="reservation.php" class="action-btn">
                                <i class="fas fa-plus-circle"></i>
                                <span>New Room Booking</span>
                            </a>
                            <a href="?section=reservations" class="action-btn">
                                <i class="fas fa-list"></i>
                                <span>View Reservations</span>
                            </a>
                            <a href="?section=services" class="action-btn">
                                <i class="fas fa-spa"></i>
                                <span>Book Service</span>
                            </a>
                            <a href="?section=profile" class="action-btn">
                                <i class="fas fa-edit"></i>
                                <span>Edit Profile</span>
                            </a>
                        </div>
                    </div>

                    <!-- Recent Reservations -->
                    <?php if (!empty($displayRoomReservations)): ?>
                    <div class="recent-section">
                        <h3>Recent Room Reservations</h3>
                        <div class="reservations-list">
                            <?php foreach (array_slice($displayRoomReservations, 0, 3) as $res): ?>
                            <?php
                                $recentRoomImage = !empty($res['image_url']) ? (string)$res['image_url'] : 'images/room/1.webp';
                                $recentRoomType = !empty($res['room_type']) ? (string)$res['room_type'] : 'Room';
                                $recentRoomNumber = !empty($res['room_number']) ? (string)$res['room_number'] : 'N/A';
                                $recentCheckIn = !empty($res['check_in_date']) ? date('M d, Y', strtotime((string)$res['check_in_date'])) : 'N/A';
                                $recentCheckOut = !empty($res['check_out_date']) ? date('M d, Y', strtotime((string)$res['check_out_date'])) : 'N/A';
                                $recentGuests = isset($res['number_of_guests']) ? (int)$res['number_of_guests'] : 0;
                                $recentStatus = !empty($res['status']) ? (string)$res['status'] : 'pending';
                                $recentTotal = isset($res['total_price']) ? (float)$res['total_price'] : 0.0;
                            ?>
                            <div class="reservation-item">
                                <div class="res-image">
                                    <img src="<?php echo htmlspecialchars($recentRoomImage, ENT_QUOTES, 'UTF-8'); ?>" alt="<?php echo htmlspecialchars($recentRoomType, ENT_QUOTES, 'UTF-8'); ?>">
                                </div>
                                <div class="res-details">
                                    <h5><?php echo htmlspecialchars($recentRoomType, ENT_QUOTES, 'UTF-8'); ?> - <?php echo htmlspecialchars($recentRoomNumber, ENT_QUOTES, 'UTF-8'); ?></h5>
                                    <p class="res-dates">
                                        <i class="fas fa-calendar"></i>
                                        <?php echo htmlspecialchars($recentCheckIn, ENT_QUOTES, 'UTF-8'); ?> to <?php echo htmlspecialchars($recentCheckOut, ENT_QUOTES, 'UTF-8'); ?>
                                    </p>
                                    <p class="res-guests">
                                        <i class="fas fa-users"></i>
                                        <?php echo $recentGuests; ?> Guest(s)
                                    </p>
                                </div>
                                <div class="res-status">
                                    <span class="badge badge-<?php echo htmlspecialchars($recentStatus, ENT_QUOTES, 'UTF-8'); ?>">
                                        <?php echo htmlspecialchars(ucfirst($recentStatus), ENT_QUOTES, 'UTF-8'); ?>
                                    </span>
                                    <p class="res-price">$<?php echo number_format($recentTotal, 2); ?></p>
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                        <div class="text-center mt-4">
                            <a href="?section=reservations" class="btn btn-outline-primary">View All Reservations</a>
                        </div>
                    </div>
                    <?php endif; ?>
                </section>
                <?php endif; ?>

                <!-- RESERVATIONS SECTION -->
                <?php if ($activeSection === 'reservations'): ?>
                <section class="dashboard-section reservations-section">
                    <div class="section-action-bar">
                        <div class="section-action-copy">
                            <h3>Manage Room Reservations</h3>
                            <p>Create a new booking or review your existing room reservations.</p>
                        </div>
                        <div class="section-action-buttons">
                            <a href="reservation.php?reservation_type=room" class="btn btn-primary">
                                <i class="fas fa-plus-circle"></i> New Room Reservation
                            </a>
                            <a href="rooms.php" class="btn btn-outline-primary">
                                <i class="fas fa-bed"></i> Browse Rooms
                            </a>
                        </div>
                    </div>
                    <?php if (!empty($displayRoomReservations)): ?>
                    <div class="reservations-container">
                        <?php foreach ($displayRoomReservations as $res): ?>
                            <?php 
                            // Ensure all required fields are present
                            $room_type = isset($res['room_type']) ? htmlspecialchars($res['room_type']) : 'Room';
                            $room_number = isset($res['room_number']) ? htmlspecialchars($res['room_number']) : 'N/A';
                            $image_url = isset($res['image_url']) && !empty($res['image_url']) ? htmlspecialchars($res['image_url']) : 'images/room/default.webp';
                            $check_in = isset($res['check_in_date']) ? date('M d, Y', strtotime($res['check_in_date'])) : 'N/A';
                            $check_out = isset($res['check_out_date']) ? date('M d, Y', strtotime($res['check_out_date'])) : 'N/A';
                            $guests = isset($res['number_of_guests']) ? intval($res['number_of_guests']) : 1;
                            $total_price = isset($res['total_price']) ? number_format(floatval($res['total_price']), 2) : '0.00';
                            $status = isset($res['status']) ? htmlspecialchars($res['status']) : 'pending';
                            $payment_status = isset($res['payment_status']) ? htmlspecialchars($res['payment_status']) : 'unpaid';
                            $special_requests = isset($res['special_requests']) ? htmlspecialchars($res['special_requests']) : '';
                            $res_id = isset($res['id']) ? intval($res['id']) : 0;
                            ?>
                        <div class="reservation-card">
                            <div class="card-header">
                                <h4><?php echo $room_type; ?></h4>
                                <span class="badge badge-<?php echo $status; ?>">
                                    <?php echo ucfirst($status); ?>
                                </span>
                            </div>
                            <div class="card-body">
                                <div class="room-image">
                                    <img src="<?php echo $image_url; ?>" alt="<?php echo $room_type; ?>">
                                </div>
                                <div class="reservation-details">
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-door-open"></i> Room Number:</span>
                                        <span class="value"><?php echo $room_number; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-calendar-check"></i> Check-in:</span>
                                        <span class="value"><?php echo $check_in; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-calendar-times"></i> Check-out:</span>
                                        <span class="value"><?php echo $check_out; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-users"></i> Guests:</span>
                                        <span class="value"><?php echo $guests; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-credit-card"></i> Total Price:</span>
                                        <span class="value price">$<?php echo $total_price; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-wallet"></i> Payment:</span>
                                        <span class="value payment-<?php echo $payment_status; ?>">
                                            <?php echo ucfirst(str_replace('_', ' ', $payment_status)); ?>
                                        </span>
                                    </div>
                                    <?php if (!empty($special_requests)): ?>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-sticky-note"></i> Special Requests:</span>
                                        <span class="value"><?php echo $special_requests; ?></span>
                                    </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="card-footer">
                                <button class="btn-main" onclick="viewReservationDetails(<?php echo $res_id; ?>)">
                                    <i class="fas fa-info-circle"></i> View Details
                                </button>
                                <?php if ($status === 'pending' || $status === 'confirmed'): ?>
                                <button class="btn btn-sm btn-danger" onclick="cancelReservation(<?php echo $res_id; ?>)">
                                    <i class="fas fa-times"></i> Cancel
                                </button>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                    </div>
                    <?php else: ?>
                    <div class="empty-state">
                        <div class="empty-icon">
                            <i class="fas fa-door-open"></i>
                        </div>
                        <h3>No Room Reservations</h3>
                        <p>You haven't made any room reservations yet.</p>
                        <a href="booking.php" class="btn btn-primary">
                            <i class="fas fa-plus"></i> Book a Room Now
                        </a>
                    </div>
                    <?php endif; ?>
                </section>
                <?php endif; ?>

                <!-- SERVICES SECTION -->
                <?php if ($activeSection === 'services'): ?>
                <section class="dashboard-section services-section">
                    <div class="section-action-bar">
                        <div class="section-action-copy">
                            <h3>Manage Service Reservations</h3>
                            <p>Add new services to your stay and track service bookings in one place.</p>
                        </div>
                        <div class="section-action-buttons">
                            <a href="reservation.php?reservation_type=service" class="btn btn-primary">
                                <i class="fas fa-plus-circle"></i> Add New Service
                            </a>
                            <a href="facilities.php" class="btn btn-outline-primary">
                                <i class="fas fa-spa"></i> Explore Services
                            </a>
                        </div>
                    </div>
                    <?php if (!empty($serviceReservations)): ?>
                    <div class="services-container">
                        <?php foreach ($serviceReservations as $service): ?>
                            <?php
                            // Ensure all required fields are present
                            $facility_name = isset($service['facility_name']) ? htmlspecialchars($service['facility_name']) : 'Service';
                            $service_start = isset($service['service_start_date']) ? date('M d, Y', strtotime($service['service_start_date'])) : 'N/A';
                            $service_end = isset($service['service_end_date']) ? date('M d, Y', strtotime($service['service_end_date'])) : 'N/A';
                            $service_guests = isset($service['number_of_guests']) ? intval($service['number_of_guests']) : 1;
                            $service_price = isset($service['total_price']) ? number_format(floatval($service['total_price']), 2) : '0.00';
                            $service_status = isset($service['status']) ? htmlspecialchars($service['status']) : 'pending';
                            $service_requests = isset($service['special_requests']) ? htmlspecialchars($service['special_requests']) : '';
                            $service_id = isset($service['id']) ? intval($service['id']) : 0;
                            ?>
                        <div class="service-card">
                            <div class="card-header">
                                <h4><?php echo $facility_name; ?></h4>
                                <span class="badge badge-<?php echo $service_status; ?>">
                                    <?php echo ucfirst($service_status); ?>
                                </span>
                            </div>
                            <div class="card-body">
                                <div class="service-details">
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-calendar-check"></i> Service Start:</span>
                                        <span class="value"><?php echo $service_start; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-calendar-times"></i> Service End:</span>
                                        <span class="value"><?php echo $service_end; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-users"></i> Guests:</span>
                                        <span class="value"><?php echo $service_guests; ?></span>
                                    </div>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-credit-card"></i> Total Price:</span>
                                        <span class="value price">$<?php echo $service_price; ?></span>
                                    </div>
                                    <?php if (!empty($service_requests)): ?>
                                    <div class="detail-item">
                                        <span class="label"><i class="fas fa-sticky-note"></i> Special Requests:</span>
                                        <span class="value"><?php echo $service_requests; ?></span>
                                    </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="card-footer">
                                <button class="btn-main" onclick="viewServiceDetails(<?php echo $service_id; ?>)">
                                    <i class="fas fa-info-circle"></i> View Details
                                </button>
                                <?php if ($service_status === 'pending'): ?>
                                <button class="btn btn-sm btn-danger" onclick="cancelService(<?php echo $service_id; ?>)">
                                    <i class="fas fa-times"></i> Cancel
                                </button>
                                <?php endif; ?>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                    <?php else: ?>
                    <div class="empty-state">
                        <div class="empty-icon">
                            <i class="fas fa-concierge-bell"></i>
                        </div>
                        <h3>No Service Reservations</h3>
                        <p>You haven't booked any services yet. Explore our facilities!</p>
                        <a href="facilities.php" class="btn btn-primary">
                            <i class="fas fa-spa"></i> Browse Services
                        </a>
                    </div>
                    <?php endif; ?>
                </section>
                <?php endif; ?>

                <!-- PROFILE SECTION -->
                <?php if ($activeSection === 'profile'): ?>
                <section class="dashboard-section profile-section">
                    <div class="profile-header">
                        <div class="profile-avatar">
                            <div class="avatar-circle">
                                <?php 
                                $initials = strtoupper(substr($userDetails['first_name'], 0, 1) . substr($userDetails['last_name'], 0, 1)); 
                                echo $initials;
                                ?>
                            </div>
                        </div>
                        <div class="profile-info">
                            <h2><?php echo htmlspecialchars($userDetails['first_name'] . ' ' . $userDetails['last_name']); ?></h2>
                            <p><?php echo htmlspecialchars($userDetails['email']); ?></p>
                            <p class="member-since">Member since <?php echo date('F Y', strtotime($userDetails['created_at'])); ?></p>
                        </div>
                    </div>

                    <form id="profileForm" class="profile-form" method="POST" action="api/update-profile.php">
                        <div class="form-group">
                            <label for="firstName">First Name</label>
                            <input type="text" id="firstName" name="first_name" value="<?php echo htmlspecialchars($userDetails['first_name']); ?>" required>
                        </div>
                        <div class="form-group">
                            <label for="lastName">Last Name</label>
                            <input type="text" id="lastName" name="last_name" value="<?php echo htmlspecialchars($userDetails['last_name']); ?>" required>
                        </div>
                        <div class="form-group">
                            <label for="email">Email</label>
                            <input type="email" id="email" value="<?php echo htmlspecialchars($userDetails['email']); ?>" disabled>
                            <small>Email cannot be changed</small>
                        </div>
                        <div class="form-group">
                            <label for="phone">Phone</label>
                            <input type="tel" id="phone" name="phone" value="<?php echo htmlspecialchars($userDetails['phone'] ?? ''); ?>">
                        </div>
                        <div class="form-group">
                            <label for="address">Address</label>
                            <input type="text" id="address" name="address" value="<?php echo htmlspecialchars($userDetails['address'] ?? ''); ?>">
                        </div>
                        <div class="form-row">
                            <div class="form-group">
                                <label for="city">City</label>
                                <input type="text" id="city" name="city" value="<?php echo htmlspecialchars($userDetails['city'] ?? ''); ?>">
                            </div>
                            <div class="form-group">
                                <label for="country">Country</label>
                                <input type="text" id="country" name="country" value="<?php echo htmlspecialchars($userDetails['country'] ?? ''); ?>">
                            </div>
                            <div class="form-group">
                                <label for="postal_code">Postal Code</label>
                                <input type="text" id="postal_code" name="postal_code" value="<?php echo htmlspecialchars($userDetails['postal_code'] ?? ''); ?>">
                            </div>
                        </div>
                        <div class="form-actions">
                            <button type="submit" class="btn btn-primary">Save Changes</button>
                            <button type="reset" class="btn btn-secondary">Reset</button>
                        </div>
                    </form>
                </section>
                <?php endif; ?>

            </div>
        </main>
    </div>


    <!-- Scripts -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="js/dashboard.js"></script>
    <script>
        // Toggle sidebar on mobile
        document.getElementById('toggleSidebar')?.addEventListener('click', function() {
            document.querySelector('.dashboard-sidebar').classList.add('active');
            document.getElementById('sidebarOverlay').classList.add('active');
        });

        document.getElementById('sidebarToggle')?.addEventListener('click', function() {
            document.querySelector('.dashboard-sidebar').classList.remove('active');
            document.getElementById('sidebarOverlay').classList.remove('active');
        });

        document.getElementById('sidebarOverlay')?.addEventListener('click', function() {
            document.querySelector('.dashboard-sidebar').classList.remove('active');
            this.classList.remove('active');
        });

        // Action handlers are managed in js/dashboard.js
    </script>
</body>

</html>
