@extends('layouts.app')

@section('title', $property->title . ' — ImóvelZapAi')
@section('page-title', $property->title)

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

    <div class="mb-6 flex flex-wrap items-center justify-between gap-3">
        <a href="{{ route('properties.index') }}" class="rounded-lg border border-slate-300 px-4 py-2 text-sm text-slate-700 hover:bg-white">
            Voltar à lista
        </a>
        <div class="flex flex-wrap items-center gap-3">
            @include('properties._availability-toggle', ['property' => $property])
            @include('properties._quick-actions', [
                'property' => $property,
                'redirectAfterDelete' => route('properties.index'),
            ])
            <a href="{{ route('properties.edit', $property) }}" class="rounded-lg bg-emerald-600 px-4 py-2 text-sm font-semibold text-white hover:bg-emerald-500">
                Editar
            </a>
        </div>
    </div>

    <div class="grid gap-6 lg:grid-cols-3">
        <div class="space-y-6 lg:col-span-2">
            @include('properties._gallery')

            <section aria-label="Informações do imóvel" class="rounded-xl border border-slate-200 bg-white p-6 shadow-sm">
                <h2 class="text-sm font-semibold uppercase tracking-wide text-slate-500">Informações</h2>

                <div class="mt-4 flex flex-wrap items-start justify-between gap-3">
                    <div>
                        @if ($property->internal_code)
                            <p class="text-xs font-medium uppercase tracking-wide text-slate-500">{{ $property->internal_code }}</p>
                        @endif
                        <p class="text-2xl font-bold text-emerald-700">R$ {{ number_format((float) $property->price, 2, ',', '.') }}</p>
                    </div>
                    <span class="rounded bg-emerald-50 px-2 py-1 text-sm font-medium text-emerald-800">{{ $property->purpose->label() }}</span>
                </div>

                @if ($property->short_description)
                    <p class="mt-3 text-lg text-slate-800">{{ $property->short_description }}</p>
                @endif

                <div class="mt-4 flex flex-wrap gap-2 text-sm">
                    <span class="rounded bg-slate-100 px-2 py-1">{{ $property->type->label() }}</span>
                    <span class="rounded bg-slate-100 px-2 py-1">{{ $property->status->label() }}</span>
                    <span class="rounded bg-slate-100 px-2 py-1">{{ $property->bedrooms }} quarto(s)</span>
                    @if ($property->suites > 0)
                        <span class="rounded bg-slate-100 px-2 py-1">{{ $property->suites }} suíte(s)</span>
                    @endif
                    @if ($property->bathrooms > 0)
                        <span class="rounded bg-slate-100 px-2 py-1">{{ $property->bathrooms }} banheiro(s)</span>
                    @endif
                    @if ($property->parking_spaces > 0)
                        <span class="rounded bg-slate-100 px-2 py-1">{{ $property->parking_spaces }} vaga(s)</span>
                    @endif
                </div>

                <dl class="mt-5 grid gap-4 text-sm sm:grid-cols-2">
                    @if ($property->condominium_fee)
                        <div>
                            <dt class="text-slate-500">Condomínio</dt>
                            <dd class="font-medium">R$ {{ number_format((float) $property->condominium_fee, 2, ',', '.') }}</dd>
                        </div>
                    @endif
                    @if ($property->iptu)
                        <div>
                            <dt class="text-slate-500">IPTU</dt>
                            <dd class="font-medium">R$ {{ number_format((float) $property->iptu, 2, ',', '.') }}</dd>
                        </div>
                    @endif
                    @if ($property->useful_area)
                        <div>
                            <dt class="text-slate-500">Área útil</dt>
                            <dd class="font-medium">{{ number_format((float) $property->useful_area, 0, ',', '.') }} m²</dd>
                        </div>
                    @endif
                    @if ($property->total_area)
                        <div>
                            <dt class="text-slate-500">Área total</dt>
                            <dd class="font-medium">{{ number_format((float) $property->total_area, 0, ',', '.') }} m²</dd>
                        </div>
                    @endif
                </dl>

                @if ($property->full_description)
                    <div class="mt-5 border-t border-slate-100 pt-5">
                        <h3 class="text-sm font-semibold text-slate-700">Descrição completa</h3>
                        <p class="mt-2 whitespace-pre-line text-slate-700">{{ $property->full_description }}</p>
                    </div>
                @endif
            </section>
        </div>

        <aside class="space-y-6">
            <section aria-label="Localização" class="rounded-xl border border-slate-200 bg-white p-6 shadow-sm">
                <h2 class="text-sm font-semibold uppercase tracking-wide text-slate-500">Localização</h2>
                <dl class="mt-4 space-y-3 text-sm">
                    <div>
                        <dt class="text-slate-500">Bairro</dt>
                        <dd class="font-medium">{{ $property->neighborhood->name }}</dd>
                    </div>
                    <div>
                        <dt class="text-slate-500">Cidade / UF</dt>
                        <dd class="font-medium">{{ $property->city->name }} — {{ $property->state->code }}</dd>
                    </div>
                    @if ($property->street)
                        <div>
                            <dt class="text-slate-500">Endereço</dt>
                            <dd class="font-medium">
                                {{ $property->street }}@if ($property->number), {{ $property->number }}@endif
                                @if ($property->complement) — {{ $property->complement }}@endif
                            </dd>
                        </div>
                    @endif
                    @if ($property->cep)
                        <div>
                            <dt class="text-slate-500">CEP</dt>
                            <dd class="font-medium">{{ $property->cep }}</dd>
                        </div>
                    @endif
                </dl>
            </section>

            @include('properties._map', ['map' => $map])

            @include('properties.partials.publication-board', ['property' => $property])

            @include('properties.partials.publication-history')
        </aside>
    </div>
@endsection
