@php $templates = $templates ?? collect(); $categoryCounts = $categoryCounts ?? ['all' => 0]; $statusCounts = $statusCounts ?? ['all' => 0, 'approved' => 0, 'pending' => 0, 'rejected' => 0]; $totalCount = $totalCount ?? 0; $currentCategory = $currentCategory ?? 'all'; $currentStatus = $currentStatus ?? 'all'; $currentSearch = $currentSearch ?? ''; $currentSort = $currentSort ?? 'newest'; $currentChannel = $currentChannel ?? 'all'; $channelCounts = $channelCounts ?? ['all' => $totalCount, 'whatsapp' => $totalCount, 'instagram' => 0, 'facebook' => 0]; @endphp
{{ __('Campaigns / Templates') }}

{{ __('Template') }} {{ __('library') }}.

{{ __('Pick a starter or submit your own. All templates must adhere to') }} {{ __("WhatsApp's guidelines") }} before they're approved by Meta.

@if (!empty($canImportMeta)) {{-- Pull templates created/approved directly in Meta Business Manager into this library. Idempotent — safe to click anytime. --}}
@csrf
@endif {{-- Sync from Instaflow — pulls the workspace's Instagram templates from a REMOTE Instaflow deployment into WaDesk's library. Shown ONLY in remote-Instaflow mode: when the native addon is the engine (instagram_enabled) templates are authored locally via "New Template Message → Instagram", so there is nothing remote to sync and the button is hidden. --}} @php $igTplSyncOn = auth()->user() && auth()->user()->current_workspace_id && ! \App\Models\SystemSetting::get('instagram_enabled', false) && class_exists(\App\Models\WorkspaceIgAccount::class) && \App\Models\WorkspaceIgAccount::hasConnected(auth()->user()->current_workspace_id); @endphp @if ($igTplSyncOn)
@csrf
@endif @if (($prebuiltBlueprints ?? collect())->isNotEmpty()) @endif
@include('user.templates._prebuilt_modal') {{-- Result banner for the "Sync from Meta" action (success/status or the real Meta error, e.g. token invalid / app missing capability). --}} @if (session('status'))
{{ session('status') }}
@endif @if ($errors->has('meta'))
{{ __('Sync from Meta failed:') }} {{ $errors->first('meta') }}
@endif {{-- Channel tabs — WhatsApp vs Instagram, colored like the Flows page. Only shown when the workspace actually has Instagram templates (synced from Instaflow); a pure-WhatsApp workspace never sees a pointless second tab. --}} @php $__etWs = (int) (auth()->user()?->current_workspace_id ?? 0); $emailTplAvail = (bool) \App\Models\SystemSetting::get('email_enabled', false) && \App\Services\PlanLimitGuard::hasFeature(auth()->user()?->currentWorkspace, 'access_email'); $emailTplCount = $emailTplAvail ? \App\Models\EmailTemplate::where('workspace_id', $__etWs)->count() : 0; @endphp @if ((($channelCounts['instagram'] ?? 0) > 0) || (($channelCounts['facebook'] ?? 0) > 0) || (($channelCounts['telegram'] ?? 0) > 0) || $emailTplAvail)
@php $chTabs = [ ['key' => 'all', 'label' => __('All channels'), 'active' => 'border-ink-900 text-ink-900 bg-paper-0'], ['key' => 'whatsapp', 'label' => __('WhatsApp'), 'active' => 'border-wa-deep text-wa-deep bg-wa-mint'], ]; // Only surface a channel tab that actually has templates — a // pure-WhatsApp + Instagram workspace never sees a dead Facebook tab. if (($channelCounts['instagram'] ?? 0) > 0) { $chTabs[] = ['key' => 'instagram', 'label' => __('Instagram'), 'active' => 'border-[#E1306C] text-[#C13584] bg-[#FDF2F8]']; } if (($channelCounts['facebook'] ?? 0) > 0) { $chTabs[] = ['key' => 'facebook', 'label' => __('Facebook'), 'active' => 'border-[#1877F2] text-[#1877F2] bg-[#EFF5FF]']; } if (($channelCounts['telegram'] ?? 0) > 0) { $chTabs[] = ['key' => 'telegram', 'label' => __('Telegram'), 'active' => 'border-[#229ED9] text-[#1B7CB0] bg-[#EAF6FC]']; } @endphp @foreach ($chTabs as $ch) @php $active = $currentChannel === $ch['key']; @endphp @endforeach {{-- Email templates live in their own visual builder + library, so this tab LINKS there rather than filtering the WhatsApp grid (different model entirely). --}} @if ($emailTplAvail) {{ __('Email') }} {{ number_format($emailTplCount) }} @endif
@endif
@php $catLabels = [ 'travel' => __('Travel'), 'healthcare' => __('Healthcare'), 'education' => __('Education'), 'ecommerce' => __('E-Commerce'), 'festival' => __('Festival'), 'finance' => __('Finance'), 'utility' => __('Utility'), 'marketing' => __('Marketing'), 'authentication' => __('Authentication'), ]; // Show ONLY categories that actually have templates (count > 0) — no // empty 0-count tabs. 'All' is always first. The label map titles known // keys; any other category key falls back to a Title-Cased label. $tabs = [['key' => 'all', 'label' => __('All')]]; foreach (($categoryCounts ?? []) as $catKey => $catCnt) { if ($catKey === 'all' || (int) $catCnt <= 0) { continue; } $tabs[] = [ 'key' => $catKey, 'label' => $catLabels[$catKey] ?? ucfirst(str_replace(['_', '-'], ' ', $catKey)), ]; } @endphp @foreach ($tabs as $tab) @php $active = $currentCategory === $tab['key']; @endphp @endforeach
{{-- WABA number filter (#52) — only shown when the workspace has more than one connected number, otherwise it's noise. --}} @if (!empty($wabaNumbers) && count($wabaNumbers) > 1) @endif {{-- STATUS filter — one dropdown rather than four pills, parked with the sort/search controls on the right so the left strip stays purely category + channel. Same wiring as the old pills: it carries data-tpl-filter="status", so init()/paintActive() drive it unchanged; counts ride in the option label and are refreshed by applyCounts() via data-tpl-status-option. --}} @php $statusPills = [ ['key' => 'all', 'label' => __('All status')], ['key' => 'pending', 'label' => __('Pending')], ['key' => 'approved', 'label' => __('Approved')], ['key' => 'rejected', 'label' => __('Rejected')], ]; @endphp
@if (\App\Services\MessageBillingService::payPerMessageFor(auth()->user()?->currentWorkspace)) @endif {{-- items-stretch (not items-start) so every card in a row is the same height — the card is flex-col with a flex-1 preview, so the body fills and the Edit/actions footer aligns to the bottom. --}}
@include('user.templates._cards', ['templates' => $templates])
@include('user.partials.pagination', [ 'paginator' => $templates, 'dataAttr' => 'data-tpl-page', 'label' => 'templates', ])
{{ __('Help - 01') }}
{{ __('What is a template message?') }}

{{ __('A pre-approved message format required by Meta for starting new conversations with customers outside the 24-hour service window.') }}

{{ __('Help - 02') }}
{{ __('How to improve approval times?') }}

{{ __('Keep your message body clear, avoid overly promotional language in Utility categories, and always provide sample values for variables.') }}

{{ __('Help - 03') }}
{{ __('Why was my template rejected?') }}

{{ __('Common reasons include incorrect formatting, mismatched category, or abusive content. Check the rejection reason and edit to resubmit.') }}