@extends('layouts.app')

@section('content')
<div class="container-fluid">
    <h1 class="h3 mb-3">Consultar entradas de inventario</h1>

    <div class="card mb-3">
        <div class="card-body">
            <form action="{{ route('consultas.entradas.filtrar') }}" method="POST" class="row g-2 align-items-end">
                @csrf
                <div class="col-md-4">
                    <label class="form-label">Producto</label>
                    <input type="text" name="producto" class="form-control" value="{{ $filtro['producto'] ?? '' }}">
                </div>
                <div class="col-md-3">
                    <label class="form-label">Desde</label>
                    <input type="date" name="desde" class="form-control" value="{{ $filtro['desde'] ?? '' }}">
                </div>
                <div class="col-md-3">
                    <label class="form-label">Hasta</label>
                    <input type="date" name="hasta" class="form-control" value="{{ $filtro['hasta'] ?? '' }}">
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">Buscar</button>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="table-responsive">
            <table class="table table-striped mb-0">
                <thead>
                    <tr>
                        <th>Fecha</th>
                        <th>Producto</th>
                        <th>Proveedor</th>
                        <th>Cantidad</th>
                        <th>Stock resultante</th>
                        <th>Motivo</th>
                        <th>Registrado por</th>
                    </tr>
                </thead>
                <tbody>
                    @forelse ($entradas as $entrada)
                        <tr>
                            <td>{{ $entrada->created_at->format('d/m/Y H:i') }}</td>
                            <td>{{ $entrada->inventario->nombre }}</td>
                            <td>{{ $entrada->proveedor->nombre ?? '—' }}</td>
                            <td>+{{ $entrada->cantidad }}</td>
                            <td>{{ $entrada->stock_resultante }}</td>
                            <td>{{ $entrada->motivo }}</td>
                            <td>{{ $entrada->user->name }}</td>
                        </tr>
                    @empty
                        <tr><td colspan="7" class="text-center text-muted py-4">No se encontraron entradas con esos filtros.</td></tr>
                    @endforelse
                </tbody>
            </table>
        </div>
    </div>

    <div class="mt-3">
        {{ $entradas->links() }}
    </div>
</div>
@endsection
