@extends('layouts.admin')
@section('title', 'Productos')
@section('content')
<div class="flex items-center justify-between mb-6">
    <h1 class="text-2xl font-semibold">Productos</h1>
    <a href="{{ route('admin.products.create') }}" class="bg-olive text-beige px-4 py-2 rounded-lg text-sm">+ Nuevo</a>
</div>

{{-- Carga masiva --}}
<div class="bg-white rounded-xl p-5 shadow-sm mb-6">
    <h2 class="font-semibold mb-3">Carga masiva (Excel)</h2>
    <div class="flex flex-wrap items-center gap-3">
        <a href="{{ route('admin.products.template') }}" class="text-olive underline text-sm">Descargar plantilla</a>
        <form method="POST" action="{{ route('admin.products.import') }}" enctype="multipart/form-data" class="flex items-center gap-2">
            @csrf
            <input type="file" name="file" accept=".xlsx,.xls,.csv" required class="text-sm">
            <button class="bg-olive text-beige px-4 py-2 rounded-lg text-sm">Importar</button>
        </form>
    </div>
</div>

<div class="bg-white rounded-xl shadow-sm overflow-hidden">
    <table class="w-full text-sm">
        <thead class="bg-gray-50 text-left text-gray-500">
            <tr><th class="p-3">Nombre</th><th class="p-3">Precio</th><th class="p-3">Stock</th><th class="p-3">Categoría</th><th class="p-3">Marca</th><th class="p-3"></th></tr>
        </thead>
        <tbody>
            @forelse($products as $p)
                <tr class="border-t">
                    <td class="p-3">{{ $p->name }}</td>
                    <td class="p-3">S/ {{ number_format($p->price, 2) }}</td>
                    <td class="p-3">{{ $p->stock }}</td>
                    <td class="p-3">{{ $p->category->name ?? '—' }}</td>
                    <td class="p-3">{{ $p->brand->name ?? '—' }}</td>
                    <td class="p-3 text-right whitespace-nowrap">
                        <a href="{{ route('admin.products.edit', $p) }}" class="text-olive">Editar</a>
                        <form method="POST" action="{{ route('admin.products.destroy', $p) }}" class="inline" onsubmit="return confirm('¿Eliminar?')">
                            @csrf @method('DELETE')
                            <button class="text-red-600 ml-2">Eliminar</button>
                        </form>
                    </td>
                </tr>
            @empty
                <tr><td colspan="6" class="p-6 text-center text-gray-400">Sin productos aún.</td></tr>
            @endforelse
        </tbody>
    </table>
</div>
<div class="mt-4">{{ $products->links() }}</div>
@endsection
