{{-- Campaign execution audience snapshot. Renders the IMMUTABLE record of who a campaign resolved to at dispatch — distinct from the live preview count elsewhere on this page, which moves with the data. Four mutually exclusive states: 1. permission withheld → nothing disclosed, stated plainly 2. executed → the full snapshot 3. legacy (pre-snapshot) → historical audience, read-only 4. not executed yet → professional empty state Aggregation comes from NotificationCenterDispatcher::snapshotSummary() (tested); this partial only presents it. No raw JSON, morph class, internal field key or column name is ever printed — audience types are translated and skip reasons are mapped to human labels. Variables: $notification, $snapshotSummary, $skippedRecipients, $canSeeAudienceDetail, $audienceHeader, $usesLegacyAudience --}} @php $hasSnapshot = is_array($snapshotSummary) && ($snapshotSummary['total'] ?? 0) > 0; $header = is_array($audienceHeader) ? $audienceHeader : null; // Morph class → translated audience label. Never print the class itself. $typeLabel = function (string $morphClass): string { $type = \App\Services\Campaigns\CampaignAudienceResolver::audienceTypeFor($morphClass); return $type !== null ? __('admin.campaign_groups.audience.' . $type) : __('admin.notification_center.snapshot.other_recipients'); }; // Skip reasons are stored as stable machine keys; map to sentences, and // fall back to a generic label rather than leaking an unknown key. $skipLabel = function (string $reason): string { $key = 'admin.notification_center.snapshot.skip.' . $reason; return __($key) === $key ? __('admin.notification_center.snapshot.skip.unknown') : __($key); }; @endphp @push('styles') @endpush

{{ __('admin.notification_center.snapshot.title') }}

@if ($hasSnapshot) {{ __('admin.notification_center.snapshot.immutable') }} @elseif ($usesLegacyAudience) {{ __('admin.notification_center.snapshot.legacy') }} @endif
{{-- ── 1. Permission withheld ─────────────────────────────────── --}} @unless ($canSeeAudienceDetail)
{{ __('admin.notification_center.snapshot.forbidden') }}
{{-- ── 2. Executed: the frozen snapshot ───────────────────────── --}} @elseif ($hasSnapshot)

{{ __('admin.notification_center.snapshot.explainer') }}

{{ number_format($snapshotSummary['included']) }}
{{ __('admin.notification_center.snapshot.eligible') }}
@foreach (($snapshotSummary['per_type'] ?? []) as $morphClass => $count)
{{ number_format($count) }}
{{ $typeLabel($morphClass) }}
@endforeach @if (($header['overlap'] ?? 0) > 0)
{{ number_format($header['overlap']) }}
{{ __('admin.notification_center.snapshot.overlap_removed') }}
@endif @if (($snapshotSummary['skipped'] ?? 0) > 0)
{{ number_format($snapshotSummary['skipped']) }}
{{ __('admin.notification_center.snapshot.skipped') }}
@endif
{{-- Preview vs actual: only meaningful when BOTH numbers exist and differ — showing them side by side otherwise is just noise. --}} @if ($header !== null && isset($header['total']) && $notification->audience_count !== null && (int) $header['total'] !== (int) $notification->audience_count)

{{ __('admin.notification_center.snapshot.preview_vs_actual', [ 'preview' => number_format((int) $notification->audience_count), 'actual' => number_format((int) $header['total']), ]) }}

@endif {{-- Selected Campaign Groups, as recorded AT EXECUTION. Read from the header, not the live relation, so a group renamed or archived afterwards still shows what was actually used. --}} @if (! empty($header['groups']))
{{ __('admin.notification_center.snapshot.selected_groups') }}
@foreach ($header['groups'] as $group) @php $stillExists = $notification->campaignGroups ->contains('id', $group['id'] ?? null); @endphp {{ $group['name'] ?: __('admin.notification_center.snapshot.unnamed_group') }} @isset($group['audience_type']) {{ __('admin.campaign_groups.audience.' . $group['audience_type']) }} @endisset @unless ($stillExists) · {{ __('admin.notification_center.snapshot.group_archived') }} @endunless @endforeach
@endif {{-- Skip reasons, grouped with counts --}} @if (! empty($snapshotSummary['skip_reasons']))
@foreach ($snapshotSummary['skip_reasons'] as $reason => $count) @endforeach
{{ __('admin.notification_center.snapshot.skip_reason') }} {{ __('admin.notification_center.snapshot.count') }}
{{ $skipLabel((string) $reason) }} {{ number_format($count) }}
@endif {{-- Exact recipient-level skip decisions. This is deliberately separate from the aggregate above so an operator can answer both "how many?" and "who, and why?". --}} @if (($skippedRecipients ?? collect())->isNotEmpty())
{{ __('admin.notification_center.snapshot.skipped_details') }} {{ __('admin.notification_center.snapshot.skipped_details_hint') }}
@foreach ($skippedRecipients as $detail) @php $snapshot = $detail['snapshot']; $affectedChannels = array_values(array_unique(array_merge( (array) $snapshot->duplicate_channels, (array) $snapshot->eligible_channels, ))); $destinations = (array) $snapshot->masked_destinations; $audienceTranslation = 'admin.notification_center.recipients_table.' . $detail['audience_key']; @endphp @endforeach
{{ __('admin.notification_center.recipients_table.recipient') }} {{ __('admin.notification_center.recipients_table.audience') }} {{ __('admin.notification_center.snapshot.skip_reason') }} {{ __('admin.notification_center.snapshot.affected_channels') }} {{ __('admin.notification_center.snapshot.destination') }}
{{ $detail['name'] }} {{ __($audienceTranslation) === $audienceTranslation ? __('admin.notification_center.snapshot.other_recipients') : __($audienceTranslation) }} {{ $skipLabel((string) $snapshot->skip_reason) }} @forelse ($affectedChannels as $channel) {{ __('admin.notification_center.channels.' . $channel) }} @empty — @endforelse
@forelse ($destinations as $channel => $destination) {{ $channel }}: {{ $destination }} @empty — @endforelse
@if ($skippedRecipients->count() >= 500)

{{ __('admin.notification_center.snapshot.skipped_capped') }}

@endif
@endif {{-- Resolution time + a stable execution reference. The reference is the campaign id + resolution instant, not an internal row id. --}}

@isset($header['resolved_at']) {{ __('admin.notification_center.snapshot.resolved_at', [ 'time' => \Illuminate\Support\Carbon::parse($header['resolved_at'])->format('Y-m-d H:i'), ]) }} · @endisset {{ __('admin.notification_center.snapshot.execution_ref') }} NC-{{ $notification->id }}@isset($header['resolved_at'])/{{ \Illuminate\Support\Carbon::parse($header['resolved_at'])->format('YmdHis') }}@endisset

{{-- ── 3. Legacy campaign, executed before snapshots existed ──── --}} @elseif ($usesLegacyAudience)

{{ __('admin.notification_center.snapshot.legacy_explainer') }}

@foreach ($notification->groups as $group) {{ $group->name }} @endforeach
@if ($notification->audience_count !== null)
{{ number_format($notification->audience_count) }}
{{ __('admin.notification_center.snapshot.recorded_count') }}
@endif {{-- ── 4. Not executed yet ───────────────────────────────────── --}} @else
{{ __('admin.notification_center.snapshot.not_executed') }}

{{ __('admin.notification_center.snapshot.not_executed_hint') }}

@endunless