netgescon-day0/resources/views/filament/pages/unita-immobiliare.blade.php

1801 lines
149 KiB
PHP
Executable File

<x-filament-panels::page>
<div class="w-full max-w-full space-y-4 px-2 lg:px-6">
{{-- BARRA NAVIGAZIONE UNIFICATA E COMPATTA --}}
<div class="mb-2 flex flex-wrap items-center justify-between gap-2 rounded-xl border border-slate-200 bg-white/80 p-2 shadow-xs backdrop-blur-xs">
<div class="flex flex-wrap items-center gap-1.5">
<a href="{{ \App\Filament\Pages\Gescon\StabiliArchivio::getUrl(panel: 'admin-filament') }}"
class="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1.5 text-xs font-semibold text-slate-700 transition hover:bg-slate-100 hover:text-slate-900">
<span>🏢</span>
<span>Elenco Stabili</span>
</a>
<a href="{{ \App\Filament\Pages\Condomini\NominativiStabile::getUrl(panel: 'admin-filament') }}"
class="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1.5 text-xs font-semibold text-slate-700 transition hover:bg-slate-100 hover:text-slate-900">
<span>👥</span>
<span>Elenco Nominativi</span>
</a>
<a href="{{ \App\Filament\Pages\UnitaImmobiliarePage::getUrl(panel: 'admin-filament') }}"
class="inline-flex items-center gap-1.5 rounded-lg border border-indigo-200 bg-indigo-50 px-2.5 py-1.5 text-xs font-semibold text-indigo-700 shadow-xs ring-2 ring-indigo-500/20">
<span>🏠</span>
<span>Unità Immobiliare</span>
</a>
<a href="{{ \App\Filament\Pages\Condomini\TabelleMillesimaliArchivio::getUrl(panel: 'admin-filament') }}"
class="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1.5 text-xs font-semibold text-slate-700 transition hover:bg-slate-100 hover:text-slate-900">
<span>📐</span>
<span>Millesimi</span>
</a>
<a href="{{ \App\Filament\Pages\Condomini\CatastoHub::getUrl(panel: 'admin-filament') }}"
class="inline-flex items-center gap-1.5 rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1.5 text-xs font-semibold text-slate-700 transition hover:bg-slate-100 hover:text-slate-900">
<span>🏛️</span>
<span>Catasto</span>
</a>
</div>
</div>
@php
$unitaOptions = $this->getUnitaOptions();
$prevUrl = $this->getPrevUnitaUrl();
$nextUrl = $this->getNextUnitaUrl();
$visibilityOptions = [
'attive' => 'Attive',
'tutte' => 'Tutte',
'archiviate' => 'Archiviate',
];
@endphp
{{-- CONTROLLI COMPATTI SELEZIONE UNITÀ & PULSANTI RUOLO CONDOMINO / INQUILINO --}}
<div class="mb-3 flex flex-wrap items-center justify-between gap-3 rounded-xl border border-slate-200 bg-white p-2.5 shadow-xs">
<div class="flex flex-wrap items-center gap-2.5">
<a href="{{ $this->getBackUrl() }}" class="inline-flex items-center gap-1 rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1 text-xs font-semibold text-slate-600 transition hover:bg-slate-100 hover:text-slate-900">
<span></span>
<span>Torna indietro</span>
</a>
<span class="text-slate-300">|</span>
<div class="flex items-center gap-1.5">
@if($prevUrl)
<a class="inline-flex items-center justify-center rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1 text-xs font-semibold text-slate-700 transition hover:bg-slate-100" href="{{ $prevUrl }}">&larr; Prec.</a>
@else
<span class="inline-flex items-center justify-center rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1 text-xs font-semibold text-slate-400 opacity-50">&larr; Prec.</span>
@endif
<div class="min-w-64 max-w-xl">
{{ $this->getSchema('unitaPicker') }}
</div>
@if($nextUrl)
<a class="inline-flex items-center justify-center rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1 text-xs font-semibold text-slate-700 transition hover:bg-slate-100" href="{{ $nextUrl }}">Succ. &rarr;</a>
@else
<span class="inline-flex items-center justify-center rounded-lg border border-slate-200 bg-slate-50 px-2.5 py-1 text-xs font-semibold text-slate-400 opacity-50">Succ. &rarr;</span>
@endif
</div>
{{-- SELETTORE ESPLICITO RUOLO CONDOMINO / INQUILINO --}}
<div class="flex items-center gap-1 rounded-lg border border-slate-200 bg-slate-100 p-1">
<button type="button" wire:click="setCondInquilActive('C')"
class="inline-flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-bold transition {{ ($condInquilActive ?? 'C') === 'C' ? 'bg-amber-600 text-white shadow-xs' : 'text-slate-600 hover:text-slate-900' }}">
<span>🏢</span>
<span>Condomino (Proprietari)</span>
</button>
<button type="button" wire:click="setCondInquilActive('I')"
class="inline-flex items-center gap-1.5 rounded-md px-3 py-1 text-xs font-bold transition {{ ($condInquilActive ?? 'C') === 'I' ? 'bg-indigo-600 text-white shadow-xs' : 'text-slate-600 hover:text-slate-900' }}">
<span>👤</span>
<span>Inquilino</span>
</button>
</div>
</div>
<div class="flex flex-wrap items-center gap-2">
<span class="text-xs font-medium text-slate-500">Vista:</span>
<button
type="button"
wire:click="toggleMostraStorico"
class="rounded-lg border px-2.5 py-1 text-xs font-semibold transition {{ $mostraStorico ? 'border-amber-300 bg-amber-50 text-amber-700 shadow-xs' : 'border-slate-200 bg-slate-50 text-slate-700 hover:bg-slate-100' }}">
{{ $mostraStorico ? 'Mostra storico (Attivo)' : 'Solo gestione selezionata' }}
</button>
<span class="text-xs font-medium text-slate-500 ml-1">Visibilità:</span>
@foreach($visibilityOptions as $key => $label)
<button
type="button"
wire:click="setUnitaVisibilita('{{ $key }}')"
class="rounded-lg border px-2.5 py-1 text-xs font-semibold transition {{ $this->unitaVisibilita === $key ? 'border-indigo-300 bg-indigo-50 text-indigo-700 shadow-xs' : 'border-slate-200 bg-slate-50 text-slate-700 hover:bg-slate-100' }}">
{{ $label }}
</button>
@endforeach
</div>
</div>
@if(!$unita)
<div class="rounded-xl border border-dashed border-gray-200 bg-white p-6 text-center text-gray-500">Nessuna unità immobiliare trovata.</div>
@else
{{-- Tabs + contenuto --}}
<x-filament::section class="p-0! overflow-hidden">
<div class="flex flex-wrap items-center gap-2 px-4 py-2 bg-white border-b">
@php
$tabs = [
'riepilogo' => ['icon' => 'heroicon-o-rectangle-group', 'label' => 'Riepilogo'],
'nominativi' => ['icon' => 'heroicon-o-user-group', 'label' => '👥 Nominativi & Subentri'],
'estratto_conto' => ['icon' => 'heroicon-o-calculator', 'label' => '🧾 Estratto Conto & Pagamenti'],
'millesimi' => ['icon' => 'heroicon-o-chart-pie', 'label' => '📊 Tabelle Millesimali & Spese'],
'preferenze' => ['icon' => 'heroicon-o-envelope', 'label' => '📨 Comunicazioni & Protocollo'],
'acqua' => ['icon' => 'heroicon-o-beaker', 'label' => '💧 Acqua'],
];
@endphp
@foreach($tabs as $key => $cfg)
<button
type="button"
wire:click="setTab('{{ $key }}')"
class="inline-flex items-center gap-2 rounded-lg border px-3 py-2 text-sm font-semibold transition
{{ $tab === $key ? 'border-primary-300 bg-primary-50 text-primary-700 shadow-sm' : 'border-transparent bg-gray-50 text-gray-700 hover:border-gray-200' }}">
<x-filament::icon :icon="$cfg['icon']" class="h-4 w-4" />
<span>{{ $cfg['label'] }}</span>
</button>
@endforeach
</div>
<div class="p-4 space-y-4">
@if($tab === 'riepilogo')
{{-- Header compatto dell'Unità Immobiliare --}}
<x-filament::section class="p-4! mb-4">
@php
$isArchivedUnita = method_exists($unita, 'trashed') && $unita->trashed();
$labelUnita = (string) ($unita->denominazione ?? '');
if ($labelUnita !== '' && preg_match('/^\s*area\s+condominiale\s*$/i', $labelUnita)) {
$labelUnita = '';
}
$condominoDaCondomin = trim((string) ($this->getLegacyCondominoRiferimentoNome() ?? ''));
$proprietariAttivi = collect($relazioniPerTipo['proprietari'] ?? []);
$condominoRiferimento = $proprietariAttivi
->first(fn (array $relazione): bool => strtolower(trim((string) ($relazione['tipo_raw'] ?? ''))) !== 'comproprietario')
?? ($relazioniPerTipo['proprietari'][0] ?? null);
$condominoNome = $condominoDaCondomin !== ''
? $condominoDaCondomin
: (string) ($condominoRiferimento['nome'] ?? '');
$condominoCf = trim((string) ($this->getLegacyCondominoRiferimentoCodiceFiscale() ?? ''));
if ($condominoCf === '') {
$condominoCf = (string) ($condominoRiferimento['codice_fiscale'] ?? '');
}
$inquilinoNome = (string) ($relazioniPerTipo['inquilini'][0]['nome'] ?? '');
$comproprietariCount = $proprietariAttivi
->filter(fn (array $relazione): bool => strtolower(trim((string) ($relazione['tipo_raw'] ?? ''))) === 'comproprietario')
->count();
$hasInquilino = !empty($relazioniPerTipo['inquilini'][0]['nome'] ?? null);
@endphp
<div class="flex items-start justify-between gap-4 flex-wrap">
<div class="space-y-1">
<div class="flex flex-wrap items-center gap-3 text-lg font-semibold text-gray-900">
<x-filament::icon icon="heroicon-o-home-modern" class="h-5 w-5 text-primary-600" />
<span class="text-primary-700 font-bold">Unità immobiliare {{ $unita->codice_unita ?? $unita->codice_completo }}</span>
@if($isArchivedUnita)
<span class="rounded-full border border-amber-300 bg-amber-50 px-2 py-0.5 text-xs font-semibold text-amber-700">Archiviata</span>
@endif
</div>
<div class="flex items-center gap-2 text-sm text-gray-800 mt-2">
<span class="inline-flex items-center rounded bg-emerald-100 px-2 py-0.5 text-xs font-bold text-emerald-800">C</span>
<span class="font-semibold">Condomino:</span>
<span class="font-bold text-indigo-900">{{ $condominoNome !== '' ? trim(str_replace([' - ', ' 0 ', ' 0', '-'], [' ', ' ', ' ', ' '], $condominoNome)) : '' }}</span>
</div>
@if($comproprietariCount > 0)
<div class="text-xs text-gray-500 pl-6">Comproprietari collegati: {{ $comproprietariCount }}</div>
@endif
<div class="flex items-center gap-2 text-sm text-gray-800 mt-1">
<span class="inline-flex items-center rounded bg-sky-100 px-2 py-0.5 text-xs font-bold text-sky-800">I</span>
<span class="font-semibold">Inquilino:</span>
<span class="font-bold text-slate-800">{{ $inquilinoNome !== '' ? trim(str_replace([' - ', ' 0 ', ' 0', '-'], [' ', ' ', ' ', ' '], $inquilinoNome)) : '' }}</span>
</div>
<div class="text-xs text-gray-600 mt-1">📍 {{ trim(($unita->indirizzo ?? '').' Scala '.($unita->scala ?? '').' Int. '.($unita->interno ?? '').' '.($unita->comune ?? '')) }}</div>
<div class="mt-3 pt-2 border-t border-gray-100">
<a href="/admin-filament/condomini/catasto-hub?unita_id={{ $unita->id }}" class="inline-flex items-center gap-2 rounded-lg bg-indigo-700 hover:bg-indigo-800 text-white font-semibold px-3.5 py-1.5 text-xs shadow-xs transition">
<span>🏛️</span>
<span>[ Apri in HUB Catasto ]</span>
</a>
</div>
</div>
<div class="grid gap-3 sm:grid-cols-2 min-w-80">
<div class="rounded-xl border border-slate-200 bg-slate-50 p-3.5">
<div class="text-xs font-semibold text-slate-500">🏢 Condomino di riferimento</div>
<div class="text-sm font-bold text-slate-900 mt-1">{{ $condominoNome !== '' ? $condominoNome : '' }}</div>
<div class="text-xs font-mono text-slate-600 mt-0.5">CF: {{ $condominoCf !== '' ? $condominoCf : '' }}</div>
</div>
<div class="rounded-xl border border-slate-200 bg-slate-50 p-3.5 {{ $hasInquilino ? '' : 'opacity-60' }}">
<div class="text-xs font-semibold text-slate-500">👤 Inquilino</div>
<div class="text-sm font-bold text-slate-900 mt-1">{{ $inquilinoNome !== '' ? $inquilinoNome : '' }}</div>
<div class="text-xs font-mono text-slate-600 mt-0.5">CF: {{ $relazioniPerTipo['inquilini'][0]['codice_fiscale'] ?? '' }}</div>
</div>
</div>
</div>
</x-filament::section>
{{-- 1. SCHEDE ANAGRAFICHE SOGGETTI ATTIVI & IDENTIFICAZIONE COMPATTA --}}
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-3">
{{-- Card Condomino / Proprietario Attivo --}}
<div class="rounded-xl border border-indigo-100 bg-white p-4 shadow-xs">
<div class="flex items-center justify-between border-b border-indigo-50 pb-2 mb-3">
<div class="flex items-center gap-2">
<span class="inline-flex h-7 w-7 items-center justify-center rounded-lg bg-indigo-100 text-sm font-bold text-indigo-800">🏢</span>
<span class="text-xs font-bold uppercase tracking-wider text-indigo-900">Condomino (Proprietario)</span>
</div>
<span class="rounded-full bg-emerald-50 border border-emerald-200 px-2 py-0.5 text-[10px] font-bold text-emerald-700">🟢 In Carica</span>
</div>
<div class="space-y-1.5">
<div class="text-base font-bold text-gray-900 leading-snug">
{{ $condominoNome !== '' ? $condominoNome : '' }}
</div>
<div class="text-xs font-mono text-gray-600">
CF: <strong>{{ $condominoCf !== '' ? $condominoCf : '' }}</strong>
</div>
<div class="flex items-center gap-2 text-xs text-gray-600 pt-1">
<span class="rounded bg-indigo-50 text-indigo-700 font-semibold px-2 py-0.5">
Quota: {{ $relazioniPerTipo['proprietari'][0]['quota_label'] ?? '100,00' }}%
</span>
@if($comproprietariCount > 0)
<span class="rounded bg-amber-50 text-amber-800 font-semibold px-2 py-0.5">
+{{ $comproprietariCount }} comproprietari
</span>
@endif
</div>
<div class="text-xs text-gray-500 pt-1">
Validità: <strong class="text-gray-700">{{ $relazioniPerTipo['proprietari'][0]['data_inizio'] ?? 'Gestione attiva' }}</strong>
</div>
</div>
</div>
{{-- Card Inquilino / Conduttore Attivo --}}
<div class="rounded-xl border border-sky-100 bg-white p-4 shadow-xs">
<div class="flex items-center justify-between border-b border-sky-50 pb-2 mb-3">
<div class="flex items-center gap-2">
<span class="inline-flex h-7 w-7 items-center justify-center rounded-lg bg-sky-100 text-sm font-bold text-sky-800">👤</span>
<span class="text-xs font-bold uppercase tracking-wider text-sky-900">Inquilino (Conduttore)</span>
</div>
@if($hasInquilino)
<span class="rounded-full bg-sky-50 border border-sky-200 px-2 py-0.5 text-[10px] font-bold text-sky-700">Locazione attiva</span>
@else
<span class="rounded-full bg-gray-100 text-gray-500 px-2 py-0.5 text-[10px] font-medium">Nessun inquilino</span>
@endif
</div>
<div class="space-y-1.5">
<div class="text-base font-bold text-gray-900 leading-snug">
{{ $inquilinoNome !== '' ? $inquilinoNome : 'Nessun inquilino registrato' }}
</div>
<div class="text-xs font-mono text-gray-600">
CF: <strong>{{ $relazioniPerTipo['inquilini'][0]['codice_fiscale'] ?? '' }}</strong>
</div>
@if($hasInquilino)
<div class="flex items-center gap-2 text-xs text-gray-600 pt-1">
<span class="rounded bg-sky-50 text-sky-700 font-semibold px-2 py-0.5">
Spese: {{ $relazioniPerTipo['inquilini'][0]['quota_label'] ?? '100,00' }}%
</span>
</div>
<div class="text-xs text-gray-500 pt-1">
Subentro: <strong class="text-gray-700">{{ $relazioniPerTipo['inquilini'][0]['data_inizio'] ?? '' }}</strong>
</div>
@else
<div class="text-xs text-gray-400 italic pt-2">
L'unità risulta occupata direttamente dal proprietario.
</div>
@endif
</div>
</div>
{{-- Card Dati Catastali & Identificazione Immobile --}}
<div class="rounded-xl border border-slate-200 bg-slate-50/70 p-4 shadow-xs">
<div class="flex items-center justify-between border-b border-slate-200 pb-2 mb-3">
<div class="flex items-center gap-2">
<span class="inline-flex h-7 w-7 items-center justify-center rounded-lg bg-slate-200 text-sm font-bold text-slate-800">🏛️</span>
<span class="text-xs font-bold uppercase tracking-wider text-slate-700">Dati Catasto & Immobile</span>
</div>
<span class="font-mono text-xs font-bold text-indigo-700">Sub. {{ $unita->subalterno ?: '—' }}</span>
</div>
<div class="space-y-1.5 text-xs">
<div class="flex items-center justify-between text-gray-600">
<span>Tipologia:</span>
<strong class="text-gray-900 capitalize">{{ $unita->tipo_unita ?? 'Abitazione' }}</strong>
</div>
<div class="flex items-center justify-between text-gray-600">
<span>Categoria & Rendita:</span>
<strong class="text-gray-900">{{ $unita->categoria_catastale ?: '—' }} · {{ number_format((float)($unita->rendita_catastale ?? 0), 2, ',', '.') }}</strong>
</div>
<div class="flex items-center justify-between text-gray-600">
<span>Foglio / Particella:</span>
<strong class="text-gray-900">Fg. {{ $unita->foglio ?: ($unita->stabile?->foglio ?: '—') }} / Part. {{ $unita->particella ?: ($unita->stabile?->particella_catasto ?: '—') }}</strong>
</div>
<div class="flex items-center justify-between text-gray-600">
<span>Posizione fabbricato:</span>
<strong class="text-gray-900">Scala {{ $unita->scala ?: '—' }} · Int. {{ $unita->interno ?: '—' }} · Piano {{ $unita->piano ?: '—' }}</strong>
</div>
</div>
</div>
</div>
{{-- 2. SEZIONE RECAPITI MULTICANALE DINAMICI (MATRICE ATOMICA DIVISA COND/INQ + AGGREGATA) --}}
@php
$multiRecapiti = $this->getRecapitiMulticanaleTableProperty();
$recapitiCondomino = array_values(array_filter($multiRecapiti, fn($r) => ($r['tipo_soggetto'] ?? 'condomino') === 'condomino'));
$recapitiInquilino = array_values(array_filter($multiRecapiti, fn($r) => ($r['tipo_soggetto'] ?? '') === 'inquilino'));
$currentRecapitiMode = $this->recapitiViewMode ?? 'diviso';
@endphp
<div class="rounded-xl border border-gray-200 bg-white shadow-xs overflow-hidden mt-4">
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between bg-gray-50/80 px-4 py-3 border-b border-gray-200 gap-3">
<div class="flex items-center gap-2">
<span class="text-base">📱</span>
<div>
<div class="text-sm font-bold text-gray-900">Recapiti Multicanale Dinamici dell'Unità</div>
<div class="text-[11px] text-gray-500">Email, PEC, cellulari, telefoni e recapiti postali divisi per Condomino e Inquilino</div>
</div>
</div>
{{-- Selettore Vista Atomica / Aggregata --}}
<div class="flex items-center gap-1.5 bg-white border border-gray-200 p-1 rounded-lg">
<button type="button"
wire:click="setRecapitiViewMode('diviso')"
class="px-2.5 py-1 text-xs font-semibold rounded-md transition {{ $currentRecapitiMode === 'diviso' ? 'bg-indigo-600 text-white shadow-xs' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100' }}">
📊 Diviso per Soggetto
</button>
<button type="button"
wire:click="setRecapitiViewMode('condomino')"
class="px-2.5 py-1 text-xs font-semibold rounded-md transition {{ $currentRecapitiMode === 'condomino' ? 'bg-amber-500 text-white shadow-xs' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100' }}">
🏢 Condomino ({{ count($recapitiCondomino) }})
</button>
<button type="button"
wire:click="setRecapitiViewMode('inquilino')"
class="px-2.5 py-1 text-xs font-semibold rounded-md transition {{ $currentRecapitiMode === 'inquilino' ? 'bg-indigo-500 text-white shadow-xs' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100' }}">
👤 Inquilino ({{ count($recapitiInquilino) }})
</button>
<button type="button"
wire:click="setRecapitiViewMode('tutti')"
class="px-2.5 py-1 text-xs font-semibold rounded-md transition {{ $currentRecapitiMode === 'tutti' ? 'bg-slate-700 text-white shadow-xs' : 'text-gray-600 hover:text-gray-900 hover:bg-gray-100' }}">
🌐 Tutti ({{ count($multiRecapiti) }})
</button>
</div>
</div>
@if(empty($multiRecapiti))
<div class="p-6 text-center text-xs text-gray-500">
Nessun recapito multicanale o contatto registrato per i soggetti di questa unità.
</div>
@else
{{-- VISTA 1: DIVISO PER SOGGETTO (DUE SOTTO-TABELLE ATOMICHE) --}}
@if($currentRecapitiMode === 'diviso')
<div class="p-4 space-y-4">
{{-- SOTTO-TABELLA CONDOMINO --}}
<div class="rounded-lg border border-amber-200 bg-amber-50/20 overflow-hidden">
<div class="flex items-center justify-between px-3.5 py-2 bg-amber-50 border-b border-amber-200">
<div class="flex items-center gap-2">
<span class="text-sm">🏢</span>
<span class="text-xs font-bold text-amber-950 uppercase tracking-wide">Recapiti Condomino / Aventi Diritto</span>
</div>
<span class="rounded bg-amber-200/80 text-amber-900 font-bold px-2 py-0.5 text-[10px]">
{{ count($recapitiCondomino) }} canali
</span>
</div>
@if(empty($recapitiCondomino))
<div class="p-3 text-center text-xs text-gray-500">Nessun contatto registrato per il Condomino.</div>
@else
<div class="overflow-x-auto">
<table class="w-full text-left text-xs text-gray-700 divide-y divide-amber-100/60">
<thead class="bg-amber-50/50 text-[10px] font-bold uppercase tracking-wider text-amber-900/70">
<tr>
<th class="px-3.5 py-2">Canale</th>
<th class="px-3.5 py-2">Etichetta</th>
<th class="px-3.5 py-2">Soggetto</th>
<th class="px-3.5 py-2">Valore Contatto</th>
<th class="px-3.5 py-2 text-center">Stato</th>
<th class="px-3.5 py-2 text-right">Azione</th>
</tr>
</thead>
<tbody class="divide-y divide-amber-100/60 bg-white">
@foreach($recapitiCondomino as $rec)
<tr class="hover:bg-amber-50/40 transition">
<td class="px-3.5 py-2 whitespace-nowrap">
<span class="inline-flex items-center gap-1.5 rounded-md border px-2 py-0.5 font-semibold text-[11px] {{ $rec['color'] }}">
<span>{{ $rec['icon'] }}</span>
<span>{{ $rec['canale'] }}</span>
</span>
</td>
<td class="px-3.5 py-2 font-medium text-gray-800 whitespace-nowrap">{{ $rec['etichetta'] }}</td>
<td class="px-3.5 py-2 whitespace-nowrap">
<span class="font-bold text-gray-900">{{ $rec['soggetto'] }}</span>
<span class="text-gray-400 font-normal">({{ $rec['ruolo'] }})</span>
</td>
<td class="px-3.5 py-2 font-mono text-gray-900 font-medium">{{ $rec['valore'] }}</td>
<td class="px-3.5 py-2 text-center whitespace-nowrap">
@if($rec['is_principal'])
<span class="rounded bg-emerald-100 text-emerald-800 px-1.5 py-0.5 text-[10px] font-bold">★ Principale</span>
@else
<span class="text-gray-400 text-[11px]">—</span>
@endif
</td>
<td class="px-3.5 py-2 text-right whitespace-nowrap">
@if(!empty($rec['action_url']))
<a href="{{ $rec['action_url'] }}" class="inline-flex items-center gap-1 rounded bg-amber-50 hover:bg-amber-100 border border-amber-200 text-amber-900 font-semibold px-2 py-0.5 text-[11px] transition">
<span>Apri</span>
</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
{{-- SOTTO-TABELLA INQUILINO --}}
<div class="rounded-lg border border-indigo-200 bg-indigo-50/20 overflow-hidden">
<div class="flex items-center justify-between px-3.5 py-2 bg-indigo-50 border-b border-indigo-200">
<div class="flex items-center gap-2">
<span class="text-sm">👤</span>
<span class="text-xs font-bold text-indigo-950 uppercase tracking-wide">Recapiti Inquilino / Conduttore</span>
</div>
<span class="rounded bg-indigo-200/80 text-indigo-900 font-bold px-2 py-0.5 text-[10px]">
{{ count($recapitiInquilino) }} canali
</span>
</div>
@if(empty($recapitiInquilino))
<div class="p-3 text-center text-xs text-gray-500">Nessun contatto o recapito registrato per l'Inquilino.</div>
@else
<div class="overflow-x-auto">
<table class="w-full text-left text-xs text-gray-700 divide-y divide-indigo-100/60">
<thead class="bg-indigo-50/50 text-[10px] font-bold uppercase tracking-wider text-indigo-900/70">
<tr>
<th class="px-3.5 py-2">Canale</th>
<th class="px-3.5 py-2">Etichetta</th>
<th class="px-3.5 py-2">Soggetto</th>
<th class="px-3.5 py-2">Valore Contatto</th>
<th class="px-3.5 py-2 text-center">Stato</th>
<th class="px-3.5 py-2 text-right">Azione</th>
</tr>
</thead>
<tbody class="divide-y divide-indigo-100/60 bg-white">
@foreach($recapitiInquilino as $rec)
<tr class="hover:bg-indigo-50/40 transition">
<td class="px-3.5 py-2 whitespace-nowrap">
<span class="inline-flex items-center gap-1.5 rounded-md border px-2 py-0.5 font-semibold text-[11px] {{ $rec['color'] }}">
<span>{{ $rec['icon'] }}</span>
<span>{{ $rec['canale'] }}</span>
</span>
</td>
<td class="px-3.5 py-2 font-medium text-gray-800 whitespace-nowrap">{{ $rec['etichetta'] }}</td>
<td class="px-3.5 py-2 whitespace-nowrap">
<span class="font-bold text-gray-900">{{ $rec['soggetto'] }}</span>
<span class="text-gray-400 font-normal">({{ $rec['ruolo'] }})</span>
</td>
<td class="px-3.5 py-2 font-mono text-gray-900 font-medium">{{ $rec['valore'] }}</td>
<td class="px-3.5 py-2 text-center whitespace-nowrap">
@if($rec['is_principal'])
<span class="rounded bg-emerald-100 text-emerald-800 px-1.5 py-0.5 text-[10px] font-bold"> Principale</span>
@else
<span class="text-gray-400 text-[11px]"></span>
@endif
</td>
<td class="px-3.5 py-2 text-right whitespace-nowrap">
@if(!empty($rec['action_url']))
<a href="{{ $rec['action_url'] }}" class="inline-flex items-center gap-1 rounded bg-indigo-50 hover:bg-indigo-100 border border-indigo-200 text-indigo-700 font-semibold px-2 py-0.5 text-[11px] transition">
<span>Apri</span>
</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
</div>
{{-- VISTA 2: FILTRATA PER CONDOMINO, INQUILINO O TUTTI --}}
@else
@php
$displayedRows = match($currentRecapitiMode) {
'condomino' => $recapitiCondomino,
'inquilino' => $recapitiInquilino,
default => $multiRecapiti,
};
@endphp
<div class="overflow-x-auto">
<table class="w-full text-left text-xs text-gray-700 divide-y divide-gray-100">
<thead class="bg-gray-50 text-[11px] font-bold uppercase tracking-wider text-gray-500">
<tr>
<th class="px-4 py-2.5">Canale</th>
<th class="px-4 py-2.5">Etichetta / Uso</th>
<th class="px-4 py-2.5">Soggetto Collegato</th>
<th class="px-4 py-2.5">Valore Contatto</th>
<th class="px-4 py-2.5 text-center">Stato</th>
<th class="px-4 py-2.5 text-right">Azioni Rapide</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-100 bg-white">
@foreach($displayedRows as $rec)
<tr class="hover:bg-indigo-50/30 transition">
<td class="px-4 py-2.5 whitespace-nowrap">
<span class="inline-flex items-center gap-1.5 rounded-md border px-2 py-0.5 font-semibold text-[11px] {{ $rec['color'] }}">
<span>{{ $rec['icon'] }}</span>
<span>{{ $rec['canale'] }}</span>
</span>
</td>
<td class="px-4 py-2.5 font-medium text-gray-800 whitespace-nowrap">
{{ $rec['etichetta'] }}
</td>
<td class="px-4 py-2.5 whitespace-nowrap">
<span class="font-bold text-gray-900">{{ $rec['soggetto'] }}</span>
<span class="text-gray-400 font-normal">({{ $rec['ruolo'] }})</span>
</td>
<td class="px-4 py-2.5 font-mono text-gray-900 font-medium">
{{ $rec['valore'] }}
</td>
<td class="px-4 py-2.5 text-center whitespace-nowrap">
@if($rec['is_principal'])
<span class="rounded bg-emerald-100 text-emerald-800 px-1.5 py-0.5 text-[10px] font-bold"> Principale</span>
@else
<span class="text-gray-400 text-[11px]"></span>
@endif
</td>
<td class="px-4 py-2.5 text-right whitespace-nowrap">
@if(!empty($rec['action_url']))
<a href="{{ $rec['action_url'] }}" class="inline-flex items-center gap-1 rounded bg-indigo-50 hover:bg-indigo-100 border border-indigo-200 text-indigo-700 font-semibold px-2 py-1 text-[11px] transition">
<span>Apri</span>
</a>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
@endif
</div>
@endif
@if($tab === 'nominativi')
<div class="space-y-4">
<div class="rounded-xl border border-indigo-100 bg-indigo-50/50 p-4">
<div class="flex items-center gap-2">
<span class="text-xl">👥</span>
<div>
<h3 class="text-base font-semibold text-gray-900">Timeline Subentri e Cronistoria Avvicendamenti</h3>
<p class="text-xs text-gray-600">Cronistoria titolari ed avvicendamenti storici per questa unità immobiliare tra le diverse gestioni annuali. Seleziona un nominativo per accedere all'estratto conto contabile analitico.</p>
</div>
</div>
</div>
@php
$timelineItems = $this->getTimelineSubentriCompletaProperty();
@endphp
@if(empty($timelineItems))
<div class="rounded-xl border border-dashed border-gray-200 bg-white p-8 text-center text-gray-500">
Nessuna cronistoria subentri registrata per questa unità immobiliare.
</div>
@else
<div class="relative border-l-2 border-indigo-200 ml-4 space-y-4 py-2">
@foreach($timelineItems as $item)
<div class="relative pl-6">
<span class="absolute -left-[9px] top-3 h-4 w-4 rounded-full border-2 border-indigo-600 bg-white"></span>
<div class="rounded-xl border border-gray-200 bg-white p-4 shadow-xs hover:border-indigo-300 hover:shadow-md transition flex flex-wrap items-center justify-between gap-4">
<div class="space-y-1">
<div class="flex items-center gap-2">
<span class="font-bold text-gray-900 text-base">{{ $item['nominativo'] }}</span>
<span class="inline-flex items-center rounded-md px-2 py-0.5 text-xs font-semibold {{ $item['ruolo'] === 'Inquilino' ? 'bg-amber-100 text-amber-800' : 'bg-indigo-100 text-indigo-800' }}">
{{ $item['ruolo'] }}
</span>
</div>
<div class="text-xs text-gray-500 flex flex-wrap items-center gap-3">
@if($item['codice_fiscale'])
<span>CF: <code class="font-mono">{{ $item['codice_fiscale'] }}</code></span>
@endif
<span>ID Condomino: <strong>#{{ $item['id_cond'] }}</strong></span>
<span>Gestioni: <strong class="text-indigo-700">{{ implode(' | ', $item['year_labels'] ?? $item['years']) }}</strong></span>
</div>
@if(!empty($item['dettaglio_subentro']))
@php
$subentroText = $item['dettaglio_subentro'];
try {
$parsedDate = \Carbon\Carbon::parse($subentroText)->format('d/m/Y');
$subentroText = 'Subentrato il: ' . $parsedDate;
} catch (\Throwable $e) {}
@endphp
<div class="text-xs text-amber-800 bg-amber-50 rounded-md border border-amber-200 px-2.5 py-1 inline-block mt-1 font-medium">
📅 {{ $subentroText }}
</div>
@endif
</div>
<div>
<button type="button"
wire:click="selectNominativoKey('{{ $item['key'] }}')"
class="inline-flex items-center gap-1.5 rounded-lg bg-indigo-600 px-3.5 py-2 text-xs font-semibold text-white shadow-xs hover:bg-indigo-700 transition">
<span>🧾</span>
<span>Vai all'Estratto Conto del Soggetto</span>
</button>
</div>
</div>
</div>
@endforeach
</div>
@endif
</div>
@endif
@if($tab === 'estratto_conto')
@php
$ec = $this->estrattoContoAtomico;
$soggetto = $ec['soggetto'] ?? [];
$totali = $ec['totali'] ?? [];
$gestioneOrdCorrente = $ec['gestione_ordinaria_corrente'] ?? [];
$gestioniStraordinarie = $ec['gestioni_straordinarie'] ?? [];
$gestioniPregresseOrd = $ec['gestioni_pregresse_ordinarie'] ?? [];
$fonteDati = $ec['fonte'] ?? 'MDB_LIVE';
$ruoloAttivo = $this->condInquilActive ?? 'C';
@endphp
<div class="space-y-6">
{{-- Toolbar & Selettore Ruolo / Ricarica MDB --}}
<div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 bg-slate-900 text-white p-4 rounded-2xl shadow-sm">
<div class="flex items-center gap-3">
<div class="h-10 w-10 rounded-xl bg-amber-500/20 text-amber-400 flex items-center justify-center font-bold text-lg">
🧾
</div>
<div>
<div class="flex items-center gap-2">
<h3 class="font-bold text-base text-white tracking-wide">
Estratto Conto Atomico & Temporale
</h3>
<span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-semibold {{ $fonteDati === 'MDB_LIVE' ? 'bg-emerald-500/20 text-emerald-300 border border-emerald-500/30' : 'bg-blue-500/20 text-blue-300 border border-blue-500/30' }}">
{{ $fonteDati === 'MDB_LIVE' ? '⚡ Archivio MDB Live' : '🗄️ Database Consolidato' }}
</span>
</div>
<p class="text-xs text-slate-300">
{{ $soggetto['nominativo'] ?? '—' }} &bull; Scala {{ $soggetto['scala'] ?? 'A' }} / Int. {{ $soggetto['interno'] ?? '1' }}
@if(!empty($soggetto['locatario']) && $ruoloAttivo === 'C')
&bull; <span class="text-amber-300">Locatario: {{ $soggetto['locatario'] }}</span>
@endif
</p>
</div>
</div>
<div class="flex flex-wrap items-center gap-2">
{{-- Switcher C / I --}}
<div class="inline-flex rounded-xl bg-slate-800 p-1 border border-slate-700">
<button type="button"
wire:click="setCondInquilActive('C')"
class="px-3 py-1.5 rounded-lg text-xs font-semibold transition {{ $ruoloAttivo === 'C' ? 'bg-amber-500 text-slate-950 shadow' : 'text-slate-300 hover:text-white' }}">
🏢 Condòmino (C)
</button>
<button type="button"
wire:click="setCondInquilActive('I')"
class="px-3 py-1.5 rounded-lg text-xs font-semibold transition {{ $ruoloAttivo === 'I' ? 'bg-amber-500 text-slate-950 shadow' : 'text-slate-300 hover:text-white' }}">
👤 Inquilino (I)
</button>
</div>
{{-- Pulsante Ricarica MDB --}}
<button type="button"
wire:click="refreshEstrattoContoMdb"
title="Ricarica i dati leggendo direttamente dai file MDB"
class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl bg-slate-800 hover:bg-slate-700 text-slate-200 border border-slate-700 text-xs font-medium transition">
<x-filament::icon icon="heroicon-m-arrow-path" class="w-4 h-4 text-amber-400" />
<span>Ricarica MDB</span>
</button>
</div>
</div>
{{-- KPI Cards Riepilogative Atomiche --}}
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4">
<!-- Card Totale Dovuto Globale -->
<div class="relative overflow-hidden rounded-2xl border p-4 shadow-xs {{ ($totali['totale_dovuto'] ?? 0) > 0 ? 'bg-rose-50/70 border-rose-200' : 'bg-emerald-50/70 border-emerald-200' }}">
<div class="flex items-center justify-between text-xs font-semibold {{ ($totali['totale_dovuto'] ?? 0) > 0 ? 'text-rose-700' : 'text-emerald-700' }}">
<span>TOTALE DA PAGARE</span>
<x-filament::icon icon="heroicon-o-banknotes" class="w-4 h-4" />
</div>
<div class="mt-2 text-2xl font-black tracking-tight {{ ($totali['totale_dovuto'] ?? 0) > 0 ? 'text-rose-900' : 'text-emerald-900' }}">
{{ number_format($totali['totale_dovuto'] ?? 0, 2, ',', '.') }}
</div>
<div class="mt-1 text-[11px] text-slate-500">
Include tutte le gestioni aperte ed esigibili
</div>
</div>
<!-- Card Gestioni Straordinarie -->
<div class="relative overflow-hidden rounded-2xl border border-amber-200 bg-amber-50/70 p-4 shadow-xs">
<div class="flex items-center justify-between text-xs font-semibold text-amber-800">
<span>STRAORDINARIE ATTIVE</span>
<x-filament::icon icon="heroicon-o-wrench-screwdriver" class="w-4 h-4" />
</div>
<div class="mt-2 text-2xl font-black tracking-tight text-amber-950">
{{ number_format($totali['totale_straordinarie_residuo'] ?? 0, 2, ',', '.') }}
</div>
<div class="mt-1 text-[11px] text-amber-700">
{{ count($gestioniStraordinarie) }} gestioni deliberate
</div>
</div>
<!-- Card Ordinaria Corrente -->
<div class="relative overflow-hidden rounded-2xl border border-slate-200 bg-white p-4 shadow-xs">
<div class="flex items-center justify-between text-xs font-semibold text-slate-700">
<span>ORDINARIA ES. {{ $gestioneOrdCorrente['anno'] ?? '2026' }}</span>
<x-filament::icon icon="heroicon-o-calendar-days" class="w-4 h-4 text-slate-500" />
</div>
<div class="mt-2 text-2xl font-black tracking-tight {{ ($totali['totale_ordinaria_corrente_residuo'] ?? 0) > 0 ? 'text-rose-600' : 'text-slate-900' }}">
{{ number_format($totali['totale_ordinaria_corrente_residuo'] ?? 0, 2, ',', '.') }}
</div>
<div class="mt-1 text-[11px] text-slate-500">
{{ ($totali['totale_ordinaria_corrente_residuo'] ?? 0) <= 0 ? 'Saldata / Compensata' : 'Residuo corrente' }}
</div>
</div>
<!-- Card Pregresse Chiuse -->
<div class="relative overflow-hidden rounded-2xl border border-slate-200 bg-white p-4 shadow-xs">
<div class="flex items-center justify-between text-xs font-semibold text-slate-700">
<span>ORDINARIE PREGRESSE</span>
<x-filament::icon icon="heroicon-o-archive-box" class="w-4 h-4 text-slate-500" />
</div>
<div class="mt-2 text-2xl font-black tracking-tight text-emerald-700">
{{ number_format($totali['totale_ordinarie_pregresse_residuo'] ?? 0, 2, ',', '.') }}
</div>
<div class="mt-1 text-[11px] text-emerald-600 font-medium">
{{ count($gestioniPregresseOrd['items'] ?? []) }} gestioni chiuse a pareggio
</div>
</div>
</div>
{{-- SEZIONE 1: GESTIONE ORDINARIA CORRENTE --}}
<div class="rounded-2xl border border-slate-200 bg-white shadow-xs overflow-hidden">
<div class="px-5 py-3.5 bg-slate-50/90 border-b border-slate-200 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
<div class="flex items-center gap-2.5">
<span class="inline-flex items-center justify-center w-7 h-7 rounded-lg bg-indigo-50 text-indigo-700 font-bold text-xs border border-indigo-200">
📅
</span>
<div>
<h4 class="font-bold text-slate-900 text-sm">
{{ $gestioneOrdCorrente['titolo'] ?? 'GESTIONE ORDINARIA' }}
</h4>
<p class="text-[11px] text-slate-500">
Dettaglio temporale rate, conguagli e incassi dell'esercizio corrente
</p>
</div>
</div>
<div class="flex items-center gap-3 text-xs">
<div><span class="text-slate-500">Dovuto:</span> <strong class="font-mono text-slate-900">€ {{ number_format($gestioneOrdCorrente['totale_dovuto'] ?? 0, 2, ',', '.') }}</strong></div>
<div><span class="text-slate-500">Pagato:</span> <strong class="font-mono text-emerald-700">€ {{ number_format($gestioneOrdCorrente['totale_pagato'] ?? 0, 2, ',', '.') }}</strong></div>
<div><span class="text-slate-500">Residuo:</span> <strong class="font-mono {{ ($gestioneOrdCorrente['residuo'] ?? 0) > 0 ? 'text-rose-600' : 'text-slate-700' }}">€ {{ number_format($gestioneOrdCorrente['residuo'] ?? 0, 2, ',', '.') }}</strong></div>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-xs text-left border-collapse">
<thead>
<tr class="bg-slate-100/75 text-slate-600 font-semibold border-b border-slate-200">
<th class="px-4 py-2.5">Data Emiss.</th>
<th class="px-3 py-2.5">Rif.</th>
<th class="px-4 py-2.5">Descrizione Movimento</th>
<th class="px-4 py-2.5 text-right">Dovuto (€)</th>
<th class="px-4 py-2.5 text-center">Data Pagamento</th>
<th class="px-4 py-2.5 text-right">Pagato (€)</th>
<th class="px-4 py-2.5 text-right">Residuo (€)</th>
<th class="px-4 py-2.5 text-center">Stato</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@forelse($gestioneOrdCorrente['rate'] ?? [] as $rata)
<tr class="hover:bg-slate-50/80 transition">
<td class="px-4 py-2.5 font-mono text-slate-700 whitespace-nowrap">{{ $rata['data'] ?? '' }}</td>
<td class="px-3 py-2.5 font-mono text-slate-500 whitespace-nowrap">{{ $rata['rif'] ?? '' }}</td>
<td class="px-4 py-2.5 text-slate-900 font-medium">{{ $rata['descrizione'] ?? '' }}</td>
<td class="px-4 py-2.5 text-right font-mono font-semibold {{ ($rata['dovuto'] ?? 0) < 0 ? 'text-emerald-700' : 'text-slate-800' }}">
€ {{ number_format($rata['dovuto'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2.5 text-center font-mono text-slate-600 whitespace-nowrap">
{{ $rata['data_pagamento'] ?? '' }}
</td>
<td class="px-4 py-2.5 text-right font-mono text-emerald-700 font-semibold">
€ {{ number_format($rata['pagato'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2.5 text-right font-mono font-bold {{ ($rata['residuo'] ?? 0) > 0 ? 'text-rose-600' : 'text-slate-400' }}">
€ {{ number_format($rata['residuo'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2.5 text-center whitespace-nowrap">
@if(($rata['stato'] ?? '') === 'Saldata')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-emerald-100 text-emerald-800">
Saldata
</span>
@elseif(($rata['stato'] ?? '') === 'Compensato')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-indigo-100 text-indigo-800">
Compensato
</span>
@else
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-rose-100 text-rose-800">
Da Pagare
</span>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="8" class="px-4 py-6 text-center text-slate-500 italic">
Nessun movimento ordinario registrato per l'esercizio corrente.
</td>
</tr>
@endforelse
</tbody>
<tfoot class="bg-slate-50 font-bold border-t border-slate-200">
<tr>
<td colspan="3" class="px-4 py-2.5 text-right text-slate-700">Totale Gestione Ordinaria:</td>
<td class="px-4 py-2.5 text-right font-mono text-slate-900"> {{ number_format($gestioneOrdCorrente['totale_dovuto'] ?? 0, 2, ',', '.') }}</td>
<td></td>
<td class="px-4 py-2.5 text-right font-mono text-emerald-700"> {{ number_format($gestioneOrdCorrente['totale_pagato'] ?? 0, 2, ',', '.') }}</td>
<td class="px-4 py-2.5 text-right font-mono {{ ($gestioneOrdCorrente['residuo'] ?? 0) > 0 ? 'text-rose-600' : 'text-slate-600' }}">
{{ number_format($gestioneOrdCorrente['residuo'] ?? 0, 2, ',', '.') }}
</td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div>
{{-- SEZIONE 2: GESTIONI STRAORDINARIE (ATOMICHE PER DELIBERA/SPESA) --}}
<div class="space-y-4">
<div class="flex items-center justify-between">
<div class="flex items-center gap-2">
<span class="inline-flex items-center justify-center w-7 h-7 rounded-lg bg-amber-100 text-amber-800 font-bold text-xs border border-amber-300">
🏗️
</span>
<div>
<h4 class="font-bold text-slate-900 text-sm">
Gestioni Straordinarie (Delibere & Lavori)
</h4>
<p class="text-[11px] text-slate-500">
Ogni spesa straordinaria è isolata atomicamente con il proprio piano rate e pagamenti
</p>
</div>
</div>
<div class="text-xs font-semibold text-slate-600">
Totale Residuo Straordinarie: <span class="font-mono font-bold text-amber-700"> {{ number_format($totali['totale_straordinarie_residuo'] ?? 0, 2, ',', '.') }}</span>
</div>
</div>
@forelse($gestioniStraordinarie as $stra)
<div class="rounded-2xl border {{ ($stra['residuo'] ?? 0) > 0 ? 'border-amber-300 bg-white' : 'border-slate-200 bg-white' }} shadow-xs overflow-hidden">
<div class="px-5 py-3 {{ ($stra['residuo'] ?? 0) > 0 ? 'bg-amber-50/60 border-b border-amber-200' : 'bg-slate-50/80 border-b border-slate-200' }} flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
<div class="flex items-center gap-2.5">
<span class="px-2 py-0.5 rounded text-[10px] font-bold {{ ($stra['residuo'] ?? 0) > 0 ? 'bg-amber-200 text-amber-900' : 'bg-emerald-100 text-emerald-800' }}">
Spesa {{ $stra['num_spesa'] }}/{{ $stra['anno'] }}
</span>
<h5 class="font-bold text-slate-900 text-xs sm:text-sm">
{{ $stra['titolo'] }}
</h5>
</div>
<div class="flex items-center gap-3 text-xs">
<div><span class="text-slate-500">Dovuto:</span> <strong class="font-mono text-slate-800"> {{ number_format($stra['totale_dovuto'] ?? 0, 2, ',', '.') }}</strong></div>
<div><span class="text-slate-500">Versato:</span> <strong class="font-mono text-emerald-700"> {{ number_format($stra['totale_pagato'] ?? 0, 2, ',', '.') }}</strong></div>
<div><span class="text-slate-500">Residuo da pagare:</span> <strong class="font-mono {{ ($stra['residuo'] ?? 0) > 0 ? 'text-rose-600' : 'text-slate-600' }}"> {{ number_format($stra['residuo'] ?? 0, 2, ',', '.') }}</strong></div>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-xs text-left border-collapse">
<thead>
<tr class="bg-slate-100/60 text-slate-600 font-semibold border-b border-slate-200">
<th class="px-4 py-2">Data Emiss.</th>
<th class="px-3 py-2">Rif.</th>
<th class="px-4 py-2">Descrizione Rata</th>
<th class="px-4 py-2 text-right">Dovuto ()</th>
<th class="px-4 py-2 text-center">Data Pagamento</th>
<th class="px-4 py-2 text-right">Pagato ()</th>
<th class="px-4 py-2 text-right">Residuo ()</th>
<th class="px-4 py-2 text-center">Stato</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($stra['rate'] ?? [] as $sr)
<tr class="hover:bg-slate-50/80 transition">
<td class="px-4 py-2 font-mono text-slate-700 whitespace-nowrap">{{ $sr['data'] ?? '—' }}</td>
<td class="px-3 py-2 font-mono text-slate-500 whitespace-nowrap">{{ $sr['rif'] ?? '—' }}</td>
<td class="px-4 py-2 text-slate-900 font-medium">{{ $sr['descrizione'] ?? '—' }}</td>
<td class="px-4 py-2 text-right font-mono font-semibold text-slate-800">
{{ number_format($sr['dovuto'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2 text-center font-mono text-slate-600 whitespace-nowrap">
{{ $sr['data_pagamento'] ?? '—' }}
</td>
<td class="px-4 py-2 text-right font-mono text-emerald-700 font-semibold">
{{ number_format($sr['pagato'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2 text-right font-mono font-bold {{ ($sr['residuo'] ?? 0) > 0 ? 'text-rose-600' : 'text-slate-400' }}">
{{ number_format($sr['residuo'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2 text-center whitespace-nowrap">
@if(($sr['stato'] ?? '') === 'Saldata')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-emerald-100 text-emerald-800">
Saldata
</span>
@elseif(($sr['stato'] ?? '') === 'Parziale')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-amber-100 text-amber-800">
Parziale
</span>
@elseif(($sr['stato'] ?? '') === 'Da Emettere')
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-slate-100 text-slate-600">
Da Emettere
</span>
@else
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-rose-100 text-rose-800">
Da Pagare
</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@empty
<div class="rounded-2xl border border-slate-200 bg-white p-6 text-center text-slate-500 italic text-xs">
Nessuna gestione straordinaria registrata per questa unità.
</div>
@endforelse
</div>
{{-- SEZIONE 3: RIEPILOGO GESTIONI ORDINARIE PREGRESSE (CONSUNTIVI CHIUSI) --}}
<div class="rounded-2xl border border-slate-200 bg-white shadow-xs overflow-hidden">
<div class="px-5 py-3.5 bg-slate-50/90 border-b border-slate-200 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-2">
<div class="flex items-center gap-2.5">
<span class="inline-flex items-center justify-center w-7 h-7 rounded-lg bg-slate-200 text-slate-700 font-bold text-xs">
🏛️
</span>
<div>
<h4 class="font-bold text-slate-900 text-sm">
Riepilogo Storico Gestioni Ordinarie Pregresse
</h4>
<p class="text-[11px] text-slate-500">
Storico annuale consolidato dei consuntivi chiusi definitivamente
</p>
</div>
</div>
<div class="text-xs">
<span class="text-slate-500">Saldo complessivo pregresso:</span>
<strong class="font-mono text-emerald-700 font-bold"> {{ number_format($gestioniPregresseOrd['saldo_residuo'] ?? 0, 2, ',', '.') }}</strong>
</div>
</div>
<div class="overflow-x-auto">
<table class="w-full text-xs text-left border-collapse">
<thead>
<tr class="bg-slate-100/75 text-slate-600 font-semibold border-b border-slate-200">
<th class="px-4 py-2.5">Anno Esercizio</th>
<th class="px-4 py-2.5">Descrizione Gestione</th>
<th class="px-4 py-2.5 text-right">Totale Addebitato ()</th>
<th class="px-4 py-2.5 text-right">Totale Versato ()</th>
<th class="px-4 py-2.5 text-right">Saldo Residuo ()</th>
<th class="px-4 py-2.5 text-center">Stato Consuntivo</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@forelse($gestioniPregresseOrd['items'] ?? [] as $gp)
<tr class="hover:bg-slate-50/80 transition">
<td class="px-4 py-2 font-mono font-bold text-slate-700 whitespace-nowrap">{{ $gp['anno'] }}</td>
<td class="px-4 py-2 text-slate-900 font-medium">{{ $gp['titolo'] }}</td>
<td class="px-4 py-2 text-right font-mono text-slate-800">
{{ number_format($gp['dovuto'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2 text-right font-mono text-emerald-700 font-semibold">
{{ number_format($gp['pagato'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2 text-right font-mono font-bold text-emerald-600">
{{ number_format($gp['saldo'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2 text-center whitespace-nowrap">
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[10px] font-semibold bg-emerald-50 text-emerald-700 border border-emerald-200">
{{ $gp['stato'] ?? 'Chiusa' }}
</span>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="px-4 py-4 text-center text-slate-500 italic">
Nessuna gestione pregressa archiviata.
</td>
</tr>
@endforelse
</tbody>
<tfoot class="bg-slate-50 font-bold border-t border-slate-200">
<tr>
<td colspan="2" class="px-4 py-2.5 text-right text-slate-700">Totale Storico Consuntivi Chiusi:</td>
<td class="px-4 py-2.5 text-right font-mono text-slate-900">
{{ number_format($gestioniPregresseOrd['totale_dovuto'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2.5 text-right font-mono text-emerald-700">
{{ number_format($gestioniPregresseOrd['totale_versato'] ?? 0, 2, ',', '.') }}
</td>
<td class="px-4 py-2.5 text-right font-mono text-emerald-600">
{{ number_format($gestioniPregresseOrd['saldo_residuo'] ?? 0, 2, ',', '.') }}
</td>
<td></td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
@endif
@if($tab === 'millesimi')
@php
$ecData = $this->getEstrattoContoNominativoDettaglioProperty();
$soggetto = $ecData['soggetto'] ?? [];
@endphp
<div class="space-y-6">
{{-- Sezione 1: Tabelle Millesimali Assegnate all'Unità --}}
<x-filament::section>
<div class="flex items-center justify-between border-b border-gray-100 pb-3 mb-4">
<div class="flex items-center gap-2">
<x-filament::icon icon="heroicon-o-chart-pie" class="h-5 w-5 text-indigo-600" />
<span class="font-bold text-slate-900 text-sm">Tabelle Millesimali Assegnate</span>
</div>
<span class="text-xs text-slate-500">Millesimi generali e speciali configurati</span>
</div>
<div class="mb-4 flex flex-wrap gap-2">
@php
$gruppi = [
'ordinarie' => 'ORDINARIE',
'riscaldamento' => 'RISCALDAMENTO',
'straordinarie' => 'STRAORDINARIE',
];
@endphp
@foreach($gruppi as $key => $label)
<button
type="button"
wire:click="setMillesimiGruppo('{{ $key }}')"
class="inline-flex items-center rounded-lg border px-4 py-2 text-xs font-semibold transition
{{ ($millesimiGruppo ?? 'ordinarie') === $key ? 'border-primary-300 bg-primary-50 text-primary-700 shadow-sm' : 'border-gray-200 bg-white text-gray-700 hover:bg-gray-50' }}"
>
{{ $label }}
</button>
@endforeach
</div>
@if(empty($millesimiPerTabella))
<div class="text-xs text-gray-500">Nessuna tabella millesimale associata.</div>
@else
@php
$selectedGruppo = $millesimiGruppo ?? 'ordinarie';
$filteredMillesimi = array_values(array_filter($millesimiPerTabella, fn ($r) => ($r['gruppo'] ?? 'ordinarie') === $selectedGruppo));
@endphp
<div class="overflow-x-auto rounded-lg border border-slate-200">
<table class="min-w-full text-xs">
<thead class="bg-slate-50 text-slate-600 border-b border-slate-200 font-semibold">
<tr class="text-left">
<th class="py-2.5 px-4">Codice Tabella</th>
<th class="py-2.5 px-4">Denominazione</th>
<th class="py-2.5 px-4 text-right">Valore Millesimi (mm)</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100 bg-white">
@forelse($filteredMillesimi as $r)
@php
$tipo = $r['tipo'] ?? 'altro';
$tipoLabel = ucwords(str_replace('_', ' ', (string) $tipo));
$prevTipo = $loop->first ? null : ($filteredMillesimi[$loop->index - 1]['tipo'] ?? 'altro');
@endphp
@if($loop->first || $tipo !== $prevTipo)
<tr class="bg-indigo-50/40">
<td class="py-2 px-4 font-bold text-indigo-900" colspan="3">{{ $tipoLabel }}</td>
</tr>
@endif
<tr class="hover:bg-slate-50">
<td class="py-2.5 px-4 font-mono font-bold text-indigo-700">{{ $r['codice'] }}</td>
<td class="py-2.5 px-4 text-slate-800">{{ $r['nome'] }}</td>
<td class="py-2.5 px-4 text-right font-mono font-semibold text-slate-900">{{ number_format($r['millesimi'], 4, ',', '.') }}</td>
</tr>
@empty
<tr>
<td class="py-4 text-center text-gray-500" colspan="3">Nessun millesimo presente per il gruppo selezionato</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@endif
</x-filament::section>
{{-- Sezione 2: Spese e Millesimi Addebitati per Gestione --}}
<div class="rounded-xl border border-slate-200 bg-white overflow-hidden shadow-xs">
<div class="border-b border-slate-200 bg-slate-50 px-4 py-3 font-semibold text-slate-800 text-sm flex items-center justify-between">
<div class="flex items-center gap-2">
<span>📊 Spese e Millesimi Addebitati a <strong>{{ $soggetto['nominativo'] ?? 'Condomino' }}</strong></span>
<span class="rounded bg-indigo-100 px-2 py-0.5 text-xs text-indigo-800 font-normal">
{{ reset($ecData['addebiti'])['anno_gestione'] ?? 'Anno In Corso' }}
</span>
</div>
<span class="text-xs text-slate-500 font-normal">Suddivise per Gruppo (Ordinaria, Riscaldamento, Straordinaria)</span>
</div>
@if(empty($ecData['addebiti']))
<div class="p-6 text-center text-slate-500 text-xs">Nessun addebito preventivato o consuntivato per questo nominativo.</div>
@else
<div class="overflow-x-auto">
<table class="w-full text-left text-xs">
<thead class="bg-slate-100 text-slate-700 font-semibold border-b border-slate-200">
<tr>
<th class="px-4 py-2.5">Codice Tabella</th>
<th class="px-4 py-2.5">Descrizione Tabella</th>
<th class="px-4 py-2.5">Tipo Gestione</th>
<th class="px-4 py-2.5 text-right">Millesimi (mm)</th>
<th class="px-4 py-2.5 text-right">Preventivo (€)</th>
<th class="px-4 py-2.5 text-right">Consuntivo (€)</th>
<th class="px-4 py-2.5 text-right">Conguaglio (€)</th>
<th class="px-4 py-2.5 text-center">Voci Spesa</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($ecData['addebiti'] as $addIndex => $add)
<tr class="hover:bg-indigo-50/50 transition cursor-pointer" onclick="document.getElementById('voc-spe-row-{{ $addIndex }}') ? document.getElementById('voc-spe-row-{{ $addIndex }}').classList.toggle('hidden') : null">
<td class="px-4 py-2.5 font-mono font-bold text-indigo-700">{{ $add['cod_tabella'] }}</td>
<td class="px-4 py-2.5 font-semibold text-slate-900">{{ $add['descrizione_tab'] }}</td>
<td class="px-4 py-2.5">
<span class="inline-flex items-center rounded-md px-2 py-0.5 text-xs font-semibold {{ $add['tipo_label'] === 'Riscaldamento' ? 'bg-amber-100 text-amber-800' : ($add['tipo_label'] === 'Straordinaria' ? 'bg-rose-100 text-rose-800' : 'bg-slate-100 text-slate-800') }}">
{{ $add['tipo_label'] }}
</span>
</td>
<td class="px-4 py-2.5 text-right font-mono text-slate-600">{{ number_format($add['millesimi'], 2, ',', '.') }}</td>
<td class="px-4 py-2.5 text-right font-mono font-medium text-slate-800">€ {{ number_format($add['preventivo_euro'], 2, ',', '.') }}</td>
<td class="px-4 py-2.5 text-right font-mono font-medium text-slate-800">€ {{ number_format($add['consuntivo_euro'], 2, ',', '.') }}</td>
<td class="px-4 py-2.5 text-right font-mono font-bold {{ $add['conguaglio_euro'] > 0 ? 'text-amber-600' : ($add['conguaglio_euro'] < 0 ? 'text-emerald-600' : 'text-slate-500') }}">
€ {{ number_format($add['conguaglio_euro'], 2, ',', '.') }}
</td>
<td class="px-4 py-2.5 text-center">
@if(!empty($add['voci_spesa']))
<span class="inline-flex items-center gap-1 rounded bg-indigo-50 border border-indigo-200 px-2 py-0.5 text-xs font-semibold text-indigo-700">
<span>{{ count($add['voci_spesa']) }} voci</span>
<span>🔍</span>
</span>
@else
<span class="text-slate-400 text-xs">—</span>
@endif
</td>
</tr>
@if(!empty($add['voci_spesa']))
<tr id="voc-spe-row-{{ $addIndex }}" class="hidden bg-slate-50/80 border-b border-indigo-100">
<td colspan="8" class="p-3">
<div class="rounded-lg border border-indigo-100 bg-white p-3 shadow-xs">
<div class="text-xs font-bold text-indigo-900 mb-2 flex items-center gap-2">
<span>📋 Voci di Spesa collegate alla Tabella <strong>{{ $add['cod_tabella'] }}</strong></span>
<span class="text-slate-500 font-normal">({{ count($add['voci_spesa']) }} voci da voc_spe)</span>
</div>
<table class="w-full text-left text-xs border border-slate-200 rounded">
<thead class="bg-indigo-50 text-indigo-900 font-semibold">
<tr>
<th class="px-3 py-1.5">Cod. Voce</th>
<th class="px-3 py-1.5">Descrizione Voce</th>
<th class="px-3 py-1.5 text-center">% Prop.</th>
<th class="px-3 py-1.5 text-center">% Inq.</th>
<th class="px-3 py-1.5 text-right">Preventivo Voce (€)</th>
<th class="px-3 py-1.5 text-right">Consuntivo Voce (€)</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($add['voci_spesa'] as $voc)
<tr class="hover:bg-slate-50">
<td class="px-3 py-1.5 font-mono font-bold text-slate-700">{{ $voc['cod_voce'] }}</td>
<td class="px-3 py-1.5 text-slate-900 font-medium">{{ $voc['descrizione'] }}</td>
<td class="px-3 py-1.5 text-center font-mono text-slate-600">{{ number_format($voc['perc_proprietario'], 0) }}%</td>
<td class="px-3 py-1.5 text-center font-mono text-slate-600">{{ number_format($voc['perc_inquilino'], 0) }}%</td>
<td class="px-3 py-1.5 text-right font-mono text-slate-800">€ {{ number_format($voc['preventivo_euro'], 2, ',', '.') }}</td>
<td class="px-3 py-1.5 text-right font-mono text-slate-800">€ {{ number_format($voc['consuntivo_euro'], 2, ',', '.') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</td>
</tr>
@endif
@endforeach
</tbody>
</table>
</div>
@endif
</div>
</div>
@endif
@if($tab === 'preferenze')
@php
$protocolloList = $this->getProtocolloComunicazioniProperty();
@endphp
<div class="space-y-6">
{{-- 1. Protocollo Corrispondenza ed Estratti Conto Inviati --}}
<div class="rounded-xl border border-slate-200 bg-white overflow-hidden shadow-xs">
<div class="border-b border-slate-200 bg-slate-50 px-4 py-3 flex items-center justify-between">
<div class="flex items-center gap-2">
<span class="text-base">📨</span>
<div>
<span class="font-bold text-slate-900 text-sm">Protocollo Comunicazioni & Corrispondenza Inviata</span>
<div class="text-xs text-slate-500">Estratti conto, lettere, circolari e comunicazioni storiche collegate all'unità</div>
</div>
</div>
<span class="rounded-full bg-indigo-50 border border-indigo-200 px-3 py-1 text-xs font-bold text-indigo-800">
{{ count($protocolloList) }} documenti a protocollo
</span>
</div>
@if(empty($protocolloList))
<div class="p-8 text-center text-slate-500 text-xs">
Nessuna comunicazione o estratto conto inviato registrato a protocollo per questa unità.
</div>
@else
<div class="overflow-x-auto">
<table class="w-full text-left text-xs">
<thead class="bg-slate-100 text-slate-700 font-semibold border-b border-slate-200">
<tr>
<th class="px-4 py-2.5">Data Invio</th>
<th class="px-4 py-2.5">Protocollo / Rif.</th>
<th class="px-4 py-2.5">Canale</th>
<th class="px-4 py-2.5">Destinatario</th>
<th class="px-4 py-2.5">Oggetto / Contenuto</th>
<th class="px-4 py-2.5 text-right">Importo E/C</th>
<th class="px-4 py-2.5 text-center">Allegato</th>
<th class="px-4 py-2.5">Note</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-100">
@foreach($protocolloList as $prot)
<tr class="hover:bg-indigo-50/40 transition">
<td class="px-4 py-2.5 font-medium text-slate-900 whitespace-nowrap">{{ $prot['data_invio'] }}</td>
<td class="px-4 py-2.5 font-mono font-bold text-indigo-700 whitespace-nowrap">{{ $prot['protocollo'] }}</td>
<td class="px-4 py-2.5 whitespace-nowrap">
<span class="inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-xs font-semibold
{{ str_contains(strtolower($prot['canale']), 'pec') ? 'bg-emerald-100 text-emerald-800' : (str_contains(strtolower($prot['canale']), 'mail') ? 'bg-blue-100 text-blue-800' : 'bg-slate-100 text-slate-800') }}">
<span>{{ str_contains(strtolower($prot['canale']), 'pec') ? '🛡️' : (str_contains(strtolower($prot['canale']), 'mail') ? '✉️' : '📮') }}</span>
<span>{{ $prot['canale'] }}</span>
</span>
</td>
<td class="px-4 py-2.5 font-medium text-slate-900">
<div>{{ $prot['destinatario'] }}</div>
<div class="text-[10px] text-slate-500 font-normal">{{ $prot['ruolo'] }}</div>
</td>
<td class="px-4 py-2.5 text-slate-700 max-w-xs truncate" title="{{ $prot['oggetto'] }}">
{{ $prot['oggetto'] }}
</td>
<td class="px-4 py-2.5 text-right font-mono font-bold {{ ($prot['importo'] ?? 0) > 0 ? 'text-slate-900' : 'text-slate-400' }}">
{{ $prot['importo'] !== null ? '€ ' . number_format($prot['importo'], 2, ',', '.') : '—' }}
</td>
<td class="px-4 py-2.5 text-center">
@php
$allegatiList = !empty($prot['allegati']) ? $prot['allegati'] : (!empty($prot['nome_file']) ? [['filename' => $prot['nome_file'], 'path' => $prot['file_path'], 'exists' => $prot['file_exists'], 'is_pdf' => str_ends_with(strtolower($prot['nome_file']), '.pdf'), 'is_image' => preg_match('/\.(jpg|jpeg|png|webp|gif)$/i', $prot['nome_file'])]] : []);
@endphp
@if(!empty($allegatiList))
<div class="flex flex-wrap items-center justify-center gap-1.5 max-w-xs mx-auto">
@foreach($allegatiList as $att)
@php
$attName = $att['filename'] ?? 'file';
$attPath = $att['path'] ?? '';
$attExists = $att['exists'] ?? false;
$isPdf = $att['is_pdf'] ?? str_ends_with(strtolower($attName), '.pdf');
$isImg = $att['is_image'] ?? preg_match('/\.(jpg|jpeg|png|webp|gif)$/i', $attName);
@endphp
<button
type="button"
wire:click="previewProtocolDoc('{{ $prot['id'] }}', '{{ addslashes($attName) }}', '{{ addslashes($attPath) }}')"
class="inline-flex items-center gap-1 rounded-md px-2 py-0.5 text-[11px] font-mono transition shadow-2xs {{ $attExists ? 'bg-slate-100 hover:bg-indigo-100 hover:text-indigo-800 text-slate-700 border border-slate-200 cursor-pointer' : 'bg-slate-50 text-slate-400 border border-dashed border-slate-200 cursor-pointer' }}"
title="{{ $attExists ? 'Visualizza anteprima (' . $attName . ')' : 'File non presente localmente (' . $attName . ')' }}"
>
<span>{{ $isPdf ? '📄' : ($isImg ? '🖼️' : '📎') }}</span>
<span class="truncate max-w-[120px] {{ $attExists ? 'underline font-medium' : 'line-through' }}">{{ $attName }}</span>
</button>
@endforeach
</div>
@else
<span class="text-slate-400"></span>
@endif
</td>
<td class="px-4 py-2.5 text-slate-500 text-[11px] max-w-xs truncate" title="{{ $prot['note'] }}">
{{ $prot['note'] ?: '—' }}
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
{{-- 2. Preferenze di Invio Ufficiali per i Soggetti --}}
<x-filament::section>
<x-slot name="heading">Canali Ufficiali di Notifica</x-slot>
<x-slot name="description">Preferenze di spedizione canoniche per proprietari e comproprietari</x-slot>
<div class="space-y-4">
@if(empty($canaliComunicazione))
<div class="text-xs text-gray-500">Nessun proprietario o comproprietario registrato per questa unità.</div>
@else
<div class="overflow-x-auto rounded-lg border border-gray-200">
<table class="w-full text-left text-xs text-gray-500">
<thead class="bg-gray-50 text-xs uppercase text-gray-700 font-semibold border-b">
<tr>
<th class="px-4 py-2.5">Soggetto / Nominativo</th>
<th class="px-4 py-2.5">Convocazione Assemblea</th>
<th class="px-4 py-2.5">Invio Verbali</th>
<th class="px-4 py-2.5">Solleciti e Rate</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
@foreach($canaliComunicazione as $soggettoId => $p)
<tr class="hover:bg-gray-50/50">
<td class="px-4 py-3">
<div class="font-bold text-gray-900">{{ $p['nominativo'] }}</div>
<div class="text-xs text-gray-500 font-mono mt-0.5">{{ $p['codice_fiscale'] ?? '—' }}</div>
</td>
<td class="px-4 py-3">
<select
wire:change="salvaCanaleComunicazione({{ $soggettoId }}, 'convocazione', $event.target.value)"
class="w-full text-xs rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 font-semibold text-gray-700">
@foreach(['PEC', 'Raccomandata AR', 'Posta Ordinaria', 'Mano'] as $opt)
<option value="{{ $opt }}" {{ $p['convocazione'] === $opt ? 'selected' : '' }}>{{ $opt }}</option>
@endforeach
</select>
</td>
<td class="px-4 py-3">
<select
wire:change="salvaCanaleComunicazione({{ $soggettoId }}, 'verbali', $event.target.value)"
class="w-full text-xs rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 font-semibold text-gray-700">
@foreach(['PEC', 'Raccomandata AR', 'Posta Ordinaria', 'Mano'] as $opt)
<option value="{{ $opt }}" {{ $p['verbali'] === $opt ? 'selected' : '' }}>{{ $opt }}</option>
@endforeach
</select>
</td>
<td class="px-4 py-3">
<select
wire:change="salvaCanaleComunicazione({{ $soggettoId }}, 'solleciti', $event.target.value)"
class="w-full text-xs rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 font-semibold text-gray-700">
@foreach(['Email Standard', 'PEC', 'Posta Ordinaria'] as $opt)
<option value="{{ $opt }}" {{ $p['solleciti'] === $opt ? 'selected' : '' }}>{{ $opt }}</option>
@endforeach
</select>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</div>
</x-filament::section>
</div>
@endif
@if($tab === 'acqua')
<div class="space-y-4">
<x-filament::section>
<x-slot name="heading">Storico letture acqua unità</x-slot>
<x-slot name="description">Andamento letture, consumi e richieste legate a questa utenza immobiliare.</x-slot>
<div class="grid gap-3 md:grid-cols-4">
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Letture registrate</div>
<div class="mt-2 text-xl font-semibold text-gray-900">{{ number_format((int) ($acquaStats['totale_letture'] ?? 0), 0, ',', '.') }}</div>
</div>
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Consumi storici</div>
<div class="mt-2 text-xl font-semibold text-gray-900">{{ number_format((float) ($acquaStats['totale_consumi_mc'] ?? 0), 3, ',', '.') }} mc</div>
</div>
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Ultima lettura</div>
<div class="mt-2 text-xl font-semibold text-gray-900">{{ isset($acquaStats['ultima_lettura']) && $acquaStats['ultima_lettura'] !== null ? number_format((float) $acquaStats['ultima_lettura'], 3, ',', '.') : '—' }}</div>
<div class="mt-1 text-[11px] text-gray-500">{{ $acquaStats['ultima_data'] ?? 'nessuna data' }}</div>
</div>
<div class="rounded-lg border bg-gray-50 p-3">
<div class="text-xs text-gray-500">Richieste aperte</div>
<div class="mt-2 text-xl font-semibold text-gray-900">{{ number_format((int) ($acquaStats['richieste_aperte'] ?? 0), 0, ',', '.') }}</div>
</div>
</div>
<div class="mt-4 grid gap-4 lg:grid-cols-[1.2fr_0.8fr]">
<div class="rounded-xl border bg-cyan-50 p-4">
<div class="text-sm font-semibold text-cyan-900">Utenza acqua collegata</div>
<div class="mt-2 grid gap-2 text-xs text-cyan-900 md:grid-cols-2">
<div>Servizio: <span class="font-semibold">{{ $acquaStats['servizio_label'] ?? 'non configurato' }}</span></div>
<div>Matricola: <span class="font-semibold">{{ $acquaStats['matricola'] ?? '—' }}</span></div>
<div>Seriale unità: <span class="font-semibold">{{ $unita->acqua_contatore_seriale ?? '—' }}</span></div>
<div>Gateway ID: <span class="font-semibold">{{ $unita->acqua_gateway_device_id ?? '—' }}</span></div>
<div>Codice utenza: <span class="font-semibold">{{ $acquaStats['utenza'] ?? '—' }}</span></div>
<div>Contratto: <span class="font-semibold">{{ $acquaStats['contratto'] ?? '—' }}</span></div>
</div>
</div>
<div class="rounded-xl border bg-white p-4">
<div class="text-sm font-semibold text-gray-900">Azioni rapide</div>
<div class="mt-3 flex flex-wrap gap-2">
@if(!empty($acquaQuickLinks['ticket_light']))
<a href="{{ $acquaQuickLinks['ticket_light'] }}" class="inline-flex items-center rounded-md border border-cyan-300 bg-cyan-50 px-3 py-1.5 text-xs font-medium text-cyan-800 hover:bg-cyan-100">Nuova lettura unità</a>
@endif
@if(!empty($acquaQuickLinks['archivio']))
<a href="{{ $acquaQuickLinks['archivio'] }}" class="inline-flex items-center rounded-md border border-gray-300 bg-gray-50 px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-100">Archivio letture</a>
@endif
@if(!empty($acquaQuickLinks['hub_stabile']))
<a href="{{ $acquaQuickLinks['hub_stabile'] }}" class="inline-flex items-center rounded-md border border-gray-300 bg-gray-50 px-3 py-1.5 text-xs font-medium text-gray-700 hover:bg-gray-100">Campagna stabile</a>
@endif
</div>
</div>
</div>
</x-filament::section>
<x-filament::section>
<x-slot name="heading">Dettaglio letture e consumi nel tempo</x-slot>
<x-slot name="description">Storico operativo della singola unità con canale di arrivo, riferimento e protocollo.</x-slot>
<div class="overflow-x-auto">
<table class="min-w-full text-sm">
<thead>
<tr class="border-b text-gray-500">
<th class="px-2 py-2 text-left">Data</th>
<th class="px-2 py-2 text-left">Periodo</th>
<th class="px-2 py-2 text-right">Lett. iniziale</th>
<th class="px-2 py-2 text-right">Lett. finale</th>
<th class="px-2 py-2 text-right">Consumo</th>
<th class="px-2 py-2 text-left">Canale / stato</th>
<th class="px-2 py-2 text-left">Riferimento</th>
</tr>
</thead>
<tbody>
@forelse($acquaLettureStorico as $row)
<tr class="border-b border-gray-100">
<td class="px-2 py-2">{{ $row['data'] ?: '—' }}</td>
<td class="px-2 py-2">{{ $row['periodo'] ?: '—' }}</td>
<td class="px-2 py-2 text-right">{{ isset($row['lettura_inizio']) && $row['lettura_inizio'] !== null ? number_format((float) $row['lettura_inizio'], 3, ',', '.') : '—' }}</td>
<td class="px-2 py-2 text-right">{{ isset($row['lettura_fine']) && $row['lettura_fine'] !== null ? number_format((float) $row['lettura_fine'], 3, ',', '.') : '—' }}</td>
<td class="px-2 py-2 text-right">{{ isset($row['consumo_valore']) && $row['consumo_valore'] !== null ? number_format((float) $row['consumo_valore'], 3, ',', '.') . ' ' . ($row['consumo_unita'] ?? 'mc') : '—' }}</td>
<td class="px-2 py-2">
<div>{{ $row['canale'] ?: '—' }}</div>
<div class="text-[11px] text-gray-500">{{ $row['workflow'] ?: '—' }} @if(!empty($row['protocollo'])) · {{ $row['protocollo'] }} @endif</div>
</td>
<td class="px-2 py-2">
<div>{{ $row['riferimento'] ?: '—' }}</div>
@if(!empty($row['fattura_label']))
<div class="text-[11px] text-cyan-700">{{ $row['fattura_label'] }}</div>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="7" class="px-2 py-6 text-center text-gray-500">Nessuna lettura acqua registrata per questa unità.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@php
$tabelleAcqua = collect($preventiviPerTabella)->filter(fn($t) => str_starts_with(strtoupper($t['codice'] ?? ''), 'AC'))->values();
$ripartiAcqua = collect($ripartizioniPerTabella)->filter(fn($t) => str_starts_with(strtoupper($t['tabella_codice'] ?? ''), 'AC'))->values();
@endphp
@if($tabelleAcqua->isNotEmpty())
<div class="mt-6">
<h3 class="text-sm font-bold text-gray-900 mb-3">Millesimi e Quote Acqua di Preventivo</h3>
<div class="space-y-4">
@foreach($tabelleAcqua as $tabella)
<div class="rounded-2xl border border-cyan-100 bg-cyan-50/20 p-4">
<div class="flex items-center justify-between mb-2">
<span class="inline-flex items-center rounded-full bg-cyan-50 px-2.5 py-0.5 text-xs font-semibold text-cyan-700">{{ $tabella['codice'] }} · {{ $tabella['nome'] }}</span>
<div class="text-right">
<div class="text-xs text-gray-500">Totale tabella</div>
<div class="text-lg font-semibold text-gray-900">{{ number_format($tabella['total_preventivo'], 2, ',', '.') }} </div>
</div>
</div>
<div class="overflow-x-auto bg-white rounded-xl border border-cyan-100 p-2">
<table class="min-w-full text-sm">
<thead>
<tr class="text-gray-500">
<th class="text-left py-1">Voce</th>
<th class="text-right py-1">Preventivo</th>
<th class="text-right py-1">Quota unità</th>
<th class="text-right py-1">Prop.</th>
<th class="text-right py-1">Inquilino</th>
<th class="text-right py-1">% Prop.</th>
<th class="text-right py-1">% Inq.</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach($tabella['voci'] as $voce)
<tr>
<td class="py-1 text-gray-800">{{ $voce['codice'] }} · {{ $voce['descrizione'] }}</td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['importo_preventivato'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['quota_unita'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['importo_proprietario'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['importo_inquilino'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-700">{{ number_format(100.00 - ($voce['percentuale_inquilino'] ?? 0), 2, ',', '.') }} %</td>
<td class="py-1 text-right text-gray-700">{{ number_format($voce['percentuale_inquilino'] ?? 0, 2, ',', '.') }} %</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endforeach
</div>
</div>
@endif
@if($ripartiAcqua->isNotEmpty())
<div class="mt-6">
<h3 class="text-sm font-bold text-gray-900 mb-3">Millesimi e Quote Acqua di Consuntivo</h3>
<div class="space-y-4">
@foreach($ripartiAcqua as $tabella)
<div class="rounded-2xl border border-cyan-100 bg-cyan-50/20 overflow-hidden">
<div class="flex items-center gap-2 bg-white px-3 py-2 border-b border-cyan-100">
<span class="inline-flex items-center rounded-full bg-cyan-50 px-2 py-0.5 text-xs font-semibold text-cyan-700">{{ $tabella['tabella_codice'] }}</span>
<span class="text-sm font-semibold text-gray-900">{{ $tabella['tabella_nome'] }}</span>
</div>
<div class="overflow-x-auto bg-white">
<table class="min-w-full text-sm">
<thead>
<tr class="text-gray-500 border-b">
<th class="text-left py-2 px-2">Voce</th>
<th class="text-center py-2 px-2">Gestione</th>
<th class="text-center py-2 px-2">Calcolo</th>
<th class="text-right py-2 px-2">% applicata</th>
<th class="text-right py-2 px-2">Quota finale</th>
<th class="text-right py-2 px-2">% prop</th>
<th class="text-right py-2 px-2">% inquilino</th>
<th class="text-right py-2 px-2">Prop.</th>
<th class="text-right py-2 px-2">Inq.</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach($tabella['righe'] as $r)
<tr>
<td class="py-2 px-2 text-gray-900 font-semibold">{{ $r['voce_codice'] ?? '—' }} {{ $r['voce_descrizione'] ?? '' }}</td>
<td class="py-2 px-2 text-center text-gray-700">{{ $r['tipo_gestione'] ?? '—' }}</td>
<td class="py-2 px-2 text-center text-gray-700">{{ $r['calcolo'] ?? '—' }}</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['percentuale_applicata'] ?? 0, 2, ',', '.') }}%</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['quota_finale'] ?? 0, 4, ',', '.') }}</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format(100.00 - ($r['percentuale_inquilino'] ?? 0), 2, ',', '.') }}%</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['percentuale_inquilino'] ?? 0, 2, ',', '.') }}%</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['importo_proprietario'] ?? 0, 4, ',', '.') }}</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['importo_inquilino'] ?? 0, 4, ',', '.') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endforeach
</div>
</div>
@endif
</x-filament::section>
</div>
@endif
@if($tab === 'economico')
<div class="grid gap-4">
{{-- Contenuti economici: preventivi/riparti (rate emesse spostate nel tab Estratto conto) --}}
@if(!empty($preventiviPerTabella))
<x-filament::section>
<div class="flex flex-wrap items-center justify-between gap-3 mb-3">
<div>
<div class="text-sm font-semibold text-gray-900">Preventivo per tabella</div>
<div class="text-xs text-gray-500">Quote unità e riparto proprietario/inquilino (dett_tab cond_inquil).</div>
</div>
@if(!empty($totaliPerGestione))
<div class="flex flex-wrap gap-2 text-sm text-gray-700">
<span class="rounded border px-3 py-1 bg-gray-50">O: {{ number_format($totaliPerGestione['O'] ?? 0, 2, ',', '.') }} </span>
<span class="rounded border px-3 py-1 bg-gray-50">R: {{ number_format($totaliPerGestione['R'] ?? 0, 2, ',', '.') }} </span>
<span class="rounded border px-3 py-1 bg-gray-50">S: {{ number_format($totaliPerGestione['S'] ?? 0, 2, ',', '.') }} </span>
</div>
@endif
</div>
<div class="space-y-4">
@foreach($preventiviPerTabella as $tabella)
@if(str_starts_with(strtoupper($tabella['codice'] ?? ''), 'AC')) @continue @endif
<div class="rounded-2xl border bg-gray-50 p-4">
<div class="flex items-center justify-between mb-2">
<div>
<div class="text-xs text-gray-600">{{ $tabella['tabella_codice'] }} · tipo {{ $tabella['tipo'] }}</div>
<div class="text-sm font-semibold text-gray-900">{{ $tabella['tabella_nome'] }}</div>
</div>
<div class="text-right">
<div class="text-xs text-gray-500">Totale tabella</div>
<div class="text-lg font-semibold text-gray-900">{{ number_format($tabella['total_preventivo'], 2, ',', '.') }} </div>
</div>
</div>
<div class="overflow-x-auto">
<table class="min-w-full text-sm">
<thead>
<tr class="text-gray-500">
<th class="text-left py-1">Voce</th>
<th class="text-right py-1">Preventivo</th>
<th class="text-right py-1">Quota unità</th>
<th class="text-right py-1">Prop.</th>
<th class="text-right py-1">Inquilino</th>
<th class="text-right py-1">% Prop.</th>
<th class="text-right py-1">% Inq.</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach($tabella['voci'] as $voce)
<tr>
<td class="py-1 text-gray-800">{{ $voce['codice'] }} · {{ $voce['descrizione'] }}</td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['importo_preventivato'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['quota_unita'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['importo_proprietario'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-900">{{ number_format($voce['importo_inquilino'] ?? 0, 2, ',', '.') }} </td>
<td class="py-1 text-right text-gray-700">{{ number_format($voce['percentuale_inquilino'] ?? 0, 2, ',', '.') }} %</td>
</tr>
@endforeach
</tbody>
</table>
</div>
<div class="mt-3 grid grid-cols-1 md:grid-cols-3 gap-3 text-sm">
<div class="rounded border bg-white p-3">
<div class="text-gray-500">Millesimi unità / tabella</div>
<div class="font-semibold text-gray-900">{{ number_format($tabella['unit_millesimi'], 3, ',', '.') }} / {{ number_format($tabella['tabella_millesimi'], 3, ',', '.') }}</div>
</div>
<div class="rounded border bg-white p-3">
<div class="text-gray-500">Quota unità</div>
<div class="font-semibold text-gray-900">{{ number_format($tabella['quota_unit'], 2, ',', '.') }} </div>
</div>
<div class="rounded border bg-white p-3">
<div class="text-gray-500">Riparto proprietario / inquilino</div>
<div class="font-semibold text-gray-900">{{ number_format($tabella['importo_proprietario'], 2, ',', '.') }} / {{ number_format($tabella['importo_inquilino'], 2, ',', '.') }} </div>
<div class="text-xs text-gray-500">% inquilino: {{ number_format($tabella['percentuale_inquilino'] ?? 0, 2, ',', '.') }}</div>
</div>
</div>
</div>
@endforeach
</div>
</x-filament::section>
@endif
<x-filament::section>
<div class="flex items-center gap-2 text-sm font-semibold text-gray-900 mb-3">
<x-filament::icon icon="heroicon-o-banknotes" class="h-5 w-5 text-emerald-600" />
<span>Voci di spesa per tabella (prop. / inq.)</span>
</div>
@if(empty($ripartizioniPerTabella))
<div class="text-sm text-gray-500">Nessuna ripartizione registrata per questa unità.</div>
@else
<div class="space-y-3">
@foreach($ripartizioniPerTabella as $tabella)
@if(str_starts_with(strtoupper($tabella['tabella_codice'] ?? ''), 'AC')) @continue @endif
<div class="rounded-2xl border bg-gray-50 overflow-hidden">
<div class="flex items-center gap-2 bg-white px-3 py-2 border-b">
<span class="inline-flex items-center rounded-full border border-primary-200 bg-primary-50 px-2 py-0.5 text-xs font-semibold text-primary-700">{{ $tabella['tabella_codice'] }}</span>
<span class="text-sm font-semibold text-gray-900">{{ $tabella['tabella_nome'] }}</span>
</div>
<div class="overflow-x-auto">
<table class="min-w-full text-sm">
<thead>
<tr class="text-gray-500 border-b">
<th class="text-left py-2 px-2">Voce</th>
<th class="text-center py-2 px-2">Gestione</th>
<th class="text-center py-2 px-2">Calcolo</th>
<th class="text-right py-2 px-2">% applicata</th>
<th class="text-right py-2 px-2">Quota finale</th>
<th class="text-right py-2 px-2">% prop</th>
<th class="text-right py-2 px-2">% inquilino</th>
<th class="text-right py-2 px-2">Prop.</th>
<th class="text-right py-2 px-2">Inq.</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach($tabella['righe'] as $r)
<tr>
<td class="py-2 px-2 text-gray-900 font-semibold">{{ $r['voce_codice'] ?? '—' }} {{ $r['voce_descrizione'] ?? '' }}</td>
<td class="py-2 px-2 text-center text-gray-700">{{ $r['tipo_gestione'] ?? '—' }}</td>
<td class="py-2 px-2 text-center text-gray-700">{{ $r['calcolo'] ?? '—' }}</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['percentuale_applicata'] ?? 0, 2, ',', '.') }}%</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['quota_finale'] ?? 0, 4, ',', '.') }}</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format(100.00 - ($r['percentuale_inquilino'] ?? 0), 2, ',', '.') }}%</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['percentuale_inquilino'] ?? 0, 2, ',', '.') }}%</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['importo_proprietario'] ?? 0, 4, ',', '.') }}</td>
<td class="py-2 px-2 text-right text-gray-900">{{ number_format($r['importo_inquilino'] ?? 0, 4, ',', '.') }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endforeach
</div>
@endif
</x-filament::section>
</div>
@endif
</div>
</x-filament::section>
@endif
{{-- Modal Anteprima Documento Protocollo / Comunicazione --}}
@if($showDocModal && $activeDoc)
<div class="fixed inset-0 z-50 overflow-y-auto bg-gray-900/60 backdrop-blur-xs flex items-center justify-center p-4">
<div class="bg-white dark:bg-gray-800 rounded-2xl shadow-2xl border border-gray-200 dark:border-gray-700 w-full max-w-3xl overflow-hidden">
<div class="flex items-center justify-between px-4 py-3 bg-gray-100 dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700">
<div class="font-bold text-sm text-gray-800 dark:text-gray-200 truncate flex items-center gap-2">
<x-heroicon-m-document-text class="w-4 h-4 text-indigo-600" />
<span>{{ $activeDoc['title'] }}</span>
</div>
<button wire:click="closeDocModal" type="button" class="text-gray-400 hover:text-gray-700 dark:hover:text-gray-200">
<x-heroicon-m-x-mark class="w-5 h-5" />
</button>
</div>
<div class="p-4 max-h-[70vh] overflow-y-auto flex items-center justify-center bg-gray-50 dark:bg-gray-950">
@php
$dPath = $activeDoc['path'] ?? null;
$dExists = $activeDoc['exists'] ?? false;
$dType = $activeDoc['content_type'] ?? 'application/pdf';
$isPdf = str_contains($dType, 'pdf') || ($dPath && str_ends_with(strtolower($dPath), '.pdf'));
$isImg = str_starts_with($dType, 'image/') || ($dPath && preg_match('/\.(jpg|jpeg|png|webp|gif)$/i', $dPath));
@endphp
@if(! $dExists && empty($activeDoc['content']))
<div class="text-center text-sm text-amber-600 p-8 space-y-2">
<div class="text-2xl">📁</div>
<div class="font-semibold">Documento non presente nel disco locale</div>
<div class="text-xs text-gray-500 font-mono">{{ $dPath }}</div>
</div>
@elseif($isImg && $dPath && file_exists($dPath))
@php
$b64 = base64_encode(file_get_contents($dPath));
@endphp
<img src="data:image/jpeg;base64,{{ $b64 }}" alt="Documento" class="max-h-[60vh] max-w-full rounded-lg object-contain shadow" />
@elseif($isPdf && $dPath && file_exists($dPath))
@php
$b64 = base64_encode(file_get_contents($dPath));
@endphp
<iframe src="data:application/pdf;base64,{{ $b64 }}" class="w-full h-[60vh] rounded-lg border border-gray-300 dark:border-gray-700"></iframe>
@elseif(!empty($activeDoc['content']))
<div class="p-4 bg-white dark:bg-gray-900 rounded-lg text-xs font-mono text-gray-800 dark:text-gray-200 whitespace-pre-wrap max-h-[50vh] overflow-y-auto w-full">
{{ $activeDoc['content'] }}
</div>
@else
<div class="text-center space-y-3 p-8">
<x-heroicon-o-document class="w-16 h-16 mx-auto text-gray-400" />
<div class="text-sm font-semibold text-gray-800 dark:text-gray-200">{{ $activeDoc['title'] }}</div>
<div class="text-xs text-gray-400">Percorso: {{ $dPath }}</div>
</div>
@endif
</div>
<div class="flex items-center justify-end gap-2 p-3 bg-gray-50 dark:bg-gray-900 border-t border-gray-200 dark:border-gray-700">
<button
wire:click="closeDocModal"
type="button"
class="px-4 py-1.5 text-xs font-semibold text-gray-600 dark:text-gray-300 hover:bg-gray-200 dark:hover:bg-gray-700 rounded-lg transition"
>
Chiudi
</button>
</div>
</div>
</div>
@endif
</div>
</x-filament-panels::page>