@extends('layouts.app')

@section('title', 'Relatório de importação — ImóvelZapAi')
@section('page-title', 'Relatório da importação')

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

    <div class="mb-6 flex flex-wrap items-center justify-between gap-3">
        <p class="text-slate-600">Resumo final da importação {{ $job->id }}.</p>
        <a href="{{ route('properties.index') }}" class="text-sm font-medium text-emerald-700 hover:underline">Ver imóveis</a>
    </div>

    <div class="mb-6 grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
        @foreach (['imported' => 'Importados', 'updated' => 'Atualizados', 'unchanged' => 'Ignorados (iguais)', 'ignored' => 'Ignorados', 'failed' => 'Erros', 'photos_imported' => 'Fotos'] as $key => $label)
            <div class="rounded-xl border border-slate-200 bg-white p-4 shadow-sm">
                <p class="text-xs uppercase text-slate-500">{{ $label }}</p>
                <p class="mt-1 text-2xl font-semibold text-slate-900">{{ $report['summary'][$key] ?? 0 }}</p>
            </div>
        @endforeach
    </div>

    @if (! empty($report['summary']['duration_seconds']))
        <p class="mb-4 text-sm text-slate-600">Duração total: {{ $report['summary']['duration_seconds'] }}s</p>
    @endif

    <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">Listing</th>
                    <th class="px-4 py-3">Resultado</th>
                    <th class="px-4 py-3">Mensagem</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-slate-100">
                @forelse ($report['items'] as $item)
                    <tr>
                        <td class="px-4 py-3">{{ $item['external_id'] ?? $item['listing_index'] }}</td>
                        <td class="px-4 py-3">{{ $item['result'] ?? $item['event'] }}</td>
                        <td class="px-4 py-3">{{ $item['message'] }}</td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="3" class="px-4 py-6 text-center text-slate-500">Sem itens no relatório.</td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
@endsection
