<x-layout title="Nuevo Producto">
    
    <x-section-header subtitle="Ventas" title="Registro de " :highlight="'ventas ' . ' '" />
    <!-- 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="{{ url('sales') }}" method="GET" class="flex flex-row w-full max-w-3xl gap-4">
            <div class="relative w-2/3">
                <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>
            <div class="w-1/3">
                <x-forms.select id="type" name="type" :error="$errors->first('type')" placeholder="Filtro...">
                    <option value="bike" class="bg-neutral-800">Bicicleta</option>
                    <option value="accessory" class="bg-neutral-800">Accesorio</option>
                    <option value="service" class="bg-neutral-800">Servicio</option>
                </x-forms.select>
            </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">
            + Registrar Venta
        </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">ID Venta</th>
                    <th scope="col" class="px-6 py-3">Descripcion</th>
                    <th scope="col" class="px-6 py-3">Cant. Productos</th>
                    <th scope="col" class="px-6 py-3 text-center">Total Venta</th>
                    <th scope="col" class="px-6 py-3 text-right">Acciones</th>
                </tr>
            </thead>
            <tbody>
                @forelse($sales 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-gray-500 font-mono">{{ $product->sku }}</div>
                    </td>
                    <td class="px-6 py-4 font-medium text-white whitespace-nowrap">
                        <div class="text-base font-bold">{{ $product->name }}</div>
                    </td>
                    <td class="px-6 py-4 font-mono text-white">
                        {{ $product->stock_quantity }}
                    </td>
                    <td class="px-6 py-4 font-mono text-white text-center">
                        ${{ number_format(($product->price * 2), 2) }}
                        {{-- @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">
        {{ $sales->links() }}
    </div>

</x-layout>