@extends('layout')
@section('title', 'Users')
@section('content')
<div class="page-header">
    <h1>Users</h1>
    <a href="{{ route('users.create') }}" class="btn btn-primary">Add user</a>
</div>

<div class="card">
    <div class="table-wrap">
    <table>
        <thead><tr><th>Name</th><th>Email</th><th>Role</th><th>Site</th><th></th></tr></thead>
        <tbody>
        @forelse($users as $user)
            <tr>
                <td>{{ $user->name }}</td>
                <td>{{ $user->email }}</td>
                <td><span class="badge badge-gray">{{ $user->role }}</span></td>
                <td>{{ $user->site->name ?? 'All sites' }}</td>
                <td>
                    <a href="{{ route('users.edit', $user) }}" class="btn btn-sm">Edit</a>
                    <form method="POST" action="{{ route('users.destroy', $user) }}" style="display:inline" onsubmit="return confirm('Remove this user?')">
                        @csrf
                        @method('DELETE')
                        <button type="submit" class="btn btn-sm btn-danger">Remove</button>
                    </form>
                </td>
            </tr>
        @empty
            <tr><td colspan="5" class="empty-state">No users found.</td></tr>
        @endforelse
        </tbody>
    </table>
    </div>
</div>
@endsection
