@extends('layouts.app')

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

@section('content')
<div class="space-y-6">

    <!-- Header -->
    <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4 pb-4 border-b border-slate-200">
        <div>
            <h1 class="text-2xl font-bold text-slate-900 tracking-tight">System Portal Control — Super Admin</h1>
            <p class="text-xs text-slate-500 mt-1">Full system overview, portal management, users, agents, request types, and reporting.</p>
        </div>
        <div class="flex items-center space-x-2">
            <a href="{{ route('admin.users.create') }}" class="px-3 py-2 bg-harcourts-blue text-white text-xs font-bold uppercase tracking-wider rounded hover:bg-blue-800 transition-colors">
                + New User Account
            </a>
            <a href="{{ route('admin.agents.create') }}" class="px-3 py-2 bg-slate-700 text-white text-xs font-bold uppercase tracking-wider rounded hover:bg-slate-800 transition-colors">
                + Add Agent
            </a>
        </div>
    </div>

    <!-- Summary Cards -->
    <div class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4">
        <div class="bg-white p-4 rounded-lg border border-slate-200 shadow-sm">
            <div class="text-[11px] font-bold text-slate-500 uppercase tracking-wider">Total Requests</div>
            <div class="text-2xl font-black text-harcourts-navy mt-1">{{ $counts['total_requests'] }}</div>
        </div>

        <div class="bg-white p-4 rounded-lg border border-slate-200 shadow-sm">
            <div class="text-[11px] font-bold text-slate-500 uppercase tracking-wider">Open Jobs</div>
            <div class="text-2xl font-black text-blue-700 mt-1">{{ $counts['open_requests'] }}</div>
        </div>

        <div class="bg-white p-4 rounded-lg border border-slate-200 shadow-sm">
            <div class="text-[11px] font-bold text-slate-500 uppercase tracking-wider">Total Users</div>
            <div class="text-2xl font-black text-slate-800 mt-1">{{ $counts['users'] }}</div>
        </div>

        <div class="bg-white p-4 rounded-lg border border-slate-200 shadow-sm">
            <div class="text-[11px] font-bold text-slate-500 uppercase tracking-wider">Designers</div>
            <div class="text-2xl font-black text-purple-700 mt-1">{{ $counts['designers'] }}</div>
        </div>

        <div class="bg-white p-4 rounded-lg border border-slate-200 shadow-sm">
            <div class="text-[11px] font-bold text-slate-500 uppercase tracking-wider">Harcourts Admins</div>
            <div class="text-2xl font-black text-emerald-700 mt-1">{{ $counts['admins'] }}</div>
        </div>

        <div class="bg-white p-4 rounded-lg border border-slate-200 shadow-sm">
            <div class="text-[11px] font-bold text-slate-500 uppercase tracking-wider">Overdue Jobs</div>
            <div class="text-2xl font-black text-red-600 mt-1">{{ $counts['overdue'] }}</div>
        </div>
    </div>

    <!-- Quick Navigation Links -->
    <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
        <a href="{{ route('admin.users.index') }}" class="p-4 bg-white rounded-lg border border-slate-200 hover:border-harcourts-blue shadow-sm transition-all group">
            <div class="font-bold text-sm text-slate-900 group-hover:text-harcourts-blue">User Management &rarr;</div>
            <p class="text-xs text-slate-500 mt-1">Manage Harcourts Admins, Designers, passwords and user statuses.</p>
        </a>

        <a href="{{ route('admin.agents.index') }}" class="p-4 bg-white rounded-lg border border-slate-200 hover:border-harcourts-blue shadow-sm transition-all group">
            <div class="font-bold text-sm text-slate-900 group-hover:text-harcourts-blue">Agent Directory &rarr;</div>
            <p class="text-xs text-slate-500 mt-1">Maintain agent directory records for request creation dropdowns.</p>
        </a>

        <a href="{{ route('admin.request-types.index') }}" class="p-4 bg-white rounded-lg border border-slate-200 hover:border-harcourts-blue shadow-sm transition-all group">
            <div class="font-bold text-sm text-slate-900 group-hover:text-harcourts-blue">Request Types &rarr;</div>
            <p class="text-xs text-slate-500 mt-1">Configure marketing request categories and campaign toggles.</p>
        </a>

        <a href="{{ route('reports.index') }}" class="p-4 bg-white rounded-lg border border-slate-200 hover:border-harcourts-blue shadow-sm transition-all group">
            <div class="font-bold text-sm text-slate-900 group-hover:text-harcourts-blue">Internal Reports &rarr;</div>
            <p class="text-xs text-slate-500 mt-1">View revision statistics per admin and designer performance metrics.</p>
        </a>
    </div>

    <!-- Recent System Requests -->
    <div class="bg-white rounded-lg border border-slate-200 shadow-sm overflow-hidden">
        <div class="px-6 py-4 border-b border-slate-200 flex items-center justify-between">
            <h2 class="text-base font-bold text-slate-900">Recent Portal Requests</h2>
            <a href="{{ route('requests.index') }}" class="text-xs text-harcourts-blue font-semibold hover:underline">View All &rarr;</a>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full text-left text-xs text-slate-700">
                <thead class="bg-slate-50 text-slate-500 uppercase tracking-wider font-semibold border-b border-slate-200">
                    <tr>
                        <th class="px-6 py-3">Request ID</th>
                        <th class="px-6 py-3">Type</th>
                        <th class="px-6 py-3">Submitted By</th>
                        <th class="px-6 py-3">Agent</th>
                        <th class="px-6 py-3">Priority</th>
                        <th class="px-6 py-3">Status</th>
                        <th class="px-6 py-3">Designer</th>
                        <th class="px-6 py-3 text-right">Action</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-slate-200">
                    @foreach($recentRequests as $req)
                        <tr class="hover:bg-slate-50 transition-colors">
                            <td class="px-6 py-3.5 font-bold text-harcourts-navy">
                                <a href="{{ route('requests.show', $req->id) }}" class="hover:underline">{{ $req->request_number }}</a>
                            </td>
                            <td class="px-6 py-3.5 font-semibold text-slate-800">{{ $req->requestType->name }}</td>
                            <td class="px-6 py-3.5">{{ $req->submitter ? $req->submitter->name : 'N/A' }}</td>
                            <td class="px-6 py-3.5">{{ $req->agent ? $req->agent->name : 'N/A' }}</td>
                            <td class="px-6 py-3.5 whitespace-nowrap">
                                <x-priority-badge :priority="$req->calculated_priority" :isOverdue="$req->is_overdue" />
                            </td>
                            <td class="px-6 py-3.5 whitespace-nowrap">
                                <x-status-badge :status="$req->status" />
                            </td>
                            <td class="px-6 py-3.5">{{ $req->designer ? $req->designer->name : 'Unassigned' }}</td>
                            <td class="px-6 py-3.5 text-right">
                                <a href="{{ route('requests.show', $req->id) }}" class="px-2.5 py-1 bg-slate-100 hover:bg-slate-200 text-slate-700 font-semibold rounded text-xs">
                                    View
                                </a>
                            </td>
                        </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>

</div>
@endsection
