@extends('layouts.app')
@section('titulo','Usuarios')
@section('contenido')
<div class="d-flex flex-wrap justify-content-between align-items-center mb-3">
  <h4><i class="fa fa-users"></i> Usuarios</h4>
  <a href="{{ route('usuarios.create') }}" class="btn btn-primario"><i class="fa fa-plus"></i> Nuevo</a>
</div>
<form method="GET" class="mb-3">
  <div class="input-group"><input name="q" value="{{ $busqueda }}" class="form-control" placeholder="Buscar...">
    <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>Usuario</th><th>Nombre</th><th>Cargo</th><th>Rol</th><th>Activo</th><th>Último acceso</th><th></th></tr></thead><tbody>
@forelse($registros as $u)
<tr>
  <td><strong>{{ $u->usuario }}</strong></td>
  <td>{{ $u->nombre_completo }}</td>
  <td>{{ $u->cargo }}</td>
  <td>@foreach($u->roles as $r)<span class="badge text-bg-info">{{ $r->name }}</span>@endforeach</td>
  <td><span class="badge text-bg-{{ $u->activo?'success':'secondary' }}">{{ $u->activo?'Sí':'No' }}</span></td>
  <td><small>{{ $u->ultimo_acceso?->format('d/m/Y H:i') ?? '—' }}</small></td>
  <td class="text-end">
    <a href="{{ route('usuarios.edit',$u) }}" class="btn btn-sm btn-outline-primary"><i class="fa fa-pen"></i></a>
    <form method="POST" action="{{ route('usuarios.destroy',$u) }}" 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="7" class="text-muted text-center py-4">Sin usuarios</td></tr> @endforelse
</tbody></table></div></div>
<div class="mt-2">{{ $registros->links() }}</div>
@endsection
