@extends('layouts.app')
@section('title','Users')
@section('crumbs','<b>Users</b>')
@section('content')
<div class="card"><div class="card-h"><h2>Users</h2><div class="sp">@if(perm('users.create'))<a class="btn btn-pri btn-sm" href="{{ route('users.create') }}">+ New user</a>@endif</div></div>
<div class="card-b">
<form method="GET" class="toolbar no-print"><input type="search" name="q" value="{{ request('q') }}" placeholder="Search name, email, username…"><button class="btn btn-sm">Search</button></form>
<div class="twrap"><table class="tbl"><thead><tr><th>Name</th><th>Username</th><th>Email</th><th>Roles</th><th>Last login</th><th>Active</th><th class="no-print">Actions</th></tr></thead>
<tbody>@forelse($rows as $u)<tr><td><b>{{ $u->name }}</b></td><td>{{ $u->username }}</td><td>{{ $u->email }}</td>
<td>@foreach($u->roles as $r)<span class="bdg b-info">{{ $r->name }}</span> @endforeach</td>
<td class="small">{{ $u->last_login_at?->format('d M Y H:i') ?? '—' }}</td>
<td>{!! $u->is_active?'<span class="bdg b-ok">Yes</span>':'<span class="bdg b-bad">No</span>' !!}</td>
<td class="no-print"><div class="row-actions">
@if(perm('users.edit'))<a class="btn btn-sm btn-ghost" href="{{ route('users.edit',$u->id) }}">Edit</a>@endif
<a class="btn btn-sm btn-ghost" href="{{ route('users.logins',$u->id) }}">Logins</a>
@if(perm('users.delete') && $u->id!==auth()->id())<form method="POST" action="{{ route('users.destroy',$u->id) }}" data-confirm="Delete user?" style="display:inline">@csrf @method('DELETE')<button class="btn btn-sm btn-danger">Del</button></form>@endif
</div></td></tr>@empty<tr><td colspan="7" class="muted c">No users.</td></tr>@endforelse</tbody></table></div>
{{ $rows->links() }}
</div></div>
@endsection
