@extends('layouts.app')

@section('title', 'Gallery Types')

@section('content')
<x-app-layout>
    <x-module-hero
        title="Gallery Types"
        description="Manage pictorial gallery categories and types"
        icon="fa-layer-group">

        <x-slot name="backButton">
            <a href="{{ route('dashboard') }}"
               class="inline-flex items-center gap-2 text-[#475569] hover:text-[#1e293b] text-sm transition">
                <i class="fas fa-arrow-left text-xs"></i> Back to Dashboard
            </a>
        </x-slot>

        <x-slot name="actions">
            @can('create gallery types')
            <a href="{{ route('media.gallery-types.create') }}"
               class="inline-flex items-center gap-2 px-4 py-2 bg-[#1e293b] text-white text-sm font-semibold rounded-lg hover:bg-[#334155] transition">
                <i class="fas fa-plus"></i> Create Gallery Type
            </a>
            @endcan
        </x-slot>
    </x-module-hero>

    <div class="p-6">
        {{-- Flash Messages --}}
        @if(session('success'))
        <div class="mb-6 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>
            <span>{{ session('success') }}</span>
        </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 gap-2">
            <i class="fas fa-times-circle"></i>
            <span>{{ session('error') }}</span>
        </div>
        @endif

        {{-- Search Form --}}
        <div class="mb-6 bg-white rounded-lg shadow-sm border border-gray-200 p-4">
            <form method="GET" action="{{ route('media.gallery-types.index') }}" class="flex gap-4">
                <div class="flex-1">
                    <input type="text" name="search" placeholder="Search gallery types..."
                           value="{{ request('search') }}"
                           class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                </div>
                <button type="submit" class="px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">
                    <i class="fas fa-search"></i> Search
                </button>
                @if(request('search'))
                <a href="{{ route('media.gallery-types.index') }}" class="px-4 py-2 bg-gray-300 text-gray-700 rounded-lg hover:bg-gray-400 transition">
                    <i class="fas fa-times"></i> Clear
                </a>
                @endif
            </form>
        </div>

        {{-- Gallery Types Grid --}}
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
            @forelse ($galleryTypes as $type)
                <div class="bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden hover:shadow-md transition-shadow">
                    {{-- Header with Color Indicator --}}
                    <div class="h-1" style="background-color: {{ $type->color }}"></div>

                    <div class="p-6">
                        {{-- Title & Icon --}}
                        <div class="flex items-start gap-3 mb-3">
                            <div class="p-3 rounded-lg" style="background-color: {{ $type->color }}20">
                                <i class="fas {{ $type->icon }} text-xl" style="color: {{ $type->color }}"></i>
                            </div>
                            <div class="flex-1">
                                <h3 class="font-semibold text-gray-900">{{ $type->name }}</h3>
                                <p class="text-xs text-gray-500">
                                    <i class="fas fa-images"></i>
                                    {{ $type->getGalleryCount() }} galleries
                                </p>
                            </div>
                        </div>

                        {{-- Description --}}
                        @if($type->description)
                        <p class="text-sm text-gray-600 mb-4 line-clamp-2">{{ $type->description }}</p>
                        @endif

                        {{-- Status Badge --}}
                        <div class="mb-4">
                            <span class="inline-block px-3 py-1 text-xs font-semibold rounded-full
                                {{ $type->is_active ? 'bg-green-100 text-green-800' : 'bg-gray-100 text-gray-800' }}">
                                {{ $type->is_active ? 'Active' : 'Inactive' }}
                            </span>
                        </div>

                        {{-- Actions --}}
                        <div class="flex gap-2 pt-4 border-t border-gray-200">
                            <a href="{{ route('media.gallery-types.show', $type) }}"
                               class="flex-1 px-3 py-2 text-center text-sm bg-blue-50 text-blue-600 rounded-lg hover:bg-blue-100 transition font-medium">
                                <i class="fas fa-eye"></i> View
                            </a>
                            @can('edit gallery types')
                            <a href="{{ route('media.gallery-types.edit', $type) }}"
                               class="flex-1 px-3 py-2 text-center text-sm bg-amber-50 text-amber-600 rounded-lg hover:bg-amber-100 transition font-medium">
                                <i class="fas fa-edit"></i> Edit
                            </a>
                            @endcan
                            @can('delete gallery types')
                            <form action="{{ route('media.gallery-types.destroy', $type) }}" method="POST" class="flex-1"
                                  onsubmit="return confirm('Delete this gallery type?');">
                                @csrf @method('DELETE')
                                <button type="submit"
                                    class="w-full px-3 py-2 text-sm bg-red-50 text-red-600 rounded-lg hover:bg-red-100 transition font-medium">
                                    <i class="fas fa-trash"></i> Delete
                                </button>
                            </form>
                            @endcan
                        </div>
                    </div>
                </div>
            @empty
                <div class="col-span-3">
                    <div class="bg-white rounded-lg shadow-sm border border-gray-200 p-12 text-center">
                        <i class="fas fa-inbox text-5xl text-gray-300 mb-4"></i>
                        <h3 class="text-xl font-semibold text-gray-700 mb-2">No Gallery Types Found</h3>
                        <p class="text-gray-500 mb-6">Create your first gallery type to get started organizing your galleries.</p>
                        @can('create gallery types')
                        <a href="{{ route('media.gallery-types.create') }}" class="inline-flex items-center gap-2 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition">
                            <i class="fas fa-plus"></i> Create Gallery Type
                        </a>
                        @endcan
                    </div>
                </div>
            @endforelse
        </div>

        {{-- Pagination --}}
        @if($galleryTypes->hasPages())
        <div class="mt-8">
            {{ $galleryTypes->links() }}
        </div>
        @endif
    </div>
</x-app-layout>
@endsection
