{{ $automationId === null ? __('New automation') : __('Edit automation') }}

{{ __('Configure when a rule fires, which tickets it matches, and what it does.') }}

@if ($automationId !== null) {{ __('Run now') }} {{ __('Preview') }} @endif {{ __('Back to list') }}
@if ($lastRunExecutionCount !== null)
@if ($lastRunExecutionCount === 0) {{ __('Last manual run: no candidates matched at the moment.') }} @else {{ __('Last manual run wrote :n execution row(s). Scroll down to inspect.', ['n' => $lastRunExecutionCount]) }} @endif
@endif
{{-- ───────────────────────────────────────────── 1. BASIC ───────────────────────────────────────────── --}}
{{ __('Basic') }} {{ __('Name') }} {{ __('Operator-facing label. The customer never sees this.') }} {{ __('Enabled') }} {{ __('When off the rule still exists, but the scheduler skips it.') }}
{{-- ───────────────────────────────────────────── 2. TRIGGER + SCHEDULE ───────────────────────────────────────────── --}}
{{ __('Trigger + schedule') }}

{{ __('Push 2 ships scheduled ticket inactivity. Event-driven triggers (created / status changed / message received) are reserved for later.') }}

{{ __('Trigger type') }} @foreach ($this->triggerOptions() as $option) {{ $option['label'] }}@if (! $option['implemented']) — {{ __('coming soon') }}@endif @endforeach {{ __('Schedule') }} @foreach (\App\Enums\AutomationScheduleCadence::cases() as $case) {{ $case->label() }} @endforeach {{ __('The cron tick fires every 15 minutes; cadence controls how often the rule actually evaluates inside that envelope.') }}
{{-- ───────────────────────────────────────────── 3. CONDITIONS ───────────────────────────────────────────── --}}
{{ __('Conditions') }} {{ __('Add condition') }}

{{ __('Every condition must hold (AND logic). For "days since" rules, the activity basis controls which timestamp the clock anchors on.') }}

@if (! empty($errors->get('conditions')))
{{ $errors->first('conditions') }}
@endif
@foreach ($conditions as $i => $row) @php $field = $row['field'] ?? null; $fieldEnum = $field ? \App\Enums\AutomationConditionField::tryFrom($field) : null; $operatorOptions = $this->operatorOptionsForField($field); @endphp
{{-- Field --}}
@foreach (\App\Enums\AutomationConditionField::cases() as $case) {{ $case->label() }}@if (! $case->isImplemented()) — {{ __('coming soon') }}@endif @endforeach
{{-- Operator --}}
@foreach ($operatorOptions as $op) {{ $op['label'] }} @endforeach
{{-- Value (per-field type) --}}
@if ($fieldEnum === \App\Enums\AutomationConditionField::Status) @foreach (\App\Enums\TicketStatus::cases() as $case) {{ ucfirst($case->value) }} @endforeach @elseif ($fieldEnum === \App\Enums\AutomationConditionField::Priority) @foreach (\App\Enums\TicketPriority::cases() as $case) {{ ucfirst($case->value) }} @endforeach @elseif ($fieldEnum === \App\Enums\AutomationConditionField::AssignedUserId) {{ __('Unassigned') }} @foreach ($this->assignableUsers() as $user) {{ $user->name }} @endforeach @elseif ($fieldEnum === \App\Enums\AutomationConditionField::ActivityAgeDays) @else @endif
{{-- Remove --}}
{{-- Basis (activity_age_days only) --}} @if ($fieldEnum === \App\Enums\AutomationConditionField::ActivityAgeDays)
{{ __('Measure inactivity from') }} @foreach (\App\Enums\AutomationActivityBasis::cases() as $basis) {{ $basis->label() }} @endforeach {{ __('Stale-pending rules default to “last agent reply” — internal notes never count, and a fresh customer reply reopens the ticket via the inbound pipeline before the rule can fire.') }}
@endif
@endforeach @if ($conditions === [])
{{ __('Add at least one condition before saving.') }}
@endif
{{-- ───────────────────────────────────────────── 4. ACTIONS ───────────────────────────────────────────── --}}
{{ __('Actions') }} {{ __('Add action') }}

{{ __('Actions run in order. Each one is idempotent — closing a closed ticket is a safe no-op.') }}

@if (! empty($errors->get('actions')))
{{ $errors->first('actions') }}
@endif
@foreach ($actions as $i => $row) @php $type = $row['type'] ?? null; $typeEnum = $type ? \App\Enums\AutomationActionType::tryFrom($type) : null; @endphp
{{-- Type --}}
@foreach ($this->actionOptions() as $option) {{ $option['label'] }}@if (! $option['implemented']) — {{ __('coming soon') }}@endif @endforeach
{{-- Per-type params --}}
@if ($typeEnum === \App\Enums\AutomationActionType::AddInternalNote) @elseif ($typeEnum === \App\Enums\AutomationActionType::AssignUser) {{ __('Pick an agent…') }} @foreach ($this->assignableUsers() as $user) {{ $user->name }} @endforeach @elseif ($typeEnum === \App\Enums\AutomationActionType::ChangePriority) @foreach (\App\Enums\TicketPriority::cases() as $case) {{ ucfirst($case->value) }} @endforeach @elseif ($typeEnum === \App\Enums\AutomationActionType::CloseTicket || $typeEnum === \App\Enums\AutomationActionType::ReopenTicket)

{{ __('No extra options.') }}

@else

{{ __('This action type is not yet implemented.') }}

@endif
{{-- Remove --}}
@endforeach @if ($actions === [])
{{ __('Add at least one action before saving.') }}
@endif
{{-- ───────────────────────────────────────────── 5. SCOPE (optional) ───────────────────────────────────────────── --}}
{{ __('Scope (optional)') }}

{{ __('Restrict the rule to a subset of tickets. Leave any field blank to skip that filter.') }}

{{ __('Assigned agent') }} {{ __('Any agent') }} @foreach ($this->assignableUsers() as $user) {{ $user->name }} @endforeach {{ __('Store') }} {{ __('Any store') }} @foreach ($this->storesForScope() as $store) {{ $store->name }} @endforeach {{ __('Priority') }} {{ __('Any priority') }} @foreach (\App\Enums\TicketPriority::cases() as $case) {{ ucfirst($case->value) }} @endforeach
{{-- ───────────────────────────────────────────── FOOTER BUTTONS ───────────────────────────────────────────── --}}
{{ $automationId === null ? __('Create automation') : __('Save changes') }} {{ __('Cancel') }}
{{-- ───────────────────────────────────────────── PREVIEW PANEL ───────────────────────────────────────────── --}} @if ($previewPayload !== null)
{{ __('Preview') }}

{{ __('Candidates :n (showing first :s).', [ 'n' => $previewPayload['candidate_count'] ?? 0, 's' => count($previewPayload['candidates'] ?? []), ]) }}

{{ __('Close preview') }}
@if (empty($previewPayload['candidates'] ?? []))
{{ __('No candidate tickets match the current conditions + scope.') }}
@else
@foreach ($previewPayload['candidates'] as $candidate) @endforeach
{{ __('Ticket') }} {{ __('Subject') }} {{ __('Would fire?') }} {{ __('Planned actions') }}
#{{ $candidate['ticket_id'] }} {{ $candidate['subject'] ?: '(no subject)' }} @if (! empty($candidate['matched'])) {{ __('Yes') }} @else {{ __('Skipped') }} {{ $candidate['reason_if_skipped'] ?? '' }} @endif {{ implode(', ', $candidate['planned_actions'] ?? []) ?: '—' }}
@endif
@endif {{-- ───────────────────────────────────────────── RECENT EXECUTIONS ───────────────────────────────────────────── --}} @if ($automationId !== null) @php $executions = $this->recentExecutions(); @endphp
{{ __('Recent executions') }} {{ __('View full history') }}

{{ __('Last 10 attempts the engine made against this rule. Skipped means the ticket drifted out of the matching state between the scan and the action.') }}

@if (collect($executions)->isEmpty())
{{ __('This rule has not fired yet. The next scheduled tick will run it.') }}
@else
@foreach ($executions as $execution) @endforeach
{{ __('When') }} {{ __('Subject') }} {{ __('Status') }} {{ __('Detail') }}
{{ $execution->started_at?->diffForHumans() ?? '—' }} @if ($execution->subject_type && $execution->subject_id) {{ class_basename($execution->subject_type) }} #{{ $execution->subject_id }} @else @endif @php $status = $execution->status; @endphp {{ $status?->label() ?? '—' }} @php $reason = $execution->condition_snapshot_json['reason_if_skipped'] ?? null; $err = $execution->error_json['message'] ?? null; @endphp @if ($err !== null) {{ $err }} @elseif ($reason !== null) {{ $reason }} @elseif ($status?->value === 'succeeded') {{ __('Actions ran cleanly.') }} @else @endif
@endif
@endif