<x-app-layout>

    <x-module-hero
        title="Hero Cards"
        description="Manage the info cards displayed below the hero slider on the homepage"
        icon="fa-th-large"
    >
        <x-slot name="tabs">
            @role('Manager|Super Manager')
            <a href="{{ route('admin.sliders.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.sliders.*') ? '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-images text-sm"></i> Hero Slider
            </a>
            <a href="{{ route('admin.hero-cards.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.hero-cards.index') ? '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-th-large text-sm"></i> All Cards
            </a>
            <a href="{{ route('admin.hero-cards.create') }}"
               class="module-hero-tab {{ request()->routeIs('admin.hero-cards.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-plus text-sm"></i> Add Card
            </a>
            @endrole
            @can('manage what we do images')
            <a href="{{ route('admin.what-we-do-images.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.what-we-do-images.*') ? '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-image text-sm"></i> What We Do Images
            </a>
            @endcan
            @can('view pages')
            <a href="{{ route('admin.pages.index') }}"
               class="module-hero-tab {{ request()->routeIs('admin.pages.*') ? '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> Pages
            </a>
            @endcan
        </x-slot>
        <x-slot name="actions">
            <a href="{{ route('admin.hero-cards.create') }}"
               class="inline-flex items-center gap-2 px-4 py-2 bg-white text-[#1a4731] text-sm font-semibold rounded-lg hover:bg-white/90 transition">
                <i class="fas fa-plus"></i> Add Card
            </a>
        </x-slot>
    </x-module-hero>

    <div class="p-6">

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

        {{-- Stats row --}}
        <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
            <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4 flex items-center gap-4">
                <div class="w-12 h-12 rounded-full bg-teal-100 flex items-center justify-center">
                    <i class="fas fa-th-large text-teal-600 text-xl"></i>
                </div>
                <div>
                    <p class="text-xs text-gray-500 font-medium uppercase tracking-wide">Total Cards</p>
                    <p class="text-2xl font-bold text-gray-800">{{ $heroCards->count() }}</p>
                </div>
            </div>
            <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4 flex items-center gap-4">
                <div class="w-12 h-12 rounded-full bg-green-100 flex items-center justify-center">
                    <i class="fas fa-eye text-green-600 text-xl"></i>
                </div>
                <div>
                    <p class="text-xs text-gray-500 font-medium uppercase tracking-wide">Active</p>
                    <p class="text-2xl font-bold text-gray-800">{{ $heroCards->where('is_active', true)->count() }}</p>
                </div>
            </div>
            <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-4 flex items-center gap-4">
                <div class="w-12 h-12 rounded-full bg-gray-100 flex items-center justify-center">
                    <i class="fas fa-eye-slash text-gray-500 text-xl"></i>
                </div>
                <div>
                    <p class="text-xs text-gray-500 font-medium uppercase tracking-wide">Inactive</p>
                    <p class="text-2xl font-bold text-gray-800">{{ $heroCards->where('is_active', false)->count() }}</p>
                </div>
            </div>
        </div>

        {{-- Table --}}
        <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
            @if($heroCards->isEmpty())
                <div class="text-center py-16">
                    <i class="fas fa-th-large text-5xl text-gray-300 mb-4 block"></i>
                    <h3 class="text-lg font-semibold text-gray-700 mb-2">No hero cards yet</h3>
                    <p class="text-gray-500 mb-6">Add your first info card to display below the slider.</p>
                    <a href="{{ route('admin.hero-cards.create') }}"
                       class="inline-flex items-center gap-2 px-5 py-2.5 bg-[#1a4731] text-white font-semibold rounded-lg hover:bg-[#276749] transition">
                        <i class="fas fa-plus"></i> Add Card
                    </a>
                </div>
            @else
                <div class="overflow-x-auto">
                    <table class="w-full table-zebra">
                        <thead>
                            <tr>
                                <th class="px-4 py-3 text-left th-col-1">Colour</th>
                                <th class="px-4 py-3 text-left th-col-2">Title</th>
                                <th class="px-4 py-3 text-left th-col-3">Content</th>
                                <th class="px-4 py-3 text-left th-col-4">Order</th>
                                <th class="px-4 py-3 text-left th-col-5">Status</th>
                                <th class="px-4 py-3 text-right th-col-6">Actions</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach($heroCards as $card)
                                <tr class="odd:bg-white even:bg-gray-50 hover:bg-gray-100 transition-colors border-b border-gray-100 last:border-0">
                                    <td class="px-4 py-3">
                                        <div class="w-10 h-10 rounded-lg {{ $card->background_color }} shadow-sm border border-gray-200"
                                             title="{{ $card->background_color }}"></div>
                                    </td>
                                    <td class="px-4 py-3">
                                        <p class="text-sm font-semibold text-gray-800">{{ $card->title }}</p>
                                        <p class="text-xs text-gray-400 mt-0.5 font-mono">{{ $card->background_color }}</p>
                                    </td>
                                    <td class="px-4 py-3 max-w-xs">
                                        <p class="text-sm text-gray-600 truncate">{{ Str::limit($card->content, 60) }}</p>
                                    </td>
                                    <td class="px-4 py-3">
                                        <span class="text-sm text-gray-600 font-mono">{{ $card->order }}</span>
                                    </td>
                                    <td class="px-4 py-3">
                                        @if($card->is_active)
                                            <span class="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-green-100 text-green-800">
                                                <i class="fas fa-circle text-green-500" style="font-size:6px"></i> Active
                                            </span>
                                        @else
                                            <span class="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-gray-100 text-gray-600">
                                                <i class="fas fa-circle text-gray-400" style="font-size:6px"></i> Inactive
                                            </span>
                                        @endif
                                    </td>
                                    <td class="px-4 py-3">
                                        <div class="flex items-center justify-end gap-2">
                                            <a href="{{ route('admin.hero-cards.edit', $card) }}"
                                               class="btn-action-edit">
                                                <i class="fas fa-edit"></i> Edit
                                            </a>
                                            <form action="{{ route('admin.hero-cards.destroy', $card) }}" method="POST"
                                                  onsubmit="return confirm('Delete this hero card? This cannot be undone.')">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit" class="btn-action-delete">
                                                    <i class="fas fa-trash"></i> Delete
                                                </button>
                                            </form>
                                        </div>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
            @endif
        </div>

    </div>
</x-app-layout>
