@muonroi/ui-engine-rule-components 0.1.16 → 0.1.17

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.
@@ -351,7 +351,7 @@ React keys must be passed directly to JSX without using spread:
351
351
  constructor(\${params}) {
352
352
  \${}
353
353
  }
354
- }`,{label:"class",detail:"definition",type:"keyword"}),ba('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),ba('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],g9=M5.concat([ba("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),ba("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),ba("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),$5=new EW,A5=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function jv(n){return(e,t)=>{let r=e.node.getChild("VariableDefinition");return r&&t(r,n),!0}}const v9=["FunctionDeclaration"],y9={FunctionDeclaration:jv("function"),ClassDeclaration:jv("class"),ClassExpression:()=>!0,EnumDeclaration:jv("constant"),TypeAliasDeclaration:jv("type"),NamespaceDeclaration:jv("namespace"),VariableDefinition(n,e){n.matchContext(v9)||e(n,"variable")},TypeDefinition(n,e){e(n,"type")},__proto__:null};function Q5(n,e){let t=$5.get(e);if(t)return t;let r=[],i=!0;function s(l,c){let h=n.sliceString(l.from,l.to);r.push({label:h,type:c})}return e.cursor(kr.IncludeAnonymous).iterate(l=>{if(i)i=!1;else if(l.name){let c=y9[l.name];if(c&&c(l,s)||A5.has(l.name))return!1}else if(l.to-l.from>8192){for(let c of Q5(n,l.node))r.push(c);return!1}}),$5.set(e,r),r}const D5=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,L5=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function O9(n){let e=xo(n.state).resolveInner(n.pos,-1);if(L5.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&D5.test(n.state.sliceDoc(e.from,e.to));if(!t&&!n.explicit)return null;let r=[];for(let i=e;i;i=i.parent)A5.has(i.name)&&(r=r.concat(Q5(n.state.doc,i)));return{options:r,from:t?e.from:n.pos,validFor:D5}}const $d=Cv.define({name:"javascript",parser:m9.configure({props:[Ex.add({IfStatement:Ev({except:/^\s*({|else\b)/}),TryStatement:Ev({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:WW,SwitchBody:n=>{let e=n.textAfter,t=/^\s*\}/.test(e),r=/^\s*(case|default)\b/.test(e);return n.baseIndent+(t?0:r?1:2)*n.unit},Block:XW({closing:"}"}),ArrowFunction:n=>n.baseIndent+n.unit,"TemplateString BlockComment":()=>null,"Statement Property":Ev({except:/^\s*{/}),JSXElement(n){let e=/^\s*<\//.test(n.textAfter);return n.lineIndent(n.node.from)+(e?0:n.unit)},JSXEscape(n){let e=/\s*\}/.test(n.textAfter);return n.lineIndent(n.node.from)+(e?0:n.unit)},"JSXOpenTag JSXSelfClosingTag"(n){return n.column(n.node.from)+n.unit}}),JQ.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":eD,BlockComment(n){return{from:n.from+2,to:n.to-2}},JSXElement(n){let e=n.firstChild;if(!e||e.name=="JSXSelfClosingTag")return null;let t=n.lastChild;return{from:e.to,to:t.type.isError?n.to:t.from}},"JSXSelfClosingTag JSXOpenTag"(n){var e;let t=(e=n.firstChild)===null||e===void 0?void 0:e.nextSibling,r=n.lastChild;return!t||t.type.isError?null:{from:t.to,to:r.type.isError?n.to:r.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),z5={test:n=>/^JSX/.test(n.name),facet:hC({commentTokens:{block:{open:"{/*",close:"*/}"}}})},x9=$d.configure({dialect:"ts"},"typescript"),b9=$d.configure({dialect:"jsx",props:[pC.add(n=>n.isTop?[z5]:void 0)]}),w9=$d.configure({dialect:"jsx ts",props:[pC.add(n=>n.isTop?[z5]:void 0)]},"typescript");let N5=n=>({label:n,type:"keyword"});const j5="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(N5),S9=j5.concat(["declare","implements","private","protected","public"].map(N5));function k9(n={}){let e=n.jsx?n.typescript?w9:b9:n.typescript?x9:$d,t=n.typescript?g9.concat(S9):M5.concat(j5);return new YQ(e,[$d.data.of({autocomplete:R7(L5,n5(t))}),$d.data.of({autocomplete:O9}),n.jsx?E9:[]])}function C9(n){for(;;){if(n.name=="JSXOpenTag"||n.name=="JSXSelfClosingTag"||n.name=="JSXFragmentTag")return n;if(n.name=="JSXEscape"||!n.parent)return null;n=n.parent}}function I5(n,e,t=n.length){for(let r=e==null?void 0:e.firstChild;r;r=r.nextSibling)if(r.name=="JSXIdentifier"||r.name=="JSXBuiltin"||r.name=="JSXNamespacedName"||r.name=="JSXMemberExpression")return n.sliceString(r.from,Math.min(r.to,t));return""}const T9=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),E9=yt.inputHandler.of((n,e,t,r,i)=>{if((T9?n.composing:n.compositionStarted)||n.state.readOnly||e!=t||r!=">"&&r!="/"||!$d.isActiveAt(n.state,e,-1))return!1;let s=i(),{state:l}=s,c=l.changeByRange(h=>{var m;let{head:v}=h,y=xo(l).resolveInner(v-1,-1),x;if(y.name=="JSXStartTag"&&(y=y.parent),!(l.doc.sliceString(v-1,v)!=r||y.name=="JSXAttributeValue"&&y.to>v)){if(r==">"&&y.name=="JSXFragmentTag")return{range:h,changes:{from:v,insert:"</>"}};if(r=="/"&&y.name=="JSXStartCloseTag"){let S=y.parent,E=S.parent;if(E&&S.from==v-2&&((x=I5(l.doc,E.firstChild,v))||((m=E.firstChild)===null||m===void 0?void 0:m.name)=="JSXFragmentTag")){let k=`${x}>`;return{range:Qe.cursor(v+k.length,-1),changes:{from:v,insert:k}}}}else if(r==">"){let S=C9(y);if(S&&S.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(l.doc.sliceString(v,v+2))&&(x=I5(l.doc,S,v)))return{range:h,changes:{from:v,insert:`</${x}>`}}}}return{range:h}});return c.changes.empty?!1:(n.dispatch([s,l.update(c,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),_9=uC({String:Ce.string,Number:Ce.number,"True False":Ce.bool,PropertyName:Ce.propertyName,Null:Ce.null,", :":Ce.separator,"[ ]":Ce.squareBracket,"{ }":Ce.brace}),R9=Nv.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:[_9],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}),P9=Cv.define({name:"json",parser:R9.configure({props:[Ex.add({Object:Ev({except:/^\s*\}/}),Array:Ev({except:/^\s*\]/})}),JQ.add({"Object Array":eD})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function M9(){return new YQ(P9)}function B5(n){switch(n){case"feel":return SY;case"liquid":return TY;case"scriban":return RY;case"javascript":return k9();case"json":return M9();case"plain-text":return[]}}const Z5=new Gc,U5=new Gc,$9=new Gc,V5=new Gc;function YC({value:n,language:e,readOnly:t,onChange:r,onInsertToken:i,extensions:s,minHeight:l,root:c,singleLine:h=!1,placeholderText:m}){const v=l??(h?36:180),y=q.useRef(null),x=q.useRef(null),S=q.useRef(r),E=q.useRef(i);S.current=r,E.current=i,q.useEffect(()=>{if(!y.current)return;const R=[...h?[]:[xW(),UX()],jX(),GX(),eW(),rH(),lY(),SH(),ux.of([...E7,...$H,...fY]),yt.updateListener.of(A=>{A.docChanged&&S.current(A.state.doc.toString())}),Z5.of([yt.editable.of(!t),Mn.readOnly.of(t)]),U5.of(B5(e)),$9.of([]),V5.of(s??[]),...h?[yt.theme({"&":{maxHeight:`${v}px`},".cm-scroller":{overflow:"hidden"},".cm-content":{padding:"4px 8px"},".cm-gutters":{display:"none"}}),Mn.transactionFilter.of(A=>A.newDoc.lines>1?[]:A)]:[],...m?[WX(m)]:[]],P=Mn.create({doc:n,extensions:R}),Q=new yt({state:P,parent:y.current,root:c});return x.current=Q,E.current&&E.current({insert:A=>{const L=Q.state.selection.main.head;Q.dispatch({changes:{from:L,insert:A},selection:{anchor:L+A.length}}),Q.focus()}}),()=>{Q.destroy(),x.current=null}},[c]),q.useEffect(()=>{const R=x.current;if(!R)return;const P=R.state.doc.toString();P!==n&&R.dispatch({changes:{from:0,to:P.length,insert:n}})},[n]),q.useEffect(()=>{const R=x.current;R&&R.dispatch({effects:U5.reconfigure(B5(e))})},[e]),q.useEffect(()=>{const R=x.current;R&&R.dispatch({effects:Z5.reconfigure([yt.editable.of(!t),Mn.readOnly.of(t)])})},[t]),q.useEffect(()=>{const R=x.current;R&&R.dispatch({effects:V5.reconfigure(s??[])})},[s]);const k={minHeight:`${v}px`,border:"1px solid rgba(148, 163, 184, 0.24)",borderRadius:h?"6px":"14px",overflow:"hidden",...h?{marginBottom:0}:{}};return C.jsx("div",{ref:y,style:k})}function A9({value:n,onChange:e,onReset:t,tokens:r,editorRoot:i}){return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",background:r.sidebarBg,borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`},children:[C.jsx("span",{style:{fontSize:12,fontWeight:600,color:r.textPrimary},children:"Input Data (JSON)"}),t?C.jsx("button",{type:"button",onClick:t,style:{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:r.textSecondary,textDecoration:"underline",padding:"2px 4px"},children:"Reset to Schema"}):null]}),C.jsx(YC,{value:n,language:"json",readOnly:!1,onChange:e,minHeight:160,singleLine:!1,root:i,placeholderText:'{ "key": "value" }'})]})}function F5({title:n,count:e,defaultExpanded:t,headerRight:r,children:i}){const[s,l]=q.useState(t);return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsxs("div",{role:"button",tabIndex:0,onClick:()=>l(!s),onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),l(!s))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[C.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:s?"▼":"▶"}),C.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:n}),e!==void 0?C.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]}),r]}),s?i:null]})}function Q9({entry:n,tokens:e,onShowFullFactBag:t}){var l,c,h;const r=n.businessFacts?n.businessFacts:n.outputs?Object.fromEntries(Object.entries(n.outputs).filter(([m])=>!m.startsWith("__graph.")&&!m.startsWith("__node.")&&!["executed","passed","errored","result"].includes(m))):{},i=Object.keys(r),s=((l=n.status)==null?void 0:l.elapsedMs)??n.elapsedMs;return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[C.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:m=>{m.currentTarget.style.textDecoration="underline"},onMouseLeave:m=>{m.currentTarget.style.textDecoration="none"},children:"< Back to Full FactBag"}),C.jsxs("div",{style:{padding:"6px 8px",borderRadius:6,background:"color-mix(in oklch, var(--mu-border-subtle) 40%, transparent)"},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:(c=n.status)!=null&&c.message||n.errors&&n.errors.length>0?6:0},children:[C.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:n.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:n.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:n.isSuccess?"✓":"✗"}),C.jsx("span",{style:{fontSize:12,fontWeight:600,color:n.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:n.isSuccess?"Passed":"Failed"}),s!==void 0?C.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:[s,"ms"]}):null]}),(h=n.status)!=null&&h.message?C.jsx("div",{style:{fontSize:12,color:n.isSuccess?e.textSecondary:"var(--mu-color-error)",...n.isSuccess?{}:{borderLeft:"3px solid var(--mu-color-error)",paddingLeft:8}},children:n.status.message}):null,n.errors&&n.errors.length>0?C.jsx("div",{style:{marginTop:4,display:"flex",flexDirection:"column",gap:2},children:n.errors.map((m,v)=>C.jsx("div",{style:{fontSize:11,color:"var(--mu-color-error)",borderLeft:"3px solid var(--mu-color-error)",paddingLeft:8},children:m},v))}):null]}),C.jsx(F5,{title:"Output",count:n.changedKeys?n.changedKeys.length:void 0,defaultExpanded:!0,children:i.length>0?C.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:i.map(m=>C.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",fontSize:11},children:[C.jsxs("span",{style:{fontWeight:600,color:e.textSecondary},children:[m,":"]}),C.jsx("span",{style:{color:e.textPrimary},children:typeof r[m]=="object"&&r[m]!==null?JSON.stringify(r[m]):String(r[m]??"")})]},m))}):C.jsx("div",{style:{padding:"4px 8px",fontSize:11,color:e.textMuted,fontStyle:"italic"},children:"No output facts"})}),C.jsx(F5,{title:"Input",defaultExpanded:!1,children:n.inputSnapshot?C.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(n.inputSnapshot,null,2)}):C.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 D9({result:n,loading:e,error:t,onSelectNode:r,onClose:i,tokens:s}){const[l,c]=q.useState(null),h=n==null?void 0:n.results.find(y=>y.ruleName===l),m=(n==null?void 0:n.results.filter(y=>y.isSuccess).length)??0,v=(n==null?void 0:n.results.filter(y=>!y.isSuccess).length)??0;return C.jsxs("div",{style:{borderTop:`2px solid ${s.sidebarBorder.replace("1px solid ","")}`,height:280,overflow:"hidden",display:"flex",flexDirection:"column",background:s.inspectorBg},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,flexShrink:0},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsx("span",{style:{fontSize:13,fontWeight:600,color:s.textPrimary},children:"Dry Run Results"}),n?C.jsxs("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,background:n.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:n.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)",fontWeight:600},children:[n.executionTimeMs,"ms"]}):null]}),C.jsx("button",{type:"button",onClick:i,style:{background:"transparent",border:"none",cursor:"pointer",color:s.textMuted,fontSize:14,padding:2},title:"Close results",children:"X"})]}),C.jsx("div",{style:{flex:1,overflow:"hidden"},children:e?C.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:s.textSecondary,fontSize:13},children:"Executing dry run..."}):t?C.jsxs("div",{style:{padding:16,color:s.errorText,fontSize:13},children:[C.jsx("strong",{children:"Error:"})," ",t]}):n?C.jsxs("div",{style:{display:"flex",height:"100%"},children:[C.jsx("div",{style:{width:"60%",overflow:"auto",borderRight:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`},children:C.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12},children:[C.jsx("thead",{children:C.jsxs("tr",{style:{borderBottom:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,position:"sticky",top:0,background:s.inspectorBg,zIndex:1},children:[C.jsx("th",{style:{...qC,color:s.textSecondary},children:"Node"}),C.jsx("th",{style:{...qC,color:s.textSecondary,width:60},children:"Status"}),C.jsx("th",{style:{...qC,color:s.textSecondary,width:80},children:"Evaluation"})]})}),C.jsx("tbody",{children:n.results.map(y=>C.jsxs("tr",{onClick:()=>{const x=y.ruleName===l?null:y.ruleName;c(x),x&&(r==null||r(x))},style:{cursor:"pointer",borderBottom:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,background:l===y.ruleName?s.overlayItemSelectedBg:"transparent"},children:[C.jsxs("td",{style:{padding:"6px 12px",color:s.textPrimary,fontWeight:500},children:[y.ruleName,y.errors&&y.errors.length>0?C.jsx("div",{style:{fontSize:11,color:s.errorText,marginTop:2},children:y.errors[0]}):null]}),C.jsx("td",{style:{padding:"6px 8px",textAlign:"center"},children:C.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:y.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:y.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:y.isSuccess?"✓":"✗"})}),C.jsx("td",{style:{padding:"6px 8px",textAlign:"center",fontSize:11,color:s.textSecondary},children:y.evaluationResult===!0?"true":y.evaluationResult===!1?"false":y.evaluationResult??"—"})]},y.ruleName))})]})}),C.jsx("div",{style:{width:"40%",overflow:"auto",padding:8},children:h?C.jsx(Q9,{entry:h,tokens:s,onShowFullFactBag:()=>c(null)}):C.jsxs(C.Fragment,{children:[C.jsx("div",{style:{fontSize:11,color:s.textSecondary,marginBottom:4,fontWeight:600},children:"Full FactBag"}),C.jsx("pre",{style:{margin:0,fontSize:11,lineHeight:1.5,color:s.textPrimary,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)"},children:JSON.stringify((n==null?void 0:n.factBagClean)??(n==null?void 0:n.factBag)??{},null,2)})]})})]}):null}),n?C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"6px 12px",borderTop:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,fontSize:12,flexShrink:0},children:[C.jsxs("span",{style:{color:"var(--mu-color-success-text)",fontWeight:600},children:[m," passed"]}),C.jsxs("span",{style:{color:"var(--mu-color-error)",fontWeight:600},children:[v," failed"]}),C.jsxs("span",{style:{color:s.textMuted,marginLeft:"auto"},children:["Total: ",n.executionTimeMs,"ms"]})]}):null]})}const qC={padding:"6px 12px",textAlign:"left",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px"};function L9({nodeName:n,isSuccess:e,evaluationResult:t,outputs:r,errors:i,position:s,tokens:l}){const c=e?"var(--mu-color-success)":"var(--mu-color-error)",h=e?"var(--mu-color-success-bg)":"var(--mu-color-error-bg)",m=e?"Pass":"Fail",v=r!=null&&Object.keys(r).length>0,y=i!=null&&i.length>0;return C.jsxs("div",{style:{position:"fixed",left:s.x+12,top:s.y-8,background:l.inspectorBg,border:`1px solid ${l.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:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[C.jsx("span",{style:{fontWeight:600,color:l.textPrimary},children:n}),C.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:12,background:h,color:c,fontWeight:600,fontSize:11},children:m})]}),t!==void 0?C.jsxs("div",{style:{color:l.textSecondary,marginBottom:4},children:["Evaluation: ",String(t)]}):null,v?C.jsxs("div",{style:{marginBottom:4},children:[C.jsx("div",{style:{color:l.textSecondary,marginBottom:2},children:"Outputs:"}),C.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:l.textPrimary},children:JSON.stringify(r,null,2)})]}):null,y?C.jsxs("div",{children:[C.jsx("div",{style:{color:"var(--mu-color-error)",marginBottom:2},children:"Errors:"}),i.map((x,S)=>C.jsx("div",{style:{color:"var(--mu-color-error)",fontSize:11},children:x},S))]}):null]})}const Mp={trigger:"Trigger",condition:"Condition",action:"Action","decision-table":"Decision Table","sub-flow":"Sub Flow",liquid:"Liquid",connector:"Connector",end:"End"},Iv={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)"},X5={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"},z9={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 Ai(n){var t,r,i,s,l,c;if(!n||typeof n!="object")return Kw();const e=n;return{nodes:Array.isArray(e.nodes)?e.nodes.map((h,m)=>I9(h,m)):[],edges:Array.isArray(e.edges)?e.edges.filter(h=>!!h&&typeof h.source=="string"&&typeof h.target=="string").map((h,m)=>({id:typeof h.id=="string"&&h.id?h.id:`edge-${m+1}`,source:h.source,target:h.target,label:typeof h.label=="string"?h.label:void 0,edgeType:Vx(h.edgeType)})):[],metadata:{version:Math.max(1,((t=e.metadata)==null?void 0:t.version)??1),tenantId:(r=e.metadata)==null?void 0:r.tenantId,ruleSetCode:(i=e.metadata)==null?void 0:i.ruleSetCode,workflowName:(s=e.metadata)==null?void 0:s.workflowName,lastModifiedAt:(l=e.metadata)==null?void 0:l.lastModifiedAt,lastModifiedBy:(c=e.metadata)==null?void 0:c.lastModifiedBy}}}function N9(n){return JSON.stringify(Ai(n),null,2)}function j9(n){let e;try{e=JSON.parse(n)}catch(l){throw new Error(`Invalid rule flow JSON: ${l.message}`)}if(e&&typeof e=="object"){const l=e;if(l.ruleSetJson&&typeof l.ruleSetJson=="string")try{e=JSON.parse(l.ruleSetJson)}catch{}const c=e;c.ruleSet&&typeof c.ruleSet=="object"&&(e=c.ruleSet);const h=e;h.flowGraph&&typeof h.flowGraph=="object"&&(e=h.flowGraph)}const t=Ai(e),r=t.nodes.filter(l=>l.type==="trigger").length,i=t.nodes.filter(l=>l.type==="end").length;if(r!==1)throw new Error("Imported flow must contain exactly one trigger node.");if(i<1)throw new Error("Imported flow must contain at least one end node.");const s=new Set(t.nodes.map(l=>l.id));if(s.size!==t.nodes.length)throw new Error("Imported flow contains duplicate node ids.");for(const l of t.edges)if(!s.has(l.source)||!s.has(l.target))throw new Error(`Imported flow edge '${l.id}' references missing nodes.`);return t}function Yi(n){const e=Ai(n);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:GC(t.data)})).sort((t,r)=>(t.id??"").localeCompare(r.id??"")),edges:e.edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??"",edgeType:t.edgeType})).sort((t,r)=>(t.id??"").localeCompare(r.id??"")),metadata:{version:e.metadata.version,tenantId:e.metadata.tenantId??"",ruleSetCode:e.metadata.ruleSetCode??"",workflowName:e.metadata.workflowName??""}})}function I9(n,e){const t=tT(n.type),r=GC(n.data),i=KC(r.expression,n.feelExpression,t),s=n.position??{x:Number.NaN,y:Number.NaN};return{id:typeof n.id=="string"&&n.id?n.id:`node-${e+1}`,type:t,label:typeof n.label=="string"&&n.label?n.label:X5[t],feelExpression:i.language==="feel"?i.body:void 0,ruleCode:typeof n.ruleCode=="string"?n.ruleCode:void 0,expressionLanguage:n.expressionLanguage==="feel"||n.expressionLanguage==="javascript"?n.expressionLanguage:void 0,position:{x:Number.isFinite(s==null?void 0:s.x)?s.x:40+e*48,y:Number.isFinite(s==null?void 0:s.y)?s.y:60+e%4*88},data:{...r,expression:i}}}function GC(n){var s;const e=n&&typeof n=="object"?n:{},t=Array.isArray(e.outputFields)?e.outputFields.map($p).filter(Boolean):[],r=B9(e.contractOverride),i=(s=r==null?void 0:r.responseFields)!=null&&s.length?r.responseFields:t.length?t:void 0;return{...e,description:typeof e.description=="string"?e.description:void 0,expression:KC(e.expression,typeof e.feelExpression=="string"?e.feelExpression:void 0),contractRef:Z9(e.contractRef),requestContract:Bv(e.requestContract),responseContract:Bv(e.responseContract),contractOverride:r||i?{...r,responseFields:i}:void 0,inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(Zx).filter(Boolean):void 0,contractLayer:q9(e.contractLayer),dependsOn:Array.isArray(e.dependsOn)?e.dependsOn.filter(l=>typeof l=="string"&&l.trim().length>0).map(l=>l.trim()):void 0,order:typeof e.order=="number"&&Number.isFinite(e.order)?e.order:void 0,conditionConfig:U9(e.conditionConfig),subFlowConfig:V9(e.subFlowConfig),liquidConfig:X9(e.liquidConfig),connectorConfig:(()=>{const l=F9(e.connectorConfig);return l&&!l.connectorType&&typeof e.connectorType=="string"&&(l.connectorType=e.connectorType),l})()}}function B9(n){if(!n||typeof n!="object")return;const e=n;return{requestFields:Array.isArray(e.requestFields)?e.requestFields.map($p).filter(Boolean):void 0,responseFields:Array.isArray(e.responseFields)?e.responseFields.map($p).filter(Boolean):void 0}}function Z9(n){if(!n||typeof n!="object")return;const e=n,t=e.sourceType,r=e.sourceCode;if(!(typeof t!="string"||typeof r!="string"||!r.trim()))return{sourceType:tq(t),sourceCode:r.trim(),label:typeof e.label=="string"?e.label:void 0}}function Bv(n){if(!n||typeof n!="object")return;const e=n,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($p).filter(Boolean):[]}}function $p(n){if(!n||typeof n!="object")return null;const e=n,t=typeof e.path=="string"&&e.path.trim()?e.path.trim():"",r=typeof e.label=="string"&&e.label.trim()?e.label.trim():t,i=typeof e.dataType=="string"&&e.dataType.trim()?e.dataType.trim():"unknown";return t?{path:t,label:r,dataType:i,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"&&eT(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($p).filter(Boolean):void 0}:null}function KC(n,e,t="action"){if(n&&typeof n=="object"){const r=n;if(typeof r.language=="string"&&typeof r.body=="string")return{language:q5(r.language),body:r.body}}return typeof e=="string"&&e.trim()?{language:"feel",body:e}:JC(t)}function U9(n){if(!n||typeof n!="object")return;const e=n;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 V9(n){if(!n||typeof n!="object")return;const e=n;return{targetFlowCode:typeof e.targetFlowCode=="string"?e.targetFlowCode:void 0,childTriggerSchema:Bv(e.childTriggerSchema),inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(Zx).filter(Boolean):[],outputMappings:Array.isArray(e.outputMappings)?e.outputMappings.map(Zx).filter(Boolean):[]}}function F9(n){if(!n||typeof n!="object")return;const e=n,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(i=>["url","method","body","operation","webhookUrl","to","key","headers"].includes(i))?(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 X9(n){if(!n||typeof n!="object")return;const e=n;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 Zx(n){if(!n||typeof n!="object")return null;const e=n;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"?q5(e.language):void 0}}function W9(n){const e=Zx(n);if(!e||!n||typeof n!="object")return e;const t=n;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 H9(n){if(!n||typeof n!="object")return null;const e=n,t=typeof e.code=="string"&&e.code.trim()?e.code.trim():"",r=typeof e.message=="string"&&e.message.trim()?e.message.trim():"";return!t||!r?null:{code:t,message:r,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 Y9(n){if(!n||typeof n!="object")return;const e=n,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($p).filter(Boolean):[],mappings:Array.isArray(e.mappings)?e.mappings.map(W9).filter(Boolean):[]}}function q9(n){if(!n||typeof n!="object")return;const e=n;return{upstreamScope:Bv(e.upstreamScope),effectiveInput:Y9(e.effectiveInput),outputContract:Bv(e.outputContract),validationIssues:Array.isArray(e.validationIssues)?e.validationIssues.map(H9).filter(Boolean):void 0}}function iu(n){const e=typeof n.feelExpression=="string"?n.feelExpression:void 0;return KC(n.expression,e,n.nodeType??"action")}function fl(n){return n??{targetFlowCode:"",childTriggerSchema:void 0,inputMappings:[],outputMappings:[]}}function W5(n){return n??{outputFormat:"json"}}function qi(n,e=[]){var t;for(const r of n)e.push(r),(t=r.children)!=null&&t.length&&qi(r.children,e);return e}function H5(n,e,t){const r=e.trim();return r?{sourceType:(t==null?void 0:t.sourceType)??Ux(n),sourceCode:r,label:t==null?void 0:t.label}:t}const G9=new Set(["condition","action","decision-table","sub-flow","liquid","connector"]);function Y5(n){return n==="trigger"?"input-data":G9.has(n)?"data-mapping":"basic-info"}function Ux(n){return n==="sub-flow"?"flow":n==="decision-table"?"decision-table":n==="liquid"||n==="connector"?"api":"rule"}function K9(n){const e=["basic-info","input-data","data-mapping","output-data"];return n!=="trigger"&&n!=="end"&&e.push("logic"),e}function J9(n){return n==="basic-info"?"Basic Info":n==="input-data"?"Input Data":n==="data-mapping"?"Data Flow":n==="output-data"?"Output Data":"Logic"}function JC(n){return{language:n==="liquid"?"liquid":"feel",body:""}}const eq=new Set(Object.keys(Mp));function eT(n){return eq.has(n)}function tT(n){return typeof n=="string"&&eT(n)?n:"action"}function Vx(n){return n==="always"||n==="on-true"||n==="on-false"||n==="on-error"?n:"always"}function q5(n){if(typeof n!="string")return"feel";const e=n.trim().toLowerCase();return e==="feel"||e==="liquid"||e==="plain-text"||e==="javascript"||e==="scriban"?e:"feel"}function tq(n){return n==="rule"||n==="flow"||n==="decision-table"||n==="api"||n==="inline"?n:"rule"}function Zv(n){return Ai(n).nodes.map(t=>({id:t.id,type:t.type,position:t.position,data:{label:t.label,ruleCode:t.ruleCode,nodeType:tT(t.type),...t.data}}))}function G5(n){return Ai(n).edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??t.edgeType,data:{edgeType:t.edgeType}}))}function nq(n,e){switch(e.type){case"commit":{const t=Ai(e.graph);return Yi(t)===Yi(n.present)?n:{past:[...n.past,n.present].slice(-50),present:t,future:[]}}case"undo":{if(n.past.length===0)return n;const t=n.past[n.past.length-1];return{past:n.past.slice(0,-1),present:t,future:[n.present,...n.future]}}case"redo":{if(n.future.length===0)return n;const[t,...r]=n.future;return{past:[...n.past,n.present].slice(-50),present:t,future:r}}case"reset":return{past:[],present:Ai(e.graph),future:[]};default:return n}}function rq(n){const e=q.useMemo(()=>Ai(n),[n]),[t,r]=q.useReducer(nq,{past:[],present:e,future:[]}),i=q.useCallback(h=>{r({type:"commit",graph:h})},[]),s=q.useCallback(()=>{r({type:"undo"})},[]),l=q.useCallback(()=>{r({type:"redo"})},[]),c=q.useCallback(h=>{r({type:"reset",graph:h})},[]);return q.useMemo(()=>({present:t.present,canUndo:t.past.length>0,canRedo:t.future.length>0,commit:i,undo:s,redo:l,reset:c}),[i,l,c,t.future.length,t.past.length,t.present,s])}const iq=yt.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"}}),oq=_x.define([{tag:Ce.keyword,color:"var(--mu-node-condition)"},{tag:Ce.string,color:"var(--mu-color-success-text)"},{tag:Ce.number,color:"var(--mu-color-warning-text)"},{tag:Ce.bool,color:"var(--mu-node-condition)"},{tag:Ce.null,color:"var(--mu-text-muted)"},{tag:Ce.operator,color:"var(--mu-color-interactive)"},{tag:Ce.comment,color:"var(--mu-text-muted)",fontStyle:"italic"},{tag:Ce.function(Ce.variableName),color:"var(--mu-color-interactive)"},{tag:Ce.variableName,color:"var(--mu-text-primary)"},{tag:Ce.propertyName,color:"var(--mu-color-interactive-subtle)"},{tag:Ce.bracket,color:"var(--mu-text-secondary)"},{tag:Ce.special(Ce.variableName),color:"var(--mu-color-interactive)",fontWeight:"600"}]);YW(oq);const nT=[{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"}],aq=new Set(["true","false","null","if","then","else","for","in","return","some","every","satisfies","not","and","or","between","instance","of","function"]),sq=new Set(nT.map(n=>n.name)),K5=(()=>{const n=["Math","Logic","Collection","Type","String","Date"],e=new Map;for(const t of n)e.set(t,[]);for(const t of nT)e.get(t.group).push(t);return n.map(t=>({group:t,functions:e.get(t)}))})(),lq=()=>C.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:C.jsx("path",{d:"M6 3l5 5-5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),uq=()=>C.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:C.jsx("path",{d:"M3 6l5 5 5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),cq=K5.reduce((n,e)=>n+e.functions.length,0),fq={borderRadius:14,background:"rgba(241, 245, 249, 0.9)",border:"1px solid rgba(148, 163, 184, 0.18)",overflow:"hidden",marginTop:8},dq={padding:"10px 12px",cursor:"pointer",fontSize:12,fontWeight:600,color:"var(--mu-color-text-secondary)",display:"flex",alignItems:"center",gap:6,userSelect:"none"},hq={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"},pq={padding:"8px 12px 4px",fontSize:11,fontWeight:700,color:"var(--mu-color-text-muted)",textTransform:"uppercase",letterSpacing:"0.04em"},mq={padding:"6px 12px",cursor:"pointer",fontSize:12,borderRadius:8,display:"flex",alignItems:"baseline",gap:6},gq={fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",color:"var(--mu-color-interactive)",fontWeight:600},vq={color:"var(--mu-color-text-muted)",marginLeft:6,fontSize:11},yq={maxHeight:280,overflowY:"auto",paddingBottom:6};function Oq({onInsert:n,visible:e}){const[t,r]=q.useState(!1),[i,s]=q.useState(null),l=q.useCallback(()=>{r(c=>!c)},[]);return e?C.jsxs("div",{style:fq,children:[C.jsxs("div",{style:dq,onClick:l,role:"button",tabIndex:0,"aria-expanded":t,children:[t?C.jsx(uq,{}):C.jsx(lq,{}),C.jsx("span",{children:"FEEL Functions"}),C.jsx("span",{style:hq,children:cq})]}),t&&C.jsx("div",{style:yq,children:K5.map(c=>C.jsxs("div",{children:[C.jsx("div",{style:pq,children:c.group}),c.functions.map(h=>{const m=`${c.group}:${h.name}`,v=i===m;return C.jsxs("div",{style:{...mq,background:v?"color-mix(in oklch, var(--mu-color-interactive) 6%, transparent)":"transparent"},onClick:()=>n(h.template),onMouseEnter:()=>s(m),onMouseLeave:()=>s(null),title:h.description,role:"button",tabIndex:0,children:[C.jsx("span",{style:gq,children:h.name}),C.jsx("span",{style:vq,children:h.signature})]},m)})]},c.group))})]}):null}function J5(n){return yY({override:[t=>{const r=qi(n),s=t.state.sliceDoc(0,t.pos).match(/([a-zA-Z_][\w.]*)\.$/);if(s){const v=s[1],y=[];for(const x of r)x.path.startsWith(v+".")&&!x.path.substring(v.length+1).includes(".")&&y.push({label:x.path,type:"variable",detail:x.dataType,info:x.sourceNodeLabel?`From: ${x.sourceNodeLabel}`:void 0,boost:2});if(y.length>0)return{from:t.pos-v.length-1,options:y,validFor:/^[\w.]*$/}}const l=t.matchBefore(/[a-zA-Z_][\w.]*/);if(!l&&!t.explicit)return null;const c=l?l.from:t.pos,h=r.map(v=>({label:v.path,type:"variable",detail:v.dataType,info:v.sourceNodeLabel?`From: ${v.sourceNodeLabel}`:void 0,boost:1})),m=nT.map(v=>({label:v.name,type:"function",detail:v.signature,info:v.description,apply:v.template,boost:0}));return{from:c,options:[...h,...m],validFor:/^[\w.]*$/}}],activateOnTyping:!0})}class eL{constructor(e,t,r){this.from=e,this.to=t,this.diagnostic=r}}class Ad{constructor(e,t,r){this.diagnostics=e,this.panel=t,this.selected=r}static init(e,t,r){let i=r.facet(ou).markerFilter;i&&(e=i(e,r));let s=e.slice().sort((S,E)=>S.from-E.from||S.to-E.to),l=new dp,c=[],h=0,m=r.doc.iter(),v=0,y=r.doc.length;for(let S=0;;){let E=S==s.length?null:s[S];if(!E&&!c.length)break;let k,R;if(c.length)k=h,R=c.reduce((A,L)=>Math.min(A,L.to),E&&E.from>k?E.from:1e8);else{if(k=E.from,k>y)break;R=E.to,c.push(E),S++}for(;S<s.length;){let A=s[S];if(A.from==k&&(A.to>A.from||A.to==k))c.push(A),S++,R=Math.min(A.to,R);else{R=Math.min(A.from,R);break}}R=Math.min(R,y);let P=!1;if(c.some(A=>A.from==k&&(A.to==R||R==y))&&(P=k==R,!P&&R-k<10)){let A=k-(v+m.value.length);A>0&&(m.next(A),v=k);for(let L=k;;){if(L>=R){P=!0;break}if(!m.lineBreak&&v+m.value.length>L)break;L=v+m.value.length,v+=m.value.length,m.next()}}let Q=cL(c);if(P)l.add(k,k,pn.widget({widget:new Eq(Q),diagnostics:c.slice()}));else{let A=c.reduce((L,B)=>B.markClass?L+" "+B.markClass:L,"");l.add(k,R,pn.mark({class:"cm-lintRange cm-lintRange-"+Q+A,diagnostics:c.slice(),inclusiveEnd:c.some(L=>L.to>R)}))}if(h=R,h==y)break;for(let A=0;A<c.length;A++)c[A].to<=h&&c.splice(A--,1)}let x=l.finish();return new Ad(x,t,Ap(x))}}function Ap(n,e=null,t=0){let r=null;return n.between(t,1e9,(i,s,{spec:l})=>{if(!(e&&l.diagnostics.indexOf(e)<0))if(!r)r=new eL(i,s,e||l.diagnostics[0]);else{if(l.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new eL(r.from,s,r.diagnostic)}}),r}function tL(n,e){let t=e.pos,r=e.end||t,i=n.state.facet(ou).hideOn(n,t,r);if(i!=null)return i;let s=n.startState.doc.lineAt(e.pos);return!!(n.effects.some(l=>l.is(Fx))||n.changes.touchesRange(s.from,Math.max(s.to,r)))}function xq(n,e){return n.field(dl,!1)?e:e.concat(bn.appendConfig.of(hL))}function bq(n,e){return{effects:xq(n,[Fx.of(e)])}}const Fx=bn.define(),nL=bn.define(),rL=bn.define(),dl=Vo.define({create(){return new Ad(pn.none,null,null)},update(n,e){if(e.docChanged&&n.diagnostics.size){let t=n.diagnostics.map(e.changes),r=null,i=n.panel;if(n.selected){let s=e.changes.mapPos(n.selected.from,1);r=Ap(t,n.selected.diagnostic,s)||Ap(t,null,s)}!t.size&&i&&e.state.facet(ou).autoPanel&&(i=null),n=new Ad(t,i,r)}for(let t of e.effects)if(t.is(Fx)){let r=e.state.facet(ou).autoPanel?t.value.length?Xx.open:null:n.panel;n=Ad.init(t.value,r,e.state)}else t.is(nL)?n=new Ad(n.diagnostics,t.value?Xx.open:null,n.selected):t.is(rL)&&(n=new Ad(n.diagnostics,n.panel,t.value));return n},provide:n=>[Gk.from(n,e=>e.panel),yt.decorations.from(n,e=>e.diagnostics)]}),wq=pn.mark({class:"cm-lintRange cm-lintRange-active"});function Sq(n,e,t){let{diagnostics:r}=n.state.field(dl),i,s=-1,l=-1;r.between(e-(t<0?1:0),e+(t>0?1:0),(h,m,{spec:v})=>{if(e>=h&&e<=m&&(h==m||(e>h||t>0)&&(e<m||t<0)))return i=v.diagnostics,s=h,l=m,!1});let c=n.state.facet(ou).tooltipFilter;return i&&c&&(i=c(i,n.state)),i?{pos:s,end:l,above:n.state.doc.lineAt(s).to<l,create(){return{dom:iL(n,i)}}}:null}function iL(n,e){return Hl("ul",{class:"cm-tooltip-lint"},e.map(t=>lL(n,t,!1)))}const oL=n=>{let e=n.state.field(dl,!1);return!e||!e.panel?!1:(n.dispatch({effects:nL.of(!1)}),!0)},kq=Mi.fromClass(class{constructor(n){this.view=n,this.timeout=-1,this.set=!0;let{delay:e}=n.state.facet(ou);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let n=Date.now();if(n<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-n);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(ou);t.length&&Cq(t.map(r=>Promise.resolve(r(this.view))),r=>{this.view.state.doc==e.doc&&this.view.dispatch(bq(this.view.state,r.reduce((i,s)=>i.concat(s))))},r=>{Xo(this.view.state,r)})}}update(n){let e=n.state.facet(ou);(n.docChanged||e!=n.startState.facet(ou)||e.needsRefresh&&e.needsRefresh(n))&&(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 Cq(n,e,t){let r=[],i=-1;for(let s of n)s.then(l=>{r.push(l),clearTimeout(i),r.length==n.length?e(r):i=setTimeout(()=>e(r),200)},t)}const ou=pt.define({combine(n){return{sources:n.map(e=>e.source).filter(e=>e!=null),...yd(n.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:aL,tooltipFilter:aL,needsRefresh:(e,t)=>e?t?r=>e(r)||t(r):e:t,hideOn:(e,t)=>e?t?(r,i,s)=>e(r,i,s)||t(r,i,s):e:t,autoPanel:(e,t)=>e||t})}}});function aL(n,e){return n?e?(t,r)=>e(n(t,r),r):n:e}function Tq(n,e={}){return[ou.of({source:n,config:e}),kq,hL]}function sL(n){let e=[];if(n)e:for(let{name:t}of n){for(let r=0;r<t.length;r++){let i=t[r];if(/[a-zA-Z]/.test(i)&&!e.some(s=>s.toLowerCase()==i.toLowerCase())){e.push(i);continue e}}e.push("")}return e}function lL(n,e,t){var r;let i=t?sL(e.actions):[];return Hl("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Hl("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(n):e.message),(r=e.actions)===null||r===void 0?void 0:r.map((s,l)=>{let c=!1,h=S=>{if(S.preventDefault(),c)return;c=!0;let E=Ap(n.state.field(dl).diagnostics,e);E&&s.apply(n,E.from,E.to)},{name:m}=s,v=i[l]?m.indexOf(i[l]):-1,y=v<0?m:[m.slice(0,v),Hl("u",m.slice(v,v+1)),m.slice(v+1)],x=s.markClass?" "+s.markClass:"";return Hl("button",{type:"button",class:"cm-diagnosticAction"+x,onclick:h,onmousedown:h,"aria-label":` Action: ${m}${v<0?"":` (access key "${i[l]})"`}.`},y)}),e.source&&Hl("div",{class:"cm-diagnosticSource"},e.source))}class Eq extends Od{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Hl("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class uL{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=lL(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Xx{constructor(e){this.view=e,this.items=[];let t=i=>{if(!(i.ctrlKey||i.altKey||i.metaKey)){if(i.keyCode==27)oL(this.view),this.view.focus();else if(i.keyCode==38||i.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(i.keyCode==40||i.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(i.keyCode==36)this.moveSelection(0);else if(i.keyCode==35)this.moveSelection(this.items.length-1);else if(i.keyCode==13)this.view.focus();else if(i.keyCode>=65&&i.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:s}=this.items[this.selectedIndex],l=sL(s.actions);for(let c=0;c<l.length;c++)if(l[c].toUpperCase().charCodeAt(0)==i.keyCode){let h=Ap(this.view.state.field(dl).diagnostics,s);h&&s.actions[c].apply(e,h.from,h.to)}}else return;i.preventDefault()}},r=i=>{for(let s=0;s<this.items.length;s++)this.items[s].dom.contains(i.target)&&this.moveSelection(s)};this.list=Hl("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:r}),this.dom=Hl("div",{class:"cm-panel-lint"},this.list,Hl("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>oL(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(dl).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(dl),r=0,i=!1,s=null,l=new Set;for(e.between(0,this.view.state.doc.length,(c,h,{spec:m})=>{for(let v of m.diagnostics){if(l.has(v))continue;l.add(v);let y=-1,x;for(let S=r;S<this.items.length;S++)if(this.items[S].diagnostic==v){y=S;break}y<0?(x=new uL(this.view,v),this.items.splice(r,0,x),i=!0):(x=this.items[y],y>r&&(this.items.splice(r,y-r),i=!0)),t&&x.diagnostic==t.diagnostic?x.dom.hasAttribute("aria-selected")||(x.dom.setAttribute("aria-selected","true"),s=x):x.dom.hasAttribute("aria-selected")&&x.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)i=!0,this.items.pop();this.items.length==0&&(this.items.push(new uL(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),i=!0),s?(this.list.setAttribute("aria-activedescendant",s.id),this.view.requestMeasure({key:this,read:()=>({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:c,panel:h})=>{let m=h.height/this.list.offsetHeight;c.top<h.top?this.list.scrollTop-=(h.top-c.top)/m:c.bottom>h.bottom&&(this.list.scrollTop+=(c.bottom-h.bottom)/m)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),i&&this.sync()}sync(){let e=this.list.firstChild;function t(){let r=e;e=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;e!=r.dom;)t();e=r.dom.nextSibling}else this.list.insertBefore(r.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(dl),r=Ap(t.diagnostics,this.items[e].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:rL.of(r)})}static open(e){return new Xx(e)}}function Wx(n,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(n)}</svg>')`}function Hx(n){return Wx(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const _q=yt.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:Hx("#d11")},".cm-lintRange-warning":{backgroundImage:Hx("orange")},".cm-lintRange-info":{backgroundImage:Hx("#999")},".cm-lintRange-hint":{backgroundImage:Hx("#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 Rq(n){return n=="error"?4:n=="warning"?3:n=="info"?2:1}function cL(n){let e="hint",t=1;for(let r of n){let i=Rq(r.severity);i>t&&(t=i,e=r.severity)}return e}class fL extends rf{constructor(e){super(),this.diagnostics=e,this.severity=cL(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let r=this.diagnostics,i=e.state.facet(Yx).tooltipFilter;return i&&(r=i(r,e.state)),r.length&&(t.onmouseover=()=>Mq(e,t,r)),t}}function Pq(n,e){let t=r=>{let i=e.getBoundingClientRect();if(!(r.clientX>i.left-10&&r.clientX<i.right+10&&r.clientY>i.top-10&&r.clientY<i.bottom+10)){for(let s=r.target;s;s=s.parentNode)if(s.nodeType==1&&s.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",t),n.state.field(dL)&&n.dispatch({effects:iT.of(null)})}};window.addEventListener("mousemove",t)}function Mq(n,e,t){function r(){let l=n.elementAtHeight(e.getBoundingClientRect().top+5-n.documentTop);n.coordsAtPos(l.from)&&n.dispatch({effects:iT.of({pos:l.from,above:!1,clip:!1,create(){return{dom:iL(n,t),getCoords:()=>e.getBoundingClientRect()}}})}),e.onmouseout=e.onmousemove=null,Pq(n,e)}let{hoverTime:i}=n.state.facet(Yx),s=setTimeout(r,i);e.onmouseout=()=>{clearTimeout(s),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(s),s=setTimeout(r,i)}}function $q(n,e){let t=Object.create(null);for(let i of e){let s=n.lineAt(i.from);(t[s.from]||(t[s.from]=[])).push(i)}let r=[];for(let i in t)r.push(new fL(t[i]).range(+i));return hn.of(r,!0)}const Aq=hW({class:"cm-gutter-lint",markers:n=>n.state.field(rT),widgetMarker:(n,e,t)=>{let r=[];return n.state.field(rT).between(t.from,t.to,(i,s,l)=>{i>t.from&&i<t.to&&r.push(...l.diagnostics)}),r.length?new fL(r):null}}),rT=Vo.define({create(){return hn.empty},update(n,e){n=n.map(e.changes);let t=e.state.facet(Yx).markerFilter;for(let r of e.effects)if(r.is(Fx)){let i=r.value;t&&(i=t(i||[],e.state)),n=$q(e.state.doc,i.slice(0))}return n}}),iT=bn.define(),dL=Vo.define({create(){return null},update(n,e){return n&&e.docChanged&&(n=tL(e,n)?null:{...n,pos:e.changes.mapPos(n.pos)}),e.effects.reduce((t,r)=>r.is(iT)?r.value:t,n)},provide:n=>dx.from(n)}),Qq=yt.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:Wx('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:Wx('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:Wx('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),hL=[dl,yt.decorations.compute([dl],n=>{let{selected:e,panel:t}=n.field(dl);return!e||!t||e.from==e.to?pn.none:pn.set([wq.range(e.from,e.to)])}),lW(Sq,{hideOn:tL}),_q],Yx=pt.define({combine(n){return yd(n,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function Dq(n={}){return[Yx.of(n),rT,Aq,Qq,dL]}function Lq(n){return[Tq(t=>{const r=t.state.doc.toString(),i=[];if(!r.trim())return i.push({from:0,to:r.length||0,severity:"info",message:"Expression is empty"}),i;const s=[["(",")"],["[","]"],["{","}"]];for(const[k,R]of s){const P=[];for(let Q=0;Q<r.length;Q++){if(r[Q]==='"'){for(Q++;Q<r.length&&r[Q]!=='"';)r[Q]==="\\"&&Q++,Q++;continue}r[Q]===k?P.push(Q):r[Q]===R&&(P.length>0?P.pop():i.push({from:Q,to:Q+1,severity:"error",message:`Unmatched closing '${R}'`}))}for(const Q of P)i.push({from:Q,to:Q+1,severity:"error",message:`Unmatched opening '${k}'`})}let l=!1,c=0;for(let k=0;k<r.length;k++)r[k]==='"'&&(k===0||r[k-1]!=="\\")&&(l?l=!1:(l=!0,c=k));l&&i.push({from:c,to:c+1,severity:"error",message:"Unclosed string literal"});const h=qi(n),m=new Set(h.map(k=>k.path)),v=/[a-zA-Z_][\w]*/g;let y;const x=[];let S=-1;for(let k=0;k<r.length;k++)r[k]==='"'&&(k===0||r[k-1]!=="\\")&&(S<0?S=k:(x.push([S,k]),S=-1));const E=k=>x.some(([R,P])=>k>=R&&k<=P);for(;(y=v.exec(r))!==null;){const k=y[0],R=y.index;if(E(R)||aq.has(k)||sq.has(k)||/^\d/.test(k))continue;let P=k,Q=R+k.length;for(;Q<r.length&&r[Q]===".";){const j=r.substring(Q+1).match(/^[a-zA-Z_][\w]*/);if(j)P+="."+j[0],Q=Q+1+j[0].length,v.lastIndex=Q;else break}if(m.has(P))continue;let A=!1;for(const B of m)if(B.startsWith(P+".")||P.startsWith(B+".")){A=!0;break}if(A)continue;let L=!1;for(const B of m)if(B===k||B.startsWith(k+".")){L=!0;break}L||i.push({from:R,to:R+P.length,severity:"warning",message:`Unknown field reference: ${P}`})}return i},{delay:300}),Dq()]}const zq={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)"}},Nq={bg:"var(--mu-surface-raised)",text:"var(--mu-text-secondary)"};function Uv({dataType:n}){const e=zq[n.toLowerCase()]??Nq;return C.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:n.toLowerCase()})}function Qp({icon:n,message:e,actionHint:t,onAction:r}){return C.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:[C.jsx("span",{style:{fontSize:16},children:n??"ⓘ"}),C.jsx("span",{style:{color:"var(--mu-text-muted)",fontSize:13},children:e}),t&&r?C.jsx("span",{role:"button",tabIndex:0,onClick:r,onKeyDown:i=>{i.key==="Enter"&&r()},style:{color:"var(--mu-color-interactive)",cursor:"pointer",textDecoration:"underline",fontSize:13},children:t}):null]})}const jq={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 pL({field:n,depth:e,readOnly:t,onInsert:r,defaultExpanded:i=!0}){var S;const s=(((S=n.children)==null?void 0:S.length)??0)>0,[l,c]=q.useState(i),[h,m]=q.useState(!1),v=n.path.split("."),y=v[v.length-1],x=v.length>1?v.slice(0,-1).join(".")+".":"";return C.jsxs("div",{children:[C.jsxs("div",{style:{...jq,paddingLeft:e*20+8,backgroundColor:h?"var(--mu-surface-raised)":"transparent"},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),children:[s?C.jsx("span",{role:"button",tabIndex:0,onClick:E=>{E.stopPropagation(),c(!l)},onKeyDown:E=>{E.key==="Enter"&&c(!l)},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:l?"▼":"▶"}):C.jsx("span",{style:{width:16,flexShrink:0}}),C.jsxs("button",{type:"button",disabled:t,onClick:()=>r(n.path),style:{border:"none",background:"transparent",padding:0,cursor:t?"default":"pointer",fontSize:12,color:"var(--mu-text-primary)",textAlign:"left",fontFamily:"inherit"},children:[x?C.jsx("span",{style:{color:"var(--mu-text-secondary)"},children:x}):null,C.jsx("strong",{children:y})]}),C.jsx(Uv,{dataType:n.dataType}),n.sourceNodeLabel?C.jsx("span",{style:{fontSize:11,color:"var(--mu-text-secondary)",marginLeft:"auto"},children:n.sourceNodeLabel}):null]}),s&&l?C.jsx("div",{children:n.children.map(E=>C.jsx(pL,{field:E,depth:e+1,readOnly:t,onInsert:r,defaultExpanded:i},E.path))}):null]})}const Iq={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 qx({tooltip:n}){return C.jsx("span",{title:n,style:{display:"inline-flex",alignItems:"center",marginLeft:4,cursor:"help",color:"var(--mu-text-secondary)"},children:C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:C.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 Bq={display:"flex",flexDirection:"column",gap:8,padding:"10px 14px",background:"var(--mu-surface-raised)",border:"1px solid var(--mu-border-subtle)",borderRadius:12};function Zq(n){var h,m,v,y,x,S,E,k;const{selectedNode:e,contractLoadState:t,readOnly:r,inspectorTab:i,setInspectorTab:s,showSectionHeader:l=!0}=n,c=e==null?void 0:e.data.contractLayer;return C.jsxs("div",{style:eG,children:[l?C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Inspector"}),C.jsx("span",{children:e?`Editing ${Mp[e.data.nodeType]}`:"Select a node to edit it."})]}):null,e?C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0},children:[C.jsx("div",{role:"tablist","aria-label":"Node inspector sections",style:tG,children:K9(e.data.nodeType).map(R=>C.jsx("button",{role:"tab","aria-selected":R===i,type:"button",style:hG(R===i),onClick:()=>s(R),children:J9(R)},R))}),i==="basic-info"?C.jsx(Uq,{...n}):null,i==="input-data"?C.jsx(Hq,{title:"Input Scope",subtitle:((h=c==null?void 0:c.upstreamScope)==null?void 0:h.title)??"Everything available before this node executes.",contract:c==null?void 0:c.upstreamScope,loadState:t,readOnly:r,onInsert:n.onInsertExpressionToken,groupBySource:!0}):null,i==="data-mapping"?C.jsx(qq,{nodeType:e.data.nodeType,readOnly:r,upstreamFields:qi(((m=c==null?void 0:c.upstreamScope)==null?void 0:m.fields)??[]),targetFields:((v=c==null?void 0:c.effectiveInput)==null?void 0:v.fields)??[],rows:((y=c==null?void 0:c.effectiveInput)==null?void 0:y.mappings)??[],onInsert:n.onInsertExpressionToken,onChangeTargetFields:n.onChangeInputContract,onChange:n.onChangeEffectiveMappings,setInspectorTab:s,hasExpression:!!((S=(x=n.selectedExpression)==null?void 0:x.body)!=null&&S.trim())}):null,i==="output-data"?C.jsx(Gq,{nodeType:e.data.nodeType,contract:c==null?void 0:c.outputContract,upstreamScope:c==null?void 0:c.upstreamScope,issues:(c==null?void 0:c.validationIssues)??[],readOnly:r,onInsert:n.onInsertExpressionToken,onChange:n.onChangeOutputContract}):null,i==="logic"?C.jsx(Vq,{nodeType:e.data.nodeType,expression:n.selectedExpression,upstreamScope:c==null?void 0:c.upstreamScope,outputContract:c==null?void 0:c.outputContract,liquidOutput:(E=e.data.liquidConfig)==null?void 0:E.outputFormat,readOnly:r,apiBaseUrl:n.apiBaseUrl,onChangeLanguage:n.onUpdateExpressionLanguage,onChangeBody:n.onUpdateExpressionBody,onInsertRef:n.onSetInsertRef,shadowRoot:n.shadowRoot}):null,(k=c==null?void 0:c.validationIssues)!=null&&k.length?C.jsx(vL,{issues:c.validationIssues}):null,t.status==="error"?C.jsx("div",{style:sG,children:t.message}):null,r?null:C.jsx("button",{type:"button",style:aG,onClick:n.onDeleteNode,children:"Delete Node"})]}):C.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 Uq(n){var h,m,v,y,x,S,E;const{selectedNode:e,readOnly:t,flowOptions:r,decisionTableOptions:i,selectedDecisionTable:s,decisionTableLoadState:l}=n;if(!e)return C.jsx(C.Fragment,{});const c=e.data.dependsOn??[];return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("label",{style:wo,children:["Label",C.jsx("input",{style:Qi,value:e.data.label,disabled:t,onChange:k=>n.onUpdateLabel(k.target.value)})]}),C.jsxs("label",{style:wo,children:["Rule Code",C.jsx("input",{style:Qi,value:e.data.ruleCode??"",disabled:t,onChange:k=>n.onUpdateRuleCode(k.target.value)})]}),C.jsxs("label",{style:wo,children:["Description",C.jsx("textarea",{style:oT,value:String(e.data.description??""),disabled:t,placeholder:"Describe what this node does for documentation purposes",onChange:k=>n.onUpdateDescription(k.target.value)})]}),C.jsxs("div",{style:nG,children:[C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Contract Source",C.jsx(qx,{tooltip:"Determines where this node's input/output schema comes from"})]}),C.jsxs("select",{style:Qi,value:((h=e.data.contractRef)==null?void 0:h.sourceType)??Ux(e.data.nodeType),disabled:t,onChange:k=>{var R,P;return n.onUpdateContractRef({sourceType:k.target.value,sourceCode:((R=e.data.contractRef)==null?void 0:R.sourceCode)??e.data.ruleCode??"",label:(P=e.data.contractRef)==null?void 0:P.label})},children:[C.jsx("option",{value:"rule",children:"rule"}),C.jsx("option",{value:"flow",children:"flow"}),C.jsx("option",{value:"decision-table",children:"decision-table"}),C.jsx("option",{value:"api",children:"api"}),C.jsx("option",{value:"inline",children:"inline"})]}),C.jsx("span",{style:{fontSize:11,color:"var(--mu-text-muted)",fontStyle:"italic",marginTop:2,lineHeight:1.4},children:Iq[((m=e.data.contractRef)==null?void 0:m.sourceType)??Ux(e.data.nodeType)]??""})]}),C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Contract Code",C.jsx(qx,{tooltip:"The unique identifier used to look up the contract"})]}),C.jsx("input",{style:Qi,value:((v=e.data.contractRef)==null?void 0:v.sourceCode)??"",disabled:t,onChange:k=>{var R,P;return n.onUpdateContractRef({sourceType:((R=e.data.contractRef)==null?void 0:R.sourceType)??Ux(e.data.nodeType),sourceCode:k.target.value,label:(P=e.data.contractRef)==null?void 0:P.label})}})]})]}),C.jsxs("div",{style:Bq,children:[C.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[C.jsx("span",{style:{marginRight:4},children:"📋"}),C.jsx("strong",{children:"Order:"})," ",e.data.order??"n/a"]}),C.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[C.jsx("span",{style:{marginRight:4},children:"🔗"}),C.jsx("strong",{children:"Depends On:"}),c.length===0?C.jsx("span",{children:"none"}):c.map(k=>C.jsx("button",{type:"button","data-testid":`depends-chip-${k}`,style:cG,onClick:()=>n.onSelectNodeByRuleCode(k),children:k},k))]})]}),e.data.nodeType==="condition"?C.jsx(Fq,{readOnly:t,value:e.data.conditionConfig,onChange:n.onUpdateConditionConfig}):null,e.data.nodeType==="decision-table"?C.jsxs(C.Fragment,{children:[C.jsxs("label",{style:wo,children:["Decision Table",C.jsxs("select",{style:Qi,value:((y=e.data.contractRef)==null?void 0:y.sourceCode)??"",disabled:t,onChange:k=>n.onUpdateDecisionTableCode(k.target.value),children:[C.jsx("option",{value:"",children:"Select decision table"}),i.map(k=>C.jsx("option",{value:k.code,children:k.label},k.code))]})]}),C.jsx(Wq,{table:s,loadState:l})]}):null,e.data.nodeType==="sub-flow"?C.jsxs("label",{style:wo,children:["Target Flow Code",C.jsxs("select",{style:Qi,value:fl(e.data.subFlowConfig).targetFlowCode??"",disabled:t,onChange:k=>n.onUpdateTargetFlowCode(k.target.value),children:[C.jsx("option",{value:"",children:"Select target flow"}),r.map(k=>C.jsx("option",{value:k.code,children:k.label},k.code))]})]}):null,e.data.nodeType==="liquid"?C.jsxs("label",{style:wo,children:["Liquid Output",C.jsxs("select",{style:Qi,value:W5(e.data.liquidConfig).outputFormat??"json",disabled:t,onChange:k=>n.onUpdateLiquidOutput(k.target.value),children:[C.jsx("option",{value:"json",children:"json"}),C.jsx("option",{value:"object",children:"object"}),C.jsx("option",{value:"text",children:"text"})]})]}):null,e.data.nodeType==="connector"?C.jsx(Xq,{config:{connectorType:((x=e.data.connectorConfig)==null?void 0:x.connectorType)??"",connectorConfig:((S=e.data.connectorConfig)==null?void 0:S.connectorConfig)??(e.data.connectorConfig&&("url"in e.data.connectorConfig||"method"in e.data.connectorConfig)?e.data.connectorConfig:{}),credentialId:(E=e.data.connectorConfig)==null?void 0:E.credentialId},catalog:n.connectorCatalog??[],readOnly:t,onChange:n.onUpdateConnectorConfig}):null]})}function Vq({nodeType:n,expression:e,upstreamScope:t,outputContract:r,liquidOutput:i,readOnly:s,apiBaseUrl:l,onChangeLanguage:c,onChangeBody:h,onInsertRef:m,shadowRoot:v}){const y=q.useRef(null),x=n==="liquid"||e.language==="liquid"?dG(e.body,(t==null?void 0:t.fields)??[],i??"json"):"",E=qi((r==null?void 0:r.fields)??[]).filter(P=>{var Q;return(Q=P.valueExpression)==null?void 0:Q.trim()}),k=E.length>0,R=n==="action"||n==="connector";return C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:R&&(k||!e.body.trim())?C.jsxs(C.Fragment,{children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Per-Field Value Expressions"}),C.jsx("span",{children:k?"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."})]}),k?C.jsx("div",{style:aT,children:C.jsxs("table",{style:sT,children:[C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{style:Cs,children:"Output Field"}),C.jsx("th",{style:Cs,children:"Type"}),C.jsx("th",{style:Cs,children:"Expression"})]})}),C.jsx("tbody",{children:E.map(P=>C.jsxs("tr",{children:[C.jsx("td",{style:Ts,children:P.path}),C.jsx("td",{style:Ts,children:P.dataType}),C.jsx("td",{style:{...Ts,fontFamily:"var(--mu-font-mono)",fontSize:12},children:P.valueExpression})]},P.path))})]})}):null,C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Tip"}),C.jsxs("span",{children:["Switch to the ",C.jsx("strong",{children:"Output Data"})," tab to add or edit value expressions for each output field."]})]})]}):C.jsxs(C.Fragment,{children:[C.jsxs("label",{style:wo,children:["Expression Language",C.jsxs("select",{style:Qi,value:e.language,disabled:s,onChange:P=>c(P.target.value),children:[C.jsx("option",{value:"feel",children:"FEEL"}),C.jsx("option",{value:"javascript",children:"JavaScript"}),C.jsx("option",{value:"scriban",children:"Scriban"}),C.jsx("option",{value:"liquid",children:"Liquid"}),C.jsx("option",{value:"plain-text",children:"Plain Text"})]})]}),(()=>{const P=qi((t==null?void 0:t.fields)??[]),Q=[];return e.language==="feel"&&(Q.push(J5(P)),Q.push(Lq(P))),C.jsxs(C.Fragment,{children:[C.jsxs("div",{style:wo,children:[e.language==="liquid"?"Liquid Template":"Expression",C.jsx(YC,{value:e.body,language:e.language,readOnly:s,onChange:h,onInsertToken:A=>{y.current=A,m==null||m(A)},extensions:Q,minHeight:180,root:v})]}),C.jsx(Oq,{visible:e.language==="feel",onInsert:A=>{var L;return(L=y.current)==null?void 0:L.insert(A)}})]})})(),C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Authoring hints"}),C.jsx("span",{children:"Type '.' after a field name or press Ctrl+Space for autocomplete. Click any field in Input Scope to insert at cursor."}),l?C.jsxs("span",{children:["Contract API: ",l]}):null]}),n==="liquid"||e.language==="liquid"?C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Liquid Preview"}),C.jsx("pre",{style:fG,children:x||"Preview is empty."})]}):null]})})}function Fq({readOnly:n,value:e,onChange:t}){const r={successLabel:(e==null?void 0:e.successLabel)??"Valid",failureLabel:(e==null?void 0:e.failureLabel)??"Rejected",failureMessage:(e==null?void 0:e.failureMessage)??""};return C.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Success Label",C.jsx(qx,{tooltip:"Shown on output edges when this condition evaluates to true"})]}),C.jsx("input",{style:Qi,value:r.successLabel,disabled:n,onChange:i=>t({...r,successLabel:i.target.value})})]}),C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Failure Label",C.jsx(qx,{tooltip:"Shown on output edges when this condition evaluates to false"})]}),C.jsx("input",{style:Qi,value:r.failureLabel,disabled:n,onChange:i=>t({...r,failureLabel:i.target.value})})]}),C.jsxs("label",{style:wo,children:["Failure Message",C.jsx("textarea",{style:oT,value:r.failureMessage,disabled:n,onChange:i=>t({...r,failureMessage:i.target.value})})]})]})}function Xq({config:n,catalog:e,readOnly:t,onChange:r}){const i=e.find(c=>c.connectorType===n.connectorType),s=(i==null?void 0:i.requiresCredentials)||(i==null?void 0:i.credentialFields)&&i.credentialFields.length>0;function l(c){r==null||r({...n,...c})}return C.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[C.jsxs("label",{style:wo,children:["Connector Type",C.jsxs("select",{style:Qi,value:n.connectorType??"",disabled:t,onChange:c=>l({connectorType:c.target.value,connectorConfig:{},credentialId:void 0}),children:[C.jsx("option",{value:"",children:"Select connector type"}),e.map(c=>C.jsxs("option",{value:c.connectorType,children:[c.displayName," ",c.category?`(${c.category})`:""]},c.connectorType))]})]}),n.connectorType?C.jsxs(C.Fragment,{children:[i!=null&&i.description?C.jsx("div",{style:Qd,children:C.jsx("span",{children:i.description})}):null,C.jsxs("label",{style:wo,children:["Config JSON",C.jsx("textarea",{style:{...oT,fontFamily:"var(--mu-font-mono)",fontSize:13},value:JSON.stringify(n.connectorConfig??{},null,2),disabled:t,onChange:c=>{try{const h=JSON.parse(c.target.value);l({connectorConfig:h})}catch{}}})]}),i!=null&&i.configSchema?C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Config Schema"}),C.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:11},children:JSON.stringify(i.configSchema,null,2)})]}):null]}):null,s?C.jsxs("label",{style:wo,children:["Credential ID",C.jsx("input",{style:Qi,value:n.credentialId??"",disabled:t,placeholder:"Enter credential identifier",onChange:c=>l({credentialId:c.target.value})})]}):null]})}function Wq({table:n,loadState:e}){return C.jsxs("div",{style:uG,"data-testid":"decision-table-overview",children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Decision Table Schema"}),C.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."})]}),n?C.jsxs(C.Fragment,{children:[C.jsxs("div",{children:[C.jsx("strong",{children:n.name})," · v",n.version," · hit policy ",n.hitPolicy]}),n.description?C.jsx("div",{children:n.description}):null,C.jsxs("div",{style:{display:"grid",gap:8},children:[C.jsxs("div",{children:[C.jsx("strong",{children:"Input Columns"}),C.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:n.inputColumns.map(t=>C.jsxs("span",{style:lT,children:[t.label," (",t.dataType,")"]},t.id))})]}),C.jsxs("div",{children:[C.jsx("strong",{children:"Output Columns"}),C.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:n.outputColumns.map(t=>C.jsxs("span",{style:lT,children:[t.label," (",t.dataType,")"]},t.id))})]})]}),C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"FEEL cell hints"}),C.jsx("span",{children:"Input columns become the effective input contract for this node. Output columns are emitted downstream after the table evaluates."}),C.jsx("span",{children:"Use FEEL row expressions against the input column names exactly as defined here."})]})]}):(e==null?void 0:e.status)==="idle"?C.jsx("span",{children:"Select a decision table to preview its column schema."}):null]})}function Hq({title:n,subtitle:e,contract:t,loadState:r,readOnly:i,onInsert:s,groupBySource:l}){const[c,h]=q.useState("tree"),[m,v]=q.useState(!0),y=(t==null?void 0:t.fields)??[],x=qi(y),S=y.length>0,E=new Map;for(const R of y){const P=l?R.sourceNodeLabel??(R.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",Q=E.get(P)??[];Q.push(R),E.set(P,Q)}const k=new Map;for(const R of x){const P=l?R.sourceNodeLabel??(R.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",Q=k.get(P)??[];Q.push(R),k.set(P,Q)}return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:n}),C.jsx("span",{children:r.status==="loading"?"Loading contract...":e})]}),S?C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[c==="tree"?C.jsx("button",{type:"button",onClick:()=>v(!m),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:m?"Collapse All":"Expand All"}):null,C.jsxs("div",{style:{display:"flex",borderRadius:6,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},children:[C.jsx("button",{type:"button",onClick:()=>h("tree"),style:{border:"none",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:c==="tree"?"var(--mu-color-interactive)":"transparent",color:c==="tree"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Schema Tree"}),C.jsx("button",{type:"button",onClick:()=>h("table"),style:{border:"none",borderLeft:"1px solid var(--mu-border-subtle)",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:c==="table"?"var(--mu-color-interactive)":"transparent",color:c==="table"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Flat Table"})]})]}):null]}),S?c==="tree"?C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,maxHeight:420,overflow:"auto"},children:[...E.entries()].map(([R,P])=>C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[l?C.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)",padding:"4px 8px"},children:R}):null,P.map(Q=>C.jsx(pL,{field:Q,depth:0,readOnly:i,onInsert:s,defaultExpanded:m},Q.path))]},R))},m?"expanded":"collapsed"):[...k.entries()].map(([R,P])=>C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[l?C.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)"},children:R}):null,C.jsx(gL,{fields:P,readOnly:i,onInsert:s})]},R)):r.status==="loading"?C.jsx(Qp,{icon:"\\u231B",message:"Fetching contract metadata..."}):C.jsx(Qp,{message:"No scope metadata available for this node."})]})}function Yq({status:n}){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[n??"mapped"]??e.mapped;return C.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 qq({nodeType:n,readOnly:e,upstreamFields:t,targetFields:r,rows:i,onInsert:s,onChangeTargetFields:l,onChange:c,setInspectorTab:h,hasExpression:m}){const v=n==="action"||n==="sub-flow",y=n==="action";function x(R,P){c(i.map(Q=>Q.id===R?P(Q):Q))}function S(){const R=`input.${r.length+1}`;l([...r,{path:R,label:R,dataType:"string",required:!1}])}function E(R,P){const Q=r.find(L=>L.path===R);if(!Q)return;const A=P(Q);l(r.map(L=>L.path===R?A:L)),c(i.map(L=>(L.targetField??L.targetPath)===R?{...L,targetField:A.path,targetPath:A.path,targetDataType:A.dataType,required:A.required}:L))}function k(R){l(r.filter(P=>P.path!==R)),c(i.filter(P=>(P.targetField??P.targetPath)!==R))}return i.length===0?n==="action"&&!m?C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&y?C.jsx("button",{type:"button",style:wa(!1),onClick:S,children:"Add Input Slot"}):null]}),C.jsx(Qp,{icon:"info",message:"This node uses code-first logic — no expression-based mapping needed. Input/output contracts come from the registered rule code."})]}):(n==="condition"||n==="liquid")&&!m?C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),C.jsx(Qp,{icon:"edit",message:"Write a FEEL expression in the Logic tab to see data flow here.",actionHint:"Go to Logic tab",onAction:()=>h("logic")})]}):C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),C.jsx(Qp,{icon:"warning",message:"Expression references fields not found in upstream scope. Check field names in the Logic tab.",actionHint:"Go to Logic tab",onAction:()=>h("logic")})]}):C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&y?C.jsx("button",{type:"button",style:wa(!1),onClick:S,children:"Add Input Slot"}):null]}),C.jsx("div",{style:aT,children:C.jsxs("table",{style:sT,children:[C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{style:Cs,children:"Source"}),C.jsx("th",{style:Cs,children:"Target"}),C.jsx("th",{style:Cs,children:"Type"}),C.jsx("th",{style:Cs,children:"Status"}),C.jsx("th",{style:Cs,children:"Transform"}),y?C.jsx("th",{style:Cs,children:"Actions"}):null]})}),C.jsx("tbody",{children:i.map(R=>C.jsxs("tr",{children:[C.jsx("td",{style:Ts,children:v?C.jsx("input",{list:"upstream-scope-fields",style:Qi,value:R.sourcePath,disabled:e,onChange:P=>x(R.id,Q=>({...Q,sourcePath:P.target.value}))}):C.jsx("button",{type:"button",style:Dp,onClick:()=>s(R.sourcePath),disabled:e||!R.sourcePath,children:R.sourcePath||"unmapped"})}),C.jsx("td",{style:Ts,children:y?C.jsx("input",{style:Qi,value:R.targetField??R.targetPath,disabled:e,onChange:P=>E(R.targetField??R.targetPath,Q=>({...Q,path:P.target.value,label:P.target.value}))}):R.targetField??R.targetPath}),C.jsx("td",{style:Ts,children:y?C.jsx("input",{style:Qi,value:R.targetDataType??"string",disabled:e,onChange:P=>E(R.targetField??R.targetPath,Q=>({...Q,dataType:P.target.value}))}):C.jsx(Uv,{dataType:`${R.sourceDataType??"unknown"} → ${R.targetDataType??"unknown"}`})}),C.jsxs("td",{style:Ts,children:[C.jsx(Yq,{status:R.status}),R.required?C.jsx("span",{style:{fontSize:10,color:"var(--mu-color-error)",marginLeft:4,fontWeight:600},children:"required"}):null]}),C.jsx("td",{style:Ts,children:v?C.jsx("input",{style:Qi,value:R.transform??R.transformSuggestion??"",disabled:e,onChange:P=>x(R.id,Q=>({...Q,transform:P.target.value}))}):R.transformSuggestion??R.transform??"—"}),y?C.jsx("td",{style:Ts,children:C.jsx("button",{type:"button",style:Dp,disabled:e,onClick:()=>k(R.targetField??R.targetPath),children:"Remove"})}):null]},R.id))})]})}),C.jsx("datalist",{id:"upstream-scope-fields",children:t.map(R=>C.jsx("option",{value:R.path},R.path))}),r.length?C.jsxs("div",{style:Qd,children:[C.jsx("strong",{title:"Fields this node declares it needs — must be provided by upstream nodes or flow input",children:"Required input slots"}),C.jsx("span",{children:r.filter(R=>R.required).map(R=>R.path).join(", ")||"No required fields declared."})]}):null]})}function mL({title:n,count:e,defaultExpanded:t,headerRight:r,children:i}){const[s,l]=q.useState(t);return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsxs("div",{role:"button",tabIndex:0,onClick:()=>l(!s),onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),l(!s))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[C.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:s?"▼":"▶"}),C.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:n}),e!==void 0?C.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]}),r]}),s?i:null]})}function Gq({nodeType:n,contract:e,upstreamScope:t,issues:r,readOnly:i,onInsert:s,onChange:l}){if(n==="end")return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Final Scope"}),C.jsx("span",{children:"Everything guaranteed to be available when the flow reaches this end node."})]}),C.jsx(gL,{fields:qi((t==null?void 0:t.fields)??[]),readOnly:i,onInsert:s})]});const c=n==="condition"||n==="action",h=qi((e==null?void 0:e.fields)??[]),m=h.filter(Q=>!Q.isResultPayload),v=h.filter(Q=>Q.isResultPayload),S=n==="condition"||n==="action";function E(Q,A){const L=h.map(B=>!B.isResultPayload&&m.indexOf(B)===Q?A(B):B);l(L)}function k(Q){const A=m[Q];l(h.filter(L=>L!==A))}function R(){const Q=`custom.${m.length+1}`;l([...h,{path:Q,label:Q,dataType:"string",required:!1}])}const P=(()=>{const Q=[];return t&&Q.push(J5(qi(t.fields))),Q})();return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[C.jsx(mL,{title:"Custom Output Fields",count:m.length,defaultExpanded:!0,headerRight:!i&&c?C.jsx("button",{type:"button",style:wa(!1),onClick:R,children:"Add Field"}):void 0,children:m.length===0?C.jsx(Qp,{message:"No custom output fields defined.",actionHint:c&&!i?"Add a field to compute values for downstream nodes.":void 0,onAction:c&&!i?R:void 0}):C.jsx("div",{style:rG,children:m.map((Q,A)=>C.jsxs("div",{style:iG,children:[C.jsxs("div",{style:yL,children:[c?C.jsx("input",{style:{...Qi,flex:"1 1 0%",minWidth:0},value:Q.path,disabled:i,placeholder:"field.path",title:"Dotted path where this value is stored in the FactBag",onChange:L=>E(A,B=>({...B,path:L.target.value,label:L.target.value}))}):C.jsx("button",{type:"button",style:{...Dp,flex:"1 1 0%",minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},onClick:()=>s(Q.path),disabled:i,children:Q.path}),c&&!i?C.jsx("button",{type:"button",style:{...Dp,color:"var(--mu-color-error-text)",flexShrink:0,fontSize:"var(--mu-text-xs)"},onClick:()=>k(A),title:"Remove this field",children:"delete"}):null]}),C.jsxs("div",{style:yL,children:[c&&!i?C.jsx("select",{style:oG,value:Q.dataType,title:"Data type of the output value",onChange:L=>E(A,B=>({...B,dataType:L.target.value})),children:["string","number","boolean","object","array"].map(L=>C.jsx("option",{value:L,children:L},L))}):C.jsx(Uv,{dataType:Q.dataType}),S?C.jsx("div",{style:{flex:"1 1 0%",minWidth:0},children:c?C.jsx(YC,{value:Q.valueExpression??"",language:"feel",readOnly:i,singleLine:!0,placeholderText:"e.g. command.details.length",onChange:L=>E(A,B=>({...B,valueExpression:L,runtimeWritten:L.trim().length>0})),extensions:P,root:void 0}):C.jsx("span",{style:{fontFamily:"var(--mu-font-mono)",fontSize:"var(--mu-text-xs)"},children:Q.valueExpression??"—"})}):null]})]},`output-custom-${A}`))})}),v.length>0?C.jsx(mL,{title:"Auto-Generated Results",count:v.length,defaultExpanded:!1,children:C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,padding:"4px 0"},children:v.map((Q,A)=>C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",fontSize:12},children:[C.jsx("button",{type:"button",style:{...Dp,flex:1,textAlign:"left"},onClick:()=>s(Q.path),disabled:i,children:Q.path}),C.jsx(Uv,{dataType:Q.dataType})]},`output-auto-${A}`))})}):null,r.length?C.jsx(vL,{issues:r.filter(Q=>Q.severity!=="info")}):null]})}function gL({fields:n,readOnly:e,onInsert:t}){return C.jsx("div",{style:aT,children:C.jsxs("table",{style:sT,children:[C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{style:Cs,children:"Path"}),C.jsx("th",{style:{...Cs,width:"15%"},children:"Type"}),C.jsx("th",{style:Cs,children:"Description"})]})}),C.jsx("tbody",{children:n.map(r=>C.jsxs("tr",{children:[C.jsx("td",{style:Ts,children:C.jsx("button",{type:"button",style:Dp,onClick:()=>t(r.path),disabled:e,children:r.path})}),C.jsx("td",{style:Ts,children:C.jsx(Uv,{dataType:r.dataType})}),C.jsx("td",{style:Ts,title:r.description??r.label,children:r.description??r.label})]},`${r.sourceNodeId??"scope"}:${r.path}`))})]})})}const Kq=C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-error)",style:{flexShrink:0,marginTop:1},children:C.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"})}),Jq=C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-warning)",style:{flexShrink:0,marginTop:1},children:C.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 vL({issues:n}){return C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.map(e=>{const t=e.severity==="error";return C.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?Kq:Jq,C.jsxs("span",{style:{color:t?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",lineHeight:"20px"},children:[C.jsx("strong",{children:e.code})," ",e.message,e.fieldPath?C.jsxs("span",{style:{opacity:.7,marginLeft:4},children:["(",e.fieldPath,")"]}):null]})]},`${e.code}:${e.message}:${e.fieldPath??""}`)})})}const qu={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-text-muted)"},eG={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)"},tG={display:"flex",flexWrap:"nowrap",overflowX:"auto",gap:0,paddingBottom:0,borderBottom:"1px solid var(--mu-border-subtle)",marginBottom:"var(--mu-space-xs)"},wo={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-medium)",color:"var(--mu-text-label)"},Qi={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%"},oT={...Qi,minHeight:116,resize:"vertical"},aT={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)"},sT={width:"100%",tableLayout:"fixed",borderCollapse:"collapse",fontSize:12},Cs={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"},Ts={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"},Dp={border:"none",background:"transparent",color:"var(--mu-color-interactive)",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,textAlign:"left"},nG={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"var(--mu-space-sm)"},rG={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",overflowY:"auto",maxHeight:"50vh",minHeight:80},iG={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)"},yL={display:"flex",alignItems:"center",gap:"var(--mu-space-xs)",minWidth:0},oG={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},aG={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},Qd={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},sG={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},lG={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},uG={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)"},lT={borderRadius:999,padding:"4px 8px",background:"var(--mu-color-interactive-subtle)",color:"var(--mu-text-primary)",fontSize:11,fontWeight:600},cG={...lT,border:"none",cursor:"pointer"},fG={margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:12};function dG(n,e,t){const r=qi(e),i=new Map(r.map(l=>[l.path,l.example??`<${l.path}>`])),s=n.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*\}\}/g,(l,c)=>String(i.get(c)??`<${c}>`));return s}function wa(n){return{borderRadius:12,border:n?"1px solid var(--mu-color-interactive-border)":"1px solid var(--mu-border-input)",background:n?"var(--mu-color-interactive-subtle)":"var(--mu-surface-raised)",color:"var(--mu-text-primary)",padding:"10px 12px",fontWeight:600,minHeight:44}}function hG(n){return{borderRadius:0,border:"none",borderBottom:n?"2px solid var(--mu-color-interactive)":"2px solid transparent",background:"transparent",color:n?"var(--mu-color-interactive)":"var(--mu-text-muted)",fontWeight:n?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 pG({groups:n,loading:e,readOnly:t,onAddRule:r,onDragStart:i}){const[s,l]=q.useState(""),c=s.trim().toLowerCase(),h=q.useMemo(()=>[...n].sort((v,y)=>(v.category??"").localeCompare(y.category??"")).map(v=>({...v,items:[...v.items].filter(y=>gG(y,c)).sort((y,x)=>(y.displayName??"").localeCompare(x.displayName??""))})).filter(v=>v.items.length>0),[n,c]);return C.jsxs("div",{style:vG,children:[C.jsxs("div",{style:yG,children:[C.jsx("strong",{children:"Rule Catalog"}),C.jsx("span",{children:"Load reusable rule templates from the control plane and drop them into the flow."})]}),C.jsxs("label",{style:OG,children:["Search rules",C.jsx("input",{"data-testid":"catalog-search-input",style:xG,value:s,onChange:m=>l(m.target.value),placeholder:"Search by name, code, tag or description",disabled:e})]}),e?C.jsx("div",{"data-testid":"catalog-loading-state",style:OL,children:"Loading rule catalog..."}):null,!e&&h.length===0?C.jsx("div",{"data-testid":"catalog-empty-state",style:OL,children:c?"No rules match the current search.":"No rules available."}):null,e?null:h.map(m=>C.jsxs("div",{"data-testid":`catalog-group-${m.category}`,style:bG,children:[C.jsx("span",{style:wG,title:m.category,children:mG(m.category)}),m.items.map(v=>C.jsx("button",{type:"button",style:SG,"data-testid":`palette-rule-${v.code}`,draggable:!t,onClick:()=>r(v),onDragStart:y=>i(y,v),disabled:t,children:C.jsxs("span",{style:kG,children:[C.jsx("strong",{children:v.displayName}),C.jsx("span",{style:CG,children:v.code}),v.description?C.jsx("span",{style:TG,children:v.description}):null,v.tags.length>0?C.jsx("span",{style:EG,children:v.tags.join(" · ")}):null]})},v.code))]},m.category))]})}function mG(n){const e=n.split(".");return e.length<=2?n:e.slice(-2).join(".")}function gG(n,e){return e?[n.code,n.displayName,n.description??"",...n.tags??[]].join(" ").toLowerCase().includes(e):!0}const vG={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},yG={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-color-text-muted)"},OG={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-xs)",color:"var(--mu-color-text-secondary)",fontWeight:600},xG={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},OL={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},bG={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},wG={fontSize:12,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--mu-color-text-secondary)"},SG={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},kG={display:"flex",flexDirection:"column",gap:4},CG={fontSize:"var(--mu-text-xs)",fontFamily:"var(--mu-font-mono)",fontWeight:500,color:"var(--mu-color-text-secondary)"},TG={fontSize:12,fontWeight:500,color:"var(--mu-color-text-muted)"},EG={fontSize:"var(--mu-text-xs)",color:"var(--mu-color-interactive)"},_G={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 uT(n){return _G}const cT={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"},RG={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"},xL={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)"},PG=xL;function bL(n,e){const t=Ai(n),r=MG(t,e);return{...t,nodes:t.nodes.map(i=>{var s,l,c,h;return{...i,data:{...i.data,contractLayer:r.get(i.id),dependsOn:i.data.dependsOn??((l=(s=e.nodeContractsById)==null?void 0:s.get(i.id))==null?void 0:l.dependsOn)??[],order:i.data.order??((h=(c=e.nodeContractsById)==null?void 0:c.get(i.id))==null?void 0:h.order)}}})}}function fT(n,e){const t=Lp(n,e),r=bL(t.graph,e),i=r.nodes.flatMap(s=>{var l;return((l=s.data.contractLayer)==null?void 0:l.validationIssues)??[]});return{graph:r,issues:[...t.issues,...i],isValid:t.isValid&&i.every(s=>s.severity!=="error")}}function Lp(n,e){var S,E;const t=Ai(n),r=t.nodes.filter(k=>k.type!=="trigger"&&k.type!=="end"),i=new Set(r.map(k=>k.id)),s=new Map(r.filter(k=>k.ruleCode).map(k=>[k.ruleCode,k.id])),l=new Map,c=new Map,h=k=>{l.has(k)||l.set(k,new Set),c.has(k)||c.set(k,0)},m=(k,R)=>{if(k===R||!i.has(k)||!i.has(R))return;h(k),h(R);const P=l.get(k);P.has(R)||(P.add(R),c.set(R,(c.get(R)??0)+1))};for(const k of r){h(k.id);const R=k.data.dependsOn??((E=(S=e.nodeContractsById)==null?void 0:S.get(k.id))==null?void 0:E.dependsOn)??[];for(const P of R){const Q=s.get(P);Q&&m(Q,k.id)}}for(const k of t.edges)k.edgeType!=="on-error"&&m(k.source,k.target);const v=[...r].sort((k,R)=>{var A,L,B,j;const P=k.data.order??((L=(A=e.nodeContractsById)==null?void 0:A.get(k.id))==null?void 0:L.order)??Number.MAX_SAFE_INTEGER,Q=R.data.order??((j=(B=e.nodeContractsById)==null?void 0:B.get(R.id))==null?void 0:j.order)??Number.MAX_SAFE_INTEGER;return P!==Q?P-Q:(k.label??"").localeCompare(R.label??"")}).filter(k=>(c.get(k.id)??0)===0).map(k=>k.id),y=[];for(;v.length>0;){const k=v.shift();y.push(k);const R=[...l.get(k)??[]].sort((P,Q)=>P.localeCompare(Q));for(const P of R){const Q=(c.get(P)??0)-1;c.set(P,Q),Q===0&&v.push(P)}}if(y.length!==r.length)return{graph:t,issues:[{code:"MRF008",severity:"error",message:"Rule flow contains a dependency cycle or invalid ordering edge."}],isValid:!1};const x=new Map(y.map((k,R)=>[k,R+1]));return{graph:{...t,nodes:t.nodes.map(k=>{var R,P;return i.has(k.id)?{...k,data:{...k.data,order:x.get(k.id)??k.data.order,dependsOn:k.data.dependsOn??((P=(R=e.nodeContractsById)==null?void 0:R.get(k.id))==null?void 0:P.dependsOn)??[]}}:k})},issues:[],isValid:!0}}function MG(n,e){const t=new Map(n.nodes.map(k=>[k.id,k])),r=new Map;for(const k of n.edges){const R=r.get(k.target)??[];R.push(k),r.set(k.target,R)}const i=new Map,s=new Set,l=k=>k.type,c=$G(n,e),h=(k,R)=>{var j,Z;const P=t.get(k);if(!P)return[];const Q=E(P),A=cf(((j=Q.upstreamScope)==null?void 0:j.fields)??[]),L=cf(((Z=Q.outputContract)==null?void 0:Z.fields)??[]);if(l(P)!=="condition")return Gu([...A,...SL(L)]);const B=R==="on-false"?L.filter(ee=>ee.isResultPayload):L;return Gu([...A,...SL(B)])},m=k=>{var A,L,B,j;const R=k.data.dependsOn??((L=(A=e.nodeContractsById)==null?void 0:A.get(k.id))==null?void 0:L.dependsOn)??[];if(R.length>0){const Z=n.nodes.filter(ee=>ee.ruleCode&&R.includes(ee.ruleCode));return Gu(Z.flatMap(ee=>h(ee.id,"always")))}const P=k.data.order??((j=(B=e.nodeContractsById)==null?void 0:B.get(k.id))==null?void 0:j.order)??Number.MAX_SAFE_INTEGER,Q=n.nodes.filter(Z=>{var ie,pe;const ee=Z.data.order??((pe=(ie=e.nodeContractsById)==null?void 0:ie.get(Z.id))==null?void 0:pe.order)??Number.MAX_SAFE_INTEGER;return Z.id!==k.id&&ee<P});return Gu(Q.flatMap(Z=>h(Z.id,"always")))},v=k=>{if(k.type==="trigger")return{contractName:`${e.flowCode??"flow"}_trigger_input`,title:"Input Scope",fields:c.map(Q=>uf(Q,{sourceKind:"flow-input"}))};const R=r.get(k.id)??[],P=R.length>0?R.flatMap(Q=>h(Q.source,Q.edgeType)):m(k);return P.length===0&&P.push(...c.map(Q=>uf(Q,{sourceKind:"flow-input"}))),{contractName:`${k.ruleCode??k.id}_input_scope`,title:"Input Scope",fields:Gu(P)}},y=(k,R)=>{var W,le,V,se,ne,ae;const P=(W=e.nodeContractsById)==null?void 0:W.get(k.id),Q=k.type==="sub-flow"?(le=e.flowContractsByCode)==null?void 0:le.get(fl(k.data.subFlowConfig).targetFlowCode??""):void 0,A=((V=k.data.contractOverride)==null?void 0:V.responseFields)??[],L=((se=Q==null?void 0:Q.responseContract)==null?void 0:se.fields)??((ne=k.data.responseContract)==null?void 0:ne.fields)??((ae=P==null?void 0:P.responseDelta)==null?void 0:ae.fields)??[],j=(Array.isArray(k.data.outputFields)?k.data.outputFields:[]).map(Y=>({path:Y.path,label:Y.path,dataType:Y.dataType??"string",valueExpression:Y.valueExpression})),Z=Gu([...cf(L),...j]),ee=A.length>0?QG(Z,A):Z,pe=(k.type==="condition"&&!k.ruleCode?ee.filter(Y=>{var G;return Y.runtimeWritten||((G=Y.valueExpression)==null?void 0:G.trim())}):ee).map(Y=>{var G;return uf(Y,{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:k.type==="sub-flow"?"sub-flow-output":"node-output",runtimeWritten:k.ruleCode?!0:k.type==="condition"?!!(Y.runtimeWritten??((G=Y.valueExpression)==null?void 0:G.trim())):Y.runtimeWritten??!0})});if(k.type==="trigger"){const Y=c.map(G=>uf(G,{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"flow-input",runtimeWritten:!0}));return{contractName:`${k.id}_output_contract`,title:"Output Contract",fields:Gu(Y)}}if(k.type!=="condition")return{contractName:`${k.ruleCode??k.id}_output_contract`,title:"Output Contract",fields:Gu(AG(k,pe))};const oe=[uf({path:"result.isPass",label:"isPass",dataType:"boolean",required:!0},{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),uf({path:"result.message",label:"message",dataType:"string"},{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),uf({path:"result.errorCode",label:"errorCode",dataType:"string"},{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0})];return{contractName:`${k.ruleCode??k.id}_output_contract`,title:"Output Contract",fields:Gu([...oe,...pe])}},x=(k,R)=>{var B,j,Z,ee,ie;const P=qi(R.fields),Q=k.type==="sub-flow"?fl(k.data.subFlowConfig).inputMappings:k.data.inputMappings??[];if(k.type==="sub-flow"){const pe=fl(k.data.subFlowConfig).childTriggerSchema,oe=qi((pe==null?void 0:pe.fields)??[]);return{contractName:`${k.ruleCode??k.id}_effective_input`,title:"Effective Input",mode:"sub-flow",fields:oe,mappings:wL(P,oe,Q)}}if(k.type==="condition"||k.type==="liquid"){const pe=iu(k.data),oe=(pe.language??"").toLowerCase(),W=oe==="feel"||oe===""?DG(pe.body,P):[];return{contractName:`${k.ruleCode??k.id}_effective_input`,title:"Effective Input",mode:k.type==="liquid"?"expression":"auto",fields:W,mappings:W.map(le=>({id:`auto-${le.path}`,sourcePath:le.path,targetPath:le.path,targetField:le.path,sourceDataType:le.dataType,targetDataType:le.dataType,sourceNodeId:le.sourceNodeId,sourceNodeLabel:le.sourceNodeLabel,status:"mapped",required:le.required}))}}const A=qi(((B=k.data.contractOverride)==null?void 0:B.requestFields)??((j=k.data.requestContract)==null?void 0:j.fields)??((ie=(ee=(Z=e.nodeContractsById)==null?void 0:Z.get(k.id))==null?void 0:ee.requestScope)==null?void 0:ie.fields)??[]),L=k.type==="end"?[]:A;return{contractName:`${k.ruleCode??k.id}_effective_input`,title:"Effective Input",mode:k.type==="decision-table"?"decision-table":k.type==="action"?"manual":"auto",fields:L,mappings:wL(P,L,Q)}},S=(k,R,P,Q)=>{var B;const A=qi(R.fields),L=[];for(const j of P.mappings){if(j.required&&!j.sourcePath.trim()){L.push({code:"MRF001",severity:"error",message:`Required input '${j.targetField??j.targetPath}' is not mapped.`,nodeId:k.id,targetPath:j.targetField??j.targetPath});continue}if(!j.sourcePath.trim())continue;if(!A.find(ee=>ee.path===j.sourcePath)){const ee=k.type==="sub-flow"||k.type==="connector"||k.type==="decision-table";L.push({code:"MRF002",severity:ee?"warning":"error",message:ee?`Source field '${j.sourcePath}' is not in upstream scope (may be resolved from FactBag at runtime).`:`Source field '${j.sourcePath}' is not available in upstream scope.`,nodeId:k.id,sourcePath:j.sourcePath,targetPath:j.targetField??j.targetPath});continue}j.targetDataType&&j.sourceDataType&&j.targetDataType!==j.sourceDataType&&!(j.transform??"").trim()&&L.push({code:"MRF003",severity:"warning",message:`Mapping '${j.sourcePath}' -> '${j.targetField??j.targetPath}' has type mismatch (${j.sourceDataType} -> ${j.targetDataType}).`,nodeId:k.id,sourcePath:j.sourcePath,targetPath:j.targetField??j.targetPath})}if(k.type==="sub-flow"){const j=fl(k.data.subFlowConfig).childTriggerSchema;for(const Z of qi((j==null?void 0:j.fields)??[]).filter(ee=>ee.required))P.mappings.some(ie=>(ie.targetField??ie.targetPath)===Z.path&&ie.sourcePath.trim().length>0)||L.push({code:"MRF004",severity:"error",message:`Sub-flow input '${Z.path}' is required but not mapped.`,nodeId:k.id,fieldPath:Z.path})}if(k.type==="condition"||k.type==="liquid"){const j=iu(k.data),Z=j.body,ee=(j.language??"").toLowerCase();if(ee==="feel"||ee===""){const pe=LG(Z),oe=kL(Z);for(const W of oe){const le=W.split(".")[0];pe.has(le)||le.startsWith("__graph")||zG.has(le)||A.some(V=>V.path===W||W.startsWith(V.path+"."))||L.push({code:"MRF005",severity:"error",message:`Expression references '${W}' but that field is not available in input scope.`,nodeId:k.id,fieldPath:W})}}}if(k.type==="condition"&&!k.ruleCode)for(const j of qi(Q.fields).filter(Z=>!Z.isResultPayload&&!Z.runtimeWritten))(B=j.valueExpression)!=null&&B.trim()||L.push({code:"MRF009",severity:"warning",message:`Condition output '${j.path}' is metadata-only until a Value Expression is configured.`,nodeId:k.id,fieldPath:j.path});return k.type==="end"&&Q.fields.length>0&&L.push({code:"MRF006",severity:"warning",message:"End nodes should not define additional output fields.",nodeId:k.id}),L},E=k=>{const R=i.get(k.id);if(R)return R;if(s.has(k.id))return{upstreamScope:{contractName:`${k.id}_input_scope`,title:"Input Scope",fields:[]},effectiveInput:{contractName:`${k.id}_effective_input`,title:"Effective Input",fields:[],mappings:[]},outputContract:{contractName:`${k.id}_output_contract`,title:"Output Contract",fields:[]},validationIssues:[{code:"MRF007",severity:"error",message:"Cycle detected in rule flow graph.",nodeId:k.id}]};s.add(k.id);const P=v(k),Q=x(k,P),A=y(k),L=S(k,P,Q,A),B={upstreamScope:P,effectiveInput:Q,outputContract:A,validationIssues:L};return i.set(k.id,B),s.delete(k.id),B};for(const k of n.nodes)E(k);return i}function $G(n,e){var l,c,h,m,v;const t=cf(((c=(l=e.currentFlowContract)==null?void 0:l.requestContract)==null?void 0:c.fields)??[]);if(t.length>0)return t;const r=[...n.nodes].filter(y=>y.type!=="trigger"&&y.type!=="end").sort((y,x)=>{var k,R,P,Q;const S=y.data.order??((R=(k=e.nodeContractsById)==null?void 0:k.get(y.id))==null?void 0:R.order)??Number.MAX_SAFE_INTEGER,E=x.data.order??((Q=(P=e.nodeContractsById)==null?void 0:P.get(x.id))==null?void 0:Q.order)??Number.MAX_SAFE_INTEGER;return S!==E?S-E:(y.label??"").localeCompare(x.label??"")})[0];if(!r)return[];const i=(h=e.nodeContractsById)==null?void 0:h.get(r.id),s=((m=i==null?void 0:i.requestScope)==null?void 0:m.fields)??((v=r.data.requestContract)==null?void 0:v.fields)??[];return cf(s)}function wL(n,e,t){const r=new Map;for(const i of t){const s=n.find(c=>c.path===i.sourcePath),l=e.find(c=>c.path===i.targetPath);r.set(i.id,{...i,targetField:(l==null?void 0:l.path)??i.targetPath,sourceDataType:s==null?void 0:s.dataType,targetDataType:l==null?void 0:l.dataType,sourceNodeId:s==null?void 0:s.sourceNodeId,sourceNodeLabel:s==null?void 0:s.sourceNodeLabel,required:l==null?void 0:l.required,status:s?l!=null&&l.dataType&&s.dataType!==l.dataType&&!(i.transform??"").trim()?"type-mismatch":"mapped":"missing"})}for(const i of e){if([...r.values()].find(c=>(c.targetField??c.targetPath)===i.path))continue;const l=n.find(c=>c.path===i.path)??n.find(c=>CL(c.path)===CL(i.path)&&c.dataType===i.dataType);r.set(`suggested-${i.path}`,{id:`suggested-${i.path}`,sourcePath:(l==null?void 0:l.path)??"",targetPath:i.path,targetField:i.path,sourceDataType:l==null?void 0:l.dataType,targetDataType:i.dataType,sourceNodeId:l==null?void 0:l.sourceNodeId,sourceNodeLabel:l==null?void 0:l.sourceNodeLabel,required:i.required,status:l?"suggested":i.required?"missing":"suggested",transformSuggestion:l&&l.dataType!==i.dataType?`to_${i.dataType}(${l.path})`:void 0})}return[...r.values()]}function AG(n,e){if(n.type!=="sub-flow")return e;const t=fl(n.data.subFlowConfig).outputMappings;return t.length===0?e:e.map(r=>{const i=t.find(s=>s.sourcePath===r.path&&s.targetPath.trim().length>0);return i?{...r,path:i.targetPath,label:i.targetPath,exposeToParent:r.exposeToParent}:r})}function uf(n,e){var t;return{...n,...e,children:(t=n.children)==null?void 0:t.map(r=>uf(r,e))}}function Gu(n){const e=new Map;for(const t of n)e.has(t.path)||e.set(t.path,t);return[...e.values()].sort((t,r)=>(t.path??"").localeCompare(r.path??""))}function cf(n){return n.map(e=>({...e,children:e.children?cf(e.children):void 0}))}function QG(n,e){const t=new Map;for(const r of n)t.set(r.path,{...r,children:r.children?cf(r.children):void 0});for(const r of e)t.set(r.path,{...r,children:r.children?cf(r.children):void 0});return[...t.values()]}function SL(n){return n.filter(e=>e.exposeToParent!==!1)}function DG(n,e){const t=new Set(kL(n));return e.filter(r=>t.has(r.path))}function kL(n){if(!n.trim())return[];const e=new Set,t=/\b[a-zA-Z_][a-zA-Z0-9_.]*\b/g;let r=t.exec(n);for(;r;){const s=r[0];s.includes(".")&&e.add(s),r=t.exec(n)}const i=/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)/g;for(r=i.exec(n);r;)e.add(r[1]),r=i.exec(n);return[...e]}function CL(n){const e=n.split(".");return e[e.length-1]??n}function LG(n){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 r of t){let i=r.exec(n);for(;i;)e.add(i[1]),i=r.exec(n)}return e}const zG=new Set(["string","number","date","time","duration","list","context","math","Math","Date","JSON","RegExp","Object","Array","console","forloop","now","true","false","null"]),dT="application/muonroi-rule-flow-node-type",TL="application/muonroi-rule-flow-rule-template",EL={duration:0,padding:.22,minZoom:.18,maxZoom:1.1},_L=860,hT={always:"→ Always","on-true":"✓ On Pass","on-false":"✗ On Fail","on-error":"⚠ On Error"},NG={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."},jG={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)"}},IG={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 BG(n){var e,t,r,i,s;if(n.nodeType==="condition"&&((e=n.conditionConfig)!=null&&e.successLabel))return`Pass: ${n.conditionConfig.successLabel} / Fail: ${n.conditionConfig.failureLabel??"—"}`;if(n.nodeType==="action")return"Execute side-effect";if(n.nodeType==="decision-table")return(t=n.contractRef)!=null&&t.sourceCode?`Table: ${n.contractRef.sourceCode}`:"Decision table lookup";if(n.nodeType==="connector"){const l=(r=n.connectorConfig)==null?void 0:r.connectorType;return l?`Connector: ${l}`:"External service call"}return n.nodeType==="sub-flow"?(i=n.subFlowConfig)!=null&&i.targetFlowCode?`Flow: ${n.subFlowConfig.targetFlowCode}`:"Delegate to sub-flow":n.nodeType==="liquid"?`Liquid → ${((s=n.liquidConfig)==null?void 0:s.outputFormat)??"json"}`:null}function ZG({politeMessage:n,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 C.jsxs(C.Fragment,{children:[C.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:t,children:n}),C.jsx("div",{role:"alert","aria-live":"assertive","aria-atomic":"true",style:t,children:e})]})}function ff({data:n,selected:e}){var m,v,y;const t=Iv[n.nodeType],r=uT(n._theme??"light"),i=iu(n),s=((m=n.requestContract)==null?void 0:m.fields.length)??0,l=((v=n.responseContract)==null?void 0:v.fields.length)??0,c=cT[n.nodeType],h=BG(n);return C.jsxs("div",{style:{...z9,background:r.nodeBg,boxShadow:r.nodeShadow,borderTop:e?`2px solid ${t}`:r.nodeBorder,borderRight:e?`2px solid ${t}`:r.nodeBorder,borderBottom:e?`2px solid ${t}`:r.nodeBorder,borderLeft:`8px solid ${t}`,borderRadius:n.nodeType==="end"?999:n.nodeType==="condition"?24:18},"aria-label":`${Mp[n.nodeType]} node: ${n.label}`,children:[C.jsx(up,{type:"target",position:Pt.Left}),C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:t,style:{flexShrink:0},children:C.jsx("path",{d:c})}),C.jsx("span",{style:{color:t,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase"},children:Mp[n.nodeType]})]}),C.jsx("strong",{style:{fontSize:14,color:r.nodeText},children:n.label}),h?C.jsx("span",{style:{fontSize:11,color:r.nodeMutedText,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}):null,n.ruleCode?C.jsxs("span",{style:{fontSize:12,color:r.nodeSubtext},children:["Rule: ",n.ruleCode]}):null,(y=n.contractRef)!=null&&y.sourceCode?C.jsxs("span",{style:{fontSize:11,color:r.nodeMutedText},children:["Contract: ",n.contractRef.sourceType,"/",n.contractRef.sourceCode]}):null,i.body?C.jsxs("span",{style:{display:"inline-block",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,color:r.nodeSubtext},children:[i.language.toUpperCase(),": ",i.body]}):null,s>0||l>0?C.jsxs("span",{style:{fontSize:11,color:r.nodeMutedText},children:["Inline contracts ",s,"/",l]}):null]}),C.jsx(up,{type:"source",position:Pt.Right})]})}const pT={trigger:ff,condition:ff,action:ff,"decision-table":ff,"sub-flow":ff,liquid:ff,connector:ff,end:ff};function df({path:n}){const e=Array.isArray(n)?n:[n];return C.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:e.map((t,r)=>C.jsx("path",{d:t},r))})}function UG({onAddTrigger:n}){return C.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:C.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:[C.jsxs("svg",{width:32,height:32,viewBox:"0 0 16 16",fill:"var(--mu-color-interactive)",opacity:.7,children:[C.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"}),C.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"})]}),C.jsx("strong",{style:{fontSize:"var(--mu-text-md)",color:"var(--mu-text-primary)"},children:"Start your workflow"}),C.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."}),C.jsx("button",{type:"button",onClick:n,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 VG({nodeIds:n,syncToken:e,hostElement:t}){const r=NV(),i=Kg(),s=IV({includeHiddenNodes:!0}),l=q.useRef(""),c=q.useRef(null);function h(){!s||n.length===0||(n.forEach(v=>r(v)),i.fitView(EL))}function m(v=0){return window.setTimeout(()=>{c.current!==null&&cancelAnimationFrame(c.current),c.current=requestAnimationFrame(()=>{c.current=null,h()})},v)}return q.useEffect(()=>{const v=String(e);if(!s||n.length===0||l.current===v)return;l.current=v;const y=m(),x=m(150),S=m(350);return()=>{window.clearTimeout(y),window.clearTimeout(x),window.clearTimeout(S),c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[n,s,i,e,r]),q.useEffect(()=>{if(!t)return;const v=new ResizeObserver(()=>{h()});v.observe(t);const y=()=>h();return window.addEventListener("resize",y),()=>{v.disconnect(),window.removeEventListener("resize",y)}},[t,s,i,r,n]),null}function FG(){const n=Kg();return q.useEffect(()=>{function e(t){const r=t.target,i=r.tagName.toLowerCase();if(i==="input"||i==="textarea"||i==="select"||r.isContentEditable)return;const s=t.ctrlKey||t.metaKey;if(t.key==="+"||s&&t.key==="="){t.preventDefault(),n.zoomIn({duration:150});return}if(t.key==="-"||s&&t.key==="-"){t.preventDefault(),n.zoomOut({duration:150});return}if(t.key==="f"||t.key==="F"||s&&t.key==="0"){t.preventDefault(),n.fitView(EL);return}}return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),null}function XG({graph:n,onGraphChange:e,readOnly:t=!1,theme:r="light",height:i=640,apiBaseUrl:s,catalogApiBase:l,tenantId:c,workflowCode:h,onPublish:m,licenseStatus:v="licensed",showHeader:y=!0,version:x=null,onVersionChange:S,editorRoot:E}){var mf;const k=q.useMemo(()=>Ai(n),[n]),R=rq(k);function P(I){return I.map(H=>({...H,data:{...H.data,_theme:r}}))}function Q(I){const H=r==="dark"?PG:xL,Se=r==="dark"?IG:jG;return I.map(We=>{var Ii;const Ae=((Ii=We.data)==null?void 0:Ii.edgeType)??"always",xt=H[Ae]??H.always,kt=Se[Ae]??Se.always,gn=hT[Ae]??"Always";return{...We,label:gn,style:{stroke:xt,strokeWidth:2},labelStyle:{fill:kt.text,fontWeight:600,fontSize:12,letterSpacing:"0.02em"},labelBgStyle:{fill:kt.bg},labelBgPadding:[4,8],labelBgBorderRadius:999}})}const[A,L]=q.useState(()=>P(Zv(R.present))),[B,j]=q.useState(()=>Q(G5(R.present))),[Z,ee]=q.useState(""),[ie,pe]=q.useState(""),[oe,W]=q.useState("basic-info"),[le,V]=q.useState({status:"idle"}),[se,ne]=q.useState([]),[ae,Y]=q.useState([]),[G,ue]=q.useState(null),[F,K]=q.useState({status:"idle"}),[Te,Ee]=q.useState([]),[ze,Ie]=q.useState([]),[Be,Pe]=q.useState(!1),[Ze,rt]=q.useState(null),[dt,ut]=q.useState(""),[et,At]=q.useState(""),Tt=q.useRef(R.present.metadata),bt=q.useRef(Yi(R.present)),[Sn,hr]=q.useState(0),Bt=q.useRef(A),Yt=q.useRef(B),Jt=q.useRef(new Map),Xt=q.useRef(new Map),Gn=q.useRef(null),Wr=q.useRef(new Map),rn=q.useMemo(()=>s?new m6({baseUrl:s,tenantId:c}):null,[s,c]),Wn=q.useMemo(()=>l?new g6({baseUrl:l,tenantId:c}):null,[l,c]),Kn=q.useMemo(()=>s?new v6({baseUrl:s,tenantId:c}):null,[s,c]),di=q.useRef(null),Di=q.useRef(null);q.useRef(null);const Fe=q.useRef(!0),ht=q.useRef(!1),Zt=q.useRef(null),[un,Dn]=q.useState(0),[Jn,Ln]=q.useState("inspector"),[lr,zn]=q.useState(!1),cn=q.useRef(null),[on,hi]=q.useState(()=>{try{const I=localStorage.getItem("muonroi-rule-studio-sidebar-width");return I?Math.max(240,Math.min(400,Number(I))):280}catch{return 280}}),[$n,Li]=q.useState(()=>{try{return localStorage.getItem("muonroi-rule-studio-sidebar-collapsed")==="true"}catch{return!1}}),pi=q.useRef(!1),[qa,Ga]=q.useState(()=>{try{const I=localStorage.getItem("muonroi-rule-studio-toolbar-groups");return I?JSON.parse(I):{}}catch{return{}}}),Ar=I=>qa[I]===!0,So=I=>Ga(H=>{const Se={...H,[I]:!H[I]};try{localStorage.setItem("muonroi-rule-studio-toolbar-groups",JSON.stringify(Se))}catch{}return Se}),[Ka,Hr]=q.useState(!1),[Cr,er]=q.useState(!1),Gi=q.useRef(null),mi=q.useRef(null),[Qr,gi]=q.useState([]),[re,$e]=q.useState(0),[Ge,it]=q.useState(!1),[Ut,Qt]=q.useState(!1),Lt=q.useMemo(()=>Qr.find(I=>I.isActive)??null,[Qr]),jt=x!=null&&Lt!=null&&x!==Lt.version,an=t||jt,mn=q.useCallback((I,H)=>{if(!s||!h){H||gi([]);return}const Se=s.replace(/\/$/,""),We=Uo(void 0,{tenantId:c});H&&Qt(!0),fetch(`${Se}/rulesets/${encodeURIComponent(h)}/versions?limit=10&offset=${I}`,{headers:We}).then(Ae=>Ae.ok?Ae.json():[]).then(Ae=>{const xt=Array.isArray(Ae)?Ae:Array.isArray(Ae==null?void 0:Ae.items)?Ae.items:[];it(xt.length===10),gi(H?kt=>[...kt,...xt].sort((gn,Ii)=>Ii.version-gn.version):xt.sort((kt,gn)=>gn.version-kt.version))}).catch(Ae=>{console.warn("[MVersionDropdown] Failed to fetch versions:",Ae),H||gi([])}).finally(()=>{H&&Qt(!1)})},[s,h,c]);q.useEffect(()=>{$e(0),it(!1),mn(0,!1)},[mn]);const Zn=q.useCallback(()=>{const I=re+10;$e(I),mn(I,!0)},[re,mn]);q.useEffect(()=>{Bt.current=A},[A]),q.useEffect(()=>{Yt.current=B},[B]),q.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-width",String(on))}catch{}},[on]),q.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-collapsed",String($n))}catch{}},[$n]),q.useEffect(()=>{const I=Gi.current;if(!I)return;const H=new ResizeObserver(Se=>{for(const We of Se){const xt=We.contentRect.width<_L;Hr(xt),xt||er(!1)}});return H.observe(I),()=>H.disconnect()},[]),q.useEffect(()=>{if(!Cr)return;const I=H=>{mi.current&&!mi.current.contains(H.target)&&er(!1)};return document.addEventListener("click",I),()=>document.removeEventListener("click",I)},[Cr]),q.useEffect(()=>()=>{Ji(),Lr()},[]),q.useEffect(()=>{L(I=>P(I)),j(I=>Q(I))},[r]),q.useEffect(()=>{const I=Ai(n),H=Yi(I);H!==bt.current&&(Tt.current=I.metadata,R.reset(I),bt.current=H,Fe.current=!0,hr(Se=>Se+1),ee(""),pe(""),W("basic-info"),es(I))},[n,R.reset]),q.useEffect(()=>{const I=R.present,H=Yi(I),Se=Yi(ur(Bt.current,Yt.current,!1));H!==Se&&(Tt.current=I.metadata,bt.current=H,es(I))},[R.present]),q.useEffect(()=>{const I=H=>{H.target;const Se=H.composedPath().some(We=>{if(!(We instanceof HTMLElement))return!1;const Ae=We.tagName;return Ae==="INPUT"||Ae==="TEXTAREA"||Ae==="SELECT"||We.isContentEditable});if((H.ctrlKey||H.metaKey)&&H.key==="z"&&!H.shiftKey){H.preventDefault(),Ji(),R.undo();return}if((H.ctrlKey||H.metaKey)&&(H.key==="y"||H.key==="z"&&H.shiftKey)){H.preventDefault(),Ji(),R.redo();return}if(H.key==="Escape"){ee(""),pe(""),W("basic-info");return}if(!(an||Se)&&(H.key==="Delete"||H.key==="Backspace")){if(Z){qr();return}ie&&zi()}};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[an,Z,ie]),q.useEffect(()=>{const I=di.current;if(!I)return;const H=()=>{var Ae;const We=((Ae=I.parentElement)==null?void 0:Ae.getBoundingClientRect().width)??I.getBoundingClientRect().width;Dn(We)};H();const Se=new ResizeObserver(()=>H());return Se.observe(I),()=>Se.disconnect()},[]);const[pr,ri]=q.useState(0),mr=q.useMemo(()=>ur(A,B,!1),[A,B]),zt=q.useMemo(()=>bL(mr,{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}),[pr,mr,h]),qe=q.useMemo(()=>Z?P(Zv(zt)).find(I=>I.id===Z)??null:null,[zt,Z,r]),vi=q.useMemo(()=>ie?B.find(I=>I.id===ie)??null:null,[B,ie]),Ja=qe?iu(qe.data):{language:"feel",body:""},Ki=q.useMemo(()=>fT(mr,{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}),[pr,mr,h]),Dr=q.useMemo(()=>Ki.issues.filter(I=>I.severity==="error"),[Ki.issues]),_s=q.useMemo(()=>Ki.issues.filter(I=>I.severity==="warning"),[Ki.issues]),ko=!an&&!!m&&Dr.length===0,Yr=q.useMemo(()=>qG(zt),[zt]);if(q.useEffect(()=>{if(!rn)return;let I=!1;return(async()=>{try{const H=await rn.MListFlows();I||ne(H.map(Se=>({code:Se.workflowName,label:Se.workflowName})))}catch{}})(),()=>{I=!0}},[rn]),q.useEffect(()=>{if(!Kn)return;let I=!1;return(async()=>{try{const H=await Kn.MListDecisionTables();if(!I){for(const Se of H)Wr.current.set(Se.id,Se);Y(H.map(Se=>({code:Se.id,label:Se.name})))}}catch{}})(),()=>{I=!0}},[Kn]),q.useEffect(()=>{const I=l?l.replace(/\/catalog\/palette\/?$/,""):s;if(!I)return;let H=!1;return(async()=>{try{const Se=await O6.MGetCatalog(I,Uo(void 0,{tenantId:c}));H||Ee(Se)}catch{H||Ee([])}})(),()=>{H=!0}},[l,s]),q.useEffect(()=>{var We,Ae,xt;if((qe==null?void 0:qe.data.nodeType)!=="decision-table"){ue(null),K({status:"idle"});return}if(!Kn){ue(null),K({status:"error",message:"No decision table API configured for this editor."});return}const I=((Ae=(We=qe.data.contractRef)==null?void 0:We.sourceCode)==null?void 0:Ae.trim())??((xt=qe.data.ruleCode)==null?void 0:xt.trim())??"";if(!I){ue(null),K({status:"idle"});return}const H=Wr.current.get(I);if(H){ue(H),K({status:"ready"}),Go(qe.id,H);return}let Se=!1;return K({status:"loading"}),(async()=>{try{const kt=await Kn.MGetDecisionTable(I);if(Se)return;Wr.current.set(I,kt),ue(kt),K({status:"ready"}),Go(qe.id,kt)}catch(kt){Se||(ue(null),K({status:"error",message:kt instanceof Error?kt.message:"Failed to load decision table metadata."}))}})(),()=>{Se=!0}},[Kn,qe==null?void 0:qe.id,qe==null?void 0:qe.data.nodeType,(mf=qe==null?void 0:qe.data.contractRef)==null?void 0:mf.sourceCode,qe==null?void 0:qe.data.ruleCode]),q.useEffect(()=>{if(!Wn){Ie([]),Pe(!1);return}let I=!1;return(async()=>{Pe(!0);try{const H=await Wn.MListCatalog();I||(Ie(H),Pe(!1))}catch{I||(Ie([]),Pe(!1))}})(),()=>{I=!0}},[Wn]),q.useEffect(()=>{if(!rn||!h)return;let I=!1;return(async()=>{var H,Se;await RL(rn,Xt.current,h);for(const We of mr.nodes){if(We.type==="trigger"||We.type==="end"||Jt.current.has(We.id))continue;const Ae=await WG(rn,h,We);Ae&&Jt.current.set(We.id,Ae)}for(const We of mr.nodes.filter(Ae=>Ae.type==="sub-flow")){const Ae=(H=fl(We.data.subFlowConfig).targetFlowCode)==null?void 0:H.trim();if(!Ae)continue;const xt=await RL(rn,Xt.current,Ae);if(I)return;const kt=await PL(rn,Ae,"trigger"),gn=(kt==null?void 0:kt.requestScope)??(xt==null?void 0:xt.requestContract),Ii=(Se=fl(We.data.subFlowConfig).childTriggerSchema)==null?void 0:Se.contractName;gn!=null&&gn.contractName&&Ii!==gn.contractName&&qo(We.id,ta=>({...ta,data:{...ta.data,subFlowConfig:{...fl(ta.data.subFlowConfig),childTriggerSchema:gn}}}),!1)}I||ri(We=>We+1)})(),()=>{I=!0}},[rn,mr.nodes,h]),q.useEffect(()=>{var H,Se;if(!qe){V({status:"idle"});return}Ln("inspector");const I=qe&&Jt.current.get(qe.id);if(I||(H=qe.data.contractLayer)!=null&&H.upstreamScope||qe.type==="trigger"||qe.type==="end"){V({status:"ready",title:(I==null?void 0:I.ruleCode)??((Se=qe.data.contractRef)==null?void 0:Se.label)??qe.data.label});return}V(rn?{status:"loading"}:{status:"error",message:"No contract API configured for this editor."})},[rn,qe,pr]),v==="unlicensed"){const I=uT();return C.jsxs("section",{style:{...iK,background:I.licenseBg,border:I.licenseBorder,color:I.licenseText},children:[C.jsx("strong",{children:"Rule Flow Designer requires a Muonroi commercial license."}),C.jsx("span",{children:"Load an activation proof before rendering this editor."})]})}function Ji(){cn.current!==null&&(window.clearTimeout(cn.current),cn.current=null)}function Lr(){Zt.current!==null&&(window.clearTimeout(Zt.current),Zt.current=null)}function es(I){Lr(),ht.current=!0,L(P(Zv(I))),j(Q(G5(I))),Zt.current=window.setTimeout(()=>{ht.current=!1,Zt.current=null},0)}function eo(I,H){var xt;Ji();const Se=Lp(I,{currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}),We=Ai(Se.graph),Ae=Yi(We);if(Tt.current=We.metadata,bt.current=Ae,es(We),H!=null&&H.syncViewport&&(Fe.current=!0,hr(kt=>kt+1)),Se.issues.length>0){const kt=((xt=Se.issues[0])==null?void 0:xt.message)??"Rule flow ordering is invalid.";V({status:"error",message:kt})}(H==null?void 0:H.pushHistory)!==!1&&R.commit(We),(H==null?void 0:H.notify)!==!1&&(e==null||e(We))}function ur(I,H,Se=!0){return{nodes:I.map(HG),edges:H.map(YG),metadata:{...Tt.current,version:Math.max(1,Tt.current.version??1),lastModifiedAt:Se?new Date().toISOString():Tt.current.lastModifiedAt}}}function qo(I,H,Se=!0){const We=Bt.current.map(xt=>xt.id===I?H(xt):xt),Ae=Lp(ur(We,Yt.current),{currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}).graph;Tt.current=Ae.metadata,bt.current=Yi(Ae),L(P(Zv(Ae))),Se&&(e==null||e(Ae))}function An(I,H="debounced"){if(t||!Z)return;const Se=Bt.current.map(Ae=>Ae.id===Z?I(Ae):Ae),We=Lp(ur(Se,Yt.current),{currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}).graph;if(Tt.current=We.metadata,bt.current=Yi(We),L(P(Zv(We))),e==null||e(We),H==="immediate"){R.commit(We);return}Ji(),cn.current=window.setTimeout(()=>{cn.current=null,R.commit(We)},300)}function qr(){t||!Z||(ee(""),W("basic-info"),eo(ur(Bt.current.filter(I=>I.id!==Z),Yt.current.filter(I=>I.source!==Z&&I.target!==Z))))}function zi(){t||!ie||(pe(""),eo(ur(Bt.current,Yt.current.filter(I=>I.id!==ie))))}function ts(I){if(t||!ie)return;const H=Yt.current.map(Se=>Se.id===ie?I(Se):Se);eo(ur(Bt.current,H),{syncViewport:!1})}function Co(I){ee(I),pe("");const H=Bt.current.find(Se=>Se.id===I);H&&W(Y5(H.data.nodeType)),Ln("inspector")}function Go(I,H){const Se=ML(H,"input"),We=ML(H,"output");qo(I,Ae=>{var xt;return{...Ae,data:{...Ae.data,description:(xt=Ae.data.description)!=null&&xt.trim()?Ae.data.description:H.description,requestContract:Se,responseContract:We,contractRef:{sourceType:"decision-table",sourceCode:H.id,label:H.name}}}},!1),ri(Ae=>Ae+1)}function ka(){const I=mT(ur(Bt.current,Yt.current));Fe.current=!0,eo(I,{syncViewport:!0})}function ns(I){const H=[...Yt.current];if(Z){const Se=`${Z}-${I.id}`;H.push({id:Se,source:Z,target:I.id,label:"always",data:{edgeType:"always"}}),pe(Se)}ee(I.id),pe(""),W(Y5(I.data.nodeType)),eo(mT(ur([...Bt.current,I],H)),{syncViewport:!0})}function to(I,H){if(t)return;const Se={id:`node-${I}-${Math.random().toString(36).slice(2,10)}`,type:I,position:H??{x:60+Bt.current.length*36,y:80+Bt.current.length%4*90},data:{label:X5[I],nodeType:I,expression:JC(I),conditionConfig:I==="condition"?{successLabel:"Valid",failureLabel:"Rejected"}:void 0,subFlowConfig:I==="sub-flow"?{targetFlowCode:"",inputMappings:[],outputMappings:[]}:void 0,liquidConfig:I==="liquid"?{outputFormat:"json"}:void 0}};ns(Se)}function hl(I,H){if(t)return;const Se={id:`node-rule-${Math.random().toString(36).slice(2,10)}`,type:"condition",position:H??{x:60+Bt.current.length*36,y:80+Bt.current.length%4*90},data:{label:I.displayName,nodeType:"condition",ruleCode:I.code,description:I.description,expression:JC("condition"),contractRef:{sourceType:"rule",sourceCode:I.code,label:I.displayName},requestContract:I.inputSchema,responseContract:I.outputSchema}};ns(Se)}function rs(){to("trigger",{x:200,y:180})}const tn=q.useRef(null),su=q.useCallback(I=>{pi.current=!0,tn.current={startX:I.clientX,startW:on},I.currentTarget.setPointerCapture(I.pointerId),I.preventDefault()},[on]),fn=q.useCallback(I=>{if(!pi.current||!tn.current)return;const H=tn.current.startW+(I.clientX-tn.current.startX);hi(Math.max(240,Math.min(400,H)))},[]),Ju=q.useCallback(I=>{pi.current&&(pi.current=!1,tn.current=null,I.currentTarget.releasePointerCapture(I.pointerId))},[]),Ca=typeof i=="number"?`${i}px`:i,Nt=un>0&&un<_L,lu=Nt?"min(52vh, 520px)":Ca,He=uT(),Ta={color:He.textPrimary},yi=C.jsxs("div",{"data-testid":"rule-flow-sidebar-palette",style:{...AL,...tK,...hK(),gap:8,padding:12},children:[Object.keys(pT).map(I=>C.jsxs("button",{type:"button",style:sK(I,He),"data-testid":`palette-${I}`,draggable:!t,onClick:()=>to(I),onDragStart:H=>As(H,I),disabled:t,children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:Iv[I],style:{flexShrink:0},children:C.jsx("path",{d:cT[I]})}),C.jsx("span",{style:{fontWeight:600},children:Mp[I]})]}),C.jsx("span",{style:{fontSize:11,color:He.textMuted,fontWeight:400},children:RG[I]})]},I)),l?C.jsx(pG,{groups:ze,loading:Be,readOnly:t,onAddRule:hl,onDragStart:(I,H)=>As(I,"condition",H)}):null]}),Ea=()=>{const I=document.createElement("input");I.type="file",I.accept="application/json,.json",I.style.position="fixed",I.style.top="-9999px",document.body.appendChild(I),I.addEventListener("change",()=>{var Se;const H=(Se=I.files)==null?void 0:Se[0];document.body.removeChild(I),H&&(async()=>{try{const We=await H.text(),Ae=Lp(j9(We),{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}).graph;Tt.current=Ae.metadata,bt.current=Yi(Ae),R.reset(Ae),es(Ae),ee(""),pe(""),W("basic-info"),Fe.current=!0,hr(xt=>xt+1),e==null||e(Ae),V({status:"ready",title:Ae.metadata.ruleSetCode??"Imported flow"})}catch(We){V({status:"error",message:We.message})}})()}),I.click()},Hn=()=>KG(ur(Bt.current,Yt.current),Tt.current.ruleSetCode),Nn=()=>{const I=fT(ur(Bt.current,Yt.current),{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current});ri(H=>H+1),I.isValid?(V({status:"ready",title:`Valid — ${I.issues.filter(H=>H.severity==="warning").length} warning(s)`}),ut(`Validation passed with ${I.issues.filter(H=>H.severity==="warning").length} warning(s).`)):(V({status:"error",message:`${I.issues.filter(H=>H.severity==="error").length} error(s) found.`}),ut(`Validation complete: ${I.issues.filter(H=>H.severity==="error").length} error(s), ${I.issues.filter(H=>H.severity==="warning").length} warning(s).`))},Rs=()=>{const I=fT(ur(Bt.current,Yt.current),{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current});if(ri(H=>H+1),!I.isValid){V({status:"error",message:"Publish blocked because one or more nodes still have contract validation errors."}),At("Publish blocked: one or more nodes still have contract validation errors.");return}rt({graph:I.graph,warnings:I.issues.filter(H=>H.severity==="warning")})},wr=I=>C.jsxs("button",{type:"button",style:I?{...vT,display:"flex",alignItems:"center",gap:5,visibility:jt?"hidden":void 0}:{...wa(!0),display:jt?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:()=>{Rs(),I&&setTimeout(()=>er(!1),0)},disabled:!ko,title:m?Dr.length>0?"Fix validation errors before publishing.":"Publish":"No publish handler configured.","aria-disabled":!ko,children:[C.jsx(df,{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"]}),ii=I=>C.jsxs("button",{type:"button",style:I?{...vT,display:"flex",alignItems:"center",gap:5,visibility:jt?"hidden":void 0}:{...wa(!1),display:jt?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},disabled:an,onClick:()=>{Ea(),I&&setTimeout(()=>er(!1),0)},title:"Import",children:[C.jsx(df,{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"]}),no=I=>C.jsxs("button",{type:"button",style:I?{...vT,display:"flex",alignItems:"center",gap:5}:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Hn(),I&&setTimeout(()=>er(!1),0)},title:"Export",children:[C.jsx(df,{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"]}),pl=C.jsxs("div",{"data-testid":"rule-flow-sidebar-actions",style:{display:"flex",flexDirection:"column",gap:8},ref:Gi,children:[Ki.issues.length>0?C.jsxs("div",{style:oK(Dr.length>0),children:[C.jsx("strong",{children:Dr.length>0?"Publish blocked":"Publish warnings"}),C.jsxs("span",{children:[Dr.length," error(s) / ",_s.length," warning(s)"]}),Dr.length>0?C.jsxs("ul",{style:{margin:"6px 0 0",padding:"0 0 0 16px",fontSize:12,lineHeight:1.5},children:[Dr.slice(0,20).map((I,H)=>C.jsxs("li",{style:{marginBottom:2},children:[C.jsx("code",{style:{fontSize:11,fontWeight:600},children:I.code}),I.nodeId?C.jsxs("span",{style:{color:"var(--mu-text-muted)"},children:[" [",I.nodeId,"]"]}):null," ",I.message]},H)),Dr.length>20?C.jsxs("li",{children:["...and ",Dr.length-20," more"]}):null]}):null]}):null,C.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:"var(--mu-space-xs)"},children:[C.jsxs("div",{"data-testid":"toolbar-group-history",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[C.jsx("button",{type:"button",onClick:()=>So("history"),style:gT(He),title:Ar("history")?"Expand History":"Collapse History",children:Ar("history")?"History ▸":"History ▾"}),Ar("history")?null:C.jsxs(C.Fragment,{children:[C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Ji(),R.undo()},disabled:an||!R.canUndo,title:"Undo (Ctrl+Z)",children:[C.jsx(df,{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"]}),C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Ji(),R.redo()},disabled:an||!R.canRedo,title:"Redo (Ctrl+Shift+Z)",children:[C.jsx(df,{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"]})]})]}),C.jsx("div",{style:{width:1,height:24,background:He.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),C.jsxs("div",{"data-testid":"toolbar-group-canvas",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[C.jsx("button",{type:"button",onClick:()=>So("canvas"),style:gT(He),title:Ar("canvas")?"Expand Canvas":"Collapse Canvas",children:Ar("canvas")?"Canvas ▸":"Canvas ▾"}),Ar("canvas")?null:C.jsxs(C.Fragment,{children:[C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:96},onClick:ka,disabled:an,title:"Auto Layout",children:[C.jsx(df,{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"]}),C.jsxs("button",{type:"button",style:{...wa(!1),display:jt?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:Nn,disabled:an,title:"Validate",children:[C.jsx(df,{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"]}),C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:72},onClick:Kt,disabled:!s||!h,title:"Dry Run",children:[C.jsx(df,{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"]})]})]}),C.jsx("div",{style:{width:1,height:24,background:He.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),Ka?C.jsxs("div",{style:{position:"relative"},ref:mi,children:[C.jsx("button",{type:"button",onClick:()=>er(I=>!I),style:{...wa(!1),minWidth:32,padding:"6px 8px",fontSize:16},title:"More actions","aria-label":"More actions",children:"⋮"}),Cr?C.jsxs("div",{style:{position:"absolute",top:"100%",right:0,marginTop:4,background:He.overlayBg,border:He.overlayBorder,borderRadius:10,boxShadow:He.overlayShadow,padding:"4px 0",minWidth:140,zIndex:10},children:[wr(!0),ii(!0),no(!0)]}):null]}):C.jsxs("div",{"data-testid":"toolbar-group-workflow",style:{display:"flex",alignItems:"center",gap:4},children:[C.jsx("button",{type:"button",onClick:()=>So("workflow"),style:gT(He),title:Ar("workflow")?"Expand Workflow":"Collapse Workflow",children:Ar("workflow")?"Workflow ▸":"Workflow ▾"}),Ar("workflow")?null:C.jsxs(C.Fragment,{children:[wr(),ii(),no()]})]})]})]}),ec=C.jsx("div",{"data-testid":"rule-flow-sidebar-inspector",style:{...AL,...nK,...pK()},children:qe?C.jsx(Zq,{selectedNode:{id:qe.id,data:qe.data},selectedExpression:Ja,contractLoadState:le,selectedDecisionTable:G,decisionTableLoadState:F,readOnly:an,apiBaseUrl:s,inspectorTab:oe,flowOptions:se,decisionTableOptions:ae,setInspectorTab:W,onSelectNodeByRuleCode:I=>{const H=Bt.current.find(Se=>Se.data.ruleCode===I);H&&Co(H.id)},onUpdateLabel:I=>An(H=>({...H,data:{...H.data,label:I}})),onUpdateRuleCode:I=>An(H=>({...H,data:{...H.data,ruleCode:I,contractRef:H5(H.data.nodeType,I,H.data.contractRef)}})),onUpdateDescription:I=>An(H=>({...H,data:{...H.data,description:I}})),onUpdateContractRef:I=>An(H=>({...H,data:{...H.data,contractRef:I,requestContract:void 0,responseContract:void 0}})),onUpdateDecisionTableCode:I=>An(H=>{var Se;return{...H,data:{...H.data,ruleCode:I,requestContract:void 0,responseContract:void 0,contractRef:I.trim()?{sourceType:"decision-table",sourceCode:I.trim(),label:((Se=ae.find(We=>We.code===I.trim()))==null?void 0:Se.label)??I.trim()}:H.data.contractRef}}}),onUpdateConditionConfig:I=>An(H=>({...H,data:{...H.data,conditionConfig:I}})),onUpdateTargetFlowCode:I=>An(H=>({...H,data:{...H.data,contractRef:I.trim()?{sourceType:"flow",sourceCode:I.trim(),label:I.trim()}:H.data.contractRef,subFlowConfig:{...fl(H.data.subFlowConfig),targetFlowCode:I}}})),onUpdateLiquidOutput:I=>An(H=>({...H,data:{...H.data,liquidConfig:{...W5(H.data.liquidConfig),outputFormat:I}}})),onUpdateExpressionLanguage:I=>An(H=>({...H,data:{...H.data,expression:{...iu(H.data),language:I}}})),onUpdateExpressionBody:I=>An(H=>({...H,data:{...H.data,expression:{...iu(H.data),body:I}}})),onInsertExpressionToken:I=>{Gn.current?Gn.current.insert(I):An(H=>({...H,data:{...H.data,expression:{...iu(H.data),body:`${iu(H.data).body}${iu(H.data).body.trim()?" ":""}${I}`}}}))},onChangeInputContract:I=>An(H=>({...H,data:{...H.data,contractOverride:{...H.data.contractOverride,requestFields:I}}})),onChangeEffectiveMappings:I=>An(H=>({...H,data:{...H.data,inputMappings:H.data.nodeType==="action"?I.map(Se=>({id:Se.id,sourcePath:Se.sourcePath,targetPath:Se.targetField??Se.targetPath,transform:Se.transform,language:Se.language})):H.data.inputMappings,subFlowConfig:H.data.nodeType==="sub-flow"?{...fl(H.data.subFlowConfig),inputMappings:I.map(Se=>({id:Se.id,sourcePath:Se.sourcePath,targetPath:Se.targetField??Se.targetPath,transform:Se.transform,language:Se.language}))}:H.data.subFlowConfig,contractLayer:H.data.contractLayer}})),onChangeOutputContract:I=>An(H=>({...H,data:{...H.data,contractOverride:{...H.data.contractOverride,responseFields:I.filter(Se=>!Se.isResultPayload)}}}),"immediate"),onDeleteNode:qr,connectorCatalog:Te,onUpdateConnectorConfig:I=>An(H=>({...H,data:{...H.data,connectorConfig:I}})),onSetInsertRef:I=>{Gn.current=I},shadowRoot:E instanceof ShadowRoot?E:void 0,showSectionHeader:!1}):C.jsx(JG,{selectedEdge:vi,readOnly:t,onUpdateEdgeType:I=>ts(H=>({...H,label:I,data:{...H.data??{},edgeType:I}})),onDeleteEdge:zi})}),is=s?s.includes("localhost")||s.includes("127.0.0.1")?"DEV":"PROD":null,[Ps,ml]=q.useState(!1),[Ld,Ni]=q.useState(!1),[To,Ko]=q.useState(!1),[ro,Ms]=q.useState("{}"),[_a,Jo]=q.useState(null),[ea,gl]=q.useState(!1),[vl,ji]=q.useState(null),[z,te]=q.useState(40),Oe=q.useRef(!1),[ke,Xe]=q.useState(new Set),[St,Ye]=q.useState(null);function Rt(){var We,Ae;const I=mr.nodes.find(xt=>xt.type==="trigger"),H=((We=I==null?void 0:I.data.requestContract)==null?void 0:We.fields)??((Ae=I==null?void 0:I.data.contractOverride)==null?void 0:Ae.requestFields);if(!H||H.length===0)return"{}";const Se={};for(const xt of H){const kt=(xt.dataType??"").toLowerCase();kt.includes("int")||kt.includes("number")||kt.includes("decimal")||kt.includes("float")||kt.includes("double")?Se[xt.path]=0:kt.includes("bool")?Se[xt.path]=!1:kt.includes("array")||kt.includes("list")?Se[xt.path]=[]:kt.includes("object")||kt.includes("map")||kt.includes("dict")?Se[xt.path]={}:Se[xt.path]=""}return JSON.stringify(Se,null,2)}function Kt(){Ko(!0),Jo(null),ji(null),Ms(Rt())}async function dn(){if(!(!s||!h)){gl(!0),ji(null),Jo(null);try{const I=s.replace(/\/$/,""),H=Uo(void 0,{tenantId:c});H.set("Content-Type","application/json");const Se=x!=null?`?version=${x}`:"",We=await fetch(`${I}/execute/${encodeURIComponent(h)}${Se}`,{method:"POST",headers:H,body:ro});if(!We.ok){const xt=await We.text();throw new Error(`Execution failed (${We.status}): ${xt}`)}const Ae=await We.json();Jo(Ae),jn(Ae)}catch(I){ji(I instanceof Error?I.message:"Unknown error")}finally{gl(!1)}}}function Un(I){const H=new Set;for(const Se of Object.keys(I)){const We=Se.match(/^__graph\.node\.(.+?)\.executed$/);We&&I[Se]===!0&&H.add(We[1])}return H}function jn(I){const H=Un(I.factBag);if(H.size===0)for(const We of I.results)H.add(We.ruleName);if(H.size>0){const We=new Map;for(const Ae of Bt.current)We.set(Ae.id,Ae.data.nodeType);for(const[Ae,xt]of We)xt==="trigger"&&H.add(Ae),xt==="end"&&I.isSuccess&&H.add(Ae)}Xe(H);const Se=new Map(I.results.map(We=>[We.ruleName,We]));L(We=>We.map(Ae=>{const xt=Ae.data.ruleCode||Ae.data.label,kt=H.has(Ae.id)||H.has(xt),gn=Se.get(xt);if(!kt)return{...Ae,style:{...Ae.style,opacity:.35,transition:"all 300ms ease",filter:"grayscale(0.5)"},className:""};const Ii=I.factBag[`__graph.node.${Ae.id}.passed`],ta=Ii!==void 0?Ii===!0:(gn==null?void 0:gn.isSuccess)??!0,as=ta?"var(--mu-color-success)":"var(--mu-color-error)",Np=ta?"color-mix(in oklch, var(--mu-color-success) 6%, transparent)":"color-mix(in oklch, var(--mu-color-error) 6%, transparent)";return{...Ae,style:{...Ae.style,opacity:1,background:Np,border:"none",borderLeft:`4px solid ${as}`,borderRadius:8,boxShadow:"none",transition:"all 300ms ease",filter:"none"},className:""}})),j(We=>We.map(Ae=>{const xt=Bt.current.find(as=>as.id===Ae.source),kt=Bt.current.find(as=>as.id===Ae.target),gn=(xt==null?void 0:xt.data.ruleCode)||(xt==null?void 0:xt.data.label)||Ae.source,Ii=(kt==null?void 0:kt.data.ruleCode)||(kt==null?void 0:kt.data.label)||Ae.target;return(H.has(Ae.source)||H.has(gn))&&(H.has(Ae.target)||H.has(Ii))?{...Ae,style:{...Ae.style,strokeWidth:3,opacity:1,transition:"all 300ms ease"}}:{...Ae,style:{...Ae.style,strokeWidth:1,opacity:.35,transition:"all 300ms ease"}}}))}function qt(){L(I=>I.map(H=>({...H,style:void 0,className:""}))),j(I=>Q(I.map(H=>({...H,style:void 0})))),Xe(new Set),Ye(null)}function Qn(){Ko(!1),Jo(null),ji(null),qt()}function ir(I,H){if(!_a||ke.size===0)return;const Se=H.data.ruleCode||H.data.label;(ke.has(H.id)||ke.has(Se))&&Ye({nodeId:Se,mousePos:{x:I.clientX,y:I.clientY}})}function $s(){Ye(null)}function tc(I){var kt;I.preventDefault(),Oe.current=!0;const H=I.clientY,Se=z,We=(kt=Di.current)==null?void 0:kt.getBoundingClientRect();if(!We)return;const Ae=gn=>{if(!Oe.current)return;const ta=(H-gn.clientY)/We.height*100,as=Math.min(70,Math.max(20,Se+ta));te(as)},xt=()=>{Oe.current=!1,document.removeEventListener("pointermove",Ae),document.removeEventListener("pointerup",xt)};document.addEventListener("pointermove",Ae),document.addEventListener("pointerup",xt)}return C.jsxs(p$,{children:[C.jsx(ZG,{politeMessage:dt,assertiveMessage:et}),y?C.jsxs("header",{style:{...CK,background:He.sidebarBg,borderBottom:He.sidebarBorder,color:He.textPrimary},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--mu-space-sm)"},children:[C.jsx("strong",{style:{fontSize:14},children:"Rule Studio"}),h?C.jsx("span",{style:{...Ku,background:He.actionPrimaryBg,border:He.actionPrimaryBorder,color:He.textPrimary},children:h}):null,Qr.length>0?C.jsx(w6,{versions:Qr,activeVersion:Lt,selectedVersion:x??null,onSelect:I=>S==null?void 0:S(I),onLoadMore:Zn,hasMore:Ge,loadingMore:Ut,tokens:He}):x!=null?C.jsxs("span",{style:{...Ku,background:He.actionPrimaryBg,border:He.actionPrimaryBorder,color:He.textPrimary,fontSize:11},children:["v",x]}):C.jsx("span",{style:{...Ku,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"}),Qr.length>1?C.jsx("span",{role:"button",tabIndex:0,style:{...Ku,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:()=>Ni(!0),onKeyDown:I=>{I.key==="Enter"&&Ni(!0)},children:"Compare"}):null,is?C.jsx("span",{style:{...Ku,background:is==="DEV"?"var(--mu-color-warning-bg)":"var(--mu-color-success-bg)",border:is==="DEV"?"1px solid var(--mu-color-warning-border)":"1px solid var(--mu-color-success-border)",color:is==="DEV"?He.warningText:"var(--mu-color-success-text)",fontSize:10,fontWeight:700},children:is}):null,an?C.jsx("span",{style:{...Ku,background:He.errorBg,border:He.errorBorder,color:He.errorText,fontSize:10,fontWeight:700},children:"READ-ONLY"}):null,(()=>{var Se;const I=x!=null?Qr.find(We=>We.version===x):Lt,H=(Se=I==null?void 0:I.status)==null?void 0:Se.toLowerCase();return H==="pendingapproval"?C.jsx("span",{style:{...Ku,background:"var(--mu-color-warning-bg)",border:"1px solid var(--mu-color-warning-border)",color:He.warningText,fontSize:10,fontWeight:700},children:"PENDING APPROVAL"}):H==="rejected"?C.jsx("span",{style:{...Ku,background:He.errorBg,border:He.errorBorder,color:He.errorText,fontSize:10,fontWeight:700},children:"REJECTED"}):H==="approved"&&!(I!=null&&I.isActive)?C.jsx("span",{style:{...Ku,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})()]}),C.jsxs("div",{style:{position:"relative"},children:[C.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",padding:4,color:He.textMuted,fontSize:16},onClick:()=>ml(I=>!I),title:"Technical details",children:C.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"currentColor",children:C.jsx("path",{d:"M7.5 1.5a6 6 0 100 12 6 6 0 000-12zM7 5h1v1H7V5zm0 2h1v4H7V7z"})})}),Ps?C.jsxs("div",{style:{...TK,background:He.dialogBg,border:He.dialogBorder,boxShadow:He.dialogShadow,color:He.textSecondary},children:[c?C.jsxs("span",{style:{fontSize:11},children:["Tenant: ",c]}):null,s?C.jsxs("span",{style:{fontSize:11,wordBreak:"break-all"},children:["API: ",s]}):null,!c&&!s?C.jsx("span",{style:{fontSize:11},children:"No API configured"}):null]}):null]})]}):null,jt?C.jsxs("div",{style:{padding:"8px 16px",background:"var(--mu-color-warning-bg)",borderBottom:"1px solid var(--mu-color-warning-border)",color:He.warningText,fontSize:12,display:"flex",alignItems:"center",gap:8},children:[C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:C.jsx("path",{d:"M8 1l7 14H1L8 1zm-.5 5v4h1V6h-1zm0 5v1h1v-1h-1z"})}),C.jsxs("span",{children:["Viewing version v",x," (read-only)"]}),C.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:6},children:[C.jsx("button",{type:"button",onClick:()=>{if(!s||!h||x==null)return;const I=s.replace(/\/$/,""),H=Uo(void 0,{tenantId:c});H.set("Content-Type","application/json"),fetch(`${I}/rulesets/${encodeURIComponent(h)}/versions`,{method:"POST",headers:H,body:JSON.stringify({sourceVersion:x})}).then(Se=>{if(!Se.ok)throw new Error("restore failed");return Se.json()}).then(Se=>{$e(0),mn(0,!1),Se.version!=null&&(S==null||S(Se.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"}),C.jsx("button",{type:"button",onClick:()=>S==null?void 0:S(null),style:{fontSize:11,padding:"4px 12px",borderRadius:6,fontWeight:600,cursor:"pointer",background:He.actionPrimaryBg,border:He.actionPrimaryBorder,color:He.textPrimary},children:"Back to Active"})]})]}):null,C.jsxs("section",{ref:di,style:{...eK,...lK(Nt,!!(qe||vi),on,$n),...Ta},children:[C.jsxs("aside",{"data-testid":"rule-flow-left-panel",style:{...uK,background:He.sidebarBg,border:He.sidebarBorder,width:$n?48:on,transition:pi.current?"none":"width 200ms ease",overflow:$n?"hidden":"auto",position:"relative"},children:[C.jsxs("div",{style:{padding:"var(--mu-space-sm)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[!$n&&C.jsx("strong",{style:{fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-semibold)",color:He.textPrimary},children:"Node Library"}),C.jsx("button",{type:"button",title:$n?"Expand Node Library":"Collapse Node Library",onClick:()=>Li(I=>!I),style:{background:"transparent",border:"none",cursor:"pointer",padding:4,borderRadius:6,fontSize:14,color:He.textMuted,lineHeight:1,marginLeft:$n?"auto":void 0,marginRight:$n?"auto":void 0},children:$n?"›":"«"})]}),$n?C.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:4,padding:"8px 0"},children:Object.keys(pT).map(I=>C.jsx("div",{title:Mp[I],style:{width:32,height:32,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",cursor:"default",fontSize:16},children:C.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:Iv[I],style:{flexShrink:0},children:C.jsx("path",{d:cT[I]})})},I))}):yi,!$n&&C.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:su,onPointerMove:fn,onPointerUp:Ju,children:C.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:I=>{I.currentTarget.style.background="color-mix(in oklch, var(--mu-color-interactive) 15%, transparent)"},onPointerLeave:I=>{I.currentTarget.style.background="transparent"},children:[0,1,2].map(I=>C.jsx("div",{style:{width:4,height:4,borderRadius:"50%",background:"var(--mu-color-border-subtle, var(--mu-text-muted))"}},I))})})]}),C.jsxs("div",{ref:Di,style:{...rK,...dK(Nt),height:lu,background:He.canvasGradient,display:"flex",flexDirection:"column"},"data-testid":"rule-flow-canvas","data-node-count":A.length,"data-edge-count":B.length,onDragOver:zd,onDrop:pf,children:[C.jsx("style",{children:`
354
+ }`,{label:"class",detail:"definition",type:"keyword"}),ba('import {${names}} from "${module}"\n${}',{label:"import",detail:"named",type:"keyword"}),ba('import ${name} from "${module}"\n${}',{label:"import",detail:"default",type:"keyword"})],g9=M5.concat([ba("interface ${name} {\n ${}\n}",{label:"interface",detail:"definition",type:"keyword"}),ba("type ${name} = ${type}",{label:"type",detail:"definition",type:"keyword"}),ba("enum ${name} {\n ${}\n}",{label:"enum",detail:"definition",type:"keyword"})]),$5=new EW,A5=new Set(["Script","Block","FunctionExpression","FunctionDeclaration","ArrowFunction","MethodDeclaration","ForStatement"]);function jv(n){return(e,t)=>{let r=e.node.getChild("VariableDefinition");return r&&t(r,n),!0}}const v9=["FunctionDeclaration"],y9={FunctionDeclaration:jv("function"),ClassDeclaration:jv("class"),ClassExpression:()=>!0,EnumDeclaration:jv("constant"),TypeAliasDeclaration:jv("type"),NamespaceDeclaration:jv("namespace"),VariableDefinition(n,e){n.matchContext(v9)||e(n,"variable")},TypeDefinition(n,e){e(n,"type")},__proto__:null};function Q5(n,e){let t=$5.get(e);if(t)return t;let r=[],i=!0;function s(l,c){let h=n.sliceString(l.from,l.to);r.push({label:h,type:c})}return e.cursor(kr.IncludeAnonymous).iterate(l=>{if(i)i=!1;else if(l.name){let c=y9[l.name];if(c&&c(l,s)||A5.has(l.name))return!1}else if(l.to-l.from>8192){for(let c of Q5(n,l.node))r.push(c);return!1}}),$5.set(e,r),r}const D5=/^[\w$\xa1-\uffff][\w$\d\xa1-\uffff]*$/,L5=["TemplateString","String","RegExp","LineComment","BlockComment","VariableDefinition","TypeDefinition","Label","PropertyDefinition","PropertyName","PrivatePropertyDefinition","PrivatePropertyName","JSXText","JSXAttributeValue","JSXOpenTag","JSXCloseTag","JSXSelfClosingTag",".","?."];function O9(n){let e=xo(n.state).resolveInner(n.pos,-1);if(L5.indexOf(e.name)>-1)return null;let t=e.name=="VariableName"||e.to-e.from<20&&D5.test(n.state.sliceDoc(e.from,e.to));if(!t&&!n.explicit)return null;let r=[];for(let i=e;i;i=i.parent)A5.has(i.name)&&(r=r.concat(Q5(n.state.doc,i)));return{options:r,from:t?e.from:n.pos,validFor:D5}}const $d=Cv.define({name:"javascript",parser:m9.configure({props:[Ex.add({IfStatement:Ev({except:/^\s*({|else\b)/}),TryStatement:Ev({except:/^\s*({|catch\b|finally\b)/}),LabeledStatement:WW,SwitchBody:n=>{let e=n.textAfter,t=/^\s*\}/.test(e),r=/^\s*(case|default)\b/.test(e);return n.baseIndent+(t?0:r?1:2)*n.unit},Block:XW({closing:"}"}),ArrowFunction:n=>n.baseIndent+n.unit,"TemplateString BlockComment":()=>null,"Statement Property":Ev({except:/^\s*{/}),JSXElement(n){let e=/^\s*<\//.test(n.textAfter);return n.lineIndent(n.node.from)+(e?0:n.unit)},JSXEscape(n){let e=/\s*\}/.test(n.textAfter);return n.lineIndent(n.node.from)+(e?0:n.unit)},"JSXOpenTag JSXSelfClosingTag"(n){return n.column(n.node.from)+n.unit}}),JQ.add({"Block ClassBody SwitchBody EnumBody ObjectExpression ArrayExpression ObjectType":eD,BlockComment(n){return{from:n.from+2,to:n.to-2}},JSXElement(n){let e=n.firstChild;if(!e||e.name=="JSXSelfClosingTag")return null;let t=n.lastChild;return{from:e.to,to:t.type.isError?n.to:t.from}},"JSXSelfClosingTag JSXOpenTag"(n){var e;let t=(e=n.firstChild)===null||e===void 0?void 0:e.nextSibling,r=n.lastChild;return!t||t.type.isError?null:{from:t.to,to:r.type.isError?n.to:r.from}}})]}),languageData:{closeBrackets:{brackets:["(","[","{","'",'"',"`"]},commentTokens:{line:"//",block:{open:"/*",close:"*/"}},indentOnInput:/^\s*(?:case |default:|\{|\}|<\/)$/,wordChars:"$"}}),z5={test:n=>/^JSX/.test(n.name),facet:hC({commentTokens:{block:{open:"{/*",close:"*/}"}}})},x9=$d.configure({dialect:"ts"},"typescript"),b9=$d.configure({dialect:"jsx",props:[pC.add(n=>n.isTop?[z5]:void 0)]}),w9=$d.configure({dialect:"jsx ts",props:[pC.add(n=>n.isTop?[z5]:void 0)]},"typescript");let N5=n=>({label:n,type:"keyword"});const j5="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(N5),S9=j5.concat(["declare","implements","private","protected","public"].map(N5));function k9(n={}){let e=n.jsx?n.typescript?w9:b9:n.typescript?x9:$d,t=n.typescript?g9.concat(S9):M5.concat(j5);return new YQ(e,[$d.data.of({autocomplete:R7(L5,n5(t))}),$d.data.of({autocomplete:O9}),n.jsx?E9:[]])}function C9(n){for(;;){if(n.name=="JSXOpenTag"||n.name=="JSXSelfClosingTag"||n.name=="JSXFragmentTag")return n;if(n.name=="JSXEscape"||!n.parent)return null;n=n.parent}}function I5(n,e,t=n.length){for(let r=e==null?void 0:e.firstChild;r;r=r.nextSibling)if(r.name=="JSXIdentifier"||r.name=="JSXBuiltin"||r.name=="JSXNamespacedName"||r.name=="JSXMemberExpression")return n.sliceString(r.from,Math.min(r.to,t));return""}const T9=typeof navigator=="object"&&/Android\b/.test(navigator.userAgent),E9=yt.inputHandler.of((n,e,t,r,i)=>{if((T9?n.composing:n.compositionStarted)||n.state.readOnly||e!=t||r!=">"&&r!="/"||!$d.isActiveAt(n.state,e,-1))return!1;let s=i(),{state:l}=s,c=l.changeByRange(h=>{var m;let{head:v}=h,y=xo(l).resolveInner(v-1,-1),x;if(y.name=="JSXStartTag"&&(y=y.parent),!(l.doc.sliceString(v-1,v)!=r||y.name=="JSXAttributeValue"&&y.to>v)){if(r==">"&&y.name=="JSXFragmentTag")return{range:h,changes:{from:v,insert:"</>"}};if(r=="/"&&y.name=="JSXStartCloseTag"){let S=y.parent,E=S.parent;if(E&&S.from==v-2&&((x=I5(l.doc,E.firstChild,v))||((m=E.firstChild)===null||m===void 0?void 0:m.name)=="JSXFragmentTag")){let k=`${x}>`;return{range:Qe.cursor(v+k.length,-1),changes:{from:v,insert:k}}}}else if(r==">"){let S=C9(y);if(S&&S.name=="JSXOpenTag"&&!/^\/?>|^<\//.test(l.doc.sliceString(v,v+2))&&(x=I5(l.doc,S,v)))return{range:h,changes:{from:v,insert:`</${x}>`}}}}return{range:h}});return c.changes.empty?!1:(n.dispatch([s,l.update(c,{userEvent:"input.complete",scrollIntoView:!0})]),!0)}),_9=uC({String:Ce.string,Number:Ce.number,"True False":Ce.bool,PropertyName:Ce.propertyName,Null:Ce.null,", :":Ce.separator,"[ ]":Ce.squareBracket,"{ }":Ce.brace}),R9=Nv.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:[_9],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}),P9=Cv.define({name:"json",parser:R9.configure({props:[Ex.add({Object:Ev({except:/^\s*\}/}),Array:Ev({except:/^\s*\]/})}),JQ.add({"Object Array":eD})]}),languageData:{closeBrackets:{brackets:["[","{",'"']},indentOnInput:/^\s*[\}\]]$/}});function M9(){return new YQ(P9)}function B5(n){switch(n){case"feel":return SY;case"liquid":return TY;case"scriban":return RY;case"javascript":return k9();case"json":return M9();case"plain-text":return[]}}const Z5=new Gc,U5=new Gc,$9=new Gc,V5=new Gc;function YC({value:n,language:e,readOnly:t,onChange:r,onInsertToken:i,extensions:s,minHeight:l,root:c,singleLine:h=!1,placeholderText:m}){const v=l??(h?36:180),y=q.useRef(null),x=q.useRef(null),S=q.useRef(r),E=q.useRef(i);S.current=r,E.current=i,q.useEffect(()=>{if(!y.current)return;const R=[...h?[]:[xW(),UX()],jX(),GX(),eW(),rH(),lY(),SH(),ux.of([...E7,...$H,...fY]),yt.updateListener.of(A=>{A.docChanged&&S.current(A.state.doc.toString())}),Z5.of([yt.editable.of(!t),Mn.readOnly.of(t)]),U5.of(B5(e)),$9.of([]),V5.of(s??[]),...h?[yt.theme({"&":{maxHeight:`${v}px`},".cm-scroller":{overflow:"hidden"},".cm-content":{padding:"4px 8px"},".cm-gutters":{display:"none"}}),Mn.transactionFilter.of(A=>A.newDoc.lines>1?[]:A)]:[],...m?[WX(m)]:[]],P=Mn.create({doc:n,extensions:R}),Q=new yt({state:P,parent:y.current,root:c});return x.current=Q,E.current&&E.current({insert:A=>{const L=Q.state.selection.main.head;Q.dispatch({changes:{from:L,insert:A},selection:{anchor:L+A.length}}),Q.focus()}}),()=>{Q.destroy(),x.current=null}},[c]),q.useEffect(()=>{const R=x.current;if(!R)return;const P=R.state.doc.toString();P!==n&&R.dispatch({changes:{from:0,to:P.length,insert:n}})},[n]),q.useEffect(()=>{const R=x.current;R&&R.dispatch({effects:U5.reconfigure(B5(e))})},[e]),q.useEffect(()=>{const R=x.current;R&&R.dispatch({effects:Z5.reconfigure([yt.editable.of(!t),Mn.readOnly.of(t)])})},[t]),q.useEffect(()=>{const R=x.current;R&&R.dispatch({effects:V5.reconfigure(s??[])})},[s]);const k={minHeight:`${v}px`,border:"1px solid rgba(148, 163, 184, 0.24)",borderRadius:h?"6px":"14px",overflow:"hidden",...h?{marginBottom:0}:{}};return C.jsx("div",{ref:y,style:k})}function A9({value:n,onChange:e,onReset:t,tokens:r,editorRoot:i}){return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:0,borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"6px 12px",background:r.sidebarBg,borderBottom:`1px solid ${r.sidebarBorder.replace("1px solid ","")}`},children:[C.jsx("span",{style:{fontSize:12,fontWeight:600,color:r.textPrimary},children:"Input Data (JSON)"}),t?C.jsx("button",{type:"button",onClick:t,style:{background:"transparent",border:"none",cursor:"pointer",fontSize:11,color:r.textSecondary,textDecoration:"underline",padding:"2px 4px"},children:"Reset to Schema"}):null]}),C.jsx(YC,{value:n,language:"json",readOnly:!1,onChange:e,minHeight:160,singleLine:!1,root:i,placeholderText:'{ "key": "value" }'})]})}function F5({title:n,count:e,defaultExpanded:t,headerRight:r,children:i}){const[s,l]=q.useState(t);return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsxs("div",{role:"button",tabIndex:0,onClick:()=>l(!s),onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),l(!s))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[C.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:s?"▼":"▶"}),C.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:n}),e!==void 0?C.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]}),r]}),s?i:null]})}function Q9({entry:n,tokens:e,onShowFullFactBag:t}){var l,c,h;const r=n.businessFacts?n.businessFacts:n.outputs?Object.fromEntries(Object.entries(n.outputs).filter(([m])=>!m.startsWith("__graph.")&&!m.startsWith("__node.")&&!["executed","passed","errored","result"].includes(m))):{},i=Object.keys(r),s=((l=n.status)==null?void 0:l.elapsedMs)??n.elapsedMs;return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[C.jsx("button",{type:"button",onClick:t,style:{fontSize:12,color:e.textSecondary,cursor:"pointer",padding:"6px 10px",background:"none",border:"none",textAlign:"left",textDecoration:"none"},onMouseEnter:m=>{m.currentTarget.style.textDecoration="underline"},onMouseLeave:m=>{m.currentTarget.style.textDecoration="none"},children:"< Back to Full FactBag"}),C.jsxs("div",{style:{padding:"6px 8px",borderRadius:6,background:"color-mix(in oklch, var(--mu-border-subtle) 40%, transparent)"},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:(c=n.status)!=null&&c.message||n.errors&&n.errors.length>0?6:0},children:[C.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:n.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:n.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:n.isSuccess?"✓":"✗"}),C.jsx("span",{style:{fontSize:13,fontWeight:600,color:n.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:n.isSuccess?"Passed":"Failed"}),s!==void 0?C.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:[s,"ms"]}):null]}),(h=n.status)!=null&&h.message?C.jsx("div",{style:{fontSize:12,color:n.isSuccess?e.textSecondary:"var(--mu-color-error)",...n.isSuccess?{}:{borderLeft:"3px solid var(--mu-color-error)",paddingLeft:8}},children:n.status.message}):null,n.errors&&n.errors.length>0?C.jsx("div",{style:{marginTop:4,display:"flex",flexDirection:"column",gap:2},children:n.errors.map((m,v)=>C.jsx("div",{style:{fontSize:11,color:"var(--mu-color-error)",borderLeft:"3px solid var(--mu-color-error)",paddingLeft:8},children:m},v))}):null]}),C.jsx(F5,{title:"Output",count:n.changedKeys?n.changedKeys.length:void 0,defaultExpanded:!0,children:i.length>0?C.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:i.map(m=>C.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",fontSize:12},children:[C.jsxs("span",{style:{fontWeight:600,color:e.textSecondary},children:[m,":"]}),C.jsx("span",{style:{color:e.textPrimary},children:typeof r[m]=="object"&&r[m]!==null?JSON.stringify(r[m]):String(r[m]??"")})]},m))}):C.jsx("div",{style:{padding:"4px 8px",fontSize:11,color:e.textMuted,fontStyle:"italic"},children:"No output facts"})}),C.jsx(F5,{title:"Input",defaultExpanded:!1,children:n.inputSnapshot?C.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(n.inputSnapshot,null,2)}):C.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 D9({result:n,loading:e,error:t,onSelectNode:r,onClose:i,tokens:s}){const[l,c]=q.useState(null),h=n==null?void 0:n.results.find(y=>y.ruleName===l),m=(n==null?void 0:n.results.filter(y=>y.isSuccess).length)??0,v=(n==null?void 0:n.results.filter(y=>!y.isSuccess).length)??0;return C.jsxs("div",{style:{borderTop:`2px solid ${s.sidebarBorder.replace("1px solid ","")}`,height:380,overflow:"hidden",display:"flex",flexDirection:"column",background:s.inspectorBg},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"8px 12px",borderBottom:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,flexShrink:0},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsx("span",{style:{fontSize:14,fontWeight:600,color:s.textPrimary},children:"Dry Run Results"}),n?C.jsxs("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:12,background:n.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:n.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)",fontWeight:600},children:[n.executionTimeMs,"ms"]}):null]}),C.jsx("button",{type:"button",onClick:i,style:{background:"transparent",border:"none",cursor:"pointer",color:s.textMuted,fontSize:14,padding:2},title:"Close results",children:"X"})]}),C.jsx("div",{style:{flex:1,overflow:"hidden"},children:e?C.jsx("div",{style:{display:"flex",alignItems:"center",justifyContent:"center",height:"100%",color:s.textSecondary,fontSize:13},children:"Executing dry run..."}):t?C.jsxs("div",{style:{padding:16,color:s.errorText,fontSize:13},children:[C.jsx("strong",{children:"Error:"})," ",t]}):n?C.jsxs("div",{style:{display:"flex",height:"100%"},children:[C.jsx("div",{style:{width:"60%",overflow:"auto",borderRight:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`},children:C.jsxs("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[C.jsx("thead",{children:C.jsxs("tr",{style:{borderBottom:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,position:"sticky",top:0,background:s.inspectorBg,zIndex:1},children:[C.jsx("th",{style:{...qC,color:s.textSecondary},children:"Node"}),C.jsx("th",{style:{...qC,color:s.textSecondary,width:60},children:"Status"}),C.jsx("th",{style:{...qC,color:s.textSecondary,width:80},children:"Evaluation"})]})}),C.jsx("tbody",{children:n.results.map(y=>C.jsxs("tr",{onClick:()=>{const x=y.ruleName===l?null:y.ruleName;c(x),x&&(r==null||r(x))},style:{cursor:"pointer",borderBottom:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,background:l===y.ruleName?s.overlayItemSelectedBg:"transparent"},children:[C.jsxs("td",{style:{padding:"8px 12px",color:s.textPrimary,fontWeight:500,fontSize:13},children:[y.ruleName,y.errors&&y.errors.length>0?C.jsx("div",{style:{fontSize:11,color:s.errorText,marginTop:2},children:y.errors[0]}):null]}),C.jsx("td",{style:{padding:"8px 8px",textAlign:"center"},children:C.jsx("span",{style:{display:"inline-block",width:18,height:18,borderRadius:"50%",lineHeight:"18px",textAlign:"center",fontSize:11,fontWeight:700,background:y.isSuccess?"color-mix(in oklch, var(--mu-color-success-text) 15%, transparent)":"color-mix(in oklch, var(--mu-color-error) 15%, transparent)",color:y.isSuccess?"var(--mu-color-success-text)":"var(--mu-color-error)"},children:y.isSuccess?"✓":"✗"})}),C.jsx("td",{style:{padding:"6px 8px",textAlign:"center",fontSize:11,color:s.textSecondary},children:y.evaluationResult===!0?"true":y.evaluationResult===!1?"false":y.evaluationResult??"—"})]},y.ruleName))})]})}),C.jsx("div",{style:{width:"40%",overflow:"auto",padding:"10px 12px"},children:h?C.jsx(Q9,{entry:h,tokens:s,onShowFullFactBag:()=>c(null)}):C.jsxs(C.Fragment,{children:[C.jsx("div",{style:{fontSize:11,color:s.textSecondary,marginBottom:4,fontWeight:600},children:"Full FactBag"}),C.jsx("pre",{style:{margin:0,fontSize:11,lineHeight:1.5,color:s.textPrimary,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace)"},children:JSON.stringify((n==null?void 0:n.factBagClean)??(n==null?void 0:n.factBag)??{},null,2)})]})})]}):null}),n?C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12,padding:"6px 12px",borderTop:`1px solid ${s.sidebarBorder.replace("1px solid ","")}`,fontSize:12,flexShrink:0},children:[C.jsxs("span",{style:{color:"var(--mu-color-success-text)",fontWeight:600},children:[m," passed"]}),C.jsxs("span",{style:{color:"var(--mu-color-error)",fontWeight:600},children:[v," failed"]}),C.jsxs("span",{style:{color:s.textMuted,marginLeft:"auto"},children:["Total: ",n.executionTimeMs,"ms"]})]}):null]})}const qC={padding:"6px 12px",textAlign:"left",fontSize:11,fontWeight:600,textTransform:"uppercase",letterSpacing:"0.5px"};function L9({nodeName:n,isSuccess:e,evaluationResult:t,outputs:r,errors:i,position:s,tokens:l}){const c=e?"var(--mu-color-success)":"var(--mu-color-error)",h=e?"var(--mu-color-success-bg)":"var(--mu-color-error-bg)",m=e?"Pass":"Fail",v=r!=null&&Object.keys(r).length>0,y=i!=null&&i.length>0;return C.jsxs("div",{style:{position:"fixed",left:s.x+12,top:s.y-8,background:l.inspectorBg,border:`1px solid ${l.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:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:6},children:[C.jsx("span",{style:{fontWeight:600,color:l.textPrimary},children:n}),C.jsx("span",{style:{display:"inline-block",padding:"2px 8px",borderRadius:12,background:h,color:c,fontWeight:600,fontSize:11},children:m})]}),t!==void 0?C.jsxs("div",{style:{color:l.textSecondary,marginBottom:4},children:["Evaluation: ",String(t)]}):null,v?C.jsxs("div",{style:{marginBottom:4},children:[C.jsx("div",{style:{color:l.textSecondary,marginBottom:2},children:"Outputs:"}),C.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:l.textPrimary},children:JSON.stringify(r,null,2)})]}):null,y?C.jsxs("div",{children:[C.jsx("div",{style:{color:"var(--mu-color-error)",marginBottom:2},children:"Errors:"}),i.map((x,S)=>C.jsx("div",{style:{color:"var(--mu-color-error)",fontSize:11},children:x},S))]}):null]})}const Mp={trigger:"Trigger",condition:"Condition",action:"Action","decision-table":"Decision Table","sub-flow":"Sub Flow",liquid:"Liquid",connector:"Connector",end:"End"},Iv={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)"},X5={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"},z9={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 Ai(n){var t,r,i,s,l,c;if(!n||typeof n!="object")return Kw();const e=n;return{nodes:Array.isArray(e.nodes)?e.nodes.map((h,m)=>I9(h,m)):[],edges:Array.isArray(e.edges)?e.edges.filter(h=>!!h&&typeof h.source=="string"&&typeof h.target=="string").map((h,m)=>({id:typeof h.id=="string"&&h.id?h.id:`edge-${m+1}`,source:h.source,target:h.target,label:typeof h.label=="string"?h.label:void 0,edgeType:Vx(h.edgeType)})):[],metadata:{version:Math.max(1,((t=e.metadata)==null?void 0:t.version)??1),tenantId:(r=e.metadata)==null?void 0:r.tenantId,ruleSetCode:(i=e.metadata)==null?void 0:i.ruleSetCode,workflowName:(s=e.metadata)==null?void 0:s.workflowName,lastModifiedAt:(l=e.metadata)==null?void 0:l.lastModifiedAt,lastModifiedBy:(c=e.metadata)==null?void 0:c.lastModifiedBy}}}function N9(n){return JSON.stringify(Ai(n),null,2)}function j9(n){let e;try{e=JSON.parse(n)}catch(l){throw new Error(`Invalid rule flow JSON: ${l.message}`)}if(e&&typeof e=="object"){const l=e;if(l.ruleSetJson&&typeof l.ruleSetJson=="string")try{e=JSON.parse(l.ruleSetJson)}catch{}const c=e;c.ruleSet&&typeof c.ruleSet=="object"&&(e=c.ruleSet);const h=e;h.flowGraph&&typeof h.flowGraph=="object"&&(e=h.flowGraph)}const t=Ai(e),r=t.nodes.filter(l=>l.type==="trigger").length,i=t.nodes.filter(l=>l.type==="end").length;if(r!==1)throw new Error("Imported flow must contain exactly one trigger node.");if(i<1)throw new Error("Imported flow must contain at least one end node.");const s=new Set(t.nodes.map(l=>l.id));if(s.size!==t.nodes.length)throw new Error("Imported flow contains duplicate node ids.");for(const l of t.edges)if(!s.has(l.source)||!s.has(l.target))throw new Error(`Imported flow edge '${l.id}' references missing nodes.`);return t}function Yi(n){const e=Ai(n);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:GC(t.data)})).sort((t,r)=>(t.id??"").localeCompare(r.id??"")),edges:e.edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??"",edgeType:t.edgeType})).sort((t,r)=>(t.id??"").localeCompare(r.id??"")),metadata:{version:e.metadata.version,tenantId:e.metadata.tenantId??"",ruleSetCode:e.metadata.ruleSetCode??"",workflowName:e.metadata.workflowName??""}})}function I9(n,e){const t=tT(n.type),r=GC(n.data),i=KC(r.expression,n.feelExpression,t),s=n.position??{x:Number.NaN,y:Number.NaN};return{id:typeof n.id=="string"&&n.id?n.id:`node-${e+1}`,type:t,label:typeof n.label=="string"&&n.label?n.label:X5[t],feelExpression:i.language==="feel"?i.body:void 0,ruleCode:typeof n.ruleCode=="string"?n.ruleCode:void 0,expressionLanguage:n.expressionLanguage==="feel"||n.expressionLanguage==="javascript"?n.expressionLanguage:void 0,position:{x:Number.isFinite(s==null?void 0:s.x)?s.x:40+e*48,y:Number.isFinite(s==null?void 0:s.y)?s.y:60+e%4*88},data:{...r,expression:i}}}function GC(n){var s;const e=n&&typeof n=="object"?n:{},t=Array.isArray(e.outputFields)?e.outputFields.map($p).filter(Boolean):[],r=B9(e.contractOverride),i=(s=r==null?void 0:r.responseFields)!=null&&s.length?r.responseFields:t.length?t:void 0;return{...e,description:typeof e.description=="string"?e.description:void 0,expression:KC(e.expression,typeof e.feelExpression=="string"?e.feelExpression:void 0),contractRef:Z9(e.contractRef),requestContract:Bv(e.requestContract),responseContract:Bv(e.responseContract),contractOverride:r||i?{...r,responseFields:i}:void 0,inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(Zx).filter(Boolean):void 0,contractLayer:q9(e.contractLayer),dependsOn:Array.isArray(e.dependsOn)?e.dependsOn.filter(l=>typeof l=="string"&&l.trim().length>0).map(l=>l.trim()):void 0,order:typeof e.order=="number"&&Number.isFinite(e.order)?e.order:void 0,conditionConfig:U9(e.conditionConfig),subFlowConfig:V9(e.subFlowConfig),liquidConfig:X9(e.liquidConfig),connectorConfig:(()=>{const l=F9(e.connectorConfig);return l&&!l.connectorType&&typeof e.connectorType=="string"&&(l.connectorType=e.connectorType),l})()}}function B9(n){if(!n||typeof n!="object")return;const e=n;return{requestFields:Array.isArray(e.requestFields)?e.requestFields.map($p).filter(Boolean):void 0,responseFields:Array.isArray(e.responseFields)?e.responseFields.map($p).filter(Boolean):void 0}}function Z9(n){if(!n||typeof n!="object")return;const e=n,t=e.sourceType,r=e.sourceCode;if(!(typeof t!="string"||typeof r!="string"||!r.trim()))return{sourceType:tq(t),sourceCode:r.trim(),label:typeof e.label=="string"?e.label:void 0}}function Bv(n){if(!n||typeof n!="object")return;const e=n,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($p).filter(Boolean):[]}}function $p(n){if(!n||typeof n!="object")return null;const e=n,t=typeof e.path=="string"&&e.path.trim()?e.path.trim():"",r=typeof e.label=="string"&&e.label.trim()?e.label.trim():t,i=typeof e.dataType=="string"&&e.dataType.trim()?e.dataType.trim():"unknown";return t?{path:t,label:r,dataType:i,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"&&eT(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($p).filter(Boolean):void 0}:null}function KC(n,e,t="action"){if(n&&typeof n=="object"){const r=n;if(typeof r.language=="string"&&typeof r.body=="string")return{language:q5(r.language),body:r.body}}return typeof e=="string"&&e.trim()?{language:"feel",body:e}:JC(t)}function U9(n){if(!n||typeof n!="object")return;const e=n;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 V9(n){if(!n||typeof n!="object")return;const e=n;return{targetFlowCode:typeof e.targetFlowCode=="string"?e.targetFlowCode:void 0,childTriggerSchema:Bv(e.childTriggerSchema),inputMappings:Array.isArray(e.inputMappings)?e.inputMappings.map(Zx).filter(Boolean):[],outputMappings:Array.isArray(e.outputMappings)?e.outputMappings.map(Zx).filter(Boolean):[]}}function F9(n){if(!n||typeof n!="object")return;const e=n,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(i=>["url","method","body","operation","webhookUrl","to","key","headers"].includes(i))?(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 X9(n){if(!n||typeof n!="object")return;const e=n;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 Zx(n){if(!n||typeof n!="object")return null;const e=n;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"?q5(e.language):void 0}}function W9(n){const e=Zx(n);if(!e||!n||typeof n!="object")return e;const t=n;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 H9(n){if(!n||typeof n!="object")return null;const e=n,t=typeof e.code=="string"&&e.code.trim()?e.code.trim():"",r=typeof e.message=="string"&&e.message.trim()?e.message.trim():"";return!t||!r?null:{code:t,message:r,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 Y9(n){if(!n||typeof n!="object")return;const e=n,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($p).filter(Boolean):[],mappings:Array.isArray(e.mappings)?e.mappings.map(W9).filter(Boolean):[]}}function q9(n){if(!n||typeof n!="object")return;const e=n;return{upstreamScope:Bv(e.upstreamScope),effectiveInput:Y9(e.effectiveInput),outputContract:Bv(e.outputContract),validationIssues:Array.isArray(e.validationIssues)?e.validationIssues.map(H9).filter(Boolean):void 0}}function iu(n){const e=typeof n.feelExpression=="string"?n.feelExpression:void 0;return KC(n.expression,e,n.nodeType??"action")}function fl(n){return n??{targetFlowCode:"",childTriggerSchema:void 0,inputMappings:[],outputMappings:[]}}function W5(n){return n??{outputFormat:"json"}}function qi(n,e=[]){var t;for(const r of n)e.push(r),(t=r.children)!=null&&t.length&&qi(r.children,e);return e}function H5(n,e,t){const r=e.trim();return r?{sourceType:(t==null?void 0:t.sourceType)??Ux(n),sourceCode:r,label:t==null?void 0:t.label}:t}const G9=new Set(["condition","action","decision-table","sub-flow","liquid","connector"]);function Y5(n){return n==="trigger"?"input-data":G9.has(n)?"data-mapping":"basic-info"}function Ux(n){return n==="sub-flow"?"flow":n==="decision-table"?"decision-table":n==="liquid"||n==="connector"?"api":"rule"}function K9(n){const e=["basic-info","input-data","data-mapping","output-data"];return n!=="trigger"&&n!=="end"&&e.push("logic"),e}function J9(n){return n==="basic-info"?"Basic Info":n==="input-data"?"Input Data":n==="data-mapping"?"Data Flow":n==="output-data"?"Output Data":"Logic"}function JC(n){return{language:n==="liquid"?"liquid":"feel",body:""}}const eq=new Set(Object.keys(Mp));function eT(n){return eq.has(n)}function tT(n){return typeof n=="string"&&eT(n)?n:"action"}function Vx(n){return n==="always"||n==="on-true"||n==="on-false"||n==="on-error"?n:"always"}function q5(n){if(typeof n!="string")return"feel";const e=n.trim().toLowerCase();return e==="feel"||e==="liquid"||e==="plain-text"||e==="javascript"||e==="scriban"?e:"feel"}function tq(n){return n==="rule"||n==="flow"||n==="decision-table"||n==="api"||n==="inline"?n:"rule"}function Zv(n){return Ai(n).nodes.map(t=>({id:t.id,type:t.type,position:t.position,data:{label:t.label,ruleCode:t.ruleCode,nodeType:tT(t.type),...t.data}}))}function G5(n){return Ai(n).edges.map(t=>({id:t.id,source:t.source,target:t.target,label:t.label??t.edgeType,data:{edgeType:t.edgeType}}))}function nq(n,e){switch(e.type){case"commit":{const t=Ai(e.graph);return Yi(t)===Yi(n.present)?n:{past:[...n.past,n.present].slice(-50),present:t,future:[]}}case"undo":{if(n.past.length===0)return n;const t=n.past[n.past.length-1];return{past:n.past.slice(0,-1),present:t,future:[n.present,...n.future]}}case"redo":{if(n.future.length===0)return n;const[t,...r]=n.future;return{past:[...n.past,n.present].slice(-50),present:t,future:r}}case"reset":return{past:[],present:Ai(e.graph),future:[]};default:return n}}function rq(n){const e=q.useMemo(()=>Ai(n),[n]),[t,r]=q.useReducer(nq,{past:[],present:e,future:[]}),i=q.useCallback(h=>{r({type:"commit",graph:h})},[]),s=q.useCallback(()=>{r({type:"undo"})},[]),l=q.useCallback(()=>{r({type:"redo"})},[]),c=q.useCallback(h=>{r({type:"reset",graph:h})},[]);return q.useMemo(()=>({present:t.present,canUndo:t.past.length>0,canRedo:t.future.length>0,commit:i,undo:s,redo:l,reset:c}),[i,l,c,t.future.length,t.past.length,t.present,s])}const iq=yt.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"}}),oq=_x.define([{tag:Ce.keyword,color:"var(--mu-node-condition)"},{tag:Ce.string,color:"var(--mu-color-success-text)"},{tag:Ce.number,color:"var(--mu-color-warning-text)"},{tag:Ce.bool,color:"var(--mu-node-condition)"},{tag:Ce.null,color:"var(--mu-text-muted)"},{tag:Ce.operator,color:"var(--mu-color-interactive)"},{tag:Ce.comment,color:"var(--mu-text-muted)",fontStyle:"italic"},{tag:Ce.function(Ce.variableName),color:"var(--mu-color-interactive)"},{tag:Ce.variableName,color:"var(--mu-text-primary)"},{tag:Ce.propertyName,color:"var(--mu-color-interactive-subtle)"},{tag:Ce.bracket,color:"var(--mu-text-secondary)"},{tag:Ce.special(Ce.variableName),color:"var(--mu-color-interactive)",fontWeight:"600"}]);YW(oq);const nT=[{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"}],aq=new Set(["true","false","null","if","then","else","for","in","return","some","every","satisfies","not","and","or","between","instance","of","function"]),sq=new Set(nT.map(n=>n.name)),K5=(()=>{const n=["Math","Logic","Collection","Type","String","Date"],e=new Map;for(const t of n)e.set(t,[]);for(const t of nT)e.get(t.group).push(t);return n.map(t=>({group:t,functions:e.get(t)}))})(),lq=()=>C.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:C.jsx("path",{d:"M6 3l5 5-5 5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),uq=()=>C.jsx("svg",{viewBox:"0 0 16 16",width:"12",height:"12",style:{flexShrink:0},children:C.jsx("path",{d:"M3 6l5 5 5-5",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),cq=K5.reduce((n,e)=>n+e.functions.length,0),fq={borderRadius:14,background:"rgba(241, 245, 249, 0.9)",border:"1px solid rgba(148, 163, 184, 0.18)",overflow:"hidden",marginTop:8},dq={padding:"10px 12px",cursor:"pointer",fontSize:12,fontWeight:600,color:"var(--mu-color-text-secondary)",display:"flex",alignItems:"center",gap:6,userSelect:"none"},hq={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"},pq={padding:"8px 12px 4px",fontSize:11,fontWeight:700,color:"var(--mu-color-text-muted)",textTransform:"uppercase",letterSpacing:"0.04em"},mq={padding:"6px 12px",cursor:"pointer",fontSize:12,borderRadius:8,display:"flex",alignItems:"baseline",gap:6},gq={fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",color:"var(--mu-color-interactive)",fontWeight:600},vq={color:"var(--mu-color-text-muted)",marginLeft:6,fontSize:11},yq={maxHeight:280,overflowY:"auto",paddingBottom:6};function Oq({onInsert:n,visible:e}){const[t,r]=q.useState(!1),[i,s]=q.useState(null),l=q.useCallback(()=>{r(c=>!c)},[]);return e?C.jsxs("div",{style:fq,children:[C.jsxs("div",{style:dq,onClick:l,role:"button",tabIndex:0,"aria-expanded":t,children:[t?C.jsx(uq,{}):C.jsx(lq,{}),C.jsx("span",{children:"FEEL Functions"}),C.jsx("span",{style:hq,children:cq})]}),t&&C.jsx("div",{style:yq,children:K5.map(c=>C.jsxs("div",{children:[C.jsx("div",{style:pq,children:c.group}),c.functions.map(h=>{const m=`${c.group}:${h.name}`,v=i===m;return C.jsxs("div",{style:{...mq,background:v?"color-mix(in oklch, var(--mu-color-interactive) 6%, transparent)":"transparent"},onClick:()=>n(h.template),onMouseEnter:()=>s(m),onMouseLeave:()=>s(null),title:h.description,role:"button",tabIndex:0,children:[C.jsx("span",{style:gq,children:h.name}),C.jsx("span",{style:vq,children:h.signature})]},m)})]},c.group))})]}):null}function J5(n){return yY({override:[t=>{const r=qi(n),s=t.state.sliceDoc(0,t.pos).match(/([a-zA-Z_][\w.]*)\.$/);if(s){const v=s[1],y=[];for(const x of r)x.path.startsWith(v+".")&&!x.path.substring(v.length+1).includes(".")&&y.push({label:x.path,type:"variable",detail:x.dataType,info:x.sourceNodeLabel?`From: ${x.sourceNodeLabel}`:void 0,boost:2});if(y.length>0)return{from:t.pos-v.length-1,options:y,validFor:/^[\w.]*$/}}const l=t.matchBefore(/[a-zA-Z_][\w.]*/);if(!l&&!t.explicit)return null;const c=l?l.from:t.pos,h=r.map(v=>({label:v.path,type:"variable",detail:v.dataType,info:v.sourceNodeLabel?`From: ${v.sourceNodeLabel}`:void 0,boost:1})),m=nT.map(v=>({label:v.name,type:"function",detail:v.signature,info:v.description,apply:v.template,boost:0}));return{from:c,options:[...h,...m],validFor:/^[\w.]*$/}}],activateOnTyping:!0})}class eL{constructor(e,t,r){this.from=e,this.to=t,this.diagnostic=r}}class Ad{constructor(e,t,r){this.diagnostics=e,this.panel=t,this.selected=r}static init(e,t,r){let i=r.facet(ou).markerFilter;i&&(e=i(e,r));let s=e.slice().sort((S,E)=>S.from-E.from||S.to-E.to),l=new dp,c=[],h=0,m=r.doc.iter(),v=0,y=r.doc.length;for(let S=0;;){let E=S==s.length?null:s[S];if(!E&&!c.length)break;let k,R;if(c.length)k=h,R=c.reduce((A,L)=>Math.min(A,L.to),E&&E.from>k?E.from:1e8);else{if(k=E.from,k>y)break;R=E.to,c.push(E),S++}for(;S<s.length;){let A=s[S];if(A.from==k&&(A.to>A.from||A.to==k))c.push(A),S++,R=Math.min(A.to,R);else{R=Math.min(A.from,R);break}}R=Math.min(R,y);let P=!1;if(c.some(A=>A.from==k&&(A.to==R||R==y))&&(P=k==R,!P&&R-k<10)){let A=k-(v+m.value.length);A>0&&(m.next(A),v=k);for(let L=k;;){if(L>=R){P=!0;break}if(!m.lineBreak&&v+m.value.length>L)break;L=v+m.value.length,v+=m.value.length,m.next()}}let Q=cL(c);if(P)l.add(k,k,pn.widget({widget:new Eq(Q),diagnostics:c.slice()}));else{let A=c.reduce((L,B)=>B.markClass?L+" "+B.markClass:L,"");l.add(k,R,pn.mark({class:"cm-lintRange cm-lintRange-"+Q+A,diagnostics:c.slice(),inclusiveEnd:c.some(L=>L.to>R)}))}if(h=R,h==y)break;for(let A=0;A<c.length;A++)c[A].to<=h&&c.splice(A--,1)}let x=l.finish();return new Ad(x,t,Ap(x))}}function Ap(n,e=null,t=0){let r=null;return n.between(t,1e9,(i,s,{spec:l})=>{if(!(e&&l.diagnostics.indexOf(e)<0))if(!r)r=new eL(i,s,e||l.diagnostics[0]);else{if(l.diagnostics.indexOf(r.diagnostic)<0)return!1;r=new eL(r.from,s,r.diagnostic)}}),r}function tL(n,e){let t=e.pos,r=e.end||t,i=n.state.facet(ou).hideOn(n,t,r);if(i!=null)return i;let s=n.startState.doc.lineAt(e.pos);return!!(n.effects.some(l=>l.is(Fx))||n.changes.touchesRange(s.from,Math.max(s.to,r)))}function xq(n,e){return n.field(dl,!1)?e:e.concat(bn.appendConfig.of(hL))}function bq(n,e){return{effects:xq(n,[Fx.of(e)])}}const Fx=bn.define(),nL=bn.define(),rL=bn.define(),dl=Vo.define({create(){return new Ad(pn.none,null,null)},update(n,e){if(e.docChanged&&n.diagnostics.size){let t=n.diagnostics.map(e.changes),r=null,i=n.panel;if(n.selected){let s=e.changes.mapPos(n.selected.from,1);r=Ap(t,n.selected.diagnostic,s)||Ap(t,null,s)}!t.size&&i&&e.state.facet(ou).autoPanel&&(i=null),n=new Ad(t,i,r)}for(let t of e.effects)if(t.is(Fx)){let r=e.state.facet(ou).autoPanel?t.value.length?Xx.open:null:n.panel;n=Ad.init(t.value,r,e.state)}else t.is(nL)?n=new Ad(n.diagnostics,t.value?Xx.open:null,n.selected):t.is(rL)&&(n=new Ad(n.diagnostics,n.panel,t.value));return n},provide:n=>[Gk.from(n,e=>e.panel),yt.decorations.from(n,e=>e.diagnostics)]}),wq=pn.mark({class:"cm-lintRange cm-lintRange-active"});function Sq(n,e,t){let{diagnostics:r}=n.state.field(dl),i,s=-1,l=-1;r.between(e-(t<0?1:0),e+(t>0?1:0),(h,m,{spec:v})=>{if(e>=h&&e<=m&&(h==m||(e>h||t>0)&&(e<m||t<0)))return i=v.diagnostics,s=h,l=m,!1});let c=n.state.facet(ou).tooltipFilter;return i&&c&&(i=c(i,n.state)),i?{pos:s,end:l,above:n.state.doc.lineAt(s).to<l,create(){return{dom:iL(n,i)}}}:null}function iL(n,e){return Hl("ul",{class:"cm-tooltip-lint"},e.map(t=>lL(n,t,!1)))}const oL=n=>{let e=n.state.field(dl,!1);return!e||!e.panel?!1:(n.dispatch({effects:nL.of(!1)}),!0)},kq=Mi.fromClass(class{constructor(n){this.view=n,this.timeout=-1,this.set=!0;let{delay:e}=n.state.facet(ou);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let n=Date.now();if(n<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-n);else{this.set=!1;let{state:e}=this.view,{sources:t}=e.facet(ou);t.length&&Cq(t.map(r=>Promise.resolve(r(this.view))),r=>{this.view.state.doc==e.doc&&this.view.dispatch(bq(this.view.state,r.reduce((i,s)=>i.concat(s))))},r=>{Xo(this.view.state,r)})}}update(n){let e=n.state.facet(ou);(n.docChanged||e!=n.startState.facet(ou)||e.needsRefresh&&e.needsRefresh(n))&&(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 Cq(n,e,t){let r=[],i=-1;for(let s of n)s.then(l=>{r.push(l),clearTimeout(i),r.length==n.length?e(r):i=setTimeout(()=>e(r),200)},t)}const ou=pt.define({combine(n){return{sources:n.map(e=>e.source).filter(e=>e!=null),...yd(n.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:aL,tooltipFilter:aL,needsRefresh:(e,t)=>e?t?r=>e(r)||t(r):e:t,hideOn:(e,t)=>e?t?(r,i,s)=>e(r,i,s)||t(r,i,s):e:t,autoPanel:(e,t)=>e||t})}}});function aL(n,e){return n?e?(t,r)=>e(n(t,r),r):n:e}function Tq(n,e={}){return[ou.of({source:n,config:e}),kq,hL]}function sL(n){let e=[];if(n)e:for(let{name:t}of n){for(let r=0;r<t.length;r++){let i=t[r];if(/[a-zA-Z]/.test(i)&&!e.some(s=>s.toLowerCase()==i.toLowerCase())){e.push(i);continue e}}e.push("")}return e}function lL(n,e,t){var r;let i=t?sL(e.actions):[];return Hl("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},Hl("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(n):e.message),(r=e.actions)===null||r===void 0?void 0:r.map((s,l)=>{let c=!1,h=S=>{if(S.preventDefault(),c)return;c=!0;let E=Ap(n.state.field(dl).diagnostics,e);E&&s.apply(n,E.from,E.to)},{name:m}=s,v=i[l]?m.indexOf(i[l]):-1,y=v<0?m:[m.slice(0,v),Hl("u",m.slice(v,v+1)),m.slice(v+1)],x=s.markClass?" "+s.markClass:"";return Hl("button",{type:"button",class:"cm-diagnosticAction"+x,onclick:h,onmousedown:h,"aria-label":` Action: ${m}${v<0?"":` (access key "${i[l]})"`}.`},y)}),e.source&&Hl("div",{class:"cm-diagnosticSource"},e.source))}class Eq extends Od{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return Hl("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class uL{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=lL(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class Xx{constructor(e){this.view=e,this.items=[];let t=i=>{if(!(i.ctrlKey||i.altKey||i.metaKey)){if(i.keyCode==27)oL(this.view),this.view.focus();else if(i.keyCode==38||i.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(i.keyCode==40||i.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(i.keyCode==36)this.moveSelection(0);else if(i.keyCode==35)this.moveSelection(this.items.length-1);else if(i.keyCode==13)this.view.focus();else if(i.keyCode>=65&&i.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:s}=this.items[this.selectedIndex],l=sL(s.actions);for(let c=0;c<l.length;c++)if(l[c].toUpperCase().charCodeAt(0)==i.keyCode){let h=Ap(this.view.state.field(dl).diagnostics,s);h&&s.actions[c].apply(e,h.from,h.to)}}else return;i.preventDefault()}},r=i=>{for(let s=0;s<this.items.length;s++)this.items[s].dom.contains(i.target)&&this.moveSelection(s)};this.list=Hl("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:r}),this.dom=Hl("div",{class:"cm-panel-lint"},this.list,Hl("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>oL(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(dl).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(dl),r=0,i=!1,s=null,l=new Set;for(e.between(0,this.view.state.doc.length,(c,h,{spec:m})=>{for(let v of m.diagnostics){if(l.has(v))continue;l.add(v);let y=-1,x;for(let S=r;S<this.items.length;S++)if(this.items[S].diagnostic==v){y=S;break}y<0?(x=new uL(this.view,v),this.items.splice(r,0,x),i=!0):(x=this.items[y],y>r&&(this.items.splice(r,y-r),i=!0)),t&&x.diagnostic==t.diagnostic?x.dom.hasAttribute("aria-selected")||(x.dom.setAttribute("aria-selected","true"),s=x):x.dom.hasAttribute("aria-selected")&&x.dom.removeAttribute("aria-selected"),r++}});r<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)i=!0,this.items.pop();this.items.length==0&&(this.items.push(new uL(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),i=!0),s?(this.list.setAttribute("aria-activedescendant",s.id),this.view.requestMeasure({key:this,read:()=>({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:c,panel:h})=>{let m=h.height/this.list.offsetHeight;c.top<h.top?this.list.scrollTop-=(h.top-c.top)/m:c.bottom>h.bottom&&(this.list.scrollTop+=(c.bottom-h.bottom)/m)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),i&&this.sync()}sync(){let e=this.list.firstChild;function t(){let r=e;e=r.nextSibling,r.remove()}for(let r of this.items)if(r.dom.parentNode==this.list){for(;e!=r.dom;)t();e=r.dom.nextSibling}else this.list.insertBefore(r.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(dl),r=Ap(t.diagnostics,this.items[e].diagnostic);r&&this.view.dispatch({selection:{anchor:r.from,head:r.to},scrollIntoView:!0,effects:rL.of(r)})}static open(e){return new Xx(e)}}function Wx(n,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(n)}</svg>')`}function Hx(n){return Wx(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${n}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const _q=yt.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:Hx("#d11")},".cm-lintRange-warning":{backgroundImage:Hx("orange")},".cm-lintRange-info":{backgroundImage:Hx("#999")},".cm-lintRange-hint":{backgroundImage:Hx("#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 Rq(n){return n=="error"?4:n=="warning"?3:n=="info"?2:1}function cL(n){let e="hint",t=1;for(let r of n){let i=Rq(r.severity);i>t&&(t=i,e=r.severity)}return e}class fL extends rf{constructor(e){super(),this.diagnostics=e,this.severity=cL(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let r=this.diagnostics,i=e.state.facet(Yx).tooltipFilter;return i&&(r=i(r,e.state)),r.length&&(t.onmouseover=()=>Mq(e,t,r)),t}}function Pq(n,e){let t=r=>{let i=e.getBoundingClientRect();if(!(r.clientX>i.left-10&&r.clientX<i.right+10&&r.clientY>i.top-10&&r.clientY<i.bottom+10)){for(let s=r.target;s;s=s.parentNode)if(s.nodeType==1&&s.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",t),n.state.field(dL)&&n.dispatch({effects:iT.of(null)})}};window.addEventListener("mousemove",t)}function Mq(n,e,t){function r(){let l=n.elementAtHeight(e.getBoundingClientRect().top+5-n.documentTop);n.coordsAtPos(l.from)&&n.dispatch({effects:iT.of({pos:l.from,above:!1,clip:!1,create(){return{dom:iL(n,t),getCoords:()=>e.getBoundingClientRect()}}})}),e.onmouseout=e.onmousemove=null,Pq(n,e)}let{hoverTime:i}=n.state.facet(Yx),s=setTimeout(r,i);e.onmouseout=()=>{clearTimeout(s),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(s),s=setTimeout(r,i)}}function $q(n,e){let t=Object.create(null);for(let i of e){let s=n.lineAt(i.from);(t[s.from]||(t[s.from]=[])).push(i)}let r=[];for(let i in t)r.push(new fL(t[i]).range(+i));return hn.of(r,!0)}const Aq=hW({class:"cm-gutter-lint",markers:n=>n.state.field(rT),widgetMarker:(n,e,t)=>{let r=[];return n.state.field(rT).between(t.from,t.to,(i,s,l)=>{i>t.from&&i<t.to&&r.push(...l.diagnostics)}),r.length?new fL(r):null}}),rT=Vo.define({create(){return hn.empty},update(n,e){n=n.map(e.changes);let t=e.state.facet(Yx).markerFilter;for(let r of e.effects)if(r.is(Fx)){let i=r.value;t&&(i=t(i||[],e.state)),n=$q(e.state.doc,i.slice(0))}return n}}),iT=bn.define(),dL=Vo.define({create(){return null},update(n,e){return n&&e.docChanged&&(n=tL(e,n)?null:{...n,pos:e.changes.mapPos(n.pos)}),e.effects.reduce((t,r)=>r.is(iT)?r.value:t,n)},provide:n=>dx.from(n)}),Qq=yt.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:Wx('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:Wx('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:Wx('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),hL=[dl,yt.decorations.compute([dl],n=>{let{selected:e,panel:t}=n.field(dl);return!e||!t||e.from==e.to?pn.none:pn.set([wq.range(e.from,e.to)])}),lW(Sq,{hideOn:tL}),_q],Yx=pt.define({combine(n){return yd(n,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function Dq(n={}){return[Yx.of(n),rT,Aq,Qq,dL]}function Lq(n){return[Tq(t=>{const r=t.state.doc.toString(),i=[];if(!r.trim())return i.push({from:0,to:r.length||0,severity:"info",message:"Expression is empty"}),i;const s=[["(",")"],["[","]"],["{","}"]];for(const[k,R]of s){const P=[];for(let Q=0;Q<r.length;Q++){if(r[Q]==='"'){for(Q++;Q<r.length&&r[Q]!=='"';)r[Q]==="\\"&&Q++,Q++;continue}r[Q]===k?P.push(Q):r[Q]===R&&(P.length>0?P.pop():i.push({from:Q,to:Q+1,severity:"error",message:`Unmatched closing '${R}'`}))}for(const Q of P)i.push({from:Q,to:Q+1,severity:"error",message:`Unmatched opening '${k}'`})}let l=!1,c=0;for(let k=0;k<r.length;k++)r[k]==='"'&&(k===0||r[k-1]!=="\\")&&(l?l=!1:(l=!0,c=k));l&&i.push({from:c,to:c+1,severity:"error",message:"Unclosed string literal"});const h=qi(n),m=new Set(h.map(k=>k.path)),v=/[a-zA-Z_][\w]*/g;let y;const x=[];let S=-1;for(let k=0;k<r.length;k++)r[k]==='"'&&(k===0||r[k-1]!=="\\")&&(S<0?S=k:(x.push([S,k]),S=-1));const E=k=>x.some(([R,P])=>k>=R&&k<=P);for(;(y=v.exec(r))!==null;){const k=y[0],R=y.index;if(E(R)||aq.has(k)||sq.has(k)||/^\d/.test(k))continue;let P=k,Q=R+k.length;for(;Q<r.length&&r[Q]===".";){const j=r.substring(Q+1).match(/^[a-zA-Z_][\w]*/);if(j)P+="."+j[0],Q=Q+1+j[0].length,v.lastIndex=Q;else break}if(m.has(P))continue;let A=!1;for(const B of m)if(B.startsWith(P+".")||P.startsWith(B+".")){A=!0;break}if(A)continue;let L=!1;for(const B of m)if(B===k||B.startsWith(k+".")){L=!0;break}L||i.push({from:R,to:R+P.length,severity:"warning",message:`Unknown field reference: ${P}`})}return i},{delay:300}),Dq()]}const zq={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)"}},Nq={bg:"var(--mu-surface-raised)",text:"var(--mu-text-secondary)"};function Uv({dataType:n}){const e=zq[n.toLowerCase()]??Nq;return C.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:n.toLowerCase()})}function Qp({icon:n,message:e,actionHint:t,onAction:r}){return C.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:[C.jsx("span",{style:{fontSize:16},children:n??"ⓘ"}),C.jsx("span",{style:{color:"var(--mu-text-muted)",fontSize:13},children:e}),t&&r?C.jsx("span",{role:"button",tabIndex:0,onClick:r,onKeyDown:i=>{i.key==="Enter"&&r()},style:{color:"var(--mu-color-interactive)",cursor:"pointer",textDecoration:"underline",fontSize:13},children:t}):null]})}const jq={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 pL({field:n,depth:e,readOnly:t,onInsert:r,defaultExpanded:i=!0}){var S;const s=(((S=n.children)==null?void 0:S.length)??0)>0,[l,c]=q.useState(i),[h,m]=q.useState(!1),v=n.path.split("."),y=v[v.length-1],x=v.length>1?v.slice(0,-1).join(".")+".":"";return C.jsxs("div",{children:[C.jsxs("div",{style:{...jq,paddingLeft:e*20+8,backgroundColor:h?"var(--mu-surface-raised)":"transparent"},onMouseEnter:()=>m(!0),onMouseLeave:()=>m(!1),children:[s?C.jsx("span",{role:"button",tabIndex:0,onClick:E=>{E.stopPropagation(),c(!l)},onKeyDown:E=>{E.key==="Enter"&&c(!l)},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:l?"▼":"▶"}):C.jsx("span",{style:{width:16,flexShrink:0}}),C.jsxs("button",{type:"button",disabled:t,onClick:()=>r(n.path),style:{border:"none",background:"transparent",padding:0,cursor:t?"default":"pointer",fontSize:12,color:"var(--mu-text-primary)",textAlign:"left",fontFamily:"inherit"},children:[x?C.jsx("span",{style:{color:"var(--mu-text-secondary)"},children:x}):null,C.jsx("strong",{children:y})]}),C.jsx(Uv,{dataType:n.dataType}),n.sourceNodeLabel?C.jsx("span",{style:{fontSize:11,color:"var(--mu-text-secondary)",marginLeft:"auto"},children:n.sourceNodeLabel}):null]}),s&&l?C.jsx("div",{children:n.children.map(E=>C.jsx(pL,{field:E,depth:e+1,readOnly:t,onInsert:r,defaultExpanded:i},E.path))}):null]})}const Iq={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 qx({tooltip:n}){return C.jsx("span",{title:n,style:{display:"inline-flex",alignItems:"center",marginLeft:4,cursor:"help",color:"var(--mu-text-secondary)"},children:C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:C.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 Bq={display:"flex",flexDirection:"column",gap:8,padding:"10px 14px",background:"var(--mu-surface-raised)",border:"1px solid var(--mu-border-subtle)",borderRadius:12};function Zq(n){var h,m,v,y,x,S,E,k;const{selectedNode:e,contractLoadState:t,readOnly:r,inspectorTab:i,setInspectorTab:s,showSectionHeader:l=!0}=n,c=e==null?void 0:e.data.contractLayer;return C.jsxs("div",{style:eG,children:[l?C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Inspector"}),C.jsx("span",{children:e?`Editing ${Mp[e.data.nodeType]}`:"Select a node to edit it."})]}):null,e?C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)",minHeight:0},children:[C.jsx("div",{role:"tablist","aria-label":"Node inspector sections",style:tG,children:K9(e.data.nodeType).map(R=>C.jsx("button",{role:"tab","aria-selected":R===i,type:"button",style:hG(R===i),onClick:()=>s(R),children:J9(R)},R))}),i==="basic-info"?C.jsx(Uq,{...n}):null,i==="input-data"?C.jsx(Hq,{title:"Input Scope",subtitle:((h=c==null?void 0:c.upstreamScope)==null?void 0:h.title)??"Everything available before this node executes.",contract:c==null?void 0:c.upstreamScope,loadState:t,readOnly:r,onInsert:n.onInsertExpressionToken,groupBySource:!0}):null,i==="data-mapping"?C.jsx(qq,{nodeType:e.data.nodeType,readOnly:r,upstreamFields:qi(((m=c==null?void 0:c.upstreamScope)==null?void 0:m.fields)??[]),targetFields:((v=c==null?void 0:c.effectiveInput)==null?void 0:v.fields)??[],rows:((y=c==null?void 0:c.effectiveInput)==null?void 0:y.mappings)??[],onInsert:n.onInsertExpressionToken,onChangeTargetFields:n.onChangeInputContract,onChange:n.onChangeEffectiveMappings,setInspectorTab:s,hasExpression:!!((S=(x=n.selectedExpression)==null?void 0:x.body)!=null&&S.trim())}):null,i==="output-data"?C.jsx(Gq,{nodeType:e.data.nodeType,contract:c==null?void 0:c.outputContract,upstreamScope:c==null?void 0:c.upstreamScope,issues:(c==null?void 0:c.validationIssues)??[],readOnly:r,onInsert:n.onInsertExpressionToken,onChange:n.onChangeOutputContract}):null,i==="logic"?C.jsx(Vq,{nodeType:e.data.nodeType,expression:n.selectedExpression,upstreamScope:c==null?void 0:c.upstreamScope,outputContract:c==null?void 0:c.outputContract,liquidOutput:(E=e.data.liquidConfig)==null?void 0:E.outputFormat,readOnly:r,apiBaseUrl:n.apiBaseUrl,onChangeLanguage:n.onUpdateExpressionLanguage,onChangeBody:n.onUpdateExpressionBody,onInsertRef:n.onSetInsertRef,shadowRoot:n.shadowRoot}):null,(k=c==null?void 0:c.validationIssues)!=null&&k.length?C.jsx(vL,{issues:c.validationIssues}):null,t.status==="error"?C.jsx("div",{style:sG,children:t.message}):null,r?null:C.jsx("button",{type:"button",style:aG,onClick:n.onDeleteNode,children:"Delete Node"})]}):C.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 Uq(n){var h,m,v,y,x,S,E;const{selectedNode:e,readOnly:t,flowOptions:r,decisionTableOptions:i,selectedDecisionTable:s,decisionTableLoadState:l}=n;if(!e)return C.jsx(C.Fragment,{});const c=e.data.dependsOn??[];return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("label",{style:wo,children:["Label",C.jsx("input",{style:Qi,value:e.data.label,disabled:t,onChange:k=>n.onUpdateLabel(k.target.value)})]}),C.jsxs("label",{style:wo,children:["Rule Code",C.jsx("input",{style:Qi,value:e.data.ruleCode??"",disabled:t,onChange:k=>n.onUpdateRuleCode(k.target.value)})]}),C.jsxs("label",{style:wo,children:["Description",C.jsx("textarea",{style:oT,value:String(e.data.description??""),disabled:t,placeholder:"Describe what this node does for documentation purposes",onChange:k=>n.onUpdateDescription(k.target.value)})]}),C.jsxs("div",{style:nG,children:[C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Contract Source",C.jsx(qx,{tooltip:"Determines where this node's input/output schema comes from"})]}),C.jsxs("select",{style:Qi,value:((h=e.data.contractRef)==null?void 0:h.sourceType)??Ux(e.data.nodeType),disabled:t,onChange:k=>{var R,P;return n.onUpdateContractRef({sourceType:k.target.value,sourceCode:((R=e.data.contractRef)==null?void 0:R.sourceCode)??e.data.ruleCode??"",label:(P=e.data.contractRef)==null?void 0:P.label})},children:[C.jsx("option",{value:"rule",children:"rule"}),C.jsx("option",{value:"flow",children:"flow"}),C.jsx("option",{value:"decision-table",children:"decision-table"}),C.jsx("option",{value:"api",children:"api"}),C.jsx("option",{value:"inline",children:"inline"})]}),C.jsx("span",{style:{fontSize:11,color:"var(--mu-text-muted)",fontStyle:"italic",marginTop:2,lineHeight:1.4},children:Iq[((m=e.data.contractRef)==null?void 0:m.sourceType)??Ux(e.data.nodeType)]??""})]}),C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Contract Code",C.jsx(qx,{tooltip:"The unique identifier used to look up the contract"})]}),C.jsx("input",{style:Qi,value:((v=e.data.contractRef)==null?void 0:v.sourceCode)??"",disabled:t,onChange:k=>{var R,P;return n.onUpdateContractRef({sourceType:((R=e.data.contractRef)==null?void 0:R.sourceType)??Ux(e.data.nodeType),sourceCode:k.target.value,label:(P=e.data.contractRef)==null?void 0:P.label})}})]})]}),C.jsxs("div",{style:Bq,children:[C.jsxs("div",{style:{display:"flex",alignItems:"center"},children:[C.jsx("span",{style:{marginRight:4},children:"📋"}),C.jsx("strong",{children:"Order:"})," ",e.data.order??"n/a"]}),C.jsxs("div",{style:{display:"flex",gap:6,flexWrap:"wrap",alignItems:"center"},children:[C.jsx("span",{style:{marginRight:4},children:"🔗"}),C.jsx("strong",{children:"Depends On:"}),c.length===0?C.jsx("span",{children:"none"}):c.map(k=>C.jsx("button",{type:"button","data-testid":`depends-chip-${k}`,style:cG,onClick:()=>n.onSelectNodeByRuleCode(k),children:k},k))]})]}),e.data.nodeType==="condition"?C.jsx(Fq,{readOnly:t,value:e.data.conditionConfig,onChange:n.onUpdateConditionConfig}):null,e.data.nodeType==="decision-table"?C.jsxs(C.Fragment,{children:[C.jsxs("label",{style:wo,children:["Decision Table",C.jsxs("select",{style:Qi,value:((y=e.data.contractRef)==null?void 0:y.sourceCode)??"",disabled:t,onChange:k=>n.onUpdateDecisionTableCode(k.target.value),children:[C.jsx("option",{value:"",children:"Select decision table"}),i.map(k=>C.jsx("option",{value:k.code,children:k.label},k.code))]})]}),C.jsx(Wq,{table:s,loadState:l})]}):null,e.data.nodeType==="sub-flow"?C.jsxs("label",{style:wo,children:["Target Flow Code",C.jsxs("select",{style:Qi,value:fl(e.data.subFlowConfig).targetFlowCode??"",disabled:t,onChange:k=>n.onUpdateTargetFlowCode(k.target.value),children:[C.jsx("option",{value:"",children:"Select target flow"}),r.map(k=>C.jsx("option",{value:k.code,children:k.label},k.code))]})]}):null,e.data.nodeType==="liquid"?C.jsxs("label",{style:wo,children:["Liquid Output",C.jsxs("select",{style:Qi,value:W5(e.data.liquidConfig).outputFormat??"json",disabled:t,onChange:k=>n.onUpdateLiquidOutput(k.target.value),children:[C.jsx("option",{value:"json",children:"json"}),C.jsx("option",{value:"object",children:"object"}),C.jsx("option",{value:"text",children:"text"})]})]}):null,e.data.nodeType==="connector"?C.jsx(Xq,{config:{connectorType:((x=e.data.connectorConfig)==null?void 0:x.connectorType)??"",connectorConfig:((S=e.data.connectorConfig)==null?void 0:S.connectorConfig)??(e.data.connectorConfig&&("url"in e.data.connectorConfig||"method"in e.data.connectorConfig)?e.data.connectorConfig:{}),credentialId:(E=e.data.connectorConfig)==null?void 0:E.credentialId},catalog:n.connectorCatalog??[],readOnly:t,onChange:n.onUpdateConnectorConfig}):null]})}function Vq({nodeType:n,expression:e,upstreamScope:t,outputContract:r,liquidOutput:i,readOnly:s,apiBaseUrl:l,onChangeLanguage:c,onChangeBody:h,onInsertRef:m,shadowRoot:v}){const y=q.useRef(null),x=n==="liquid"||e.language==="liquid"?dG(e.body,(t==null?void 0:t.fields)??[],i??"json"):"",E=qi((r==null?void 0:r.fields)??[]).filter(P=>{var Q;return(Q=P.valueExpression)==null?void 0:Q.trim()}),k=E.length>0,R=n==="action"||n==="connector";return C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:R&&(k||!e.body.trim())?C.jsxs(C.Fragment,{children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Per-Field Value Expressions"}),C.jsx("span",{children:k?"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."})]}),k?C.jsx("div",{style:aT,children:C.jsxs("table",{style:sT,children:[C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{style:Cs,children:"Output Field"}),C.jsx("th",{style:Cs,children:"Type"}),C.jsx("th",{style:Cs,children:"Expression"})]})}),C.jsx("tbody",{children:E.map(P=>C.jsxs("tr",{children:[C.jsx("td",{style:Ts,children:P.path}),C.jsx("td",{style:Ts,children:P.dataType}),C.jsx("td",{style:{...Ts,fontFamily:"var(--mu-font-mono)",fontSize:12},children:P.valueExpression})]},P.path))})]})}):null,C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Tip"}),C.jsxs("span",{children:["Switch to the ",C.jsx("strong",{children:"Output Data"})," tab to add or edit value expressions for each output field."]})]})]}):C.jsxs(C.Fragment,{children:[C.jsxs("label",{style:wo,children:["Expression Language",C.jsxs("select",{style:Qi,value:e.language,disabled:s,onChange:P=>c(P.target.value),children:[C.jsx("option",{value:"feel",children:"FEEL"}),C.jsx("option",{value:"javascript",children:"JavaScript"}),C.jsx("option",{value:"scriban",children:"Scriban"}),C.jsx("option",{value:"liquid",children:"Liquid"}),C.jsx("option",{value:"plain-text",children:"Plain Text"})]})]}),(()=>{const P=qi((t==null?void 0:t.fields)??[]),Q=[];return e.language==="feel"&&(Q.push(J5(P)),Q.push(Lq(P))),C.jsxs(C.Fragment,{children:[C.jsxs("div",{style:wo,children:[e.language==="liquid"?"Liquid Template":"Expression",C.jsx(YC,{value:e.body,language:e.language,readOnly:s,onChange:h,onInsertToken:A=>{y.current=A,m==null||m(A)},extensions:Q,minHeight:180,root:v})]}),C.jsx(Oq,{visible:e.language==="feel",onInsert:A=>{var L;return(L=y.current)==null?void 0:L.insert(A)}})]})})(),C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Authoring hints"}),C.jsx("span",{children:"Type '.' after a field name or press Ctrl+Space for autocomplete. Click any field in Input Scope to insert at cursor."}),l?C.jsxs("span",{children:["Contract API: ",l]}):null]}),n==="liquid"||e.language==="liquid"?C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Liquid Preview"}),C.jsx("pre",{style:fG,children:x||"Preview is empty."})]}):null]})})}function Fq({readOnly:n,value:e,onChange:t}){const r={successLabel:(e==null?void 0:e.successLabel)??"Valid",failureLabel:(e==null?void 0:e.failureLabel)??"Rejected",failureMessage:(e==null?void 0:e.failureMessage)??""};return C.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Success Label",C.jsx(qx,{tooltip:"Shown on output edges when this condition evaluates to true"})]}),C.jsx("input",{style:Qi,value:r.successLabel,disabled:n,onChange:i=>t({...r,successLabel:i.target.value})})]}),C.jsxs("label",{style:wo,children:[C.jsxs("span",{children:["Failure Label",C.jsx(qx,{tooltip:"Shown on output edges when this condition evaluates to false"})]}),C.jsx("input",{style:Qi,value:r.failureLabel,disabled:n,onChange:i=>t({...r,failureLabel:i.target.value})})]}),C.jsxs("label",{style:wo,children:["Failure Message",C.jsx("textarea",{style:oT,value:r.failureMessage,disabled:n,onChange:i=>t({...r,failureMessage:i.target.value})})]})]})}function Xq({config:n,catalog:e,readOnly:t,onChange:r}){const i=e.find(c=>c.connectorType===n.connectorType),s=(i==null?void 0:i.requiresCredentials)||(i==null?void 0:i.credentialFields)&&i.credentialFields.length>0;function l(c){r==null||r({...n,...c})}return C.jsxs("div",{style:{display:"grid",gap:"var(--mu-space-sm)"},children:[C.jsxs("label",{style:wo,children:["Connector Type",C.jsxs("select",{style:Qi,value:n.connectorType??"",disabled:t,onChange:c=>l({connectorType:c.target.value,connectorConfig:{},credentialId:void 0}),children:[C.jsx("option",{value:"",children:"Select connector type"}),e.map(c=>C.jsxs("option",{value:c.connectorType,children:[c.displayName," ",c.category?`(${c.category})`:""]},c.connectorType))]})]}),n.connectorType?C.jsxs(C.Fragment,{children:[i!=null&&i.description?C.jsx("div",{style:Qd,children:C.jsx("span",{children:i.description})}):null,C.jsxs("label",{style:wo,children:["Config JSON",C.jsx("textarea",{style:{...oT,fontFamily:"var(--mu-font-mono)",fontSize:13},value:JSON.stringify(n.connectorConfig??{},null,2),disabled:t,onChange:c=>{try{const h=JSON.parse(c.target.value);l({connectorConfig:h})}catch{}}})]}),i!=null&&i.configSchema?C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"Config Schema"}),C.jsx("pre",{style:{margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:11},children:JSON.stringify(i.configSchema,null,2)})]}):null]}):null,s?C.jsxs("label",{style:wo,children:["Credential ID",C.jsx("input",{style:Qi,value:n.credentialId??"",disabled:t,placeholder:"Enter credential identifier",onChange:c=>l({credentialId:c.target.value})})]}):null]})}function Wq({table:n,loadState:e}){return C.jsxs("div",{style:uG,"data-testid":"decision-table-overview",children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Decision Table Schema"}),C.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."})]}),n?C.jsxs(C.Fragment,{children:[C.jsxs("div",{children:[C.jsx("strong",{children:n.name})," · v",n.version," · hit policy ",n.hitPolicy]}),n.description?C.jsx("div",{children:n.description}):null,C.jsxs("div",{style:{display:"grid",gap:8},children:[C.jsxs("div",{children:[C.jsx("strong",{children:"Input Columns"}),C.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:n.inputColumns.map(t=>C.jsxs("span",{style:lT,children:[t.label," (",t.dataType,")"]},t.id))})]}),C.jsxs("div",{children:[C.jsx("strong",{children:"Output Columns"}),C.jsx("div",{style:{display:"flex",flexWrap:"wrap",gap:6,marginTop:6},children:n.outputColumns.map(t=>C.jsxs("span",{style:lT,children:[t.label," (",t.dataType,")"]},t.id))})]})]}),C.jsxs("div",{style:Qd,children:[C.jsx("strong",{children:"FEEL cell hints"}),C.jsx("span",{children:"Input columns become the effective input contract for this node. Output columns are emitted downstream after the table evaluates."}),C.jsx("span",{children:"Use FEEL row expressions against the input column names exactly as defined here."})]})]}):(e==null?void 0:e.status)==="idle"?C.jsx("span",{children:"Select a decision table to preview its column schema."}):null]})}function Hq({title:n,subtitle:e,contract:t,loadState:r,readOnly:i,onInsert:s,groupBySource:l}){const[c,h]=q.useState("tree"),[m,v]=q.useState(!0),y=(t==null?void 0:t.fields)??[],x=qi(y),S=y.length>0,E=new Map;for(const R of y){const P=l?R.sourceNodeLabel??(R.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",Q=E.get(P)??[];Q.push(R),E.set(P,Q)}const k=new Map;for(const R of x){const P=l?R.sourceNodeLabel??(R.sourceKind==="flow-input"?"Flow Input":"Current Scope"):"All Fields",Q=k.get(P)??[];Q.push(R),k.set(P,Q)}return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:n}),C.jsx("span",{children:r.status==="loading"?"Loading contract...":e})]}),S?C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,flexShrink:0},children:[c==="tree"?C.jsx("button",{type:"button",onClick:()=>v(!m),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:m?"Collapse All":"Expand All"}):null,C.jsxs("div",{style:{display:"flex",borderRadius:6,overflow:"hidden",border:"1px solid var(--mu-border-subtle)"},children:[C.jsx("button",{type:"button",onClick:()=>h("tree"),style:{border:"none",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:c==="tree"?"var(--mu-color-interactive)":"transparent",color:c==="tree"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Schema Tree"}),C.jsx("button",{type:"button",onClick:()=>h("table"),style:{border:"none",borderLeft:"1px solid var(--mu-border-subtle)",padding:"3px 10px",fontSize:11,cursor:"pointer",fontWeight:600,backgroundColor:c==="table"?"var(--mu-color-interactive)":"transparent",color:c==="table"?"var(--mu-text-on-accent)":"var(--mu-text-muted)"},children:"Flat Table"})]})]}):null]}),S?c==="tree"?C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:4,maxHeight:420,overflow:"auto"},children:[...E.entries()].map(([R,P])=>C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:2},children:[l?C.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)",padding:"4px 8px"},children:R}):null,P.map(Q=>C.jsx(pL,{field:Q,depth:0,readOnly:i,onInsert:s,defaultExpanded:m},Q.path))]},R))},m?"expanded":"collapsed"):[...k.entries()].map(([R,P])=>C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[l?C.jsx("div",{style:{fontSize:12,fontWeight:700,color:"var(--mu-text-secondary)"},children:R}):null,C.jsx(gL,{fields:P,readOnly:i,onInsert:s})]},R)):r.status==="loading"?C.jsx(Qp,{icon:"\\u231B",message:"Fetching contract metadata..."}):C.jsx(Qp,{message:"No scope metadata available for this node."})]})}function Yq({status:n}){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[n??"mapped"]??e.mapped;return C.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 qq({nodeType:n,readOnly:e,upstreamFields:t,targetFields:r,rows:i,onInsert:s,onChangeTargetFields:l,onChange:c,setInspectorTab:h,hasExpression:m}){const v=n==="action"||n==="sub-flow",y=n==="action";function x(R,P){c(i.map(Q=>Q.id===R?P(Q):Q))}function S(){const R=`input.${r.length+1}`;l([...r,{path:R,label:R,dataType:"string",required:!1}])}function E(R,P){const Q=r.find(L=>L.path===R);if(!Q)return;const A=P(Q);l(r.map(L=>L.path===R?A:L)),c(i.map(L=>(L.targetField??L.targetPath)===R?{...L,targetField:A.path,targetPath:A.path,targetDataType:A.dataType,required:A.required}:L))}function k(R){l(r.filter(P=>P.path!==R)),c(i.filter(P=>(P.targetField??P.targetPath)!==R))}return i.length===0?n==="action"&&!m?C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&y?C.jsx("button",{type:"button",style:wa(!1),onClick:S,children:"Add Input Slot"}):null]}),C.jsx(Qp,{icon:"info",message:"This node uses code-first logic — no expression-based mapping needed. Input/output contracts come from the registered rule code."})]}):(n==="condition"||n==="liquid")&&!m?C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),C.jsx(Qp,{icon:"edit",message:"Write a FEEL expression in the Logic tab to see data flow here.",actionHint:"Go to Logic tab",onAction:()=>h("logic")})]}):C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),C.jsx(Qp,{icon:"warning",message:"Expression references fields not found in upstream scope. Check field names in the Logic tab.",actionHint:"Go to Logic tab",onAction:()=>h("logic")})]}):C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:"var(--mu-space-sm)",alignItems:"center"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Data Flow"}),C.jsx("span",{children:"Where this node gets its data from upstream nodes"})]}),!e&&y?C.jsx("button",{type:"button",style:wa(!1),onClick:S,children:"Add Input Slot"}):null]}),C.jsx("div",{style:aT,children:C.jsxs("table",{style:sT,children:[C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{style:Cs,children:"Source"}),C.jsx("th",{style:Cs,children:"Target"}),C.jsx("th",{style:Cs,children:"Type"}),C.jsx("th",{style:Cs,children:"Status"}),C.jsx("th",{style:Cs,children:"Transform"}),y?C.jsx("th",{style:Cs,children:"Actions"}):null]})}),C.jsx("tbody",{children:i.map(R=>C.jsxs("tr",{children:[C.jsx("td",{style:Ts,children:v?C.jsx("input",{list:"upstream-scope-fields",style:Qi,value:R.sourcePath,disabled:e,onChange:P=>x(R.id,Q=>({...Q,sourcePath:P.target.value}))}):C.jsx("button",{type:"button",style:Dp,onClick:()=>s(R.sourcePath),disabled:e||!R.sourcePath,children:R.sourcePath||"unmapped"})}),C.jsx("td",{style:Ts,children:y?C.jsx("input",{style:Qi,value:R.targetField??R.targetPath,disabled:e,onChange:P=>E(R.targetField??R.targetPath,Q=>({...Q,path:P.target.value,label:P.target.value}))}):R.targetField??R.targetPath}),C.jsx("td",{style:Ts,children:y?C.jsx("input",{style:Qi,value:R.targetDataType??"string",disabled:e,onChange:P=>E(R.targetField??R.targetPath,Q=>({...Q,dataType:P.target.value}))}):C.jsx(Uv,{dataType:`${R.sourceDataType??"unknown"} → ${R.targetDataType??"unknown"}`})}),C.jsxs("td",{style:Ts,children:[C.jsx(Yq,{status:R.status}),R.required?C.jsx("span",{style:{fontSize:10,color:"var(--mu-color-error)",marginLeft:4,fontWeight:600},children:"required"}):null]}),C.jsx("td",{style:Ts,children:v?C.jsx("input",{style:Qi,value:R.transform??R.transformSuggestion??"",disabled:e,onChange:P=>x(R.id,Q=>({...Q,transform:P.target.value}))}):R.transformSuggestion??R.transform??"—"}),y?C.jsx("td",{style:Ts,children:C.jsx("button",{type:"button",style:Dp,disabled:e,onClick:()=>k(R.targetField??R.targetPath),children:"Remove"})}):null]},R.id))})]})}),C.jsx("datalist",{id:"upstream-scope-fields",children:t.map(R=>C.jsx("option",{value:R.path},R.path))}),r.length?C.jsxs("div",{style:Qd,children:[C.jsx("strong",{title:"Fields this node declares it needs — must be provided by upstream nodes or flow input",children:"Required input slots"}),C.jsx("span",{children:r.filter(R=>R.required).map(R=>R.path).join(", ")||"No required fields declared."})]}):null]})}function mL({title:n,count:e,defaultExpanded:t,headerRight:r,children:i}){const[s,l]=q.useState(t);return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)"},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsxs("div",{role:"button",tabIndex:0,onClick:()=>l(!s),onKeyDown:c=>{(c.key==="Enter"||c.key===" ")&&(c.preventDefault(),l(!s))},style:{display:"flex",alignItems:"center",gap:8,cursor:"pointer",padding:"6px 8px",borderRadius:6,userSelect:"none",transition:"background-color 0.1s",flex:1},children:[C.jsx("span",{style:{fontSize:10,color:"var(--mu-text-muted)",width:16,textAlign:"center"},children:s?"▼":"▶"}),C.jsx("strong",{style:{fontSize:13,color:"var(--mu-text-label)"},children:n}),e!==void 0?C.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]}),r]}),s?i:null]})}function Gq({nodeType:n,contract:e,upstreamScope:t,issues:r,readOnly:i,onInsert:s,onChange:l}){if(n==="end")return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},children:[C.jsxs("div",{style:qu,children:[C.jsx("strong",{children:"Final Scope"}),C.jsx("span",{children:"Everything guaranteed to be available when the flow reaches this end node."})]}),C.jsx(gL,{fields:qi((t==null?void 0:t.fields)??[]),readOnly:i,onInsert:s})]});const c=n==="condition"||n==="action",h=qi((e==null?void 0:e.fields)??[]),m=h.filter(Q=>!Q.isResultPayload),v=h.filter(Q=>Q.isResultPayload),S=n==="condition"||n==="action";function E(Q,A){const L=h.map(B=>!B.isResultPayload&&m.indexOf(B)===Q?A(B):B);l(L)}function k(Q){const A=m[Q];l(h.filter(L=>L!==A))}function R(){const Q=`custom.${m.length+1}`;l([...h,{path:Q,label:Q,dataType:"string",required:!1}])}const P=(()=>{const Q=[];return t&&Q.push(J5(qi(t.fields))),Q})();return C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:16},children:[C.jsx(mL,{title:"Custom Output Fields",count:m.length,defaultExpanded:!0,headerRight:!i&&c?C.jsx("button",{type:"button",style:wa(!1),onClick:R,children:"Add Field"}):void 0,children:m.length===0?C.jsx(Qp,{message:"No custom output fields defined.",actionHint:c&&!i?"Add a field to compute values for downstream nodes.":void 0,onAction:c&&!i?R:void 0}):C.jsx("div",{style:rG,children:m.map((Q,A)=>C.jsxs("div",{style:iG,children:[C.jsxs("div",{style:yL,children:[c?C.jsx("input",{style:{...Qi,flex:"1 1 0%",minWidth:0},value:Q.path,disabled:i,placeholder:"field.path",title:"Dotted path where this value is stored in the FactBag",onChange:L=>E(A,B=>({...B,path:L.target.value,label:L.target.value}))}):C.jsx("button",{type:"button",style:{...Dp,flex:"1 1 0%",minWidth:0,overflow:"hidden",textOverflow:"ellipsis"},onClick:()=>s(Q.path),disabled:i,children:Q.path}),c&&!i?C.jsx("button",{type:"button",style:{...Dp,color:"var(--mu-color-error-text)",flexShrink:0,fontSize:"var(--mu-text-xs)"},onClick:()=>k(A),title:"Remove this field",children:"delete"}):null]}),C.jsxs("div",{style:yL,children:[c&&!i?C.jsx("select",{style:oG,value:Q.dataType,title:"Data type of the output value",onChange:L=>E(A,B=>({...B,dataType:L.target.value})),children:["string","number","boolean","object","array"].map(L=>C.jsx("option",{value:L,children:L},L))}):C.jsx(Uv,{dataType:Q.dataType}),S?C.jsx("div",{style:{flex:"1 1 0%",minWidth:0},children:c?C.jsx(YC,{value:Q.valueExpression??"",language:"feel",readOnly:i,singleLine:!0,placeholderText:"e.g. command.details.length",onChange:L=>E(A,B=>({...B,valueExpression:L,runtimeWritten:L.trim().length>0})),extensions:P,root:void 0}):C.jsx("span",{style:{fontFamily:"var(--mu-font-mono)",fontSize:"var(--mu-text-xs)"},children:Q.valueExpression??"—"})}):null]})]},`output-custom-${A}`))})}),v.length>0?C.jsx(mL,{title:"Auto-Generated Results",count:v.length,defaultExpanded:!1,children:C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:2,padding:"4px 0"},children:v.map((Q,A)=>C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6,padding:"3px 8px",fontSize:12},children:[C.jsx("button",{type:"button",style:{...Dp,flex:1,textAlign:"left"},onClick:()=>s(Q.path),disabled:i,children:Q.path}),C.jsx(Uv,{dataType:Q.dataType})]},`output-auto-${A}`))})}):null,r.length?C.jsx(vL,{issues:r.filter(Q=>Q.severity!=="info")}):null]})}function gL({fields:n,readOnly:e,onInsert:t}){return C.jsx("div",{style:aT,children:C.jsxs("table",{style:sT,children:[C.jsx("thead",{children:C.jsxs("tr",{children:[C.jsx("th",{style:Cs,children:"Path"}),C.jsx("th",{style:{...Cs,width:"15%"},children:"Type"}),C.jsx("th",{style:Cs,children:"Description"})]})}),C.jsx("tbody",{children:n.map(r=>C.jsxs("tr",{children:[C.jsx("td",{style:Ts,children:C.jsx("button",{type:"button",style:Dp,onClick:()=>t(r.path),disabled:e,children:r.path})}),C.jsx("td",{style:Ts,children:C.jsx(Uv,{dataType:r.dataType})}),C.jsx("td",{style:Ts,title:r.description??r.label,children:r.description??r.label})]},`${r.sourceNodeId??"scope"}:${r.path}`))})]})})}const Kq=C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-error)",style:{flexShrink:0,marginTop:1},children:C.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"})}),Jq=C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"var(--mu-color-warning)",style:{flexShrink:0,marginTop:1},children:C.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 vL({issues:n}){return C.jsx("div",{style:{display:"flex",flexDirection:"column",gap:6},children:n.map(e=>{const t=e.severity==="error";return C.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?Kq:Jq,C.jsxs("span",{style:{color:t?"var(--mu-color-error-text)":"var(--mu-color-warning-text)",lineHeight:"20px"},children:[C.jsx("strong",{children:e.code})," ",e.message,e.fieldPath?C.jsxs("span",{style:{opacity:.7,marginLeft:4},children:["(",e.fieldPath,")"]}):null]})]},`${e.code}:${e.message}:${e.fieldPath??""}`)})})}const qu={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-text-muted)"},eG={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)"},tG={display:"flex",flexWrap:"nowrap",overflowX:"auto",gap:0,paddingBottom:0,borderBottom:"1px solid var(--mu-border-subtle)",marginBottom:"var(--mu-space-xs)"},wo={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-medium)",color:"var(--mu-text-label)"},Qi={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%"},oT={...Qi,minHeight:116,resize:"vertical"},aT={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)"},sT={width:"100%",tableLayout:"fixed",borderCollapse:"collapse",fontSize:12},Cs={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"},Ts={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"},Dp={border:"none",background:"transparent",color:"var(--mu-color-interactive)",padding:0,cursor:"pointer",fontFamily:"inherit",fontSize:12,textAlign:"left"},nG={display:"grid",gridTemplateColumns:"repeat(2, minmax(0, 1fr))",gap:"var(--mu-space-sm)"},rG={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",overflowY:"auto",maxHeight:"50vh",minHeight:80},iG={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)"},yL={display:"flex",alignItems:"center",gap:"var(--mu-space-xs)",minWidth:0},oG={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},aG={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},Qd={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},sG={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},lG={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},uG={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)"},lT={borderRadius:999,padding:"4px 8px",background:"var(--mu-color-interactive-subtle)",color:"var(--mu-text-primary)",fontSize:11,fontWeight:600},cG={...lT,border:"none",cursor:"pointer"},fG={margin:0,whiteSpace:"pre-wrap",wordBreak:"break-word",fontFamily:"var(--mu-font-mono)",fontSize:12};function dG(n,e,t){const r=qi(e),i=new Map(r.map(l=>[l.path,l.example??`<${l.path}>`])),s=n.replace(/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)\s*\}\}/g,(l,c)=>String(i.get(c)??`<${c}>`));return s}function wa(n){return{borderRadius:12,border:n?"1px solid var(--mu-color-interactive-border)":"1px solid var(--mu-border-input)",background:n?"var(--mu-color-interactive-subtle)":"var(--mu-surface-raised)",color:"var(--mu-text-primary)",padding:"10px 12px",fontWeight:600,minHeight:44}}function hG(n){return{borderRadius:0,border:"none",borderBottom:n?"2px solid var(--mu-color-interactive)":"2px solid transparent",background:"transparent",color:n?"var(--mu-color-interactive)":"var(--mu-text-muted)",fontWeight:n?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 pG({groups:n,loading:e,readOnly:t,onAddRule:r,onDragStart:i}){const[s,l]=q.useState(""),c=s.trim().toLowerCase(),h=q.useMemo(()=>[...n].sort((v,y)=>(v.category??"").localeCompare(y.category??"")).map(v=>({...v,items:[...v.items].filter(y=>gG(y,c)).sort((y,x)=>(y.displayName??"").localeCompare(x.displayName??""))})).filter(v=>v.items.length>0),[n,c]);return C.jsxs("div",{style:vG,children:[C.jsxs("div",{style:yG,children:[C.jsx("strong",{children:"Rule Catalog"}),C.jsx("span",{children:"Load reusable rule templates from the control plane and drop them into the flow."})]}),C.jsxs("label",{style:OG,children:["Search rules",C.jsx("input",{"data-testid":"catalog-search-input",style:xG,value:s,onChange:m=>l(m.target.value),placeholder:"Search by name, code, tag or description",disabled:e})]}),e?C.jsx("div",{"data-testid":"catalog-loading-state",style:OL,children:"Loading rule catalog..."}):null,!e&&h.length===0?C.jsx("div",{"data-testid":"catalog-empty-state",style:OL,children:c?"No rules match the current search.":"No rules available."}):null,e?null:h.map(m=>C.jsxs("div",{"data-testid":`catalog-group-${m.category}`,style:bG,children:[C.jsx("span",{style:wG,title:m.category,children:mG(m.category)}),m.items.map(v=>C.jsx("button",{type:"button",style:SG,"data-testid":`palette-rule-${v.code}`,draggable:!t,onClick:()=>r(v),onDragStart:y=>i(y,v),disabled:t,children:C.jsxs("span",{style:kG,children:[C.jsx("strong",{children:v.displayName}),C.jsx("span",{style:CG,children:v.code}),v.description?C.jsx("span",{style:TG,children:v.description}):null,v.tags.length>0?C.jsx("span",{style:EG,children:v.tags.join(" · ")}):null]})},v.code))]},m.category))]})}function mG(n){const e=n.split(".");return e.length<=2?n:e.slice(-2).join(".")}function gG(n,e){return e?[n.code,n.displayName,n.description??"",...n.tags??[]].join(" ").toLowerCase().includes(e):!0}const vG={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},yG={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-sm)",color:"var(--mu-color-text-muted)"},OG={display:"flex",flexDirection:"column",gap:"var(--mu-space-xs)",fontSize:"var(--mu-text-xs)",color:"var(--mu-color-text-secondary)",fontWeight:600},xG={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},OL={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},bG={display:"flex",flexDirection:"column",gap:"var(--mu-space-sm)"},wG={fontSize:12,fontWeight:700,letterSpacing:"0.04em",textTransform:"uppercase",color:"var(--mu-color-text-secondary)"},SG={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},kG={display:"flex",flexDirection:"column",gap:4},CG={fontSize:"var(--mu-text-xs)",fontFamily:"var(--mu-font-mono)",fontWeight:500,color:"var(--mu-color-text-secondary)"},TG={fontSize:12,fontWeight:500,color:"var(--mu-color-text-muted)"},EG={fontSize:"var(--mu-text-xs)",color:"var(--mu-color-interactive)"},_G={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 uT(n){return _G}const cT={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"},RG={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"},xL={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)"},PG=xL;function bL(n,e){const t=Ai(n),r=MG(t,e);return{...t,nodes:t.nodes.map(i=>{var s,l,c,h;return{...i,data:{...i.data,contractLayer:r.get(i.id),dependsOn:i.data.dependsOn??((l=(s=e.nodeContractsById)==null?void 0:s.get(i.id))==null?void 0:l.dependsOn)??[],order:i.data.order??((h=(c=e.nodeContractsById)==null?void 0:c.get(i.id))==null?void 0:h.order)}}})}}function fT(n,e){const t=Lp(n,e),r=bL(t.graph,e),i=r.nodes.flatMap(s=>{var l;return((l=s.data.contractLayer)==null?void 0:l.validationIssues)??[]});return{graph:r,issues:[...t.issues,...i],isValid:t.isValid&&i.every(s=>s.severity!=="error")}}function Lp(n,e){var S,E;const t=Ai(n),r=t.nodes.filter(k=>k.type!=="trigger"&&k.type!=="end"),i=new Set(r.map(k=>k.id)),s=new Map(r.filter(k=>k.ruleCode).map(k=>[k.ruleCode,k.id])),l=new Map,c=new Map,h=k=>{l.has(k)||l.set(k,new Set),c.has(k)||c.set(k,0)},m=(k,R)=>{if(k===R||!i.has(k)||!i.has(R))return;h(k),h(R);const P=l.get(k);P.has(R)||(P.add(R),c.set(R,(c.get(R)??0)+1))};for(const k of r){h(k.id);const R=k.data.dependsOn??((E=(S=e.nodeContractsById)==null?void 0:S.get(k.id))==null?void 0:E.dependsOn)??[];for(const P of R){const Q=s.get(P);Q&&m(Q,k.id)}}for(const k of t.edges)k.edgeType!=="on-error"&&m(k.source,k.target);const v=[...r].sort((k,R)=>{var A,L,B,j;const P=k.data.order??((L=(A=e.nodeContractsById)==null?void 0:A.get(k.id))==null?void 0:L.order)??Number.MAX_SAFE_INTEGER,Q=R.data.order??((j=(B=e.nodeContractsById)==null?void 0:B.get(R.id))==null?void 0:j.order)??Number.MAX_SAFE_INTEGER;return P!==Q?P-Q:(k.label??"").localeCompare(R.label??"")}).filter(k=>(c.get(k.id)??0)===0).map(k=>k.id),y=[];for(;v.length>0;){const k=v.shift();y.push(k);const R=[...l.get(k)??[]].sort((P,Q)=>P.localeCompare(Q));for(const P of R){const Q=(c.get(P)??0)-1;c.set(P,Q),Q===0&&v.push(P)}}if(y.length!==r.length)return{graph:t,issues:[{code:"MRF008",severity:"error",message:"Rule flow contains a dependency cycle or invalid ordering edge."}],isValid:!1};const x=new Map(y.map((k,R)=>[k,R+1]));return{graph:{...t,nodes:t.nodes.map(k=>{var R,P;return i.has(k.id)?{...k,data:{...k.data,order:x.get(k.id)??k.data.order,dependsOn:k.data.dependsOn??((P=(R=e.nodeContractsById)==null?void 0:R.get(k.id))==null?void 0:P.dependsOn)??[]}}:k})},issues:[],isValid:!0}}function MG(n,e){const t=new Map(n.nodes.map(k=>[k.id,k])),r=new Map;for(const k of n.edges){const R=r.get(k.target)??[];R.push(k),r.set(k.target,R)}const i=new Map,s=new Set,l=k=>k.type,c=$G(n,e),h=(k,R)=>{var j,Z;const P=t.get(k);if(!P)return[];const Q=E(P),A=cf(((j=Q.upstreamScope)==null?void 0:j.fields)??[]),L=cf(((Z=Q.outputContract)==null?void 0:Z.fields)??[]);if(l(P)!=="condition")return Gu([...A,...SL(L)]);const B=R==="on-false"?L.filter(ee=>ee.isResultPayload):L;return Gu([...A,...SL(B)])},m=k=>{var A,L,B,j;const R=k.data.dependsOn??((L=(A=e.nodeContractsById)==null?void 0:A.get(k.id))==null?void 0:L.dependsOn)??[];if(R.length>0){const Z=n.nodes.filter(ee=>ee.ruleCode&&R.includes(ee.ruleCode));return Gu(Z.flatMap(ee=>h(ee.id,"always")))}const P=k.data.order??((j=(B=e.nodeContractsById)==null?void 0:B.get(k.id))==null?void 0:j.order)??Number.MAX_SAFE_INTEGER,Q=n.nodes.filter(Z=>{var ie,pe;const ee=Z.data.order??((pe=(ie=e.nodeContractsById)==null?void 0:ie.get(Z.id))==null?void 0:pe.order)??Number.MAX_SAFE_INTEGER;return Z.id!==k.id&&ee<P});return Gu(Q.flatMap(Z=>h(Z.id,"always")))},v=k=>{if(k.type==="trigger")return{contractName:`${e.flowCode??"flow"}_trigger_input`,title:"Input Scope",fields:c.map(Q=>uf(Q,{sourceKind:"flow-input"}))};const R=r.get(k.id)??[],P=R.length>0?R.flatMap(Q=>h(Q.source,Q.edgeType)):m(k);return P.length===0&&P.push(...c.map(Q=>uf(Q,{sourceKind:"flow-input"}))),{contractName:`${k.ruleCode??k.id}_input_scope`,title:"Input Scope",fields:Gu(P)}},y=(k,R)=>{var W,le,V,se,ne,ae;const P=(W=e.nodeContractsById)==null?void 0:W.get(k.id),Q=k.type==="sub-flow"?(le=e.flowContractsByCode)==null?void 0:le.get(fl(k.data.subFlowConfig).targetFlowCode??""):void 0,A=((V=k.data.contractOverride)==null?void 0:V.responseFields)??[],L=((se=Q==null?void 0:Q.responseContract)==null?void 0:se.fields)??((ne=k.data.responseContract)==null?void 0:ne.fields)??((ae=P==null?void 0:P.responseDelta)==null?void 0:ae.fields)??[],j=(Array.isArray(k.data.outputFields)?k.data.outputFields:[]).map(Y=>({path:Y.path,label:Y.path,dataType:Y.dataType??"string",valueExpression:Y.valueExpression})),Z=Gu([...cf(L),...j]),ee=A.length>0?QG(Z,A):Z,pe=(k.type==="condition"&&!k.ruleCode?ee.filter(Y=>{var G;return Y.runtimeWritten||((G=Y.valueExpression)==null?void 0:G.trim())}):ee).map(Y=>{var G;return uf(Y,{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:k.type==="sub-flow"?"sub-flow-output":"node-output",runtimeWritten:k.ruleCode?!0:k.type==="condition"?!!(Y.runtimeWritten??((G=Y.valueExpression)==null?void 0:G.trim())):Y.runtimeWritten??!0})});if(k.type==="trigger"){const Y=c.map(G=>uf(G,{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"flow-input",runtimeWritten:!0}));return{contractName:`${k.id}_output_contract`,title:"Output Contract",fields:Gu(Y)}}if(k.type!=="condition")return{contractName:`${k.ruleCode??k.id}_output_contract`,title:"Output Contract",fields:Gu(AG(k,pe))};const oe=[uf({path:"result.isPass",label:"isPass",dataType:"boolean",required:!0},{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),uf({path:"result.message",label:"message",dataType:"string"},{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0}),uf({path:"result.errorCode",label:"errorCode",dataType:"string"},{sourceNodeId:k.id,sourceNodeLabel:k.label,sourceNodeType:k.type,sourceKind:"result-payload",isResultPayload:!0,runtimeWritten:!0})];return{contractName:`${k.ruleCode??k.id}_output_contract`,title:"Output Contract",fields:Gu([...oe,...pe])}},x=(k,R)=>{var B,j,Z,ee,ie;const P=qi(R.fields),Q=k.type==="sub-flow"?fl(k.data.subFlowConfig).inputMappings:k.data.inputMappings??[];if(k.type==="sub-flow"){const pe=fl(k.data.subFlowConfig).childTriggerSchema,oe=qi((pe==null?void 0:pe.fields)??[]);return{contractName:`${k.ruleCode??k.id}_effective_input`,title:"Effective Input",mode:"sub-flow",fields:oe,mappings:wL(P,oe,Q)}}if(k.type==="condition"||k.type==="liquid"){const pe=iu(k.data),oe=(pe.language??"").toLowerCase(),W=oe==="feel"||oe===""?DG(pe.body,P):[];return{contractName:`${k.ruleCode??k.id}_effective_input`,title:"Effective Input",mode:k.type==="liquid"?"expression":"auto",fields:W,mappings:W.map(le=>({id:`auto-${le.path}`,sourcePath:le.path,targetPath:le.path,targetField:le.path,sourceDataType:le.dataType,targetDataType:le.dataType,sourceNodeId:le.sourceNodeId,sourceNodeLabel:le.sourceNodeLabel,status:"mapped",required:le.required}))}}const A=qi(((B=k.data.contractOverride)==null?void 0:B.requestFields)??((j=k.data.requestContract)==null?void 0:j.fields)??((ie=(ee=(Z=e.nodeContractsById)==null?void 0:Z.get(k.id))==null?void 0:ee.requestScope)==null?void 0:ie.fields)??[]),L=k.type==="end"?[]:A;return{contractName:`${k.ruleCode??k.id}_effective_input`,title:"Effective Input",mode:k.type==="decision-table"?"decision-table":k.type==="action"?"manual":"auto",fields:L,mappings:wL(P,L,Q)}},S=(k,R,P,Q)=>{var B;const A=qi(R.fields),L=[];for(const j of P.mappings){if(j.required&&!j.sourcePath.trim()){L.push({code:"MRF001",severity:"error",message:`Required input '${j.targetField??j.targetPath}' is not mapped.`,nodeId:k.id,targetPath:j.targetField??j.targetPath});continue}if(!j.sourcePath.trim())continue;if(!A.find(ee=>ee.path===j.sourcePath)){const ee=k.type==="sub-flow"||k.type==="connector"||k.type==="decision-table";L.push({code:"MRF002",severity:ee?"warning":"error",message:ee?`Source field '${j.sourcePath}' is not in upstream scope (may be resolved from FactBag at runtime).`:`Source field '${j.sourcePath}' is not available in upstream scope.`,nodeId:k.id,sourcePath:j.sourcePath,targetPath:j.targetField??j.targetPath});continue}j.targetDataType&&j.sourceDataType&&j.targetDataType!==j.sourceDataType&&!(j.transform??"").trim()&&L.push({code:"MRF003",severity:"warning",message:`Mapping '${j.sourcePath}' -> '${j.targetField??j.targetPath}' has type mismatch (${j.sourceDataType} -> ${j.targetDataType}).`,nodeId:k.id,sourcePath:j.sourcePath,targetPath:j.targetField??j.targetPath})}if(k.type==="sub-flow"){const j=fl(k.data.subFlowConfig).childTriggerSchema;for(const Z of qi((j==null?void 0:j.fields)??[]).filter(ee=>ee.required))P.mappings.some(ie=>(ie.targetField??ie.targetPath)===Z.path&&ie.sourcePath.trim().length>0)||L.push({code:"MRF004",severity:"error",message:`Sub-flow input '${Z.path}' is required but not mapped.`,nodeId:k.id,fieldPath:Z.path})}if(k.type==="condition"||k.type==="liquid"){const j=iu(k.data),Z=j.body,ee=(j.language??"").toLowerCase();if(ee==="feel"||ee===""){const pe=LG(Z),oe=kL(Z);for(const W of oe){const le=W.split(".")[0];pe.has(le)||le.startsWith("__graph")||zG.has(le)||A.some(V=>V.path===W||W.startsWith(V.path+"."))||L.push({code:"MRF005",severity:"error",message:`Expression references '${W}' but that field is not available in input scope.`,nodeId:k.id,fieldPath:W})}}}if(k.type==="condition"&&!k.ruleCode)for(const j of qi(Q.fields).filter(Z=>!Z.isResultPayload&&!Z.runtimeWritten))(B=j.valueExpression)!=null&&B.trim()||L.push({code:"MRF009",severity:"warning",message:`Condition output '${j.path}' is metadata-only until a Value Expression is configured.`,nodeId:k.id,fieldPath:j.path});return k.type==="end"&&Q.fields.length>0&&L.push({code:"MRF006",severity:"warning",message:"End nodes should not define additional output fields.",nodeId:k.id}),L},E=k=>{const R=i.get(k.id);if(R)return R;if(s.has(k.id))return{upstreamScope:{contractName:`${k.id}_input_scope`,title:"Input Scope",fields:[]},effectiveInput:{contractName:`${k.id}_effective_input`,title:"Effective Input",fields:[],mappings:[]},outputContract:{contractName:`${k.id}_output_contract`,title:"Output Contract",fields:[]},validationIssues:[{code:"MRF007",severity:"error",message:"Cycle detected in rule flow graph.",nodeId:k.id}]};s.add(k.id);const P=v(k),Q=x(k,P),A=y(k),L=S(k,P,Q,A),B={upstreamScope:P,effectiveInput:Q,outputContract:A,validationIssues:L};return i.set(k.id,B),s.delete(k.id),B};for(const k of n.nodes)E(k);return i}function $G(n,e){var l,c,h,m,v;const t=cf(((c=(l=e.currentFlowContract)==null?void 0:l.requestContract)==null?void 0:c.fields)??[]);if(t.length>0)return t;const r=[...n.nodes].filter(y=>y.type!=="trigger"&&y.type!=="end").sort((y,x)=>{var k,R,P,Q;const S=y.data.order??((R=(k=e.nodeContractsById)==null?void 0:k.get(y.id))==null?void 0:R.order)??Number.MAX_SAFE_INTEGER,E=x.data.order??((Q=(P=e.nodeContractsById)==null?void 0:P.get(x.id))==null?void 0:Q.order)??Number.MAX_SAFE_INTEGER;return S!==E?S-E:(y.label??"").localeCompare(x.label??"")})[0];if(!r)return[];const i=(h=e.nodeContractsById)==null?void 0:h.get(r.id),s=((m=i==null?void 0:i.requestScope)==null?void 0:m.fields)??((v=r.data.requestContract)==null?void 0:v.fields)??[];return cf(s)}function wL(n,e,t){const r=new Map;for(const i of t){const s=n.find(c=>c.path===i.sourcePath),l=e.find(c=>c.path===i.targetPath);r.set(i.id,{...i,targetField:(l==null?void 0:l.path)??i.targetPath,sourceDataType:s==null?void 0:s.dataType,targetDataType:l==null?void 0:l.dataType,sourceNodeId:s==null?void 0:s.sourceNodeId,sourceNodeLabel:s==null?void 0:s.sourceNodeLabel,required:l==null?void 0:l.required,status:s?l!=null&&l.dataType&&s.dataType!==l.dataType&&!(i.transform??"").trim()?"type-mismatch":"mapped":"missing"})}for(const i of e){if([...r.values()].find(c=>(c.targetField??c.targetPath)===i.path))continue;const l=n.find(c=>c.path===i.path)??n.find(c=>CL(c.path)===CL(i.path)&&c.dataType===i.dataType);r.set(`suggested-${i.path}`,{id:`suggested-${i.path}`,sourcePath:(l==null?void 0:l.path)??"",targetPath:i.path,targetField:i.path,sourceDataType:l==null?void 0:l.dataType,targetDataType:i.dataType,sourceNodeId:l==null?void 0:l.sourceNodeId,sourceNodeLabel:l==null?void 0:l.sourceNodeLabel,required:i.required,status:l?"suggested":i.required?"missing":"suggested",transformSuggestion:l&&l.dataType!==i.dataType?`to_${i.dataType}(${l.path})`:void 0})}return[...r.values()]}function AG(n,e){if(n.type!=="sub-flow")return e;const t=fl(n.data.subFlowConfig).outputMappings;return t.length===0?e:e.map(r=>{const i=t.find(s=>s.sourcePath===r.path&&s.targetPath.trim().length>0);return i?{...r,path:i.targetPath,label:i.targetPath,exposeToParent:r.exposeToParent}:r})}function uf(n,e){var t;return{...n,...e,children:(t=n.children)==null?void 0:t.map(r=>uf(r,e))}}function Gu(n){const e=new Map;for(const t of n)e.has(t.path)||e.set(t.path,t);return[...e.values()].sort((t,r)=>(t.path??"").localeCompare(r.path??""))}function cf(n){return n.map(e=>({...e,children:e.children?cf(e.children):void 0}))}function QG(n,e){const t=new Map;for(const r of n)t.set(r.path,{...r,children:r.children?cf(r.children):void 0});for(const r of e)t.set(r.path,{...r,children:r.children?cf(r.children):void 0});return[...t.values()]}function SL(n){return n.filter(e=>e.exposeToParent!==!1)}function DG(n,e){const t=new Set(kL(n));return e.filter(r=>t.has(r.path))}function kL(n){if(!n.trim())return[];const e=new Set,t=/\b[a-zA-Z_][a-zA-Z0-9_.]*\b/g;let r=t.exec(n);for(;r;){const s=r[0];s.includes(".")&&e.add(s),r=t.exec(n)}const i=/\{\{\s*([a-zA-Z_][a-zA-Z0-9_.]*)/g;for(r=i.exec(n);r;)e.add(r[1]),r=i.exec(n);return[...e]}function CL(n){const e=n.split(".");return e[e.length-1]??n}function LG(n){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 r of t){let i=r.exec(n);for(;i;)e.add(i[1]),i=r.exec(n)}return e}const zG=new Set(["string","number","date","time","duration","list","context","math","Math","Date","JSON","RegExp","Object","Array","console","forloop","now","true","false","null"]),dT="application/muonroi-rule-flow-node-type",TL="application/muonroi-rule-flow-rule-template",EL={duration:0,padding:.22,minZoom:.18,maxZoom:1.1},_L=860,hT={always:"→ Always","on-true":"✓ On Pass","on-false":"✗ On Fail","on-error":"⚠ On Error"},NG={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."},jG={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)"}},IG={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 BG(n){var e,t,r,i,s;if(n.nodeType==="condition"&&((e=n.conditionConfig)!=null&&e.successLabel))return`Pass: ${n.conditionConfig.successLabel} / Fail: ${n.conditionConfig.failureLabel??"—"}`;if(n.nodeType==="action")return"Execute side-effect";if(n.nodeType==="decision-table")return(t=n.contractRef)!=null&&t.sourceCode?`Table: ${n.contractRef.sourceCode}`:"Decision table lookup";if(n.nodeType==="connector"){const l=(r=n.connectorConfig)==null?void 0:r.connectorType;return l?`Connector: ${l}`:"External service call"}return n.nodeType==="sub-flow"?(i=n.subFlowConfig)!=null&&i.targetFlowCode?`Flow: ${n.subFlowConfig.targetFlowCode}`:"Delegate to sub-flow":n.nodeType==="liquid"?`Liquid → ${((s=n.liquidConfig)==null?void 0:s.outputFormat)??"json"}`:null}function ZG({politeMessage:n,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 C.jsxs(C.Fragment,{children:[C.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:t,children:n}),C.jsx("div",{role:"alert","aria-live":"assertive","aria-atomic":"true",style:t,children:e})]})}function ff({data:n,selected:e}){var m,v,y;const t=Iv[n.nodeType],r=uT(n._theme??"light"),i=iu(n),s=((m=n.requestContract)==null?void 0:m.fields.length)??0,l=((v=n.responseContract)==null?void 0:v.fields.length)??0,c=cT[n.nodeType],h=BG(n);return C.jsxs("div",{style:{...z9,background:r.nodeBg,boxShadow:r.nodeShadow,borderTop:e?`2px solid ${t}`:r.nodeBorder,borderRight:e?`2px solid ${t}`:r.nodeBorder,borderBottom:e?`2px solid ${t}`:r.nodeBorder,borderLeft:`8px solid ${t}`,borderRadius:n.nodeType==="end"?999:n.nodeType==="condition"?24:18},"aria-label":`${Mp[n.nodeType]} node: ${n.label}`,children:[C.jsx(up,{type:"target",position:Pt.Left}),C.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:6},children:[C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:t,style:{flexShrink:0},children:C.jsx("path",{d:c})}),C.jsx("span",{style:{color:t,fontSize:11,fontWeight:700,letterSpacing:"0.08em",textTransform:"uppercase"},children:Mp[n.nodeType]})]}),C.jsx("strong",{style:{fontSize:14,color:r.nodeText},children:n.label}),h?C.jsx("span",{style:{fontSize:11,color:r.nodeMutedText,maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h}):null,n.ruleCode?C.jsxs("span",{style:{fontSize:12,color:r.nodeSubtext},children:["Rule: ",n.ruleCode]}):null,(y=n.contractRef)!=null&&y.sourceCode?C.jsxs("span",{style:{fontSize:11,color:r.nodeMutedText},children:["Contract: ",n.contractRef.sourceType,"/",n.contractRef.sourceCode]}):null,i.body?C.jsxs("span",{style:{display:"inline-block",maxWidth:220,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap",fontSize:12,color:r.nodeSubtext},children:[i.language.toUpperCase(),": ",i.body]}):null,s>0||l>0?C.jsxs("span",{style:{fontSize:11,color:r.nodeMutedText},children:["Inline contracts ",s,"/",l]}):null]}),C.jsx(up,{type:"source",position:Pt.Right})]})}const pT={trigger:ff,condition:ff,action:ff,"decision-table":ff,"sub-flow":ff,liquid:ff,connector:ff,end:ff};function df({path:n}){const e=Array.isArray(n)?n:[n];return C.jsx("svg",{width:12,height:12,viewBox:"0 0 16 16",fill:"currentColor",style:{flexShrink:0},children:e.map((t,r)=>C.jsx("path",{d:t},r))})}function UG({onAddTrigger:n}){return C.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:C.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:[C.jsxs("svg",{width:32,height:32,viewBox:"0 0 16 16",fill:"var(--mu-color-interactive)",opacity:.7,children:[C.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"}),C.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"})]}),C.jsx("strong",{style:{fontSize:"var(--mu-text-md)",color:"var(--mu-text-primary)"},children:"Start your workflow"}),C.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."}),C.jsx("button",{type:"button",onClick:n,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 VG({nodeIds:n,syncToken:e,hostElement:t}){const r=NV(),i=Kg(),s=IV({includeHiddenNodes:!0}),l=q.useRef(""),c=q.useRef(null);function h(){!s||n.length===0||(n.forEach(v=>r(v)),i.fitView(EL))}function m(v=0){return window.setTimeout(()=>{c.current!==null&&cancelAnimationFrame(c.current),c.current=requestAnimationFrame(()=>{c.current=null,h()})},v)}return q.useEffect(()=>{const v=String(e);if(!s||n.length===0||l.current===v)return;l.current=v;const y=m(),x=m(150),S=m(350);return()=>{window.clearTimeout(y),window.clearTimeout(x),window.clearTimeout(S),c.current!==null&&(cancelAnimationFrame(c.current),c.current=null)}},[n,s,i,e,r]),q.useEffect(()=>{if(!t)return;const v=new ResizeObserver(()=>{h()});v.observe(t);const y=()=>h();return window.addEventListener("resize",y),()=>{v.disconnect(),window.removeEventListener("resize",y)}},[t,s,i,r,n]),null}function FG(){const n=Kg();return q.useEffect(()=>{function e(t){const r=t.target,i=r.tagName.toLowerCase();if(i==="input"||i==="textarea"||i==="select"||r.isContentEditable)return;const s=t.ctrlKey||t.metaKey;if(t.key==="+"||s&&t.key==="="){t.preventDefault(),n.zoomIn({duration:150});return}if(t.key==="-"||s&&t.key==="-"){t.preventDefault(),n.zoomOut({duration:150});return}if(t.key==="f"||t.key==="F"||s&&t.key==="0"){t.preventDefault(),n.fitView(EL);return}}return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[n]),null}function XG({graph:n,onGraphChange:e,readOnly:t=!1,theme:r="light",height:i=640,apiBaseUrl:s,catalogApiBase:l,tenantId:c,workflowCode:h,onPublish:m,licenseStatus:v="licensed",showHeader:y=!0,version:x=null,onVersionChange:S,editorRoot:E}){var mf;const k=q.useMemo(()=>Ai(n),[n]),R=rq(k);function P(I){return I.map(H=>({...H,data:{...H.data,_theme:r}}))}function Q(I){const H=r==="dark"?PG:xL,Se=r==="dark"?IG:jG;return I.map(We=>{var Ii;const Ae=((Ii=We.data)==null?void 0:Ii.edgeType)??"always",xt=H[Ae]??H.always,kt=Se[Ae]??Se.always,gn=hT[Ae]??"Always";return{...We,label:gn,style:{stroke:xt,strokeWidth:2},labelStyle:{fill:kt.text,fontWeight:600,fontSize:12,letterSpacing:"0.02em"},labelBgStyle:{fill:kt.bg},labelBgPadding:[4,8],labelBgBorderRadius:999}})}const[A,L]=q.useState(()=>P(Zv(R.present))),[B,j]=q.useState(()=>Q(G5(R.present))),[Z,ee]=q.useState(""),[ie,pe]=q.useState(""),[oe,W]=q.useState("basic-info"),[le,V]=q.useState({status:"idle"}),[se,ne]=q.useState([]),[ae,Y]=q.useState([]),[G,ue]=q.useState(null),[F,K]=q.useState({status:"idle"}),[Te,Ee]=q.useState([]),[ze,Ie]=q.useState([]),[Be,Pe]=q.useState(!1),[Ze,rt]=q.useState(null),[dt,ut]=q.useState(""),[et,At]=q.useState(""),Tt=q.useRef(R.present.metadata),bt=q.useRef(Yi(R.present)),[Sn,hr]=q.useState(0),Bt=q.useRef(A),Yt=q.useRef(B),Jt=q.useRef(new Map),Xt=q.useRef(new Map),Gn=q.useRef(null),Wr=q.useRef(new Map),rn=q.useMemo(()=>s?new m6({baseUrl:s,tenantId:c}):null,[s,c]),Wn=q.useMemo(()=>l?new g6({baseUrl:l,tenantId:c}):null,[l,c]),Kn=q.useMemo(()=>s?new v6({baseUrl:s,tenantId:c}):null,[s,c]),di=q.useRef(null),Di=q.useRef(null);q.useRef(null);const Fe=q.useRef(!0),ht=q.useRef(!1),Zt=q.useRef(null),[un,Dn]=q.useState(0),[Jn,Ln]=q.useState("inspector"),[lr,zn]=q.useState(!1),cn=q.useRef(null),[on,hi]=q.useState(()=>{try{const I=localStorage.getItem("muonroi-rule-studio-sidebar-width");return I?Math.max(240,Math.min(400,Number(I))):280}catch{return 280}}),[$n,Li]=q.useState(()=>{try{return localStorage.getItem("muonroi-rule-studio-sidebar-collapsed")==="true"}catch{return!1}}),pi=q.useRef(!1),[qa,Ga]=q.useState(()=>{try{const I=localStorage.getItem("muonroi-rule-studio-toolbar-groups");return I?JSON.parse(I):{}}catch{return{}}}),Ar=I=>qa[I]===!0,So=I=>Ga(H=>{const Se={...H,[I]:!H[I]};try{localStorage.setItem("muonroi-rule-studio-toolbar-groups",JSON.stringify(Se))}catch{}return Se}),[Ka,Hr]=q.useState(!1),[Cr,er]=q.useState(!1),Gi=q.useRef(null),mi=q.useRef(null),[Qr,gi]=q.useState([]),[re,$e]=q.useState(0),[Ge,it]=q.useState(!1),[Ut,Qt]=q.useState(!1),Lt=q.useMemo(()=>Qr.find(I=>I.isActive)??null,[Qr]),jt=x!=null&&Lt!=null&&x!==Lt.version,an=t||jt,mn=q.useCallback((I,H)=>{if(!s||!h){H||gi([]);return}const Se=s.replace(/\/$/,""),We=Uo(void 0,{tenantId:c});H&&Qt(!0),fetch(`${Se}/rulesets/${encodeURIComponent(h)}/versions?limit=10&offset=${I}`,{headers:We}).then(Ae=>Ae.ok?Ae.json():[]).then(Ae=>{const xt=Array.isArray(Ae)?Ae:Array.isArray(Ae==null?void 0:Ae.items)?Ae.items:[];it(xt.length===10),gi(H?kt=>[...kt,...xt].sort((gn,Ii)=>Ii.version-gn.version):xt.sort((kt,gn)=>gn.version-kt.version))}).catch(Ae=>{console.warn("[MVersionDropdown] Failed to fetch versions:",Ae),H||gi([])}).finally(()=>{H&&Qt(!1)})},[s,h,c]);q.useEffect(()=>{$e(0),it(!1),mn(0,!1)},[mn]);const Zn=q.useCallback(()=>{const I=re+10;$e(I),mn(I,!0)},[re,mn]);q.useEffect(()=>{Bt.current=A},[A]),q.useEffect(()=>{Yt.current=B},[B]),q.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-width",String(on))}catch{}},[on]),q.useEffect(()=>{try{localStorage.setItem("muonroi-rule-studio-sidebar-collapsed",String($n))}catch{}},[$n]),q.useEffect(()=>{const I=Gi.current;if(!I)return;const H=new ResizeObserver(Se=>{for(const We of Se){const xt=We.contentRect.width<_L;Hr(xt),xt||er(!1)}});return H.observe(I),()=>H.disconnect()},[]),q.useEffect(()=>{if(!Cr)return;const I=H=>{mi.current&&!mi.current.contains(H.target)&&er(!1)};return document.addEventListener("click",I),()=>document.removeEventListener("click",I)},[Cr]),q.useEffect(()=>()=>{Ji(),Lr()},[]),q.useEffect(()=>{L(I=>P(I)),j(I=>Q(I))},[r]),q.useEffect(()=>{const I=Ai(n),H=Yi(I);H!==bt.current&&(Tt.current=I.metadata,R.reset(I),bt.current=H,Fe.current=!0,hr(Se=>Se+1),ee(""),pe(""),W("basic-info"),es(I))},[n,R.reset]),q.useEffect(()=>{const I=R.present,H=Yi(I),Se=Yi(ur(Bt.current,Yt.current,!1));H!==Se&&(Tt.current=I.metadata,bt.current=H,es(I))},[R.present]),q.useEffect(()=>{const I=H=>{H.target;const Se=H.composedPath().some(We=>{if(!(We instanceof HTMLElement))return!1;const Ae=We.tagName;return Ae==="INPUT"||Ae==="TEXTAREA"||Ae==="SELECT"||We.isContentEditable});if((H.ctrlKey||H.metaKey)&&H.key==="z"&&!H.shiftKey){H.preventDefault(),Ji(),R.undo();return}if((H.ctrlKey||H.metaKey)&&(H.key==="y"||H.key==="z"&&H.shiftKey)){H.preventDefault(),Ji(),R.redo();return}if(H.key==="Escape"){ee(""),pe(""),W("basic-info");return}if(!(an||Se)&&(H.key==="Delete"||H.key==="Backspace")){if(Z){qr();return}ie&&zi()}};return window.addEventListener("keydown",I),()=>window.removeEventListener("keydown",I)},[an,Z,ie]),q.useEffect(()=>{const I=di.current;if(!I)return;const H=()=>{var Ae;const We=((Ae=I.parentElement)==null?void 0:Ae.getBoundingClientRect().width)??I.getBoundingClientRect().width;Dn(We)};H();const Se=new ResizeObserver(()=>H());return Se.observe(I),()=>Se.disconnect()},[]);const[pr,ri]=q.useState(0),mr=q.useMemo(()=>ur(A,B,!1),[A,B]),zt=q.useMemo(()=>bL(mr,{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}),[pr,mr,h]),qe=q.useMemo(()=>Z?P(Zv(zt)).find(I=>I.id===Z)??null:null,[zt,Z,r]),vi=q.useMemo(()=>ie?B.find(I=>I.id===ie)??null:null,[B,ie]),Ja=qe?iu(qe.data):{language:"feel",body:""},Ki=q.useMemo(()=>fT(mr,{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}),[pr,mr,h]),Dr=q.useMemo(()=>Ki.issues.filter(I=>I.severity==="error"),[Ki.issues]),_s=q.useMemo(()=>Ki.issues.filter(I=>I.severity==="warning"),[Ki.issues]),ko=!an&&!!m&&Dr.length===0,Yr=q.useMemo(()=>qG(zt),[zt]);if(q.useEffect(()=>{if(!rn)return;let I=!1;return(async()=>{try{const H=await rn.MListFlows();I||ne(H.map(Se=>({code:Se.workflowName,label:Se.workflowName})))}catch{}})(),()=>{I=!0}},[rn]),q.useEffect(()=>{if(!Kn)return;let I=!1;return(async()=>{try{const H=await Kn.MListDecisionTables();if(!I){for(const Se of H)Wr.current.set(Se.id,Se);Y(H.map(Se=>({code:Se.id,label:Se.name})))}}catch{}})(),()=>{I=!0}},[Kn]),q.useEffect(()=>{const I=l?l.replace(/\/catalog\/palette\/?$/,""):s;if(!I)return;let H=!1;return(async()=>{try{const Se=await O6.MGetCatalog(I,Uo(void 0,{tenantId:c}));H||Ee(Se)}catch{H||Ee([])}})(),()=>{H=!0}},[l,s]),q.useEffect(()=>{var We,Ae,xt;if((qe==null?void 0:qe.data.nodeType)!=="decision-table"){ue(null),K({status:"idle"});return}if(!Kn){ue(null),K({status:"error",message:"No decision table API configured for this editor."});return}const I=((Ae=(We=qe.data.contractRef)==null?void 0:We.sourceCode)==null?void 0:Ae.trim())??((xt=qe.data.ruleCode)==null?void 0:xt.trim())??"";if(!I){ue(null),K({status:"idle"});return}const H=Wr.current.get(I);if(H){ue(H),K({status:"ready"}),Go(qe.id,H);return}let Se=!1;return K({status:"loading"}),(async()=>{try{const kt=await Kn.MGetDecisionTable(I);if(Se)return;Wr.current.set(I,kt),ue(kt),K({status:"ready"}),Go(qe.id,kt)}catch(kt){Se||(ue(null),K({status:"error",message:kt instanceof Error?kt.message:"Failed to load decision table metadata."}))}})(),()=>{Se=!0}},[Kn,qe==null?void 0:qe.id,qe==null?void 0:qe.data.nodeType,(mf=qe==null?void 0:qe.data.contractRef)==null?void 0:mf.sourceCode,qe==null?void 0:qe.data.ruleCode]),q.useEffect(()=>{if(!Wn){Ie([]),Pe(!1);return}let I=!1;return(async()=>{Pe(!0);try{const H=await Wn.MListCatalog();I||(Ie(H),Pe(!1))}catch{I||(Ie([]),Pe(!1))}})(),()=>{I=!0}},[Wn]),q.useEffect(()=>{if(!rn||!h)return;let I=!1;return(async()=>{var H,Se;await RL(rn,Xt.current,h);for(const We of mr.nodes){if(We.type==="trigger"||We.type==="end"||Jt.current.has(We.id))continue;const Ae=await WG(rn,h,We);Ae&&Jt.current.set(We.id,Ae)}for(const We of mr.nodes.filter(Ae=>Ae.type==="sub-flow")){const Ae=(H=fl(We.data.subFlowConfig).targetFlowCode)==null?void 0:H.trim();if(!Ae)continue;const xt=await RL(rn,Xt.current,Ae);if(I)return;const kt=await PL(rn,Ae,"trigger"),gn=(kt==null?void 0:kt.requestScope)??(xt==null?void 0:xt.requestContract),Ii=(Se=fl(We.data.subFlowConfig).childTriggerSchema)==null?void 0:Se.contractName;gn!=null&&gn.contractName&&Ii!==gn.contractName&&qo(We.id,ta=>({...ta,data:{...ta.data,subFlowConfig:{...fl(ta.data.subFlowConfig),childTriggerSchema:gn}}}),!1)}I||ri(We=>We+1)})(),()=>{I=!0}},[rn,mr.nodes,h]),q.useEffect(()=>{var H,Se;if(!qe){V({status:"idle"});return}Ln("inspector");const I=qe&&Jt.current.get(qe.id);if(I||(H=qe.data.contractLayer)!=null&&H.upstreamScope||qe.type==="trigger"||qe.type==="end"){V({status:"ready",title:(I==null?void 0:I.ruleCode)??((Se=qe.data.contractRef)==null?void 0:Se.label)??qe.data.label});return}V(rn?{status:"loading"}:{status:"error",message:"No contract API configured for this editor."})},[rn,qe,pr]),v==="unlicensed"){const I=uT();return C.jsxs("section",{style:{...iK,background:I.licenseBg,border:I.licenseBorder,color:I.licenseText},children:[C.jsx("strong",{children:"Rule Flow Designer requires a Muonroi commercial license."}),C.jsx("span",{children:"Load an activation proof before rendering this editor."})]})}function Ji(){cn.current!==null&&(window.clearTimeout(cn.current),cn.current=null)}function Lr(){Zt.current!==null&&(window.clearTimeout(Zt.current),Zt.current=null)}function es(I){Lr(),ht.current=!0,L(P(Zv(I))),j(Q(G5(I))),Zt.current=window.setTimeout(()=>{ht.current=!1,Zt.current=null},0)}function eo(I,H){var xt;Ji();const Se=Lp(I,{currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}),We=Ai(Se.graph),Ae=Yi(We);if(Tt.current=We.metadata,bt.current=Ae,es(We),H!=null&&H.syncViewport&&(Fe.current=!0,hr(kt=>kt+1)),Se.issues.length>0){const kt=((xt=Se.issues[0])==null?void 0:xt.message)??"Rule flow ordering is invalid.";V({status:"error",message:kt})}(H==null?void 0:H.pushHistory)!==!1&&R.commit(We),(H==null?void 0:H.notify)!==!1&&(e==null||e(We))}function ur(I,H,Se=!0){return{nodes:I.map(HG),edges:H.map(YG),metadata:{...Tt.current,version:Math.max(1,Tt.current.version??1),lastModifiedAt:Se?new Date().toISOString():Tt.current.lastModifiedAt}}}function qo(I,H,Se=!0){const We=Bt.current.map(xt=>xt.id===I?H(xt):xt),Ae=Lp(ur(We,Yt.current),{currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}).graph;Tt.current=Ae.metadata,bt.current=Yi(Ae),L(P(Zv(Ae))),Se&&(e==null||e(Ae))}function An(I,H="debounced"){if(t||!Z)return;const Se=Bt.current.map(Ae=>Ae.id===Z?I(Ae):Ae),We=Lp(ur(Se,Yt.current),{currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}).graph;if(Tt.current=We.metadata,bt.current=Yi(We),L(P(Zv(We))),e==null||e(We),H==="immediate"){R.commit(We);return}Ji(),cn.current=window.setTimeout(()=>{cn.current=null,R.commit(We)},300)}function qr(){t||!Z||(ee(""),W("basic-info"),eo(ur(Bt.current.filter(I=>I.id!==Z),Yt.current.filter(I=>I.source!==Z&&I.target!==Z))))}function zi(){t||!ie||(pe(""),eo(ur(Bt.current,Yt.current.filter(I=>I.id!==ie))))}function ts(I){if(t||!ie)return;const H=Yt.current.map(Se=>Se.id===ie?I(Se):Se);eo(ur(Bt.current,H),{syncViewport:!1})}function Co(I){ee(I),pe("");const H=Bt.current.find(Se=>Se.id===I);H&&W(Y5(H.data.nodeType)),Ln("inspector")}function Go(I,H){const Se=ML(H,"input"),We=ML(H,"output");qo(I,Ae=>{var xt;return{...Ae,data:{...Ae.data,description:(xt=Ae.data.description)!=null&&xt.trim()?Ae.data.description:H.description,requestContract:Se,responseContract:We,contractRef:{sourceType:"decision-table",sourceCode:H.id,label:H.name}}}},!1),ri(Ae=>Ae+1)}function ka(){const I=mT(ur(Bt.current,Yt.current));Fe.current=!0,eo(I,{syncViewport:!0})}function ns(I){const H=[...Yt.current];if(Z){const Se=`${Z}-${I.id}`;H.push({id:Se,source:Z,target:I.id,label:"always",data:{edgeType:"always"}}),pe(Se)}ee(I.id),pe(""),W(Y5(I.data.nodeType)),eo(mT(ur([...Bt.current,I],H)),{syncViewport:!0})}function to(I,H){if(t)return;const Se={id:`node-${I}-${Math.random().toString(36).slice(2,10)}`,type:I,position:H??{x:60+Bt.current.length*36,y:80+Bt.current.length%4*90},data:{label:X5[I],nodeType:I,expression:JC(I),conditionConfig:I==="condition"?{successLabel:"Valid",failureLabel:"Rejected"}:void 0,subFlowConfig:I==="sub-flow"?{targetFlowCode:"",inputMappings:[],outputMappings:[]}:void 0,liquidConfig:I==="liquid"?{outputFormat:"json"}:void 0}};ns(Se)}function hl(I,H){if(t)return;const Se={id:`node-rule-${Math.random().toString(36).slice(2,10)}`,type:"condition",position:H??{x:60+Bt.current.length*36,y:80+Bt.current.length%4*90},data:{label:I.displayName,nodeType:"condition",ruleCode:I.code,description:I.description,expression:JC("condition"),contractRef:{sourceType:"rule",sourceCode:I.code,label:I.displayName},requestContract:I.inputSchema,responseContract:I.outputSchema}};ns(Se)}function rs(){to("trigger",{x:200,y:180})}const tn=q.useRef(null),su=q.useCallback(I=>{pi.current=!0,tn.current={startX:I.clientX,startW:on},I.currentTarget.setPointerCapture(I.pointerId),I.preventDefault()},[on]),fn=q.useCallback(I=>{if(!pi.current||!tn.current)return;const H=tn.current.startW+(I.clientX-tn.current.startX);hi(Math.max(240,Math.min(400,H)))},[]),Ju=q.useCallback(I=>{pi.current&&(pi.current=!1,tn.current=null,I.currentTarget.releasePointerCapture(I.pointerId))},[]),Ca=typeof i=="number"?`${i}px`:i,Nt=un>0&&un<_L,lu=Nt?"min(52vh, 520px)":Ca,He=uT(),Ta={color:He.textPrimary},yi=C.jsxs("div",{"data-testid":"rule-flow-sidebar-palette",style:{...AL,...tK,...hK(),gap:8,padding:12},children:[Object.keys(pT).map(I=>C.jsxs("button",{type:"button",style:sK(I,He),"data-testid":`palette-${I}`,draggable:!t,onClick:()=>to(I),onDragStart:H=>As(H,I),disabled:t,children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[C.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:Iv[I],style:{flexShrink:0},children:C.jsx("path",{d:cT[I]})}),C.jsx("span",{style:{fontWeight:600},children:Mp[I]})]}),C.jsx("span",{style:{fontSize:11,color:He.textMuted,fontWeight:400},children:RG[I]})]},I)),l?C.jsx(pG,{groups:ze,loading:Be,readOnly:t,onAddRule:hl,onDragStart:(I,H)=>As(I,"condition",H)}):null]}),Ea=()=>{const I=document.createElement("input");I.type="file",I.accept="application/json,.json",I.style.position="fixed",I.style.top="-9999px",document.body.appendChild(I),I.addEventListener("change",()=>{var Se;const H=(Se=I.files)==null?void 0:Se[0];document.body.removeChild(I),H&&(async()=>{try{const We=await H.text(),Ae=Lp(j9(We),{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current}).graph;Tt.current=Ae.metadata,bt.current=Yi(Ae),R.reset(Ae),es(Ae),ee(""),pe(""),W("basic-info"),Fe.current=!0,hr(xt=>xt+1),e==null||e(Ae),V({status:"ready",title:Ae.metadata.ruleSetCode??"Imported flow"})}catch(We){V({status:"error",message:We.message})}})()}),I.click()},Hn=()=>KG(ur(Bt.current,Yt.current),Tt.current.ruleSetCode),Nn=()=>{const I=fT(ur(Bt.current,Yt.current),{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current});ri(H=>H+1),I.isValid?(V({status:"ready",title:`Valid — ${I.issues.filter(H=>H.severity==="warning").length} warning(s)`}),ut(`Validation passed with ${I.issues.filter(H=>H.severity==="warning").length} warning(s).`)):(V({status:"error",message:`${I.issues.filter(H=>H.severity==="error").length} error(s) found.`}),ut(`Validation complete: ${I.issues.filter(H=>H.severity==="error").length} error(s), ${I.issues.filter(H=>H.severity==="warning").length} warning(s).`))},Rs=()=>{const I=fT(ur(Bt.current,Yt.current),{flowCode:h,currentFlowContract:h?Xt.current.get(h):void 0,flowContractsByCode:Xt.current,nodeContractsById:Jt.current});if(ri(H=>H+1),!I.isValid){V({status:"error",message:"Publish blocked because one or more nodes still have contract validation errors."}),At("Publish blocked: one or more nodes still have contract validation errors.");return}rt({graph:I.graph,warnings:I.issues.filter(H=>H.severity==="warning")})},wr=I=>C.jsxs("button",{type:"button",style:I?{...vT,display:"flex",alignItems:"center",gap:5,visibility:jt?"hidden":void 0}:{...wa(!0),display:jt?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:()=>{Rs(),I&&setTimeout(()=>er(!1),0)},disabled:!ko,title:m?Dr.length>0?"Fix validation errors before publishing.":"Publish":"No publish handler configured.","aria-disabled":!ko,children:[C.jsx(df,{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"]}),ii=I=>C.jsxs("button",{type:"button",style:I?{...vT,display:"flex",alignItems:"center",gap:5,visibility:jt?"hidden":void 0}:{...wa(!1),display:jt?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},disabled:an,onClick:()=>{Ea(),I&&setTimeout(()=>er(!1),0)},title:"Import",children:[C.jsx(df,{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"]}),no=I=>C.jsxs("button",{type:"button",style:I?{...vT,display:"flex",alignItems:"center",gap:5}:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Hn(),I&&setTimeout(()=>er(!1),0)},title:"Export",children:[C.jsx(df,{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"]}),pl=C.jsxs("div",{"data-testid":"rule-flow-sidebar-actions",style:{display:"flex",flexDirection:"column",gap:8},ref:Gi,children:[Ki.issues.length>0?C.jsxs("div",{style:oK(Dr.length>0),children:[C.jsx("strong",{children:Dr.length>0?"Publish blocked":"Publish warnings"}),C.jsxs("span",{children:[Dr.length," error(s) / ",_s.length," warning(s)"]}),Dr.length>0?C.jsxs("ul",{style:{margin:"6px 0 0",padding:"0 0 0 16px",fontSize:12,lineHeight:1.5},children:[Dr.slice(0,20).map((I,H)=>C.jsxs("li",{style:{marginBottom:2},children:[C.jsx("code",{style:{fontSize:11,fontWeight:600},children:I.code}),I.nodeId?C.jsxs("span",{style:{color:"var(--mu-text-muted)"},children:[" [",I.nodeId,"]"]}):null," ",I.message]},H)),Dr.length>20?C.jsxs("li",{children:["...and ",Dr.length-20," more"]}):null]}):null]}):null,C.jsxs("div",{style:{display:"flex",alignItems:"center",flexWrap:"wrap",gap:"var(--mu-space-xs)"},children:[C.jsxs("div",{"data-testid":"toolbar-group-history",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[C.jsx("button",{type:"button",onClick:()=>So("history"),style:gT(He),title:Ar("history")?"Expand History":"Collapse History",children:Ar("history")?"History ▸":"History ▾"}),Ar("history")?null:C.jsxs(C.Fragment,{children:[C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Ji(),R.undo()},disabled:an||!R.canUndo,title:"Undo (Ctrl+Z)",children:[C.jsx(df,{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"]}),C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:64},onClick:()=>{Ji(),R.redo()},disabled:an||!R.canRedo,title:"Redo (Ctrl+Shift+Z)",children:[C.jsx(df,{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"]})]})]}),C.jsx("div",{style:{width:1,height:24,background:He.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),C.jsxs("div",{"data-testid":"toolbar-group-canvas",style:{display:"flex",alignItems:"center",gap:"var(--mu-space-xs)"},children:[C.jsx("button",{type:"button",onClick:()=>So("canvas"),style:gT(He),title:Ar("canvas")?"Expand Canvas":"Collapse Canvas",children:Ar("canvas")?"Canvas ▸":"Canvas ▾"}),Ar("canvas")?null:C.jsxs(C.Fragment,{children:[C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:96},onClick:ka,disabled:an,title:"Auto Layout",children:[C.jsx(df,{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"]}),C.jsxs("button",{type:"button",style:{...wa(!1),display:jt?"none":"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:80},onClick:Nn,disabled:an,title:"Validate",children:[C.jsx(df,{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"]}),C.jsxs("button",{type:"button",style:{...wa(!1),display:"inline-flex",alignItems:"center",gap:5,flex:"1 1 auto",minWidth:72},onClick:Kt,disabled:!s||!h,title:"Dry Run",children:[C.jsx(df,{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"]})]})]}),C.jsx("div",{style:{width:1,height:24,background:He.sidebarBorder,margin:"0 var(--mu-space-sm)",flexShrink:0}}),Ka?C.jsxs("div",{style:{position:"relative"},ref:mi,children:[C.jsx("button",{type:"button",onClick:()=>er(I=>!I),style:{...wa(!1),minWidth:32,padding:"6px 8px",fontSize:16},title:"More actions","aria-label":"More actions",children:"⋮"}),Cr?C.jsxs("div",{style:{position:"absolute",top:"100%",right:0,marginTop:4,background:He.overlayBg,border:He.overlayBorder,borderRadius:10,boxShadow:He.overlayShadow,padding:"4px 0",minWidth:140,zIndex:10},children:[wr(!0),ii(!0),no(!0)]}):null]}):C.jsxs("div",{"data-testid":"toolbar-group-workflow",style:{display:"flex",alignItems:"center",gap:4},children:[C.jsx("button",{type:"button",onClick:()=>So("workflow"),style:gT(He),title:Ar("workflow")?"Expand Workflow":"Collapse Workflow",children:Ar("workflow")?"Workflow ▸":"Workflow ▾"}),Ar("workflow")?null:C.jsxs(C.Fragment,{children:[wr(),ii(),no()]})]})]})]}),ec=C.jsx("div",{"data-testid":"rule-flow-sidebar-inspector",style:{...AL,...nK,...pK()},children:qe?C.jsx(Zq,{selectedNode:{id:qe.id,data:qe.data},selectedExpression:Ja,contractLoadState:le,selectedDecisionTable:G,decisionTableLoadState:F,readOnly:an,apiBaseUrl:s,inspectorTab:oe,flowOptions:se,decisionTableOptions:ae,setInspectorTab:W,onSelectNodeByRuleCode:I=>{const H=Bt.current.find(Se=>Se.data.ruleCode===I);H&&Co(H.id)},onUpdateLabel:I=>An(H=>({...H,data:{...H.data,label:I}})),onUpdateRuleCode:I=>An(H=>({...H,data:{...H.data,ruleCode:I,contractRef:H5(H.data.nodeType,I,H.data.contractRef)}})),onUpdateDescription:I=>An(H=>({...H,data:{...H.data,description:I}})),onUpdateContractRef:I=>An(H=>({...H,data:{...H.data,contractRef:I,requestContract:void 0,responseContract:void 0}})),onUpdateDecisionTableCode:I=>An(H=>{var Se;return{...H,data:{...H.data,ruleCode:I,requestContract:void 0,responseContract:void 0,contractRef:I.trim()?{sourceType:"decision-table",sourceCode:I.trim(),label:((Se=ae.find(We=>We.code===I.trim()))==null?void 0:Se.label)??I.trim()}:H.data.contractRef}}}),onUpdateConditionConfig:I=>An(H=>({...H,data:{...H.data,conditionConfig:I}})),onUpdateTargetFlowCode:I=>An(H=>({...H,data:{...H.data,contractRef:I.trim()?{sourceType:"flow",sourceCode:I.trim(),label:I.trim()}:H.data.contractRef,subFlowConfig:{...fl(H.data.subFlowConfig),targetFlowCode:I}}})),onUpdateLiquidOutput:I=>An(H=>({...H,data:{...H.data,liquidConfig:{...W5(H.data.liquidConfig),outputFormat:I}}})),onUpdateExpressionLanguage:I=>An(H=>({...H,data:{...H.data,expression:{...iu(H.data),language:I}}})),onUpdateExpressionBody:I=>An(H=>({...H,data:{...H.data,expression:{...iu(H.data),body:I}}})),onInsertExpressionToken:I=>{Gn.current?Gn.current.insert(I):An(H=>({...H,data:{...H.data,expression:{...iu(H.data),body:`${iu(H.data).body}${iu(H.data).body.trim()?" ":""}${I}`}}}))},onChangeInputContract:I=>An(H=>({...H,data:{...H.data,contractOverride:{...H.data.contractOverride,requestFields:I}}})),onChangeEffectiveMappings:I=>An(H=>({...H,data:{...H.data,inputMappings:H.data.nodeType==="action"?I.map(Se=>({id:Se.id,sourcePath:Se.sourcePath,targetPath:Se.targetField??Se.targetPath,transform:Se.transform,language:Se.language})):H.data.inputMappings,subFlowConfig:H.data.nodeType==="sub-flow"?{...fl(H.data.subFlowConfig),inputMappings:I.map(Se=>({id:Se.id,sourcePath:Se.sourcePath,targetPath:Se.targetField??Se.targetPath,transform:Se.transform,language:Se.language}))}:H.data.subFlowConfig,contractLayer:H.data.contractLayer}})),onChangeOutputContract:I=>An(H=>({...H,data:{...H.data,contractOverride:{...H.data.contractOverride,responseFields:I.filter(Se=>!Se.isResultPayload)}}}),"immediate"),onDeleteNode:qr,connectorCatalog:Te,onUpdateConnectorConfig:I=>An(H=>({...H,data:{...H.data,connectorConfig:I}})),onSetInsertRef:I=>{Gn.current=I},shadowRoot:E instanceof ShadowRoot?E:void 0,showSectionHeader:!1}):C.jsx(JG,{selectedEdge:vi,readOnly:t,onUpdateEdgeType:I=>ts(H=>({...H,label:I,data:{...H.data??{},edgeType:I}})),onDeleteEdge:zi})}),is=s?s.includes("localhost")||s.includes("127.0.0.1")?"DEV":"PROD":null,[Ps,ml]=q.useState(!1),[Ld,Ni]=q.useState(!1),[To,Ko]=q.useState(!1),[ro,Ms]=q.useState("{}"),[_a,Jo]=q.useState(null),[ea,gl]=q.useState(!1),[vl,ji]=q.useState(null),[z,te]=q.useState(40),Oe=q.useRef(!1),[ke,Xe]=q.useState(new Set),[St,Ye]=q.useState(null);function Rt(){var We,Ae;const I=mr.nodes.find(xt=>xt.type==="trigger"),H=((We=I==null?void 0:I.data.requestContract)==null?void 0:We.fields)??((Ae=I==null?void 0:I.data.contractOverride)==null?void 0:Ae.requestFields);if(!H||H.length===0)return"{}";const Se={};for(const xt of H){const kt=(xt.dataType??"").toLowerCase();kt.includes("int")||kt.includes("number")||kt.includes("decimal")||kt.includes("float")||kt.includes("double")?Se[xt.path]=0:kt.includes("bool")?Se[xt.path]=!1:kt.includes("array")||kt.includes("list")?Se[xt.path]=[]:kt.includes("object")||kt.includes("map")||kt.includes("dict")?Se[xt.path]={}:Se[xt.path]=""}return JSON.stringify(Se,null,2)}function Kt(){Ko(!0),Jo(null),ji(null),Ms(Rt())}async function dn(){if(!(!s||!h)){gl(!0),ji(null),Jo(null);try{const I=s.replace(/\/$/,""),H=Uo(void 0,{tenantId:c});H.set("Content-Type","application/json");const Se=x!=null?`?version=${x}`:"",We=await fetch(`${I}/execute/${encodeURIComponent(h)}${Se}`,{method:"POST",headers:H,body:ro});if(!We.ok){const xt=await We.text();throw new Error(`Execution failed (${We.status}): ${xt}`)}const Ae=await We.json();Jo(Ae),jn(Ae)}catch(I){ji(I instanceof Error?I.message:"Unknown error")}finally{gl(!1)}}}function Un(I){const H=new Set;for(const Se of Object.keys(I)){const We=Se.match(/^__graph\.node\.(.+?)\.executed$/);We&&I[Se]===!0&&H.add(We[1])}return H}function jn(I){const H=Un(I.factBag);if(H.size===0)for(const We of I.results)H.add(We.ruleName);if(H.size>0){const We=new Map;for(const Ae of Bt.current)We.set(Ae.id,Ae.data.nodeType);for(const[Ae,xt]of We)xt==="trigger"&&H.add(Ae),xt==="end"&&I.isSuccess&&H.add(Ae)}Xe(H);const Se=new Map(I.results.map(We=>[We.ruleName,We]));L(We=>We.map(Ae=>{const xt=Ae.data.ruleCode||Ae.data.label,kt=H.has(Ae.id)||H.has(xt),gn=Se.get(xt);if(!kt)return{...Ae,style:{...Ae.style,opacity:.35,transition:"all 300ms ease",filter:"grayscale(0.5)"},className:""};const Ii=I.factBag[`__graph.node.${Ae.id}.passed`],ta=Ii!==void 0?Ii===!0:(gn==null?void 0:gn.isSuccess)??!0,as=ta?"var(--mu-color-success)":"var(--mu-color-error)",Np=ta?"color-mix(in oklch, var(--mu-color-success) 6%, transparent)":"color-mix(in oklch, var(--mu-color-error) 6%, transparent)";return{...Ae,style:{...Ae.style,opacity:1,background:Np,border:"none",borderLeft:`4px solid ${as}`,borderRadius:8,boxShadow:"none",transition:"all 300ms ease",filter:"none"},className:""}})),j(We=>We.map(Ae=>{const xt=Bt.current.find(as=>as.id===Ae.source),kt=Bt.current.find(as=>as.id===Ae.target),gn=(xt==null?void 0:xt.data.ruleCode)||(xt==null?void 0:xt.data.label)||Ae.source,Ii=(kt==null?void 0:kt.data.ruleCode)||(kt==null?void 0:kt.data.label)||Ae.target;return(H.has(Ae.source)||H.has(gn))&&(H.has(Ae.target)||H.has(Ii))?{...Ae,style:{...Ae.style,strokeWidth:3,opacity:1,transition:"all 300ms ease"}}:{...Ae,style:{...Ae.style,strokeWidth:1,opacity:.35,transition:"all 300ms ease"}}}))}function qt(){L(I=>I.map(H=>({...H,style:void 0,className:""}))),j(I=>Q(I.map(H=>({...H,style:void 0})))),Xe(new Set),Ye(null)}function Qn(){Ko(!1),Jo(null),ji(null),qt()}function ir(I,H){if(!_a||ke.size===0)return;const Se=H.data.ruleCode||H.data.label;(ke.has(H.id)||ke.has(Se))&&Ye({nodeId:Se,mousePos:{x:I.clientX,y:I.clientY}})}function $s(){Ye(null)}function tc(I){var kt;I.preventDefault(),Oe.current=!0;const H=I.clientY,Se=z,We=(kt=Di.current)==null?void 0:kt.getBoundingClientRect();if(!We)return;const Ae=gn=>{if(!Oe.current)return;const ta=(H-gn.clientY)/We.height*100,as=Math.min(70,Math.max(20,Se+ta));te(as)},xt=()=>{Oe.current=!1,document.removeEventListener("pointermove",Ae),document.removeEventListener("pointerup",xt)};document.addEventListener("pointermove",Ae),document.addEventListener("pointerup",xt)}return C.jsxs(p$,{children:[C.jsx(ZG,{politeMessage:dt,assertiveMessage:et}),y?C.jsxs("header",{style:{...CK,background:He.sidebarBg,borderBottom:He.sidebarBorder,color:He.textPrimary},children:[C.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"var(--mu-space-sm)"},children:[C.jsx("strong",{style:{fontSize:14},children:"Rule Studio"}),h?C.jsx("span",{style:{...Ku,background:He.actionPrimaryBg,border:He.actionPrimaryBorder,color:He.textPrimary},children:h}):null,Qr.length>0?C.jsx(w6,{versions:Qr,activeVersion:Lt,selectedVersion:x??null,onSelect:I=>S==null?void 0:S(I),onLoadMore:Zn,hasMore:Ge,loadingMore:Ut,tokens:He}):x!=null?C.jsxs("span",{style:{...Ku,background:He.actionPrimaryBg,border:He.actionPrimaryBorder,color:He.textPrimary,fontSize:11},children:["v",x]}):C.jsx("span",{style:{...Ku,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"}),Qr.length>1?C.jsx("span",{role:"button",tabIndex:0,style:{...Ku,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:()=>Ni(!0),onKeyDown:I=>{I.key==="Enter"&&Ni(!0)},children:"Compare"}):null,is?C.jsx("span",{style:{...Ku,background:is==="DEV"?"var(--mu-color-warning-bg)":"var(--mu-color-success-bg)",border:is==="DEV"?"1px solid var(--mu-color-warning-border)":"1px solid var(--mu-color-success-border)",color:is==="DEV"?He.warningText:"var(--mu-color-success-text)",fontSize:10,fontWeight:700},children:is}):null,an?C.jsx("span",{style:{...Ku,background:He.errorBg,border:He.errorBorder,color:He.errorText,fontSize:10,fontWeight:700},children:"READ-ONLY"}):null,(()=>{var Se;const I=x!=null?Qr.find(We=>We.version===x):Lt,H=(Se=I==null?void 0:I.status)==null?void 0:Se.toLowerCase();return H==="pendingapproval"?C.jsx("span",{style:{...Ku,background:"var(--mu-color-warning-bg)",border:"1px solid var(--mu-color-warning-border)",color:He.warningText,fontSize:10,fontWeight:700},children:"PENDING APPROVAL"}):H==="rejected"?C.jsx("span",{style:{...Ku,background:He.errorBg,border:He.errorBorder,color:He.errorText,fontSize:10,fontWeight:700},children:"REJECTED"}):H==="approved"&&!(I!=null&&I.isActive)?C.jsx("span",{style:{...Ku,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})()]}),C.jsxs("div",{style:{position:"relative"},children:[C.jsx("button",{type:"button",style:{background:"transparent",border:"none",cursor:"pointer",padding:4,color:He.textMuted,fontSize:16},onClick:()=>ml(I=>!I),title:"Technical details",children:C.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:"currentColor",children:C.jsx("path",{d:"M7.5 1.5a6 6 0 100 12 6 6 0 000-12zM7 5h1v1H7V5zm0 2h1v4H7V7z"})})}),Ps?C.jsxs("div",{style:{...TK,background:He.dialogBg,border:He.dialogBorder,boxShadow:He.dialogShadow,color:He.textSecondary},children:[c?C.jsxs("span",{style:{fontSize:11},children:["Tenant: ",c]}):null,s?C.jsxs("span",{style:{fontSize:11,wordBreak:"break-all"},children:["API: ",s]}):null,!c&&!s?C.jsx("span",{style:{fontSize:11},children:"No API configured"}):null]}):null]})]}):null,jt?C.jsxs("div",{style:{padding:"8px 16px",background:"var(--mu-color-warning-bg)",borderBottom:"1px solid var(--mu-color-warning-border)",color:He.warningText,fontSize:12,display:"flex",alignItems:"center",gap:8},children:[C.jsx("svg",{width:14,height:14,viewBox:"0 0 16 16",fill:"currentColor",children:C.jsx("path",{d:"M8 1l7 14H1L8 1zm-.5 5v4h1V6h-1zm0 5v1h1v-1h-1z"})}),C.jsxs("span",{children:["Viewing version v",x," (read-only)"]}),C.jsxs("div",{style:{marginLeft:"auto",display:"flex",gap:6},children:[C.jsx("button",{type:"button",onClick:()=>{if(!s||!h||x==null)return;const I=s.replace(/\/$/,""),H=Uo(void 0,{tenantId:c});H.set("Content-Type","application/json"),fetch(`${I}/rulesets/${encodeURIComponent(h)}/versions`,{method:"POST",headers:H,body:JSON.stringify({sourceVersion:x})}).then(Se=>{if(!Se.ok)throw new Error("restore failed");return Se.json()}).then(Se=>{$e(0),mn(0,!1),Se.version!=null&&(S==null||S(Se.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"}),C.jsx("button",{type:"button",onClick:()=>S==null?void 0:S(null),style:{fontSize:11,padding:"4px 12px",borderRadius:6,fontWeight:600,cursor:"pointer",background:He.actionPrimaryBg,border:He.actionPrimaryBorder,color:He.textPrimary},children:"Back to Active"})]})]}):null,C.jsxs("section",{ref:di,style:{...eK,...lK(Nt,!!(qe||vi),on,$n),...Ta},children:[C.jsxs("aside",{"data-testid":"rule-flow-left-panel",style:{...uK,background:He.sidebarBg,border:He.sidebarBorder,width:$n?48:on,transition:pi.current?"none":"width 200ms ease",overflow:$n?"hidden":"auto",position:"relative"},children:[C.jsxs("div",{style:{padding:"var(--mu-space-sm)",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[!$n&&C.jsx("strong",{style:{fontSize:"var(--mu-text-sm)",fontWeight:"var(--mu-font-semibold)",color:He.textPrimary},children:"Node Library"}),C.jsx("button",{type:"button",title:$n?"Expand Node Library":"Collapse Node Library",onClick:()=>Li(I=>!I),style:{background:"transparent",border:"none",cursor:"pointer",padding:4,borderRadius:6,fontSize:14,color:He.textMuted,lineHeight:1,marginLeft:$n?"auto":void 0,marginRight:$n?"auto":void 0},children:$n?"›":"«"})]}),$n?C.jsx("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:4,padding:"8px 0"},children:Object.keys(pT).map(I=>C.jsx("div",{title:Mp[I],style:{width:32,height:32,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",cursor:"default",fontSize:16},children:C.jsx("svg",{width:16,height:16,viewBox:"0 0 16 16",fill:Iv[I],style:{flexShrink:0},children:C.jsx("path",{d:cT[I]})})},I))}):yi,!$n&&C.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:su,onPointerMove:fn,onPointerUp:Ju,children:C.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:I=>{I.currentTarget.style.background="color-mix(in oklch, var(--mu-color-interactive) 15%, transparent)"},onPointerLeave:I=>{I.currentTarget.style.background="transparent"},children:[0,1,2].map(I=>C.jsx("div",{style:{width:4,height:4,borderRadius:"50%",background:"var(--mu-color-border-subtle, var(--mu-text-muted))"}},I))})})]}),C.jsxs("div",{ref:Di,style:{...rK,...dK(Nt),height:lu,background:He.canvasGradient,display:"flex",flexDirection:"column"},"data-testid":"rule-flow-canvas","data-node-count":A.length,"data-edge-count":B.length,onDragOver:zd,onDrop:pf,children:[C.jsx("style",{children:`
355
355
  .mu-node-running {
356
356
  animation: muNodePulse 0.8s ease-in-out infinite;
357
357
  }