@extends('layouts.app-universal')

@section('page-title', 'Dashboard Amministratore')

@section('content')
<div class="container-fluid">
    <!-- User Info Header -->
    <div class="row mb-4">
        <div class="col-12">
            <div class="card border-0 shadow-sm bg-gradient-success text-white">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="avatar-lg bg-white bg-opacity-25 rounded-circle d-flex align-items-center justify-content-center">
                                <i class="fas fa-user-cog fa-2x text-white"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h3 class="mb-1">{{ $user->name }}</h3>
                            <p class="mb-0 opacity-75">
                                <i class="fas fa-building me-1"></i>
                                Amministratore Condominiale
                                <span class="badge bg-white bg-opacity-25 ms-2">{{ $userCode }}</span>
                            </p>
                            <small class="opacity-75">
                                <i class="fas fa-clock me-1"></i>
                                Ultimo accesso: {{ $user->last_login_at ? $user->last_login_at->diffForHumans() : 'Primo accesso' }}
                            </small>
                        </div>
                        @if($amministratore)
                        <div class="flex-shrink-0">
                            <div class="text-end">
                                <h5 class="mb-0">{{ $amministratore->ragione_sociale ?: $amministratore->nome . ' ' . $amministratore->cognome }}</h5>
                                <small class="opacity-75">{{ $amministratore->codice_fiscale ?: $amministratore->partita_iva }}</small>
                            </div>
                        </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Statistics Cards -->
    <div class="row g-3 mb-4">
        <div class="col-xl-3 col-lg-6 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="avatar-md bg-primary bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center">
                                <i class="fas fa-building text-primary fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Stabili Gestiti</h6>
                            <h3 class="mb-0">{{ number_format($stats['stabili_count']) }}</h3>
                            <small class="text-muted">
                                <i class="fas fa-home me-1"></i>
                                {{ $stats['unita_count'] }} unità totali
                            </small>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xl-3 col-lg-6 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="avatar-md bg-warning bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center">
                                <i class="fas fa-ticket-alt text-warning fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Ticket Aperti</h6>
                            <h3 class="mb-0">{{ number_format($stats['tickets_aperti']) }}</h3>
                            <small class="text-warning">
                                <i class="fas fa-exclamation-triangle me-1"></i>
                                Richiede attenzione
                            </small>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xl-3 col-lg-6 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="avatar-md bg-danger bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center">
                                <i class="fas fa-calendar-exclamation text-danger fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Scadenze Prossime</h6>
                            <h3 class="mb-0">{{ number_format($stats['scadenze_prossime']) }}</h3>
                            <small class="text-danger">
                                <i class="fas fa-clock me-1"></i>
                                Entro 7 giorni
                            </small>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-xl-3 col-lg-6 col-md-6">
            <div class="card border-0 shadow-sm h-100">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <div class="flex-shrink-0">
                            <div class="avatar-md bg-success bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center">
                                <i class="fas fa-euro-sign text-success fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Stato Bilanci</h6>
                            <h5 class="mb-0">In regola</h5>
                            <small class="text-success">
                                <i class="fas fa-check-circle me-1"></i>
                                Aggiornati
                            </small>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Quick Actions -->
    <div class="row g-3 mb-4">
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-transparent border-0">
                    <h5 class="mb-0">
                        <i class="fas fa-bolt text-primary me-2"></i>
                        Azioni Rapide
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row g-3">
                        <div class="col-lg-3 col-md-6">
                            <a href="{{ route('userspace.manage.stabili.create', $userCode) }}" class="btn btn-outline-primary w-100 h-100 d-flex flex-column align-items-center justify-content-center py-3">
                                <i class="fas fa-plus-circle fa-2x mb-2"></i>
                                <span>Nuovo Stabile</span>
                            </a>
                        </div>
                        <div class="col-lg-3 col-md-6">
                            <a href="{{ route('userspace.manage.tickets.create', $userCode) }}" class="btn btn-outline-warning w-100 h-100 d-flex flex-column align-items-center justify-content-center py-3">
                                <i class="fas fa-ticket-alt fa-2x mb-2"></i>
                                <span>Nuovo Ticket</span>
                            </a>
                        </div>
                        <div class="col-lg-3 col-md-6">
                            <a href="{{ route('userspace.manage.contabilita.prima-nota', $userCode) }}" class="btn btn-outline-success w-100 h-100 d-flex flex-column align-items-center justify-content-center py-3">
                                <i class="fas fa-calculator fa-2x mb-2"></i>
                                <span>Prima Nota</span>
                            </a>
                        </div>
                        <div class="col-lg-3 col-md-6">
                            <a href="{{ route('userspace.manage.documenti.index', $userCode) }}" class="btn btn-outline-info w-100 h-100 d-flex flex-column align-items-center justify-content-center py-3">
                                <i class="fas fa-file-alt fa-2x mb-2"></i>
                                <span>Documenti</span>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-4">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-transparent border-0">
                    <h5 class="mb-0">
                        <i class="fas fa-calendar-check text-info me-2"></i>
                        Promemoria
                    </h5>
                </div>
                <div class="card-body">
                    <div class="text-center py-4">
                        <i class="fas fa-calendar-day text-muted fa-3x mb-3"></i>
                        <p class="text-muted mb-0">Nessun promemoria</p>
                        <small class="text-muted">per oggi</small>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Management Sections -->
    <div class="row g-3">
        <div class="col-lg-6">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-transparent border-0">
                    <div class="d-flex align-items-center justify-content-between">
                        <h5 class="mb-0">
                            <i class="fas fa-building text-primary me-2"></i>
                            Stabili Recenti
                        </h5>
                        <a href="{{ route('userspace.manage.stabili.index', $userCode) }}" class="btn btn-sm btn-outline-primary">
                            <i class="fas fa-external-link-alt me-1"></i>
                            Vedi tutti
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="text-center py-4">
                        <i class="fas fa-building-circle-exclamation text-muted fa-3x mb-3"></i>
                        <p class="text-muted mb-0">Nessuno stabile aggiunto</p>
                        <a href="{{ route('userspace.manage.stabili.create', $userCode) }}" class="btn btn-sm btn-primary mt-2">
                            <i class="fas fa-plus me-1"></i>
                            Aggiungi il primo stabile
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="col-lg-6">
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-transparent border-0">
                    <div class="d-flex align-items-center justify-content-between">
                        <h5 class="mb-0">
                            <i class="fas fa-ticket-alt text-warning me-2"></i>
                            Ticket Recenti
                        </h5>
                        <a href="{{ route('userspace.manage.tickets.index', $userCode) }}" class="btn btn-sm btn-outline-warning">
                            <i class="fas fa-external-link-alt me-1"></i>
                            Vedi tutti
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="text-center py-4">
                        <i class="fas fa-ticket-simple text-muted fa-3x mb-3"></i>
                        <p class="text-muted mb-0">Nessun ticket aperto</p>
                        <small class="text-muted">Ottimo lavoro!</small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@push('scripts')
<script>
document.addEventListener('DOMContentLoaded', function() {
    // Auto-refresh stats ogni 60 secondi
    setInterval(function() {
        // TODO: Implementare refresh automatico statistiche via AJAX
    }, 60000);
});
</script>
@endpush
