{{-- Admin Membership Categories Index --}}
<x-app-layout title="Membership Categories">

    <x-module-hero title="Membership Categories" description="Manage membership types and fee structures" icon="fa-tags">
        <x-slot name="tabs">
            @can('view members')
                <a href="{{ route('admin.membership.dashboard') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.membership.dashboard') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-tachometer-alt text-sm"></i> Dashboard
                </a>
            @endcan
            @can('view members')
                <a href="{{ route('admin.members.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.members.index') || request()->routeIs('admin.members.show') || request()->routeIs('admin.members.create') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-users text-sm"></i> Members
                </a>
            @endcan
            @can('view members')
                <a href="{{ route('admin.members.applications.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.members.applications.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-file-alt text-sm"></i> Applications
                </a>
            @endcan
            @can('view membership categories')
                <a href="{{ route('admin.membership-categories.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.membership-categories.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-tags text-sm"></i> Categories
                </a>
            @endcan
            @can('manage renewal configs')
                <a href="{{ route('admin.renewal-configs.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.renewal-configs.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-rotate text-sm"></i> Renewal Config
                </a>
            @endcan
            @can('view contributions')
                <a href="{{ route('admin.contributions.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.contributions.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-hand-holding-usd text-sm"></i> Contributions
                </a>
            @endcan
            @can('view loan products')
                <a href="{{ route('admin.loan-products.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.loan-products.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-box text-sm"></i> Loan Products
                </a>
            @endcan
            @can('view loan applications')
                <a href="{{ route('admin.loan-applications.index') }}"
                   class="module-hero-tab {{ request()->routeIs('admin.loan-applications.*') ? 'border-b-2 border-[#1e293b]' : 'opacity-70 hover:opacity-100 transition-opacity' }}
                          inline-flex items-center gap-2 px-4 py-3 text-[#1e293b] text-sm font-medium
                          md:w-auto w-full border-b border-[#cbd5e1] md:border-b-0">
                    <i class="fas fa-money-bill-wave text-sm"></i> Loan Applications
                </a>
            @endcan
        </x-slot>
        <x-slot name="actions">
            @can('create membership categories')
                <a href="{{ route('admin.membership-categories.create') }}" class="inline-flex items-center gap-2 px-4 py-2 bg-[#1e293b]/10 hover:bg-[#1e293b]/20 text-[#1e293b] text-sm font-medium rounded transition">
                    <i class="fas fa-plus"></i> New Category
                </a>
            @endcan
        </x-slot>
    </x-module-hero>

    <div class="p-6">
        @if(session('success'))
            <div class="mb-6 p-4 bg-green-100 border border-green-400 text-green-700 rounded-lg flex items-center">
                <i class="fas fa-check-circle mr-3"></i> {{ session('success') }}
            </div>
        @endif
        @if(session('error'))
            <div class="mb-6 p-4 bg-red-100 border border-red-400 text-red-700 rounded-lg flex items-center">
                <i class="fas fa-exclamation-circle mr-3"></i> {{ session('error') }}
            </div>
        @endif

        @if($categories->count() > 0)
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                @foreach($categories as $category)
                    <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden hover:shadow-md transition-shadow">
                        <div class="p-5 text-white" style="background-color: var(--theme-bg-sidebar);">
                            <div class="flex items-center justify-between mb-2">
                                <i class="fas {{ $category->icon ?? 'fa-users' }} text-2xl opacity-80"></i>
                                <span class="text-xs px-2 py-1 rounded-full font-semibold {{ $category->is_active ? 'bg-green-400 text-green-900' : 'bg-red-400 text-red-900' }}">
                                    {{ $category->is_active ? 'Active' : 'Inactive' }}
                                </span>
                            </div>
                            <h3 class="text-lg font-bold">{{ $category->name }}</h3>
                        </div>
                        <div class="p-5">
                            <p class="text-gray-600 text-sm mb-4 line-clamp-2">{{ $category->description ?? 'No description provided.' }}</p>
                            <div class="grid grid-cols-3 gap-2 mb-4 text-center">
                                <div class="bg-gray-50 rounded-lg py-2">
                                    <div class="text-lg font-bold text-gray-900">{{ $category->members_count }}</div>
                                    <div class="text-xs text-gray-500">Members</div>
                                </div>
                                <div class="bg-gray-50 rounded-lg py-2">
                                    <div class="text-lg font-bold text-gray-900">{{ $category->subscriptionFees->count() }}</div>
                                    <div class="text-xs text-gray-500">Sub Fees</div>
                                </div>
                                <div class="bg-gray-50 rounded-lg py-2">
                                    <div class="text-lg font-bold text-gray-900">{{ $category->contributionFees->count() }}</div>
                                    <div class="text-xs text-gray-500">Cont Fees</div>
                                </div>
                            </div>
                            <div class="flex gap-2">
                                <a href="{{ route('admin.membership-categories.show', $category) }}" class="btn-action-view flex-1 justify-center">
                                    <i class="fas fa-eye"></i> View
                                </a>
                                @can('edit membership categories')
                                    <a href="{{ route('admin.membership-categories.edit', $category) }}" class="btn-action-edit flex-1 justify-center">
                                        <i class="fas fa-edit"></i> Edit
                                    </a>
                                @endcan
                            </div>
                        </div>
                    </div>
                @endforeach
            </div>
        @else
            <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-12 text-center">
                <i class="fas fa-folder-open text-5xl text-gray-300 mb-4"></i>
                <h3 class="text-lg font-semibold text-gray-700 mb-2">No Membership Categories</h3>
                <p class="text-gray-500 mb-6">Get started by creating your first membership category.</p>
                @can('create membership categories')
                    <a href="{{ route('admin.membership-categories.create') }}" class="inline-flex items-center px-6 py-2.5 bg-green-600 text-white rounded-lg hover:bg-green-700 transition text-sm font-medium">
                        <i class="fas fa-plus mr-2"></i> Create First Category
                    </a>
                @endcan
            </div>
        @endif
    </div>

</x-app-layout>
