@extends('layouts.app')

@section('title', 'Plano')
@section('page-title', 'Configurações')

@section('content')
    <x-settings.shell title="Configurações" subtitle="Assinatura e limites da organização.">
    <div class="space-y-6">
        <div class="rounded-xl border border-slate-200 bg-white p-6 shadow-sm">
            <h2 class="text-lg font-semibold text-slate-900">Plano</h2>
            <p class="mt-1 text-sm text-slate-600">Assinatura e limites da organização {{ $tenant->name }}.</p>

            @if ($subscription?->plan)
                <dl class="mt-6 grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
                    <div>
                        <dt class="text-xs font-medium uppercase tracking-wide text-slate-500">Plano</dt>
                        <dd class="mt-1 text-sm font-semibold text-slate-900">{{ $subscription->plan->name }}</dd>
                    </div>
                    <div>
                        <dt class="text-xs font-medium uppercase tracking-wide text-slate-500">Status</dt>
                        <dd class="mt-1 text-sm font-semibold text-slate-900">{{ $subscription->status?->label() }}</dd>
                    </div>
                    <div>
                        <dt class="text-xs font-medium uppercase tracking-wide text-slate-500">Ciclo</dt>
                        <dd class="mt-1 text-sm text-slate-800">{{ $subscription->billing_cycle === 'yearly' ? 'Anual' : 'Mensal' }}</dd>
                    </div>
                    <div>
                        <dt class="text-xs font-medium uppercase tracking-wide text-slate-500">Próximo período</dt>
                        <dd class="mt-1 text-sm text-slate-800">
                            {{ $subscription->current_period_ends_at?->format('d/m/Y') ?? '—' }}
                        </dd>
                    </div>
                    <div>
                        <dt class="text-xs font-medium uppercase tracking-wide text-slate-500">Usuários</dt>
                        <dd class="mt-1 text-sm text-slate-800">
                            {{ (int) $subscription->plan->max_users === 0 ? 'Ilimitado' : $subscription->plan->max_users }}
                        </dd>
                    </div>
                    <div>
                        <dt class="text-xs font-medium uppercase tracking-wide text-slate-500">Imóveis</dt>
                        <dd class="mt-1 text-sm text-slate-800">
                            {{ (int) $subscription->plan->max_properties === 0 ? 'Ilimitado' : number_format($subscription->plan->max_properties, 0, ',', '.') }}
                        </dd>
                    </div>
                </dl>

                @if (! empty($subscription->plan->features))
                    <ul class="mt-4 flex flex-wrap gap-2">
                        @foreach ($subscription->plan->features as $feature)
                            <li class="rounded-full bg-slate-100 px-3 py-1 text-xs font-medium text-slate-700">
                                {{ \ImovelZapAi\Billing\Domain\Enums\PlanFeature::tryFrom($feature)?->label() ?? $feature }}
                            </li>
                        @endforeach
                    </ul>
                @endif
            @else
                <p class="mt-4 text-sm text-slate-600">Nenhum plano atribuído.</p>
            @endif

            @if ($can_manage)
                <div class="mt-6">
                    <a href="{{ route('billing.plan') }}"
                       class="inline-flex rounded-lg bg-emerald-700 px-4 py-2 text-sm font-medium text-white hover:bg-emerald-600">
                        Gerenciar plano e assinar
                    </a>
                </div>
            @else
                <p class="mt-6 text-sm text-slate-500">Somente Admin ou Gestor podem alterar o plano.</p>
            @endif
        </div>
    </div>
    </x-settings.shell>
@endsection
