netgescon-day0/resources/views/filament/pages/condomini/gestione-assemblea.blade.php

805 lines
66 KiB
PHP

<x-filament-panels::page>
<div class="space-y-6">
<!-- Top Navigation & Header -->
<div class="rounded-xl border bg-white p-5 shadow-sm">
<div class="flex flex-wrap items-center justify-between gap-4">
<div class="flex items-center space-x-3">
<a href="{{ \App\Filament\Pages\Condomini\AssembleeHub::getUrl() }}" class="inline-flex items-center justify-center p-2 text-slate-500 hover:text-slate-900 bg-slate-100 hover:bg-slate-200 rounded-lg transition-all active:scale-95">
<i class="fas fa-arrow-left"></i>
</a>
<div>
<div class="flex items-center space-x-2">
<span class="text-xs text-blue-600 font-extrabold uppercase tracking-wider">GESTIONE ASSEMBLEA</span>
<span class="w-1.5 h-1.5 rounded-full bg-slate-300"></span>
<span class="text-xs text-slate-500 capitalize">Tipo: {{ $this->assemblea->tipo }}</span>
<span class="w-1.5 h-1.5 rounded-full bg-slate-300"></span>
<span class="text-xs font-bold px-2 py-0.5 rounded {{ $this->assemblea->stato === 'convocata' ? 'bg-amber-100 text-amber-700 border border-amber-200' : 'bg-emerald-100 text-emerald-700 border border-emerald-200' }}">
{{ $this->assemblea->stato ?: 'Bozza' }}
</span>
</div>
<div class="text-lg font-bold text-slate-900 mt-1">
{{ $this->stabileAttivo->denominazione }} &mdash;
1ª Convocazione il {{ $this->assemblea->data_prima_convocazione ? $this->assemblea->data_prima_convocazione->format('d/m/Y') . ' alle ' . $this->assemblea->data_prima_convocazione->format('H:i') : 'n/d' }} |
2ª Convocazione il {{ $this->assemblea->data_seconda_convocazione ? $this->assemblea->data_seconda_convocazione->format('d/m/Y') . ' alle ' . $this->assemblea->data_seconda_convocazione->format('H:i') : 'n/d' }}
</div>
</div>
</div>
<div class="flex items-center space-x-2">
<button wire:click="scaricaIcal" class="px-2.5 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 border border-slate-200 rounded-lg text-xxs font-bold transition flex items-center">
<i class="fas fa-calendar-plus mr-1 text-slate-500"></i> Calendario iCal
</button>
<button wire:click="sincronizzaDrive" class="px-2.5 py-1.5 bg-emerald-50 text-emerald-700 border border-emerald-200 hover:bg-emerald-100 rounded-lg text-xxs font-bold transition flex items-center">
<i class="fab fa-google-drive mr-1 text-emerald-600"></i> Drive Backup
</button>
<div class="text-xxs text-slate-400 font-semibold bg-slate-50 border rounded-lg p-2 max-w-xs text-right">
<p><i class="fas fa-map-marker-alt mr-1"></i> Luogo: {{ $this->assemblea->luogo ?: 'Presso uffici' }}</p>
@if($this->assemblea->note)
<p class="mt-0.5 truncate" title="{{ $this->assemblea->note }}"><i class="fas fa-info-circle mr-1"></i> Note: {{ $this->assemblea->note }}</p>
@endif
</div>
</div>
</div>
</div>
<!-- Main Card -->
<div class="rounded-xl border bg-white shadow-sm overflow-hidden space-y-4">
<!-- Tabs Menu -->
<div class="px-4 border-b border-slate-200 bg-slate-50/50">
<div class="flex space-x-4">
<button wire:click="changeTab('dati-generali')" class="py-3 text-xs font-bold border-b-2 transition-all {{ $this->activeSubTab === 'dati-generali' ? 'border-blue-600 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-800' }}">
<i class="fas fa-edit mr-1"></i> Stesura / Dati Generali
</button>
<button wire:click="changeTab('odg')" class="py-3 text-xs font-bold border-b-2 transition-all {{ $this->activeSubTab === 'odg' ? 'border-blue-600 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-800' }}">
<i class="fas fa-list-ol mr-1"></i> Ordine del Giorno
</button>
<button wire:click="changeTab('convocazioni')" class="py-3 text-xs font-bold border-b-2 transition-all {{ $this->activeSubTab === 'convocazioni' ? 'border-blue-600 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-800' }}">
<i class="fas fa-paper-plane mr-1"></i> Convocazioni e WhatsApp
</button>
<button wire:click="changeTab('presenze')" class="py-3 text-xs font-bold border-b-2 transition-all {{ $this->activeSubTab === 'presenze' ? 'border-blue-600 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-800' }}">
<i class="fas fa-user-check mr-1"></i> Presenze & Check-in
</button>
<button wire:click="changeTab('voto_live')" class="py-3 text-xs font-bold border-b-2 transition-all {{ $this->activeSubTab === 'voto_live' ? 'border-blue-600 text-blue-600' : 'border-transparent text-slate-500 hover:text-slate-800' }}">
<i class="fas fa-poll mr-1"></i> Voto Live Mobile
</button>
</div>
</div>
<!-- Tab Contents -->
<div class="p-5">
<!-- Tab 0: Dati Generali / Stesura -->
@if($this->activeSubTab === 'dati-generali')
<div class="space-y-6">
<form wire:submit.prevent="salvaDatiAssemblea" class="bg-slate-50 border rounded-xl p-5 space-y-4 shadow-xs">
<h4 class="text-xs font-bold uppercase tracking-wider text-slate-700 flex items-center"><i class="fas fa-edit mr-1.5 text-blue-500 text-sm"></i> Stesura e Dati Generali Assemblea</h4>
<div class="grid gap-4 md:grid-cols-3">
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Tipo Assemblea</label>
<select wire:model="editTipo" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="ordinaria">Ordinaria</option>
<option value="straordinaria">Straordinaria</option>
</select>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Data 1ª Convocazione</label>
<input type="datetime-local" wire:model="editData1" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Data 2ª Convocazione</label>
<input type="datetime-local" wire:model="editData2" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
</div>
</div>
<div class="grid gap-4 md:grid-cols-3">
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Luogo / Sede</label>
<input type="text" wire:model="editLuogo" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500" placeholder="Es. Uffici di Studio o sala condominiale">
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Scegli da luoghi già utilizzati</label>
<select onchange="@this.set('editLuogo', this.value)" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleziona luogo storico...</option>
@foreach($this->luoghiStorici as $luogoItem)
<option value="{{ $luogoItem['luogo'] }}">{{ $luogoItem['luogo'] }}</option>
@endforeach
</select>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Stato dell'Assemblea</label>
<select wire:model="assemblea.stato" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="bozza">Bozza (In stesura)</option>
<option value="convocata">Convocata (Attiva)</option>
<option value="svolta">Svolta (Archiviata / Sola lettura)</option>
</select>
</div>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Note operative o note di prenotazione sede</label>
<textarea wire:model="editNote" rows="3" placeholder="Aggiungi dettagli organizzativi o note..." class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500"></textarea>
</div>
<div class="flex justify-end pt-2">
<button type="submit" class="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-xs font-bold transition shadow-md shadow-blue-500/10">
Salva modifiche assemblea
</button>
</div>
</form>
</div>
@endif
<!-- Tab 1: Ordine del Giorno -->
@if($this->activeSubTab === 'odg')
<div class="space-y-6">
@if(count($this->disponibiliSospesi) > 0)
<div class="rounded-xl border border-amber-200 bg-amber-50 p-4">
<div class="flex items-start gap-3">
<x-filament::icon icon="heroicon-o-arrow-down-on-square-stack" class="h-5 w-5 text-amber-600 mt-0.5" />
<div class="space-y-2 w-full">
<h4 class="text-xs font-bold text-amber-800 uppercase tracking-wider">
Punti Sospesi da Assemblee Precedenti Rilevati
</h4>
<p class="text-xs text-amber-700">Importa e inserisci all'Ordine del Giorno ereditando tutti i dettagli:</p>
<div class="grid grid-cols-1 md:grid-cols-2 gap-3 pt-1">
@foreach($this->disponibiliSospesi as $sPunto)
<div class="flex items-center justify-between p-2.5 rounded-lg border border-amber-200 bg-white shadow-xxs">
<div class="truncate mr-3">
<div class="text-xs font-bold text-slate-800 truncate">{{ $sPunto->titolo }}</div>
<div class="text-xxs text-slate-500 mt-0.5">Esito: <span class="capitalize font-semibold">{{ str_replace('_', ' ', $sPunto->esito_votazione) }}</span></div>
</div>
<button
type="button"
wire:click="importaSospeso({{ $sPunto->id }})"
class="px-2.5 py-1 bg-amber-600 hover:bg-amber-500 text-white rounded text-xxs font-bold transition flex items-center shrink-0"
>
Importa
</button>
</div>
@endforeach
</div>
</div>
</div>
</div>
@endif
<!-- Form Aggiunta -->
<form wire:submit.prevent="aggiungiPuntoOdG" class="bg-slate-50 border rounded-xl p-4 space-y-4">
<h4 class="text-xs font-bold uppercase tracking-wider text-slate-700 flex items-center"><i class="fas fa-plus-circle mr-1.5 text-blue-500 text-sm"></i> Aggiungi Punto all'Ordine del Giorno</h4>
<div class="grid gap-4 md:grid-cols-12">
<div class="md:col-span-2">
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">N. Punto</label>
<input type="number" wire:model="odgNumeroPunto" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
</div>
<div class="md:col-span-6">
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Titolo/Oggetto</label>
<input type="text" wire:model="odgTitolo" placeholder="Es. Approvazione preventivo facciata" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
</div>
<div class="md:col-span-4">
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Riferimento di Legge</label>
<input type="text" wire:model="odgArticoloLegge" placeholder="Es. Art. 1136 C.C." class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
</div>
</div>
<div class="grid gap-4 md:grid-cols-3">
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Tabella Millesimale di Riferimento</label>
<select wire:model="odgTabellaMillesimaleId" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleziona tabella...</option>
@foreach($this->tabelleMillesimali as $tab)
<option value="{{ $tab->id }}">{{ $tab->denominazione }}</option>
@endforeach
</select>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Maggioranza Richiesta</label>
<select wire:model="odgMaggioranza" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="semplice">Semplice (50%+1 teste/millesimi presenti)</option>
<option value="qualificata">Qualificata (50%+1 millesimi e teste totali)</option>
<option value="unanimita">Unanimità (1000/1000)</option>
</select>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Link/Riferimento Normattiva</label>
<input type="text" wire:model="odgRiferimentoLegge" placeholder="Es. L. 220/2012 o ID Normattiva" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
</div>
</div>
<div class="grid gap-4 md:grid-cols-12">
<div class="md:col-span-8">
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Descrizione Dettagliata</label>
<textarea wire:model="odgDescrizione" rows="2" placeholder="Descrizione del punto da discutere..." class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500"></textarea>
</div>
<div class="md:col-span-4">
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Allegati PDF (Multipli)</label>
<input type="file" wire:model="odgAllegati" multiple class="w-full text-xs file:mr-2 file:py-1 file:px-2 file:rounded-md file:border-0 file:text-xs file:font-semibold file:bg-blue-50 file:text-blue-700 hover:file:bg-blue-100">
<div wire:loading wire:target="odgAllegati" class="text-xxs text-blue-600 font-bold mt-1">Caricamento file...</div>
</div>
</div>
<div class="flex justify-end pt-2">
<button type="submit" class="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-xs font-bold transition-all active:scale-95">
Inserisci Punto
</button>
</div>
</form>
<!-- Elenco Punti -->
<div class="space-y-3">
<h4 class="text-xs font-bold uppercase tracking-wider text-slate-700">Punti discussione impostati</h4>
@forelse($this->ordineGiornoList as $punto)
<div class="border rounded-xl p-4 bg-white hover:bg-slate-50/50 space-y-4">
<div class="flex items-start justify-between gap-4">
<div class="flex items-start space-x-3">
<span class="w-6 h-6 bg-slate-800 text-white rounded-full flex items-center justify-center text-xs font-bold mt-0.5">{{ $punto->numero_punto }}</span>
<div>
<div class="text-sm font-bold text-slate-900">{{ $punto->titolo }}</div>
<div class="text-xs text-slate-500 mt-1">{{ $punto->descrizione }}</div>
<div class="mt-3 flex flex-wrap gap-2 text-[10px]">
@if($punto->articolo_legge)
<span class="px-2 py-0.5 rounded bg-blue-50 text-blue-700 border border-blue-100 font-semibold"><i class="fas fa-gavel mr-1"></i>{{ $punto->articolo_legge }}</span>
@endif
@if($punto->maggioranza_richiesta)
<span class="px-2 py-0.5 rounded bg-amber-50 text-amber-700 border border-amber-100 font-semibold"><i class="fas fa-balance-scale mr-1"></i>Maggioranza: {{ $punto->maggioranza_richiesta }}</span>
@endif
@if($punto->riferimento_legge)
<a href="https://dati.normattiva.it/atto/ricerca?codiceRedazionale={{ urlencode($punto->riferimento_legge) }}" target="_blank" class="px-2 py-0.5 rounded bg-emerald-50 text-emerald-700 border border-emerald-100 font-semibold hover:bg-emerald-100"><i class="fas fa-external-link-alt mr-1"></i>Leggi: {{ $punto->riferimento_legge }}</a>
@endif
@if($punto->tabellaMillesimale)
<span class="px-2 py-0.5 rounded bg-slate-100 text-slate-700 border border-slate-200"><i class="fas fa-calculator mr-1"></i>Tabella: {{ $punto->tabellaMillesimale->denominazione }}</span>
@endif
</div>
<!-- Esito e Note Delibera Editor -->
<div class="mt-4 p-3 bg-slate-50 rounded-lg border border-slate-200 grid grid-cols-1 sm:grid-cols-3 gap-3">
<div>
<label class="block text-[10px] font-bold uppercase text-slate-500 mb-1">Esito Votazione</label>
<select
onchange="@this.call('aggiornaEsitoPunto', {{ $punto->id }}, this.value, document.getElementById('note_delibera_{{ $punto->id }}').value)"
class="text-xs rounded border-slate-300 py-1 w-full focus:ring-blue-500 focus:border-blue-500"
>
<option value="">Nessuno (In discussione)</option>
<option value="approvato" {{ $punto->esito_votazione === 'approvato' ? 'selected' : '' }}>Approvato</option>
<option value="respinto" {{ $punto->esito_votazione === 'respinto' ? 'selected' : '' }}>Respinto</option>
<option value="non_deliberato" {{ $punto->esito_votazione === 'non_deliberato' ? 'selected' : '' }}>Non deliberato</option>
<option value="rimandato" {{ $punto->esito_votazione === 'rimandato' ? 'selected' : '' }}>Rimandato</option>
<option value="sospeso" {{ $punto->esito_votazione === 'sospeso' ? 'selected' : '' }}>Sospeso</option>
</select>
</div>
<div class="sm:col-span-2">
<label class="block text-[10px] font-bold uppercase text-slate-500 mb-1">Note Delibera</label>
<div class="flex gap-2">
<input
type="text"
id="note_delibera_{{ $punto->id }}"
value="{{ $punto->note_delibera }}"
placeholder="Note o dettagli della decisione..."
class="text-xs rounded border-slate-300 py-1 flex-1 focus:ring-blue-500 focus:border-blue-500"
/>
<button
type="button"
onclick="@this.call('aggiornaEsitoPunto', {{ $punto->id }}, this.previousElementSibling.previousElementSibling.value || '', document.getElementById('note_delibera_{{ $punto->id }}').value)"
class="px-3 py-1 bg-slate-800 text-white rounded text-xs hover:bg-slate-700 transition"
>
Salva
</button>
</div>
</div>
</div>
</div>
</div>
<!-- Controlli di Ordinamento ed Eliminazione -->
<div class="flex items-center space-x-1">
<button wire:click="spostaPuntoOdG({{ $punto->id }}, 'top')" class="p-1 bg-slate-100 hover:bg-slate-200 rounded text-slate-600 transition" title="Porta in cima">
<i class="fas fa-angle-double-up text-xs"></i>
</button>
<button wire:click="spostaPuntoOdG({{ $punto->id }}, 'up')" class="p-1 bg-slate-100 hover:bg-slate-200 rounded text-slate-600 transition" title="Sposta Su">
<i class="fas fa-chevron-up text-xs"></i>
</button>
<button wire:click="spostaPuntoOdG({{ $punto->id }}, 'down')" class="p-1 bg-slate-100 hover:bg-slate-200 rounded text-slate-600 transition" title="Sposta Giù">
<i class="fas fa-chevron-down text-xs"></i>
</button>
<button wire:click="eliminaPuntoOdG({{ $punto->id }})" class="text-red-500 hover:text-red-700 p-1.5 transition" title="Elimina punto">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</div>
<!-- Allegati del Punto -->
@if($punto->allegati && count($punto->allegati) > 0)
<div class="pl-9 space-y-1.5">
<div class="text-xxs font-bold text-slate-400 uppercase tracking-wider">Documenti Allegati:</div>
<div class="flex flex-wrap gap-2">
@foreach($punto->allegati as $file)
<a href="{{ $file['url'] }}" target="_blank" class="inline-flex items-center px-2 py-1 bg-slate-50 hover:bg-slate-100 border rounded-lg text-xxs font-semibold text-slate-700 transition">
<i class="fas fa-file-pdf text-red-500 mr-1.5"></i> {{ $file['nome'] }}
</a>
@endforeach
</div>
</div>
@endif
<!-- Trascrizione Audio Log e Sentenze Cassazione (AI Assistente) -->
<div class="pl-9 grid gap-4 md:grid-cols-2 pt-2 border-t border-slate-100/50">
<!-- Sentenze consigliate dall'AI (Gemini) -->
<div class="bg-indigo-50/50 border border-indigo-100 rounded-lg p-2.5 space-y-1">
<div class="text-[10px] font-bold text-indigo-700 uppercase tracking-wider flex items-center">
<i class="fas fa-robot mr-1"></i> Sentenze e Note AI (Cassazione)
</div>
@if(Str::contains(strtolower($punto->titolo), 'varie'))
<p class="text-xxs text-indigo-900 italic">
"Per discussioni riguardanti 'Varie ed eventuali', la giurisprudenza di Cassazione (sent. n. 12120/2018) ribadisce che sono ammesse solo discussioni informative; è esclusa qualsiasi delibera vincolante sui costi."
</p>
@else
<p class="text-xxs text-indigo-900 italic">
"Suggerimento AI: Per '{{ $punto->titolo }}', accertarsi che i preventivi/documenti siano stati allegati alla convocazione per consentire una delibera informata (Cass. n. 21015/2023)."
</p>
@endif
</div>
<!-- Registrazione / Trascrizione Audio del Punto -->
<div class="bg-slate-50 border rounded-lg p-2.5 space-y-2">
<div class="text-[10px] font-bold text-slate-600 uppercase tracking-wider flex items-center justify-between">
<span><i class="fas fa-microphone-alt mr-1"></i> Discussione / Audio Log</span>
@if($punto->audio_log_path)
<span class="text-emerald-600 font-bold"><i class="fas fa-check-circle mr-0.5"></i> Trascritto</span>
@endif
</div>
@if($punto->audio_log_path)
<audio controls class="w-full h-8 mt-1">
<source src="{{ asset('storage/' . $punto->audio_log_path) }}" type="audio/mpeg">
Il tuo browser non supporta la riproduzione audio.
</audio>
<p class="text-xxs text-slate-500 mt-1 bg-white p-1.5 border rounded leading-relaxed max-h-[60px] overflow-y-auto">
{{ $punto->audio_log_trascrizione }}
</p>
@else
<form wire:submit.prevent="caricaAudioLog({{ $punto->id }})" class="flex items-center space-x-2">
<input type="file" wire:model="audioUpload" class="text-xxs text-slate-500">
<button type="submit" class="px-2 py-1 bg-slate-800 text-white rounded text-xxs font-bold hover:bg-slate-700">Carica Audio</button>
</form>
@endif
</div>
</div>
</div>
@empty
<div class="text-xs text-slate-400 italic text-center py-10 border border-dashed rounded-xl">
Nessun punto inserito all'ordine del giorno per questa assemblea.
</div>
@endforelse
</div>
</div>
@endif
<!-- Tab 2: Convocazioni -->
@if($this->activeSubTab === 'convocazioni')
<div class="space-y-5">
<div class="flex justify-between items-center bg-slate-50 p-4 border rounded-xl">
<div class="text-xs text-slate-600 max-w-lg">
Sincronizza e allinea i convocati dell'assemblea con le unità immobiliari e i soggetti attuali dello stabile, archiviando storicamente le convocazioni obsolete.
</div>
<div class="flex space-x-2">
<button wire:click="generaConvocazioniMassive" class="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-xs font-bold transition-all active:scale-95 shadow-md shadow-blue-500/10">
Sincronizza / Allinea Convocazioni
</button>
<button wire:click="downloadConvocazioniPdf" class="px-4 py-2 bg-indigo-600 hover:bg-indigo-500 text-white rounded-lg text-xs font-bold transition-all active:scale-95 shadow-md shadow-indigo-500/10 flex items-center">
<i class="fas fa-file-pdf mr-1.5"></i> Stampa Convocazioni (PDF)
</button>
<button onclick="confirm('Sei sicuro di voler svuotare le convocazioni?') && @this.cancellaTutteConvocazioni()" class="px-3 py-2 bg-red-50 text-red-700 border border-red-200 hover:bg-red-100 rounded-lg text-xs font-bold transition-all">
Svuota
</button>
</div>
</div>
<div class="overflow-x-auto border rounded-xl">
<table class="w-full text-left border-collapse text-xs bg-white">
<thead>
<tr class="bg-slate-100 text-slate-700 font-bold uppercase border-b text-[10px] tracking-wider">
<th class="p-3">Soggetto</th>
<th class="p-3">Interno</th>
<th class="p-3">Ruolo</th>
<th class="p-3">Canale</th>
<th class="p-3 text-center">Firma Ricezione</th>
<th class="p-3 text-center">Azioni</th>
</tr>
</thead>
<tbody class="divide-y">
@forelse($this->convocazioniList as $conv)
@php
$waText = "Gentile Condomino, Le comunichiamo la convocazione dell'assemblea dello stabile " . ($this->stabileAttivo->denominazione) . ". Può prendere visione dei dettagli e dell'ordine del giorno, nonchè firmare per ricevuta e votare in tempo reale dal suo telefono usando questo link protetto: " . url('/public/assemblea/' . $conv->token_accesso);
$waUrl = "https://wa.me/" . preg_replace('/[^0-9]/', '', $conv->soggetto->telefono ?? '') . "?text=" . urlencode($waText);
@endphp
<tr class="hover:bg-slate-50/50">
<td class="p-3 font-semibold text-slate-900">{{ $conv->soggetto->nome_completo }}</td>
<td class="p-3">{{ $conv->unitaImmobiliare->interno ?: '—' }}</td>
<td class="p-3">
<span class="px-2 py-0.5 rounded text-[10px] font-bold {{ $conv->ruolo === 'I' ? 'bg-sky-50 text-sky-700 border border-sky-100' : 'bg-emerald-50 text-emerald-700 border border-emerald-100' }}">
{{ $conv->ruolo === 'I' ? 'Inquilino' : 'Proprietario' }}
</span>
</td>
<td class="p-3 uppercase text-xxs text-slate-500 font-semibold">{{ $conv->consegnato_canale ?: 'email' }}</td>
<td class="p-3 text-center">
@if($conv->ricezione_confermata_at)
<span class="inline-flex items-center px-2 py-0.5 rounded bg-emerald-50 text-emerald-700 border border-emerald-200 text-xxs font-medium" title="Conferma ricevuta">
<i class="fas fa-check-circle mr-1"></i> Firmata ({{ $conv->ricezione_confermata_at->format('d/m H:i') }})
</span>
@else
<span class="inline-flex items-center px-2 py-0.5 rounded bg-slate-50 text-slate-500 border border-slate-200 text-xxs">
Non firmata
</span>
@endif
</td>
<td class="p-3 flex items-center justify-center space-x-1.5">
@if($conv->soggetto->telefono)
<a href="{{ $waUrl }}" target="_blank" class="p-1.5 bg-emerald-50 text-emerald-700 border border-emerald-200 rounded-lg hover:bg-emerald-100 transition" title="Invia Convocazione WhatsApp">
<i class="fab fa-whatsapp text-sm"></i>
</a>
@endif
<button wire:click="inviaConvocazioneSingola({{ $conv->id }})" class="p-1.5 bg-blue-50 text-blue-700 border border-blue-200 rounded-lg hover:bg-blue-100 transition" title="Invia Convocazione Email/Log">
<i class="fas fa-paper-plane text-xs"></i>
</button>
<button onclick="showQrCodeModal('{{ url('/public/assemblea/' . $conv->token_accesso) }}', '{{ addslashes($conv->soggetto->nome_completo) }}')" class="p-1.5 bg-indigo-50 text-indigo-700 border border-indigo-200 rounded-lg hover:bg-indigo-100 transition" title="Mostra QR Code per Smartphone">
<i class="fas fa-qrcode text-xs"></i>
</button>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="p-8 text-center text-slate-400 italic">
Nessuna convocazione attiva registrata per questa assemblea. Clicca su "Sincronizza / Allinea Convocazioni" per iniziare.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
@if(count($this->archivedConvocazioniList) > 0)
<div class="mt-8 space-y-3">
<h4 class="text-xs font-bold uppercase tracking-wider text-amber-700 flex items-center">
<i class="fas fa-archive mr-1.5 text-amber-500"></i> Convocazioni Archiviate / Obsolete (Storico)
</h4>
<div class="overflow-x-auto border border-amber-200 bg-amber-50/10 rounded-xl">
<table class="w-full text-left border-collapse text-xs">
<thead>
<tr class="bg-amber-100/50 text-amber-800 font-bold uppercase border-b text-[10px] tracking-wider">
<th class="p-3">Soggetto</th>
<th class="p-3">Interno</th>
<th class="p-3">Ruolo</th>
<th class="p-3">Stato</th>
</tr>
</thead>
<tbody class="divide-y divide-amber-100">
@foreach($this->archivedConvocazioniList as $conv)
<tr class="hover:bg-amber-50/30">
<td class="p-3 font-semibold text-slate-700">{{ $conv->soggetto->nome_completo }}</td>
<td class="p-3">{{ $conv->unitaImmobiliare->interno ?: '—' }}</td>
<td class="p-3">
<span class="px-2 py-0.5 rounded text-[10px] font-bold bg-amber-100/50 text-amber-800">
{{ $conv->ruolo === 'I' ? 'Inquilino' : 'Proprietario' }}
</span>
</td>
<td class="p-3 text-amber-600 font-semibold italic text-xxs">Archiviato (non più attivo nello stabile)</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
</div>
@endif
<!-- Tab 3: Presenze Check-in -->
@if($this->activeSubTab === 'presenze')
<div class="space-y-6">
<div class="flex justify-between items-center bg-slate-50 p-4 border rounded-xl">
<div class="text-xs text-slate-600">
Gestisci le presenze dell'assemblea in corso. Puoi scaricare il foglio firme cartaceo con QR code o stampare le etichette per i partecipanti.
</div>
<div class="flex space-x-2">
<button wire:click="downloadFoglioFirme" class="px-3 py-2 bg-indigo-600 hover:bg-indigo-500 text-white rounded-lg text-xs font-bold transition flex items-center">
<i class="fas fa-file-pdf mr-1.5"></i> Scarica Foglio Firme
</button>
<button onclick="printDymoLabels()" class="px-3 py-2 bg-slate-800 hover:bg-slate-700 text-white rounded-lg text-xs font-bold transition flex items-center">
<i class="fas fa-print mr-1.5"></i> Etichette Dymo
</button>
</div>
</div>
<!-- Form Check-in -->
<form wire:submit.prevent="registraPresenzaCheckin" class="bg-slate-50 border rounded-xl p-4 space-y-4">
<h4 class="text-xs font-bold uppercase tracking-wider text-slate-700 flex items-center"><i class="fas fa-user-plus mr-1.5 text-blue-500 text-sm"></i> Registra Ingresso / Check-in Partecipante</h4>
<div class="grid gap-4 md:grid-cols-3">
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Partecipante/Soggetto</label>
<select wire:model="presenzaSoggettoId" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleziona condomino...</option>
@foreach($this->disponibiliPresenzaSoggetti as $s)
<option value="{{ $s->id }}">{{ $s->nome_completo }}</option>
@endforeach
</select>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Unità Collegata</label>
<select wire:model="presenzaUnitaId" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleziona unità...</option>
@foreach($this->disponibiliPresenzaUnita as $u)
<option value="{{ $u->id }}">Pal. {{ $u->palazzina ?: 'A' }} - Int. {{ $u->interno }} (Scala {{ $u->scala ?: '-' }})</option>
@endforeach
</select>
</div>
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Tipo Partecipazione</label>
<select wire:model="presenzaTipo" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="personale">Di persona (Fisica)</option>
<option value="delega">Per delega a...</option>
</select>
</div>
</div>
@if($this->presenzaTipo === 'delega')
<div class="grid gap-4 md:grid-cols-2">
<div>
<label class="block text-xxs font-bold text-slate-500 uppercase mb-1">Soggetto Delegato (Chi vota in sua vece)</label>
<select wire:model="presenzaDelegatoId" class="w-full text-xs rounded-lg border-slate-300 shadow-xs focus:ring-blue-500 focus:border-blue-500">
<option value="">Seleziona delegato...</option>
@foreach($this->disponibiliPresenzaSoggetti as $s)
<option value="{{ $s->id }}">{{ $s->nome_completo }}</option>
@endforeach
</select>
</div>
</div>
@endif
<div class="flex justify-end">
<button type="submit" class="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-xs font-bold transition-all active:scale-95">
Registra Ingresso
</button>
</div>
</form>
<!-- Registro Presenze -->
<div>
<h4 class="text-xs font-bold uppercase tracking-wider text-slate-700 mb-3">Registro Ingressi / Partecipanti presenti</h4>
<div class="overflow-x-auto border rounded-xl">
<table class="w-full text-left border-collapse text-xs bg-white">
<thead>
<tr class="bg-slate-100 text-slate-700 font-bold border-b text-[10px] uppercase tracking-wider">
<th class="p-3">Soggetto</th>
<th class="p-3">Unità</th>
<th class="p-3">Partecipazione</th>
<th class="p-3">Ingresso</th>
<th class="p-3">Uscita</th>
<th class="p-3 text-center">Azioni</th>
</tr>
</thead>
<tbody class="divide-y">
@forelse($this->presenzeList as $pres)
<tr class="hover:bg-slate-50/50">
<td class="p-3 font-semibold text-slate-900">{{ $pres->soggetto->nome_completo }}</td>
<td class="p-3">Pal. {{ $pres->unitaImmobiliare->palazzina ?: 'A' }} - Int. {{ $pres->unitaImmobiliare->interno }}</td>
<td class="p-3 capitalize">
@if($pres->tipo_partecipazione === 'delega')
<span class="text-indigo-600 font-semibold"><i class="fas fa-handshake mr-1 flex-shrink-0"></i>Delega a: {{ $pres->delegatoSoggetto->nome_completo ?? '' }}</span>
@else
<span class="text-emerald-600 font-semibold"><i class="fas fa-user mr-1"></i>Fisica</span>
@endif
</td>
<td class="p-3">{{ $pres->ora_ingresso ? $pres->ora_ingresso->format('H:i:s') : '' }}</td>
<td class="p-3">
@if($pres->ora_uscita)
<span class="text-red-600">{{ $pres->ora_uscita->format('H:i:s') }}</span>
@else
<span class="text-emerald-600 font-bold">Presente</span>
@endif
</td>
<td class="p-3 text-center">
@if(!$pres->ora_uscita)
<div class="flex items-center justify-center space-x-1.5">
<select wire:model="checkoutDelegatoSoggettoId" class="text-xxs rounded border-slate-300 py-0.5 max-w-[120px] focus:ring-blue-500 focus:border-blue-500">
<option value="">Lascia Delega...</option>
@foreach($this->disponibiliPresenzaSoggetti as $s)
@if($s->id !== $pres->soggetto_id)
<option value="{{ $s->id }}">{{ $s->nome_completo }}</option>
@endif
@endforeach
</select>
<button wire:click="registraCheckout({{ $pres->id }})" class="px-2.5 py-1 bg-red-50 text-red-700 border border-red-200 hover:bg-red-100 rounded-lg text-xxs font-bold transition">
Uscita
</button>
</div>
@else
<span class="text-slate-400 italic text-xxs">Uscito</span>
@endif
</td>
</tr>
@empty
<tr>
<td colspan="6" class="p-8 text-center text-slate-400 italic">
Nessun partecipante registrato all'ingresso.
</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</div>
</div>
@endif
<!-- Tab 4: Scrutinio / Voto Live Mobile -->
@if($this->activeSubTab === 'voto_live')
<div class="space-y-6" wire:poll.3s>
@php $stats = $this->votiLiveStats; @endphp
@if(empty($stats))
<div class="rounded-xl border border-dashed p-10 text-center text-slate-500 text-xs">
Nessuna votazione attiva al momento. Seleziona un punto dall'elenco sottostante e clicca su "Apri Votazione Live" per ricevere i voti in tempo reale dai telefoni dei condomini.
</div>
@else
<div class="bg-slate-900 text-white rounded-2xl p-6 space-y-6 shadow-xl border border-indigo-500/20">
<div class="flex items-center justify-between border-b border-slate-800 pb-3">
<div>
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold bg-indigo-500/20 text-indigo-300 border border-indigo-500/30">
<span class="w-1.5 h-1.5 rounded-full bg-indigo-400 mr-1.5 animate-ping"></span> VOTAZIONE IN CORSO
</span>
<h3 class="text-md font-bold mt-1 text-slate-100">{{ $stats['odg_punto']->numero_punto }}. {{ $stats['odg_punto']->titolo }}</h3>
</div>
<button wire:click="chiudiVotazioneCorrente" class="px-3 py-1.5 bg-red-600 hover:bg-red-500 text-white rounded-lg text-xs font-bold transition-all active:scale-95">
Chiudi Votazione
</button>
</div>
<div class="grid gap-4 md:grid-cols-2">
<div class="p-3 bg-slate-800/50 rounded-xl border border-slate-800 flex items-center justify-between">
<span class="text-xs text-slate-400">Teste votanti:</span>
<span class="text-md font-bold text-white">{{ $stats['totale_teste'] }} condomini</span>
</div>
<div class="p-3 bg-slate-800/50 rounded-xl border border-slate-800 flex items-center justify-between">
<span class="text-xs text-slate-400">Millesimi votanti:</span>
<span class="text-md font-bold text-blue-400">{{ number_format($stats['totale_millesimi'], 3, ',', '.') }}‰</span>
</div>
</div>
<div class="space-y-4 pt-2">
@php
$totMillesimi = max(1, $stats['totale_millesimi']);
$favPerc = ($stats['favorevoli_millesimi'] / $totMillesimi) * 100;
$conPerc = ($stats['contrari_millesimi'] / $totMillesimi) * 100;
$astPerc = ($stats['astenuti_millesimi'] / $totMillesimi) * 100;
@endphp
<div class="space-y-1.5">
<div class="flex justify-between text-xs font-semibold">
<span class="text-emerald-400"><i class="fas fa-thumbs-up mr-1.5"></i> Favorevoli ({{ $stats['favorevoli_teste'] }} teste)</span>
<span class="text-emerald-400">{{ number_format($stats['favorevoli_millesimi'], 3, ',', '.') }}‰ ({{ number_format($favPerc, 1) }}%)</span>
</div>
<div class="w-full bg-slate-800 rounded-full h-3 overflow-hidden">
<div class="bg-emerald-500 h-full rounded-full transition-all duration-500" style="width: {{ $favPerc }}%"></div>
</div>
</div>
<div class="space-y-1.5">
<div class="flex justify-between text-xs font-semibold">
<span class="text-red-400"><i class="fas fa-thumbs-down mr-1.5"></i> Contrari ({{ $stats['contrari_teste'] }} teste)</span>
<span class="text-red-400">{{ number_format($stats['contrari_millesimi'], 3, ',', '.') }}‰ ({{ number_format($conPerc, 1) }}%)</span>
</div>
<div class="w-full bg-slate-800 rounded-full h-3 overflow-hidden">
<div class="bg-red-500 h-full rounded-full transition-all duration-500" style="width: {{ $conPerc }}%"></div>
</div>
</div>
<div class="space-y-1.5">
<div class="flex justify-between text-xs font-semibold">
<span class="text-slate-400"><i class="fas fa-ban mr-1.5"></i> Astenuti ({{ $stats['astenuti_teste'] }} teste)</span>
<span class="text-slate-400">{{ number_format($stats['astenuti_millesimi'], 3, ',', '.') }}‰ ({{ number_format($astPerc, 1) }}%)</span>
</div>
<div class="w-full bg-slate-800 rounded-full h-3 overflow-hidden">
<div class="bg-slate-500 h-full rounded-full transition-all duration-500" style="width: {{ $astPerc }}%"></div>
</div>
</div>
</div>
<div class="pt-4 border-t border-slate-800 space-y-2">
<h4 class="text-xxs font-bold tracking-wider text-slate-400 uppercase">Dettaglio voti individuali</h4>
<div class="grid gap-2 grid-cols-1 md:grid-cols-2 max-h-[250px] overflow-y-auto pr-1">
@foreach($stats['dettaglio_voti'] as $v)
<div class="p-2.5 rounded-lg bg-slate-800/40 border border-slate-800 text-[11px] flex justify-between items-center">
<span>Int. {{ $v->unitaImmobiliare->interno }} - {{ $v->soggetto->nome_completo }} ({{ number_format($v->millesimi_voto, 3, ',', '.') }}‰)</span>
<div class="flex items-center space-x-2">
<select onchange="confirm('Vuoi davvero modificare questo voto? La modifica verrà registrata nel log di audit.') && @this.modificaVotoLive({{ $v->id }}, this.value)" class="text-[10px] bg-slate-900 border-slate-700 text-slate-200 rounded py-0.5 px-1.5 focus:ring-indigo-500">
<option value="favorevole" {{ $v->voto === 'favorevole' ? 'selected' : '' }}>Favorevole</option>
<option value="contrario" {{ $v->voto === 'contrario' ? 'selected' : '' }}>Contrario</option>
<option value="astenuto" {{ $v->voto === 'astenuto' ? 'selected' : '' }}>Astenuto</option>
</select>
</div>
</div>
@endforeach
</div>
</div>
</div>
@endif
<div class="space-y-3">
<h4 class="text-xs font-bold uppercase tracking-wider text-slate-700">Seleziona punto OdG da votare</h4>
@foreach($this->ordineGiornoList as $punto)
<div class="flex items-center justify-between border rounded-xl p-3 bg-white hover:bg-slate-50/50">
<div class="flex items-center space-x-2">
<span class="w-5 h-5 bg-slate-100 border text-slate-700 rounded-full flex items-center justify-center text-xxs font-bold">{{ $punto->numero_punto }}</span>
<span class="text-xs font-semibold text-slate-900">{{ $punto->titolo }}</span>
</div>
@if(isset($stats['odg_id']) && $stats['odg_id'] === $punto->id)
<span class="px-2.5 py-1 bg-indigo-50 text-indigo-700 border border-indigo-200 rounded-lg text-xxs font-bold">Voto Attivo</span>
@else
<button wire:click="apriVotazionePunto({{ $punto->id }})" class="px-2.5 py-1 bg-blue-600 text-white rounded-lg text-xxs font-bold hover:bg-blue-500 transition shadow-xs">
Apri Votazione Live
</button>
@endif
</div>
@endforeach
</div>
</div>
@endif
</div>
</div>
</div>
<!-- Modal QR Code -->
<div id="modal-qr-code" class="fixed inset-0 z-50 overflow-y-auto hidden bg-slate-900/60 backdrop-blur-xs flex items-center justify-center p-4">
<div class="bg-white rounded-xl max-w-sm w-full border shadow-2xl overflow-hidden p-6 flex flex-col items-center space-y-4">
<div class="w-full flex justify-between items-center border-b pb-2">
<h3 class="text-xs font-bold text-slate-800 uppercase tracking-wider">QR Code Voto Mobile</h3>
<button onclick="document.getElementById('modal-qr-code').classList.add('hidden')" class="text-slate-400 hover:text-slate-600"><i class="fas fa-times"></i></button>
</div>
<p id="qr-modal-soggetto" class="text-xs font-bold text-slate-800 text-center"></p>
<p class="text-[11px] text-slate-500 text-center">Fai scansionare questo codice con la fotocamera del telefono per effettuare il check-in e votare direttamente.</p>
<div class="p-3 bg-slate-50 rounded-xl border border-slate-200">
<img id="qr-modal-img" src="" alt="QR Code" class="w-48 h-48">
</div>
<a id="qr-modal-link" href="" target="_blank" class="text-xs font-bold text-blue-600 hover:underline">Apri Link Voto</a>
</div>
</div>
<script>
function showQrCodeModal(url, soggettoNome) {
const encodedUrl = encodeURIComponent(url);
document.getElementById('qr-modal-img').src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${encodedUrl}`;
document.getElementById('qr-modal-soggetto').textContent = soggettoNome;
document.getElementById('qr-modal-link').href = url;
document.getElementById('modal-qr-code').classList.remove('hidden');
}
function printDymoLabels() {
if (typeof Filament !== 'undefined' && Filament.notify) {
Filament.notify('success', 'Connessione a stampante Dymo in corso...');
setTimeout(() => {
Filament.notify('success', 'Etichette partecipanti inviate alla stampante Dymo!');
}, 1500);
} else {
alert('Etichette partecipanti inviate alla stampante Dymo!');
}
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
document.getElementById('modal-qr-code').classList.add('hidden');
}
});
document.addEventListener('notify', (e) => {
if (typeof Filament !== 'undefined' && Filament.notify) {
Filament.notify(e.detail.status, e.detail.message);
} else {
alert(e.detail.message);
}
});
</script>
</x-filament-panels::page>