@extends('layouts.app')
@section('title','Users & Roles') @section('page_title','Users & Roles')
@section('content')
<div class="page-header"><div><h1>Users & Roles</h1><p class="muted">Control access by role and branch.</p></div><div class="actions">@if(auth()->user()->hasPermission('roles.create'))<a class="btn btn-secondary" href="{{ route('roles.create') }}">New Role</a>@endif @if(auth()->user()->hasPermission('users.create'))<a class="btn btn-primary" href="{{ route('users.create') }}">New User</a>@endif</div></div>
<div class="grid grid-3" style="margin-bottom:20px">@foreach($roles as $role)<div class="card"><div class="card-body"><div class="flex-between"><div><strong>{{ $role->name }}</strong><div class="muted">{{ $role->users_count }} user(s)</div></div>@if(auth()->user()->hasPermission('roles.edit_draft'))<a class="btn btn-secondary btn-sm" href="{{ route('roles.edit',$role) }}">Permissions</a>@endif</div></div></div>@endforeach</div>
<div class="card"><div class="card-header"><form class="filter-bar" method="get"><input class="control" name="search" value="{{ request('search') }}" placeholder="Search user or email"><button class="btn btn-secondary">Search</button></form></div><div class="table-wrap"><table><thead><tr><th>User</th><th>Branch</th><th>Roles</th><th>Last Login</th><th>Status</th><th></th></tr></thead><tbody>@forelse($users as $user)<tr><td><strong>{{ $user->name }}</strong><div class="muted">{{ $user->email }}</div></td><td>{{ $user->branch?->name ?? 'All branches' }}</td><td>@foreach($user->roles as $role)<span class="badge">{{ $role->name }}</span>@endforeach</td><td>{{ $user->last_login_at?->format('d M Y H:i') ?? 'Never' }}</td><td><span class="badge {{ $user->is_active?'badge-success':'badge-danger' }}">{{ $user->is_active?'Active':'Inactive' }}</span></td><td class="text-right">@if(auth()->user()->hasPermission('users.edit_draft'))<a class="btn btn-secondary btn-sm" href="{{ route('users.edit',$user) }}">Edit</a>@endif</td></tr>@empty<tr><td colspan="6" class="empty">No users found.</td></tr>@endforelse</tbody></table></div><div class="card-footer">{{ $users->links() }}</div></div>
@endsection
