@extends('admin.layouts.app') @section('title', __('admin.automations.edit_title') . ' — ' . $automation->displayName()) @section('page_title', __('admin.automations.edit_title')) @php use App\Models\Automation; $selectedChannels = old('channels', $automation->channels ?: []); $isReminder = $automation->type === Automation::TYPE_REMINDER; // `creation` automations (committee_created — automations #9 + #10) // fire IMMEDIATELY via the event listener // App\Listeners\DispatchCommitteeCreationAutomations, so a delay // setting would be ignored. The form hides the "Execute After // Registration" field for them and shows a small info line instead. $isCreation = $automation->type === Automation::TYPE_CREATION; /* Channel accordion — the SAME four channels as the Actions (label option-edit) screen: email, SMS, WhatsApp, in-app notification. Order matches the dispatch order in AutomationNotificationService. */ /* Channel-row icons. WhatsApp uses its real brand glyph (green); the rest stay as emoji — same set the Actions option-edit screen uses. */ $waLogo = ''; $channelDefs = [ 'email' => '✉️', 'sms' => '📱', 'whatsapp' => $waLogo, 'notification' => '🔔', ]; // Chip palette source. AutomationController::edit() is the // authoritative scope filter — it already drops rejection_only + // committee_attendance_only + investor_committee_only + // startup_committee_only based on the automation's audience and // trigger. Whatever lands in $templateVariables is by definition // visible for THIS automation, so we just pass the keys through // without re-filtering. (The legacy view-side filter was stricter // than the controller and silently hid the new committee_*_slots // placeholders.) $vars = array_keys(($templateVariables ?? [])); /* WhatsApp positional placeholders. Seed with three empty slots when none are stored so the grid (matching the Actions screen) opens with something to fill rather than an empty void. */ $waPlaceholders = old('whatsapp_placeholders', $automation->whatsapp_placeholders ?: []); if (! is_array($waPlaceholders) || count($waPlaceholders) === 0) { $waPlaceholders = ['', '', '']; } @endphp @push('styles') @endpush @section('content') {{ __('admin.automations.back') }} @include('admin.partials.flash')
@csrf @method('PATCH')

{{ __('admin.automations.settings_title') }}

{{-- Enable toggle --}}
{{ __('admin.automations.enable_automation') }}
{{ __('admin.automations.enable_hint') }}
@if ($isReminder)
{{ __('admin.automations.reminder_minutes_hint') }} @error('reminder_minutes') {{ $message }} @enderror
@elseif ($isCreation) {{-- Committee-creation automations fire immediately via the queued event listener — no delay is honored or editable. The info banner replaces the now-removed "Execute After Registration" field. --}}
{{ __('admin.automations.execute_immediate') }} {{ __('admin.automations.execute_immediate_hint') }}
@else {{-- Execute After Registration — the per-automation waiting window the onboarding scan honours before firing. The scan reads (value, unit) and converts to minutes. Only the `new` (onboarding) automations need this. --}}
{{ __('admin.automations.execute_after_hint') }} @error('execute_after_value') {{ $message }} @enderror @error('execute_after_unit') {{ $message }} @enderror
@endif {{-- ── Channels section ── --}}

{{ __('admin.automations.notification_channels') }}

{{ __('admin.automations.channels_hint') }}

@foreach ($channelDefs as $channel => $icon)
{{ __('admin.automations.channels.' . $channel) }}
{{ __('admin.automations.' . $channel . '_content_hint') }}
@if ($channel === 'email') {{-- `dir="auto"` lets the browser pick per-paragraph direction from the first strong character — Arabic paragraphs flow RTL with the colon / period at the end of the line, Latin paragraphs flow LTR. Without this the editor inherited the page's LTR direction and Arabic lines like "التاريخ: {{ '{{date}}' }}" came out visually mirrored. --}}
{{ __('admin.automations.email_body_hint') }}
@elseif ($channel === 'sms')
{{ __('admin.automations.sms_body_hint') }}
@elseif ($channel === 'whatsapp') {{-- WhatsApp template + placeholder UI — the SAME picker the Actions option-edit screen uses (SendPulse dropdown + manual fallback + dynamic positional placeholders). The template id is submitted via the hidden field below; the select / text input are pure UI bound to Alpine state. --}}
@error('whatsapp_template_id') {{ $message }} @enderror
{{ __('admin.labels.whatsapp_placeholders_hint') }}
@else
@endif {{-- Server-side Preview (Phase 8 backend, Phase 10 UI). Renders the SAVED automation body against the same TemplateContext the real dispatcher uses + auto-picks a realistic recipient + committee. Hidden until clicked. Skipped for the in-app channel (no real provider yet). --}} @if ($channel !== 'notification')
{{-- Placeholder legend (real/sample chips) removed per UX request — the rendered subject + body alone tell admins what the recipient would see; the chip list was visual noise. The Preview service still computes the legend; we simply no longer render it. --}}
@endif
@endforeach
@error('channels') {{ $message }} @enderror {{-- ── Template variables ── --}}

{{ __('admin.automations.template_variables') }}

{{ __('admin.automations.template_variables_hint') }}

@forelse ($vars as $key) @empty {{ __('admin.automations.no_variables') }} @endforelse
{{ __('admin.actions.cancel') }}
@endsection @push('scripts') @endpush