@extends('layouts.app')
@section('titulo','Repuestos')
@section('contenido')
<div class="d-flex flex-wrap justify-content-between align-items-center mb-3">
  <h4><i class="fa fa-box"></i> Repuestos / inventario</h4>
  @can('repuestos.gestionar')<a href="{{ route('repuestos.create') }}" class="btn btn-primario"><i class="fa fa-plus"></i> Nuevo</a>@endcan
</div>
<form method="GET" class="mb-3"><div class="input-group">
  <input name="q" value="{{ $busqueda }}" class="form-control" placeholder="Buscar por código o nombre">
  <button class="btn btn-outline-primary"><i class="fa fa-search"></i></button>
</div></form>
<div class="card"><div class="table-responsive"><table class="table table-hover mb-0">
<thead><tr><th>Código</th><th>Nombre</th><th>Unidad</th><th class="text-end">Stock</th><th class="text-end">Mínimo</th><th class="text-end">Costo</th><th>Activo</th><th></th></tr></thead><tbody>
@forelse($registros as $rp)
<tr class="{{ $rp->stock < $rp->stock_minimo ? 'table-warning' : '' }}">
  <td><strong>{{ $rp->codigo }}</strong></td>
  <td>{{ $rp->nombre }}</td>
  <td>{{ optional($rp->unidad)->codigo }}</td>
  <td class="text-end">{{ $rp->stock }}</td>
  <td class="text-end">{{ $rp->stock_minimo }}</td>
  <td class="text-end">{{ number_format($rp->costo_unitario,2) }}</td>
  <td><span class="badge text-bg-{{ $rp->activo?'success':'secondary' }}">{{ $rp->activo?'Sí':'No' }}</span></td>
  <td class="text-end">
    @can('repuestos.gestionar')
    <a href="{{ route('repuestos.edit',$rp) }}" class="btn btn-sm btn-outline-primary"><i class="fa fa-pen"></i></a>
    <form method="POST" action="{{ route('repuestos.destroy',$rp) }}" class="d-inline" onsubmit="return confirm('¿Eliminar?');">
      @csrf @method('DELETE')<button class="btn btn-sm btn-outline-danger"><i class="fa fa-trash"></i></button></form>
    @endcan
  </td>
</tr>
@empty <tr><td colspan="8" class="text-muted text-center py-4">Sin repuestos</td></tr> @endforelse
</tbody></table></div></div>
<div class="mt-2">{{ $registros->links() }}</div>
@endsection
