@curie-agent/daemon 0.3.7 → 0.3.8

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.
@@ -109,8 +109,8 @@ ${this.parser.parse(e)}</blockquote>
109
109
  ${e}</tr>
110
110
  `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
111
111
  `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${mn(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let l=this.parser.parseInline(n),a=Ig(e);if(a===null)return l;e=a;let s='<a href="'+e+'"';return t&&(s+=' title="'+mn(t)+'"'),s+=">"+l+"</a>",s}image({href:e,title:t,text:n,tokens:l}){l&&(n=this.parser.parseInline(l,this.parser.textRenderer));let a=Ig(e);if(a===null)return mn(n);e=a;let s=`<img src="${e}" alt="${mn(n)}"`;return t&&(s+=` title="${mn(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:mn(e.text)}},Rh=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},ln=class lf{constructor(t){fe(this,"options");fe(this,"renderer");fe(this,"textRenderer");this.options=t||ba,this.options.renderer=this.options.renderer||new Zo,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Rh}static parse(t,n){return new lf(n).parse(t)}static parseInline(t,n){return new lf(n).parseInline(t)}parse(t){var l,a;this.renderer.parser=this;let n="";for(let s=0;s<t.length;s++){let i=t[s];if((a=(l=this.options.extensions)==null?void 0:l.renderers)!=null&&a[i.type]){let c=i,u=this.options.extensions.renderers[c.type].call({parser:this},c);if(u!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(c.type)){n+=u||"";continue}}let r=i;switch(r.type){case"space":{n+=this.renderer.space(r);break}case"hr":{n+=this.renderer.hr(r);break}case"heading":{n+=this.renderer.heading(r);break}case"code":{n+=this.renderer.code(r);break}case"table":{n+=this.renderer.table(r);break}case"blockquote":{n+=this.renderer.blockquote(r);break}case"list":{n+=this.renderer.list(r);break}case"checkbox":{n+=this.renderer.checkbox(r);break}case"html":{n+=this.renderer.html(r);break}case"def":{n+=this.renderer.def(r);break}case"paragraph":{n+=this.renderer.paragraph(r);break}case"text":{n+=this.renderer.text(r);break}default:{let c='Token with "'+r.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return n}parseInline(t,n=this.renderer){var a,s;this.renderer.parser=this;let l="";for(let i=0;i<t.length;i++){let r=t[i];if((s=(a=this.options.extensions)==null?void 0:a.renderers)!=null&&s[r.type]){let u=this.options.extensions.renderers[r.type].call({parser:this},r);if(u!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(r.type)){l+=u||"";continue}}let c=r;switch(c.type){case"escape":{l+=n.text(c);break}case"html":{l+=n.html(c);break}case"link":{l+=n.link(c);break}case"image":{l+=n.image(c);break}case"checkbox":{l+=n.checkbox(c);break}case"strong":{l+=n.strong(c);break}case"em":{l+=n.em(c);break}case"codespan":{l+=n.codespan(c);break}case"br":{l+=n.br(c);break}case"del":{l+=n.del(c);break}case"text":{l+=n.text(c);break}default:{let u='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(u),"";throw new Error(u)}}}return l}},Qr,Is=(Qr=class{constructor(e){fe(this,"options");fe(this,"block");this.options=e||ba}preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?nn.lex:nn.lexInline}provideParser(e=this.block){return e?ln.parse:ln.parseInline}},fe(Qr,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens","emStrongMask"])),fe(Qr,"passThroughHooksRespectAsync",new Set(["preprocess","postprocess","processAllTokens"])),Qr),bj=class{constructor(...e){fe(this,"defaults",Eh());fe(this,"options",this.setOptions);fe(this,"parse",this.parseMarkdown(!0));fe(this,"parseInline",this.parseMarkdown(!1));fe(this,"Parser",ln);fe(this,"Renderer",Zo);fe(this,"TextRenderer",Rh);fe(this,"Lexer",nn);fe(this,"Tokenizer",Qo);fe(this,"Hooks",Is);this.use(...e)}walkTokens(e,t){var l,a;let n=[];for(let s of e)switch(n=n.concat(t.call(this,s)),s.type){case"table":{let i=s;for(let r of i.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of i.rows)for(let c of r)n=n.concat(this.walkTokens(c.tokens,t));break}case"list":{let i=s;n=n.concat(this.walkTokens(i.items,t));break}default:{let i=s;(a=(l=this.defaults.extensions)==null?void 0:l.childTokens)!=null&&a[i.type]?this.defaults.extensions.childTokens[i.type].forEach(r=>{let c=i[r].flat(1/0);n=n.concat(this.walkTokens(c,t))}):i.tokens&&(n=n.concat(this.walkTokens(i.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let l={...n};if(l.async=this.defaults.async||l.async||!1,n.extensions&&(n.extensions.forEach(a=>{if(!a.name)throw new Error("extension name required");if("renderer"in a){let s=t.renderers[a.name];s?t.renderers[a.name]=function(...i){let r=a.renderer.apply(this,i);return r===!1&&(r=s.apply(this,i)),r}:t.renderers[a.name]=a.renderer}if("tokenizer"in a){if(!a.level||a.level!=="block"&&a.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let s=t[a.level];s?s.unshift(a.tokenizer):t[a.level]=[a.tokenizer],a.start&&(a.level==="block"?t.startBlock?t.startBlock.push(a.start):t.startBlock=[a.start]:a.level==="inline"&&(t.startInline?t.startInline.push(a.start):t.startInline=[a.start]))}"childTokens"in a&&a.childTokens&&(t.childTokens[a.name]=a.childTokens)}),l.extensions=t),n.renderer){let a=this.defaults.renderer||new Zo(this.defaults);for(let s in n.renderer){if(!(s in a))throw new Error(`renderer '${s}' does not exist`);if(["options","parser"].includes(s))continue;let i=s,r=n.renderer[i],c=a[i];a[i]=(...u)=>{let d=r.apply(a,u);return d===!1&&(d=c.apply(a,u)),d||""}}l.renderer=a}if(n.tokenizer){let a=this.defaults.tokenizer||new Qo(this.defaults);for(let s in n.tokenizer){if(!(s in a))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;let i=s,r=n.tokenizer[i],c=a[i];a[i]=(...u)=>{let d=r.apply(a,u);return d===!1&&(d=c.apply(a,u)),d}}l.tokenizer=a}if(n.hooks){let a=this.defaults.hooks||new Is;for(let s in n.hooks){if(!(s in a))throw new Error(`hook '${s}' does not exist`);if(["options","block"].includes(s))continue;let i=s,r=n.hooks[i],c=a[i];Is.passThroughHooks.has(s)?a[i]=u=>{if(this.defaults.async&&Is.passThroughHooksRespectAsync.has(s))return(async()=>{let f=await r.call(a,u);return c.call(a,f)})();let d=r.call(a,u);return c.call(a,d)}:a[i]=(...u)=>{if(this.defaults.async)return(async()=>{let f=await r.apply(a,u);return f===!1&&(f=await c.apply(a,u)),f})();let d=r.apply(a,u);return d===!1&&(d=c.apply(a,u)),d}}l.hooks=a}if(n.walkTokens){let a=this.defaults.walkTokens,s=n.walkTokens;l.walkTokens=function(i){let r=[];return r.push(s.call(this,i)),a&&(r=r.concat(a.call(this,i))),r}}this.defaults={...this.defaults,...l}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return nn.lex(e,t??this.defaults)}parser(e,t){return ln.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let l={...n},a={...this.defaults,...l},s=this.onError(!!a.silent,!!a.async);if(this.defaults.async===!0&&l.async===!1)return s(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return s(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return s(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(a.hooks&&(a.hooks.options=a,a.hooks.block=e),a.async)return(async()=>{let i=a.hooks?await a.hooks.preprocess(t):t,r=await(a.hooks?await a.hooks.provideLexer(e):e?nn.lex:nn.lexInline)(i,a),c=a.hooks?await a.hooks.processAllTokens(r):r;a.walkTokens&&await Promise.all(this.walkTokens(c,a.walkTokens));let u=await(a.hooks?await a.hooks.provideParser(e):e?ln.parse:ln.parseInline)(c,a);return a.hooks?await a.hooks.postprocess(u):u})().catch(s);try{a.hooks&&(t=a.hooks.preprocess(t));let i=(a.hooks?a.hooks.provideLexer(e):e?nn.lex:nn.lexInline)(t,a);a.hooks&&(i=a.hooks.processAllTokens(i)),a.walkTokens&&this.walkTokens(i,a.walkTokens);let r=(a.hooks?a.hooks.provideParser(e):e?ln.parse:ln.parseInline)(i,a);return a.hooks&&(r=a.hooks.postprocess(r)),r}catch(i){return s(i)}}}onError(e,t){return n=>{if(n.message+=`
112
- Please report this to https://github.com/markedjs/marked.`,e){let l="<p>An error occurred:</p><pre>"+mn(n.message+"",!0)+"</pre>";return t?Promise.resolve(l):l}if(t)return Promise.reject(n);throw n}}},ua=new bj;function ve(e,t){return ua.parse(e,t)}ve.options=ve.setOptions=function(e){return ua.setOptions(e),ve.defaults=ua.defaults,Mv(ve.defaults),ve};ve.getDefaults=Eh;ve.defaults=ba;ve.use=function(...e){return ua.use(...e),ve.defaults=ua.defaults,Mv(ve.defaults),ve};ve.walkTokens=function(e,t){return ua.walkTokens(e,t)};ve.parseInline=ua.parseInline;ve.Parser=ln;ve.parser=ln.parse;ve.Renderer=Zo;ve.TextRenderer=Rh;ve.Lexer=nn;ve.lexer=nn.lex;ve.Tokenizer=Qo;ve.Hooks=Is;ve.parse=ve;ve.options;ve.setOptions;ve.use;ve.walkTokens;ve.parseInline;ln.parse;nn.lex;function Fg(e){return e<1e3?String(e):`${(e/1e3).toFixed(1)}k`}function wj({onSend:e,onCancel:t,cmdInput:n,onClearCmdInput:l,totalTokens:a,contextTokens:s,costUsd:i}){const{providers:r,get:c}=kh(),u=c("current_provider"),d=c("model"),f=r.find(g=>g.name===u&&g.configured)||r.find(g=>g.configured)||{name:"none"},[h,p]=b.useState(""),x=b.useRef(null);b.useEffect(()=>{n&&(p(n),setTimeout(()=>{x.current&&(x.current.focus(),x.current.selectionStart=x.current.selectionEnd=n.length)},50),l==null||l())},[n,l]);const S=b.useCallback(()=>{const g=x.current;g&&(g.style.height="",g.style.height=Math.min(g.scrollHeight,160)+"px")},[]),w=b.useCallback(g=>{if(g.key==="Enter"&&!g.shiftKey){g.preventDefault();const y=h.trim();if(!y)return;e(y),p(""),setTimeout(()=>{x.current&&(x.current.style.height="")},0)}},[h,e]);return o.jsx("div",{className:"px-5 pt-3 pb-7 md:pb-3 bg-transparent",children:o.jsxs("div",{className:"glass-card rounded-xl transition-all duration-200",style:{background:"linear-gradient(135deg, var(--s2) 0%, color-mix(in srgb, var(--s1) 90%, var(--wood)) 100%)",border:"1px solid var(--b2)"},children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-[10.5px]",children:[o.jsx("span",{className:"w-[6px] h-[6px] rounded-full shrink-0",style:{background:u?"var(--green)":"var(--muted2)",opacity:u?1:.3}}),o.jsx("span",{style:{color:"var(--gold)",opacity:.8},children:f.name}),o.jsx("span",{className:"text-muted",children:" · "}),o.jsx("span",{className:"text-muted",children:d||"no model set"})]}),o.jsx("textarea",{ref:x,className:"w-full bg-transparent border-0 outline-none text-fg font-sans text-[13.5px] px-3.5 py-2.5 resize-none leading-[1.5]",style:{color:"var(--cream)"},rows:1,placeholder:"Message curie-agent...",value:h,onChange:g=>{p(g.target.value),S()},onKeyDown:w}),o.jsxs("div",{className:"flex items-center px-3 pb-2.5 pt-1",children:[a!==void 0?o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"text-[10px] text-muted font-mono",style:{opacity:.6},children:[Fg(a)," tokens"]}),o.jsx("span",{className:"opacity-30 mx-1",children:" · "}),o.jsxs("span",{className:"text-[10px] text-muted font-mono",style:{opacity:.6},children:["ctx ",Fg(s??0)]}),o.jsx("span",{className:"opacity-30 mx-1",children:" · "}),o.jsxs("span",{className:"text-[10px] text-muted font-mono",style:{color:"var(--green)",opacity:.6},children:["$",(i??0).toFixed(4)]}),o.jsx("div",{className:"flex-1"})]}):null,t?o.jsx("button",{className:"w-8 h-8 flex items-center justify-center cursor-pointer transition-all duration-200 hover:scale-105 active:scale-95 rounded-lg",style:{background:"var(--red)",color:"#fff"},onClick:t,title:"Stop agent",children:o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1.5"})})}):o.jsx("button",{className:"btn-gold rounded-lg w-8 h-8 flex items-center justify-center cursor-pointer transition-all duration-200 hover:scale-105 active:scale-95",onClick:()=>{const g=h.trim();g&&(e(g),p(""))},children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#1a1410",strokeWidth:"2.5",children:[o.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),o.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})})}const Sj=["line","area","bar","stacked-bar","scatter"];function Nj(e){if(!e||typeof e!="object")return!1;const t=e;if(typeof t.type!="string"||!Sj.includes(t.type)||typeof t.title!="string"||t.title.length===0||t.normalize!==void 0&&typeof t.normalize!="boolean"||!Array.isArray(t.series)||t.series.length===0)return!1;for(const n of t.series){if(!n||typeof n!="object")return!1;const l=n;if(typeof l.name!="string"||!Array.isArray(l.points)||l.points.length===0)return!1;for(const a of l.points){if(!a||typeof a!="object")return!1;const s=a;if(typeof s.x!="string"&&typeof s.x!="number"||typeof s.y!="number"||!Number.isFinite(s.y))return!1}}return!0}const Pg=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--chart-6)","var(--chart-7)","var(--chart-8)"];function yt(e){return Pg[e%Pg.length]}function jj({spec:e,renderChart:t,renderTable:n,height:l=220}){const a=b.useRef(null),[s,i]=b.useState(0),[r,c]=b.useState(!1);b.useEffect(()=>{const d=a.current;if(!d)return;const f=new ResizeObserver(h=>{var x;const p=(x=h[0])==null?void 0:x.contentRect.width;p&&i(Math.max(240,Math.floor(p)))});return f.observe(d),()=>f.disconnect()},[]);const u=e.series.length>1;return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-xl p-4 select-none",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:[o.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1.5",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-display font-semibold truncate",style:{color:"var(--chart-ink)"},children:e.title}),e.subtitle&&o.jsx("div",{className:"text-[11px] mt-0.5",style:{color:"var(--chart-ink-muted)"},children:e.subtitle})]}),o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.normalize&&o.jsx("span",{className:"text-[10px] font-mono px-2 py-1 rounded-[4px]",style:{background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--chart-ink-muted)"},title:"Each series is rebased to 100 at its first point, so differently-scaled series can be compared on one shared axis.",children:"Indexed"}),o.jsx("button",{onClick:()=>c(d=>!d),className:"text-[10px] font-mono px-2 py-1 rounded-[4px] cursor-pointer transition-colors",style:{background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--chart-ink-muted)"},children:r?"Chart":"Table"})]})]}),u&&o.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1 mb-2",children:e.series.map((d,f)=>o.jsxs("div",{className:"flex items-center gap-1.5 text-[10.5px]",style:{color:"var(--chart-ink-muted)"},children:[o.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-full shrink-0",style:{background:yt(f)}}),d.name]},d.name))}),o.jsx("div",{ref:a,className:"w-full",style:{minHeight:l},children:r?n():s>0?t(s,l):null}),e.note&&o.jsx("div",{className:"mt-2 text-[10.5px] italic",style:{color:"var(--chart-ink-muted)"},children:e.note})]})})}function kj(e,t,n=.3){const[l,a]=t,s=a-l,i=e>0?s/e:s,r=Math.max(1,i*(1-n));return{step:i,bandWidth:r,center:c=>l+i*c+i/2,start:c=>l+i*c+(i-r)/2}}function em(e,t){const n=e||1,l=Math.floor(Math.log10(n)),a=n/Math.pow(10,l);let s;return t?a<1.5?s=1:a<3?s=2:a<7?s=5:s=10:a<=1?s=1:a<=2?s=2:a<=5?s=5:s=10,s*Math.pow(10,l)}function Io(e,t,n=5){let l=e,a=t;if(l===a){const d=Math.abs(l)*.1||1;l-=d,a+=d}const s=em(a-l,!1),i=em(s/Math.max(1,n-1),!0),r=Math.floor(l/i)*i,c=Math.ceil(a/i)*i,u=[];for(let d=r;d<=c+i*.5;d+=i)u.push(Math.round(d*1e10)/1e10);return u}function Ej(e){var l;if(e.length===0)return 1;const t=Math.max(...e.map(a=>a.points.length));let n=0;for(let a=0;a<t;a++){let s=0;for(const i of e)s+=((l=i.points[a])==null?void 0:l.y)??0;s>n&&(n=s)}return n||1}function Cj(e){return e.map(t=>{var l;const n=(l=t.points[0])==null?void 0:l.y;return n?{...t,points:t.points.map(a=>({x:a.x,y:a.y/n*100}))}:t})}function $v(e){const t=Math.abs(e);return t<1e3?Number.isInteger(e)?String(e):e.toFixed(2):t<1e6?`${(e/1e3).toFixed(1)}k`:t<1e9?`${(e/1e6).toFixed(2)}M`:`${(e/1e9).toFixed(2)}B`}function Mj(e){return Math.abs(e)>=1e3?`$${$v(e)}`:`$${e.toLocaleString(void 0,{maximumFractionDigits:2})}`}function _j(e){const t=["B","KB","MB","GB","TB"];let n=Math.abs(e),l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l++;return`${e<0?"-":""}${n.toFixed(n<10&&l>0?1:0)} ${t[l]}`}function Zn(e,t){switch(t){case"compact":return $v(e);case"currency":return Mj(e);case"percent":return`${(e*100).toFixed(1)}%`;case"bytes":return _j(e);case"number":default:return e.toLocaleString()}}function Oh({data:e,chartWidth:t}){if(!e)return null;const n=e.x>t*.6;return o.jsxs("div",{className:"absolute pointer-events-none z-10 rounded-lg px-2.5 py-1.5 text-[10.5px] font-mono shadow-lg",style:{left:n?void 0:Math.max(0,e.x+10),right:n?Math.max(0,t-e.x+10):void 0,top:Math.max(0,e.y-10),background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--chart-ink)",minWidth:96,whiteSpace:"nowrap"},children:[o.jsx("div",{className:"font-semibold mb-1",style:{color:"var(--chart-ink-muted)"},children:e.label}),e.rows.map((l,a)=>o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"inline-block w-2 h-2 rounded-full shrink-0",style:{background:l.color}}),o.jsxs("span",{children:[l.name,":"]}),o.jsx("span",{className:"font-semibold ml-auto pl-2",style:{color:"var(--chart-ink)"},children:l.value})]},a))]})}function Aj({spec:e,width:t,height:n}){var V;const[l,a]=b.useState(null),s=e.type==="area",i=44,r=12,c=12,u=24,d=Math.max(10,t-i-r),f=Math.max(10,n-c-u),h=e.normalize?Cj(e.series):e.series,p=((V=h[0])==null?void 0:V.points)??[],x=p.length,S=h.flatMap(N=>N.points.map(D=>D.y)),w=Io(Math.min(0,...S),Math.max(...S,1),5),g=w[0],m=w[w.length-1]-g||1,v=N=>x>1?i+N/(x-1)*d:i+d/2,j=N=>c+f-(N-g)/m*f,E=h.map(N=>N.points.map((D,k)=>`${k===0?"M":"L"} ${v(k)} ${j(D.y)}`).join(" ")),M=s?h.map((N,D)=>{const k=E[D],R=v(N.points.length-1),z=v(0);return`${k} L ${R} ${c+f} L ${z} ${c+f} Z`}):[],A=e.series.length>1&&e.series.length<=4,C=N=>{const D=N.currentTarget.getBoundingClientRect(),k=N.clientX-D.left,R=x>1?Math.round((k-i)/d*(x-1)):0;a(Math.min(x-1,Math.max(0,R)))},H=l!==null&&p[l]?{x:v(l),y:j(Math.max(...h.map(N=>{var D;return((D=N.points[l])==null?void 0:D.y)??g}))),label:String(p[l].x),rows:e.series.map((N,D)=>{var z,O,Y;const k=(z=N.points[l])==null?void 0:z.y;if(k===void 0)return{name:N.name,value:"—",color:yt(D)};if(!e.normalize)return{name:N.name,value:Zn(k,e.y_format),color:yt(D)};const R=((Y=(O=h[D])==null?void 0:O.points[l])==null?void 0:Y.y)??0;return{name:N.name,value:`${Zn(k,e.y_format)} (${R.toFixed(1)})`,color:yt(D)}})}:null,T=Math.floor((x-1)/2),$=x>0?Array.from(new Set([0,T,x-1])):[];return o.jsxs("div",{className:"relative",style:{width:"100%",height:n},children:[o.jsxs("svg",{width:t,height:n,className:"overflow-visible",children:[o.jsx("defs",{children:e.series.map((N,D)=>o.jsxs("linearGradient",{id:`chart-grad-${D}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:yt(D),stopOpacity:"0.22"}),o.jsx("stop",{offset:"100%",stopColor:yt(D),stopOpacity:"0"})]},D))}),w.map((N,D)=>{const k=j(N);return o.jsxs("g",{children:[o.jsx("line",{x1:i,y1:k,x2:t-r,y2:k,stroke:"var(--chart-grid)",strokeWidth:"1"}),o.jsx("text",{x:i-8,y:k+3.5,textAnchor:"end",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace"},children:e.normalize?N.toFixed(0):Zn(N,e.y_format)})]},D)}),o.jsx("line",{x1:i,y1:c+f,x2:t-r,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1"}),$.map(N=>{var D;return o.jsx("text",{x:v(N),y:n-6,textAnchor:N===0?"start":N===x-1?"end":"middle",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace",opacity:.7},children:String(((D=p[N])==null?void 0:D.x)??"")},N)}),s&&M.map((N,D)=>o.jsx("path",{d:N,fill:`url(#chart-grad-${D})`},`area-${D}`)),E.map((N,D)=>o.jsx("path",{d:N,fill:"none",stroke:yt(D),strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},`line-${D}`)),h.map((N,D)=>{const k=N.points[N.points.length-1];if(!k)return null;const R=v(N.points.length-1),z=j(k.y),O=Math.min(R+6,t-r-4),Y=O>t-r-34;return o.jsxs("g",{children:[o.jsx("circle",{cx:R,cy:z,r:"3",fill:yt(D),stroke:"var(--s1)",strokeWidth:"1.5"}),A&&o.jsx("text",{x:Y?t-r:O,y:z+3,textAnchor:Y?"end":"start",style:{fill:"var(--chart-ink)",fontSize:9.5,fontWeight:600,fontFamily:"inherit"},children:N.name})]},`endpoint-${D}`)}),H&&o.jsx("line",{x1:H.x,y1:c,x2:H.x,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1",strokeOpacity:"0.6"}),o.jsx("rect",{x:i,y:c,width:d,height:f,fill:"transparent",onMouseMove:C,onMouseLeave:()=>a(null),style:{cursor:"crosshair"}})]}),o.jsx(Oh,{data:H,chartWidth:t})]})}function Tj({spec:e,width:t,height:n}){var A;const[l,a]=b.useState(null),s=e.type==="stacked-bar",i=44,r=12,c=12,u=24,d=Math.max(10,t-i-r),f=Math.max(10,n-c-u),h=((A=e.series[0])==null?void 0:A.points)??[],p=h.length,x=s?Ej(e.series):Math.max(...e.series.flatMap(C=>C.points.map(H=>H.y)),1),S=Io(0,x,5),w=S[S.length-1],g=C=>c+f-C/(w||1)*f,y=kj(p,[i,i+d],.3),m=2,v=e.series.length,j=s?y.bandWidth:Math.max(2,(y.bandWidth-m*(v-1))/v),E=l!==null&&h[l]?{x:y.center(l),y:c,label:String(h[l].x),rows:e.series.map((C,H)=>{var T;return{name:C.name,value:Zn(((T=C.points[l])==null?void 0:T.y)??0,e.y_format),color:yt(H)}})}:null,M=Math.floor((p-1)/2);return o.jsxs("div",{className:"relative",style:{width:"100%",height:n},children:[o.jsxs("svg",{width:t,height:n,className:"overflow-visible",children:[S.map((C,H)=>{const T=g(C);return o.jsxs("g",{children:[o.jsx("line",{x1:i,y1:T,x2:t-r,y2:T,stroke:"var(--chart-grid)",strokeWidth:"1"}),o.jsx("text",{x:i-8,y:T+3.5,textAnchor:"end",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace"},children:Zn(C,e.y_format)})]},H)}),o.jsx("line",{x1:i,y1:c+f,x2:t-r,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1"}),h.map((C,H)=>p<=1||H===0||H===p-1||H===M?o.jsx("text",{x:y.center(H),y:n-6,textAnchor:"middle",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace",opacity:.7},children:String(C.x)},`label-${H}`):null),h.map((C,H)=>{const T=y.start(H);let $=c+f;return o.jsxs("g",{onMouseEnter:()=>a(H),onMouseLeave:()=>a(null),children:[o.jsx("rect",{x:y.center(H)-y.step/2,y:c,width:y.step,height:f,fill:"transparent"}),e.series.map((V,N)=>{var O;const D=((O=V.points[H])==null?void 0:O.y)??0;if(D<=0)return null;const k=D/(w||1)*f;let R,z;return s?(R=T,z=$-k-(N>0?m:0),$=z):(R=T+N*(j+m),z=c+f-k),o.jsx("rect",{x:R,y:z,width:j,height:k,rx:"2",fill:yt(N)},N)})]},`group-${H}`)}),E&&o.jsx("line",{x1:E.x,y1:c,x2:E.x,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1",strokeOpacity:"0.4"})]}),o.jsx(Oh,{data:E,chartWidth:t})]})}function Yu(e,t){if(typeof e=="number")return e;const n=Number(e);return Number.isFinite(n)?n:t}function zj({spec:e,width:t,height:n}){var M,A;const[l,a]=b.useState(null),s=48,i=16,r=14,c=26,u=Math.max(10,t-s-i),d=Math.max(10,n-r-c),f=e.series.flatMap(C=>C.points.map((H,T)=>Yu(H.x,T))),h=e.series.flatMap(C=>C.points.map(H=>H.y)),p=Io(Math.min(...f),Math.max(...f),4),x=Io(Math.min(0,...h),Math.max(...h,1),5),S=p[0],w=p[p.length-1],g=x[0],y=x[x.length-1],m=C=>s+(C-S)/(w-S||1)*u,v=C=>r+d-(C-g)/(y-g||1)*d,j=l?(M=e.series[l.si])==null?void 0:M.points[l.pi]:void 0,E=l&&j?{x:m(Yu(j.x,l.pi)),y:v(j.y),label:((A=e.series[l.si])==null?void 0:A.name)??"",rows:[{name:e.x_label||"x",value:String(j.x),color:yt(l.si)},{name:e.y_label||"y",value:Zn(j.y,e.y_format),color:yt(l.si)}]}:null;return o.jsxs("div",{className:"relative",style:{width:"100%",height:n},children:[o.jsxs("svg",{width:t,height:n,className:"overflow-visible",children:[x.map((C,H)=>{const T=v(C);return o.jsxs("g",{children:[o.jsx("line",{x1:s,y1:T,x2:t-i,y2:T,stroke:"var(--chart-grid)",strokeWidth:"1"}),o.jsx("text",{x:s-8,y:T+3.5,textAnchor:"end",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace"},children:Zn(C,e.y_format)})]},`y-${H}`)}),p.map((C,H)=>o.jsx("text",{x:m(C),y:n-6,textAnchor:"middle",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace",opacity:.7},children:Zn(C)},`x-${H}`)),o.jsx("line",{x1:s,y1:r+d,x2:t-i,y2:r+d,stroke:"var(--chart-axis)",strokeWidth:"1"}),o.jsx("line",{x1:s,y1:r,x2:s,y2:r+d,stroke:"var(--chart-axis)",strokeWidth:"1"}),e.series.map((C,H)=>C.points.map((T,$)=>{const V=m(Yu(T.x,$)),N=v(T.y);return o.jsxs("g",{children:[o.jsx("circle",{cx:V,cy:N,r:"12",fill:"transparent",onMouseEnter:()=>a({si:H,pi:$}),onMouseLeave:()=>a(null),style:{cursor:"pointer"}}),o.jsx("circle",{cx:V,cy:N,r:"4",fill:yt(H),stroke:"var(--s1)",strokeWidth:"1.5"})]},`${H}-${$}`)})),E&&l&&o.jsx("circle",{cx:E.x,cy:E.y,r:"7",fill:"none",stroke:yt(l.si),strokeWidth:"1.5"})]}),o.jsx(Oh,{data:E,chartWidth:t})]})}function Dj({spec:e}){var n;const t=((n=e.series[0])==null?void 0:n.points.map(l=>l.x))??[];return o.jsxs("div",{children:[o.jsx("div",{className:"overflow-x-auto overflow-y-auto max-h-[260px] scrollbar-thin",children:o.jsxs("table",{className:"w-full text-[11.5px] font-mono",children:[o.jsx("thead",{children:o.jsxs("tr",{style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("th",{className:"text-left py-1.5 pr-3 font-medium",style:{color:"var(--chart-ink-muted)"},children:e.x_label||"x"}),e.series.map(l=>o.jsx("th",{className:"text-right py-1.5 pl-3 font-medium",style:{color:"var(--chart-ink-muted)"},children:l.name},l.name))]})}),o.jsx("tbody",{children:t.map((l,a)=>o.jsxs("tr",{style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 40%, transparent)"},children:[o.jsx("td",{className:"py-1 pr-3",style:{color:"var(--chart-ink)",fontVariantNumeric:"tabular-nums"},children:String(l)}),e.series.map(s=>{var i;return o.jsx("td",{className:"text-right py-1 pl-3",style:{color:"var(--chart-ink)",fontVariantNumeric:"tabular-nums"},children:Zn(((i=s.points[a])==null?void 0:i.y)??0,e.y_format)},s.name)})]},a))})]})}),e.normalize&&o.jsx("div",{className:"mt-2 text-[10.5px] italic",style:{color:"var(--chart-ink-muted)"},children:"Chart is indexed to 100 at the first point; this table shows raw values."})]})}function tm({message:e,raw:t}){return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-xl p-4",style:{background:"color-mix(in srgb, var(--red) 6%, var(--s2))",border:"1px solid color-mix(in srgb, var(--red) 25%, var(--b1))"},children:[o.jsx("div",{className:"text-[12px] font-semibold mb-1.5",style:{color:"var(--red)"},children:"Chart could not be rendered"}),o.jsx("div",{className:"text-[11.5px] mb-2",style:{color:"var(--text)"},children:e}),o.jsx("pre",{className:"text-[10.5px] font-mono overflow-x-auto whitespace-pre-wrap",style:{color:"var(--muted)"},children:typeof t=="string"?t:JSON.stringify(t,null,2)})]})})}function Rj({spec:e}){const t=(n,l)=>{switch(e.type){case"line":case"area":return o.jsx(Aj,{spec:e,width:n,height:l});case"bar":case"stacked-bar":return o.jsx(Tj,{spec:e,width:n,height:l});case"scatter":return o.jsx(zj,{spec:e,width:n,height:l});default:return null}};return o.jsx(jj,{spec:e,renderChart:t,renderTable:()=>o.jsx(Dj,{spec:e})})}function Oj({spec:e,error:t}){return t?o.jsx(tm,{message:t,raw:e}):Nj(e)?o.jsx(Rj,{spec:e}):o.jsx(tm,{message:"The chart data did not match the expected format.",raw:e})}const nm=["what are we discovering today?","greetings from the lab!","lab coat is on ... ","the system is radioactive","what is our next experiment?","atomic levels are stable!","what is our next reaction?","geiger counter is ticking...","mobile X-ray unit deployed","nobel-tier assist activated","emitting helpful isotopes","cathode rays engaged"];function lm(){return nm[Math.floor(Math.random()*nm.length)]}function Bv({content:e}){const[t,n]=b.useState(!0);return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden cursor-pointer select-none transition-all duration-150",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},onClick:()=>n(!t),children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{background:"color-mix(in srgb, var(--s2) 80%, transparent)"},children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",className:"shrink-0",style:{opacity:.7},children:[o.jsx("path",{d:"M12 2a7 7 0 0 0-7 7c0 3 2 5 2 8h10c0-3 2-5 2-8a7 7 0 0 0-7-7z"}),o.jsx("circle",{cx:"9",cy:"9",r:"1",fill:"currentColor"}),o.jsx("circle",{cx:"15",cy:"9",r:"1",fill:"currentColor"})]}),o.jsx("span",{className:"text-[11.5px] font-medium text-text font-mono",children:t?"Hide thinking":"Show thinking"}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${t?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),t&&o.jsx("div",{className:"px-3 py-2.5",style:{borderTop:"1px solid var(--b1)",background:"color-mix(in srgb, var(--s1) 60%, transparent)"},children:o.jsx("pre",{className:"text-[11px] text-muted leading-relaxed whitespace-pre-wrap font-mono max-h-[300px] overflow-y-auto",children:e})})]})})}function Uv({toolCalls:e}){const[t,n]=b.useState(!1);return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden mb-1",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer select-none transition-all duration-150",style:{background:"color-mix(in srgb, var(--s2) 80%, transparent)"},onClick:()=>n(!t),children:[o.jsx("div",{className:"w-[14px] h-[14px] rounded-[3px] flex items-center justify-center",style:{background:"color-mix(in srgb, var(--gold) 15%, var(--s3))"},children:o.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",style:{opacity:.7},children:[o.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),o.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),o.jsxs("span",{className:"text-[11.5px] font-medium text-text font-mono",children:[e.length," tool call",e.length>1?"s":""]}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${t?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),t&&e.map((l,a)=>o.jsxs("div",{className:"px-3 py-2.5 first:border-t-0",style:{borderTop:"1px solid var(--b1)",background:"color-mix(in srgb, var(--s1) 60%, transparent)"},children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:"text-[11.5px] font-semibold font-mono",style:{color:"var(--gold)"},children:l.name}),o.jsx("span",{className:"text-xs text-muted font-mono truncate max-w-[250px]",children:l.args})]}),o.jsx("pre",{className:"text-[11px] text-muted font-mono leading-[1.5] overflow-x-auto whitespace-pre-wrap",children:l.input?qv(l.input):""})]},a))]})})}function Hj({event:e}){const[t,n]=b.useState(!1);return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden mb-1",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer select-none transition-all duration-150",style:{background:"color-mix(in srgb, var(--s2) 80%, transparent)"},onClick:()=>n(!t),children:[o.jsx("div",{className:"w-[14px] h-[14px] rounded-[3px] flex items-center justify-center",style:{background:"color-mix(in srgb, var(--red) 15%, var(--s3))"},children:o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"1.5",children:o.jsx("path",{d:"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"})})}),o.jsxs("span",{className:"text-[11.5px] font-semibold text-fg font-mono",children:["Heartbeat Brief (",e.scheduleType,")"]}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${t?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),t&&o.jsx("div",{className:"px-3 py-3 markdown-body",style:{borderTop:"1px solid var(--b1)",background:"color-mix(in srgb, var(--s1) 60%, transparent)"},children:o.jsx("div",{dangerouslySetInnerHTML:{__html:Ko(e.formattedText||"")}})})]})})}function Lj({message:e,time:t}){return o.jsx("div",{className:"px-3 py-1.5 animate-fadeIn",children:o.jsxs("div",{className:"p-3.5 rounded-xl backdrop-blur-md shadow-lg max-w-[480px] flex gap-3 transition-all duration-200 relative overflow-hidden group",style:{background:"linear-gradient(135deg, color-mix(in srgb, var(--gold) 8%, var(--s2)), color-mix(in srgb, var(--gold) 4%, var(--s1)))",border:"1px solid color-mix(in srgb, var(--gold) 20%, var(--b1))"},children:[o.jsx("div",{className:"absolute top-0 right-0 w-24 h-24 rounded-full filter blur-xl opacity-30 group-hover:scale-125 transition-transform duration-500",style:{background:"var(--gold)"}}),o.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg shrink-0 relative",style:{background:"color-mix(in srgb, var(--gold) 15%, transparent)",color:"var(--gold)"},children:[o.jsx("span",{className:"absolute inset-0 rounded-lg animate-ping opacity-50",style:{background:"color-mix(in srgb, var(--gold) 20%, transparent)",animationDuration:"2s"}}),o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"animate-wiggle",children:[o.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),o.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})]}),o.jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1 select-none",children:[o.jsx("span",{className:"font-bold text-xs tracking-wide uppercase",style:{color:"var(--gold)"},children:"Reminder Fired"}),o.jsx("span",{className:"text-[10px] text-muted font-mono",children:t})]}),o.jsx("div",{className:"text-[13px] text-text leading-relaxed font-semibold",children:e})]})]})})}function On(e){return new Date(e).toLocaleTimeString("en",{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function qv(e){if(!e||Object.keys(e).length===0)return"";const t=Object.entries(e);if(t.length===1){const n=t[0];if(!n)return"";const l=n[0],a=n[1],s=typeof a=="object"?JSON.stringify(a,null,2):String(a);return`${l}: ${s}`}return t.map(([n,l])=>{const a=typeof l=="object"?JSON.stringify(l,null,2):String(l);return`${n}: ${a}`}).join(`
113
- `)}function $j(e,t){if(e==="Bash")return String(t.command||"").slice(0,80);const n=t.file_path||t.path||"";return n?String(n):Object.entries(t).map(([l,a])=>`${l}: ${String(a).slice(0,60)}`).join(", ")}function Bj(e,t){const n=e.find(l=>l.type==="tool-result"&&l.toolCallId===t);return n==null?void 0:n.error}function Uj(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>")}ve.setOptions({gfm:!0,breaks:!0});function Ko(e){try{return ve.parse(e)}catch{return Uj(e)}}function Yv({toolCallId:e,name:t,input:n,decision:l,events:a,rpc:s,mode:i}){const[r,c]=b.useState(!1),[u,d]=b.useState(null),f=a.find(S=>S.type==="approval-decision"&&S.toolCallId===e),h=f?f.decision:u,p=l==="ask"&&!h,x=async S=>{if(s){c(!0);try{await s.approvalDecide(e,S),d(S)}catch(w){console.error("Failed to submit tool approval decision:",w)}finally{c(!1)}}};if(!p){const S=h==="allow";return o.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2.5 animate-fadeIn select-none",children:[o.jsx("div",{className:`flex items-center justify-center w-5 h-5 rounded-full ${S?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"} shrink-0`,children:o.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:S?o.jsx("polyline",{points:"20 6 9 17 4 12"}):o.jsxs(o.Fragment,{children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}),o.jsxs("div",{className:"flex items-baseline gap-1.5 text-xs text-muted",children:[o.jsx("span",{className:"font-semibold text-fg",children:S?"Authorized":"Blocked"}),o.jsx("span",{children:"action:"}),o.jsx("code",{className:"font-mono bg-s3 border border-b1 px-1.5 py-0.5 rounded text-[11px] text-fg",children:t})]})]})}return i==="auto"?null:o.jsx("div",{className:"fixed inset-0 z-[999] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-fadeIn",children:o.jsxs("div",{className:"w-full max-w-[480px] p-6 rounded-2xl border border-b2 bg-s2/95 backdrop-blur-md shadow-2xl transition-all duration-200 transform scale-100 animate-scaleIn",children:[o.jsxs("div",{className:"flex items-start gap-4 border-b border-b1 pb-4 mb-4",children:[o.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-xl bg-yellow-500/10 text-yellow-500 shrink-0",children:o.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("span",{className:"font-bold text-fg text-base block mb-0.5",children:"Authorization Required"}),o.jsx("span",{className:"text-[12px] text-muted",children:"The agent requires permission to run this action."})]})]}),o.jsxs("div",{className:"mb-4",children:[o.jsx("div",{className:"text-[9px] text-muted2 font-mono uppercase tracking-wider mb-1.5 select-none",children:"Action / Tool"}),o.jsx("div",{className:"flex items-center",children:o.jsx("code",{className:"font-mono bg-s3 border border-b1 px-2.5 py-1 rounded-lg text-xs text-fg font-semibold",children:t})})]}),o.jsxs("div",{className:"bg-s1 rounded-xl border border-b1 p-4 mb-6 max-h-[220px] overflow-y-auto scrollbar-thin",children:[o.jsx("div",{className:"text-[9px] text-muted2 font-mono uppercase tracking-wider mb-1.5 select-none",children:"Arguments"}),o.jsx("pre",{className:"font-mono text-[11.5px] text-text overflow-x-auto m-0 leading-normal",children:qv(n)})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsxs("button",{onClick:()=>x("allow"),disabled:r,className:"flex-1 py-2 px-4 rounded-xl bg-green-600 hover:bg-green-500 text-white font-semibold text-[13px] shadow-lg shadow-green-600/10 hover:shadow-green-600/20 transition-all duration-150 active:scale-[0.98] disabled:opacity-50 disabled:pointer-events-none cursor-pointer flex items-center justify-center gap-1.5",children:[o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Approve Action"]}),o.jsxs("button",{onClick:()=>x("deny"),disabled:r,className:"py-2 px-3 rounded-xl bg-s3 border border-b2 hover:bg-s4 text-fg hover:text-text hover:border-b3 font-semibold text-[13px] transition-all duration-150 active:scale-[0.98] disabled:opacity-50 disabled:pointer-events-none cursor-pointer flex items-center justify-center gap-1.5",children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Deny"]})]})]})})}function qj({blocks:e,blockCount:t,response:n,time:l,events:a,rpc:s}){const[i,r]=b.useState(!1);return e&&e.length>0||!!n?o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden cursor-pointer select-none transition-all duration-150",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},onClick:()=>r(!i),children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{background:"var(--bg)"},children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",className:"shrink-0",style:{opacity:.7},children:[o.jsx("circle",{cx:"12",cy:"12",r:"2"}),o.jsx("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4"}),o.jsx("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",transform:"rotate(60 12 12)"}),o.jsx("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",transform:"rotate(120 12 12)"})]}),o.jsxs("span",{className:"text-[11.5px] font-medium text-text font-mono",children:[t," agent action",t>1?"s":""]}),n&&o.jsxs("span",{className:"text-[10px] text-muted2 font-mono truncate max-w-[120px]",title:n,children:["“",n.slice(0,60),"...","”"]}),l&&o.jsx("span",{className:"text-[10px] text-muted2 font-mono",children:l}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${i?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),i&&o.jsxs("div",{className:"px-1 py-1",style:{borderTop:"1px solid var(--b1)",background:"var(--bg)"},onClick:u=>u.stopPropagation(),children:[e.map((u,d)=>{if(u.type==="thinking")return o.jsx(Bv,{content:u.content},d);if(u.type==="tool-group"){const f=u;return f.toolCalls.length>0?o.jsx(Uv,{toolCalls:f.toolCalls},d):null}return u.type==="approval-request"?o.jsx(Yv,{toolCallId:u.toolCallId,name:u.name,input:u.input,decision:u.decision,events:a||[],rpc:s||null,mode:u.mode},d):null}),n&&o.jsxs("div",{className:"mt-3",children:[o.jsx("div",{className:"flex items-baseline gap-2 mb-1",children:o.jsx("span",{className:"text-[10px] font-semibold text-fg",style:{color:"var(--gold)"},children:"curie-agent"})}),o.jsx("div",{className:"text-[13px] text-text leading-[1.65] markdown-body chat-msg-agent pl-3",dangerouslySetInnerHTML:{__html:Ko(n)}})]})]})]})}):null}function Yj(e){switch(e.type){case"user-prompt":return{type:"user",content:e.text||"",time:On(e.timestamp)};case"assistant-delta":return{type:"assistant",content:e.text||"",time:On(e.timestamp)};case"thinking-delta":return{type:"thinking",content:e.text||"",time:On(e.timestamp)};case"heartbeat-brief":return{type:"heartbeat-brief",content:e.formattedText||"",time:On(e.timestamp),event:e};case"tool-call":{const t=e.name||"tool",n=e.input||{};if(t==="Chart")return{type:"chart",spec:n,toolCallId:e.toolCallId||"",time:On(e.timestamp)};const l=$j(t,n);return{type:"tool-group",content:"",time:"",toolCalls:[{name:t,args:l,input:n}]}}case"approval-request":{const t=e.toolCallId,n=e.name||"tool";if(n==="Chart")return null;const l=e.input||{},a=e.decision,s=e.mode;return{type:"approval-request",toolCallId:t,name:n,input:l,decision:a,mode:s,time:On(e.timestamp)}}case"cron-task-fired":{const t=e.message||"",n=e.taskId||"";return{type:"reminder-fired",message:t,taskId:n,time:On(e.timestamp)}}case"context-warning":return{type:"assistant",content:e.message||"",time:On(e.timestamp)};case"error":return{type:"error",content:e.message||`An error occurred (code: ${e.code||"unknown"})`,time:On(e.timestamp)};default:return null}}function Vj(e){const t=[];let n=[],l="",a=!1,s="",i=null,r=0;const c=()=>{a&&s&&(n.push({type:"thinking",content:s,time:""}),a=!1,s="")},u=()=>{var h;if(n.length===0)return;let f=0;for(let p=r;p<n.length;p++){const x=n[p];x.type==="tool-group"?f+=((h=x.toolCalls)==null?void 0:h.length)||1:f+=1}i?(i.blocks=[...i.blocks,...n.slice(r)],i.blockCount+=f):(i={type:"agent-actions",blocks:[...n],blockCount:f,response:void 0,time:n[0].time||""},t.push(i)),r=n.length},d=()=>{c(),u(),l&&t.push({type:"assistant",content:l,time:""}),n=[],l="",i=null,r=0};for(const f of e){const h=Yj(f);if(h)if(h.type==="user"||h.type==="error"||h.type==="heartbeat-brief"||h.type==="reminder-fired")d(),t.push(h);else if(h.type==="assistant")l+=h.content;else if(h.type==="thinking")a=!0,s+=h.content||"";else if(h.type==="tool-group"){c();const p=h;n.length>0&&n[n.length-1].type==="tool-group"?n[n.length-1].toolCalls.push(...p.toolCalls||[]):n.push({type:"tool-group",content:"",time:h.time||"",toolCalls:p.toolCalls||[]}),u()}else h.type==="approval-request"?(c(),n.push({type:"approval-request",content:"",time:h.time||"",toolCallId:h.toolCallId||"",name:h.name||"tool",input:h.input||{},decision:h.decision||"ask",mode:h.mode}),u()):(d(),t.push(h))}return d(),t}function Xj({cmdResult:e,rpc:t,className:n,activeSessionId:l,onCreateSession:a,onClearCmdResult:s,events:i,addLiveEvent:r,totalTokens:c,contextTokens:u,costUsd:d,onSwitchView:f}){const{ws:h,connected:p,connectionStatus:x}=Cn(),[S,w]=b.useState(!1),[g,y]=b.useState(null),[m,v]=b.useState(""),j=b.useRef(null),E=b.useRef(null),[M,A]=b.useState(lm);b.useEffect(()=>{E.current&&!l&&A(lm()),E.current=l},[l]),b.useEffect(()=>{if(x==="connected")y(null);else if(x==="reconnecting")y(null);else{const N=setTimeout(()=>{y("Disconnected from daemon. Check that the daemon is running.")},2e3);return()=>clearTimeout(N)}},[p,x]);const C=b.useMemo(()=>Vj(i),[i]),H=b.useRef(!0),T=b.useCallback(()=>{j.current&&(j.current.scrollTop=j.current.scrollHeight,H.current=!0)},[]);b.useEffect(()=>{const N=j.current;if(!N)return;const D=()=>{const k=N.scrollHeight-N.scrollTop-N.clientHeight<80;H.current=k};return N.addEventListener("scroll",D,{passive:!0}),()=>N.removeEventListener("scroll",D)},[]),b.useEffect(()=>{H.current&&T()},[C,S,T]),b.useEffect(()=>{T()},[T]),b.useEffect(()=>{e&&(console.log("Command palette result:",e),v(e),s==null||s())},[e,s]);const $=b.useCallback(async N=>{var k,R;if(!t){y("Not connected to daemon. Make sure the daemon is running.");return}if(w(!0),y(null),T(),N.startsWith("/")){const z=N.match(/^\/([^\s]+)(?:\s+(.*))?$/);if(z){const O=z[1].toLowerCase(),Y=(z[2]||"").trim();if(O==="heartbeat"){r({type:"user-prompt",id:`local-prompt-${Date.now()}`,timestamp:Date.now(),text:N});const X=Y.toLowerCase();if(X==="now"){r({type:"assistant-delta",id:`local-running-${Date.now()}`,timestamp:Date.now(),text:"Executing immediate heartbeat cycle in background..."});try{await t.heartbeatRun(),w(!1)}catch(L){const U=L instanceof Error?L.message:String(L);r({type:"error",id:`local-err-${Date.now()}`,timestamp:Date.now(),message:`Heartbeat failed: ${U}`}),w(!1)}}else if(X==="status"||X==="")try{const L=await t.heartbeatStatus(),U=(L==null?void 0:L.schedule)==="on",_=(L==null?void 0:L.intraday)||"(not set)",B=`### Heartbeat Cycle Status:
112
+ Please report this to https://github.com/markedjs/marked.`,e){let l="<p>An error occurred:</p><pre>"+mn(n.message+"",!0)+"</pre>";return t?Promise.resolve(l):l}if(t)return Promise.reject(n);throw n}}},ua=new bj;function ve(e,t){return ua.parse(e,t)}ve.options=ve.setOptions=function(e){return ua.setOptions(e),ve.defaults=ua.defaults,Mv(ve.defaults),ve};ve.getDefaults=Eh;ve.defaults=ba;ve.use=function(...e){return ua.use(...e),ve.defaults=ua.defaults,Mv(ve.defaults),ve};ve.walkTokens=function(e,t){return ua.walkTokens(e,t)};ve.parseInline=ua.parseInline;ve.Parser=ln;ve.parser=ln.parse;ve.Renderer=Zo;ve.TextRenderer=Rh;ve.Lexer=nn;ve.lexer=nn.lex;ve.Tokenizer=Qo;ve.Hooks=Is;ve.parse=ve;ve.options;ve.setOptions;ve.use;ve.walkTokens;ve.parseInline;ln.parse;nn.lex;function Fg(e){return e<1e3?String(e):`${(e/1e3).toFixed(1)}k`}function wj({onSend:e,onCancel:t,cmdInput:n,onClearCmdInput:l,totalTokens:a,contextTokens:s,costUsd:i}){const{providers:r,get:c}=kh(),u=c("current_provider"),d=c("model"),f=r.find(g=>g.name===u&&g.configured)||r.find(g=>g.configured)||{name:"none"},[h,p]=b.useState(""),x=b.useRef(null);b.useEffect(()=>{n&&(p(n),setTimeout(()=>{x.current&&(x.current.focus(),x.current.selectionStart=x.current.selectionEnd=n.length)},50),l==null||l())},[n,l]);const S=b.useCallback(()=>{const g=x.current;g&&(g.style.height="",g.style.height=Math.min(g.scrollHeight,160)+"px")},[]),w=b.useCallback(g=>{if(g.key==="Enter"&&!g.shiftKey){g.preventDefault();const y=h.trim();if(!y)return;e(y),p(""),setTimeout(()=>{x.current&&(x.current.style.height="")},0)}},[h,e]);return o.jsx("div",{className:"px-5 pt-3 pb-7 md:pb-3 bg-transparent",children:o.jsxs("div",{className:"glass-card rounded-xl transition-all duration-200",style:{background:"linear-gradient(135deg, var(--s2) 0%, color-mix(in srgb, var(--s1) 90%, var(--wood)) 100%)",border:"1px solid var(--b2)"},children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 text-[10.5px]",children:[o.jsx("span",{className:"w-[6px] h-[6px] rounded-full shrink-0",style:{background:u?"var(--green)":"var(--muted2)",opacity:u?1:.3}}),o.jsx("span",{style:{color:"var(--gold)",opacity:.8},children:f.name}),o.jsx("span",{className:"text-muted",children:" · "}),o.jsx("span",{className:"text-muted",children:d||"no model set"})]}),o.jsx("textarea",{ref:x,className:"w-full bg-transparent border-0 outline-none text-fg font-sans text-[13.5px] px-3.5 py-2.5 resize-none leading-[1.5]",style:{color:"var(--cream)"},rows:1,placeholder:"Message curie-agent...",value:h,onChange:g=>{p(g.target.value),S()},onKeyDown:w}),o.jsxs("div",{className:"flex items-center px-3 pb-2.5 pt-1",children:[a!==void 0?o.jsxs(o.Fragment,{children:[o.jsxs("span",{className:"text-[10px] text-muted font-mono",style:{opacity:.6},children:[Fg(a)," tokens"]}),o.jsx("span",{className:"opacity-30 mx-1",children:" · "}),o.jsxs("span",{className:"text-[10px] text-muted font-mono",style:{opacity:.6},children:["ctx ",Fg(s??0)]}),o.jsx("span",{className:"opacity-30 mx-1",children:" · "}),o.jsxs("span",{className:"text-[10px] text-muted font-mono",style:{color:"var(--green)",opacity:.6},children:["$",(i??0).toFixed(4)]}),o.jsx("div",{className:"flex-1"})]}):null,t?o.jsx("button",{className:"w-8 h-8 flex items-center justify-center cursor-pointer transition-all duration-200 hover:scale-105 active:scale-95 rounded-lg",style:{background:"var(--red)",color:"#fff"},onClick:t,title:"Stop agent",children:o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:o.jsx("rect",{x:"6",y:"6",width:"12",height:"12",rx:"1.5"})})}):o.jsx("button",{className:"btn-gold rounded-lg w-8 h-8 flex items-center justify-center cursor-pointer transition-all duration-200 hover:scale-105 active:scale-95",onClick:()=>{const g=h.trim();g&&(e(g),p(""))},children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#1a1410",strokeWidth:"2.5",children:[o.jsx("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),o.jsx("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})})]})]})})}const Sj=["line","area","bar","stacked-bar","scatter"];function Nj(e){if(!e||typeof e!="object")return!1;const t=e;if(typeof t.type!="string"||!Sj.includes(t.type)||typeof t.title!="string"||t.title.length===0||t.normalize!==void 0&&typeof t.normalize!="boolean"||!Array.isArray(t.series)||t.series.length===0)return!1;for(const n of t.series){if(!n||typeof n!="object")return!1;const l=n;if(typeof l.name!="string"||!Array.isArray(l.points)||l.points.length===0)return!1;for(const a of l.points){if(!a||typeof a!="object")return!1;const s=a;if(typeof s.x!="string"&&typeof s.x!="number"||typeof s.y!="number"||!Number.isFinite(s.y))return!1}}return!0}const Pg=["var(--chart-1)","var(--chart-2)","var(--chart-3)","var(--chart-4)","var(--chart-5)","var(--chart-6)","var(--chart-7)","var(--chart-8)"];function yt(e){return Pg[e%Pg.length]}function jj({spec:e,renderChart:t,renderTable:n,height:l=220}){const a=b.useRef(null),[s,i]=b.useState(0),[r,c]=b.useState(!1);b.useEffect(()=>{const d=a.current;if(!d)return;const f=new ResizeObserver(h=>{var x;const p=(x=h[0])==null?void 0:x.contentRect.width;p&&i(Math.max(240,Math.floor(p)))});return f.observe(d),()=>f.disconnect()},[]);const u=e.series.length>1;return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-xl p-4 select-none",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:[o.jsxs("div",{className:"flex items-start justify-between gap-3 mb-1.5",children:[o.jsxs("div",{className:"min-w-0",children:[o.jsx("div",{className:"text-[13px] font-display font-semibold truncate",style:{color:"var(--chart-ink)"},children:e.title}),e.subtitle&&o.jsx("div",{className:"text-[11px] mt-0.5",style:{color:"var(--chart-ink-muted)"},children:e.subtitle})]}),o.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.normalize&&o.jsx("span",{className:"text-[10px] font-mono px-2 py-1 rounded-[4px]",style:{background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--chart-ink-muted)"},title:"Each series is rebased to 100 at its first point, so differently-scaled series can be compared on one shared axis.",children:"Indexed"}),o.jsx("button",{onClick:()=>c(d=>!d),className:"text-[10px] font-mono px-2 py-1 rounded-[4px] cursor-pointer transition-colors",style:{background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--chart-ink-muted)"},children:r?"Chart":"Table"})]})]}),u&&o.jsx("div",{className:"flex flex-wrap gap-x-4 gap-y-1 mb-2",children:e.series.map((d,f)=>o.jsxs("div",{className:"flex items-center gap-1.5 text-[10.5px]",style:{color:"var(--chart-ink-muted)"},children:[o.jsx("span",{className:"inline-block w-2.5 h-2.5 rounded-full shrink-0",style:{background:yt(f)}}),d.name]},d.name))}),o.jsx("div",{ref:a,className:"w-full",style:{minHeight:l},children:r?n():s>0?t(s,l):null}),e.note&&o.jsx("div",{className:"mt-2 text-[10.5px] italic",style:{color:"var(--chart-ink-muted)"},children:e.note})]})})}function kj(e,t,n=.3){const[l,a]=t,s=a-l,i=e>0?s/e:s,r=Math.max(1,i*(1-n));return{step:i,bandWidth:r,center:c=>l+i*c+i/2,start:c=>l+i*c+(i-r)/2}}function em(e,t){const n=e||1,l=Math.floor(Math.log10(n)),a=n/Math.pow(10,l);let s;return t?a<1.5?s=1:a<3?s=2:a<7?s=5:s=10:a<=1?s=1:a<=2?s=2:a<=5?s=5:s=10,s*Math.pow(10,l)}function Io(e,t,n=5){let l=e,a=t;if(l===a){const d=Math.abs(l)*.1||1;l-=d,a+=d}const s=em(a-l,!1),i=em(s/Math.max(1,n-1),!0),r=Math.floor(l/i)*i,c=Math.ceil(a/i)*i,u=[];for(let d=r;d<=c+i*.5;d+=i)u.push(Math.round(d*1e10)/1e10);return u}function Ej(e){var l;if(e.length===0)return 1;const t=Math.max(...e.map(a=>a.points.length));let n=0;for(let a=0;a<t;a++){let s=0;for(const i of e)s+=((l=i.points[a])==null?void 0:l.y)??0;s>n&&(n=s)}return n||1}function Cj(e){return e.map(t=>{var l;const n=(l=t.points[0])==null?void 0:l.y;return n?{...t,points:t.points.map(a=>({x:a.x,y:a.y/n*100}))}:t})}function $v(e){const t=Math.abs(e);return t<1e3?Number.isInteger(e)?String(e):e.toFixed(2):t<1e6?`${(e/1e3).toFixed(1)}k`:t<1e9?`${(e/1e6).toFixed(2)}M`:`${(e/1e9).toFixed(2)}B`}function Mj(e){return Math.abs(e)>=1e3?`$${$v(e)}`:`$${e.toLocaleString(void 0,{maximumFractionDigits:2})}`}function _j(e){const t=["B","KB","MB","GB","TB"];let n=Math.abs(e),l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l++;return`${e<0?"-":""}${n.toFixed(n<10&&l>0?1:0)} ${t[l]}`}function Zn(e,t){switch(t){case"compact":return $v(e);case"currency":return Mj(e);case"percent":return`${(e*100).toFixed(1)}%`;case"bytes":return _j(e);case"number":default:return e.toLocaleString()}}function Oh({data:e,chartWidth:t}){if(!e)return null;const n=e.x>t*.6;return o.jsxs("div",{className:"absolute pointer-events-none z-10 rounded-lg px-2.5 py-1.5 text-[10.5px] font-mono shadow-lg",style:{left:n?void 0:Math.max(0,e.x+10),right:n?Math.max(0,t-e.x+10):void 0,top:Math.max(0,e.y-10),background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--chart-ink)",minWidth:96,whiteSpace:"nowrap"},children:[o.jsx("div",{className:"font-semibold mb-1",style:{color:"var(--chart-ink-muted)"},children:e.label}),e.rows.map((l,a)=>o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsx("span",{className:"inline-block w-2 h-2 rounded-full shrink-0",style:{background:l.color}}),o.jsxs("span",{children:[l.name,":"]}),o.jsx("span",{className:"font-semibold ml-auto pl-2",style:{color:"var(--chart-ink)"},children:l.value})]},a))]})}function Aj({spec:e,width:t,height:n}){var V;const[l,a]=b.useState(null),s=e.type==="area",i=44,r=12,c=12,u=24,d=Math.max(10,t-i-r),f=Math.max(10,n-c-u),h=e.normalize?Cj(e.series):e.series,p=((V=h[0])==null?void 0:V.points)??[],x=p.length,S=h.flatMap(N=>N.points.map(D=>D.y)),w=Io(Math.min(0,...S),Math.max(...S,1),5),g=w[0],m=w[w.length-1]-g||1,v=N=>x>1?i+N/(x-1)*d:i+d/2,j=N=>c+f-(N-g)/m*f,E=h.map(N=>N.points.map((D,k)=>`${k===0?"M":"L"} ${v(k)} ${j(D.y)}`).join(" ")),M=s?h.map((N,D)=>{const k=E[D],R=v(N.points.length-1),z=v(0);return`${k} L ${R} ${c+f} L ${z} ${c+f} Z`}):[],A=e.series.length>1&&e.series.length<=4,C=N=>{const D=N.currentTarget.getBoundingClientRect(),k=N.clientX-D.left,R=x>1?Math.round((k-i)/d*(x-1)):0;a(Math.min(x-1,Math.max(0,R)))},H=l!==null&&p[l]?{x:v(l),y:j(Math.max(...h.map(N=>{var D;return((D=N.points[l])==null?void 0:D.y)??g}))),label:String(p[l].x),rows:e.series.map((N,D)=>{var z,O,Y;const k=(z=N.points[l])==null?void 0:z.y;if(k===void 0)return{name:N.name,value:"—",color:yt(D)};if(!e.normalize)return{name:N.name,value:Zn(k,e.y_format),color:yt(D)};const R=((Y=(O=h[D])==null?void 0:O.points[l])==null?void 0:Y.y)??0;return{name:N.name,value:`${Zn(k,e.y_format)} (${R.toFixed(1)})`,color:yt(D)}})}:null,T=Math.floor((x-1)/2),$=x>0?Array.from(new Set([0,T,x-1])):[];return o.jsxs("div",{className:"relative",style:{width:"100%",height:n},children:[o.jsxs("svg",{width:t,height:n,className:"overflow-visible",children:[o.jsx("defs",{children:e.series.map((N,D)=>o.jsxs("linearGradient",{id:`chart-grad-${D}`,x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:yt(D),stopOpacity:"0.22"}),o.jsx("stop",{offset:"100%",stopColor:yt(D),stopOpacity:"0"})]},D))}),w.map((N,D)=>{const k=j(N);return o.jsxs("g",{children:[o.jsx("line",{x1:i,y1:k,x2:t-r,y2:k,stroke:"var(--chart-grid)",strokeWidth:"1"}),o.jsx("text",{x:i-8,y:k+3.5,textAnchor:"end",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace"},children:e.normalize?N.toFixed(0):Zn(N,e.y_format)})]},D)}),o.jsx("line",{x1:i,y1:c+f,x2:t-r,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1"}),$.map(N=>{var D;return o.jsx("text",{x:v(N),y:n-6,textAnchor:N===0?"start":N===x-1?"end":"middle",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace",opacity:.7},children:String(((D=p[N])==null?void 0:D.x)??"")},N)}),s&&M.map((N,D)=>o.jsx("path",{d:N,fill:`url(#chart-grad-${D})`},`area-${D}`)),E.map((N,D)=>o.jsx("path",{d:N,fill:"none",stroke:yt(D),strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"},`line-${D}`)),h.map((N,D)=>{const k=N.points[N.points.length-1];if(!k)return null;const R=v(N.points.length-1),z=j(k.y),O=Math.min(R+6,t-r-4),Y=O>t-r-34;return o.jsxs("g",{children:[o.jsx("circle",{cx:R,cy:z,r:"3",fill:yt(D),stroke:"var(--s1)",strokeWidth:"1.5"}),A&&o.jsx("text",{x:Y?t-r:O,y:z+3,textAnchor:Y?"end":"start",style:{fill:"var(--chart-ink)",fontSize:9.5,fontWeight:600,fontFamily:"inherit"},children:N.name})]},`endpoint-${D}`)}),H&&o.jsx("line",{x1:H.x,y1:c,x2:H.x,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1",strokeOpacity:"0.6"}),o.jsx("rect",{x:i,y:c,width:d,height:f,fill:"transparent",onMouseMove:C,onMouseLeave:()=>a(null),style:{cursor:"crosshair"}})]}),o.jsx(Oh,{data:H,chartWidth:t})]})}function Tj({spec:e,width:t,height:n}){var A;const[l,a]=b.useState(null),s=e.type==="stacked-bar",i=44,r=12,c=12,u=24,d=Math.max(10,t-i-r),f=Math.max(10,n-c-u),h=((A=e.series[0])==null?void 0:A.points)??[],p=h.length,x=s?Ej(e.series):Math.max(...e.series.flatMap(C=>C.points.map(H=>H.y)),1),S=Io(0,x,5),w=S[S.length-1],g=C=>c+f-C/(w||1)*f,y=kj(p,[i,i+d],.3),m=2,v=e.series.length,j=s?y.bandWidth:Math.max(2,(y.bandWidth-m*(v-1))/v),E=l!==null&&h[l]?{x:y.center(l),y:c,label:String(h[l].x),rows:e.series.map((C,H)=>{var T;return{name:C.name,value:Zn(((T=C.points[l])==null?void 0:T.y)??0,e.y_format),color:yt(H)}})}:null,M=Math.floor((p-1)/2);return o.jsxs("div",{className:"relative",style:{width:"100%",height:n},children:[o.jsxs("svg",{width:t,height:n,className:"overflow-visible",children:[S.map((C,H)=>{const T=g(C);return o.jsxs("g",{children:[o.jsx("line",{x1:i,y1:T,x2:t-r,y2:T,stroke:"var(--chart-grid)",strokeWidth:"1"}),o.jsx("text",{x:i-8,y:T+3.5,textAnchor:"end",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace"},children:Zn(C,e.y_format)})]},H)}),o.jsx("line",{x1:i,y1:c+f,x2:t-r,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1"}),h.map((C,H)=>p<=1||H===0||H===p-1||H===M?o.jsx("text",{x:y.center(H),y:n-6,textAnchor:"middle",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace",opacity:.7},children:String(C.x)},`label-${H}`):null),h.map((C,H)=>{const T=y.start(H);let $=c+f;return o.jsxs("g",{onMouseEnter:()=>a(H),onMouseLeave:()=>a(null),children:[o.jsx("rect",{x:y.center(H)-y.step/2,y:c,width:y.step,height:f,fill:"transparent"}),e.series.map((V,N)=>{var O;const D=((O=V.points[H])==null?void 0:O.y)??0;if(D<=0)return null;const k=D/(w||1)*f;let R,z;return s?(R=T,z=$-k-(N>0?m:0),$=z):(R=T+N*(j+m),z=c+f-k),o.jsx("rect",{x:R,y:z,width:j,height:k,rx:"2",fill:yt(N)},N)})]},`group-${H}`)}),E&&o.jsx("line",{x1:E.x,y1:c,x2:E.x,y2:c+f,stroke:"var(--chart-axis)",strokeWidth:"1",strokeOpacity:"0.4"})]}),o.jsx(Oh,{data:E,chartWidth:t})]})}function Yu(e,t){if(typeof e=="number")return e;const n=Number(e);return Number.isFinite(n)?n:t}function zj({spec:e,width:t,height:n}){var M,A;const[l,a]=b.useState(null),s=48,i=16,r=14,c=26,u=Math.max(10,t-s-i),d=Math.max(10,n-r-c),f=e.series.flatMap(C=>C.points.map((H,T)=>Yu(H.x,T))),h=e.series.flatMap(C=>C.points.map(H=>H.y)),p=Io(Math.min(...f),Math.max(...f),4),x=Io(Math.min(0,...h),Math.max(...h,1),5),S=p[0],w=p[p.length-1],g=x[0],y=x[x.length-1],m=C=>s+(C-S)/(w-S||1)*u,v=C=>r+d-(C-g)/(y-g||1)*d,j=l?(M=e.series[l.si])==null?void 0:M.points[l.pi]:void 0,E=l&&j?{x:m(Yu(j.x,l.pi)),y:v(j.y),label:((A=e.series[l.si])==null?void 0:A.name)??"",rows:[{name:e.x_label||"x",value:String(j.x),color:yt(l.si)},{name:e.y_label||"y",value:Zn(j.y,e.y_format),color:yt(l.si)}]}:null;return o.jsxs("div",{className:"relative",style:{width:"100%",height:n},children:[o.jsxs("svg",{width:t,height:n,className:"overflow-visible",children:[x.map((C,H)=>{const T=v(C);return o.jsxs("g",{children:[o.jsx("line",{x1:s,y1:T,x2:t-i,y2:T,stroke:"var(--chart-grid)",strokeWidth:"1"}),o.jsx("text",{x:s-8,y:T+3.5,textAnchor:"end",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace"},children:Zn(C,e.y_format)})]},`y-${H}`)}),p.map((C,H)=>o.jsx("text",{x:m(C),y:n-6,textAnchor:"middle",style:{fill:"var(--chart-ink-muted)",fontSize:9.5,fontFamily:"monospace",opacity:.7},children:Zn(C)},`x-${H}`)),o.jsx("line",{x1:s,y1:r+d,x2:t-i,y2:r+d,stroke:"var(--chart-axis)",strokeWidth:"1"}),o.jsx("line",{x1:s,y1:r,x2:s,y2:r+d,stroke:"var(--chart-axis)",strokeWidth:"1"}),e.series.map((C,H)=>C.points.map((T,$)=>{const V=m(Yu(T.x,$)),N=v(T.y);return o.jsxs("g",{children:[o.jsx("circle",{cx:V,cy:N,r:"12",fill:"transparent",onMouseEnter:()=>a({si:H,pi:$}),onMouseLeave:()=>a(null),style:{cursor:"pointer"}}),o.jsx("circle",{cx:V,cy:N,r:"4",fill:yt(H),stroke:"var(--s1)",strokeWidth:"1.5"})]},`${H}-${$}`)})),E&&l&&o.jsx("circle",{cx:E.x,cy:E.y,r:"7",fill:"none",stroke:yt(l.si),strokeWidth:"1.5"})]}),o.jsx(Oh,{data:E,chartWidth:t})]})}function Dj({spec:e}){var n;const t=((n=e.series[0])==null?void 0:n.points.map(l=>l.x))??[];return o.jsxs("div",{children:[o.jsx("div",{className:"overflow-x-auto overflow-y-auto max-h-[260px] scrollbar-thin",children:o.jsxs("table",{className:"w-full text-[11.5px] font-mono",children:[o.jsx("thead",{children:o.jsxs("tr",{style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("th",{className:"text-left py-1.5 pr-3 font-medium",style:{color:"var(--chart-ink-muted)"},children:e.x_label||"x"}),e.series.map(l=>o.jsx("th",{className:"text-right py-1.5 pl-3 font-medium",style:{color:"var(--chart-ink-muted)"},children:l.name},l.name))]})}),o.jsx("tbody",{children:t.map((l,a)=>o.jsxs("tr",{style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 40%, transparent)"},children:[o.jsx("td",{className:"py-1 pr-3",style:{color:"var(--chart-ink)",fontVariantNumeric:"tabular-nums"},children:String(l)}),e.series.map(s=>{var i;return o.jsx("td",{className:"text-right py-1 pl-3",style:{color:"var(--chart-ink)",fontVariantNumeric:"tabular-nums"},children:Zn(((i=s.points[a])==null?void 0:i.y)??0,e.y_format)},s.name)})]},a))})]})}),e.normalize&&o.jsx("div",{className:"mt-2 text-[10.5px] italic",style:{color:"var(--chart-ink-muted)"},children:"Chart is indexed to 100 at the first point; this table shows raw values."})]})}function Rj(){return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-xl p-4 flex items-center gap-2",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("div",{className:"w-[6px] h-[6px] rounded-full shrink-0 animate-pulse",style:{background:"var(--muted)"}}),o.jsx("div",{className:"text-[11.5px]",style:{color:"var(--muted)"},children:"Rendering chart…"})]})})}function tm({message:e,raw:t}){return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-xl p-4",style:{background:"color-mix(in srgb, var(--red) 6%, var(--s2))",border:"1px solid color-mix(in srgb, var(--red) 25%, var(--b1))"},children:[o.jsx("div",{className:"text-[12px] font-semibold mb-1.5",style:{color:"var(--red)"},children:"Chart could not be rendered"}),o.jsx("div",{className:"text-[11.5px] mb-2",style:{color:"var(--text)"},children:e}),o.jsx("pre",{className:"text-[10.5px] font-mono overflow-x-auto whitespace-pre-wrap",style:{color:"var(--muted)"},children:typeof t=="string"?t:JSON.stringify(t,null,2)})]})})}function Oj({spec:e}){const t=(n,l)=>{switch(e.type){case"line":case"area":return o.jsx(Aj,{spec:e,width:n,height:l});case"bar":case"stacked-bar":return o.jsx(Tj,{spec:e,width:n,height:l});case"scatter":return o.jsx(zj,{spec:e,width:n,height:l});default:return null}};return o.jsx(jj,{spec:e,renderChart:t,renderTable:()=>o.jsx(Dj,{spec:e})})}function Hj({spec:e,error:t,pending:n,rawInput:l}){return t?o.jsx(tm,{message:t,raw:l??e}):n?o.jsx(Rj,{}):Nj(e)?o.jsx(Oj,{spec:e}):o.jsx(tm,{message:"The chart data did not match the expected format.",raw:l??e})}const nm=["what are we discovering today?","greetings from the lab!","lab coat is on ... ","the system is radioactive","what is our next experiment?","atomic levels are stable!","what is our next reaction?","geiger counter is ticking...","mobile X-ray unit deployed","nobel-tier assist activated","emitting helpful isotopes","cathode rays engaged"];function lm(){return nm[Math.floor(Math.random()*nm.length)]}function Bv({content:e}){const[t,n]=b.useState(!0);return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden cursor-pointer select-none transition-all duration-150",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},onClick:()=>n(!t),children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{background:"color-mix(in srgb, var(--s2) 80%, transparent)"},children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",className:"shrink-0",style:{opacity:.7},children:[o.jsx("path",{d:"M12 2a7 7 0 0 0-7 7c0 3 2 5 2 8h10c0-3 2-5 2-8a7 7 0 0 0-7-7z"}),o.jsx("circle",{cx:"9",cy:"9",r:"1",fill:"currentColor"}),o.jsx("circle",{cx:"15",cy:"9",r:"1",fill:"currentColor"})]}),o.jsx("span",{className:"text-[11.5px] font-medium text-text font-mono",children:t?"Hide thinking":"Show thinking"}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${t?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),t&&o.jsx("div",{className:"px-3 py-2.5",style:{borderTop:"1px solid var(--b1)",background:"color-mix(in srgb, var(--s1) 60%, transparent)"},children:o.jsx("pre",{className:"text-[11px] text-muted leading-relaxed whitespace-pre-wrap font-mono max-h-[300px] overflow-y-auto",children:e})})]})})}function Uv({toolCalls:e}){const[t,n]=b.useState(!1);return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden mb-1",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer select-none transition-all duration-150",style:{background:"color-mix(in srgb, var(--s2) 80%, transparent)"},onClick:()=>n(!t),children:[o.jsx("div",{className:"w-[14px] h-[14px] rounded-[3px] flex items-center justify-center",style:{background:"color-mix(in srgb, var(--gold) 15%, var(--s3))"},children:o.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",style:{opacity:.7},children:[o.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),o.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),o.jsxs("span",{className:"text-[11.5px] font-medium text-text font-mono",children:[e.length," tool call",e.length>1?"s":""]}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${t?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),t&&e.map((l,a)=>o.jsxs("div",{className:"px-3 py-2.5 first:border-t-0",style:{borderTop:"1px solid var(--b1)",background:"color-mix(in srgb, var(--s1) 60%, transparent)"},children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[o.jsx("span",{className:"text-[11.5px] font-semibold font-mono",style:{color:"var(--gold)"},children:l.name}),o.jsx("span",{className:"text-xs text-muted font-mono truncate max-w-[250px]",children:l.args})]}),o.jsx("pre",{className:"text-[11px] text-muted font-mono leading-[1.5] overflow-x-auto whitespace-pre-wrap",children:l.input?qv(l.input):""})]},a))]})})}function Lj({event:e}){const[t,n]=b.useState(!1);return o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden mb-1",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer select-none transition-all duration-150",style:{background:"color-mix(in srgb, var(--s2) 80%, transparent)"},onClick:()=>n(!t),children:[o.jsx("div",{className:"w-[14px] h-[14px] rounded-[3px] flex items-center justify-center",style:{background:"color-mix(in srgb, var(--red) 15%, var(--s3))"},children:o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"var(--red)",strokeWidth:"1.5",children:o.jsx("path",{d:"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"})})}),o.jsxs("span",{className:"text-[11.5px] font-semibold text-fg font-mono",children:["Heartbeat Brief (",e.scheduleType,")"]}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${t?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),t&&o.jsx("div",{className:"px-3 py-3 markdown-body",style:{borderTop:"1px solid var(--b1)",background:"color-mix(in srgb, var(--s1) 60%, transparent)"},children:o.jsx("div",{dangerouslySetInnerHTML:{__html:Ko(e.formattedText||"")}})})]})})}function $j({message:e,time:t}){return o.jsx("div",{className:"px-3 py-1.5 animate-fadeIn",children:o.jsxs("div",{className:"p-3.5 rounded-xl backdrop-blur-md shadow-lg max-w-[480px] flex gap-3 transition-all duration-200 relative overflow-hidden group",style:{background:"linear-gradient(135deg, color-mix(in srgb, var(--gold) 8%, var(--s2)), color-mix(in srgb, var(--gold) 4%, var(--s1)))",border:"1px solid color-mix(in srgb, var(--gold) 20%, var(--b1))"},children:[o.jsx("div",{className:"absolute top-0 right-0 w-24 h-24 rounded-full filter blur-xl opacity-30 group-hover:scale-125 transition-transform duration-500",style:{background:"var(--gold)"}}),o.jsxs("div",{className:"flex items-center justify-center w-8 h-8 rounded-lg shrink-0 relative",style:{background:"color-mix(in srgb, var(--gold) 15%, transparent)",color:"var(--gold)"},children:[o.jsx("span",{className:"absolute inset-0 rounded-lg animate-ping opacity-50",style:{background:"color-mix(in srgb, var(--gold) 20%, transparent)",animationDuration:"2s"}}),o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"animate-wiggle",children:[o.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),o.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})]}),o.jsxs("div",{className:"flex-1 min-w-0 flex flex-col justify-center",children:[o.jsxs("div",{className:"flex items-center justify-between gap-2 mb-1 select-none",children:[o.jsx("span",{className:"font-bold text-xs tracking-wide uppercase",style:{color:"var(--gold)"},children:"Reminder Fired"}),o.jsx("span",{className:"text-[10px] text-muted font-mono",children:t})]}),o.jsx("div",{className:"text-[13px] text-text leading-relaxed font-semibold",children:e})]})]})})}function On(e){return new Date(e).toLocaleTimeString("en",{hour:"2-digit",minute:"2-digit",second:"2-digit"})}function qv(e){if(!e||Object.keys(e).length===0)return"";const t=Object.entries(e);if(t.length===1){const n=t[0];if(!n)return"";const l=n[0],a=n[1],s=typeof a=="object"?JSON.stringify(a,null,2):String(a);return`${l}: ${s}`}return t.map(([n,l])=>{const a=typeof l=="object"?JSON.stringify(l,null,2):String(l);return`${n}: ${a}`}).join(`
113
+ `)}function Bj(e,t){if(e==="Bash")return String(t.command||"").slice(0,80);const n=t.file_path||t.path||"";return n?String(n):Object.entries(t).map(([l,a])=>`${l}: ${String(a).slice(0,60)}`).join(", ")}function Uj(e,t){const n=e.find(l=>l.type==="tool-result"&&l.toolCallId===t);if(n)return{output:n.output,error:n.error}}function qj(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br>")}ve.setOptions({gfm:!0,breaks:!0});function Ko(e){try{return ve.parse(e)}catch{return qj(e)}}function Yv({toolCallId:e,name:t,input:n,decision:l,events:a,rpc:s,mode:i}){const[r,c]=b.useState(!1),[u,d]=b.useState(null),f=a.find(S=>S.type==="approval-decision"&&S.toolCallId===e),h=f?f.decision:u,p=l==="ask"&&!h,x=async S=>{if(s){c(!0);try{await s.approvalDecide(e,S),d(S)}catch(w){console.error("Failed to submit tool approval decision:",w)}finally{c(!1)}}};if(!p){const S=h==="allow";return o.jsxs("div",{className:"px-3 py-1.5 flex items-center gap-2.5 animate-fadeIn select-none",children:[o.jsx("div",{className:`flex items-center justify-center w-5 h-5 rounded-full ${S?"bg-green-500/10 text-green-500":"bg-red-500/10 text-red-500"} shrink-0`,children:o.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:S?o.jsx("polyline",{points:"20 6 9 17 4 12"}):o.jsxs(o.Fragment,{children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})}),o.jsxs("div",{className:"flex items-baseline gap-1.5 text-xs text-muted",children:[o.jsx("span",{className:"font-semibold text-fg",children:S?"Authorized":"Blocked"}),o.jsx("span",{children:"action:"}),o.jsx("code",{className:"font-mono bg-s3 border border-b1 px-1.5 py-0.5 rounded text-[11px] text-fg",children:t})]})]})}return i==="auto"?null:o.jsx("div",{className:"fixed inset-0 z-[999] flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-fadeIn",children:o.jsxs("div",{className:"w-full max-w-[480px] p-6 rounded-2xl border border-b2 bg-s2/95 backdrop-blur-md shadow-2xl transition-all duration-200 transform scale-100 animate-scaleIn",children:[o.jsxs("div",{className:"flex items-start gap-4 border-b border-b1 pb-4 mb-4",children:[o.jsx("div",{className:"flex items-center justify-center w-10 h-10 rounded-xl bg-yellow-500/10 text-yellow-500 shrink-0",children:o.jsx("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o.jsx("path",{d:"M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"})})}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("span",{className:"font-bold text-fg text-base block mb-0.5",children:"Authorization Required"}),o.jsx("span",{className:"text-[12px] text-muted",children:"The agent requires permission to run this action."})]})]}),o.jsxs("div",{className:"mb-4",children:[o.jsx("div",{className:"text-[9px] text-muted2 font-mono uppercase tracking-wider mb-1.5 select-none",children:"Action / Tool"}),o.jsx("div",{className:"flex items-center",children:o.jsx("code",{className:"font-mono bg-s3 border border-b1 px-2.5 py-1 rounded-lg text-xs text-fg font-semibold",children:t})})]}),o.jsxs("div",{className:"bg-s1 rounded-xl border border-b1 p-4 mb-6 max-h-[220px] overflow-y-auto scrollbar-thin",children:[o.jsx("div",{className:"text-[9px] text-muted2 font-mono uppercase tracking-wider mb-1.5 select-none",children:"Arguments"}),o.jsx("pre",{className:"font-mono text-[11.5px] text-text overflow-x-auto m-0 leading-normal",children:qv(n)})]}),o.jsxs("div",{className:"flex items-center gap-3",children:[o.jsxs("button",{onClick:()=>x("allow"),disabled:r,className:"flex-1 py-2 px-4 rounded-xl bg-green-600 hover:bg-green-500 text-white font-semibold text-[13px] shadow-lg shadow-green-600/10 hover:shadow-green-600/20 transition-all duration-150 active:scale-[0.98] disabled:opacity-50 disabled:pointer-events-none cursor-pointer flex items-center justify-center gap-1.5",children:[o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Approve Action"]}),o.jsxs("button",{onClick:()=>x("deny"),disabled:r,className:"py-2 px-3 rounded-xl bg-s3 border border-b2 hover:bg-s4 text-fg hover:text-text hover:border-b3 font-semibold text-[13px] transition-all duration-150 active:scale-[0.98] disabled:opacity-50 disabled:pointer-events-none cursor-pointer flex items-center justify-center gap-1.5",children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]}),"Deny"]})]})]})})}function Yj({blocks:e,blockCount:t,response:n,time:l,events:a,rpc:s}){const[i,r]=b.useState(!1);return e&&e.length>0||!!n?o.jsx("div",{className:"px-3 py-1 animate-fadeIn",children:o.jsxs("div",{className:"rounded-lg overflow-hidden cursor-pointer select-none transition-all duration-150",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 2px 8px rgba(0,0,0,0.15)"},onClick:()=>r(!i),children:[o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2",style:{background:"var(--bg)"},children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",className:"shrink-0",style:{opacity:.7},children:[o.jsx("circle",{cx:"12",cy:"12",r:"2"}),o.jsx("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4"}),o.jsx("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",transform:"rotate(60 12 12)"}),o.jsx("ellipse",{cx:"12",cy:"12",rx:"10",ry:"4",transform:"rotate(120 12 12)"})]}),o.jsxs("span",{className:"text-[11.5px] font-medium text-text font-mono",children:[t," agent action",t>1?"s":""]}),n&&o.jsxs("span",{className:"text-[10px] text-muted2 font-mono truncate max-w-[120px]",title:n,children:["“",n.slice(0,60),"...","”"]}),l&&o.jsx("span",{className:"text-[10px] text-muted2 font-mono",children:l}),o.jsx("div",{className:"flex-1"}),o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:`text-muted transition-transform duration-200 ${i?"rotate-180":""}`,children:o.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),i&&o.jsxs("div",{className:"px-1 py-1",style:{borderTop:"1px solid var(--b1)",background:"var(--bg)"},onClick:u=>u.stopPropagation(),children:[e.map((u,d)=>{if(u.type==="thinking")return o.jsx(Bv,{content:u.content},d);if(u.type==="tool-group"){const f=u;return f.toolCalls.length>0?o.jsx(Uv,{toolCalls:f.toolCalls},d):null}return u.type==="approval-request"?o.jsx(Yv,{toolCallId:u.toolCallId,name:u.name,input:u.input,decision:u.decision,events:a||[],rpc:s||null,mode:u.mode},d):null}),n&&o.jsxs("div",{className:"mt-3",children:[o.jsx("div",{className:"flex items-baseline gap-2 mb-1",children:o.jsx("span",{className:"text-[10px] font-semibold text-fg",style:{color:"var(--gold)"},children:"curie-agent"})}),o.jsx("div",{className:"text-[13px] text-text leading-[1.65] markdown-body chat-msg-agent pl-3",dangerouslySetInnerHTML:{__html:Ko(n)}})]})]})]})}):null}function Vj(e){switch(e.type){case"user-prompt":return{type:"user",content:e.text||"",time:On(e.timestamp)};case"assistant-delta":return{type:"assistant",content:e.text||"",time:On(e.timestamp)};case"thinking-delta":return{type:"thinking",content:e.text||"",time:On(e.timestamp)};case"heartbeat-brief":return{type:"heartbeat-brief",content:e.formattedText||"",time:On(e.timestamp),event:e};case"tool-call":{const t=e.name||"tool",n=e.input||{};if(t==="Chart")return{type:"chart",toolCallId:e.toolCallId||"",rawInput:n,time:On(e.timestamp)};const l=Bj(t,n);return{type:"tool-group",content:"",time:"",toolCalls:[{name:t,args:l,input:n}]}}case"approval-request":{const t=e.toolCallId,n=e.name||"tool";if(n==="Chart")return null;const l=e.input||{},a=e.decision,s=e.mode;return{type:"approval-request",toolCallId:t,name:n,input:l,decision:a,mode:s,time:On(e.timestamp)}}case"cron-task-fired":{const t=e.message||"",n=e.taskId||"";return{type:"reminder-fired",message:t,taskId:n,time:On(e.timestamp)}}case"context-warning":return{type:"assistant",content:e.message||"",time:On(e.timestamp)};case"error":return{type:"error",content:e.message||`An error occurred (code: ${e.code||"unknown"})`,time:On(e.timestamp)};default:return null}}function Xj(e){const t=[];let n=[],l="",a=!1,s="",i=null,r=0;const c=()=>{a&&s&&(n.push({type:"thinking",content:s,time:""}),a=!1,s="")},u=()=>{var h;if(n.length===0)return;let f=0;for(let p=r;p<n.length;p++){const x=n[p];x.type==="tool-group"?f+=((h=x.toolCalls)==null?void 0:h.length)||1:f+=1}i?(i.blocks=[...i.blocks,...n.slice(r)],i.blockCount+=f):(i={type:"agent-actions",blocks:[...n],blockCount:f,response:void 0,time:n[0].time||""},t.push(i)),r=n.length},d=()=>{c(),u(),l&&t.push({type:"assistant",content:l,time:""}),n=[],l="",i=null,r=0};for(const f of e){const h=Vj(f);if(h)if(h.type==="user"||h.type==="error"||h.type==="heartbeat-brief"||h.type==="reminder-fired")d(),t.push(h);else if(h.type==="assistant")l+=h.content;else if(h.type==="thinking")a=!0,s+=h.content||"";else if(h.type==="tool-group"){c();const p=h;n.length>0&&n[n.length-1].type==="tool-group"?n[n.length-1].toolCalls.push(...p.toolCalls||[]):n.push({type:"tool-group",content:"",time:h.time||"",toolCalls:p.toolCalls||[]}),u()}else h.type==="approval-request"?(c(),n.push({type:"approval-request",content:"",time:h.time||"",toolCallId:h.toolCallId||"",name:h.name||"tool",input:h.input||{},decision:h.decision||"ask",mode:h.mode}),u()):(d(),t.push(h))}return d(),t}function Gj({cmdResult:e,rpc:t,className:n,activeSessionId:l,onCreateSession:a,onClearCmdResult:s,events:i,addLiveEvent:r,totalTokens:c,contextTokens:u,costUsd:d,onSwitchView:f}){const{ws:h,connected:p,connectionStatus:x}=Cn(),[S,w]=b.useState(!1),[g,y]=b.useState(null),[m,v]=b.useState(""),j=b.useRef(null),E=b.useRef(null),[M,A]=b.useState(lm);b.useEffect(()=>{E.current&&!l&&A(lm()),E.current=l},[l]),b.useEffect(()=>{if(x==="connected")y(null);else if(x==="reconnecting")y(null);else{const N=setTimeout(()=>{y("Disconnected from daemon. Check that the daemon is running.")},2e3);return()=>clearTimeout(N)}},[p,x]);const C=b.useMemo(()=>Xj(i),[i]),H=b.useRef(!0),T=b.useCallback(()=>{j.current&&(j.current.scrollTop=j.current.scrollHeight,H.current=!0)},[]);b.useEffect(()=>{const N=j.current;if(!N)return;const D=()=>{const k=N.scrollHeight-N.scrollTop-N.clientHeight<80;H.current=k};return N.addEventListener("scroll",D,{passive:!0}),()=>N.removeEventListener("scroll",D)},[]),b.useEffect(()=>{H.current&&T()},[C,S,T]),b.useEffect(()=>{T()},[T]),b.useEffect(()=>{e&&(console.log("Command palette result:",e),v(e),s==null||s())},[e,s]);const $=b.useCallback(async N=>{var k,R;if(!t){y("Not connected to daemon. Make sure the daemon is running.");return}if(w(!0),y(null),T(),N.startsWith("/")){const z=N.match(/^\/([^\s]+)(?:\s+(.*))?$/);if(z){const O=z[1].toLowerCase(),Y=(z[2]||"").trim();if(O==="heartbeat"){r({type:"user-prompt",id:`local-prompt-${Date.now()}`,timestamp:Date.now(),text:N});const X=Y.toLowerCase();if(X==="now"){r({type:"assistant-delta",id:`local-running-${Date.now()}`,timestamp:Date.now(),text:"Executing immediate heartbeat cycle in background..."});try{await t.heartbeatRun(),w(!1)}catch(L){const U=L instanceof Error?L.message:String(L);r({type:"error",id:`local-err-${Date.now()}`,timestamp:Date.now(),message:`Heartbeat failed: ${U}`}),w(!1)}}else if(X==="status"||X==="")try{const L=await t.heartbeatStatus(),U=(L==null?void 0:L.schedule)==="on",_=(L==null?void 0:L.intraday)||"(not set)",B=`### Heartbeat Cycle Status:
114
114
  * **Enabled**: \`${U?"yes":"no"}\`
115
115
  * **Intraday**: \`${_}\`
116
116
  * **Daily**: \`${(L==null?void 0:L.daily)||"6:00"}\`
@@ -136,11 +136,11 @@ ${B.join(`
136
136
  `)}`})}w(!1)}catch(U){r({type:"error",id:`local-err-${Date.now()}`,timestamp:Date.now(),message:`Wiki search failed: ${U instanceof Error?U.message:String(U)}`}),w(!1)}else if(X==="lint")try{const U=await t.wikiLint(),_=(U==null?void 0:U.issues)??[];if(_.length===0)r({type:"assistant-delta",id:`local-wiki-${Date.now()}`,timestamp:Date.now(),text:"Wiki is healthy — no issues found."});else{const B=_.map(G=>`- **[${G.type}]** ${G.slug?`\`${G.slug}\`: `:""}${G.message}`);r({type:"assistant-delta",id:`local-wiki-${Date.now()}`,timestamp:Date.now(),text:`### Wiki Lint (${_.length} issues)
137
137
 
138
138
  ${B.join(`
139
- `)}`})}w(!1)}catch(U){r({type:"error",id:`local-err-${Date.now()}`,timestamp:Date.now(),message:`Wiki lint failed: ${U instanceof Error?U.message:String(U)}`}),w(!1)}else r({type:"assistant-delta",id:`local-wiki-${Date.now()}`,timestamp:Date.now(),text:"Wiki commands:\n- `/wiki` — Open wiki view\n- `/wiki list` — List all pages\n- `/wiki search <q>` — Search pages\n- `/wiki lint` — Health check"}),w(!1);return}}}const D=l||"";try{const z=await t.sessionSend(D,N,"webui");z!=null&&z.sessionId&&!l&&(h==null||h.subscribe(z.sessionId),a==null||a(z.sessionId))}catch(z){const O=z instanceof Error?z.message:String(z);y(`Failed to send: ${O}`),w(!1)}},[t,h,l,T,a,r]);b.useEffect(()=>{h&&(h.on("assistant-stop",()=>w(!1)),h.on("error",()=>w(!1)))},[h]);const V=b.useCallback(async()=>{if(!(!t||!l)){w(!1),y(null),T();try{await t.sessionCancel(l)}catch(N){const D=N instanceof Error?N.message:String(N);y(`Failed to cancel: ${D}`)}}},[t,l,T]);return o.jsxs("div",{className:`flex flex-col h-full ${n||""}`,children:[o.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-thin",ref:j,children:[C.length===0&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted",children:[o.jsx("div",{className:"text-lg mb-2 font-display",style:{color:"var(--cream)"},children:"curie"}),o.jsx("div",{className:"text-sm text-muted",children:M})]}),o.jsxs("div",{className:"py-4 pb-6",children:[C.map((N,D)=>{if(N.type==="thinking")return o.jsx(Bv,{content:N.content},`thinking-${D}`);if(N.type==="user")return o.jsx("div",{className:"flex flex-row-reverse px-3 py-0.5 animate-fadeIn transition-colors duration-100",children:o.jsxs("div",{className:"flex flex-1 flex-col items-end min-w-0",children:[o.jsxs("div",{className:"flex flex-row-reverse items-baseline gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-semibold",style:{color:"var(--cream)"},children:"you"}),o.jsx("span",{className:"text-xs text-muted font-mono",children:N.time})]}),o.jsx("div",{className:"text-[13px] text-text leading-[1.65] chat-msg-user rounded-t-[10px] rounded-bl-[10px] px-3.5 py-2.5 max-w-[480px] markdown-body",dangerouslySetInnerHTML:{__html:Ko(N.content)}})]})},D);if(N.type==="tool-group"){const k=N;if(k.toolCalls.length>0)return o.jsx(Uv,{toolCalls:k.toolCalls},D)}if(N.type==="agent-actions"){const k=N;return o.jsx(qj,{blocks:k.blocks,blockCount:k.blockCount,time:k.time,events:i,rpc:t},`agent-${k.time||D}`)}if(N.type==="approval-request")return o.jsx(Yv,{toolCallId:N.toolCallId,name:N.name,input:N.input,decision:N.decision,events:i,rpc:t,mode:N.mode},D);if(N.type==="heartbeat-brief"){const k=N;return o.jsx(Hj,{event:k.event},D)}return N.type==="reminder-fired"?o.jsx(Lj,{message:N.message,time:N.time},D):N.type==="chart"?o.jsx(Oj,{spec:N.spec,error:Bj(i,N.toolCallId)},D):N.type==="error"?o.jsxs("div",{className:"px-3 py-0.5 animate-fadeIn transition-colors duration-100",children:[o.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-semibold",style:{color:"var(--red)"},children:"error"}),o.jsx("span",{className:"text-xs text-muted font-mono",children:N.time})]}),o.jsx("div",{className:"text-[13px] text-red leading-[1.65] rounded-lg px-3 py-2 bg-red/5 border border-red/10",children:N.content})]},D):o.jsxs("div",{className:"px-3 py-0.5 animate-fadeIn transition-colors duration-100",children:[o.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-semibold",style:{color:"var(--gold)"},children:"curie-agent"}),o.jsx("span",{className:"text-xs text-muted font-mono",children:N.time})]}),o.jsx("div",{className:"text-[13px] text-text leading-[1.65] markdown-body chat-msg-agent pl-3",dangerouslySetInnerHTML:{__html:Ko(N.content)}})]},D)}),S&&o.jsx("div",{className:"flex items-center px-3 py-2",children:o.jsxs("div",{className:"flex gap-1.5",children:[o.jsx("span",{className:"w-[5px] h-[5px] bg-muted2 rounded-full animate-dot inline-block",style:{animation:"tdot 1.4s infinite"}}),o.jsx("span",{className:"w-[5px] h-[5px] bg-muted2 rounded-full animate-dot inline-block",style:{animation:"tdot 1.4s infinite 0.2s"}}),o.jsx("span",{className:"w-[5px] h-[5px] bg-muted2 rounded-full animate-dot inline-block",style:{animation:"tdot 1.4s infinite 0.4s"}})]})})]})]}),o.jsxs("div",{className:"flex-shrink-0",children:[g&&o.jsx("div",{className:"px-3 py-1.5 bg-red/10 border-t border-red/20",children:o.jsx("div",{className:"text-[11px] text-red font-mono",children:g})}),o.jsx(wj,{onSend:$,onCancel:S?V:void 0,cmdInput:m,onClearCmdInput:()=>v(""),totalTokens:c,contextTokens:u,costUsd:d})]})]})}function Gj(e,t,n,l){if(l){const[r,c]=l.split(";"),u=parseFloat(r||"0"),d=parseFloat(c||"0");if(!isNaN(u)&&!isNaN(d))return(t*u+n*d)/1e6}const a={opus:{in:15,out:75},sonnet:{in:3,out:15},haiku:{in:.8,out:4},"gpt-4o":{in:2.5,out:10},"gpt-4":{in:5,out:15},qwen:{in:.112,out:.224}},s=Object.keys(a).find(r=>e.toLowerCase().includes(r))||"sonnet",i=a[s];return(t*i.in+n*i.out)/1e6}function Qj({cmdResult:e,onClearCmdResult:t,rpc:n,className:l,activeSessionId:a,onCreateSession:s,events:i,addLiveEvent:r,onSwitchView:c}){var y;const{get:u,providers:d}=kh(),f=u("model"),h=u("current_provider")||"anthropic",p=(y=d.find(m=>m.name===h))==null?void 0:y.model_cost;let x=0,S=0,w=0;const g=a?i.filter(m=>m.type==="usage"):[];if(g.length>0){x=g.reduce((v,j)=>v+(j.inputTokens||0)+(j.outputTokens||0),0);const m=g[g.length-1];S=m&&m.inputTokens||0,w=g.reduce((v,j)=>v+Gj(f||"sonnet",j.inputTokens||0,j.outputTokens||0,p),0)}return o.jsx("div",{className:`flex flex-col h-full ${l||""}`,children:o.jsx(Xj,{cmdResult:e,onClearCmdResult:t,rpc:n,activeSessionId:a,onCreateSession:s,events:i,addLiveEvent:r,totalTokens:x,contextTokens:S,costUsd:w,onSwitchView:c})})}function Zj({rpc:e,className:t}){const[n,l]=b.useState(null),[a,s]=b.useState(null),[i,r]=b.useState(null),[c,u]=b.useState(!0);b.useEffect(()=>{e&&Promise.all([e.configGet("channels.bot_token").catch(()=>null),e.configGet("channels.user_id").catch(()=>null),e.configGet("channels.chat_id").catch(()=>null)]).then(([f,h,p])=>{l(f),s(h),r(p)}).finally(()=>u(!1))},[e]);const d=!!n&&!!a;return o.jsxs("div",{className:`flex-1 overflow-y-auto p-7 scrollbar-thin ${t||""}`,children:[o.jsxs("div",{className:"flex items-center justify-between mb-5",children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight",children:"Channels"}),o.jsxs("button",{className:"flex items-center gap-1 bg-transparent border border-b2 rounded px-3 py-1.5 text-muted text-xs hover:border-b3 hover:text-fg transition-colors duration-100",children:[o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[o.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Connect"]})]}),c?o.jsx("div",{className:"flex items-center justify-center py-10 text-muted",children:"Loading..."}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg mb-0.5 bg-s2",children:[o.jsx("div",{className:"w-8 h-8 rounded-lg bg-s3 flex items-center justify-center shrink-0 text-base",children:d?"📱":"🔌"}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[13px] font-medium text-fg",children:d?"Telegram Connected":"Not Connected"}),o.jsx("div",{className:"text-xs text-muted truncate",children:d?`Bot configured for user ${a}`:"Configure a Telegram bot to enable channel messaging"})]}),o.jsx("div",{className:`w-[6px] h-[6px] rounded-full shrink-0 ${d?"bg-green":"bg-muted2"}`})]}),d&&o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] overflow-hidden mt-3",children:[o.jsx("div",{className:"text-[12px] font-medium text-text2 px-4 py-3 border-b border-b1",children:"Channel Configuration"}),o.jsx(Vu,{label:"Bot Token",value:(n==null?void 0:n.slice(0,12))+"..."||""}),o.jsx(Vu,{label:"User ID",value:a||""}),o.jsx(Vu,{label:"Chat ID",value:i||"not set"})]})]})]})}function Vu({label:e,value:t}){return o.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-b1/50",children:[o.jsx("span",{className:"text-xs text-muted",children:e}),o.jsx("span",{className:"text-xs text-text font-mono",children:t})]})}function Ij({rpc:e,className:t}){const{ws:n}=Cn(),[l,a]=b.useState(null),[s,i]=b.useState([]),[r,c]=b.useState(!0),[u,d]=b.useState(null),[f,h]=b.useState(null),p=b.useRef(null),x=b.useCallback(async()=>{if(e)try{const[_,B]=await Promise.all([e.sessionStats(),e.sessionList()]);_&&a(_),Array.isArray(B)&&i(B)}catch(_){console.error("[StatsView] Failed to load statistics:",_)}},[e]);if(b.useEffect(()=>{c(!0),x().finally(()=>c(!1))},[x]),b.useEffect(()=>{if(!n)return;const _=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(x,2e3)},B=n.on("session-stop",_),G=n.on("session-start",_);return()=>{B(),G(),p.current&&clearTimeout(p.current)}},[n,x]),r)return o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted py-20 select-none animate-pulse",children:[o.jsx("div",{className:"w-8 h-8 rounded-full mb-4 animate-spin",style:{background:"conic-gradient(from 0deg, transparent, var(--gold))",mask:"radial-gradient(farthest-side, transparent calc(100% - 2px), #000 0)",WebkitMask:"radial-gradient(farthest-side, transparent calc(100% - 2px), #000 0)"}}),o.jsx("span",{className:"text-[13px] font-mono",style:{color:"var(--gold)",opacity:.7},children:"Compiling operations telemetry..."})]});if(!l||l.summary.totalSessions===0)return o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted py-20 select-none",children:[o.jsx("div",{className:"w-14 h-14 rounded-xl flex items-center justify-center mb-4",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 4px 16px rgba(0,0,0,0.2)"},children:o.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",style:{opacity:.6},children:[o.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),o.jsx("path",{d:"M21 12H3M12 3v18"})]})}),o.jsx("div",{className:"text-[14px] font-display font-semibold",style:{color:"var(--cream)"},children:"No operational data found"}),o.jsx("div",{className:"text-[11.5px] text-muted mt-1",children:"Start a conversation to generate metrics."})]});const{summary:S,hourly:w,entrypoints:g,topTools:y}=l,m=_=>_<1e3?String(_):_<1e6?`${(_/1e3).toFixed(1)}k`:`${(_/1e6).toFixed(2)}M`,v=600,j=140,E=45,M=15,A=15,C=25,H=Math.max(...w.map(_=>_.inputTokens+_.outputTokens),1),T=v-E-M,$=j-A-C,V=w.map((_,B)=>{const G=_.inputTokens+_.outputTokens,q=E+B/23*T,Q=A+$-G/H*$;return{x:q,y:Q,..._}}),N=V.length>0?`${V.map((_,B)=>`${B===0?"M":"L"} ${_.x} ${_.y}`).join(" ")} L ${V[V.length-1].x} ${A+$} L ${V[0].x} ${A+$} Z`:"",D=V.length>0?V.map((_,B)=>`${B===0?"M":"L"} ${_.x} ${_.y}`).join(" "):"",k=600,R=140,z=Math.max(...w.map(_=>Math.max(_.toolCalls,_.messages)),1),O=k-E-M,Y=R-A-C,X=O/24*.75,L=O/24*.25,U=g.webui+g.tui+g.telegram+g.heartbeat||1;return o.jsxs("div",{className:`flex-1 overflow-y-auto p-4 md:p-7 scrollbar-thin ${t||""}`,children:[o.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-6",children:[o.jsxs("div",{children:[o.jsx("h2",{className:"text-lg font-display font-semibold tracking-tight",style:{color:"var(--cream)"},children:"System Telemetry"}),o.jsx("p",{className:"text-[11.5px] text-muted mt-0.5",children:"Real-time daily operations telemetry and interface execution load."})]}),o.jsxs("span",{className:"self-start sm:self-auto text-[11px] font-mono rounded-full px-3 py-1 text-muted select-none",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)"},children:["Today: ",new Date().toLocaleDateString(void 0,{weekday:"long",month:"short",day:"numeric"})]})]}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[o.jsx(Tr,{label:"Today's Sessions",value:String(S.totalSessionsToday),subtitle:"conversations today"}),o.jsx(Tr,{label:"Operational Cost",value:`$${S.totalCost.toFixed(4)}`,subtitle:"estimated total",isGreen:!0}),o.jsx(Tr,{label:"Volume Consumed",value:m(S.totalTokens),subtitle:"total system tokens"}),o.jsx(Tr,{label:"Agent Executions",value:String(S.totalToolCalls),subtitle:"integrated tool calls"})]}),o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5 mb-6",children:[o.jsxs("div",{className:"glass-card rounded-xl p-5 flex flex-col relative select-none",children:[o.jsxs("div",{className:"flex items-center justify-between h-6 mb-4",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:"var(--gold)",opacity:.8},children:"Hourly Token Consumption"}),o.jsx("span",{className:`text-[11px] font-mono text-fg px-2 py-0.5 rounded-[4px] transition-opacity duration-150 ${u!==null?"opacity-100":"opacity-0 pointer-events-none"}`,style:{background:"var(--s3)",border:"1px solid var(--b1)"},children:u!==null?`${String(u).padStart(2,"0")}:00 · ${m(w[u].inputTokens+w[u].outputTokens)} tok`:"00:00 · 0 tok"})]}),o.jsx("div",{className:"relative flex-1 h-[140px]",children:o.jsxs("svg",{width:"100%",height:"100%",viewBox:`0 0 ${v} ${j}`,preserveAspectRatio:"none",className:"overflow-visible",children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:"tokenGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:"var(--gold)",stopOpacity:"0.25"}),o.jsx("stop",{offset:"100%",stopColor:"var(--gold)",stopOpacity:"0"})]})}),Array.from({length:5}).map((_,B)=>{const G=A+B/4*$,q=Math.round(H-B/4*H);return o.jsxs("g",{className:"opacity-25",children:[o.jsx("line",{x1:E,y1:G,x2:v-M,y2:G,stroke:"var(--b2)",strokeWidth:"0.75",strokeDasharray:"3 3"}),o.jsx("text",{x:E-8,y:G+3.5,textAnchor:"end",className:"fill-muted font-mono text-[9.5px]",children:m(q)})]},B)}),Array.from({length:7}).map((_,B)=>{const G=Math.round(B/6*23),q=E+G/23*T;return o.jsxs("text",{x:q,y:j-6,textAnchor:"middle",className:"fill-muted font-mono text-[9.5px] opacity-60",children:[String(G).padStart(2,"0"),":00"]},B)}),N&&o.jsx("path",{d:N,fill:"url(#tokenGrad)"}),D&&o.jsx("path",{d:D,fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",strokeLinecap:"round"}),V.map((_,B)=>o.jsxs("g",{onMouseEnter:()=>d(B),onMouseLeave:()=>d(null),children:[o.jsx("rect",{x:_.x-T/48,y:A,width:T/24,height:$,fill:"transparent",className:"cursor-pointer"}),u===B&&o.jsxs(o.Fragment,{children:[o.jsx("line",{x1:_.x,y1:A,x2:_.x,y2:A+$,stroke:"var(--b2)",strokeWidth:"0.75"}),o.jsx("circle",{cx:_.x,cy:_.y,r:"4",fill:"var(--gold)",stroke:"var(--s1)",strokeWidth:"1.5"})]})]},B))]})})]}),o.jsxs("div",{className:"glass-card rounded-xl p-5 flex flex-col relative select-none",children:[o.jsxs("div",{className:"flex items-center justify-between h-6 mb-4",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:"var(--gold)",opacity:.8},children:"Hourly Tool & Prompt Load"}),o.jsx("span",{className:`text-[11px] font-mono text-fg px-2 py-0.5 rounded-[4px] transition-opacity duration-150 ${f!==null?"opacity-100":"opacity-0 pointer-events-none"}`,style:{background:"var(--s3)",border:"1px solid var(--b1)"},children:f!==null?`${String(f).padStart(2,"0")}:00 · 🛠️ ${w[f].toolCalls} calls · 💬 ${w[f].messages} msg`:"00:00 · 0 calls · 0 msg"})]}),o.jsx("div",{className:"relative flex-1 h-[140px]",children:o.jsxs("svg",{width:"100%",height:"100%",viewBox:`0 0 ${k} ${R}`,preserveAspectRatio:"none",className:"overflow-visible",children:[Array.from({length:5}).map((_,B)=>{const G=A+B/4*Y,q=Math.round(z-B/4*z);return o.jsxs("g",{className:"opacity-25",children:[o.jsx("line",{x1:E,y1:G,x2:k-M,y2:G,stroke:"var(--b2)",strokeWidth:"0.75",strokeDasharray:"3 3"}),o.jsx("text",{x:E-8,y:G+3.5,textAnchor:"end",className:"fill-muted font-mono text-[9.5px]",children:q})]},B)}),Array.from({length:7}).map((_,B)=>{const G=Math.round(B/6*23),q=E+G/23*O;return o.jsxs("text",{x:q,y:R-6,textAnchor:"middle",className:"fill-muted font-mono text-[9.5px] opacity-60",children:[String(G).padStart(2,"0"),":00"]},B)}),w.map((_,B)=>{const G=E+B*(X+L),q=_.messages/z*Y,Q=_.toolCalls/z*Y,K=A+Y-q,W=K-Q;return o.jsxs("g",{onMouseEnter:()=>h(B),onMouseLeave:()=>h(null),className:"cursor-pointer",children:[_.messages>0&&o.jsx("rect",{x:G,y:K,width:X,height:q,fill:"var(--yellow)",rx:"1",className:"transition-all duration-100 hover:opacity-80"}),_.toolCalls>0&&o.jsx("rect",{x:G,y:W,width:X,height:Q,fill:"var(--cream)",rx:"1",className:"transition-all duration-100 hover:opacity-80"}),o.jsx("rect",{x:G-L/2,y:A,width:X+L,height:Y,fill:"transparent"})]},B)})]})})]})]}),o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 mb-6",children:[o.jsxs("div",{className:"glass-card rounded-xl p-5 flex flex-col select-none",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider mb-4 block",style:{color:"var(--gold)",opacity:.8},children:"Telemetry Channels"}),o.jsxs("div",{className:"space-y-3.5 flex-1 flex flex-col justify-center",children:[o.jsx(zr,{label:"Web UI Console",count:g.webui,percent:Math.round(g.webui/U*100),color:"var(--gold)"}),o.jsx(zr,{label:"CLI TUI Terminal",count:g.tui,percent:Math.round(g.tui/U*100),color:"var(--yellow)"}),o.jsx(zr,{label:"Telegram Bot",count:g.telegram,percent:Math.round(g.telegram/U*100),color:"var(--cream)"}),o.jsx(zr,{label:"Heartbeat Scheduler",count:g.heartbeat,percent:Math.round(g.heartbeat/U*100),color:"var(--red)"})]})]}),o.jsxs("div",{className:"col-span-1 md:col-span-2 glass-card rounded-xl p-5",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider mb-3 block",style:{color:"var(--gold)",opacity:.8},children:"Top Executed Tools Today"}),y.length===0?o.jsx("div",{className:"flex items-center justify-center h-28 text-xs text-muted",children:"No tool executions tracked today"}):o.jsx("div",{className:"overflow-hidden",children:o.jsxs("table",{className:"w-full text-left text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"font-mono text-[10px]",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 40%, transparent)",color:"var(--muted)"},children:[o.jsx("th",{className:"pb-1.5 font-medium",children:"TOOL DEFINITION"}),o.jsx("th",{className:"pb-1.5 font-medium text-right",children:"CALLS"})]})}),o.jsx("tbody",{children:y.map((_,B)=>o.jsxs("tr",{className:"transition-colors duration-100",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 20%, transparent)"},children:[o.jsx("td",{className:"py-2 font-mono text-fg font-medium",children:_.name}),o.jsxs("td",{className:"py-2 text-right font-mono font-semibold",style:{color:"var(--gold)"},children:[_.count," executions"]})]},B))})]})})]})]}),s.length>0&&o.jsxs("div",{className:"glass-card rounded-xl overflow-hidden",children:[o.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider px-4 py-3.5",style:{borderBottom:"1px solid var(--b1)",color:"var(--gold)",opacity:.8},children:"Telemetry Operations Stream"}),o.jsx("div",{className:"overflow-x-auto",children:o.jsxs("table",{className:"w-full text-[12.5px]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-left text-xs text-muted font-mono text-[10px]",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 40%, transparent)"},children:[o.jsx("th",{className:"px-4 py-2 font-medium",children:"SESSION ID"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"CHANNEL"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"MODEL MODEL"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"TELEMETRY TIMESTAMP"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"ACTIVE DIRECTORY"})]})}),o.jsx("tbody",{children:s.slice(0,15).map(_=>o.jsxs("tr",{className:"transition-colors duration-75",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 20%, transparent)"},children:[o.jsx("td",{className:"px-4 py-2.5 font-mono text-[11.5px] text-fg",children:_.id}),o.jsx("td",{className:"px-4 py-2.5",children:o.jsx("span",{className:"px-2 py-0.5 rounded-[4px] text-[10px] font-mono select-none",style:{background:_.type==="telegram"?"color-mix(in srgb, var(--cream) 10%, transparent)":_.type==="tui"?"color-mix(in srgb, var(--yellow) 10%, transparent)":_.type==="heartbeat"?"color-mix(in srgb, var(--red) 10%, transparent)":"color-mix(in srgb, var(--gold) 10%, transparent)",color:_.type==="telegram"?"var(--cream)":_.type==="tui"?"var(--yellow)":_.type==="heartbeat"?"var(--red)":"var(--gold)",border:"1px solid color-mix(in srgb, var(--b1) 30%, transparent)"},children:_.type||"webui"})}),o.jsx("td",{className:"px-4 py-2.5 text-text font-mono text-[11.5px]",children:_.model}),o.jsx("td",{className:"px-4 py-2.5 text-muted text-xs",children:new Date(_.createdAt).toLocaleString()}),o.jsx("td",{className:"px-4 py-2.5 text-muted text-xs truncate max-w-[220px]",title:_.cwd,children:_.cwd})]},_.id))})]})})]})]})}function Tr({label:e,value:t,subtitle:n,isGreen:l}){return o.jsxs("div",{className:"metric-card rounded-xl px-6 py-5 flex flex-col justify-between select-none",children:[o.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider mb-2",style:{color:"var(--gold)",opacity:.7},children:e}),o.jsx("div",{className:"text-2xl font-display font-bold tracking-tight leading-none",style:{color:l?"var(--green)":"var(--cream)"},children:t}),o.jsx("span",{className:"text-[10px] text-muted mt-2 font-mono",children:n})]})}function zr({label:e,count:t,percent:n,color:l}){return o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-xs font-medium text-text2",children:[o.jsx("span",{children:e}),o.jsxs("span",{className:"font-mono text-muted",children:[t," sessions (",n||0,"%)"]})]}),o.jsx("div",{className:"w-full h-1.5 rounded-full overflow-hidden",style:{background:"var(--s2)"},children:o.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${n||0}%`,background:l}})})]})}function Kj({rpc:e,className:t}){const[n,l]=b.useState([]),[a,s]=b.useState(!0);b.useEffect(()=>{e&&(s(!0),e.sessionList().then(r=>{Array.isArray(r)&&l(r)}).catch(()=>{}).finally(()=>s(!1)))},[e]);const i=b.useMemo(()=>{const r=new Map;for(const c of n){const u=r.get(c.cwd)||[];u.push(c),r.set(c.cwd,u)}return Array.from(r.entries()).map(([c,u])=>({cwd:c,sessions:u.length,providers:[...new Set(u.map(d=>d.provider))],models:[...new Set(u.map(d=>d.model))],lastActive:Math.max(...u.map(d=>d.updatedAt))})).sort((c,u)=>u.lastActive-c.lastActive)},[n]);return o.jsxs("div",{className:`flex-1 overflow-y-auto p-7 scrollbar-thin ${t||""}`,children:[o.jsxs("div",{className:"flex items-center justify-between mb-5",children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight",children:"Projects"}),o.jsxs("span",{className:"text-xs text-muted font-mono",children:[i.length," projects"]})]}),a?o.jsx("div",{className:"flex items-center justify-center py-10 text-muted",children:"Loading..."}):i.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-muted",children:[o.jsx("div",{className:"text-sm",children:"No projects yet"}),o.jsx("div",{className:"text-xs text-muted2 mt-1",children:"Sessions will appear here once you run them"})]}):i.map(r=>o.jsx(Wj,{project:r},r.cwd))]})}function Wj({project:e}){const t=e.cwd.split("/").pop()||e.cwd;return o.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg mb-0.5 hover:bg-s2 cursor-pointer transition-colors duration-100",children:[o.jsx("div",{className:"w-[6px] h-[6px] rounded-full bg-green shrink-0"}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[13px] font-medium text-fg",children:t}),o.jsx("div",{className:"text-xs text-muted font-mono",children:e.cwd})]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsxs("span",{className:"text-xs text-muted",children:[e.sessions," session",e.sessions!==1?"s":""]}),o.jsx("span",{className:"text-xs text-muted",children:e.providers.join(", ")})]}),o.jsx("span",{className:"text-[10px] font-medium rounded-full px-2 py-0.5 font-mono bg-green/10 text-green",children:"active"})]})}function Jj(){const{rpc:e,ws:t}=Cn(),[n,l]=b.useState(new Map);b.useEffect(()=>{e&&e.subagentList().then(d=>{if(Array.isArray(d)){const f=new Map;for(const h of d)f.set(h.agentId,h);l(f)}}).catch(()=>{})},[e]),b.useEffect(()=>{if(!t)return;const d=g=>{l(y=>{const m=new Map(y);return m.set(g.agentId,{agentId:g.agentId,sessionId:g.sessionId||"",prompt:g.prompt||"",provider:g.provider||"unknown",status:"starting",text:"",toolCalls:0,errors:[],inputTokens:0,outputTokens:0,startedAt:g.timestamp}),m})},f=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,text:v.text+g.text}),m})},h=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,toolCalls:v.toolCalls+1}),m})},p=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,inputTokens:v.inputTokens+(g.inputTokens||0),outputTokens:v.outputTokens+(g.outputTokens||0)}),m})},x=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,status:"done",text:g.text||v.text,toolCalls:g.toolCalls??v.toolCalls,errors:g.errors||[],doneAt:g.timestamp}),m})},S=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,status:"error",errors:[...v.errors||[],g.message],doneAt:g.timestamp}),m})},w=[t.on("agent-start",d),t.on("agent-text-delta",f),t.on("agent-tool-call",h),t.on("agent-usage",p),t.on("agent-done",x),t.on("agent-error",S)];return()=>{for(const g of w)g()}},[t]);const a=b.useCallback(async d=>{if(!e)return null;try{return await e.subagentSpawn(d)}catch(f){return console.error("[useSubagents] Spawn failed:",f),null}},[e]),s=b.useCallback(async d=>{if(!e)return!1;try{return await e.subagentCancel(d),l(f=>{const h=new Map(f),p=h.get(d);return p&&h.set(d,{...p,status:"cancelled",doneAt:Date.now()}),h}),!0}catch{return!1}},[e]),i=b.useCallback(async(d,f)=>{if(!e)return!1;try{return await e.subagentSend(d,f),!0}catch{return!1}},[e]),r=Array.from(n.values()).filter(d=>d.status==="running"||d.status==="starting"),c=Array.from(n.values()).filter(d=>d.status==="done"),u=Array.from(n.values()).filter(d=>d.status==="error");return{agents:n,running:r,completed:c,failed:u,spawn:a,cancel:s,send:i}}function Fj({rpc:e,sessionId:t,className:n}){const{ws:l}=Cn(),{agents:a,running:s,completed:i,failed:r,spawn:c,cancel:u,send:d}=Jj(),[f,h]=b.useState(!1),[p,x]=b.useState(!1),[S,w]=b.useState(""),[g,y]=b.useState("auto"),[m,v]=b.useState("auto"),[j,E]=b.useState(""),[M,A]=b.useState(""),[C,H]=b.useState(""),[T,$]=b.useState(""),[V,N]=b.useState(""),[D,k]=b.useState(""),[R,z]=b.useState(""),[O,Y]=b.useState("auto"),[X,L]=b.useState(""),[U,_]=b.useState(""),[B,G]=b.useState(""),[q,Q]=b.useState(null),[K,W]=b.useState(0),P=b.useCallback(async()=>{if(!S.trim()||!e)return;let I=t;if(!I)try{const se=await e.sessionList();Array.isArray(se)&&se.length>0&&(I=se[0].id)}catch{}await c({sessionId:I||"",prompt:S.trim(),provider:j||void 0,mode:g!=="auto"?g:void 0,effort:m!=="auto"?m:void 0,model:M||void 0}),w(""),h(!1),E("")},[S,g,m,j,M,t,e,c]),J=b.useCallback(async()=>{if(!e||!C.trim()||!T||!V){L("Please fill in prompt and date/time");return}L("");const I=`${T}T${V}:00`;try{await e.taskSchedule({instruction:C.trim(),scheduled_at:I,provider:D||void 0,model:R||void 0,effort:O!=="auto"?O:void 0}),H(""),$(""),N(""),x(!1)}catch(se){L(se instanceof Error?se.message:"Failed to schedule task")}},[C,T,V,D,R,O,e]),F=b.useCallback(async()=>{!U||!B.trim()||(await d(U,B.trim()),G(""))},[U,B,d]),le=Array.from(a.values()).sort((I,se)=>(se.startedAt||0)-(I.startedAt||0)),ae=le.filter(I=>I.status==="done"||I.status==="error"||I.status==="cancelled"),te=ae.slice(K*10,(K+1)*10),ge=I=>{const se=Math.floor(I/1e3);return se<60?`${se}s`:`${Math.floor(se/60)}m${se%60}s`};return o.jsxs("div",{className:`flex-1 overflow-y-auto p-4 md:p-7 scrollbar-thin ${n||""}`,children:[o.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-6",children:[o.jsxs("div",{children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight",children:"Agents"}),o.jsx("p",{className:"text-[11.5px] text-muted mt-0.5",children:"Parallel subagent orchestration and monitoring."})]}),o.jsxs("div",{className:"flex gap-2 self-start sm:self-auto",children:[o.jsx("button",{onClick:()=>x(!p),className:`text-xs font-medium border rounded-[8px] px-4 py-2 transition-colors select-none ${p?"bg-blue/15 text-blue border-blue/30":"bg-s2 text-muted border-b1 hover:text-fg"}`,children:"Schedule"}),o.jsx("button",{onClick:()=>h(!f),className:"text-xs font-medium bg-green/10 text-green border border-green/20 rounded-[8px] px-4 py-2 hover:bg-green/20 transition-colors duration-150 select-none",children:f?"Cancel":"+ Spawn Agent"})]})]}),f&&o.jsx("div",{className:"bg-s1 border border-b1 rounded-[10px] p-5 mb-6 animate-in",children:o.jsxs("div",{className:"flex flex-col gap-3",children:[o.jsx("textarea",{className:"bg-s2 border border-b1 rounded-[8px] p-3 text-[13px] text-fg font-mino resize-y min-h-[60px] focus:border-fg/30 outline-none transition-colors duration-150",placeholder:"What should the subagent do?",value:S,onChange:I=>w(I.target.value),onKeyDown:I=>{I.key==="Enter"&&!I.shiftKey&&(I.preventDefault(),P())}}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:g,onChange:I=>y(I.target.value),children:[o.jsx("option",{value:"auto",children:"Mode: inherit"}),o.jsx("option",{value:"plan",children:"Mode: plan"}),o.jsx("option",{value:"edit",children:"Mode: edit"}),o.jsx("option",{value:"auto",children:"Mode: auto"}),o.jsx("option",{value:"yolo",children:"Mode: yolo"})]}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:m,onChange:I=>v(I.target.value),children:[o.jsx("option",{value:"auto",children:"Effort: inherit"}),o.jsx("option",{value:"low",children:"Effort: low"}),o.jsx("option",{value:"medium",children:"Effort: medium"}),o.jsx("option",{value:"high",children:"Effort: high"}),o.jsx("option",{value:"max",children:"Effort: max"})]}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:j,onChange:I=>E(I.target.value),children:[o.jsx("option",{value:"",children:"Provider: inherit"}),o.jsx("option",{value:"anthropic",children:"Anthropic"}),o.jsx("option",{value:"openai",children:"OpenAI"}),o.jsx("option",{value:"google",children:"Google"}),o.jsx("option",{value:"ollama",children:"Ollama"}),o.jsx("option",{value:"openrouter",children:"OpenRouter"})]}),o.jsx("input",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none font-mono",placeholder:"Model override (optional)",value:M,onChange:I=>A(I.target.value)}),o.jsx("button",{onClick:P,disabled:!S.trim(),className:"bg-green/20 text-green border border-green/30 rounded-[8px] px-4 py-2 text-xs font-medium hover:bg-green/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Spawn"})]})]})}),p&&o.jsx("div",{className:"bg-s1 border border-b1 rounded-[10px] p-5 mb-6 animate-in",children:o.jsxs("div",{className:"flex flex-col gap-3",children:[o.jsx("textarea",{className:"bg-s2 border border-b1 rounded-[8px] p-3 text-[13px] text-fg font-mino resize-y min-h-[60px] focus:border-fg/30 outline-none transition-colors duration-150",placeholder:"What should the scheduled agent do?",value:C,onChange:I=>H(I.target.value)}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[o.jsx("input",{type:"date",className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:T,onChange:I=>$(I.target.value)}),o.jsx("input",{type:"time",className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:V,onChange:I=>N(I.target.value)}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:O,onChange:I=>Y(I.target.value),children:[o.jsx("option",{value:"auto",children:"Effort: auto"}),o.jsx("option",{value:"low",children:"Effort: low"}),o.jsx("option",{value:"medium",children:"Effort: medium"}),o.jsx("option",{value:"high",children:"Effort: high"}),o.jsx("option",{value:"max",children:"Effort: max"})]}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:D,onChange:I=>k(I.target.value),children:[o.jsx("option",{value:"",children:"Provider: inherit"}),o.jsx("option",{value:"anthropic",children:"Anthropic"}),o.jsx("option",{value:"openai",children:"OpenAI"}),o.jsx("option",{value:"google",children:"Google"}),o.jsx("option",{value:"ollama",children:"Ollama"}),o.jsx("option",{value:"openrouter",children:"OpenRouter"})]}),o.jsx("input",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none font-mono col-span-2 md:col-span-4",placeholder:"Model override (optional)",value:R,onChange:I=>z(I.target.value)})]}),X&&o.jsx("div",{className:"text-[11px] text-red bg-red/5 rounded-[6px] p-2",children:X}),o.jsx("button",{onClick:J,disabled:!C.trim()||!T||!V,className:"bg-blue/20 text-blue border border-blue/30 rounded-[8px] px-4 py-2 text-xs font-medium hover:bg-blue/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed self-start",children:"Schedule Agent"})]})}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[o.jsx(Dr,{label:"Running",value:String(s.length),color:"text-yellow"}),o.jsx(Dr,{label:"Completed",value:String(i.length),color:"text-green"}),o.jsx(Dr,{label:"Failed",value:String(r.length),color:"text-red"}),o.jsx(Dr,{label:"Total Tokens",value:af(le.reduce((I,se)=>I+se.inputTokens+se.outputTokens,0)),color:"text-fg"})]}),s.length>0&&o.jsxs("div",{className:"mb-6",children:[o.jsx("h3",{className:"text-[11px] font-semibold text-text2 uppercase tracking-wider mb-3",children:"Live Agents"}),o.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(I=>o.jsx(Pj,{agent:I,onCancel:()=>u(I.agentId),onExpand:()=>Q(q===I.agentId?null:I.agentId)},I.agentId))})]}),ae.length>0&&o.jsxs("div",{className:"mb-6",children:[o.jsx("h3",{className:"text-[11px] font-semibold text-text2 uppercase tracking-wider mb-3",children:"History"}),o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] overflow-hidden",children:[o.jsx("div",{className:"overflow-x-auto",children:o.jsxs("table",{className:"w-full text-[12px]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-left text-xs text-muted border-b border-b1 font-mono text-[10px]",children:[o.jsx("th",{className:"px-4 py-2 font-medium",children:"STATUS"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"PROVIDER"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"PROMPT"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"DURATION"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"TOOLS"}),o.jsx("th",{className:"px-4 py-2 font-medium text-right",children:"TOKENS"})]})}),o.jsx("tbody",{children:te.map(I=>{const se=I.status==="done"?"text-green":I.status==="cancelled"?"text-muted2":"text-red",Re=I.doneAt?ge(I.doneAt-I.startedAt):"-",st=I.inputTokens+I.outputTokens;return o.jsxs("tr",{className:"hover:bg-s2/30 transition-colors cursor-pointer border-b border-b1/40",onClick:()=>Q(q===I.agentId?null:I.agentId),children:[o.jsx("td",{className:"px-4 py-2.5",children:o.jsx("span",{className:`text-[10px] font-mono px-2 py-0.5 rounded-[4px] ${se==="text-green"?"bg-green/10":se==="text-red"?"bg-red/10":"bg-muted/10"}`,children:I.status})}),o.jsx("td",{className:"px-4 py-2.5 text-muted font-mono text-[11.5px]",children:I.provider||"-"}),o.jsx("td",{className:"px-4 py-2.5 text-fg truncate max-w-[200px]",title:I.prompt,children:I.prompt}),o.jsx("td",{className:"px-4 py-2.5 text-muted font-mono",children:Re}),o.jsx("td",{className:"px-4 py-2.5 text-muted font-mono",children:I.toolCalls}),o.jsx("td",{className:"px-4 py-2.5 text-right font-mono text-muted",children:st>0?af(st):"-"})]},I.agentId)})})]})}),ae.length>10&&o.jsxs("div",{className:"flex items-center justify-center gap-4 py-2 border-t border-b1",children:[o.jsx("button",{className:"text-xs text-muted hover:text-fg transition-colors disabled:opacity-30",disabled:K===0,onClick:()=>W(I=>I-1),children:"Prev"}),o.jsxs("span",{className:"text-[10px] text-muted font-mono",children:[K+1," / ",Math.ceil(ae.length/10)]}),o.jsx("button",{className:"text-xs text-muted hover:text-fg transition-colors disabled:opacity-30",disabled:(K+1)*10>=ae.length,onClick:()=>W(I=>I+1),children:"Next"})]})]}),q&&(()=>{const I=a.get(q);return I?o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] p-4 mt-2",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsxs("span",{className:"text-[11px] font-mono text-muted",children:["Agent: ",I.agentId.slice(0,12),"..."]}),o.jsx("span",{className:"text-[10px] text-muted",children:new Date(I.startedAt).toLocaleString()})]}),o.jsx("pre",{className:"text-[12px] text-fg bg-s2 rounded-[8px] p-3 overflow-x-auto max-h-[200px] overflow-y-auto whitespace-pre-wrap font-mono",children:I.text||"(no output)"}),I.errors.length>0&&o.jsx("div",{className:"mt-2 text-[11px] text-red bg-red/5 rounded-[6px] p-2",children:I.errors.map((se,Re)=>o.jsxs("div",{children:["Error: ",se]},Re))})]}):null})()]}),s.length>0&&o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] p-4 mb-6",children:[o.jsx("h3",{className:"text-[11px] font-semibold text-text2 uppercase tracking-wider mb-3",children:"Send Message to Agent"}),o.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none flex-[0.5]",value:U,onChange:I=>_(I.target.value),children:[o.jsx("option",{value:"",children:"Select agent..."}),s.map(I=>o.jsxs("option",{value:I.agentId,children:[I.prompt.slice(0,40),I.prompt.length>40?"...":""]},I.agentId))]}),o.jsx("input",{className:"flex-1 bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",placeholder:"Type a message to inject into the agent...",value:B,onChange:I=>G(I.target.value),onKeyDown:I=>{I.key==="Enter"&&F()}}),o.jsx("button",{onClick:F,disabled:!U||!B.trim(),className:"bg-fg/10 text-fg border border-fg/20 rounded-[8px] px-4 py-2 text-xs font-medium hover:bg-fg/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Send"})]})]}),o.jsx(t5,{ws:l})]})}function Dr({label:e,value:t,color:n}){return o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] px-5 py-4 flex flex-col justify-between select-none",children:[o.jsx("span",{className:"text-[10px] font-semibold text-muted uppercase tracking-wider",children:e}),o.jsx("div",{className:`text-2xl font-bold tracking-tight leading-none mt-1 ${n}`,children:t})]})}function Pj({agent:e,onCancel:t,onExpand:n}){const l=Date.now()-e.startedAt,a=e.inputTokens+e.outputTokens,s=e.status==="running"?"text-yellow":"text-green";return o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] p-4 hover:border-b2 transition-colors cursor-pointer select-none",onClick:n,children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("div",{className:`w-[6px] h-[6px] rounded-full shrink-0 ${e.status==="running"?"bg-yellow animate-pulse":"bg-green"}`}),o.jsx("span",{className:"text-[12.5px] font-medium text-fg truncate flex-1",children:e.prompt}),o.jsx("span",{className:"text-[9px] font-mono bg-s3 px-1.5 py-0.5 rounded-[3px] text-muted shrink-0",children:e.provider}),o.jsx("span",{className:`text-[10px] font-mono ${s}`,children:e.status}),e.status==="running"&&o.jsx("button",{className:"text-[10px] text-red/70 hover:text-red font-mono shrink-0",onClick:i=>{i.stopPropagation(),t()},children:"Cancel"})]}),o.jsxs("div",{className:"text-[10.5px] text-muted font-mono mb-2",children:[e5(l)," · ",e.toolCalls," tools · ",af(a)," tok"]}),e.text&&o.jsx("div",{className:"text-[11px] text-text2 line-clamp-2 font-mono leading-relaxed",children:e.text.slice(-200)})]})}function e5(e){const t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${t%60}s`}function af(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function t5({ws:e}){const[t,n]=b.useState([]);return!e||(["agent-start","agent-text-delta","agent-done","agent-error","agent-tool-call"].forEach(a=>{e.on(a,s=>{n(i=>[{...s,_type:a},...i].slice(0,30))})}),t.length===0)?null:o.jsxs("div",{children:[o.jsx("div",{className:"h-px bg-b1 my-5"}),o.jsx("div",{className:"text-[11.5px] font-medium text-muted mb-2.5",children:"Live Agent Events"}),t.slice(0,15).map((a,s)=>o.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 rounded-lg mb-0.5 hover:bg-s2",children:[o.jsx("div",{className:`w-[6px] h-[6px] rounded-full shrink-0 ${a._type==="agent-start"?"bg-yellow":a._type==="agent-done"?"bg-green":a._type==="agent-error"?"bg-red":a._type==="agent-tool-call"?"bg-fg":"bg-muted2"}`}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[12px] text-text font-mono",children:a._type}),o.jsx("div",{className:"text-xs text-muted truncate",children:a.prompt||a.message||""})]}),o.jsx("span",{className:"text-[10px] text-muted font-mono",children:new Date(a.timestamp).toLocaleTimeString()})]},s))]})}function n5(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return b.useMemo(()=>l=>{t.forEach(a=>a(l))},t)}const Rc=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ms(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Hh(e){return"nodeType"in e}function ft(e){var t,n;return e?Ms(e)?e:Hh(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Lh(e){const{Document:t}=ft(e);return e instanceof t}function er(e){return Ms(e)?!1:e instanceof ft(e).HTMLElement}function Vv(e){return e instanceof ft(e).SVGElement}function _s(e){return e?Ms(e)?e.document:Hh(e)?Lh(e)?e:er(e)||Vv(e)?e.ownerDocument:document:document:document}const on=Rc?b.useLayoutEffect:b.useEffect;function Oc(e){const t=b.useRef(e);return on(()=>{t.current=e}),b.useCallback(function(){for(var n=arguments.length,l=new Array(n),a=0;a<n;a++)l[a]=arguments[a];return t.current==null?void 0:t.current(...l)},[])}function l5(){const e=b.useRef(null),t=b.useCallback((l,a)=>{e.current=setInterval(l,a)},[]),n=b.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function Ai(e,t){t===void 0&&(t=[e]);const n=b.useRef(e);return on(()=>{n.current!==e&&(n.current=e)},t),n}function tr(e,t){const n=b.useRef();return b.useMemo(()=>{const l=e(n.current);return n.current=l,l},[...t])}function Wo(e){const t=Oc(e),n=b.useRef(null),l=b.useCallback(a=>{a!==n.current&&(t==null||t(a,n.current)),n.current=a},[]);return[n,l]}function Jo(e){const t=b.useRef();return b.useEffect(()=>{t.current=e},[e]),t.current}let Xu={};function nr(e,t){return b.useMemo(()=>{if(t)return t;const n=Xu[e]==null?0:Xu[e]+1;return Xu[e]=n,e+"-"+n},[e,t])}function Xv(e){return function(t){for(var n=arguments.length,l=new Array(n>1?n-1:0),a=1;a<n;a++)l[a-1]=arguments[a];return l.reduce((s,i)=>{const r=Object.entries(i);for(const[c,u]of r){const d=s[c];d!=null&&(s[c]=d+e*u)}return s},{...t})}}const Wa=Xv(1),Fo=Xv(-1);function a5(e){return"clientX"in e&&"clientY"in e}function Hc(e){if(!e)return!1;const{KeyboardEvent:t}=ft(e.target);return t&&e instanceof t}function s5(e){if(!e)return!1;const{TouchEvent:t}=ft(e.target);return t&&e instanceof t}function Po(e){if(s5(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return a5(e)?{x:e.clientX,y:e.clientY}:null}const Hl=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[Hl.Translate.toString(e),Hl.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:l}=e;return t+" "+n+"ms "+l}}}),am="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function i5(e){return e.matches(am)?e:e.querySelector(am)}const r5={display:"none"};function o5(e){let{id:t,value:n}=e;return Me.createElement("div",{id:t,style:r5},n)}function c5(e){let{id:t,announcement:n,ariaLiveType:l="assertive"}=e;const a={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return Me.createElement("div",{id:t,style:a,role:"status","aria-live":l,"aria-atomic":!0},n)}function u5(){const[e,t]=b.useState("");return{announce:b.useCallback(l=>{l!=null&&t(l)},[]),announcement:e}}const Gv=b.createContext(null);function d5(e){const t=b.useContext(Gv);b.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function f5(){const[e]=b.useState(()=>new Set),t=b.useCallback(l=>(e.add(l),()=>e.delete(l)),[e]);return[b.useCallback(l=>{let{type:a,event:s}=l;e.forEach(i=>{var r;return(r=i[a])==null?void 0:r.call(i,s)})},[e]),t]}const h5={draggable:`
139
+ `)}`})}w(!1)}catch(U){r({type:"error",id:`local-err-${Date.now()}`,timestamp:Date.now(),message:`Wiki lint failed: ${U instanceof Error?U.message:String(U)}`}),w(!1)}else r({type:"assistant-delta",id:`local-wiki-${Date.now()}`,timestamp:Date.now(),text:"Wiki commands:\n- `/wiki` — Open wiki view\n- `/wiki list` — List all pages\n- `/wiki search <q>` — Search pages\n- `/wiki lint` — Health check"}),w(!1);return}}}const D=l||"";try{const z=await t.sessionSend(D,N,"webui");z!=null&&z.sessionId&&!l&&(h==null||h.subscribe(z.sessionId),a==null||a(z.sessionId))}catch(z){const O=z instanceof Error?z.message:String(z);y(`Failed to send: ${O}`),w(!1)}},[t,h,l,T,a,r]);b.useEffect(()=>{h&&(h.on("assistant-stop",()=>w(!1)),h.on("error",()=>w(!1)))},[h]);const V=b.useCallback(async()=>{if(!(!t||!l)){w(!1),y(null),T();try{await t.sessionCancel(l)}catch(N){const D=N instanceof Error?N.message:String(N);y(`Failed to cancel: ${D}`)}}},[t,l,T]);return o.jsxs("div",{className:`flex flex-col h-full ${n||""}`,children:[o.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto scrollbar-thin",ref:j,children:[C.length===0&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted",children:[o.jsx("div",{className:"text-lg mb-2 font-display",style:{color:"var(--cream)"},children:"curie"}),o.jsx("div",{className:"text-sm text-muted",children:M})]}),o.jsxs("div",{className:"py-4 pb-6",children:[C.map((N,D)=>{if(N.type==="thinking")return o.jsx(Bv,{content:N.content},`thinking-${D}`);if(N.type==="user")return o.jsx("div",{className:"flex flex-row-reverse px-3 py-0.5 animate-fadeIn transition-colors duration-100",children:o.jsxs("div",{className:"flex flex-1 flex-col items-end min-w-0",children:[o.jsxs("div",{className:"flex flex-row-reverse items-baseline gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-semibold",style:{color:"var(--cream)"},children:"you"}),o.jsx("span",{className:"text-xs text-muted font-mono",children:N.time})]}),o.jsx("div",{className:"text-[13px] text-text leading-[1.65] chat-msg-user rounded-t-[10px] rounded-bl-[10px] px-3.5 py-2.5 max-w-[480px] markdown-body",dangerouslySetInnerHTML:{__html:Ko(N.content)}})]})},D);if(N.type==="tool-group"){const k=N;if(k.toolCalls.length>0)return o.jsx(Uv,{toolCalls:k.toolCalls},D)}if(N.type==="agent-actions"){const k=N;return o.jsx(Yj,{blocks:k.blocks,blockCount:k.blockCount,time:k.time,events:i,rpc:t},`agent-${k.time||D}`)}if(N.type==="approval-request")return o.jsx(Yv,{toolCallId:N.toolCallId,name:N.name,input:N.input,decision:N.decision,events:i,rpc:t,mode:N.mode},D);if(N.type==="heartbeat-brief"){const k=N;return o.jsx(Lj,{event:k.event},D)}if(N.type==="reminder-fired")return o.jsx($j,{message:N.message,time:N.time},D);if(N.type==="chart"){const k=Uj(i,N.toolCallId);return o.jsx(Hj,{spec:k==null?void 0:k.output,error:k==null?void 0:k.error,pending:!k,rawInput:N.rawInput},D)}return N.type==="error"?o.jsxs("div",{className:"px-3 py-0.5 animate-fadeIn transition-colors duration-100",children:[o.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-semibold",style:{color:"var(--red)"},children:"error"}),o.jsx("span",{className:"text-xs text-muted font-mono",children:N.time})]}),o.jsx("div",{className:"text-[13px] text-red leading-[1.65] rounded-lg px-3 py-2 bg-red/5 border border-red/10",children:N.content})]},D):o.jsxs("div",{className:"px-3 py-0.5 animate-fadeIn transition-colors duration-100",children:[o.jsxs("div",{className:"flex items-baseline gap-2 mb-1",children:[o.jsx("span",{className:"text-xs font-semibold",style:{color:"var(--gold)"},children:"curie-agent"}),o.jsx("span",{className:"text-xs text-muted font-mono",children:N.time})]}),o.jsx("div",{className:"text-[13px] text-text leading-[1.65] markdown-body chat-msg-agent pl-3",dangerouslySetInnerHTML:{__html:Ko(N.content)}})]},D)}),S&&o.jsx("div",{className:"flex items-center px-3 py-2",children:o.jsxs("div",{className:"flex gap-1.5",children:[o.jsx("span",{className:"w-[5px] h-[5px] bg-muted2 rounded-full animate-dot inline-block",style:{animation:"tdot 1.4s infinite"}}),o.jsx("span",{className:"w-[5px] h-[5px] bg-muted2 rounded-full animate-dot inline-block",style:{animation:"tdot 1.4s infinite 0.2s"}}),o.jsx("span",{className:"w-[5px] h-[5px] bg-muted2 rounded-full animate-dot inline-block",style:{animation:"tdot 1.4s infinite 0.4s"}})]})})]})]}),o.jsxs("div",{className:"flex-shrink-0",children:[g&&o.jsx("div",{className:"px-3 py-1.5 bg-red/10 border-t border-red/20",children:o.jsx("div",{className:"text-[11px] text-red font-mono",children:g})}),o.jsx(wj,{onSend:$,onCancel:S?V:void 0,cmdInput:m,onClearCmdInput:()=>v(""),totalTokens:c,contextTokens:u,costUsd:d})]})]})}function Qj(e,t,n,l){if(l){const[r,c]=l.split(";"),u=parseFloat(r||"0"),d=parseFloat(c||"0");if(!isNaN(u)&&!isNaN(d))return(t*u+n*d)/1e6}const a={opus:{in:15,out:75},sonnet:{in:3,out:15},haiku:{in:.8,out:4},"gpt-4o":{in:2.5,out:10},"gpt-4":{in:5,out:15},qwen:{in:.112,out:.224}},s=Object.keys(a).find(r=>e.toLowerCase().includes(r))||"sonnet",i=a[s];return(t*i.in+n*i.out)/1e6}function Zj({cmdResult:e,onClearCmdResult:t,rpc:n,className:l,activeSessionId:a,onCreateSession:s,events:i,addLiveEvent:r,onSwitchView:c}){var y;const{get:u,providers:d}=kh(),f=u("model"),h=u("current_provider")||"anthropic",p=(y=d.find(m=>m.name===h))==null?void 0:y.model_cost;let x=0,S=0,w=0;const g=a?i.filter(m=>m.type==="usage"):[];if(g.length>0){x=g.reduce((v,j)=>v+(j.inputTokens||0)+(j.outputTokens||0),0);const m=g[g.length-1];S=m&&m.inputTokens||0,w=g.reduce((v,j)=>v+Qj(f||"sonnet",j.inputTokens||0,j.outputTokens||0,p),0)}return o.jsx("div",{className:`flex flex-col h-full ${l||""}`,children:o.jsx(Gj,{cmdResult:e,onClearCmdResult:t,rpc:n,activeSessionId:a,onCreateSession:s,events:i,addLiveEvent:r,totalTokens:x,contextTokens:S,costUsd:w,onSwitchView:c})})}function Ij({rpc:e,className:t}){const[n,l]=b.useState(null),[a,s]=b.useState(null),[i,r]=b.useState(null),[c,u]=b.useState(!0);b.useEffect(()=>{e&&Promise.all([e.configGet("channels.bot_token").catch(()=>null),e.configGet("channels.user_id").catch(()=>null),e.configGet("channels.chat_id").catch(()=>null)]).then(([f,h,p])=>{l(f),s(h),r(p)}).finally(()=>u(!1))},[e]);const d=!!n&&!!a;return o.jsxs("div",{className:`flex-1 overflow-y-auto p-7 scrollbar-thin ${t||""}`,children:[o.jsxs("div",{className:"flex items-center justify-between mb-5",children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight",children:"Channels"}),o.jsxs("button",{className:"flex items-center gap-1 bg-transparent border border-b2 rounded px-3 py-1.5 text-muted text-xs hover:border-b3 hover:text-fg transition-colors duration-100",children:[o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[o.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),"Connect"]})]}),c?o.jsx("div",{className:"flex items-center justify-center py-10 text-muted",children:"Loading..."}):o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg mb-0.5 bg-s2",children:[o.jsx("div",{className:"w-8 h-8 rounded-lg bg-s3 flex items-center justify-center shrink-0 text-base",children:d?"📱":"🔌"}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[13px] font-medium text-fg",children:d?"Telegram Connected":"Not Connected"}),o.jsx("div",{className:"text-xs text-muted truncate",children:d?`Bot configured for user ${a}`:"Configure a Telegram bot to enable channel messaging"})]}),o.jsx("div",{className:`w-[6px] h-[6px] rounded-full shrink-0 ${d?"bg-green":"bg-muted2"}`})]}),d&&o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] overflow-hidden mt-3",children:[o.jsx("div",{className:"text-[12px] font-medium text-text2 px-4 py-3 border-b border-b1",children:"Channel Configuration"}),o.jsx(Vu,{label:"Bot Token",value:(n==null?void 0:n.slice(0,12))+"..."||""}),o.jsx(Vu,{label:"User ID",value:a||""}),o.jsx(Vu,{label:"Chat ID",value:i||"not set"})]})]})]})}function Vu({label:e,value:t}){return o.jsxs("div",{className:"flex items-center justify-between px-4 py-2 border-b border-b1/50",children:[o.jsx("span",{className:"text-xs text-muted",children:e}),o.jsx("span",{className:"text-xs text-text font-mono",children:t})]})}function Kj({rpc:e,className:t}){const{ws:n}=Cn(),[l,a]=b.useState(null),[s,i]=b.useState([]),[r,c]=b.useState(!0),[u,d]=b.useState(null),[f,h]=b.useState(null),p=b.useRef(null),x=b.useCallback(async()=>{if(e)try{const[_,B]=await Promise.all([e.sessionStats(),e.sessionList()]);_&&a(_),Array.isArray(B)&&i(B)}catch(_){console.error("[StatsView] Failed to load statistics:",_)}},[e]);if(b.useEffect(()=>{c(!0),x().finally(()=>c(!1))},[x]),b.useEffect(()=>{if(!n)return;const _=()=>{p.current&&clearTimeout(p.current),p.current=setTimeout(x,2e3)},B=n.on("session-stop",_),G=n.on("session-start",_);return()=>{B(),G(),p.current&&clearTimeout(p.current)}},[n,x]),r)return o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted py-20 select-none animate-pulse",children:[o.jsx("div",{className:"w-8 h-8 rounded-full mb-4 animate-spin",style:{background:"conic-gradient(from 0deg, transparent, var(--gold))",mask:"radial-gradient(farthest-side, transparent calc(100% - 2px), #000 0)",WebkitMask:"radial-gradient(farthest-side, transparent calc(100% - 2px), #000 0)"}}),o.jsx("span",{className:"text-[13px] font-mono",style:{color:"var(--gold)",opacity:.7},children:"Compiling operations telemetry..."})]});if(!l||l.summary.totalSessions===0)return o.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-muted py-20 select-none",children:[o.jsx("div",{className:"w-14 h-14 rounded-xl flex items-center justify-center mb-4",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)",boxShadow:"0 4px 16px rgba(0,0,0,0.2)"},children:o.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",style:{opacity:.6},children:[o.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),o.jsx("path",{d:"M21 12H3M12 3v18"})]})}),o.jsx("div",{className:"text-[14px] font-display font-semibold",style:{color:"var(--cream)"},children:"No operational data found"}),o.jsx("div",{className:"text-[11.5px] text-muted mt-1",children:"Start a conversation to generate metrics."})]});const{summary:S,hourly:w,entrypoints:g,topTools:y}=l,m=_=>_<1e3?String(_):_<1e6?`${(_/1e3).toFixed(1)}k`:`${(_/1e6).toFixed(2)}M`,v=600,j=140,E=45,M=15,A=15,C=25,H=Math.max(...w.map(_=>_.inputTokens+_.outputTokens),1),T=v-E-M,$=j-A-C,V=w.map((_,B)=>{const G=_.inputTokens+_.outputTokens,q=E+B/23*T,Q=A+$-G/H*$;return{x:q,y:Q,..._}}),N=V.length>0?`${V.map((_,B)=>`${B===0?"M":"L"} ${_.x} ${_.y}`).join(" ")} L ${V[V.length-1].x} ${A+$} L ${V[0].x} ${A+$} Z`:"",D=V.length>0?V.map((_,B)=>`${B===0?"M":"L"} ${_.x} ${_.y}`).join(" "):"",k=600,R=140,z=Math.max(...w.map(_=>Math.max(_.toolCalls,_.messages)),1),O=k-E-M,Y=R-A-C,X=O/24*.75,L=O/24*.25,U=g.webui+g.tui+g.telegram+g.heartbeat||1;return o.jsxs("div",{className:`flex-1 overflow-y-auto p-4 md:p-7 scrollbar-thin ${t||""}`,children:[o.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-6",children:[o.jsxs("div",{children:[o.jsx("h2",{className:"text-lg font-display font-semibold tracking-tight",style:{color:"var(--cream)"},children:"System Telemetry"}),o.jsx("p",{className:"text-[11.5px] text-muted mt-0.5",children:"Real-time daily operations telemetry and interface execution load."})]}),o.jsxs("span",{className:"self-start sm:self-auto text-[11px] font-mono rounded-full px-3 py-1 text-muted select-none",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b1)"},children:["Today: ",new Date().toLocaleDateString(void 0,{weekday:"long",month:"short",day:"numeric"})]})]}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[o.jsx(Tr,{label:"Today's Sessions",value:String(S.totalSessionsToday),subtitle:"conversations today"}),o.jsx(Tr,{label:"Operational Cost",value:`$${S.totalCost.toFixed(4)}`,subtitle:"estimated total",isGreen:!0}),o.jsx(Tr,{label:"Volume Consumed",value:m(S.totalTokens),subtitle:"total system tokens"}),o.jsx(Tr,{label:"Agent Executions",value:String(S.totalToolCalls),subtitle:"integrated tool calls"})]}),o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5 mb-6",children:[o.jsxs("div",{className:"glass-card rounded-xl p-5 flex flex-col relative select-none",children:[o.jsxs("div",{className:"flex items-center justify-between h-6 mb-4",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:"var(--gold)",opacity:.8},children:"Hourly Token Consumption"}),o.jsx("span",{className:`text-[11px] font-mono text-fg px-2 py-0.5 rounded-[4px] transition-opacity duration-150 ${u!==null?"opacity-100":"opacity-0 pointer-events-none"}`,style:{background:"var(--s3)",border:"1px solid var(--b1)"},children:u!==null?`${String(u).padStart(2,"0")}:00 · ${m(w[u].inputTokens+w[u].outputTokens)} tok`:"00:00 · 0 tok"})]}),o.jsx("div",{className:"relative flex-1 h-[140px]",children:o.jsxs("svg",{width:"100%",height:"100%",viewBox:`0 0 ${v} ${j}`,preserveAspectRatio:"none",className:"overflow-visible",children:[o.jsx("defs",{children:o.jsxs("linearGradient",{id:"tokenGrad",x1:"0",y1:"0",x2:"0",y2:"1",children:[o.jsx("stop",{offset:"0%",stopColor:"var(--gold)",stopOpacity:"0.25"}),o.jsx("stop",{offset:"100%",stopColor:"var(--gold)",stopOpacity:"0"})]})}),Array.from({length:5}).map((_,B)=>{const G=A+B/4*$,q=Math.round(H-B/4*H);return o.jsxs("g",{className:"opacity-25",children:[o.jsx("line",{x1:E,y1:G,x2:v-M,y2:G,stroke:"var(--b2)",strokeWidth:"0.75",strokeDasharray:"3 3"}),o.jsx("text",{x:E-8,y:G+3.5,textAnchor:"end",className:"fill-muted font-mono text-[9.5px]",children:m(q)})]},B)}),Array.from({length:7}).map((_,B)=>{const G=Math.round(B/6*23),q=E+G/23*T;return o.jsxs("text",{x:q,y:j-6,textAnchor:"middle",className:"fill-muted font-mono text-[9.5px] opacity-60",children:[String(G).padStart(2,"0"),":00"]},B)}),N&&o.jsx("path",{d:N,fill:"url(#tokenGrad)"}),D&&o.jsx("path",{d:D,fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",strokeLinecap:"round"}),V.map((_,B)=>o.jsxs("g",{onMouseEnter:()=>d(B),onMouseLeave:()=>d(null),children:[o.jsx("rect",{x:_.x-T/48,y:A,width:T/24,height:$,fill:"transparent",className:"cursor-pointer"}),u===B&&o.jsxs(o.Fragment,{children:[o.jsx("line",{x1:_.x,y1:A,x2:_.x,y2:A+$,stroke:"var(--b2)",strokeWidth:"0.75"}),o.jsx("circle",{cx:_.x,cy:_.y,r:"4",fill:"var(--gold)",stroke:"var(--s1)",strokeWidth:"1.5"})]})]},B))]})})]}),o.jsxs("div",{className:"glass-card rounded-xl p-5 flex flex-col relative select-none",children:[o.jsxs("div",{className:"flex items-center justify-between h-6 mb-4",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider",style:{color:"var(--gold)",opacity:.8},children:"Hourly Tool & Prompt Load"}),o.jsx("span",{className:`text-[11px] font-mono text-fg px-2 py-0.5 rounded-[4px] transition-opacity duration-150 ${f!==null?"opacity-100":"opacity-0 pointer-events-none"}`,style:{background:"var(--s3)",border:"1px solid var(--b1)"},children:f!==null?`${String(f).padStart(2,"0")}:00 · 🛠️ ${w[f].toolCalls} calls · 💬 ${w[f].messages} msg`:"00:00 · 0 calls · 0 msg"})]}),o.jsx("div",{className:"relative flex-1 h-[140px]",children:o.jsxs("svg",{width:"100%",height:"100%",viewBox:`0 0 ${k} ${R}`,preserveAspectRatio:"none",className:"overflow-visible",children:[Array.from({length:5}).map((_,B)=>{const G=A+B/4*Y,q=Math.round(z-B/4*z);return o.jsxs("g",{className:"opacity-25",children:[o.jsx("line",{x1:E,y1:G,x2:k-M,y2:G,stroke:"var(--b2)",strokeWidth:"0.75",strokeDasharray:"3 3"}),o.jsx("text",{x:E-8,y:G+3.5,textAnchor:"end",className:"fill-muted font-mono text-[9.5px]",children:q})]},B)}),Array.from({length:7}).map((_,B)=>{const G=Math.round(B/6*23),q=E+G/23*O;return o.jsxs("text",{x:q,y:R-6,textAnchor:"middle",className:"fill-muted font-mono text-[9.5px] opacity-60",children:[String(G).padStart(2,"0"),":00"]},B)}),w.map((_,B)=>{const G=E+B*(X+L),q=_.messages/z*Y,Q=_.toolCalls/z*Y,K=A+Y-q,W=K-Q;return o.jsxs("g",{onMouseEnter:()=>h(B),onMouseLeave:()=>h(null),className:"cursor-pointer",children:[_.messages>0&&o.jsx("rect",{x:G,y:K,width:X,height:q,fill:"var(--yellow)",rx:"1",className:"transition-all duration-100 hover:opacity-80"}),_.toolCalls>0&&o.jsx("rect",{x:G,y:W,width:X,height:Q,fill:"var(--cream)",rx:"1",className:"transition-all duration-100 hover:opacity-80"}),o.jsx("rect",{x:G-L/2,y:A,width:X+L,height:Y,fill:"transparent"})]},B)})]})})]})]}),o.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 mb-6",children:[o.jsxs("div",{className:"glass-card rounded-xl p-5 flex flex-col select-none",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider mb-4 block",style:{color:"var(--gold)",opacity:.8},children:"Telemetry Channels"}),o.jsxs("div",{className:"space-y-3.5 flex-1 flex flex-col justify-center",children:[o.jsx(zr,{label:"Web UI Console",count:g.webui,percent:Math.round(g.webui/U*100),color:"var(--gold)"}),o.jsx(zr,{label:"CLI TUI Terminal",count:g.tui,percent:Math.round(g.tui/U*100),color:"var(--yellow)"}),o.jsx(zr,{label:"Telegram Bot",count:g.telegram,percent:Math.round(g.telegram/U*100),color:"var(--cream)"}),o.jsx(zr,{label:"Heartbeat Scheduler",count:g.heartbeat,percent:Math.round(g.heartbeat/U*100),color:"var(--red)"})]})]}),o.jsxs("div",{className:"col-span-1 md:col-span-2 glass-card rounded-xl p-5",children:[o.jsx("span",{className:"text-xs font-semibold uppercase tracking-wider mb-3 block",style:{color:"var(--gold)",opacity:.8},children:"Top Executed Tools Today"}),y.length===0?o.jsx("div",{className:"flex items-center justify-center h-28 text-xs text-muted",children:"No tool executions tracked today"}):o.jsx("div",{className:"overflow-hidden",children:o.jsxs("table",{className:"w-full text-left text-xs",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"font-mono text-[10px]",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 40%, transparent)",color:"var(--muted)"},children:[o.jsx("th",{className:"pb-1.5 font-medium",children:"TOOL DEFINITION"}),o.jsx("th",{className:"pb-1.5 font-medium text-right",children:"CALLS"})]})}),o.jsx("tbody",{children:y.map((_,B)=>o.jsxs("tr",{className:"transition-colors duration-100",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 20%, transparent)"},children:[o.jsx("td",{className:"py-2 font-mono text-fg font-medium",children:_.name}),o.jsxs("td",{className:"py-2 text-right font-mono font-semibold",style:{color:"var(--gold)"},children:[_.count," executions"]})]},B))})]})})]})]}),s.length>0&&o.jsxs("div",{className:"glass-card rounded-xl overflow-hidden",children:[o.jsx("div",{className:"text-xs font-semibold uppercase tracking-wider px-4 py-3.5",style:{borderBottom:"1px solid var(--b1)",color:"var(--gold)",opacity:.8},children:"Telemetry Operations Stream"}),o.jsx("div",{className:"overflow-x-auto",children:o.jsxs("table",{className:"w-full text-[12.5px]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-left text-xs text-muted font-mono text-[10px]",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 40%, transparent)"},children:[o.jsx("th",{className:"px-4 py-2 font-medium",children:"SESSION ID"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"CHANNEL"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"MODEL MODEL"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"TELEMETRY TIMESTAMP"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"ACTIVE DIRECTORY"})]})}),o.jsx("tbody",{children:s.slice(0,15).map(_=>o.jsxs("tr",{className:"transition-colors duration-75",style:{borderBottom:"1px solid color-mix(in srgb, var(--b1) 20%, transparent)"},children:[o.jsx("td",{className:"px-4 py-2.5 font-mono text-[11.5px] text-fg",children:_.id}),o.jsx("td",{className:"px-4 py-2.5",children:o.jsx("span",{className:"px-2 py-0.5 rounded-[4px] text-[10px] font-mono select-none",style:{background:_.type==="telegram"?"color-mix(in srgb, var(--cream) 10%, transparent)":_.type==="tui"?"color-mix(in srgb, var(--yellow) 10%, transparent)":_.type==="heartbeat"?"color-mix(in srgb, var(--red) 10%, transparent)":"color-mix(in srgb, var(--gold) 10%, transparent)",color:_.type==="telegram"?"var(--cream)":_.type==="tui"?"var(--yellow)":_.type==="heartbeat"?"var(--red)":"var(--gold)",border:"1px solid color-mix(in srgb, var(--b1) 30%, transparent)"},children:_.type||"webui"})}),o.jsx("td",{className:"px-4 py-2.5 text-text font-mono text-[11.5px]",children:_.model}),o.jsx("td",{className:"px-4 py-2.5 text-muted text-xs",children:new Date(_.createdAt).toLocaleString()}),o.jsx("td",{className:"px-4 py-2.5 text-muted text-xs truncate max-w-[220px]",title:_.cwd,children:_.cwd})]},_.id))})]})})]})]})}function Tr({label:e,value:t,subtitle:n,isGreen:l}){return o.jsxs("div",{className:"metric-card rounded-xl px-6 py-5 flex flex-col justify-between select-none",children:[o.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-wider mb-2",style:{color:"var(--gold)",opacity:.7},children:e}),o.jsx("div",{className:"text-2xl font-display font-bold tracking-tight leading-none",style:{color:l?"var(--green)":"var(--cream)"},children:t}),o.jsx("span",{className:"text-[10px] text-muted mt-2 font-mono",children:n})]})}function zr({label:e,count:t,percent:n,color:l}){return o.jsxs("div",{className:"space-y-1",children:[o.jsxs("div",{className:"flex items-center justify-between text-xs font-medium text-text2",children:[o.jsx("span",{children:e}),o.jsxs("span",{className:"font-mono text-muted",children:[t," sessions (",n||0,"%)"]})]}),o.jsx("div",{className:"w-full h-1.5 rounded-full overflow-hidden",style:{background:"var(--s2)"},children:o.jsx("div",{className:"h-full rounded-full transition-all duration-500",style:{width:`${n||0}%`,background:l}})})]})}function Wj({rpc:e,className:t}){const[n,l]=b.useState([]),[a,s]=b.useState(!0);b.useEffect(()=>{e&&(s(!0),e.sessionList().then(r=>{Array.isArray(r)&&l(r)}).catch(()=>{}).finally(()=>s(!1)))},[e]);const i=b.useMemo(()=>{const r=new Map;for(const c of n){const u=r.get(c.cwd)||[];u.push(c),r.set(c.cwd,u)}return Array.from(r.entries()).map(([c,u])=>({cwd:c,sessions:u.length,providers:[...new Set(u.map(d=>d.provider))],models:[...new Set(u.map(d=>d.model))],lastActive:Math.max(...u.map(d=>d.updatedAt))})).sort((c,u)=>u.lastActive-c.lastActive)},[n]);return o.jsxs("div",{className:`flex-1 overflow-y-auto p-7 scrollbar-thin ${t||""}`,children:[o.jsxs("div",{className:"flex items-center justify-between mb-5",children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight",children:"Projects"}),o.jsxs("span",{className:"text-xs text-muted font-mono",children:[i.length," projects"]})]}),a?o.jsx("div",{className:"flex items-center justify-center py-10 text-muted",children:"Loading..."}):i.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center py-10 text-muted",children:[o.jsx("div",{className:"text-sm",children:"No projects yet"}),o.jsx("div",{className:"text-xs text-muted2 mt-1",children:"Sessions will appear here once you run them"})]}):i.map(r=>o.jsx(Jj,{project:r},r.cwd))]})}function Jj({project:e}){const t=e.cwd.split("/").pop()||e.cwd;return o.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5 rounded-lg mb-0.5 hover:bg-s2 cursor-pointer transition-colors duration-100",children:[o.jsx("div",{className:"w-[6px] h-[6px] rounded-full bg-green shrink-0"}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[13px] font-medium text-fg",children:t}),o.jsx("div",{className:"text-xs text-muted font-mono",children:e.cwd})]}),o.jsxs("div",{className:"flex gap-3",children:[o.jsxs("span",{className:"text-xs text-muted",children:[e.sessions," session",e.sessions!==1?"s":""]}),o.jsx("span",{className:"text-xs text-muted",children:e.providers.join(", ")})]}),o.jsx("span",{className:"text-[10px] font-medium rounded-full px-2 py-0.5 font-mono bg-green/10 text-green",children:"active"})]})}function Fj(){const{rpc:e,ws:t}=Cn(),[n,l]=b.useState(new Map);b.useEffect(()=>{e&&e.subagentList().then(d=>{if(Array.isArray(d)){const f=new Map;for(const h of d)f.set(h.agentId,h);l(f)}}).catch(()=>{})},[e]),b.useEffect(()=>{if(!t)return;const d=g=>{l(y=>{const m=new Map(y);return m.set(g.agentId,{agentId:g.agentId,sessionId:g.sessionId||"",prompt:g.prompt||"",provider:g.provider||"unknown",status:"starting",text:"",toolCalls:0,errors:[],inputTokens:0,outputTokens:0,startedAt:g.timestamp}),m})},f=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,text:v.text+g.text}),m})},h=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,toolCalls:v.toolCalls+1}),m})},p=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,inputTokens:v.inputTokens+(g.inputTokens||0),outputTokens:v.outputTokens+(g.outputTokens||0)}),m})},x=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,status:"done",text:g.text||v.text,toolCalls:g.toolCalls??v.toolCalls,errors:g.errors||[],doneAt:g.timestamp}),m})},S=g=>{l(y=>{const m=new Map(y),v=m.get(g.agentId);return v&&m.set(g.agentId,{...v,status:"error",errors:[...v.errors||[],g.message],doneAt:g.timestamp}),m})},w=[t.on("agent-start",d),t.on("agent-text-delta",f),t.on("agent-tool-call",h),t.on("agent-usage",p),t.on("agent-done",x),t.on("agent-error",S)];return()=>{for(const g of w)g()}},[t]);const a=b.useCallback(async d=>{if(!e)return null;try{return await e.subagentSpawn(d)}catch(f){return console.error("[useSubagents] Spawn failed:",f),null}},[e]),s=b.useCallback(async d=>{if(!e)return!1;try{return await e.subagentCancel(d),l(f=>{const h=new Map(f),p=h.get(d);return p&&h.set(d,{...p,status:"cancelled",doneAt:Date.now()}),h}),!0}catch{return!1}},[e]),i=b.useCallback(async(d,f)=>{if(!e)return!1;try{return await e.subagentSend(d,f),!0}catch{return!1}},[e]),r=Array.from(n.values()).filter(d=>d.status==="running"||d.status==="starting"),c=Array.from(n.values()).filter(d=>d.status==="done"),u=Array.from(n.values()).filter(d=>d.status==="error");return{agents:n,running:r,completed:c,failed:u,spawn:a,cancel:s,send:i}}function Pj({rpc:e,sessionId:t,className:n}){const{ws:l}=Cn(),{agents:a,running:s,completed:i,failed:r,spawn:c,cancel:u,send:d}=Fj(),[f,h]=b.useState(!1),[p,x]=b.useState(!1),[S,w]=b.useState(""),[g,y]=b.useState("auto"),[m,v]=b.useState("auto"),[j,E]=b.useState(""),[M,A]=b.useState(""),[C,H]=b.useState(""),[T,$]=b.useState(""),[V,N]=b.useState(""),[D,k]=b.useState(""),[R,z]=b.useState(""),[O,Y]=b.useState("auto"),[X,L]=b.useState(""),[U,_]=b.useState(""),[B,G]=b.useState(""),[q,Q]=b.useState(null),[K,W]=b.useState(0),P=b.useCallback(async()=>{if(!S.trim()||!e)return;let I=t;if(!I)try{const se=await e.sessionList();Array.isArray(se)&&se.length>0&&(I=se[0].id)}catch{}await c({sessionId:I||"",prompt:S.trim(),provider:j||void 0,mode:g!=="auto"?g:void 0,effort:m!=="auto"?m:void 0,model:M||void 0}),w(""),h(!1),E("")},[S,g,m,j,M,t,e,c]),J=b.useCallback(async()=>{if(!e||!C.trim()||!T||!V){L("Please fill in prompt and date/time");return}L("");const I=`${T}T${V}:00`;try{await e.taskSchedule({instruction:C.trim(),scheduled_at:I,provider:D||void 0,model:R||void 0,effort:O!=="auto"?O:void 0}),H(""),$(""),N(""),x(!1)}catch(se){L(se instanceof Error?se.message:"Failed to schedule task")}},[C,T,V,D,R,O,e]),F=b.useCallback(async()=>{!U||!B.trim()||(await d(U,B.trim()),G(""))},[U,B,d]),le=Array.from(a.values()).sort((I,se)=>(se.startedAt||0)-(I.startedAt||0)),ae=le.filter(I=>I.status==="done"||I.status==="error"||I.status==="cancelled"),te=ae.slice(K*10,(K+1)*10),ge=I=>{const se=Math.floor(I/1e3);return se<60?`${se}s`:`${Math.floor(se/60)}m${se%60}s`};return o.jsxs("div",{className:`flex-1 overflow-y-auto p-4 md:p-7 scrollbar-thin ${n||""}`,children:[o.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-3 mb-6",children:[o.jsxs("div",{children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight",children:"Agents"}),o.jsx("p",{className:"text-[11.5px] text-muted mt-0.5",children:"Parallel subagent orchestration and monitoring."})]}),o.jsxs("div",{className:"flex gap-2 self-start sm:self-auto",children:[o.jsx("button",{onClick:()=>x(!p),className:`text-xs font-medium border rounded-[8px] px-4 py-2 transition-colors select-none ${p?"bg-blue/15 text-blue border-blue/30":"bg-s2 text-muted border-b1 hover:text-fg"}`,children:"Schedule"}),o.jsx("button",{onClick:()=>h(!f),className:"text-xs font-medium bg-green/10 text-green border border-green/20 rounded-[8px] px-4 py-2 hover:bg-green/20 transition-colors duration-150 select-none",children:f?"Cancel":"+ Spawn Agent"})]})]}),f&&o.jsx("div",{className:"bg-s1 border border-b1 rounded-[10px] p-5 mb-6 animate-in",children:o.jsxs("div",{className:"flex flex-col gap-3",children:[o.jsx("textarea",{className:"bg-s2 border border-b1 rounded-[8px] p-3 text-[13px] text-fg font-mino resize-y min-h-[60px] focus:border-fg/30 outline-none transition-colors duration-150",placeholder:"What should the subagent do?",value:S,onChange:I=>w(I.target.value),onKeyDown:I=>{I.key==="Enter"&&!I.shiftKey&&(I.preventDefault(),P())}}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:g,onChange:I=>y(I.target.value),children:[o.jsx("option",{value:"auto",children:"Mode: inherit"}),o.jsx("option",{value:"plan",children:"Mode: plan"}),o.jsx("option",{value:"edit",children:"Mode: edit"}),o.jsx("option",{value:"auto",children:"Mode: auto"}),o.jsx("option",{value:"yolo",children:"Mode: yolo"})]}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:m,onChange:I=>v(I.target.value),children:[o.jsx("option",{value:"auto",children:"Effort: inherit"}),o.jsx("option",{value:"low",children:"Effort: low"}),o.jsx("option",{value:"medium",children:"Effort: medium"}),o.jsx("option",{value:"high",children:"Effort: high"}),o.jsx("option",{value:"max",children:"Effort: max"})]}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:j,onChange:I=>E(I.target.value),children:[o.jsx("option",{value:"",children:"Provider: inherit"}),o.jsx("option",{value:"anthropic",children:"Anthropic"}),o.jsx("option",{value:"openai",children:"OpenAI"}),o.jsx("option",{value:"google",children:"Google"}),o.jsx("option",{value:"ollama",children:"Ollama"}),o.jsx("option",{value:"openrouter",children:"OpenRouter"})]}),o.jsx("input",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none font-mono",placeholder:"Model override (optional)",value:M,onChange:I=>A(I.target.value)}),o.jsx("button",{onClick:P,disabled:!S.trim(),className:"bg-green/20 text-green border border-green/30 rounded-[8px] px-4 py-2 text-xs font-medium hover:bg-green/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Spawn"})]})]})}),p&&o.jsx("div",{className:"bg-s1 border border-b1 rounded-[10px] p-5 mb-6 animate-in",children:o.jsxs("div",{className:"flex flex-col gap-3",children:[o.jsx("textarea",{className:"bg-s2 border border-b1 rounded-[8px] p-3 text-[13px] text-fg font-mino resize-y min-h-[60px] focus:border-fg/30 outline-none transition-colors duration-150",placeholder:"What should the scheduled agent do?",value:C,onChange:I=>H(I.target.value)}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[o.jsx("input",{type:"date",className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:T,onChange:I=>$(I.target.value)}),o.jsx("input",{type:"time",className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:V,onChange:I=>N(I.target.value)}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:O,onChange:I=>Y(I.target.value),children:[o.jsx("option",{value:"auto",children:"Effort: auto"}),o.jsx("option",{value:"low",children:"Effort: low"}),o.jsx("option",{value:"medium",children:"Effort: medium"}),o.jsx("option",{value:"high",children:"Effort: high"}),o.jsx("option",{value:"max",children:"Effort: max"})]}),o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",value:D,onChange:I=>k(I.target.value),children:[o.jsx("option",{value:"",children:"Provider: inherit"}),o.jsx("option",{value:"anthropic",children:"Anthropic"}),o.jsx("option",{value:"openai",children:"OpenAI"}),o.jsx("option",{value:"google",children:"Google"}),o.jsx("option",{value:"ollama",children:"Ollama"}),o.jsx("option",{value:"openrouter",children:"OpenRouter"})]}),o.jsx("input",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none font-mono col-span-2 md:col-span-4",placeholder:"Model override (optional)",value:R,onChange:I=>z(I.target.value)})]}),X&&o.jsx("div",{className:"text-[11px] text-red bg-red/5 rounded-[6px] p-2",children:X}),o.jsx("button",{onClick:J,disabled:!C.trim()||!T||!V,className:"bg-blue/20 text-blue border border-blue/30 rounded-[8px] px-4 py-2 text-xs font-medium hover:bg-blue/30 transition-colors disabled:opacity-40 disabled:cursor-not-allowed self-start",children:"Schedule Agent"})]})}),o.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4 mb-6",children:[o.jsx(Dr,{label:"Running",value:String(s.length),color:"text-yellow"}),o.jsx(Dr,{label:"Completed",value:String(i.length),color:"text-green"}),o.jsx(Dr,{label:"Failed",value:String(r.length),color:"text-red"}),o.jsx(Dr,{label:"Total Tokens",value:af(le.reduce((I,se)=>I+se.inputTokens+se.outputTokens,0)),color:"text-fg"})]}),s.length>0&&o.jsxs("div",{className:"mb-6",children:[o.jsx("h3",{className:"text-[11px] font-semibold text-text2 uppercase tracking-wider mb-3",children:"Live Agents"}),o.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:s.map(I=>o.jsx(e5,{agent:I,onCancel:()=>u(I.agentId),onExpand:()=>Q(q===I.agentId?null:I.agentId)},I.agentId))})]}),ae.length>0&&o.jsxs("div",{className:"mb-6",children:[o.jsx("h3",{className:"text-[11px] font-semibold text-text2 uppercase tracking-wider mb-3",children:"History"}),o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] overflow-hidden",children:[o.jsx("div",{className:"overflow-x-auto",children:o.jsxs("table",{className:"w-full text-[12px]",children:[o.jsx("thead",{children:o.jsxs("tr",{className:"text-left text-xs text-muted border-b border-b1 font-mono text-[10px]",children:[o.jsx("th",{className:"px-4 py-2 font-medium",children:"STATUS"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"PROVIDER"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"PROMPT"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"DURATION"}),o.jsx("th",{className:"px-4 py-2 font-medium",children:"TOOLS"}),o.jsx("th",{className:"px-4 py-2 font-medium text-right",children:"TOKENS"})]})}),o.jsx("tbody",{children:te.map(I=>{const se=I.status==="done"?"text-green":I.status==="cancelled"?"text-muted2":"text-red",Re=I.doneAt?ge(I.doneAt-I.startedAt):"-",st=I.inputTokens+I.outputTokens;return o.jsxs("tr",{className:"hover:bg-s2/30 transition-colors cursor-pointer border-b border-b1/40",onClick:()=>Q(q===I.agentId?null:I.agentId),children:[o.jsx("td",{className:"px-4 py-2.5",children:o.jsx("span",{className:`text-[10px] font-mono px-2 py-0.5 rounded-[4px] ${se==="text-green"?"bg-green/10":se==="text-red"?"bg-red/10":"bg-muted/10"}`,children:I.status})}),o.jsx("td",{className:"px-4 py-2.5 text-muted font-mono text-[11.5px]",children:I.provider||"-"}),o.jsx("td",{className:"px-4 py-2.5 text-fg truncate max-w-[200px]",title:I.prompt,children:I.prompt}),o.jsx("td",{className:"px-4 py-2.5 text-muted font-mono",children:Re}),o.jsx("td",{className:"px-4 py-2.5 text-muted font-mono",children:I.toolCalls}),o.jsx("td",{className:"px-4 py-2.5 text-right font-mono text-muted",children:st>0?af(st):"-"})]},I.agentId)})})]})}),ae.length>10&&o.jsxs("div",{className:"flex items-center justify-center gap-4 py-2 border-t border-b1",children:[o.jsx("button",{className:"text-xs text-muted hover:text-fg transition-colors disabled:opacity-30",disabled:K===0,onClick:()=>W(I=>I-1),children:"Prev"}),o.jsxs("span",{className:"text-[10px] text-muted font-mono",children:[K+1," / ",Math.ceil(ae.length/10)]}),o.jsx("button",{className:"text-xs text-muted hover:text-fg transition-colors disabled:opacity-30",disabled:(K+1)*10>=ae.length,onClick:()=>W(I=>I+1),children:"Next"})]})]}),q&&(()=>{const I=a.get(q);return I?o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] p-4 mt-2",children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsxs("span",{className:"text-[11px] font-mono text-muted",children:["Agent: ",I.agentId.slice(0,12),"..."]}),o.jsx("span",{className:"text-[10px] text-muted",children:new Date(I.startedAt).toLocaleString()})]}),o.jsx("pre",{className:"text-[12px] text-fg bg-s2 rounded-[8px] p-3 overflow-x-auto max-h-[200px] overflow-y-auto whitespace-pre-wrap font-mono",children:I.text||"(no output)"}),I.errors.length>0&&o.jsx("div",{className:"mt-2 text-[11px] text-red bg-red/5 rounded-[6px] p-2",children:I.errors.map((se,Re)=>o.jsxs("div",{children:["Error: ",se]},Re))})]}):null})()]}),s.length>0&&o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] p-4 mb-6",children:[o.jsx("h3",{className:"text-[11px] font-semibold text-text2 uppercase tracking-wider mb-3",children:"Send Message to Agent"}),o.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[o.jsxs("select",{className:"bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none flex-[0.5]",value:U,onChange:I=>_(I.target.value),children:[o.jsx("option",{value:"",children:"Select agent..."}),s.map(I=>o.jsxs("option",{value:I.agentId,children:[I.prompt.slice(0,40),I.prompt.length>40?"...":""]},I.agentId))]}),o.jsx("input",{className:"flex-1 bg-s2 border border-b1 rounded-[8px] px-3 py-2 text-xs text-fg outline-none",placeholder:"Type a message to inject into the agent...",value:B,onChange:I=>G(I.target.value),onKeyDown:I=>{I.key==="Enter"&&F()}}),o.jsx("button",{onClick:F,disabled:!U||!B.trim(),className:"bg-fg/10 text-fg border border-fg/20 rounded-[8px] px-4 py-2 text-xs font-medium hover:bg-fg/20 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:"Send"})]})]}),o.jsx(n5,{ws:l})]})}function Dr({label:e,value:t,color:n}){return o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] px-5 py-4 flex flex-col justify-between select-none",children:[o.jsx("span",{className:"text-[10px] font-semibold text-muted uppercase tracking-wider",children:e}),o.jsx("div",{className:`text-2xl font-bold tracking-tight leading-none mt-1 ${n}`,children:t})]})}function e5({agent:e,onCancel:t,onExpand:n}){const l=Date.now()-e.startedAt,a=e.inputTokens+e.outputTokens,s=e.status==="running"?"text-yellow":"text-green";return o.jsxs("div",{className:"bg-s1 border border-b1 rounded-[10px] p-4 hover:border-b2 transition-colors cursor-pointer select-none",onClick:n,children:[o.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[o.jsx("div",{className:`w-[6px] h-[6px] rounded-full shrink-0 ${e.status==="running"?"bg-yellow animate-pulse":"bg-green"}`}),o.jsx("span",{className:"text-[12.5px] font-medium text-fg truncate flex-1",children:e.prompt}),o.jsx("span",{className:"text-[9px] font-mono bg-s3 px-1.5 py-0.5 rounded-[3px] text-muted shrink-0",children:e.provider}),o.jsx("span",{className:`text-[10px] font-mono ${s}`,children:e.status}),e.status==="running"&&o.jsx("button",{className:"text-[10px] text-red/70 hover:text-red font-mono shrink-0",onClick:i=>{i.stopPropagation(),t()},children:"Cancel"})]}),o.jsxs("div",{className:"text-[10.5px] text-muted font-mono mb-2",children:[t5(l)," · ",e.toolCalls," tools · ",af(a)," tok"]}),e.text&&o.jsx("div",{className:"text-[11px] text-text2 line-clamp-2 font-mono leading-relaxed",children:e.text.slice(-200)})]})}function t5(e){const t=Math.floor(e/1e3);return t<60?`${t}s`:`${Math.floor(t/60)}m${t%60}s`}function af(e){return e<1e3?String(e):e<1e6?`${(e/1e3).toFixed(1)}k`:`${(e/1e6).toFixed(1)}M`}function n5({ws:e}){const[t,n]=b.useState([]);return!e||(["agent-start","agent-text-delta","agent-done","agent-error","agent-tool-call"].forEach(a=>{e.on(a,s=>{n(i=>[{...s,_type:a},...i].slice(0,30))})}),t.length===0)?null:o.jsxs("div",{children:[o.jsx("div",{className:"h-px bg-b1 my-5"}),o.jsx("div",{className:"text-[11.5px] font-medium text-muted mb-2.5",children:"Live Agent Events"}),t.slice(0,15).map((a,s)=>o.jsxs("div",{className:"flex items-center gap-3 px-3 py-1.5 rounded-lg mb-0.5 hover:bg-s2",children:[o.jsx("div",{className:`w-[6px] h-[6px] rounded-full shrink-0 ${a._type==="agent-start"?"bg-yellow":a._type==="agent-done"?"bg-green":a._type==="agent-error"?"bg-red":a._type==="agent-tool-call"?"bg-fg":"bg-muted2"}`}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[12px] text-text font-mono",children:a._type}),o.jsx("div",{className:"text-xs text-muted truncate",children:a.prompt||a.message||""})]}),o.jsx("span",{className:"text-[10px] text-muted font-mono",children:new Date(a.timestamp).toLocaleTimeString()})]},s))]})}function l5(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return b.useMemo(()=>l=>{t.forEach(a=>a(l))},t)}const Rc=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function Ms(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function Hh(e){return"nodeType"in e}function ft(e){var t,n;return e?Ms(e)?e:Hh(e)&&(t=(n=e.ownerDocument)==null?void 0:n.defaultView)!=null?t:window:window}function Lh(e){const{Document:t}=ft(e);return e instanceof t}function er(e){return Ms(e)?!1:e instanceof ft(e).HTMLElement}function Vv(e){return e instanceof ft(e).SVGElement}function _s(e){return e?Ms(e)?e.document:Hh(e)?Lh(e)?e:er(e)||Vv(e)?e.ownerDocument:document:document:document}const on=Rc?b.useLayoutEffect:b.useEffect;function Oc(e){const t=b.useRef(e);return on(()=>{t.current=e}),b.useCallback(function(){for(var n=arguments.length,l=new Array(n),a=0;a<n;a++)l[a]=arguments[a];return t.current==null?void 0:t.current(...l)},[])}function a5(){const e=b.useRef(null),t=b.useCallback((l,a)=>{e.current=setInterval(l,a)},[]),n=b.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,n]}function Ai(e,t){t===void 0&&(t=[e]);const n=b.useRef(e);return on(()=>{n.current!==e&&(n.current=e)},t),n}function tr(e,t){const n=b.useRef();return b.useMemo(()=>{const l=e(n.current);return n.current=l,l},[...t])}function Wo(e){const t=Oc(e),n=b.useRef(null),l=b.useCallback(a=>{a!==n.current&&(t==null||t(a,n.current)),n.current=a},[]);return[n,l]}function Jo(e){const t=b.useRef();return b.useEffect(()=>{t.current=e},[e]),t.current}let Xu={};function nr(e,t){return b.useMemo(()=>{if(t)return t;const n=Xu[e]==null?0:Xu[e]+1;return Xu[e]=n,e+"-"+n},[e,t])}function Xv(e){return function(t){for(var n=arguments.length,l=new Array(n>1?n-1:0),a=1;a<n;a++)l[a-1]=arguments[a];return l.reduce((s,i)=>{const r=Object.entries(i);for(const[c,u]of r){const d=s[c];d!=null&&(s[c]=d+e*u)}return s},{...t})}}const Wa=Xv(1),Fo=Xv(-1);function s5(e){return"clientX"in e&&"clientY"in e}function Hc(e){if(!e)return!1;const{KeyboardEvent:t}=ft(e.target);return t&&e instanceof t}function i5(e){if(!e)return!1;const{TouchEvent:t}=ft(e.target);return t&&e instanceof t}function Po(e){if(i5(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return s5(e)?{x:e.clientX,y:e.clientY}:null}const Hl=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[Hl.Translate.toString(e),Hl.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:l}=e;return t+" "+n+"ms "+l}}}),am="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function r5(e){return e.matches(am)?e:e.querySelector(am)}const o5={display:"none"};function c5(e){let{id:t,value:n}=e;return Me.createElement("div",{id:t,style:o5},n)}function u5(e){let{id:t,announcement:n,ariaLiveType:l="assertive"}=e;const a={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return Me.createElement("div",{id:t,style:a,role:"status","aria-live":l,"aria-atomic":!0},n)}function d5(){const[e,t]=b.useState("");return{announce:b.useCallback(l=>{l!=null&&t(l)},[]),announcement:e}}const Gv=b.createContext(null);function f5(e){const t=b.useContext(Gv);b.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function h5(){const[e]=b.useState(()=>new Set),t=b.useCallback(l=>(e.add(l),()=>e.delete(l)),[e]);return[b.useCallback(l=>{let{type:a,event:s}=l;e.forEach(i=>{var r;return(r=i[a])==null?void 0:r.call(i,s)})},[e]),t]}const p5={draggable:`
140
140
  To pick up a draggable item, press the space bar.
141
141
  While dragging, use the arrow keys to move the item.
142
142
  Press space again to drop the item in its new position, or press escape to cancel.
143
- `},p5={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function g5(e){let{announcements:t=p5,container:n,hiddenTextDescribedById:l,screenReaderInstructions:a=h5}=e;const{announce:s,announcement:i}=u5(),r=nr("DndLiveRegion"),[c,u]=b.useState(!1);if(b.useEffect(()=>{u(!0)},[]),d5(b.useMemo(()=>({onDragStart(f){let{active:h}=f;s(t.onDragStart({active:h}))},onDragMove(f){let{active:h,over:p}=f;t.onDragMove&&s(t.onDragMove({active:h,over:p}))},onDragOver(f){let{active:h,over:p}=f;s(t.onDragOver({active:h,over:p}))},onDragEnd(f){let{active:h,over:p}=f;s(t.onDragEnd({active:h,over:p}))},onDragCancel(f){let{active:h,over:p}=f;s(t.onDragCancel({active:h,over:p}))}}),[s,t])),!c)return null;const d=Me.createElement(Me.Fragment,null,Me.createElement(o5,{id:l,value:a.draggable}),Me.createElement(c5,{id:r,announcement:i}));return n?Wl.createPortal(d,n):d}var Ge;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Ge||(Ge={}));function ec(){}function sm(e,t){return b.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function m5(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return b.useMemo(()=>[...t].filter(l=>l!=null),[...t])}const cn=Object.freeze({x:0,y:0});function x5(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function y5(e,t){const n=Po(e);if(!n)return"0 0";const l={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return l.x+"% "+l.y+"%"}function v5(e,t){let{data:{value:n}}=e,{data:{value:l}}=t;return n-l}function b5(e,t){let{data:{value:n}}=e,{data:{value:l}}=t;return l-n}function im(e){let{left:t,top:n,height:l,width:a}=e;return[{x:t,y:n},{x:t+a,y:n},{x:t,y:n+l},{x:t+a,y:n+l}]}function w5(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}const S5=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:l}=e;const a=im(t),s=[];for(const i of l){const{id:r}=i,c=n.get(r);if(c){const u=im(c),d=a.reduce((h,p,x)=>h+x5(u[x],p),0),f=Number((d/4).toFixed(4));s.push({id:r,data:{droppableContainer:i,value:f}})}}return s.sort(v5)};function N5(e,t){const n=Math.max(t.top,e.top),l=Math.max(t.left,e.left),a=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),i=a-l,r=s-n;if(l<a&&n<s){const c=t.width*t.height,u=e.width*e.height,d=i*r,f=d/(c+u-d);return Number(f.toFixed(4))}return 0}const j5=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:l}=e;const a=[];for(const s of l){const{id:i}=s,r=n.get(i);if(r){const c=N5(r,t);c>0&&a.push({id:i,data:{droppableContainer:s,value:c}})}}return a.sort(b5)};function k5(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function Qv(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:cn}function E5(e){return function(n){for(var l=arguments.length,a=new Array(l>1?l-1:0),s=1;s<l;s++)a[s-1]=arguments[s];return a.reduce((i,r)=>({...i,top:i.top+e*r.y,bottom:i.bottom+e*r.y,left:i.left+e*r.x,right:i.right+e*r.x}),{...n})}}const C5=E5(1);function Zv(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function M5(e,t,n){const l=Zv(t);if(!l)return e;const{scaleX:a,scaleY:s,x:i,y:r}=l,c=e.left-i-(1-a)*parseFloat(n),u=e.top-r-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=a?e.width/a:e.width,f=s?e.height/s:e.height;return{width:d,height:f,top:u,right:c+d,bottom:u+f,left:c}}const _5={ignoreTransform:!1};function As(e,t){t===void 0&&(t=_5);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:d}=ft(e).getComputedStyle(e);u&&(n=M5(n,u,d))}const{top:l,left:a,width:s,height:i,bottom:r,right:c}=n;return{top:l,left:a,width:s,height:i,bottom:r,right:c}}function rm(e){return As(e,{ignoreTransform:!0})}function A5(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function T5(e,t){return t===void 0&&(t=ft(e).getComputedStyle(e)),t.position==="fixed"}function z5(e,t){t===void 0&&(t=ft(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(a=>{const s=t[a];return typeof s=="string"?n.test(s):!1})}function $h(e,t){const n=[];function l(a){if(t!=null&&n.length>=t||!a)return n;if(Lh(a)&&a.scrollingElement!=null&&!n.includes(a.scrollingElement))return n.push(a.scrollingElement),n;if(!er(a)||Vv(a)||n.includes(a))return n;const s=ft(e).getComputedStyle(a);return a!==e&&z5(a,s)&&n.push(a),T5(a,s)?n:l(a.parentNode)}return e?l(e):n}function Iv(e){const[t]=$h(e,1);return t??null}function Gu(e){return!Rc||!e?null:Ms(e)?e:Hh(e)?Lh(e)||e===_s(e).scrollingElement?window:er(e)?e:null:null}function Kv(e){return Ms(e)?e.scrollX:e.scrollLeft}function Wv(e){return Ms(e)?e.scrollY:e.scrollTop}function sf(e){return{x:Kv(e),y:Wv(e)}}var We;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(We||(We={}));function Jv(e){return!Rc||!e?!1:e===document.scrollingElement}function Fv(e){const t={x:0,y:0},n=Jv(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},l={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},a=e.scrollTop<=t.y,s=e.scrollLeft<=t.x,i=e.scrollTop>=l.y,r=e.scrollLeft>=l.x;return{isTop:a,isLeft:s,isBottom:i,isRight:r,maxScroll:l,minScroll:t}}const D5={x:.2,y:.2};function R5(e,t,n,l,a){let{top:s,left:i,right:r,bottom:c}=n;l===void 0&&(l=10),a===void 0&&(a=D5);const{isTop:u,isBottom:d,isLeft:f,isRight:h}=Fv(e),p={x:0,y:0},x={x:0,y:0},S={height:t.height*a.y,width:t.width*a.x};return!u&&s<=t.top+S.height?(p.y=We.Backward,x.y=l*Math.abs((t.top+S.height-s)/S.height)):!d&&c>=t.bottom-S.height&&(p.y=We.Forward,x.y=l*Math.abs((t.bottom-S.height-c)/S.height)),!h&&r>=t.right-S.width?(p.x=We.Forward,x.x=l*Math.abs((t.right-S.width-r)/S.width)):!f&&i<=t.left+S.width&&(p.x=We.Backward,x.x=l*Math.abs((t.left+S.width-i)/S.width)),{direction:p,speed:x}}function O5(e){if(e===document.scrollingElement){const{innerWidth:s,innerHeight:i}=window;return{top:0,left:0,right:s,bottom:i,width:s,height:i}}const{top:t,left:n,right:l,bottom:a}=e.getBoundingClientRect();return{top:t,left:n,right:l,bottom:a,width:e.clientWidth,height:e.clientHeight}}function Pv(e){return e.reduce((t,n)=>Wa(t,sf(n)),cn)}function H5(e){return e.reduce((t,n)=>t+Kv(n),0)}function L5(e){return e.reduce((t,n)=>t+Wv(n),0)}function e1(e,t){if(t===void 0&&(t=As),!e)return;const{top:n,left:l,bottom:a,right:s}=t(e);Iv(e)&&(a<=0||s<=0||n>=window.innerHeight||l>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const $5=[["x",["left","right"],H5],["y",["top","bottom"],L5]];class Bh{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const l=$h(n),a=Pv(l);this.rect={...t},this.width=t.width,this.height=t.height;for(const[s,i,r]of $5)for(const c of i)Object.defineProperty(this,c,{get:()=>{const u=r(l),d=a[s]-u;return this.rect[c]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class di{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var l;return(l=this.target)==null?void 0:l.removeEventListener(...n)})},this.target=t}add(t,n,l){var a;(a=this.target)==null||a.addEventListener(t,n,l),this.listeners.push([t,n,l])}}function B5(e){const{EventTarget:t}=ft(e);return e instanceof t?e:_s(e)}function Qu(e,t){const n=Math.abs(e.x),l=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+l**2)>t:"x"in t&&"y"in t?n>t.x&&l>t.y:"x"in t?n>t.x:"y"in t?l>t.y:!1}var qt;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(qt||(qt={}));function om(e){e.preventDefault()}function U5(e){e.stopPropagation()}var me;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(me||(me={}));const t1={start:[me.Space,me.Enter],cancel:[me.Esc],end:[me.Space,me.Enter,me.Tab]},q5=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case me.Right:return{...n,x:n.x+25};case me.Left:return{...n,x:n.x-25};case me.Down:return{...n,y:n.y+25};case me.Up:return{...n,y:n.y-25}}};class Uh{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new di(_s(n)),this.windowListeners=new di(ft(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(qt.Resize,this.handleCancel),this.windowListeners.add(qt.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(qt.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,l=t.node.current;l&&e1(l),n(cn)}handleKeyDown(t){if(Hc(t)){const{active:n,context:l,options:a}=this.props,{keyboardCodes:s=t1,coordinateGetter:i=q5,scrollBehavior:r="smooth"}=a,{code:c}=t;if(s.end.includes(c)){this.handleEnd(t);return}if(s.cancel.includes(c)){this.handleCancel(t);return}const{collisionRect:u}=l.current,d=u?{x:u.left,y:u.top}:cn;this.referenceCoordinates||(this.referenceCoordinates=d);const f=i(t,{active:n,context:l.current,currentCoordinates:d});if(f){const h=Fo(f,d),p={x:0,y:0},{scrollableAncestors:x}=l.current;for(const S of x){const w=t.code,{isTop:g,isRight:y,isLeft:m,isBottom:v,maxScroll:j,minScroll:E}=Fv(S),M=O5(S),A={x:Math.min(w===me.Right?M.right-M.width/2:M.right,Math.max(w===me.Right?M.left:M.left+M.width/2,f.x)),y:Math.min(w===me.Down?M.bottom-M.height/2:M.bottom,Math.max(w===me.Down?M.top:M.top+M.height/2,f.y))},C=w===me.Right&&!y||w===me.Left&&!m,H=w===me.Down&&!v||w===me.Up&&!g;if(C&&A.x!==f.x){const T=S.scrollLeft+h.x,$=w===me.Right&&T<=j.x||w===me.Left&&T>=E.x;if($&&!h.y){S.scrollTo({left:T,behavior:r});return}$?p.x=S.scrollLeft-T:p.x=w===me.Right?S.scrollLeft-j.x:S.scrollLeft-E.x,p.x&&S.scrollBy({left:-p.x,behavior:r});break}else if(H&&A.y!==f.y){const T=S.scrollTop+h.y,$=w===me.Down&&T<=j.y||w===me.Up&&T>=E.y;if($&&!h.x){S.scrollTo({top:T,behavior:r});return}$?p.y=S.scrollTop-T:p.y=w===me.Down?S.scrollTop-j.y:S.scrollTop-E.y,p.y&&S.scrollBy({top:-p.y,behavior:r});break}}this.handleMove(t,Wa(Fo(f,this.referenceCoordinates),p))}}}handleMove(t,n){const{onMove:l}=this.props;t.preventDefault(),l(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Uh.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:l=t1,onActivation:a}=t,{active:s}=n;const{code:i}=e.nativeEvent;if(l.start.includes(i)){const r=s.activatorNode.current;return r&&e.target!==r?!1:(e.preventDefault(),a==null||a({event:e.nativeEvent}),!0)}return!1}}];function cm(e){return!!(e&&"distance"in e)}function um(e){return!!(e&&"delay"in e)}class qh{constructor(t,n,l){var a;l===void 0&&(l=B5(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:s}=t,{target:i}=s;this.props=t,this.events=n,this.document=_s(i),this.documentListeners=new di(this.document),this.listeners=new di(l),this.windowListeners=new di(ft(i)),this.initialCoordinates=(a=Po(s))!=null?a:cn,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:l}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(qt.Resize,this.handleCancel),this.windowListeners.add(qt.DragStart,om),this.windowListeners.add(qt.VisibilityChange,this.handleCancel),this.windowListeners.add(qt.ContextMenu,om),this.documentListeners.add(qt.Keydown,this.handleKeydown),n){if(l!=null&&l({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(um(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(cm(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:l,onPending:a}=this.props;a(l,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(qt.Click,U5,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(qt.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:l,initialCoordinates:a,props:s}=this,{onMove:i,options:{activationConstraint:r}}=s;if(!a)return;const c=(n=Po(t))!=null?n:cn,u=Fo(a,c);if(!l&&r){if(cm(r)){if(r.tolerance!=null&&Qu(u,r.tolerance))return this.handleCancel();if(Qu(u,r.distance))return this.handleStart()}if(um(r)&&Qu(u,r.tolerance))return this.handleCancel();this.handlePending(r,u);return}t.cancelable&&t.preventDefault(),i(c)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===me.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const Y5={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Yh extends qh{constructor(t){const{event:n}=t,l=_s(n.target);super(t,Y5,l)}}Yh.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:l}=t;return!n.isPrimary||n.button!==0?!1:(l==null||l({event:n}),!0)}}];const V5={move:{name:"mousemove"},end:{name:"mouseup"}};var rf;(function(e){e[e.RightClick=2]="RightClick"})(rf||(rf={}));class X5 extends qh{constructor(t){super(t,V5,_s(t.event.target))}}X5.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:l}=t;return n.button===rf.RightClick?!1:(l==null||l({event:n}),!0)}}];const Zu={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class G5 extends qh{constructor(t){super(t,Zu)}static setup(){return window.addEventListener(Zu.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Zu.move.name,t)};function t(){}}}G5.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:l}=t;const{touches:a}=n;return a.length>1?!1:(l==null||l({event:n}),!0)}}];var fi;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(fi||(fi={}));var tc;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(tc||(tc={}));function Q5(e){let{acceleration:t,activator:n=fi.Pointer,canScroll:l,draggingRect:a,enabled:s,interval:i=5,order:r=tc.TreeOrder,pointerCoordinates:c,scrollableAncestors:u,scrollableAncestorRects:d,delta:f,threshold:h}=e;const p=I5({delta:f,disabled:!s}),[x,S]=l5(),w=b.useRef({x:0,y:0}),g=b.useRef({x:0,y:0}),y=b.useMemo(()=>{switch(n){case fi.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case fi.DraggableRect:return a}},[n,a,c]),m=b.useRef(null),v=b.useCallback(()=>{const E=m.current;if(!E)return;const M=w.current.x*g.current.x,A=w.current.y*g.current.y;E.scrollBy(M,A)},[]),j=b.useMemo(()=>r===tc.TreeOrder?[...u].reverse():u,[r,u]);b.useEffect(()=>{if(!s||!u.length||!y){S();return}for(const E of j){if((l==null?void 0:l(E))===!1)continue;const M=u.indexOf(E),A=d[M];if(!A)continue;const{direction:C,speed:H}=R5(E,A,y,t,h);for(const T of["x","y"])p[T][C[T]]||(H[T]=0,C[T]=0);if(H.x>0||H.y>0){S(),m.current=E,x(v,i),w.current=H,g.current=C;return}}w.current={x:0,y:0},g.current={x:0,y:0},S()},[t,v,l,S,s,i,JSON.stringify(y),JSON.stringify(p),x,u,j,d,JSON.stringify(h)])}const Z5={x:{[We.Backward]:!1,[We.Forward]:!1},y:{[We.Backward]:!1,[We.Forward]:!1}};function I5(e){let{delta:t,disabled:n}=e;const l=Jo(t);return tr(a=>{if(n||!l||!a)return Z5;const s={x:Math.sign(t.x-l.x),y:Math.sign(t.y-l.y)};return{x:{[We.Backward]:a.x[We.Backward]||s.x===-1,[We.Forward]:a.x[We.Forward]||s.x===1},y:{[We.Backward]:a.y[We.Backward]||s.y===-1,[We.Forward]:a.y[We.Forward]||s.y===1}}},[n,t,l])}function K5(e,t){const n=t!=null?e.get(t):void 0,l=n?n.node.current:null;return tr(a=>{var s;return t==null?null:(s=l??a)!=null?s:null},[l,t])}function W5(e,t){return b.useMemo(()=>e.reduce((n,l)=>{const{sensor:a}=l,s=a.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,l)}));return[...n,...s]},[]),[e,t])}var Ti;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Ti||(Ti={}));var of;(function(e){e.Optimized="optimized"})(of||(of={}));const dm=new Map;function J5(e,t){let{dragging:n,dependencies:l,config:a}=t;const[s,i]=b.useState(null),{frequency:r,measure:c,strategy:u}=a,d=b.useRef(e),f=w(),h=Ai(f),p=b.useCallback(function(g){g===void 0&&(g=[]),!h.current&&i(y=>y===null?g:y.concat(g.filter(m=>!y.includes(m))))},[h]),x=b.useRef(null),S=tr(g=>{if(f&&!n)return dm;if(!g||g===dm||d.current!==e||s!=null){const y=new Map;for(let m of e){if(!m)continue;if(s&&s.length>0&&!s.includes(m.id)&&m.rect.current){y.set(m.id,m.rect.current);continue}const v=m.node.current,j=v?new Bh(c(v),v):null;m.rect.current=j,j&&y.set(m.id,j)}return y}return g},[e,s,n,f,c]);return b.useEffect(()=>{d.current=e},[e]),b.useEffect(()=>{f||p()},[n,f]),b.useEffect(()=>{s&&s.length>0&&i(null)},[JSON.stringify(s)]),b.useEffect(()=>{f||typeof r!="number"||x.current!==null||(x.current=setTimeout(()=>{p(),x.current=null},r))},[r,f,p,...l]),{droppableRects:S,measureDroppableContainers:p,measuringScheduled:s!=null};function w(){switch(u){case Ti.Always:return!1;case Ti.BeforeDragging:return n;default:return!n}}}function Vh(e,t){return tr(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function F5(e,t){return Vh(e,t)}function P5(e){let{callback:t,disabled:n}=e;const l=Oc(t),a=b.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:s}=window;return new s(l)},[l,n]);return b.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function Lc(e){let{callback:t,disabled:n}=e;const l=Oc(t),a=b.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:s}=window;return new s(l)},[n]);return b.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function ek(e){return new Bh(As(e),e)}function fm(e,t,n){t===void 0&&(t=ek);const[l,a]=b.useState(null);function s(){a(c=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=c??n)!=null?u:null}const d=t(e);return JSON.stringify(c)===JSON.stringify(d)?c:d})}const i=P5({callback(c){if(e)for(const u of c){const{type:d,target:f}=u;if(d==="childList"&&f instanceof HTMLElement&&f.contains(e)){s();break}}}}),r=Lc({callback:s});return on(()=>{s(),e?(r==null||r.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(r==null||r.disconnect(),i==null||i.disconnect())},[e]),l}function tk(e){const t=Vh(e);return Qv(e,t)}const hm=[];function nk(e){const t=b.useRef(e),n=tr(l=>e?l&&l!==hm&&e&&t.current&&e.parentNode===t.current.parentNode?l:$h(e):hm,[e]);return b.useEffect(()=>{t.current=e},[e]),n}function lk(e){const[t,n]=b.useState(null),l=b.useRef(e),a=b.useCallback(s=>{const i=Gu(s.target);i&&n(r=>r?(r.set(i,sf(i)),new Map(r)):null)},[]);return b.useEffect(()=>{const s=l.current;if(e!==s){i(s);const r=e.map(c=>{const u=Gu(c);return u?(u.addEventListener("scroll",a,{passive:!0}),[u,sf(u)]):null}).filter(c=>c!=null);n(r.length?new Map(r):null),l.current=e}return()=>{i(e),i(s)};function i(r){r.forEach(c=>{const u=Gu(c);u==null||u.removeEventListener("scroll",a)})}},[a,e]),b.useMemo(()=>e.length?t?Array.from(t.values()).reduce((s,i)=>Wa(s,i),cn):Pv(e):cn,[e,t])}function pm(e,t){t===void 0&&(t=[]);const n=b.useRef(null);return b.useEffect(()=>{n.current=null},t),b.useEffect(()=>{const l=e!==cn;l&&!n.current&&(n.current=e),!l&&n.current&&(n.current=null)},[e]),n.current?Fo(e,n.current):cn}function ak(e){b.useEffect(()=>{if(!Rc)return;const t=e.map(n=>{let{sensor:l}=n;return l.setup==null?void 0:l.setup()});return()=>{for(const n of t)n==null||n()}},e.map(t=>{let{sensor:n}=t;return n}))}function sk(e,t){return b.useMemo(()=>e.reduce((n,l)=>{let{eventName:a,handler:s}=l;return n[a]=i=>{s(i,t)},n},{}),[e,t])}function n1(e){return b.useMemo(()=>e?A5(e):null,[e])}const gm=[];function ik(e,t){t===void 0&&(t=As);const[n]=e,l=n1(n?ft(n):null),[a,s]=b.useState(gm);function i(){s(()=>e.length?e.map(c=>Jv(c)?l:new Bh(t(c),c)):gm)}const r=Lc({callback:i});return on(()=>{r==null||r.disconnect(),i(),e.forEach(c=>r==null?void 0:r.observe(c))},[e]),a}function l1(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return er(t)?t:e}function rk(e){let{measure:t}=e;const[n,l]=b.useState(null),a=b.useCallback(u=>{for(const{target:d}of u)if(er(d)){l(f=>{const h=t(d);return f?{...f,width:h.width,height:h.height}:h});break}},[t]),s=Lc({callback:a}),i=b.useCallback(u=>{const d=l1(u);s==null||s.disconnect(),d&&(s==null||s.observe(d)),l(d?t(d):null)},[t,s]),[r,c]=Wo(i);return b.useMemo(()=>({nodeRef:r,rect:n,setRef:c}),[n,r,c])}const ok=[{sensor:Yh,options:{}},{sensor:Uh,options:{}}],ck={current:{}},oo={draggable:{measure:rm},droppable:{measure:rm,strategy:Ti.WhileDragging,frequency:of.Optimized},dragOverlay:{measure:As}};class hi extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,l;return(n=(l=this.get(t))==null?void 0:l.node.current)!=null?n:void 0}}const uk={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new hi,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:ec},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:oo,measureDroppableContainers:ec,windowRect:null,measuringScheduled:!1},a1={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:ec,draggableNodes:new Map,over:null,measureDroppableContainers:ec},lr=b.createContext(a1),s1=b.createContext(uk);function dk(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new hi}}}function fk(e,t){switch(t.type){case Ge.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Ge.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Ge.DragEnd:case Ge.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Ge.RegisterDroppable:{const{element:n}=t,{id:l}=n,a=new hi(e.droppable.containers);return a.set(l,n),{...e,droppable:{...e.droppable,containers:a}}}case Ge.SetDroppableDisabled:{const{id:n,key:l,disabled:a}=t,s=e.droppable.containers.get(n);if(!s||l!==s.key)return e;const i=new hi(e.droppable.containers);return i.set(n,{...s,disabled:a}),{...e,droppable:{...e.droppable,containers:i}}}case Ge.UnregisterDroppable:{const{id:n,key:l}=t,a=e.droppable.containers.get(n);if(!a||l!==a.key)return e;const s=new hi(e.droppable.containers);return s.delete(n),{...e,droppable:{...e.droppable,containers:s}}}default:return e}}function hk(e){let{disabled:t}=e;const{active:n,activatorEvent:l,draggableNodes:a}=b.useContext(lr),s=Jo(l),i=Jo(n==null?void 0:n.id);return b.useEffect(()=>{if(!t&&!l&&s&&i!=null){if(!Hc(s)||document.activeElement===s.target)return;const r=a.get(i);if(!r)return;const{activatorNode:c,node:u}=r;if(!c.current&&!u.current)return;requestAnimationFrame(()=>{for(const d of[c.current,u.current]){if(!d)continue;const f=i5(d);if(f){f.focus();break}}})}},[l,t,a,i,s]),null}function i1(e,t){let{transform:n,...l}=t;return e!=null&&e.length?e.reduce((a,s)=>s({transform:a,...l}),n):n}function pk(e){return b.useMemo(()=>({draggable:{...oo.draggable,...e==null?void 0:e.draggable},droppable:{...oo.droppable,...e==null?void 0:e.droppable},dragOverlay:{...oo.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function gk(e){let{activeNode:t,measure:n,initialRect:l,config:a=!0}=e;const s=b.useRef(!1),{x:i,y:r}=typeof a=="boolean"?{x:a,y:a}:a;on(()=>{if(!i&&!r||!t){s.current=!1;return}if(s.current||!l)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const d=n(u),f=Qv(d,l);if(i||(f.x=0),r||(f.y=0),s.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=Iv(u);h&&h.scrollBy({top:f.y,left:f.x})}},[t,i,r,l,n])}const $c=b.createContext({...cn,scaleX:1,scaleY:1});var fl;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(fl||(fl={}));const mk=b.memo(function(t){var n,l,a,s;let{id:i,accessibility:r,autoScroll:c=!0,children:u,sensors:d=ok,collisionDetection:f=j5,measuring:h,modifiers:p,...x}=t;const S=b.useReducer(fk,void 0,dk),[w,g]=S,[y,m]=f5(),[v,j]=b.useState(fl.Uninitialized),E=v===fl.Initialized,{draggable:{active:M,nodes:A,translate:C},droppable:{containers:H}}=w,T=M!=null?A.get(M):null,$=b.useRef({initial:null,translated:null}),V=b.useMemo(()=>{var Ie;return M!=null?{id:M,data:(Ie=T==null?void 0:T.data)!=null?Ie:ck,rect:$}:null},[M,T]),N=b.useRef(null),[D,k]=b.useState(null),[R,z]=b.useState(null),O=Ai(x,Object.values(x)),Y=nr("DndDescribedBy",i),X=b.useMemo(()=>H.getEnabled(),[H]),L=pk(h),{droppableRects:U,measureDroppableContainers:_,measuringScheduled:B}=J5(X,{dragging:E,dependencies:[C.x,C.y],config:L.droppable}),G=K5(A,M),q=b.useMemo(()=>R?Po(R):null,[R]),Q=lu(),K=F5(G,L.draggable.measure);gk({activeNode:M!=null?A.get(M):null,config:Q.layoutShiftCompensation,initialRect:K,measure:L.draggable.measure});const W=fm(G,L.draggable.measure,K),P=fm(G?G.parentElement:null),J=b.useRef({activatorEvent:null,active:null,activeNode:G,collisionRect:null,collisions:null,droppableRects:U,draggableNodes:A,draggingNode:null,draggingNodeRect:null,droppableContainers:H,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),F=H.getNodeFor((n=J.current.over)==null?void 0:n.id),le=rk({measure:L.dragOverlay.measure}),ae=(l=le.nodeRef.current)!=null?l:G,te=E?(a=le.rect)!=null?a:W:null,ge=!!(le.nodeRef.current&&le.rect),I=tk(ge?null:W),se=n1(ae?ft(ae):null),Re=nk(E?F??G:null),st=ik(Re),Nt=i1(p,{transform:{x:C.x-I.x,y:C.y-I.y,scaleX:1,scaleY:1},activatorEvent:R,active:V,activeNodeRect:W,containerNodeRect:P,draggingNodeRect:te,over:J.current.over,overlayNodeRect:le.rect,scrollableAncestors:Re,scrollableAncestorRects:st,windowRect:se}),Ht=q?Wa(q,C):null,ll=lk(Re),_n=pm(ll),Jt=pm(ll,[W]),Lt=Wa(Nt,_n),An=te?C5(te,Nt):null,Bl=V&&An?f({active:V,collisionRect:An,droppableRects:U,droppableContainers:X,pointerCoordinates:Ht}):null,wa=w5(Bl,"id"),[fn,ur]=b.useState(null),Fc=ge?Nt:Wa(Nt,Jt),Pc=k5(Fc,(s=fn==null?void 0:fn.rect)!=null?s:null,W),Ts=b.useRef(null),dr=b.useCallback((Ie,it)=>{let{sensor:rt,options:hn}=it;if(N.current==null)return;const ht=A.get(N.current);if(!ht)return;const ot=Ie.nativeEvent,$t=new rt({active:N.current,activeNode:ht,event:ot,options:hn,context:J,onAbort(Xe){if(!A.get(Xe))return;const{onDragAbort:Bt}=O.current,Ft={id:Xe};Bt==null||Bt(Ft),y({type:"onDragAbort",event:Ft})},onPending(Xe,pn,Bt,Ft){if(!A.get(Xe))return;const{onDragPending:ql}=O.current,gn={id:Xe,constraint:pn,initialCoordinates:Bt,offset:Ft};ql==null||ql(gn),y({type:"onDragPending",event:gn})},onStart(Xe){const pn=N.current;if(pn==null)return;const Bt=A.get(pn);if(!Bt)return;const{onDragStart:Ft}=O.current,Ul={activatorEvent:ot,active:{id:pn,data:Bt.data,rect:$}};Wl.unstable_batchedUpdates(()=>{Ft==null||Ft(Ul),j(fl.Initializing),g({type:Ge.DragStart,initialCoordinates:Xe,active:pn}),y({type:"onDragStart",event:Ul}),k(Ts.current),z(ot)})},onMove(Xe){g({type:Ge.DragMove,coordinates:Xe})},onEnd:al(Ge.DragEnd),onCancel:al(Ge.DragCancel)});Ts.current=$t;function al(Xe){return async function(){const{active:Bt,collisions:Ft,over:Ul,scrollAdjustedTranslate:ql}=J.current;let gn=null;if(Bt&&ql){const{cancelDrop:Yl}=O.current;gn={activatorEvent:ot,active:Bt,collisions:Ft,delta:ql,over:Ul},Xe===Ge.DragEnd&&typeof Yl=="function"&&await Promise.resolve(Yl(gn))&&(Xe=Ge.DragCancel)}N.current=null,Wl.unstable_batchedUpdates(()=>{g({type:Xe}),j(fl.Uninitialized),ur(null),k(null),z(null),Ts.current=null;const Yl=Xe===Ge.DragEnd?"onDragEnd":"onDragCancel";if(gn){const zs=O.current[Yl];zs==null||zs(gn),y({type:Yl,event:gn})}})}}},[A]),eu=b.useCallback((Ie,it)=>(rt,hn)=>{const ht=rt.nativeEvent,ot=A.get(hn);if(N.current!==null||!ot||ht.dndKit||ht.defaultPrevented)return;const $t={active:ot};Ie(rt,it.options,$t)===!0&&(ht.dndKit={capturedBy:it.sensor},N.current=hn,dr(rt,it))},[A,dr]),fr=W5(d,eu);ak(d),on(()=>{W&&v===fl.Initializing&&j(fl.Initialized)},[W,v]),b.useEffect(()=>{const{onDragMove:Ie}=O.current,{active:it,activatorEvent:rt,collisions:hn,over:ht}=J.current;if(!it||!rt)return;const ot={active:it,activatorEvent:rt,collisions:hn,delta:{x:Lt.x,y:Lt.y},over:ht};Wl.unstable_batchedUpdates(()=>{Ie==null||Ie(ot),y({type:"onDragMove",event:ot})})},[Lt.x,Lt.y]),b.useEffect(()=>{const{active:Ie,activatorEvent:it,collisions:rt,droppableContainers:hn,scrollAdjustedTranslate:ht}=J.current;if(!Ie||N.current==null||!it||!ht)return;const{onDragOver:ot}=O.current,$t=hn.get(wa),al=$t&&$t.rect.current?{id:$t.id,rect:$t.rect.current,data:$t.data,disabled:$t.disabled}:null,Xe={active:Ie,activatorEvent:it,collisions:rt,delta:{x:ht.x,y:ht.y},over:al};Wl.unstable_batchedUpdates(()=>{ur(al),ot==null||ot(Xe),y({type:"onDragOver",event:Xe})})},[wa]),on(()=>{J.current={activatorEvent:R,active:V,activeNode:G,collisionRect:An,collisions:Bl,droppableRects:U,draggableNodes:A,draggingNode:ae,draggingNodeRect:te,droppableContainers:H,over:fn,scrollableAncestors:Re,scrollAdjustedTranslate:Lt},$.current={initial:te,translated:An}},[V,G,Bl,An,A,ae,te,U,H,fn,Re,Lt]),Q5({...Q,delta:C,draggingRect:An,pointerCoordinates:Ht,scrollableAncestors:Re,scrollableAncestorRects:st});const tu=b.useMemo(()=>({active:V,activeNode:G,activeNodeRect:W,activatorEvent:R,collisions:Bl,containerNodeRect:P,dragOverlay:le,draggableNodes:A,droppableContainers:H,droppableRects:U,over:fn,measureDroppableContainers:_,scrollableAncestors:Re,scrollableAncestorRects:st,measuringConfiguration:L,measuringScheduled:B,windowRect:se}),[V,G,W,R,Bl,P,le,A,H,U,fn,_,Re,st,L,B,se]),nu=b.useMemo(()=>({activatorEvent:R,activators:fr,active:V,activeNodeRect:W,ariaDescribedById:{draggable:Y},dispatch:g,draggableNodes:A,over:fn,measureDroppableContainers:_}),[R,fr,V,W,g,Y,A,fn,_]);return Me.createElement(Gv.Provider,{value:m},Me.createElement(lr.Provider,{value:nu},Me.createElement(s1.Provider,{value:tu},Me.createElement($c.Provider,{value:Pc},u)),Me.createElement(hk,{disabled:(r==null?void 0:r.restoreFocus)===!1})),Me.createElement(g5,{...r,hiddenTextDescribedById:Y}));function lu(){const Ie=(D==null?void 0:D.autoScrollEnabled)===!1,it=typeof c=="object"?c.enabled===!1:c===!1,rt=E&&!Ie&&!it;return typeof c=="object"?{...c,enabled:rt}:{enabled:rt}}}),xk=b.createContext(null),mm="button",yk="Draggable";function vk(e){let{id:t,data:n,disabled:l=!1,attributes:a}=e;const s=nr(yk),{activators:i,activatorEvent:r,active:c,activeNodeRect:u,ariaDescribedById:d,draggableNodes:f,over:h}=b.useContext(lr),{role:p=mm,roleDescription:x="draggable",tabIndex:S=0}=a??{},w=(c==null?void 0:c.id)===t,g=b.useContext(w?$c:xk),[y,m]=Wo(),[v,j]=Wo(),E=sk(i,t),M=Ai(n);on(()=>(f.set(t,{id:t,key:s,node:y,activatorNode:v,data:M}),()=>{const C=f.get(t);C&&C.key===s&&f.delete(t)}),[f,t]);const A=b.useMemo(()=>({role:p,tabIndex:S,"aria-disabled":l,"aria-pressed":w&&p===mm?!0:void 0,"aria-roledescription":x,"aria-describedby":d.draggable}),[l,p,S,w,x,d.draggable]);return{active:c,activatorEvent:r,activeNodeRect:u,attributes:A,isDragging:w,listeners:l?void 0:E,node:y,over:h,setNodeRef:m,setActivatorNodeRef:j,transform:g}}function r1(){return b.useContext(s1)}const bk="Droppable",wk={timeout:25};function o1(e){let{data:t,disabled:n=!1,id:l,resizeObserverConfig:a}=e;const s=nr(bk),{active:i,dispatch:r,over:c,measureDroppableContainers:u}=b.useContext(lr),d=b.useRef({disabled:n}),f=b.useRef(!1),h=b.useRef(null),p=b.useRef(null),{disabled:x,updateMeasurementsFor:S,timeout:w}={...wk,...a},g=Ai(S??l),y=b.useCallback(()=>{if(!f.current){f.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{u(Array.isArray(g.current)?g.current:[g.current]),p.current=null},w)},[w]),m=Lc({callback:y,disabled:x||!i}),v=b.useCallback((A,C)=>{m&&(C&&(m.unobserve(C),f.current=!1),A&&m.observe(A))},[m]),[j,E]=Wo(v),M=Ai(t);return b.useEffect(()=>{!m||!j.current||(m.disconnect(),f.current=!1,m.observe(j.current))},[j,m]),b.useEffect(()=>(r({type:Ge.RegisterDroppable,element:{id:l,key:s,disabled:n,node:j,rect:h,data:M}}),()=>r({type:Ge.UnregisterDroppable,key:s,id:l})),[l]),b.useEffect(()=>{n!==d.current.disabled&&(r({type:Ge.SetDroppableDisabled,id:l,key:s,disabled:n}),d.current.disabled=n)},[l,s,n,r]),{active:i,rect:h,isOver:(c==null?void 0:c.id)===l,node:j,over:c,setNodeRef:E}}function Sk(e){let{animation:t,children:n}=e;const[l,a]=b.useState(null),[s,i]=b.useState(null),r=Jo(n);return!n&&!l&&r&&a(r),on(()=>{if(!s)return;const c=l==null?void 0:l.key,u=l==null?void 0:l.props.id;if(c==null||u==null){a(null);return}Promise.resolve(t(u,s)).then(()=>{a(null)})},[t,l,s]),Me.createElement(Me.Fragment,null,n,l?b.cloneElement(l,{ref:i}):null)}const Nk={x:0,y:0,scaleX:1,scaleY:1};function jk(e){let{children:t}=e;return Me.createElement(lr.Provider,{value:a1},Me.createElement($c.Provider,{value:Nk},t))}const kk={position:"fixed",touchAction:"none"},Ek=e=>Hc(e)?"transform 250ms ease":void 0,Ck=b.forwardRef((e,t)=>{let{as:n,activatorEvent:l,adjustScale:a,children:s,className:i,rect:r,style:c,transform:u,transition:d=Ek}=e;if(!r)return null;const f=a?u:{...u,scaleX:1,scaleY:1},h={...kk,width:r.width,height:r.height,top:r.top,left:r.left,transform:Hl.Transform.toString(f),transformOrigin:a&&l?y5(l,r):void 0,transition:typeof d=="function"?d(l):d,...c};return Me.createElement(n,{className:i,style:h,ref:t},s)}),Mk=e=>t=>{let{active:n,dragOverlay:l}=t;const a={},{styles:s,className:i}=e;if(s!=null&&s.active)for(const[r,c]of Object.entries(s.active))c!==void 0&&(a[r]=n.node.style.getPropertyValue(r),n.node.style.setProperty(r,c));if(s!=null&&s.dragOverlay)for(const[r,c]of Object.entries(s.dragOverlay))c!==void 0&&l.node.style.setProperty(r,c);return i!=null&&i.active&&n.node.classList.add(i.active),i!=null&&i.dragOverlay&&l.node.classList.add(i.dragOverlay),function(){for(const[c,u]of Object.entries(a))n.node.style.setProperty(c,u);i!=null&&i.active&&n.node.classList.remove(i.active)}},_k=e=>{let{transform:{initial:t,final:n}}=e;return[{transform:Hl.Transform.toString(t)},{transform:Hl.Transform.toString(n)}]},Ak={duration:250,easing:"ease",keyframes:_k,sideEffects:Mk({styles:{active:{opacity:"0"}}})};function Tk(e){let{config:t,draggableNodes:n,droppableContainers:l,measuringConfiguration:a}=e;return Oc((s,i)=>{if(t===null)return;const r=n.get(s);if(!r)return;const c=r.node.current;if(!c)return;const u=l1(i);if(!u)return;const{transform:d}=ft(i).getComputedStyle(i),f=Zv(d);if(!f)return;const h=typeof t=="function"?t:zk(t);return e1(c,a.draggable.measure),h({active:{id:s,data:r.data,node:c,rect:a.draggable.measure(c)},draggableNodes:n,dragOverlay:{node:i,rect:a.dragOverlay.measure(u)},droppableContainers:l,measuringConfiguration:a,transform:f})})}function zk(e){const{duration:t,easing:n,sideEffects:l,keyframes:a}={...Ak,...e};return s=>{let{active:i,dragOverlay:r,transform:c,...u}=s;if(!t)return;const d={x:r.rect.left-i.rect.left,y:r.rect.top-i.rect.top},f={scaleX:c.scaleX!==1?i.rect.width*c.scaleX/r.rect.width:1,scaleY:c.scaleY!==1?i.rect.height*c.scaleY/r.rect.height:1},h={x:c.x-d.x,y:c.y-d.y,...f},p=a({...u,active:i,dragOverlay:r,transform:{initial:c,final:h}}),[x]=p,S=p[p.length-1];if(JSON.stringify(x)===JSON.stringify(S))return;const w=l==null?void 0:l({active:i,dragOverlay:r,...u}),g=r.node.animate(p,{duration:t,easing:n,fill:"forwards"});return new Promise(y=>{g.onfinish=()=>{w==null||w(),y()}})}}let xm=0;function Dk(e){return b.useMemo(()=>{if(e!=null)return xm++,xm},[e])}const Rk=Me.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:l,style:a,transition:s,modifiers:i,wrapperElement:r="div",className:c,zIndex:u=999}=e;const{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggableNodes:x,droppableContainers:S,dragOverlay:w,over:g,measuringConfiguration:y,scrollableAncestors:m,scrollableAncestorRects:v,windowRect:j}=r1(),E=b.useContext($c),M=Dk(f==null?void 0:f.id),A=i1(i,{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggingNodeRect:w.rect,over:g,overlayNodeRect:w.rect,scrollableAncestors:m,scrollableAncestorRects:v,transform:E,windowRect:j}),C=Vh(h),H=Tk({config:l,draggableNodes:x,droppableContainers:S,measuringConfiguration:y}),T=C?w.setRef:void 0;return Me.createElement(jk,null,Me.createElement(Sk,{animation:H},f&&M?Me.createElement(Ck,{key:M,id:f.id,ref:T,as:r,activatorEvent:d,adjustScale:t,className:c,transition:s,rect:C,style:{zIndex:u,...a},transform:A},n):null))});function c1(e,t,n){const l=e.slice();return l.splice(n<0?l.length+n:n,0,l.splice(t,1)[0]),l}function Ok(e,t){return e.reduce((n,l,a)=>{const s=t.get(l);return s&&(n[a]=s),n},Array(e.length))}function Rr(e){return e!==null&&e>=0}function Hk(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function Lk(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const u1=e=>{let{rects:t,activeIndex:n,overIndex:l,index:a}=e;const s=c1(t,l,n),i=t[a],r=s[a];return!r||!i?null:{x:r.left-i.left,y:r.top-i.top,scaleX:r.width/i.width,scaleY:r.height/i.height}},Or={scaleX:1,scaleY:1},$k=e=>{var t;let{activeIndex:n,activeNodeRect:l,index:a,rects:s,overIndex:i}=e;const r=(t=s[n])!=null?t:l;if(!r)return null;if(a===n){const u=s[i];return u?{x:0,y:n<i?u.top+u.height-(r.top+r.height):u.top-r.top,...Or}:null}const c=Bk(s,a,n);return a>n&&a<=i?{x:0,y:-r.height-c,...Or}:a<n&&a>=i?{x:0,y:r.height+c,...Or}:{x:0,y:0,...Or}};function Bk(e,t,n){const l=e[t],a=e[t-1],s=e[t+1];return l?n<t?a?l.top-(a.top+a.height):s?s.top-(l.top+l.height):0:s?s.top-(l.top+l.height):a?l.top-(a.top+a.height):0:0}const d1="Sortable",f1=Me.createContext({activeIndex:-1,containerId:d1,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:u1,disabled:{draggable:!1,droppable:!1}});function Uk(e){let{children:t,id:n,items:l,strategy:a=u1,disabled:s=!1}=e;const{active:i,dragOverlay:r,droppableRects:c,over:u,measureDroppableContainers:d}=r1(),f=nr(d1,n),h=r.rect!==null,p=b.useMemo(()=>l.map(E=>typeof E=="object"&&"id"in E?E.id:E),[l]),x=i!=null,S=i?p.indexOf(i.id):-1,w=u?p.indexOf(u.id):-1,g=b.useRef(p),y=!Hk(p,g.current),m=w!==-1&&S===-1||y,v=Lk(s);on(()=>{y&&x&&d(p)},[y,p,x,d]),b.useEffect(()=>{g.current=p},[p]);const j=b.useMemo(()=>({activeIndex:S,containerId:f,disabled:v,disableTransforms:m,items:p,overIndex:w,useDragOverlay:h,sortedRects:Ok(p,c),strategy:a}),[S,f,v.draggable,v.droppable,m,p,w,c,h,a]);return Me.createElement(f1.Provider,{value:j},t)}const qk=e=>{let{id:t,items:n,activeIndex:l,overIndex:a}=e;return c1(n,l,a).indexOf(t)},Yk=e=>{let{containerId:t,isSorting:n,wasDragging:l,index:a,items:s,newIndex:i,previousItems:r,previousContainerId:c,transition:u}=e;return!u||!l||r!==s&&a===i?!1:n?!0:i!==a&&t===c},Vk={duration:200,easing:"ease"},h1="transform",Xk=Hl.Transition.toString({property:h1,duration:0,easing:"linear"}),Gk={roleDescription:"sortable"};function Qk(e){let{disabled:t,index:n,node:l,rect:a}=e;const[s,i]=b.useState(null),r=b.useRef(n);return on(()=>{if(!t&&n!==r.current&&l.current){const c=a.current;if(c){const u=As(l.current,{ignoreTransform:!0}),d={x:c.left-u.left,y:c.top-u.top,scaleX:c.width/u.width,scaleY:c.height/u.height};(d.x||d.y)&&i(d)}}n!==r.current&&(r.current=n)},[t,n,l,a]),b.useEffect(()=>{s&&i(null)},[s]),s}function Zk(e){let{animateLayoutChanges:t=Yk,attributes:n,disabled:l,data:a,getNewIndex:s=qk,id:i,strategy:r,resizeObserverConfig:c,transition:u=Vk}=e;const{items:d,containerId:f,activeIndex:h,disabled:p,disableTransforms:x,sortedRects:S,overIndex:w,useDragOverlay:g,strategy:y}=b.useContext(f1),m=Ik(l,p),v=d.indexOf(i),j=b.useMemo(()=>({sortable:{containerId:f,index:v,items:d},...a}),[f,a,v,d]),E=b.useMemo(()=>d.slice(d.indexOf(i)),[d,i]),{rect:M,node:A,isOver:C,setNodeRef:H}=o1({id:i,data:j,disabled:m.droppable,resizeObserverConfig:{updateMeasurementsFor:E,...c}}),{active:T,activatorEvent:$,activeNodeRect:V,attributes:N,setNodeRef:D,listeners:k,isDragging:R,over:z,setActivatorNodeRef:O,transform:Y}=vk({id:i,data:j,attributes:{...Gk,...n},disabled:m.draggable}),X=n5(H,D),L=!!T,U=L&&!x&&Rr(h)&&Rr(w),_=!g&&R,B=_&&U?Y:null,q=U?B??(r??y)({rects:S,activeNodeRect:V,activeIndex:h,overIndex:w,index:v}):null,Q=Rr(h)&&Rr(w)?s({id:i,items:d,activeIndex:h,overIndex:w}):v,K=T==null?void 0:T.id,W=b.useRef({activeId:K,items:d,newIndex:Q,containerId:f}),P=d!==W.current.items,J=t({active:T,containerId:f,isDragging:R,isSorting:L,id:i,index:v,items:d,newIndex:W.current.newIndex,previousItems:W.current.items,previousContainerId:W.current.containerId,transition:u,wasDragging:W.current.activeId!=null}),F=Qk({disabled:!J,index:v,node:A,rect:M});return b.useEffect(()=>{L&&W.current.newIndex!==Q&&(W.current.newIndex=Q),f!==W.current.containerId&&(W.current.containerId=f),d!==W.current.items&&(W.current.items=d)},[L,Q,f,d]),b.useEffect(()=>{if(K===W.current.activeId)return;if(K!=null&&W.current.activeId==null){W.current.activeId=K;return}const ae=setTimeout(()=>{W.current.activeId=K},50);return()=>clearTimeout(ae)},[K]),{active:T,activeIndex:h,attributes:N,data:j,rect:M,index:v,newIndex:Q,items:d,isOver:C,isSorting:L,isDragging:R,listeners:k,node:A,overIndex:w,over:z,setNodeRef:X,setActivatorNodeRef:O,setDroppableNodeRef:H,setDraggableNodeRef:D,transform:F??q,transition:le()};function le(){if(F||P&&W.current.newIndex===v)return Xk;if(!(_&&!Hc($)||!u)&&(L||J))return Hl.Transition.toString({...u,property:h1})}}function Ik(e,t){var n,l;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e==null?void 0:e.draggable)!=null?n:t.draggable,droppable:(l=e==null?void 0:e.droppable)!=null?l:t.droppable}}me.Down,me.Right,me.Up,me.Left;const Xh=[{id:"backlog",label:"Backlog",statuses:["backlog"],defaultStatus:"backlog"},{id:"todo",label:"To Do",statuses:["todo","pending"],defaultStatus:"todo"},{id:"in_progress",label:"In Progress",statuses:["in_progress","executing"],defaultStatus:"in_progress"},{id:"done",label:"Done",statuses:["done","completed"],defaultStatus:"done"}],ym=new Map(Xh.map(e=>[e.id,e]));function co(e){for(const t of Xh)if(t.statuses.includes(e))return t.id;return null}function Kk(e){const t=new Map;for(const n of e){const l=co(n.status);l&&t.set(n.id,l)}return t}const vm=["canceled","failed"],Wk={critical:"var(--red)",high:"var(--yellow)",medium:"var(--muted)",low:"var(--green)"},Gh={human:"H",agent:"A",notify:"N"};function Jk({task:e}){const t=Wk[e.priority]||"var(--muted)",n=e.scheduled_at?new Date(e.scheduled_at).toLocaleDateString(void 0,{month:"short",day:"numeric"}):null;return o.jsxs("div",{className:"glass-card rounded-xl p-3 mb-2 w-[256px] select-none",children:[o.jsx("div",{className:"flex items-center justify-between mb-1.5",children:o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor",className:"text-muted2",children:[o.jsx("circle",{cx:"3",cy:"2",r:"1"}),o.jsx("circle",{cx:"9",cy:"2",r:"1"}),o.jsx("circle",{cx:"3",cy:"6",r:"1"}),o.jsx("circle",{cx:"9",cy:"6",r:"1"}),o.jsx("circle",{cx:"3",cy:"10",r:"1"}),o.jsx("circle",{cx:"9",cy:"10",r:"1"})]}),o.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:t}})]})}),o.jsx("div",{className:"text-[12.5px] font-medium text-fg mb-1.5 leading-snug line-clamp-3",children:e.title}),o.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[o.jsxs("span",{className:"text-[9px] font-mono font-bold px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:["[",Gh[e.mode]||"?","]"]}),e.scope==="project"&&o.jsx("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:"proj"}),n&&o.jsx("span",{className:"text-[9px] text-muted2",children:n}),e.tags.slice(0,3).map(l=>o.jsx("span",{className:"leather-tag text-[9px] px-1.5 py-0.5 rounded-full text-muted",children:l},l)),e.tags.length>3&&o.jsxs("span",{className:"text-[9px] text-muted2",children:["+",e.tags.length-3]})]})]})}function Fk({task:e,onEdit:t,onRemove:n}){const{attributes:l,listeners:a,setNodeRef:s,transform:i,isDragging:r}=Zk({id:e.id,animateLayoutChanges:()=>!1}),c={transform:Hl.Transform.toString(i),opacity:r?0:1};return o.jsxs("div",{ref:s,style:c,className:"cursor-grab active:cursor-grabbing",...l,...a,onClick:()=>t(e),children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("div",{}),o.jsx("button",{onClick:u=>{u.stopPropagation(),n(e.id)},className:"text-muted2 hover:text-red transition-colors p-0.5 rounded cursor-pointer",title:"Delete task",children:o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsx("div",{className:"text-[12.5px] font-medium text-fg mb-1.5 leading-snug line-clamp-3 glass-card rounded-xl p-3 mb-2",children:e.title}),o.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap px-3 pb-2",children:[o.jsxs("span",{className:"text-[9px] font-mono font-bold px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:["[",Gh[e.mode]||"?","]"]}),e.scope==="project"&&o.jsx("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:"proj"}),e.scheduled_at&&o.jsx("span",{className:"text-[9px] text-muted2",children:new Date(e.scheduled_at).toLocaleDateString(void 0,{month:"short",day:"numeric"})}),e.tags.slice(0,3).map(u=>o.jsx("span",{className:"leather-tag text-[9px] px-1.5 py-0.5 rounded-full text-muted",children:u},u)),e.tags.length>3&&o.jsxs("span",{className:"text-[9px] text-muted2",children:["+",e.tags.length-3]})]})]})}function Pk({column:e,tasks:t,isDragging:n,onEdit:l,onRemove:a,className:s=""}){const{setNodeRef:i,isOver:r}=o1({id:e.id}),c=function(u){return o.jsx(Fk,{task:u,onEdit:l,onRemove:a},u.id)};return o.jsxs("div",{className:`flex flex-col h-full min-w-[260px] sm:flex-1 ${s}`,children:[o.jsx("div",{className:"flex items-center justify-between px-3 py-2.5 shrink-0",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[12px] font-semibold font-display",style:{color:"var(--gold)"},children:e.label}),o.jsx("span",{className:"text-[10px] font-mono text-muted bg-s3 px-1.5 py-0.5 rounded",children:t.length})]})}),o.jsxs("div",{ref:i,className:"flex-1 px-2 pb-2 min-h-0 relative transition-colors duration-150 rounded-xl kanban-column-scroll",style:{overflowY:n?"visible":"auto",background:r?"color-mix(in srgb, var(--gold) 8%, transparent)":"transparent"},children:[t.map(c),t.length===0&&o.jsx("div",{className:"text-center py-8 text-[11px] text-muted2 min-h-[120px] flex items-center justify-center",children:"No tasks"})]})]})}function bm({task:e,onSave:t,onClose:n}){const[l,a]=b.useState((e==null?void 0:e.title)??""),[s,i]=b.useState((e==null?void 0:e.description)??""),[r,c]=b.useState((e==null?void 0:e.priority)??"medium"),[u,d]=b.useState((e==null?void 0:e.mode)??"human"),[f,h]=b.useState((e==null?void 0:e.scope)??"personal"),[p,x]=b.useState((e==null?void 0:e.status)??"backlog"),[S,w]=b.useState(()=>{if(e!=null&&e.scheduled_at){const v=new Date(e.scheduled_at),j=v.getTimezoneOffset()*6e4;return new Date(v.getTime()-j).toISOString().slice(0,16)}return""}),[g,y]=b.useState((e==null?void 0:e.tags.join(", "))??""),m=()=>{l.trim()&&t({title:l.trim(),description:s.trim(),priority:r,mode:u,scope:f,status:p,tags:g.split(",").map(v=>v.trim()).filter(Boolean),scheduled_at:S?new Date(S).getTime():void 0})};return o.jsx("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center p-4 animate-fadeIn",style:{background:"rgba(10, 8, 5, 0.7)",backdropFilter:"blur(8px)"},onClick:n,children:o.jsxs("div",{className:"w-full max-w-[420px] rounded-2xl shadow-2xl animate-scaleIn select-none glass-card p-5",onClick:v=>v.stopPropagation(),children:[o.jsxs("div",{className:"flex items-center justify-between pb-3 mb-4",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("span",{className:"font-bold text-[13.5px] font-display",style:{color:"var(--cream)"},children:e?"Edit Task":"New Task"}),o.jsx("button",{onClick:n,className:"text-muted hover:text-fg transition-colors cursor-pointer",children:o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Title"}),o.jsx("input",{type:"text",value:l,onChange:v=>a(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none transition-colors focus:ring-1 focus:ring-gold/30",style:{background:"var(--s2)",border:"1px solid var(--b1)"},autoFocus:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Description"}),o.jsx("textarea",{value:s,onChange:v=>i(v.target.value),rows:2,className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none resize-none transition-colors focus:ring-1 focus:ring-gold/30 scrollbar-thin",style:{background:"var(--s2)",border:"1px solid var(--b1)"}})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Priority"}),o.jsxs("select",{value:r,onChange:v=>c(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"low",children:"Low"}),o.jsx("option",{value:"medium",children:"Medium"}),o.jsx("option",{value:"high",children:"High"}),o.jsx("option",{value:"critical",children:"Critical"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Mode"}),o.jsxs("select",{value:u,onChange:v=>d(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"human",children:"Human"}),o.jsx("option",{value:"agent",children:"Agent"}),o.jsx("option",{value:"notify",children:"Notify"})]})]})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Scope"}),o.jsxs("select",{value:f,onChange:v=>h(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"personal",children:"Personal"}),o.jsx("option",{value:"project",children:"Project"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Status"}),o.jsxs("select",{value:p,onChange:v=>x(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"backlog",children:"Backlog"}),o.jsx("option",{value:"todo",children:"To Do"}),o.jsx("option",{value:"in_progress",children:"In Progress"}),o.jsx("option",{value:"done",children:"Done"})]})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Scheduled (optional)"}),o.jsx("input",{type:"datetime-local",value:S,onChange:v=>w(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"}})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Tags (comma-separated)"}),o.jsx("input",{type:"text",value:g,onChange:v=>y(v.target.value),placeholder:"bug, feature, urgent",className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none transition-colors focus:ring-1 focus:ring-gold/30",style:{background:"var(--s2)",border:"1px solid var(--b1)"}})]})]}),o.jsxs("div",{className:"flex gap-2 mt-5",children:[o.jsx("button",{onClick:n,className:"flex-1 py-2.5 px-4 rounded-xl text-[12px] font-semibold cursor-pointer transition-all duration-150 active:scale-[0.98]",style:{background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--muted)"},children:"Cancel"}),o.jsx("button",{onClick:m,disabled:!l.trim(),className:"flex-1 btn-gold py-2.5 px-4 rounded-xl text-[12px] font-semibold cursor-pointer active:scale-[0.98] disabled:opacity-50 disabled:cursor-not-allowed",children:e?"Save":"Create"})]})]})})}function e3({rpc:e,className:t}){const{ws:n}=Cn(),[l,a]=b.useState([]),[s,i]=b.useState(!0),[r,c]=b.useState(null),[u,d]=b.useState(!1),[f,h]=b.useState(!1),[p,x]=b.useState("all"),[S,w]=b.useState("all"),[g,y]=b.useState("all"),[m,v]=b.useState(!1),j=b.useRef(null),[E,M]=b.useState({top:0,left:0}),[A,C]=b.useState(null),H=b.useCallback(async()=>{if(e)try{const _={};p!=="all"&&(_.mode=p),S!=="all"&&(_.priority=S),g!=="all"&&(_.scope=g);const B=await e.todoList(Object.keys(_).length?_:void 0);a(Array.isArray(B)?B:[])}catch(_){console.error("[Kanban] Failed to fetch tasks:",_)}finally{i(!1)}},[e,p,S,g]);b.useEffect(()=>{H()},[H]),b.useEffect(()=>{if(!n)return;const _=()=>H(),B=n.on("todo-changed",_),G=n.on("cron-task-fired",_);return()=>{B(),G()}},[n,H]),b.useEffect(()=>{if(!m)return;const _=B=>{B.target.closest("[data-filter-dropdown]")||v(!1)};return document.addEventListener("click",_),()=>document.removeEventListener("click",_)},[m]);const T=b.useMemo(()=>{const _={backlog:[],todo:[],in_progress:[],done:[]};for(const B of l){if(B.mode==="notify")continue;const G=co(B.status);G&&_[G]&&_[G].push(B)}return Object.values(_).forEach(B=>B.sort((G,q)=>G.order-q.order)),_},[l]),$=b.useMemo(()=>l.filter(_=>vm.includes(_.status)),[l]),V=b.useMemo(()=>Kk(l),[l]),N=b.useMemo(()=>{const _={backlog:[],todo:[],in_progress:[],done:[]};for(const B of l){if(B.mode==="notify")continue;const G=co(B.status);G&&!vm.includes(B.status)&&_[G].push(B.id)}return _},[l]),D=m5(sm(Yh,{activationConstraint:{delay:250,tolerance:5}}),sm(Uh)),[k,R]=b.useState(!1),z=b.useCallback(_=>{R(!0),C(String(_.active.id))},[]),O=b.useCallback(()=>{R(!1),C(null)},[]),Y=b.useCallback(async _=>{const{active:B,over:G}=_;if(!G||!e){R(!1),C(null);return}const q=String(B.id),Q=String(G.id),K=l.find(ae=>ae.id===q);if(!K){R(!1),C(null);return}if(!V.get(q)){R(!1),C(null);return}let P=K.status;const J=ym.get(Q);if(J)P=J.defaultStatus;else{const ae=l.find(te=>te.id===Q);if(ae){const te=co(ae.status);te&&(P=ym.get(te).defaultStatus)}}if(K.status!==P){const ae=K.status;a(te=>te.map(ge=>ge.id===q?{...ge,status:P}:ge));try{await e.todoUpdate({id:q,status:P})}catch{a(te=>te.map(ge=>ge.id===q?{...ge,status:ae}:ge))}}else try{await e.todoUpdate({id:q})}catch{}C(null),R(!1)},[e,l,V]),X=b.useCallback(async _=>{e&&(await e.todoCreate({title:(_.title??"").trim(),description:_.description,priority:_.priority??"medium",mode:_.mode??"human",scope:_.scope??"personal",status:_.status??"backlog",tags:_.tags,scheduled_at:_.scheduled_at}),h(!1))},[e]),L=b.useCallback(async _=>{!e||!r||(await e.todoUpdate({id:r.id,..._}),c(null))},[e,r]),U=b.useCallback(async _=>{e&&await e.todoRemove(_)},[e]);return s?o.jsx("div",{className:t||"",children:o.jsx("div",{className:"flex items-center justify-center h-full text-muted text-xs",children:"Loading tasks..."})}):o.jsxs("div",{className:`flex flex-col h-full ${t||""}`,children:[o.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("h2",{className:"text-[13px] font-semibold font-display",style:{color:"var(--cream)"},children:"Tasks"}),o.jsxs("div",{className:"relative","data-filter-dropdown":!0,children:[o.jsx("button",{ref:j,onClick:()=>{if(!m&&j.current){const _=j.current.getBoundingClientRect(),B=200;let G=_.left;G+B>window.innerWidth-8&&(G=window.innerWidth-B-8),M({top:_.bottom+4,left:Math.max(G,8)})}v(!m)},className:"p-1.5 rounded-lg cursor-pointer transition-colors",style:{background:p!=="all"||S!=="all"||g!=="all"?"var(--s3)":"transparent",border:"1px solid var(--b2)",color:"var(--muted)"},children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}),m&&Wl.createPortal(o.jsxs("div",{"data-filter-dropdown":!0,className:"fixed rounded-xl shadow-2xl p-3 space-y-2.5 w-[200px]",style:{top:E.top,left:E.left,background:"var(--s1)",border:"1px solid var(--b1)",zIndex:9999},children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[9px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Mode"}),o.jsx("div",{className:"flex rounded-lg overflow-hidden",style:{border:"1px solid var(--b2)"},children:["all","human","agent","notify"].map(_=>o.jsx("button",{onClick:()=>{x(_),v(!1)},className:"flex-1 px-1.5 py-1 text-[10px] font-mono cursor-pointer transition-all",style:{color:p===_?"var(--gold)":"var(--muted)",background:p===_?"var(--s3)":"transparent"},children:_==="all"?"All":_.charAt(0).toUpperCase()+_.slice(1)},_))})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[9px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Priority"}),o.jsxs("select",{value:S,onChange:_=>{w(_.target.value),v(!1)},className:"w-full px-2 py-1 rounded-lg text-[11px] font-mono outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b2)",color:"var(--muted)"},children:[o.jsx("option",{value:"all",children:"All"}),o.jsx("option",{value:"low",children:"Low"}),o.jsx("option",{value:"medium",children:"Medium"}),o.jsx("option",{value:"high",children:"High"}),o.jsx("option",{value:"critical",children:"Critical"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[9px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Scope"}),o.jsx("div",{className:"flex rounded-lg overflow-hidden",style:{border:"1px solid var(--b2)"},children:["all","personal","project"].map(_=>o.jsx("button",{onClick:()=>{y(_),v(!1)},className:"flex-1 px-1.5 py-1 text-[10px] font-mono cursor-pointer transition-all",style:{color:g===_?"var(--gold)":"var(--muted)",background:g===_?"var(--s3)":"transparent"},children:_==="all"?"All":_.charAt(0).toUpperCase()+_.slice(1)},_))})]})]}),document.body)]}),o.jsx("div",{className:"flex-1"}),o.jsxs("button",{onClick:()=>d(!u),className:"text-[10px] font-mono px-2 py-0.5 rounded cursor-pointer transition-all duration-150",style:{color:u?"var(--gold)":"var(--muted)",background:u?"var(--s3)":"transparent",border:"1px solid var(--b2)"},children:["Archive ",$.length]}),o.jsx("button",{onClick:()=>h(!0),className:"btn-gold px-3 py-1.5 rounded-lg text-[11px] font-semibold cursor-pointer active:scale-[0.98]",children:"Add"})]}),o.jsxs(mk,{sensors:D,collisionDetection:S5,onDragStart:z,onDragCancel:O,onDragEnd:Y,children:[o.jsx("div",{className:"flex-1 overflow-x-auto overflow-y-hidden min-h-0 snap-x snap-mandatory sm:overflow-x-visible sm:snap-none",children:o.jsx("div",{className:"flex h-full sm:gap-4 sm:flex-row flex-nowrap sm:min-w-0",children:Xh.map(_=>o.jsx(Uk,{items:N[_.id],strategy:$k,children:o.jsx(Pk,{column:_,tasks:T[_.id],isDragging:k,onEdit:c,onRemove:U,className:"snap-center flex-shrink-0 w-screen sm:w-auto sm:flex-1 px-4 sm:px-0"})},_.id))})}),o.jsx(Rk,{children:A&&o.jsx(Jk,{task:l.find(_=>_.id===A)})})]}),u&&$.length>0&&o.jsxs("div",{className:"px-4 py-3 shrink-0",style:{borderTop:"1px solid var(--b1)"},children:[o.jsx("h3",{className:"text-[11px] font-semibold text-muted mb-2",children:"Archived Tasks"}),o.jsx("div",{className:"flex gap-2 flex-wrap",children:$.map(_=>o.jsxs("div",{className:"glass-card rounded-lg px-3 py-2 flex items-center gap-2",style:{opacity:.6},children:[o.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{background:_.status==="failed"?"var(--red)":"var(--muted2)"}}),o.jsx("span",{className:"text-[11px] text-muted line-through",children:_.title}),o.jsxs("span",{className:"text-[9px] font-mono text-muted2",children:["[",Gh[_.mode],"]"]})]},_.id))})]}),f&&o.jsx(bm,{task:null,onSave:X,onClose:()=>h(!1)}),r&&o.jsx(bm,{task:r,onSave:L,onClose:()=>c(null)})]})}function Ve(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,l;n<e.length;n++)(l=Ve(e[n]))!==""&&(t+=(t&&" ")+l);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var t3={value:()=>{}};function Bc(){for(var e=0,t=arguments.length,n={},l;e<t;++e){if(!(l=arguments[e]+"")||l in n||/[\s.]/.test(l))throw new Error("illegal type: "+l);n[l]=[]}return new uo(n)}function uo(e){this._=e}function n3(e,t){return e.trim().split(/^|\s+/).map(function(n){var l="",a=n.indexOf(".");if(a>=0&&(l=n.slice(a+1),n=n.slice(0,a)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:l}})}uo.prototype=Bc.prototype={constructor:uo,on:function(e,t){var n=this._,l=n3(e+"",n),a,s=-1,i=l.length;if(arguments.length<2){for(;++s<i;)if((a=(e=l[s]).type)&&(a=l3(n[a],e.name)))return a;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++s<i;)if(a=(e=l[s]).type)n[a]=wm(n[a],e.name,t);else if(t==null)for(a in n)n[a]=wm(n[a],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new uo(e)},call:function(e,t){if((a=arguments.length-2)>0)for(var n=new Array(a),l=0,a,s;l<a;++l)n[l]=arguments[l+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(s=this._[e],l=0,a=s.length;l<a;++l)s[l].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var l=this._[e],a=0,s=l.length;a<s;++a)l[a].value.apply(t,n)}};function l3(e,t){for(var n=0,l=e.length,a;n<l;++n)if((a=e[n]).name===t)return a.value}function wm(e,t,n){for(var l=0,a=e.length;l<a;++l)if(e[l].name===t){e[l]=t3,e=e.slice(0,l).concat(e.slice(l+1));break}return n!=null&&e.push({name:t,value:n}),e}var cf="http://www.w3.org/1999/xhtml";const Sm={svg:"http://www.w3.org/2000/svg",xhtml:cf,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Uc(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Sm.hasOwnProperty(t)?{space:Sm[t],local:e}:e}function a3(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===cf&&t.documentElement.namespaceURI===cf?t.createElement(e):t.createElementNS(n,e)}}function s3(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function p1(e){var t=Uc(e);return(t.local?s3:a3)(t)}function i3(){}function Qh(e){return e==null?i3:function(){return this.querySelector(e)}}function r3(e){typeof e!="function"&&(e=Qh(e));for(var t=this._groups,n=t.length,l=new Array(n),a=0;a<n;++a)for(var s=t[a],i=s.length,r=l[a]=new Array(i),c,u,d=0;d<i;++d)(c=s[d])&&(u=e.call(c,c.__data__,d,s))&&("__data__"in c&&(u.__data__=c.__data__),r[d]=u);return new Ot(l,this._parents)}function o3(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function c3(){return[]}function g1(e){return e==null?c3:function(){return this.querySelectorAll(e)}}function u3(e){return function(){return o3(e.apply(this,arguments))}}function d3(e){typeof e=="function"?e=u3(e):e=g1(e);for(var t=this._groups,n=t.length,l=[],a=[],s=0;s<n;++s)for(var i=t[s],r=i.length,c,u=0;u<r;++u)(c=i[u])&&(l.push(e.call(c,c.__data__,u,i)),a.push(c));return new Ot(l,a)}function m1(e){return function(){return this.matches(e)}}function x1(e){return function(t){return t.matches(e)}}var f3=Array.prototype.find;function h3(e){return function(){return f3.call(this.children,e)}}function p3(){return this.firstElementChild}function g3(e){return this.select(e==null?p3:h3(typeof e=="function"?e:x1(e)))}var m3=Array.prototype.filter;function x3(){return Array.from(this.children)}function y3(e){return function(){return m3.call(this.children,e)}}function v3(e){return this.selectAll(e==null?x3:y3(typeof e=="function"?e:x1(e)))}function b3(e){typeof e!="function"&&(e=m1(e));for(var t=this._groups,n=t.length,l=new Array(n),a=0;a<n;++a)for(var s=t[a],i=s.length,r=l[a]=[],c,u=0;u<i;++u)(c=s[u])&&e.call(c,c.__data__,u,s)&&r.push(c);return new Ot(l,this._parents)}function y1(e){return new Array(e.length)}function w3(){return new Ot(this._enter||this._groups.map(y1),this._parents)}function nc(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}nc.prototype={constructor:nc,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function S3(e){return function(){return e}}function N3(e,t,n,l,a,s){for(var i=0,r,c=t.length,u=s.length;i<u;++i)(r=t[i])?(r.__data__=s[i],l[i]=r):n[i]=new nc(e,s[i]);for(;i<c;++i)(r=t[i])&&(a[i]=r)}function j3(e,t,n,l,a,s,i){var r,c,u=new Map,d=t.length,f=s.length,h=new Array(d),p;for(r=0;r<d;++r)(c=t[r])&&(h[r]=p=i.call(c,c.__data__,r,t)+"",u.has(p)?a[r]=c:u.set(p,c));for(r=0;r<f;++r)p=i.call(e,s[r],r,s)+"",(c=u.get(p))?(l[r]=c,c.__data__=s[r],u.delete(p)):n[r]=new nc(e,s[r]);for(r=0;r<d;++r)(c=t[r])&&u.get(h[r])===c&&(a[r]=c)}function k3(e){return e.__data__}function E3(e,t){if(!arguments.length)return Array.from(this,k3);var n=t?j3:N3,l=this._parents,a=this._groups;typeof e!="function"&&(e=S3(e));for(var s=a.length,i=new Array(s),r=new Array(s),c=new Array(s),u=0;u<s;++u){var d=l[u],f=a[u],h=f.length,p=C3(e.call(d,d&&d.__data__,u,l)),x=p.length,S=r[u]=new Array(x),w=i[u]=new Array(x),g=c[u]=new Array(h);n(d,f,S,w,g,p,t);for(var y=0,m=0,v,j;y<x;++y)if(v=S[y]){for(y>=m&&(m=y+1);!(j=w[m])&&++m<x;);v._next=j||null}}return i=new Ot(i,l),i._enter=r,i._exit=c,i}function C3(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function M3(){return new Ot(this._exit||this._groups.map(y1),this._parents)}function _3(e,t,n){var l=this.enter(),a=this,s=this.exit();return typeof e=="function"?(l=e(l),l&&(l=l.selection())):l=l.append(e+""),t!=null&&(a=t(a),a&&(a=a.selection())),n==null?s.remove():n(s),l&&a?l.merge(a).order():a}function A3(e){for(var t=e.selection?e.selection():e,n=this._groups,l=t._groups,a=n.length,s=l.length,i=Math.min(a,s),r=new Array(a),c=0;c<i;++c)for(var u=n[c],d=l[c],f=u.length,h=r[c]=new Array(f),p,x=0;x<f;++x)(p=u[x]||d[x])&&(h[x]=p);for(;c<a;++c)r[c]=n[c];return new Ot(r,this._parents)}function T3(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var l=e[t],a=l.length-1,s=l[a],i;--a>=0;)(i=l[a])&&(s&&i.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(i,s),s=i);return this}function z3(e){e||(e=D3);function t(f,h){return f&&h?e(f.__data__,h.__data__):!f-!h}for(var n=this._groups,l=n.length,a=new Array(l),s=0;s<l;++s){for(var i=n[s],r=i.length,c=a[s]=new Array(r),u,d=0;d<r;++d)(u=i[d])&&(c[d]=u);c.sort(t)}return new Ot(a,this._parents).order()}function D3(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function R3(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function O3(){return Array.from(this)}function H3(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var l=e[t],a=0,s=l.length;a<s;++a){var i=l[a];if(i)return i}return null}function L3(){let e=0;for(const t of this)++e;return e}function $3(){return!this.node()}function B3(e){for(var t=this._groups,n=0,l=t.length;n<l;++n)for(var a=t[n],s=0,i=a.length,r;s<i;++s)(r=a[s])&&e.call(r,r.__data__,s,a);return this}function U3(e){return function(){this.removeAttribute(e)}}function q3(e){return function(){this.removeAttributeNS(e.space,e.local)}}function Y3(e,t){return function(){this.setAttribute(e,t)}}function V3(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function X3(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function G3(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Q3(e,t){var n=Uc(e);if(arguments.length<2){var l=this.node();return n.local?l.getAttributeNS(n.space,n.local):l.getAttribute(n)}return this.each((t==null?n.local?q3:U3:typeof t=="function"?n.local?G3:X3:n.local?V3:Y3)(n,t))}function v1(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function Z3(e){return function(){this.style.removeProperty(e)}}function I3(e,t,n){return function(){this.style.setProperty(e,t,n)}}function K3(e,t,n){return function(){var l=t.apply(this,arguments);l==null?this.style.removeProperty(e):this.style.setProperty(e,l,n)}}function W3(e,t,n){return arguments.length>1?this.each((t==null?Z3:typeof t=="function"?K3:I3)(e,t,n??"")):us(this.node(),e)}function us(e,t){return e.style.getPropertyValue(t)||v1(e).getComputedStyle(e,null).getPropertyValue(t)}function J3(e){return function(){delete this[e]}}function F3(e,t){return function(){this[e]=t}}function P3(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function eE(e,t){return arguments.length>1?this.each((t==null?J3:typeof t=="function"?P3:F3)(e,t)):this.node()[e]}function b1(e){return e.trim().split(/^|\s+/)}function Zh(e){return e.classList||new w1(e)}function w1(e){this._node=e,this._names=b1(e.getAttribute("class")||"")}w1.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function S1(e,t){for(var n=Zh(e),l=-1,a=t.length;++l<a;)n.add(t[l])}function N1(e,t){for(var n=Zh(e),l=-1,a=t.length;++l<a;)n.remove(t[l])}function tE(e){return function(){S1(this,e)}}function nE(e){return function(){N1(this,e)}}function lE(e,t){return function(){(t.apply(this,arguments)?S1:N1)(this,e)}}function aE(e,t){var n=b1(e+"");if(arguments.length<2){for(var l=Zh(this.node()),a=-1,s=n.length;++a<s;)if(!l.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?lE:t?tE:nE)(n,t))}function sE(){this.textContent=""}function iE(e){return function(){this.textContent=e}}function rE(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function oE(e){return arguments.length?this.each(e==null?sE:(typeof e=="function"?rE:iE)(e)):this.node().textContent}function cE(){this.innerHTML=""}function uE(e){return function(){this.innerHTML=e}}function dE(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function fE(e){return arguments.length?this.each(e==null?cE:(typeof e=="function"?dE:uE)(e)):this.node().innerHTML}function hE(){this.nextSibling&&this.parentNode.appendChild(this)}function pE(){return this.each(hE)}function gE(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function mE(){return this.each(gE)}function xE(e){var t=typeof e=="function"?e:p1(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function yE(){return null}function vE(e,t){var n=typeof e=="function"?e:p1(e),l=t==null?yE:typeof t=="function"?t:Qh(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),l.apply(this,arguments)||null)})}function bE(){var e=this.parentNode;e&&e.removeChild(this)}function wE(){return this.each(bE)}function SE(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function NE(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function jE(e){return this.select(e?NE:SE)}function kE(e){return arguments.length?this.property("__data__",e):this.node().__data__}function EE(e){return function(t){e.call(this,t,this.__data__)}}function CE(e){return e.trim().split(/^|\s+/).map(function(t){var n="",l=t.indexOf(".");return l>=0&&(n=t.slice(l+1),t=t.slice(0,l)),{type:t,name:n}})}function ME(e){return function(){var t=this.__on;if(t){for(var n=0,l=-1,a=t.length,s;n<a;++n)s=t[n],(!e.type||s.type===e.type)&&s.name===e.name?this.removeEventListener(s.type,s.listener,s.options):t[++l]=s;++l?t.length=l:delete this.__on}}}function _E(e,t,n){return function(){var l=this.__on,a,s=EE(t);if(l){for(var i=0,r=l.length;i<r;++i)if((a=l[i]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=s,a.options=n),a.value=t;return}}this.addEventListener(e.type,s,n),a={type:e.type,name:e.name,value:t,listener:s,options:n},l?l.push(a):this.__on=[a]}}function AE(e,t,n){var l=CE(e+""),a,s=l.length,i;if(arguments.length<2){var r=this.node().__on;if(r){for(var c=0,u=r.length,d;c<u;++c)for(a=0,d=r[c];a<s;++a)if((i=l[a]).type===d.type&&i.name===d.name)return d.value}return}for(r=t?_E:ME,a=0;a<s;++a)this.each(r(l[a],t,n));return this}function j1(e,t,n){var l=v1(e),a=l.CustomEvent;typeof a=="function"?a=new a(t,n):(a=l.document.createEvent("Event"),n?(a.initEvent(t,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(t,!1,!1)),e.dispatchEvent(a)}function TE(e,t){return function(){return j1(this,e,t)}}function zE(e,t){return function(){return j1(this,e,t.apply(this,arguments))}}function DE(e,t){return this.each((typeof t=="function"?zE:TE)(e,t))}function*RE(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var l=e[t],a=0,s=l.length,i;a<s;++a)(i=l[a])&&(yield i)}var k1=[null];function Ot(e,t){this._groups=e,this._parents=t}function ar(){return new Ot([[document.documentElement]],k1)}function OE(){return this}Ot.prototype=ar.prototype={constructor:Ot,select:r3,selectAll:d3,selectChild:g3,selectChildren:v3,filter:b3,data:E3,enter:w3,exit:M3,join:_3,merge:A3,selection:OE,order:T3,sort:z3,call:R3,nodes:O3,node:H3,size:L3,empty:$3,each:B3,attr:Q3,style:W3,property:eE,classed:aE,text:oE,html:fE,raise:pE,lower:mE,append:xE,insert:vE,remove:wE,clone:jE,datum:kE,on:AE,dispatch:DE,[Symbol.iterator]:RE};function Ct(e){return typeof e=="string"?new Ot([[document.querySelector(e)]],[document.documentElement]):new Ot([[e]],k1)}function HE(e){let t;for(;t=e.sourceEvent;)e=t;return e}function tn(e,t){if(e=HE(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var l=n.createSVGPoint();return l.x=e.clientX,l.y=e.clientY,l=l.matrixTransform(t.getScreenCTM().inverse()),[l.x,l.y]}if(t.getBoundingClientRect){var a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}}return[e.pageX,e.pageY]}const LE={passive:!1},zi={capture:!0,passive:!1};function Iu(e){e.stopImmediatePropagation()}function Ja(e){e.preventDefault(),e.stopImmediatePropagation()}function E1(e){var t=e.document.documentElement,n=Ct(e).on("dragstart.drag",Ja,zi);"onselectstart"in t?n.on("selectstart.drag",Ja,zi):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function C1(e,t){var n=e.document.documentElement,l=Ct(e).on("dragstart.drag",null);t&&(l.on("click.drag",Ja,zi),setTimeout(function(){l.on("click.drag",null)},0)),"onselectstart"in n?l.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Hr=e=>()=>e;function uf(e,{sourceEvent:t,subject:n,target:l,identifier:a,active:s,x:i,y:r,dx:c,dy:u,dispatch:d}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:l,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:s,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:r,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:d}})}uf.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function $E(e){return!e.ctrlKey&&!e.button}function BE(){return this.parentNode}function UE(e,t){return t??{x:e.x,y:e.y}}function qE(){return navigator.maxTouchPoints||"ontouchstart"in this}function M1(){var e=$E,t=BE,n=UE,l=qE,a={},s=Bc("start","drag","end"),i=0,r,c,u,d,f=0;function h(v){v.on("mousedown.drag",p).filter(l).on("touchstart.drag",w).on("touchmove.drag",g,LE).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(v,j){if(!(d||!e.call(this,v,j))){var E=m(this,t.call(this,v,j),v,j,"mouse");E&&(Ct(v.view).on("mousemove.drag",x,zi).on("mouseup.drag",S,zi),E1(v.view),Iu(v),u=!1,r=v.clientX,c=v.clientY,E("start",v))}}function x(v){if(Ja(v),!u){var j=v.clientX-r,E=v.clientY-c;u=j*j+E*E>f}a.mouse("drag",v)}function S(v){Ct(v.view).on("mousemove.drag mouseup.drag",null),C1(v.view,u),Ja(v),a.mouse("end",v)}function w(v,j){if(e.call(this,v,j)){var E=v.changedTouches,M=t.call(this,v,j),A=E.length,C,H;for(C=0;C<A;++C)(H=m(this,M,v,j,E[C].identifier,E[C]))&&(Iu(v),H("start",v,E[C]))}}function g(v){var j=v.changedTouches,E=j.length,M,A;for(M=0;M<E;++M)(A=a[j[M].identifier])&&(Ja(v),A("drag",v,j[M]))}function y(v){var j=v.changedTouches,E=j.length,M,A;for(d&&clearTimeout(d),d=setTimeout(function(){d=null},500),M=0;M<E;++M)(A=a[j[M].identifier])&&(Iu(v),A("end",v,j[M]))}function m(v,j,E,M,A,C){var H=s.copy(),T=tn(C||E,j),$,V,N;if((N=n.call(v,new uf("beforestart",{sourceEvent:E,target:h,identifier:A,active:i,x:T[0],y:T[1],dx:0,dy:0,dispatch:H}),M))!=null)return $=N.x-T[0]||0,V=N.y-T[1]||0,function D(k,R,z){var O=T,Y;switch(k){case"start":a[A]=D,Y=i++;break;case"end":delete a[A],--i;case"drag":T=tn(z||R,j),Y=i;break}H.call(k,v,new uf(k,{sourceEvent:R,subject:N,target:h,identifier:A,active:Y,x:T[0]+$,y:T[1]+V,dx:T[0]-O[0],dy:T[1]-O[1],dispatch:H}),M)}}return h.filter=function(v){return arguments.length?(e=typeof v=="function"?v:Hr(!!v),h):e},h.container=function(v){return arguments.length?(t=typeof v=="function"?v:Hr(v),h):t},h.subject=function(v){return arguments.length?(n=typeof v=="function"?v:Hr(v),h):n},h.touchable=function(v){return arguments.length?(l=typeof v=="function"?v:Hr(!!v),h):l},h.on=function(){var v=s.on.apply(s,arguments);return v===s?h:v},h.clickDistance=function(v){return arguments.length?(f=(v=+v)*v,h):Math.sqrt(f)},h}function Ih(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function _1(e,t){var n=Object.create(e.prototype);for(var l in t)n[l]=t[l];return n}function sr(){}var Di=.7,lc=1/Di,Fa="\\s*([+-]?\\d+)\\s*",Ri="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Nn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",YE=/^#([0-9a-f]{3,8})$/,VE=new RegExp(`^rgb\\(${Fa},${Fa},${Fa}\\)$`),XE=new RegExp(`^rgb\\(${Nn},${Nn},${Nn}\\)$`),GE=new RegExp(`^rgba\\(${Fa},${Fa},${Fa},${Ri}\\)$`),QE=new RegExp(`^rgba\\(${Nn},${Nn},${Nn},${Ri}\\)$`),ZE=new RegExp(`^hsl\\(${Ri},${Nn},${Nn}\\)$`),IE=new RegExp(`^hsla\\(${Ri},${Nn},${Nn},${Ri}\\)$`),Nm={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Ih(sr,da,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:jm,formatHex:jm,formatHex8:KE,formatHsl:WE,formatRgb:km,toString:km});function jm(){return this.rgb().formatHex()}function KE(){return this.rgb().formatHex8()}function WE(){return A1(this).formatHsl()}function km(){return this.rgb().formatRgb()}function da(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=YE.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Em(t):n===3?new vt(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Lr(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Lr(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=VE.exec(e))?new vt(t[1],t[2],t[3],1):(t=XE.exec(e))?new vt(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=GE.exec(e))?Lr(t[1],t[2],t[3],t[4]):(t=QE.exec(e))?Lr(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=ZE.exec(e))?_m(t[1],t[2]/100,t[3]/100,1):(t=IE.exec(e))?_m(t[1],t[2]/100,t[3]/100,t[4]):Nm.hasOwnProperty(e)?Em(Nm[e]):e==="transparent"?new vt(NaN,NaN,NaN,0):null}function Em(e){return new vt(e>>16&255,e>>8&255,e&255,1)}function Lr(e,t,n,l){return l<=0&&(e=t=n=NaN),new vt(e,t,n,l)}function JE(e){return e instanceof sr||(e=da(e)),e?(e=e.rgb(),new vt(e.r,e.g,e.b,e.opacity)):new vt}function df(e,t,n,l){return arguments.length===1?JE(e):new vt(e,t,n,l??1)}function vt(e,t,n,l){this.r=+e,this.g=+t,this.b=+n,this.opacity=+l}Ih(vt,df,_1(sr,{brighter(e){return e=e==null?lc:Math.pow(lc,e),new vt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Di:Math.pow(Di,e),new vt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new vt(la(this.r),la(this.g),la(this.b),ac(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Cm,formatHex:Cm,formatHex8:FE,formatRgb:Mm,toString:Mm}));function Cm(){return`#${Jl(this.r)}${Jl(this.g)}${Jl(this.b)}`}function FE(){return`#${Jl(this.r)}${Jl(this.g)}${Jl(this.b)}${Jl((isNaN(this.opacity)?1:this.opacity)*255)}`}function Mm(){const e=ac(this.opacity);return`${e===1?"rgb(":"rgba("}${la(this.r)}, ${la(this.g)}, ${la(this.b)}${e===1?")":`, ${e})`}`}function ac(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function la(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Jl(e){return e=la(e),(e<16?"0":"")+e.toString(16)}function _m(e,t,n,l){return l<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new an(e,t,n,l)}function A1(e){if(e instanceof an)return new an(e.h,e.s,e.l,e.opacity);if(e instanceof sr||(e=da(e)),!e)return new an;if(e instanceof an)return e;e=e.rgb();var t=e.r/255,n=e.g/255,l=e.b/255,a=Math.min(t,n,l),s=Math.max(t,n,l),i=NaN,r=s-a,c=(s+a)/2;return r?(t===s?i=(n-l)/r+(n<l)*6:n===s?i=(l-t)/r+2:i=(t-n)/r+4,r/=c<.5?s+a:2-s-a,i*=60):r=c>0&&c<1?0:i,new an(i,r,c,e.opacity)}function PE(e,t,n,l){return arguments.length===1?A1(e):new an(e,t,n,l??1)}function an(e,t,n,l){this.h=+e,this.s=+t,this.l=+n,this.opacity=+l}Ih(an,PE,_1(sr,{brighter(e){return e=e==null?lc:Math.pow(lc,e),new an(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Di:Math.pow(Di,e),new an(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,l=n+(n<.5?n:1-n)*t,a=2*n-l;return new vt(Ku(e>=240?e-240:e+120,a,l),Ku(e,a,l),Ku(e<120?e+240:e-120,a,l),this.opacity)},clamp(){return new an(Am(this.h),$r(this.s),$r(this.l),ac(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=ac(this.opacity);return`${e===1?"hsl(":"hsla("}${Am(this.h)}, ${$r(this.s)*100}%, ${$r(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Am(e){return e=(e||0)%360,e<0?e+360:e}function $r(e){return Math.max(0,Math.min(1,e||0))}function Ku(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Kh=e=>()=>e;function eC(e,t){return function(n){return e+n*t}}function tC(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(l){return Math.pow(e+l*t,n)}}function nC(e){return(e=+e)==1?T1:function(t,n){return n-t?tC(t,n,e):Kh(isNaN(t)?n:t)}}function T1(e,t){var n=t-e;return n?eC(e,n):Kh(isNaN(e)?t:e)}const sc=function e(t){var n=nC(t);function l(a,s){var i=n((a=df(a)).r,(s=df(s)).r),r=n(a.g,s.g),c=n(a.b,s.b),u=T1(a.opacity,s.opacity);return function(d){return a.r=i(d),a.g=r(d),a.b=c(d),a.opacity=u(d),a+""}}return l.gamma=e,l}(1);function lC(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,l=t.slice(),a;return function(s){for(a=0;a<n;++a)l[a]=e[a]*(1-s)+t[a]*s;return l}}function aC(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function sC(e,t){var n=t?t.length:0,l=e?Math.min(n,e.length):0,a=new Array(l),s=new Array(n),i;for(i=0;i<l;++i)a[i]=pi(e[i],t[i]);for(;i<n;++i)s[i]=t[i];return function(r){for(i=0;i<l;++i)s[i]=a[i](r);return s}}function iC(e,t){var n=new Date;return e=+e,t=+t,function(l){return n.setTime(e*(1-l)+t*l),n}}function yn(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function rC(e,t){var n={},l={},a;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(a in t)a in e?n[a]=pi(e[a],t[a]):l[a]=t[a];return function(s){for(a in n)l[a]=n[a](s);return l}}var ff=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Wu=new RegExp(ff.source,"g");function oC(e){return function(){return e}}function cC(e){return function(t){return e(t)+""}}function z1(e,t){var n=ff.lastIndex=Wu.lastIndex=0,l,a,s,i=-1,r=[],c=[];for(e=e+"",t=t+"";(l=ff.exec(e))&&(a=Wu.exec(t));)(s=a.index)>n&&(s=t.slice(n,s),r[i]?r[i]+=s:r[++i]=s),(l=l[0])===(a=a[0])?r[i]?r[i]+=a:r[++i]=a:(r[++i]=null,c.push({i,x:yn(l,a)})),n=Wu.lastIndex;return n<t.length&&(s=t.slice(n),r[i]?r[i]+=s:r[++i]=s),r.length<2?c[0]?cC(c[0].x):oC(t):(t=c.length,function(u){for(var d=0,f;d<t;++d)r[(f=c[d]).i]=f.x(u);return r.join("")})}function pi(e,t){var n=typeof t,l;return t==null||n==="boolean"?Kh(t):(n==="number"?yn:n==="string"?(l=da(t))?(t=l,sc):z1:t instanceof da?sc:t instanceof Date?iC:aC(t)?lC:Array.isArray(t)?sC:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?rC:yn)(e,t)}var Tm=180/Math.PI,hf={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function D1(e,t,n,l,a,s){var i,r,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(c=e*n+t*l)&&(n-=e*c,l-=t*c),(r=Math.sqrt(n*n+l*l))&&(n/=r,l/=r,c/=r),e*l<t*n&&(e=-e,t=-t,c=-c,i=-i),{translateX:a,translateY:s,rotate:Math.atan2(t,e)*Tm,skewX:Math.atan(c)*Tm,scaleX:i,scaleY:r}}var Br;function uC(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?hf:D1(t.a,t.b,t.c,t.d,t.e,t.f)}function dC(e){return e==null||(Br||(Br=document.createElementNS("http://www.w3.org/2000/svg","g")),Br.setAttribute("transform",e),!(e=Br.transform.baseVal.consolidate()))?hf:(e=e.matrix,D1(e.a,e.b,e.c,e.d,e.e,e.f))}function R1(e,t,n,l){function a(u){return u.length?u.pop()+" ":""}function s(u,d,f,h,p,x){if(u!==f||d!==h){var S=p.push("translate(",null,t,null,n);x.push({i:S-4,x:yn(u,f)},{i:S-2,x:yn(d,h)})}else(f||h)&&p.push("translate("+f+t+h+n)}function i(u,d,f,h){u!==d?(u-d>180?d+=360:d-u>180&&(u+=360),h.push({i:f.push(a(f)+"rotate(",null,l)-2,x:yn(u,d)})):d&&f.push(a(f)+"rotate("+d+l)}function r(u,d,f,h){u!==d?h.push({i:f.push(a(f)+"skewX(",null,l)-2,x:yn(u,d)}):d&&f.push(a(f)+"skewX("+d+l)}function c(u,d,f,h,p,x){if(u!==f||d!==h){var S=p.push(a(p)+"scale(",null,",",null,")");x.push({i:S-4,x:yn(u,f)},{i:S-2,x:yn(d,h)})}else(f!==1||h!==1)&&p.push(a(p)+"scale("+f+","+h+")")}return function(u,d){var f=[],h=[];return u=e(u),d=e(d),s(u.translateX,u.translateY,d.translateX,d.translateY,f,h),i(u.rotate,d.rotate,f,h),r(u.skewX,d.skewX,f,h),c(u.scaleX,u.scaleY,d.scaleX,d.scaleY,f,h),u=d=null,function(p){for(var x=-1,S=h.length,w;++x<S;)f[(w=h[x]).i]=w.x(p);return f.join("")}}}var fC=R1(uC,"px, ","px)","deg)"),hC=R1(dC,", ",")",")"),pC=1e-12;function zm(e){return((e=Math.exp(e))+1/e)/2}function gC(e){return((e=Math.exp(e))-1/e)/2}function mC(e){return((e=Math.exp(2*e))-1)/(e+1)}const fo=function e(t,n,l){function a(s,i){var r=s[0],c=s[1],u=s[2],d=i[0],f=i[1],h=i[2],p=d-r,x=f-c,S=p*p+x*x,w,g;if(S<pC)g=Math.log(h/u)/t,w=function(M){return[r+M*p,c+M*x,u*Math.exp(t*M*g)]};else{var y=Math.sqrt(S),m=(h*h-u*u+l*S)/(2*u*n*y),v=(h*h-u*u-l*S)/(2*h*n*y),j=Math.log(Math.sqrt(m*m+1)-m),E=Math.log(Math.sqrt(v*v+1)-v);g=(E-j)/t,w=function(M){var A=M*g,C=zm(j),H=u/(n*y)*(C*mC(t*A+j)-gC(j));return[r+H*p,c+H*x,u*C/zm(t*A+j)]}}return w.duration=g*1e3*t/Math.SQRT2,w}return a.rho=function(s){var i=Math.max(.001,+s),r=i*i,c=r*r;return e(i,r,c)},a}(Math.SQRT2,2,4);var ds=0,Ks=0,qs=0,O1=1e3,ic,Ws,rc=0,fa=0,qc=0,Oi=typeof performance=="object"&&performance.now?performance:Date,H1=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Wh(){return fa||(H1(xC),fa=Oi.now()+qc)}function xC(){fa=0}function oc(){this._call=this._time=this._next=null}oc.prototype=L1.prototype={constructor:oc,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Wh():+n)+(t==null?0:+t),!this._next&&Ws!==this&&(Ws?Ws._next=this:ic=this,Ws=this),this._call=e,this._time=n,pf()},stop:function(){this._call&&(this._call=null,this._time=1/0,pf())}};function L1(e,t,n){var l=new oc;return l.restart(e,t,n),l}function yC(){Wh(),++ds;for(var e=ic,t;e;)(t=fa-e._time)>=0&&e._call.call(void 0,t),e=e._next;--ds}function Dm(){fa=(rc=Oi.now())+qc,ds=Ks=0;try{yC()}finally{ds=0,bC(),fa=0}}function vC(){var e=Oi.now(),t=e-rc;t>O1&&(qc-=t,rc=e)}function bC(){for(var e,t=ic,n,l=1/0;t;)t._call?(l>t._time&&(l=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:ic=n);Ws=e,pf(l)}function pf(e){if(!ds){Ks&&(Ks=clearTimeout(Ks));var t=e-fa;t>24?(e<1/0&&(Ks=setTimeout(Dm,e-Oi.now()-qc)),qs&&(qs=clearInterval(qs))):(qs||(rc=Oi.now(),qs=setInterval(vC,O1)),ds=1,H1(Dm))}}function Rm(e,t,n){var l=new oc;return t=t==null?0:+t,l.restart(a=>{l.stop(),e(a+t)},t,n),l}var wC=Bc("start","end","cancel","interrupt"),SC=[],$1=0,Om=1,gf=2,ho=3,Hm=4,mf=5,po=6;function Yc(e,t,n,l,a,s){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;NC(e,n,{name:t,index:l,group:a,on:wC,tween:SC,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:$1})}function Jh(e,t){var n=dn(e,t);if(n.state>$1)throw new Error("too late; already scheduled");return n}function Mn(e,t){var n=dn(e,t);if(n.state>ho)throw new Error("too late; already running");return n}function dn(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function NC(e,t,n){var l=e.__transition,a;l[t]=n,n.timer=L1(s,0,n.time);function s(u){n.state=Om,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var d,f,h,p;if(n.state!==Om)return c();for(d in l)if(p=l[d],p.name===n.name){if(p.state===ho)return Rm(i);p.state===Hm?(p.state=po,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete l[d]):+d<t&&(p.state=po,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete l[d])}if(Rm(function(){n.state===ho&&(n.state=Hm,n.timer.restart(r,n.delay,n.time),r(u))}),n.state=gf,n.on.call("start",e,e.__data__,n.index,n.group),n.state===gf){for(n.state=ho,a=new Array(h=n.tween.length),d=0,f=-1;d<h;++d)(p=n.tween[d].value.call(e,e.__data__,n.index,n.group))&&(a[++f]=p);a.length=f+1}}function r(u){for(var d=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=mf,1),f=-1,h=a.length;++f<h;)a[f].call(e,d);n.state===mf&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=po,n.timer.stop(),delete l[t];for(var u in l)return;delete e.__transition}}function go(e,t){var n=e.__transition,l,a,s=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((l=n[i]).name!==t){s=!1;continue}a=l.state>gf&&l.state<mf,l.state=po,l.timer.stop(),l.on.call(a?"interrupt":"cancel",e,e.__data__,l.index,l.group),delete n[i]}s&&delete e.__transition}}function jC(e){return this.each(function(){go(this,e)})}function kC(e,t){var n,l;return function(){var a=Mn(this,e),s=a.tween;if(s!==n){l=n=s;for(var i=0,r=l.length;i<r;++i)if(l[i].name===t){l=l.slice(),l.splice(i,1);break}}a.tween=l}}function EC(e,t,n){var l,a;if(typeof n!="function")throw new Error;return function(){var s=Mn(this,e),i=s.tween;if(i!==l){a=(l=i).slice();for(var r={name:t,value:n},c=0,u=a.length;c<u;++c)if(a[c].name===t){a[c]=r;break}c===u&&a.push(r)}s.tween=a}}function CC(e,t){var n=this._id;if(e+="",arguments.length<2){for(var l=dn(this.node(),n).tween,a=0,s=l.length,i;a<s;++a)if((i=l[a]).name===e)return i.value;return null}return this.each((t==null?kC:EC)(n,e,t))}function Fh(e,t,n){var l=e._id;return e.each(function(){var a=Mn(this,l);(a.value||(a.value={}))[t]=n.apply(this,arguments)}),function(a){return dn(a,l).value[t]}}function B1(e,t){var n;return(typeof t=="number"?yn:t instanceof da?sc:(n=da(t))?(t=n,sc):z1)(e,t)}function MC(e){return function(){this.removeAttribute(e)}}function _C(e){return function(){this.removeAttributeNS(e.space,e.local)}}function AC(e,t,n){var l,a=n+"",s;return function(){var i=this.getAttribute(e);return i===a?null:i===l?s:s=t(l=i,n)}}function TC(e,t,n){var l,a=n+"",s;return function(){var i=this.getAttributeNS(e.space,e.local);return i===a?null:i===l?s:s=t(l=i,n)}}function zC(e,t,n){var l,a,s;return function(){var i,r=n(this),c;return r==null?void this.removeAttribute(e):(i=this.getAttribute(e),c=r+"",i===c?null:i===l&&c===a?s:(a=c,s=t(l=i,r)))}}function DC(e,t,n){var l,a,s;return function(){var i,r=n(this),c;return r==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),c=r+"",i===c?null:i===l&&c===a?s:(a=c,s=t(l=i,r)))}}function RC(e,t){var n=Uc(e),l=n==="transform"?hC:B1;return this.attrTween(e,typeof t=="function"?(n.local?DC:zC)(n,l,Fh(this,"attr."+e,t)):t==null?(n.local?_C:MC)(n):(n.local?TC:AC)(n,l,t))}function OC(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function HC(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function LC(e,t){var n,l;function a(){var s=t.apply(this,arguments);return s!==l&&(n=(l=s)&&HC(e,s)),n}return a._value=t,a}function $C(e,t){var n,l;function a(){var s=t.apply(this,arguments);return s!==l&&(n=(l=s)&&OC(e,s)),n}return a._value=t,a}function BC(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var l=Uc(e);return this.tween(n,(l.local?LC:$C)(l,t))}function UC(e,t){return function(){Jh(this,e).delay=+t.apply(this,arguments)}}function qC(e,t){return t=+t,function(){Jh(this,e).delay=t}}function YC(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?UC:qC)(t,e)):dn(this.node(),t).delay}function VC(e,t){return function(){Mn(this,e).duration=+t.apply(this,arguments)}}function XC(e,t){return t=+t,function(){Mn(this,e).duration=t}}function GC(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?VC:XC)(t,e)):dn(this.node(),t).duration}function QC(e,t){if(typeof t!="function")throw new Error;return function(){Mn(this,e).ease=t}}function ZC(e){var t=this._id;return arguments.length?this.each(QC(t,e)):dn(this.node(),t).ease}function IC(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Mn(this,e).ease=n}}function KC(e){if(typeof e!="function")throw new Error;return this.each(IC(this._id,e))}function WC(e){typeof e!="function"&&(e=m1(e));for(var t=this._groups,n=t.length,l=new Array(n),a=0;a<n;++a)for(var s=t[a],i=s.length,r=l[a]=[],c,u=0;u<i;++u)(c=s[u])&&e.call(c,c.__data__,u,s)&&r.push(c);return new el(l,this._parents,this._name,this._id)}function JC(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,l=t.length,a=n.length,s=Math.min(l,a),i=new Array(l),r=0;r<s;++r)for(var c=t[r],u=n[r],d=c.length,f=i[r]=new Array(d),h,p=0;p<d;++p)(h=c[p]||u[p])&&(f[p]=h);for(;r<l;++r)i[r]=t[r];return new el(i,this._parents,this._name,this._id)}function FC(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function PC(e,t,n){var l,a,s=FC(t)?Jh:Mn;return function(){var i=s(this,e),r=i.on;r!==l&&(a=(l=r).copy()).on(t,n),i.on=a}}function e4(e,t){var n=this._id;return arguments.length<2?dn(this.node(),n).on.on(e):this.each(PC(n,e,t))}function t4(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function n4(){return this.on("end.remove",t4(this._id))}function l4(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Qh(e));for(var l=this._groups,a=l.length,s=new Array(a),i=0;i<a;++i)for(var r=l[i],c=r.length,u=s[i]=new Array(c),d,f,h=0;h<c;++h)(d=r[h])&&(f=e.call(d,d.__data__,h,r))&&("__data__"in d&&(f.__data__=d.__data__),u[h]=f,Yc(u[h],t,n,h,u,dn(d,n)));return new el(s,this._parents,t,n)}function a4(e){var t=this._name,n=this._id;typeof e!="function"&&(e=g1(e));for(var l=this._groups,a=l.length,s=[],i=[],r=0;r<a;++r)for(var c=l[r],u=c.length,d,f=0;f<u;++f)if(d=c[f]){for(var h=e.call(d,d.__data__,f,c),p,x=dn(d,n),S=0,w=h.length;S<w;++S)(p=h[S])&&Yc(p,t,n,S,h,x);s.push(h),i.push(d)}return new el(s,i,t,n)}var s4=ar.prototype.constructor;function i4(){return new s4(this._groups,this._parents)}function r4(e,t){var n,l,a;return function(){var s=us(this,e),i=(this.style.removeProperty(e),us(this,e));return s===i?null:s===n&&i===l?a:a=t(n=s,l=i)}}function U1(e){return function(){this.style.removeProperty(e)}}function o4(e,t,n){var l,a=n+"",s;return function(){var i=us(this,e);return i===a?null:i===l?s:s=t(l=i,n)}}function c4(e,t,n){var l,a,s;return function(){var i=us(this,e),r=n(this),c=r+"";return r==null&&(c=r=(this.style.removeProperty(e),us(this,e))),i===c?null:i===l&&c===a?s:(a=c,s=t(l=i,r))}}function u4(e,t){var n,l,a,s="style."+t,i="end."+s,r;return function(){var c=Mn(this,e),u=c.on,d=c.value[s]==null?r||(r=U1(t)):void 0;(u!==n||a!==d)&&(l=(n=u).copy()).on(i,a=d),c.on=l}}function d4(e,t,n){var l=(e+="")=="transform"?fC:B1;return t==null?this.styleTween(e,r4(e,l)).on("end.style."+e,U1(e)):typeof t=="function"?this.styleTween(e,c4(e,l,Fh(this,"style."+e,t))).each(u4(this._id,e)):this.styleTween(e,o4(e,l,t),n).on("end.style."+e,null)}function f4(e,t,n){return function(l){this.style.setProperty(e,t.call(this,l),n)}}function h4(e,t,n){var l,a;function s(){var i=t.apply(this,arguments);return i!==a&&(l=(a=i)&&f4(e,i,n)),l}return s._value=t,s}function p4(e,t,n){var l="style."+(e+="");if(arguments.length<2)return(l=this.tween(l))&&l._value;if(t==null)return this.tween(l,null);if(typeof t!="function")throw new Error;return this.tween(l,h4(e,t,n??""))}function g4(e){return function(){this.textContent=e}}function m4(e){return function(){var t=e(this);this.textContent=t??""}}function x4(e){return this.tween("text",typeof e=="function"?m4(Fh(this,"text",e)):g4(e==null?"":e+""))}function y4(e){return function(t){this.textContent=e.call(this,t)}}function v4(e){var t,n;function l(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&y4(a)),t}return l._value=e,l}function b4(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,v4(e))}function w4(){for(var e=this._name,t=this._id,n=q1(),l=this._groups,a=l.length,s=0;s<a;++s)for(var i=l[s],r=i.length,c,u=0;u<r;++u)if(c=i[u]){var d=dn(c,t);Yc(c,e,n,u,i,{time:d.time+d.delay+d.duration,delay:0,duration:d.duration,ease:d.ease})}return new el(l,this._parents,e,n)}function S4(){var e,t,n=this,l=n._id,a=n.size();return new Promise(function(s,i){var r={value:i},c={value:function(){--a===0&&s()}};n.each(function(){var u=Mn(this,l),d=u.on;d!==e&&(t=(e=d).copy(),t._.cancel.push(r),t._.interrupt.push(r),t._.end.push(c)),u.on=t}),a===0&&s()})}var N4=0;function el(e,t,n,l){this._groups=e,this._parents=t,this._name=n,this._id=l}function q1(){return++N4}var Hn=ar.prototype;el.prototype={constructor:el,select:l4,selectAll:a4,selectChild:Hn.selectChild,selectChildren:Hn.selectChildren,filter:WC,merge:JC,selection:i4,transition:w4,call:Hn.call,nodes:Hn.nodes,node:Hn.node,size:Hn.size,empty:Hn.empty,each:Hn.each,on:e4,attr:RC,attrTween:BC,style:d4,styleTween:p4,text:x4,textTween:b4,remove:n4,tween:CC,delay:YC,duration:GC,ease:ZC,easeVarying:KC,end:S4,[Symbol.iterator]:Hn[Symbol.iterator]};function j4(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var k4={time:null,delay:0,duration:250,ease:j4};function E4(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function C4(e){var t,n;e instanceof el?(t=e._id,e=e._name):(t=q1(),(n=k4).time=Wh(),e=e==null?null:e+"");for(var l=this._groups,a=l.length,s=0;s<a;++s)for(var i=l[s],r=i.length,c,u=0;u<r;++u)(c=i[u])&&Yc(c,e,t,u,i,n||E4(c,t));return new el(l,this._parents,e,t)}ar.prototype.interrupt=jC;ar.prototype.transition=C4;const Ur=e=>()=>e;function M4(e,{sourceEvent:t,target:n,transform:l,dispatch:a}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:l,enumerable:!0,configurable:!0},_:{value:a}})}function Vn(e,t,n){this.k=e,this.x=t,this.y=n}Vn.prototype={constructor:Vn,scale:function(e){return e===1?this:new Vn(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Vn(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Vc=new Vn(1,0,0);Y1.prototype=Vn.prototype;function Y1(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Vc;return e.__zoom}function Ju(e){e.stopImmediatePropagation()}function Ys(e){e.preventDefault(),e.stopImmediatePropagation()}function _4(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function A4(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Lm(){return this.__zoom||Vc}function T4(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function z4(){return navigator.maxTouchPoints||"ontouchstart"in this}function D4(e,t,n){var l=e.invertX(t[0][0])-n[0][0],a=e.invertX(t[1][0])-n[1][0],s=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(a>l?(l+a)/2:Math.min(0,l)||Math.max(0,a),i>s?(s+i)/2:Math.min(0,s)||Math.max(0,i))}function V1(){var e=_4,t=A4,n=D4,l=T4,a=z4,s=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],r=250,c=fo,u=Bc("start","zoom","end"),d,f,h,p=500,x=150,S=0,w=10;function g(N){N.property("__zoom",Lm).on("wheel.zoom",A,{passive:!1}).on("mousedown.zoom",C).on("dblclick.zoom",H).filter(a).on("touchstart.zoom",T).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(N,D,k,R){var z=N.selection?N.selection():N;z.property("__zoom",Lm),N!==z?j(N,D,k,R):z.interrupt().each(function(){E(this,arguments).event(R).start().zoom(null,typeof D=="function"?D.apply(this,arguments):D).end()})},g.scaleBy=function(N,D,k,R){g.scaleTo(N,function(){var z=this.__zoom.k,O=typeof D=="function"?D.apply(this,arguments):D;return z*O},k,R)},g.scaleTo=function(N,D,k,R){g.transform(N,function(){var z=t.apply(this,arguments),O=this.__zoom,Y=k==null?v(z):typeof k=="function"?k.apply(this,arguments):k,X=O.invert(Y),L=typeof D=="function"?D.apply(this,arguments):D;return n(m(y(O,L),Y,X),z,i)},k,R)},g.translateBy=function(N,D,k,R){g.transform(N,function(){return n(this.__zoom.translate(typeof D=="function"?D.apply(this,arguments):D,typeof k=="function"?k.apply(this,arguments):k),t.apply(this,arguments),i)},null,R)},g.translateTo=function(N,D,k,R,z){g.transform(N,function(){var O=t.apply(this,arguments),Y=this.__zoom,X=R==null?v(O):typeof R=="function"?R.apply(this,arguments):R;return n(Vc.translate(X[0],X[1]).scale(Y.k).translate(typeof D=="function"?-D.apply(this,arguments):-D,typeof k=="function"?-k.apply(this,arguments):-k),O,i)},R,z)};function y(N,D){return D=Math.max(s[0],Math.min(s[1],D)),D===N.k?N:new Vn(D,N.x,N.y)}function m(N,D,k){var R=D[0]-k[0]*N.k,z=D[1]-k[1]*N.k;return R===N.x&&z===N.y?N:new Vn(N.k,R,z)}function v(N){return[(+N[0][0]+ +N[1][0])/2,(+N[0][1]+ +N[1][1])/2]}function j(N,D,k,R){N.on("start.zoom",function(){E(this,arguments).event(R).start()}).on("interrupt.zoom end.zoom",function(){E(this,arguments).event(R).end()}).tween("zoom",function(){var z=this,O=arguments,Y=E(z,O).event(R),X=t.apply(z,O),L=k==null?v(X):typeof k=="function"?k.apply(z,O):k,U=Math.max(X[1][0]-X[0][0],X[1][1]-X[0][1]),_=z.__zoom,B=typeof D=="function"?D.apply(z,O):D,G=c(_.invert(L).concat(U/_.k),B.invert(L).concat(U/B.k));return function(q){if(q===1)q=B;else{var Q=G(q),K=U/Q[2];q=new Vn(K,L[0]-Q[0]*K,L[1]-Q[1]*K)}Y.zoom(null,q)}})}function E(N,D,k){return!k&&N.__zooming||new M(N,D)}function M(N,D){this.that=N,this.args=D,this.active=0,this.sourceEvent=null,this.extent=t.apply(N,D),this.taps=0}M.prototype={event:function(N){return N&&(this.sourceEvent=N),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(N,D){return this.mouse&&N!=="mouse"&&(this.mouse[1]=D.invert(this.mouse[0])),this.touch0&&N!=="touch"&&(this.touch0[1]=D.invert(this.touch0[0])),this.touch1&&N!=="touch"&&(this.touch1[1]=D.invert(this.touch1[0])),this.that.__zoom=D,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(N){var D=Ct(this.that).datum();u.call(N,this.that,new M4(N,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),D)}};function A(N,...D){if(!e.apply(this,arguments))return;var k=E(this,D).event(N),R=this.__zoom,z=Math.max(s[0],Math.min(s[1],R.k*Math.pow(2,l.apply(this,arguments)))),O=tn(N);if(k.wheel)(k.mouse[0][0]!==O[0]||k.mouse[0][1]!==O[1])&&(k.mouse[1]=R.invert(k.mouse[0]=O)),clearTimeout(k.wheel);else{if(R.k===z)return;k.mouse=[O,R.invert(O)],go(this),k.start()}Ys(N),k.wheel=setTimeout(Y,x),k.zoom("mouse",n(m(y(R,z),k.mouse[0],k.mouse[1]),k.extent,i));function Y(){k.wheel=null,k.end()}}function C(N,...D){if(h||!e.apply(this,arguments))return;var k=N.currentTarget,R=E(this,D,!0).event(N),z=Ct(N.view).on("mousemove.zoom",L,!0).on("mouseup.zoom",U,!0),O=tn(N,k),Y=N.clientX,X=N.clientY;E1(N.view),Ju(N),R.mouse=[O,this.__zoom.invert(O)],go(this),R.start();function L(_){if(Ys(_),!R.moved){var B=_.clientX-Y,G=_.clientY-X;R.moved=B*B+G*G>S}R.event(_).zoom("mouse",n(m(R.that.__zoom,R.mouse[0]=tn(_,k),R.mouse[1]),R.extent,i))}function U(_){z.on("mousemove.zoom mouseup.zoom",null),C1(_.view,R.moved),Ys(_),R.event(_).end()}}function H(N,...D){if(e.apply(this,arguments)){var k=this.__zoom,R=tn(N.changedTouches?N.changedTouches[0]:N,this),z=k.invert(R),O=k.k*(N.shiftKey?.5:2),Y=n(m(y(k,O),R,z),t.apply(this,D),i);Ys(N),r>0?Ct(this).transition().duration(r).call(j,Y,R,N):Ct(this).call(g.transform,Y,R,N)}}function T(N,...D){if(e.apply(this,arguments)){var k=N.touches,R=k.length,z=E(this,D,N.changedTouches.length===R).event(N),O,Y,X,L;for(Ju(N),Y=0;Y<R;++Y)X=k[Y],L=tn(X,this),L=[L,this.__zoom.invert(L),X.identifier],z.touch0?!z.touch1&&z.touch0[2]!==L[2]&&(z.touch1=L,z.taps=0):(z.touch0=L,O=!0,z.taps=1+!!d);d&&(d=clearTimeout(d)),O&&(z.taps<2&&(f=L[0],d=setTimeout(function(){d=null},p)),go(this),z.start())}}function $(N,...D){if(this.__zooming){var k=E(this,D).event(N),R=N.changedTouches,z=R.length,O,Y,X,L;for(Ys(N),O=0;O<z;++O)Y=R[O],X=tn(Y,this),k.touch0&&k.touch0[2]===Y.identifier?k.touch0[0]=X:k.touch1&&k.touch1[2]===Y.identifier&&(k.touch1[0]=X);if(Y=k.that.__zoom,k.touch1){var U=k.touch0[0],_=k.touch0[1],B=k.touch1[0],G=k.touch1[1],q=(q=B[0]-U[0])*q+(q=B[1]-U[1])*q,Q=(Q=G[0]-_[0])*Q+(Q=G[1]-_[1])*Q;Y=y(Y,Math.sqrt(q/Q)),X=[(U[0]+B[0])/2,(U[1]+B[1])/2],L=[(_[0]+G[0])/2,(_[1]+G[1])/2]}else if(k.touch0)X=k.touch0[0],L=k.touch0[1];else return;k.zoom("touch",n(m(Y,X,L),k.extent,i))}}function V(N,...D){if(this.__zooming){var k=E(this,D).event(N),R=N.changedTouches,z=R.length,O,Y;for(Ju(N),h&&clearTimeout(h),h=setTimeout(function(){h=null},p),O=0;O<z;++O)Y=R[O],k.touch0&&k.touch0[2]===Y.identifier?delete k.touch0:k.touch1&&k.touch1[2]===Y.identifier&&delete k.touch1;if(k.touch1&&!k.touch0&&(k.touch0=k.touch1,delete k.touch1),k.touch0)k.touch0[1]=this.__zoom.invert(k.touch0[0]);else if(k.end(),k.taps===2&&(Y=tn(Y,this),Math.hypot(f[0]-Y[0],f[1]-Y[1])<w)){var X=Ct(this).on("dblclick.zoom");X&&X.apply(this,arguments)}}}return g.wheelDelta=function(N){return arguments.length?(l=typeof N=="function"?N:Ur(+N),g):l},g.filter=function(N){return arguments.length?(e=typeof N=="function"?N:Ur(!!N),g):e},g.touchable=function(N){return arguments.length?(a=typeof N=="function"?N:Ur(!!N),g):a},g.extent=function(N){return arguments.length?(t=typeof N=="function"?N:Ur([[+N[0][0],+N[0][1]],[+N[1][0],+N[1][1]]]),g):t},g.scaleExtent=function(N){return arguments.length?(s[0]=+N[0],s[1]=+N[1],g):[s[0],s[1]]},g.translateExtent=function(N){return arguments.length?(i[0][0]=+N[0][0],i[1][0]=+N[1][0],i[0][1]=+N[0][1],i[1][1]=+N[1][1],g):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},g.constrain=function(N){return arguments.length?(n=N,g):n},g.duration=function(N){return arguments.length?(r=+N,g):r},g.interpolate=function(N){return arguments.length?(c=N,g):c},g.on=function(){var N=u.on.apply(u,arguments);return N===u?g:N},g.clickDistance=function(N){return arguments.length?(S=(N=+N)*N,g):Math.sqrt(S)},g.tapDistance=function(N){return arguments.length?(w=+N,g):w},g}const jn={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:l})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:l}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},Hi=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],X1=["Enter"," ","Escape"],G1={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var fs;(function(e){e.Strict="strict",e.Loose="loose"})(fs||(fs={}));var aa;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(aa||(aa={}));var Li;(function(e){e.Partial="partial",e.Full="full"})(Li||(Li={}));const Q1={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var xl;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(xl||(xl={}));var cc;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(cc||(cc={}));var ee;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ee||(ee={}));const $m={[ee.Left]:ee.Right,[ee.Right]:ee.Left,[ee.Top]:ee.Bottom,[ee.Bottom]:ee.Top};function Z1(e){return e===null?null:e?"valid":"invalid"}const I1=e=>"id"in e&&"source"in e&&"target"in e,R4=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ph=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),ir=(e,t=[0,0])=>{const{width:n,height:l}=nl(e),a=e.origin??t,s=n*a[0],i=l*a[1];return{x:e.position.x-s,y:e.position.y-i}},O4=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((l,a)=>{const s=typeof a=="string";let i=!t.nodeLookup&&!s?a:void 0;t.nodeLookup&&(i=s?t.nodeLookup.get(a):Ph(a)?a:t.nodeLookup.get(a.id));const r=i?uc(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Xc(l,r)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Gc(n)},rr=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},l=!1;return e.forEach(a=>{(t.filter===void 0||t.filter(a))&&(n=Xc(n,uc(a)),l=!0)}),l?Gc(n):{x:0,y:0,width:0,height:0}},ep=(e,t,[n,l,a]=[0,0,1],s=!1,i=!1)=>{const r={...cr(t,[n,l,a]),width:t.width/a,height:t.height/a},c=[];for(const u of e.values()){const{measured:d,selectable:f=!0,hidden:h=!1}=u;if(i&&!f||h)continue;const p=d.width??u.width??u.initialWidth??null,x=d.height??u.height??u.initialHeight??null,S=$i(r,ps(u)),w=(p??0)*(x??0),g=s&&S>0;(!u.internals.handleBounds||g||S>=w||u.dragging)&&c.push(u)}return c},H4=(e,t)=>{const n=new Set;return e.forEach(l=>{n.add(l.id)}),t.filter(l=>n.has(l.source)||n.has(l.target))};function L4(e,t){const n=new Map,l=t!=null&&t.nodes?new Set(t.nodes.map(a=>a.id)):null;return e.forEach(a=>{a.measured.width&&a.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!a.hidden)&&(!l||l.has(a.id))&&n.set(a.id,a)}),n}async function $4({nodes:e,width:t,height:n,panZoom:l,minZoom:a,maxZoom:s},i){if(e.size===0)return Promise.resolve(!0);const r=L4(e,i),c=rr(r),u=tp(c,t,n,(i==null?void 0:i.minZoom)??a,(i==null?void 0:i.maxZoom)??s,(i==null?void 0:i.padding)??.1);return await l.setViewport(u,{duration:i==null?void 0:i.duration,ease:i==null?void 0:i.ease,interpolate:i==null?void 0:i.interpolate}),Promise.resolve(!0)}function K1({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:l=[0,0],nodeExtent:a,onError:s}){const i=n.get(e),r=i.parentId?n.get(i.parentId):void 0,{x:c,y:u}=r?r.internals.positionAbsolute:{x:0,y:0},d=i.origin??l;let f=i.extent||a;if(i.extent==="parent"&&!i.expandParent)if(!r)s==null||s("005",jn.error005());else{const p=r.measured.width,x=r.measured.height;p&&x&&(f=[[c,u],[c+p,u+x]])}else r&&gs(i.extent)&&(f=[[i.extent[0][0]+c,i.extent[0][1]+u],[i.extent[1][0]+c,i.extent[1][1]+u]]);const h=gs(f)?ha(t,f,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&(s==null||s("015",jn.error015())),{position:{x:h.x-c+(i.measured.width??0)*d[0],y:h.y-u+(i.measured.height??0)*d[1]},positionAbsolute:h}}async function B4({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:l,onBeforeDelete:a}){const s=new Set(e.map(h=>h.id)),i=[];for(const h of n){if(h.deletable===!1)continue;const p=s.has(h.id),x=!p&&h.parentId&&i.find(S=>S.id===h.parentId);(p||x)&&i.push(h)}const r=new Set(t.map(h=>h.id)),c=l.filter(h=>h.deletable!==!1),d=H4(i,c);for(const h of c)r.has(h.id)&&!d.find(x=>x.id===h.id)&&d.push(h);if(!a)return{edges:d,nodes:i};const f=await a({nodes:i,edges:d});return typeof f=="boolean"?f?{edges:d,nodes:i}:{edges:[],nodes:[]}:f}const hs=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),ha=(e={x:0,y:0},t,n)=>({x:hs(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:hs(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function W1(e,t,n){const{width:l,height:a}=nl(n),{x:s,y:i}=n.internals.positionAbsolute;return ha(e,[[s,i],[s+l,i+a]],t)}const Bm=(e,t,n)=>e<t?hs(Math.abs(e-t),1,t)/t:e>n?-hs(Math.abs(e-n),1,t)/t:0,J1=(e,t,n=15,l=40)=>{const a=Bm(e.x,l,t.width-l)*n,s=Bm(e.y,l,t.height-l)*n;return[a,s]},Xc=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),xf=({x:e,y:t,width:n,height:l})=>({x:e,y:t,x2:e+n,y2:t+l}),Gc=({x:e,y:t,x2:n,y2:l})=>({x:e,y:t,width:n-e,height:l-t}),ps=(e,t=[0,0])=>{var a,s;const{x:n,y:l}=Ph(e)?e.internals.positionAbsolute:ir(e,t);return{x:n,y:l,width:((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0,height:((s=e.measured)==null?void 0:s.height)??e.height??e.initialHeight??0}},uc=(e,t=[0,0])=>{var a,s;const{x:n,y:l}=Ph(e)?e.internals.positionAbsolute:ir(e,t);return{x:n,y:l,x2:n+(((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0),y2:l+(((s=e.measured)==null?void 0:s.height)??e.height??e.initialHeight??0)}},F1=(e,t)=>Gc(Xc(xf(e),xf(t))),$i=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),l=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*l)},Um=e=>sn(e.width)&&sn(e.height)&&sn(e.x)&&sn(e.y),sn=e=>!isNaN(e)&&isFinite(e),U4=(e,t)=>{},or=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),cr=({x:e,y:t},[n,l,a],s=!1,i=[1,1])=>{const r={x:(e-n)/a,y:(t-l)/a};return s?or(r,i):r},dc=({x:e,y:t},[n,l,a])=>({x:e*a+n,y:t*a+l});function ja(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function q4(e,t,n){if(typeof e=="string"||typeof e=="number"){const l=ja(e,n),a=ja(e,t);return{top:l,right:a,bottom:l,left:a,x:a*2,y:l*2}}if(typeof e=="object"){const l=ja(e.top??e.y??0,n),a=ja(e.bottom??e.y??0,n),s=ja(e.left??e.x??0,t),i=ja(e.right??e.x??0,t);return{top:l,right:i,bottom:a,left:s,x:s+i,y:l+a}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function Y4(e,t,n,l,a,s){const{x:i,y:r}=dc(e,[t,n,l]),{x:c,y:u}=dc({x:e.x+e.width,y:e.y+e.height},[t,n,l]),d=a-c,f=s-u;return{left:Math.floor(i),top:Math.floor(r),right:Math.floor(d),bottom:Math.floor(f)}}const tp=(e,t,n,l,a,s)=>{const i=q4(s,t,n),r=(t-i.x)/e.width,c=(n-i.y)/e.height,u=Math.min(r,c),d=hs(u,l,a),f=e.x+e.width/2,h=e.y+e.height/2,p=t/2-f*d,x=n/2-h*d,S=Y4(e,p,x,d,t,n),w={left:Math.min(S.left-i.left,0),top:Math.min(S.top-i.top,0),right:Math.min(S.right-i.right,0),bottom:Math.min(S.bottom-i.bottom,0)};return{x:p-w.left+w.right,y:x-w.top+w.bottom,zoom:d}},Bi=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function gs(e){return e!=null&&e!=="parent"}function nl(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function P1(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function eb(e,t={width:0,height:0},n,l,a){const s={...e},i=l.get(n);if(i){const r=i.origin||a;s.x+=i.internals.positionAbsolute.x-(t.width??0)*r[0],s.y+=i.internals.positionAbsolute.y-(t.height??0)*r[1]}return s}function qm(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function V4(){let e,t;return{promise:new Promise((l,a)=>{e=l,t=a}),resolve:e,reject:t}}function X4(e){return{...G1,...e||{}}}function gi(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:l,containerBounds:a}){const{x:s,y:i}=rn(e),r=cr({x:s-((a==null?void 0:a.left)??0),y:i-((a==null?void 0:a.top)??0)},l),{x:c,y:u}=n?or(r,t):r;return{xSnapped:c,ySnapped:u,...r}}const np=e=>({width:e.offsetWidth,height:e.offsetHeight}),tb=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},G4=["INPUT","SELECT","TEXTAREA"];function nb(e){var l,a;const t=((a=(l=e.composedPath)==null?void 0:l.call(e))==null?void 0:a[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:G4.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const lb=e=>"clientX"in e,rn=(e,t)=>{var s,i;const n=lb(e),l=n?e.clientX:(s=e.touches)==null?void 0:s[0].clientX,a=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:l-((t==null?void 0:t.left)??0),y:a-((t==null?void 0:t.top)??0)}},Ym=(e,t,n,l,a)=>{const s=t.querySelectorAll(`.${e}`);return!s||!s.length?null:Array.from(s).map(i=>{const r=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:a,position:i.getAttribute("data-handlepos"),x:(r.left-n.left)/l,y:(r.top-n.top)/l,...np(i)}})};function ab({sourceX:e,sourceY:t,targetX:n,targetY:l,sourceControlX:a,sourceControlY:s,targetControlX:i,targetControlY:r}){const c=e*.125+a*.375+i*.375+n*.125,u=t*.125+s*.375+r*.375+l*.125,d=Math.abs(c-e),f=Math.abs(u-t);return[c,u,d,f]}function qr(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Vm({pos:e,x1:t,y1:n,x2:l,y2:a,c:s}){switch(e){case ee.Left:return[t-qr(t-l,s),n];case ee.Right:return[t+qr(l-t,s),n];case ee.Top:return[t,n-qr(n-a,s)];case ee.Bottom:return[t,n+qr(a-n,s)]}}function sb({sourceX:e,sourceY:t,sourcePosition:n=ee.Bottom,targetX:l,targetY:a,targetPosition:s=ee.Top,curvature:i=.25}){const[r,c]=Vm({pos:n,x1:e,y1:t,x2:l,y2:a,c:i}),[u,d]=Vm({pos:s,x1:l,y1:a,x2:e,y2:t,c:i}),[f,h,p,x]=ab({sourceX:e,sourceY:t,targetX:l,targetY:a,sourceControlX:r,sourceControlY:c,targetControlX:u,targetControlY:d});return[`M${e},${t} C${r},${c} ${u},${d} ${l},${a}`,f,h,p,x]}function ib({sourceX:e,sourceY:t,targetX:n,targetY:l}){const a=Math.abs(n-e)/2,s=n<e?n+a:n-a,i=Math.abs(l-t)/2,r=l<t?l+i:l-i;return[s,r,a,i]}function Q4({sourceNode:e,targetNode:t,selected:n=!1,zIndex:l=0,elevateOnSelect:a=!1,zIndexMode:s="basic"}){if(s==="manual")return l;const i=a&&n?l+1e3:l,r=Math.max(e.parentId||a&&e.selected?e.internals.z:0,t.parentId||a&&t.selected?t.internals.z:0);return i+r}function Z4({sourceNode:e,targetNode:t,width:n,height:l,transform:a}){const s=Xc(uc(e),uc(t));s.x===s.x2&&(s.x2+=1),s.y===s.y2&&(s.y2+=1);const i={x:-a[0]/a[2],y:-a[1]/a[2],width:n/a[2],height:l/a[2]};return $i(i,Gc(s))>0}const I4=({source:e,sourceHandle:t,target:n,targetHandle:l})=>`xy-edge__${e}${t||""}-${n}${l||""}`,K4=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),W4=(e,t,n={})=>{if(!e.source||!e.target)return t;const l=n.getEdgeId||I4;let a;return I1(e)?a={...e}:a={...e,id:l(e)},K4(a,t)?t:(a.sourceHandle===null&&delete a.sourceHandle,a.targetHandle===null&&delete a.targetHandle,t.concat(a))};function rb({sourceX:e,sourceY:t,targetX:n,targetY:l}){const[a,s,i,r]=ib({sourceX:e,sourceY:t,targetX:n,targetY:l});return[`M ${e},${t}L ${n},${l}`,a,s,i,r]}const Xm={[ee.Left]:{x:-1,y:0},[ee.Right]:{x:1,y:0},[ee.Top]:{x:0,y:-1},[ee.Bottom]:{x:0,y:1}},J4=({source:e,sourcePosition:t=ee.Bottom,target:n})=>t===ee.Left||t===ee.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},Gm=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function F4({source:e,sourcePosition:t=ee.Bottom,target:n,targetPosition:l=ee.Top,center:a,offset:s,stepPosition:i}){const r=Xm[t],c=Xm[l],u={x:e.x+r.x*s,y:e.y+r.y*s},d={x:n.x+c.x*s,y:n.y+c.y*s},f=J4({source:u,sourcePosition:t,target:d}),h=f.x!==0?"x":"y",p=f[h];let x=[],S,w;const g={x:0,y:0},y={x:0,y:0},[,,m,v]=ib({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(r[h]*c[h]===-1){h==="x"?(S=a.x??u.x+(d.x-u.x)*i,w=a.y??(u.y+d.y)/2):(S=a.x??(u.x+d.x)/2,w=a.y??u.y+(d.y-u.y)*i);const A=[{x:S,y:u.y},{x:S,y:d.y}],C=[{x:u.x,y:w},{x:d.x,y:w}];r[h]===p?x=h==="x"?A:C:x=h==="x"?C:A}else{const A=[{x:u.x,y:d.y}],C=[{x:d.x,y:u.y}];if(h==="x"?x=r.x===p?C:A:x=r.y===p?A:C,t===l){const N=Math.abs(e[h]-n[h]);if(N<=s){const D=Math.min(s-1,s-N);r[h]===p?g[h]=(u[h]>e[h]?-1:1)*D:y[h]=(d[h]>n[h]?-1:1)*D}}if(t!==l){const N=h==="x"?"y":"x",D=r[h]===c[N],k=u[N]>d[N],R=u[N]<d[N];(r[h]===1&&(!D&&k||D&&R)||r[h]!==1&&(!D&&R||D&&k))&&(x=h==="x"?A:C)}const H={x:u.x+g.x,y:u.y+g.y},T={x:d.x+y.x,y:d.y+y.y},$=Math.max(Math.abs(H.x-x[0].x),Math.abs(T.x-x[0].x)),V=Math.max(Math.abs(H.y-x[0].y),Math.abs(T.y-x[0].y));$>=V?(S=(H.x+T.x)/2,w=x[0].y):(S=x[0].x,w=(H.y+T.y)/2)}const j={x:u.x+g.x,y:u.y+g.y},E={x:d.x+y.x,y:d.y+y.y};return[[e,...j.x!==x[0].x||j.y!==x[0].y?[j]:[],...x,...E.x!==x[x.length-1].x||E.y!==x[x.length-1].y?[E]:[],n],S,w,m,v]}function P4(e,t,n,l){const a=Math.min(Gm(e,t)/2,Gm(t,n)/2,l),{x:s,y:i}=t;if(e.x===s&&s===n.x||e.y===i&&i===n.y)return`L${s} ${i}`;if(e.y===i){const u=e.x<n.x?-1:1,d=e.y<n.y?1:-1;return`L ${s+a*u},${i}Q ${s},${i} ${s},${i+a*d}`}const r=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${s},${i+a*c}Q ${s},${i} ${s+a*r},${i}`}function yf({sourceX:e,sourceY:t,sourcePosition:n=ee.Bottom,targetX:l,targetY:a,targetPosition:s=ee.Top,borderRadius:i=5,centerX:r,centerY:c,offset:u=20,stepPosition:d=.5}){const[f,h,p,x,S]=F4({source:{x:e,y:t},sourcePosition:n,target:{x:l,y:a},targetPosition:s,center:{x:r,y:c},offset:u,stepPosition:d});let w=`M${f[0].x} ${f[0].y}`;for(let g=1;g<f.length-1;g++)w+=P4(f[g-1],f[g],f[g+1],i);return w+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[w,h,p,x,S]}function Qm(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function eM(e){var f;const{sourceNode:t,targetNode:n}=e;if(!Qm(t)||!Qm(n))return null;const l=t.internals.handleBounds||Zm(t.handles),a=n.internals.handleBounds||Zm(n.handles),s=Im((l==null?void 0:l.source)??[],e.sourceHandle),i=Im(e.connectionMode===fs.Strict?(a==null?void 0:a.target)??[]:((a==null?void 0:a.target)??[]).concat((a==null?void 0:a.source)??[]),e.targetHandle);if(!s||!i)return(f=e.onError)==null||f.call(e,"008",jn.error008(s?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const r=(s==null?void 0:s.position)||ee.Bottom,c=(i==null?void 0:i.position)||ee.Top,u=pa(t,s,r),d=pa(n,i,c);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y,sourcePosition:r,targetPosition:c}}function Zm(e){if(!e)return null;const t=[],n=[];for(const l of e)l.width=l.width??1,l.height=l.height??1,l.type==="source"?t.push(l):l.type==="target"&&n.push(l);return{source:t,target:n}}function pa(e,t,n=ee.Left,l=!1){const a=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,s=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:i,height:r}=t??nl(e);if(l)return{x:a+i/2,y:s+r/2};switch((t==null?void 0:t.position)??n){case ee.Top:return{x:a+i/2,y:s};case ee.Right:return{x:a+i,y:s+r/2};case ee.Bottom:return{x:a+i/2,y:s+r};case ee.Left:return{x:a,y:s+r/2}}}function Im(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function vf(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(l=>`${l}=${e[l]}`).join("&")}`:""}function tM(e,{id:t,defaultColor:n,defaultMarkerStart:l,defaultMarkerEnd:a}){const s=new Set;return e.reduce((i,r)=>([r.markerStart||l,r.markerEnd||a].forEach(c=>{if(c&&typeof c=="object"){const u=vf(c,t);s.has(u)||(i.push({id:u,color:c.color||n,...c}),s.add(u))}}),i),[]).sort((i,r)=>i.id.localeCompare(r.id))}const ob=1e3,nM=10,lp={nodeOrigin:[0,0],nodeExtent:Hi,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},lM={...lp,checkEquality:!0};function ap(e,t){const n={...e};for(const l in t)t[l]!==void 0&&(n[l]=t[l]);return n}function aM(e,t,n){const l=ap(lp,n);for(const a of e.values())if(a.parentId)ip(a,e,t,l);else{const s=ir(a,l.nodeOrigin),i=gs(a.extent)?a.extent:l.nodeExtent,r=ha(s,i,nl(a));a.internals.positionAbsolute=r}}function sM(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],l=[];for(const a of e.handles){const s={id:a.id,width:a.width??1,height:a.height??1,nodeId:e.id,x:a.x,y:a.y,position:a.position,type:a.type};a.type==="source"?n.push(s):a.type==="target"&&l.push(s)}return{source:n,target:l}}function sp(e){return e==="manual"}function bf(e,t,n,l={}){var d,f;const a=ap(lM,l),s={i:0},i=new Map(t),r=a!=null&&a.elevateNodesOnSelect&&!sp(a.zIndexMode)?ob:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const h of e){let p=i.get(h.id);if(a.checkEquality&&h===(p==null?void 0:p.internals.userNode))t.set(h.id,p);else{const x=ir(h,a.nodeOrigin),S=gs(h.extent)?h.extent:a.nodeExtent,w=ha(x,S,nl(h));p={...a.defaults,...h,measured:{width:(d=h.measured)==null?void 0:d.width,height:(f=h.measured)==null?void 0:f.height},internals:{positionAbsolute:w,handleBounds:sM(h,p),z:cb(h,r,a.zIndexMode),userNode:h}},t.set(h.id,p)}(p.measured===void 0||p.measured.width===void 0||p.measured.height===void 0)&&!p.hidden&&(c=!1),h.parentId&&ip(p,t,n,l,s),u||(u=h.selected??!1)}return{nodesInitialized:c,hasSelectedNodes:u}}function iM(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function ip(e,t,n,l,a){const{elevateNodesOnSelect:s,nodeOrigin:i,nodeExtent:r,zIndexMode:c}=ap(lp,l),u=e.parentId,d=t.get(u);if(!d){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}iM(e,n),a&&!d.parentId&&d.internals.rootParentIndex===void 0&&c==="auto"&&(d.internals.rootParentIndex=++a.i,d.internals.z=d.internals.z+a.i*nM),a&&d.internals.rootParentIndex!==void 0&&(a.i=d.internals.rootParentIndex);const f=s&&!sp(c)?ob:0,{x:h,y:p,z:x}=rM(e,d,i,r,f,c),{positionAbsolute:S}=e.internals,w=h!==S.x||p!==S.y;(w||x!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:h,y:p}:S,z:x}})}function cb(e,t,n){const l=sn(e.zIndex)?e.zIndex:0;return sp(n)?l:l+(e.selected?t:0)}function rM(e,t,n,l,a,s){const{x:i,y:r}=t.internals.positionAbsolute,c=nl(e),u=ir(e,n),d=gs(e.extent)?ha(u,e.extent,c):u;let f=ha({x:i+d.x,y:r+d.y},l,c);e.extent==="parent"&&(f=W1(f,c,t));const h=cb(e,a,s),p=t.internals.z??0;return{x:f.x,y:f.y,z:p>=h?p+1:h}}function rp(e,t,n,l=[0,0]){var i;const a=[],s=new Map;for(const r of e){const c=t.get(r.parentId);if(!c)continue;const u=((i=s.get(r.parentId))==null?void 0:i.expandedRect)??ps(c),d=F1(u,r.rect);s.set(r.parentId,{expandedRect:d,parent:c})}return s.size>0&&s.forEach(({expandedRect:r,parent:c},u)=>{var m;const d=c.internals.positionAbsolute,f=nl(c),h=c.origin??l,p=r.x<d.x?Math.round(Math.abs(d.x-r.x)):0,x=r.y<d.y?Math.round(Math.abs(d.y-r.y)):0,S=Math.max(f.width,Math.round(r.width)),w=Math.max(f.height,Math.round(r.height)),g=(S-f.width)*h[0],y=(w-f.height)*h[1];(p>0||x>0||g||y)&&(a.push({id:u,type:"position",position:{x:c.position.x-p+g,y:c.position.y-x+y}}),(m=n.get(u))==null||m.forEach(v=>{e.some(j=>j.id===v.id)||a.push({id:v.id,type:"position",position:{x:v.position.x+p,y:v.position.y+x}})})),(f.width<r.width||f.height<r.height||p||x)&&a.push({id:u,type:"dimensions",setAttributes:!0,dimensions:{width:S+(p?h[0]*p-g:0),height:w+(x?h[1]*x-y:0)}})}),a}function oM(e,t,n,l,a,s,i){const r=l==null?void 0:l.querySelector(".xyflow__viewport");let c=!1;if(!r)return{changes:[],updatedInternals:c};const u=[],d=window.getComputedStyle(r),{m22:f}=new window.DOMMatrixReadOnly(d.transform),h=[];for(const p of e.values()){const x=t.get(p.id);if(!x)continue;if(x.hidden){t.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),c=!0;continue}const S=np(p.nodeElement),w=x.measured.width!==S.width||x.measured.height!==S.height;if(!!(S.width&&S.height&&(w||!x.internals.handleBounds||p.force))){const y=p.nodeElement.getBoundingClientRect(),m=gs(x.extent)?x.extent:s;let{positionAbsolute:v}=x.internals;x.parentId&&x.extent==="parent"?v=W1(v,S,t.get(x.parentId)):m&&(v=ha(v,m,S));const j={...x,measured:S,internals:{...x.internals,positionAbsolute:v,handleBounds:{source:Ym("source",p.nodeElement,y,f,x.id),target:Ym("target",p.nodeElement,y,f,x.id)}}};t.set(x.id,j),x.parentId&&ip(j,t,n,{nodeOrigin:a,zIndexMode:i}),c=!0,w&&(u.push({id:x.id,type:"dimensions",dimensions:S}),x.expandParent&&x.parentId&&h.push({id:x.id,parentId:x.parentId,rect:ps(j,a)}))}}if(h.length>0){const p=rp(h,t,n,a);u.push(...p)}return{changes:u,updatedInternals:c}}async function cM({delta:e,panZoom:t,transform:n,translateExtent:l,width:a,height:s}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[a,s]],l),r=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(r)}function Km(e,t,n,l,a,s){let i=a;const r=l.get(i)||new Map;l.set(i,r.set(n,t)),i=`${a}-${e}`;const c=l.get(i)||new Map;if(l.set(i,c.set(n,t)),s){i=`${a}-${e}-${s}`;const u=l.get(i)||new Map;l.set(i,u.set(n,t))}}function ub(e,t,n){e.clear(),t.clear();for(const l of n){const{source:a,target:s,sourceHandle:i=null,targetHandle:r=null}=l,c={edgeId:l.id,source:a,target:s,sourceHandle:i,targetHandle:r},u=`${a}-${i}--${s}-${r}`,d=`${s}-${r}--${a}-${i}`;Km("source",c,d,e,a,i),Km("target",c,u,e,s,r),t.set(l.id,l)}}function db(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:db(n,t):!1}function Wm(e,t,n){var a;let l=e;do{if((a=l==null?void 0:l.matches)!=null&&a.call(l,t))return!0;if(l===n)return!1;l=l==null?void 0:l.parentElement}while(l);return!1}function uM(e,t,n,l){const a=new Map;for(const[s,i]of e)if((i.selected||i.id===l)&&(!i.parentId||!db(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const r=e.get(s);r&&a.set(s,{id:s,position:r.position||{x:0,y:0},distance:{x:n.x-r.internals.positionAbsolute.x,y:n.y-r.internals.positionAbsolute.y},extent:r.extent,parentId:r.parentId,origin:r.origin,expandParent:r.expandParent,internals:{positionAbsolute:r.internals.positionAbsolute||{x:0,y:0}},measured:{width:r.measured.width??0,height:r.measured.height??0}})}return a}function Fu({nodeId:e,dragItems:t,nodeLookup:n,dragging:l=!0}){var i,r,c;const a=[];for(const[u,d]of t){const f=(i=n.get(u))==null?void 0:i.internals.userNode;f&&a.push({...f,position:d.position,dragging:l})}if(!e)return[a[0],a];const s=(r=n.get(e))==null?void 0:r.internals.userNode;return[s?{...s,position:((c=t.get(e))==null?void 0:c.position)||s.position,dragging:l}:a[0],a]}function dM({dragItems:e,snapGrid:t,x:n,y:l}){const a=e.values().next().value;if(!a)return null;const s={x:n-a.distance.x,y:l-a.distance.y},i=or(s,t);return{x:i.x-s.x,y:i.y-s.y}}function fM({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:l,onDragStop:a}){let s={x:null,y:null},i=0,r=new Map,c=!1,u={x:0,y:0},d=null,f=!1,h=null,p=!1,x=!1,S=null;function w({noDragClassName:y,handleSelector:m,domNode:v,isSelectable:j,nodeId:E,nodeClickDistance:M=0}){h=Ct(v);function A({x:$,y:V}){const{nodeLookup:N,nodeExtent:D,snapGrid:k,snapToGrid:R,nodeOrigin:z,onNodeDrag:O,onSelectionDrag:Y,onError:X,updateNodePositions:L}=t();s={x:$,y:V};let U=!1;const _=r.size>1,B=_&&D?xf(rr(r)):null,G=_&&R?dM({dragItems:r,snapGrid:k,x:$,y:V}):null;for(const[q,Q]of r){if(!N.has(q))continue;let K={x:$-Q.distance.x,y:V-Q.distance.y};R&&(K=G?{x:Math.round(K.x+G.x),y:Math.round(K.y+G.y)}:or(K,k));let W=null;if(_&&D&&!Q.extent&&B){const{positionAbsolute:F}=Q.internals,le=F.x-B.x+D[0][0],ae=F.x+Q.measured.width-B.x2+D[1][0],te=F.y-B.y+D[0][1],ge=F.y+Q.measured.height-B.y2+D[1][1];W=[[le,te],[ae,ge]]}const{position:P,positionAbsolute:J}=K1({nodeId:q,nextPosition:K,nodeLookup:N,nodeExtent:W||D,nodeOrigin:z,onError:X});U=U||Q.position.x!==P.x||Q.position.y!==P.y,Q.position=P,Q.internals.positionAbsolute=J}if(x=x||U,!!U&&(L(r,!0),S&&(l||O||!E&&Y))){const[q,Q]=Fu({nodeId:E,dragItems:r,nodeLookup:N});l==null||l(S,r,q,Q),O==null||O(S,q,Q),E||Y==null||Y(S,Q)}}async function C(){if(!d)return;const{transform:$,panBy:V,autoPanSpeed:N,autoPanOnNodeDrag:D}=t();if(!D){c=!1,cancelAnimationFrame(i);return}const[k,R]=J1(u,d,N);(k!==0||R!==0)&&(s.x=(s.x??0)-k/$[2],s.y=(s.y??0)-R/$[2],await V({x:k,y:R})&&A(s)),i=requestAnimationFrame(C)}function H($){var _;const{nodeLookup:V,multiSelectionActive:N,nodesDraggable:D,transform:k,snapGrid:R,snapToGrid:z,selectNodesOnDrag:O,onNodeDragStart:Y,onSelectionDragStart:X,unselectNodesAndEdges:L}=t();f=!0,(!O||!j)&&!N&&E&&((_=V.get(E))!=null&&_.selected||L()),j&&O&&E&&(e==null||e(E));const U=gi($.sourceEvent,{transform:k,snapGrid:R,snapToGrid:z,containerBounds:d});if(s=U,r=uM(V,D,U,E),r.size>0&&(n||Y||!E&&X)){const[B,G]=Fu({nodeId:E,dragItems:r,nodeLookup:V});n==null||n($.sourceEvent,r,B,G),Y==null||Y($.sourceEvent,B,G),E||X==null||X($.sourceEvent,G)}}const T=M1().clickDistance(M).on("start",$=>{const{domNode:V,nodeDragThreshold:N,transform:D,snapGrid:k,snapToGrid:R}=t();d=(V==null?void 0:V.getBoundingClientRect())||null,p=!1,x=!1,S=$.sourceEvent,N===0&&H($),s=gi($.sourceEvent,{transform:D,snapGrid:k,snapToGrid:R,containerBounds:d}),u=rn($.sourceEvent,d)}).on("drag",$=>{const{autoPanOnNodeDrag:V,transform:N,snapGrid:D,snapToGrid:k,nodeDragThreshold:R,nodeLookup:z}=t(),O=gi($.sourceEvent,{transform:N,snapGrid:D,snapToGrid:k,containerBounds:d});if(S=$.sourceEvent,($.sourceEvent.type==="touchmove"&&$.sourceEvent.touches.length>1||E&&!z.has(E))&&(p=!0),!p){if(!c&&V&&f&&(c=!0,C()),!f){const Y=rn($.sourceEvent,d),X=Y.x-u.x,L=Y.y-u.y;Math.sqrt(X*X+L*L)>R&&H($)}(s.x!==O.xSnapped||s.y!==O.ySnapped)&&r&&f&&(u=rn($.sourceEvent,d),A(O))}}).on("end",$=>{if(!(!f||p)&&(c=!1,f=!1,cancelAnimationFrame(i),r.size>0)){const{nodeLookup:V,updateNodePositions:N,onNodeDragStop:D,onSelectionDragStop:k}=t();if(x&&(N(r,!1),x=!1),a||D||!E&&k){const[R,z]=Fu({nodeId:E,dragItems:r,nodeLookup:V,dragging:!1});a==null||a($.sourceEvent,r,R,z),D==null||D($.sourceEvent,R,z),E||k==null||k($.sourceEvent,z)}}}).filter($=>{const V=$.target;return!$.button&&(!y||!Wm(V,`.${y}`,v))&&(!m||Wm(V,m,v))});h.call(T)}function g(){h==null||h.on(".drag",null)}return{update:w,destroy:g}}function hM(e,t,n){const l=[],a={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const s of t.values())$i(a,ps(s))>0&&l.push(s);return l}const pM=250;function gM(e,t,n,l){var r,c;let a=[],s=1/0;const i=hM(e,n,t+pM);for(const u of i){const d=[...((r=u.internals.handleBounds)==null?void 0:r.source)??[],...((c=u.internals.handleBounds)==null?void 0:c.target)??[]];for(const f of d){if(l.nodeId===f.nodeId&&l.type===f.type&&l.id===f.id)continue;const{x:h,y:p}=pa(u,f,f.position,!0),x=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(p-e.y,2));x>t||(x<s?(a=[{...f,x:h,y:p}],s=x):x===s&&a.push({...f,x:h,y:p}))}}if(!a.length)return null;if(a.length>1){const u=l.type==="source"?"target":"source";return a.find(d=>d.type===u)??a[0]}return a[0]}function fb(e,t,n,l,a,s=!1){var u,d,f;const i=l.get(e);if(!i)return null;const r=a==="strict"?(u=i.internals.handleBounds)==null?void 0:u[t]:[...((d=i.internals.handleBounds)==null?void 0:d.source)??[],...((f=i.internals.handleBounds)==null?void 0:f.target)??[]],c=(n?r==null?void 0:r.find(h=>h.id===n):r==null?void 0:r[0])??null;return c&&s?{...c,...pa(i,c,c.position,!0)}:c}function hb(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function mM(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const pb=()=>!0;function xM(e,{connectionMode:t,connectionRadius:n,handleId:l,nodeId:a,edgeUpdaterType:s,isTarget:i,domNode:r,nodeLookup:c,lib:u,autoPanOnConnect:d,flowId:f,panBy:h,cancelConnection:p,onConnectStart:x,onConnect:S,onConnectEnd:w,isValidConnection:g=pb,onReconnectEnd:y,updateConnection:m,getTransform:v,getFromHandle:j,autoPanSpeed:E,dragThreshold:M=1,handleDomNode:A}){const C=tb(e.target);let H=0,T;const{x:$,y:V}=rn(e),N=hb(s,A),D=r==null?void 0:r.getBoundingClientRect();let k=!1;if(!D||!N)return;const R=fb(a,N,l,c,t);if(!R)return;let z=rn(e,D),O=!1,Y=null,X=!1,L=null;function U(){if(!d||!D)return;const[P,J]=J1(z,D,E);h({x:P,y:J}),H=requestAnimationFrame(U)}const _={...R,nodeId:a,type:N,position:R.position},B=c.get(a);let q={inProgress:!0,isValid:null,from:pa(B,_,ee.Left,!0),fromHandle:_,fromPosition:_.position,fromNode:B,to:z,toHandle:null,toPosition:$m[_.position],toNode:null,pointer:z};function Q(){k=!0,m(q),x==null||x(e,{nodeId:a,handleId:l,handleType:N})}M===0&&Q();function K(P){if(!k){const{x:ge,y:I}=rn(P),se=ge-$,Re=I-V;if(!(se*se+Re*Re>M*M))return;Q()}if(!j()||!_){W(P);return}const J=v();z=rn(P,D),T=gM(cr(z,J,!1,[1,1]),n,c,_),O||(U(),O=!0);const F=gb(P,{handle:T,connectionMode:t,fromNodeId:a,fromHandleId:l,fromType:i?"target":"source",isValidConnection:g,doc:C,lib:u,flowId:f,nodeLookup:c});L=F.handleDomNode,Y=F.connection,X=mM(!!T,F.isValid);const le=c.get(a),ae=le?pa(le,_,ee.Left,!0):q.from,te={...q,from:ae,isValid:X,to:F.toHandle&&X?dc({x:F.toHandle.x,y:F.toHandle.y},J):z,toHandle:F.toHandle,toPosition:X&&F.toHandle?F.toHandle.position:$m[_.position],toNode:F.toHandle?c.get(F.toHandle.nodeId):null,pointer:z};m(te),q=te}function W(P){if(!("touches"in P&&P.touches.length>0)){if(k){(T||L)&&Y&&X&&(S==null||S(Y));const{inProgress:J,...F}=q,le={...F,toPosition:q.toHandle?q.toPosition:null};w==null||w(P,le),s&&(y==null||y(P,le))}p(),cancelAnimationFrame(H),O=!1,X=!1,Y=null,L=null,C.removeEventListener("mousemove",K),C.removeEventListener("mouseup",W),C.removeEventListener("touchmove",K),C.removeEventListener("touchend",W)}}C.addEventListener("mousemove",K),C.addEventListener("mouseup",W),C.addEventListener("touchmove",K),C.addEventListener("touchend",W)}function gb(e,{handle:t,connectionMode:n,fromNodeId:l,fromHandleId:a,fromType:s,doc:i,lib:r,flowId:c,isValidConnection:u=pb,nodeLookup:d}){const f=s==="target",h=t?i.querySelector(`.${r}-flow__handle[data-id="${c}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:p,y:x}=rn(e),S=i.elementFromPoint(p,x),w=S!=null&&S.classList.contains(`${r}-flow__handle`)?S:h,g={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const y=hb(void 0,w),m=w.getAttribute("data-nodeid"),v=w.getAttribute("data-handleid"),j=w.classList.contains("connectable"),E=w.classList.contains("connectableend");if(!m||!y)return g;const M={source:f?m:l,sourceHandle:f?v:a,target:f?l:m,targetHandle:f?a:v};g.connection=M;const C=j&&E&&(n===fs.Strict?f&&y==="source"||!f&&y==="target":m!==l||v!==a);g.isValid=C&&u(M),g.toHandle=fb(m,y,v,d,n,!0)}return g}const wf={onPointerDown:xM,isValid:gb};function yM({domNode:e,panZoom:t,getTransform:n,getViewScale:l}){const a=Ct(e);function s({translateExtent:r,width:c,height:u,zoomStep:d=1,pannable:f=!0,zoomable:h=!0,inversePan:p=!1}){const x=m=>{if(m.sourceEvent.type!=="wheel"||!t)return;const v=n(),j=m.sourceEvent.ctrlKey&&Bi()?10:1,E=-m.sourceEvent.deltaY*(m.sourceEvent.deltaMode===1?.05:m.sourceEvent.deltaMode?1:.002)*d,M=v[2]*Math.pow(2,E*j);t.scaleTo(M)};let S=[0,0];const w=m=>{(m.sourceEvent.type==="mousedown"||m.sourceEvent.type==="touchstart")&&(S=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY])},g=m=>{const v=n();if(m.sourceEvent.type!=="mousemove"&&m.sourceEvent.type!=="touchmove"||!t)return;const j=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY],E=[j[0]-S[0],j[1]-S[1]];S=j;const M=l()*Math.max(v[2],Math.log(v[2]))*(p?-1:1),A={x:v[0]-E[0]*M,y:v[1]-E[1]*M},C=[[0,0],[c,u]];t.setViewportConstrained({x:A.x,y:A.y,zoom:v[2]},C,r)},y=V1().on("start",w).on("zoom",f?g:null).on("zoom.wheel",h?x:null);a.call(y,{})}function i(){a.on("zoom",null)}return{update:s,destroy:i,pointer:tn}}const Qc=e=>({x:e.x,y:e.y,zoom:e.k}),Pu=({x:e,y:t,zoom:n})=>Vc.translate(e,t).scale(n),qa=(e,t)=>e.target.closest(`.${t}`),mb=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),vM=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,ed=(e,t=0,n=vM,l=()=>{})=>{const a=typeof t=="number"&&t>0;return a||l(),a?e.transition().duration(t).ease(n).on("end",l):e},xb=e=>{const t=e.ctrlKey&&Bi()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function bM({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:l,panOnScrollMode:a,panOnScrollSpeed:s,zoomOnPinch:i,onPanZoomStart:r,onPanZoom:c,onPanZoomEnd:u}){return d=>{if(qa(d,t))return d.ctrlKey&&d.preventDefault(),!1;d.preventDefault(),d.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(d.ctrlKey&&i){const w=tn(d),g=xb(d),y=f*Math.pow(2,g);l.scaleTo(n,y,w,d);return}const h=d.deltaMode===1?20:1;let p=a===aa.Vertical?0:d.deltaX*h,x=a===aa.Horizontal?0:d.deltaY*h;!Bi()&&d.shiftKey&&a!==aa.Vertical&&(p=d.deltaY*h,x=0),l.translateBy(n,-(p/f)*s,-(x/f)*s,{internal:!0});const S=Qc(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c==null||c(d,S),e.panScrollTimeout=setTimeout(()=>{u==null||u(d,S),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,r==null||r(d,S))}}function wM({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(l,a){const s=l.type==="wheel",i=!t&&s&&!l.ctrlKey,r=qa(l,e);if(l.ctrlKey&&s&&r&&l.preventDefault(),i||r)return null;l.preventDefault(),n.call(this,l,a)}}function SM({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return l=>{var s,i,r;if((s=l.sourceEvent)!=null&&s.internal)return;const a=Qc(l.transform);e.mouseButton=((i=l.sourceEvent)==null?void 0:i.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=a,((r=l.sourceEvent)==null?void 0:r.type)==="mousedown"&&t(!0),n&&(n==null||n(l.sourceEvent,a))}}function NM({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:l,onPanZoom:a}){return s=>{var i,r;e.usedRightMouseButton=!!(n&&mb(t,e.mouseButton??0)),(i=s.sourceEvent)!=null&&i.sync||l([s.transform.x,s.transform.y,s.transform.k]),a&&!((r=s.sourceEvent)!=null&&r.internal)&&(a==null||a(s.sourceEvent,Qc(s.transform)))}}function jM({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:l,onPanZoomEnd:a,onPaneContextMenu:s}){return i=>{var r;if(!((r=i.sourceEvent)!=null&&r.internal)&&(e.isZoomingOrPanning=!1,s&&mb(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&s(i.sourceEvent),e.usedRightMouseButton=!1,l(!1),a)){const c=Qc(i.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{a==null||a(i.sourceEvent,c)},n?150:0)}}}function kM({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:l,panOnScroll:a,zoomOnDoubleClick:s,userSelectionActive:i,noWheelClassName:r,noPanClassName:c,lib:u,connectionInProgress:d}){return f=>{var w;const h=e||t,p=n&&f.ctrlKey,x=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(qa(f,`${u}-flow__node`)||qa(f,`${u}-flow__edge`)))return!0;if(!l&&!h&&!a&&!s&&!n||i||d&&!x||qa(f,r)&&x||qa(f,c)&&(!x||a&&x&&!e)||!n&&f.ctrlKey&&x)return!1;if(!n&&f.type==="touchstart"&&((w=f.touches)==null?void 0:w.length)>1)return f.preventDefault(),!1;if(!h&&!a&&!p&&x||!l&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(l)&&!l.includes(f.button)&&f.type==="mousedown")return!1;const S=Array.isArray(l)&&l.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||x)&&S}}function EM({domNode:e,minZoom:t,maxZoom:n,translateExtent:l,viewport:a,onPanZoom:s,onPanZoomStart:i,onPanZoomEnd:r,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},d=e.getBoundingClientRect(),f=V1().scaleExtent([t,n]).translateExtent(l),h=Ct(e).call(f);y({x:a.x,y:a.y,zoom:hs(a.zoom,t,n)},[[0,0],[d.width,d.height]],l);const p=h.on("wheel.zoom"),x=h.on("dblclick.zoom");f.wheelDelta(xb);function S(T,$){return h?new Promise(V=>{f==null||f.interpolate(($==null?void 0:$.interpolate)==="linear"?pi:fo).transform(ed(h,$==null?void 0:$.duration,$==null?void 0:$.ease,()=>V(!0)),T)}):Promise.resolve(!1)}function w({noWheelClassName:T,noPanClassName:$,onPaneContextMenu:V,userSelectionActive:N,panOnScroll:D,panOnDrag:k,panOnScrollMode:R,panOnScrollSpeed:z,preventScrolling:O,zoomOnPinch:Y,zoomOnScroll:X,zoomOnDoubleClick:L,zoomActivationKeyPressed:U,lib:_,onTransformChange:B,connectionInProgress:G,paneClickDistance:q,selectionOnDrag:Q}){N&&!u.isZoomingOrPanning&&g();const K=D&&!U&&!N;f.clickDistance(Q?1/0:!sn(q)||q<0?0:q);const W=K?bM({zoomPanValues:u,noWheelClassName:T,d3Selection:h,d3Zoom:f,panOnScrollMode:R,panOnScrollSpeed:z,zoomOnPinch:Y,onPanZoomStart:i,onPanZoom:s,onPanZoomEnd:r}):wM({noWheelClassName:T,preventScrolling:O,d3ZoomHandler:p});if(h.on("wheel.zoom",W,{passive:!1}),!N){const J=SM({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:i});f.on("start",J);const F=NM({zoomPanValues:u,panOnDrag:k,onPaneContextMenu:!!V,onPanZoom:s,onTransformChange:B});f.on("zoom",F);const le=jM({zoomPanValues:u,panOnDrag:k,panOnScroll:D,onPaneContextMenu:V,onPanZoomEnd:r,onDraggingChange:c});f.on("end",le)}const P=kM({zoomActivationKeyPressed:U,panOnDrag:k,zoomOnScroll:X,panOnScroll:D,zoomOnDoubleClick:L,zoomOnPinch:Y,userSelectionActive:N,noPanClassName:$,noWheelClassName:T,lib:_,connectionInProgress:G});f.filter(P),L?h.on("dblclick.zoom",x):h.on("dblclick.zoom",null)}function g(){f.on("zoom",null)}async function y(T,$,V){const N=Pu(T),D=f==null?void 0:f.constrain()(N,$,V);return D&&await S(D),new Promise(k=>k(D))}async function m(T,$){const V=Pu(T);return await S(V,$),new Promise(N=>N(V))}function v(T){if(h){const $=Pu(T),V=h.property("__zoom");(V.k!==T.zoom||V.x!==T.x||V.y!==T.y)&&(f==null||f.transform(h,$,null,{sync:!0}))}}function j(){const T=h?Y1(h.node()):{x:0,y:0,k:1};return{x:T.x,y:T.y,zoom:T.k}}function E(T,$){return h?new Promise(V=>{f==null||f.interpolate(($==null?void 0:$.interpolate)==="linear"?pi:fo).scaleTo(ed(h,$==null?void 0:$.duration,$==null?void 0:$.ease,()=>V(!0)),T)}):Promise.resolve(!1)}function M(T,$){return h?new Promise(V=>{f==null||f.interpolate(($==null?void 0:$.interpolate)==="linear"?pi:fo).scaleBy(ed(h,$==null?void 0:$.duration,$==null?void 0:$.ease,()=>V(!0)),T)}):Promise.resolve(!1)}function A(T){f==null||f.scaleExtent(T)}function C(T){f==null||f.translateExtent(T)}function H(T){const $=!sn(T)||T<0?0:T;f==null||f.clickDistance($)}return{update:w,destroy:g,setViewport:m,setViewportConstrained:y,getViewport:j,scaleTo:E,scaleBy:M,setScaleExtent:A,setTranslateExtent:C,syncViewport:v,setClickDistance:H}}var ms;(function(e){e.Line="line",e.Handle="handle"})(ms||(ms={}));function CM({width:e,prevWidth:t,height:n,prevHeight:l,affectsX:a,affectsY:s}){const i=e-t,r=n-l,c=[i>0?1:i<0?-1:0,r>0?1:r<0?-1:0];return i&&a&&(c[0]=c[0]*-1),r&&s&&(c[1]=c[1]*-1),c}function Jm(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),l=e.includes("left"),a=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:l,affectsY:a}}function rl(e,t){return Math.max(0,t-e)}function ol(e,t){return Math.max(0,e-t)}function Yr(e,t,n){return Math.max(0,t-e,e-n)}function Fm(e,t){return e?!t:t}function MM(e,t,n,l,a,s,i,r){let{affectsX:c,affectsY:u}=t;const{isHorizontal:d,isVertical:f}=t,h=d&&f,{xSnapped:p,ySnapped:x}=n,{minWidth:S,maxWidth:w,minHeight:g,maxHeight:y}=l,{x:m,y:v,width:j,height:E,aspectRatio:M}=e;let A=Math.floor(d?p-e.pointerX:0),C=Math.floor(f?x-e.pointerY:0);const H=j+(c?-A:A),T=E+(u?-C:C),$=-s[0]*j,V=-s[1]*E;let N=Yr(H,S,w),D=Yr(T,g,y);if(i){let z=0,O=0;c&&A<0?z=rl(m+A+$,i[0][0]):!c&&A>0&&(z=ol(m+H+$,i[1][0])),u&&C<0?O=rl(v+C+V,i[0][1]):!u&&C>0&&(O=ol(v+T+V,i[1][1])),N=Math.max(N,z),D=Math.max(D,O)}if(r){let z=0,O=0;c&&A>0?z=ol(m+A,r[0][0]):!c&&A<0&&(z=rl(m+H,r[1][0])),u&&C>0?O=ol(v+C,r[0][1]):!u&&C<0&&(O=rl(v+T,r[1][1])),N=Math.max(N,z),D=Math.max(D,O)}if(a){if(d){const z=Yr(H/M,g,y)*M;if(N=Math.max(N,z),i){let O=0;!c&&!u||c&&!u&&h?O=ol(v+V+H/M,i[1][1])*M:O=rl(v+V+(c?A:-A)/M,i[0][1])*M,N=Math.max(N,O)}if(r){let O=0;!c&&!u||c&&!u&&h?O=rl(v+H/M,r[1][1])*M:O=ol(v+(c?A:-A)/M,r[0][1])*M,N=Math.max(N,O)}}if(f){const z=Yr(T*M,S,w)/M;if(D=Math.max(D,z),i){let O=0;!c&&!u||u&&!c&&h?O=ol(m+T*M+$,i[1][0])/M:O=rl(m+(u?C:-C)*M+$,i[0][0])/M,D=Math.max(D,O)}if(r){let O=0;!c&&!u||u&&!c&&h?O=rl(m+T*M,r[1][0])/M:O=ol(m+(u?C:-C)*M,r[0][0])/M,D=Math.max(D,O)}}}C=C+(C<0?D:-D),A=A+(A<0?N:-N),a&&(h?H>T*M?C=(Fm(c,u)?-A:A)/M:A=(Fm(c,u)?-C:C)*M:d?(C=A/M,u=c):(A=C*M,c=u));const k=c?m+A:m,R=u?v+C:v;return{width:j+(c?-A:A),height:E+(u?-C:C),x:s[0]*A*(c?-1:1)+k,y:s[1]*C*(u?-1:1)+R}}const yb={width:0,height:0,x:0,y:0},_M={...yb,pointerX:0,pointerY:0,aspectRatio:1};function AM(e){return[[0,0],[e.measured.width,e.measured.height]]}function TM(e,t,n){const l=t.position.x+e.position.x,a=t.position.y+e.position.y,s=e.measured.width??0,i=e.measured.height??0,r=n[0]*s,c=n[1]*i;return[[l-r,a-c],[l+s-r,a+i-c]]}function zM({domNode:e,nodeId:t,getStoreItems:n,onChange:l,onEnd:a}){const s=Ct(e);let i={controlDirection:Jm("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function r({controlPosition:u,boundaries:d,keepAspectRatio:f,resizeDirection:h,onResizeStart:p,onResize:x,onResizeEnd:S,shouldResize:w}){let g={...yb},y={..._M};i={boundaries:d,resizeDirection:h,keepAspectRatio:f,controlDirection:Jm(u)};let m,v=null,j=[],E,M,A,C=!1;const H=M1().on("start",T=>{const{nodeLookup:$,transform:V,snapGrid:N,snapToGrid:D,nodeOrigin:k,paneDomNode:R}=n();if(m=$.get(t),!m)return;v=(R==null?void 0:R.getBoundingClientRect())??null;const{xSnapped:z,ySnapped:O}=gi(T.sourceEvent,{transform:V,snapGrid:N,snapToGrid:D,containerBounds:v});g={width:m.measured.width??0,height:m.measured.height??0,x:m.position.x??0,y:m.position.y??0},y={...g,pointerX:z,pointerY:O,aspectRatio:g.width/g.height},E=void 0,m.parentId&&(m.extent==="parent"||m.expandParent)&&(E=$.get(m.parentId),M=E&&m.extent==="parent"?AM(E):void 0),j=[],A=void 0;for(const[Y,X]of $)if(X.parentId===t&&(j.push({id:Y,position:{...X.position},extent:X.extent}),X.extent==="parent"||X.expandParent)){const L=TM(X,m,X.origin??k);A?A=[[Math.min(L[0][0],A[0][0]),Math.min(L[0][1],A[0][1])],[Math.max(L[1][0],A[1][0]),Math.max(L[1][1],A[1][1])]]:A=L}p==null||p(T,{...g})}).on("drag",T=>{const{transform:$,snapGrid:V,snapToGrid:N,nodeOrigin:D}=n(),k=gi(T.sourceEvent,{transform:$,snapGrid:V,snapToGrid:N,containerBounds:v}),R=[];if(!m)return;const{x:z,y:O,width:Y,height:X}=g,L={},U=m.origin??D,{width:_,height:B,x:G,y:q}=MM(y,i.controlDirection,k,i.boundaries,i.keepAspectRatio,U,M,A),Q=_!==Y,K=B!==X,W=G!==z&&Q,P=q!==O&&K;if(!W&&!P&&!Q&&!K)return;if((W||P||U[0]===1||U[1]===1)&&(L.x=W?G:g.x,L.y=P?q:g.y,g.x=L.x,g.y=L.y,j.length>0)){const ae=G-z,te=q-O;for(const ge of j)ge.position={x:ge.position.x-ae+U[0]*(_-Y),y:ge.position.y-te+U[1]*(B-X)},R.push(ge)}if((Q||K)&&(L.width=Q&&(!i.resizeDirection||i.resizeDirection==="horizontal")?_:g.width,L.height=K&&(!i.resizeDirection||i.resizeDirection==="vertical")?B:g.height,g.width=L.width,g.height=L.height),E&&m.expandParent){const ae=U[0]*(L.width??0);L.x&&L.x<ae&&(g.x=ae,y.x=y.x-(L.x-ae));const te=U[1]*(L.height??0);L.y&&L.y<te&&(g.y=te,y.y=y.y-(L.y-te))}const J=CM({width:g.width,prevWidth:Y,height:g.height,prevHeight:X,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),F={...g,direction:J};(w==null?void 0:w(T,F))!==!1&&(C=!0,x==null||x(T,F),l(L,R))}).on("end",T=>{C&&(S==null||S(T,{...g}),a==null||a({...g}),C=!1)});s.call(H)}function c(){s.on(".drag",null)}return{update:r,destroy:c}}var vb={exports:{}},bb={},wb={exports:{}},Sb={};/**
143
+ `},g5={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was moved over droppable area "+n.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:n}=e;return n?"Draggable item "+t.id+" was dropped over droppable area "+n.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function m5(e){let{announcements:t=g5,container:n,hiddenTextDescribedById:l,screenReaderInstructions:a=p5}=e;const{announce:s,announcement:i}=d5(),r=nr("DndLiveRegion"),[c,u]=b.useState(!1);if(b.useEffect(()=>{u(!0)},[]),f5(b.useMemo(()=>({onDragStart(f){let{active:h}=f;s(t.onDragStart({active:h}))},onDragMove(f){let{active:h,over:p}=f;t.onDragMove&&s(t.onDragMove({active:h,over:p}))},onDragOver(f){let{active:h,over:p}=f;s(t.onDragOver({active:h,over:p}))},onDragEnd(f){let{active:h,over:p}=f;s(t.onDragEnd({active:h,over:p}))},onDragCancel(f){let{active:h,over:p}=f;s(t.onDragCancel({active:h,over:p}))}}),[s,t])),!c)return null;const d=Me.createElement(Me.Fragment,null,Me.createElement(c5,{id:l,value:a.draggable}),Me.createElement(u5,{id:r,announcement:i}));return n?Wl.createPortal(d,n):d}var Ge;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Ge||(Ge={}));function ec(){}function sm(e,t){return b.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function x5(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return b.useMemo(()=>[...t].filter(l=>l!=null),[...t])}const cn=Object.freeze({x:0,y:0});function y5(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function v5(e,t){const n=Po(e);if(!n)return"0 0";const l={x:(n.x-t.left)/t.width*100,y:(n.y-t.top)/t.height*100};return l.x+"% "+l.y+"%"}function b5(e,t){let{data:{value:n}}=e,{data:{value:l}}=t;return n-l}function w5(e,t){let{data:{value:n}}=e,{data:{value:l}}=t;return l-n}function im(e){let{left:t,top:n,height:l,width:a}=e;return[{x:t,y:n},{x:t+a,y:n},{x:t,y:n+l},{x:t+a,y:n+l}]}function S5(e,t){if(!e||e.length===0)return null;const[n]=e;return n[t]}const N5=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:l}=e;const a=im(t),s=[];for(const i of l){const{id:r}=i,c=n.get(r);if(c){const u=im(c),d=a.reduce((h,p,x)=>h+y5(u[x],p),0),f=Number((d/4).toFixed(4));s.push({id:r,data:{droppableContainer:i,value:f}})}}return s.sort(b5)};function j5(e,t){const n=Math.max(t.top,e.top),l=Math.max(t.left,e.left),a=Math.min(t.left+t.width,e.left+e.width),s=Math.min(t.top+t.height,e.top+e.height),i=a-l,r=s-n;if(l<a&&n<s){const c=t.width*t.height,u=e.width*e.height,d=i*r,f=d/(c+u-d);return Number(f.toFixed(4))}return 0}const k5=e=>{let{collisionRect:t,droppableRects:n,droppableContainers:l}=e;const a=[];for(const s of l){const{id:i}=s,r=n.get(i);if(r){const c=j5(r,t);c>0&&a.push({id:i,data:{droppableContainer:s,value:c}})}}return a.sort(w5)};function E5(e,t,n){return{...e,scaleX:t&&n?t.width/n.width:1,scaleY:t&&n?t.height/n.height:1}}function Qv(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:cn}function C5(e){return function(n){for(var l=arguments.length,a=new Array(l>1?l-1:0),s=1;s<l;s++)a[s-1]=arguments[s];return a.reduce((i,r)=>({...i,top:i.top+e*r.y,bottom:i.bottom+e*r.y,left:i.left+e*r.x,right:i.right+e*r.x}),{...n})}}const M5=C5(1);function Zv(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function _5(e,t,n){const l=Zv(t);if(!l)return e;const{scaleX:a,scaleY:s,x:i,y:r}=l,c=e.left-i-(1-a)*parseFloat(n),u=e.top-r-(1-s)*parseFloat(n.slice(n.indexOf(" ")+1)),d=a?e.width/a:e.width,f=s?e.height/s:e.height;return{width:d,height:f,top:u,right:c+d,bottom:u+f,left:c}}const A5={ignoreTransform:!1};function As(e,t){t===void 0&&(t=A5);let n=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:d}=ft(e).getComputedStyle(e);u&&(n=_5(n,u,d))}const{top:l,left:a,width:s,height:i,bottom:r,right:c}=n;return{top:l,left:a,width:s,height:i,bottom:r,right:c}}function rm(e){return As(e,{ignoreTransform:!0})}function T5(e){const t=e.innerWidth,n=e.innerHeight;return{top:0,left:0,right:t,bottom:n,width:t,height:n}}function z5(e,t){return t===void 0&&(t=ft(e).getComputedStyle(e)),t.position==="fixed"}function D5(e,t){t===void 0&&(t=ft(e).getComputedStyle(e));const n=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(a=>{const s=t[a];return typeof s=="string"?n.test(s):!1})}function $h(e,t){const n=[];function l(a){if(t!=null&&n.length>=t||!a)return n;if(Lh(a)&&a.scrollingElement!=null&&!n.includes(a.scrollingElement))return n.push(a.scrollingElement),n;if(!er(a)||Vv(a)||n.includes(a))return n;const s=ft(e).getComputedStyle(a);return a!==e&&D5(a,s)&&n.push(a),z5(a,s)?n:l(a.parentNode)}return e?l(e):n}function Iv(e){const[t]=$h(e,1);return t??null}function Gu(e){return!Rc||!e?null:Ms(e)?e:Hh(e)?Lh(e)||e===_s(e).scrollingElement?window:er(e)?e:null:null}function Kv(e){return Ms(e)?e.scrollX:e.scrollLeft}function Wv(e){return Ms(e)?e.scrollY:e.scrollTop}function sf(e){return{x:Kv(e),y:Wv(e)}}var We;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(We||(We={}));function Jv(e){return!Rc||!e?!1:e===document.scrollingElement}function Fv(e){const t={x:0,y:0},n=Jv(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},l={x:e.scrollWidth-n.width,y:e.scrollHeight-n.height},a=e.scrollTop<=t.y,s=e.scrollLeft<=t.x,i=e.scrollTop>=l.y,r=e.scrollLeft>=l.x;return{isTop:a,isLeft:s,isBottom:i,isRight:r,maxScroll:l,minScroll:t}}const R5={x:.2,y:.2};function O5(e,t,n,l,a){let{top:s,left:i,right:r,bottom:c}=n;l===void 0&&(l=10),a===void 0&&(a=R5);const{isTop:u,isBottom:d,isLeft:f,isRight:h}=Fv(e),p={x:0,y:0},x={x:0,y:0},S={height:t.height*a.y,width:t.width*a.x};return!u&&s<=t.top+S.height?(p.y=We.Backward,x.y=l*Math.abs((t.top+S.height-s)/S.height)):!d&&c>=t.bottom-S.height&&(p.y=We.Forward,x.y=l*Math.abs((t.bottom-S.height-c)/S.height)),!h&&r>=t.right-S.width?(p.x=We.Forward,x.x=l*Math.abs((t.right-S.width-r)/S.width)):!f&&i<=t.left+S.width&&(p.x=We.Backward,x.x=l*Math.abs((t.left+S.width-i)/S.width)),{direction:p,speed:x}}function H5(e){if(e===document.scrollingElement){const{innerWidth:s,innerHeight:i}=window;return{top:0,left:0,right:s,bottom:i,width:s,height:i}}const{top:t,left:n,right:l,bottom:a}=e.getBoundingClientRect();return{top:t,left:n,right:l,bottom:a,width:e.clientWidth,height:e.clientHeight}}function Pv(e){return e.reduce((t,n)=>Wa(t,sf(n)),cn)}function L5(e){return e.reduce((t,n)=>t+Kv(n),0)}function $5(e){return e.reduce((t,n)=>t+Wv(n),0)}function e1(e,t){if(t===void 0&&(t=As),!e)return;const{top:n,left:l,bottom:a,right:s}=t(e);Iv(e)&&(a<=0||s<=0||n>=window.innerHeight||l>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const B5=[["x",["left","right"],L5],["y",["top","bottom"],$5]];class Bh{constructor(t,n){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const l=$h(n),a=Pv(l);this.rect={...t},this.width=t.width,this.height=t.height;for(const[s,i,r]of B5)for(const c of i)Object.defineProperty(this,c,{get:()=>{const u=r(l),d=a[s]-u;return this.rect[c]+d},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class di{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(n=>{var l;return(l=this.target)==null?void 0:l.removeEventListener(...n)})},this.target=t}add(t,n,l){var a;(a=this.target)==null||a.addEventListener(t,n,l),this.listeners.push([t,n,l])}}function U5(e){const{EventTarget:t}=ft(e);return e instanceof t?e:_s(e)}function Qu(e,t){const n=Math.abs(e.x),l=Math.abs(e.y);return typeof t=="number"?Math.sqrt(n**2+l**2)>t:"x"in t&&"y"in t?n>t.x&&l>t.y:"x"in t?n>t.x:"y"in t?l>t.y:!1}var qt;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(qt||(qt={}));function om(e){e.preventDefault()}function q5(e){e.stopPropagation()}var me;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(me||(me={}));const t1={start:[me.Space,me.Enter],cancel:[me.Esc],end:[me.Space,me.Enter,me.Tab]},Y5=(e,t)=>{let{currentCoordinates:n}=t;switch(e.code){case me.Right:return{...n,x:n.x+25};case me.Left:return{...n,x:n.x-25};case me.Down:return{...n,y:n.y+25};case me.Up:return{...n,y:n.y-25}}};class Uh{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:n}}=t;this.props=t,this.listeners=new di(_s(n)),this.windowListeners=new di(ft(n)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(qt.Resize,this.handleCancel),this.windowListeners.add(qt.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(qt.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:n}=this.props,l=t.node.current;l&&e1(l),n(cn)}handleKeyDown(t){if(Hc(t)){const{active:n,context:l,options:a}=this.props,{keyboardCodes:s=t1,coordinateGetter:i=Y5,scrollBehavior:r="smooth"}=a,{code:c}=t;if(s.end.includes(c)){this.handleEnd(t);return}if(s.cancel.includes(c)){this.handleCancel(t);return}const{collisionRect:u}=l.current,d=u?{x:u.left,y:u.top}:cn;this.referenceCoordinates||(this.referenceCoordinates=d);const f=i(t,{active:n,context:l.current,currentCoordinates:d});if(f){const h=Fo(f,d),p={x:0,y:0},{scrollableAncestors:x}=l.current;for(const S of x){const w=t.code,{isTop:g,isRight:y,isLeft:m,isBottom:v,maxScroll:j,minScroll:E}=Fv(S),M=H5(S),A={x:Math.min(w===me.Right?M.right-M.width/2:M.right,Math.max(w===me.Right?M.left:M.left+M.width/2,f.x)),y:Math.min(w===me.Down?M.bottom-M.height/2:M.bottom,Math.max(w===me.Down?M.top:M.top+M.height/2,f.y))},C=w===me.Right&&!y||w===me.Left&&!m,H=w===me.Down&&!v||w===me.Up&&!g;if(C&&A.x!==f.x){const T=S.scrollLeft+h.x,$=w===me.Right&&T<=j.x||w===me.Left&&T>=E.x;if($&&!h.y){S.scrollTo({left:T,behavior:r});return}$?p.x=S.scrollLeft-T:p.x=w===me.Right?S.scrollLeft-j.x:S.scrollLeft-E.x,p.x&&S.scrollBy({left:-p.x,behavior:r});break}else if(H&&A.y!==f.y){const T=S.scrollTop+h.y,$=w===me.Down&&T<=j.y||w===me.Up&&T>=E.y;if($&&!h.x){S.scrollTo({top:T,behavior:r});return}$?p.y=S.scrollTop-T:p.y=w===me.Down?S.scrollTop-j.y:S.scrollTop-E.y,p.y&&S.scrollBy({top:-p.y,behavior:r});break}}this.handleMove(t,Wa(Fo(f,this.referenceCoordinates),p))}}}handleMove(t,n){const{onMove:l}=this.props;t.preventDefault(),l(n)}handleEnd(t){const{onEnd:n}=this.props;t.preventDefault(),this.detach(),n()}handleCancel(t){const{onCancel:n}=this.props;t.preventDefault(),this.detach(),n()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}Uh.activators=[{eventName:"onKeyDown",handler:(e,t,n)=>{let{keyboardCodes:l=t1,onActivation:a}=t,{active:s}=n;const{code:i}=e.nativeEvent;if(l.start.includes(i)){const r=s.activatorNode.current;return r&&e.target!==r?!1:(e.preventDefault(),a==null||a({event:e.nativeEvent}),!0)}return!1}}];function cm(e){return!!(e&&"distance"in e)}function um(e){return!!(e&&"delay"in e)}class qh{constructor(t,n,l){var a;l===void 0&&(l=U5(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=n;const{event:s}=t,{target:i}=s;this.props=t,this.events=n,this.document=_s(i),this.documentListeners=new di(this.document),this.listeners=new di(l),this.windowListeners=new di(ft(i)),this.initialCoordinates=(a=Po(s))!=null?a:cn,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:n,bypassActivationConstraint:l}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(qt.Resize,this.handleCancel),this.windowListeners.add(qt.DragStart,om),this.windowListeners.add(qt.VisibilityChange,this.handleCancel),this.windowListeners.add(qt.ContextMenu,om),this.documentListeners.add(qt.Keydown,this.handleKeydown),n){if(l!=null&&l({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(um(n)){this.timeoutId=setTimeout(this.handleStart,n.delay),this.handlePending(n);return}if(cm(n)){this.handlePending(n);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,n){const{active:l,onPending:a}=this.props;a(l,t,this.initialCoordinates,n)}handleStart(){const{initialCoordinates:t}=this,{onStart:n}=this.props;t&&(this.activated=!0,this.documentListeners.add(qt.Click,q5,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(qt.SelectionChange,this.removeTextSelection),n(t))}handleMove(t){var n;const{activated:l,initialCoordinates:a,props:s}=this,{onMove:i,options:{activationConstraint:r}}=s;if(!a)return;const c=(n=Po(t))!=null?n:cn,u=Fo(a,c);if(!l&&r){if(cm(r)){if(r.tolerance!=null&&Qu(u,r.tolerance))return this.handleCancel();if(Qu(u,r.distance))return this.handleStart()}if(um(r)&&Qu(u,r.tolerance))return this.handleCancel();this.handlePending(r,u);return}t.cancelable&&t.preventDefault(),i(c)}handleEnd(){const{onAbort:t,onEnd:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleCancel(){const{onAbort:t,onCancel:n}=this.props;this.detach(),this.activated||t(this.props.active),n()}handleKeydown(t){t.code===me.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const V5={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class Yh extends qh{constructor(t){const{event:n}=t,l=_s(n.target);super(t,V5,l)}}Yh.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:l}=t;return!n.isPrimary||n.button!==0?!1:(l==null||l({event:n}),!0)}}];const X5={move:{name:"mousemove"},end:{name:"mouseup"}};var rf;(function(e){e[e.RightClick=2]="RightClick"})(rf||(rf={}));class G5 extends qh{constructor(t){super(t,X5,_s(t.event.target))}}G5.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:l}=t;return n.button===rf.RightClick?!1:(l==null||l({event:n}),!0)}}];const Zu={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class Q5 extends qh{constructor(t){super(t,Zu)}static setup(){return window.addEventListener(Zu.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(Zu.move.name,t)};function t(){}}}Q5.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:n}=e,{onActivation:l}=t;const{touches:a}=n;return a.length>1?!1:(l==null||l({event:n}),!0)}}];var fi;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(fi||(fi={}));var tc;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(tc||(tc={}));function Z5(e){let{acceleration:t,activator:n=fi.Pointer,canScroll:l,draggingRect:a,enabled:s,interval:i=5,order:r=tc.TreeOrder,pointerCoordinates:c,scrollableAncestors:u,scrollableAncestorRects:d,delta:f,threshold:h}=e;const p=K5({delta:f,disabled:!s}),[x,S]=a5(),w=b.useRef({x:0,y:0}),g=b.useRef({x:0,y:0}),y=b.useMemo(()=>{switch(n){case fi.Pointer:return c?{top:c.y,bottom:c.y,left:c.x,right:c.x}:null;case fi.DraggableRect:return a}},[n,a,c]),m=b.useRef(null),v=b.useCallback(()=>{const E=m.current;if(!E)return;const M=w.current.x*g.current.x,A=w.current.y*g.current.y;E.scrollBy(M,A)},[]),j=b.useMemo(()=>r===tc.TreeOrder?[...u].reverse():u,[r,u]);b.useEffect(()=>{if(!s||!u.length||!y){S();return}for(const E of j){if((l==null?void 0:l(E))===!1)continue;const M=u.indexOf(E),A=d[M];if(!A)continue;const{direction:C,speed:H}=O5(E,A,y,t,h);for(const T of["x","y"])p[T][C[T]]||(H[T]=0,C[T]=0);if(H.x>0||H.y>0){S(),m.current=E,x(v,i),w.current=H,g.current=C;return}}w.current={x:0,y:0},g.current={x:0,y:0},S()},[t,v,l,S,s,i,JSON.stringify(y),JSON.stringify(p),x,u,j,d,JSON.stringify(h)])}const I5={x:{[We.Backward]:!1,[We.Forward]:!1},y:{[We.Backward]:!1,[We.Forward]:!1}};function K5(e){let{delta:t,disabled:n}=e;const l=Jo(t);return tr(a=>{if(n||!l||!a)return I5;const s={x:Math.sign(t.x-l.x),y:Math.sign(t.y-l.y)};return{x:{[We.Backward]:a.x[We.Backward]||s.x===-1,[We.Forward]:a.x[We.Forward]||s.x===1},y:{[We.Backward]:a.y[We.Backward]||s.y===-1,[We.Forward]:a.y[We.Forward]||s.y===1}}},[n,t,l])}function W5(e,t){const n=t!=null?e.get(t):void 0,l=n?n.node.current:null;return tr(a=>{var s;return t==null?null:(s=l??a)!=null?s:null},[l,t])}function J5(e,t){return b.useMemo(()=>e.reduce((n,l)=>{const{sensor:a}=l,s=a.activators.map(i=>({eventName:i.eventName,handler:t(i.handler,l)}));return[...n,...s]},[]),[e,t])}var Ti;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Ti||(Ti={}));var of;(function(e){e.Optimized="optimized"})(of||(of={}));const dm=new Map;function F5(e,t){let{dragging:n,dependencies:l,config:a}=t;const[s,i]=b.useState(null),{frequency:r,measure:c,strategy:u}=a,d=b.useRef(e),f=w(),h=Ai(f),p=b.useCallback(function(g){g===void 0&&(g=[]),!h.current&&i(y=>y===null?g:y.concat(g.filter(m=>!y.includes(m))))},[h]),x=b.useRef(null),S=tr(g=>{if(f&&!n)return dm;if(!g||g===dm||d.current!==e||s!=null){const y=new Map;for(let m of e){if(!m)continue;if(s&&s.length>0&&!s.includes(m.id)&&m.rect.current){y.set(m.id,m.rect.current);continue}const v=m.node.current,j=v?new Bh(c(v),v):null;m.rect.current=j,j&&y.set(m.id,j)}return y}return g},[e,s,n,f,c]);return b.useEffect(()=>{d.current=e},[e]),b.useEffect(()=>{f||p()},[n,f]),b.useEffect(()=>{s&&s.length>0&&i(null)},[JSON.stringify(s)]),b.useEffect(()=>{f||typeof r!="number"||x.current!==null||(x.current=setTimeout(()=>{p(),x.current=null},r))},[r,f,p,...l]),{droppableRects:S,measureDroppableContainers:p,measuringScheduled:s!=null};function w(){switch(u){case Ti.Always:return!1;case Ti.BeforeDragging:return n;default:return!n}}}function Vh(e,t){return tr(n=>e?n||(typeof t=="function"?t(e):e):null,[t,e])}function P5(e,t){return Vh(e,t)}function ek(e){let{callback:t,disabled:n}=e;const l=Oc(t),a=b.useMemo(()=>{if(n||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:s}=window;return new s(l)},[l,n]);return b.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function Lc(e){let{callback:t,disabled:n}=e;const l=Oc(t),a=b.useMemo(()=>{if(n||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:s}=window;return new s(l)},[n]);return b.useEffect(()=>()=>a==null?void 0:a.disconnect(),[a]),a}function tk(e){return new Bh(As(e),e)}function fm(e,t,n){t===void 0&&(t=tk);const[l,a]=b.useState(null);function s(){a(c=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=c??n)!=null?u:null}const d=t(e);return JSON.stringify(c)===JSON.stringify(d)?c:d})}const i=ek({callback(c){if(e)for(const u of c){const{type:d,target:f}=u;if(d==="childList"&&f instanceof HTMLElement&&f.contains(e)){s();break}}}}),r=Lc({callback:s});return on(()=>{s(),e?(r==null||r.observe(e),i==null||i.observe(document.body,{childList:!0,subtree:!0})):(r==null||r.disconnect(),i==null||i.disconnect())},[e]),l}function nk(e){const t=Vh(e);return Qv(e,t)}const hm=[];function lk(e){const t=b.useRef(e),n=tr(l=>e?l&&l!==hm&&e&&t.current&&e.parentNode===t.current.parentNode?l:$h(e):hm,[e]);return b.useEffect(()=>{t.current=e},[e]),n}function ak(e){const[t,n]=b.useState(null),l=b.useRef(e),a=b.useCallback(s=>{const i=Gu(s.target);i&&n(r=>r?(r.set(i,sf(i)),new Map(r)):null)},[]);return b.useEffect(()=>{const s=l.current;if(e!==s){i(s);const r=e.map(c=>{const u=Gu(c);return u?(u.addEventListener("scroll",a,{passive:!0}),[u,sf(u)]):null}).filter(c=>c!=null);n(r.length?new Map(r):null),l.current=e}return()=>{i(e),i(s)};function i(r){r.forEach(c=>{const u=Gu(c);u==null||u.removeEventListener("scroll",a)})}},[a,e]),b.useMemo(()=>e.length?t?Array.from(t.values()).reduce((s,i)=>Wa(s,i),cn):Pv(e):cn,[e,t])}function pm(e,t){t===void 0&&(t=[]);const n=b.useRef(null);return b.useEffect(()=>{n.current=null},t),b.useEffect(()=>{const l=e!==cn;l&&!n.current&&(n.current=e),!l&&n.current&&(n.current=null)},[e]),n.current?Fo(e,n.current):cn}function sk(e){b.useEffect(()=>{if(!Rc)return;const t=e.map(n=>{let{sensor:l}=n;return l.setup==null?void 0:l.setup()});return()=>{for(const n of t)n==null||n()}},e.map(t=>{let{sensor:n}=t;return n}))}function ik(e,t){return b.useMemo(()=>e.reduce((n,l)=>{let{eventName:a,handler:s}=l;return n[a]=i=>{s(i,t)},n},{}),[e,t])}function n1(e){return b.useMemo(()=>e?T5(e):null,[e])}const gm=[];function rk(e,t){t===void 0&&(t=As);const[n]=e,l=n1(n?ft(n):null),[a,s]=b.useState(gm);function i(){s(()=>e.length?e.map(c=>Jv(c)?l:new Bh(t(c),c)):gm)}const r=Lc({callback:i});return on(()=>{r==null||r.disconnect(),i(),e.forEach(c=>r==null?void 0:r.observe(c))},[e]),a}function l1(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return er(t)?t:e}function ok(e){let{measure:t}=e;const[n,l]=b.useState(null),a=b.useCallback(u=>{for(const{target:d}of u)if(er(d)){l(f=>{const h=t(d);return f?{...f,width:h.width,height:h.height}:h});break}},[t]),s=Lc({callback:a}),i=b.useCallback(u=>{const d=l1(u);s==null||s.disconnect(),d&&(s==null||s.observe(d)),l(d?t(d):null)},[t,s]),[r,c]=Wo(i);return b.useMemo(()=>({nodeRef:r,rect:n,setRef:c}),[n,r,c])}const ck=[{sensor:Yh,options:{}},{sensor:Uh,options:{}}],uk={current:{}},oo={draggable:{measure:rm},droppable:{measure:rm,strategy:Ti.WhileDragging,frequency:of.Optimized},dragOverlay:{measure:As}};class hi extends Map{get(t){var n;return t!=null&&(n=super.get(t))!=null?n:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:n}=t;return!n})}getNodeFor(t){var n,l;return(n=(l=this.get(t))==null?void 0:l.node.current)!=null?n:void 0}}const dk={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new hi,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:ec},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:oo,measureDroppableContainers:ec,windowRect:null,measuringScheduled:!1},a1={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:ec,draggableNodes:new Map,over:null,measureDroppableContainers:ec},lr=b.createContext(a1),s1=b.createContext(dk);function fk(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new hi}}}function hk(e,t){switch(t.type){case Ge.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Ge.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Ge.DragEnd:case Ge.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Ge.RegisterDroppable:{const{element:n}=t,{id:l}=n,a=new hi(e.droppable.containers);return a.set(l,n),{...e,droppable:{...e.droppable,containers:a}}}case Ge.SetDroppableDisabled:{const{id:n,key:l,disabled:a}=t,s=e.droppable.containers.get(n);if(!s||l!==s.key)return e;const i=new hi(e.droppable.containers);return i.set(n,{...s,disabled:a}),{...e,droppable:{...e.droppable,containers:i}}}case Ge.UnregisterDroppable:{const{id:n,key:l}=t,a=e.droppable.containers.get(n);if(!a||l!==a.key)return e;const s=new hi(e.droppable.containers);return s.delete(n),{...e,droppable:{...e.droppable,containers:s}}}default:return e}}function pk(e){let{disabled:t}=e;const{active:n,activatorEvent:l,draggableNodes:a}=b.useContext(lr),s=Jo(l),i=Jo(n==null?void 0:n.id);return b.useEffect(()=>{if(!t&&!l&&s&&i!=null){if(!Hc(s)||document.activeElement===s.target)return;const r=a.get(i);if(!r)return;const{activatorNode:c,node:u}=r;if(!c.current&&!u.current)return;requestAnimationFrame(()=>{for(const d of[c.current,u.current]){if(!d)continue;const f=r5(d);if(f){f.focus();break}}})}},[l,t,a,i,s]),null}function i1(e,t){let{transform:n,...l}=t;return e!=null&&e.length?e.reduce((a,s)=>s({transform:a,...l}),n):n}function gk(e){return b.useMemo(()=>({draggable:{...oo.draggable,...e==null?void 0:e.draggable},droppable:{...oo.droppable,...e==null?void 0:e.droppable},dragOverlay:{...oo.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function mk(e){let{activeNode:t,measure:n,initialRect:l,config:a=!0}=e;const s=b.useRef(!1),{x:i,y:r}=typeof a=="boolean"?{x:a,y:a}:a;on(()=>{if(!i&&!r||!t){s.current=!1;return}if(s.current||!l)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const d=n(u),f=Qv(d,l);if(i||(f.x=0),r||(f.y=0),s.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const h=Iv(u);h&&h.scrollBy({top:f.y,left:f.x})}},[t,i,r,l,n])}const $c=b.createContext({...cn,scaleX:1,scaleY:1});var fl;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(fl||(fl={}));const xk=b.memo(function(t){var n,l,a,s;let{id:i,accessibility:r,autoScroll:c=!0,children:u,sensors:d=ck,collisionDetection:f=k5,measuring:h,modifiers:p,...x}=t;const S=b.useReducer(hk,void 0,fk),[w,g]=S,[y,m]=h5(),[v,j]=b.useState(fl.Uninitialized),E=v===fl.Initialized,{draggable:{active:M,nodes:A,translate:C},droppable:{containers:H}}=w,T=M!=null?A.get(M):null,$=b.useRef({initial:null,translated:null}),V=b.useMemo(()=>{var Ie;return M!=null?{id:M,data:(Ie=T==null?void 0:T.data)!=null?Ie:uk,rect:$}:null},[M,T]),N=b.useRef(null),[D,k]=b.useState(null),[R,z]=b.useState(null),O=Ai(x,Object.values(x)),Y=nr("DndDescribedBy",i),X=b.useMemo(()=>H.getEnabled(),[H]),L=gk(h),{droppableRects:U,measureDroppableContainers:_,measuringScheduled:B}=F5(X,{dragging:E,dependencies:[C.x,C.y],config:L.droppable}),G=W5(A,M),q=b.useMemo(()=>R?Po(R):null,[R]),Q=lu(),K=P5(G,L.draggable.measure);mk({activeNode:M!=null?A.get(M):null,config:Q.layoutShiftCompensation,initialRect:K,measure:L.draggable.measure});const W=fm(G,L.draggable.measure,K),P=fm(G?G.parentElement:null),J=b.useRef({activatorEvent:null,active:null,activeNode:G,collisionRect:null,collisions:null,droppableRects:U,draggableNodes:A,draggingNode:null,draggingNodeRect:null,droppableContainers:H,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),F=H.getNodeFor((n=J.current.over)==null?void 0:n.id),le=ok({measure:L.dragOverlay.measure}),ae=(l=le.nodeRef.current)!=null?l:G,te=E?(a=le.rect)!=null?a:W:null,ge=!!(le.nodeRef.current&&le.rect),I=nk(ge?null:W),se=n1(ae?ft(ae):null),Re=lk(E?F??G:null),st=rk(Re),Nt=i1(p,{transform:{x:C.x-I.x,y:C.y-I.y,scaleX:1,scaleY:1},activatorEvent:R,active:V,activeNodeRect:W,containerNodeRect:P,draggingNodeRect:te,over:J.current.over,overlayNodeRect:le.rect,scrollableAncestors:Re,scrollableAncestorRects:st,windowRect:se}),Ht=q?Wa(q,C):null,ll=ak(Re),_n=pm(ll),Jt=pm(ll,[W]),Lt=Wa(Nt,_n),An=te?M5(te,Nt):null,Bl=V&&An?f({active:V,collisionRect:An,droppableRects:U,droppableContainers:X,pointerCoordinates:Ht}):null,wa=S5(Bl,"id"),[fn,ur]=b.useState(null),Fc=ge?Nt:Wa(Nt,Jt),Pc=E5(Fc,(s=fn==null?void 0:fn.rect)!=null?s:null,W),Ts=b.useRef(null),dr=b.useCallback((Ie,it)=>{let{sensor:rt,options:hn}=it;if(N.current==null)return;const ht=A.get(N.current);if(!ht)return;const ot=Ie.nativeEvent,$t=new rt({active:N.current,activeNode:ht,event:ot,options:hn,context:J,onAbort(Xe){if(!A.get(Xe))return;const{onDragAbort:Bt}=O.current,Ft={id:Xe};Bt==null||Bt(Ft),y({type:"onDragAbort",event:Ft})},onPending(Xe,pn,Bt,Ft){if(!A.get(Xe))return;const{onDragPending:ql}=O.current,gn={id:Xe,constraint:pn,initialCoordinates:Bt,offset:Ft};ql==null||ql(gn),y({type:"onDragPending",event:gn})},onStart(Xe){const pn=N.current;if(pn==null)return;const Bt=A.get(pn);if(!Bt)return;const{onDragStart:Ft}=O.current,Ul={activatorEvent:ot,active:{id:pn,data:Bt.data,rect:$}};Wl.unstable_batchedUpdates(()=>{Ft==null||Ft(Ul),j(fl.Initializing),g({type:Ge.DragStart,initialCoordinates:Xe,active:pn}),y({type:"onDragStart",event:Ul}),k(Ts.current),z(ot)})},onMove(Xe){g({type:Ge.DragMove,coordinates:Xe})},onEnd:al(Ge.DragEnd),onCancel:al(Ge.DragCancel)});Ts.current=$t;function al(Xe){return async function(){const{active:Bt,collisions:Ft,over:Ul,scrollAdjustedTranslate:ql}=J.current;let gn=null;if(Bt&&ql){const{cancelDrop:Yl}=O.current;gn={activatorEvent:ot,active:Bt,collisions:Ft,delta:ql,over:Ul},Xe===Ge.DragEnd&&typeof Yl=="function"&&await Promise.resolve(Yl(gn))&&(Xe=Ge.DragCancel)}N.current=null,Wl.unstable_batchedUpdates(()=>{g({type:Xe}),j(fl.Uninitialized),ur(null),k(null),z(null),Ts.current=null;const Yl=Xe===Ge.DragEnd?"onDragEnd":"onDragCancel";if(gn){const zs=O.current[Yl];zs==null||zs(gn),y({type:Yl,event:gn})}})}}},[A]),eu=b.useCallback((Ie,it)=>(rt,hn)=>{const ht=rt.nativeEvent,ot=A.get(hn);if(N.current!==null||!ot||ht.dndKit||ht.defaultPrevented)return;const $t={active:ot};Ie(rt,it.options,$t)===!0&&(ht.dndKit={capturedBy:it.sensor},N.current=hn,dr(rt,it))},[A,dr]),fr=J5(d,eu);sk(d),on(()=>{W&&v===fl.Initializing&&j(fl.Initialized)},[W,v]),b.useEffect(()=>{const{onDragMove:Ie}=O.current,{active:it,activatorEvent:rt,collisions:hn,over:ht}=J.current;if(!it||!rt)return;const ot={active:it,activatorEvent:rt,collisions:hn,delta:{x:Lt.x,y:Lt.y},over:ht};Wl.unstable_batchedUpdates(()=>{Ie==null||Ie(ot),y({type:"onDragMove",event:ot})})},[Lt.x,Lt.y]),b.useEffect(()=>{const{active:Ie,activatorEvent:it,collisions:rt,droppableContainers:hn,scrollAdjustedTranslate:ht}=J.current;if(!Ie||N.current==null||!it||!ht)return;const{onDragOver:ot}=O.current,$t=hn.get(wa),al=$t&&$t.rect.current?{id:$t.id,rect:$t.rect.current,data:$t.data,disabled:$t.disabled}:null,Xe={active:Ie,activatorEvent:it,collisions:rt,delta:{x:ht.x,y:ht.y},over:al};Wl.unstable_batchedUpdates(()=>{ur(al),ot==null||ot(Xe),y({type:"onDragOver",event:Xe})})},[wa]),on(()=>{J.current={activatorEvent:R,active:V,activeNode:G,collisionRect:An,collisions:Bl,droppableRects:U,draggableNodes:A,draggingNode:ae,draggingNodeRect:te,droppableContainers:H,over:fn,scrollableAncestors:Re,scrollAdjustedTranslate:Lt},$.current={initial:te,translated:An}},[V,G,Bl,An,A,ae,te,U,H,fn,Re,Lt]),Z5({...Q,delta:C,draggingRect:An,pointerCoordinates:Ht,scrollableAncestors:Re,scrollableAncestorRects:st});const tu=b.useMemo(()=>({active:V,activeNode:G,activeNodeRect:W,activatorEvent:R,collisions:Bl,containerNodeRect:P,dragOverlay:le,draggableNodes:A,droppableContainers:H,droppableRects:U,over:fn,measureDroppableContainers:_,scrollableAncestors:Re,scrollableAncestorRects:st,measuringConfiguration:L,measuringScheduled:B,windowRect:se}),[V,G,W,R,Bl,P,le,A,H,U,fn,_,Re,st,L,B,se]),nu=b.useMemo(()=>({activatorEvent:R,activators:fr,active:V,activeNodeRect:W,ariaDescribedById:{draggable:Y},dispatch:g,draggableNodes:A,over:fn,measureDroppableContainers:_}),[R,fr,V,W,g,Y,A,fn,_]);return Me.createElement(Gv.Provider,{value:m},Me.createElement(lr.Provider,{value:nu},Me.createElement(s1.Provider,{value:tu},Me.createElement($c.Provider,{value:Pc},u)),Me.createElement(pk,{disabled:(r==null?void 0:r.restoreFocus)===!1})),Me.createElement(m5,{...r,hiddenTextDescribedById:Y}));function lu(){const Ie=(D==null?void 0:D.autoScrollEnabled)===!1,it=typeof c=="object"?c.enabled===!1:c===!1,rt=E&&!Ie&&!it;return typeof c=="object"?{...c,enabled:rt}:{enabled:rt}}}),yk=b.createContext(null),mm="button",vk="Draggable";function bk(e){let{id:t,data:n,disabled:l=!1,attributes:a}=e;const s=nr(vk),{activators:i,activatorEvent:r,active:c,activeNodeRect:u,ariaDescribedById:d,draggableNodes:f,over:h}=b.useContext(lr),{role:p=mm,roleDescription:x="draggable",tabIndex:S=0}=a??{},w=(c==null?void 0:c.id)===t,g=b.useContext(w?$c:yk),[y,m]=Wo(),[v,j]=Wo(),E=ik(i,t),M=Ai(n);on(()=>(f.set(t,{id:t,key:s,node:y,activatorNode:v,data:M}),()=>{const C=f.get(t);C&&C.key===s&&f.delete(t)}),[f,t]);const A=b.useMemo(()=>({role:p,tabIndex:S,"aria-disabled":l,"aria-pressed":w&&p===mm?!0:void 0,"aria-roledescription":x,"aria-describedby":d.draggable}),[l,p,S,w,x,d.draggable]);return{active:c,activatorEvent:r,activeNodeRect:u,attributes:A,isDragging:w,listeners:l?void 0:E,node:y,over:h,setNodeRef:m,setActivatorNodeRef:j,transform:g}}function r1(){return b.useContext(s1)}const wk="Droppable",Sk={timeout:25};function o1(e){let{data:t,disabled:n=!1,id:l,resizeObserverConfig:a}=e;const s=nr(wk),{active:i,dispatch:r,over:c,measureDroppableContainers:u}=b.useContext(lr),d=b.useRef({disabled:n}),f=b.useRef(!1),h=b.useRef(null),p=b.useRef(null),{disabled:x,updateMeasurementsFor:S,timeout:w}={...Sk,...a},g=Ai(S??l),y=b.useCallback(()=>{if(!f.current){f.current=!0;return}p.current!=null&&clearTimeout(p.current),p.current=setTimeout(()=>{u(Array.isArray(g.current)?g.current:[g.current]),p.current=null},w)},[w]),m=Lc({callback:y,disabled:x||!i}),v=b.useCallback((A,C)=>{m&&(C&&(m.unobserve(C),f.current=!1),A&&m.observe(A))},[m]),[j,E]=Wo(v),M=Ai(t);return b.useEffect(()=>{!m||!j.current||(m.disconnect(),f.current=!1,m.observe(j.current))},[j,m]),b.useEffect(()=>(r({type:Ge.RegisterDroppable,element:{id:l,key:s,disabled:n,node:j,rect:h,data:M}}),()=>r({type:Ge.UnregisterDroppable,key:s,id:l})),[l]),b.useEffect(()=>{n!==d.current.disabled&&(r({type:Ge.SetDroppableDisabled,id:l,key:s,disabled:n}),d.current.disabled=n)},[l,s,n,r]),{active:i,rect:h,isOver:(c==null?void 0:c.id)===l,node:j,over:c,setNodeRef:E}}function Nk(e){let{animation:t,children:n}=e;const[l,a]=b.useState(null),[s,i]=b.useState(null),r=Jo(n);return!n&&!l&&r&&a(r),on(()=>{if(!s)return;const c=l==null?void 0:l.key,u=l==null?void 0:l.props.id;if(c==null||u==null){a(null);return}Promise.resolve(t(u,s)).then(()=>{a(null)})},[t,l,s]),Me.createElement(Me.Fragment,null,n,l?b.cloneElement(l,{ref:i}):null)}const jk={x:0,y:0,scaleX:1,scaleY:1};function kk(e){let{children:t}=e;return Me.createElement(lr.Provider,{value:a1},Me.createElement($c.Provider,{value:jk},t))}const Ek={position:"fixed",touchAction:"none"},Ck=e=>Hc(e)?"transform 250ms ease":void 0,Mk=b.forwardRef((e,t)=>{let{as:n,activatorEvent:l,adjustScale:a,children:s,className:i,rect:r,style:c,transform:u,transition:d=Ck}=e;if(!r)return null;const f=a?u:{...u,scaleX:1,scaleY:1},h={...Ek,width:r.width,height:r.height,top:r.top,left:r.left,transform:Hl.Transform.toString(f),transformOrigin:a&&l?v5(l,r):void 0,transition:typeof d=="function"?d(l):d,...c};return Me.createElement(n,{className:i,style:h,ref:t},s)}),_k=e=>t=>{let{active:n,dragOverlay:l}=t;const a={},{styles:s,className:i}=e;if(s!=null&&s.active)for(const[r,c]of Object.entries(s.active))c!==void 0&&(a[r]=n.node.style.getPropertyValue(r),n.node.style.setProperty(r,c));if(s!=null&&s.dragOverlay)for(const[r,c]of Object.entries(s.dragOverlay))c!==void 0&&l.node.style.setProperty(r,c);return i!=null&&i.active&&n.node.classList.add(i.active),i!=null&&i.dragOverlay&&l.node.classList.add(i.dragOverlay),function(){for(const[c,u]of Object.entries(a))n.node.style.setProperty(c,u);i!=null&&i.active&&n.node.classList.remove(i.active)}},Ak=e=>{let{transform:{initial:t,final:n}}=e;return[{transform:Hl.Transform.toString(t)},{transform:Hl.Transform.toString(n)}]},Tk={duration:250,easing:"ease",keyframes:Ak,sideEffects:_k({styles:{active:{opacity:"0"}}})};function zk(e){let{config:t,draggableNodes:n,droppableContainers:l,measuringConfiguration:a}=e;return Oc((s,i)=>{if(t===null)return;const r=n.get(s);if(!r)return;const c=r.node.current;if(!c)return;const u=l1(i);if(!u)return;const{transform:d}=ft(i).getComputedStyle(i),f=Zv(d);if(!f)return;const h=typeof t=="function"?t:Dk(t);return e1(c,a.draggable.measure),h({active:{id:s,data:r.data,node:c,rect:a.draggable.measure(c)},draggableNodes:n,dragOverlay:{node:i,rect:a.dragOverlay.measure(u)},droppableContainers:l,measuringConfiguration:a,transform:f})})}function Dk(e){const{duration:t,easing:n,sideEffects:l,keyframes:a}={...Tk,...e};return s=>{let{active:i,dragOverlay:r,transform:c,...u}=s;if(!t)return;const d={x:r.rect.left-i.rect.left,y:r.rect.top-i.rect.top},f={scaleX:c.scaleX!==1?i.rect.width*c.scaleX/r.rect.width:1,scaleY:c.scaleY!==1?i.rect.height*c.scaleY/r.rect.height:1},h={x:c.x-d.x,y:c.y-d.y,...f},p=a({...u,active:i,dragOverlay:r,transform:{initial:c,final:h}}),[x]=p,S=p[p.length-1];if(JSON.stringify(x)===JSON.stringify(S))return;const w=l==null?void 0:l({active:i,dragOverlay:r,...u}),g=r.node.animate(p,{duration:t,easing:n,fill:"forwards"});return new Promise(y=>{g.onfinish=()=>{w==null||w(),y()}})}}let xm=0;function Rk(e){return b.useMemo(()=>{if(e!=null)return xm++,xm},[e])}const Ok=Me.memo(e=>{let{adjustScale:t=!1,children:n,dropAnimation:l,style:a,transition:s,modifiers:i,wrapperElement:r="div",className:c,zIndex:u=999}=e;const{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggableNodes:x,droppableContainers:S,dragOverlay:w,over:g,measuringConfiguration:y,scrollableAncestors:m,scrollableAncestorRects:v,windowRect:j}=r1(),E=b.useContext($c),M=Rk(f==null?void 0:f.id),A=i1(i,{activatorEvent:d,active:f,activeNodeRect:h,containerNodeRect:p,draggingNodeRect:w.rect,over:g,overlayNodeRect:w.rect,scrollableAncestors:m,scrollableAncestorRects:v,transform:E,windowRect:j}),C=Vh(h),H=zk({config:l,draggableNodes:x,droppableContainers:S,measuringConfiguration:y}),T=C?w.setRef:void 0;return Me.createElement(kk,null,Me.createElement(Nk,{animation:H},f&&M?Me.createElement(Mk,{key:M,id:f.id,ref:T,as:r,activatorEvent:d,adjustScale:t,className:c,transition:s,rect:C,style:{zIndex:u,...a},transform:A},n):null))});function c1(e,t,n){const l=e.slice();return l.splice(n<0?l.length+n:n,0,l.splice(t,1)[0]),l}function Hk(e,t){return e.reduce((n,l,a)=>{const s=t.get(l);return s&&(n[a]=s),n},Array(e.length))}function Rr(e){return e!==null&&e>=0}function Lk(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function $k(e){return typeof e=="boolean"?{draggable:e,droppable:e}:e}const u1=e=>{let{rects:t,activeIndex:n,overIndex:l,index:a}=e;const s=c1(t,l,n),i=t[a],r=s[a];return!r||!i?null:{x:r.left-i.left,y:r.top-i.top,scaleX:r.width/i.width,scaleY:r.height/i.height}},Or={scaleX:1,scaleY:1},Bk=e=>{var t;let{activeIndex:n,activeNodeRect:l,index:a,rects:s,overIndex:i}=e;const r=(t=s[n])!=null?t:l;if(!r)return null;if(a===n){const u=s[i];return u?{x:0,y:n<i?u.top+u.height-(r.top+r.height):u.top-r.top,...Or}:null}const c=Uk(s,a,n);return a>n&&a<=i?{x:0,y:-r.height-c,...Or}:a<n&&a>=i?{x:0,y:r.height+c,...Or}:{x:0,y:0,...Or}};function Uk(e,t,n){const l=e[t],a=e[t-1],s=e[t+1];return l?n<t?a?l.top-(a.top+a.height):s?s.top-(l.top+l.height):0:s?s.top-(l.top+l.height):a?l.top-(a.top+a.height):0:0}const d1="Sortable",f1=Me.createContext({activeIndex:-1,containerId:d1,disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:u1,disabled:{draggable:!1,droppable:!1}});function qk(e){let{children:t,id:n,items:l,strategy:a=u1,disabled:s=!1}=e;const{active:i,dragOverlay:r,droppableRects:c,over:u,measureDroppableContainers:d}=r1(),f=nr(d1,n),h=r.rect!==null,p=b.useMemo(()=>l.map(E=>typeof E=="object"&&"id"in E?E.id:E),[l]),x=i!=null,S=i?p.indexOf(i.id):-1,w=u?p.indexOf(u.id):-1,g=b.useRef(p),y=!Lk(p,g.current),m=w!==-1&&S===-1||y,v=$k(s);on(()=>{y&&x&&d(p)},[y,p,x,d]),b.useEffect(()=>{g.current=p},[p]);const j=b.useMemo(()=>({activeIndex:S,containerId:f,disabled:v,disableTransforms:m,items:p,overIndex:w,useDragOverlay:h,sortedRects:Hk(p,c),strategy:a}),[S,f,v.draggable,v.droppable,m,p,w,c,h,a]);return Me.createElement(f1.Provider,{value:j},t)}const Yk=e=>{let{id:t,items:n,activeIndex:l,overIndex:a}=e;return c1(n,l,a).indexOf(t)},Vk=e=>{let{containerId:t,isSorting:n,wasDragging:l,index:a,items:s,newIndex:i,previousItems:r,previousContainerId:c,transition:u}=e;return!u||!l||r!==s&&a===i?!1:n?!0:i!==a&&t===c},Xk={duration:200,easing:"ease"},h1="transform",Gk=Hl.Transition.toString({property:h1,duration:0,easing:"linear"}),Qk={roleDescription:"sortable"};function Zk(e){let{disabled:t,index:n,node:l,rect:a}=e;const[s,i]=b.useState(null),r=b.useRef(n);return on(()=>{if(!t&&n!==r.current&&l.current){const c=a.current;if(c){const u=As(l.current,{ignoreTransform:!0}),d={x:c.left-u.left,y:c.top-u.top,scaleX:c.width/u.width,scaleY:c.height/u.height};(d.x||d.y)&&i(d)}}n!==r.current&&(r.current=n)},[t,n,l,a]),b.useEffect(()=>{s&&i(null)},[s]),s}function Ik(e){let{animateLayoutChanges:t=Vk,attributes:n,disabled:l,data:a,getNewIndex:s=Yk,id:i,strategy:r,resizeObserverConfig:c,transition:u=Xk}=e;const{items:d,containerId:f,activeIndex:h,disabled:p,disableTransforms:x,sortedRects:S,overIndex:w,useDragOverlay:g,strategy:y}=b.useContext(f1),m=Kk(l,p),v=d.indexOf(i),j=b.useMemo(()=>({sortable:{containerId:f,index:v,items:d},...a}),[f,a,v,d]),E=b.useMemo(()=>d.slice(d.indexOf(i)),[d,i]),{rect:M,node:A,isOver:C,setNodeRef:H}=o1({id:i,data:j,disabled:m.droppable,resizeObserverConfig:{updateMeasurementsFor:E,...c}}),{active:T,activatorEvent:$,activeNodeRect:V,attributes:N,setNodeRef:D,listeners:k,isDragging:R,over:z,setActivatorNodeRef:O,transform:Y}=bk({id:i,data:j,attributes:{...Qk,...n},disabled:m.draggable}),X=l5(H,D),L=!!T,U=L&&!x&&Rr(h)&&Rr(w),_=!g&&R,B=_&&U?Y:null,q=U?B??(r??y)({rects:S,activeNodeRect:V,activeIndex:h,overIndex:w,index:v}):null,Q=Rr(h)&&Rr(w)?s({id:i,items:d,activeIndex:h,overIndex:w}):v,K=T==null?void 0:T.id,W=b.useRef({activeId:K,items:d,newIndex:Q,containerId:f}),P=d!==W.current.items,J=t({active:T,containerId:f,isDragging:R,isSorting:L,id:i,index:v,items:d,newIndex:W.current.newIndex,previousItems:W.current.items,previousContainerId:W.current.containerId,transition:u,wasDragging:W.current.activeId!=null}),F=Zk({disabled:!J,index:v,node:A,rect:M});return b.useEffect(()=>{L&&W.current.newIndex!==Q&&(W.current.newIndex=Q),f!==W.current.containerId&&(W.current.containerId=f),d!==W.current.items&&(W.current.items=d)},[L,Q,f,d]),b.useEffect(()=>{if(K===W.current.activeId)return;if(K!=null&&W.current.activeId==null){W.current.activeId=K;return}const ae=setTimeout(()=>{W.current.activeId=K},50);return()=>clearTimeout(ae)},[K]),{active:T,activeIndex:h,attributes:N,data:j,rect:M,index:v,newIndex:Q,items:d,isOver:C,isSorting:L,isDragging:R,listeners:k,node:A,overIndex:w,over:z,setNodeRef:X,setActivatorNodeRef:O,setDroppableNodeRef:H,setDraggableNodeRef:D,transform:F??q,transition:le()};function le(){if(F||P&&W.current.newIndex===v)return Gk;if(!(_&&!Hc($)||!u)&&(L||J))return Hl.Transition.toString({...u,property:h1})}}function Kk(e,t){var n,l;return typeof e=="boolean"?{draggable:e,droppable:!1}:{draggable:(n=e==null?void 0:e.draggable)!=null?n:t.draggable,droppable:(l=e==null?void 0:e.droppable)!=null?l:t.droppable}}me.Down,me.Right,me.Up,me.Left;const Xh=[{id:"backlog",label:"Backlog",statuses:["backlog"],defaultStatus:"backlog"},{id:"todo",label:"To Do",statuses:["todo","pending"],defaultStatus:"todo"},{id:"in_progress",label:"In Progress",statuses:["in_progress","executing"],defaultStatus:"in_progress"},{id:"done",label:"Done",statuses:["done","completed"],defaultStatus:"done"}],ym=new Map(Xh.map(e=>[e.id,e]));function co(e){for(const t of Xh)if(t.statuses.includes(e))return t.id;return null}function Wk(e){const t=new Map;for(const n of e){const l=co(n.status);l&&t.set(n.id,l)}return t}const vm=["canceled","failed"],Jk={critical:"var(--red)",high:"var(--yellow)",medium:"var(--muted)",low:"var(--green)"},Gh={human:"H",agent:"A",notify:"N"};function Fk({task:e}){const t=Jk[e.priority]||"var(--muted)",n=e.scheduled_at?new Date(e.scheduled_at).toLocaleDateString(void 0,{month:"short",day:"numeric"}):null;return o.jsxs("div",{className:"glass-card rounded-xl p-3 mb-2 w-[256px] select-none",children:[o.jsx("div",{className:"flex items-center justify-between mb-1.5",children:o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 12 12",fill:"currentColor",className:"text-muted2",children:[o.jsx("circle",{cx:"3",cy:"2",r:"1"}),o.jsx("circle",{cx:"9",cy:"2",r:"1"}),o.jsx("circle",{cx:"3",cy:"6",r:"1"}),o.jsx("circle",{cx:"9",cy:"6",r:"1"}),o.jsx("circle",{cx:"3",cy:"10",r:"1"}),o.jsx("circle",{cx:"9",cy:"10",r:"1"})]}),o.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:t}})]})}),o.jsx("div",{className:"text-[12.5px] font-medium text-fg mb-1.5 leading-snug line-clamp-3",children:e.title}),o.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[o.jsxs("span",{className:"text-[9px] font-mono font-bold px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:["[",Gh[e.mode]||"?","]"]}),e.scope==="project"&&o.jsx("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:"proj"}),n&&o.jsx("span",{className:"text-[9px] text-muted2",children:n}),e.tags.slice(0,3).map(l=>o.jsx("span",{className:"leather-tag text-[9px] px-1.5 py-0.5 rounded-full text-muted",children:l},l)),e.tags.length>3&&o.jsxs("span",{className:"text-[9px] text-muted2",children:["+",e.tags.length-3]})]})]})}function Pk({task:e,onEdit:t,onRemove:n}){const{attributes:l,listeners:a,setNodeRef:s,transform:i,isDragging:r}=Ik({id:e.id,animateLayoutChanges:()=>!1}),c={transform:Hl.Transform.toString(i),opacity:r?0:1};return o.jsxs("div",{ref:s,style:c,className:"cursor-grab active:cursor-grabbing",...l,...a,onClick:()=>t(e),children:[o.jsxs("div",{className:"flex items-center justify-between mb-2",children:[o.jsx("div",{}),o.jsx("button",{onClick:u=>{u.stopPropagation(),n(e.id)},className:"text-muted2 hover:text-red transition-colors p-0.5 rounded cursor-pointer",title:"Delete task",children:o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsx("div",{className:"text-[12.5px] font-medium text-fg mb-1.5 leading-snug line-clamp-3 glass-card rounded-xl p-3 mb-2",children:e.title}),o.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap px-3 pb-2",children:[o.jsxs("span",{className:"text-[9px] font-mono font-bold px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:["[",Gh[e.mode]||"?","]"]}),e.scope==="project"&&o.jsx("span",{className:"text-[9px] font-mono px-1 py-0.5 rounded leading-none",style:{color:"var(--muted)"},children:"proj"}),e.scheduled_at&&o.jsx("span",{className:"text-[9px] text-muted2",children:new Date(e.scheduled_at).toLocaleDateString(void 0,{month:"short",day:"numeric"})}),e.tags.slice(0,3).map(u=>o.jsx("span",{className:"leather-tag text-[9px] px-1.5 py-0.5 rounded-full text-muted",children:u},u)),e.tags.length>3&&o.jsxs("span",{className:"text-[9px] text-muted2",children:["+",e.tags.length-3]})]})]})}function e3({column:e,tasks:t,isDragging:n,onEdit:l,onRemove:a,className:s=""}){const{setNodeRef:i,isOver:r}=o1({id:e.id}),c=function(u){return o.jsx(Pk,{task:u,onEdit:l,onRemove:a},u.id)};return o.jsxs("div",{className:`flex flex-col h-full min-w-[260px] sm:flex-1 ${s}`,children:[o.jsx("div",{className:"flex items-center justify-between px-3 py-2.5 shrink-0",children:o.jsxs("div",{className:"flex items-center gap-2",children:[o.jsx("span",{className:"text-[12px] font-semibold font-display",style:{color:"var(--gold)"},children:e.label}),o.jsx("span",{className:"text-[10px] font-mono text-muted bg-s3 px-1.5 py-0.5 rounded",children:t.length})]})}),o.jsxs("div",{ref:i,className:"flex-1 px-2 pb-2 min-h-0 relative transition-colors duration-150 rounded-xl kanban-column-scroll",style:{overflowY:n?"visible":"auto",background:r?"color-mix(in srgb, var(--gold) 8%, transparent)":"transparent"},children:[t.map(c),t.length===0&&o.jsx("div",{className:"text-center py-8 text-[11px] text-muted2 min-h-[120px] flex items-center justify-center",children:"No tasks"})]})]})}function bm({task:e,onSave:t,onClose:n}){const[l,a]=b.useState((e==null?void 0:e.title)??""),[s,i]=b.useState((e==null?void 0:e.description)??""),[r,c]=b.useState((e==null?void 0:e.priority)??"medium"),[u,d]=b.useState((e==null?void 0:e.mode)??"human"),[f,h]=b.useState((e==null?void 0:e.scope)??"personal"),[p,x]=b.useState((e==null?void 0:e.status)??"backlog"),[S,w]=b.useState(()=>{if(e!=null&&e.scheduled_at){const v=new Date(e.scheduled_at),j=v.getTimezoneOffset()*6e4;return new Date(v.getTime()-j).toISOString().slice(0,16)}return""}),[g,y]=b.useState((e==null?void 0:e.tags.join(", "))??""),m=()=>{l.trim()&&t({title:l.trim(),description:s.trim(),priority:r,mode:u,scope:f,status:p,tags:g.split(",").map(v=>v.trim()).filter(Boolean),scheduled_at:S?new Date(S).getTime():void 0})};return o.jsx("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center p-4 animate-fadeIn",style:{background:"rgba(10, 8, 5, 0.7)",backdropFilter:"blur(8px)"},onClick:n,children:o.jsxs("div",{className:"w-full max-w-[420px] rounded-2xl shadow-2xl animate-scaleIn select-none glass-card p-5",onClick:v=>v.stopPropagation(),children:[o.jsxs("div",{className:"flex items-center justify-between pb-3 mb-4",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("span",{className:"font-bold text-[13.5px] font-display",style:{color:"var(--cream)"},children:e?"Edit Task":"New Task"}),o.jsx("button",{onClick:n,className:"text-muted hover:text-fg transition-colors cursor-pointer",children:o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsxs("div",{className:"space-y-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Title"}),o.jsx("input",{type:"text",value:l,onChange:v=>a(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none transition-colors focus:ring-1 focus:ring-gold/30",style:{background:"var(--s2)",border:"1px solid var(--b1)"},autoFocus:!0})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Description"}),o.jsx("textarea",{value:s,onChange:v=>i(v.target.value),rows:2,className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none resize-none transition-colors focus:ring-1 focus:ring-gold/30 scrollbar-thin",style:{background:"var(--s2)",border:"1px solid var(--b1)"}})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Priority"}),o.jsxs("select",{value:r,onChange:v=>c(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"low",children:"Low"}),o.jsx("option",{value:"medium",children:"Medium"}),o.jsx("option",{value:"high",children:"High"}),o.jsx("option",{value:"critical",children:"Critical"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Mode"}),o.jsxs("select",{value:u,onChange:v=>d(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"human",children:"Human"}),o.jsx("option",{value:"agent",children:"Agent"}),o.jsx("option",{value:"notify",children:"Notify"})]})]})]}),o.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Scope"}),o.jsxs("select",{value:f,onChange:v=>h(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"personal",children:"Personal"}),o.jsx("option",{value:"project",children:"Project"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Status"}),o.jsxs("select",{value:p,onChange:v=>x(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsx("option",{value:"backlog",children:"Backlog"}),o.jsx("option",{value:"todo",children:"To Do"}),o.jsx("option",{value:"in_progress",children:"In Progress"}),o.jsx("option",{value:"done",children:"Done"})]})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Scheduled (optional)"}),o.jsx("input",{type:"datetime-local",value:S,onChange:v=>w(v.target.value),className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b1)"}})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[10px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Tags (comma-separated)"}),o.jsx("input",{type:"text",value:g,onChange:v=>y(v.target.value),placeholder:"bug, feature, urgent",className:"w-full px-3 py-2 rounded-lg text-[12.5px] text-fg outline-none transition-colors focus:ring-1 focus:ring-gold/30",style:{background:"var(--s2)",border:"1px solid var(--b1)"}})]})]}),o.jsxs("div",{className:"flex gap-2 mt-5",children:[o.jsx("button",{onClick:n,className:"flex-1 py-2.5 px-4 rounded-xl text-[12px] font-semibold cursor-pointer transition-all duration-150 active:scale-[0.98]",style:{background:"var(--s3)",border:"1px solid var(--b1)",color:"var(--muted)"},children:"Cancel"}),o.jsx("button",{onClick:m,disabled:!l.trim(),className:"flex-1 btn-gold py-2.5 px-4 rounded-xl text-[12px] font-semibold cursor-pointer active:scale-[0.98] disabled:opacity-50 disabled:cursor-not-allowed",children:e?"Save":"Create"})]})]})})}function t3({rpc:e,className:t}){const{ws:n}=Cn(),[l,a]=b.useState([]),[s,i]=b.useState(!0),[r,c]=b.useState(null),[u,d]=b.useState(!1),[f,h]=b.useState(!1),[p,x]=b.useState("all"),[S,w]=b.useState("all"),[g,y]=b.useState("all"),[m,v]=b.useState(!1),j=b.useRef(null),[E,M]=b.useState({top:0,left:0}),[A,C]=b.useState(null),H=b.useCallback(async()=>{if(e)try{const _={};p!=="all"&&(_.mode=p),S!=="all"&&(_.priority=S),g!=="all"&&(_.scope=g);const B=await e.todoList(Object.keys(_).length?_:void 0);a(Array.isArray(B)?B:[])}catch(_){console.error("[Kanban] Failed to fetch tasks:",_)}finally{i(!1)}},[e,p,S,g]);b.useEffect(()=>{H()},[H]),b.useEffect(()=>{if(!n)return;const _=()=>H(),B=n.on("todo-changed",_),G=n.on("cron-task-fired",_);return()=>{B(),G()}},[n,H]),b.useEffect(()=>{if(!m)return;const _=B=>{B.target.closest("[data-filter-dropdown]")||v(!1)};return document.addEventListener("click",_),()=>document.removeEventListener("click",_)},[m]);const T=b.useMemo(()=>{const _={backlog:[],todo:[],in_progress:[],done:[]};for(const B of l){if(B.mode==="notify")continue;const G=co(B.status);G&&_[G]&&_[G].push(B)}return Object.values(_).forEach(B=>B.sort((G,q)=>G.order-q.order)),_},[l]),$=b.useMemo(()=>l.filter(_=>vm.includes(_.status)),[l]),V=b.useMemo(()=>Wk(l),[l]),N=b.useMemo(()=>{const _={backlog:[],todo:[],in_progress:[],done:[]};for(const B of l){if(B.mode==="notify")continue;const G=co(B.status);G&&!vm.includes(B.status)&&_[G].push(B.id)}return _},[l]),D=x5(sm(Yh,{activationConstraint:{delay:250,tolerance:5}}),sm(Uh)),[k,R]=b.useState(!1),z=b.useCallback(_=>{R(!0),C(String(_.active.id))},[]),O=b.useCallback(()=>{R(!1),C(null)},[]),Y=b.useCallback(async _=>{const{active:B,over:G}=_;if(!G||!e){R(!1),C(null);return}const q=String(B.id),Q=String(G.id),K=l.find(ae=>ae.id===q);if(!K){R(!1),C(null);return}if(!V.get(q)){R(!1),C(null);return}let P=K.status;const J=ym.get(Q);if(J)P=J.defaultStatus;else{const ae=l.find(te=>te.id===Q);if(ae){const te=co(ae.status);te&&(P=ym.get(te).defaultStatus)}}if(K.status!==P){const ae=K.status;a(te=>te.map(ge=>ge.id===q?{...ge,status:P}:ge));try{await e.todoUpdate({id:q,status:P})}catch{a(te=>te.map(ge=>ge.id===q?{...ge,status:ae}:ge))}}else try{await e.todoUpdate({id:q})}catch{}C(null),R(!1)},[e,l,V]),X=b.useCallback(async _=>{e&&(await e.todoCreate({title:(_.title??"").trim(),description:_.description,priority:_.priority??"medium",mode:_.mode??"human",scope:_.scope??"personal",status:_.status??"backlog",tags:_.tags,scheduled_at:_.scheduled_at}),h(!1))},[e]),L=b.useCallback(async _=>{!e||!r||(await e.todoUpdate({id:r.id,..._}),c(null))},[e,r]),U=b.useCallback(async _=>{e&&await e.todoRemove(_)},[e]);return s?o.jsx("div",{className:t||"",children:o.jsx("div",{className:"flex items-center justify-center h-full text-muted text-xs",children:"Loading tasks..."})}):o.jsxs("div",{className:`flex flex-col h-full ${t||""}`,children:[o.jsxs("div",{className:"flex items-center gap-3 px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("h2",{className:"text-[13px] font-semibold font-display",style:{color:"var(--cream)"},children:"Tasks"}),o.jsxs("div",{className:"relative","data-filter-dropdown":!0,children:[o.jsx("button",{ref:j,onClick:()=>{if(!m&&j.current){const _=j.current.getBoundingClientRect(),B=200;let G=_.left;G+B>window.innerWidth-8&&(G=window.innerWidth-B-8),M({top:_.bottom+4,left:Math.max(G,8)})}v(!m)},className:"p-1.5 rounded-lg cursor-pointer transition-colors",style:{background:p!=="all"||S!=="all"||g!=="all"?"var(--s3)":"transparent",border:"1px solid var(--b2)",color:"var(--muted)"},children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o.jsx("polygon",{points:"22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"})})}),m&&Wl.createPortal(o.jsxs("div",{"data-filter-dropdown":!0,className:"fixed rounded-xl shadow-2xl p-3 space-y-2.5 w-[200px]",style:{top:E.top,left:E.left,background:"var(--s1)",border:"1px solid var(--b1)",zIndex:9999},children:[o.jsxs("div",{children:[o.jsx("label",{className:"text-[9px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Mode"}),o.jsx("div",{className:"flex rounded-lg overflow-hidden",style:{border:"1px solid var(--b2)"},children:["all","human","agent","notify"].map(_=>o.jsx("button",{onClick:()=>{x(_),v(!1)},className:"flex-1 px-1.5 py-1 text-[10px] font-mono cursor-pointer transition-all",style:{color:p===_?"var(--gold)":"var(--muted)",background:p===_?"var(--s3)":"transparent"},children:_==="all"?"All":_.charAt(0).toUpperCase()+_.slice(1)},_))})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[9px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Priority"}),o.jsxs("select",{value:S,onChange:_=>{w(_.target.value),v(!1)},className:"w-full px-2 py-1 rounded-lg text-[11px] font-mono outline-none cursor-pointer",style:{background:"var(--s2)",border:"1px solid var(--b2)",color:"var(--muted)"},children:[o.jsx("option",{value:"all",children:"All"}),o.jsx("option",{value:"low",children:"Low"}),o.jsx("option",{value:"medium",children:"Medium"}),o.jsx("option",{value:"high",children:"High"}),o.jsx("option",{value:"critical",children:"Critical"})]})]}),o.jsxs("div",{children:[o.jsx("label",{className:"text-[9px] text-muted uppercase tracking-wider font-mono mb-1 block",children:"Scope"}),o.jsx("div",{className:"flex rounded-lg overflow-hidden",style:{border:"1px solid var(--b2)"},children:["all","personal","project"].map(_=>o.jsx("button",{onClick:()=>{y(_),v(!1)},className:"flex-1 px-1.5 py-1 text-[10px] font-mono cursor-pointer transition-all",style:{color:g===_?"var(--gold)":"var(--muted)",background:g===_?"var(--s3)":"transparent"},children:_==="all"?"All":_.charAt(0).toUpperCase()+_.slice(1)},_))})]})]}),document.body)]}),o.jsx("div",{className:"flex-1"}),o.jsxs("button",{onClick:()=>d(!u),className:"text-[10px] font-mono px-2 py-0.5 rounded cursor-pointer transition-all duration-150",style:{color:u?"var(--gold)":"var(--muted)",background:u?"var(--s3)":"transparent",border:"1px solid var(--b2)"},children:["Archive ",$.length]}),o.jsx("button",{onClick:()=>h(!0),className:"btn-gold px-3 py-1.5 rounded-lg text-[11px] font-semibold cursor-pointer active:scale-[0.98]",children:"Add"})]}),o.jsxs(xk,{sensors:D,collisionDetection:N5,onDragStart:z,onDragCancel:O,onDragEnd:Y,children:[o.jsx("div",{className:"flex-1 overflow-x-auto overflow-y-hidden min-h-0 snap-x snap-mandatory sm:overflow-x-visible sm:snap-none",children:o.jsx("div",{className:"flex h-full sm:gap-4 sm:flex-row flex-nowrap sm:min-w-0",children:Xh.map(_=>o.jsx(qk,{items:N[_.id],strategy:Bk,children:o.jsx(e3,{column:_,tasks:T[_.id],isDragging:k,onEdit:c,onRemove:U,className:"snap-center flex-shrink-0 w-screen sm:w-auto sm:flex-1 px-4 sm:px-0"})},_.id))})}),o.jsx(Ok,{children:A&&o.jsx(Fk,{task:l.find(_=>_.id===A)})})]}),u&&$.length>0&&o.jsxs("div",{className:"px-4 py-3 shrink-0",style:{borderTop:"1px solid var(--b1)"},children:[o.jsx("h3",{className:"text-[11px] font-semibold text-muted mb-2",children:"Archived Tasks"}),o.jsx("div",{className:"flex gap-2 flex-wrap",children:$.map(_=>o.jsxs("div",{className:"glass-card rounded-lg px-3 py-2 flex items-center gap-2",style:{opacity:.6},children:[o.jsx("div",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{background:_.status==="failed"?"var(--red)":"var(--muted2)"}}),o.jsx("span",{className:"text-[11px] text-muted line-through",children:_.title}),o.jsxs("span",{className:"text-[9px] font-mono text-muted2",children:["[",Gh[_.mode],"]"]})]},_.id))})]}),f&&o.jsx(bm,{task:null,onSave:X,onClose:()=>h(!1)}),r&&o.jsx(bm,{task:r,onSave:L,onClose:()=>c(null)})]})}function Ve(e){if(typeof e=="string"||typeof e=="number")return""+e;let t="";if(Array.isArray(e))for(let n=0,l;n<e.length;n++)(l=Ve(e[n]))!==""&&(t+=(t&&" ")+l);else for(let n in e)e[n]&&(t+=(t&&" ")+n);return t}var n3={value:()=>{}};function Bc(){for(var e=0,t=arguments.length,n={},l;e<t;++e){if(!(l=arguments[e]+"")||l in n||/[\s.]/.test(l))throw new Error("illegal type: "+l);n[l]=[]}return new uo(n)}function uo(e){this._=e}function l3(e,t){return e.trim().split(/^|\s+/).map(function(n){var l="",a=n.indexOf(".");if(a>=0&&(l=n.slice(a+1),n=n.slice(0,a)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:l}})}uo.prototype=Bc.prototype={constructor:uo,on:function(e,t){var n=this._,l=l3(e+"",n),a,s=-1,i=l.length;if(arguments.length<2){for(;++s<i;)if((a=(e=l[s]).type)&&(a=a3(n[a],e.name)))return a;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++s<i;)if(a=(e=l[s]).type)n[a]=wm(n[a],e.name,t);else if(t==null)for(a in n)n[a]=wm(n[a],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new uo(e)},call:function(e,t){if((a=arguments.length-2)>0)for(var n=new Array(a),l=0,a,s;l<a;++l)n[l]=arguments[l+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(s=this._[e],l=0,a=s.length;l<a;++l)s[l].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var l=this._[e],a=0,s=l.length;a<s;++a)l[a].value.apply(t,n)}};function a3(e,t){for(var n=0,l=e.length,a;n<l;++n)if((a=e[n]).name===t)return a.value}function wm(e,t,n){for(var l=0,a=e.length;l<a;++l)if(e[l].name===t){e[l]=n3,e=e.slice(0,l).concat(e.slice(l+1));break}return n!=null&&e.push({name:t,value:n}),e}var cf="http://www.w3.org/1999/xhtml";const Sm={svg:"http://www.w3.org/2000/svg",xhtml:cf,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function Uc(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Sm.hasOwnProperty(t)?{space:Sm[t],local:e}:e}function s3(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===cf&&t.documentElement.namespaceURI===cf?t.createElement(e):t.createElementNS(n,e)}}function i3(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function p1(e){var t=Uc(e);return(t.local?i3:s3)(t)}function r3(){}function Qh(e){return e==null?r3:function(){return this.querySelector(e)}}function o3(e){typeof e!="function"&&(e=Qh(e));for(var t=this._groups,n=t.length,l=new Array(n),a=0;a<n;++a)for(var s=t[a],i=s.length,r=l[a]=new Array(i),c,u,d=0;d<i;++d)(c=s[d])&&(u=e.call(c,c.__data__,d,s))&&("__data__"in c&&(u.__data__=c.__data__),r[d]=u);return new Ot(l,this._parents)}function c3(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function u3(){return[]}function g1(e){return e==null?u3:function(){return this.querySelectorAll(e)}}function d3(e){return function(){return c3(e.apply(this,arguments))}}function f3(e){typeof e=="function"?e=d3(e):e=g1(e);for(var t=this._groups,n=t.length,l=[],a=[],s=0;s<n;++s)for(var i=t[s],r=i.length,c,u=0;u<r;++u)(c=i[u])&&(l.push(e.call(c,c.__data__,u,i)),a.push(c));return new Ot(l,a)}function m1(e){return function(){return this.matches(e)}}function x1(e){return function(t){return t.matches(e)}}var h3=Array.prototype.find;function p3(e){return function(){return h3.call(this.children,e)}}function g3(){return this.firstElementChild}function m3(e){return this.select(e==null?g3:p3(typeof e=="function"?e:x1(e)))}var x3=Array.prototype.filter;function y3(){return Array.from(this.children)}function v3(e){return function(){return x3.call(this.children,e)}}function b3(e){return this.selectAll(e==null?y3:v3(typeof e=="function"?e:x1(e)))}function w3(e){typeof e!="function"&&(e=m1(e));for(var t=this._groups,n=t.length,l=new Array(n),a=0;a<n;++a)for(var s=t[a],i=s.length,r=l[a]=[],c,u=0;u<i;++u)(c=s[u])&&e.call(c,c.__data__,u,s)&&r.push(c);return new Ot(l,this._parents)}function y1(e){return new Array(e.length)}function S3(){return new Ot(this._enter||this._groups.map(y1),this._parents)}function nc(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}nc.prototype={constructor:nc,appendChild:function(e){return this._parent.insertBefore(e,this._next)},insertBefore:function(e,t){return this._parent.insertBefore(e,t)},querySelector:function(e){return this._parent.querySelector(e)},querySelectorAll:function(e){return this._parent.querySelectorAll(e)}};function N3(e){return function(){return e}}function j3(e,t,n,l,a,s){for(var i=0,r,c=t.length,u=s.length;i<u;++i)(r=t[i])?(r.__data__=s[i],l[i]=r):n[i]=new nc(e,s[i]);for(;i<c;++i)(r=t[i])&&(a[i]=r)}function k3(e,t,n,l,a,s,i){var r,c,u=new Map,d=t.length,f=s.length,h=new Array(d),p;for(r=0;r<d;++r)(c=t[r])&&(h[r]=p=i.call(c,c.__data__,r,t)+"",u.has(p)?a[r]=c:u.set(p,c));for(r=0;r<f;++r)p=i.call(e,s[r],r,s)+"",(c=u.get(p))?(l[r]=c,c.__data__=s[r],u.delete(p)):n[r]=new nc(e,s[r]);for(r=0;r<d;++r)(c=t[r])&&u.get(h[r])===c&&(a[r]=c)}function E3(e){return e.__data__}function C3(e,t){if(!arguments.length)return Array.from(this,E3);var n=t?k3:j3,l=this._parents,a=this._groups;typeof e!="function"&&(e=N3(e));for(var s=a.length,i=new Array(s),r=new Array(s),c=new Array(s),u=0;u<s;++u){var d=l[u],f=a[u],h=f.length,p=M3(e.call(d,d&&d.__data__,u,l)),x=p.length,S=r[u]=new Array(x),w=i[u]=new Array(x),g=c[u]=new Array(h);n(d,f,S,w,g,p,t);for(var y=0,m=0,v,j;y<x;++y)if(v=S[y]){for(y>=m&&(m=y+1);!(j=w[m])&&++m<x;);v._next=j||null}}return i=new Ot(i,l),i._enter=r,i._exit=c,i}function M3(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function _3(){return new Ot(this._exit||this._groups.map(y1),this._parents)}function A3(e,t,n){var l=this.enter(),a=this,s=this.exit();return typeof e=="function"?(l=e(l),l&&(l=l.selection())):l=l.append(e+""),t!=null&&(a=t(a),a&&(a=a.selection())),n==null?s.remove():n(s),l&&a?l.merge(a).order():a}function T3(e){for(var t=e.selection?e.selection():e,n=this._groups,l=t._groups,a=n.length,s=l.length,i=Math.min(a,s),r=new Array(a),c=0;c<i;++c)for(var u=n[c],d=l[c],f=u.length,h=r[c]=new Array(f),p,x=0;x<f;++x)(p=u[x]||d[x])&&(h[x]=p);for(;c<a;++c)r[c]=n[c];return new Ot(r,this._parents)}function z3(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var l=e[t],a=l.length-1,s=l[a],i;--a>=0;)(i=l[a])&&(s&&i.compareDocumentPosition(s)^4&&s.parentNode.insertBefore(i,s),s=i);return this}function D3(e){e||(e=R3);function t(f,h){return f&&h?e(f.__data__,h.__data__):!f-!h}for(var n=this._groups,l=n.length,a=new Array(l),s=0;s<l;++s){for(var i=n[s],r=i.length,c=a[s]=new Array(r),u,d=0;d<r;++d)(u=i[d])&&(c[d]=u);c.sort(t)}return new Ot(a,this._parents).order()}function R3(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function O3(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function H3(){return Array.from(this)}function L3(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var l=e[t],a=0,s=l.length;a<s;++a){var i=l[a];if(i)return i}return null}function $3(){let e=0;for(const t of this)++e;return e}function B3(){return!this.node()}function U3(e){for(var t=this._groups,n=0,l=t.length;n<l;++n)for(var a=t[n],s=0,i=a.length,r;s<i;++s)(r=a[s])&&e.call(r,r.__data__,s,a);return this}function q3(e){return function(){this.removeAttribute(e)}}function Y3(e){return function(){this.removeAttributeNS(e.space,e.local)}}function V3(e,t){return function(){this.setAttribute(e,t)}}function X3(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function G3(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function Q3(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttributeNS(e.space,e.local):this.setAttributeNS(e.space,e.local,n)}}function Z3(e,t){var n=Uc(e);if(arguments.length<2){var l=this.node();return n.local?l.getAttributeNS(n.space,n.local):l.getAttribute(n)}return this.each((t==null?n.local?Y3:q3:typeof t=="function"?n.local?Q3:G3:n.local?X3:V3)(n,t))}function v1(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function I3(e){return function(){this.style.removeProperty(e)}}function K3(e,t,n){return function(){this.style.setProperty(e,t,n)}}function W3(e,t,n){return function(){var l=t.apply(this,arguments);l==null?this.style.removeProperty(e):this.style.setProperty(e,l,n)}}function J3(e,t,n){return arguments.length>1?this.each((t==null?I3:typeof t=="function"?W3:K3)(e,t,n??"")):us(this.node(),e)}function us(e,t){return e.style.getPropertyValue(t)||v1(e).getComputedStyle(e,null).getPropertyValue(t)}function F3(e){return function(){delete this[e]}}function P3(e,t){return function(){this[e]=t}}function eE(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function tE(e,t){return arguments.length>1?this.each((t==null?F3:typeof t=="function"?eE:P3)(e,t)):this.node()[e]}function b1(e){return e.trim().split(/^|\s+/)}function Zh(e){return e.classList||new w1(e)}function w1(e){this._node=e,this._names=b1(e.getAttribute("class")||"")}w1.prototype={add:function(e){var t=this._names.indexOf(e);t<0&&(this._names.push(e),this._node.setAttribute("class",this._names.join(" ")))},remove:function(e){var t=this._names.indexOf(e);t>=0&&(this._names.splice(t,1),this._node.setAttribute("class",this._names.join(" ")))},contains:function(e){return this._names.indexOf(e)>=0}};function S1(e,t){for(var n=Zh(e),l=-1,a=t.length;++l<a;)n.add(t[l])}function N1(e,t){for(var n=Zh(e),l=-1,a=t.length;++l<a;)n.remove(t[l])}function nE(e){return function(){S1(this,e)}}function lE(e){return function(){N1(this,e)}}function aE(e,t){return function(){(t.apply(this,arguments)?S1:N1)(this,e)}}function sE(e,t){var n=b1(e+"");if(arguments.length<2){for(var l=Zh(this.node()),a=-1,s=n.length;++a<s;)if(!l.contains(n[a]))return!1;return!0}return this.each((typeof t=="function"?aE:t?nE:lE)(n,t))}function iE(){this.textContent=""}function rE(e){return function(){this.textContent=e}}function oE(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function cE(e){return arguments.length?this.each(e==null?iE:(typeof e=="function"?oE:rE)(e)):this.node().textContent}function uE(){this.innerHTML=""}function dE(e){return function(){this.innerHTML=e}}function fE(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function hE(e){return arguments.length?this.each(e==null?uE:(typeof e=="function"?fE:dE)(e)):this.node().innerHTML}function pE(){this.nextSibling&&this.parentNode.appendChild(this)}function gE(){return this.each(pE)}function mE(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function xE(){return this.each(mE)}function yE(e){var t=typeof e=="function"?e:p1(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function vE(){return null}function bE(e,t){var n=typeof e=="function"?e:p1(e),l=t==null?vE:typeof t=="function"?t:Qh(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),l.apply(this,arguments)||null)})}function wE(){var e=this.parentNode;e&&e.removeChild(this)}function SE(){return this.each(wE)}function NE(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function jE(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function kE(e){return this.select(e?jE:NE)}function EE(e){return arguments.length?this.property("__data__",e):this.node().__data__}function CE(e){return function(t){e.call(this,t,this.__data__)}}function ME(e){return e.trim().split(/^|\s+/).map(function(t){var n="",l=t.indexOf(".");return l>=0&&(n=t.slice(l+1),t=t.slice(0,l)),{type:t,name:n}})}function _E(e){return function(){var t=this.__on;if(t){for(var n=0,l=-1,a=t.length,s;n<a;++n)s=t[n],(!e.type||s.type===e.type)&&s.name===e.name?this.removeEventListener(s.type,s.listener,s.options):t[++l]=s;++l?t.length=l:delete this.__on}}}function AE(e,t,n){return function(){var l=this.__on,a,s=CE(t);if(l){for(var i=0,r=l.length;i<r;++i)if((a=l[i]).type===e.type&&a.name===e.name){this.removeEventListener(a.type,a.listener,a.options),this.addEventListener(a.type,a.listener=s,a.options=n),a.value=t;return}}this.addEventListener(e.type,s,n),a={type:e.type,name:e.name,value:t,listener:s,options:n},l?l.push(a):this.__on=[a]}}function TE(e,t,n){var l=ME(e+""),a,s=l.length,i;if(arguments.length<2){var r=this.node().__on;if(r){for(var c=0,u=r.length,d;c<u;++c)for(a=0,d=r[c];a<s;++a)if((i=l[a]).type===d.type&&i.name===d.name)return d.value}return}for(r=t?AE:_E,a=0;a<s;++a)this.each(r(l[a],t,n));return this}function j1(e,t,n){var l=v1(e),a=l.CustomEvent;typeof a=="function"?a=new a(t,n):(a=l.document.createEvent("Event"),n?(a.initEvent(t,n.bubbles,n.cancelable),a.detail=n.detail):a.initEvent(t,!1,!1)),e.dispatchEvent(a)}function zE(e,t){return function(){return j1(this,e,t)}}function DE(e,t){return function(){return j1(this,e,t.apply(this,arguments))}}function RE(e,t){return this.each((typeof t=="function"?DE:zE)(e,t))}function*OE(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var l=e[t],a=0,s=l.length,i;a<s;++a)(i=l[a])&&(yield i)}var k1=[null];function Ot(e,t){this._groups=e,this._parents=t}function ar(){return new Ot([[document.documentElement]],k1)}function HE(){return this}Ot.prototype=ar.prototype={constructor:Ot,select:o3,selectAll:f3,selectChild:m3,selectChildren:b3,filter:w3,data:C3,enter:S3,exit:_3,join:A3,merge:T3,selection:HE,order:z3,sort:D3,call:O3,nodes:H3,node:L3,size:$3,empty:B3,each:U3,attr:Z3,style:J3,property:tE,classed:sE,text:cE,html:hE,raise:gE,lower:xE,append:yE,insert:bE,remove:SE,clone:kE,datum:EE,on:TE,dispatch:RE,[Symbol.iterator]:OE};function Ct(e){return typeof e=="string"?new Ot([[document.querySelector(e)]],[document.documentElement]):new Ot([[e]],k1)}function LE(e){let t;for(;t=e.sourceEvent;)e=t;return e}function tn(e,t){if(e=LE(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var l=n.createSVGPoint();return l.x=e.clientX,l.y=e.clientY,l=l.matrixTransform(t.getScreenCTM().inverse()),[l.x,l.y]}if(t.getBoundingClientRect){var a=t.getBoundingClientRect();return[e.clientX-a.left-t.clientLeft,e.clientY-a.top-t.clientTop]}}return[e.pageX,e.pageY]}const $E={passive:!1},zi={capture:!0,passive:!1};function Iu(e){e.stopImmediatePropagation()}function Ja(e){e.preventDefault(),e.stopImmediatePropagation()}function E1(e){var t=e.document.documentElement,n=Ct(e).on("dragstart.drag",Ja,zi);"onselectstart"in t?n.on("selectstart.drag",Ja,zi):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function C1(e,t){var n=e.document.documentElement,l=Ct(e).on("dragstart.drag",null);t&&(l.on("click.drag",Ja,zi),setTimeout(function(){l.on("click.drag",null)},0)),"onselectstart"in n?l.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const Hr=e=>()=>e;function uf(e,{sourceEvent:t,subject:n,target:l,identifier:a,active:s,x:i,y:r,dx:c,dy:u,dispatch:d}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},subject:{value:n,enumerable:!0,configurable:!0},target:{value:l,enumerable:!0,configurable:!0},identifier:{value:a,enumerable:!0,configurable:!0},active:{value:s,enumerable:!0,configurable:!0},x:{value:i,enumerable:!0,configurable:!0},y:{value:r,enumerable:!0,configurable:!0},dx:{value:c,enumerable:!0,configurable:!0},dy:{value:u,enumerable:!0,configurable:!0},_:{value:d}})}uf.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function BE(e){return!e.ctrlKey&&!e.button}function UE(){return this.parentNode}function qE(e,t){return t??{x:e.x,y:e.y}}function YE(){return navigator.maxTouchPoints||"ontouchstart"in this}function M1(){var e=BE,t=UE,n=qE,l=YE,a={},s=Bc("start","drag","end"),i=0,r,c,u,d,f=0;function h(v){v.on("mousedown.drag",p).filter(l).on("touchstart.drag",w).on("touchmove.drag",g,$E).on("touchend.drag touchcancel.drag",y).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function p(v,j){if(!(d||!e.call(this,v,j))){var E=m(this,t.call(this,v,j),v,j,"mouse");E&&(Ct(v.view).on("mousemove.drag",x,zi).on("mouseup.drag",S,zi),E1(v.view),Iu(v),u=!1,r=v.clientX,c=v.clientY,E("start",v))}}function x(v){if(Ja(v),!u){var j=v.clientX-r,E=v.clientY-c;u=j*j+E*E>f}a.mouse("drag",v)}function S(v){Ct(v.view).on("mousemove.drag mouseup.drag",null),C1(v.view,u),Ja(v),a.mouse("end",v)}function w(v,j){if(e.call(this,v,j)){var E=v.changedTouches,M=t.call(this,v,j),A=E.length,C,H;for(C=0;C<A;++C)(H=m(this,M,v,j,E[C].identifier,E[C]))&&(Iu(v),H("start",v,E[C]))}}function g(v){var j=v.changedTouches,E=j.length,M,A;for(M=0;M<E;++M)(A=a[j[M].identifier])&&(Ja(v),A("drag",v,j[M]))}function y(v){var j=v.changedTouches,E=j.length,M,A;for(d&&clearTimeout(d),d=setTimeout(function(){d=null},500),M=0;M<E;++M)(A=a[j[M].identifier])&&(Iu(v),A("end",v,j[M]))}function m(v,j,E,M,A,C){var H=s.copy(),T=tn(C||E,j),$,V,N;if((N=n.call(v,new uf("beforestart",{sourceEvent:E,target:h,identifier:A,active:i,x:T[0],y:T[1],dx:0,dy:0,dispatch:H}),M))!=null)return $=N.x-T[0]||0,V=N.y-T[1]||0,function D(k,R,z){var O=T,Y;switch(k){case"start":a[A]=D,Y=i++;break;case"end":delete a[A],--i;case"drag":T=tn(z||R,j),Y=i;break}H.call(k,v,new uf(k,{sourceEvent:R,subject:N,target:h,identifier:A,active:Y,x:T[0]+$,y:T[1]+V,dx:T[0]-O[0],dy:T[1]-O[1],dispatch:H}),M)}}return h.filter=function(v){return arguments.length?(e=typeof v=="function"?v:Hr(!!v),h):e},h.container=function(v){return arguments.length?(t=typeof v=="function"?v:Hr(v),h):t},h.subject=function(v){return arguments.length?(n=typeof v=="function"?v:Hr(v),h):n},h.touchable=function(v){return arguments.length?(l=typeof v=="function"?v:Hr(!!v),h):l},h.on=function(){var v=s.on.apply(s,arguments);return v===s?h:v},h.clickDistance=function(v){return arguments.length?(f=(v=+v)*v,h):Math.sqrt(f)},h}function Ih(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function _1(e,t){var n=Object.create(e.prototype);for(var l in t)n[l]=t[l];return n}function sr(){}var Di=.7,lc=1/Di,Fa="\\s*([+-]?\\d+)\\s*",Ri="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Nn="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",VE=/^#([0-9a-f]{3,8})$/,XE=new RegExp(`^rgb\\(${Fa},${Fa},${Fa}\\)$`),GE=new RegExp(`^rgb\\(${Nn},${Nn},${Nn}\\)$`),QE=new RegExp(`^rgba\\(${Fa},${Fa},${Fa},${Ri}\\)$`),ZE=new RegExp(`^rgba\\(${Nn},${Nn},${Nn},${Ri}\\)$`),IE=new RegExp(`^hsl\\(${Ri},${Nn},${Nn}\\)$`),KE=new RegExp(`^hsla\\(${Ri},${Nn},${Nn},${Ri}\\)$`),Nm={aliceblue:15792383,antiquewhite:16444375,aqua:65535,aquamarine:8388564,azure:15794175,beige:16119260,bisque:16770244,black:0,blanchedalmond:16772045,blue:255,blueviolet:9055202,brown:10824234,burlywood:14596231,cadetblue:6266528,chartreuse:8388352,chocolate:13789470,coral:16744272,cornflowerblue:6591981,cornsilk:16775388,crimson:14423100,cyan:65535,darkblue:139,darkcyan:35723,darkgoldenrod:12092939,darkgray:11119017,darkgreen:25600,darkgrey:11119017,darkkhaki:12433259,darkmagenta:9109643,darkolivegreen:5597999,darkorange:16747520,darkorchid:10040012,darkred:9109504,darksalmon:15308410,darkseagreen:9419919,darkslateblue:4734347,darkslategray:3100495,darkslategrey:3100495,darkturquoise:52945,darkviolet:9699539,deeppink:16716947,deepskyblue:49151,dimgray:6908265,dimgrey:6908265,dodgerblue:2003199,firebrick:11674146,floralwhite:16775920,forestgreen:2263842,fuchsia:16711935,gainsboro:14474460,ghostwhite:16316671,gold:16766720,goldenrod:14329120,gray:8421504,green:32768,greenyellow:11403055,grey:8421504,honeydew:15794160,hotpink:16738740,indianred:13458524,indigo:4915330,ivory:16777200,khaki:15787660,lavender:15132410,lavenderblush:16773365,lawngreen:8190976,lemonchiffon:16775885,lightblue:11393254,lightcoral:15761536,lightcyan:14745599,lightgoldenrodyellow:16448210,lightgray:13882323,lightgreen:9498256,lightgrey:13882323,lightpink:16758465,lightsalmon:16752762,lightseagreen:2142890,lightskyblue:8900346,lightslategray:7833753,lightslategrey:7833753,lightsteelblue:11584734,lightyellow:16777184,lime:65280,limegreen:3329330,linen:16445670,magenta:16711935,maroon:8388608,mediumaquamarine:6737322,mediumblue:205,mediumorchid:12211667,mediumpurple:9662683,mediumseagreen:3978097,mediumslateblue:8087790,mediumspringgreen:64154,mediumturquoise:4772300,mediumvioletred:13047173,midnightblue:1644912,mintcream:16121850,mistyrose:16770273,moccasin:16770229,navajowhite:16768685,navy:128,oldlace:16643558,olive:8421376,olivedrab:7048739,orange:16753920,orangered:16729344,orchid:14315734,palegoldenrod:15657130,palegreen:10025880,paleturquoise:11529966,palevioletred:14381203,papayawhip:16773077,peachpuff:16767673,peru:13468991,pink:16761035,plum:14524637,powderblue:11591910,purple:8388736,rebeccapurple:6697881,red:16711680,rosybrown:12357519,royalblue:4286945,saddlebrown:9127187,salmon:16416882,sandybrown:16032864,seagreen:3050327,seashell:16774638,sienna:10506797,silver:12632256,skyblue:8900331,slateblue:6970061,slategray:7372944,slategrey:7372944,snow:16775930,springgreen:65407,steelblue:4620980,tan:13808780,teal:32896,thistle:14204888,tomato:16737095,turquoise:4251856,violet:15631086,wheat:16113331,white:16777215,whitesmoke:16119285,yellow:16776960,yellowgreen:10145074};Ih(sr,da,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:jm,formatHex:jm,formatHex8:WE,formatHsl:JE,formatRgb:km,toString:km});function jm(){return this.rgb().formatHex()}function WE(){return this.rgb().formatHex8()}function JE(){return A1(this).formatHsl()}function km(){return this.rgb().formatRgb()}function da(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=VE.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?Em(t):n===3?new vt(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?Lr(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?Lr(t>>12&15|t>>8&240,t>>8&15|t>>4&240,t>>4&15|t&240,((t&15)<<4|t&15)/255):null):(t=XE.exec(e))?new vt(t[1],t[2],t[3],1):(t=GE.exec(e))?new vt(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=QE.exec(e))?Lr(t[1],t[2],t[3],t[4]):(t=ZE.exec(e))?Lr(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=IE.exec(e))?_m(t[1],t[2]/100,t[3]/100,1):(t=KE.exec(e))?_m(t[1],t[2]/100,t[3]/100,t[4]):Nm.hasOwnProperty(e)?Em(Nm[e]):e==="transparent"?new vt(NaN,NaN,NaN,0):null}function Em(e){return new vt(e>>16&255,e>>8&255,e&255,1)}function Lr(e,t,n,l){return l<=0&&(e=t=n=NaN),new vt(e,t,n,l)}function FE(e){return e instanceof sr||(e=da(e)),e?(e=e.rgb(),new vt(e.r,e.g,e.b,e.opacity)):new vt}function df(e,t,n,l){return arguments.length===1?FE(e):new vt(e,t,n,l??1)}function vt(e,t,n,l){this.r=+e,this.g=+t,this.b=+n,this.opacity=+l}Ih(vt,df,_1(sr,{brighter(e){return e=e==null?lc:Math.pow(lc,e),new vt(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?Di:Math.pow(Di,e),new vt(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new vt(la(this.r),la(this.g),la(this.b),ac(this.opacity))},displayable(){return-.5<=this.r&&this.r<255.5&&-.5<=this.g&&this.g<255.5&&-.5<=this.b&&this.b<255.5&&0<=this.opacity&&this.opacity<=1},hex:Cm,formatHex:Cm,formatHex8:PE,formatRgb:Mm,toString:Mm}));function Cm(){return`#${Jl(this.r)}${Jl(this.g)}${Jl(this.b)}`}function PE(){return`#${Jl(this.r)}${Jl(this.g)}${Jl(this.b)}${Jl((isNaN(this.opacity)?1:this.opacity)*255)}`}function Mm(){const e=ac(this.opacity);return`${e===1?"rgb(":"rgba("}${la(this.r)}, ${la(this.g)}, ${la(this.b)}${e===1?")":`, ${e})`}`}function ac(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function la(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function Jl(e){return e=la(e),(e<16?"0":"")+e.toString(16)}function _m(e,t,n,l){return l<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new an(e,t,n,l)}function A1(e){if(e instanceof an)return new an(e.h,e.s,e.l,e.opacity);if(e instanceof sr||(e=da(e)),!e)return new an;if(e instanceof an)return e;e=e.rgb();var t=e.r/255,n=e.g/255,l=e.b/255,a=Math.min(t,n,l),s=Math.max(t,n,l),i=NaN,r=s-a,c=(s+a)/2;return r?(t===s?i=(n-l)/r+(n<l)*6:n===s?i=(l-t)/r+2:i=(t-n)/r+4,r/=c<.5?s+a:2-s-a,i*=60):r=c>0&&c<1?0:i,new an(i,r,c,e.opacity)}function eC(e,t,n,l){return arguments.length===1?A1(e):new an(e,t,n,l??1)}function an(e,t,n,l){this.h=+e,this.s=+t,this.l=+n,this.opacity=+l}Ih(an,eC,_1(sr,{brighter(e){return e=e==null?lc:Math.pow(lc,e),new an(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?Di:Math.pow(Di,e),new an(this.h,this.s,this.l*e,this.opacity)},rgb(){var e=this.h%360+(this.h<0)*360,t=isNaN(e)||isNaN(this.s)?0:this.s,n=this.l,l=n+(n<.5?n:1-n)*t,a=2*n-l;return new vt(Ku(e>=240?e-240:e+120,a,l),Ku(e,a,l),Ku(e<120?e+240:e-120,a,l),this.opacity)},clamp(){return new an(Am(this.h),$r(this.s),$r(this.l),ac(this.opacity))},displayable(){return(0<=this.s&&this.s<=1||isNaN(this.s))&&0<=this.l&&this.l<=1&&0<=this.opacity&&this.opacity<=1},formatHsl(){const e=ac(this.opacity);return`${e===1?"hsl(":"hsla("}${Am(this.h)}, ${$r(this.s)*100}%, ${$r(this.l)*100}%${e===1?")":`, ${e})`}`}}));function Am(e){return e=(e||0)%360,e<0?e+360:e}function $r(e){return Math.max(0,Math.min(1,e||0))}function Ku(e,t,n){return(e<60?t+(n-t)*e/60:e<180?n:e<240?t+(n-t)*(240-e)/60:t)*255}const Kh=e=>()=>e;function tC(e,t){return function(n){return e+n*t}}function nC(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(l){return Math.pow(e+l*t,n)}}function lC(e){return(e=+e)==1?T1:function(t,n){return n-t?nC(t,n,e):Kh(isNaN(t)?n:t)}}function T1(e,t){var n=t-e;return n?tC(e,n):Kh(isNaN(e)?t:e)}const sc=function e(t){var n=lC(t);function l(a,s){var i=n((a=df(a)).r,(s=df(s)).r),r=n(a.g,s.g),c=n(a.b,s.b),u=T1(a.opacity,s.opacity);return function(d){return a.r=i(d),a.g=r(d),a.b=c(d),a.opacity=u(d),a+""}}return l.gamma=e,l}(1);function aC(e,t){t||(t=[]);var n=e?Math.min(t.length,e.length):0,l=t.slice(),a;return function(s){for(a=0;a<n;++a)l[a]=e[a]*(1-s)+t[a]*s;return l}}function sC(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function iC(e,t){var n=t?t.length:0,l=e?Math.min(n,e.length):0,a=new Array(l),s=new Array(n),i;for(i=0;i<l;++i)a[i]=pi(e[i],t[i]);for(;i<n;++i)s[i]=t[i];return function(r){for(i=0;i<l;++i)s[i]=a[i](r);return s}}function rC(e,t){var n=new Date;return e=+e,t=+t,function(l){return n.setTime(e*(1-l)+t*l),n}}function yn(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}function oC(e,t){var n={},l={},a;(e===null||typeof e!="object")&&(e={}),(t===null||typeof t!="object")&&(t={});for(a in t)a in e?n[a]=pi(e[a],t[a]):l[a]=t[a];return function(s){for(a in n)l[a]=n[a](s);return l}}var ff=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,Wu=new RegExp(ff.source,"g");function cC(e){return function(){return e}}function uC(e){return function(t){return e(t)+""}}function z1(e,t){var n=ff.lastIndex=Wu.lastIndex=0,l,a,s,i=-1,r=[],c=[];for(e=e+"",t=t+"";(l=ff.exec(e))&&(a=Wu.exec(t));)(s=a.index)>n&&(s=t.slice(n,s),r[i]?r[i]+=s:r[++i]=s),(l=l[0])===(a=a[0])?r[i]?r[i]+=a:r[++i]=a:(r[++i]=null,c.push({i,x:yn(l,a)})),n=Wu.lastIndex;return n<t.length&&(s=t.slice(n),r[i]?r[i]+=s:r[++i]=s),r.length<2?c[0]?uC(c[0].x):cC(t):(t=c.length,function(u){for(var d=0,f;d<t;++d)r[(f=c[d]).i]=f.x(u);return r.join("")})}function pi(e,t){var n=typeof t,l;return t==null||n==="boolean"?Kh(t):(n==="number"?yn:n==="string"?(l=da(t))?(t=l,sc):z1:t instanceof da?sc:t instanceof Date?rC:sC(t)?aC:Array.isArray(t)?iC:typeof t.valueOf!="function"&&typeof t.toString!="function"||isNaN(t)?oC:yn)(e,t)}var Tm=180/Math.PI,hf={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function D1(e,t,n,l,a,s){var i,r,c;return(i=Math.sqrt(e*e+t*t))&&(e/=i,t/=i),(c=e*n+t*l)&&(n-=e*c,l-=t*c),(r=Math.sqrt(n*n+l*l))&&(n/=r,l/=r,c/=r),e*l<t*n&&(e=-e,t=-t,c=-c,i=-i),{translateX:a,translateY:s,rotate:Math.atan2(t,e)*Tm,skewX:Math.atan(c)*Tm,scaleX:i,scaleY:r}}var Br;function dC(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?hf:D1(t.a,t.b,t.c,t.d,t.e,t.f)}function fC(e){return e==null||(Br||(Br=document.createElementNS("http://www.w3.org/2000/svg","g")),Br.setAttribute("transform",e),!(e=Br.transform.baseVal.consolidate()))?hf:(e=e.matrix,D1(e.a,e.b,e.c,e.d,e.e,e.f))}function R1(e,t,n,l){function a(u){return u.length?u.pop()+" ":""}function s(u,d,f,h,p,x){if(u!==f||d!==h){var S=p.push("translate(",null,t,null,n);x.push({i:S-4,x:yn(u,f)},{i:S-2,x:yn(d,h)})}else(f||h)&&p.push("translate("+f+t+h+n)}function i(u,d,f,h){u!==d?(u-d>180?d+=360:d-u>180&&(u+=360),h.push({i:f.push(a(f)+"rotate(",null,l)-2,x:yn(u,d)})):d&&f.push(a(f)+"rotate("+d+l)}function r(u,d,f,h){u!==d?h.push({i:f.push(a(f)+"skewX(",null,l)-2,x:yn(u,d)}):d&&f.push(a(f)+"skewX("+d+l)}function c(u,d,f,h,p,x){if(u!==f||d!==h){var S=p.push(a(p)+"scale(",null,",",null,")");x.push({i:S-4,x:yn(u,f)},{i:S-2,x:yn(d,h)})}else(f!==1||h!==1)&&p.push(a(p)+"scale("+f+","+h+")")}return function(u,d){var f=[],h=[];return u=e(u),d=e(d),s(u.translateX,u.translateY,d.translateX,d.translateY,f,h),i(u.rotate,d.rotate,f,h),r(u.skewX,d.skewX,f,h),c(u.scaleX,u.scaleY,d.scaleX,d.scaleY,f,h),u=d=null,function(p){for(var x=-1,S=h.length,w;++x<S;)f[(w=h[x]).i]=w.x(p);return f.join("")}}}var hC=R1(dC,"px, ","px)","deg)"),pC=R1(fC,", ",")",")"),gC=1e-12;function zm(e){return((e=Math.exp(e))+1/e)/2}function mC(e){return((e=Math.exp(e))-1/e)/2}function xC(e){return((e=Math.exp(2*e))-1)/(e+1)}const fo=function e(t,n,l){function a(s,i){var r=s[0],c=s[1],u=s[2],d=i[0],f=i[1],h=i[2],p=d-r,x=f-c,S=p*p+x*x,w,g;if(S<gC)g=Math.log(h/u)/t,w=function(M){return[r+M*p,c+M*x,u*Math.exp(t*M*g)]};else{var y=Math.sqrt(S),m=(h*h-u*u+l*S)/(2*u*n*y),v=(h*h-u*u-l*S)/(2*h*n*y),j=Math.log(Math.sqrt(m*m+1)-m),E=Math.log(Math.sqrt(v*v+1)-v);g=(E-j)/t,w=function(M){var A=M*g,C=zm(j),H=u/(n*y)*(C*xC(t*A+j)-mC(j));return[r+H*p,c+H*x,u*C/zm(t*A+j)]}}return w.duration=g*1e3*t/Math.SQRT2,w}return a.rho=function(s){var i=Math.max(.001,+s),r=i*i,c=r*r;return e(i,r,c)},a}(Math.SQRT2,2,4);var ds=0,Ks=0,qs=0,O1=1e3,ic,Ws,rc=0,fa=0,qc=0,Oi=typeof performance=="object"&&performance.now?performance:Date,H1=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function Wh(){return fa||(H1(yC),fa=Oi.now()+qc)}function yC(){fa=0}function oc(){this._call=this._time=this._next=null}oc.prototype=L1.prototype={constructor:oc,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?Wh():+n)+(t==null?0:+t),!this._next&&Ws!==this&&(Ws?Ws._next=this:ic=this,Ws=this),this._call=e,this._time=n,pf()},stop:function(){this._call&&(this._call=null,this._time=1/0,pf())}};function L1(e,t,n){var l=new oc;return l.restart(e,t,n),l}function vC(){Wh(),++ds;for(var e=ic,t;e;)(t=fa-e._time)>=0&&e._call.call(void 0,t),e=e._next;--ds}function Dm(){fa=(rc=Oi.now())+qc,ds=Ks=0;try{vC()}finally{ds=0,wC(),fa=0}}function bC(){var e=Oi.now(),t=e-rc;t>O1&&(qc-=t,rc=e)}function wC(){for(var e,t=ic,n,l=1/0;t;)t._call?(l>t._time&&(l=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:ic=n);Ws=e,pf(l)}function pf(e){if(!ds){Ks&&(Ks=clearTimeout(Ks));var t=e-fa;t>24?(e<1/0&&(Ks=setTimeout(Dm,e-Oi.now()-qc)),qs&&(qs=clearInterval(qs))):(qs||(rc=Oi.now(),qs=setInterval(bC,O1)),ds=1,H1(Dm))}}function Rm(e,t,n){var l=new oc;return t=t==null?0:+t,l.restart(a=>{l.stop(),e(a+t)},t,n),l}var SC=Bc("start","end","cancel","interrupt"),NC=[],$1=0,Om=1,gf=2,ho=3,Hm=4,mf=5,po=6;function Yc(e,t,n,l,a,s){var i=e.__transition;if(!i)e.__transition={};else if(n in i)return;jC(e,n,{name:t,index:l,group:a,on:SC,tween:NC,time:s.time,delay:s.delay,duration:s.duration,ease:s.ease,timer:null,state:$1})}function Jh(e,t){var n=dn(e,t);if(n.state>$1)throw new Error("too late; already scheduled");return n}function Mn(e,t){var n=dn(e,t);if(n.state>ho)throw new Error("too late; already running");return n}function dn(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function jC(e,t,n){var l=e.__transition,a;l[t]=n,n.timer=L1(s,0,n.time);function s(u){n.state=Om,n.timer.restart(i,n.delay,n.time),n.delay<=u&&i(u-n.delay)}function i(u){var d,f,h,p;if(n.state!==Om)return c();for(d in l)if(p=l[d],p.name===n.name){if(p.state===ho)return Rm(i);p.state===Hm?(p.state=po,p.timer.stop(),p.on.call("interrupt",e,e.__data__,p.index,p.group),delete l[d]):+d<t&&(p.state=po,p.timer.stop(),p.on.call("cancel",e,e.__data__,p.index,p.group),delete l[d])}if(Rm(function(){n.state===ho&&(n.state=Hm,n.timer.restart(r,n.delay,n.time),r(u))}),n.state=gf,n.on.call("start",e,e.__data__,n.index,n.group),n.state===gf){for(n.state=ho,a=new Array(h=n.tween.length),d=0,f=-1;d<h;++d)(p=n.tween[d].value.call(e,e.__data__,n.index,n.group))&&(a[++f]=p);a.length=f+1}}function r(u){for(var d=u<n.duration?n.ease.call(null,u/n.duration):(n.timer.restart(c),n.state=mf,1),f=-1,h=a.length;++f<h;)a[f].call(e,d);n.state===mf&&(n.on.call("end",e,e.__data__,n.index,n.group),c())}function c(){n.state=po,n.timer.stop(),delete l[t];for(var u in l)return;delete e.__transition}}function go(e,t){var n=e.__transition,l,a,s=!0,i;if(n){t=t==null?null:t+"";for(i in n){if((l=n[i]).name!==t){s=!1;continue}a=l.state>gf&&l.state<mf,l.state=po,l.timer.stop(),l.on.call(a?"interrupt":"cancel",e,e.__data__,l.index,l.group),delete n[i]}s&&delete e.__transition}}function kC(e){return this.each(function(){go(this,e)})}function EC(e,t){var n,l;return function(){var a=Mn(this,e),s=a.tween;if(s!==n){l=n=s;for(var i=0,r=l.length;i<r;++i)if(l[i].name===t){l=l.slice(),l.splice(i,1);break}}a.tween=l}}function CC(e,t,n){var l,a;if(typeof n!="function")throw new Error;return function(){var s=Mn(this,e),i=s.tween;if(i!==l){a=(l=i).slice();for(var r={name:t,value:n},c=0,u=a.length;c<u;++c)if(a[c].name===t){a[c]=r;break}c===u&&a.push(r)}s.tween=a}}function MC(e,t){var n=this._id;if(e+="",arguments.length<2){for(var l=dn(this.node(),n).tween,a=0,s=l.length,i;a<s;++a)if((i=l[a]).name===e)return i.value;return null}return this.each((t==null?EC:CC)(n,e,t))}function Fh(e,t,n){var l=e._id;return e.each(function(){var a=Mn(this,l);(a.value||(a.value={}))[t]=n.apply(this,arguments)}),function(a){return dn(a,l).value[t]}}function B1(e,t){var n;return(typeof t=="number"?yn:t instanceof da?sc:(n=da(t))?(t=n,sc):z1)(e,t)}function _C(e){return function(){this.removeAttribute(e)}}function AC(e){return function(){this.removeAttributeNS(e.space,e.local)}}function TC(e,t,n){var l,a=n+"",s;return function(){var i=this.getAttribute(e);return i===a?null:i===l?s:s=t(l=i,n)}}function zC(e,t,n){var l,a=n+"",s;return function(){var i=this.getAttributeNS(e.space,e.local);return i===a?null:i===l?s:s=t(l=i,n)}}function DC(e,t,n){var l,a,s;return function(){var i,r=n(this),c;return r==null?void this.removeAttribute(e):(i=this.getAttribute(e),c=r+"",i===c?null:i===l&&c===a?s:(a=c,s=t(l=i,r)))}}function RC(e,t,n){var l,a,s;return function(){var i,r=n(this),c;return r==null?void this.removeAttributeNS(e.space,e.local):(i=this.getAttributeNS(e.space,e.local),c=r+"",i===c?null:i===l&&c===a?s:(a=c,s=t(l=i,r)))}}function OC(e,t){var n=Uc(e),l=n==="transform"?pC:B1;return this.attrTween(e,typeof t=="function"?(n.local?RC:DC)(n,l,Fh(this,"attr."+e,t)):t==null?(n.local?AC:_C)(n):(n.local?zC:TC)(n,l,t))}function HC(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function LC(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function $C(e,t){var n,l;function a(){var s=t.apply(this,arguments);return s!==l&&(n=(l=s)&&LC(e,s)),n}return a._value=t,a}function BC(e,t){var n,l;function a(){var s=t.apply(this,arguments);return s!==l&&(n=(l=s)&&HC(e,s)),n}return a._value=t,a}function UC(e,t){var n="attr."+e;if(arguments.length<2)return(n=this.tween(n))&&n._value;if(t==null)return this.tween(n,null);if(typeof t!="function")throw new Error;var l=Uc(e);return this.tween(n,(l.local?$C:BC)(l,t))}function qC(e,t){return function(){Jh(this,e).delay=+t.apply(this,arguments)}}function YC(e,t){return t=+t,function(){Jh(this,e).delay=t}}function VC(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?qC:YC)(t,e)):dn(this.node(),t).delay}function XC(e,t){return function(){Mn(this,e).duration=+t.apply(this,arguments)}}function GC(e,t){return t=+t,function(){Mn(this,e).duration=t}}function QC(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?XC:GC)(t,e)):dn(this.node(),t).duration}function ZC(e,t){if(typeof t!="function")throw new Error;return function(){Mn(this,e).ease=t}}function IC(e){var t=this._id;return arguments.length?this.each(ZC(t,e)):dn(this.node(),t).ease}function KC(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;Mn(this,e).ease=n}}function WC(e){if(typeof e!="function")throw new Error;return this.each(KC(this._id,e))}function JC(e){typeof e!="function"&&(e=m1(e));for(var t=this._groups,n=t.length,l=new Array(n),a=0;a<n;++a)for(var s=t[a],i=s.length,r=l[a]=[],c,u=0;u<i;++u)(c=s[u])&&e.call(c,c.__data__,u,s)&&r.push(c);return new el(l,this._parents,this._name,this._id)}function FC(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,l=t.length,a=n.length,s=Math.min(l,a),i=new Array(l),r=0;r<s;++r)for(var c=t[r],u=n[r],d=c.length,f=i[r]=new Array(d),h,p=0;p<d;++p)(h=c[p]||u[p])&&(f[p]=h);for(;r<l;++r)i[r]=t[r];return new el(i,this._parents,this._name,this._id)}function PC(e){return(e+"").trim().split(/^|\s+/).every(function(t){var n=t.indexOf(".");return n>=0&&(t=t.slice(0,n)),!t||t==="start"})}function e4(e,t,n){var l,a,s=PC(t)?Jh:Mn;return function(){var i=s(this,e),r=i.on;r!==l&&(a=(l=r).copy()).on(t,n),i.on=a}}function t4(e,t){var n=this._id;return arguments.length<2?dn(this.node(),n).on.on(e):this.each(e4(n,e,t))}function n4(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function l4(){return this.on("end.remove",n4(this._id))}function a4(e){var t=this._name,n=this._id;typeof e!="function"&&(e=Qh(e));for(var l=this._groups,a=l.length,s=new Array(a),i=0;i<a;++i)for(var r=l[i],c=r.length,u=s[i]=new Array(c),d,f,h=0;h<c;++h)(d=r[h])&&(f=e.call(d,d.__data__,h,r))&&("__data__"in d&&(f.__data__=d.__data__),u[h]=f,Yc(u[h],t,n,h,u,dn(d,n)));return new el(s,this._parents,t,n)}function s4(e){var t=this._name,n=this._id;typeof e!="function"&&(e=g1(e));for(var l=this._groups,a=l.length,s=[],i=[],r=0;r<a;++r)for(var c=l[r],u=c.length,d,f=0;f<u;++f)if(d=c[f]){for(var h=e.call(d,d.__data__,f,c),p,x=dn(d,n),S=0,w=h.length;S<w;++S)(p=h[S])&&Yc(p,t,n,S,h,x);s.push(h),i.push(d)}return new el(s,i,t,n)}var i4=ar.prototype.constructor;function r4(){return new i4(this._groups,this._parents)}function o4(e,t){var n,l,a;return function(){var s=us(this,e),i=(this.style.removeProperty(e),us(this,e));return s===i?null:s===n&&i===l?a:a=t(n=s,l=i)}}function U1(e){return function(){this.style.removeProperty(e)}}function c4(e,t,n){var l,a=n+"",s;return function(){var i=us(this,e);return i===a?null:i===l?s:s=t(l=i,n)}}function u4(e,t,n){var l,a,s;return function(){var i=us(this,e),r=n(this),c=r+"";return r==null&&(c=r=(this.style.removeProperty(e),us(this,e))),i===c?null:i===l&&c===a?s:(a=c,s=t(l=i,r))}}function d4(e,t){var n,l,a,s="style."+t,i="end."+s,r;return function(){var c=Mn(this,e),u=c.on,d=c.value[s]==null?r||(r=U1(t)):void 0;(u!==n||a!==d)&&(l=(n=u).copy()).on(i,a=d),c.on=l}}function f4(e,t,n){var l=(e+="")=="transform"?hC:B1;return t==null?this.styleTween(e,o4(e,l)).on("end.style."+e,U1(e)):typeof t=="function"?this.styleTween(e,u4(e,l,Fh(this,"style."+e,t))).each(d4(this._id,e)):this.styleTween(e,c4(e,l,t),n).on("end.style."+e,null)}function h4(e,t,n){return function(l){this.style.setProperty(e,t.call(this,l),n)}}function p4(e,t,n){var l,a;function s(){var i=t.apply(this,arguments);return i!==a&&(l=(a=i)&&h4(e,i,n)),l}return s._value=t,s}function g4(e,t,n){var l="style."+(e+="");if(arguments.length<2)return(l=this.tween(l))&&l._value;if(t==null)return this.tween(l,null);if(typeof t!="function")throw new Error;return this.tween(l,p4(e,t,n??""))}function m4(e){return function(){this.textContent=e}}function x4(e){return function(){var t=e(this);this.textContent=t??""}}function y4(e){return this.tween("text",typeof e=="function"?x4(Fh(this,"text",e)):m4(e==null?"":e+""))}function v4(e){return function(t){this.textContent=e.call(this,t)}}function b4(e){var t,n;function l(){var a=e.apply(this,arguments);return a!==n&&(t=(n=a)&&v4(a)),t}return l._value=e,l}function w4(e){var t="text";if(arguments.length<1)return(t=this.tween(t))&&t._value;if(e==null)return this.tween(t,null);if(typeof e!="function")throw new Error;return this.tween(t,b4(e))}function S4(){for(var e=this._name,t=this._id,n=q1(),l=this._groups,a=l.length,s=0;s<a;++s)for(var i=l[s],r=i.length,c,u=0;u<r;++u)if(c=i[u]){var d=dn(c,t);Yc(c,e,n,u,i,{time:d.time+d.delay+d.duration,delay:0,duration:d.duration,ease:d.ease})}return new el(l,this._parents,e,n)}function N4(){var e,t,n=this,l=n._id,a=n.size();return new Promise(function(s,i){var r={value:i},c={value:function(){--a===0&&s()}};n.each(function(){var u=Mn(this,l),d=u.on;d!==e&&(t=(e=d).copy(),t._.cancel.push(r),t._.interrupt.push(r),t._.end.push(c)),u.on=t}),a===0&&s()})}var j4=0;function el(e,t,n,l){this._groups=e,this._parents=t,this._name=n,this._id=l}function q1(){return++j4}var Hn=ar.prototype;el.prototype={constructor:el,select:a4,selectAll:s4,selectChild:Hn.selectChild,selectChildren:Hn.selectChildren,filter:JC,merge:FC,selection:r4,transition:S4,call:Hn.call,nodes:Hn.nodes,node:Hn.node,size:Hn.size,empty:Hn.empty,each:Hn.each,on:t4,attr:OC,attrTween:UC,style:f4,styleTween:g4,text:y4,textTween:w4,remove:l4,tween:MC,delay:VC,duration:QC,ease:IC,easeVarying:WC,end:N4,[Symbol.iterator]:Hn[Symbol.iterator]};function k4(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var E4={time:null,delay:0,duration:250,ease:k4};function C4(e,t){for(var n;!(n=e.__transition)||!(n=n[t]);)if(!(e=e.parentNode))throw new Error(`transition ${t} not found`);return n}function M4(e){var t,n;e instanceof el?(t=e._id,e=e._name):(t=q1(),(n=E4).time=Wh(),e=e==null?null:e+"");for(var l=this._groups,a=l.length,s=0;s<a;++s)for(var i=l[s],r=i.length,c,u=0;u<r;++u)(c=i[u])&&Yc(c,e,t,u,i,n||C4(c,t));return new el(l,this._parents,e,t)}ar.prototype.interrupt=kC;ar.prototype.transition=M4;const Ur=e=>()=>e;function _4(e,{sourceEvent:t,target:n,transform:l,dispatch:a}){Object.defineProperties(this,{type:{value:e,enumerable:!0,configurable:!0},sourceEvent:{value:t,enumerable:!0,configurable:!0},target:{value:n,enumerable:!0,configurable:!0},transform:{value:l,enumerable:!0,configurable:!0},_:{value:a}})}function Vn(e,t,n){this.k=e,this.x=t,this.y=n}Vn.prototype={constructor:Vn,scale:function(e){return e===1?this:new Vn(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new Vn(this.k,this.x+this.k*e,this.y+this.k*t)},apply:function(e){return[e[0]*this.k+this.x,e[1]*this.k+this.y]},applyX:function(e){return e*this.k+this.x},applyY:function(e){return e*this.k+this.y},invert:function(e){return[(e[0]-this.x)/this.k,(e[1]-this.y)/this.k]},invertX:function(e){return(e-this.x)/this.k},invertY:function(e){return(e-this.y)/this.k},rescaleX:function(e){return e.copy().domain(e.range().map(this.invertX,this).map(e.invert,e))},rescaleY:function(e){return e.copy().domain(e.range().map(this.invertY,this).map(e.invert,e))},toString:function(){return"translate("+this.x+","+this.y+") scale("+this.k+")"}};var Vc=new Vn(1,0,0);Y1.prototype=Vn.prototype;function Y1(e){for(;!e.__zoom;)if(!(e=e.parentNode))return Vc;return e.__zoom}function Ju(e){e.stopImmediatePropagation()}function Ys(e){e.preventDefault(),e.stopImmediatePropagation()}function A4(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function T4(){var e=this;return e instanceof SVGElement?(e=e.ownerSVGElement||e,e.hasAttribute("viewBox")?(e=e.viewBox.baseVal,[[e.x,e.y],[e.x+e.width,e.y+e.height]]):[[0,0],[e.width.baseVal.value,e.height.baseVal.value]]):[[0,0],[e.clientWidth,e.clientHeight]]}function Lm(){return this.__zoom||Vc}function z4(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function D4(){return navigator.maxTouchPoints||"ontouchstart"in this}function R4(e,t,n){var l=e.invertX(t[0][0])-n[0][0],a=e.invertX(t[1][0])-n[1][0],s=e.invertY(t[0][1])-n[0][1],i=e.invertY(t[1][1])-n[1][1];return e.translate(a>l?(l+a)/2:Math.min(0,l)||Math.max(0,a),i>s?(s+i)/2:Math.min(0,s)||Math.max(0,i))}function V1(){var e=A4,t=T4,n=R4,l=z4,a=D4,s=[0,1/0],i=[[-1/0,-1/0],[1/0,1/0]],r=250,c=fo,u=Bc("start","zoom","end"),d,f,h,p=500,x=150,S=0,w=10;function g(N){N.property("__zoom",Lm).on("wheel.zoom",A,{passive:!1}).on("mousedown.zoom",C).on("dblclick.zoom",H).filter(a).on("touchstart.zoom",T).on("touchmove.zoom",$).on("touchend.zoom touchcancel.zoom",V).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}g.transform=function(N,D,k,R){var z=N.selection?N.selection():N;z.property("__zoom",Lm),N!==z?j(N,D,k,R):z.interrupt().each(function(){E(this,arguments).event(R).start().zoom(null,typeof D=="function"?D.apply(this,arguments):D).end()})},g.scaleBy=function(N,D,k,R){g.scaleTo(N,function(){var z=this.__zoom.k,O=typeof D=="function"?D.apply(this,arguments):D;return z*O},k,R)},g.scaleTo=function(N,D,k,R){g.transform(N,function(){var z=t.apply(this,arguments),O=this.__zoom,Y=k==null?v(z):typeof k=="function"?k.apply(this,arguments):k,X=O.invert(Y),L=typeof D=="function"?D.apply(this,arguments):D;return n(m(y(O,L),Y,X),z,i)},k,R)},g.translateBy=function(N,D,k,R){g.transform(N,function(){return n(this.__zoom.translate(typeof D=="function"?D.apply(this,arguments):D,typeof k=="function"?k.apply(this,arguments):k),t.apply(this,arguments),i)},null,R)},g.translateTo=function(N,D,k,R,z){g.transform(N,function(){var O=t.apply(this,arguments),Y=this.__zoom,X=R==null?v(O):typeof R=="function"?R.apply(this,arguments):R;return n(Vc.translate(X[0],X[1]).scale(Y.k).translate(typeof D=="function"?-D.apply(this,arguments):-D,typeof k=="function"?-k.apply(this,arguments):-k),O,i)},R,z)};function y(N,D){return D=Math.max(s[0],Math.min(s[1],D)),D===N.k?N:new Vn(D,N.x,N.y)}function m(N,D,k){var R=D[0]-k[0]*N.k,z=D[1]-k[1]*N.k;return R===N.x&&z===N.y?N:new Vn(N.k,R,z)}function v(N){return[(+N[0][0]+ +N[1][0])/2,(+N[0][1]+ +N[1][1])/2]}function j(N,D,k,R){N.on("start.zoom",function(){E(this,arguments).event(R).start()}).on("interrupt.zoom end.zoom",function(){E(this,arguments).event(R).end()}).tween("zoom",function(){var z=this,O=arguments,Y=E(z,O).event(R),X=t.apply(z,O),L=k==null?v(X):typeof k=="function"?k.apply(z,O):k,U=Math.max(X[1][0]-X[0][0],X[1][1]-X[0][1]),_=z.__zoom,B=typeof D=="function"?D.apply(z,O):D,G=c(_.invert(L).concat(U/_.k),B.invert(L).concat(U/B.k));return function(q){if(q===1)q=B;else{var Q=G(q),K=U/Q[2];q=new Vn(K,L[0]-Q[0]*K,L[1]-Q[1]*K)}Y.zoom(null,q)}})}function E(N,D,k){return!k&&N.__zooming||new M(N,D)}function M(N,D){this.that=N,this.args=D,this.active=0,this.sourceEvent=null,this.extent=t.apply(N,D),this.taps=0}M.prototype={event:function(N){return N&&(this.sourceEvent=N),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(N,D){return this.mouse&&N!=="mouse"&&(this.mouse[1]=D.invert(this.mouse[0])),this.touch0&&N!=="touch"&&(this.touch0[1]=D.invert(this.touch0[0])),this.touch1&&N!=="touch"&&(this.touch1[1]=D.invert(this.touch1[0])),this.that.__zoom=D,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(N){var D=Ct(this.that).datum();u.call(N,this.that,new _4(N,{sourceEvent:this.sourceEvent,target:g,transform:this.that.__zoom,dispatch:u}),D)}};function A(N,...D){if(!e.apply(this,arguments))return;var k=E(this,D).event(N),R=this.__zoom,z=Math.max(s[0],Math.min(s[1],R.k*Math.pow(2,l.apply(this,arguments)))),O=tn(N);if(k.wheel)(k.mouse[0][0]!==O[0]||k.mouse[0][1]!==O[1])&&(k.mouse[1]=R.invert(k.mouse[0]=O)),clearTimeout(k.wheel);else{if(R.k===z)return;k.mouse=[O,R.invert(O)],go(this),k.start()}Ys(N),k.wheel=setTimeout(Y,x),k.zoom("mouse",n(m(y(R,z),k.mouse[0],k.mouse[1]),k.extent,i));function Y(){k.wheel=null,k.end()}}function C(N,...D){if(h||!e.apply(this,arguments))return;var k=N.currentTarget,R=E(this,D,!0).event(N),z=Ct(N.view).on("mousemove.zoom",L,!0).on("mouseup.zoom",U,!0),O=tn(N,k),Y=N.clientX,X=N.clientY;E1(N.view),Ju(N),R.mouse=[O,this.__zoom.invert(O)],go(this),R.start();function L(_){if(Ys(_),!R.moved){var B=_.clientX-Y,G=_.clientY-X;R.moved=B*B+G*G>S}R.event(_).zoom("mouse",n(m(R.that.__zoom,R.mouse[0]=tn(_,k),R.mouse[1]),R.extent,i))}function U(_){z.on("mousemove.zoom mouseup.zoom",null),C1(_.view,R.moved),Ys(_),R.event(_).end()}}function H(N,...D){if(e.apply(this,arguments)){var k=this.__zoom,R=tn(N.changedTouches?N.changedTouches[0]:N,this),z=k.invert(R),O=k.k*(N.shiftKey?.5:2),Y=n(m(y(k,O),R,z),t.apply(this,D),i);Ys(N),r>0?Ct(this).transition().duration(r).call(j,Y,R,N):Ct(this).call(g.transform,Y,R,N)}}function T(N,...D){if(e.apply(this,arguments)){var k=N.touches,R=k.length,z=E(this,D,N.changedTouches.length===R).event(N),O,Y,X,L;for(Ju(N),Y=0;Y<R;++Y)X=k[Y],L=tn(X,this),L=[L,this.__zoom.invert(L),X.identifier],z.touch0?!z.touch1&&z.touch0[2]!==L[2]&&(z.touch1=L,z.taps=0):(z.touch0=L,O=!0,z.taps=1+!!d);d&&(d=clearTimeout(d)),O&&(z.taps<2&&(f=L[0],d=setTimeout(function(){d=null},p)),go(this),z.start())}}function $(N,...D){if(this.__zooming){var k=E(this,D).event(N),R=N.changedTouches,z=R.length,O,Y,X,L;for(Ys(N),O=0;O<z;++O)Y=R[O],X=tn(Y,this),k.touch0&&k.touch0[2]===Y.identifier?k.touch0[0]=X:k.touch1&&k.touch1[2]===Y.identifier&&(k.touch1[0]=X);if(Y=k.that.__zoom,k.touch1){var U=k.touch0[0],_=k.touch0[1],B=k.touch1[0],G=k.touch1[1],q=(q=B[0]-U[0])*q+(q=B[1]-U[1])*q,Q=(Q=G[0]-_[0])*Q+(Q=G[1]-_[1])*Q;Y=y(Y,Math.sqrt(q/Q)),X=[(U[0]+B[0])/2,(U[1]+B[1])/2],L=[(_[0]+G[0])/2,(_[1]+G[1])/2]}else if(k.touch0)X=k.touch0[0],L=k.touch0[1];else return;k.zoom("touch",n(m(Y,X,L),k.extent,i))}}function V(N,...D){if(this.__zooming){var k=E(this,D).event(N),R=N.changedTouches,z=R.length,O,Y;for(Ju(N),h&&clearTimeout(h),h=setTimeout(function(){h=null},p),O=0;O<z;++O)Y=R[O],k.touch0&&k.touch0[2]===Y.identifier?delete k.touch0:k.touch1&&k.touch1[2]===Y.identifier&&delete k.touch1;if(k.touch1&&!k.touch0&&(k.touch0=k.touch1,delete k.touch1),k.touch0)k.touch0[1]=this.__zoom.invert(k.touch0[0]);else if(k.end(),k.taps===2&&(Y=tn(Y,this),Math.hypot(f[0]-Y[0],f[1]-Y[1])<w)){var X=Ct(this).on("dblclick.zoom");X&&X.apply(this,arguments)}}}return g.wheelDelta=function(N){return arguments.length?(l=typeof N=="function"?N:Ur(+N),g):l},g.filter=function(N){return arguments.length?(e=typeof N=="function"?N:Ur(!!N),g):e},g.touchable=function(N){return arguments.length?(a=typeof N=="function"?N:Ur(!!N),g):a},g.extent=function(N){return arguments.length?(t=typeof N=="function"?N:Ur([[+N[0][0],+N[0][1]],[+N[1][0],+N[1][1]]]),g):t},g.scaleExtent=function(N){return arguments.length?(s[0]=+N[0],s[1]=+N[1],g):[s[0],s[1]]},g.translateExtent=function(N){return arguments.length?(i[0][0]=+N[0][0],i[1][0]=+N[1][0],i[0][1]=+N[0][1],i[1][1]=+N[1][1],g):[[i[0][0],i[0][1]],[i[1][0],i[1][1]]]},g.constrain=function(N){return arguments.length?(n=N,g):n},g.duration=function(N){return arguments.length?(r=+N,g):r},g.interpolate=function(N){return arguments.length?(c=N,g):c},g.on=function(){var N=u.on.apply(u,arguments);return N===u?g:N},g.clickDistance=function(N){return arguments.length?(S=(N=+N)*N,g):Math.sqrt(S)},g.tapDistance=function(N){return arguments.length?(w=+N,g):w},g}const jn={error001:()=>"[React Flow]: Seems like you have not used zustand provider as an ancestor. Help: https://reactflow.dev/error#001",error002:()=>"It looks like you've created a new nodeTypes or edgeTypes object. If this wasn't on purpose please define the nodeTypes/edgeTypes outside of the component or memoize them.",error003:e=>`Node type "${e}" not found. Using fallback type "default".`,error004:()=>"The React Flow parent container needs a width and a height to render the graph.",error005:()=>"Only child nodes can use a parent extent.",error006:()=>"Can't create edge. An edge needs a source and a target.",error007:e=>`The old edge with id=${e} does not exist.`,error009:e=>`Marker type "${e}" doesn't exist.`,error008:(e,{id:t,sourceHandle:n,targetHandle:l})=>`Couldn't create edge for ${e} handle id: "${e==="source"?n:l}", edge id: ${t}.`,error010:()=>"Handle: No node id found. Make sure to only use a Handle inside a custom Node.",error011:e=>`Edge type "${e}" not found. Using fallback type "default".`,error012:e=>`Node with id "${e}" does not exist, it may have been removed. This can happen when a node is deleted before the "onNodeClick" handler is called.`,error013:(e="react")=>`It seems that you haven't loaded the styles. Please import '@xyflow/${e}/dist/style.css' or base.css to make sure everything is working properly.`,error014:()=>"useNodeConnections: No node ID found. Call useNodeConnections inside a custom Node or provide a node ID.",error015:()=>"It seems that you are trying to drag a node that is not initialized. Please use onNodesChange as explained in the docs."},Hi=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],X1=["Enter"," ","Escape"],G1={"node.a11yDescription.default":"Press enter or space to select a node. Press delete to remove it and escape to cancel.","node.a11yDescription.keyboardDisabled":"Press enter or space to select a node. You can then use the arrow keys to move the node around. Press delete to remove it and escape to cancel.","node.a11yDescription.ariaLiveMessage":({direction:e,x:t,y:n})=>`Moved selected node ${e}. New position, x: ${t}, y: ${n}`,"edge.a11yDescription.default":"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel.","controls.ariaLabel":"Control Panel","controls.zoomIn.ariaLabel":"Zoom In","controls.zoomOut.ariaLabel":"Zoom Out","controls.fitView.ariaLabel":"Fit View","controls.interactive.ariaLabel":"Toggle Interactivity","minimap.ariaLabel":"Mini Map","handle.ariaLabel":"Handle"};var fs;(function(e){e.Strict="strict",e.Loose="loose"})(fs||(fs={}));var aa;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(aa||(aa={}));var Li;(function(e){e.Partial="partial",e.Full="full"})(Li||(Li={}));const Q1={inProgress:!1,isValid:null,from:null,fromHandle:null,fromPosition:null,fromNode:null,to:null,toHandle:null,toPosition:null,toNode:null,pointer:null};var xl;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(xl||(xl={}));var cc;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(cc||(cc={}));var ee;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(ee||(ee={}));const $m={[ee.Left]:ee.Right,[ee.Right]:ee.Left,[ee.Top]:ee.Bottom,[ee.Bottom]:ee.Top};function Z1(e){return e===null?null:e?"valid":"invalid"}const I1=e=>"id"in e&&"source"in e&&"target"in e,O4=e=>"id"in e&&"position"in e&&!("source"in e)&&!("target"in e),Ph=e=>"id"in e&&"internals"in e&&!("source"in e)&&!("target"in e),ir=(e,t=[0,0])=>{const{width:n,height:l}=nl(e),a=e.origin??t,s=n*a[0],i=l*a[1];return{x:e.position.x-s,y:e.position.y-i}},H4=(e,t={nodeOrigin:[0,0]})=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((l,a)=>{const s=typeof a=="string";let i=!t.nodeLookup&&!s?a:void 0;t.nodeLookup&&(i=s?t.nodeLookup.get(a):Ph(a)?a:t.nodeLookup.get(a.id));const r=i?uc(i,t.nodeOrigin):{x:0,y:0,x2:0,y2:0};return Xc(l,r)},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return Gc(n)},rr=(e,t={})=>{let n={x:1/0,y:1/0,x2:-1/0,y2:-1/0},l=!1;return e.forEach(a=>{(t.filter===void 0||t.filter(a))&&(n=Xc(n,uc(a)),l=!0)}),l?Gc(n):{x:0,y:0,width:0,height:0}},ep=(e,t,[n,l,a]=[0,0,1],s=!1,i=!1)=>{const r={...cr(t,[n,l,a]),width:t.width/a,height:t.height/a},c=[];for(const u of e.values()){const{measured:d,selectable:f=!0,hidden:h=!1}=u;if(i&&!f||h)continue;const p=d.width??u.width??u.initialWidth??null,x=d.height??u.height??u.initialHeight??null,S=$i(r,ps(u)),w=(p??0)*(x??0),g=s&&S>0;(!u.internals.handleBounds||g||S>=w||u.dragging)&&c.push(u)}return c},L4=(e,t)=>{const n=new Set;return e.forEach(l=>{n.add(l.id)}),t.filter(l=>n.has(l.source)||n.has(l.target))};function $4(e,t){const n=new Map,l=t!=null&&t.nodes?new Set(t.nodes.map(a=>a.id)):null;return e.forEach(a=>{a.measured.width&&a.measured.height&&((t==null?void 0:t.includeHiddenNodes)||!a.hidden)&&(!l||l.has(a.id))&&n.set(a.id,a)}),n}async function B4({nodes:e,width:t,height:n,panZoom:l,minZoom:a,maxZoom:s},i){if(e.size===0)return Promise.resolve(!0);const r=$4(e,i),c=rr(r),u=tp(c,t,n,(i==null?void 0:i.minZoom)??a,(i==null?void 0:i.maxZoom)??s,(i==null?void 0:i.padding)??.1);return await l.setViewport(u,{duration:i==null?void 0:i.duration,ease:i==null?void 0:i.ease,interpolate:i==null?void 0:i.interpolate}),Promise.resolve(!0)}function K1({nodeId:e,nextPosition:t,nodeLookup:n,nodeOrigin:l=[0,0],nodeExtent:a,onError:s}){const i=n.get(e),r=i.parentId?n.get(i.parentId):void 0,{x:c,y:u}=r?r.internals.positionAbsolute:{x:0,y:0},d=i.origin??l;let f=i.extent||a;if(i.extent==="parent"&&!i.expandParent)if(!r)s==null||s("005",jn.error005());else{const p=r.measured.width,x=r.measured.height;p&&x&&(f=[[c,u],[c+p,u+x]])}else r&&gs(i.extent)&&(f=[[i.extent[0][0]+c,i.extent[0][1]+u],[i.extent[1][0]+c,i.extent[1][1]+u]]);const h=gs(f)?ha(t,f,i.measured):t;return(i.measured.width===void 0||i.measured.height===void 0)&&(s==null||s("015",jn.error015())),{position:{x:h.x-c+(i.measured.width??0)*d[0],y:h.y-u+(i.measured.height??0)*d[1]},positionAbsolute:h}}async function U4({nodesToRemove:e=[],edgesToRemove:t=[],nodes:n,edges:l,onBeforeDelete:a}){const s=new Set(e.map(h=>h.id)),i=[];for(const h of n){if(h.deletable===!1)continue;const p=s.has(h.id),x=!p&&h.parentId&&i.find(S=>S.id===h.parentId);(p||x)&&i.push(h)}const r=new Set(t.map(h=>h.id)),c=l.filter(h=>h.deletable!==!1),d=L4(i,c);for(const h of c)r.has(h.id)&&!d.find(x=>x.id===h.id)&&d.push(h);if(!a)return{edges:d,nodes:i};const f=await a({nodes:i,edges:d});return typeof f=="boolean"?f?{edges:d,nodes:i}:{edges:[],nodes:[]}:f}const hs=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),ha=(e={x:0,y:0},t,n)=>({x:hs(e.x,t[0][0],t[1][0]-((n==null?void 0:n.width)??0)),y:hs(e.y,t[0][1],t[1][1]-((n==null?void 0:n.height)??0))});function W1(e,t,n){const{width:l,height:a}=nl(n),{x:s,y:i}=n.internals.positionAbsolute;return ha(e,[[s,i],[s+l,i+a]],t)}const Bm=(e,t,n)=>e<t?hs(Math.abs(e-t),1,t)/t:e>n?-hs(Math.abs(e-n),1,t)/t:0,J1=(e,t,n=15,l=40)=>{const a=Bm(e.x,l,t.width-l)*n,s=Bm(e.y,l,t.height-l)*n;return[a,s]},Xc=(e,t)=>({x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x2,t.x2),y2:Math.max(e.y2,t.y2)}),xf=({x:e,y:t,width:n,height:l})=>({x:e,y:t,x2:e+n,y2:t+l}),Gc=({x:e,y:t,x2:n,y2:l})=>({x:e,y:t,width:n-e,height:l-t}),ps=(e,t=[0,0])=>{var a,s;const{x:n,y:l}=Ph(e)?e.internals.positionAbsolute:ir(e,t);return{x:n,y:l,width:((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0,height:((s=e.measured)==null?void 0:s.height)??e.height??e.initialHeight??0}},uc=(e,t=[0,0])=>{var a,s;const{x:n,y:l}=Ph(e)?e.internals.positionAbsolute:ir(e,t);return{x:n,y:l,x2:n+(((a=e.measured)==null?void 0:a.width)??e.width??e.initialWidth??0),y2:l+(((s=e.measured)==null?void 0:s.height)??e.height??e.initialHeight??0)}},F1=(e,t)=>Gc(Xc(xf(e),xf(t))),$i=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),l=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*l)},Um=e=>sn(e.width)&&sn(e.height)&&sn(e.x)&&sn(e.y),sn=e=>!isNaN(e)&&isFinite(e),q4=(e,t)=>{},or=(e,t=[1,1])=>({x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}),cr=({x:e,y:t},[n,l,a],s=!1,i=[1,1])=>{const r={x:(e-n)/a,y:(t-l)/a};return s?or(r,i):r},dc=({x:e,y:t},[n,l,a])=>({x:e*a+n,y:t*a+l});function ja(e,t){if(typeof e=="number")return Math.floor((t-t/(1+e))*.5);if(typeof e=="string"&&e.endsWith("px")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(n)}if(typeof e=="string"&&e.endsWith("%")){const n=parseFloat(e);if(!Number.isNaN(n))return Math.floor(t*n*.01)}return console.error(`[React Flow] The padding value "${e}" is invalid. Please provide a number or a string with a valid unit (px or %).`),0}function Y4(e,t,n){if(typeof e=="string"||typeof e=="number"){const l=ja(e,n),a=ja(e,t);return{top:l,right:a,bottom:l,left:a,x:a*2,y:l*2}}if(typeof e=="object"){const l=ja(e.top??e.y??0,n),a=ja(e.bottom??e.y??0,n),s=ja(e.left??e.x??0,t),i=ja(e.right??e.x??0,t);return{top:l,right:i,bottom:a,left:s,x:s+i,y:l+a}}return{top:0,right:0,bottom:0,left:0,x:0,y:0}}function V4(e,t,n,l,a,s){const{x:i,y:r}=dc(e,[t,n,l]),{x:c,y:u}=dc({x:e.x+e.width,y:e.y+e.height},[t,n,l]),d=a-c,f=s-u;return{left:Math.floor(i),top:Math.floor(r),right:Math.floor(d),bottom:Math.floor(f)}}const tp=(e,t,n,l,a,s)=>{const i=Y4(s,t,n),r=(t-i.x)/e.width,c=(n-i.y)/e.height,u=Math.min(r,c),d=hs(u,l,a),f=e.x+e.width/2,h=e.y+e.height/2,p=t/2-f*d,x=n/2-h*d,S=V4(e,p,x,d,t,n),w={left:Math.min(S.left-i.left,0),top:Math.min(S.top-i.top,0),right:Math.min(S.right-i.right,0),bottom:Math.min(S.bottom-i.bottom,0)};return{x:p-w.left+w.right,y:x-w.top+w.bottom,zoom:d}},Bi=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0};function gs(e){return e!=null&&e!=="parent"}function nl(e){var t,n;return{width:((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth??0,height:((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight??0}}function P1(e){var t,n;return(((t=e.measured)==null?void 0:t.width)??e.width??e.initialWidth)!==void 0&&(((n=e.measured)==null?void 0:n.height)??e.height??e.initialHeight)!==void 0}function eb(e,t={width:0,height:0},n,l,a){const s={...e},i=l.get(n);if(i){const r=i.origin||a;s.x+=i.internals.positionAbsolute.x-(t.width??0)*r[0],s.y+=i.internals.positionAbsolute.y-(t.height??0)*r[1]}return s}function qm(e,t){if(e.size!==t.size)return!1;for(const n of e)if(!t.has(n))return!1;return!0}function X4(){let e,t;return{promise:new Promise((l,a)=>{e=l,t=a}),resolve:e,reject:t}}function G4(e){return{...G1,...e||{}}}function gi(e,{snapGrid:t=[0,0],snapToGrid:n=!1,transform:l,containerBounds:a}){const{x:s,y:i}=rn(e),r=cr({x:s-((a==null?void 0:a.left)??0),y:i-((a==null?void 0:a.top)??0)},l),{x:c,y:u}=n?or(r,t):r;return{xSnapped:c,ySnapped:u,...r}}const np=e=>({width:e.offsetWidth,height:e.offsetHeight}),tb=e=>{var t;return((t=e==null?void 0:e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},Q4=["INPUT","SELECT","TEXTAREA"];function nb(e){var l,a;const t=((a=(l=e.composedPath)==null?void 0:l.call(e))==null?void 0:a[0])||e.target;return(t==null?void 0:t.nodeType)!==1?!1:Q4.includes(t.nodeName)||t.hasAttribute("contenteditable")||!!t.closest(".nokey")}const lb=e=>"clientX"in e,rn=(e,t)=>{var s,i;const n=lb(e),l=n?e.clientX:(s=e.touches)==null?void 0:s[0].clientX,a=n?e.clientY:(i=e.touches)==null?void 0:i[0].clientY;return{x:l-((t==null?void 0:t.left)??0),y:a-((t==null?void 0:t.top)??0)}},Ym=(e,t,n,l,a)=>{const s=t.querySelectorAll(`.${e}`);return!s||!s.length?null:Array.from(s).map(i=>{const r=i.getBoundingClientRect();return{id:i.getAttribute("data-handleid"),type:e,nodeId:a,position:i.getAttribute("data-handlepos"),x:(r.left-n.left)/l,y:(r.top-n.top)/l,...np(i)}})};function ab({sourceX:e,sourceY:t,targetX:n,targetY:l,sourceControlX:a,sourceControlY:s,targetControlX:i,targetControlY:r}){const c=e*.125+a*.375+i*.375+n*.125,u=t*.125+s*.375+r*.375+l*.125,d=Math.abs(c-e),f=Math.abs(u-t);return[c,u,d,f]}function qr(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function Vm({pos:e,x1:t,y1:n,x2:l,y2:a,c:s}){switch(e){case ee.Left:return[t-qr(t-l,s),n];case ee.Right:return[t+qr(l-t,s),n];case ee.Top:return[t,n-qr(n-a,s)];case ee.Bottom:return[t,n+qr(a-n,s)]}}function sb({sourceX:e,sourceY:t,sourcePosition:n=ee.Bottom,targetX:l,targetY:a,targetPosition:s=ee.Top,curvature:i=.25}){const[r,c]=Vm({pos:n,x1:e,y1:t,x2:l,y2:a,c:i}),[u,d]=Vm({pos:s,x1:l,y1:a,x2:e,y2:t,c:i}),[f,h,p,x]=ab({sourceX:e,sourceY:t,targetX:l,targetY:a,sourceControlX:r,sourceControlY:c,targetControlX:u,targetControlY:d});return[`M${e},${t} C${r},${c} ${u},${d} ${l},${a}`,f,h,p,x]}function ib({sourceX:e,sourceY:t,targetX:n,targetY:l}){const a=Math.abs(n-e)/2,s=n<e?n+a:n-a,i=Math.abs(l-t)/2,r=l<t?l+i:l-i;return[s,r,a,i]}function Z4({sourceNode:e,targetNode:t,selected:n=!1,zIndex:l=0,elevateOnSelect:a=!1,zIndexMode:s="basic"}){if(s==="manual")return l;const i=a&&n?l+1e3:l,r=Math.max(e.parentId||a&&e.selected?e.internals.z:0,t.parentId||a&&t.selected?t.internals.z:0);return i+r}function I4({sourceNode:e,targetNode:t,width:n,height:l,transform:a}){const s=Xc(uc(e),uc(t));s.x===s.x2&&(s.x2+=1),s.y===s.y2&&(s.y2+=1);const i={x:-a[0]/a[2],y:-a[1]/a[2],width:n/a[2],height:l/a[2]};return $i(i,Gc(s))>0}const K4=({source:e,sourceHandle:t,target:n,targetHandle:l})=>`xy-edge__${e}${t||""}-${n}${l||""}`,W4=(e,t)=>t.some(n=>n.source===e.source&&n.target===e.target&&(n.sourceHandle===e.sourceHandle||!n.sourceHandle&&!e.sourceHandle)&&(n.targetHandle===e.targetHandle||!n.targetHandle&&!e.targetHandle)),J4=(e,t,n={})=>{if(!e.source||!e.target)return t;const l=n.getEdgeId||K4;let a;return I1(e)?a={...e}:a={...e,id:l(e)},W4(a,t)?t:(a.sourceHandle===null&&delete a.sourceHandle,a.targetHandle===null&&delete a.targetHandle,t.concat(a))};function rb({sourceX:e,sourceY:t,targetX:n,targetY:l}){const[a,s,i,r]=ib({sourceX:e,sourceY:t,targetX:n,targetY:l});return[`M ${e},${t}L ${n},${l}`,a,s,i,r]}const Xm={[ee.Left]:{x:-1,y:0},[ee.Right]:{x:1,y:0},[ee.Top]:{x:0,y:-1},[ee.Bottom]:{x:0,y:1}},F4=({source:e,sourcePosition:t=ee.Bottom,target:n})=>t===ee.Left||t===ee.Right?e.x<n.x?{x:1,y:0}:{x:-1,y:0}:e.y<n.y?{x:0,y:1}:{x:0,y:-1},Gm=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function P4({source:e,sourcePosition:t=ee.Bottom,target:n,targetPosition:l=ee.Top,center:a,offset:s,stepPosition:i}){const r=Xm[t],c=Xm[l],u={x:e.x+r.x*s,y:e.y+r.y*s},d={x:n.x+c.x*s,y:n.y+c.y*s},f=F4({source:u,sourcePosition:t,target:d}),h=f.x!==0?"x":"y",p=f[h];let x=[],S,w;const g={x:0,y:0},y={x:0,y:0},[,,m,v]=ib({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(r[h]*c[h]===-1){h==="x"?(S=a.x??u.x+(d.x-u.x)*i,w=a.y??(u.y+d.y)/2):(S=a.x??(u.x+d.x)/2,w=a.y??u.y+(d.y-u.y)*i);const A=[{x:S,y:u.y},{x:S,y:d.y}],C=[{x:u.x,y:w},{x:d.x,y:w}];r[h]===p?x=h==="x"?A:C:x=h==="x"?C:A}else{const A=[{x:u.x,y:d.y}],C=[{x:d.x,y:u.y}];if(h==="x"?x=r.x===p?C:A:x=r.y===p?A:C,t===l){const N=Math.abs(e[h]-n[h]);if(N<=s){const D=Math.min(s-1,s-N);r[h]===p?g[h]=(u[h]>e[h]?-1:1)*D:y[h]=(d[h]>n[h]?-1:1)*D}}if(t!==l){const N=h==="x"?"y":"x",D=r[h]===c[N],k=u[N]>d[N],R=u[N]<d[N];(r[h]===1&&(!D&&k||D&&R)||r[h]!==1&&(!D&&R||D&&k))&&(x=h==="x"?A:C)}const H={x:u.x+g.x,y:u.y+g.y},T={x:d.x+y.x,y:d.y+y.y},$=Math.max(Math.abs(H.x-x[0].x),Math.abs(T.x-x[0].x)),V=Math.max(Math.abs(H.y-x[0].y),Math.abs(T.y-x[0].y));$>=V?(S=(H.x+T.x)/2,w=x[0].y):(S=x[0].x,w=(H.y+T.y)/2)}const j={x:u.x+g.x,y:u.y+g.y},E={x:d.x+y.x,y:d.y+y.y};return[[e,...j.x!==x[0].x||j.y!==x[0].y?[j]:[],...x,...E.x!==x[x.length-1].x||E.y!==x[x.length-1].y?[E]:[],n],S,w,m,v]}function eM(e,t,n,l){const a=Math.min(Gm(e,t)/2,Gm(t,n)/2,l),{x:s,y:i}=t;if(e.x===s&&s===n.x||e.y===i&&i===n.y)return`L${s} ${i}`;if(e.y===i){const u=e.x<n.x?-1:1,d=e.y<n.y?1:-1;return`L ${s+a*u},${i}Q ${s},${i} ${s},${i+a*d}`}const r=e.x<n.x?1:-1,c=e.y<n.y?-1:1;return`L ${s},${i+a*c}Q ${s},${i} ${s+a*r},${i}`}function yf({sourceX:e,sourceY:t,sourcePosition:n=ee.Bottom,targetX:l,targetY:a,targetPosition:s=ee.Top,borderRadius:i=5,centerX:r,centerY:c,offset:u=20,stepPosition:d=.5}){const[f,h,p,x,S]=P4({source:{x:e,y:t},sourcePosition:n,target:{x:l,y:a},targetPosition:s,center:{x:r,y:c},offset:u,stepPosition:d});let w=`M${f[0].x} ${f[0].y}`;for(let g=1;g<f.length-1;g++)w+=eM(f[g-1],f[g],f[g+1],i);return w+=`L${f[f.length-1].x} ${f[f.length-1].y}`,[w,h,p,x,S]}function Qm(e){var t;return e&&!!(e.internals.handleBounds||(t=e.handles)!=null&&t.length)&&!!(e.measured.width||e.width||e.initialWidth)}function tM(e){var f;const{sourceNode:t,targetNode:n}=e;if(!Qm(t)||!Qm(n))return null;const l=t.internals.handleBounds||Zm(t.handles),a=n.internals.handleBounds||Zm(n.handles),s=Im((l==null?void 0:l.source)??[],e.sourceHandle),i=Im(e.connectionMode===fs.Strict?(a==null?void 0:a.target)??[]:((a==null?void 0:a.target)??[]).concat((a==null?void 0:a.source)??[]),e.targetHandle);if(!s||!i)return(f=e.onError)==null||f.call(e,"008",jn.error008(s?"target":"source",{id:e.id,sourceHandle:e.sourceHandle,targetHandle:e.targetHandle})),null;const r=(s==null?void 0:s.position)||ee.Bottom,c=(i==null?void 0:i.position)||ee.Top,u=pa(t,s,r),d=pa(n,i,c);return{sourceX:u.x,sourceY:u.y,targetX:d.x,targetY:d.y,sourcePosition:r,targetPosition:c}}function Zm(e){if(!e)return null;const t=[],n=[];for(const l of e)l.width=l.width??1,l.height=l.height??1,l.type==="source"?t.push(l):l.type==="target"&&n.push(l);return{source:t,target:n}}function pa(e,t,n=ee.Left,l=!1){const a=((t==null?void 0:t.x)??0)+e.internals.positionAbsolute.x,s=((t==null?void 0:t.y)??0)+e.internals.positionAbsolute.y,{width:i,height:r}=t??nl(e);if(l)return{x:a+i/2,y:s+r/2};switch((t==null?void 0:t.position)??n){case ee.Top:return{x:a+i/2,y:s};case ee.Right:return{x:a+i,y:s+r/2};case ee.Bottom:return{x:a+i/2,y:s+r};case ee.Left:return{x:a,y:s+r/2}}}function Im(e,t){return e&&(t?e.find(n=>n.id===t):e[0])||null}function vf(e,t){return e?typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(l=>`${l}=${e[l]}`).join("&")}`:""}function nM(e,{id:t,defaultColor:n,defaultMarkerStart:l,defaultMarkerEnd:a}){const s=new Set;return e.reduce((i,r)=>([r.markerStart||l,r.markerEnd||a].forEach(c=>{if(c&&typeof c=="object"){const u=vf(c,t);s.has(u)||(i.push({id:u,color:c.color||n,...c}),s.add(u))}}),i),[]).sort((i,r)=>i.id.localeCompare(r.id))}const ob=1e3,lM=10,lp={nodeOrigin:[0,0],nodeExtent:Hi,elevateNodesOnSelect:!0,zIndexMode:"basic",defaults:{}},aM={...lp,checkEquality:!0};function ap(e,t){const n={...e};for(const l in t)t[l]!==void 0&&(n[l]=t[l]);return n}function sM(e,t,n){const l=ap(lp,n);for(const a of e.values())if(a.parentId)ip(a,e,t,l);else{const s=ir(a,l.nodeOrigin),i=gs(a.extent)?a.extent:l.nodeExtent,r=ha(s,i,nl(a));a.internals.positionAbsolute=r}}function iM(e,t){if(!e.handles)return e.measured?t==null?void 0:t.internals.handleBounds:void 0;const n=[],l=[];for(const a of e.handles){const s={id:a.id,width:a.width??1,height:a.height??1,nodeId:e.id,x:a.x,y:a.y,position:a.position,type:a.type};a.type==="source"?n.push(s):a.type==="target"&&l.push(s)}return{source:n,target:l}}function sp(e){return e==="manual"}function bf(e,t,n,l={}){var d,f;const a=ap(aM,l),s={i:0},i=new Map(t),r=a!=null&&a.elevateNodesOnSelect&&!sp(a.zIndexMode)?ob:0;let c=e.length>0,u=!1;t.clear(),n.clear();for(const h of e){let p=i.get(h.id);if(a.checkEquality&&h===(p==null?void 0:p.internals.userNode))t.set(h.id,p);else{const x=ir(h,a.nodeOrigin),S=gs(h.extent)?h.extent:a.nodeExtent,w=ha(x,S,nl(h));p={...a.defaults,...h,measured:{width:(d=h.measured)==null?void 0:d.width,height:(f=h.measured)==null?void 0:f.height},internals:{positionAbsolute:w,handleBounds:iM(h,p),z:cb(h,r,a.zIndexMode),userNode:h}},t.set(h.id,p)}(p.measured===void 0||p.measured.width===void 0||p.measured.height===void 0)&&!p.hidden&&(c=!1),h.parentId&&ip(p,t,n,l,s),u||(u=h.selected??!1)}return{nodesInitialized:c,hasSelectedNodes:u}}function rM(e,t){if(!e.parentId)return;const n=t.get(e.parentId);n?n.set(e.id,e):t.set(e.parentId,new Map([[e.id,e]]))}function ip(e,t,n,l,a){const{elevateNodesOnSelect:s,nodeOrigin:i,nodeExtent:r,zIndexMode:c}=ap(lp,l),u=e.parentId,d=t.get(u);if(!d){console.warn(`Parent node ${u} not found. Please make sure that parent nodes are in front of their child nodes in the nodes array.`);return}rM(e,n),a&&!d.parentId&&d.internals.rootParentIndex===void 0&&c==="auto"&&(d.internals.rootParentIndex=++a.i,d.internals.z=d.internals.z+a.i*lM),a&&d.internals.rootParentIndex!==void 0&&(a.i=d.internals.rootParentIndex);const f=s&&!sp(c)?ob:0,{x:h,y:p,z:x}=oM(e,d,i,r,f,c),{positionAbsolute:S}=e.internals,w=h!==S.x||p!==S.y;(w||x!==e.internals.z)&&t.set(e.id,{...e,internals:{...e.internals,positionAbsolute:w?{x:h,y:p}:S,z:x}})}function cb(e,t,n){const l=sn(e.zIndex)?e.zIndex:0;return sp(n)?l:l+(e.selected?t:0)}function oM(e,t,n,l,a,s){const{x:i,y:r}=t.internals.positionAbsolute,c=nl(e),u=ir(e,n),d=gs(e.extent)?ha(u,e.extent,c):u;let f=ha({x:i+d.x,y:r+d.y},l,c);e.extent==="parent"&&(f=W1(f,c,t));const h=cb(e,a,s),p=t.internals.z??0;return{x:f.x,y:f.y,z:p>=h?p+1:h}}function rp(e,t,n,l=[0,0]){var i;const a=[],s=new Map;for(const r of e){const c=t.get(r.parentId);if(!c)continue;const u=((i=s.get(r.parentId))==null?void 0:i.expandedRect)??ps(c),d=F1(u,r.rect);s.set(r.parentId,{expandedRect:d,parent:c})}return s.size>0&&s.forEach(({expandedRect:r,parent:c},u)=>{var m;const d=c.internals.positionAbsolute,f=nl(c),h=c.origin??l,p=r.x<d.x?Math.round(Math.abs(d.x-r.x)):0,x=r.y<d.y?Math.round(Math.abs(d.y-r.y)):0,S=Math.max(f.width,Math.round(r.width)),w=Math.max(f.height,Math.round(r.height)),g=(S-f.width)*h[0],y=(w-f.height)*h[1];(p>0||x>0||g||y)&&(a.push({id:u,type:"position",position:{x:c.position.x-p+g,y:c.position.y-x+y}}),(m=n.get(u))==null||m.forEach(v=>{e.some(j=>j.id===v.id)||a.push({id:v.id,type:"position",position:{x:v.position.x+p,y:v.position.y+x}})})),(f.width<r.width||f.height<r.height||p||x)&&a.push({id:u,type:"dimensions",setAttributes:!0,dimensions:{width:S+(p?h[0]*p-g:0),height:w+(x?h[1]*x-y:0)}})}),a}function cM(e,t,n,l,a,s,i){const r=l==null?void 0:l.querySelector(".xyflow__viewport");let c=!1;if(!r)return{changes:[],updatedInternals:c};const u=[],d=window.getComputedStyle(r),{m22:f}=new window.DOMMatrixReadOnly(d.transform),h=[];for(const p of e.values()){const x=t.get(p.id);if(!x)continue;if(x.hidden){t.set(x.id,{...x,internals:{...x.internals,handleBounds:void 0}}),c=!0;continue}const S=np(p.nodeElement),w=x.measured.width!==S.width||x.measured.height!==S.height;if(!!(S.width&&S.height&&(w||!x.internals.handleBounds||p.force))){const y=p.nodeElement.getBoundingClientRect(),m=gs(x.extent)?x.extent:s;let{positionAbsolute:v}=x.internals;x.parentId&&x.extent==="parent"?v=W1(v,S,t.get(x.parentId)):m&&(v=ha(v,m,S));const j={...x,measured:S,internals:{...x.internals,positionAbsolute:v,handleBounds:{source:Ym("source",p.nodeElement,y,f,x.id),target:Ym("target",p.nodeElement,y,f,x.id)}}};t.set(x.id,j),x.parentId&&ip(j,t,n,{nodeOrigin:a,zIndexMode:i}),c=!0,w&&(u.push({id:x.id,type:"dimensions",dimensions:S}),x.expandParent&&x.parentId&&h.push({id:x.id,parentId:x.parentId,rect:ps(j,a)}))}}if(h.length>0){const p=rp(h,t,n,a);u.push(...p)}return{changes:u,updatedInternals:c}}async function uM({delta:e,panZoom:t,transform:n,translateExtent:l,width:a,height:s}){if(!t||!e.x&&!e.y)return Promise.resolve(!1);const i=await t.setViewportConstrained({x:n[0]+e.x,y:n[1]+e.y,zoom:n[2]},[[0,0],[a,s]],l),r=!!i&&(i.x!==n[0]||i.y!==n[1]||i.k!==n[2]);return Promise.resolve(r)}function Km(e,t,n,l,a,s){let i=a;const r=l.get(i)||new Map;l.set(i,r.set(n,t)),i=`${a}-${e}`;const c=l.get(i)||new Map;if(l.set(i,c.set(n,t)),s){i=`${a}-${e}-${s}`;const u=l.get(i)||new Map;l.set(i,u.set(n,t))}}function ub(e,t,n){e.clear(),t.clear();for(const l of n){const{source:a,target:s,sourceHandle:i=null,targetHandle:r=null}=l,c={edgeId:l.id,source:a,target:s,sourceHandle:i,targetHandle:r},u=`${a}-${i}--${s}-${r}`,d=`${s}-${r}--${a}-${i}`;Km("source",c,d,e,a,i),Km("target",c,u,e,s,r),t.set(l.id,l)}}function db(e,t){if(!e.parentId)return!1;const n=t.get(e.parentId);return n?n.selected?!0:db(n,t):!1}function Wm(e,t,n){var a;let l=e;do{if((a=l==null?void 0:l.matches)!=null&&a.call(l,t))return!0;if(l===n)return!1;l=l==null?void 0:l.parentElement}while(l);return!1}function dM(e,t,n,l){const a=new Map;for(const[s,i]of e)if((i.selected||i.id===l)&&(!i.parentId||!db(i,e))&&(i.draggable||t&&typeof i.draggable>"u")){const r=e.get(s);r&&a.set(s,{id:s,position:r.position||{x:0,y:0},distance:{x:n.x-r.internals.positionAbsolute.x,y:n.y-r.internals.positionAbsolute.y},extent:r.extent,parentId:r.parentId,origin:r.origin,expandParent:r.expandParent,internals:{positionAbsolute:r.internals.positionAbsolute||{x:0,y:0}},measured:{width:r.measured.width??0,height:r.measured.height??0}})}return a}function Fu({nodeId:e,dragItems:t,nodeLookup:n,dragging:l=!0}){var i,r,c;const a=[];for(const[u,d]of t){const f=(i=n.get(u))==null?void 0:i.internals.userNode;f&&a.push({...f,position:d.position,dragging:l})}if(!e)return[a[0],a];const s=(r=n.get(e))==null?void 0:r.internals.userNode;return[s?{...s,position:((c=t.get(e))==null?void 0:c.position)||s.position,dragging:l}:a[0],a]}function fM({dragItems:e,snapGrid:t,x:n,y:l}){const a=e.values().next().value;if(!a)return null;const s={x:n-a.distance.x,y:l-a.distance.y},i=or(s,t);return{x:i.x-s.x,y:i.y-s.y}}function hM({onNodeMouseDown:e,getStoreItems:t,onDragStart:n,onDrag:l,onDragStop:a}){let s={x:null,y:null},i=0,r=new Map,c=!1,u={x:0,y:0},d=null,f=!1,h=null,p=!1,x=!1,S=null;function w({noDragClassName:y,handleSelector:m,domNode:v,isSelectable:j,nodeId:E,nodeClickDistance:M=0}){h=Ct(v);function A({x:$,y:V}){const{nodeLookup:N,nodeExtent:D,snapGrid:k,snapToGrid:R,nodeOrigin:z,onNodeDrag:O,onSelectionDrag:Y,onError:X,updateNodePositions:L}=t();s={x:$,y:V};let U=!1;const _=r.size>1,B=_&&D?xf(rr(r)):null,G=_&&R?fM({dragItems:r,snapGrid:k,x:$,y:V}):null;for(const[q,Q]of r){if(!N.has(q))continue;let K={x:$-Q.distance.x,y:V-Q.distance.y};R&&(K=G?{x:Math.round(K.x+G.x),y:Math.round(K.y+G.y)}:or(K,k));let W=null;if(_&&D&&!Q.extent&&B){const{positionAbsolute:F}=Q.internals,le=F.x-B.x+D[0][0],ae=F.x+Q.measured.width-B.x2+D[1][0],te=F.y-B.y+D[0][1],ge=F.y+Q.measured.height-B.y2+D[1][1];W=[[le,te],[ae,ge]]}const{position:P,positionAbsolute:J}=K1({nodeId:q,nextPosition:K,nodeLookup:N,nodeExtent:W||D,nodeOrigin:z,onError:X});U=U||Q.position.x!==P.x||Q.position.y!==P.y,Q.position=P,Q.internals.positionAbsolute=J}if(x=x||U,!!U&&(L(r,!0),S&&(l||O||!E&&Y))){const[q,Q]=Fu({nodeId:E,dragItems:r,nodeLookup:N});l==null||l(S,r,q,Q),O==null||O(S,q,Q),E||Y==null||Y(S,Q)}}async function C(){if(!d)return;const{transform:$,panBy:V,autoPanSpeed:N,autoPanOnNodeDrag:D}=t();if(!D){c=!1,cancelAnimationFrame(i);return}const[k,R]=J1(u,d,N);(k!==0||R!==0)&&(s.x=(s.x??0)-k/$[2],s.y=(s.y??0)-R/$[2],await V({x:k,y:R})&&A(s)),i=requestAnimationFrame(C)}function H($){var _;const{nodeLookup:V,multiSelectionActive:N,nodesDraggable:D,transform:k,snapGrid:R,snapToGrid:z,selectNodesOnDrag:O,onNodeDragStart:Y,onSelectionDragStart:X,unselectNodesAndEdges:L}=t();f=!0,(!O||!j)&&!N&&E&&((_=V.get(E))!=null&&_.selected||L()),j&&O&&E&&(e==null||e(E));const U=gi($.sourceEvent,{transform:k,snapGrid:R,snapToGrid:z,containerBounds:d});if(s=U,r=dM(V,D,U,E),r.size>0&&(n||Y||!E&&X)){const[B,G]=Fu({nodeId:E,dragItems:r,nodeLookup:V});n==null||n($.sourceEvent,r,B,G),Y==null||Y($.sourceEvent,B,G),E||X==null||X($.sourceEvent,G)}}const T=M1().clickDistance(M).on("start",$=>{const{domNode:V,nodeDragThreshold:N,transform:D,snapGrid:k,snapToGrid:R}=t();d=(V==null?void 0:V.getBoundingClientRect())||null,p=!1,x=!1,S=$.sourceEvent,N===0&&H($),s=gi($.sourceEvent,{transform:D,snapGrid:k,snapToGrid:R,containerBounds:d}),u=rn($.sourceEvent,d)}).on("drag",$=>{const{autoPanOnNodeDrag:V,transform:N,snapGrid:D,snapToGrid:k,nodeDragThreshold:R,nodeLookup:z}=t(),O=gi($.sourceEvent,{transform:N,snapGrid:D,snapToGrid:k,containerBounds:d});if(S=$.sourceEvent,($.sourceEvent.type==="touchmove"&&$.sourceEvent.touches.length>1||E&&!z.has(E))&&(p=!0),!p){if(!c&&V&&f&&(c=!0,C()),!f){const Y=rn($.sourceEvent,d),X=Y.x-u.x,L=Y.y-u.y;Math.sqrt(X*X+L*L)>R&&H($)}(s.x!==O.xSnapped||s.y!==O.ySnapped)&&r&&f&&(u=rn($.sourceEvent,d),A(O))}}).on("end",$=>{if(!(!f||p)&&(c=!1,f=!1,cancelAnimationFrame(i),r.size>0)){const{nodeLookup:V,updateNodePositions:N,onNodeDragStop:D,onSelectionDragStop:k}=t();if(x&&(N(r,!1),x=!1),a||D||!E&&k){const[R,z]=Fu({nodeId:E,dragItems:r,nodeLookup:V,dragging:!1});a==null||a($.sourceEvent,r,R,z),D==null||D($.sourceEvent,R,z),E||k==null||k($.sourceEvent,z)}}}).filter($=>{const V=$.target;return!$.button&&(!y||!Wm(V,`.${y}`,v))&&(!m||Wm(V,m,v))});h.call(T)}function g(){h==null||h.on(".drag",null)}return{update:w,destroy:g}}function pM(e,t,n){const l=[],a={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(const s of t.values())$i(a,ps(s))>0&&l.push(s);return l}const gM=250;function mM(e,t,n,l){var r,c;let a=[],s=1/0;const i=pM(e,n,t+gM);for(const u of i){const d=[...((r=u.internals.handleBounds)==null?void 0:r.source)??[],...((c=u.internals.handleBounds)==null?void 0:c.target)??[]];for(const f of d){if(l.nodeId===f.nodeId&&l.type===f.type&&l.id===f.id)continue;const{x:h,y:p}=pa(u,f,f.position,!0),x=Math.sqrt(Math.pow(h-e.x,2)+Math.pow(p-e.y,2));x>t||(x<s?(a=[{...f,x:h,y:p}],s=x):x===s&&a.push({...f,x:h,y:p}))}}if(!a.length)return null;if(a.length>1){const u=l.type==="source"?"target":"source";return a.find(d=>d.type===u)??a[0]}return a[0]}function fb(e,t,n,l,a,s=!1){var u,d,f;const i=l.get(e);if(!i)return null;const r=a==="strict"?(u=i.internals.handleBounds)==null?void 0:u[t]:[...((d=i.internals.handleBounds)==null?void 0:d.source)??[],...((f=i.internals.handleBounds)==null?void 0:f.target)??[]],c=(n?r==null?void 0:r.find(h=>h.id===n):r==null?void 0:r[0])??null;return c&&s?{...c,...pa(i,c,c.position,!0)}:c}function hb(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function xM(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}const pb=()=>!0;function yM(e,{connectionMode:t,connectionRadius:n,handleId:l,nodeId:a,edgeUpdaterType:s,isTarget:i,domNode:r,nodeLookup:c,lib:u,autoPanOnConnect:d,flowId:f,panBy:h,cancelConnection:p,onConnectStart:x,onConnect:S,onConnectEnd:w,isValidConnection:g=pb,onReconnectEnd:y,updateConnection:m,getTransform:v,getFromHandle:j,autoPanSpeed:E,dragThreshold:M=1,handleDomNode:A}){const C=tb(e.target);let H=0,T;const{x:$,y:V}=rn(e),N=hb(s,A),D=r==null?void 0:r.getBoundingClientRect();let k=!1;if(!D||!N)return;const R=fb(a,N,l,c,t);if(!R)return;let z=rn(e,D),O=!1,Y=null,X=!1,L=null;function U(){if(!d||!D)return;const[P,J]=J1(z,D,E);h({x:P,y:J}),H=requestAnimationFrame(U)}const _={...R,nodeId:a,type:N,position:R.position},B=c.get(a);let q={inProgress:!0,isValid:null,from:pa(B,_,ee.Left,!0),fromHandle:_,fromPosition:_.position,fromNode:B,to:z,toHandle:null,toPosition:$m[_.position],toNode:null,pointer:z};function Q(){k=!0,m(q),x==null||x(e,{nodeId:a,handleId:l,handleType:N})}M===0&&Q();function K(P){if(!k){const{x:ge,y:I}=rn(P),se=ge-$,Re=I-V;if(!(se*se+Re*Re>M*M))return;Q()}if(!j()||!_){W(P);return}const J=v();z=rn(P,D),T=mM(cr(z,J,!1,[1,1]),n,c,_),O||(U(),O=!0);const F=gb(P,{handle:T,connectionMode:t,fromNodeId:a,fromHandleId:l,fromType:i?"target":"source",isValidConnection:g,doc:C,lib:u,flowId:f,nodeLookup:c});L=F.handleDomNode,Y=F.connection,X=xM(!!T,F.isValid);const le=c.get(a),ae=le?pa(le,_,ee.Left,!0):q.from,te={...q,from:ae,isValid:X,to:F.toHandle&&X?dc({x:F.toHandle.x,y:F.toHandle.y},J):z,toHandle:F.toHandle,toPosition:X&&F.toHandle?F.toHandle.position:$m[_.position],toNode:F.toHandle?c.get(F.toHandle.nodeId):null,pointer:z};m(te),q=te}function W(P){if(!("touches"in P&&P.touches.length>0)){if(k){(T||L)&&Y&&X&&(S==null||S(Y));const{inProgress:J,...F}=q,le={...F,toPosition:q.toHandle?q.toPosition:null};w==null||w(P,le),s&&(y==null||y(P,le))}p(),cancelAnimationFrame(H),O=!1,X=!1,Y=null,L=null,C.removeEventListener("mousemove",K),C.removeEventListener("mouseup",W),C.removeEventListener("touchmove",K),C.removeEventListener("touchend",W)}}C.addEventListener("mousemove",K),C.addEventListener("mouseup",W),C.addEventListener("touchmove",K),C.addEventListener("touchend",W)}function gb(e,{handle:t,connectionMode:n,fromNodeId:l,fromHandleId:a,fromType:s,doc:i,lib:r,flowId:c,isValidConnection:u=pb,nodeLookup:d}){const f=s==="target",h=t?i.querySelector(`.${r}-flow__handle[data-id="${c}-${t==null?void 0:t.nodeId}-${t==null?void 0:t.id}-${t==null?void 0:t.type}"]`):null,{x:p,y:x}=rn(e),S=i.elementFromPoint(p,x),w=S!=null&&S.classList.contains(`${r}-flow__handle`)?S:h,g={handleDomNode:w,isValid:!1,connection:null,toHandle:null};if(w){const y=hb(void 0,w),m=w.getAttribute("data-nodeid"),v=w.getAttribute("data-handleid"),j=w.classList.contains("connectable"),E=w.classList.contains("connectableend");if(!m||!y)return g;const M={source:f?m:l,sourceHandle:f?v:a,target:f?l:m,targetHandle:f?a:v};g.connection=M;const C=j&&E&&(n===fs.Strict?f&&y==="source"||!f&&y==="target":m!==l||v!==a);g.isValid=C&&u(M),g.toHandle=fb(m,y,v,d,n,!0)}return g}const wf={onPointerDown:yM,isValid:gb};function vM({domNode:e,panZoom:t,getTransform:n,getViewScale:l}){const a=Ct(e);function s({translateExtent:r,width:c,height:u,zoomStep:d=1,pannable:f=!0,zoomable:h=!0,inversePan:p=!1}){const x=m=>{if(m.sourceEvent.type!=="wheel"||!t)return;const v=n(),j=m.sourceEvent.ctrlKey&&Bi()?10:1,E=-m.sourceEvent.deltaY*(m.sourceEvent.deltaMode===1?.05:m.sourceEvent.deltaMode?1:.002)*d,M=v[2]*Math.pow(2,E*j);t.scaleTo(M)};let S=[0,0];const w=m=>{(m.sourceEvent.type==="mousedown"||m.sourceEvent.type==="touchstart")&&(S=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY])},g=m=>{const v=n();if(m.sourceEvent.type!=="mousemove"&&m.sourceEvent.type!=="touchmove"||!t)return;const j=[m.sourceEvent.clientX??m.sourceEvent.touches[0].clientX,m.sourceEvent.clientY??m.sourceEvent.touches[0].clientY],E=[j[0]-S[0],j[1]-S[1]];S=j;const M=l()*Math.max(v[2],Math.log(v[2]))*(p?-1:1),A={x:v[0]-E[0]*M,y:v[1]-E[1]*M},C=[[0,0],[c,u]];t.setViewportConstrained({x:A.x,y:A.y,zoom:v[2]},C,r)},y=V1().on("start",w).on("zoom",f?g:null).on("zoom.wheel",h?x:null);a.call(y,{})}function i(){a.on("zoom",null)}return{update:s,destroy:i,pointer:tn}}const Qc=e=>({x:e.x,y:e.y,zoom:e.k}),Pu=({x:e,y:t,zoom:n})=>Vc.translate(e,t).scale(n),qa=(e,t)=>e.target.closest(`.${t}`),mb=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),bM=e=>((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2,ed=(e,t=0,n=bM,l=()=>{})=>{const a=typeof t=="number"&&t>0;return a||l(),a?e.transition().duration(t).ease(n).on("end",l):e},xb=e=>{const t=e.ctrlKey&&Bi()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t};function wM({zoomPanValues:e,noWheelClassName:t,d3Selection:n,d3Zoom:l,panOnScrollMode:a,panOnScrollSpeed:s,zoomOnPinch:i,onPanZoomStart:r,onPanZoom:c,onPanZoomEnd:u}){return d=>{if(qa(d,t))return d.ctrlKey&&d.preventDefault(),!1;d.preventDefault(),d.stopImmediatePropagation();const f=n.property("__zoom").k||1;if(d.ctrlKey&&i){const w=tn(d),g=xb(d),y=f*Math.pow(2,g);l.scaleTo(n,y,w,d);return}const h=d.deltaMode===1?20:1;let p=a===aa.Vertical?0:d.deltaX*h,x=a===aa.Horizontal?0:d.deltaY*h;!Bi()&&d.shiftKey&&a!==aa.Vertical&&(p=d.deltaY*h,x=0),l.translateBy(n,-(p/f)*s,-(x/f)*s,{internal:!0});const S=Qc(n.property("__zoom"));clearTimeout(e.panScrollTimeout),e.isPanScrolling?(c==null||c(d,S),e.panScrollTimeout=setTimeout(()=>{u==null||u(d,S),e.isPanScrolling=!1},150)):(e.isPanScrolling=!0,r==null||r(d,S))}}function SM({noWheelClassName:e,preventScrolling:t,d3ZoomHandler:n}){return function(l,a){const s=l.type==="wheel",i=!t&&s&&!l.ctrlKey,r=qa(l,e);if(l.ctrlKey&&s&&r&&l.preventDefault(),i||r)return null;l.preventDefault(),n.call(this,l,a)}}function NM({zoomPanValues:e,onDraggingChange:t,onPanZoomStart:n}){return l=>{var s,i,r;if((s=l.sourceEvent)!=null&&s.internal)return;const a=Qc(l.transform);e.mouseButton=((i=l.sourceEvent)==null?void 0:i.button)||0,e.isZoomingOrPanning=!0,e.prevViewport=a,((r=l.sourceEvent)==null?void 0:r.type)==="mousedown"&&t(!0),n&&(n==null||n(l.sourceEvent,a))}}function jM({zoomPanValues:e,panOnDrag:t,onPaneContextMenu:n,onTransformChange:l,onPanZoom:a}){return s=>{var i,r;e.usedRightMouseButton=!!(n&&mb(t,e.mouseButton??0)),(i=s.sourceEvent)!=null&&i.sync||l([s.transform.x,s.transform.y,s.transform.k]),a&&!((r=s.sourceEvent)!=null&&r.internal)&&(a==null||a(s.sourceEvent,Qc(s.transform)))}}function kM({zoomPanValues:e,panOnDrag:t,panOnScroll:n,onDraggingChange:l,onPanZoomEnd:a,onPaneContextMenu:s}){return i=>{var r;if(!((r=i.sourceEvent)!=null&&r.internal)&&(e.isZoomingOrPanning=!1,s&&mb(t,e.mouseButton??0)&&!e.usedRightMouseButton&&i.sourceEvent&&s(i.sourceEvent),e.usedRightMouseButton=!1,l(!1),a)){const c=Qc(i.transform);e.prevViewport=c,clearTimeout(e.timerId),e.timerId=setTimeout(()=>{a==null||a(i.sourceEvent,c)},n?150:0)}}}function EM({zoomActivationKeyPressed:e,zoomOnScroll:t,zoomOnPinch:n,panOnDrag:l,panOnScroll:a,zoomOnDoubleClick:s,userSelectionActive:i,noWheelClassName:r,noPanClassName:c,lib:u,connectionInProgress:d}){return f=>{var w;const h=e||t,p=n&&f.ctrlKey,x=f.type==="wheel";if(f.button===1&&f.type==="mousedown"&&(qa(f,`${u}-flow__node`)||qa(f,`${u}-flow__edge`)))return!0;if(!l&&!h&&!a&&!s&&!n||i||d&&!x||qa(f,r)&&x||qa(f,c)&&(!x||a&&x&&!e)||!n&&f.ctrlKey&&x)return!1;if(!n&&f.type==="touchstart"&&((w=f.touches)==null?void 0:w.length)>1)return f.preventDefault(),!1;if(!h&&!a&&!p&&x||!l&&(f.type==="mousedown"||f.type==="touchstart")||Array.isArray(l)&&!l.includes(f.button)&&f.type==="mousedown")return!1;const S=Array.isArray(l)&&l.includes(f.button)||!f.button||f.button<=1;return(!f.ctrlKey||x)&&S}}function CM({domNode:e,minZoom:t,maxZoom:n,translateExtent:l,viewport:a,onPanZoom:s,onPanZoomStart:i,onPanZoomEnd:r,onDraggingChange:c}){const u={isZoomingOrPanning:!1,usedRightMouseButton:!1,prevViewport:{},mouseButton:0,timerId:void 0,panScrollTimeout:void 0,isPanScrolling:!1},d=e.getBoundingClientRect(),f=V1().scaleExtent([t,n]).translateExtent(l),h=Ct(e).call(f);y({x:a.x,y:a.y,zoom:hs(a.zoom,t,n)},[[0,0],[d.width,d.height]],l);const p=h.on("wheel.zoom"),x=h.on("dblclick.zoom");f.wheelDelta(xb);function S(T,$){return h?new Promise(V=>{f==null||f.interpolate(($==null?void 0:$.interpolate)==="linear"?pi:fo).transform(ed(h,$==null?void 0:$.duration,$==null?void 0:$.ease,()=>V(!0)),T)}):Promise.resolve(!1)}function w({noWheelClassName:T,noPanClassName:$,onPaneContextMenu:V,userSelectionActive:N,panOnScroll:D,panOnDrag:k,panOnScrollMode:R,panOnScrollSpeed:z,preventScrolling:O,zoomOnPinch:Y,zoomOnScroll:X,zoomOnDoubleClick:L,zoomActivationKeyPressed:U,lib:_,onTransformChange:B,connectionInProgress:G,paneClickDistance:q,selectionOnDrag:Q}){N&&!u.isZoomingOrPanning&&g();const K=D&&!U&&!N;f.clickDistance(Q?1/0:!sn(q)||q<0?0:q);const W=K?wM({zoomPanValues:u,noWheelClassName:T,d3Selection:h,d3Zoom:f,panOnScrollMode:R,panOnScrollSpeed:z,zoomOnPinch:Y,onPanZoomStart:i,onPanZoom:s,onPanZoomEnd:r}):SM({noWheelClassName:T,preventScrolling:O,d3ZoomHandler:p});if(h.on("wheel.zoom",W,{passive:!1}),!N){const J=NM({zoomPanValues:u,onDraggingChange:c,onPanZoomStart:i});f.on("start",J);const F=jM({zoomPanValues:u,panOnDrag:k,onPaneContextMenu:!!V,onPanZoom:s,onTransformChange:B});f.on("zoom",F);const le=kM({zoomPanValues:u,panOnDrag:k,panOnScroll:D,onPaneContextMenu:V,onPanZoomEnd:r,onDraggingChange:c});f.on("end",le)}const P=EM({zoomActivationKeyPressed:U,panOnDrag:k,zoomOnScroll:X,panOnScroll:D,zoomOnDoubleClick:L,zoomOnPinch:Y,userSelectionActive:N,noPanClassName:$,noWheelClassName:T,lib:_,connectionInProgress:G});f.filter(P),L?h.on("dblclick.zoom",x):h.on("dblclick.zoom",null)}function g(){f.on("zoom",null)}async function y(T,$,V){const N=Pu(T),D=f==null?void 0:f.constrain()(N,$,V);return D&&await S(D),new Promise(k=>k(D))}async function m(T,$){const V=Pu(T);return await S(V,$),new Promise(N=>N(V))}function v(T){if(h){const $=Pu(T),V=h.property("__zoom");(V.k!==T.zoom||V.x!==T.x||V.y!==T.y)&&(f==null||f.transform(h,$,null,{sync:!0}))}}function j(){const T=h?Y1(h.node()):{x:0,y:0,k:1};return{x:T.x,y:T.y,zoom:T.k}}function E(T,$){return h?new Promise(V=>{f==null||f.interpolate(($==null?void 0:$.interpolate)==="linear"?pi:fo).scaleTo(ed(h,$==null?void 0:$.duration,$==null?void 0:$.ease,()=>V(!0)),T)}):Promise.resolve(!1)}function M(T,$){return h?new Promise(V=>{f==null||f.interpolate(($==null?void 0:$.interpolate)==="linear"?pi:fo).scaleBy(ed(h,$==null?void 0:$.duration,$==null?void 0:$.ease,()=>V(!0)),T)}):Promise.resolve(!1)}function A(T){f==null||f.scaleExtent(T)}function C(T){f==null||f.translateExtent(T)}function H(T){const $=!sn(T)||T<0?0:T;f==null||f.clickDistance($)}return{update:w,destroy:g,setViewport:m,setViewportConstrained:y,getViewport:j,scaleTo:E,scaleBy:M,setScaleExtent:A,setTranslateExtent:C,syncViewport:v,setClickDistance:H}}var ms;(function(e){e.Line="line",e.Handle="handle"})(ms||(ms={}));function MM({width:e,prevWidth:t,height:n,prevHeight:l,affectsX:a,affectsY:s}){const i=e-t,r=n-l,c=[i>0?1:i<0?-1:0,r>0?1:r<0?-1:0];return i&&a&&(c[0]=c[0]*-1),r&&s&&(c[1]=c[1]*-1),c}function Jm(e){const t=e.includes("right")||e.includes("left"),n=e.includes("bottom")||e.includes("top"),l=e.includes("left"),a=e.includes("top");return{isHorizontal:t,isVertical:n,affectsX:l,affectsY:a}}function rl(e,t){return Math.max(0,t-e)}function ol(e,t){return Math.max(0,e-t)}function Yr(e,t,n){return Math.max(0,t-e,e-n)}function Fm(e,t){return e?!t:t}function _M(e,t,n,l,a,s,i,r){let{affectsX:c,affectsY:u}=t;const{isHorizontal:d,isVertical:f}=t,h=d&&f,{xSnapped:p,ySnapped:x}=n,{minWidth:S,maxWidth:w,minHeight:g,maxHeight:y}=l,{x:m,y:v,width:j,height:E,aspectRatio:M}=e;let A=Math.floor(d?p-e.pointerX:0),C=Math.floor(f?x-e.pointerY:0);const H=j+(c?-A:A),T=E+(u?-C:C),$=-s[0]*j,V=-s[1]*E;let N=Yr(H,S,w),D=Yr(T,g,y);if(i){let z=0,O=0;c&&A<0?z=rl(m+A+$,i[0][0]):!c&&A>0&&(z=ol(m+H+$,i[1][0])),u&&C<0?O=rl(v+C+V,i[0][1]):!u&&C>0&&(O=ol(v+T+V,i[1][1])),N=Math.max(N,z),D=Math.max(D,O)}if(r){let z=0,O=0;c&&A>0?z=ol(m+A,r[0][0]):!c&&A<0&&(z=rl(m+H,r[1][0])),u&&C>0?O=ol(v+C,r[0][1]):!u&&C<0&&(O=rl(v+T,r[1][1])),N=Math.max(N,z),D=Math.max(D,O)}if(a){if(d){const z=Yr(H/M,g,y)*M;if(N=Math.max(N,z),i){let O=0;!c&&!u||c&&!u&&h?O=ol(v+V+H/M,i[1][1])*M:O=rl(v+V+(c?A:-A)/M,i[0][1])*M,N=Math.max(N,O)}if(r){let O=0;!c&&!u||c&&!u&&h?O=rl(v+H/M,r[1][1])*M:O=ol(v+(c?A:-A)/M,r[0][1])*M,N=Math.max(N,O)}}if(f){const z=Yr(T*M,S,w)/M;if(D=Math.max(D,z),i){let O=0;!c&&!u||u&&!c&&h?O=ol(m+T*M+$,i[1][0])/M:O=rl(m+(u?C:-C)*M+$,i[0][0])/M,D=Math.max(D,O)}if(r){let O=0;!c&&!u||u&&!c&&h?O=rl(m+T*M,r[1][0])/M:O=ol(m+(u?C:-C)*M,r[0][0])/M,D=Math.max(D,O)}}}C=C+(C<0?D:-D),A=A+(A<0?N:-N),a&&(h?H>T*M?C=(Fm(c,u)?-A:A)/M:A=(Fm(c,u)?-C:C)*M:d?(C=A/M,u=c):(A=C*M,c=u));const k=c?m+A:m,R=u?v+C:v;return{width:j+(c?-A:A),height:E+(u?-C:C),x:s[0]*A*(c?-1:1)+k,y:s[1]*C*(u?-1:1)+R}}const yb={width:0,height:0,x:0,y:0},AM={...yb,pointerX:0,pointerY:0,aspectRatio:1};function TM(e){return[[0,0],[e.measured.width,e.measured.height]]}function zM(e,t,n){const l=t.position.x+e.position.x,a=t.position.y+e.position.y,s=e.measured.width??0,i=e.measured.height??0,r=n[0]*s,c=n[1]*i;return[[l-r,a-c],[l+s-r,a+i-c]]}function DM({domNode:e,nodeId:t,getStoreItems:n,onChange:l,onEnd:a}){const s=Ct(e);let i={controlDirection:Jm("bottom-right"),boundaries:{minWidth:0,minHeight:0,maxWidth:Number.MAX_VALUE,maxHeight:Number.MAX_VALUE},resizeDirection:void 0,keepAspectRatio:!1};function r({controlPosition:u,boundaries:d,keepAspectRatio:f,resizeDirection:h,onResizeStart:p,onResize:x,onResizeEnd:S,shouldResize:w}){let g={...yb},y={...AM};i={boundaries:d,resizeDirection:h,keepAspectRatio:f,controlDirection:Jm(u)};let m,v=null,j=[],E,M,A,C=!1;const H=M1().on("start",T=>{const{nodeLookup:$,transform:V,snapGrid:N,snapToGrid:D,nodeOrigin:k,paneDomNode:R}=n();if(m=$.get(t),!m)return;v=(R==null?void 0:R.getBoundingClientRect())??null;const{xSnapped:z,ySnapped:O}=gi(T.sourceEvent,{transform:V,snapGrid:N,snapToGrid:D,containerBounds:v});g={width:m.measured.width??0,height:m.measured.height??0,x:m.position.x??0,y:m.position.y??0},y={...g,pointerX:z,pointerY:O,aspectRatio:g.width/g.height},E=void 0,m.parentId&&(m.extent==="parent"||m.expandParent)&&(E=$.get(m.parentId),M=E&&m.extent==="parent"?TM(E):void 0),j=[],A=void 0;for(const[Y,X]of $)if(X.parentId===t&&(j.push({id:Y,position:{...X.position},extent:X.extent}),X.extent==="parent"||X.expandParent)){const L=zM(X,m,X.origin??k);A?A=[[Math.min(L[0][0],A[0][0]),Math.min(L[0][1],A[0][1])],[Math.max(L[1][0],A[1][0]),Math.max(L[1][1],A[1][1])]]:A=L}p==null||p(T,{...g})}).on("drag",T=>{const{transform:$,snapGrid:V,snapToGrid:N,nodeOrigin:D}=n(),k=gi(T.sourceEvent,{transform:$,snapGrid:V,snapToGrid:N,containerBounds:v}),R=[];if(!m)return;const{x:z,y:O,width:Y,height:X}=g,L={},U=m.origin??D,{width:_,height:B,x:G,y:q}=_M(y,i.controlDirection,k,i.boundaries,i.keepAspectRatio,U,M,A),Q=_!==Y,K=B!==X,W=G!==z&&Q,P=q!==O&&K;if(!W&&!P&&!Q&&!K)return;if((W||P||U[0]===1||U[1]===1)&&(L.x=W?G:g.x,L.y=P?q:g.y,g.x=L.x,g.y=L.y,j.length>0)){const ae=G-z,te=q-O;for(const ge of j)ge.position={x:ge.position.x-ae+U[0]*(_-Y),y:ge.position.y-te+U[1]*(B-X)},R.push(ge)}if((Q||K)&&(L.width=Q&&(!i.resizeDirection||i.resizeDirection==="horizontal")?_:g.width,L.height=K&&(!i.resizeDirection||i.resizeDirection==="vertical")?B:g.height,g.width=L.width,g.height=L.height),E&&m.expandParent){const ae=U[0]*(L.width??0);L.x&&L.x<ae&&(g.x=ae,y.x=y.x-(L.x-ae));const te=U[1]*(L.height??0);L.y&&L.y<te&&(g.y=te,y.y=y.y-(L.y-te))}const J=MM({width:g.width,prevWidth:Y,height:g.height,prevHeight:X,affectsX:i.controlDirection.affectsX,affectsY:i.controlDirection.affectsY}),F={...g,direction:J};(w==null?void 0:w(T,F))!==!1&&(C=!0,x==null||x(T,F),l(L,R))}).on("end",T=>{C&&(S==null||S(T,{...g}),a==null||a({...g}),C=!1)});s.call(H)}function c(){s.on(".drag",null)}return{update:r,destroy:c}}var vb={exports:{}},bb={},wb={exports:{}},Sb={};/**
144
144
  * @license React
145
145
  * use-sync-external-store-shim.production.js
146
146
  *
@@ -148,7 +148,7 @@ ${B.join(`
148
148
  *
149
149
  * This source code is licensed under the MIT license found in the
150
150
  * LICENSE file in the root directory of this source tree.
151
- */var xs=b;function DM(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var RM=typeof Object.is=="function"?Object.is:DM,OM=xs.useState,HM=xs.useEffect,LM=xs.useLayoutEffect,$M=xs.useDebugValue;function BM(e,t){var n=t(),l=OM({inst:{value:n,getSnapshot:t}}),a=l[0].inst,s=l[1];return LM(function(){a.value=n,a.getSnapshot=t,td(a)&&s({inst:a})},[e,n,t]),HM(function(){return td(a)&&s({inst:a}),e(function(){td(a)&&s({inst:a})})},[e]),$M(n),n}function td(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!RM(e,n)}catch{return!0}}function UM(e,t){return t()}var qM=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?UM:BM;Sb.useSyncExternalStore=xs.useSyncExternalStore!==void 0?xs.useSyncExternalStore:qM;wb.exports=Sb;var YM=wb.exports;/**
151
+ */var xs=b;function RM(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var OM=typeof Object.is=="function"?Object.is:RM,HM=xs.useState,LM=xs.useEffect,$M=xs.useLayoutEffect,BM=xs.useDebugValue;function UM(e,t){var n=t(),l=HM({inst:{value:n,getSnapshot:t}}),a=l[0].inst,s=l[1];return $M(function(){a.value=n,a.getSnapshot=t,td(a)&&s({inst:a})},[e,n,t]),LM(function(){return td(a)&&s({inst:a}),e(function(){td(a)&&s({inst:a})})},[e]),BM(n),n}function td(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!OM(e,n)}catch{return!0}}function qM(e,t){return t()}var YM=typeof window>"u"||typeof window.document>"u"||typeof window.document.createElement>"u"?qM:UM;Sb.useSyncExternalStore=xs.useSyncExternalStore!==void 0?xs.useSyncExternalStore:YM;wb.exports=Sb;var VM=wb.exports;/**
152
152
  * @license React
153
153
  * use-sync-external-store-shim/with-selector.production.js
154
154
  *
@@ -156,10 +156,10 @@ ${B.join(`
156
156
  *
157
157
  * This source code is licensed under the MIT license found in the
158
158
  * LICENSE file in the root directory of this source tree.
159
- */var Zc=b,VM=YM;function XM(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var GM=typeof Object.is=="function"?Object.is:XM,QM=VM.useSyncExternalStore,ZM=Zc.useRef,IM=Zc.useEffect,KM=Zc.useMemo,WM=Zc.useDebugValue;bb.useSyncExternalStoreWithSelector=function(e,t,n,l,a){var s=ZM(null);if(s.current===null){var i={hasValue:!1,value:null};s.current=i}else i=s.current;s=KM(function(){function c(p){if(!u){if(u=!0,d=p,p=l(p),a!==void 0&&i.hasValue){var x=i.value;if(a(x,p))return f=x}return f=p}if(x=f,GM(d,p))return x;var S=l(p);return a!==void 0&&a(x,S)?(d=p,x):(d=p,f=S)}var u=!1,d,f,h=n===void 0?null:n;return[function(){return c(t())},h===null?void 0:function(){return c(h())}]},[t,n,l,a]);var r=QM(e,s[0],s[1]);return IM(function(){i.hasValue=!0,i.value=r},[r]),WM(r),r};vb.exports=bb;var JM=vb.exports;const FM=jx(JM),PM={},Pm=e=>{let t;const n=new Set,l=(d,f)=>{const h=typeof d=="function"?d(t):d;if(!Object.is(h,t)){const p=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(x=>x(t,p))}},a=()=>t,c={setState:l,getState:a,getInitialState:()=>u,subscribe:d=>(n.add(d),()=>n.delete(d)),destroy:()=>{(PM?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(l,a,c);return c},e_=e=>e?Pm(e):Pm,{useDebugValue:t_}=Me,{useSyncExternalStoreWithSelector:n_}=FM,l_=e=>e;function Nb(e,t=l_,n){const l=n_(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return t_(l),l}const ex=(e,t)=>{const n=e_(e),l=(a,s=t)=>Nb(n,a,s);return Object.assign(l,n),l},a_=(e,t)=>e?ex(e,t):ex;function ze(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[l,a]of e)if(!Object.is(a,t.get(l)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const l of e)if(!t.has(l))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const l of n)if(!Object.prototype.hasOwnProperty.call(t,l)||!Object.is(e[l],t[l]))return!1;return!0}const Ic=b.createContext(null),s_=Ic.Provider,jb=jn.error001();function he(e,t){const n=b.useContext(Ic);if(n===null)throw new Error(jb);return Nb(n,e,t)}function De(){const e=b.useContext(Ic);if(e===null)throw new Error(jb);return b.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const tx={display:"none"},i_={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},kb="react-flow__node-desc",Eb="react-flow__edge-desc",r_="react-flow__aria-live",o_=e=>e.ariaLiveMessage,c_=e=>e.ariaLabelConfig;function u_({rfId:e}){const t=he(o_);return o.jsx("div",{id:`${r_}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:i_,children:t})}function d_({rfId:e,disableKeyboardA11y:t}){const n=he(c_);return o.jsxs(o.Fragment,{children:[o.jsx("div",{id:`${kb}-${e}`,style:tx,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),o.jsx("div",{id:`${Eb}-${e}`,style:tx,children:n["edge.a11yDescription.default"]}),!t&&o.jsx(u_,{rfId:e})]})}const Kc=b.forwardRef(({position:e="top-left",children:t,className:n,style:l,...a},s)=>{const i=`${e}`.split("-");return o.jsx("div",{className:Ve(["react-flow__panel",n,...i]),style:l,ref:s,...a,children:t})});Kc.displayName="Panel";function f_({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:o.jsx(Kc,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:o.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const h_=e=>{const t=[],n=[];for(const[,l]of e.nodeLookup)l.selected&&t.push(l.internals.userNode);for(const[,l]of e.edgeLookup)l.selected&&n.push(l);return{selectedNodes:t,selectedEdges:n}},Vr=e=>e.id;function p_(e,t){return ze(e.selectedNodes.map(Vr),t.selectedNodes.map(Vr))&&ze(e.selectedEdges.map(Vr),t.selectedEdges.map(Vr))}function g_({onSelectionChange:e}){const t=De(),{selectedNodes:n,selectedEdges:l}=he(h_,p_);return b.useEffect(()=>{const a={nodes:n,edges:l};e==null||e(a),t.getState().onSelectionChangeHandlers.forEach(s=>s(a))},[n,l,e]),null}const m_=e=>!!e.onSelectionChangeHandlers;function x_({onSelectionChange:e}){const t=he(m_);return e||t?o.jsx(g_,{onSelectionChange:e}):null}const Sf=typeof window<"u"?b.useLayoutEffect:b.useEffect,Cb=[0,0],y_={x:0,y:0,zoom:1},v_=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],nx=[...v_,"rfId"],b_=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),lx={translateExtent:Hi,nodeOrigin:Cb,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function w_(e){const{setNodes:t,setEdges:n,setMinZoom:l,setMaxZoom:a,setTranslateExtent:s,setNodeExtent:i,reset:r,setDefaultNodesAndEdges:c}=he(b_,ze),u=De();Sf(()=>(c(e.defaultNodes,e.defaultEdges),()=>{d.current=lx,r()}),[]);const d=b.useRef(lx);return Sf(()=>{for(const f of nx){const h=e[f],p=d.current[f];h!==p&&(typeof e[f]>"u"||(f==="nodes"?t(h):f==="edges"?n(h):f==="minZoom"?l(h):f==="maxZoom"?a(h):f==="translateExtent"?s(h):f==="nodeExtent"?i(h):f==="ariaLabelConfig"?u.setState({ariaLabelConfig:X4(h)}):f==="fitView"?u.setState({fitViewQueued:h}):f==="fitViewOptions"?u.setState({fitViewOptions:h}):u.setState({[f]:h})))}d.current=e},nx.map(f=>e[f])),null}function ax(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function S_(e){var l;const[t,n]=b.useState(e==="system"?null:e);return b.useEffect(()=>{if(e!=="system"){n(e);return}const a=ax(),s=()=>n(a!=null&&a.matches?"dark":"light");return s(),a==null||a.addEventListener("change",s),()=>{a==null||a.removeEventListener("change",s)}},[e]),t!==null?t:(l=ax())!=null&&l.matches?"dark":"light"}const sx=typeof document<"u"?document:null;function Ui(e=null,t={target:sx,actInsideInputWithModifier:!0}){const[n,l]=b.useState(!1),a=b.useRef(!1),s=b.useRef(new Set([])),[i,r]=b.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
159
+ */var Zc=b,XM=VM;function GM(e,t){return e===t&&(e!==0||1/e===1/t)||e!==e&&t!==t}var QM=typeof Object.is=="function"?Object.is:GM,ZM=XM.useSyncExternalStore,IM=Zc.useRef,KM=Zc.useEffect,WM=Zc.useMemo,JM=Zc.useDebugValue;bb.useSyncExternalStoreWithSelector=function(e,t,n,l,a){var s=IM(null);if(s.current===null){var i={hasValue:!1,value:null};s.current=i}else i=s.current;s=WM(function(){function c(p){if(!u){if(u=!0,d=p,p=l(p),a!==void 0&&i.hasValue){var x=i.value;if(a(x,p))return f=x}return f=p}if(x=f,QM(d,p))return x;var S=l(p);return a!==void 0&&a(x,S)?(d=p,x):(d=p,f=S)}var u=!1,d,f,h=n===void 0?null:n;return[function(){return c(t())},h===null?void 0:function(){return c(h())}]},[t,n,l,a]);var r=ZM(e,s[0],s[1]);return KM(function(){i.hasValue=!0,i.value=r},[r]),JM(r),r};vb.exports=bb;var FM=vb.exports;const PM=jx(FM),e_={},Pm=e=>{let t;const n=new Set,l=(d,f)=>{const h=typeof d=="function"?d(t):d;if(!Object.is(h,t)){const p=t;t=f??(typeof h!="object"||h===null)?h:Object.assign({},t,h),n.forEach(x=>x(t,p))}},a=()=>t,c={setState:l,getState:a,getInitialState:()=>u,subscribe:d=>(n.add(d),()=>n.delete(d)),destroy:()=>{(e_?"production":void 0)!=="production"&&console.warn("[DEPRECATED] The `destroy` method will be unsupported in a future version. Instead use unsubscribe function returned by subscribe. Everything will be garbage-collected if store is garbage-collected."),n.clear()}},u=t=e(l,a,c);return c},t_=e=>e?Pm(e):Pm,{useDebugValue:n_}=Me,{useSyncExternalStoreWithSelector:l_}=PM,a_=e=>e;function Nb(e,t=a_,n){const l=l_(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return n_(l),l}const ex=(e,t)=>{const n=t_(e),l=(a,s=t)=>Nb(n,a,s);return Object.assign(l,n),l},s_=(e,t)=>e?ex(e,t):ex;function ze(e,t){if(Object.is(e,t))return!0;if(typeof e!="object"||e===null||typeof t!="object"||t===null)return!1;if(e instanceof Map&&t instanceof Map){if(e.size!==t.size)return!1;for(const[l,a]of e)if(!Object.is(a,t.get(l)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const l of e)if(!t.has(l))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const l of n)if(!Object.prototype.hasOwnProperty.call(t,l)||!Object.is(e[l],t[l]))return!1;return!0}const Ic=b.createContext(null),i_=Ic.Provider,jb=jn.error001();function he(e,t){const n=b.useContext(Ic);if(n===null)throw new Error(jb);return Nb(n,e,t)}function De(){const e=b.useContext(Ic);if(e===null)throw new Error(jb);return b.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe}),[e])}const tx={display:"none"},r_={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},kb="react-flow__node-desc",Eb="react-flow__edge-desc",o_="react-flow__aria-live",c_=e=>e.ariaLiveMessage,u_=e=>e.ariaLabelConfig;function d_({rfId:e}){const t=he(c_);return o.jsx("div",{id:`${o_}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:r_,children:t})}function f_({rfId:e,disableKeyboardA11y:t}){const n=he(u_);return o.jsxs(o.Fragment,{children:[o.jsx("div",{id:`${kb}-${e}`,style:tx,children:t?n["node.a11yDescription.default"]:n["node.a11yDescription.keyboardDisabled"]}),o.jsx("div",{id:`${Eb}-${e}`,style:tx,children:n["edge.a11yDescription.default"]}),!t&&o.jsx(d_,{rfId:e})]})}const Kc=b.forwardRef(({position:e="top-left",children:t,className:n,style:l,...a},s)=>{const i=`${e}`.split("-");return o.jsx("div",{className:Ve(["react-flow__panel",n,...i]),style:l,ref:s,...a,children:t})});Kc.displayName="Panel";function h_({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:o.jsx(Kc,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://pro.reactflow.dev",children:o.jsx("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution",children:"React Flow"})})}const p_=e=>{const t=[],n=[];for(const[,l]of e.nodeLookup)l.selected&&t.push(l.internals.userNode);for(const[,l]of e.edgeLookup)l.selected&&n.push(l);return{selectedNodes:t,selectedEdges:n}},Vr=e=>e.id;function g_(e,t){return ze(e.selectedNodes.map(Vr),t.selectedNodes.map(Vr))&&ze(e.selectedEdges.map(Vr),t.selectedEdges.map(Vr))}function m_({onSelectionChange:e}){const t=De(),{selectedNodes:n,selectedEdges:l}=he(p_,g_);return b.useEffect(()=>{const a={nodes:n,edges:l};e==null||e(a),t.getState().onSelectionChangeHandlers.forEach(s=>s(a))},[n,l,e]),null}const x_=e=>!!e.onSelectionChangeHandlers;function y_({onSelectionChange:e}){const t=he(x_);return e||t?o.jsx(m_,{onSelectionChange:e}):null}const Sf=typeof window<"u"?b.useLayoutEffect:b.useEffect,Cb=[0,0],v_={x:0,y:0,zoom:1},b_=["nodes","edges","defaultNodes","defaultEdges","onConnect","onConnectStart","onConnectEnd","onClickConnectStart","onClickConnectEnd","nodesDraggable","autoPanOnNodeFocus","nodesConnectable","nodesFocusable","edgesFocusable","edgesReconnectable","elevateNodesOnSelect","elevateEdgesOnSelect","minZoom","maxZoom","nodeExtent","onNodesChange","onEdgesChange","elementsSelectable","connectionMode","snapGrid","snapToGrid","translateExtent","connectOnClick","defaultEdgeOptions","fitView","fitViewOptions","onNodesDelete","onEdgesDelete","onDelete","onNodeDrag","onNodeDragStart","onNodeDragStop","onSelectionDrag","onSelectionDragStart","onSelectionDragStop","onMoveStart","onMove","onMoveEnd","noPanClassName","nodeOrigin","autoPanOnConnect","autoPanOnNodeDrag","onError","connectionRadius","isValidConnection","selectNodesOnDrag","nodeDragThreshold","connectionDragThreshold","onBeforeDelete","debug","autoPanSpeed","ariaLabelConfig","zIndexMode"],nx=[...b_,"rfId"],w_=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges}),lx={translateExtent:Hi,nodeOrigin:Cb,minZoom:.5,maxZoom:2,elementsSelectable:!0,noPanClassName:"nopan",rfId:"1"};function S_(e){const{setNodes:t,setEdges:n,setMinZoom:l,setMaxZoom:a,setTranslateExtent:s,setNodeExtent:i,reset:r,setDefaultNodesAndEdges:c}=he(w_,ze),u=De();Sf(()=>(c(e.defaultNodes,e.defaultEdges),()=>{d.current=lx,r()}),[]);const d=b.useRef(lx);return Sf(()=>{for(const f of nx){const h=e[f],p=d.current[f];h!==p&&(typeof e[f]>"u"||(f==="nodes"?t(h):f==="edges"?n(h):f==="minZoom"?l(h):f==="maxZoom"?a(h):f==="translateExtent"?s(h):f==="nodeExtent"?i(h):f==="ariaLabelConfig"?u.setState({ariaLabelConfig:G4(h)}):f==="fitView"?u.setState({fitViewQueued:h}):f==="fitViewOptions"?u.setState({fitViewOptions:h}):u.setState({[f]:h})))}d.current=e},nx.map(f=>e[f])),null}function ax(){return typeof window>"u"||!window.matchMedia?null:window.matchMedia("(prefers-color-scheme: dark)")}function N_(e){var l;const[t,n]=b.useState(e==="system"?null:e);return b.useEffect(()=>{if(e!=="system"){n(e);return}const a=ax(),s=()=>n(a!=null&&a.matches?"dark":"light");return s(),a==null||a.addEventListener("change",s),()=>{a==null||a.removeEventListener("change",s)}},[e]),t!==null?t:(l=ax())!=null&&l.matches?"dark":"light"}const sx=typeof document<"u"?document:null;function Ui(e=null,t={target:sx,actInsideInputWithModifier:!0}){const[n,l]=b.useState(!1),a=b.useRef(!1),s=b.useRef(new Set([])),[i,r]=b.useMemo(()=>{if(e!==null){const u=(Array.isArray(e)?e:[e]).filter(f=>typeof f=="string").map(f=>f.replace("+",`
160
160
  `).replace(`
161
161
 
162
162
  `,`
163
163
  +`).split(`
164
- `)),d=u.reduce((f,h)=>f.concat(...h),[]);return[u,d]}return[[],[]]},[e]);return b.useEffect(()=>{const c=(t==null?void 0:t.target)??sx,u=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const d=p=>{var w,g;if(a.current=p.ctrlKey||p.metaKey||p.shiftKey||p.altKey,(!a.current||a.current&&!u)&&nb(p))return!1;const S=rx(p.code,r);if(s.current.add(p[S]),ix(i,s.current,!1)){const y=((g=(w=p.composedPath)==null?void 0:w.call(p))==null?void 0:g[0])||p.target,m=(y==null?void 0:y.nodeName)==="BUTTON"||(y==null?void 0:y.nodeName)==="A";t.preventDefault!==!1&&(a.current||!m)&&p.preventDefault(),l(!0)}},f=p=>{const x=rx(p.code,r);ix(i,s.current,!0)?(l(!1),s.current.clear()):s.current.delete(p[x]),p.key==="Meta"&&s.current.clear(),a.current=!1},h=()=>{s.current.clear(),l(!1)};return c==null||c.addEventListener("keydown",d),c==null||c.addEventListener("keyup",f),window.addEventListener("blur",h),window.addEventListener("contextmenu",h),()=>{c==null||c.removeEventListener("keydown",d),c==null||c.removeEventListener("keyup",f),window.removeEventListener("blur",h),window.removeEventListener("contextmenu",h)}}},[e,l]),n}function ix(e,t,n){return e.filter(l=>n||l.length===t.size).some(l=>l.every(a=>t.has(a)))}function rx(e,t){return t.includes(e)?"code":"key"}const N_=()=>{const e=De();return b.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:l}=e.getState();return l?l.scaleTo(t,n):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[l,a,s],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??l,y:t.y??a,zoom:t.zoom??s},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,l]=e.getState().transform;return{x:t,y:n,zoom:l}},setCenter:async(t,n,l)=>e.getState().setCenter(t,n,l),fitBounds:async(t,n)=>{const{width:l,height:a,minZoom:s,maxZoom:i,panZoom:r}=e.getState(),c=tp(t,l,a,s,i,(n==null?void 0:n.padding)??.1);return r?(await r.setViewport(c,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:l,snapGrid:a,snapToGrid:s,domNode:i}=e.getState();if(!i)return t;const{x:r,y:c}=i.getBoundingClientRect(),u={x:t.x-r,y:t.y-c},d=n.snapGrid??a,f=n.snapToGrid??s;return cr(u,l,f,d)},flowToScreenPosition:t=>{const{transform:n,domNode:l}=e.getState();if(!l)return t;const{x:a,y:s}=l.getBoundingClientRect(),i=dc(t,n);return{x:i.x+a,y:i.y+s}}}),[])};function Mb(e,t){const n=[],l=new Map,a=[];for(const s of e)if(s.type==="add"){a.push(s);continue}else if(s.type==="remove"||s.type==="replace")l.set(s.id,[s]);else{const i=l.get(s.id);i?i.push(s):l.set(s.id,[s])}for(const s of t){const i=l.get(s.id);if(!i){n.push(s);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const r={...s};for(const c of i)j_(c,r);n.push(r)}return a.length&&a.forEach(s=>{s.index!==void 0?n.splice(s.index,0,{...s.item}):n.push({...s.item})}),n}function j_(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function _b(e,t){return Mb(e,t)}function Ab(e,t){return Mb(e,t)}function Il(e,t){return{id:e,type:"select",selected:t}}function Ya(e,t=new Set,n=!1){const l=[];for(const[a,s]of e){const i=t.has(a);!(s.selected===void 0&&!i)&&s.selected!==i&&(n&&(s.selected=i),l.push(Il(s.id,i)))}return l}function ox({items:e=[],lookup:t}){var a;const n=[],l=new Map(e.map(s=>[s.id,s]));for(const[s,i]of e.entries()){const r=t.get(i.id),c=((a=r==null?void 0:r.internals)==null?void 0:a.userNode)??r;c!==void 0&&c!==i&&n.push({id:i.id,item:i,type:"replace"}),c===void 0&&n.push({item:i,type:"add",index:s})}for(const[s]of t)l.get(s)===void 0&&n.push({id:s,type:"remove"});return n}function cx(e){return{id:e.id,type:"remove"}}const ux=e=>R4(e),k_=e=>I1(e);function Tb(e){return b.forwardRef(e)}function dx(e){const[t,n]=b.useState(BigInt(0)),[l]=b.useState(()=>E_(()=>n(a=>a+BigInt(1))));return Sf(()=>{const a=l.get();a.length&&(e(a),l.reset())},[t]),l}function E_(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const zb=b.createContext(null);function C_({children:e}){const t=De(),n=b.useCallback(r=>{const{nodes:c=[],setNodes:u,hasDefaultNodes:d,onNodesChange:f,nodeLookup:h,fitViewQueued:p,onNodesChangeMiddlewareMap:x}=t.getState();let S=c;for(const g of r)S=typeof g=="function"?g(S):g;let w=ox({items:S,lookup:h});for(const g of x.values())w=g(w);d&&u(S),w.length>0?f==null||f(w):p&&window.requestAnimationFrame(()=>{const{fitViewQueued:g,nodes:y,setNodes:m}=t.getState();g&&m(y)})},[]),l=dx(n),a=b.useCallback(r=>{const{edges:c=[],setEdges:u,hasDefaultEdges:d,onEdgesChange:f,edgeLookup:h}=t.getState();let p=c;for(const x of r)p=typeof x=="function"?x(p):x;d?u(p):f&&f(ox({items:p,lookup:h}))},[]),s=dx(a),i=b.useMemo(()=>({nodeQueue:l,edgeQueue:s}),[]);return o.jsx(zb.Provider,{value:i,children:e})}function M_(){const e=b.useContext(zb);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const __=e=>!!e.panZoom;function op(){const e=N_(),t=De(),n=M_(),l=he(__),a=b.useMemo(()=>{const s=f=>t.getState().nodeLookup.get(f),i=f=>{n.nodeQueue.push(f)},r=f=>{n.edgeQueue.push(f)},c=f=>{var g,y;const{nodeLookup:h,nodeOrigin:p}=t.getState(),x=ux(f)?f:h.get(f.id),S=x.parentId?eb(x.position,x.measured,x.parentId,h,p):x.position,w={...x,position:S,width:((g=x.measured)==null?void 0:g.width)??x.width,height:((y=x.measured)==null?void 0:y.height)??x.height};return ps(w)},u=(f,h,p={replace:!1})=>{i(x=>x.map(S=>{if(S.id===f){const w=typeof h=="function"?h(S):h;return p.replace&&ux(w)?w:{...S,...w}}return S}))},d=(f,h,p={replace:!1})=>{r(x=>x.map(S=>{if(S.id===f){const w=typeof h=="function"?h(S):h;return p.replace&&k_(w)?w:{...S,...w}}return S}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>{var h;return(h=s(f))==null?void 0:h.internals.userNode},getInternalNode:s,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(h=>({...h}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:i,setEdges:r,addNodes:f=>{const h=Array.isArray(f)?f:[f];n.nodeQueue.push(p=>[...p,...h])},addEdges:f=>{const h=Array.isArray(f)?f:[f];n.edgeQueue.push(p=>[...p,...h])},toObject:()=>{const{nodes:f=[],edges:h=[],transform:p}=t.getState(),[x,S,w]=p;return{nodes:f.map(g=>({...g})),edges:h.map(g=>({...g})),viewport:{x,y:S,zoom:w}}},deleteElements:async({nodes:f=[],edges:h=[]})=>{const{nodes:p,edges:x,onNodesDelete:S,onEdgesDelete:w,triggerNodeChanges:g,triggerEdgeChanges:y,onDelete:m,onBeforeDelete:v}=t.getState(),{nodes:j,edges:E}=await B4({nodesToRemove:f,edgesToRemove:h,nodes:p,edges:x,onBeforeDelete:v}),M=E.length>0,A=j.length>0;if(M){const C=E.map(cx);w==null||w(E),y(C)}if(A){const C=j.map(cx);S==null||S(j),g(C)}return(A||M)&&(m==null||m({nodes:j,edges:E})),{deletedNodes:j,deletedEdges:E}},getIntersectingNodes:(f,h=!0,p)=>{const x=Um(f),S=x?f:c(f),w=p!==void 0;return S?(p||t.getState().nodes).filter(g=>{const y=t.getState().nodeLookup.get(g.id);if(y&&!x&&(g.id===f.id||!y.internals.positionAbsolute))return!1;const m=ps(w?g:y),v=$i(m,S);return h&&v>0||v>=m.width*m.height||v>=S.width*S.height}):[]},isNodeIntersecting:(f,h,p=!0)=>{const S=Um(f)?f:c(f);if(!S)return!1;const w=$i(S,h);return p&&w>0||w>=h.width*h.height||w>=S.width*S.height},updateNode:u,updateNodeData:(f,h,p={replace:!1})=>{u(f,x=>{const S=typeof h=="function"?h(x):h;return p.replace?{...x,data:S}:{...x,data:{...x.data,...S}}},p)},updateEdge:d,updateEdgeData:(f,h,p={replace:!1})=>{d(f,x=>{const S=typeof h=="function"?h(x):h;return p.replace?{...x,data:S}:{...x,data:{...x.data,...S}}},p)},getNodesBounds:f=>{const{nodeLookup:h,nodeOrigin:p}=t.getState();return O4(f,{nodeLookup:h,nodeOrigin:p})},getHandleConnections:({type:f,id:h,nodeId:p})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${p}-${f}${h?`-${h}`:""}`))==null?void 0:x.values())??[])},getNodeConnections:({type:f,handleId:h,nodeId:p})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${p}${f?h?`-${f}-${h}`:`-${f}`:""}`))==null?void 0:x.values())??[])},fitView:async f=>{const h=t.getState().fitViewResolver??V4();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:h}),n.nodeQueue.push(p=>[...p]),h.promise}}},[]);return b.useMemo(()=>({...a,...e,viewportInitialized:l}),[l])}const fx=e=>e.selected,A_=typeof window<"u"?window:void 0;function T_({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=De(),{deleteElements:l}=op(),a=Ui(e,{actInsideInputWithModifier:!1}),s=Ui(t,{target:A_});b.useEffect(()=>{if(a){const{edges:i,nodes:r}=n.getState();l({nodes:r.filter(fx),edges:i.filter(fx)}),n.setState({nodesSelectionActive:!1})}},[a]),b.useEffect(()=>{n.setState({multiSelectionActive:s})},[s])}function z_(e){const t=De();b.useEffect(()=>{const n=()=>{var a,s,i,r;if(!e.current||!(((s=(a=e.current).checkVisibility)==null?void 0:s.call(a))??!0))return!1;const l=np(e.current);(l.height===0||l.width===0)&&((r=(i=t.getState()).onError)==null||r.call(i,"004",jn.error004())),t.setState({width:l.width||500,height:l.height||500})};if(e.current){n(),window.addEventListener("resize",n);const l=new ResizeObserver(()=>n());return l.observe(e.current),()=>{window.removeEventListener("resize",n),l&&e.current&&l.unobserve(e.current)}}},[])}const Wc={position:"absolute",width:"100%",height:"100%",top:0,left:0},D_=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function R_({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:l=!1,panOnScrollSpeed:a=.5,panOnScrollMode:s=aa.Free,zoomOnDoubleClick:i=!0,panOnDrag:r=!0,defaultViewport:c,translateExtent:u,minZoom:d,maxZoom:f,zoomActivationKeyCode:h,preventScrolling:p=!0,children:x,noWheelClassName:S,noPanClassName:w,onViewportChange:g,isControlledViewport:y,paneClickDistance:m,selectionOnDrag:v}){const j=De(),E=b.useRef(null),{userSelectionActive:M,lib:A,connectionInProgress:C}=he(D_,ze),H=Ui(h),T=b.useRef();z_(E);const $=b.useCallback(V=>{g==null||g({x:V[0],y:V[1],zoom:V[2]}),y||j.setState({transform:V})},[g,y]);return b.useEffect(()=>{if(E.current){T.current=EM({domNode:E.current,minZoom:d,maxZoom:f,translateExtent:u,viewport:c,onDraggingChange:k=>j.setState(R=>R.paneDragging===k?R:{paneDragging:k}),onPanZoomStart:(k,R)=>{const{onViewportChangeStart:z,onMoveStart:O}=j.getState();O==null||O(k,R),z==null||z(R)},onPanZoom:(k,R)=>{const{onViewportChange:z,onMove:O}=j.getState();O==null||O(k,R),z==null||z(R)},onPanZoomEnd:(k,R)=>{const{onViewportChangeEnd:z,onMoveEnd:O}=j.getState();O==null||O(k,R),z==null||z(R)}});const{x:V,y:N,zoom:D}=T.current.getViewport();return j.setState({panZoom:T.current,transform:[V,N,D],domNode:E.current.closest(".react-flow")}),()=>{var k;(k=T.current)==null||k.destroy()}}},[]),b.useEffect(()=>{var V;(V=T.current)==null||V.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:l,panOnScrollSpeed:a,panOnScrollMode:s,zoomOnDoubleClick:i,panOnDrag:r,zoomActivationKeyPressed:H,preventScrolling:p,noPanClassName:w,userSelectionActive:M,noWheelClassName:S,lib:A,onTransformChange:$,connectionInProgress:C,selectionOnDrag:v,paneClickDistance:m})},[e,t,n,l,a,s,i,r,H,p,w,M,S,A,$,C,v,m]),o.jsx("div",{className:"react-flow__renderer",ref:E,style:Wc,children:x})}const O_=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function H_(){const{userSelectionActive:e,userSelectionRect:t}=he(O_,ze);return e&&t?o.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const nd=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},L_=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function $_({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Li.Full,panOnDrag:l,paneClickDistance:a,selectionOnDrag:s,onSelectionStart:i,onSelectionEnd:r,onPaneClick:c,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:h,onPaneMouseLeave:p,children:x}){const S=De(),{userSelectionActive:w,elementsSelectable:g,dragging:y,connectionInProgress:m}=he(L_,ze),v=g&&(e||w),j=b.useRef(null),E=b.useRef(),M=b.useRef(new Set),A=b.useRef(new Set),C=b.useRef(!1),H=z=>{if(C.current||m){C.current=!1;return}c==null||c(z),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},T=z=>{if(Array.isArray(l)&&(l!=null&&l.includes(2))){z.preventDefault();return}u==null||u(z)},$=d?z=>d(z):void 0,V=z=>{C.current&&(z.stopPropagation(),C.current=!1)},N=z=>{var B,G;const{domNode:O}=S.getState();if(E.current=O==null?void 0:O.getBoundingClientRect(),!E.current)return;const Y=z.target===j.current;if(!Y&&!!z.target.closest(".nokey")||!e||!(s&&Y||t)||z.button!==0||!z.isPrimary)return;(G=(B=z.target)==null?void 0:B.setPointerCapture)==null||G.call(B,z.pointerId),C.current=!1;const{x:U,y:_}=rn(z.nativeEvent,E.current);S.setState({userSelectionRect:{width:0,height:0,startX:U,startY:_,x:U,y:_}}),Y||(z.stopPropagation(),z.preventDefault())},D=z=>{const{userSelectionRect:O,transform:Y,nodeLookup:X,edgeLookup:L,connectionLookup:U,triggerNodeChanges:_,triggerEdgeChanges:B,defaultEdgeOptions:G,resetSelectedElements:q}=S.getState();if(!E.current||!O)return;const{x:Q,y:K}=rn(z.nativeEvent,E.current),{startX:W,startY:P}=O;if(!C.current){const te=t?0:a;if(Math.hypot(Q-W,K-P)<=te)return;q(),i==null||i(z)}C.current=!0;const J={startX:W,startY:P,x:Q<W?Q:W,y:K<P?K:P,width:Math.abs(Q-W),height:Math.abs(K-P)},F=M.current,le=A.current;M.current=new Set(ep(X,J,Y,n===Li.Partial,!0).map(te=>te.id)),A.current=new Set;const ae=(G==null?void 0:G.selectable)??!0;for(const te of M.current){const ge=U.get(te);if(ge)for(const{edgeId:I}of ge.values()){const se=L.get(I);se&&(se.selectable??ae)&&A.current.add(I)}}if(!qm(F,M.current)){const te=Ya(X,M.current,!0);_(te)}if(!qm(le,A.current)){const te=Ya(L,A.current);B(te)}S.setState({userSelectionRect:J,userSelectionActive:!0,nodesSelectionActive:!1})},k=z=>{var O,Y;z.button===0&&((Y=(O=z.target)==null?void 0:O.releasePointerCapture)==null||Y.call(O,z.pointerId),!w&&z.target===j.current&&S.getState().userSelectionRect&&(H==null||H(z)),S.setState({userSelectionActive:!1,userSelectionRect:null}),C.current&&(r==null||r(z),S.setState({nodesSelectionActive:M.current.size>0})))},R=l===!0||Array.isArray(l)&&l.includes(0);return o.jsxs("div",{className:Ve(["react-flow__pane",{draggable:R,dragging:y,selection:e}]),onClick:v?void 0:nd(H,j),onContextMenu:nd(T,j),onWheel:nd($,j),onPointerEnter:v?void 0:f,onPointerMove:v?D:h,onPointerUp:v?k:void 0,onPointerDownCapture:v?N:void 0,onClickCapture:v?V:void 0,onPointerLeave:p,ref:j,style:Wc,children:[x,o.jsx(H_,{})]})}function Nf({id:e,store:t,unselect:n=!1,nodeRef:l}){const{addSelectedNodes:a,unselectNodesAndEdges:s,multiSelectionActive:i,nodeLookup:r,onError:c}=t.getState(),u=r.get(e);if(!u){c==null||c("012",jn.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&i)&&(s({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var d;return(d=l==null?void 0:l.current)==null?void 0:d.blur()})):a([e])}function Db({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:l,nodeId:a,isSelectable:s,nodeClickDistance:i}){const r=De(),[c,u]=b.useState(!1),d=b.useRef();return b.useEffect(()=>{d.current=fM({getStoreItems:()=>r.getState(),onNodeMouseDown:f=>{Nf({id:f,store:r,nodeRef:e})},onDragStart:()=>{u(!0)},onDragStop:()=>{u(!1)}})},[]),b.useEffect(()=>{if(!(t||!e.current||!d.current))return d.current.update({noDragClassName:n,handleSelector:l,domNode:e.current,isSelectable:s,nodeId:a,nodeClickDistance:i}),()=>{var f;(f=d.current)==null||f.destroy()}},[n,l,t,s,e,a,i]),c}const B_=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Rb(){const e=De();return b.useCallback(n=>{const{nodeExtent:l,snapToGrid:a,snapGrid:s,nodesDraggable:i,onError:r,updateNodePositions:c,nodeLookup:u,nodeOrigin:d}=e.getState(),f=new Map,h=B_(i),p=a?s[0]:5,x=a?s[1]:5,S=n.direction.x*p*n.factor,w=n.direction.y*x*n.factor;for(const[,g]of u){if(!h(g))continue;let y={x:g.internals.positionAbsolute.x+S,y:g.internals.positionAbsolute.y+w};a&&(y=or(y,s));const{position:m,positionAbsolute:v}=K1({nodeId:g.id,nextPosition:y,nodeLookup:u,nodeExtent:l,nodeOrigin:d,onError:r});g.position=m,g.internals.positionAbsolute=v,f.set(g.id,g)}c(f)},[])}const cp=b.createContext(null),U_=cp.Provider;cp.Consumer;const Ob=()=>b.useContext(cp),q_=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),Y_=(e,t,n)=>l=>{const{connectionClickStartHandle:a,connectionMode:s,connection:i}=l,{fromHandle:r,toHandle:c,isValid:u}=i,d=(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.id)===t&&(c==null?void 0:c.type)===n;return{connectingFrom:(r==null?void 0:r.nodeId)===e&&(r==null?void 0:r.id)===t&&(r==null?void 0:r.type)===n,connectingTo:d,clickConnecting:(a==null?void 0:a.nodeId)===e&&(a==null?void 0:a.id)===t&&(a==null?void 0:a.type)===n,isPossibleEndHandle:s===fs.Strict?(r==null?void 0:r.type)!==n:e!==(r==null?void 0:r.nodeId)||t!==(r==null?void 0:r.id),connectionInProcess:!!r,clickConnectionInProcess:!!a,valid:d&&u}};function V_({type:e="source",position:t=ee.Top,isValidConnection:n,isConnectable:l=!0,isConnectableStart:a=!0,isConnectableEnd:s=!0,id:i,onConnect:r,children:c,className:u,onMouseDown:d,onTouchStart:f,...h},p){var D,k;const x=i||null,S=e==="target",w=De(),g=Ob(),{connectOnClick:y,noPanClassName:m,rfId:v}=he(q_,ze),{connectingFrom:j,connectingTo:E,clickConnecting:M,isPossibleEndHandle:A,connectionInProcess:C,clickConnectionInProcess:H,valid:T}=he(Y_(g,x,e),ze);g||(k=(D=w.getState()).onError)==null||k.call(D,"010",jn.error010());const $=R=>{const{defaultEdgeOptions:z,onConnect:O,hasDefaultEdges:Y}=w.getState(),X={...z,...R};if(Y){const{edges:L,setEdges:U}=w.getState();U(W4(X,L))}O==null||O(X),r==null||r(X)},V=R=>{if(!g)return;const z=lb(R.nativeEvent);if(a&&(z&&R.button===0||!z)){const O=w.getState();wf.onPointerDown(R.nativeEvent,{handleDomNode:R.currentTarget,autoPanOnConnect:O.autoPanOnConnect,connectionMode:O.connectionMode,connectionRadius:O.connectionRadius,domNode:O.domNode,nodeLookup:O.nodeLookup,lib:O.lib,isTarget:S,handleId:x,nodeId:g,flowId:O.rfId,panBy:O.panBy,cancelConnection:O.cancelConnection,onConnectStart:O.onConnectStart,onConnectEnd:(...Y)=>{var X,L;return(L=(X=w.getState()).onConnectEnd)==null?void 0:L.call(X,...Y)},updateConnection:O.updateConnection,onConnect:$,isValidConnection:n||((...Y)=>{var X,L;return((L=(X=w.getState()).isValidConnection)==null?void 0:L.call(X,...Y))??!0}),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:O.autoPanSpeed,dragThreshold:O.connectionDragThreshold})}z?d==null||d(R):f==null||f(R)},N=R=>{const{onClickConnectStart:z,onClickConnectEnd:O,connectionClickStartHandle:Y,connectionMode:X,isValidConnection:L,lib:U,rfId:_,nodeLookup:B,connection:G}=w.getState();if(!g||!Y&&!a)return;if(!Y){z==null||z(R.nativeEvent,{nodeId:g,handleId:x,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:g,type:e,id:x}});return}const q=tb(R.target),Q=n||L,{connection:K,isValid:W}=wf.isValid(R.nativeEvent,{handle:{nodeId:g,id:x,type:e},connectionMode:X,fromNodeId:Y.nodeId,fromHandleId:Y.id||null,fromType:Y.type,isValidConnection:Q,flowId:_,doc:q,lib:U,nodeLookup:B});W&&K&&$(K);const P=structuredClone(G);delete P.inProgress,P.toPosition=P.toHandle?P.toHandle.position:null,O==null||O(R,P),w.setState({connectionClickStartHandle:null})};return o.jsx("div",{"data-handleid":x,"data-nodeid":g,"data-handlepos":t,"data-id":`${v}-${g}-${x}-${e}`,className:Ve(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",m,u,{source:!S,target:S,connectable:l,connectablestart:a,connectableend:s,clickconnecting:M,connectingfrom:j,connectingto:E,valid:T,connectionindicator:l&&(!C||A)&&(C||H?s:a)}]),onMouseDown:V,onTouchStart:V,onClick:y?N:void 0,ref:p,...h,children:c})}const ys=b.memo(Tb(V_));function X_({data:e,isConnectable:t,sourcePosition:n=ee.Bottom}){return o.jsxs(o.Fragment,{children:[e==null?void 0:e.label,o.jsx(ys,{type:"source",position:n,isConnectable:t})]})}function G_({data:e,isConnectable:t,targetPosition:n=ee.Top,sourcePosition:l=ee.Bottom}){return o.jsxs(o.Fragment,{children:[o.jsx(ys,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,o.jsx(ys,{type:"source",position:l,isConnectable:t})]})}function Q_(){return null}function Z_({data:e,isConnectable:t,targetPosition:n=ee.Top}){return o.jsxs(o.Fragment,{children:[o.jsx(ys,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const fc={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},hx={input:X_,default:G_,output:Z_,group:Q_};function I_(e){var t,n,l,a;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((l=e.style)==null?void 0:l.width),height:e.height??((a=e.style)==null?void 0:a.height)}}const K_=e=>{const{width:t,height:n,x:l,y:a}=rr(e.nodeLookup,{filter:s=>!!s.selected});return{width:sn(t)?t:null,height:sn(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${l}px,${a}px)`}};function W_({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const l=De(),{width:a,height:s,transformString:i,userSelectionActive:r}=he(K_,ze),c=Rb(),u=b.useRef(null);b.useEffect(()=>{var p;n||(p=u.current)==null||p.focus({preventScroll:!0})},[n]);const d=!r&&a!==null&&s!==null;if(Db({nodeRef:u,disabled:!d}),!d)return null;const f=e?p=>{const x=l.getState().nodes.filter(S=>S.selected);e(p,x)}:void 0,h=p=>{Object.prototype.hasOwnProperty.call(fc,p.key)&&(p.preventDefault(),c({direction:fc[p.key],factor:p.shiftKey?4:1}))};return o.jsx("div",{className:Ve(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:o.jsx("div",{ref:u,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:h,style:{width:a,height:s}})})}const px=typeof window<"u"?window:void 0,J_=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Hb({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:l,onPaneMouseLeave:a,onPaneContextMenu:s,onPaneScroll:i,paneClickDistance:r,deleteKeyCode:c,selectionKeyCode:u,selectionOnDrag:d,selectionMode:f,onSelectionStart:h,onSelectionEnd:p,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:w,elementsSelectable:g,zoomOnScroll:y,zoomOnPinch:m,panOnScroll:v,panOnScrollSpeed:j,panOnScrollMode:E,zoomOnDoubleClick:M,panOnDrag:A,defaultViewport:C,translateExtent:H,minZoom:T,maxZoom:$,preventScrolling:V,onSelectionContextMenu:N,noWheelClassName:D,noPanClassName:k,disableKeyboardA11y:R,onViewportChange:z,isControlledViewport:O}){const{nodesSelectionActive:Y,userSelectionActive:X}=he(J_,ze),L=Ui(u,{target:px}),U=Ui(S,{target:px}),_=U||A,B=U||v,G=d&&_!==!0,q=L||X||G;return T_({deleteKeyCode:c,multiSelectionKeyCode:x}),o.jsx(R_,{onPaneContextMenu:s,elementsSelectable:g,zoomOnScroll:y,zoomOnPinch:m,panOnScroll:B,panOnScrollSpeed:j,panOnScrollMode:E,zoomOnDoubleClick:M,panOnDrag:!L&&_,defaultViewport:C,translateExtent:H,minZoom:T,maxZoom:$,zoomActivationKeyCode:w,preventScrolling:V,noWheelClassName:D,noPanClassName:k,onViewportChange:z,isControlledViewport:O,paneClickDistance:r,selectionOnDrag:G,children:o.jsxs($_,{onSelectionStart:h,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:l,onPaneMouseLeave:a,onPaneContextMenu:s,onPaneScroll:i,panOnDrag:_,isSelecting:!!q,selectionMode:f,selectionKeyPressed:L,paneClickDistance:r,selectionOnDrag:G,children:[e,Y&&o.jsx(W_,{onSelectionContextMenu:N,noPanClassName:k,disableKeyboardA11y:R})]})})}Hb.displayName="FlowRenderer";const F_=b.memo(Hb),P_=e=>t=>e?ep(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function eA(e){return he(b.useCallback(P_(e),[e]),ze)}const tA=e=>e.updateNodeInternals;function nA(){const e=he(tA),[t]=b.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const l=new Map;n.forEach(a=>{const s=a.target.getAttribute("data-id");l.set(s,{id:s,nodeElement:a.target,force:!0})}),e(l)}));return b.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function lA({node:e,nodeType:t,hasDimensions:n,resizeObserver:l}){const a=De(),s=b.useRef(null),i=b.useRef(null),r=b.useRef(e.sourcePosition),c=b.useRef(e.targetPosition),u=b.useRef(t),d=n&&!!e.internals.handleBounds;return b.useEffect(()=>{s.current&&!e.hidden&&(!d||i.current!==s.current)&&(i.current&&(l==null||l.unobserve(i.current)),l==null||l.observe(s.current),i.current=s.current)},[d,e.hidden]),b.useEffect(()=>()=>{i.current&&(l==null||l.unobserve(i.current),i.current=null)},[]),b.useEffect(()=>{if(s.current){const f=u.current!==t,h=r.current!==e.sourcePosition,p=c.current!==e.targetPosition;(f||h||p)&&(u.current=t,r.current=e.sourcePosition,c.current=e.targetPosition,a.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:s.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),s}function aA({id:e,onClick:t,onMouseEnter:n,onMouseMove:l,onMouseLeave:a,onContextMenu:s,onDoubleClick:i,nodesDraggable:r,elementsSelectable:c,nodesConnectable:u,nodesFocusable:d,resizeObserver:f,noDragClassName:h,noPanClassName:p,disableKeyboardA11y:x,rfId:S,nodeTypes:w,nodeClickDistance:g,onError:y}){const{node:m,internals:v,isParent:j}=he(Q=>{const K=Q.nodeLookup.get(e),W=Q.parentLookup.has(e);return{node:K,internals:K.internals,isParent:W}},ze);let E=m.type||"default",M=(w==null?void 0:w[E])||hx[E];M===void 0&&(y==null||y("003",jn.error003(E)),E="default",M=(w==null?void 0:w.default)||hx.default);const A=!!(m.draggable||r&&typeof m.draggable>"u"),C=!!(m.selectable||c&&typeof m.selectable>"u"),H=!!(m.connectable||u&&typeof m.connectable>"u"),T=!!(m.focusable||d&&typeof m.focusable>"u"),$=De(),V=P1(m),N=lA({node:m,nodeType:E,hasDimensions:V,resizeObserver:f}),D=Db({nodeRef:N,disabled:m.hidden||!A,noDragClassName:h,handleSelector:m.dragHandle,nodeId:e,isSelectable:C,nodeClickDistance:g}),k=Rb();if(m.hidden)return null;const R=nl(m),z=I_(m),O=C||A||t||n||l||a,Y=n?Q=>n(Q,{...v.userNode}):void 0,X=l?Q=>l(Q,{...v.userNode}):void 0,L=a?Q=>a(Q,{...v.userNode}):void 0,U=s?Q=>s(Q,{...v.userNode}):void 0,_=i?Q=>i(Q,{...v.userNode}):void 0,B=Q=>{const{selectNodesOnDrag:K,nodeDragThreshold:W}=$.getState();C&&(!K||!A||W>0)&&Nf({id:e,store:$,nodeRef:N}),t&&t(Q,{...v.userNode})},G=Q=>{if(!(nb(Q.nativeEvent)||x)){if(X1.includes(Q.key)&&C){const K=Q.key==="Escape";Nf({id:e,store:$,unselect:K,nodeRef:N})}else if(A&&m.selected&&Object.prototype.hasOwnProperty.call(fc,Q.key)){Q.preventDefault();const{ariaLabelConfig:K}=$.getState();$.setState({ariaLiveMessage:K["node.a11yDescription.ariaLiveMessage"]({direction:Q.key.replace("Arrow","").toLowerCase(),x:~~v.positionAbsolute.x,y:~~v.positionAbsolute.y})}),k({direction:fc[Q.key],factor:Q.shiftKey?4:1})}}},q=()=>{var le;if(x||!((le=N.current)!=null&&le.matches(":focus-visible")))return;const{transform:Q,width:K,height:W,autoPanOnNodeFocus:P,setCenter:J}=$.getState();if(!P)return;ep(new Map([[e,m]]),{x:0,y:0,width:K,height:W},Q,!0).length>0||J(m.position.x+R.width/2,m.position.y+R.height/2,{zoom:Q[2]})};return o.jsx("div",{className:Ve(["react-flow__node",`react-flow__node-${E}`,{[p]:A},m.className,{selected:m.selected,selectable:C,parent:j,draggable:A,dragging:D}]),ref:N,style:{zIndex:v.z,transform:`translate(${v.positionAbsolute.x}px,${v.positionAbsolute.y}px)`,pointerEvents:O?"all":"none",visibility:V?"visible":"hidden",...m.style,...z},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:Y,onMouseMove:X,onMouseLeave:L,onContextMenu:U,onClick:B,onDoubleClick:_,onKeyDown:T?G:void 0,tabIndex:T?0:void 0,onFocus:T?q:void 0,role:m.ariaRole??(T?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${kb}-${S}`,"aria-label":m.ariaLabel,...m.domAttributes,children:o.jsx(U_,{value:e,children:o.jsx(M,{id:e,data:m.data,type:E,positionAbsoluteX:v.positionAbsolute.x,positionAbsoluteY:v.positionAbsolute.y,selected:m.selected??!1,selectable:C,draggable:A,deletable:m.deletable??!0,isConnectable:H,sourcePosition:m.sourcePosition,targetPosition:m.targetPosition,dragging:D,dragHandle:m.dragHandle,zIndex:v.z,parentId:m.parentId,...R})})})}var sA=b.memo(aA);const iA=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Lb(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:l,elementsSelectable:a,onError:s}=he(iA,ze),i=eA(e.onlyRenderVisibleElements),r=nA();return o.jsx("div",{className:"react-flow__nodes",style:Wc,children:i.map(c=>o.jsx(sA,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:r,nodesDraggable:t,nodesConnectable:n,nodesFocusable:l,elementsSelectable:a,nodeClickDistance:e.nodeClickDistance,onError:s},c))})}Lb.displayName="NodeRenderer";const rA=b.memo(Lb);function oA(e){return he(b.useCallback(n=>{if(!e)return n.edges.map(a=>a.id);const l=[];if(n.width&&n.height)for(const a of n.edges){const s=n.nodeLookup.get(a.source),i=n.nodeLookup.get(a.target);s&&i&&Z4({sourceNode:s,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&l.push(a.id)}return l},[e]),ze)}const cA=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return o.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},uA=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return o.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},gx={[cc.Arrow]:cA,[cc.ArrowClosed]:uA};function dA(e){const t=De();return b.useMemo(()=>{var a,s;return Object.prototype.hasOwnProperty.call(gx,e)?gx[e]:((s=(a=t.getState()).onError)==null||s.call(a,"009",jn.error009(e)),null)},[e])}const fA=({id:e,type:t,color:n,width:l=12.5,height:a=12.5,markerUnits:s="strokeWidth",strokeWidth:i,orient:r="auto-start-reverse"})=>{const c=dA(t);return c?o.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${l}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:s,orient:r,refX:"0",refY:"0",children:o.jsx(c,{color:n,strokeWidth:i})}):null},$b=({defaultColor:e,rfId:t})=>{const n=he(s=>s.edges),l=he(s=>s.defaultEdgeOptions),a=b.useMemo(()=>tM(n,{id:t,defaultColor:e,defaultMarkerStart:l==null?void 0:l.markerStart,defaultMarkerEnd:l==null?void 0:l.markerEnd}),[n,l,t,e]);return a.length?o.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:o.jsx("defs",{children:a.map(s=>o.jsx(fA,{id:s.id,type:s.type,color:s.color,width:s.width,height:s.height,markerUnits:s.markerUnits,strokeWidth:s.strokeWidth,orient:s.orient},s.id))})}):null};$b.displayName="MarkerDefinitions";var hA=b.memo($b);function Bb({x:e,y:t,label:n,labelStyle:l,labelShowBg:a=!0,labelBgStyle:s,labelBgPadding:i=[2,4],labelBgBorderRadius:r=2,children:c,className:u,...d}){const[f,h]=b.useState({x:1,y:0,width:0,height:0}),p=Ve(["react-flow__edge-textwrapper",u]),x=b.useRef(null);return b.useEffect(()=>{if(x.current){const S=x.current.getBBox();h({x:S.x,y:S.y,width:S.width,height:S.height})}},[n]),n?o.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:p,visibility:f.width?"visible":"hidden",...d,children:[a&&o.jsx("rect",{width:f.width+2*i[0],x:-i[0],y:-i[1],height:f.height+2*i[1],className:"react-flow__edge-textbg",style:s,rx:r,ry:r}),o.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:x,style:l,children:n}),c]}):null}Bb.displayName="EdgeText";const pA=b.memo(Bb);function Jc({path:e,labelX:t,labelY:n,label:l,labelStyle:a,labelShowBg:s,labelBgStyle:i,labelBgPadding:r,labelBgBorderRadius:c,interactionWidth:u=20,...d}){return o.jsxs(o.Fragment,{children:[o.jsx("path",{...d,d:e,fill:"none",className:Ve(["react-flow__edge-path",d.className])}),u?o.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:u,className:"react-flow__edge-interaction"}):null,l&&sn(t)&&sn(n)?o.jsx(pA,{x:t,y:n,label:l,labelStyle:a,labelShowBg:s,labelBgStyle:i,labelBgPadding:r,labelBgBorderRadius:c}):null]})}function mx({pos:e,x1:t,y1:n,x2:l,y2:a}){return e===ee.Left||e===ee.Right?[.5*(t+l),n]:[t,.5*(n+a)]}function Ub({sourceX:e,sourceY:t,sourcePosition:n=ee.Bottom,targetX:l,targetY:a,targetPosition:s=ee.Top}){const[i,r]=mx({pos:n,x1:e,y1:t,x2:l,y2:a}),[c,u]=mx({pos:s,x1:l,y1:a,x2:e,y2:t}),[d,f,h,p]=ab({sourceX:e,sourceY:t,targetX:l,targetY:a,sourceControlX:i,sourceControlY:r,targetControlX:c,targetControlY:u});return[`M${e},${t} C${i},${r} ${c},${u} ${l},${a}`,d,f,h,p]}function qb(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,sourcePosition:i,targetPosition:r,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,interactionWidth:g})=>{const[y,m,v]=Ub({sourceX:n,sourceY:l,sourcePosition:i,targetX:a,targetY:s,targetPosition:r}),j=e.isInternal?void 0:t;return o.jsx(Jc,{id:j,path:y,labelX:m,labelY:v,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,interactionWidth:g})})}const gA=qb({isInternal:!1}),Yb=qb({isInternal:!0});gA.displayName="SimpleBezierEdge";Yb.displayName="SimpleBezierEdgeInternal";function Vb(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,sourcePosition:p=ee.Bottom,targetPosition:x=ee.Top,markerEnd:S,markerStart:w,pathOptions:g,interactionWidth:y})=>{const[m,v,j]=yf({sourceX:n,sourceY:l,sourcePosition:p,targetX:a,targetY:s,targetPosition:x,borderRadius:g==null?void 0:g.borderRadius,offset:g==null?void 0:g.offset,stepPosition:g==null?void 0:g.stepPosition}),E=e.isInternal?void 0:t;return o.jsx(Jc,{id:E,path:m,labelX:v,labelY:j,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,markerEnd:S,markerStart:w,interactionWidth:y})})}const Xb=Vb({isInternal:!1}),Gb=Vb({isInternal:!0});Xb.displayName="SmoothStepEdge";Gb.displayName="SmoothStepEdgeInternal";function Qb(e){return b.memo(({id:t,...n})=>{var a;const l=e.isInternal?void 0:t;return o.jsx(Xb,{...n,id:l,pathOptions:b.useMemo(()=>{var s;return{borderRadius:0,offset:(s=n.pathOptions)==null?void 0:s.offset}},[(a=n.pathOptions)==null?void 0:a.offset])})})}const mA=Qb({isInternal:!1}),Zb=Qb({isInternal:!0});mA.displayName="StepEdge";Zb.displayName="StepEdgeInternal";function Ib(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,markerEnd:p,markerStart:x,interactionWidth:S})=>{const[w,g,y]=rb({sourceX:n,sourceY:l,targetX:a,targetY:s}),m=e.isInternal?void 0:t;return o.jsx(Jc,{id:m,path:w,labelX:g,labelY:y,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,markerEnd:p,markerStart:x,interactionWidth:S})})}const xA=Ib({isInternal:!1}),Kb=Ib({isInternal:!0});xA.displayName="StraightEdge";Kb.displayName="StraightEdgeInternal";function Wb(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,sourcePosition:i=ee.Bottom,targetPosition:r=ee.Top,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,pathOptions:g,interactionWidth:y})=>{const[m,v,j]=sb({sourceX:n,sourceY:l,sourcePosition:i,targetX:a,targetY:s,targetPosition:r,curvature:g==null?void 0:g.curvature}),E=e.isInternal?void 0:t;return o.jsx(Jc,{id:E,path:m,labelX:v,labelY:j,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,interactionWidth:y})})}const yA=Wb({isInternal:!1}),Jb=Wb({isInternal:!0});yA.displayName="BezierEdge";Jb.displayName="BezierEdgeInternal";const xx={default:Jb,straight:Kb,step:Zb,smoothstep:Gb,simplebezier:Yb},yx={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},vA=(e,t,n)=>n===ee.Left?e-t:n===ee.Right?e+t:e,bA=(e,t,n)=>n===ee.Top?e-t:n===ee.Bottom?e+t:e,vx="react-flow__edgeupdater";function bx({position:e,centerX:t,centerY:n,radius:l=10,onMouseDown:a,onMouseEnter:s,onMouseOut:i,type:r}){return o.jsx("circle",{onMouseDown:a,onMouseEnter:s,onMouseOut:i,className:Ve([vx,`${vx}-${r}`]),cx:vA(t,l,e),cy:bA(n,l,e),r:l,stroke:"transparent",fill:"transparent"})}function wA({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:l,sourceY:a,targetX:s,targetY:i,sourcePosition:r,targetPosition:c,onReconnect:u,onReconnectStart:d,onReconnectEnd:f,setReconnecting:h,setUpdateHover:p}){const x=De(),S=(v,j)=>{if(v.button!==0)return;const{autoPanOnConnect:E,domNode:M,connectionMode:A,connectionRadius:C,lib:H,onConnectStart:T,cancelConnection:$,nodeLookup:V,rfId:N,panBy:D,updateConnection:k}=x.getState(),R=j.type==="target",z=(X,L)=>{h(!1),f==null||f(X,n,j.type,L)},O=X=>u==null?void 0:u(n,X),Y=(X,L)=>{h(!0),d==null||d(v,n,j.type),T==null||T(X,L)};wf.onPointerDown(v.nativeEvent,{autoPanOnConnect:E,connectionMode:A,connectionRadius:C,domNode:M,handleId:j.id,nodeId:j.nodeId,nodeLookup:V,isTarget:R,edgeUpdaterType:j.type,lib:H,flowId:N,cancelConnection:$,panBy:D,isValidConnection:(...X)=>{var L,U;return((U=(L=x.getState()).isValidConnection)==null?void 0:U.call(L,...X))??!0},onConnect:O,onConnectStart:Y,onConnectEnd:(...X)=>{var L,U;return(U=(L=x.getState()).onConnectEnd)==null?void 0:U.call(L,...X)},onReconnectEnd:z,updateConnection:k,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:v.currentTarget})},w=v=>S(v,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),g=v=>S(v,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),y=()=>p(!0),m=()=>p(!1);return o.jsxs(o.Fragment,{children:[(e===!0||e==="source")&&o.jsx(bx,{position:r,centerX:l,centerY:a,radius:t,onMouseDown:w,onMouseEnter:y,onMouseOut:m,type:"source"}),(e===!0||e==="target")&&o.jsx(bx,{position:c,centerX:s,centerY:i,radius:t,onMouseDown:g,onMouseEnter:y,onMouseOut:m,type:"target"})]})}function SA({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:l,onClick:a,onDoubleClick:s,onContextMenu:i,onMouseEnter:r,onMouseMove:c,onMouseLeave:u,reconnectRadius:d,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,rfId:x,edgeTypes:S,noPanClassName:w,onError:g,disableKeyboardA11y:y}){let m=he(J=>J.edgeLookup.get(e));const v=he(J=>J.defaultEdgeOptions);m=v?{...v,...m}:m;let j=m.type||"default",E=(S==null?void 0:S[j])||xx[j];E===void 0&&(g==null||g("011",jn.error011(j)),j="default",E=(S==null?void 0:S.default)||xx.default);const M=!!(m.focusable||t&&typeof m.focusable>"u"),A=typeof f<"u"&&(m.reconnectable||n&&typeof m.reconnectable>"u"),C=!!(m.selectable||l&&typeof m.selectable>"u"),H=b.useRef(null),[T,$]=b.useState(!1),[V,N]=b.useState(!1),D=De(),{zIndex:k,sourceX:R,sourceY:z,targetX:O,targetY:Y,sourcePosition:X,targetPosition:L}=he(b.useCallback(J=>{const F=J.nodeLookup.get(m.source),le=J.nodeLookup.get(m.target);if(!F||!le)return{zIndex:m.zIndex,...yx};const ae=eM({id:e,sourceNode:F,targetNode:le,sourceHandle:m.sourceHandle||null,targetHandle:m.targetHandle||null,connectionMode:J.connectionMode,onError:g});return{zIndex:Q4({selected:m.selected,zIndex:m.zIndex,sourceNode:F,targetNode:le,elevateOnSelect:J.elevateEdgesOnSelect,zIndexMode:J.zIndexMode}),...ae||yx}},[m.source,m.target,m.sourceHandle,m.targetHandle,m.selected,m.zIndex]),ze),U=b.useMemo(()=>m.markerStart?`url('#${vf(m.markerStart,x)}')`:void 0,[m.markerStart,x]),_=b.useMemo(()=>m.markerEnd?`url('#${vf(m.markerEnd,x)}')`:void 0,[m.markerEnd,x]);if(m.hidden||R===null||z===null||O===null||Y===null)return null;const B=J=>{var te;const{addSelectedEdges:F,unselectNodesAndEdges:le,multiSelectionActive:ae}=D.getState();C&&(D.setState({nodesSelectionActive:!1}),m.selected&&ae?(le({nodes:[],edges:[m]}),(te=H.current)==null||te.blur()):F([e])),a&&a(J,m)},G=s?J=>{s(J,{...m})}:void 0,q=i?J=>{i(J,{...m})}:void 0,Q=r?J=>{r(J,{...m})}:void 0,K=c?J=>{c(J,{...m})}:void 0,W=u?J=>{u(J,{...m})}:void 0,P=J=>{var F;if(!y&&X1.includes(J.key)&&C){const{unselectNodesAndEdges:le,addSelectedEdges:ae}=D.getState();J.key==="Escape"?((F=H.current)==null||F.blur(),le({edges:[m]})):ae([e])}};return o.jsx("svg",{style:{zIndex:k},children:o.jsxs("g",{className:Ve(["react-flow__edge",`react-flow__edge-${j}`,m.className,w,{selected:m.selected,animated:m.animated,inactive:!C&&!a,updating:T,selectable:C}]),onClick:B,onDoubleClick:G,onContextMenu:q,onMouseEnter:Q,onMouseMove:K,onMouseLeave:W,onKeyDown:M?P:void 0,tabIndex:M?0:void 0,role:m.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":m.ariaLabel===null?void 0:m.ariaLabel||`Edge from ${m.source} to ${m.target}`,"aria-describedby":M?`${Eb}-${x}`:void 0,ref:H,...m.domAttributes,children:[!V&&o.jsx(E,{id:e,source:m.source,target:m.target,type:m.type,selected:m.selected,animated:m.animated,selectable:C,deletable:m.deletable??!0,label:m.label,labelStyle:m.labelStyle,labelShowBg:m.labelShowBg,labelBgStyle:m.labelBgStyle,labelBgPadding:m.labelBgPadding,labelBgBorderRadius:m.labelBgBorderRadius,sourceX:R,sourceY:z,targetX:O,targetY:Y,sourcePosition:X,targetPosition:L,data:m.data,style:m.style,sourceHandleId:m.sourceHandle,targetHandleId:m.targetHandle,markerStart:U,markerEnd:_,pathOptions:"pathOptions"in m?m.pathOptions:void 0,interactionWidth:m.interactionWidth}),A&&o.jsx(wA,{edge:m,isReconnectable:A,reconnectRadius:d,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,sourceX:R,sourceY:z,targetX:O,targetY:Y,sourcePosition:X,targetPosition:L,setUpdateHover:$,setReconnecting:N})]})})}var NA=b.memo(SA);const jA=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Fb({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:l,noPanClassName:a,onReconnect:s,onEdgeContextMenu:i,onEdgeMouseEnter:r,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:d,reconnectRadius:f,onEdgeDoubleClick:h,onReconnectStart:p,onReconnectEnd:x,disableKeyboardA11y:S}){const{edgesFocusable:w,edgesReconnectable:g,elementsSelectable:y,onError:m}=he(jA,ze),v=oA(t);return o.jsxs("div",{className:"react-flow__edges",children:[o.jsx(hA,{defaultColor:e,rfId:n}),v.map(j=>o.jsx(NA,{id:j,edgesFocusable:w,edgesReconnectable:g,elementsSelectable:y,noPanClassName:a,onReconnect:s,onContextMenu:i,onMouseEnter:r,onMouseMove:c,onMouseLeave:u,onClick:d,reconnectRadius:f,onDoubleClick:h,onReconnectStart:p,onReconnectEnd:x,rfId:n,onError:m,edgeTypes:l,disableKeyboardA11y:S},j))]})}Fb.displayName="EdgeRenderer";const kA=b.memo(Fb),EA=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function CA({children:e}){const t=he(EA);return o.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function MA(e){const t=op(),n=b.useRef(!1);b.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const _A=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function AA(e){const t=he(_A),n=De();return b.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function TA(e){return e.connection.inProgress?{...e.connection,to:cr(e.connection.to,e.transform)}:{...e.connection}}function zA(e){return TA}function DA(e){const t=zA();return he(t,ze)}const RA=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function OA({containerStyle:e,style:t,type:n,component:l}){const{nodesConnectable:a,width:s,height:i,isValid:r,inProgress:c}=he(RA,ze);return!(s&&a&&c)?null:o.jsx("svg",{style:e,width:s,height:i,className:"react-flow__connectionline react-flow__container",children:o.jsx("g",{className:Ve(["react-flow__connection",Z1(r)]),children:o.jsx(Pb,{style:t,type:n,CustomComponent:l,isValid:r})})})}const Pb=({style:e,type:t=xl.Bezier,CustomComponent:n,isValid:l})=>{const{inProgress:a,from:s,fromNode:i,fromHandle:r,fromPosition:c,to:u,toNode:d,toHandle:f,toPosition:h,pointer:p}=DA();if(!a)return;if(n)return o.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:r,fromX:s.x,fromY:s.y,toX:u.x,toY:u.y,fromPosition:c,toPosition:h,connectionStatus:Z1(l),toNode:d,toHandle:f,pointer:p});let x="";const S={sourceX:s.x,sourceY:s.y,sourcePosition:c,targetX:u.x,targetY:u.y,targetPosition:h};switch(t){case xl.Bezier:[x]=sb(S);break;case xl.SimpleBezier:[x]=Ub(S);break;case xl.Step:[x]=yf({...S,borderRadius:0});break;case xl.SmoothStep:[x]=yf(S);break;default:[x]=rb(S)}return o.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};Pb.displayName="ConnectionLine";const HA={};function wx(e=HA){b.useRef(e),De(),b.useEffect(()=>{},[e])}function LA(){De(),b.useRef(!1),b.useEffect(()=>{},[])}function e2({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:l,onEdgeClick:a,onNodeDoubleClick:s,onEdgeDoubleClick:i,onNodeMouseEnter:r,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,onSelectionContextMenu:f,onSelectionStart:h,onSelectionEnd:p,connectionLineType:x,connectionLineStyle:S,connectionLineComponent:w,connectionLineContainerStyle:g,selectionKeyCode:y,selectionOnDrag:m,selectionMode:v,multiSelectionKeyCode:j,panActivationKeyCode:E,zoomActivationKeyCode:M,deleteKeyCode:A,onlyRenderVisibleElements:C,elementsSelectable:H,defaultViewport:T,translateExtent:$,minZoom:V,maxZoom:N,preventScrolling:D,defaultMarkerColor:k,zoomOnScroll:R,zoomOnPinch:z,panOnScroll:O,panOnScrollSpeed:Y,panOnScrollMode:X,zoomOnDoubleClick:L,panOnDrag:U,onPaneClick:_,onPaneMouseEnter:B,onPaneMouseMove:G,onPaneMouseLeave:q,onPaneScroll:Q,onPaneContextMenu:K,paneClickDistance:W,nodeClickDistance:P,onEdgeContextMenu:J,onEdgeMouseEnter:F,onEdgeMouseMove:le,onEdgeMouseLeave:ae,reconnectRadius:te,onReconnect:ge,onReconnectStart:I,onReconnectEnd:se,noDragClassName:Re,noWheelClassName:st,noPanClassName:Nt,disableKeyboardA11y:Ht,nodeExtent:ll,rfId:_n,viewport:Jt,onViewportChange:Lt}){return wx(e),wx(t),LA(),MA(n),AA(Jt),o.jsx(F_,{onPaneClick:_,onPaneMouseEnter:B,onPaneMouseMove:G,onPaneMouseLeave:q,onPaneContextMenu:K,onPaneScroll:Q,paneClickDistance:W,deleteKeyCode:A,selectionKeyCode:y,selectionOnDrag:m,selectionMode:v,onSelectionStart:h,onSelectionEnd:p,multiSelectionKeyCode:j,panActivationKeyCode:E,zoomActivationKeyCode:M,elementsSelectable:H,zoomOnScroll:R,zoomOnPinch:z,zoomOnDoubleClick:L,panOnScroll:O,panOnScrollSpeed:Y,panOnScrollMode:X,panOnDrag:U,defaultViewport:T,translateExtent:$,minZoom:V,maxZoom:N,onSelectionContextMenu:f,preventScrolling:D,noDragClassName:Re,noWheelClassName:st,noPanClassName:Nt,disableKeyboardA11y:Ht,onViewportChange:Lt,isControlledViewport:!!Jt,children:o.jsxs(CA,{children:[o.jsx(kA,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:i,onReconnect:ge,onReconnectStart:I,onReconnectEnd:se,onlyRenderVisibleElements:C,onEdgeContextMenu:J,onEdgeMouseEnter:F,onEdgeMouseMove:le,onEdgeMouseLeave:ae,reconnectRadius:te,defaultMarkerColor:k,noPanClassName:Nt,disableKeyboardA11y:Ht,rfId:_n}),o.jsx(OA,{style:S,type:x,component:w,containerStyle:g}),o.jsx("div",{className:"react-flow__edgelabel-renderer"}),o.jsx(rA,{nodeTypes:e,onNodeClick:l,onNodeDoubleClick:s,onNodeMouseEnter:r,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,nodeClickDistance:P,onlyRenderVisibleElements:C,noPanClassName:Nt,noDragClassName:Re,disableKeyboardA11y:Ht,nodeExtent:ll,rfId:_n}),o.jsx("div",{className:"react-flow__viewport-portal"})]})})}e2.displayName="GraphView";const $A=b.memo(e2),Sx=({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,width:a,height:s,fitView:i,fitViewOptions:r,minZoom:c=.5,maxZoom:u=2,nodeOrigin:d,nodeExtent:f,zIndexMode:h="basic"}={})=>{const p=new Map,x=new Map,S=new Map,w=new Map,g=l??t??[],y=n??e??[],m=d??[0,0],v=f??Hi;ub(S,w,g);const{nodesInitialized:j}=bf(y,p,x,{nodeOrigin:m,nodeExtent:v,zIndexMode:h});let E=[0,0,1];if(i&&a&&s){const M=rr(p,{filter:T=>!!((T.width||T.initialWidth)&&(T.height||T.initialHeight))}),{x:A,y:C,zoom:H}=tp(M,a,s,c,u,(r==null?void 0:r.padding)??.1);E=[A,C,H]}return{rfId:"1",width:a??0,height:s??0,transform:E,nodes:y,nodesInitialized:j,nodeLookup:p,parentLookup:x,edges:g,edgeLookup:w,connectionLookup:S,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:l!==void 0,panZoom:null,minZoom:c,maxZoom:u,translateExtent:Hi,nodeExtent:v,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:fs.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:m,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:i??!1,fitViewOptions:r,fitViewResolver:null,connection:{...Q1},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:U4,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:G1,zIndexMode:h,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},BA=({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,width:a,height:s,fitView:i,fitViewOptions:r,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:h})=>a_((p,x)=>{async function S(){const{nodeLookup:w,panZoom:g,fitViewOptions:y,fitViewResolver:m,width:v,height:j,minZoom:E,maxZoom:M}=x();g&&(await $4({nodes:w,width:v,height:j,panZoom:g,minZoom:E,maxZoom:M},y),m==null||m.resolve(!0),p({fitViewResolver:null}))}return{...Sx({nodes:e,edges:t,width:a,height:s,fitView:i,fitViewOptions:r,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,defaultNodes:n,defaultEdges:l,zIndexMode:h}),setNodes:w=>{const{nodeLookup:g,parentLookup:y,nodeOrigin:m,elevateNodesOnSelect:v,fitViewQueued:j,zIndexMode:E,nodesSelectionActive:M}=x(),{nodesInitialized:A,hasSelectedNodes:C}=bf(w,g,y,{nodeOrigin:m,nodeExtent:f,elevateNodesOnSelect:v,checkEquality:!0,zIndexMode:E}),H=M&&C;j&&A?(S(),p({nodes:w,nodesInitialized:A,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:H})):p({nodes:w,nodesInitialized:A,nodesSelectionActive:H})},setEdges:w=>{const{connectionLookup:g,edgeLookup:y}=x();ub(g,y,w),p({edges:w})},setDefaultNodesAndEdges:(w,g)=>{if(w){const{setNodes:y}=x();y(w),p({hasDefaultNodes:!0})}if(g){const{setEdges:y}=x();y(g),p({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:g,nodeLookup:y,parentLookup:m,domNode:v,nodeOrigin:j,nodeExtent:E,debug:M,fitViewQueued:A,zIndexMode:C}=x(),{changes:H,updatedInternals:T}=oM(w,y,m,v,j,E,C);T&&(aM(y,m,{nodeOrigin:j,nodeExtent:E,zIndexMode:C}),A?(S(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),(H==null?void 0:H.length)>0&&(M&&console.log("React Flow: trigger node changes",H),g==null||g(H)))},updateNodePositions:(w,g=!1)=>{const y=[];let m=[];const{nodeLookup:v,triggerNodeChanges:j,connection:E,updateConnection:M,onNodesChangeMiddlewareMap:A}=x();for(const[C,H]of w){const T=v.get(C),$=!!(T!=null&&T.expandParent&&(T!=null&&T.parentId)&&(H!=null&&H.position)),V={id:C,type:"position",position:$?{x:Math.max(0,H.position.x),y:Math.max(0,H.position.y)}:H.position,dragging:g};if(T&&E.inProgress&&E.fromNode.id===T.id){const N=pa(T,E.fromHandle,ee.Left,!0);M({...E,from:N})}$&&T.parentId&&y.push({id:C,parentId:T.parentId,rect:{...H.internals.positionAbsolute,width:H.measured.width??0,height:H.measured.height??0}}),m.push(V)}if(y.length>0){const{parentLookup:C,nodeOrigin:H}=x(),T=rp(y,v,C,H);m.push(...T)}for(const C of A.values())m=C(m);j(m)},triggerNodeChanges:w=>{const{onNodesChange:g,setNodes:y,nodes:m,hasDefaultNodes:v,debug:j}=x();if(w!=null&&w.length){if(v){const E=_b(w,m);y(E)}j&&console.log("React Flow: trigger node changes",w),g==null||g(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:g,setEdges:y,edges:m,hasDefaultEdges:v,debug:j}=x();if(w!=null&&w.length){if(v){const E=Ab(w,m);y(E)}j&&console.log("React Flow: trigger edge changes",w),g==null||g(w)}},addSelectedNodes:w=>{const{multiSelectionActive:g,edgeLookup:y,nodeLookup:m,triggerNodeChanges:v,triggerEdgeChanges:j}=x();if(g){const E=w.map(M=>Il(M,!0));v(E);return}v(Ya(m,new Set([...w]),!0)),j(Ya(y))},addSelectedEdges:w=>{const{multiSelectionActive:g,edgeLookup:y,nodeLookup:m,triggerNodeChanges:v,triggerEdgeChanges:j}=x();if(g){const E=w.map(M=>Il(M,!0));j(E);return}j(Ya(y,new Set([...w]))),v(Ya(m,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:g}={})=>{const{edges:y,nodes:m,nodeLookup:v,triggerNodeChanges:j,triggerEdgeChanges:E}=x(),M=w||m,A=g||y,C=[];for(const T of M){if(!T.selected)continue;const $=v.get(T.id);$&&($.selected=!1),C.push(Il(T.id,!1))}const H=[];for(const T of A)T.selected&&H.push(Il(T.id,!1));j(C),E(H)},setMinZoom:w=>{const{panZoom:g,maxZoom:y}=x();g==null||g.setScaleExtent([w,y]),p({minZoom:w})},setMaxZoom:w=>{const{panZoom:g,minZoom:y}=x();g==null||g.setScaleExtent([y,w]),p({maxZoom:w})},setTranslateExtent:w=>{var g;(g=x().panZoom)==null||g.setTranslateExtent(w),p({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:g,triggerNodeChanges:y,triggerEdgeChanges:m,elementsSelectable:v}=x();if(!v)return;const j=g.reduce((M,A)=>A.selected?[...M,Il(A.id,!1)]:M,[]),E=w.reduce((M,A)=>A.selected?[...M,Il(A.id,!1)]:M,[]);y(j),m(E)},setNodeExtent:w=>{const{nodes:g,nodeLookup:y,parentLookup:m,nodeOrigin:v,elevateNodesOnSelect:j,nodeExtent:E,zIndexMode:M}=x();w[0][0]===E[0][0]&&w[0][1]===E[0][1]&&w[1][0]===E[1][0]&&w[1][1]===E[1][1]||(bf(g,y,m,{nodeOrigin:v,nodeExtent:w,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:M}),p({nodeExtent:w}))},panBy:w=>{const{transform:g,width:y,height:m,panZoom:v,translateExtent:j}=x();return cM({delta:w,panZoom:v,transform:g,translateExtent:j,width:y,height:m})},setCenter:async(w,g,y)=>{const{width:m,height:v,maxZoom:j,panZoom:E}=x();if(!E)return Promise.resolve(!1);const M=typeof(y==null?void 0:y.zoom)<"u"?y.zoom:j;return await E.setViewport({x:m/2-w*M,y:v/2-g*M,zoom:M},{duration:y==null?void 0:y.duration,ease:y==null?void 0:y.ease,interpolate:y==null?void 0:y.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{p({connection:{...Q1}})},updateConnection:w=>{p({connection:w})},reset:()=>p({...Sx()})}},Object.is);function UA({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:l,initialWidth:a,initialHeight:s,initialMinZoom:i,initialMaxZoom:r,initialFitViewOptions:c,fitView:u,nodeOrigin:d,nodeExtent:f,zIndexMode:h,children:p}){const[x]=b.useState(()=>BA({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,width:a,height:s,fitView:u,minZoom:i,maxZoom:r,fitViewOptions:c,nodeOrigin:d,nodeExtent:f,zIndexMode:h}));return o.jsx(s_,{value:x,children:o.jsx(C_,{children:p})})}function qA({children:e,nodes:t,edges:n,defaultNodes:l,defaultEdges:a,width:s,height:i,fitView:r,fitViewOptions:c,minZoom:u,maxZoom:d,nodeOrigin:f,nodeExtent:h,zIndexMode:p}){return b.useContext(Ic)?o.jsx(o.Fragment,{children:e}):o.jsx(UA,{initialNodes:t,initialEdges:n,defaultNodes:l,defaultEdges:a,initialWidth:s,initialHeight:i,fitView:r,initialFitViewOptions:c,initialMinZoom:u,initialMaxZoom:d,nodeOrigin:f,nodeExtent:h,zIndexMode:p,children:e})}const YA={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function VA({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,className:a,nodeTypes:s,edgeTypes:i,onNodeClick:r,onEdgeClick:c,onInit:u,onMove:d,onMoveStart:f,onMoveEnd:h,onConnect:p,onConnectStart:x,onConnectEnd:S,onClickConnectStart:w,onClickConnectEnd:g,onNodeMouseEnter:y,onNodeMouseMove:m,onNodeMouseLeave:v,onNodeContextMenu:j,onNodeDoubleClick:E,onNodeDragStart:M,onNodeDrag:A,onNodeDragStop:C,onNodesDelete:H,onEdgesDelete:T,onDelete:$,onSelectionChange:V,onSelectionDragStart:N,onSelectionDrag:D,onSelectionDragStop:k,onSelectionContextMenu:R,onSelectionStart:z,onSelectionEnd:O,onBeforeDelete:Y,connectionMode:X,connectionLineType:L=xl.Bezier,connectionLineStyle:U,connectionLineComponent:_,connectionLineContainerStyle:B,deleteKeyCode:G="Backspace",selectionKeyCode:q="Shift",selectionOnDrag:Q=!1,selectionMode:K=Li.Full,panActivationKeyCode:W="Space",multiSelectionKeyCode:P=Bi()?"Meta":"Control",zoomActivationKeyCode:J=Bi()?"Meta":"Control",snapToGrid:F,snapGrid:le,onlyRenderVisibleElements:ae=!1,selectNodesOnDrag:te,nodesDraggable:ge,autoPanOnNodeFocus:I,nodesConnectable:se,nodesFocusable:Re,nodeOrigin:st=Cb,edgesFocusable:Nt,edgesReconnectable:Ht,elementsSelectable:ll=!0,defaultViewport:_n=y_,minZoom:Jt=.5,maxZoom:Lt=2,translateExtent:An=Hi,preventScrolling:Bl=!0,nodeExtent:wa,defaultMarkerColor:fn="#b1b1b7",zoomOnScroll:ur=!0,zoomOnPinch:Fc=!0,panOnScroll:Pc=!1,panOnScrollSpeed:Ts=.5,panOnScrollMode:dr=aa.Free,zoomOnDoubleClick:eu=!0,panOnDrag:fr=!0,onPaneClick:tu,onPaneMouseEnter:nu,onPaneMouseMove:lu,onPaneMouseLeave:Ie,onPaneScroll:it,onPaneContextMenu:rt,paneClickDistance:hn=1,nodeClickDistance:ht=0,children:ot,onReconnect:$t,onReconnectStart:al,onReconnectEnd:Xe,onEdgeContextMenu:pn,onEdgeDoubleClick:Bt,onEdgeMouseEnter:Ft,onEdgeMouseMove:Ul,onEdgeMouseLeave:ql,reconnectRadius:gn=10,onNodesChange:Yl,onEdgesChange:zs,noDragClassName:a2="nodrag",noWheelClassName:s2="nowheel",noPanClassName:up="nopan",fitView:dp,fitViewOptions:fp,connectOnClick:i2,attributionPosition:r2,proOptions:o2,defaultEdgeOptions:c2,elevateNodesOnSelect:u2=!0,elevateEdgesOnSelect:d2=!1,disableKeyboardA11y:hp=!1,autoPanOnConnect:f2,autoPanOnNodeDrag:h2,autoPanSpeed:p2,connectionRadius:g2,isValidConnection:m2,onError:x2,style:y2,id:pp,nodeDragThreshold:v2,connectionDragThreshold:b2,viewport:w2,onViewportChange:S2,width:N2,height:j2,colorMode:k2="light",debug:E2,onScroll:hr,ariaLabelConfig:C2,zIndexMode:gp="basic",...M2},_2){const au=pp||"1",A2=S_(k2),T2=b.useCallback(mp=>{mp.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),hr==null||hr(mp)},[hr]);return o.jsx("div",{"data-testid":"rf__wrapper",...M2,onScroll:T2,style:{...y2,...YA},ref:_2,className:Ve(["react-flow",a,A2]),id:pp,role:"application",children:o.jsxs(qA,{nodes:e,edges:t,width:N2,height:j2,fitView:dp,fitViewOptions:fp,minZoom:Jt,maxZoom:Lt,nodeOrigin:st,nodeExtent:wa,zIndexMode:gp,children:[o.jsx(w_,{nodes:e,edges:t,defaultNodes:n,defaultEdges:l,onConnect:p,onConnectStart:x,onConnectEnd:S,onClickConnectStart:w,onClickConnectEnd:g,nodesDraggable:ge,autoPanOnNodeFocus:I,nodesConnectable:se,nodesFocusable:Re,edgesFocusable:Nt,edgesReconnectable:Ht,elementsSelectable:ll,elevateNodesOnSelect:u2,elevateEdgesOnSelect:d2,minZoom:Jt,maxZoom:Lt,nodeExtent:wa,onNodesChange:Yl,onEdgesChange:zs,snapToGrid:F,snapGrid:le,connectionMode:X,translateExtent:An,connectOnClick:i2,defaultEdgeOptions:c2,fitView:dp,fitViewOptions:fp,onNodesDelete:H,onEdgesDelete:T,onDelete:$,onNodeDragStart:M,onNodeDrag:A,onNodeDragStop:C,onSelectionDrag:D,onSelectionDragStart:N,onSelectionDragStop:k,onMove:d,onMoveStart:f,onMoveEnd:h,noPanClassName:up,nodeOrigin:st,rfId:au,autoPanOnConnect:f2,autoPanOnNodeDrag:h2,autoPanSpeed:p2,onError:x2,connectionRadius:g2,isValidConnection:m2,selectNodesOnDrag:te,nodeDragThreshold:v2,connectionDragThreshold:b2,onBeforeDelete:Y,debug:E2,ariaLabelConfig:C2,zIndexMode:gp}),o.jsx($A,{onInit:u,onNodeClick:r,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:m,onNodeMouseLeave:v,onNodeContextMenu:j,onNodeDoubleClick:E,nodeTypes:s,edgeTypes:i,connectionLineType:L,connectionLineStyle:U,connectionLineComponent:_,connectionLineContainerStyle:B,selectionKeyCode:q,selectionOnDrag:Q,selectionMode:K,deleteKeyCode:G,multiSelectionKeyCode:P,panActivationKeyCode:W,zoomActivationKeyCode:J,onlyRenderVisibleElements:ae,defaultViewport:_n,translateExtent:An,minZoom:Jt,maxZoom:Lt,preventScrolling:Bl,zoomOnScroll:ur,zoomOnPinch:Fc,zoomOnDoubleClick:eu,panOnScroll:Pc,panOnScrollSpeed:Ts,panOnScrollMode:dr,panOnDrag:fr,onPaneClick:tu,onPaneMouseEnter:nu,onPaneMouseMove:lu,onPaneMouseLeave:Ie,onPaneScroll:it,onPaneContextMenu:rt,paneClickDistance:hn,nodeClickDistance:ht,onSelectionContextMenu:R,onSelectionStart:z,onSelectionEnd:O,onReconnect:$t,onReconnectStart:al,onReconnectEnd:Xe,onEdgeContextMenu:pn,onEdgeDoubleClick:Bt,onEdgeMouseEnter:Ft,onEdgeMouseMove:Ul,onEdgeMouseLeave:ql,reconnectRadius:gn,defaultMarkerColor:fn,noDragClassName:a2,noWheelClassName:s2,noPanClassName:up,rfId:au,disableKeyboardA11y:hp,nodeExtent:wa,viewport:w2,onViewportChange:S2}),o.jsx(x_,{onSelectionChange:V}),ot,o.jsx(f_,{proOptions:o2,position:r2}),o.jsx(d_,{rfId:au,disableKeyboardA11y:hp})]})})}var XA=Tb(VA);function GA(e){const[t,n]=b.useState(e),l=b.useCallback(a=>n(s=>_b(a,s)),[]);return[t,n,l]}function QA(e){const[t,n]=b.useState(e),l=b.useCallback(a=>n(s=>Ab(a,s)),[]);return[t,n,l]}function ZA({dimensions:e,lineWidth:t,variant:n,className:l}){return o.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Ve(["react-flow__background-pattern",n,l])})}function IA({radius:e,className:t}){return o.jsx("circle",{cx:e,cy:e,r:e,className:Ve(["react-flow__background-pattern","dots",t])})}var In;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(In||(In={}));const KA={[In.Dots]:1,[In.Lines]:1,[In.Cross]:6},WA=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function t2({id:e,variant:t=In.Dots,gap:n=20,size:l,lineWidth:a=1,offset:s=0,color:i,bgColor:r,style:c,className:u,patternClassName:d}){const f=b.useRef(null),{transform:h,patternId:p}=he(WA,ze),x=l||KA[t],S=t===In.Dots,w=t===In.Cross,g=Array.isArray(n)?n:[n,n],y=[g[0]*h[2]||1,g[1]*h[2]||1],m=x*h[2],v=Array.isArray(s)?s:[s,s],j=w?[m,m]:y,E=[v[0]*h[2]||1+j[0]/2,v[1]*h[2]||1+j[1]/2],M=`${p}${e||""}`;return o.jsxs("svg",{className:Ve(["react-flow__background",u]),style:{...c,...Wc,"--xy-background-color-props":r,"--xy-background-pattern-color-props":i},ref:f,"data-testid":"rf__background",children:[o.jsx("pattern",{id:M,x:h[0]%y[0],y:h[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${E[0]},-${E[1]})`,children:S?o.jsx(IA,{radius:m/2,className:d}):o.jsx(ZA,{dimensions:j,lineWidth:a,variant:t,className:d})}),o.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}t2.displayName="Background";const JA=b.memo(t2);function FA(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:o.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function PA(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:o.jsx("path",{d:"M0 0h32v4.2H0z"})})}function eT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:o.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function tT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:o.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function nT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:o.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Xr({children:e,className:t,...n}){return o.jsx("button",{type:"button",className:Ve(["react-flow__controls-button",t]),...n,children:e})}const lT=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function n2({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:l=!0,fitViewOptions:a,onZoomIn:s,onZoomOut:i,onFitView:r,onInteractiveChange:c,className:u,children:d,position:f="bottom-left",orientation:h="vertical","aria-label":p}){const x=De(),{isInteractive:S,minZoomReached:w,maxZoomReached:g,ariaLabelConfig:y}=he(lT,ze),{zoomIn:m,zoomOut:v,fitView:j}=op(),E=()=>{m(),s==null||s()},M=()=>{v(),i==null||i()},A=()=>{j(a),r==null||r()},C=()=>{x.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),c==null||c(!S)},H=h==="horizontal"?"horizontal":"vertical";return o.jsxs(Kc,{className:Ve(["react-flow__controls",H,u]),position:f,style:e,"data-testid":"rf__controls","aria-label":p??y["controls.ariaLabel"],children:[t&&o.jsxs(o.Fragment,{children:[o.jsx(Xr,{onClick:E,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:g,children:o.jsx(FA,{})}),o.jsx(Xr,{onClick:M,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:w,children:o.jsx(PA,{})})]}),n&&o.jsx(Xr,{className:"react-flow__controls-fitview",onClick:A,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:o.jsx(eT,{})}),l&&o.jsx(Xr,{className:"react-flow__controls-interactive",onClick:C,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:S?o.jsx(nT,{}):o.jsx(tT,{})}),d]})}n2.displayName="Controls";const aT=b.memo(n2);function sT({id:e,x:t,y:n,width:l,height:a,style:s,color:i,strokeColor:r,strokeWidth:c,className:u,borderRadius:d,shapeRendering:f,selected:h,onClick:p}){const{background:x,backgroundColor:S}=s||{},w=i||x||S;return o.jsx("rect",{className:Ve(["react-flow__minimap-node",{selected:h},u]),x:t,y:n,rx:d,ry:d,width:l,height:a,style:{fill:w,stroke:r,strokeWidth:c},shapeRendering:f,onClick:p?g=>p(g,e):void 0})}const iT=b.memo(sT),rT=e=>e.nodes.map(t=>t.id),ld=e=>e instanceof Function?e:()=>e;function oT({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:l=5,nodeStrokeWidth:a,nodeComponent:s=iT,onClick:i}){const r=he(rT,ze),c=ld(t),u=ld(e),d=ld(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return o.jsx(o.Fragment,{children:r.map(h=>o.jsx(uT,{id:h,nodeColorFunc:c,nodeStrokeColorFunc:u,nodeClassNameFunc:d,nodeBorderRadius:l,nodeStrokeWidth:a,NodeComponent:s,onClick:i,shapeRendering:f},h))})}function cT({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:l,nodeBorderRadius:a,nodeStrokeWidth:s,shapeRendering:i,NodeComponent:r,onClick:c}){const{node:u,x:d,y:f,width:h,height:p}=he(x=>{const S=x.nodeLookup.get(e);if(!S)return{node:void 0,x:0,y:0,width:0,height:0};const w=S.internals.userNode,{x:g,y}=S.internals.positionAbsolute,{width:m,height:v}=nl(w);return{node:w,x:g,y,width:m,height:v}},ze);return!u||u.hidden||!P1(u)?null:o.jsx(r,{x:d,y:f,width:h,height:p,style:u.style,selected:!!u.selected,className:l(u),color:t(u),borderRadius:a,strokeColor:n(u),strokeWidth:s,shapeRendering:i,onClick:c,id:u.id})}const uT=b.memo(cT);var dT=b.memo(oT);const fT=200,hT=150,pT=e=>!e.hidden,gT=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?F1(rr(e.nodeLookup,{filter:pT}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},mT="react-flow__minimap-desc";function l2({style:e,className:t,nodeStrokeColor:n,nodeColor:l,nodeClassName:a="",nodeBorderRadius:s=5,nodeStrokeWidth:i,nodeComponent:r,bgColor:c,maskColor:u,maskStrokeColor:d,maskStrokeWidth:f,position:h="bottom-right",onClick:p,onNodeClick:x,pannable:S=!1,zoomable:w=!1,ariaLabel:g,inversePan:y,zoomStep:m=1,offsetScale:v=5}){const j=De(),E=b.useRef(null),{boundingRect:M,viewBB:A,rfId:C,panZoom:H,translateExtent:T,flowWidth:$,flowHeight:V,ariaLabelConfig:N}=he(gT,ze),D=(e==null?void 0:e.width)??fT,k=(e==null?void 0:e.height)??hT,R=M.width/D,z=M.height/k,O=Math.max(R,z),Y=O*D,X=O*k,L=v*O,U=M.x-(Y-M.width)/2-L,_=M.y-(X-M.height)/2-L,B=Y+L*2,G=X+L*2,q=`${mT}-${C}`,Q=b.useRef(0),K=b.useRef();Q.current=O,b.useEffect(()=>{if(E.current&&H)return K.current=yM({domNode:E.current,panZoom:H,getTransform:()=>j.getState().transform,getViewScale:()=>Q.current}),()=>{var F;(F=K.current)==null||F.destroy()}},[H]),b.useEffect(()=>{var F;(F=K.current)==null||F.update({translateExtent:T,width:$,height:V,inversePan:y,pannable:S,zoomStep:m,zoomable:w})},[S,w,y,m,T,$,V]);const W=p?F=>{var te;const[le,ae]=((te=K.current)==null?void 0:te.pointer(F))||[0,0];p(F,{x:le,y:ae})}:void 0,P=x?b.useCallback((F,le)=>{const ae=j.getState().nodeLookup.get(le).internals.userNode;x(F,ae)},[]):void 0,J=g??N["minimap.ariaLabel"];return o.jsx(Kc,{position:h,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*O:void 0,"--xy-minimap-node-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof i=="number"?i:void 0},className:Ve(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:o.jsxs("svg",{width:D,height:k,viewBox:`${U} ${_} ${B} ${G}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":q,ref:E,onClick:W,children:[J&&o.jsx("title",{id:q,children:J}),o.jsx(dT,{onClick:P,nodeColor:l,nodeStrokeColor:n,nodeBorderRadius:s,nodeClassName:a,nodeStrokeWidth:i,nodeComponent:r}),o.jsx("path",{className:"react-flow__minimap-mask",d:`M${U-L},${_-L}h${B+L*2}v${G+L*2}h${-B-L*2}z
165
- M${A.x},${A.y}h${A.width}v${A.height}h${-A.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}l2.displayName="MiniMap";const xT=b.memo(l2),yT=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,vT={[ms.Line]:"right",[ms.Handle]:"bottom-right"};function bT({nodeId:e,position:t,variant:n=ms.Handle,className:l,style:a=void 0,children:s,color:i,minWidth:r=10,minHeight:c=10,maxWidth:u=Number.MAX_VALUE,maxHeight:d=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:h,autoScale:p=!0,shouldResize:x,onResizeStart:S,onResize:w,onResizeEnd:g}){const y=Ob(),m=typeof e=="string"?e:y,v=De(),j=b.useRef(null),E=n===ms.Handle,M=he(b.useCallback(yT(E&&p),[E,p]),ze),A=b.useRef(null),C=t??vT[n];b.useEffect(()=>{if(!(!j.current||!m))return A.current||(A.current=zM({domNode:j.current,nodeId:m,getStoreItems:()=>{const{nodeLookup:T,transform:$,snapGrid:V,snapToGrid:N,nodeOrigin:D,domNode:k}=v.getState();return{nodeLookup:T,transform:$,snapGrid:V,snapToGrid:N,nodeOrigin:D,paneDomNode:k}},onChange:(T,$)=>{const{triggerNodeChanges:V,nodeLookup:N,parentLookup:D,nodeOrigin:k}=v.getState(),R=[],z={x:T.x,y:T.y},O=N.get(m);if(O&&O.expandParent&&O.parentId){const Y=O.origin??k,X=T.width??O.measured.width??0,L=T.height??O.measured.height??0,U={id:O.id,parentId:O.parentId,rect:{width:X,height:L,...eb({x:T.x??O.position.x,y:T.y??O.position.y},{width:X,height:L},O.parentId,N,Y)}},_=rp([U],N,D,k);R.push(..._),z.x=T.x?Math.max(Y[0]*X,T.x):void 0,z.y=T.y?Math.max(Y[1]*L,T.y):void 0}if(z.x!==void 0&&z.y!==void 0){const Y={id:m,type:"position",position:{...z}};R.push(Y)}if(T.width!==void 0&&T.height!==void 0){const X={id:m,type:"dimensions",resizing:!0,setAttributes:h?h==="horizontal"?"width":"height":!0,dimensions:{width:T.width,height:T.height}};R.push(X)}for(const Y of $){const X={...Y,type:"position"};R.push(X)}V(R)},onEnd:({width:T,height:$})=>{const V={id:m,type:"dimensions",resizing:!1,dimensions:{width:T,height:$}};v.getState().triggerNodeChanges([V])}})),A.current.update({controlPosition:C,boundaries:{minWidth:r,minHeight:c,maxWidth:u,maxHeight:d},keepAspectRatio:f,resizeDirection:h,onResizeStart:S,onResize:w,onResizeEnd:g,shouldResize:x}),()=>{var T;(T=A.current)==null||T.destroy()}},[C,r,c,u,d,f,S,w,g,x]);const H=C.split("-");return o.jsx("div",{className:Ve(["react-flow__resize-control","nodrag",...H,n,l]),ref:j,style:{...a,scale:M,...i&&{[E?"backgroundColor":"borderColor"]:i}},children:s})}b.memo(bT);const xn={concepts:{fill:"#f75858",light:"#ff9090",dark:"#be3232",glowRgb:"254,0,0",edgeColor:"rgba(254,0,0,0.55)",hex:"#f75858"},entities:{fill:"#5e89e0",light:"#8cb4ff",dark:"#3658b4",glowRgb:"16,96,255",edgeColor:"rgba(16,96,255,0.55)",hex:"#5e89e0"},summaries:{fill:"#bd68bd",light:"#dc8cdc",dark:"#460f46",glowRgb:"171,49,170",edgeColor:"rgba(171,49,170,0.55)",hex:"#bd68bd"},other:{fill:"#24b550",light:"#82e6a0",dark:"#0c5023",glowRgb:"36,181,80",edgeColor:"rgba(36,181,80,0.55)",hex:"#24b550"}};function ad(e){return xn[e.toLowerCase()]??xn.other}function wT(e,t,n=150){const l=e.length,a=new Map,s=new Map,i=Math.min(600,Math.max(150,l*40));e.forEach((c,u)=>{const d=u/l*2*Math.PI;a.set(c.slug,{x:400+i*Math.cos(d),y:400+i*Math.sin(d)}),s.set(c.slug,{vx:0,vy:0})});const r=e.map(c=>c.slug);for(let c=0;c<n;c++){for(let u=0;u<r.length;u++)for(let d=u+1;d<r.length;d++){const f=r[u],h=r[d],p=a.get(f),x=a.get(h),S=x.x-p.x,w=x.y-p.y,g=Math.max(1,S*S+w*w),y=Math.sqrt(g),m=18e3/g,v=S/y*m,j=w/y*m,E=s.get(f),M=s.get(h);E.vx-=v,E.vy-=j,M.vx+=v,M.vy+=j}for(const u of t){const d=a.get(u.source),f=a.get(u.target);if(!d||!f)continue;const h=f.x-d.x,p=f.y-d.y,x=Math.max(1,Math.sqrt(h*h+p*p)),S=x*.02,w=h/x*S,g=p/x*S,y=s.get(u.source),m=s.get(u.target);y&&(y.vx+=w,y.vy+=g),m&&(m.vx-=w,m.vy-=g)}for(const u of r){const d=a.get(u),f=s.get(u);f.vx=Math.max(-20,Math.min(20,f.vx)),f.vy=Math.max(-20,Math.min(20,f.vy)),d.x+=f.vx,d.y+=f.vy,f.vx*=.85,f.vy*=.85}}return a}const ST=5,NT=9;function jT(e){const t=e.data,n=t.radius,l=t.degree,a=t.dimmed,s=t.hovered,i=t.glowRgb,r=t.fill,c=l>=ST,u=l>=NT,d=a?"none":s?`0 0 0 1.5px rgba(${i},0.8), 0 0 10px rgba(${i},1), 0 0 24px rgba(${i},0.7), 0 0 44px rgba(${i},0.3), 0 0 70px rgba(${i},0.12)`:`0 0 0 1px rgba(${i},0.35), 0 0 7px rgba(${i},0.65), 0 0 18px rgba(${i},0.25)`,f=s?"scale(1.28)":"scale(1)";return o.jsxs("div",{style:{position:"relative",width:n*2,height:n*2},children:[c&&!a&&o.jsx("div",{style:{position:"absolute",inset:-(n*.55),borderRadius:"50%",background:`radial-gradient(circle, rgba(${i},0.08) 0%, transparent 70%)`,pointerEvents:"none"}}),c&&!a&&o.jsx("div",{style:{position:"absolute",inset:-(n*.45),borderRadius:"50%",border:`1.5px solid rgba(${i},0.5)`,animation:"wikiNodePulse 2.6s cubic-bezier(0.4,0,0.6,1) infinite",pointerEvents:"none"}}),u&&!a&&o.jsx("div",{style:{position:"absolute",inset:-(n*.8),borderRadius:"50%",border:`1px solid rgba(${i},0.28)`,animation:"wikiNodePulse 3.8s cubic-bezier(0.4,0,0.6,1) infinite 1.1s",pointerEvents:"none"}}),o.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:"50%",background:`radial-gradient(circle at 33% 28%, ${t.light} 0%, ${r} 52%, ${t.dark} 100%)`,boxShadow:d,opacity:a?.06:1,transform:f,transition:"transform 0.22s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s ease, opacity 0.18s ease",overflow:"hidden"},children:[o.jsx("div",{style:{position:"absolute",top:"9%",left:"14%",width:"38%",height:"38%",borderRadius:"50%",background:"radial-gradient(circle, rgba(255,255,255,0.62) 0%, rgba(255,255,255,0.1) 55%, transparent 100%)",pointerEvents:"none"}}),o.jsx("div",{style:{position:"absolute",bottom:"10%",right:"12%",width:"22%",height:"22%",borderRadius:"50%",background:"radial-gradient(circle, rgba(255,255,255,0.18) 0%, transparent 100%)",pointerEvents:"none"}})]}),!a&&o.jsx("div",{style:{position:"absolute",top:n*2+5,left:"50%",transform:"translateX(-50%)",whiteSpace:"nowrap",maxWidth:128,overflow:"hidden",textOverflow:"ellipsis",fontSize:s?10:9,fontWeight:s?600:400,color:s?r:"var(--text2)",background:"color-mix(in srgb, var(--bg) 78%, transparent)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",padding:"1px 6px 2px",borderRadius:5,border:s?`1px solid rgba(${i},0.4)`:"1px solid transparent",boxShadow:s?`0 0 8px rgba(${i},0.3)`:"none",transition:"all 0.2s ease",fontFamily:"inherit",letterSpacing:s?"0.025em":"normal",pointerEvents:"none"},children:t.title}),o.jsx(ys,{type:"target",position:ee.Left,style:{opacity:0,pointerEvents:"none"}}),o.jsx(ys,{type:"source",position:ee.Right,style:{opacity:0,pointerEvents:"none"}})]})}const kT={wikiNode:jT},ET=[{label:"Concepts",color:xn.concepts.fill,rgb:xn.concepts.glowRgb},{label:"Entities",color:xn.entities.fill,rgb:xn.entities.glowRgb},{label:"Summaries",color:xn.summaries.fill,rgb:xn.summaries.glowRgb},{label:"Other",color:xn.other.fill,rgb:xn.other.glowRgb}];function CT({graphData:e,loading:t,onNodeClick:n}){const{initNodes:l,initEdges:a,adjacency:s}=b.useMemo(()=>{var M,A;const S=(e==null?void 0:e.nodes)??[],w=(e==null?void 0:e.edges)??[];if(S.length===0)return{initNodes:[],initEdges:[],adjacency:new Map};const g=new Map,y=new Map;for(const C of S)g.set(C.slug,0),y.set(C.slug,C.category);for(const C of w)g.set(C.source,(g.get(C.source)??0)+1),g.set(C.target,(g.get(C.target)??0)+1);const m=new Map;for(const C of S)m.set(C.slug,new Set);for(const C of w)(M=m.get(C.source))==null||M.add(C.target),(A=m.get(C.target))==null||A.add(C.source);const v=wT(S,w,150),j=S.map(C=>{const H=g.get(C.slug)??0,T=Math.min(11,Math.max(4,4+H*.8)),$=v.get(C.slug)??{x:400,y:400},V=ad(C.category);return{id:C.slug,type:"wikiNode",position:$,data:{slug:C.slug,title:C.title||(C.slug.split("/").pop()??C.slug),category:C.category,fill:V.fill,light:V.light,dark:V.dark,glowRgb:V.glowRgb,radius:T,degree:H,dimmed:!1,hovered:!1}}}),E=w.map((C,H)=>{const T=ad(y.get(C.source)??"other");return{id:`e${H}-${C.source}-${C.target}`,source:C.source,target:C.target,type:"straight",animated:!0,style:{stroke:T.edgeColor,strokeWidth:1.3,opacity:.85}}});return{initNodes:j,initEdges:E,adjacency:m}},[e]),[i,r,c]=GA(l),[u,d,f]=QA(a);b.useEffect(()=>{r(l),d(a)},[l,a,r,d]);const h=b.useCallback((S,w)=>{n(w.id)},[n]),p=b.useCallback((S,w)=>{const g=w.id,y=new Set([g,...s.get(g)??[]]);r(m=>m.map(v=>({...v,data:{...v.data,dimmed:!y.has(v.id),hovered:v.id===g}}))),d(m=>m.map(v=>({...v,style:{...v.style??{},opacity:y.has(v.source)&&y.has(v.target)?1:.05}})))},[s,r,d]),x=b.useCallback(()=>{r(S=>S.map(w=>({...w,data:{...w.data,dimmed:!1,hovered:!1}}))),d(S=>S.map(w=>({...w,style:{...w.style??{},opacity:.85}})))},[r,d]);return t?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4",style:{color:"var(--muted)"},children:[o.jsx("div",{style:{width:36,height:36,border:"2.5px solid var(--b2)",borderTopColor:"var(--gold)",borderRadius:"50%",animation:"wikiSpin 0.75s linear infinite",boxShadow:"0 0 12px rgba(224,175,104,0.35)"}}),o.jsx("span",{className:"text-[11px]",children:"Building knowledge graph…"})]}):!e||e.nodes.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-center",children:[o.jsx("div",{style:{width:56,height:56,borderRadius:"50%",background:"radial-gradient(circle at 35% 30%, var(--s3), var(--s1))",border:"1px solid var(--b1)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 24px rgba(224,175,104,0.08)"},children:o.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--gold)",opacity:.5},children:[o.jsx("circle",{cx:"12",cy:"12",r:"2.5"}),o.jsx("circle",{cx:"4.5",cy:"4.5",r:"1.5"}),o.jsx("circle",{cx:"19.5",cy:"4.5",r:"1.5"}),o.jsx("circle",{cx:"4.5",cy:"19.5",r:"1.5"}),o.jsx("circle",{cx:"19.5",cy:"19.5",r:"1.5"}),o.jsx("line",{x1:"12",y1:"9.5",x2:"5.5",y2:"5.5"}),o.jsx("line",{x1:"12",y1:"9.5",x2:"18.5",y2:"5.5"}),o.jsx("line",{x1:"12",y1:"14.5",x2:"5.5",y2:"18.5"}),o.jsx("line",{x1:"12",y1:"14.5",x2:"18.5",y2:"18.5"})]})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[13px] font-semibold",style:{color:"var(--fg)"},children:"Graph is empty"}),o.jsx("div",{className:"text-[11px] mt-1.5",style:{color:"var(--muted)"},children:"Ingest documents to build the knowledge graph"})]}),o.jsx("div",{className:"text-[10px] font-mono px-3 py-1.5 rounded-lg",style:{background:"var(--s2)",color:"var(--muted)",border:"1px solid var(--b1)",letterSpacing:"0.02em"},children:"ingest plans/spec.md into the wiki"})]}):o.jsxs("div",{style:{width:"100%",height:"100%",position:"relative",background:"var(--bg)"},children:[o.jsxs(XA,{nodes:i,edges:u,onNodesChange:c,onEdgesChange:f,nodeTypes:kT,onNodeClick:h,onNodeMouseEnter:p,onNodeMouseLeave:x,fitView:!0,fitViewOptions:{padding:.2},colorMode:"dark",proOptions:{hideAttribution:!0},style:{background:"var(--bg)"},nodesDraggable:!0,nodesConnectable:!1,elementsSelectable:!1,children:[o.jsx(JA,{variant:In.Dots,gap:26,size:1.2,color:"var(--b1)"}),o.jsx(aT,{}),o.jsx(xT,{nodeColor:S=>ad(S.data.category).hex,maskColor:"color-mix(in srgb, var(--s1) 75%, transparent)",style:{background:"color-mix(in srgb, var(--s2) 90%, transparent)",backdropFilter:"blur(8px)",border:"1px solid color-mix(in srgb, var(--b2) 50%, transparent)",borderRadius:10,boxShadow:"0 4px 20px rgba(0,0,0,0.35)"}})]}),o.jsx("div",{style:{position:"absolute",inset:0,background:["radial-gradient(ellipse 75% 75% at 50% 50%, transparent 25%, color-mix(in srgb, var(--s1) 65%, transparent) 100%)","radial-gradient(circle at 25% 80%, rgba(224,175,104,0.03) 0%, transparent 50%)"].join(", "),pointerEvents:"none",zIndex:3}}),o.jsx("div",{style:{position:"absolute",bottom:14,left:14,zIndex:10,display:"flex",flexDirection:"column",gap:6,background:"color-mix(in srgb, var(--s2) 88%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",border:"1px solid color-mix(in srgb, var(--b2) 45%, transparent)",borderRadius:11,padding:"9px 13px",pointerEvents:"none",boxShadow:"0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04)"},children:ET.map(({label:S,color:w,rgb:g})=>o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[o.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:w,boxShadow:`0 0 6px rgba(${g},0.7)`,flexShrink:0}}),o.jsx("span",{style:{fontSize:10,color:"var(--text2)",fontFamily:"inherit",letterSpacing:"0.02em"},children:S})]},S))}),o.jsxs("div",{style:{position:"absolute",top:12,left:"50%",transform:"translateX(-50%)",zIndex:10,display:"flex",alignItems:"center",gap:8,background:"color-mix(in srgb, var(--s2) 88%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",border:"1px solid color-mix(in srgb, var(--b2) 40%, transparent)",borderRadius:20,padding:"3px 12px",pointerEvents:"none",boxShadow:"0 2px 12px rgba(0,0,0,0.25)"},children:[o.jsxs("span",{style:{fontSize:10,color:"var(--text2)",fontFamily:"inherit",letterSpacing:"0.04em"},children:[o.jsx("span",{style:{color:"var(--gold)",fontWeight:600},children:e.nodes.length})," ","nodes"]}),o.jsx("div",{style:{width:1,height:10,background:"var(--b2)"}}),o.jsxs("span",{style:{fontSize:10,color:"var(--text2)",fontFamily:"inherit",letterSpacing:"0.04em"},children:[o.jsx("span",{style:{color:"var(--gold)",fontWeight:600},children:e.edges.length})," ","connections"]})]})]})}function MT({rpc:e,className:t}){const{ws:n}=Cn(),[l,a]=b.useState([]),[s,i]=b.useState(!0),[r,c]=b.useState("browse"),u=b.useRef("browse");u.current=r;const[d,f]=b.useState(null),[h,p]=b.useState(null),[x,S]=b.useState(!1),[w,g]=b.useState(""),[y,m]=b.useState([]),[v,j]=b.useState(!1),[E,M]=b.useState(null),[A,C]=b.useState(!1),[H,T]=b.useState(null),[$,V]=b.useState(null),[N,D]=b.useState(!1),k=b.useCallback(async(U=!1)=>{if(e){U||D(!0);try{const _=await e.wikiGraph();V(_??{nodes:[],edges:[]})}catch{V({nodes:[],edges:[]})}finally{U||D(!1)}}},[e]),R=b.useCallback(async(U=!1)=>{if(e){U||i(!0),T(null);try{const _=await e.wikiListPages();a((_==null?void 0:_.pages)??[])}catch(_){T(_ instanceof Error?_.message:"Failed to load wiki")}finally{U||i(!1)}}},[e]);b.useEffect(()=>{R()},[R]),b.useEffect(()=>{if(n)return n.on("wiki-op",()=>{R(!0),u.current==="graph"&&k(!0)})},[n,R,k]);const z=b.useCallback(async U=>{if(e){f(U),c("page"),S(!0),p(null);try{const _=await e.wikiPageGet(U);p((_==null?void 0:_.content)??(_==null?void 0:_.error)??"Empty page")}catch(_){p(_ instanceof Error?_.message:"Error loading page")}finally{S(!1)}}},[e]),O=b.useCallback(async()=>{if(!(!e||!w.trim())){j(!0),m([]);try{const U=await e.wikiSearch(w);m(U??[])}finally{j(!1)}}},[e,w]),Y=b.useCallback(async()=>{if(e){c("lint"),C(!0),M(null);try{const U=await e.wikiLint();M(U??{orphanPages:[],brokenLinks:[],missingFromIndex:[],staleFrontmatter:[]})}finally{C(!1)}}},[e]),X=l.reduce((U,_)=>{const B=_.category||"Other";return(U[B]??(U[B]=[])).push(_),U},{}),L=E?E.orphanPages.length+E.brokenLinks.length+E.missingFromIndex.length+E.staleFrontmatter.length:null;return o.jsxs("div",{className:`flex flex-col h-full ${t??""}`,children:[o.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--gold)",flexShrink:0},children:[o.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),o.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"})]}),o.jsx("span",{className:"text-[13px] font-semibold font-display",style:{color:"var(--cream)"},children:"Wiki"}),o.jsxs("span",{className:"text-[11px] font-mono",style:{color:"var(--muted)"},children:[l.length," pages"]}),o.jsx("div",{className:"flex-1"}),o.jsx("button",{onClick:()=>c("browse"),className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer",style:{background:r==="browse"?"var(--s3)":"transparent",color:r==="browse"?"var(--gold)":"var(--muted)",border:r==="browse"?"1px solid var(--b2)":"1px solid transparent"},children:"Browse"}),o.jsx("button",{onClick:()=>c("search"),className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer",style:{background:r==="search"?"var(--s3)":"transparent",color:r==="search"?"var(--gold)":"var(--muted)",border:r==="search"?"1px solid var(--b2)":"1px solid transparent"},children:"Search"}),o.jsxs("button",{onClick:Y,className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer flex items-center gap-1",style:{background:r==="lint"?"var(--s3)":"transparent",color:r==="lint"?"var(--gold)":"var(--muted)",border:r==="lint"?"1px solid var(--b2)":"1px solid transparent"},children:["Lint",L!==null&&L>0&&o.jsx("span",{className:"rounded-full w-4 h-4 flex items-center justify-center text-[9px] font-bold",style:{background:"var(--red)",color:"#fff"},children:L})]}),o.jsx("button",{onClick:()=>{c("graph"),!$&&!N&&k()},className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer",style:{background:r==="graph"?"var(--s3)":"transparent",color:r==="graph"?"var(--gold)":"var(--muted)",border:r==="graph"?"1px solid var(--b2)":"1px solid transparent"},children:"Graph"}),o.jsx("button",{onClick:()=>R(),className:"flex items-center justify-center w-7 h-7 rounded-lg transition-all duration-150 cursor-pointer",style:{color:"var(--muted)",border:"1px solid transparent"},title:"Refresh",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[o.jsx("polyline",{points:"23 4 23 10 17 10"}),o.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})})]}),r==="graph"&&o.jsx("div",{className:"flex-1 min-h-0",children:o.jsx(CT,{graphData:$,loading:N,onNodeClick:z})}),o.jsxs("div",{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3 scrollbar-thin${r==="graph"?" hidden":""}`,children:[r==="browse"&&o.jsxs(o.Fragment,{children:[s&&o.jsx("div",{className:"flex items-center justify-center h-32 text-xs",style:{color:"var(--muted)"},children:"Loading…"}),H&&o.jsx("div",{className:"text-xs px-3 py-2 rounded-lg",style:{background:"color-mix(in srgb, var(--red) 10%, transparent)",color:"var(--red)",border:"1px solid color-mix(in srgb, var(--red) 20%, transparent)"},children:H}),!s&&!H&&l.length===0&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-48 gap-3 text-center",children:[o.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",style:{color:"var(--muted)",opacity:.4},children:[o.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),o.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[12px] font-semibold",style:{color:"var(--fg)"},children:"Wiki is empty"}),o.jsx("div",{className:"text-[11px] mt-1",style:{color:"var(--muted)"},children:"Ask the agent to ingest a document to get started"})]}),o.jsx("div",{className:"text-[10px] font-mono px-3 py-1.5 rounded-lg",style:{background:"var(--s2)",color:"var(--muted)",border:"1px solid var(--b1)"},children:"ingest plans/spec.md into the wiki"})]}),!s&&Object.entries(X).map(([U,_])=>o.jsxs("div",{className:"mb-4",children:[o.jsx("div",{className:"text-[10px] font-mono uppercase tracking-widest mb-1.5 px-1",style:{color:"var(--muted)"},children:U}),o.jsx("div",{className:"space-y-1",children:_.map(B=>o.jsxs("button",{onClick:()=>z(B.slug),className:"w-full text-left px-3 py-2 rounded-lg transition-all duration-150 cursor-pointer active:scale-[0.99]",style:{background:"var(--s2)",border:"1px solid var(--b1)",color:"var(--fg)"},children:[o.jsx("div",{className:"text-[12px] font-medium truncate",children:B.title||B.slug.split("/").pop()}),o.jsx("div",{className:"text-[10px] font-mono mt-0.5 truncate",style:{color:"var(--muted)"},children:B.slug})]},B.slug))})]},U))]}),r==="page"&&o.jsxs("div",{children:[o.jsxs("button",{onClick:()=>c("browse"),className:"flex items-center gap-1.5 text-[11px] mb-3 cursor-pointer transition-colors duration-100",style:{color:"var(--muted)"},children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Back to index"]}),x&&o.jsx("div",{className:"flex items-center justify-center h-32 text-xs",style:{color:"var(--muted)"},children:"Loading…"}),!x&&h!==null&&o.jsx("pre",{className:"text-[11px] leading-relaxed whitespace-pre-wrap font-mono p-3 rounded-lg overflow-auto",style:{background:"var(--s2)",color:"var(--fg)",border:"1px solid var(--b1)"},children:h})]}),r==="search"&&o.jsxs("div",{children:[o.jsxs("div",{className:"flex gap-2 mb-3",children:[o.jsx("input",{type:"text",value:w,onChange:U=>g(U.target.value),onKeyDown:U=>U.key==="Enter"&&O(),placeholder:"Search wiki pages…",className:"flex-1 px-3 py-2 rounded-lg text-[12px] outline-none",style:{background:"var(--s2)",border:"1px solid var(--b2)",color:"var(--fg)"},autoFocus:!0}),o.jsx("button",{onClick:O,disabled:v||!w.trim(),className:"px-3 py-2 rounded-lg text-[11px] font-semibold cursor-pointer transition-all duration-150 active:scale-[0.97]",style:{background:"color-mix(in srgb, var(--gold) 15%, transparent)",color:"var(--gold)",border:"1px solid color-mix(in srgb, var(--gold) 25%, transparent)",opacity:v||!w.trim()?.5:1},children:v?"…":"Search"})]}),y.length===0&&!v&&w&&o.jsxs("div",{className:"text-center py-8 text-xs",style:{color:"var(--muted)"},children:['No results for "',w,'"']}),y.length>0&&o.jsx("div",{className:"space-y-1",children:y.map((U,_)=>o.jsxs("button",{onClick:()=>z(U.slug),className:"w-full text-left px-3 py-2 rounded-lg transition-all duration-150 cursor-pointer active:scale-[0.99]",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsxs("div",{className:"text-[11px] font-mono",style:{color:"var(--gold)"},children:[U.slug,":",U.lineNumber]}),o.jsx("div",{className:"text-[11px] mt-0.5 truncate font-mono",style:{color:"var(--fg)"},children:U.line.trim()})]},_))})]}),r==="lint"&&o.jsxs("div",{children:[A&&o.jsx("div",{className:"flex items-center justify-center h-32 text-xs",style:{color:"var(--muted)"},children:"Running lint…"}),!A&&E&&o.jsxs("div",{className:"space-y-4",children:[L===0&&o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"color-mix(in srgb, var(--green) 10%, transparent)",color:"var(--green)",border:"1px solid color-mix(in srgb, var(--green) 20%, transparent)"},children:[o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Wiki looks clean — no issues found"]}),o.jsx(Gr,{title:"Orphan pages",items:E.orphanPages,color:"var(--yellow)",note:"Written but not linked from any other page"}),o.jsx(Gr,{title:"Broken links",items:E.brokenLinks.map(U=>`${U.from} → [[${U.to}]]`),color:"var(--red)",note:"[[wikilinks]] that reference missing pages"}),o.jsx(Gr,{title:"Missing from index",items:E.missingFromIndex,color:"var(--yellow)",note:"Pages not listed in index.md"}),o.jsx(Gr,{title:"Stale frontmatter",items:E.staleFrontmatter,color:"var(--muted)",note:"updated: field older than 30 days"})]})]})]})]})}function Gr({title:e,items:t,color:n,note:l}){return t.length===0?null:o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[o.jsx("span",{className:"text-[11px] font-semibold",style:{color:n},children:e}),o.jsx("span",{className:"rounded-full px-1.5 py-0.5 text-[9px] font-bold font-mono",style:{background:`color-mix(in srgb, ${n} 15%, transparent)`,color:n},children:t.length})]}),o.jsx("div",{className:"text-[10px] mb-2",style:{color:"var(--muted)"},children:l}),o.jsx("div",{className:"space-y-1",children:t.map((a,s)=>o.jsx("div",{className:"px-3 py-1.5 rounded-lg text-[11px] font-mono truncate",style:{background:"var(--s2)",color:"var(--fg)",border:"1px solid var(--b1)"},children:a},s))})]})}const Nx=[["/status","Show version, model, provider, tokens, CWD"],["/help","List all available commands"],["/model [name]","Switch model · opus / sonnet / haiku / gpt4o"],["/mode <mode>","Set approval mode · plan|edit|auto|yolo"],["/theme [name]","Change color theme"],["/debug [on|off]","Toggle debug logging"],["/effort [level]","Set reasoning effort · low|medium|high|max"],["/context","Show context window usage grid"],["/context compact","Compact the context window"],["/context auto","Configure auto-compaction"],["/memory status","View memory file sizes"],["/memory add","Capture a memory"],["/wiki","Open the wiki knowledge base"],["/wiki list","List all wiki pages by category"],["/wiki search <query>","Search wiki pages"],["/wiki lint","Run wiki health check"],["/heartbeat now","Trigger heartbeat immediately"],["/heartbeat enable","Enable heartbeat schedule"],["/remind <msg at time>","Create a reminder"],["/cron list","List all reminders"],["/channels list","Show Telegram channels"],["/mcp list","Show MCP servers"],["/mcp add","Add an MCP server"],["/tools [n]","View/set tool call limit per turn"],["/websearch [n]","Set web search limit per turn"],["/snapshots","List git snapshots"],["/revert","Revert to a snapshot"],["/stats","View usage stats"],["/agent <prompt>","Spawn a subagent"],["/task create","Create a scheduled task"],["/provider <name>","Switch AI provider"],["/init","Run interactive setup wizard"],["/exit","Exit curie-agent"]];function _T({open:e,onClose:t,onPick:n}){const[l,a]=b.useState(""),[s,i]=b.useState(0),r=b.useRef(null),c=l?Nx.filter(([f,h])=>f.includes(l.toLowerCase())||h.toLowerCase().includes(l.toLowerCase())):Nx,u=b.useCallback(f=>{t(),n(f)},[t,n]);b.useEffect(()=>{e&&(a(""),i(0),setTimeout(()=>{var f;return(f=r.current)==null?void 0:f.focus()},50))},[e]);const d=b.useCallback(f=>{if(f.key==="Escape"){t();return}f.key==="ArrowDown"&&(i(h=>Math.min(h+1,c.length-1)),f.preventDefault()),f.key==="ArrowUp"&&(i(h=>Math.max(h-1,0)),f.preventDefault()),f.key==="Enter"&&c[s]&&u(c[s][0])},[c,s,t,u]);return e?o.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[120px]",style:{background:"rgba(10, 8, 5, 0.85)",backdropFilter:"blur(8px)"},onClick:t,children:o.jsxs("div",{className:"w-[560px] rounded-xl overflow-hidden animate-scaleIn",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b2)",boxShadow:"0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.03)"},onClick:f=>f.stopPropagation(),children:[o.jsxs("div",{className:"flex items-center gap-2 px-4 py-3",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",className:"shrink-0",style:{opacity:.7},children:[o.jsx("circle",{cx:"11",cy:"11",r:"8"}),o.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),o.jsx("input",{ref:r,className:"flex-1 bg-transparent border-0 outline-none font-sans text-sm",style:{color:"var(--cream)"},placeholder:"Search commands...",value:l,onChange:f=>{a(f.target.value),i(0)},onKeyDown:d})]}),o.jsx("div",{className:"gold-divider"}),o.jsxs("div",{className:"max-h-[340px] overflow-y-auto py-1 scrollbar-thin",children:[c.map(([f,h],p)=>o.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg cursor-pointer transition-all duration-150 mx-1",style:{background:p===s?"var(--s3)":"transparent",borderLeft:p===s?"2px solid var(--gold)":"2px solid transparent"},onClick:()=>u(f),children:[o.jsx("span",{className:"font-mono text-[12.5px] min-w-[190px]",style:{color:p===s?"var(--gold)":"var(--text)"},children:f}),o.jsx("span",{className:"text-xs text-muted truncate",children:h})]},f)),c.length===0&&o.jsx("div",{className:"px-3 py-6 text-center text-muted text-sm",children:"No commands found"})]})]})}):null}const ka={anthropic:{label:"Anthropic",defaultModel:"claude-sonnet-4-6",requiresKey:!0},openai:{label:"OpenAI",defaultModel:"gpt-4o",requiresKey:!0},local:{label:"Local (OpenAI-compatible)",defaultModel:"custom",requiresKey:!1},openrouter:{label:"OpenRouter",defaultModel:"anthropic/claude-sonnet-4-6",requiresKey:!0},ollama:{label:"Ollama (Local)",defaultModel:"custom",requiresKey:!1}};function AT({rpc:e,onComplete:t,className:n}){const[l,a]=b.useState("provider"),[s,i]=b.useState(null),[r,c]=b.useState(""),[u,d]=b.useState(""),[f,h]=b.useState(""),[p,x]=b.useState(""),[S,w]=b.useState(""),[g,y]=b.useState(""),[m,v]=b.useState(""),[j,E]=b.useState(!1),[M,A]=b.useState(null),C=b.useCallback(()=>{switch(A(null),l){case"provider":{if(!s)return;const N=ka[s];d(N.defaultModel),a(N.requiresKey?"api_key":"model");break}case"api_key":a("model");break;case"model":a("soul_name");break;case"soul_name":if(!f.trim())return;a("soul_vibe");break;case"soul_vibe":a("user_name");break;case"user_name":if(!S.trim())return;a("user_tz");break;case"user_tz":a("user_lang");break;case"user_lang":a("agents");break;case"agents":a("memory");break;case"memory":a("tools");break;case"tools":a("confirm");break}},[l,s,f,S]),H=b.useCallback(async()=>{if(!(!e||!s)){E(!0),A(null);try{await e.identitySetup({provider:s,apiKey:r,model:u,soulName:f.trim()||"Curie",soulVibe:p.trim()||"AI coding assistant — sharp, resourceful, gets things done",userName:S.trim()||"User",userTimezone:g.trim()||"UTC",userLanguages:m.trim()||"TypeScript, Python"}),t()}catch(N){A(N instanceof Error?N.message:"Setup failed")}finally{E(!1)}}},[e,s,r,u,f,p,S,g,m,t]),T=()=>{switch(l){case"provider":return"Choose your provider";case"api_key":return"API key";case"model":return"Select a model";case"soul_name":return"Name your assistant";case"soul_vibe":return"Define the vibe";case"user_name":return"Your name";case"user_tz":return"Timezone";case"user_lang":return"Programming languages";case"agents":return"Workspace configuration";case"memory":return"Memory";case"tools":return"Tools";case"confirm":return"Review & create"}},$=()=>(["provider","api_key","model","soul_name","soul_vibe","user_name","user_tz","user_lang","agents","memory","tools","confirm"].indexOf(l)+1)/12,V=()=>{switch(l){case"provider":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted mb-4",children:"Which LLM provider do you want to use for your AI assistant?"}),o.jsx("div",{className:"grid grid-cols-1 gap-2",children:Object.entries(ka).map(([N,D])=>o.jsxs("button",{type:"button",onClick:()=>i(N),className:`flex items-center gap-3 px-4 py-3 rounded-xl border text-left transition-all duration-100 ${s===N?"border-blue-500 bg-blue-500/10 text-text":"border-b2 bg-s2 text-text hover:border-b3 hover:bg-s2/80"}`,children:[o.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center shrink-0 ${s===N?"border-blue-500":"border-b3"}`,children:s===N&&o.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-xs font-medium text-text",children:D.label}),o.jsxs("div",{className:"text-[10.5px] text-muted",children:["Model: ",D.defaultModel]})]})]},N))})]});case"api_key":{const N=ka[s];return o.jsxs("div",{className:"space-y-3",children:[o.jsxs("p",{className:"text-xs text-muted",children:["Enter your ",N.label," API key:"]}),o.jsx("input",{type:"password",value:r,onChange:D=>c(D.target.value),placeholder:"sk-...",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text font-mono placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0}),o.jsx("p",{className:"text-[10px] text-muted",children:"Saved to ~/.curie-settings.json"})]})}case"model":{const N=ka[s];return o.jsxs("div",{className:"space-y-3",children:[o.jsxs("p",{className:"text-xs text-muted",children:["Suggested model: ",o.jsx("code",{className:"text-text font-mono",children:N.defaultModel})]}),o.jsx("input",{type:"text",value:u,onChange:D=>d(D.target.value),placeholder:"Enter model name or accept the default",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text font-mono placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]})}case"soul_name":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"What should your AI assistant's name be?"}),o.jsx("input",{type:"text",value:f,onChange:N=>h(N.target.value),placeholder:"Curie",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"soul_vibe":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Describe your assistant's vibe/personality (1 sentence)."}),o.jsx("input",{type:"text",value:p,onChange:N=>x(N.target.value),placeholder:"AI coding assistant — sharp, resourceful, gets things done",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"user_name":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"What is your name?"}),o.jsx("input",{type:"text",value:S,onChange:N=>w(N.target.value),placeholder:"Paweł",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"user_tz":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Your timezone?"}),o.jsx("input",{type:"text",value:g,onChange:N=>y(N.target.value),placeholder:"Europe/Warsaw",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text font-mono placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"user_lang":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Your primary programming languages?"}),o.jsx("input",{type:"text",value:m,onChange:N=>v(N.target.value),placeholder:"TypeScript, Python",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"agents":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Next: I'll create your workspace configuration files."}),o.jsxs("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-[10.5px] text-text leading-relaxed",children:[o.jsx("p",{className:"font-medium mb-1",children:"AGENTS.md will include:"}),o.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-muted",children:[o.jsx("li",{children:"Session startup instructions"}),o.jsx("li",{children:"Memory system (daily notes + long-term)"}),o.jsx("li",{children:"Coding agent capabilities"}),o.jsx("li",{children:"Red lines and safety boundaries"}),o.jsx("li",{children:"Heartbeat configuration"})]})]})]});case"memory":return o.jsx("div",{className:"space-y-3",children:o.jsx("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-xs text-text leading-relaxed",children:o.jsx("p",{children:"Auto-creating MEMORY.md with initialization entry..."})})});case"tools":return o.jsx("div",{className:"space-y-3",children:o.jsx("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-xs text-text leading-relaxed",children:o.jsx("p",{children:"Auto-creating TOOLS.md and HEARTBEAT.md..."})})});case"confirm":return o.jsxs("div",{className:"space-y-4",children:[o.jsx("p",{className:"text-xs text-muted",children:"Review your configuration before creating files:"}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(cl,{label:"Provider",value:ka[s].label}),o.jsx(cl,{label:"Model",value:u}),o.jsx(cl,{label:"API Key",value:r?"[set]":"(not set)"}),o.jsx(cl,{label:"Assistant Name",value:f.trim()||"Curie"}),o.jsx(cl,{label:"Vibe",value:p.trim()||"AI coding assistant"}),o.jsx(cl,{label:"Your Name",value:S.trim()||"User"}),o.jsx(cl,{label:"Timezone",value:g.trim()||"UTC"}),o.jsx(cl,{label:"Languages",value:m.trim()||"TypeScript, Python"})]}),o.jsxs("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-[10.5px] text-muted leading-relaxed",children:["Identity files to be created:",o.jsxs("ul",{className:"list-disc list-inside mt-1",children:[o.jsx("li",{children:"~/.curie-agent/SOUL.md"}),o.jsx("li",{children:"~/.curie-agent/USER.md"}),o.jsx("li",{children:"~/.curie-agent/AGENTS.md"}),o.jsx("li",{children:"~/.curie-agent/MEMORY.md"}),o.jsx("li",{children:"~/.curie-agent/TOOLS.md"}),o.jsx("li",{children:"~/.curie-agent/HEARTBEAT.md"})]})]})]})}};return o.jsx("div",{className:`flex-1 overflow-y-auto p-7 scrollbar-thin flex flex-col ${n||""}`,children:o.jsxs("div",{className:"max-w-lg mx-auto w-full",children:[o.jsxs("div",{className:"mb-6",children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight mb-1",children:"Setup Wizard"}),o.jsx("p",{className:"text-[11px] text-muted",children:"Configure your AI assistant — takes about 2 minutes"})]}),o.jsx("div",{className:"mb-5",children:o.jsx("div",{className:"h-1 bg-b2 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full bg-blue-500 rounded-full transition-all duration-300",style:{width:`${$()*100}%`}})})}),o.jsx("h3",{className:"text-sm font-medium text-text mb-4",children:T()}),o.jsx("div",{className:"mb-6",children:V()}),M&&o.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-xs flex items-start gap-2.5 mb-4",children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"shrink-0 mt-0.5",children:[o.jsx("circle",{cx:"12",cy:"12",r:"10"}),o.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),o.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),o.jsx("span",{children:M})]}),o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l!=="provider"&&l!=="confirm"?o.jsxs("button",{type:"button",onClick:()=>{switch(A(null),l){case"api_key":a("provider");break;case"model":a(ka[s].requiresKey?"api_key":"provider");break;case"soul_name":a("provider");break;case"soul_vibe":a("soul_name");break;case"user_name":a("soul_vibe");break;case"user_tz":a("user_name");break;case"user_lang":a("user_tz");break;case"agents":a("user_lang");break;case"memory":a("agents");break;case"tools":a("memory");break}},className:"flex items-center gap-1 bg-transparent border border-b2 rounded px-3 py-2 text-muted text-xs hover:border-b3 hover:text-fg transition-colors duration-100",children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Back"]}):o.jsx("div",{}),l==="confirm"?o.jsx("button",{type:"button",onClick:H,disabled:j,className:"flex items-center gap-2 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white font-semibold text-xs px-5 py-2 rounded-xl shadow-lg shadow-blue-500/10 disabled:opacity-50 disabled:pointer-events-none active:scale-[0.98] transition-all duration-150",children:j?o.jsxs(o.Fragment,{children:[o.jsxs("svg",{className:"animate-spin h-3.5 w-3.5 text-white",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Creating..."]}):"Create Setup"}):o.jsxs("button",{type:"button",onClick:C,disabled:l==="provider"&&!s||l==="soul_name"&&!f.trim()||l==="user_name"&&!S.trim(),className:"flex items-center gap-2 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white font-semibold text-xs px-5 py-2 rounded-xl shadow-lg shadow-blue-500/10 disabled:opacity-50 disabled:pointer-events-none active:scale-[0.98] transition-all duration-150",children:["Next",o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),o.jsx("polyline",{points:"12 5 19 12 12 19"})]})]})]})]})})}function cl({label:e,value:t}){return o.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-b1/50",children:[o.jsx("span",{className:"text-[10.5px] text-muted",children:e}),o.jsx("span",{className:"text-[10.5px] text-text font-mono",children:t})]})}function TT({onReload:e}){const[t,n]=b.useState(!1);b.useEffect(()=>{const a=()=>n(!0),s=()=>{n(!1),e==null||e()};return window.addEventListener("pwa-update-available",a),window.addEventListener("pwa-controller-updated",s),()=>{window.removeEventListener("pwa-update-available",a),window.removeEventListener("pwa-controller-updated",s)}},[e]);const l=()=>{n(!1),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then(a=>{a.waiting&&a.waiting.postMessage("SKIP_WAITING")}),window._pendingUpdateWorker&&window._pendingUpdateWorker.postMessage("SKIP_WAITING")};return t?o.jsxs("div",{className:"bg-blue-500/10 border-b border-blue-500/20 text-blue-400 px-4 py-2 text-center text-xs font-semibold flex items-center justify-center gap-2 select-none shrink-0 z-50 animate-fadeIn",children:[o.jsxs("svg",{className:"animate-bounce shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),o.jsx("polyline",{points:"17 8 12 3 7 8"}),o.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Update available",o.jsx("button",{onClick:l,className:"bg-blue-500/20 border border-blue-500/40 text-blue-400 px-2 py-0.5 rounded-[4px] text-[11px] font-bold cursor-pointer hover:bg-blue-500/30 transition-all duration-100",children:"Update"})]}):null}const zT="0.2.4";function DT({intervalMs:e=3*60*1e3,onNewVersion:t}){const[n,l]=b.useState(!1);return b.useEffect(()=>{async function a(){var i;try{const c=await(await fetch("/health?token="+encodeURIComponent(((i=document.cookie.match(/curie_token=([^;]*)/))==null?void 0:i[1])??""),{cache:"no-store"})).json();c.version&&c.version!==zT&&!n&&(l(!0),t==null||t(c.version),window.dispatchEvent(new CustomEvent("pwa-version-update")))}catch{}}a();const s=setInterval(a,e);return()=>clearInterval(s)},[e,n,t]),null}function RT(){const{rpc:e,ws:t}=Cn(),[n,l]=b.useState([]),a=b.useCallback(()=>{e&&e.sessionList().then(s=>{Array.isArray(s)&&l(s)}).catch(()=>{})},[e]);return b.useEffect(()=>{a()},[a]),b.useEffect(()=>{if(!t)return;const s=["user-prompt","assistant-stop","error","session-start","session-resumed"],i=[];for(const r of s)i.push(t.on(r,a));return()=>{for(const r of i)r()}},[t,a]),{sessions:n,refetch:a}}function OT(e){const{rpc:t,ws:n}=Cn(),[l,a]=b.useState(null),[s,i]=b.useState([]),[r,c]=b.useState(!1);b.useEffect(()=>{if(!t||!e){a(null),i([]),c(!1);return}c(!0),t.sessionGet(e).then(d=>{d!=null&&d.info&&a(d.info),d!=null&&d.events&&i(d.events)}).catch(()=>{}).finally(()=>c(!1))},[t,e]),b.useEffect(()=>{if(!n||!e)return;const d=p=>{if(p.type!=="heartbeat-brief"&&p.type!=="cron-task-fired"){const x=p.sessionId||p.id;if(x&&x!==e)return}i(x=>x.slice(-10).some(w=>w.timestamp===p.timestamp&&w.type===p.type&&JSON.stringify(w)===JSON.stringify(p))?x:[...x,p])},f=[],h=["user-prompt","assistant-delta","assistant-stop","tool-call","tool-result","error","status","usage","thinking-delta","heartbeat-brief","approval-request","approval-decision","context-warning","cron-task-fired"];for(const p of h)f.push(n.on(p,d));return()=>{for(const p of f)p()}},[n,e]);const u=b.useCallback(d=>{i(f=>[...f,d])},[]);return{info:l,events:s,loading:r,addLiveEvent:u}}function HT({onAuthorize:e}){const[t,n]=b.useState(""),[l,a]=b.useState(!1),[s,i]=b.useState(null),r=async c=>{if(c.preventDefault(),!!t.trim()){a(!0),i(null);try{(await fetch("/health",{headers:{Authorization:`Bearer ${t.trim()}`}})).ok?e(t.trim()):i("Invalid Access Token. Please verify and try again.")}catch{i("Cannot connect to Curie Daemon. Make sure the daemon is running.")}finally{a(!1)}}};return o.jsxs("div",{className:"flex min-h-screen w-screen items-center justify-center p-4 font-sans select-none relative overflow-hidden",style:{background:"#0e0b08",color:"var(--cream, #f5e6d0)"},children:[o.jsx("div",{className:"absolute top-[-20%] left-[-20%] w-[60%] h-[60%] rounded-full opacity-30 blur-[120px] pointer-events-none",style:{background:"#2d1f0e"}}),o.jsx("div",{className:"absolute bottom-[-20%] right-[-20%] w-[60%] h-[60%] rounded-full opacity-25 blur-[120px] pointer-events-none",style:{background:"#1e1408"}}),o.jsx("div",{className:"absolute top-[40%] left-[50%] w-[40%] h-[40%] rounded-full opacity-15 blur-[100px] pointer-events-none",style:{background:"#d4a54a",transform:"translate(-50%, -50%)"}}),o.jsxs("div",{className:"w-full max-w-[440px] rounded-2xl shadow-2xl p-7 flex flex-col items-center animate-scaleIn relative z-10",style:{background:"linear-gradient(135deg, rgba(34, 28, 22, 0.95), rgba(20, 16, 12, 0.98))",backdropFilter:"blur(24px)",border:"1px solid rgba(86, 72, 58, 0.5)",boxShadow:"0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(245,230,208,0.04)"},children:[o.jsx("div",{className:"absolute top-0 left-0 right-0 h-[2px] rounded-t-2xl",style:{background:"linear-gradient(90deg, transparent, #d4a54a, transparent)"}}),o.jsxs("div",{className:"flex flex-col items-center gap-3 mb-6 mt-2",children:[o.jsxs("div",{className:"relative group",children:[o.jsx("div",{className:"absolute inset-0 rounded-xl blur-md group-hover:blur-lg transition-all duration-300 animate-gold-pulse",style:{background:"rgba(212, 165, 74, 0.2)"}}),o.jsx("img",{src:"/icons/logo-512.png",alt:"Curie Logo",className:"w-14 h-14 object-contain rounded-xl relative z-10 transform group-hover:scale-105 transition-transform duration-300",style:{border:"1px solid rgba(86, 72, 58, 0.6)",boxShadow:"0 4px 16px rgba(0,0,0,0.4)"}})]}),o.jsxs("div",{className:"text-center mt-1",children:[o.jsx("span",{className:"text-xl font-display font-bold gold-shimmer block",children:"curie-agent"}),o.jsx("span",{className:"text-[10px] font-mono block mt-0.5",style:{color:"#d4a54a",opacity:.6},children:"v0.2.4"})]})]}),o.jsxs("div",{className:"text-center mb-6",children:[o.jsx("h2",{className:"text-sm font-semibold mb-2",style:{color:"#f5e6d0"},children:"Authorize this device"}),o.jsx("p",{className:"text-[12.5px] leading-relaxed px-2",style:{color:"#8b7355"},children:"Curie requires a secure daemon connection. Enter your access token below to authorize this device and start planning."})]}),o.jsxs("form",{onSubmit:r,className:"w-full space-y-4",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider block ml-1",style:{color:"#d4a54a",opacity:.7},children:"Daemon Access Token"}),o.jsxs("div",{className:"relative group",children:[o.jsx("div",{className:"absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none transition-colors duration-200",style:{color:"#8b7355"},children:o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}),o.jsx("input",{type:"password",required:!0,placeholder:"Paste your daemon.token...",value:t,onChange:c=>n(c.target.value),disabled:l,className:"w-full pl-10 pr-4 py-2.5 rounded-xl text-[13px] font-mono focus:outline-none transition-all duration-200",style:{background:"rgba(14, 11, 8, 0.8)",border:"1px solid rgba(86, 72, 58, 0.4)",color:"#f5e6d0"}})]})]}),s&&o.jsxs("div",{className:"p-3 rounded-xl text-xs flex items-start gap-2.5 animate-fadeIn",style:{background:"color-mix(in srgb, var(--red) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--red) 20%, transparent)",color:"var(--red)"},children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"shrink-0 mt-0.5",children:[o.jsx("circle",{cx:"12",cy:"12",r:"10"}),o.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),o.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),o.jsx("span",{children:s})]}),o.jsx("button",{type:"submit",disabled:l||!t.trim(),className:"btn-gold w-full py-2.5 px-4 rounded-xl font-semibold text-xs active:scale-[0.98] transition-all duration-150 disabled:opacity-50 disabled:pointer-events-none cursor-pointer flex items-center justify-center gap-2",children:l?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"w-3.5 h-3.5 rounded-full animate-spin",style:{background:"conic-gradient(from 0deg, transparent, #1a1410)",mask:"radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 0)",WebkitMask:"radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 0)"}}),"Verifying Credentials..."]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"Authorize & Connect"}),o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),o.jsx("polyline",{points:"12 5 19 12 12 19"})]})]})})]}),o.jsxs("div",{className:"w-full mt-6 pt-5 space-y-2 leading-relaxed",style:{borderTop:"1px solid rgba(86, 72, 58, 0.3)",fontSize:"11.5px",color:"#8b7355"},children:[o.jsx("div",{className:"font-semibold",style:{color:"#bfae94"},children:"Where is my token?"}),o.jsx("p",{children:"When starting the daemon, look for the console output in your terminal. It displays the dashboard link containing the secure token."}),o.jsxs("p",{children:["You can also find the raw token inside the file ",o.jsx("code",{className:"font-mono px-1 py-0.5 rounded text-[10.5px]",style:{background:"rgba(14, 11, 8, 0.6)",border:"1px solid rgba(86, 72, 58, 0.3)",color:"#d4c4a8"},children:"~/.curie-agent/daemon.token"})," on your host machine."]})]})]})]})}const LT=["plan","edit","auto","yolo"],$T=[{view:"assistant",label:"Assistant",icon:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},{view:"channels",label:"Channels",icon:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.86 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.77 2h3a2 2 0 0 1 2 1.72c.127.96.361 1.903.7 2.81a2 2 0 0 1-.45 2.11L7.91 9.91a16 16 0 0 0 6.16 6.16l1.27-1.27a2 2 0 0 1 2.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0 1 22 16.92z"},{view:"stats",label:"Stats",icon:"M18 20V10M12 20V4M6 20v-6"},{view:"projects",label:"Projects",icon:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"},{view:"agents",label:"Agents",icon:"M12 8c0 2.21-1.79 4-4 4s-4-1.79-4-4 1.79-4 4-4 4 1.79 4 4zm-6 12v-2a6 6 0 0 1 12 0v2"},{view:"kanban",label:"Tasks",icon:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"},{view:"wiki",label:"Wiki",icon:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"},{view:"settings",label:"Settings",icon:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}];function BT(){const{rpc:e,connected:t,token:n,setToken:l}=Cn(),{get:a,set:s,providers:i}=kh(),[r,c]=b.useState("assistant"),u=a("mode")||"auto",[d,f]=b.useState(!1),[h,p]=b.useState(""),[x,S]=b.useState(null),[w,g]=b.useState(!1),[y,m]=b.useState(null),[v,j]=b.useState(navigator.onLine),[E,M]=b.useState(!1),[A,C]=b.useState(!1),[H,T]=b.useState(!1),[$,V]=b.useState(!1),N=/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;b.useEffect(()=>{const q=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0;M(!!q)},[]),b.useEffect(()=>{const q=W=>{W.preventDefault(),m(W)},Q=()=>j(!0),K=()=>j(!1);return window.addEventListener("beforeinstallprompt",q),window.addEventListener("online",Q),window.addEventListener("offline",K),()=>{window.removeEventListener("beforeinstallprompt",q),window.removeEventListener("online",Q),window.removeEventListener("offline",K)}},[]);const D=async()=>{if(y){y.prompt();const{outcome:q}=await y.userChoice;console.log(`PWA install prompt choice: ${q}`),m(null)}else C(!0)},{sessions:k,refetch:R}=RT(),{events:z,addLiveEvent:O}=OT(x),Y=a("theme")||"curie";b.useEffect(()=>{document.documentElement.setAttribute("data-theme",Y)},[Y]),b.useEffect(()=>{const q=()=>g(window.innerWidth<768);return q(),window.addEventListener("resize",q),()=>window.removeEventListener("resize",q)},[]),b.useEffect(()=>{!t||!e||e.configGet("current_provider").then(q=>{q||T(!0)}).catch(()=>{})},[t,e]);const X=b.useCallback(()=>{S(null)},[]),L=b.useCallback(q=>{S(q)},[]),U=b.useCallback(q=>{S(q),R()},[R]);b.useEffect(()=>{const q=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="k"&&(Q.preventDefault(),f(!0))};return document.addEventListener("keydown",q),()=>document.removeEventListener("keydown",q)},[]);const _=b.useCallback(q=>{p(q),f(!1)},[]),B=b.useCallback(()=>{p("")},[]),G=(q,Q=18)=>o.jsx("svg",{width:Q,height:Q,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:o.jsx("path",{d:q.icon})});return n?o.jsxs("div",{className:"flex h-dvh w-screen flex-col overflow-hidden bg-bg coffee-pattern",children:[!v&&o.jsxs("div",{className:"px-4 py-2 text-center text-xs font-semibold flex items-center justify-center gap-2 select-none shrink-0 z-50 animate-fadeIn",style:{background:"color-mix(in srgb, var(--yellow) 10%, transparent)",borderBottom:"1px solid color-mix(in srgb, var(--yellow) 20%, transparent)",color:"var(--yellow)"},children:[o.jsxs("svg",{className:"animate-pulse shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),o.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),o.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),"Offline Mode — Curie is running on cached local client"]}),o.jsx(TT,{}),o.jsx(DT,{}),o.jsxs("main",{className:"flex flex-1 flex-col overflow-hidden bg-bg",children:[o.jsxs("div",{className:"topbar-wood flex h-12 items-center gap-3 px-4 shrink-0",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsxs("button",{className:"relative flex items-center justify-center w-8 h-8 rounded-lg transition-all duration-150",style:{color:$?"var(--fg)":"var(--muted)",background:$?"var(--s3)":"transparent",border:$?"1px solid var(--b1)":"1px solid transparent"},onClick:()=>V(!0),title:"Sessions",children:[o.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:o.jsx("path",{d:"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"})}),k.length>0&&o.jsx("span",{className:"absolute -top-0.5 -right-0.5 text-[9px] font-bold rounded-full w-4 h-4 flex items-center justify-center",style:{background:"var(--gold)",color:"#1a1410"},children:k.length>99?"99+":k.length})]}),o.jsx("div",{className:"w-px h-5 bg-b1 mx-0.5"}),$T.map(q=>o.jsx("button",{className:"flex items-center justify-center w-8 h-8 rounded-lg transition-all duration-150 cursor-pointer",style:{color:r===q.view?"var(--gold)":"var(--muted)",background:r===q.view?"var(--s3)":"transparent",border:r===q.view?"1px solid var(--b1)":"1px solid transparent"},onClick:()=>c(q.view),title:q.label,children:G(q,18)},q.view))]}),o.jsx("div",{className:"flex-1"}),window.innerWidth>=640&&o.jsx("div",{className:"flex rounded-lg overflow-hidden",style:{border:"1px solid var(--b2)",background:"var(--bg)"},children:LT.map(q=>o.jsx("button",{className:"px-2.5 py-1 text-xs cursor-pointer transition-all duration-150 font-mono select-none",style:{color:u===q?"var(--gold)":"var(--muted)",background:u===q?"var(--s3)":"transparent",borderRight:"1px solid var(--b1)"},onClick:()=>s("mode",q),children:q},q))}),(y||w&&!E)&&o.jsxs("button",{onClick:D,className:"flex items-center justify-center rounded-lg transition-all duration-150 px-2.5 py-1 gap-1.5 text-xs font-semibold cursor-pointer shrink-0",style:{background:"var(--bg)",border:"1px solid color-mix(in srgb, var(--green) 30%, transparent)",color:"var(--green)"},children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),o.jsx("polyline",{points:"7 10 12 15 17 10"}),o.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),!w&&o.jsx(o.Fragment,{children:"Install"})]}),o.jsxs("button",{className:"flex items-center justify-center rounded-lg transition-all duration-150 px-2.5 py-1 gap-1.5 text-xs font-semibold cursor-pointer shrink-0",style:{background:"transparent",border:"1px solid var(--b2)",color:"var(--muted)"},onClick:()=>f(!0),title:"Open Commands",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[o.jsx("circle",{cx:"11",cy:"11",r:"8"}),o.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),!w&&o.jsx(o.Fragment,{children:"Ctrl+k"})]})]}),o.jsxs("div",{className:"relative flex-1 min-h-0",children:[H&&e?o.jsx(AT,{rpc:e,onComplete:()=>T(!1),className:"absolute inset-0"}):r==="assistant"&&o.jsx(Qj,{cmdResult:h,onClearCmdResult:B,rpc:e,className:"absolute inset-0",activeSessionId:x,onCreateSession:U,events:z,addLiveEvent:O,onSwitchView:q=>c(q)}),r==="channels"&&o.jsx(Zj,{rpc:e,className:"absolute inset-0"}),r==="stats"&&o.jsx(Ij,{rpc:e,className:"absolute inset-0"}),r==="projects"&&o.jsx(Kj,{rpc:e,className:"absolute inset-0"}),r==="agents"&&o.jsx(Fj,{rpc:e,className:"absolute inset-0"}),r==="kanban"&&o.jsx(e3,{rpc:e,className:"absolute inset-0"}),r==="wiki"&&o.jsx(MT,{rpc:e,className:"absolute inset-0"}),r==="settings"&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-muted text-xs",children:"Settings view — coming soon"})]})]}),o.jsx(_T,{open:d,onClose:()=>f(!1),onPick:_}),$&&o.jsx("div",{className:"fixed inset-0 z-[998] flex items-end animate-fadeIn",style:{background:"rgba(10, 8, 5, 0.6)",backdropFilter:"blur(4px)"},onClick:()=>V(!1),children:o.jsxs("div",{className:"w-full max-h-[70vh] rounded-t-2xl overflow-hidden animate-slideUp select-none flex flex-col wood-grain",style:{background:"var(--s1)",borderTop:"1px solid var(--b1)"},onClick:q=>q.stopPropagation(),children:[o.jsx("div",{className:"flex justify-center pt-3 pb-1 shrink-0",children:o.jsx("div",{className:"w-8 h-1 rounded-full",style:{background:"var(--gold)",opacity:.3}})}),o.jsxs("div",{className:"flex items-center justify-between px-4 pb-3 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("span",{className:"text-[13px] font-display font-semibold",style:{color:"var(--cream)"},children:"Sessions"}),o.jsx("button",{onClick:()=>V(!1),className:"text-muted hover:text-fg transition-colors duration-100 p-1",children:o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsx("div",{className:"px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:o.jsxs("button",{onClick:()=>{X(),V(!1)},className:"w-full flex items-center gap-2.5 py-2 px-3 rounded-xl transition-all duration-150 active:scale-[0.98] cursor-pointer",style:{background:"color-mix(in srgb, var(--gold) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--gold) 20%, transparent)",color:"var(--gold)"},children:[o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[o.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),o.jsx("span",{className:"text-[12.5px] font-semibold",children:"New Chat"})]})}),o.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4 scrollbar-thin",children:[k.sort((q,Q)=>Q.updatedAt-q.updatedAt).map(q=>o.jsx("button",{className:"w-full text-left py-3 px-3 rounded-xl mb-1 transition-all duration-150 active:scale-[0.98] min-h-[52px] cursor-pointer",style:{background:q.id===x?"linear-gradient(135deg, var(--s3) 0%, var(--s2) 100%)":"transparent",border:q.id===x?"1px solid var(--b2)":"1px solid transparent"},onClick:()=>{L(q.id),V(!1)},children:o.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[o.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:q.id===x?"var(--gold)":"transparent",boxShadow:q.id===x?"0 0 4px var(--gold)":"none"}}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[12.5px] font-medium text-fg truncate",children:q.name||q.provider}),o.jsxs("div",{className:"text-[11px] text-muted",children:[q.provider," · ",(()=>{const Q=Date.now()-q.updatedAt;return Q<6e4?"just now":Q<36e5?`${Math.floor(Q/6e4)}m ago`:Q<864e5?`${Math.floor(Q/36e5)}h ago`:`${Math.floor(Q/864e5)}d ago`})()]})]}),q.type&&q.type!=="webui"&&o.jsx("span",{className:"text-[9px] font-mono text-muted bg-s2 px-1.5 py-0.5 rounded shrink-0",children:q.type})]})},q.id)),k.length===0&&o.jsx("div",{className:"text-center py-8 text-xs text-muted",children:"No sessions yet"})]}),x&&o.jsx("div",{className:"border-t border-b1 px-4 py-3 shrink-0",children:(()=>{var ge;const q=z.filter(I=>I.type==="usage"),Q=q.reduce((I,se)=>I+(se.inputTokens||0)+(se.outputTokens||0),0),K=q[q.length-1],W=K&&K.inputTokens||0;function P(I){return I<1e3?String(I):`${(I/1e3).toFixed(1)}k`}const J=a("current_provider")||"anthropic",F=(ge=i.find(I=>I.name===J))==null?void 0:ge.model_cost,le=a("model")||"sonnet";function ae(I,se){if(F){const[Ht,ll]=F.split(";"),_n=parseFloat(Ht||"0"),Jt=parseFloat(ll||"0");if(!isNaN(_n)&&!isNaN(Jt))return(I*_n+se*Jt)/1e6}const Re={opus:{in:15,out:75},sonnet:{in:3,out:15},haiku:{in:.8,out:4},"gpt-4o":{in:2.5,out:10},"gpt-4":{in:5,out:15},qwen:{in:.112,out:.224}},st=Object.keys(Re).find(Ht=>le.toLowerCase().includes(Ht))||"sonnet",Nt=Re[st];return(I*Nt.in+se*Nt.out)/1e6}const te=q.reduce((I,se)=>I+ae(se.inputTokens||0,se.outputTokens||0),0);return o.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-[9px] text-muted2 uppercase tracking-wider font-mono",children:"Tokens"}),o.jsx("div",{className:"text-[12px] text-fg font-mono font-semibold",children:P(Q)})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[9px] text-muted2 uppercase tracking-wider font-mono",children:"Context"}),o.jsx("div",{className:"text-[12px] text-fg font-mono font-semibold",children:P(W)})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[9px] text-muted2 uppercase tracking-wider font-mono",children:"Cost"}),o.jsxs("div",{className:"text-[12px] text-green font-mono font-semibold",children:["$",te.toFixed(4)]})]})]})})()})]})}),A&&o.jsx("div",{className:"fixed inset-0 z-[999] flex items-center justify-center p-4 animate-fadeIn",style:{background:"rgba(10, 8, 5, 0.7)",backdropFilter:"blur(8px)"},children:o.jsxs("div",{className:"w-full max-w-[340px] p-5 rounded-2xl shadow-2xl animate-scaleIn select-none",style:{background:"linear-gradient(135deg, var(--s2), var(--s1))",border:"1px solid var(--b2)",boxShadow:"0 20px 60px rgba(0,0,0,0.5)"},children:[o.jsxs("div",{className:"flex items-center justify-between pb-3 mb-4",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("span",{className:"font-bold text-[13.5px] font-display",style:{color:"var(--cream)"},children:"Install Curie Agent"}),o.jsx("button",{onClick:()=>C(!1),className:"text-muted hover:text-fg transition-colors duration-100 cursor-pointer",children:o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsx("div",{className:"space-y-3.5 text-xs text-text leading-relaxed",children:N?o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-[12px] text-muted mb-1 px-0.5",children:"Follow these simple steps to add Curie to your home screen:"}),o.jsxs("div",{className:"flex gap-3 items-start p-3 rounded-xl",style:{background:"color-mix(in srgb, var(--s1) 50%, transparent)",border:"1px solid var(--b1)"},children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg shrink-0",style:{background:"color-mix(in srgb, var(--gold) 10%, transparent)",color:"var(--gold)"},children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13"})})}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"1. Tap the Share Button"}),o.jsx("span",{className:"text-[11px] text-muted",children:"Tap the Share icon in Safari's bottom toolbar."})]})]}),o.jsxs("div",{className:"flex gap-3 items-start p-3 rounded-xl",style:{background:"color-mix(in srgb, var(--s1) 50%, transparent)",border:"1px solid var(--b1)"},children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg shrink-0 font-bold font-mono text-[16px] select-none",style:{background:"color-mix(in srgb, var(--gold) 10%, transparent)",color:"var(--gold)"},children:"+"}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"2. Add to Home Screen"}),o.jsxs("span",{className:"text-[11px] text-muted",children:["Scroll down and select ",o.jsx("strong",{children:"Add to Home Screen"}),"."]})]})]})]}):o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-[12px] text-muted mb-1 px-0.5",children:"Follow these simple steps to add Curie to your home screen:"}),o.jsxs("div",{className:"flex gap-3 items-start bg-s1/50 border border-b1 p-3 rounded-xl",children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-blue-500/10 text-blue-400 shrink-0",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("circle",{cx:"12",cy:"12",r:"1"}),o.jsx("circle",{cx:"12",cy:"5",r:"1"}),o.jsx("circle",{cx:"12",cy:"19",r:"1"})]})}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"1. Open Browser Menu"}),o.jsx("span",{className:"text-[11px] text-muted",children:"Tap the menu icon (three dots) in the top-right corner."})]})]}),o.jsxs("div",{className:"flex gap-3 items-start bg-s1/50 border border-b1 p-3 rounded-xl",children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-blue-500/10 text-blue-400 shrink-0",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),o.jsx("polyline",{points:"7 10 12 15 17 10"}),o.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"2. Select Add / Install"}),o.jsxs("span",{className:"text-[11px] text-muted",children:["Tap ",o.jsx("strong",{children:"Add to Home screen"})," or ",o.jsx("strong",{children:"Install app"}),"."]})]})]})]})}),o.jsx("button",{onClick:()=>C(!1),className:"btn-gold w-full mt-5 py-2.5 px-4 rounded-xl font-semibold text-xs active:scale-[0.98] transition-all duration-150 cursor-pointer flex items-center justify-center",children:"Got it"})]})})]}):o.jsx(HT,{onAuthorize:l})}function UT(){return o.jsx(DN,{children:o.jsx(BT,{})})}const qT=_N.createRoot(document.getElementById("root"));qT.render(o.jsx(Me.StrictMode,{children:o.jsx(UT,{})}));"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js").then(e=>{console.log("ServiceWorker registration successful with scope: ",e.scope),e.addEventListener("updatefound",()=>{const t=e.installing;t&&(window._pendingUpdateWorker=t,t.addEventListener("statechange",()=>{t.state==="installed"&&(window._hasPendingUpdate=!0,window.dispatchEvent(new CustomEvent("pwa-update-available")))}))}),navigator.serviceWorker.addEventListener("controllerchange",()=>{window.dispatchEvent(new CustomEvent("pwa-controller-updated"))})}).catch(e=>console.error("ServiceWorker registration failed: ",e))});
164
+ `)),d=u.reduce((f,h)=>f.concat(...h),[]);return[u,d]}return[[],[]]},[e]);return b.useEffect(()=>{const c=(t==null?void 0:t.target)??sx,u=(t==null?void 0:t.actInsideInputWithModifier)??!0;if(e!==null){const d=p=>{var w,g;if(a.current=p.ctrlKey||p.metaKey||p.shiftKey||p.altKey,(!a.current||a.current&&!u)&&nb(p))return!1;const S=rx(p.code,r);if(s.current.add(p[S]),ix(i,s.current,!1)){const y=((g=(w=p.composedPath)==null?void 0:w.call(p))==null?void 0:g[0])||p.target,m=(y==null?void 0:y.nodeName)==="BUTTON"||(y==null?void 0:y.nodeName)==="A";t.preventDefault!==!1&&(a.current||!m)&&p.preventDefault(),l(!0)}},f=p=>{const x=rx(p.code,r);ix(i,s.current,!0)?(l(!1),s.current.clear()):s.current.delete(p[x]),p.key==="Meta"&&s.current.clear(),a.current=!1},h=()=>{s.current.clear(),l(!1)};return c==null||c.addEventListener("keydown",d),c==null||c.addEventListener("keyup",f),window.addEventListener("blur",h),window.addEventListener("contextmenu",h),()=>{c==null||c.removeEventListener("keydown",d),c==null||c.removeEventListener("keyup",f),window.removeEventListener("blur",h),window.removeEventListener("contextmenu",h)}}},[e,l]),n}function ix(e,t,n){return e.filter(l=>n||l.length===t.size).some(l=>l.every(a=>t.has(a)))}function rx(e,t){return t.includes(e)?"code":"key"}const j_=()=>{const e=De();return b.useMemo(()=>({zoomIn:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1.2,t):Promise.resolve(!1)},zoomOut:t=>{const{panZoom:n}=e.getState();return n?n.scaleBy(1/1.2,t):Promise.resolve(!1)},zoomTo:(t,n)=>{const{panZoom:l}=e.getState();return l?l.scaleTo(t,n):Promise.resolve(!1)},getZoom:()=>e.getState().transform[2],setViewport:async(t,n)=>{const{transform:[l,a,s],panZoom:i}=e.getState();return i?(await i.setViewport({x:t.x??l,y:t.y??a,zoom:t.zoom??s},n),Promise.resolve(!0)):Promise.resolve(!1)},getViewport:()=>{const[t,n,l]=e.getState().transform;return{x:t,y:n,zoom:l}},setCenter:async(t,n,l)=>e.getState().setCenter(t,n,l),fitBounds:async(t,n)=>{const{width:l,height:a,minZoom:s,maxZoom:i,panZoom:r}=e.getState(),c=tp(t,l,a,s,i,(n==null?void 0:n.padding)??.1);return r?(await r.setViewport(c,{duration:n==null?void 0:n.duration,ease:n==null?void 0:n.ease,interpolate:n==null?void 0:n.interpolate}),Promise.resolve(!0)):Promise.resolve(!1)},screenToFlowPosition:(t,n={})=>{const{transform:l,snapGrid:a,snapToGrid:s,domNode:i}=e.getState();if(!i)return t;const{x:r,y:c}=i.getBoundingClientRect(),u={x:t.x-r,y:t.y-c},d=n.snapGrid??a,f=n.snapToGrid??s;return cr(u,l,f,d)},flowToScreenPosition:t=>{const{transform:n,domNode:l}=e.getState();if(!l)return t;const{x:a,y:s}=l.getBoundingClientRect(),i=dc(t,n);return{x:i.x+a,y:i.y+s}}}),[])};function Mb(e,t){const n=[],l=new Map,a=[];for(const s of e)if(s.type==="add"){a.push(s);continue}else if(s.type==="remove"||s.type==="replace")l.set(s.id,[s]);else{const i=l.get(s.id);i?i.push(s):l.set(s.id,[s])}for(const s of t){const i=l.get(s.id);if(!i){n.push(s);continue}if(i[0].type==="remove")continue;if(i[0].type==="replace"){n.push({...i[0].item});continue}const r={...s};for(const c of i)k_(c,r);n.push(r)}return a.length&&a.forEach(s=>{s.index!==void 0?n.splice(s.index,0,{...s.item}):n.push({...s.item})}),n}function k_(e,t){switch(e.type){case"select":{t.selected=e.selected;break}case"position":{typeof e.position<"u"&&(t.position=e.position),typeof e.dragging<"u"&&(t.dragging=e.dragging);break}case"dimensions":{typeof e.dimensions<"u"&&(t.measured={...e.dimensions},e.setAttributes&&((e.setAttributes===!0||e.setAttributes==="width")&&(t.width=e.dimensions.width),(e.setAttributes===!0||e.setAttributes==="height")&&(t.height=e.dimensions.height))),typeof e.resizing=="boolean"&&(t.resizing=e.resizing);break}}}function _b(e,t){return Mb(e,t)}function Ab(e,t){return Mb(e,t)}function Il(e,t){return{id:e,type:"select",selected:t}}function Ya(e,t=new Set,n=!1){const l=[];for(const[a,s]of e){const i=t.has(a);!(s.selected===void 0&&!i)&&s.selected!==i&&(n&&(s.selected=i),l.push(Il(s.id,i)))}return l}function ox({items:e=[],lookup:t}){var a;const n=[],l=new Map(e.map(s=>[s.id,s]));for(const[s,i]of e.entries()){const r=t.get(i.id),c=((a=r==null?void 0:r.internals)==null?void 0:a.userNode)??r;c!==void 0&&c!==i&&n.push({id:i.id,item:i,type:"replace"}),c===void 0&&n.push({item:i,type:"add",index:s})}for(const[s]of t)l.get(s)===void 0&&n.push({id:s,type:"remove"});return n}function cx(e){return{id:e.id,type:"remove"}}const ux=e=>O4(e),E_=e=>I1(e);function Tb(e){return b.forwardRef(e)}function dx(e){const[t,n]=b.useState(BigInt(0)),[l]=b.useState(()=>C_(()=>n(a=>a+BigInt(1))));return Sf(()=>{const a=l.get();a.length&&(e(a),l.reset())},[t]),l}function C_(e){let t=[];return{get:()=>t,reset:()=>{t=[]},push:n=>{t.push(n),e()}}}const zb=b.createContext(null);function M_({children:e}){const t=De(),n=b.useCallback(r=>{const{nodes:c=[],setNodes:u,hasDefaultNodes:d,onNodesChange:f,nodeLookup:h,fitViewQueued:p,onNodesChangeMiddlewareMap:x}=t.getState();let S=c;for(const g of r)S=typeof g=="function"?g(S):g;let w=ox({items:S,lookup:h});for(const g of x.values())w=g(w);d&&u(S),w.length>0?f==null||f(w):p&&window.requestAnimationFrame(()=>{const{fitViewQueued:g,nodes:y,setNodes:m}=t.getState();g&&m(y)})},[]),l=dx(n),a=b.useCallback(r=>{const{edges:c=[],setEdges:u,hasDefaultEdges:d,onEdgesChange:f,edgeLookup:h}=t.getState();let p=c;for(const x of r)p=typeof x=="function"?x(p):x;d?u(p):f&&f(ox({items:p,lookup:h}))},[]),s=dx(a),i=b.useMemo(()=>({nodeQueue:l,edgeQueue:s}),[]);return o.jsx(zb.Provider,{value:i,children:e})}function __(){const e=b.useContext(zb);if(!e)throw new Error("useBatchContext must be used within a BatchProvider");return e}const A_=e=>!!e.panZoom;function op(){const e=j_(),t=De(),n=__(),l=he(A_),a=b.useMemo(()=>{const s=f=>t.getState().nodeLookup.get(f),i=f=>{n.nodeQueue.push(f)},r=f=>{n.edgeQueue.push(f)},c=f=>{var g,y;const{nodeLookup:h,nodeOrigin:p}=t.getState(),x=ux(f)?f:h.get(f.id),S=x.parentId?eb(x.position,x.measured,x.parentId,h,p):x.position,w={...x,position:S,width:((g=x.measured)==null?void 0:g.width)??x.width,height:((y=x.measured)==null?void 0:y.height)??x.height};return ps(w)},u=(f,h,p={replace:!1})=>{i(x=>x.map(S=>{if(S.id===f){const w=typeof h=="function"?h(S):h;return p.replace&&ux(w)?w:{...S,...w}}return S}))},d=(f,h,p={replace:!1})=>{r(x=>x.map(S=>{if(S.id===f){const w=typeof h=="function"?h(S):h;return p.replace&&E_(w)?w:{...S,...w}}return S}))};return{getNodes:()=>t.getState().nodes.map(f=>({...f})),getNode:f=>{var h;return(h=s(f))==null?void 0:h.internals.userNode},getInternalNode:s,getEdges:()=>{const{edges:f=[]}=t.getState();return f.map(h=>({...h}))},getEdge:f=>t.getState().edgeLookup.get(f),setNodes:i,setEdges:r,addNodes:f=>{const h=Array.isArray(f)?f:[f];n.nodeQueue.push(p=>[...p,...h])},addEdges:f=>{const h=Array.isArray(f)?f:[f];n.edgeQueue.push(p=>[...p,...h])},toObject:()=>{const{nodes:f=[],edges:h=[],transform:p}=t.getState(),[x,S,w]=p;return{nodes:f.map(g=>({...g})),edges:h.map(g=>({...g})),viewport:{x,y:S,zoom:w}}},deleteElements:async({nodes:f=[],edges:h=[]})=>{const{nodes:p,edges:x,onNodesDelete:S,onEdgesDelete:w,triggerNodeChanges:g,triggerEdgeChanges:y,onDelete:m,onBeforeDelete:v}=t.getState(),{nodes:j,edges:E}=await U4({nodesToRemove:f,edgesToRemove:h,nodes:p,edges:x,onBeforeDelete:v}),M=E.length>0,A=j.length>0;if(M){const C=E.map(cx);w==null||w(E),y(C)}if(A){const C=j.map(cx);S==null||S(j),g(C)}return(A||M)&&(m==null||m({nodes:j,edges:E})),{deletedNodes:j,deletedEdges:E}},getIntersectingNodes:(f,h=!0,p)=>{const x=Um(f),S=x?f:c(f),w=p!==void 0;return S?(p||t.getState().nodes).filter(g=>{const y=t.getState().nodeLookup.get(g.id);if(y&&!x&&(g.id===f.id||!y.internals.positionAbsolute))return!1;const m=ps(w?g:y),v=$i(m,S);return h&&v>0||v>=m.width*m.height||v>=S.width*S.height}):[]},isNodeIntersecting:(f,h,p=!0)=>{const S=Um(f)?f:c(f);if(!S)return!1;const w=$i(S,h);return p&&w>0||w>=h.width*h.height||w>=S.width*S.height},updateNode:u,updateNodeData:(f,h,p={replace:!1})=>{u(f,x=>{const S=typeof h=="function"?h(x):h;return p.replace?{...x,data:S}:{...x,data:{...x.data,...S}}},p)},updateEdge:d,updateEdgeData:(f,h,p={replace:!1})=>{d(f,x=>{const S=typeof h=="function"?h(x):h;return p.replace?{...x,data:S}:{...x,data:{...x.data,...S}}},p)},getNodesBounds:f=>{const{nodeLookup:h,nodeOrigin:p}=t.getState();return H4(f,{nodeLookup:h,nodeOrigin:p})},getHandleConnections:({type:f,id:h,nodeId:p})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${p}-${f}${h?`-${h}`:""}`))==null?void 0:x.values())??[])},getNodeConnections:({type:f,handleId:h,nodeId:p})=>{var x;return Array.from(((x=t.getState().connectionLookup.get(`${p}${f?h?`-${f}-${h}`:`-${f}`:""}`))==null?void 0:x.values())??[])},fitView:async f=>{const h=t.getState().fitViewResolver??X4();return t.setState({fitViewQueued:!0,fitViewOptions:f,fitViewResolver:h}),n.nodeQueue.push(p=>[...p]),h.promise}}},[]);return b.useMemo(()=>({...a,...e,viewportInitialized:l}),[l])}const fx=e=>e.selected,T_=typeof window<"u"?window:void 0;function z_({deleteKeyCode:e,multiSelectionKeyCode:t}){const n=De(),{deleteElements:l}=op(),a=Ui(e,{actInsideInputWithModifier:!1}),s=Ui(t,{target:T_});b.useEffect(()=>{if(a){const{edges:i,nodes:r}=n.getState();l({nodes:r.filter(fx),edges:i.filter(fx)}),n.setState({nodesSelectionActive:!1})}},[a]),b.useEffect(()=>{n.setState({multiSelectionActive:s})},[s])}function D_(e){const t=De();b.useEffect(()=>{const n=()=>{var a,s,i,r;if(!e.current||!(((s=(a=e.current).checkVisibility)==null?void 0:s.call(a))??!0))return!1;const l=np(e.current);(l.height===0||l.width===0)&&((r=(i=t.getState()).onError)==null||r.call(i,"004",jn.error004())),t.setState({width:l.width||500,height:l.height||500})};if(e.current){n(),window.addEventListener("resize",n);const l=new ResizeObserver(()=>n());return l.observe(e.current),()=>{window.removeEventListener("resize",n),l&&e.current&&l.unobserve(e.current)}}},[])}const Wc={position:"absolute",width:"100%",height:"100%",top:0,left:0},R_=e=>({userSelectionActive:e.userSelectionActive,lib:e.lib,connectionInProgress:e.connection.inProgress});function O_({onPaneContextMenu:e,zoomOnScroll:t=!0,zoomOnPinch:n=!0,panOnScroll:l=!1,panOnScrollSpeed:a=.5,panOnScrollMode:s=aa.Free,zoomOnDoubleClick:i=!0,panOnDrag:r=!0,defaultViewport:c,translateExtent:u,minZoom:d,maxZoom:f,zoomActivationKeyCode:h,preventScrolling:p=!0,children:x,noWheelClassName:S,noPanClassName:w,onViewportChange:g,isControlledViewport:y,paneClickDistance:m,selectionOnDrag:v}){const j=De(),E=b.useRef(null),{userSelectionActive:M,lib:A,connectionInProgress:C}=he(R_,ze),H=Ui(h),T=b.useRef();D_(E);const $=b.useCallback(V=>{g==null||g({x:V[0],y:V[1],zoom:V[2]}),y||j.setState({transform:V})},[g,y]);return b.useEffect(()=>{if(E.current){T.current=CM({domNode:E.current,minZoom:d,maxZoom:f,translateExtent:u,viewport:c,onDraggingChange:k=>j.setState(R=>R.paneDragging===k?R:{paneDragging:k}),onPanZoomStart:(k,R)=>{const{onViewportChangeStart:z,onMoveStart:O}=j.getState();O==null||O(k,R),z==null||z(R)},onPanZoom:(k,R)=>{const{onViewportChange:z,onMove:O}=j.getState();O==null||O(k,R),z==null||z(R)},onPanZoomEnd:(k,R)=>{const{onViewportChangeEnd:z,onMoveEnd:O}=j.getState();O==null||O(k,R),z==null||z(R)}});const{x:V,y:N,zoom:D}=T.current.getViewport();return j.setState({panZoom:T.current,transform:[V,N,D],domNode:E.current.closest(".react-flow")}),()=>{var k;(k=T.current)==null||k.destroy()}}},[]),b.useEffect(()=>{var V;(V=T.current)==null||V.update({onPaneContextMenu:e,zoomOnScroll:t,zoomOnPinch:n,panOnScroll:l,panOnScrollSpeed:a,panOnScrollMode:s,zoomOnDoubleClick:i,panOnDrag:r,zoomActivationKeyPressed:H,preventScrolling:p,noPanClassName:w,userSelectionActive:M,noWheelClassName:S,lib:A,onTransformChange:$,connectionInProgress:C,selectionOnDrag:v,paneClickDistance:m})},[e,t,n,l,a,s,i,r,H,p,w,M,S,A,$,C,v,m]),o.jsx("div",{className:"react-flow__renderer",ref:E,style:Wc,children:x})}const H_=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function L_(){const{userSelectionActive:e,userSelectionRect:t}=he(H_,ze);return e&&t?o.jsx("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}const nd=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},$_=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,connectionInProgress:e.connection.inProgress,dragging:e.paneDragging});function B_({isSelecting:e,selectionKeyPressed:t,selectionMode:n=Li.Full,panOnDrag:l,paneClickDistance:a,selectionOnDrag:s,onSelectionStart:i,onSelectionEnd:r,onPaneClick:c,onPaneContextMenu:u,onPaneScroll:d,onPaneMouseEnter:f,onPaneMouseMove:h,onPaneMouseLeave:p,children:x}){const S=De(),{userSelectionActive:w,elementsSelectable:g,dragging:y,connectionInProgress:m}=he($_,ze),v=g&&(e||w),j=b.useRef(null),E=b.useRef(),M=b.useRef(new Set),A=b.useRef(new Set),C=b.useRef(!1),H=z=>{if(C.current||m){C.current=!1;return}c==null||c(z),S.getState().resetSelectedElements(),S.setState({nodesSelectionActive:!1})},T=z=>{if(Array.isArray(l)&&(l!=null&&l.includes(2))){z.preventDefault();return}u==null||u(z)},$=d?z=>d(z):void 0,V=z=>{C.current&&(z.stopPropagation(),C.current=!1)},N=z=>{var B,G;const{domNode:O}=S.getState();if(E.current=O==null?void 0:O.getBoundingClientRect(),!E.current)return;const Y=z.target===j.current;if(!Y&&!!z.target.closest(".nokey")||!e||!(s&&Y||t)||z.button!==0||!z.isPrimary)return;(G=(B=z.target)==null?void 0:B.setPointerCapture)==null||G.call(B,z.pointerId),C.current=!1;const{x:U,y:_}=rn(z.nativeEvent,E.current);S.setState({userSelectionRect:{width:0,height:0,startX:U,startY:_,x:U,y:_}}),Y||(z.stopPropagation(),z.preventDefault())},D=z=>{const{userSelectionRect:O,transform:Y,nodeLookup:X,edgeLookup:L,connectionLookup:U,triggerNodeChanges:_,triggerEdgeChanges:B,defaultEdgeOptions:G,resetSelectedElements:q}=S.getState();if(!E.current||!O)return;const{x:Q,y:K}=rn(z.nativeEvent,E.current),{startX:W,startY:P}=O;if(!C.current){const te=t?0:a;if(Math.hypot(Q-W,K-P)<=te)return;q(),i==null||i(z)}C.current=!0;const J={startX:W,startY:P,x:Q<W?Q:W,y:K<P?K:P,width:Math.abs(Q-W),height:Math.abs(K-P)},F=M.current,le=A.current;M.current=new Set(ep(X,J,Y,n===Li.Partial,!0).map(te=>te.id)),A.current=new Set;const ae=(G==null?void 0:G.selectable)??!0;for(const te of M.current){const ge=U.get(te);if(ge)for(const{edgeId:I}of ge.values()){const se=L.get(I);se&&(se.selectable??ae)&&A.current.add(I)}}if(!qm(F,M.current)){const te=Ya(X,M.current,!0);_(te)}if(!qm(le,A.current)){const te=Ya(L,A.current);B(te)}S.setState({userSelectionRect:J,userSelectionActive:!0,nodesSelectionActive:!1})},k=z=>{var O,Y;z.button===0&&((Y=(O=z.target)==null?void 0:O.releasePointerCapture)==null||Y.call(O,z.pointerId),!w&&z.target===j.current&&S.getState().userSelectionRect&&(H==null||H(z)),S.setState({userSelectionActive:!1,userSelectionRect:null}),C.current&&(r==null||r(z),S.setState({nodesSelectionActive:M.current.size>0})))},R=l===!0||Array.isArray(l)&&l.includes(0);return o.jsxs("div",{className:Ve(["react-flow__pane",{draggable:R,dragging:y,selection:e}]),onClick:v?void 0:nd(H,j),onContextMenu:nd(T,j),onWheel:nd($,j),onPointerEnter:v?void 0:f,onPointerMove:v?D:h,onPointerUp:v?k:void 0,onPointerDownCapture:v?N:void 0,onClickCapture:v?V:void 0,onPointerLeave:p,ref:j,style:Wc,children:[x,o.jsx(L_,{})]})}function Nf({id:e,store:t,unselect:n=!1,nodeRef:l}){const{addSelectedNodes:a,unselectNodesAndEdges:s,multiSelectionActive:i,nodeLookup:r,onError:c}=t.getState(),u=r.get(e);if(!u){c==null||c("012",jn.error012(e));return}t.setState({nodesSelectionActive:!1}),u.selected?(n||u.selected&&i)&&(s({nodes:[u],edges:[]}),requestAnimationFrame(()=>{var d;return(d=l==null?void 0:l.current)==null?void 0:d.blur()})):a([e])}function Db({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:l,nodeId:a,isSelectable:s,nodeClickDistance:i}){const r=De(),[c,u]=b.useState(!1),d=b.useRef();return b.useEffect(()=>{d.current=hM({getStoreItems:()=>r.getState(),onNodeMouseDown:f=>{Nf({id:f,store:r,nodeRef:e})},onDragStart:()=>{u(!0)},onDragStop:()=>{u(!1)}})},[]),b.useEffect(()=>{if(!(t||!e.current||!d.current))return d.current.update({noDragClassName:n,handleSelector:l,domNode:e.current,isSelectable:s,nodeId:a,nodeClickDistance:i}),()=>{var f;(f=d.current)==null||f.destroy()}},[n,l,t,s,e,a,i]),c}const U_=e=>t=>t.selected&&(t.draggable||e&&typeof t.draggable>"u");function Rb(){const e=De();return b.useCallback(n=>{const{nodeExtent:l,snapToGrid:a,snapGrid:s,nodesDraggable:i,onError:r,updateNodePositions:c,nodeLookup:u,nodeOrigin:d}=e.getState(),f=new Map,h=U_(i),p=a?s[0]:5,x=a?s[1]:5,S=n.direction.x*p*n.factor,w=n.direction.y*x*n.factor;for(const[,g]of u){if(!h(g))continue;let y={x:g.internals.positionAbsolute.x+S,y:g.internals.positionAbsolute.y+w};a&&(y=or(y,s));const{position:m,positionAbsolute:v}=K1({nodeId:g.id,nextPosition:y,nodeLookup:u,nodeExtent:l,nodeOrigin:d,onError:r});g.position=m,g.internals.positionAbsolute=v,f.set(g.id,g)}c(f)},[])}const cp=b.createContext(null),q_=cp.Provider;cp.Consumer;const Ob=()=>b.useContext(cp),Y_=e=>({connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName,rfId:e.rfId}),V_=(e,t,n)=>l=>{const{connectionClickStartHandle:a,connectionMode:s,connection:i}=l,{fromHandle:r,toHandle:c,isValid:u}=i,d=(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.id)===t&&(c==null?void 0:c.type)===n;return{connectingFrom:(r==null?void 0:r.nodeId)===e&&(r==null?void 0:r.id)===t&&(r==null?void 0:r.type)===n,connectingTo:d,clickConnecting:(a==null?void 0:a.nodeId)===e&&(a==null?void 0:a.id)===t&&(a==null?void 0:a.type)===n,isPossibleEndHandle:s===fs.Strict?(r==null?void 0:r.type)!==n:e!==(r==null?void 0:r.nodeId)||t!==(r==null?void 0:r.id),connectionInProcess:!!r,clickConnectionInProcess:!!a,valid:d&&u}};function X_({type:e="source",position:t=ee.Top,isValidConnection:n,isConnectable:l=!0,isConnectableStart:a=!0,isConnectableEnd:s=!0,id:i,onConnect:r,children:c,className:u,onMouseDown:d,onTouchStart:f,...h},p){var D,k;const x=i||null,S=e==="target",w=De(),g=Ob(),{connectOnClick:y,noPanClassName:m,rfId:v}=he(Y_,ze),{connectingFrom:j,connectingTo:E,clickConnecting:M,isPossibleEndHandle:A,connectionInProcess:C,clickConnectionInProcess:H,valid:T}=he(V_(g,x,e),ze);g||(k=(D=w.getState()).onError)==null||k.call(D,"010",jn.error010());const $=R=>{const{defaultEdgeOptions:z,onConnect:O,hasDefaultEdges:Y}=w.getState(),X={...z,...R};if(Y){const{edges:L,setEdges:U}=w.getState();U(J4(X,L))}O==null||O(X),r==null||r(X)},V=R=>{if(!g)return;const z=lb(R.nativeEvent);if(a&&(z&&R.button===0||!z)){const O=w.getState();wf.onPointerDown(R.nativeEvent,{handleDomNode:R.currentTarget,autoPanOnConnect:O.autoPanOnConnect,connectionMode:O.connectionMode,connectionRadius:O.connectionRadius,domNode:O.domNode,nodeLookup:O.nodeLookup,lib:O.lib,isTarget:S,handleId:x,nodeId:g,flowId:O.rfId,panBy:O.panBy,cancelConnection:O.cancelConnection,onConnectStart:O.onConnectStart,onConnectEnd:(...Y)=>{var X,L;return(L=(X=w.getState()).onConnectEnd)==null?void 0:L.call(X,...Y)},updateConnection:O.updateConnection,onConnect:$,isValidConnection:n||((...Y)=>{var X,L;return((L=(X=w.getState()).isValidConnection)==null?void 0:L.call(X,...Y))??!0}),getTransform:()=>w.getState().transform,getFromHandle:()=>w.getState().connection.fromHandle,autoPanSpeed:O.autoPanSpeed,dragThreshold:O.connectionDragThreshold})}z?d==null||d(R):f==null||f(R)},N=R=>{const{onClickConnectStart:z,onClickConnectEnd:O,connectionClickStartHandle:Y,connectionMode:X,isValidConnection:L,lib:U,rfId:_,nodeLookup:B,connection:G}=w.getState();if(!g||!Y&&!a)return;if(!Y){z==null||z(R.nativeEvent,{nodeId:g,handleId:x,handleType:e}),w.setState({connectionClickStartHandle:{nodeId:g,type:e,id:x}});return}const q=tb(R.target),Q=n||L,{connection:K,isValid:W}=wf.isValid(R.nativeEvent,{handle:{nodeId:g,id:x,type:e},connectionMode:X,fromNodeId:Y.nodeId,fromHandleId:Y.id||null,fromType:Y.type,isValidConnection:Q,flowId:_,doc:q,lib:U,nodeLookup:B});W&&K&&$(K);const P=structuredClone(G);delete P.inProgress,P.toPosition=P.toHandle?P.toHandle.position:null,O==null||O(R,P),w.setState({connectionClickStartHandle:null})};return o.jsx("div",{"data-handleid":x,"data-nodeid":g,"data-handlepos":t,"data-id":`${v}-${g}-${x}-${e}`,className:Ve(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",m,u,{source:!S,target:S,connectable:l,connectablestart:a,connectableend:s,clickconnecting:M,connectingfrom:j,connectingto:E,valid:T,connectionindicator:l&&(!C||A)&&(C||H?s:a)}]),onMouseDown:V,onTouchStart:V,onClick:y?N:void 0,ref:p,...h,children:c})}const ys=b.memo(Tb(X_));function G_({data:e,isConnectable:t,sourcePosition:n=ee.Bottom}){return o.jsxs(o.Fragment,{children:[e==null?void 0:e.label,o.jsx(ys,{type:"source",position:n,isConnectable:t})]})}function Q_({data:e,isConnectable:t,targetPosition:n=ee.Top,sourcePosition:l=ee.Bottom}){return o.jsxs(o.Fragment,{children:[o.jsx(ys,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,o.jsx(ys,{type:"source",position:l,isConnectable:t})]})}function Z_(){return null}function I_({data:e,isConnectable:t,targetPosition:n=ee.Top}){return o.jsxs(o.Fragment,{children:[o.jsx(ys,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label]})}const fc={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}},hx={input:G_,default:Q_,output:I_,group:Z_};function K_(e){var t,n,l,a;return e.internals.handleBounds===void 0?{width:e.width??e.initialWidth??((t=e.style)==null?void 0:t.width),height:e.height??e.initialHeight??((n=e.style)==null?void 0:n.height)}:{width:e.width??((l=e.style)==null?void 0:l.width),height:e.height??((a=e.style)==null?void 0:a.height)}}const W_=e=>{const{width:t,height:n,x:l,y:a}=rr(e.nodeLookup,{filter:s=>!!s.selected});return{width:sn(t)?t:null,height:sn(n)?n:null,userSelectionActive:e.userSelectionActive,transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]}) translate(${l}px,${a}px)`}};function J_({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const l=De(),{width:a,height:s,transformString:i,userSelectionActive:r}=he(W_,ze),c=Rb(),u=b.useRef(null);b.useEffect(()=>{var p;n||(p=u.current)==null||p.focus({preventScroll:!0})},[n]);const d=!r&&a!==null&&s!==null;if(Db({nodeRef:u,disabled:!d}),!d)return null;const f=e?p=>{const x=l.getState().nodes.filter(S=>S.selected);e(p,x)}:void 0,h=p=>{Object.prototype.hasOwnProperty.call(fc,p.key)&&(p.preventDefault(),c({direction:fc[p.key],factor:p.shiftKey?4:1}))};return o.jsx("div",{className:Ve(["react-flow__nodesselection","react-flow__container",t]),style:{transform:i},children:o.jsx("div",{ref:u,className:"react-flow__nodesselection-rect",onContextMenu:f,tabIndex:n?void 0:-1,onKeyDown:n?void 0:h,style:{width:a,height:s}})})}const px=typeof window<"u"?window:void 0,F_=e=>({nodesSelectionActive:e.nodesSelectionActive,userSelectionActive:e.userSelectionActive});function Hb({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:l,onPaneMouseLeave:a,onPaneContextMenu:s,onPaneScroll:i,paneClickDistance:r,deleteKeyCode:c,selectionKeyCode:u,selectionOnDrag:d,selectionMode:f,onSelectionStart:h,onSelectionEnd:p,multiSelectionKeyCode:x,panActivationKeyCode:S,zoomActivationKeyCode:w,elementsSelectable:g,zoomOnScroll:y,zoomOnPinch:m,panOnScroll:v,panOnScrollSpeed:j,panOnScrollMode:E,zoomOnDoubleClick:M,panOnDrag:A,defaultViewport:C,translateExtent:H,minZoom:T,maxZoom:$,preventScrolling:V,onSelectionContextMenu:N,noWheelClassName:D,noPanClassName:k,disableKeyboardA11y:R,onViewportChange:z,isControlledViewport:O}){const{nodesSelectionActive:Y,userSelectionActive:X}=he(F_,ze),L=Ui(u,{target:px}),U=Ui(S,{target:px}),_=U||A,B=U||v,G=d&&_!==!0,q=L||X||G;return z_({deleteKeyCode:c,multiSelectionKeyCode:x}),o.jsx(O_,{onPaneContextMenu:s,elementsSelectable:g,zoomOnScroll:y,zoomOnPinch:m,panOnScroll:B,panOnScrollSpeed:j,panOnScrollMode:E,zoomOnDoubleClick:M,panOnDrag:!L&&_,defaultViewport:C,translateExtent:H,minZoom:T,maxZoom:$,zoomActivationKeyCode:w,preventScrolling:V,noWheelClassName:D,noPanClassName:k,onViewportChange:z,isControlledViewport:O,paneClickDistance:r,selectionOnDrag:G,children:o.jsxs(B_,{onSelectionStart:h,onSelectionEnd:p,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:l,onPaneMouseLeave:a,onPaneContextMenu:s,onPaneScroll:i,panOnDrag:_,isSelecting:!!q,selectionMode:f,selectionKeyPressed:L,paneClickDistance:r,selectionOnDrag:G,children:[e,Y&&o.jsx(J_,{onSelectionContextMenu:N,noPanClassName:k,disableKeyboardA11y:R})]})})}Hb.displayName="FlowRenderer";const P_=b.memo(Hb),eA=e=>t=>e?ep(t.nodeLookup,{x:0,y:0,width:t.width,height:t.height},t.transform,!0).map(n=>n.id):Array.from(t.nodeLookup.keys());function tA(e){return he(b.useCallback(eA(e),[e]),ze)}const nA=e=>e.updateNodeInternals;function lA(){const e=he(nA),[t]=b.useState(()=>typeof ResizeObserver>"u"?null:new ResizeObserver(n=>{const l=new Map;n.forEach(a=>{const s=a.target.getAttribute("data-id");l.set(s,{id:s,nodeElement:a.target,force:!0})}),e(l)}));return b.useEffect(()=>()=>{t==null||t.disconnect()},[t]),t}function aA({node:e,nodeType:t,hasDimensions:n,resizeObserver:l}){const a=De(),s=b.useRef(null),i=b.useRef(null),r=b.useRef(e.sourcePosition),c=b.useRef(e.targetPosition),u=b.useRef(t),d=n&&!!e.internals.handleBounds;return b.useEffect(()=>{s.current&&!e.hidden&&(!d||i.current!==s.current)&&(i.current&&(l==null||l.unobserve(i.current)),l==null||l.observe(s.current),i.current=s.current)},[d,e.hidden]),b.useEffect(()=>()=>{i.current&&(l==null||l.unobserve(i.current),i.current=null)},[]),b.useEffect(()=>{if(s.current){const f=u.current!==t,h=r.current!==e.sourcePosition,p=c.current!==e.targetPosition;(f||h||p)&&(u.current=t,r.current=e.sourcePosition,c.current=e.targetPosition,a.getState().updateNodeInternals(new Map([[e.id,{id:e.id,nodeElement:s.current,force:!0}]])))}},[e.id,t,e.sourcePosition,e.targetPosition]),s}function sA({id:e,onClick:t,onMouseEnter:n,onMouseMove:l,onMouseLeave:a,onContextMenu:s,onDoubleClick:i,nodesDraggable:r,elementsSelectable:c,nodesConnectable:u,nodesFocusable:d,resizeObserver:f,noDragClassName:h,noPanClassName:p,disableKeyboardA11y:x,rfId:S,nodeTypes:w,nodeClickDistance:g,onError:y}){const{node:m,internals:v,isParent:j}=he(Q=>{const K=Q.nodeLookup.get(e),W=Q.parentLookup.has(e);return{node:K,internals:K.internals,isParent:W}},ze);let E=m.type||"default",M=(w==null?void 0:w[E])||hx[E];M===void 0&&(y==null||y("003",jn.error003(E)),E="default",M=(w==null?void 0:w.default)||hx.default);const A=!!(m.draggable||r&&typeof m.draggable>"u"),C=!!(m.selectable||c&&typeof m.selectable>"u"),H=!!(m.connectable||u&&typeof m.connectable>"u"),T=!!(m.focusable||d&&typeof m.focusable>"u"),$=De(),V=P1(m),N=aA({node:m,nodeType:E,hasDimensions:V,resizeObserver:f}),D=Db({nodeRef:N,disabled:m.hidden||!A,noDragClassName:h,handleSelector:m.dragHandle,nodeId:e,isSelectable:C,nodeClickDistance:g}),k=Rb();if(m.hidden)return null;const R=nl(m),z=K_(m),O=C||A||t||n||l||a,Y=n?Q=>n(Q,{...v.userNode}):void 0,X=l?Q=>l(Q,{...v.userNode}):void 0,L=a?Q=>a(Q,{...v.userNode}):void 0,U=s?Q=>s(Q,{...v.userNode}):void 0,_=i?Q=>i(Q,{...v.userNode}):void 0,B=Q=>{const{selectNodesOnDrag:K,nodeDragThreshold:W}=$.getState();C&&(!K||!A||W>0)&&Nf({id:e,store:$,nodeRef:N}),t&&t(Q,{...v.userNode})},G=Q=>{if(!(nb(Q.nativeEvent)||x)){if(X1.includes(Q.key)&&C){const K=Q.key==="Escape";Nf({id:e,store:$,unselect:K,nodeRef:N})}else if(A&&m.selected&&Object.prototype.hasOwnProperty.call(fc,Q.key)){Q.preventDefault();const{ariaLabelConfig:K}=$.getState();$.setState({ariaLiveMessage:K["node.a11yDescription.ariaLiveMessage"]({direction:Q.key.replace("Arrow","").toLowerCase(),x:~~v.positionAbsolute.x,y:~~v.positionAbsolute.y})}),k({direction:fc[Q.key],factor:Q.shiftKey?4:1})}}},q=()=>{var le;if(x||!((le=N.current)!=null&&le.matches(":focus-visible")))return;const{transform:Q,width:K,height:W,autoPanOnNodeFocus:P,setCenter:J}=$.getState();if(!P)return;ep(new Map([[e,m]]),{x:0,y:0,width:K,height:W},Q,!0).length>0||J(m.position.x+R.width/2,m.position.y+R.height/2,{zoom:Q[2]})};return o.jsx("div",{className:Ve(["react-flow__node",`react-flow__node-${E}`,{[p]:A},m.className,{selected:m.selected,selectable:C,parent:j,draggable:A,dragging:D}]),ref:N,style:{zIndex:v.z,transform:`translate(${v.positionAbsolute.x}px,${v.positionAbsolute.y}px)`,pointerEvents:O?"all":"none",visibility:V?"visible":"hidden",...m.style,...z},"data-id":e,"data-testid":`rf__node-${e}`,onMouseEnter:Y,onMouseMove:X,onMouseLeave:L,onContextMenu:U,onClick:B,onDoubleClick:_,onKeyDown:T?G:void 0,tabIndex:T?0:void 0,onFocus:T?q:void 0,role:m.ariaRole??(T?"group":void 0),"aria-roledescription":"node","aria-describedby":x?void 0:`${kb}-${S}`,"aria-label":m.ariaLabel,...m.domAttributes,children:o.jsx(q_,{value:e,children:o.jsx(M,{id:e,data:m.data,type:E,positionAbsoluteX:v.positionAbsolute.x,positionAbsoluteY:v.positionAbsolute.y,selected:m.selected??!1,selectable:C,draggable:A,deletable:m.deletable??!0,isConnectable:H,sourcePosition:m.sourcePosition,targetPosition:m.targetPosition,dragging:D,dragHandle:m.dragHandle,zIndex:v.z,parentId:m.parentId,...R})})})}var iA=b.memo(sA);const rA=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,onError:e.onError});function Lb(e){const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:l,elementsSelectable:a,onError:s}=he(rA,ze),i=tA(e.onlyRenderVisibleElements),r=lA();return o.jsx("div",{className:"react-flow__nodes",style:Wc,children:i.map(c=>o.jsx(iA,{id:c,nodeTypes:e.nodeTypes,nodeExtent:e.nodeExtent,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,resizeObserver:r,nodesDraggable:t,nodesConnectable:n,nodesFocusable:l,elementsSelectable:a,nodeClickDistance:e.nodeClickDistance,onError:s},c))})}Lb.displayName="NodeRenderer";const oA=b.memo(Lb);function cA(e){return he(b.useCallback(n=>{if(!e)return n.edges.map(a=>a.id);const l=[];if(n.width&&n.height)for(const a of n.edges){const s=n.nodeLookup.get(a.source),i=n.nodeLookup.get(a.target);s&&i&&I4({sourceNode:s,targetNode:i,width:n.width,height:n.height,transform:n.transform})&&l.push(a.id)}return l},[e]),ze)}const uA=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e}};return o.jsx("polyline",{className:"arrow",style:n,strokeLinecap:"round",fill:"none",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4"})},dA=({color:e="none",strokeWidth:t=1})=>{const n={strokeWidth:t,...e&&{stroke:e,fill:e}};return o.jsx("polyline",{className:"arrowclosed",style:n,strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"})},gx={[cc.Arrow]:uA,[cc.ArrowClosed]:dA};function fA(e){const t=De();return b.useMemo(()=>{var a,s;return Object.prototype.hasOwnProperty.call(gx,e)?gx[e]:((s=(a=t.getState()).onError)==null||s.call(a,"009",jn.error009(e)),null)},[e])}const hA=({id:e,type:t,color:n,width:l=12.5,height:a=12.5,markerUnits:s="strokeWidth",strokeWidth:i,orient:r="auto-start-reverse"})=>{const c=fA(t);return c?o.jsx("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${l}`,markerHeight:`${a}`,viewBox:"-10 -10 20 20",markerUnits:s,orient:r,refX:"0",refY:"0",children:o.jsx(c,{color:n,strokeWidth:i})}):null},$b=({defaultColor:e,rfId:t})=>{const n=he(s=>s.edges),l=he(s=>s.defaultEdgeOptions),a=b.useMemo(()=>nM(n,{id:t,defaultColor:e,defaultMarkerStart:l==null?void 0:l.markerStart,defaultMarkerEnd:l==null?void 0:l.markerEnd}),[n,l,t,e]);return a.length?o.jsx("svg",{className:"react-flow__marker","aria-hidden":"true",children:o.jsx("defs",{children:a.map(s=>o.jsx(hA,{id:s.id,type:s.type,color:s.color,width:s.width,height:s.height,markerUnits:s.markerUnits,strokeWidth:s.strokeWidth,orient:s.orient},s.id))})}):null};$b.displayName="MarkerDefinitions";var pA=b.memo($b);function Bb({x:e,y:t,label:n,labelStyle:l,labelShowBg:a=!0,labelBgStyle:s,labelBgPadding:i=[2,4],labelBgBorderRadius:r=2,children:c,className:u,...d}){const[f,h]=b.useState({x:1,y:0,width:0,height:0}),p=Ve(["react-flow__edge-textwrapper",u]),x=b.useRef(null);return b.useEffect(()=>{if(x.current){const S=x.current.getBBox();h({x:S.x,y:S.y,width:S.width,height:S.height})}},[n]),n?o.jsxs("g",{transform:`translate(${e-f.width/2} ${t-f.height/2})`,className:p,visibility:f.width?"visible":"hidden",...d,children:[a&&o.jsx("rect",{width:f.width+2*i[0],x:-i[0],y:-i[1],height:f.height+2*i[1],className:"react-flow__edge-textbg",style:s,rx:r,ry:r}),o.jsx("text",{className:"react-flow__edge-text",y:f.height/2,dy:"0.3em",ref:x,style:l,children:n}),c]}):null}Bb.displayName="EdgeText";const gA=b.memo(Bb);function Jc({path:e,labelX:t,labelY:n,label:l,labelStyle:a,labelShowBg:s,labelBgStyle:i,labelBgPadding:r,labelBgBorderRadius:c,interactionWidth:u=20,...d}){return o.jsxs(o.Fragment,{children:[o.jsx("path",{...d,d:e,fill:"none",className:Ve(["react-flow__edge-path",d.className])}),u?o.jsx("path",{d:e,fill:"none",strokeOpacity:0,strokeWidth:u,className:"react-flow__edge-interaction"}):null,l&&sn(t)&&sn(n)?o.jsx(gA,{x:t,y:n,label:l,labelStyle:a,labelShowBg:s,labelBgStyle:i,labelBgPadding:r,labelBgBorderRadius:c}):null]})}function mx({pos:e,x1:t,y1:n,x2:l,y2:a}){return e===ee.Left||e===ee.Right?[.5*(t+l),n]:[t,.5*(n+a)]}function Ub({sourceX:e,sourceY:t,sourcePosition:n=ee.Bottom,targetX:l,targetY:a,targetPosition:s=ee.Top}){const[i,r]=mx({pos:n,x1:e,y1:t,x2:l,y2:a}),[c,u]=mx({pos:s,x1:l,y1:a,x2:e,y2:t}),[d,f,h,p]=ab({sourceX:e,sourceY:t,targetX:l,targetY:a,sourceControlX:i,sourceControlY:r,targetControlX:c,targetControlY:u});return[`M${e},${t} C${i},${r} ${c},${u} ${l},${a}`,d,f,h,p]}function qb(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,sourcePosition:i,targetPosition:r,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,interactionWidth:g})=>{const[y,m,v]=Ub({sourceX:n,sourceY:l,sourcePosition:i,targetX:a,targetY:s,targetPosition:r}),j=e.isInternal?void 0:t;return o.jsx(Jc,{id:j,path:y,labelX:m,labelY:v,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,interactionWidth:g})})}const mA=qb({isInternal:!1}),Yb=qb({isInternal:!0});mA.displayName="SimpleBezierEdge";Yb.displayName="SimpleBezierEdgeInternal";function Vb(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,sourcePosition:p=ee.Bottom,targetPosition:x=ee.Top,markerEnd:S,markerStart:w,pathOptions:g,interactionWidth:y})=>{const[m,v,j]=yf({sourceX:n,sourceY:l,sourcePosition:p,targetX:a,targetY:s,targetPosition:x,borderRadius:g==null?void 0:g.borderRadius,offset:g==null?void 0:g.offset,stepPosition:g==null?void 0:g.stepPosition}),E=e.isInternal?void 0:t;return o.jsx(Jc,{id:E,path:m,labelX:v,labelY:j,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,markerEnd:S,markerStart:w,interactionWidth:y})})}const Xb=Vb({isInternal:!1}),Gb=Vb({isInternal:!0});Xb.displayName="SmoothStepEdge";Gb.displayName="SmoothStepEdgeInternal";function Qb(e){return b.memo(({id:t,...n})=>{var a;const l=e.isInternal?void 0:t;return o.jsx(Xb,{...n,id:l,pathOptions:b.useMemo(()=>{var s;return{borderRadius:0,offset:(s=n.pathOptions)==null?void 0:s.offset}},[(a=n.pathOptions)==null?void 0:a.offset])})})}const xA=Qb({isInternal:!1}),Zb=Qb({isInternal:!0});xA.displayName="StepEdge";Zb.displayName="StepEdgeInternal";function Ib(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,markerEnd:p,markerStart:x,interactionWidth:S})=>{const[w,g,y]=rb({sourceX:n,sourceY:l,targetX:a,targetY:s}),m=e.isInternal?void 0:t;return o.jsx(Jc,{id:m,path:w,labelX:g,labelY:y,label:i,labelStyle:r,labelShowBg:c,labelBgStyle:u,labelBgPadding:d,labelBgBorderRadius:f,style:h,markerEnd:p,markerStart:x,interactionWidth:S})})}const yA=Ib({isInternal:!1}),Kb=Ib({isInternal:!0});yA.displayName="StraightEdge";Kb.displayName="StraightEdgeInternal";function Wb(e){return b.memo(({id:t,sourceX:n,sourceY:l,targetX:a,targetY:s,sourcePosition:i=ee.Bottom,targetPosition:r=ee.Top,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,pathOptions:g,interactionWidth:y})=>{const[m,v,j]=sb({sourceX:n,sourceY:l,sourcePosition:i,targetX:a,targetY:s,targetPosition:r,curvature:g==null?void 0:g.curvature}),E=e.isInternal?void 0:t;return o.jsx(Jc,{id:E,path:m,labelX:v,labelY:j,label:c,labelStyle:u,labelShowBg:d,labelBgStyle:f,labelBgPadding:h,labelBgBorderRadius:p,style:x,markerEnd:S,markerStart:w,interactionWidth:y})})}const vA=Wb({isInternal:!1}),Jb=Wb({isInternal:!0});vA.displayName="BezierEdge";Jb.displayName="BezierEdgeInternal";const xx={default:Jb,straight:Kb,step:Zb,smoothstep:Gb,simplebezier:Yb},yx={sourceX:null,sourceY:null,targetX:null,targetY:null,sourcePosition:null,targetPosition:null},bA=(e,t,n)=>n===ee.Left?e-t:n===ee.Right?e+t:e,wA=(e,t,n)=>n===ee.Top?e-t:n===ee.Bottom?e+t:e,vx="react-flow__edgeupdater";function bx({position:e,centerX:t,centerY:n,radius:l=10,onMouseDown:a,onMouseEnter:s,onMouseOut:i,type:r}){return o.jsx("circle",{onMouseDown:a,onMouseEnter:s,onMouseOut:i,className:Ve([vx,`${vx}-${r}`]),cx:bA(t,l,e),cy:wA(n,l,e),r:l,stroke:"transparent",fill:"transparent"})}function SA({isReconnectable:e,reconnectRadius:t,edge:n,sourceX:l,sourceY:a,targetX:s,targetY:i,sourcePosition:r,targetPosition:c,onReconnect:u,onReconnectStart:d,onReconnectEnd:f,setReconnecting:h,setUpdateHover:p}){const x=De(),S=(v,j)=>{if(v.button!==0)return;const{autoPanOnConnect:E,domNode:M,connectionMode:A,connectionRadius:C,lib:H,onConnectStart:T,cancelConnection:$,nodeLookup:V,rfId:N,panBy:D,updateConnection:k}=x.getState(),R=j.type==="target",z=(X,L)=>{h(!1),f==null||f(X,n,j.type,L)},O=X=>u==null?void 0:u(n,X),Y=(X,L)=>{h(!0),d==null||d(v,n,j.type),T==null||T(X,L)};wf.onPointerDown(v.nativeEvent,{autoPanOnConnect:E,connectionMode:A,connectionRadius:C,domNode:M,handleId:j.id,nodeId:j.nodeId,nodeLookup:V,isTarget:R,edgeUpdaterType:j.type,lib:H,flowId:N,cancelConnection:$,panBy:D,isValidConnection:(...X)=>{var L,U;return((U=(L=x.getState()).isValidConnection)==null?void 0:U.call(L,...X))??!0},onConnect:O,onConnectStart:Y,onConnectEnd:(...X)=>{var L,U;return(U=(L=x.getState()).onConnectEnd)==null?void 0:U.call(L,...X)},onReconnectEnd:z,updateConnection:k,getTransform:()=>x.getState().transform,getFromHandle:()=>x.getState().connection.fromHandle,dragThreshold:x.getState().connectionDragThreshold,handleDomNode:v.currentTarget})},w=v=>S(v,{nodeId:n.target,id:n.targetHandle??null,type:"target"}),g=v=>S(v,{nodeId:n.source,id:n.sourceHandle??null,type:"source"}),y=()=>p(!0),m=()=>p(!1);return o.jsxs(o.Fragment,{children:[(e===!0||e==="source")&&o.jsx(bx,{position:r,centerX:l,centerY:a,radius:t,onMouseDown:w,onMouseEnter:y,onMouseOut:m,type:"source"}),(e===!0||e==="target")&&o.jsx(bx,{position:c,centerX:s,centerY:i,radius:t,onMouseDown:g,onMouseEnter:y,onMouseOut:m,type:"target"})]})}function NA({id:e,edgesFocusable:t,edgesReconnectable:n,elementsSelectable:l,onClick:a,onDoubleClick:s,onContextMenu:i,onMouseEnter:r,onMouseMove:c,onMouseLeave:u,reconnectRadius:d,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,rfId:x,edgeTypes:S,noPanClassName:w,onError:g,disableKeyboardA11y:y}){let m=he(J=>J.edgeLookup.get(e));const v=he(J=>J.defaultEdgeOptions);m=v?{...v,...m}:m;let j=m.type||"default",E=(S==null?void 0:S[j])||xx[j];E===void 0&&(g==null||g("011",jn.error011(j)),j="default",E=(S==null?void 0:S.default)||xx.default);const M=!!(m.focusable||t&&typeof m.focusable>"u"),A=typeof f<"u"&&(m.reconnectable||n&&typeof m.reconnectable>"u"),C=!!(m.selectable||l&&typeof m.selectable>"u"),H=b.useRef(null),[T,$]=b.useState(!1),[V,N]=b.useState(!1),D=De(),{zIndex:k,sourceX:R,sourceY:z,targetX:O,targetY:Y,sourcePosition:X,targetPosition:L}=he(b.useCallback(J=>{const F=J.nodeLookup.get(m.source),le=J.nodeLookup.get(m.target);if(!F||!le)return{zIndex:m.zIndex,...yx};const ae=tM({id:e,sourceNode:F,targetNode:le,sourceHandle:m.sourceHandle||null,targetHandle:m.targetHandle||null,connectionMode:J.connectionMode,onError:g});return{zIndex:Z4({selected:m.selected,zIndex:m.zIndex,sourceNode:F,targetNode:le,elevateOnSelect:J.elevateEdgesOnSelect,zIndexMode:J.zIndexMode}),...ae||yx}},[m.source,m.target,m.sourceHandle,m.targetHandle,m.selected,m.zIndex]),ze),U=b.useMemo(()=>m.markerStart?`url('#${vf(m.markerStart,x)}')`:void 0,[m.markerStart,x]),_=b.useMemo(()=>m.markerEnd?`url('#${vf(m.markerEnd,x)}')`:void 0,[m.markerEnd,x]);if(m.hidden||R===null||z===null||O===null||Y===null)return null;const B=J=>{var te;const{addSelectedEdges:F,unselectNodesAndEdges:le,multiSelectionActive:ae}=D.getState();C&&(D.setState({nodesSelectionActive:!1}),m.selected&&ae?(le({nodes:[],edges:[m]}),(te=H.current)==null||te.blur()):F([e])),a&&a(J,m)},G=s?J=>{s(J,{...m})}:void 0,q=i?J=>{i(J,{...m})}:void 0,Q=r?J=>{r(J,{...m})}:void 0,K=c?J=>{c(J,{...m})}:void 0,W=u?J=>{u(J,{...m})}:void 0,P=J=>{var F;if(!y&&X1.includes(J.key)&&C){const{unselectNodesAndEdges:le,addSelectedEdges:ae}=D.getState();J.key==="Escape"?((F=H.current)==null||F.blur(),le({edges:[m]})):ae([e])}};return o.jsx("svg",{style:{zIndex:k},children:o.jsxs("g",{className:Ve(["react-flow__edge",`react-flow__edge-${j}`,m.className,w,{selected:m.selected,animated:m.animated,inactive:!C&&!a,updating:T,selectable:C}]),onClick:B,onDoubleClick:G,onContextMenu:q,onMouseEnter:Q,onMouseMove:K,onMouseLeave:W,onKeyDown:M?P:void 0,tabIndex:M?0:void 0,role:m.ariaRole??(M?"group":"img"),"aria-roledescription":"edge","data-id":e,"data-testid":`rf__edge-${e}`,"aria-label":m.ariaLabel===null?void 0:m.ariaLabel||`Edge from ${m.source} to ${m.target}`,"aria-describedby":M?`${Eb}-${x}`:void 0,ref:H,...m.domAttributes,children:[!V&&o.jsx(E,{id:e,source:m.source,target:m.target,type:m.type,selected:m.selected,animated:m.animated,selectable:C,deletable:m.deletable??!0,label:m.label,labelStyle:m.labelStyle,labelShowBg:m.labelShowBg,labelBgStyle:m.labelBgStyle,labelBgPadding:m.labelBgPadding,labelBgBorderRadius:m.labelBgBorderRadius,sourceX:R,sourceY:z,targetX:O,targetY:Y,sourcePosition:X,targetPosition:L,data:m.data,style:m.style,sourceHandleId:m.sourceHandle,targetHandleId:m.targetHandle,markerStart:U,markerEnd:_,pathOptions:"pathOptions"in m?m.pathOptions:void 0,interactionWidth:m.interactionWidth}),A&&o.jsx(SA,{edge:m,isReconnectable:A,reconnectRadius:d,onReconnect:f,onReconnectStart:h,onReconnectEnd:p,sourceX:R,sourceY:z,targetX:O,targetY:Y,sourcePosition:X,targetPosition:L,setUpdateHover:$,setReconnecting:N})]})})}var jA=b.memo(NA);const kA=e=>({edgesFocusable:e.edgesFocusable,edgesReconnectable:e.edgesReconnectable,elementsSelectable:e.elementsSelectable,connectionMode:e.connectionMode,onError:e.onError});function Fb({defaultMarkerColor:e,onlyRenderVisibleElements:t,rfId:n,edgeTypes:l,noPanClassName:a,onReconnect:s,onEdgeContextMenu:i,onEdgeMouseEnter:r,onEdgeMouseMove:c,onEdgeMouseLeave:u,onEdgeClick:d,reconnectRadius:f,onEdgeDoubleClick:h,onReconnectStart:p,onReconnectEnd:x,disableKeyboardA11y:S}){const{edgesFocusable:w,edgesReconnectable:g,elementsSelectable:y,onError:m}=he(kA,ze),v=cA(t);return o.jsxs("div",{className:"react-flow__edges",children:[o.jsx(pA,{defaultColor:e,rfId:n}),v.map(j=>o.jsx(jA,{id:j,edgesFocusable:w,edgesReconnectable:g,elementsSelectable:y,noPanClassName:a,onReconnect:s,onContextMenu:i,onMouseEnter:r,onMouseMove:c,onMouseLeave:u,onClick:d,reconnectRadius:f,onDoubleClick:h,onReconnectStart:p,onReconnectEnd:x,rfId:n,onError:m,edgeTypes:l,disableKeyboardA11y:S},j))]})}Fb.displayName="EdgeRenderer";const EA=b.memo(Fb),CA=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function MA({children:e}){const t=he(CA);return o.jsx("div",{className:"react-flow__viewport xyflow__viewport react-flow__container",style:{transform:t},children:e})}function _A(e){const t=op(),n=b.useRef(!1);b.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const AA=e=>{var t;return(t=e.panZoom)==null?void 0:t.syncViewport};function TA(e){const t=he(AA),n=De();return b.useEffect(()=>{e&&(t==null||t(e),n.setState({transform:[e.x,e.y,e.zoom]}))},[e,t]),null}function zA(e){return e.connection.inProgress?{...e.connection,to:cr(e.connection.to,e.transform)}:{...e.connection}}function DA(e){return zA}function RA(e){const t=DA();return he(t,ze)}const OA=e=>({nodesConnectable:e.nodesConnectable,isValid:e.connection.isValid,inProgress:e.connection.inProgress,width:e.width,height:e.height});function HA({containerStyle:e,style:t,type:n,component:l}){const{nodesConnectable:a,width:s,height:i,isValid:r,inProgress:c}=he(OA,ze);return!(s&&a&&c)?null:o.jsx("svg",{style:e,width:s,height:i,className:"react-flow__connectionline react-flow__container",children:o.jsx("g",{className:Ve(["react-flow__connection",Z1(r)]),children:o.jsx(Pb,{style:t,type:n,CustomComponent:l,isValid:r})})})}const Pb=({style:e,type:t=xl.Bezier,CustomComponent:n,isValid:l})=>{const{inProgress:a,from:s,fromNode:i,fromHandle:r,fromPosition:c,to:u,toNode:d,toHandle:f,toPosition:h,pointer:p}=RA();if(!a)return;if(n)return o.jsx(n,{connectionLineType:t,connectionLineStyle:e,fromNode:i,fromHandle:r,fromX:s.x,fromY:s.y,toX:u.x,toY:u.y,fromPosition:c,toPosition:h,connectionStatus:Z1(l),toNode:d,toHandle:f,pointer:p});let x="";const S={sourceX:s.x,sourceY:s.y,sourcePosition:c,targetX:u.x,targetY:u.y,targetPosition:h};switch(t){case xl.Bezier:[x]=sb(S);break;case xl.SimpleBezier:[x]=Ub(S);break;case xl.Step:[x]=yf({...S,borderRadius:0});break;case xl.SmoothStep:[x]=yf(S);break;default:[x]=rb(S)}return o.jsx("path",{d:x,fill:"none",className:"react-flow__connection-path",style:e})};Pb.displayName="ConnectionLine";const LA={};function wx(e=LA){b.useRef(e),De(),b.useEffect(()=>{},[e])}function $A(){De(),b.useRef(!1),b.useEffect(()=>{},[])}function e2({nodeTypes:e,edgeTypes:t,onInit:n,onNodeClick:l,onEdgeClick:a,onNodeDoubleClick:s,onEdgeDoubleClick:i,onNodeMouseEnter:r,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,onSelectionContextMenu:f,onSelectionStart:h,onSelectionEnd:p,connectionLineType:x,connectionLineStyle:S,connectionLineComponent:w,connectionLineContainerStyle:g,selectionKeyCode:y,selectionOnDrag:m,selectionMode:v,multiSelectionKeyCode:j,panActivationKeyCode:E,zoomActivationKeyCode:M,deleteKeyCode:A,onlyRenderVisibleElements:C,elementsSelectable:H,defaultViewport:T,translateExtent:$,minZoom:V,maxZoom:N,preventScrolling:D,defaultMarkerColor:k,zoomOnScroll:R,zoomOnPinch:z,panOnScroll:O,panOnScrollSpeed:Y,panOnScrollMode:X,zoomOnDoubleClick:L,panOnDrag:U,onPaneClick:_,onPaneMouseEnter:B,onPaneMouseMove:G,onPaneMouseLeave:q,onPaneScroll:Q,onPaneContextMenu:K,paneClickDistance:W,nodeClickDistance:P,onEdgeContextMenu:J,onEdgeMouseEnter:F,onEdgeMouseMove:le,onEdgeMouseLeave:ae,reconnectRadius:te,onReconnect:ge,onReconnectStart:I,onReconnectEnd:se,noDragClassName:Re,noWheelClassName:st,noPanClassName:Nt,disableKeyboardA11y:Ht,nodeExtent:ll,rfId:_n,viewport:Jt,onViewportChange:Lt}){return wx(e),wx(t),$A(),_A(n),TA(Jt),o.jsx(P_,{onPaneClick:_,onPaneMouseEnter:B,onPaneMouseMove:G,onPaneMouseLeave:q,onPaneContextMenu:K,onPaneScroll:Q,paneClickDistance:W,deleteKeyCode:A,selectionKeyCode:y,selectionOnDrag:m,selectionMode:v,onSelectionStart:h,onSelectionEnd:p,multiSelectionKeyCode:j,panActivationKeyCode:E,zoomActivationKeyCode:M,elementsSelectable:H,zoomOnScroll:R,zoomOnPinch:z,zoomOnDoubleClick:L,panOnScroll:O,panOnScrollSpeed:Y,panOnScrollMode:X,panOnDrag:U,defaultViewport:T,translateExtent:$,minZoom:V,maxZoom:N,onSelectionContextMenu:f,preventScrolling:D,noDragClassName:Re,noWheelClassName:st,noPanClassName:Nt,disableKeyboardA11y:Ht,onViewportChange:Lt,isControlledViewport:!!Jt,children:o.jsxs(MA,{children:[o.jsx(EA,{edgeTypes:t,onEdgeClick:a,onEdgeDoubleClick:i,onReconnect:ge,onReconnectStart:I,onReconnectEnd:se,onlyRenderVisibleElements:C,onEdgeContextMenu:J,onEdgeMouseEnter:F,onEdgeMouseMove:le,onEdgeMouseLeave:ae,reconnectRadius:te,defaultMarkerColor:k,noPanClassName:Nt,disableKeyboardA11y:Ht,rfId:_n}),o.jsx(HA,{style:S,type:x,component:w,containerStyle:g}),o.jsx("div",{className:"react-flow__edgelabel-renderer"}),o.jsx(oA,{nodeTypes:e,onNodeClick:l,onNodeDoubleClick:s,onNodeMouseEnter:r,onNodeMouseMove:c,onNodeMouseLeave:u,onNodeContextMenu:d,nodeClickDistance:P,onlyRenderVisibleElements:C,noPanClassName:Nt,noDragClassName:Re,disableKeyboardA11y:Ht,nodeExtent:ll,rfId:_n}),o.jsx("div",{className:"react-flow__viewport-portal"})]})})}e2.displayName="GraphView";const BA=b.memo(e2),Sx=({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,width:a,height:s,fitView:i,fitViewOptions:r,minZoom:c=.5,maxZoom:u=2,nodeOrigin:d,nodeExtent:f,zIndexMode:h="basic"}={})=>{const p=new Map,x=new Map,S=new Map,w=new Map,g=l??t??[],y=n??e??[],m=d??[0,0],v=f??Hi;ub(S,w,g);const{nodesInitialized:j}=bf(y,p,x,{nodeOrigin:m,nodeExtent:v,zIndexMode:h});let E=[0,0,1];if(i&&a&&s){const M=rr(p,{filter:T=>!!((T.width||T.initialWidth)&&(T.height||T.initialHeight))}),{x:A,y:C,zoom:H}=tp(M,a,s,c,u,(r==null?void 0:r.padding)??.1);E=[A,C,H]}return{rfId:"1",width:a??0,height:s??0,transform:E,nodes:y,nodesInitialized:j,nodeLookup:p,parentLookup:x,edges:g,edgeLookup:w,connectionLookup:S,onNodesChange:null,onEdgesChange:null,hasDefaultNodes:n!==void 0,hasDefaultEdges:l!==void 0,panZoom:null,minZoom:c,maxZoom:u,translateExtent:Hi,nodeExtent:v,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionMode:fs.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:m,nodeDragThreshold:1,connectionDragThreshold:1,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesReconnectable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,elevateEdgesOnSelect:!0,selectNodesOnDrag:!0,multiSelectionActive:!1,fitViewQueued:i??!1,fitViewOptions:r,fitViewResolver:null,connection:{...Q1},connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,autoPanOnNodeFocus:!0,autoPanSpeed:15,connectionRadius:20,onError:q4,isValidConnection:void 0,onSelectionChangeHandlers:[],lib:"react",debug:!1,ariaLabelConfig:G1,zIndexMode:h,onNodesChangeMiddlewareMap:new Map,onEdgesChangeMiddlewareMap:new Map}},UA=({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,width:a,height:s,fitView:i,fitViewOptions:r,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,zIndexMode:h})=>s_((p,x)=>{async function S(){const{nodeLookup:w,panZoom:g,fitViewOptions:y,fitViewResolver:m,width:v,height:j,minZoom:E,maxZoom:M}=x();g&&(await B4({nodes:w,width:v,height:j,panZoom:g,minZoom:E,maxZoom:M},y),m==null||m.resolve(!0),p({fitViewResolver:null}))}return{...Sx({nodes:e,edges:t,width:a,height:s,fitView:i,fitViewOptions:r,minZoom:c,maxZoom:u,nodeOrigin:d,nodeExtent:f,defaultNodes:n,defaultEdges:l,zIndexMode:h}),setNodes:w=>{const{nodeLookup:g,parentLookup:y,nodeOrigin:m,elevateNodesOnSelect:v,fitViewQueued:j,zIndexMode:E,nodesSelectionActive:M}=x(),{nodesInitialized:A,hasSelectedNodes:C}=bf(w,g,y,{nodeOrigin:m,nodeExtent:f,elevateNodesOnSelect:v,checkEquality:!0,zIndexMode:E}),H=M&&C;j&&A?(S(),p({nodes:w,nodesInitialized:A,fitViewQueued:!1,fitViewOptions:void 0,nodesSelectionActive:H})):p({nodes:w,nodesInitialized:A,nodesSelectionActive:H})},setEdges:w=>{const{connectionLookup:g,edgeLookup:y}=x();ub(g,y,w),p({edges:w})},setDefaultNodesAndEdges:(w,g)=>{if(w){const{setNodes:y}=x();y(w),p({hasDefaultNodes:!0})}if(g){const{setEdges:y}=x();y(g),p({hasDefaultEdges:!0})}},updateNodeInternals:w=>{const{triggerNodeChanges:g,nodeLookup:y,parentLookup:m,domNode:v,nodeOrigin:j,nodeExtent:E,debug:M,fitViewQueued:A,zIndexMode:C}=x(),{changes:H,updatedInternals:T}=cM(w,y,m,v,j,E,C);T&&(sM(y,m,{nodeOrigin:j,nodeExtent:E,zIndexMode:C}),A?(S(),p({fitViewQueued:!1,fitViewOptions:void 0})):p({}),(H==null?void 0:H.length)>0&&(M&&console.log("React Flow: trigger node changes",H),g==null||g(H)))},updateNodePositions:(w,g=!1)=>{const y=[];let m=[];const{nodeLookup:v,triggerNodeChanges:j,connection:E,updateConnection:M,onNodesChangeMiddlewareMap:A}=x();for(const[C,H]of w){const T=v.get(C),$=!!(T!=null&&T.expandParent&&(T!=null&&T.parentId)&&(H!=null&&H.position)),V={id:C,type:"position",position:$?{x:Math.max(0,H.position.x),y:Math.max(0,H.position.y)}:H.position,dragging:g};if(T&&E.inProgress&&E.fromNode.id===T.id){const N=pa(T,E.fromHandle,ee.Left,!0);M({...E,from:N})}$&&T.parentId&&y.push({id:C,parentId:T.parentId,rect:{...H.internals.positionAbsolute,width:H.measured.width??0,height:H.measured.height??0}}),m.push(V)}if(y.length>0){const{parentLookup:C,nodeOrigin:H}=x(),T=rp(y,v,C,H);m.push(...T)}for(const C of A.values())m=C(m);j(m)},triggerNodeChanges:w=>{const{onNodesChange:g,setNodes:y,nodes:m,hasDefaultNodes:v,debug:j}=x();if(w!=null&&w.length){if(v){const E=_b(w,m);y(E)}j&&console.log("React Flow: trigger node changes",w),g==null||g(w)}},triggerEdgeChanges:w=>{const{onEdgesChange:g,setEdges:y,edges:m,hasDefaultEdges:v,debug:j}=x();if(w!=null&&w.length){if(v){const E=Ab(w,m);y(E)}j&&console.log("React Flow: trigger edge changes",w),g==null||g(w)}},addSelectedNodes:w=>{const{multiSelectionActive:g,edgeLookup:y,nodeLookup:m,triggerNodeChanges:v,triggerEdgeChanges:j}=x();if(g){const E=w.map(M=>Il(M,!0));v(E);return}v(Ya(m,new Set([...w]),!0)),j(Ya(y))},addSelectedEdges:w=>{const{multiSelectionActive:g,edgeLookup:y,nodeLookup:m,triggerNodeChanges:v,triggerEdgeChanges:j}=x();if(g){const E=w.map(M=>Il(M,!0));j(E);return}j(Ya(y,new Set([...w]))),v(Ya(m,new Set,!0))},unselectNodesAndEdges:({nodes:w,edges:g}={})=>{const{edges:y,nodes:m,nodeLookup:v,triggerNodeChanges:j,triggerEdgeChanges:E}=x(),M=w||m,A=g||y,C=[];for(const T of M){if(!T.selected)continue;const $=v.get(T.id);$&&($.selected=!1),C.push(Il(T.id,!1))}const H=[];for(const T of A)T.selected&&H.push(Il(T.id,!1));j(C),E(H)},setMinZoom:w=>{const{panZoom:g,maxZoom:y}=x();g==null||g.setScaleExtent([w,y]),p({minZoom:w})},setMaxZoom:w=>{const{panZoom:g,minZoom:y}=x();g==null||g.setScaleExtent([y,w]),p({maxZoom:w})},setTranslateExtent:w=>{var g;(g=x().panZoom)==null||g.setTranslateExtent(w),p({translateExtent:w})},resetSelectedElements:()=>{const{edges:w,nodes:g,triggerNodeChanges:y,triggerEdgeChanges:m,elementsSelectable:v}=x();if(!v)return;const j=g.reduce((M,A)=>A.selected?[...M,Il(A.id,!1)]:M,[]),E=w.reduce((M,A)=>A.selected?[...M,Il(A.id,!1)]:M,[]);y(j),m(E)},setNodeExtent:w=>{const{nodes:g,nodeLookup:y,parentLookup:m,nodeOrigin:v,elevateNodesOnSelect:j,nodeExtent:E,zIndexMode:M}=x();w[0][0]===E[0][0]&&w[0][1]===E[0][1]&&w[1][0]===E[1][0]&&w[1][1]===E[1][1]||(bf(g,y,m,{nodeOrigin:v,nodeExtent:w,elevateNodesOnSelect:j,checkEquality:!1,zIndexMode:M}),p({nodeExtent:w}))},panBy:w=>{const{transform:g,width:y,height:m,panZoom:v,translateExtent:j}=x();return uM({delta:w,panZoom:v,transform:g,translateExtent:j,width:y,height:m})},setCenter:async(w,g,y)=>{const{width:m,height:v,maxZoom:j,panZoom:E}=x();if(!E)return Promise.resolve(!1);const M=typeof(y==null?void 0:y.zoom)<"u"?y.zoom:j;return await E.setViewport({x:m/2-w*M,y:v/2-g*M,zoom:M},{duration:y==null?void 0:y.duration,ease:y==null?void 0:y.ease,interpolate:y==null?void 0:y.interpolate}),Promise.resolve(!0)},cancelConnection:()=>{p({connection:{...Q1}})},updateConnection:w=>{p({connection:w})},reset:()=>p({...Sx()})}},Object.is);function qA({initialNodes:e,initialEdges:t,defaultNodes:n,defaultEdges:l,initialWidth:a,initialHeight:s,initialMinZoom:i,initialMaxZoom:r,initialFitViewOptions:c,fitView:u,nodeOrigin:d,nodeExtent:f,zIndexMode:h,children:p}){const[x]=b.useState(()=>UA({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,width:a,height:s,fitView:u,minZoom:i,maxZoom:r,fitViewOptions:c,nodeOrigin:d,nodeExtent:f,zIndexMode:h}));return o.jsx(i_,{value:x,children:o.jsx(M_,{children:p})})}function YA({children:e,nodes:t,edges:n,defaultNodes:l,defaultEdges:a,width:s,height:i,fitView:r,fitViewOptions:c,minZoom:u,maxZoom:d,nodeOrigin:f,nodeExtent:h,zIndexMode:p}){return b.useContext(Ic)?o.jsx(o.Fragment,{children:e}):o.jsx(qA,{initialNodes:t,initialEdges:n,defaultNodes:l,defaultEdges:a,initialWidth:s,initialHeight:i,fitView:r,initialFitViewOptions:c,initialMinZoom:u,initialMaxZoom:d,nodeOrigin:f,nodeExtent:h,zIndexMode:p,children:e})}const VA={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0};function XA({nodes:e,edges:t,defaultNodes:n,defaultEdges:l,className:a,nodeTypes:s,edgeTypes:i,onNodeClick:r,onEdgeClick:c,onInit:u,onMove:d,onMoveStart:f,onMoveEnd:h,onConnect:p,onConnectStart:x,onConnectEnd:S,onClickConnectStart:w,onClickConnectEnd:g,onNodeMouseEnter:y,onNodeMouseMove:m,onNodeMouseLeave:v,onNodeContextMenu:j,onNodeDoubleClick:E,onNodeDragStart:M,onNodeDrag:A,onNodeDragStop:C,onNodesDelete:H,onEdgesDelete:T,onDelete:$,onSelectionChange:V,onSelectionDragStart:N,onSelectionDrag:D,onSelectionDragStop:k,onSelectionContextMenu:R,onSelectionStart:z,onSelectionEnd:O,onBeforeDelete:Y,connectionMode:X,connectionLineType:L=xl.Bezier,connectionLineStyle:U,connectionLineComponent:_,connectionLineContainerStyle:B,deleteKeyCode:G="Backspace",selectionKeyCode:q="Shift",selectionOnDrag:Q=!1,selectionMode:K=Li.Full,panActivationKeyCode:W="Space",multiSelectionKeyCode:P=Bi()?"Meta":"Control",zoomActivationKeyCode:J=Bi()?"Meta":"Control",snapToGrid:F,snapGrid:le,onlyRenderVisibleElements:ae=!1,selectNodesOnDrag:te,nodesDraggable:ge,autoPanOnNodeFocus:I,nodesConnectable:se,nodesFocusable:Re,nodeOrigin:st=Cb,edgesFocusable:Nt,edgesReconnectable:Ht,elementsSelectable:ll=!0,defaultViewport:_n=v_,minZoom:Jt=.5,maxZoom:Lt=2,translateExtent:An=Hi,preventScrolling:Bl=!0,nodeExtent:wa,defaultMarkerColor:fn="#b1b1b7",zoomOnScroll:ur=!0,zoomOnPinch:Fc=!0,panOnScroll:Pc=!1,panOnScrollSpeed:Ts=.5,panOnScrollMode:dr=aa.Free,zoomOnDoubleClick:eu=!0,panOnDrag:fr=!0,onPaneClick:tu,onPaneMouseEnter:nu,onPaneMouseMove:lu,onPaneMouseLeave:Ie,onPaneScroll:it,onPaneContextMenu:rt,paneClickDistance:hn=1,nodeClickDistance:ht=0,children:ot,onReconnect:$t,onReconnectStart:al,onReconnectEnd:Xe,onEdgeContextMenu:pn,onEdgeDoubleClick:Bt,onEdgeMouseEnter:Ft,onEdgeMouseMove:Ul,onEdgeMouseLeave:ql,reconnectRadius:gn=10,onNodesChange:Yl,onEdgesChange:zs,noDragClassName:a2="nodrag",noWheelClassName:s2="nowheel",noPanClassName:up="nopan",fitView:dp,fitViewOptions:fp,connectOnClick:i2,attributionPosition:r2,proOptions:o2,defaultEdgeOptions:c2,elevateNodesOnSelect:u2=!0,elevateEdgesOnSelect:d2=!1,disableKeyboardA11y:hp=!1,autoPanOnConnect:f2,autoPanOnNodeDrag:h2,autoPanSpeed:p2,connectionRadius:g2,isValidConnection:m2,onError:x2,style:y2,id:pp,nodeDragThreshold:v2,connectionDragThreshold:b2,viewport:w2,onViewportChange:S2,width:N2,height:j2,colorMode:k2="light",debug:E2,onScroll:hr,ariaLabelConfig:C2,zIndexMode:gp="basic",...M2},_2){const au=pp||"1",A2=N_(k2),T2=b.useCallback(mp=>{mp.currentTarget.scrollTo({top:0,left:0,behavior:"instant"}),hr==null||hr(mp)},[hr]);return o.jsx("div",{"data-testid":"rf__wrapper",...M2,onScroll:T2,style:{...y2,...VA},ref:_2,className:Ve(["react-flow",a,A2]),id:pp,role:"application",children:o.jsxs(YA,{nodes:e,edges:t,width:N2,height:j2,fitView:dp,fitViewOptions:fp,minZoom:Jt,maxZoom:Lt,nodeOrigin:st,nodeExtent:wa,zIndexMode:gp,children:[o.jsx(S_,{nodes:e,edges:t,defaultNodes:n,defaultEdges:l,onConnect:p,onConnectStart:x,onConnectEnd:S,onClickConnectStart:w,onClickConnectEnd:g,nodesDraggable:ge,autoPanOnNodeFocus:I,nodesConnectable:se,nodesFocusable:Re,edgesFocusable:Nt,edgesReconnectable:Ht,elementsSelectable:ll,elevateNodesOnSelect:u2,elevateEdgesOnSelect:d2,minZoom:Jt,maxZoom:Lt,nodeExtent:wa,onNodesChange:Yl,onEdgesChange:zs,snapToGrid:F,snapGrid:le,connectionMode:X,translateExtent:An,connectOnClick:i2,defaultEdgeOptions:c2,fitView:dp,fitViewOptions:fp,onNodesDelete:H,onEdgesDelete:T,onDelete:$,onNodeDragStart:M,onNodeDrag:A,onNodeDragStop:C,onSelectionDrag:D,onSelectionDragStart:N,onSelectionDragStop:k,onMove:d,onMoveStart:f,onMoveEnd:h,noPanClassName:up,nodeOrigin:st,rfId:au,autoPanOnConnect:f2,autoPanOnNodeDrag:h2,autoPanSpeed:p2,onError:x2,connectionRadius:g2,isValidConnection:m2,selectNodesOnDrag:te,nodeDragThreshold:v2,connectionDragThreshold:b2,onBeforeDelete:Y,debug:E2,ariaLabelConfig:C2,zIndexMode:gp}),o.jsx(BA,{onInit:u,onNodeClick:r,onEdgeClick:c,onNodeMouseEnter:y,onNodeMouseMove:m,onNodeMouseLeave:v,onNodeContextMenu:j,onNodeDoubleClick:E,nodeTypes:s,edgeTypes:i,connectionLineType:L,connectionLineStyle:U,connectionLineComponent:_,connectionLineContainerStyle:B,selectionKeyCode:q,selectionOnDrag:Q,selectionMode:K,deleteKeyCode:G,multiSelectionKeyCode:P,panActivationKeyCode:W,zoomActivationKeyCode:J,onlyRenderVisibleElements:ae,defaultViewport:_n,translateExtent:An,minZoom:Jt,maxZoom:Lt,preventScrolling:Bl,zoomOnScroll:ur,zoomOnPinch:Fc,zoomOnDoubleClick:eu,panOnScroll:Pc,panOnScrollSpeed:Ts,panOnScrollMode:dr,panOnDrag:fr,onPaneClick:tu,onPaneMouseEnter:nu,onPaneMouseMove:lu,onPaneMouseLeave:Ie,onPaneScroll:it,onPaneContextMenu:rt,paneClickDistance:hn,nodeClickDistance:ht,onSelectionContextMenu:R,onSelectionStart:z,onSelectionEnd:O,onReconnect:$t,onReconnectStart:al,onReconnectEnd:Xe,onEdgeContextMenu:pn,onEdgeDoubleClick:Bt,onEdgeMouseEnter:Ft,onEdgeMouseMove:Ul,onEdgeMouseLeave:ql,reconnectRadius:gn,defaultMarkerColor:fn,noDragClassName:a2,noWheelClassName:s2,noPanClassName:up,rfId:au,disableKeyboardA11y:hp,nodeExtent:wa,viewport:w2,onViewportChange:S2}),o.jsx(y_,{onSelectionChange:V}),ot,o.jsx(h_,{proOptions:o2,position:r2}),o.jsx(f_,{rfId:au,disableKeyboardA11y:hp})]})})}var GA=Tb(XA);function QA(e){const[t,n]=b.useState(e),l=b.useCallback(a=>n(s=>_b(a,s)),[]);return[t,n,l]}function ZA(e){const[t,n]=b.useState(e),l=b.useCallback(a=>n(s=>Ab(a,s)),[]);return[t,n,l]}function IA({dimensions:e,lineWidth:t,variant:n,className:l}){return o.jsx("path",{strokeWidth:t,d:`M${e[0]/2} 0 V${e[1]} M0 ${e[1]/2} H${e[0]}`,className:Ve(["react-flow__background-pattern",n,l])})}function KA({radius:e,className:t}){return o.jsx("circle",{cx:e,cy:e,r:e,className:Ve(["react-flow__background-pattern","dots",t])})}var In;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(In||(In={}));const WA={[In.Dots]:1,[In.Lines]:1,[In.Cross]:6},JA=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function t2({id:e,variant:t=In.Dots,gap:n=20,size:l,lineWidth:a=1,offset:s=0,color:i,bgColor:r,style:c,className:u,patternClassName:d}){const f=b.useRef(null),{transform:h,patternId:p}=he(JA,ze),x=l||WA[t],S=t===In.Dots,w=t===In.Cross,g=Array.isArray(n)?n:[n,n],y=[g[0]*h[2]||1,g[1]*h[2]||1],m=x*h[2],v=Array.isArray(s)?s:[s,s],j=w?[m,m]:y,E=[v[0]*h[2]||1+j[0]/2,v[1]*h[2]||1+j[1]/2],M=`${p}${e||""}`;return o.jsxs("svg",{className:Ve(["react-flow__background",u]),style:{...c,...Wc,"--xy-background-color-props":r,"--xy-background-pattern-color-props":i},ref:f,"data-testid":"rf__background",children:[o.jsx("pattern",{id:M,x:h[0]%y[0],y:h[1]%y[1],width:y[0],height:y[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${E[0]},-${E[1]})`,children:S?o.jsx(KA,{radius:m/2,className:d}):o.jsx(IA,{dimensions:j,lineWidth:a,variant:t,className:d})}),o.jsx("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${M})`})]})}t2.displayName="Background";const FA=b.memo(t2);function PA(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32",children:o.jsx("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"})})}function eT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5",children:o.jsx("path",{d:"M0 0h32v4.2H0z"})})}function tT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30",children:o.jsx("path",{d:"M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z"})})}function nT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:o.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0 8 0 4.571 3.429 4.571 7.619v3.048H3.048A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047zm4.724-13.866H7.467V7.619c0-2.59 2.133-4.724 4.723-4.724 2.591 0 4.724 2.133 4.724 4.724v3.048z"})})}function lT(){return o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32",children:o.jsx("path",{d:"M21.333 10.667H19.81V7.619C19.81 3.429 16.38 0 12.19 0c-4.114 1.828-1.37 2.133.305 2.438 1.676.305 4.42 2.59 4.42 5.181v3.048H3.047A3.056 3.056 0 000 13.714v15.238A3.056 3.056 0 003.048 32h18.285a3.056 3.056 0 003.048-3.048V13.714a3.056 3.056 0 00-3.048-3.047zM12.19 24.533a3.056 3.056 0 01-3.047-3.047 3.056 3.056 0 013.047-3.048 3.056 3.056 0 013.048 3.048 3.056 3.056 0 01-3.048 3.047z"})})}function Xr({children:e,className:t,...n}){return o.jsx("button",{type:"button",className:Ve(["react-flow__controls-button",t]),...n,children:e})}const aT=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom,ariaLabelConfig:e.ariaLabelConfig});function n2({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:l=!0,fitViewOptions:a,onZoomIn:s,onZoomOut:i,onFitView:r,onInteractiveChange:c,className:u,children:d,position:f="bottom-left",orientation:h="vertical","aria-label":p}){const x=De(),{isInteractive:S,minZoomReached:w,maxZoomReached:g,ariaLabelConfig:y}=he(aT,ze),{zoomIn:m,zoomOut:v,fitView:j}=op(),E=()=>{m(),s==null||s()},M=()=>{v(),i==null||i()},A=()=>{j(a),r==null||r()},C=()=>{x.setState({nodesDraggable:!S,nodesConnectable:!S,elementsSelectable:!S}),c==null||c(!S)},H=h==="horizontal"?"horizontal":"vertical";return o.jsxs(Kc,{className:Ve(["react-flow__controls",H,u]),position:f,style:e,"data-testid":"rf__controls","aria-label":p??y["controls.ariaLabel"],children:[t&&o.jsxs(o.Fragment,{children:[o.jsx(Xr,{onClick:E,className:"react-flow__controls-zoomin",title:y["controls.zoomIn.ariaLabel"],"aria-label":y["controls.zoomIn.ariaLabel"],disabled:g,children:o.jsx(PA,{})}),o.jsx(Xr,{onClick:M,className:"react-flow__controls-zoomout",title:y["controls.zoomOut.ariaLabel"],"aria-label":y["controls.zoomOut.ariaLabel"],disabled:w,children:o.jsx(eT,{})})]}),n&&o.jsx(Xr,{className:"react-flow__controls-fitview",onClick:A,title:y["controls.fitView.ariaLabel"],"aria-label":y["controls.fitView.ariaLabel"],children:o.jsx(tT,{})}),l&&o.jsx(Xr,{className:"react-flow__controls-interactive",onClick:C,title:y["controls.interactive.ariaLabel"],"aria-label":y["controls.interactive.ariaLabel"],children:S?o.jsx(lT,{}):o.jsx(nT,{})}),d]})}n2.displayName="Controls";const sT=b.memo(n2);function iT({id:e,x:t,y:n,width:l,height:a,style:s,color:i,strokeColor:r,strokeWidth:c,className:u,borderRadius:d,shapeRendering:f,selected:h,onClick:p}){const{background:x,backgroundColor:S}=s||{},w=i||x||S;return o.jsx("rect",{className:Ve(["react-flow__minimap-node",{selected:h},u]),x:t,y:n,rx:d,ry:d,width:l,height:a,style:{fill:w,stroke:r,strokeWidth:c},shapeRendering:f,onClick:p?g=>p(g,e):void 0})}const rT=b.memo(iT),oT=e=>e.nodes.map(t=>t.id),ld=e=>e instanceof Function?e:()=>e;function cT({nodeStrokeColor:e,nodeColor:t,nodeClassName:n="",nodeBorderRadius:l=5,nodeStrokeWidth:a,nodeComponent:s=rT,onClick:i}){const r=he(oT,ze),c=ld(t),u=ld(e),d=ld(n),f=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return o.jsx(o.Fragment,{children:r.map(h=>o.jsx(dT,{id:h,nodeColorFunc:c,nodeStrokeColorFunc:u,nodeClassNameFunc:d,nodeBorderRadius:l,nodeStrokeWidth:a,NodeComponent:s,onClick:i,shapeRendering:f},h))})}function uT({id:e,nodeColorFunc:t,nodeStrokeColorFunc:n,nodeClassNameFunc:l,nodeBorderRadius:a,nodeStrokeWidth:s,shapeRendering:i,NodeComponent:r,onClick:c}){const{node:u,x:d,y:f,width:h,height:p}=he(x=>{const S=x.nodeLookup.get(e);if(!S)return{node:void 0,x:0,y:0,width:0,height:0};const w=S.internals.userNode,{x:g,y}=S.internals.positionAbsolute,{width:m,height:v}=nl(w);return{node:w,x:g,y,width:m,height:v}},ze);return!u||u.hidden||!P1(u)?null:o.jsx(r,{x:d,y:f,width:h,height:p,style:u.style,selected:!!u.selected,className:l(u),color:t(u),borderRadius:a,strokeColor:n(u),strokeWidth:s,shapeRendering:i,onClick:c,id:u.id})}const dT=b.memo(uT);var fT=b.memo(cT);const hT=200,pT=150,gT=e=>!e.hidden,mT=e=>{const t={x:-e.transform[0]/e.transform[2],y:-e.transform[1]/e.transform[2],width:e.width/e.transform[2],height:e.height/e.transform[2]};return{viewBB:t,boundingRect:e.nodeLookup.size>0?F1(rr(e.nodeLookup,{filter:gT}),t):t,rfId:e.rfId,panZoom:e.panZoom,translateExtent:e.translateExtent,flowWidth:e.width,flowHeight:e.height,ariaLabelConfig:e.ariaLabelConfig}},xT="react-flow__minimap-desc";function l2({style:e,className:t,nodeStrokeColor:n,nodeColor:l,nodeClassName:a="",nodeBorderRadius:s=5,nodeStrokeWidth:i,nodeComponent:r,bgColor:c,maskColor:u,maskStrokeColor:d,maskStrokeWidth:f,position:h="bottom-right",onClick:p,onNodeClick:x,pannable:S=!1,zoomable:w=!1,ariaLabel:g,inversePan:y,zoomStep:m=1,offsetScale:v=5}){const j=De(),E=b.useRef(null),{boundingRect:M,viewBB:A,rfId:C,panZoom:H,translateExtent:T,flowWidth:$,flowHeight:V,ariaLabelConfig:N}=he(mT,ze),D=(e==null?void 0:e.width)??hT,k=(e==null?void 0:e.height)??pT,R=M.width/D,z=M.height/k,O=Math.max(R,z),Y=O*D,X=O*k,L=v*O,U=M.x-(Y-M.width)/2-L,_=M.y-(X-M.height)/2-L,B=Y+L*2,G=X+L*2,q=`${xT}-${C}`,Q=b.useRef(0),K=b.useRef();Q.current=O,b.useEffect(()=>{if(E.current&&H)return K.current=vM({domNode:E.current,panZoom:H,getTransform:()=>j.getState().transform,getViewScale:()=>Q.current}),()=>{var F;(F=K.current)==null||F.destroy()}},[H]),b.useEffect(()=>{var F;(F=K.current)==null||F.update({translateExtent:T,width:$,height:V,inversePan:y,pannable:S,zoomStep:m,zoomable:w})},[S,w,y,m,T,$,V]);const W=p?F=>{var te;const[le,ae]=((te=K.current)==null?void 0:te.pointer(F))||[0,0];p(F,{x:le,y:ae})}:void 0,P=x?b.useCallback((F,le)=>{const ae=j.getState().nodeLookup.get(le).internals.userNode;x(F,ae)},[]):void 0,J=g??N["minimap.ariaLabel"];return o.jsx(Kc,{position:h,style:{...e,"--xy-minimap-background-color-props":typeof c=="string"?c:void 0,"--xy-minimap-mask-background-color-props":typeof u=="string"?u:void 0,"--xy-minimap-mask-stroke-color-props":typeof d=="string"?d:void 0,"--xy-minimap-mask-stroke-width-props":typeof f=="number"?f*O:void 0,"--xy-minimap-node-background-color-props":typeof l=="string"?l:void 0,"--xy-minimap-node-stroke-color-props":typeof n=="string"?n:void 0,"--xy-minimap-node-stroke-width-props":typeof i=="number"?i:void 0},className:Ve(["react-flow__minimap",t]),"data-testid":"rf__minimap",children:o.jsxs("svg",{width:D,height:k,viewBox:`${U} ${_} ${B} ${G}`,className:"react-flow__minimap-svg",role:"img","aria-labelledby":q,ref:E,onClick:W,children:[J&&o.jsx("title",{id:q,children:J}),o.jsx(fT,{onClick:P,nodeColor:l,nodeStrokeColor:n,nodeBorderRadius:s,nodeClassName:a,nodeStrokeWidth:i,nodeComponent:r}),o.jsx("path",{className:"react-flow__minimap-mask",d:`M${U-L},${_-L}h${B+L*2}v${G+L*2}h${-B-L*2}z
165
+ M${A.x},${A.y}h${A.width}v${A.height}h${-A.width}z`,fillRule:"evenodd",pointerEvents:"none"})]})})}l2.displayName="MiniMap";const yT=b.memo(l2),vT=e=>t=>e?`${Math.max(1/t.transform[2],1)}`:void 0,bT={[ms.Line]:"right",[ms.Handle]:"bottom-right"};function wT({nodeId:e,position:t,variant:n=ms.Handle,className:l,style:a=void 0,children:s,color:i,minWidth:r=10,minHeight:c=10,maxWidth:u=Number.MAX_VALUE,maxHeight:d=Number.MAX_VALUE,keepAspectRatio:f=!1,resizeDirection:h,autoScale:p=!0,shouldResize:x,onResizeStart:S,onResize:w,onResizeEnd:g}){const y=Ob(),m=typeof e=="string"?e:y,v=De(),j=b.useRef(null),E=n===ms.Handle,M=he(b.useCallback(vT(E&&p),[E,p]),ze),A=b.useRef(null),C=t??bT[n];b.useEffect(()=>{if(!(!j.current||!m))return A.current||(A.current=DM({domNode:j.current,nodeId:m,getStoreItems:()=>{const{nodeLookup:T,transform:$,snapGrid:V,snapToGrid:N,nodeOrigin:D,domNode:k}=v.getState();return{nodeLookup:T,transform:$,snapGrid:V,snapToGrid:N,nodeOrigin:D,paneDomNode:k}},onChange:(T,$)=>{const{triggerNodeChanges:V,nodeLookup:N,parentLookup:D,nodeOrigin:k}=v.getState(),R=[],z={x:T.x,y:T.y},O=N.get(m);if(O&&O.expandParent&&O.parentId){const Y=O.origin??k,X=T.width??O.measured.width??0,L=T.height??O.measured.height??0,U={id:O.id,parentId:O.parentId,rect:{width:X,height:L,...eb({x:T.x??O.position.x,y:T.y??O.position.y},{width:X,height:L},O.parentId,N,Y)}},_=rp([U],N,D,k);R.push(..._),z.x=T.x?Math.max(Y[0]*X,T.x):void 0,z.y=T.y?Math.max(Y[1]*L,T.y):void 0}if(z.x!==void 0&&z.y!==void 0){const Y={id:m,type:"position",position:{...z}};R.push(Y)}if(T.width!==void 0&&T.height!==void 0){const X={id:m,type:"dimensions",resizing:!0,setAttributes:h?h==="horizontal"?"width":"height":!0,dimensions:{width:T.width,height:T.height}};R.push(X)}for(const Y of $){const X={...Y,type:"position"};R.push(X)}V(R)},onEnd:({width:T,height:$})=>{const V={id:m,type:"dimensions",resizing:!1,dimensions:{width:T,height:$}};v.getState().triggerNodeChanges([V])}})),A.current.update({controlPosition:C,boundaries:{minWidth:r,minHeight:c,maxWidth:u,maxHeight:d},keepAspectRatio:f,resizeDirection:h,onResizeStart:S,onResize:w,onResizeEnd:g,shouldResize:x}),()=>{var T;(T=A.current)==null||T.destroy()}},[C,r,c,u,d,f,S,w,g,x]);const H=C.split("-");return o.jsx("div",{className:Ve(["react-flow__resize-control","nodrag",...H,n,l]),ref:j,style:{...a,scale:M,...i&&{[E?"backgroundColor":"borderColor"]:i}},children:s})}b.memo(wT);const xn={concepts:{fill:"#f75858",light:"#ff9090",dark:"#be3232",glowRgb:"254,0,0",edgeColor:"rgba(254,0,0,0.55)",hex:"#f75858"},entities:{fill:"#5e89e0",light:"#8cb4ff",dark:"#3658b4",glowRgb:"16,96,255",edgeColor:"rgba(16,96,255,0.55)",hex:"#5e89e0"},summaries:{fill:"#bd68bd",light:"#dc8cdc",dark:"#460f46",glowRgb:"171,49,170",edgeColor:"rgba(171,49,170,0.55)",hex:"#bd68bd"},other:{fill:"#24b550",light:"#82e6a0",dark:"#0c5023",glowRgb:"36,181,80",edgeColor:"rgba(36,181,80,0.55)",hex:"#24b550"}};function ad(e){return xn[e.toLowerCase()]??xn.other}function ST(e,t,n=150){const l=e.length,a=new Map,s=new Map,i=Math.min(600,Math.max(150,l*40));e.forEach((c,u)=>{const d=u/l*2*Math.PI;a.set(c.slug,{x:400+i*Math.cos(d),y:400+i*Math.sin(d)}),s.set(c.slug,{vx:0,vy:0})});const r=e.map(c=>c.slug);for(let c=0;c<n;c++){for(let u=0;u<r.length;u++)for(let d=u+1;d<r.length;d++){const f=r[u],h=r[d],p=a.get(f),x=a.get(h),S=x.x-p.x,w=x.y-p.y,g=Math.max(1,S*S+w*w),y=Math.sqrt(g),m=18e3/g,v=S/y*m,j=w/y*m,E=s.get(f),M=s.get(h);E.vx-=v,E.vy-=j,M.vx+=v,M.vy+=j}for(const u of t){const d=a.get(u.source),f=a.get(u.target);if(!d||!f)continue;const h=f.x-d.x,p=f.y-d.y,x=Math.max(1,Math.sqrt(h*h+p*p)),S=x*.02,w=h/x*S,g=p/x*S,y=s.get(u.source),m=s.get(u.target);y&&(y.vx+=w,y.vy+=g),m&&(m.vx-=w,m.vy-=g)}for(const u of r){const d=a.get(u),f=s.get(u);f.vx=Math.max(-20,Math.min(20,f.vx)),f.vy=Math.max(-20,Math.min(20,f.vy)),d.x+=f.vx,d.y+=f.vy,f.vx*=.85,f.vy*=.85}}return a}const NT=5,jT=9;function kT(e){const t=e.data,n=t.radius,l=t.degree,a=t.dimmed,s=t.hovered,i=t.glowRgb,r=t.fill,c=l>=NT,u=l>=jT,d=a?"none":s?`0 0 0 1.5px rgba(${i},0.8), 0 0 10px rgba(${i},1), 0 0 24px rgba(${i},0.7), 0 0 44px rgba(${i},0.3), 0 0 70px rgba(${i},0.12)`:`0 0 0 1px rgba(${i},0.35), 0 0 7px rgba(${i},0.65), 0 0 18px rgba(${i},0.25)`,f=s?"scale(1.28)":"scale(1)";return o.jsxs("div",{style:{position:"relative",width:n*2,height:n*2},children:[c&&!a&&o.jsx("div",{style:{position:"absolute",inset:-(n*.55),borderRadius:"50%",background:`radial-gradient(circle, rgba(${i},0.08) 0%, transparent 70%)`,pointerEvents:"none"}}),c&&!a&&o.jsx("div",{style:{position:"absolute",inset:-(n*.45),borderRadius:"50%",border:`1.5px solid rgba(${i},0.5)`,animation:"wikiNodePulse 2.6s cubic-bezier(0.4,0,0.6,1) infinite",pointerEvents:"none"}}),u&&!a&&o.jsx("div",{style:{position:"absolute",inset:-(n*.8),borderRadius:"50%",border:`1px solid rgba(${i},0.28)`,animation:"wikiNodePulse 3.8s cubic-bezier(0.4,0,0.6,1) infinite 1.1s",pointerEvents:"none"}}),o.jsxs("div",{style:{position:"absolute",inset:0,borderRadius:"50%",background:`radial-gradient(circle at 33% 28%, ${t.light} 0%, ${r} 52%, ${t.dark} 100%)`,boxShadow:d,opacity:a?.06:1,transform:f,transition:"transform 0.22s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s ease, opacity 0.18s ease",overflow:"hidden"},children:[o.jsx("div",{style:{position:"absolute",top:"9%",left:"14%",width:"38%",height:"38%",borderRadius:"50%",background:"radial-gradient(circle, rgba(255,255,255,0.62) 0%, rgba(255,255,255,0.1) 55%, transparent 100%)",pointerEvents:"none"}}),o.jsx("div",{style:{position:"absolute",bottom:"10%",right:"12%",width:"22%",height:"22%",borderRadius:"50%",background:"radial-gradient(circle, rgba(255,255,255,0.18) 0%, transparent 100%)",pointerEvents:"none"}})]}),!a&&o.jsx("div",{style:{position:"absolute",top:n*2+5,left:"50%",transform:"translateX(-50%)",whiteSpace:"nowrap",maxWidth:128,overflow:"hidden",textOverflow:"ellipsis",fontSize:s?10:9,fontWeight:s?600:400,color:s?r:"var(--text2)",background:"color-mix(in srgb, var(--bg) 78%, transparent)",backdropFilter:"blur(6px)",WebkitBackdropFilter:"blur(6px)",padding:"1px 6px 2px",borderRadius:5,border:s?`1px solid rgba(${i},0.4)`:"1px solid transparent",boxShadow:s?`0 0 8px rgba(${i},0.3)`:"none",transition:"all 0.2s ease",fontFamily:"inherit",letterSpacing:s?"0.025em":"normal",pointerEvents:"none"},children:t.title}),o.jsx(ys,{type:"target",position:ee.Left,style:{opacity:0,pointerEvents:"none"}}),o.jsx(ys,{type:"source",position:ee.Right,style:{opacity:0,pointerEvents:"none"}})]})}const ET={wikiNode:kT},CT=[{label:"Concepts",color:xn.concepts.fill,rgb:xn.concepts.glowRgb},{label:"Entities",color:xn.entities.fill,rgb:xn.entities.glowRgb},{label:"Summaries",color:xn.summaries.fill,rgb:xn.summaries.glowRgb},{label:"Other",color:xn.other.fill,rgb:xn.other.glowRgb}];function MT({graphData:e,loading:t,onNodeClick:n}){const{initNodes:l,initEdges:a,adjacency:s}=b.useMemo(()=>{var M,A;const S=(e==null?void 0:e.nodes)??[],w=(e==null?void 0:e.edges)??[];if(S.length===0)return{initNodes:[],initEdges:[],adjacency:new Map};const g=new Map,y=new Map;for(const C of S)g.set(C.slug,0),y.set(C.slug,C.category);for(const C of w)g.set(C.source,(g.get(C.source)??0)+1),g.set(C.target,(g.get(C.target)??0)+1);const m=new Map;for(const C of S)m.set(C.slug,new Set);for(const C of w)(M=m.get(C.source))==null||M.add(C.target),(A=m.get(C.target))==null||A.add(C.source);const v=ST(S,w,150),j=S.map(C=>{const H=g.get(C.slug)??0,T=Math.min(11,Math.max(4,4+H*.8)),$=v.get(C.slug)??{x:400,y:400},V=ad(C.category);return{id:C.slug,type:"wikiNode",position:$,data:{slug:C.slug,title:C.title||(C.slug.split("/").pop()??C.slug),category:C.category,fill:V.fill,light:V.light,dark:V.dark,glowRgb:V.glowRgb,radius:T,degree:H,dimmed:!1,hovered:!1}}}),E=w.map((C,H)=>{const T=ad(y.get(C.source)??"other");return{id:`e${H}-${C.source}-${C.target}`,source:C.source,target:C.target,type:"straight",animated:!0,style:{stroke:T.edgeColor,strokeWidth:1.3,opacity:.85}}});return{initNodes:j,initEdges:E,adjacency:m}},[e]),[i,r,c]=QA(l),[u,d,f]=ZA(a);b.useEffect(()=>{r(l),d(a)},[l,a,r,d]);const h=b.useCallback((S,w)=>{n(w.id)},[n]),p=b.useCallback((S,w)=>{const g=w.id,y=new Set([g,...s.get(g)??[]]);r(m=>m.map(v=>({...v,data:{...v.data,dimmed:!y.has(v.id),hovered:v.id===g}}))),d(m=>m.map(v=>({...v,style:{...v.style??{},opacity:y.has(v.source)&&y.has(v.target)?1:.05}})))},[s,r,d]),x=b.useCallback(()=>{r(S=>S.map(w=>({...w,data:{...w.data,dimmed:!1,hovered:!1}}))),d(S=>S.map(w=>({...w,style:{...w.style??{},opacity:.85}})))},[r,d]);return t?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4",style:{color:"var(--muted)"},children:[o.jsx("div",{style:{width:36,height:36,border:"2.5px solid var(--b2)",borderTopColor:"var(--gold)",borderRadius:"50%",animation:"wikiSpin 0.75s linear infinite",boxShadow:"0 0 12px rgba(224,175,104,0.35)"}}),o.jsx("span",{className:"text-[11px]",children:"Building knowledge graph…"})]}):!e||e.nodes.length===0?o.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 text-center",children:[o.jsx("div",{style:{width:56,height:56,borderRadius:"50%",background:"radial-gradient(circle at 35% 30%, var(--s3), var(--s1))",border:"1px solid var(--b1)",display:"flex",alignItems:"center",justifyContent:"center",boxShadow:"0 0 24px rgba(224,175,104,0.08)"},children:o.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--gold)",opacity:.5},children:[o.jsx("circle",{cx:"12",cy:"12",r:"2.5"}),o.jsx("circle",{cx:"4.5",cy:"4.5",r:"1.5"}),o.jsx("circle",{cx:"19.5",cy:"4.5",r:"1.5"}),o.jsx("circle",{cx:"4.5",cy:"19.5",r:"1.5"}),o.jsx("circle",{cx:"19.5",cy:"19.5",r:"1.5"}),o.jsx("line",{x1:"12",y1:"9.5",x2:"5.5",y2:"5.5"}),o.jsx("line",{x1:"12",y1:"9.5",x2:"18.5",y2:"5.5"}),o.jsx("line",{x1:"12",y1:"14.5",x2:"5.5",y2:"18.5"}),o.jsx("line",{x1:"12",y1:"14.5",x2:"18.5",y2:"18.5"})]})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[13px] font-semibold",style:{color:"var(--fg)"},children:"Graph is empty"}),o.jsx("div",{className:"text-[11px] mt-1.5",style:{color:"var(--muted)"},children:"Ingest documents to build the knowledge graph"})]}),o.jsx("div",{className:"text-[10px] font-mono px-3 py-1.5 rounded-lg",style:{background:"var(--s2)",color:"var(--muted)",border:"1px solid var(--b1)",letterSpacing:"0.02em"},children:"ingest plans/spec.md into the wiki"})]}):o.jsxs("div",{style:{width:"100%",height:"100%",position:"relative",background:"var(--bg)"},children:[o.jsxs(GA,{nodes:i,edges:u,onNodesChange:c,onEdgesChange:f,nodeTypes:ET,onNodeClick:h,onNodeMouseEnter:p,onNodeMouseLeave:x,fitView:!0,fitViewOptions:{padding:.2},colorMode:"dark",proOptions:{hideAttribution:!0},style:{background:"var(--bg)"},nodesDraggable:!0,nodesConnectable:!1,elementsSelectable:!1,children:[o.jsx(FA,{variant:In.Dots,gap:26,size:1.2,color:"var(--b1)"}),o.jsx(sT,{}),o.jsx(yT,{nodeColor:S=>ad(S.data.category).hex,maskColor:"color-mix(in srgb, var(--s1) 75%, transparent)",style:{background:"color-mix(in srgb, var(--s2) 90%, transparent)",backdropFilter:"blur(8px)",border:"1px solid color-mix(in srgb, var(--b2) 50%, transparent)",borderRadius:10,boxShadow:"0 4px 20px rgba(0,0,0,0.35)"}})]}),o.jsx("div",{style:{position:"absolute",inset:0,background:["radial-gradient(ellipse 75% 75% at 50% 50%, transparent 25%, color-mix(in srgb, var(--s1) 65%, transparent) 100%)","radial-gradient(circle at 25% 80%, rgba(224,175,104,0.03) 0%, transparent 50%)"].join(", "),pointerEvents:"none",zIndex:3}}),o.jsx("div",{style:{position:"absolute",bottom:14,left:14,zIndex:10,display:"flex",flexDirection:"column",gap:6,background:"color-mix(in srgb, var(--s2) 88%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",border:"1px solid color-mix(in srgb, var(--b2) 45%, transparent)",borderRadius:11,padding:"9px 13px",pointerEvents:"none",boxShadow:"0 4px 24px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.04)"},children:CT.map(({label:S,color:w,rgb:g})=>o.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8},children:[o.jsx("div",{style:{width:8,height:8,borderRadius:"50%",background:w,boxShadow:`0 0 6px rgba(${g},0.7)`,flexShrink:0}}),o.jsx("span",{style:{fontSize:10,color:"var(--text2)",fontFamily:"inherit",letterSpacing:"0.02em"},children:S})]},S))}),o.jsxs("div",{style:{position:"absolute",top:12,left:"50%",transform:"translateX(-50%)",zIndex:10,display:"flex",alignItems:"center",gap:8,background:"color-mix(in srgb, var(--s2) 88%, transparent)",backdropFilter:"blur(10px)",WebkitBackdropFilter:"blur(10px)",border:"1px solid color-mix(in srgb, var(--b2) 40%, transparent)",borderRadius:20,padding:"3px 12px",pointerEvents:"none",boxShadow:"0 2px 12px rgba(0,0,0,0.25)"},children:[o.jsxs("span",{style:{fontSize:10,color:"var(--text2)",fontFamily:"inherit",letterSpacing:"0.04em"},children:[o.jsx("span",{style:{color:"var(--gold)",fontWeight:600},children:e.nodes.length})," ","nodes"]}),o.jsx("div",{style:{width:1,height:10,background:"var(--b2)"}}),o.jsxs("span",{style:{fontSize:10,color:"var(--text2)",fontFamily:"inherit",letterSpacing:"0.04em"},children:[o.jsx("span",{style:{color:"var(--gold)",fontWeight:600},children:e.edges.length})," ","connections"]})]})]})}function _T({rpc:e,className:t}){const{ws:n}=Cn(),[l,a]=b.useState([]),[s,i]=b.useState(!0),[r,c]=b.useState("browse"),u=b.useRef("browse");u.current=r;const[d,f]=b.useState(null),[h,p]=b.useState(null),[x,S]=b.useState(!1),[w,g]=b.useState(""),[y,m]=b.useState([]),[v,j]=b.useState(!1),[E,M]=b.useState(null),[A,C]=b.useState(!1),[H,T]=b.useState(null),[$,V]=b.useState(null),[N,D]=b.useState(!1),k=b.useCallback(async(U=!1)=>{if(e){U||D(!0);try{const _=await e.wikiGraph();V(_??{nodes:[],edges:[]})}catch{V({nodes:[],edges:[]})}finally{U||D(!1)}}},[e]),R=b.useCallback(async(U=!1)=>{if(e){U||i(!0),T(null);try{const _=await e.wikiListPages();a((_==null?void 0:_.pages)??[])}catch(_){T(_ instanceof Error?_.message:"Failed to load wiki")}finally{U||i(!1)}}},[e]);b.useEffect(()=>{R()},[R]),b.useEffect(()=>{if(n)return n.on("wiki-op",()=>{R(!0),u.current==="graph"&&k(!0)})},[n,R,k]);const z=b.useCallback(async U=>{if(e){f(U),c("page"),S(!0),p(null);try{const _=await e.wikiPageGet(U);p((_==null?void 0:_.content)??(_==null?void 0:_.error)??"Empty page")}catch(_){p(_ instanceof Error?_.message:"Error loading page")}finally{S(!1)}}},[e]),O=b.useCallback(async()=>{if(!(!e||!w.trim())){j(!0),m([]);try{const U=await e.wikiSearch(w);m(U??[])}finally{j(!1)}}},[e,w]),Y=b.useCallback(async()=>{if(e){c("lint"),C(!0),M(null);try{const U=await e.wikiLint();M(U??{orphanPages:[],brokenLinks:[],missingFromIndex:[],staleFrontmatter:[]})}finally{C(!1)}}},[e]),X=l.reduce((U,_)=>{const B=_.category||"Other";return(U[B]??(U[B]=[])).push(_),U},{}),L=E?E.orphanPages.length+E.brokenLinks.length+E.missingFromIndex.length+E.staleFrontmatter.length:null;return o.jsxs("div",{className:`flex flex-col h-full ${t??""}`,children:[o.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",style:{color:"var(--gold)",flexShrink:0},children:[o.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),o.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"})]}),o.jsx("span",{className:"text-[13px] font-semibold font-display",style:{color:"var(--cream)"},children:"Wiki"}),o.jsxs("span",{className:"text-[11px] font-mono",style:{color:"var(--muted)"},children:[l.length," pages"]}),o.jsx("div",{className:"flex-1"}),o.jsx("button",{onClick:()=>c("browse"),className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer",style:{background:r==="browse"?"var(--s3)":"transparent",color:r==="browse"?"var(--gold)":"var(--muted)",border:r==="browse"?"1px solid var(--b2)":"1px solid transparent"},children:"Browse"}),o.jsx("button",{onClick:()=>c("search"),className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer",style:{background:r==="search"?"var(--s3)":"transparent",color:r==="search"?"var(--gold)":"var(--muted)",border:r==="search"?"1px solid var(--b2)":"1px solid transparent"},children:"Search"}),o.jsxs("button",{onClick:Y,className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer flex items-center gap-1",style:{background:r==="lint"?"var(--s3)":"transparent",color:r==="lint"?"var(--gold)":"var(--muted)",border:r==="lint"?"1px solid var(--b2)":"1px solid transparent"},children:["Lint",L!==null&&L>0&&o.jsx("span",{className:"rounded-full w-4 h-4 flex items-center justify-center text-[9px] font-bold",style:{background:"var(--red)",color:"#fff"},children:L})]}),o.jsx("button",{onClick:()=>{c("graph"),!$&&!N&&k()},className:"px-2.5 py-1 rounded-lg text-[11px] font-semibold transition-all duration-150 cursor-pointer",style:{background:r==="graph"?"var(--s3)":"transparent",color:r==="graph"?"var(--gold)":"var(--muted)",border:r==="graph"?"1px solid var(--b2)":"1px solid transparent"},children:"Graph"}),o.jsx("button",{onClick:()=>R(),className:"flex items-center justify-center w-7 h-7 rounded-lg transition-all duration-150 cursor-pointer",style:{color:"var(--muted)",border:"1px solid transparent"},title:"Refresh",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[o.jsx("polyline",{points:"23 4 23 10 17 10"}),o.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})})]}),r==="graph"&&o.jsx("div",{className:"flex-1 min-h-0",children:o.jsx(MT,{graphData:$,loading:N,onNodeClick:z})}),o.jsxs("div",{className:`flex-1 min-h-0 overflow-y-auto px-4 py-3 scrollbar-thin${r==="graph"?" hidden":""}`,children:[r==="browse"&&o.jsxs(o.Fragment,{children:[s&&o.jsx("div",{className:"flex items-center justify-center h-32 text-xs",style:{color:"var(--muted)"},children:"Loading…"}),H&&o.jsx("div",{className:"text-xs px-3 py-2 rounded-lg",style:{background:"color-mix(in srgb, var(--red) 10%, transparent)",color:"var(--red)",border:"1px solid color-mix(in srgb, var(--red) 20%, transparent)"},children:H}),!s&&!H&&l.length===0&&o.jsxs("div",{className:"flex flex-col items-center justify-center h-48 gap-3 text-center",children:[o.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",style:{color:"var(--muted)",opacity:.4},children:[o.jsx("path",{d:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20"}),o.jsx("path",{d:"M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[12px] font-semibold",style:{color:"var(--fg)"},children:"Wiki is empty"}),o.jsx("div",{className:"text-[11px] mt-1",style:{color:"var(--muted)"},children:"Ask the agent to ingest a document to get started"})]}),o.jsx("div",{className:"text-[10px] font-mono px-3 py-1.5 rounded-lg",style:{background:"var(--s2)",color:"var(--muted)",border:"1px solid var(--b1)"},children:"ingest plans/spec.md into the wiki"})]}),!s&&Object.entries(X).map(([U,_])=>o.jsxs("div",{className:"mb-4",children:[o.jsx("div",{className:"text-[10px] font-mono uppercase tracking-widest mb-1.5 px-1",style:{color:"var(--muted)"},children:U}),o.jsx("div",{className:"space-y-1",children:_.map(B=>o.jsxs("button",{onClick:()=>z(B.slug),className:"w-full text-left px-3 py-2 rounded-lg transition-all duration-150 cursor-pointer active:scale-[0.99]",style:{background:"var(--s2)",border:"1px solid var(--b1)",color:"var(--fg)"},children:[o.jsx("div",{className:"text-[12px] font-medium truncate",children:B.title||B.slug.split("/").pop()}),o.jsx("div",{className:"text-[10px] font-mono mt-0.5 truncate",style:{color:"var(--muted)"},children:B.slug})]},B.slug))})]},U))]}),r==="page"&&o.jsxs("div",{children:[o.jsxs("button",{onClick:()=>c("browse"),className:"flex items-center gap-1.5 text-[11px] mb-3 cursor-pointer transition-colors duration-100",style:{color:"var(--muted)"},children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Back to index"]}),x&&o.jsx("div",{className:"flex items-center justify-center h-32 text-xs",style:{color:"var(--muted)"},children:"Loading…"}),!x&&h!==null&&o.jsx("pre",{className:"text-[11px] leading-relaxed whitespace-pre-wrap font-mono p-3 rounded-lg overflow-auto",style:{background:"var(--s2)",color:"var(--fg)",border:"1px solid var(--b1)"},children:h})]}),r==="search"&&o.jsxs("div",{children:[o.jsxs("div",{className:"flex gap-2 mb-3",children:[o.jsx("input",{type:"text",value:w,onChange:U=>g(U.target.value),onKeyDown:U=>U.key==="Enter"&&O(),placeholder:"Search wiki pages…",className:"flex-1 px-3 py-2 rounded-lg text-[12px] outline-none",style:{background:"var(--s2)",border:"1px solid var(--b2)",color:"var(--fg)"},autoFocus:!0}),o.jsx("button",{onClick:O,disabled:v||!w.trim(),className:"px-3 py-2 rounded-lg text-[11px] font-semibold cursor-pointer transition-all duration-150 active:scale-[0.97]",style:{background:"color-mix(in srgb, var(--gold) 15%, transparent)",color:"var(--gold)",border:"1px solid color-mix(in srgb, var(--gold) 25%, transparent)",opacity:v||!w.trim()?.5:1},children:v?"…":"Search"})]}),y.length===0&&!v&&w&&o.jsxs("div",{className:"text-center py-8 text-xs",style:{color:"var(--muted)"},children:['No results for "',w,'"']}),y.length>0&&o.jsx("div",{className:"space-y-1",children:y.map((U,_)=>o.jsxs("button",{onClick:()=>z(U.slug),className:"w-full text-left px-3 py-2 rounded-lg transition-all duration-150 cursor-pointer active:scale-[0.99]",style:{background:"var(--s2)",border:"1px solid var(--b1)"},children:[o.jsxs("div",{className:"text-[11px] font-mono",style:{color:"var(--gold)"},children:[U.slug,":",U.lineNumber]}),o.jsx("div",{className:"text-[11px] mt-0.5 truncate font-mono",style:{color:"var(--fg)"},children:U.line.trim()})]},_))})]}),r==="lint"&&o.jsxs("div",{children:[A&&o.jsx("div",{className:"flex items-center justify-center h-32 text-xs",style:{color:"var(--muted)"},children:"Running lint…"}),!A&&E&&o.jsxs("div",{className:"space-y-4",children:[L===0&&o.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"color-mix(in srgb, var(--green) 10%, transparent)",color:"var(--green)",border:"1px solid color-mix(in srgb, var(--green) 20%, transparent)"},children:[o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("polyline",{points:"20 6 9 17 4 12"})}),"Wiki looks clean — no issues found"]}),o.jsx(Gr,{title:"Orphan pages",items:E.orphanPages,color:"var(--yellow)",note:"Written but not linked from any other page"}),o.jsx(Gr,{title:"Broken links",items:E.brokenLinks.map(U=>`${U.from} → [[${U.to}]]`),color:"var(--red)",note:"[[wikilinks]] that reference missing pages"}),o.jsx(Gr,{title:"Missing from index",items:E.missingFromIndex,color:"var(--yellow)",note:"Pages not listed in index.md"}),o.jsx(Gr,{title:"Stale frontmatter",items:E.staleFrontmatter,color:"var(--muted)",note:"updated: field older than 30 days"})]})]})]})]})}function Gr({title:e,items:t,color:n,note:l}){return t.length===0?null:o.jsxs("div",{children:[o.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[o.jsx("span",{className:"text-[11px] font-semibold",style:{color:n},children:e}),o.jsx("span",{className:"rounded-full px-1.5 py-0.5 text-[9px] font-bold font-mono",style:{background:`color-mix(in srgb, ${n} 15%, transparent)`,color:n},children:t.length})]}),o.jsx("div",{className:"text-[10px] mb-2",style:{color:"var(--muted)"},children:l}),o.jsx("div",{className:"space-y-1",children:t.map((a,s)=>o.jsx("div",{className:"px-3 py-1.5 rounded-lg text-[11px] font-mono truncate",style:{background:"var(--s2)",color:"var(--fg)",border:"1px solid var(--b1)"},children:a},s))})]})}const Nx=[["/status","Show version, model, provider, tokens, CWD"],["/help","List all available commands"],["/model [name]","Switch model · opus / sonnet / haiku / gpt4o"],["/mode <mode>","Set approval mode · plan|edit|auto|yolo"],["/theme [name]","Change color theme"],["/debug [on|off]","Toggle debug logging"],["/effort [level]","Set reasoning effort · low|medium|high|max"],["/context","Show context window usage grid"],["/context compact","Compact the context window"],["/context auto","Configure auto-compaction"],["/memory status","View memory file sizes"],["/memory add","Capture a memory"],["/wiki","Open the wiki knowledge base"],["/wiki list","List all wiki pages by category"],["/wiki search <query>","Search wiki pages"],["/wiki lint","Run wiki health check"],["/heartbeat now","Trigger heartbeat immediately"],["/heartbeat enable","Enable heartbeat schedule"],["/remind <msg at time>","Create a reminder"],["/cron list","List all reminders"],["/channels list","Show Telegram channels"],["/mcp list","Show MCP servers"],["/mcp add","Add an MCP server"],["/tools [n]","View/set tool call limit per turn"],["/websearch [n]","Set web search limit per turn"],["/snapshots","List git snapshots"],["/revert","Revert to a snapshot"],["/stats","View usage stats"],["/agent <prompt>","Spawn a subagent"],["/task create","Create a scheduled task"],["/provider <name>","Switch AI provider"],["/init","Run interactive setup wizard"],["/exit","Exit curie-agent"]];function AT({open:e,onClose:t,onPick:n}){const[l,a]=b.useState(""),[s,i]=b.useState(0),r=b.useRef(null),c=l?Nx.filter(([f,h])=>f.includes(l.toLowerCase())||h.toLowerCase().includes(l.toLowerCase())):Nx,u=b.useCallback(f=>{t(),n(f)},[t,n]);b.useEffect(()=>{e&&(a(""),i(0),setTimeout(()=>{var f;return(f=r.current)==null?void 0:f.focus()},50))},[e]);const d=b.useCallback(f=>{if(f.key==="Escape"){t();return}f.key==="ArrowDown"&&(i(h=>Math.min(h+1,c.length-1)),f.preventDefault()),f.key==="ArrowUp"&&(i(h=>Math.max(h-1,0)),f.preventDefault()),f.key==="Enter"&&c[s]&&u(c[s][0])},[c,s,t,u]);return e?o.jsx("div",{className:"fixed inset-0 z-50 flex items-start justify-center pt-[120px]",style:{background:"rgba(10, 8, 5, 0.85)",backdropFilter:"blur(8px)"},onClick:t,children:o.jsxs("div",{className:"w-[560px] rounded-xl overflow-hidden animate-scaleIn",style:{background:"linear-gradient(135deg, var(--s2) 0%, var(--s1) 100%)",border:"1px solid var(--b2)",boxShadow:"0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.03)"},onClick:f=>f.stopPropagation(),children:[o.jsxs("div",{className:"flex items-center gap-2 px-4 py-3",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"var(--gold)",strokeWidth:"1.5",className:"shrink-0",style:{opacity:.7},children:[o.jsx("circle",{cx:"11",cy:"11",r:"8"}),o.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),o.jsx("input",{ref:r,className:"flex-1 bg-transparent border-0 outline-none font-sans text-sm",style:{color:"var(--cream)"},placeholder:"Search commands...",value:l,onChange:f=>{a(f.target.value),i(0)},onKeyDown:d})]}),o.jsx("div",{className:"gold-divider"}),o.jsxs("div",{className:"max-h-[340px] overflow-y-auto py-1 scrollbar-thin",children:[c.map(([f,h],p)=>o.jsxs("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-lg cursor-pointer transition-all duration-150 mx-1",style:{background:p===s?"var(--s3)":"transparent",borderLeft:p===s?"2px solid var(--gold)":"2px solid transparent"},onClick:()=>u(f),children:[o.jsx("span",{className:"font-mono text-[12.5px] min-w-[190px]",style:{color:p===s?"var(--gold)":"var(--text)"},children:f}),o.jsx("span",{className:"text-xs text-muted truncate",children:h})]},f)),c.length===0&&o.jsx("div",{className:"px-3 py-6 text-center text-muted text-sm",children:"No commands found"})]})]})}):null}const ka={anthropic:{label:"Anthropic",defaultModel:"claude-sonnet-4-6",requiresKey:!0},openai:{label:"OpenAI",defaultModel:"gpt-4o",requiresKey:!0},local:{label:"Local (OpenAI-compatible)",defaultModel:"custom",requiresKey:!1},openrouter:{label:"OpenRouter",defaultModel:"anthropic/claude-sonnet-4-6",requiresKey:!0},ollama:{label:"Ollama (Local)",defaultModel:"custom",requiresKey:!1}};function TT({rpc:e,onComplete:t,className:n}){const[l,a]=b.useState("provider"),[s,i]=b.useState(null),[r,c]=b.useState(""),[u,d]=b.useState(""),[f,h]=b.useState(""),[p,x]=b.useState(""),[S,w]=b.useState(""),[g,y]=b.useState(""),[m,v]=b.useState(""),[j,E]=b.useState(!1),[M,A]=b.useState(null),C=b.useCallback(()=>{switch(A(null),l){case"provider":{if(!s)return;const N=ka[s];d(N.defaultModel),a(N.requiresKey?"api_key":"model");break}case"api_key":a("model");break;case"model":a("soul_name");break;case"soul_name":if(!f.trim())return;a("soul_vibe");break;case"soul_vibe":a("user_name");break;case"user_name":if(!S.trim())return;a("user_tz");break;case"user_tz":a("user_lang");break;case"user_lang":a("agents");break;case"agents":a("memory");break;case"memory":a("tools");break;case"tools":a("confirm");break}},[l,s,f,S]),H=b.useCallback(async()=>{if(!(!e||!s)){E(!0),A(null);try{await e.identitySetup({provider:s,apiKey:r,model:u,soulName:f.trim()||"Curie",soulVibe:p.trim()||"AI coding assistant — sharp, resourceful, gets things done",userName:S.trim()||"User",userTimezone:g.trim()||"UTC",userLanguages:m.trim()||"TypeScript, Python"}),t()}catch(N){A(N instanceof Error?N.message:"Setup failed")}finally{E(!1)}}},[e,s,r,u,f,p,S,g,m,t]),T=()=>{switch(l){case"provider":return"Choose your provider";case"api_key":return"API key";case"model":return"Select a model";case"soul_name":return"Name your assistant";case"soul_vibe":return"Define the vibe";case"user_name":return"Your name";case"user_tz":return"Timezone";case"user_lang":return"Programming languages";case"agents":return"Workspace configuration";case"memory":return"Memory";case"tools":return"Tools";case"confirm":return"Review & create"}},$=()=>(["provider","api_key","model","soul_name","soul_vibe","user_name","user_tz","user_lang","agents","memory","tools","confirm"].indexOf(l)+1)/12,V=()=>{switch(l){case"provider":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted mb-4",children:"Which LLM provider do you want to use for your AI assistant?"}),o.jsx("div",{className:"grid grid-cols-1 gap-2",children:Object.entries(ka).map(([N,D])=>o.jsxs("button",{type:"button",onClick:()=>i(N),className:`flex items-center gap-3 px-4 py-3 rounded-xl border text-left transition-all duration-100 ${s===N?"border-blue-500 bg-blue-500/10 text-text":"border-b2 bg-s2 text-text hover:border-b3 hover:bg-s2/80"}`,children:[o.jsx("div",{className:`w-4 h-4 rounded-full border-2 flex items-center justify-center shrink-0 ${s===N?"border-blue-500":"border-b3"}`,children:s===N&&o.jsx("div",{className:"w-2 h-2 rounded-full bg-blue-500"})}),o.jsxs("div",{children:[o.jsx("div",{className:"text-xs font-medium text-text",children:D.label}),o.jsxs("div",{className:"text-[10.5px] text-muted",children:["Model: ",D.defaultModel]})]})]},N))})]});case"api_key":{const N=ka[s];return o.jsxs("div",{className:"space-y-3",children:[o.jsxs("p",{className:"text-xs text-muted",children:["Enter your ",N.label," API key:"]}),o.jsx("input",{type:"password",value:r,onChange:D=>c(D.target.value),placeholder:"sk-...",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text font-mono placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0}),o.jsx("p",{className:"text-[10px] text-muted",children:"Saved to ~/.curie-settings.json"})]})}case"model":{const N=ka[s];return o.jsxs("div",{className:"space-y-3",children:[o.jsxs("p",{className:"text-xs text-muted",children:["Suggested model: ",o.jsx("code",{className:"text-text font-mono",children:N.defaultModel})]}),o.jsx("input",{type:"text",value:u,onChange:D=>d(D.target.value),placeholder:"Enter model name or accept the default",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text font-mono placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]})}case"soul_name":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"What should your AI assistant's name be?"}),o.jsx("input",{type:"text",value:f,onChange:N=>h(N.target.value),placeholder:"Curie",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"soul_vibe":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Describe your assistant's vibe/personality (1 sentence)."}),o.jsx("input",{type:"text",value:p,onChange:N=>x(N.target.value),placeholder:"AI coding assistant — sharp, resourceful, gets things done",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"user_name":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"What is your name?"}),o.jsx("input",{type:"text",value:S,onChange:N=>w(N.target.value),placeholder:"Paweł",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"user_tz":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Your timezone?"}),o.jsx("input",{type:"text",value:g,onChange:N=>y(N.target.value),placeholder:"Europe/Warsaw",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text font-mono placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"user_lang":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Your primary programming languages?"}),o.jsx("input",{type:"text",value:m,onChange:N=>v(N.target.value),placeholder:"TypeScript, Python",className:"w-full px-3 py-2.5 bg-[#0d1117] border border-b2 rounded-xl text-xs text-text placeholder-slate-600 focus:outline-none focus:border-blue-500/70 transition-colors",autoFocus:!0})]});case"agents":return o.jsxs("div",{className:"space-y-3",children:[o.jsx("p",{className:"text-xs text-muted",children:"Next: I'll create your workspace configuration files."}),o.jsxs("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-[10.5px] text-text leading-relaxed",children:[o.jsx("p",{className:"font-medium mb-1",children:"AGENTS.md will include:"}),o.jsxs("ul",{className:"list-disc list-inside space-y-0.5 text-muted",children:[o.jsx("li",{children:"Session startup instructions"}),o.jsx("li",{children:"Memory system (daily notes + long-term)"}),o.jsx("li",{children:"Coding agent capabilities"}),o.jsx("li",{children:"Red lines and safety boundaries"}),o.jsx("li",{children:"Heartbeat configuration"})]})]})]});case"memory":return o.jsx("div",{className:"space-y-3",children:o.jsx("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-xs text-text leading-relaxed",children:o.jsx("p",{children:"Auto-creating MEMORY.md with initialization entry..."})})});case"tools":return o.jsx("div",{className:"space-y-3",children:o.jsx("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-xs text-text leading-relaxed",children:o.jsx("p",{children:"Auto-creating TOOLS.md and HEARTBEAT.md..."})})});case"confirm":return o.jsxs("div",{className:"space-y-4",children:[o.jsx("p",{className:"text-xs text-muted",children:"Review your configuration before creating files:"}),o.jsxs("div",{className:"space-y-2",children:[o.jsx(cl,{label:"Provider",value:ka[s].label}),o.jsx(cl,{label:"Model",value:u}),o.jsx(cl,{label:"API Key",value:r?"[set]":"(not set)"}),o.jsx(cl,{label:"Assistant Name",value:f.trim()||"Curie"}),o.jsx(cl,{label:"Vibe",value:p.trim()||"AI coding assistant"}),o.jsx(cl,{label:"Your Name",value:S.trim()||"User"}),o.jsx(cl,{label:"Timezone",value:g.trim()||"UTC"}),o.jsx(cl,{label:"Languages",value:m.trim()||"TypeScript, Python"})]}),o.jsxs("div",{className:"p-3 bg-s2 border border-b1 rounded-xl text-[10.5px] text-muted leading-relaxed",children:["Identity files to be created:",o.jsxs("ul",{className:"list-disc list-inside mt-1",children:[o.jsx("li",{children:"~/.curie-agent/SOUL.md"}),o.jsx("li",{children:"~/.curie-agent/USER.md"}),o.jsx("li",{children:"~/.curie-agent/AGENTS.md"}),o.jsx("li",{children:"~/.curie-agent/MEMORY.md"}),o.jsx("li",{children:"~/.curie-agent/TOOLS.md"}),o.jsx("li",{children:"~/.curie-agent/HEARTBEAT.md"})]})]})]})}};return o.jsx("div",{className:`flex-1 overflow-y-auto p-7 scrollbar-thin flex flex-col ${n||""}`,children:o.jsxs("div",{className:"max-w-lg mx-auto w-full",children:[o.jsxs("div",{className:"mb-6",children:[o.jsx("h2",{className:"text-base font-semibold text-fg tracking-tight mb-1",children:"Setup Wizard"}),o.jsx("p",{className:"text-[11px] text-muted",children:"Configure your AI assistant — takes about 2 minutes"})]}),o.jsx("div",{className:"mb-5",children:o.jsx("div",{className:"h-1 bg-b2 rounded-full overflow-hidden",children:o.jsx("div",{className:"h-full bg-blue-500 rounded-full transition-all duration-300",style:{width:`${$()*100}%`}})})}),o.jsx("h3",{className:"text-sm font-medium text-text mb-4",children:T()}),o.jsx("div",{className:"mb-6",children:V()}),M&&o.jsxs("div",{className:"p-3 bg-red-500/10 border border-red-500/20 rounded-xl text-red-400 text-xs flex items-start gap-2.5 mb-4",children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"shrink-0 mt-0.5",children:[o.jsx("circle",{cx:"12",cy:"12",r:"10"}),o.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),o.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),o.jsx("span",{children:M})]}),o.jsxs("div",{className:"flex items-center justify-between gap-3",children:[l!=="provider"&&l!=="confirm"?o.jsxs("button",{type:"button",onClick:()=>{switch(A(null),l){case"api_key":a("provider");break;case"model":a(ka[s].requiresKey?"api_key":"provider");break;case"soul_name":a("provider");break;case"soul_vibe":a("soul_name");break;case"user_name":a("soul_vibe");break;case"user_tz":a("user_name");break;case"user_lang":a("user_tz");break;case"agents":a("user_lang");break;case"memory":a("agents");break;case"tools":a("memory");break}},className:"flex items-center gap-1 bg-transparent border border-b2 rounded px-3 py-2 text-muted text-xs hover:border-b3 hover:text-fg transition-colors duration-100",children:[o.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:o.jsx("polyline",{points:"15 18 9 12 15 6"})}),"Back"]}):o.jsx("div",{}),l==="confirm"?o.jsx("button",{type:"button",onClick:H,disabled:j,className:"flex items-center gap-2 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white font-semibold text-xs px-5 py-2 rounded-xl shadow-lg shadow-blue-500/10 disabled:opacity-50 disabled:pointer-events-none active:scale-[0.98] transition-all duration-150",children:j?o.jsxs(o.Fragment,{children:[o.jsxs("svg",{className:"animate-spin h-3.5 w-3.5 text-white",fill:"none",viewBox:"0 0 24 24",children:[o.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),o.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]}),"Creating..."]}):"Create Setup"}):o.jsxs("button",{type:"button",onClick:C,disabled:l==="provider"&&!s||l==="soul_name"&&!f.trim()||l==="user_name"&&!S.trim(),className:"flex items-center gap-2 bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white font-semibold text-xs px-5 py-2 rounded-xl shadow-lg shadow-blue-500/10 disabled:opacity-50 disabled:pointer-events-none active:scale-[0.98] transition-all duration-150",children:["Next",o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),o.jsx("polyline",{points:"12 5 19 12 12 19"})]})]})]})]})})}function cl({label:e,value:t}){return o.jsxs("div",{className:"flex items-center justify-between px-3 py-2 border-b border-b1/50",children:[o.jsx("span",{className:"text-[10.5px] text-muted",children:e}),o.jsx("span",{className:"text-[10.5px] text-text font-mono",children:t})]})}function zT({onReload:e}){const[t,n]=b.useState(!1);b.useEffect(()=>{const a=()=>n(!0),s=()=>{n(!1),e==null||e()};return window.addEventListener("pwa-update-available",a),window.addEventListener("pwa-controller-updated",s),()=>{window.removeEventListener("pwa-update-available",a),window.removeEventListener("pwa-controller-updated",s)}},[e]);const l=()=>{n(!1),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then(a=>{a.waiting&&a.waiting.postMessage("SKIP_WAITING")}),window._pendingUpdateWorker&&window._pendingUpdateWorker.postMessage("SKIP_WAITING")};return t?o.jsxs("div",{className:"bg-blue-500/10 border-b border-blue-500/20 text-blue-400 px-4 py-2 text-center text-xs font-semibold flex items-center justify-center gap-2 select-none shrink-0 z-50 animate-fadeIn",children:[o.jsxs("svg",{className:"animate-bounce shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),o.jsx("polyline",{points:"17 8 12 3 7 8"}),o.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]}),"Update available",o.jsx("button",{onClick:l,className:"bg-blue-500/20 border border-blue-500/40 text-blue-400 px-2 py-0.5 rounded-[4px] text-[11px] font-bold cursor-pointer hover:bg-blue-500/30 transition-all duration-100",children:"Update"})]}):null}const DT="0.2.4";function RT({intervalMs:e=3*60*1e3,onNewVersion:t}){const[n,l]=b.useState(!1);return b.useEffect(()=>{async function a(){var i;try{const c=await(await fetch("/health?token="+encodeURIComponent(((i=document.cookie.match(/curie_token=([^;]*)/))==null?void 0:i[1])??""),{cache:"no-store"})).json();c.version&&c.version!==DT&&!n&&(l(!0),t==null||t(c.version),window.dispatchEvent(new CustomEvent("pwa-version-update")))}catch{}}a();const s=setInterval(a,e);return()=>clearInterval(s)},[e,n,t]),null}function OT(){const{rpc:e,ws:t}=Cn(),[n,l]=b.useState([]),a=b.useCallback(()=>{e&&e.sessionList().then(s=>{Array.isArray(s)&&l(s)}).catch(()=>{})},[e]);return b.useEffect(()=>{a()},[a]),b.useEffect(()=>{if(!t)return;const s=["user-prompt","assistant-stop","error","session-start","session-resumed"],i=[];for(const r of s)i.push(t.on(r,a));return()=>{for(const r of i)r()}},[t,a]),{sessions:n,refetch:a}}function HT(e){const{rpc:t,ws:n}=Cn(),[l,a]=b.useState(null),[s,i]=b.useState([]),[r,c]=b.useState(!1);b.useEffect(()=>{if(!t||!e){a(null),i([]),c(!1);return}c(!0),t.sessionGet(e).then(d=>{d!=null&&d.info&&a(d.info),d!=null&&d.events&&i(d.events)}).catch(()=>{}).finally(()=>c(!1))},[t,e]),b.useEffect(()=>{if(!n||!e)return;const d=p=>{if(p.type!=="heartbeat-brief"&&p.type!=="cron-task-fired"){const x=p.sessionId||p.id;if(x&&x!==e)return}i(x=>x.slice(-10).some(w=>w.timestamp===p.timestamp&&w.type===p.type&&JSON.stringify(w)===JSON.stringify(p))?x:[...x,p])},f=[],h=["user-prompt","assistant-delta","assistant-stop","tool-call","tool-result","error","status","usage","thinking-delta","heartbeat-brief","approval-request","approval-decision","context-warning","cron-task-fired"];for(const p of h)f.push(n.on(p,d));return()=>{for(const p of f)p()}},[n,e]);const u=b.useCallback(d=>{i(f=>[...f,d])},[]);return{info:l,events:s,loading:r,addLiveEvent:u}}function LT({onAuthorize:e}){const[t,n]=b.useState(""),[l,a]=b.useState(!1),[s,i]=b.useState(null),r=async c=>{if(c.preventDefault(),!!t.trim()){a(!0),i(null);try{(await fetch("/health",{headers:{Authorization:`Bearer ${t.trim()}`}})).ok?e(t.trim()):i("Invalid Access Token. Please verify and try again.")}catch{i("Cannot connect to Curie Daemon. Make sure the daemon is running.")}finally{a(!1)}}};return o.jsxs("div",{className:"flex min-h-screen w-screen items-center justify-center p-4 font-sans select-none relative overflow-hidden",style:{background:"#0e0b08",color:"var(--cream, #f5e6d0)"},children:[o.jsx("div",{className:"absolute top-[-20%] left-[-20%] w-[60%] h-[60%] rounded-full opacity-30 blur-[120px] pointer-events-none",style:{background:"#2d1f0e"}}),o.jsx("div",{className:"absolute bottom-[-20%] right-[-20%] w-[60%] h-[60%] rounded-full opacity-25 blur-[120px] pointer-events-none",style:{background:"#1e1408"}}),o.jsx("div",{className:"absolute top-[40%] left-[50%] w-[40%] h-[40%] rounded-full opacity-15 blur-[100px] pointer-events-none",style:{background:"#d4a54a",transform:"translate(-50%, -50%)"}}),o.jsxs("div",{className:"w-full max-w-[440px] rounded-2xl shadow-2xl p-7 flex flex-col items-center animate-scaleIn relative z-10",style:{background:"linear-gradient(135deg, rgba(34, 28, 22, 0.95), rgba(20, 16, 12, 0.98))",backdropFilter:"blur(24px)",border:"1px solid rgba(86, 72, 58, 0.5)",boxShadow:"0 20px 60px rgba(0,0,0,0.5), inset 0 1px 0 rgba(245,230,208,0.04)"},children:[o.jsx("div",{className:"absolute top-0 left-0 right-0 h-[2px] rounded-t-2xl",style:{background:"linear-gradient(90deg, transparent, #d4a54a, transparent)"}}),o.jsxs("div",{className:"flex flex-col items-center gap-3 mb-6 mt-2",children:[o.jsxs("div",{className:"relative group",children:[o.jsx("div",{className:"absolute inset-0 rounded-xl blur-md group-hover:blur-lg transition-all duration-300 animate-gold-pulse",style:{background:"rgba(212, 165, 74, 0.2)"}}),o.jsx("img",{src:"/icons/logo-512.png",alt:"Curie Logo",className:"w-14 h-14 object-contain rounded-xl relative z-10 transform group-hover:scale-105 transition-transform duration-300",style:{border:"1px solid rgba(86, 72, 58, 0.6)",boxShadow:"0 4px 16px rgba(0,0,0,0.4)"}})]}),o.jsxs("div",{className:"text-center mt-1",children:[o.jsx("span",{className:"text-xl font-display font-bold gold-shimmer block",children:"curie-agent"}),o.jsx("span",{className:"text-[10px] font-mono block mt-0.5",style:{color:"#d4a54a",opacity:.6},children:"v0.2.4"})]})]}),o.jsxs("div",{className:"text-center mb-6",children:[o.jsx("h2",{className:"text-sm font-semibold mb-2",style:{color:"#f5e6d0"},children:"Authorize this device"}),o.jsx("p",{className:"text-[12.5px] leading-relaxed px-2",style:{color:"#8b7355"},children:"Curie requires a secure daemon connection. Enter your access token below to authorize this device and start planning."})]}),o.jsxs("form",{onSubmit:r,className:"w-full space-y-4",children:[o.jsxs("div",{className:"space-y-1.5",children:[o.jsx("label",{className:"text-[10px] font-semibold uppercase tracking-wider block ml-1",style:{color:"#d4a54a",opacity:.7},children:"Daemon Access Token"}),o.jsxs("div",{className:"relative group",children:[o.jsx("div",{className:"absolute inset-y-0 left-0 pl-3.5 flex items-center pointer-events-none transition-colors duration-200",style:{color:"#8b7355"},children:o.jsx("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("path",{d:"M21 2l-2 2m-7.61 7.61a5.5 5.5 0 1 1-7.778 7.778 5.5 5.5 0 0 1 7.777-7.777zm0 0L15.5 7.5m0 0l3 3L22 7l-3-3m-3.5 3.5L19 4"})})}),o.jsx("input",{type:"password",required:!0,placeholder:"Paste your daemon.token...",value:t,onChange:c=>n(c.target.value),disabled:l,className:"w-full pl-10 pr-4 py-2.5 rounded-xl text-[13px] font-mono focus:outline-none transition-all duration-200",style:{background:"rgba(14, 11, 8, 0.8)",border:"1px solid rgba(86, 72, 58, 0.4)",color:"#f5e6d0"}})]})]}),s&&o.jsxs("div",{className:"p-3 rounded-xl text-xs flex items-start gap-2.5 animate-fadeIn",style:{background:"color-mix(in srgb, var(--red) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--red) 20%, transparent)",color:"var(--red)"},children:[o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"shrink-0 mt-0.5",children:[o.jsx("circle",{cx:"12",cy:"12",r:"10"}),o.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),o.jsx("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),o.jsx("span",{children:s})]}),o.jsx("button",{type:"submit",disabled:l||!t.trim(),className:"btn-gold w-full py-2.5 px-4 rounded-xl font-semibold text-xs active:scale-[0.98] transition-all duration-150 disabled:opacity-50 disabled:pointer-events-none cursor-pointer flex items-center justify-center gap-2",children:l?o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"w-3.5 h-3.5 rounded-full animate-spin",style:{background:"conic-gradient(from 0deg, transparent, #1a1410)",mask:"radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 0)",WebkitMask:"radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 0)"}}),"Verifying Credentials..."]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"Authorize & Connect"}),o.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"}),o.jsx("polyline",{points:"12 5 19 12 12 19"})]})]})})]}),o.jsxs("div",{className:"w-full mt-6 pt-5 space-y-2 leading-relaxed",style:{borderTop:"1px solid rgba(86, 72, 58, 0.3)",fontSize:"11.5px",color:"#8b7355"},children:[o.jsx("div",{className:"font-semibold",style:{color:"#bfae94"},children:"Where is my token?"}),o.jsx("p",{children:"When starting the daemon, look for the console output in your terminal. It displays the dashboard link containing the secure token."}),o.jsxs("p",{children:["You can also find the raw token inside the file ",o.jsx("code",{className:"font-mono px-1 py-0.5 rounded text-[10.5px]",style:{background:"rgba(14, 11, 8, 0.6)",border:"1px solid rgba(86, 72, 58, 0.3)",color:"#d4c4a8"},children:"~/.curie-agent/daemon.token"})," on your host machine."]})]})]})]})}const $T=["plan","edit","auto","yolo"],BT=[{view:"assistant",label:"Assistant",icon:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"},{view:"channels",label:"Channels",icon:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07A19.5 19.5 0 0 1 4.86 13a19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 3.77 2h3a2 2 0 0 1 2 1.72c.127.96.361 1.903.7 2.81a2 2 0 0 1-.45 2.11L7.91 9.91a16 16 0 0 0 6.16 6.16l1.27-1.27a2 2 0 0 1 2.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0 1 22 16.92z"},{view:"stats",label:"Stats",icon:"M18 20V10M12 20V4M6 20v-6"},{view:"projects",label:"Projects",icon:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"},{view:"agents",label:"Agents",icon:"M12 8c0 2.21-1.79 4-4 4s-4-1.79-4-4 1.79-4 4-4 4 1.79 4 4zm-6 12v-2a6 6 0 0 1 12 0v2"},{view:"kanban",label:"Tasks",icon:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"},{view:"wiki",label:"Wiki",icon:"M4 19.5A2.5 2.5 0 0 1 6.5 17H20M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z"},{view:"settings",label:"Settings",icon:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z"}];function UT(){const{rpc:e,connected:t,token:n,setToken:l}=Cn(),{get:a,set:s,providers:i}=kh(),[r,c]=b.useState("assistant"),u=a("mode")||"auto",[d,f]=b.useState(!1),[h,p]=b.useState(""),[x,S]=b.useState(null),[w,g]=b.useState(!1),[y,m]=b.useState(null),[v,j]=b.useState(navigator.onLine),[E,M]=b.useState(!1),[A,C]=b.useState(!1),[H,T]=b.useState(!1),[$,V]=b.useState(!1),N=/iPad|iPhone|iPod/.test(navigator.userAgent)||navigator.platform==="MacIntel"&&navigator.maxTouchPoints>1;b.useEffect(()=>{const q=window.matchMedia("(display-mode: standalone)").matches||window.navigator.standalone===!0;M(!!q)},[]),b.useEffect(()=>{const q=W=>{W.preventDefault(),m(W)},Q=()=>j(!0),K=()=>j(!1);return window.addEventListener("beforeinstallprompt",q),window.addEventListener("online",Q),window.addEventListener("offline",K),()=>{window.removeEventListener("beforeinstallprompt",q),window.removeEventListener("online",Q),window.removeEventListener("offline",K)}},[]);const D=async()=>{if(y){y.prompt();const{outcome:q}=await y.userChoice;console.log(`PWA install prompt choice: ${q}`),m(null)}else C(!0)},{sessions:k,refetch:R}=OT(),{events:z,addLiveEvent:O}=HT(x),Y=a("theme")||"curie";b.useEffect(()=>{document.documentElement.setAttribute("data-theme",Y)},[Y]),b.useEffect(()=>{const q=()=>g(window.innerWidth<768);return q(),window.addEventListener("resize",q),()=>window.removeEventListener("resize",q)},[]),b.useEffect(()=>{!t||!e||e.configGet("current_provider").then(q=>{q||T(!0)}).catch(()=>{})},[t,e]);const X=b.useCallback(()=>{S(null)},[]),L=b.useCallback(q=>{S(q)},[]),U=b.useCallback(q=>{S(q),R()},[R]);b.useEffect(()=>{const q=Q=>{(Q.metaKey||Q.ctrlKey)&&Q.key==="k"&&(Q.preventDefault(),f(!0))};return document.addEventListener("keydown",q),()=>document.removeEventListener("keydown",q)},[]);const _=b.useCallback(q=>{p(q),f(!1)},[]),B=b.useCallback(()=>{p("")},[]),G=(q,Q=18)=>o.jsx("svg",{width:Q,height:Q,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:o.jsx("path",{d:q.icon})});return n?o.jsxs("div",{className:"flex h-dvh w-screen flex-col overflow-hidden bg-bg coffee-pattern",children:[!v&&o.jsxs("div",{className:"px-4 py-2 text-center text-xs font-semibold flex items-center justify-center gap-2 select-none shrink-0 z-50 animate-fadeIn",style:{background:"color-mix(in srgb, var(--yellow) 10%, transparent)",borderBottom:"1px solid color-mix(in srgb, var(--yellow) 20%, transparent)",color:"var(--yellow)"},children:[o.jsxs("svg",{className:"animate-pulse shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),o.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),o.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]}),"Offline Mode — Curie is running on cached local client"]}),o.jsx(zT,{}),o.jsx(RT,{}),o.jsxs("main",{className:"flex flex-1 flex-col overflow-hidden bg-bg",children:[o.jsxs("div",{className:"topbar-wood flex h-12 items-center gap-3 px-4 shrink-0",children:[o.jsxs("div",{className:"flex items-center gap-1.5",children:[o.jsxs("button",{className:"relative flex items-center justify-center w-8 h-8 rounded-lg transition-all duration-150",style:{color:$?"var(--fg)":"var(--muted)",background:$?"var(--s3)":"transparent",border:$?"1px solid var(--b1)":"1px solid transparent"},onClick:()=>V(!0),title:"Sessions",children:[o.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:o.jsx("path",{d:"M8 6h13M8 12h13M8 18h13M3 6h.01M3 12h.01M3 18h.01"})}),k.length>0&&o.jsx("span",{className:"absolute -top-0.5 -right-0.5 text-[9px] font-bold rounded-full w-4 h-4 flex items-center justify-center",style:{background:"var(--gold)",color:"#1a1410"},children:k.length>99?"99+":k.length})]}),o.jsx("div",{className:"w-px h-5 bg-b1 mx-0.5"}),BT.map(q=>o.jsx("button",{className:"flex items-center justify-center w-8 h-8 rounded-lg transition-all duration-150 cursor-pointer",style:{color:r===q.view?"var(--gold)":"var(--muted)",background:r===q.view?"var(--s3)":"transparent",border:r===q.view?"1px solid var(--b1)":"1px solid transparent"},onClick:()=>c(q.view),title:q.label,children:G(q,18)},q.view))]}),o.jsx("div",{className:"flex-1"}),window.innerWidth>=640&&o.jsx("div",{className:"flex rounded-lg overflow-hidden",style:{border:"1px solid var(--b2)",background:"var(--bg)"},children:$T.map(q=>o.jsx("button",{className:"px-2.5 py-1 text-xs cursor-pointer transition-all duration-150 font-mono select-none",style:{color:u===q?"var(--gold)":"var(--muted)",background:u===q?"var(--s3)":"transparent",borderRight:"1px solid var(--b1)"},onClick:()=>s("mode",q),children:q},q))}),(y||w&&!E)&&o.jsxs("button",{onClick:D,className:"flex items-center justify-center rounded-lg transition-all duration-150 px-2.5 py-1 gap-1.5 text-xs font-semibold cursor-pointer shrink-0",style:{background:"var(--bg)",border:"1px solid color-mix(in srgb, var(--green) 30%, transparent)",color:"var(--green)"},children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),o.jsx("polyline",{points:"7 10 12 15 17 10"}),o.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]}),!w&&o.jsx(o.Fragment,{children:"Install"})]}),o.jsxs("button",{className:"flex items-center justify-center rounded-lg transition-all duration-150 px-2.5 py-1 gap-1.5 text-xs font-semibold cursor-pointer shrink-0",style:{background:"transparent",border:"1px solid var(--b2)",color:"var(--muted)"},onClick:()=>f(!0),title:"Open Commands",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[o.jsx("circle",{cx:"11",cy:"11",r:"8"}),o.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),!w&&o.jsx(o.Fragment,{children:"Ctrl+k"})]})]}),o.jsxs("div",{className:"relative flex-1 min-h-0",children:[H&&e?o.jsx(TT,{rpc:e,onComplete:()=>T(!1),className:"absolute inset-0"}):r==="assistant"&&o.jsx(Zj,{cmdResult:h,onClearCmdResult:B,rpc:e,className:"absolute inset-0",activeSessionId:x,onCreateSession:U,events:z,addLiveEvent:O,onSwitchView:q=>c(q)}),r==="channels"&&o.jsx(Ij,{rpc:e,className:"absolute inset-0"}),r==="stats"&&o.jsx(Kj,{rpc:e,className:"absolute inset-0"}),r==="projects"&&o.jsx(Wj,{rpc:e,className:"absolute inset-0"}),r==="agents"&&o.jsx(Pj,{rpc:e,className:"absolute inset-0"}),r==="kanban"&&o.jsx(t3,{rpc:e,className:"absolute inset-0"}),r==="wiki"&&o.jsx(_T,{rpc:e,className:"absolute inset-0"}),r==="settings"&&o.jsx("div",{className:"absolute inset-0 flex items-center justify-center text-muted text-xs",children:"Settings view — coming soon"})]})]}),o.jsx(AT,{open:d,onClose:()=>f(!1),onPick:_}),$&&o.jsx("div",{className:"fixed inset-0 z-[998] flex items-end animate-fadeIn",style:{background:"rgba(10, 8, 5, 0.6)",backdropFilter:"blur(4px)"},onClick:()=>V(!1),children:o.jsxs("div",{className:"w-full max-h-[70vh] rounded-t-2xl overflow-hidden animate-slideUp select-none flex flex-col wood-grain",style:{background:"var(--s1)",borderTop:"1px solid var(--b1)"},onClick:q=>q.stopPropagation(),children:[o.jsx("div",{className:"flex justify-center pt-3 pb-1 shrink-0",children:o.jsx("div",{className:"w-8 h-1 rounded-full",style:{background:"var(--gold)",opacity:.3}})}),o.jsxs("div",{className:"flex items-center justify-between px-4 pb-3 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("span",{className:"text-[13px] font-display font-semibold",style:{color:"var(--cream)"},children:"Sessions"}),o.jsx("button",{onClick:()=>V(!1),className:"text-muted hover:text-fg transition-colors duration-100 p-1",children:o.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsx("div",{className:"px-4 py-2.5 shrink-0",style:{borderBottom:"1px solid var(--b1)"},children:o.jsxs("button",{onClick:()=>{X(),V(!1)},className:"w-full flex items-center gap-2.5 py-2 px-3 rounded-xl transition-all duration-150 active:scale-[0.98] cursor-pointer",style:{background:"color-mix(in srgb, var(--gold) 10%, transparent)",border:"1px solid color-mix(in srgb, var(--gold) 20%, transparent)",color:"var(--gold)"},children:[o.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[o.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),o.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),o.jsx("span",{className:"text-[12.5px] font-semibold",children:"New Chat"})]})}),o.jsxs("div",{className:"flex-1 overflow-y-auto px-4 pb-4 scrollbar-thin",children:[k.sort((q,Q)=>Q.updatedAt-q.updatedAt).map(q=>o.jsx("button",{className:"w-full text-left py-3 px-3 rounded-xl mb-1 transition-all duration-150 active:scale-[0.98] min-h-[52px] cursor-pointer",style:{background:q.id===x?"linear-gradient(135deg, var(--s3) 0%, var(--s2) 100%)":"transparent",border:q.id===x?"1px solid var(--b2)":"1px solid transparent"},onClick:()=>{L(q.id),V(!1)},children:o.jsxs("div",{className:"flex items-center gap-2.5 min-w-0",children:[o.jsx("div",{className:"w-2 h-2 rounded-full shrink-0",style:{background:q.id===x?"var(--gold)":"transparent",boxShadow:q.id===x?"0 0 4px var(--gold)":"none"}}),o.jsxs("div",{className:"flex-1 min-w-0",children:[o.jsx("div",{className:"text-[12.5px] font-medium text-fg truncate",children:q.name||q.provider}),o.jsxs("div",{className:"text-[11px] text-muted",children:[q.provider," · ",(()=>{const Q=Date.now()-q.updatedAt;return Q<6e4?"just now":Q<36e5?`${Math.floor(Q/6e4)}m ago`:Q<864e5?`${Math.floor(Q/36e5)}h ago`:`${Math.floor(Q/864e5)}d ago`})()]})]}),q.type&&q.type!=="webui"&&o.jsx("span",{className:"text-[9px] font-mono text-muted bg-s2 px-1.5 py-0.5 rounded shrink-0",children:q.type})]})},q.id)),k.length===0&&o.jsx("div",{className:"text-center py-8 text-xs text-muted",children:"No sessions yet"})]}),x&&o.jsx("div",{className:"border-t border-b1 px-4 py-3 shrink-0",children:(()=>{var ge;const q=z.filter(I=>I.type==="usage"),Q=q.reduce((I,se)=>I+(se.inputTokens||0)+(se.outputTokens||0),0),K=q[q.length-1],W=K&&K.inputTokens||0;function P(I){return I<1e3?String(I):`${(I/1e3).toFixed(1)}k`}const J=a("current_provider")||"anthropic",F=(ge=i.find(I=>I.name===J))==null?void 0:ge.model_cost,le=a("model")||"sonnet";function ae(I,se){if(F){const[Ht,ll]=F.split(";"),_n=parseFloat(Ht||"0"),Jt=parseFloat(ll||"0");if(!isNaN(_n)&&!isNaN(Jt))return(I*_n+se*Jt)/1e6}const Re={opus:{in:15,out:75},sonnet:{in:3,out:15},haiku:{in:.8,out:4},"gpt-4o":{in:2.5,out:10},"gpt-4":{in:5,out:15},qwen:{in:.112,out:.224}},st=Object.keys(Re).find(Ht=>le.toLowerCase().includes(Ht))||"sonnet",Nt=Re[st];return(I*Nt.in+se*Nt.out)/1e6}const te=q.reduce((I,se)=>I+ae(se.inputTokens||0,se.outputTokens||0),0);return o.jsxs("div",{className:"grid grid-cols-3 gap-3 text-center",children:[o.jsxs("div",{children:[o.jsx("div",{className:"text-[9px] text-muted2 uppercase tracking-wider font-mono",children:"Tokens"}),o.jsx("div",{className:"text-[12px] text-fg font-mono font-semibold",children:P(Q)})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[9px] text-muted2 uppercase tracking-wider font-mono",children:"Context"}),o.jsx("div",{className:"text-[12px] text-fg font-mono font-semibold",children:P(W)})]}),o.jsxs("div",{children:[o.jsx("div",{className:"text-[9px] text-muted2 uppercase tracking-wider font-mono",children:"Cost"}),o.jsxs("div",{className:"text-[12px] text-green font-mono font-semibold",children:["$",te.toFixed(4)]})]})]})})()})]})}),A&&o.jsx("div",{className:"fixed inset-0 z-[999] flex items-center justify-center p-4 animate-fadeIn",style:{background:"rgba(10, 8, 5, 0.7)",backdropFilter:"blur(8px)"},children:o.jsxs("div",{className:"w-full max-w-[340px] p-5 rounded-2xl shadow-2xl animate-scaleIn select-none",style:{background:"linear-gradient(135deg, var(--s2), var(--s1))",border:"1px solid var(--b2)",boxShadow:"0 20px 60px rgba(0,0,0,0.5)"},children:[o.jsxs("div",{className:"flex items-center justify-between pb-3 mb-4",style:{borderBottom:"1px solid var(--b1)"},children:[o.jsx("span",{className:"font-bold text-[13.5px] font-display",style:{color:"var(--cream)"},children:"Install Curie Agent"}),o.jsx("button",{onClick:()=>C(!1),className:"text-muted hover:text-fg transition-colors duration-100 cursor-pointer",children:o.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),o.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),o.jsx("div",{className:"space-y-3.5 text-xs text-text leading-relaxed",children:N?o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-[12px] text-muted mb-1 px-0.5",children:"Follow these simple steps to add Curie to your home screen:"}),o.jsxs("div",{className:"flex gap-3 items-start p-3 rounded-xl",style:{background:"color-mix(in srgb, var(--s1) 50%, transparent)",border:"1px solid var(--b1)"},children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg shrink-0",style:{background:"color-mix(in srgb, var(--gold) 10%, transparent)",color:"var(--gold)"},children:o.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:o.jsx("path",{d:"M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8M16 6l-4-4-4 4M12 2v13"})})}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"1. Tap the Share Button"}),o.jsx("span",{className:"text-[11px] text-muted",children:"Tap the Share icon in Safari's bottom toolbar."})]})]}),o.jsxs("div",{className:"flex gap-3 items-start p-3 rounded-xl",style:{background:"color-mix(in srgb, var(--s1) 50%, transparent)",border:"1px solid var(--b1)"},children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg shrink-0 font-bold font-mono text-[16px] select-none",style:{background:"color-mix(in srgb, var(--gold) 10%, transparent)",color:"var(--gold)"},children:"+"}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"2. Add to Home Screen"}),o.jsxs("span",{className:"text-[11px] text-muted",children:["Scroll down and select ",o.jsx("strong",{children:"Add to Home Screen"}),"."]})]})]})]}):o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"text-[12px] text-muted mb-1 px-0.5",children:"Follow these simple steps to add Curie to your home screen:"}),o.jsxs("div",{className:"flex gap-3 items-start bg-s1/50 border border-b1 p-3 rounded-xl",children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-blue-500/10 text-blue-400 shrink-0",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("circle",{cx:"12",cy:"12",r:"1"}),o.jsx("circle",{cx:"12",cy:"5",r:"1"}),o.jsx("circle",{cx:"12",cy:"19",r:"1"})]})}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"1. Open Browser Menu"}),o.jsx("span",{className:"text-[11px] text-muted",children:"Tap the menu icon (three dots) in the top-right corner."})]})]}),o.jsxs("div",{className:"flex gap-3 items-start bg-s1/50 border border-b1 p-3 rounded-xl",children:[o.jsx("div",{className:"flex items-center justify-center w-7 h-7 rounded-lg bg-blue-500/10 text-blue-400 shrink-0",children:o.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[o.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),o.jsx("polyline",{points:"7 10 12 15 17 10"}),o.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})}),o.jsxs("div",{children:[o.jsx("span",{className:"font-semibold text-fg block mb-0.5",children:"2. Select Add / Install"}),o.jsxs("span",{className:"text-[11px] text-muted",children:["Tap ",o.jsx("strong",{children:"Add to Home screen"})," or ",o.jsx("strong",{children:"Install app"}),"."]})]})]})]})}),o.jsx("button",{onClick:()=>C(!1),className:"btn-gold w-full mt-5 py-2.5 px-4 rounded-xl font-semibold text-xs active:scale-[0.98] transition-all duration-150 cursor-pointer flex items-center justify-center",children:"Got it"})]})})]}):o.jsx(LT,{onAuthorize:l})}function qT(){return o.jsx(DN,{children:o.jsx(UT,{})})}const YT=_N.createRoot(document.getElementById("root"));YT.render(o.jsx(Me.StrictMode,{children:o.jsx(qT,{})}));"serviceWorker"in navigator&&window.addEventListener("load",()=>{navigator.serviceWorker.register("/sw.js").then(e=>{console.log("ServiceWorker registration successful with scope: ",e.scope),e.addEventListener("updatefound",()=>{const t=e.installing;t&&(window._pendingUpdateWorker=t,t.addEventListener("statechange",()=>{t.state==="installed"&&(window._hasPendingUpdate=!0,window.dispatchEvent(new CustomEvent("pwa-update-available")))}))}),navigator.serviceWorker.addEventListener("controllerchange",()=>{window.dispatchEvent(new CustomEvent("pwa-controller-updated"))})}).catch(e=>console.error("ServiceWorker registration failed: ",e))});