@muonroi/ui-engine-rule-components 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -723,7 +723,7 @@ React keys must be passed directly to JSX without using spread:
|
|
|
723
723
|
constructor(\${params}) {
|
|
724
724
|
\${}
|
|
725
725
|
}
|
|
726
|
-
}`,{label:"class",detail:"definition",type:"keyword"}),dh('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),dh('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],fet=Z1e.concat([dh("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),dh("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),dh("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),X1e=new CZe,Y1e=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function uM(s){return(e,t)=>{let i=e.node.getChild("VariableDefinition");return i&&t(i,s),!0}}const get=["FunctionDeclaration"],pet={FunctionDeclaration:uM("function"),ClassDeclaration:uM("class"),ClassExpression:()=>!0,EnumDeclaration:uM("constant"),TypeAliasDeclaration:uM("type"),NamespaceDeclaration:uM("namespace"),VariableDefinition(s,e){s.matchContext(get)||e(s,"variable")},TypeDefinition(s,e){e(s,"type")},__proto__:null};function J1e(s,e){let t=X1e.get(e);if(t)return t;let i=[],n=!0;function r(o,a){let l=s.sliceString(o.from,o.to);i.push({label:l,type:a})}return e.cursor(zo.IncludeAnonymous).iterate(o=>{if(n)n=!1;else if(o.name){let a=pet[o.name];if(a&&a(o,r)||Y1e.has(o.name))return!1}else if(o.to-o.from>8192){for(let a of J1e(s,o.node))i.push(a);return!1}}),X1e.set(e,i),i}const eCe=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,tCe=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function met(s){let e=md(s.state).resolveInner(s.pos,-1);if(tCe.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&eCe.test(s.state.sliceDoc(e.from,e.to));if(!t&&!s.explicit)return null;let i=[];for(let n=e;n;n=n.parent)Y1e.has(n.name)&&(i=i.concat(J1e(s.state.doc,n)));return{options:i,from:t?e.from:s.pos,validFor:eCe}}const cS=XA.define({name:"javascript",parser:het.configure({props:[G$.add({IfStatement:JA({except:/^\s*({|else\b)/}),TryStatement:JA({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:VZe,SwitchBody:s=>{let e=s.textAfter,t=/^\s*\}/.test(e),i=/^\s*(case|default)\b/.test(e);return s.baseIndent+(t?0:i?1:2)*s.unit},Block:HZe({closing:"}"}),ArrowFunction:s=>s.baseIndent+s.unit,"TemplateString BlockComment":()=>null,"Statement Property":JA({except:/^\s*{/}),JSXElement(s){let e=/^\s*<\//.test(s.textAfter);return s.lineIndent(s.node.from)+(e?0:s.unit)},JSXEscape(s){let e=/\s*\}/.test(s.textAfter);return s.lineIndent(s.node.from)+(e?0:s.unit)},"JSXOpenTag JSXSelfClosingTag"(s){return s.column(s.node.from)+s.unit}}),b0e.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":v0e,BlockComment(s){return{from:s.from+2,to:s.to-2}},JSXElement(s){let e=s.firstChild;if(!e||e.name=="JSXSelfClosingTag")return null;let t=s.lastChild;return{from:e.to,to:t.type.isError?s.to:t.from}},"JSXSelfClosingTag JSXOpenTag"(s){var e;let t=(e=s.firstChild)===null||e===void 0?void 0:e.nextSibling,i=s.lastChild;return!t||t.type.isError?null:{from:t.to,to:i.type.isError?s.to:i.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),iCe={test:s=>/^JSX/.test(s.name),facet:LZ({commentTokens:{block:{open:"{/*",close:"*/}"}}})},_et=cS.configure({dialect:"ts"},"typescript"),bet=cS.configure({dialect:"jsx",props:[TZ.add(s=>s.isTop?[iCe]:void 0)]}),vet=cS.configure({dialect:"jsx ts",props:[TZ.add(s=>s.isTop?[iCe]:void 0)]},"typescript");let nCe=s=>({label:s,type:"keyword"});const sCe="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(nCe),yet=sCe.concat(["declare","implements","private","protected","public"].map(nCe));function wet(s={}){let e=s.jsx?s.typescript?vet:bet:s.typescript?_et:cS,t=s.typescript?fet.concat(yet):Z1e.concat(sCe);return new g0e(e,[cS.data.of({autocomplete:xYe(tCe,w1e(t))}),cS.data.of({autocomplete:met}),s.jsx?ket:[]])}function Cet(s){for(;;){if(s.name=="JSXOpenTag"||s.name=="JSXSelfClosingTag"||s.name=="JSXFragmentTag")return s;if(s.name=="JSXEscape"||!s.parent)return null;s=s.parent}}function rCe(s,e,t=s.length){for(let i=e==null?void 0:e.firstChild;i;i=i.nextSibling)if(i.name=="JSXIdentifier"||i.name=="JSXBuiltin"||i.name=="JSXNamespacedName"||i.name=="JSXMemberExpression")return s.sliceString(i.from,Math.min(i.to,t));return""}const xet=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),ket=Mi.inputHandler.of((s,e,t,i,n)=>{if((xet?s.composing:s.compositionStarted)||s.state.readOnly||e!=t||i!=">"&&i!="/"||!cS.isActiveAt(s.state,e,-1))return!1;let r=n(),{state:o}=r,a=o.changeByRange(l=>{var c;let{head:d}=l,u=md(o).resolveInner(d-1,-1),f;if(u.name=="JSXStartTag"&&(u=u.parent),!(o.doc.sliceString(d-1,d)!=i||u.name=="JSXAttributeValue"&&u.to>d)){if(i==">"&&u.name=="JSXFragmentTag")return{range:l,changes:{from:d,insert:"</>"}};if(i=="/"&&u.name=="JSXStartCloseTag"){let p=u.parent,m=p.parent;if(m&&p.from==d-2&&((f=rCe(o.doc,m.firstChild,d))||((c=m.firstChild)===null||c===void 0?void 0:c.name)=="JSXFragmentTag")){let b=`${f}>`;return{range:Ct.cursor(d+b.length,-1),changes:{from:d,insert:b}}}}else if(i==">"){let p=Cet(u);if(p&&p.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(d,d+2))&&(f=rCe(o.doc,p,d)))return{range:l,changes:{from:d,insert:`</${f}>`}}}}return{range:l}});return a.changes.empty?!1:(s.dispatch([r,o.update(a,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),Oet=xZ({String:lt.string,Number:lt.number,"True False":lt.bool,PropertyName:lt.propertyName,Null:lt.null,", :":lt.separator,"[ ]":lt.squareBracket,"{ }":lt.brace}),Eet=dM.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:"#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O",goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:"⚠ JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",maxTerm:25,nodeProps:[["isolate",-2,6,11,""],["openedBy",7,"{",14,"["],["closedBy",8,"}",15,"]"]],propSources:[Oet],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0}),Let=XA.define({name:"json",parser:Eet.configure({props:[G$.add({Object:JA({except:/^\s*\}/}),Array:JA({except:/^\s*\]/})}),b0e.add({"Object Array":v0e})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function Tet(){return new g0e(Let)}function oCe(s){switch(s){case"feel":return bJe;case"liquid":return wJe;case"scriban":return xJe;case"javascript":return wet();case"json":return Tet();case"plain-text":return[]}}const aCe=new Mw,lCe=new Mw,Det=new Mw,cCe=new Mw;function dX({value:s,language:e,readOnly:t,onChange:i,onInsertToken:n,extensions:r,minHeight:o,root:a,singleLine:l=!1,placeholderText:c}){const d=o??(l?36:180),u=ve.useRef(null),f=ve.useRef(null),p=ve.useRef(i),m=ve.useRef(n);p.current=i,m.current=n,ve.useEffect(()=>{if(!u.current)return;const w=[...l?[]:[pZe(),BKe()],AKe(),qKe(),KKe(),YZe(),nJe(),bXe(),D$.of([...CYe,...EXe,...oJe]),Mi.updateListener.of(O=>{O.docChanged&&p.current(O.state.doc.toString())}),aCe.of([Mi.editable.of(!t),aa.readOnly.of(t)]),lCe.of(oCe(e)),Det.of([]),cCe.of(r??[]),...l?[Mi.theme({"&":{maxHeight:`${d}px`},".cm-scroller":{overflow:"hidden"},".cm-content":{padding:"4px 8px"},".cm-gutters":{display:"none"}}),aa.transactionFilter.of(O=>O.newDoc.lines>1?[]:O)]:[],...c?[VKe(c)]:[]],S=aa.create({doc:s,extensions:w}),k=new Mi({state:S,parent:u.current,root:a});return f.current=k,m.current&&m.current({insert:O=>{const L=k.state.selection.main.head;k.dispatch({changes:{from:L,insert:O},selection:{anchor:L+O.length}}),k.focus()}}),()=>{k.destroy(),f.current=null}},[a]),ve.useEffect(()=>{const w=f.current;if(!w)return;const S=w.state.doc.toString();S!==s&&w.dispatch({changes:{from:0,to:S.length,insert:s}})},[s]),ve.useEffect(()=>{const w=f.current;w&&w.dispatch({effects:lCe.reconfigure(oCe(e))})},[e]),ve.useEffect(()=>{const w=f.current;w&&w.dispatch({effects:aCe.reconfigure([Mi.editable.of(!t),aa.readOnly.of(t)])})},[t]),ve.useEffect(()=>{const w=f.current;w&&w.dispatch({effects:cCe.reconfigure(r??[])})},[r]);const b={minHeight:`${d}px`,border:"1px solid rgba(148, 163, 184, 0.24)",borderRadius:l?"6px":"14px",overflow:"hidden",...l?{marginBottom:0}:{}};return M.jsx("div",{ref:u,style:b})}function Iet({value:s,onChange:e,onReset:t,tokens:i,editorRoot:n}){return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,borderBottom:`1px solid ${i.sidebarBorder.replace("1px solid ","")}`},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",background:i.sidebarBg,borderBottom:`1px solid ${i.sidebarBorder.replace("1px solid ","")}`},children:[M.jsx("span",{style:{fontSize:12,fontWeight:600,color:i.textPrimary},children:"Input Data (JSON)"}),t?M.jsx("button",{type:"button",onClick:t,style:{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:i.textSecondary,textDecoration:"underline",padding:"2px 4px"},children:"Reset to Schema"}):null]}),M.jsx(dX,{value:s,language:"json",readOnly:!1,onChange:e,minHeight:160,singleLine:!1,root:n,placeholderText:'{ "key": "value" }'})]})}function dCe({title:s,count:e,defaultExpanded:t,headerRight:i,children:n}){const[r,o]=ve.useState(t);return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsxs("div",{role:"button",tabIndex:0,onClick:()=>o(!r),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(!r))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[M.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:r?"▼":"▶"}),M.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:s}),e!==void 0?M.jsxs("span",{style:{background:"var(--mu-border-subtle)",padding:"2px 8px",borderRadius:10,fontSize:11,color:"var(--mu-text-secondary)",fontWeight:600},children:[e," field",e!==1?"s":""]}):null]}),i]}),r?n:null]})}function Ret({entry:s,tokens:e,onShowFullFactBag:t}){var o,a,l;const i=s.businessFacts?s.businessFacts:s.outputs?Object.fromEntries(Object.entries(s.outputs).filter(([c])=>!c.startsWith("__graph.")&&!c.startsWith("__node.")&&!["executed","passed","errored","result"].includes(c))):{},n=Object.keys(i),r=((o=s.status)==null?void 0:o.elapsedMs)??s.elapsedMs;return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[M.jsx("button",{type:"button",onClick:t,style:{fontSize:11,color:e.textSecondary,cursor:"pointer",padding:"4px 8px",background:"none",border:"none",textAlign:"left",textDecoration:"none"},onMouseEnter:c=>{c.currentTarget.style.textDecoration="underline"},onMouseLeave:c=>{c.currentTarget.style.textDecoration="none"},children:"< Back to Full FactBag"}),M.jsxs("div",{style:{padding:"6px 8px",borderRadius:6,background:"color-mix(in oklch, var(--mu-border-subtle) 40%, transparent)"},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:(a=s.status)!=null&&a.message||s.errors&&s.errors.length>0?6:0},children:[M.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:s.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:s.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:s.isSuccess?"✓":"✗"}),M.jsx("span",{style:{fontSize:12,fontWeight:600,color:s.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:s.isSuccess?"Passed":"Failed"}),r!==void 0?M.jsxs("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,marginLeft:"auto",background:"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)",color:"var(--mu-color-success-text)",fontWeight:600},children:[r,"ms"]}):null]}),(l=s.status)!=null&&l.message?M.jsx("div",{style:{fontSize:12,color:s.isSuccess?e.textSecondary:"var(--mu-color-error)",...s.isSuccess?{}:{borderLeft:"3px solid var(--mu-color-error)",paddingLeft:8}},children:s.status.message}):null,s.errors&&s.errors.length>0?M.jsx("div",{style:{marginTop:4,display:"flex",flexDirection:"column",gap:2},children:s.errors.map((c,d)=>M.jsx("div",{style:{fontSize:11,color:"var(--mu-color-error)",borderLeft:"3px solid var(--mu-color-error)",paddingLeft:8},children:c},d))}):null]}),M.jsx(dCe,{title:"Output",count:s.changedKeys?s.changedKeys.length:void 0,defaultExpanded:!0,children:n.length>0?M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,padding:"4px 8px",fontFamily:"var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)"},children:n.map(c=>M.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",fontSize:11},children:[M.jsxs("span",{style:{fontWeight:600,color:e.textSecondary},children:[c,":"]}),M.jsx("span",{style:{color:e.textPrimary},children:typeof i[c]=="object"&&i[c]!==null?JSON.stringify(i[c]):String(i[c]??"")})]},c))}):M.jsx("div",{style:{padding:"4px 8px",fontSize:11,color:e.textMuted,fontStyle:"italic"},children:"No output facts"})}),M.jsx(dCe,{title:"Input",defaultExpanded:!1,children:s.inputSnapshot?M.jsx("pre",{style:{margin:0,fontSize:11,lineHeight:1.5,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)",color:e.textPrimary,maxHeight:200,overflowY:"auto",padding:"4px 8px"},children:JSON.stringify(s.inputSnapshot,null,2)}):M.jsx("div",{style:{padding:"4px 8px",fontSize:11,color:e.textMuted,fontStyle:"italic"},children:"Input data not available (run via consumer runtime for full input capture)"})})]})}function Net({result:s,loading:e,error:t,onSelectNode:i,onClose:n,tokens:r}){const[o,a]=ve.useState(null),l=s==null?void 0:s.results.find(u=>u.ruleName===o),c=(s==null?void 0:s.results.filter(u=>u.isSuccess).length)??0,d=(s==null?void 0:s.results.filter(u=>!u.isSuccess).length)??0;return M.jsxs("div",{style:{borderTop:`2px solid ${r.sidebarBorder.replace("1px solid ","")}`,height:280,overflow:"hidden",display:"flex",flexDirection:"column",background:r.inspectorBg},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,flexShrink:0},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsx("span",{style:{fontSize:13,fontWeight:600,color:r.textPrimary},children:"Dry Run Results"}),s?M.jsxs("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,background:s.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:s.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)",fontWeight:600},children:[s.executionTimeMs,"ms"]}):null]}),M.jsx("button",{type:"button",onClick:n,style:{background:"transparent",border:"none",cursor:"pointer",color:r.textMuted,fontSize:14,padding:2},title:"Close results",children:"X"})]}),M.jsx("div",{style:{flex:1,overflow:"hidden"},children:e?M.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:r.textSecondary,fontSize:13},children:"Executing dry run..."}):t?M.jsxs("div",{style:{padding:16,color:r.errorText,fontSize:13},children:[M.jsx("strong",{children:"Error:"})," ",t]}):s?M.jsxs("div",{style:{display:"flex",height:"100%"},children:[M.jsx("div",{style:{width:"60%",overflow:"auto",borderRight:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`},children:M.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[M.jsx("thead",{children:M.jsxs("tr",{style:{borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,position:"sticky",top:0,background:r.inspectorBg,zIndex:1},children:[M.jsx("th",{style:{...uX,color:r.textSecondary},children:"Node"}),M.jsx("th",{style:{...uX,color:r.textSecondary,width:60},children:"Status"}),M.jsx("th",{style:{...uX,color:r.textSecondary,width:80},children:"Evaluation"})]})}),M.jsx("tbody",{children:s.results.map(u=>M.jsxs("tr",{onClick:()=>{const f=u.ruleName===o?null:u.ruleName;a(f),f&&(i==null||i(f))},style:{cursor:"pointer",borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,background:o===u.ruleName?r.overlayItemSelectedBg:"transparent"},children:[M.jsxs("td",{style:{padding:"6px 12px",color:r.textPrimary,fontWeight:500},children:[u.ruleName,u.errors&&u.errors.length>0?M.jsx("div",{style:{fontSize:11,color:r.errorText,marginTop:2},children:u.errors[0]}):null]}),M.jsx("td",{style:{padding:"6px 8px",textAlign:"center"},children:M.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:u.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:u.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:u.isSuccess?"✓":"✗"})}),M.jsx("td",{style:{padding:"6px 8px",textAlign:"center",fontSize:11,color:r.textSecondary},children:u.evaluationResult===!0?"true":u.evaluationResult===!1?"false":u.evaluationResult??"—"})]},u.ruleName))})]})}),M.jsx("div",{style:{width:"40%",overflow:"auto",padding:8},children:l?M.jsx(Ret,{entry:l,tokens:r,onShowFullFactBag:()=>a(null)}):M.jsxs(M.Fragment,{children:[M.jsx("div",{style:{fontSize:11,color:r.textSecondary,marginBottom:4,fontWeight:600},children:"Full FactBag"}),M.jsx("pre",{style:{margin:0,fontSize:11,lineHeight:1.5,color:r.textPrimary,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)"},children:JSON.stringify((s==null?void 0:s.factBagClean)??(s==null?void 0:s.factBag)??{},null,2)})]})})]}):null}),s?M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"6px 12px",borderTop:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,fontSize:12,flexShrink:0},children:[M.jsxs("span",{style:{color:"var(--mu-color-success-text)",fontWeight:600},children:[c," passed"]}),M.jsxs("span",{style:{color:"var(--mu-color-error)",fontWeight:600},children:[d," failed"]}),M.jsxs("span",{style:{color:r.textMuted,marginLeft:"auto"},children:["Total: ",s.executionTimeMs,"ms"]})]}):null]})}const uX={padding:"6px 12px",textAlign:"left",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px"};function Aet({nodeName:s,isSuccess:e,evaluationResult:t,outputs:i,errors:n,position:r,tokens:o}){const a=e?"var(--mu-color-success)":"var(--mu-color-error)",l=e?"var(--mu-color-success-bg)":"var(--mu-color-error-bg)",c=e?"Pass":"Fail",d=i!=null&&Object.keys(i).length>0,u=n!=null&&n.length>0;return M.jsxs("div",{style:{position:"fixed",left:r.x+12,top:r.y-8,background:o.inspectorBg,border:`1px solid ${o.sidebarBorder.replace("1px solid ","")}`,borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",padding:"10px 14px",maxWidth:320,zIndex:1e3,pointerEvents:"none",fontSize:12},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[M.jsx("span",{style:{fontWeight:600,color:o.textPrimary},children:s}),M.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:12,background:l,color:a,fontWeight:600,fontSize:11},children:c})]}),t!==void 0?M.jsxs("div",{style:{color:o.textSecondary,marginBottom:4},children:["Evaluation: ",String(t)]}):null,d?M.jsxs("div",{style:{marginBottom:4},children:[M.jsx("div",{style:{color:o.textSecondary,marginBottom:2},children:"Outputs:"}),M.jsx("pre",{style:{maxHeight:120,overflowY:"auto",fontFamily:"monospace",fontSize:11,margin:0,padding:"4px 6px",background:"rgba(0,0,0,0.04)",borderRadius:4,whiteSpace:"pre-wrap",wordBreak:"break-all",color:o.textPrimary},children:JSON.stringify(i,null,2)})]}):null,u?M.jsxs("div",{children:[M.jsx("div",{style:{color:"var(--mu-color-error)",marginBottom:2},children:"Errors:"}),n.map((f,p)=>M.jsx("div",{style:{color:"var(--mu-color-error)",fontSize:11},children:f},p))]}):null]})}const _L={trigger:"Trigger",condition:"Condition",action:"Action","decision-table":"Decision Table","sub-flow":"Sub Flow",liquid:"Liquid",connector:"Connector",end:"End"},hM={trigger:"var(--mu-node-trigger)",condition:"var(--mu-node-condition)",action:"var(--mu-node-action)","decision-table":"var(--mu-node-decision-table)","sub-flow":"var(--mu-node-sub-flow)",liquid:"var(--mu-node-liquid)",connector:"var(--mu-node-connector)",end:"var(--mu-node-end)"},uCe={trigger:"Create request",condition:"New Condition",action:"New Action","decision-table":"Decision Table","sub-flow":"Sub Flow",liquid:"Liquid Transform",connector:"New Connector",end:"End"},Met={minWidth:188,borderRadius:18,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-base)",boxShadow:"var(--mu-shadow-node)",padding:"12px 14px"};function Cl(s){var t,i,n,r,o,a;if(!s||typeof s!="object")return gB();const e=s;return{nodes:Array.isArray(e.nodes)?e.nodes.map((l,c)=>Pet(l,c)):[],edges:Array.isArray(e.edges)?e.edges.filter(l=>!!l&&typeof l.source=="string"&&typeof l.target=="string").map((l,c)=>({id:typeof l.id=="string"&&l.id?l.id:`edge-${c+1}`,source:l.source,target:l.target,label:typeof l.label=="string"?l.label:void 0,edgeType:d8(l.edgeType)})):[],metadata:{version:Math.max(1,((t=e.metadata)==null?void 0:t.version)??1),tenantId:(i=e.metadata)==null?void 0:i.tenantId,ruleSetCode:(n=e.metadata)==null?void 0:n.ruleSetCode,workflowName:(r=e.metadata)==null?void 0:r.workflowName,lastModifiedAt:(o=e.metadata)==null?void 0:o.lastModifiedAt,lastModifiedBy:(a=e.metadata)==null?void 0:a.lastModifiedBy}}}function hCe(s){return JSON.stringify(Cl(s),null,2)}function fCe(s){let e;try{e=JSON.parse(s)}catch(o){throw new Error(`Invalid rule flow JSON: ${o.message}`)}if(e&&typeof e=="object"){const o=e;if(o.ruleSetJson&&typeof o.ruleSetJson=="string")try{e=JSON.parse(o.ruleSetJson)}catch{}const a=e;a.ruleSet&&typeof a.ruleSet=="object"&&(e=a.ruleSet);const l=e;l.flowGraph&&typeof l.flowGraph=="object"&&(e=l.flowGraph)}const t=Cl(e),i=t.nodes.filter(o=>o.type==="trigger").length,n=t.nodes.filter(o=>o.type==="end").length;if(i!==1)throw new Error("Imported flow must contain exactly one trigger node.");if(n<1)throw new Error("Imported flow must contain at least one end node.");const r=new Set(t.nodes.map(o=>o.id));if(r.size!==t.nodes.length)throw new Error("Imported flow contains duplicate node ids.");for(const o of t.edges)if(!r.has(o.source)||!r.has(o.target))throw new Error(`Imported flow edge '${o.id}' references missing nodes.`);return t}function Yl(s){const e=Cl(s);return JSON.stringify({nodes:e.nodes.map(t=>({id:t.id,type:t.type,label:t.label,ruleCode:t.ruleCode??"",feelExpression:t.feelExpression??"",position:t.position,data:hX(t.data)})).sort((t,i)=>(t.id??"").localeCompare(i.id??"")),edges:e.edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??"",edgeType:t.edgeType})).sort((t,i)=>(t.id??"").localeCompare(i.id??"")),metadata:{version:e.metadata.version,tenantId:e.metadata.tenantId??"",ruleSetCode:e.metadata.ruleSetCode??"",workflowName:e.metadata.workflowName??""}})}function Pet(s,e){const t=mX(s.type),i=hX(s.data),n=fX(i.expression,s.feelExpression,t),r=s.position??{x:Number.NaN,y:Number.NaN};return{id:typeof s.id=="string"&&s.id?s.id:`node-${e+1}`,type:t,label:typeof s.label=="string"&&s.label?s.label:uCe[t],feelExpression:n.language==="feel"?n.body:void 0,ruleCode:typeof s.ruleCode=="string"?s.ruleCode:void 0,expressionLanguage:s.expressionLanguage==="feel"||s.expressionLanguage==="javascript"?s.expressionLanguage:void 0,position:{x:Number.isFinite(r==null?void 0:r.x)?r.x:40+e*48,y:Number.isFinite(r==null?void 0:r.y)?r.y:60+e%4*88},data:{...i,expression:n}}}function hX(s){var r;const e=s&&typeof s=="object"?s:{},t=Array.isArray(e.outputFields)?e.outputFields.map(bL).filter(Boolean):[],i=Fet(e.contractOverride),n=(r=i==null?void 0:i.responseFields)!=null&&r.length?i.responseFields:t.length?t:void 0;return{...e,description:typeof e.description=="string"?e.description:void 0,expression:fX(e.expression,typeof e.feelExpression=="string"?e.feelExpression:void 0),contractRef:Bet(e.contractRef),requestContract:fM(e.requestContract),responseContract:fM(e.responseContract),contractOverride:i||n?{...i,responseFields:n}:void 0,inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(l8).filter(Boolean):void 0,contractLayer:qet(e.contractLayer),dependsOn:Array.isArray(e.dependsOn)?e.dependsOn.filter(o=>typeof o=="string"&&o.trim().length>0).map(o=>o.trim()):void 0,order:typeof e.order=="number"&&Number.isFinite(e.order)?e.order:void 0,conditionConfig:$et(e.conditionConfig),subFlowConfig:Wet(e.subFlowConfig),liquidConfig:Vet(e.liquidConfig),connectorConfig:(()=>{const o=Het(e.connectorConfig);return o&&!o.connectorType&&typeof e.connectorType=="string"&&(o.connectorType=e.connectorType),o})()}}function Fet(s){if(!s||typeof s!="object")return;const e=s;return{requestFields:Array.isArray(e.requestFields)?e.requestFields.map(bL).filter(Boolean):void 0,responseFields:Array.isArray(e.responseFields)?e.responseFields.map(bL).filter(Boolean):void 0}}function Bet(s){if(!s||typeof s!="object")return;const e=s,t=e.sourceType,i=e.sourceCode;if(!(typeof t!="string"||typeof i!="string"||!i.trim()))return{sourceType:Xet(t),sourceCode:i.trim(),label:typeof e.label=="string"?e.label:void 0}}function fM(s){if(!s||typeof s!="object")return;const e=s,t=typeof e.contractName=="string"&&e.contractName.trim()?e.contractName.trim():"";if(t)return{contractName:t,title:typeof e.title=="string"?e.title:void 0,description:typeof e.description=="string"?e.description:void 0,rootType:typeof e.rootType=="string"?e.rootType:void 0,fields:Array.isArray(e.fields)?e.fields.map(bL).filter(Boolean):[]}}function bL(s){if(!s||typeof s!="object")return null;const e=s,t=typeof e.path=="string"&&e.path.trim()?e.path.trim():"",i=typeof e.label=="string"&&e.label.trim()?e.label.trim():t,n=typeof e.dataType=="string"&&e.dataType.trim()?e.dataType.trim():"unknown";return t?{path:t,label:i,dataType:n,valueExpression:typeof e.valueExpression=="string"?e.valueExpression:void 0,runtimeWritten:e.runtimeWritten===!0?!0:void 0,required:!!e.required,description:typeof e.description=="string"?e.description:void 0,example:typeof e.example=="string"?e.example:void 0,exposeToParent:e.exposeToParent===!1?!1:void 0,isResultPayload:e.isResultPayload===!0?!0:void 0,sourceNodeId:typeof e.sourceNodeId=="string"?e.sourceNodeId:void 0,sourceNodeLabel:typeof e.sourceNodeLabel=="string"?e.sourceNodeLabel:void 0,sourceNodeType:typeof e.sourceNodeType=="string"&&pX(e.sourceNodeType)?e.sourceNodeType:void 0,sourceKind:e.sourceKind==="flow-input"||e.sourceKind==="node-output"||e.sourceKind==="result-payload"||e.sourceKind==="sub-flow-output"||e.sourceKind==="inline"?e.sourceKind:void 0,children:Array.isArray(e.children)?e.children.map(bL).filter(Boolean):void 0}:null}function fX(s,e,t="action"){if(s&&typeof s=="object"){const i=s;if(typeof i.language=="string"&&typeof i.body=="string")return{language:_Ce(i.language),body:i.body}}return typeof e=="string"&&e.trim()?{language:"feel",body:e}:gX(t)}function $et(s){if(!s||typeof s!="object")return;const e=s;return{successLabel:typeof e.successLabel=="string"?e.successLabel:void 0,failureLabel:typeof e.failureLabel=="string"?e.failureLabel:void 0,failureMessage:typeof e.failureMessage=="string"?e.failureMessage:void 0}}function Wet(s){if(!s||typeof s!="object")return;const e=s;return{targetFlowCode:typeof e.targetFlowCode=="string"?e.targetFlowCode:void 0,childTriggerSchema:fM(e.childTriggerSchema),inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(l8).filter(Boolean):[],outputMappings:Array.isArray(e.outputMappings)?e.outputMappings.map(l8).filter(Boolean):[]}}function Het(s){if(!s||typeof s!="object")return;const e=s,t=Object.keys(e);return console.log("[muonroi-debug] MNormalizeConnectorConfig input keys:",t.join(","),"| has url:","url"in e,"| has connectorType:",typeof e.connectorType),typeof e.connectorType=="string"&&e.connectorConfig&&typeof e.connectorConfig=="object"?(console.log("[muonroi-debug] → nested format detected"),{connectorType:e.connectorType,connectorConfig:e.connectorConfig,credentialId:typeof e.credentialId=="string"?e.credentialId:void 0}):t.some(n=>["url","method","body","operation","webhookUrl","to","key","headers"].includes(n))?(console.log("[muonroi-debug] → flat/runtime format detected, using candidate as connectorConfig"),{connectorType:typeof e.connectorType=="string"?e.connectorType:void 0,connectorConfig:e,credentialId:typeof e.credentialId=="string"?e.credentialId:void 0}):(console.log("[muonroi-debug] → legacy/fallback format"),{connectorType:typeof e.connectorType=="string"?e.connectorType:void 0,connectorConfig:e.connectorConfig&&typeof e.connectorConfig=="object"?e.connectorConfig:void 0,credentialId:typeof e.credentialId=="string"?e.credentialId:void 0})}function Vet(s){if(!s||typeof s!="object")return;const e=s;return{template:typeof e.template=="string"?e.template:void 0,outputFormat:e.outputFormat==="json"||e.outputFormat==="text"||e.outputFormat==="object"?e.outputFormat:void 0}}function l8(s){if(!s||typeof s!="object")return null;const e=s;return{id:typeof e.id=="string"&&e.id?e.id:`map-${Math.random().toString(36).slice(2,9)}`,sourcePath:typeof e.sourcePath=="string"?e.sourcePath:"",targetPath:typeof e.targetPath=="string"?e.targetPath:"",transform:typeof e.transform=="string"?e.transform:void 0,language:typeof e.language=="string"?_Ce(e.language):void 0}}function zet(s){const e=l8(s);if(!e||!s||typeof s!="object")return e;const t=s;return{...e,targetField:typeof t.targetField=="string"?t.targetField:void 0,sourceDataType:typeof t.sourceDataType=="string"?t.sourceDataType:void 0,targetDataType:typeof t.targetDataType=="string"?t.targetDataType:void 0,sourceNodeId:typeof t.sourceNodeId=="string"?t.sourceNodeId:void 0,sourceNodeLabel:typeof t.sourceNodeLabel=="string"?t.sourceNodeLabel:void 0,required:t.required===!0?!0:void 0,status:t.status==="mapped"||t.status==="missing"||t.status==="type-mismatch"||t.status==="suggested"?t.status:void 0,transformSuggestion:typeof t.transformSuggestion=="string"?t.transformSuggestion:void 0}}function Uet(s){if(!s||typeof s!="object")return null;const e=s,t=typeof e.code=="string"&&e.code.trim()?e.code.trim():"",i=typeof e.message=="string"&&e.message.trim()?e.message.trim():"";return!t||!i?null:{code:t,message:i,severity:e.severity==="warning"||e.severity==="info"?e.severity:"error",nodeId:typeof e.nodeId=="string"?e.nodeId:void 0,fieldPath:typeof e.fieldPath=="string"?e.fieldPath:void 0,sourcePath:typeof e.sourcePath=="string"?e.sourcePath:void 0,targetPath:typeof e.targetPath=="string"?e.targetPath:void 0,relatedNodeId:typeof e.relatedNodeId=="string"?e.relatedNodeId:void 0}}function jet(s){if(!s||typeof s!="object")return;const e=s,t=typeof e.contractName=="string"&&e.contractName.trim()?e.contractName.trim():"";if(t)return{contractName:t,title:typeof e.title=="string"?e.title:void 0,description:typeof e.description=="string"?e.description:void 0,mode:e.mode==="auto"||e.mode==="manual"||e.mode==="expression"||e.mode==="decision-table"||e.mode==="sub-flow"?e.mode:void 0,fields:Array.isArray(e.fields)?e.fields.map(bL).filter(Boolean):[],mappings:Array.isArray(e.mappings)?e.mappings.map(zet).filter(Boolean):[]}}function qet(s){if(!s||typeof s!="object")return;const e=s;return{upstreamScope:fM(e.upstreamScope),effectiveInput:jet(e.effectiveInput),outputContract:fM(e.outputContract),validationIssues:Array.isArray(e.validationIssues)?e.validationIssues.map(Uet).filter(Boolean):void 0}}function y_(s){const e=typeof s.feelExpression=="string"?s.feelExpression:void 0;return fX(s.expression,e,s.nodeType??"action")}function Tp(s){return s??{targetFlowCode:"",childTriggerSchema:void 0,inputMappings:[],outputMappings:[]}}function gCe(s){return s??{outputFormat:"json"}}function Oc(s,e=[]){var t;for(const i of s)e.push(i),(t=i.children)!=null&&t.length&&Oc(i.children,e);return e}function pCe(s,e,t){const i=e.trim();return i?{sourceType:(t==null?void 0:t.sourceType)??c8(s),sourceCode:i,label:t==null?void 0:t.label}:t}const Qet=new Set(["condition","action","decision-table","sub-flow","liquid","connector"]);function mCe(s){return s==="trigger"?"input-data":Qet.has(s)?"data-mapping":"basic-info"}function c8(s){return s==="sub-flow"?"flow":s==="decision-table"?"decision-table":s==="liquid"||s==="connector"?"api":"rule"}function Get(s){const e=["basic-info","input-data","data-mapping","output-data"];return s!=="trigger"&&s!=="end"&&e.push("logic"),e}function Ket(s){return s==="basic-info"?"Basic Info":s==="input-data"?"Input Data":s==="data-mapping"?"Data Flow":s==="output-data"?"Output Data":"Logic"}function gX(s){return{language:s==="liquid"?"liquid":"feel",body:""}}const Zet=new Set(Object.keys(_L));function pX(s){return Zet.has(s)}function mX(s){return typeof s=="string"&&pX(s)?s:"action"}function d8(s){return s==="always"||s==="on-true"||s==="on-false"||s==="on-error"?s:"always"}function _Ce(s){if(typeof s!="string")return"feel";const e=s.trim().toLowerCase();return e==="feel"||e==="liquid"||e==="plain-text"||e==="javascript"||e==="scriban"?e:"feel"}function Xet(s){return s==="rule"||s==="flow"||s==="decision-table"||s==="api"||s==="inline"?s:"rule"}function gM(s){return Cl(s).nodes.map(t=>({id:t.id,type:t.type,position:t.position,data:{label:t.label,ruleCode:t.ruleCode,nodeType:mX(t.type),...t.data}}))}function bCe(s){return Cl(s).edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??t.edgeType,data:{edgeType:t.edgeType}}))}function Yet(s,e){switch(e.type){case"commit":{const t=Cl(e.graph);return Yl(t)===Yl(s.present)?s:{past:[...s.past,s.present].slice(-50),present:t,future:[]}}case"undo":{if(s.past.length===0)return s;const t=s.past[s.past.length-1];return{past:s.past.slice(0,-1),present:t,future:[s.present,...s.future]}}case"redo":{if(s.future.length===0)return s;const[t,...i]=s.future;return{past:[...s.past,s.present].slice(-50),present:t,future:i}}case"reset":return{past:[],present:Cl(e.graph),future:[]};default:return s}}function Jet(s){const e=ve.useMemo(()=>Cl(s),[s]),[t,i]=ve.useReducer(Yet,{past:[],present:e,future:[]}),n=ve.useCallback(l=>{i({type:"commit",graph:l})},[]),r=ve.useCallback(()=>{i({type:"undo"})},[]),o=ve.useCallback(()=>{i({type:"redo"})},[]),a=ve.useCallback(l=>{i({type:"reset",graph:l})},[]);return ve.useMemo(()=>({present:t.present,canUndo:t.past.length>0,canRedo:t.future.length>0,commit:n,undo:r,redo:o,reset:a}),[n,o,a,t.future.length,t.past.length,t.present,r])}const ett=Mi.theme({"&":{fontSize:"12px",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},".cm-content":{padding:"10px 12px",minHeight:"160px"},".cm-editor":{background:"var(--mu-surface-base)"},".cm-editor.cm-focused":{outline:"2px solid color-mix(in oklch, var(--mu-color-interactive) 40%, transparent)"},".cm-gutters":{background:"var(--mu-surface-raised)",color:"var(--mu-text-muted)",borderRight:"1px solid color-mix(in oklch, var(--mu-border-subtle) 60%, transparent)"},".cm-activeLine":{background:"color-mix(in oklch, var(--mu-surface-raised) 50%, transparent)"},".cm-selectionBackground":{background:"color-mix(in oklch, var(--mu-color-interactive) 15%, transparent) !important"},".cm-cursor":{borderLeftColor:"var(--mu-text-primary)"},".cm-tooltip":{borderRadius:"12px",border:"1px solid color-mix(in oklch, var(--mu-border-subtle) 80%, transparent)",boxShadow:"0 4px 12px rgba(0,0,0,0.08)",fontSize:"12px",background:"var(--mu-surface-raised)",color:"var(--mu-text-primary)"},".cm-tooltip-autocomplete":{borderRadius:"12px"},".cm-tooltip-autocomplete ul li[aria-selected]":{background:"color-mix(in oklch, var(--mu-color-interactive) 12%, transparent)",color:"var(--mu-text-primary)"},".cm-lintRange-error":{backgroundImage:"none",textDecoration:"underline wavy var(--mu-color-error)"},".cm-lintRange-warning":{backgroundImage:"none",textDecoration:"underline wavy var(--mu-color-warning)"},".cm-diagnostic-error":{borderLeft:"3px solid var(--mu-color-error)"},".cm-diagnostic-warning":{borderLeft:"3px solid var(--mu-color-warning)"},".cm-completionIcon-variable::after":{content:"'x'",display:"inline-block",width:"16px",height:"16px",lineHeight:"16px",textAlign:"center",borderRadius:"50%",background:"color-mix(in oklch, var(--mu-color-interactive) 12%, transparent)",color:"var(--mu-color-interactive)",fontSize:"10px",fontWeight:"700"},".cm-completionIcon-function::after":{content:"'f'",display:"inline-block",width:"16px",height:"16px",lineHeight:"16px",textAlign:"center",borderRadius:"50%",background:"color-mix(in oklch, var(--mu-node-condition) 12%, transparent)",color:"var(--mu-node-condition)",fontSize:"10px",fontWeight:"700",fontStyle:"italic"}}),ttt=K$.define([{tag:lt.keyword,color:"var(--mu-node-condition)"},{tag:lt.string,color:"var(--mu-color-success-text)"},{tag:lt.number,color:"var(--mu-color-warning-text)"},{tag:lt.bool,color:"var(--mu-node-condition)"},{tag:lt.null,color:"var(--mu-text-muted)"},{tag:lt.operator,color:"var(--mu-color-interactive)"},{tag:lt.comment,color:"var(--mu-text-muted)",fontStyle:"italic"},{tag:lt.function(lt.variableName),color:"var(--mu-color-interactive)"},{tag:lt.variableName,color:"var(--mu-text-primary)"},{tag:lt.propertyName,color:"var(--mu-color-interactive-subtle)"},{tag:lt.bracket,color:"var(--mu-text-secondary)"},{tag:lt.special(lt.variableName),color:"var(--mu-color-interactive)",fontWeight:"600"}]);UZe(ttt);const _X=[{name:"sum",signature:"(list) -> number",description:"Sum of all numbers in a list",template:"sum()",group:"Math"},{name:"count",signature:"(list) -> number",description:"Count of elements in a list",template:"count()",group:"Math"},{name:"min",signature:"(a, b, ...) -> number",description:"Minimum value",template:"min()",group:"Math"},{name:"max",signature:"(a, b, ...) -> number",description:"Maximum value",template:"max()",group:"Math"},{name:"mean",signature:"(list) -> number",description:"Arithmetic mean of a list",template:"mean()",group:"Math"},{name:"abs",signature:"(n) -> number",description:"Absolute value",template:"abs()",group:"Math"},{name:"floor",signature:"(n) -> number",description:"Round down to nearest integer",template:"floor()",group:"Math"},{name:"ceiling",signature:"(n) -> number",description:"Round up to nearest integer",template:"ceiling()",group:"Math"},{name:"round up",signature:"(n, scale) -> number",description:"Round up to given scale",template:"round up(, )",group:"Math"},{name:"round down",signature:"(n, scale) -> number",description:"Round down to given scale",template:"round down(, )",group:"Math"},{name:"decimal",signature:"(n, scale) -> number",description:"Round to specified decimal places",template:"decimal(, )",group:"Math"},{name:"modulo",signature:"(dividend, divisor) -> number",description:"Remainder of division",template:"modulo(, )",group:"Math"},{name:"sqrt",signature:"(n) -> number",description:"Square root",template:"sqrt()",group:"Math"},{name:"log",signature:"(n) -> number",description:"Natural logarithm",template:"log()",group:"Math"},{name:"exp",signature:"(n) -> number",description:"Euler's number raised to power",template:"exp()",group:"Math"},{name:"if",signature:"condition then value else alternative",description:"Conditional expression",template:"if then else ",group:"Logic"},{name:"not",signature:"(value) -> boolean",description:"Logical negation",template:"not()",group:"Logic"},{name:"and",signature:"(a, b) -> boolean",description:"Logical conjunction",template:"and(, )",group:"Logic"},{name:"or",signature:"(a, b) -> boolean",description:"Logical disjunction",template:"or(, )",group:"Logic"},{name:"for",signature:"item in collection return expression",description:"Iterate over collection",template:"for in return ",group:"Collection"},{name:"some",signature:"item in collection satisfies condition",description:"Existential quantifier",template:"some in satisfies ",group:"Collection"},{name:"every",signature:"item in collection satisfies condition",description:"Universal quantifier",template:"every in satisfies ",group:"Collection"},{name:"list contains",signature:"(list, element) -> boolean",description:"Check if list contains element",template:"list contains(, )",group:"Collection"},{name:"append",signature:"(list, item) -> list",description:"Append item to list",template:"append(, )",group:"Collection"},{name:"concatenate",signature:"(list1, list2) -> list",description:"Concatenate two lists",template:"concatenate(, )",group:"Collection"},{name:"flatten",signature:"(list) -> list",description:"Flatten nested list",template:"flatten()",group:"Collection"},{name:"distinct values",signature:"(list) -> list",description:"Remove duplicates from list",template:"distinct values()",group:"Collection"},{name:"sort",signature:"(list) -> list",description:"Sort list in ascending order",template:"sort()",group:"Collection"},{name:"reverse",signature:"(list) -> list",description:"Reverse list order",template:"reverse()",group:"Collection"},{name:"index of",signature:"(list, element) -> number",description:"Find index of element in list",template:"index of(, )",group:"Collection"},{name:"union",signature:"(list1, list2) -> list",description:"Union of two lists (deduplicated)",template:"union(, )",group:"Collection"},{name:"sublist",signature:"(list, start, length) -> list",description:"Extract sublist",template:"sublist(, , )",group:"Collection"},{name:"string",signature:"(value) -> string",description:"Convert value to string",template:"string()",group:"Type"},{name:"number",signature:"(from, grouping, decimal) -> number",description:"Parse string to number",template:"number(, , )",group:"Type"},{name:"date",signature:"(from) -> date",description:"Parse string to date",template:"date()",group:"Type"},{name:"time",signature:"(from) -> time",description:"Parse string to time",template:"time()",group:"Type"},{name:"date and time",signature:"(from) -> date-time",description:"Parse string to date-time",template:"date and time()",group:"Type"},{name:"duration",signature:"(from) -> duration",description:"Parse string to duration",template:"duration()",group:"Type"},{name:"string length",signature:"(s) -> number",description:"Length of string",template:"string length()",group:"String"},{name:"substring",signature:"(s, start, length) -> string",description:"Extract substring",template:"substring(, , )",group:"String"},{name:"upper case",signature:"(s) -> string",description:"Convert to uppercase",template:"upper case()",group:"String"},{name:"lower case",signature:"(s) -> string",description:"Convert to lowercase",template:"lower case()",group:"String"},{name:"contains",signature:"(s, match) -> boolean",description:"Check if string contains match",template:"contains(, )",group:"String"},{name:"starts with",signature:"(s, match) -> boolean",description:"Check if string starts with match",template:"starts with(, )",group:"String"},{name:"ends with",signature:"(s, match) -> boolean",description:"Check if string ends with match",template:"ends with(, )",group:"String"},{name:"matches",signature:"(s, pattern) -> boolean",description:"Check if string matches regex pattern",template:"matches(, )",group:"String"},{name:"replace",signature:"(s, pattern, replacement) -> string",description:"Replace pattern in string",template:"replace(, , )",group:"String"},{name:"split",signature:"(s, delimiter) -> list",description:"Split string by delimiter",template:"split(, )",group:"String"},{name:"now",signature:"() -> date-time",description:"Current date and time",template:"now()",group:"Date"},{name:"today",signature:"() -> date",description:"Current date",template:"today()",group:"Date"},{name:"day of week",signature:"(date) -> string",description:"Day of week name",template:"day of week()",group:"Date"},{name:"month of year",signature:"(date) -> string",description:"Month of year name",template:"month of year()",group:"Date"},{name:"years and months duration",signature:"(from, to) -> duration",description:"Duration between two dates in years and months",template:"years and months duration(, )",group:"Date"}],itt=new Set(["true","false","null","if","then","else","for","in","return","some","every","satisfies","not","and","or","between","instance","of","function"]),ntt=new Set(_X.map(s=>s.name)),vCe=(()=>{const s=["Math","Logic","Collection","Type","String","Date"],e=new Map;for(const t of s)e.set(t,[]);for(const t of _X)e.get(t.group).push(t);return s.map(t=>({group:t,functions:e.get(t)}))})(),stt=()=>M.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:M.jsx("path",{d:"M6 3l5 5-5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),rtt=()=>M.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:M.jsx("path",{d:"M3 6l5 5 5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),ott=vCe.reduce((s,e)=>s+e.functions.length,0),att={borderRadius:14,background:"rgba(241, 245, 249, 0.9)",border:"1px solid rgba(148, 163, 184, 0.18)",overflow:"hidden",marginTop:8},ltt={padding:"10px 12px",cursor:"pointer",fontSize:12,fontWeight:600,color:"var(--mu-color-text-secondary)",display:"flex",alignItems:"center",gap:6,userSelect:"none"},ctt={fontSize:10,fontWeight:600,color:"var(--mu-color-text-muted)",background:"color-mix(in oklch, var(--mu-color-border-subtle) 18%, transparent)",borderRadius:8,padding:"1px 6px",marginLeft:"auto"},dtt={padding:"8px 12px 4px",fontSize:11,fontWeight:700,color:"var(--mu-color-text-muted)",textTransform:"uppercase",letterSpacing:"0.04em"},utt={padding:"6px 12px",cursor:"pointer",fontSize:12,borderRadius:8,display:"flex",alignItems:"baseline",gap:6},htt={fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",color:"var(--mu-color-interactive)",fontWeight:600},ftt={color:"var(--mu-color-text-muted)",marginLeft:6,fontSize:11},gtt={maxHeight:280,overflowY:"auto",paddingBottom:6};function ptt({onInsert:s,visible:e}){const[t,i]=ve.useState(!1),[n,r]=ve.useState(null),o=ve.useCallback(()=>{i(a=>!a)},[]);return e?M.jsxs("div",{style:att,children:[M.jsxs("div",{style:ltt,onClick:o,role:"button",tabIndex:0,"aria-expanded":t,children:[t?M.jsx(rtt,{}):M.jsx(stt,{}),M.jsx("span",{children:"FEEL Functions"}),M.jsx("span",{style:ctt,children:ott})]}),t&&M.jsx("div",{style:gtt,children:vCe.map(a=>M.jsxs("div",{children:[M.jsx("div",{style:dtt,children:a.group}),a.functions.map(l=>{const c=`${a.group}:${l.name}`,d=n===c;return M.jsxs("div",{style:{...utt,background:d?"color-mix(in oklch, var(--mu-color-interactive) 6%, transparent)":"transparent"},onClick:()=>s(l.template),onMouseEnter:()=>r(c),onMouseLeave:()=>r(null),title:l.description,role:"button",tabIndex:0,children:[M.jsx("span",{style:htt,children:l.name}),M.jsx("span",{style:ftt,children:l.signature})]},c)})]},a.group))})]}):null}function yCe(s){return fJe({override:[t=>{const i=Oc(s),r=t.state.sliceDoc(0,t.pos).match(/([a-zA-Z_][\w.]*)\.$/);if(r){const d=r[1],u=[];for(const f of i)f.path.startsWith(d+".")&&!f.path.substring(d.length+1).includes(".")&&u.push({label:f.path,type:"variable",detail:f.dataType,info:f.sourceNodeLabel?`From: ${f.sourceNodeLabel}`:void 0,boost:2});if(u.length>0)return{from:t.pos-d.length-1,options:u,validFor:/^[\w.]*$/}}const o=t.matchBefore(/[a-zA-Z_][\w.]*/);if(!o&&!t.explicit)return null;const a=o?o.from:t.pos,l=i.map(d=>({label:d.path,type:"variable",detail:d.dataType,info:d.sourceNodeLabel?`From: ${d.sourceNodeLabel}`:void 0,boost:1})),c=_X.map(d=>({label:d.name,type:"function",detail:d.signature,info:d.description,apply:d.template,boost:0}));return{from:a,options:[...l,...c],validFor:/^[\w.]*$/}}],activateOnTyping:!0})}class wCe{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class dS{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(w_).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((p,m)=>p.from-m.from||p.to-m.to),o=new YE,a=[],l=0,c=i.doc.iter(),d=0,u=i.doc.length;for(let p=0;;){let m=p==r.length?null:r[p];if(!m&&!a.length)break;let b,w;if(a.length)b=l,w=a.reduce((O,L)=>Math.min(O,L.to),m&&m.from>b?m.from:1e8);else{if(b=m.from,b>u)break;w=m.to,a.push(m),p++}for(;p<r.length;){let O=r[p];if(O.from==b&&(O.to>O.from||O.to==b))a.push(O),p++,w=Math.min(O.to,w);else{w=Math.min(O.from,w);break}}w=Math.min(w,u);let S=!1;if(a.some(O=>O.from==b&&(O.to==w||w==u))&&(S=b==w,!S&&w-b<10)){let O=b-(d+c.value.length);O>0&&(c.next(O),d=b);for(let L=b;;){if(L>=w){S=!0;break}if(!c.lineBreak&&d+c.value.length>L)break;L=d+c.value.length,d+=c.value.length,c.next()}}let k=ICe(a);if(S)o.add(b,b,ks.widget({widget:new Stt(k),diagnostics:a.slice()}));else{let O=a.reduce((L,D)=>D.markClass?L+" "+D.markClass:L,"");o.add(b,w,ks.mark({class:"cm-lintRange cm-lintRange-"+k+O,diagnostics:a.slice(),inclusiveEnd:a.some(L=>L.to>w)}))}if(l=w,l==u)break;for(let O=0;O<a.length;O++)a[O].to<=l&&a.splice(O--,1)}let f=o.finish();return new dS(f,t,vL(f))}}function vL(s,e=null,t=0){let i=null;return s.between(t,1e9,(n,r,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!i)i=new wCe(n,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new wCe(i.from,r,i.diagnostic)}}),i}function CCe(s,e){let t=e.pos,i=e.end||t,n=s.state.facet(w_).hideOn(s,t,i);if(n!=null)return n;let r=s.startState.doc.lineAt(e.pos);return!!(s.effects.some(o=>o.is(u8))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function mtt(s,e){return s.field(Dp,!1)?e:e.concat(Ms.appendConfig.of(ACe))}function _tt(s,e){return{effects:mtt(s,[u8.of(e)])}}const u8=Ms.define(),SCe=Ms.define(),xCe=Ms.define(),Dp=ru.define({create(){return new dS(ks.none,null,null)},update(s,e){if(e.docChanged&&s.diagnostics.size){let t=s.diagnostics.map(e.changes),i=null,n=s.panel;if(s.selected){let r=e.changes.mapPos(s.selected.from,1);i=vL(t,s.selected.diagnostic,r)||vL(t,null,r)}!t.size&&n&&e.state.facet(w_).autoPanel&&(n=null),s=new dS(t,n,i)}for(let t of e.effects)if(t.is(u8)){let i=e.state.facet(w_).autoPanel?t.value.length?h8.open:null:s.panel;s=dS.init(t.value,i,e.state)}else t.is(SCe)?s=new dS(s.diagnostics,t.value?h8.open:null,s.selected):t.is(xCe)&&(s=new dS(s.diagnostics,s.panel,t.value));return s},provide:s=>[hZ.from(s,e=>e.panel),Mi.decorations.from(s,e=>e.diagnostics)]}),btt=ks.mark({class:"cm-lintRange cm-lintRange-active"});function vtt(s,e,t){let{diagnostics:i}=s.state.field(Dp),n,r=-1,o=-1;i.between(e-(t<0?1:0),e+(t>0?1:0),(l,c,{spec:d})=>{if(e>=l&&e<=c&&(l==c||(e>l||t>0)&&(e<c||t<0)))return n=d.diagnostics,r=l,o=c,!1});let a=s.state.facet(w_).tooltipFilter;return n&&a&&(n=a(n,s.state)),n?{pos:r,end:o,above:s.state.doc.lineAt(r).to<o,create(){return{dom:kCe(s,n)}}}:null}function kCe(s,e){return c_("ul",{class:"cm-tooltip-lint"},e.map(t=>TCe(s,t,!1)))}const OCe=s=>{let e=s.state.field(Dp,!1);return!e||!e.panel?!1:(s.dispatch({effects:SCe.of(!1)}),!0)},ytt=Zl.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:e}=s.state.facet(w_);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(w_);t.length&&wtt(t.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==e.doc&&this.view.dispatch(_tt(this.view.state,i.reduce((n,r)=>n.concat(r))))},i=>{au(this.view.state,i)})}}update(s){let e=s.state.facet(w_);(s.docChanged||e!=s.startState.facet(w_)||e.needsRefresh&&e.needsRefresh(s))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function wtt(s,e,t){let i=[],n=-1;for(let r of s)r.then(o=>{i.push(o),clearTimeout(n),i.length==s.length?e(i):n=setTimeout(()=>e(i),200)},t)}const w_=Li.define({combine(s){return{sources:s.map(e=>e.source).filter(e=>e!=null),...KC(s.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ECe,tooltipFilter:ECe,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})}}});function ECe(s,e){return s?e?(t,i)=>e(s(t,i),i):s:e}function Ctt(s,e={}){return[w_.of({source:s,config:e}),ytt,ACe]}function LCe(s){let e=[];if(s)e:for(let{name:t}of s){for(let i=0;i<t.length;i++){let n=t[i];if(/[a-zA-Z]/.test(n)&&!e.some(r=>r.toLowerCase()==n.toLowerCase())){e.push(n);continue e}}e.push("")}return e}function TCe(s,e,t){var i;let n=t?LCe(e.actions):[];return c_("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},c_("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(s):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let a=!1,l=p=>{if(p.preventDefault(),a)return;a=!0;let m=vL(s.state.field(Dp).diagnostics,e);m&&r.apply(s,m.from,m.to)},{name:c}=r,d=n[o]?c.indexOf(n[o]):-1,u=d<0?c:[c.slice(0,d),c_("u",c.slice(d,d+1)),c.slice(d+1)],f=r.markClass?" "+r.markClass:"";return c_("button",{type:"button",class:"cm-diagnosticAction"+f,onclick:l,onmousedown:l,"aria-label":` Action: ${c}${d<0?"":` (access key "${n[o]})"`}.`},u)}),e.source&&c_("div",{class:"cm-diagnosticSource"},e.source))}class Stt extends ZC{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return c_("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class DCe{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=TCe(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class h8{constructor(e){this.view=e,this.items=[];let t=n=>{if(!(n.ctrlKey||n.altKey||n.metaKey)){if(n.keyCode==27)OCe(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=LCe(r.actions);for(let a=0;a<o.length;a++)if(o[a].toUpperCase().charCodeAt(0)==n.keyCode){let l=vL(this.view.state.field(Dp).diagnostics,r);l&&r.actions[a].apply(e,l.from,l.to)}}else return;n.preventDefault()}},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=c_("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=c_("div",{class:"cm-panel-lint"},this.list,c_("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>OCe(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Dp).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Dp),i=0,n=!1,r=null,o=new Set;for(e.between(0,this.view.state.doc.length,(a,l,{spec:c})=>{for(let d of c.diagnostics){if(o.has(d))continue;o.add(d);let u=-1,f;for(let p=i;p<this.items.length;p++)if(this.items[p].diagnostic==d){u=p;break}u<0?(f=new DCe(this.view,d),this.items.splice(i,0,f),n=!0):(f=this.items[u],u>i&&(this.items.splice(i,u-i),n=!0)),t&&f.diagnostic==t.diagnostic?f.dom.hasAttribute("aria-selected")||(f.dom.setAttribute("aria-selected","true"),r=f):f.dom.hasAttribute("aria-selected")&&f.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new DCe(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:l})=>{let c=l.height/this.list.offsetHeight;a.top<l.top?this.list.scrollTop-=(l.top-a.top)/c:a.bottom>l.bottom&&(this.list.scrollTop+=(a.bottom-l.bottom)/c)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(Dp),i=vL(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:xCe.of(i)})}static open(e){return new h8(e)}}function f8(s,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(s)}</svg>')`}function g8(s){return f8(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const xtt=Mi.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:g8("#d11")},".cm-lintRange-warning":{backgroundImage:g8("orange")},".cm-lintRange-info":{backgroundImage:g8("#999")},".cm-lintRange-hint":{backgroundImage:g8("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function ktt(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function ICe(s){let e="hint",t=1;for(let i of s){let n=ktt(i.severity);n>t&&(t=n,e=i.severity)}return e}class RCe extends Hw{constructor(e){super(),this.diagnostics=e,this.severity=ICe(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,n=e.state.facet(p8).tooltipFilter;return n&&(i=n(i,e.state)),i.length&&(t.onmouseover=()=>Ett(e,t,i)),t}}function Ott(s,e){let t=i=>{let n=e.getBoundingClientRect();if(!(i.clientX>n.left-10&&i.clientX<n.right+10&&i.clientY>n.top-10&&i.clientY<n.bottom+10)){for(let r=i.target;r;r=r.parentNode)if(r.nodeType==1&&r.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",t),s.state.field(NCe)&&s.dispatch({effects:vX.of(null)})}};window.addEventListener("mousemove",t)}function Ett(s,e,t){function i(){let o=s.elementAtHeight(e.getBoundingClientRect().top+5-s.documentTop);s.coordsAtPos(o.from)&&s.dispatch({effects:vX.of({pos:o.from,above:!1,clip:!1,create(){return{dom:kCe(s,t),getCoords:()=>e.getBoundingClientRect()}}})}),e.onmouseout=e.onmousemove=null,Ott(s,e)}let{hoverTime:n}=s.state.facet(p8),r=setTimeout(i,n);e.onmouseout=()=>{clearTimeout(r),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(r),r=setTimeout(i,n)}}function Ltt(s,e){let t=Object.create(null);for(let n of e){let r=s.lineAt(n.from);(t[r.from]||(t[r.from]=[])).push(n)}let i=[];for(let n in t)i.push(new RCe(t[n]).range(+n));return xs.of(i,!0)}const Ttt=lZe({class:"cm-gutter-lint",markers:s=>s.state.field(bX),widgetMarker:(s,e,t)=>{let i=[];return s.state.field(bX).between(t.from,t.to,(n,r,o)=>{n>t.from&&n<t.to&&i.push(...o.diagnostics)}),i.length?new RCe(i):null}}),bX=ru.define({create(){return xs.empty},update(s,e){s=s.map(e.changes);let t=e.state.facet(p8).markerFilter;for(let i of e.effects)if(i.is(u8)){let n=i.value;t&&(n=t(n||[],e.state)),s=Ltt(e.state.doc,n.slice(0))}return s}}),vX=Ms.define(),NCe=ru.define({create(){return null},update(s,e){return s&&e.docChanged&&(s=CCe(e,s)?null:{...s,pos:e.changes.mapPos(s.pos)}),e.effects.reduce((t,i)=>i.is(vX)?i.value:t,s)},provide:s=>N$.from(s)}),Dtt=Mi.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:f8('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:f8('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:f8('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),ACe=[Dp,Mi.decorations.compute([Dp],s=>{let{selected:e,panel:t}=s.field(Dp);return!e||!t||e.from==e.to?ks.none:ks.set([btt.range(e.from,e.to)])}),nZe(vtt,{hideOn:CCe}),xtt],p8=Li.define({combine(s){return KC(s,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function Itt(s={}){return[p8.of(s),bX,Ttt,Dtt,NCe]}function Rtt(s){return[Ctt(t=>{const i=t.state.doc.toString(),n=[];if(!i.trim())return n.push({from:0,to:i.length||0,severity:"info",message:"Expression is empty"}),n;const r=[["(",")"],["[","]"],["{","}"]];for(const[b,w]of r){const S=[];for(let k=0;k<i.length;k++){if(i[k]==='"'){for(k++;k<i.length&&i[k]!=='"';)i[k]==="\\"&&k++,k++;continue}i[k]===b?S.push(k):i[k]===w&&(S.length>0?S.pop():n.push({from:k,to:k+1,severity:"error",message:`Unmatched closing '${w}'`}))}for(const k of S)n.push({from:k,to:k+1,severity:"error",message:`Unmatched opening '${b}'`})}let o=!1,a=0;for(let b=0;b<i.length;b++)i[b]==='"'&&(b===0||i[b-1]!=="\\")&&(o?o=!1:(o=!0,a=b));o&&n.push({from:a,to:a+1,severity:"error",message:"Unclosed string literal"});const l=Oc(s),c=new Set(l.map(b=>b.path)),d=/[a-zA-Z_][\w]*/g;let u;const f=[];let p=-1;for(let b=0;b<i.length;b++)i[b]==='"'&&(b===0||i[b-1]!=="\\")&&(p<0?p=b:(f.push([p,b]),p=-1));const m=b=>f.some(([w,S])=>b>=w&&b<=S);for(;(u=d.exec(i))!==null;){const b=u[0],w=u.index;if(m(w)||itt.has(b)||ntt.has(b)||/^\d/.test(b))continue;let S=b,k=w+b.length;for(;k<i.length&&i[k]===".";){const R=i.substring(k+1).match(/^[a-zA-Z_][\w]*/);if(R)S+="."+R[0],k=k+1+R[0].length,d.lastIndex=k;else break}if(c.has(S))continue;let O=!1;for(const D of c)if(D.startsWith(S+".")||S.startsWith(D+".")){O=!0;break}if(O)continue;let L=!1;for(const D of c)if(D===b||D.startsWith(b+".")){L=!0;break}L||n.push({from:w,to:w+S.length,severity:"warning",message:`Unknown field reference: ${S}`})}return n},{delay:300}),Itt()]}const Ntt={string:{bg:"var(--mu-color-info-bg)",text:"var(--mu-color-interactive)"},number:{bg:"var(--mu-color-info-bg)",text:"var(--mu-node-condition)"},boolean:{bg:"var(--mu-color-warning-bg)",text:"var(--mu-color-warning-text)"},array:{bg:"var(--mu-color-success-bg)",text:"var(--mu-color-success-text)"},object:{bg:"var(--mu-surface-raised)",text:"var(--mu-text-secondary)"}},Att={bg:"var(--mu-surface-raised)",text:"var(--mu-text-secondary)"};function pM({dataType:s}){const e=Ntt[s.toLowerCase()]??Att;return M.jsx("span",{style:{display:"inline-block",fontSize:11,padding:"1px 6px",borderRadius:4,fontWeight:600,backgroundColor:e.bg,color:e.text,lineHeight:"16px",whiteSpace:"nowrap"},children:s.toLowerCase()})}function yL({icon:s,message:e,actionHint:t,onAction:i}){return M.jsxs("div",{style:{background:"var(--mu-surface-raised)",border:"1px solid var(--mu-border-subtle)",borderRadius:8,padding:"16px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:6,textAlign:"center"},children:[M.jsx("span",{style:{fontSize:16},children:s??"ⓘ"}),M.jsx("span",{style:{color:"var(--mu-text-muted)",fontSize:13},children:e}),t&&i?M.jsx("span",{role:"button",tabIndex:0,onClick:i,onKeyDown:n=>{n.key==="Enter"&&i()},style:{color:"var(--mu-color-interactive)",cursor:"pointer",textDecoration:"underline",fontSize:13},children:t}):null]})}const Mtt={display:"flex",alignItems:"center",gap:6,padding:"4px 8px",borderRadius:4,cursor:"pointer",fontSize:12,color:"var(--mu-text-primary)",transition:"background-color 0.1s"};function MCe({field:s,depth:e,readOnly:t,onInsert:i,defaultExpanded:n=!0}){var p;const r=(((p=s.children)==null?void 0:p.length)??0)>0,[o,a]=ve.useState(n),[l,c]=ve.useState(!1),d=s.path.split("."),u=d[d.length-1],f=d.length>1?d.slice(0,-1).join(".")+".":"";return M.jsxs("div",{children:[M.jsxs("div",{style:{...Mtt,paddingLeft:e*20+8,backgroundColor:l?"var(--mu-surface-raised)":"transparent"},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[r?M.jsx("span",{role:"button",tabIndex:0,onClick:m=>{m.stopPropagation(),a(!o)},onKeyDown:m=>{m.key==="Enter"&&a(!o)},style:{width:16,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:10,color:"var(--mu-text-muted)",flexShrink:0,userSelect:"none"},children:o?"▼":"▶"}):M.jsx("span",{style:{width:16,flexShrink:0}}),M.jsxs("button",{type:"button",disabled:t,onClick:()=>i(s.path),style:{border:"none",background:"transparent",padding:0,cursor:t?"default":"pointer",fontSize:12,color:"var(--mu-text-primary)",textAlign:"left",fontFamily:"inherit"},children:[f?M.jsx("span",{style:{color:"var(--mu-text-secondary)"},children:f}):null,M.jsx("strong",{children:u})]}),M.jsx(pM,{dataType:s.dataType}),s.sourceNodeLabel?M.jsx("span",{style:{fontSize:11,color:"var(--mu-text-secondary)",marginLeft:"auto"},children:s.sourceNodeLabel}):null]}),r&&o?M.jsx("div",{children:s.children.map(m=>M.jsx(MCe,{field:m,depth:e+1,readOnly:t,onInsert:i,defaultExpanded:n},m.path))}):null]})}const Ptt={rule:"Schema loaded from the registered rule code",flow:"Uses the flow's input schema","decision-table":"Schema from the linked decision table",api:"Schema fetched from external API endpoint",inline:"Schema defined manually in this node"};function m8({tooltip:s}){return M.jsx("span",{title:s,style:{display:"inline-flex",alignItems:"center",marginLeft:4,cursor:"help",color:"var(--mu-text-secondary)"},children:M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:M.jsx("path",{d:"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zm0 2.5a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM6.5 7h2v5h-2V7h1z"})})})}const Ftt={display:"flex",flexDirection:"column",gap:8,padding:"10px 14px",background:"var(--mu-surface-raised)",border:"1px solid var(--mu-border-subtle)",borderRadius:12};function Btt(s){var l,c,d,u,f,p,m,b;const{selectedNode:e,contractLoadState:t,readOnly:i,inspectorTab:n,setInspectorTab:r,showSectionHeader:o=!0}=s,a=e==null?void 0:e.data.contractLayer;return M.jsxs("div",{style:Ztt,children:[o?M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Inspector"}),M.jsx("span",{children:e?`Editing ${_L[e.data.nodeType]}`:"Select a node to edit it."})]}):null,e?M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0},children:[M.jsx("div",{role:"tablist","aria-label":"Node inspector sections",style:Xtt,children:Get(e.data.nodeType).map(w=>M.jsx("button",{role:"tab","aria-selected":w===n,type:"button",style:cit(w===n),onClick:()=>r(w),children:Ket(w)},w))}),n==="basic-info"?M.jsx($tt,{...s}):null,n==="input-data"?M.jsx(Utt,{title:"Input Scope",subtitle:((l=a==null?void 0:a.upstreamScope)==null?void 0:l.title)??"Everything available before this node executes.",contract:a==null?void 0:a.upstreamScope,loadState:t,readOnly:i,onInsert:s.onInsertExpressionToken,groupBySource:!0}):null,n==="data-mapping"?M.jsx(qtt,{nodeType:e.data.nodeType,readOnly:i,upstreamFields:Oc(((c=a==null?void 0:a.upstreamScope)==null?void 0:c.fields)??[]),targetFields:((d=a==null?void 0:a.effectiveInput)==null?void 0:d.fields)??[],rows:((u=a==null?void 0:a.effectiveInput)==null?void 0:u.mappings)??[],onInsert:s.onInsertExpressionToken,onChangeTargetFields:s.onChangeInputContract,onChange:s.onChangeEffectiveMappings,setInspectorTab:r,hasExpression:!!((p=(f=s.selectedExpression)==null?void 0:f.body)!=null&&p.trim())}):null,n==="output-data"?M.jsx(Qtt,{nodeType:e.data.nodeType,contract:a==null?void 0:a.outputContract,upstreamScope:a==null?void 0:a.upstreamScope,issues:(a==null?void 0:a.validationIssues)??[],readOnly:i,onInsert:s.onInsertExpressionToken,onChange:s.onChangeOutputContract}):null,n==="logic"?M.jsx(Wtt,{nodeType:e.data.nodeType,expression:s.selectedExpression,upstreamScope:a==null?void 0:a.upstreamScope,outputContract:a==null?void 0:a.outputContract,liquidOutput:(m=e.data.liquidConfig)==null?void 0:m.outputFormat,readOnly:i,apiBaseUrl:s.apiBaseUrl,onChangeLanguage:s.onUpdateExpressionLanguage,onChangeBody:s.onUpdateExpressionBody,onInsertRef:s.onSetInsertRef,shadowRoot:s.shadowRoot}):null,(b=a==null?void 0:a.validationIssues)!=null&&b.length?M.jsx(BCe,{issues:a.validationIssues}):null,t.status==="error"?M.jsx("div",{style:nit,children:t.message}):null,i?null:M.jsx("button",{type:"button",style:iit,onClick:s.onDeleteNode,children:"Delete Node"})]}):M.jsx("div",{style:{color:"var(--mu-text-muted)",fontSize:13,lineHeight:1.5},children:"Use the palette to add a node, then inspect available input scope, effective mappings, and output contract before publishing."})]})}function $tt(s){var l,c,d,u,f,p,m;const{selectedNode:e,readOnly:t,flowOptions:i,decisionTableOptions:n,selectedDecisionTable:r,decisionTableLoadState:o}=s;if(!e)return M.jsx(M.Fragment,{});const a=e.data.dependsOn??[];return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("label",{style:bd,children:["Label",M.jsx("input",{style:Jl,value:e.data.label,disabled:t,onChange:b=>s.onUpdateLabel(b.target.value)})]}),M.jsxs("label",{style:bd,children:["Rule Code",M.jsx("input",{style:Jl,value:e.data.ruleCode??"",disabled:t,onChange:b=>s.onUpdateRuleCode(b.target.value)})]}),M.jsxs("label",{style:bd,children:["Description",M.jsx("textarea",{style:yX,value:String(e.data.description??""),disabled:t,placeholder:"Describe what this node does for documentation purposes",onChange:b=>s.onUpdateDescription(b.target.value)})]}),M.jsxs("div",{style:Ytt,children:[M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Contract Source",M.jsx(m8,{tooltip:"Determines where this node's input/output schema comes from"})]}),M.jsxs("select",{style:Jl,value:((l=e.data.contractRef)==null?void 0:l.sourceType)??c8(e.data.nodeType),disabled:t,onChange:b=>{var w,S;return s.onUpdateContractRef({sourceType:b.target.value,sourceCode:((w=e.data.contractRef)==null?void 0:w.sourceCode)??e.data.ruleCode??"",label:(S=e.data.contractRef)==null?void 0:S.label})},children:[M.jsx("option",{value:"rule",children:"rule"}),M.jsx("option",{value:"flow",children:"flow"}),M.jsx("option",{value:"decision-table",children:"decision-table"}),M.jsx("option",{value:"api",children:"api"}),M.jsx("option",{value:"inline",children:"inline"})]}),M.jsx("span",{style:{fontSize:11,color:"var(--mu-text-muted)",fontStyle:"italic",marginTop:2,lineHeight:1.4},children:Ptt[((c=e.data.contractRef)==null?void 0:c.sourceType)??c8(e.data.nodeType)]??""})]}),M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Contract Code",M.jsx(m8,{tooltip:"The unique identifier used to look up the contract"})]}),M.jsx("input",{style:Jl,value:((d=e.data.contractRef)==null?void 0:d.sourceCode)??"",disabled:t,onChange:b=>{var w,S;return s.onUpdateContractRef({sourceType:((w=e.data.contractRef)==null?void 0:w.sourceType)??c8(e.data.nodeType),sourceCode:b.target.value,label:(S=e.data.contractRef)==null?void 0:S.label})}})]})]}),M.jsxs("div",{style:Ftt,children:[M.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[M.jsx("span",{style:{marginRight:4},children:"📋"}),M.jsx("strong",{children:"Order:"})," ",e.data.order??"n/a"]}),M.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[M.jsx("span",{style:{marginRight:4},children:"🔗"}),M.jsx("strong",{children:"Depends On:"}),a.length===0?M.jsx("span",{children:"none"}):a.map(b=>M.jsx("button",{type:"button","data-testid":`depends-chip-${b}`,style:oit,onClick:()=>s.onSelectNodeByRuleCode(b),children:b},b))]})]}),e.data.nodeType==="condition"?M.jsx(Htt,{readOnly:t,value:e.data.conditionConfig,onChange:s.onUpdateConditionConfig}):null,e.data.nodeType==="decision-table"?M.jsxs(M.Fragment,{children:[M.jsxs("label",{style:bd,children:["Decision Table",M.jsxs("select",{style:Jl,value:((u=e.data.contractRef)==null?void 0:u.sourceCode)??"",disabled:t,onChange:b=>s.onUpdateDecisionTableCode(b.target.value),children:[M.jsx("option",{value:"",children:"Select decision table"}),n.map(b=>M.jsx("option",{value:b.code,children:b.label},b.code))]})]}),M.jsx(ztt,{table:r,loadState:o})]}):null,e.data.nodeType==="sub-flow"?M.jsxs("label",{style:bd,children:["Target Flow Code",M.jsxs("select",{style:Jl,value:Tp(e.data.subFlowConfig).targetFlowCode??"",disabled:t,onChange:b=>s.onUpdateTargetFlowCode(b.target.value),children:[M.jsx("option",{value:"",children:"Select target flow"}),i.map(b=>M.jsx("option",{value:b.code,children:b.label},b.code))]})]}):null,e.data.nodeType==="liquid"?M.jsxs("label",{style:bd,children:["Liquid Output",M.jsxs("select",{style:Jl,value:gCe(e.data.liquidConfig).outputFormat??"json",disabled:t,onChange:b=>s.onUpdateLiquidOutput(b.target.value),children:[M.jsx("option",{value:"json",children:"json"}),M.jsx("option",{value:"object",children:"object"}),M.jsx("option",{value:"text",children:"text"})]})]}):null,e.data.nodeType==="connector"?M.jsx(Vtt,{config:{connectorType:((f=e.data.connectorConfig)==null?void 0:f.connectorType)??"",connectorConfig:((p=e.data.connectorConfig)==null?void 0:p.connectorConfig)??(e.data.connectorConfig&&("url"in e.data.connectorConfig||"method"in e.data.connectorConfig)?e.data.connectorConfig:{}),credentialId:(m=e.data.connectorConfig)==null?void 0:m.credentialId},catalog:s.connectorCatalog??[],readOnly:t,onChange:s.onUpdateConnectorConfig}):null]})}function Wtt({nodeType:s,expression:e,upstreamScope:t,outputContract:i,liquidOutput:n,readOnly:r,apiBaseUrl:o,onChangeLanguage:a,onChangeBody:l,onInsertRef:c,shadowRoot:d}){const u=ve.useRef(null),f=s==="liquid"||e.language==="liquid"?lit(e.body,(t==null?void 0:t.fields)??[],n??"json"):"",m=Oc((i==null?void 0:i.fields)??[]).filter(S=>{var k;return(k=S.valueExpression)==null?void 0:k.trim()}),b=m.length>0,w=s==="action"||s==="connector";return M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:w&&(b||!e.body.trim())?M.jsxs(M.Fragment,{children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Per-Field Value Expressions"}),M.jsx("span",{children:b?"This node computes output fields using individual FEEL expressions. Edit them in the Output Data tab.":"No value expressions configured yet. Add output fields with expressions in the Output Data tab."})]}),b?M.jsx("div",{style:wX,children:M.jsxs("table",{style:CX,children:[M.jsx("thead",{children:M.jsxs("tr",{children:[M.jsx("th",{style:gg,children:"Output Field"}),M.jsx("th",{style:gg,children:"Type"}),M.jsx("th",{style:gg,children:"Expression"})]})}),M.jsx("tbody",{children:m.map(S=>M.jsxs("tr",{children:[M.jsx("td",{style:pg,children:S.path}),M.jsx("td",{style:pg,children:S.dataType}),M.jsx("td",{style:{...pg,fontFamily:"var(--mu-font-mono)",fontSize:12},children:S.valueExpression})]},S.path))})]})}):null,M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Tip"}),M.jsxs("span",{children:["Switch to the ",M.jsx("strong",{children:"Output Data"})," tab to add or edit value expressions for each output field."]})]})]}):M.jsxs(M.Fragment,{children:[M.jsxs("label",{style:bd,children:["Expression Language",M.jsxs("select",{style:Jl,value:e.language,disabled:r,onChange:S=>a(S.target.value),children:[M.jsx("option",{value:"feel",children:"FEEL"}),M.jsx("option",{value:"javascript",children:"JavaScript"}),M.jsx("option",{value:"scriban",children:"Scriban"}),M.jsx("option",{value:"liquid",children:"Liquid"}),M.jsx("option",{value:"plain-text",children:"Plain Text"})]})]}),(()=>{const S=Oc((t==null?void 0:t.fields)??[]),k=[];return e.language==="feel"&&(k.push(yCe(S)),k.push(Rtt(S))),M.jsxs(M.Fragment,{children:[M.jsxs("div",{style:bd,children:[e.language==="liquid"?"Liquid Template":"Expression",M.jsx(dX,{value:e.body,language:e.language,readOnly:r,onChange:l,onInsertToken:O=>{u.current=O,c==null||c(O)},extensions:k,minHeight:180,root:d})]}),M.jsx(ptt,{visible:e.language==="feel",onInsert:O=>{var L;return(L=u.current)==null?void 0:L.insert(O)}})]})})(),M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Authoring hints"}),M.jsx("span",{children:"Type '.' after a field name or press Ctrl+Space for autocomplete. Click any field in Input Scope to insert at cursor."}),o?M.jsxs("span",{children:["Contract API: ",o]}):null]}),s==="liquid"||e.language==="liquid"?M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Liquid Preview"}),M.jsx("pre",{style:ait,children:f||"Preview is empty."})]}):null]})})}function Htt({readOnly:s,value:e,onChange:t}){const i={successLabel:(e==null?void 0:e.successLabel)??"Valid",failureLabel:(e==null?void 0:e.failureLabel)??"Rejected",failureMessage:(e==null?void 0:e.failureMessage)??""};return M.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Success Label",M.jsx(m8,{tooltip:"Shown on output edges when this condition evaluates to true"})]}),M.jsx("input",{style:Jl,value:i.successLabel,disabled:s,onChange:n=>t({...i,successLabel:n.target.value})})]}),M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Failure Label",M.jsx(m8,{tooltip:"Shown on output edges when this condition evaluates to false"})]}),M.jsx("input",{style:Jl,value:i.failureLabel,disabled:s,onChange:n=>t({...i,failureLabel:n.target.value})})]}),M.jsxs("label",{style:bd,children:["Failure Message",M.jsx("textarea",{style:yX,value:i.failureMessage,disabled:s,onChange:n=>t({...i,failureMessage:n.target.value})})]})]})}function Vtt({config:s,catalog:e,readOnly:t,onChange:i}){const n=e.find(a=>a.connectorType===s.connectorType),r=(n==null?void 0:n.requiresCredentials)||(n==null?void 0:n.credentialFields)&&n.credentialFields.length>0;function o(a){i==null||i({...s,...a})}return M.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[M.jsxs("label",{style:bd,children:["Connector Type",M.jsxs("select",{style:Jl,value:s.connectorType??"",disabled:t,onChange:a=>o({connectorType:a.target.value,connectorConfig:{},credentialId:void 0}),children:[M.jsx("option",{value:"",children:"Select connector type"}),e.map(a=>M.jsxs("option",{value:a.connectorType,children:[a.displayName," ",a.category?`(${a.category})`:""]},a.connectorType))]})]}),s.connectorType?M.jsxs(M.Fragment,{children:[n!=null&&n.description?M.jsx("div",{style:uS,children:M.jsx("span",{children:n.description})}):null,M.jsxs("label",{style:bd,children:["Config JSON",M.jsx("textarea",{style:{...yX,fontFamily:"var(--mu-font-mono)",fontSize:13},value:JSON.stringify(s.connectorConfig??{},null,2),disabled:t,onChange:a=>{try{const l=JSON.parse(a.target.value);o({connectorConfig:l})}catch{}}})]}),n!=null&&n.configSchema?M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Config Schema"}),M.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:11},children:JSON.stringify(n.configSchema,null,2)})]}):null]}):null,r?M.jsxs("label",{style:bd,children:["Credential ID",M.jsx("input",{style:Jl,value:s.credentialId??"",disabled:t,placeholder:"Enter credential identifier",onChange:a=>o({credentialId:a.target.value})})]}):null]})}function ztt({table:s,loadState:e}){return M.jsxs("div",{style:rit,"data-testid":"decision-table-overview",children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Decision Table Schema"}),M.jsx("span",{children:(e==null?void 0:e.status)==="loading"?"Loading decision table columns...":(e==null?void 0:e.status)==="error"?e.message:"Input and output columns drive node contracts and FEEL cell authoring."})]}),s?M.jsxs(M.Fragment,{children:[M.jsxs("div",{children:[M.jsx("strong",{children:s.name})," · v",s.version," · hit policy ",s.hitPolicy]}),s.description?M.jsx("div",{children:s.description}):null,M.jsxs("div",{style:{display:"grid",gap:8},children:[M.jsxs("div",{children:[M.jsx("strong",{children:"Input Columns"}),M.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:s.inputColumns.map(t=>M.jsxs("span",{style:SX,children:[t.label," (",t.dataType,")"]},t.id))})]}),M.jsxs("div",{children:[M.jsx("strong",{children:"Output Columns"}),M.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:s.outputColumns.map(t=>M.jsxs("span",{style:SX,children:[t.label," (",t.dataType,")"]},t.id))})]})]}),M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"FEEL cell hints"}),M.jsx("span",{children:"Input columns become the effective input contract for this node. Output columns are emitted downstream after the table evaluates."}),M.jsx("span",{children:"Use FEEL row expressions against the input column names exactly as defined here."})]})]}):(e==null?void 0:e.status)==="idle"?M.jsx("span",{children:"Select a decision table to preview its column schema."}):null]})}function Utt({title:s,subtitle:e,contract:t,loadState:i,readOnly:n,onInsert:r,groupBySource:o}){const[a,l]=ve.useState("tree"),[c,d]=ve.useState(!0),u=(t==null?void 0:t.fields)??[],f=Oc(u),p=u.length>0,m=new Map;for(const w of u){const S=o?w.sourceNodeLabel??(w.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",k=m.get(S)??[];k.push(w),m.set(S,k)}const b=new Map;for(const w of f){const S=o?w.sourceNodeLabel??(w.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",k=b.get(S)??[];k.push(w),b.set(S,k)}return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:s}),M.jsx("span",{children:i.status==="loading"?"Loading contract...":e})]}),p?M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[a==="tree"?M.jsx("button",{type:"button",onClick:()=>d(!c),style:{border:"1px solid var(--mu-border-subtle)",background:"transparent",borderRadius:6,padding:"3px 8px",fontSize:11,color:"var(--mu-text-muted)",cursor:"pointer",whiteSpace:"nowrap"},children:c?"Collapse All":"Expand All"}):null,M.jsxs("div",{style:{display:"flex",borderRadius:6,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},children:[M.jsx("button",{type:"button",onClick:()=>l("tree"),style:{border:"none",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:a==="tree"?"var(--mu-color-interactive)":"transparent",color:a==="tree"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Schema Tree"}),M.jsx("button",{type:"button",onClick:()=>l("table"),style:{border:"none",borderLeft:"1px solid var(--mu-border-subtle)",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:a==="table"?"var(--mu-color-interactive)":"transparent",color:a==="table"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Flat Table"})]})]}):null]}),p?a==="tree"?M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,maxHeight:420,overflow:"auto"},children:[...m.entries()].map(([w,S])=>M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[o?M.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)",padding:"4px 8px"},children:w}):null,S.map(k=>M.jsx(MCe,{field:k,depth:0,readOnly:n,onInsert:r,defaultExpanded:c},k.path))]},w))},c?"expanded":"collapsed"):[...b.entries()].map(([w,S])=>M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[o?M.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)"},children:w}):null,M.jsx(FCe,{fields:S,readOnly:n,onInsert:r})]},w)):i.status==="loading"?M.jsx(yL,{icon:"\\u231B",message:"Fetching contract metadata..."}):M.jsx(yL,{message:"No scope metadata available for this node."})]})}function jtt({status:s}){const e={mapped:{icon:"✅",label:"Mapped",bg:"var(--mu-color-success-bg)",text:"var(--mu-color-success-text)"},suggested:{icon:"⚠️",label:"Suggested",bg:"var(--mu-color-warning-bg)",text:"var(--mu-color-warning-text)"},missing:{icon:"❌",label:"Missing",bg:"var(--mu-color-error-bg)",text:"var(--mu-color-error-text)"},"type-mismatch":{icon:"🔄",label:"Type Mismatch",bg:"var(--mu-color-warning-bg)",text:"var(--mu-color-warning-text)"}},t=e[s??"mapped"]??e.mapped;return M.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:12,padding:"2px 8px",borderRadius:10,background:t.bg,color:t.text,fontWeight:500},children:[t.icon," ",t.label]})}function qtt({nodeType:s,readOnly:e,upstreamFields:t,targetFields:i,rows:n,onInsert:r,onChangeTargetFields:o,onChange:a,setInspectorTab:l,hasExpression:c}){const d=s==="action"||s==="sub-flow",u=s==="action";function f(w,S){a(n.map(k=>k.id===w?S(k):k))}function p(){const w=`input.${i.length+1}`;o([...i,{path:w,label:w,dataType:"string",required:!1}])}function m(w,S){const k=i.find(L=>L.path===w);if(!k)return;const O=S(k);o(i.map(L=>L.path===w?O:L)),a(n.map(L=>(L.targetField??L.targetPath)===w?{...L,targetField:O.path,targetPath:O.path,targetDataType:O.dataType,required:O.required}:L))}function b(w){o(i.filter(S=>S.path!==w)),a(n.filter(S=>(S.targetField??S.targetPath)!==w))}return n.length===0?s==="action"&&!c?M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&u?M.jsx("button",{type:"button",style:uh(!1),onClick:p,children:"Add Input Slot"}):null]}),M.jsx(yL,{icon:"info",message:"This node uses code-first logic — no expression-based mapping needed. Input/output contracts come from the registered rule code."})]}):(s==="condition"||s==="liquid")&&!c?M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),M.jsx(yL,{icon:"edit",message:"Write a FEEL expression in the Logic tab to see data flow here.",actionHint:"Go to Logic tab",onAction:()=>l("logic")})]}):M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),M.jsx(yL,{icon:"warning",message:"Expression references fields not found in upstream scope. Check field names in the Logic tab.",actionHint:"Go to Logic tab",onAction:()=>l("logic")})]}):M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&u?M.jsx("button",{type:"button",style:uh(!1),onClick:p,children:"Add Input Slot"}):null]}),M.jsx("div",{style:wX,children:M.jsxs("table",{style:CX,children:[M.jsx("thead",{children:M.jsxs("tr",{children:[M.jsx("th",{style:gg,children:"Source"}),M.jsx("th",{style:gg,children:"Target"}),M.jsx("th",{style:gg,children:"Type"}),M.jsx("th",{style:gg,children:"Status"}),M.jsx("th",{style:gg,children:"Transform"}),u?M.jsx("th",{style:gg,children:"Actions"}):null]})}),M.jsx("tbody",{children:n.map(w=>M.jsxs("tr",{children:[M.jsx("td",{style:pg,children:d?M.jsx("input",{list:"upstream-scope-fields",style:Jl,value:w.sourcePath,disabled:e,onChange:S=>f(w.id,k=>({...k,sourcePath:S.target.value}))}):M.jsx("button",{type:"button",style:wL,onClick:()=>r(w.sourcePath),disabled:e||!w.sourcePath,children:w.sourcePath||"unmapped"})}),M.jsx("td",{style:pg,children:u?M.jsx("input",{style:Jl,value:w.targetField??w.targetPath,disabled:e,onChange:S=>m(w.targetField??w.targetPath,k=>({...k,path:S.target.value,label:S.target.value}))}):w.targetField??w.targetPath}),M.jsx("td",{style:pg,children:u?M.jsx("input",{style:Jl,value:w.targetDataType??"string",disabled:e,onChange:S=>m(w.targetField??w.targetPath,k=>({...k,dataType:S.target.value}))}):M.jsx(pM,{dataType:`${w.sourceDataType??"unknown"} → ${w.targetDataType??"unknown"}`})}),M.jsxs("td",{style:pg,children:[M.jsx(jtt,{status:w.status}),w.required?M.jsx("span",{style:{fontSize:10,color:"var(--mu-color-error)",marginLeft:4,fontWeight:600},children:"required"}):null]}),M.jsx("td",{style:pg,children:d?M.jsx("input",{style:Jl,value:w.transform??w.transformSuggestion??"",disabled:e,onChange:S=>f(w.id,k=>({...k,transform:S.target.value}))}):w.transformSuggestion??w.transform??"—"}),u?M.jsx("td",{style:pg,children:M.jsx("button",{type:"button",style:wL,disabled:e,onClick:()=>b(w.targetField??w.targetPath),children:"Remove"})}):null]},w.id))})]})}),M.jsx("datalist",{id:"upstream-scope-fields",children:t.map(w=>M.jsx("option",{value:w.path},w.path))}),i.length?M.jsxs("div",{style:uS,children:[M.jsx("strong",{title:"Fields this node declares it needs — must be provided by upstream nodes or flow input",children:"Required input slots"}),M.jsx("span",{children:i.filter(w=>w.required).map(w=>w.path).join(", ")||"No required fields declared."})]}):null]})}function PCe({title:s,count:e,defaultExpanded:t,headerRight:i,children:n}){const[r,o]=ve.useState(t);return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsxs("div",{role:"button",tabIndex:0,onClick:()=>o(!r),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(!r))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[M.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:r?"▼":"▶"}),M.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:s}),e!==void 0?M.jsxs("span",{style:{background:"var(--mu-border-subtle)",padding:"2px 8px",borderRadius:10,fontSize:11,color:"var(--mu-text-secondary)",fontWeight:600},children:[e," field",e!==1?"s":""]}):null]}),i]}),r?n:null]})}function Qtt({nodeType:s,contract:e,upstreamScope:t,issues:i,readOnly:n,onInsert:r,onChange:o}){if(s==="end")return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Final Scope"}),M.jsx("span",{children:"Everything guaranteed to be available when the flow reaches this end node."})]}),M.jsx(FCe,{fields:Oc((t==null?void 0:t.fields)??[]),readOnly:n,onInsert:r})]});const a=s==="condition"||s==="action",l=Oc((e==null?void 0:e.fields)??[]),c=l.filter(k=>!k.isResultPayload),d=l.filter(k=>k.isResultPayload),p=s==="condition"||s==="action";function m(k,O){const L=l.map(D=>!D.isResultPayload&&c.indexOf(D)===k?O(D):D);o(L)}function b(k){const O=c[k];o(l.filter(L=>L!==O))}function w(){const k=`custom.${c.length+1}`;o([...l,{path:k,label:k,dataType:"string",required:!1}])}const S=(()=>{const k=[];return t&&k.push(yCe(Oc(t.fields))),k})();return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[M.jsx(PCe,{title:"Custom Output Fields",count:c.length,defaultExpanded:!0,headerRight:!n&&a?M.jsx("button",{type:"button",style:uh(!1),onClick:w,children:"Add Field"}):void 0,children:c.length===0?M.jsx(yL,{message:"No custom output fields defined.",actionHint:a&&!n?"Add a field to compute values for downstream nodes.":void 0,onAction:a&&!n?w:void 0}):M.jsx("div",{style:Jtt,children:c.map((k,O)=>M.jsxs("div",{style:eit,children:[M.jsxs("div",{style:$Ce,children:[a?M.jsx("input",{style:{...Jl,flex:"1 1 0%",minWidth:0},value:k.path,disabled:n,placeholder:"field.path",title:"Dotted path where this value is stored in the FactBag",onChange:L=>m(O,D=>({...D,path:L.target.value,label:L.target.value}))}):M.jsx("button",{type:"button",style:{...wL,flex:"1 1 0%",minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},onClick:()=>r(k.path),disabled:n,children:k.path}),a&&!n?M.jsx("button",{type:"button",style:{...wL,color:"var(--mu-color-error-text)",flexShrink:0,fontSize:"var(--mu-text-xs)"},onClick:()=>b(O),title:"Remove this field",children:"delete"}):null]}),M.jsxs("div",{style:$Ce,children:[a&&!n?M.jsx("select",{style:tit,value:k.dataType,title:"Data type of the output value",onChange:L=>m(O,D=>({...D,dataType:L.target.value})),children:["string","number","boolean","object","array"].map(L=>M.jsx("option",{value:L,children:L},L))}):M.jsx(pM,{dataType:k.dataType}),p?M.jsx("div",{style:{flex:"1 1 0%",minWidth:0},children:a?M.jsx(dX,{value:k.valueExpression??"",language:"feel",readOnly:n,singleLine:!0,placeholderText:"e.g. command.details.length",onChange:L=>m(O,D=>({...D,valueExpression:L,runtimeWritten:L.trim().length>0})),extensions:S,root:void 0}):M.jsx("span",{style:{fontFamily:"var(--mu-font-mono)",fontSize:"var(--mu-text-xs)"},children:k.valueExpression??"—"})}):null]})]},`output-custom-${O}`))})}),d.length>0?M.jsx(PCe,{title:"Auto-Generated Results",count:d.length,defaultExpanded:!1,children:M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,padding:"4px 0"},children:d.map((k,O)=>M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",fontSize:12},children:[M.jsx("button",{type:"button",style:{...wL,flex:1,textAlign:"left"},onClick:()=>r(k.path),disabled:n,children:k.path}),M.jsx(pM,{dataType:k.dataType})]},`output-auto-${O}`))})}):null,i.length?M.jsx(BCe,{issues:i.filter(k=>k.severity!=="info")}):null]})}function FCe({fields:s,readOnly:e,onInsert:t}){return M.jsx("div",{style:wX,children:M.jsxs("table",{style:CX,children:[M.jsx("thead",{children:M.jsxs("tr",{children:[M.jsx("th",{style:gg,children:"Path"}),M.jsx("th",{style:{...gg,width:"15%"},children:"Type"}),M.jsx("th",{style:gg,children:"Description"})]})}),M.jsx("tbody",{children:s.map(i=>M.jsxs("tr",{children:[M.jsx("td",{style:pg,children:M.jsx("button",{type:"button",style:wL,onClick:()=>t(i.path),disabled:e,children:i.path})}),M.jsx("td",{style:pg,children:M.jsx(pM,{dataType:i.dataType})}),M.jsx("td",{style:pg,title:i.description??i.label,children:i.description??i.label})]},`${i.sourceNodeId??"scope"}:${i.path}`))})]})})}const Gtt=M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-error)",style:{flexShrink:0,marginTop:1},children:M.jsx("path",{d:"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zm2.97 4.03a.75.75 0 0 1 0 1.06L9.06 8l1.91 1.91a.75.75 0 1 1-1.06 1.06L8 9.06l-1.91 1.91a.75.75 0 1 1-1.06-1.06L6.94 8 5.03 6.09a.75.75 0 0 1 1.06-1.06L8 6.94l1.91-1.91a.75.75 0 0 1 1.06 0z"})}),Ktt=M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-warning)",style:{flexShrink:0,marginTop:1},children:M.jsx("path",{d:"M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"})});function BCe({issues:s}){return M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.map(e=>{const t=e.severity==="error";return M.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,padding:"8px 10px",borderRadius:8,borderLeft:t?"3px solid var(--mu-color-error)":"3px solid var(--mu-color-warning)",background:t?"var(--mu-color-error-bg)":"var(--mu-color-warning-bg)",fontSize:"var(--mu-text-sm)"},children:[t?Gtt:Ktt,M.jsxs("span",{style:{color:t?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",lineHeight:"20px"},children:[M.jsx("strong",{children:e.code})," ",e.message,e.fieldPath?M.jsxs("span",{style:{opacity:.7,marginLeft:4},children:["(",e.fieldPath,")"]}):null]})]},`${e.code}:${e.message}:${e.fieldPath??""}`)})})}const vv={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-text-muted)"},Ztt={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",padding:"var(--mu-space-md)",width:"100%",minWidth:0,borderRadius:18,background:"var(--mu-surface-sidebar)",border:"1px solid var(--mu-border-subtle)"},Xtt={display:"flex",flexWrap:"nowrap",overflowX:"auto",gap:0,paddingBottom:0,borderBottom:"1px solid var(--mu-border-subtle)",marginBottom:"var(--mu-space-xs)"},bd={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-medium)",color:"var(--mu-text-label)"},Jl={borderRadius:8,border:"1px solid var(--mu-border-input)",padding:"var(--mu-space-xs) var(--mu-space-sm)",fontSize:"var(--mu-text-xs)",width:"100%"},yX={...Jl,minHeight:116,resize:"vertical"},wX={borderRadius:12,border:"1px solid var(--mu-border-subtle)",overflow:"hidden",overflowY:"auto",flex:"1 1 auto",minHeight:120,maxHeight:"50vh",minWidth:0,background:"var(--mu-surface-base)"},CX={width:"100%",tableLayout:"fixed",borderCollapse:"collapse",fontSize:12},gg={position:"sticky",top:0,background:"var(--mu-surface-raised)",textAlign:"left",padding:"var(--mu-space-xs) var(--mu-space-xs)",fontSize:"var(--mu-text-xs)",color:"var(--mu-text-secondary)",borderBottom:"1px solid var(--mu-border-subtle)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},pg={padding:"8px 6px",fontSize:12,color:"var(--mu-text-primary)",borderBottom:"1px solid var(--mu-border-subtle)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",verticalAlign:"middle"},wL={border:"none",background:"transparent",color:"var(--mu-color-interactive)",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,textAlign:"left"},Ytt={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"var(--mu-space-sm)"},Jtt={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",overflowY:"auto",maxHeight:"50vh",minHeight:80},eit={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",padding:"var(--mu-space-sm)",borderRadius:10,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-base)"},$Ce={display:"flex",alignItems:"center",gap:"var(--mu-space-xs)",minWidth:0},tit={fontSize:"var(--mu-text-xs)",padding:"2px 4px",borderRadius:6,border:"1px solid var(--mu-border-input)",background:"var(--mu-surface-raised)",cursor:"pointer",flexShrink:0},iit={borderRadius:12,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"12px 14px",fontWeight:600},uS={display:"flex",flexDirection:"column",gap:4,padding:12,borderRadius:14,background:"var(--mu-surface-raised)",color:"var(--mu-text-secondary)",fontSize:12,lineHeight:1.5},nit={borderRadius:12,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"10px 12px",fontSize:12},sit={borderRadius:12,border:"1px solid var(--mu-color-warning-border)",background:"var(--mu-color-warning-bg)",color:"var(--mu-color-warning-text)",padding:"10px 12px",fontSize:12},rit={borderRadius:14,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-base)",padding:12,display:"flex",flexDirection:"column",gap:8,fontSize:12,color:"var(--mu-text-label)"},SX={borderRadius:999,padding:"4px 8px",background:"var(--mu-color-interactive-subtle)",color:"var(--mu-text-primary)",fontSize:11,fontWeight:600},oit={...SX,border:"none",cursor:"pointer"},ait={margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:12};function lit(s,e,t){const i=Oc(e),n=new Map(i.map(o=>[o.path,o.example??`<${o.path}>`])),r=s.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*\}\}/g,(o,a)=>String(n.get(a)??`<${a}>`));return r}function uh(s){return{borderRadius:12,border:s?"1px solid var(--mu-color-interactive-border)":"1px solid var(--mu-border-input)",background:s?"var(--mu-color-interactive-subtle)":"var(--mu-surface-raised)",color:"var(--mu-text-primary)",padding:"10px 12px",fontWeight:600,minHeight:44}}function cit(s){return{borderRadius:0,border:"none",borderBottom:s?"2px solid var(--mu-color-interactive)":"2px solid transparent",background:"transparent",color:s?"var(--mu-color-interactive)":"var(--mu-text-muted)",fontWeight:s?600:400,fontSize:"var(--mu-text-sm)",padding:"var(--mu-space-xs) var(--mu-space-sm)",cursor:"pointer",whiteSpace:"nowrap",transition:"border-color 0.15s, color 0.15s",outline:"none",minHeight:44}}function dit({groups:s,loading:e,readOnly:t,onAddRule:i,onDragStart:n}){const[r,o]=ve.useState(""),a=r.trim().toLowerCase(),l=ve.useMemo(()=>[...s].sort((d,u)=>(d.category??"").localeCompare(u.category??"")).map(d=>({...d,items:[...d.items].filter(u=>hit(u,a)).sort((u,f)=>(u.displayName??"").localeCompare(f.displayName??""))})).filter(d=>d.items.length>0),[s,a]);return M.jsxs("div",{style:fit,children:[M.jsxs("div",{style:git,children:[M.jsx("strong",{children:"Rule Catalog"}),M.jsx("span",{children:"Load reusable rule templates from the control plane and drop them into the flow."})]}),M.jsxs("label",{style:pit,children:["Search rules",M.jsx("input",{"data-testid":"catalog-search-input",style:mit,value:r,onChange:c=>o(c.target.value),placeholder:"Search by name, code, tag or description",disabled:e})]}),e?M.jsx("div",{"data-testid":"catalog-loading-state",style:WCe,children:"Loading rule catalog..."}):null,!e&&l.length===0?M.jsx("div",{"data-testid":"catalog-empty-state",style:WCe,children:a?"No rules match the current search.":"No rules available."}):null,e?null:l.map(c=>M.jsxs("div",{"data-testid":`catalog-group-${c.category}`,style:_it,children:[M.jsx("span",{style:bit,title:c.category,children:uit(c.category)}),c.items.map(d=>M.jsx("button",{type:"button",style:vit,"data-testid":`palette-rule-${d.code}`,draggable:!t,onClick:()=>i(d),onDragStart:u=>n(u,d),disabled:t,children:M.jsxs("span",{style:yit,children:[M.jsx("strong",{children:d.displayName}),M.jsx("span",{style:wit,children:d.code}),d.description?M.jsx("span",{style:Cit,children:d.description}):null,d.tags.length>0?M.jsx("span",{style:Sit,children:d.tags.join(" · ")}):null]})},d.code))]},c.category))]})}function uit(s){const e=s.split(".");return e.length<=2?s:e.slice(-2).join(".")}function hit(s,e){return e?[s.code,s.displayName,s.description??"",...s.tags??[]].join(" ").toLowerCase().includes(e):!0}const fit={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},git={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-color-text-muted)"},pit={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-xs)",color:"var(--mu-color-text-secondary)",fontWeight:600},mit={borderRadius:12,border:"1px solid rgba(148, 163, 184, 0.32)",background:"var(--mu-color-surface-base)",color:"var(--mu-color-text-primary)",minHeight:40,padding:"10px 12px",fontSize:13},WCe={borderRadius:14,border:"1px dashed rgba(148, 163, 184, 0.35)",background:"rgba(248, 250, 252, 0.9)",color:"var(--mu-color-text-muted)",padding:"12px 14px",fontSize:13,lineHeight:1.5},_it={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},bit={fontSize:12,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--mu-color-text-secondary)"},vit={borderRadius:14,border:"1px solid color-mix(in oklch, var(--mu-color-interactive) 14%, transparent)",background:"color-mix(in oklch, var(--mu-color-interactive) 8%, transparent)",color:"var(--mu-color-text-primary)",padding:"11px 12px",textAlign:"left",fontWeight:600},yit={display:"flex",flexDirection:"column",gap:4},wit={fontSize:"var(--mu-text-xs)",fontFamily:"var(--mu-font-mono)",fontWeight:500,color:"var(--mu-color-text-secondary)"},Cit={fontSize:12,fontWeight:500,color:"var(--mu-color-text-muted)"},Sit={fontSize:"var(--mu-text-xs)",color:"var(--mu-color-interactive)"},xit={canvasGradient:"radial-gradient(circle at top left, color-mix(in oklch, var(--mu-color-interactive) 12%, transparent), transparent 38%), linear-gradient(180deg, var(--mu-surface-canvas), var(--mu-surface-base))",sidebarBg:"var(--mu-surface-sidebar)",sidebarBorder:"1px solid var(--mu-border-subtle)",sidebarOpenBg:"var(--mu-surface-raised)",sidebarOpenBorder:"1px solid var(--mu-border-default)",sidebarOpenShadow:"var(--mu-shadow-sidebar)",sidebarHeaderColor:"var(--mu-text-primary)",nodeBg:"var(--mu-surface-base)",nodeBorder:"1px solid var(--mu-border-subtle)",nodeShadow:"var(--mu-shadow-node)",nodeText:"var(--mu-text-primary)",nodeSubtext:"var(--mu-text-secondary)",nodeMutedText:"var(--mu-text-muted)",inspectorBg:"var(--mu-surface-sidebar)",inspectorBorder:"1px solid var(--mu-border-subtle)",inputBg:"var(--mu-surface-input)",inputBorder:"1px solid var(--mu-border-input)",inputText:"var(--mu-text-primary)",labelColor:"var(--mu-text-label)",overlayBg:"var(--mu-surface-overlay)",overlayBorder:"1px solid var(--mu-border-default)",overlayShadow:"var(--mu-shadow-overlay)",overlayItemBg:"var(--mu-surface-raised)",overlayItemBorder:"1px solid var(--mu-border-subtle)",overlayItemSelectedBg:"var(--mu-color-selected-bg)",overlayItemSelectedBorder:"1px solid var(--mu-color-selected-border)",backdropBg:"var(--mu-surface-backdrop)",dialogBg:"var(--mu-surface-dialog)",dialogBorder:"1px solid var(--mu-border-default)",dialogShadow:"var(--mu-shadow-dialog)",textPrimary:"var(--mu-text-primary)",textSecondary:"var(--mu-text-secondary)",textMuted:"var(--mu-text-muted)",paletteBtnBorderAlpha:"22",paletteBtnBgAlpha:"10",chevronBg:"var(--mu-border-subtle)",chevronColor:"var(--mu-text-secondary)",sectionDescColor:"var(--mu-text-muted)",hintBg:"var(--mu-surface-raised)",hintBorder:"1px solid var(--mu-border-subtle)",hintText:"var(--mu-text-label)",errorBg:"var(--mu-color-error-bg)",errorBorder:"1px solid var(--mu-color-error-border)",errorText:"var(--mu-color-error-text)",warningBg:"var(--mu-color-warning-bg)",warningBorder:"1px solid var(--mu-color-warning-border)",warningText:"var(--mu-color-warning-text)",deleteBg:"var(--mu-color-error-bg)",deleteBorder:"1px solid var(--mu-color-error-border)",deleteText:"var(--mu-color-error-text)",actionPrimaryBorder:"1px solid var(--mu-color-interactive-border)",actionPrimaryBg:"var(--mu-color-interactive-subtle)",actionSecondaryBorder:"1px solid var(--mu-border-input)",actionSecondaryBg:"var(--mu-surface-raised)",validationErrorBg:"var(--mu-color-error-bg)",validationErrorBorder:"1px solid var(--mu-color-error-border)",validationErrorText:"var(--mu-color-error-text)",validationWarnBg:"var(--mu-color-warning-bg)",validationWarnBorder:"1px solid var(--mu-color-warning-border)",validationWarnText:"var(--mu-color-warning-text)",licenseBg:"var(--mu-color-warning-bg)",licenseBorder:"1px solid var(--mu-color-warning-border)",licenseText:"var(--mu-color-warning-text)",edgeLabelBg:"var(--mu-edge-label-bg)"};function xX(s){return xit}const kX={trigger:"M6 2.5v11l5.5-5.5z",condition:"M8 1L15 8 8 15 1 8zm0 2.83L3.83 8 8 12.17 12.17 8z",action:"M7 2v5H2v2h5v5h2V9h5V7H9V2z","decision-table":"M2 3h12v1.5H2zm0 3.5h12V8H2zm0 3.5h12V11.5H2zm0 3.5h12V15H2z","sub-flow":"M3 3h4v4H3zm6 0h4v4H9zM5 7v2h6V7M8 9v3M5 12h6",liquid:"M8 1C5.8 5.3 3 7.4 3 10.5 3 13 5.2 15 8 15s5-2 5-4.5C13 7.4 10.2 5.3 8 1z",connector:"M2 4h4v3H2zm8 0h4v3h-4zM4 7v2h1v1H4v2h2v-2h1V9h2v2h1v2h2v-2h-1V9H9.5V7m-5 0",end:"M8 2a6 6 0 100 12A6 6 0 008 2zm0 3a3 3 0 110 6 3 3 0 010-6z"},kit={trigger:"Entry point for the rule flow",condition:"Evaluate a rule with pass/fail routing",action:"Execute side effects or transformations","decision-table":"Evaluate a FEEL decision table","sub-flow":"Delegate to another rule flow",liquid:"Transform data with Liquid templates",connector:"Integrate with external services via connectors",end:"Terminal node — flow completes here"},HCe={always:"var(--mu-edge-always)","on-true":"var(--mu-edge-on-true)","on-false":"var(--mu-edge-on-false)","on-error":"var(--mu-edge-on-error)"},Oit=HCe;function VCe(s,e){const t=Cl(s),i=Eit(t,e);return{...t,nodes:t.nodes.map(n=>{var r,o,a,l;return{...n,data:{...n.data,contractLayer:i.get(n.id),dependsOn:n.data.dependsOn??((o=(r=e.nodeContractsById)==null?void 0:r.get(n.id))==null?void 0:o.dependsOn)??[],order:n.data.order??((l=(a=e.nodeContractsById)==null?void 0:a.get(n.id))==null?void 0:l.order)}}})}}function OX(s,e){const t=CL(s,e),i=VCe(t.graph,e),n=i.nodes.flatMap(r=>{var o;return((o=r.data.contractLayer)==null?void 0:o.validationIssues)??[]});return{graph:i,issues:[...t.issues,...n],isValid:t.isValid&&n.every(r=>r.severity!=="error")}}function CL(s,e){var p,m;const t=Cl(s),i=t.nodes.filter(b=>b.type!=="trigger"&&b.type!=="end"),n=new Set(i.map(b=>b.id)),r=new Map(i.filter(b=>b.ruleCode).map(b=>[b.ruleCode,b.id])),o=new Map,a=new Map,l=b=>{o.has(b)||o.set(b,new Set),a.has(b)||a.set(b,0)},c=(b,w)=>{if(b===w||!n.has(b)||!n.has(w))return;l(b),l(w);const S=o.get(b);S.has(w)||(S.add(w),a.set(w,(a.get(w)??0)+1))};for(const b of i){l(b.id);const w=b.data.dependsOn??((m=(p=e.nodeContractsById)==null?void 0:p.get(b.id))==null?void 0:m.dependsOn)??[];for(const S of w){const k=r.get(S);k&&c(k,b.id)}}for(const b of t.edges)b.edgeType!=="on-error"&&c(b.source,b.target);const d=[...i].sort((b,w)=>{var O,L,D,R;const S=b.data.order??((L=(O=e.nodeContractsById)==null?void 0:O.get(b.id))==null?void 0:L.order)??Number.MAX_SAFE_INTEGER,k=w.data.order??((R=(D=e.nodeContractsById)==null?void 0:D.get(w.id))==null?void 0:R.order)??Number.MAX_SAFE_INTEGER;return S!==k?S-k:(b.label??"").localeCompare(w.label??"")}).filter(b=>(a.get(b.id)??0)===0).map(b=>b.id),u=[];for(;d.length>0;){const b=d.shift();u.push(b);const w=[...o.get(b)??[]].sort((S,k)=>S.localeCompare(k));for(const S of w){const k=(a.get(S)??0)-1;a.set(S,k),k===0&&d.push(S)}}if(u.length!==i.length)return{graph:t,issues:[{code:"MRF008",severity:"error",message:"Rule flow contains a dependency cycle or invalid ordering edge."}],isValid:!1};const f=new Map(u.map((b,w)=>[b,w+1]));return{graph:{...t,nodes:t.nodes.map(b=>{var w,S;return n.has(b.id)?{...b,data:{...b.data,order:f.get(b.id)??b.data.order,dependsOn:b.data.dependsOn??((S=(w=e.nodeContractsById)==null?void 0:w.get(b.id))==null?void 0:S.dependsOn)??[]}}:b})},issues:[],isValid:!0}}function Eit(s,e){const t=new Map(s.nodes.map(b=>[b.id,b])),i=new Map;for(const b of s.edges){const w=i.get(b.target)??[];w.push(b),i.set(b.target,w)}const n=new Map,r=new Set,o=b=>b.type,a=Lit(s,e),l=(b,w)=>{var R,A;const S=t.get(b);if(!S)return[];const k=m(S),O=Qw(((R=k.upstreamScope)==null?void 0:R.fields)??[]),L=Qw(((A=k.outputContract)==null?void 0:A.fields)??[]);if(o(S)!=="condition")return yv([...O,...UCe(L)]);const D=w==="on-false"?L.filter(F=>F.isResultPayload):L;return yv([...O,...UCe(D)])},c=b=>{var O,L,D,R;const w=b.data.dependsOn??((L=(O=e.nodeContractsById)==null?void 0:O.get(b.id))==null?void 0:L.dependsOn)??[];if(w.length>0){const A=s.nodes.filter(F=>F.ruleCode&&w.includes(F.ruleCode));return yv(A.flatMap(F=>l(F.id,"always")))}const S=b.data.order??((R=(D=e.nodeContractsById)==null?void 0:D.get(b.id))==null?void 0:R.order)??Number.MAX_SAFE_INTEGER,k=s.nodes.filter(A=>{var $,Y;const F=A.data.order??((Y=($=e.nodeContractsById)==null?void 0:$.get(A.id))==null?void 0:Y.order)??Number.MAX_SAFE_INTEGER;return A.id!==b.id&&F<S});return yv(k.flatMap(A=>l(A.id,"always")))},d=b=>{if(b.type==="trigger")return{contractName:`${e.flowCode??"flow"}_trigger_input`,title:"Input Scope",fields:a.map(k=>qw(k,{sourceKind:"flow-input"}))};const w=i.get(b.id)??[],S=w.length>0?w.flatMap(k=>l(k.source,k.edgeType)):c(b);return S.length===0&&S.push(...a.map(k=>qw(k,{sourceKind:"flow-input"}))),{contractName:`${b.ruleCode??b.id}_input_scope`,title:"Input Scope",fields:yv(S)}},u=(b,w)=>{var j,G,V,J,re,le;const S=(j=e.nodeContractsById)==null?void 0:j.get(b.id),k=b.type==="sub-flow"?(G=e.flowContractsByCode)==null?void 0:G.get(Tp(b.data.subFlowConfig).targetFlowCode??""):void 0,O=((V=b.data.contractOverride)==null?void 0:V.responseFields)??[],L=((J=k==null?void 0:k.responseContract)==null?void 0:J.fields)??((re=b.data.responseContract)==null?void 0:re.fields)??((le=S==null?void 0:S.responseDelta)==null?void 0:le.fields)??[],R=(Array.isArray(b.data.outputFields)?b.data.outputFields:[]).map(ie=>({path:ie.path,label:ie.path,dataType:ie.dataType??"string",valueExpression:ie.valueExpression})),A=yv([...Qw(L),...R]),F=O.length>0?Dit(A,O):A,Y=(b.type==="condition"&&!b.ruleCode?F.filter(ie=>{var oe;return ie.runtimeWritten||((oe=ie.valueExpression)==null?void 0:oe.trim())}):F).map(ie=>{var oe;return qw(ie,{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:b.type==="sub-flow"?"sub-flow-output":"node-output",runtimeWritten:b.ruleCode?!0:b.type==="condition"?!!(ie.runtimeWritten??((oe=ie.valueExpression)==null?void 0:oe.trim())):ie.runtimeWritten??!0})});if(b.type==="trigger"){const ie=a.map(oe=>qw(oe,{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"flow-input",runtimeWritten:!0}));return{contractName:`${b.id}_output_contract`,title:"Output Contract",fields:yv(ie)}}if(b.type!=="condition")return{contractName:`${b.ruleCode??b.id}_output_contract`,title:"Output Contract",fields:yv(Tit(b,Y))};const q=[qw({path:"result.isPass",label:"isPass",dataType:"boolean",required:!0},{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),qw({path:"result.message",label:"message",dataType:"string"},{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),qw({path:"result.errorCode",label:"errorCode",dataType:"string"},{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0})];return{contractName:`${b.ruleCode??b.id}_output_contract`,title:"Output Contract",fields:yv([...q,...Y])}},f=(b,w)=>{var D,R,A,F,$;const S=Oc(w.fields),k=b.type==="sub-flow"?Tp(b.data.subFlowConfig).inputMappings:b.data.inputMappings??[];if(b.type==="sub-flow"){const Y=Tp(b.data.subFlowConfig).childTriggerSchema,q=Oc((Y==null?void 0:Y.fields)??[]);return{contractName:`${b.ruleCode??b.id}_effective_input`,title:"Effective Input",mode:"sub-flow",fields:q,mappings:zCe(S,q,k)}}if(b.type==="condition"||b.type==="liquid"){const Y=y_(b.data),q=(Y.language??"").toLowerCase(),j=q==="feel"||q===""?Iit(Y.body,S):[];return{contractName:`${b.ruleCode??b.id}_effective_input`,title:"Effective Input",mode:b.type==="liquid"?"expression":"auto",fields:j,mappings:j.map(G=>({id:`auto-${G.path}`,sourcePath:G.path,targetPath:G.path,targetField:G.path,sourceDataType:G.dataType,targetDataType:G.dataType,sourceNodeId:G.sourceNodeId,sourceNodeLabel:G.sourceNodeLabel,status:"mapped",required:G.required}))}}const O=Oc(((D=b.data.contractOverride)==null?void 0:D.requestFields)??((R=b.data.requestContract)==null?void 0:R.fields)??(($=(F=(A=e.nodeContractsById)==null?void 0:A.get(b.id))==null?void 0:F.requestScope)==null?void 0:$.fields)??[]),L=b.type==="end"?[]:O;return{contractName:`${b.ruleCode??b.id}_effective_input`,title:"Effective Input",mode:b.type==="decision-table"?"decision-table":b.type==="action"?"manual":"auto",fields:L,mappings:zCe(S,L,k)}},p=(b,w,S,k)=>{var D;const O=Oc(w.fields),L=[];for(const R of S.mappings){if(R.required&&!R.sourcePath.trim()){L.push({code:"MRF001",severity:"error",message:`Required input '${R.targetField??R.targetPath}' is not mapped.`,nodeId:b.id,targetPath:R.targetField??R.targetPath});continue}if(!R.sourcePath.trim())continue;if(!O.find(F=>F.path===R.sourcePath)){const F=b.type==="sub-flow"||b.type==="connector"||b.type==="decision-table";L.push({code:"MRF002",severity:F?"warning":"error",message:F?`Source field '${R.sourcePath}' is not in upstream scope (may be resolved from FactBag at runtime).`:`Source field '${R.sourcePath}' is not available in upstream scope.`,nodeId:b.id,sourcePath:R.sourcePath,targetPath:R.targetField??R.targetPath});continue}R.targetDataType&&R.sourceDataType&&R.targetDataType!==R.sourceDataType&&!(R.transform??"").trim()&&L.push({code:"MRF003",severity:"warning",message:`Mapping '${R.sourcePath}' -> '${R.targetField??R.targetPath}' has type mismatch (${R.sourceDataType} -> ${R.targetDataType}).`,nodeId:b.id,sourcePath:R.sourcePath,targetPath:R.targetField??R.targetPath})}if(b.type==="sub-flow"){const R=Tp(b.data.subFlowConfig).childTriggerSchema;for(const A of Oc((R==null?void 0:R.fields)??[]).filter(F=>F.required))S.mappings.some($=>($.targetField??$.targetPath)===A.path&&$.sourcePath.trim().length>0)||L.push({code:"MRF004",severity:"error",message:`Sub-flow input '${A.path}' is required but not mapped.`,nodeId:b.id,fieldPath:A.path})}if(b.type==="condition"||b.type==="liquid"){const R=y_(b.data),A=R.body,F=(R.language??"").toLowerCase();if(F==="feel"||F===""){const Y=Rit(A),q=jCe(A);for(const j of q){const G=j.split(".")[0];Y.has(G)||G.startsWith("__graph")||Nit.has(G)||O.some(V=>V.path===j||j.startsWith(V.path+"."))||L.push({code:"MRF005",severity:"error",message:`Expression references '${j}' but that field is not available in input scope.`,nodeId:b.id,fieldPath:j})}}}if(b.type==="condition"&&!b.ruleCode)for(const R of Oc(k.fields).filter(A=>!A.isResultPayload&&!A.runtimeWritten))(D=R.valueExpression)!=null&&D.trim()||L.push({code:"MRF009",severity:"warning",message:`Condition output '${R.path}' is metadata-only until a Value Expression is configured.`,nodeId:b.id,fieldPath:R.path});return b.type==="end"&&k.fields.length>0&&L.push({code:"MRF006",severity:"warning",message:"End nodes should not define additional output fields.",nodeId:b.id}),L},m=b=>{const w=n.get(b.id);if(w)return w;if(r.has(b.id))return{upstreamScope:{contractName:`${b.id}_input_scope`,title:"Input Scope",fields:[]},effectiveInput:{contractName:`${b.id}_effective_input`,title:"Effective Input",fields:[],mappings:[]},outputContract:{contractName:`${b.id}_output_contract`,title:"Output Contract",fields:[]},validationIssues:[{code:"MRF007",severity:"error",message:"Cycle detected in rule flow graph.",nodeId:b.id}]};r.add(b.id);const S=d(b),k=f(b,S),O=u(b),L=p(b,S,k,O),D={upstreamScope:S,effectiveInput:k,outputContract:O,validationIssues:L};return n.set(b.id,D),r.delete(b.id),D};for(const b of s.nodes)m(b);return n}function Lit(s,e){var o,a,l,c,d;const t=Qw(((a=(o=e.currentFlowContract)==null?void 0:o.requestContract)==null?void 0:a.fields)??[]);if(t.length>0)return t;const i=[...s.nodes].filter(u=>u.type!=="trigger"&&u.type!=="end").sort((u,f)=>{var b,w,S,k;const p=u.data.order??((w=(b=e.nodeContractsById)==null?void 0:b.get(u.id))==null?void 0:w.order)??Number.MAX_SAFE_INTEGER,m=f.data.order??((k=(S=e.nodeContractsById)==null?void 0:S.get(f.id))==null?void 0:k.order)??Number.MAX_SAFE_INTEGER;return p!==m?p-m:(u.label??"").localeCompare(f.label??"")})[0];if(!i)return[];const n=(l=e.nodeContractsById)==null?void 0:l.get(i.id),r=((c=n==null?void 0:n.requestScope)==null?void 0:c.fields)??((d=i.data.requestContract)==null?void 0:d.fields)??[];return Qw(r)}function zCe(s,e,t){const i=new Map;for(const n of t){const r=s.find(a=>a.path===n.sourcePath),o=e.find(a=>a.path===n.targetPath);i.set(n.id,{...n,targetField:(o==null?void 0:o.path)??n.targetPath,sourceDataType:r==null?void 0:r.dataType,targetDataType:o==null?void 0:o.dataType,sourceNodeId:r==null?void 0:r.sourceNodeId,sourceNodeLabel:r==null?void 0:r.sourceNodeLabel,required:o==null?void 0:o.required,status:r?o!=null&&o.dataType&&r.dataType!==o.dataType&&!(n.transform??"").trim()?"type-mismatch":"mapped":"missing"})}for(const n of e){if([...i.values()].find(a=>(a.targetField??a.targetPath)===n.path))continue;const o=s.find(a=>a.path===n.path)??s.find(a=>qCe(a.path)===qCe(n.path)&&a.dataType===n.dataType);i.set(`suggested-${n.path}`,{id:`suggested-${n.path}`,sourcePath:(o==null?void 0:o.path)??"",targetPath:n.path,targetField:n.path,sourceDataType:o==null?void 0:o.dataType,targetDataType:n.dataType,sourceNodeId:o==null?void 0:o.sourceNodeId,sourceNodeLabel:o==null?void 0:o.sourceNodeLabel,required:n.required,status:o?"suggested":n.required?"missing":"suggested",transformSuggestion:o&&o.dataType!==n.dataType?`to_${n.dataType}(${o.path})`:void 0})}return[...i.values()]}function Tit(s,e){if(s.type!=="sub-flow")return e;const t=Tp(s.data.subFlowConfig).outputMappings;return t.length===0?e:e.map(i=>{const n=t.find(r=>r.sourcePath===i.path&&r.targetPath.trim().length>0);return n?{...i,path:n.targetPath,label:n.targetPath,exposeToParent:i.exposeToParent}:i})}function qw(s,e){var t;return{...s,...e,children:(t=s.children)==null?void 0:t.map(i=>qw(i,e))}}function yv(s){const e=new Map;for(const t of s)e.has(t.path)||e.set(t.path,t);return[...e.values()].sort((t,i)=>(t.path??"").localeCompare(i.path??""))}function Qw(s){return s.map(e=>({...e,children:e.children?Qw(e.children):void 0}))}function Dit(s,e){const t=new Map;for(const i of s)t.set(i.path,{...i,children:i.children?Qw(i.children):void 0});for(const i of e)t.set(i.path,{...i,children:i.children?Qw(i.children):void 0});return[...t.values()]}function UCe(s){return s.filter(e=>e.exposeToParent!==!1)}function Iit(s,e){const t=new Set(jCe(s));return e.filter(i=>t.has(i.path))}function jCe(s){if(!s.trim())return[];const e=new Set,t=/\b[a-zA-Z_][a-zA-Z0-9_.]*\b/g;let i=t.exec(s);for(;i;){const r=i[0];r.includes(".")&&e.add(r),i=t.exec(s)}const n=/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)/g;for(i=n.exec(s);i;)e.add(i[1]),i=n.exec(s);return[...e]}function qCe(s){const e=s.split(".");return e[e.length-1]??s}function Rit(s){const e=new Set,t=[/\bfor\s+([a-zA-Z_]\w*)\s+in\b/g,/\bevery\s+([a-zA-Z_]\w*)\s+in\b/g,/\bsome\s+([a-zA-Z_]\w*)\s+in\b/g];for(const i of t){let n=i.exec(s);for(;n;)e.add(n[1]),n=i.exec(s)}return e}const Nit=new Set(["string","number","date","time","duration","list","context","math","Math","Date","JSON","RegExp","Object","Array","console","forloop","now","true","false","null"]),EX="application/muonroi-rule-flow-node-type",QCe="application/muonroi-rule-flow-rule-template",GCe={duration:0,padding:.22,minZoom:.18,maxZoom:1.1},KCe=860,LX={always:"→ Always","on-true":"✓ On Pass","on-false":"✗ On Fail","on-error":"⚠ On Error"},Ait={always:"Always continue to the next node when the source node executed.","on-true":"Continue only when the source node passed.","on-false":"Continue only when the source node failed without throwing.","on-error":"Continue only when the source node threw an exception."},Mit={always:{bg:"oklch(82% 0.01 255)",text:"oklch(35% 0.02 255)"},"on-true":{bg:"oklch(82% 0.08 150)",text:"oklch(30% 0.10 150)"},"on-false":{bg:"oklch(82% 0.08 25)",text:"oklch(35% 0.14 25)"},"on-error":{bg:"oklch(85% 0.06 75)",text:"oklch(38% 0.12 70)"}},Pit={always:{bg:"oklch(38% 0.01 255)",text:"oklch(82% 0.01 255)"},"on-true":{bg:"oklch(35% 0.06 150)",text:"oklch(80% 0.08 150)"},"on-false":{bg:"oklch(35% 0.06 25)",text:"oklch(80% 0.08 25)"},"on-error":{bg:"oklch(38% 0.05 75)",text:"oklch(82% 0.06 70)"}};function Fit(s){var e,t,i,n,r;if(s.nodeType==="condition"&&((e=s.conditionConfig)!=null&&e.successLabel))return`Pass: ${s.conditionConfig.successLabel} / Fail: ${s.conditionConfig.failureLabel??"—"}`;if(s.nodeType==="action")return"Execute side-effect";if(s.nodeType==="decision-table")return(t=s.contractRef)!=null&&t.sourceCode?`Table: ${s.contractRef.sourceCode}`:"Decision table lookup";if(s.nodeType==="connector"){const o=(i=s.connectorConfig)==null?void 0:i.connectorType;return o?`Connector: ${o}`:"External service call"}return s.nodeType==="sub-flow"?(n=s.subFlowConfig)!=null&&n.targetFlowCode?`Flow: ${s.subFlowConfig.targetFlowCode}`:"Delegate to sub-flow":s.nodeType==="liquid"?`Liquid → ${((r=s.liquidConfig)==null?void 0:r.outputFormat)??"json"}`:null}function Bit({politeMessage:s,assertiveMessage:e}){const t={position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};return M.jsxs(M.Fragment,{children:[M.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:t,children:s}),M.jsx("div",{role:"alert","aria-live":"assertive","aria-atomic":"true",style:t,children:e})]})}function Gw({data:s,selected:e}){var c,d,u;const t=hM[s.nodeType],i=xX(s._theme??"light"),n=y_(s),r=((c=s.requestContract)==null?void 0:c.fields.length)??0,o=((d=s.responseContract)==null?void 0:d.fields.length)??0,a=kX[s.nodeType],l=Fit(s);return M.jsxs("div",{style:{...Met,background:i.nodeBg,boxShadow:i.nodeShadow,borderTop:e?`2px solid ${t}`:i.nodeBorder,borderRight:e?`2px solid ${t}`:i.nodeBorder,borderBottom:e?`2px solid ${t}`:i.nodeBorder,borderLeft:`8px solid ${t}`,borderRadius:s.nodeType==="end"?999:s.nodeType==="condition"?24:18},"aria-label":`${_L[s.nodeType]} node: ${s.label}`,children:[M.jsx(KE,{type:"target",position:dn.Left}),M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:t,style:{flexShrink:0},children:M.jsx("path",{d:a})}),M.jsx("span",{style:{color:t,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase"},children:_L[s.nodeType]})]}),M.jsx("strong",{style:{fontSize:14,color:i.nodeText},children:s.label}),l?M.jsx("span",{style:{fontSize:11,color:i.nodeMutedText,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l}):null,s.ruleCode?M.jsxs("span",{style:{fontSize:12,color:i.nodeSubtext},children:["Rule: ",s.ruleCode]}):null,(u=s.contractRef)!=null&&u.sourceCode?M.jsxs("span",{style:{fontSize:11,color:i.nodeMutedText},children:["Contract: ",s.contractRef.sourceType,"/",s.contractRef.sourceCode]}):null,n.body?M.jsxs("span",{style:{display:"inline-block",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,color:i.nodeSubtext},children:[n.language.toUpperCase(),": ",n.body]}):null,r>0||o>0?M.jsxs("span",{style:{fontSize:11,color:i.nodeMutedText},children:["Inline contracts ",r,"/",o]}):null]}),M.jsx(KE,{type:"source",position:dn.Right})]})}const TX={trigger:Gw,condition:Gw,action:Gw,"decision-table":Gw,"sub-flow":Gw,liquid:Gw,connector:Gw,end:Gw};function Kw({path:s}){const e=Array.isArray(s)?s:[s];return M.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:e.map((t,i)=>M.jsx("path",{d:t},i))})}function $it({onAddTrigger:s}){return M.jsx("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"var(--mu-space-md)",pointerEvents:"none",zIndex:5},children:M.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"var(--mu-space-sm)",padding:"var(--mu-space-lg) var(--mu-space-xl)",background:"var(--mu-surface-overlay)",border:"1px solid var(--mu-border-subtle)",borderRadius:18,boxShadow:"var(--mu-shadow-node)",pointerEvents:"auto",maxWidth:320,textAlign:"center"},children:[M.jsxs("svg",{width:32,height:32,viewBox:"0 0 16 16",fill:"var(--mu-color-interactive)",opacity:.7,children:[M.jsx("path",{d:"M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"}),M.jsx("path",{d:"M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"})]}),M.jsx("strong",{style:{fontSize:"var(--mu-text-md)",color:"var(--mu-text-primary)"},children:"Start your workflow"}),M.jsx("span",{style:{fontSize:"var(--mu-text-sm)",color:"var(--mu-text-muted)",lineHeight:"20px"},children:"Drop a trigger node to begin, or click the button below to add one automatically."}),M.jsx("button",{type:"button",onClick:s,style:{padding:"var(--mu-space-xs) var(--mu-space-md)",borderRadius:8,border:"1px solid var(--mu-color-interactive-border)",background:"var(--mu-color-interactive)",color:"var(--mu-text-on-accent)",fontSize:"var(--mu-text-sm)",fontWeight:600,cursor:"pointer",marginTop:"var(--mu-space-xs)"},children:"Add Trigger Node"})]})})}function Wit({nodeIds:s,syncToken:e,hostElement:t}){const i=Fqe(),n=kA(),r=$qe({includeHiddenNodes:!0}),o=ve.useRef(""),a=ve.useRef(null);function l(){!r||s.length===0||(s.forEach(d=>i(d)),n.fitView(GCe))}function c(d=0){return window.setTimeout(()=>{a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{a.current=null,l()})},d)}return ve.useEffect(()=>{const d=String(e);if(!r||s.length===0||o.current===d)return;o.current=d;const u=c(),f=c(150),p=c(350);return()=>{window.clearTimeout(u),window.clearTimeout(f),window.clearTimeout(p),a.current!==null&&(cancelAnimationFrame(a.current),a.current=null)}},[s,r,n,e,i]),ve.useEffect(()=>{if(!t)return;const d=new ResizeObserver(()=>{l()});d.observe(t);const u=()=>l();return window.addEventListener("resize",u),()=>{d.disconnect(),window.removeEventListener("resize",u)}},[t,r,n,i,s]),null}function Hit(){const s=kA();return ve.useEffect(()=>{function e(t){const i=t.target,n=i.tagName.toLowerCase();if(n==="input"||n==="textarea"||n==="select"||i.isContentEditable)return;const r=t.ctrlKey||t.metaKey;if(t.key==="+"||r&&t.key==="="){t.preventDefault(),s.zoomIn({duration:150});return}if(t.key==="-"||r&&t.key==="-"){t.preventDefault(),s.zoomOut({duration:150});return}if(t.key==="f"||t.key==="F"||r&&t.key==="0"){t.preventDefault(),s.fitView(GCe);return}}return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[s]),null}function ZCe({graph:s,onGraphChange:e,readOnly:t=!1,theme:i="light",height:n=640,apiBaseUrl:r,catalogApiBase:o,tenantId:a,workflowCode:l,onPublish:c,licenseStatus:d="licensed",showHeader:u=!0,version:f=null,onVersionChange:p,editorRoot:m}){var U1;const b=ve.useMemo(()=>Cl(s),[s]),w=Jet(b);function S(ne){return ne.map(_e=>({..._e,data:{..._e.data,_theme:i}}))}function k(ne){const _e=i==="dark"?Oit:HCe,st=i==="dark"?Pit:Mit;return ne.map(jt=>{var _c;const wt=((_c=jt.data)==null?void 0:_c.edgeType)??"always",Hi=_e[wt]??_e.always,Yi=st[wt]??st.always,Ds=LX[wt]??"Always";return{...jt,label:Ds,style:{stroke:Hi,strokeWidth:2},labelStyle:{fill:Yi.text,fontWeight:600,fontSize:12,letterSpacing:"0.02em"},labelBgStyle:{fill:Yi.bg},labelBgPadding:[4,8],labelBgBorderRadius:999}})}const[O,L]=ve.useState(()=>S(gM(w.present))),[D,R]=ve.useState(()=>k(bCe(w.present))),[A,F]=ve.useState(""),[$,Y]=ve.useState(""),[q,j]=ve.useState("basic-info"),[G,V]=ve.useState({status:"idle"}),[J,re]=ve.useState([]),[le,ie]=ve.useState([]),[oe,ge]=ve.useState(null),[se,pe]=ve.useState({status:"idle"}),[De,Fe]=ve.useState([]),[it,dt]=ve.useState([]),[bt,rt]=ve.useState(!1),[St,Xt]=ve.useState(null),[di,Vt]=ve.useState(""),[Yt,Bi]=ve.useState(""),$i=ve.useRef(w.present.metadata),Ei=ve.useRef(Yl(w.present)),[Yn,Sr]=ve.useState(0),tn=ve.useRef(O),Cn=ve.useRef(D),Hn=ve.useRef(new Map),Sn=ve.useRef(new Map),qs=ve.useRef(null),Ur=ve.useRef(new Map),Mn=ve.useMemo(()=>r?new Nve({baseUrl:r,tenantId:a}):null,[r,a]),ys=ve.useMemo(()=>o?new Ave({baseUrl:o,tenantId:a}):null,[o,a]),Qs=ve.useMemo(()=>r?new Mve({baseUrl:r,tenantId:a}):null,[r,a]),Bo=ve.useRef(null),vo=ve.useRef(null);ve.useRef(null);const Et=ve.useRef(!0),ni=ve.useRef(!1),Ui=ve.useRef(null),[Bn,mn]=ve.useState(0),[as,gs]=ve.useState("inspector"),[ws,Pi]=ve.useState(!1),jn=ve.useRef(null),[ns,Jo]=ve.useState(()=>{try{const ne=localStorage.getItem("muonroi-rule-studio-sidebar-width");return ne?Math.max(240,Math.min(400,Number(ne))):280}catch{return 280}}),[_n,uo]=ve.useState(()=>{try{return localStorage.getItem("muonroi-rule-studio-sidebar-collapsed")==="true"}catch{return!1}}),ea=ve.useRef(!1),[fc,Al]=ve.useState(()=>{try{const ne=localStorage.getItem("muonroi-rule-studio-toolbar-groups");return ne?JSON.parse(ne):{}}catch{return{}}}),mi=ne=>fc[ne]===!0,ae=ne=>Al(_e=>{const st={..._e,[ne]:!_e[ne]};try{localStorage.setItem("muonroi-rule-studio-toolbar-groups",JSON.stringify(st))}catch{}return st}),[de,ue]=ve.useState(!1),[Ce,ke]=ve.useState(!1),Me=ve.useRef(null),Qe=ve.useRef(null),[xt,zt]=ve.useState([]),[fe,Xe]=ve.useState(0),[vt,It]=ve.useState(!1),[ri,xi]=ve.useState(!1),Di=ve.useMemo(()=>xt.find(ne=>ne.isActive)??null,[xt]),nn=f!=null&&Di!=null&&f!==Di.version,Mt=t||nn,xe=ve.useCallback((ne,_e)=>{if(!r||!l){_e||zt([]);return}const st=r.replace(/\/$/,""),jt=fd(void 0,{tenantId:a});_e&&xi(!0),fetch(`${st}/rulesets/${encodeURIComponent(l)}/versions?limit=10&offset=${ne}`,{headers:jt}).then(wt=>wt.ok?wt.json():[]).then(wt=>{const Hi=Array.isArray(wt)?wt:Array.isArray(wt==null?void 0:wt.items)?wt.items:[];It(Hi.length===10),zt(_e?Yi=>[...Yi,...Hi].sort((Ds,_c)=>_c.version-Ds.version):Hi.sort((Yi,Ds)=>Ds.version-Yi.version))}).catch(wt=>{console.warn("[MVersionDropdown] Failed to fetch versions:",wt),_e||zt([])}).finally(()=>{_e&&xi(!1)})},[r,l,a]);ve.useEffect(()=>{Xe(0),It(!1),xe(0,!1)},[xe]);const pt=ve.useCallback(()=>{const ne=fe+10;Xe(ne),xe(ne,!0)},[fe,xe]);ve.useEffect(()=>{tn.current=O},[O]),ve.useEffect(()=>{Cn.current=D},[D]),ve.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-width",String(ns))}catch{}},[ns]),ve.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-collapsed",String(_n))}catch{}},[_n]),ve.useEffect(()=>{const ne=Me.current;if(!ne)return;const _e=new ResizeObserver(st=>{for(const jt of st){const Hi=jt.contentRect.width<KCe;ue(Hi),Hi||ke(!1)}});return _e.observe(ne),()=>_e.disconnect()},[]),ve.useEffect(()=>{if(!Ce)return;const ne=_e=>{Qe.current&&!Qe.current.contains(_e.target)&&ke(!1)};return document.addEventListener("click",ne),()=>document.removeEventListener("click",ne)},[Ce]),ve.useEffect(()=>()=>{Kc(),ba()},[]),ve.useEffect(()=>{L(ne=>S(ne)),R(ne=>k(ne))},[i]),ve.useEffect(()=>{const ne=Cl(s),_e=Yl(ne);_e!==Ei.current&&($i.current=ne.metadata,w.reset(ne),Ei.current=_e,Et.current=!0,Sr(st=>st+1),F(""),Y(""),j("basic-info"),zf(ne))},[s,w.reset]),ve.useEffect(()=>{const ne=w.present,_e=Yl(ne),st=Yl(yo(tn.current,Cn.current,!1));_e!==st&&($i.current=ne.metadata,Ei.current=_e,zf(ne))},[w.present]),ve.useEffect(()=>{const ne=_e=>{_e.target;const st=_e.composedPath().some(jt=>{if(!(jt instanceof HTMLElement))return!1;const wt=jt.tagName;return wt==="INPUT"||wt==="TEXTAREA"||wt==="SELECT"||jt.isContentEditable});if((_e.ctrlKey||_e.metaKey)&&_e.key==="z"&&!_e.shiftKey){_e.preventDefault(),Kc(),w.undo();return}if((_e.ctrlKey||_e.metaKey)&&(_e.key==="y"||_e.key==="z"&&_e.shiftKey)){_e.preventDefault(),Kc(),w.redo();return}if(_e.key==="Escape"){F(""),Y(""),j("basic-info");return}if(!(Mt||st)&&(_e.key==="Delete"||_e.key==="Backspace")){if(A){Va();return}$&&gc()}};return window.addEventListener("keydown",ne),()=>window.removeEventListener("keydown",ne)},[Mt,A,$]),ve.useEffect(()=>{const ne=Bo.current;if(!ne)return;const _e=()=>{var wt;const jt=((wt=ne.parentElement)==null?void 0:wt.getBoundingClientRect().width)??ne.getBoundingClientRect().width;mn(jt)};_e();const st=new ResizeObserver(()=>_e());return st.observe(ne),()=>st.disconnect()},[]);const[Qt,Vn]=ve.useState(0),ls=ve.useMemo(()=>yo(O,D,!1),[O,D]),Ci=ve.useMemo(()=>VCe(ls,{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}),[Qt,ls,l]),$t=ve.useMemo(()=>A?S(gM(Ci)).find(ne=>ne.id===A)??null:null,[Ci,A,i]),Mr=ve.useMemo(()=>$?D.find(ne=>ne.id===$)??null:null,[D,$]),Ml=$t?y_($t.data):{language:"feel",body:""},ur=ve.useMemo(()=>OX(ls,{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}),[Qt,ls,l]),Lo=ve.useMemo(()=>ur.issues.filter(ne=>ne.severity==="error"),[ur.issues]),$u=ve.useMemo(()=>ur.issues.filter(ne=>ne.severity==="warning"),[ur.issues]),Wd=!Mt&&!!c&&Lo.length===0,Ha=ve.useMemo(()=>jit(Ci),[Ci]);if(ve.useEffect(()=>{if(!Mn)return;let ne=!1;return(async()=>{try{const _e=await Mn.MListFlows();ne||re(_e.map(st=>({code:st.workflowName,label:st.workflowName})))}catch{}})(),()=>{ne=!0}},[Mn]),ve.useEffect(()=>{if(!Qs)return;let ne=!1;return(async()=>{try{const _e=await Qs.MListDecisionTables();if(!ne){for(const st of _e)Ur.current.set(st.id,st);ie(_e.map(st=>({code:st.id,label:st.name})))}}catch{}})(),()=>{ne=!0}},[Qs]),ve.useEffect(()=>{const ne=o?o.replace(/\/catalog\/palette\/?$/,""):r;if(!ne)return;let _e=!1;return(async()=>{try{const st=await qC.MGetCatalog(ne,fd(void 0,{tenantId:a}));_e||Fe(st)}catch{_e||Fe([])}})(),()=>{_e=!0}},[o,r]),ve.useEffect(()=>{var jt,wt,Hi;if(($t==null?void 0:$t.data.nodeType)!=="decision-table"){ge(null),pe({status:"idle"});return}if(!Qs){ge(null),pe({status:"error",message:"No decision table API configured for this editor."});return}const ne=((wt=(jt=$t.data.contractRef)==null?void 0:jt.sourceCode)==null?void 0:wt.trim())??((Hi=$t.data.ruleCode)==null?void 0:Hi.trim())??"";if(!ne){ge(null),pe({status:"idle"});return}const _e=Ur.current.get(ne);if(_e){ge(_e),pe({status:"ready"}),Hu($t.id,_e);return}let st=!1;return pe({status:"loading"}),(async()=>{try{const Yi=await Qs.MGetDecisionTable(ne);if(st)return;Ur.current.set(ne,Yi),ge(Yi),pe({status:"ready"}),Hu($t.id,Yi)}catch(Yi){st||(ge(null),pe({status:"error",message:Yi instanceof Error?Yi.message:"Failed to load decision table metadata."}))}})(),()=>{st=!0}},[Qs,$t==null?void 0:$t.id,$t==null?void 0:$t.data.nodeType,(U1=$t==null?void 0:$t.data.contractRef)==null?void 0:U1.sourceCode,$t==null?void 0:$t.data.ruleCode]),ve.useEffect(()=>{if(!ys){dt([]),rt(!1);return}let ne=!1;return(async()=>{rt(!0);try{const _e=await ys.MListCatalog();ne||(dt(_e),rt(!1))}catch{ne||(dt([]),rt(!1))}})(),()=>{ne=!0}},[ys]),ve.useEffect(()=>{if(!Mn||!l)return;let ne=!1;return(async()=>{var _e,st;await XCe(Mn,Sn.current,l);for(const jt of ls.nodes){if(jt.type==="trigger"||jt.type==="end"||Hn.current.has(jt.id))continue;const wt=await Vit(Mn,l,jt);wt&&Hn.current.set(jt.id,wt)}for(const jt of ls.nodes.filter(wt=>wt.type==="sub-flow")){const wt=(_e=Tp(jt.data.subFlowConfig).targetFlowCode)==null?void 0:_e.trim();if(!wt)continue;const Hi=await XCe(Mn,Sn.current,wt);if(ne)return;const Yi=await YCe(Mn,wt,"trigger"),Ds=(Yi==null?void 0:Yi.requestScope)??(Hi==null?void 0:Hi.requestContract),_c=(st=Tp(jt.data.subFlowConfig).childTriggerSchema)==null?void 0:st.contractName;Ds!=null&&Ds.contractName&&_c!==Ds.contractName&&Wu(jt.id,ju=>({...ju,data:{...ju.data,subFlowConfig:{...Tp(ju.data.subFlowConfig),childTriggerSchema:Ds}}}),!1)}ne||Vn(jt=>jt+1)})(),()=>{ne=!0}},[Mn,ls.nodes,l]),ve.useEffect(()=>{var _e,st;if(!$t){V({status:"idle"});return}gs("inspector");const ne=$t&&Hn.current.get($t.id);if(ne||(_e=$t.data.contractLayer)!=null&&_e.upstreamScope||$t.type==="trigger"||$t.type==="end"){V({status:"ready",title:(ne==null?void 0:ne.ruleCode)??((st=$t.data.contractRef)==null?void 0:st.label)??$t.data.label});return}V(Mn?{status:"loading"}:{status:"error",message:"No contract API configured for this editor."})},[Mn,$t,Qt]),d==="unlicensed"){const ne=xX();return M.jsxs("section",{style:{...Jit,background:ne.licenseBg,border:ne.licenseBorder,color:ne.licenseText},children:[M.jsx("strong",{children:"Rule Flow Designer requires a Muonroi commercial license."}),M.jsx("span",{children:"Load an activation proof before rendering this editor."})]})}function Kc(){jn.current!==null&&(window.clearTimeout(jn.current),jn.current=null)}function ba(){Ui.current!==null&&(window.clearTimeout(Ui.current),Ui.current=null)}function zf(ne){ba(),ni.current=!0,L(S(gM(ne))),R(k(bCe(ne))),Ui.current=window.setTimeout(()=>{ni.current=!1,Ui.current=null},0)}function Zc(ne,_e){var Hi;Kc();const st=CL(ne,{currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}),jt=Cl(st.graph),wt=Yl(jt);if($i.current=jt.metadata,Ei.current=wt,zf(jt),_e!=null&&_e.syncViewport&&(Et.current=!0,Sr(Yi=>Yi+1)),st.issues.length>0){const Yi=((Hi=st.issues[0])==null?void 0:Hi.message)??"Rule flow ordering is invalid.";V({status:"error",message:Yi})}(_e==null?void 0:_e.pushHistory)!==!1&&w.commit(jt),(_e==null?void 0:_e.notify)!==!1&&(e==null||e(jt))}function yo(ne,_e,st=!0){return{nodes:ne.map(zit),edges:_e.map(Uit),metadata:{...$i.current,version:Math.max(1,$i.current.version??1),lastModifiedAt:st?new Date().toISOString():$i.current.lastModifiedAt}}}function Wu(ne,_e,st=!0){const jt=tn.current.map(Hi=>Hi.id===ne?_e(Hi):Hi),wt=CL(yo(jt,Cn.current),{currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}).graph;$i.current=wt.metadata,Ei.current=Yl(wt),L(S(gM(wt))),st&&(e==null||e(wt))}function hr(ne,_e="debounced"){if(t||!A)return;const st=tn.current.map(wt=>wt.id===A?ne(wt):wt),jt=CL(yo(st,Cn.current),{currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}).graph;if($i.current=jt.metadata,Ei.current=Yl(jt),L(S(gM(jt))),e==null||e(jt),_e==="immediate"){w.commit(jt);return}Kc(),jn.current=window.setTimeout(()=>{jn.current=null,w.commit(jt)},300)}function Va(){t||!A||(F(""),j("basic-info"),Zc(yo(tn.current.filter(ne=>ne.id!==A),Cn.current.filter(ne=>ne.source!==A&&ne.target!==A))))}function gc(){t||!$||(Y(""),Zc(yo(tn.current,Cn.current.filter(ne=>ne.id!==$))))}function Uf(ne){if(t||!$)return;const _e=Cn.current.map(st=>st.id===$?ne(st):st);Zc(yo(tn.current,_e),{syncViewport:!1})}function Hd(ne){F(ne),Y("");const _e=tn.current.find(st=>st.id===ne);_e&&j(mCe(_e.data.nodeType)),gs("inspector")}function Hu(ne,_e){const st=JCe(_e,"input"),jt=JCe(_e,"output");Wu(ne,wt=>{var Hi;return{...wt,data:{...wt.data,description:(Hi=wt.data.description)!=null&&Hi.trim()?wt.data.description:_e.description,requestContract:st,responseContract:jt,contractRef:{sourceType:"decision-table",sourceCode:_e.id,label:_e.name}}}},!1),Vn(wt=>wt+1)}function Uh(){const ne=DX(yo(tn.current,Cn.current));Et.current=!0,Zc(ne,{syncViewport:!0})}function jf(ne){const _e=[...Cn.current];if(A){const st=`${A}-${ne.id}`;_e.push({id:st,source:A,target:ne.id,label:"always",data:{edgeType:"always"}}),Y(st)}F(ne.id),Y(""),j(mCe(ne.data.nodeType)),Zc(DX(yo([...tn.current,ne],_e)),{syncViewport:!0})}function Xc(ne,_e){if(t)return;const st={id:`node-${ne}-${Math.random().toString(36).slice(2,10)}`,type:ne,position:_e??{x:60+tn.current.length*36,y:80+tn.current.length%4*90},data:{label:uCe[ne],nodeType:ne,expression:gX(ne),conditionConfig:ne==="condition"?{successLabel:"Valid",failureLabel:"Rejected"}:void 0,subFlowConfig:ne==="sub-flow"?{targetFlowCode:"",inputMappings:[],outputMappings:[]}:void 0,liquidConfig:ne==="liquid"?{outputFormat:"json"}:void 0}};jf(st)}function Om(ne,_e){if(t)return;const st={id:`node-rule-${Math.random().toString(36).slice(2,10)}`,type:"condition",position:_e??{x:60+tn.current.length*36,y:80+tn.current.length%4*90},data:{label:ne.displayName,nodeType:"condition",ruleCode:ne.code,description:ne.description,expression:gX("condition"),contractRef:{sourceType:"rule",sourceCode:ne.code,label:ne.displayName},requestContract:ne.inputSchema,responseContract:ne.outputSchema}};jf(st)}function qf(){Xc("trigger",{x:200,y:180})}const hs=ve.useRef(null),Eb=ve.useCallback(ne=>{ea.current=!0,hs.current={startX:ne.clientX,startW:ns},ne.currentTarget.setPointerCapture(ne.pointerId),ne.preventDefault()},[ns]),Cs=ve.useCallback(ne=>{if(!ea.current||!hs.current)return;const _e=hs.current.startW+(ne.clientX-hs.current.startX);Jo(Math.max(240,Math.min(400,_e)))},[]),Fy=ve.useCallback(ne=>{ea.current&&(ea.current=!1,hs.current=null,ne.currentTarget.releasePointerCapture(ne.pointerId))},[]),jh=typeof n=="number"?`${n}px`:n,xn=Bn>0&&Bn<KCe,Lb=xn?"min(52vh, 520px)":jh,Gt=xX(),qh={color:Gt.textPrimary},Pl=M.jsxs("div",{"data-testid":"rule-flow-sidebar-palette",style:{...tSe,...Zit,...lnt(),gap:8,padding:12},children:[Object.keys(TX).map(ne=>M.jsxs("button",{type:"button",style:int(ne,Gt),"data-testid":`palette-${ne}`,draggable:!t,onClick:()=>Xc(ne),onDragStart:_e=>Kg(_e,ne),disabled:t,children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:hM[ne],style:{flexShrink:0},children:M.jsx("path",{d:kX[ne]})}),M.jsx("span",{style:{fontWeight:600},children:_L[ne]})]}),M.jsx("span",{style:{fontSize:11,color:Gt.textMuted,fontWeight:400},children:kit[ne]})]},ne)),o?M.jsx(dit,{groups:it,loading:bt,readOnly:t,onAddRule:Om,onDragStart:(ne,_e)=>Kg(ne,"condition",_e)}):null]}),Qh=()=>{const ne=document.createElement("input");ne.type="file",ne.accept="application/json,.json",ne.style.position="fixed",ne.style.top="-9999px",document.body.appendChild(ne),ne.addEventListener("change",()=>{var st;const _e=(st=ne.files)==null?void 0:st[0];document.body.removeChild(ne),_e&&(async()=>{try{const jt=await _e.text(),wt=CL(fCe(jt),{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}).graph;$i.current=wt.metadata,Ei.current=Yl(wt),w.reset(wt),zf(wt),F(""),Y(""),j("basic-info"),Et.current=!0,Sr(Hi=>Hi+1),e==null||e(wt),V({status:"ready",title:wt.metadata.ruleSetCode??"Imported flow"})}catch(jt){V({status:"error",message:jt.message})}})()}),ne.click()},jr=()=>Qit(yo(tn.current,Cn.current),$i.current.ruleSetCode),xr=()=>{const ne=OX(yo(tn.current,Cn.current),{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current});Vn(_e=>_e+1),ne.isValid?(V({status:"ready",title:`Valid — ${ne.issues.filter(_e=>_e.severity==="warning").length} warning(s)`}),Vt(`Validation passed with ${ne.issues.filter(_e=>_e.severity==="warning").length} warning(s).`)):(V({status:"error",message:`${ne.issues.filter(_e=>_e.severity==="error").length} error(s) found.`}),Vt(`Validation complete: ${ne.issues.filter(_e=>_e.severity==="error").length} error(s), ${ne.issues.filter(_e=>_e.severity==="warning").length} warning(s).`))},jg=()=>{const ne=OX(yo(tn.current,Cn.current),{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current});if(Vn(_e=>_e+1),!ne.isValid){V({status:"error",message:"Publish blocked because one or more nodes still have contract validation errors."}),Bi("Publish blocked: one or more nodes still have contract validation errors.");return}Xt({graph:ne.graph,warnings:ne.issues.filter(_e=>_e.severity==="warning")})},$o=ne=>M.jsxs("button",{type:"button",style:ne?{...RX,display:"flex",alignItems:"center",gap:5,visibility:nn?"hidden":void 0}:{...uh(!0),display:nn?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:()=>{jg(),ne&&setTimeout(()=>ke(!1),0)},disabled:!Wd,title:c?Lo.length>0?"Fix validation errors before publishing.":"Publish":"No publish handler configured.","aria-disabled":!Wd,children:[M.jsx(Kw,{path:"M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3zM1 13.5a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13a.5.5 0 0 1-.5-.5z"}),"Publish"]}),pl=ne=>M.jsxs("button",{type:"button",style:ne?{...RX,display:"flex",alignItems:"center",gap:5,visibility:nn?"hidden":void 0}:{...uh(!1),display:nn?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},disabled:Mt,onClick:()=>{Qh(),ne&&setTimeout(()=>ke(!1),0)},title:"Import",children:[M.jsx(Kw,{path:["M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z","M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"]}),"Import"]}),Yc=ne=>M.jsxs("button",{type:"button",style:ne?{...RX,display:"flex",alignItems:"center",gap:5}:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{jr(),ne&&setTimeout(()=>ke(!1),0)},title:"Export",children:[M.jsx(Kw,{path:["M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z","M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3z"]}),"Export"]}),Em=M.jsxs("div",{"data-testid":"rule-flow-sidebar-actions",style:{display:"flex",flexDirection:"column",gap:8},ref:Me,children:[ur.issues.length>0?M.jsxs("div",{style:ent(Lo.length>0),children:[M.jsx("strong",{children:Lo.length>0?"Publish blocked":"Publish warnings"}),M.jsxs("span",{children:[Lo.length," error(s) / ",$u.length," warning(s)"]}),Lo.length>0?M.jsxs("ul",{style:{margin:"6px 0 0",padding:"0 0 0 16px",fontSize:12,lineHeight:1.5},children:[Lo.slice(0,20).map((ne,_e)=>M.jsxs("li",{style:{marginBottom:2},children:[M.jsx("code",{style:{fontSize:11,fontWeight:600},children:ne.code}),ne.nodeId?M.jsxs("span",{style:{color:"var(--mu-text-muted)"},children:[" [",ne.nodeId,"]"]}):null," ",ne.message]},_e)),Lo.length>20?M.jsxs("li",{children:["...and ",Lo.length-20," more"]}):null]}):null]}):null,M.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:"var(--mu-space-xs)"},children:[M.jsxs("div",{"data-testid":"toolbar-group-history",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[M.jsx("button",{type:"button",onClick:()=>ae("history"),style:IX(Gt),title:mi("history")?"Expand History":"Collapse History",children:mi("history")?"History ▸":"History ▾"}),mi("history")?null:M.jsxs(M.Fragment,{children:[M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Kc(),w.undo()},disabled:Mt||!w.canUndo,title:"Undo (Ctrl+Z)",children:[M.jsx(Kw,{path:"M7.5 4H3V0L0 3l3 3V3h4.5A3.5 3.5 0 0 1 11 6.5 3.5 3.5 0 0 1 7.5 10H4v1.5h3.5A5 5 0 0 0 12.5 6.5 5 5 0 0 0 7.5 2V4z"}),"Undo"]}),M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Kc(),w.redo()},disabled:Mt||!w.canRedo,title:"Redo (Ctrl+Shift+Z)",children:[M.jsx(Kw,{path:"M8.5 4h4.5v3l3-3-3-3v3H8.5A5 5 0 0 0 3.5 6.5 5 5 0 0 0 8.5 11H12V9.5H8.5A3.5 3.5 0 0 1 5 6.5 3.5 3.5 0 0 1 8.5 3V4z"}),"Redo"]})]})]}),M.jsx("div",{style:{width:1,height:24,background:Gt.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),M.jsxs("div",{"data-testid":"toolbar-group-canvas",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[M.jsx("button",{type:"button",onClick:()=>ae("canvas"),style:IX(Gt),title:mi("canvas")?"Expand Canvas":"Collapse Canvas",children:mi("canvas")?"Canvas ▸":"Canvas ▾"}),mi("canvas")?null:M.jsxs(M.Fragment,{children:[M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:96},onClick:Uh,disabled:Mt,title:"Auto Layout",children:[M.jsx(Kw,{path:"M1 2.5A1.5 1.5 0 0 1 2.5 1h3A1.5 1.5 0 0 1 7 2.5v3A1.5 1.5 0 0 1 5.5 7h-3A1.5 1.5 0 0 1 1 5.5v-3zm8 0A1.5 1.5 0 0 1 10.5 1h3A1.5 1.5 0 0 1 15 2.5v3A1.5 1.5 0 0 1 13.5 7h-3A1.5 1.5 0 0 1 9 5.5v-3zm-8 8A1.5 1.5 0 0 1 2.5 9h3A1.5 1.5 0 0 1 7 10.5v3A1.5 1.5 0 0 1 5.5 15h-3A1.5 1.5 0 0 1 1 13.5v-3zm8 0A1.5 1.5 0 0 1 10.5 9h3A1.5 1.5 0 0 1 15 10.5v3A1.5 1.5 0 0 1 13.5 15h-3A1.5 1.5 0 0 1 9 13.5v-3z"}),"Auto Layout"]}),M.jsxs("button",{type:"button",style:{...uh(!1),display:nn?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:xr,disabled:Mt,title:"Validate",children:[M.jsx(Kw,{path:"M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"}),"Validate"]}),M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:72},onClick:ss,disabled:!r||!l,title:"Dry Run",children:[M.jsx(Kw,{path:"M11.5 2H9V.5a.5.5 0 0 0-1 0V2H5.5A2.5 2.5 0 0 0 3 4.5v7A2.5 2.5 0 0 0 5.5 14h5A2.5 2.5 0 0 0 13 11.5v-7A2.5 2.5 0 0 0 11.5 2zM8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0-1a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"}),"Dry Run"]})]})]}),M.jsx("div",{style:{width:1,height:24,background:Gt.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),de?M.jsxs("div",{style:{position:"relative"},ref:Qe,children:[M.jsx("button",{type:"button",onClick:()=>ke(ne=>!ne),style:{...uh(!1),minWidth:32,padding:"6px 8px",fontSize:16},title:"More actions","aria-label":"More actions",children:"⋮"}),Ce?M.jsxs("div",{style:{position:"absolute",top:"100%",right:0,marginTop:4,background:Gt.overlayBg,border:Gt.overlayBorder,borderRadius:10,boxShadow:Gt.overlayShadow,padding:"4px 0",minWidth:140,zIndex:10},children:[$o(!0),pl(!0),Yc(!0)]}):null]}):M.jsxs("div",{"data-testid":"toolbar-group-workflow",style:{display:"flex",alignItems:"center",gap:4},children:[M.jsx("button",{type:"button",onClick:()=>ae("workflow"),style:IX(Gt),title:mi("workflow")?"Expand Workflow":"Collapse Workflow",children:mi("workflow")?"Workflow ▸":"Workflow ▾"}),mi("workflow")?null:M.jsxs(M.Fragment,{children:[$o(),pl(),Yc()]})]})]})]}),By=M.jsx("div",{"data-testid":"rule-flow-sidebar-inspector",style:{...tSe,...Xit,...cnt()},children:$t?M.jsx(Btt,{selectedNode:{id:$t.id,data:$t.data},selectedExpression:Ml,contractLoadState:G,selectedDecisionTable:oe,decisionTableLoadState:se,readOnly:Mt,apiBaseUrl:r,inspectorTab:q,flowOptions:J,decisionTableOptions:le,setInspectorTab:j,onSelectNodeByRuleCode:ne=>{const _e=tn.current.find(st=>st.data.ruleCode===ne);_e&&Hd(_e.id)},onUpdateLabel:ne=>hr(_e=>({..._e,data:{..._e.data,label:ne}})),onUpdateRuleCode:ne=>hr(_e=>({..._e,data:{..._e.data,ruleCode:ne,contractRef:pCe(_e.data.nodeType,ne,_e.data.contractRef)}})),onUpdateDescription:ne=>hr(_e=>({..._e,data:{..._e.data,description:ne}})),onUpdateContractRef:ne=>hr(_e=>({..._e,data:{..._e.data,contractRef:ne,requestContract:void 0,responseContract:void 0}})),onUpdateDecisionTableCode:ne=>hr(_e=>{var st;return{..._e,data:{..._e.data,ruleCode:ne,requestContract:void 0,responseContract:void 0,contractRef:ne.trim()?{sourceType:"decision-table",sourceCode:ne.trim(),label:((st=le.find(jt=>jt.code===ne.trim()))==null?void 0:st.label)??ne.trim()}:_e.data.contractRef}}}),onUpdateConditionConfig:ne=>hr(_e=>({..._e,data:{..._e.data,conditionConfig:ne}})),onUpdateTargetFlowCode:ne=>hr(_e=>({..._e,data:{..._e.data,contractRef:ne.trim()?{sourceType:"flow",sourceCode:ne.trim(),label:ne.trim()}:_e.data.contractRef,subFlowConfig:{...Tp(_e.data.subFlowConfig),targetFlowCode:ne}}})),onUpdateLiquidOutput:ne=>hr(_e=>({..._e,data:{..._e.data,liquidConfig:{...gCe(_e.data.liquidConfig),outputFormat:ne}}})),onUpdateExpressionLanguage:ne=>hr(_e=>({..._e,data:{..._e.data,expression:{...y_(_e.data),language:ne}}})),onUpdateExpressionBody:ne=>hr(_e=>({..._e,data:{..._e.data,expression:{...y_(_e.data),body:ne}}})),onInsertExpressionToken:ne=>{qs.current?qs.current.insert(ne):hr(_e=>({..._e,data:{..._e.data,expression:{...y_(_e.data),body:`${y_(_e.data).body}${y_(_e.data).body.trim()?" ":""}${ne}`}}}))},onChangeInputContract:ne=>hr(_e=>({..._e,data:{..._e.data,contractOverride:{..._e.data.contractOverride,requestFields:ne}}})),onChangeEffectiveMappings:ne=>hr(_e=>({..._e,data:{..._e.data,inputMappings:_e.data.nodeType==="action"?ne.map(st=>({id:st.id,sourcePath:st.sourcePath,targetPath:st.targetField??st.targetPath,transform:st.transform,language:st.language})):_e.data.inputMappings,subFlowConfig:_e.data.nodeType==="sub-flow"?{...Tp(_e.data.subFlowConfig),inputMappings:ne.map(st=>({id:st.id,sourcePath:st.sourcePath,targetPath:st.targetField??st.targetPath,transform:st.transform,language:st.language}))}:_e.data.subFlowConfig,contractLayer:_e.data.contractLayer}})),onChangeOutputContract:ne=>hr(_e=>({..._e,data:{..._e.data,contractOverride:{..._e.data.contractOverride,responseFields:ne.filter(st=>!st.isResultPayload)}}}),"immediate"),onDeleteNode:Va,connectorCatalog:De,onUpdateConnectorConfig:ne=>hr(_e=>({..._e,data:{..._e.data,connectorConfig:ne}})),onSetInsertRef:ne=>{qs.current=ne},shadowRoot:m instanceof ShadowRoot?m:void 0,showSectionHeader:!1}):M.jsx(Git,{selectedEdge:Mr,readOnly:t,onUpdateEdgeType:ne=>Uf(_e=>({..._e,label:ne,data:{..._e.data??{},edgeType:ne}})),onDeleteEdge:gc})}),Qf=r?r.includes("localhost")||r.includes("127.0.0.1")?"DEV":"PROD":null,[qg,Lm]=ve.useState(!1),[_O,pc]=ve.useState(!1),[Vd,Vu]=ve.useState(!1),[Jc,Qg]=ve.useState("{}"),[Gh,zu]=ve.useState(null),[Uu,Tm]=ve.useState(!1),[Dm,mc]=ve.useState(null),[K,Se]=ve.useState(40),Ge=ve.useRef(!1),[ot,Ut]=ve.useState(new Set),[Xi,si]=ve.useState(null);function cn(){var jt,wt;const ne=ls.nodes.find(Hi=>Hi.type==="trigger"),_e=((jt=ne==null?void 0:ne.data.requestContract)==null?void 0:jt.fields)??((wt=ne==null?void 0:ne.data.contractOverride)==null?void 0:wt.requestFields);if(!_e||_e.length===0)return"{}";const st={};for(const Hi of _e){const Yi=(Hi.dataType??"").toLowerCase();Yi.includes("int")||Yi.includes("number")||Yi.includes("decimal")||Yi.includes("float")||Yi.includes("double")?st[Hi.path]=0:Yi.includes("bool")?st[Hi.path]=!1:Yi.includes("array")||Yi.includes("list")?st[Hi.path]=[]:Yi.includes("object")||Yi.includes("map")||Yi.includes("dict")?st[Hi.path]={}:st[Hi.path]=""}return JSON.stringify(st,null,2)}function ss(){Vu(!0),zu(null),mc(null),Qg(cn())}async function Ss(){if(!(!r||!l)){Tm(!0),mc(null),zu(null);try{const ne=r.replace(/\/$/,""),_e=fd(void 0,{tenantId:a});_e.set("Content-Type","application/json");const st=f!=null?`?version=${f}`:"",jt=await fetch(`${ne}/execute/${encodeURIComponent(l)}${st}`,{method:"POST",headers:_e,body:Jc});if(!jt.ok){const Hi=await jt.text();throw new Error(`Execution failed (${jt.status}): ${Hi}`)}const wt=await jt.json();zu(wt),kr(wt)}catch(ne){mc(ne instanceof Error?ne.message:"Unknown error")}finally{Tm(!1)}}}function Pr(ne){const _e=new Set;for(const st of Object.keys(ne)){const jt=st.match(/^__graph\.node\.(.+?)\.executed$/);jt&&ne[st]===!0&&_e.add(jt[1])}return _e}function kr(ne){const _e=Pr(ne.factBag);if(_e.size===0)for(const jt of ne.results)_e.add(jt.ruleName);if(_e.size>0){const jt=new Map;for(const wt of tn.current)jt.set(wt.id,wt.data.nodeType);for(const[wt,Hi]of jt)Hi==="trigger"&&_e.add(wt),Hi==="end"&&ne.isSuccess&&_e.add(wt)}Ut(_e);const st=new Map(ne.results.map(jt=>[jt.ruleName,jt]));L(jt=>jt.map(wt=>{const Hi=wt.data.ruleCode||wt.data.label,Yi=_e.has(wt.id)||_e.has(Hi),Ds=st.get(Hi);if(!Yi)return{...wt,style:{...wt.style,opacity:.35,transition:"all 300ms ease",filter:"grayscale(0.5)"},className:""};const _c=ne.factBag[`__graph.node.${wt.id}.passed`],ju=_c!==void 0?_c===!0:(Ds==null?void 0:Ds.isSuccess)??!0,Kf=ju?"var(--mu-color-success)":"var(--mu-color-error)",aR=ju?"color-mix(in oklch, var(--mu-color-success) 6%, transparent)":"color-mix(in oklch, var(--mu-color-error) 6%, transparent)";return{...wt,style:{...wt.style,opacity:1,background:aR,border:"none",borderLeft:`4px solid ${Kf}`,borderRadius:8,boxShadow:"none",transition:"all 300ms ease",filter:"none"},className:""}})),R(jt=>jt.map(wt=>{const Hi=tn.current.find(Kf=>Kf.id===wt.source),Yi=tn.current.find(Kf=>Kf.id===wt.target),Ds=(Hi==null?void 0:Hi.data.ruleCode)||(Hi==null?void 0:Hi.data.label)||wt.source,_c=(Yi==null?void 0:Yi.data.ruleCode)||(Yi==null?void 0:Yi.data.label)||wt.target;return(_e.has(wt.source)||_e.has(Ds))&&(_e.has(wt.target)||_e.has(_c))?{...wt,style:{...wt.style,strokeWidth:3,opacity:1,transition:"all 300ms ease"}}:{...wt,style:{...wt.style,strokeWidth:1,opacity:.35,transition:"all 300ms ease"}}}))}function Zn(){L(ne=>ne.map(_e=>({..._e,style:void 0,className:""}))),R(ne=>k(ne.map(_e=>({..._e,style:void 0})))),Ut(new Set),si(null)}function fr(){Vu(!1),zu(null),mc(null),Zn()}function ho(ne,_e){if(!Gh||ot.size===0)return;const st=_e.data.ruleCode||_e.data.label;(ot.has(_e.id)||ot.has(st))&&si({nodeId:st,mousePos:{x:ne.clientX,y:ne.clientY}})}function Gg(){si(null)}function $y(ne){var Yi;ne.preventDefault(),Ge.current=!0;const _e=ne.clientY,st=K,jt=(Yi=vo.current)==null?void 0:Yi.getBoundingClientRect();if(!jt)return;const wt=Ds=>{if(!Ge.current)return;const ju=(_e-Ds.clientY)/jt.height*100,Kf=Math.min(70,Math.max(20,st+ju));Se(Kf)},Hi=()=>{Ge.current=!1,document.removeEventListener("pointermove",wt),document.removeEventListener("pointerup",Hi)};document.addEventListener("pointermove",wt),document.addEventListener("pointerup",Hi)}return M.jsxs(Tve,{children:[M.jsx(Bit,{politeMessage:di,assertiveMessage:Yt}),u?M.jsxs("header",{style:{...ynt,background:Gt.sidebarBg,borderBottom:Gt.sidebarBorder,color:Gt.textPrimary},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--mu-space-sm)"},children:[M.jsx("strong",{style:{fontSize:14},children:"Rule Studio"}),l?M.jsx("span",{style:{...wv,background:Gt.actionPrimaryBg,border:Gt.actionPrimaryBorder,color:Gt.textPrimary},children:l}):null,xt.length>0?M.jsx(_Qe,{versions:xt,activeVersion:Di,selectedVersion:f??null,onSelect:ne=>p==null?void 0:p(ne),onLoadMore:pt,hasMore:vt,loadingMore:ri,tokens:Gt}):f!=null?M.jsxs("span",{style:{...wv,background:Gt.actionPrimaryBg,border:Gt.actionPrimaryBorder,color:Gt.textPrimary,fontSize:11},children:["v",f]}):M.jsx("span",{style:{...wv,background:"var(--mu-color-success-bg)",border:"1px solid var(--mu-color-success-border)",color:"var(--mu-color-success-text)",fontSize:11,fontWeight:700},children:"Active"}),xt.length>1?M.jsx("span",{role:"button",tabIndex:0,style:{...wv,cursor:"pointer",background:"var(--mu-color-interactive-subtle)",border:"1px solid var(--mu-color-interactive-border)",color:"var(--mu-color-interactive)",fontSize:11,fontWeight:600,padding:"3px 10px"},onClick:()=>pc(!0),onKeyDown:ne=>{ne.key==="Enter"&&pc(!0)},children:"Compare"}):null,Qf?M.jsx("span",{style:{...wv,background:Qf==="DEV"?"var(--mu-color-warning-bg)":"var(--mu-color-success-bg)",border:Qf==="DEV"?"1px solid var(--mu-color-warning-border)":"1px solid var(--mu-color-success-border)",color:Qf==="DEV"?Gt.warningText:"var(--mu-color-success-text)",fontSize:10,fontWeight:700},children:Qf}):null,Mt?M.jsx("span",{style:{...wv,background:Gt.errorBg,border:Gt.errorBorder,color:Gt.errorText,fontSize:10,fontWeight:700},children:"READ-ONLY"}):null,(()=>{var st;const ne=f!=null?xt.find(jt=>jt.version===f):Di,_e=(st=ne==null?void 0:ne.status)==null?void 0:st.toLowerCase();return _e==="pendingapproval"?M.jsx("span",{style:{...wv,background:"var(--mu-color-warning-bg)",border:"1px solid var(--mu-color-warning-border)",color:Gt.warningText,fontSize:10,fontWeight:700},children:"PENDING APPROVAL"}):_e==="rejected"?M.jsx("span",{style:{...wv,background:Gt.errorBg,border:Gt.errorBorder,color:Gt.errorText,fontSize:10,fontWeight:700},children:"REJECTED"}):_e==="approved"&&!(ne!=null&&ne.isActive)?M.jsx("span",{style:{...wv,background:"color-mix(in oklch, var(--mu-color-interactive) 12%, transparent)",border:"1px solid color-mix(in oklch, var(--mu-color-interactive) 25%, transparent)",color:"var(--mu-color-interactive)",fontSize:10,fontWeight:700},children:"APPROVED"}):null})()]}),M.jsxs("div",{style:{position:"relative"},children:[M.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",padding:4,color:Gt.textMuted,fontSize:16},onClick:()=>Lm(ne=>!ne),title:"Technical details",children:M.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"currentColor",children:M.jsx("path",{d:"M7.5 1.5a6 6 0 100 12 6 6 0 000-12zM7 5h1v1H7V5zm0 2h1v4H7V7z"})})}),qg?M.jsxs("div",{style:{...wnt,background:Gt.dialogBg,border:Gt.dialogBorder,boxShadow:Gt.dialogShadow,color:Gt.textSecondary},children:[a?M.jsxs("span",{style:{fontSize:11},children:["Tenant: ",a]}):null,r?M.jsxs("span",{style:{fontSize:11,wordBreak:"break-all"},children:["API: ",r]}):null,!a&&!r?M.jsx("span",{style:{fontSize:11},children:"No API configured"}):null]}):null]})]}):null,nn?M.jsxs("div",{style:{padding:"8px 16px",background:"var(--mu-color-warning-bg)",borderBottom:"1px solid var(--mu-color-warning-border)",color:Gt.warningText,fontSize:12,display:"flex",alignItems:"center",gap:8},children:[M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:M.jsx("path",{d:"M8 1l7 14H1L8 1zm-.5 5v4h1V6h-1zm0 5v1h1v-1h-1z"})}),M.jsxs("span",{children:["Viewing version v",f," (read-only)"]}),M.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:6},children:[M.jsx("button",{type:"button",onClick:()=>{if(!r||!l||f==null)return;const ne=r.replace(/\/$/,""),_e=fd(void 0,{tenantId:a});_e.set("Content-Type","application/json"),fetch(`${ne}/rulesets/${encodeURIComponent(l)}/versions`,{method:"POST",headers:_e,body:JSON.stringify({sourceVersion:f})}).then(st=>{if(!st.ok)throw new Error("restore failed");return st.json()}).then(st=>{Xe(0),xe(0,!1),st.version!=null&&(p==null||p(st.version))}).catch(()=>{})},style:{fontSize:11,padding:"4px 12px",borderRadius:6,fontWeight:600,cursor:"pointer",background:"var(--mu-color-success-bg)",border:"1px solid var(--mu-color-success-border)",color:"var(--mu-color-success-text)"},children:"Restore as New Version"}),M.jsx("button",{type:"button",onClick:()=>p==null?void 0:p(null),style:{fontSize:11,padding:"4px 12px",borderRadius:6,fontWeight:600,cursor:"pointer",background:Gt.actionPrimaryBg,border:Gt.actionPrimaryBorder,color:Gt.textPrimary},children:"Back to Active"})]})]}):null,M.jsxs("section",{ref:Bo,style:{...Kit,...nnt(xn,!!($t||Mr),ns,_n),...qh},children:[M.jsxs("aside",{"data-testid":"rule-flow-left-panel",style:{...snt,background:Gt.sidebarBg,border:Gt.sidebarBorder,width:_n?48:ns,transition:ea.current?"none":"width 200ms ease",overflow:_n?"hidden":"auto",position:"relative"},children:[M.jsxs("div",{style:{padding:"var(--mu-space-sm)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[!_n&&M.jsx("strong",{style:{fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-semibold)",color:Gt.textPrimary},children:"Node Library"}),M.jsx("button",{type:"button",title:_n?"Expand Node Library":"Collapse Node Library",onClick:()=>uo(ne=>!ne),style:{background:"transparent",border:"none",cursor:"pointer",padding:4,borderRadius:6,fontSize:14,color:Gt.textMuted,lineHeight:1,marginLeft:_n?"auto":void 0,marginRight:_n?"auto":void 0},children:_n?"›":"«"})]}),_n?M.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:4,padding:"8px 0"},children:Object.keys(TX).map(ne=>M.jsx("div",{title:_L[ne],style:{width:32,height:32,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",cursor:"default",fontSize:16},children:M.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:hM[ne],style:{flexShrink:0},children:M.jsx("path",{d:kX[ne]})})},ne))}):Pl,!_n&&M.jsx("div",{style:{position:"absolute",right:-6,top:0,bottom:0,width:12,cursor:"col-resize",zIndex:5,display:"flex",alignItems:"center",justifyContent:"center"},onPointerDown:Eb,onPointerMove:Cs,onPointerUp:Fy,children:M.jsx("div",{"data-testid":"sidebar-resize-grip",style:{display:"flex",flexDirection:"column",alignItems:"center",gap:3,padding:"4px 2px",borderRadius:4,background:"transparent",transition:"background 150ms"},onPointerEnter:ne=>{ne.currentTarget.style.background="color-mix(in oklch, var(--mu-color-interactive) 15%, transparent)"},onPointerLeave:ne=>{ne.currentTarget.style.background="transparent"},children:[0,1,2].map(ne=>M.jsx("div",{style:{width:4,height:4,borderRadius:"50%",background:"var(--mu-color-border-subtle, var(--mu-text-muted))"}},ne))})})]}),M.jsxs("div",{ref:vo,style:{...Yit,...ant(xn),height:Lb,background:Gt.canvasGradient,display:"flex",flexDirection:"column"},"data-testid":"rule-flow-canvas","data-node-count":O.length,"data-edge-count":D.length,onDragOver:bO,onDrop:z1,children:[M.jsx("style",{children:`
|
|
726
|
+
}`,{label:"class",detail:"definition",type:"keyword"}),dh('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),dh('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],fet=Z1e.concat([dh("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),dh("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),dh("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),X1e=new CZe,Y1e=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function uM(s){return(e,t)=>{let i=e.node.getChild("VariableDefinition");return i&&t(i,s),!0}}const get=["FunctionDeclaration"],pet={FunctionDeclaration:uM("function"),ClassDeclaration:uM("class"),ClassExpression:()=>!0,EnumDeclaration:uM("constant"),TypeAliasDeclaration:uM("type"),NamespaceDeclaration:uM("namespace"),VariableDefinition(s,e){s.matchContext(get)||e(s,"variable")},TypeDefinition(s,e){e(s,"type")},__proto__:null};function J1e(s,e){let t=X1e.get(e);if(t)return t;let i=[],n=!0;function r(o,a){let l=s.sliceString(o.from,o.to);i.push({label:l,type:a})}return e.cursor(zo.IncludeAnonymous).iterate(o=>{if(n)n=!1;else if(o.name){let a=pet[o.name];if(a&&a(o,r)||Y1e.has(o.name))return!1}else if(o.to-o.from>8192){for(let a of J1e(s,o.node))i.push(a);return!1}}),X1e.set(e,i),i}const eCe=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,tCe=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function met(s){let e=md(s.state).resolveInner(s.pos,-1);if(tCe.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&eCe.test(s.state.sliceDoc(e.from,e.to));if(!t&&!s.explicit)return null;let i=[];for(let n=e;n;n=n.parent)Y1e.has(n.name)&&(i=i.concat(J1e(s.state.doc,n)));return{options:i,from:t?e.from:s.pos,validFor:eCe}}const cS=XA.define({name:"javascript",parser:het.configure({props:[G$.add({IfStatement:JA({except:/^\s*({|else\b)/}),TryStatement:JA({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:VZe,SwitchBody:s=>{let e=s.textAfter,t=/^\s*\}/.test(e),i=/^\s*(case|default)\b/.test(e);return s.baseIndent+(t?0:i?1:2)*s.unit},Block:HZe({closing:"}"}),ArrowFunction:s=>s.baseIndent+s.unit,"TemplateString BlockComment":()=>null,"Statement Property":JA({except:/^\s*{/}),JSXElement(s){let e=/^\s*<\//.test(s.textAfter);return s.lineIndent(s.node.from)+(e?0:s.unit)},JSXEscape(s){let e=/\s*\}/.test(s.textAfter);return s.lineIndent(s.node.from)+(e?0:s.unit)},"JSXOpenTag JSXSelfClosingTag"(s){return s.column(s.node.from)+s.unit}}),b0e.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":v0e,BlockComment(s){return{from:s.from+2,to:s.to-2}},JSXElement(s){let e=s.firstChild;if(!e||e.name=="JSXSelfClosingTag")return null;let t=s.lastChild;return{from:e.to,to:t.type.isError?s.to:t.from}},"JSXSelfClosingTag JSXOpenTag"(s){var e;let t=(e=s.firstChild)===null||e===void 0?void 0:e.nextSibling,i=s.lastChild;return!t||t.type.isError?null:{from:t.to,to:i.type.isError?s.to:i.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),iCe={test:s=>/^JSX/.test(s.name),facet:LZ({commentTokens:{block:{open:"{/*",close:"*/}"}}})},_et=cS.configure({dialect:"ts"},"typescript"),bet=cS.configure({dialect:"jsx",props:[TZ.add(s=>s.isTop?[iCe]:void 0)]}),vet=cS.configure({dialect:"jsx ts",props:[TZ.add(s=>s.isTop?[iCe]:void 0)]},"typescript");let nCe=s=>({label:s,type:"keyword"});const sCe="break case const continue default delete export extends false finally in instanceof let new return static super switch this throw true typeof var yield".split(" ").map(nCe),yet=sCe.concat(["declare","implements","private","protected","public"].map(nCe));function wet(s={}){let e=s.jsx?s.typescript?vet:bet:s.typescript?_et:cS,t=s.typescript?fet.concat(yet):Z1e.concat(sCe);return new g0e(e,[cS.data.of({autocomplete:xYe(tCe,w1e(t))}),cS.data.of({autocomplete:met}),s.jsx?ket:[]])}function Cet(s){for(;;){if(s.name=="JSXOpenTag"||s.name=="JSXSelfClosingTag"||s.name=="JSXFragmentTag")return s;if(s.name=="JSXEscape"||!s.parent)return null;s=s.parent}}function rCe(s,e,t=s.length){for(let i=e==null?void 0:e.firstChild;i;i=i.nextSibling)if(i.name=="JSXIdentifier"||i.name=="JSXBuiltin"||i.name=="JSXNamespacedName"||i.name=="JSXMemberExpression")return s.sliceString(i.from,Math.min(i.to,t));return""}const xet=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),ket=Mi.inputHandler.of((s,e,t,i,n)=>{if((xet?s.composing:s.compositionStarted)||s.state.readOnly||e!=t||i!=">"&&i!="/"||!cS.isActiveAt(s.state,e,-1))return!1;let r=n(),{state:o}=r,a=o.changeByRange(l=>{var c;let{head:d}=l,u=md(o).resolveInner(d-1,-1),f;if(u.name=="JSXStartTag"&&(u=u.parent),!(o.doc.sliceString(d-1,d)!=i||u.name=="JSXAttributeValue"&&u.to>d)){if(i==">"&&u.name=="JSXFragmentTag")return{range:l,changes:{from:d,insert:"</>"}};if(i=="/"&&u.name=="JSXStartCloseTag"){let p=u.parent,m=p.parent;if(m&&p.from==d-2&&((f=rCe(o.doc,m.firstChild,d))||((c=m.firstChild)===null||c===void 0?void 0:c.name)=="JSXFragmentTag")){let b=`${f}>`;return{range:Ct.cursor(d+b.length,-1),changes:{from:d,insert:b}}}}else if(i==">"){let p=Cet(u);if(p&&p.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(o.doc.sliceString(d,d+2))&&(f=rCe(o.doc,p,d)))return{range:l,changes:{from:d,insert:`</${f}>`}}}}return{range:l}});return a.changes.empty?!1:(s.dispatch([r,o.update(a,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),Oet=xZ({String:lt.string,Number:lt.number,"True False":lt.bool,PropertyName:lt.propertyName,Null:lt.null,", :":lt.separator,"[ ]":lt.squareBracket,"{ }":lt.brace}),Eet=dM.deserialize({version:14,states:"$bOVQPOOOOQO'#Cb'#CbOnQPO'#CeOvQPO'#ClOOQO'#Cr'#CrQOQPOOOOQO'#Cg'#CgO}QPO'#CfO!SQPO'#CtOOQO,59P,59PO![QPO,59PO!aQPO'#CuOOQO,59W,59WO!iQPO,59WOVQPO,59QOqQPO'#CmO!nQPO,59`OOQO1G.k1G.kOVQPO'#CnO!vQPO,59aOOQO1G.r1G.rOOQO1G.l1G.lOOQO,59X,59XOOQO-E6k-E6kOOQO,59Y,59YOOQO-E6l-E6l",stateData:"#O~OeOS~OQSORSOSSOTSOWQO_ROgPO~OVXOgUO~O^[O~PVO[^O~O]_OVhX~OVaO~O]bO^iX~O^dO~O]_OVha~O]bO^ia~O",goto:"!kjPPPPPPkPPkqwPPPPk{!RPPP!XP!e!hXSOR^bQWQRf_TVQ_Q`WRg`QcZRicQTOQZRQe^RhbRYQR]R",nodeNames:"⚠ JsonText True False Null Number String } { Object Property PropertyName : , ] [ Array",maxTerm:25,nodeProps:[["isolate",-2,6,11,""],["openedBy",7,"{",14,"["],["closedBy",8,"}",15,"]"]],propSources:[Oet],skippedNodes:[0],repeatNodeCount:2,tokenData:"(|~RaXY!WYZ!W]^!Wpq!Wrs!]|}$u}!O$z!Q!R%T!R![&c![!]&t!}#O&y#P#Q'O#Y#Z'T#b#c'r#h#i(Z#o#p(r#q#r(w~!]Oe~~!`Wpq!]qr!]rs!xs#O!]#O#P!}#P;'S!];'S;=`$o<%lO!]~!}Og~~#QXrs!]!P!Q!]#O#P!]#U#V!]#Y#Z!]#b#c!]#f#g!]#h#i!]#i#j#m~#pR!Q![#y!c!i#y#T#Z#y~#|R!Q![$V!c!i$V#T#Z$V~$YR!Q![$c!c!i$c#T#Z$c~$fR!Q![!]!c!i!]#T#Z!]~$rP;=`<%l!]~$zO]~~$}Q!Q!R%T!R![&c~%YRT~!O!P%c!g!h%w#X#Y%w~%fP!Q![%i~%nRT~!Q![%i!g!h%w#X#Y%w~%zR{|&T}!O&T!Q![&Z~&WP!Q![&Z~&`PT~!Q![&Z~&hST~!O!P%c!Q![&c!g!h%w#X#Y%w~&yO[~~'OO_~~'TO^~~'WP#T#U'Z~'^P#`#a'a~'dP#g#h'g~'jP#X#Y'm~'rOR~~'uP#i#j'x~'{P#`#a(O~(RP#`#a(U~(ZOS~~(^P#f#g(a~(dP#i#j(g~(jP#X#Y(m~(rOQ~~(wOW~~(|OV~",tokenizers:[0],topRules:{JsonText:[0,1]},tokenPrec:0}),Let=XA.define({name:"json",parser:Eet.configure({props:[G$.add({Object:JA({except:/^\s*\}/}),Array:JA({except:/^\s*\]/})}),b0e.add({"Object Array":v0e})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function Tet(){return new g0e(Let)}function oCe(s){switch(s){case"feel":return bJe;case"liquid":return wJe;case"scriban":return xJe;case"javascript":return wet();case"json":return Tet();case"plain-text":return[]}}const aCe=new Mw,lCe=new Mw,Det=new Mw,cCe=new Mw;function dX({value:s,language:e,readOnly:t,onChange:i,onInsertToken:n,extensions:r,minHeight:o,root:a,singleLine:l=!1,placeholderText:c}){const d=o??(l?36:180),u=ve.useRef(null),f=ve.useRef(null),p=ve.useRef(i),m=ve.useRef(n);p.current=i,m.current=n,ve.useEffect(()=>{if(!u.current)return;const w=[...l?[]:[pZe(),BKe()],AKe(),qKe(),KKe(),YZe(),nJe(),bXe(),D$.of([...CYe,...EXe,...oJe]),Mi.updateListener.of(O=>{O.docChanged&&p.current(O.state.doc.toString())}),aCe.of([Mi.editable.of(!t),aa.readOnly.of(t)]),lCe.of(oCe(e)),Det.of([]),cCe.of(r??[]),...l?[Mi.theme({"&":{maxHeight:`${d}px`},".cm-scroller":{overflow:"hidden"},".cm-content":{padding:"4px 8px"},".cm-gutters":{display:"none"}}),aa.transactionFilter.of(O=>O.newDoc.lines>1?[]:O)]:[],...c?[VKe(c)]:[]],S=aa.create({doc:s,extensions:w}),k=new Mi({state:S,parent:u.current,root:a});return f.current=k,m.current&&m.current({insert:O=>{const L=k.state.selection.main.head;k.dispatch({changes:{from:L,insert:O},selection:{anchor:L+O.length}}),k.focus()}}),()=>{k.destroy(),f.current=null}},[a]),ve.useEffect(()=>{const w=f.current;if(!w)return;const S=w.state.doc.toString();S!==s&&w.dispatch({changes:{from:0,to:S.length,insert:s}})},[s]),ve.useEffect(()=>{const w=f.current;w&&w.dispatch({effects:lCe.reconfigure(oCe(e))})},[e]),ve.useEffect(()=>{const w=f.current;w&&w.dispatch({effects:aCe.reconfigure([Mi.editable.of(!t),aa.readOnly.of(t)])})},[t]),ve.useEffect(()=>{const w=f.current;w&&w.dispatch({effects:cCe.reconfigure(r??[])})},[r]);const b={minHeight:`${d}px`,border:"1px solid rgba(148, 163, 184, 0.24)",borderRadius:l?"6px":"14px",overflow:"hidden",...l?{marginBottom:0}:{}};return M.jsx("div",{ref:u,style:b})}function Iet({value:s,onChange:e,onReset:t,tokens:i,editorRoot:n}){return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,borderBottom:`1px solid ${i.sidebarBorder.replace("1px solid ","")}`},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",background:i.sidebarBg,borderBottom:`1px solid ${i.sidebarBorder.replace("1px solid ","")}`},children:[M.jsx("span",{style:{fontSize:12,fontWeight:600,color:i.textPrimary},children:"Input Data (JSON)"}),t?M.jsx("button",{type:"button",onClick:t,style:{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:i.textSecondary,textDecoration:"underline",padding:"2px 4px"},children:"Reset to Schema"}):null]}),M.jsx(dX,{value:s,language:"json",readOnly:!1,onChange:e,minHeight:160,singleLine:!1,root:n,placeholderText:'{ "key": "value" }'})]})}function dCe({title:s,count:e,defaultExpanded:t,headerRight:i,children:n}){const[r,o]=ve.useState(t);return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsxs("div",{role:"button",tabIndex:0,onClick:()=>o(!r),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(!r))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[M.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:r?"▼":"▶"}),M.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:s}),e!==void 0?M.jsxs("span",{style:{background:"var(--mu-border-subtle)",padding:"2px 8px",borderRadius:10,fontSize:11,color:"var(--mu-text-secondary)",fontWeight:600},children:[e," field",e!==1?"s":""]}):null]}),i]}),r?n:null]})}function Ret({entry:s,tokens:e,onShowFullFactBag:t,factBagClean:i}){var c,d,u,f;const n={};if(s.businessFacts&&Object.assign(n,s.businessFacts),s.outputs){const p=s.outputs.result;if(p&&typeof p=="object"){const m=p;m.message!=null&&(n.message=m.message),m.errorCode!=null&&(n.errorCode=m.errorCode)}for(const[m,b]of Object.entries(s.outputs))["executed","passed","errored","result"].includes(m)||(n[m]=b)}const r=Object.keys(n),o=((c=s.status)==null?void 0:c.elapsedMs)??s.elapsedMs,a={};if(i)for(const[p,m]of Object.entries(i))p.startsWith("__")||(a[p]=m);const l="var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)";return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[M.jsx("button",{type:"button",onClick:t,style:{fontSize:13,color:e.textSecondary,cursor:"pointer",padding:"6px 10px",background:"none",border:"none",textAlign:"left",textDecoration:"none"},onMouseEnter:p=>{p.currentTarget.style.textDecoration="underline"},onMouseLeave:p=>{p.currentTarget.style.textDecoration="none"},children:"< Back to Full FactBag"}),M.jsxs("div",{style:{padding:"8px 12px",borderRadius:6,background:"color-mix(in oklch, var(--mu-border-subtle) 40%, transparent)"},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10,marginBottom:(d=s.status)!=null&&d.message||s.errors&&s.errors.length>0?8:0},children:[M.jsx("span",{style:{display:"inline-block",width:22,height:22,borderRadius:"50%",lineHeight:"22px",textAlign:"center",fontSize:13,fontWeight:700,background:s.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:s.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:s.isSuccess?"✓":"✗"}),M.jsx("span",{style:{fontSize:15,fontWeight:600,color:s.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:s.isSuccess?"Passed":"Failed"}),((u=s.status)==null?void 0:u.executed)===!1?M.jsx("span",{style:{fontSize:12,color:"var(--mu-text-muted)",fontStyle:"italic"},children:"skipped"}):null,o!==void 0?M.jsxs("span",{style:{fontSize:12,padding:"2px 10px",borderRadius:12,marginLeft:"auto",background:"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)",color:"var(--mu-color-success-text)",fontWeight:600},children:[o,"ms"]}):null]}),(f=s.status)!=null&&f.message?M.jsx("div",{style:{fontSize:13,color:s.isSuccess?e.textSecondary:"var(--mu-color-error)",...s.isSuccess?{}:{borderLeft:"3px solid var(--mu-color-error)",paddingLeft:10}},children:s.status.message}):null,s.errors&&s.errors.length>0?M.jsx("div",{style:{marginTop:6,display:"flex",flexDirection:"column",gap:4},children:s.errors.map((p,m)=>M.jsx("div",{style:{fontSize:12,color:"var(--mu-color-error)",borderLeft:"3px solid var(--mu-color-error)",paddingLeft:10},children:p},m))}):null]}),M.jsx(dCe,{title:"Output",count:r.length>0?r.length:void 0,defaultExpanded:!0,children:r.length>0?M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,padding:"6px 10px",fontFamily:l},children:r.map(p=>M.jsxs("div",{style:{display:"flex",gap:8,flexWrap:"wrap",fontSize:13},children:[M.jsxs("span",{style:{fontWeight:600,color:e.textSecondary,minWidth:80},children:[p,":"]}),M.jsx("span",{style:{color:e.textPrimary},children:typeof n[p]=="object"&&n[p]!==null?JSON.stringify(n[p]):String(n[p]??"")})]},p))}):M.jsx("div",{style:{padding:"6px 10px",fontSize:13,color:e.textMuted,fontStyle:"italic"},children:"No output facts — code-first rule writes directly to FactBag"})}),M.jsx(dCe,{title:"FactBag Context",count:Object.keys(a).length>0?Object.keys(a).length:void 0,defaultExpanded:!1,children:Object.keys(a).length>0?M.jsx("pre",{style:{margin:0,fontSize:12,lineHeight:1.6,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:l,color:e.textPrimary,maxHeight:250,overflowY:"auto",padding:"6px 10px"},children:JSON.stringify(a,null,2)}):M.jsx("div",{style:{padding:"6px 10px",fontSize:13,color:e.textMuted,fontStyle:"italic"},children:"No FactBag data available"})})]})}function Net({result:s,loading:e,error:t,onSelectNode:i,onClose:n,tokens:r}){const[o,a]=ve.useState(null),l=s==null?void 0:s.results.find(u=>u.ruleName===o),c=(s==null?void 0:s.results.filter(u=>u.isSuccess).length)??0,d=(s==null?void 0:s.results.filter(u=>!u.isSuccess).length)??0;return M.jsxs("div",{style:{borderTop:`2px solid ${r.sidebarBorder.replace("1px solid ","")}`,height:"45vh",minHeight:280,overflow:"hidden",display:"flex",flexDirection:"column",background:r.inspectorBg},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,flexShrink:0},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsx("span",{style:{fontSize:14,fontWeight:600,color:r.textPrimary},children:"Dry Run Results"}),s?M.jsxs("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,background:s.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:s.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)",fontWeight:600},children:[s.executionTimeMs,"ms"]}):null]}),M.jsx("button",{type:"button",onClick:n,style:{background:"transparent",border:"none",cursor:"pointer",color:r.textMuted,fontSize:14,padding:2},title:"Close results",children:"X"})]}),M.jsx("div",{style:{flex:1,overflow:"hidden"},children:e?M.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:r.textSecondary,fontSize:13},children:"Executing dry run..."}):t?M.jsxs("div",{style:{padding:16,color:r.errorText,fontSize:13},children:[M.jsx("strong",{children:"Error:"})," ",t]}):s?M.jsxs("div",{style:{display:"flex",height:"100%"},children:[M.jsx("div",{style:{width:"60%",overflow:"auto",borderRight:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`},children:M.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[M.jsx("thead",{children:M.jsxs("tr",{style:{borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,position:"sticky",top:0,background:r.inspectorBg,zIndex:1},children:[M.jsx("th",{style:{...uX,color:r.textSecondary},children:"Node"}),M.jsx("th",{style:{...uX,color:r.textSecondary,width:60},children:"Status"}),M.jsx("th",{style:{...uX,color:r.textSecondary,width:80},children:"Evaluation"})]})}),M.jsx("tbody",{children:s.results.map(u=>M.jsxs("tr",{onClick:()=>{const f=u.ruleName===o?null:u.ruleName;a(f),f&&(i==null||i(f))},style:{cursor:"pointer",borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,background:o===u.ruleName?r.overlayItemSelectedBg:"transparent"},children:[M.jsxs("td",{style:{padding:"8px 12px",color:r.textPrimary,fontWeight:500,fontSize:13},children:[u.ruleName,u.errors&&u.errors.length>0?M.jsx("div",{style:{fontSize:11,color:r.errorText,marginTop:2},children:u.errors[0]}):null]}),M.jsx("td",{style:{padding:"8px 8px",textAlign:"center"},children:M.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:u.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:u.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:u.isSuccess?"✓":"✗"})}),M.jsx("td",{style:{padding:"6px 8px",textAlign:"center",fontSize:11,color:r.textSecondary},children:u.evaluationResult===!0?"true":u.evaluationResult===!1?"false":u.evaluationResult??"—"})]},u.ruleName))})]})}),M.jsx("div",{style:{width:"40%",overflow:"auto",padding:"10px 12px"},children:l?M.jsx(Ret,{entry:l,tokens:r,onShowFullFactBag:()=>a(null),factBagClean:s==null?void 0:s.factBagClean}):M.jsxs(M.Fragment,{children:[M.jsx("div",{style:{fontSize:11,color:r.textSecondary,marginBottom:4,fontWeight:600},children:"Full FactBag"}),M.jsx("pre",{style:{margin:0,fontSize:11,lineHeight:1.5,color:r.textPrimary,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)"},children:JSON.stringify((s==null?void 0:s.factBagClean)??(s==null?void 0:s.factBag)??{},null,2)})]})})]}):null}),s?M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"6px 12px",borderTop:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`,fontSize:12,flexShrink:0},children:[M.jsxs("span",{style:{color:"var(--mu-color-success-text)",fontWeight:600},children:[c," passed"]}),M.jsxs("span",{style:{color:"var(--mu-color-error)",fontWeight:600},children:[d," failed"]}),M.jsxs("span",{style:{color:r.textMuted,marginLeft:"auto"},children:["Total: ",s.executionTimeMs,"ms"]})]}):null]})}const uX={padding:"10px 12px",textAlign:"left",fontSize:12,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px"};function Aet({nodeName:s,isSuccess:e,evaluationResult:t,outputs:i,errors:n,position:r,tokens:o}){const a=e?"var(--mu-color-success)":"var(--mu-color-error)",l=e?"var(--mu-color-success-bg)":"var(--mu-color-error-bg)",c=e?"Pass":"Fail",d=i!=null&&Object.keys(i).length>0,u=n!=null&&n.length>0;return M.jsxs("div",{style:{position:"fixed",left:r.x+12,top:r.y-8,background:o.inspectorBg,border:`1px solid ${o.sidebarBorder.replace("1px solid ","")}`,borderRadius:8,boxShadow:"0 4px 12px rgba(0,0,0,0.15)",padding:"10px 14px",maxWidth:320,zIndex:1e3,pointerEvents:"none",fontSize:12},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[M.jsx("span",{style:{fontWeight:600,color:o.textPrimary},children:s}),M.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:12,background:l,color:a,fontWeight:600,fontSize:11},children:c})]}),t!==void 0?M.jsxs("div",{style:{color:o.textSecondary,marginBottom:4},children:["Evaluation: ",String(t)]}):null,d?M.jsxs("div",{style:{marginBottom:4},children:[M.jsx("div",{style:{color:o.textSecondary,marginBottom:2},children:"Outputs:"}),M.jsx("pre",{style:{maxHeight:120,overflowY:"auto",fontFamily:"monospace",fontSize:11,margin:0,padding:"4px 6px",background:"rgba(0,0,0,0.04)",borderRadius:4,whiteSpace:"pre-wrap",wordBreak:"break-all",color:o.textPrimary},children:JSON.stringify(i,null,2)})]}):null,u?M.jsxs("div",{children:[M.jsx("div",{style:{color:"var(--mu-color-error)",marginBottom:2},children:"Errors:"}),n.map((f,p)=>M.jsx("div",{style:{color:"var(--mu-color-error)",fontSize:11},children:f},p))]}):null]})}const _L={trigger:"Trigger",condition:"Condition",action:"Action","decision-table":"Decision Table","sub-flow":"Sub Flow",liquid:"Liquid",connector:"Connector",end:"End"},hM={trigger:"var(--mu-node-trigger)",condition:"var(--mu-node-condition)",action:"var(--mu-node-action)","decision-table":"var(--mu-node-decision-table)","sub-flow":"var(--mu-node-sub-flow)",liquid:"var(--mu-node-liquid)",connector:"var(--mu-node-connector)",end:"var(--mu-node-end)"},uCe={trigger:"Create request",condition:"New Condition",action:"New Action","decision-table":"Decision Table","sub-flow":"Sub Flow",liquid:"Liquid Transform",connector:"New Connector",end:"End"},Met={minWidth:188,borderRadius:18,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-base)",boxShadow:"var(--mu-shadow-node)",padding:"12px 14px"};function Cl(s){var t,i,n,r,o,a;if(!s||typeof s!="object")return gB();const e=s;return{nodes:Array.isArray(e.nodes)?e.nodes.map((l,c)=>Pet(l,c)):[],edges:Array.isArray(e.edges)?e.edges.filter(l=>!!l&&typeof l.source=="string"&&typeof l.target=="string").map((l,c)=>({id:typeof l.id=="string"&&l.id?l.id:`edge-${c+1}`,source:l.source,target:l.target,label:typeof l.label=="string"?l.label:void 0,edgeType:d8(l.edgeType)})):[],metadata:{version:Math.max(1,((t=e.metadata)==null?void 0:t.version)??1),tenantId:(i=e.metadata)==null?void 0:i.tenantId,ruleSetCode:(n=e.metadata)==null?void 0:n.ruleSetCode,workflowName:(r=e.metadata)==null?void 0:r.workflowName,lastModifiedAt:(o=e.metadata)==null?void 0:o.lastModifiedAt,lastModifiedBy:(a=e.metadata)==null?void 0:a.lastModifiedBy}}}function hCe(s){return JSON.stringify(Cl(s),null,2)}function fCe(s){let e;try{e=JSON.parse(s)}catch(o){throw new Error(`Invalid rule flow JSON: ${o.message}`)}if(e&&typeof e=="object"){const o=e;if(o.ruleSetJson&&typeof o.ruleSetJson=="string")try{e=JSON.parse(o.ruleSetJson)}catch{}const a=e;a.ruleSet&&typeof a.ruleSet=="object"&&(e=a.ruleSet);const l=e;l.flowGraph&&typeof l.flowGraph=="object"&&(e=l.flowGraph)}const t=Cl(e),i=t.nodes.filter(o=>o.type==="trigger").length,n=t.nodes.filter(o=>o.type==="end").length;if(i!==1)throw new Error("Imported flow must contain exactly one trigger node.");if(n<1)throw new Error("Imported flow must contain at least one end node.");const r=new Set(t.nodes.map(o=>o.id));if(r.size!==t.nodes.length)throw new Error("Imported flow contains duplicate node ids.");for(const o of t.edges)if(!r.has(o.source)||!r.has(o.target))throw new Error(`Imported flow edge '${o.id}' references missing nodes.`);return t}function Yl(s){const e=Cl(s);return JSON.stringify({nodes:e.nodes.map(t=>({id:t.id,type:t.type,label:t.label,ruleCode:t.ruleCode??"",feelExpression:t.feelExpression??"",position:t.position,data:hX(t.data)})).sort((t,i)=>(t.id??"").localeCompare(i.id??"")),edges:e.edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??"",edgeType:t.edgeType})).sort((t,i)=>(t.id??"").localeCompare(i.id??"")),metadata:{version:e.metadata.version,tenantId:e.metadata.tenantId??"",ruleSetCode:e.metadata.ruleSetCode??"",workflowName:e.metadata.workflowName??""}})}function Pet(s,e){const t=mX(s.type),i=hX(s.data),n=fX(i.expression,s.feelExpression,t),r=s.position??{x:Number.NaN,y:Number.NaN};return{id:typeof s.id=="string"&&s.id?s.id:`node-${e+1}`,type:t,label:typeof s.label=="string"&&s.label?s.label:uCe[t],feelExpression:n.language==="feel"?n.body:void 0,ruleCode:typeof s.ruleCode=="string"?s.ruleCode:void 0,expressionLanguage:s.expressionLanguage==="feel"||s.expressionLanguage==="javascript"?s.expressionLanguage:void 0,position:{x:Number.isFinite(r==null?void 0:r.x)?r.x:40+e*48,y:Number.isFinite(r==null?void 0:r.y)?r.y:60+e%4*88},data:{...i,expression:n}}}function hX(s){var r;const e=s&&typeof s=="object"?s:{},t=Array.isArray(e.outputFields)?e.outputFields.map(bL).filter(Boolean):[],i=Fet(e.contractOverride),n=(r=i==null?void 0:i.responseFields)!=null&&r.length?i.responseFields:t.length?t:void 0;return{...e,description:typeof e.description=="string"?e.description:void 0,expression:fX(e.expression,typeof e.feelExpression=="string"?e.feelExpression:void 0),contractRef:Bet(e.contractRef),requestContract:fM(e.requestContract),responseContract:fM(e.responseContract),contractOverride:i||n?{...i,responseFields:n}:void 0,inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(l8).filter(Boolean):void 0,contractLayer:qet(e.contractLayer),dependsOn:Array.isArray(e.dependsOn)?e.dependsOn.filter(o=>typeof o=="string"&&o.trim().length>0).map(o=>o.trim()):void 0,order:typeof e.order=="number"&&Number.isFinite(e.order)?e.order:void 0,conditionConfig:$et(e.conditionConfig),subFlowConfig:Wet(e.subFlowConfig),liquidConfig:Vet(e.liquidConfig),connectorConfig:(()=>{const o=Het(e.connectorConfig);return o&&!o.connectorType&&typeof e.connectorType=="string"&&(o.connectorType=e.connectorType),o})()}}function Fet(s){if(!s||typeof s!="object")return;const e=s;return{requestFields:Array.isArray(e.requestFields)?e.requestFields.map(bL).filter(Boolean):void 0,responseFields:Array.isArray(e.responseFields)?e.responseFields.map(bL).filter(Boolean):void 0}}function Bet(s){if(!s||typeof s!="object")return;const e=s,t=e.sourceType,i=e.sourceCode;if(!(typeof t!="string"||typeof i!="string"||!i.trim()))return{sourceType:Xet(t),sourceCode:i.trim(),label:typeof e.label=="string"?e.label:void 0}}function fM(s){if(!s||typeof s!="object")return;const e=s,t=typeof e.contractName=="string"&&e.contractName.trim()?e.contractName.trim():"";if(t)return{contractName:t,title:typeof e.title=="string"?e.title:void 0,description:typeof e.description=="string"?e.description:void 0,rootType:typeof e.rootType=="string"?e.rootType:void 0,fields:Array.isArray(e.fields)?e.fields.map(bL).filter(Boolean):[]}}function bL(s){if(!s||typeof s!="object")return null;const e=s,t=typeof e.path=="string"&&e.path.trim()?e.path.trim():"",i=typeof e.label=="string"&&e.label.trim()?e.label.trim():t,n=typeof e.dataType=="string"&&e.dataType.trim()?e.dataType.trim():"unknown";return t?{path:t,label:i,dataType:n,valueExpression:typeof e.valueExpression=="string"?e.valueExpression:void 0,runtimeWritten:e.runtimeWritten===!0?!0:void 0,required:!!e.required,description:typeof e.description=="string"?e.description:void 0,example:typeof e.example=="string"?e.example:void 0,exposeToParent:e.exposeToParent===!1?!1:void 0,isResultPayload:e.isResultPayload===!0?!0:void 0,sourceNodeId:typeof e.sourceNodeId=="string"?e.sourceNodeId:void 0,sourceNodeLabel:typeof e.sourceNodeLabel=="string"?e.sourceNodeLabel:void 0,sourceNodeType:typeof e.sourceNodeType=="string"&&pX(e.sourceNodeType)?e.sourceNodeType:void 0,sourceKind:e.sourceKind==="flow-input"||e.sourceKind==="node-output"||e.sourceKind==="result-payload"||e.sourceKind==="sub-flow-output"||e.sourceKind==="inline"?e.sourceKind:void 0,children:Array.isArray(e.children)?e.children.map(bL).filter(Boolean):void 0}:null}function fX(s,e,t="action"){if(s&&typeof s=="object"){const i=s;if(typeof i.language=="string"&&typeof i.body=="string")return{language:_Ce(i.language),body:i.body}}return typeof e=="string"&&e.trim()?{language:"feel",body:e}:gX(t)}function $et(s){if(!s||typeof s!="object")return;const e=s;return{successLabel:typeof e.successLabel=="string"?e.successLabel:void 0,failureLabel:typeof e.failureLabel=="string"?e.failureLabel:void 0,failureMessage:typeof e.failureMessage=="string"?e.failureMessage:void 0}}function Wet(s){if(!s||typeof s!="object")return;const e=s;return{targetFlowCode:typeof e.targetFlowCode=="string"?e.targetFlowCode:void 0,childTriggerSchema:fM(e.childTriggerSchema),inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(l8).filter(Boolean):[],outputMappings:Array.isArray(e.outputMappings)?e.outputMappings.map(l8).filter(Boolean):[]}}function Het(s){if(!s||typeof s!="object")return;const e=s,t=Object.keys(e);return console.log("[muonroi-debug] MNormalizeConnectorConfig input keys:",t.join(","),"| has url:","url"in e,"| has connectorType:",typeof e.connectorType),typeof e.connectorType=="string"&&e.connectorConfig&&typeof e.connectorConfig=="object"?(console.log("[muonroi-debug] → nested format detected"),{connectorType:e.connectorType,connectorConfig:e.connectorConfig,credentialId:typeof e.credentialId=="string"?e.credentialId:void 0}):t.some(n=>["url","method","body","operation","webhookUrl","to","key","headers"].includes(n))?(console.log("[muonroi-debug] → flat/runtime format detected, using candidate as connectorConfig"),{connectorType:typeof e.connectorType=="string"?e.connectorType:void 0,connectorConfig:e,credentialId:typeof e.credentialId=="string"?e.credentialId:void 0}):(console.log("[muonroi-debug] → legacy/fallback format"),{connectorType:typeof e.connectorType=="string"?e.connectorType:void 0,connectorConfig:e.connectorConfig&&typeof e.connectorConfig=="object"?e.connectorConfig:void 0,credentialId:typeof e.credentialId=="string"?e.credentialId:void 0})}function Vet(s){if(!s||typeof s!="object")return;const e=s;return{template:typeof e.template=="string"?e.template:void 0,outputFormat:e.outputFormat==="json"||e.outputFormat==="text"||e.outputFormat==="object"?e.outputFormat:void 0}}function l8(s){if(!s||typeof s!="object")return null;const e=s;return{id:typeof e.id=="string"&&e.id?e.id:`map-${Math.random().toString(36).slice(2,9)}`,sourcePath:typeof e.sourcePath=="string"?e.sourcePath:"",targetPath:typeof e.targetPath=="string"?e.targetPath:"",transform:typeof e.transform=="string"?e.transform:void 0,language:typeof e.language=="string"?_Ce(e.language):void 0}}function zet(s){const e=l8(s);if(!e||!s||typeof s!="object")return e;const t=s;return{...e,targetField:typeof t.targetField=="string"?t.targetField:void 0,sourceDataType:typeof t.sourceDataType=="string"?t.sourceDataType:void 0,targetDataType:typeof t.targetDataType=="string"?t.targetDataType:void 0,sourceNodeId:typeof t.sourceNodeId=="string"?t.sourceNodeId:void 0,sourceNodeLabel:typeof t.sourceNodeLabel=="string"?t.sourceNodeLabel:void 0,required:t.required===!0?!0:void 0,status:t.status==="mapped"||t.status==="missing"||t.status==="type-mismatch"||t.status==="suggested"?t.status:void 0,transformSuggestion:typeof t.transformSuggestion=="string"?t.transformSuggestion:void 0}}function Uet(s){if(!s||typeof s!="object")return null;const e=s,t=typeof e.code=="string"&&e.code.trim()?e.code.trim():"",i=typeof e.message=="string"&&e.message.trim()?e.message.trim():"";return!t||!i?null:{code:t,message:i,severity:e.severity==="warning"||e.severity==="info"?e.severity:"error",nodeId:typeof e.nodeId=="string"?e.nodeId:void 0,fieldPath:typeof e.fieldPath=="string"?e.fieldPath:void 0,sourcePath:typeof e.sourcePath=="string"?e.sourcePath:void 0,targetPath:typeof e.targetPath=="string"?e.targetPath:void 0,relatedNodeId:typeof e.relatedNodeId=="string"?e.relatedNodeId:void 0}}function jet(s){if(!s||typeof s!="object")return;const e=s,t=typeof e.contractName=="string"&&e.contractName.trim()?e.contractName.trim():"";if(t)return{contractName:t,title:typeof e.title=="string"?e.title:void 0,description:typeof e.description=="string"?e.description:void 0,mode:e.mode==="auto"||e.mode==="manual"||e.mode==="expression"||e.mode==="decision-table"||e.mode==="sub-flow"?e.mode:void 0,fields:Array.isArray(e.fields)?e.fields.map(bL).filter(Boolean):[],mappings:Array.isArray(e.mappings)?e.mappings.map(zet).filter(Boolean):[]}}function qet(s){if(!s||typeof s!="object")return;const e=s;return{upstreamScope:fM(e.upstreamScope),effectiveInput:jet(e.effectiveInput),outputContract:fM(e.outputContract),validationIssues:Array.isArray(e.validationIssues)?e.validationIssues.map(Uet).filter(Boolean):void 0}}function y_(s){const e=typeof s.feelExpression=="string"?s.feelExpression:void 0;return fX(s.expression,e,s.nodeType??"action")}function Tp(s){return s??{targetFlowCode:"",childTriggerSchema:void 0,inputMappings:[],outputMappings:[]}}function gCe(s){return s??{outputFormat:"json"}}function Oc(s,e=[]){var t;for(const i of s)e.push(i),(t=i.children)!=null&&t.length&&Oc(i.children,e);return e}function pCe(s,e,t){const i=e.trim();return i?{sourceType:(t==null?void 0:t.sourceType)??c8(s),sourceCode:i,label:t==null?void 0:t.label}:t}const Qet=new Set(["condition","action","decision-table","sub-flow","liquid","connector"]);function mCe(s){return s==="trigger"?"input-data":Qet.has(s)?"data-mapping":"basic-info"}function c8(s){return s==="sub-flow"?"flow":s==="decision-table"?"decision-table":s==="liquid"||s==="connector"?"api":"rule"}function Get(s){const e=["basic-info","input-data","data-mapping","output-data"];return s!=="trigger"&&s!=="end"&&e.push("logic"),e}function Ket(s){return s==="basic-info"?"Basic Info":s==="input-data"?"Input Data":s==="data-mapping"?"Data Flow":s==="output-data"?"Output Data":"Logic"}function gX(s){return{language:s==="liquid"?"liquid":"feel",body:""}}const Zet=new Set(Object.keys(_L));function pX(s){return Zet.has(s)}function mX(s){return typeof s=="string"&&pX(s)?s:"action"}function d8(s){return s==="always"||s==="on-true"||s==="on-false"||s==="on-error"?s:"always"}function _Ce(s){if(typeof s!="string")return"feel";const e=s.trim().toLowerCase();return e==="feel"||e==="liquid"||e==="plain-text"||e==="javascript"||e==="scriban"?e:"feel"}function Xet(s){return s==="rule"||s==="flow"||s==="decision-table"||s==="api"||s==="inline"?s:"rule"}function gM(s){return Cl(s).nodes.map(t=>({id:t.id,type:t.type,position:t.position,data:{label:t.label,ruleCode:t.ruleCode,nodeType:mX(t.type),...t.data}}))}function bCe(s){return Cl(s).edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??t.edgeType,data:{edgeType:t.edgeType}}))}function Yet(s,e){switch(e.type){case"commit":{const t=Cl(e.graph);return Yl(t)===Yl(s.present)?s:{past:[...s.past,s.present].slice(-50),present:t,future:[]}}case"undo":{if(s.past.length===0)return s;const t=s.past[s.past.length-1];return{past:s.past.slice(0,-1),present:t,future:[s.present,...s.future]}}case"redo":{if(s.future.length===0)return s;const[t,...i]=s.future;return{past:[...s.past,s.present].slice(-50),present:t,future:i}}case"reset":return{past:[],present:Cl(e.graph),future:[]};default:return s}}function Jet(s){const e=ve.useMemo(()=>Cl(s),[s]),[t,i]=ve.useReducer(Yet,{past:[],present:e,future:[]}),n=ve.useCallback(l=>{i({type:"commit",graph:l})},[]),r=ve.useCallback(()=>{i({type:"undo"})},[]),o=ve.useCallback(()=>{i({type:"redo"})},[]),a=ve.useCallback(l=>{i({type:"reset",graph:l})},[]);return ve.useMemo(()=>({present:t.present,canUndo:t.past.length>0,canRedo:t.future.length>0,commit:n,undo:r,redo:o,reset:a}),[n,o,a,t.future.length,t.past.length,t.present,r])}const ett=Mi.theme({"&":{fontSize:"12px",fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace"},".cm-content":{padding:"10px 12px",minHeight:"160px"},".cm-editor":{background:"var(--mu-surface-base)"},".cm-editor.cm-focused":{outline:"2px solid color-mix(in oklch, var(--mu-color-interactive) 40%, transparent)"},".cm-gutters":{background:"var(--mu-surface-raised)",color:"var(--mu-text-muted)",borderRight:"1px solid color-mix(in oklch, var(--mu-border-subtle) 60%, transparent)"},".cm-activeLine":{background:"color-mix(in oklch, var(--mu-surface-raised) 50%, transparent)"},".cm-selectionBackground":{background:"color-mix(in oklch, var(--mu-color-interactive) 15%, transparent) !important"},".cm-cursor":{borderLeftColor:"var(--mu-text-primary)"},".cm-tooltip":{borderRadius:"12px",border:"1px solid color-mix(in oklch, var(--mu-border-subtle) 80%, transparent)",boxShadow:"0 4px 12px rgba(0,0,0,0.08)",fontSize:"12px",background:"var(--mu-surface-raised)",color:"var(--mu-text-primary)"},".cm-tooltip-autocomplete":{borderRadius:"12px"},".cm-tooltip-autocomplete ul li[aria-selected]":{background:"color-mix(in oklch, var(--mu-color-interactive) 12%, transparent)",color:"var(--mu-text-primary)"},".cm-lintRange-error":{backgroundImage:"none",textDecoration:"underline wavy var(--mu-color-error)"},".cm-lintRange-warning":{backgroundImage:"none",textDecoration:"underline wavy var(--mu-color-warning)"},".cm-diagnostic-error":{borderLeft:"3px solid var(--mu-color-error)"},".cm-diagnostic-warning":{borderLeft:"3px solid var(--mu-color-warning)"},".cm-completionIcon-variable::after":{content:"'x'",display:"inline-block",width:"16px",height:"16px",lineHeight:"16px",textAlign:"center",borderRadius:"50%",background:"color-mix(in oklch, var(--mu-color-interactive) 12%, transparent)",color:"var(--mu-color-interactive)",fontSize:"10px",fontWeight:"700"},".cm-completionIcon-function::after":{content:"'f'",display:"inline-block",width:"16px",height:"16px",lineHeight:"16px",textAlign:"center",borderRadius:"50%",background:"color-mix(in oklch, var(--mu-node-condition) 12%, transparent)",color:"var(--mu-node-condition)",fontSize:"10px",fontWeight:"700",fontStyle:"italic"}}),ttt=K$.define([{tag:lt.keyword,color:"var(--mu-node-condition)"},{tag:lt.string,color:"var(--mu-color-success-text)"},{tag:lt.number,color:"var(--mu-color-warning-text)"},{tag:lt.bool,color:"var(--mu-node-condition)"},{tag:lt.null,color:"var(--mu-text-muted)"},{tag:lt.operator,color:"var(--mu-color-interactive)"},{tag:lt.comment,color:"var(--mu-text-muted)",fontStyle:"italic"},{tag:lt.function(lt.variableName),color:"var(--mu-color-interactive)"},{tag:lt.variableName,color:"var(--mu-text-primary)"},{tag:lt.propertyName,color:"var(--mu-color-interactive-subtle)"},{tag:lt.bracket,color:"var(--mu-text-secondary)"},{tag:lt.special(lt.variableName),color:"var(--mu-color-interactive)",fontWeight:"600"}]);UZe(ttt);const _X=[{name:"sum",signature:"(list) -> number",description:"Sum of all numbers in a list",template:"sum()",group:"Math"},{name:"count",signature:"(list) -> number",description:"Count of elements in a list",template:"count()",group:"Math"},{name:"min",signature:"(a, b, ...) -> number",description:"Minimum value",template:"min()",group:"Math"},{name:"max",signature:"(a, b, ...) -> number",description:"Maximum value",template:"max()",group:"Math"},{name:"mean",signature:"(list) -> number",description:"Arithmetic mean of a list",template:"mean()",group:"Math"},{name:"abs",signature:"(n) -> number",description:"Absolute value",template:"abs()",group:"Math"},{name:"floor",signature:"(n) -> number",description:"Round down to nearest integer",template:"floor()",group:"Math"},{name:"ceiling",signature:"(n) -> number",description:"Round up to nearest integer",template:"ceiling()",group:"Math"},{name:"round up",signature:"(n, scale) -> number",description:"Round up to given scale",template:"round up(, )",group:"Math"},{name:"round down",signature:"(n, scale) -> number",description:"Round down to given scale",template:"round down(, )",group:"Math"},{name:"decimal",signature:"(n, scale) -> number",description:"Round to specified decimal places",template:"decimal(, )",group:"Math"},{name:"modulo",signature:"(dividend, divisor) -> number",description:"Remainder of division",template:"modulo(, )",group:"Math"},{name:"sqrt",signature:"(n) -> number",description:"Square root",template:"sqrt()",group:"Math"},{name:"log",signature:"(n) -> number",description:"Natural logarithm",template:"log()",group:"Math"},{name:"exp",signature:"(n) -> number",description:"Euler's number raised to power",template:"exp()",group:"Math"},{name:"if",signature:"condition then value else alternative",description:"Conditional expression",template:"if then else ",group:"Logic"},{name:"not",signature:"(value) -> boolean",description:"Logical negation",template:"not()",group:"Logic"},{name:"and",signature:"(a, b) -> boolean",description:"Logical conjunction",template:"and(, )",group:"Logic"},{name:"or",signature:"(a, b) -> boolean",description:"Logical disjunction",template:"or(, )",group:"Logic"},{name:"for",signature:"item in collection return expression",description:"Iterate over collection",template:"for in return ",group:"Collection"},{name:"some",signature:"item in collection satisfies condition",description:"Existential quantifier",template:"some in satisfies ",group:"Collection"},{name:"every",signature:"item in collection satisfies condition",description:"Universal quantifier",template:"every in satisfies ",group:"Collection"},{name:"list contains",signature:"(list, element) -> boolean",description:"Check if list contains element",template:"list contains(, )",group:"Collection"},{name:"append",signature:"(list, item) -> list",description:"Append item to list",template:"append(, )",group:"Collection"},{name:"concatenate",signature:"(list1, list2) -> list",description:"Concatenate two lists",template:"concatenate(, )",group:"Collection"},{name:"flatten",signature:"(list) -> list",description:"Flatten nested list",template:"flatten()",group:"Collection"},{name:"distinct values",signature:"(list) -> list",description:"Remove duplicates from list",template:"distinct values()",group:"Collection"},{name:"sort",signature:"(list) -> list",description:"Sort list in ascending order",template:"sort()",group:"Collection"},{name:"reverse",signature:"(list) -> list",description:"Reverse list order",template:"reverse()",group:"Collection"},{name:"index of",signature:"(list, element) -> number",description:"Find index of element in list",template:"index of(, )",group:"Collection"},{name:"union",signature:"(list1, list2) -> list",description:"Union of two lists (deduplicated)",template:"union(, )",group:"Collection"},{name:"sublist",signature:"(list, start, length) -> list",description:"Extract sublist",template:"sublist(, , )",group:"Collection"},{name:"string",signature:"(value) -> string",description:"Convert value to string",template:"string()",group:"Type"},{name:"number",signature:"(from, grouping, decimal) -> number",description:"Parse string to number",template:"number(, , )",group:"Type"},{name:"date",signature:"(from) -> date",description:"Parse string to date",template:"date()",group:"Type"},{name:"time",signature:"(from) -> time",description:"Parse string to time",template:"time()",group:"Type"},{name:"date and time",signature:"(from) -> date-time",description:"Parse string to date-time",template:"date and time()",group:"Type"},{name:"duration",signature:"(from) -> duration",description:"Parse string to duration",template:"duration()",group:"Type"},{name:"string length",signature:"(s) -> number",description:"Length of string",template:"string length()",group:"String"},{name:"substring",signature:"(s, start, length) -> string",description:"Extract substring",template:"substring(, , )",group:"String"},{name:"upper case",signature:"(s) -> string",description:"Convert to uppercase",template:"upper case()",group:"String"},{name:"lower case",signature:"(s) -> string",description:"Convert to lowercase",template:"lower case()",group:"String"},{name:"contains",signature:"(s, match) -> boolean",description:"Check if string contains match",template:"contains(, )",group:"String"},{name:"starts with",signature:"(s, match) -> boolean",description:"Check if string starts with match",template:"starts with(, )",group:"String"},{name:"ends with",signature:"(s, match) -> boolean",description:"Check if string ends with match",template:"ends with(, )",group:"String"},{name:"matches",signature:"(s, pattern) -> boolean",description:"Check if string matches regex pattern",template:"matches(, )",group:"String"},{name:"replace",signature:"(s, pattern, replacement) -> string",description:"Replace pattern in string",template:"replace(, , )",group:"String"},{name:"split",signature:"(s, delimiter) -> list",description:"Split string by delimiter",template:"split(, )",group:"String"},{name:"now",signature:"() -> date-time",description:"Current date and time",template:"now()",group:"Date"},{name:"today",signature:"() -> date",description:"Current date",template:"today()",group:"Date"},{name:"day of week",signature:"(date) -> string",description:"Day of week name",template:"day of week()",group:"Date"},{name:"month of year",signature:"(date) -> string",description:"Month of year name",template:"month of year()",group:"Date"},{name:"years and months duration",signature:"(from, to) -> duration",description:"Duration between two dates in years and months",template:"years and months duration(, )",group:"Date"}],itt=new Set(["true","false","null","if","then","else","for","in","return","some","every","satisfies","not","and","or","between","instance","of","function"]),ntt=new Set(_X.map(s=>s.name)),vCe=(()=>{const s=["Math","Logic","Collection","Type","String","Date"],e=new Map;for(const t of s)e.set(t,[]);for(const t of _X)e.get(t.group).push(t);return s.map(t=>({group:t,functions:e.get(t)}))})(),stt=()=>M.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:M.jsx("path",{d:"M6 3l5 5-5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),rtt=()=>M.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:M.jsx("path",{d:"M3 6l5 5 5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),ott=vCe.reduce((s,e)=>s+e.functions.length,0),att={borderRadius:14,background:"rgba(241, 245, 249, 0.9)",border:"1px solid rgba(148, 163, 184, 0.18)",overflow:"hidden",marginTop:8},ltt={padding:"10px 12px",cursor:"pointer",fontSize:12,fontWeight:600,color:"var(--mu-color-text-secondary)",display:"flex",alignItems:"center",gap:6,userSelect:"none"},ctt={fontSize:10,fontWeight:600,color:"var(--mu-color-text-muted)",background:"color-mix(in oklch, var(--mu-color-border-subtle) 18%, transparent)",borderRadius:8,padding:"1px 6px",marginLeft:"auto"},dtt={padding:"8px 12px 4px",fontSize:11,fontWeight:700,color:"var(--mu-color-text-muted)",textTransform:"uppercase",letterSpacing:"0.04em"},utt={padding:"6px 12px",cursor:"pointer",fontSize:12,borderRadius:8,display:"flex",alignItems:"baseline",gap:6},htt={fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",color:"var(--mu-color-interactive)",fontWeight:600},ftt={color:"var(--mu-color-text-muted)",marginLeft:6,fontSize:11},gtt={maxHeight:280,overflowY:"auto",paddingBottom:6};function ptt({onInsert:s,visible:e}){const[t,i]=ve.useState(!1),[n,r]=ve.useState(null),o=ve.useCallback(()=>{i(a=>!a)},[]);return e?M.jsxs("div",{style:att,children:[M.jsxs("div",{style:ltt,onClick:o,role:"button",tabIndex:0,"aria-expanded":t,children:[t?M.jsx(rtt,{}):M.jsx(stt,{}),M.jsx("span",{children:"FEEL Functions"}),M.jsx("span",{style:ctt,children:ott})]}),t&&M.jsx("div",{style:gtt,children:vCe.map(a=>M.jsxs("div",{children:[M.jsx("div",{style:dtt,children:a.group}),a.functions.map(l=>{const c=`${a.group}:${l.name}`,d=n===c;return M.jsxs("div",{style:{...utt,background:d?"color-mix(in oklch, var(--mu-color-interactive) 6%, transparent)":"transparent"},onClick:()=>s(l.template),onMouseEnter:()=>r(c),onMouseLeave:()=>r(null),title:l.description,role:"button",tabIndex:0,children:[M.jsx("span",{style:htt,children:l.name}),M.jsx("span",{style:ftt,children:l.signature})]},c)})]},a.group))})]}):null}function yCe(s){return fJe({override:[t=>{const i=Oc(s),r=t.state.sliceDoc(0,t.pos).match(/([a-zA-Z_][\w.]*)\.$/);if(r){const d=r[1],u=[];for(const f of i)f.path.startsWith(d+".")&&!f.path.substring(d.length+1).includes(".")&&u.push({label:f.path,type:"variable",detail:f.dataType,info:f.sourceNodeLabel?`From: ${f.sourceNodeLabel}`:void 0,boost:2});if(u.length>0)return{from:t.pos-d.length-1,options:u,validFor:/^[\w.]*$/}}const o=t.matchBefore(/[a-zA-Z_][\w.]*/);if(!o&&!t.explicit)return null;const a=o?o.from:t.pos,l=i.map(d=>({label:d.path,type:"variable",detail:d.dataType,info:d.sourceNodeLabel?`From: ${d.sourceNodeLabel}`:void 0,boost:1})),c=_X.map(d=>({label:d.name,type:"function",detail:d.signature,info:d.description,apply:d.template,boost:0}));return{from:a,options:[...l,...c],validFor:/^[\w.]*$/}}],activateOnTyping:!0})}class wCe{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class dS{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,i){let n=i.facet(w_).markerFilter;n&&(e=n(e,i));let r=e.slice().sort((p,m)=>p.from-m.from||p.to-m.to),o=new YE,a=[],l=0,c=i.doc.iter(),d=0,u=i.doc.length;for(let p=0;;){let m=p==r.length?null:r[p];if(!m&&!a.length)break;let b,w;if(a.length)b=l,w=a.reduce((O,L)=>Math.min(O,L.to),m&&m.from>b?m.from:1e8);else{if(b=m.from,b>u)break;w=m.to,a.push(m),p++}for(;p<r.length;){let O=r[p];if(O.from==b&&(O.to>O.from||O.to==b))a.push(O),p++,w=Math.min(O.to,w);else{w=Math.min(O.from,w);break}}w=Math.min(w,u);let S=!1;if(a.some(O=>O.from==b&&(O.to==w||w==u))&&(S=b==w,!S&&w-b<10)){let O=b-(d+c.value.length);O>0&&(c.next(O),d=b);for(let L=b;;){if(L>=w){S=!0;break}if(!c.lineBreak&&d+c.value.length>L)break;L=d+c.value.length,d+=c.value.length,c.next()}}let k=ICe(a);if(S)o.add(b,b,ks.widget({widget:new Stt(k),diagnostics:a.slice()}));else{let O=a.reduce((L,D)=>D.markClass?L+" "+D.markClass:L,"");o.add(b,w,ks.mark({class:"cm-lintRange cm-lintRange-"+k+O,diagnostics:a.slice(),inclusiveEnd:a.some(L=>L.to>w)}))}if(l=w,l==u)break;for(let O=0;O<a.length;O++)a[O].to<=l&&a.splice(O--,1)}let f=o.finish();return new dS(f,t,vL(f))}}function vL(s,e=null,t=0){let i=null;return s.between(t,1e9,(n,r,{spec:o})=>{if(!(e&&o.diagnostics.indexOf(e)<0))if(!i)i=new wCe(n,r,e||o.diagnostics[0]);else{if(o.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new wCe(i.from,r,i.diagnostic)}}),i}function CCe(s,e){let t=e.pos,i=e.end||t,n=s.state.facet(w_).hideOn(s,t,i);if(n!=null)return n;let r=s.startState.doc.lineAt(e.pos);return!!(s.effects.some(o=>o.is(u8))||s.changes.touchesRange(r.from,Math.max(r.to,i)))}function mtt(s,e){return s.field(Dp,!1)?e:e.concat(Ms.appendConfig.of(ACe))}function _tt(s,e){return{effects:mtt(s,[u8.of(e)])}}const u8=Ms.define(),SCe=Ms.define(),xCe=Ms.define(),Dp=ru.define({create(){return new dS(ks.none,null,null)},update(s,e){if(e.docChanged&&s.diagnostics.size){let t=s.diagnostics.map(e.changes),i=null,n=s.panel;if(s.selected){let r=e.changes.mapPos(s.selected.from,1);i=vL(t,s.selected.diagnostic,r)||vL(t,null,r)}!t.size&&n&&e.state.facet(w_).autoPanel&&(n=null),s=new dS(t,n,i)}for(let t of e.effects)if(t.is(u8)){let i=e.state.facet(w_).autoPanel?t.value.length?h8.open:null:s.panel;s=dS.init(t.value,i,e.state)}else t.is(SCe)?s=new dS(s.diagnostics,t.value?h8.open:null,s.selected):t.is(xCe)&&(s=new dS(s.diagnostics,s.panel,t.value));return s},provide:s=>[hZ.from(s,e=>e.panel),Mi.decorations.from(s,e=>e.diagnostics)]}),btt=ks.mark({class:"cm-lintRange cm-lintRange-active"});function vtt(s,e,t){let{diagnostics:i}=s.state.field(Dp),n,r=-1,o=-1;i.between(e-(t<0?1:0),e+(t>0?1:0),(l,c,{spec:d})=>{if(e>=l&&e<=c&&(l==c||(e>l||t>0)&&(e<c||t<0)))return n=d.diagnostics,r=l,o=c,!1});let a=s.state.facet(w_).tooltipFilter;return n&&a&&(n=a(n,s.state)),n?{pos:r,end:o,above:s.state.doc.lineAt(r).to<o,create(){return{dom:kCe(s,n)}}}:null}function kCe(s,e){return c_("ul",{class:"cm-tooltip-lint"},e.map(t=>TCe(s,t,!1)))}const OCe=s=>{let e=s.state.field(Dp,!1);return!e||!e.panel?!1:(s.dispatch({effects:SCe.of(!1)}),!0)},ytt=Zl.fromClass(class{constructor(s){this.view=s,this.timeout=-1,this.set=!0;let{delay:e}=s.state.facet(w_);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let s=Date.now();if(s<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-s);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(w_);t.length&&wtt(t.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==e.doc&&this.view.dispatch(_tt(this.view.state,i.reduce((n,r)=>n.concat(r))))},i=>{au(this.view.state,i)})}}update(s){let e=s.state.facet(w_);(s.docChanged||e!=s.startState.facet(w_)||e.needsRefresh&&e.needsRefresh(s))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function wtt(s,e,t){let i=[],n=-1;for(let r of s)r.then(o=>{i.push(o),clearTimeout(n),i.length==s.length?e(i):n=setTimeout(()=>e(i),200)},t)}const w_=Li.define({combine(s){return{sources:s.map(e=>e.source).filter(e=>e!=null),...KC(s.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ECe,tooltipFilter:ECe,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,r)=>e(i,n,r)||t(i,n,r):e:t,autoPanel:(e,t)=>e||t})}}});function ECe(s,e){return s?e?(t,i)=>e(s(t,i),i):s:e}function Ctt(s,e={}){return[w_.of({source:s,config:e}),ytt,ACe]}function LCe(s){let e=[];if(s)e:for(let{name:t}of s){for(let i=0;i<t.length;i++){let n=t[i];if(/[a-zA-Z]/.test(n)&&!e.some(r=>r.toLowerCase()==n.toLowerCase())){e.push(n);continue e}}e.push("")}return e}function TCe(s,e,t){var i;let n=t?LCe(e.actions):[];return c_("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},c_("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(s):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((r,o)=>{let a=!1,l=p=>{if(p.preventDefault(),a)return;a=!0;let m=vL(s.state.field(Dp).diagnostics,e);m&&r.apply(s,m.from,m.to)},{name:c}=r,d=n[o]?c.indexOf(n[o]):-1,u=d<0?c:[c.slice(0,d),c_("u",c.slice(d,d+1)),c.slice(d+1)],f=r.markClass?" "+r.markClass:"";return c_("button",{type:"button",class:"cm-diagnosticAction"+f,onclick:l,onmousedown:l,"aria-label":` Action: ${c}${d<0?"":` (access key "${n[o]})"`}.`},u)}),e.source&&c_("div",{class:"cm-diagnosticSource"},e.source))}class Stt extends ZC{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return c_("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class DCe{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=TCe(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class h8{constructor(e){this.view=e,this.items=[];let t=n=>{if(!(n.ctrlKey||n.altKey||n.metaKey)){if(n.keyCode==27)OCe(this.view),this.view.focus();else if(n.keyCode==38||n.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(n.keyCode==40||n.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(n.keyCode==36)this.moveSelection(0);else if(n.keyCode==35)this.moveSelection(this.items.length-1);else if(n.keyCode==13)this.view.focus();else if(n.keyCode>=65&&n.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:r}=this.items[this.selectedIndex],o=LCe(r.actions);for(let a=0;a<o.length;a++)if(o[a].toUpperCase().charCodeAt(0)==n.keyCode){let l=vL(this.view.state.field(Dp).diagnostics,r);l&&r.actions[a].apply(e,l.from,l.to)}}else return;n.preventDefault()}},i=n=>{for(let r=0;r<this.items.length;r++)this.items[r].dom.contains(n.target)&&this.moveSelection(r)};this.list=c_("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i}),this.dom=c_("div",{class:"cm-panel-lint"},this.list,c_("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>OCe(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(Dp).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(Dp),i=0,n=!1,r=null,o=new Set;for(e.between(0,this.view.state.doc.length,(a,l,{spec:c})=>{for(let d of c.diagnostics){if(o.has(d))continue;o.add(d);let u=-1,f;for(let p=i;p<this.items.length;p++)if(this.items[p].diagnostic==d){u=p;break}u<0?(f=new DCe(this.view,d),this.items.splice(i,0,f),n=!0):(f=this.items[u],u>i&&(this.items.splice(i,u-i),n=!0)),t&&f.diagnostic==t.diagnostic?f.dom.hasAttribute("aria-selected")||(f.dom.setAttribute("aria-selected","true"),r=f):f.dom.hasAttribute("aria-selected")&&f.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)n=!0,this.items.pop();this.items.length==0&&(this.items.push(new DCe(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),n=!0),r?(this.list.setAttribute("aria-activedescendant",r.id),this.view.requestMeasure({key:this,read:()=>({sel:r.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:l})=>{let c=l.height/this.list.offsetHeight;a.top<l.top?this.list.scrollTop-=(l.top-a.top)/c:a.bottom>l.bottom&&(this.list.scrollTop+=(a.bottom-l.bottom)/c)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(Dp),i=vL(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:xCe.of(i)})}static open(e){return new h8(e)}}function f8(s,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(s)}</svg>')`}function g8(s){return f8(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${s}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const xtt=Mi.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:g8("#d11")},".cm-lintRange-warning":{backgroundImage:g8("orange")},".cm-lintRange-info":{backgroundImage:g8("#999")},".cm-lintRange-hint":{backgroundImage:g8("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function ktt(s){return s=="error"?4:s=="warning"?3:s=="info"?2:1}function ICe(s){let e="hint",t=1;for(let i of s){let n=ktt(i.severity);n>t&&(t=n,e=i.severity)}return e}class RCe extends Hw{constructor(e){super(),this.diagnostics=e,this.severity=ICe(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,n=e.state.facet(p8).tooltipFilter;return n&&(i=n(i,e.state)),i.length&&(t.onmouseover=()=>Ett(e,t,i)),t}}function Ott(s,e){let t=i=>{let n=e.getBoundingClientRect();if(!(i.clientX>n.left-10&&i.clientX<n.right+10&&i.clientY>n.top-10&&i.clientY<n.bottom+10)){for(let r=i.target;r;r=r.parentNode)if(r.nodeType==1&&r.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",t),s.state.field(NCe)&&s.dispatch({effects:vX.of(null)})}};window.addEventListener("mousemove",t)}function Ett(s,e,t){function i(){let o=s.elementAtHeight(e.getBoundingClientRect().top+5-s.documentTop);s.coordsAtPos(o.from)&&s.dispatch({effects:vX.of({pos:o.from,above:!1,clip:!1,create(){return{dom:kCe(s,t),getCoords:()=>e.getBoundingClientRect()}}})}),e.onmouseout=e.onmousemove=null,Ott(s,e)}let{hoverTime:n}=s.state.facet(p8),r=setTimeout(i,n);e.onmouseout=()=>{clearTimeout(r),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(r),r=setTimeout(i,n)}}function Ltt(s,e){let t=Object.create(null);for(let n of e){let r=s.lineAt(n.from);(t[r.from]||(t[r.from]=[])).push(n)}let i=[];for(let n in t)i.push(new RCe(t[n]).range(+n));return xs.of(i,!0)}const Ttt=lZe({class:"cm-gutter-lint",markers:s=>s.state.field(bX),widgetMarker:(s,e,t)=>{let i=[];return s.state.field(bX).between(t.from,t.to,(n,r,o)=>{n>t.from&&n<t.to&&i.push(...o.diagnostics)}),i.length?new RCe(i):null}}),bX=ru.define({create(){return xs.empty},update(s,e){s=s.map(e.changes);let t=e.state.facet(p8).markerFilter;for(let i of e.effects)if(i.is(u8)){let n=i.value;t&&(n=t(n||[],e.state)),s=Ltt(e.state.doc,n.slice(0))}return s}}),vX=Ms.define(),NCe=ru.define({create(){return null},update(s,e){return s&&e.docChanged&&(s=CCe(e,s)?null:{...s,pos:e.changes.mapPos(s.pos)}),e.effects.reduce((t,i)=>i.is(vX)?i.value:t,s)},provide:s=>N$.from(s)}),Dtt=Mi.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:f8('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:f8('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:f8('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),ACe=[Dp,Mi.decorations.compute([Dp],s=>{let{selected:e,panel:t}=s.field(Dp);return!e||!t||e.from==e.to?ks.none:ks.set([btt.range(e.from,e.to)])}),nZe(vtt,{hideOn:CCe}),xtt],p8=Li.define({combine(s){return KC(s,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function Itt(s={}){return[p8.of(s),bX,Ttt,Dtt,NCe]}function Rtt(s){return[Ctt(t=>{const i=t.state.doc.toString(),n=[];if(!i.trim())return n.push({from:0,to:i.length||0,severity:"info",message:"Expression is empty"}),n;const r=[["(",")"],["[","]"],["{","}"]];for(const[b,w]of r){const S=[];for(let k=0;k<i.length;k++){if(i[k]==='"'){for(k++;k<i.length&&i[k]!=='"';)i[k]==="\\"&&k++,k++;continue}i[k]===b?S.push(k):i[k]===w&&(S.length>0?S.pop():n.push({from:k,to:k+1,severity:"error",message:`Unmatched closing '${w}'`}))}for(const k of S)n.push({from:k,to:k+1,severity:"error",message:`Unmatched opening '${b}'`})}let o=!1,a=0;for(let b=0;b<i.length;b++)i[b]==='"'&&(b===0||i[b-1]!=="\\")&&(o?o=!1:(o=!0,a=b));o&&n.push({from:a,to:a+1,severity:"error",message:"Unclosed string literal"});const l=Oc(s),c=new Set(l.map(b=>b.path)),d=/[a-zA-Z_][\w]*/g;let u;const f=[];let p=-1;for(let b=0;b<i.length;b++)i[b]==='"'&&(b===0||i[b-1]!=="\\")&&(p<0?p=b:(f.push([p,b]),p=-1));const m=b=>f.some(([w,S])=>b>=w&&b<=S);for(;(u=d.exec(i))!==null;){const b=u[0],w=u.index;if(m(w)||itt.has(b)||ntt.has(b)||/^\d/.test(b))continue;let S=b,k=w+b.length;for(;k<i.length&&i[k]===".";){const R=i.substring(k+1).match(/^[a-zA-Z_][\w]*/);if(R)S+="."+R[0],k=k+1+R[0].length,d.lastIndex=k;else break}if(c.has(S))continue;let O=!1;for(const D of c)if(D.startsWith(S+".")||S.startsWith(D+".")){O=!0;break}if(O)continue;let L=!1;for(const D of c)if(D===b||D.startsWith(b+".")){L=!0;break}L||n.push({from:w,to:w+S.length,severity:"warning",message:`Unknown field reference: ${S}`})}return n},{delay:300}),Itt()]}const Ntt={string:{bg:"var(--mu-color-info-bg)",text:"var(--mu-color-interactive)"},number:{bg:"var(--mu-color-info-bg)",text:"var(--mu-node-condition)"},boolean:{bg:"var(--mu-color-warning-bg)",text:"var(--mu-color-warning-text)"},array:{bg:"var(--mu-color-success-bg)",text:"var(--mu-color-success-text)"},object:{bg:"var(--mu-surface-raised)",text:"var(--mu-text-secondary)"}},Att={bg:"var(--mu-surface-raised)",text:"var(--mu-text-secondary)"};function pM({dataType:s}){const e=Ntt[s.toLowerCase()]??Att;return M.jsx("span",{style:{display:"inline-block",fontSize:11,padding:"1px 6px",borderRadius:4,fontWeight:600,backgroundColor:e.bg,color:e.text,lineHeight:"16px",whiteSpace:"nowrap"},children:s.toLowerCase()})}function yL({icon:s,message:e,actionHint:t,onAction:i}){return M.jsxs("div",{style:{background:"var(--mu-surface-raised)",border:"1px solid var(--mu-border-subtle)",borderRadius:8,padding:"16px 20px",display:"flex",flexDirection:"column",alignItems:"center",gap:6,textAlign:"center"},children:[M.jsx("span",{style:{fontSize:16},children:s??"ⓘ"}),M.jsx("span",{style:{color:"var(--mu-text-muted)",fontSize:13},children:e}),t&&i?M.jsx("span",{role:"button",tabIndex:0,onClick:i,onKeyDown:n=>{n.key==="Enter"&&i()},style:{color:"var(--mu-color-interactive)",cursor:"pointer",textDecoration:"underline",fontSize:13},children:t}):null]})}const Mtt={display:"flex",alignItems:"center",gap:6,padding:"4px 8px",borderRadius:4,cursor:"pointer",fontSize:12,color:"var(--mu-text-primary)",transition:"background-color 0.1s"};function MCe({field:s,depth:e,readOnly:t,onInsert:i,defaultExpanded:n=!0}){var p;const r=(((p=s.children)==null?void 0:p.length)??0)>0,[o,a]=ve.useState(n),[l,c]=ve.useState(!1),d=s.path.split("."),u=d[d.length-1],f=d.length>1?d.slice(0,-1).join(".")+".":"";return M.jsxs("div",{children:[M.jsxs("div",{style:{...Mtt,paddingLeft:e*20+8,backgroundColor:l?"var(--mu-surface-raised)":"transparent"},onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[r?M.jsx("span",{role:"button",tabIndex:0,onClick:m=>{m.stopPropagation(),a(!o)},onKeyDown:m=>{m.key==="Enter"&&a(!o)},style:{width:16,height:16,display:"inline-flex",alignItems:"center",justifyContent:"center",cursor:"pointer",fontSize:10,color:"var(--mu-text-muted)",flexShrink:0,userSelect:"none"},children:o?"▼":"▶"}):M.jsx("span",{style:{width:16,flexShrink:0}}),M.jsxs("button",{type:"button",disabled:t,onClick:()=>i(s.path),style:{border:"none",background:"transparent",padding:0,cursor:t?"default":"pointer",fontSize:12,color:"var(--mu-text-primary)",textAlign:"left",fontFamily:"inherit"},children:[f?M.jsx("span",{style:{color:"var(--mu-text-secondary)"},children:f}):null,M.jsx("strong",{children:u})]}),M.jsx(pM,{dataType:s.dataType}),s.sourceNodeLabel?M.jsx("span",{style:{fontSize:11,color:"var(--mu-text-secondary)",marginLeft:"auto"},children:s.sourceNodeLabel}):null]}),r&&o?M.jsx("div",{children:s.children.map(m=>M.jsx(MCe,{field:m,depth:e+1,readOnly:t,onInsert:i,defaultExpanded:n},m.path))}):null]})}const Ptt={rule:"Schema loaded from the registered rule code",flow:"Uses the flow's input schema","decision-table":"Schema from the linked decision table",api:"Schema fetched from external API endpoint",inline:"Schema defined manually in this node"};function m8({tooltip:s}){return M.jsx("span",{title:s,style:{display:"inline-flex",alignItems:"center",marginLeft:4,cursor:"help",color:"var(--mu-text-secondary)"},children:M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:M.jsx("path",{d:"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zm0 2.5a1 1 0 1 1 0 2 1 1 0 0 1 0-2zM6.5 7h2v5h-2V7h1z"})})})}const Ftt={display:"flex",flexDirection:"column",gap:8,padding:"10px 14px",background:"var(--mu-surface-raised)",border:"1px solid var(--mu-border-subtle)",borderRadius:12};function Btt(s){var l,c,d,u,f,p,m,b;const{selectedNode:e,contractLoadState:t,readOnly:i,inspectorTab:n,setInspectorTab:r,showSectionHeader:o=!0}=s,a=e==null?void 0:e.data.contractLayer;return M.jsxs("div",{style:Ztt,children:[o?M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Inspector"}),M.jsx("span",{children:e?`Editing ${_L[e.data.nodeType]}`:"Select a node to edit it."})]}):null,e?M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0},children:[M.jsx("div",{role:"tablist","aria-label":"Node inspector sections",style:Xtt,children:Get(e.data.nodeType).map(w=>M.jsx("button",{role:"tab","aria-selected":w===n,type:"button",style:cit(w===n),onClick:()=>r(w),children:Ket(w)},w))}),n==="basic-info"?M.jsx($tt,{...s}):null,n==="input-data"?M.jsx(Utt,{title:"Input Scope",subtitle:((l=a==null?void 0:a.upstreamScope)==null?void 0:l.title)??"Everything available before this node executes.",contract:a==null?void 0:a.upstreamScope,loadState:t,readOnly:i,onInsert:s.onInsertExpressionToken,groupBySource:!0}):null,n==="data-mapping"?M.jsx(qtt,{nodeType:e.data.nodeType,readOnly:i,upstreamFields:Oc(((c=a==null?void 0:a.upstreamScope)==null?void 0:c.fields)??[]),targetFields:((d=a==null?void 0:a.effectiveInput)==null?void 0:d.fields)??[],rows:((u=a==null?void 0:a.effectiveInput)==null?void 0:u.mappings)??[],onInsert:s.onInsertExpressionToken,onChangeTargetFields:s.onChangeInputContract,onChange:s.onChangeEffectiveMappings,setInspectorTab:r,hasExpression:!!((p=(f=s.selectedExpression)==null?void 0:f.body)!=null&&p.trim())}):null,n==="output-data"?M.jsx(Qtt,{nodeType:e.data.nodeType,contract:a==null?void 0:a.outputContract,upstreamScope:a==null?void 0:a.upstreamScope,issues:(a==null?void 0:a.validationIssues)??[],readOnly:i,onInsert:s.onInsertExpressionToken,onChange:s.onChangeOutputContract}):null,n==="logic"?M.jsx(Wtt,{nodeType:e.data.nodeType,expression:s.selectedExpression,upstreamScope:a==null?void 0:a.upstreamScope,outputContract:a==null?void 0:a.outputContract,liquidOutput:(m=e.data.liquidConfig)==null?void 0:m.outputFormat,readOnly:i,apiBaseUrl:s.apiBaseUrl,onChangeLanguage:s.onUpdateExpressionLanguage,onChangeBody:s.onUpdateExpressionBody,onInsertRef:s.onSetInsertRef,shadowRoot:s.shadowRoot}):null,(b=a==null?void 0:a.validationIssues)!=null&&b.length?M.jsx(BCe,{issues:a.validationIssues}):null,t.status==="error"?M.jsx("div",{style:nit,children:t.message}):null,i?null:M.jsx("button",{type:"button",style:iit,onClick:s.onDeleteNode,children:"Delete Node"})]}):M.jsx("div",{style:{color:"var(--mu-text-muted)",fontSize:13,lineHeight:1.5},children:"Use the palette to add a node, then inspect available input scope, effective mappings, and output contract before publishing."})]})}function $tt(s){var l,c,d,u,f,p,m;const{selectedNode:e,readOnly:t,flowOptions:i,decisionTableOptions:n,selectedDecisionTable:r,decisionTableLoadState:o}=s;if(!e)return M.jsx(M.Fragment,{});const a=e.data.dependsOn??[];return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("label",{style:bd,children:["Label",M.jsx("input",{style:Jl,value:e.data.label,disabled:t,onChange:b=>s.onUpdateLabel(b.target.value)})]}),M.jsxs("label",{style:bd,children:["Rule Code",M.jsx("input",{style:Jl,value:e.data.ruleCode??"",disabled:t,onChange:b=>s.onUpdateRuleCode(b.target.value)})]}),M.jsxs("label",{style:bd,children:["Description",M.jsx("textarea",{style:yX,value:String(e.data.description??""),disabled:t,placeholder:"Describe what this node does for documentation purposes",onChange:b=>s.onUpdateDescription(b.target.value)})]}),M.jsxs("div",{style:Ytt,children:[M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Contract Source",M.jsx(m8,{tooltip:"Determines where this node's input/output schema comes from"})]}),M.jsxs("select",{style:Jl,value:((l=e.data.contractRef)==null?void 0:l.sourceType)??c8(e.data.nodeType),disabled:t,onChange:b=>{var w,S;return s.onUpdateContractRef({sourceType:b.target.value,sourceCode:((w=e.data.contractRef)==null?void 0:w.sourceCode)??e.data.ruleCode??"",label:(S=e.data.contractRef)==null?void 0:S.label})},children:[M.jsx("option",{value:"rule",children:"rule"}),M.jsx("option",{value:"flow",children:"flow"}),M.jsx("option",{value:"decision-table",children:"decision-table"}),M.jsx("option",{value:"api",children:"api"}),M.jsx("option",{value:"inline",children:"inline"})]}),M.jsx("span",{style:{fontSize:11,color:"var(--mu-text-muted)",fontStyle:"italic",marginTop:2,lineHeight:1.4},children:Ptt[((c=e.data.contractRef)==null?void 0:c.sourceType)??c8(e.data.nodeType)]??""})]}),M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Contract Code",M.jsx(m8,{tooltip:"The unique identifier used to look up the contract"})]}),M.jsx("input",{style:Jl,value:((d=e.data.contractRef)==null?void 0:d.sourceCode)??"",disabled:t,onChange:b=>{var w,S;return s.onUpdateContractRef({sourceType:((w=e.data.contractRef)==null?void 0:w.sourceType)??c8(e.data.nodeType),sourceCode:b.target.value,label:(S=e.data.contractRef)==null?void 0:S.label})}})]})]}),M.jsxs("div",{style:Ftt,children:[M.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[M.jsx("span",{style:{marginRight:4},children:"📋"}),M.jsx("strong",{children:"Order:"})," ",e.data.order??"n/a"]}),M.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[M.jsx("span",{style:{marginRight:4},children:"🔗"}),M.jsx("strong",{children:"Depends On:"}),a.length===0?M.jsx("span",{children:"none"}):a.map(b=>M.jsx("button",{type:"button","data-testid":`depends-chip-${b}`,style:oit,onClick:()=>s.onSelectNodeByRuleCode(b),children:b},b))]})]}),e.data.nodeType==="condition"?M.jsx(Htt,{readOnly:t,value:e.data.conditionConfig,onChange:s.onUpdateConditionConfig}):null,e.data.nodeType==="decision-table"?M.jsxs(M.Fragment,{children:[M.jsxs("label",{style:bd,children:["Decision Table",M.jsxs("select",{style:Jl,value:((u=e.data.contractRef)==null?void 0:u.sourceCode)??"",disabled:t,onChange:b=>s.onUpdateDecisionTableCode(b.target.value),children:[M.jsx("option",{value:"",children:"Select decision table"}),n.map(b=>M.jsx("option",{value:b.code,children:b.label},b.code))]})]}),M.jsx(ztt,{table:r,loadState:o})]}):null,e.data.nodeType==="sub-flow"?M.jsxs("label",{style:bd,children:["Target Flow Code",M.jsxs("select",{style:Jl,value:Tp(e.data.subFlowConfig).targetFlowCode??"",disabled:t,onChange:b=>s.onUpdateTargetFlowCode(b.target.value),children:[M.jsx("option",{value:"",children:"Select target flow"}),i.map(b=>M.jsx("option",{value:b.code,children:b.label},b.code))]})]}):null,e.data.nodeType==="liquid"?M.jsxs("label",{style:bd,children:["Liquid Output",M.jsxs("select",{style:Jl,value:gCe(e.data.liquidConfig).outputFormat??"json",disabled:t,onChange:b=>s.onUpdateLiquidOutput(b.target.value),children:[M.jsx("option",{value:"json",children:"json"}),M.jsx("option",{value:"object",children:"object"}),M.jsx("option",{value:"text",children:"text"})]})]}):null,e.data.nodeType==="connector"?M.jsx(Vtt,{config:{connectorType:((f=e.data.connectorConfig)==null?void 0:f.connectorType)??"",connectorConfig:((p=e.data.connectorConfig)==null?void 0:p.connectorConfig)??(e.data.connectorConfig&&("url"in e.data.connectorConfig||"method"in e.data.connectorConfig)?e.data.connectorConfig:{}),credentialId:(m=e.data.connectorConfig)==null?void 0:m.credentialId},catalog:s.connectorCatalog??[],readOnly:t,onChange:s.onUpdateConnectorConfig}):null]})}function Wtt({nodeType:s,expression:e,upstreamScope:t,outputContract:i,liquidOutput:n,readOnly:r,apiBaseUrl:o,onChangeLanguage:a,onChangeBody:l,onInsertRef:c,shadowRoot:d}){const u=ve.useRef(null),f=s==="liquid"||e.language==="liquid"?lit(e.body,(t==null?void 0:t.fields)??[],n??"json"):"",m=Oc((i==null?void 0:i.fields)??[]).filter(S=>{var k;return(k=S.valueExpression)==null?void 0:k.trim()}),b=m.length>0,w=s==="action"||s==="connector";return M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:w&&(b||!e.body.trim())?M.jsxs(M.Fragment,{children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Per-Field Value Expressions"}),M.jsx("span",{children:b?"This node computes output fields using individual FEEL expressions. Edit them in the Output Data tab.":"No value expressions configured yet. Add output fields with expressions in the Output Data tab."})]}),b?M.jsx("div",{style:wX,children:M.jsxs("table",{style:CX,children:[M.jsx("thead",{children:M.jsxs("tr",{children:[M.jsx("th",{style:gg,children:"Output Field"}),M.jsx("th",{style:gg,children:"Type"}),M.jsx("th",{style:gg,children:"Expression"})]})}),M.jsx("tbody",{children:m.map(S=>M.jsxs("tr",{children:[M.jsx("td",{style:pg,children:S.path}),M.jsx("td",{style:pg,children:S.dataType}),M.jsx("td",{style:{...pg,fontFamily:"var(--mu-font-mono)",fontSize:12},children:S.valueExpression})]},S.path))})]})}):null,M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Tip"}),M.jsxs("span",{children:["Switch to the ",M.jsx("strong",{children:"Output Data"})," tab to add or edit value expressions for each output field."]})]})]}):M.jsxs(M.Fragment,{children:[M.jsxs("label",{style:bd,children:["Expression Language",M.jsxs("select",{style:Jl,value:e.language,disabled:r,onChange:S=>a(S.target.value),children:[M.jsx("option",{value:"feel",children:"FEEL"}),M.jsx("option",{value:"javascript",children:"JavaScript"}),M.jsx("option",{value:"scriban",children:"Scriban"}),M.jsx("option",{value:"liquid",children:"Liquid"}),M.jsx("option",{value:"plain-text",children:"Plain Text"})]})]}),(()=>{const S=Oc((t==null?void 0:t.fields)??[]),k=[];return e.language==="feel"&&(k.push(yCe(S)),k.push(Rtt(S))),M.jsxs(M.Fragment,{children:[M.jsxs("div",{style:bd,children:[e.language==="liquid"?"Liquid Template":"Expression",M.jsx(dX,{value:e.body,language:e.language,readOnly:r,onChange:l,onInsertToken:O=>{u.current=O,c==null||c(O)},extensions:k,minHeight:180,root:d})]}),M.jsx(ptt,{visible:e.language==="feel",onInsert:O=>{var L;return(L=u.current)==null?void 0:L.insert(O)}})]})})(),M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Authoring hints"}),M.jsx("span",{children:"Type '.' after a field name or press Ctrl+Space for autocomplete. Click any field in Input Scope to insert at cursor."}),o?M.jsxs("span",{children:["Contract API: ",o]}):null]}),s==="liquid"||e.language==="liquid"?M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Liquid Preview"}),M.jsx("pre",{style:ait,children:f||"Preview is empty."})]}):null]})})}function Htt({readOnly:s,value:e,onChange:t}){const i={successLabel:(e==null?void 0:e.successLabel)??"Valid",failureLabel:(e==null?void 0:e.failureLabel)??"Rejected",failureMessage:(e==null?void 0:e.failureMessage)??""};return M.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Success Label",M.jsx(m8,{tooltip:"Shown on output edges when this condition evaluates to true"})]}),M.jsx("input",{style:Jl,value:i.successLabel,disabled:s,onChange:n=>t({...i,successLabel:n.target.value})})]}),M.jsxs("label",{style:bd,children:[M.jsxs("span",{children:["Failure Label",M.jsx(m8,{tooltip:"Shown on output edges when this condition evaluates to false"})]}),M.jsx("input",{style:Jl,value:i.failureLabel,disabled:s,onChange:n=>t({...i,failureLabel:n.target.value})})]}),M.jsxs("label",{style:bd,children:["Failure Message",M.jsx("textarea",{style:yX,value:i.failureMessage,disabled:s,onChange:n=>t({...i,failureMessage:n.target.value})})]})]})}function Vtt({config:s,catalog:e,readOnly:t,onChange:i}){const n=e.find(a=>a.connectorType===s.connectorType),r=(n==null?void 0:n.requiresCredentials)||(n==null?void 0:n.credentialFields)&&n.credentialFields.length>0;function o(a){i==null||i({...s,...a})}return M.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[M.jsxs("label",{style:bd,children:["Connector Type",M.jsxs("select",{style:Jl,value:s.connectorType??"",disabled:t,onChange:a=>o({connectorType:a.target.value,connectorConfig:{},credentialId:void 0}),children:[M.jsx("option",{value:"",children:"Select connector type"}),e.map(a=>M.jsxs("option",{value:a.connectorType,children:[a.displayName," ",a.category?`(${a.category})`:""]},a.connectorType))]})]}),s.connectorType?M.jsxs(M.Fragment,{children:[n!=null&&n.description?M.jsx("div",{style:uS,children:M.jsx("span",{children:n.description})}):null,M.jsxs("label",{style:bd,children:["Config JSON",M.jsx("textarea",{style:{...yX,fontFamily:"var(--mu-font-mono)",fontSize:13},value:JSON.stringify(s.connectorConfig??{},null,2),disabled:t,onChange:a=>{try{const l=JSON.parse(a.target.value);o({connectorConfig:l})}catch{}}})]}),n!=null&&n.configSchema?M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"Config Schema"}),M.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:11},children:JSON.stringify(n.configSchema,null,2)})]}):null]}):null,r?M.jsxs("label",{style:bd,children:["Credential ID",M.jsx("input",{style:Jl,value:s.credentialId??"",disabled:t,placeholder:"Enter credential identifier",onChange:a=>o({credentialId:a.target.value})})]}):null]})}function ztt({table:s,loadState:e}){return M.jsxs("div",{style:rit,"data-testid":"decision-table-overview",children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Decision Table Schema"}),M.jsx("span",{children:(e==null?void 0:e.status)==="loading"?"Loading decision table columns...":(e==null?void 0:e.status)==="error"?e.message:"Input and output columns drive node contracts and FEEL cell authoring."})]}),s?M.jsxs(M.Fragment,{children:[M.jsxs("div",{children:[M.jsx("strong",{children:s.name})," · v",s.version," · hit policy ",s.hitPolicy]}),s.description?M.jsx("div",{children:s.description}):null,M.jsxs("div",{style:{display:"grid",gap:8},children:[M.jsxs("div",{children:[M.jsx("strong",{children:"Input Columns"}),M.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:s.inputColumns.map(t=>M.jsxs("span",{style:SX,children:[t.label," (",t.dataType,")"]},t.id))})]}),M.jsxs("div",{children:[M.jsx("strong",{children:"Output Columns"}),M.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:s.outputColumns.map(t=>M.jsxs("span",{style:SX,children:[t.label," (",t.dataType,")"]},t.id))})]})]}),M.jsxs("div",{style:uS,children:[M.jsx("strong",{children:"FEEL cell hints"}),M.jsx("span",{children:"Input columns become the effective input contract for this node. Output columns are emitted downstream after the table evaluates."}),M.jsx("span",{children:"Use FEEL row expressions against the input column names exactly as defined here."})]})]}):(e==null?void 0:e.status)==="idle"?M.jsx("span",{children:"Select a decision table to preview its column schema."}):null]})}function Utt({title:s,subtitle:e,contract:t,loadState:i,readOnly:n,onInsert:r,groupBySource:o}){const[a,l]=ve.useState("tree"),[c,d]=ve.useState(!0),u=(t==null?void 0:t.fields)??[],f=Oc(u),p=u.length>0,m=new Map;for(const w of u){const S=o?w.sourceNodeLabel??(w.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",k=m.get(S)??[];k.push(w),m.set(S,k)}const b=new Map;for(const w of f){const S=o?w.sourceNodeLabel??(w.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",k=b.get(S)??[];k.push(w),b.set(S,k)}return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:s}),M.jsx("span",{children:i.status==="loading"?"Loading contract...":e})]}),p?M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[a==="tree"?M.jsx("button",{type:"button",onClick:()=>d(!c),style:{border:"1px solid var(--mu-border-subtle)",background:"transparent",borderRadius:6,padding:"3px 8px",fontSize:11,color:"var(--mu-text-muted)",cursor:"pointer",whiteSpace:"nowrap"},children:c?"Collapse All":"Expand All"}):null,M.jsxs("div",{style:{display:"flex",borderRadius:6,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},children:[M.jsx("button",{type:"button",onClick:()=>l("tree"),style:{border:"none",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:a==="tree"?"var(--mu-color-interactive)":"transparent",color:a==="tree"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Schema Tree"}),M.jsx("button",{type:"button",onClick:()=>l("table"),style:{border:"none",borderLeft:"1px solid var(--mu-border-subtle)",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:a==="table"?"var(--mu-color-interactive)":"transparent",color:a==="table"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Flat Table"})]})]}):null]}),p?a==="tree"?M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,maxHeight:420,overflow:"auto"},children:[...m.entries()].map(([w,S])=>M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[o?M.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)",padding:"4px 8px"},children:w}):null,S.map(k=>M.jsx(MCe,{field:k,depth:0,readOnly:n,onInsert:r,defaultExpanded:c},k.path))]},w))},c?"expanded":"collapsed"):[...b.entries()].map(([w,S])=>M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[o?M.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)"},children:w}):null,M.jsx(FCe,{fields:S,readOnly:n,onInsert:r})]},w)):i.status==="loading"?M.jsx(yL,{icon:"\\u231B",message:"Fetching contract metadata..."}):M.jsx(yL,{message:"No scope metadata available for this node."})]})}function jtt({status:s}){const e={mapped:{icon:"✅",label:"Mapped",bg:"var(--mu-color-success-bg)",text:"var(--mu-color-success-text)"},suggested:{icon:"⚠️",label:"Suggested",bg:"var(--mu-color-warning-bg)",text:"var(--mu-color-warning-text)"},missing:{icon:"❌",label:"Missing",bg:"var(--mu-color-error-bg)",text:"var(--mu-color-error-text)"},"type-mismatch":{icon:"🔄",label:"Type Mismatch",bg:"var(--mu-color-warning-bg)",text:"var(--mu-color-warning-text)"}},t=e[s??"mapped"]??e.mapped;return M.jsxs("span",{style:{display:"inline-flex",alignItems:"center",gap:4,fontSize:12,padding:"2px 8px",borderRadius:10,background:t.bg,color:t.text,fontWeight:500},children:[t.icon," ",t.label]})}function qtt({nodeType:s,readOnly:e,upstreamFields:t,targetFields:i,rows:n,onInsert:r,onChangeTargetFields:o,onChange:a,setInspectorTab:l,hasExpression:c}){const d=s==="action"||s==="sub-flow",u=s==="action";function f(w,S){a(n.map(k=>k.id===w?S(k):k))}function p(){const w=`input.${i.length+1}`;o([...i,{path:w,label:w,dataType:"string",required:!1}])}function m(w,S){const k=i.find(L=>L.path===w);if(!k)return;const O=S(k);o(i.map(L=>L.path===w?O:L)),a(n.map(L=>(L.targetField??L.targetPath)===w?{...L,targetField:O.path,targetPath:O.path,targetDataType:O.dataType,required:O.required}:L))}function b(w){o(i.filter(S=>S.path!==w)),a(n.filter(S=>(S.targetField??S.targetPath)!==w))}return n.length===0?s==="action"&&!c?M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&u?M.jsx("button",{type:"button",style:uh(!1),onClick:p,children:"Add Input Slot"}):null]}),M.jsx(yL,{icon:"info",message:"This node uses code-first logic — no expression-based mapping needed. Input/output contracts come from the registered rule code."})]}):(s==="condition"||s==="liquid")&&!c?M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),M.jsx(yL,{icon:"edit",message:"Write a FEEL expression in the Logic tab to see data flow here.",actionHint:"Go to Logic tab",onAction:()=>l("logic")})]}):M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),M.jsx(yL,{icon:"warning",message:"Expression references fields not found in upstream scope. Check field names in the Logic tab.",actionHint:"Go to Logic tab",onAction:()=>l("logic")})]}):M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Data Flow"}),M.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&u?M.jsx("button",{type:"button",style:uh(!1),onClick:p,children:"Add Input Slot"}):null]}),M.jsx("div",{style:wX,children:M.jsxs("table",{style:CX,children:[M.jsx("thead",{children:M.jsxs("tr",{children:[M.jsx("th",{style:gg,children:"Source"}),M.jsx("th",{style:gg,children:"Target"}),M.jsx("th",{style:gg,children:"Type"}),M.jsx("th",{style:gg,children:"Status"}),M.jsx("th",{style:gg,children:"Transform"}),u?M.jsx("th",{style:gg,children:"Actions"}):null]})}),M.jsx("tbody",{children:n.map(w=>M.jsxs("tr",{children:[M.jsx("td",{style:pg,children:d?M.jsx("input",{list:"upstream-scope-fields",style:Jl,value:w.sourcePath,disabled:e,onChange:S=>f(w.id,k=>({...k,sourcePath:S.target.value}))}):M.jsx("button",{type:"button",style:wL,onClick:()=>r(w.sourcePath),disabled:e||!w.sourcePath,children:w.sourcePath||"unmapped"})}),M.jsx("td",{style:pg,children:u?M.jsx("input",{style:Jl,value:w.targetField??w.targetPath,disabled:e,onChange:S=>m(w.targetField??w.targetPath,k=>({...k,path:S.target.value,label:S.target.value}))}):w.targetField??w.targetPath}),M.jsx("td",{style:pg,children:u?M.jsx("input",{style:Jl,value:w.targetDataType??"string",disabled:e,onChange:S=>m(w.targetField??w.targetPath,k=>({...k,dataType:S.target.value}))}):M.jsx(pM,{dataType:`${w.sourceDataType??"unknown"} → ${w.targetDataType??"unknown"}`})}),M.jsxs("td",{style:pg,children:[M.jsx(jtt,{status:w.status}),w.required?M.jsx("span",{style:{fontSize:10,color:"var(--mu-color-error)",marginLeft:4,fontWeight:600},children:"required"}):null]}),M.jsx("td",{style:pg,children:d?M.jsx("input",{style:Jl,value:w.transform??w.transformSuggestion??"",disabled:e,onChange:S=>f(w.id,k=>({...k,transform:S.target.value}))}):w.transformSuggestion??w.transform??"—"}),u?M.jsx("td",{style:pg,children:M.jsx("button",{type:"button",style:wL,disabled:e,onClick:()=>b(w.targetField??w.targetPath),children:"Remove"})}):null]},w.id))})]})}),M.jsx("datalist",{id:"upstream-scope-fields",children:t.map(w=>M.jsx("option",{value:w.path},w.path))}),i.length?M.jsxs("div",{style:uS,children:[M.jsx("strong",{title:"Fields this node declares it needs — must be provided by upstream nodes or flow input",children:"Required input slots"}),M.jsx("span",{children:i.filter(w=>w.required).map(w=>w.path).join(", ")||"No required fields declared."})]}):null]})}function PCe({title:s,count:e,defaultExpanded:t,headerRight:i,children:n}){const[r,o]=ve.useState(t);return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsxs("div",{role:"button",tabIndex:0,onClick:()=>o(!r),onKeyDown:a=>{(a.key==="Enter"||a.key===" ")&&(a.preventDefault(),o(!r))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[M.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:r?"▼":"▶"}),M.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:s}),e!==void 0?M.jsxs("span",{style:{background:"var(--mu-border-subtle)",padding:"2px 8px",borderRadius:10,fontSize:11,color:"var(--mu-text-secondary)",fontWeight:600},children:[e," field",e!==1?"s":""]}):null]}),i]}),r?n:null]})}function Qtt({nodeType:s,contract:e,upstreamScope:t,issues:i,readOnly:n,onInsert:r,onChange:o}){if(s==="end")return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[M.jsxs("div",{style:vv,children:[M.jsx("strong",{children:"Final Scope"}),M.jsx("span",{children:"Everything guaranteed to be available when the flow reaches this end node."})]}),M.jsx(FCe,{fields:Oc((t==null?void 0:t.fields)??[]),readOnly:n,onInsert:r})]});const a=s==="condition"||s==="action",l=Oc((e==null?void 0:e.fields)??[]),c=l.filter(k=>!k.isResultPayload),d=l.filter(k=>k.isResultPayload),p=s==="condition"||s==="action";function m(k,O){const L=l.map(D=>!D.isResultPayload&&c.indexOf(D)===k?O(D):D);o(L)}function b(k){const O=c[k];o(l.filter(L=>L!==O))}function w(){const k=`custom.${c.length+1}`;o([...l,{path:k,label:k,dataType:"string",required:!1}])}const S=(()=>{const k=[];return t&&k.push(yCe(Oc(t.fields))),k})();return M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[M.jsx(PCe,{title:"Custom Output Fields",count:c.length,defaultExpanded:!0,headerRight:!n&&a?M.jsx("button",{type:"button",style:uh(!1),onClick:w,children:"Add Field"}):void 0,children:c.length===0?M.jsx(yL,{message:"No custom output fields defined.",actionHint:a&&!n?"Add a field to compute values for downstream nodes.":void 0,onAction:a&&!n?w:void 0}):M.jsx("div",{style:Jtt,children:c.map((k,O)=>M.jsxs("div",{style:eit,children:[M.jsxs("div",{style:$Ce,children:[a?M.jsx("input",{style:{...Jl,flex:"1 1 0%",minWidth:0},value:k.path,disabled:n,placeholder:"field.path",title:"Dotted path where this value is stored in the FactBag",onChange:L=>m(O,D=>({...D,path:L.target.value,label:L.target.value}))}):M.jsx("button",{type:"button",style:{...wL,flex:"1 1 0%",minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},onClick:()=>r(k.path),disabled:n,children:k.path}),a&&!n?M.jsx("button",{type:"button",style:{...wL,color:"var(--mu-color-error-text)",flexShrink:0,fontSize:"var(--mu-text-xs)"},onClick:()=>b(O),title:"Remove this field",children:"delete"}):null]}),M.jsxs("div",{style:$Ce,children:[a&&!n?M.jsx("select",{style:tit,value:k.dataType,title:"Data type of the output value",onChange:L=>m(O,D=>({...D,dataType:L.target.value})),children:["string","number","boolean","object","array"].map(L=>M.jsx("option",{value:L,children:L},L))}):M.jsx(pM,{dataType:k.dataType}),p?M.jsx("div",{style:{flex:"1 1 0%",minWidth:0},children:a?M.jsx(dX,{value:k.valueExpression??"",language:"feel",readOnly:n,singleLine:!0,placeholderText:"e.g. command.details.length",onChange:L=>m(O,D=>({...D,valueExpression:L,runtimeWritten:L.trim().length>0})),extensions:S,root:void 0}):M.jsx("span",{style:{fontFamily:"var(--mu-font-mono)",fontSize:"var(--mu-text-xs)"},children:k.valueExpression??"—"})}):null]})]},`output-custom-${O}`))})}),d.length>0?M.jsx(PCe,{title:"Auto-Generated Results",count:d.length,defaultExpanded:!1,children:M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,padding:"4px 0"},children:d.map((k,O)=>M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",fontSize:12},children:[M.jsx("button",{type:"button",style:{...wL,flex:1,textAlign:"left"},onClick:()=>r(k.path),disabled:n,children:k.path}),M.jsx(pM,{dataType:k.dataType})]},`output-auto-${O}`))})}):null,i.length?M.jsx(BCe,{issues:i.filter(k=>k.severity!=="info")}):null]})}function FCe({fields:s,readOnly:e,onInsert:t}){return M.jsx("div",{style:wX,children:M.jsxs("table",{style:CX,children:[M.jsx("thead",{children:M.jsxs("tr",{children:[M.jsx("th",{style:gg,children:"Path"}),M.jsx("th",{style:{...gg,width:"15%"},children:"Type"}),M.jsx("th",{style:gg,children:"Description"})]})}),M.jsx("tbody",{children:s.map(i=>M.jsxs("tr",{children:[M.jsx("td",{style:pg,children:M.jsx("button",{type:"button",style:wL,onClick:()=>t(i.path),disabled:e,children:i.path})}),M.jsx("td",{style:pg,children:M.jsx(pM,{dataType:i.dataType})}),M.jsx("td",{style:pg,title:i.description??i.label,children:i.description??i.label})]},`${i.sourceNodeId??"scope"}:${i.path}`))})]})})}const Gtt=M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-error)",style:{flexShrink:0,marginTop:1},children:M.jsx("path",{d:"M8 1a7 7 0 1 0 0 14A7 7 0 0 0 8 1zm2.97 4.03a.75.75 0 0 1 0 1.06L9.06 8l1.91 1.91a.75.75 0 1 1-1.06 1.06L8 9.06l-1.91 1.91a.75.75 0 1 1-1.06-1.06L6.94 8 5.03 6.09a.75.75 0 0 1 1.06-1.06L8 6.94l1.91-1.91a.75.75 0 0 1 1.06 0z"})}),Ktt=M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-warning)",style:{flexShrink:0,marginTop:1},children:M.jsx("path",{d:"M8.982 1.566a1.13 1.13 0 0 0-1.96 0L.165 13.233c-.457.778.091 1.767.98 1.767h13.713c.889 0 1.438-.99.98-1.767L8.982 1.566zM8 5c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 5.995A.905.905 0 0 1 8 5zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"})});function BCe({issues:s}){return M.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:s.map(e=>{const t=e.severity==="error";return M.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:8,padding:"8px 10px",borderRadius:8,borderLeft:t?"3px solid var(--mu-color-error)":"3px solid var(--mu-color-warning)",background:t?"var(--mu-color-error-bg)":"var(--mu-color-warning-bg)",fontSize:"var(--mu-text-sm)"},children:[t?Gtt:Ktt,M.jsxs("span",{style:{color:t?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",lineHeight:"20px"},children:[M.jsx("strong",{children:e.code})," ",e.message,e.fieldPath?M.jsxs("span",{style:{opacity:.7,marginLeft:4},children:["(",e.fieldPath,")"]}):null]})]},`${e.code}:${e.message}:${e.fieldPath??""}`)})})}const vv={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-text-muted)"},Ztt={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",padding:"var(--mu-space-md)",width:"100%",minWidth:0,borderRadius:18,background:"var(--mu-surface-sidebar)",border:"1px solid var(--mu-border-subtle)"},Xtt={display:"flex",flexWrap:"nowrap",overflowX:"auto",gap:0,paddingBottom:0,borderBottom:"1px solid var(--mu-border-subtle)",marginBottom:"var(--mu-space-xs)"},bd={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-medium)",color:"var(--mu-text-label)"},Jl={borderRadius:8,border:"1px solid var(--mu-border-input)",padding:"var(--mu-space-xs) var(--mu-space-sm)",fontSize:"var(--mu-text-xs)",width:"100%"},yX={...Jl,minHeight:116,resize:"vertical"},wX={borderRadius:12,border:"1px solid var(--mu-border-subtle)",overflow:"hidden",overflowY:"auto",flex:"1 1 auto",minHeight:120,maxHeight:"50vh",minWidth:0,background:"var(--mu-surface-base)"},CX={width:"100%",tableLayout:"fixed",borderCollapse:"collapse",fontSize:12},gg={position:"sticky",top:0,background:"var(--mu-surface-raised)",textAlign:"left",padding:"var(--mu-space-xs) var(--mu-space-xs)",fontSize:"var(--mu-text-xs)",color:"var(--mu-text-secondary)",borderBottom:"1px solid var(--mu-border-subtle)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},pg={padding:"8px 6px",fontSize:12,color:"var(--mu-text-primary)",borderBottom:"1px solid var(--mu-border-subtle)",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",verticalAlign:"middle"},wL={border:"none",background:"transparent",color:"var(--mu-color-interactive)",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,textAlign:"left"},Ytt={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"var(--mu-space-sm)"},Jtt={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",overflowY:"auto",maxHeight:"50vh",minHeight:80},eit={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",padding:"var(--mu-space-sm)",borderRadius:10,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-base)"},$Ce={display:"flex",alignItems:"center",gap:"var(--mu-space-xs)",minWidth:0},tit={fontSize:"var(--mu-text-xs)",padding:"2px 4px",borderRadius:6,border:"1px solid var(--mu-border-input)",background:"var(--mu-surface-raised)",cursor:"pointer",flexShrink:0},iit={borderRadius:12,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"12px 14px",fontWeight:600},uS={display:"flex",flexDirection:"column",gap:4,padding:12,borderRadius:14,background:"var(--mu-surface-raised)",color:"var(--mu-text-secondary)",fontSize:12,lineHeight:1.5},nit={borderRadius:12,border:"1px solid var(--mu-color-error-border)",background:"var(--mu-color-error-bg)",color:"var(--mu-color-error-text)",padding:"10px 12px",fontSize:12},sit={borderRadius:12,border:"1px solid var(--mu-color-warning-border)",background:"var(--mu-color-warning-bg)",color:"var(--mu-color-warning-text)",padding:"10px 12px",fontSize:12},rit={borderRadius:14,border:"1px solid var(--mu-border-subtle)",background:"var(--mu-surface-base)",padding:12,display:"flex",flexDirection:"column",gap:8,fontSize:12,color:"var(--mu-text-label)"},SX={borderRadius:999,padding:"4px 8px",background:"var(--mu-color-interactive-subtle)",color:"var(--mu-text-primary)",fontSize:11,fontWeight:600},oit={...SX,border:"none",cursor:"pointer"},ait={margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:12};function lit(s,e,t){const i=Oc(e),n=new Map(i.map(o=>[o.path,o.example??`<${o.path}>`])),r=s.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*\}\}/g,(o,a)=>String(n.get(a)??`<${a}>`));return r}function uh(s){return{borderRadius:12,border:s?"1px solid var(--mu-color-interactive-border)":"1px solid var(--mu-border-input)",background:s?"var(--mu-color-interactive-subtle)":"var(--mu-surface-raised)",color:"var(--mu-text-primary)",padding:"10px 12px",fontWeight:600,minHeight:44}}function cit(s){return{borderRadius:0,border:"none",borderBottom:s?"2px solid var(--mu-color-interactive)":"2px solid transparent",background:"transparent",color:s?"var(--mu-color-interactive)":"var(--mu-text-muted)",fontWeight:s?600:400,fontSize:"var(--mu-text-sm)",padding:"var(--mu-space-xs) var(--mu-space-sm)",cursor:"pointer",whiteSpace:"nowrap",transition:"border-color 0.15s, color 0.15s",outline:"none",minHeight:44}}function dit({groups:s,loading:e,readOnly:t,onAddRule:i,onDragStart:n}){const[r,o]=ve.useState(""),a=r.trim().toLowerCase(),l=ve.useMemo(()=>[...s].sort((d,u)=>(d.category??"").localeCompare(u.category??"")).map(d=>({...d,items:[...d.items].filter(u=>hit(u,a)).sort((u,f)=>(u.displayName??"").localeCompare(f.displayName??""))})).filter(d=>d.items.length>0),[s,a]);return M.jsxs("div",{style:fit,children:[M.jsxs("div",{style:git,children:[M.jsx("strong",{children:"Rule Catalog"}),M.jsx("span",{children:"Load reusable rule templates from the control plane and drop them into the flow."})]}),M.jsxs("label",{style:pit,children:["Search rules",M.jsx("input",{"data-testid":"catalog-search-input",style:mit,value:r,onChange:c=>o(c.target.value),placeholder:"Search by name, code, tag or description",disabled:e})]}),e?M.jsx("div",{"data-testid":"catalog-loading-state",style:WCe,children:"Loading rule catalog..."}):null,!e&&l.length===0?M.jsx("div",{"data-testid":"catalog-empty-state",style:WCe,children:a?"No rules match the current search.":"No rules available."}):null,e?null:l.map(c=>M.jsxs("div",{"data-testid":`catalog-group-${c.category}`,style:_it,children:[M.jsx("span",{style:bit,title:c.category,children:uit(c.category)}),c.items.map(d=>M.jsx("button",{type:"button",style:vit,"data-testid":`palette-rule-${d.code}`,draggable:!t,onClick:()=>i(d),onDragStart:u=>n(u,d),disabled:t,children:M.jsxs("span",{style:yit,children:[M.jsx("strong",{children:d.displayName}),M.jsx("span",{style:wit,children:d.code}),d.description?M.jsx("span",{style:Cit,children:d.description}):null,d.tags.length>0?M.jsx("span",{style:Sit,children:d.tags.join(" · ")}):null]})},d.code))]},c.category))]})}function uit(s){const e=s.split(".");return e.length<=2?s:e.slice(-2).join(".")}function hit(s,e){return e?[s.code,s.displayName,s.description??"",...s.tags??[]].join(" ").toLowerCase().includes(e):!0}const fit={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},git={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-color-text-muted)"},pit={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-xs)",color:"var(--mu-color-text-secondary)",fontWeight:600},mit={borderRadius:12,border:"1px solid rgba(148, 163, 184, 0.32)",background:"var(--mu-color-surface-base)",color:"var(--mu-color-text-primary)",minHeight:40,padding:"10px 12px",fontSize:13},WCe={borderRadius:14,border:"1px dashed rgba(148, 163, 184, 0.35)",background:"rgba(248, 250, 252, 0.9)",color:"var(--mu-color-text-muted)",padding:"12px 14px",fontSize:13,lineHeight:1.5},_it={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},bit={fontSize:12,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--mu-color-text-secondary)"},vit={borderRadius:14,border:"1px solid color-mix(in oklch, var(--mu-color-interactive) 14%, transparent)",background:"color-mix(in oklch, var(--mu-color-interactive) 8%, transparent)",color:"var(--mu-color-text-primary)",padding:"11px 12px",textAlign:"left",fontWeight:600},yit={display:"flex",flexDirection:"column",gap:4},wit={fontSize:"var(--mu-text-xs)",fontFamily:"var(--mu-font-mono)",fontWeight:500,color:"var(--mu-color-text-secondary)"},Cit={fontSize:12,fontWeight:500,color:"var(--mu-color-text-muted)"},Sit={fontSize:"var(--mu-text-xs)",color:"var(--mu-color-interactive)"},xit={canvasGradient:"radial-gradient(circle at top left, color-mix(in oklch, var(--mu-color-interactive) 12%, transparent), transparent 38%), linear-gradient(180deg, var(--mu-surface-canvas), var(--mu-surface-base))",sidebarBg:"var(--mu-surface-sidebar)",sidebarBorder:"1px solid var(--mu-border-subtle)",sidebarOpenBg:"var(--mu-surface-raised)",sidebarOpenBorder:"1px solid var(--mu-border-default)",sidebarOpenShadow:"var(--mu-shadow-sidebar)",sidebarHeaderColor:"var(--mu-text-primary)",nodeBg:"var(--mu-surface-base)",nodeBorder:"1px solid var(--mu-border-subtle)",nodeShadow:"var(--mu-shadow-node)",nodeText:"var(--mu-text-primary)",nodeSubtext:"var(--mu-text-secondary)",nodeMutedText:"var(--mu-text-muted)",inspectorBg:"var(--mu-surface-sidebar)",inspectorBorder:"1px solid var(--mu-border-subtle)",inputBg:"var(--mu-surface-input)",inputBorder:"1px solid var(--mu-border-input)",inputText:"var(--mu-text-primary)",labelColor:"var(--mu-text-label)",overlayBg:"var(--mu-surface-overlay)",overlayBorder:"1px solid var(--mu-border-default)",overlayShadow:"var(--mu-shadow-overlay)",overlayItemBg:"var(--mu-surface-raised)",overlayItemBorder:"1px solid var(--mu-border-subtle)",overlayItemSelectedBg:"var(--mu-color-selected-bg)",overlayItemSelectedBorder:"1px solid var(--mu-color-selected-border)",backdropBg:"var(--mu-surface-backdrop)",dialogBg:"var(--mu-surface-dialog)",dialogBorder:"1px solid var(--mu-border-default)",dialogShadow:"var(--mu-shadow-dialog)",textPrimary:"var(--mu-text-primary)",textSecondary:"var(--mu-text-secondary)",textMuted:"var(--mu-text-muted)",paletteBtnBorderAlpha:"22",paletteBtnBgAlpha:"10",chevronBg:"var(--mu-border-subtle)",chevronColor:"var(--mu-text-secondary)",sectionDescColor:"var(--mu-text-muted)",hintBg:"var(--mu-surface-raised)",hintBorder:"1px solid var(--mu-border-subtle)",hintText:"var(--mu-text-label)",errorBg:"var(--mu-color-error-bg)",errorBorder:"1px solid var(--mu-color-error-border)",errorText:"var(--mu-color-error-text)",warningBg:"var(--mu-color-warning-bg)",warningBorder:"1px solid var(--mu-color-warning-border)",warningText:"var(--mu-color-warning-text)",deleteBg:"var(--mu-color-error-bg)",deleteBorder:"1px solid var(--mu-color-error-border)",deleteText:"var(--mu-color-error-text)",actionPrimaryBorder:"1px solid var(--mu-color-interactive-border)",actionPrimaryBg:"var(--mu-color-interactive-subtle)",actionSecondaryBorder:"1px solid var(--mu-border-input)",actionSecondaryBg:"var(--mu-surface-raised)",validationErrorBg:"var(--mu-color-error-bg)",validationErrorBorder:"1px solid var(--mu-color-error-border)",validationErrorText:"var(--mu-color-error-text)",validationWarnBg:"var(--mu-color-warning-bg)",validationWarnBorder:"1px solid var(--mu-color-warning-border)",validationWarnText:"var(--mu-color-warning-text)",licenseBg:"var(--mu-color-warning-bg)",licenseBorder:"1px solid var(--mu-color-warning-border)",licenseText:"var(--mu-color-warning-text)",edgeLabelBg:"var(--mu-edge-label-bg)"};function xX(s){return xit}const kX={trigger:"M6 2.5v11l5.5-5.5z",condition:"M8 1L15 8 8 15 1 8zm0 2.83L3.83 8 8 12.17 12.17 8z",action:"M7 2v5H2v2h5v5h2V9h5V7H9V2z","decision-table":"M2 3h12v1.5H2zm0 3.5h12V8H2zm0 3.5h12V11.5H2zm0 3.5h12V15H2z","sub-flow":"M3 3h4v4H3zm6 0h4v4H9zM5 7v2h6V7M8 9v3M5 12h6",liquid:"M8 1C5.8 5.3 3 7.4 3 10.5 3 13 5.2 15 8 15s5-2 5-4.5C13 7.4 10.2 5.3 8 1z",connector:"M2 4h4v3H2zm8 0h4v3h-4zM4 7v2h1v1H4v2h2v-2h1V9h2v2h1v2h2v-2h-1V9H9.5V7m-5 0",end:"M8 2a6 6 0 100 12A6 6 0 008 2zm0 3a3 3 0 110 6 3 3 0 010-6z"},kit={trigger:"Entry point for the rule flow",condition:"Evaluate a rule with pass/fail routing",action:"Execute side effects or transformations","decision-table":"Evaluate a FEEL decision table","sub-flow":"Delegate to another rule flow",liquid:"Transform data with Liquid templates",connector:"Integrate with external services via connectors",end:"Terminal node — flow completes here"},HCe={always:"var(--mu-edge-always)","on-true":"var(--mu-edge-on-true)","on-false":"var(--mu-edge-on-false)","on-error":"var(--mu-edge-on-error)"},Oit=HCe;function VCe(s,e){const t=Cl(s),i=Eit(t,e);return{...t,nodes:t.nodes.map(n=>{var r,o,a,l;return{...n,data:{...n.data,contractLayer:i.get(n.id),dependsOn:n.data.dependsOn??((o=(r=e.nodeContractsById)==null?void 0:r.get(n.id))==null?void 0:o.dependsOn)??[],order:n.data.order??((l=(a=e.nodeContractsById)==null?void 0:a.get(n.id))==null?void 0:l.order)}}})}}function OX(s,e){const t=CL(s,e),i=VCe(t.graph,e),n=i.nodes.flatMap(r=>{var o;return((o=r.data.contractLayer)==null?void 0:o.validationIssues)??[]});return{graph:i,issues:[...t.issues,...n],isValid:t.isValid&&n.every(r=>r.severity!=="error")}}function CL(s,e){var p,m;const t=Cl(s),i=t.nodes.filter(b=>b.type!=="trigger"&&b.type!=="end"),n=new Set(i.map(b=>b.id)),r=new Map(i.filter(b=>b.ruleCode).map(b=>[b.ruleCode,b.id])),o=new Map,a=new Map,l=b=>{o.has(b)||o.set(b,new Set),a.has(b)||a.set(b,0)},c=(b,w)=>{if(b===w||!n.has(b)||!n.has(w))return;l(b),l(w);const S=o.get(b);S.has(w)||(S.add(w),a.set(w,(a.get(w)??0)+1))};for(const b of i){l(b.id);const w=b.data.dependsOn??((m=(p=e.nodeContractsById)==null?void 0:p.get(b.id))==null?void 0:m.dependsOn)??[];for(const S of w){const k=r.get(S);k&&c(k,b.id)}}for(const b of t.edges)b.edgeType!=="on-error"&&c(b.source,b.target);const d=[...i].sort((b,w)=>{var O,L,D,R;const S=b.data.order??((L=(O=e.nodeContractsById)==null?void 0:O.get(b.id))==null?void 0:L.order)??Number.MAX_SAFE_INTEGER,k=w.data.order??((R=(D=e.nodeContractsById)==null?void 0:D.get(w.id))==null?void 0:R.order)??Number.MAX_SAFE_INTEGER;return S!==k?S-k:(b.label??"").localeCompare(w.label??"")}).filter(b=>(a.get(b.id)??0)===0).map(b=>b.id),u=[];for(;d.length>0;){const b=d.shift();u.push(b);const w=[...o.get(b)??[]].sort((S,k)=>S.localeCompare(k));for(const S of w){const k=(a.get(S)??0)-1;a.set(S,k),k===0&&d.push(S)}}if(u.length!==i.length)return{graph:t,issues:[{code:"MRF008",severity:"error",message:"Rule flow contains a dependency cycle or invalid ordering edge."}],isValid:!1};const f=new Map(u.map((b,w)=>[b,w+1]));return{graph:{...t,nodes:t.nodes.map(b=>{var w,S;return n.has(b.id)?{...b,data:{...b.data,order:f.get(b.id)??b.data.order,dependsOn:b.data.dependsOn??((S=(w=e.nodeContractsById)==null?void 0:w.get(b.id))==null?void 0:S.dependsOn)??[]}}:b})},issues:[],isValid:!0}}function Eit(s,e){const t=new Map(s.nodes.map(b=>[b.id,b])),i=new Map;for(const b of s.edges){const w=i.get(b.target)??[];w.push(b),i.set(b.target,w)}const n=new Map,r=new Set,o=b=>b.type,a=Lit(s,e),l=(b,w)=>{var R,A;const S=t.get(b);if(!S)return[];const k=m(S),O=Qw(((R=k.upstreamScope)==null?void 0:R.fields)??[]),L=Qw(((A=k.outputContract)==null?void 0:A.fields)??[]);if(o(S)!=="condition")return yv([...O,...UCe(L)]);const D=w==="on-false"?L.filter(F=>F.isResultPayload):L;return yv([...O,...UCe(D)])},c=b=>{var O,L,D,R;const w=b.data.dependsOn??((L=(O=e.nodeContractsById)==null?void 0:O.get(b.id))==null?void 0:L.dependsOn)??[];if(w.length>0){const A=s.nodes.filter(F=>F.ruleCode&&w.includes(F.ruleCode));return yv(A.flatMap(F=>l(F.id,"always")))}const S=b.data.order??((R=(D=e.nodeContractsById)==null?void 0:D.get(b.id))==null?void 0:R.order)??Number.MAX_SAFE_INTEGER,k=s.nodes.filter(A=>{var $,Y;const F=A.data.order??((Y=($=e.nodeContractsById)==null?void 0:$.get(A.id))==null?void 0:Y.order)??Number.MAX_SAFE_INTEGER;return A.id!==b.id&&F<S});return yv(k.flatMap(A=>l(A.id,"always")))},d=b=>{if(b.type==="trigger")return{contractName:`${e.flowCode??"flow"}_trigger_input`,title:"Input Scope",fields:a.map(k=>qw(k,{sourceKind:"flow-input"}))};const w=i.get(b.id)??[],S=w.length>0?w.flatMap(k=>l(k.source,k.edgeType)):c(b);return S.length===0&&S.push(...a.map(k=>qw(k,{sourceKind:"flow-input"}))),{contractName:`${b.ruleCode??b.id}_input_scope`,title:"Input Scope",fields:yv(S)}},u=(b,w)=>{var j,G,V,J,re,le;const S=(j=e.nodeContractsById)==null?void 0:j.get(b.id),k=b.type==="sub-flow"?(G=e.flowContractsByCode)==null?void 0:G.get(Tp(b.data.subFlowConfig).targetFlowCode??""):void 0,O=((V=b.data.contractOverride)==null?void 0:V.responseFields)??[],L=((J=k==null?void 0:k.responseContract)==null?void 0:J.fields)??((re=b.data.responseContract)==null?void 0:re.fields)??((le=S==null?void 0:S.responseDelta)==null?void 0:le.fields)??[],R=(Array.isArray(b.data.outputFields)?b.data.outputFields:[]).map(ie=>({path:ie.path,label:ie.path,dataType:ie.dataType??"string",valueExpression:ie.valueExpression})),A=yv([...Qw(L),...R]),F=O.length>0?Dit(A,O):A,Y=(b.type==="condition"&&!b.ruleCode?F.filter(ie=>{var oe;return ie.runtimeWritten||((oe=ie.valueExpression)==null?void 0:oe.trim())}):F).map(ie=>{var oe;return qw(ie,{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:b.type==="sub-flow"?"sub-flow-output":"node-output",runtimeWritten:b.ruleCode?!0:b.type==="condition"?!!(ie.runtimeWritten??((oe=ie.valueExpression)==null?void 0:oe.trim())):ie.runtimeWritten??!0})});if(b.type==="trigger"){const ie=a.map(oe=>qw(oe,{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"flow-input",runtimeWritten:!0}));return{contractName:`${b.id}_output_contract`,title:"Output Contract",fields:yv(ie)}}if(b.type!=="condition")return{contractName:`${b.ruleCode??b.id}_output_contract`,title:"Output Contract",fields:yv(Tit(b,Y))};const q=[qw({path:"result.isPass",label:"isPass",dataType:"boolean",required:!0},{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),qw({path:"result.message",label:"message",dataType:"string"},{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),qw({path:"result.errorCode",label:"errorCode",dataType:"string"},{sourceNodeId:b.id,sourceNodeLabel:b.label,sourceNodeType:b.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0})];return{contractName:`${b.ruleCode??b.id}_output_contract`,title:"Output Contract",fields:yv([...q,...Y])}},f=(b,w)=>{var D,R,A,F,$;const S=Oc(w.fields),k=b.type==="sub-flow"?Tp(b.data.subFlowConfig).inputMappings:b.data.inputMappings??[];if(b.type==="sub-flow"){const Y=Tp(b.data.subFlowConfig).childTriggerSchema,q=Oc((Y==null?void 0:Y.fields)??[]);return{contractName:`${b.ruleCode??b.id}_effective_input`,title:"Effective Input",mode:"sub-flow",fields:q,mappings:zCe(S,q,k)}}if(b.type==="condition"||b.type==="liquid"){const Y=y_(b.data),q=(Y.language??"").toLowerCase(),j=q==="feel"||q===""?Iit(Y.body,S):[];return{contractName:`${b.ruleCode??b.id}_effective_input`,title:"Effective Input",mode:b.type==="liquid"?"expression":"auto",fields:j,mappings:j.map(G=>({id:`auto-${G.path}`,sourcePath:G.path,targetPath:G.path,targetField:G.path,sourceDataType:G.dataType,targetDataType:G.dataType,sourceNodeId:G.sourceNodeId,sourceNodeLabel:G.sourceNodeLabel,status:"mapped",required:G.required}))}}const O=Oc(((D=b.data.contractOverride)==null?void 0:D.requestFields)??((R=b.data.requestContract)==null?void 0:R.fields)??(($=(F=(A=e.nodeContractsById)==null?void 0:A.get(b.id))==null?void 0:F.requestScope)==null?void 0:$.fields)??[]),L=b.type==="end"?[]:O;return{contractName:`${b.ruleCode??b.id}_effective_input`,title:"Effective Input",mode:b.type==="decision-table"?"decision-table":b.type==="action"?"manual":"auto",fields:L,mappings:zCe(S,L,k)}},p=(b,w,S,k)=>{var D;const O=Oc(w.fields),L=[];for(const R of S.mappings){if(R.required&&!R.sourcePath.trim()){L.push({code:"MRF001",severity:"error",message:`Required input '${R.targetField??R.targetPath}' is not mapped.`,nodeId:b.id,targetPath:R.targetField??R.targetPath});continue}if(!R.sourcePath.trim())continue;if(!O.find(F=>F.path===R.sourcePath)){const F=b.type==="sub-flow"||b.type==="connector"||b.type==="decision-table";L.push({code:"MRF002",severity:F?"warning":"error",message:F?`Source field '${R.sourcePath}' is not in upstream scope (may be resolved from FactBag at runtime).`:`Source field '${R.sourcePath}' is not available in upstream scope.`,nodeId:b.id,sourcePath:R.sourcePath,targetPath:R.targetField??R.targetPath});continue}R.targetDataType&&R.sourceDataType&&R.targetDataType!==R.sourceDataType&&!(R.transform??"").trim()&&L.push({code:"MRF003",severity:"warning",message:`Mapping '${R.sourcePath}' -> '${R.targetField??R.targetPath}' has type mismatch (${R.sourceDataType} -> ${R.targetDataType}).`,nodeId:b.id,sourcePath:R.sourcePath,targetPath:R.targetField??R.targetPath})}if(b.type==="sub-flow"){const R=Tp(b.data.subFlowConfig).childTriggerSchema;for(const A of Oc((R==null?void 0:R.fields)??[]).filter(F=>F.required))S.mappings.some($=>($.targetField??$.targetPath)===A.path&&$.sourcePath.trim().length>0)||L.push({code:"MRF004",severity:"error",message:`Sub-flow input '${A.path}' is required but not mapped.`,nodeId:b.id,fieldPath:A.path})}if(b.type==="condition"||b.type==="liquid"){const R=y_(b.data),A=R.body,F=(R.language??"").toLowerCase();if(F==="feel"||F===""){const Y=Rit(A),q=jCe(A);for(const j of q){const G=j.split(".")[0];Y.has(G)||G.startsWith("__graph")||Nit.has(G)||O.some(V=>V.path===j||j.startsWith(V.path+"."))||L.push({code:"MRF005",severity:"error",message:`Expression references '${j}' but that field is not available in input scope.`,nodeId:b.id,fieldPath:j})}}}if(b.type==="condition"&&!b.ruleCode)for(const R of Oc(k.fields).filter(A=>!A.isResultPayload&&!A.runtimeWritten))(D=R.valueExpression)!=null&&D.trim()||L.push({code:"MRF009",severity:"warning",message:`Condition output '${R.path}' is metadata-only until a Value Expression is configured.`,nodeId:b.id,fieldPath:R.path});return b.type==="end"&&k.fields.length>0&&L.push({code:"MRF006",severity:"warning",message:"End nodes should not define additional output fields.",nodeId:b.id}),L},m=b=>{const w=n.get(b.id);if(w)return w;if(r.has(b.id))return{upstreamScope:{contractName:`${b.id}_input_scope`,title:"Input Scope",fields:[]},effectiveInput:{contractName:`${b.id}_effective_input`,title:"Effective Input",fields:[],mappings:[]},outputContract:{contractName:`${b.id}_output_contract`,title:"Output Contract",fields:[]},validationIssues:[{code:"MRF007",severity:"error",message:"Cycle detected in rule flow graph.",nodeId:b.id}]};r.add(b.id);const S=d(b),k=f(b,S),O=u(b),L=p(b,S,k,O),D={upstreamScope:S,effectiveInput:k,outputContract:O,validationIssues:L};return n.set(b.id,D),r.delete(b.id),D};for(const b of s.nodes)m(b);return n}function Lit(s,e){var o,a,l,c,d;const t=Qw(((a=(o=e.currentFlowContract)==null?void 0:o.requestContract)==null?void 0:a.fields)??[]);if(t.length>0)return t;const i=[...s.nodes].filter(u=>u.type!=="trigger"&&u.type!=="end").sort((u,f)=>{var b,w,S,k;const p=u.data.order??((w=(b=e.nodeContractsById)==null?void 0:b.get(u.id))==null?void 0:w.order)??Number.MAX_SAFE_INTEGER,m=f.data.order??((k=(S=e.nodeContractsById)==null?void 0:S.get(f.id))==null?void 0:k.order)??Number.MAX_SAFE_INTEGER;return p!==m?p-m:(u.label??"").localeCompare(f.label??"")})[0];if(!i)return[];const n=(l=e.nodeContractsById)==null?void 0:l.get(i.id),r=((c=n==null?void 0:n.requestScope)==null?void 0:c.fields)??((d=i.data.requestContract)==null?void 0:d.fields)??[];return Qw(r)}function zCe(s,e,t){const i=new Map;for(const n of t){const r=s.find(a=>a.path===n.sourcePath),o=e.find(a=>a.path===n.targetPath);i.set(n.id,{...n,targetField:(o==null?void 0:o.path)??n.targetPath,sourceDataType:r==null?void 0:r.dataType,targetDataType:o==null?void 0:o.dataType,sourceNodeId:r==null?void 0:r.sourceNodeId,sourceNodeLabel:r==null?void 0:r.sourceNodeLabel,required:o==null?void 0:o.required,status:r?o!=null&&o.dataType&&r.dataType!==o.dataType&&!(n.transform??"").trim()?"type-mismatch":"mapped":"missing"})}for(const n of e){if([...i.values()].find(a=>(a.targetField??a.targetPath)===n.path))continue;const o=s.find(a=>a.path===n.path)??s.find(a=>qCe(a.path)===qCe(n.path)&&a.dataType===n.dataType);i.set(`suggested-${n.path}`,{id:`suggested-${n.path}`,sourcePath:(o==null?void 0:o.path)??"",targetPath:n.path,targetField:n.path,sourceDataType:o==null?void 0:o.dataType,targetDataType:n.dataType,sourceNodeId:o==null?void 0:o.sourceNodeId,sourceNodeLabel:o==null?void 0:o.sourceNodeLabel,required:n.required,status:o?"suggested":n.required?"missing":"suggested",transformSuggestion:o&&o.dataType!==n.dataType?`to_${n.dataType}(${o.path})`:void 0})}return[...i.values()]}function Tit(s,e){if(s.type!=="sub-flow")return e;const t=Tp(s.data.subFlowConfig).outputMappings;return t.length===0?e:e.map(i=>{const n=t.find(r=>r.sourcePath===i.path&&r.targetPath.trim().length>0);return n?{...i,path:n.targetPath,label:n.targetPath,exposeToParent:i.exposeToParent}:i})}function qw(s,e){var t;return{...s,...e,children:(t=s.children)==null?void 0:t.map(i=>qw(i,e))}}function yv(s){const e=new Map;for(const t of s)e.has(t.path)||e.set(t.path,t);return[...e.values()].sort((t,i)=>(t.path??"").localeCompare(i.path??""))}function Qw(s){return s.map(e=>({...e,children:e.children?Qw(e.children):void 0}))}function Dit(s,e){const t=new Map;for(const i of s)t.set(i.path,{...i,children:i.children?Qw(i.children):void 0});for(const i of e)t.set(i.path,{...i,children:i.children?Qw(i.children):void 0});return[...t.values()]}function UCe(s){return s.filter(e=>e.exposeToParent!==!1)}function Iit(s,e){const t=new Set(jCe(s));return e.filter(i=>t.has(i.path))}function jCe(s){if(!s.trim())return[];const e=new Set,t=/\b[a-zA-Z_][a-zA-Z0-9_.]*\b/g;let i=t.exec(s);for(;i;){const r=i[0];r.includes(".")&&e.add(r),i=t.exec(s)}const n=/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)/g;for(i=n.exec(s);i;)e.add(i[1]),i=n.exec(s);return[...e]}function qCe(s){const e=s.split(".");return e[e.length-1]??s}function Rit(s){const e=new Set,t=[/\bfor\s+([a-zA-Z_]\w*)\s+in\b/g,/\bevery\s+([a-zA-Z_]\w*)\s+in\b/g,/\bsome\s+([a-zA-Z_]\w*)\s+in\b/g];for(const i of t){let n=i.exec(s);for(;n;)e.add(n[1]),n=i.exec(s)}return e}const Nit=new Set(["string","number","date","time","duration","list","context","math","Math","Date","JSON","RegExp","Object","Array","console","forloop","now","true","false","null"]),EX="application/muonroi-rule-flow-node-type",QCe="application/muonroi-rule-flow-rule-template",GCe={duration:0,padding:.22,minZoom:.18,maxZoom:1.1},KCe=860,LX={always:"→ Always","on-true":"✓ On Pass","on-false":"✗ On Fail","on-error":"⚠ On Error"},Ait={always:"Always continue to the next node when the source node executed.","on-true":"Continue only when the source node passed.","on-false":"Continue only when the source node failed without throwing.","on-error":"Continue only when the source node threw an exception."},Mit={always:{bg:"oklch(82% 0.01 255)",text:"oklch(35% 0.02 255)"},"on-true":{bg:"oklch(82% 0.08 150)",text:"oklch(30% 0.10 150)"},"on-false":{bg:"oklch(82% 0.08 25)",text:"oklch(35% 0.14 25)"},"on-error":{bg:"oklch(85% 0.06 75)",text:"oklch(38% 0.12 70)"}},Pit={always:{bg:"oklch(38% 0.01 255)",text:"oklch(82% 0.01 255)"},"on-true":{bg:"oklch(35% 0.06 150)",text:"oklch(80% 0.08 150)"},"on-false":{bg:"oklch(35% 0.06 25)",text:"oklch(80% 0.08 25)"},"on-error":{bg:"oklch(38% 0.05 75)",text:"oklch(82% 0.06 70)"}};function Fit(s){var e,t,i,n,r;if(s.nodeType==="condition"&&((e=s.conditionConfig)!=null&&e.successLabel))return`Pass: ${s.conditionConfig.successLabel} / Fail: ${s.conditionConfig.failureLabel??"—"}`;if(s.nodeType==="action")return"Execute side-effect";if(s.nodeType==="decision-table")return(t=s.contractRef)!=null&&t.sourceCode?`Table: ${s.contractRef.sourceCode}`:"Decision table lookup";if(s.nodeType==="connector"){const o=(i=s.connectorConfig)==null?void 0:i.connectorType;return o?`Connector: ${o}`:"External service call"}return s.nodeType==="sub-flow"?(n=s.subFlowConfig)!=null&&n.targetFlowCode?`Flow: ${s.subFlowConfig.targetFlowCode}`:"Delegate to sub-flow":s.nodeType==="liquid"?`Liquid → ${((r=s.liquidConfig)==null?void 0:r.outputFormat)??"json"}`:null}function Bit({politeMessage:s,assertiveMessage:e}){const t={position:"absolute",width:1,height:1,padding:0,margin:-1,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",border:0};return M.jsxs(M.Fragment,{children:[M.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:t,children:s}),M.jsx("div",{role:"alert","aria-live":"assertive","aria-atomic":"true",style:t,children:e})]})}function Gw({data:s,selected:e}){var c,d,u;const t=hM[s.nodeType],i=xX(s._theme??"light"),n=y_(s),r=((c=s.requestContract)==null?void 0:c.fields.length)??0,o=((d=s.responseContract)==null?void 0:d.fields.length)??0,a=kX[s.nodeType],l=Fit(s);return M.jsxs("div",{style:{...Met,background:i.nodeBg,boxShadow:i.nodeShadow,borderTop:e?`2px solid ${t}`:i.nodeBorder,borderRight:e?`2px solid ${t}`:i.nodeBorder,borderBottom:e?`2px solid ${t}`:i.nodeBorder,borderLeft:`8px solid ${t}`,borderRadius:s.nodeType==="end"?999:s.nodeType==="condition"?24:18},"aria-label":`${_L[s.nodeType]} node: ${s.label}`,children:[M.jsx(KE,{type:"target",position:dn.Left}),M.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:t,style:{flexShrink:0},children:M.jsx("path",{d:a})}),M.jsx("span",{style:{color:t,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase"},children:_L[s.nodeType]})]}),M.jsx("strong",{style:{fontSize:14,color:i.nodeText},children:s.label}),l?M.jsx("span",{style:{fontSize:11,color:i.nodeMutedText,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:l}):null,s.ruleCode?M.jsxs("span",{style:{fontSize:12,color:i.nodeSubtext},children:["Rule: ",s.ruleCode]}):null,(u=s.contractRef)!=null&&u.sourceCode?M.jsxs("span",{style:{fontSize:11,color:i.nodeMutedText},children:["Contract: ",s.contractRef.sourceType,"/",s.contractRef.sourceCode]}):null,n.body?M.jsxs("span",{style:{display:"inline-block",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,color:i.nodeSubtext},children:[n.language.toUpperCase(),": ",n.body]}):null,r>0||o>0?M.jsxs("span",{style:{fontSize:11,color:i.nodeMutedText},children:["Inline contracts ",r,"/",o]}):null]}),M.jsx(KE,{type:"source",position:dn.Right})]})}const TX={trigger:Gw,condition:Gw,action:Gw,"decision-table":Gw,"sub-flow":Gw,liquid:Gw,connector:Gw,end:Gw};function Kw({path:s}){const e=Array.isArray(s)?s:[s];return M.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:e.map((t,i)=>M.jsx("path",{d:t},i))})}function $it({onAddTrigger:s}){return M.jsx("div",{style:{position:"absolute",inset:0,display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:"var(--mu-space-md)",pointerEvents:"none",zIndex:5},children:M.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"var(--mu-space-sm)",padding:"var(--mu-space-lg) var(--mu-space-xl)",background:"var(--mu-surface-overlay)",border:"1px solid var(--mu-border-subtle)",borderRadius:18,boxShadow:"var(--mu-shadow-node)",pointerEvents:"auto",maxWidth:320,textAlign:"center"},children:[M.jsxs("svg",{width:32,height:32,viewBox:"0 0 16 16",fill:"var(--mu-color-interactive)",opacity:.7,children:[M.jsx("path",{d:"M14 1a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1h12zM2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2z"}),M.jsx("path",{d:"M8 4a.5.5 0 0 1 .5.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3A.5.5 0 0 1 8 4z"})]}),M.jsx("strong",{style:{fontSize:"var(--mu-text-md)",color:"var(--mu-text-primary)"},children:"Start your workflow"}),M.jsx("span",{style:{fontSize:"var(--mu-text-sm)",color:"var(--mu-text-muted)",lineHeight:"20px"},children:"Drop a trigger node to begin, or click the button below to add one automatically."}),M.jsx("button",{type:"button",onClick:s,style:{padding:"var(--mu-space-xs) var(--mu-space-md)",borderRadius:8,border:"1px solid var(--mu-color-interactive-border)",background:"var(--mu-color-interactive)",color:"var(--mu-text-on-accent)",fontSize:"var(--mu-text-sm)",fontWeight:600,cursor:"pointer",marginTop:"var(--mu-space-xs)"},children:"Add Trigger Node"})]})})}function Wit({nodeIds:s,syncToken:e,hostElement:t}){const i=Fqe(),n=kA(),r=$qe({includeHiddenNodes:!0}),o=ve.useRef(""),a=ve.useRef(null);function l(){!r||s.length===0||(s.forEach(d=>i(d)),n.fitView(GCe))}function c(d=0){return window.setTimeout(()=>{a.current!==null&&cancelAnimationFrame(a.current),a.current=requestAnimationFrame(()=>{a.current=null,l()})},d)}return ve.useEffect(()=>{const d=String(e);if(!r||s.length===0||o.current===d)return;o.current=d;const u=c(),f=c(150),p=c(350);return()=>{window.clearTimeout(u),window.clearTimeout(f),window.clearTimeout(p),a.current!==null&&(cancelAnimationFrame(a.current),a.current=null)}},[s,r,n,e,i]),ve.useEffect(()=>{if(!t)return;const d=new ResizeObserver(()=>{l()});d.observe(t);const u=()=>l();return window.addEventListener("resize",u),()=>{d.disconnect(),window.removeEventListener("resize",u)}},[t,r,n,i,s]),null}function Hit(){const s=kA();return ve.useEffect(()=>{function e(t){const i=t.target,n=i.tagName.toLowerCase();if(n==="input"||n==="textarea"||n==="select"||i.isContentEditable)return;const r=t.ctrlKey||t.metaKey;if(t.key==="+"||r&&t.key==="="){t.preventDefault(),s.zoomIn({duration:150});return}if(t.key==="-"||r&&t.key==="-"){t.preventDefault(),s.zoomOut({duration:150});return}if(t.key==="f"||t.key==="F"||r&&t.key==="0"){t.preventDefault(),s.fitView(GCe);return}}return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[s]),null}function ZCe({graph:s,onGraphChange:e,readOnly:t=!1,theme:i="light",height:n=640,apiBaseUrl:r,catalogApiBase:o,tenantId:a,workflowCode:l,onPublish:c,licenseStatus:d="licensed",showHeader:u=!0,version:f=null,onVersionChange:p,editorRoot:m}){var U1;const b=ve.useMemo(()=>Cl(s),[s]),w=Jet(b);function S(ne){return ne.map(_e=>({..._e,data:{..._e.data,_theme:i}}))}function k(ne){const _e=i==="dark"?Oit:HCe,st=i==="dark"?Pit:Mit;return ne.map(jt=>{var _c;const wt=((_c=jt.data)==null?void 0:_c.edgeType)??"always",Hi=_e[wt]??_e.always,Yi=st[wt]??st.always,Ds=LX[wt]??"Always";return{...jt,label:Ds,style:{stroke:Hi,strokeWidth:2},labelStyle:{fill:Yi.text,fontWeight:600,fontSize:12,letterSpacing:"0.02em"},labelBgStyle:{fill:Yi.bg},labelBgPadding:[4,8],labelBgBorderRadius:999}})}const[O,L]=ve.useState(()=>S(gM(w.present))),[D,R]=ve.useState(()=>k(bCe(w.present))),[A,F]=ve.useState(""),[$,Y]=ve.useState(""),[q,j]=ve.useState("basic-info"),[G,V]=ve.useState({status:"idle"}),[J,re]=ve.useState([]),[le,ie]=ve.useState([]),[oe,ge]=ve.useState(null),[se,pe]=ve.useState({status:"idle"}),[De,Fe]=ve.useState([]),[it,dt]=ve.useState([]),[bt,rt]=ve.useState(!1),[St,Xt]=ve.useState(null),[di,Vt]=ve.useState(""),[Yt,Bi]=ve.useState(""),$i=ve.useRef(w.present.metadata),Ei=ve.useRef(Yl(w.present)),[Yn,Sr]=ve.useState(0),tn=ve.useRef(O),Cn=ve.useRef(D),Hn=ve.useRef(new Map),Sn=ve.useRef(new Map),qs=ve.useRef(null),Ur=ve.useRef(new Map),Mn=ve.useMemo(()=>r?new Nve({baseUrl:r,tenantId:a}):null,[r,a]),ys=ve.useMemo(()=>o?new Ave({baseUrl:o,tenantId:a}):null,[o,a]),Qs=ve.useMemo(()=>r?new Mve({baseUrl:r,tenantId:a}):null,[r,a]),Bo=ve.useRef(null),vo=ve.useRef(null);ve.useRef(null);const Et=ve.useRef(!0),ni=ve.useRef(!1),Ui=ve.useRef(null),[Bn,mn]=ve.useState(0),[as,gs]=ve.useState("inspector"),[ws,Pi]=ve.useState(!1),jn=ve.useRef(null),[ns,Jo]=ve.useState(()=>{try{const ne=localStorage.getItem("muonroi-rule-studio-sidebar-width");return ne?Math.max(240,Math.min(400,Number(ne))):280}catch{return 280}}),[_n,uo]=ve.useState(()=>{try{return localStorage.getItem("muonroi-rule-studio-sidebar-collapsed")==="true"}catch{return!1}}),ea=ve.useRef(!1),[fc,Al]=ve.useState(()=>{try{const ne=localStorage.getItem("muonroi-rule-studio-toolbar-groups");return ne?JSON.parse(ne):{}}catch{return{}}}),mi=ne=>fc[ne]===!0,ae=ne=>Al(_e=>{const st={..._e,[ne]:!_e[ne]};try{localStorage.setItem("muonroi-rule-studio-toolbar-groups",JSON.stringify(st))}catch{}return st}),[de,ue]=ve.useState(!1),[Ce,ke]=ve.useState(!1),Me=ve.useRef(null),Qe=ve.useRef(null),[xt,zt]=ve.useState([]),[fe,Xe]=ve.useState(0),[vt,It]=ve.useState(!1),[ri,xi]=ve.useState(!1),Di=ve.useMemo(()=>xt.find(ne=>ne.isActive)??null,[xt]),nn=f!=null&&Di!=null&&f!==Di.version,Mt=t||nn,xe=ve.useCallback((ne,_e)=>{if(!r||!l){_e||zt([]);return}const st=r.replace(/\/$/,""),jt=fd(void 0,{tenantId:a});_e&&xi(!0),fetch(`${st}/rulesets/${encodeURIComponent(l)}/versions?limit=10&offset=${ne}`,{headers:jt}).then(wt=>wt.ok?wt.json():[]).then(wt=>{const Hi=Array.isArray(wt)?wt:Array.isArray(wt==null?void 0:wt.items)?wt.items:[];It(Hi.length===10),zt(_e?Yi=>[...Yi,...Hi].sort((Ds,_c)=>_c.version-Ds.version):Hi.sort((Yi,Ds)=>Ds.version-Yi.version))}).catch(wt=>{console.warn("[MVersionDropdown] Failed to fetch versions:",wt),_e||zt([])}).finally(()=>{_e&&xi(!1)})},[r,l,a]);ve.useEffect(()=>{Xe(0),It(!1),xe(0,!1)},[xe]);const pt=ve.useCallback(()=>{const ne=fe+10;Xe(ne),xe(ne,!0)},[fe,xe]);ve.useEffect(()=>{tn.current=O},[O]),ve.useEffect(()=>{Cn.current=D},[D]),ve.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-width",String(ns))}catch{}},[ns]),ve.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-collapsed",String(_n))}catch{}},[_n]),ve.useEffect(()=>{const ne=Me.current;if(!ne)return;const _e=new ResizeObserver(st=>{for(const jt of st){const Hi=jt.contentRect.width<KCe;ue(Hi),Hi||ke(!1)}});return _e.observe(ne),()=>_e.disconnect()},[]),ve.useEffect(()=>{if(!Ce)return;const ne=_e=>{Qe.current&&!Qe.current.contains(_e.target)&&ke(!1)};return document.addEventListener("click",ne),()=>document.removeEventListener("click",ne)},[Ce]),ve.useEffect(()=>()=>{Kc(),ba()},[]),ve.useEffect(()=>{L(ne=>S(ne)),R(ne=>k(ne))},[i]),ve.useEffect(()=>{const ne=Cl(s),_e=Yl(ne);_e!==Ei.current&&($i.current=ne.metadata,w.reset(ne),Ei.current=_e,Et.current=!0,Sr(st=>st+1),F(""),Y(""),j("basic-info"),zf(ne))},[s,w.reset]),ve.useEffect(()=>{const ne=w.present,_e=Yl(ne),st=Yl(yo(tn.current,Cn.current,!1));_e!==st&&($i.current=ne.metadata,Ei.current=_e,zf(ne))},[w.present]),ve.useEffect(()=>{const ne=_e=>{_e.target;const st=_e.composedPath().some(jt=>{if(!(jt instanceof HTMLElement))return!1;const wt=jt.tagName;return wt==="INPUT"||wt==="TEXTAREA"||wt==="SELECT"||jt.isContentEditable});if((_e.ctrlKey||_e.metaKey)&&_e.key==="z"&&!_e.shiftKey){_e.preventDefault(),Kc(),w.undo();return}if((_e.ctrlKey||_e.metaKey)&&(_e.key==="y"||_e.key==="z"&&_e.shiftKey)){_e.preventDefault(),Kc(),w.redo();return}if(_e.key==="Escape"){F(""),Y(""),j("basic-info");return}if(!(Mt||st)&&(_e.key==="Delete"||_e.key==="Backspace")){if(A){Va();return}$&&gc()}};return window.addEventListener("keydown",ne),()=>window.removeEventListener("keydown",ne)},[Mt,A,$]),ve.useEffect(()=>{const ne=Bo.current;if(!ne)return;const _e=()=>{var wt;const jt=((wt=ne.parentElement)==null?void 0:wt.getBoundingClientRect().width)??ne.getBoundingClientRect().width;mn(jt)};_e();const st=new ResizeObserver(()=>_e());return st.observe(ne),()=>st.disconnect()},[]);const[Qt,Vn]=ve.useState(0),ls=ve.useMemo(()=>yo(O,D,!1),[O,D]),Ci=ve.useMemo(()=>VCe(ls,{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}),[Qt,ls,l]),$t=ve.useMemo(()=>A?S(gM(Ci)).find(ne=>ne.id===A)??null:null,[Ci,A,i]),Mr=ve.useMemo(()=>$?D.find(ne=>ne.id===$)??null:null,[D,$]),Ml=$t?y_($t.data):{language:"feel",body:""},ur=ve.useMemo(()=>OX(ls,{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}),[Qt,ls,l]),Lo=ve.useMemo(()=>ur.issues.filter(ne=>ne.severity==="error"),[ur.issues]),$u=ve.useMemo(()=>ur.issues.filter(ne=>ne.severity==="warning"),[ur.issues]),Wd=!Mt&&!!c&&Lo.length===0,Ha=ve.useMemo(()=>jit(Ci),[Ci]);if(ve.useEffect(()=>{if(!Mn)return;let ne=!1;return(async()=>{try{const _e=await Mn.MListFlows();ne||re(_e.map(st=>({code:st.workflowName,label:st.workflowName})))}catch{}})(),()=>{ne=!0}},[Mn]),ve.useEffect(()=>{if(!Qs)return;let ne=!1;return(async()=>{try{const _e=await Qs.MListDecisionTables();if(!ne){for(const st of _e)Ur.current.set(st.id,st);ie(_e.map(st=>({code:st.id,label:st.name})))}}catch{}})(),()=>{ne=!0}},[Qs]),ve.useEffect(()=>{const ne=o?o.replace(/\/catalog\/palette\/?$/,""):r;if(!ne)return;let _e=!1;return(async()=>{try{const st=await qC.MGetCatalog(ne,fd(void 0,{tenantId:a}));_e||Fe(st)}catch{_e||Fe([])}})(),()=>{_e=!0}},[o,r]),ve.useEffect(()=>{var jt,wt,Hi;if(($t==null?void 0:$t.data.nodeType)!=="decision-table"){ge(null),pe({status:"idle"});return}if(!Qs){ge(null),pe({status:"error",message:"No decision table API configured for this editor."});return}const ne=((wt=(jt=$t.data.contractRef)==null?void 0:jt.sourceCode)==null?void 0:wt.trim())??((Hi=$t.data.ruleCode)==null?void 0:Hi.trim())??"";if(!ne){ge(null),pe({status:"idle"});return}const _e=Ur.current.get(ne);if(_e){ge(_e),pe({status:"ready"}),Hu($t.id,_e);return}let st=!1;return pe({status:"loading"}),(async()=>{try{const Yi=await Qs.MGetDecisionTable(ne);if(st)return;Ur.current.set(ne,Yi),ge(Yi),pe({status:"ready"}),Hu($t.id,Yi)}catch(Yi){st||(ge(null),pe({status:"error",message:Yi instanceof Error?Yi.message:"Failed to load decision table metadata."}))}})(),()=>{st=!0}},[Qs,$t==null?void 0:$t.id,$t==null?void 0:$t.data.nodeType,(U1=$t==null?void 0:$t.data.contractRef)==null?void 0:U1.sourceCode,$t==null?void 0:$t.data.ruleCode]),ve.useEffect(()=>{if(!ys){dt([]),rt(!1);return}let ne=!1;return(async()=>{rt(!0);try{const _e=await ys.MListCatalog();ne||(dt(_e),rt(!1))}catch{ne||(dt([]),rt(!1))}})(),()=>{ne=!0}},[ys]),ve.useEffect(()=>{if(!Mn||!l)return;let ne=!1;return(async()=>{var _e,st;await XCe(Mn,Sn.current,l);for(const jt of ls.nodes){if(jt.type==="trigger"||jt.type==="end"||Hn.current.has(jt.id))continue;const wt=await Vit(Mn,l,jt);wt&&Hn.current.set(jt.id,wt)}for(const jt of ls.nodes.filter(wt=>wt.type==="sub-flow")){const wt=(_e=Tp(jt.data.subFlowConfig).targetFlowCode)==null?void 0:_e.trim();if(!wt)continue;const Hi=await XCe(Mn,Sn.current,wt);if(ne)return;const Yi=await YCe(Mn,wt,"trigger"),Ds=(Yi==null?void 0:Yi.requestScope)??(Hi==null?void 0:Hi.requestContract),_c=(st=Tp(jt.data.subFlowConfig).childTriggerSchema)==null?void 0:st.contractName;Ds!=null&&Ds.contractName&&_c!==Ds.contractName&&Wu(jt.id,ju=>({...ju,data:{...ju.data,subFlowConfig:{...Tp(ju.data.subFlowConfig),childTriggerSchema:Ds}}}),!1)}ne||Vn(jt=>jt+1)})(),()=>{ne=!0}},[Mn,ls.nodes,l]),ve.useEffect(()=>{var _e,st;if(!$t){V({status:"idle"});return}gs("inspector");const ne=$t&&Hn.current.get($t.id);if(ne||(_e=$t.data.contractLayer)!=null&&_e.upstreamScope||$t.type==="trigger"||$t.type==="end"){V({status:"ready",title:(ne==null?void 0:ne.ruleCode)??((st=$t.data.contractRef)==null?void 0:st.label)??$t.data.label});return}V(Mn?{status:"loading"}:{status:"error",message:"No contract API configured for this editor."})},[Mn,$t,Qt]),d==="unlicensed"){const ne=xX();return M.jsxs("section",{style:{...Jit,background:ne.licenseBg,border:ne.licenseBorder,color:ne.licenseText},children:[M.jsx("strong",{children:"Rule Flow Designer requires a Muonroi commercial license."}),M.jsx("span",{children:"Load an activation proof before rendering this editor."})]})}function Kc(){jn.current!==null&&(window.clearTimeout(jn.current),jn.current=null)}function ba(){Ui.current!==null&&(window.clearTimeout(Ui.current),Ui.current=null)}function zf(ne){ba(),ni.current=!0,L(S(gM(ne))),R(k(bCe(ne))),Ui.current=window.setTimeout(()=>{ni.current=!1,Ui.current=null},0)}function Zc(ne,_e){var Hi;Kc();const st=CL(ne,{currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}),jt=Cl(st.graph),wt=Yl(jt);if($i.current=jt.metadata,Ei.current=wt,zf(jt),_e!=null&&_e.syncViewport&&(Et.current=!0,Sr(Yi=>Yi+1)),st.issues.length>0){const Yi=((Hi=st.issues[0])==null?void 0:Hi.message)??"Rule flow ordering is invalid.";V({status:"error",message:Yi})}(_e==null?void 0:_e.pushHistory)!==!1&&w.commit(jt),(_e==null?void 0:_e.notify)!==!1&&(e==null||e(jt))}function yo(ne,_e,st=!0){return{nodes:ne.map(zit),edges:_e.map(Uit),metadata:{...$i.current,version:Math.max(1,$i.current.version??1),lastModifiedAt:st?new Date().toISOString():$i.current.lastModifiedAt}}}function Wu(ne,_e,st=!0){const jt=tn.current.map(Hi=>Hi.id===ne?_e(Hi):Hi),wt=CL(yo(jt,Cn.current),{currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}).graph;$i.current=wt.metadata,Ei.current=Yl(wt),L(S(gM(wt))),st&&(e==null||e(wt))}function hr(ne,_e="debounced"){if(t||!A)return;const st=tn.current.map(wt=>wt.id===A?ne(wt):wt),jt=CL(yo(st,Cn.current),{currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}).graph;if($i.current=jt.metadata,Ei.current=Yl(jt),L(S(gM(jt))),e==null||e(jt),_e==="immediate"){w.commit(jt);return}Kc(),jn.current=window.setTimeout(()=>{jn.current=null,w.commit(jt)},300)}function Va(){t||!A||(F(""),j("basic-info"),Zc(yo(tn.current.filter(ne=>ne.id!==A),Cn.current.filter(ne=>ne.source!==A&&ne.target!==A))))}function gc(){t||!$||(Y(""),Zc(yo(tn.current,Cn.current.filter(ne=>ne.id!==$))))}function Uf(ne){if(t||!$)return;const _e=Cn.current.map(st=>st.id===$?ne(st):st);Zc(yo(tn.current,_e),{syncViewport:!1})}function Hd(ne){F(ne),Y("");const _e=tn.current.find(st=>st.id===ne);_e&&j(mCe(_e.data.nodeType)),gs("inspector")}function Hu(ne,_e){const st=JCe(_e,"input"),jt=JCe(_e,"output");Wu(ne,wt=>{var Hi;return{...wt,data:{...wt.data,description:(Hi=wt.data.description)!=null&&Hi.trim()?wt.data.description:_e.description,requestContract:st,responseContract:jt,contractRef:{sourceType:"decision-table",sourceCode:_e.id,label:_e.name}}}},!1),Vn(wt=>wt+1)}function Uh(){const ne=DX(yo(tn.current,Cn.current));Et.current=!0,Zc(ne,{syncViewport:!0})}function jf(ne){const _e=[...Cn.current];if(A){const st=`${A}-${ne.id}`;_e.push({id:st,source:A,target:ne.id,label:"always",data:{edgeType:"always"}}),Y(st)}F(ne.id),Y(""),j(mCe(ne.data.nodeType)),Zc(DX(yo([...tn.current,ne],_e)),{syncViewport:!0})}function Xc(ne,_e){if(t)return;const st={id:`node-${ne}-${Math.random().toString(36).slice(2,10)}`,type:ne,position:_e??{x:60+tn.current.length*36,y:80+tn.current.length%4*90},data:{label:uCe[ne],nodeType:ne,expression:gX(ne),conditionConfig:ne==="condition"?{successLabel:"Valid",failureLabel:"Rejected"}:void 0,subFlowConfig:ne==="sub-flow"?{targetFlowCode:"",inputMappings:[],outputMappings:[]}:void 0,liquidConfig:ne==="liquid"?{outputFormat:"json"}:void 0}};jf(st)}function Om(ne,_e){if(t)return;const st={id:`node-rule-${Math.random().toString(36).slice(2,10)}`,type:"condition",position:_e??{x:60+tn.current.length*36,y:80+tn.current.length%4*90},data:{label:ne.displayName,nodeType:"condition",ruleCode:ne.code,description:ne.description,expression:gX("condition"),contractRef:{sourceType:"rule",sourceCode:ne.code,label:ne.displayName},requestContract:ne.inputSchema,responseContract:ne.outputSchema}};jf(st)}function qf(){Xc("trigger",{x:200,y:180})}const hs=ve.useRef(null),Eb=ve.useCallback(ne=>{ea.current=!0,hs.current={startX:ne.clientX,startW:ns},ne.currentTarget.setPointerCapture(ne.pointerId),ne.preventDefault()},[ns]),Cs=ve.useCallback(ne=>{if(!ea.current||!hs.current)return;const _e=hs.current.startW+(ne.clientX-hs.current.startX);Jo(Math.max(240,Math.min(400,_e)))},[]),Fy=ve.useCallback(ne=>{ea.current&&(ea.current=!1,hs.current=null,ne.currentTarget.releasePointerCapture(ne.pointerId))},[]),jh=typeof n=="number"?`${n}px`:n,xn=Bn>0&&Bn<KCe,Lb=xn?"min(52vh, 520px)":jh,Gt=xX(),qh={color:Gt.textPrimary},Pl=M.jsxs("div",{"data-testid":"rule-flow-sidebar-palette",style:{...tSe,...Zit,...lnt(),gap:8,padding:12},children:[Object.keys(TX).map(ne=>M.jsxs("button",{type:"button",style:int(ne,Gt),"data-testid":`palette-${ne}`,draggable:!t,onClick:()=>Xc(ne),onDragStart:_e=>Kg(_e,ne),disabled:t,children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[M.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:hM[ne],style:{flexShrink:0},children:M.jsx("path",{d:kX[ne]})}),M.jsx("span",{style:{fontWeight:600},children:_L[ne]})]}),M.jsx("span",{style:{fontSize:11,color:Gt.textMuted,fontWeight:400},children:kit[ne]})]},ne)),o?M.jsx(dit,{groups:it,loading:bt,readOnly:t,onAddRule:Om,onDragStart:(ne,_e)=>Kg(ne,"condition",_e)}):null]}),Qh=()=>{const ne=document.createElement("input");ne.type="file",ne.accept="application/json,.json",ne.style.position="fixed",ne.style.top="-9999px",document.body.appendChild(ne),ne.addEventListener("change",()=>{var st;const _e=(st=ne.files)==null?void 0:st[0];document.body.removeChild(ne),_e&&(async()=>{try{const jt=await _e.text(),wt=CL(fCe(jt),{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current}).graph;$i.current=wt.metadata,Ei.current=Yl(wt),w.reset(wt),zf(wt),F(""),Y(""),j("basic-info"),Et.current=!0,Sr(Hi=>Hi+1),e==null||e(wt),V({status:"ready",title:wt.metadata.ruleSetCode??"Imported flow"})}catch(jt){V({status:"error",message:jt.message})}})()}),ne.click()},jr=()=>Qit(yo(tn.current,Cn.current),$i.current.ruleSetCode),xr=()=>{const ne=OX(yo(tn.current,Cn.current),{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current});Vn(_e=>_e+1),ne.isValid?(V({status:"ready",title:`Valid — ${ne.issues.filter(_e=>_e.severity==="warning").length} warning(s)`}),Vt(`Validation passed with ${ne.issues.filter(_e=>_e.severity==="warning").length} warning(s).`)):(V({status:"error",message:`${ne.issues.filter(_e=>_e.severity==="error").length} error(s) found.`}),Vt(`Validation complete: ${ne.issues.filter(_e=>_e.severity==="error").length} error(s), ${ne.issues.filter(_e=>_e.severity==="warning").length} warning(s).`))},jg=()=>{const ne=OX(yo(tn.current,Cn.current),{flowCode:l,currentFlowContract:l?Sn.current.get(l):void 0,flowContractsByCode:Sn.current,nodeContractsById:Hn.current});if(Vn(_e=>_e+1),!ne.isValid){V({status:"error",message:"Publish blocked because one or more nodes still have contract validation errors."}),Bi("Publish blocked: one or more nodes still have contract validation errors.");return}Xt({graph:ne.graph,warnings:ne.issues.filter(_e=>_e.severity==="warning")})},$o=ne=>M.jsxs("button",{type:"button",style:ne?{...RX,display:"flex",alignItems:"center",gap:5,visibility:nn?"hidden":void 0}:{...uh(!0),display:nn?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:()=>{jg(),ne&&setTimeout(()=>ke(!1),0)},disabled:!Wd,title:c?Lo.length>0?"Fix validation errors before publishing.":"Publish":"No publish handler configured.","aria-disabled":!Wd,children:[M.jsx(Kw,{path:"M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3zM1 13.5a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13a.5.5 0 0 1-.5-.5z"}),"Publish"]}),pl=ne=>M.jsxs("button",{type:"button",style:ne?{...RX,display:"flex",alignItems:"center",gap:5,visibility:nn?"hidden":void 0}:{...uh(!1),display:nn?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},disabled:Mt,onClick:()=>{Qh(),ne&&setTimeout(()=>ke(!1),0)},title:"Import",children:[M.jsx(Kw,{path:["M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z","M7.646 11.854a.5.5 0 0 0 .708 0l3-3a.5.5 0 0 0-.708-.708L8.5 10.293V1.5a.5.5 0 0 0-1 0v8.793L5.354 8.146a.5.5 0 1 0-.708.708l3 3z"]}),"Import"]}),Yc=ne=>M.jsxs("button",{type:"button",style:ne?{...RX,display:"flex",alignItems:"center",gap:5}:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{jr(),ne&&setTimeout(()=>ke(!1),0)},title:"Export",children:[M.jsx(Kw,{path:["M.5 9.9a.5.5 0 0 1 .5.5v2.5a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-2.5a.5.5 0 0 1 1 0v2.5a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2v-2.5a.5.5 0 0 1 .5-.5z","M7.646 1.146a.5.5 0 0 1 .708 0l3 3a.5.5 0 0 1-.708.708L8.5 2.707V11.5a.5.5 0 0 1-1 0V2.707L5.354 4.854a.5.5 0 1 1-.708-.708l3-3z"]}),"Export"]}),Em=M.jsxs("div",{"data-testid":"rule-flow-sidebar-actions",style:{display:"flex",flexDirection:"column",gap:8},ref:Me,children:[ur.issues.length>0?M.jsxs("div",{style:ent(Lo.length>0),children:[M.jsx("strong",{children:Lo.length>0?"Publish blocked":"Publish warnings"}),M.jsxs("span",{children:[Lo.length," error(s) / ",$u.length," warning(s)"]}),Lo.length>0?M.jsxs("ul",{style:{margin:"6px 0 0",padding:"0 0 0 16px",fontSize:12,lineHeight:1.5},children:[Lo.slice(0,20).map((ne,_e)=>M.jsxs("li",{style:{marginBottom:2},children:[M.jsx("code",{style:{fontSize:11,fontWeight:600},children:ne.code}),ne.nodeId?M.jsxs("span",{style:{color:"var(--mu-text-muted)"},children:[" [",ne.nodeId,"]"]}):null," ",ne.message]},_e)),Lo.length>20?M.jsxs("li",{children:["...and ",Lo.length-20," more"]}):null]}):null]}):null,M.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:"var(--mu-space-xs)"},children:[M.jsxs("div",{"data-testid":"toolbar-group-history",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[M.jsx("button",{type:"button",onClick:()=>ae("history"),style:IX(Gt),title:mi("history")?"Expand History":"Collapse History",children:mi("history")?"History ▸":"History ▾"}),mi("history")?null:M.jsxs(M.Fragment,{children:[M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Kc(),w.undo()},disabled:Mt||!w.canUndo,title:"Undo (Ctrl+Z)",children:[M.jsx(Kw,{path:"M7.5 4H3V0L0 3l3 3V3h4.5A3.5 3.5 0 0 1 11 6.5 3.5 3.5 0 0 1 7.5 10H4v1.5h3.5A5 5 0 0 0 12.5 6.5 5 5 0 0 0 7.5 2V4z"}),"Undo"]}),M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Kc(),w.redo()},disabled:Mt||!w.canRedo,title:"Redo (Ctrl+Shift+Z)",children:[M.jsx(Kw,{path:"M8.5 4h4.5v3l3-3-3-3v3H8.5A5 5 0 0 0 3.5 6.5 5 5 0 0 0 8.5 11H12V9.5H8.5A3.5 3.5 0 0 1 5 6.5 3.5 3.5 0 0 1 8.5 3V4z"}),"Redo"]})]})]}),M.jsx("div",{style:{width:1,height:24,background:Gt.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),M.jsxs("div",{"data-testid":"toolbar-group-canvas",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[M.jsx("button",{type:"button",onClick:()=>ae("canvas"),style:IX(Gt),title:mi("canvas")?"Expand Canvas":"Collapse Canvas",children:mi("canvas")?"Canvas ▸":"Canvas ▾"}),mi("canvas")?null:M.jsxs(M.Fragment,{children:[M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:96},onClick:Uh,disabled:Mt,title:"Auto Layout",children:[M.jsx(Kw,{path:"M1 2.5A1.5 1.5 0 0 1 2.5 1h3A1.5 1.5 0 0 1 7 2.5v3A1.5 1.5 0 0 1 5.5 7h-3A1.5 1.5 0 0 1 1 5.5v-3zm8 0A1.5 1.5 0 0 1 10.5 1h3A1.5 1.5 0 0 1 15 2.5v3A1.5 1.5 0 0 1 13.5 7h-3A1.5 1.5 0 0 1 9 5.5v-3zm-8 8A1.5 1.5 0 0 1 2.5 9h3A1.5 1.5 0 0 1 7 10.5v3A1.5 1.5 0 0 1 5.5 15h-3A1.5 1.5 0 0 1 1 13.5v-3zm8 0A1.5 1.5 0 0 1 10.5 9h3A1.5 1.5 0 0 1 15 10.5v3A1.5 1.5 0 0 1 13.5 15h-3A1.5 1.5 0 0 1 9 13.5v-3z"}),"Auto Layout"]}),M.jsxs("button",{type:"button",style:{...uh(!1),display:nn?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:xr,disabled:Mt,title:"Validate",children:[M.jsx(Kw,{path:"M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"}),"Validate"]}),M.jsxs("button",{type:"button",style:{...uh(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:72},onClick:ss,disabled:!r||!l,title:"Dry Run",children:[M.jsx(Kw,{path:"M11.5 2H9V.5a.5.5 0 0 0-1 0V2H5.5A2.5 2.5 0 0 0 3 4.5v7A2.5 2.5 0 0 0 5.5 14h5A2.5 2.5 0 0 0 13 11.5v-7A2.5 2.5 0 0 0 11.5 2zM8 11a3 3 0 1 1 0-6 3 3 0 0 1 0 6zm0-1a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"}),"Dry Run"]})]})]}),M.jsx("div",{style:{width:1,height:24,background:Gt.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),de?M.jsxs("div",{style:{position:"relative"},ref:Qe,children:[M.jsx("button",{type:"button",onClick:()=>ke(ne=>!ne),style:{...uh(!1),minWidth:32,padding:"6px 8px",fontSize:16},title:"More actions","aria-label":"More actions",children:"⋮"}),Ce?M.jsxs("div",{style:{position:"absolute",top:"100%",right:0,marginTop:4,background:Gt.overlayBg,border:Gt.overlayBorder,borderRadius:10,boxShadow:Gt.overlayShadow,padding:"4px 0",minWidth:140,zIndex:10},children:[$o(!0),pl(!0),Yc(!0)]}):null]}):M.jsxs("div",{"data-testid":"toolbar-group-workflow",style:{display:"flex",alignItems:"center",gap:4},children:[M.jsx("button",{type:"button",onClick:()=>ae("workflow"),style:IX(Gt),title:mi("workflow")?"Expand Workflow":"Collapse Workflow",children:mi("workflow")?"Workflow ▸":"Workflow ▾"}),mi("workflow")?null:M.jsxs(M.Fragment,{children:[$o(),pl(),Yc()]})]})]})]}),By=M.jsx("div",{"data-testid":"rule-flow-sidebar-inspector",style:{...tSe,...Xit,...cnt()},children:$t?M.jsx(Btt,{selectedNode:{id:$t.id,data:$t.data},selectedExpression:Ml,contractLoadState:G,selectedDecisionTable:oe,decisionTableLoadState:se,readOnly:Mt,apiBaseUrl:r,inspectorTab:q,flowOptions:J,decisionTableOptions:le,setInspectorTab:j,onSelectNodeByRuleCode:ne=>{const _e=tn.current.find(st=>st.data.ruleCode===ne);_e&&Hd(_e.id)},onUpdateLabel:ne=>hr(_e=>({..._e,data:{..._e.data,label:ne}})),onUpdateRuleCode:ne=>hr(_e=>({..._e,data:{..._e.data,ruleCode:ne,contractRef:pCe(_e.data.nodeType,ne,_e.data.contractRef)}})),onUpdateDescription:ne=>hr(_e=>({..._e,data:{..._e.data,description:ne}})),onUpdateContractRef:ne=>hr(_e=>({..._e,data:{..._e.data,contractRef:ne,requestContract:void 0,responseContract:void 0}})),onUpdateDecisionTableCode:ne=>hr(_e=>{var st;return{..._e,data:{..._e.data,ruleCode:ne,requestContract:void 0,responseContract:void 0,contractRef:ne.trim()?{sourceType:"decision-table",sourceCode:ne.trim(),label:((st=le.find(jt=>jt.code===ne.trim()))==null?void 0:st.label)??ne.trim()}:_e.data.contractRef}}}),onUpdateConditionConfig:ne=>hr(_e=>({..._e,data:{..._e.data,conditionConfig:ne}})),onUpdateTargetFlowCode:ne=>hr(_e=>({..._e,data:{..._e.data,contractRef:ne.trim()?{sourceType:"flow",sourceCode:ne.trim(),label:ne.trim()}:_e.data.contractRef,subFlowConfig:{...Tp(_e.data.subFlowConfig),targetFlowCode:ne}}})),onUpdateLiquidOutput:ne=>hr(_e=>({..._e,data:{..._e.data,liquidConfig:{...gCe(_e.data.liquidConfig),outputFormat:ne}}})),onUpdateExpressionLanguage:ne=>hr(_e=>({..._e,data:{..._e.data,expression:{...y_(_e.data),language:ne}}})),onUpdateExpressionBody:ne=>hr(_e=>({..._e,data:{..._e.data,expression:{...y_(_e.data),body:ne}}})),onInsertExpressionToken:ne=>{qs.current?qs.current.insert(ne):hr(_e=>({..._e,data:{..._e.data,expression:{...y_(_e.data),body:`${y_(_e.data).body}${y_(_e.data).body.trim()?" ":""}${ne}`}}}))},onChangeInputContract:ne=>hr(_e=>({..._e,data:{..._e.data,contractOverride:{..._e.data.contractOverride,requestFields:ne}}})),onChangeEffectiveMappings:ne=>hr(_e=>({..._e,data:{..._e.data,inputMappings:_e.data.nodeType==="action"?ne.map(st=>({id:st.id,sourcePath:st.sourcePath,targetPath:st.targetField??st.targetPath,transform:st.transform,language:st.language})):_e.data.inputMappings,subFlowConfig:_e.data.nodeType==="sub-flow"?{...Tp(_e.data.subFlowConfig),inputMappings:ne.map(st=>({id:st.id,sourcePath:st.sourcePath,targetPath:st.targetField??st.targetPath,transform:st.transform,language:st.language}))}:_e.data.subFlowConfig,contractLayer:_e.data.contractLayer}})),onChangeOutputContract:ne=>hr(_e=>({..._e,data:{..._e.data,contractOverride:{..._e.data.contractOverride,responseFields:ne.filter(st=>!st.isResultPayload)}}}),"immediate"),onDeleteNode:Va,connectorCatalog:De,onUpdateConnectorConfig:ne=>hr(_e=>({..._e,data:{..._e.data,connectorConfig:ne}})),onSetInsertRef:ne=>{qs.current=ne},shadowRoot:m instanceof ShadowRoot?m:void 0,showSectionHeader:!1}):M.jsx(Git,{selectedEdge:Mr,readOnly:t,onUpdateEdgeType:ne=>Uf(_e=>({..._e,label:ne,data:{..._e.data??{},edgeType:ne}})),onDeleteEdge:gc})}),Qf=r?r.includes("localhost")||r.includes("127.0.0.1")?"DEV":"PROD":null,[qg,Lm]=ve.useState(!1),[_O,pc]=ve.useState(!1),[Vd,Vu]=ve.useState(!1),[Jc,Qg]=ve.useState("{}"),[Gh,zu]=ve.useState(null),[Uu,Tm]=ve.useState(!1),[Dm,mc]=ve.useState(null),[K,Se]=ve.useState(40),Ge=ve.useRef(!1),[ot,Ut]=ve.useState(new Set),[Xi,si]=ve.useState(null);function cn(){var jt,wt;const ne=ls.nodes.find(Hi=>Hi.type==="trigger"),_e=((jt=ne==null?void 0:ne.data.requestContract)==null?void 0:jt.fields)??((wt=ne==null?void 0:ne.data.contractOverride)==null?void 0:wt.requestFields);if(!_e||_e.length===0)return"{}";const st={};for(const Hi of _e){const Yi=(Hi.dataType??"").toLowerCase();Yi.includes("int")||Yi.includes("number")||Yi.includes("decimal")||Yi.includes("float")||Yi.includes("double")?st[Hi.path]=0:Yi.includes("bool")?st[Hi.path]=!1:Yi.includes("array")||Yi.includes("list")?st[Hi.path]=[]:Yi.includes("object")||Yi.includes("map")||Yi.includes("dict")?st[Hi.path]={}:st[Hi.path]=""}return JSON.stringify(st,null,2)}function ss(){Vu(!0),zu(null),mc(null),Qg(cn())}async function Ss(){if(!(!r||!l)){Tm(!0),mc(null),zu(null);try{const ne=r.replace(/\/$/,""),_e=fd(void 0,{tenantId:a});_e.set("Content-Type","application/json");const st=f!=null?`?version=${f}`:"",jt=await fetch(`${ne}/execute/${encodeURIComponent(l)}${st}`,{method:"POST",headers:_e,body:Jc});if(!jt.ok){const Hi=await jt.text();throw new Error(`Execution failed (${jt.status}): ${Hi}`)}const wt=await jt.json();zu(wt),kr(wt)}catch(ne){mc(ne instanceof Error?ne.message:"Unknown error")}finally{Tm(!1)}}}function Pr(ne){const _e=new Set;for(const st of Object.keys(ne)){const jt=st.match(/^__graph\.node\.(.+?)\.executed$/);jt&&ne[st]===!0&&_e.add(jt[1])}return _e}function kr(ne){const _e=Pr(ne.factBag);if(_e.size===0)for(const jt of ne.results)_e.add(jt.ruleName);if(_e.size>0){const jt=new Map;for(const wt of tn.current)jt.set(wt.id,wt.data.nodeType);for(const[wt,Hi]of jt)Hi==="trigger"&&_e.add(wt),Hi==="end"&&ne.isSuccess&&_e.add(wt)}Ut(_e);const st=new Map(ne.results.map(jt=>[jt.ruleName,jt]));L(jt=>jt.map(wt=>{const Hi=wt.data.ruleCode||wt.data.label,Yi=_e.has(wt.id)||_e.has(Hi),Ds=st.get(Hi);if(!Yi)return{...wt,style:{...wt.style,opacity:.35,transition:"all 300ms ease",filter:"grayscale(0.5)"},className:""};const _c=ne.factBag[`__graph.node.${wt.id}.passed`],ju=_c!==void 0?_c===!0:(Ds==null?void 0:Ds.isSuccess)??!0,Kf=ju?"var(--mu-color-success)":"var(--mu-color-error)",aR=ju?"color-mix(in oklch, var(--mu-color-success) 6%, transparent)":"color-mix(in oklch, var(--mu-color-error) 6%, transparent)";return{...wt,style:{...wt.style,opacity:1,background:aR,border:"none",borderLeft:`4px solid ${Kf}`,borderRadius:8,boxShadow:"none",transition:"all 300ms ease",filter:"none"},className:""}})),R(jt=>jt.map(wt=>{const Hi=tn.current.find(Kf=>Kf.id===wt.source),Yi=tn.current.find(Kf=>Kf.id===wt.target),Ds=(Hi==null?void 0:Hi.data.ruleCode)||(Hi==null?void 0:Hi.data.label)||wt.source,_c=(Yi==null?void 0:Yi.data.ruleCode)||(Yi==null?void 0:Yi.data.label)||wt.target;return(_e.has(wt.source)||_e.has(Ds))&&(_e.has(wt.target)||_e.has(_c))?{...wt,style:{...wt.style,strokeWidth:3,opacity:1,transition:"all 300ms ease"}}:{...wt,style:{...wt.style,strokeWidth:1,opacity:.35,transition:"all 300ms ease"}}}))}function Zn(){L(ne=>ne.map(_e=>({..._e,style:void 0,className:""}))),R(ne=>k(ne.map(_e=>({..._e,style:void 0})))),Ut(new Set),si(null)}function fr(){Vu(!1),zu(null),mc(null),Zn()}function ho(ne,_e){if(!Gh||ot.size===0)return;const st=_e.data.ruleCode||_e.data.label;(ot.has(_e.id)||ot.has(st))&&si({nodeId:st,mousePos:{x:ne.clientX,y:ne.clientY}})}function Gg(){si(null)}function $y(ne){var Yi;ne.preventDefault(),Ge.current=!0;const _e=ne.clientY,st=K,jt=(Yi=vo.current)==null?void 0:Yi.getBoundingClientRect();if(!jt)return;const wt=Ds=>{if(!Ge.current)return;const ju=(_e-Ds.clientY)/jt.height*100,Kf=Math.min(70,Math.max(20,st+ju));Se(Kf)},Hi=()=>{Ge.current=!1,document.removeEventListener("pointermove",wt),document.removeEventListener("pointerup",Hi)};document.addEventListener("pointermove",wt),document.addEventListener("pointerup",Hi)}return M.jsxs(Tve,{children:[M.jsx(Bit,{politeMessage:di,assertiveMessage:Yt}),u?M.jsxs("header",{style:{...ynt,background:Gt.sidebarBg,borderBottom:Gt.sidebarBorder,color:Gt.textPrimary},children:[M.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--mu-space-sm)"},children:[M.jsx("strong",{style:{fontSize:14},children:"Rule Studio"}),l?M.jsx("span",{style:{...wv,background:Gt.actionPrimaryBg,border:Gt.actionPrimaryBorder,color:Gt.textPrimary},children:l}):null,xt.length>0?M.jsx(_Qe,{versions:xt,activeVersion:Di,selectedVersion:f??null,onSelect:ne=>p==null?void 0:p(ne),onLoadMore:pt,hasMore:vt,loadingMore:ri,tokens:Gt}):f!=null?M.jsxs("span",{style:{...wv,background:Gt.actionPrimaryBg,border:Gt.actionPrimaryBorder,color:Gt.textPrimary,fontSize:11},children:["v",f]}):M.jsx("span",{style:{...wv,background:"var(--mu-color-success-bg)",border:"1px solid var(--mu-color-success-border)",color:"var(--mu-color-success-text)",fontSize:11,fontWeight:700},children:"Active"}),xt.length>1?M.jsx("span",{role:"button",tabIndex:0,style:{...wv,cursor:"pointer",background:"var(--mu-color-interactive-subtle)",border:"1px solid var(--mu-color-interactive-border)",color:"var(--mu-color-interactive)",fontSize:11,fontWeight:600,padding:"3px 10px"},onClick:()=>pc(!0),onKeyDown:ne=>{ne.key==="Enter"&&pc(!0)},children:"Compare"}):null,Qf?M.jsx("span",{style:{...wv,background:Qf==="DEV"?"var(--mu-color-warning-bg)":"var(--mu-color-success-bg)",border:Qf==="DEV"?"1px solid var(--mu-color-warning-border)":"1px solid var(--mu-color-success-border)",color:Qf==="DEV"?Gt.warningText:"var(--mu-color-success-text)",fontSize:10,fontWeight:700},children:Qf}):null,Mt?M.jsx("span",{style:{...wv,background:Gt.errorBg,border:Gt.errorBorder,color:Gt.errorText,fontSize:10,fontWeight:700},children:"READ-ONLY"}):null,(()=>{var st;const ne=f!=null?xt.find(jt=>jt.version===f):Di,_e=(st=ne==null?void 0:ne.status)==null?void 0:st.toLowerCase();return _e==="pendingapproval"?M.jsx("span",{style:{...wv,background:"var(--mu-color-warning-bg)",border:"1px solid var(--mu-color-warning-border)",color:Gt.warningText,fontSize:10,fontWeight:700},children:"PENDING APPROVAL"}):_e==="rejected"?M.jsx("span",{style:{...wv,background:Gt.errorBg,border:Gt.errorBorder,color:Gt.errorText,fontSize:10,fontWeight:700},children:"REJECTED"}):_e==="approved"&&!(ne!=null&&ne.isActive)?M.jsx("span",{style:{...wv,background:"color-mix(in oklch, var(--mu-color-interactive) 12%, transparent)",border:"1px solid color-mix(in oklch, var(--mu-color-interactive) 25%, transparent)",color:"var(--mu-color-interactive)",fontSize:10,fontWeight:700},children:"APPROVED"}):null})()]}),M.jsxs("div",{style:{position:"relative"},children:[M.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",padding:4,color:Gt.textMuted,fontSize:16},onClick:()=>Lm(ne=>!ne),title:"Technical details",children:M.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"currentColor",children:M.jsx("path",{d:"M7.5 1.5a6 6 0 100 12 6 6 0 000-12zM7 5h1v1H7V5zm0 2h1v4H7V7z"})})}),qg?M.jsxs("div",{style:{...wnt,background:Gt.dialogBg,border:Gt.dialogBorder,boxShadow:Gt.dialogShadow,color:Gt.textSecondary},children:[a?M.jsxs("span",{style:{fontSize:11},children:["Tenant: ",a]}):null,r?M.jsxs("span",{style:{fontSize:11,wordBreak:"break-all"},children:["API: ",r]}):null,!a&&!r?M.jsx("span",{style:{fontSize:11},children:"No API configured"}):null]}):null]})]}):null,nn?M.jsxs("div",{style:{padding:"8px 16px",background:"var(--mu-color-warning-bg)",borderBottom:"1px solid var(--mu-color-warning-border)",color:Gt.warningText,fontSize:12,display:"flex",alignItems:"center",gap:8},children:[M.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:M.jsx("path",{d:"M8 1l7 14H1L8 1zm-.5 5v4h1V6h-1zm0 5v1h1v-1h-1z"})}),M.jsxs("span",{children:["Viewing version v",f," (read-only)"]}),M.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:6},children:[M.jsx("button",{type:"button",onClick:()=>{if(!r||!l||f==null)return;const ne=r.replace(/\/$/,""),_e=fd(void 0,{tenantId:a});_e.set("Content-Type","application/json"),fetch(`${ne}/rulesets/${encodeURIComponent(l)}/versions`,{method:"POST",headers:_e,body:JSON.stringify({sourceVersion:f})}).then(st=>{if(!st.ok)throw new Error("restore failed");return st.json()}).then(st=>{Xe(0),xe(0,!1),st.version!=null&&(p==null||p(st.version))}).catch(()=>{})},style:{fontSize:11,padding:"4px 12px",borderRadius:6,fontWeight:600,cursor:"pointer",background:"var(--mu-color-success-bg)",border:"1px solid var(--mu-color-success-border)",color:"var(--mu-color-success-text)"},children:"Restore as New Version"}),M.jsx("button",{type:"button",onClick:()=>p==null?void 0:p(null),style:{fontSize:11,padding:"4px 12px",borderRadius:6,fontWeight:600,cursor:"pointer",background:Gt.actionPrimaryBg,border:Gt.actionPrimaryBorder,color:Gt.textPrimary},children:"Back to Active"})]})]}):null,M.jsxs("section",{ref:Bo,style:{...Kit,...nnt(xn,!!($t||Mr),ns,_n),...qh},children:[M.jsxs("aside",{"data-testid":"rule-flow-left-panel",style:{...snt,background:Gt.sidebarBg,border:Gt.sidebarBorder,width:_n?48:ns,transition:ea.current?"none":"width 200ms ease",overflow:_n?"hidden":"auto",position:"relative"},children:[M.jsxs("div",{style:{padding:"var(--mu-space-sm)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[!_n&&M.jsx("strong",{style:{fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-semibold)",color:Gt.textPrimary},children:"Node Library"}),M.jsx("button",{type:"button",title:_n?"Expand Node Library":"Collapse Node Library",onClick:()=>uo(ne=>!ne),style:{background:"transparent",border:"none",cursor:"pointer",padding:4,borderRadius:6,fontSize:14,color:Gt.textMuted,lineHeight:1,marginLeft:_n?"auto":void 0,marginRight:_n?"auto":void 0},children:_n?"›":"«"})]}),_n?M.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:4,padding:"8px 0"},children:Object.keys(TX).map(ne=>M.jsx("div",{title:_L[ne],style:{width:32,height:32,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",cursor:"default",fontSize:16},children:M.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:hM[ne],style:{flexShrink:0},children:M.jsx("path",{d:kX[ne]})})},ne))}):Pl,!_n&&M.jsx("div",{style:{position:"absolute",right:-6,top:0,bottom:0,width:12,cursor:"col-resize",zIndex:5,display:"flex",alignItems:"center",justifyContent:"center"},onPointerDown:Eb,onPointerMove:Cs,onPointerUp:Fy,children:M.jsx("div",{"data-testid":"sidebar-resize-grip",style:{display:"flex",flexDirection:"column",alignItems:"center",gap:3,padding:"4px 2px",borderRadius:4,background:"transparent",transition:"background 150ms"},onPointerEnter:ne=>{ne.currentTarget.style.background="color-mix(in oklch, var(--mu-color-interactive) 15%, transparent)"},onPointerLeave:ne=>{ne.currentTarget.style.background="transparent"},children:[0,1,2].map(ne=>M.jsx("div",{style:{width:4,height:4,borderRadius:"50%",background:"var(--mu-color-border-subtle, var(--mu-text-muted))"}},ne))})})]}),M.jsxs("div",{ref:vo,style:{...Yit,...ant(xn),height:Lb,background:Gt.canvasGradient,display:"flex",flexDirection:"column"},"data-testid":"rule-flow-canvas","data-node-count":O.length,"data-edge-count":D.length,onDragOver:bO,onDrop:z1,children:[M.jsx("style",{children:`
|
|
727
727
|
.mu-node-running {
|
|
728
728
|
animation: muNodePulse 0.8s ease-in-out infinite;
|
|
729
729
|
}
|