<x-layouts.dashboard title="Client Dashboard">
    @php
        $design = [
            'Active Plan' => ['plans', 'blue', 'Current package'],
            'Total Work Limit' => ['tasks', 'purple', 'Monthly work'],
            'Completed Work' => ['downloads', 'green', 'Delivered files'],
            'Remaining Work' => ['tasks', 'orange', 'Open work'],
            'Pending Requests' => ['requests', 'blue', 'Admin review'],
            'Pending Payments' => ['payments', 'orange', 'Proof review'],
            'Downloads' => ['downloads', 'blue', 'Ready files'],
            'Open Orders' => ['requests', 'blue', 'One-time service jobs'],
        ];
        $oneTimeClient = auth()->user()->client_type === 'one_time';
    @endphp
    <div class="stats role-stats">
        @foreach ($stats as $label => $value)
            @php
                [$icon, $tone, $detail] = $design[$label] ?? ['dashboard', 'blue', 'Portal metric'];
            @endphp
            <article class="stat role-stat"><span class="stat-top"><i class="stat-icon {{ $tone }}"><x-sidebar-icon :name="$icon"/></i></span><small>{{ $label }}</small><strong>{{ $value }}</strong><span class="role-detail">{{ $detail }}</span></article>
        @endforeach
        @if(! $oneTimeClient)
            <article class="stat role-stat"><span class="stat-top"><i class="stat-icon {{ $stats['Pending Payments'] ? 'blue' : 'green' }}"><x-sidebar-icon name="payments"/></i></span><small>Payment Status</small><strong>{{ $stats['Pending Payments'] ? 'Review' : 'Clear' }}</strong><span class="role-detail">Manual approval</span></article>
        @endif
    </div>
    <div class="grid two role-panels">
        @if($oneTimeClient)
            <div class="card role-focus"><header class="table-head"><div><h3>Service Orders</h3><p>One-time project delivery queue</p></div><a class="ghost small" href="{{ route('service.order') }}">New Order</a></header><p class="price">{{ $stats['Open Orders'] ?? 0 }} open orders</p><div class="progress"><i style="width:{{ min((int) (($stats['Completed Work'] ?? 0) * 20), 100) }}%"></i></div><p class="muted">No monthly plan is required for this portal.</p><div class="quick-actions"><a class="btn small" href="{{ route('client.requests') }}">My Orders</a><a class="ghost small" href="{{ route('client.work') }}">My Work</a></div></div>
        @else
            <div class="card role-focus"><header class="table-head"><div><h3>My Plan</h3><p>Usage and delivery balance</p></div><a class="ghost small" href="{{ route('client.plan') }}">Open</a></header><p class="price">{{ $subscription->plan->name ?? 'No active plan' }}</p><div class="progress"><i style="width:{{ min((int) (($subscription->usage_count ?? 0) * 8), 100) }}%"></i></div><p class="muted">Usage: {{ $subscription->usage_count ?? 0 }} work items</p><div class="quick-actions"><a class="btn small" href="{{ route('client.requests') }}">New Request</a><a class="ghost small" href="{{ route('client.payments') }}">Payments</a></div></div>
        @endif
        <div class="table-card"><header class="table-head"><div><h3>Recent Work</h3><p>Status from your delivery queue</p></div><a class="ghost small" href="{{ route('client.work') }}">View All</a></header>@include('partials.task-table', ['tasks' => $tasks])</div>
    </div>
</x-layouts.dashboard>
