@if (session('status') || $errors->any()) @push('scripts') @endpush @endif @php // Pre-fill helpers. The campaign's array/JSON casts hydrate the // buttons + variable map; old() wins on a validation re-render so the // operator never loses an in-progress edit. $statusKey = strtolower((string) $campaign->status); $curType = old('campaign_type', $campaign->campaign_type ?: 'text'); $curSchedule = old('schedule_type', $campaign->schedule_type ?: 'scheduled'); $buttons = old('custom_buttons', is_array($campaign->custom_buttons) ? $campaign->custom_buttons : []); if (empty($buttons)) { $buttons = [['type' => 'visit_website', 'text' => '', 'url' => '', 'value' => '']]; } // Existing attachment label — shown so the operator knows a file is // already attached and only re-uploads to replace it. $existingMedia = null; if ($campaign->custom_image) { $existingMedia = ['type' => 'Image', 'path' => $campaign->custom_image]; } elseif ($campaign->custom_video) { $existingMedia = ['type' => 'Video', 'path' => $campaign->custom_video]; } elseif ($campaign->custom_document) { $existingMedia = ['type' => 'Document', 'path' => $campaign->custom_document]; } $varMapRaw = old('custom_message_variable_map', $campaign->custom_variable_map ?: '{}'); $varMapJson = is_string($varMapRaw) ? $varMapRaw : json_encode($varMapRaw); if (!$varMapJson) { $varMapJson = '{}'; } $recipientIds = $recipientIds ?? []; @endphp
{{ __('WA Campaigns / Edit') }} / #{{ $campaign->id }}
{{ __('Edit') }} {{ $campaign->campaign_name }}
{{ ucfirst($statusKey ?: 'draft') }}
@csrf @method('PUT')
{{-- ===== Setup ===== --}}
01 {{ __('Campaign setup') }} {{ __('required') }}
{{-- ===== Compose: custom body ===== --}}
02 {{ __('Compose') }} {{ __('message content') }}
{{-- Seed the positional {{1}}→attribute map the compose component emits as custom_message_variable_map. The component hardcodes an empty "{}" default, so without this a saved map would be wiped on edit (stored bodies are already positional, so normalizeCustomMessage leaves them untouched + keeps this map). --}} @push('scripts') @endpush
{{ __('Markdown:') }} *bold* _italic_ ~strike~
{{-- Attachment — only a NEW upload replaces the stored file. --}}
@if ($existingMedia)
{{ __('Current attachment') }}: {{ $existingMedia['type'] }} · {{ \Illuminate\Support\Str::afterLast($existingMedia['path'], '/') }}
@endif
{{ __('No change — keep the existing attachment (if any).') }}
{{-- Buttons — each stored CTA row is pre-filled. JS adds/removes rows. --}}
@foreach ($buttons as $i => $btn) @php $bType = $btn['type'] ?? 'visit_website'; $bText = $btn['text'] ?? ''; $bUrl = $btn['url'] ?? ''; $bVal = $btn['value'] ?? ''; @endphp
@endforeach
{{-- Template picker — only consumed when type=template. --}}
{{-- ===== Recipients ===== --}}
03 {{ __('Recipients') }} {{ count($recipientIds) }} {{ __('selected') }}
{{ __('Leave the current selection untouched to keep the existing audience, or re-pick contacts below to replace it.') }}
@if ($contacts->isNotEmpty())
@foreach ($contacts as $contact) @endforeach
@else
{{ __('No contacts in this workspace yet.') }}
@endif
{{-- ===== Schedule ===== --}}
04 {{ __('Schedule') }} {{ __('queue') }}
{{ __('Cancel') }}