{{-- <x-appc>
    <x-slot name="title">Lauck - Home - Productos</x-slot>
    <x-slot name="navTitle">Productos</x-slot>

    <div class="w-6xl mx-auto flex flex-col justify-start items-stretch gap-5 my-5">
        <a href="{{route('productos.create')}}" class="w-fit mx-auto px-4 py-2 rounded-full text-white font-semibold bg-stone-500 hover:scale-105 transition">
            Agregar Producto
        </a>
        <div class="overflow-x-auto rounded-lg shadow-xl">
            <table class="w-full min-w-xl text-sm text-left rtl:text-right text-neutral-500 dark:text-neutral-400">
                <thead class="text-xs text-neutral-700 uppercase bg-neutral-50 dark:bg-neutral-700 dark:text-neutral-400">
                    <tr>
                        <th scope="col" class="px-6 py-3">Nombre</th>
                        <th scope="col" class="px-6 py-3">Marca</th>
                        <th scope="col" class="px-6 py-3">Modelo</th>
                        <th scope="col" class="px-6 py-3">Rodado</th>
                        <th scope="col" class="px-6 py-3">Color</th>
                        <th scope="col" class="px-6 py-3">Tipo</th>
                        <th scope="col" class="px-6 py-3">Precio</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach ($products as $prod)
                        <tr class="bg-white border-b dark:bg-neutral-800 dark:border-neutral-700 border-neutral-200">
                            <th scope="row"
                                class="px-6 py-4 font-medium text-neutral-900 whitespace-nowrap dark:text-white">
                                <a href="{{route('productos.show',$prod)}}">{{ $prod->name }}</a>
                            </th>
                            <td class="px-6 py-4">{{ $prod->marca }}</td>
                            <td class="px-6 py-4">{{ $prod->modelo }}</td>
                            <td class="px-6 py-4">{{ $prod->rodado }}</td>
                            <td class="px-6 py-4">{{ $prod->color }}</td>
                            <td class="px-6 py-4">{{ $prod->tipo }}</td>
                            <td class="px-6 py-4">{{ $prod->precio }}</td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>

        {{$products->links()}}
    </div>

</x-appc> --}}

<x-layout title="Stock - Lauck">
    
    <x-section-header subtitle="Gestión de Inventario" title="Listado de " highlight="Productos" />

    <!-- Mensajes de feedback -->
    <x-ui.alert />

    <!-- Barra de Herramientas (Buscador + Botón Crear) -->
    <div class="w-full flex flex-col md:flex-row justify-between items-center gap-4 mb-6">
        
        <!-- Buscador -->
        <form action="{{ route('productos.index') }}" method="GET" class="w-full md:w-1/2">
            <div class="relative">
                <div class="absolute inset-y-0 start-0 flex items-center ps-3 pointer-events-none">
                    <svg class="w-4 h-4 text-gray-500" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 20 20">
                        <path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 19-4-4m0-7A7 7 0 1 1 1 8a7 7 0 0 1 14 0Z"/>
                    </svg>
                </div>
                <input type="text" name="search" value="{{ request('search') }}" 
                    class="block w-full p-3 ps-10 text-sm text-white border border-neutral-700 rounded-lg bg-neutral-800 focus:ring-neon-lime focus:border-neon-lime placeholder-gray-500" 
                    placeholder="Buscar por nombre, SKU o marca...">
            </div>
        </form>

        <!-- Botón Nuevo -->
        <a href="{{ route('productos.create') }}" class="w-full md:w-auto text-center px-5 py-3 text-sm font-bold text-neutral-900 bg-neon-lime rounded-lg hover:bg-[#b3e600] transition-colors uppercase tracking-wide">
            + Nuevo Producto
        </a>
    </div>

    <!-- Tabla de Productos -->
    <div class="relative overflow-x-auto shadow-md sm:rounded-lg border border-neutral-800 w-full">
        <table class="w-full text-sm text-left rtl:text-right text-gray-400">
            <thead class="text-xs text-gray-300 uppercase bg-neutral-800 border-b border-neutral-700">
                <tr>
                    <th scope="col" class="px-6 py-3">Producto / SKU</th>
                    <th scope="col" class="px-6 py-3">Tipo</th>
                    <th scope="col" class="px-6 py-3">Precio</th>
                    <th scope="col" class="px-6 py-3 text-center">Stock</th>
                    <th scope="col" class="px-6 py-3 text-right">Acciones</th>
                </tr>
            </thead>
            <tbody>
                @forelse($products as $product)
                <tr class="bg-neutral-900/50 border-b border-neutral-800 hover:bg-neutral-800 transition-colors group">
                    <td class="px-6 py-4 font-medium text-white whitespace-nowrap">
                        <div class="text-base font-bold">{{ $product->name }}</div>
                        <div class="text-xs text-gray-500 font-mono">{{ $product->sku }}</div>
                    </td>
                    <td class="px-6 py-4">
                        @if($product->type === 'bike') <x-ui.badge color="neon">Bicicleta</x-ui.badge>
                        @elseif($product->type === 'accessory') <x-ui.badge color="gray">Accesorio</x-ui.badge>
                        @else <x-ui.badge color="yellow">Servicio</x-ui.badge> @endif
                    </td>
                    <td class="px-6 py-4 font-mono text-white">
                        ${{ number_format($product->price, 2) }}
                    </td>
                    <td class="px-6 py-4 text-center">
                        @if($product->type === 'service')
                            <span class="text-gray-600">-</span>
                        @elseif($product->stock_quantity <= $product->min_stock_alert)
                            <x-ui.badge color="red">{{ $product->stock_quantity }}</x-ui.badge>
                        @else
                            <x-ui.badge color="green">{{ $product->stock_quantity }}</x-ui.badge>
                        @endif
                    </td>
                    <td class="px-6 py-4 text-right">
                        <a href="{{ route('productos.edit', $product) }}" class="font-medium text-blue-400 hover:underline mr-3">Editar</a>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="5" class="px-6 py-10 text-center text-gray-500">
                        No se encontraron productos.
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <!-- Paginación -->
    <div class="mt-4 w-full">
        {{ $products->links() }}
    </div>

</x-layout>