@extends('layouts.client')

@section('header_title', 'Resumo da Conta')
@section('header_subtitle', 'Bem-vindo de volta! Aqui está o formato atual dos seus serviços.')

@section('content')
    <!-- Alerts/Notifications Area -->
    <div class="mb-8">
        <div class="flex items-start gap-4 p-4 rounded-2xl bg-blue-500/10 border border-blue-500/20">
            <svg class="h-6 w-6 text-blue-400 shrink-0 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
            </svg>
            <div>
                <h4 class="text-white font-medium">Tudo a funcionar corretamente</h4>
                <p class="text-sm text-blue-200 mt-1">Os seus sistemas de segurança estão ativos e a reportar para a central sem quaisquer anomalias. Última verificação há 2 minutos.</p>
            </div>
        </div>
    </div>

    <!-- Main Grid -->
    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 mb-8">
        <!-- Card 1 -->
        <div class="p-6 rounded-3xl bg-slate-900/80 border border-white/5 shadow-xl">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 rounded-2xl bg-indigo-500/10 flex items-center justify-center text-indigo-400">
                    <svg class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4" />
                    </svg>
                </div>
                <span class="px-3 py-1 text-xs font-semibold rounded-full bg-emerald-500/10 text-emerald-400">Ativo</span>
            </div>
            <h3 class="text-sm text-slate-400 font-medium mb-1">Locais Monitorizados</h3>
            <p class="text-3xl font-bold font-heading text-white">{{ count($installations ?? []) }}</p>
        </div>

        <!-- Card 2 -->
        <div class="p-6 rounded-3xl bg-slate-900/80 border border-white/5 shadow-xl">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 rounded-2xl bg-blue-500/10 flex items-center justify-center text-blue-400">
                    <svg class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 10l4.553-2.276A1 1 0 0121 8.618v6.764a1 1 0 01-1.447.894L15 14M5 18h8a2 2 0 002-2V8a2 2 0 00-2-2H5a2 2 0 00-2 2v8a2 2 0 002 2z" />
                    </svg>
                </div>
            </div>
            <h3 class="text-sm text-slate-400 font-medium mb-1">Câmeras Conectadas</h3>
            <p class="text-3xl font-bold font-heading text-white">{{ $camerasCount ?? 0 }}</p>
        </div>

        <!-- Card 3 -->
        <div class="p-6 rounded-3xl bg-slate-900/80 border border-white/5 shadow-xl">
            <div class="flex items-center justify-between mb-4">
                <div class="w-12 h-12 rounded-2xl bg-amber-500/10 flex items-center justify-center text-amber-400">
                    <svg class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
                    </svg>
                </div>
                @if($latestInvoice ?? false)
                    <span class="px-3 py-1 text-xs font-semibold rounded-full bg-slate-800 text-slate-300">Próxima a expirar</span>
                @endif
            </div>
            <h3 class="text-sm text-slate-400 font-medium mb-1">Próximo Pagamento</h3>
            <p class="text-3xl font-bold font-heading text-white">
                @if($latestInvoice ?? false)
                    €{{ number_format($latestInvoice->amount, 2, ',', '.') }}
                @else
                    ---
                @endif
            </p>
            @if($latestInvoice ?? false)
                <p class="text-xs text-slate-500 mt-2">Vence a {{ $latestInvoice->due_date->format('d/m/Y') }}</p>
            @endif
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
        <!-- Locations List -->
        <div>
            <h3 class="text-lg font-bold font-heading text-white mb-4">As Suhas Instalações</h3>
            <div class="space-y-4">
                @forelse($installations ?? [] as $inst)
                <a href="{{ route('client.equipment.index') }}" class="p-5 rounded-2xl bg-slate-900 border border-white/5 flex items-center justify-between group hover:border-slate-700 transition-colors">
                    <div class="flex items-center gap-4">
                        <div class="w-10 h-10 rounded-xl bg-slate-800 flex items-center justify-center text-slate-400 group-hover:text-white group-hover:bg-blue-600 transition-colors">
                            <svg class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" />
                            </svg>
                        </div>
                        <div>
                            <p class="text-white font-medium">{{ $inst->address }}</p>
                            <p class="text-xs text-slate-500">{{ count($inst->cameras) }} câmeras associadas</p>
                        </div>
                    </div>
                    <svg class="w-5 h-5 text-slate-600 group-hover:text-slate-400 transition-colors" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7" />
                    </svg>
                </a>
                @empty
                <div class="p-8 rounded-2xl border border-dashed border-white/10 text-center">
                    <p class="text-slate-500">Ainda não existem instalações ativas associadas à sua conta.</p>
                </div>
                @endforelse
            </div>
        </div>

        <!-- Recent Tickets -->
        <div>
            <div class="flex items-center justify-between mb-4">
                <h3 class="text-lg font-bold font-heading text-white">Últimos Pedidos (Tickets)</h3>
                <a href="{{ route('client.tickets.create') }}" class="text-sm font-medium text-blue-400 hover:text-blue-300 transition-colors">Novo Pedido</a>
            </div>
            <div class="space-y-4">
                @forelse($tickets ?? [] as $ticket)
                <div class="p-5 rounded-2xl bg-slate-900 border border-white/5">
                    <div class="flex justify-between items-start mb-2">
                        <h4 class="text-white font-medium truncate pr-4">{{ $ticket->subject }}</h4>
                        <span class="shrink-0 text-[10px] uppercase font-bold px-2 py-0.5 rounded-full 
                            @if($ticket->status == 'open') bg-amber-500/20 text-amber-400
                            @elseif($ticket->status == 'in_progress') bg-blue-500/20 text-blue-400
                            @else bg-emerald-500/20 text-emerald-400 @endif">
                            {{ $ticket->status }}
                        </span>
                    </div>
                    <p class="text-sm text-slate-400 mb-3 truncate">{{ $ticket->description }}</p>
                    <p class="text-xs text-slate-500">Atualizado há {{ $ticket->updated_at->diffForHumans() }}</p>
                </div>
                @empty
                <div class="p-8 rounded-2xl border border-dashed border-white/10 text-center">
                    <p class="text-slate-500">Não existem pedidos de suporte recentes.</p>
                </div>
                @endforelse
            </div>
        </div>
    </div>
@endsection
