{{-- Instagram templates are local reusable DMs — no Meta category/language,
no header/footer, and no "submit for review". When the channel is
Instagram (chosen on the New-template modal) we hide those Meta-only
sections so the form shows only what Instagram actually supports:
name, body, media, and buttons. --}}
@php
$isIg = ($defaultChannel ?? '') === 'instagram';
// Facebook mirrors Instagram: a LOCAL reusable Messenger DM (no Meta
// approval). Both hide the Meta-only category/language/header/attachment/
// footer sections and swap the submit label + preview chrome for the DM
// look — $isLocalDm gates everything the two channels share.
$isFb = ($defaultChannel ?? '') === 'facebook';
// Telegram mirrors Instagram/Facebook: a LOCAL reusable bot message (no
// Meta approval). Same hidden Meta-only sections + DM chrome.
$isTg = ($defaultChannel ?? '') === 'telegram';
$isLocalDm = $isIg || $isFb || $isTg;
// Catalog templates are WhatsApp Cloud API (Meta official) ONLY. When the
// format chooser opened this page with ?type=catalog we lock the whole
// form to WABA — the send-channel picker below is filtered to WABA so the
// only sender/device the form can resolve is a WhatsApp Business number.
$isCatalog = request()->query('type') === 'catalog';
$catalogHasWaba = in_array('waba', $channels ?? [], true);
// Built here (raw PHP) rather than inline in the textarea's Blade echo —
// a literal {{name}} inside a {{ }} echo makes the Blade compiler choke
// ("Unclosed '(' does not match '}'").
$bodyPlaceholder = $isTg
? __('Type your Telegram bot message. Press / to insert a variable like {{name}}.')
: ($isFb
? __('Type your Messenger DM. Press / to insert a variable like {{name}}.')
: ($isIg
? __('Type your Instagram DM. Press / to insert a variable like {{name}}.')
: 'Type your message. Press / to insert a variable. Meta requires positional placeholders like {{1}} {{2}}.'));
// Pre-built template prefill. $prefill is the admin blueprint (WaTemplate,
// is_prebuilt) when the operator arrived via "Use this template"
// (?from_prebuilt=…). Everything below falls back to old() first so a
// validation round-trip still wins, then the blueprint, then the default.
$prefill = $prefill ?? null;
$pfId = $prefill->id ?? null;
$pfMetaCat = strtolower((string) old('meta_category', $prefill->meta_category ?? ($prefill->category ?? 'utility')));
if (!in_array($pfMetaCat, ['marketing', 'utility', 'authentication'], true)) { $pfMetaCat = 'utility'; }
$pfAttach = (string) old('attachment_type', $prefill->attachment_type ?? 'none');
// Blueprint buttons → the create form's button rows. Blueprint stores
// {type: quick_reply|url|phone_number}; the form uses visit_website /
// call_phone / quick_reply (copy_code unused by blueprints).
$pfButtons = [];
if ($prefill && is_array($prefill->buttons)) {
$btnMap = ['url' => 'visit_website', 'phone_number' => 'call_phone', 'quick_reply' => 'quick_reply'];
foreach ($prefill->buttons as $b) {
$ft = $btnMap[$b['type'] ?? ''] ?? null;
if (!$ft) continue;
$pfButtons[] = [
'type' => $ft,
'text' => (string) ($b['text'] ?? ''),
'value' => $ft === 'quick_reply' ? '' : (string) ($b['value'] ?? ''),
];
}
}
$pfMediaUrl = ($prefill && $prefill->attachment_file && str_contains((string) $prefill->attachment_type, 'image'))
? media_url($prefill->attachment_file) : '';
@endphp
{{ __('Templates / New') }}
{{ __('Create message') }} {{ __('template') }}
{{ __('Standard') }}{{ __('Draft / unsaved') }}
@if ($errors->any())
{{ __('Could not save the template:') }}
@foreach ($errors->all() as $msg)
{{ $msg }}
@endforeach
@endif
{{-- Build-with-AI modal — vanilla Tailwind, same overlay/panel
pattern as /templates#type-modal so the visual language stays
consistent. Opened by #open-ai-modal in the sticky bar above.
POST submission lives in user-templates-create.js. --}}
{{ __('Templates / AI') }}
{{ __('Build with') }} AI
{{ __('Draft a high-converting WhatsApp template from a short brief.') }}
{{-- Empty-state when admin hasn't enabled any provider. The
form below stays hidden in that case so the operator
can't submit a request that 422s. --}}
No AI providers are enabled. Ask an admin to add a key in
/admin/api-keys before this can run.