@extends('layouts.app')

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

@section('content')
    @include('partials.flash')
    <div class="mb-6 flex flex-wrap items-center justify-between gap-3">
        <p class="text-slate-600">Transforme cada proprietário em uma nova oportunidade de captação.</p>
        <div class="flex gap-2">
            <a href="{{ route('owners.kanban') }}" class="rounded-lg border border-slate-300 px-4 py-2 text-sm font-medium">Kanban</a>
            <a href="{{ route('owners.create') }}" class="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-semibold text-white">Novo proprietário</a>
        </div>
    </div>
    <div class="mb-6 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
        <div class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
            <p class="text-xs uppercase text-slate-500">Em captação</p>
            <p class="mt-1 text-2xl font-semibold">{{ $dashboard['open_captures'] }}</p>
        </div>
        <div class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
            <p class="text-xs uppercase text-slate-500">Contratos a vencer</p>
            <p class="mt-1 text-2xl font-semibold">{{ $dashboard['expiring_agreements'] }}</p>
        </div>
        <div class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
            <p class="text-xs uppercase text-slate-500">Exclusividades</p>
            <p class="mt-1 text-2xl font-semibold">{{ $dashboard['exclusive_agreements'] }}</p>
        </div>
        <div class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
            <p class="text-xs uppercase text-slate-500">Conversão</p>
            <p class="mt-1 text-2xl font-semibold">{{ $dashboard['conversion_rate'] !== null ? $dashboard['conversion_rate'].'%' : '—' }}</p>
        </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 text-left text-xs font-semibold uppercase text-slate-500">
                <tr>
                    <th class="px-4 py-3">Proprietário</th>
                    <th class="px-4 py-3">Documento</th>
                    <th class="px-4 py-3">Contato</th>
                    <th class="px-4 py-3"></th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-100">
                @forelse ($owners as $owner)
                    <tr>
                        <td class="px-4 py-3 font-medium">{{ $owner->name }}</td>
                        <td class="px-4 py-3">{{ $owner->document ?? '—' }}</td>
                        <td class="px-4 py-3">{{ $owner->contacts->first()?->value ?? '—' }}</td>
                        <td class="px-4 py-3 text-right"><a href="{{ route('owners.show', $owner) }}" class="text-emerald-700 hover:underline">Abrir</a></td>
                    </tr>
                @empty
                    <tr><td colspan="4" class="px-4 py-8 text-center text-slate-500">Nenhum proprietário.</td></tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="mt-4">{{ $owners->links() }}</div>
@endsection
