@extends('layouts.app-universal')

@section('page-title', 'Dashboard Super Admin')

@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-primary 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-crown 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-shield-alt me-1"></i>
                                Super Amministratore
                                <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>
                        <div class="flex-shrink-0">
                            <div class="text-end">
                                <h5 class="mb-0">Sistema NetGesCon</h5>
                                <small class="opacity-75">v{{ $stats['sistema_versione'] }}</small>
                            </div>
                        </div>
                    </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-users-cog text-primary fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Amministratori Totali</h6>
                            <h3 class="mb-0">{{ number_format($stats['amministratori_count']) }}</h3>
                            <small class="text-success">
                                <i class="fas fa-check-circle me-1"></i>
                                {{ $stats['amministratori_attivi'] }} attivi
                            </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-database text-success fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Database Attivi</h6>
                            <h3 class="mb-0">{{ number_format($stats['database_count']) }}</h3>
                            <small class="text-muted">
                                <i class="fas fa-info-circle me-1"></i>
                                Multi-database attivo
                            </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-info bg-opacity-10 rounded-circle d-flex align-items-center justify-content-center">
                                <i class="fas fa-server text-info fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Uptime Sistema</h6>
                            <h5 class="mb-0">{{ $stats['uptime'] }}</h5>
                            <small class="text-success">
                                <i class="fas fa-circle me-1"></i>
                                Sistema operativo
                            </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-code-branch text-warning fa-lg"></i>
                            </div>
                        </div>
                        <div class="flex-grow-1 ms-3">
                            <h6 class="mb-0 text-muted">Versione Sistema</h6>
                            <h5 class="mb-0">{{ $stats['sistema_versione'] }}</h5>
                            <small class="text-muted">
                                <i class="fas fa-calendar me-1"></i>
                                {{ now()->format('Y') }}
                            </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-4 col-md-6">
                            <a href="{{ route('userspace.system.amministratori.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-user-plus fa-2x mb-2"></i>
                                <span>Nuovo Amministratore</span>
                            </a>
                        </div>
                        <div class="col-lg-4 col-md-6">
                            <a href="{{ route('userspace.system.impostazioni.index', $userCode) }}" class="btn btn-outline-secondary w-100 h-100 d-flex flex-column align-items-center justify-content-center py-3">
                                <i class="fas fa-cogs fa-2x mb-2"></i>
                                <span>Impostazioni Sistema</span>
                            </a>
                        </div>
                        <div class="col-lg-4 col-md-6">
                            <a href="{{ route('userspace.system.diagnostica', $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-stethoscope fa-2x mb-2"></i>
                                <span>Diagnostica</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-bell text-warning me-2"></i>
                        Notifiche Sistema
                    </h5>
                </div>
                <div class="card-body">
                    <div class="text-center py-4">
                        <i class="fas fa-check-circle text-success fa-3x mb-3"></i>
                        <p class="text-muted mb-0">Tutti i sistemi funzionano correttamente</p>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Recent Activities -->
    <div class="row">
        <div class="col-12">
            <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-history text-secondary me-2"></i>
                            Attività Recenti
                        </h5>
                        <a href="#" class="btn btn-sm btn-outline-secondary">
                            <i class="fas fa-external-link-alt me-1"></i>
                            Vedi tutte
                        </a>
                    </div>
                </div>
                <div class="card-body">
                    <div class="text-center py-5">
                        <i class="fas fa-clock text-muted fa-3x mb-3"></i>
                        <p class="text-muted mb-0">Nessuna attività recente</p>
                        <small class="text-muted">Le attività del sistema appariranno qui</small>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

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