@extends('layouts.app')

@section('title', 'Caixa de entrada — ImóvelZapAi')
@section('page-title', 'Caixa de entrada')

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

    <div class="mb-6 flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
        <p class="text-sm text-slate-600">
            Priorize quem precisa de resposta agora — como um e-mail organizado por urgência.
        </p>
        <a
            href="{{ route('people.index') }}"
            class="text-sm font-medium text-emerald-700 hover:text-emerald-800"
        >
            Ver funil completo →
        </a>
    </div>

    <div class="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm">
        @foreach ($sections as $section)
            @php
                $items = $grouped[$section->value] ?? collect();
                $count = $counts[$section->value] ?? 0;
            @endphp

            <section @class(['border-b border-slate-200 last:border-b-0' => true]) aria-label="{{ $section->label() }}">
                <header class="flex items-center gap-3 border-b border-slate-100 bg-slate-50 px-4 py-3">
                    <span class="text-lg" aria-hidden="true">{{ $section->icon() }}</span>
                    <h2 class="text-sm font-semibold text-slate-900">{{ $section->label() }}</h2>
                    @if ($count > 0)
                        <span @class([
                            'rounded-full px-2 py-0.5 text-xs font-semibold',
                            'bg-red-100 text-red-800' => $section === \ImovelZapAi\Conversations\Domain\Enums\InboxSection::RequiresResponse,
                            'bg-amber-100 text-amber-800' => $section === \ImovelZapAi\Conversations\Domain\Enums\InboxSection::HighInterest,
                            'bg-slate-200 text-slate-700' => ! in_array($section, [
                                \ImovelZapAi\Conversations\Domain\Enums\InboxSection::RequiresResponse,
                                \ImovelZapAi\Conversations\Domain\Enums\InboxSection::HighInterest,
                            ], true),
                        ])>{{ $count }}</span>
                    @endif
                </header>

                @if ($items->isEmpty())
                    <p class="px-4 py-6 text-center text-sm text-slate-400">Nenhuma conversa nesta seção.</p>
                @else
                    <ul class="divide-y divide-slate-100">
                        @foreach ($items as $item)
                            @include('conversations.people.partials.inbox-item', ['item' => $item])
                        @endforeach
                    </ul>
                @endif
            </section>
        @endforeach
    </div>
@endsection
