/* global React */ const { useState, useEffect, useRef } = React; // ============================================ // AUTOMATION FLOW HERO VISUAL // 5 nodes connected in a workflow, animated activation cycle. // ============================================ window.AutomationFlow = function AutomationFlow({ t }) { const [activeIdx, setActiveIdx] = useState(0); const [logs, setLogs] = useState([]); const [dotPos, setDotPos] = useState(null); const positions = [ { x: 8, y: 8 }, { x: 56, y: 8 }, { x: 8, y: 35 }, { x: 56, y: 35 }, { x: 30, y: 62 }, ]; useEffect(() => { const i = setInterval(() => { setActiveIdx(prev => { const next = (prev + 1) % t.flow.nodes.length; setLogs(l => { const newLog = t.flow.logs[next]; const out = [...l, { id: Date.now() + next, text: newLog }]; return out.slice(-3); }); return next; }); }, 1700); return () => clearInterval(i); }, [t]); useEffect(() => { setLogs([]); }, [t]); useEffect(() => { const prev = (activeIdx - 1 + positions.length) % positions.length; const from = positions[prev]; const to = positions[activeIdx]; let start; let raf; const dur = 600; const animate = (ts) => { if (!start) start = ts; const p = Math.min(1, (ts - start) / dur); const eased = p < 0.5 ? 2*p*p : 1 - Math.pow(-2*p + 2, 2) / 2; setDotPos({ x: from.x + (to.x - from.x) * eased + 9, y: from.y + (to.y - from.y) * eased + 4, }); if (p < 1) raf = requestAnimationFrame(animate); else setDotPos(null); }; raf = requestAnimationFrame(animate); return () => cancelAnimationFrame(raf); }, [activeIdx]); const connections = positions.map((p, i) => { const next = positions[(i + 1) % positions.length]; return { from: p, to: next, id: i }; }); const pathFor = (from, to) => { const fx = from.x + 18, fy = from.y + 5.5; const tx = to.x + 18, ty = to.y + 5.5; const midX = (fx + tx) / 2; return `M ${fx} ${fy} L ${midX} ${fy} L ${midX} ${ty} L ${tx} ${ty}`; }; return (
{t.flow.header} = 1 ? "on" : ""}/>= 3 ? "on" : ""}/> {t.flow.status}
{connections.map((c, i) => ( ))} {dotPos && ( )} {t.flow.nodes.map((n, i) => (
{n.code}
{n.label}
))}
{logs.map((l, i) => ( {l.text} ))}
); };