{{-- Header --}}

{{ __('Knowledge Agent Insights') }}

{{ __('See what your AI is answering, where it gets stuck, and which sources are doing the work.') }}

{{-- Empty state shown when the workspace hasn't added any KB content yet. Without this every chart is zero-filled which makes the page look broken on a fresh install. --}} @if(!$this->hasKbContent)

{{ __('No knowledge base content yet') }}

{{ __('Add documents, websites, or Q&A pairs to your knowledge base and your AI will start answering customer questions automatically. Come back here to see how it’s performing.') }}

{{ __('Add knowledge') }}
@endif {{-- Range + channel filters --}}
{{ __('Range') }}: @foreach([7 => '7d', 30 => '30d', 90 => '90d'] as $days => $label) @endforeach @if(count($this->availableChannels) > 0) {{ __('Channel') }}: @foreach($this->availableChannels as $channel) @endforeach @endif
{{-- KPI cards. Deflection rate is the headline number — the one marketing screenshots will lead with. --}}

{{ __('Deflection Rate') }}

{{ $this->stats['deflection_rate'] }}%

{{ $this->stats['answered'] }} {{ __('answered') }} / {{ $this->stats['total'] }} {{ __('total') }}

{{ __('Questions Answered') }}

{{ number_format($this->stats['total']) }}

{{ __('last') }} {{ $rangeDays }}d

{{ __('Avg Confidence') }}

{{ $this->stats['avg_confidence'] }}

{{ __('out of 100') }}

{{ __('Hours Saved') }}

{{ $this->stats['hours_saved'] }}

{{ __('vs human-answered') }}

{{ __('Total AI Cost') }}

${{ number_format($this->stats['total_cost'], 2) }}

${{ number_format($this->stats['avg_cost'], 4) }} / {{ __('answer') }}

{{-- Most-asked questions row. Clustered semantically so 15 phrasings of "what's your refund policy?" surface as one entry with a count of 15 — turning a flat answer log into something the team can actually act on. --}} @if(!empty($this->topAskedQuestions) || !empty($this->clusteredGaps))

{{ __('Most-Asked Questions') }}

{{ __('Topics customers keep asking about — clustered so similar phrasings count as one.') }}

@if(empty($this->topAskedQuestions))

{{ __('No answered questions in this window.') }}

@else
@foreach($this->topAskedQuestions as $cluster)
×{{ $cluster['count'] }}

{{ $cluster['representative'] }}

{{ __('Last asked') }} {{ \Carbon\Carbon::parse($cluster['last_asked'])->diffForHumans() }}

@endforeach
@endif

{{ __('Top Gap Clusters') }}

{{ __('Recurring questions the agent could not answer — fix the biggest one first.') }}

@if(empty($this->clusteredGaps))

{{ __('No recurring gaps — your KB covers what customers ask.') }}

@else
@foreach($this->clusteredGaps as $cluster)
×{{ $cluster['count'] }}

{{ $cluster['representative'] }}

{{ __('Last asked') }} {{ \Carbon\Carbon::parse($cluster['last_asked'])->diffForHumans() }}

{{ __('Fix') }}
@endforeach
@endif
@endif
{{-- Knowledge gaps — left 2/3. These are the most-actionable items on the whole page: questions the agent failed to answer well because nothing in the KB matched. --}}

{{ __('Knowledge Gaps') }}

{{ __('Customer questions your AI could not answer. Each one is a candidate Q&A to add.') }}

{{ $this->stats['fallbacks'] }} {{ __('total') }}
@if($this->knowledgeGaps->isEmpty())

{{ $this->stats['total'] > 0 ? __('No gaps in this window — your AI answered every question with confidence.') : __('No questions logged yet in this window.') }}

@else
@foreach($this->knowledgeGaps as $gap)

{{ $gap->question }}

@if($gap->channel) {{ ucfirst($gap->channel) }} @endif {{ __('Confidence') }}: {{ $gap->confidence }} {{ $gap->created_at->diffForHumans() }}
{{-- "Add to KB" pre-fills a Q&A on the document manager with this question as the Q field. Wired via query string the doc manager already reads. --}} {{ __('Add to KB') }}
@endforeach
@endif
{{-- Top sources — right 1/3. Lets admin see which documents are pulling weight and which are dead. --}}

{{ __('Top Sources') }}

{{ __('Most-cited knowledge base documents.') }}

@if(empty($this->topSources))

{{ __('No citations yet in this window.') }}

@else
@foreach($this->topSources as $source)
@if($source['type'] === 'website') @elseif($source['type'] === 'qa') @else @endif
@if($source['source_url']) {{ $source['title'] }} @else

{{ $source['title'] }}

@endif
{{ $source['citations'] }}
@endforeach
@endif
{{-- Recent answers feed. Admin can mark answers helpful/unhelpful from here as a tuning signal — customer-facing thumbs go in the widget/email channels in Phase 1 and update the same column. --}}

{{ __('Recent Answers') }}

{{ __('A live tail of what your AI has been saying. Mark answers helpful or unhelpful to tune.') }}

@if($this->recentLogs->isEmpty())

{{ __('No replies in this window yet.') }}

@else
@foreach($this->recentLogs as $log)

{{ $log->question }}

{{ $log->answer }}

@if($log->channel) {{ ucfirst($log->channel) }} @endif {{ __('Confidence') }}: {{ $log->confidence }} @if($log->was_fallback) {{ __('Fallback') }} @endif @if(!empty($log->cited_chunk_ids)) {{ count($log->cited_chunk_ids) }} {{ __('sources') }} @endif {{ $log->created_at->diffForHumans() }}
@endforeach
@endif