@php $formatHours = function (?int $minutes): string { $minutes = max(0, (int) $minutes); $hours = intdiv($minutes, 60); $remainingMinutes = $minutes % 60; return $hours . 'h' . str_pad((string) $remainingMinutes, 2, '0', STR_PAD_LEFT); }; $formatSessionDuration = fn (mixed $minutes): string => $minutes === null ? __('Sans durée') : $formatHours((int) $minutes); $formatActivityDate = fn ($session): string => $session->all_day ? ($session->started_at?->format('d/m') ?? '—') : ($session->started_at?->format('d/m H:i') ?? '—'); $formatNumber = fn (mixed $value): string => rtrim(rtrim(number_format((float) $value, 1, ',', ' '), '0'), ','); $formatMetricValue = function (mixed $value, ?string $unit) use ($formatNumber): string { return trim($formatNumber($value) . ' ' . ($unit ?? '')); }; $typeStatsUrl = fn (mixed $row): string => route('statistics.index', [ 'category_id' => data_get($row, 'category_id'), 'type_id' => data_get($row, 'type_id'), ]); $periods = [ ['label' => trans_choice('ui.common.days', 7, ['count' => 7]), 'stats' => $weekStats], ['label' => trans_choice('ui.common.days', 30, ['count' => 30]), 'stats' => $monthStats], ]; $monthSummary = $monthStats->summary; $bestDay = data_get($monthSummary, 'best_day'); $bestWeek = data_get($monthSummary, 'best_week'); $lastSession = data_get($monthSummary, 'last_session'); $showTypeBreakdown = $showTypeBreakdown ?? true; $historyTitle = $historyTitle ?? __('Historique des sessions'); $emptyHistoryText = $emptyHistoryText ?? __('Aucune session sur cette période.'); $metricPanelId = md5($historyTitle . 'metrics'); $monthMetricCount = collect($monthStats->metricGroups)->sum(fn ($group) => count(data_get($group, 'metrics', []))); $metricChartPairs = collect($monthStats->metricGroups) ->flatMap(function (array $monthGroup) use ($weekStats) { $weekGroup = collect($weekStats->metricGroups)->first(function (array $group) use ($monthGroup): bool { return data_get($group, 'type_key') === data_get($monthGroup, 'type_key'); }); return collect(data_get($monthGroup, 'metrics', []))->map(function (array $monthMetric) use ($monthGroup, $weekGroup): array { $weekMetric = collect(data_get($weekGroup, 'metrics', []))->first(function (array $metric) use ($monthMetric): bool { return data_get($metric, 'name') === data_get($monthMetric, 'name') && data_get($metric, 'unit') === data_get($monthMetric, 'unit'); }); return [ 'type_name' => data_get($monthGroup, 'type_name'), 'metric' => $monthMetric, 'week_points' => data_get($weekMetric, 'points', []), 'month_points' => data_get($monthMetric, 'points', []), ]; }); }) ->values(); @endphp
@foreach ($periods as $period) @php $summary = $period['stats']->summary; @endphp

{{ __('Temps total') }} · {{ $period['label'] }}

{{ $formatHours(data_get($summary, 'total_minutes')) }}

{{ trans_choice('ui.common.active_days', data_get($summary, 'active_day_count', 0), ['count' => data_get($summary, 'active_day_count', 0)]) }}

{{ __('Sessions') }} · {{ $period['label'] }}

{{ data_get($summary, 'session_count', 0) }}

{{ __('ui.common.average_per_session', ['duration' => $formatHours(data_get($summary, 'average_minutes_per_session'))]) }}

{{ __('Régularité') }} · {{ $period['label'] }}

{{ $formatNumber(data_get($summary, 'regularity_rate', 0)) }}%

{{ __('ui.common.average_per_active_day', ['duration' => $formatHours(data_get($summary, 'average_minutes_per_active_day'))]) }}

@endforeach
@if ($showTypeBreakdown) @endif

{{ __('Historique') }}

{{ $historyTitle }}

{{ trans_choice('ui.common.sessions', $monthStats->history->count(), ['count' => $monthStats->history->count()]) }}
@forelse ($monthStats->history as $session) @php $satisfactionScore = $session->satisfaction_score; $satisfactionPercent = $satisfactionScore === null ? '0%' : min(100, max(0, ((int) $satisfactionScore) * 10)) . '%'; @endphp

{{ $session->title ?? $session->activityType?->name ?? $session->activityCategory?->name ?? __('Activité') }}

{{ __('Catégorie') }} · {{ $session->activityCategory?->name ?? __('Sans catégorie') }} {{ __('Type') }} · {{ $session->activityType?->name ?? __('Sans type') }} {{ $formatActivityDate($session) }} @if ($session->is_deepwork) {{ __('Deepwork · x1.5') }} @endif
@if ($session->activitySessionMetrics->isNotEmpty()) @endif

{{ $formatSessionDuration($session->duration_min) }}

{{ $satisfactionScore === null ? '—' : (int) $satisfactionScore }} /10
@empty
{{ $emptyHistoryText }}
@endforelse
@if ($weekStats->hasMetrics() || $monthStats->hasMetrics())

{{ __('Métriques') }}

{{ __('Données spécifiques par type') }}

{{ trans_choice('ui.common.metrics', $monthMetricCount, ['count' => $monthMetricCount]) }}
@foreach ($periods as $periodKey => $period) @php $datasetKey = $periodKey === 0 ? 'week' : 'month'; $metricGroups = collect($period['stats']->metricGroups); @endphp
@forelse ($metricGroups as $metricGroup)

{{ __('Type') }} · {{ $period['label'] }}

{{ data_get($metricGroup, 'type_name') }}

@if (data_get($metricGroup, 'category_id') && data_get($metricGroup, 'type_id')) {{ __('Voir le type') }} @endif
@foreach (data_get($metricGroup, 'metrics', []) as $metric)

{{ data_get($metric, 'label') }}

{{ $formatMetricValue(data_get($metric, 'total'), data_get($metric, 'unit')) }}

{{ __('Meilleure valeur') }} {{ $formatMetricValue(data_get($metric, 'maximum'), data_get($metric, 'unit')) }}

{{ __('Moy.') }} {{ $formatMetricValue(data_get($metric, 'average'), data_get($metric, 'unit')) }} · {{ trans_choice('ui.common.entries', data_get($metric, 'entry_count'), ['count' => data_get($metric, 'entry_count')]) }}

@endforeach
@empty
{{ __('ui.common.no_specific_metric', ['period' => $period['label']]) }}
@endforelse
@endforeach
@if ($metricChartPairs->isNotEmpty())
@foreach ($metricChartPairs as $metricChart) @endforeach
@endif @endif