{{-- Mentorship Public Category View --}}
{{-- Programmes filtered by category --}}

<x-site-layout 
    title="{{ $category->name }} - Mentorship Programmes"
    meta-description="{{ Str::limit($category->description ?? 'Browse mentorship programmes in ' . $category->name, 160) }}"
    :show-breadcrumbs="true">

    {{-- Hero Section — Advocacy Style --}}
    <div class="relative bg-gradient-to-r from-green-700 to-emerald-800 shadow-xl">
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-16">
            <div class="text-center">
                <div class="w-16 h-16 mx-auto mb-4 bg-white/20 rounded-full flex items-center justify-center">
                    <i class="{{ $category->icon ?? 'fas fa-folder' }} text-3xl text-white"></i>
                </div>
                <h1 class="text-4xl md:text-5xl font-serif font-bold text-white mb-4">
                    {{ $category->name }}
                </h1>
                @if($category->description)
                    <p class="text-xl text-green-100 max-w-3xl mx-auto mb-6">
                        {{ $category->description }}
                    </p>
                @endif
                <span class="inline-block px-4 py-1 bg-white/20 text-white rounded-full text-sm font-semibold">
                    <i class="fas fa-graduation-cap mr-2"></i>
                    {{ $programmes->total() }} Programme{{ $programmes->total() !== 1 ? 's' : '' }} Available
                </span>
            </div>
        </div>
    </div>

    {{-- Breadcrumb --}}
    <div class="bg-gray-50 border-b border-gray-200">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-3">
            <nav class="flex items-center space-x-2 text-sm text-gray-600" aria-label="Breadcrumb">
                <a href="{{ url('/') }}" class="hover:text-green-600 transition flex items-center">
                    <i class="fas fa-home mr-1"></i>Home
                </a>
                <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
                <a href="{{ route('mentorship.public.index') }}" class="hover:text-green-600 transition">Mentorship</a>
                <i class="fas fa-chevron-right text-gray-400 text-xs"></i>
                <span class="text-gray-900 font-medium">{{ $category->name }}</span>
            </nav>
        </div>
    </div>

    {{-- Main Content Area --}}
    <div class="py-12 bg-gray-50">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="grid grid-cols-1 lg:grid-cols-4 gap-8">
                {{-- Sidebar --}}
                <div class="lg:col-span-1">
                    <div class="bg-white rounded-lg shadow-sm sticky top-4">
                        <div class="p-6 border-b border-gray-200">
                            <h3 class="text-lg font-semibold text-gray-900">
                                <i class="fas fa-filter mr-2 text-green-600"></i>
                                Categories
                            </h3>
                        </div>
                        <div class="p-4">
                            <ul class="space-y-1">
                                @foreach($categories as $cat)
                                    <li>
                                        <a href="{{ route('mentorship.public.category', $cat) }}" 
                                           class="flex items-center justify-between px-3 py-2 rounded-lg transition {{ $cat->id === $category->id ? 'bg-green-100 text-green-700 font-medium' : 'text-gray-600 hover:bg-gray-50' }}">
                                            <span class="flex items-center">
                                                <i class="{{ $cat->icon ?? 'fas fa-folder' }} mr-2 text-sm"></i>
                                                {{ $cat->name }}
                                            </span>
                                            <span class="text-xs {{ $cat->id === $category->id ? 'text-green-600' : 'text-gray-400' }}">
                                                {{ $cat->active_programmes_count ?? 0 }}
                                            </span>
                                        </a>
                                    </li>
                                @endforeach
                            </ul>
                        </div>
                    </div>

                    {{-- Filter Card --}}
                    <div class="bg-white rounded-lg shadow-sm mt-6">
                        <div class="p-6 border-b border-gray-200">
                            <h3 class="text-lg font-semibold text-gray-900">
                                <i class="fas fa-sliders-h mr-2 text-green-600"></i>
                                Filters
                            </h3>
                        </div>
                        <div class="p-6">
                            <form method="GET" action="{{ route('mentorship.public.category', $category) }}">
                                {{-- Search --}}
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-600 mb-1">Search</label>
                                    <input type="text" 
                                           name="search" 
                                           value="{{ request('search') }}"
                                           placeholder="Search programmes..."
                                           class="w-full border border-gray-300 rounded-lg px-3 py-2 bg-white text-gray-900 focus:ring-2 focus:ring-green-500 focus:border-green-500 text-sm">
                                </div>

                                {{-- Fee Filter --}}
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-600 mb-1">Fee</label>
                                    <select name="is_free" 
                                            class="w-full border border-gray-300 rounded-lg px-3 py-2 bg-white text-gray-900 focus:ring-2 focus:ring-green-500 focus:border-green-500 text-sm">
                                        <option value="">All</option>
                                        <option value="1" {{ request('is_free') === '1' ? 'selected' : '' }}>Free Only</option>
                                        <option value="0" {{ request('is_free') === '0' ? 'selected' : '' }}>Paid Only</option>
                                    </select>
                                </div>

                                {{-- Session Type --}}
                                <div class="mb-4">
                                    <label class="block text-sm font-medium text-gray-600 mb-1">Format</label>
                                    <select name="session_type" 
                                            class="w-full border border-gray-300 rounded-lg px-3 py-2 bg-white text-gray-900 focus:ring-2 focus:ring-green-500 focus:border-green-500 text-sm">
                                        <option value="">All Formats</option>
                                        <option value="online" {{ request('session_type') === 'online' ? 'selected' : '' }}>Online</option>
                                        <option value="in_person" {{ request('session_type') === 'in_person' ? 'selected' : '' }}>In-Person</option>
                                        <option value="hybrid" {{ request('session_type') === 'hybrid' ? 'selected' : '' }}>Hybrid</option>
                                    </select>
                                </div>

                                <div class="flex gap-2">
                                    <button type="submit" class="flex-1 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm">
                                        Apply
                                    </button>
                                    <a href="{{ route('mentorship.public.category', $category) }}" 
                                       class="px-4 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 transition text-sm">
                                        Clear
                                    </a>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

                {{-- Programmes Grid --}}
                <div class="lg:col-span-3">
                    {{-- Results Header --}}
                    <div class="flex items-center justify-between mb-6">
                        <p class="text-gray-600">
                            Showing {{ $programmes->firstItem() ?? 0 }} - {{ $programmes->lastItem() ?? 0 }} of {{ $programmes->total() }} programmes
                        </p>
                        <a href="{{ route('mentorship.public.index') }}" 
                           class="text-green-600 hover:underline text-sm">
                            <i class="fas fa-arrow-left mr-1"></i>
                            View All Programmes
                        </a>
                    </div>

                    @if($programmes->count() > 0)
                        <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-6">
                            @foreach($programmes as $programme)
                                <div class="bg-white rounded-lg shadow-sm border border-gray-100 overflow-hidden hover:shadow-md transition group">
                                    @if($programme->featured_image)
                                        <div class="h-40 bg-cover bg-center" 
                                             style="background-image: url('{{ $programme->featured_image }}')">
                                        </div>
                                    @else
                                        <div class="h-40 bg-gradient-to-r from-green-500 to-green-600 flex items-center justify-center">
                                            <i class="fas fa-graduation-cap text-white text-4xl opacity-50"></i>
                                        </div>
                                    @endif
                                    <div class="p-5">
                                        <div class="flex items-center justify-between mb-2">
                                            @if($programme->is_featured)
                                                <span class="text-xs px-2 py-1 bg-yellow-100 text-yellow-800 rounded">
                                                    <i class="fas fa-star mr-1"></i>Featured
                                                </span>
                                            @else
                                                <span class="text-xs text-gray-400">&nbsp;</span>
                                            @endif
                                            @if($programme->is_free)
                                                <span class="text-xs font-semibold text-green-600">FREE</span>
                                            @else
                                                <span class="text-xs font-semibold text-gray-900">{{ $programme->formatted_fee }}</span>
                                            @endif
                                        </div>
                                        <h3 class="text-lg font-semibold text-gray-900 group-hover:text-green-600 transition">
                                            {{ $programme->title }}
                                        </h3>
                                        <p class="text-sm text-gray-600 mt-2 line-clamp-2">
                                            {{ Str::limit($programme->description, 100) }}
                                        </p>
                                        <div class="flex items-center gap-3 mt-3 text-xs text-gray-500">
                                            <span>
                                                <i class="fas fa-clock mr-1"></i>
                                                {{ $programme->duration_text }}
                                            </span>
                                            <span>
                                                @if($programme->session_type === 'online')
                                                    <i class="fas fa-video mr-1"></i>Online
                                                @elseif($programme->session_type === 'in_person')
                                                    <i class="fas fa-map-marker-alt mr-1"></i>In-Person
                                                @else
                                                    <i class="fas fa-globe mr-1"></i>Hybrid
                                                @endif
                                            </span>
                                        </div>
                                        <div class="flex items-center gap-2 mt-4">
                                            <a href="{{ route('mentorship.public.programme', $programme) }}" 
                                               class="flex-1 text-center px-3 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm font-medium">
                                                View Details
                                            </a>
                                            @if($programme->canApply(auth()->user()))
                                                <a href="{{ route('mentorship.public.apply', ['programme_id' => $programme->id]) }}" 
                                                   class="px-3 py-2 border border-gray-300 rounded-lg hover:bg-gray-50 transition text-sm">
                                                    <i class="fas fa-user-plus"></i>
                                                </a>
                                            @endif
                                        </div>
                                    </div>
                                </div>
                            @endforeach
                        </div>

                        {{-- Pagination --}}
                        <div class="mt-8">
                            {{ $programmes->links() }}
                        </div>
                    @else
                        {{-- Empty State --}}
                        <div class="bg-white rounded-lg shadow-sm">
                            <div class="p-12 text-center">
                                <div class="w-20 h-20 mx-auto mb-6 bg-gray-100 rounded-full flex items-center justify-center">
                                    <i class="fas fa-search text-gray-300 text-3xl"></i>
                                </div>
                                <h3 class="text-xl font-semibold text-gray-900 mb-2">No Programmes Found</h3>
                                <p class="text-gray-500 mb-6 max-w-md mx-auto">
                                    No programmes match your current filters. Try adjusting your search or browse other categories.
                                </p>
                                <a href="{{ route('mentorship.public.index') }}" 
                                   class="inline-flex items-center px-6 py-3 bg-green-600 text-white rounded-lg hover:bg-green-700 transition">
                                    <i class="fas fa-graduation-cap mr-2"></i>
                                    Browse All Programmes
                                </a>
                            </div>
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>
</x-site-layout>
