<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    
    @hotelSettings<title>Room Maintenance History - {{ hotelName() }}</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">
    <style>
        :root {
            --primary-green: #1a936f;
            --secondary-green: #88d498;
            --light-green: #c6dabf;
            --dark-green: #114b5f;
            --accent: #f3e9d2;
        }
        
        body {
            background-color: #f8f9fa;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        .navbar {
            background: linear-gradient(90deg, var(--dark-green) 0%, var(--primary-green) 100%);
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }
        
        .main-content {
            margin-left: 150px;
            margin-right: 150px;
            padding: 20px;
            margin-top: 56px;
        }
        
        .dashboard-card {
            border-radius: 10px;
            transition: transform 0.3s, box-shadow 0.3s;
            border: none;
        }
        
        .dashboard-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
        }
        
        .card-header {
            background: linear-gradient(90deg, var(--primary-green) 0%, var(--secondary-green) 100%);
            color: white;
            border-radius: 10px 10px 0 0 !important;
        }
        
        .bg-primary {
            background-color: var(--primary-green) !important;
        }
        
        .btn-primary {
            background-color: var(--primary-green);
            border-color: var(--primary-green);
        }
        
        .btn-primary:hover {
            background-color: var(--dark-green);
            border-color: var(--dark-green);
        }
        
        .status-badge {
            padding: 5px 10px;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: 600;
        }
        
        .status-pending { background-color: #fff3cd; color: #856404; }
        .status-in_progress { background-color: #d1ecf1; color: #0c5460; }
        .status-completed { background-color: #d4edda; color: #155724; }
        .status-cancelled { background-color: #f8d7da; color: #721c24; }
        
        .priority-badge {
            padding: 4px 8px;
            border-radius: 15px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        
        .priority-low { background-color: #d4edda; color: #155724; }
        .priority-medium { background-color: #fff3cd; color: #856404; }
        .priority-high { background-color: #f8d7da; color: #721c24; }
        .priority-urgent { background-color: #dc3545; color: white; }
        
        .room-info-card {
            background: linear-gradient(135deg, var(--light-green) 0%, var(--accent) 100%);
            border: none;
            border-radius: 10px;
        }
        
        @media (max-width: 768px) {
            .main-content {
                margin-left: 0;
                margin-right: 0;
            }
        }
    </style>
</head>
<body>
    <!-- Navbar -->
    <nav class="navbar navbar-expand-lg navbar-dark">
        <div class="container-fluid">
            <a class="navbar-brand" href="#">
                <i class="fas fa-hotel me-2"></i>
                {{ hotelName() }} Management / ROOM MAINTENANCE
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav ms-auto">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="fas fa-user-circle me-1"></i> Admin
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="#"><i class="fas fa-user me-2"></i> Profile</a></li>
                            <li><a class="dropdown-item" href="#"><i class="fas fa-cog me-2"></i> Settings</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="#"><i class="fas fa-sign-out-alt me-2"></i> Logout</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- Main Content -->
    <div class="main-content">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <a href="{{ route('rooms.index') }}" class="btn btn-outline-primary me-2">
                    <i class="fas fa-arrow-left me-2"></i>Back to Rooms
                </a>
                <a href="{{ route('maintenance.create', ['room_id' => $room->id]) }}" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>New Maintenance Request
                </a>
            </div>
        </div>

        <!-- Room Information -->
        <div class="card room-info-card mb-4">
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <h4 class="card-title">Room {{ $room->room_number }}</h4>
                        <p class="card-text mb-1">
                            <strong>Type:</strong> {{ $room->roomType->name ?? 'No Type' }}
                        </p>
                        <p class="card-text mb-1">
                            <strong>Floor:</strong> {{ $room->floor }}
                        </p>
                        <p class="card-text mb-1">
                            <strong>Capacity:</strong> {{ $room->capacity }} Guests
                        </p>
                    </div>
                    <div class="col-md-6">
                        <p class="card-text mb-1">
                            <strong>Current Status:</strong> 
                            <span class="status-badge status-{{ $room->status }}">
                                {{ ucfirst($room->status) }}
                            </span>
                        </p>
                        <p class="card-text mb-1">
                            <strong>Price:</strong> UGX {{ number_format($room->price_per_night, 2) }}/night
                        </p>
                        <p class="card-text">
                            <strong>Active Maintenance Requests:</strong> 
                            <span class="badge bg-warning">{{ $maintenanceRequests->whereIn('status', ['pending', 'in_progress'])->count() }}</span>
                        </p>
                    </div>
                </div>
            </div>
        </div>

        <!-- Maintenance Statistics -->
        <div class="row mb-4">
            <div class="col-xl-2 col-md-4 mb-3">
                <div class="card dashboard-card border-left-primary shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-primary text-uppercase mb-1">
                                    Total Requests
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $maintenanceRequests->count() }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-clipboard-list fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-2 col-md-4 mb-3">
                <div class="card dashboard-card border-left-warning shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-warning text-uppercase mb-1">
                                    Pending
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $maintenanceRequests->where('status', 'pending')->count() }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-clock fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-2 col-md-4 mb-3">
                <div class="card dashboard-card border-left-info shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-info text-uppercase mb-1">
                                    In Progress
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $maintenanceRequests->where('status', 'in_progress')->count() }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-spinner fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-2 col-md-4 mb-3">
                <div class="card dashboard-card border-left-success shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-success text-uppercase mb-1">
                                    Completed
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $maintenanceRequests->where('status', 'completed')->count() }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-check-circle fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-2 col-md-4 mb-3">
                <div class="card dashboard-card border-left-danger shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-danger text-uppercase mb-1">
                                    High Priority
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $maintenanceRequests->whereIn('priority', ['high', 'urgent'])->count() }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-exclamation-triangle fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xl-2 col-md-4 mb-3">
                <div class="card dashboard-card border-left-secondary shadow h-100 py-2">
                    <div class="card-body">
                        <div class="row no-gutters align-items-center">
                            <div class="col mr-2">
                                <div class="text-xs font-weight-bold text-secondary text-uppercase mb-1">
                                    Repair Jobs
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">{{ $maintenanceRequests->where('maintenance_type', 'repair')->count() }}</div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-tools fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Maintenance Requests Table -->
        <div class="card dashboard-card">
            <div class="card-header d-flex justify-content-between align-items-center">
                <h5 class="mb-0"><i class="fas fa-tools me-2"></i>Maintenance History</h5>
                <span class="badge bg-primary">{{ $maintenanceRequests->count() }} requests</span>
            </div>
            <div class="card-body">
                @if($maintenanceRequests->count() > 0)
                    <div class="table-responsive">
                        <table class="table table-hover">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Title</th>
                                    <th>Type</th>
                                    <th>Priority</th>
                                    <th>Status</th>
                                    <th>Reported Date</th>
                                    <th>Scheduled Date</th>
                                    <th>Completed Date</th>
                                    <th>Assigned To</th>
                                    <th>Actions</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($maintenanceRequests as $maintenance)
                                <tr>
                                    <td>#{{ $maintenance->id }}</td>
                                    <td>
                                        <a href="{{ route('maintenance.show', $maintenance) }}" class="text-decoration-none">
                                            {{ Str::limit($maintenance->title, 40) }}
                                        </a>
                                    </td>
                                    <td>
                                        <span class="text-capitalize">{{ $maintenance->maintenance_type }}</span>
                                        @if($maintenance->maintenance_type === 'repair')
                                            <span class="badge bg-danger ms-1">Repair</span>
                                        @endif
                                    </td>
                                    <td>
                                        <span class="priority-badge priority-{{ $maintenance->priority }}">
                                            {{ ucfirst($maintenance->priority) }}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="status-badge status-{{ $maintenance->status }}">
                                            {{ ucfirst(str_replace('_', ' ', $maintenance->status)) }}
                                        </span>
                                    </td>
                                    <td>{{ $maintenance->reported_date->format('M j, Y') }}</td>
                                    <td>
                                        @if($maintenance->scheduled_date)
                                            {{ $maintenance->scheduled_date->format('M j, Y') }}
                                        @else
                                            <span class="text-muted">Not scheduled</span>
                                        @endif
                                    </td>
                                    <td>
                                        @if($maintenance->completed_date)
                                            {{ $maintenance->completed_date->format('M j, Y') }}
                                        @else
                                            <span class="text-muted">-</span>
                                        @endif
                                    </td>
                                    <td>{{ $maintenance->assignedTechnician?->name ?? 'Not Assigned' }}</td>
                                    <td>
                                        <div class="btn-group btn-group-sm">
                                            <a href="{{ route('maintenance.show', $maintenance) }}" class="btn btn-outline-primary" title="View">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                            <a href="{{ route('maintenance.edit', $maintenance) }}" class="btn btn-outline-warning" title="Edit">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                @else
                    <div class="text-center py-5">
                        <i class="fas fa-tools fa-3x text-muted mb-3"></i>
                        <h4 class="text-muted">No maintenance requests found</h4>
                        <p class="text-muted">This room has no maintenance history.</p>
                        <a href="{{ route('maintenance.create', ['room_id' => $room->id]) }}" class="btn btn-primary">
                            <i class="fas fa-plus me-2"></i>Create First Request
                        </a>
                    </div>
                @endif
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script src="{{ asset('js/theme-applier.js') }}"></script>
</body>
</html>

