PageSourceSearch

https://araf.az/_next/static/chunks/8119.c843839b21af3ffe.js

js araf.az collected 2026-10-03 00:55:17 UTC 73,569 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[8119],{18119:function(e,t,a){a.r(t),a.d(t,{default:function(){return ex}});var s=a(27573),n=a(7653);let l={trigger:{bg:"bg-orange-50 dark:bg-orange-900/20",border:"border-orange-300 dark:border-orange-700",icon:"text-orange-500",label:"Trigger"},condition:{bg:"bg-amber-50 dark:bg-amber-900/20",border:"border-amber-300 dark:border-amber-700",icon:"text-amber-500",label:"Condition"},switch:{bg:"bg-purple-50 dark:bg-purple-900/20",border:"border-purple-300 dark:border-purple-700",icon:"text-purple-500",label:"Switch"},action:{bg:"bg-blue-50 dark:bg-blue-900/20",border:"border-blue-300 dark:border-blue-700",icon:"text-blue-500",label:"Action"},loop:{bg:"bg-cyan-50 dark:bg-cyan-900/20",border:"border-cyan-300 dark:border-cyan-700",icon:"text-cyan-500",label:"Loop"},merge:{bg:"bg-indigo-50 dark:bg-indigo-900/20",border:"border-indigo-300 dark:border-indigo-700",icon:"text-indigo-500",label:"Merge"},filter:{bg:"bg-emerald-50 dark:bg-emerald-900/20",border:"border-emerald-300 dark:border-emerald-700",icon:"text-emerald-500",label:"Filter"},set:{bg:"bg-teal-50 dark:bg-teal-900/20",border:"border-teal-300 dark:border-teal-700",icon:"text-teal-500",label:"Set"},code:{bg:"bg-slate-50 dark:bg-slate-900/20",border:"border-slate-300 dark:border-slate-700",icon:"text-slate-500",label:"Code"}},r=[{value:"send_email",label:"Send Email",icon:"Mail"},{value:"delay",label:"Delay / Wait",icon:"Clock"},{value:"webhook",label:"Webhook",icon:"Globe"},{value:"update_record",label:"Update Record",icon:"Database"},{value:"reply_in_chat",label:"Reply in Chat",icon:"MessageSquare"},{value:"send_twilio",label:"Send SMS / WhatsApp",icon:"Smartphone"},{value:"ai_generate",label:"AI Generate",icon:"Sparkles"}],o=[{value:"equals",label:"Equals"},{value:"not_equals",label:"Not equals"},{value:"contains",label:"Contains"},{value:"not_contains",label:"Not contains"},{value:"starts_with",label:"Starts with"},{value:"ends_with",label:"Ends with"},{value:"not_empty",label:"Is not empty"},{value:"empty",label:"Is empty"},{value:"greater_than",label:"Greater than"},{value:"less_than",label:"Less than"}];function i(e){switch(e.type){case"trigger":case"action":case"filter":case"set":case"code":case"merge":default:return[{id:"default",label:""}];case"condition":return[{id:"yes",label:"Y",color:"#22c55e"},{id:"no",label:"N",color:"#ef4444"}];case"switch":{let t=(e.data.cases||[]).map((e,t)=>({id:"case_".concat(t),label:e.label||e.value||"".concat(t+1),color:c[t%c.length]}));return t.push({id:"default",label:"Else",color:"#94a3b8"}),t}case"loop":return[{id:"body",label:"Each",color:"#06b6d4"},{id:"done",label:"Done",color:"#22c55e"}]}}let c=["#8b5cf6","#3b82f6","#06b6d4","#10b981","#f59e0b","#ef4444"];function d(e){return"switch"===e.type?Math.max(220,44*i(e).length+44):220}var u=a(90743),x=a(3349),p=a(26987),m=a(8627),h=a(93640),g=a(44242),b=a(34527),v=a(61569),f=a(25555),y=a(34078),j=a(5965),N=a(61990);let k={trigger:u.Z,condition:x.Z,switch:x.Z,loop:p.Z,merge:m.Z,filter:h.Z,set:g.Z,code:b.Z},w={send_email:v.Z,delay:f.Z,webhook:y.Z,update_record:j.Z};function _(e){let{node:t,isSelected:a}=e,n=l[t.type],o=function(e){var t;if("action"===e.type){let t=r.find(t=>t.value===e.data.actionType);return t?t.label:"Action"}return(null===(t=l[e.type])||void 0===t?void 0:t.label)||"Unknown"}(t),i=function(e){switch(e.type){case"trigger":return e.data.event?e.data.event.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase()):"Select event...";case"condition":if(e.data.field){let t="not_empty"===e.data.operator?"exists":"empty"===e.data.operator?"is empty":"".concat(e.data.operator," ").concat(e.data.value||"");return"".concat(e.data.field," ").concat(t)}return"Set condition...";case"switch":if(e.data.field){let t=e.data.cases||[];return"".concat(e.data.field," → ").concat(t.length," branches")}return"Configure switch...";case"filter":if(e.data.field)return"".concat(e.data.field," ").concat(e.data.operator||"?");return"Set filter...";case"loop":return e.data.listField?"Each in ".concat(e.data.listField):"Configure list...";case"merge":return"".concat(e.data.mode||"combine"," branches");case"set":{let t=e.data.mappings||[];return t.length>0?"".concat(t.length," variable(s)"):"Add mappings..."}case"code":return e.data.code?"".concat(e.data.language||"expression"):"Write code...";case"action":if(!e.data.actionType)return"Choose action type...";switch(e.data.actionType){case"send_email":return e.data.to?"To: ".concat(e.data.to):"Configure email...";case"delay":return e.data.duration?"Wait ".concat(e.data.duration," ").concat(e.data.unit||"min"):"Set delay...";case"webhook":return e.data.url?"".concat(e.data.method||"POST"," ").concat(C(e.data.url,22)):"Set URL...";case"ai_generate":return e.data.prompt?"AI: ".concat(C(e.data.prompt,22)):"Write prompt...";case"send_twilio":return e.data.to?"".concat((e.data.channel||"sms").toUpperCase()," → ").concat(C(e.data.to,18)):"Set recipient...";case"reply_in_chat":return e.data.message?"Reply: ".concat(C(e.data.message,22)):"Write reply...";case"update_record":return e.data.table?"".concat(e.data.table,".").concat(e.data.field||"?"):"Configure...";default:return"Configure..."}default:return"Unknown"}}(t),c=d(t),u=k[t.type]||N.Z;return"action"===t.type&&(u=w[t.data.actionType]||N.Z),(0,s.jsx)("foreignObject",{x:0,y:0,width:c,height:72,style:{overflow:"visible"},children:(0,s.jsxs)("div",{className:"rounded-xl border-2 ".concat(n.bg," ").concat(a?"border-[#F07B6E] shadow-lg shadow-[#F07B6E]/20":n.border," flex items-center gap-3 px-4 select-none transition-all hover:shadow-md"),style:{height:"".concat(72,"px"),width:"".concat(c,"px")}
1,children:[(0,s.jsx)("div",{className:"w-9 h-9 rounded-lg flex items-center justify-center ".concat(n.icon," bg-white/80 dark:bg-gray-800/80 shadow-sm flex-shrink-0"),children:(0,s.jsx)(u,{className:"w-[18px] h-[18px]"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500",children:o}),(0,s.jsx)("div",{className:"text-[13px] font-medium text-gray-800 dark:text-gray-200 truncate",children:i})]})]})})}function C(e,t){return e?e.length>t?e.slice(0,t)+"…":e:""}function E(e){let t,{edge:a,nodes:n,onDelete:l}=e,r=n.find(e=>e.id===a.source),o=n.find(e=>e.id===a.target);if(!r||!o)return null;let c=i(r),u=c.findIndex(e=>e.id===a.sourceHandle),x=c[u],p=d(r);t=1===c.length?r.position.x+p/2:r.position.x+p/(c.length+1)*((u>=0?u:0)+1);let m=r.position.y+72,h=o.position.x+d(o)/2,g=o.position.y,b=Math.max(50,.4*Math.abs(g-m)),v="M ".concat(t," ").concat(m," C ").concat(t," ").concat(m+b,", ").concat(h," ").concat(g-b,", ").concat(h," ").concat(g),f=(t+h)/2,y=(m+g)/2,j=(null==x?void 0:x.color)||"#94a3b8",N=(null==x?void 0:x.label)&&""!==x.label;return(0,s.jsxs)("g",{className:"group cursor-pointer",children:[(0,s.jsx)("path",{d:v,fill:"none",stroke:"transparent",strokeWidth:16,onClick:()=>l(a.id)}),(0,s.jsx)("path",{d:v,fill:"none",stroke:j,strokeWidth:2,className:"group-hover:stroke-[#F07B6E] transition-colors"}),(0,s.jsx)("circle",{cx:h,cy:g,r:3,fill:j,className:"group-hover:fill-[#F07B6E]"}),N&&(0,s.jsxs)("g",{children:[(0,s.jsx)("rect",{x:f-16,y:y-10,width:32,height:20,rx:10,fill:"".concat(j,"22"),stroke:j,strokeWidth:1}),(0,s.jsx)("text",{x:f,y:y+4,textAnchor:"middle",fontSize:10,fontWeight:600,fill:j,children:x.label})]}),(0,s.jsxs)("g",{className:"opacity-0 group-hover:opacity-100 transition-opacity",onClick:()=>l(a.id),children:[(0,s.jsx)("circle",{cx:f,cy:N?y+20:y,r:10,fill:"#fee2e2",stroke:"#ef4444",strokeWidth:1}),(0,s.jsx)("text",{x:f,y:(N?y+20:y)+4,textAnchor:"middle",fontSize:12,fill:"#ef4444",children:"\xd7"})]})]})}function S(e){let t,{sourceNode:a,handleType:n,mouseX:l,mouseY:r}=e,o=i(a),c=o.findIndex(e=>e.id===n),u=d(a);t=1===o.length?a.position.x+u/2:a.position.x+u/(o.length+1)*((c>=0?c:0)+1);let x=a.position.y+72,p=Math.max(50,.4*Math.abs(r-x)),m="M ".concat(t," ").concat(x," C ").concat(t," ").concat(x+p,", ").concat(l," ").concat(r-p,", ").concat(l," ").concat(r);return(0,s.jsx)("path",{d:m,fill:"none",stroke:"#F07B6E",strokeWidth:2,strokeDasharray:"6 3",pointerEvents:"none"})}var T=a(3172);let I={trigger:u.Z,condition:x.Z,switch:x.Z,action:N.Z,loop:p.Z,merge:m.Z,filter:h.Z,set:g.Z,code:b.Z},F=[{label:"Logic",items:[{type:"condition",description:"If/else (yes/no)"},{type:"switch",description:"Multi-branch routing"},{type:"filter",description:"Pass or block data"}]},{label:"Flow",items:[{type:"loop",description:"Iterate over a list"},{type:"merge",description:"Wait & combine branches"}]},{label:"Transform",items:[{type:"set",description:"Set/modify variables"},{type:"code",description:"Custom expression"}]},{label:"Actions",items:[{type:"action",description:"Email, webhook, delay..."}]}];function A(e){let{onAddNode:t,hasTrigger:a}=e;return(0,s.jsxs)("div",{className:"w-52 flex-shrink-0 bg-white dark:bg-gray-900 border-r border-gray-200 dark:border-gray-700 flex flex-col",children:[(0,s.jsx)("div",{className:"px-4 py-3 border-b border-gray-200 dark:border-gray-700",children:(0,s.jsx)("h3",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-400",children:"Add Nodes"})}),(0,s.jsxs)("div",{className:"flex-1 overflow-y-auto p-3 space-y-4",children:[!a&&(0,s.jsx)("div",{children:(0,s.jsx)(Z,{type:"trigger",description:"Starting event",onAdd:t})}),F.map(e=>(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-[9px] font-semibold uppercase tracking-wider text-gray-300 dark:text-gray-600 mb-1.5 px-1",children:e.label}),(0,s.jsx)("div",{className:"space-y-1.5",children:e.items.map(e=>(0,s.jsx)(Z,{type:e.type,description:e.description,onAdd:t},e.type))})]},e.label))]}),(0,s.jsx)("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700",children:(0,s.jsx)("p",{className:"text-[10px] text-gray-400 leading-relaxed",children:"Click ● handles to connect nodes."})})]})}function Z(e){let{type:t,description:a,onAdd:n}=e,r=l[t],o=I[t];return(0,s.jsxs)("button",{onClick:()=>n(t),className:"w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg border ".concat(r.border," ").concat(r.bg," hover:shadow-sm transition-all text-left group"),children:[(0,s.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center ".concat(r.icon," bg-white/80 dark:bg-gray-800/80"),children:(0,s.jsx)(o,{className:"w-3.5 h-3.5"})}),(0,s.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,s.jsx)("div",{className:"text-xs font-medium text-gray-800 dark:text-gray-200",children:r.label}),(0,s.jsx)("div",{className:"text-[9px] text-gray-400 truncate",children:a})]}),(0,s.jsx)(T.Z,{className:"w-3 h-3 text-gray-300 group-hover:text-[#F07B6E] transition-colors"})]})}var O=a(53146),D=a.n(O),M=a(10269),z=a(46762);function W(e){let{label:t,children:a,className:n=""}=e;return(0,s.jsxs)("div",{className:n,children:[(0,s.jsx)("label",{className:"block text-xs font-medium text-gray-500 dark:text-gray-400 mb-1.5",children:t}),a]})}function B(e){let{variables:t,onInsert:a,position:l="bottom"}
1=e,[r,o]=(0,n.useState)(!1),i=(0,n.useRef)(null);return((0,n.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),0===t.length)?null:(0,s.jsxs)("div",{ref:i,className:"absolute right-2 ".concat("top"===l?"top-2":"top-1/2 -translate-y-1/2"),children:[(0,s.jsx)("button",{onClick:()=>o(!r),type:"button",className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-400 hover:text-[#F07B6E] transition-colors",title:"Insert variable",children:(0,s.jsx)(z.Z,{className:"w-3.5 h-3.5"})}),r&&(0,s.jsx)("div",{className:"absolute right-0 ".concat("top"===l?"top-7":"bottom-7"," w-48 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-600 rounded-lg shadow-lg z-50 max-h-48 overflow-y-auto"),children:(0,s.jsx)("div",{className:"p-1",children:t.map(e=>(0,s.jsx)("button",{onClick:()=>{a(e),o(!1)},className:"w-full text-left px-2 py-1.5 text-xs font-mono text-gray-700 dark:text-gray-300 hover:bg-[#F07B6E]/10 hover:text-[#F07B6E] rounded transition-colors",children:"{{".concat(e,"}}")},e))})})]})}function L(e,t){let a=(a,s)=>t({...e,[a]:s});return{update:a,updateMultiple:a=>t({...e,...a}),insertVariable:(t,s)=>{let n=e[t]||"";a(t,n+"{{".concat(s,"}}"))}}}var P=a(87354),R=a(51856);let U=[{label:"Every 5 minutes",value:"*/5 * * * *"},{label:"Every 15 minutes",value:"*/15 * * * *"},{label:"Every hour",value:"0 * * * *"},{label:"Every day at 9 AM",value:"0 9 * * *"},{label:"Every Monday at 9 AM",value:"0 9 * * 1"},{label:"Every 1st of month",value:"0 0 1 * *"},{label:"Custom",value:"custom"}];var V=a(10997),q=a(20054),J=a(75721),G=a(32906),H=a(27126),Y=a(54169),X=a(38983),Q=a(2966),K=a(58153);function $(e){let{data:t,onUpdate:a}=e;return(0,s.jsx)(W,{label:"Action Type",children:(0,s.jsxs)("select",{value:t.actionType||"",onChange:e=>{let t=e.target.value;a({send_email:{actionType:t,to:"",subject:"",body:"",template_id:0,wrapper:!0},delay:{actionType:t,duration:5,unit:"minutes"},webhook:{actionType:t,url:"",method:"POST"},update_record:{actionType:t,table:"",field:"",value:""},reply_in_chat:{actionType:t,message:"",session_token:"{{session_token}}"},send_twilio:{actionType:t,channel:"sms",to:"",body:""},ai_generate:{actionType:t,agent_slug:"",prompt:"",output:"text",max_tokens:1024}}[t]||{actionType:t})},className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Select action..."}),r.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]})})}let ee={trigger:u.Z,condition:x.Z,switch:x.Z,action:N.Z,loop:p.Z,merge:m.Z,filter:h.Z,set:g.Z,code:b.Z},et={trigger:function(e){var t;let{data:a,eventTypes:l,projectId:r,onUpdate:o}=e,{update:i,updateMultiple:c}
1=L(a,o),[d,u]=(0,n.useState)(!1),[x,p]=(0,n.useState)(a.cron_expression&&!U.some(e=>e.value===a.cron_expression)?"custom":a.cron_expression||""),m=[{name:"form_submitted",label:"Form Submitted",icon:"\uD83D\uDCDD"},{name:"webhook_received",label:"Webhook Received",icon:"\uD83C\uDF10"},{name:"scheduled",label:"Scheduled / Cron",icon:"⏰"}],h=[...m,...(l||[]).filter(e=>e.icon&&!m.some(t=>t.name===e.name)).map(e=>({name:e.name,label:e.label,icon:e.icon}))],g=a.webhook_slug?"".concat(window.location.origin,"/api/v1/modules/automations/webhook/").concat(r,"/").concat(a.webhook_slug):"",b=e=>{p(e),"custom"!==e&&i("cron_expression",e)};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(W,{label:"When this happens",children:(0,s.jsxs)("select",{value:a.event||"",onChange:e=>{let t=e.target.value,a={event:t};"webhook_received"!==t&&(a.webhook_slug=""),"scheduled"!==t&&(a.cron_expression=""),c(a)},className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Select event..."}),h.map(e=>(0,s.jsxs)("option",{value:e.name,children:[e.icon," ",e.label]},e.name))]})}),"form_submitted"===a.event&&(0,s.jsxs)("p",{className:"text-xs text-gray-400 mt-2",children:["All form fields are passed as variables. Use ",(0,s.jsx)("code",{className:"text-[10px] bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"{{field_name}}"})," in downstream nodes."]}),["chat_started","chat_message_received","payment_received","payment_failed","visitor_file_uploaded","member_auth"].includes(a.event)&&(0,s.jsxs)("div",{className:"mt-2 p-2 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[(0,s.jsx)("p",{className:"text-[10px] text-blue-600 dark:text-blue-400 font-medium mb-1",children:"Available variables:"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1",children:((null===(t=(l||[]).find(e=>e.name===a.event))||void 0===t?void 0:t.variables)||[]).map(e=>(0,s.jsx)("span",{className:"px-1.5 py-0.5 bg-blue-100 dark:bg-blue-800/40 text-blue-700 dark:text-blue-300 text-[10px] rounded font-mono",children:"{{".concat(e,"}}")},e))}),(0,s.jsx)("p",{className:"text-[10px] text-blue-500 dark:text-blue-400 mt-1",children:"member_auth"===a.event?"One trigger for everything about a member. The variable event says which case it is (password_reset_requested for now): add a Condition on event, then a Send Email. link is a one-time link, minutes is how long it works.":a.event.startsWith("chat_")?'answered_by is "faq" or "ai". Chat Started fires only on the visitor\'s first real message; Chat Message Received fires on every message.':a.event.startsWith("payment_")?'Fires from the unified payment confirmation (all providers). status is "paid" or "failed"; error holds the failure reason.':"Fires only for unauthenticated storefront form uploads (form-uploads folder); admin uploads never trigger it. file_path is relative (/files/...); prefix your site domain for a full link."})]}),"webhook_received"===a.event&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(W,{label:"Webhook Slug",children:[(0,s.jsx)("input",{type:"text",value:a.webhook_slug||"",onChange:e=>i("webhook_slug",e.target.value.replace(/[^a-z0-9_-]/gi,"").toLowerCase()),placeholder:"my-webhook",className:"input-field"}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Lowercase letters, numbers, hyphens, underscores only"})]}),a.webhook_slug&&(0,s.jsxs)(W,{label:"Webhook URL",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,s.jsx)("div",{className:"flex-1 p-2 bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg text-[10px] font-mono text-gray-600 dark:text-gray-400 break-all select-all",children:g}),(0,s.jsx)("button",{onClick:()=>{navigator.clipboard.writeText(g),u(!0),setTimeout(()=>u(!1),2e3)},className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-400 hover:text-[#F07B6E] transition-colors flex-shrink-0",title:"Copy URL",children:d?(0,s.jsx)(P.Z,{className:"w-4 h-4 text-green-500"}):(0,s.jsx)(R.Z,{className:"w-4 h-4"})})]}),(0,s.jsxs)("div",{className:"mt-2 p-2 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[(0,s.jsx)("p",{className:"text-[10px] text-blue-600 dar
1k:text-blue-400 font-medium mb-1",children:"Available variables:"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1",children:["webhook_method","webhook_slug","webhook_ip","webhook_body"].map(e=>(0,s.jsx)("span",{className:"px-1.5 py-0.5 bg-blue-100 dark:bg-blue-800/40 text-blue-700 dark:text-blue-300 text-[10px] rounded font-mono",children:"{{".concat(e,"}}")},e))}),(0,s.jsx)("p",{className:"text-[10px] text-blue-500 dark:text-blue-400 mt-1",children:"POST body fields are also available as variables."})]})]})]}),"scheduled"===a.event&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(W,{label:"Schedule",children:(0,s.jsxs)("select",{value:x,onChange:e=>b(e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Select schedule..."}),U.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]})}),"custom"===x&&(0,s.jsxs)(W,{label:"Cron Expression",children:[(0,s.jsx)("input",{type:"text",value:a.cron_expression||"",onChange:e=>i("cron_expression",e.target.value),placeholder:"*/5 * * * *",className:"input-field font-mono"}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Format: minute hour day_of_month month day_of_week"})]}),a.cron_expression&&(0,s.jsxs)("div",{className:"p-2.5 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[(0,s.jsx)(f.Z,{className:"w-3 h-3 text-amber-500"}),(0,s.jsx)("span",{className:"text-[10px] font-semibold text-amber-700 dark:text-amber-300",children:"Schedule Preview"})]}),(0,s.jsx)("p",{className:"text-xs text-amber-600 dark:text-amber-400",children:function(e){let t=e.trim().split(/\s+/);if(5!==t.length)return"Invalid cron expression";let[a,s,n,l,r]=t;return t.every(e=>"*"===e)?"Every minute":a.startsWith("*/")&&"*"===s&&"*"===n&&"*"===l&&"*"===r?"Every ".concat(a.slice(2)," minutes"):"*"===s&&"*"===n&&"*"===l&&"*"===r?"Every hour at minute ".concat(a):"*"===n&&"*"===l&&"*"===r?"Daily at ".concat(s,":").concat(a.padStart(2,"0")):"*"===n&&"*"===l&&"*"!==r?"Every ".concat({0:"Sunday",1:"Monday",2:"Tuesday",3:"Wednesday",4:"Thursday",5:"Friday",6:"Saturday"}[r]||r," at ").concat(s,":").concat(a.padStart(2,"0")):"*"===l&&"*"===r?"Monthly on day ".concat(n," at ").concat(s,":").concat(a.padStart(2,"0")):e}(a.cron_expression)}),(0,s.jsx)("p",{className:"text-[10px] text-amber-500 dark:text-amber-500 font-mono mt-1",children:a.cron_expression})]}),a.cron_expression&&(0,s.jsxs)("div",{className:"p-2 bg-blue-50 dark:bg-blue-900/20 rounded-lg",children:[(0,s.jsx)("p",{className:"text-[10px] text-blue-600 dark:text-blue-400 font-medium mb-1",children:"Available variables:"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1",children:["current_time","current_date","trigger_type","cron"].map(e=>(0,s.jsx)("span",{className:"px-1.5 py-0.5 bg-blue-100 dark:bg-blue-800/40 text-blue-700 dark:text-blue-300 text-[10px] rounded font-mono",children:"{{".concat(e,"}}")},e))})]})]})]})},condition:function(e){let{data:t,variables:a,onUpdate:l}=e,{update:r,updateMultiple:i}=L(t,l),[c,d]=(0,n.useState)(t.mode||"simple"),u=e=>{if(d(e),"expression"===e){let e=t.field||"",a=t.operator||"",s=t.value||"",n="";if(e&&a)switch(a){case"equals":default:n="".concat(e,' == "').concat(s,'"');break;case"not_equals":n="".concat(e,' != "').concat(s,'"');break;case"contains":n="".concat(e,' contains "').concat(s,'"');break;case"not_contains":n="".concat(e,' not_contains "').concat(s,'"');break;case"starts_with":n="".concat(e,' starts_with "').concat(s,'"');break;case"ends_with":n="".concat(e,' ends_with "').concat(s,'"');break;case"not_empty":n="".concat(e,' != ""');break;case"empty":n="".concat(e,' == ""');break;case"greater_than":n="".concat(e,' > "').concat(s,'"');break;case"less_than":n="".concat(e,' < "').concat(s,'"')}i({mode:"expression",expression:n})}else i({mode:"simple"})};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 p-0.5 bg-gray-100 dark:bg-gray-800 rounded-lg",children:[(0,s.jsx)("button",{onClick:()=>u("simple"),className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md transition-all ".concat("simple"===c?"bg-white dark:bg-gray-700 text-gray-800 dark:text-gray-200 shadow-sm":"text-gray-400 hover:text-gray-600"),children:"Simple"}),(0,s.jsx)("button",{onClick:()=>u("expression"),className:"flex-1 px-3 py-1.5 text-xs font-medium rounded-md transition-all ".concat("expression"===c?"bg-white dark:bg-gray-700 text-gray-800 dark:text-gray-200 shadow-sm":"text-gray-400 hover:text-gray-600"),children:"Expression"})]}),"simple"===c?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(W,{label:"Field",children:[(0,s.jsx)("input",{type:"text",value:t.field||"",onChange:e=>r("field",e.target.value),placeholder:"e.g. email, country, form_name",className:"input-field"}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Type the exact field name from your form submission"})]}),(0,s.jsx)(W,{label:"Operator",children:(0,s.jsxs)("select",{value:t.operator||"",onChange:e=>r("operator",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Select..."}),o.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]})}),t.operator&&!["not_empty","empty"].includes(t.operator)&&(0,s.jsx)(W,{label:"Value",children:(0,s.jsx)("input",{type:"text",value:t.value||"",onChange:e=>r("value",e.target.value),placeholder:"Compare value...",className:"input-field"})})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(W,{label:"Condition Expression",children:(0,s.jsx)("textarea",{value:t.expression||"",onChange:e=>r("expression",e.target.value),placeholder:'// Examples:\nemail != ""\ncountry == "Azerbaijan"\nform_name == "Get Quote"\npostal_code starts_with "AZ"\n\n// Combine with && (and) || (or)\nemail != "" && country == "Turkey"\nform_name == "Contact" || form_name == "Quote"',rows:8,className:"input-field resize-none text-xs font-mono leading-relaxed"})}),(0,s.jsxs)("div",{className:"text-[10px] text-gray-400 space-y-1",children:[(0,s.jsx)("p",{className:"font-medium text-gray-500",children:"Operators:"}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-x-2 gap-y-0.5 font-mono",children:[(0,s.jsx)("span",{children:"== equals"}),(0,s.jsx)("span",{children:"!= not equals"}),(0,s.jsx)("span",{children:"contains"}),(0,s.jsx)("span",{children:"not_contains"}),(0,s.jsx)("span",{children:"starts_with"}),(0,s.jsx)("span",{children:"ends_with"}),(0,s.jsx)("span",{children:"> greater than"}),(0,s.jsx)("span",{children:"< less than"})]}),(0,s.jsxs)("p",{className:"mt-1",children:["Use ",(0,s.jsx)("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"&&"})," for AND, ",(0,s.jsx)("code",{className:"bg-gray-100 dark:bg-gray-800 px-1 rounded",children:"||"})," for OR"]})]})]})]})},switch:function(e){let{data:t,variables:a,onUpdate:n}=e,{update:l}=L(t,n),r=t.cases||[],o=e=>{l("cases",r.filter((t,a)=>a!==e))},i=(e,t,a)=>{l("cases",r.map((s,n)=>n===e?{...s,[t]:a}:s))};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)(W,{label:"Switch on field",children:[(0,s.jsx)("input",{type:"text",value:t.field||"",onChange:e=>l("field",e.target.value),placeholder:"e.g. country, form_id, source",className:"input-field"}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Type the exact field name from your form submission"})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("label",{className:"text-xs font-medium text-gray-500",children:"Cases"}),(0,s.jsxs)("button",{onClick:()=>{l("cases",[...r,{value:"",label:"",operator:"equals"}])},className:"flex items-center gap-1 text-xs text-[#F07B6E] hover:text-[#e06555]",children:[(0,s.jsx)(T.Z,{className:"w-3 h-3"})," Add"]})]}),(0,s.jsx)("div",{className:"space-y-2",children:r.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-center gap-1.5 p-2 bg-gray-50 dark:bg-gray-800 rounded-lg",children:[(0,s.jsx)("span",{className:"text-[10px] font-bold text-purple-500 w-4",children:t+1}),(0,s.jsxs)("select",{value:e.operator,onChange:e=>i(t,"operator",e.target.value),className:"input-field !py-1 !text-xs !w-24 flex-shrink-0",children:[(0,s.jsx)("option",{value:"equals",children:"Equals"}),(0,s.jsx)("option",{value:"contains",children:"Contains"}),(0,s.jsx)("option",{value:"starts_with",children:"Starts with"}),(0,s.jsx)("option",{value:"not_empty",children:"Not empty"})]}),(0,s.jsx)("input",{value:e.value,onChange:e=>i(t,"value",e.target.value),placeholder:"Value",className:"input-field !py-1 !text-xs flex-1"}),(0,s.jsx)("input",{value:e.label,onChange:e=>i(t,"label",e.target.value),placeholder:"Label",className:"input-field !py-1 !text-xs !w-16"}),(0,s.jsx)("button",{onClick:()=>o(t),className:"p-1 text-gray-400 hover:text-red-500",children:(0,s.jsx)(V.Z,{className:"w-3 h-3"})})]},t))}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-2",children:'Unmatched values go to the "Else" output.'})]})]})},filter:function(e){let{data:t,variables:a,onUpdate:n}=e,{update:l}=L(t,n);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 bg-emerald-50 dark:bg-emerald-900/20 p-2 rounded-lg",children:"Data continues only if this condition passes. Otherwise execution stops here."}),(0,s.jsxs)(W,{label:"Field",children:[(0,s.jsx)("input",{type:"text",value:t.field||"",onChange:e=>l("field",e.target.value),placeholder:"e.g. email, country, form_name",className:"input-field"}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Type the exact field name from your form submission"})]}),(0,s.jsx)(W,{label:"Operator",children:(0,s.jsxs)("select",{value:t.operator||"",onChange:e=>l("operator",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Select..."}),o.map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))]})}),t.operator&&!["not_empty","empty"].includes(t.operator)&&(0,s.jsx)(W,{label:"Value",children:(0,s.jsx)("input",{type:"text",value:t.value||"",onChange:e=>l("value",e.target.value),placeholder:"Compare value...",className:"input-field"})})]})},loop:function(e){let{data:t,variables:a,onUpdate:n}=e,{update:l}=L(t,n);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 bg-cyan-50 dark:bg-cyan-900/20 p-2 rounded-lg",children:'Iterate over a list. The "Each" output runs for every item, "Done" runs after all items.'}),(0,s.jsx)(W,{label:"List Source",children:(0,s.jsxs)("select",{value:t.mode||"variable",onCh
1ange:e=>l("mode",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"variable",children:"From variable (JSON array)"}),(0,s.jsx)("option",{value:"static",children:"Static items"}),(0,s.jsx)("option",{value:"range",children:"Numeric range"})]})}),"variable"===t.mode&&(0,s.jsxs)(W,{label:"Variable Name",children:[(0,s.jsxs)("select",{value:t.listField||"",onChange:e=>l("listField",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Select variable..."}),a.map(e=>(0,s.jsx)("option",{value:e,children:e},e))]}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Must contain a JSON array or comma-separated values."})]}),"static"===t.mode&&(0,s.jsx)(W,{label:"Items (one per line)",children:(0,s.jsx)("textarea",{value:(t.items||[]).join("\n"),onChange:e=>l("items",e.target.value.split("\n").filter(Boolean)),placeholder:"item1 item2 item3",rows:4,className:"input-field resize-none text-xs font-mono"})}),"range"===t.mode&&(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(W,{label:"Start",className:"flex-1",children:(0,s.jsx)("input",{type:"number",value:t.rangeStart||0,onChange:e=>l("rangeStart",parseInt(e.target.value)||0),className:"input-field"})}),(0,s.jsx)(W,{label:"End",className:"flex-1",children:(0,s.jsx)("input",{type:"number",value:t.rangeEnd||10,onChange:e=>l("rangeEnd",parseInt(e.target.value)||10),className:"input-field"})})]}),(0,s.jsx)(W,{label:"Loop Variables",children:(0,s.jsx)("div",{className:"flex flex-wrap gap-1",children:["loop_index","loop_item","loop_count","loop_first","loop_last"].map(e=>(0,s.jsx)("span",{className:"px-1.5 py-0.5 bg-cyan-50 dark:bg-cyan-900/30 text-cyan-600 text-[10px] rounded font-mono",children:"{{".concat(e,"}}")},e))})})]})},merge:function(e){let{data:t,onUpdate:a}=e,{update:n}=L(t,a);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 bg-indigo-50 dark:bg-indigo-900/20 p-2 rounded-lg",children:"Waits for all incoming branches to complete, then combines their data."}),(0,s.jsx)(W,{label:"Merge Mode",children:(0,s.jsxs)("select",{value:t.mode||"combine",onChange:e=>n("mode",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"combine",children:"Combine — merge all outputs into one object"}),(0,s.jsx)("option",{value:"append",children:"Append — collect outputs as array"}),(0,s.jsx)("option",{value:"wait",children:"Wait only — just synchronize, pass variables through"})]})}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400",children:"Connect multiple branches to this node's input handles. Execution continues only after all branches arrive."})]})},set:function(e){let{data:t,variables:a,onUpdate:n}=e,{update:l}=L(t,n),r=t.mappings||[],o=e=>l("mappings",r.filter((t,a)=>a!==e)),i=(e,t,a)=>{l("mappings",r.map((s,n)=>n===e?{...s,[t]:a}:s))};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 bg-teal-50 dark:bg-teal-900/20 p-2 rounded-lg",children:"Set or transform variables for downstream nodes."}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,s.jsx)("label",{className:"text-xs font-medium text-gray-500",children:"Mappings"}),(0,s.jsxs)("button",{onClick:()=>l("mappings",[...r,{key:"",value:"",mode:"static"}]),className:"flex items-center gap-1 text-xs text-[#F07B6E] hover:text-[#e06555]",children:[(0,s.jsx)(T.Z,{className:"w-3 h-3"})," Add"]})]}),(0,s.jsx)("div",{className:"space-y-2",children:r.map((e,t)=>(0,s.jsxs)("div",{className:"p-2 bg-gray-50 dark:bg-gray-800 rounded-lg space-y-1.5",children:[(0,s.jsxs)("div",{className:"flex gap-1.5",children:[(0,s.jsx)("input",{value:e.key,onChange:e=>i(t,"key",e.target.value),placeholder:"Variable name",className:"input-field !py-1 !text-xs flex-1"}),(0,s.jsxs)("select",{value:e.mode,onChange:e=>i(t,"mode",e.target.value),className:"input-field !py-1 !text-xs !w-24",children:[(0,s.jsx)("option",{value:"static",children:"Static"}),(0,s.jsx)("option",{value:"expression",children:"Expression"})]}),(0,s.jsx)("button",{onClick:()=>o(t),className:"p-1 text-gray-400 hover:text-red-500",children:(0,s.jsx)(V.Z,{className:"w-3 h-3"})})]}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{value:e.value,onChange:e=>i(t,"value",e.target.value),placeholder:"expression"===e.mode?"concat(first_name, ' ', last_name)":"{{client_name}}",className:"input-field !py-1 !text-xs pr-7"}),(0,s.jsx)(B,{variables:a,onInsert:a=>i(t,"value",e.value+"{{".concat(a,"}}"))})]})]},t))}),r.length>0&&(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-2",children:"Expressions: concat(), upper(), lower(), trim(), default()"})]})]})},code:function(e){let{data:t,variables:a,onUpdate:l}=e,{update:r}
1=L(t,l),[o,i]=(0,n.useState)(!1),c=t.language||"expression",d={expression:"// Set variables for next nodes\nfull_name = concat(first_name, ' ', last_name)\nstatus = \"processed\"\nemail_lower = lower(client_email)",json:'{\n  "full_name": "{{first_name}} {{last_name}}",\n  "processed": true\n}',javascript:'// Available: variables, nodes, input\n// Must return an object\nconst calc = JSON.parse(nodes["NODE_ID"].response_body.response.calculate);\nreturn {\n  total_price: calc.totalPrice,\n  products_price: calc.productsPrice\n};'};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 bg-slate-50 dark:bg-slate-900/20 p-2 rounded-lg",children:{expression:"Each line: key = value. Supports concat(), upper(), lower(), trim().",json:"Output a JSON object. {{variables}} are resolved before parsing.",javascript:"Full JavaScript. Access variables, nodes, input. Must return an object. 10s timeout."}[c]}),(0,s.jsx)(W,{label:"Language",children:(0,s.jsxs)("select",{value:c,onChange:e=>r("language",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"expression",children:"Expression"}),(0,s.jsx)("option",{value:"json",children:"JSON Output"}),(0,s.jsx)("option",{value:"javascript",children:"JavaScript"})]})}),(0,s.jsx)(W,{label:"Code",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("textarea",{value:t.code||"",onChange:e=>r("code",e.target.value),placeholder:d[c],rows:8,className:"input-field resize-none text-xs font-mono leading-relaxed pr-8"}),(0,s.jsx)("button",{type:"button",onClick:()=>i(!0),title:"Open editor",className:"absolute top-1.5 right-1.5 p-1 rounded hover:bg-slate-200 dark:hover:bg-slate-700 text-slate-400 hover:text-slate-700 dark:hover:text-slate-200",children:(0,s.jsx)(K.Z,{className:"w-3.5 h-3.5"})})]})}),a.length>0&&(0,s.jsx)(W,{label:"Available Variables",children:(0,s.jsx)("div",{className:"flex flex-wrap gap-1",children:a.map(e=>(0,s.jsx)("span",{className:"px-1.5 py-0.5 bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-300 text-[10px] rounded font-mono cursor-pointer hover:bg-[#F07B6E]/10 hover:text-[#F07B6E]",onClick:()=>r("code",(t.code||"")+"{{".concat(e,"}}")),children:e},e))})}),o&&(0,s.jsx)("div",{className:"fixed inset-0 z-[1000] bg-black/70 flex items-center justify-center p-6",children:(0,s.jsxs)("div",{className:"bg-white dark:bg-slate-900 rounded-lg shadow-2xl w-full max-w-5xl h-[85vh] flex flex-col",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 border-b border-slate-200 dark:border-slate-700",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",children:"Code Editor"}),(0,s.jsxs)("select",{value:c,onChange:e=>r("language",e.target.value),className:"text-xs px-2 py-1 border border-slate-300 dark:border-slate-600 rounded bg-white dark:bg-slate-800",children:[(0,s.jsx)("option",{value:"expression",children:"Expression"}),(0,s.jsx)("option",{value:"json",children:"JSON Output"}),(0,s.jsx)("option",{value:"javascript",children:"JavaScript"})]})]}),(0,s.jsx)("button",{onClick:()=>i(!1),className:"p-1.5 rounded hover:bg-slate-100 dark:hover:bg-slate-800",children:(0,s.jsx)(M.Z,{className:"w-4 h-4"})})]}),(0,s.jsx)("textarea",{value:t.code||"",onChange:e=>r("code",e.target.value),placeholder:d[c],spellCheck:!1,className:"flex-1 w-full p-4 bg-slate-950 text-slate-100 font-mono text-sm leading-relaxed resize-none outline-none rounded-b-lg"})]})})]})},"action:send_email":function(e){let{data:t,variables:a,projectId:l,onUpdate:r}=e,{update:o,updateMultiple:i,insertVariable:c}
1=L(t,r),[d,u]=(0,n.useState)(null),[x,p]=(0,n.useState)([]),[m,h]=(0,n.useState)([]),[g,b]=(0,n.useState)(!1);return(0,n.useEffect)(()=>{null===d&&(b(!0),Promise.all([fetch("/api/v1/integrations/email/settings?project_id=".concat(l),{credentials:"include"}).then(e=>e.ok?e.json():null).catch(()=>null),fetch("/api/v1/modules/app/sections?project_id=".concat(l),{credentials:"include"}).then(e=>e.ok?e.json():null).catch(()=>null)]).then(e=>{let[a,s]=e;if(a){u(a.configured||!1),p(a.accounts||[]);let e=a.accounts||[];if(e.length>0){let a=t.account_id&&e.some(e=>e.id===t.account_id);t.account_id&&a||o("account_id",(e.find(e=>e.is_default)||e[0]).id)}}else u(!1);Array.isArray(s)&&h(s.filter(e=>(e.tags||[]).some(e=>"email"===e.toLowerCase())).map(e=>({id:e.id,name:e.name}))),b(!1)}))},[l]),(0,s.jsxs)(s.Fragment,{children:[!1===d&&!g&&(0,s.jsxs)("div",{className:"flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg",children:[(0,s.jsx)(q.Z,{className:"w-4 h-4 text-amber-500 mt-0.5 flex-shrink-0"}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs font-medium text-amber-800 dark:text-amber-200",children:"No email integration"}),(0,s.jsxs)("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-0.5",children:["Connect email in ",(0,s.jsx)("a",{href:"/manage/integrations/email",className:"underline font-medium",children:"Integrations → Email"})]})]})]}),!0===d&&x.length>0&&(0,s.jsx)(W,{label:"Send From",children:(0,s.jsxs)("select",{value:t.account_id||"",onChange:e=>o("account_id",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Default account"}),x.map(e=>(0,s.jsxs)("option",{value:e.id,children:[e.from_email,e.is_default?" (default)":""]},e.id))]})}),(0,s.jsxs)(W,{label:"Email Template",children:[(0,s.jsxs)("select",{value:t.template_id||0,onChange:e=>{let t=parseInt(e.target.value);i({template_id:t,wrapper:!(t>0)})},className:"input-field",children:[(0,s.jsx)("option",{value:0,children:"No template (raw body)"}),m.map(e=>(0,s.jsx)("option",{value:e.id,children:e.name},e.id))]}),0===m.length&&!g&&(0,s.jsxs)("p",{className:"text-xs text-gray-400 mt-1",children:['Create sections with tag "email" in ',(0,s.jsx)("a",{href:"/manage/app/sections",className:"underline",children:"App → Sections"})]})]}),(0,s.jsx)(W,{label:"To",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:t.to||"",onChange:e=>o("to",e.target.value),placeholder:"{{client_email}}",className:"input-field pr-8"}),(0,s.jsx)(B,{variables:a,onInsert:e=>c("to",e)})]})}),(0,s.jsx)(W,{label:"Subject",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:t.subject||"",onChange:e=>o("subject",e.target.value),placeholder:"Thank you, {{client_name}}!",className:"input-field pr-8"}),(0,s.jsx)(B,{variables:a,onInsert:e=>c("subject",e)})]})}),(0,s.jsx)(W,{label:t.template_id>0?"Fallback Body":"Email Body",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("textarea",{value:t.body||"",onChange:e=>o("body",e.target.value),placeholder:"Write your email content...",rows:5,className:"input-field resize-none text-sm font-mono"}),(0,s.jsx)(B,{variables:a,onInsert:e=>c("body",e),position:"top"})]})}),!t.template_id&&(0,s.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:!1!==t.wrapper,onChange:e=>o("wrapper",e.target.checked),className:"w-4 h-4 rounded border-gray-300 text-[#F07B6E] focus:ring-[#F07B6E]"}),(0,s.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-400",children:"Wrap in branded email layout"})]})]})},"action:webhook":function(e){let{data:t,variables:a,onUpdate:n}=e,{update:l,insertVariable:r}=L(t,n);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(W,{label:"Method",children:(0,s.jsxs)("select",{value:t.method||"POST",onChange:e=>l("method",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"GET",children:"GET"}),(0,s.jsx)("option",{value:"POST",children:"POST"}),(0,s.jsx)("option",{value:"PUT",children:"PUT"}),(0,s.jsx)("option",{value:"PATCH",children:"PATCH"}),(0,s.jsx)("option",{value:"DELETE",children:"DELETE"})]})}),(0,s.jsx)(W,{label:"URL",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"url",value:t.url||"",onChange:e=>l("url",e.target.value),placeholder:"https://...",className:"input-field pr-8"}),(0,s.jsx)(B,{variables:a,onInsert:e=>r("url",e)})]})})]})},"action:delay":function(e){let{data:t,onUpdate:a}=e,{update:n}=L(t,a);return(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(W,{label:"Duration",className:"flex-1",children:(0,s.jsx)("input",{type:"number",min:1,value:t.duration||5,onChange:e=>n("duration",parseInt(e.target.value)||1),className:"input-field"})}),(0,s.jsx)(W,{label:"Unit",className:"flex-1",children:(0,s.jsxs)("select",{value:t.unit||"minutes",onChange:e=>n("unit",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"minutes",children:"Minutes"}),(0,s.jsx)("option",{value:"hours",children:"Hours"}),(0,s.jsx)("option",{value:"days",children:"Days"})]})})]})},"action:update_record":function(e){let{data:t,variables:a,projectId:l,onUpdate:r}=e,{update:o,updateMultiple:i}
1=L(t,r),[c,d]=(0,n.useState)([]),[u,x]=(0,n.useState)([]),[p,m]=(0,n.useState)(!1),[h,g]=(0,n.useState)(!1),[b,v]=(0,n.useState)(!1),[f,y]=(0,n.useState)(""),[N,k]=(0,n.useState)(!1),w=t.field_mappings||[];(0,n.useEffect)(()=>{l&&(m(!0),fetch("/api/v1/modules/automations/tables?project_id=".concat(l),{credentials:"include"}).then(e=>e.ok?e.json():null).then(e=>{(null==e?void 0:e.tables)&&d(e.tables)}).catch(()=>{}).finally(()=>m(!1)))},[l]),(0,n.useEffect)(()=>{if(!t.table||!l){x([]);return}g(!0),fetch("/api/v1/modules/automations/tables/".concat(t.table,"?project_id=").concat(l),{credentials:"include"}).then(e=>e.ok?e.json():null).then(e=>{(null==e?void 0:e.columns)&&x(e.columns)}).catch(()=>x([])).finally(()=>g(!1))},[t.table,l]);let _=(e,a,s)=>{let n=[...w];n[e]={...n[e],[a]:s},i({...t,field_mappings:n})},C=e=>{i({...t,field_mappings:w.filter((t,a)=>a!==e)})},E=f?c.filter(e=>e.toLowerCase().includes(f.toLowerCase())):c,S=u.filter(e=>"id"!==e.column_name&&"created_at"!==e.column_name&&"updated_at"!==e.column_name),I=e=>e.includes("character")||e.includes("text")?"text":e.includes("integer")||e.includes("bigint")||e.includes("smallint")?"int":e.includes("numeric")||e.includes("decimal")||e.includes("double")||e.includes("real")?"num":e.includes("boolean")?"bool":e.includes("json")?"json":e.includes("timestamp")?"time":e.includes("date")?"date":e.includes("uuid")?"uuid":e.split(" ")[0];return(0,s.jsxs)("div",{className:"space-y-4",children:[(0,s.jsx)(W,{label:"Table",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("div",{className:"flex items-center gap-1.5",children:(0,s.jsxs)("div",{className:"relative flex-1",children:[(0,s.jsx)(j.Z,{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-gray-400"}),(0,s.jsx)("input",{type:"text",value:t.table||"",onChange:e=>o("table",e.target.value),onFocus:()=>v(!0),placeholder:"Enter or select table name...",className:"input-field pl-8 pr-8 font-mono text-xs"}),p?(0,s.jsx)(J.Z,{className:"absolute right-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-gray-300 animate-spin"}):(0,s.jsx)("button",{onClick:()=>v(!b),className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-1 rounded hover:bg-gray-100 dark:hover:bg-gray-700 text-gray-400",children:(0,s.jsx)(G.Z,{className:"w-3.5 h-3.5"})})]})}),b&&c.length>0&&(0,s.jsxs)("div",{className:"absolute z-50 left-0 right-0 top-full mt-1 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg overflow-hidden",children:[(0,s.jsx)("div",{className:"p-1.5 border-b border-gray-100 dark:border-gray-700",children:(0,s.jsx)("input",{type:"text",value:f,onChange:e=>y(e.target.value),placeholder:"Search tables...",className:"w-full px-2 py-1.5 text-xs bg-gray-50 dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded focus:outline-none focus:border-[#F07B6E]",autoFocus:!0})}),(0,s.jsxs)("div",{className:"max-h-48 overflow-y-auto p-1",children:[E.map(e=>(0,s.jsxs)("button",{onClick:()=>{o("table",e),v(!1),y("")},className:"w-full text-left px-2.5 py-2 text-xs rounded transition-colors flex items-center gap-2 ".concat(t.table===e?"bg-[#F07B6E]/10 text-[#F07B6E] font-medium":"text-gray-700 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-700"),children:[(0,s.jsx)(G.Z,{className:"w-3 h-3 text-gray-400 flex-shrink-0"}),(0,s.jsx)("span",{className:"font-mono",children:e})]},e)),0===E.length&&(0,s.jsx)("p",{className:"text-[10px] text-gray-400 text-center py-2",children:"No tables match"})]})]})]})}),b&&(0,s.jsx)("div",{className:"fixed inset-0 z-40",onClick:()=>{v(!1),y("")}}),t.table&&(0,s.jsxs)("div",{className:"flex gap-2 p-2.5 bg-blue-50 dark:bg-blue-900/15 border border-blue-200 dark:border-blue-800 rounded-lg",children:[(0,s.jsx)(H.Z,{className:"w-3.5 h-3.5 text-blue-500 mt-0.5 flex-shrink-0"}),(0,s.jsx)("p",{className:"text-[11px] text-blue-600 dark:text-blue-400 leading-relaxed",children:"contacts"===t.table?"Finds existing contact by email. If found → updates. If not → creates new.":"submissions"===t.table?"Creates new submission with trigger data as JSON. Links contact_id from previous nodes.":'If record ID is available → updates. Otherwise → creates new record in "'.concat(t.table,'".')})]}),t.table&&(0,s.jsxs)(s.Fragment,{children:[h?(0,s.jsxs)("div",{className:"flex items-center gap-2 py-2 text-xs text-gray-400",children:[(0,s.jsx)(J.Z,{className:"w-3.5 h-3.5 animate-spin"})," Loading columns..."]}):S.length>0?(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center gap-1.5 mb-2",children:[(0,s.jsx)(Y.Z,{className:"w-3.5 h-3.5 text-gray-400"}),(0,s.jsxs)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-400",children:["Columns (",S.length,")"]})]}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1 mb-3",children:S.map(e=>(0,s.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 bg-gray-50 dark:bg-gray-800 border border-gray-100 dark:border-gray-700 rounded text-[10px] font-mono text-gray-600 dark:text-gray-400",children:[e.column_name,(0,s.jsx)("span",{className:"text-gray-300 dark:text-gray-600",children:I(e.data_type)})]},e.column_name))})]}):null,(0,s.jsx)(W,{label:"Field",children:S.length>0?(0,s.jsxs)("select",{value:t.field||"",onChange:e=>o("field",e.target.value),className:"input-field font-mono text-xs",children:[(0,s.jsx)("option",{value:"",children:"Select column..."}),S.map(e=>(0,s.jsxs)("option",{value:e.column_name,children:[e.column_name," (",I(e.data_type),")"]},e.column_name))]}):(0,s.jsx)("input",{type:"text",value:t.field||"",onChange:e=>o("field",e.target.value),placeholder:"column_name",className:"input-field font-mono text-xs"})}),t.field&&(0,s.jsx)(W,{label:"Value",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:t.value||"",onChange:e=>o("value",e.target.value),placeholder:"Enter value or {{variable}}",className:"input-field pr-8 text-xs"}),(0,s.jsx)(B,{variables:a,onInsert:e=>{o("value",(t.value||"")+"{{".concat(e,"}}"))}})]})}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("button",{onClick:()=>k(!N),className:"w-full flex items-center gap-1.5 text-xs font-medium text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300 transition-colors py-1",children:[N?(0,s.jsx)(X.Z,{className:"w-3.5 h-3.5"}):(0,s.jsx)(Q.Z,{className:"w-3.5 h-3.5"}),"Additional Fields (",w.length,")"]}),N&&(0,s.jsxs)("div",{className:"mt-2 space-y-2",children:[w.map((e,t)=>(0,s.jsxs)("div",{className:"flex items-start gap-1.5 p-2 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-100 dark:border-gray-800",children:[(0,s.jsxs)("div",{className:"flex-1 space-y-1.5",children:[S.length>0?(0,s.jsxs)("select",{value:e.field,onChange:e=>_(t,"field",e.target.value),className:"input-field text-xs font-mono",children:[(0,s.jsx)("option",{value:"",children:"Column..."}),S.map(e=>(0,s.jsxs)("option",{value:e.column_name,children:[e.column_name," (",I(e.data_type),")"]},e.column_name))]}):(0,s.jsx)("input",{type:"text",value:e.field,onChange:e=>_(t,"field",e.target.value),placeholder:"column_name",className:"input-field text-xs font-mono"}),(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:e.value,onChange:e=>_(t,"value",e.target.value),placeholder:"Value or {{variable}}",className:"input-field text-xs pr-7"}),(0,s.jsx)(B,{variables:a,onInsert:a=>{_(t,"value",e.value+"{{".concat(a,"}}"))}})]})]}),(0,s.jsx)("button",{onClick:()=>C(t),className:"p-1 mt-1 rounded hover:bg-red-50 dark:hover:bg-red-900/20 text-gray-300 hover:text-red-500 transition-colors",children:(0,s.jsx)(V.Z,{className:"w-3.5 h-3.5"})})]},t)),(0,s.jsxs)("button",{onClick:()=>{i({...t,field_mappings:[...w,{field:"",value:""}]})},className:"w-full flex items-center justify-center gap-1.5 p-2 border border-dashed border-gray-200 dark:border-gray-700 rounded-lg text-xs text-gray-400 hover:text-[#F07B6E] hover:border-[#F07B6E] transition-colors",children:[(0,s.jsx)(T.Z,{className:"w-3 h-3"})," Add field mapping"]})]})]})]}),t.table&&a.length>0&&(0,s.jsxs)("div",{className:"pt-2 border-t border-gray-100 dark:border-gray-800",children:[(0,s.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-400 mb-2",children:"Available Variables"}),(0,s.jsx)("div",{className:"flex flex-wrap gap-1",children:a.map(e=>(0,s.jsx)("span",{className:"px-1.5 py-0.5 bg-gray-100 dark:bg-gray-800 text-[10px] font-mono text-gray-500 dark:text-gray-400 rounded",children:"{{".concat(e,"}}")},e))})]})]})},"action:reply_in_chat":function(e){var t;let{data:a,variables:n,onUpdate:l}=e,{update:r,insertVariable:o}=L(a,l);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("p",{className:"text-xs text-gray-500 bg-blue-50 dark:bg-blue-900/20 p-2 rounded-lg",children:"Posts a message into the visitor's chat as the assistant. Works with Chat triggers (session token is taken from the trigger)."}),(0,s.jsx)(W,{label:"Message",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("textarea",{value:a.message||"",onChange:e=>r("message",e.target.value),placeholder:"Thanks {{visitor_name}}, we received your request…",rows:5,className:"input-field resize-none text-sm"}),(0,s.jsx)(B,{variables:n,onInsert:e=>o("message",e),position:"top"})]})}),(0,s.jsxs)(W,{label:"Session token",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:null!==(t=a.session_token)&&void 0!==t?t:"{{session_token}}",onChange:e=>r("session_token",e.target.value),placeholder:"{{session_token}}",className:"input-field pr-8 font-mono text-xs"}),(0,s.jsx)(B,{variables:n,onInsert:e=>o("session_token",e)})]}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"Leave as is for chat triggers. Change only if the token comes from another node."})]})]})},"action:send_twilio":function(e){let{data:t,variables:a,projectId:l,onUpdate:r}=e,{update:o,insertVariable:i}
1=L(t,r),[c,d]=(0,n.useState)(null),[u,x]=(0,n.useState)("");return(0,n.useEffect)(()=>{fetch("/api/v1/integrations/twilio/settings?project_id=".concat(l),{credentials:"include"}).then(e=>e.ok?e.json():null).then(e=>{d(!!(e&&e.configured&&e.is_active)),x((null==e?void 0:e.phone_number)||"")}).catch(()=>d(!1))},[l]),(0,s.jsxs)(s.Fragment,{children:[!1===c&&(0,s.jsxs)("div",{className:"flex items-start gap-2 p-3 bg-amber-50 dark:bg-amber-900/20 border border-amber-200 dark:border-amber-800 rounded-lg",children:[(0,s.jsx)(q.Z,{className:"w-4 h-4 text-amber-500 mt-0.5 flex-shrink-0"}),(0,s.jsxs)("div",{children:[(0,s.jsx)("p",{className:"text-xs font-medium text-amber-800 dark:text-amber-200",children:"Twilio not connected or disabled"}),(0,s.jsxs)("p",{className:"text-xs text-amber-600 dark:text-amber-400 mt-0.5",children:["Configure it in ",(0,s.jsx)("a",{href:"/manage/integrations/twilio",className:"underline font-medium",children:"Integrations → Twilio"})]})]})]}),(0,s.jsxs)(W,{label:"Channel",children:[(0,s.jsxs)("select",{value:t.channel||"sms",onChange:e=>o("channel",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"sms",children:"SMS"}),(0,s.jsx)("option",{value:"whatsapp",children:"WhatsApp"})]}),u&&(0,s.jsxs)("p",{className:"text-[10px] text-gray-400 mt-1",children:["From: ",u]})]}),(0,s.jsx)(W,{label:"To (phone, with country code)",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("input",{type:"text",value:t.to||"",onChange:e=>o("to",e.target.value),placeholder:"+994501234567 or {{visitor_phone}}",className:"input-field pr-8"}),(0,s.jsx)(B,{variables:a,onInsert:e=>i("to",e)})]})}),(0,s.jsxs)(W,{label:"Message",children:[(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("textarea",{value:t.body||"",onChange:e=>o("body",e.target.value),placeholder:"New request from {{visitor_name}}: {{message}}",rows:5,className:"input-field resize-none text-sm"}),(0,s.jsx)(B,{variables:a,onInsert:e=>i("body",e),position:"top"})]}),"whatsapp"===t.channel&&(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"WhatsApp: outside a 24h customer window Twilio only delivers approved templates."})]})]})},"action:ai_generate":function(e){let{node:t,data:a,variables:l,projectId:r,onUpdate:o}=e,{update:i,insertVariable:c}
1=L(a,o),[d,u]=(0,n.useState)([]);(0,n.useEffect)(()=>{fetch("/api/v1/integrations/ai-agent/project-agents?project_id=".concat(r),{credentials:"include"}).then(e=>e.ok?e.json():[]).then(e=>u(Array.isArray(e)?e.filter(e=>!1!==e.is_active).map(e=>({slug:e.slug,name:e.name})):[])).catch(()=>u([]))},[r]);let x="{{nodes.".concat(t.id,".result}}");return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("p",{className:"text-xs text-gray-500 bg-violet-50 dark:bg-violet-900/20 p-2 rounded-lg",children:["Runs the prompt through your AI and stores the answer for later nodes as ",(0,s.jsx)("code",{className:"font-mono text-[10px]",children:x}),"."]}),(0,s.jsxs)(W,{label:"Agent (optional)",children:[(0,s.jsxs)("select",{value:a.agent_slug||"",onChange:e=>i("agent_slug",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"",children:"Project default provider (no agent prompt)"}),d.map(e=>(0,s.jsxs)("option",{value:e.slug,children:[e.name," (",e.slug,")"]},e.slug))]}),(0,s.jsx)("p",{className:"text-[10px] text-gray-400 mt-1",children:"An agent adds its knowledge prompt and model."})]}),(0,s.jsx)(W,{label:"Prompt",children:(0,s.jsxs)("div",{className:"relative",children:[(0,s.jsx)("textarea",{value:a.prompt||"",onChange:e=>i("prompt",e.target.value),placeholder:'Classify this visitor message as "sales", "support" or "other". Message: {{message}}',rows:6,className:"input-field resize-none text-sm"}),(0,s.jsx)(B,{variables:l,onInsert:e=>c("prompt",e),position:"top"})]})}),(0,s.jsxs)("div",{className:"flex gap-2",children:[(0,s.jsx)(W,{label:"Output",className:"flex-1",children:(0,s.jsxs)("select",{value:a.output||"text",onChange:e=>i("output",e.target.value),className:"input-field",children:[(0,s.jsx)("option",{value:"text",children:"Text"}),(0,s.jsx)("option",{value:"json",children:"JSON (keys become variables)"})]})}),(0,s.jsx)(W,{label:"Max tokens",className:"w-28",children:(0,s.jsx)("input",{type:"number",min:64,max:8192,value:a.max_tokens||1024,onChange:e=>i("max_tokens",parseInt(e.target.value)||1024),className:"input-field"})})]}),"json"===a.output&&(0,s.jsxs)("p",{className:"text-[10px] text-gray-400",children:["Ask for JSON in the prompt, e.g. ",(0,s.jsx)("code",{className:"font-mono",children:'{"category": "...", "priority": "..."}'}),". Then use ",(0,s.jsx)("code",{className:"font-mono",children:"{{nodes.".concat(t.id,".category}}")}),"."]})]})}};function ea(e){let{node:t,eventTypes:a,triggerEvent:n,projectId:r,onUpdate:o,onClose:i}=e,{type:c,data:d}=t,u=l[c],x=ee[c]||N.Z,p=a.find(e=>e.name===n),m=(null==p?void 0:p.variables)||[],h=c;"action"===c&&d.actionType&&(h="action:".concat(d.actionType));let g=et[h],b={node:t,data:d,variables:m,projectId:r,eventTypes:a,triggerEvent:n,onUpdate:o};return(0,s.jsxs)("div",{className:"jsx-5355b9485ef057d w-80 bg-white dark:bg-gray-900 border-l border-gray-200 dark:border-gray-700 flex flex-col overflow-hidden",children:[(0,s.jsxs)("div",{className:"jsx-5355b9485ef057d "+"flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700 ".concat(u.bg),children:[(0,s.jsxs)("div",{className:"jsx-5355b9485ef057d flex items-center gap-2",children:[(0,s.jsx)("div",{className:"jsx-5355b9485ef057d "+"w-7 h-7 rounded-lg flex items-center justify-center ".concat(u.icon," bg-white/80 dark:bg-gray-800/80"),children:(0,s.jsx)(x,{className:"jsx-5355b9485ef057d w-4 h-4"})}),(0,s.jsxs)("span",{className:"jsx-5355b9485ef057d text-sm font-semibold text-gray-800 dark:text-gray-200",children:[u.label," Properties"]})]}),(0,s.jsx)("button",{onClick:i,className:"jsx-5355b9485ef057d p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-700",children:(0,s.jsx)(M.Z,{className:"w-4 h-4 text-gray-400"})})]}),(0,s.jsxs)("div",{className:"jsx-5355b9485ef057d flex-1 overflow-y-auto p-4 space-y-4",children:["action"===c&&(0,s.jsx)($,{data:d,onUpdate:o}),g?(0,s.jsx)(g,{...b,className:"jsx-5355b9485ef057d "+(b&&null!=b.className&&b.className||"")}):"action"!==c||d.actionType?(0,s.jsx)("p",{className:"jsx-5355b9485ef057d text-xs text-gray-400 text-center py-4",children:"No configuration available"}):(0,s.jsx)("p",{className:"jsx-5355b9485ef057d text-xs text-gray-400 text-center py-4",children:"Select an action type above"})]}),(0,s.jsx)(D(),{id:"5355b9485ef057d",children:".input-field{width:100%;padding:.5rem .75rem;font-size:.8125rem;border:1px solid#e5e7eb;-webkit-border-radius:.5rem;-moz-border-radius:.5rem;border-radius:.5rem;background:white;color:#111827;-webkit-transition:border-color.15s;-moz-transition:border-color.15s;-o-transition:border-color.15s;transition:border-color.15s}.input-field:focus{outline:none;border-color:#F07B6E;-webkit-box-shadow:0 0 0 2px rgba(240,123,110,.15);-moz-box-shadow:0 0 0 2px rgba(240,123,110,.15);box-shadow:0 0 0 2px rgba(240,123,110,.15)}.dark .input-field{background:#1f2937;border-color:#374151;color:#f3f4f6}"})]})}var es=a(6315),en=a(61883),el=a(94303),er=a(42587),eo=a(6991);function ei(e,t){switch(t.type){case"SET_ALL":return{...e,nodes:t.nodes,edges:t.edges,selectedNodeId:null,connecting:null};case"ADD_NODE":return{...e,nodes:[...e.nodes,t.node],selectedNodeId:t.node.id};case"MOVE_NODE":return{...e,nodes:e.nodes.map(e=>e.id===t.nodeId?{...e,position:{x:t.x,y:t.y}}:e)};case"DELETE_NODE":return{...e,nodes:e.nodes.filter(e=>e.id!==t.nodeId),edges:e.edges.filter(e=>e.source!==t.nodeId&&e.target!==t.nodeId),selectedNodeId:null};case"UPDATE_NODE_DATA":return{...e,nodes:e.nodes.map(e=>e.id===t.nodeId?{...e,data:t.data}:e)};case"ADD_EDGE":return e.edges.some(e=>e.source===t.edge.source&&e.target===t.edge.target&&e.sourceHandle===t.edge.sourceHandle)?{...e,connecting:null}:{...e,edges:[...e.edges,t.edge],connecting:null};case"DELETE_EDGE":return{...e,edges:e.edges.filter(e=>e.id!==t.edgeId)};case"SET_SELECTED":return{...e,selectedNodeId:t.nodeId};case"SET_VIEWPORT":return{...e,viewport:t.viewport};case"START_CONNECTING":return{...e,connecting:{sourceId:t.sourceId,handleType:t.handleType}};
1case"FINISH_CONNECTING":{if(!e.connecting||e.connecting.sourceId===t.targetId)return{...e,connecting:null};let a=e.nodes.find(e=>e.id===t.targetId);if(!a||"trigger"===a.type||e.edges.some(a=>a.source===e.connecting.sourceId&&a.target===t.targetId&&a.sourceHandle===e.connecting.handleType))return{...e,connecting:null};let s={id:"edge-".concat(Date.now()),source:e.connecting.sourceId,target:t.targetId,sourceHandle:e.connecting.handleType,label:""};return{...e,edges:[...e.edges,s],connecting:null}}case"CANCEL_CONNECTING":return{...e,connecting:null};default:return e}}let ec={nodes:[],edges:[],selectedNodeId:null,viewport:{x:0,y:0,zoom:1},connecting:null};function ed(e){let{name:t,onChange:a}=e,[l,r]=(0,n.useState)(!1),[o,i]=(0,n.useState)(t),c=(0,n.useRef)(null),d=(0,n.useRef)(!1),u=()=>{if(!d.current)return;d.current=!1;let e=o.trim();e&&e!==t&&(null==a||a(e)),r(!1)},x=()=>{d.current=!1,i(t),r(!1)};return a?l?(0,s.jsx)("input",{ref:c,type:"text",value:o,autoFocus:!0,onChange:e=>i(e.target.value),onBlur:u,onKeyDown:e=>{"Enter"===e.key&&u(),"Escape"===e.key&&x()},placeholder:"Automation name",className:"text-sm font-semibold text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-800 border border-[#F07B6E] rounded-md px-2 py-1 min-w-[16rem] focus:outline-none focus:ring-2 focus:ring-[#F07B6E]/20"}):(0,s.jsxs)("button",{type:"button",onClick:()=>{i(t),d.current=!0,r(!0),setTimeout(()=>{var e;return null===(e=c.current)||void 0===e?void 0:e.select()},0)},title:"Rename automation",className:"group flex items-center gap-1.5 px-2 py-1 -ml-2 rounded-md hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",children:[(0,s.jsx)("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-200",children:t||"Untitled automation"}),(0,s.jsx)(es.Z,{className:"w-3.5 h-3.5 text-gray-300 group-hover:text-gray-500 transition-colors"})]}):(0,s.jsx)("span",{className:"text-sm font-semibold text-gray-800 dark:text-gray-200",children:t||"Workflow Editor"})}function eu(e){var t,a;let{projectId:l,initialNodes:r,initialEdges:o,eventTypes:c,triggerEvent:u,onTriggerChange:x,onSave:p,onBack:m,saving:h,ruleName:g,onRuleNameChange:b}=e,[v,f]=(0,n.useReducer)(ei,{...ec,nodes:r,edges:o}),y=(0,n.useRef)(null),[j,N]=(0,n.useState)({x:0,y:0}),[k,w]=(0,n.useState)(!1),C=(0,n.useRef)({x:0,y:0}),[T,I]=(0,n.useState)(null),F=(0,n.useRef)({x:0,y:0}),{nodes:Z,edges:O,selectedNodeId:D,viewport:M,connecting:z}=v,W=Z.find(e=>e.id===D)||null,B=Z.some(e=>"trigger"===e.type),L=(null===(a=Z.find(e=>"trigger"===e.type))||void 0===a?void 0:null===(t=a.data)||void 0===t?void 0:t.event)||u,P=(0,n.useCallback)((e,t)=>{var a;let s=null===(a=y.current)||void 0===a?void 0:a.getBoundingClientRect();return s?{x:(e-s.left-M.x)/M.zoom,y:(t-s.top-M.y)/M.zoom}:{x:0,y:0}},[M]),R=(0,n.useCallback)(e=>{if(0!==e.button)return;let t=e.target,a=t.closest("[data-handle]"),s=t.closest("[data-node-id]");if(a){e.stopPropagation();let t=a.getAttribute("data-node-id"),s=a.getAttribute("data-handle");"input"===s?z&&f({type:"FINISH_CONNECTING",targetId:t}):f({type:"START_CONNECTING",sourceId:t,handleType:s});return}if(s){e.stopPropagation();let t=s.getAttribute("data-node-id");if(z){f({type:"FINISH_CONNECTING",targetId:t});return}f({type:"SET_SELECTED",nodeId:t});let a=P(e.clientX,e.clientY),n=Z.find(e=>e.id===t);n&&(F.current={x:a.x-n.position.x,y:a.y-n.position.y},I(t));return}if(z){f({type:"CANCEL_CONNECTING"});return}f({type:"SET_SELECTED",nodeId:null}),w(!0),C.current={x:e.clientX-M.x,y:e.clientY-M.y}},[M,z,Z,P]),U=(0,n.useCallback)(e=>{let t=P(e.clientX,e.clientY);N(t),k&&f({type:"SET_VIEWPORT",viewport:{...M,x:e.clientX-C.current.x,y:e.clientY-C.current.y,zoom:M.zoom}}),T&&f({type:"MOVE_NODE",nodeId:T,x:t.x-F.current.x,y:t.y-F.current.y})},[k,M,T,P]),V=(0,n.useCallback)(()=>{w(!1),I(null)},[]),q=(0,n.useCallback)(e=>{var t;e.preventDefault();let a=e.deltaY>0?.9:1.1,s=Math.max(.2,Math.min(3,M.zoom*a)),n=null===(t=y.current)||void 0===t?void 0:t.getBoundingClientRect();if(!n)return;let l=e.clientX-n.left,r=e.clientY-n.top;f({type:"SET_VIEWPORT",viewport:{x:l-(l-M.x)*(s/M.zoom),y:r-(r-M.y)*(s/M.zoom),zoom:s}})},[M]),J=(0,n.useCallback)(e=>{var t;let a=null===(t=y.current)||void 0===t?void 0:t.getBoundingClientRect(),s=a?(a.width/2-M.x)/M.zoom-110:200,n=a?(a.height/2-M.y)/M.zoom-36:200,l=30*Z.length;f({type:"ADD_NODE",node:{id:"node-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,6)),type:e,position:{x:s+l,y:n+l},data:{trigger:{event:""},condition:{field:"",operator:"",value:""},switch:{field:"",cases:[{value:"",label:"",operator:"equals"}]},action:{actionType:""},loop:{listField:"",mode:"variable"},merge:{mode:"combine"},filter:{field:"",operator:"",value:""},set:{mappings:[{key:"",value:"",mode:"static"}]},code:{code:"",language:"expression"}}[e]||{}}})},[M,Z]);return(0,s.jsxs)("div",{className:"flex flex-col h-full bg-gray-50 dark:bg-gray-950",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700 shadow-sm z-10",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3",children:[(0,s.jsx)("button",{onClick:m,className:"p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors",children:(0,s.jsx)(en.Z,{className:"w-4 h-4 text-gray-500"})}),(0,s.jsx)(ed,{name:g,onChange:b}),z&&(0,s.jsx)("span",{className:"text-xs text-[#F07B6E] bg-[#F07B6E]/10 px-2 py-1 rounded-full animate-pulse",children:"Click a node to connect..."})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-1 bg-gray-100 dark:bg-gray-800 rounded-lg p-0.5",children:[(0,s.jsx)("button",{onClick:()=>f({type:"SET_VIEWPORT",viewport:{...M,zoom:Math.max(.2,.8*M.zoom)}}),className:"p-1.5 rounded hover:bg-white dark:hover:bg-gray-700 transition-colors",children:(0,s.jsx)(el.Z,{className:"w-3.5 h-3.5 text-gray-500"})}),(0,s.jsxs)("span",{className:"text-xs text-gray-500 px-1 min-w-[3rem] text-center",children:[Math.round(100*M.zoom),"%"]}),(0,s.jsx)("button",{onClick:()=>f({type:"SET_VIEWPORT",viewport:{...M,zoom:Math.min(3,1.2*M.zoom)}}),className:"p-1.5 rounded hover:bg-white dark:hover:bg-gray-700 transition-colors",children:(0,s.jsx)(er.Z,{className:"w-3.5 h-3.5 text-gray-500"})}),(0,s.jsx)("button",{onClick:()=>{var e;if(!Z.length){f({type:"SET_VIEWPORT",viewport:{x:0,y:0,zoom:1}});return}let t=null===(e=y.current)||void 0===e?void 0:e.getBoundingClientRect();if(!t)return;let a=Math.min(...Z.map(e=>e.position.x))-60,s=Math.min(...Z.map(e=>e.position.y))-60,n=Math.max(...Z.map(e=>e.position.x+d(e)))+60,l=Math.max(...Z.map(e=>e.position.y+72))+60,r=n-a,o=l-s,i=Math.min(t.width/r,t.height/o,1.5);f({type:"SET_VIEWPORT",viewport:{x:(t.width-r*i)/2-a*i,y:(t.height-o*i)/2-s*i,zoom:i}})},className:"p-1.5 rounded hover:bg-white dark:hover:bg-gray-700 transition-colors",children:(0,s.jsx)(K.Z,{className:"w-3.5 h-3.5 text-gray-500"})})]}),(0,s.jsxs)("button",{onClick:()=>p(Z,O),disabled:h,className:"flex items-center gap-2 px-4 py-2 bg-[#F07B6E] hover:bg-[#e06555] text-white text-sm font-medium rounded-lg transition-colors disabled:opacity-50",children:[(0,s.jsx)(eo.Z,{className:"w-4 h-4"}),h?"Saving...":"Save"]})]})]}),(0,s.jsxs)("div",{className:"flex flex-1 overflow-hidden",children:[(0,s.jsx)(A,{onAddNode:J,hasTrigger:B}),(0,s.jsx)("div",{className:"flex-1 relative overflow-hidden",children:(0,s.jsxs)("svg",{ref:y,className:"w-full h-full ".concat(T?"cursor-grabbing":k?"cursor-grabbing":"cursor-grab"),onMouseDown:R,onMouseMove:U,onMouseUp:V,onMouseLeave:V,onWheel:q,children:[(0,s.jsx)("defs",{children:(0,s.jsx)("pattern",{id:"grid",width:20*M.zoom,height:20*M.zoom,patternUnits:"userSpaceOnUse",x:M.x%(20*M.zoom),y:M.y%(20*M.zoom),children:(0,s.jsx)("circle",{cx:1,cy:1,r:.5,fill:"#d1d5db"})})}),(0,s.jsx)("rect",{width:"100%",height:"100%",fill:"url(#grid)"}),(0,s.jsxs)("g",{transform:"translate(".concat(M.x,", ").concat(M.y,") scale(").concat(M.zoom,")"),children:[O.map(e=>(0,s.jsx)(E,{edge:e,nodes:Z,onDelete:e=>f({type:"DELETE_EDGE",edgeId:e})},e.id)),z&&(()=>{let e=Z.find(e=>e.id===z.sourceId);return e?(0,s.jsx)(S,{sourceNode:e,handleType:z.handleType,mouseX:j.x,mouseY:j.y}):null})(),Z.map(e=>{let t=d(e),a=i(e),n="trigger"===e.type?0:"merge"===e.type?2:1;return(0,s.jsxs)("g",{"data-node-id":e.id,transform:"translate(".concat(e.position.x,", ").concat(e.position.y,")"),children:[n>0&&Array.from({length:n}).map((a,l)=>(0,s.jsx)("circle",{"data-handle":"input","data-node-id":e.id,cx:1===n?t/2:t/(n+1)*(l+1),cy:0,r:7,fill:z?"#FEE2E2":"#f1f5f9",stroke:z?"#F07B6E":"#94a3b8",strokeWidth:2,className:"cursor-pointer hover:fill-[#FEE2E2] hover:stroke-[#F07B6E] transition-colors"},"in-".concat(l))),(0,s.jsx)(_,{node:{...e,position:{x:0,y:0}},isSelected:D===e.id,isConnecting:!!z}),a.map((n,l)=>{let r=1===a.length?t/2:t/(a.length+1)*(l+1),o=n.color||"#94a3b8",i=n.color?"".concat(n.color,"22"):"#f1f5f9";return(0,s.jsxs)("g",{children:[(0,s.jsx)("circle",{"data-handle":n.id,"data-node-id":e.id,cx:r,cy:72,r:7,fill:i,stroke:o,strokeWidth:2,className:"cursor-pointer hover:brightness-110 transition-colors"}),n.label&&(0,s.jsx)("text",{x:r,y:90,textAnchor:"middle",fontSize:9,fontWeight:600,fill:o,className:"pointer-events-none",children:n.label})]},n.id)}),D===e.id&&"trigger"!==e.type&&(0,s.jsxs)("g",{className:"cursor-pointer",onClick:t=>{t.stopPropagation(),f({type:"DELETE_NODE",nodeId:e.id})},children:[(0,s.jsx)("circle",{cx:t-2,cy:2,r:10,fill:"#fee2e2",stroke:"#ef4444",strokeWidth:1}),(0,s.jsx)("text",{x:t-2,y:6,textAnchor:"middle",fontSize:14,fontWeight:600,fill:"#ef4444",children:"\xd7"})]})]},e.id)})]})]})}),W&&(0,s.jsx)(ea,{projectId:l,node:W,eventTypes:c,triggerEvent:L,onUpdate:e=>{f({type:"UPDATE_NODE_DATA",nodeId:W.id,data:e}),"trigger"===W.type&&e.event&&x(e.event)},onClose:()=>f({type:"SET_SELECTED",nodeId:null})})]})]})}function ex(e){let{projectId:t,ruleId:a}
1=e,[l,r]=(0,n.useState)(null),[o,i]=(0,n.useState)([]),[c,d]=(0,n.useState)(!0),[u,x]=(0,n.useState)(!1),[p,m]=(0,n.useState)(""),[h,g]=(0,n.useState)(""),b=!a||"new"===a;(0,n.useEffect)(()=>{t&&(v(),b?d(!1):f())},[t,a]);let v=async()=>{try{let e=await fetch("/api/v1/modules/automations/event-types?project_id=".concat(t),{credentials:"include"});e.ok&&i(await e.json())}catch(e){console.error("Failed to fetch event types:",e)}},f=async()=>{try{let e=await fetch("/api/v1/modules/automations/rules/".concat(a,"?project_id=").concat(t),{credentials:"include"});if(e.ok){let t=await e.json(),a={...t,nodes:"string"==typeof t.nodes?JSON.parse(t.nodes):t.nodes||[],edges:"string"==typeof t.edges?JSON.parse(t.edges):t.edges||[],conditions:"string"==typeof t.conditions?JSON.parse(t.conditions):t.conditions||[],actions:"string"==typeof t.actions?JSON.parse(t.actions):t.actions||[]};if(r(a),m(a.name),g(a.trigger),a.webhook_slug||a.cron_expression){let e=a.nodes.find(e=>"trigger"===e.type);e&&(a.webhook_slug&&(e.data.webhook_slug=a.webhook_slug),a.cron_expression&&(e.data.cron_expression=a.cron_expression))}}}catch(e){console.error("Failed to fetch rule:",e)}d(!1)},y=async(e,s)=>{var n,o,i,c;if(!t)return;x(!0);let d=e.find(e=>"trigger"===e.type),u=(null==d?void 0:null===(n=d.data)||void 0===n?void 0:n.event)||h||"form_submitted",g=p;if(!g.trim()){let e=prompt("Enter a name for this automation:");if(!e){x(!1);return}m(g=e.trim())}let v={name:g,trigger:u,nodes:e,edges:s,conditions:[],actions:[],enabled:null===(c=null==l?void 0:l.enabled)||void 0===c||c,webhook_slug:(null==d?void 0:null===(o=d.data)||void 0===o?void 0:o.webhook_slug)||"",cron_expression:(null==d?void 0:null===(i=d.data)||void 0===i?void 0:i.cron_expression)||""};try{let n=b?"/api/v1/modules/automations/rules?project_id=".concat(t):"/api/v1/modules/automations/rules/".concat(a,"?project_id=").concat(t),o=await fetch(n,{method:b?"POST":"PUT",credentials:"include",headers:{"Content-Type":"application/json"},body:JSON.stringify(v)});if(o.ok){let t=await o.json();b?window.location.href="/manage/automations/rules/".concat(t.id):r({...l,...t,nodes:e,edges:s})}else alert("Failed to save rule")}catch(e){console.error("Save failed:",e),alert("Failed to save rule")}x(!1)};if(!t)return(0,s.jsx)("div",{className:"flex items-center justify-center h-screen text-gray-400",children:"Loading..."});if(c)return(0,s.jsx)("div",{className:"flex items-center justify-center h-screen",children:(0,s.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-[#5B7B9A]"})});let j=(null==l?void 0:l.nodes)||[],N=(null==l?void 0:l.edges)||[];return b&&0===j.length&&(j=[{id:"node-".concat(Date.now()),type:"trigger",position:{x:300,y:80},data:{event:""}}]),(0,s.jsx)("div",{className:"fixed inset-0 z-50 flex flex-col bg-white dark:bg-gray-950",children:(0,s.jsx)(eu,{projectId:t,initialNodes:j,initialEdges:N,eventTypes:o,triggerEvent:h,onTriggerChange:g,onSave:y,onBack:()=>{window.location.href="/manage/automations/rules"},saving:u,ruleName:p,onRuleNameChange:m})})}}}]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.