{{--
    Gestione Stabili - Layout Modulare  
    Utilizza il componente layout universale aggiornato
--}}

<x-layout.universal 
    pageTitle="Gestione Stabili"
    showSidebar="true"
    showBreadcrumb="true">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h3 class="card-title mb-0">Lista Stabili</h3>
                    <a href="{{ route('admin.stabili.create') }}" class="btn btn-primary">
                        <i class="fas fa-plus me-1"></i>Nuovo Stabile
                    </a>
                </div>
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead class="table-dark">
                                <tr>
                                    <th>ID</th>
                                    <th>Denominazione</th>
                                    <th>Codice Fiscale</th>
                                    <th>Indirizzo</th>
                                    <th>Città</th>
                                    <th>Stato</th>
                                    <th>Azioni</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($stabili as $stabile)
                                    <tr>
                                        <td>{{ $stabile->id_stabile }}</td>
                                        <td><strong>{{ $stabile->denominazione }}</strong></td>
                                        <td>{{ $stabile->codice_fiscale ?? '-' }}</td>
                                        <td>{{ $stabile->indirizzo }}</td>
                                        <td>{{ $stabile->citta }} ({{ $stabile->provincia }})</td>
                                        <td>
                                            <span class="badge {{ $stabile->stato === 'attivo' ? 'bg-success' : 'bg-danger' }}">
                                                {{ ucfirst($stabile->stato) }}
                                            </span>
                                        </td>
                                        <td>
                                            <div class="btn-group" role="group">
                                                <a href="{{ route('admin.stabili.show', $stabile) }}" class="btn btn-sm btn-outline-info">
                                                    <i class="fas fa-eye"></i> Visualizza
                                                </a>
                                                <a href="{{ route('admin.stabili.edit', $stabile) }}" class="btn btn-sm btn-outline-primary">
                                                    <i class="fas fa-edit"></i> Modifica
                                                </a>
                                                <form method="POST" action="{{ route('admin.stabili.destroy', $stabile) }}" class="d-inline" onsubmit="return confirm('Sei sicuro di voler eliminare questo stabile?')">
                                                    @csrf
                                                    @method('DELETE')
                                                    <button type="submit" class="btn btn-sm btn-outline-danger">
                                                        <i class="fas fa-trash"></i> Elimina
                                                    </button>
                                                </form>
                                            </div>
                                        </td>
                                    </tr>
                                @empty
                                    <tr>
                                        <td colspan="7" class="text-center">
                                            <div class="alert alert-info">
                                                <i class="fas fa-info-circle"></i> Nessuno stabile trovato.
                                            </div>
                                        </td>
                                    </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>

                    <!-- Paginazione -->
                    @if($stabili->hasPages())
                        <div class="d-flex justify-content-center mt-4">
                            {{ $stabili->links() }}
                        </div>
                    @endif
                </div>
            </div>
        </div>
    </div>

</x-layout.universal>