@extends('layouts.app')

@section('title', 'Usuários — ImóvelZapAi')
@section('page-title', 'Usuários')

@section('content')
    @include('partials.flash')

    <div class="mb-6 flex flex-wrap items-center justify-between gap-3">
        <p class="text-slate-600">Usuários da imobiliária atual.</p>
        <div class="flex gap-2">
            <a href="{{ route('brokers.create') }}" class="rounded-lg border border-slate-300 px-4 py-2 text-sm font-medium text-slate-700 hover:bg-slate-50">
                Cadastrar corretor
            </a>
            <a href="{{ route('users.create') }}" class="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-semibold text-white hover:bg-emerald-500">
                Novo usuário
            </a>
        </div>
    </div>

    <div class="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
        <table class="min-w-full divide-y divide-slate-200 text-sm">
            <thead class="bg-slate-50">
                <tr>
                    <th class="px-4 py-3 text-left font-medium text-slate-600">Nome</th>
                    <th class="px-4 py-3 text-left font-medium text-slate-600">E-mail</th>
                    <th class="px-4 py-3 text-left font-medium text-slate-600">Papel</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-100">
                @forelse ($users as $user)
                    <tr>
                        <td class="px-4 py-3">{{ $user->name }}</td>
                        <td class="px-4 py-3">{{ $user->email }}</td>
                        <td class="px-4 py-3">{{ $user->getRoleNames()->first() ?? '—' }}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="px-4 py-6 text-center text-slate-500">Nenhum usuário cadastrado.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
@endsection
