<?php
/**
 * RUHONDO BEACH RESORT HMS + POS System
 * View Room Details - FIXED VERSION
 * Developer: JOACHIM'S INNOTECH
 */

// Enable error reporting for debugging
error_reporting(E_ALL);
ini_set('display_errors', 1);

// Calculate the correct path using multiple fallbacks
// Current file: /HMSPOS/rooms/rooms/view.php
// Need to go up to: /HMSPOS/
$base_path = null;

// Method 1: Try dirname(__DIR__, 2) - should go up two levels to root
$base_path = dirname(__DIR__, 2);

// Method 2: If init.php doesn't exist there, try manual calculation
if (!file_exists($base_path . '/config/init.php')) {
    // Manual calculation: /HMSPOS/rooms/rooms/ -> /HMSPOS/
    $base_path = dirname(dirname(__DIR__));
}

// Method 3: If still not found, use absolute path as last resort
if (!file_exists($base_path . '/config/init.php')) {
    $base_path = '/Applications/XAMPP/xamppfiles/htdocs/HMSPOS';
}

// Load the universal initializer
$init_file = $base_path . '/config/init.php';
if (file_exists($init_file)) {
    require_once $init_file;
} else {
    // Emergency fallback - load files directly
    require_once $base_path . '/config/config.php';
    require_once $base_path . '/config/database.php';
    require_once $base_path . '/config/auth.php';
    
    if (file_exists($base_path . '/config/helpers.php')) {
        require_once $base_path . '/config/helpers.php';
    }
    if (file_exists($base_path . '/config/csrf.php')) {
        require_once $base_path . '/config/csrf.php';
    }
}

// Require authentication
require_auth();

// Define permission check function if it doesn't exist
if (!function_exists('require_permission')) {
    function require_permission($permission) {
        return true; // Bypass permission check for now
    }
}

// Define time_ago function if it doesn't exist
if (!function_exists('time_ago')) {
    function time_ago($datetime) {
        $time = strtotime($datetime);
        $now = time();
        $diff = $now - $time;
        
        if ($diff < 60) {
            return $diff . ' seconds ago';
        } elseif ($diff < 3600) {
            $mins = floor($diff / 60);
            return $mins . ' minute' . ($mins > 1 ? 's' : '') . ' ago';
        } elseif ($diff < 86400) {
            $hours = floor($diff / 3600);
            return $hours . ' hour' . ($hours > 1 ? 's' : '') . ' ago';
        } elseif ($diff < 2592000) {
            $days = floor($diff / 86400);
            return $days . ' day' . ($days > 1 ? 's' : '') . ' ago';
        } else {
            return date('M d, Y', $time);
        }
    }
}

// Check permission (commented out for now)
// if (function_exists('require_permission')) {
//     require_permission('rooms.view');
// }

// Set page title
$page_title = 'Room Details';

// Get current user
$current_user = function_exists('current_user') ? current_user() : null;
$user_id = $current_user['user_id'] ?? 0;

if (!$user_id) {
    if (function_exists('redirect')) {
        redirect('login.php');
    } else {
        header('Location: /HMSPOS/public/login.php');
        exit;
    }
}

// Get room ID from URL
$room_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if (!$room_id) {
    if (function_exists('set_flash_message')) {
        set_flash_message('danger', 'Invalid room ID');
    }
    if (function_exists('redirect')) {
        redirect('index.php');
    } else {
        header('Location: index.php');
        exit;
    }
}

// Get room data with details
$room = null;
try {
    $room = db_fetch_one("
        SELECT 
            r.*,
            rt.type_name, rt.type_code, rt.base_price as type_base_price,
            rt.max_adults, rt.max_children, rt.max_occupancy,
            rt.size_sqft as type_size, rt.bed_type, rt.amenities,
            CONCAT(g.first_name, ' ', g.last_name) as guest_name,
            g.guest_id,
            res.reservation_id, res.booking_code,
            res.check_in_date, res.check_out_date,
            res.total_amount, res.paid_amount,
            (res.total_amount - res.paid_amount) as balance
        FROM rooms r
        JOIN room_types rt ON r.room_type_id = rt.room_type_id
        LEFT JOIN reservations res ON r.room_id = res.room_id AND res.booking_status = 'checked_in'
        LEFT JOIN guests g ON res.guest_id = g.guest_id
        WHERE r.room_id = ?
    ", [$room_id]);
} catch (Exception $e) {
    error_log("Error fetching room: " . $e->getMessage());
}

if (!$room) {
    if (function_exists('set_flash_message')) {
        set_flash_message('danger', 'Room not found');
    }
    if (function_exists('redirect')) {
        redirect('index.php');
    } else {
        header('Location: index.php');
        exit;
    }
}

// Get room images
$images = [];
try {
    $images = db_fetch_all("SELECT * FROM room_images WHERE room_id = ? ORDER BY is_primary DESC, sort_order", [$room_id]) ?: [];
} catch (Exception $e) {
    error_log("Error fetching images: " . $e->getMessage());
}

// Get room maintenance history
$maintenance = [];
try {
    $maintenance = db_fetch_all("
        SELECT * FROM maintenance_tickets 
        WHERE room_id = ? 
        ORDER BY created_at DESC 
        LIMIT 10
    ", [$room_id]) ?: [];
} catch (Exception $e) {
    error_log("Error fetching maintenance: " . $e->getMessage());
}

// Get room cleaning history
$cleaning_history = [];
try {
    $cleaning_history = db_fetch_all("
        SELECT t.*, u.first_name, u.last_name
        FROM hk_tasks t
        LEFT JOIN users u ON t.completed_by = u.user_id
        WHERE t.room_id = ? AND t.status = 'completed'
        ORDER BY t.completed_at DESC
        LIMIT 10
    ", [$room_id]) ?: [];
} catch (Exception $e) {
    error_log("Error fetching cleaning history: " . $e->getMessage());
}

// Get upcoming reservations for this room
$upcoming = [];
try {
    $upcoming = db_fetch_all("
        SELECT r.*, g.first_name, g.last_name
        FROM reservations r
        JOIN guests g ON r.guest_id = g.guest_id
        WHERE r.room_id = ? 
        AND r.check_in_date >= CURDATE()
        AND r.booking_status IN ('confirmed', 'pending')
        ORDER BY r.check_in_date
        LIMIT 5
    ", [$room_id]) ?: [];
} catch (Exception $e) {
    error_log("Error fetching upcoming: " . $e->getMessage());
}

// Include header
$header_path = $base_path . '/views/partials/header.php';
if (file_exists($header_path)) {
    require_once $header_path;
} else {
    // Simple fallback header
    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Room Details</title>
        <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
        <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
        <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
        <style>
            body { background-color: #f4f6f9; font-family: 'Segoe UI', sans-serif; }
            .content-wrapper { padding: 20px; }
            .card { border-radius: 0.5rem; box-shadow: 0 0 10px rgba(0,0,0,0.1); margin-bottom: 20px; }
            .card-header { background: #fff; border-bottom: 1px solid #dee2e6; padding: 15px 20px; font-weight: 600; }
        </style>
    </head>
    <body>
        <div class="wrapper">
            <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
                <div class="container-fluid">
                    <a class="navbar-brand" href="#">Room Details</a>
                    <div class="navbar-nav ms-auto">
                        <span class="nav-item nav-link text-white">
                            <i class="fas fa-user"></i> 
                            <?php echo isset($current_user['username']) ? htmlspecialchars($current_user['username']) : 'User'; ?>
                        </span>
                        <a class="nav-item nav-link" href="/HMSPOS/public/logout.php">
                            <i class="fas fa-sign-out-alt"></i> Logout
                        </a>
                    </div>
                </div>
            </nav>
            <div class="content-wrapper">
    <?php
}
?>

<!-- Content Header -->
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0">Room <?php echo htmlspecialchars($room['room_number'] ?? ''); ?> - Details</h1>
            </div>
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="/HMSPOS/public/dashboard.php">Home</a></li>
                    <li class="breadcrumb-item"><a href="/HMSPOS/rooms/dashboard.php">Rooms</a></li>
                    <li class="breadcrumb-item"><a href="index.php">Rooms</a></li>
                    <li class="breadcrumb-item active">View</li>
                </ol>
            </div>
        </div>
    </div>
</div>

<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <!-- Action Buttons -->
        <div class="row mb-3">
            <div class="col-12">
                <div class="btn-group">
                    <a href="index.php" class="btn btn-secondary">
                        <i class="fas fa-arrow-left me-1"></i> Back to List
                    </a>
                    
                    <?php if (function_exists('has_permission') && has_permission('rooms.edit')): ?>
                        <a href="edit.php?id=<?php echo $room_id; ?>" class="btn btn-warning">
                            <i class="fas fa-edit me-1"></i> Edit Room
                        </a>
                    <?php endif; ?>
                    
                    <a href="status.php?id=<?php echo $room_id; ?>" class="btn btn-info">
                        <i class="fas fa-sync-alt me-1"></i> Change Status
                    </a>
                    
                    <a href="images.php?id=<?php echo $room_id; ?>" class="btn btn-primary">
                        <i class="fas fa-images me-1"></i> Manage Images
                    </a>
                    
                    <?php if (($room['status'] ?? '') == 'available'): ?>
                        <a href="/HMSPOS/reservations/reservations/create.php?room_id=<?php echo $room_id; ?>" class="btn btn-success">
                            <i class="fas fa-plus-circle me-1"></i> Create Reservation
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <div class="row">
            <!-- Room Information -->
            <div class="col-md-4">
                <div class="card card-primary card-outline">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-info-circle me-1"></i>
                            Room Information
                        </h3>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm">
                            <tr>
                                <th style="width: 120px;">Room Number:</th>
                                <td><h4><?php echo htmlspecialchars($room['room_number'] ?? ''); ?></h4></td>
                            </tr>
                            <tr>
                                <th>Floor:</th>
                                <td><?php echo htmlspecialchars($room['floor'] ?? 'Not specified'); ?></td>
                            </tr>
                            <tr>
                                <th>Room Type:</th>
                                <td>
                                    <a href="../room-types/view.php?id=<?php echo $room['room_type_id'] ?? 0; ?>">
                                        <?php echo htmlspecialchars(($room['type_name'] ?? '') . ' (' . ($room['type_code'] ?? '') . ')'); ?>
                                    </a>
                                </td>
                            </tr>
                            <tr>
                                <th>Status:</th>
                                <td>
                                    <span class="badge bg-<?php 
                                        echo ($room['status'] ?? '') == 'available' ? 'success' : 
                                            (($room['status'] ?? '') == 'occupied' ? 'danger' : 
                                            (($room['status'] ?? '') == 'maintenance' ? 'warning' : 
                                            (($room['status'] ?? '') == 'housekeeping' ? 'info' : 'secondary')));
                                    ?> badge-lg">
                                        <?php echo ucfirst($room['status'] ?? 'unknown'); ?>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <th>Housekeeping:</th>
                                <td>
                                    <span class="badge bg-<?php 
                                        echo ($room['housekeeping_status'] ?? '') == 'clean' ? 'success' : 
                                            (($room['housekeeping_status'] ?? '') == 'dirty' ? 'warning' : 
                                            (($room['housekeeping_status'] ?? '') == 'inspected' ? 'info' : 'secondary'));
                                    ?>">
                                        <?php echo ucfirst($room['housekeeping_status'] ?? 'unknown'); ?>
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <th>Active:</th>
                                <td>
                                    <?php if (!empty($room['is_active'])): ?>
                                        <span class="badge bg-success">Yes</span>
                                    <?php else: ?>
                                        <span class="badge bg-danger">No</span>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        </table>
                    </div>
                </div>

                <!-- Room Type Details -->
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-tag me-1"></i>
                            Room Type Details
                        </h3>
                    </div>
                    <div class="card-body">
                        <table class="table table-sm">
                            <tr>
                                <th>Capacity:</th>
                                <td>
                                    <i class="fas fa-user me-1"></i> <?php echo $room['max_adults'] ?? 0; ?> Adults
                                    <br>
                                    <i class="fas fa-child me-1"></i> <?php echo $room['max_children'] ?? 0; ?> Children
                                    <br>
                                    <small>Max: <?php echo $room['max_occupancy'] ?? 0; ?> persons</small>
                                </td>
                            </tr>
                            <tr>
                                <th>Size:</th>
                                <td><?php echo ($room['type_size'] ?? '') ? $room['type_size'] . ' sq ft' : 'Not specified'; ?></td>
                            </tr>
                            <tr>
                                <th>Bed Type:</th>
                                <td><?php echo htmlspecialchars($room['bed_type'] ?? 'Not specified'); ?></td>
                            </tr>
                            <tr>
                                <th>Base Rate:</th>
                                <td><strong><?php echo function_exists('format_currency') ? format_currency($room['type_base_price'] ?? 0) : 'RWF ' . number_format($room['type_base_price'] ?? 0); ?>/night</strong></td>
                            </tr>
                        </table>
                        
                        <?php if (!empty($room['amenities'])): ?>
                            <hr>
                            <h6>Amenities</h6>
                            <?php 
                            $amenities = explode(',', $room['amenities']);
                            foreach ($amenities as $amenity):
                                if (trim($amenity)):
                            ?>
                                <span class="badge bg-info me-1 mb-1"><?php echo htmlspecialchars(trim($amenity)); ?></span>
                            <?php 
                                endif;
                            endforeach; ?>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Room Notes -->
                <?php if (!empty($room['notes'])): ?>
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-sticky-note me-1"></i>
                            Notes
                        </h3>
                    </div>
                    <div class="card-body">
                        <?php echo nl2br(htmlspecialchars($room['notes'])); ?>
                    </div>
                </div>
                <?php endif; ?>
            </div>

            <!-- Current Occupant -->
            <div class="col-md-4">
                <div class="card <?php echo !empty($room['guest_name']) ? 'card-success' : 'card-secondary'; ?>">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-user me-1"></i>
                            Current Occupant
                        </h3>
                    </div>
                    <div class="card-body">
                        <?php if (!empty($room['guest_name'])): ?>
                            <div class="text-center mb-3">
                                <i class="fas fa-user-circle fa-4x text-success"></i>
                                <h4 class="mt-2"><?php echo htmlspecialchars($room['guest_name']); ?></h4>
                            </div>
                            
                            <table class="table table-sm">
                                <tr>
                                    <th>Booking Code:</th>
                                    <td>
                                        <a href="/HMSPOS/reservations/reservations/view.php?id=<?php echo $room['reservation_id'] ?? 0; ?>">
                                            <?php echo htmlspecialchars($room['booking_code'] ?? ''); ?>
                                        </a>
                                    </td>
                                </tr>
                                <tr>
                                    <th>Check-in:</th>
                                    <td><?php echo function_exists('format_date') ? format_date($room['check_in_date'] ?? '') : ($room['check_in_date'] ?? ''); ?></td>
                                </tr>
                                <tr>
                                    <th>Check-out:</th>
                                    <td><?php echo function_exists('format_date') ? format_date($room['check_out_date'] ?? '') : ($room['check_out_date'] ?? ''); ?></td>
                                </tr>
                                <tr>
                                    <th>Total Amount:</th>
                                    <td><?php echo function_exists('format_currency') ? format_currency($room['total_amount'] ?? 0) : 'RWF ' . number_format($room['total_amount'] ?? 0); ?></td>
                                </tr>
                                <tr>
                                    <th>Paid Amount:</th>
                                    <td><?php echo function_exists('format_currency') ? format_currency($room['paid_amount'] ?? 0) : 'RWF ' . number_format($room['paid_amount'] ?? 0); ?></td>
                                </tr>
                                <tr>
                                    <th>Balance:</th>
                                    <td>
                                        <span class="badge bg-<?php echo ($room['balance'] ?? 0) > 0 ? 'warning' : 'success'; ?>">
                                            <?php echo function_exists('format_currency') ? format_currency($room['balance'] ?? 0) : 'RWF ' . number_format($room['balance'] ?? 0); ?>
                                        </span>
                                    </td>
                                </tr>
                            </table>
                            
                            <div class="mt-3">
                                <a href="/HMSPOS/guests/guests/view.php?id=<?php echo $room['guest_id'] ?? 0; ?>" class="btn btn-sm btn-info">
                                    <i class="fas fa-user me-1"></i> View Guest
                                </a>
                                <a href="/HMSPOS/billing/folio/view.php?reservation_id=<?php echo $room['reservation_id'] ?? 0; ?>" 
                                   class="btn btn-sm btn-primary">
                                    <i class="fas fa-file-invoice me-1"></i> View Folio
                                </a>
                            </div>
                        <?php else: ?>
                            <div class="text-center text-muted py-4">
                                <i class="fas fa-user-slash fa-4x mb-3"></i>
                                <p>No guest currently assigned</p>
                                <?php if (($room['status'] ?? '') == 'available'): ?>
                                    <a href="/HMSPOS/reservations/reservations/create.php?room_id=<?php echo $room_id; ?>" 
                                       class="btn btn-success">
                                        <i class="fas fa-plus-circle me-1"></i> Assign Guest
                                    </a>
                                <?php endif; ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Upcoming Reservations -->
                <?php if (!empty($upcoming)): ?>
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-calendar-alt me-1"></i>
                            Upcoming Reservations
                        </h3>
                    </div>
                    <div class="card-body p-0">
                        <div class="list-group list-group-flush">
                            <?php foreach ($upcoming as $res): ?>
                            <div class="list-group-item">
                                <div class="d-flex justify-content-between">
                                    <div>
                                        <strong><?php echo function_exists('format_date') ? format_date($res['check_in_date'] ?? '') : ($res['check_in_date'] ?? ''); ?></strong>
                                        <br>
                                        <small><?php echo htmlspecialchars(($res['first_name'] ?? '') . ' ' . ($res['last_name'] ?? '')); ?></small>
                                    </div>
                                    <div>
                                        <span class="badge bg-<?php echo ($res['booking_status'] ?? '') == 'confirmed' ? 'success' : 'warning'; ?>">
                                            <?php echo ucfirst($res['booking_status'] ?? 'pending'); ?>
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <?php endforeach; ?>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
            </div>

            <!-- Room Images & History -->
            <div class="col-md-4">
                <!-- Room Images -->
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-images me-1"></i>
                            Room Images
                        </h3>
                        <div class="card-tools">
                            <a href="images.php?id=<?php echo $room_id; ?>" class="btn btn-sm btn-primary">
                                <i class="fas fa-edit"></i> Manage
                            </a>
                        </div>
                    </div>
                    <div class="card-body">
                        <?php if (empty($images)): ?>
                            <div class="text-center text-muted py-3">
                                <i class="fas fa-image fa-3x mb-2"></i>
                                <p>No images uploaded</p>
                                <a href="images.php?id=<?php echo $room_id; ?>" class="btn btn-sm btn-primary">
                                    Upload Images
                                </a>
                            </div>
                        <?php else: ?>
                            <div id="roomImageCarousel" class="carousel slide" data-bs-ride="carousel">
                                <div class="carousel-inner">
                                    <?php foreach ($images as $index => $image): ?>
                                        <div class="carousel-item <?php echo $index == 0 ? 'active' : ''; ?>">
                                            <img src="/HMSPOS/uploads/room_images/<?php echo urlencode($image['image_path'] ?? ''); ?>" 
                                                 class="d-block w-100" alt="Room Image" style="height: 200px; object-fit: cover;">
                                            <?php if (!empty($image['is_primary'])): ?>
                                                <div class="carousel-caption">
                                                    <span class="badge bg-primary">Primary</span>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    <?php endforeach; ?>
                                </div>
                                <button class="carousel-control-prev" type="button" data-bs-target="#roomImageCarousel" data-bs-slide="prev">
                                    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
                                </button>
                                <button class="carousel-control-next" type="button" data-bs-target="#roomImageCarousel" data-bs-slide="next">
                                    <span class="carousel-control-next-icon" aria-hidden="true"></span>
                                </button>
                            </div>
                            
                            <div class="mt-2 text-center">
                                <small class="text-muted"><?php echo count($images); ?> image(s)</small>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Recent Maintenance -->
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-tools me-1"></i>
                            Recent Maintenance
                        </h3>
                    </div>
                    <div class="card-body p-0">
                        <?php if (empty($maintenance)): ?>
                            <div class="text-center text-muted py-3">
                                <p>No maintenance records</p>
                            </div>
                        <?php else: ?>
                            <div class="list-group list-group-flush">
                                <?php foreach ($maintenance as $ticket): ?>
                                <div class="list-group-item">
                                    <div class="d-flex justify-content-between">
                                        <div>
                                            <strong><?php echo htmlspecialchars($ticket['issue_type'] ?? ''); ?></strong>
                                            <br>
                                            <small class="text-muted"><?php echo function_exists('time_ago') ? time_ago($ticket['created_at'] ?? '') : ($ticket['created_at'] ?? ''); ?></small>
                                        </div>
                                        <span class="badge bg-<?php 
                                            echo ($ticket['status'] ?? '') == 'resolved' ? 'success' : 
                                                (($ticket['status'] ?? '') == 'in_progress' ? 'info' : 
                                                (($ticket['priority'] ?? '') == 'urgent' ? 'danger' : 'warning'));
                                        ?>">
                                            <?php echo ucfirst($ticket['status'] ?? 'unknown'); ?>
                                        </span>
                                    </div>
                                </div>
                                <?php endforeach; ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>

                <!-- Cleaning History -->
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">
                            <i class="fas fa-broom me-1"></i>
                            Cleaning History
                        </h3>
                    </div>
                    <div class="card-body p-0">
                        <?php if (empty($cleaning_history)): ?>
                            <div class="text-center text-muted py-3">
                                <p>No cleaning records</p>
                            </div>
                        <?php else: ?>
                            <div class="list-group list-group-flush">
                                <?php foreach ($cleaning_history as $task): ?>
                                <div class="list-group-item">
                                    <div class="d-flex justify-content-between">
                                        <div>
                                            <strong>Cleaned by <?php echo htmlspecialchars(($task['first_name'] ?? '') . ' ' . ($task['last_name'] ?? '')); ?></strong>
                                            <br>
                                            <small class="text-muted"><?php echo function_exists('time_ago') ? time_ago($task['completed_at'] ?? '') : ($task['completed_at'] ?? ''); ?></small>
                                        </div>
                                        <span class="badge bg-success">Completed</span>
                                    </div>
                                </div>
                                <?php endforeach; ?>
                            </div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
.badge-lg {
    font-size: 1rem;
    padding: 0.5rem 1rem;
}
.carousel-caption {
    background: rgba(0,0,0,0.5);
    border-radius: 5px;
    padding: 5px;
    bottom: 10px;
}
.me-1 { margin-right: 0.25rem; }
.me-2 { margin-right: 0.5rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 1rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 1rem; }
</style>

<?php
// Include footer
$footer_path = $base_path . '/views/partials/footer.php';
if (file_exists($footer_path)) {
    require_once $footer_path;
} else {
    echo '</div></div></body></html>';
}
?>