@props([ 'objectiveKey', 'objectiveData', 'usesDailyMetrics' => false, 'usdToTndRate' => 4, ]) @php $isConversion = $objectiveKey === 'conversion'; $label = $isConversion ? 'Couverture' : 'Interaction'; $resultLabel = $isConversion ? 'Couverture' : 'Interactions'; $chartId = 'meta-post-report-chart-'.$objectiveKey; $adsWithMetrics = $objectiveData['ads_with_metrics'] ?? []; $groupedReportAds = collect($adsWithMetrics)->groupBy(fn ($row) => (string) $row['ad']->post_name); $postTotalsByName = collect($objectiveData['by_post'] ?? [])->keyBy('post_name'); $spendColor = '#E83646'; $spendStatClass = 'bg-rose-50 text-rose-700 ring-rose-200'; $theme = $isConversion ? [ 'section' => 'border-emerald-200/80 bg-white', 'accent' => 'bg-emerald-500', 'badge' => 'bg-emerald-100 text-emerald-800', 'header' => 'text-emerald-900', 'pubHeader' => 'bg-emerald-50 text-emerald-900', 'rowOdd' => 'bg-emerald-50/40', 'subtotal' => 'bg-emerald-100/70 text-emerald-950', 'sectionTotal' => 'bg-emerald-600 text-white', 'chartColors' => [$spendColor, '#16a34a'], 'statBg' => 'bg-emerald-50 text-emerald-800 ring-emerald-200', ] : [ 'section' => 'border-violet-200/80 bg-white', 'accent' => 'bg-violet-500', 'badge' => 'bg-violet-100 text-violet-800', 'header' => 'text-violet-900', 'pubHeader' => 'bg-violet-50 text-violet-900', 'rowOdd' => 'bg-violet-50/40', 'subtotal' => 'bg-violet-100/70 text-violet-950', 'sectionTotal' => 'bg-violet-600 text-white', 'chartColors' => [$spendColor, '#7c3aed'], 'statBg' => 'bg-violet-50 text-violet-800 ring-violet-200', ]; @endphp @if ($adsWithMetrics !== [])

{{ $label }}

{{ count($adsWithMetrics) }} ad{{ count($adsWithMetrics) > 1 ? 's' : '' }}
Spend {{ number_format($objectiveData['totals']['spend'], 2, ',', ' ') }} $ · {{ number_format($objectiveData['totals']['spend'] * $usdToTndRate, 2, ',', ' ') }} TND {{ $resultLabel }} {{ number_format($objectiveData['totals']['results'], 0, ',', ' ') }}

Graphique

@foreach ($groupedReportAds as $postName => $postRows) @foreach ($postRows as $index => $reportRow) @php($reportAd = $reportRow['ad']) @php($resultValue = $isConversion ? $reportRow['conversions'] : $reportRow['interactions']) @endforeach @php($postTotals = $postTotalsByName->get($postName)) @php($postResult = $isConversion ? (int) ($postTotals['conversions'] ?? 0) : (int) ($postTotals['interactions'] ?? 0)) @endforeach
Publication / Ad Spend {{ $resultLabel }}
{{ $postName }}

{{ $reportAd->ad_name ?: 'Sans nom' }}

@include('integrations.meta.partials.spend-amount', [ 'amount' => $reportRow['spend'], 'usdToTndRate' => $usdToTndRate, 'class' => 'inline-block text-right', ]) {{ number_format($resultValue, 0, ',', ' ') }}
Sous-total @include('integrations.meta.partials.spend-amount', [ 'amount' => (float) ($postTotals['spend'] ?? 0), 'usdToTndRate' => $usdToTndRate, 'class' => 'inline-block text-right', ]) {{ number_format($postResult, 0, ',', ' ') }}
Total {{ $label }} @include('integrations.meta.partials.spend-amount', [ 'amount' => $objectiveData['totals']['spend'], 'usdToTndRate' => $usdToTndRate, 'class' => 'inline-block text-right', 'tndClass' => 'text-white/80', ]) {{ number_format($objectiveData['totals']['results'], 0, ',', ' ') }}
@endif