@php $cat = $featured->category ?: 'flow'; $catLabel = ucfirst(str_replace('-', ' ', $cat)); $data = $featured->decoded_flow_data; $nodes = is_array($data['flowNodes'] ?? null) ? $data['flowNodes'] : []; $edges = is_array($data['flowEdges'] ?? null) ? $data['flowEdges'] : []; $stepCount = count($nodes); $messageCount = count( array_filter( $nodes, fn($n) => in_array($n['type'] ?? '', ['message', 'template', 'media', 'buttons', 'list', 'cta'], true), ), ); $waitTotal = 0; foreach ($nodes as $n) { if (($n['type'] ?? '') === 'delay') { $amount = (int) ($n['data']['amount'] ?? 0); $unit = $n['data']['unit'] ?? 'min'; $mins = match ($unit) { 'sec' => max(1, intdiv($amount, 60)), 'hour' => $amount * 60, 'day' => $amount * 1440, default => $amount, }; $waitTotal += $mins; } } $waitLabel = $waitTotal > 0 ? '~' . ($waitTotal >= 60 ? round($waitTotal / 60, 1) . ' h' : $waitTotal . ' min') . ' total' : 'no waits'; // Pick up to 3 nodes for the mini preview pane on the right. $previewable = array_slice(array_values(array_filter($nodes, fn($n) => !empty($n['type']))), 0, 4); $nodeStyle = function (string $type) { return match ($type) { 'trigger' => 'start', 'delay' => 'wait', 'condition' => 'cond', 'message', 'template', 'media', 'buttons', 'list' => 'send', 'tag', 'assign' => 'tag', 'end' => 'end', default => '', }; }; $nodeLabel = function (array $n) { $t = $n['type'] ?? ''; $d = $n['data'] ?? []; return match ($t) { 'trigger' => 'Trigger / ' . ($d['kind'] ?? 'manual'), 'message' => \Illuminate\Support\Str::limit((string) ($d['text'] ?? 'Send message'), 28), 'template' => 'Send template ' . ($d['tpl'] ?? ''), 'media' => 'Send ' . ($d['kind'] ?? 'media'), 'buttons' => 'Quick replies', 'list' => 'List message', 'ask' => \Illuminate\Support\Str::limit((string) ($d['prompt'] ?? 'Ask'), 28), 'condition' => 'If ' . ($d['var'] ?? 'value') . ' ' . ($d['op'] ?? '==') . ' ' . ($d['value'] ?? ''), 'delay' => 'Wait ' . ($d['amount'] ?? '?') . ' ' . ($d['unit'] ?? 'min'), 'webhook' => 'Webhook ' . ($d['method'] ?? 'POST'), 'ai' => 'AI ' . ($d['model'] ?? ''), 'tag' => 'Tag: ' . ($d['action'] ?? 'add') . ' ' . ($d['tag'] ?? ''), 'assign' => 'Assign to ' . ($d['team'] ?? 'team'), 'end' => 'End flow', default => ucfirst($t), }; }; $stateBadge = $featured->is_published ? ['bg-wa-mint', 'text-wa-deep', 'bg-wa-green', 'Live'] : ['bg-paper-50', 'text-ink-500', 'bg-paper-200', 'Draft']; @endphp
{{ $catLabel }} {{ __('Most used') }} {{ $stateBadge[3] }}
{{ __('Your most-used flow') }}

{{ $featured->flow_name }}

{{ $stepCount }} {{ \Illuminate\Support\Str::plural('step', $stepCount) }} {{ $messageCount }} {{ \Illuminate\Support\Str::plural('message', $messageCount) }} {{ $waitLabel }} {{ count($edges) }} {{ \Illuminate\Support\Str::plural('connection', count($edges)) }}

Updated {{ $featured->updated_at?->diffForHumans() ?? '/' }}. Open it to keep iterating, or duplicate it as the starting point for a new flow.

{{ __('Open flow') }}
@csrf
@if (empty($previewable))
{{ __('This flow has no nodes yet. Open the builder to add steps.') }}
@else @foreach ($previewable as $idx => $n) @php $cls = $nodeStyle($n['type'] ?? ''); $label = $nodeLabel($n); $base = 'fl-node bg-white border border-dashed border-[#C9D7CE] rounded-[10px] px-2.5 py-2 text-[11px] text-ink-700 flex items-center gap-1.5'; $variant = match ($cls) { 'start' => 'bg-wa-bubble border-solid border-wa-green text-wa-deep font-medium', 'send' => 'bg-wa-bubble border-solid border-wa-green/40 text-wa-deep', 'wait' => 'bg-[#FFF6E0] border-solid border-accent-amber text-[#7B5A14]', 'cond' => 'bg-[#F4E9C9] border-solid border-[#D9B864] text-[#7B5A14]', 'tag' => 'bg-[#E4DAF1] border-solid border-[#B59FE0] text-[#5B3D8A]', 'end' => 'bg-[#FCE0D5] border-solid border-accent-coral text-[#A1431F] font-medium', default => '', }; @endphp
{{ $label }}
@if (!$loop->last)
@endif @endforeach @if ($stepCount > count($previewable))
/ {{ $stepCount - count($previewable) }} more {{ \Illuminate\Support\Str::plural('step', $stepCount - count($previewable)) }}
@endif @endif