PageSourceSearch

https://www.propora.ai/assets/Flow-CZTC0Hyd.js

js propora.ai collected 2026-10-05 14:30:21 UTC 146,081 bytes, 1 lines download raw bytes

1import{r as l,j as e,D as yt,au as nt,a$ as Ve,bq as xt,bJ as Ca,d as mt,B as K,ay as Sa,u as xa,d5 as Aa,cM as $t,d6 as Et,m as Rt,C as Fa,bd as ze,a2 as fa,a3 as ha,t as re,v as Lt,bW as zt,cJ as Xt,cl as Gt,co as Bt,d7 as Tt,bg as Da,d8 as Pa,bX as Ea,b1 as ya,bZ as Ta,b_ as ba,S as Oa,d9 as Ut,da as Ia,R as Ma,x as ea,p as _a,ar as ka,by as $a,d3 as ja,aj as Ra,i as bt,cK as ft,e as Le,cH as ta,k as La,ap as Va,db as za,E as ht,dc as aa,bY as tt,dd as Ga,de as ut,U as Ya,df as Ha,K as wa,aZ as Ja,bS as Vt,dg as qa,J as Wa,az as he,L as Ka,bR as Qa,dh as Za,di as Xa,b2 as Ba,be as Ua,av as en,aw as tn,ax as an}from"./index-BzAldwSt.js";import{S as nn,f as na}from"./SmsTemplateManager-CT6JW3Oj.js";import{E as sn}from"./EmailTemplateEditor-Daa7Rocr.js";import{S as sa,T as rn,C as ra,a as ln,g as on}from"./TemplateVariableSelector-CBAynpaG.js";import{T as at}from"./Toggle-b4zdh5cA.js";import{I as cn}from"./InlineLoader-Dz1DSjy6.js";import{E as dn}from"./ErrorState-BmS3Y4XK.js";import{D as gn,C as pn,P as mn}from"./react-beautiful-dnd.esm-CxbV2q_5.js";import{C as un}from"./ContactTagsManager-DhyEHHm7.js";import{F as xn}from"./FeatureLockWrapper-DfEPkIdL.js";import{P as fn}from"./PageHeader-DrXPJ5Ip.js";import{E as hn}from"./EmptyState-6NsaUXsP.js";/* empty css               */import"./CustomQuillEditor-BRNHP8zV.js";import"./quill.snow-FxEw-Ia8.js";import"./isEqual-DzSeg6ii.js";import"./editorImageUpload-DQ0rSbGc.js";import"./inheritsLoose-Dh9mjS0Z.js";import"./defineProperty-DbXIQDXj.js";import"./typeof-QjJsDpFa.js";import"./tiny-invariant-CopsF_GD.js";import"./billingStore-C_SenOcV.js";import"./react-BY6lNfys.js";function yn({isOpen:a,onClose:f}){const[w,E]=l.useState(!1),[y,g]=l.useState(!1),[r,O]=l.useState(""),[m,h]=l.useState([]),[F,J]=l.useState(""),[D,$]=l.useState(!1),[u,b]=l.useState(null),[V,Q]=l.useState("edit"),[H,te]=l.useState(!1);l.useEffect(()=>{E(!0)},[]),l.useEffect(()=>{if(!a)return;const v=document.body.style.overflow;return document.body.style.overflow="hidden",()=>{document.body.style.overflow=v||"auto"}},[a]);const x=async()=>{var v;g(!0),O("");try{const z=await mt.get(`${K}/api_new/admin/business/email-template/library`,{headers:{Authorization:`Bearer ${localStorage.getItem("token")}`}});(v=z==null?void 0:z.data)!=null&&v.success?h(Array.isArray(z.data.data)?z.data.data:[]):h([])}catch{O("Failed to load email templates"),h([])}finally{g(!1)}};l.useEffect(()=>{a&&x()},[a]);const C=async v=>{try{await mt.post(`${K}/api_new/admin/business/email-template/library`,{templates:v},{headers:{Authorization:`Bearer ${localStorage.getItem("token")}`}})}catch{}},S=l.useMemo(()=>{const v=F.trim().toLowerCase();return v?(m||[]).filter(z=>(z.name||"").toLowerCase().includes(v)||(z.description||"").toLowerCase().includes(v)||(z.key||"").toLowerCase().includes(v)):m},[m,F]),_=(v,z=null)=>{const ae=[...m],R=ae[v],X=z!==null?!!z:!R.enabled;ae[v]={...R,enabled:X},h(ae),C(ae)},P=v=>{b(v),Q("edit"),$(!0)},ge=(v,z,ae,R)=>{if(!u)return;const X=(m||[]).map(se=>se.key===u.key?{...se,subject:v,htmlContent:z,textContent:ae,name:(R==null?void 0:R.name)||se.name,description:(R==null?void 0:R.description)||se.description}:se);h(X),C(X)},be=async v=>{var z,ae;try{const R=v==null?void 0:v.id;if(!R){alert("Template id is missing.");return}const X=(v==null?void 0:v.name)||"this template";if(!window.confirm(`Delete ${X}? This action cannot be undone.`))return;await mt.delete(`${K}/api_new/admin/business/email-template/library/${R}`,{headers:{Authorization:`Bearer ${localStorage.getItem("token")}`}}),h(se=>(se||[]).filter(Ce=>Ce.id!==R))}catch(R){const X=((ae=(z=R==null?void 0:R.response)==null?void 0:z.data)==null?void 0:ae.message)||(R==null?void 0:R.message)||"Failed to delete template";alert(X)}},ne=async(v,z,ae,R)=>{var X,se,Ce,_e;try{const B={name:(R==null?void 0:R.name)||"",key:(R==null?void 0:R.key)||"",description:(R==null?void 0:R.description)||"",subject:v||"",htmlContent:z||"",textContent:ae||"",enabled:!0};if(!B.name||!B.key||!B.htmlContent||!B.textContent){alert("Please provide a Name, Key, HTML content and Text content");return}const ke=(B.key||"").toLowerCase().trim();if(B.key=ke,(m||[]).some(pe=>((pe==null?void 0:pe.key)||"").toLowerCase().trim()===ke)){let pe="this business";try{pe=await Sa()}catch{}alert(`The key "${ke}" is already in use for business "${pe}". Keys must be unique per business. Please choose a different template name (which generates a different key).`);return}const Z=await mt.post(`${K}/api_new/admin/business/email-template/library/create`,B,{headers:{Authorization:`Bearer ${localStorage.getItem("token")}`}});(X=Z==null?void 0:Z.data)!=null&&X.success&&Z.data.data?h(pe=>{const je=Array.isArray(pe)?[...pe,Z.data.data]:[Z.data.data];return je.sort((Se,Ae)=>(Se.name||"").localeCompare(Ae.name||"")),je}):alert(((se=Z==null?void 0:Z.data)==null?void 0:se.message)||"Failed to create template")}catch(B){const ke=((_e=(Ce=B==null?void 0:B.response)==null?void 0:Ce.data)==null?void 0:_e.message)||(B==null?void 0:B.message)||"Failed to create template";alert(ke)}};return!a||!w?null:e.jsxs(yt,{isOpen:a,onClose:f,title:"Email Templates",maxWidthClass:"max-w-5xl",lockBodyScroll:!0,zIndexClass:"z-[10100]",contentClassName:"max-h-[90vh] flex flex-col",bodyClassName:"p-4 flex-1 overflow-y-auto",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-4 mb-3",children:[e.jsxs("div",{className:"flex-1 flex items-center gap-3 px-3 py-2.5 rounded bg-gray-800 border border-gray-700",children:[e.jsx(nt,{className:"text-gray-400"}),e.jsx("input",{value:F,onChange:v=>J(v.target.value),placeholder:"Search templates",className:"bg-transparent text-sm text-white placeholder-gray-400 outline-none w-full"})]}),e.jsx("button",{onClick:()=>{Q("create"),b(null),$(!0)},className:"btn-primary",children:"Add Email Template"})]}),y?e.jsx(cn,{message:"Loading templates...",size:"sm"}):r?e.jsx(dn,{message:r,onRetry:x,compact:!0}):e.jsxs("div",{className:"space-y-4",children:[(S||[]).map((v,z)=>e.jsx("div",{className:"bg-gray-800 border border-gray-700 rounded-lg overflow-hidden",children:e.jsxs("div",{className:"flex justify-between items-center p-4 border-b border-gray-700",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:"bg-gradient-to-r from-teal-600/20 to-blue-700/20 p-2 rounded-lg mr-3",children:e.jsx(Ve,{className:"text-teal-400"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium text-white",children:v.name}),e.jsx("p",{className:"text-gray-400 text-sm",children:v.description})]})]}),e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsx("div",{className:"flex items-center hidden",children:e.jsx(at,{enabled:!!v.enabled,onChange:ae=>_(z,ae)})}),e.jsx("button",{type:"button",onClick:()=>be(v),className:"p-2 rounded text-red-800 hover:text-white transition-colors",title:"Delete Template",children:e.jsx(xt,{})}),e.jsx("button",{disabled:!v.enabled,className:`btn-secondary ${v.enabled?"text-teal-400 hover:text-teal-300":"text-gray-600 cursor-not-allowed"}`,onClick:()=>v.enabled&&P(v),children:e.jsx(Ca,{className:""})})]})]})},v.key||z)),S.length===0&&e.jsx("div",{className:"text-sm text-gray-500",children:"No templates"})]})]}),e.jsx(sn,{isOpen:D,onClose:()=>$(!1),mode:V,templateName:V==="create"?"New Email Template":(u==null?void 0:u.name)||"Email Template",currentName:V==="create"?"":(u==null?void 0:u.name)||"",currentKey:V==="create"?"":(u==null?void 0:u.ke
1y)||"",currentDescription:V==="create"?"":(u==null?void 0:u.description)||"",currentSubject:u==null?void 0:u.subject,currentHtml:u==null?void 0:u.htmlContent,currentText:u==null?void 0:u.textContent,templateVariables:sa,onVariableSelect:()=>te(!0),onSave:V==="create"?ne:ge}),e.jsx(rn,{isOpen:H,onClose:()=>te(!1),variables:sa,onSelect:v=>{window.templateEditorInsertVariable&&window.templateEditorInsertVariable(v)},templateKey:(u==null?void 0:u.key)||(u==null?void 0:u.name)||""})]})}function bn({isOpen:a,onClose:f,title:w="Prospect Details",prospects:E=[]}){return e.jsx(yt,{isOpen:a,onClose:f,title:w,maxWidthClass:"max-w-2xl",zIndexClass:"z-[7100]",footer:e.jsx("div",{className:"flex items-center justify-end",children:e.jsx("button",{type:"button",onClick:f,className:"btn-primary px-4 py-2",children:"Close"})}),children:e.jsx("div",{className:"p-4 overflow-auto max-h-[60vh]",children:Array.isArray(E)&&E.length>0?e.jsx("ul",{className:"divide-y divide-gray-800",children:E.map((y,g)=>e.jsx("li",{className:"py-2 flex items-center justify-between gap-3",children:e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-gray-200 text-sm truncate",children:y!=null&&y.name?y.name:"Unnamed"}),e.jsxs("div",{className:"text-[12px] text-gray-400 truncate",children:[e.jsx("span",{className:"text-blue-300",children:(y==null?void 0:y.email)||"no-email"}),e.jsx("span",{className:"text-gray-600 mx-2",children:"—"}),e.jsx("span",{className:"text-green-300",children:(y==null?void 0:y.phone)||"no-phone"})]})]})},g))}):e.jsx("div",{className:"text-sm text-gray-400",children:"No prospects available"})})})}function ia({behavior:a,eventId:f,onUpdateBehavior:w,staffList:E=[],staffTypes:y=[],staffLoading:g=!1,isTaggedStaffEvent:r=!1,isAddNoteEvent:O=!1}){var J,D,$;const m=a,h=((J=m==null?void 0:m.config)==null?void 0:J.staff_selection_mode)||"specific",F=(u,b={})=>{w==null||w(f,m.id,{config:{...m.config||{},staff_selection_mode:u,...b}})};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-md text-gray-400",children:"Recipient Selection"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>F("specific",{staff_type_ids:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${h==="specific"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"Specific Staff"}),e.jsx("button",{onClick:()=>F("type",{staff_ids:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${h==="type"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"By Staff Type"}),r&&e.jsx("button",{onClick:()=>F("tagged",{staff_ids:null,staff_type_ids:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${h==="tagged"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"Tagged Staff Member"}),O&&e.jsx("button",{onClick:()=>F("assigned_client_manager",{staff_ids:null,staff_type_ids:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${h==="assigned_client_manager"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"Assigned Client Manager"})]})]}),h==="tagged"&&e.jsx("p",{className:"text-xs text-teal-300",children:"Recipient is resolved from the triggering tagged-note event (at_event_email / tagged staff)."}),h==="assigned_client_manager"&&e.jsx("p",{className:"text-xs text-teal-300",children:"Recipient is resolved from the current assigned client manager on the note's transaction."}),h==="specific"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm text-gray-400",children:"Select Staff Members (Multiple)"}),e.jsx("div",{className:"max-h-48 overflow-y-auto border border-gray-700 rounded bg-gray-800 p-2",children:g?e.jsx("p",{className:"text-xs text-gray-500",children:"Loading staff..."}):E.length===0?e.jsx("p",{className:"text-xs text-gray-500",children:"No staff members found"}):E.map(u=>{var H;const V=(Array.isArray((H=m==null?void 0:m.config)==null?void 0:H.staff_ids)?m.config.staff_ids:[]).includes(String(u.id)),Q=[u.first_name,u.last_name].filter(
1Boolean).join(" ")||u.email;return e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-gray-700 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:V,onChange:te=>{var S;const x=Array.isArray((S=m==null?void 0:m.config)==null?void 0:S.staff_ids)?m.config.staff_ids:[],C=te.target.checked?[...x,String(u.id)]:x.filter(_=>_!==String(u.id));w==null||w(f,m.id,{config:{...m.config||{},staff_ids:C}})},className:"w-4 h-4 text-teal-600 bg-gray-700 border-gray-600 rounded focus:ring-teal-500 focus:ring-2"}),e.jsx("span",{className:"text-xs text-gray-200",children:Q})]},u.id)})}),Array.isArray((D=m==null?void 0:m.config)==null?void 0:D.staff_ids)&&m.config.staff_ids.length>0&&e.jsxs("p",{className:"text-xs text-gray-400",children:[m.config.staff_ids.length," staff member",m.config.staff_ids.length!==1?"s":""," selected"]})]}),h==="type"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm text-gray-400",children:"Select Staff Types (Multiple)"}),e.jsx("div",{className:"max-h-48 overflow-y-auto border border-gray-700 rounded bg-gray-800 p-2",children:g?e.jsx("p",{className:"text-xs text-gray-500",children:"Loading staff types..."}):y.length===0?e.jsx("p",{className:"text-xs text-gray-500",children:"No staff types found"}):y.map(u=>{var Q;const V=(Array.isArray((Q=m==null?void 0:m.config)==null?void 0:Q.staff_type_ids)?m.config.staff_type_ids:[]).includes(String(u.id));return e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-gray-700 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:V,onChange:H=>{var C;const te=Array.isArray((C=m==null?void 0:m.config)==null?void 0:C.staff_type_ids)?m.config.staff_type_ids:[],x=H.target.checked?[...te,String(u.id)]:te.filter(S=>S!==String(u.id));w==null||w(f,m.id,{config:{...m.config||{},staff_type_ids:x}})},className:"w-4 h-4 text-teal-600 bg-gray-700 border-gray-600 rounded focus:ring-teal-500 focus:ring-2"}),e.jsx("span",{className:"text-xs text-gray-200",children:u.name})]},u.id)})}),Array.isArray(($=m==null?void 0:m.config)==null?void 0:$.staff_type_ids)&&m.config.staff_type_ids.length>0&&e.jsxs("p",{className:"text-xs text-gray-400",children:[m.config.staff_type_ids.length," staff type",m.config.staff_type_ids.length!==1?"s":""," selected"]})]})]})}const _n=["B&P Inspector","Q&S Surveyor","Property Manager","Sales Agent","Accountant","Mortgage Broker","Tradesperson","Conveyancer","Buyer's Agent","Financial Planner","Insurance Broker","Pest Inspector","Strata Manager","Town Planner","Valuer","Depreciation Specialist","Solicitor","Other"];function la({behavior:a,eventId:f,onUpdateBehavior:w,partnerList:E=[],partnersLoading:y=!1}){var m,h,F,J,D,$,u;const g=a,r=((m=g==null?void 0:g.config)==null?void 0:m.partner_selection_mode)||"specific",O=(b,V={})=>{w==null||w(f,g.id,{config:{...g.config||{},partner_selection_mode:b,...V}})};return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-md text-gray-400",children:"Partner Recipient Selection"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>O("specific",{partner_category:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${r==="specific"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"Specific Partner"}),e.jsx("button",{onClick:()=>O("all_referred_to",{partner_id:null,partner_category:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${r==="all_referred_to"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"All Referred To"}),e.jsx("button",{onClick:()=>O("all_referred_from",{partner_id:null,partner_category:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${r==="all_referred_from"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"All Referred From"}),e.jsx("button",{onClick:()=>O("all_transaction",{partner_id:null,partner_category:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${r==="all_transaction"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"All on Transaction"}),e.jsx("button",{onClick:()=>O("category",{partner_id:null}),className:`px-3 py-1.5 rounded text-xs font-medium transition-colors ${r==="category"?"bg-teal-600 text-white":"bg-gray-700 text-gray-300 hover:bg-gray-600"}`,children:"By Category"})]})]}),r==="all_referred_to"&&e.jsx("p",{className:"text-xs text-teal-300",children:'Sends to all partners on the transaction with direction "referred to".'}),r==="all_referred_from"&&e.jsx("p",{className:"text-xs text-teal-300",children:'Sends to the partner on the transaction with direction "referred from" (the referral source).'}),r==="all_transaction"&&e.jsx("p",{className:"text-xs text-teal-300",children:"Sends to all partners on the transaction regardless of direction or category."}),r==="specific"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm text-gray-400",children:"Select Partner"}),e.jsxs("select",{value:((h=g==null?void 0:g.config)==null?void 0:h.partner_id)||"",onChange:b=>{w==null||w(f,g.id,{config:{...g.config||{},partner_id:b.target.value||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select a partner —"}),y?e.jsx("option",{disabled:!0,children:"Loading partners..."}):E.map(b=>e.jsxs("option",{value:b.id,children:[b.company_name||b.contact_name,b.category?` (${b.category})`:""]},b.id))]}),((F=g==null?void 0:g.config)==null?void 0:F.partner_id)&&e.jsxs("p",{className:"text-xs text-gray-400",children:["Partner selected: ",((J=E.find(b=>String(b.id)===String(g.config.partner_id)))==null?void 0:J.company_name)||((D=E.find(b=>String(b.id)===String(g.config.partner_id)))==null?void 0:D.contact_name)||g.config.partner_id]})]}),r==="category"&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"text-sm text-gray-400",children:"Select Partner Category"}),e.jsxs("select",{value:(($=g==null?void 0:g.config)==null?void 0:$.partner_category)||"",onChange:b=>{w==null||w(f,g.id,{config:{...g.config||{},partner_category:b.target.value||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select a category —"}),_n.map(b=>e.jsx("option",{value:b,children:b},b))]}),((u=g==null?void 0:g.config)==null?void 0:u.partner_category)&&e.jsxs("p",{className:"text-xs text-teal-300",children:["Will send to all ",g.config.partner_category," partners on the transaction."]})]})]})}const oa={send_email:"Sends a templated email to the client when this event fires.",propora_smart:"Sends a templated SMS to the client via Propora SMART messaging.",add_tag:"Adds a tag to the client’s contact record for segmentation.",remove_tag:"Removes a tag from the client’s contact record.",staff_email:"Sends a notification email to selected staff members.",staff_sms:"Sends an SMS notification to selected staff members.",send_agreement:"Creates and sends a contract agreement to the client for signing.",send_kyc_link:'Creates an identity (KYC) verification link for the client and/or their partner. Add a follow-up Send Email/SMS step on "ID Verification Link Created" using {{kyc_link}}.',send_sms:"Sends a direct SMS to the client, their partner (spouse / co-buyer), or both.",create_chat_channel:"Creates a new chat channel for the client.",send_channel_message:"Sends a message to the client’s chat channel.",partner_email:"Sends a templated email to selected business partner(s).",partner_sms:"Sends a templated SMS to selected business partner(s)."};function kn({ev:a,index:f,provided:w,snapshot:E,onRemove:y,onAddBehavior:g,onUpdateBehavior:r,onRemoveBehavior:O,behaviorTypes:m=[],smsTemplates:h=[],onOpenSmsM
1anager:F,availableTags:J=[],tagsLoading:D=!1,emailTemplates:$=[],onRefreshTags:u=()=>{},onUpdateEvent:b=()=>{},agreementDefinitions:V=[],agreementDefinitionsLoading:Q=!1,catalog:H=[]}){var dt,Xe;const[te,x]=l.useState(!1),[C,S]=l.useState(!1),[_,P]=l.useState(null),[ge,be]=l.useState(""),[ne,v]=l.useState(""),[z,ae]=l.useState(!1),[R,X]=l.useState(!1),[se,Ce]=l.useState([]),[_e,B]=l.useState([]),[ke,Ge]=l.useState([]),[Z,pe]=l.useState(!1),[je,Se]=l.useState([]),[Ae,Ne]=l.useState(!1),[W,Ee]=l.useState({}),[Te,st]=l.useState({}),[ye,_t]=l.useState(()=>a!=null&&a.run_flow_event_for_tags?a.run_flow_event_for_tags.split(",").map(A=>parseInt(A.trim(),10)).filter(A=>!isNaN(A)):[]),[xe,Oe]=l.useState(()=>a!=null&&a.run_flow_event_for_agreement_definitions?a.run_flow_event_for_agreement_definitions.split(",").map(t=>t.trim()).filter(Boolean):[]),[U,rt]=l.useState(()=>a!=null&&a.skip_flow_event_if_completed?a.skip_flow_event_if_completed.split(",").map(t=>t.trim()).filter(Boolean):[]);l.useEffect(()=>{(ye.length>0||xe.length>0||U.length>0)&&S(!0)},[]);const it=t=>{if(!t)return null;const A=(J||[]).find(G=>String(G==null?void 0:G.id)===String(t));return(A==null?void 0:A.name)||null},Ke=String((a==null?void 0:a.type)||"").trim()==="backend|transaction|note_tagged",we=String((a==null?void 0:a.type)||"").trim()==="backend|transaction|add_note",ie=_?((a==null?void 0:a.behaviors)||[]).find(t=>String(t.id)===String(_.behaviorId)):null;l.useEffect(()=>{(async()=>{pe(!0);try{const[A,G]=await Promise.all([fetch(`${K}
1/api_new/admin/staff`,{headers:re()}),fetch(`${K}/api_new/admin/staff/types`,{headers:re()})]);if(A.ok){const I=await A.json();B(Array.isArray(I==null?void 0:I.data)?I.data:[])}if(G.ok){const I=await G.json();Ge(Array.isArray(I==null?void 0:I.data)?I.data:[])}}catch{}finally{pe(!1)}})()},[]),l.useEffect(()=>{(async()=>{Ne(!0);try{const A=await fetch(`${K}/api_new/admin/business-partners?limit=500`,{headers:re()});if(A.ok){const G=await A.json();Se(Array.isArray(G==null?void 0:G.data)?G.data:[])}}catch{}finally{Ne(!1)}})()},[]),l.useEffect(()=>{if(_&&ie){const t=ie.config||{};be(t.tag_id||""),v(t.new_tag_name||"")}else be(""),v("")},[_,ie]);const lt=(t={})=>{const A=[t==null?void 0:t.name,t==null?void 0:t.full_name,[t==null?void 0:t.first_name,t==null?void 0:t.last_name].filter(Boolean).join(" ")].find(Boolean)||"",G=(t==null?void 0:t.email)||"",I=(t==null?void 0:t.phone)||(t==null?void 0:t.phone_number)||"";return{name:String(A).trim(),email:String(G).trim(),phone:String(I).trim()}},kt=(t=[])=>{const A=new Map;return t.flat().forEach(G=>{const I=lt(G||{}),ee=I.email||I.phone||`${I.name}-${I.email}-${I.phone}`;if(ee)if(!A.has(ee))A.set(ee,{...I});else{const fe=A.get(ee);A.set(ee,{name:fe.name||I.name,email:fe.email||I.email,phone:fe.phone||I.phone})}}),Array.from(A.values())},jt=()=>{const t=Array.isArray(a==null?void 0:a.funnelEmailClients)?a.funnelEmailClients:[],A=Array.isArray(a==null?void 0:a.funnelPhoneClients)?a.funnelPhoneClients:[],G=t.length===0&&A.length===0&&Array.isArray(a==null?void 0:a.funnelClients)?a.funnelClients:[];return kt([t,A,G])},Qe=xa(),Ye=t=>{const A=Array.from(t.target.selectedOptions,I=>parseInt(I.value,10));_t(A);const G=A.join(",");b==null||b(a.id,{run_flow_event_for_tags:G})},wt=t=>{const A=Array.from(t.target.selectedOptions,I=>I.value);Oe(A);const G=A.join(",");b==null||b(a.id,{run_flow_event_for_agreement_definitions:G})},vt=t=>{const A=Array.from(t.target.selectedOptions,I=>I.value);rt(A);const G=A.join(",");b==null||b(a.id,{skip_flow_event_if_completed:G})},ot=ye.length+xe.length+U.length,He={minutes:1,hours:60,days:1440},Nt=t=>t>0&&t%1440===0?"days":t>0&&t%60===0?"hours":"minutes",Ze=t=>t?t%1440===0?`${t/1440}d`:t%60===0?`${t/60}h`:`${t}m`:"",Fe=[{value:"is_true",label:"is true"},{value:"is_false",label:"is false"},{value:"equals",label:"equals"},{value:"not_equals",label:"does not equal"},{value:"gt",label:"is greater than"},{value:"gte",label:"is greater than or equal to"},{value:"lt",label:"is less than"},{value:"lte",label:"is less than or equal to"}],Je=t=>t==="gt"||t==="gte"||t==="lt"||t==="lte",Re=t=>t==="equals"||t==="not_equals",Ie={kyc_status:[{value:"submitted",label:"Submitted"},{value:"auto_verified",label:"Auto-verified"},{value:"approved",label:"Approved"},{value:"rejected",label:"Rejected"}]};Ie.kyc_status_client=Ie.kyc_status,Ie.kyc_status_partner=Ie.kyc_status;const Ct=t=>{var ee;if(!t||!t.field||!t.operator)return"";const A=((ee=Fe.find(fe=>fe.value===t.operator))==null?void 0:ee.label)||t.operator,G=Je(t.operator)||Re(t.operator)?` ${t.value??""}`:"";return`${t.source==="contact"?"contact.":"trigger."}${t.field} ${A}${G}`},ct=(a.label||"").replace(/^(Backend\||Frontend\|)/,"").replace(/\|/g," – "),St=t=>{const A=t.lagMinutes>0?`${Ze(t.lagMinutes)} after`:"immediately when";let G="";U.length>0&&(G=` — skipped if the client has already completed: ${U.map(De=>{var Me;return((Me=H.find($e=>($e==null?void 0:$e.key)===De))==null?void 0:Me.label)||De}).join(", ")}`);const I=Ct(t.fieldCondition),ee=I?` Only runs if ${I}.`:"";return`Fires ${A} "${ct}"${G}.${ee}`};return e.jsxs("div",{ref:w.innerRef,...w.draggableProps,className:`mx-3 my-3 rounded-2xl border ${E.isDragging?"border-teal-600":"border-gray-700"} bg-gray-800 shadow transition-colors`,children:[e.jsxs("div",{className:`${Qe?"px-3 py-3":"px-5 py-4"} border-b border-gray-800`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{...w.dragHandleProps,className:"cursor-move text-gray-500 hover:text-gray-200 flex-shrink-0",children:e.jsx(Aa,{className:"text-xs"})}),e.jsxs("h4",{className:"text-white font-semibold text-sm md:text-base truncate min-w-0 flex-1",children:[e.jsx("span",{className:"text-xs font-medium text-gray-500 mr-1",children:"When:"}),((dt=a.label)==null?void 0:dt.replace(/^(Backend\||Frontend\|)/,"").replace(/\|/g," – "))||a.label]}),e.jsxs("button",{type:"button",onClick:()=>S(t=>
1!t),className:`inline-flex items-center gap-1 px-2 py-1 rounded text-xs transition-colors flex-shrink-0 ${C?"bg-gray-700 text-white":"text-gray-500 hover:text-gray-200 hover:bg-gray-800"}`,title:"Tag filters",children:[e.jsx($t,{className:"text-[10px]"}),!Qe&&e.jsx("span",{children:"Filters"}),ot>0&&e.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-teal-900/40 text-teal-300 text-[10px] font-medium",children:ot})]}),e.jsx("button",{onClick:()=>y==null?void 0:y(a.id),className:"p-1.5 rounded text-red-400/60 hover:text-red-200 hover:bg-red-900/40 flex-shrink-0 transition-colors","aria-label":`Remove ${a.label}`,children:e.jsx(xt,{className:"text-[11px]"})})]}),C&&e.jsxs("div",{className:"mt-3 grid grid-cols-1 md:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"p-3 rounded-lg bg-gray-900/40 border border-gray-700/50",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Et,{className:"text-[10px] text-blue-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Contact Tags"}),ye.length>0&&e.jsx("span",{className:"ml-auto px-1.5 py-0.5 rounded-full bg-blue-900/40 text-blue-300 text-[10px] font-medium",children:ye.length})]}),e.jsx("select",{multiple:!0,value:ye.map(String),onChange:Ye,className:"w-full bg-gray-800 text-gray-100 border border-gray-700 rounded px-2 py-1.5 text-xs focus:outline-none focus:border-teal-500 min-h-[90px] max-h-[130px]",disabled:D,children:D?e.jsx("option",{disabled:!0,children:"Loading tags..."}):Array.isArray(J)&&J.length>0?J.map(t=>e.jsxs("option",{value:t==null?void 0:t.id,children:[t==null?void 0:t.name,typeof(t==null?void 0:t.contact_count)=="number"?` (${t.contact_count})`:""]},t==null?void 0:t.id)):e.jsx("option",{disabled:!0,children:"No tags available"})}),e.jsx("p",{className:"text-[11px] mt-1.5 leading-snug",style:{color:ye.length>0?"#5eead4":"#6b7280"},children:ye.length>0?`${ye.length} tag${ye.length!==1?"s":""} selected — only matching contacts trigger this.`:"No filter — runs for all contacts."})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-gray-900/40 border border-gray-700/50",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Rt,{className:"text-[10px] text-purple-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Agreement Type"}),xe.length>0&&e.jsx("span",{className:"ml-auto px-1.5 py-0.5 rounded-full bg-purple-900/40 text-purple-300 text-[10px] font-medium",children:xe.length})]}),e.jsx("select",{multiple:!0,value:xe,onChange:wt,className:"w-full bg-gray-800 text-gray-100 border border-gray-700 rounded px-2 py-1.5 text-xs focus:outline-none focus:border-teal-500 min-h-[90px] max-h-[130px]",disabled:Q,children:Q?e.jsx("option",{disabled:!0,children:"Loading agreement types..."}):Array.isArray(V)&&V.length>0?V.map(t=>e.jsxs("option",{value:t==null?void 0:t.id,children:[t==null?void 0:t.name,typeof(t==null?void 0:t.instance_count)=="number"?` (${t.instance_count} sent)`:""]},t==null?void 0:t.id)):e.jsx("option",{disabled:!0,children:"No agreement types available"})}),e.jsx("p",{className:"text-[11px] mt-1.5 leading-snug",style:{color:xe.length>0?"#c4b5fd":"#6b7280"},children:xe.length>0?`${xe.length} type${xe.length!==1?"s":""} selected — only matching agreement triggers this.`:"No filter — runs for all agreement types."})]}),e.jsxs("div",{className:"p-3 rounded-lg bg-gray-900/40 border border-gray-700/50",children:[e.jsxs("div",{className:"flex items-center gap-1.5 mb-2",children:[e.jsx(Fa,{className:"text-[10px] text-red-400"}),e.jsx("span",{className:"text-xs font-medium text-gray-300",children:"Client Has NOT Completed"}),U.length>0&&e.jsx("span",{className:"ml-auto px-1.5 py-0.5 rounded-full bg-red-900/40 text-red-300 text-[10px] font-medium",children:U.length})]}),e.jsx("select",{multiple:!0,value:U,onChange:vt,className:"w-full bg-gray-800 text-gray-100 border border-gray-700 rounded px-2 py-1.5 text-xs focus:outline-none focus:border-teal-500 min-h-[90px] max-h-[130px]",children:Array.isArray(H)&&H.length>0?H.map(t=>e.jsx("option",{value:t==null?void 0:t.key,children:t==null?void 0:t.label},t==null?void 0:t.key)):e.jsx("option",{disabled:!0,children:"No event types available"})}),e.jsx("p",{className:"text-[11px] mt-1.5 leading-snug",style:{color:U.length>0?"#fca5a5":"#6b7280"},children:U.length>0?`Re-checked when each action actually fires (after its delay) — cancelled if the client has ever completed any of ${U.length} selected event${U.length!==1?"s":""} by then.`:"No condition — runs regardless of other events."})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2 mt-3",children:[e.jsxs("button",{type:"button",onClick:()=>{Ce(jt()),X(!0)},className:"inline-flex items-center gap-2 px-2.5 py-1 rounded-md bg-gray-800/80 text-gray-400 hover:text-white hover:bg-gray-700/80 transition-colors text-xs",title:"Clients who triggered this event in the selected date range. This is not a pending-send backlog — actions fire as soon as their delay elapses.",children:[e.jsxs("span",{children:[typeof a.funnelCount=="number"?a.funnelCount:"…"," clients triggered"]}),e.jsx(Rt,{className:"text-[10px] text-gray-500"})]}),(Array.isArray(a==null?void 0:a.behaviors)?a.behaviors.length:0)===0?e.jsx("button",{type:"button",onClick:()=>{g==null||g(a.id),x(!0)},className:"px-2.5 md:px-3 py-1 md:py-1.5 btn-secondary flex items-center gap-1.5 flex-shrink-0",title:"Add first action",children:e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs",children:[e.jsx(ze,{className:"text-[10px]"})," Add Action"]})}):e.jsxs("button",{type:"button",onClick:()=>x(t=>
1!t),className:"px-2.5 md:px-3 py-1 md:py-1.5 btn-secondary flex items-center gap-1.5 flex-shrink-0",title:"View actions","aria-label":te?"Collapse":"Expand",children:[e.jsxs("span",{className:"inline-flex items-center gap-1 text-xs",children:[(a.behaviors||[]).length," Action",(a.behaviors||[]).length!==1?"s":""]}),te?e.jsx(fa,{className:"text-[10px]"}):e.jsx(ha,{className:"text-[10px]"})]})]})]}),te&&e.jsxs("div",{className:"px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsx("span",{className:"text-sm text-gray-300 font-medium",children:"Actions"}),e.jsxs("button",{type:"button",onClick:()=>g==null?void 0:g(a.id),className:"px-2 py-1 text-xs bg-gray-700 hover:bg-gray-600 rounded text-gray-200 inline-flex items-center gap-1 border border-gray-600",children:[e.jsx(ze,{})," Add Action"]})]}),(a.behaviors||[]).length>0&&e.jsx("div",{className:"space-y-2",children:(a.behaviors||[]).map((t,A)=>{var G,I,ee,fe,De,Me,$e,Be;return e.jsxs("div",{className:"p-3 rounded-lg bg-gray-900/40 border border-gray-700/60",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("select",{value:t.kind,onChange:d=>r==null?void 0:r(a.id,t.id,{kind:d.target.value}),className:"px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs font-medium focus:outline-none focus:ring-2 focus:ring-teal-500",children:m.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))}),oa[t.kind]&&e.jsx("span",{className:"text-[11px] text-gray-500 italic hidden md:inline truncate flex-1",children:oa[t.kind]}),e.jsx("button",{type:"button",onClick:()=>O==null?void 0:O(a.id,t.id),className:"ml-auto p-1.5 rounded text-red-400/50 hover:text-red-200 hover:bg-red-900/40 transition-colors flex-shrink-0","aria-label":"Remove action",children:e.jsx(xt,{className:"text-[11px]"})})]}),e.jsxs("div",{className:"mt-2.5",children:[t.kind==="send_email"&&(()=>{var T,j;const d=($||[]).find(M=>{var me,le;return String(M.id)===String((me=t==null?void 0:t.config)==null?void 0:me.template_id)||M.key===((le=t==null?void 0:t.config)==null?void 0:le.template_key)}),q=d?String(d.id):"",k=((T=t==null?void 0:t.config)==null?void 0:T.recipient)||"client";return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Email template"}),e.jsxs("select",{value:q,onChange:M=>{const me=M.target.value,le=($||[]).find(ve=>String(ve.id)===String(me));r==null||r(a.id,t.id,{config:{...t.config||{},template_id:me,template_key:(le==null?void 0:le.key)||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select template —"}),($||[]).map(M=>e.jsx("option",{value:M.id,children:M.name},M.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Send to"}),e.jsxs("select",{value:k,onChange:M=>r==null?void 0:r(a.id,t.id,{config:{...t.config||{},recipient:M.target.value}}),className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"client",children:"Client"}),e.jsx("option",{value:"partner",children:"Partner / spouse only"}),e.jsx("option",{value:"both",children:"Client and partner"})]}),k==="client"?e.jsxs("p",{className:"text-[11px] text-gray-500 mt-1",children:["The contact's partner (if any) is always Cc'd on this send, unless the email contains a ","{{kyc_link}}"," — a verification link is single-use, so partners are never Cc'd on a KYC email."]}):e.jsxs("p",{className:"text-[11px] text-gray-500 mt-1",children:["Uses the partner details on the contact record. Each person is emailed separately, so ","{{kyc_link}}"," resolves to their own verification link — a verification link is single-use, so it is never sent to anyone but the person it was minted for. On a KYC email, whoever you send to must be covered by the paired “Send KYC Link” step's Verify setting, or that send is skipped."]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"CC staff"}),e.jsx("div",{className:"max-h-48 overflow-y-auto border border-gray-700 rounded bg-gray-800 p-2",children:Z?e.jsx("p",{className:"text-xs text-gray-500 px-1 py-1",children:"Loading staff..."}):(_e||[]).length===0?e.jsx("p",{className:"text-xs text-gray-500 px-1 py-1",children:"No staff members found"}):(_e||[]).map(M=>{var Pe;const le=(Array.isArray((Pe=t==null?void 0:t.config)==null?void 0:Pe.cc_staff_ids)?t.config.cc_staff_ids:[]).includes(String(M.id)),ve=[M.first_name,M.last_name].filter(
1Boolean).join(" ")||M.email;return e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 hover:bg-gray-700 rounded cursor-pointer",children:[e.jsx("input",{type:"checkbox",checked:le,onChange:qe=>{var gt;const Ue=Array.isArray((gt=t==null?void 0:t.config)==null?void 0:gt.cc_staff_ids)?t.config.cc_staff_ids:[],At=qe.target.checked?[...Ue,String(M.id)]:Ue.filter(Ft=>Ft!==String(M.id));r==null||r(a.id,t.id,{config:{...t.config||{},cc_staff_ids:At}})},className:"w-4 h-4 text-teal-600 bg-gray-700 border-gray-600 rounded focus:ring-teal-500 focus:ring-2"}),e.jsx("span",{className:"text-xs text-gray-200",children:ve})]},M.id)})}),Array.isArray((j=t==null?void 0:t.config)==null?void 0:j.cc_staff_ids)&&t.config.cc_staff_ids.length>0&&e.jsxs("p",{className:"text-[11px] text-gray-500 mt-1",children:[t.config.cc_staff_ids.length," staff member",t.config.cc_staff_ids.length!==1?"s":""," selected"]})]})]})})(),t.kind==="staff_email"&&(()=>{const d=($||[]).find(k=>{var T,j;return String(k.id)===String((T=t==null?void 0:t.config)==null?void 0:T.template_id)||k.key===((j=t==null?void 0:t.config)==null?void 0:j.template_key)}),q=d?String(d.id):"";return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Email template"}),e.jsxs("select",{value:q,onChange:k=>{const T=k.target.value,j=($||[]).find(M=>String(M.id)===String(T));r==null||r(a.id,t.id,{config:{...t.config||{},template_id:T,template_key:(j==null?void 0:j.key)||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select template —"}),($||[]).map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))]})]}),e.jsx(ia,{behavior:t,eventId:a.id,onUpdateBehavior:r,staffList:_e,staffTypes:ke,staffLoading:Z,isTaggedStaffEvent:Ke,isAddNoteEvent:we})]})})(),(t.kind==="send_sms"||t.kind==="propora_smart")&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"SMS template"}),e.jsxs("select",{value:((G=t==null?void 0:t.config)==null?void 0:G.template_id)||"",onChange:d=>{const q=d.target.value,k=(h||[]).find(T=>String(T.id)===String(q));r==null||r(a.id,t.id,{config:{...t.config||{},template_id:q,template_key:(k==null?void 0:k.template_key)||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select template —"}),(h||[]).map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]}),t.kind==="send_sms"&&e.jsxs("div",{className:"mt-2.5",children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Send to"}),e.jsxs("select",{value:((I=t==null?void 0:t.config)==null?void 0:I.recipient)||"both",onChange:d=>r==null?void 0:r(a.id,t.id,{config:{...t.config||{},recipient:d.target.value}}),className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"client",children:"Client"}),e.jsx("option",{value:"partner",children:"Partner / spouse only"}),e.jsx("option",{value:"both",children:"Client and partner"})]})]})]}),t.kind==="staff_sms"&&e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"SMS template"}),e.jsxs("select",{value:((ee=t==null?void 0:t.config)==null?void 0:ee.template_id)||"",onChange:d=>{const q=d.target.value,k=(h||[]).find(T=>String(T.id)===String(q));r==null||r(a.id,t.id,{config:{...t.config||{},template_id:q,template_key:(k==null?void 0:k.template_key)||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select template —"}),(h||[]).map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]}
1),e.jsx(ia,{behavior:t,eventId:a.id,onUpdateBehavior:r,staffList:_e,staffTypes:ke,staffLoading:Z,isTaggedStaffEvent:Ke,isAddNoteEvent:we})]}),t.kind==="add_tag"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2 flex-wrap",children:(()=>{var k,T,j,M,me,le;const d=((k=t==null?void 0:t.config)==null?void 0:k.new_tag_name)&&String((T=t==null?void 0:t.config)==null?void 0:T.new_tag_name).trim(),q=(j=t==null?void 0:t.config)==null?void 0:j.tag_id;return d&&!q?e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-emerald-900/40 text-emerald-200 border border-emerald-700",children:["New: ",String((M=t==null?void 0:t.config)==null?void 0:M.new_tag_name).trim()]}):q?e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-teal-900/40 text-teal-200 border border-teal-700",children:it((me=t==null?void 0:t.config)==null?void 0:me.tag_id)||`#${(le=t==null?void 0:t.config)==null?void 0:le.tag_id}`}):e.jsx("span",{className:"text-[11px] text-gray-500",children:"No tag selected"})})()}),e.jsxs("button",{type:"button",onClick:()=>P({behaviorId:t.id,mode:"add"}),className:"px-2 py-1 text-xs bg-gray-700 hover:bg-gray-600 rounded text-gray-200 border border-gray-600 inline-flex items-center gap-1 flex-shrink-0",children:[e.jsx(Et,{className:"text-[10px]"})," Choose"]})]}),t.kind==="send_agreement"&&(()=>{var T;const d=(V||[]).find(j=>{var M;return String(j.id)===String((M=t==null?void 0:t.config)==null?void 0:M.definition_id)});let q=[];if(d!=null&&d.fields)try{q=typeof d.fields=="string"?JSON.parse(d.fields):d.fields||[]}catch{q=[]}const k=q.filter(j=>j&&j.type==="text");return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Agreement Definition"}),e.jsxs("select",{value:((T=t==null?void 0:t.config)==null?void 0:T.definition_id)||"",onChange:j=>{const M=j.target.value;r==null||r(a.id,t.id,{config:{...t.config||{},definition_id:M,field_overrides:{}}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",disabled:Q,children:[e.jsx("option",{value:"",children:"— Select agreement —"}),(V||[]).map(j=>e.jsx("option",{value:j.id,children:j.name},j.id))]})]}),d&&k.length>0&&e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Prefill Fields"}),e.jsx("div",{className:"space-y-2",children:k.map(j=>{var M,me;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-gray-400 w-28 truncate flex-shrink-0",title:j.label||j.id,children:j.label||j.id}),e.jsx("input",{type:"text",value:((me=(M=t==null?void 0:t.config)==null?void 0:M.field_overrides)==null?void 0:me[j.id])??j.defaultValue??"",onChange:le=>{var Pe;const ve={...((Pe=t==null?void 0:t.config)==null?void 0:Pe.field_overrides)||{}};ve[j.id]=le.target.value,r==null||r(a.id,t.id,{config:{...t.config||{},field_overrides:ve}})},placeholder:j.placeholder||j.defaultValue||"Enter value",className:"flex-1 px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500"})]},j.id)})})]}),d&&e.jsxs("p",{className:"text-[11px] text-teal-400",children:['Agreement "',d.name,'" will be created and sent to the client automatically.']})]})})(),t.kind==="send_kyc_link"&&(()=>{var k,T;const d=((k=t==null?void 0:t.config)==null?void 0:k.subject)||"client",q=((T=t==null?void 0:t.config)==null?void 0:T.skip_if_verified)!==!1;return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Verify"}),e.jsxs("select",{value:d,onChange:j=>r==null?void 0:r(a.id,t.id,{config:{...t.config||{},subject:j.target.value}}),className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"client",children:"Client only"}),e.jsx("option",{value:"spouse",children:"Partner / spouse only"}),e.jsx("option",{value:"both",children:"Client and partner"})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"text-[11px] text-gray-400",children:"Skip if already verified"}),e.jsx("p",{className:"text-[11px] text-gray-500",children:"Don’t mint a new link when that person’s ID is already approved."})]}
1),e.jsx(at,{enabled:q,onChange:j=>r==null?void 0:r(a.id,t.id,{config:{...t.config||{},skip_if_verified:j}})})]}),e.jsxs("p",{className:"text-[11px] text-teal-400",children:["Links are single-use and expire after 7 days. Any earlier unused link for the same person is revoked. Add a Send Email or SMART SMS step on the “ID Verification Link Created” event using ","{{kyc_link}}"," to deliver it."]})]})})(),t.kind==="partner_email"&&(()=>{const d=($||[]).find(k=>{var T,j;return String(k.id)===String((T=t==null?void 0:t.config)==null?void 0:T.template_id)||k.key===((j=t==null?void 0:t.config)==null?void 0:j.template_key)}),q=d?String(d.id):"";return e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"Email template"}),e.jsxs("select",{value:q,onChange:k=>{const T=k.target.value,j=($||[]).find(M=>String(M.id)===String(T));r==null||r(a.id,t.id,{config:{...t.config||{},template_id:T,template_key:(j==null?void 0:j.key)||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select template —"}),($||[]).map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))]})]}),e.jsx(la,{behavior:t,eventId:a.id,onUpdateBehavior:r,partnerList:je,partnersLoading:Ae})]})})(),t.kind==="partner_sms"&&e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-[11px] text-gray-500 mb-1 block",children:"SMS template"}),e.jsxs("select",{value:((fe=t==null?void 0:t.config)==null?void 0:fe.template_id)||"",onChange:d=>{const q=d.target.value,k=(h||[]).find(T=>String(T.id)===String(q));r==null||r(a.id,t.id,{config:{...t.config||{},template_id:q,template_key:(k==null?void 0:k.template_key)||null}})},className:"w-full px-2 py-1.5 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"— Select template —"}),(h||[]).map(d=>e.jsx("option",{value:d.id,children:d.name},d.id))]})]}),e.jsx(la,{behavior:t,eventId:a.id,onUpdateBehavior:r,partnerList:je,partnersLoading:Ae})]}),t.kind==="remove_tag"&&e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"flex items-center gap-2",children:(De=t==null?void 0:t.config)!=null&&De.tag_id?e.jsx("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs bg-purple-900/30 text-purple-200 border border-purple-700",children:it((Me=t==null?void 0:t.config)==null?void 0:Me.tag_id)||`#${($e=t==null?void 0:t.config)==null?void 0:$e.tag_id}`}):e.jsx("span",{className:"text-[11px] text-gray-500",children:"No tag selected"})}),e.jsxs("button",{type:"button",onClick:()=>P({behaviorId:t.id,mode:"remove"}),className:"px-2 py-1 text-xs bg-gray-700 hover:bg-gray-600 rounded text-gray-200 border border-gray-600 inline-flex items-center gap-1 flex-shrink-0",children:[e.jsx(Et,{className:"text-[10px]"})," Choose"]})]})]}),e.jsxs("details",{className:"mt-2.5 group",children:[e.jsxs("summary",{className:"flex items-center gap-1.5 text-[11px] text-gray-500 hover:text-gray-300 cursor-pointer select-none transition-colors",children:[e.jsx($t,{className:"text-[9px]"}),e.jsx("span",{children:"Timing"}),t.lagMinutes>0&&e.jsxs("span",{className:"px-1.5 py-0.5 rounded bg-gray-700/60 text-gray-400 text-[10px]",children:[Ze(t.lagMinutes)," delay"]})]}),e.jsxs("div",{className:"mt-2 pl-4 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-[11px] text-gray-500 w-20",children:"Delay"}),(()=>{const d=Te[t.id]||Nt(t.lagMinutes||0),q=W[t.id]!==void 0?W[t.id]:t.lagMinutes?String(Number((t.lagMinutes/He[d]).toFixed(4))):"";return e.jsxs(e.Fragment,{children:[e.jsx("input",{type:"number",min:0,step:"any",value:q,onChange:k=>{Ee(T=>({...T,[t.id]:k.target.value}))},onBlur:k=>{const T=parseFloat(k.target.value),j=isNaN(T)?0:Math.round(Math.max(0,T)*He[d]);r==null||r(a.id,t.id,{lagMinutes:j}),Ee(M=>({...M,[t.id]:void 0}))},onKeyDown:k=>{k.key==="Enter"&&k.target.blur()},className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs w-20 focu
1s:outline-none focus:ring-2 focus:ring-teal-500"}),e.jsxs("select",{value:d,onChange:k=>{const T=k.target.value;if(st(j=>({...j,[t.id]:T})),W[t.id]!==void 0){const j=parseFloat(W[t.id]);if(!isNaN(j)){const M=j*He[d],me=Number((M/He[T]).toFixed(4));Ee(le=>({...le,[t.id]:String(me)}))}}},className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"minutes",children:"Minutes"}),e.jsx("option",{value:"hours",children:"Hours"}),e.jsx("option",{value:"days",children:"Days"})]})]})})()]}),e.jsxs("div",{className:"flex items-center gap-2 justify-between",children:[e.jsx("label",{className:"text-[11px] text-gray-500",children:"Skip if next step completes first"}),e.jsx(at,{enabled:!!t.skipIfNextCompleted,onChange:d=>r==null?void 0:r(a.id,t.id,{skipIfNextCompleted:d})})]}),e.jsxs("div",{className:"border-t border-gray-700/50 pt-2 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 justify-between",children:[e.jsx("label",{className:"text-[11px] text-gray-500",children:"Only run if a field matches"}),e.jsx(at,{enabled:!!t.fieldCondition,onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:d?{source:"contact",field:"",operator:"is_true",value:""}:null})})]}),t.fieldCondition&&e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsxs("select",{value:t.fieldCondition.source||"trigger_event",onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:{...t.fieldCondition,source:d.target.value}}),className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",title:"Where this field is read from when the action is about to fire",children:[e.jsx("option",{value:"contact",children:"Contact field (live, checked when this action fires)"}),e.jsx("option",{value:"trigger_event",children:"Trigger event data (fixed at the moment the flow started)"})]}),e.jsxs("select",{value:t.fieldCondition.field||"",onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:{...t.fieldCondition,field:d.target.value}}),title:"Which field to check",className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs w-48 focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"Select a field…"}),t.fieldCondition.field&&!(t.fieldCondition.source==="contact"?ra:ln).some(d=>d.key===t.fieldCondition.field)&&e.jsxs("option",{value:t.fieldCondition.field,children:[t.fieldCondition.field," (custom, already set)"]}),(t.fieldCondition.source||"trigger_event")==="contact"?e.jsx("optgroup",{label:"Identity Verification (live)",children:ra.map(d=>e.jsx("option",{value:d.key,children:d.label},d.key))}):Array.from(on()).map(([d,q])=>e.jsx("optgroup",{label:d,children:q.map(k=>e.jsx("option",{value:k.key,children:k.label},k.key))},d))]}),e.jsx("select",{value:t.fieldCondition.operator||"is_true",onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:{...t.fieldCondition,operator:d.target.value}}),className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:Fe.map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))}),Je(t.fieldCondition.operator)&&e.jsx("input",{type:"number",step:"any",value:t.fieldCondition.value??"",onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:{...t.fieldCondition,value:d.target.value}}),placeholder:"value",className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs w-20 focus:outline-none focus:ring-2 focus:ring-teal-500"}),Re(t.fieldCondition.operator)&&(Ie[t.fieldCondition.field]?e.jsxs("select",{value:t.fieldCondition.value??"",onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:{...t.fieldCondition,value:d.target.value}}),title:"Value to compare against",className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"",children:"Select a value…"}),Ie[t.fieldCondition.field].map(d=>e.jsx("option",{value:d.value,children:d.label},d.value))]}):e.jsx("input",{type:"text",value:t.fieldCondition.value??"",onChange:d=>r==null?void 0:r(a.id,t.id,{fieldCondition:{...t.fieldCondition,value:d.target.value}}),placeholder:"value",className:"px-2 py-1 bg-gray-800 border border-gray-600 rounded text-gray-200 text-xs w-32 focus:outline-none focus:ring-2 focus:ring-teal-500"}))]}),e.jsxs("p",{className:"text-[10px] text-gray-600 leading-snug",children:[(((Be=t.fieldCondition)==null?void 0:Be.source)||"trigger_event")==="contact"?"Re-read from the client’s contact record right when this action fires — use this for a field that can change during the delay (e.g. after a prior action in this same stage updates it).":"Checked against the data on the event that triggered this stage (e.g. an amount, a yes/no flag) — this is a fixed snapshot from when the flow started, so it will not reflect anything that changes during the delay."," ","The dropdown lists the same variables available in templates as ",e.jsx("code",{children:"{{tokens}}"}),"."]})]}),e.jsx("p",{className:"text-[11px] text-teal-400/90 leading-snug border-t border-gray-700/50 pt-2",children:St(t)})]})]})]},t.id)})})]}),e.jsx(yt,{isOpen:!!_,onClose:()=>P(null),title:(_==null?void 0:_.mode)==="remove"?"Select Tag to Remove":"Select or Create Tag",maxWidthClass:"max-w-[640px]",zIndexClass:"z-[7000]",footer
1:_&&e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{onClick:async()=>{var I;if(!ie)return;const t=ie.config||{},A=(ne||"").trim(),G=ge;if(_.mode!=="remove"&&A){try{ae(!0);const ee=await fetch(`${K}/api_new/admin/tags`,{method:"POST",headers:re(!1),body:JSON.stringify({name:A})}),fe=await ee.json().catch(()=>({})),De=(I=fe==null?void 0:fe.data)==null?void 0:I.id;if(ee.ok&&De){r==null||r(a.id,ie.id,{config:{...t,tag_id:De,new_tag_name:""}});try{await u()}catch{}}else r==null||r(a.id,ie.id,{config:{...t,new_tag_name:A,tag_id:""}})}catch{r==null||r(a.id,ie.id,{config:{...t,new_tag_name:A,tag_id:""}})}finally{ae(!1),P(null)}return}if(G){r==null||r(a.id,ie.id,{config:{...t,tag_id:G,new_tag_name:""}}),P(null);return}},disabled:z||!ge&&!((_==null?void 0:_.mode)!=="remove"&&ne.trim()),className:`btn-primary text-sm ${z||!ge&&!((_==null?void 0:_.mode)!=="remove"&&ne.trim())?"opacity-50 cursor-not-allowed":""}`,children:z?"Saving…":(_==null?void 0:_.mode)==="remove"?"Remove Tag":"Add Tag"})}),children:_&&e.jsx("div",{children:e.jsx(un,{mode:"add",availableTags:J,tagsLoading:D,selectedTagId:ge,onSelectedTagIdChange:t=>{ie&&(be(t),v(""),r==null||r(a.id,ie.id,{config:{...ie.config||{},tag_id:t,new_tag_name:""}}),P(null))},newTagName:_.mode==="remove"?"":ne,onNewTagNameChange:t=>{_.mode!=="remove"&&ie&&(v(t),r==null||r(a.id,ie.id,{config:{...ie.config||{},new_tag_name:t}}))},showPrimaryAction:!1,allowCreate:_.mode!=="remove"})})}),e.jsx(bn,{isOpen:R,onClose:()=>X(!1),title:((Xe=a==null?void 0:a.label)==null?void 0:Xe.replace(/^(Backend\||Frontend\|)/,"").replace(/\|/g," – "))||"Prospects",prospects:se})]})}const et={"backend|contact|create":"New Contact Created","backend|contact|update":"Contact Updated","backend|contact|delete":"Contact Deleted","backend|contact|email_verify_send":"Email Verification Sent","backend|contact|invite":"Client Invited","backend|contact|partner_invite":"Partner Invited","backend|contact|partner_invite_claimed":"Partner Login Created","backend|contact|reset_password":"Password Reset","backend|contract_instance|add":"Agreement Created","backend|contract_instance|viewed":"Agreement Viewed","backend|contract_instance|signed":"Agreement Signed","backend|transaction|add":"New Transaction","backend|transaction|property_add":"Property Added to Transaction","backend|transaction|property_shortlist":"Property Shortlisted","backend|transaction|property_accept":"Property Accepted by Client","backend|transaction|property_approve":"Property Approved","backend|transaction|property_rejected":"Property Rejected","backend|transaction|property_rejected_by_client":"Property Rejected by Client","frontend|transaction|property_rejected":"Property Rejected (Client Dashboard)","frontend|transaction|property_rejected_by_client":"Property Rejected by Client (Dashboard)","backend|transaction|offer_add":"Offer Made","backend|transaction|offer_update":"Offer Updated","backend|transaction|offer_exchange":"Offer Exchanged","backend|transaction|unconditional":"Unconditional","backend|transaction|unconditional_add":"Unconditional Added","backend|transaction|paid":"Transaction Marked as Paid","backend|transaction|booking_add":"Strategy Session / Booking Added","backend|transaction|booking_update":"Booking Updated","backend|transaction|update_status":"Status Changed","backend|transaction|add_note":"Note Added","backend|transaction|note_tagged":"Staff Tagged in Note","backend|transaction|new_client_note":"New Client Note","backend|transaction|add_brief":"Brief Added","backend|transaction|update_brief":"Brief Updated","backend|transaction|approved_brief":"Brief Approved","backend|transaction|add_locations":"Locations Added","backend|transaction|target_location_add":"Target Location Added","backend|transaction|target_location_add_multiple":"Multiple Locations Added","backend|transaction|target_location_approved":"Location Approved","backend|transaction|cm_assign_pending":"CM Assignment Pending","backend|transaction|cm_assign_approved":"CM Assignment Approved","backend|transaction|wa_assign_approved":"WA Assignment Approved","backend|transaction|stage_change_engaged":"Stage → Engaged","backend|transaction|stage_change_booked":"Stage → Booked","backend|transaction|stage_change_searching":"Stage → Searching","backend|transaction|stage_change_decision_pending":"Stage → Decision Pending","backend|transaction|stage_change_dd_pending":"Stage → DD Pending","backend|transaction|stage_change_offer_submitted":"Stage → Offer Submitted","backend|transaction|stage_change_offer_accepted":"Stage → Offer Accepted","backend|transaction|stage_change_building_and_pest":"Stage → Bu
1ilding & Pest","backend|transaction|stage_change_unconditional":"Stage → Unconditional","backend|transaction|stage_change_settled":"Stage → Settled","backend|transaction|stage_change_cm_acceptance_first":"Stage → CM Acceptance (First Time Only)","backend|transaction|stage_change_searching_first":"Stage → Searching (First Time Only)","backend|transaction|stage_change_decision_pending_first":"Stage → Decision Pending (First Time Only)","backend|transaction|stage_change_dd_pending_first":"Stage → DD Pending (First Time Only)","backend|transaction|stage_change_offer_submitted_first":"Stage → Offer Submitted (First Time Only)","backend|transaction|stage_change_offer_accepted_first":"Stage → Offer Accepted (First Time Only)","backend|transaction|stage_change_building_and_pest_first":"Stage → Building & Pest (First Time Only)","backend|transaction|stage_change_unconditional_first":"Stage → Unconditional (First Time Only)","backend|aml_idv|link_created":"ID Verification Link Created","backend|aml_idv|submitted":"ID Verification Submitted by Client","backend|aml_idv|approved":"ID Verification Approved","backend|aml_idv|rejected":"ID Verification Rejected","backend|guest|create":"Guest Created","backend|guest|convert_to_prospect":"Guest → Prospect","backend|email|open":"Email Opened","backend|email|click":"Email Link Clicked","backend|document|add":"Document Uploaded","backend|chat_channel_messages|add":"Chat Message Sent","backend|client|verify_otp":"OTP Verified","backend|client|resolve":"Client Resolved","backend|client_onboarding|add":"Onboarding Started","backend|client_onboarding|update":"Onboarding Updated","backend|client_data|update":"Client Data Updated","backend|client_property|add":"Client Property Added","backend|client_property|update":"Client Property Updated","backend|user|staff_welcome_email_send":"Staff Welcome Email Sent","backend|transaction|transaction_paused_expired":"Pause Date Expired","backend|transaction|property_overdue":"Property DD Stage Overdue","backend|transaction|pipeline_stage_overdue":"Pipeline Stage Overdue","backend|transaction|property_overdue_contact_agent":"Property Overdue: Contact Agent","backend|transaction|property_overdue_agent_contacted":"Property Overdue: Agent Contacted","backend|transaction|property_overdue_appraise":"Property Overdue: Appraise","backend|transaction|property_overdue_review":"Property Overdue: Review","backend|transaction|property_overdue_re_appraise":"Property Overdue: Re-Appraise","backend|transaction|property_overdue_allocate":"Property Overdue: Allocate","backend|transaction|property_overdue_repurpose":"Property Overdue: Repurpose","backend|transaction|dd_stage_change":"Property DD Stage Changed","backend|transaction|dd_stage_change_contact_agent":"DD Stage Changed: Contact Agent","backend|transaction|dd_stage_change_agent_contacted":"DD Stage Changed: Agent Contacted","backend|transaction|dd_stage_change_appraise":"DD Stage Changed: Appraise","backend|transaction|dd_stage_change_review":"DD Stage Changed: Review","backend|transaction|dd_stage_change_re_appraise":"DD Stage Changed: Re-Appraise","backend|transaction|dd_stage_change_allocate":"DD Stage Changed: Allocate","backend|transaction|dd_stage_change_repurpose":"DD Stage Changed: Repurpose","backend|transaction|pipeline_stage_overdue_engaged":"Pipeline Overdue: Engaged","backend|transaction|pipeline_stage_overdue_booked":"Pipeline Overdue: Booked","backend|transaction|pipeline_stage_overdue_cm_acceptance":"Pipeline Overdue: CM Acceptance","backend|transaction|pipeline_stage_overdue_searching":"Pipeline Overdue: Searching","backend|transaction|pipeline_stage_overdue_decision":"Pipeline Overdue: Decision Pending","backend|transaction|pipeline_stage_overdue_dd_pending":"Pipeline Overdue: DD Pending","backend|transaction|pipeline_stage_overdue_offer_made":"Pipeline Overdue: Offer Made","backend|transaction|pipeline_stage_overdue_exchanged":"Pipeline Overdue: Exchanged","backend|transaction|pipeline_stage_overdue_building_pest":"Pipeline Overdue: Building & Pest","backend|transaction|pipeline_stage_overdue_unconditional":"Pipeline Overdue: Unconditional","backend|partner|create":"New Partner Added","backend|partner|update":"Partner Updated","backend|partner|delete":"Partner Deleted","backend|partner|sub_contact_create":"Sub-Contact Added to Partner","backend|partner|sub_contact_update":"Sub-Contact Updated","backend|partner|sub_contact_delete":"Sub-Contact Removed from Partner","backend|contact|referral_create":"Contact Referral Created","backend|contact|referral_update":"Contact Referral Updated","backend|contact|referral_delete":"Contact Referral Deleted","backend|transaction|partner_assign":"Partner Assigned to Transaction","backend|transaction|partner_update":"Transaction Partner Updated","backend|transaction|partner_unassign":"Partner Removed from Transaction","backend|voice_call|outbound":"Outbound Call Made","backend|voice_call|inbound":"Inbound Call Received","backend|voice_call|completed":"Call Completed","backend|voice_call|no_answer":"Call No Answer","backend|voice_call|busy":"Call Busy","backend|voice_call|failed":"Call Failed","backend|voice_call|canceled":"Call Cancelled","backend|voice_call|recording":"Call Recording Available","backend|transaction|property_add_pending_cm_approval":"Property Added (Pending CM Approval)","backend|transaction|property_approved_by_cm":"Property Approved by CM","backend|transaction|property_cm_rejected":"Property Rejected by CM","backend|sms|once_off_send":"Once-Off SMS Sent","backend|sms|reply_received":"SMS Reply Received","backend|property_agent_sms|escalated":"Property Agent SMS Escalated to Staff","backend|chat_channel_messages|get":"Chat Messages Viewed","backend|chat_channel_email_reply|received":"Email Reply Received (Chat)","backend|video_call|created":"Video Call Created","backend|goal|add":"Goal Added","backend|goal|update":"Goal Updated","backend|goal|complete":"Goal Completed","backend|goal|delete":"Goal Deleted","backend|client_goal|add":"Client Goal Added","backend|client_goal|update":"Client Goal Updated","backend|client_goal|complete":"Client Goal Completed","backend|client_goal|delete":"Client Goal Deleted","backend|client_goal|get_data":"Client Goal Data Viewed","backend|onboarding|add":"Onboarding Started (Legacy)","backend|onboarding|update":"Onboarding Updated (Legacy)","backend|contact_tag|add":"Tag Added to Contact","backend|contact|email_changed":"Contact Email Changed","backend|contact|partner_email_changed":"Partner Email Changed","backend|client|add":"Client Account Created","backend|client|master_password_login":"Master Password Login","backend|client_data|insert":"Client Data Inserted","backend|notification_prefences|update":"Notification Preferences 
1Updated","backend|assumptions|get":"Assumptions Viewed","backend|assumptions|update":"Assumptions Updated","backend|assumptions|delete":"Assumptions Deleted","backend|client_assumptions|update":"Client Assumptions Updated","backend|appraisal_perception|upsert":"Appraisal Perception Saved","backend|property|add":"Property Added (Pool)","backend|property|get_additional_data":"Property Data Fetched","backend|property_simulated|add":"Simulated Property Added","backend|property_simulated|update":"Simulated Property Updated","backend|property_simulated|delete":"Simulated Property Deleted","backend|property_simulated|convert":"Simulated Property Converted","backend|property_simulated|convert_to_owned":"Simulated Property → Owned","backend|property_simulated|cleanup":"Simulated Property Cleanup","backend|property_simulated|cleanup_old":"Simulated Property Cleanup (Old)","backend|property_simulated|get":"Simulated Property Viewed","backend|transaction|review_submitted":"Review Submitted","backend|transaction|review_referrals_submitted":"Review Referrals Submitted","backend|transaction|review_referrals_skipped":"Review Referrals Skipped"},jn=(a="")=>{const f=(a??"").toString();if(!f)return"";const w=f.split("|");return(w.length>=3?w.slice(1):w).join(" ").replace(/_/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,y=>y.toUpperCase())},Yt=(a="")=>et[a]||jn(a)||(a||"").toString(),ca={"backend|contact|create":"Fires when a new contact is added to the system","backend|contact|invite":"Fires when a client invitation is sent","backend|contract_instance|add":"Fires when a new agreement is created","backend|contract_instance|viewed":"Fires when a client views their agreement","backend|contract_instance|signed":"Fires when a client signs their agreement","backend|transaction|add":"Fires when a new transaction is started","backend|transaction|property_add":"Fires when a property is added to a transaction","backend|transaction|property_shortlist":"Fires when a property is shortlisted for a client","backend|transaction|property_accept":"Fires when a client accepts a shortlisted property","backend|transaction|property_approve":"Fires when a property is approved for purchase","backend|transaction|property_rejected":"Fires when a property is rejected","backend|transaction|property_rejected_by_client":"Fires when a client rejects a property (client-derived rejection)","frontend|transaction|property_rejected_by_client":"Fires when a client rejects a property from their own dashboard","backend|transaction|offer_add":"Fires when an offer is submitted on a property","backend|transaction|offer_exchange":"Fires when contracts are exchanged","backend|transaction|unconditional":"Fires when a transaction becomes unconditional","backend|transaction|paid":"Fires when a transaction is marked as Paid (by a Super User, Admin or Accounting user)","backend|transaction|booking_add":"Fires when a Strategy Session is booked (or any manual booking is added). Payload includes calendar metadata + Daily.co video room URLs — use {{strategy_booking_client_meeting_url}} for client emails and {{strategy_booking_date}} / {{strategy_booking_time}} / {{strategy_booking_staff_name}} for booking details.","backend|transaction|add_note":"Fires when a note is added to a transaction","backend|transaction|note_tagged":"Fires when a staff member is tagged in a note","backend|transaction|add_brief":"Fires when a search brief is created","backend|transaction|target_location_add":"Fires when a target location is added","backend|transaction|target_location_approved":"Fires when a target location is approved","backend|transaction|cm_assign_approved":"Fires when a client manager is assigned","backend|transaction|stage_change_engaged":"Fires when a transaction enters the Engaged stage","backend|transaction|stage_change_booked":"Fires when a transaction enters the Booked stage","backend|transaction|stage_change_searching":"Fires when a transaction enters the Searching stage","backend|transaction|stage_change_decision_pending":"Fires when a transaction enters Decision Pending","backend|transaction|stage_change_dd_pending":"Fires when a transaction enter
1s DD Pending","backend|transaction|stage_change_offer_submitted":"Fires when an offer is submitted on a transaction","backend|transaction|stage_change_offer_accepted":"Fires when an offer is accepted on a transaction","backend|transaction|stage_change_building_and_pest":"Fires when a transaction enters the Building & Pest stage","backend|transaction|stage_change_unconditional":"Fires when a transaction becomes unconditional","backend|transaction|stage_change_settled":"Fires when a transaction settles","backend|transaction|stage_change_cm_acceptance_first":"Fires ONLY the first time a Client Manager is accepted on a transaction (not on later CM reassignments)","backend|transaction|stage_change_searching_first":"Fires ONLY the first time a transaction enters Searching (not on later re-entries, e.g. returning from Decision Pending)","backend|transaction|stage_change_decision_pending_first":"Fires ONLY the first time a transaction enters Decision Pending (not on later re-entries)","backend|transaction|stage_change_dd_pending_first":"Fires ONLY the first time a transaction enters DD Pending (not on later re-entries)","backend|transaction|stage_change_offer_submitted_first":"Fires ONLY the first time an offer is submitted on a transaction (not on later re-entries)","backend|transaction|stage_change_offer_accepted_first":"Fires ONLY the first time an offer is accepted on a transaction (not on later re-entries)","backend|transaction|stage_change_building_and_pest_first":"Fires ONLY the first time a transaction enters Building & Pest (not on later re-entries)","backend|transaction|stage_change_unconditional_first":"Fires ONLY the first time a transaction enters Unconditional (not on later re-entries)","backend|guest|create":"Fires when a guest registers on the platform","backend|guest|convert_to_prospect":"Fires when a guest converts to a prospect","backend|email|open":"Fires when a client opens an email","backend|email|click":"Fires when a client clicks a link in an email","backend|document|add":"Fires when a document is uploaded","backend|chat_channel_messages|add":"Fires when a message is sent in chat","backend|client_onboarding|add":"Fires when client onboarding begins","backend|client_onboarding|update":"Fires when onboarding progress changes","backend|user|staff_welcome_email_send":"Fires when a staff welcome email is sent","backend|transaction|transaction_paused_expired":"Fires when a paused transaction's pause-until date has passed","backend|transaction|property_overdue":"Fires when a property exceeds the configured DD stage hours to perform","backend|transaction|pipeline_stage_overdue":"Fires when a transaction exceeds the configured pipeline stage hours to perform","backend|transaction|property_overdue_contact_agent":"Fires when a property is overdue specifically in the Contact Agent DD stage","backend|transaction|property_overdue_agent_contacted":"Fires when a property is overdue specifically in the Agent Contacted DD stage","backend|transaction|property_overdue_appraise":"Fires when a property is overdue specifically in the Appraise DD stage","backend|transaction|property_overdue_review":"Fires when a property is overdue specifically in the Review DD stage","backend|transaction|property_overdue_re_appraise":"Fires when a property is overdue specifically in the Re-Appraise DD stage","backend|transaction|property_overdue_allocate":"Fires when a property is overdue specifically in the Allocate DD stage","backend|transaction|property_overdue_repurpose":"Fires when a property is overdue specifically in the Repurpose DD stage","backend|transaction|dd_stage_change":"Fires when a staff member manually changes a shortlisted property's DD stage","backend|transaction|dd_stage_change_contact_agent":"Fires when a property's DD stage is manually changed to Contact Agent","backend|transaction|dd_stage_change_agent_contacted":"Fires when a property's DD stage is manually changed to Agent Contacted","backend|transaction|dd_stage_change_appraise":"Fires when a property's DD stage is manually changed to Appraise","backend|transaction|dd_stage_change_review":"Fires when a property's DD stage is manually changed to Review","backend|transaction|dd_stage_change_re_appraise":"Fires when a property's DD stage is manually changed to Re-Appraise","backend|transaction|dd_stage_change_allocate":"Fires when a property's DD stage is manually changed to Allocate","backend|transaction|dd_stage_change_repurpose":"Fires when a property's DD stage is manually changed to Repurpose","backend|transaction|pipeline_stage_overdue_engaged":"Fires when a transaction is overdue specifically in the Engaged pipeline stage","backend|transaction|pipeline_stage_overdue_booked":"Fires when a transaction is overdue specifically in the Booked pipeline stage","backend|transaction|pipeline_stage_overdue_cm_acceptance":"Fires when a transaction is overdue specifically in the CM Acceptance pipeline stage","backend|transaction|pipeline_stage_overdue_searching":"Fires when a transaction is overdue specifically in the Searching pipeline stage","backend|transaction|pipeline_stage_overdue_decision":"Fires when a transaction is overdue specifically in the Decision Pending pipeline stage","backend|transaction|pipeline_stage_overdue_dd_pending":"Fires when a transaction is overdue specifically in the DD Pending pipeline stage","backend|transaction|pipeline_stage_overdue_offer_made":"Fires when a transaction is overdue specifically in the Offer Made pi
1peline stage","backend|transaction|pipeline_stage_overdue_exchanged":"Fires when a transaction is overdue specifically in the Exchanged pipeline stage","backend|transaction|pipeline_stage_overdue_building_pest":"Fires when a transaction is overdue specifically in the Building & Pest pipeline stage","backend|transaction|pipeline_stage_overdue_unconditional":"Fires when a transaction is overdue specifically in the Unconditional pipeline stage","backend|partner|create":"Fires when a new business partner is added","backend|partner|update":"Fires when a business partner is updated","backend|partner|delete":"Fires when a business partner is deleted","backend|partner|sub_contact_create":"Fires when a sub-contact is added to a business partner","backend|partner|sub_contact_update":"Fires when a sub-contact on a business partner is updated","backend|partner|sub_contact_delete":"Fires when a sub-contact is removed from a business partner","backend|contact|referral_create":"Fires when a referral (referred from/to) is added to a contact","backend|contact|referral_update":"Fires when a contact referral is updated","backend|contact|referral_delete":"Fires when a contact referral is removed","backend|transaction|partner_assign":"Fires when a partner is assigned to a transaction","backend|transaction|partner_update":"Fires when a transaction partner assignment is updated (direction, sub-contact, notes)","backend|transaction|partner_unassign":"Fires when a partner is removed from a transaction","backend|voice_call|outbound":"Fires when a staff member places an outbound call to a contact","backend|voice_call|inbound":"Fires when an inbound call is received from a contact","backend|voice_call|completed":"Fires when a voice call is completed successfully","backend|voice_call|no_answer":"Fires when a call goes unanswered","backend|voice_call|busy":"Fires when the callee line is busy","backend|voice_call|failed":"Fires when a call fails due to a network or carrier error","backend|voice_call|canceled":"Fires when a call is cancelled before being answered","backend|voice_call|recording":"Fires when a call recording becomes available"},wn={Contacts:{icon:ba,color:"text-violet-400",bgColor:"bg-violet-500/10",borderColor:"border-violet-500/20",gradient:"from-violet-500 to-purple-600"},Agreements:{icon:Ta,color:"text-blue-400",bgColor:"bg-blue-500/10",borderColor:"border-blue-500/20",gradient:"from-blue-500 to-blue-700"},Transactions:{icon:ya,color:"text-teal-400",bgColor:"bg-teal-500/10",borderColor:"border-teal-500/20",gradient:"from-teal-500 to-green-600"},Client:{icon:Tt,color:"text-cyan-400",bgColor:"bg-cyan-500/10",borderColor:"border-cyan-500/20",gradient:"from-cyan-500 to-teal-600"},"Client Onboarding":{icon:Ea,color:"text-cyan-400",bgColor:"bg-cyan-500/10",borderColor:"border-cyan-500/20",gradient:"from-cyan-500 to-teal-600"},"Client Data":{icon:Tt,color:"text-cyan-400",bgColor:"bg-cyan-500/10",borderColor:"border-cyan-500/20",gradient:"from-cyan-500 to-teal-600"},"Client Property":{icon:Lt,color:"text-cyan-400",bgColor:"bg-cyan-500/10",borderColor:"border-cyan-500/20",gradient:"from-cyan-500 to-teal-600"},Guests:{icon:Bt,color:"text-amber-400",bgColor:"bg-amber-500/10",borderColor:"border-amber-500/20",gradient:"from-amber-500 to-orange-600"},"Email Events":{icon:Pa,color:"text-indigo-400",bgColor:"bg-indigo-500/10",borderColor:"border-indigo-500/20",gradient:"from-indigo-500 to-purple-700"},Chat:{icon:Xt,color:"text-indigo-400",bgColor:"bg-indigo-500/10",borderColor:"border-indigo-500/20",gradient:"from-indigo-500 to-purple-700"},Documents:{icon:Da,color:"text-emerald-400",bgColor:"bg-emerald-500/10",borderColor:"border-emerald-500/20",gradient:"from-emerald-500 to-green-700"},Staff:{icon:Tt,color:"text-pink-400",bgColor:"bg-pink-500/10",borderColor:"border-pink-500/20",gradient:"from-pink-500 to-rose-600"},Partners:{icon:Bt,color:"text-orange-400",bgColor:"bg-orange-500/10",borderColor:"border-orange-500/20",gradient:"from-orange-500 to-amber-600"},"Voice Calls":{icon:Gt,color:"text-green-400",bgColor:"bg-green-500/10",borderColor:"border-green-500/20",gradient:"from-green-500 to-emerald-600"}
1,SMS:{icon:Xt,color:"text-sky-400",bgColor:"bg-sky-500/10",borderColor:"border-sky-500/20",gradient:"from-sky-500 to-blue-600"},Goals:{icon:zt,color:"text-amber-400",bgColor:"bg-amber-500/10",borderColor:"border-amber-500/20",gradient:"from-amber-500 to-orange-600"},Properties:{icon:Lt,color:"text-emerald-400",bgColor:"bg-emerald-500/10",borderColor:"border-emerald-500/20",gradient:"from-emerald-500 to-green-700"}},vn=[{title:"Property Pipeline",description:"Track properties through your pipeline stages",icon:Lt,color:"text-teal-400",events:["backend|transaction|property_add","backend|transaction|property_shortlist","backend|transaction|property_approve","backend|transaction|property_rejected","backend|transaction|property_rejected_by_client","backend|transaction|property_accept","backend|transaction|dd_stage_change","backend|transaction|dd_stage_change_contact_agent","backend|transaction|dd_stage_change_agent_contacted","backend|transaction|dd_stage_change_appraise","backend|transaction|dd_stage_change_review","backend|transaction|dd_stage_change_re_appraise","backend|transaction|dd_stage_change_allocate","backend|transaction|dd_stage_change_repurpose"]},{title:"Client Journey",description:"Key milestones in the client lifecycle",icon:ba,color:"text-violet-400",events:["backend|contact|create","backend|contact|invite","backend|contract_instance|signed","backend|guest|convert_to_prospect"]},{title:"Deals & Offers",description:"Offer, exchange, and settlement events",icon:Oa,color:"text-blue-400",events:["backend|transaction|offer_add","backend|transaction|offer_exchange","backend|transaction|unconditional","backend|transaction|paid"]},{title:"Strategy Sessions & Bookings",description:"Calendar-driven Strategy Sessions with Daily.co video room — perfect trigger for client confirmation emails / SMS",icon:Ut,color:"text-teal-400",events:["backend|transaction|booking_add","backend|transaction|booking_update","backend|transaction|stage_change_booked"]},{title:"Transaction Stages",description:"Triggers for each pipeline stage transition",icon:Ut,color:"text-emerald-400",events:["backend|transaction|stage_change_engaged","backend|transaction|stage_change_booked","backend|transaction|stage_change_searching","backend|transaction|stage_change_decision_pending","backend|transaction|stage_change_dd_pending","backend|transaction|stage_change_offer_submitted","backend|transaction|stage_change_offer_accepted","backend|transaction|stage_change_building_and_pest","backend|transaction|stage_change_unconditional","backend|transaction|stage_change_settled"]},{title:"Voice Calls",description:"Call events for outbound, inbound, and recordings",icon:Gt,color:"text-green-400",events:["backend|voice_call|outbound","backend|voice_call|completed","backend|voice_call|no_answer","backend|voice_call|recording"]},{title:"Overdue Alerts",description:"Fires when a property or pipeline stage exceeds configured time limits",icon:Ia,color:"text-red-400",events:["backend|transaction|transaction_paused_expired","backend|transaction|property_overdue","backend|transaction|pipeline_stage_overdue","backend|transaction|property_overdue_contact_agent","backend|transaction|property_overdue_agent_contacted","backend|transaction|property_overdue_appraise","backend|transaction|property_overdue_review","backend|transaction|property_overdue_re_appraise","backend|transaction|property_overdue_allocate","backend|transaction|property_overdue_repurpose","backend|transaction|pipeline_stage_overdue_engaged","backend|transaction|pipeline_stage_overdue_booked","backend|transaction|pipeline_stage_overdue_cm_acceptance","backend|transaction|pipeline_stage_overdue_searching","backend|transaction|pipeline_stage_overdue_decision","backend|transaction|pipeline_stage_overdue_dd_pending","backend|transaction|pipeline_stage_overdue_offer_made","backend|transaction|pipeline_stage_overdue_exchanged","backend|transaction|pipeline_stage_overdue_building_pest","backend|transaction|pipeline_stage_overdue_unconditional"]}],Nn={client:"Client",client_welcome:"Client",client_onboarding:"Client Onboarding",client_data:"Client Data",client_phone:"Client",client_financials:"Client",client_property:"Client Property",contact:"Contacts",contract_instance:"Agreements",transaction:"Transactions",guest:"Guests",guest_portfolio:"Guests",guest_property:"Guests",email:"Email Events",document:"Documents",chat_channel_messages:"Chat",purchase:"Transactions",preferences:"Client",notifications:"Client",user:"Staff",partner:"Partners",voice_call:"Voice Calls",video_call:"Voice Calls",sms:"SMS",chat_channel_email_reply:"Chat",goal:"Goals",client_goal:"Goals",onboarding:"Client Onboarding",contact_tag:"Contacts",assumptions:"Client Data",client_assumptions:"Client Data",appraisal_perception:"Client Property",property:"Properties",property_simulated:"Properties",notification_prefences:"Client"},da=["Transactions","Contacts","Agreements","Guests","Client","Client Onboarding","Client Data","Client Property","Properties","Goals","Email Events","Chat","SMS","Voice Calls","Documents","Staff","Partners"],va=({catalog:a=[],catalogError:f=!1,onRetryCatalog:w,selectedEventKey:E,onChangeSelectedEventKey:y,onAdd:g})=>{const[r,O]=l.useState(!1),m=Array.isArray(a)&&a.length>0,[h,F]=l.useState(""),[J,D]=l.useState(null);l.useEffect(()=>{if(r&&m&&!E){const x=a[0];x!=null&&x.key&&y(x.key)}},[r,m]),l.useEffect(()=>{r&&(F(""),D(null))},[r]);const $=()=>O(!0),u=()=>O(!1),b=async x=>{if(x){y==null||y(x.key);try{await(g==null?void 0:g(x.key))}finally{O(!1)}}},V=l.useMemo(()=>{const x=new Map;
1return(a||[]).forEach(C=>{const S=(C.key||"").split("|").map(ne=>ne.trim()).filter(Boolean),_=S[1]||"General",P=Nn[_]||_.replace(/_/g," ").replace(/\b\w/g,ne=>ne.toUpperCase());x.has(P)||x.set(P,[]);const be=et[C.key]||(S.length>2?S[2].replace(/_/g," ").replace(/\b\w/g,ne=>ne.toUpperCase()):C.label);x.get(P).push({...C,_display:be})}),Array.from(x.entries()).sort(([C],[S])=>{const _=da.indexOf(C),P=da.indexOf(S);return _!==-1&&P!==-1?_-P:_!==-1?-1:P!==-1?1:C.localeCompare(S)}).map(([C,S])=>({name:C,options:S.sort((_,P)=>(_._display||_.label).localeCompare(P._display||P.label)),config:wn[C]||{icon:ya,color:"text-gray-400",bgColor:"bg-gray-500/10",borderColor:"border-gray-500/20",gradient:"from-gray-500 to-gray-700"}}))},[a]),Q=l.useMemo(()=>{if(!h.trim())return[];const x=h.toLowerCase();return(a||[]).filter(C=>(et[C.key]||"").toLowerCase().includes(x)||(C.label||"").toLowerCase().includes(x)||(C.key||"").toLowerCase().includes(x)).map(C=>{const S=(C.key||"").split("|").map(P=>P.trim()).filter(Boolean),_=et[C.key]||(S.length>2?S[2].replace(/_/g," ").replace(/\b\w/g,P=>P.toUpperCase()):C.label);return{...C,_display:_}})},[a,h]),H=l.useMemo(()=>J?V.filter(x=>x.name===J):V,[V,J]),te=e.jsx(yt,{isOpen:!0,onClose:u,title:"Add a Trigger Stage",maxWidthClass:"max-w-4xl",zIndexClass:"z-[6000]",footer:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx("p",{className:"text-gray-500 text-xs",children:"Click any event to add it as a stage"}),e.jsx("button",{type:"button",onClick:u,className:"px-4 py-2 rounded-lg bg-gray-700 hover:bg-gray-600 text-white text-sm transition-colors",children:"Cancel"})]}),children:e.jsxs("div",{className:"bg-gray-850",children:[e.jsx("div",{className:"px-6 pt-4 pb-3",children:e.jsxs("p",{className:"text-gray-400 text-sm leading-relaxed",children:["Choose an event that will ",e.jsx("strong",{className:"text-gray-200",children:"trigger"})," this stage. When this event occurs, any actions you configure will run automatically."]})}),e.jsx("div",{className:"px-6 pb-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(nt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 w-3.5 h-3.5"}),e.jsx("input",{type:"text",value:h,onChange:x=>F(x.target.value),placeholder:"Search for an event…",className:"w-full bg-gray-800 border border-gray-700 rounded-lg pl-10 pr-4 py-2.5 text-white text-sm placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-teal-500 focus:border-transparent transition-all",autoFocus:!0}),h&&e.jsx("button",{onClick:()=>F(""),className:"absolute right-3 top-1/2 -translate-y-1/2 text-gray-500 hover:text-gray-300 text-xs",children:"Clear"})]})}),h.trim()?e.jsx("div",{className:"px-6 pb-4",children:Q.length===0?e.jsxs("div",{className:"text-center py-8 text-gray-500 text-sm",children:['No events match "',e.jsx("span",{className:"text-gray-300",children:h}),'"']}):e.jsx("div",{className:"bg-gray-800 rounded-lg border border-gray-700 overflow-hidden max-h-[400px] overflow-y-auto",children:Q.map(x=>{const C=ca[x.key]||"";return e.jsxs("button",{onClick:()=>{b(x),F("")},className:"w-full text-left flex items-start gap-3 px-4 py-3 hover:bg-gray-700/60 cursor-pointer border-b border-gray-700/50 last:border-b-0 transition-colors group",children:[e.jsx("span",{className:"mt-0.5 w-5 h-5 rounded bg-gray-700 flex items-center justify-center flex-shrink-0 group-hover:bg-teal-600/30",children:e.jsx(ze,{className:"w-2.5 h-2.5 text-gray-400 group-hover:text-teal-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm text-white font-medium",children:x._display}),C&&e.jsx("div",{className:"text-xs text-gray-500 mt-0.5",children:C})]})]},x.key)})})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"px-6 pb-4",children:[e.jsxs("h4",{className:"text-xs font-semibold text-gray-400 uppercase tracking-wider mb-3 flex items-center gap-1.5",children:[e.jsx(zt,{className:"text-amber-400 w-3 h-3"})," Most Used"]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-3",children:vn.map(x=>{const C=x.icon,S=x.events.map(_=>(a||[]).find(P=>
1P.key===_)).filter(Boolean);return S.length===0?null:e.jsxs("div",{className:"bg-gray-800/60 rounded-lg border border-gray-700/60 p-3",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx(C,{className:`w-3.5 h-3.5 ${x.color}`}),e.jsx("span",{className:"text-xs font-semibold text-white",children:x.title})]}),e.jsx("div",{className:"space-y-1",children:S.map(_=>{const P=et[_.key]||_.label;return e.jsxs("button",{onClick:()=>b(_),className:"w-full text-left flex items-center gap-2 px-2.5 py-1.5 rounded-md hover:bg-gray-700/60 transition-colors group",children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-gray-600 group-hover:bg-teal-400 flex-shrink-0 transition-colors"}),e.jsx("span",{className:"text-xs text-gray-300 group-hover:text-white transition-colors truncate",children:P})]},_.key)})})]},x.title)})})]}),e.jsx("div",{className:"px-6 pb-2",children:e.jsx("div",{className:"border-t border-gray-700/60"})}),e.jsx("div",{className:"px-6 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2 overflow-x-auto pb-1 scrollbar-thin",children:[e.jsx("button",{onClick:()=>D(null),className:`flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-medium transition-colors ${J?"bg-gray-800 text-gray-400 border border-gray-700 hover:text-white hover:border-gray-600":"bg-teal-600/20 text-teal-300 border border-teal-500/30"}`,children:"All"}),V.map(x=>{const C=x.config.icon,S=J===x.name;return e.jsxs("button",{onClick:()=>D(S?null:x.name),className:`flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-medium transition-colors inline-flex items-center gap-1.5 ${S?"bg-teal-600/20 text-teal-300 border border-teal-500/30":"bg-gray-800 text-gray-400 border border-gray-700 hover:text-white hover:border-gray-600"}`,children:[e.jsx(C,{className:"w-2.5 h-2.5"}),x.name,e.jsx("span",{className:`text-[10px] ${S?"text-teal-400":"text-gray-600"}`,children:x.options.length})]},x.name)})]})}),e.jsx("div",{className:"px-6 pb-4 max-h-[340px] overflow-y-auto",children:e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3",children:H.map(x=>{const C=x.config.icon;return e.jsxs("div",{className:`rounded-lg p-3 border ${x.config.borderColor} ${x.config.bgColor}`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2.5",children:[e.jsx("div",{className:`w-6 h-6 rounded flex items-center justify-center ${x.config.bgColor}`,children:e.jsx(C,{className:`w-3 h-3 ${x.config.color}`})}),e.jsx("h4",{className:`text-sm font-bold bg-clip-text text-transparent bg-gradient-to-r ${x.config.gradient}`,children:x.name}),e.jsx("span",{className:"text-[10px] text-gray-600 ml-auto",children:x.options.length})]}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:x.options.map(S=>{const _=S._display||S.label,P=ca[S.key]||"";return e.jsxs("button",{onClick:()=>b(S),className:"relative flex items-center bg-gray-900/60 hover:bg-gray-700 border border-gray-700/60 hover:border-gray-600 rounded-lg px-2.5 py-1.5 text-xs text-gray-300 hover:text-white transition-all group",title:P||S.key,children:[_,P&&e.jsx("span",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 px-2.5 py-1.5 bg-gray-900 border border-gray-600 text-gray-300 text-[10px] rounded-md whitespace-nowrap opacity-0 pointer-events-none group-hover:opacity-100 transition-opacity shadow-lg z-10 max-w-[200px] text-center leading-relaxed whitespace-normal",children:P})]},S.key)})})]},x.name)})})})]})]})});return e.jsxs("div",{className:"p-4 flex flex-col items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:$,disabled:!m,title:f?"Failed to load event types":m?void 0:"Loading event types…",className:"inline-flex items-center gap-2 px-4 py-2.5 rounded-lg bg-gradient-to-r from-teal-600 to-blue-700 hover:from-teal-500 hover:to-blue-600 text-white font-medium text-sm transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(ze,{className:"w-3 h-3"})," Add Stage"]}),!m&&f&&e.jsxs("div",{className:"flex items-center gap-2 text-xs text-red-400",children:[e.jsx("span",{children:"Failed to load event types."}),e.jsx("button",{type:"button",onClick:w,className:"underline hover:text-red-300",children:"Retry"})]}),!m&&!f&&e.jsx("span",{className:"text-xs text-gray-500",children:"Loading event types…"}),r?te:null]})};function Cn({events:a=[],onDragEnd:f,onRemove:w,onAddBehavior:E,onUpdateBehavior:y,onRemoveBehavior:g,onUpdateEvent:r,behaviorTypes:O=[],smsTemplates:m=[],onOpenSmsM
1anager:h,availableTags:F=[],tagsLoading:J=!1,emailTemplates:D=[],onRefreshTags:$,agreementDefinitions:u=[],agreementDefinitionsLoading:b=!1,catalog:V,catalogError:Q,onRetryCatalog:H,selectedEventKey:te,onChangeSelectedEventKey:x,onAdd:C}){return e.jsxs("div",{children:[e.jsx(gn,{onDragEnd:f,children:e.jsx(pn,{droppableId:"flow-events",children:S=>e.jsxs("div",{ref:S.innerRef,...S.droppableProps,children:[a.map((_,P)=>e.jsxs(Ma.Fragment,{children:[P>0&&e.jsx("div",{className:"flex justify-center py-1",children:e.jsxs("div",{className:"flex flex-col items-center gap-0.5 text-gray-500",children:[e.jsx("div",{className:"w-px h-2 bg-gray-600"}),e.jsx(ea,{className:"text-xs"}),e.jsx("div",{className:"w-px h-2 bg-gray-600"})]})}),e.jsx(mn,{draggableId:_.id,index:P,children:(ge,be)=>e.jsx(kn,{ev:_,index:P,provided:ge,snapshot:be,onRemove:w,onAddBehavior:E,onUpdateBehavior:y,onRemoveBehavior:g,onUpdateEvent:r,behaviorTypes:O,smsTemplates:m,onOpenSmsManager:h,availableTags:F,tagsLoading:J,emailTemplates:D,onRefreshTags:$,agreementDefinitions:u,agreementDefinitionsLoading:b,catalog:V})})]},_.id)),S.placeholder]})})}),V&&e.jsxs("div",{className:"flex flex-col items-center pb-4",children:[a.length>0&&e.jsxs("div",{className:"flex flex-col items-center gap-0.5 text-gray-500 py-1",children:[e.jsx("div",{className:"w-px h-2 bg-gray-600"}),e.jsx(ea,{className:"text-xs"}),e.jsx("div",{className:"w-px h-2 bg-gray-600"})]}),e.jsx(va,{catalog:V,catalogError:Q,onRetryCatalog:H,selectedEventKey:te,onChangeSelectedEventKey:x,onAdd:C})]})]})}const Sn=({isOpen:a,onClose:f,flowName:w,onChangeFlowName:E,selectedFlowId:y,selectedFlow:g,onTogglePaused:r,events:O,onDragEnd:m,onRemove:h,onAddBehavior:F,onUpdateBehavior:J,onRemoveBehavior:D,onUpdateEvent:$,behaviorTypes:u,smsTemplates:b,onOpenSmsManager:V,emailTemplates:Q,availableTags:H,tagsLoading:te,onRefreshTags:x,agreementDefinitions:C,agreementDefinitionsLoading:S,catalog:_,catalogError:P,onRetryCatalog:ge,selectedEventKey:be,onChangeSelectedEventKey:ne,onAdd:v,onSave:z,onReset:ae,onSendTest:R,isSaving:X,isSendingTest:se,hasUnsavedChanges:Ce,dateRange:_e,onChangeDateRange:B,isMobile:ke})=>{const[Ge,Z]=l.useState(!1);if(!a)return null;const pe=y&&!!(g!=null&&g.paused),je=()=>{pe?Z(!0):z()},Se=async()=>{Z(!1),await r(y,!0),z()},Ae=()=>{Z(!1),z()},Ne=W=>{W.target===W.currentTarget&&f()};return _a.createPortal(e.jsx("div",{className:"fixed inset-0 z-[5000] flex items-start justify-center overflow-y-auto",style:{backgroundColor:"#020617"},onClick:Ne,children:e.jsxs("div",{className:"w-full max-w-5xl my-4 mx-4 rounded-xl border border-gray-700 shadow-2xl flex flex-col",style:{minHeight:"70vh",maxHeight:"92vh",backgroundColor:"var(--app-bg)"},onClick:W=>W.stopPropagation(),children:[e.jsxs("div",{className:"p-4 bg-gray-800 border-b border-gray-700 rounded-t-xl flex flex-col md:flex-row gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-1 min-w-0",children:[e.jsx("input",{type:"text",value:w,onChange:W=>E(W.target.value),placeholder:"Enter flow name…",className:"px-3 py-2 bg-gray-900 border border-gray-600 rounded-lg text-white text-sm focus:outline-none focus:ring-2 focus:ring-teal-500 flex-1 min-w-0"}),Ce&&e.jsx("span",{className:"text-xs text-yellow-400 whitespace-nowrap",children:"Unsaved changes"})]}),e.jsxs("div",{className:"flex items-center gap-3 flex-shrink-0",children:[y&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-gray-400 text-xs",children:"Active"}),e.jsx(at,{enabled:!(g!=null&&g.paused),onChange:()=>{y&&r(y,!!(g!=null&&g.paused))}})]}),e.jsx("button",{type:"button",onClick:f,className:"p-2 rounded-lg text-gray-400 hover:text-white hover:bg-gray-700 transition-colors",title:"Close",children:e.jsx(ka,{className:"w-5 h-5"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",style:{backgroundColor:"var(--app-bg)"},children:O.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center p-12 text-center",children:[e.jsx("div",{className:"mb-4 w-14 h-14 rounded-full bg-gray-800 border border-gray-700 flex items-center justify-center",children:e.jsx(ze,{className:"w-5 h-5 text-gray-500"})}),e.jsx("h4",{className:"text-white font-medium mb-2",children:"No stages yet"}),e.jsx("p",{className:"text-gray-500 text-sm mb-4 max-w-sm",children:"Add your first event trigger, then configure actions for each stage."}),e.jsx(va,{catalog:_,catalogError:P,onRetryCatalog:ge,selectedEventKey:be,onChangeSelectedEventKey:ne,onAdd:v})]}):e.jsx(Cn,{events:O,onDragEnd:m,onRemove:h,onAddBehavior:F,onUpdateBehavior:J,onRemoveBehavior:D,onUpdateEvent:$,behaviorTypes:u,smsTemplates:b,onOpenSmsM
1anager:V,availableTags:H,tagsLoading:te,emailTemplates:Q,onRefreshTags:x,agreementDefinitions:C,agreementDefinitionsLoading:S,catalog:_,catalogError:P,onRetryCatalog:ge,selectedEventKey:be,onChangeSelectedEventKey:ne,onAdd:v})}),e.jsxs("div",{className:"p-3 md:p-4 bg-gray-800 border-t border-gray-700 rounded-b-xl flex flex-col md:flex-row items-stretch md:items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("label",{className:"text-gray-400 text-xs whitespace-nowrap flex items-center gap-1",children:["Stage Stats",e.jsxs("span",{className:"relative group",children:[e.jsx(Rt,{className:"text-gray-500 hover:text-gray-300 cursor-help"}),e.jsx("span",{className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-1.5 px-2.5 py-1.5 bg-gray-900 border border-gray-600 text-gray-300 text-[11px] rounded-md whitespace-nowrap opacity-0 pointer-events-none group-hover:opacity-100 transition-opacity shadow-lg z-10",children:"Date range for trigger & funnel counts on each stage"})]})]}),e.jsxs("select",{value:_e,onChange:W=>B(W.target.value),className:"px-2 py-1.5 bg-gray-900 border border-gray-600 rounded text-white text-xs focus:outline-none focus:ring-2 focus:ring-teal-500",children:[e.jsx("option",{value:"today",children:"Today"}),e.jsx("option",{value:"yesterday",children:"Yesterday"}),e.jsx("option",{value:"last_7_days",children:"Last 7 days"}),e.jsx("option",{value:"this_month",children:"This Month"}),e.jsx("option",{value:"last_month",children:"Last Month"}),e.jsx("option",{value:"last_90_days",children:"Last 90 Days"}),e.jsx("option",{value:"all_time",children:"All Time"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[e.jsxs("button",{onClick:ae,disabled:!y,className:`px-3 py-2 rounded-lg text-white text-xs inline-flex items-center gap-1.5 border border-gray-600 whitespace-nowrap ${y?"bg-gray-700 hover:bg-gray-600":"bg-gray-700 cursor-not-allowed opacity-50"}`,title:"Reset flow to last saved version",children:[e.jsx($a,{className:"text-xs"})," Reset"]}),e.jsxs("button",{onClick:R,className:`px-3 py-2 rounded-lg text-white font-medium text-xs inline-flex items-center gap-1.5 transition-all whitespace-nowrap ${se||O.length===0?"bg-gray-600 cursor-not-allowed opacity-60":"bg-gradient-to-r from-purple-600 to-pink-600 hover:from-purple-500 hover:to-pink-500"}`,title:"Preview all behaviors using real event data",children:[e.jsx(ja,{className:"text-xs"})," ",se?"Loading…":"Preview"]}),e.jsxs("button",{onClick:je,disabled:X,className:`px-4 py-2 rounded-lg text-white font-medium text-xs inline-flex items-center gap-1.5 transition-all whitespace-nowrap ${X?"bg-gray-600 cursor-not-allowed":"bg-gradient-to-r from-teal-600 to-blue-700 hover:from-teal-500 hover:to-blue-600"}`,children:[e.jsx(Ra,{className:"text-xs"})," ",X?"Saving…":"Save Flow"]})]}),Ge&&e.jsxs("div",{className:"col-span-full flex flex-col sm:flex-row items-stretch sm:items-center justify-between gap-2 mt-2 p-3 bg-yellow-900/30 border border-yellow-700/50 rounded-lg",children:[e.jsx("p",{className:"text-yellow-300 text-xs",children:"This flow is not active. It won't run until activated."}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx("button",{onClick:()=>Z(!1),className:"px-3 py-1.5 rounded-lg text-gray-300 text-xs border border-gray-600 hover:bg-gray-700 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:Ae,className:"px-3 py-1.5 rounded-lg text-white text-xs bg-gray-600 hover:bg-gray-500 transition-colors",children:"Save Inactive"}),e.jsx("button",{onClick:Se,className:"px-3 py-1.5 rounded-lg text-white text-xs font-medium bg-gradient-to-r from-teal-600 to-blue-700 hover:from-teal-500 hover:to-blue-600 transition-all",children:"Activate & Save"})]})]})]})]})}),document.body)},ga=/^[^\s@]+@[^\s@]+\.[^\s@]+$/,pa="flowTestEmailAddress",An={email:{label:"Client Email",icon:Ve,color:"text-blue-400",bg:"bg-blue-500/10 border-blue-500/30"},staff_email:{label:"Staff Email",icon:ta,color:"text-purple-400",bg:"bg-purple-500/10 border-purple-500/30"},sms:{label:"Client SMS",icon:Le,color:"text-green-400",bg:"bg-green-500/10 border-green-500/30"}
1,staff_sms:{label:"Staff SMS",icon:ta,color:"text-amber-400",bg:"bg-amber-500/10 border-amber-500/30"},smart_engagement:{label:"Smart Engagement",icon:Le,color:"text-teal-400",bg:"bg-teal-500/10 border-teal-500/30"},add_tag:{label:"Add Tag",icon:ft,color:"text-yellow-400",bg:"bg-yellow-500/10 border-yellow-500/30"},remove_tag:{label:"Remove Tag",icon:ft,color:"text-red-400",bg:"bg-red-500/10 border-red-500/30"}};function Fn(a){if(!a)return"N/A";try{return new Date(a).toLocaleString()}catch{return a}}function Dn({eventRow:a}){const[f,w]=l.useState(!1);return a?e.jsxs("div",{className:"mt-2 mb-3",children:[e.jsxs("button",{onClick:()=>w(!f),className:"inline-flex items-center gap-1.5 text-xs text-teal-400 hover:text-teal-300 transition-colors cursor-pointer",children:[e.jsx(za,{className:"w-3 h-3"}),e.jsx("span",{className:"underline underline-offset-2",children:"View Event Row Data"}),f?e.jsx(fa,{className:"w-2.5 h-2.5"}):e.jsx(ha,{className:"w-2.5 h-2.5"})]}),f&&e.jsx("textarea",{readOnly:!0,value:JSON.stringify(a,null,2),className:"mt-2 w-full bg-gray-900 border border-gray-700 rounded-lg p-3 text-xs text-gray-300 font-mono resize-y focus:outline-none focus:ring-1 focus:ring-teal-500",style:{minHeight:"120px",maxHeight:"400px"}})]}):null}function Pn({preview:a}){const[f,w]=l.useState(()=>{try{return localStorage.getItem(pa)||localStorage.getItem("currentUserEmail")||""}catch{return""}}),[E,y]=l.useState(""),[g,r]=l.useState(!1),[O,m]=l.useState(null),h=!a.client_id,F=a.template_found!==!1,J=async()=>{const D=(f||"").trim();if(!ga.test(D)){m({type:"error",message:"Enter a valid email address."});return}const $=(E||"").trim();if(h&&!ga.test($)){m({type:"error",message:"Enter the contact's email address to build the test email from."});return}r(!0),m(null);try{try{localStorage.setItem(pa,D)}catch{}const u=await fetch(`${K}/api_new/admin/flow-profiles/test-send-email`,{method:"POST",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({to:D,...h?{client_email:$}:{client_id:a.client_id},step_type:a.step_type,behavior:{type:"send_email",config:a.behavior_config||{}}})}),b=await u.json().catch(()=>({}));if(!u.ok||!b.success)throw new Error(b.message||b.error||"Failed to send test email");const V=Array.isArray(b.recipients)?b.recipients.length:1;m({type:"success",message:`Sent ${V>1?`${V} copies`:""} to ${D}${b.kyc_link_included?" with a live verification link":""}.`.replace("  "," ")})}catch(u){m({type:"error",message:u.message})}finally{r(!1)}};return e.jsxs("div",{className:"mt-3 pt-3 border-t border-gray-700/60",children:[e.jsxs("div",{className:"text-xs text-gray-400 mb-2",children:["Send this exact email to a test mailbox (uses ",a.client_name||"this contact","'s real data):"]}),h&&e.jsx("input",{type:"email",value:E,onChange:D=>{y(D.target.value),m(null)},placeholder:"Contact to build it from, e.g. [email protected]",disabled:!F||g,className:"w-full mb-2 bg-gray-900 border border-gray-700 rounded-lg px-3 py-1.5 text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:ring-1 focus:ring-teal-500 disabled:opacity-50"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{type:"email",value:f,onChange:D=>{w(D.target.value),m(null)},placeholder:"[email protected]",disabled:!F||g,className:"flex-1 min-w-[200px] bg-gray-900 border border-gray-700 rounded-lg px-3 py-1.5 text-xs text-gray-200 placeholder-gray-600 focus:outline-none focus:ring-1 focus:ring-teal-500 disabled:opacity-50"}),e.jsxs("button",{type:"button",onClick:J,disabled:!F||g,className:"inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium bg-teal-600 hover:bg-teal-500 text-white transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[e.jsx(ja,{className:"w-3 h-3"}),g?"Sending…":"Send test email"]})]}),!F&&e.jsx("div",{className:"mt-2 text-xs text-yellow-500",children:"Select a template on this action before sending a test."}),F&&h&&e.jsx("div",{className:"mt-2 text-xs text-gray-500",children:"No contact has triggered this step yet, so name one above — the test email is built from their real data."}),O&&e.jsxs("div",{className:`mt-2 text-xs flex items-start gap-1.5 ${O.type==="success"?"text-green-400":"text-red-400"}`,children:[O.type==="success"?e.jsx(ht,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}):e.jsx(bt,{className:"w-3 h-3 mt-0.5 flex-shrink-0"}),e.jsx("span",{children:O.message})]})]})}function En({preview:a}){const[f,w]=l.useState(!1),E=An[a.channel]||{label:a.channel||a.behavior_type,icon:Ve,color:"text-gray-400",bg:"bg-gray-500/10 border-gray-500/30"},y=E.icon,g=a.channel==="email"||a.channel==="staff_email",r=a.channel==="sms"||a.channel==="staff_sms"||a.channel==="smart_engagement",O=a.channel==="add_tag"||a.channel==="remove_tag";return e.jsxs("div",{className:`rounded-lg border ${E.bg} p-4`,children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx(y,{className:`w-4 h-4 ${E.color}`}),e.jsx("span",{className:`text-sm font-medium ${E.color}`,children:E.label}),e.jsxs("span",{className:"text-gray-500 text-xs ml-auto",children:["Step: ",Yt(a.step_type)]})]}),e.jsx("div",{className:"flex items-center gap-3 mb-3 text-xs text-gray-500",children:a.event_found?e.jsx(e.Fragment,{children:e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(La,{className:"w-3 h-3"})," Event: ",Fn(a.event_created_at)]})}):e.jsxs("span",{className:"flex items-center gap-1 text-yellow-500",children:[e.jsx(bt,{className:"w-3 h-3"})," No event found for this step type"]})}),e.jsx(Dn,{eventRow:a.event_row}),a.to&&e.jsxs("div",{className:"mb-2 text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"To: "}),e.jsx("span",{className:"text-gray-300",children:a.recipient_name?`${a.recipient_name} <${a.to}>`:a.to})]}),a.kyc_link&&e.jsxs("div",{className:"mb-2 text-xs flex items-start gap-1.5",children:[e.jsx(Va,{className:"w-3 h-3 mt-0.5 text-teal-400 flex-shrink-0"}),e.jsx("span",{className:"text-gray-500",children:"Verification link: "}),e.jsx("a",{href:a.kyc_link,target:"_blank",rel:"noopener noreferrer",className:"text-teal-400 hover:text-teal-300 underline underline-offset-2 break-all",children:a.kyc_link})]}),a.template_key&&e.jsxs("div",{className:"mb-2 text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Template: "}),e.jsx("span",{className:"text-gray-300",children:a.template_name||a.template_key}),a.template_found===!1&&e.jsx("span",{className:"text-red-400 ml-2",children:"(not found)"})]}),g&&e.jsxs("div",{className:"mt-3 space-y-2",children:[a.subject&&e.jsxs("div",{className:"text-xs",children:[e.jsx("span",{className:"text-gray-500",children:"Subject: "}),e.jsx("span",{className:"text-white font-medium",children:a.subject})]}),e.jsxs("div",{className:"flex gap-2 mb-2",children:[e.jsx("button",{onClick:()=>w(!1),className:`px-2 py-1 rounded text-xs transition-colors ${f?"bg-gray-800 text-gray-400 hover:text-white":"bg-gray-600 text-white"}`,children:"Preview"}),e.jsx("button",{onClick:()=>w(!0),className:`px-2 py-1 rounded text-xs transition-colors ${f?"bg-gray-600 text-white":"bg-gray-800 text-gray-400 hover:text-white"}`,children:"HTML Source"})]}),f?e.jsx("pre",{className:"bg-gray-900 border border-gray-700 rounded-lg p-3 text-xs text-gray-300 overflow-x-auto max-h-64 overflow-y-auto whitespace-pre-wrap break-words",children:a.html||"(empty)"}):e.jsx("div",{className:"bg-white rounded-lg p-4 text-sm max-h-80 overflow-y-auto",dangerouslySetInnerHTML:{__html:a.html||'<p style="color:#999">(empty)</p>'}}),a.channel==="email"&&e.jsx(Pn,{preview:a})]}),r&&e.jsx("div",{className:"mt-3",children:e.jsx("div",{className:"bg-gray-900 border border-gray-700 rounded-lg p-3 text-sm text-gray-200 whitespace-pre-wrap",children:a.content||"(empty)"})}),O&&e.jsxs("div",{className:"mt-3 text-sm text-gray-300",children:[a.channel==="add_tag"?"Will add tag: ":"Will remove tag: ",e.jsx("span",{className:"font-medium text-white",children:a.tag_name||`#${a.tag_id}`})]}),a.error&&e.jsxs("div",{className:"mt-3 text-xs text-red-400 bg-red-500/10 border border-red-500/30 rounded-lg p-2",children:["Error: ",a.error]}),a.note&&e.jsx("div",{className:"mt-3 text-xs text-gray-500 italic",children:a.note})]})}function Tn({isOpen:a,onClose:f,previewData:w}){if(!a||!w)return null;const{flow_name:E,business_prefix:y,steps_count:g,previews:r=[]}=w,O={};for(const h of r){const F=`${h.step_index}_${h.step_type}`;O[F]||(O[F]={step_index:h.step_index,step_type:h.step_type,items:[]}),O[F].items.push(h)}const m=Object.values(O).sort((h,F)=>h.step_index-F.step_index);return _a.createPortal(e.jsx("div",{className:"fixed inset-0 z-[6000] flex items-start justify-center overflow-y-auto",style:{backgroundColor:"rgba(2, 6, 23, 0.85)",backdropFilter:"blur(6px)"},onClick:h=>{h.target===h.currentTarget&&f()},children:e.jsxs("div",{className:"w-full max-w-4xl my-6 mx-4 rounded-xl border border-gray-700 bg-gray-850 shadow-2xl flex flex-col",style:{maxHeight:"90vh"},onClick:h=>h.stopPropagation(),children:[e.jsxs("div",{className:"p-4 bg-gray-800 border-b border-gray-700 rounded-t-xl flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-white font-semibold text-lg",children:"Flow Preview"}),e.jsxs("p",{className:"text-gray-400 text-xs mt-0.5",children:[E," · ",g," step",g!==1?"s":""," · ",r.length," behavior",r.length!==1?"s":""," · ",y]})]}),e.jsx("button",{onClick:f,className:"p-2 rounded-lg text-gray-400 hover:text-white hover:bg-gray-700 transition-colors",children:e.jsx(ka,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-4 space-y-6",children:r.length===0?e.jsxs("div",{className:"text-center py-12 text-gray-500",children:[e.jsx(bt,{className:"w-8 h-8 mx-auto mb-3 text-yellow-500"}),e.jsx("p",{className:"text-sm",children:"No behaviors found to preview."}),e.jsx("p",{className:"text-xs mt-1",children:"Add behaviors to your flow steps, then try again."})]}):m.map(h=>e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"w-6 h-6 rounded-full bg-gray-700 text-gray-300 text-xs font-bold flex items-center justify-center",children:h.step_index+1}),e.jsx("span",{className:"text-gray-300 text-sm font-medium",children:Yt(h.step_type)})]}),e.jsx("div",{className:"space-y-3 ml-8",children:h.items.map((F,J)=>e.jsx(En,{preview:F},J))})]},`${h.step_index}_${h.step_type}`))}),e.jsxs("div",{className:"p-3 bg-gray-800 border-t border-gray-700 rounded-b-xl flex items-center justify-between",children:[e.jsx("p",{className:"text-gray-500 text-xs",children:"Data sourced from the latest real events. Nothing is sent unless you use “Send test email” on an email action."}),e.jsx("button",{onClick:f,className:"px-4 py-2 rounded-lg text-white text-xs font-medium bg-gray-700 hover:bg-gray-600 transition-colors",children:"Close"})]})]})}),document.body)}const de=[];for(let a=0;a<256;++a)de.push((a+256).toString(16).slice(1));
1function On(a,f=0){return(de[a[f+0]]+de[a[f+1]]+de[a[f+2]]+de[a[f+3]]+"-"+de[a[f+4]]+de[a[f+5]]+"-"+de[a[f+6]]+de[a[f+7]]+"-"+de[a[f+8]]+de[a[f+9]]+"-"+de[a[f+10]]+de[a[f+11]]+de[a[f+12]]+de[a[f+13]]+de[a[f+14]]+de[a[f+15]]).toLowerCase()}let Ot;const In=new Uint8Array(16);function Mn(){if(!Ot){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ot=crypto.getRandomValues.bind(crypto)}return Ot(In)}const $n=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ma={randomUUID:$n};function We(a,f,w){var y;if(ma.randomUUID&&!a)return ma.randomUUID();a=a||{};const E=a.random??((y=a.rng)==null?void 0:y.call(a))??Mn();if(E.length<16)throw new Error("Random bytes length must be >= 16");return E[6]=E[6]&15|64,E[8]=E[8]&63|128,On(E)}async function ua(){const a=await fetch(`${K}/api_new/admin/business/email-template/library`,{method:"GET",headers:re()});if(!a.ok)throw new Error(`Failed to load Email templates (${a.status})`);const f=await a.json();return Array.isArray(f==null?void 0:f.data)?f.data:[]}const It={send_email:Ve,phone_call:Gt,schedule_meeting:Wa,create_task:qa,verify_client:tt,attach_document:Vt,checklist_review:Ja,send_message:Le,assign_location:wa,notify_team:Ha,auto_enrich:Ya,research:nt,approve:ht,prioritize:ut,property_shortlist:zt,property_approve:Ga,property_rejected:aa,"backend|aml_idv|link_created":tt,"backend|aml_idv|submitted":tt,"backend|aml_idv|approved":ht,"backend|aml_idv|rejected":aa},Mt=(a="")=>Yt(a),ls=()=>{const[a,f]=l.useState([]),[w,E]=l.useState(!1),[y,g]=l.useState([]),[r,O]=l.useState(""),[m,h]=l.useState(!1),[F,J]=l.useState([]),[D,$]=l.useState(null),[u,b]=l.useState(""),[V,Q]=l.useState(!1),[H,te]=l.useState("last_7_days"),[x,C]=l.useState(!1),[S,_]=l.useState(!1),[P,ge]=l.useState([]),[be,ne]=l.useState(!1),[v,z]=l.useState([]),[ae,R]=l.useState(!1),[X,se]=l.useState([]),[Ce,_e]=l.useState(!1),[B,ke]=l.useState([]),[Ge,Z]=l.useState(!1),[pe,je]=l.useState(!1),[Se,Ae]=l.useState(null),[Ne,W]=l.useState(!1),[Ee,Te]=l.useState([]),[st,ye]=l.useState(!1),[_t,xe]=l.useState(!1),Oe=xa(),[U,rt]=l.useState(""),[it,Ke]=l.useState(!1),[we,ie]=l.useState({key:null,direction:null}),lt=async()=>{_e(!0);try{const s=await fetch(`${K}/api_new/admin/tags`,{headers:{...re()}});if(!s.ok)throw new Error(`tags ${s.status}`);const i=await s.json(),n=Array.isArray(i==null?void 0:i.data)?i.data:[];se(n)}catch{se([])}finally{_e(!1)}},kt=l.useMemo(()=>Object.fromEntries((a||[]).map(s=>[s.key,s])),[a]),jt=l.useMemo(()=>(F||[]).find(s=>s.id===D)||null,[F,D]),Qe=l.useMemo(()=>[{value:"send_email",label:"Send Email"},{value:"propora_smart",label:"SMART SMS"},{value:"add_tag",label:"Add Tag"},{value:"remove_tag",label:"Remove Tag"},{value:"staff_email",label:"Staff Email"},{value:"staff_sms",label:"Staff SMS"},{value:"send_agreement",label:"Send Agreement"},{value:"send_kyc_link",label:"Send KYC Link"},{value:"partner_email",label:"Send Partner Email"},{value:"partner_sms",label:"Send Partner SMS"}],[]),Ye=l.useCallback(async({isMounted:s=()=>!0}={})=>{var i;try{const n=`${K}/api_new/admin/client/event-types`,o=await fetch(n,{method:"POST",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({})});if(!o.ok)throw new Error(`Failed to load event types (${o.status})`);const c=await o.json(),L=(Array.isArray(c==null?void 0:c.event_types)?c.event_types:[]).map(oe=>typeof oe=="string"?oe:oe==null?void 0:oe.event_type).filter(Boolean).map(oe=>({key:oe,label:Mt(oe),icon:It[oe]||ut}));s()&&(f(L),O(((i=L[0])==null?void 0:i.key)||""),g(oe=>oe&&oe.length?oe:[]),E(!1))}catch{s()&&(f([]),E(!0)),he.error("Failed to load event types — click Retry to try again")}},[]);l.useEffect(()=>{let s=!0;return Ye({isMounted:()=>s}),()=>{s=!1}},[Ye]);const wt=l.useCallback(()=>{Ye()},[Ye]);l.useEffect(()=>{let s=!0;return(async()=>{try{ne(!0);const n=await na();s&&ge(Array.isArray(n)?n:[])}catch{s&&ge([])}finally{s&&ne(!1)}})(),()=>{s=!1}},[]),l.useEffect(()=>{let s=!0;return(async()=>{try{R(!0);const n=await ua();s&&z(Array.isArray(n)?n:[])}catch{s&&z([])}finally{s&&R(!1)}})(),()=>{s=!1}},[]),l.useEffect(()=>{let s=!0;return(async()=>
1{if(!x)try{const n=await na();s&&ge(Array.isArray(n)?n:[])}catch{}})(),()=>{s=!1}},[x]),l.useEffect(()=>{let s=!0;return(async()=>{if(!S)try{const n=await ua();s&&z(Array.isArray(n)?n:[])}catch{}})(),()=>{s=!1}},[S]),l.useEffect(()=>{let s=!0;return(async()=>await lt())(),()=>{s=!1}},[]),l.useEffect(()=>{let s=!0;return(async()=>{Z(!0);try{const n=await fetch(`${K}/api/contracts/definitions?limit=100`,{headers:{Authorization:`Bearer ${localStorage.getItem("token")}`}});if(!n.ok)throw new Error(`Failed to load agreement definitions (${n.status})`);const o=await n.json();s&&ke(Array.isArray(o==null?void 0:o.definitions)?o.definitions:[])}catch{s&&ke([])}finally{s&&Z(!1)}})(),()=>{s=!1}},[]);const vt=s=>{g(i=>(i||[]).map(n=>{var c;if(n.id!==s)return n;const o=(n.behaviors||[]).concat([{id:We(),kind:((c=Qe[0])==null?void 0:c.value)||"send_email",lagMinutes:0,skipIfNextCompleted:!0,fieldCondition:null,config:null}]);return{...n,behaviors:o}}))},ot=(s,i,n)=>{g(o=>(o||[]).map(c=>{if(c.id!==s)return c;const p=(c.behaviors||[]).map(N=>N.id===i?{...N,...n}:N);return{...c,behaviors:p}}))},He=(s,i)=>{g(n=>(n||[]).map(o=>{if(o.id!==s)return o;const c=(o.behaviors||[]).filter(p=>p.id!==i);return{...o,behaviors:c}}))},Nt=(s,i)=>{g(n=>(n||[]).map(o=>o.id!==s?o:{...o,...i}))},Ze=s=>{const i=new Date,n=o=>{const c=o.getFullYear(),p=String(o.getMonth()+1).padStart(2,"0"),N=String(o.getDate()).padStart(2,"0");return`${c}-${p}-${N}`};switch(s){case"today":return{startDate:n(new Date(i.getFullYear(),i.getMonth(),i.getDate())),endDate:n(i)};case"yesterday":const o=new Date(i.getFullYear(),i.getMonth(),i.getDate()-1);return{startDate:n(o),endDate:n(o)};case"last_7_days":return{days:7};case"this_month":const c=new Date(i.getFullYear(),i.getMonth(),1);return{startDate:n(c),endDate:n(i)};case"last_month":const p=new Date(i.getFullYear(),i.getMonth()-1,1),N=new Date(i.getFullYear(),i.getMonth(),0);return{startDate:n(p),endDate:n(N)};case"last_90_days":return{days:90};case"all_time":return{days:null};default:return{days:7}}},Fe=async(s,i="last_7_days")=>{try{const n=(s||[]).slice().sort((ce,Y)=>ce.order-Y.order),o=n.map(ce=>({type:ce.type}));if(!o.length)return;const c=Ze(i),p=`${K}/api_new/admin/client/event-types/funnel`,N=await fetch(p,{method:"POST",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({steps:o,lastDays:c.days,startDate:c.startDate,endDate:c.endDate})});if(!N.ok)throw new Error(`Failed to fetch funnel counts (${N.status})`);const L=await N.json(),oe=Array.isArray(L==null?void 0:L.counts)?L.counts:[],Dt=Array.isArray(L==null?void 0:L.email_counts)?L.email_counts:[],Pt=Array.isArray(L==null?void 0:L.phone_counts)?L.phone_counts:[],pt=Array.isArray(L==null?void 0:L.clients_by_step)?L.clients_by_step:[],ue=Array.isArray(L==null?void 0:L.email_clients_by_step)?L.email_clients_by_step:[],Ht=Array.isArray(L==null?void 0:L.phone_clients_by_step)?L.phone_clients_by_step:[],Jt=new Map(n.map((ce,Y)=>[ce.id,oe[Y]??0])),qt=new Map(n.map((ce,Y)=>[ce.id,Dt[Y]??void 0])),Wt=new Map(n.map((ce,Y)=>[ce.id,Pt[Y]??void 0])),Kt=new Map(n.map((ce,Y)=>[ce.id,Array.isArray(pt[Y])?pt[Y]:[]])),Qt=new Map(n.map((ce,Y)=>[ce.id,Array.isArray(ue[Y])?ue[Y]:[]])),Zt=new Map(n.map((ce,Y)=>[ce.id,Array.isArray(Ht[Y])?Ht[Y]:[]]));g(ce=>(ce||[]).map(Y=>({...Y,funnelCount:Jt.has(Y.id)?Jt.get(Y.id):Y.funnelCount,funnelEmailCount:qt.has(Y.id)?qt.get(Y.id):Y.funnelEmailCount,funnelPhoneCount:Wt.has(Y.id)?Wt.get(Y.id):Y.funnelPhoneCount,funnelClients:Kt.has(Y.id)?Kt.get(Y.id):Y.funnelClients,funnelEmailClients:Qt.has(Y.id)?Qt.get(Y.id):Y.funnelEmailClients,funnelPhoneClients:Zt.has(Y.id)?Zt.get(Y.id):Y.funnelPhoneClients})))}catch{}},Je=(s=[])=>(Array.isArray(s)?s:[]).map(n=>typeof n=="string"?{type:n}:n).map((n,o)=>{const c=(n==null?void 0:n.type)||"",p=It[c]||ut,N=Mt(c),oe=(Array.isArray(n==null?void 0:n.behaviors)?n.behaviors:[]).map(ue=>({id:We(),kind:ue.kind||ue.type||"send_email",lagMinutes:typeof ue.lagMinutes=="number"?ue.lagMinutes:typeof ue.lag_minutes=="number"?ue.lag_minutes:0,skipIfNextCompleted:typeof ue.skipIfNextCompleted=="boolean"?ue.skipIfNextCompleted:typeof ue.skip_if_next_completed=="boolean"?ue.skip_if_next_completed:!0,fieldCondition:ue.fieldCondition||ue.field_condition||null,config:ue.config||null})),Dt=(n==null?void 0:n.run_flow_event_for_tags)||"",Pt=(n==null?void 0:n.run_flow_event_for_agreement_definitions)||"",pt=(n==null?void 0:n.skip_flow_event_if_completed)||"";return{id:We(),type:c,label:N,icon:p,order:o,count:void 0,funnelCount:void 0,behaviors:oe,run_flow_event_for_tags:Dt,run_flow_event_for_agreement_definitions:Pt,skip_flow_event_if_completed:pt}}),Re=async(s,i=H)=>{try{const n=Array.from(new Set((s||[]).map(p=>
1p.type).filter(Boolean))),o=await Promise.all(n.map(async p=>[p,await ct(p,i)])),c=Object.fromEntries(o);g(p=>(p||[]).map(N=>({...N,count:c[N.type]??N.count})))}catch{}};l.useEffect(()=>{let s=!0;return(async()=>{Q(!0);try{const n=`${K}/api_new/admin/flow-profiles`,o=await fetch(n,{method:"GET",headers:{...re()}});if(!o.ok)throw new Error(`Failed to load profiles (${o.status})`);const c=await o.json(),p=Array.isArray(c==null?void 0:c.data)?c.data:[];if(!s)return;J(p),$(null),b(""),g([])}catch{}finally{s&&Q(!1)}})(),()=>{s=!1}},[]),l.useEffect(()=>{(y||[]).length&&(Re(y,H),Fe(y,H))},[H]),l.useEffect(()=>{if(D&&y.length>0&&Ee.length>0){const s=o=>o.map(c=>({id:c.id,type:c.type,label:c.label,order:c.order,behaviors:c.behaviors||[],run_flow_event_for_tags:c.run_flow_event_for_tags||"",run_flow_event_for_agreement_definitions:c.run_flow_event_for_agreement_definitions||"",skip_flow_event_if_completed:c.skip_flow_event_if_completed||""})),i=JSON.stringify(s(y)),n=JSON.stringify(s(Ee));W(i!==n)}else D&&y.length===0&&Ee.length>0?W(!0):D||W(!1)},[y,Ee,D]),l.useEffect(()=>{const s=i=>{Ne&&(i.preventDefault(),i.returnValue="")};return window.addEventListener("beforeunload",s),()=>window.removeEventListener("beforeunload",s)},[Ne]);const Ie=s=>{if(!s.destination)return;const i=Array.from(y),[n]=i.splice(s.source.index,1);i.splice(s.destination.index,0,n);const o=i.map((c,p)=>({...c,order:p}));g(o),Fe(o,H)},Ct=s=>{let i;g(n=>(i=n.filter(o=>o.id!==s).map((o,c)=>({...o,order:c})),i)),i&&Fe(i,H)},ct=async(s,i=H)=>{const n=Ze(i);try{const o=`${K}/api_new/admin/client/event-types`,c=await fetch(o,{method:"POST",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({event_type:s,lastDays:n.days,startDate:n.startDate,endDate:n.endDate,count:!0,distinct_clients:!0})});if(!c.ok)throw new Error(`Failed to fetch count (${c.status})`);const p=await c.json(),N=Array.isArray(p==null?void 0:p.event_types)?p.event_types[0]:null,L=typeof N=="object"&&N!==null?Number(N.count||0):0;return Number.isFinite(L)?L:0}catch{return 0}},St=async(s=null)=>{const n=kt[s||r]||a[0];if(!n){he.error("Event types are still loading — please try again in a moment.");return}const o={id:We(),type:n.key,label:n.label,icon:n.icon,order:y.length,count:void 0,funnelCount:void 0,behaviors:[]};g(N=>[...N,o]);const c=await ct(n.key,H);let p;g(N=>(p=N.map(L=>L.id===o.id?{...L,count:c}:L),p)),p&&await Fe(p,H)},dt=()=>{D&&(fe(D),he.info("Flow reset to last saved version"))},Xe=()=>{Ne&&D&&!window.confirm("You have unsaved changes. Discard them?")||($(null),b(""),g([]),Te([]),W(!1),xe(!0))},t=s=>{if(Ne&&D&&!window.confirm("You have unsaved changes. Discard them?"))return;const i=s?parseInt(s,10):null;if(i){const n=(F||[]).find(c=>c.id===i);$(i),b((n==null?void 0:n.name)||"");const o=Je((n==null?void 0:n.steps)||[]);g(o),Te(JSON.parse(JSON.stringify(o))),W(!1),Re(o,H),Fe(o,H)}xe(!0)},A=()=>{Ne&&!window.confirm("You have unsaved changes. Discard them?")||(xe(!1),W(!1))},G=async s=>{const i=s??D;if(i)try{const n=`${K}/api_new/admin/flow-profiles/${i}`,o=await fetch(n,{method:"DELETE",headers:{...re()}});if(!o.ok)throw new Error(`Delete failed (${o.status})`);he.success("Flow deleted");const p=await(await fetch(`${K}/api_new/admin/flow-profiles`,{headers:{...re()}})).json(),N=Array.isArray(p==null?void 0:p.data)?p.data:[];J(N),$(null),b(""),g([])}catch{he.error("Failed to delete flow")}},I=async()=>{if(!u||!u.trim()){he.error("Please enter a flow name before saving");return}try{h(!0);const s={name:u.trim(),steps:y.map(p=>({type:p.type,order:p.order,label:p.label,behaviors:p.behaviors||[],run_flow_event_for_tags:p.run_flow_event_for_tags||"",run_flow_event_for_agreement_definitions:p.run_flow_event_for_agreement_definitions||"",skip_flow_event_if_completed:p.skip_flow_event_if_completed||""}))};if(D){const p=`${K}/api_new/admin/flow-profiles/${D}`,N=await fetch(p,{method:"PUT",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({name:s.name,steps:s.steps})});if(N.status===409){he.error("A flow with this name already exists");return}if(!N.ok)throw new Error(`Update failed (${N.status})`);he.success("Flow updated")}else{const p=`${K}/api_new/admin/flow-profiles`,N=await fetch(p,{method:"POST",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({name:s.name,steps:s.steps,paused:!0})});if(N.status===409){he.error("A flow with this name already exists");return}if(!N.ok)throw new Error(`Create failed (${N.status})`);he.success("Flow created")}const n=await(await fetch(`${K}/api_new/admin/flow-profiles`,{headers:{...re()}})).json(),o=Array.isArray(n==null?void 0:n.data)?n.data:[];J(o);const c=o.find(p=>p.name===u.trim());if(c){$(c.id);const p=Je(c.steps||[]);g(p),Te(JSON.parse(JSON.stringify(p))),W(!1),Re(p,H),Fe(p,H)}xe(!1)}catch{he.error("Failed to save flow")}finally{h(!1)}},ee=async(s,i)=>{try{const n=!i,o=`${K}/api_new/admin/flow-profiles/${s}`,c=await fetch(o,{method:"PUT",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({paused:n})});if(!c.ok)throw new Error(`Toggle failed (${c.status})`);J(p=>(p||[]).map(N=>N.id===s?{...N,paused:n}:N)),he.success(n?"Flow paused":"Flow enabled")}catch{he.error("Failed to toggle flow status")}},fe=s=>{const i=s?parseInt(s,10):null;if(i){const n=(F||[]).find(c=>c.id===i);$(i),b((n==null?void 0:n.name)||"");const o=Je((n==null?void 0:n.steps)||[]);g(o),Te(JSON.parse(JSON.stringify(o))),W(!1),Re(o,H),Fe(o,H)}else $(null),b(""),g([]),Te([]),W(!1)},De=async s=>{if(!s)return;const i=F.find(n=>n.id===s);Ae(i),je(!0)},Me=async()=>{Se&&(je(!1),await G(Se.id),Ae(null))},[$e,Be]=l.useState(!1),[d,q]=l.useState(null),[k,T]=l.useState(!1),j=async()=>
1{if(y.length===0){he.error("Add at least one stage before previewing");return}const s=y.map(i=>({type:i.type,behaviors:(i.behaviors||[]).map(n=>({kind:n.kind,type:n.kind,lagMinutes:n.lagMinutes,lag_minutes:n.lagMinutes,skipIfNextCompleted:n.skipIfNextCompleted,skip_if_next_completed:n.skipIfNextCompleted,fieldCondition:n.fieldCondition||null,field_condition:n.fieldCondition||null,config:n.config||null})),run_flow_event_for_tags:i.run_flow_event_for_tags||"",run_flow_event_for_agreement_definitions:i.run_flow_event_for_agreement_definitions||"",skip_flow_event_if_completed:i.skip_flow_event_if_completed||""}));try{Be(!0);const i=`${K}/api_new/admin/flow-profiles/preview`,n=await fetch(i,{method:"POST",headers:{...re(),"Content-Type":"application/json"},body:JSON.stringify({steps:s,flow_name:u||"Unsaved Flow"})});if(!n.ok){const c=await n.json().catch(()=>({}));throw new Error(c.message||c.error||"Failed to generate preview")}const o=await n.json();q(o),T(!0)}catch(i){he.error("Failed to send test: "+i.message)}finally{Be(!1)}},M={send_email:{icon:Ve,label:"Email",color:"text-blue-400"},propora_smart:{icon:Le,label:"SMART SMS",color:"text-teal-400"},send_sms:{icon:Le,label:"SMS",color:"text-green-400"},add_tag:{icon:ft,label:"Tag",color:"text-amber-400"},remove_tag:{icon:ft,label:"Untag",color:"text-gray-400"},staff_email:{icon:Ve,label:"Staff Email",color:"text-purple-400"},staff_sms:{icon:Le,label:"Staff SMS",color:"text-pink-400"},send_agreement:{icon:Vt,label:"Agreement",color:"text-indigo-400"},send_kyc_link:{icon:tt,label:"KYC Link",color:"text-teal-300"}},me=s=>{const n=((s==null?void 0:s.steps)||[]).flatMap(c=>(c.behaviors||[]).map(p=>p.kind||p.type));return[...new Set(n)]},le=s=>((s==null?void 0:s.steps)||[]).reduce((i,n)=>i+(n.behaviors||[]).length,0),ve=l.useMemo(()=>{let s=F||[];if(U.trim()){const i=U.trim().toLowerCase();s=s.filter(n=>(n.name||"").toLowerCase().includes(i))}return s},[F,U]),Pe=s=>{let i="ascending";we.key===s&&(i=we.direction==="ascending"?"descending":"ascending"),ie({key:s,direction:i})},qe=s=>we.key!==s?e.jsx(en,{size:10,className:"ml-1 text-gray-500"}):we.direction==="ascending"?e.jsx(tn,{size:10,className:"ml-1 text-teal-400"}):e.jsx(an,{size:10,className:"ml-1 text-teal-400"}),Ue=l.useMemo(()=>we.key?[...ve].sort((s,i)=>{let n,o;switch(we.key){case"name":n=(s.name||"").toLowerCase(),o=(i.name||"").toLowerCase();break;case"status":n=s.paused?1:0,o=i.paused?1:0;break;case"steps":n=(s.steps||[]).length,o=(i.steps||[]).length;break;case"actions":n=(s.steps||[]).reduce((c,p)=>c+(p.behaviors||[]).length,0),o=(i.steps||[]).reduce((c,p)=>c+(p.behaviors||[]).length,0);break;default:return 0}return n==null?1:o==null?-1:n<o?we.direction==="ascending"?-1:1:n>o?we.direction==="ascending"?1:-1:0}):ve,[ve,we]),At=s=>{if(!s||!(P!=null&&P.length))return null;const i=P.find(n=>n.template_key===s);return i?String(i.id):null},gt=[{name:"Welcome new clients automatically",desc:"When a new contact is created, send them a welcome SMS and tag them for follow-up.",icon:tt,color:"from-teal-600/20 to-teal-800/20",iconColor:"text-teal-400",steps:[{type:"backend|contact|create",behaviors:[{kind:"propora_smart",config:{template_key:"welcome"}},{kind:"add_tag"}]}]},{name:"Notify staff when agreements are signed",desc:"Alert your team via SMS when a client signs their agreement.",icon:Vt,color:"from-blue-600/20 to-blue-800/20",iconColor:"text-blue-400",steps:[{type:"backend|contract_instance|signed",behaviors:[{kind:"staff_sms",config:{template_key:"staff-agreement-signed"}}]}]},{name:"Follow up after property shortlisting",desc:"SMS the client with an equity pitch when a property is added to their transaction.",icon:wa,color:"from-purple-600/20 to-purple-800/20",iconColor:"text-purple-400",steps:[{type:"backend|transaction|property_add",behaviors:[{kind:"propora_smart",config:{template_key:"Equity"}},{kind:"add_tag"}]}]},{name:"Alert team on offers and exchanges",desc:"Notify staff when an offer is made and SMS the client on exchange.",icon:ht,color:"from-emerald-600/20 to-emerald-800/20",iconColor:"text-emerald-400",steps:[{type:"backend|transaction|offer_add",behaviors:[{kind:"staff_sms",config:{template_key:"staff-agreement-sent"}}]},{type:"backend|transaction|offer_exchange",behaviors:[{kind:"staff_sms",config:{template_key:"staff-agreement-signed"}},{kind:"propora_smart",config:{template_key:"ai-sms-discovery"}}]}]}],Ft=s=>{const i=s.steps.map((n,o)=>({id:We(),type:n.type,label:Mt(n.type),icon:It[n.type]||ut,order:o,behaviors:(n.behaviors||[]).map(c=>
1{let p=c.config?{...c.config}:null;if(p!=null&&p.template_key){const N=At(p.template_key);N&&(p.template_id=N)}return{id:We(),kind:c.kind,lagMinutes:0,skipIfNextCompleted:!0,fieldCondition:null,config:p}})}));b(s.name),$(null),g(i),Te([]),W(!0),xe(!0)},Na=(F||[]).length>0;return e.jsx(xn,{feature:"flow_automation",description:"Automate client engagement with scheduled SMS, emails, and task sequences.",children:e.jsxs("div",{className:"animate-fadeIn",children:[e.jsx(fn,{title:"Flow Builder",subtitle:Oe?void 0:"Automate messages and actions when your business or clients hit key milestones.",className:"mb-4",actions:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(Ka,{to:"/admin/flow/logs",className:"inline-flex items-center justify-center gap-1.5 h-10 px-3 rounded-lg border border-gray-600 bg-gray-800/60 text-gray-300 hover:bg-gray-700/60 hover:text-white transition-all",title:"View Flow Logs",children:[e.jsx(Qa,{className:"w-4 h-4"}),!Oe&&e.jsx("span",{className:"text-sm",children:"Logs"})]}),e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("button",{onClick:()=>ye(!st),className:"inline-flex items-center justify-center w-10 h-10 rounded-lg border border-gray-600 bg-gray-800/60 text-gray-300 hover:bg-gray-700/60 hover:text-white transition-all",title:"Settings",children:e.jsx($t,{className:"w-4 h-4 md:w-5 md:h-5"})}),st&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>ye(!1)}),e.jsxs("div",{className:"absolute right-0 mt-2 w-56 bg-gray-800 border border-gray-700 rounded-lg shadow-lg z-50",children:[e.jsxs("button",{onClick:()=>{C(!0),ye(!1)},className:"w-full px-4 py-3 text-left text-gray-300 hover:bg-gray-700 hover:text-white transition-colors flex items-center gap-2 rounded-t-lg",children:[e.jsx(Le,{})," SMS Templates"]}),e.jsxs("button",{onClick:()=>{_(!0),ye(!1)},className:"w-full px-4 py-3 text-left text-gray-300 hover:bg-gray-700 hover:text-white transition-colors flex items-center gap-2 rounded-b-lg",children:[e.jsx(Ve,{})," Email Templates"]})]})]})]}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>Ke(s=>!s),className:`inline-flex items-center justify-center w-10 h-10 rounded-lg border transition-all ${U?"bg-teal-900/30 border-teal-700 text-teal-300":"border-gray-600 bg-gray-800/60 text-gray-300 hover:bg-gray-700/60 hover:text-white"}`,title:"Search flows","aria-label":"Search flows",children:e.jsx(nt,{className:"w-4 h-4"})}),it&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>Ke(!1)}),e.jsx("div",{className:"absolute right-0 mt-2 w-72 bg-gray-800 border border-gray-700 rounded-lg shadow-xl z-50 p-3",children:e.jsxs("div",{className:"relative",children:[e.jsx(nt,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-gray-500 w-3.5 h-3.5"}
1),e.jsx("input",{autoFocus:!0,type:"text",placeholder:"Search flows…",value:U,onChange:s=>rt(s.target.value),className:"w-full pl-9 pr-8 py-2 bg-gray-900 border border-gray-600 rounded-lg text-white text-sm placeholder-gray-500 focus:outline-none focus:ring-2 focus:ring-teal-500"}),U&&e.jsx("button",{onClick:()=>rt(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-gray-400 hover:text-white text-xs",children:"✕"})]})})]})]}),e.jsxs("button",{onClick:Xe,className:"inline-flex items-center justify-center gap-2 h-10 px-4 rounded-lg bg-gradient-to-r from-teal-600 to-blue-700 hover:from-teal-500 hover:to-blue-600 text-white font-medium text-sm transition-all",children:[e.jsx(ze,{className:"w-3 h-3"}),!Oe&&"New Flow"]})]})}),e.jsx("div",{className:"p-3 md:p-5",children:!V&&!Na?e.jsxs("div",{className:"max-w-3xl mx-auto py-8",children:[e.jsxs("div",{className:"text-center mb-10",children:[e.jsx("div",{className:"mb-5 inline-flex items-center justify-center w-20 h-20 rounded-full bg-gradient-to-br from-teal-600/20 to-blue-600/20 border border-teal-700/40",children:e.jsx(Za,{className:"w-9 h-9 text-teal-400"})}),e.jsx("h2",{className:"text-2xl font-bold text-white mb-3",children:"Automate Your Business in 3 Steps"}),e.jsx("p",{className:"text-gray-400 max-w-md mx-auto",children:"Flows listen for events, wait if needed, then take action automatically — so you never miss a beat."}),e.jsxs("div",{className:"flex items-center justify-center gap-2 mt-6",children:[e.jsx("div",{className:"px-4 py-2 rounded-lg bg-teal-900/30 border border-teal-700/40 text-teal-300 text-sm font-medium",children:"Trigger"}),e.jsx("span",{className:"text-gray-600",children:"→"}),e.jsx("div",{className:"px-4 py-2 rounded-lg bg-gray-800 border border-gray-700 text-gray-400 text-sm font-medium",children:"Wait"}),e.jsx("span",{className:"text-gray-600",children:"→"}),e.jsx("div",{className:"px-4 py-2 rounded-lg bg-blue-900/30 border border-blue-700/40 text-blue-300 text-sm font-medium",children:"Action"})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4 mb-8",children:gt.map(s=>{const i=s.icon;return e.jsx("button",{type:"button",onClick:()=>Ft(s),className:"p-5 rounded-xl bg-gray-800/50 border border-gray-700/60 hover:border-teal-600/50 hover:bg-gray-800/80 transition-all text-left group",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:`flex-shrink-0 w-10 h-10 rounded-lg bg-gradient-to-br ${s.color} border border-gray-700/40 flex items-center justify-center`,children:e.jsx(i,{className:`w-4 h-4 ${s.iconColor}`})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold text-white mb-1 group-hover:text-teal-300 transition-colors",children:s.name}),e.jsx("div",{className:"text-xs text-gray-500 leading-relaxed",children:s.desc}),e.jsxs("div",{className:"text-[10px] text-gray-600 mt-2",children:[s.steps.length," step",s.steps.length!==1?"s":""," · ",s.steps.reduce((n,o)=>{var c;return n+(((c=o.behaviors)==null?void 0:c.length)||0)},0)," action",s.steps.reduce((n,o)=>{var c;return n+(((c=o.behaviors)==null?void 0:c.length)||0)},0)!==1?"s":""]})]})]})},s.name)})}),e.jsx("div",{className:"text-center",children:e.jsxs("button",{onClick:Xe,className:"px-5 py-2.5 rounded-lg bg-gray-800 hover:bg-gray-700 border border-gray-700 text-gray-300 hover:text-white text-sm inline-flex items-center gap-2 transition-colors",children:[e.jsx(ze,{className:"w-3 h-3"})," Build from scratch"]})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"table-container my-4",children:e.jsxs("table",{className:"custom-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{onClick:()=>Pe("name"),style:{cursor:"pointer",textAlign:"left"},children:e.jsxs("div",{className:"flex items-center",children:["Flow Name ",qe("name")]})}),e.jsx("th",{onClick:()=>Pe("status"),style:{cursor:"pointer"},className:"hidden md:table-cell",children:e.jsxs("div",{className:"flex items-center justify-center",children:["Status ",qe("status")]})}),e.jsx("th",{onClick:()=>Pe("steps"),style:{cursor:"pointer"},className:"hidden md:table-cell",children:e.jsxs("div",{className:"flex items-center justify-center",children:["Steps ",qe("steps")]})}),e.jsx("th",{onClick:()=>Pe("actions"),style:{cursor:"pointer"},children:e.jsxs("div",{className:"flex items-center justify-center",children:["Actions ",qe("actions")]})}),e.jsx("th",{children:e.jsx("div",{})})]})}),e.jsx("tbody",{children:V?Array.from({length:5}).map((s,i)=>e.jsx("tr",{children:e.jsx("td",{colSpan:Oe?3:5,className:"animate-pulse",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-4 bg-gray-700 rounded w-1/3"}),e.jsx("div",{className:"h-4 bg-gray-700 rounded w-16 ml-auto"})]})})},`skel-${i}`)):Ue.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Oe?3:5,children:e.jsx(hn,{title:U?"No flows match your search":"No flows yet",subtitle:U?"Try a different search term.":"Create your first flow to get started.",compact:!0})})}):Ue.map(s=>{const i=(s.steps||[]).length,n=me(s),o=le(s),c=!!s.paused;return e.jsxs("tr",{onClick:()=>t(s.id),className:"cursor-pointer",children:[e.jsx("td",{style:{textAlign:"left"},children:e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[e.jsx("span",{className:`flex-shrink-0 w-2 h-2 rounded-full ${c?"bg-gray-500":"bg-teal-500"}`}),e.jsx("span",{className:"text-white text-sm font-medium truncate",children:s.name})]})}),e.jsx("td",{className:"hidden md:table-cell",children:e.jsx("span",{className:`px-2.5 py-0.5 rounded text-[10px] font-semibold uppercase tracking-wide ${c?"bg-gray-700/60 text-gray-400 border border-gray-600/40":"bg-teal-900/40 text-teal-300 border border-teal-800/40"}`,children:c?"Paused":"Active"})}),e.jsx("td",{className:"hidden md:table-cell",children:e.jsx("span",{className:"text-gray-300 text-sm font-mono",children:i})}),e.jsx("td",{children:e.jsxs("div",{className:"flex items-center justify-center gap-1.5 flex-wrap",children:[n.length>0?n.map(p=>{const N=M[p];if(!N)return null;const L=N.icon;return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded bg-gray-800 border border-gray-700/60 text-[10px]",title:N.label,children:[e.jsx(L,{className:`w-2.5 h-2.5 ${N.color}`}),e.jsx("span",{className:"text-gray-400 hidden lg:inline",children:N.label})]},p)}):e.jsx("span",{className:"text-gray-600 text-xs italic",children:"No actions"}),o>n.length&&e.jsxs("span",{className:"text-gray-500 text-[10px]",children:["(",o," total)"]})]})}),e.jsx("td",{onClick:p=>p.stopPropagation(),children:e.jsxs("div",{className:"flex items-center justify-end gap-1.5",children:[e.jsx("button",{onClick:()=>ee(s.id,c),className:`p-1.5 rounded-md transition-colors ${c?"text-teal-400 hover:bg-teal-900/30 hover:text-teal-300":"text-gray-400 hover:bg-gray-700 hover:text-yellow-400"}`,title:c?"Enable flow":"Pause flow",children:c?e.jsx(Xa,{className:"w-3 h-3"}):e.jsx(Ba,{className:"w-3 h-3"})}),e.jsx("button",{onClick:()=>t(s.id),className:"p-1.5 rounded-md text-gray-400 hover:bg-gray-700 hover:text-white transition-colors",title:"Edit flow",children:e.jsx(Ua,{className:"w-3 h-3"})}),e.jsx("button",{onClick:()=>De(s.id),className:"p-1.5 rounded-md text-gray-500 hover:bg-red-900/30 hover:text-red-400 transition-colors",title:"Delete flow",children:e.jsx(xt,{className:"w-3 h-3"})})]})})]},s.id)})})]})}),!V&&e.jsxs("div",{className:"mt-3 px-1 flex items-center justify-between text-xs text-gray-500",children:[e.jsxs("span",{children:[ve.length," flow",ve.length!==1?"s":""]}),e.jsxs("span",{children:[(F||[]).filter(s=>!s.paused).length," active · ",(F||[]).filter(s=>s.paused).length," paused"]})]})]})}),e.jsx(Sn,{isOpen:_t,onClose:A,flowName:u,onChangeFlowName:b,selectedFlowId:D,selectedFlow:jt,onTogglePaused:ee,events:y,onDragEnd:Ie,onRemove:Ct,onAddBehavior:vt,onUpdateBehavior:ot,onRemoveBehavior:He,onUpdateEvent:Nt,behaviorTypes:Qe,smsTemplates:P,onOpenSmsM
1anager:()=>C(!0),emailTemplates:v,availableTags:X,tagsLoading:Ce,onRefreshTags:lt,agreementDefinitions:B,agreementDefinitionsLoading:Ge,catalog:a,catalogError:w,onRetryCatalog:wt,selectedEventKey:r,onChangeSelectedEventKey:O,onAdd:St,onSave:I,onReset:dt,onSendTest:j,isSaving:m,isSendingTest:$e,hasUnsavedChanges:Ne,dateRange:H,onChangeDateRange:te,isMobile:Oe}),e.jsx(nn,{isOpen:x,onClose:()=>C(!1)}),e.jsx(yn,{isOpen:S,onClose:()=>_(!1)}),e.jsx(Tn,{isOpen:k,onClose:()=>T(!1),previewData:d}),pe&&Se&&e.jsx("div",{className:"fixed inset-0 z-[6000] flex items-center justify-center bg-black bg-opacity-50",children:e.jsxs("div",{className:"bg-gray-800 border border-gray-700 rounded-lg shadow-xl max-w-md w-full mx-4 p-6",children:[e.jsxs("div",{className:"flex items-start gap-4 mb-4",children:[e.jsx("div",{className:"flex-shrink-0 w-12 h-12 rounded-full bg-red-900/30 flex items-center justify-center",children:e.jsx(bt,{className:"w-6 h-6 text-red-500"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-lg font-semibold text-white mb-2",children:"Delete Flow?"}),e.jsxs("p",{className:"text-gray-300 mb-1",children:["Are you sure you want to delete ",e.jsxs("span",{className:"font-semibold text-white",children:['"',Se.name,'"']}),"?"]}),e.jsx("p",{className:"text-sm text-gray-400",children:"This action cannot be undone. All scheduled behaviors using this flow will stop."})]})]}),e.jsxs("div",{className:"flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>{je(!1),Ae(null)},className:"px-4 py-2 bg-gray-700 hover:bg-gray-600 rounded-lg text-white transition-colors",children:"Cancel"}),e.jsx("button",{onClick:Me,className:"px-4 py-2 bg-red-600 hover:bg-red-700 rounded-lg text-white font-medium transition-colors",children:"Delete Flow"})]})]})})]})})};export{ls as default};

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.