@extends('layouts.main') @section('title', $session->name . ' — AI Analysis') @section('container')
{{-- ══ SIDEBAR ════════════════════════════════════════════════ --}}
SESSION STATUS
@php $sc=['upload'=>'s-upload','analyzing'=>'s-analyzing','clarifying'=>'s-clarifying','reviewing'=>'s-reviewing','complete'=>'s-complete','failed'=>'s-failed','cancelled'=>'s-cancelled'][$session->status]??'s-upload'; @endphp {{ ucfirst($session->status) }}
{{ $session->created_at->diffForHumans() }}
{{ $session->name }}
{{-- Live activity indicator --}}
AI is working…
{{-- Stuck warning (shown after 3 min of no new messages) --}}
AI seems stuck
No activity for 3+ minutes.
UPLOADED FILES
@foreach($session->files as $file) @php $tc=['input'=>'#2196f3','output'=>'#4caf50','report'=>'#ff9800'][$file->file_type]??'#666'; @endphp
{{ strtoupper($file->file_type) }}
{{ $file->original_name }}
{{ $file->formattedSize() }}
@if($file->parsed_metadata) @foreach($file->parsed_metadata['sheets']??[] as $sh)
{{ $sh['name'] }}: {{ count($sh['headers']??[]) }} cols • {{ $sh['row_count'] }} rows
@endforeach @endif
@endforeach
@if($session->template) View Saved Template @endif @if(!in_array($session->status,['cancelled','failed','complete']))
@csrf
@endif All Sessions
{{-- ══ CHAT + ACTIONS ══════════════════════════════════════════ --}}
{{-- Header --}}
AI Analysis Chat
{{ $session->messages->count() }} messages
{{-- Flash messages inside chat card --}} @if(session('success')) @endif @if(session('error')) @endif @if($errors->any())
@foreach($errors->all() as $e)
{{ $e }}
@endforeach
@endif {{-- Scrollable messages --}}
@forelse($session->messages as $msg) @include('ai-report-builder.partials.message', ['msg' => $msg]) @empty

AI analysis is starting…

@endforelse
{{-- ── Bottom action area ────────────────────────────── --}}
{{-- Chat input: shown when clarifying OR reviewing (to refine config) --}}
@if($session->status === 'clarifying') AI needs your answer to continue: @else Refine the mapping — tell AI what to fix: @endif
{{-- Test Parser (only in reviewing) --}}
Test parser — upload input file to preview output
{{-- Save Template (only in reviewing, no template yet) --}} @if($session->status === 'reviewing' && !$session->template) @php $scores = $session->analysis_json['confidence_scores'] ?? []; // Support both new value-proven keys and legacy name-mapping keys $thresholds = [ 'grouping_proven' => 95, 'numeric_proven' => 90, 'totals_match' => 90, 'overall' => 90, // Legacy 'header_mapping' => 95, 'product_mapping' => 90, 'book_stock_mapping' => 90, ]; $blocked = []; foreach($thresholds as $k => $min) { if(!array_key_exists($k, $scores)) continue; $v = (int)$scores[$k]; if(!empty($scores) && $v < $min) $blocked[] = ucwords(str_replace('_',' ',$k)) . ": {$v}%<{$min}%"; } $canSave = empty($blocked); @endphp {{-- Confidence score bar --}} @if(!empty($scores))
Confidence: @foreach($scores as $key => $val) @php $label = ucwords(str_replace('_',' ',$key)); $min = $thresholds[$key] ?? 0; $ok = ($min===0 || $val>=$min); @endphp {{ $label }}: {{ $val }}%{{ $min>0?($ok?' ✓':' ✗ need '.$min.'%'):'' }} @endforeach
@endif
@if(!$canSave)
Save blocked — confidence too low: {{ implode(', ', $blocked) }}
Use the chat to refine the AI mapping until all scores meet thresholds.
@endif
Save as Template:
@csrf
@elseif($session->template) @endif
@endsection