@extends('layouts.app') @section('title', __('My results')) @section('page-title', __('My results')) @section('page-subtitle', __('Read-only view of analyses delivered to you. Filter and export.')) @section('content') @php use App\Models\FileSubmission; $total = method_exists($analyses, 'total') ? $analyses->total() : $analyses->count(); $perPage = method_exists($analyses, 'perPage') ? $analyses->perPage() : 15; $current = method_exists($analyses, 'currentPage') ? $analyses->currentPage() : 1; $rangeFrom = $total ? (($current - 1) * $perPage) + 1 : 0; $rangeTo = min($current * $perPage, $total); $latestDate = optional($analyses->first())->finished_at; $newOnPage = $analyses->filter(fn ($a) => optional($a->submission)->status === FileSubmission::STATUS_SENT)->count(); $f = $filters ?? []; $activeType = $f['type'] ?? ''; $activeFrom = $f['from'] ?? ''; $activeTo = $f['to'] ?? ''; $activeQ = $f['q'] ?? ''; $hasFilter = $activeType || $activeFrom || $activeTo || $activeQ; // URL helper — preserves all current filters and overrides/removes only what's passed. $qs = function (array $overrides = []) use ($f) { $merged = array_merge($f, $overrides); $merged = array_filter($merged, fn ($v) => $v !== null && $v !== ''); return $merged ? '?'.http_build_query($merged) : ''; }; $today = now()->toDateString(); $sevenAgo = now()->subDays(7)->toDateString(); $thirtyAgo = now()->subDays(30)->toDateString(); $monthStart = now()->startOfMonth()->toDateString(); $isLast7 = $activeFrom === $sevenAgo && (! $activeTo || $activeTo === $today); $isLast30 = $activeFrom === $thirtyAgo && (! $activeTo || $activeTo === $today); $isThisMo = $activeFrom === $monthStart && (! $activeTo || $activeTo === $today); $isAllTime = ! $activeFrom && ! $activeTo; $periodLabel = $isLast7 ? __('Last 7 days') : ($isLast30 ? __('Last 30 days') : ($isThisMo ? __('This month') : ($activeFrom || $activeTo ? trim(($activeFrom ? \Illuminate\Support\Carbon::parse($activeFrom)->isoFormat('ll') : '…').' → '.($activeTo ? \Illuminate\Support\Carbon::parse($activeTo)->isoFormat('ll') : '…')) : __('All time')))); $typeIcons = [ 'cashflow' => 'trending-up', 'cash_flow_analysis' => 'trending-up', 'bank_evolution' => 'trending-up', 'balance_sheet_review' => 'chart', 'income_statement_review' => 'receipt', 'profitability_ratios' => 'sparkles', 'liquidity_ratios' => 'droplet', 'solvency_ratios' => 'shield', 'efficiency_ratios' => 'refresh', 'variance_analysis' => 'chart', 'trend_analysis' => 'trending-up', 'common_size' => 'chart', 'dupont_analysis' => 'sparkles', 'altman_z_score' => 'alert', 'beneish_m_score' => 'alert', 'piotroski_f_score' => 'check', 'working_capital' => 'refresh', ]; $iconFor = fn ($k) => $typeIcons[$k] ?? 'chart'; // Smart date: relative for ≤7d, short absolute beyond. $smartDate = fn ($dt) => ! $dt ? '—' : ($dt->gt(now()->subDays(7)) ? $dt->diffForHumans() : $dt->isoFormat('ll')); // Group cards by month for visual rhythm — reads more like a timeline. $grouped = $analyses->getCollection()->groupBy(fn ($a) => optional($a->finished_at)->isoFormat('MMMM YYYY') ?: __('Undated')); // Restrict the type chips to types that this user actually has, and cap // visible chips to the first 5 — the rest live behind a "More" popover. $availableTypes = $availableTypes ?? []; $typeChips = collect($availableTypes)->keys()->take(5)->all(); $typeOverflow = collect($availableTypes)->keys()->slice(5)->all(); @endphp {{-- ╭──────────────────────────────────────────────────────────────────╮ │ HERO ── lightweight banner with live counters │ ╰──────────────────────────────────────────────────────────────────╯ --}}
{{ __('Your deliverables') }}

{{ __(':count analyses available', ['count' => $total]) }}

@if($latestDate) {{ __('Latest delivery :when', ['when' => $latestDate->diffForHumans()]) }} @else {{ __('Once analyses are sent they will appear here.') }} @endif

@if($newOnPage > 0) {{ trans_choice('{1} :count new|[2,*] :count new', $newOnPage, ['count' => $newOnPage]) }} @endif {{ __('Read-only') }}
{{-- ╭──────────────────────────────────────────────────────────────────╮ │ TOOLBAR ── single fluid row: search · type · period │ │ │ │ Type and period are popovers so the toolbar never wraps badly. │ │ All controls submit via GET so the URL is shareable / bookmark- │ │ able. │ ╰──────────────────────────────────────────────────────────────────╯ --}}
{{-- Search ── primary control, takes available width --}}
@if($activeType) @endif @if($activeFrom) @endif @if($activeTo) @endif @if($activeQ) @endif
{{-- Type popover ───────────────────────────────────────────────── Compact button shows the current selection. Clicking opens a panel with: top types as one-click chips, and a select for the long tail of less-used types so the surface stays small. --}}
{{-- Period popover ──────────────────────────────────────────── --}}
@if($hasFilter) @endif
{{-- Results meta strip --}} @if($total > 0)
{{ __('Showing :from–:to of :total', ['from' => $rangeFrom, 'to' => $rangeTo, 'total' => $total]) }}
@endif {{-- ╭──────────────────────────────────────────────────────────────────╮ │ RESULTS ── timeline-style: cards grouped by month │ ╰──────────────────────────────────────────────────────────────────╯ --}} @if($analyses->isEmpty())

{{ $hasFilter ? __('No matches for those filters') : __('No results yet') }}

{{ $hasFilter ? __('Try widening the date range or clearing the search.') : __('Once your analyses are sent they will appear here. You can then open them and export reports.') }}

@if($hasFilter) {{ __('Reset filters') }} @endif
@else
@foreach($grouped as $period => $rows)

{{ $period }}

{{ $rows->count() }}
@foreach($rows as $a) @php $kpiCount = is_array($a->kpis) ? count($a->kpis) : 0; $icon = $iconFor($a->analysis_type); $isNew = optional($a->submission)->status === FileSubmission::STATUS_SENT; @endphp
@if($isNew) {{ __('New') }} @endif {{-- Whole card opens the result --}}

{{ $a->typeLabel() }}

{{ $smartDate($a->finished_at) }}

{{ $a->language }}

{{ $a->submission?->original_filename ?? '—' }}

{{ trans_choice('{0} no KPI|{1} :count KPI|[2,*] :count KPIs', $kpiCount, ['count' => $kpiCount]) }} @if($a->summary) {{ __('Summary') }} @endif
@endforeach
@endforeach
{{ $analyses->links() }}
@endif @endsection