@php // Pre-compute defaults so the form opens with sensible values: // send-date = today in the workspace tz, send-time = now + 30min. // The schedule fields stay hidden until the operator clicks // "Schedule for later" — JS toggles `[data-sched]` visibility. $tz = $defaultTz ?? config('app.timezone', 'UTC'); $defaultDate = \Illuminate\Support\Carbon::now($tz)->format('Y-m-d'); $defaultTime = \Illuminate\Support\Carbon::now($tz)->addMinutes(30)->format('H:i'); // Group categories of WaTemplate buckets so the preview can show // the right Marketing/Utility chip on the right. $templates = $templates ?? collect(); $devices = $devices ?? collect(); $contacts = $contacts ?? collect(); $groups = $groups ?? collect(); $timezones = $timezones ?? [config('app.timezone', 'UTC')]; @endphp
{{ __('Broadcasts / New') }}
{{ __('Create new') }} {{ __('broadcast') }}
{{ __('Draft / unsaved') }}
@if (session('error'))
{{ session('error') }}
@endif @if (isset($errors) && $errors->any())
{{ $errors->first() }}
@endif @php $isIg = ($broadcastChannel ?? 'whatsapp') === 'instagram'; @endphp
@csrf @if ($isIg)@endif
01 {{ __('Broadcast setup') }} {{ $isIg ? __('direct message') : __('template message') }}
{{ __('Internal label used in broadcast reports.') }}
@if ($isIg)
{{ __('The Instagram account this DM is sent from.') }}
@else
@php // Multi-engine: show the Twilio "ready / plain-text" template hints // whenever Twilio is among the workspace's enabled engines, not only // when it's the single default (mirrors TemplatesController). $_bcWsId = auth()->user()->current_workspace_id ?? 0; $isTwilioWs = $_bcWsId && \App\Services\WorkspaceEngine::isEngineEnabled($_bcWsId, 'twilio'); @endphp {{-- Send-time mapping: edit this broadcast's variable values, header media, and button links WITHOUT editing the template. Posts `template_overrides`. --}} @if ($templates->isEmpty())
{{ __('No approved templates yet.') }} {{ __('Create one →') }}
@elseif ($isTwilioWs)
{{ __('Twilio compliant sends require a Content SID per template — flag a template as "Twilio ready" via /templates/{id}/edit. Templates without a ContentSid will send as plain text (loses Meta template approval).') }}
@else
{{ __('Broadcasts send approved templates only.') }}
@endif
@endif
@if ($isIg) {{-- Content — choose "Write text" or "Use template" (a saved Instagram message that prefills the box). --}}
{{ __('Instagram sends a plain DM — no approval needed. Use {name} to personalise.') }}
@endif @unless ($isIg) {{-- Device picker — multi-device aware. With one device we render a single hidden input. With 2+ we render a checkbox list and the controller fans out into N broadcasts at save time. data-device-picker = refreshed in place by the global Connect-device popover after a new device connects. --}}
@if ($devices->count() === 0)
{{ __('No connected devices.') }}
@elseif ($devices->count() === 1) @php $only = $devices->first(); @endphp
{{-- Single sender: post the composite engine:id key so the store stamps the chosen engine (legacy bare-int still accepted as a fallback). --}} {{ $only['label'] }} {{ $only['phone'] }}
@else {{-- Multi-device picker. Operator ticks devices and (when 2+ are ticked) sets per-device share weights so they control HOW the audience is split. Weights are positive numbers; the server normalises them so an audience of N contacts gets `round(N * weight_i / sum_weights)` per device. Equal weights = even split (legacy round-robin). 70 / 30 = bigger device takes 70% of the audience. --}} @php // Group senders by engine so a workspace running 2+ engines // at once shows a header per engine ("Unofficial API", "Meta", // "Twilio"). One engine ⇒ no headers, identical to the legacy // flat list. Preserve the senders() order (default first). $bcByEngine = $devices->groupBy('engine'); $bcEngineOrder = $devices->pluck('engine')->unique()->values(); $bcMultiEngine = $bcEngineOrder->count() > 1; $bcEngineLabel = fn ($engine) => optional($devices->firstWhere('engine', $engine))['engineLabel'] ?? $engine; @endphp
@foreach ($bcEngineOrder as $bcEngine) @if ($bcMultiEngine)
{{ $bcEngineLabel($bcEngine) }}
@endif @foreach ($bcByEngine[$bcEngine] as $d) @endforeach @endforeach
{{ __('Tick devices and set share weights — e.g.') }} 7 / 3 sends 70% of contacts via the first device and 30% via the second. Equal weights split evenly.
@endif
@endunless

{{ $isIg ? __('Which Instagram chats?') : __('Who do you want to send it to?') }}

{{ __('Pick contacts directly or pick a contact group.') }}

0 selected
@unless ($isIg) {{-- Tag audience — ticking a tag adds every contact carrying it, merged with groups / individual picks / manual numbers. Same resolution + workspace guard as the campaigns page. --}} @if (!empty($tags) && count($tags))
{{ __('Tags') }} @foreach ($tags as $tg) @endforeach
@endif @if ($groups->isNotEmpty())
{{ __('Groups') }} @foreach ($groups as $g) @endforeach
@endif @endunless
@if ($isIg) @php $igRows = []; foreach (($igChats ?? []) as $acctId => $rows) { foreach ($rows as $r) { $igRows[] = $r + ['account' => (string) $acctId]; } } @endphp @forelse ($igRows as $r) @empty @endforelse @else @forelse ($contacts as $c) @php // Build display name from whatever fields exist — // `name` is the catch-all; some imports only have // first/last. Phone uses `mobile` + optional // `country_code` (legacy schema kept them split). $cname = trim((string) ($c->name ?? '')) ?: trim(($c->first_name ?? '') . ' ' . ($c->last_name ?? '')) ?: 'Contact #' . $c->id; $cdial = trim((string) ($c->country_code ?? '')); $cphone = trim((string) ($c->mobile ?? '')); $cfull = $cphone === '' ? '' : ($cdial !== '' ? '+' . ltrim($cdial, '+') . ' ' . $cphone : $cphone); @endphp @empty @endforelse @endif
{{ __('Name') }} {{ $isIg ? __('Instagram') : __('Phone') }}
{{ $r['title'] }}
{{ __('Instagram DM') }}
{{ __('No Instagram conversations yet — someone must message this account first.') }}
{{ $cname }}
{{ $cfull ?: '—' }}
{{ __('No contacts yet.') }} {{ __('Add some →') }}
@unless ($isIg)

{{ __('When do you want to send your broadcast?') }}

{{ __('Send immediately or pick a future date / time.') }}

{{-- Schedule fields are hidden by default and revealed when "Schedule for later" is picked. Avoids the form looking cluttered for the common "send now" path. --}}
@endunless