@extends('admin.layouts.app') @section('title', $notification->title . ' — ' . __('admin.notification_center.title')) @section('page_title', __('admin.notification_center.title')) @php use App\Models\AdminNotification; $statusMeta = [ AdminNotification::STATUS_DRAFT => ['fg' => '#475569', 'bg' => '#f1f5f9'], AdminNotification::STATUS_SENDING => ['fg' => '#9a3412', 'bg' => '#ffedd5'], AdminNotification::STATUS_SENT => ['fg' => '#047857', 'bg' => '#ecfdf5'], AdminNotification::STATUS_PARTIAL => ['fg' => '#92400e', 'bg' => '#fef3c7'], AdminNotification::STATUS_FAILED => ['fg' => '#b91c1c', 'bg' => '#fef2f2'], ]; $sm = $statusMeta[$notification->status] ?? $statusMeta['draft']; @endphp @push('styles') @endpush @section('content') {{ __('admin.notification_center.back') }} @include('admin.partials.flash')
{{-- ── Summary ── --}}

{{ __('admin.notification_center.summary') }}

{{ __('admin.notification_center.status.' . $notification->status) }}
{{ __('admin.notification_center.col.channels') }} @forelse (($notification->channels ?: []) as $c) {{ __('admin.notification_center.channels.' . $c) }} @empty {{ __('admin.notification_center.errors.no_channels') }} @endforelse
{{ __('admin.notification_center.col.audience') }} {{-- null = the viewer may not resolve audiences; a dash beats a fake 0. --}} {{ $audienceTotal === null ? '—' : __('admin.notification_center.recipients_count', ['count' => $audienceTotal]) }}
{{ __('admin.notification_center.groups') }} {{-- Campaign Groups for modern campaigns; the legacy investor-group pivot for pre-Campaign-Groups ones. --}} @forelse ($notification->campaignGroups as $cg) {{ $cg->displayName() }} @empty @foreach ($notification->groups as $g) {{ $g->name }} @endforeach @endforelse
@if ($notification->scheduled_at) @php $schedTz = $notification->timezone ?: 'UTC'; @endphp
{{ __('admin.notification_center.scheduled_for') }} {{ $notification->scheduled_at->copy()->setTimezone($schedTz)->format('Y-m-d H:i') }} ({{ $schedTz }})
@endif @if ($notification->sent_at)
{{ __('admin.notification_center.sent_at') }} {{ $notification->sent_at->format('Y-m-d H:i') }}
@endif
@if (filled($notification->email_subject) || filled($notification->email_body))
{{ __('admin.notification_center.channels.email') }} @if (filled($notification->email_subject))
{{ $notification->email_subject }}
@endif
{!! nl2br(e(strip_tags($notification->email_body ?? ''))) !!}
@endif @if (filled($notification->sms_body))
{{ __('admin.notification_center.channels.sms') }}
{{ $notification->sms_body }}
@endif @if (filled($notification->whatsapp_template_id))
{{ __('admin.notification_center.channels.whatsapp') }}
{{ $notification->whatsapp_template_id }}
{{-- The header image this campaign ships with its template. --}} @if ($mediaUrl = $notification->whatsappHeaderMediaUrl())
{{ __('admin.notification_center.whatsapp_media') }}
@endif @endif
@php $ncSendBtn = ''; // Send confirmations quote the audience size; when the viewer // may not resolve it, ask without inventing a number. $ncSendConfirm = $audienceTotal === null ? __('admin.notification_center.confirm.send_unknown') : __('admin.notification_center.confirm.send', ['count' => $audienceTotal]); $ncSendNowConfirm = $audienceTotal === null ? __('admin.notification_center.confirm.send_unknown') : __('admin.notification_center.confirm.send_now_scheduled', ['count' => $audienceTotal]); @endphp @if ($notification->isDraft())
@csrf @method('DELETE')
{{ __('admin.actions.edit') }}
@csrf
@elseif ($notification->isScheduled()) {{-- Pending scheduled broadcast: editable, cancellable, and can be sent earlier — all reuse the same engine + atomic claim. --}} {{ __('admin.actions.edit') }}
@csrf
@csrf
@csrf
@elseif ($notification->isCancelled()) {{-- Cancelled: read-only; duplicate to send again. --}}
@csrf
@else
@csrf
{{-- SAME Smart-Retry modal + planner + dry-run used by Demo pages (the shared component). Automation-only filters are hidden because a broadcast is a single source targeting investors. --}} @endif
{{-- ── Execution audience snapshot (PLT-CAMPAIGNS-001-C) ── The IMMUTABLE record of who this campaign resolved to at dispatch. Deliberately separate from the live preview count above: that one changes with the data, this one never does. --}} @include('admin.notification-center.partials.audience-snapshot') {{-- ── Delivery stats (only once sent) ── --}} @if ($stats) @php $delivery = $stats['delivery_statuses'] ?? []; @endphp

{{ __('admin.notification_center.delivery') }}

{{ $stats['targeted'] }}
{{ __('admin.notification_center.stats.targeted') }}
{{ $delivery['accepted'] ?? 0 }}
{{ __('admin.notification_center.stats.accepted') }}
{{ $delivery['confirmed_delivered'] ?? 0 }}
{{ __('admin.notification_center.stats.confirmed_delivered') }}
{{ $delivery['read'] ?? 0 }}
{{ __('admin.notification_center.stats.read') }}
{{ $delivery['failed'] ?? 0 }}
{{ __('admin.notification_center.stats.failed') }}
{{ ($delivery['pending'] ?? 0) + ($delivery['not_sent'] ?? 0) }}
{{ __('admin.notification_center.stats.pending') }}
@foreach (($stats['channel_delivery_statuses'] ?? []) as $channel => $counts) @php $total = max(1, $counts['total'] ?? 0); $accepted = $counts['accepted'] ?? 0; $delivered = $counts['delivered'] ?? 0; $read = $counts['read'] ?? 0; $failed = $counts['failed'] ?? 0; $pending = ($counts['pending'] ?? 0) + ($counts['not_sent'] ?? 0); @endphp
{{ __('admin.notification_center.channels.' . $channel) }}
{{ $accepted }} {{ __('admin.notification_center.stats.accepted') }} ✓ {{ $delivered }} {{ __('admin.notification_center.stats.delivered') }} ✓✓ {{ $read }} {{ __('admin.notification_center.stats.read') }} ✕ {{ $failed }} {{ __('admin.notification_center.stats.failed') }} • {{ $pending }} {{ __('admin.notification_center.stats.pending') }}
@endforeach

{{ __('admin.notification_center.stats.hint') }}

@endif {{-- ── Recipients (per-recipient × channel delivery, from the shared log) ── --}} {{-- A dedicated failure list keeps actionable provider errors visible even when hundreds of successful rows were written afterwards. --}} @if (($failedRecipients ?? collect())->isNotEmpty())

{{ __('admin.notification_center.failures.title', ['count' => $failedRecipients->count()]) }}

{{ __('admin.notification_center.failures.hint') }}

@foreach ($failedRecipients as $failure) @php $log = $failure['log']; $response = (array) ($failure['response'] ?? []); $recipient = $log->recipient; $audienceKey = $recipient instanceof \App\Models\CampaignExternalRecipient ? 'crm_' . $recipient->entity_type : ($recipient instanceof \App\Models\Startup ? 'numu_startup' : 'numu_investor'); $failureStatusKey = $log->status === \App\Models\NotificationLog::STATUS_SENT ? 'accepted_' . $log->channel : $log->status; $httpStatus = null; if (preg_match('/^http_(\d{3})$/', (string) $log->error_code, $httpMatch)) { $httpStatus = $httpMatch[1]; } foreach (['http_status', 'status_code', 'status'] as $statusKey) { if ($httpStatus === null && isset($response[$statusKey]) && is_numeric($response[$statusKey])) { $httpStatus = (string) $response[$statusKey]; } } if ($httpStatus === null && preg_match('/HTTP\s+(\d{3})/i', (string) $log->error, $httpMatch)) { $httpStatus = $httpMatch[1]; } @endphp @endforeach
{{ __('admin.notification_center.recipients_table.recipient') }} {{ __('admin.notification_center.recipients_table.audience') }} {{ __('admin.notification_center.recipients_table.channel') }} {{ __('admin.notification_center.recipients_table.status') }} {{ __('admin.notification_center.failures.destination') }} {{ __('admin.notification_center.failures.http_status') }} {{ __('admin.notification_center.failures.error_code') }} {{ __('admin.notification_center.recipients_table.error') }} {{ __('admin.notification_center.failures.provider_response') }} {{ __('admin.notification_center.recipients_table.retries') }}
{{ optional($recipient)->display_name ?: $log->address ?: '—' }} {{ __('admin.notification_center.recipients_table.' . $audienceKey) }} {{ __('admin.notification_center.channels.' . $log->channel) }} {{ __('admin.notification_center.delivery_status.' . $failureStatusKey) }} {{ $log->address ?: '—' }} {{ $httpStatus ?: '—' }} {!! $log->error_code ? ''.e($log->error_code).'' : '—' !!} {{ $log->error ?: __('admin.notification_center.failures.no_reason_recorded') }} @if ($response !== [])
{{ __('admin.notification_center.failures.view_response') }}
{{ json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) }}
@else {{ __('admin.notification_center.failures.no_response') }} @endif
{{ (int) $log->attempt_count }}
@if ($failedRecipients->count() >= 500)
{{ __('admin.notification_center.failures.capped') }}
@endif
@endif @if (! $notification->isDraft()) @php $logStatusMeta = [ 'sent' => ['#047857', '#ecfdf5'], 'delivered' => ['#047857', '#ecfdf5'], 'read' => ['#047857', '#ecfdf5'], 'pending' => ['#475569', '#f1f5f9'], 'failed' => ['#b91c1c', '#fef2f2'], 'undelivered' => ['#b91c1c', '#fef2f2'], 'permanently_failed' => ['#b91c1c', '#fef2f2'], ]; @endphp

{{ __('admin.notification_center.recipients_heading') }}

@if ($recipients->isEmpty())
{{ __('admin.notification_center.recipients_empty') }}
@else
@foreach ($recipients as $log) @php $lm = $logStatusMeta[$log->status] ?? $logStatusMeta['pending']; $recipient = $log->recipient; $audienceKey = $recipient instanceof \App\Models\CampaignExternalRecipient ? 'crm_' . $recipient->entity_type : ($recipient instanceof \App\Models\Startup ? 'numu_startup' : 'numu_investor'); $statusKey = $log->status === \App\Models\NotificationLog::STATUS_SENT ? 'accepted_' . $log->channel : $log->status; @endphp @endforeach
{{ __('admin.notification_center.recipients_table.recipient') }} {{ __('admin.notification_center.recipients_table.audience') }} {{ __('admin.notification_center.recipients_table.channel') }} {{ __('admin.notification_center.recipients_table.status') }} {{ __('admin.notification_center.recipients_table.sent_at') }} {{ __('admin.notification_center.recipients_table.error') }} {{ __('admin.notification_center.recipients_table.retries') }}
{{ optional($recipient)->display_name ?: $log->address ?: '—' }} {{ __('admin.notification_center.recipients_table.' . $audienceKey) }} {{ __('admin.notification_center.channels.' . $log->channel) }} {{ __('admin.notification_center.delivery_status.' . $statusKey) }} {{ $log->sent_at?->format('Y-m-d H:i') ?? '—' }} {{ $log->error ? \Illuminate\Support\Str::limit($log->error, 80) : '—' }} {{ (int) $log->attempt_count }}
@if ($recipients->count() >= 500)
{{ __('admin.notification_center.recipients_capped') }}
@endif @endif
@endif {{-- ── Audience preview (draft) ── --}} @if ($notification->isDraft() && $audiencePreview->isNotEmpty())

{{ __('admin.notification_center.audience_preview') }}

@foreach ($audiencePreview as $inv) {{ $inv->display_name ?? $inv->email }} @endforeach @if ($audienceTotal > $audiencePreview->count()) +{{ $audienceTotal - $audiencePreview->count() }} @endif
@endif
@endsection