@php $kpis = $kpis ?? []; $byProvider = $byProvider ?? []; $daily = $daily ?? []; $byModel = $byModel ?? []; $sourceSplit = $sourceSplit ?? ['admin' => 0, 'workspace' => 0]; $cap = $cap ?? ['used' => 0, 'limit' => null, 'pct' => 0]; $voice = $voice ?? ['voice_rows' => 0, 'calls' => 0]; $window = $window ?? '30d'; $windows = ['7d' => __('7 days'), '30d' => __('30 days'), '90d' => __('90 days'), '1y' => __('1 year')]; $provColor = [ 'openai' => '#10a37f', 'anthropic' => '#d97757', 'gemini' => '#4285f4', 'google' => '#4285f4', 'deepseek' => '#4d6bfe', 'grok' => '#111', 'mistral' => '#fa520f', ]; $maxProv = max(1, collect($byProvider)->max('tokens') ?: 1); $maxDaily = max(1, collect($daily)->max() ?: 1); $totalSplit = max(1, ($sourceSplit['admin'] ?? 0) + ($sourceSplit['workspace'] ?? 0)); @endphp
{{-- Header + window switcher --}}
{{ __('AI · Spend & usage') }}

{{ __('AI') }} {{ __('usage') }}

{{ __('Every AI call your workspace made — tokens burnt, by model and provider, plan keys vs your own keys, and an estimated cost.') }}

@foreach ($windows as $key => $label) {{ $label }} @endforeach
{{-- KPI cards --}}
{{ __('Tokens used') }}
{{ number_format($kpis['tokens'] ?? 0) }}
{{ number_format($kpis['calls'] ?? 0) }} {{ __('AI calls') }}
{{ __('Estimated cost') }}
≈ {!! \App\Support\FormatSettings::currency($kpis['cost'] ?? 0) !!}
{{ __('blended provider rate') }}
{{ __('On plan keys') }}
{{ number_format($kpis['admin_tokens'] ?? 0) }}
{{ __('tokens billed to your plan') }}
{{ __('On your keys (BYOK)') }}
{{ number_format($kpis['byok_tokens'] ?? 0) }}
{{ __('tokens on your own API keys') }}
{{-- Monthly plan cap --}}
{{ __('This month · plan AI cap') }}
{{ __('Manage AI keys →') }}
@if ($cap['limit'] === null)
{{ number_format($cap['used']) }} {{ __('tokens') }} · {{ __('unlimited on your plan') }}
@else
{{ number_format($cap['used']) }} / {{ number_format($cap['limit']) }} {{ __('tokens') }}
{{ $cap['pct'] }}%
@if ($cap['pct'] >= 90)

{{ __('Almost at your monthly cap. Upgrade your plan or add your own keys (BYOK) to keep using AI.') }}

@endif @endif
{{-- Daily trend --}}
{{ __('Daily token burn') }}
@if (collect($daily)->sum() === 0)
{{ __('No AI usage in this window yet.') }}
@else
@foreach ($daily as $date => $val)
@endforeach
@endif
{{-- Plan vs BYOK split --}}
{{ __('Plan keys vs your keys') }}
@php $adminPct = (int) round(($sourceSplit['admin'] ?? 0) / $totalSplit * 100); @endphp
{{ __('Plan keys') }} {{ number_format($sourceSplit['admin'] ?? 0) }}
{{ __('Your keys (BYOK)') }} {{ number_format($sourceSplit['workspace'] ?? 0) }}

{{ __('BYOK tokens run on your own provider account and never count against your plan cap.') }}

{{-- By provider --}}
{{ __('By provider') }}
@if (empty($byProvider))
{{ __('No provider usage yet.') }}
@else
@foreach ($byProvider as $p) @php $c = $provColor[strtolower($p['provider'])] ?? '#128C7E'; @endphp
{{ $p['provider'] }} {{ number_format($p['tokens']) }} {{ __('tok') }} · {{ number_format($p['calls']) }} {{ __('calls') }}
@endforeach
@endif
{{-- By model --}}
{{ __('By model') }}
@if (empty($byModel))
{{ __('No model usage yet.') }}
@else
@foreach ($byModel as $m) @endforeach
{{ __('Model') }} {{ __('Provider') }} {{ __('Prompt') }} {{ __('Completion') }} {{ __('Total') }} {{ __('Calls') }}
{{ $m['model'] }} {{ $m['provider'] ?: '—' }} {{ number_format($m['prompt']) }} {{ number_format($m['completion']) }} {{ number_format($m['tokens']) }} {{ number_format($m['calls']) }}
@endif
{{-- Voice / calls footnote --}} @if (($voice['calls'] ?? 0) > 0 || ($voice['voice_rows'] ?? 0) > 0)
{{ __('Voice & AI calls') }}
{{ number_format($voice['calls'] ?? 0) }} {{ __('AI voice calls in window') }}
{{ number_format($voice['voice_rows'] ?? 0) }} {{ __('voice usage days logged') }}
@endif

{{ __('Cost is an estimate based on published blended per-provider token rates and may differ from your provider invoice. Token counts are exact.') }}