<x-support-team-layout>
    <x-slot name="header">
        <div class="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
            <div>
                <p class="text-sm font-semibold uppercase tracking-wide text-blue-600 dark:text-blue-300">Support Team</p>
                <h2 class="mt-1 text-2xl font-bold text-slate-950 dark:text-white">Ticket Dashboard</h2>
            </div>
            <a href="{{ route('support-team.tickets.index') }}" class="rounded-lg bg-blue-600 px-4 py-2 text-sm font-semibold text-white transition hover:bg-blue-700 dark:bg-blue-500 dark:hover:bg-blue-400">View Tickets</a>
        </div>
    </x-slot>

    <div class="space-y-8">
        <section class="grid gap-4 sm:grid-cols-2 xl:grid-cols-3">
            @foreach ([
                ['label' => 'Total Tickets', 'value' => $totalTickets, 'color' => 'text-slate-950 dark:text-white'],
                ['label' => 'Open Tickets', 'value' => $openTickets, 'color' => 'text-blue-600 dark:text-blue-400'],
                ['label' => 'Pending Tickets', 'value' => $pendingTickets, 'color' => 'text-amber-600 dark:text-amber-300'],
                ['label' => 'Answered Tickets', 'value' => $answeredTickets, 'color' => 'text-emerald-600 dark:text-emerald-300'],
                ['label' => 'Closed Tickets', 'value' => $closedTickets, 'color' => 'text-slate-600 dark:text-slate-300'],
                ['label' => 'Urgent Tickets', 'value' => $urgentTickets, 'color' => 'text-red-600 dark:text-red-400'],
            ] as $stat)
                <div class="rounded-lg border border-blue-100 bg-white p-5 shadow-sm transition hover:-translate-y-1 hover:shadow-lg dark:border-blue-900/50 dark:bg-slate-900">
                    <p class="text-sm font-medium text-slate-500 dark:text-slate-400">{{ $stat['label'] }}</p>
                    <p class="mt-3 text-3xl font-black {{ $stat['color'] }}">{{ number_format($stat['value']) }}</p>
                </div>
            @endforeach
        </section>

        <section class="rounded-lg border border-blue-100 bg-white shadow-sm dark:border-blue-900/50 dark:bg-slate-900">
            <div class="border-b border-blue-100 p-6 dark:border-blue-900/50">
                <h3 class="text-lg font-bold text-slate-950 dark:text-white">Latest Tickets</h3>
                <p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Newest support conversations that need team attention.</p>
            </div>
            <div class="overflow-x-auto">
                <table class="min-w-full divide-y divide-blue-100 dark:divide-blue-900/50">
                    <thead class="bg-blue-50 dark:bg-blue-950/40">
                        <tr>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase tracking-wide text-blue-700 dark:text-blue-300">Ticket</th>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase tracking-wide text-blue-700 dark:text-blue-300">Priority</th>
                            <th class="px-4 py-3 text-left text-xs font-bold uppercase tracking-wide text-blue-700 dark:text-blue-300">Status</th>
                            <th class="px-4 py-3 text-right text-xs font-bold uppercase tracking-wide text-blue-700 dark:text-blue-300">Action</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-blue-50 bg-white dark:divide-blue-900/40 dark:bg-slate-900">
                        @forelse ($latestTickets as $ticket)
                            <tr>
                                <td class="px-4 py-4">
                                    <p class="text-sm font-semibold text-slate-950 dark:text-white">{{ $ticket->subject }}</p>
                                    <p class="mt-1 text-xs text-slate-500 dark:text-slate-400">{{ $ticket->ticketNumber() }} - {{ $ticket->email }}</p>
                                </td>
                                <td class="px-4 py-4 text-sm font-bold capitalize text-slate-600 dark:text-slate-300">{{ $ticket->priority }}</td>
                                <td class="px-4 py-4 text-sm font-bold capitalize text-blue-600 dark:text-blue-300">{{ $ticket->status }}</td>
                                <td class="px-4 py-4 text-right text-sm">
                                    <a href="{{ route('support-team.tickets.show', $ticket) }}" class="font-semibold text-blue-700 dark:text-blue-300">Open</a>
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td colspan="4" class="px-4 py-10 text-center text-sm text-slate-500 dark:text-slate-400">No tickets yet.</td>
                            </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>
        </section>
    </div>
</x-support-team-layout>
