@php /** @var \App\Models\WaTemplate $template */ $template = $template ?? null; $provider = $provider ?? null; $wabaSubmittable = $wabaSubmittable ?? false; $metaStatus = strtoupper((string) $template->meta_status); $localStatus = (string) $template->status; // Every Meta-side state we have to render. APPROVED + REJECTED are // terminal-ish; PENDING/IN_APPEAL/PENDING_DELETION are transient; // PAUSED/DISABLED/LIMIT_EXCEEDED/FLAGGED block sends. DELETED keeps // the row visible for audit but locks edit/send. $isPending = in_array($metaStatus, ['PENDING', 'IN_APPEAL', 'PENDING_DELETION'], true) // A locally-submitted template whose Meta status hasn't synced back yet // (meta_status still empty) is also "in review" — otherwise the pending // banner + its Refresh button never rendered for a freshly-submitted row. || ($metaStatus === '' && $localStatus === 'pending'); $isApproved = $metaStatus === 'APPROVED'; $isRejected = $metaStatus === 'REJECTED'; $isPaused = $metaStatus === 'PAUSED' || ($template->paused_until && now()->lt($template->paused_until)); $isDisabled = in_array($metaStatus, ['DISABLED', 'LIMIT_EXCEEDED', 'FLAGGED', 'DELETED'], true); $quality = strtoupper((string) ($template->quality_score ?: 'UNKNOWN')); // Whether the template actually exists on Meta. A locally-"pending" row with // NO meta_template_id means the submit FAILED (or never ran) — it isn't // really in review (that's why Status/Template ID show blank), so we show a // "Submit to Meta" recovery banner instead of the misleading "Submitted for // review" one. $onMeta = (bool) $template->meta_template_id; $notSubmitted = !$onMeta && in_array($localStatus, ['pending', 'draft'], true) && !$isApproved && !$isRejected; $statusPillClass = match (true) { $isApproved => 'bg-wa-mint text-wa-deep ring-1 ring-wa-green/30', $isRejected => 'bg-rose-50 text-rose-700 ring-1 ring-rose-200', $isPaused => 'bg-amber-50 text-amber-700 ring-1 ring-amber-200', $isDisabled => 'bg-zinc-100 text-zinc-700 ring-1 ring-zinc-300', $isPending => 'bg-sky-50 text-sky-700 ring-1 ring-sky-200', default => 'bg-paper-50 text-ink-700 ring-1 ring-paper-200', }; $statusLabel = match ($metaStatus) { 'APPROVED' => 'Approved', 'REJECTED' => 'Rejected', 'PENDING' => 'In review', 'IN_APPEAL' => 'In appeal', 'PENDING_DELETION' => 'Deleting', 'DELETED' => 'Deleted', 'DISABLED' => 'Disabled', 'LIMIT_EXCEEDED' => 'Limit exceeded', 'FLAGGED' => 'Flagged', 'PAUSED' => 'Paused', default => $isPaused ? 'Paused' : ucfirst(strtolower($metaStatus ?: $localStatus ?: 'Draft')), }; // A locally-pending row that never reached Meta reads as "Not submitted" // (amber), not a spinning "Pending" — the pill must not imply active review. if ($notSubmitted) { $statusLabel = 'Not submitted'; $statusPillClass = 'bg-amber-50 text-amber-700 ring-1 ring-amber-200'; } $qualityPillClass = match ($quality) { 'GREEN' => 'bg-wa-mint text-wa-deep ring-1 ring-wa-green/30', 'YELLOW' => 'bg-amber-50 text-amber-700 ring-1 ring-amber-200', 'RED' => 'bg-rose-50 text-rose-700 ring-1 ring-rose-200', default => 'bg-paper-50 text-ink-500 ring-1 ring-paper-200', }; $rejectionFriendly = match ($template->rejection_reason_code) { 'ABUSIVE_CONTENT' => 'Content was flagged as abusive or threatening.', 'INVALID_FORMAT' => 'Format violates Meta\'s template rules (placeholders, line breaks, length).', 'PROMOTIONAL' => 'Marketing language not allowed in this category.', 'TAG_CONTENT_MISMATCH' => 'Category does not match the content (e.g. promotional copy in a UTILITY template).', 'SCAM' => 'Meta flagged the template as a potential scam — review claims and language.', 'NONE' => null, default => $template->rejection_reason ?: null, }; $lintWarnings = (array) session('lint_warnings', []); // Channel drives the accent + which side-cards make sense: an Instagram // template is local (synced to Instaflow) and never touches Meta, so the // Meta-sync / WABA cards are swapped for an Instagram card. $isInstagram = ($template->channel ?? '') === 'instagram' || (method_exists($template, 'engineKey') && $template->engineKey() === 'instagram'); @endphp
{{-- =============== LEFT RAIL =============== --}} {{-- =============== MAIN =============== --}}
{{-- Page header (SLA-style: breadcrumb + big title + actions) --}}
{{ __('Templates') }} / {{ __('Detail') }}

{{ $template->template_name }}

{{ $isInstagram ? 'INSTAGRAM' : strtoupper($template->meta_category ?: $template->category) }} · {{ $template->language ?: 'en_US' }} · {{ ucfirst($template->template_type ?: 'standard') }}

@unless ($isInstagram) @endunless {{ __('Edit') }}
{{-- ============================================================ --}} {{-- BANNERS ----------------------------------------------------- --}} {{-- ============================================================ --}} {{-- Meta submission error — set by store()/submit via withErrors('meta'). Shows the REAL reason (lint failure, Meta rejection, no WABA) that the template never got a Template ID. --}} @if ($errors->has('meta'))
{{ __('Meta submission failed') }}
{{ $errors->first('meta') }}
@endif {{-- Not on Meta yet — the initial submit failed, so there's no meta_template_id and the row can't be reviewed or sent. Offer a one-click resubmit (POST templates.submit → submitToMetaAction). --}} @if ($notSubmitted && $wabaSubmittable)
{{ __('Not submitted to Meta yet') }}
{{ __('This template is saved locally but has no Meta Template ID — Meta never accepted it, which is why the status shows blank and it can’t be reviewed or sent. Submit it now to start the review.') }}
{{-- Multi-WABA: when >1 WhatsApp Business account is connected, let the operator pick WHICH one to (re)submit this template on. The media header/carousel upload + the Meta submit both use it (submitToMeta → resolveTemplateConfig reads this provider_config_id first). Pre-selects the template's remembered WABA. Hidden with 0/1 WABA (uses primary). --}}
@csrf @if (($wabaConfigs ?? collect())->count() > 1) @endif
@elseif ($notSubmitted) {{-- No WABA connected → can't submit; point them to connect one. --}}
{{ __('Not submitted to Meta yet') }}
{{ __('This template has no Meta Template ID. Connect a WhatsApp Business (WABA) account, then submit it for review.') }}
@endif @if ($isPending && $onMeta)
{{ __('Submitted for Meta review') }}
{{ __('Most templates are approved within minutes — Meta allows up to 48 hours. This page refreshes automatically every 30 seconds while the status is pending.') }}
@if ($template->submitted_at)
Submitted {{ $template->submitted_at->diffForHumans() }} @if ($template->last_synced_at) · last checked {{ $template->last_synced_at->diffForHumans() }} @endif
@endif
@endif @if ($isRejected)
{{ __('Rejected by Meta') }}
@if ($rejectionFriendly)
{{ $rejectionFriendly }}
@endif @if ($template->rejection_reason_code)
Code: {{ $template->rejection_reason_code }}
@endif
Edit & resubmit
@endif @if ($isPaused)
{{ __('Paused by Meta') }}
Repeated negative feedback (blocks/spam reports) paused this template. Quality score must recover before it can be sent again. @if ($template->paused_until) Auto-unpause after {{ $template->paused_until->format('M j, H:i') }}. @endif
@endif @foreach ($lintWarnings as $warning)
{{ $warning }}
@endforeach {{-- Preview card --}}

{{ __('Preview') }}

{{ $isInstagram ? __('How it appears on Instagram') : __('How it appears on WhatsApp') }}
@php // WhatsApp-style formatting — same as the list cards: // *bold* _italic_ ~strike~ and {{variable}} pills. Escape first. $fmt = e((string) $template->template_body); $fmt = preg_replace('/\*(.+?)\*/s', '$1', $fmt); $fmt = preg_replace('/_(.+?)_/s', '$1', $fmt); $fmt = preg_replace('/~(.+?)~/s', '$1', $fmt); $fmt = preg_replace('/\{\{\s*([^{}]+?)\s*\}\}/', '{{$1}}', $fmt); $fmt = nl2br($fmt); $att = strtolower((string) $template->attachment_type); $hasMedia = in_array($att, ['image', 'video', 'document', 'media', 'location'], true); @endphp {{-- Received-message bubble (tail on the top-left, like an inbound WA msg) --}}
@if ($hasMedia) {{-- Prefer an uploaded header image; else fall back to Meta's OWN approved sample captured at sync (header_sample_url) — the exact image this template was approved with, and the one the send uploads to /media. Without this fallback the preview showed the grey placeholder even when we DID hold an image. --}} @php $previewImg = $att === 'image' ? ($template->attachment_file ? media_url($template->attachment_file) : ($template->header_sample_url ?: null)) : null; @endphp @if ($previewImg) {{ __('header media') }} @else
@if ($att === 'video') @elseif ($att === 'document') @elseif ($att === 'location') @else @endif
@endif @endif @if ($template->header && !$hasMedia)
{{ $template->header }}
@endif
{!! $fmt !== '' ? $fmt : '' . e(__('No body text')) . '' !!}
@if ($template->footer)
{{ $template->footer }}
@endif
10:30
@if (is_array($template->buttons) && count($template->buttons)) {{-- Interactive buttons render as tappable rows BELOW the bubble --}}
@foreach ($template->buttons as $btn)
@if (($btn['type'] ?? '') === 'URL' || !empty($btn['url'])) @elseif (($btn['type'] ?? '') === 'PHONE_NUMBER' || !empty($btn['phone_number'])) @elseif (strtolower($btn['type'] ?? '') === 'catalog') @else @endif {{ $btn['text'] ?? __('Button') }}
@endforeach
@endif @if ($template->template_type === 'carousel' && is_array($template->carousel_data) && count($template->carousel_data))
@foreach ($template->carousel_data as $card)
@if (!empty($card['image'])) {{-- A synced card image is Meta's own CDN URL (absolute https) — use it as-is; only a locally uploaded file goes through the storage path. --}} @endif
{{ $card['body'] ?? '' }}
@if (!empty($card['buttons']))
@foreach ($card['buttons'] as $b)
{{ $b['text'] ?? '' }}
@endforeach
@endif
@endforeach
@endif
{{-- Components breakdown --}}

{{ __('Components') }}

@if ($template->header)
{{ __('Header') }}
{{ $template->header }}
@endif
{{ __('Body') }}
{{ $template->template_body }}
@if ($template->footer)
{{ __('Footer') }}
{{ $template->footer }}
@endif @if (is_array($template->buttons) && count($template->buttons))
{{ __('Buttons') }}
@foreach ($template->buttons as $btn)
{{ $btn['type'] ?? 'quick_reply' }} {{ $btn['text'] ?? '' }} @if (!empty($btn['value'])) → {{ $btn['value'] }} @endif
@endforeach
@endif