<div>
    {{-- Cabecera --}}
    <div class="w-full flex items-center mb-8">
        <a href="{{ route('products.show', $product) }}"
            class="flex rounded-lg bg-white border border-gray-200 px-4 py-2 text-gray-700 hover:bg-gray-100 font-bold">
            <img src="{{ asset('vendor/blade-untitledui-icons/arrow-narrow-left.svg') }}" alt="Volver" class="w-6 h-6">
            <span class="ml-2">Volver</span>
        </a>
    </div>

    {{-- Mensajes de éxito/error --}}
    @if (session()->has('success'))
        <div class="mb-4 rounded bg-green-100 px-4 py-2 text-green-700">
            {{ session('success') }}
        </div>
    @endif

    @if (session()->has('error'))
        <div class="mb-4 rounded bg-red-100 px-4 py-2 text-red-700">
            {{ session('error') }}
        </div>
    @endif

    {{-- Información del producto --}}
    <div class="w-full flex flex-wrap items-center justify-between rounded-lg bg-white border border-gray-200 px-8 py-4 mb-6">
        <div class="w-full flex items-center justify-between">
            <div class="flex items-center gap-4">
                {{-- Logo del producto --}}
                <div class="flex items-center justify-center w-16 h-16 rounded-lg bg-white border border-gray-200 p-2">
                    <img src="{{ $product->image_url ?? asset('images/placeholder.png') }}" alt="{{ $product->name }}"
                        class="w-full h-full object-contain">
                </div>
                <div>
                    <h1 class="text-4xl font-bold">Setups - {{ $product->name }}</h1>
                </div>
            </div>
        </div>
    </div>

    {{-- Búsqueda y filtros --}}
    <div class="mb-6 rounded-lg bg-white border border-gray-200 px-6 py-4">
        <div class="flex items-center justify-between gap-4">
            <div class="flex items-center gap-4 flex-1">
                <div class="w-64">
                    <input
                        type="text"
                        wire:model.live.debounce.300ms="search"
                        placeholder="Buscar producto o versión..."
                        class="w-full rounded-lg border border-gray-200 px-4 py-2 focus:outline-none focus:ring-2 focus:ring-orange-300"
                    >
                </div>

                <div class="w-48">
                    <select
                        wire:model.live="statusFilter"
                        class="w-full rounded-lg border border-gray-200 px-4 py-2 focus:outline-none focus:ring-2 focus:ring-orange-300"
                    >
                        <option value="">Todos los estados</option>
                        <option value="active">Activos</option>
                        <option value="deprecated">Deprecados</option>
                    </select>
                </div>
            </div>

            <a href="{{ route('products.setups.create', $product) }}"
               class="flex items-center rounded-lg bg-orange-600 px-4 py-2 text-white hover:bg-orange-700 font-semibold">
                <img src="{{ asset('vendor/blade-untitledui-icons/plus.svg') }}" alt="Crear" class="w-5 h-5 mr-2 svg-fill-white">
                Crear setup
            </a>
        </div>
    </div>

    {{-- Tabla de setups --}}
    <div class="rounded-lg bg-white border border-gray-200 overflow-hidden">
        <div class="overflow-x-auto">
            <table class="min-w-full text-sm">
                <thead class="bg-gray-100 text-xs uppercase text-gray-600">
                <tr>
                    <th class="px-4 py-3 text-left">Versión</th>
                    <th class="px-4 py-3 text-left">Estado</th>
                    <th class="px-4 py-3 text-left">Creado por</th>
                    <th class="px-4 py-3 text-left">Fecha</th>
                    <th class="px-4 py-3 text-right">Acciones</th>
                </tr>
                </thead>

                <tbody class="divide-y">
                @forelse ($setups as $setup)
                    <tr class="hover:bg-gray-50">
                        <td class="px-4 py-3 font-mono font-semibold">{{ $setup->version }}</td>

                        <td class="px-4 py-3">
                            @if($setup->status === 'active')
                                <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-semibold bg-green-100 text-green-800">Activo</span>
                            @else
                                <span class="inline-flex items-center px-2 py-1 rounded-full text-xs font-semibold bg-gray-100 text-gray-800">Deprecado</span>
                            @endif
                        </td>

                        <td class="px-4 py-3 text-gray-700">{{ $setup->creator?->name ?? 'N/A' }}</td>

                        <td class="px-4 py-3 text-gray-700">{{ $setup->created_at->format('Y-m-d H:i') }}</td>

                        <td class="px-4 py-3 text-right">
                            <div class="flex items-center justify-end gap-2">
                                <a href="{{ route('products.setups.show', [$product, $setup]) }}"
                                   class="text-indigo-600 hover:text-indigo-800 text-xs font-semibold">
                                    Ver →
                                </a>
                                <a href="{{ route('products.setups.edit', [$product, $setup]) }}"
                                   class="text-orange-600 hover:text-orange-800 text-xs font-semibold">
                                    Editar
                                </a>

                                <button wire:click="duplicate({{ $setup->id }})"
                                        wire:confirm="¿Seguro que deseas duplicar este setup? Se creará una nueva versión automáticamente."
                                        class="text-green-600 hover:text-green-800 text-xs font-semibold">
                                    Duplicar
                                </button>

                                @if($setup->status === 'active')
                                    <button wire:click="toggleStatus({{ $setup->id }})"
                                            wire:confirm="¿Seguro que deseas marcar este setup como deprecado?"
                                            class="text-orange-600 hover:text-orange-800 text-xs font-semibold">
                                        Deprecar
                                    </button>
                                @else
                                    <button wire:click="toggleStatus({{ $setup->id }})"
                                            wire:confirm="¿Seguro que deseas reactivar este setup?"
                                            class="text-green-600 hover:text-green-800 text-xs font-semibold">
                                        Activar
                                    </button>
                                @endif
                            </div>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="5" class="px-4 py-8 text-center text-gray-500">
                            <div class="flex flex-col items-center">
                                <p class="text-sm">No hay setups.</p>
                                <a href="{{ route('products.setups.create', $product) }}"
                                   class="mt-4 rounded-lg bg-orange-600 px-4 py-2 text-sm text-white hover:bg-orange-700 font-semibold">
                                    Crear el primer setup
                                </a>
                            </div>
                        </td>
                    </tr>
                @endforelse
                </tbody>
            </table>
        </div>
    </div>

    {{-- Paginación --}}
    @if($setups->hasPages())
        <div class="mt-6">
            {{ $setups->links() }}
        </div>
    @endif
</div>
