@extends('layouts.app')
@section('titulo','Equipos')
@section('contenido')
<div class="d-flex flex-wrap justify-content-between align-items-center mb-3">
  <h4><i class="fa fa-gear"></i> Equipos</h4>
  <a href="{{ route('equipos.create') }}" class="btn btn-primario"><i class="fa fa-plus"></i> Nuevo</a>
</div>
<form method="GET" class="row g-2 mb-3">
  <div class="col-md-3"><input name="q" value="{{ $busqueda }}" class="form-control" placeholder="Buscar..."></div>
  <div class="col-md-3"><select name="area_id" class="form-select"><option value="">— Área —</option>
    @foreach($areas as $a)<option value="{{ $a->id }}" @selected($area_id==$a->id)>{{ $a->nombre }}</option>@endforeach
  </select></div>
  <div class="col-md-3"><select name="sistema_id" class="form-select"><option value="">— Sistema —</option>
    @foreach($sistemas as $s)<option value="{{ $s->id }}" @selected($sistema_id==$s->id)>{{ $s->nombre }}</option>@endforeach
  </select></div>
  <div class="col-md-2"><button class="btn btn-outline-primary w-100"><i class="fa fa-filter"></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>Área</th><th>Sistema</th><th>Comp.</th><th>OT</th><th>Activo</th><th></th></tr></thead><tbody>
@forelse($registros as $e)
<tr>
  <td><strong>{{ $e->codigo }}</strong></td>
  <td>{{ $e->nombre }}</td>
  <td>{{ optional($e->area)->nombre }}</td>
  <td>{{ optional($e->sistema)->nombre }}</td>
  <td>{{ $e->componentes_count }}</td>
  <td>{{ $e->ordenes_count }}</td>
  <td><span class="badge text-bg-{{ $e->activo?'success':'secondary' }}">{{ $e->activo?'Sí':'No' }}</span></td>
  <td class="text-end">
    <a href="{{ route('equipos.edit',$e) }}" class="btn btn-sm btn-outline-primary"><i class="fa fa-pen"></i></a>
    <form method="POST" action="{{ route('equipos.destroy',$e) }}" 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>
  </td>
</tr>
@empty <tr><td colspan="8" class="text-muted text-center py-4">Sin equipos</td></tr> @endforelse
</tbody></table></div></div>
<div class="mt-2">{{ $registros->links() }}</div>
@endsection
