<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Room Maintenance - {{ 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);
        }
        
        .sidebar {
            background-color: white;
            box-shadow: 3px 0 10px rgba(0, 0, 0, 0.1);
            height: calc(100vh - 56px);
            position: fixed;
            top: 56px;
            padding: 15px;
            z-index: 1000;
            overflow-y: auto;
            width: 250px;
        }
        
        .sidebar .nav-link {
            color: #495057;
            padding: 15px 20px;
            border-left: 4px solid transparent;
            transition: all 0.3s;
        }
        
        .sidebar .nav-link:hover {
            background-color: #f8f9fa;
            border-left: 4px solid var(--secondary-green);
        }
        
        .sidebar .nav-link.active {
            background-color: var(--light-green);
            color: var(--dark-green);
            border-left: 4px solid var(--primary-green);
            font-weight: 600;
        }
        
        .sidebar .nav-link i {
            margin-right: 10px;
            color: var(--primary-green);
        }
        
        .main-content {
            margin-left: 250px;
            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(-5px);
            box-shadow: 0 10px 20px 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;
        }
        
        .text-primary {
            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;
        }
        
        .priority-badge {
            font-size: 0.75rem;
            padding: 0.35em 0.65em;
        }
        
        .room-header {
            background: linear-gradient(135deg, var(--primary-green) 0%, var(--dark-green) 100%);
            color: white;
            border-radius: 10px;
            padding: 20px;
            margin-bottom: 20px;
        }
        
        @media (max-width: 768px) {
            .sidebar {
                width: 100%;
                position: relative;
                height: auto;
                top: 0;
            }
            
            .main-content {
                margin-left: 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
            </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>

    <!-- Sidebar -->

    <!-- Main Content -->
    <div class="main-content">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <div>
                <h1 class="h3 mb-0 text-gray-800">
                    <i class="fas fa-tools me-2"></i>Maintenance History
                </h1>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb mb-0">
                        <li class="breadcrumb-item"><a href="{{ route('rooms.index') }}">Room Management</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('rooms.show', $room->id) }}">Room {{ $room->room_number }}</a></li>
                        <li class="breadcrumb-item active">Maintenance History</li>
                    </ol>
                </nav>
            </div>
            <div class="action-buttons">
                <a href="{{ route('maintenance.create', ['room_id' => $room->id]) }}" class="btn btn-primary">
                    <i class="fas fa-plus me-2"></i>New Request
                </a>
                <a href="{{ route('rooms.show', $room->id) }}" class="btn btn-outline-secondary">
                    <i class="fas fa-bed me-2"></i>Back to Room
                </a>
            </div>
        </div>

        <!-- Room Information -->
        <div class="room-header">
            <div class="row">
                <div class="col-md-6">
                    <h3 class="mb-1">Room {{ $room->room_number }}</h3>
                    <p class="mb-0">{{ $room->roomType->name ?? 'No Type' }} • Floor {{ $room->floor }}</p>
                </div>
                <div class="col-md-6 text-end">
                    <div class="room-status">
                        <span class="badge bg-{{ $room->status_badge_class }} fs-6">
                            {{ ucfirst($room->status) }}
                        </span>
                        @if($room->has_active_maintenance)
                            <span class="badge bg-warning fs-6 ms-2">
                                <i class="fas fa-tools me-1"></i>Active Maintenance
                            </span>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <!-- Maintenance Statistics -->
        <div class="row mb-4">
            <div class="col-xl-3 col-md-6 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">{{ $maintenances->total() }}</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-3 col-md-6 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">
                                    Active Requests
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    {{ $room->activeMaintenanceRequests->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-3 col-md-6 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">
                                    @php
                                        $completedCount = $room->maintenanceRequests->where('status', 'completed')->count();
                                    @endphp
                                    {{ $completedCount }}
                                </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-3 col-md-6 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">
                                    Repair Requests
                                </div>
                                <div class="h5 mb-0 font-weight-bold text-gray-800">
                                    @php
                                        $repairCount = $room->maintenanceRequests->where('maintenance_type', 'repair')->count();
                                    @endphp
                                    {{ $repairCount }}
                                </div>
                            </div>
                            <div class="col-auto">
                                <i class="fas fa-wrench fa-2x text-gray-300"></i>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Maintenance History -->
        <div class="card dashboard-card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">
                    <i class="fas fa-history me-2"></i>Maintenance History
                    <span class="badge bg-light text-dark ms-2">{{ $maintenances->total() }}</span>
                </h5>
            </div>
            <div class="card-body">
                @if($maintenances->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($maintenances as $maintenance)
                                <tr>
                                    <td>#{{ $maintenance->id }}</td>
                                    <td>
                                        <a href="{{ route('maintenance.show', $maintenance) }}" class="text-decoration-none">
                                            {{ $maintenance->title }}
                                        </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="badge priority-badge {{ $maintenance->priority_badge }}">
                                            {{ ucfirst($maintenance->priority) }}
                                        </span>
                                    </td>
                                    <td>
                                        <span class="badge priority-badge {{ $maintenance->status_badge }}">
                                            {{ 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">
                                                <i class="fas fa-eye"></i>
                                            </a>
                                            <a href="{{ route('maintenance.edit', $maintenance) }}" class="btn btn-outline-warning">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                        </div>
                                    </td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    
                    <!-- Pagination -->
                    <div class="d-flex justify-content-between align-items-center mt-3">
                        <div>Showing {{ $maintenances->firstItem() }} to {{ $maintenances->lastItem() }} of {{ $maintenances->total() }} maintenance requests</div>
                        {{ $maintenances->links() }}
                    </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 history found</h4>
                        <p class="text-muted">This room has no maintenance requests yet.</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>
</body>
</html>
