ccdeck 3.29.10 → 3.29.11

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.
@@ -54,7 +54,7 @@ Error generating stack: `+N.message+`
54
54
  * This source code is licensed under the MIT license found in the
55
55
  * LICENSE file in the root directory of this source tree.
56
56
  */var V1;function LO(){if(V1)return lm;V1=1;var e=qu(),t=OO();function n(p,h){return p===h&&(p!==0||1/p===1/h)||p!==p&&h!==h}var r=typeof Object.is=="function"?Object.is:n,s=t.useSyncExternalStore,l=e.useRef,c=e.useEffect,u=e.useMemo,f=e.useDebugValue;return lm.useSyncExternalStoreWithSelector=function(p,h,m,y,v){var S=l(null);if(S.current===null){var b={hasValue:!1,value:null};S.current=b}else b=S.current;S=u(function(){function k(I){if(!j){if(j=!0,E=I,I=y(I),v!==void 0&&b.hasValue){var $=b.value;if(v($,I))return C=$}return C=I}if($=C,r(E,I))return $;var q=y(I);return v!==void 0&&v($,q)?(E=I,$):(E=I,C=q)}var j=!1,E,C,R=m===void 0?null:m;return[function(){return k(h())},R===null?void 0:function(){return k(R())}]},[h,m,y,v]);var _=s(p,S[0],S[1]);return c(function(){b.hasValue=!0,b.value=_},[_]),f(_),_},lm}var G1;function PO(){return G1||(G1=1,im.exports=LO()),im.exports}var DO=PO();const FO=sb(DO),qO={},K1=e=>{let t;const n=new Set,r=(h,m)=>{const y=typeof h=="function"?h(t):h;if(!Object.is(y,t)){const v=t;t=m??(typeof y!="object"||y===null)?y:Object.assign({},t,y),n.forEach(S=>S(t,v))}},s=()=>t,f={setState:r,getState:s,getInitialState:()=>p,subscribe:h=>(n.add(h),()=>n.delete(h)),destroy:()=>{(qO?"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()}},p=t=e(r,s,f);return f},BO=e=>e?K1(e):K1,{useDebugValue:zO}=ve,{useSyncExternalStoreWithSelector:UO}=FO,HO=e=>e;function jR(e,t=HO,n){const r=UO(e.subscribe,e.getState,e.getServerState||e.getInitialState,t,n);return zO(r),r}const Y1=(e,t)=>{const n=BO(e),r=(s,l=t)=>jR(n,s,l);return Object.assign(r,n),r},WO=(e,t)=>e?Y1(e,t):Y1;function pn(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[r,s]of e)if(!Object.is(s,t.get(r)))return!1;return!0}if(e instanceof Set&&t instanceof Set){if(e.size!==t.size)return!1;for(const r of e)if(!t.has(r))return!1;return!0}const n=Object.keys(e);if(n.length!==Object.keys(t).length)return!1;for(const r of n)if(!Object.prototype.hasOwnProperty.call(t,r)||!Object.is(e[r],t[r]))return!1;return!0}var VO={value:()=>{}};function gf(){for(var e=0,t=arguments.length,n={},r;e<t;++e){if(!(r=arguments[e]+"")||r in n||/[\s.]/.test(r))throw new Error("illegal type: "+r);n[r]=[]}return new Oh(n)}function Oh(e){this._=e}function GO(e,t){return e.trim().split(/^|\s+/).map(function(n){var r="",s=n.indexOf(".");if(s>=0&&(r=n.slice(s+1),n=n.slice(0,s)),n&&!t.hasOwnProperty(n))throw new Error("unknown type: "+n);return{type:n,name:r}})}Oh.prototype=gf.prototype={constructor:Oh,on:function(e,t){var n=this._,r=GO(e+"",n),s,l=-1,c=r.length;if(arguments.length<2){for(;++l<c;)if((s=(e=r[l]).type)&&(s=KO(n[s],e.name)))return s;return}if(t!=null&&typeof t!="function")throw new Error("invalid callback: "+t);for(;++l<c;)if(s=(e=r[l]).type)n[s]=X1(n[s],e.name,t);else if(t==null)for(s in n)n[s]=X1(n[s],e.name,null);return this},copy:function(){var e={},t=this._;for(var n in t)e[n]=t[n].slice();return new Oh(e)},call:function(e,t){if((s=arguments.length-2)>0)for(var n=new Array(s),r=0,s,l;r<s;++r)n[r]=arguments[r+2];if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(l=this._[e],r=0,s=l.length;r<s;++r)l[r].value.apply(t,n)},apply:function(e,t,n){if(!this._.hasOwnProperty(e))throw new Error("unknown type: "+e);for(var r=this._[e],s=0,l=r.length;s<l;++s)r[s].value.apply(t,n)}};function KO(e,t){for(var n=0,r=e.length,s;n<r;++n)if((s=e[n]).name===t)return s.value}function X1(e,t,n){for(var r=0,s=e.length;r<s;++r)if(e[r].name===t){e[r]=VO,e=e.slice(0,r).concat(e.slice(r+1));break}return n!=null&&e.push({name:t,value:n}),e}var d0="http://www.w3.org/1999/xhtml";const Z1={svg:"http://www.w3.org/2000/svg",xhtml:d0,xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};function yf(e){var t=e+="",n=t.indexOf(":");return n>=0&&(t=e.slice(0,n))!=="xmlns"&&(e=e.slice(n+1)),Z1.hasOwnProperty(t)?{space:Z1[t],local:e}:e}function YO(e){return function(){var t=this.ownerDocument,n=this.namespaceURI;return n===d0&&t.documentElement.namespaceURI===d0?t.createElement(e):t.createElementNS(n,e)}}function XO(e){return function(){return this.ownerDocument.createElementNS(e.space,e.local)}}function _R(e){var t=yf(e);return(t.local?XO:YO)(t)}function ZO(){}function ob(e){return e==null?ZO:function(){return this.querySelector(e)}}function QO(e){typeof e!="function"&&(e=ob(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var l=t[s],c=l.length,u=r[s]=new Array(c),f,p,h=0;h<c;++h)(f=l[h])&&(p=e.call(f,f.__data__,h,l))&&("__data__"in f&&(p.__data__=f.__data__),u[h]=p);return new vr(r,this._parents)}function JO(e){return e==null?[]:Array.isArray(e)?e:Array.from(e)}function eL(){return[]}function ER(e){return e==null?eL:function(){return this.querySelectorAll(e)}}function tL(e){return function(){return JO(e.apply(this,arguments))}}function nL(e){typeof e=="function"?e=tL(e):e=ER(e);for(var t=this._groups,n=t.length,r=[],s=[],l=0;l<n;++l)for(var c=t[l],u=c.length,f,p=0;p<u;++p)(f=c[p])&&(r.push(e.call(f,f.__data__,p,c)),s.push(f));return new vr(r,s)}function CR(e){return function(){return this.matches(e)}}function TR(e){return function(t){return t.matches(e)}}var rL=Array.prototype.find;function sL(e){return function(){return rL.call(this.children,e)}}function aL(){return this.firstElementChild}function oL(e){return this.select(e==null?aL:sL(typeof e=="function"?e:TR(e)))}var iL=Array.prototype.filter;function lL(){return Array.from(this.children)}function cL(e){return function(){return iL.call(this.children,e)}}function uL(e){return this.selectAll(e==null?lL:cL(typeof e=="function"?e:TR(e)))}function dL(e){typeof e!="function"&&(e=CR(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var l=t[s],c=l.length,u=r[s]=[],f,p=0;p<c;++p)(f=l[p])&&e.call(f,f.__data__,p,l)&&u.push(f);return new vr(r,this._parents)}function RR(e){return new Array(e.length)}function hL(){return new vr(this._enter||this._groups.map(RR),this._parents)}function Wh(e,t){this.ownerDocument=e.ownerDocument,this.namespaceURI=e.namespaceURI,this._next=null,this._parent=e,this.__data__=t}Wh.prototype={constructor:Wh,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 fL(e){return function(){return e}}function pL(e,t,n,r,s,l){for(var c=0,u,f=t.length,p=l.length;c<p;++c)(u=t[c])?(u.__data__=l[c],r[c]=u):n[c]=new Wh(e,l[c]);for(;c<f;++c)(u=t[c])&&(s[c]=u)}function mL(e,t,n,r,s,l,c){var u,f,p=new Map,h=t.length,m=l.length,y=new Array(h),v;for(u=0;u<h;++u)(f=t[u])&&(y[u]=v=c.call(f,f.__data__,u,t)+"",p.has(v)?s[u]=f:p.set(v,f));for(u=0;u<m;++u)v=c.call(e,l[u],u,l)+"",(f=p.get(v))?(r[u]=f,f.__data__=l[u],p.delete(v)):n[u]=new Wh(e,l[u]);for(u=0;u<h;++u)(f=t[u])&&p.get(y[u])===f&&(s[u]=f)}function gL(e){return e.__data__}function yL(e,t){if(!arguments.length)return Array.from(this,gL);var n=t?mL:pL,r=this._parents,s=this._groups;typeof e!="function"&&(e=fL(e));for(var l=s.length,c=new Array(l),u=new Array(l),f=new Array(l),p=0;p<l;++p){var h=r[p],m=s[p],y=m.length,v=wL(e.call(h,h&&h.__data__,p,r)),S=v.length,b=u[p]=new Array(S),_=c[p]=new Array(S),k=f[p]=new Array(y);n(h,m,b,_,k,v,t);for(var j=0,E=0,C,R;j<S;++j)if(C=b[j]){for(j>=E&&(E=j+1);!(R=_[E])&&++E<S;);C._next=R||null}}return c=new vr(c,r),c._enter=u,c._exit=f,c}function wL(e){return typeof e=="object"&&"length"in e?e:Array.from(e)}function vL(){return new vr(this._exit||this._groups.map(RR),this._parents)}function xL(e,t,n){var r=this.enter(),s=this,l=this.exit();return typeof e=="function"?(r=e(r),r&&(r=r.selection())):r=r.append(e+""),t!=null&&(s=t(s),s&&(s=s.selection())),n==null?l.remove():n(l),r&&s?r.merge(s).order():s}function bL(e){for(var t=e.selection?e.selection():e,n=this._groups,r=t._groups,s=n.length,l=r.length,c=Math.min(s,l),u=new Array(s),f=0;f<c;++f)for(var p=n[f],h=r[f],m=p.length,y=u[f]=new Array(m),v,S=0;S<m;++S)(v=p[S]||h[S])&&(y[S]=v);for(;f<s;++f)u[f]=n[f];return new vr(u,this._parents)}function kL(){for(var e=this._groups,t=-1,n=e.length;++t<n;)for(var r=e[t],s=r.length-1,l=r[s],c;--s>=0;)(c=r[s])&&(l&&c.compareDocumentPosition(l)^4&&l.parentNode.insertBefore(c,l),l=c);return this}function NL(e){e||(e=SL);function t(m,y){return m&&y?e(m.__data__,y.__data__):!m-!y}for(var n=this._groups,r=n.length,s=new Array(r),l=0;l<r;++l){for(var c=n[l],u=c.length,f=s[l]=new Array(u),p,h=0;h<u;++h)(p=c[h])&&(f[h]=p);f.sort(t)}return new vr(s,this._parents).order()}function SL(e,t){return e<t?-1:e>t?1:e>=t?0:NaN}function jL(){var e=arguments[0];return arguments[0]=this,e.apply(null,arguments),this}function _L(){return Array.from(this)}function EL(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,l=r.length;s<l;++s){var c=r[s];if(c)return c}return null}function CL(){let e=0;for(const t of this)++e;return e}function TL(){return!this.node()}function RL(e){for(var t=this._groups,n=0,r=t.length;n<r;++n)for(var s=t[n],l=0,c=s.length,u;l<c;++l)(u=s[l])&&e.call(u,u.__data__,l,s);return this}function AL(e){return function(){this.removeAttribute(e)}}function ML(e){return function(){this.removeAttributeNS(e.space,e.local)}}function IL(e,t){return function(){this.setAttribute(e,t)}}function $L(e,t){return function(){this.setAttributeNS(e.space,e.local,t)}}function OL(e,t){return function(){var n=t.apply(this,arguments);n==null?this.removeAttribute(e):this.setAttribute(e,n)}}function LL(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 PL(e,t){var n=yf(e);if(arguments.length<2){var r=this.node();return n.local?r.getAttributeNS(n.space,n.local):r.getAttribute(n)}return this.each((t==null?n.local?ML:AL:typeof t=="function"?n.local?LL:OL:n.local?$L:IL)(n,t))}function AR(e){return e.ownerDocument&&e.ownerDocument.defaultView||e.document&&e||e.defaultView}function DL(e){return function(){this.style.removeProperty(e)}}function FL(e,t,n){return function(){this.style.setProperty(e,t,n)}}function qL(e,t,n){return function(){var r=t.apply(this,arguments);r==null?this.style.removeProperty(e):this.style.setProperty(e,r,n)}}function BL(e,t,n){return arguments.length>1?this.each((t==null?DL:typeof t=="function"?qL:FL)(e,t,n??"")):Ul(this.node(),e)}function Ul(e,t){return e.style.getPropertyValue(t)||AR(e).getComputedStyle(e,null).getPropertyValue(t)}function zL(e){return function(){delete this[e]}}function UL(e,t){return function(){this[e]=t}}function HL(e,t){return function(){var n=t.apply(this,arguments);n==null?delete this[e]:this[e]=n}}function WL(e,t){return arguments.length>1?this.each((t==null?zL:typeof t=="function"?HL:UL)(e,t)):this.node()[e]}function MR(e){return e.trim().split(/^|\s+/)}function ib(e){return e.classList||new IR(e)}function IR(e){this._node=e,this._names=MR(e.getAttribute("class")||"")}IR.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 $R(e,t){for(var n=ib(e),r=-1,s=t.length;++r<s;)n.add(t[r])}function OR(e,t){for(var n=ib(e),r=-1,s=t.length;++r<s;)n.remove(t[r])}function VL(e){return function(){$R(this,e)}}function GL(e){return function(){OR(this,e)}}function KL(e,t){return function(){(t.apply(this,arguments)?$R:OR)(this,e)}}function YL(e,t){var n=MR(e+"");if(arguments.length<2){for(var r=ib(this.node()),s=-1,l=n.length;++s<l;)if(!r.contains(n[s]))return!1;return!0}return this.each((typeof t=="function"?KL:t?VL:GL)(n,t))}function XL(){this.textContent=""}function ZL(e){return function(){this.textContent=e}}function QL(e){return function(){var t=e.apply(this,arguments);this.textContent=t??""}}function JL(e){return arguments.length?this.each(e==null?XL:(typeof e=="function"?QL:ZL)(e)):this.node().textContent}function e3(){this.innerHTML=""}function t3(e){return function(){this.innerHTML=e}}function n3(e){return function(){var t=e.apply(this,arguments);this.innerHTML=t??""}}function r3(e){return arguments.length?this.each(e==null?e3:(typeof e=="function"?n3:t3)(e)):this.node().innerHTML}function s3(){this.nextSibling&&this.parentNode.appendChild(this)}function a3(){return this.each(s3)}function o3(){this.previousSibling&&this.parentNode.insertBefore(this,this.parentNode.firstChild)}function i3(){return this.each(o3)}function l3(e){var t=typeof e=="function"?e:_R(e);return this.select(function(){return this.appendChild(t.apply(this,arguments))})}function c3(){return null}function u3(e,t){var n=typeof e=="function"?e:_R(e),r=t==null?c3:typeof t=="function"?t:ob(t);return this.select(function(){return this.insertBefore(n.apply(this,arguments),r.apply(this,arguments)||null)})}function d3(){var e=this.parentNode;e&&e.removeChild(this)}function h3(){return this.each(d3)}function f3(){var e=this.cloneNode(!1),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function p3(){var e=this.cloneNode(!0),t=this.parentNode;return t?t.insertBefore(e,this.nextSibling):e}function m3(e){return this.select(e?p3:f3)}function g3(e){return arguments.length?this.property("__data__",e):this.node().__data__}function y3(e){return function(t){e.call(this,t,this.__data__)}}function w3(e){return e.trim().split(/^|\s+/).map(function(t){var n="",r=t.indexOf(".");return r>=0&&(n=t.slice(r+1),t=t.slice(0,r)),{type:t,name:n}})}function v3(e){return function(){var t=this.__on;if(t){for(var n=0,r=-1,s=t.length,l;n<s;++n)l=t[n],(!e.type||l.type===e.type)&&l.name===e.name?this.removeEventListener(l.type,l.listener,l.options):t[++r]=l;++r?t.length=r:delete this.__on}}}function x3(e,t,n){return function(){var r=this.__on,s,l=y3(t);if(r){for(var c=0,u=r.length;c<u;++c)if((s=r[c]).type===e.type&&s.name===e.name){this.removeEventListener(s.type,s.listener,s.options),this.addEventListener(s.type,s.listener=l,s.options=n),s.value=t;return}}this.addEventListener(e.type,l,n),s={type:e.type,name:e.name,value:t,listener:l,options:n},r?r.push(s):this.__on=[s]}}function b3(e,t,n){var r=w3(e+""),s,l=r.length,c;if(arguments.length<2){var u=this.node().__on;if(u){for(var f=0,p=u.length,h;f<p;++f)for(s=0,h=u[f];s<l;++s)if((c=r[s]).type===h.type&&c.name===h.name)return h.value}return}for(u=t?x3:v3,s=0;s<l;++s)this.each(u(r[s],t,n));return this}function LR(e,t,n){var r=AR(e),s=r.CustomEvent;typeof s=="function"?s=new s(t,n):(s=r.document.createEvent("Event"),n?(s.initEvent(t,n.bubbles,n.cancelable),s.detail=n.detail):s.initEvent(t,!1,!1)),e.dispatchEvent(s)}function k3(e,t){return function(){return LR(this,e,t)}}function N3(e,t){return function(){return LR(this,e,t.apply(this,arguments))}}function S3(e,t){return this.each((typeof t=="function"?N3:k3)(e,t))}function*j3(){for(var e=this._groups,t=0,n=e.length;t<n;++t)for(var r=e[t],s=0,l=r.length,c;s<l;++s)(c=r[s])&&(yield c)}var PR=[null];function vr(e,t){this._groups=e,this._parents=t}function Bu(){return new vr([[document.documentElement]],PR)}function _3(){return this}vr.prototype=Bu.prototype={constructor:vr,select:QO,selectAll:nL,selectChild:oL,selectChildren:uL,filter:dL,data:yL,enter:hL,exit:vL,join:xL,merge:bL,selection:_3,order:kL,sort:NL,call:jL,nodes:_L,node:EL,size:CL,empty:TL,each:RL,attr:PL,style:BL,property:WL,classed:YL,text:JL,html:r3,raise:a3,lower:i3,append:l3,insert:u3,remove:h3,clone:m3,datum:g3,on:b3,dispatch:S3,[Symbol.iterator]:j3};function Lr(e){return typeof e=="string"?new vr([[document.querySelector(e)]],[document.documentElement]):new vr([[e]],PR)}function E3(e){let t;for(;t=e.sourceEvent;)e=t;return e}function fs(e,t){if(e=E3(e),t===void 0&&(t=e.currentTarget),t){var n=t.ownerSVGElement||t;if(n.createSVGPoint){var r=n.createSVGPoint();return r.x=e.clientX,r.y=e.clientY,r=r.matrixTransform(t.getScreenCTM().inverse()),[r.x,r.y]}if(t.getBoundingClientRect){var s=t.getBoundingClientRect();return[e.clientX-s.left-t.clientLeft,e.clientY-s.top-t.clientTop]}}return[e.pageX,e.pageY]}const C3={passive:!1},xu={capture:!0,passive:!1};function dm(e){e.stopImmediatePropagation()}function Dl(e){e.preventDefault(),e.stopImmediatePropagation()}function DR(e){var t=e.document.documentElement,n=Lr(e).on("dragstart.drag",Dl,xu);"onselectstart"in t?n.on("selectstart.drag",Dl,xu):(t.__noselect=t.style.MozUserSelect,t.style.MozUserSelect="none")}function FR(e,t){var n=e.document.documentElement,r=Lr(e).on("dragstart.drag",null);t&&(r.on("click.drag",Dl,xu),setTimeout(function(){r.on("click.drag",null)},0)),"onselectstart"in n?r.on("selectstart.drag",null):(n.style.MozUserSelect=n.__noselect,delete n.__noselect)}const ah=e=>()=>e;function h0(e,{sourceEvent:t,subject:n,target:r,identifier:s,active:l,x:c,y:u,dx:f,dy:p,dispatch:h}){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:r,enumerable:!0,configurable:!0},identifier:{value:s,enumerable:!0,configurable:!0},active:{value:l,enumerable:!0,configurable:!0},x:{value:c,enumerable:!0,configurable:!0},y:{value:u,enumerable:!0,configurable:!0},dx:{value:f,enumerable:!0,configurable:!0},dy:{value:p,enumerable:!0,configurable:!0},_:{value:h}})}h0.prototype.on=function(){var e=this._.on.apply(this._,arguments);return e===this._?this:e};function T3(e){return!e.ctrlKey&&!e.button}function R3(){return this.parentNode}function A3(e,t){return t??{x:e.x,y:e.y}}function M3(){return navigator.maxTouchPoints||"ontouchstart"in this}function I3(){var e=T3,t=R3,n=A3,r=M3,s={},l=gf("start","drag","end"),c=0,u,f,p,h,m=0;function y(C){C.on("mousedown.drag",v).filter(r).on("touchstart.drag",_).on("touchmove.drag",k,C3).on("touchend.drag touchcancel.drag",j).style("touch-action","none").style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}function v(C,R){if(!(h||!e.call(this,C,R))){var I=E(this,t.call(this,C,R),C,R,"mouse");I&&(Lr(C.view).on("mousemove.drag",S,xu).on("mouseup.drag",b,xu),DR(C.view),dm(C),p=!1,u=C.clientX,f=C.clientY,I("start",C))}}function S(C){if(Dl(C),!p){var R=C.clientX-u,I=C.clientY-f;p=R*R+I*I>m}s.mouse("drag",C)}function b(C){Lr(C.view).on("mousemove.drag mouseup.drag",null),FR(C.view,p),Dl(C),s.mouse("end",C)}function _(C,R){if(e.call(this,C,R)){var I=C.changedTouches,$=t.call(this,C,R),q=I.length,B,P;for(B=0;B<q;++B)(P=E(this,$,C,R,I[B].identifier,I[B]))&&(dm(C),P("start",C,I[B]))}}function k(C){var R=C.changedTouches,I=R.length,$,q;for($=0;$<I;++$)(q=s[R[$].identifier])&&(Dl(C),q("drag",C,R[$]))}function j(C){var R=C.changedTouches,I=R.length,$,q;for(h&&clearTimeout(h),h=setTimeout(function(){h=null},500),$=0;$<I;++$)(q=s[R[$].identifier])&&(dm(C),q("end",C,R[$]))}function E(C,R,I,$,q,B){var P=l.copy(),W=fs(B||I,R),ne,ee,M;if((M=n.call(C,new h0("beforestart",{sourceEvent:I,target:y,identifier:q,active:c,x:W[0],y:W[1],dx:0,dy:0,dispatch:P}),$))!=null)return ne=M.x-W[0]||0,ee=M.y-W[1]||0,function X(V,G,F){var L=W,H;switch(V){case"start":s[q]=X,H=c++;break;case"end":delete s[q],--c;case"drag":W=fs(F||G,R),H=c;break}P.call(V,C,new h0(V,{sourceEvent:G,subject:M,target:y,identifier:q,active:H,x:W[0]+ne,y:W[1]+ee,dx:W[0]-L[0],dy:W[1]-L[1],dispatch:P}),$)}}return y.filter=function(C){return arguments.length?(e=typeof C=="function"?C:ah(!!C),y):e},y.container=function(C){return arguments.length?(t=typeof C=="function"?C:ah(C),y):t},y.subject=function(C){return arguments.length?(n=typeof C=="function"?C:ah(C),y):n},y.touchable=function(C){return arguments.length?(r=typeof C=="function"?C:ah(!!C),y):r},y.on=function(){var C=l.on.apply(l,arguments);return C===l?y:C},y.clickDistance=function(C){return arguments.length?(m=(C=+C)*C,y):Math.sqrt(m)},y}function lb(e,t,n){e.prototype=t.prototype=n,n.constructor=e}function qR(e,t){var n=Object.create(e.prototype);for(var r in t)n[r]=t[r];return n}function zu(){}var bu=.7,Vh=1/bu,Fl="\\s*([+-]?\\d+)\\s*",ku="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)\\s*",Ds="\\s*([+-]?(?:\\d*\\.)?\\d+(?:[eE][+-]?\\d+)?)%\\s*",$3=/^#([0-9a-f]{3,8})$/,O3=new RegExp(`^rgb\\(${Fl},${Fl},${Fl}\\)$`),L3=new RegExp(`^rgb\\(${Ds},${Ds},${Ds}\\)$`),P3=new RegExp(`^rgba\\(${Fl},${Fl},${Fl},${ku}\\)$`),D3=new RegExp(`^rgba\\(${Ds},${Ds},${Ds},${ku}\\)$`),F3=new RegExp(`^hsl\\(${ku},${Ds},${Ds}\\)$`),q3=new RegExp(`^hsla\\(${ku},${Ds},${Ds},${ku}\\)$`),Q1={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};lb(zu,Nu,{copy(e){return Object.assign(new this.constructor,this,e)},displayable(){return this.rgb().displayable()},hex:J1,formatHex:J1,formatHex8:B3,formatHsl:z3,formatRgb:eN,toString:eN});function J1(){return this.rgb().formatHex()}function B3(){return this.rgb().formatHex8()}function z3(){return BR(this).formatHsl()}function eN(){return this.rgb().formatRgb()}function Nu(e){var t,n;return e=(e+"").trim().toLowerCase(),(t=$3.exec(e))?(n=t[1].length,t=parseInt(t[1],16),n===6?tN(t):n===3?new sr(t>>8&15|t>>4&240,t>>4&15|t&240,(t&15)<<4|t&15,1):n===8?oh(t>>24&255,t>>16&255,t>>8&255,(t&255)/255):n===4?oh(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=O3.exec(e))?new sr(t[1],t[2],t[3],1):(t=L3.exec(e))?new sr(t[1]*255/100,t[2]*255/100,t[3]*255/100,1):(t=P3.exec(e))?oh(t[1],t[2],t[3],t[4]):(t=D3.exec(e))?oh(t[1]*255/100,t[2]*255/100,t[3]*255/100,t[4]):(t=F3.exec(e))?sN(t[1],t[2]/100,t[3]/100,1):(t=q3.exec(e))?sN(t[1],t[2]/100,t[3]/100,t[4]):Q1.hasOwnProperty(e)?tN(Q1[e]):e==="transparent"?new sr(NaN,NaN,NaN,0):null}function tN(e){return new sr(e>>16&255,e>>8&255,e&255,1)}function oh(e,t,n,r){return r<=0&&(e=t=n=NaN),new sr(e,t,n,r)}function U3(e){return e instanceof zu||(e=Nu(e)),e?(e=e.rgb(),new sr(e.r,e.g,e.b,e.opacity)):new sr}function f0(e,t,n,r){return arguments.length===1?U3(e):new sr(e,t,n,r??1)}function sr(e,t,n,r){this.r=+e,this.g=+t,this.b=+n,this.opacity=+r}lb(sr,f0,qR(zu,{brighter(e){return e=e==null?Vh:Math.pow(Vh,e),new sr(this.r*e,this.g*e,this.b*e,this.opacity)},darker(e){return e=e==null?bu:Math.pow(bu,e),new sr(this.r*e,this.g*e,this.b*e,this.opacity)},rgb(){return this},clamp(){return new sr(ci(this.r),ci(this.g),ci(this.b),Gh(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:nN,formatHex:nN,formatHex8:H3,formatRgb:rN,toString:rN}));function nN(){return`#${ii(this.r)}${ii(this.g)}${ii(this.b)}`}function H3(){return`#${ii(this.r)}${ii(this.g)}${ii(this.b)}${ii((isNaN(this.opacity)?1:this.opacity)*255)}`}function rN(){const e=Gh(this.opacity);return`${e===1?"rgb(":"rgba("}${ci(this.r)}, ${ci(this.g)}, ${ci(this.b)}${e===1?")":`, ${e})`}`}function Gh(e){return isNaN(e)?1:Math.max(0,Math.min(1,e))}function ci(e){return Math.max(0,Math.min(255,Math.round(e)||0))}function ii(e){return e=ci(e),(e<16?"0":"")+e.toString(16)}function sN(e,t,n,r){return r<=0?e=t=n=NaN:n<=0||n>=1?e=t=NaN:t<=0&&(e=NaN),new ms(e,t,n,r)}function BR(e){if(e instanceof ms)return new ms(e.h,e.s,e.l,e.opacity);if(e instanceof zu||(e=Nu(e)),!e)return new ms;if(e instanceof ms)return e;e=e.rgb();var t=e.r/255,n=e.g/255,r=e.b/255,s=Math.min(t,n,r),l=Math.max(t,n,r),c=NaN,u=l-s,f=(l+s)/2;return u?(t===l?c=(n-r)/u+(n<r)*6:n===l?c=(r-t)/u+2:c=(t-n)/u+4,u/=f<.5?l+s:2-l-s,c*=60):u=f>0&&f<1?0:c,new ms(c,u,f,e.opacity)}function W3(e,t,n,r){return arguments.length===1?BR(e):new ms(e,t,n,r??1)}function ms(e,t,n,r){this.h=+e,this.s=+t,this.l=+n,this.opacity=+r}lb(ms,W3,qR(zu,{brighter(e){return e=e==null?Vh:Math.pow(Vh,e),new ms(this.h,this.s,this.l*e,this.opacity)},darker(e){return e=e==null?bu:Math.pow(bu,e),new ms(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,r=n+(n<.5?n:1-n)*t,s=2*n-r;return new sr(hm(e>=240?e-240:e+120,s,r),hm(e,s,r),hm(e<120?e+240:e-120,s,r),this.opacity)},clamp(){return new ms(aN(this.h),ih(this.s),ih(this.l),Gh(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=Gh(this.opacity);return`${e===1?"hsl(":"hsla("}${aN(this.h)}, ${ih(this.s)*100}%, ${ih(this.l)*100}%${e===1?")":`, ${e})`}`}}));function aN(e){return e=(e||0)%360,e<0?e+360:e}function ih(e){return Math.max(0,Math.min(1,e||0))}function hm(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 zR=e=>()=>e;function V3(e,t){return function(n){return e+n*t}}function G3(e,t,n){return e=Math.pow(e,n),t=Math.pow(t,n)-e,n=1/n,function(r){return Math.pow(e+r*t,n)}}function K3(e){return(e=+e)==1?UR:function(t,n){return n-t?G3(t,n,e):zR(isNaN(t)?n:t)}}function UR(e,t){var n=t-e;return n?V3(e,n):zR(isNaN(e)?t:e)}const oN=(function e(t){var n=K3(t);function r(s,l){var c=n((s=f0(s)).r,(l=f0(l)).r),u=n(s.g,l.g),f=n(s.b,l.b),p=UR(s.opacity,l.opacity);return function(h){return s.r=c(h),s.g=u(h),s.b=f(h),s.opacity=p(h),s+""}}return r.gamma=e,r})(1);function Qa(e,t){return e=+e,t=+t,function(n){return e*(1-n)+t*n}}var p0=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g,fm=new RegExp(p0.source,"g");function Y3(e){return function(){return e}}function X3(e){return function(t){return e(t)+""}}function Z3(e,t){var n=p0.lastIndex=fm.lastIndex=0,r,s,l,c=-1,u=[],f=[];for(e=e+"",t=t+"";(r=p0.exec(e))&&(s=fm.exec(t));)(l=s.index)>n&&(l=t.slice(n,l),u[c]?u[c]+=l:u[++c]=l),(r=r[0])===(s=s[0])?u[c]?u[c]+=s:u[++c]=s:(u[++c]=null,f.push({i:c,x:Qa(r,s)})),n=fm.lastIndex;return n<t.length&&(l=t.slice(n),u[c]?u[c]+=l:u[++c]=l),u.length<2?f[0]?X3(f[0].x):Y3(t):(t=f.length,function(p){for(var h=0,m;h<t;++h)u[(m=f[h]).i]=m.x(p);return u.join("")})}var iN=180/Math.PI,m0={translateX:0,translateY:0,rotate:0,skewX:0,scaleX:1,scaleY:1};function HR(e,t,n,r,s,l){var c,u,f;return(c=Math.sqrt(e*e+t*t))&&(e/=c,t/=c),(f=e*n+t*r)&&(n-=e*f,r-=t*f),(u=Math.sqrt(n*n+r*r))&&(n/=u,r/=u,f/=u),e*r<t*n&&(e=-e,t=-t,f=-f,c=-c),{translateX:s,translateY:l,rotate:Math.atan2(t,e)*iN,skewX:Math.atan(f)*iN,scaleX:c,scaleY:u}}var lh;function Q3(e){const t=new(typeof DOMMatrix=="function"?DOMMatrix:WebKitCSSMatrix)(e+"");return t.isIdentity?m0:HR(t.a,t.b,t.c,t.d,t.e,t.f)}function J3(e){return e==null||(lh||(lh=document.createElementNS("http://www.w3.org/2000/svg","g")),lh.setAttribute("transform",e),!(e=lh.transform.baseVal.consolidate()))?m0:(e=e.matrix,HR(e.a,e.b,e.c,e.d,e.e,e.f))}function WR(e,t,n,r){function s(p){return p.length?p.pop()+" ":""}function l(p,h,m,y,v,S){if(p!==m||h!==y){var b=v.push("translate(",null,t,null,n);S.push({i:b-4,x:Qa(p,m)},{i:b-2,x:Qa(h,y)})}else(m||y)&&v.push("translate("+m+t+y+n)}function c(p,h,m,y){p!==h?(p-h>180?h+=360:h-p>180&&(p+=360),y.push({i:m.push(s(m)+"rotate(",null,r)-2,x:Qa(p,h)})):h&&m.push(s(m)+"rotate("+h+r)}function u(p,h,m,y){p!==h?y.push({i:m.push(s(m)+"skewX(",null,r)-2,x:Qa(p,h)}):h&&m.push(s(m)+"skewX("+h+r)}function f(p,h,m,y,v,S){if(p!==m||h!==y){var b=v.push(s(v)+"scale(",null,",",null,")");S.push({i:b-4,x:Qa(p,m)},{i:b-2,x:Qa(h,y)})}else(m!==1||y!==1)&&v.push(s(v)+"scale("+m+","+y+")")}return function(p,h){var m=[],y=[];return p=e(p),h=e(h),l(p.translateX,p.translateY,h.translateX,h.translateY,m,y),c(p.rotate,h.rotate,m,y),u(p.skewX,h.skewX,m,y),f(p.scaleX,p.scaleY,h.scaleX,h.scaleY,m,y),p=h=null,function(v){for(var S=-1,b=y.length,_;++S<b;)m[(_=y[S]).i]=_.x(v);return m.join("")}}}var eP=WR(Q3,"px, ","px)","deg)"),tP=WR(J3,", ",")",")"),nP=1e-12;function lN(e){return((e=Math.exp(e))+1/e)/2}function rP(e){return((e=Math.exp(e))-1/e)/2}function sP(e){return((e=Math.exp(2*e))-1)/(e+1)}const aP=(function e(t,n,r){function s(l,c){var u=l[0],f=l[1],p=l[2],h=c[0],m=c[1],y=c[2],v=h-u,S=m-f,b=v*v+S*S,_,k;if(b<nP)k=Math.log(y/p)/t,_=function($){return[u+$*v,f+$*S,p*Math.exp(t*$*k)]};else{var j=Math.sqrt(b),E=(y*y-p*p+r*b)/(2*p*n*j),C=(y*y-p*p-r*b)/(2*y*n*j),R=Math.log(Math.sqrt(E*E+1)-E),I=Math.log(Math.sqrt(C*C+1)-C);k=(I-R)/t,_=function($){var q=$*k,B=lN(R),P=p/(n*j)*(B*sP(t*q+R)-rP(R));return[u+P*v,f+P*S,p*B/lN(t*q+R)]}}return _.duration=k*1e3*t/Math.SQRT2,_}return s.rho=function(l){var c=Math.max(.001,+l),u=c*c,f=u*u;return e(c,u,f)},s})(Math.SQRT2,2,4);var Hl=0,lu=0,Jc=0,VR=1e3,Kh,cu,Yh=0,pi=0,wf=0,Su=typeof performance=="object"&&performance.now?performance:Date,GR=typeof window=="object"&&window.requestAnimationFrame?window.requestAnimationFrame.bind(window):function(e){setTimeout(e,17)};function cb(){return pi||(GR(oP),pi=Su.now()+wf)}function oP(){pi=0}function Xh(){this._call=this._time=this._next=null}Xh.prototype=KR.prototype={constructor:Xh,restart:function(e,t,n){if(typeof e!="function")throw new TypeError("callback is not a function");n=(n==null?cb():+n)+(t==null?0:+t),!this._next&&cu!==this&&(cu?cu._next=this:Kh=this,cu=this),this._call=e,this._time=n,g0()},stop:function(){this._call&&(this._call=null,this._time=1/0,g0())}};function KR(e,t,n){var r=new Xh;return r.restart(e,t,n),r}function iP(){cb(),++Hl;for(var e=Kh,t;e;)(t=pi-e._time)>=0&&e._call.call(void 0,t),e=e._next;--Hl}function cN(){pi=(Yh=Su.now())+wf,Hl=lu=0;try{iP()}finally{Hl=0,cP(),pi=0}}function lP(){var e=Su.now(),t=e-Yh;t>VR&&(wf-=t,Yh=e)}function cP(){for(var e,t=Kh,n,r=1/0;t;)t._call?(r>t._time&&(r=t._time),e=t,t=t._next):(n=t._next,t._next=null,t=e?e._next=n:Kh=n);cu=e,g0(r)}function g0(e){if(!Hl){lu&&(lu=clearTimeout(lu));var t=e-pi;t>24?(e<1/0&&(lu=setTimeout(cN,e-Su.now()-wf)),Jc&&(Jc=clearInterval(Jc))):(Jc||(Yh=Su.now(),Jc=setInterval(lP,VR)),Hl=1,GR(cN))}}function uN(e,t,n){var r=new Xh;return t=t==null?0:+t,r.restart(s=>{r.stop(),e(s+t)},t,n),r}var uP=gf("start","end","cancel","interrupt"),dP=[],YR=0,dN=1,y0=2,Lh=3,hN=4,w0=5,Ph=6;function vf(e,t,n,r,s,l){var c=e.__transition;if(!c)e.__transition={};else if(n in c)return;hP(e,n,{name:t,index:r,group:s,on:uP,tween:dP,time:l.time,delay:l.delay,duration:l.duration,ease:l.ease,timer:null,state:YR})}function ub(e,t){var n=bs(e,t);if(n.state>YR)throw new Error("too late; already scheduled");return n}function zs(e,t){var n=bs(e,t);if(n.state>Lh)throw new Error("too late; already running");return n}function bs(e,t){var n=e.__transition;if(!n||!(n=n[t]))throw new Error("transition not found");return n}function hP(e,t,n){var r=e.__transition,s;r[t]=n,n.timer=KR(l,0,n.time);function l(p){n.state=dN,n.timer.restart(c,n.delay,n.time),n.delay<=p&&c(p-n.delay)}function c(p){var h,m,y,v;if(n.state!==dN)return f();for(h in r)if(v=r[h],v.name===n.name){if(v.state===Lh)return uN(c);v.state===hN?(v.state=Ph,v.timer.stop(),v.on.call("interrupt",e,e.__data__,v.index,v.group),delete r[h]):+h<t&&(v.state=Ph,v.timer.stop(),v.on.call("cancel",e,e.__data__,v.index,v.group),delete r[h])}if(uN(function(){n.state===Lh&&(n.state=hN,n.timer.restart(u,n.delay,n.time),u(p))}),n.state=y0,n.on.call("start",e,e.__data__,n.index,n.group),n.state===y0){for(n.state=Lh,s=new Array(y=n.tween.length),h=0,m=-1;h<y;++h)(v=n.tween[h].value.call(e,e.__data__,n.index,n.group))&&(s[++m]=v);s.length=m+1}}function u(p){for(var h=p<n.duration?n.ease.call(null,p/n.duration):(n.timer.restart(f),n.state=w0,1),m=-1,y=s.length;++m<y;)s[m].call(e,h);n.state===w0&&(n.on.call("end",e,e.__data__,n.index,n.group),f())}function f(){n.state=Ph,n.timer.stop(),delete r[t];for(var p in r)return;delete e.__transition}}function Dh(e,t){var n=e.__transition,r,s,l=!0,c;if(n){t=t==null?null:t+"";for(c in n){if((r=n[c]).name!==t){l=!1;continue}s=r.state>y0&&r.state<w0,r.state=Ph,r.timer.stop(),r.on.call(s?"interrupt":"cancel",e,e.__data__,r.index,r.group),delete n[c]}l&&delete e.__transition}}function fP(e){return this.each(function(){Dh(this,e)})}function pP(e,t){var n,r;return function(){var s=zs(this,e),l=s.tween;if(l!==n){r=n=l;for(var c=0,u=r.length;c<u;++c)if(r[c].name===t){r=r.slice(),r.splice(c,1);break}}s.tween=r}}function mP(e,t,n){var r,s;if(typeof n!="function")throw new Error;return function(){var l=zs(this,e),c=l.tween;if(c!==r){s=(r=c).slice();for(var u={name:t,value:n},f=0,p=s.length;f<p;++f)if(s[f].name===t){s[f]=u;break}f===p&&s.push(u)}l.tween=s}}function gP(e,t){var n=this._id;if(e+="",arguments.length<2){for(var r=bs(this.node(),n).tween,s=0,l=r.length,c;s<l;++s)if((c=r[s]).name===e)return c.value;return null}return this.each((t==null?pP:mP)(n,e,t))}function db(e,t,n){var r=e._id;return e.each(function(){var s=zs(this,r);(s.value||(s.value={}))[t]=n.apply(this,arguments)}),function(s){return bs(s,r).value[t]}}function XR(e,t){var n;return(typeof t=="number"?Qa:t instanceof Nu?oN:(n=Nu(t))?(t=n,oN):Z3)(e,t)}function yP(e){return function(){this.removeAttribute(e)}}function wP(e){return function(){this.removeAttributeNS(e.space,e.local)}}function vP(e,t,n){var r,s=n+"",l;return function(){var c=this.getAttribute(e);return c===s?null:c===r?l:l=t(r=c,n)}}function xP(e,t,n){var r,s=n+"",l;return function(){var c=this.getAttributeNS(e.space,e.local);return c===s?null:c===r?l:l=t(r=c,n)}}function bP(e,t,n){var r,s,l;return function(){var c,u=n(this),f;return u==null?void this.removeAttribute(e):(c=this.getAttribute(e),f=u+"",c===f?null:c===r&&f===s?l:(s=f,l=t(r=c,u)))}}function kP(e,t,n){var r,s,l;return function(){var c,u=n(this),f;return u==null?void this.removeAttributeNS(e.space,e.local):(c=this.getAttributeNS(e.space,e.local),f=u+"",c===f?null:c===r&&f===s?l:(s=f,l=t(r=c,u)))}}function NP(e,t){var n=yf(e),r=n==="transform"?tP:XR;return this.attrTween(e,typeof t=="function"?(n.local?kP:bP)(n,r,db(this,"attr."+e,t)):t==null?(n.local?wP:yP)(n):(n.local?xP:vP)(n,r,t))}function SP(e,t){return function(n){this.setAttribute(e,t.call(this,n))}}function jP(e,t){return function(n){this.setAttributeNS(e.space,e.local,t.call(this,n))}}function _P(e,t){var n,r;function s(){var l=t.apply(this,arguments);return l!==r&&(n=(r=l)&&jP(e,l)),n}return s._value=t,s}function EP(e,t){var n,r;function s(){var l=t.apply(this,arguments);return l!==r&&(n=(r=l)&&SP(e,l)),n}return s._value=t,s}function CP(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 r=yf(e);return this.tween(n,(r.local?_P:EP)(r,t))}function TP(e,t){return function(){ub(this,e).delay=+t.apply(this,arguments)}}function RP(e,t){return t=+t,function(){ub(this,e).delay=t}}function AP(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?TP:RP)(t,e)):bs(this.node(),t).delay}function MP(e,t){return function(){zs(this,e).duration=+t.apply(this,arguments)}}function IP(e,t){return t=+t,function(){zs(this,e).duration=t}}function $P(e){var t=this._id;return arguments.length?this.each((typeof e=="function"?MP:IP)(t,e)):bs(this.node(),t).duration}function OP(e,t){if(typeof t!="function")throw new Error;return function(){zs(this,e).ease=t}}function LP(e){var t=this._id;return arguments.length?this.each(OP(t,e)):bs(this.node(),t).ease}function PP(e,t){return function(){var n=t.apply(this,arguments);if(typeof n!="function")throw new Error;zs(this,e).ease=n}}function DP(e){if(typeof e!="function")throw new Error;return this.each(PP(this._id,e))}function FP(e){typeof e!="function"&&(e=CR(e));for(var t=this._groups,n=t.length,r=new Array(n),s=0;s<n;++s)for(var l=t[s],c=l.length,u=r[s]=[],f,p=0;p<c;++p)(f=l[p])&&e.call(f,f.__data__,p,l)&&u.push(f);return new da(r,this._parents,this._name,this._id)}function qP(e){if(e._id!==this._id)throw new Error;for(var t=this._groups,n=e._groups,r=t.length,s=n.length,l=Math.min(r,s),c=new Array(r),u=0;u<l;++u)for(var f=t[u],p=n[u],h=f.length,m=c[u]=new Array(h),y,v=0;v<h;++v)(y=f[v]||p[v])&&(m[v]=y);for(;u<r;++u)c[u]=t[u];return new da(c,this._parents,this._name,this._id)}function BP(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 zP(e,t,n){var r,s,l=BP(t)?ub:zs;return function(){var c=l(this,e),u=c.on;u!==r&&(s=(r=u).copy()).on(t,n),c.on=s}}function UP(e,t){var n=this._id;return arguments.length<2?bs(this.node(),n).on.on(e):this.each(zP(n,e,t))}function HP(e){return function(){var t=this.parentNode;for(var n in this.__transition)if(+n!==e)return;t&&t.removeChild(this)}}function WP(){return this.on("end.remove",HP(this._id))}function VP(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ob(e));for(var r=this._groups,s=r.length,l=new Array(s),c=0;c<s;++c)for(var u=r[c],f=u.length,p=l[c]=new Array(f),h,m,y=0;y<f;++y)(h=u[y])&&(m=e.call(h,h.__data__,y,u))&&("__data__"in h&&(m.__data__=h.__data__),p[y]=m,vf(p[y],t,n,y,p,bs(h,n)));return new da(l,this._parents,t,n)}function GP(e){var t=this._name,n=this._id;typeof e!="function"&&(e=ER(e));for(var r=this._groups,s=r.length,l=[],c=[],u=0;u<s;++u)for(var f=r[u],p=f.length,h,m=0;m<p;++m)if(h=f[m]){for(var y=e.call(h,h.__data__,m,f),v,S=bs(h,n),b=0,_=y.length;b<_;++b)(v=y[b])&&vf(v,t,n,b,y,S);l.push(y),c.push(h)}return new da(l,c,t,n)}var KP=Bu.prototype.constructor;function YP(){return new KP(this._groups,this._parents)}function XP(e,t){var n,r,s;return function(){var l=Ul(this,e),c=(this.style.removeProperty(e),Ul(this,e));return l===c?null:l===n&&c===r?s:s=t(n=l,r=c)}}function ZR(e){return function(){this.style.removeProperty(e)}}function ZP(e,t,n){var r,s=n+"",l;return function(){var c=Ul(this,e);return c===s?null:c===r?l:l=t(r=c,n)}}function QP(e,t,n){var r,s,l;return function(){var c=Ul(this,e),u=n(this),f=u+"";return u==null&&(f=u=(this.style.removeProperty(e),Ul(this,e))),c===f?null:c===r&&f===s?l:(s=f,l=t(r=c,u))}}function JP(e,t){var n,r,s,l="style."+t,c="end."+l,u;return function(){var f=zs(this,e),p=f.on,h=f.value[l]==null?u||(u=ZR(t)):void 0;(p!==n||s!==h)&&(r=(n=p).copy()).on(c,s=h),f.on=r}}function e4(e,t,n){var r=(e+="")=="transform"?eP:XR;return t==null?this.styleTween(e,XP(e,r)).on("end.style."+e,ZR(e)):typeof t=="function"?this.styleTween(e,QP(e,r,db(this,"style."+e,t))).each(JP(this._id,e)):this.styleTween(e,ZP(e,r,t),n).on("end.style."+e,null)}function t4(e,t,n){return function(r){this.style.setProperty(e,t.call(this,r),n)}}function n4(e,t,n){var r,s;function l(){var c=t.apply(this,arguments);return c!==s&&(r=(s=c)&&t4(e,c,n)),r}return l._value=t,l}function r4(e,t,n){var r="style."+(e+="");if(arguments.length<2)return(r=this.tween(r))&&r._value;if(t==null)return this.tween(r,null);if(typeof t!="function")throw new Error;return this.tween(r,n4(e,t,n??""))}function s4(e){return function(){this.textContent=e}}function a4(e){return function(){var t=e(this);this.textContent=t??""}}function o4(e){return this.tween("text",typeof e=="function"?a4(db(this,"text",e)):s4(e==null?"":e+""))}function i4(e){return function(t){this.textContent=e.call(this,t)}}function l4(e){var t,n;function r(){var s=e.apply(this,arguments);return s!==n&&(t=(n=s)&&i4(s)),t}return r._value=e,r}function c4(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,l4(e))}function u4(){for(var e=this._name,t=this._id,n=QR(),r=this._groups,s=r.length,l=0;l<s;++l)for(var c=r[l],u=c.length,f,p=0;p<u;++p)if(f=c[p]){var h=bs(f,t);vf(f,e,n,p,c,{time:h.time+h.delay+h.duration,delay:0,duration:h.duration,ease:h.ease})}return new da(r,this._parents,e,n)}function d4(){var e,t,n=this,r=n._id,s=n.size();return new Promise(function(l,c){var u={value:c},f={value:function(){--s===0&&l()}};n.each(function(){var p=zs(this,r),h=p.on;h!==e&&(t=(e=h).copy(),t._.cancel.push(u),t._.interrupt.push(u),t._.end.push(f)),p.on=t}),s===0&&l()})}var h4=0;function da(e,t,n,r){this._groups=e,this._parents=t,this._name=n,this._id=r}function QR(){return++h4}var ia=Bu.prototype;da.prototype={constructor:da,select:VP,selectAll:GP,selectChild:ia.selectChild,selectChildren:ia.selectChildren,filter:FP,merge:qP,selection:YP,transition:u4,call:ia.call,nodes:ia.nodes,node:ia.node,size:ia.size,empty:ia.empty,each:ia.each,on:UP,attr:NP,attrTween:CP,style:e4,styleTween:r4,text:o4,textTween:c4,remove:WP,tween:gP,delay:AP,duration:$P,ease:LP,easeVarying:DP,end:d4,[Symbol.iterator]:ia[Symbol.iterator]};function f4(e){return((e*=2)<=1?e*e*e:(e-=2)*e*e+2)/2}var p4={time:null,delay:0,duration:250,ease:f4};function m4(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 g4(e){var t,n;e instanceof da?(t=e._id,e=e._name):(t=QR(),(n=p4).time=cb(),e=e==null?null:e+"");for(var r=this._groups,s=r.length,l=0;l<s;++l)for(var c=r[l],u=c.length,f,p=0;p<u;++p)(f=c[p])&&vf(f,e,t,p,c,n||m4(f,t));return new da(r,this._parents,e,t)}Bu.prototype.interrupt=fP;Bu.prototype.transition=g4;const ch=e=>()=>e;function y4(e,{sourceEvent:t,target:n,transform:r,dispatch:s}){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:r,enumerable:!0,configurable:!0},_:{value:s}})}function ca(e,t,n){this.k=e,this.x=t,this.y=n}ca.prototype={constructor:ca,scale:function(e){return e===1?this:new ca(this.k*e,this.x,this.y)},translate:function(e,t){return e===0&t===0?this:new ca(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 ua=new ca(1,0,0);ca.prototype;function pm(e){e.stopImmediatePropagation()}function eu(e){e.preventDefault(),e.stopImmediatePropagation()}function w4(e){return(!e.ctrlKey||e.type==="wheel")&&!e.button}function v4(){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 fN(){return this.__zoom||ua}function x4(e){return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*(e.ctrlKey?10:1)}function b4(){return navigator.maxTouchPoints||"ontouchstart"in this}function k4(e,t,n){var r=e.invertX(t[0][0])-n[0][0],s=e.invertX(t[1][0])-n[1][0],l=e.invertY(t[0][1])-n[0][1],c=e.invertY(t[1][1])-n[1][1];return e.translate(s>r?(r+s)/2:Math.min(0,r)||Math.max(0,s),c>l?(l+c)/2:Math.min(0,l)||Math.max(0,c))}function JR(){var e=w4,t=v4,n=k4,r=x4,s=b4,l=[0,1/0],c=[[-1/0,-1/0],[1/0,1/0]],u=250,f=aP,p=gf("start","zoom","end"),h,m,y,v=500,S=150,b=0,_=10;function k(M){M.property("__zoom",fN).on("wheel.zoom",q,{passive:!1}).on("mousedown.zoom",B).on("dblclick.zoom",P).filter(s).on("touchstart.zoom",W).on("touchmove.zoom",ne).on("touchend.zoom touchcancel.zoom",ee).style("-webkit-tap-highlight-color","rgba(0,0,0,0)")}k.transform=function(M,X,V,G){var F=M.selection?M.selection():M;F.property("__zoom",fN),M!==F?R(M,X,V,G):F.interrupt().each(function(){I(this,arguments).event(G).start().zoom(null,typeof X=="function"?X.apply(this,arguments):X).end()})},k.scaleBy=function(M,X,V,G){k.scaleTo(M,function(){var F=this.__zoom.k,L=typeof X=="function"?X.apply(this,arguments):X;return F*L},V,G)},k.scaleTo=function(M,X,V,G){k.transform(M,function(){var F=t.apply(this,arguments),L=this.__zoom,H=V==null?C(F):typeof V=="function"?V.apply(this,arguments):V,D=L.invert(H),K=typeof X=="function"?X.apply(this,arguments):X;return n(E(j(L,K),H,D),F,c)},V,G)},k.translateBy=function(M,X,V,G){k.transform(M,function(){return n(this.__zoom.translate(typeof X=="function"?X.apply(this,arguments):X,typeof V=="function"?V.apply(this,arguments):V),t.apply(this,arguments),c)},null,G)},k.translateTo=function(M,X,V,G,F){k.transform(M,function(){var L=t.apply(this,arguments),H=this.__zoom,D=G==null?C(L):typeof G=="function"?G.apply(this,arguments):G;return n(ua.translate(D[0],D[1]).scale(H.k).translate(typeof X=="function"?-X.apply(this,arguments):-X,typeof V=="function"?-V.apply(this,arguments):-V),L,c)},G,F)};function j(M,X){return X=Math.max(l[0],Math.min(l[1],X)),X===M.k?M:new ca(X,M.x,M.y)}function E(M,X,V){var G=X[0]-V[0]*M.k,F=X[1]-V[1]*M.k;return G===M.x&&F===M.y?M:new ca(M.k,G,F)}function C(M){return[(+M[0][0]+ +M[1][0])/2,(+M[0][1]+ +M[1][1])/2]}function R(M,X,V,G){M.on("start.zoom",function(){I(this,arguments).event(G).start()}).on("interrupt.zoom end.zoom",function(){I(this,arguments).event(G).end()}).tween("zoom",function(){var F=this,L=arguments,H=I(F,L).event(G),D=t.apply(F,L),K=V==null?C(D):typeof V=="function"?V.apply(F,L):V,re=Math.max(D[1][0]-D[0][0],D[1][1]-D[0][1]),z=F.__zoom,Z=typeof X=="function"?X.apply(F,L):X,U=f(z.invert(K).concat(re/z.k),Z.invert(K).concat(re/Z.k));return function(ae){if(ae===1)ae=Z;else{var le=U(ae),ge=re/le[2];ae=new ca(ge,K[0]-le[0]*ge,K[1]-le[1]*ge)}H.zoom(null,ae)}})}function I(M,X,V){return!V&&M.__zooming||new $(M,X)}function $(M,X){this.that=M,this.args=X,this.active=0,this.sourceEvent=null,this.extent=t.apply(M,X),this.taps=0}$.prototype={event:function(M){return M&&(this.sourceEvent=M),this},start:function(){return++this.active===1&&(this.that.__zooming=this,this.emit("start")),this},zoom:function(M,X){return this.mouse&&M!=="mouse"&&(this.mouse[1]=X.invert(this.mouse[0])),this.touch0&&M!=="touch"&&(this.touch0[1]=X.invert(this.touch0[0])),this.touch1&&M!=="touch"&&(this.touch1[1]=X.invert(this.touch1[0])),this.that.__zoom=X,this.emit("zoom"),this},end:function(){return--this.active===0&&(delete this.that.__zooming,this.emit("end")),this},emit:function(M){var X=Lr(this.that).datum();p.call(M,this.that,new y4(M,{sourceEvent:this.sourceEvent,target:k,transform:this.that.__zoom,dispatch:p}),X)}};function q(M,...X){if(!e.apply(this,arguments))return;var V=I(this,X).event(M),G=this.__zoom,F=Math.max(l[0],Math.min(l[1],G.k*Math.pow(2,r.apply(this,arguments)))),L=fs(M);if(V.wheel)(V.mouse[0][0]!==L[0]||V.mouse[0][1]!==L[1])&&(V.mouse[1]=G.invert(V.mouse[0]=L)),clearTimeout(V.wheel);else{if(G.k===F)return;V.mouse=[L,G.invert(L)],Dh(this),V.start()}eu(M),V.wheel=setTimeout(H,S),V.zoom("mouse",n(E(j(G,F),V.mouse[0],V.mouse[1]),V.extent,c));function H(){V.wheel=null,V.end()}}function B(M,...X){if(y||!e.apply(this,arguments))return;var V=M.currentTarget,G=I(this,X,!0).event(M),F=Lr(M.view).on("mousemove.zoom",K,!0).on("mouseup.zoom",re,!0),L=fs(M,V),H=M.clientX,D=M.clientY;DR(M.view),pm(M),G.mouse=[L,this.__zoom.invert(L)],Dh(this),G.start();function K(z){if(eu(z),!G.moved){var Z=z.clientX-H,U=z.clientY-D;G.moved=Z*Z+U*U>b}G.event(z).zoom("mouse",n(E(G.that.__zoom,G.mouse[0]=fs(z,V),G.mouse[1]),G.extent,c))}function re(z){F.on("mousemove.zoom mouseup.zoom",null),FR(z.view,G.moved),eu(z),G.event(z).end()}}function P(M,...X){if(e.apply(this,arguments)){var V=this.__zoom,G=fs(M.changedTouches?M.changedTouches[0]:M,this),F=V.invert(G),L=V.k*(M.shiftKey?.5:2),H=n(E(j(V,L),G,F),t.apply(this,X),c);eu(M),u>0?Lr(this).transition().duration(u).call(R,H,G,M):Lr(this).call(k.transform,H,G,M)}}function W(M,...X){if(e.apply(this,arguments)){var V=M.touches,G=V.length,F=I(this,X,M.changedTouches.length===G).event(M),L,H,D,K;for(pm(M),H=0;H<G;++H)D=V[H],K=fs(D,this),K=[K,this.__zoom.invert(K),D.identifier],F.touch0?!F.touch1&&F.touch0[2]!==K[2]&&(F.touch1=K,F.taps=0):(F.touch0=K,L=!0,F.taps=1+!!h);h&&(h=clearTimeout(h)),L&&(F.taps<2&&(m=K[0],h=setTimeout(function(){h=null},v)),Dh(this),F.start())}}function ne(M,...X){if(this.__zooming){var V=I(this,X).event(M),G=M.changedTouches,F=G.length,L,H,D,K;for(eu(M),L=0;L<F;++L)H=G[L],D=fs(H,this),V.touch0&&V.touch0[2]===H.identifier?V.touch0[0]=D:V.touch1&&V.touch1[2]===H.identifier&&(V.touch1[0]=D);if(H=V.that.__zoom,V.touch1){var re=V.touch0[0],z=V.touch0[1],Z=V.touch1[0],U=V.touch1[1],ae=(ae=Z[0]-re[0])*ae+(ae=Z[1]-re[1])*ae,le=(le=U[0]-z[0])*le+(le=U[1]-z[1])*le;H=j(H,Math.sqrt(ae/le)),D=[(re[0]+Z[0])/2,(re[1]+Z[1])/2],K=[(z[0]+U[0])/2,(z[1]+U[1])/2]}else if(V.touch0)D=V.touch0[0],K=V.touch0[1];else return;V.zoom("touch",n(E(H,D,K),V.extent,c))}}function ee(M,...X){if(this.__zooming){var V=I(this,X).event(M),G=M.changedTouches,F=G.length,L,H;for(pm(M),y&&clearTimeout(y),y=setTimeout(function(){y=null},v),L=0;L<F;++L)H=G[L],V.touch0&&V.touch0[2]===H.identifier?delete V.touch0:V.touch1&&V.touch1[2]===H.identifier&&delete V.touch1;if(V.touch1&&!V.touch0&&(V.touch0=V.touch1,delete V.touch1),V.touch0)V.touch0[1]=this.__zoom.invert(V.touch0[0]);else if(V.end(),V.taps===2&&(H=fs(H,this),Math.hypot(m[0]-H[0],m[1]-H[1])<_)){var D=Lr(this).on("dblclick.zoom");D&&D.apply(this,arguments)}}}return k.wheelDelta=function(M){return arguments.length?(r=typeof M=="function"?M:ch(+M),k):r},k.filter=function(M){return arguments.length?(e=typeof M=="function"?M:ch(!!M),k):e},k.touchable=function(M){return arguments.length?(s=typeof M=="function"?M:ch(!!M),k):s},k.extent=function(M){return arguments.length?(t=typeof M=="function"?M:ch([[+M[0][0],+M[0][1]],[+M[1][0],+M[1][1]]]),k):t},k.scaleExtent=function(M){return arguments.length?(l[0]=+M[0],l[1]=+M[1],k):[l[0],l[1]]},k.translateExtent=function(M){return arguments.length?(c[0][0]=+M[0][0],c[1][0]=+M[1][0],c[0][1]=+M[0][1],c[1][1]=+M[1][1],k):[[c[0][0],c[0][1]],[c[1][0],c[1][1]]]},k.constrain=function(M){return arguments.length?(n=M,k):n},k.duration=function(M){return arguments.length?(u=+M,k):u},k.interpolate=function(M){return arguments.length?(f=M,k):f},k.on=function(){var M=p.on.apply(p,arguments);return M===p?k:M},k.clickDistance=function(M){return arguments.length?(b=(M=+M)*M,k):Math.sqrt(b)},k.tapDistance=function(M){return arguments.length?(_=+M,k):_},k}var On=SR();const xf=w.createContext(null),N4=xf.Provider,ha={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,t)=>`Couldn't create edge for ${e?"target":"source"} handle id: "${e?t.targetHandle:t.sourceHandle}", edge id: ${t.id}.`,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.`},eA=ha.error001();function Et(e,t){const n=w.useContext(xf);if(n===null)throw new Error(eA);return jR(n,e,t)}const tn=()=>{const e=w.useContext(xf);if(e===null)throw new Error(eA);return w.useMemo(()=>({getState:e.getState,setState:e.setState,subscribe:e.subscribe,destroy:e.destroy}),[e])},S4=e=>e.userSelectionActive?"none":"all";function hb({position:e,children:t,className:n,style:r,...s}){const l=Et(S4),c=`${e}`.split("-");return ve.createElement("div",{className:jn(["react-flow__panel",n,...c]),style:{...r,pointerEvents:l},...s},t)}function j4({proOptions:e,position:t="bottom-right"}){return e!=null&&e.hideAttribution?null:ve.createElement(hb,{position:t,className:"react-flow__attribution","data-message":"Please only hide this attribution when you are subscribed to React Flow Pro: https://reactflow.dev/pro"},ve.createElement("a",{href:"https://reactflow.dev",target:"_blank",rel:"noopener noreferrer","aria-label":"React Flow attribution"},"React Flow"))}const _4=({x:e,y:t,label:n,labelStyle:r={},labelShowBg:s=!0,labelBgStyle:l={},labelBgPadding:c=[2,4],labelBgBorderRadius:u=2,children:f,className:p,...h})=>{const m=w.useRef(null),[y,v]=w.useState({x:0,y:0,width:0,height:0}),S=jn(["react-flow__edge-textwrapper",p]);return w.useEffect(()=>{if(m.current){const b=m.current.getBBox();v({x:b.x,y:b.y,width:b.width,height:b.height})}},[n]),typeof n>"u"||!n?null:ve.createElement("g",{transform:`translate(${e-y.width/2} ${t-y.height/2})`,className:S,visibility:y.width?"visible":"hidden",...h},s&&ve.createElement("rect",{width:y.width+2*c[0],x:-c[0],y:-c[1],height:y.height+2*c[1],className:"react-flow__edge-textbg",style:l,rx:u,ry:u}),ve.createElement("text",{className:"react-flow__edge-text",y:y.height/2,dy:"0.3em",ref:m,style:r},n),f)};var E4=w.memo(_4);const fb=e=>({width:e.offsetWidth,height:e.offsetHeight}),Wl=(e,t=0,n=1)=>Math.min(Math.max(e,t),n),pb=(e={x:0,y:0},t)=>({x:Wl(e.x,t[0][0],t[1][0]),y:Wl(e.y,t[0][1],t[1][1])}),pN=(e,t,n)=>e<t?Wl(Math.abs(e-t),1,50)/50:e>n?-Wl(Math.abs(e-n),1,50)/50:0,tA=(e,t)=>{const n=pN(e.x,35,t.width-35)*20,r=pN(e.y,35,t.height-35)*20;return[n,r]},nA=e=>{var t;return((t=e.getRootNode)==null?void 0:t.call(e))||(window==null?void 0:window.document)},rA=(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)}),ju=({x:e,y:t,width:n,height:r})=>({x:e,y:t,x2:e+n,y2:t+r}),sA=({x:e,y:t,x2:n,y2:r})=>({x:e,y:t,width:n-e,height:r-t}),mN=e=>({...e.positionAbsolute||{x:0,y:0},width:e.width||0,height:e.height||0}),C4=(e,t)=>sA(rA(ju(e),ju(t))),v0=(e,t)=>{const n=Math.max(0,Math.min(e.x+e.width,t.x+t.width)-Math.max(e.x,t.x)),r=Math.max(0,Math.min(e.y+e.height,t.y+t.height)-Math.max(e.y,t.y));return Math.ceil(n*r)},T4=e=>Pr(e.width)&&Pr(e.height)&&Pr(e.x)&&Pr(e.y),Pr=e=>!isNaN(e)&&isFinite(e),Wt=Symbol.for("internals"),aA=["Enter"," ","Escape"],R4=(e,t)=>{},A4=e=>"nativeEvent"in e;function x0(e){var s,l;const t=A4(e)?e.nativeEvent:e,n=((l=(s=t.composedPath)==null?void 0:s.call(t))==null?void 0:l[0])||e.target;return["INPUT","SELECT","TEXTAREA"].includes(n==null?void 0:n.nodeName)||(n==null?void 0:n.hasAttribute("contenteditable"))||!!(n!=null&&n.closest(".nokey"))}const oA=e=>"clientX"in e,so=(e,t)=>{var l,c;const n=oA(e),r=n?e.clientX:(l=e.touches)==null?void 0:l[0].clientX,s=n?e.clientY:(c=e.touches)==null?void 0:c[0].clientY;return{x:r-((t==null?void 0:t.left)??0),y:s-((t==null?void 0:t.top)??0)}},Zh=()=>{var e;return typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)==null?void 0:e.indexOf("Mac"))>=0},Uu=({id:e,path:t,labelX:n,labelY:r,label:s,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:m,markerStart:y,interactionWidth:v=20})=>ve.createElement(ve.Fragment,null,ve.createElement("path",{id:e,style:h,d:t,fill:"none",className:"react-flow__edge-path",markerEnd:m,markerStart:y}),v&&ve.createElement("path",{d:t,fill:"none",strokeOpacity:0,strokeWidth:v,className:"react-flow__edge-interaction"}),s&&Pr(n)&&Pr(r)?ve.createElement(E4,{x:n,y:r,label:s,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:p}):null);Uu.displayName="BaseEdge";function tu(e,t,n){return n===void 0?n:r=>{const s=t().edges.find(l=>l.id===e);s&&n(r,{...s})}}function iA({sourceX:e,sourceY:t,targetX:n,targetY:r}){const s=Math.abs(n-e)/2,l=n<e?n+s:n-s,c=Math.abs(r-t)/2,u=r<t?r+c:r-c;return[l,u,s,c]}function lA({sourceX:e,sourceY:t,targetX:n,targetY:r,sourceControlX:s,sourceControlY:l,targetControlX:c,targetControlY:u}){const f=e*.125+s*.375+c*.375+n*.125,p=t*.125+l*.375+u*.375+r*.125,h=Math.abs(f-e),m=Math.abs(p-t);return[f,p,h,m]}var mi;(function(e){e.Strict="strict",e.Loose="loose"})(mi||(mi={}));var li;(function(e){e.Free="free",e.Vertical="vertical",e.Horizontal="horizontal"})(li||(li={}));var _u;(function(e){e.Partial="partial",e.Full="full"})(_u||(_u={}));var eo;(function(e){e.Bezier="default",e.Straight="straight",e.Step="step",e.SmoothStep="smoothstep",e.SimpleBezier="simplebezier"})(eo||(eo={}));var Qh;(function(e){e.Arrow="arrow",e.ArrowClosed="arrowclosed"})(Qh||(Qh={}));var nt;(function(e){e.Left="left",e.Top="top",e.Right="right",e.Bottom="bottom"})(nt||(nt={}));function gN({pos:e,x1:t,y1:n,x2:r,y2:s}){return e===nt.Left||e===nt.Right?[.5*(t+r),n]:[t,.5*(n+s)]}function cA({sourceX:e,sourceY:t,sourcePosition:n=nt.Bottom,targetX:r,targetY:s,targetPosition:l=nt.Top}){const[c,u]=gN({pos:n,x1:e,y1:t,x2:r,y2:s}),[f,p]=gN({pos:l,x1:r,y1:s,x2:e,y2:t}),[h,m,y,v]=lA({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:c,sourceControlY:u,targetControlX:f,targetControlY:p});return[`M${e},${t} C${c},${u} ${f},${p} ${r},${s}`,h,m,y,v]}const mb=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=nt.Bottom,targetPosition:l=nt.Top,label:c,labelStyle:u,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:y,markerEnd:v,markerStart:S,interactionWidth:b})=>{const[_,k,j]=cA({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:l});return ve.createElement(Uu,{path:_,labelX:k,labelY:j,label:c,labelStyle:u,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:y,markerEnd:v,markerStart:S,interactionWidth:b})});mb.displayName="SimpleBezierEdge";const yN={[nt.Left]:{x:-1,y:0},[nt.Right]:{x:1,y:0},[nt.Top]:{x:0,y:-1},[nt.Bottom]:{x:0,y:1}},M4=({source:e,sourcePosition:t=nt.Bottom,target:n})=>t===nt.Left||t===nt.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},wN=(e,t)=>Math.sqrt(Math.pow(t.x-e.x,2)+Math.pow(t.y-e.y,2));function I4({source:e,sourcePosition:t=nt.Bottom,target:n,targetPosition:r=nt.Top,center:s,offset:l}){const c=yN[t],u=yN[r],f={x:e.x+c.x*l,y:e.y+c.y*l},p={x:n.x+u.x*l,y:n.y+u.y*l},h=M4({source:f,sourcePosition:t,target:p}),m=h.x!==0?"x":"y",y=h[m];let v=[],S,b;const _={x:0,y:0},k={x:0,y:0},[j,E,C,R]=iA({sourceX:e.x,sourceY:e.y,targetX:n.x,targetY:n.y});if(c[m]*u[m]===-1){S=s.x??j,b=s.y??E;const $=[{x:S,y:f.y},{x:S,y:p.y}],q=[{x:f.x,y:b},{x:p.x,y:b}];c[m]===y?v=m==="x"?$:q:v=m==="x"?q:$}else{const $=[{x:f.x,y:p.y}],q=[{x:p.x,y:f.y}];if(m==="x"?v=c.x===y?q:$:v=c.y===y?$:q,t===r){const ee=Math.abs(e[m]-n[m]);if(ee<=l){const M=Math.min(l-1,l-ee);c[m]===y?_[m]=(f[m]>e[m]?-1:1)*M:k[m]=(p[m]>n[m]?-1:1)*M}}if(t!==r){const ee=m==="x"?"y":"x",M=c[m]===u[ee],X=f[ee]>p[ee],V=f[ee]<p[ee];(c[m]===1&&(!M&&X||M&&V)||c[m]!==1&&(!M&&V||M&&X))&&(v=m==="x"?$:q)}const B={x:f.x+_.x,y:f.y+_.y},P={x:p.x+k.x,y:p.y+k.y},W=Math.max(Math.abs(B.x-v[0].x),Math.abs(P.x-v[0].x)),ne=Math.max(Math.abs(B.y-v[0].y),Math.abs(P.y-v[0].y));W>=ne?(S=(B.x+P.x)/2,b=v[0].y):(S=v[0].x,b=(B.y+P.y)/2)}return[[e,{x:f.x+_.x,y:f.y+_.y},...v,{x:p.x+k.x,y:p.y+k.y},n],S,b,C,R]}function $4(e,t,n,r){const s=Math.min(wN(e,t)/2,wN(t,n)/2,r),{x:l,y:c}=t;if(e.x===l&&l===n.x||e.y===c&&c===n.y)return`L${l} ${c}`;if(e.y===c){const p=e.x<n.x?-1:1,h=e.y<n.y?1:-1;return`L ${l+s*p},${c}Q ${l},${c} ${l},${c+s*h}`}const u=e.x<n.x?1:-1,f=e.y<n.y?-1:1;return`L ${l},${c+s*f}Q ${l},${c} ${l+s*u},${c}`}function b0({sourceX:e,sourceY:t,sourcePosition:n=nt.Bottom,targetX:r,targetY:s,targetPosition:l=nt.Top,borderRadius:c=5,centerX:u,centerY:f,offset:p=20}){const[h,m,y,v,S]=I4({source:{x:e,y:t},sourcePosition:n,target:{x:r,y:s},targetPosition:l,center:{x:u,y:f},offset:p});return[h.reduce((_,k,j)=>{let E="";return j>0&&j<h.length-1?E=$4(h[j-1],k,h[j+1],c):E=`${j===0?"M":"L"}${k.x} ${k.y}`,_+=E,_},""),m,y,v,S]}const bf=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:p,style:h,sourcePosition:m=nt.Bottom,targetPosition:y=nt.Top,markerEnd:v,markerStart:S,pathOptions:b,interactionWidth:_})=>{const[k,j,E]=b0({sourceX:e,sourceY:t,sourcePosition:m,targetX:n,targetY:r,targetPosition:y,borderRadius:b==null?void 0:b.borderRadius,offset:b==null?void 0:b.offset});return ve.createElement(Uu,{path:k,labelX:j,labelY:E,label:s,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:v,markerStart:S,interactionWidth:_})});bf.displayName="SmoothStepEdge";const gb=w.memo(e=>{var t;return ve.createElement(bf,{...e,pathOptions:w.useMemo(()=>{var n;return{borderRadius:0,offset:(n=e.pathOptions)==null?void 0:n.offset}},[(t=e.pathOptions)==null?void 0:t.offset])})});gb.displayName="StepEdge";function O4({sourceX:e,sourceY:t,targetX:n,targetY:r}){const[s,l,c,u]=iA({sourceX:e,sourceY:t,targetX:n,targetY:r});return[`M ${e},${t}L ${n},${r}`,s,l,c,u]}const yb=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,label:s,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:m,markerStart:y,interactionWidth:v})=>{const[S,b,_]=O4({sourceX:e,sourceY:t,targetX:n,targetY:r});return ve.createElement(Uu,{path:S,labelX:b,labelY:_,label:s,labelStyle:l,labelShowBg:c,labelBgStyle:u,labelBgPadding:f,labelBgBorderRadius:p,style:h,markerEnd:m,markerStart:y,interactionWidth:v})});yb.displayName="StraightEdge";function uh(e,t){return e>=0?.5*e:t*25*Math.sqrt(-e)}function vN({pos:e,x1:t,y1:n,x2:r,y2:s,c:l}){switch(e){case nt.Left:return[t-uh(t-r,l),n];case nt.Right:return[t+uh(r-t,l),n];case nt.Top:return[t,n-uh(n-s,l)];case nt.Bottom:return[t,n+uh(s-n,l)]}}function wb({sourceX:e,sourceY:t,sourcePosition:n=nt.Bottom,targetX:r,targetY:s,targetPosition:l=nt.Top,curvature:c=.25}){const[u,f]=vN({pos:n,x1:e,y1:t,x2:r,y2:s,c}),[p,h]=vN({pos:l,x1:r,y1:s,x2:e,y2:t,c}),[m,y,v,S]=lA({sourceX:e,sourceY:t,targetX:r,targetY:s,sourceControlX:u,sourceControlY:f,targetControlX:p,targetControlY:h});return[`M${e},${t} C${u},${f} ${p},${h} ${r},${s}`,m,y,v,S]}const Jh=w.memo(({sourceX:e,sourceY:t,targetX:n,targetY:r,sourcePosition:s=nt.Bottom,targetPosition:l=nt.Top,label:c,labelStyle:u,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:y,markerEnd:v,markerStart:S,pathOptions:b,interactionWidth:_})=>{const[k,j,E]=wb({sourceX:e,sourceY:t,sourcePosition:s,targetX:n,targetY:r,targetPosition:l,curvature:b==null?void 0:b.curvature});return ve.createElement(Uu,{path:k,labelX:j,labelY:E,label:c,labelStyle:u,labelShowBg:f,labelBgStyle:p,labelBgPadding:h,labelBgBorderRadius:m,style:y,markerEnd:v,markerStart:S,interactionWidth:_})});Jh.displayName="BezierEdge";const vb=w.createContext(null),L4=vb.Provider;vb.Consumer;const P4=()=>w.useContext(vb),D4=e=>"id"in e&&"source"in e&&"target"in e,F4=({source:e,sourceHandle:t,target:n,targetHandle:r})=>`reactflow__edge-${e}${t||""}-${n}${r||""}`,k0=(e,t)=>typeof e>"u"?"":typeof e=="string"?e:`${t?`${t}__`:""}${Object.keys(e).sort().map(r=>`${r}=${e[r]}`).join("&")}`,q4=(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)),B4=(e,t)=>{if(!e.source||!e.target)return t;let n;return D4(e)?n={...e}:n={...e,id:F4(e)},q4(n,t)?t:t.concat(n)},N0=({x:e,y:t},[n,r,s],l,[c,u])=>{const f={x:(e-n)/s,y:(t-r)/s};return l?{x:c*Math.round(f.x/c),y:u*Math.round(f.y/u)}:f},uA=({x:e,y:t},[n,r,s])=>({x:e*s+n,y:t*s+r}),ui=(e,t=[0,0])=>{if(!e)return{x:0,y:0,positionAbsolute:{x:0,y:0}};const n=(e.width??0)*t[0],r=(e.height??0)*t[1],s={x:e.position.x-n,y:e.position.y-r};return{...s,positionAbsolute:e.positionAbsolute?{x:e.positionAbsolute.x-n,y:e.positionAbsolute.y-r}:s}},kf=(e,t=[0,0])=>{if(e.length===0)return{x:0,y:0,width:0,height:0};const n=e.reduce((r,s)=>{const{x:l,y:c}=ui(s,t).positionAbsolute;return rA(r,ju({x:l,y:c,width:s.width||0,height:s.height||0}))},{x:1/0,y:1/0,x2:-1/0,y2:-1/0});return sA(n)},dA=(e,t,[n,r,s]=[0,0,1],l=!1,c=!1,u=[0,0])=>{const f={x:(t.x-n)/s,y:(t.y-r)/s,width:t.width/s,height:t.height/s},p=[];return e.forEach(h=>{const{width:m,height:y,selectable:v=!0,hidden:S=!1}=h;if(c&&!v||S)return!1;const{positionAbsolute:b}=ui(h,u),_={x:b.x,y:b.y,width:m||0,height:y||0},k=v0(f,_),j=typeof m>"u"||typeof y>"u"||m===null||y===null,E=l&&k>0,C=(m||0)*(y||0);(j||E||k>=C||h.dragging)&&p.push(h)}),p},hA=(e,t)=>{const n=e.map(r=>r.id);return t.filter(r=>n.includes(r.source)||n.includes(r.target))},fA=(e,t,n,r,s,l=.1)=>{const c=t/(e.width*(1+l)),u=n/(e.height*(1+l)),f=Math.min(c,u),p=Wl(f,r,s),h=e.x+e.width/2,m=e.y+e.height/2,y=t/2-h*p,v=n/2-m*p;return{x:y,y:v,zoom:p}},ai=(e,t=0)=>e.transition().duration(t);function xN(e,t,n,r){return(t[n]||[]).reduce((s,l)=>{var c,u;return`${e.id}-${l.id}-${n}`!==r&&s.push({id:l.id||null,type:n,nodeId:e.id,x:(((c=e.positionAbsolute)==null?void 0:c.x)??0)+l.x+l.width/2,y:(((u=e.positionAbsolute)==null?void 0:u.y)??0)+l.y+l.height/2}),s},[])}function z4(e,t,n,r,s,l){const{x:c,y:u}=so(e),p=t.elementsFromPoint(c,u).find(S=>S.classList.contains("react-flow__handle"));if(p){const S=p.getAttribute("data-nodeid");if(S){const b=xb(void 0,p),_=p.getAttribute("data-handleid"),k=l({nodeId:S,id:_,type:b});if(k){const j=s.find(E=>E.nodeId===S&&E.type===b&&E.id===_);return{handle:{id:_,type:b,nodeId:S,x:(j==null?void 0:j.x)||n.x,y:(j==null?void 0:j.y)||n.y},validHandleResult:k}}}}let h=[],m=1/0;if(s.forEach(S=>{const b=Math.sqrt((S.x-n.x)**2+(S.y-n.y)**2);if(b<=r){const _=l(S);b<=m&&(b<m?h=[{handle:S,validHandleResult:_}]:b===m&&h.push({handle:S,validHandleResult:_}),m=b)}}),!h.length)return{handle:null,validHandleResult:pA()};if(h.length===1)return h[0];const y=h.some(({validHandleResult:S})=>S.isValid),v=h.some(({handle:S})=>S.type==="target");return h.find(({handle:S,validHandleResult:b})=>v?S.type==="target":y?b.isValid:!0)||h[0]}const U4={source:null,target:null,sourceHandle:null,targetHandle:null},pA=()=>({handleDomNode:null,isValid:!1,connection:U4,endHandle:null});function mA(e,t,n,r,s,l,c){const u=s==="target",f=c.querySelector(`.react-flow__handle[data-id="${e==null?void 0:e.nodeId}-${e==null?void 0:e.id}-${e==null?void 0:e.type}"]`),p={...pA(),handleDomNode:f};if(f){const h=xb(void 0,f),m=f.getAttribute("data-nodeid"),y=f.getAttribute("data-handleid"),v=f.classList.contains("connectable"),S=f.classList.contains("connectableend"),b={source:u?m:n,sourceHandle:u?y:r,target:u?n:m,targetHandle:u?r:y};p.connection=b,v&&S&&(t===mi.Strict?u&&h==="source"||!u&&h==="target":m!==n||y!==r)&&(p.endHandle={nodeId:m,handleId:y,type:h},p.isValid=l(b))}return p}function H4({nodes:e,nodeId:t,handleId:n,handleType:r}){return e.reduce((s,l)=>{if(l[Wt]){const{handleBounds:c}=l[Wt];let u=[],f=[];c&&(u=xN(l,c,"source",`${t}-${n}-${r}`),f=xN(l,c,"target",`${t}-${n}-${r}`)),s.push(...u,...f)}return s},[])}function xb(e,t){return e||(t!=null&&t.classList.contains("target")?"target":t!=null&&t.classList.contains("source")?"source":null)}function mm(e){e==null||e.classList.remove("valid","connecting","react-flow__handle-valid","react-flow__handle-connecting")}function W4(e,t){let n=null;return t?n="valid":e&&!t&&(n="invalid"),n}function gA({event:e,handleId:t,nodeId:n,onConnect:r,isTarget:s,getState:l,setState:c,isValidConnection:u,edgeUpdaterType:f,onReconnectEnd:p}){const h=nA(e.target),{connectionMode:m,domNode:y,autoPanOnConnect:v,connectionRadius:S,onConnectStart:b,panBy:_,getNodes:k,cancelConnection:j}=l();let E=0,C;const{x:R,y:I}=so(e),$=h==null?void 0:h.elementFromPoint(R,I),q=xb(f,$),B=y==null?void 0:y.getBoundingClientRect();if(!B||!q)return;let P,W=so(e,B),ne=!1,ee=null,M=!1,X=null;const V=H4({nodes:k(),nodeId:n,handleId:t,handleType:q}),G=()=>{if(!v)return;const[H,D]=tA(W,B);_({x:H,y:D}),E=requestAnimationFrame(G)};c({connectionPosition:W,connectionStatus:null,connectionNodeId:n,connectionHandleId:t,connectionHandleType:q,connectionStartHandle:{nodeId:n,handleId:t,type:q},connectionEndHandle:null}),b==null||b(e,{nodeId:n,handleId:t,handleType:q});function F(H){const{transform:D}=l();W=so(H,B);const{handle:K,validHandleResult:re}=z4(H,h,N0(W,D,!1,[1,1]),S,V,z=>mA(z,m,n,t,s?"target":"source",u,h));if(C=K,ne||(G(),ne=!0),X=re.handleDomNode,ee=re.connection,M=re.isValid,c({connectionPosition:C&&M?uA({x:C.x,y:C.y},D):W,connectionStatus:W4(!!C,M),connectionEndHandle:re.endHandle}),!C&&!M&&!X)return mm(P);ee.source!==ee.target&&X&&(mm(P),P=X,X.classList.add("connecting","react-flow__handle-connecting"),X.classList.toggle("valid",M),X.classList.toggle("react-flow__handle-valid",M))}function L(H){var D,K;(C||X)&&ee&&M&&(r==null||r(ee)),(K=(D=l()).onConnectEnd)==null||K.call(D,H),f&&(p==null||p(H)),mm(P),j(),cancelAnimationFrame(E),ne=!1,M=!1,ee=null,X=null,h.removeEventListener("mousemove",F),h.removeEventListener("mouseup",L),h.removeEventListener("touchmove",F),h.removeEventListener("touchend",L)}h.addEventListener("mousemove",F),h.addEventListener("mouseup",L),h.addEventListener("touchmove",F),h.addEventListener("touchend",L)}const bN=()=>!0,V4=e=>({connectionStartHandle:e.connectionStartHandle,connectOnClick:e.connectOnClick,noPanClassName:e.noPanClassName}),G4=(e,t,n)=>r=>{const{connectionStartHandle:s,connectionEndHandle:l,connectionClickStartHandle:c}=r;return{connecting:(s==null?void 0:s.nodeId)===e&&(s==null?void 0:s.handleId)===t&&(s==null?void 0:s.type)===n||(l==null?void 0:l.nodeId)===e&&(l==null?void 0:l.handleId)===t&&(l==null?void 0:l.type)===n,clickConnecting:(c==null?void 0:c.nodeId)===e&&(c==null?void 0:c.handleId)===t&&(c==null?void 0:c.type)===n}},yA=w.forwardRef(({type:e="source",position:t=nt.Top,isValidConnection:n,isConnectable:r=!0,isConnectableStart:s=!0,isConnectableEnd:l=!0,id:c,onConnect:u,children:f,className:p,onMouseDown:h,onTouchStart:m,...y},v)=>{var B,P;const S=c||null,b=e==="target",_=tn(),k=P4(),{connectOnClick:j,noPanClassName:E}=Et(V4,pn),{connecting:C,clickConnecting:R}=Et(G4(k,S,e),pn);k||(P=(B=_.getState()).onError)==null||P.call(B,"010",ha.error010());const I=W=>{const{defaultEdgeOptions:ne,onConnect:ee,hasDefaultEdges:M}=_.getState(),X={...ne,...W};if(M){const{edges:V,setEdges:G}=_.getState();G(B4(X,V))}ee==null||ee(X),u==null||u(X)},$=W=>{if(!k)return;const ne=oA(W);s&&(ne&&W.button===0||!ne)&&gA({event:W,handleId:S,nodeId:k,onConnect:I,isTarget:b,getState:_.getState,setState:_.setState,isValidConnection:n||_.getState().isValidConnection||bN}),ne?h==null||h(W):m==null||m(W)},q=W=>{const{onClickConnectStart:ne,onClickConnectEnd:ee,connectionClickStartHandle:M,connectionMode:X,isValidConnection:V}=_.getState();if(!k||!M&&!s)return;if(!M){ne==null||ne(W,{nodeId:k,handleId:S,handleType:e}),_.setState({connectionClickStartHandle:{nodeId:k,type:e,handleId:S}});return}const G=nA(W.target),F=n||V||bN,{connection:L,isValid:H}=mA({nodeId:k,id:S,type:e},X,M.nodeId,M.handleId||null,M.type,F,G);H&&I(L),ee==null||ee(W),_.setState({connectionClickStartHandle:null})};return ve.createElement("div",{"data-handleid":S,"data-nodeid":k,"data-handlepos":t,"data-id":`${k}-${S}-${e}`,className:jn(["react-flow__handle",`react-flow__handle-${t}`,"nodrag",E,p,{source:!b,target:b,connectable:r,connectablestart:s,connectableend:l,connecting:R,connectionindicator:r&&(s&&!C||l&&C)}]),onMouseDown:$,onTouchStart:$,onClick:j?q:void 0,ref:v,...y},f)});yA.displayName="Handle";var gi=w.memo(yA);const wA=({data:e,isConnectable:t,targetPosition:n=nt.Top,sourcePosition:r=nt.Bottom})=>ve.createElement(ve.Fragment,null,ve.createElement(gi,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label,ve.createElement(gi,{type:"source",position:r,isConnectable:t}));wA.displayName="DefaultNode";var S0=w.memo(wA);const vA=({data:e,isConnectable:t,sourcePosition:n=nt.Bottom})=>ve.createElement(ve.Fragment,null,e==null?void 0:e.label,ve.createElement(gi,{type:"source",position:n,isConnectable:t}));vA.displayName="InputNode";var xA=w.memo(vA);const bA=({data:e,isConnectable:t,targetPosition:n=nt.Top})=>ve.createElement(ve.Fragment,null,ve.createElement(gi,{type:"target",position:n,isConnectable:t}),e==null?void 0:e.label);bA.displayName="OutputNode";var kA=w.memo(bA);const bb=()=>null;bb.displayName="GroupNode";const K4=e=>({selectedNodes:e.getNodes().filter(t=>t.selected),selectedEdges:e.edges.filter(t=>t.selected).map(t=>({...t}))}),dh=e=>e.id;function Y4(e,t){return pn(e.selectedNodes.map(dh),t.selectedNodes.map(dh))&&pn(e.selectedEdges.map(dh),t.selectedEdges.map(dh))}const NA=w.memo(({onSelectionChange:e})=>{const t=tn(),{selectedNodes:n,selectedEdges:r}=Et(K4,Y4);return w.useEffect(()=>{const s={nodes:n,edges:r};e==null||e(s),t.getState().onSelectionChange.forEach(l=>l(s))},[n,r,e]),null});NA.displayName="SelectionListener";const X4=e=>!!e.onSelectionChange;function Z4({onSelectionChange:e}){const t=Et(X4);return e||t?ve.createElement(NA,{onSelectionChange:e}):null}const Q4=e=>({setNodes:e.setNodes,setEdges:e.setEdges,setDefaultNodesAndEdges:e.setDefaultNodesAndEdges,setMinZoom:e.setMinZoom,setMaxZoom:e.setMaxZoom,setTranslateExtent:e.setTranslateExtent,setNodeExtent:e.setNodeExtent,reset:e.reset});function vl(e,t){w.useEffect(()=>{typeof e<"u"&&t(e)},[e])}function mt(e,t,n){w.useEffect(()=>{typeof t<"u"&&n({[e]:t})},[t])}const J4=({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:s,onConnectStart:l,onConnectEnd:c,onClickConnectStart:u,onClickConnectEnd:f,nodesDraggable:p,nodesConnectable:h,nodesFocusable:m,edgesFocusable:y,edgesUpdatable:v,elevateNodesOnSelect:S,minZoom:b,maxZoom:_,nodeExtent:k,onNodesChange:j,onEdgesChange:E,elementsSelectable:C,connectionMode:R,snapGrid:I,snapToGrid:$,translateExtent:q,connectOnClick:B,defaultEdgeOptions:P,fitView:W,fitViewOptions:ne,onNodesDelete:ee,onEdgesDelete:M,onNodeDrag:X,onNodeDragStart:V,onNodeDragStop:G,onSelectionDrag:F,onSelectionDragStart:L,onSelectionDragStop:H,noPanClassName:D,nodeOrigin:K,rfId:re,autoPanOnConnect:z,autoPanOnNodeDrag:Z,onError:U,connectionRadius:ae,isValidConnection:le,nodeDragThreshold:ge})=>{const{setNodes:Ne,setEdges:Ie,setDefaultNodesAndEdges:Ge,setMinZoom:Pe,setMaxZoom:ze,setTranslateExtent:Re,setNodeExtent:st,reset:ue}=Et(Q4,pn),ce=tn();return w.useEffect(()=>{const se=r==null?void 0:r.map(be=>({...be,...P}));return Ge(n,se),()=>{ue()}},[]),mt("defaultEdgeOptions",P,ce.setState),mt("connectionMode",R,ce.setState),mt("onConnect",s,ce.setState),mt("onConnectStart",l,ce.setState),mt("onConnectEnd",c,ce.setState),mt("onClickConnectStart",u,ce.setState),mt("onClickConnectEnd",f,ce.setState),mt("nodesDraggable",p,ce.setState),mt("nodesConnectable",h,ce.setState),mt("nodesFocusable",m,ce.setState),mt("edgesFocusable",y,ce.setState),mt("edgesUpdatable",v,ce.setState),mt("elementsSelectable",C,ce.setState),mt("elevateNodesOnSelect",S,ce.setState),mt("snapToGrid",$,ce.setState),mt("snapGrid",I,ce.setState),mt("onNodesChange",j,ce.setState),mt("onEdgesChange",E,ce.setState),mt("connectOnClick",B,ce.setState),mt("fitViewOnInit",W,ce.setState),mt("fitViewOnInitOptions",ne,ce.setState),mt("onNodesDelete",ee,ce.setState),mt("onEdgesDelete",M,ce.setState),mt("onNodeDrag",X,ce.setState),mt("onNodeDragStart",V,ce.setState),mt("onNodeDragStop",G,ce.setState),mt("onSelectionDrag",F,ce.setState),mt("onSelectionDragStart",L,ce.setState),mt("onSelectionDragStop",H,ce.setState),mt("noPanClassName",D,ce.setState),mt("nodeOrigin",K,ce.setState),mt("rfId",re,ce.setState),mt("autoPanOnConnect",z,ce.setState),mt("autoPanOnNodeDrag",Z,ce.setState),mt("onError",U,ce.setState),mt("connectionRadius",ae,ce.setState),mt("isValidConnection",le,ce.setState),mt("nodeDragThreshold",ge,ce.setState),vl(e,Ne),vl(t,Ie),vl(b,Pe),vl(_,ze),vl(q,Re),vl(k,st),null},kN={display:"none"},eD={position:"absolute",width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0px, 0px, 0px, 0px)",clipPath:"inset(100%)"},SA="react-flow__node-desc",jA="react-flow__edge-desc",tD="react-flow__aria-live",nD=e=>e.ariaLiveMessage;function rD({rfId:e}){const t=Et(nD);return ve.createElement("div",{id:`${tD}-${e}`,"aria-live":"assertive","aria-atomic":"true",style:eD},t)}function sD({rfId:e,disableKeyboardA11y:t}){return ve.createElement(ve.Fragment,null,ve.createElement("div",{id:`${SA}-${e}`,style:kN},"Press enter or space to select a node.",!t&&"You can then use the arrow keys to move the node around."," Press delete to remove it and escape to cancel."," "),ve.createElement("div",{id:`${jA}-${e}`,style:kN},"Press enter or space to select an edge. You can then press delete to remove it or escape to cancel."),!t&&ve.createElement(rD,{rfId:e}))}var Eu=(e=null,t={actInsideInputWithModifier:!0})=>{const[n,r]=w.useState(!1),s=w.useRef(!1),l=w.useRef(new Set([])),[c,u]=w.useMemo(()=>{if(e!==null){const p=(Array.isArray(e)?e:[e]).filter(m=>typeof m=="string").map(m=>m.split("+")),h=p.reduce((m,y)=>m.concat(...y),[]);return[p,h]}return[[],[]]},[e]);return w.useEffect(()=>{const f=typeof document<"u"?document:null,p=(t==null?void 0:t.target)||f;if(e!==null){const h=v=>{if(s.current=v.ctrlKey||v.metaKey||v.shiftKey,(!s.current||s.current&&!t.actInsideInputWithModifier)&&x0(v))return!1;const b=SN(v.code,u);l.current.add(v[b]),NN(c,l.current,!1)&&(v.preventDefault(),r(!0))},m=v=>{if((!s.current||s.current&&!t.actInsideInputWithModifier)&&x0(v))return!1;const b=SN(v.code,u);NN(c,l.current,!0)?(r(!1),l.current.clear()):l.current.delete(v[b]),v.key==="Meta"&&l.current.clear(),s.current=!1},y=()=>{l.current.clear(),r(!1)};return p==null||p.addEventListener("keydown",h),p==null||p.addEventListener("keyup",m),window.addEventListener("blur",y),()=>{p==null||p.removeEventListener("keydown",h),p==null||p.removeEventListener("keyup",m),window.removeEventListener("blur",y)}}},[e,r]),n};function NN(e,t,n){return e.filter(r=>n||r.length===t.size).some(r=>r.every(s=>t.has(s)))}function SN(e,t){return t.includes(e)?"code":"key"}function _A(e,t,n,r){var u,f;const s=e.parentNode||e.parentId;if(!s)return n;const l=t.get(s),c=ui(l,r);return _A(l,t,{x:(n.x??0)+c.x,y:(n.y??0)+c.y,z:(((u=l[Wt])==null?void 0:u.z)??0)>(n.z??0)?((f=l[Wt])==null?void 0:f.z)??0:n.z??0},r)}function EA(e,t,n){e.forEach(r=>{var l;const s=r.parentNode||r.parentId;if(s&&!e.has(s))throw new Error(`Parent node ${s} not found`);if(s||n!=null&&n[r.id]){const{x:c,y:u,z:f}=_A(r,e,{...r.position,z:((l=r[Wt])==null?void 0:l.z)??0},t);r.positionAbsolute={x:c,y:u},r[Wt].z=f,n!=null&&n[r.id]&&(r[Wt].isParent=!0)}})}function gm(e,t,n,r){const s=new Map,l={},c=r?1e3:0;return e.forEach(u=>{var v;const f=(Pr(u.zIndex)?u.zIndex:0)+(u.selected?c:0),p=t.get(u.id),h={...u,positionAbsolute:{x:u.position.x,y:u.position.y}},m=u.parentNode||u.parentId;m&&(l[m]=!0);const y=(p==null?void 0:p.type)&&(p==null?void 0:p.type)!==u.type;Object.defineProperty(h,Wt,{enumerable:!1,value:{handleBounds:y||(v=p==null?void 0:p[Wt])==null?void 0:v.handleBounds,z:f}}),s.set(u.id,h)}),EA(s,n,l),s}function CA(e,t={}){const{getNodes:n,width:r,height:s,minZoom:l,maxZoom:c,d3Zoom:u,d3Selection:f,fitViewOnInitDone:p,fitViewOnInit:h,nodeOrigin:m}=e(),y=t.initial&&!p&&h;if(u&&f&&(y||!t.initial)){const S=n().filter(_=>{var j;const k=t.includeHiddenNodes?_.width&&_.height:!_.hidden;return(j=t.nodes)!=null&&j.length?k&&t.nodes.some(E=>E.id===_.id):k}),b=S.every(_=>_.width&&_.height);if(S.length>0&&b){const _=kf(S,m),{x:k,y:j,zoom:E}=fA(_,r,s,t.minZoom??l,t.maxZoom??c,t.padding??.1),C=ua.translate(k,j).scale(E);return typeof t.duration=="number"&&t.duration>0?u.transform(ai(f,t.duration),C):u.transform(f,C),!0}}return!1}function aD(e,t){return e.forEach(n=>{const r=t.get(n.id);r&&t.set(r.id,{...r,[Wt]:r[Wt],selected:n.selected})}),new Map(t)}function oD(e,t){return t.map(n=>{const r=e.find(s=>s.id===n.id);return r&&(n.selected=r.selected),n})}function hh({changedNodes:e,changedEdges:t,get:n,set:r}){const{nodeInternals:s,edges:l,onNodesChange:c,onEdgesChange:u,hasDefaultNodes:f,hasDefaultEdges:p}=n();e!=null&&e.length&&(f&&r({nodeInternals:aD(e,s)}),c==null||c(e)),t!=null&&t.length&&(p&&r({edges:oD(t,l)}),u==null||u(t))}const xl=()=>{},iD={zoomIn:xl,zoomOut:xl,zoomTo:xl,getZoom:()=>1,setViewport:xl,getViewport:()=>({x:0,y:0,zoom:1}),fitView:()=>!1,setCenter:xl,fitBounds:xl,project:e=>e,screenToFlowPosition:e=>e,flowToScreenPosition:e=>e,viewportInitialized:!1},lD=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection}),cD=()=>{const e=tn(),{d3Zoom:t,d3Selection:n}=Et(lD,pn);return w.useMemo(()=>n&&t?{zoomIn:s=>t.scaleBy(ai(n,s==null?void 0:s.duration),1.2),zoomOut:s=>t.scaleBy(ai(n,s==null?void 0:s.duration),1/1.2),zoomTo:(s,l)=>t.scaleTo(ai(n,l==null?void 0:l.duration),s),getZoom:()=>e.getState().transform[2],setViewport:(s,l)=>{const[c,u,f]=e.getState().transform,p=ua.translate(s.x??c,s.y??u).scale(s.zoom??f);t.transform(ai(n,l==null?void 0:l.duration),p)},getViewport:()=>{const[s,l,c]=e.getState().transform;return{x:s,y:l,zoom:c}},fitView:s=>CA(e.getState,s),setCenter:(s,l,c)=>{const{width:u,height:f,maxZoom:p}=e.getState(),h=typeof(c==null?void 0:c.zoom)<"u"?c.zoom:p,m=u/2-s*h,y=f/2-l*h,v=ua.translate(m,y).scale(h);t.transform(ai(n,c==null?void 0:c.duration),v)},fitBounds:(s,l)=>{const{width:c,height:u,minZoom:f,maxZoom:p}=e.getState(),{x:h,y:m,zoom:y}=fA(s,c,u,f,p,(l==null?void 0:l.padding)??.1),v=ua.translate(h,m).scale(y);t.transform(ai(n,l==null?void 0:l.duration),v)},project:s=>{const{transform:l,snapToGrid:c,snapGrid:u}=e.getState();return console.warn("[DEPRECATED] `project` is deprecated. Instead use `screenToFlowPosition`. There is no need to subtract the react flow bounds anymore! https://reactflow.dev/api-reference/types/react-flow-instance#screen-to-flow-position"),N0(s,l,c,u)},screenToFlowPosition:s=>{const{transform:l,snapToGrid:c,snapGrid:u,domNode:f}=e.getState();if(!f)return s;const{x:p,y:h}=f.getBoundingClientRect(),m={x:s.x-p,y:s.y-h};return N0(m,l,c,u)},flowToScreenPosition:s=>{const{transform:l,domNode:c}=e.getState();if(!c)return s;const{x:u,y:f}=c.getBoundingClientRect(),p=uA(s,l);return{x:p.x+u,y:p.y+f}},viewportInitialized:!0}:iD,[t,n])};function Nf(){const e=cD(),t=tn(),n=w.useCallback(()=>t.getState().getNodes().map(b=>({...b})),[]),r=w.useCallback(b=>t.getState().nodeInternals.get(b),[]),s=w.useCallback(()=>{const{edges:b=[]}=t.getState();return b.map(_=>({..._}))},[]),l=w.useCallback(b=>{const{edges:_=[]}=t.getState();return _.find(k=>k.id===b)},[]),c=w.useCallback(b=>{const{getNodes:_,setNodes:k,hasDefaultNodes:j,onNodesChange:E}=t.getState(),C=_(),R=typeof b=="function"?b(C):b;if(j)k(R);else if(E){const I=R.length===0?C.map($=>({type:"remove",id:$.id})):R.map($=>({item:$,type:"reset"}));E(I)}},[]),u=w.useCallback(b=>{const{edges:_=[],setEdges:k,hasDefaultEdges:j,onEdgesChange:E}=t.getState(),C=typeof b=="function"?b(_):b;if(j)k(C);else if(E){const R=C.length===0?_.map(I=>({type:"remove",id:I.id})):C.map(I=>({item:I,type:"reset"}));E(R)}},[]),f=w.useCallback(b=>{const _=Array.isArray(b)?b:[b],{getNodes:k,setNodes:j,hasDefaultNodes:E,onNodesChange:C}=t.getState();if(E){const I=[...k(),..._];j(I)}else if(C){const R=_.map(I=>({item:I,type:"add"}));C(R)}},[]),p=w.useCallback(b=>{const _=Array.isArray(b)?b:[b],{edges:k=[],setEdges:j,hasDefaultEdges:E,onEdgesChange:C}=t.getState();if(E)j([...k,..._]);else if(C){const R=_.map(I=>({item:I,type:"add"}));C(R)}},[]),h=w.useCallback(()=>{const{getNodes:b,edges:_=[],transform:k}=t.getState(),[j,E,C]=k;return{nodes:b().map(R=>({...R})),edges:_.map(R=>({...R})),viewport:{x:j,y:E,zoom:C}}},[]),m=w.useCallback(({nodes:b,edges:_})=>{const{nodeInternals:k,getNodes:j,edges:E,hasDefaultNodes:C,hasDefaultEdges:R,onNodesDelete:I,onEdgesDelete:$,onNodesChange:q,onEdgesChange:B}=t.getState(),P=(b||[]).map(X=>X.id),W=(_||[]).map(X=>X.id),ne=j().reduce((X,V)=>{const G=V.parentNode||V.parentId,F=!P.includes(V.id)&&G&&X.find(H=>H.id===G);return(typeof V.deletable=="boolean"?V.deletable:!0)&&(P.includes(V.id)||F)&&X.push(V),X},[]),ee=E.filter(X=>typeof X.deletable=="boolean"?X.deletable:!0),M=ee.filter(X=>W.includes(X.id));if(ne||M){const X=hA(ne,ee),V=[...M,...X],G=V.reduce((F,L)=>(F.includes(L.id)||F.push(L.id),F),[]);if((R||C)&&(R&&t.setState({edges:E.filter(F=>!G.includes(F.id))}),C&&(ne.forEach(F=>{k.delete(F.id)}),t.setState({nodeInternals:new Map(k)}))),G.length>0&&($==null||$(V),B&&B(G.map(F=>({id:F,type:"remove"})))),ne.length>0&&(I==null||I(ne),q)){const F=ne.map(L=>({id:L.id,type:"remove"}));q(F)}}},[]),y=w.useCallback(b=>{const _=T4(b),k=_?null:t.getState().nodeInternals.get(b.id);return!_&&!k?[null,null,_]:[_?b:mN(k),k,_]},[]),v=w.useCallback((b,_=!0,k)=>{const[j,E,C]=y(b);return j?(k||t.getState().getNodes()).filter(R=>{if(!C&&(R.id===E.id||!R.positionAbsolute))return!1;const I=mN(R),$=v0(I,j);return _&&$>0||$>=j.width*j.height}):[]},[]),S=w.useCallback((b,_,k=!0)=>{const[j]=y(b);if(!j)return!1;const E=v0(j,_);return k&&E>0||E>=j.width*j.height},[]);return w.useMemo(()=>({...e,getNodes:n,getNode:r,getEdges:s,getEdge:l,setNodes:c,setEdges:u,addNodes:f,addEdges:p,toObject:h,deleteElements:m,getIntersectingNodes:v,isNodeIntersecting:S}),[e,n,r,s,l,c,u,f,p,h,m,v,S])}const uD={actInsideInputWithModifier:!1};var dD=({deleteKeyCode:e,multiSelectionKeyCode:t})=>{const n=tn(),{deleteElements:r}=Nf(),s=Eu(e,uD),l=Eu(t);w.useEffect(()=>{if(s){const{edges:c,getNodes:u}=n.getState(),f=u().filter(h=>h.selected),p=c.filter(h=>h.selected);r({nodes:f,edges:p}),n.setState({nodesSelectionActive:!1})}},[s]),w.useEffect(()=>{n.setState({multiSelectionActive:l})},[l])};function hD(e){const t=tn();w.useEffect(()=>{let n;const r=()=>{var l,c;if(!e.current)return;const s=fb(e.current);(s.height===0||s.width===0)&&((c=(l=t.getState()).onError)==null||c.call(l,"004",ha.error004())),t.setState({width:s.width||500,height:s.height||500})};return r(),window.addEventListener("resize",r),e.current&&(n=new ResizeObserver(()=>r()),n.observe(e.current)),()=>{window.removeEventListener("resize",r),n&&e.current&&n.unobserve(e.current)}},[])}const kb={position:"absolute",width:"100%",height:"100%",top:0,left:0},fD=(e,t)=>e.x!==t.x||e.y!==t.y||e.zoom!==t.k,fh=e=>({x:e.x,y:e.y,zoom:e.k}),bl=(e,t)=>e.target.closest(`.${t}`),jN=(e,t)=>t===2&&Array.isArray(e)&&e.includes(2),_N=e=>{const t=e.ctrlKey&&Zh()?10:1;return-e.deltaY*(e.deltaMode===1?.05:e.deltaMode?1:.002)*t},pD=e=>({d3Zoom:e.d3Zoom,d3Selection:e.d3Selection,d3ZoomHandler:e.d3ZoomHandler,userSelectionActive:e.userSelectionActive}),mD=({onMove:e,onMoveStart:t,onMoveEnd:n,onPaneContextMenu:r,zoomOnScroll:s=!0,zoomOnPinch:l=!0,panOnScroll:c=!1,panOnScrollSpeed:u=.5,panOnScrollMode:f=li.Free,zoomOnDoubleClick:p=!0,elementsSelectable:h,panOnDrag:m=!0,defaultViewport:y,translateExtent:v,minZoom:S,maxZoom:b,zoomActivationKeyCode:_,preventScrolling:k=!0,children:j,noWheelClassName:E,noPanClassName:C})=>{const R=w.useRef(),I=tn(),$=w.useRef(!1),q=w.useRef(!1),B=w.useRef(null),P=w.useRef({x:0,y:0,zoom:0}),{d3Zoom:W,d3Selection:ne,d3ZoomHandler:ee,userSelectionActive:M}=Et(pD,pn),X=Eu(_),V=w.useRef(0),G=w.useRef(!1),F=w.useRef();return hD(B),w.useEffect(()=>{if(B.current){const L=B.current.getBoundingClientRect(),H=JR().scaleExtent([S,b]).translateExtent(v),D=Lr(B.current).call(H),K=ua.translate(y.x,y.y).scale(Wl(y.zoom,S,b)),re=[[0,0],[L.width,L.height]],z=H.constrain()(K,re,v);H.transform(D,z),H.wheelDelta(_N),I.setState({d3Zoom:H,d3Selection:D,d3ZoomHandler:D.on("wheel.zoom"),transform:[z.x,z.y,z.k],domNode:B.current.closest(".react-flow")})}},[]),w.useEffect(()=>{ne&&W&&(c&&!X&&!M?ne.on("wheel.zoom",L=>{if(bl(L,E))return!1;L.preventDefault(),L.stopImmediatePropagation();const H=ne.property("__zoom").k||1;if(L.ctrlKey&&l){const le=fs(L),ge=_N(L),Ne=H*Math.pow(2,ge);W.scaleTo(ne,Ne,le,L);return}const D=L.deltaMode===1?20:1;let K=f===li.Vertical?0:L.deltaX*D,re=f===li.Horizontal?0:L.deltaY*D;!Zh()&&L.shiftKey&&f!==li.Vertical&&(K=L.deltaY*D,re=0),W.translateBy(ne,-(K/H)*u,-(re/H)*u,{internal:!0});const z=fh(ne.property("__zoom")),{onViewportChangeStart:Z,onViewportChange:U,onViewportChangeEnd:ae}=I.getState();clearTimeout(F.current),G.current||(G.current=!0,t==null||t(L,z),Z==null||Z(z)),G.current&&(e==null||e(L,z),U==null||U(z),F.current=setTimeout(()=>{n==null||n(L,z),ae==null||ae(z),G.current=!1},150))},{passive:!1}):typeof ee<"u"&&ne.on("wheel.zoom",function(L,H){if(!k&&L.type==="wheel"&&!L.ctrlKey||bl(L,E))return null;L.preventDefault(),ee.call(this,L,H)},{passive:!1}))},[M,c,f,ne,W,ee,X,l,k,E,t,e,n]),w.useEffect(()=>{W&&W.on("start",L=>{var K,re;if(!L.sourceEvent||L.sourceEvent.internal)return null;V.current=(K=L.sourceEvent)==null?void 0:K.button;const{onViewportChangeStart:H}=I.getState(),D=fh(L.transform);$.current=!0,P.current=D,((re=L.sourceEvent)==null?void 0:re.type)==="mousedown"&&I.setState({paneDragging:!0}),H==null||H(D),t==null||t(L.sourceEvent,D)})},[W,t]),w.useEffect(()=>{W&&(M&&!$.current?W.on("zoom",null):M||W.on("zoom",L=>{var D;const{onViewportChange:H}=I.getState();if(I.setState({transform:[L.transform.x,L.transform.y,L.transform.k]}),q.current=!!(r&&jN(m,V.current??0)),(e||H)&&!((D=L.sourceEvent)!=null&&D.internal)){const K=fh(L.transform);H==null||H(K),e==null||e(L.sourceEvent,K)}}))},[M,W,e,m,r]),w.useEffect(()=>{W&&W.on("end",L=>{if(!L.sourceEvent||L.sourceEvent.internal)return null;const{onViewportChangeEnd:H}=I.getState();if($.current=!1,I.setState({paneDragging:!1}),r&&jN(m,V.current??0)&&!q.current&&r(L.sourceEvent),q.current=!1,(n||H)&&fD(P.current,L.transform)){const D=fh(L.transform);P.current=D,clearTimeout(R.current),R.current=setTimeout(()=>{H==null||H(D),n==null||n(L.sourceEvent,D)},c?150:0)}})},[W,c,m,n,r]),w.useEffect(()=>{W&&W.filter(L=>{const H=X||s,D=l&&L.ctrlKey;if((m===!0||Array.isArray(m)&&m.includes(1))&&L.button===1&&L.type==="mousedown"&&(bl(L,"react-flow__node")||bl(L,"react-flow__edge")))return!0;if(!m&&!H&&!c&&!p&&!l||M||!p&&L.type==="dblclick"||bl(L,E)&&L.type==="wheel"||bl(L,C)&&(L.type!=="wheel"||c&&L.type==="wheel"&&!X)||!l&&L.ctrlKey&&L.type==="wheel"||!H&&!c&&!D&&L.type==="wheel"||!m&&(L.type==="mousedown"||L.type==="touchstart")||Array.isArray(m)&&!m.includes(L.button)&&L.type==="mousedown")return!1;const K=Array.isArray(m)&&m.includes(L.button)||!L.button||L.button<=1;return(!L.ctrlKey||L.type==="wheel")&&K})},[M,W,s,l,c,p,m,h,X]),ve.createElement("div",{className:"react-flow__renderer",ref:B,style:kb},j)},gD=e=>({userSelectionActive:e.userSelectionActive,userSelectionRect:e.userSelectionRect});function yD(){const{userSelectionActive:e,userSelectionRect:t}=Et(gD,pn);return e&&t?ve.createElement("div",{className:"react-flow__selection react-flow__container",style:{width:t.width,height:t.height,transform:`translate(${t.x}px, ${t.y}px)`}}):null}function EN(e,t){const n=t.parentNode||t.parentId,r=e.find(s=>s.id===n);if(r){const s=t.position.x+t.width-r.width,l=t.position.y+t.height-r.height;if(s>0||l>0||t.position.x<0||t.position.y<0){if(r.style={...r.style},r.style.width=r.style.width??r.width,r.style.height=r.style.height??r.height,s>0&&(r.style.width+=s),l>0&&(r.style.height+=l),t.position.x<0){const c=Math.abs(t.position.x);r.position.x=r.position.x-c,r.style.width+=c,t.position.x=0}if(t.position.y<0){const c=Math.abs(t.position.y);r.position.y=r.position.y-c,r.style.height+=c,t.position.y=0}r.width=r.style.width,r.height=r.style.height}}}function wD(e,t){if(e.some(r=>r.type==="reset"))return e.filter(r=>r.type==="reset").map(r=>r.item);const n=e.filter(r=>r.type==="add").map(r=>r.item);return t.reduce((r,s)=>{const l=e.filter(u=>u.id===s.id);if(l.length===0)return r.push(s),r;const c={...s};for(const u of l)if(u)switch(u.type){case"select":{c.selected=u.selected;break}case"position":{typeof u.position<"u"&&(c.position=u.position),typeof u.positionAbsolute<"u"&&(c.positionAbsolute=u.positionAbsolute),typeof u.dragging<"u"&&(c.dragging=u.dragging),c.expandParent&&EN(r,c);break}case"dimensions":{typeof u.dimensions<"u"&&(c.width=u.dimensions.width,c.height=u.dimensions.height),typeof u.updateStyle<"u"&&(c.style={...c.style||{},...u.dimensions}),typeof u.resizing=="boolean"&&(c.resizing=u.resizing),c.expandParent&&EN(r,c);break}case"remove":return r}return r.push(c),r},n)}function vD(e,t){return wD(e,t)}const Ja=(e,t)=>({id:e,type:"select",selected:t});function Il(e,t){return e.reduce((n,r)=>{const s=t.includes(r.id);return!r.selected&&s?(r.selected=!0,n.push(Ja(r.id,!0))):r.selected&&!s&&(r.selected=!1,n.push(Ja(r.id,!1))),n},[])}const ym=(e,t)=>n=>{n.target===t.current&&(e==null||e(n))},xD=e=>({userSelectionActive:e.userSelectionActive,elementsSelectable:e.elementsSelectable,dragging:e.paneDragging}),TA=w.memo(({isSelecting:e,selectionMode:t=_u.Full,panOnDrag:n,onSelectionStart:r,onSelectionEnd:s,onPaneClick:l,onPaneContextMenu:c,onPaneScroll:u,onPaneMouseEnter:f,onPaneMouseMove:p,onPaneMouseLeave:h,children:m})=>{const y=w.useRef(null),v=tn(),S=w.useRef(0),b=w.useRef(0),_=w.useRef(),{userSelectionActive:k,elementsSelectable:j,dragging:E}=Et(xD,pn),C=()=>{v.setState({userSelectionActive:!1,userSelectionRect:null}),S.current=0,b.current=0},R=ee=>{l==null||l(ee),v.getState().resetSelectedElements(),v.setState({nodesSelectionActive:!1})},I=ee=>{if(Array.isArray(n)&&(n!=null&&n.includes(2))){ee.preventDefault();return}c==null||c(ee)},$=u?ee=>u(ee):void 0,q=ee=>{const{resetSelectedElements:M,domNode:X}=v.getState();if(_.current=X==null?void 0:X.getBoundingClientRect(),!j||!e||ee.button!==0||ee.target!==y.current||!_.current)return;const{x:V,y:G}=so(ee,_.current);M(),v.setState({userSelectionRect:{width:0,height:0,startX:V,startY:G,x:V,y:G}}),r==null||r(ee)},B=ee=>{const{userSelectionRect:M,nodeInternals:X,edges:V,transform:G,onNodesChange:F,onEdgesChange:L,nodeOrigin:H,getNodes:D}=v.getState();if(!e||!_.current||!M)return;v.setState({userSelectionActive:!0,nodesSelectionActive:!1});const K=so(ee,_.current),re=M.startX??0,z=M.startY??0,Z={...M,x:K.x<re?K.x:re,y:K.y<z?K.y:z,width:Math.abs(K.x-re),height:Math.abs(K.y-z)},U=D(),ae=dA(X,Z,G,t===_u.Partial,!0,H),le=hA(ae,V).map(Ne=>Ne.id),ge=ae.map(Ne=>Ne.id);if(S.current!==ge.length){S.current=ge.length;const Ne=Il(U,ge);Ne.length&&(F==null||F(Ne))}if(b.current!==le.length){b.current=le.length;const Ne=Il(V,le);Ne.length&&(L==null||L(Ne))}v.setState({userSelectionRect:Z})},P=ee=>{if(ee.button!==0)return;const{userSelectionRect:M}=v.getState();!k&&M&&ee.target===y.current&&(R==null||R(ee)),v.setState({nodesSelectionActive:S.current>0}),C(),s==null||s(ee)},W=ee=>{k&&(v.setState({nodesSelectionActive:S.current>0}),s==null||s(ee)),C()},ne=j&&(e||k);return ve.createElement("div",{className:jn(["react-flow__pane",{dragging:E,selection:e}]),onClick:ne?void 0:ym(R,y),onContextMenu:ym(I,y),onWheel:ym($,y),onMouseEnter:ne?void 0:f,onMouseDown:ne?q:void 0,onMouseMove:ne?B:p,onMouseUp:ne?P:void 0,onMouseLeave:ne?W:h,ref:y,style:kb},m,ve.createElement(yD,null))});TA.displayName="Pane";function RA(e,t){const n=e.parentNode||e.parentId;if(!n)return!1;const r=t.get(n);return r?r.selected?!0:RA(r,t):!1}function CN(e,t,n){let r=e;do{if(r!=null&&r.matches(t))return!0;if(r===n.current)return!1;r=r.parentElement}while(r);return!1}function bD(e,t,n,r){return Array.from(e.values()).filter(s=>(s.selected||s.id===r)&&(!s.parentNode||s.parentId||!RA(s,e))&&(s.draggable||t&&typeof s.draggable>"u")).map(s=>{var l,c;return{id:s.id,position:s.position||{x:0,y:0},positionAbsolute:s.positionAbsolute||{x:0,y:0},distance:{x:n.x-(((l=s.positionAbsolute)==null?void 0:l.x)??0),y:n.y-(((c=s.positionAbsolute)==null?void 0:c.y)??0)},delta:{x:0,y:0},extent:s.extent,parentNode:s.parentNode||s.parentId,parentId:s.parentNode||s.parentId,width:s.width,height:s.height,expandParent:s.expandParent}})}function kD(e,t){return!t||t==="parent"?t:[t[0],[t[1][0]-(e.width||0),t[1][1]-(e.height||0)]]}function AA(e,t,n,r,s=[0,0],l){const c=kD(e,e.extent||r);let u=c;const f=e.parentNode||e.parentId;if(e.extent==="parent"&&!e.expandParent)if(f&&e.width&&e.height){const m=n.get(f),{x:y,y:v}=ui(m,s).positionAbsolute;u=m&&Pr(y)&&Pr(v)&&Pr(m.width)&&Pr(m.height)?[[y+e.width*s[0],v+e.height*s[1]],[y+m.width-e.width+e.width*s[0],v+m.height-e.height+e.height*s[1]]]:u}else l==null||l("005",ha.error005()),u=c;else if(e.extent&&f&&e.extent!=="parent"){const m=n.get(f),{x:y,y:v}=ui(m,s).positionAbsolute;u=[[e.extent[0][0]+y,e.extent[0][1]+v],[e.extent[1][0]+y,e.extent[1][1]+v]]}let p={x:0,y:0};if(f){const m=n.get(f);p=ui(m,s).positionAbsolute}const h=u&&u!=="parent"?pb(t,u):t;return{position:{x:h.x-p.x,y:h.y-p.y},positionAbsolute:h}}function wm({nodeId:e,dragItems:t,nodeInternals:n}){const r=t.map(s=>({...n.get(s.id),position:s.position,positionAbsolute:s.positionAbsolute}));return[e?r.find(s=>s.id===e):r[0],r]}const TN=(e,t,n,r)=>{const s=t.querySelectorAll(e);if(!s||!s.length)return null;const l=Array.from(s),c=t.getBoundingClientRect(),u={x:c.width*r[0],y:c.height*r[1]};return l.map(f=>{const p=f.getBoundingClientRect();return{id:f.getAttribute("data-handleid"),position:f.getAttribute("data-handlepos"),x:(p.left-c.left-u.x)/n,y:(p.top-c.top-u.y)/n,...fb(f)}})};function nu(e,t,n){return n===void 0?n:r=>{const s=t().nodeInternals.get(e);s&&n(r,{...s})}}function j0({id:e,store:t,unselect:n=!1,nodeRef:r}){const{addSelectedNodes:s,unselectNodesAndEdges:l,multiSelectionActive:c,nodeInternals:u,onError:f}=t.getState(),p=u.get(e);if(!p){f==null||f("012",ha.error012(e));return}t.setState({nodesSelectionActive:!1}),p.selected?(n||p.selected&&c)&&(l({nodes:[p],edges:[]}),requestAnimationFrame(()=>{var h;return(h=r==null?void 0:r.current)==null?void 0:h.blur()})):s([e])}function ND(){const e=tn();return w.useCallback(({sourceEvent:n})=>{const{transform:r,snapGrid:s,snapToGrid:l}=e.getState(),c=n.touches?n.touches[0].clientX:n.clientX,u=n.touches?n.touches[0].clientY:n.clientY,f={x:(c-r[0])/r[2],y:(u-r[1])/r[2]};return{xSnapped:l?s[0]*Math.round(f.x/s[0]):f.x,ySnapped:l?s[1]*Math.round(f.y/s[1]):f.y,...f}},[])}function vm(e){return(t,n,r)=>e==null?void 0:e(t,r)}function MA({nodeRef:e,disabled:t=!1,noDragClassName:n,handleSelector:r,nodeId:s,isSelectable:l,selectNodesOnDrag:c}){const u=tn(),[f,p]=w.useState(!1),h=w.useRef([]),m=w.useRef({x:null,y:null}),y=w.useRef(0),v=w.useRef(null),S=w.useRef({x:0,y:0}),b=w.useRef(null),_=w.useRef(!1),k=w.useRef(!1),j=w.useRef(!1),E=ND();return w.useEffect(()=>{if(e!=null&&e.current){const C=Lr(e.current),R=({x:q,y:B})=>{const{nodeInternals:P,onNodeDrag:W,onSelectionDrag:ne,updateNodePositions:ee,nodeExtent:M,snapGrid:X,snapToGrid:V,nodeOrigin:G,onError:F}=u.getState();m.current={x:q,y:B};let L=!1,H={x:0,y:0,x2:0,y2:0};if(h.current.length>1&&M){const K=kf(h.current,G);H=ju(K)}if(h.current=h.current.map(K=>{const re={x:q-K.distance.x,y:B-K.distance.y};V&&(re.x=X[0]*Math.round(re.x/X[0]),re.y=X[1]*Math.round(re.y/X[1]));const z=[[M[0][0],M[0][1]],[M[1][0],M[1][1]]];h.current.length>1&&M&&!K.extent&&(z[0][0]=K.positionAbsolute.x-H.x+M[0][0],z[1][0]=K.positionAbsolute.x+(K.width??0)-H.x2+M[1][0],z[0][1]=K.positionAbsolute.y-H.y+M[0][1],z[1][1]=K.positionAbsolute.y+(K.height??0)-H.y2+M[1][1]);const Z=AA(K,re,P,z,G,F);return L=L||K.position.x!==Z.position.x||K.position.y!==Z.position.y,K.position=Z.position,K.positionAbsolute=Z.positionAbsolute,K}),!L)return;ee(h.current,!0,!0),p(!0);const D=s?W:vm(ne);if(D&&b.current){const[K,re]=wm({nodeId:s,dragItems:h.current,nodeInternals:P});D(b.current,K,re)}},I=()=>{if(!v.current)return;const[q,B]=tA(S.current,v.current);if(q!==0||B!==0){const{transform:P,panBy:W}=u.getState();m.current.x=(m.current.x??0)-q/P[2],m.current.y=(m.current.y??0)-B/P[2],W({x:q,y:B})&&R(m.current)}y.current=requestAnimationFrame(I)},$=q=>{var G;const{nodeInternals:B,multiSelectionActive:P,nodesDraggable:W,unselectNodesAndEdges:ne,onNodeDragStart:ee,onSelectionDragStart:M}=u.getState();k.current=!0;const X=s?ee:vm(M);(!c||!l)&&!P&&s&&((G=B.get(s))!=null&&G.selected||ne()),s&&l&&c&&j0({id:s,store:u,nodeRef:e});const V=E(q);if(m.current=V,h.current=bD(B,W,V,s),X&&h.current){const[F,L]=wm({nodeId:s,dragItems:h.current,nodeInternals:B});X(q.sourceEvent,F,L)}};if(t)C.on(".drag",null);else{const q=I3().on("start",B=>{const{domNode:P,nodeDragThreshold:W}=u.getState();W===0&&$(B),j.current=!1;const ne=E(B);m.current=ne,v.current=(P==null?void 0:P.getBoundingClientRect())||null,S.current=so(B.sourceEvent,v.current)}).on("drag",B=>{var ee,M;const P=E(B),{autoPanOnNodeDrag:W,nodeDragThreshold:ne}=u.getState();if(B.sourceEvent.type==="touchmove"&&B.sourceEvent.touches.length>1&&(j.current=!0),!j.current){if(!_.current&&k.current&&W&&(_.current=!0,I()),!k.current){const X=P.xSnapped-(((ee=m==null?void 0:m.current)==null?void 0:ee.x)??0),V=P.ySnapped-(((M=m==null?void 0:m.current)==null?void 0:M.y)??0);Math.sqrt(X*X+V*V)>ne&&$(B)}(m.current.x!==P.xSnapped||m.current.y!==P.ySnapped)&&h.current&&k.current&&(b.current=B.sourceEvent,S.current=so(B.sourceEvent,v.current),R(P))}}).on("end",B=>{if(!(!k.current||j.current)&&(p(!1),_.current=!1,k.current=!1,cancelAnimationFrame(y.current),h.current)){const{updateNodePositions:P,nodeInternals:W,onNodeDragStop:ne,onSelectionDragStop:ee}=u.getState(),M=s?ne:vm(ee);if(P(h.current,!1,!1),M){const[X,V]=wm({nodeId:s,dragItems:h.current,nodeInternals:W});M(B.sourceEvent,X,V)}}}).filter(B=>{const P=B.target;return!B.button&&(!n||!CN(P,`.${n}`,e))&&(!r||CN(P,r,e))});return C.call(q),()=>{C.on(".drag",null)}}}},[e,t,n,r,l,u,s,c,E]),f}function IA(){const e=tn();return w.useCallback(n=>{const{nodeInternals:r,nodeExtent:s,updateNodePositions:l,getNodes:c,snapToGrid:u,snapGrid:f,onError:p,nodesDraggable:h}=e.getState(),m=c().filter(j=>j.selected&&(j.draggable||h&&typeof j.draggable>"u")),y=u?f[0]:5,v=u?f[1]:5,S=n.isShiftPressed?4:1,b=n.x*y*S,_=n.y*v*S,k=m.map(j=>{if(j.positionAbsolute){const E={x:j.positionAbsolute.x+b,y:j.positionAbsolute.y+_};u&&(E.x=f[0]*Math.round(E.x/f[0]),E.y=f[1]*Math.round(E.y/f[1]));const{positionAbsolute:C,position:R}=AA(j,E,r,s,void 0,p);j.position=R,j.positionAbsolute=C}return j});l(k,!0,!1)},[])}const ql={ArrowUp:{x:0,y:-1},ArrowDown:{x:0,y:1},ArrowLeft:{x:-1,y:0},ArrowRight:{x:1,y:0}};var ru=e=>{const t=({id:n,type:r,data:s,xPos:l,yPos:c,xPosOrigin:u,yPosOrigin:f,selected:p,onClick:h,onMouseEnter:m,onMouseMove:y,onMouseLeave:v,onContextMenu:S,onDoubleClick:b,style:_,className:k,isDraggable:j,isSelectable:E,isConnectable:C,isFocusable:R,selectNodesOnDrag:I,sourcePosition:$,targetPosition:q,hidden:B,resizeObserver:P,dragHandle:W,zIndex:ne,isParent:ee,noDragClassName:M,noPanClassName:X,initialized:V,disableKeyboardA11y:G,ariaLabel:F,rfId:L,hasHandleBounds:H})=>{const D=tn(),K=w.useRef(null),re=w.useRef(null),z=w.useRef($),Z=w.useRef(q),U=w.useRef(r),ae=E||j||h||m||y||v,le=IA(),ge=nu(n,D.getState,m),Ne=nu(n,D.getState,y),Ie=nu(n,D.getState,v),Ge=nu(n,D.getState,S),Pe=nu(n,D.getState,b),ze=ue=>{const{nodeDragThreshold:ce}=D.getState();if(E&&(!I||!j||ce>0)&&j0({id:n,store:D,nodeRef:K}),h){const se=D.getState().nodeInternals.get(n);se&&h(ue,{...se})}},Re=ue=>{if(!x0(ue)&&!G)if(aA.includes(ue.key)&&E){const ce=ue.key==="Escape";j0({id:n,store:D,unselect:ce,nodeRef:K})}else j&&p&&Object.prototype.hasOwnProperty.call(ql,ue.key)&&(D.setState({ariaLiveMessage:`Moved selected node ${ue.key.replace("Arrow","").toLowerCase()}. New position, x: ${~~l}, y: ${~~c}`}),le({x:ql[ue.key].x,y:ql[ue.key].y,isShiftPressed:ue.shiftKey}))};w.useEffect(()=>()=>{re.current&&(P==null||P.unobserve(re.current),re.current=null)},[]),w.useEffect(()=>{if(K.current&&!B){const ue=K.current;(!V||!H||re.current!==ue)&&(re.current&&(P==null||P.unobserve(re.current)),P==null||P.observe(ue),re.current=ue)}},[B,V,H]),w.useEffect(()=>{const ue=U.current!==r,ce=z.current!==$,se=Z.current!==q;K.current&&(ue||ce||se)&&(ue&&(U.current=r),ce&&(z.current=$),se&&(Z.current=q),D.getState().updateNodeDimensions([{id:n,nodeElement:K.current,forceUpdate:!0}]))},[n,r,$,q]);const st=MA({nodeRef:K,disabled:B||!j,noDragClassName:M,handleSelector:W,nodeId:n,isSelectable:E,selectNodesOnDrag:I});return B?null:ve.createElement("div",{className:jn(["react-flow__node",`react-flow__node-${r}`,{[X]:j},k,{selected:p,selectable:E,parent:ee,dragging:st}]),ref:K,style:{zIndex:ne,transform:`translate(${u}px,${f}px)`,pointerEvents:ae?"all":"none",visibility:V?"visible":"hidden",..._},"data-id":n,"data-testid":`rf__node-${n}`,onMouseEnter:ge,onMouseMove:Ne,onMouseLeave:Ie,onContextMenu:Ge,onClick:ze,onDoubleClick:Pe,onKeyDown:R?Re:void 0,tabIndex:R?0:void 0,role:R?"button":void 0,"aria-describedby":G?void 0:`${SA}-${L}`,"aria-label":F},ve.createElement(L4,{value:n},ve.createElement(e,{id:n,data:s,type:r,xPos:l,yPos:c,selected:p,isConnectable:C,sourcePosition:$,targetPosition:q,dragging:st,dragHandle:W,zIndex:ne})))};return t.displayName="NodeWrapper",w.memo(t)};const SD=e=>{const t=e.getNodes().filter(n=>n.selected);return{...kf(t,e.nodeOrigin),transformString:`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`,userSelectionActive:e.userSelectionActive}};function jD({onSelectionContextMenu:e,noPanClassName:t,disableKeyboardA11y:n}){const r=tn(),{width:s,height:l,x:c,y:u,transformString:f,userSelectionActive:p}=Et(SD,pn),h=IA(),m=w.useRef(null);if(w.useEffect(()=>{var S;n||(S=m.current)==null||S.focus({preventScroll:!0})},[n]),MA({nodeRef:m}),p||!s||!l)return null;const y=e?S=>{const b=r.getState().getNodes().filter(_=>_.selected);e(S,b)}:void 0,v=S=>{Object.prototype.hasOwnProperty.call(ql,S.key)&&h({x:ql[S.key].x,y:ql[S.key].y,isShiftPressed:S.shiftKey})};return ve.createElement("div",{className:jn(["react-flow__nodesselection","react-flow__container",t]),style:{transform:f}},ve.createElement("div",{ref:m,className:"react-flow__nodesselection-rect",onContextMenu:y,tabIndex:n?void 0:-1,onKeyDown:n?void 0:v,style:{width:s,height:l,top:u,left:c}}))}var _D=w.memo(jD);const ED=e=>e.nodesSelectionActive,$A=({children:e,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:l,onPaneScroll:c,deleteKeyCode:u,onMove:f,onMoveStart:p,onMoveEnd:h,selectionKeyCode:m,selectionOnDrag:y,selectionMode:v,onSelectionStart:S,onSelectionEnd:b,multiSelectionKeyCode:_,panActivationKeyCode:k,zoomActivationKeyCode:j,elementsSelectable:E,zoomOnScroll:C,zoomOnPinch:R,panOnScroll:I,panOnScrollSpeed:$,panOnScrollMode:q,zoomOnDoubleClick:B,panOnDrag:P,defaultViewport:W,translateExtent:ne,minZoom:ee,maxZoom:M,preventScrolling:X,onSelectionContextMenu:V,noWheelClassName:G,noPanClassName:F,disableKeyboardA11y:L})=>{const H=Et(ED),D=Eu(m),K=Eu(k),re=K||P,z=K||I,Z=D||y&&re!==!0;return dD({deleteKeyCode:u,multiSelectionKeyCode:_}),ve.createElement(mD,{onMove:f,onMoveStart:p,onMoveEnd:h,onPaneContextMenu:l,elementsSelectable:E,zoomOnScroll:C,zoomOnPinch:R,panOnScroll:z,panOnScrollSpeed:$,panOnScrollMode:q,zoomOnDoubleClick:B,panOnDrag:!D&&re,defaultViewport:W,translateExtent:ne,minZoom:ee,maxZoom:M,zoomActivationKeyCode:j,preventScrolling:X,noWheelClassName:G,noPanClassName:F},ve.createElement(TA,{onSelectionStart:S,onSelectionEnd:b,onPaneClick:t,onPaneMouseEnter:n,onPaneMouseMove:r,onPaneMouseLeave:s,onPaneContextMenu:l,onPaneScroll:c,panOnDrag:re,isSelecting:!!Z,selectionMode:v},e,H&&ve.createElement(_D,{onSelectionContextMenu:V,noPanClassName:F,disableKeyboardA11y:L})))};$A.displayName="FlowRenderer";var CD=w.memo($A);function TD(e){return Et(w.useCallback(n=>e?dA(n.nodeInternals,{x:0,y:0,width:n.width,height:n.height},n.transform,!0):n.getNodes(),[e]))}function RD(e){const t={input:ru(e.input||xA),default:ru(e.default||S0),output:ru(e.output||kA),group:ru(e.group||bb)},n={},r=Object.keys(e).filter(s=>!["input","default","output","group"].includes(s)).reduce((s,l)=>(s[l]=ru(e[l]||S0),s),n);return{...t,...r}}const AD=({x:e,y:t,width:n,height:r,origin:s})=>!n||!r?{x:e,y:t}:s[0]<0||s[1]<0||s[0]>1||s[1]>1?{x:e,y:t}:{x:e-n*s[0],y:t-r*s[1]},MD=e=>({nodesDraggable:e.nodesDraggable,nodesConnectable:e.nodesConnectable,nodesFocusable:e.nodesFocusable,elementsSelectable:e.elementsSelectable,updateNodeDimensions:e.updateNodeDimensions,onError:e.onError}),OA=e=>{const{nodesDraggable:t,nodesConnectable:n,nodesFocusable:r,elementsSelectable:s,updateNodeDimensions:l,onError:c}=Et(MD,pn),u=TD(e.onlyRenderVisibleElements),f=w.useRef(),p=w.useMemo(()=>{if(typeof ResizeObserver>"u")return null;const h=new ResizeObserver(m=>{const y=m.map(v=>({id:v.target.getAttribute("data-id"),nodeElement:v.target,forceUpdate:!0}));l(y)});return f.current=h,h},[]);return w.useEffect(()=>()=>{var h;(h=f==null?void 0:f.current)==null||h.disconnect()},[]),ve.createElement("div",{className:"react-flow__nodes",style:kb},u.map(h=>{var R,I,$;let m=h.type||"default";e.nodeTypes[m]||(c==null||c("003",ha.error003(m)),m="default");const y=e.nodeTypes[m]||e.nodeTypes.default,v=!!(h.draggable||t&&typeof h.draggable>"u"),S=!!(h.selectable||s&&typeof h.selectable>"u"),b=!!(h.connectable||n&&typeof h.connectable>"u"),_=!!(h.focusable||r&&typeof h.focusable>"u"),k=e.nodeExtent?pb(h.positionAbsolute,e.nodeExtent):h.positionAbsolute,j=(k==null?void 0:k.x)??0,E=(k==null?void 0:k.y)??0,C=AD({x:j,y:E,width:h.width??0,height:h.height??0,origin:e.nodeOrigin});return ve.createElement(y,{key:h.id,id:h.id,className:h.className,style:h.style,type:m,data:h.data,sourcePosition:h.sourcePosition||nt.Bottom,targetPosition:h.targetPosition||nt.Top,hidden:h.hidden,xPos:j,yPos:E,xPosOrigin:C.x,yPosOrigin:C.y,selectNodesOnDrag:e.selectNodesOnDrag,onClick:e.onNodeClick,onMouseEnter:e.onNodeMouseEnter,onMouseMove:e.onNodeMouseMove,onMouseLeave:e.onNodeMouseLeave,onContextMenu:e.onNodeContextMenu,onDoubleClick:e.onNodeDoubleClick,selected:!!h.selected,isDraggable:v,isSelectable:S,isConnectable:b,isFocusable:_,resizeObserver:p,dragHandle:h.dragHandle,zIndex:((R=h[Wt])==null?void 0:R.z)??0,isParent:!!((I=h[Wt])!=null&&I.isParent),noDragClassName:e.noDragClassName,noPanClassName:e.noPanClassName,initialized:!!h.width&&!!h.height,rfId:e.rfId,disableKeyboardA11y:e.disableKeyboardA11y,ariaLabel:h.ariaLabel,hasHandleBounds:!!(($=h[Wt])!=null&&$.handleBounds)})}))};OA.displayName="NodeRenderer";var ID=w.memo(OA);const $D=(e,t,n)=>n===nt.Left?e-t:n===nt.Right?e+t:e,OD=(e,t,n)=>n===nt.Top?e-t:n===nt.Bottom?e+t:e,RN="react-flow__edgeupdater",AN=({position:e,centerX:t,centerY:n,radius:r=10,onMouseDown:s,onMouseEnter:l,onMouseOut:c,type:u})=>ve.createElement("circle",{onMouseDown:s,onMouseEnter:l,onMouseOut:c,className:jn([RN,`${RN}-${u}`]),cx:$D(t,r,e),cy:OD(n,r,e),r,stroke:"transparent",fill:"transparent"}),LD=()=>!0;var kl=e=>{const t=({id:n,className:r,type:s,data:l,onClick:c,onEdgeDoubleClick:u,selected:f,animated:p,label:h,labelStyle:m,labelShowBg:y,labelBgStyle:v,labelBgPadding:S,labelBgBorderRadius:b,style:_,source:k,target:j,sourceX:E,sourceY:C,targetX:R,targetY:I,sourcePosition:$,targetPosition:q,elementsSelectable:B,hidden:P,sourceHandleId:W,targetHandleId:ne,onContextMenu:ee,onMouseEnter:M,onMouseMove:X,onMouseLeave:V,reconnectRadius:G,onReconnect:F,onReconnectStart:L,onReconnectEnd:H,markerEnd:D,markerStart:K,rfId:re,ariaLabel:z,isFocusable:Z,isReconnectable:U,pathOptions:ae,interactionWidth:le,disableKeyboardA11y:ge})=>{const Ne=w.useRef(null),[Ie,Ge]=w.useState(!1),[Pe,ze]=w.useState(!1),Re=tn(),st=w.useMemo(()=>`url('#${k0(K,re)}')`,[K,re]),ue=w.useMemo(()=>`url('#${k0(D,re)}')`,[D,re]);if(P)return null;const ce=Ue=>{var yt;const{edges:Fe,addSelectedEdges:Ve,unselectNodesAndEdges:rt,multiSelectionActive:ut}=Re.getState(),ct=Fe.find(It=>It.id===n);ct&&(B&&(Re.setState({nodesSelectionActive:!1}),ct.selected&&ut?(rt({nodes:[],edges:[ct]}),(yt=Ne.current)==null||yt.blur()):Ve([n])),c&&c(Ue,ct))},se=tu(n,Re.getState,u),be=tu(n,Re.getState,ee),Le=tu(n,Re.getState,M),de=tu(n,Re.getState,X),fe=tu(n,Re.getState,V),Ce=(Ue,Fe)=>{if(Ue.button!==0)return;const{edges:Ve,isValidConnection:rt}=Re.getState(),ut=Fe?j:k,ct=(Fe?ne:W)||null,yt=Fe?"target":"source",It=rt||LD,zt=Fe,Xt=Ve.find(Se=>Se.id===n);ze(!0),L==null||L(Ue,Xt,yt);const Ft=Se=>{ze(!1),H==null||H(Se,Xt,yt)};gA({event:Ue,handleId:ct,nodeId:ut,onConnect:Se=>F==null?void 0:F(Xt,Se),isTarget:zt,getState:Re.getState,setState:Re.setState,isValidConnection:It,edgeUpdaterType:yt,onReconnectEnd:Ft})},pe=Ue=>Ce(Ue,!0),_e=Ue=>Ce(Ue,!1),Ye=()=>Ge(!0),qe=()=>Ge(!1),ke=!B&&!c,Ae=Ue=>{var Fe;if(!ge&&aA.includes(Ue.key)&&B){const{unselectNodesAndEdges:Ve,addSelectedEdges:rt,edges:ut}=Re.getState();Ue.key==="Escape"?((Fe=Ne.current)==null||Fe.blur(),Ve({edges:[ut.find(yt=>yt.id===n)]})):rt([n])}};return ve.createElement("g",{className:jn(["react-flow__edge",`react-flow__edge-${s}`,r,{selected:f,animated:p,inactive:ke,updating:Ie}]),onClick:ce,onDoubleClick:se,onContextMenu:be,onMouseEnter:Le,onMouseMove:de,onMouseLeave:fe,onKeyDown:Z?Ae:void 0,tabIndex:Z?0:void 0,role:Z?"button":"img","data-testid":`rf__edge-${n}`,"aria-label":z===null?void 0:z||`Edge from ${k} to ${j}`,"aria-describedby":Z?`${jA}-${re}`:void 0,ref:Ne},!Pe&&ve.createElement(e,{id:n,source:k,target:j,selected:f,animated:p,label:h,labelStyle:m,labelShowBg:y,labelBgStyle:v,labelBgPadding:S,labelBgBorderRadius:b,data:l,style:_,sourceX:E,sourceY:C,targetX:R,targetY:I,sourcePosition:$,targetPosition:q,sourceHandleId:W,targetHandleId:ne,markerStart:st,markerEnd:ue,pathOptions:ae,interactionWidth:le}),U&&ve.createElement(ve.Fragment,null,(U==="source"||U===!0)&&ve.createElement(AN,{position:$,centerX:E,centerY:C,radius:G,onMouseDown:pe,onMouseEnter:Ye,onMouseOut:qe,type:"source"}),(U==="target"||U===!0)&&ve.createElement(AN,{position:q,centerX:R,centerY:I,radius:G,onMouseDown:_e,onMouseEnter:Ye,onMouseOut:qe,type:"target"})))};return t.displayName="EdgeWrapper",w.memo(t)};function PD(e){const t={default:kl(e.default||Jh),straight:kl(e.bezier||yb),step:kl(e.step||gb),smoothstep:kl(e.step||bf),simplebezier:kl(e.simplebezier||mb)},n={},r=Object.keys(e).filter(s=>!["default","bezier"].includes(s)).reduce((s,l)=>(s[l]=kl(e[l]||Jh),s),n);return{...t,...r}}function MN(e,t,n=null){const r=((n==null?void 0:n.x)||0)+t.x,s=((n==null?void 0:n.y)||0)+t.y,l=(n==null?void 0:n.width)||t.width,c=(n==null?void 0:n.height)||t.height;switch(e){case nt.Top:return{x:r+l/2,y:s};case nt.Right:return{x:r+l,y:s+c/2};case nt.Bottom:return{x:r+l/2,y:s+c};case nt.Left:return{x:r,y:s+c/2}}}function IN(e,t){return e?e.length===1||!t?e[0]:t&&e.find(n=>n.id===t)||null:null}const DD=(e,t,n,r,s,l)=>{const c=MN(n,e,t),u=MN(l,r,s);return{sourceX:c.x,sourceY:c.y,targetX:u.x,targetY:u.y}};function FD({sourcePos:e,targetPos:t,sourceWidth:n,sourceHeight:r,targetWidth:s,targetHeight:l,width:c,height:u,transform:f}){const p={x:Math.min(e.x,t.x),y:Math.min(e.y,t.y),x2:Math.max(e.x+n,t.x+s),y2:Math.max(e.y+r,t.y+l)};p.x===p.x2&&(p.x2+=1),p.y===p.y2&&(p.y2+=1);const h=ju({x:(0-f[0])/f[2],y:(0-f[1])/f[2],width:c/f[2],height:u/f[2]}),m=Math.max(0,Math.min(h.x2,p.x2)-Math.max(h.x,p.x)),y=Math.max(0,Math.min(h.y2,p.y2)-Math.max(h.y,p.y));return Math.ceil(m*y)>0}function $N(e){var r,s,l,c,u;const t=((r=e==null?void 0:e[Wt])==null?void 0:r.handleBounds)||null,n=t&&(e==null?void 0:e.width)&&(e==null?void 0:e.height)&&typeof((s=e==null?void 0:e.positionAbsolute)==null?void 0:s.x)<"u"&&typeof((l=e==null?void 0:e.positionAbsolute)==null?void 0:l.y)<"u";return[{x:((c=e==null?void 0:e.positionAbsolute)==null?void 0:c.x)||0,y:((u=e==null?void 0:e.positionAbsolute)==null?void 0:u.y)||0,width:(e==null?void 0:e.width)||0,height:(e==null?void 0:e.height)||0},t,!!n]}const qD=[{level:0,isMaxLevel:!0,edges:[]}];function BD(e,t,n=!1){let r=-1;const s=e.reduce((c,u)=>{var h,m;const f=Pr(u.zIndex);let p=f?u.zIndex:0;if(n){const y=t.get(u.target),v=t.get(u.source),S=u.selected||(y==null?void 0:y.selected)||(v==null?void 0:v.selected),b=Math.max(((h=v==null?void 0:v[Wt])==null?void 0:h.z)||0,((m=y==null?void 0:y[Wt])==null?void 0:m.z)||0,1e3);p=(f?u.zIndex:0)+(S?b:0)}return c[p]?c[p].push(u):c[p]=[u],r=p>r?p:r,c},{}),l=Object.entries(s).map(([c,u])=>{const f=+c;return{edges:u,level:f,isMaxLevel:f===r}});return l.length===0?qD:l}function zD(e,t,n){const r=Et(w.useCallback(s=>e?s.edges.filter(l=>{const c=t.get(l.source),u=t.get(l.target);return(c==null?void 0:c.width)&&(c==null?void 0:c.height)&&(u==null?void 0:u.width)&&(u==null?void 0:u.height)&&FD({sourcePos:c.positionAbsolute||{x:0,y:0},targetPos:u.positionAbsolute||{x:0,y:0},sourceWidth:c.width,sourceHeight:c.height,targetWidth:u.width,targetHeight:u.height,width:s.width,height:s.height,transform:s.transform})}):s.edges,[e,t]));return BD(r,t,n)}const UD=({color:e="none",strokeWidth:t=1})=>ve.createElement("polyline",{style:{stroke:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",fill:"none",points:"-5,-4 0,0 -5,4"}),HD=({color:e="none",strokeWidth:t=1})=>ve.createElement("polyline",{style:{stroke:e,fill:e,strokeWidth:t},strokeLinecap:"round",strokeLinejoin:"round",points:"-5,-4 0,0 -5,4 -5,-4"}),ON={[Qh.Arrow]:UD,[Qh.ArrowClosed]:HD};function WD(e){const t=tn();return w.useMemo(()=>{var s,l;return Object.prototype.hasOwnProperty.call(ON,e)?ON[e]:((l=(s=t.getState()).onError)==null||l.call(s,"009",ha.error009(e)),null)},[e])}const VD=({id:e,type:t,color:n,width:r=12.5,height:s=12.5,markerUnits:l="strokeWidth",strokeWidth:c,orient:u="auto-start-reverse"})=>{const f=WD(t);return f?ve.createElement("marker",{className:"react-flow__arrowhead",id:e,markerWidth:`${r}`,markerHeight:`${s}`,viewBox:"-10 -10 20 20",markerUnits:l,orient:u,refX:"0",refY:"0"},ve.createElement(f,{color:n,strokeWidth:c})):null},GD=({defaultColor:e,rfId:t})=>n=>{const r=[];return n.edges.reduce((s,l)=>([l.markerStart,l.markerEnd].forEach(c=>{if(c&&typeof c=="object"){const u=k0(c,t);r.includes(u)||(s.push({id:u,color:c.color||e,...c}),r.push(u))}}),s),[]).sort((s,l)=>s.id.localeCompare(l.id))},LA=({defaultColor:e,rfId:t})=>{const n=Et(w.useCallback(GD({defaultColor:e,rfId:t}),[e,t]),(r,s)=>!(r.length!==s.length||r.some((l,c)=>l.id!==s[c].id)));return ve.createElement("defs",null,n.map(r=>ve.createElement(VD,{id:r.id,key:r.id,type:r.type,color:r.color,width:r.width,height:r.height,markerUnits:r.markerUnits,strokeWidth:r.strokeWidth,orient:r.orient})))};LA.displayName="MarkerDefinitions";var KD=w.memo(LA);const YD=e=>({nodesConnectable:e.nodesConnectable,edgesFocusable:e.edgesFocusable,edgesUpdatable:e.edgesUpdatable,elementsSelectable:e.elementsSelectable,width:e.width,height:e.height,connectionMode:e.connectionMode,nodeInternals:e.nodeInternals,onError:e.onError}),PA=({defaultMarkerColor:e,onlyRenderVisibleElements:t,elevateEdgesOnSelect:n,rfId:r,edgeTypes:s,noPanClassName:l,onEdgeContextMenu:c,onEdgeMouseEnter:u,onEdgeMouseMove:f,onEdgeMouseLeave:p,onEdgeClick:h,onEdgeDoubleClick:m,onReconnect:y,onReconnectStart:v,onReconnectEnd:S,reconnectRadius:b,children:_,disableKeyboardA11y:k})=>{const{edgesFocusable:j,edgesUpdatable:E,elementsSelectable:C,width:R,height:I,connectionMode:$,nodeInternals:q,onError:B}=Et(YD,pn),P=zD(t,q,n);return R?ve.createElement(ve.Fragment,null,P.map(({level:W,edges:ne,isMaxLevel:ee})=>ve.createElement("svg",{key:W,style:{zIndex:W},width:R,height:I,className:"react-flow__edges react-flow__container"},ee&&ve.createElement(KD,{defaultColor:e,rfId:r}),ve.createElement("g",null,ne.map(M=>{const[X,V,G]=$N(q.get(M.source)),[F,L,H]=$N(q.get(M.target));if(!G||!H)return null;let D=M.type||"default";s[D]||(B==null||B("011",ha.error011(D)),D="default");const K=s[D]||s.default,re=$===mi.Strict?L.target:(L.target??[]).concat(L.source??[]),z=IN(V.source,M.sourceHandle),Z=IN(re,M.targetHandle),U=(z==null?void 0:z.position)||nt.Bottom,ae=(Z==null?void 0:Z.position)||nt.Top,le=!!(M.focusable||j&&typeof M.focusable>"u"),ge=M.reconnectable||M.updatable,Ne=typeof y<"u"&&(ge||E&&typeof ge>"u");if(!z||!Z)return B==null||B("008",ha.error008(z,M)),null;const{sourceX:Ie,sourceY:Ge,targetX:Pe,targetY:ze}=DD(X,z,U,F,Z,ae);return ve.createElement(K,{key:M.id,id:M.id,className:jn([M.className,l]),type:D,data:M.data,selected:!!M.selected,animated:!!M.animated,hidden:!!M.hidden,label:M.label,labelStyle:M.labelStyle,labelShowBg:M.labelShowBg,labelBgStyle:M.labelBgStyle,labelBgPadding:M.labelBgPadding,labelBgBorderRadius:M.labelBgBorderRadius,style:M.style,source:M.source,target:M.target,sourceHandleId:M.sourceHandle,targetHandleId:M.targetHandle,markerEnd:M.markerEnd,markerStart:M.markerStart,sourceX:Ie,sourceY:Ge,targetX:Pe,targetY:ze,sourcePosition:U,targetPosition:ae,elementsSelectable:C,onContextMenu:c,onMouseEnter:u,onMouseMove:f,onMouseLeave:p,onClick:h,onEdgeDoubleClick:m,onReconnect:y,onReconnectStart:v,onReconnectEnd:S,reconnectRadius:b,rfId:r,ariaLabel:M.ariaLabel,isFocusable:le,isReconnectable:Ne,pathOptions:"pathOptions"in M?M.pathOptions:void 0,interactionWidth:M.interactionWidth,disableKeyboardA11y:k})})))),_):null};PA.displayName="EdgeRenderer";var XD=w.memo(PA);const ZD=e=>`translate(${e.transform[0]}px,${e.transform[1]}px) scale(${e.transform[2]})`;function QD({children:e}){const t=Et(ZD);return ve.createElement("div",{className:"react-flow__viewport react-flow__container",style:{transform:t}},e)}function JD(e){const t=Nf(),n=w.useRef(!1);w.useEffect(()=>{!n.current&&t.viewportInitialized&&e&&(setTimeout(()=>e(t),1),n.current=!0)},[e,t.viewportInitialized])}const e5={[nt.Left]:nt.Right,[nt.Right]:nt.Left,[nt.Top]:nt.Bottom,[nt.Bottom]:nt.Top},DA=({nodeId:e,handleType:t,style:n,type:r=eo.Bezier,CustomComponent:s,connectionStatus:l})=>{var I,$,q;const{fromNode:c,handleId:u,toX:f,toY:p,connectionMode:h}=Et(w.useCallback(B=>({fromNode:B.nodeInternals.get(e),handleId:B.connectionHandleId,toX:(B.connectionPosition.x-B.transform[0])/B.transform[2],toY:(B.connectionPosition.y-B.transform[1])/B.transform[2],connectionMode:B.connectionMode}),[e]),pn),m=(I=c==null?void 0:c[Wt])==null?void 0:I.handleBounds;let y=m==null?void 0:m[t];if(h===mi.Loose&&(y=y||(m==null?void 0:m[t==="source"?"target":"source"])),!c||!y)return null;const v=u?y.find(B=>B.id===u):y[0],S=v?v.x+v.width/2:(c.width??0)/2,b=v?v.y+v.height/2:c.height??0,_=((($=c.positionAbsolute)==null?void 0:$.x)??0)+S,k=(((q=c.positionAbsolute)==null?void 0:q.y)??0)+b,j=v==null?void 0:v.position,E=j?e5[j]:null;if(!j||!E)return null;if(s)return ve.createElement(s,{connectionLineType:r,connectionLineStyle:n,fromNode:c,fromHandle:v,fromX:_,fromY:k,toX:f,toY:p,fromPosition:j,toPosition:E,connectionStatus:l});let C="";const R={sourceX:_,sourceY:k,sourcePosition:j,targetX:f,targetY:p,targetPosition:E};return r===eo.Bezier?[C]=wb(R):r===eo.Step?[C]=b0({...R,borderRadius:0}):r===eo.SmoothStep?[C]=b0(R):r===eo.SimpleBezier?[C]=cA(R):C=`M${_},${k} ${f},${p}`,ve.createElement("path",{d:C,fill:"none",className:"react-flow__connection-path",style:n})};DA.displayName="ConnectionLine";const t5=e=>({nodeId:e.connectionNodeId,handleType:e.connectionHandleType,nodesConnectable:e.nodesConnectable,connectionStatus:e.connectionStatus,width:e.width,height:e.height});function n5({containerStyle:e,style:t,type:n,component:r}){const{nodeId:s,handleType:l,nodesConnectable:c,width:u,height:f,connectionStatus:p}=Et(t5,pn);return!(s&&l&&u&&c)?null:ve.createElement("svg",{style:e,width:u,height:f,className:"react-flow__edges react-flow__connectionline react-flow__container"},ve.createElement("g",{className:jn(["react-flow__connection",p])},ve.createElement(DA,{nodeId:s,handleType:l,style:t,type:n,CustomComponent:r,connectionStatus:p})))}function LN(e,t){return w.useRef(null),tn(),w.useMemo(()=>t(e),[e])}const FA=({nodeTypes:e,edgeTypes:t,onMove:n,onMoveStart:r,onMoveEnd:s,onInit:l,onNodeClick:c,onEdgeClick:u,onNodeDoubleClick:f,onEdgeDoubleClick:p,onNodeMouseEnter:h,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:v,onSelectionContextMenu:S,onSelectionStart:b,onSelectionEnd:_,connectionLineType:k,connectionLineStyle:j,connectionLineComponent:E,connectionLineContainerStyle:C,selectionKeyCode:R,selectionOnDrag:I,selectionMode:$,multiSelectionKeyCode:q,panActivationKeyCode:B,zoomActivationKeyCode:P,deleteKeyCode:W,onlyRenderVisibleElements:ne,elementsSelectable:ee,selectNodesOnDrag:M,defaultViewport:X,translateExtent:V,minZoom:G,maxZoom:F,preventScrolling:L,defaultMarkerColor:H,zoomOnScroll:D,zoomOnPinch:K,panOnScroll:re,panOnScrollSpeed:z,panOnScrollMode:Z,zoomOnDoubleClick:U,panOnDrag:ae,onPaneClick:le,onPaneMouseEnter:ge,onPaneMouseMove:Ne,onPaneMouseLeave:Ie,onPaneScroll:Ge,onPaneContextMenu:Pe,onEdgeContextMenu:ze,onEdgeMouseEnter:Re,onEdgeMouseMove:st,onEdgeMouseLeave:ue,onReconnect:ce,onReconnectStart:se,onReconnectEnd:be,reconnectRadius:Le,noDragClassName:de,noWheelClassName:fe,noPanClassName:Ce,elevateEdgesOnSelect:pe,disableKeyboardA11y:_e,nodeOrigin:Ye,nodeExtent:qe,rfId:ke})=>{const Ae=LN(e,RD),Ue=LN(t,PD);return JD(l),ve.createElement(CD,{onPaneClick:le,onPaneMouseEnter:ge,onPaneMouseMove:Ne,onPaneMouseLeave:Ie,onPaneContextMenu:Pe,onPaneScroll:Ge,deleteKeyCode:W,selectionKeyCode:R,selectionOnDrag:I,selectionMode:$,onSelectionStart:b,onSelectionEnd:_,multiSelectionKeyCode:q,panActivationKeyCode:B,zoomActivationKeyCode:P,elementsSelectable:ee,onMove:n,onMoveStart:r,onMoveEnd:s,zoomOnScroll:D,zoomOnPinch:K,zoomOnDoubleClick:U,panOnScroll:re,panOnScrollSpeed:z,panOnScrollMode:Z,panOnDrag:ae,defaultViewport:X,translateExtent:V,minZoom:G,maxZoom:F,onSelectionContextMenu:S,preventScrolling:L,noDragClassName:de,noWheelClassName:fe,noPanClassName:Ce,disableKeyboardA11y:_e},ve.createElement(QD,null,ve.createElement(XD,{edgeTypes:Ue,onEdgeClick:u,onEdgeDoubleClick:p,onlyRenderVisibleElements:ne,onEdgeContextMenu:ze,onEdgeMouseEnter:Re,onEdgeMouseMove:st,onEdgeMouseLeave:ue,onReconnect:ce,onReconnectStart:se,onReconnectEnd:be,reconnectRadius:Le,defaultMarkerColor:H,noPanClassName:Ce,elevateEdgesOnSelect:!!pe,disableKeyboardA11y:_e,rfId:ke},ve.createElement(n5,{style:j,type:k,component:E,containerStyle:C})),ve.createElement("div",{className:"react-flow__edgelabel-renderer"}),ve.createElement(ID,{nodeTypes:Ae,onNodeClick:c,onNodeDoubleClick:f,onNodeMouseEnter:h,onNodeMouseMove:m,onNodeMouseLeave:y,onNodeContextMenu:v,selectNodesOnDrag:M,onlyRenderVisibleElements:ne,noPanClassName:Ce,noDragClassName:de,disableKeyboardA11y:_e,nodeOrigin:Ye,nodeExtent:qe,rfId:ke})))};FA.displayName="GraphView";var r5=w.memo(FA);const _0=[[Number.NEGATIVE_INFINITY,Number.NEGATIVE_INFINITY],[Number.POSITIVE_INFINITY,Number.POSITIVE_INFINITY]],Ka={rfId:"1",width:0,height:0,transform:[0,0,1],nodeInternals:new Map,edges:[],onNodesChange:null,onEdgesChange:null,hasDefaultNodes:!1,hasDefaultEdges:!1,d3Zoom:null,d3Selection:null,d3ZoomHandler:void 0,minZoom:.5,maxZoom:2,translateExtent:_0,nodeExtent:_0,nodesSelectionActive:!1,userSelectionActive:!1,userSelectionRect:null,connectionNodeId:null,connectionHandleId:null,connectionHandleType:"source",connectionPosition:{x:0,y:0},connectionStatus:null,connectionMode:mi.Strict,domNode:null,paneDragging:!1,noPanClassName:"nopan",nodeOrigin:[0,0],nodeDragThreshold:0,snapGrid:[15,15],snapToGrid:!1,nodesDraggable:!0,nodesConnectable:!0,nodesFocusable:!0,edgesFocusable:!0,edgesUpdatable:!0,elementsSelectable:!0,elevateNodesOnSelect:!0,fitViewOnInit:!1,fitViewOnInitDone:!1,fitViewOnInitOptions:void 0,onSelectionChange:[],multiSelectionActive:!1,connectionStartHandle:null,connectionEndHandle:null,connectionClickStartHandle:null,connectOnClick:!0,ariaLiveMessage:"",autoPanOnConnect:!0,autoPanOnNodeDrag:!0,connectionRadius:20,onError:R4,isValidConnection:void 0},s5=()=>WO((e,t)=>({...Ka,setNodes:n=>{const{nodeInternals:r,nodeOrigin:s,elevateNodesOnSelect:l}=t();e({nodeInternals:gm(n,r,s,l)})},getNodes:()=>Array.from(t().nodeInternals.values()),setEdges:n=>{const{defaultEdgeOptions:r={}}=t();e({edges:n.map(s=>({...r,...s}))})},setDefaultNodesAndEdges:(n,r)=>{const s=typeof n<"u",l=typeof r<"u",c=s?gm(n,new Map,t().nodeOrigin,t().elevateNodesOnSelect):new Map;e({nodeInternals:c,edges:l?r:[],hasDefaultNodes:s,hasDefaultEdges:l})},updateNodeDimensions:n=>{const{onNodesChange:r,nodeInternals:s,fitViewOnInit:l,fitViewOnInitDone:c,fitViewOnInitOptions:u,domNode:f,nodeOrigin:p}=t(),h=f==null?void 0:f.querySelector(".react-flow__viewport");if(!h)return;const m=window.getComputedStyle(h),{m22:y}=new window.DOMMatrixReadOnly(m.transform),v=n.reduce((b,_)=>{const k=s.get(_.id);if(k!=null&&k.hidden)s.set(k.id,{...k,[Wt]:{...k[Wt],handleBounds:void 0}});else if(k){const j=fb(_.nodeElement);!!(j.width&&j.height&&(k.width!==j.width||k.height!==j.height||_.forceUpdate))&&(s.set(k.id,{...k,[Wt]:{...k[Wt],handleBounds:{source:TN(".source",_.nodeElement,y,p),target:TN(".target",_.nodeElement,y,p)}},...j}),b.push({id:k.id,type:"dimensions",dimensions:j}))}return b},[]);EA(s,p);const S=c||l&&!c&&CA(t,{initial:!0,...u});e({nodeInternals:new Map(s),fitViewOnInitDone:S}),(v==null?void 0:v.length)>0&&(r==null||r(v))},updateNodePositions:(n,r=!0,s=!1)=>{const{triggerNodeChanges:l}=t(),c=n.map(u=>{const f={id:u.id,type:"position",dragging:s};return r&&(f.positionAbsolute=u.positionAbsolute,f.position=u.position),f});l(c)},triggerNodeChanges:n=>{const{onNodesChange:r,nodeInternals:s,hasDefaultNodes:l,nodeOrigin:c,getNodes:u,elevateNodesOnSelect:f}=t();if(n!=null&&n.length){if(l){const p=vD(n,u()),h=gm(p,s,c,f);e({nodeInternals:h})}r==null||r(n)}},addSelectedNodes:n=>{const{multiSelectionActive:r,edges:s,getNodes:l}=t();let c,u=null;r?c=n.map(f=>Ja(f,!0)):(c=Il(l(),n),u=Il(s,[])),hh({changedNodes:c,changedEdges:u,get:t,set:e})},addSelectedEdges:n=>{const{multiSelectionActive:r,edges:s,getNodes:l}=t();let c,u=null;r?c=n.map(f=>Ja(f,!0)):(c=Il(s,n),u=Il(l(),[])),hh({changedNodes:u,changedEdges:c,get:t,set:e})},unselectNodesAndEdges:({nodes:n,edges:r}={})=>{const{edges:s,getNodes:l}=t(),c=n||l(),u=r||s,f=c.map(h=>(h.selected=!1,Ja(h.id,!1))),p=u.map(h=>Ja(h.id,!1));hh({changedNodes:f,changedEdges:p,get:t,set:e})},setMinZoom:n=>{const{d3Zoom:r,maxZoom:s}=t();r==null||r.scaleExtent([n,s]),e({minZoom:n})},setMaxZoom:n=>{const{d3Zoom:r,minZoom:s}=t();r==null||r.scaleExtent([s,n]),e({maxZoom:n})},setTranslateExtent:n=>{var r;(r=t().d3Zoom)==null||r.translateExtent(n),e({translateExtent:n})},resetSelectedElements:()=>{const{edges:n,getNodes:r}=t(),l=r().filter(u=>u.selected).map(u=>Ja(u.id,!1)),c=n.filter(u=>u.selected).map(u=>Ja(u.id,!1));hh({changedNodes:l,changedEdges:c,get:t,set:e})},setNodeExtent:n=>{const{nodeInternals:r}=t();r.forEach(s=>{s.positionAbsolute=pb(s.position,n)}),e({nodeExtent:n,nodeInternals:new Map(r)})},panBy:n=>{const{transform:r,width:s,height:l,d3Zoom:c,d3Selection:u,translateExtent:f}=t();if(!c||!u||!n.x&&!n.y)return!1;const p=ua.translate(r[0]+n.x,r[1]+n.y).scale(r[2]),h=[[0,0],[s,l]],m=c==null?void 0:c.constrain()(p,h,f);return c.transform(u,m),r[0]!==m.x||r[1]!==m.y||r[2]!==m.k},cancelConnection:()=>e({connectionNodeId:Ka.connectionNodeId,connectionHandleId:Ka.connectionHandleId,connectionHandleType:Ka.connectionHandleType,connectionStatus:Ka.connectionStatus,connectionStartHandle:Ka.connectionStartHandle,connectionEndHandle:Ka.connectionEndHandle}),reset:()=>e({...Ka})}),Object.is),Nb=({children:e})=>{const t=w.useRef(null);return t.current||(t.current=s5()),ve.createElement(N4,{value:t.current},e)};Nb.displayName="ReactFlowProvider";const qA=({children:e})=>w.useContext(xf)?ve.createElement(ve.Fragment,null,e):ve.createElement(Nb,null,e);qA.displayName="ReactFlowWrapper";const a5={input:xA,default:S0,output:kA,group:bb},o5={default:Jh,straight:yb,step:gb,smoothstep:bf,simplebezier:mb},i5=[0,0],l5=[15,15],c5={x:0,y:0,zoom:1},u5={width:"100%",height:"100%",overflow:"hidden",position:"relative",zIndex:0},BA=w.forwardRef(({nodes:e,edges:t,defaultNodes:n,defaultEdges:r,className:s,nodeTypes:l=a5,edgeTypes:c=o5,onNodeClick:u,onEdgeClick:f,onInit:p,onMove:h,onMoveStart:m,onMoveEnd:y,onConnect:v,onConnectStart:S,onConnectEnd:b,onClickConnectStart:_,onClickConnectEnd:k,onNodeMouseEnter:j,onNodeMouseMove:E,onNodeMouseLeave:C,onNodeContextMenu:R,onNodeDoubleClick:I,onNodeDragStart:$,onNodeDrag:q,onNodeDragStop:B,onNodesDelete:P,onEdgesDelete:W,onSelectionChange:ne,onSelectionDragStart:ee,onSelectionDrag:M,onSelectionDragStop:X,onSelectionContextMenu:V,onSelectionStart:G,onSelectionEnd:F,connectionMode:L=mi.Strict,connectionLineType:H=eo.Bezier,connectionLineStyle:D,connectionLineComponent:K,connectionLineContainerStyle:re,deleteKeyCode:z="Backspace",selectionKeyCode:Z="Shift",selectionOnDrag:U=!1,selectionMode:ae=_u.Full,panActivationKeyCode:le="Space",multiSelectionKeyCode:ge=Zh()?"Meta":"Control",zoomActivationKeyCode:Ne=Zh()?"Meta":"Control",snapToGrid:Ie=!1,snapGrid:Ge=l5,onlyRenderVisibleElements:Pe=!1,selectNodesOnDrag:ze=!0,nodesDraggable:Re,nodesConnectable:st,nodesFocusable:ue,nodeOrigin:ce=i5,edgesFocusable:se,edgesUpdatable:be,elementsSelectable:Le,defaultViewport:de=c5,minZoom:fe=.5,maxZoom:Ce=2,translateExtent:pe=_0,preventScrolling:_e=!0,nodeExtent:Ye,defaultMarkerColor:qe="#b1b1b7",zoomOnScroll:ke=!0,zoomOnPinch:Ae=!0,panOnScroll:Ue=!1,panOnScrollSpeed:Fe=.5,panOnScrollMode:Ve=li.Free,zoomOnDoubleClick:rt=!0,panOnDrag:ut=!0,onPaneClick:ct,onPaneMouseEnter:yt,onPaneMouseMove:It,onPaneMouseLeave:zt,onPaneScroll:Xt,onPaneContextMenu:Ft,children:rn,onEdgeContextMenu:Se,onEdgeDoubleClick:vt,onEdgeMouseEnter:kt,onEdgeMouseMove:_n,onEdgeMouseLeave:Ut,onEdgeUpdate:Vn,onEdgeUpdateStart:Vt,onEdgeUpdateEnd:$t,onReconnect:Zt,onReconnectStart:Ln,onReconnectEnd:Ur,reconnectRadius:xe=10,edgeUpdaterRadius:ir=10,onNodesChange:Ns,onEdgesChange:Hr,noDragClassName:ma="nodrag",noWheelClassName:Ss="nowheel",noPanClassName:xr="nopan",fitView:Pn=!1,fitViewOptions:Hs,connectOnClick:Q=!0,attributionPosition:De,proOptions:Je,defaultEdgeOptions:He,elevateNodesOnSelect:tt=!0,elevateEdgesOnSelect:wt=!1,disableKeyboardA11y:gt=!1,autoPanOnConnect:At=!0,autoPanOnNodeDrag:Ct=!0,connectionRadius:Qt=20,isValidConnection:St,onError:br,style:lr,id:Ci,nodeDragThreshold:dt,...cr},sn)=>{const Wr=Ci||"1";return ve.createElement("div",{...cr,style:{...lr,...u5},ref:sn,className:jn(["react-flow",s]),"data-testid":"rf__wrapper",id:Ci},ve.createElement(qA,null,ve.createElement(r5,{onInit:p,onMove:h,onMoveStart:m,onMoveEnd:y,onNodeClick:u,onEdgeClick:f,onNodeMouseEnter:j,onNodeMouseMove:E,onNodeMouseLeave:C,onNodeContextMenu:R,onNodeDoubleClick:I,nodeTypes:l,edgeTypes:c,connectionLineType:H,connectionLineStyle:D,connectionLineComponent:K,connectionLineContainerStyle:re,selectionKeyCode:Z,selectionOnDrag:U,selectionMode:ae,deleteKeyCode:z,multiSelectionKeyCode:ge,panActivationKeyCode:le,zoomActivationKeyCode:Ne,onlyRenderVisibleElements:Pe,selectNodesOnDrag:ze,defaultViewport:de,translateExtent:pe,minZoom:fe,maxZoom:Ce,preventScrolling:_e,zoomOnScroll:ke,zoomOnPinch:Ae,zoomOnDoubleClick:rt,panOnScroll:Ue,panOnScrollSpeed:Fe,panOnScrollMode:Ve,panOnDrag:ut,onPaneClick:ct,onPaneMouseEnter:yt,onPaneMouseMove:It,onPaneMouseLeave:zt,onPaneScroll:Xt,onPaneContextMenu:Ft,onSelectionContextMenu:V,onSelectionStart:G,onSelectionEnd:F,onEdgeContextMenu:Se,onEdgeDoubleClick:vt,onEdgeMouseEnter:kt,onEdgeMouseMove:_n,onEdgeMouseLeave:Ut,onReconnect:Zt??Vn,onReconnectStart:Ln??Vt,onReconnectEnd:Ur??$t,reconnectRadius:xe??ir,defaultMarkerColor:qe,noDragClassName:ma,noWheelClassName:Ss,noPanClassName:xr,elevateEdgesOnSelect:wt,rfId:Wr,disableKeyboardA11y:gt,nodeOrigin:ce,nodeExtent:Ye}),ve.createElement(J4,{nodes:e,edges:t,defaultNodes:n,defaultEdges:r,onConnect:v,onConnectStart:S,onConnectEnd:b,onClickConnectStart:_,onClickConnectEnd:k,nodesDraggable:Re,nodesConnectable:st,nodesFocusable:ue,edgesFocusable:se,edgesUpdatable:be,elementsSelectable:Le,elevateNodesOnSelect:tt,minZoom:fe,maxZoom:Ce,nodeExtent:Ye,onNodesChange:Ns,onEdgesChange:Hr,snapToGrid:Ie,snapGrid:Ge,connectionMode:L,translateExtent:pe,connectOnClick:Q,defaultEdgeOptions:He,fitView:Pn,fitViewOptions:Hs,onNodesDelete:P,onEdgesDelete:W,onNodeDragStart:$,onNodeDrag:q,onNodeDragStop:B,onSelectionDrag:M,onSelectionDragStart:ee,onSelectionDragStop:X,noPanClassName:xr,nodeOrigin:ce,rfId:Wr,autoPanOnConnect:At,autoPanOnNodeDrag:Ct,onError:br,connectionRadius:Qt,isValidConnection:St,nodeDragThreshold:dt}),ve.createElement(Z4,{onSelectionChange:ne}),rn,ve.createElement(j4,{proOptions:Je,position:De}),ve.createElement(sD,{rfId:Wr,disableKeyboardA11y:gt})))});BA.displayName="ReactFlow";const d5=e=>({x:e.transform[0],y:e.transform[1],zoom:e.transform[2]});function zA(){return Et(d5,pn)}const UA=({id:e,x:t,y:n,width:r,height:s,style:l,color:c,strokeColor:u,strokeWidth:f,className:p,borderRadius:h,shapeRendering:m,onClick:y,selected:v})=>{const{background:S,backgroundColor:b}=l||{},_=c||S||b;return ve.createElement("rect",{className:jn(["react-flow__minimap-node",{selected:v},p]),x:t,y:n,rx:h,ry:h,width:r,height:s,fill:_,stroke:u,strokeWidth:f,shapeRendering:m,onClick:y?k=>y(k,e):void 0})};UA.displayName="MiniMapNode";var h5=w.memo(UA);const f5=e=>e.nodeOrigin,p5=e=>e.getNodes().filter(t=>!t.hidden&&t.width&&t.height),xm=e=>e instanceof Function?e:()=>e;function m5({nodeStrokeColor:e="transparent",nodeColor:t="#e2e2e2",nodeClassName:n="",nodeBorderRadius:r=5,nodeStrokeWidth:s=2,nodeComponent:l=h5,onClick:c}){const u=Et(p5,pn),f=Et(f5),p=xm(t),h=xm(e),m=xm(n),y=typeof window>"u"||window.chrome?"crispEdges":"geometricPrecision";return ve.createElement(ve.Fragment,null,u.map(v=>{const{x:S,y:b}=ui(v,f).positionAbsolute;return ve.createElement(l,{key:v.id,x:S,y:b,width:v.width,height:v.height,style:v.style,selected:v.selected,className:m(v),color:p(v),borderRadius:r,strokeColor:h(v),strokeWidth:s,shapeRendering:y,onClick:c,id:v.id})}))}var g5=w.memo(m5);const y5=200,w5=150,v5=e=>{const t=e.getNodes(),n={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:n,boundingRect:t.length>0?C4(kf(t,e.nodeOrigin),n):n,rfId:e.rfId}},x5="react-flow__minimap-desc";function HA({style:e,className:t,nodeStrokeColor:n="transparent",nodeColor:r="#e2e2e2",nodeClassName:s="",nodeBorderRadius:l=5,nodeStrokeWidth:c=2,nodeComponent:u,maskColor:f="rgb(240, 240, 240, 0.6)",maskStrokeColor:p="none",maskStrokeWidth:h=1,position:m="bottom-right",onClick:y,onNodeClick:v,pannable:S=!1,zoomable:b=!1,ariaLabel:_="React Flow mini map",inversePan:k=!1,zoomStep:j=10,offsetScale:E=5}){const C=tn(),R=w.useRef(null),{boundingRect:I,viewBB:$,rfId:q}=Et(v5,pn),B=(e==null?void 0:e.width)??y5,P=(e==null?void 0:e.height)??w5,W=I.width/B,ne=I.height/P,ee=Math.max(W,ne),M=ee*B,X=ee*P,V=E*ee,G=I.x-(M-I.width)/2-V,F=I.y-(X-I.height)/2-V,L=M+V*2,H=X+V*2,D=`${x5}-${q}`,K=w.useRef(0);K.current=ee,w.useEffect(()=>{if(R.current){const Z=Lr(R.current),U=ge=>{const{transform:Ne,d3Selection:Ie,d3Zoom:Ge}=C.getState();if(ge.sourceEvent.type!=="wheel"||!Ie||!Ge)return;const Pe=-ge.sourceEvent.deltaY*(ge.sourceEvent.deltaMode===1?.05:ge.sourceEvent.deltaMode?1:.002)*j,ze=Ne[2]*Math.pow(2,Pe);Ge.scaleTo(Ie,ze)},ae=ge=>{const{transform:Ne,d3Selection:Ie,d3Zoom:Ge,translateExtent:Pe,width:ze,height:Re}=C.getState();if(ge.sourceEvent.type!=="mousemove"||!Ie||!Ge)return;const st=K.current*Math.max(1,Ne[2])*(k?-1:1),ue={x:Ne[0]-ge.sourceEvent.movementX*st,y:Ne[1]-ge.sourceEvent.movementY*st},ce=[[0,0],[ze,Re]],se=ua.translate(ue.x,ue.y).scale(Ne[2]),be=Ge.constrain()(se,ce,Pe);Ge.transform(Ie,be)},le=JR().on("zoom",S?ae:null).on("zoom.wheel",b?U:null);return Z.call(le),()=>{Z.on("zoom",null)}}},[S,b,k,j]);const re=y?Z=>{const U=fs(Z);y(Z,{x:U[0],y:U[1]})}:void 0,z=v?(Z,U)=>{const ae=C.getState().nodeInternals.get(U);v(Z,ae)}:void 0;return ve.createElement(hb,{position:m,style:e,className:jn(["react-flow__minimap",t]),"data-testid":"rf__minimap"},ve.createElement("svg",{width:B,height:P,viewBox:`${G} ${F} ${L} ${H}`,role:"img","aria-labelledby":D,ref:R,onClick:re},_&&ve.createElement("title",{id:D},_),ve.createElement(g5,{onClick:z,nodeColor:r,nodeStrokeColor:n,nodeBorderRadius:l,nodeClassName:s,nodeStrokeWidth:c,nodeComponent:u}),ve.createElement("path",{className:"react-flow__minimap-mask",d:`M${G-V},${F-V}h${L+V*2}v${H+V*2}h${-L-V*2}z
57
- M${$.x},${$.y}h${$.width}v${$.height}h${-$.width}z`,fill:f,fillRule:"evenodd",stroke:p,strokeWidth:h,pointerEvents:"none"})))}HA.displayName="MiniMap";var b5=w.memo(HA);function k5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},ve.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function N5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},ve.createElement("path",{d:"M0 0h32v4.2H0z"}))}function S5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},ve.createElement("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 j5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},ve.createElement("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 _5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},ve.createElement("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"}))}const Or=({children:e,className:t,...n})=>ve.createElement("button",{type:"button",className:jn(["react-flow__controls-button",t]),...n},e);Or.displayName="ControlButton";const E5=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),WA=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:l,onZoomOut:c,onFitView:u,onInteractiveChange:f,className:p,children:h,position:m="bottom-left"})=>{const y=tn(),[v,S]=w.useState(!1),{isInteractive:b,minZoomReached:_,maxZoomReached:k}=Et(E5,pn),{zoomIn:j,zoomOut:E,fitView:C}=Nf();if(w.useEffect(()=>{S(!0)},[]),!v)return null;const R=()=>{j(),l==null||l()},I=()=>{E(),c==null||c()},$=()=>{C(s),u==null||u()},q=()=>{y.setState({nodesDraggable:!b,nodesConnectable:!b,elementsSelectable:!b}),f==null||f(!b)};return ve.createElement(hb,{className:jn(["react-flow__controls",p]),position:m,style:e,"data-testid":"rf__controls"},t&&ve.createElement(ve.Fragment,null,ve.createElement(Or,{onClick:R,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:k},ve.createElement(k5,null)),ve.createElement(Or,{onClick:I,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:_},ve.createElement(N5,null))),n&&ve.createElement(Or,{className:"react-flow__controls-fitview",onClick:$,title:"fit view","aria-label":"fit view"},ve.createElement(S5,null)),r&&ve.createElement(Or,{className:"react-flow__controls-interactive",onClick:q,title:"toggle interactivity","aria-label":"toggle interactivity"},b?ve.createElement(_5,null):ve.createElement(j5,null)),h)};WA.displayName="Controls";var C5=w.memo(WA),ys;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ys||(ys={}));function T5({color:e,dimensions:t,lineWidth:n}){return ve.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function R5({color:e,radius:t}){return ve.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const A5={[ys.Dots]:"#91919a",[ys.Lines]:"#eee",[ys.Cross]:"#e2e2e2"},M5={[ys.Dots]:1,[ys.Lines]:1,[ys.Cross]:6},I5=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function VA({id:e,variant:t=ys.Dots,gap:n=20,size:r,lineWidth:s=1,offset:l=2,color:c,style:u,className:f}){const p=w.useRef(null),{transform:h,patternId:m}=Et(I5,pn),y=c||A5[t],v=r||M5[t],S=t===ys.Dots,b=t===ys.Cross,_=Array.isArray(n)?n:[n,n],k=[_[0]*h[2]||1,_[1]*h[2]||1],j=v*h[2],E=b?[j,j]:k,C=S?[j/l,j/l]:[E[0]/l,E[1]/l];return ve.createElement("svg",{className:jn(["react-flow__background",f]),style:{...u,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:p,"data-testid":"rf__background"},ve.createElement("pattern",{id:m+e,x:h[0]%k[0],y:h[1]%k[1],width:k[0],height:k[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`},S?ve.createElement(R5,{color:y,radius:j/l}):ve.createElement(T5,{dimensions:E,color:y,lineWidth:s})),ve.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${m+e})`}))}VA.displayName="Background";var $5=w.memo(VA);const O5=["us-gov","global","apac","us","eu","jp","au"],L5=new RegExp(`^(?:(?:${O5.join("|")})\\.)?anthropic\\.`,"i");function nc(e){return e.replace(L5,"")}const P5=["command","cmd","file_path","path","url","pattern","notebook_path"],PN=120,bm=e=>e.length>PN?`${e.slice(0,PN-1)}…`:e;function D5(e){if(typeof e=="string")return e.trim()?bm(e.trim()):null;if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;for(const n of P5){const r=t[n];if(typeof r=="string"&&r.trim())return bm(r.trim());if(Array.isArray(r)&&r.length>0&&r.every(s=>typeof s=="string")){const s=r.join(" ").trim();if(s)return bm(s)}}return null}const F5=/^\s*<task-notification>([\s\S]*?)<\/task-notification>/;function DN(e,t){var n;return((n=new RegExp(`<${t}>([\\s\\S]*?)</${t}>`).exec(e))==null?void 0:n[1].trim())||void 0}const FN={completed:"background task finished",failed:"background task failed",killed:"background task stopped"};function Sb(e){const t=F5.exec(e);if(!t)return null;const n=DN(t[1],"status");return{label:(n&&Object.hasOwn(FN,n)?FN[n]:void 0)??"background task update",detail:DN(t[1],"summary")}}function GA(e){return e.filter(t=>!Sb(t.text))}const q5=/[0-9a-f]{16,}/i,B5=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function KA(e){return q5.test(e)||B5.test(e)}function z5(e){if(!e)return;const t=e.replace(/\\/g,"/").split("/").filter(Boolean);for(let n=t.length-1;n>=0;n--)if(!KA(t[n]))return t[n];return t[t.length-1]}function YA(){return{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0}}function jb(e){const t=e.cache_creation,n=t&&typeof t=="object"?t:e,r=n.ephemeral_1h_input_tokens,s=n.ephemeral_5m_input_tokens;return typeof r!="number"&&typeof s!="number"?{}:{cacheCreate1hTokens:Number(r??0),cacheCreate5mTokens:Number(s??0)}}function U5(e){const t=jb(e),n={inputTokens:Number(e.input_tokens??0),outputTokens:Number(e.output_tokens??0),cacheReadTokens:Number(e.cache_read_input_tokens??e.cached_input_tokens??0),cacheCreateTokens:Number(e.cache_creation_input_tokens??e.cache_write_input_tokens??0),cacheCreate1hTokens:t.cacheCreate1hTokens,cacheCreate5mTokens:t.cacheCreate5mTokens};return typeof e.reasoning_output_tokens=="number"&&(n.reasoningOutputTokens=Number(e.reasoning_output_tokens)),n}function H5(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t={};for(const[n,r]of Object.entries(e))!n||!r||typeof r!="object"||(t[n]=U5(r));return Object.keys(t).length?t:void 0}function XA(e,t=0){if(!e||typeof e!="object"||t>6)return null;const n=e;if(typeof n.input_tokens=="number"||typeof n.output_tokens=="number"||typeof n.cache_read_input_tokens=="number"||typeof n.cache_creation_input_tokens=="number")return{inputTokens:Number(n.input_tokens??0),outputTokens:Number(n.output_tokens??0),cacheReadTokens:Number(n.cache_read_input_tokens??0),cacheCreateTokens:Number(n.cache_creation_input_tokens??0),...jb(n)};for(const r of Object.values(n)){const s=XA(r,t+1);if(s)return s}return null}const W5=/^(?:claude[-_]|gpt[-_]|o\d|codex[-_])/i,V5=new Set(["tool_input","tool_response"]);function ZA(e,t=0){if(!e||typeof e!="object"||t>6)return null;const n=e;if(typeof n.model=="string"&&W5.test(nc(n.model)))return n.model;for(const[r,s]of Object.entries(n)){if(V5.has(r))continue;const l=ZA(s,t+1);if(l)return l}return null}function E0(){return{agents:new Map,toolIndex:new Map,activeSubagentStack:new Map,subagentTombstones:new Map,pendingSubagentModels:new Map,lastSeq:0,seqEpoch:null,totalEvents:0,revision:0}}function ao(e){return z5(e)}function qN(){return{msgsUser:0,msgsAssistant:0,toolUses:0,toolResults:0,systemReminders:0,currentContextTokens:0,memoryFiles:[]}}function Vl(e,t){return`${e}::${t}`}function oo(e,t){return`${e}\0${t}`}function ef(e){const t=e.agent_type??e.subagent_type;return t&&!KA(t)?t:"subagent"}function mu(e){return e.agent_id?e.agent_id:e.parent_tool_use_id?e.parent_tool_use_id:null}function $l(e,t,n,r){const s=t;let l=e.agents.get(s);return l||(l={id:s,sessionId:t,label:"session",kind:"root",state:"active",startedAt:n,lastEventAt:n,tools:[],prompts:[],toolCount:0,childCount:0,synthetic:r,usage:YA()},e.agents.set(s,l),l)}function QA(e,t,n,r){const s=Vl(t,n),l=e.agents.get(s);if(!l)return null;!l.cwd&&r.cwd&&(l.cwd=r.cwd,l.cwdBasename=ao(r.cwd));const c=ef(r);return c&&(l.label==="subagent"||!l.label)&&(l.label=c),l}function G5(e,t,n){const r=t.session_id??"unknown",s=mu(t);if(s){const f=QA(e,r,s,t);if(f)return f}const l=e.activeSubagentStack.get(r),c=l&&l.length>0?l[l.length-1]:null;if(c){const f=e.agents.get(Vl(r,c));if(f)return!f.cwd&&t.cwd&&(f.cwd=t.cwd,f.cwdBasename=ao(t.cwd)),f}const u=$l(e,r,n,t.hook_event_name!=="SessionStart");return!u.cwd&&t.cwd&&(u.cwd=t.cwd,u.cwdBasename=ao(t.cwd)),u.label==="session"&&t.cwd&&(u.label=ao(t.cwd)??"session"),u}function K5(e,t,n,r,s){const l=Vl(t,n),c=$l(e,t,s,!0);let u=e.agents.get(l);if(u){!u.cwd&&r.cwd&&(u.cwd=r.cwd,u.cwdBasename=ao(r.cwd));const p=ef(r);return p&&(u.label==="subagent"||!u.label)&&(u.label=p),u}u={id:l,sessionId:t,label:ef(r),kind:"subagent",parentId:c.id,state:"active",startedAt:s,tools:[],prompts:[],cwd:r.cwd,cwdBasename:ao(r.cwd),toolCount:0,childCount:0,usage:YA()},e.agents.set(l,u);const f=e.pendingSubagentModels.get(l);return f&&(u.model=f,e.pendingSubagentModels.delete(l)),c.childCount+=1,u}function Y5(e,t,n){const r=e.activeSubagentStack.get(t)??[];r.includes(n)||(r.push(n),e.activeSubagentStack.set(t,r))}function BN(e,t,n){const r=e.activeSubagentStack.get(t);if(r){for(let s=r.length-1;s>=0;s--)if(r[s]===n){r.splice(s,1);break}r.length===0&&e.activeSubagentStack.delete(t)}}function ph(e,t=80){if(e==null)return"";if(typeof e=="string")return e.length>t?e.slice(0,t-1)+"…":e;try{const n=JSON.stringify(e);return n.length>t?n.slice(0,t-1)+"…":n}catch{return String(e)}}const zN=200;function X5(e,t){for(const n of e.values()){const r=n.tools.find(s=>s.id===t);if(r)return r}return null}const Z5=25;function Q5(e,t){const n=t.tools;if(n.length>zN){const r=n.splice(0,n.length-zN);for(const s of r){const l=oo(t.sessionId,s.id);e.toolIndex.get(l)===s&&e.toolIndex.delete(l)}}for(let r=n.length-Z5-1;r>=0;r--){const s=n[r];if(s.trimmed)break;s.input=void 0,s.response=void 0,s.trimmed=!0}}function J5(e,t,n){const r=e.toolIndex.get(oo(t.sessionId,n));if(r)return r;for(let s=t.tools.length-1;s>=0;s--)if(t.tools[s].id===n)return t.tools[s];return null}const UN=2e3;function e6(e,t,n){for(let r=e.prompts.length-1;r>=0;r--){const s=e.prompts[r];if(s.at<t-UN)return!1;if(s.text===n&&s.at<=t+UN)return!0}return!1}const mh=2e3;function t6(e){let t=e.startedAt;for(const n of e.prompts)n.at>t&&(t=n.at);return t}function JA(e,t){for(const n of t.tools){const r=oo(t.sessionId,n.id);e.toolIndex.get(r)===n&&e.toolIndex.delete(r)}}function Hu(e,t){return t&&(e.revision+=1),t}function n6(e,t,n,r,s){if(e.agents.size<=n)return!1;const l=m=>m.state==="done"&&m.endedAt!=null&&t-m.endedAt>r,c=[],u=new Map;for(const[m,y]of e.agents){if(y.parentId!=null){const v=u.get(y.parentId);v?v.push(m):u.set(y.parentId,[m])}l(y)&&c.push({id:m,endedAt:y.endedAt})}if(c.length===0)return!1;c.sort((m,y)=>m.endedAt-y.endedAt);let f=0;const p=new Set,h=m=>{const y=e.agents.get(m);y&&(JA(e,y),e.agents.delete(m),p.add(y.sessionId),f++)};for(const m of c){if(e.agents.size<=n)break;if(!e.agents.has(m.id))continue;const y=(u.get(m.id)??[]).map(v=>e.agents.get(v)).filter(v=>v!=null);if(!y.some(v=>!l(v))){for(const v of y)h(v.id);h(m.id)}}if(s&&p.size>0){const m=new Set;for(const y of e.agents.values())m.add(y.sessionId);for(const y of p)m.has(y)||s(y)}return Hu(e,f>0)}function r6(e,t,n,r,s){const l=new Map;for(const[h,m]of e.agents){let y=l.get(m.sessionId);y||(y={ids:[],endedAt:0,live:!1,closed:!1},l.set(m.sessionId,y)),y.ids.push(h),m.kind==="root"&&m.closedAt!=null&&(y.closed=!0),m.state==="done"&&m.endedAt!=null?y.endedAt=Math.max(y.endedAt,m.endedAt):y.live=!0}const c=[...l].filter(([,h])=>!h.live&&h.endedAt>0&&t-h.endedAt>r).sort(([,h],[,m])=>h.closed===m.closed?h.endedAt-m.endedAt:h.closed?-1:1);let f=[...l.values()].filter(h=>!h.live).length-n;if(f<=0)return!1;let p=!1;for(const[h,m]of c){if(f<=0)break;for(const y of m.ids){const v=e.agents.get(y);v&&JA(e,v),e.agents.delete(y)}for(const y of e.pendingSubagentModels.keys())y.startsWith(`${h}::`)&&e.pendingSubagentModels.delete(y);s==null||s(h),f--,p=!0}return Hu(e,p)}function s6(e,t){const n=t==null?void 0:t.payload,r=n==null?void 0:n.hook_event_name;if(r!=="PostToolUse"&&r!=="PostToolUseFailure")return!1;const s=n==null?void 0:n.tool_use_id;return typeof s!="string"||s.length===0?!1:e.toolIndex.has(oo((n==null?void 0:n.session_id)??"unknown",s))}function a6(e){let t=!1;for(const n of e.agents.values())for(const r of n.tools)r.endedAt!=null||r.outcomeGap||(r.outcomeGap=!0,t=!0);return Hu(e,t)}function o6(e,t,n){let r=!1;for(const s of e.agents.values()){if(s.provider==="codex")continue;const l=e.agents.get(s.sessionId),c=(l==null?void 0:l.lastEventAt)??(l==null?void 0:l.startedAt);for(const u of s.tools){const f=Math.max(u.startedAt,c??u.startedAt);u.endedAt==null&&t-f>n&&(u.endedAt=f,u.ok=!1,u.errorPreview=u.outcomeGap?"no result reached the deck — events were dropped while the deck was paused":"session ended before this call returned",e.toolIndex.delete(oo(s.sessionId,u.id)),r=!0)}}return Hu(e,r)}const HN=90*6e4;function i6(e,t,n){let r=!1;for(const s of e.agents.values()){if(s.kind!=="root")continue;const l=s.lastEventAt??s.startedAt;if(!(t-l<=n)){s.waiting&&(s.waiting=null,r=!0),s.closedAt==null&&(s.closedAt=l),s.state==="active"&&(s.state="done",s.endedAt=l,s.reaped=!0,r=!0);for(const c of e.agents.values())c.sessionId!==s.sessionId||c.kind==="root"||c.state!=="active"||(c.state="done",c.endedAt=l,r=!0);e.activeSubagentStack.delete(s.sessionId)}}return Hu(e,r)}function l6(e){return e==="permission_prompt"?"permission":e==="agent_needs_input"?"asked":e==="idle_prompt"?"idle":null}const c6=new Set(["Notification","ModelObserved","ContextObserved","UsageObserved","SessionNamed","SessionRecapped"]);function u6(e,t){let n=null;for(const r of e.toolIndex.values()){const s=r.agentId?e.agents.get(r.agentId):void 0;!s||s.sessionId!==t||(!n||r.startedAt>n.startedAt)&&(n=r)}return n}const d6=3e4;function h6(e,t){if(!(!e||!e.name)&&!(t-e.startedAt>d6)&&!(e.startedAt>t))return{name:e.name,preview:D5(e.input)??""}}function f6(e,t,n,r,s){if(n!=="permission")return{kind:n,message:r,since:s};const l=u6(e,t),c={kind:n,message:r,since:s};l!=null&&l.explicitSubagentId&&(c.subagentId=l.explicitSubagentId);const u=h6(l,s);return u&&(c.tool=u),c}function p6(e,t,n){if(e.kind==="idle")return!0;const r=mu(t);return r==null?!0:e.subagentId!=null&&Vl(n,r)===e.subagentId}function WN(e,t){const n=t.epoch??null;if(n!==null&&n!==e.seqEpoch)e.seqEpoch=n,e.lastSeq=0;else if(t.seq<=e.lastSeq)return e;const r=t.payload??{},s=t.receivedAt,l=r.hook_event_name??"Unknown";if(l==="__clear")return{...E0(),lastSeq:t.seq,seqEpoch:e.seqEpoch,revision:e.revision+1};e.totalEvents+=1,e.lastSeq=t.seq,e.revision+=1;const c=r.session_id??"unknown";if(!c6.has(l)){const h=e.agents.get(c);h!=null&&h.waiting&&p6(h.waiting,r,c)&&(h.waiting=null)}const u=e.agents.get(c);if(u&&s>(u.lastEventAt??0)&&(u.lastEventAt=s,u.reaped&&(u.reaped=!1,u.state="active",u.endedAt=void 0,u.closedAt=void 0)),typeof r.model_context_window=="number"&&r.model_context_window>0){const h=e.agents.get(c);h&&(h.contextWindow=r.model_context_window)}if(typeof r.approval_policy=="string"&&r.approval_policy){const h=e.agents.get(c);h&&(h.approvalPolicy=r.approval_policy)}if(typeof r.context_tokens=="number"&&r.context_tokens>=0){const h=e.agents.get(c);h&&(h.context={...h.context??qN(),currentContextTokens:r.context_tokens})}if(l==="ModelObserved"){const h=typeof r.model=="string"?r.model:null;if(h){const y=e.agents.get(c);y&&(y.model=h)}const m=r.subagentModels;if(m&&typeof m=="object")for(const[y,v]of Object.entries(m)){if(typeof v!="string")continue;const S=`${c}::${y}`,b=e.agents.get(S);if(b)b.model=v,e.pendingSubagentModels.delete(S);else if(e.pendingSubagentModels.delete(S),e.pendingSubagentModels.set(S,v),e.pendingSubagentModels.size>256){const _=e.pendingSubagentModels.keys().next().value;_!==void 0&&e.pendingSubagentModels.delete(_)}}return e}if(l==="ContextObserved"){const h=r.context??null;if(h){const m=e.agents.get(c);if(m){const y=m.context??qN(),v=(b,_)=>typeof h[b]=="number"?h[b]:_,S=Array.isArray(h.memoryFiles)?h.memoryFiles:Array.isArray(h.claudeMdFiles)?h.claudeMdFiles:null;m.context={msgsUser:v("msgsUser",y.msgsUser),msgsAssistant:v("msgsAssistant",y.msgsAssistant),toolUses:v("toolUses",y.toolUses),toolResults:v("toolResults",y.toolResults),systemReminders:v("systemReminders",y.systemReminders),currentContextTokens:v("currentContextTokens",y.currentContextTokens),memoryFiles:S??y.memoryFiles}}}return e}if(l==="SessionNamed"){const h=e.agents.get(c);if(h){const m=typeof r.sessionName=="string"?r.sessionName.trim():"",y=typeof r.sessionTitle=="string"?r.sessionTitle.trim():"";m&&(h.sessionName=m),y&&(h.sessionTitle=y);const v=h.sessionName??"";h.sessionTitle&&v&&h.sessionTitle.toLowerCase()===v.toLowerCase()&&(h.sessionTitle=void 0)}return e}if(l==="SessionRecapped"){const h=e.agents.get(c);if(h){const m=r.recap;m===null?h.recap=void 0:m&&typeof m.text=="string"&&m.text.trim()&&Number.isFinite(m.at)&&(h.recap={text:m.text.trim(),at:m.at})}return e}if(l==="OutputObserved"){const h=r.kind==="thinking"||r.kind==="text"||r.kind==="tool_use"?r.kind:null,m=typeof r.at=="number"&&Number.isFinite(r.at)?r.at:s;if(!h)return e;const y=e.agents.get(c);if(!y||y.lastOutputAt!=null&&m<=y.lastOutputAt)return e;if(y.lastOutputAt=m,h!=="tool_use"){const v=(y.outputs??[]).filter(S=>m-S<m6);v.push(m),y.outputs=v.length>VN?v.slice(-VN):v}return e.revision+=1,e}if(l==="UsageObserved"){const h=r.usage??null;if(h){const m=e.agents.get(c);if(m){m.usage.inputTokens=Number(h.input_tokens??0),m.usage.outputTokens=Number(h.output_tokens??0),m.usage.cacheReadTokens=Number(h.cache_read_input_tokens??h.cached_input_tokens??0),m.usage.cacheCreateTokens=Number(h.cache_creation_input_tokens??h.cache_write_input_tokens??0);const y=jb(h);m.usage.cacheCreate1hTokens=y.cacheCreate1hTokens,m.usage.cacheCreate5mTokens=y.cacheCreate5mTokens,typeof h.reasoning_output_tokens=="number"&&(m.usage.reasoningOutputTokens=Number(h.reasoning_output_tokens)),m.usageByModel=H5(r.usageByModel)}}return e}const f=G5(e,r,s);f.provider||(f.provider=r.provider==="codex"?"codex":"claude");const p=ZA(r);switch(p&&(f.model=p),l){case"SessionStart":{const h=$l(e,c,s,!1);h.synthetic=!1,h.state="active",h.closedAt=void 0,h.endedAt=void 0,h.startedAt=Math.min(h.startedAt??s,s),!h.cwd&&r.cwd&&(h.cwd=r.cwd,h.cwdBasename=ao(r.cwd)),h.label==="session"&&r.cwd&&(h.label=ao(r.cwd)??"session");break}case"UserPromptSubmit":{for(const y of e.agents.values())y.sessionId===c&&y.kind==="subagent"&&y.state==="done"&&y.exitAt==null&&y.endedAt!=null&&y.endedAt<s&&(y.exitAt=s);const h=$l(e,c,s,!1);h.state="active",h.endedAt=void 0,h.closedAt=void 0,h.exitAt=void 0;const m=(typeof r.prompt=="string"?r.prompt:typeof r.message=="string"?r.message:"")??"";m&&!e6(h,s,m)&&(h.prompts.push({at:s,text:m}),!h.firstPrompt&&!Sb(m)&&(h.firstPrompt=ph(m,120)));break}case"PreToolUse":{const h=r.tool_use_id?J5(e,f,r.tool_use_id):null;if(h){r.tool_name&&h.name==="?"&&(h.name=r.tool_name),h.endedAt==null&&!h.trimmed&&r.tool_input!==void 0&&(h.input=r.tool_input,h.inputPreview=ph(r.tool_input));break}const m=r.tool_use_id??`${f.id}:${f.toolCount}`,y=mu(r),v={id:m,name:r.tool_name??"?",input:r.tool_input,inputPreview:ph(r.tool_input),agentId:f.id,explicitSubagentId:y?Vl(c,y):void 0,startedAt:s};f.tools.push(v),f.toolCount+=1,f.state="active",e.toolIndex.set(oo(f.sessionId,m),v),Q5(e,f);break}case"PostToolUse":case"PostToolUseFailure":{const h=r.tool_use_id;if(!h)break;const m=oo(c,h);let y=e.toolIndex.get(m),v=!1;if(!y)for(const b of e.agents.values()){if(b.sessionId!==c)continue;const _=b.tools.find(k=>k.id===h);if(_){y=_,v=!0;break}}if(!y||y.outcomeApplied)break;y.outcomeApplied=!0,y.outcomeGap=void 0,y.endedAt=s,y.ok=l==="PostToolUse",y.trimmed||(y.response=r.tool_response),l==="PostToolUseFailure"?y.errorPreview=ph(r.tool_response):v&&(y.errorPreview=void 0);const S=XA(r.tool_response);S&&(y.usage=S),e.toolIndex.delete(m);break}case"SubagentStart":{const h=mu(r);if(!h)break;const m=K5(e,c,h,r,s),y=ef(r);y&&(m.label=y);const v=e.subagentTombstones.get(m.id);v!=null&&e.subagentTombstones.delete(m.id);const S=m.endedAt!=null&&s-m.endedAt<=mh,b=v!=null&&s-v<=mh;if(S||b){const _=b?v:m.endedAt;m.state="done",m.endedAt=_,m.startedAt=Math.min(m.startedAt,_),BN(e,c,h);break}m.state="active",m.startedAt=m.startedAt||s,m.exitAt=void 0,m.endedAt=void 0,Y5(e,c,h);break}case"SubagentStop":{const h=mu(r);if(!h)break;const m=QA(e,c,h,r);if(!m){for(const[y,v]of e.subagentTombstones)s-v>mh&&e.subagentTombstones.delete(y);e.subagentTombstones.set(Vl(c,h),s);break}m.state="done",m.endedAt=Math.min(m.endedAt??s,s),BN(e,c,h);break}case"Stop":case"SessionEnd":{const h=$l(e,c,s,!1),m=t6(h);if(s<m)break;const y=h.lastTurnEndAt;if(y!=null&&m>y&&s<=y+mh)break;h.state="done",h.endedAt=s,h.lastTurnEndAt=s;for(const v of h.provider==="codex"?[]:e.agents.values())if(v.sessionId===c)for(const S of v.tools)S.endedAt==null&&S.explicitSubagentId==null&&(S.endedAt=s,S.ok=!1,S.errorPreview=S.outcomeGap?"no result reached the deck — events were dropped while the deck was paused":"the turn ended before this call returned",e.toolIndex.delete(oo(v.sessionId,S.id)));l==="SessionEnd"&&(h.closedAt=s),e.activeSubagentStack.delete(c);break}case"Notification":{const h=l6(r.notification_type);if(!h)break;const m=$l(e,c,s,!1),y=typeof r.message=="string"?r.message:"",v=m.waiting;m.waiting=v&&v.kind===h&&v.message===y?{...v,since:Math.min(v.since,s)}:f6(e,c,h,y,s);break}}return e}const m6=6e4,VN=64;function tf(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t)%360}const g6={input:2,output:10,cacheRead:.2,cacheWrite:2.5,cacheWrite1h:4},y6=[{match:/^claude[-_](fable|mythos)[-_]5[-_.]1\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:10,output:50,cacheRead:.25,cacheWrite:12.5,cacheWrite1h:20}},{match:/^claude[-_](fable|mythos)[-_]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:10,output:50,cacheRead:1,cacheWrite:12.5,cacheWrite1h:20}},{match:/^claude[-_]opus[-_]5[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:4,output:20,cacheRead:.2,cacheWrite:5,cacheWrite1h:8}},{match:/^claude[-_]opus[-_]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:5,output:25,cacheRead:.5,cacheWrite:6.25,cacheWrite1h:10}},{match:/^claude[-_]sonnet[-_]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:g6},{match:/^claude[-_]opus[-_]4[-_.](?:5|6|7|8)\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:5,output:25,cacheRead:.5,cacheWrite:6.25,cacheWrite1h:10}},{match:/^claude[-_]opus[-_]4(?:[-_.]1)?\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75,cacheWrite1h:30}},{match:/^claude[-_]sonnet[-_]4[-_.](?:5|6)\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}},{match:/^claude[-_]sonnet[-_]4\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}},{match:/^claude[-_]haiku[-_]4[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:1,output:5,cacheRead:.1,cacheWrite:1.25,cacheWrite1h:2}},{match:/^claude[-_]haiku[-_]3[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:.8,output:4,cacheRead:.08,cacheWrite:1,cacheWrite1h:1.6}},{match:/^gpt[-_]6[-_]astra\b(?![-_][A-Za-z])/i,rates:{input:10,output:50,cacheRead:1,cacheWrite:12.5}},{match:/^gpt[-_]5[-_.]6[-_]cyber/i,rates:{input:12.5,output:75,cacheRead:1.25,cacheWrite:15.625}},{match:/^gpt[-_]5[-_.]6[-_]luna/i,rates:{input:.2,output:1.2,cacheRead:.02,cacheWrite:.25}},{match:/^gpt[-_]5[-_.]6[-_]terra/i,rates:{input:2,output:12,cacheRead:.2,cacheWrite:2.5}},{match:/^gpt[-_]5[-_.]6(?:[-_]sol)?\b(?![-_][A-Za-z])/i,rates:{input:4,output:20,cacheRead:.4,cacheWrite:5}},{match:/^gpt[-_]5[-_.]5[-_]pro/i,rates:{input:30,output:180,cacheRead:30,cacheWrite:0}},{match:/^gpt[-_]5[-_.]5\b(?![-_][A-Za-z])/i,rates:{input:5,output:30,cacheRead:.5,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]pro/i,rates:{input:30,output:180,cacheRead:3,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]mini/i,rates:{input:.75,output:4.5,cacheRead:.075,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]nano/i,rates:{input:.2,output:1.25,cacheRead:.02,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4\b/i,rates:{input:2.5,output:15,cacheRead:.25,cacheWrite:0}},{match:/^gpt[-_]5[-_.]3[-_]codex/i,rates:{input:1.75,output:14,cacheRead:.175,cacheWrite:0}},{match:/^gpt[-_]5[-_.]2[-_]pro/i,rates:{input:21,output:168,cacheRead:21,cacheWrite:0}},{match:/^gpt[-_]5[-_.]2\b/i,rates:{input:1.75,output:14,cacheRead:.175,cacheWrite:0}},{match:/^gpt[-_]5[-_.]1[-_]codex[-_]mini/i,rates:{input:.25,output:2,cacheRead:.025,cacheWrite:0}},{match:/^gpt[-_]5[-_.]1(?!\d)/i,rates:{input:1.25,output:10,cacheRead:.125,cacheWrite:0}},{match:/^gpt[-_]5[-_]pro\b/i,rates:{input:15,output:120,cacheRead:15,cacheWrite:0}},{match:/^gpt[-_]5[-_]mini/i,rates:{input:.25,output:2,cacheRead:.025,cacheWrite:0}},{match:/^gpt[-_]5[-_]nano/i,rates:{input:.05,output:.4,cacheRead:.005,cacheWrite:0}},{match:/^gpt[-_]5(?![-_.]\d)/i,rates:{input:1.25,output:10,cacheRead:.125,cacheWrite:0}},{match:/^codex[-_]mini/i,rates:{input:1.5,output:6,cacheRead:.375,cacheWrite:0}},{match:/^o1[-_]pro/i,rates:{input:150,output:600,cacheRead:150,cacheWrite:0}},{match:/^o1[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0}},{match:/^o1\b/i,rates:{input:15,output:60,cacheRead:7.5,cacheWrite:0}},{match:/^o3[-_]deep[-_]research/i,rates:{input:10,output:40,cacheRead:2.5,cacheWrite:0}},{match:/^o3[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0}},{match:/^o3[-_]pro/i,rates:{input:20,output:80,cacheRead:20,cacheWrite:0}},{match:/^o4[-_]mini[-_]deep[-_]research/i,rates:{input:2,output:8,cacheRead:.5,cacheWrite:0}},{match:/^o4[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.275,cacheWrite:0}},{match:/^o3\b/i,rates:{input:2,output:8,cacheRead:.5,cacheWrite:0}}];function w6(e){return e?/^(?:gpt[-_]|codex[-_]|o\d)/i.test(e):!1}function Ni(e,t=Date.now()){if(!e)return null;const n=nc(e);for(const r of y6)if(r.match.test(n))return typeof r.rates=="function"?r.rates(t):r.rates;return null}function eM(e,t){const n=Math.max(0,e.cacheCreate1hTokens??0),r=Math.max(0,e.cacheCreate5mTokens??0),s=Math.max(0,e.cacheCreateTokens-n-r),l=r+s,c=t.cacheWrite1h??t.cacheWrite;return{tokens5m:l,tokens1h:n,usd5m:l*t.cacheWrite/1e6,usd1h:n*c/1e6}}function tM(e,t,n=Date.now()){if(!w6(t))return e.inputTokens;const r=Ni(t,n),s=((r==null?void 0:r.cacheWrite)??0)>0?Math.max(0,e.cacheCreateTokens):0;return Math.max(0,e.inputTokens-e.cacheReadTokens-s)}function Cu(e,t,n=Date.now()){const r=Ni(t,n);if(!r)return{input:0,output:0,cacheRead:0,cacheWrite:0,total:0};const s=tM(e,t,n)*r.input/1e6,l=e.outputTokens*r.output/1e6,c=e.cacheReadTokens*r.cacheRead/1e6,u=eM(e,r),f=u.usd5m+u.usd1h;return{input:s,output:l,cacheRead:c,cacheWrite:f,total:s+l+c+f}}const GN=2e5,v6=1e6,x6=[/\[1m\]/i,/^claude[-_]opus[-_]5\b/i,/^claude[-_]sonnet[-_]5\b/i,/^claude[-_]opus[-_]4[-_.](?:6|7|8)\b/i,/^claude[-_]sonnet[-_]4[-_.]6\b/i,/^claude[-_](fable|mythos)[-_]5\b/i],b6=[{match:/^gpt[-_]6[-_]astra/i,window:105e4},{match:/^gpt[-_]5[-_.]6[-_]cyber/i,window:4e5},{match:/^gpt[-_]5[-_.]6/i,window:105e4},{match:/^gpt[-_]5[-_.]5/i,window:105e4},{match:/^gpt[-_]5[-_.]4[-_](?:mini|nano)/i,window:4e5},{match:/^gpt[-_]5[-_.]4/i,window:105e4},{match:/^gpt[-_]5[-_.]3[-_]codex[-_]spark/i,window:128e3},{match:/^gpt[-_]5[-_.]3[-_]codex/i,window:4e5},{match:/^gpt[-_]5[-_.]2/i,window:4e5},{match:/^gpt[-_]5/i,window:4e5},{match:/^codex[-_]mini/i,window:2e5},{match:/^o\d/i,window:2e5}];function k6(e){if(!e)return GN;const t=nc(e);for(const n of x6)if(n.test(t))return v6;for(const n of b6)if(n.match.test(t))return n.window;return GN}function nM(e,t){return typeof e=="number"&&e>0?e:k6(t)}const la="not priced";function bt(e){if(e<=0)return"—";if(e<.005)return"<1¢";if(e<1){const t=(e*100).toFixed(e<.1?1:0);if(Number(t)<100)return`${t}¢`}if(e<100){const t=e.toFixed(2);if(Number(t)<100)return`$${t}`}if(e<1e4){const t=e.toFixed(0);if(Number(t)<1e4)return`$${t}`}return`$${(e/1e3).toFixed(1)}k`}function _b(e,t){if(e<=0||t<10)return null;const n=e/t,r=n*60;return r>=.01?`${bt(r)}/min`:`${bt(n*3600)}/hr`}function N6(e,t){const n={inputTokens:e.inputTokens+t.inputTokens,outputTokens:e.outputTokens+t.outputTokens,cacheReadTokens:e.cacheReadTokens+t.cacheReadTokens,cacheCreateTokens:e.cacheCreateTokens+t.cacheCreateTokens};return(e.cacheCreate1hTokens!==void 0||e.cacheCreate5mTokens!==void 0||t.cacheCreate1hTokens!==void 0||t.cacheCreate5mTokens!==void 0)&&(n.cacheCreate1hTokens=(e.cacheCreate1hTokens??0)+(t.cacheCreate1hTokens??0),n.cacheCreate5mTokens=(e.cacheCreate5mTokens??0)+(t.cacheCreate5mTokens??0)),(e.reasoningOutputTokens!==void 0||t.reasoningOutputTokens!==void 0)&&(n.reasoningOutputTokens=(e.reasoningOutputTokens??0)+(t.reasoningOutputTokens??0)),n}function S6(e,t){let n=0,r=0,s=0,l=0,c=0,u=0;for(const m of t)n+=m.inputTokens,r+=m.outputTokens,s+=m.cacheReadTokens,l+=m.cacheCreateTokens,c+=m.cacheCreate1hTokens??0,u+=m.cacheCreate5mTokens??0;const f=(m,y)=>Math.max(0,m-y),p={inputTokens:f(e.inputTokens,n),outputTokens:f(e.outputTokens,r),cacheReadTokens:f(e.cacheReadTokens,s),cacheCreateTokens:f(e.cacheCreateTokens,l)};return(e.cacheCreate1hTokens!==void 0||e.cacheCreate5mTokens!==void 0)&&(p.cacheCreate1hTokens=f(e.cacheCreate1hTokens??0,c),p.cacheCreate5mTokens=f(e.cacheCreate5mTokens??0,u)),p.inputTokens+p.outputTokens+p.cacheReadTokens+p.cacheCreateTokens>0?p:null}function Wu(e){const t=e.usageByModel,n=t?Object.keys(t):[];if(!t||n.length===0)return[{model:e.model,usage:e.usage}];const r=n.map(l=>({model:l,usage:t[l]})),s=S6(e.usage,r.map(l=>l.usage));if(s){const l=r.findIndex(c=>c.model===e.model);l>=0?r[l]={model:r[l].model,usage:N6(r[l].usage,s)}:r.push({model:e.model,usage:s})}return r}function or(e,t=Date.now()){const n={input:0,output:0,cacheRead:0,cacheWrite:0,total:0};for(const r of Wu(e)){const s=Cu(r.usage,r.model,t);n.input+=s.input,n.output+=s.output,n.cacheRead+=s.cacheRead,n.cacheWrite+=s.cacheWrite,n.total+=s.total}return n}function Tu(e,t=Date.now()){let n=0;for(const r of Wu(e))Ni(r.model,t)==null&&(n+=r.usage.inputTokens+r.usage.outputTokens);return n}function rM(e){const t=[];for(const n of Wu(e)){if(!n.model||t.includes(n.model))continue;const r=n.usage;r.inputTokens+r.outputTokens+r.cacheReadTokens+r.cacheCreateTokens<=0||t.push(n.model)}return t}function sM(e){return rM(e).filter(t=>t!==e.model)}const j6=new Set(["untrusted","on-request","on-failure"]);function _6(e){return typeof e!="string"||!e?null:j6.has(e)?!0:e==="never"?!1:null}function E6(e){if(e.provider!=="codex"||e.kind!=="root"||e.waiting||e.state!=="active")return null;const t=_6(e.approvalPolicy);return t===!1?null:{label:"approvals not visible",detail:`${t===!0?`This session's approval policy is "${e.approvalPolicy}", so Codex can stop and ask you to approve a command.`:"This session's approval policy has not been read yet, so it may be able to stop and ask you to approve a command."}
57
+ M${$.x},${$.y}h${$.width}v${$.height}h${-$.width}z`,fill:f,fillRule:"evenodd",stroke:p,strokeWidth:h,pointerEvents:"none"})))}HA.displayName="MiniMap";var b5=w.memo(HA);function k5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 32"},ve.createElement("path",{d:"M32 18.133H18.133V32h-4.266V18.133H0v-4.266h13.867V0h4.266v13.867H32z"}))}function N5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 5"},ve.createElement("path",{d:"M0 0h32v4.2H0z"}))}function S5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 32 30"},ve.createElement("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 j5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},ve.createElement("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 _5(){return ve.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 25 32"},ve.createElement("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"}))}const Or=({children:e,className:t,...n})=>ve.createElement("button",{type:"button",className:jn(["react-flow__controls-button",t]),...n},e);Or.displayName="ControlButton";const E5=e=>({isInteractive:e.nodesDraggable||e.nodesConnectable||e.elementsSelectable,minZoomReached:e.transform[2]<=e.minZoom,maxZoomReached:e.transform[2]>=e.maxZoom}),WA=({style:e,showZoom:t=!0,showFitView:n=!0,showInteractive:r=!0,fitViewOptions:s,onZoomIn:l,onZoomOut:c,onFitView:u,onInteractiveChange:f,className:p,children:h,position:m="bottom-left"})=>{const y=tn(),[v,S]=w.useState(!1),{isInteractive:b,minZoomReached:_,maxZoomReached:k}=Et(E5,pn),{zoomIn:j,zoomOut:E,fitView:C}=Nf();if(w.useEffect(()=>{S(!0)},[]),!v)return null;const R=()=>{j(),l==null||l()},I=()=>{E(),c==null||c()},$=()=>{C(s),u==null||u()},q=()=>{y.setState({nodesDraggable:!b,nodesConnectable:!b,elementsSelectable:!b}),f==null||f(!b)};return ve.createElement(hb,{className:jn(["react-flow__controls",p]),position:m,style:e,"data-testid":"rf__controls"},t&&ve.createElement(ve.Fragment,null,ve.createElement(Or,{onClick:R,className:"react-flow__controls-zoomin",title:"zoom in","aria-label":"zoom in",disabled:k},ve.createElement(k5,null)),ve.createElement(Or,{onClick:I,className:"react-flow__controls-zoomout",title:"zoom out","aria-label":"zoom out",disabled:_},ve.createElement(N5,null))),n&&ve.createElement(Or,{className:"react-flow__controls-fitview",onClick:$,title:"fit view","aria-label":"fit view"},ve.createElement(S5,null)),r&&ve.createElement(Or,{className:"react-flow__controls-interactive",onClick:q,title:"toggle interactivity","aria-label":"toggle interactivity"},b?ve.createElement(_5,null):ve.createElement(j5,null)),h)};WA.displayName="Controls";var C5=w.memo(WA),ys;(function(e){e.Lines="lines",e.Dots="dots",e.Cross="cross"})(ys||(ys={}));function T5({color:e,dimensions:t,lineWidth:n}){return ve.createElement("path",{stroke:e,strokeWidth:n,d:`M${t[0]/2} 0 V${t[1]} M0 ${t[1]/2} H${t[0]}`})}function R5({color:e,radius:t}){return ve.createElement("circle",{cx:t,cy:t,r:t,fill:e})}const A5={[ys.Dots]:"#91919a",[ys.Lines]:"#eee",[ys.Cross]:"#e2e2e2"},M5={[ys.Dots]:1,[ys.Lines]:1,[ys.Cross]:6},I5=e=>({transform:e.transform,patternId:`pattern-${e.rfId}`});function VA({id:e,variant:t=ys.Dots,gap:n=20,size:r,lineWidth:s=1,offset:l=2,color:c,style:u,className:f}){const p=w.useRef(null),{transform:h,patternId:m}=Et(I5,pn),y=c||A5[t],v=r||M5[t],S=t===ys.Dots,b=t===ys.Cross,_=Array.isArray(n)?n:[n,n],k=[_[0]*h[2]||1,_[1]*h[2]||1],j=v*h[2],E=b?[j,j]:k,C=S?[j/l,j/l]:[E[0]/l,E[1]/l];return ve.createElement("svg",{className:jn(["react-flow__background",f]),style:{...u,position:"absolute",width:"100%",height:"100%",top:0,left:0},ref:p,"data-testid":"rf__background"},ve.createElement("pattern",{id:m+e,x:h[0]%k[0],y:h[1]%k[1],width:k[0],height:k[1],patternUnits:"userSpaceOnUse",patternTransform:`translate(-${C[0]},-${C[1]})`},S?ve.createElement(R5,{color:y,radius:j/l}):ve.createElement(T5,{dimensions:E,color:y,lineWidth:s})),ve.createElement("rect",{x:"0",y:"0",width:"100%",height:"100%",fill:`url(#${m+e})`}))}VA.displayName="Background";var $5=w.memo(VA);const O5=["us-gov","global","apac","us","eu","jp","au"],L5=new RegExp(`^(?:(?:${O5.join("|")})\\.)?anthropic\\.`,"i");function nc(e){return e.replace(L5,"")}const P5=["command","cmd","file_path","path","url","pattern","notebook_path"],PN=120,bm=e=>e.length>PN?`${e.slice(0,PN-1)}…`:e;function D5(e){if(typeof e=="string")return e.trim()?bm(e.trim()):null;if(!e||typeof e!="object"||Array.isArray(e))return null;const t=e;for(const n of P5){const r=t[n];if(typeof r=="string"&&r.trim())return bm(r.trim());if(Array.isArray(r)&&r.length>0&&r.every(s=>typeof s=="string")){const s=r.join(" ").trim();if(s)return bm(s)}}return null}const F5=/^\s*<task-notification>([\s\S]*?)<\/task-notification>/;function DN(e,t){var n;return((n=new RegExp(`<${t}>([\\s\\S]*?)</${t}>`).exec(e))==null?void 0:n[1].trim())||void 0}const FN={completed:"background task finished",failed:"background task failed",killed:"background task stopped"};function Sb(e){const t=F5.exec(e);if(!t)return null;const n=DN(t[1],"status");return{label:(n&&Object.hasOwn(FN,n)?FN[n]:void 0)??"background task update",detail:DN(t[1],"summary")}}function GA(e){return e.filter(t=>!Sb(t.text))}const q5=/[0-9a-f]{16,}/i,B5=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function KA(e){return q5.test(e)||B5.test(e)}function z5(e){if(!e)return;const t=e.replace(/\\/g,"/").split("/").filter(Boolean);for(let n=t.length-1;n>=0;n--)if(!KA(t[n]))return t[n];return t[t.length-1]}function YA(){return{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0}}function jb(e){const t=e.cache_creation,n=t&&typeof t=="object"?t:e,r=n.ephemeral_1h_input_tokens,s=n.ephemeral_5m_input_tokens;return typeof r!="number"&&typeof s!="number"?{}:{cacheCreate1hTokens:Number(r??0),cacheCreate5mTokens:Number(s??0)}}function U5(e){const t=jb(e),n={inputTokens:Number(e.input_tokens??0),outputTokens:Number(e.output_tokens??0),cacheReadTokens:Number(e.cache_read_input_tokens??e.cached_input_tokens??0),cacheCreateTokens:Number(e.cache_creation_input_tokens??e.cache_write_input_tokens??0),cacheCreate1hTokens:t.cacheCreate1hTokens,cacheCreate5mTokens:t.cacheCreate5mTokens};return typeof e.reasoning_output_tokens=="number"&&(n.reasoningOutputTokens=Number(e.reasoning_output_tokens)),n}function H5(e){if(!e||typeof e!="object"||Array.isArray(e))return;const t={};for(const[n,r]of Object.entries(e))!n||!r||typeof r!="object"||(t[n]=U5(r));return Object.keys(t).length?t:void 0}function XA(e,t=0){if(!e||typeof e!="object"||t>6)return null;const n=e;if(typeof n.input_tokens=="number"||typeof n.output_tokens=="number"||typeof n.cache_read_input_tokens=="number"||typeof n.cache_creation_input_tokens=="number")return{inputTokens:Number(n.input_tokens??0),outputTokens:Number(n.output_tokens??0),cacheReadTokens:Number(n.cache_read_input_tokens??0),cacheCreateTokens:Number(n.cache_creation_input_tokens??0),...jb(n)};for(const r of Object.values(n)){const s=XA(r,t+1);if(s)return s}return null}const W5=/^(?:claude[-_]|gpt[-_]|o\d|codex[-_])/i,V5=new Set(["tool_input","tool_response"]);function ZA(e,t=0){if(!e||typeof e!="object"||t>6)return null;const n=e;if(typeof n.model=="string"&&W5.test(nc(n.model)))return n.model;for(const[r,s]of Object.entries(n)){if(V5.has(r))continue;const l=ZA(s,t+1);if(l)return l}return null}function E0(){return{agents:new Map,toolIndex:new Map,activeSubagentStack:new Map,subagentTombstones:new Map,pendingSubagentModels:new Map,lastSeq:0,seqEpoch:null,totalEvents:0,revision:0}}function ao(e){return z5(e)}function qN(){return{msgsUser:0,msgsAssistant:0,toolUses:0,toolResults:0,systemReminders:0,currentContextTokens:0,memoryFiles:[]}}function Vl(e,t){return`${e}::${t}`}function oo(e,t){return`${e}\0${t}`}function ef(e){const t=e.agent_type??e.subagent_type;return t&&!KA(t)?t:"subagent"}function mu(e){return e.agent_id?e.agent_id:e.parent_tool_use_id?e.parent_tool_use_id:null}function $l(e,t,n,r){const s=t;let l=e.agents.get(s);return l||(l={id:s,sessionId:t,label:"session",kind:"root",state:"active",startedAt:n,lastEventAt:n,tools:[],prompts:[],toolCount:0,childCount:0,synthetic:r,usage:YA()},e.agents.set(s,l),l)}function QA(e,t,n,r){const s=Vl(t,n),l=e.agents.get(s);if(!l)return null;!l.cwd&&r.cwd&&(l.cwd=r.cwd,l.cwdBasename=ao(r.cwd));const c=ef(r);return c&&(l.label==="subagent"||!l.label)&&(l.label=c),l}function G5(e,t,n){const r=t.session_id??"unknown",s=mu(t);if(s){const f=QA(e,r,s,t);if(f)return f}const l=e.activeSubagentStack.get(r),c=l&&l.length>0?l[l.length-1]:null;if(c){const f=e.agents.get(Vl(r,c));if(f)return!f.cwd&&t.cwd&&(f.cwd=t.cwd,f.cwdBasename=ao(t.cwd)),f}const u=$l(e,r,n,t.hook_event_name!=="SessionStart");return!u.cwd&&t.cwd&&(u.cwd=t.cwd,u.cwdBasename=ao(t.cwd)),u.label==="session"&&t.cwd&&(u.label=ao(t.cwd)??"session"),u}function K5(e,t,n,r,s){const l=Vl(t,n),c=$l(e,t,s,!0);let u=e.agents.get(l);if(u){!u.cwd&&r.cwd&&(u.cwd=r.cwd,u.cwdBasename=ao(r.cwd));const p=ef(r);return p&&(u.label==="subagent"||!u.label)&&(u.label=p),u}u={id:l,sessionId:t,label:ef(r),kind:"subagent",parentId:c.id,state:"active",startedAt:s,tools:[],prompts:[],cwd:r.cwd,cwdBasename:ao(r.cwd),toolCount:0,childCount:0,usage:YA()},e.agents.set(l,u);const f=e.pendingSubagentModels.get(l);return f&&(u.model=f,e.pendingSubagentModels.delete(l)),c.childCount+=1,u}function Y5(e,t,n){const r=e.activeSubagentStack.get(t)??[];r.includes(n)||(r.push(n),e.activeSubagentStack.set(t,r))}function BN(e,t,n){const r=e.activeSubagentStack.get(t);if(r){for(let s=r.length-1;s>=0;s--)if(r[s]===n){r.splice(s,1);break}r.length===0&&e.activeSubagentStack.delete(t)}}function ph(e,t=80){if(e==null)return"";if(typeof e=="string")return e.length>t?e.slice(0,t-1)+"…":e;try{const n=JSON.stringify(e);return n.length>t?n.slice(0,t-1)+"…":n}catch{return String(e)}}const zN=200;function X5(e,t){for(const n of e.values()){const r=n.tools.find(s=>s.id===t);if(r)return r}return null}const Z5=25;function Q5(e,t){const n=t.tools;if(n.length>zN){const r=n.splice(0,n.length-zN);for(const s of r){const l=oo(t.sessionId,s.id);e.toolIndex.get(l)===s&&e.toolIndex.delete(l)}}for(let r=n.length-Z5-1;r>=0;r--){const s=n[r];if(s.trimmed)break;s.input=void 0,s.response=void 0,s.trimmed=!0}}function J5(e,t,n){const r=e.toolIndex.get(oo(t.sessionId,n));if(r)return r;for(let s=t.tools.length-1;s>=0;s--)if(t.tools[s].id===n)return t.tools[s];return null}const UN=2e3;function e6(e,t,n){for(let r=e.prompts.length-1;r>=0;r--){const s=e.prompts[r];if(s.at<t-UN)return!1;if(s.text===n&&s.at<=t+UN)return!0}return!1}const mh=2e3;function t6(e){let t=e.startedAt;for(const n of e.prompts)n.at>t&&(t=n.at);return t}function JA(e,t){for(const n of t.tools){const r=oo(t.sessionId,n.id);e.toolIndex.get(r)===n&&e.toolIndex.delete(r)}}function Hu(e,t){return t&&(e.revision+=1),t}function n6(e,t,n,r,s){if(e.agents.size<=n)return!1;const l=m=>m.state==="done"&&m.endedAt!=null&&t-m.endedAt>r,c=[],u=new Map;for(const[m,y]of e.agents){if(y.parentId!=null){const v=u.get(y.parentId);v?v.push(m):u.set(y.parentId,[m])}l(y)&&c.push({id:m,endedAt:y.endedAt})}if(c.length===0)return!1;c.sort((m,y)=>m.endedAt-y.endedAt);let f=0;const p=new Set,h=m=>{const y=e.agents.get(m);y&&(JA(e,y),e.agents.delete(m),p.add(y.sessionId),f++)};for(const m of c){if(e.agents.size<=n)break;if(!e.agents.has(m.id))continue;const y=(u.get(m.id)??[]).map(v=>e.agents.get(v)).filter(v=>v!=null);if(!y.some(v=>!l(v))){for(const v of y)h(v.id);h(m.id)}}if(s&&p.size>0){const m=new Set;for(const y of e.agents.values())m.add(y.sessionId);for(const y of p)m.has(y)||s(y)}return Hu(e,f>0)}function r6(e,t,n,r,s){const l=new Map;for(const[h,m]of e.agents){let y=l.get(m.sessionId);y||(y={ids:[],endedAt:0,live:!1,closed:!1},l.set(m.sessionId,y)),y.ids.push(h),m.kind==="root"&&m.closedAt!=null&&(y.closed=!0),m.state==="done"&&m.endedAt!=null?y.endedAt=Math.max(y.endedAt,m.endedAt):y.live=!0}const c=[...l].filter(([,h])=>!h.live&&h.endedAt>0&&t-h.endedAt>r).sort(([,h],[,m])=>h.closed===m.closed?h.endedAt-m.endedAt:h.closed?-1:1);let f=[...l.values()].filter(h=>!h.live).length-n;if(f<=0)return!1;let p=!1;for(const[h,m]of c){if(f<=0)break;for(const y of m.ids){const v=e.agents.get(y);v&&JA(e,v),e.agents.delete(y)}for(const y of e.pendingSubagentModels.keys())y.startsWith(`${h}::`)&&e.pendingSubagentModels.delete(y);s==null||s(h),f--,p=!0}return Hu(e,p)}function s6(e,t){const n=t==null?void 0:t.payload,r=n==null?void 0:n.hook_event_name;if(r!=="PostToolUse"&&r!=="PostToolUseFailure")return!1;const s=n==null?void 0:n.tool_use_id;return typeof s!="string"||s.length===0?!1:e.toolIndex.has(oo((n==null?void 0:n.session_id)??"unknown",s))}function a6(e){let t=!1;for(const n of e.agents.values())for(const r of n.tools)r.endedAt!=null||r.outcomeGap||(r.outcomeGap=!0,t=!0);return Hu(e,t)}function o6(e,t,n){let r=!1;for(const s of e.agents.values()){if(s.provider==="codex")continue;const l=e.agents.get(s.sessionId),c=(l==null?void 0:l.lastEventAt)??(l==null?void 0:l.startedAt);for(const u of s.tools){const f=Math.max(u.startedAt,c??u.startedAt);u.endedAt==null&&t-f>n&&(u.endedAt=f,u.ok=!1,u.errorPreview=u.outcomeGap?"no result reached the deck — events were dropped while the deck was paused":"session ended before this call returned",e.toolIndex.delete(oo(s.sessionId,u.id)),r=!0)}}return Hu(e,r)}const HN=90*6e4;function i6(e,t,n){let r=!1;for(const s of e.agents.values()){if(s.kind!=="root")continue;const l=s.lastEventAt??s.startedAt;if(!(t-l<=n)){s.waiting&&(s.waiting=null,r=!0),s.closedAt==null&&(s.closedAt=l),s.state==="active"&&(s.state="done",s.endedAt=l,s.reaped=!0,r=!0);for(const c of e.agents.values())c.sessionId!==s.sessionId||c.kind==="root"||c.state!=="active"||(c.state="done",c.endedAt=l,r=!0);e.activeSubagentStack.delete(s.sessionId)}}return Hu(e,r)}function l6(e){return e==="permission_prompt"?"permission":e==="agent_needs_input"?"asked":e==="idle_prompt"?"idle":null}const c6=new Set(["Notification","ModelObserved","ContextObserved","UsageObserved","SessionNamed","SessionRecapped"]);function u6(e,t){let n=null;for(const r of e.toolIndex.values()){const s=r.agentId?e.agents.get(r.agentId):void 0;!s||s.sessionId!==t||(!n||r.startedAt>n.startedAt)&&(n=r)}return n}const d6=3e4;function h6(e,t){if(!(!e||!e.name)&&!(t-e.startedAt>d6)&&!(e.startedAt>t))return{name:e.name,preview:D5(e.input)??""}}function f6(e,t,n,r,s){if(n!=="permission")return{kind:n,message:r,since:s};const l=u6(e,t),c={kind:n,message:r,since:s};l!=null&&l.explicitSubagentId&&(c.subagentId=l.explicitSubagentId);const u=h6(l,s);return u&&(c.tool=u),c}function p6(e,t,n){if(e.kind==="idle")return!0;const r=mu(t);return r==null?!0:e.subagentId!=null&&Vl(n,r)===e.subagentId}function WN(e,t){const n=t.epoch??null;if(n!==null&&n!==e.seqEpoch)e.seqEpoch=n,e.lastSeq=0;else if(t.seq<=e.lastSeq)return e;const r=t.payload??{},s=t.receivedAt,l=r.hook_event_name??"Unknown";if(l==="__clear")return{...E0(),lastSeq:t.seq,seqEpoch:e.seqEpoch,revision:e.revision+1};e.totalEvents+=1,e.lastSeq=t.seq,e.revision+=1;const c=r.session_id??"unknown";if(!c6.has(l)){const h=e.agents.get(c);h!=null&&h.waiting&&p6(h.waiting,r,c)&&(h.waiting=null)}const u=e.agents.get(c);if(u&&s>(u.lastEventAt??0)&&(u.lastEventAt=s,u.reaped&&(u.reaped=!1,u.state="active",u.endedAt=void 0,u.closedAt=void 0)),typeof r.model_context_window=="number"&&r.model_context_window>0){const h=e.agents.get(c);h&&(h.contextWindow=r.model_context_window)}if(typeof r.approval_policy=="string"&&r.approval_policy){const h=e.agents.get(c);h&&(h.approvalPolicy=r.approval_policy)}if(typeof r.context_tokens=="number"&&r.context_tokens>=0){const h=e.agents.get(c);h&&(h.context={...h.context??qN(),currentContextTokens:r.context_tokens})}if(l==="ModelObserved"){const h=typeof r.model=="string"?r.model:null;if(h){const y=e.agents.get(c);y&&(y.model=h)}const m=r.subagentModels;if(m&&typeof m=="object")for(const[y,v]of Object.entries(m)){if(typeof v!="string")continue;const S=`${c}::${y}`,b=e.agents.get(S);if(b)b.model=v,e.pendingSubagentModels.delete(S);else if(e.pendingSubagentModels.delete(S),e.pendingSubagentModels.set(S,v),e.pendingSubagentModels.size>256){const _=e.pendingSubagentModels.keys().next().value;_!==void 0&&e.pendingSubagentModels.delete(_)}}return e}if(l==="ContextObserved"){const h=r.context??null;if(h){const m=e.agents.get(c);if(m){const y=m.context??qN(),v=(b,_)=>typeof h[b]=="number"?h[b]:_,S=Array.isArray(h.memoryFiles)?h.memoryFiles:Array.isArray(h.claudeMdFiles)?h.claudeMdFiles:null;m.context={msgsUser:v("msgsUser",y.msgsUser),msgsAssistant:v("msgsAssistant",y.msgsAssistant),toolUses:v("toolUses",y.toolUses),toolResults:v("toolResults",y.toolResults),systemReminders:v("systemReminders",y.systemReminders),currentContextTokens:v("currentContextTokens",y.currentContextTokens),memoryFiles:S??y.memoryFiles}}}return e}if(l==="SessionNamed"){const h=e.agents.get(c);if(h){const m=typeof r.sessionName=="string"?r.sessionName.trim():"",y=typeof r.sessionTitle=="string"?r.sessionTitle.trim():"";m&&(h.sessionName=m),y&&(h.sessionTitle=y);const v=h.sessionName??"";h.sessionTitle&&v&&h.sessionTitle.toLowerCase()===v.toLowerCase()&&(h.sessionTitle=void 0)}return e}if(l==="SessionRecapped"){const h=e.agents.get(c);if(h){const m=r.recap;m===null?h.recap=void 0:m&&typeof m.text=="string"&&m.text.trim()&&Number.isFinite(m.at)&&(h.recap={text:m.text.trim(),at:m.at})}return e}if(l==="OutputObserved"){const h=r.kind==="thinking"||r.kind==="text"||r.kind==="tool_use"?r.kind:null,m=typeof r.at=="number"&&Number.isFinite(r.at)?r.at:s;if(!h)return e;const y=e.agents.get(c);if(!y||y.lastOutputAt!=null&&m<=y.lastOutputAt)return e;if(y.lastOutputAt=m,h!=="tool_use"){const v=(y.outputs??[]).filter(S=>m-S<m6);v.push(m),y.outputs=v.length>VN?v.slice(-VN):v}return e.revision+=1,e}if(l==="UsageObserved"){const h=r.usage??null;if(h){const m=e.agents.get(c);if(m){m.usage.inputTokens=Number(h.input_tokens??0),m.usage.outputTokens=Number(h.output_tokens??0),m.usage.cacheReadTokens=Number(h.cache_read_input_tokens??h.cached_input_tokens??0),m.usage.cacheCreateTokens=Number(h.cache_creation_input_tokens??h.cache_write_input_tokens??0);const y=jb(h);m.usage.cacheCreate1hTokens=y.cacheCreate1hTokens,m.usage.cacheCreate5mTokens=y.cacheCreate5mTokens,typeof h.reasoning_output_tokens=="number"&&(m.usage.reasoningOutputTokens=Number(h.reasoning_output_tokens)),m.usageByModel=H5(r.usageByModel)}}return e}const f=G5(e,r,s);f.provider||(f.provider=r.provider==="codex"?"codex":"claude");const p=ZA(r);switch(p&&(f.model=p),l){case"SessionStart":{const h=$l(e,c,s,!1);h.synthetic=!1,h.state="active",h.closedAt=void 0,h.endedAt=void 0,h.startedAt=Math.min(h.startedAt??s,s),!h.cwd&&r.cwd&&(h.cwd=r.cwd,h.cwdBasename=ao(r.cwd)),h.label==="session"&&r.cwd&&(h.label=ao(r.cwd)??"session");break}case"UserPromptSubmit":{for(const y of e.agents.values())y.sessionId===c&&y.kind==="subagent"&&y.state==="done"&&y.exitAt==null&&y.endedAt!=null&&y.endedAt<s&&(y.exitAt=s);const h=$l(e,c,s,!1);h.state="active",h.endedAt=void 0,h.closedAt=void 0,h.exitAt=void 0;const m=(typeof r.prompt=="string"?r.prompt:typeof r.message=="string"?r.message:"")??"";m&&!e6(h,s,m)&&(h.prompts.push({at:s,text:m}),!h.firstPrompt&&!Sb(m)&&(h.firstPrompt=ph(m,120)));break}case"PreToolUse":{const h=r.tool_use_id?J5(e,f,r.tool_use_id):null;if(h){r.tool_name&&h.name==="?"&&(h.name=r.tool_name),h.endedAt==null&&!h.trimmed&&r.tool_input!==void 0&&(h.input=r.tool_input,h.inputPreview=ph(r.tool_input));break}const m=r.tool_use_id??`${f.id}:${f.toolCount}`,y=mu(r),v={id:m,name:r.tool_name??"?",input:r.tool_input,inputPreview:ph(r.tool_input),agentId:f.id,explicitSubagentId:y?Vl(c,y):void 0,startedAt:s};f.tools.push(v),f.toolCount+=1,f.state="active",e.toolIndex.set(oo(f.sessionId,m),v),Q5(e,f);break}case"PostToolUse":case"PostToolUseFailure":{const h=r.tool_use_id;if(!h)break;const m=oo(c,h);let y=e.toolIndex.get(m),v=!1;if(!y)for(const b of e.agents.values()){if(b.sessionId!==c)continue;const _=b.tools.find(k=>k.id===h);if(_){y=_,v=!0;break}}if(!y||y.outcomeApplied)break;y.outcomeApplied=!0,y.outcomeGap=void 0,y.endedAt=s,y.ok=l==="PostToolUse",y.trimmed||(y.response=r.tool_response),l==="PostToolUseFailure"?y.errorPreview=ph(r.tool_response):v&&(y.errorPreview=void 0);const S=XA(r.tool_response);S&&(y.usage=S),e.toolIndex.delete(m);break}case"SubagentStart":{const h=mu(r);if(!h)break;const m=K5(e,c,h,r,s),y=ef(r);y&&(m.label=y);const v=e.subagentTombstones.get(m.id);v!=null&&e.subagentTombstones.delete(m.id);const S=m.endedAt!=null&&s-m.endedAt<=mh,b=v!=null&&s-v<=mh;if(S||b){const _=b?v:m.endedAt;m.state="done",m.endedAt=_,m.startedAt=Math.min(m.startedAt,_),BN(e,c,h);break}m.state="active",m.startedAt=m.startedAt||s,m.exitAt=void 0,m.endedAt=void 0,Y5(e,c,h);break}case"SubagentStop":{const h=mu(r);if(!h)break;const m=QA(e,c,h,r);if(!m){for(const[y,v]of e.subagentTombstones)s-v>mh&&e.subagentTombstones.delete(y);e.subagentTombstones.set(Vl(c,h),s);break}m.state="done",m.endedAt=Math.min(m.endedAt??s,s),BN(e,c,h);break}case"Stop":case"SessionEnd":{const h=$l(e,c,s,!1),m=t6(h);if(s<m)break;const y=h.lastTurnEndAt;if(y!=null&&m>y&&s<=y+mh)break;h.state="done",h.endedAt=s,h.lastTurnEndAt=s;for(const v of h.provider==="codex"?[]:e.agents.values())if(v.sessionId===c)for(const S of v.tools)S.endedAt==null&&S.explicitSubagentId==null&&(S.endedAt=s,S.ok=!1,S.errorPreview=S.outcomeGap?"no result reached the deck — events were dropped while the deck was paused":"the turn ended before this call returned",e.toolIndex.delete(oo(v.sessionId,S.id)));l==="SessionEnd"&&(h.closedAt=s),e.activeSubagentStack.delete(c);break}case"Notification":{const h=l6(r.notification_type);if(!h)break;const m=$l(e,c,s,!1),y=typeof r.message=="string"?r.message:"",v=m.waiting;m.waiting=v&&v.kind===h&&v.message===y?{...v,since:Math.min(v.since,s)}:f6(e,c,h,y,s);break}}return e}const m6=6e4,VN=64;function tf(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(n);return Math.abs(t)%360}const g6={input:2,output:10,cacheRead:.2,cacheWrite:2.5,cacheWrite1h:4},y6=[{match:/^claude[-_](fable|mythos)[-_]5[-_.]1\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:10,output:50,cacheRead:.25,cacheWrite:12.5,cacheWrite1h:20}},{match:/^claude[-_](fable|mythos)[-_]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:10,output:50,cacheRead:1,cacheWrite:12.5,cacheWrite1h:20}},{match:/^claude[-_]opus[-_]5[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:4,output:20,cacheRead:.2,cacheWrite:5,cacheWrite1h:8}},{match:/^claude[-_]opus[-_]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:5,output:25,cacheRead:.5,cacheWrite:6.25,cacheWrite1h:10}},{match:/^claude[-_]sonnet[-_]5[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:2,output:10,cacheRead:.2,cacheWrite:2.5,cacheWrite1h:4}},{match:/^claude[-_]sonnet[-_]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:g6},{match:/^claude[-_]opus[-_]4[-_.](?:5|6|7|8)\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:5,output:25,cacheRead:.5,cacheWrite:6.25,cacheWrite1h:10}},{match:/^claude[-_]opus[-_]4(?:[-_.]1)?\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75,cacheWrite1h:30}},{match:/^claude[-_]sonnet[-_]4[-_.](?:5|6)\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}},{match:/^claude[-_]sonnet[-_]4\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:3,output:15,cacheRead:.3,cacheWrite:3.75,cacheWrite1h:6}},{match:/^claude[-_]haiku[-_]4[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:1,output:5,cacheRead:.1,cacheWrite:1.25,cacheWrite1h:2}},{match:/^claude[-_]haiku[-_]3[-_.]5\b(?![-_.]\d{1,7}(?!\d))/i,rates:{input:.8,output:4,cacheRead:.08,cacheWrite:1,cacheWrite1h:1.6}},{match:/^gpt[-_]6[-_]astra\b(?![-_][A-Za-z])/i,rates:{input:10,output:50,cacheRead:1,cacheWrite:12.5}},{match:/^gpt[-_]5[-_.]6[-_]cyber/i,rates:{input:12.5,output:75,cacheRead:1.25,cacheWrite:15.625}},{match:/^gpt[-_]5[-_.]6[-_]luna/i,rates:{input:.2,output:1.2,cacheRead:.02,cacheWrite:.25}},{match:/^gpt[-_]5[-_.]6[-_]terra/i,rates:{input:2,output:12,cacheRead:.2,cacheWrite:2.5}},{match:/^gpt[-_]5[-_.]6(?:[-_]sol)?\b(?![-_][A-Za-z])/i,rates:{input:4,output:20,cacheRead:.4,cacheWrite:5}},{match:/^gpt[-_]5[-_.]5[-_]pro/i,rates:{input:30,output:180,cacheRead:30,cacheWrite:0}},{match:/^gpt[-_]5[-_.]5\b(?![-_][A-Za-z])/i,rates:{input:5,output:30,cacheRead:.5,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]pro/i,rates:{input:30,output:180,cacheRead:3,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]mini/i,rates:{input:.75,output:4.5,cacheRead:.075,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4[-_]nano/i,rates:{input:.2,output:1.25,cacheRead:.02,cacheWrite:0}},{match:/^gpt[-_]5[-_.]4\b/i,rates:{input:2.5,output:15,cacheRead:.25,cacheWrite:0}},{match:/^gpt[-_]5[-_.]3[-_]codex/i,rates:{input:1.75,output:14,cacheRead:.175,cacheWrite:0}},{match:/^gpt[-_]5[-_.]2[-_]pro/i,rates:{input:21,output:168,cacheRead:21,cacheWrite:0}},{match:/^gpt[-_]5[-_.]2\b/i,rates:{input:1.75,output:14,cacheRead:.175,cacheWrite:0}},{match:/^gpt[-_]5[-_.]1[-_]codex[-_]mini/i,rates:{input:.25,output:2,cacheRead:.025,cacheWrite:0}},{match:/^gpt[-_]5[-_.]1(?!\d)/i,rates:{input:1.25,output:10,cacheRead:.125,cacheWrite:0}},{match:/^gpt[-_]5[-_]pro\b/i,rates:{input:15,output:120,cacheRead:15,cacheWrite:0}},{match:/^gpt[-_]5[-_]mini/i,rates:{input:.25,output:2,cacheRead:.025,cacheWrite:0}},{match:/^gpt[-_]5[-_]nano/i,rates:{input:.05,output:.4,cacheRead:.005,cacheWrite:0}},{match:/^gpt[-_]5(?![-_.]\d)/i,rates:{input:1.25,output:10,cacheRead:.125,cacheWrite:0}},{match:/^codex[-_]mini/i,rates:{input:1.5,output:6,cacheRead:.375,cacheWrite:0}},{match:/^o1[-_]pro/i,rates:{input:150,output:600,cacheRead:150,cacheWrite:0}},{match:/^o1[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0}},{match:/^o1\b/i,rates:{input:15,output:60,cacheRead:7.5,cacheWrite:0}},{match:/^o3[-_]deep[-_]research/i,rates:{input:10,output:40,cacheRead:2.5,cacheWrite:0}},{match:/^o3[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.55,cacheWrite:0}},{match:/^o3[-_]pro/i,rates:{input:20,output:80,cacheRead:20,cacheWrite:0}},{match:/^o4[-_]mini[-_]deep[-_]research/i,rates:{input:2,output:8,cacheRead:.5,cacheWrite:0}},{match:/^o4[-_]mini/i,rates:{input:1.1,output:4.4,cacheRead:.275,cacheWrite:0}},{match:/^o3\b/i,rates:{input:2,output:8,cacheRead:.5,cacheWrite:0}}];function w6(e){return e?/^(?:gpt[-_]|codex[-_]|o\d)/i.test(e):!1}function Ni(e,t=Date.now()){if(!e)return null;const n=nc(e);for(const r of y6)if(r.match.test(n))return typeof r.rates=="function"?r.rates(t):r.rates;return null}function eM(e,t){const n=Math.max(0,e.cacheCreate1hTokens??0),r=Math.max(0,e.cacheCreate5mTokens??0),s=Math.max(0,e.cacheCreateTokens-n-r),l=r+s,c=t.cacheWrite1h??t.cacheWrite;return{tokens5m:l,tokens1h:n,usd5m:l*t.cacheWrite/1e6,usd1h:n*c/1e6}}function tM(e,t,n=Date.now()){if(!w6(t))return e.inputTokens;const r=Ni(t,n),s=((r==null?void 0:r.cacheWrite)??0)>0?Math.max(0,e.cacheCreateTokens):0;return Math.max(0,e.inputTokens-e.cacheReadTokens-s)}function Cu(e,t,n=Date.now()){const r=Ni(t,n);if(!r)return{input:0,output:0,cacheRead:0,cacheWrite:0,total:0};const s=tM(e,t,n)*r.input/1e6,l=e.outputTokens*r.output/1e6,c=e.cacheReadTokens*r.cacheRead/1e6,u=eM(e,r),f=u.usd5m+u.usd1h;return{input:s,output:l,cacheRead:c,cacheWrite:f,total:s+l+c+f}}const GN=2e5,v6=1e6,x6=[/\[1m\]/i,/^claude[-_]opus[-_]5\b/i,/^claude[-_]sonnet[-_]5\b/i,/^claude[-_]opus[-_]4[-_.](?:6|7|8)\b/i,/^claude[-_]sonnet[-_]4[-_.]6\b/i,/^claude[-_](fable|mythos)[-_]5\b/i],b6=[{match:/^gpt[-_]6[-_]astra/i,window:105e4},{match:/^gpt[-_]5[-_.]6[-_]cyber/i,window:4e5},{match:/^gpt[-_]5[-_.]6/i,window:105e4},{match:/^gpt[-_]5[-_.]5/i,window:105e4},{match:/^gpt[-_]5[-_.]4[-_](?:mini|nano)/i,window:4e5},{match:/^gpt[-_]5[-_.]4/i,window:105e4},{match:/^gpt[-_]5[-_.]3[-_]codex[-_]spark/i,window:128e3},{match:/^gpt[-_]5[-_.]3[-_]codex/i,window:4e5},{match:/^gpt[-_]5[-_.]2/i,window:4e5},{match:/^gpt[-_]5/i,window:4e5},{match:/^codex[-_]mini/i,window:2e5},{match:/^o\d/i,window:2e5}];function k6(e){if(!e)return GN;const t=nc(e);for(const n of x6)if(n.test(t))return v6;for(const n of b6)if(n.match.test(t))return n.window;return GN}function nM(e,t){return typeof e=="number"&&e>0?e:k6(t)}const la="not priced";function bt(e){if(e<=0)return"—";if(e<.005)return"<1¢";if(e<1){const t=(e*100).toFixed(e<.1?1:0);if(Number(t)<100)return`${t}¢`}if(e<100){const t=e.toFixed(2);if(Number(t)<100)return`$${t}`}if(e<1e4){const t=e.toFixed(0);if(Number(t)<1e4)return`$${t}`}return`$${(e/1e3).toFixed(1)}k`}function _b(e,t){if(e<=0||t<10)return null;const n=e/t,r=n*60;return r>=.01?`${bt(r)}/min`:`${bt(n*3600)}/hr`}function N6(e,t){const n={inputTokens:e.inputTokens+t.inputTokens,outputTokens:e.outputTokens+t.outputTokens,cacheReadTokens:e.cacheReadTokens+t.cacheReadTokens,cacheCreateTokens:e.cacheCreateTokens+t.cacheCreateTokens};return(e.cacheCreate1hTokens!==void 0||e.cacheCreate5mTokens!==void 0||t.cacheCreate1hTokens!==void 0||t.cacheCreate5mTokens!==void 0)&&(n.cacheCreate1hTokens=(e.cacheCreate1hTokens??0)+(t.cacheCreate1hTokens??0),n.cacheCreate5mTokens=(e.cacheCreate5mTokens??0)+(t.cacheCreate5mTokens??0)),(e.reasoningOutputTokens!==void 0||t.reasoningOutputTokens!==void 0)&&(n.reasoningOutputTokens=(e.reasoningOutputTokens??0)+(t.reasoningOutputTokens??0)),n}function S6(e,t){let n=0,r=0,s=0,l=0,c=0,u=0;for(const m of t)n+=m.inputTokens,r+=m.outputTokens,s+=m.cacheReadTokens,l+=m.cacheCreateTokens,c+=m.cacheCreate1hTokens??0,u+=m.cacheCreate5mTokens??0;const f=(m,y)=>Math.max(0,m-y),p={inputTokens:f(e.inputTokens,n),outputTokens:f(e.outputTokens,r),cacheReadTokens:f(e.cacheReadTokens,s),cacheCreateTokens:f(e.cacheCreateTokens,l)};return(e.cacheCreate1hTokens!==void 0||e.cacheCreate5mTokens!==void 0)&&(p.cacheCreate1hTokens=f(e.cacheCreate1hTokens??0,c),p.cacheCreate5mTokens=f(e.cacheCreate5mTokens??0,u)),p.inputTokens+p.outputTokens+p.cacheReadTokens+p.cacheCreateTokens>0?p:null}function Wu(e){const t=e.usageByModel,n=t?Object.keys(t):[];if(!t||n.length===0)return[{model:e.model,usage:e.usage}];const r=n.map(l=>({model:l,usage:t[l]})),s=S6(e.usage,r.map(l=>l.usage));if(s){const l=r.findIndex(c=>c.model===e.model);l>=0?r[l]={model:r[l].model,usage:N6(r[l].usage,s)}:r.push({model:e.model,usage:s})}return r}function or(e,t=Date.now()){const n={input:0,output:0,cacheRead:0,cacheWrite:0,total:0};for(const r of Wu(e)){const s=Cu(r.usage,r.model,t);n.input+=s.input,n.output+=s.output,n.cacheRead+=s.cacheRead,n.cacheWrite+=s.cacheWrite,n.total+=s.total}return n}function Tu(e,t=Date.now()){let n=0;for(const r of Wu(e))Ni(r.model,t)==null&&(n+=r.usage.inputTokens+r.usage.outputTokens);return n}function rM(e){const t=[];for(const n of Wu(e)){if(!n.model||t.includes(n.model))continue;const r=n.usage;r.inputTokens+r.outputTokens+r.cacheReadTokens+r.cacheCreateTokens<=0||t.push(n.model)}return t}function sM(e){return rM(e).filter(t=>t!==e.model)}const j6=new Set(["untrusted","on-request","on-failure"]);function _6(e){return typeof e!="string"||!e?null:j6.has(e)?!0:e==="never"?!1:null}function E6(e){if(e.provider!=="codex"||e.kind!=="root"||e.waiting||e.state!=="active")return null;const t=_6(e.approvalPolicy);return t===!1?null:{label:"approvals not visible",detail:`${t===!0?`This session's approval policy is "${e.approvalPolicy}", so Codex can stop and ask you to approve a command.`:"This session's approval policy has not been read yet, so it may be able to stop and ask you to approve a command."}
58
58
 
59
59
  Codex writes no approval request to its rollout files, which are the only thing this deck can read — so when it does ask, this card, the sidebar, the topbar count, the tab title and the favicon will all stay silent. Check the terminal.`}}function KN(e){return e[0].toUpperCase()+e.slice(1).toLowerCase()}function io(e){const t=nc(e).replace(/[-_]\d{8}(?!\d)/,""),n=t.match(/^claude[-_](opus|sonnet|haiku|fable|mythos)[-_](\d+(?:[-_.]\d+)*)/i);if(n){const s=KN(n[1]),l=n[2].replace(/[-_]/g,".");return`${s} ${l}`}const r=t.match(/^gpt[-_](\d+(?:[-_.]\d+)*)((?:[-_][A-Za-z0-9.]+)*)$/i);if(r){const s=r[1].replace(/[-_]/g,"."),l=r[2].split(/[-_]/).filter(Boolean).map(KN);return[`GPT-${s}`,...l].join(" ")}return e}function Sf(e){const t=nc(e??""),n=t.match(/^claude[-_](opus|sonnet|haiku|fable|mythos)[-_]/i);return n?n[1].toLowerCase():/^gpt[-_]/i.test(t)?"gpt":""}function Dr(e){return(e==null?void 0:e.kind)==="permission"||(e==null?void 0:e.kind)==="asked"}function km(e){const t=[];for(const n of e)n.kind==="root"&&Dr(n.waiting)&&t.push({id:n.id,label:n.label,waiting:n.waiting});return t.sort((n,r)=>n.waiting.since-r.waiting.since)}function C6(e,t){if(e.length===0)return null;const n=e.findIndex(r=>r.id===t);return e[(n+1)%e.length]}function T6(e){const t=new Set;for(const n of e)n.state==="active"&&t.add(n.sessionId);return t.size}function jf(e,t){return`${e}@${t.since}`}function aM(e,t){if(!e.tool)return null;const{name:n,preview:r}=e.tool,s=new RegExp(`\\b${n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}\\b`,"i").test(t);return r?s?r:`${n} · ${r}`:s?null:n}function R6(e){const t=e.message||"Needs your permission",n=aM(e,t);return n?`${t}
60
60
  Likely on: ${n}`:t}function A6(e,t,n,r=!0){if(!r)return[];if(n)return[];const s=[];for(const l of e){if(!Dr(l.waiting))continue;const c=jf(l.id,l.waiting);t.has(c)||s.push({key:c,title:l.label,body:R6(l.waiting),sessionId:l.id})}return s}function M6(e,t,n){const r=new Set;for(const l of e)r.add(jf(l.id,l.waiting));const s=new Set;for(const l of n)r.has(l)&&s.add(l);for(const l of t)s.add(l.key);return s}function Nm(e){return new Set(e.map(t=>jf(t.id,t.waiting)))}function I6(e,t){return e!==t}function $6(e,t){return!e&&t!=null}function O6(e,t){return e!==null&&t!=null}function Pt(e){const t=Math.round(e);return t<1e3?`${t}`:t<1e6?`${(t/1e3).toFixed(1)}k`:t<1e9?`${(t/1e6).toFixed(2)}M`:`${(t/1e9).toFixed(2)}B`}function Gl(e,t,n){const r=(t??n)-e;if(r<1e3)return`${Math.max(0,r)}ms`;const s=Math.floor(r/1e3);if(s<60)return`${s}s`;const l=Math.floor(s/60),c=s%60;return`${l}m ${String(c).padStart(2,"0")}s`}function oM(e,t){if(e.endedAt==null)return t;const n=e.endedAt-e.startedAt;return n<1e3?`${n}ms`:`${(n/1e3).toFixed(2)}s`}function Eb(e,t){const n=typeof e=="string"?e.trim():"",r=typeof t=="string"?t.trim():"";return{face:n||r||void 0,tooltip:r||n||void 0}}const L6=1;function P6(){const e=[];let t=0;function n(){let r;for(const s of e)(!r||s.layer>r.layer||s.layer===r.layer&&s.seq>r.seq)&&(r=s);return r}return{push(r,s=0,l="dialog"){const c={dismiss:r,layer:s,kind:l,seq:t++};return e.push(c),()=>{const u=e.indexOf(c);u!==-1&&e.splice(u,1)}},dismissTop(){const r=n();return r?(r.dismiss(),!0):!1},isTop(r){const s=n();return s!=null&&s.dismiss===r},depth(){return e.length},dialogDepth(){return e.filter(r=>r.kind==="dialog").length}}}const gu=P6(),D6=e=>e==="Escape";function F6(e){return e.overlayOpen?"dismiss":e.typing?"blur":"clear-selection"}function YN(e){return String(e.tagName??"").toUpperCase()==="BODY"}function q6(e,t){return!e||!e.isConnected||YN(e)?!1:t==null||YN(t)}const XN="a[href], button, input, select, textarea, [tabindex]";function B6(e){return!e||e.disabled||e.rendered===!1?!1:(e.tabIndex??0)>=0}function z6(e){if(!e||!e.overflowing||e.hasFocusable)return!1;const t=String(e.overflow??"").toLowerCase();return t==="auto"||t==="scroll"}function U6({count:e,index:t,shiftKey:n}){return e<=0?{kind:"hold"}:t<0||t>=e?{kind:"focus",index:n?e-1:0}:!n&&t===e-1?{kind:"focus",index:0}:n&&t===0?{kind:"focus",index:e-1}:{kind:"allow"}}function _f(e){return e.ctrlKey||e.metaKey||e.altKey}const H6=new Set(["button","checkbox","color","file","image","radio","range","reset","submit"]),W6=new Set(["INPUT","TEXTAREA","SELECT","OPTION","BUTTON","SUMMARY","A"]),V6=new Set(["button","checkbox","combobox","link","listbox","menu","menubar","menuitem","menuitemcheckbox","menuitemradio","option","radio","searchbox","slider","spinbutton","switch","tab","textbox","treeitem"]);function Cb(e){return typeof e.tagName=="string"?e.tagName.toUpperCase():""}function G6(e){return Cb(e)==="BUTTON"?!0:(typeof e.role=="string"?e.role.trim().toLowerCase():"").split(/\s+/).includes("button")}function Ef(e){if(!e)return!1;if(e.isContentEditable)return!0;const t=Cb(e);return t==="TEXTAREA"?!0:t!=="INPUT"?!1:!H6.has(String(e.type??"text").toLowerCase())}function K6(e,t){if(!e)return!1;if(Ef(e))return!0;if(t!=null&&t.length===1&&t!==" "&&e.pointerFocused&&G6(e))return!1;if(W6.has(Cb(e)))return!0;const n=typeof e.role=="string"?e.role.trim().toLowerCase():"";return n!==""&&n.split(/\s+/).some(r=>V6.has(r))}function Y6({key:e,modalOpen:t,sheetOpen:n}){return t?!(e==="?"&&n):!1}function X6({appModal:e,dialogDepth:t}){return e||t>0}function iM(e){return e?Array.from(e.querySelectorAll("*")).filter(t=>{if(t.matches(XN))return B6({disabled:t.disabled,tabIndex:t.tabIndex,rendered:t.getClientRects().length>0});const n=t.scrollHeight>t.clientHeight;return n&&z6({overflowing:n,overflow:getComputedStyle(t).overflowY,hasFocusable:t.querySelector(XN)!=null})}):[]}function Z6(e,t){const n=iM(e);if(!t||!e.contains(t)||n.includes(t))return n;const r=n.findIndex(s=>(t.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_FOLLOWING)!==0);return r===-1?[...n,t]:[...n.slice(0,r),t,...n.slice(r)]}function mn(e,t={}){const{focusRef:n,layer:r,popover:s}=t,l=s?"popover":"dialog",c=w.useRef(null),u=w.useRef(e);u.current=e;const f=w.useRef(null);f.current===null&&(f.current=()=>u.current());const p=f.current;return w.useEffect(()=>gu.push(p,r,l),[p,r,l]),w.useEffect(()=>{var m;const h=document.activeElement;return(m=(n==null?void 0:n.current)??iM(c.current)[0])==null||m.focus(),()=>{q6(h,document.activeElement)&&h.focus()}},[]),w.useEffect(()=>{const h=m=>{var k;if(m.key!=="Tab"||_f(m))return;const y=c.current;if(!y)return;const v=document.activeElement;if(!(v!=null&&y.contains(v))&&!gu.isTop(p))return;const b=Z6(y,v),_=U6({count:b.length,index:v?b.indexOf(v):-1,shiftKey:m.shiftKey});_.kind!=="allow"&&(m.preventDefault(),_.kind==="focus"&&((k=b[_.index])==null||k.focus()))};return window.addEventListener("keydown",h),()=>window.removeEventListener("keydown",h)},[p]),c}function Q6(e){return e==="codex"?{subtitle:"reported by the Codex CLI — as of its most recent request",windowScope:"last request",compositionCounted:!1,compositionUncounted:"Not counted for Codex — the deck reconstructs the session from its rollout file and skips whatever was written before it attached, so a message and tool-call breakdown here would be short by an unknown amount. The window figure above is the CLI's own and is unaffected.",memoryHeading:"AGENTS.md files in scope",memoryEmpty:"No AGENTS.md files found on the path from cwd to the filesystem root, or in $CODEX_HOME."}:{subtitle:"approximation — CC's /context isn't hook-exposed",windowScope:"current turn",compositionCounted:!0,compositionUncounted:"",memoryHeading:"CLAUDE.md files in scope",memoryEmpty:"No CLAUDE.md files found on the path from cwd to ~/.claude."}}function $r(e){return e.toLocaleString()}function J6(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`}const eF=60;function tF(e,t=eF){if(e.length<=t)return e;const n=e.slice(e.length-(t-1)),r=n.search(/[/\\]/);return"…"+(r===-1?n:n.slice(r))}function nF({agent:e,onClose:t}){var y;const n=w.useRef(null),r=mn(t,{focusRef:n}),s=e.context,l=e.usage,c=(s==null?void 0:s.currentContextTokens)??0,u=nM(e.contextWindow,e.model),f=Math.min(100,c/u*100),p=or(e),h=e.provider==="codex"?l.inputTokens+l.outputTokens:l.inputTokens+l.outputTokens+l.cacheReadTokens+l.cacheCreateTokens,m=Q6(e.provider);return o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:r,className:"modal ctx-modal",onClick:v=>v.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Context breakdown",children:[o.jsxs("header",{className:"ctx-modal-head",children:[o.jsxs("div",{children:[o.jsxs("div",{className:"ctx-modal-title",children:["Context · ",e.label]}),o.jsx("div",{className:"ctx-modal-sub",children:m.subtitle})]}),o.jsx("button",{type:"button",ref:n,className:"glyph-btn ctx-modal-close",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})]}),o.jsxs("section",{className:"ctx-window-row",children:[o.jsx("div",{className:"ctx-window-bar",role:"progressbar","aria-label":"Context window used","aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":Math.round(f),children:o.jsx("div",{className:"ctx-window-fill",style:{transform:`scaleX(${Math.min(100,Math.max(0,f))/100})`}})}),o.jsxs("div",{className:"ctx-window-meta",children:[o.jsxs("span",{className:"ctx-window-pct",children:[f.toFixed(1),"%"]}),o.jsxs("span",{children:[$r(c)," / ",$r(u)," tok (",m.windowScope,")"]})]})]}),o.jsx("h3",{className:"ctx-section-title",children:"Cumulative usage · whole session"}),o.jsxs("div",{className:"ctx-grid",children:[o.jsx(hs,{label:"input tokens",val:$r(l.inputTokens)}),o.jsx(hs,{label:"output tokens",val:$r(l.outputTokens)}),o.jsx(hs,{label:"cache reads",val:$r(l.cacheReadTokens)}),o.jsx(hs,{label:"cache writes",val:$r(l.cacheCreateTokens)}),o.jsx(hs,{label:"cumulative total",val:$r(h)}),o.jsx(hs,{label:"estimated cost",val:bt(p.total),accent:!0})]}),o.jsx("h3",{className:"ctx-section-title",children:"Transcript composition"}),m.compositionCounted?o.jsxs("div",{className:"ctx-grid",children:[o.jsx(hs,{label:"user messages",val:$r((s==null?void 0:s.msgsUser)??0)}),o.jsx(hs,{label:"assistant messages",val:$r((s==null?void 0:s.msgsAssistant)??0)}),o.jsx(hs,{label:"tool uses",val:$r((s==null?void 0:s.toolUses)??0)}),o.jsx(hs,{label:"tool results",val:$r((s==null?void 0:s.toolResults)??0)}),o.jsx(hs,{label:"system-reminders",val:$r((s==null?void 0:s.systemReminders)??0)})]}):o.jsx("div",{className:"ctx-empty",children:m.compositionUncounted}),o.jsx("h3",{className:"ctx-section-title",children:m.memoryHeading}),(((y=s==null?void 0:s.memoryFiles)==null?void 0:y.length)??0)===0?o.jsx("div",{className:"ctx-empty",children:m.memoryEmpty}):o.jsx("ul",{className:"ctx-md-list",children:s.memoryFiles.map(v=>o.jsxs("li",{children:[o.jsx("span",{className:"ctx-md-path",title:v.path,children:tF(v.path)}),o.jsx("span",{className:"ctx-md-size",children:J6(v.bytes)})]},v.path))})]})})}function hs({label:e,val:t,accent:n}){return o.jsxs("div",{className:`ctx-row${n?" accent":""}`,children:[o.jsx("span",{className:"ctx-row-label",children:e}),o.jsx("span",{className:"ctx-row-val",children:t})]})}function rF({currentContextTokens:e,modelId:t,contextWindow:n,size:r=26,onClick:s}){const l=nM(n,t),c=Math.min(1,e/l),u=r/2-3,f=r/2,p=2*Math.PI*u,h=p*c,m=c>.9?"var(--err)":c>.7?"var(--inflight)":"var(--accent)";return o.jsx("button",{type:"button",className:"ctx-donut",onClick:s,title:`context: ${e.toLocaleString()} / ${l.toLocaleString()} (${(c*100).toFixed(1)}%)`,"aria-label":`Context ${Math.round(c*100)}% of ${l.toLocaleString()} tokens — show breakdown`,children:o.jsxs("svg",{width:r,height:r,viewBox:`0 0 ${r} ${r}`,"aria-hidden":"true",children:[o.jsx("circle",{cx:f,cy:f,r:u,stroke:"var(--line)",strokeWidth:"2.5",fill:"none"}),o.jsx("circle",{cx:f,cy:f,r:u,stroke:m,strokeWidth:"2.5",fill:"none",strokeDasharray:`${h} ${p-h}`,strokeDashoffset:p/4,strokeLinecap:"round",style:{transition:"var(--ctx-arc-transition)"}}),o.jsx("text",{x:f,y:f+3,textAnchor:"middle",fontSize:"8",fill:"var(--text)",fontWeight:"600",children:Math.round(c*100)})]})})}const ZN=new Map;function lM(e){let t=ZN.get(e);return t||(t={now:Date.now(),listeners:new Set,timer:null},ZN.set(e,t)),t}function sF(e,t){const n=lM(e);return n.listeners.add(t),n.timer===null&&(n.now=Date.now(),n.timer=setInterval(()=>{n.now=Date.now();for(const r of n.listeners)r()},e)),()=>{n.listeners.delete(t),n.listeners.size===0&&n.timer!==null&&(clearInterval(n.timer),n.timer=null)}}function aF(e){return lM(e).now}const QN=new Map,JN=new Map;function rc(e=1e3){let t=QN.get(e);t||(t=r=>sF(e,r),QN.set(e,t));let n=JN.get(e);return n||(n=()=>aF(e),JN.set(e,n)),w.useSyncExternalStore(t,n,n)}function Cf(e){const t=e.recap;if(e.kind!=="root"||!t||e.state==="active"||e.closedAt!=null)return null;for(const n of e.prompts)if(n.at>t.at)return null;return t}const oF="1",eS="agent-dag.schema",iF=["agent-dag.layout","agent-dag.viewport"];function yr(e){if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function lF(e,t=oF){let n=null;try{n=e.getItem(eS)}catch{return[]}if(n===t)return[];const r=[];if(n!==null)for(const s of iF)try{e.getItem(s)!==null&&(e.removeItem(s),r.push(s))}catch{}try{e.setItem(eS,t)}catch{}return r}const cM="agent-dag.recapsDismissed",tS=200;function cF(){const e=yr(cM);if(!e)return[];try{const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}let Kl=new Set(cF());const C0=new Set;let uM=0;function dM(e){return C0.add(e),()=>{C0.delete(e)}}function hM(e){if(Kl=e,uM++,typeof window<"u")try{const t=Array.from(e);window.localStorage.setItem(cM,JSON.stringify(t.length>tS?t.slice(-tS):t))}catch{}for(const t of C0)t()}function fM(e,t){return`${e}@${t}`}function uF(e){return Kl.has(e)}function dF(e){if(Kl.has(e))return;const t=new Set(Kl);t.add(e),hM(t)}function hF(e){const t=new Set(Kl);t.delete(e)||t.add(e),hM(t)}function fF(e){return w.useSyncExternalStore(dM,()=>e!=null&&Kl.has(e),()=>!1)}function Tb(e){return`recap:${e}`}function pF(e){return e.startsWith("recap:")}function mF(){return w.useSyncExternalStore(dM,()=>uM,()=>0)}function gF(e){const t=new Map;for(const n of e){if(n.kind!=="subagent"||n.exitAt!=null)continue;let r=t.get(n.sessionId);r||(r={total:0,live:0,done:0,err:0,failed:0},t.set(n.sessionId,r)),r.total+=1,n.state==="active"?r.live+=1:n.state==="err"?r.err+=1:r.done+=1;for(const s of n.tools)s.ok===!1&&(r.failed+=1)}return t}function pM(e){return[`${e.total} ${e.total===1?"subagent":"subagents"}`,e.live>0?`${e.live} live`:null,e.done>0?`${e.done} done`:null,e.err>0?`${e.err} err`:null].filter(Boolean).join(" · ")}function mM(e){return e.live>0?`→ ${e.total} · ${e.live} live`:`→ ${e.total} · done`}function yF(e,t,n){const r=e.kind==="root"?e.waiting:null;if(r&&Dr(r))return{tone:"warn",long:n.sayWaiting(r),short:r.kind==="permission"?"Needs you":"Asked you"};if(r&&r.kind==="idle"){const l=n.sayWaiting(r);return{tone:"idle",long:l,short:l}}const s=e.tools.filter(l=>l.ok===!1).length;if(s>0)return{tone:"err",long:`${s} tool ${s===1?"call":"calls"} failed`,short:`${s} failed`};if(t&&t.total>0)return{tone:"muted",long:pM(t),short:mM(t)};if(e.state==="active")for(let l=e.tools.length-1;l>=0;l--){const c=e.tools[l];if(c.endedAt!=null)continue;const{name:u,subject:f}=n.describeCall(c);return{tone:"muted",long:f?`${u} · ${f}`:u,short:u}}return null}function T0(e){return e==="active"?"live":e==="done"?"done":"err"}const Tf={exec:{category:"shell",emoji:"⚡",label:"Shell",shell:!0},shell:{category:"shell",emoji:"⚡",label:"Shell",shell:!0},exec_command:{category:"shell",emoji:"⚡",label:"Shell",shell:!0},shell_command:{category:"shell",emoji:"⚡",label:"Shell",shell:!0},write_stdin:{category:"shell",emoji:"💻",label:"stdin",shell:!0},wait:{category:"shell",emoji:"⏳",label:"wait",shell:!0},apply_patch:{category:"file",emoji:"🩹",label:"Edit"},update_plan:{category:"task",emoji:"📋",label:"Plan"},run:{category:"web",emoji:"🌐",label:"Web"}},wF=Object.fromEntries(Object.entries(Tf).map(([e,t])=>[e,t.category])),vF=Object.fromEntries(Object.entries(Tf).map(([e,t])=>[e,t.emoji])),xF=Object.fromEntries(Object.entries(Tf).map(([e,t])=>[e,t.label])),bF=new Set(Object.entries(Tf).filter(([,e])=>e.shell).map(([e])=>e)),nS={Read:"file",Write:"file",Edit:"file",MultiEdit:"file",Glob:"file",Grep:"file",LS:"file",NotebookEdit:"file",Bash:"shell",PowerShell:"shell",WebFetch:"web",WebSearch:"web",Task:"agent",Agent:"agent",TodoWrite:"task",TaskCreate:"task",TaskUpdate:"task",TaskList:"task",TaskGet:"task",TaskOutput:"task",TaskStop:"task",EnterPlanMode:"plan",ExitPlanMode:"plan",AskUserQuestion:"plan",Skill:"plan",Workflow:"plan",...wF};function gM(e){return e.startsWith("mcp__")?"mcp":Object.hasOwn(nS,e)?nS[e]:"other"}const kF=/\btools\.exec_command\s*\(\s*\{[^{}]*?\bcmd\s*:\s*(["'`])((?:\\.|(?!\1)[^\\])*)\1/,NF=/\btools\.([A-Za-z_$][\w$]*)\s*\(/;function SF(e){if(typeof e!="string"||!e)return null;const t=kF.exec(e);if(t){const r=jF(t[2]);if(r.trim())return r}const n=NF.exec(e);return n?n[1]:null}function jF(e){return e.replace(/\\(["'`\\nrt])/g,(t,n)=>n==="n"?`
@@ -89,7 +89,7 @@ ${Ae.sessionId}`:Ae.sessionId,children:Ae.label??Ae.sessionId.slice(0,8)}),o.jsx
89
89
 
90
90
  ${n}`:`Sort by ${t}`,onClick:()=>s(W8(r,e)),children:[t,o.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:l==="none"?"":l==="ascending"?"↑":"↓"})]})})}const J8=3e3;function eB(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function tB(e,t,n=Date.now()){const r=Math.max(0,Math.min(100,100-e));return{pct:r,value:`${r}%`,tone:r===0?"calm":r>=30?"hot":"warn",note:r>0?`CPU held to ${e}% of full speed to cool down`:t?`at full speed · held to ${100-t.peak}% ${nB(t.lastMs,n)}`:"running at full speed, and never held back"}}function nB(e,t=Date.now()){const n=Math.max(0,Math.floor((t-e)/6e4));if(n<2)return"just now";if(n<60)return`${n} minutes ago`;const r=Math.floor(n/60);return r===1?"an hour ago":`${r} hours ago`}function au(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:`${Math.round(e/1024)} KB`}function rB(e){const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h`:n>0?`${n}h ${r}m`:`${r}m`}function sB(e){var n,r,s;const t=(r=(n=e.thermal)==null?void 0:n.throttle)==null?void 0:r.speedLimit;return t!=null&&t<100?`throttled to ${t}% of full speed`:e.memory&&e.memory.usedPct>=90?`physical memory ${Math.round(e.memory.usedPct)}% full`:(s=e.network)!=null&&s.api&&e.network.api.ms==null?"the Claude API is not answering":null}function aB(){const[e,t]=w.useState(null),n=w.useRef(null);return w.useEffect(()=>{let r=!0;const s=async()=>{if(document.visibilityState!=="hidden")try{const f=await fetch("/api/system");if(!f.ok)return;const p=await f.json();r&&(p!=null&&p.ok)&&t(p)}catch{}},l=()=>{n.current==null&&(s(),n.current=window.setInterval(s,J8))},c=()=>{n.current!=null&&(window.clearInterval(n.current),n.current=null)},u=()=>{if(document.visibilityState==="hidden"){c();return}l(),s()};return l(),document.addEventListener("visibilitychange",u),()=>{r=!1,c(),document.removeEventListener("visibilitychange",u)}},[]),e}function $S({usageOpen:e,leaving:t,sub:n,flag:r,onClose:s,children:l}){return o.jsxs("aside",{className:`sysdetail${e?" shifted":""}${t?" leaving":""}`,id:"system-panel","aria-labelledby":"sd-title",children:[o.jsxs("div",{className:"sd-top",children:[o.jsxs("div",{className:"sd-head",children:[o.jsx("h2",{className:"sd-title",id:"sd-title",children:"This machine"}),n&&o.jsx("span",{className:"sd-sub",children:n}),o.jsx("button",{type:"button",className:"glyph-btn sd-close",onClick:s,"aria-label":"Close",title:"Close",children:"×"})]}),r&&o.jsx("p",{className:"sd-flag",children:r})]}),l]})}function oB({usageOpen:e,leaving:t,onClose:n}){const r=aB();if(!r||r.cpu==null||!r.memory)return o.jsx($S,{usageOpen:e,leaving:t,onClose:n,children:o.jsx("div",{className:"sd-note",children:"reading this machine…"})});const{memory:s,swap:l,perCore:c,loadavg:u,cores:f,uptimeSec:p,platform:h,thermal:m,network:y,cpu:v}=r;return o.jsxs($S,{usageOpen:e,leaving:t,sub:`up ${rB(p)} · ${f} cores`,flag:sB(r),onClose:n,children:[o.jsx(iB,{cpu:v,perCore:c,loadavg:u,cores:f}),o.jsx(lB,{memory:s,swap:l,platform:h}),y&&o.jsx(cB,{network:y}),o.jsx(hB,{thermal:m}),o.jsx(fB,{sys:r})]})}function iB({cpu:e,perCore:t,loadavg:n,cores:r}){const s=!!t&&t.length>0;return!s&&!n?null:o.jsxs("div",{className:"sd-section sd-cpu",role:"group","aria-label":"CPU",children:[s&&o.jsx(Iu,{group:"cores",title:"Core history",action:"Show core history",label:"CPU",value:e==null?null:`${Math.round(e)}%`,children:o.jsx("div",{className:"sd-cores",role:"img","aria-label":`${t.length} logical cores, busiest at ${Math.round(Math.max(...t))}%`,children:t.map((l,c)=>o.jsx("span",{className:"sd-core",title:`logical core ${c+1} · ${l}% busy`,children:o.jsx("span",{className:"sd-core-fill",style:{transform:`scaleY(${Math.max(2,l)/100})`}})},c))})}),n&&o.jsxs(Iu,{group:"load",title:"Load history",action:"Show load history",label:"Load average",hint:"the queue for the cores, counted in tasks rather than as a share of them",children:[o.jsx("div",{className:"sd-figs",title:"The queue for this machine's cores, averaged over one, five and fifteen minutes. A count of tasks, not a share of the CPU.",children:n.map((l,c)=>o.jsx(L0,{value:l.toFixed(2),cap:["1m","5m","15m"][c]},c))}),n[0]>r&&o.jsx("div",{className:"sd-note",children:`${(n[0]/r).toFixed(1)}× more work queued than cores to run it`})]})]})}function lB({memory:e,swap:t,platform:n}){const r=e.total-e.available,s=n==="win32"?"Commit":"Swap",l=t&&t.total>0?t.used/t.total*100:0;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Memory",children:o.jsxs(Iu,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[o.jsx(rf,{label:"Physical",value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:au(r)})," of ",au(e.total)]}),pct:e.usedPct,tone:e.usedPct>=90?"warn":"calm",note:`${au(e.available)} available`}),t&&t.total>0&&o.jsx(rf,{label:s,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:au(t.used)})," of ",au(t.total)]}),pct:l,tone:l>=90?"warn":"calm"})]})})}function cB({network:e}){const{down:t,up:n,api:r,route:s}=e,[l,c]=w.useState(!1),u=r&&r.ms!=null?If(r.ms):null,f=t!=null&&n!=null;return o.jsxs("div",{className:"sd-section",role:"group","aria-label":"Network",children:[o.jsxs(Iu,{group:"network",title:"Network history",action:"Show network history",label:"Network",children:[(f||u)&&o.jsxs("div",{className:"sd-figs sd-figs-named",children:[f&&[["Download",t],["Upload",n]].map(([p,h])=>{const m=Ob(h);return o.jsx(L0,{value:m.value,unit:m.unit,cap:p},p)}),u&&o.jsx(L0,{value:u.value,unit:u.unit,cap:"Claude API"})]}),!f&&o.jsx("div",{className:"sd-note",children:"measuring…"}),r&&r.ms==null&&o.jsx("div",{className:"sd-note sd-note-warn",children:"Can’t reach Claude"})]}),s&&o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:"sd-detail",id:"sd-conn","aria-expanded":l,"aria-haspopup":"dialog",onClick:()=>c(p=>!p),children:["Connection details",s.relay&&o.jsx("span",{className:"sd-route-relay",children:" · relayed"}),o.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),l&&o.jsx(dB,{route:s,api:r,onClose:()=>c(!1)})]})]})}function L0({value:e,unit:t,cap:n}){return t?o.jsxs("span",{className:"sd-fig",children:[o.jsx("span",{className:"sd-fig-cap",children:n}),o.jsxs("span",{className:"sd-fig-read",children:[o.jsx("b",{children:e})," ",o.jsx("span",{className:"sd-fig-unit",children:t})]})]}):o.jsxs("span",{className:"sd-fig",children:[o.jsx("b",{children:e}),o.jsx("span",{className:"sd-fig-cap",children:n})]})}function uB(e){return e.kind==="tailscale-exit"?e.node?`Tailscale exit node ${e.node}`:"a Tailscale exit node":e.kind==="tailscale"?"Tailscale":`${e.name?`${e.name} `:""}VPN${e.iface?` (${e.iface})`:""}`}function dB({route:e,api:t,onClose:n}){return o.jsxs(O0,{anchorId:"sd-conn",boundaryId:"system-panel",id:"sd-conn-pop",className:"sd-pop",role:"dialog",labelledBy:"sd-conn-title",onClose:n,children:[o.jsx("p",{className:"sd-pop-title",id:"sd-conn-title",children:"Connection"}),o.jsxs("dl",{className:"sd-pop-rows",children:[o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:e.to==="claude"?"Traffic to Claude":"Internet traffic"}),o.jsxs("dd",{children:["through ",uB(e)]})]}),e.relay&&o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Relay"}),o.jsxs("dd",{children:[o.jsx("span",{className:"sd-route-relay",children:e.relay})," — not a direct path, so every packet carries one more round trip than it has to"]})]}),t&&o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Round trip"}),o.jsx("dd",{children:t.ms==null?`${t.host} did not answer`:`${Mu(If(t.ms))} to open a connection to ${t.host}`})]}),o.jsxs("div",{className:"sd-pop-row",children:[o.jsx("dt",{children:"Throughput"}),o.jsx("dd",{children:"every interface on this machine, not this path alone"})]})]})]})}function Iu({group:e,title:t,action:n,label:r,value:s,hint:l,children:c}){const[u,f]=w.useState(!1);return o.jsxs(o.Fragment,{children:[o.jsxs("button",{type:"button",className:"sd-open",onClick:()=>f(!0),title:n,"aria-label":s==null?n:`${n}, now ${s}`,"aria-describedby":l?`sd-hint-${e}`:void 0,children:[o.jsxs("div",{className:"sd-h","aria-hidden":!0,children:[r," ",o.jsx("i",{className:"sd-row-more",children:"›"}),s!=null&&o.jsx("span",{className:"sd-h-val",children:s})]}),c]}),l&&o.jsx("span",{id:`sd-hint-${e}`,className:"vis-hidden",children:l}),u&&o.jsx(A8,{group:e,title:t,onClose:()=>f(!1)})]})}function hB({thermal:e}){if(!e)return null;const t=e.throttle?tB(e.throttle.speedLimit,e.heldBack):null;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:o.jsxs(Iu,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>o.jsx(rf,{label:n.label,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:n.celsius})," °C"]}),pct:n.celsius/n.critAt*100,mark:n.warnAt/n.critAt*100,tone:eB(n.celsius,n.warnAt,n.critAt),title:`bar runs 0–${n.critAt} °C · amber from ${n.warnAt} °C, red at ${n.critAt} °C`,trackLabel:`${n.celsius} °C on a bar that runs to ${n.critAt} °C, amber from ${n.warnAt} °C`},n.label)),t&&o.jsx(rf,{label:"Throttling",value:o.jsx("b",{children:t.value}),pct:t.pct,tone:t.tone,note:t.note})]})})}function fB({sys:e}){const[t,n]=w.useState(!1);return o.jsxs("div",{className:"sd-section sd-door-section",children:[o.jsx("button",{type:"button",className:"sd-open sd-door",onClick:()=>n(!0),"aria-label":"Show every process the deck is watching",children:o.jsxs("span",{className:"sd-door-plate",children:[o.jsxs("span",{className:"sd-door-name",children:["Busiest processes",o.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),o.jsx("span",{className:"sd-door-sub",children:"every process, with its command line"})]})}),t&&o.jsx(Q8,{sys:e,onClose:()=>n(!1)})]})}function rf({label:e,value:t,pct:n,tone:r="calm",note:s,mark:l,title:c,trackLabel:u}){return o.jsxs("div",{className:"sd-row",title:c,children:[o.jsxs("div",{className:"sd-row-head",children:[o.jsx("span",{className:"sd-row-label",children:e}),o.jsx("span",{className:"sd-row-val",children:t})]}),o.jsxs("span",{className:"sd-track",role:u?"img":void 0,"aria-label":u,children:[o.jsx("span",{className:`sd-fill${r==="calm"?"":` ${r}`}`,style:{transform:`scaleX(${n<=0?0:Math.max(1,Math.min(100,n))/100})`}}),l!=null&&l>0&&l<100&&o.jsx("span",{className:"sd-mark",style:{left:`${l}%`},"aria-hidden":!0})]}),s&&o.jsx("div",{className:"sd-note",children:s})]})}function pB(e){return{inputTokens:e.i,outputTokens:e.o,cacheReadTokens:e.cr,cacheCreateTokens:e.cc,cacheCreate1hTokens:e.c1h,cacheCreate5mTokens:e.c5m}}function FM(e){return e.i+e.o+e.cr+e.cc}function OS(e){let t=0;for(const n of Object.values(e))t+=FM(n);return t}function mB(e){const t=s=>typeof s=="number"&&Number.isFinite(s)?s:0,n=new Map,r=e&&Array.isArray(e.days)?e.days:[];for(const s of r){const l=typeof s.period=="string"?s.period:"",c=Array.isArray(s.modelBreakdowns)?s.modelBreakdowns:[];for(const u of c){const f=typeof u.modelName=="string"?u.modelName:"";if(!l||!/claude/i.test(f)||u.missingPricing===!0)continue;const p=`${l}|${f}`,h=n.get(p),m=h?h.usage:{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0,cacheCreate1hTokens:0,cacheCreate5mTokens:0};m.inputTokens+=t(u.inputTokens),m.outputTokens+=t(u.outputTokens),m.cacheReadTokens+=t(u.cacheReadTokens),m.cacheCreateTokens+=t(u.cacheCreationTokens),h?h.cost+=t(u.cost):n.set(p,{cost:t(u.cost),usage:m})}}return n}function gB(e,t,n,r=Date.now()){const s=new Map;let l=0,c=0;for(const[R,I]of n){const $=R.indexOf("|"),q=R.slice(0,$),B=R.slice($+1),P=Cu(I.usage,B,r).total;if(!(P>0&&I.cost>0))continue;l+=I.cost,c+=P;let W=s.get(q);W||(W=new Map,s.set(q,W)),W.set(B,I.cost/P)}const u=c>0,f=(R,I)=>{const $=s.get(R);return($==null?void 0:$.get(I))??($==null?void 0:$.get(nc(I)))??1},p=new Set,h=(R,I)=>{let $=0,q=0;for(const[B,P]of Object.entries(R)){if(Ni(B,r)){$+=Cu(pB(P),B,r).total*I(B);continue}const W=FM(P);W>0&&(q+=W,p.add(B))}return{cost:$,unpriced:q}},m=new Map,y=[];for(const R of e){const I=new Map,$=new Map;let q=0;for(const B of R.projects){const{cost:P,unpriced:W}=h(B.models,ee=>f(R.day,ee));I.set(B.path,(I.get(B.path)??0)+P),W>0&&$.set(B.path,($.get(B.path)??0)+W),q+=P;let ne=m.get(B.path);ne||(ne={path:B.path,cost:0,tokens:0,unpricedTokens:0},m.set(B.path,ne)),ne.cost+=P,ne.tokens+=OS(B.models),ne.unpricedTokens+=W}y.push({day:R.day,total:q,byPath:I,unpricedByPath:$})}const v=[...m.values()].sort((R,I)=>I.cost-R.cost||I.tokens-R.tokens),S=v.reduce((R,I)=>R+I.cost,0),b=v.reduce((R,I)=>R+I.tokens,0),_=v.reduce((R,I)=>R+I.unpricedTokens,0),k=u?l/c:1,j=t?OS(t):0,E=t?h(t,()=>k):{cost:0,unpriced:0},C=E.cost>0||j>0?{cost:E.cost,tokens:j,unpricedTokens:E.unpriced}:null;return{projects:v,totalCost:S,totalTokens:b,unpricedTokens:_,perDay:y,unattributed:C,unpricedModels:[...p].sort(),calibrated:u,reconciled:u&&_===0}}function Ls(e,t,n=bt){return t>0?e>0?`${n(e)}+`:la:n(e)}function jl(e){return e>0?`${Pt(e)} of these tokens are on an unpriced model, so this is a floor`:void 0}function yB(e){if(e.length===0)return null;const t=e.length===1,n=t?e[0]:`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`;return t?`${n} is ${la}: this build holds no published rate for it, so its tokens are counted and its dollars are not.`:`${n} are ${la}: this build holds no published rate for them, so their tokens are counted and their dollars are not.`}const wB={phase:"running"},vB={phase:"failed"},xB={gen:0,report:null,error:null,early:null};function bB(e,t){var n,r;if(t.type!=="start"&&t.gen!==e.gen)return e;switch(t.type){case"start":return{...e,gen:t.gen,error:null,early:null};case"report":{const s=((n=e.early)==null?void 0:n.gen)===t.gen?e.early.cost:wB;return{...e,report:{gen:t.gen,days:t.days,data:t.data,cost:s},early:null}}case"reportFailed":return{...e,report:null,error:t.message,early:null};case"cost":return((r=e.report)==null?void 0:r.gen)===t.gen?{...e,report:{...e.report,cost:t.cost}}:{...e,early:{gen:t.gen,cost:t.cost}}}}function kB(e){var t;return((t=e.report)==null?void 0:t.gen)!==e.gen&&e.error===null}function NB(e){const t=e;return t&&t.ok!==!1?{phase:"ready",range:t}:vB}function LS(e){return`${e.getFullYear()}${String(e.getMonth()+1).padStart(2,"0")}${String(e.getDate()).padStart(2,"0")}`}function SB(e,t,n=Date.now()){const r=t===0?60:t,s=LS(new Date(n-(r-1)*864e5)),l=LS(new Date(n));return{report:`/api/account-projects?num=${e}&days=${t}`,ccusage:`/api/ccusage?since=${s}&until=${l}`}}function jB({num:e,days:t,gen:n,dispatch:r,get:s=(c,u)=>fetch(c,u),now:l=Date.now()}){const c=SB(e,t,l),u={credentials:"same-origin"};s(c.report,u).then(f=>f.ok?f.json():Promise.reject(new Error(`HTTP ${f.status}`))).then(f=>r({type:"report",gen:n,days:t,data:f}),f=>r({type:"reportFailed",gen:n,message:(f==null?void 0:f.message)||"Could not load"})),s(c.ccusage,u).then(f=>f.ok?f.json():null).catch(()=>null).then(f=>r({type:"cost",gen:n,cost:NB(f)}))}function qM(e){return/^[A-Za-z]:[\\/]$/.test(e)?e:e.replace(/[\\/]+$/,"")}function Cm(e){const t=qM(e).replace(/\\/g,"/");return/^[A-Za-z]:\//.test(t)?t.toLowerCase():t}function PS(e){if(!e)return e;const t=qM(e),n=t.match(/^\/(?:Users|home)\/[^/]+(\/.*)?$/);if(n)return`~${n[1]??""}`;const r=t.replace(/\\/g,"/").match(/^[A-Za-z]:\/Users\/[^/]+(\/.*)?$/i);return r?`~${r[1]??""}`:t.replace(/\\/g,"/")}function _B(e,t){const n=Cm(e);let r;for(const s of t){const l=Cm(s.path);!l||l===n||!n.startsWith(`${l}/`)||(!r||Cm(r.path).length<l.length)&&(r=s)}return r==null?void 0:r.label}function P0(e){return e===0?"all time":e===1?"today":`the last ${e} days`}function EB(e){return e===1?"No work attributed to this account yet today.":`No work attributed to this account in ${P0(e)}.`}function CB(e){return e===1?7:e===7?30:e===30?0:null}function TB(e,t){return e!==1&&t>0}const RB=[{days:1,label:"Today"},{days:7,label:"7d"},{days:30,label:"30d"},{days:0,label:"All"}],_l=["var(--usage-blue)","var(--usage-green)","var(--usage-amber)","var(--usage-purple)","var(--usage-indigo)","var(--usage-red)","var(--usage-orange)","var(--usage-zinc)"],AB="var(--usage-zinc)",Tm=6,MB=1600;function IB(e){const t=bt(e),n=/^\$(\d{4,})$/.exec(t);return n?`$${Number(n[1]).toLocaleString("en-US")}`:t}function bh(e,t){if(t<=0||e<=0)return"0%";const n=e/t*100;return n<.01?"<0.01%":n<1?`${n.toFixed(2)}%`:n<10?`${n.toFixed(1)}%`:`${Math.round(n)}%`}function $B(e){const t=/^\d{4}-(\d{2})-(\d{2})$/.exec(e);return t?`${Number(t[1])}/${Number(t[2])}`:e}function OB(e){const t=Math.max(1,Math.ceil(e/6));return n=>n===0||n===e-1||n%t===0}function Rm(e){if(!e)return"";try{return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return""}}function LB({num:e,name:t,onClose:n}){var X,V,G,F;const[r,s]=w.useState(1),[l,c]=w.useReducer(bB,xB),u=((X=l.report)==null?void 0:X.data)??null,f=((V=l.report)==null?void 0:V.days)??r,p=((G=l.report)==null?void 0:G.cost.phase)==="ready"?l.report.cost.range:null,h=((F=l.report)==null?void 0:F.cost.phase)==="running",[m,y]=w.useState(null),[v,S]=w.useState(()=>new Set),b=kB(l),_=l.error,[k,j]=w.useState(null),E=w.useRef(void 0),C=w.useRef(!0);w.useEffect(()=>()=>{C.current=!1,window.clearTimeout(E.current)},[]);const R=w.useRef(null),I=mn(n,{focusRef:R}),$=w.useRef(0);w.useEffect(()=>{const L=++$.current;c({type:"start",gen:L}),y(null),S(new Set),jB({num:e,days:r,gen:L,dispatch:c})},[e,r]);const q=w.useMemo(()=>{const L=Date.now();if(!u)return null;const H=gB(u.daily??[],u.unattributed,mB(p),L),D=ce=>ce.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||ce||"(unknown)",K=new Map;for(const ce of H.projects)K.set(D(ce.path),(K.get(D(ce.path))??0)+1);const re=ce=>{const se=D(ce);if((K.get(se)??0)<=1)return se;const be=ce.replace(/[\\/]+$/,"").split(/[\\/]/).slice(-2,-1)[0];return be?`${be}/${se}`:se},z=H.projects.map(ce=>({path:ce.path,label:re(ce.path)})),Z=ce=>({path:ce.path,label:re(ce.path),parentLabel:_B(ce.path,z),cost:ce.cost,tokens:ce.tokens,unpricedTokens:ce.unpricedTokens}),U=_l[Tm%_l.length],ae=new Map,le=[],ge=H.projects.slice(0,Tm),Ne=H.projects.slice(Tm);ge.forEach((ce,se)=>{ae.set(ce.path,_l[se%_l.length]),le.push({key:ce.path,...Z(ce),color:_l[se%_l.length]})}),Ne.length&&le.push({key:"__other__",label:`Other · ${Ne.length} project${Ne.length>1?"s":""}`,cost:Ne.reduce((ce,se)=>ce+se.cost,0),tokens:Ne.reduce((ce,se)=>ce+se.tokens,0),unpricedTokens:Ne.reduce((ce,se)=>ce+se.unpricedTokens,0),color:U,muted:!0,members:Ne.map(Z)});const Ie=H.totalCost,Ge=H.totalTokens,Pe=Ie>0&&H.unpricedTokens===0?"cost":"tokens",ze=Pe==="cost"?Ie:Ge,Re=le.map(ce=>ce.color),st=H.perDay.map(ce=>{const se=new Map;for(const[de,fe]of ce.byPath){const Ce=ae.get(de)??U;se.set(Ce,(se.get(Ce)??0)+fe)}const be=new Map;let Le=0;for(const[de,fe]of ce.unpricedByPath){const Ce=ae.get(de)??U;be.set(Ce,(be.get(Ce)??0)+fe),Le+=fe}return{day:ce.day,total:ce.total,costByColor:se,unpricedByColor:be,unpriced:Le}}),ue=st.reduce((ce,se)=>Math.max(ce,se.total),0);return{rows:le,totalCost:Ie,totalTokens:Ge,basis:Pe,denom:ze,un:H.unattributed,chart:st,maxDay:ue,colorOrder:Re,unpricedTokens:H.unpricedTokens,unpricedNote:yB(H.unpricedModels),calibrated:H.calibrated,reconciled:H.reconciled}},[u,p]),B=(L,H)=>{yi(L).then(D=>{C.current&&(window.clearTimeout(E.current),j({path:L,label:H,ok:D}),E.current=window.setTimeout(()=>{C.current&&j(null)},MB))})},P=L=>k!=null&&k.ok&&k.path===L?"Copied":"Copy",W=u!=null&&u.trackedSince?`Tracked since ${Rm(u.trackedSince)}`:"Tracking starts with this version",ne=P0(f),ee=CB(f),M=b&&!!u;return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:I,className:"modal ap-proj-modal",onClick:L=>L.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"ap-proj-title ap-proj-sub",children:[o.jsxs("header",{className:"ap-proj-head",children:[o.jsxs("div",{className:"ap-proj-titlewrap",children:[o.jsx("div",{className:"ap-proj-title",id:"ap-proj-title",children:"Projects"}),o.jsx("div",{className:"ap-proj-sub",id:"ap-proj-sub",title:t,children:t})]}),o.jsx("div",{className:"uh-range",role:"group","aria-label":"Range",children:RB.map(L=>o.jsx("button",{type:"button",className:"uh-range-btn","aria-pressed":r===L.days,onClick:()=>s(L.days),children:L.label},L.days))}),o.jsx("button",{ref:R,className:"glyph-btn ap-proj-close",onClick:n,"aria-label":"Close",children:"×"})]}),o.jsxs("div",{className:`ap-proj-body${M?" refreshing":""}`,"aria-busy":b,children:[b&&!u&&o.jsx("div",{className:"ap-proj-state",children:"Loading…"}),!b&&_&&o.jsxs("div",{className:"ap-proj-state ap-proj-error",children:["Couldn’t load this report: ",_]}),!_&&q&&o.jsx(o.Fragment,{children:q.rows.length===0?o.jsxs("div",{className:"ap-proj-state",children:[EB(f),ee!=null&&o.jsx("div",{className:"ap-proj-widen-wrap",children:o.jsxs("button",{type:"button",className:"ap-proj-copy",onClick:()=>s(ee),children:["Show ",P0(ee)]})}),o.jsxs("div",{className:"ap-proj-note",children:[W,". Only work from this version onward can be tied to an account."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"ap-proj-bar",role:"img","aria-label":q.basis==="cost"?`Share of ${bt(q.totalCost)} across ${q.rows.length} projects`:`Share of ${Pt(q.totalTokens)} tokens across ${q.rows.length} projects`,children:q.rows.map(L=>{const H=q.basis==="cost"?L.cost:L.tokens,D=q.denom>0?H/q.denom*100:0;if(D<=0)return null;const K=q.basis==="cost"?bh(L.cost,q.totalCost):`${bh(L.tokens,q.totalTokens)} of tokens`;return o.jsx("span",{className:"ap-proj-seg",style:{width:`${D}%`,background:L.color},title:`${L.label} · ${Ls(L.cost,L.unpricedTokens)} · ${K}${L.tokens?` · ${Pt(L.tokens)} tokens`:""}`},L.key)})}),o.jsxs("div",{className:"ap-proj-totals",children:[o.jsx("span",{className:"ap-proj-total-cost",title:jl(q.unpricedTokens),children:Ls(q.totalCost,q.unpricedTokens)}),o.jsxs("span",{className:"ap-proj-total-tok",children:[Pt(q.totalTokens)," tokens"]}),o.jsxs("span",{className:"ap-proj-total-win",children:["· ",ne]}),h&&o.jsx("span",{className:"ap-proj-total-pending",children:"Reconciling cost…"})]}),q.unpricedNote&&o.jsx("div",{className:"ap-proj-note",children:q.unpricedNote}),TB(f,q.chart.length)&&o.jsxs("div",{className:"ap-proj-days",children:[o.jsxs("div",{className:"ap-proj-days-cap",children:["By day",q.chart.length>1?" · click a bar":""]}),o.jsx("div",{className:"ap-proj-days-plot",role:"img","aria-label":`Spend across ${q.chart.length} day${q.chart.length>1?"s":""}`,children:q.chart.map(L=>{const H=q.maxDay>0?L.total/q.maxDay*100:0,D=m===L.day,K=q.rows.map(z=>({label:z.label,c:L.costByColor.get(z.color)??0,u:L.unpricedByColor.get(z.color)??0})).filter(z=>z.c>0||z.u>0),re=`${Rm(Date.parse(`${L.day}T00:00:00`))}, ${Ls(L.total,L.unpriced)}. ${K.map(z=>`${z.label} ${Ls(z.c,z.u)}`).join(", ")}`;return o.jsx("button",{type:"button",className:`ap-proj-day${D?" selected":""}`,"aria-pressed":D,"aria-label":re,title:`${L.day} · ${Ls(L.total,L.unpriced)}`,onClick:()=>y(z=>z===L.day?null:L.day),children:o.jsx("span",{className:"ap-proj-col",style:{height:`${H}%`},children:q.colorOrder.map((z,Z)=>{const U=L.costByColor.get(z)??0;return U<=0||L.total<=0?null:o.jsx("span",{className:"ap-proj-colseg",style:{height:`${U/L.total*100}%`,background:z}},Z)})})},L.day)})}),(()=>{const L=OB(q.chart.length);return o.jsx("div",{className:"ap-proj-days-axis","aria-hidden":"true",children:q.chart.map((H,D)=>o.jsx("div",{className:"ap-proj-axis-cell",children:L(D)?$B(H.day):""},H.day))})})(),(()=>{const L=m?q.chart.find(D=>D.day===m):null;if(!L)return null;const H=q.rows.map(D=>({r:D,c:L.costByColor.get(D.color)??0,u:L.unpricedByColor.get(D.color)??0})).filter(D=>D.c>0||D.u>0);return o.jsxs("div",{className:"ap-proj-day-detail",children:[o.jsxs("div",{className:"ap-proj-day-detail-head",children:[o.jsx("span",{children:Rm(Date.parse(`${L.day}T00:00:00`))}),o.jsx("span",{className:"ap-proj-day-detail-total",title:jl(L.unpriced),children:Ls(L.total,L.unpriced)})]}),H.map(({r:D,c:K,u:re})=>o.jsxs("div",{className:"ap-proj-day-detail-row",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:D.color},"aria-hidden":"true"}),o.jsx("span",{className:"ap-proj-day-detail-name",children:D.label}),o.jsx("span",{className:"ap-proj-day-detail-cost",title:jl(re),children:Ls(K,re)})]},D.key))]})})()]}),o.jsx("ul",{className:"ap-proj-list",children:q.rows.map((L,H)=>{const D=q.basis==="cost"?L.cost:L.tokens,K=q.denom>0?D/q.denom*100:0,re=v.has(L.key),z=`ap-proj-details-${H}`,Z=re&&(!!L.path||!!L.members),U=L.members?`${re?"Hide":"Show"} the ${L.members.length} project${L.members.length>1?"s":""} folded into Other`:`${re?"Hide":"Show"} location for ${L.label}`;return o.jsxs("li",{className:`ap-proj-row${L.muted?" muted":""}${re?" expanded":""}`,children:[o.jsx("span",{className:"ap-proj-dot",style:{background:L.color},"aria-hidden":"true"}),o.jsxs("span",{className:"ap-proj-name",children:[L.label,L.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",L.parentLabel]})]}),o.jsx("span",{className:"ap-proj-track",title:q.basis==="cost"?`${bh(L.cost,q.totalCost)} of tracked cost`:`${bh(L.tokens,q.totalTokens)} of tracked tokens`,children:o.jsx("span",{className:"ap-proj-fill",style:{width:`${K}%`,background:L.color}})}),o.jsx("span",{className:"ap-proj-cost",title:jl(L.unpricedTokens),children:Ls(L.cost,L.unpricedTokens)}),o.jsx("span",{className:"ap-proj-tok",children:Pt(L.tokens)}),o.jsx("button",{type:"button",className:"glyph-btn ap-proj-info","aria-expanded":re,"aria-controls":Z?z:void 0,"aria-label":U,onClick:()=>S(ae=>{const le=new Set(ae);return le.has(L.key)?le.delete(L.key):le.add(L.key),le}),children:"ⓘ"}),re&&L.path&&o.jsxs("div",{className:"ap-proj-details",id:z,children:[o.jsx("code",{className:"ap-proj-path",children:PS(L.path)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${P(L.path)} location for ${L.label}`,onClick:()=>B(L.path,L.label),children:P(L.path)})]}),re&&L.members&&o.jsx("div",{className:"ap-proj-details ap-proj-other-members",id:z,children:L.members.map(ae=>o.jsxs("div",{className:"ap-proj-other-member",children:[o.jsxs("div",{className:"ap-proj-other-name",children:[ae.label,ae.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",ae.parentLabel]})]}),o.jsx("code",{className:"ap-proj-path",children:PS(ae.path)}),o.jsx("span",{className:"ap-proj-cost",title:jl(ae.unpricedTokens),children:Ls(ae.cost,ae.unpricedTokens)}),o.jsx("span",{className:"ap-proj-tok",children:Pt(ae.tokens)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${P(ae.path)} location for ${ae.label}`,onClick:()=>B(ae.path,ae.label),children:P(ae.path)})]},ae.path))})]},L.key)})}),q.un&&o.jsxs("div",{className:"ap-proj-unattributed",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:AB},"aria-hidden":"true"}),o.jsxs("div",{className:"ap-proj-un-labels",children:[o.jsx("span",{className:"ap-proj-un-title",children:"Unattributed usage"}),o.jsx("span",{className:"ap-proj-un-tag",children:"Excluded from the project totals"})]}),o.jsx("span",{className:"ap-proj-un-cost",title:jl(q.un.unpricedTokens),children:Ls(q.un.cost,q.un.unpricedTokens,IB)}),o.jsx("span",{className:"ap-proj-un-tok",children:Pt(q.un.tokens)}),o.jsx("div",{className:"ap-proj-note",children:"Work no account could be tied to — from before tracking, or a gap."})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:k&&(k.ok?`Copied the location of ${k.label}`:`Could not copy the location of ${k.label} — select it and copy it by hand`)}),o.jsxs("div",{className:"ap-proj-foot",children:[h?"Dollars estimated · ccusage still running":q.reconciled?"Dollars from ccusage · split by activity":q.calibrated?"Dollars from ccusage for the priced models · split by activity":p?"Dollars estimated · ccusage could not price this window":"Dollars estimated · ccusage unavailable"," · ",W]})]})})]})]})}),document.body)}const DS=18,PB=1100,El=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},DB=Array.from({length:DS},(e,t)=>{const n=-72+144*t/(DS-1)+(El(t,1)-.5)*9,r=(n-90)*(Math.PI/180),s=(54+32*Math.cos(n*Math.PI/180))*(.74+El(t,2)*.52);return{dx:Math.cos(r)*s,dy:Math.sin(r)*s,rot:(t%2?1:-1)*(100+El(t,3)*260),delay:Math.round(El(t,4)*90),dur:760+Math.round(El(t,5)*260),scale:.8+El(t,6)*.45,hue:t%4,round:t%3===0}});function FS({anchor:e}){var s;const[t,n]=w.useState(null),r=typeof window<"u"&&((s=window.matchMedia)==null?void 0:s.call(window,"(prefers-reduced-motion: reduce)").matches);return w.useEffect(()=>{if(r)return;const l=e.current;if(!l)return;const c=l.getBoundingClientRect();n({x:c.left+c.width/2,y:c.top+c.height/2});const u=window.setTimeout(()=>n(null),PB);return()=>window.clearTimeout(u)},[e,r]),r||!t?null:On.createPortal(o.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:DB.map((l,c)=>o.jsx("span",{className:`confetti-bit${l.round?" round":""}`,"data-hue":l.hue,style:{"--dx":`${l.dx.toFixed(1)}px`,"--dy":`${l.dy.toFixed(1)}px`,"--rot":`${l.rot}deg`,"--s":l.scale.toFixed(2),animationDelay:`${l.delay}ms`,animationDuration:`${l.dur}ms, ${l.dur}ms`}},c))}),document.body)}const BM=new Set(["awaiting_url","awaiting_code","registering"]);function FB(e){return e!=null&&BM.has(e)}function zM(e){return e!=null&&e!=="done"&&!BM.has(e)}const qB="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",BB="the sign-in did not complete";function zB({state:e,serverError:t,localError:n}){const r=e==="idle";return{title:r?"Sign-in ended":"Sign-in failed",message:n||t||(r?qB:BB)}}function UB({restored:e,activeAccount:t}){if(e!==!1)return null;const n=(t==null?void 0:t.email)||((t==null?void 0:t.num)!=null?`account ${t.num}`:null);return n?`This machine is now signed in as ${n} — the account you were using could not be put back. Switch back from the accounts panel.`:"The account you were using could not be put back — check which account this machine is signed in as from the accounts panel."}function HB({started:e,state:t}){return!e||t==="done"?null:{action:"login-cancel"}}const WB="done";function VB(){let e=!1;return{shouldAnnounce(t){return t!==WB?(e=!1,!1):e?!1:(e=!0,!0)}}}function Db(e,t){return t&&Object.hasOwn(e,t)?e[t]:void 0}const GB={already_running:"a sign-in is already in progress",no_url:"the claude CLI did not offer a sign-in link — is it installed?",not_waiting:"that sign-in is no longer waiting for a code",not_prompted:"the CLI has not asked for a code yet",code_rejected:"that code was not accepted — copy it again from the browser",no_verdict:"the claude CLI has not answered — try the code again",empty_code:"paste the code from the browser first",login_failed:"the code was not accepted",no_identity:"signed in, but the CLI still reports nobody logged in",add_failed:"signed in, but claude-swap could not record the account",not_a_share:"that does not look like a shared account — it should start with ccdeck2:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:`that share was made by a newer ${hn}`,expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import",unreadable_export:"claude-swap wrote something this deck could not read — try again, and upgrade it if this repeats",mixed_versions:"claude-swap changed format part-way through — try again",nothing_to_share:"none of those accounts could be exported",too_many:"that is more accounts than one share can carry",not_in_bundle:"that account is not in this share",bad_value:"an alias can only use letters, numbers, spaces, dots, dashes and underscores, up to 64 characters, and cannot start with a dash",bad_email:"that does not look like an email address — it cannot contain spaces or start with a dash"},KB={no_cswap:"claude-swap could not be run — it is not on this deck's PATH. Set AGENTS_DECK_CSWAP to its full path",timeout:"claude-swap took too long and was stopped — try again",switch_failed:"claude-swap refused the switch",bad_account:"that is not an account claude-swap has",unknown_setting:"claude-swap has no such setting",out_of_range:"that value is outside what the setting allows",bad_value:"claude-swap does not accept that value",set_failed:"claude-swap refused the change",command_failed:"claude-swap refused the command"},Fb=`claude-swap could not read the login keychain — start ${hn} from a Terminal window rather than a background service`,qS={unreadable_here:{short:"Keychain locked on this Mac",long:`${Fb}.`},no_credentials_here:{short:"no stored login here",long:"claude-swap still holds no login for it here."},relogin_required_here:{short:"login expired",long:"the imported login was rejected — sign in again on a deck where it still works."},unverified_here:{short:"not checked",long:"claude-swap could not confirm whether this Mac can read it."}};function sf(e){return e&&Object.hasOwn(qS,e)?qS[e]:null}const UM={401:"this deck did not accept the page as its own, so nothing was changed",403:"this deck refused a change from this address — open it on the address the deck prints, not through a proxy"};function D0(e,t,n){const r=n==null?null:UM[n];if(r)return r;if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test($u(e)))return Fb;const s=Db(KB,e==null?void 0:e.reason);return s||(e==null?void 0:e.reason)||t}function $u(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const YB={no_install:"ccusage is not installed, and AGENTS_DECK_NO_INSTALL=1 forbids fetching it — unset that variable and restart the deck, or install ccusage yourself so it is on this deck's PATH",bad_override:"AGENTS_DECK_CCUSAGE names a file that is not there — correct it to the full path of your ccusage, or unset it to let the deck find its own",timeout:"ccusage took more than 90 seconds and was stopped — a narrower range usually finishes",bad_output:"ccusage ran but printed no usage data — try again, and run ccusage daily --json in a terminal if it keeps happening",run_failed:"ccusage could not report usage — try again",bad_range:"that date range is not a YYYYMMDD date — reopen the modal and pick one of the presets",unreachable:"the deck did not answer — check it is still running, then try again"},XB="ccusage could not be started — npx is not on this deck's PATH. Install Node's npm/npx, or put ccusage on PATH yourself";function ZB(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const QB="ccusage could not be started — the deck launched npx and Node could not load the npm script it points at. An older deck asked cmd.exe for a bare npx.cmd, which made the shim look for that script under the deck's working directory instead of beside itself; update the deck and reopen this modal",JB="ccusage could not be started — the copy npx fetched will not load: Node could not resolve a file inside it. That copy is in npx's own cache, which the deck never rewrites, so clear it with `npm cache clean --force` and reopen this modal",ez=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),tz=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,nz=/[\\/]_npx[\\/]/i,rz=`the copy of ccusage ${hn} installed for itself`;function sz(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function fZ(e,t){const n=az(e,t),r=sz(e);switch(e==null?void 0:e.stage){case"npx":return r?`ccusage failed on both of its paths. The managed install failed first — ${r} — and the deck then fell back to npx, where ${ou(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${ou(n)}`;case"managed":return`${rz} failed to run: ${ou(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${ou(n)}`:`the ccusage this deck found on your PATH failed to run: ${ou(n)}`;default:return n}}const ou=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function az(e,t){const n=$u(e);if(ez(n)){if(nz.test(n))return JB;if(tz.test(n))return QB}if(ZB(n))return XB;const r=Db(YB,e==null?void 0:e.reason);return r||(e==null?void 0:e.reason)||t}function Ol(e,t,n){const r=n==null?null:UM[n];if(r)return r;if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&zM(e.state))return e.error;const s=Db(GB,e==null?void 0:e.reason);return s||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function oz(e,t,n){if(n<=0||_f(e))return{kind:"pass"};const r=t>=0&&t<n?t:-1;switch(e.key){case"ArrowRight":return{kind:"select",index:r===-1?0:(r+1)%n};case"ArrowLeft":return{kind:"select",index:r===-1?n-1:(r-1+n)%n};case"Home":return{kind:"select",index:0};case"End":return{kind:"select",index:n-1};default:return{kind:"pass"}}}function HM(e,t){const n=Math.round(e/1e3)-t;return n<=0?{text:"expired",tone:"gone"}:n<60?{text:`expires in ${n}s`,tone:"soon"}:{text:`expires in ${Math.round(n/60)}m`,tone:"ok"}}function iz(e){const t=new Map;for(const n of e){const r=(n.email??"").trim().toLowerCase();r&&t.set(r,(t.get(r)??0)+1)}return e.map(n=>{const r=(n.email??"").trim(),s=n.alias||r||`account ${n.num}`,l=[];return n.alias&&r&&l.push(r),r&&(t.get(r.toLowerCase())??0)>1&&l.push(n.org||`slot ${n.num}`),{num:n.num,label:s,sub:l.length?l.join(" · "):null}})}function lz(e,t){return e.filter(n=>!t.includes(n.num)).map(n=>n.num)}function cz(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function uz(e){return e.length?{action:"share",accounts:[...e]}:null}function dz(e){return e<=0?"Nothing picked yet.":e===1?"1 account — its sign-in token will be on your clipboard.":`${e} accounts — ${e} sign-in tokens will be on your clipboard.`}function F0(e){return`${e.email}|${e.org??""}`}function hz(e,t,n){return e&&e.map(r=>F0(r)===t?n:r)}function fz(e){switch(e){case"imported":return"imported";case"healed":return"dead token replaced";case"updated":return"updated";case"present":return"already here";default:return"not imported"}}function pz(e){const t=e.length;if(!t)return"Nothing to import.";const n=h=>e.filter(m=>m.state===h).length,r=[],s=n("imported");s&&r.push(`${s} of ${t} imported`);const l=n("healed");l&&r.push(`${l} had a dead token replaced`);const c=n("updated");c&&r.push(`${c} updated`);const u=n("present");u&&r.push(`${u} already here`);const f=n("failed");f&&r.push(`${f} did not arrive`);const p=[...new Set(e.map(h=>{var m;return(m=sf(h.check))==null?void 0:m.short}).filter(h=>!!h))];return`${r.join(", ")}${p.length?`, ${p.join(", ")}`:""}.`}const mz=1500,kh=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],BS="aa-panel",zS=e=>`aa-tab-${e}`;async function iu(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const q0=ve.forwardRef((e,t)=>o.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:t,children:[o.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),o.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));q0.displayName="SuccessMark";function gz({onClose:e,onChanged:t}){const[n,r]=w.useState("login"),[s,l]=w.useState(null),[c,u]=w.useState(""),[f,p]=w.useState(""),[h,m]=w.useState(!1),[y,v]=w.useState(null),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useRef(""),R=w.useRef(!1),I=w.useRef(!1),$=w.useRef(null),q=w.useRef(null),B=w.useRef(null),P=w.useRef(null),W=w.useRef([]),ne=w.useRef(!1),ee=w.useCallback(()=>{const U=HB({started:R.current,state:s==null?void 0:s.state});U&&iu(U).catch(()=>{}),e()},[e,s==null?void 0:s.state]),M=mn(ee,{focusRef:B}),X=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null),R.current=!0;const U=await iu({action:"login"}).catch(()=>null);if(I.current=!1,m(!1),!(U!=null&&U.ok)){v(Ol(U,"could not start the sign-in"));return}l(U)},[]);w.useEffect(()=>{if(!FB(s==null?void 0:s.state))return;const U=window.setInterval(async()=>{try{const ae=await fetch("/api/claude-accounts/login");ae.ok&&l(await ae.json())}catch{}},mz);return()=>window.clearInterval(U)},[s]);const V=w.useRef(t);V.current=t;const G=w.useState(VB)[0];w.useEffect(()=>{var U;(s==null?void 0:s.state)==="awaiting_code"&&((U=$.current)==null||U.focus()),G.shouldAnnounce(s==null?void 0:s.state)&&V.current()},[s==null?void 0:s.state,G]),w.useEffect(()=>{var U;n==="paste"&&!ne.current&&((U=q.current)==null||U.focus()),ne.current=!1},[n]);const F=w.useCallback(U=>{var le;const ae=oz(U,kh.findIndex(ge=>ge.id===n),kh.length);ae.kind!=="pass"&&(U.preventDefault(),ne.current=!0,r(kh[ae.index].id),(le=W.current[ae.index])==null||le.focus())},[n]),L=w.useCallback(async()=>{var ae;if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const U=await iu({action:"login-code",code:c}).catch(()=>null);if(I.current=!1,m(!1),!(U!=null&&U.ok)){v(Ol(U,"the code was not accepted")),U!=null&&U.state&&l(U),(ae=$.current)==null||ae.select();return}u(""),l(U)},[c,s]),H=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const U=await iu({action:"import",blob:f}).catch(()=>null);if(I.current=!1,m(!1),!(U!=null&&U.ok)){v(Ol(U,"the import failed"));return}C.current=f,p(""),E(null),b(U.results??[]),t()},[f,t]),D=w.useCallback(async U=>{const ae=F0(U);if(!Ps(I.current)||!C.current)return;I.current=!0,m(!0),k(ae),E(null);const le=await iu({action:"import",blob:C.current,force:!0,only:{email:U.email,org:U.org??""}}).catch(()=>null);if(I.current=!1,m(!1),k(null),!(le!=null&&le.ok)){E({key:ae,text:Ol(le,"that account could not be updated")});return}const ge=(le.results??[])[0];ge&&b(Ne=>hz(Ne,ae,ge)),t()},[t]),K=(s==null?void 0:s.state)==="done"?s.account:null,re=UB({restored:s==null?void 0:s.restored,activeAccount:s==null?void 0:s.activeAccount}),z=zM(s==null?void 0:s.state)||!!(y&&R.current&&!h),Z=zB({state:s==null?void 0:s.state,serverError:s==null?void 0:s.error,localError:y});return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:ee,role:"presentation",children:o.jsxs("div",{ref:M,className:"modal aa-modal",onClick:U=>U.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{className:"aa-tabs",role:"tablist","aria-label":"How to add the account",onKeyDown:F,children:kh.map((U,ae)=>o.jsx("button",{type:"button",role:"tab",id:zS(U.id),ref:le=>{W.current[ae]=le},"aria-selected":n===U.id,"aria-controls":BS,tabIndex:n===U.id?0:-1,className:`aa-tab${n===U.id?" on":""}`,onClick:()=>{ne.current=!1,r(U.id)},children:U.label},U.id))})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:ee,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body aa-body",id:BS,role:"tabpanel","aria-labelledby":zS(n),children:n==="login"?K?o.jsxs("div",{className:"aa-done",children:[o.jsx(q0,{ref:P}),o.jsx(FS,{anchor:P}),o.jsx("h4",{children:K.added?`Account ${K.num} added`:"Credentials refreshed"}),o.jsxs("p",{className:"aa-note",children:[o.jsx("strong",{children:K.email}),K.added?re?" is in the rotation.":" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),re?o.jsx("p",{className:"aa-note aa-warn",role:"status",children:re}):null,o.jsx("button",{type:"button",className:"btn primary",onClick:ee,children:"Done"})]}):(s==null?void 0:s.state)==="awaiting_code"||(s==null?void 0:s.state)==="registering"?o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"1 · Approve in the browser"}),o.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),o.jsx("a",{className:"aa-link",href:s.url??"#",target:"_blank",rel:"noreferrer noopener",children:s.url})]}),o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"2 · Paste a code, if the page shows one"}),o.jsx("p",{className:"aa-note",children:"It usually finishes on its own — if the page says you are all set, there is nothing to do here."}),o.jsxs("div",{className:"aa-field",children:[o.jsx("input",{ref:$,type:"text",value:c,onChange:U=>u(U.target.value),onKeyDown:U=>{U.key==="Enter"&&c.trim()&&!h&&L()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:s.state==="registering"}),o.jsx("button",{type:"button",className:"btn primary",...to(h,!c.trim()||s.state==="registering"),onClick:L,children:s.state==="registering"?"registering…":"Continue"})]}),(y||s.error)&&o.jsx("p",{className:"aa-err",children:y??s.error}),o.jsx("p",{className:"aa-note",children:"The code goes straight to the claude CLI on this machine. It is never stored or sent anywhere else."})]})]}):z?o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:Z.title}),o.jsx("p",{className:"aa-err",children:Z.message}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{R.current=!1,l(null),v(null),X()},children:"Try again"})]}):h||R.current?o.jsx("div",{className:"aa-step",children:o.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):o.jsxs("div",{className:"aa-step aa-primer",children:[o.jsx("h4",{children:"Sign in to Anthropic"}),o.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in. It normally completes by itself; only if the page hands you a code does it need pasting back here. claude-swap records the account when it completes, and the account you are using now stays active."}),o.jsx("div",{className:"aa-actions",children:o.jsx("button",{type:"button",ref:B,className:"btn primary",onClick:X,children:"Open the sign-in page"})})]}):S?(()=>{const U=S.filter(le=>le.state==="imported").length,ae=S.some(le=>sf(le.check));return o.jsxs("div",{className:"aa-done",children:[!ae&&o.jsx(q0,{ref:P}),U>0&&!ae&&o.jsx(FS,{anchor:P}),o.jsx("h4",{children:pz(S)}),S.length>0&&o.jsx("ul",{className:"aa-results",children:S.map(le=>{const ge=F0(le),Ne=sf(le.check);return o.jsxs("li",{className:`aa-result ${le.state}`,children:[o.jsx("span",{className:"aa-result-who",children:le.email||(le.num?`slot ${le.num}`:"an account")}),o.jsx("span",{className:"aa-result-what",children:fz(le.state)}),le.state==="present"&&o.jsx("button",{type:"button",className:"aa-result-fix","aria-busy":_===ge,title:`Overwrite the stored login for ${le.email} with the one in this share. Do this when that account has stopped working here; if it works, leave it.`,onClick:()=>D(le),children:_===ge?"updating…":"update anyway"}),Ne&&o.jsx("span",{className:"aa-result-err",children:Ne.long}),(j==null?void 0:j.key)===ge&&o.jsx("span",{className:"aa-result-err",children:j.text})]},ge)})}),o.jsxs("p",{className:"aa-note",children:["Nothing changed on the deck you copied this from. An account already here is left as it is, unless its stored login was dead or you pressed",o.jsx("strong",{children:" update anyway"}),"."]}),o.jsxs("div",{className:"aa-actions",children:[o.jsx("button",{type:"button",className:"btn primary",onClick:ee,children:"Done"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{C.current="",E(null),b(null)},children:"Import another"})]})]})})():o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:"Paste an account shared from another deck"}),o.jsxs("div",{className:"aa-field",children:[o.jsx("input",{ref:q,type:"text",value:f,onChange:U=>p(U.target.value),onKeyDown:U=>{U.key==="Enter"&&f.trim()&&!h&&H()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),o.jsx("button",{type:"button",className:"btn primary",...to(h,!f.trim()),onClick:H,children:h?"importing…":"Import"})]}),y&&o.jsx("p",{className:"aa-err",children:y}),o.jsxs("p",{className:"aa-note",children:["Use ",o.jsx("strong",{children:"share"})," on one account in the other deck, or ",o.jsx("strong",{children:"↗"})," above its list to send several at once. A share carries a live login for every account in it and expires ten minutes after it is made."]})]})})]})}),document.body)}const yz=6;function wz(e,t){const n=e.filter(u=>u.ready);if(t.armed&&e.length>0&&n.length===0)return{text:"Auto-switch has nowhere to go",tone:"bad",free:null};const r=n.length===e.length?`${e.length} ready`:n.length===0?e.length===1?"not ready":`none of ${e.length} ready`:`${n.length} of ${e.length} ready`,s=n.length?"ok":"idle",l=t.strained&&!t.armed?vz(n):null,c=[r];return l!=null&&c.push(`${l}% free`),c.push(t.armed?`auto ${t.threshold??"on"}${t.threshold?"%":""}`:"auto off"),{text:c.join(" · "),tone:s,free:l}}function vz(e){const t=e.map(n=>n.headroom).filter(n=>typeof n=="number");return t.length?Math.max(...t):null}function xz(e){const t=[...e].sort((s,l)=>{if(s.ready!==l.ready)return s.ready?-1:1;if(!s.ready)return s.name.localeCompare(l.name);const c=s.headroom,u=l.headroom;return c==null&&u==null?s.name.localeCompare(l.name):c==null?1:u==null?-1:u-c}),n=t.slice(0,yz),r=t.length-n.length;return{title:e.some(s=>s.ready)?"Where you could switch":"Nothing to switch to",shown:n,rest:r>0?`and ${r} more`:null}}function WM({title:e,steps:t,finish:n,aside:r,onClose:s}){const l=w.useRef(null),c=mn(s,{focusRef:l}),[u,f]=w.useState(0),p=u===t.length-1,h=t[u],m=S=>f(Math.max(0,Math.min(t.length-1,S))),y=S=>{S.key!=="ArrowRight"&&S.key!=="ArrowLeft"||(S.preventDefault(),S.stopPropagation(),m(S.key==="ArrowRight"?u+1:u-1))},v=()=>{if(!p){m(u+1);return}n?n.act():s()};return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:s,role:"presentation",children:o.jsxs("div",{ref:c,className:"modal guide",onClick:S=>S.stopPropagation(),onKeyDown:y,role:"dialog","aria-modal":"true","aria-labelledby":"guide-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{id:"guide-title",className:"modal-tool-name",children:e}),o.jsxs("span",{className:"modal-tool-id",children:[u+1," / ",t.length]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:s,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsx("div",{className:"guide-stage",children:h.art},u),o.jsx("p",{className:"guide-line","aria-live":"polite",children:h.line}),o.jsx("p",{className:"guide-tip",children:h.tip??""}),o.jsxs("div",{className:"guide-foot",children:[o.jsx("div",{className:"guide-dots",children:t.map((S,b)=>o.jsx("button",{type:"button",className:"glyph-btn guide-dot","aria-label":`Step ${b+1} of ${t.length}`,"aria-current":b===u?"step":void 0,onClick:()=>m(b)},b))}),p&&r&&o.jsx("button",{type:"button",className:"ap-lan-word guide-aside",onClick:r.act,children:r.label}),u>0&&o.jsx("button",{type:"button",className:"btn",onClick:()=>m(u-1),children:"Back"}),o.jsx("button",{ref:l,type:"button",className:"btn primary",onClick:v,children:p?(n==null?void 0:n.label)??"Done":"Next"})]})]})]})}),document.body)}const B0={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function qr({children:e}){return o.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function Fr({x:e,y:t=34,w:n=176,h:r=132,label:s}){return o.jsxs(o.Fragment,{children:[s&&o.jsx("text",{x:e+2,y:t-9,className:"ga-cap",children:s}),o.jsx("rect",{x:e,y:t,width:n,height:r,rx:10,className:"ga-screen"})]})}function ws({x:e,y:t,email:n,state:r,tone:s,bars:l}){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{cx:e+3,cy:t-4,r:3,className:B0[s]}),o.jsx("text",{x:e+12,y:t,className:"ga-t ga-mono",children:n}),o.jsx("text",{x:e+12,y:t+16,className:`ga-s ${B0[s]}`,children:r}),l==null?void 0:l.map((c,u)=>o.jsxs("g",{children:[o.jsx("text",{x:e,y:t+40+u*18,className:"ga-s",children:u?"7d":"5h"}),o.jsx("rect",{x:e+22,y:t+35+u*18,width:96,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:e+22,y:t+35+u*18,width:96*c/100,height:4,rx:2,className:"ga-accent"}),o.jsxs("text",{x:e+148,y:t+40+u*18,className:"ga-s ga-accent",textAnchor:"end",children:[c,"%"]})]},u))]})}function VM({x:e,y:t,on:n}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:30,height:18,rx:9,className:n?"ga-switch-on":"ga-switch"}),o.jsx("circle",{cx:n?e+21:e+9,cy:t+9,r:6,className:n?"ga-knob-on":"ga-knob"})]})}function Nh({x:e,y:t,name:n,here:r=!0}){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{cx:e+3,cy:t-4,r:3,className:r?"ga-ok":"ga-dim"}),o.jsx("text",{x:e+12,y:t,className:r?"ga-t":"ga-s",children:n})]})}function US({x:e,y:t,on:n}){return n?o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:12,height:12,rx:3,className:"ga-accent"}),o.jsx("path",{d:`M${e+3} ${t+6.2}l2.3 2.3 4-4.6`,className:"ga-tick"})]}):o.jsx("rect",{x:e+.5,y:t+.5,width:11,height:11,rx:3,className:"ga-box"})}function HS({x:e,y:t,d:n}){return o.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function qb({x:e,y:t}){return o.jsx("path",{d:`M${e} ${t}l0 13 3.4-3 2.4 5.2 2-.9-2.4-5.1 4.6-.2z`,className:"ga-pointer"})}function Bb(){return o.jsxs(o.Fragment,{children:[o.jsx("circle",{r:9,className:"ga-key-bed"}),o.jsxs("g",{transform:"translate(-6 -6) scale(0.857)",className:"ga-key",children:[o.jsx("circle",{cx:4.6,cy:7,r:2.6}),o.jsx("path",{d:"M7.2 7h5.2M10.6 7v2.2M12.4 7v1.6"})]})]})}function Ll({x:e,y:t,w:n,title:r,sub:s,tone:l}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:n,height:40,rx:8,className:"ga-screen"}),o.jsx("rect",{x:e+6,y:t+10,width:3,height:20,rx:1.5,className:B0[l]}),o.jsx("text",{x:e+16,y:t+17,className:"ga-t ga-strong",children:r}),o.jsx("text",{x:e+16,y:t+31,className:"ga-s",children:s})]})}function Bl({x:e,y:t,label:n,live:r}){return o.jsxs(o.Fragment,{children:[o.jsx("rect",{x:e,y:t,width:46,height:20,rx:10,className:r?"ga-chip-live":"ga-chip"}),o.jsx("text",{x:e+23,y:t+14,className:"ga-s ga-mono",textAnchor:"middle",children:n})]})}function af({x:e,y:t}){return o.jsxs(o.Fragment,{children:[o.jsx("text",{x:e,y:t,className:"ga-cap",children:"LOCAL NETWORK"}),o.jsx(VM,{x:e+118,y:t-13,on:!0})]})}function bz(){return o.jsxs(qr,{children:[o.jsx("rect",{x:14,y:14,width:206,height:172,rx:10,className:"ga-screen"}),o.jsx("text",{x:28,y:38,className:"ga-t ga-strong",children:"Sessions"}),o.jsx("text",{x:206,y:38,className:"ga-s ga-warn",textAnchor:"end",children:"1 waiting"}),o.jsx("rect",{x:20,y:50,width:194,height:42,rx:6,className:"ga-bed-warn"}),o.jsx("circle",{cx:33,cy:64,r:7,className:"ga-ring-warn ga-ping"}),o.jsx("circle",{cx:33,cy:64,r:3.5,className:"ga-warn"}),o.jsx("text",{x:44,y:68,className:"ga-t",children:"api-server"}),o.jsx("text",{x:44,y:83,className:"ga-s ga-warn",children:"waiting 6m · Bash"}),o.jsx("circle",{cx:33,cy:108,r:3.5,className:"ga-flight"}),o.jsx("text",{x:44,y:112,className:"ga-t",children:"docs-site"}),o.jsx("text",{x:44,y:127,className:"ga-s",children:"running · 12 tools"}),o.jsx("circle",{cx:33,cy:150,r:3.5,className:"ga-ok"}),o.jsx("text",{x:44,y:154,className:"ga-t",children:"billing"}),o.jsx("text",{x:44,y:169,className:"ga-s",children:"done · $0.84"}),o.jsx("path",{d:"M216 71C234 71 230 100 244 100",className:"ga-arc"}),o.jsx("path",{d:"M239 96l5 4-5 4",className:"ga-arrow"}),o.jsx("rect",{x:248,y:44,width:178,height:112,rx:10,className:"ga-screen"}),o.jsx("text",{x:262,y:64,className:"ga-cap",children:"API-SERVER"}),o.jsx("line",{x1:248,y1:74,x2:426,y2:74,className:"ga-line"}),o.jsx("text",{x:262,y:96,className:"ga-s ga-mono",children:"Bash(npm test)"}),o.jsx("text",{x:262,y:116,className:"ga-t ga-mono ga-warn",children:"Allow this command?"}),o.jsx("text",{x:262,y:136,className:"ga-s ga-mono",children:"> 1. Yes 2. No"})]})}function kz(){return o.jsxs(qr,{children:[o.jsx("path",{d:"M136 100C166 100 166 38 196 38",className:"ga-edge ga-flow"}),o.jsx("path",{d:"M136 100H196",className:"ga-edge ga-flow"}),o.jsx("path",{d:"M136 100C166 100 166 162 196 162",className:"ga-edge-done"}),o.jsx("path",{d:"M308 38H326M308 100H326",className:"ga-edge"}),o.jsx(Ll,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),o.jsx(Ll,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),o.jsx(Ll,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),o.jsx(Ll,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),o.jsx(Bl,{x:326,y:28,label:"Read"}),o.jsx(Bl,{x:380,y:28,label:"Grep",live:!0}),o.jsx(Bl,{x:326,y:90,label:"Bash",live:!0})]})}function WS({x:e,y:t,label:n,pct:r,note:s}){return o.jsxs(o.Fragment,{children:[o.jsx("text",{x:e,y:t,className:"ga-s",children:n}),o.jsxs("text",{x:e+194,y:t,className:"ga-s ga-accent",textAnchor:"end",children:[r,"%"]}),o.jsx("rect",{x:e,y:t+7,width:194,height:5,rx:2.5,className:"ga-track"}),o.jsx("rect",{x:e,y:t+7,width:194*r/100,height:5,rx:2.5,className:"ga-accent"}),o.jsx("text",{x:e,y:t+26,className:"ga-s",children:s})]})}function Nz(){return o.jsxs(qr,{children:[o.jsx("rect",{x:14,y:30,width:172,height:140,rx:10,className:"ga-screen"}),o.jsx("text",{x:30,y:56,className:"ga-cap",children:"THIS SESSION"}),o.jsx("text",{x:30,y:98,className:"ga-big",children:"$3.66"}),o.jsx("text",{x:30,y:122,className:"ga-s",children:"Opus 5 · 1.2M tokens"}),o.jsx("text",{x:30,y:150,className:"ga-s",children:"$21.40 today"}),o.jsx("rect",{x:200,y:30,width:226,height:140,rx:10,className:"ga-screen"}),o.jsx("text",{x:216,y:56,className:"ga-cap",children:"CLAUDE QUOTA"}),o.jsx(WS,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),o.jsx(WS,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function Sz(){return o.jsxs(qr,{children:[o.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),o.jsx(Ll,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),o.jsx(qb,{x:156,y:106}),o.jsx("path",{d:"M170 92C186 92 184 60 200 60",className:"ga-arc"}),o.jsx("path",{d:"M195 56l5 4-5 4",className:"ga-arrow"}),o.jsx(Fr,{x:200,y:22,w:226,h:160}),o.jsx("text",{x:214,y:46,className:"ga-t ga-strong",children:"tests"}),o.jsx("text",{x:412,y:46,className:"ga-s",textAnchor:"end",children:"Sonnet 5 · 38s"}),o.jsx("line",{x1:200,y1:56,x2:426,y2:56,className:"ga-line"}),o.jsx("text",{x:214,y:76,className:"ga-cap",children:"PROMPT"}),o.jsx("text",{x:214,y:92,className:"ga-t",children:"Run the suite and fix what fails"}),o.jsx("text",{x:214,y:116,className:"ga-cap",children:"TOOLS · 6"}),o.jsx(Bl,{x:214,y:122,label:"Read"}),o.jsx(Bl,{x:266,y:122,label:"Edit"}),o.jsx(Bl,{x:318,y:122,label:"Bash",live:!0}),o.jsx("text",{x:214,y:164,className:"ga-cap",children:"TOKENS"}),o.jsx("text",{x:214,y:178,className:"ga-s ga-mono",children:"41k in · 2.1k out · $0.12"})]})}function jz(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return o.jsxs(qr,{children:[o.jsx(Fr,{x:14,y:20,w:412,h:160}),o.jsx("text",{x:28,y:44,className:"ga-t ga-strong",children:"This machine"}),o.jsx("text",{x:412,y:44,className:"ga-s",textAnchor:"end",children:"12 cores · up 10d"}),o.jsx("line",{x1:14,y1:56,x2:426,y2:56,className:"ga-line"}),o.jsx("text",{x:28,y:76,className:"ga-cap",children:"CORES"}),e.map((t,n)=>o.jsxs("g",{children:[o.jsx("rect",{x:28+n*15,y:82,width:10,height:30,rx:2,className:"ga-track"}),o.jsx("rect",{x:28+n*15,y:112-t,width:10,height:t,rx:2,className:"ga-accent"})]},n)),o.jsx("text",{x:28,y:136,className:"ga-cap",children:"MEMORY"}),o.jsx("rect",{x:28,y:143,width:178,height:5,rx:2.5,className:"ga-track"}),o.jsx("rect",{x:28,y:143,width:105,height:5,rx:2.5,className:"ga-accent"}),o.jsx("text",{x:28,y:165,className:"ga-s",children:"18.9 GB of 32.0 GB"}),o.jsx("text",{x:240,y:76,className:"ga-cap",children:"THERMAL"}),o.jsx("text",{x:240,y:100,className:"ga-big",children:"66 °C"}),o.jsx("text",{x:240,y:118,className:"ga-s ga-ok",children:"running at full speed"}),o.jsx("text",{x:240,y:142,className:"ga-cap",children:"BUSIEST PROCESSES"}),o.jsx("text",{x:240,y:160,className:"ga-s ga-mono",children:"node · claude"}),o.jsx("text",{x:412,y:160,className:"ga-s ga-mono",textAnchor:"end",children:"38%"}),o.jsx("text",{x:240,y:176,className:"ga-s ga-mono",children:"esbuild"}),o.jsx("text",{x:412,y:176,className:"ga-s ga-mono",textAnchor:"end",children:"21%"})]})}function _z(){return o.jsxs(qr,{children:[o.jsx("rect",{x:14,y:40,width:188,height:120,rx:10,className:"ga-screen"}),o.jsx("text",{x:28,y:60,className:"ga-cap",children:"~/MY-PROJECT"}),o.jsx("line",{x1:14,y1:70,x2:202,y2:70,className:"ga-line"}),o.jsxs("text",{x:28,y:100,className:"ga-t ga-mono",children:[o.jsx("tspan",{className:"ga-accent",children:"$"})," claude"]}),o.jsx("rect",{x:86,y:90,width:7,height:13,className:"ga-caret ga-blink"}),o.jsx("text",{x:28,y:130,className:"ga-s ga-mono",children:"or: codex"}),o.jsx("path",{d:"M210 100H238",className:"ga-arc"}),o.jsx("path",{d:"M233 95l6 5-6 5",className:"ga-arrow"}),o.jsx("rect",{x:250,y:40,width:176,height:120,rx:10,className:"ga-canvas"}),o.jsx("g",{className:"ga-pop",children:o.jsx(Ll,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function Ez(){return o.jsxs(qr,{children:[o.jsx(Fr,{x:14,y:16,w:232,h:170}),o.jsx("text",{x:28,y:40,className:"ga-t ga-strong",children:"Claude accounts"}),o.jsx(HS,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),o.jsx(HS,{x:220,y:33,d:"M3.3 10.7L10.7 3.3M5.2 3.3h5.5v5.5"}),o.jsx("line",{x1:14,y1:52,x2:246,y2:52,className:"ga-line"}),o.jsx(ws,{x:28,y:74,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("rect",{x:190,y:62,width:44,height:18,rx:9,className:"ga-accent"}),o.jsx("text",{x:212,y:74,className:"ga-s ga-on-accent",textAnchor:"middle",children:"active"}),o.jsx("line",{x1:14,y1:140,x2:246,y2:140,className:"ga-line"}),o.jsx(ws,{x:28,y:160,email:"personal@me.dev",state:"signed in",tone:"ok"}),o.jsx("rect",{x:188,y:148,width:46,height:18,rx:9,className:"ga-chip"}),o.jsx("text",{x:211,y:160,className:"ga-s",textAnchor:"middle",children:"switch"}),o.jsx(qb,{x:221,y:161}),o.jsx("path",{d:"M250 40C270 40 262 78 282 78",className:"ga-arc"}),o.jsx("path",{d:"M277 74l5 4-5 4",className:"ga-arrow"}),o.jsx(Fr,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),o.jsx("g",{className:"ga-pop",children:o.jsx(ws,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function Cz(){return o.jsxs(qr,{children:[o.jsx(Fr,{x:14,label:"THIS MACHINE"}),o.jsx(af,{x:28,y:60}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ws,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ws,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(Fr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(af,{x:264,y:60}),o.jsx(ws,{x:264,y:98,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("path",{d:"M246 120C234 80 206 80 194 120",className:"ga-arc"}),o.jsx("g",{className:"ga-travel ga-travel-low",transform:"translate(220 90)",children:o.jsx(Bb,{})})]})}const Tz=[{art:o.jsx(bz,{}),line:"Sessions waiting on you top the session list, longest wait first.",tip:"A tone and a system notification when one stops to ask. The speaker in the topbar."},{art:o.jsx(kz,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:o.jsx(Sz,{}),line:"Double-click any node: its prompt, every tool call, tokens and timing."},{art:o.jsx(Nz,{}),line:"What each session costs, and how much quota is left."},{art:o.jsx(jz,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:o.jsx(Ez,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:o.jsx(Cz,{}),line:"Your machines repair each other's expired logins over the local network.",tip:"Open it from the row at the foot of the Claude accounts panel."},{art:o.jsx(_z,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function Rz(){return o.jsxs(qr,{children:[o.jsx(Fr,{x:14,label:"THIS MACHINE"}),o.jsx(ws,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"}),o.jsx("rect",{x:40,y:94,width:86,height:20,rx:10,className:"ga-pill-warn"}),o.jsx("text",{x:83,y:108,className:"ga-s ga-warn",textAnchor:"middle",children:"sign in again"}),o.jsx("line",{x1:198,y1:100,x2:242,y2:100,className:"ga-off"}),o.jsx(Fr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ws,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function Az(){return o.jsxs(qr,{children:[o.jsx(Fr,{x:14,label:"THIS MACHINE"}),o.jsx(af,{x:28,y:60}),o.jsx(Nh,{x:28,y:92,name:"Ana's MacBook"}),o.jsx(Nh,{x:28,y:114,name:"Dorin's PC"}),o.jsx(Fr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(af,{x:264,y:60}),o.jsx(Nh,{x:264,y:92,name:"Your MacBook"}),o.jsx(Nh,{x:264,y:114,name:"Dorin's PC"}),o.jsx("line",{x1:196,y1:100,x2:244,y2:100,className:"ga-arc"}),o.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping"}),o.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping ga-ping-2"}),o.jsx("circle",{cx:220,cy:100,r:3,className:"ga-accent"})]})}function Mz(){return o.jsxs(qr,{children:[o.jsx("rect",{x:90,y:18,width:260,height:164,rx:10,className:"ga-screen"}),o.jsx("text",{x:106,y:42,className:"ga-t ga-strong",children:"This deck on the network"}),o.jsx("line",{x1:90,y1:54,x2:350,y2:54,className:"ga-line"}),o.jsx("text",{x:106,y:76,className:"ga-cap",children:"SHARE THESE ACCOUNTS"}),o.jsx(US,{x:106,y:88,on:!0}),o.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),o.jsx(US,{x:106,y:112}),o.jsx("text",{x:126,y:122,className:"ga-s ga-mono",children:"personal@me.dev"}),o.jsx("text",{x:106,y:150,className:"ga-cap",children:"PAIRING"}),o.jsx("text",{x:106,y:168,className:"ga-s",children:"Say yes to every deck that asks"}),o.jsx(VM,{x:304,y:157,on:!0}),o.jsx(qb,{x:115,y:97})]})}function Iz(){return o.jsxs(qr,{children:[o.jsx(Fr,{x:14,label:"THIS MACHINE"}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ws,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ws,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(Fr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ws,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),o.jsx("path",{d:"M246 96C234 56 206 56 194 96",className:"ga-arc"}),o.jsx("g",{className:"ga-travel",transform:"translate(220 66)",children:o.jsx(Bb,{})})]})}const $z=[{art:o.jsx(Rz,{}),line:"A login can expire on one machine while it still works on another."},{art:o.jsx(Az,{}),line:"Both decks are on. They find each other and ask to pair.",tip:"Not showing up? The + in the section reaches a machine by address or invite."},{art:o.jsx(Mz,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:o.jsx(Iz,{}),line:"An expired login is copied from a paired machine within a minute."}];function Oz(){return o.jsxs("svg",{className:"guide-art",viewBox:"0 0 232 60","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{x:1,y:14,width:78,height:42,rx:7,className:"ga-screen"}),o.jsx("circle",{cx:13,cy:29,r:3,className:"ga-warn"}),o.jsx("rect",{x:21,y:27,width:46,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:13,y:39,width:40,height:3,rx:1.5,className:"ga-track"}),o.jsx("rect",{x:153,y:14,width:78,height:42,rx:7,className:"ga-screen"}),o.jsx("circle",{cx:165,cy:29,r:3,className:"ga-ok"}),o.jsx("rect",{x:173,y:27,width:46,height:4,rx:2,className:"ga-track"}),o.jsx("rect",{x:165,y:39,width:40,height:3,rx:1.5,className:"ga-accent"}),o.jsx("path",{d:"M150 36C138 6 94 6 82 36",className:"ga-arc"}),o.jsx("g",{transform:"translate(116 13)",children:o.jsx(Bb,{})})]})}const Lz={panel:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it behind the + above, where an address can be typed too.",dialog:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it below, or type their address."},Pz=1600;function GM({reach:e,where:t}){const[n,r]=w.useState(!1),s=w.useRef(!0);w.useEffect(()=>()=>{s.current=!1},[]);const l=(e==null?void 0:e.steps)??[],c=w.useCallback(async()=>{await yi(l.join(`
91
91
  `))&&s.current&&(r(!0),window.setTimeout(()=>{s.current&&r(!1)},Pz))},[l]);if(!(e!=null&&e.blocked))return null;const u=e.shell==="sh";return o.jsxs("div",{className:"ap-lan-reach",children:[o.jsx("p",{className:"lan-warn",children:e.text}),o.jsx("p",{className:"lan-note",children:Lz[t]}),l.length>0&&o.jsxs("details",{className:"ap-lan-reach-fix",children:[o.jsx("summary",{children:"or let them find this deck on their own"}),o.jsxs("p",{className:"lan-note",children:[u?o.jsx(o.Fragment,{children:"Run this in a terminal on this machine, then restart the deck."}):o.jsxs(o.Fragment,{children:["Run this in PowerShell ",o.jsx("strong",{children:"as Administrator"}),", then restart the deck."]}),e.category==="Public"&&o.jsx(o.Fragment,{children:" The first line marks this network as a home or office one — leave it out on a network you do not trust."}),e.unsure&&o.jsxs(o.Fragment,{children:[" ",e.unsure]})]}),o.jsx("pre",{className:"ap-lan-cmd",children:o.jsx("code",{children:l.join(`
92
- `)})}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void c(),title:u?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}async function Am(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const Dz={not_an_invite:"That is not an invite — paste the whole line they sent you.",expired:"That invite has run out. Ask them for a fresh one.",not_running:"This deck is not on the network yet. Turn Local network on, then try again."},Fz={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function VS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||dn(n,t)}function qz({status:e,manual:t,startWith:n,onClose:r,onChanged:s}){const l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),f=e.pairingMode==="invite",p=mn(r,{focusRef:f?c:l}),[h,m]=w.useState(""),[y,v]=w.useState(""),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(null),[I,$]=w.useState(()=>Date.now());w.useEffect(()=>{const re=window.setInterval(()=>$(Date.now()),1e3);return()=>window.clearInterval(re)},[]);const q=w.useRef(!0);w.useEffect(()=>()=>{q.current=!1},[]);const B=w.useRef(null),P=w.useCallback(re=>Mf(B.current)?(B.current=re,E(re),!0):!1,[]),W=w.useCallback(()=>{B.current=null,q.current&&E(null)},[]),ne=re=>{const z=lo(j,re);return{disabled:z.disabled,"aria-busy":z.busy}},ee=re=>(S==null?void 0:S.field)===re?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},M=re=>b(z=>z&&z.field===re?null:z),X=w.useCallback(async()=>{if(f)return;const re=tU(h);if(!re){b({text:Bz(h),field:"addr"});return}const z=`${re.addr}:${re.port}`,Z=e.peers.find(U=>U.addr===re.addr&&U.port===re.port&&U.paired);if(Z){b({text:`Already paired with ${Z.name} at that address.`,field:"addr"});return}if(t.includes(z)){b({text:"This deck already calls that address.",field:"addr"});return}if(P("add"))try{const U=await Am("/api/prefs",{lan:{manual:[...t,z]}});if(!q.current)return;U!=null&&U.ok?(b(null),m(""),s(),r()):b({text:dn("add that address",U),field:"addr"})}catch{q.current&&b({text:dn("add that address",null),field:"addr"})}finally{W()}},[h,f,t,e.peers,s,r,P,W]),V=w.useCallback(async re=>{if(!P(`invite:${re}`))return;const z=re==="make"?"make an invite":"cancel that invite";try{const Z=await Am("/api/lan/invite",{action:re});if(!q.current)return;Z!=null&&Z.ok?(b(null),k(null),s()):b({text:VS(Fz,Z,z)})}catch{q.current&&b({text:dn(z,null)})}finally{W()}},[s,P,W]),G=w.useCallback(async()=>{const re=y.trim();if(!(!re||!P("join"))){R(null);try{const z=await Am("/api/lan/invite",{action:"join",token:re});if(!q.current)return;z!=null&&z.ok?(v(""),b(null),s(),r()):(z==null?void 0:z.reason)==="unreachable"&&Array.isArray(z.tried)&&z.tried.length?(R(z.tried),b(null)):(R(null),b({text:VS(Dz,z,"use that invite"),field:"join"}))}catch{q.current&&b({text:dn("use that invite",null),field:"join"})}finally{W()}}},[y,s,r,P,W]),F=w.useCallback(async(re,z)=>{try{await navigator.clipboard.writeText(re),k(z),window.setTimeout(()=>{q.current&&k(Z=>Z===z?null:Z)},1600)}catch{b({text:"Could not copy it — select the text and copy it by hand."})}},[]),L=e.invite&&e.invite.expiresAt>I?e.invite:null,H=w.useRef(!1);w.useEffect(()=>{n!=="invite"||H.current||L||(H.current=!0,V("make"))},[n,L,V]);const D=w.useRef(!1);w.useEffect(()=>{var re;n!=="invite"||D.current||!L||(D.current=!0,(re=u.current)==null||re.focus())},[n,L]);const K=e.port!=null?(e.addrs??[]).map(re=>`${re}:${e.port}`):[];return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:o.jsxs("div",{ref:p,className:"modal lan-add",onClick:re=>re.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[S&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:S.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>b(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsx(GM,{reach:e.reach,where:"dialog"}),f&&o.jsx("div",{className:"modal-section",children:o.jsx("p",{className:"lan-note",children:"Adding by address is off while this deck pairs only by invite."})}),!f&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"By address"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:l,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:h,placeholder:"192.168.1.5:54340",spellCheck:!1,...ee("addr"),onChange:re=>{m(re.target.value),M("addr")},onKeyDown:re=>{re.key==="Enter"&&X()}}),h.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("add"),onClick:()=>void X(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),o.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&K.length>0&&o.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",K.map((re,z)=>o.jsxs("span",{children:[z>0&&" or ",o.jsx("code",{className:"ap-lan-code",children:re})]},re)),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...ne("copy:mine"),onClick:()=>void F(K.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:_==="mine"?"copied":"copy"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:["With an invite",!L&&o.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...ne("invite:make"),onClick:()=>void V("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:j==="invite:make"?"making…":"make one to send"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:c,className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:y,placeholder:"paste one you were sent",spellCheck:!1,...ee("join"),onChange:re=>{v(re.target.value),R(null),M("join")},onKeyDown:re=>{re.key==="Enter"&&G()}}),y.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("join"),onClick:()=>void G(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:j==="join"?"joining…":"join"})]}),o.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),C&&o.jsxs("div",{className:"ap-lan-tried",children:[o.jsx("span",{className:"lan-note",children:"Nothing answered at any address in that invite. Check that deck is running with its Local network switch on."}),C.map(re=>o.jsxs("span",{className:"ap-lan-tried-row",children:[o.jsx("code",{className:"ap-lan-code",children:re.addr}),o.jsx("span",{className:"ap-lan-bad",children:re.why})]},re.addr))]}),L&&o.jsxs("div",{className:"ap-lan-invite",children:[o.jsxs("div",{className:"ap-lan-invite-head",children:[o.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),o.jsxs("span",{className:"ap-lan-invite-left",id:"lan-invite-left",children:[lU(L.expiresAt,I)," left"]})]}),o.jsx("code",{className:"ap-lan-token",children:L.token}),o.jsxs("div",{className:"ap-lan-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:u,...ne("copy:invite"),"aria-label":_==="invite"?"Invite copied":"Copy invite","aria-describedby":"lan-invite-left",onClick:()=>void F(L.token,"invite"),title:"Copy it, and send it however you already talk to them",children:_==="invite"?"copied":"copy"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("invite:withdraw"),onClick:()=>void V("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),o.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function Bz(e){const t=(e??"").trim();if(t==="")return"Type an address and a port, like 192.168.1.5:54340.";if(!t.startsWith("[")&&(t.match(/:/g)??[]).length>1)return"Too many colons to split. Use that deck's IPv4 address or its name, like 192.168.1.5:54340.";if(!t.includes(":"))return`Add the port too, like ${t}:54340.`;const n=t.slice(t.lastIndexOf(":")+1).trim();return n===""?"That is missing its port — try 192.168.1.5:54340.":/^\d+$/.test(n)?`A port runs from 1 to 65535, and this one is ${n}.`:`A port is a number, and this one is "${n}".`}const zz=1e3;function Uz(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=qs(e,t);return`${n} · ${r==="now"?"just now":r}`}function GS(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function Hz(){return o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),o.jsx("path",{d:"M8.4 3.6l2 2"})]})}function KS(){return o.jsxs("svg",{className:"lan-machine",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),o.jsx("path",{d:"M1 13h14"})]})}function Sh({dir:e,gate:t=!1}){const n=t?12:8;return o.jsx("svg",{className:"lan-chev","data-dir":e,"data-gate":t||void 0,width:n,height:"8",viewBox:`0 0 ${n} 8`,fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":t?"M1 1v6M9.6 1L6.4 4l3.2 3":"M5.2 1L2 4l3.2 3"})})}const Wz={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},Vz={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function Gz(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Wz[e.here]}, ${Vz[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Kz({row:e,source:t,status:n,accounts:r,now:s,busy:l,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,onInvite:m,twins:y=[],onUnpair:v}){var It,zt,Xt,Ft,rn;const S=w.useRef(null),b=mn(c,{focusRef:S}),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(!1),I=w.useRef(0),[$,q]=w.useState(null),[B,P]=w.useState(!1),[W,ne]=w.useState(0),ee=w.useRef(null),M=w.useRef(!0);w.useEffect(()=>()=>{M.current=!1},[]);const X=_!=null;w.useEffect(()=>{var Se;X&&((Se=ee.current)==null||Se.select())},[X]),w.useEffect(()=>{if(!C)return;const Se=window.setTimeout(()=>R(!1),4e3);return()=>window.clearTimeout(Se)},[C]),w.useEffect(()=>{if(!$)return;const Se=window.setTimeout(()=>q(null),4e3);return()=>window.clearTimeout(Se)},[$]);const V=Se=>{const vt=lo(l,Se);return{disabled:vt.disabled,"aria-busy":vt.busy}},G=async Se=>{const vt=await Se();return M.current&&E(vt),vt==null},{peer:F,stranger:L}=t,H=e.kind==="paired",D=e.self??e.name,K=e.kind!=="dialling",re=e.kind==="dialling"?null:e.fp,z=F?F.addr?`${F.addr}:${F.port}`:"":L?L.port?`${L.addr}:${L.port}`:L.addr:e.addr,Z=(F==null?void 0:F.about)??null,U=((It=n.about)==null?void 0:It.version)??null,ae=async Se=>{const vt=Se.trim()===D?"":Se;await G(()=>u(vt))&&k(null)},le=async()=>{if(re)try{if(await navigator.clipboard.writeText(re),!M.current)return;P(!0),window.setTimeout(()=>{M.current&&P(!1)},1600)}catch{M.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},ge=H?F!=null&&F.waiting?F.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":F!=null&&F.offers?"not said — it runs an older version":"not reached yet":"shown once paired",Ne=GS(n.about),Ie=GS(Z),Ge=Z!=null&&Z.version&&U?yU(Z.version,U):null,Pe=F?Ub(F.last,s):null,ze=F&&((zt=F.last)!=null&&zt.error)?eU({error:F.last.error,host:F.addr,port:F.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(Se=>!Se.manual&&Se.addr).map(Se=>({fp:Se.fp,name:Se.name,addr:Se.addr,port:Se.port,at:Se.lastSeen??0}))],s):null,Re=(Xt=F==null?void 0:F.last)!=null&&Xt.error&&Pe&&Pe.text!==F.last.error?F.last.error:null,st=((Ft=F==null?void 0:F.last)==null?void 0:Ft.done)??[],ue=!!Pe&&!!Re&&!e.quiet&&e.state.startsWith(Pe.text),ce=H||e.kind==="dialling",se=((F==null?void 0:F.via)??e.via)==="tailscale",be=F?F.waiting?null:F.manual?se?"added by its Tailscale address":"added by address":se?"over Tailscale":"on this network":e.kind==="nearby"?se?"heard over Tailscale":"heard on this network":se?"asked this deck to pair, over Tailscale":"asked this deck to pair",Le=e.tone==="bad"?"bad":H?e.here?"up":"down":"loose",de=l===`check:${e.fp}`,fe=(F==null?void 0:F.offers)??null,Ce=Le==="up"?(fe==null?void 0:fe.current)??null:null,pe=Ce&&"key"in Ce?Ce.key:null,_e=!!Ce&&"hidden"in Ce,Ye=!!Ce&&"other"in Ce,qe=H?vU((fe==null?void 0:fe.accounts)??null,r,n.shared??[],pe):[],ke=qe.filter(Se=>Se.in==null&&Se.out==="cut"),Ae=qe.some(Se=>Se.in!=null),Ue=qe.some(Se=>Se.out!=null),Fe=new Map(st.map(Se=>[Se.email,Se])),Ve=st.filter(Se=>!qe.some(vt=>vt.email===Se.email)),rt=H?fe?fe.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:F!=null&&F.waiting?"What that deck offers is not known yet. A deck that calls in says so each time it calls — one on an older version never does.":(rn=F==null?void 0:F.last)!=null&&rn.error?"What that deck offers is not known — the last attempt to ask it did not get through.":"Nobody has asked that deck what it offers yet. The next round asks it.":null,ut=fe&&(F!=null&&F.last)&&F.last.at-fe.at>zz?qs(fe.at,s):null,ct=[];H&&(F!=null&&F.pairedAt)?ct.push({label:"Paired",value:Uz(F.pairedAt,s),tone:"meta"}):e.kind==="declined"&&L&&ct.push({label:"Paired",value:`no · you said no ${Hb(L.at,s)}`,tone:"meta"}),ct.push({label:"Fingerprint",value:re?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:re}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void le(),"aria-label":B?"Fingerprint copied":"Copy the fingerprint",children:B?"copied":"copy"})]}):"not known — nothing has answered there",tone:re?void 0:"quiet"});const yt=y.length?[{row:e,peer:F??null},...y]:[];return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:o.jsxs("div",{ref:b,className:"modal lan-peer","data-tone":e.tone,onClick:Se=>Se.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[o.jsxs("header",{className:"modal-head lan-peer-head",children:[o.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("div",{className:"lan-peer-id",children:[X?o.jsxs("form",{className:"lan-peer-edit",onSubmit:Se=>{Se.preventDefault(),ae(_??"")},children:[o.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),o.jsx("input",{ref:ee,className:"ap-manage-input lan-peer-input",value:_??"",maxLength:48,placeholder:D,"aria-label":"Name for this deck, shown on this deck only",onChange:Se=>k(Se.target.value)}),o.jsx("button",{type:"submit",className:"ap-manage-btn",...V(`alias:${e.fp}`),children:"save"}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>k(null),children:"cancel"})]}):o.jsxs("span",{className:"lan-peer-title",children:[o.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),K&&o.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{E(null),k(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:o.jsx(Hz,{})})]}),o.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&o.jsxs(o.Fragment,{children:["calls itself ",o.jsx("span",{className:"lan-peer-self",children:e.self}),X&&o.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...V(`alias:${e.fp}`),onClick:()=>void ae(""),children:"use this name"}),o.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&o.jsx("span",{"aria-hidden":!0,children:" · "})]}),o.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{ref:S,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body lan-peer-body",children:[j&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:j}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>E(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"lan-map","data-link":Le,"data-asking":de||void 0,"data-bus":qe.length>0||void 0,children:[o.jsxs("div",{className:"lan-ends",children:[o.jsxs("p",{className:"lan-end",children:[o.jsx("span",{className:"lan-end-name",children:"This deck"}),Ne&&o.jsx("span",{className:"lan-end-runs",children:Ne}),H&&n.shareActive===!1&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),o.jsxs("p",{className:"lan-end","data-side":"there",children:[o.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&o.jsxs("span",{className:"lan-end-runs",children:[Ie??(Z?"not said":ge),Ge?` · ${Ge<0?"older":"newer"}`:null]}),_e&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ye&&o.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),o.jsxs("div",{className:"lan-link",children:[o.jsx(KS,{}),o.jsxs("span",{className:"lan-span",children:[o.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[o.jsx("i",{className:"lan-glint","data-dir":"out"}),o.jsx("i",{className:"lan-glint","data-dir":"in"})]}),o.jsx("span",{className:"lan-link-label",children:z?o.jsx("code",{className:"ap-lan-code",children:z}):"none here — it calls this deck"})]}),o.jsx(KS,{}),(z&&be||ce)&&o.jsxs("p",{className:"lan-link-sub",children:[z&&be,z&&be&&ce&&" · ",ce&&(Pe?ue?o.jsx("code",{className:"ap-lan-code",children:Re}):o.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),ce&&Re&&!ue&&o.jsx("code",{className:"lan-fact-raw",children:Re})]}),Ve.length>0&&o.jsx("ul",{className:"lan-done",children:Ve.map(Se=>{const vt=z0(Se);return o.jsxs("li",{"data-ok":Se.ok&&!vt,children:[Se.email," ",o.jsxs("span",{className:"lan-done-what",children:[Se.ok?"arrived":"did not arrive",vt&&` — ${vt.long}`]})]},`${Se.email}:${Se.action}`)})}),ze&&o.jsx("p",{className:"lan-note lan-link-note",children:ze}),(F==null?void 0:F.waiting)&&o.jsx("p",{className:"lan-note lan-link-note",children:e.hint}),(Pe==null?void 0:Pe.hint)&&o.jsx("p",{className:"lan-note lan-link-note",children:Pe.hint})]}),qe.length>0&&o.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:qe.map((Se,vt)=>{const kt=Fe.get(Se.email),_n=kt?z0(kt):null,Ut=Se.out==="live"||Se.in!=null&&Se.in!=="cut";return o.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":Se.tone,"data-draw":Se.in&&Se.out?"both":Se.in?"in":"out","data-used-there":Se.usedThere||void 0,style:{"--i":vt},children:[o.jsx("i",{className:"lan-pip","data-end":"here","data-state":Se.here,"aria-hidden":!0}),o.jsxs("span",{className:"lan-track",children:[o.jsxs("span",{className:"lan-wire","data-flow":Ut?"live":"cut","aria-hidden":!0,children:[(Se.in==="live"||Se.in==="wait")&&o.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":Se.in}),Se.out==="live"&&o.jsx("i",{className:"lan-glint","data-dir":"out"})]}),Se.in&&Se.in!=="cut"&&o.jsx(Sh,{dir:"in",gate:Se.in==="blocked"}),Se.out==="live"&&o.jsx(Sh,{dir:"out"}),o.jsx("span",{className:"lan-lane-email",children:Se.email})]}),o.jsx("i",{className:"lan-pip","data-end":"there","data-state":Se.there,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:Gz(Se)}),(Se.caption||kt)&&o.jsxs("span",{className:"lan-lane-note",children:[Se.caption,Se.caption&&kt&&" · ",kt&&o.jsxs("span",{className:"lan-lane-done","data-ok":kt.ok&&!_n,children:[kt.ok?"arrived last round":"did not arrive last round",_n&&` — ${_n.long}`]})]})]},Se.key)})},W),H&&o.jsxs(o.Fragment,{children:[ke.length>0&&o.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ke.length===1?ke[0].email:"the expired ones"," until you sign in again here."]}),rt&&o.jsx("p",{className:"lan-empty",children:rt}),ut&&o.jsxs("p",{className:"lan-stale",children:["As of ",ut==="now"?"just now":ut,", when it last answered."]}),o.jsxs("div",{className:"lan-legend",children:[Ae&&o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:o.jsx(Sh,{dir:"in"})}),"from ",e.name]}),Ue?o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:o.jsx(Sh,{dir:"out"})}),"from this deck, to every paired deck"]}):o.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),o.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),o.jsx("dl",{className:"lan-facts",children:ct.map(Se=>o.jsxs("div",{className:"lan-fact","data-tone":Se.tone,children:[o.jsx("dt",{children:Se.label}),o.jsx("dd",{children:Se.value})]},Se.label))}),yt.length>1&&o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:[yt.length," decks on this machine"]}),o.jsx("ul",{className:"lan-twins",role:"list",children:yt.map((Se,vt)=>{var $t,Zt,Ln,Ur;const kt=($t=Se.peer)!=null&&$t.addr?`${Se.peer.addr}:${Se.peer.port}`:Se.row.addr,_n=kt||Se.row.fp,Ut=(Zt=Se.peer)!=null&&Zt.pairedAt?qs(Se.peer.pairedAt,s):null,Vn=[(Ur=(Ln=Se.peer)==null?void 0:Ln.about)!=null&&Ur.version?`runs ${Se.peer.about.version}`:null,Ut?`paired ${Ut==="now"?"just now":Ut}`:null,Se.row.state].filter(Boolean).join(" · "),Vt=Se.row.fp;return o.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":Se.row.tone,children:[o.jsx("i",{className:Se.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),kt?o.jsx("code",{className:"ap-lan-code lan-twin-at",children:kt}):o.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),o.jsx("code",{className:"ap-lan-code lan-twin-fp",children:Vt}),vt>0&&v&&o.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${$===Vt?" armed":""}`,...V(`unpair:${Vt}`),onKeyDown:xe=>{xe.repeat&&xe.preventDefault()},onClick:()=>{const xe=Date.now(),ir=Au({armedFor:$,target:Vt,armedAt:I.current,now:xe,gapMs:Ou});if(ir==="arm"){q(Vt),I.current=xe;return}ir!=="ignore"&&(q(null),G(()=>v(Vt)))},"aria-label":$===Vt?`Confirm unpairing ${_n}`:`Unpair ${_n}`,title:$===Vt?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this one of the machine's decks",children:l===`unpair:${Vt}`?"unpairing…":$===Vt?"confirm":"unpair"}),o.jsx("span",{className:"lan-twin-meta",children:vt===0?`${Vn} · shown above`:Vn})]},Vt)})})]})]}),o.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&o.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),H&&!(F!=null&&F.waiting)&&o.jsx("button",{type:"button",className:"btn",...V(`check:${e.fp}`),onClick:()=>void G(f).then(Se=>{Se&&M.current&&ne(vt=>vt+1)}),title:"Ask this deck now instead of waiting for the next round",children:l===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&o.jsx("button",{type:"button",className:`btn danger lan-peer-verb${C?" armed":""}`,...V(`unpair:${e.fp}`),onKeyDown:Se=>{Se.repeat&&Se.preventDefault()},onClick:()=>{const Se=Date.now(),vt=Au({armedFor:C?e.fp:null,target:e.fp,armedAt:I.current,now:Se,gapMs:Ou});if(vt==="arm"){R(!0),I.current=Se;return}vt!=="ignore"&&(R(!1),G(p))},"aria-label":C?`Confirm unpairing ${e.name}`:`Unpair ${e.name}`,title:C?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:l===`unpair:${e.fp}`?"Unpairing…":C?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...V(`accept:${e.fp}`),onClick:()=>void G(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:l===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...V(`drop:${e.fp}`),onClick:()=>void G(p),title:"Stop trying this address. Nothing was ever paired here.",children:l===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...V(`allow:${e.fp}`),onClick:()=>void G(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:l===`allow:${e.fp}`?"Allowing…":"Let it ask again"}),(e.kind==="nearby"||e.kind==="declined")&&n.pairingMode==="invite"&&m&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",onClick:m,title:"This deck pairs only by invite. Make one and send it to whoever is at that machine.",children:"Invite to pair"})]})]})}),document.body)}function Yz(e){if(!e.running)return`Tailscale is ${e.state==="Stopped"?"turned off":e.state==="NeedsLogin"||e.state==="NeedsMachineAuth"?"signed out":e.state==="Starting"?"still starting":"not answering"} on this machine`;const t=e.login??"your Tailscale account";return e.on?`${e.devices} online · ${t}`:t}const jh="Paused while this deck pairs only by invite. Turn that off above to use it.";function Xz({status:e,accounts:t,onClose:n,onChanged:r}){const s=mn(n),[l,c]=w.useState(null),[u,f]=w.useState(null),[p,h]=w.useState(!1),[m,y]=w.useState(null),v=w.useRef(null),S=M=>{const X=lo(m,M);return{disabled:X.disabled,"aria-busy":X.busy}},b=w.useRef(null),_=w.useRef(!0);w.useEffect(()=>()=>{_.current=!1},[]),w.useEffect(()=>{b.current=ZS(b.current,e.shared??[],null)},[e.shared]);const k=w.useCallback(async(M,X,V="write")=>{v.current=V,y(V);try{const F=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:M})})).json().catch(()=>null);return _.current?(F!=null&&F.ok?f(null):f(dn(X,F)),r(),(F==null?void 0:F.ok)===!0):!1}catch{return _.current&&f(dn(X,null)),!1}finally{v.current=null,_.current&&y(null)}},[r]),j=w.useCallback(async()=>{if(l!=null&&l!==(e.name??"")){if(!await k({name:l},"save the name","name"))return;_.current&&c(null)}n()},[l,e.name,k,n]),E=async()=>{if(!e.fp)return;const M=await yi(e.fp);if(_.current){if(!M){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{_.current&&h(!1)},1600)}},C=new Set(b.current??e.shared??[]),R=e.autoAsk!==!1,I=e.autoAccept!==!1,$=e.pairingMode==="invite",q=M=>{const X=S(M);return{...X,disabled:X.disabled||$}},B=e.shareActive!==!1,P=e.tailscale??null,W=!!(P!=null&&P.on),ne=(P==null?void 0:P.ask)!==!1,ee=(P==null?void 0:P.accept)!==!1;return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal lan-modal",onClick:M=>M.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[u&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:u}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Name"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"appear as"}),o.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:M=>c(M.target.value),onKeyDown:M=>{M.key!=="Enter"||l==null||(k({name:l},"save the name","name"),c(null))}}),l!=null&&l!==(e.name??"")&&o.jsx("button",{type:"button",className:"ap-manage-btn",...S("name"),onClick:()=>{k({name:l},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:e.fp}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void E(),"aria-label":p?"Fingerprint copied":"Copy this deck's fingerprint",children:p?"copied":"copy"})]}):o.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Share these accounts"}),o.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&o.jsx("span",{className:"ap-lan-empty",children:"No Claude accounts on this deck yet — add one with + at the top of this panel."}),t.map(M=>o.jsxs("label",{className:"ap-lan-pick",title:M.alive?"Offer this account to the decks you have paired with, so one whose copy has died can heal from yours. Unticking stops it being offered from now on; it does not take back a copy somebody already has.":"This deck cannot use this login, so it has nothing to offer — a deck that can will heal it",children:[o.jsx("input",{type:"checkbox",checked:C.has(M.key),onChange:X=>{const V=iU(b.current,e.shared??[],M.key,X.target.checked);b.current=V,k({shared:V},X.target.checked?"share that account":"stop sharing that account").then(G=>{b.current===V&&(b.current=ZS(V,e.shared??[],{ok:G}))})}}),o.jsx("span",{className:"ap-lan-pick-name",children:M.email}),!M.alive&&o.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},M.key))]}),t.length>0&&o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":B,"aria-label":"Show paired decks which of these this deck is using",...S("current"),onClick:()=>void k({shareActive:!B},B?"stop showing which account this deck is using":"show which account this deck is using","current"),title:B?"Stop telling paired decks which account this one is on. They read “current account hidden” instead.":"Tell paired decks which of the ticked accounts this one is on. An unticked account is never named.",children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",id:"lan-pairing-h",children:"Pairing"}),o.jsx("div",{className:"lan-switches lan-switches-lead",role:"group","aria-labelledby":"lan-pairing-h",children:o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Pair new decks only by invite",$&&o.jsx("span",{id:"lan-invite-only-detail",className:"lan-switch-detail",children:"A new deck needs an invite from + in the panel. Paired decks stay paired."})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":$,"aria-label":"Pair new decks only by invite","aria-describedby":$?"lan-invite-only-detail":void 0,...S("mode"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({pairingMode:$?"automatic":"invite"},$?"let decks pair on their own again":"pair new decks only by invite","mode"),title:$?"Let decks on this network pair as the two switches below say again.":"Only a deck you send an invite to can pair with this one. Nearby decks can't ask, and requests waiting now are turned away.",children:o.jsx("span",{className:"switch-knob"})})]})}),o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-auto-h",children:["Automatic pairing",$&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches","data-paused":$||void 0,children:[o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":R,"aria-label":"Ask every deck this one finds",...q("ask"),onClick:()=>void k({autoAsk:!R},R?"stop asking automatically":"ask every deck this one finds","ask"),title:$?jh:R?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck heard on this network. Somebody over there still has to say yes.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Say yes to every deck that asks","data-tone":"warn",...q("accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({autoAccept:!I},I?"stop accepting automatically":"accept every deck that asks","accept"),title:$?jh:I?"Stop saying yes for you. A deck that asks waits in the panel again.":"Say yes for you. Every deck on this network that asks is paired without anybody being asked here.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]}),(P==null?void 0:P.found)&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Tailscale"}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",o.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:Yz(P)})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":W,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...S("tailscale"),onClick:()=>void k({tailscale:!W},W?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:W?"Stop. Nothing is looked for or answered over the tailnet; decks already paired stay paired.":"Find the decks on your other machines on Tailscale, wherever they are. Only machines signed in to your Tailscale account are asked.",children:o.jsx("span",{className:"switch-knob"})})]}),W&&o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-ts-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-ts-auto-h",children:["Automatic pairing with my devices",$&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch","data-paused":$||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ne,"aria-label":"Ask each of my devices it finds over Tailscale",...q("tailscale-ask"),onClick:()=>void k({tailscaleAsk:!ne},ne?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:$?jh:ne?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck found on your devices over Tailscale.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch","data-paused":$||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ee,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",...q("tailscale-accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({tailscaleAccept:!ee},ee?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:$?jh:ee?"Stop saying yes for you. A device that asks waits in the panel again.":"Say yes for you when a deck on one of your own devices asks. Anybody else on the tailnet still waits for a press.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]})]})]}),o.jsxs("footer",{className:"lan-setup-foot",children:[o.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),o.jsx("button",{type:"button",className:"btn primary",...S("name"),onClick:()=>void j(),children:"Done"})]})]})}),document.body)}function qs(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const s=Math.round(r/60);return s<48?`${s}h ago`:`${Math.round(s/24)}d ago`}const YS={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${Fb}. The next round brings it.`}};function z0(e){return e.why?Object.hasOwn(YS,e.why)?YS[e.why]:sf(e.why):null}const zb={"waiting for the other deck to accept this one":{text:"waiting for them to say yes",tone:"idle"},"that deck said no":{text:"it said no",tone:"bad"},"that deck pairs only by invite":{text:"it pairs only by invite",tone:"idle"},"this deck pairs only by invite":{text:"needs an invite · your setting",tone:"idle"}},Zz={ECONNREFUSED:"not listening",EHOSTUNREACH:"no route to it",ENETUNREACH:"no network here",ETIMEDOUT:"no answer",ECONNRESET:"it hung up",EHOSTDOWN:"it is down",ENOTFOUND:"name not found",EACCES:"blocked here",EPIPE:"it hung up"};function XS(e){var r;const t=Qz[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&Zz[n]||e}const Qz={"handshake timed out":"no answer","peer closed the connection":"it hung up","peer went quiet":"it stopped mid-sentence","bad reply":"it answered with nonsense","no manifest":"it would not say what it has","bad challenge":"it answered as somebody else","a different deck is answering at that address":"a different deck is at that address","that deck could not prove its own key":"it could not prove who it is","the other deck refused this one's proof":"it would not take this deck's word","the other deck refused this handshake":"it turned this deck away","that deck has this one pinned under a different key":"it knows this deck by another key"};function Ub(e,t){var h;if(!e)return null;if(e.error&&((h=e.done)!=null&&h.length)){const m=Ub({...e,error:void 0},t),y=` · ${qs(e.at,t)}`;return{...m,text:`${m.text.slice(0,-y.length)}, then ${XS(e.error)}${y}`,tone:"bad"}}if(e.error)return zb[e.error]??{text:XS(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${qs(e.at,t)}`,tone:"idle"};const r=n.filter(m=>m.ok),s=r.length===1?"login":"logins",l=n.map(m=>({d:m,why:z0(m)})).filter(m=>m.why),c=[...new Set(l.map(m=>m.why.short))],u=c.length?`, ${c.join(", ")}`:"",f=l.length?l.map(m=>`${m.d.email}: ${m.why.long}`).join(" "):void 0,p=qs(e.at,t);return r.length===n.length?{text:`${r.length} ${s} arrived${u} · ${p}`,tone:l.length?"warn":"ok",...f?{hint:f}:{}}:{text:`${r.length} of ${n.length} logins arrived${u} · ${p}`,tone:"bad",...f?{hint:f}:{}}}const Jz=9e4;function eU({error:e,host:t,port:n},r,s,l=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=r.filter(p=>p.addr===c&&p.port&&p.at>0&&s-p.at<Jz);if(!u.length)return null;const f=[...new Set(u.map(p=>p.port))];if(n!=null&&!f.includes(n)){const p=f.length===1?`port ${f[0]}`:`ports ${f.join(" and ")}`;return`A deck at ${c} is announcing itself on ${p}, not on ${n}. This deck already hears it and dials it there, so this typed row has nothing to reach.`}return`That machine is running the deck — its beacon arrives here every half minute — and what this deck sends back never gets there. That is a firewall on ${c}, not a network fault. Whoever uses it can allow two ports: UDP ${l} and TCP ${n??f[0]}.`}const U0=5e3,KM=6e4,Ou=400;function tU(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const r=t.slice(0,n).trim(),s=Number(t.slice(n+1).trim());return!r||!Number.isInteger(s)||s<1||s>65535||r.includes(":")&&!(r.startsWith("[")&&r.endsWith("]"))?null:{addr:r,port:s}}function dn(e,t){if(t==null)return`Could not ${e} — the deck did not answer.`;const n=t.reason?sU(t.reason,t.detail):void 0;return n?`Could not ${e} — ${n}`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}const nU={prefs_unreadable:"this deck cannot read its settings file, so it will not write over it. The file may belong to another user, for example after ccdeck was run with sudo. The deck's log names the file.",prefs_not_writable:"this deck is not allowed to save its settings. The settings folder may belong to another user, for example after ccdeck was run with sudo, or another program may be holding the file. The deck's log names the folder."},rU=new Set(["EACCES","EPERM"]);function sU(e,t){const n=nU[e];if(!n)return;const r=e==="prefs_unreadable"&&t?aU(t):void 0,s=t!=null&&t.code&&t.code!=="BADJSON"?` Error code: ${t.code}.`:"";return(r??n)+s}function aU({code:e,owner:t,on:n}){if(e==="BADJSON")return"its settings file is damaged and could not be moved aside, so it will not write over it. The deck's log names the file.";if(n==="folder"&&t==="other")return"this deck cannot open its settings folder, which belongs to another user, for example after ccdeck was run with sudo. The deck's log has the command that gives it back.";if(n==="folder"&&t==="you")return"this deck cannot open its own settings folder, so it will not write over what is in it. The deck's log names the folder.";if(t==="other")return"its settings file belongs to another user and could not be moved aside, so it will not write over it. The deck's log names the file.";if(t==="you")return"this deck cannot read its settings file although the file is yours, so it will not write over it. Something on this machine is blocking the read; the deck's log names the file.";if(e&&!rU.has(e))return"this deck cannot read its settings file, so it will not write over it. The deck's log names the file."}function oU(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function iU(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function ZS(e,t,n){return e==null||n!=null&&!n.ok||oU(e,t)?null:e}function lU(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function YM(e,t){var n,r;return(n=e.last)!=null&&n.error&&!zb[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<of||e.lastSeen!=null&&t-e.lastSeen<of)}const of=95e3,XM=160,cU=6,ZM=140;function uU(e,t){const n=[],r=[];for(const s of e??[])(YM(s,t)?n:r).push(s);return{online:n,offline:r}}function dU(e){var t;return(t=e.tailscale)!=null&&t.exitNode?"Tailscale sends this machine's local network through an exit node, so decks on this network cannot find this one. Turn on Allow local network access in Tailscale's exit node menu to bring them back.":"This machine sends its local network through a VPN, so decks on this network cannot find this one. Allowing local network access in the VPN brings them back."}function hU(e,t){if(!e)return{text:"checking…",tone:"idle"};if(!e.enabled)return{text:"",tone:"idle"};if(e.stalled)return{text:`could not start — ${e.stalled}`,tone:"bad"};if(!e.running)return{text:"starting…",tone:"wait"};const n=(e.pending??[]).length;if(n)return{text:n===1?"1 deck is waiting for your answer":`${n} decks are waiting for your answer`,tone:"wait"};const r=(e.peers??[]).filter(v=>v.paired!==!1||v.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const s=r.filter(v=>v.waiting),l=r.filter(v=>!v.waiting),c=s.filter(v=>{var S;return!((S=v.last)!=null&&S.error)&&v.lastSeen!=null&&t-v.lastSeen<of}),{online:u,offline:f}=uU(l,t),p=[...f,...s.filter(v=>!c.includes(v))],h=u.length+c.length,m=u.filter(v=>{var S;return((S=v.last)==null?void 0:S.error)==="waiting for the other deck to accept this one"});if(h&&m.length===h)return{text:h===1?"1 deck found · waiting for them to accept":`${h} decks found · waiting for them to accept`,tone:"wait"};if(!h)return{text:p.length===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${p.length} decks`,tone:"bad"};const y=h===1?"1 deck ready":`${h} decks ready`;return{text:p.length?`${y} · ${p.length} away`:y,tone:"ok"}}function fU(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=qs(e,t);return r==="now"?"checked just now":`checked ${r}`}function Hb(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const r=Math.round(n/60);return r<60?`${r}m ago`:`${Math.round(r/60)}h ago`}function pU(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<of;return{text:n?"online · one-way, it calls in":`one-way · last online ${qs(e,t)}`,here:n}}function QS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${qs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function mU(e,t){var y,v,S,b,_;if(!e)return[];const n=[],r=new Set,s=(k,j)=>k.name.localeCompare(j.name,void 0,{numeric:!0}),l=e.aliases??{},c=(k,j)=>{const E=k?l[k]:void 0;return E&&E!==j?{name:E,self:j}:{name:j}};for(const k of e.pending??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);n.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"asks",state:`wants to pair · ${Hb(k.at,t)}`,tone:"wait",here:!0,hint:`${j.name} at ${k.addr}${k.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}const u=[],f=[];for(const k of e.peers??[]){const j=k.peerFp??k.fp;if(!j||r.has(j))continue;r.add(j);const E=Ub(k.last,t),C=YM(k,t),R=k.addr?`${k.addr}:${k.port}`:"";if(!k.paired&&k.manual&&!k.met){f.push({fp:R,name:R||k.name||j,addr:k.addr??"",kind:"dialling",state:E?E.text.replace(/ · .*$/,""):"trying…",tone:E?E.tone:"idle",here:!1,hint:(y=k.last)!=null&&y.error?`Nothing has answered at ${R} yet — ${k.last.error}.`:`Dialling ${R} until something answers.`,...k.via==="tailscale"?{via:"tailscale"}:{}});continue}const I=k.waiting?pU(k.lastSeen,t):null,$=I?I.here:C,q=!I&&E?$?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${QS(k,$,t)}`:I?I.text:QS(k,$,t),B=(v=k.last)!=null&&v.error?zb[k.last.error]:null,P=!I&&$&&!((S=k.last)!=null&&S.error)&&!(((b=k.last)==null?void 0:b.done)??[]).length,W=k.manual&&!k.met?{name:R}:c(j,k.name||j);u.push({fp:j,name:W.name,...W.self?{self:W.self}:{},addr:k.addr??"",kind:"paired",state:q,quiet:P,tone:B?B.tone==="bad"?"bad":"wait":E?E.tone:$?"ok":"idle",here:I?I.here:C,...k.via==="tailscale"?{via:"tailscale"}:{},hint:I?`${W.name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. ${k.lastSeen==null?"It has not called since this deck started.":`It last called ${qs(k.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${W.name}${R?` at ${R}`:""}${(_=k.last)!=null&&_.error?` — ${k.last.error}`:""}${E!=null&&E.hint?` — ${E.hint}`:""}`})}n.push(...gU(u).sort(s),...f.sort(s));const p=[];for(const k of e.strangers??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);p.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"nearby",state:e.pairingMode==="invite"?"needs an invite":"not paired yet",tone:"idle",here:!0,hint:k.via==="tailscale"?`${j.name} at ${k.addr} is on your tailnet and nothing is shared with it.`:`${j.name} at ${k.addr} is on this network and nothing is shared with it.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}n.push(...p.sort(s));const h=[];for(const k of e.declined??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);h.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${j.name} asked and was turned away. It is not asking any more.`})}n.push(...h.sort(s));const m=new Map;for(const k of n)m.set(k.name,(m.get(k.name)??0)+1);for(const k of n)(m.get(k.name)??0)<2||!k.addr||(k.state=k.quiet||!k.state?k.addr:`${k.addr} · ${k.state}`,k.quiet=!1);return n}function gU(e){const t=new Map;for(const r of e){const s=t.get(r.name);s?s.push(r):t.set(r.name,[r])}const n=[];for(const r of t.values()){const s=[...new Set(r.filter(l=>l.addr).map(l=>l.addr))];if(s.length>1){for(const l of s)n.push(JS(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(JS(r))}return n}function JS(e){const[t,...n]=[...e].sort((r,s)=>Number(s.here)-Number(r.here)||+!!s.addr-+!!r.addr);return n.length?{...t,twins:n}:t}function ej(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function tj(e,t){if(!e)return{};switch(t.kind){case"paired":return{peer:(e.peers??[]).find(n=>(n.peerFp??n.fp)===t.fp)??null};case"dialling":return{peer:(e.peers??[]).find(n=>n.manual&&!n.met&&`${n.addr}:${n.port}`===t.fp)??null};case"nearby":return{stranger:(e.strangers??[]).find(n=>n.fp===t.fp)??null};case"declined":return{stranger:(e.declined??[]).find(n=>n.fp===t.fp)??null};case"asks":return{stranger:(e.pending??[]).find(n=>n.fp===t.fp)??null}}}function yU(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!r)return null;for(let s=1;s<=3;s++){const l=Number(n[s])-Number(r[s]);if(l)return Math.sign(l)}return 0}function wU(e,t,n){const r=t?t.alive?t.shareable===!1?"cannot share here":"works here":"expired here":"not on this deck";if(e.alive&&e.shareable===!1)return{there:"cannot share there",here:r,note:null,tone:"idle"};if(!e.alive){const s=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:r,note:s,tone:s?"bad":"idle"}}return t?t.alive?{there:"works there",here:r,note:null,tone:t.shareable===!1?"idle":"ok"}:n?{there:"works there",here:r,note:"repairs next round",tone:"wait"}:{there:"works there",here:r,note:"share it to repair",tone:"bad"}:{there:"works there",here:r,note:"arrives next round",tone:"wait"}}function vU(e,t,n,r=null){var f;const s=new Map;for(const p of t)(f=s.get(p.key))!=null&&f.alive||s.set(p.key,p);const l=new Set(n),c=[],u=new Set;for(const p of e??[]){if(u.has(p.key))continue;u.add(p.key);const h=s.get(p.key)??null,m=l.has(p.key),y=wU(p,h,m),v=h?h.alive?h.shareable===!1?"unavailable":"works":"expired":"missing",S=!p.alive&&h&&!h.alive?y.note:[v==="works"?null:y.here,p.alive&&p.shareable!==!1?null:y.there,y.note].filter(Boolean).join(" · ")||null;c.push({key:p.key,email:p.email,here:v,there:p.alive?p.shareable===!1?"unavailable":"works":"broken",in:!p.alive||p.shareable===!1?"cut":y.tone==="wait"?"wait":y.tone==="bad"?"blocked":"live",out:m&&h?h.alive&&h.shareable!==!1?"live":"cut":null,caption:S,tone:y.tone,usedThere:r===p.key})}for(const p of n){const h=s.get(p);!h||u.has(p)||(u.add(p),c.push({key:p,email:h.email,here:h.alive?h.shareable===!1?"unavailable":"works":"expired",there:"unknown",in:null,out:h.alive&&h.shareable!==!1?"live":"cut",caption:h.alive?h.shareable===!1?"cannot share here":null:"expired here",tone:h.alive?h.shareable===!1?"idle":"ok":"bad",usedThere:!1}))}return c}async function Cl(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function xU({anchorId:e,id:t,rows:n,onHold:r,onLet:s}){const l=w.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,cU),p=c.length-u.length,h=u.length>f.length?`and ${u.length-f.length} more`:p>0?`${p} not on right now`:null,m=w.useCallback(()=>{const y=l.current,v=document.getElementById(e);if(!y||!v)return;const S=Pb(v.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${S.top}px`,y.style.left=`${S.left}px`,y.style.maxHeight=S.maxHeight==null?"":`${S.maxHeight}px`,y.dataset.side=S.side},[e]);return w.useLayoutEffect(()=>{m()}),w.useEffect(()=>(window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[m]),On.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&o.jsx("div",{className:"ap-peek-list",children:f.map(y=>o.jsxs("span",{className:"ap-peek-who",children:[o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),o.jsxs("span",{children:[y.name,y.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${y.kind}:${y.fp}`))}),h&&o.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function bU(e,t){var l;if(!e)return{text:"checking…",tone:"idle",live:!1};if(!e.enabled)return{text:"Off",tone:"idle",live:!1};if(e.stalled)return{text:"could not start",tone:"bad",live:!1};if(!e.running)return{text:"starting…",tone:"wait",live:!1};const n=t.filter(c=>c.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((l=e.reach)!=null&&l.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(c=>c.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const s=r.filter(c=>c.here).length;return s?s===r.length?{text:`${s} online`,tone:"ok",live:!0}:{text:`${s} of ${r.length} online`,tone:"ok",live:!0}:{text:`none of ${r.length} online`,tone:"idle",live:!1}}function kU({accounts:e,onChanged:t,view:n,onOpen:r,onBack:s,closeButton:l}){const[c,u]=w.useState(null),[f,p]=w.useState([]),[h,m]=w.useState(null),[y,v]=w.useState(!1),[S,b]=w.useState(null),_=w.useRef(0),[k,j]=w.useState(!1),[E,C]=w.useState(!1),[R,I]=w.useState(!1),$=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout($.current),[]);const[q,B]=w.useState(!1),[P,W]=w.useState(null),ne=w.useRef(null),ee=w.useCallback(de=>Mf(ne.current)?(ne.current=de,m(de),!0):!1,[]),M=w.useCallback(()=>{ne.current=null,F.current&&m(null)},[]),X=de=>{const fe=lo(h,de);return{disabled:fe.disabled,"aria-busy":fe.busy}},[V,G]=w.useState(()=>Date.now()),F=w.useRef(!0),L=w.useRef(U0),H=w.useCallback(async()=>{var de,fe;try{const[Ce,pe]=await Promise.all([fetch("/api/lan").then(_e=>_e.json()),fetch("/api/prefs").then(_e=>_e.json())]);if(!F.current)return;Ce!=null&&Ce.ok&&u(Ce),pe!=null&&pe.ok&&p(Array.isArray((fe=(de=pe.prefs)==null?void 0:de.lan)==null?void 0:fe.manual)?pe.prefs.lan.manual:[]),L.current=(Ce==null?void 0:Ce.enabled)===!0?U0:KM}catch{}},[]);w.useEffect(()=>{F.current=!0;let de=0;const fe=async()=>{G(Date.now()),await H(),F.current&&(de=window.setTimeout(fe,L.current))};return fe(),()=>{F.current=!1,window.clearTimeout(de)}},[H]);const D=w.useCallback(async()=>{const de=(c==null?void 0:c.enabled)===!0;if(ee("switch"))try{const fe=await Cl("/api/prefs",{lan:{enabled:!de}});if(!F.current)return;fe!=null&&fe.ok?(W(null),de||v(!0)):W(dn(de?"turn this off":"turn this on",fe)),await H()}catch{F.current&&W(dn(de?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,H,ee,M]),K=w.useCallback(async(de,fe,Ce)=>{if(!ee(`${de}:${fe}`))return null;let pe=null;try{const _e=await Cl("/api/lan/peer",{action:de,fp:fe});if(!F.current)return null;_e!=null&&_e.ok?(u(_e),W(null)):(pe=dn(Ce,_e),W(pe)),await H()}catch{pe=dn(Ce,null),F.current&&W(pe)}finally{M()}return pe},[H,ee,M]),re=w.useCallback(async de=>{if(!ee(`drop:${de}`))return null;let fe=null;try{const Ce=await Cl("/api/prefs",{lan:{manual:f.filter(pe=>pe!==de)}});if(!F.current)return null;Ce!=null&&Ce.ok?(W(null),t()):(fe=dn("stop dialling that address",Ce),W(fe)),await H()}catch{fe=dn("stop dialling that address",null),F.current&&W(fe)}finally{M()}return fe},[f,H,t,ee,M]),[z,Z]=w.useState(null),U=w.useCallback(async(de,fe)=>{if(!ee(`alias:${de}`))return"Something else is still being saved. Try again in a moment.";try{const Ce=await Cl("/api/lan/peer",{action:"alias",fp:de,name:fe});return F.current?Ce!=null&&Ce.ok?(u(Ce),null):dn("rename that deck",Ce):null}catch{return dn("rename that deck",null)}finally{M()}},[ee,M]),ae=w.useCallback(async de=>{if(!ee(`check:${de}`))return null;try{const fe=await Cl("/api/lan/sync",{fp:de});return F.current?fe!=null&&fe.ok?(u(fe),t(),null):(fe==null?void 0:fe.reason)==="no_address"?"There is no address here to call it on. It calls this deck, and it is up to date each time it does.":dn("check that deck",fe):null}catch{return dn("check that deck",null)}finally{M()}},[ee,M,t]),le=w.useCallback(async()=>{if(ee("check"))try{const de=await Cl("/api/lan/sync",{});if(!F.current)return;de!=null&&de.ok?(u(de),W(null)):W(dn("check the other decks",de)),t()}catch{F.current&&W(dn("check the other decks",null))}finally{M()}},[ee,M,t]),ge=(c==null?void 0:c.enabled)===!0,Ne=mU((c==null?void 0:c.pairingMode)==="invite"&&c?{...c,pending:[]}:c,V),Ie=z?Ne.find(de=>{var fe;return de.fp===z||((fe=de.twins)==null?void 0:fe.some(Ce=>Ce.fp===z))})??null:null;w.useEffect(()=>{z&&c&&!Ie&&Z(null)},[z,c,Ie]);const Ge=Ne.filter(de=>de.kind==="asks"),Pe=Ne.filter(de=>de.kind!=="asks"),ze=Pe.filter(de=>de.here),Re=Pe.filter(de=>!de.here),st=Re.filter(de=>de.tone==="bad").length,ue=q||ze.length===0,ce=hU(c,V),se=Pe.filter(de=>de.kind==="paired").length,be=bU(c,Ne),Le=o.jsxs(o.Fragment,{children:[k&&c&&o.jsx(qz,{status:c,manual:f,startWith:k==="invite"?"invite":void 0,onClose:()=>j(!1),onChanged:()=>{H(),t()}}),E&&o.jsx(WM,{title:"How Local network works",steps:$z,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),D()}},onClose:()=>C(!1)}),y&&c&&o.jsx(Xz,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>v(!1),onChanged:()=>{H(),t()}}),Ie&&c&&o.jsx(Kz,{row:Ie,source:tj(c,Ie),status:c,accounts:e,now:V,busy:h,onClose:()=>Z(null),onRename:de=>U(Ie.fp,de),onCheck:()=>ae(Ie.fp),onVerb:()=>{switch(Ie.kind){case"paired":return K("unpair",Ie.fp,"unpair that deck");case"nearby":return K("accept",Ie.fp,"reach that deck");case"declined":return K("allow",Ie.fp,"let that deck ask again");case"dialling":return re(Ie.fp);default:return Promise.resolve(null)}},onSettings:()=>{Z(null),v(!0)},onInvite:()=>{Z(null),j("invite")},twins:(Ie.twins??[]).map(de=>({row:de,peer:tj(c,de).peer??null})),onUnpair:de=>K("unpair",de,"unpair that deck")})]});if(!n){const de=_e=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>I(!0),_e)},fe=()=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>I(!1),ZM)},Ce=()=>window.clearTimeout($.current),pe=()=>{window.clearTimeout($.current),I(!1)};return o.jsxs("div",{className:"ap-foot",children:[o.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{pe(),r()},"aria-describedby":R?"ap-lan-peek":void 0,onPointerEnter:_e=>{_e.pointerType==="mouse"&&de(XM)},onPointerLeave:fe,onFocus:_e=>{_e.target.matches(":focus-visible")&&de(0)},onBlur:fe,children:[o.jsxs("svg",{className:"ap-nav-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),o.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Local network"}),o.jsxs("span",{className:"ap-nav-state","data-tone":be.tone,children:[be.live&&o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),be.text]})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),R&&o.jsx(xU,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:Ne,onHold:Ce,onLet:fe}),o.jsx("p",{className:"vis-hidden",role:"status",children:ce.tone==="ok"?"":ce.text}),Le]})}return o.jsxs("div",{className:"ap-lan-view",children:[o.jsxs("div",{className:"ap-header",children:[o.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:s,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),o.jsx("h2",{id:"ap-lan-title",children:"Local network"}),o.jsxs("div",{className:"ap-header-right",children:[ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>j("add"),"aria-label":"Add a deck",title:(c==null?void 0:c.pairingMode)==="invite"?"Send an invite, or use one you were sent. This deck pairs only by invite.":"Reach a deck that has not turned up on its own — by address, or with an invite",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M6.1 7.9a2.6 2.6 0 0 0 3.7 0l1.9-1.9a2.6 2.6 0 0 0-3.7-3.7l-.9.9"}),o.jsx("path",{d:"M7.9 6.1a2.6 2.6 0 0 0-3.7 0L2.3 8a2.6 2.6 0 0 0 3.7 3.7l.9-.9"})]})}),ge&&se>0&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...X("check"),onClick:()=>void le(),"aria-label":h==="check"?"Checking every paired deck":"Check every paired deck now",title:"Ask every paired deck now for anything this deck's expired logins need, instead of waiting for the next round",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),o.jsx("path",{d:"M4.6 4.6a3.4 3.4 0 0 0 0 4.8M9.4 4.6a3.4 3.4 0 0 1 0 4.8"}),o.jsx("path",{d:"M2.6 2.6a6.2 6.2 0 0 0 0 8.8M11.4 2.6a6.2 6.2 0 0 1 0 8.8"})]})}),ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...X("setup"),onClick:()=>v(!0),"aria-label":"This deck's name and shared logins",title:"This deck's name on the network, and which of its logins it offers",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),o.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),o.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),l]})]}),o.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:o.jsxs("div",{className:"ap-lan",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ge,"aria-label":"Sync with paired decks",...X("switch"),onClick:()=>void D(),title:ge?"Stop talking to other decks. Nothing is shared while this is off.":"Let the decks you pair with repair this one's expired logins",children:o.jsx("span",{className:"switch-knob"})})]}),ge&&o.jsx(GM,{reach:c==null?void 0:c.reach,where:"panel"}),ge&&(c==null?void 0:c.deaf)&&o.jsx("p",{className:"ap-lan-fine",children:c.deaf}),ge&&(c==null?void 0:c.lanTunneled)&&o.jsx("p",{className:"ap-lan-fine",children:dU(c)}),!ge&&o.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>C(!0),title:"Four pictures: what this does, and what to do on each machine",children:[o.jsx(Oz,{}),o.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),o.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),o.jsx("p",{className:`ap-lan-status ${ce.tone}`,role:"status",children:ce.tone==="ok"?"":ce.text}),P&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:P}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>W(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ge&&o.jsxs(o.Fragment,{children:[Ge.length>0&&o.jsx("div",{className:"ap-lan-asks",role:"alert",children:Ge.map(de=>o.jsxs("div",{className:"ap-lan-ask",children:[o.jsxs("span",{className:"ap-lan-ask-what",children:[o.jsx("strong",{className:"ap-lan-peer-name",children:de.name})," at ",o.jsx("code",{className:"ap-lan-code",children:de.addr})," wants to pair"]}),o.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",o.jsx("code",{className:"ap-lan-code",children:de.fp})]}),o.jsxs("span",{className:"ap-lan-ask-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",...X(`accept:${de.fp}`),onClick:()=>void K("accept",de.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${de.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...X(`dismiss:${de.fp}`),onClick:()=>void K("dismiss",de.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},de.fp))}),(ue?[...ze,...Re]:ze).length>0&&o.jsx("ul",{className:"ap-lan-here",children:(ue?[...ze,...Re]:ze).map((de,fe)=>o.jsxs("li",{className:"ap-lan-who","data-tone":de.tone,children:[o.jsx("i",{className:de.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[de.name,de.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),o.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${fe}`,onClick:()=>Z(de.fp),children:o.jsxs("span",{className:"vis-hidden",children:[de.name,de.via==="tailscale"?", over Tailscale":"",", details"]})}),o.jsx("span",{id:`lan-who-state-${fe}`,className:de.quiet?"vis-hidden":"ap-lan-who-when",children:de.state}),de.kind==="nearby"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`accept:${de.fp}`),onClick:()=>void K("accept",de.fp,"reach that deck"),"aria-label":`Ask ${de.name} to pair`,title:`Send ${de.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${de.fp}.`,children:"ask"}),(de.kind==="nearby"||de.kind==="declined")&&(c==null?void 0:c.pairingMode)==="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do","aria-haspopup":"dialog",onClick:()=>j("invite"),"aria-label":`Invite ${de.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${de.name}.`,children:"invite"}),de.kind==="paired"&&o.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${S===de.fp?" armed":""}`,...X(`unpair:${de.fp}`),onClick:()=>{const Ce=Date.now(),pe=Au({armedFor:S,target:de.fp,armedAt:_.current,now:Ce,gapMs:Ou});if(pe==="arm"){b(de.fp),_.current=Ce,window.setTimeout(()=>b(_e=>_e===de.fp?null:_e),4e3);return}pe!=="ignore"&&(b(null),K("unpair",de.fp,"unpair that deck"))},"aria-label":S===de.fp?`Confirm unpairing ${de.name}`:`Unpair ${de.name}`,title:S===de.fp?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:S===de.fp?"confirm":"unpair"}),de.kind==="dialling"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`drop:${de.fp}`),onClick:()=>void re(de.fp),"aria-label":`Stop dialling ${de.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),de.kind==="declined"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`allow:${de.fp}`),onClick:()=>void K("allow",de.fp,"let that deck ask again"),"aria-label":`Let ${de.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${de.kind}:${de.fp}`))}),(ze.length>0&&Re.length>0||ge&&se>0)&&o.jsxs("div",{className:"ap-lan-tail",children:[ze.length>0&&Re.length>0&&o.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":q,onClick:()=>B(de=>!de),title:q?"Show only the decks that are on":`Show the ${Re.length} deck${Re.length===1?"":"s"} that are not responding right now`,children:[o.jsx("span",{className:`ap-lan-chev${q?" open":""}`,"aria-hidden":!0,children:"›"}),q?"fewer":`${Re.length} more`,!q&&st>0&&o.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",st," not responding"]})]}),ge&&se>0&&o.jsx("span",{className:"ap-lan-checked",children:fU(c==null?void 0:c.checkedAt,V,h==="check")})]}),Pe.length===0&&Ge.length===0&&!(c!=null&&c.stalled)&&!(c!=null&&c.deaf)&&!(c!=null&&c.lanTunneled)&&o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"ap-lan-fine",children:"No other deck yet. Decks on one network usually find each other on their own; when that has not happened, the link at the top of this view reaches one by address or by invite."}),o.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),Le]})}function NU({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const l=w.useRef(null),{title:c,shown:u,rest:f}=xz(n),p=w.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=Pb(m.getBoundingClientRect(),{width:h.offsetWidth,height:h.offsetHeight},{width:window.innerWidth,height:window.innerHeight});h.style.top=`${y.top}px`,h.style.left=`${y.left}px`,h.style.maxHeight=y.maxHeight==null?"":`${y.maxHeight}px`,h.dataset.side=y.side},[e]);return w.useLayoutEffect(()=>{p()}),w.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),On.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:c}),o.jsx("div",{className:"ap-peek-list",children:u.map(h=>o.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[o.jsx("span",{className:"ap-fold-name",children:h.name}),o.jsx("span",{className:"ap-fold-state","data-tone":h.ready?"ok":h.warn?"warn":"idle",children:h.ready?h.headroom==null?"not read yet":`${h.headroom}% free`:h.why})]},h.key))}),f&&o.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function SU({peers:e,strained:t,armed:n,threshold:r,open:s,onToggle:l}){const[c,u]=w.useState(!1),f=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(f.current),[]),w.useEffect(()=>{s&&(window.clearTimeout(f.current),u(!1))},[s]);const p=S=>{s||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!0),S))},h=()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!1),ZM)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},v=wz(e,{strained:t&&!s,armed:n,threshold:r});return o.jsxs("div",{className:"ap-rest",children:[o.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":s,"aria-controls":s?"ap-rest-panel":void 0,"aria-describedby":c?"ap-rest-peek":void 0,onClick:()=>{y(),l()},onPointerEnter:S=>{S.pointerType==="mouse"&&p(XM)},onPointerLeave:h,onFocus:S=>{S.target.matches(":focus-visible")&&p(0)},onBlur:h,children:[o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),o.jsx("span",{className:"ap-nav-state","data-tone":v.tone,children:v.text})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),c&&o.jsx(NU,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function jU(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const _U=1800;function EU({accounts:e,onClose:t,copyText:n}){const[r,s]=w.useState([]),[l,c]=w.useState(null),[u,f]=w.useState(!1),[p,h]=w.useState(null),[m,y]=w.useState(!1),[v,S]=w.useState(()=>Math.floor(Date.now()/1e3)),b=w.useRef(null),_=w.useRef(!1),k=mn(t,{focusRef:b});w.useEffect(()=>{if(!l)return;S(Math.floor(Date.now()/1e3));const P=window.setInterval(()=>S(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval(P)},[l]);const j=iz(e),E=lz(e,r),C=E.length===e.length,R=P=>s(W=>cz(W,P)),I=w.useCallback(async()=>{const P=uz(E);if(!Ps(_.current)||!P)return;_.current=!0,f(!0),h(null),y(!1);const W=await jU(P).catch(()=>null);if(_.current=!1,f(!1),!(W!=null&&W.ok)){h(Ol(W,"the share could not be made"));return}c({blob:W.blob,expiresAt:W.expiresAt,shared:W.shared??[],failed:W.failed??[]})},[e,E]),$=l?HM(l.expiresAt,v):null,q=($==null?void 0:$.tone)==="gone",B=(l==null?void 0:l.shared.length)??0;return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:k,className:"modal sa-modal",onClick:P=>P.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("h3",{children:"Share accounts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body sa-body",children:l?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:q?"This share has expired":B===1?"1 account, ready to paste":`${B} accounts, ready to paste`}),o.jsx("code",{className:`ap-share-blob${q?" sa-dead":""}`,children:l.blob}),o.jsxs("div",{className:"ap-share-foot",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:b,onClick:async()=>{if(q){c(null),I();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),_U))},children:q?"make a new share":m?"copied":`copy ${B===1?"the share":"all "+B}`}),o.jsxs("span",{className:"ap-manage-hint",title:"This text is the sign-in for every account in it. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the logins themselves are in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign those accounts out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:B===1?"this is the password":`this is ${B} passwords`})," · ",o.jsx("span",{className:`ap-share-expiry ${$==null?void 0:$.tone}`,children:$==null?void 0:$.text})]})]}),l.failed.length>0&&o.jsxs("div",{className:"sa-failed",role:"alert",children:[o.jsx("p",{className:"sa-failed-head",children:l.failed.length===1?"One account is not in this bundle:":`${l.failed.length} accounts are not in this bundle:`}),o.jsx("ul",{className:"sa-list",children:l.failed.map(P=>{var ne;const W=!!(P.email&&((ne=P.detail)!=null&&ne.includes(P.email)));return o.jsxs("li",{children:[!W&&o.jsx("span",{className:"sa-who",children:P.email||`account ${P.num}`}),o.jsx("span",{className:"sa-why",children:P.detail||"could not be exported"})]},`${P.num}-${P.email}`)})})]}),o.jsx("p",{className:"sa-note",children:q?o.jsx(o.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):o.jsxs(o.Fragment,{children:["Paste it into the other deck with ",o.jsx("strong",{children:"+"})," → ",o.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),o.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:"Nothing to share"}),o.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",o.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),o.jsx("div",{className:"sa-actions",children:o.jsx("button",{type:"button",className:"btn primary",ref:b,onClick:t,children:"Close"})})]}):o.jsxs("div",{className:"sa-step",children:[o.jsxs("h4",{children:["Which accounts go to the other ",hn,"?"]}),o.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:dz(E.length)}),o.jsx("ul",{className:"sa-list sa-pick",children:j.map(P=>o.jsx("li",{children:o.jsxs("label",{className:"sa-row",children:[o.jsx("input",{type:"checkbox",checked:E.includes(P.num),onChange:()=>R(P.num)}),o.jsx("span",{className:"sa-who",children:P.label}),P.sub&&o.jsx("span",{className:"sa-sub",children:P.sub})]})},P.num))}),p&&o.jsx("p",{className:"aa-err",children:p}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>s(C?e.map(P=>P.num):[]),children:C?"Clear all":"Select all"}),o.jsx("button",{type:"button",className:"btn primary",ref:b,...to(u,!E.length),onClick:I,children:u?"making the share…":E.length===0?"Share":E.length===1?"Share 1 account":`Share ${E.length} accounts`})]})]})})]})}),document.body)}function CU(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((s,l)=>s-l).map(s=>{const l=s===t?"here":n.has(s)?"swap":"free";return{slot:s,kind:l,label:l==="here"?`slot ${s}`:`slot ${s} · ${l}`}})}function TU(e,t,n){if(!(n!=null&&n.ok))return null;const r=Number.isInteger(n.to)?n.to:null;if(r==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const s=n.swapped===!0&&r!==t;return{menuFor:e.menuFor===t?r:s&&e.menuFor===r?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:s?{at:r,displaced:t}:null}}function RU(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function AU(e,t,n){var s;const r=((s=e.find(l=>l.slot===t))==null?void 0:s.kind)??"here";return r==="swap"?{label:"swap",done:"swapped",sends:!0,swaps:!0,title:`Send this account to slot ${t}. That slot is taken, so the two accounts trade places and the one standing there moves to slot ${n}.`}:r==="free"?{label:"move",done:"moved",sends:!0,swaps:!1,title:`Send this account to slot ${t}. That slot is empty, so no other account moves.`}:{label:"move",done:"here",sends:!1,swaps:!1,title:`This account already holds slot ${n}.`}}function MU(e,t){return{label:"save",done:"saved",sends:e!==t,swaps:!1,title:`Switch the active account out once it passes ${e}% of its limit.`}}function nj(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function IU(e){const t=e.filter(u=>!nj(u)),n=e.filter(u=>nj(u)),r=t.length?t:n,s=t.length?n:[],l=r.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of s)l&&u.pct<=l.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:r,rest:s,fuller:c,peak:c??l}}const $U="\0";function lf(e){const t=typeof e.email=="string"?e.email.trim():"";if(!t)return`slot:${e.num}`;const n=typeof e.org=="string"?e.org.trim():"";return`acct:${t}${$U}${n}`}function OU(e,t){const n=lf(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function LU(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(lf)),r=e.filter(s=>n.has(s));return r.length===e.length?e:r}const PU=64;function DU(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function FU(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}const qU=Object.freeze({text:"couldn't reach the deck server",reload:!0}),BU=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function rj(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function zU(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=$u(t.body);return{text:D0(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function sj(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}const aj=15e3,UU=8e3,HU=1800,WU=3e4,Mm=[70,80,85,90,95];function Im(e,t){return NM(t-Math.floor(e/1e3))}function VU(e,t){if(!e)return"";const n=Math.floor(e/1e3)-t;return n<=0?" · due":n<60?` · next in ${n}s`:` · next in ${Math.round(n/60)}m`}function uu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function GU(e,t){const n="The deck can still see this account — its live usage is being read — but claude-swap's own stored copy of the login was rejected, so these numbers stopped updating.";if((e==null?void 0:e.state)==="running")return{text:"resuming…",hint:`${n} The deck is re-capturing it from the login you already have. No sign-in, no switch.`};if((e==null?void 0:e.state)==="failed"){const r=Math.max(1,Math.ceil((e.retryAt/1e3-t)/60)),s=e.reason?`Re-capturing it from the login you already have did not work (${e.reason}).`:"The deck re-captured it from the login you already have, and claude-swap still cannot read it.";return{text:"numbers paused",hint:`${n} ${s} It tries again in ${r}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function KU(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function YU(e){switch(e){case"no_credentials":return{text:"no stored login",hint:"claude-swap holds no credentials for this account, so there is nothing to read its usage with and nothing to switch to. A paired deck that has them sends them on its own; signing in as this account puts them there by hand.",fix:"sign in"};case"relogin_required":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fix:"sign in again"};case"keychain_unavailable":return{text:"keychain unreadable",hint:"This is about the deck, not the account: claude-swap could not open your keychain, so it cannot read any account's stored login. A deck started from a background session cannot reach the keychain at all — start it from a terminal, or let it start at login, and this clears."};case"token_expired":return{text:"token expired",hint:"The access token ran out and the refresh was deferred. The next collection retries."};case"foreign_credential":return{text:"wrong credential",hint:"The live credential belongs to a different account. Switching to this one repairs it."};case null:case void 0:return null;default:return{text:e,hint:`claude-swap reported "${e}" for this account.`}}}function _h(e,t){if(e.staleCopy){const n=GU(e.repair??null,t);return{text:uu(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=YU(e.collector??null);if(!n)return{text:"Not collecting",hint:"claude-swap has collected nothing for this account in over half a day and has not said why. A paired deck holding a working copy of this account will replace it on its own. To do it by hand, sign in as this account from + Add.",fix:null,tone:"quiet",blocksSwitch:!1};const r=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:uu(n.text),hint:n.hint,fix:n.fix?uu(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=KU(e.error);return{text:uu(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function $m(){return o.jsxs("svg",{className:"ap-warn-glyph",width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),o.jsx("path",{d:"M7 5.6v2.9"}),o.jsx("path",{d:"M7 10.3v.05"})]})}function XU(e){return e>=90?"hi":e>=70?"mid":void 0}function ZU(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Mm.includes(t)?[...Mm,t]:Mm].sort((r,s)=>r-s)}function QU({lane:e,nowSec:t,frozen:n}){const r=Math.min(100,Math.max(0,e.pct)),s=n?"var(--muted)":r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",l=e.resetAt&&!n?SM(e.resetAt,t):null;return o.jsxs("div",{className:"ap-lane",children:[o.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),o.jsx("div",{className:"ap-lane-track",children:o.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:s,opacity:r===0||n?.4:1}})}),o.jsxs("span",{className:"ap-lane-pct",style:{color:s},children:[r,"%"]}),o.jsx("span",{className:"ap-lane-reset",title:l?`${e.label} resets in ${l}`:void 0,children:l&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"vis-hidden",children:"resets in "}),l]})})]})}function JU({onClose:e,leaving:t}){var xr,Pn,Hs;const[n,r]=w.useState(null),[s,l]=w.useState(null),[c,u]=w.useState(null),[f,p]=w.useState(!1),[h,m]=w.useState(null),[y,v]=w.useState(null),[S,b]=w.useState("accounts"),[_,k]=w.useState(!1),[j,E]=w.useState(null),C=w.useRef(j);C.current=j;const[R,I]=w.useState(()=>Math.floor(Date.now()/1e3)),$=w.useRef(null),[q,B]=w.useState(null),P=(q==null?void 0:q.num)??null,W=w.useRef(q);W.current=q;const[ne,ee]=w.useState(null),[M,X]=w.useState(!1),[V,G]=w.useState(""),[F,L]=w.useState(null),H=w.useRef(0),[D,K]=w.useState(null),[re,z]=w.useState(!1),[Z,U]=w.useState(!1),[ae,le]=w.useState(null),[ge,Ne]=w.useState(null),[Ie,Ge]=w.useState(null),[Pe,ze]=w.useState(null),[Re,st]=w.useState(!1),ue=w.useRef(null),ce=w.useRef(null),[se,be]=w.useState([]),[Le,de]=w.useState(!1),fe=w.useRef(null),Ce=w.useCallback(Q=>Mf(fe.current)?(fe.current=Q,u(Q),!0):!1,[]),pe=w.useCallback(()=>{fe.current=null,u(null)},[]),_e=(Q,De=!1)=>{const Je=lo(c,Q);return{disabled:Je.disabled,"aria-busy":Je.busy||De}},Ye=w.useCallback(Q=>{window.requestAnimationFrame(()=>{var De;if($0(((De=document.activeElement)==null?void 0:De.tagName)??null))for(const Je of h8(Q)){const He=document.querySelector(Je);if(He){He.focus();return}}})},[]),qe=w.useCallback(async(Q=!1)=>{Q&&p(!0);const De=new AbortController,Je=window.setTimeout(()=>De.abort(),WU);try{const[He,tt]=await Promise.all([fetch(`/api/claude-accounts${Q?"?refresh=1":""}`,{signal:De.signal}),fetch("/api/cswap-auto",{signal:De.signal})]);if(He.ok){const gt=await He.json();r(gt),be(At=>LU(At,gt.accounts))}tt.ok&&l(await tt.json());const wt=zU([await rj(He),await rj(tt)]);m(gt=>sj(gt,wt))}catch{m(He=>sj(He,De.signal.aborted?BU:qU))}finally{window.clearTimeout(Je),Q&&p(!1)}},[]),ke=w.useCallback(async(Q,De,Je="panel")=>{if(!Ce(De))return null;const He=Je==="menu"?ee:m;He(null);try{const tt=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),wt=await tt.json().catch(()=>null);return wt!=null&&wt.ok||He({text:D0(wt,"command failed",tt.status),raw:$u(wt)}),wt}catch{return He({text:"server unreachable"}),null}finally{pe()}},[Ce,pe]),Ae=w.useCallback(async(Q,De)=>{if(!Ce(De))return null;m(null),ee(null);try{const Je=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),He=await Je.json().catch(()=>null);return He!=null&&He.ok||ee({text:Ol(He,"command failed",Je.status)}),He}catch{return ee({text:"server unreachable"}),null}finally{pe()}},[Ce,pe]);w.useEffect(()=>(qe(!0),$.current=window.setInterval(()=>qe(!1),aj),()=>{$.current!=null&&window.clearInterval($.current)}),[qe]),w.useEffect(()=>{!(n!=null&&n.ok)||!n.accounts||v(Q=>FU(Q,n.accounts))},[n]),w.useEffect(()=>{const Q=window.setInterval(()=>I(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(Q)},[]);const Ue=((xr=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:xr.value)??"90",Fe=Pe??Ue,Ve=MU(Fe,Ue),rt=(Pn=n==null?void 0:n.accounts)==null?void 0:Pn.find(Q=>Q.active),ut=rt?_h(rt,R):null,ct=(n==null?void 0:n.accounts)??[],yt=rt?ct.filter(Q=>!Q.active):[],It=yt.length?ct.filter(Q=>Q.active):ct,zt=yt.map(Q=>{const De=_h(Q,R);return{key:lf(Q),name:Q.alias??Q.email??`account ${Q.num}`,ready:!Q.disabled&&!(De!=null&&De.blocksSwitch),why:Q.disabled?"held out":De!=null&&De.blocksSwitch?De.text:null,warn:(De==null?void 0:De.tone)==="warn",headroom:Q.headroom}}),Xt=Number(Ue),Ft=(rt==null?void 0:rt.headroom)!=null&&Number.isFinite(Xt)&&100-rt.headroom>=Xt,rn=(s==null?void 0:s.ok)===!0&&(s.enabled||s.external),Se=Q=>Le&&yt.some(De=>De.num===Q)?"ap-rest-list":"ap-scroll",vt=async(Q,De)=>{if(Ce(`switch-${Q}`)){m(null),v(null);try{const He=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:Q})})).json().catch(()=>null);He!=null&&He.ok?v({num:Q,name:De}):m({text:D0(He,"the switch failed"),raw:$u(He),row:Q}),await qe(!0)}catch{m({text:"server unreachable",row:Q})}finally{pe(),Ye(Q)}}},kt=w.useCallback(()=>{B(null),ee(null),L(null),K(null),U(!1)},[]),_n=(Q,De="first")=>{kt(),E(null),Ge(null),B({num:Q,view:"menu",start:De})},Ut=(Q,De)=>{kt(),E(Je=>(Je==null?void 0:Je.anchor)===De?null:{num:Q,anchor:De})},Vn=w.useCallback((Q=!1)=>{var Je;const De=C.current;Q&&De&&((Je=document.getElementById(De.anchor))==null||Je.focus()),E(null)},[]),Vt=()=>{kt(),E(null),b("lan")},$t=w.useRef(S);w.useEffect(()=>{$t.current!==S&&($t.current=S,window.requestAnimationFrame(()=>{var Q;(Q=document.getElementById(S==="lan"?"ap-lan-back":"ap-lan-entry"))==null||Q.focus()}))},[S]),w.useEffect(()=>{n!=null&&n.ok&&k(!0)},[n==null?void 0:n.ok]);const Zt=w.useCallback(Q=>{var He,tt;const De=W.current;if(!De||Q!=null&&De.num!==Q)return;const Je=document.getElementById(`ap-menu-${De.num}`);(Je!=null&&Je.contains(document.activeElement)||$0(((He=document.activeElement)==null?void 0:He.tagName)??null))&&((tt=document.getElementById(`ap-more-${De.num}`))==null||tt.focus()),kt()},[kt]);w.useEffect(()=>{t&&(kt(),E(null))},[t,kt]),w.useEffect(()=>{q&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===q.num)&&kt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===j.num)&&E(null)},[n,q,j,kt]);const Ln=async Q=>{var Je;U(!1);const De=await Ae({action:"share",account:Q},`share-${Q}`);!(De!=null&&De.ok)||((Je=W.current)==null?void 0:Je.num)!==Q||(K({num:Q,blob:De.blob,expiresAt:De.expiresAt}),B({num:Q,view:"share"}))},Ur=async(Q,De)=>{const{commit:Je,alias:He}=DU(V,De);if(Je){const tt=await Ae({action:"alias",account:Q,alias:He},`alias-${Q}`);if(await qe(!0),!(tt!=null&&tt.ok))return}Zt(Q)},xe=async(Q,De)=>{var tt,wt;const Je=await Ae({action:"move",account:Q,slot:De},`move-${Q}`),He=TU({menuFor:((tt=W.current)==null?void 0:tt.num)??null,shareFor:(D==null?void 0:D.num)??null},Q,Je);if(await qe(!0),He){((wt=W.current)==null?void 0:wt.num)===Q&&kt(),L(He.confirmRemove),He.shareFor==null&&(K(null),U(!1)),Ne(He.swapNote);const gt=He.swapNote;gt&&window.setTimeout(()=>Ne(At=>At===gt?null:At),UU),Ge(null),Ye(He.menuFor)}return Je},ir=async(Q,De,Je)=>{if(!Je.sends){Zt(Q);return}await xe(Q,De)},Ns=async(Q,De)=>{if(De.sends){const Je=await ke({action:"setting",key:"autoswitch.threshold",value:Q},"threshold");if(await qe(!0),!(Je!=null&&Je.ok))return;ze(null)}st(!0),window.setTimeout(()=>{var Je;document.activeElement===ce.current&&((Je=ue.current)==null||Je.focus()),st(!1)},HU)},Hr=o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),ma=Q=>{const{shown:De,fuller:Je}=IU(Q.lanes),He=_h(Q,R),tt=Q.active||se.includes(lf(Q)),wt=Q.alias??Q.email??`account ${Q.num}`,gt=Q.alias&&Q.email?`${Q.alias} · ${Q.email}`:wt,At=Q.stale||(He==null?void 0:He.blocksSwitch)===!0,Ct=Je?[...De,Je]:De,Qt=Q.fetchedAt?Im(Q.fetchedAt,R):null;return o.jsxs("li",{className:`ap-account${Q.active?" active":""}`,"aria-current":Q.active?"true":void 0,"data-open":tt?"":void 0,"data-frozen":At?"":void 0,children:[!Q.active&&o.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${Q.num}`,title:gt,"aria-expanded":tt,"aria-controls":tt?`ap-detail-${Q.num}`:void 0,"aria-describedby":[Q.alias&&Q.email?`ap-email-${Q.num}`:null,!tt&&!(He!=null&&He.blocksSwitch)?`ap-quota-${Q.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>be(St=>OU(St,Q)),children:o.jsxs("span",{className:"vis-hidden",children:[wt,", ",tt?"hide details":"details"]})}),o.jsxs("div",{className:"ap-account-head",children:[Q.active?o.jsx("span",{className:"ap-live",title:`Active account · slot ${Q.num}`,children:o.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",Q.num,":"]})}):o.jsx("span",{className:"ap-num",children:Q.num}),Q.alias&&o.jsx("span",{className:"ap-alias",title:Q.alias,children:Q.alias}),o.jsx("span",{className:"ap-email",id:`ap-email-${Q.num}`,title:Q.email??void 0,children:Q.email}),Q.disabled&&o.jsx("span",{className:"ap-held",children:"held out"}),!Q.active&&!Q.disabled&&!(He!=null&&He.blocksSwitch)&&o.jsx("button",{type:"button",className:"ap-switch",..._e(`switch-${Q.num}`),onClick:()=>vt(Q.num,wt),"aria-label":`Switch to ${wt}`,title:`Switch to ${Q.alias??Q.email}`,children:c===`switch-${Q.num}`?"…":"Switch"}),o.jsx("button",{type:"button",id:`ap-more-${Q.num}`,className:"ap-more","aria-label":`More actions for ${Q.email??Q.alias??`account ${Q.num}`}`,"aria-haspopup":"menu","aria-expanded":P===Q.num,"aria-controls":P===Q.num?`ap-menu-${Q.num}`:void 0,title:"More actions",onClick:()=>P===Q.num?Zt():_n(Q.num),onKeyDown:St=>{St.key!=="ArrowDown"&&St.key!=="ArrowUp"||(St.preventDefault(),_n(Q.num,St.key==="ArrowUp"?"last":"first"))},children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[o.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===Q.num&&o.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),Q.active&&(y==null?void 0:y.num)===Q.num&&o.jsx("p",{className:"ap-switched",children:"Now active. New sessions start on it; ones already running pick it up on their next message, up to about 30 seconds later on macOS."}),(ge==null?void 0:ge.at)===Q.num&&(()=>{const St=ct.find(lr=>lr.num===ge.displaced),br=(St==null?void 0:St.alias)??(St==null?void 0:St.email)??"the account that was there";return o.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${ge.at} was taken, so the two accounts traded places: ${br} now holds slot ${ge.displaced}.`,children:["swapped with slot ",ge.displaced]})})(),He&&o.jsxs("div",{className:"ap-issue-line",children:[o.jsxs("button",{type:"button",id:`ap-issue-${Q.num}`,className:"ap-issue","data-tone":He.tone,"aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`,"aria-controls":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`?"ap-issue-pop":void 0,onClick:()=>Ut(Q.num,`ap-issue-${Q.num}`),children:[He.tone==="warn"&&o.jsx($m,{}),o.jsx("span",{className:"ap-issue-text",children:He.text})]}),!tt&&o.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),!tt&&!(He!=null&&He.blocksSwitch)&&o.jsxs("p",{className:"ap-quota",id:`ap-quota-${Q.num}`,children:[Ct.length?Ct.map(St=>o.jsxs("span",{className:"ap-q",children:[o.jsx("span",{className:"ap-q-label",children:St.label})," ",o.jsxs("span",{className:"ap-q-pct","data-level":At?void 0:XU(St.pct),children:[Math.round(St.pct),"%"]})]},St.id)):o.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),Q.stale&&!He&&o.jsx("span",{className:"ap-q-age","data-never":Qt?void 0:"",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),tt&&o.jsxs("div",{className:"ap-detail",id:`ap-detail-${Q.num}`,children:[o.jsx("div",{className:"ap-lanes",children:Q.lanes.length?Q.lanes.map(St=>o.jsx(QU,{lane:St,nowSec:R,frozen:At},St.id)):o.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),o.jsx("div",{className:"ap-meta",children:Q.fetchedAt?o.jsxs("span",{className:`ap-age${Q.stale&&!He?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",Im(Q.fetchedAt,R),He!=null&&He.blocksSwitch?"":VU(Q.nextAt,R)]}):o.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},Q.num)},Ss=n!=null&&n.ok&&(s!=null&&s.ok)?o.jsxs("div",{className:"ap-policy-block",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),o.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:o.jsx("select",{ref:ue,"aria-label":"Switch threshold",value:Fe,..._e("threshold"),onChange:Q=>ze(Q.target.value),children:ZU(Ue).map(Q=>o.jsxs("option",{value:Q,children:[Q,"%"]},Q))})}),(Ve.sends||Re)&&o.jsx("button",{ref:ce,type:"button",className:"ap-manage-btn",..._e("threshold"),title:Ve.title,onClick:()=>Ns(Fe,Ve),children:Re&&!Ve.sends?Ve.done:Ve.label}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":s.enabled,"aria-label":"Auto-switch",..._e("enable"),onClick:()=>ke({action:"enable",enabled:!s.enabled},"enable").then(()=>qe(!0)),title:s.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:o.jsx("span",{className:"switch-knob"})})]}),s.external&&o.jsxs("p",{className:"ap-auto-note",children:[o.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",o.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",s.enabled?" — this toggle takes over when you stop it.":"."]})]}):null;return o.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[S==="accounts"&&o.jsxs("div",{className:"ap-header",children:[o.jsx("h2",{children:"Claude accounts"}),o.jsxs("div",{className:"ap-header-right",children:[o.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>X(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((Hs=n==null?void 0:n.accounts)==null?void 0:Hs.length)??0)>0&&o.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>z(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${hn} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),o.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),o.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>qe(!0),..._e("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),o.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),Hr]})]}),S==="accounts"&&o.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?o.jsxs("div",{className:"ap-empty",role:"alert",children:[o.jsx("span",{title:h.raw||void 0,children:h.text}),o.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",aj/1e3," seconds."]}),o.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>qe(!0),children:f?"trying…":"try again"})]}):o.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?o.jsxs(o.Fragment,{children:[rt&&(ut==null?void 0:ut.tone)==="warn"&&o.jsxs("div",{className:"ap-notice",children:[o.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)==="ap-notice","aria-controls":(j==null?void 0:j.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>Ut(rt.num,"ap-notice"),children:[o.jsx($m,{}),o.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),ut.fix&&o.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>X(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),o.jsx("ul",{className:"ap-list",children:It.map(ma)}),yt.length>0&&o.jsx(SU,{peers:zt,strained:Ft,armed:rn,threshold:s!=null&&s.ok?Ue:null,open:Le,onToggle:()=>de(Q=>!Q)}),yt.length>0&&Le&&o.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[o.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",children:yt.map(ma)}),Ss]}),yt.length===0&&Ss,h&&h.row==null&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),q&&(()=>{var He;const Q=(He=n.accounts)==null?void 0:He.find(tt=>tt.num===q.num);if(!Q)return null;const De=`ap-pop-title-${Q.num}`,Je=ne&&o.jsx("p",{className:"ap-pop-error",role:"alert",title:ne.raw||void 0,children:ne.text});return o.jsxs(O0,{anchorId:`ap-more-${Q.num}`,boundaryId:Se(Q.num),id:`ap-menu-${Q.num}`,className:"ap-pop",role:q.view==="menu"?"menu":"dialog",labelledBy:q.view==="menu"?`ap-more-${Q.num}`:De,start:q.start,onClose:kt,children:[q.view==="menu"&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{G(Q.alias??""),ee(null),B({num:Q.num,view:"rename"})},children:"Rename"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{Ge(null),ee(null),B({num:Q.num,view:"move"})},children:"Move to slot…"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",..._e(`share-${Q.num}`),title:`Copy this account to another ${hn}. Anyone who has the text can use the account — treat it as the password. The other deck stops accepting it after 10 minutes; that does not make an escaped copy safe.`,onClick:()=>Ln(Q.num),children:c===`share-${Q.num}`?"Sharing…":"Share"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",title:"See how much this account worked in each project",onClick:()=>{le(Q.num),Zt(Q.num)},children:"Projects"}),(((s==null?void 0:s.enabled)||(s==null?void 0:s.external))&&!Q.active||Q.disabled)&&o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",..._e(`rot-${Q.num}`),title:Q.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>ke({action:"account",account:Q.num,enabled:Q.disabled},`rot-${Q.num}`,"menu").then(tt=>{qe(!0),tt!=null&&tt.ok&&Zt(Q.num)}),children:Q.disabled?"Put back in rotation":"Hold out of rotation"}),o.jsx("div",{role:"separator",className:"ap-menu-sep"}),o.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${F===Q.num?" armed":""}`,..._e(`rm-${Q.num}`),"aria-label":F===Q.num?"Confirm remove":void 0,title:F===Q.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{const tt=Date.now(),wt=Au({armedFor:F,target:Q.num,armedAt:H.current,now:tt,gapMs:Ou});if(wt==="arm"){L(Q.num),H.current=tt,window.setTimeout(()=>L(gt=>gt===Q.num?null:gt),4e3);return}wt!=="ignore"&&(L(null),Ae({action:"remove",account:Q.num},`rm-${Q.num}`).then(gt=>{var At;qe(!0),gt!=null&&gt.ok&&(((At=W.current)==null?void 0:At.num)===Q.num&&kt(),Ye(null))}))},children:c===`rm-${Q.num}`?"Removing…":F===Q.num?"Confirm":"Remove"}),Je]}),q.view==="rename"&&o.jsxs("form",{className:"ap-pop-form",onSubmit:tt=>{tt.preventDefault(),Ur(Q.num,Q.alias)},children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-alias-${Q.num}`,children:"Rename account"}),o.jsx("input",{id:`ap-alias-${Q.num}`,className:"ap-manage-input",type:"text",value:V,onChange:tt=>G(tt.target.value),maxLength:PU,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:tt=>tt.currentTarget.select()}),Je,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"submit",className:"btn primary",..._e(`alias-${Q.num}`),title:"A short name to show instead of the email",children:c===`alias-${Q.num}`?"…":"Save"})]})]}),q.view==="move"&&(()=>{const tt=CU((n.accounts??[]).map(At=>At.num),Q.num),wt=RU(tt,Ie,Q.num),gt=AU(tt,wt,Q.num);return o.jsxs("div",{className:"ap-pop-form",children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-slot-${Q.num}`,children:"Move to slot"}),o.jsx("span",{className:"ap-field",children:o.jsx("select",{id:`ap-slot-${Q.num}`,value:String(wt),..._e(`move-${Q.num}`),onChange:At=>Ge(Number(At.target.value)),autoFocus:!0,children:tt.map(At=>o.jsx("option",{value:At.slot,children:At.label},At.slot))})}),Je,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"button",className:"btn primary",..._e(`move-${Q.num}`),title:gt.title,onClick:()=>ir(Q.num,wt,gt),children:c===`move-${Q.num}`?"…":uu(gt.label)})]})]})})(),q.view==="share"&&(D==null?void 0:D.num)===Q.num&&(()=>{const tt=HM(D.expiresAt,R),wt=tt.tone==="gone";return o.jsxs("div",{className:`ap-pop-form ap-share${wt?" expired":""}`,children:[o.jsx("p",{className:"ap-pop-title",id:De,children:"Share account"}),o.jsx("code",{className:"ap-share-blob",children:D.blob}),o.jsxs("p",{className:"ap-pop-note",title:"This text is the account's password. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the login itself is in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign the account out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",o.jsx("span",{className:`ap-share-expiry ${tt.tone}`,children:tt.text})]}),Je,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Done"}),o.jsx("button",{type:"button",className:"btn primary",..._e(`share-${Q.num}`),autoFocus:!0,onClick:async()=>{if(wt){await Ln(Q.num);return}await yi(D.blob)&&(U(!0),window.setTimeout(()=>U(!1),1800))},children:wt?"Make a new share":Z?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var Je;const Q=(Je=n.accounts)==null?void 0:Je.find(He=>He.num===j.num),De=Q?_h(Q,R):null;return!Q||!De?null:o.jsx(O0,{anchorId:j.anchor,boundaryId:j.anchor==="ap-notice"?"ap-scroll":Se(Q.num),id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>Vn(),children:o.jsxs("div",{className:"ap-pop-form",children:[o.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":De.tone,children:[De.tone==="warn"&&o.jsx($m,{}),De.text]}),o.jsx("p",{className:"ap-pop-note ap-issue-hint",children:De.hint}),o.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[o.jsx("span",{className:"ap-issue-who",children:Q.alias??Q.email??`account ${Q.num}`})," · ",Q.fetchedAt?`last collected ${Im(Q.fetchedAt,R)}`:"never collected"]}),o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Vn(!0),children:"Done"}),De.fix&&o.jsx("button",{type:"button",className:"btn primary",onClick:()=>{Vn(!0),X(!0)},title:"Open the sign-in dialog. Signing in as this account puts its login back in this slot — it keeps its slot, its alias and its history.",children:De.fix})]})]})})})()]}):o.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"claude-swap isn't installed."}),o.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&o.jsx("code",{className:"ap-cmd",children:n.hint}),o.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",o.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"No accounts added yet."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",o.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"Couldn't read the account store."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),_&&o.jsx(kU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({key:`${String(Q.email??"").trim().toLowerCase()}@@${Q.orgUuid??""}`,email:Q.email??"",alive:Q.alive===!0,shareable:Q.collector==="ok"||Q.collector==null&&!Q.active})),onChanged:()=>qe(!0),view:S==="lan",onOpen:Vt,onBack:()=>b("accounts"),closeButton:Hr}),M&&o.jsx(gz,{onClose:()=>X(!1),onChanged:()=>qe(!0)}),re&&o.jsx(EU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({num:Q.num,email:Q.email,alias:Q.alias,org:Q.org})),onClose:()=>z(!1),copyText:yi}),ae!=null&&(()=>{const Q=((n==null?void 0:n.accounts)??[]).find(De=>De.num===ae);return Q?o.jsx(LB,{num:Q.num,name:Q.alias??Q.email??`account ${Q.num}`,onClose:()=>le(null)}):(le(null),null)})()]})}const eH=3e4;function tH({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function nH({bundle:e,running:t,pending:n,lastTried:r}){return t?tH({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function rH(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function sH({asked:e,reported:t}){return t?t!==e:!1}function QM(e){const t=e.thresholdMs??eH;return!e.enabled||e.kind!=="restart"||!e.canRestart||!e.noticeOpen||!e.visible||e.busy?null:e.idleSince==null||e.now<e.idleSince?t:Math.max(0,t-(e.now-e.idleSince))}function aH(e){const t=Math.max(0,Math.ceil(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function oH(e,t){return e?t==null?"auto when idle":`auto in ${aH(t)}`:"auto-restart off"}function oj(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function iH(e){return e<=0?{label:"Restart now",clause:"nothing is running"}:{label:"Restart anyway",clause:`${e===1?"1 agent is running":`${e} agents are running`} — their events during the restart are lost`}}function lH(e){const t=QM(e);return t==null?{idleSince:null,restart:!1,remainingMs:null}:e.idleSince==null||e.now<e.idleSince?{idleSince:e.now,restart:!1,remainingMs:t}:{idleSince:e.idleSince,restart:t===0,remainingMs:t}}function Wb(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Om,ij;function cH(){if(ij)return Om;ij=1;function e(){this.__data__=[],this.size=0}return Om=e,Om}var Lm,lj;function sc(){if(lj)return Lm;lj=1;function e(t,n){return t===n||t!==t&&n!==n}return Lm=e,Lm}var Pm,cj;function Of(){if(cj)return Pm;cj=1;var e=sc();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return Pm=t,Pm}var Dm,uj;function uH(){if(uj)return Dm;uj=1;var e=Of(),t=Array.prototype,n=t.splice;function r(s){var l=this.__data__,c=e(l,s);if(c<0)return!1;var u=l.length-1;return c==u?l.pop():n.call(l,c,1),--this.size,!0}return Dm=r,Dm}var Fm,dj;function dH(){if(dj)return Fm;dj=1;var e=Of();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Fm=t,Fm}var qm,hj;function hH(){if(hj)return qm;hj=1;var e=Of();function t(n){return e(this.__data__,n)>-1}return qm=t,qm}var Bm,fj;function fH(){if(fj)return Bm;fj=1;var e=Of();function t(n,r){var s=this.__data__,l=e(s,n);return l<0?(++this.size,s.push([n,r])):s[l][1]=r,this}return Bm=t,Bm}var zm,pj;function Lf(){if(pj)return zm;pj=1;var e=cH(),t=uH(),n=dH(),r=hH(),s=fH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,zm=l,zm}var Um,mj;function pH(){if(mj)return Um;mj=1;var e=Lf();function t(){this.__data__=new e,this.size=0}return Um=t,Um}var Hm,gj;function mH(){if(gj)return Hm;gj=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Hm=e,Hm}var Wm,yj;function gH(){if(yj)return Wm;yj=1;function e(t){return this.__data__.get(t)}return Wm=e,Wm}var Vm,wj;function yH(){if(wj)return Vm;wj=1;function e(t){return this.__data__.has(t)}return Vm=e,Vm}var Gm,vj;function JM(){if(vj)return Gm;vj=1;var e=typeof rh=="object"&&rh&&rh.Object===Object&&rh;return Gm=e,Gm}var Km,xj;function ks(){if(xj)return Km;xj=1;var e=JM(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Km=n,Km}var Ym,bj;function ac(){if(bj)return Ym;bj=1;var e=ks(),t=e.Symbol;return Ym=t,Ym}var Xm,kj;function wH(){if(kj)return Xm;kj=1;var e=ac(),t=Object.prototype,n=t.hasOwnProperty,r=t.toString,s=e?e.toStringTag:void 0;function l(c){var u=n.call(c,s),f=c[s];try{c[s]=void 0;var p=!0}catch{}var h=r.call(c);return p&&(u?c[s]=f:delete c[s]),h}return Xm=l,Xm}var Zm,Nj;function vH(){if(Nj)return Zm;Nj=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Zm=n,Zm}var Qm,Sj;function Si(){if(Sj)return Qm;Sj=1;var e=ac(),t=wH(),n=vH(),r="[object Null]",s="[object Undefined]",l=e?e.toStringTag:void 0;function c(u){return u==null?u===void 0?s:r:l&&l in Object(u)?t(u):n(u)}return Qm=c,Qm}var Jm,jj;function Br(){if(jj)return Jm;jj=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return Jm=e,Jm}var eg,_j;function Vu(){if(_j)return eg;_j=1;var e=Si(),t=Br(),n="[object AsyncFunction]",r="[object Function]",s="[object GeneratorFunction]",l="[object Proxy]";function c(u){if(!t(u))return!1;var f=e(u);return f==r||f==s||f==n||f==l}return eg=c,eg}var tg,Ej;function xH(){if(Ej)return tg;Ej=1;var e=ks(),t=e["__core-js_shared__"];return tg=t,tg}var ng,Cj;function bH(){if(Cj)return ng;Cj=1;var e=xH(),t=(function(){var r=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""})();function n(r){return!!t&&t in r}return ng=n,ng}var rg,Tj;function eI(){if(Tj)return rg;Tj=1;var e=Function.prototype,t=e.toString;function n(r){if(r!=null){try{return t.call(r)}catch{}try{return r+""}catch{}}return""}return rg=n,rg}var sg,Rj;function kH(){if(Rj)return sg;Rj=1;var e=Vu(),t=bH(),n=Br(),r=eI(),s=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,f=c.toString,p=u.hasOwnProperty,h=RegExp("^"+f.call(p).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!n(y)||t(y))return!1;var v=e(y)?h:l;return v.test(r(y))}return sg=m,sg}var ag,Aj;function NH(){if(Aj)return ag;Aj=1;function e(t,n){return t==null?void 0:t[n]}return ag=e,ag}var og,Mj;function ji(){if(Mj)return og;Mj=1;var e=kH(),t=NH();function n(r,s){var l=t(r,s);return e(l)?l:void 0}return og=n,og}var ig,Ij;function Vb(){if(Ij)return ig;Ij=1;var e=ji(),t=ks(),n=e(t,"Map");return ig=n,ig}var lg,$j;function Pf(){if($j)return lg;$j=1;var e=ji(),t=e(Object,"create");return lg=t,lg}var cg,Oj;function SH(){if(Oj)return cg;Oj=1;var e=Pf();function t(){this.__data__=e?e(null):{},this.size=0}return cg=t,cg}var ug,Lj;function jH(){if(Lj)return ug;Lj=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return ug=e,ug}var dg,Pj;function _H(){if(Pj)return dg;Pj=1;var e=Pf(),t="__lodash_hash_undefined__",n=Object.prototype,r=n.hasOwnProperty;function s(l){var c=this.__data__;if(e){var u=c[l];return u===t?void 0:u}return r.call(c,l)?c[l]:void 0}return dg=s,dg}var hg,Dj;function EH(){if(Dj)return hg;Dj=1;var e=Pf(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var l=this.__data__;return e?l[s]!==void 0:n.call(l,s)}return hg=r,hg}var fg,Fj;function CH(){if(Fj)return fg;Fj=1;var e=Pf(),t="__lodash_hash_undefined__";function n(r,s){var l=this.__data__;return this.size+=this.has(r)?0:1,l[r]=e&&s===void 0?t:s,this}return fg=n,fg}var pg,qj;function TH(){if(qj)return pg;qj=1;var e=SH(),t=jH(),n=_H(),r=EH(),s=CH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,pg=l,pg}var mg,Bj;function RH(){if(Bj)return mg;Bj=1;var e=TH(),t=Lf(),n=Vb();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return mg=r,mg}var gg,zj;function AH(){if(zj)return gg;zj=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return gg=e,gg}var yg,Uj;function Df(){if(Uj)return yg;Uj=1;var e=AH();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return yg=t,yg}var wg,Hj;function MH(){if(Hj)return wg;Hj=1;var e=Df();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return wg=t,wg}var vg,Wj;function IH(){if(Wj)return vg;Wj=1;var e=Df();function t(n){return e(this,n).get(n)}return vg=t,vg}var xg,Vj;function $H(){if(Vj)return xg;Vj=1;var e=Df();function t(n){return e(this,n).has(n)}return xg=t,xg}var bg,Gj;function OH(){if(Gj)return bg;Gj=1;var e=Df();function t(n,r){var s=e(this,n),l=s.size;return s.set(n,r),this.size+=s.size==l?0:1,this}return bg=t,bg}var kg,Kj;function Gb(){if(Kj)return kg;Kj=1;var e=RH(),t=MH(),n=IH(),r=$H(),s=OH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,kg=l,kg}var Ng,Yj;function LH(){if(Yj)return Ng;Yj=1;var e=Lf(),t=Vb(),n=Gb(),r=200;function s(l,c){var u=this.__data__;if(u instanceof e){var f=u.__data__;if(!t||f.length<r-1)return f.push([l,c]),this.size=++u.size,this;u=this.__data__=new n(f)}return u.set(l,c),this.size=u.size,this}return Ng=s,Ng}var Sg,Xj;function Ff(){if(Xj)return Sg;Xj=1;var e=Lf(),t=pH(),n=mH(),r=gH(),s=yH(),l=LH();function c(u){var f=this.__data__=new e(u);this.size=f.size}return c.prototype.clear=t,c.prototype.delete=n,c.prototype.get=r,c.prototype.has=s,c.prototype.set=l,Sg=c,Sg}var jg,Zj;function Kb(){if(Zj)return jg;Zj=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s&&n(t[r],r,t)!==!1;);return t}return jg=e,jg}var _g,Qj;function tI(){if(Qj)return _g;Qj=1;var e=ji(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return _g=t,_g}var Eg,Jj;function qf(){if(Jj)return Eg;Jj=1;var e=tI();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Eg=t,Eg}var Cg,e_;function Bf(){if(e_)return Cg;e_=1;var e=qf(),t=sc(),n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u){var f=l[c];(!(r.call(l,c)&&t(f,u))||u===void 0&&!(c in l))&&e(l,c,u)}return Cg=s,Cg}var Tg,t_;function Gu(){if(t_)return Tg;t_=1;var e=Bf(),t=qf();function n(r,s,l,c){var u=!l;l||(l={});for(var f=-1,p=s.length;++f<p;){var h=s[f],m=c?c(l[h],r[h],h,l,r):void 0;m===void 0&&(m=r[h]),u?t(l,h,m):e(l,h,m)}return l}return Tg=n,Tg}var Rg,n_;function PH(){if(n_)return Rg;n_=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Rg=e,Rg}var Ag,r_;function Us(){if(r_)return Ag;r_=1;function e(t){return t!=null&&typeof t=="object"}return Ag=e,Ag}var Mg,s_;function DH(){if(s_)return Mg;s_=1;var e=Si(),t=Us(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Mg=r,Mg}var Ig,a_;function Ku(){if(a_)return Ig;a_=1;var e=DH(),t=Us(),n=Object.prototype,r=n.hasOwnProperty,s=n.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(c){return t(c)&&r.call(c,"callee")&&!s.call(c,"callee")};return Ig=l,Ig}var $g,o_;function nn(){if(o_)return $g;o_=1;var e=Array.isArray;return $g=e,$g}var du={exports:{}},Og,i_;function FH(){if(i_)return Og;i_=1;function e(){return!1}return Og=e,Og}du.exports;var l_;function oc(){return l_||(l_=1,(function(e,t){var n=ks(),r=FH(),s=t&&!t.nodeType&&t,l=s&&!0&&e&&!e.nodeType&&e,c=l&&l.exports===s,u=c?n.Buffer:void 0,f=u?u.isBuffer:void 0,p=f||r;e.exports=p})(du,du.exports)),du.exports}var Lg,c_;function zf(){if(c_)return Lg;c_=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function n(r,s){var l=typeof r;return s=s??e,!!s&&(l=="number"||l!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r<s}return Lg=n,Lg}var Pg,u_;function Yb(){if(u_)return Pg;u_=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return Pg=t,Pg}var Dg,d_;function qH(){if(d_)return Dg;d_=1;var e=Si(),t=Yb(),n=Us(),r="[object Arguments]",s="[object Array]",l="[object Boolean]",c="[object Date]",u="[object Error]",f="[object Function]",p="[object Map]",h="[object Number]",m="[object Object]",y="[object RegExp]",v="[object Set]",S="[object String]",b="[object WeakMap]",_="[object ArrayBuffer]",k="[object DataView]",j="[object Float32Array]",E="[object Float64Array]",C="[object Int8Array]",R="[object Int16Array]",I="[object Int32Array]",$="[object Uint8Array]",q="[object Uint8ClampedArray]",B="[object Uint16Array]",P="[object Uint32Array]",W={};W[j]=W[E]=W[C]=W[R]=W[I]=W[$]=W[q]=W[B]=W[P]=!0,W[r]=W[s]=W[_]=W[l]=W[k]=W[c]=W[u]=W[f]=W[p]=W[h]=W[m]=W[y]=W[v]=W[S]=W[b]=!1;function ne(ee){return n(ee)&&t(ee.length)&&!!W[e(ee)]}return Dg=ne,Dg}var Fg,h_;function Uf(){if(h_)return Fg;h_=1;function e(t){return function(n){return t(n)}}return Fg=e,Fg}var hu={exports:{}};hu.exports;var f_;function Xb(){return f_||(f_=1,(function(e,t){var n=JM(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l&&n.process,u=(function(){try{var f=s&&s.require&&s.require("util").types;return f||c&&c.binding&&c.binding("util")}catch{}})();e.exports=u})(hu,hu.exports)),hu.exports}var qg,p_;function Yu(){if(p_)return qg;p_=1;var e=qH(),t=Uf(),n=Xb(),r=n&&n.isTypedArray,s=r?t(r):e;return qg=s,qg}var Bg,m_;function nI(){if(m_)return Bg;m_=1;var e=PH(),t=Ku(),n=nn(),r=oc(),s=zf(),l=Yu(),c=Object.prototype,u=c.hasOwnProperty;function f(p,h){var m=n(p),y=!m&&t(p),v=!m&&!y&&r(p),S=!m&&!y&&!v&&l(p),b=m||y||v||S,_=b?e(p.length,String):[],k=_.length;for(var j in p)(h||u.call(p,j))&&!(b&&(j=="length"||v&&(j=="offset"||j=="parent")||S&&(j=="buffer"||j=="byteLength"||j=="byteOffset")||s(j,k)))&&_.push(j);return _}return Bg=f,Bg}var zg,g_;function Hf(){if(g_)return zg;g_=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return zg=t,zg}var Ug,y_;function rI(){if(y_)return Ug;y_=1;function e(t,n){return function(r){return t(n(r))}}return Ug=e,Ug}var Hg,w_;function BH(){if(w_)return Hg;w_=1;var e=rI(),t=e(Object.keys,Object);return Hg=t,Hg}var Wg,v_;function Zb(){if(v_)return Wg;v_=1;var e=Hf(),t=BH(),n=Object.prototype,r=n.hasOwnProperty;function s(l){if(!e(l))return t(l);var c=[];for(var u in Object(l))r.call(l,u)&&u!="constructor"&&c.push(u);return c}return Wg=s,Wg}var Vg,x_;function fa(){if(x_)return Vg;x_=1;var e=Vu(),t=Yb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Vg=n,Vg}var Gg,b_;function co(){if(b_)return Gg;b_=1;var e=nI(),t=Zb(),n=fa();function r(s){return n(s)?e(s):t(s)}return Gg=r,Gg}var Kg,k_;function zH(){if(k_)return Kg;k_=1;var e=Gu(),t=co();function n(r,s){return r&&e(s,t(s),r)}return Kg=n,Kg}var Yg,N_;function UH(){if(N_)return Yg;N_=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Yg=e,Yg}var Xg,S_;function HH(){if(S_)return Xg;S_=1;var e=Br(),t=Hf(),n=UH(),r=Object.prototype,s=r.hasOwnProperty;function l(c){if(!e(c))return n(c);var u=t(c),f=[];for(var p in c)p=="constructor"&&(u||!s.call(c,p))||f.push(p);return f}return Xg=l,Xg}var Zg,j_;function _i(){if(j_)return Zg;j_=1;var e=nI(),t=HH(),n=fa();function r(s){return n(s)?e(s,!0):t(s)}return Zg=r,Zg}var Qg,__;function WH(){if(__)return Qg;__=1;var e=Gu(),t=_i();function n(r,s){return r&&e(s,t(s),r)}return Qg=n,Qg}var fu={exports:{}};fu.exports;var E_;function sI(){return E_||(E_=1,(function(e,t){var n=ks(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l?n.Buffer:void 0,u=c?c.allocUnsafe:void 0;function f(p,h){if(h)return p.slice();var m=p.length,y=u?u(m):new p.constructor(m);return p.copy(y),y}e.exports=f})(fu,fu.exports)),fu.exports}var Jg,C_;function aI(){if(C_)return Jg;C_=1;function e(t,n){var r=-1,s=t.length;for(n||(n=Array(s));++r<s;)n[r]=t[r];return n}return Jg=e,Jg}var ey,T_;function oI(){if(T_)return ey;T_=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=0,c=[];++r<s;){var u=t[r];n(u,r,t)&&(c[l++]=u)}return c}return ey=e,ey}var ty,R_;function iI(){if(R_)return ty;R_=1;function e(){return[]}return ty=e,ty}var ny,A_;function Qb(){if(A_)return ny;A_=1;var e=oI(),t=iI(),n=Object.prototype,r=n.propertyIsEnumerable,s=Object.getOwnPropertySymbols,l=s?function(c){return c==null?[]:(c=Object(c),e(s(c),function(u){return r.call(c,u)}))}:t;return ny=l,ny}var ry,M_;function VH(){if(M_)return ry;M_=1;var e=Gu(),t=Qb();function n(r,s){return e(r,t(r),s)}return ry=n,ry}var sy,I_;function Jb(){if(I_)return sy;I_=1;function e(t,n){for(var r=-1,s=n.length,l=t.length;++r<s;)t[l+r]=n[r];return t}return sy=e,sy}var ay,$_;function Wf(){if($_)return ay;$_=1;var e=rI(),t=e(Object.getPrototypeOf,Object);return ay=t,ay}var oy,O_;function lI(){if(O_)return oy;O_=1;var e=Jb(),t=Wf(),n=Qb(),r=iI(),s=Object.getOwnPropertySymbols,l=s?function(c){for(var u=[];c;)e(u,n(c)),c=t(c);return u}:r;return oy=l,oy}var iy,L_;function GH(){if(L_)return iy;L_=1;var e=Gu(),t=lI();function n(r,s){return e(r,t(r),s)}return iy=n,iy}var ly,P_;function cI(){if(P_)return ly;P_=1;var e=Jb(),t=nn();function n(r,s,l){var c=s(r);return t(r)?c:e(c,l(r))}return ly=n,ly}var cy,D_;function uI(){if(D_)return cy;D_=1;var e=cI(),t=Qb(),n=co();function r(s){return e(s,n,t)}return cy=r,cy}var uy,F_;function KH(){if(F_)return uy;F_=1;var e=cI(),t=lI(),n=_i();function r(s){return e(s,n,t)}return uy=r,uy}var dy,q_;function YH(){if(q_)return dy;q_=1;var e=ji(),t=ks(),n=e(t,"DataView");return dy=n,dy}var hy,B_;function XH(){if(B_)return hy;B_=1;var e=ji(),t=ks(),n=e(t,"Promise");return hy=n,hy}var fy,z_;function dI(){if(z_)return fy;z_=1;var e=ji(),t=ks(),n=e(t,"Set");return fy=n,fy}var py,U_;function ZH(){if(U_)return py;U_=1;var e=ji(),t=ks(),n=e(t,"WeakMap");return py=n,py}var my,H_;function ic(){if(H_)return my;H_=1;var e=YH(),t=Vb(),n=XH(),r=dI(),s=ZH(),l=Si(),c=eI(),u="[object Map]",f="[object Object]",p="[object Promise]",h="[object Set]",m="[object WeakMap]",y="[object DataView]",v=c(e),S=c(t),b=c(n),_=c(r),k=c(s),j=l;return(e&&j(new e(new ArrayBuffer(1)))!=y||t&&j(new t)!=u||n&&j(n.resolve())!=p||r&&j(new r)!=h||s&&j(new s)!=m)&&(j=function(E){var C=l(E),R=C==f?E.constructor:void 0,I=R?c(R):"";if(I)switch(I){case v:return y;case S:return u;case b:return p;case _:return h;case k:return m}return C}),my=j,my}var gy,W_;function QH(){if(W_)return gy;W_=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r){var s=r.length,l=new r.constructor(s);return s&&typeof r[0]=="string"&&t.call(r,"index")&&(l.index=r.index,l.input=r.input),l}return gy=n,gy}var yy,V_;function hI(){if(V_)return yy;V_=1;var e=ks(),t=e.Uint8Array;return yy=t,yy}var wy,G_;function ek(){if(G_)return wy;G_=1;var e=hI();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return wy=t,wy}var vy,K_;function JH(){if(K_)return vy;K_=1;var e=ek();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return vy=t,vy}var xy,Y_;function eW(){if(Y_)return xy;Y_=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return xy=t,xy}var by,X_;function tW(){if(X_)return by;X_=1;var e=ac(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return by=r,by}var ky,Z_;function fI(){if(Z_)return ky;Z_=1;var e=ek();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return ky=t,ky}var Ny,Q_;function nW(){if(Q_)return Ny;Q_=1;var e=ek(),t=JH(),n=eW(),r=tW(),s=fI(),l="[object Boolean]",c="[object Date]",u="[object Map]",f="[object Number]",p="[object RegExp]",h="[object Set]",m="[object String]",y="[object Symbol]",v="[object ArrayBuffer]",S="[object DataView]",b="[object Float32Array]",_="[object Float64Array]",k="[object Int8Array]",j="[object Int16Array]",E="[object Int32Array]",C="[object Uint8Array]",R="[object Uint8ClampedArray]",I="[object Uint16Array]",$="[object Uint32Array]";function q(B,P,W){var ne=B.constructor;switch(P){case v:return e(B);case l:case c:return new ne(+B);case S:return t(B,W);case b:case _:case k:case j:case E:case C:case R:case I:case $:return s(B,W);case u:return new ne;case f:case m:return new ne(B);case p:return n(B);case h:return new ne;case y:return r(B)}}return Ny=q,Ny}var Sy,J_;function pI(){if(J_)return Sy;J_=1;var e=Br(),t=Object.create,n=(function(){function r(){}return function(s){if(!e(s))return{};if(t)return t(s);r.prototype=s;var l=new r;return r.prototype=void 0,l}})();return Sy=n,Sy}var jy,eE;function mI(){if(eE)return jy;eE=1;var e=pI(),t=Wf(),n=Hf();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return jy=r,jy}var _y,tE;function rW(){if(tE)return _y;tE=1;var e=ic(),t=Us(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return _y=r,_y}var Ey,nE;function sW(){if(nE)return Ey;nE=1;var e=rW(),t=Uf(),n=Xb(),r=n&&n.isMap,s=r?t(r):e;return Ey=s,Ey}var Cy,rE;function aW(){if(rE)return Cy;rE=1;var e=ic(),t=Us(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return Cy=r,Cy}var Ty,sE;function oW(){if(sE)return Ty;sE=1;var e=aW(),t=Uf(),n=Xb(),r=n&&n.isSet,s=r?t(r):e;return Ty=s,Ty}var Ry,aE;function gI(){if(aE)return Ry;aE=1;var e=Ff(),t=Kb(),n=Bf(),r=zH(),s=WH(),l=sI(),c=aI(),u=VH(),f=GH(),p=uI(),h=KH(),m=ic(),y=QH(),v=nW(),S=mI(),b=nn(),_=oc(),k=sW(),j=Br(),E=oW(),C=co(),R=_i(),I=1,$=2,q=4,B="[object Arguments]",P="[object Array]",W="[object Boolean]",ne="[object Date]",ee="[object Error]",M="[object Function]",X="[object GeneratorFunction]",V="[object Map]",G="[object Number]",F="[object Object]",L="[object RegExp]",H="[object Set]",D="[object String]",K="[object Symbol]",re="[object WeakMap]",z="[object ArrayBuffer]",Z="[object DataView]",U="[object Float32Array]",ae="[object Float64Array]",le="[object Int8Array]",ge="[object Int16Array]",Ne="[object Int32Array]",Ie="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Pe="[object Uint16Array]",ze="[object Uint32Array]",Re={};Re[B]=Re[P]=Re[z]=Re[Z]=Re[W]=Re[ne]=Re[U]=Re[ae]=Re[le]=Re[ge]=Re[Ne]=Re[V]=Re[G]=Re[F]=Re[L]=Re[H]=Re[D]=Re[K]=Re[Ie]=Re[Ge]=Re[Pe]=Re[ze]=!0,Re[ee]=Re[M]=Re[re]=!1;function st(ue,ce,se,be,Le,de){var fe,Ce=ce&I,pe=ce&$,_e=ce&q;if(se&&(fe=Le?se(ue,be,Le,de):se(ue)),fe!==void 0)return fe;if(!j(ue))return ue;var Ye=b(ue);if(Ye){if(fe=y(ue),!Ce)return c(ue,fe)}else{var qe=m(ue),ke=qe==M||qe==X;if(_(ue))return l(ue,Ce);if(qe==F||qe==B||ke&&!Le){if(fe=pe||ke?{}:S(ue),!Ce)return pe?f(ue,s(fe,ue)):u(ue,r(fe,ue))}else{if(!Re[qe])return Le?ue:{};fe=v(ue,qe,Ce)}}de||(de=new e);var Ae=de.get(ue);if(Ae)return Ae;de.set(ue,fe),E(ue)?ue.forEach(function(Ve){fe.add(st(Ve,ce,se,Ve,ue,de))}):k(ue)&&ue.forEach(function(Ve,rt){fe.set(rt,st(Ve,ce,se,rt,ue,de))});var Ue=_e?pe?h:p:pe?R:C,Fe=Ye?void 0:Ue(ue);return t(Fe||ue,function(Ve,rt){Fe&&(rt=Ve,Ve=ue[rt]),n(fe,rt,st(Ve,ce,se,rt,ue,de))}),fe}return Ry=st,Ry}var Ay,oE;function iW(){if(oE)return Ay;oE=1;var e=gI(),t=4;function n(r){return e(r,t)}return Ay=n,Ay}var My,iE;function tk(){if(iE)return My;iE=1;function e(t){return function(){return t}}return My=e,My}var Iy,lE;function lW(){if(lE)return Iy;lE=1;function e(t){return function(n,r,s){for(var l=-1,c=Object(n),u=s(n),f=u.length;f--;){var p=u[t?f:++l];if(r(c[p],p,c)===!1)break}return n}}return Iy=e,Iy}var $y,cE;function nk(){if(cE)return $y;cE=1;var e=lW(),t=e();return $y=t,$y}var Oy,uE;function rk(){if(uE)return Oy;uE=1;var e=nk(),t=co();function n(r,s){return r&&e(r,s,t)}return Oy=n,Oy}var Ly,dE;function cW(){if(dE)return Ly;dE=1;var e=fa();function t(n,r){return function(s,l){if(s==null)return s;if(!e(s))return n(s,l);for(var c=s.length,u=r?c:-1,f=Object(s);(r?u--:++u<c)&&l(f[u],u,f)!==!1;);return s}}return Ly=t,Ly}var Py,hE;function Vf(){if(hE)return Py;hE=1;var e=rk(),t=cW(),n=t(e);return Py=n,Py}var Dy,fE;function Ei(){if(fE)return Dy;fE=1;function e(t){return t}return Dy=e,Dy}var Fy,pE;function yI(){if(pE)return Fy;pE=1;var e=Ei();function t(n){return typeof n=="function"?n:e}return Fy=t,Fy}var qy,mE;function wI(){if(mE)return qy;mE=1;var e=Kb(),t=Vf(),n=yI(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c))}return qy=s,qy}var By,gE;function vI(){return gE||(gE=1,By=wI()),By}var zy,yE;function uW(){if(yE)return zy;yE=1;var e=Vf();function t(n,r){var s=[];return e(n,function(l,c,u){r(l,c,u)&&s.push(l)}),s}return zy=t,zy}var Uy,wE;function dW(){if(wE)return Uy;wE=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return Uy=t,Uy}var Hy,vE;function hW(){if(vE)return Hy;vE=1;function e(t){return this.__data__.has(t)}return Hy=e,Hy}var Wy,xE;function xI(){if(xE)return Wy;xE=1;var e=Gb(),t=dW(),n=hW();function r(s){var l=-1,c=s==null?0:s.length;for(this.__data__=new e;++l<c;)this.add(s[l])}return r.prototype.add=r.prototype.push=t,r.prototype.has=n,Wy=r,Wy}var Vy,bE;function fW(){if(bE)return Vy;bE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s;)if(n(t[r],r,t))return!0;return!1}return Vy=e,Vy}var Gy,kE;function bI(){if(kE)return Gy;kE=1;function e(t,n){return t.has(n)}return Gy=e,Gy}var Ky,NE;function kI(){if(NE)return Ky;NE=1;var e=xI(),t=fW(),n=bI(),r=1,s=2;function l(c,u,f,p,h,m){var y=f&r,v=c.length,S=u.length;if(v!=S&&!(y&&S>v))return!1;var b=m.get(c),_=m.get(u);if(b&&_)return b==u&&_==c;var k=-1,j=!0,E=f&s?new e:void 0;for(m.set(c,u),m.set(u,c);++k<v;){var C=c[k],R=u[k];if(p)var I=y?p(R,C,k,u,c,m):p(C,R,k,c,u,m);if(I!==void 0){if(I)continue;j=!1;break}if(E){if(!t(u,function($,q){if(!n(E,q)&&(C===$||h(C,$,f,p,m)))return E.push(q)})){j=!1;break}}else if(!(C===R||h(C,R,f,p,m))){j=!1;break}}return m.delete(c),m.delete(u),j}return Ky=l,Ky}var Yy,SE;function pW(){if(SE)return Yy;SE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,l){r[++n]=[l,s]}),r}return Yy=e,Yy}var Xy,jE;function sk(){if(jE)return Xy;jE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return Xy=e,Xy}var Zy,_E;function mW(){if(_E)return Zy;_E=1;var e=ac(),t=hI(),n=sc(),r=kI(),s=pW(),l=sk(),c=1,u=2,f="[object Boolean]",p="[object Date]",h="[object Error]",m="[object Map]",y="[object Number]",v="[object RegExp]",S="[object Set]",b="[object String]",_="[object Symbol]",k="[object ArrayBuffer]",j="[object DataView]",E=e?e.prototype:void 0,C=E?E.valueOf:void 0;function R(I,$,q,B,P,W,ne){switch(q){case j:if(I.byteLength!=$.byteLength||I.byteOffset!=$.byteOffset)return!1;I=I.buffer,$=$.buffer;case k:return!(I.byteLength!=$.byteLength||!W(new t(I),new t($)));case f:case p:case y:return n(+I,+$);case h:return I.name==$.name&&I.message==$.message;case v:case b:return I==$+"";case m:var ee=s;case S:var M=B&c;if(ee||(ee=l),I.size!=$.size&&!M)return!1;var X=ne.get(I);if(X)return X==$;B|=u,ne.set(I,$);var V=r(ee(I),ee($),B,P,W,ne);return ne.delete(I),V;case _:if(C)return C.call(I)==C.call($)}return!1}return Zy=R,Zy}var Qy,EE;function gW(){if(EE)return Qy;EE=1;var e=uI(),t=1,n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u,f,p,h){var m=u&t,y=e(l),v=y.length,S=e(c),b=S.length;if(v!=b&&!m)return!1;for(var _=v;_--;){var k=y[_];if(!(m?k in c:r.call(c,k)))return!1}var j=h.get(l),E=h.get(c);if(j&&E)return j==c&&E==l;var C=!0;h.set(l,c),h.set(c,l);for(var R=m;++_<v;){k=y[_];var I=l[k],$=c[k];if(f)var q=m?f($,I,k,c,l,h):f(I,$,k,l,c,h);if(!(q===void 0?I===$||p(I,$,u,f,h):q)){C=!1;break}R||(R=k=="constructor")}if(C&&!R){var B=l.constructor,P=c.constructor;B!=P&&"constructor"in l&&"constructor"in c&&!(typeof B=="function"&&B instanceof B&&typeof P=="function"&&P instanceof P)&&(C=!1)}return h.delete(l),h.delete(c),C}return Qy=s,Qy}var Jy,CE;function yW(){if(CE)return Jy;CE=1;var e=Ff(),t=kI(),n=mW(),r=gW(),s=ic(),l=nn(),c=oc(),u=Yu(),f=1,p="[object Arguments]",h="[object Array]",m="[object Object]",y=Object.prototype,v=y.hasOwnProperty;function S(b,_,k,j,E,C){var R=l(b),I=l(_),$=R?h:s(b),q=I?h:s(_);$=$==p?m:$,q=q==p?m:q;var B=$==m,P=q==m,W=$==q;if(W&&c(b)){if(!c(_))return!1;R=!0,B=!1}if(W&&!B)return C||(C=new e),R||u(b)?t(b,_,k,j,E,C):n(b,_,$,k,j,E,C);if(!(k&f)){var ne=B&&v.call(b,"__wrapped__"),ee=P&&v.call(_,"__wrapped__");if(ne||ee){var M=ne?b.value():b,X=ee?_.value():_;return C||(C=new e),E(M,X,k,j,C)}}return W?(C||(C=new e),r(b,_,k,j,E,C)):!1}return Jy=S,Jy}var ew,TE;function NI(){if(TE)return ew;TE=1;var e=yW(),t=Us();function n(r,s,l,c,u){return r===s?!0:r==null||s==null||!t(r)&&!t(s)?r!==r&&s!==s:e(r,s,l,c,n,u)}return ew=n,ew}var tw,RE;function wW(){if(RE)return tw;RE=1;var e=Ff(),t=NI(),n=1,r=2;function s(l,c,u,f){var p=u.length,h=p,m=!f;if(l==null)return!h;for(l=Object(l);p--;){var y=u[p];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++p<h;){y=u[p];var v=y[0],S=l[v],b=y[1];if(m&&y[2]){if(S===void 0&&!(v in l))return!1}else{var _=new e;if(f)var k=f(S,b,v,l,c,_);if(!(k===void 0?t(b,S,n|r,f,_):k))return!1}}return!0}return tw=s,tw}var nw,AE;function SI(){if(AE)return nw;AE=1;var e=Br();function t(n){return n===n&&!e(n)}return nw=t,nw}var rw,ME;function vW(){if(ME)return rw;ME=1;var e=SI(),t=co();function n(r){for(var s=t(r),l=s.length;l--;){var c=s[l],u=r[c];s[l]=[c,u,e(u)]}return s}return rw=n,rw}var sw,IE;function jI(){if(IE)return sw;IE=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return sw=e,sw}var aw,$E;function xW(){if($E)return aw;$E=1;var e=wW(),t=vW(),n=jI();function r(s){var l=t(s);return l.length==1&&l[0][2]?n(l[0][0],l[0][1]):function(c){return c===s||e(c,s,l)}}return aw=r,aw}var ow,OE;function lc(){if(OE)return ow;OE=1;var e=Si(),t=Us(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return ow=r,ow}var iw,LE;function ak(){if(LE)return iw;LE=1;var e=nn(),t=lc(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(l,c){if(e(l))return!1;var u=typeof l;return u=="number"||u=="symbol"||u=="boolean"||l==null||t(l)?!0:r.test(l)||!n.test(l)||c!=null&&l in Object(c)}return iw=s,iw}var lw,PE;function bW(){if(PE)return lw;PE=1;var e=Gb(),t="Expected a function";function n(r,s){if(typeof r!="function"||s!=null&&typeof s!="function")throw new TypeError(t);var l=function(){var c=arguments,u=s?s.apply(this,c):c[0],f=l.cache;if(f.has(u))return f.get(u);var p=r.apply(this,c);return l.cache=f.set(u,p)||f,p};return l.cache=new(n.Cache||e),l}return n.Cache=e,lw=n,lw}var cw,DE;function kW(){if(DE)return cw;DE=1;var e=bW(),t=500;function n(r){var s=e(r,function(c){return l.size===t&&l.clear(),c}),l=s.cache;return s}return cw=n,cw}var uw,FE;function NW(){if(FE)return uw;FE=1;var e=kW(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,n=/\\(\\)?/g,r=e(function(s){var l=[];return s.charCodeAt(0)===46&&l.push(""),s.replace(t,function(c,u,f,p){l.push(f?p.replace(n,"$1"):u||c)}),l});return uw=r,uw}var dw,qE;function Gf(){if(qE)return dw;qE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=Array(s);++r<s;)l[r]=n(t[r],r,t);return l}return dw=e,dw}var hw,BE;function SW(){if(BE)return hw;BE=1;var e=ac(),t=Gf(),n=nn(),r=lc(),s=e?e.prototype:void 0,l=s?s.toString:void 0;function c(u){if(typeof u=="string")return u;if(n(u))return t(u,c)+"";if(r(u))return l?l.call(u):"";var f=u+"";return f=="0"&&1/u==-1/0?"-0":f}return hw=c,hw}var fw,zE;function _I(){if(zE)return fw;zE=1;var e=SW();function t(n){return n==null?"":e(n)}return fw=t,fw}var pw,UE;function Kf(){if(UE)return pw;UE=1;var e=nn(),t=ak(),n=NW(),r=_I();function s(l,c){return e(l)?l:t(l,c)?[l]:n(r(l))}return pw=s,pw}var mw,HE;function Xu(){if(HE)return mw;HE=1;var e=lc();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return mw=t,mw}var gw,WE;function Yf(){if(WE)return gw;WE=1;var e=Kf(),t=Xu();function n(r,s){s=e(s,r);for(var l=0,c=s.length;r!=null&&l<c;)r=r[t(s[l++])];return l&&l==c?r:void 0}return gw=n,gw}var yw,VE;function jW(){if(VE)return yw;VE=1;var e=Yf();function t(n,r,s){var l=n==null?void 0:e(n,r);return l===void 0?s:l}return yw=t,yw}var ww,GE;function _W(){if(GE)return ww;GE=1;function e(t,n){return t!=null&&n in Object(t)}return ww=e,ww}var vw,KE;function EI(){if(KE)return vw;KE=1;var e=Kf(),t=Ku(),n=nn(),r=zf(),s=Yb(),l=Xu();function c(u,f,p){f=e(f,u);for(var h=-1,m=f.length,y=!1;++h<m;){var v=l(f[h]);if(!(y=u!=null&&p(u,v)))break;u=u[v]}return y||++h!=m?y:(m=u==null?0:u.length,!!m&&s(m)&&r(v,m)&&(n(u)||t(u)))}return vw=c,vw}var xw,YE;function CI(){if(YE)return xw;YE=1;var e=_W(),t=EI();function n(r,s){return r!=null&&t(r,s,e)}return xw=n,xw}var bw,XE;function EW(){if(XE)return bw;XE=1;var e=NI(),t=jW(),n=CI(),r=ak(),s=SI(),l=jI(),c=Xu(),u=1,f=2;function p(h,m){return r(h)&&s(m)?l(c(h),m):function(y){var v=t(y,h);return v===void 0&&v===m?n(y,h):e(m,v,u|f)}}return bw=p,bw}var kw,ZE;function TI(){if(ZE)return kw;ZE=1;function e(t){return function(n){return n==null?void 0:n[t]}}return kw=e,kw}var Nw,QE;function CW(){if(QE)return Nw;QE=1;var e=Yf();function t(n){return function(r){return e(r,n)}}return Nw=t,Nw}var Sw,JE;function TW(){if(JE)return Sw;JE=1;var e=TI(),t=CW(),n=ak(),r=Xu();function s(l){return n(l)?e(r(l)):t(l)}return Sw=s,Sw}var jw,eC;function pa(){if(eC)return jw;eC=1;var e=xW(),t=EW(),n=Ei(),r=nn(),s=TW();function l(c){return typeof c=="function"?c:c==null?n:typeof c=="object"?r(c)?t(c[0],c[1]):e(c):s(c)}return jw=l,jw}var _w,tC;function RI(){if(tC)return _w;tC=1;var e=oI(),t=uW(),n=pa(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c,3))}return _w=s,_w}var Ew,nC;function RW(){if(nC)return Ew;nC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Ew=n,Ew}var Cw,rC;function AI(){if(rC)return Cw;rC=1;var e=RW(),t=EI();function n(r,s){return r!=null&&t(r,s,e)}return Cw=n,Cw}var Tw,sC;function AW(){if(sC)return Tw;sC=1;var e=Zb(),t=ic(),n=Ku(),r=nn(),s=fa(),l=oc(),c=Hf(),u=Yu(),f="[object Map]",p="[object Set]",h=Object.prototype,m=h.hasOwnProperty;function y(v){if(v==null)return!0;if(s(v)&&(r(v)||typeof v=="string"||typeof v.splice=="function"||l(v)||u(v)||n(v)))return!v.length;var S=t(v);if(S==f||S==p)return!v.size;if(c(v))return!e(v).length;for(var b in v)if(m.call(v,b))return!1;return!0}return Tw=y,Tw}var Rw,aC;function MI(){if(aC)return Rw;aC=1;function e(t){return t===void 0}return Rw=e,Rw}var Aw,oC;function II(){if(oC)return Aw;oC=1;var e=Vf(),t=fa();function n(r,s){var l=-1,c=t(r)?Array(r.length):[];return e(r,function(u,f,p){c[++l]=s(u,f,p)}),c}return Aw=n,Aw}var Mw,iC;function $I(){if(iC)return Mw;iC=1;var e=Gf(),t=pa(),n=II(),r=nn();function s(l,c){var u=r(l)?e:n;return u(l,t(c,3))}return Mw=s,Mw}var Iw,lC;function MW(){if(lC)return Iw;lC=1;function e(t,n,r,s){var l=-1,c=t==null?0:t.length;for(s&&c&&(r=t[++l]);++l<c;)r=n(r,t[l],l,t);return r}return Iw=e,Iw}var $w,cC;function IW(){if(cC)return $w;cC=1;function e(t,n,r,s,l){return l(t,function(c,u,f){r=s?(s=!1,c):n(r,c,u,f)}),r}return $w=e,$w}var Ow,uC;function OI(){if(uC)return Ow;uC=1;var e=MW(),t=Vf(),n=pa(),r=IW(),s=nn();function l(c,u,f){var p=s(c)?e:r,h=arguments.length<3;return p(c,n(u,4),f,h,t)}return Ow=l,Ow}var Lw,dC;function $W(){if(dC)return Lw;dC=1;var e=Si(),t=nn(),n=Us(),r="[object String]";function s(l){return typeof l=="string"||!t(l)&&n(l)&&e(l)==r}return Lw=s,Lw}var Pw,hC;function OW(){if(hC)return Pw;hC=1;var e=TI(),t=e("length");return Pw=t,Pw}var Dw,fC;function LW(){if(fC)return Dw;fC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="\\u200d",u=RegExp("["+c+e+s+l+"]");function f(p){return u.test(p)}return Dw=f,Dw}var Fw,pC;function PW(){if(pC)return Fw;pC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="["+e+"]",u="["+s+"]",f="\\ud83c[\\udffb-\\udfff]",p="(?:"+u+"|"+f+")",h="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",v="\\u200d",S=p+"?",b="["+l+"]?",_="(?:"+v+"(?:"+[h,m,y].join("|")+")"+b+S+")*",k=b+S+_,j="(?:"+[h+u+"?",u,m,y,c].join("|")+")",E=RegExp(f+"(?="+f+")|"+j+k,"g");function C(R){for(var I=E.lastIndex=0;E.test(R);)++I;return I}return Fw=C,Fw}var qw,mC;function DW(){if(mC)return qw;mC=1;var e=OW(),t=LW(),n=PW();function r(s){return t(s)?n(s):e(s)}return qw=r,qw}var Bw,gC;function FW(){if(gC)return Bw;gC=1;var e=Zb(),t=ic(),n=fa(),r=$W(),s=DW(),l="[object Map]",c="[object Set]";function u(f){if(f==null)return 0;if(n(f))return r(f)?s(f):f.length;var p=t(f);return p==l||p==c?f.size:e(f).length}return Bw=u,Bw}var zw,yC;function qW(){if(yC)return zw;yC=1;var e=Kb(),t=pI(),n=rk(),r=pa(),s=Wf(),l=nn(),c=oc(),u=Vu(),f=Br(),p=Yu();function h(m,y,v){var S=l(m),b=S||c(m)||p(m);if(y=r(y,4),v==null){var _=m&&m.constructor;b?v=S?new _:[]:f(m)?v=u(_)?t(s(m)):{}:v={}}return(b?e:n)(m,function(k,j,E){return y(v,k,j,E)}),v}return zw=h,zw}var Uw,wC;function BW(){if(wC)return Uw;wC=1;var e=ac(),t=Ku(),n=nn(),r=e?e.isConcatSpreadable:void 0;function s(l){return n(l)||t(l)||!!(r&&l&&l[r])}return Uw=s,Uw}var Hw,vC;function ok(){if(vC)return Hw;vC=1;var e=Jb(),t=BW();function n(r,s,l,c,u){var f=-1,p=r.length;for(l||(l=t),u||(u=[]);++f<p;){var h=r[f];s>0&&l(h)?s>1?n(h,s-1,l,c,u):e(u,h):c||(u[u.length]=h)}return u}return Hw=n,Hw}var Ww,xC;function zW(){if(xC)return Ww;xC=1;function e(t,n,r){switch(r.length){case 0:return t.call(n);case 1:return t.call(n,r[0]);case 2:return t.call(n,r[0],r[1]);case 3:return t.call(n,r[0],r[1],r[2])}return t.apply(n,r)}return Ww=e,Ww}var Vw,bC;function LI(){if(bC)return Vw;bC=1;var e=zW(),t=Math.max;function n(r,s,l){return s=t(s===void 0?r.length-1:s,0),function(){for(var c=arguments,u=-1,f=t(c.length-s,0),p=Array(f);++u<f;)p[u]=c[s+u];u=-1;for(var h=Array(s+1);++u<s;)h[u]=c[u];return h[s]=l(p),e(r,this,h)}}return Vw=n,Vw}var Gw,kC;function UW(){if(kC)return Gw;kC=1;var e=tk(),t=tI(),n=Ei(),r=t?function(s,l){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:n;return Gw=r,Gw}var Kw,NC;function HW(){if(NC)return Kw;NC=1;var e=800,t=16,n=Date.now;function r(s){var l=0,c=0;return function(){var u=n(),f=t-(u-c);if(c=u,f>0){if(++l>=e)return arguments[0]}else l=0;return s.apply(void 0,arguments)}}return Kw=r,Kw}var Yw,SC;function PI(){if(SC)return Yw;SC=1;var e=UW(),t=HW(),n=t(e);return Yw=n,Yw}var Xw,jC;function Xf(){if(jC)return Xw;jC=1;var e=Ei(),t=LI(),n=PI();function r(s,l){return n(t(s,l,e),s+"")}return Xw=r,Xw}var Zw,_C;function DI(){if(_C)return Zw;_C=1;function e(t,n,r,s){for(var l=t.length,c=r+(s?1:-1);s?c--:++c<l;)if(n(t[c],c,t))return c;return-1}return Zw=e,Zw}var Qw,EC;function WW(){if(EC)return Qw;EC=1;function e(t){return t!==t}return Qw=e,Qw}var Jw,CC;function VW(){if(CC)return Jw;CC=1;function e(t,n,r){for(var s=r-1,l=t.length;++s<l;)if(t[s]===n)return s;return-1}return Jw=e,Jw}var ev,TC;function GW(){if(TC)return ev;TC=1;var e=DI(),t=WW(),n=VW();function r(s,l,c){return l===l?n(s,l,c):e(s,t,c)}return ev=r,ev}var tv,RC;function KW(){if(RC)return tv;RC=1;var e=GW();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return tv=t,tv}var nv,AC;function YW(){if(AC)return nv;AC=1;function e(t,n,r){for(var s=-1,l=t==null?0:t.length;++s<l;)if(r(n,t[s]))return!0;return!1}return nv=e,nv}var rv,MC;function XW(){if(MC)return rv;MC=1;function e(){}return rv=e,rv}var sv,IC;function ZW(){if(IC)return sv;IC=1;var e=dI(),t=XW(),n=sk(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(l){return new e(l)}:t;return sv=s,sv}var av,$C;function QW(){if($C)return av;$C=1;var e=xI(),t=KW(),n=YW(),r=bI(),s=ZW(),l=sk(),c=200;function u(f,p,h){var m=-1,y=t,v=f.length,S=!0,b=[],_=b;if(h)S=!1,y=n;else if(v>=c){var k=p?null:s(f);if(k)return l(k);S=!1,y=r,_=new e}else _=p?[]:b;e:for(;++m<v;){var j=f[m],E=p?p(j):j;if(j=h||j!==0?j:0,S&&E===E){for(var C=_.length;C--;)if(_[C]===E)continue e;p&&_.push(E),b.push(j)}else y(_,E,h)||(_!==b&&_.push(E),b.push(j))}return b}return av=u,av}var ov,OC;function FI(){if(OC)return ov;OC=1;var e=fa(),t=Us();function n(r){return t(r)&&e(r)}return ov=n,ov}var iv,LC;function JW(){if(LC)return iv;LC=1;var e=ok(),t=Xf(),n=QW(),r=FI(),s=t(function(l){return n(e(l,1,r,!0))});return iv=s,iv}var lv,PC;function e7(){if(PC)return lv;PC=1;var e=Gf();function t(n,r){return e(r,function(s){return n[s]})}return lv=t,lv}var cv,DC;function qI(){if(DC)return cv;DC=1;var e=e7(),t=co();function n(r){return r==null?[]:e(r,t(r))}return cv=n,cv}var uv,FC;function zr(){if(FC)return uv;FC=1;var e;if(typeof Wb=="function")try{e={clone:iW(),constant:tk(),each:vI(),filter:RI(),has:AI(),isArray:nn(),isEmpty:AW(),isFunction:Vu(),isUndefined:MI(),keys:co(),map:$I(),reduce:OI(),size:FW(),transform:qW(),union:JW(),values:qI()}}catch{}return e||(e=window._),uv=e,uv}var dv,qC;function ik(){if(qC)return dv;qC=1;var e=zr();dv=s;var t="\0",n="\0",r="";function s(h){this._isDirected=e.has(h,"directed")?h.directed:!0,this._isMultigraph=e.has(h,"multigraph")?h.multigraph:!1,this._isCompound=e.has(h,"compound")?h.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[n]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}s.prototype._nodeCount=0,s.prototype._edgeCount=0,s.prototype.isDirected=function(){return this._isDirected},s.prototype.isMultigraph=function(){return this._isMultigraph},s.prototype.isCompound=function(){return this._isCompound},s.prototype.setGraph=function(h){return this._label=h,this},s.prototype.graph=function(){return this._label},s.prototype.setDefaultNodeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultNodeLabelFn=h,this},s.prototype.nodeCount=function(){return this._nodeCount},s.prototype.nodes=function(){return e.keys(this._nodes)},s.prototype.sources=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._in[m])})},s.prototype.sinks=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._out[m])})},s.prototype.setNodes=function(h,m){var y=arguments,v=this;return e.each(h,function(S){y.length>1?v.setNode(S,m):v.setNode(S)}),this},s.prototype.setNode=function(h,m){return e.has(this._nodes,h)?(arguments.length>1&&(this._nodes[h]=m),this):(this._nodes[h]=arguments.length>1?m:this._defaultNodeLabelFn(h),this._isCompound&&(this._parent[h]=n,this._children[h]={},this._children[n][h]=!0),this._in[h]={},this._preds[h]={},this._out[h]={},this._sucs[h]={},++this._nodeCount,this)},s.prototype.node=function(h){return this._nodes[h]},s.prototype.hasNode=function(h){return e.has(this._nodes,h)},s.prototype.removeNode=function(h){var m=this;if(e.has(this._nodes,h)){var y=function(v){m.removeEdge(m._edgeObjs[v])};delete this._nodes[h],this._isCompound&&(this._removeFromParentsChildList(h),delete this._parent[h],e.each(this.children(h),function(v){m.setParent(v)}),delete this._children[h]),e.each(e.keys(this._in[h]),y),delete this._in[h],delete this._preds[h],e.each(e.keys(this._out[h]),y),delete this._out[h],delete this._sucs[h],--this._nodeCount}return this},s.prototype.setParent=function(h,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=n;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===h)throw new Error("Setting "+m+" as parent of "+h+" would create a cycle");this.setNode(m)}return this.setNode(h),this._removeFromParentsChildList(h),this._parent[h]=m,this._children[m][h]=!0,this},s.prototype._removeFromParentsChildList=function(h){delete this._children[this._parent[h]][h]},s.prototype.parent=function(h){if(this._isCompound){var m=this._parent[h];if(m!==n)return m}},s.prototype.children=function(h){if(e.isUndefined(h)&&(h=n),this._isCompound){var m=this._children[h];if(m)return e.keys(m)}else{if(h===n)return this.nodes();if(this.hasNode(h))return[]}},s.prototype.predecessors=function(h){var m=this._preds[h];if(m)return e.keys(m)},s.prototype.successors=function(h){var m=this._sucs[h];if(m)return e.keys(m)},s.prototype.neighbors=function(h){var m=this.predecessors(h);if(m)return e.union(m,this.successors(h))},s.prototype.isLeaf=function(h){var m;return this.isDirected()?m=this.successors(h):m=this.neighbors(h),m.length===0},s.prototype.filterNodes=function(h){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(b,_){h(_)&&m.setNode(_,b)}),e.each(this._edgeObjs,function(b){m.hasNode(b.v)&&m.hasNode(b.w)&&m.setEdge(b,y.edge(b))});var v={};function S(b){var _=y.parent(b);return _===void 0||m.hasNode(_)?(v[b]=_,_):_ in v?v[_]:S(_)}return this._isCompound&&e.each(m.nodes(),function(b){m.setParent(b,S(b))}),m},s.prototype.setDefaultEdgeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultEdgeLabelFn=h,this},s.prototype.edgeCount=function(){return this._edgeCount},s.prototype.edges=function(){return e.values(this._edgeObjs)},s.prototype.setPath=function(h,m){var y=this,v=arguments;return e.reduce(h,function(S,b){return v.length>1?y.setEdge(S,b,m):y.setEdge(S,b),b}),this},s.prototype.setEdge=function(){var h,m,y,v,S=!1,b=arguments[0];typeof b=="object"&&b!==null&&"v"in b?(h=b.v,m=b.w,y=b.name,arguments.length===2&&(v=arguments[1],S=!0)):(h=b,m=arguments[1],y=arguments[3],arguments.length>2&&(v=arguments[2],S=!0)),h=""+h,m=""+m,e.isUndefined(y)||(y=""+y);var _=u(this._isDirected,h,m,y);if(e.has(this._edgeLabels,_))return S&&(this._edgeLabels[_]=v),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(h),this.setNode(m),this._edgeLabels[_]=S?v:this._defaultEdgeLabelFn(h,m,y);var k=f(this._isDirected,h,m,y);return h=k.v,m=k.w,Object.freeze(k),this._edgeObjs[_]=k,l(this._preds[m],h),l(this._sucs[h],m),this._in[m][_]=k,this._out[h][_]=k,this._edgeCount++,this},s.prototype.edge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return this._edgeLabels[v]},s.prototype.hasEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return e.has(this._edgeLabels,v)},s.prototype.removeEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y),S=this._edgeObjs[v];return S&&(h=S.v,m=S.w,delete this._edgeLabels[v],delete this._edgeObjs[v],c(this._preds[m],h),c(this._sucs[h],m),delete this._in[m][v],delete this._out[h][v],this._edgeCount--),this},s.prototype.inEdges=function(h,m){var y=this._in[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.v===m}):v}},s.prototype.outEdges=function(h,m){var y=this._out[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.w===m}):v}},s.prototype.nodeEdges=function(h,m){var y=this.inEdges(h,m);if(y)return y.concat(this.outEdges(h,m))};function l(h,m){h[m]?h[m]++:h[m]=1}function c(h,m){--h[m]||delete h[m]}function u(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}return S+r+b+r+(e.isUndefined(v)?t:v)}function f(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}var k={v:S,w:b};return v&&(k.name=v),k}function p(h,m){return u(h,m.v,m.w,m.name)}return dv}var hv,BC;function t7(){return BC||(BC=1,hv="2.1.8"),hv}var fv,zC;function n7(){return zC||(zC=1,fv={Graph:ik(),version:t7()}),fv}var pv,UC;function r7(){if(UC)return pv;UC=1;var e=zr(),t=ik();pv={write:n,read:l};function n(c){var u={options:{directed:c.isDirected(),multigraph:c.isMultigraph(),compound:c.isCompound()},nodes:r(c),edges:s(c)};return e.isUndefined(c.graph())||(u.value=e.clone(c.graph())),u}function r(c){return e.map(c.nodes(),function(u){var f=c.node(u),p=c.parent(u),h={v:u};return e.isUndefined(f)||(h.value=f),e.isUndefined(p)||(h.parent=p),h})}function s(c){return e.map(c.edges(),function(u){var f=c.edge(u),p={v:u.v,w:u.w};return e.isUndefined(u.name)||(p.name=u.name),e.isUndefined(f)||(p.value=f),p})}function l(c){var u=new t(c.options).setGraph(c.value);return e.each(c.nodes,function(f){u.setNode(f.v,f.value),f.parent&&u.setParent(f.v,f.parent)}),e.each(c.edges,function(f){u.setEdge({v:f.v,w:f.w,name:f.name},f.value)}),u}return pv}var mv,HC;function s7(){if(HC)return mv;HC=1;var e=zr();mv=t;function t(n){var r={},s=[],l;function c(u){e.has(r,u)||(r[u]=!0,l.push(u),e.each(n.successors(u),c),e.each(n.predecessors(u),c))}return e.each(n.nodes(),function(u){l=[],c(u),l.length&&s.push(l)}),s}return mv}var gv,WC;function BI(){if(WC)return gv;WC=1;var e=zr();gv=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(n){return n.key})},t.prototype.has=function(n){return e.has(this._keyIndices,n)},t.prototype.priority=function(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(n,r){var s=this._keyIndices;if(n=String(n),!e.has(s,n)){var l=this._arr,c=l.length;return s[n]=c,l.push({key:n,priority:r}),this._decrease(c),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key},t.prototype.decrease=function(n,r){var s=this._keyIndices[n];if(r>this._arr[s].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[s].priority+" New: "+r);this._arr[s].priority=r,this._decrease(s)},t.prototype._heapify=function(n){var r=this._arr,s=2*n,l=s+1,c=n;s<r.length&&(c=r[s].priority<r[c].priority?s:c,l<r.length&&(c=r[l].priority<r[c].priority?l:c),c!==n&&(this._swap(n,c),this._heapify(c)))},t.prototype._decrease=function(n){for(var r=this._arr,s=r[n].priority,l;n!==0&&(l=n>>1,!(r[l].priority<s));)this._swap(n,l),n=l},t.prototype._swap=function(n,r){var s=this._arr,l=this._keyIndices,c=s[n],u=s[r];s[n]=u,s[r]=c,l[u.key]=n,l[c.key]=r},gv}var yv,VC;function zI(){if(VC)return yv;VC=1;var e=zr(),t=BI();yv=r;var n=e.constant(1);function r(l,c,u,f){return s(l,String(c),u||n,f||function(p){return l.outEdges(p)})}function s(l,c,u,f){var p={},h=new t,m,y,v=function(S){var b=S.v!==m?S.v:S.w,_=p[b],k=u(S),j=y.distance+k;if(k<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+S+" Weight: "+k);j<_.distance&&(_.distance=j,_.predecessor=m,h.decrease(b,j))};for(l.nodes().forEach(function(S){var b=S===c?0:Number.POSITIVE_INFINITY;p[S]={distance:b},h.add(S,b)});h.size()>0&&(m=h.removeMin(),y=p[m],y.distance!==Number.POSITIVE_INFINITY);)f(m).forEach(v);return p}return yv}var wv,GC;function a7(){if(GC)return wv;GC=1;var e=zI(),t=zr();wv=n;function n(r,s,l){return t.transform(r.nodes(),function(c,u){c[u]=e(r,u,s,l)},{})}return wv}var vv,KC;function UI(){if(KC)return vv;KC=1;var e=zr();vv=t;function t(n){var r=0,s=[],l={},c=[];function u(f){var p=l[f]={onStack:!0,lowlink:r,index:r++};if(s.push(f),n.successors(f).forEach(function(y){e.has(l,y)?l[y].onStack&&(p.lowlink=Math.min(p.lowlink,l[y].index)):(u(y),p.lowlink=Math.min(p.lowlink,l[y].lowlink))}),p.lowlink===p.index){var h=[],m;do m=s.pop(),l[m].onStack=!1,h.push(m);while(f!==m);c.push(h)}}return n.nodes().forEach(function(f){e.has(l,f)||u(f)}),c}return vv}var xv,YC;function o7(){if(YC)return xv;YC=1;var e=zr(),t=UI();xv=n;function n(r){return e.filter(t(r),function(s){return s.length>1||s.length===1&&r.hasEdge(s[0],s[0])})}return xv}var bv,XC;function i7(){if(XC)return bv;XC=1;var e=zr();bv=n;var t=e.constant(1);function n(s,l,c){return r(s,l||t,c||function(u){return s.outEdges(u)})}function r(s,l,c){var u={},f=s.nodes();return f.forEach(function(p){u[p]={},u[p][p]={distance:0},f.forEach(function(h){p!==h&&(u[p][h]={distance:Number.POSITIVE_INFINITY})}),c(p).forEach(function(h){var m=h.v===p?h.w:h.v,y=l(h);u[p][m]={distance:y,predecessor:p}})}),f.forEach(function(p){var h=u[p];f.forEach(function(m){var y=u[m];f.forEach(function(v){var S=y[p],b=h[v],_=y[v],k=S.distance+b.distance;k<_.distance&&(_.distance=k,_.predecessor=b.predecessor)})})}),u}return bv}var kv,ZC;function HI(){if(ZC)return kv;ZC=1;var e=zr();kv=t,t.CycleException=n;function t(r){var s={},l={},c=[];function u(f){if(e.has(l,f))throw new n;e.has(s,f)||(l[f]=!0,s[f]=!0,e.each(r.predecessors(f),u),delete l[f],c.push(f))}if(e.each(r.sinks(),u),e.size(s)!==r.nodeCount())throw new n;return c}function n(){}return n.prototype=new Error,kv}var Nv,QC;function l7(){if(QC)return Nv;QC=1;var e=HI();Nv=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return Nv}var Sv,JC;function WI(){if(JC)return Sv;JC=1;var e=zr();Sv=t;function t(r,s,l){e.isArray(s)||(s=[s]);var c=(r.isDirected()?r.successors:r.neighbors).bind(r),u=[],f={};return e.each(s,function(p){if(!r.hasNode(p))throw new Error("Graph does not have node: "+p);n(r,p,l==="post",f,c,u)}),u}function n(r,s,l,c,u,f){e.has(c,s)||(c[s]=!0,l||f.push(s),e.each(u(s),function(p){n(r,p,l,c,u,f)}),l&&f.push(s))}return Sv}var jv,eT;function c7(){if(eT)return jv;eT=1;var e=WI();jv=t;function t(n,r){return e(n,r,"post")}return jv}var _v,tT;function u7(){if(tT)return _v;tT=1;var e=WI();_v=t;function t(n,r){return e(n,r,"pre")}return _v}var Ev,nT;function d7(){if(nT)return Ev;nT=1;var e=zr(),t=ik(),n=BI();Ev=r;function r(s,l){var c=new t,u={},f=new n,p;function h(y){var v=y.v===p?y.w:y.v,S=f.priority(v);if(S!==void 0){var b=l(y);b<S&&(u[v]=p,f.decrease(v,b))}}if(s.nodeCount()===0)return c;e.each(s.nodes(),function(y){f.add(y,Number.POSITIVE_INFINITY),c.setNode(y)}),f.decrease(s.nodes()[0],0);for(var m=!1;f.size()>0;){if(p=f.removeMin(),e.has(u,p))c.setEdge(p,u[p]);else{if(m)throw new Error("Input graph is not connected: "+s);m=!0}s.nodeEdges(p).forEach(h)}return c}return Ev}var Cv,rT;function h7(){return rT||(rT=1,Cv={components:s7(),dijkstra:zI(),dijkstraAll:a7(),findCycles:o7(),floydWarshall:i7(),isAcyclic:l7(),postorder:c7(),preorder:u7(),prim:d7(),tarjan:UI(),topsort:HI()}),Cv}var Tv,sT;function f7(){if(sT)return Tv;sT=1;var e=n7();return Tv={Graph:e.Graph,json:r7(),alg:h7(),version:e.version},Tv}var Rv,aT;function xs(){if(aT)return Rv;aT=1;var e;if(typeof Wb=="function")try{e=f7()}catch{}return e||(e=window.graphlib),Rv=e,Rv}var Av,oT;function p7(){if(oT)return Av;oT=1;var e=gI(),t=1,n=4;function r(s){return e(s,t|n)}return Av=r,Av}var Mv,iT;function Zf(){if(iT)return Mv;iT=1;var e=sc(),t=fa(),n=zf(),r=Br();function s(l,c,u){if(!r(u))return!1;var f=typeof c;return(f=="number"?t(u)&&n(c,u.length):f=="string"&&c in u)?e(u[c],l):!1}return Mv=s,Mv}var Iv,lT;function m7(){if(lT)return Iv;lT=1;var e=Xf(),t=sc(),n=Zf(),r=_i(),s=Object.prototype,l=s.hasOwnProperty,c=e(function(u,f){u=Object(u);var p=-1,h=f.length,m=h>2?f[2]:void 0;for(m&&n(f[0],f[1],m)&&(h=1);++p<h;)for(var y=f[p],v=r(y),S=-1,b=v.length;++S<b;){var _=v[S],k=u[_];(k===void 0||t(k,s[_])&&!l.call(u,_))&&(u[_]=y[_])}return u});return Iv=c,Iv}var $v,cT;function g7(){if(cT)return $v;cT=1;var e=pa(),t=fa(),n=co();function r(s){return function(l,c,u){var f=Object(l);if(!t(l)){var p=e(c,3);l=n(l),c=function(m){return p(f[m],m,f)}}var h=s(l,c,u);return h>-1?f[p?l[h]:h]:void 0}}return $v=r,$v}var Ov,uT;function y7(){if(uT)return Ov;uT=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Ov=t,Ov}var Lv,dT;function w7(){if(dT)return Lv;dT=1;var e=y7(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Lv=n,Lv}var Pv,hT;function v7(){if(hT)return Pv;hT=1;var e=w7(),t=Br(),n=lc(),r=NaN,s=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;function f(p){if(typeof p=="number")return p;if(n(p))return r;if(t(p)){var h=typeof p.valueOf=="function"?p.valueOf():p;p=t(h)?h+"":h}if(typeof p!="string")return p===0?p:+p;p=e(p);var m=l.test(p);return m||c.test(p)?u(p.slice(2),m?2:8):s.test(p)?r:+p}return Pv=f,Pv}var Dv,fT;function VI(){if(fT)return Dv;fT=1;var e=v7(),t=1/0,n=17976931348623157e292;function r(s){if(!s)return s===0?s:0;if(s=e(s),s===t||s===-t){var l=s<0?-1:1;return l*n}return s===s?s:0}return Dv=r,Dv}var Fv,pT;function x7(){if(pT)return Fv;pT=1;var e=VI();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Fv=t,Fv}var qv,mT;function b7(){if(mT)return qv;mT=1;var e=DI(),t=pa(),n=x7(),r=Math.max;function s(l,c,u){var f=l==null?0:l.length;if(!f)return-1;var p=u==null?0:n(u);return p<0&&(p=r(f+p,0)),e(l,t(c,3),p)}return qv=s,qv}var Bv,gT;function k7(){if(gT)return Bv;gT=1;var e=g7(),t=b7(),n=e(t);return Bv=n,Bv}var zv,yT;function GI(){if(yT)return zv;yT=1;var e=ok();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return zv=t,zv}var Uv,wT;function N7(){if(wT)return Uv;wT=1;var e=nk(),t=yI(),n=_i();function r(s,l){return s==null?s:e(s,t(l),n)}return Uv=r,Uv}var Hv,vT;function S7(){if(vT)return Hv;vT=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Hv=e,Hv}var Wv,xT;function j7(){if(xT)return Wv;xT=1;var e=qf(),t=rk(),n=pa();function r(s,l){var c={};return l=n(l,3),t(s,function(u,f,p){e(c,f,l(u,f,p))}),c}return Wv=r,Wv}var Vv,bT;function lk(){if(bT)return Vv;bT=1;var e=lc();function t(n,r,s){for(var l=-1,c=n.length;++l<c;){var u=n[l],f=r(u);if(f!=null&&(p===void 0?f===f&&!e(f):s(f,p)))var p=f,h=u}return h}return Vv=t,Vv}var Gv,kT;function _7(){if(kT)return Gv;kT=1;function e(t,n){return t>n}return Gv=e,Gv}var Kv,NT;function E7(){if(NT)return Kv;NT=1;var e=lk(),t=_7(),n=Ei();function r(s){return s&&s.length?e(s,n,t):void 0}return Kv=r,Kv}var Yv,ST;function KI(){if(ST)return Yv;ST=1;var e=qf(),t=sc();function n(r,s,l){(l!==void 0&&!t(r[s],l)||l===void 0&&!(s in r))&&e(r,s,l)}return Yv=n,Yv}var Xv,jT;function C7(){if(jT)return Xv;jT=1;var e=Si(),t=Wf(),n=Us(),r="[object Object]",s=Function.prototype,l=Object.prototype,c=s.toString,u=l.hasOwnProperty,f=c.call(Object);function p(h){if(!n(h)||e(h)!=r)return!1;var m=t(h);if(m===null)return!0;var y=u.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&c.call(y)==f}return Xv=p,Xv}var Zv,_T;function YI(){if(_T)return Zv;_T=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Zv=e,Zv}var Qv,ET;function T7(){if(ET)return Qv;ET=1;var e=Gu(),t=_i();function n(r){return e(r,t(r))}return Qv=n,Qv}var Jv,CT;function R7(){if(CT)return Jv;CT=1;var e=KI(),t=sI(),n=fI(),r=aI(),s=mI(),l=Ku(),c=nn(),u=FI(),f=oc(),p=Vu(),h=Br(),m=C7(),y=Yu(),v=YI(),S=T7();function b(_,k,j,E,C,R,I){var $=v(_,j),q=v(k,j),B=I.get(q);if(B){e(_,j,B);return}var P=R?R($,q,j+"",_,k,I):void 0,W=P===void 0;if(W){var ne=c(q),ee=!ne&&f(q),M=!ne&&!ee&&y(q);P=q,ne||ee||M?c($)?P=$:u($)?P=r($):ee?(W=!1,P=t(q,!0)):M?(W=!1,P=n(q,!0)):P=[]:m(q)||l(q)?(P=$,l($)?P=S($):(!h($)||p($))&&(P=s(q))):W=!1}W&&(I.set(q,P),C(P,q,E,R,I),I.delete(q)),e(_,j,P)}return Jv=b,Jv}var ex,TT;function A7(){if(TT)return ex;TT=1;var e=Ff(),t=KI(),n=nk(),r=R7(),s=Br(),l=_i(),c=YI();function u(f,p,h,m,y){f!==p&&n(p,function(v,S){if(y||(y=new e),s(v))r(f,p,S,h,u,m,y);else{var b=m?m(c(f,S),v,S+"",f,p,y):void 0;b===void 0&&(b=v),t(f,S,b)}},l)}return ex=u,ex}var tx,RT;function M7(){if(RT)return tx;RT=1;var e=Xf(),t=Zf();function n(r){return e(function(s,l){var c=-1,u=l.length,f=u>1?l[u-1]:void 0,p=u>2?l[2]:void 0;for(f=r.length>3&&typeof f=="function"?(u--,f):void 0,p&&t(l[0],l[1],p)&&(f=u<3?void 0:f,u=1),s=Object(s);++c<u;){var h=l[c];h&&r(s,h,c,f)}return s})}return tx=n,tx}var nx,AT;function I7(){if(AT)return nx;AT=1;var e=A7(),t=M7(),n=t(function(r,s,l){e(r,s,l)});return nx=n,nx}var rx,MT;function XI(){if(MT)return rx;MT=1;function e(t,n){return t<n}return rx=e,rx}var sx,IT;function $7(){if(IT)return sx;IT=1;var e=lk(),t=XI(),n=Ei();function r(s){return s&&s.length?e(s,n,t):void 0}return sx=r,sx}var ax,$T;function O7(){if($T)return ax;$T=1;var e=lk(),t=pa(),n=XI();function r(s,l){return s&&s.length?e(s,t(l,2),n):void 0}return ax=r,ax}var ox,OT;function L7(){if(OT)return ox;OT=1;var e=ks(),t=function(){return e.Date.now()};return ox=t,ox}var ix,LT;function P7(){if(LT)return ix;LT=1;var e=Bf(),t=Kf(),n=zf(),r=Br(),s=Xu();function l(c,u,f,p){if(!r(c))return c;u=t(u,c);for(var h=-1,m=u.length,y=m-1,v=c;v!=null&&++h<m;){var S=s(u[h]),b=f;if(S==="__proto__"||S==="constructor"||S==="prototype")return c;if(h!=y){var _=v[S];b=p?p(_,S,v):void 0,b===void 0&&(b=r(_)?_:n(u[h+1])?[]:{})}e(v,S,b),v=v[S]}return c}return ix=l,ix}var lx,PT;function D7(){if(PT)return lx;PT=1;var e=Yf(),t=P7(),n=Kf();function r(s,l,c){for(var u=-1,f=l.length,p={};++u<f;){var h=l[u],m=e(s,h);c(m,h)&&t(p,n(h,s),m)}return p}return lx=r,lx}var cx,DT;function F7(){if(DT)return cx;DT=1;var e=D7(),t=CI();function n(r,s){return e(r,s,function(l,c){return t(r,c)})}return cx=n,cx}var ux,FT;function q7(){if(FT)return ux;FT=1;var e=GI(),t=LI(),n=PI();function r(s){return n(t(s,void 0,e),s+"")}return ux=r,ux}var dx,qT;function B7(){if(qT)return dx;qT=1;var e=F7(),t=q7(),n=t(function(r,s){return r==null?{}:e(r,s)});return dx=n,dx}var hx,BT;function z7(){if(BT)return hx;BT=1;var e=Math.ceil,t=Math.max;function n(r,s,l,c){for(var u=-1,f=t(e((s-r)/(l||1)),0),p=Array(f);f--;)p[c?f:++u]=r,r+=l;return p}return hx=n,hx}var fx,zT;function U7(){if(zT)return fx;zT=1;var e=z7(),t=Zf(),n=VI();function r(s){return function(l,c,u){return u&&typeof u!="number"&&t(l,c,u)&&(c=u=void 0),l=n(l),c===void 0?(c=l,l=0):c=n(c),u=u===void 0?l<c?1:-1:n(u),e(l,c,u,s)}}return fx=r,fx}var px,UT;function H7(){if(UT)return px;UT=1;var e=U7(),t=e();return px=t,px}var mx,HT;function W7(){if(HT)return mx;HT=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return mx=e,mx}var gx,WT;function V7(){if(WT)return gx;WT=1;var e=lc();function t(n,r){if(n!==r){var s=n!==void 0,l=n===null,c=n===n,u=e(n),f=r!==void 0,p=r===null,h=r===r,m=e(r);if(!p&&!m&&!u&&n>r||u&&f&&h&&!p&&!m||l&&f&&h||!s&&h||!c)return 1;if(!l&&!u&&!m&&n<r||m&&s&&c&&!l&&!u||p&&s&&c||!f&&c||!h)return-1}return 0}return gx=t,gx}var yx,VT;function G7(){if(VT)return yx;VT=1;var e=V7();function t(n,r,s){for(var l=-1,c=n.criteria,u=r.criteria,f=c.length,p=s.length;++l<f;){var h=e(c[l],u[l]);if(h){if(l>=p)return h;var m=s[l];return h*(m=="desc"?-1:1)}}return n.index-r.index}return yx=t,yx}var wx,GT;function K7(){if(GT)return wx;GT=1;var e=Gf(),t=Yf(),n=pa(),r=II(),s=W7(),l=Uf(),c=G7(),u=Ei(),f=nn();function p(h,m,y){m.length?m=e(m,function(b){return f(b)?function(_){return t(_,b.length===1?b[0]:b)}:b}):m=[u];var v=-1;m=e(m,l(n));var S=r(h,function(b,_,k){var j=e(m,function(E){return E(b)});return{criteria:j,index:++v,value:b}});return s(S,function(b,_){return c(b,_,y)})}return wx=p,wx}var vx,KT;function Y7(){if(KT)return vx;KT=1;var e=ok(),t=K7(),n=Xf(),r=Zf(),s=n(function(l,c){if(l==null)return[];var u=c.length;return u>1&&r(l,c[0],c[1])?c=[]:u>2&&r(c[0],c[1],c[2])&&(c=[c[0]]),t(l,e(c,1),[])});return vx=s,vx}var xx,YT;function X7(){if(YT)return xx;YT=1;var e=_I(),t=0;function n(r){var s=++t;return e(r)+s}return xx=n,xx}var bx,XT;function Z7(){if(XT)return bx;XT=1;function e(t,n,r){for(var s=-1,l=t.length,c=n.length,u={};++s<l;){var f=s<c?n[s]:void 0;r(u,t[s],f)}return u}return bx=e,bx}var kx,ZT;function Q7(){if(ZT)return kx;ZT=1;var e=Bf(),t=Z7();function n(r,s){return t(r||[],s||[],e)}return kx=n,kx}var Nx,QT;function Dt(){if(QT)return Nx;QT=1;var e;if(typeof Wb=="function")try{e={cloneDeep:p7(),constant:tk(),defaults:m7(),each:vI(),filter:RI(),find:k7(),flatten:GI(),forEach:wI(),forIn:N7(),has:AI(),isUndefined:MI(),last:S7(),map:$I(),mapValues:j7(),max:E7(),merge:I7(),min:$7(),minBy:O7(),now:L7(),pick:B7(),range:H7(),reduce:OI(),sortBy:Y7(),uniqueId:X7(),values:qI(),zipObject:Q7()}}catch{}return e||(e=window._),Nx=e,Nx}var Sx,JT;function J7(){if(JT)return Sx;JT=1,Sx=e;function e(){var r={};r._next=r._prev=r,this._sentinel=r}e.prototype.dequeue=function(){var r=this._sentinel,s=r._prev;if(s!==r)return t(s),s},e.prototype.enqueue=function(r){var s=this._sentinel;r._prev&&r._next&&t(r),r._next=s._next,s._next._prev=r,s._next=r,r._prev=s},e.prototype.toString=function(){for(var r=[],s=this._sentinel,l=s._prev;l!==s;)r.push(JSON.stringify(l,n)),l=l._prev;return"["+r.join(", ")+"]"};function t(r){r._prev._next=r._next,r._next._prev=r._prev,delete r._next,delete r._prev}function n(r,s){if(r!=="_next"&&r!=="_prev")return s}return Sx}var jx,e2;function e9(){if(e2)return jx;e2=1;var e=Dt(),t=xs().Graph,n=J7();jx=s;var r=e.constant(1);function s(p,h){if(p.nodeCount()<=1)return[];var m=u(p,h||r),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(v){return p.outEdges(v.v,v.w)}),!0)}function l(p,h,m){for(var y=[],v=h[h.length-1],S=h[0],b;p.nodeCount();){for(;b=S.dequeue();)c(p,h,m,b);for(;b=v.dequeue();)c(p,h,m,b);if(p.nodeCount()){for(var _=h.length-2;_>0;--_)if(b=h[_].dequeue(),b){y=y.concat(c(p,h,m,b,!0));break}}}return y}function c(p,h,m,y,v){var S=v?[]:void 0;return e.forEach(p.inEdges(y.v),function(b){var _=p.edge(b),k=p.node(b.v);v&&S.push({v:b.v,w:b.w}),k.out-=_,f(h,m,k)}),e.forEach(p.outEdges(y.v),function(b){var _=p.edge(b),k=b.w,j=p.node(k);j.in-=_,f(h,m,j)}),p.removeNode(y.v),S}function u(p,h){var m=new t,y=0,v=0;e.forEach(p.nodes(),function(_){m.setNode(_,{v:_,in:0,out:0})}),e.forEach(p.edges(),function(_){var k=m.edge(_.v,_.w)||0,j=h(_),E=k+j;m.setEdge(_.v,_.w,E),v=Math.max(v,m.node(_.v).out+=j),y=Math.max(y,m.node(_.w).in+=j)});var S=e.range(v+y+3).map(function(){return new n}),b=y+1;return e.forEach(m.nodes(),function(_){f(S,b,m.node(_))}),{graph:m,buckets:S,zeroIdx:b}}function f(p,h,m){m.out?m.in?p[m.out-m.in+h].enqueue(m):p[p.length-1].enqueue(m):p[0].enqueue(m)}return jx}var _x,t2;function t9(){if(t2)return _x;t2=1;var e=Dt(),t=e9();_x={run:n,undo:s};function n(l){var c=l.graph().acyclicer==="greedy"?t(l,u(l)):r(l);e.forEach(c,function(f){var p=l.edge(f);l.removeEdge(f),p.forwardName=f.name,p.reversed=!0,l.setEdge(f.w,f.v,p,e.uniqueId("rev"))});function u(f){return function(p){return f.edge(p).weight}}}function r(l){var c=[],u={},f={};function p(h){e.has(f,h)||(f[h]=!0,u[h]=!0,e.forEach(l.outEdges(h),function(m){e.has(u,m.w)?c.push(m):p(m.w)}),delete u[h])}return e.forEach(l.nodes(),p),c}function s(l){e.forEach(l.edges(),function(c){var u=l.edge(c);if(u.reversed){l.removeEdge(c);var f=u.forwardName;delete u.reversed,delete u.forwardName,l.setEdge(c.w,c.v,u,f)}})}return _x}var Ex,n2;function ar(){if(n2)return Ex;n2=1;var e=Dt(),t=xs().Graph;Ex={addDummyNode:n,simplify:r,asNonCompoundGraph:s,successorWeights:l,predecessorWeights:c,intersectRect:u,buildLayerMatrix:f,normalizeRanks:p,removeEmptyRanks:h,addBorderNode:m,maxRank:y,partition:v,time:S,notime:b};function n(_,k,j,E){var C;do C=e.uniqueId(E);while(_.hasNode(C));return j.dummy=k,_.setNode(C,j),C}function r(_){var k=new t().setGraph(_.graph());return e.forEach(_.nodes(),function(j){k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){var E=k.edge(j.v,j.w)||{weight:0,minlen:1},C=_.edge(j);k.setEdge(j.v,j.w,{weight:E.weight+C.weight,minlen:Math.max(E.minlen,C.minlen)})}),k}function s(_){var k=new t({multigraph:_.isMultigraph()}).setGraph(_.graph());return e.forEach(_.nodes(),function(j){_.children(j).length||k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){k.setEdge(j,_.edge(j))}),k}function l(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.outEdges(j),function(C){E[C.w]=(E[C.w]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function c(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.inEdges(j),function(C){E[C.v]=(E[C.v]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function u(_,k){var j=_.x,E=_.y,C=k.x-j,R=k.y-E,I=_.width/2,$=_.height/2;if(!C&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var q,B;return Math.abs(R)*I>Math.abs(C)*$?(R<0&&($=-$),q=$*C/R,B=$):(C<0&&(I=-I),q=I,B=I*R/C),{x:j+q,y:E+B}}function f(_){var k=e.map(e.range(y(_)+1),function(){return[]});return e.forEach(_.nodes(),function(j){var E=_.node(j),C=E.rank;e.isUndefined(C)||(k[C][E.order]=j)}),k}function p(_){var k=e.min(e.map(_.nodes(),function(j){return _.node(j).rank}));e.forEach(_.nodes(),function(j){var E=_.node(j);e.has(E,"rank")&&(E.rank-=k)})}function h(_){var k=e.min(e.map(_.nodes(),function(R){return _.node(R).rank})),j=[];e.forEach(_.nodes(),function(R){var I=_.node(R).rank-k;j[I]||(j[I]=[]),j[I].push(R)});var E=0,C=_.graph().nodeRankFactor;e.forEach(j,function(R,I){e.isUndefined(R)&&I%C!==0?--E:E&&e.forEach(R,function($){_.node($).rank+=E})})}function m(_,k,j,E){var C={width:0,height:0};return arguments.length>=4&&(C.rank=j,C.order=E),n(_,"border",C,k)}function y(_){return e.max(e.map(_.nodes(),function(k){var j=_.node(k).rank;if(!e.isUndefined(j))return j}))}function v(_,k){var j={lhs:[],rhs:[]};return e.forEach(_,function(E){k(E)?j.lhs.push(E):j.rhs.push(E)}),j}function S(_,k){var j=e.now();try{return k()}finally{console.log(_+" time: "+(e.now()-j)+"ms")}}function b(_,k){return k()}return Ex}var Cx,r2;function n9(){if(r2)return Cx;r2=1;var e=Dt(),t=ar();Cx={run:n,undo:s};function n(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(c){r(l,c)})}function r(l,c){var u=c.v,f=l.node(u).rank,p=c.w,h=l.node(p).rank,m=c.name,y=l.edge(c),v=y.labelRank;if(h!==f+1){l.removeEdge(c);var S,b,_;for(_=0,++f;f<h;++_,++f)y.points=[],b={width:0,height:0,edgeLabel:y,edgeObj:c,rank:f},S=t.addDummyNode(l,"edge",b,"_d"),f===v&&(b.width=y.width,b.height=y.height,b.dummy="edge-label",b.labelpos=y.labelpos),l.setEdge(u,S,{weight:y.weight},m),_===0&&l.graph().dummyChains.push(S),u=S;l.setEdge(u,p,{weight:y.weight},m)}}function s(l){e.forEach(l.graph().dummyChains,function(c){var u=l.node(c),f=u.edgeLabel,p;for(l.setEdge(u.edgeObj,f);u.dummy;)p=l.successors(c)[0],l.removeNode(c),f.points.push({x:u.x,y:u.y}),u.dummy==="edge-label"&&(f.x=u.x,f.y=u.y,f.width=u.width,f.height=u.height),c=p,u=l.node(c)})}return Cx}var Tx,s2;function cf(){if(s2)return Tx;s2=1;var e=Dt();Tx={longestPath:t,slack:n};function t(r){var s={};function l(c){var u=r.node(c);if(e.has(s,c))return u.rank;s[c]=!0;var f=e.min(e.map(r.outEdges(c),function(p){return l(p.w)-r.edge(p).minlen}));return(f===Number.POSITIVE_INFINITY||f===void 0||f===null)&&(f=0),u.rank=f}e.forEach(r.sources(),l)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return Tx}var Rx,a2;function ZI(){if(a2)return Rx;a2=1;var e=Dt(),t=xs().Graph,n=cf().slack;Rx=r;function r(u){var f=new t({directed:!1}),p=u.nodes()[0],h=u.nodeCount();f.setNode(p,{});for(var m,y;s(f,u)<h;)m=l(f,u),y=f.hasNode(m.v)?n(u,m):-n(u,m),c(f,u,y);return f}function s(u,f){function p(h){e.forEach(f.nodeEdges(h),function(m){var y=m.v,v=h===y?m.w:y;!u.hasNode(v)&&!n(f,m)&&(u.setNode(v,{}),u.setEdge(h,v,{}),p(v))})}return e.forEach(u.nodes(),p),u.nodeCount()}function l(u,f){return e.minBy(f.edges(),function(p){if(u.hasNode(p.v)!==u.hasNode(p.w))return n(f,p)})}function c(u,f,p){e.forEach(u.nodes(),function(h){f.node(h).rank+=p})}return Rx}var Ax,o2;function r9(){if(o2)return Ax;o2=1;var e=Dt(),t=ZI(),n=cf().slack,r=cf().longestPath,s=xs().alg.preorder,l=xs().alg.postorder,c=ar().simplify;Ax=u,u.initLowLimValues=m,u.initCutValues=f,u.calcCutValue=h,u.leaveEdge=v,u.enterEdge=S,u.exchangeEdges=b;function u(E){E=c(E),r(E);var C=t(E);m(C),f(C,E);for(var R,I;R=v(C);)I=S(C,E,R),b(C,E,R,I)}function f(E,C){var R=l(E,E.nodes());R=R.slice(0,R.length-1),e.forEach(R,function(I){p(E,C,I)})}function p(E,C,R){var I=E.node(R),$=I.parent;E.edge(R,$).cutvalue=h(E,C,R)}function h(E,C,R){var I=E.node(R),$=I.parent,q=!0,B=C.edge(R,$),P=0;return B||(q=!1,B=C.edge($,R)),P=B.weight,e.forEach(C.nodeEdges(R),function(W){var ne=W.v===R,ee=ne?W.w:W.v;if(ee!==$){var M=ne===q,X=C.edge(W).weight;if(P+=M?X:-X,k(E,R,ee)){var V=E.edge(R,ee).cutvalue;P+=M?-V:V}}}),P}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,R,I,$){var q=R,B=E.node(I);return C[I]=!0,e.forEach(E.neighbors(I),function(P){e.has(C,P)||(R=y(E,C,R,P,I))}),B.low=q,B.lim=R++,$?B.parent=$:delete B.parent,R}function v(E){return e.find(E.edges(),function(C){return E.edge(C).cutvalue<0})}function S(E,C,R){var I=R.v,$=R.w;C.hasEdge(I,$)||(I=R.w,$=R.v);var q=E.node(I),B=E.node($),P=q,W=!1;q.lim>B.lim&&(P=B,W=!0);var ne=e.filter(C.edges(),function(ee){return W===j(E,E.node(ee.v),P)&&W!==j(E,E.node(ee.w),P)});return e.minBy(ne,function(ee){return n(C,ee)})}function b(E,C,R,I){var $=R.v,q=R.w;E.removeEdge($,q),E.setEdge(I.v,I.w,{}),m(E),f(E,C),_(E,C)}function _(E,C){var R=e.find(E.nodes(),function($){return!C.node($).parent}),I=s(E,R);I=I.slice(1),e.forEach(I,function($){var q=E.node($).parent,B=C.edge($,q),P=!1;B||(B=C.edge(q,$),P=!0),C.node($).rank=C.node(q).rank+(P?B.minlen:-B.minlen)})}function k(E,C,R){return E.hasEdge(C,R)}function j(E,C,R){return R.low<=C.lim&&C.lim<=R.lim}return Ax}var Mx,i2;function s9(){if(i2)return Mx;i2=1;var e=cf(),t=e.longestPath,n=ZI(),r=r9();Mx=s;function s(f){switch(f.graph().ranker){case"network-simplex":u(f);break;case"tight-tree":c(f);break;case"longest-path":l(f);break;default:u(f)}}var l=t;function c(f){t(f),n(f)}function u(f){r(f)}return Mx}var Ix,l2;function a9(){if(l2)return Ix;l2=1;var e=Dt();Ix=t;function t(s){var l=r(s);e.forEach(s.graph().dummyChains,function(c){for(var u=s.node(c),f=u.edgeObj,p=n(s,l,f.v,f.w),h=p.path,m=p.lca,y=0,v=h[y],S=!0;c!==f.w;){if(u=s.node(c),S){for(;(v=h[y])!==m&&s.node(v).maxRank<u.rank;)y++;v===m&&(S=!1)}if(!S){for(;y<h.length-1&&s.node(v=h[y+1]).minRank<=u.rank;)y++;v=h[y]}s.setParent(c,v),c=s.successors(c)[0]}})}function n(s,l,c,u){var f=[],p=[],h=Math.min(l[c].low,l[u].low),m=Math.max(l[c].lim,l[u].lim),y,v;y=c;do y=s.parent(y),f.push(y);while(y&&(l[y].low>h||m>l[y].lim));for(v=y,y=u;(y=s.parent(y))!==v;)p.push(y);return{path:f.concat(p.reverse()),lca:v}}function r(s){var l={},c=0;function u(f){var p=c;e.forEach(s.children(f),u),l[f]={low:p,lim:c++}}return e.forEach(s.children(),u),l}return Ix}var $x,c2;function o9(){if(c2)return $x;c2=1;var e=Dt(),t=ar();$x={run:n,cleanup:c};function n(u){var f=t.addDummyNode(u,"root",{},"_root"),p=s(u),h=e.max(e.values(p))-1,m=2*h+1;u.graph().nestingRoot=f,e.forEach(u.edges(),function(v){u.edge(v).minlen*=m});var y=l(u)+1;e.forEach(u.children(),function(v){r(u,f,m,y,h,p,v)}),u.graph().nodeRankFactor=m}function r(u,f,p,h,m,y,v){var S=u.children(v);if(!S.length){v!==f&&u.setEdge(f,v,{weight:0,minlen:p});return}var b=t.addBorderNode(u,"_bt"),_=t.addBorderNode(u,"_bb"),k=u.node(v);u.setParent(b,v),k.borderTop=b,u.setParent(_,v),k.borderBottom=_,e.forEach(S,function(j){r(u,f,p,h,m,y,j);var E=u.node(j),C=E.borderTop?E.borderTop:j,R=E.borderBottom?E.borderBottom:j,I=E.borderTop?h:2*h,$=C!==R?1:m-y[v]+1;u.setEdge(b,C,{weight:I,minlen:$,nestingEdge:!0}),u.setEdge(R,_,{weight:I,minlen:$,nestingEdge:!0})}),u.parent(v)||u.setEdge(f,b,{weight:0,minlen:m+y[v]})}function s(u){var f={};function p(h,m){var y=u.children(h);y&&y.length&&e.forEach(y,function(v){p(v,m+1)}),f[h]=m}return e.forEach(u.children(),function(h){p(h,1)}),f}function l(u){return e.reduce(u.edges(),function(f,p){return f+u.edge(p).weight},0)}function c(u){var f=u.graph();u.removeNode(f.nestingRoot),delete f.nestingRoot,e.forEach(u.edges(),function(p){var h=u.edge(p);h.nestingEdge&&u.removeEdge(p)})}return $x}var Ox,u2;function i9(){if(u2)return Ox;u2=1;var e=Dt(),t=ar();Ox=n;function n(s){function l(c){var u=s.children(c),f=s.node(c);if(u.length&&e.forEach(u,l),e.has(f,"minRank")){f.borderLeft=[],f.borderRight=[];for(var p=f.minRank,h=f.maxRank+1;p<h;++p)r(s,"borderLeft","_bl",c,f,p),r(s,"borderRight","_br",c,f,p)}}e.forEach(s.children(),l)}function r(s,l,c,u,f,p){var h={width:0,height:0,rank:p,borderType:l},m=f[l][p-1],y=t.addDummyNode(s,"border",h,c);f[l][p]=y,s.setParent(y,u),m&&s.setEdge(m,y,{weight:1})}return Ox}var Lx,d2;function l9(){if(d2)return Lx;d2=1;var e=Dt();Lx={adjust:t,undo:n};function t(p){var h=p.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&r(p)}function n(p){var h=p.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&l(p),(h==="lr"||h==="rl")&&(u(p),r(p))}function r(p){e.forEach(p.nodes(),function(h){s(p.node(h))}),e.forEach(p.edges(),function(h){s(p.edge(h))})}function s(p){var h=p.width;p.width=p.height,p.height=h}function l(p){e.forEach(p.nodes(),function(h){c(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,c),e.has(m,"y")&&c(m)})}function c(p){p.y=-p.y}function u(p){e.forEach(p.nodes(),function(h){f(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,f),e.has(m,"x")&&f(m)})}function f(p){var h=p.x;p.x=p.y,p.y=h}return Lx}var Px,h2;function c9(){if(h2)return Px;h2=1;var e=Dt();Px=t;function t(n){var r={},s=e.filter(n.nodes(),function(p){return!n.children(p).length}),l=e.max(e.map(s,function(p){return n.node(p).rank})),c=e.map(e.range(l+1),function(){return[]});function u(p){if(!e.has(r,p)){r[p]=!0;var h=n.node(p);c[h.rank].push(p),e.forEach(n.successors(p),u)}}var f=e.sortBy(s,function(p){return n.node(p).rank});return e.forEach(f,u),c}return Px}var Dx,f2;function u9(){if(f2)return Dx;f2=1;var e=Dt();Dx=t;function t(r,s){for(var l=0,c=1;c<s.length;++c)l+=n(r,s[c-1],s[c]);return l}function n(r,s,l){for(var c=e.zipObject(l,e.map(l,function(y,v){return v})),u=e.flatten(e.map(s,function(y){return e.sortBy(e.map(r.outEdges(y),function(v){return{pos:c[v.w],weight:r.edge(v).weight}}),"pos")}),!0),f=1;f<l.length;)f<<=1;var p=2*f-1;f-=1;var h=e.map(new Array(p),function(){return 0}),m=0;return e.forEach(u.forEach(function(y){var v=y.pos+f;h[v]+=y.weight;for(var S=0;v>0;)v%2&&(S+=h[v+1]),v=v-1>>1,h[v]+=y.weight;m+=y.weight*S})),m}return Dx}var Fx,p2;function d9(){if(p2)return Fx;p2=1;var e=Dt();Fx=t;function t(n,r){return e.map(r,function(s){var l=n.inEdges(s);if(l.length){var c=e.reduce(l,function(u,f){var p=n.edge(f),h=n.node(f.v);return{sum:u.sum+p.weight*h.order,weight:u.weight+p.weight}},{sum:0,weight:0});return{v:s,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:s}})}return Fx}var qx,m2;function h9(){if(m2)return qx;m2=1;var e=Dt();qx=t;function t(s,l){var c={};e.forEach(s,function(f,p){var h=c[f.v]={indegree:0,in:[],out:[],vs:[f.v],i:p};e.isUndefined(f.barycenter)||(h.barycenter=f.barycenter,h.weight=f.weight)}),e.forEach(l.edges(),function(f){var p=c[f.v],h=c[f.w];!e.isUndefined(p)&&!e.isUndefined(h)&&(h.indegree++,p.out.push(c[f.w]))});var u=e.filter(c,function(f){return!f.indegree});return n(u)}function n(s){var l=[];function c(p){return function(h){h.merged||(e.isUndefined(h.barycenter)||e.isUndefined(p.barycenter)||h.barycenter>=p.barycenter)&&r(p,h)}}function u(p){return function(h){h.in.push(p),--h.indegree===0&&s.push(h)}}for(;s.length;){var f=s.pop();l.push(f),e.forEach(f.in.reverse(),c(f)),e.forEach(f.out,u(f))}return e.map(e.filter(l,function(p){return!p.merged}),function(p){return e.pick(p,["vs","i","barycenter","weight"])})}function r(s,l){var c=0,u=0;s.weight&&(c+=s.barycenter*s.weight,u+=s.weight),l.weight&&(c+=l.barycenter*l.weight,u+=l.weight),s.vs=l.vs.concat(s.vs),s.barycenter=c/u,s.weight=u,s.i=Math.min(l.i,s.i),l.merged=!0}return qx}var Bx,g2;function f9(){if(g2)return Bx;g2=1;var e=Dt(),t=ar();Bx=n;function n(l,c){var u=t.partition(l,function(b){return e.has(b,"barycenter")}),f=u.lhs,p=e.sortBy(u.rhs,function(b){return-b.i}),h=[],m=0,y=0,v=0;f.sort(s(!!c)),v=r(h,p,v),e.forEach(f,function(b){v+=b.vs.length,h.push(b.vs),m+=b.barycenter*b.weight,y+=b.weight,v=r(h,p,v)});var S={vs:e.flatten(h,!0)};return y&&(S.barycenter=m/y,S.weight=y),S}function r(l,c,u){for(var f;c.length&&(f=e.last(c)).i<=u;)c.pop(),l.push(f.vs),u++;return u}function s(l){return function(c,u){return c.barycenter<u.barycenter?-1:c.barycenter>u.barycenter?1:l?u.i-c.i:c.i-u.i}}return Bx}var zx,y2;function p9(){if(y2)return zx;y2=1;var e=Dt(),t=d9(),n=h9(),r=f9();zx=s;function s(u,f,p,h){var m=u.children(f),y=u.node(f),v=y?y.borderLeft:void 0,S=y?y.borderRight:void 0,b={};v&&(m=e.filter(m,function(R){return R!==v&&R!==S}));var _=t(u,m);e.forEach(_,function(R){if(u.children(R.v).length){var I=s(u,R.v,p,h);b[R.v]=I,e.has(I,"barycenter")&&c(R,I)}});var k=n(_,p);l(k,b);var j=r(k,h);if(v&&(j.vs=e.flatten([v,j.vs,S],!0),u.predecessors(v).length)){var E=u.node(u.predecessors(v)[0]),C=u.node(u.predecessors(S)[0]);e.has(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+E.order+C.order)/(j.weight+2),j.weight+=2}return j}function l(u,f){e.forEach(u,function(p){p.vs=e.flatten(p.vs.map(function(h){return f[h]?f[h].vs:h}),!0)})}function c(u,f){e.isUndefined(u.barycenter)?(u.barycenter=f.barycenter,u.weight=f.weight):(u.barycenter=(u.barycenter*u.weight+f.barycenter*f.weight)/(u.weight+f.weight),u.weight+=f.weight)}return zx}var Ux,w2;function m9(){if(w2)return Ux;w2=1;var e=Dt(),t=xs().Graph;Ux=n;function n(s,l,c){var u=r(s),f=new t({compound:!0}).setGraph({root:u}).setDefaultNodeLabel(function(p){return s.node(p)});return e.forEach(s.nodes(),function(p){var h=s.node(p),m=s.parent(p);(h.rank===l||h.minRank<=l&&l<=h.maxRank)&&(f.setNode(p),f.setParent(p,m||u),e.forEach(s[c](p),function(y){var v=y.v===p?y.w:y.v,S=f.edge(v,p),b=e.isUndefined(S)?0:S.weight;f.setEdge(v,p,{weight:s.edge(y).weight+b})}),e.has(h,"minRank")&&f.setNode(p,{borderLeft:h.borderLeft[l],borderRight:h.borderRight[l]}))}),f}function r(s){for(var l;s.hasNode(l=e.uniqueId("_root")););return l}return Ux}var Hx,v2;function g9(){if(v2)return Hx;v2=1;var e=Dt();Hx=t;function t(n,r,s){var l={},c;e.forEach(s,function(u){for(var f=n.parent(u),p,h;f;){if(p=n.parent(f),p?(h=l[p],l[p]=f):(h=c,c=f),h&&h!==f){r.setEdge(h,f);return}f=p}})}return Hx}var Wx,x2;function y9(){if(x2)return Wx;x2=1;var e=Dt(),t=c9(),n=u9(),r=p9(),s=m9(),l=g9(),c=xs().Graph,u=ar();Wx=f;function f(y){var v=u.maxRank(y),S=p(y,e.range(1,v+1),"inEdges"),b=p(y,e.range(v-1,-1,-1),"outEdges"),_=t(y);m(y,_);for(var k=Number.POSITIVE_INFINITY,j,E=0,C=0;C<4;++E,++C){h(E%2?S:b,E%4>=2),_=u.buildLayerMatrix(y);var R=n(y,_);R<k&&(C=0,j=e.cloneDeep(_),k=R)}m(y,j)}function p(y,v,S){return e.map(v,function(b){return s(y,b,S)})}function h(y,v){var S=new c;e.forEach(y,function(b){var _=b.graph().root,k=r(b,_,S,v);e.forEach(k.vs,function(j,E){b.node(j).order=E}),l(b,S,k.vs)})}function m(y,v){e.forEach(v,function(S){e.forEach(S,function(b,_){y.node(b).order=_})})}return Wx}var Vx,b2;function w9(){if(b2)return Vx;b2=1;var e=Dt(),t=xs().Graph,n=ar();Vx={positionX:S,findType1Conflicts:r,findType2Conflicts:s,addConflict:c,hasConflict:u,verticalAlignment:f,horizontalCompaction:p,alignCoordinates:y,findSmallestWidthAlignment:m,balance:v};function r(k,j){var E={};function C(R,I){var $=0,q=0,B=R.length,P=e.last(I);return e.forEach(I,function(W,ne){var ee=l(k,W),M=ee?k.node(ee).order:B;(ee||W===P)&&(e.forEach(I.slice(q,ne+1),function(X){e.forEach(k.predecessors(X),function(V){var G=k.node(V),F=G.order;(F<$||M<F)&&!(G.dummy&&k.node(X).dummy)&&c(E,V,X)})}),q=ne+1,$=M)}),I}return e.reduce(j,C),E}function s(k,j){var E={};function C(I,$,q,B,P){var W;e.forEach(e.range($,q),function(ne){W=I[ne],k.node(W).dummy&&e.forEach(k.predecessors(W),function(ee){var M=k.node(ee);M.dummy&&(M.order<B||M.order>P)&&c(E,ee,W)})})}function R(I,$){var q=-1,B,P=0;return e.forEach($,function(W,ne){if(k.node(W).dummy==="border"){var ee=k.predecessors(W);ee.length&&(B=k.node(ee[0]).order,C($,P,ne,q,B),P=ne,q=B)}C($,P,$.length,B,I.length)}),$}return e.reduce(j,R),E}function l(k,j){if(k.node(j).dummy)return e.find(k.predecessors(j),function(E){return k.node(E).dummy})}function c(k,j,E){if(j>E){var C=j;j=E,E=C}var R=k[j];R||(k[j]=R={}),R[E]=!0}function u(k,j,E){if(j>E){var C=j;j=E,E=C}return e.has(k[j],E)}function f(k,j,E,C){var R={},I={},$={};return e.forEach(j,function(q){e.forEach(q,function(B,P){R[B]=B,I[B]=B,$[B]=P})}),e.forEach(j,function(q){var B=-1;e.forEach(q,function(P){var W=C(P);if(W.length){W=e.sortBy(W,function(V){return $[V]});for(var ne=(W.length-1)/2,ee=Math.floor(ne),M=Math.ceil(ne);ee<=M;++ee){var X=W[ee];I[P]===P&&B<$[X]&&!u(E,P,X)&&(I[X]=P,I[P]=R[P]=R[X],B=$[X])}}})}),{root:R,align:I}}function p(k,j,E,C,R){var I={},$=h(k,j,E,R),q=R?"borderLeft":"borderRight";function B(ne,ee){for(var M=$.nodes(),X=M.pop(),V={};X;)V[X]?ne(X):(V[X]=!0,M.push(X),M=M.concat(ee(X))),X=M.pop()}function P(ne){I[ne]=$.inEdges(ne).reduce(function(ee,M){return Math.max(ee,I[M.v]+$.edge(M))},0)}function W(ne){var ee=$.outEdges(ne).reduce(function(X,V){return Math.min(X,I[V.w]-$.edge(V))},Number.POSITIVE_INFINITY),M=k.node(ne);ee!==Number.POSITIVE_INFINITY&&M.borderType!==q&&(I[ne]=Math.max(I[ne],ee))}return B(P,$.predecessors.bind($)),B(W,$.successors.bind($)),e.forEach(C,function(ne){I[ne]=I[E[ne]]}),I}function h(k,j,E,C){var R=new t,I=k.graph(),$=b(I.nodesep,I.edgesep,C);return e.forEach(j,function(q){var B;e.forEach(q,function(P){var W=E[P];if(R.setNode(W),B){var ne=E[B],ee=R.edge(ne,W);R.setEdge(ne,W,Math.max($(k,P,B),ee||0))}B=P})}),R}function m(k,j){return e.minBy(e.values(j),function(E){var C=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY;return e.forIn(E,function(I,$){var q=_(k,$)/2;C=Math.max(I+q,C),R=Math.min(I-q,R)}),C-R})}function y(k,j){var E=e.values(j),C=e.min(E),R=e.max(E);e.forEach(["u","d"],function(I){e.forEach(["l","r"],function($){var q=I+$,B=k[q],P;if(B!==j){var W=e.values(B);P=$==="l"?C-e.min(W):R-e.max(W),P&&(k[q]=e.mapValues(B,function(ne){return ne+P}))}})})}function v(k,j){return e.mapValues(k.ul,function(E,C){if(j)return k[j.toLowerCase()][C];var R=e.sortBy(e.map(k,C));return(R[1]+R[2])/2})}function S(k){var j=n.buildLayerMatrix(k),E=e.merge(r(k,j),s(k,j)),C={},R;e.forEach(["u","d"],function($){R=$==="u"?j:e.values(j).reverse(),e.forEach(["l","r"],function(q){q==="r"&&(R=e.map(R,function(ne){return e.values(ne).reverse()}));var B=($==="u"?k.predecessors:k.successors).bind(k),P=f(k,R,E,B),W=p(k,R,P.root,P.align,q==="r");q==="r"&&(W=e.mapValues(W,function(ne){return-ne})),C[$+q]=W})});var I=m(k,C);return y(C,I),v(C,k.graph().align)}function b(k,j,E){return function(C,R,I){var $=C.node(R),q=C.node(I),B=0,P;if(B+=$.width/2,e.has($,"labelpos"))switch($.labelpos.toLowerCase()){case"l":P=-$.width/2;break;case"r":P=$.width/2;break}if(P&&(B+=E?P:-P),P=0,B+=($.dummy?j:k)/2,B+=(q.dummy?j:k)/2,B+=q.width/2,e.has(q,"labelpos"))switch(q.labelpos.toLowerCase()){case"l":P=q.width/2;break;case"r":P=-q.width/2;break}return P&&(B+=E?P:-P),P=0,B}}function _(k,j){return k.node(j).width}return Vx}var Gx,k2;function v9(){if(k2)return Gx;k2=1;var e=Dt(),t=ar(),n=w9().positionX;Gx=r;function r(l){l=t.asNonCompoundGraph(l),s(l),e.forEach(n(l),function(c,u){l.node(u).x=c})}function s(l){var c=t.buildLayerMatrix(l),u=l.graph().ranksep,f=0;e.forEach(c,function(p){var h=e.max(e.map(p,function(m){return l.node(m).height}));e.forEach(p,function(m){l.node(m).y=f+h/2}),f+=h+u})}return Gx}var Kx,N2;function x9(){if(N2)return Kx;N2=1;var e=Dt(),t=t9(),n=n9(),r=s9(),s=ar().normalizeRanks,l=a9(),c=ar().removeEmptyRanks,u=o9(),f=i9(),p=l9(),h=y9(),m=v9(),y=ar(),v=xs().Graph;Kx=S;function S(z,Z){var U=Z&&Z.debugTiming?y.time:y.notime;U("layout",function(){var ae=U(" buildLayoutGraph",function(){return B(z)});U(" runLayout",function(){b(ae,U)}),U(" updateInputGraph",function(){_(z,ae)})})}function b(z,Z){Z(" makeSpaceForEdgeLabels",function(){P(z)}),Z(" removeSelfEdges",function(){L(z)}),Z(" acyclic",function(){t.run(z)}),Z(" nestingGraph.run",function(){u.run(z)}),Z(" rank",function(){r(y.asNonCompoundGraph(z))}),Z(" injectEdgeLabelProxies",function(){W(z)}),Z(" removeEmptyRanks",function(){c(z)}),Z(" nestingGraph.cleanup",function(){u.cleanup(z)}),Z(" normalizeRanks",function(){s(z)}),Z(" assignRankMinMax",function(){ne(z)}),Z(" removeEdgeLabelProxies",function(){ee(z)}),Z(" normalize.run",function(){n.run(z)}),Z(" parentDummyChains",function(){l(z)}),Z(" addBorderSegments",function(){f(z)}),Z(" order",function(){h(z)}),Z(" insertSelfEdges",function(){H(z)}),Z(" adjustCoordinateSystem",function(){p.adjust(z)}),Z(" position",function(){m(z)}),Z(" positionSelfEdges",function(){D(z)}),Z(" removeBorderNodes",function(){F(z)}),Z(" normalize.undo",function(){n.undo(z)}),Z(" fixupEdgeLabelCoords",function(){V(z)}),Z(" undoCoordinateSystem",function(){p.undo(z)}),Z(" translateGraph",function(){M(z)}),Z(" assignNodeIntersects",function(){X(z)}),Z(" reversePoints",function(){G(z)}),Z(" acyclic.undo",function(){t.undo(z)})}function _(z,Z){e.forEach(z.nodes(),function(U){var ae=z.node(U),le=Z.node(U);ae&&(ae.x=le.x,ae.y=le.y,Z.children(U).length&&(ae.width=le.width,ae.height=le.height))}),e.forEach(z.edges(),function(U){var ae=z.edge(U),le=Z.edge(U);ae.points=le.points,e.has(le,"x")&&(ae.x=le.x,ae.y=le.y)}),z.graph().width=Z.graph().width,z.graph().height=Z.graph().height}var k=["nodesep","edgesep","ranksep","marginx","marginy"],j={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},E=["acyclicer","ranker","rankdir","align"],C=["width","height"],R={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],$={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},q=["labelpos"];function B(z){var Z=new v({multigraph:!0,compound:!0}),U=re(z.graph());return Z.setGraph(e.merge({},j,K(U,k),e.pick(U,E))),e.forEach(z.nodes(),function(ae){var le=re(z.node(ae));Z.setNode(ae,e.defaults(K(le,C),R)),Z.setParent(ae,z.parent(ae))}),e.forEach(z.edges(),function(ae){var le=re(z.edge(ae));Z.setEdge(ae,e.merge({},$,K(le,I),e.pick(le,q)))}),Z}function P(z){var Z=z.graph();Z.ranksep/=2,e.forEach(z.edges(),function(U){var ae=z.edge(U);ae.minlen*=2,ae.labelpos.toLowerCase()!=="c"&&(Z.rankdir==="TB"||Z.rankdir==="BT"?ae.width+=ae.labeloffset:ae.height+=ae.labeloffset)})}function W(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z);if(U.width&&U.height){var ae=z.node(Z.v),le=z.node(Z.w),ge={rank:(le.rank-ae.rank)/2+ae.rank,e:Z};y.addDummyNode(z,"edge-proxy",ge,"_ep")}})}function ne(z){var Z=0;e.forEach(z.nodes(),function(U){var ae=z.node(U);ae.borderTop&&(ae.minRank=z.node(ae.borderTop).rank,ae.maxRank=z.node(ae.borderBottom).rank,Z=e.max(Z,ae.maxRank))}),z.graph().maxRank=Z}function ee(z){e.forEach(z.nodes(),function(Z){var U=z.node(Z);U.dummy==="edge-proxy"&&(z.edge(U.e).labelRank=U.rank,z.removeNode(Z))})}function M(z){var Z=Number.POSITIVE_INFINITY,U=0,ae=Number.POSITIVE_INFINITY,le=0,ge=z.graph(),Ne=ge.marginx||0,Ie=ge.marginy||0;function Ge(Pe){var ze=Pe.x,Re=Pe.y,st=Pe.width,ue=Pe.height;Z=Math.min(Z,ze-st/2),U=Math.max(U,ze+st/2),ae=Math.min(ae,Re-ue/2),le=Math.max(le,Re+ue/2)}e.forEach(z.nodes(),function(Pe){Ge(z.node(Pe))}),e.forEach(z.edges(),function(Pe){var ze=z.edge(Pe);e.has(ze,"x")&&Ge(ze)}),Z-=Ne,ae-=Ie,e.forEach(z.nodes(),function(Pe){var ze=z.node(Pe);ze.x-=Z,ze.y-=ae}),e.forEach(z.edges(),function(Pe){var ze=z.edge(Pe);e.forEach(ze.points,function(Re){Re.x-=Z,Re.y-=ae}),e.has(ze,"x")&&(ze.x-=Z),e.has(ze,"y")&&(ze.y-=ae)}),ge.width=U-Z+Ne,ge.height=le-ae+Ie}function X(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z),ae=z.node(Z.v),le=z.node(Z.w),ge,Ne;U.points?(ge=U.points[0],Ne=U.points[U.points.length-1]):(U.points=[],ge=le,Ne=ae),U.points.unshift(y.intersectRect(ae,ge)),U.points.push(y.intersectRect(le,Ne))})}function V(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z);if(e.has(U,"x"))switch((U.labelpos==="l"||U.labelpos==="r")&&(U.width-=U.labeloffset),U.labelpos){case"l":U.x-=U.width/2+U.labeloffset;break;case"r":U.x+=U.width/2+U.labeloffset;break}})}function G(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z);U.reversed&&U.points.reverse()})}function F(z){e.forEach(z.nodes(),function(Z){if(z.children(Z).length){var U=z.node(Z),ae=z.node(U.borderTop),le=z.node(U.borderBottom),ge=z.node(e.last(U.borderLeft)),Ne=z.node(e.last(U.borderRight));U.width=Math.abs(Ne.x-ge.x),U.height=Math.abs(le.y-ae.y),U.x=ge.x+U.width/2,U.y=ae.y+U.height/2}}),e.forEach(z.nodes(),function(Z){z.node(Z).dummy==="border"&&z.removeNode(Z)})}function L(z){e.forEach(z.edges(),function(Z){if(Z.v===Z.w){var U=z.node(Z.v);U.selfEdges||(U.selfEdges=[]),U.selfEdges.push({e:Z,label:z.edge(Z)}),z.removeEdge(Z)}})}function H(z){var Z=y.buildLayerMatrix(z);e.forEach(Z,function(U){var ae=0;e.forEach(U,function(le,ge){var Ne=z.node(le);Ne.order=ge+ae,e.forEach(Ne.selfEdges,function(Ie){y.addDummyNode(z,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Ne.rank,order:ge+ ++ae,e:Ie.e,label:Ie.label},"_se")}),delete Ne.selfEdges})})}function D(z){e.forEach(z.nodes(),function(Z){var U=z.node(Z);if(U.dummy==="selfedge"){var ae=z.node(U.e.v),le=ae.x+ae.width/2,ge=ae.y,Ne=U.x-le,Ie=ae.height/2;z.setEdge(U.e,U.label),z.removeNode(Z),U.label.points=[{x:le+2*Ne/3,y:ge-Ie},{x:le+5*Ne/6,y:ge-Ie},{x:le+Ne,y:ge},{x:le+5*Ne/6,y:ge+Ie},{x:le+2*Ne/3,y:ge+Ie}],U.label.x=U.x,U.label.y=U.y}})}function K(z,Z){return e.mapValues(e.pick(z,Z),Number)}function re(z){var Z={};return e.forEach(z,function(U,ae){Z[ae.toLowerCase()]=U}),Z}return Kx}var Yx,S2;function b9(){if(S2)return Yx;S2=1;var e=Dt(),t=ar(),n=xs().Graph;Yx={debugOrdering:r};function r(s){var l=t.buildLayerMatrix(s),c=new n({compound:!0,multigraph:!0}).setGraph({});return e.forEach(s.nodes(),function(u){c.setNode(u,{label:u}),c.setParent(u,"layer"+s.node(u).rank)}),e.forEach(s.edges(),function(u){c.setEdge(u.v,u.w,{},u.name)}),e.forEach(l,function(u,f){var p="layer"+f;c.setNode(p,{rank:"same"}),e.reduce(u,function(h,m){return c.setEdge(h,m,{style:"invis"}),m})}),c}return Yx}var Xx,j2;function k9(){return j2||(j2=1,Xx="0.8.5"),Xx}var Zx,_2;function N9(){return _2||(_2=1,Zx={graphlib:xs(),layout:x9(),debug:b9(),util:{time:ar().time,notime:ar().notime},version:k9()}),Zx}var S9=N9();const E2=sb(S9),vi=240,Lu=130,zl=74,Qf=72,wu=zl+Qf;function QI(e,t){var r;let n=vi;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??vi);return n}const uf=420,JI=1;function j9(e,t,n,r){return Math.min(JI,n/Math.max(1,e),r/Math.max(1,t))}function xi(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function _9(e,t){return((t==null?void 0:t.get(e))??0)>0?uf:0}function E9(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function Pu(e,t,n){const r=t.get(e);return{w:((r==null?void 0:r.width)??vi)+_9(e,n),h:Math.max((r==null?void 0:r.height)??Lu,E9(e,n))}}function C9(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function T9(e,t,n,r,s,l){const c=new E2.graphlib.Graph;c.setDefaultEdgeLabel(()=>({})),c.setGraph({rankdir:n,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const u=e.filter(k=>!s.has(k)),f=new Set(u);for(const k of u){const{w:j,h:E}=Pu(k,r,l);c.setNode(k,{width:j,height:E})}for(const k of t)f.has(k.source)&&f.has(k.target)&&c.setEdge(k.source,k.target);E2.layout(c);const p=new Map;let h=1/0,m=1/0,y=-1/0,v=-1/0;for(const k of u){const j=c.node(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??vi,R=(E==null?void 0:E.height)??Lu,I=Pu(k,r,l),$=j.x-I.w/2,q=j.y-I.h/2;p.set(k,{x:$,y:q}),$<h&&(h=$),q<m&&(m=q),$+C>y&&(y=$+C),q+R>v&&(v=q+R)}if(Number.isFinite(h)&&Number.isFinite(m))for(const[k,j]of p)p.set(k,{x:j.x-h,y:j.y-m});const S=Number.isFinite(y)?y-h:0,b=Number.isFinite(v)?v-m:0;let _=null;for(const k of e){const j=s.get(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??vi,R=(E==null?void 0:E.height)??Lu;_=_===null?{minX:j.x,minY:j.y,maxX:j.x+C,maxY:j.y+R}:{minX:Math.min(_.minX,j.x),minY:Math.min(_.minY,j.y),maxX:Math.max(_.maxX,j.x+C),maxY:Math.max(_.maxY,j.y+R)}}return{positions:p,width:S,height:b,pinnedBox:_}}function e$(e,t,n){const r=n.direction??"LR",s=n.pinned??new Map,l=n.measured??new Map,c=n.lanes,u=new Map;for(const h of e){const m=xi(h),y=u.get(m);y?y.push(h.id):u.set(m,[h.id])}return{laid:Array.from(u.keys()).sort().map(h=>({sid:h,...T9(u.get(h),t,r,l,s,c)})),gap:QI(e,l)}}const t$=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+uf,R9=e=>e.reduce((t,n)=>t+n.height,0)+wu*Math.max(0,e.length-1);function H0(e,t,n,r){const s=f=>{const p=[[]];let h=0;for(const m of e)h>0&&h+m.height>f&&(p.push([]),h=0),p[p.length-1].push(m),h+=m.height+wu;return p},l=[];for(let f=0;f<e.length;f++){let p=-wu;for(let h=f;h<e.length;h++)l.push(p+=e[h].height+wu)}l.sort((f,p)=>f-p);const c=f=>{let p=0,h=l.length-1;for(;p<h;){const m=p+h>>1;s(l[m]).length<=f?h=m:p=m+1}return s(l[p])};let u=[e];if(n>0&&r>0){const f=h=>j9(h.reduce((m,y)=>m+t$(y),0)+t*(h.length-1),Math.max(...h.map(R9)),n,r);let p=f(u);for(let h=2;h<=e.length;h++){const m=c(h),y=f(m);y>p+1e-9&&(p=y,u=m)}}return u}function A9(e,t,n,r,s){if(!(r.width>0&&r.height>0&&s.width>0&&s.height>0))return!1;const{laid:l,gap:c}=e$(e,t,n);return l.length<2?!1:H0(l,c,r.width,r.height).length!==H0(l,c,s.width,s.height).length}function M9(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:l}=e$(e,t,n),c=H0(s,l,n.availableWidth??0,n.availableHeight??0),u=new Map;let f=0;for(const p of c){const h=t$(p);let m=0;for(const{positions:y,height:v,pinnedBox:S}of p){for(const[_,k]of y)u.set(_,{x:k.x+f,y:k.y+m});let b=m+v;S&&S.maxY>b&&S.minX<f+h&&f<S.maxX&&(b=S.maxY),m=b+wu}f+=h+l}return e.map(p=>{const h=r.get(p.id);if(h)return{...p,position:h};const m=u.get(p.id);return m?{...p,position:m}:p})}function I9(e,t,n,r,s){const c=zl+Qf,u=60,f=v=>Pu(v,r,s),p=new Map(e.map(v=>[v.id,xi(v)])),h=[],m=e.map(v=>({id:v.id,pos:n.get(v.id)??t.get(v.id)})).filter(v=>v.pos!=null).sort((v,S)=>v.pos.y-S.pos.y||v.pos.x-S.pos.x||v.id.localeCompare(S.id)),y=[];for(const{id:v,pos:S}of m){const{w:b,h:_}=f(v),k=p.get(v)??"_default";if(n.has(v)){h.push({x:S.x,y:S.y,w:b,h:_,sid:k});continue}let j=S.y;for(let E=0;E<h.length+1;E++){const C=h.find(R=>{const I=R.sid===k?24:u,$=R.sid===k?24:c;return S.x<R.x+R.w+I&&R.x<S.x+b+I&&j<R.y+R.h+$&&R.y<j+_+$});if(!C)break;j=C.y+C.h+(C.sid===k?24:c)}j!==S.y&&(t.set(v,{x:S.x,y:j}),y.push(v)),h.push({x:S.x,y:j,w:b,h:_,sid:k})}return y}function $9(e,t,n,r,s,l,c){const u=E=>Pu(E,r,l),f=E=>n.get(E)??t.get(E),p=E=>{const C=r.get(E);return{cw:(C==null?void 0:C.width)??vi,ch:(C==null?void 0:C.height)??Lu}},h=c!=null&&c.width>0&&c.height>0,m=new Map;for(const E of e){if(!f(E.id))continue;const C=xi(E),R=m.get(C);R?R.push(E):m.set(C,[E])}const y=new Set;for(const[E,C]of m)C.every(R=>s.has(R.id)&&!n.has(R.id))&&y.add(E);const v=new Map,S=[];for(const E of e){const C=f(E.id);if(!C)continue;const{w:R,h:I}=u(E.id),$=xi(E);y.has($)?(v.get($)??v.set($,[]).get($)).push(E):S.push({x:C.x,y:C.y,w:R,h:I,...p(E.id)})}if(v.size===0||h&&S.length===0)return[];const b=zl+Qf,_=(E,C,R,I)=>S.some($=>E<$.x+$.w+zl&&$.x<E+R+zl&&C<$.y+$.h+b&&$.y<C+I+b),k=QI(e,r),j=[];for(const E of[...v.keys()].sort()){const C=v.get(E);let R=1/0,I=1/0,$=-1/0,q=-1/0,B=-1/0,P=-1/0;for(const G of C){const F=f(G.id),{w:L,h:H}=u(G.id),{cw:D,ch:K}=p(G.id);R=Math.min(R,F.x),I=Math.min(I,F.y),$=Math.max($,F.x+L),q=Math.max(q,F.y+H),B=Math.max(B,F.x+D),P=Math.max(P,F.y+K)}const W=$-R,ne=q-I,ee=[...new Set(S.map(G=>Math.round(G.x)))].sort((G,F)=>G-F),M=ee.length?ee:[R],X=[0,...S.map(G=>G.y+G.h+b)].sort((G,F)=>G-F);let V=null;if(h){let G=1/0,F=1/0,L=-1/0,H=-1/0;for(const U of S)G=Math.min(G,U.x),F=Math.min(F,U.y),L=Math.max(L,U.x+U.cw),H=Math.max(H,U.y+U.ch);const D=(U,ae)=>{const le=c.width/(Math.max(L,U+B-R)-Math.min(G,U)+uf),ge=c.height/(Math.max(H,ae+P-I)-Math.min(F,ae));return[Math.min(JI,le,ge),Math.min(le,ge),Math.max(le,ge)]},K=(U,ae)=>{for(let le=0;le<U.length;le++){if(U[le]>ae[le]+1e-9)return!0;if(U[le]<ae[le]-1e-9)return!1}return!1},re=Math.round(L+uf+k),z=[...new Set([...X,F])].sort((U,ae)=>U-ae);let Z=null;for(const U of[...M,re])for(const ae of z){if(_(U,ae,W,ne))continue;const le=D(U,ae);(Z===null||K(le,Z))&&(Z=le,V={x:U,y:ae})}V&&V.x===R&&V.y===I&&(V=null)}else e:for(const G of M)for(const F of X){if(F>=I)break;if(!_(G,F,W,ne)){V={x:G,y:F};break e}}if(V){const G=V.x-R,F=V.y-I;for(const L of C){const H=f(L.id);t.set(L.id,{x:H.x+G,y:H.y+F})}j.push(E)}for(const G of C){const F=f(G.id),{w:L,h:H}=u(G.id);S.push({x:F.x,y:F.y,w:L,h:H,...p(G.id)})}}return j}function O9(e,t,n){const r=new Map;for(const s of e){if(t.has(s.id)||!n(s.id))continue;const l=xi(s);(r.get(l)??r.set(l,[]).get(l)).push(s)}if(r.size===0)return e;for(const s of r.values())s.sort((l,c)=>l.id.localeCompare(c.id));return e.map(s=>{var p;if(t.has(s.id)||n(s.id))return s;const l=r.get(xi(s));if(!l)return s;const c=(p=s.data)==null?void 0:p.parentId,u=l.find(h=>h.id===c)??l[0],f=n(u.id);return{...s,position:{x:s.position.x+f.x-u.position.x,y:s.position.y+f.y-u.position.y}}})}function L9(e,t,n,r,s,l=!1,c){const p=zl+Qf+1,h=8,m=1.75,y=200,v=.7,S=.01,b=P=>Pu(P,r,c),_=P=>n.get(P)??t.get(P),k=new Map;for(const P of e){if(!_(P.id))continue;const W=xi(P),ne=k.get(W);ne?ne.push(P):k.set(W,[P])}const j=[],E=new Set,C=new Set,R=s.size===0;for(const P of[...k.keys()].sort()){const W=k.get(P);let ne=1/0,ee=1/0,M=-1/0,X=-1/0,V=!1;for(const H of W){const D=_(H.id),{w:K,h:re}=b(H.id);ne=Math.min(ne,D.x),ee=Math.min(ee,D.y),M=Math.max(M,D.x+K),X=Math.max(X,D.y+re),n.has(H.id)&&(V=!0)}const G=M-ne,F=X-ee;C.add(P);const L=s.get(P);L&&(G>L.w+h||F>L.h+h)&&E.add(P),s.set(P,{w:G,h:F}),j.push({sid:P,members:W.map(H=>H.id),x:ne,y:ee,w:G,h:F,anchored:V,mass:1})}for(const P of[...s.keys()])C.has(P)||s.delete(P);if(l||R)return[];let I=!1;for(let P=0;P<j.length&&!I;P++)for(let W=P+1;W<j.length;W++){const ne=j[P],ee=j[W];if(!(ne.anchored&&ee.anchored)&&Math.abs(ne.x+ne.w/2-(ee.x+ee.w/2))<(ne.w+ee.w)/2+61&&Math.abs(ne.y+ne.h/2-(ee.y+ee.h/2))<(ne.h+ee.h)/2+p){I=!0;break}}if(E.size===0&&!I)return[];if(E.size>0)for(const P of j)E.has(P.sid)&&(P.mass=8);else for(const P of j)P.mass=Math.max(1,P.w*P.h/(vi*Lu));const $=new Map(j.map(P=>[P.sid,P.x])),q=new Map(j.map(P=>[P.sid,P.y]));for(let P=0;P<y;P++){const W=new Map,ne=new Map;let ee=0;for(let M=0;M<j.length;M++)for(let X=M+1;X<j.length;X++){const V=j[M],G=j[X];if(V.anchored&&G.anchored)continue;const F=V.x+V.w/2,L=V.y+V.h/2,H=G.x+G.w/2,D=G.y+G.h/2,K=(V.w+G.w)/2+61-Math.abs(F-H),re=(V.h+G.h)/2+p-Math.abs(L-D);if(K<=0||re<=0)continue;const z=(fe,Ce)=>!fe.anchored&&!(Ce<0&&fe.x<=0),Z=(fe,Ce)=>!fe.anchored&&!(Ce<0&&fe.y<=0),U=(fe,Ce,pe)=>{const _e=fe===Ce,Ye=_e?V.sid<G.sid?-1:1:Math.sign(fe-Ce);return pe(V,Ye)||pe(G,-Ye)?Ye:_e&&(pe(V,-Ye)||pe(G,Ye))?-Ye:0},ae=U(F,H,z),le=U(L,D,Z),ge=ae!==0,Ne=le!==0;if(!ge&&!Ne)continue;const Ie=ge&&(!Ne||K*m<re),[Ge,Pe,ze,Re]=Ie?[ae,K,W,z]:[le,re,ne,Z],st=Re(V,Ge),ue=Re(G,-Ge),ce=V.mass,se=G.mass,be=st?ue?se/(ce+se):1:0,Le=ue?st?ce/(ce+se):1:0,de=Pe*v;ze.set(V.sid,(ze.get(V.sid)??0)+Ge*de*be),ze.set(G.sid,(ze.get(G.sid)??0)-Ge*de*Le),ee+=de}for(const M of j)M.anchored||(M.x=Math.max(0,M.x+(W.get(M.sid)??0)),M.y=Math.max(0,M.y+(ne.get(M.sid)??0)));if(ee<S)break}const B=[];for(const P of j){const W=P.x-$.get(P.sid),ne=P.y-q.get(P.sid);if(!(Math.abs(W)<1&&Math.abs(ne)<1)){for(const ee of P.members){if(n.has(ee))continue;const M=t.get(ee);M&&t.set(ee,{x:M.x+W,y:M.y+ne})}B.push(P.sid)}}return B}function zh(e,t,n){return!t.has(e)||n.has(e)}function P9(e,t,n,r){return!t.has(e)&&zh(e,n,r)}function D9(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function C2(e,t,n,r){n.set(e,t),r.delete(e)}const F9=200,q9=5*6e4,B9=6,z9=2*6e4;function Eh(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function U9(e,t){let n=!1;for(const s of e)if(!t.has(s)){n=!0;break}if(!n)return e;const r=new Set;for(const s of e)t.has(s)&&r.add(s);return r}function H9(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(Tb(n.id));return t}function W9(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(Tb(n.id));return t}function V9(e,t){let n=o6(e,t,HN);i6(e,t,HN)&&(n=!0);const r=[],s=l=>{r.push(l)};return n6(e,t,F9,q9,s)&&(n=!0),r6(e,t,B9,z9,s)&&(n=!0),{changed:n,forgotten:r}}const G9=300,T2=130,K9=160,R2=new WeakMap;function Y9(e,t){let n=R2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:gF(e.agents.values())},R2.set(e,n));const{byId:r,branches:s}=n;return l=>{let c=r.get(l.id);if(!c){const u=l.kind==="root"?s.get(l.sessionId):void 0;c=u?{...l,onOpenContext:t,branch:u}:{...l,onOpenContext:t},r.set(l.id,c)}return c}}function W0(e){const t=new Map;for(const n of e.agents.values())n.tools.length>0&&t.set(n.id,Math.min(4,n.tools.length));return t}function X9(e,t,n,r,s,l,c,u,f,p,h,m,y,v,S,b,_,k){var ee,M,X,V;const j=[],E=[],C=Y9(e,k);for(const G of e.agents.values()){if(!_.has(G.id))continue;const F=G.exitAt!=null,L=b!=null&&!b.has(G.id),H=[F?"rf-exiting":"",L?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,D=l.get(G.id);if(j.push({id:G.id,type:"agent",position:{x:0,y:0},data:C(G),className:H,ariaLabel:oq(G,t,S.has(G.id)),...D?{width:D.width,height:D.height}:null}),G.parentId&&_.has(G.parentId)){const z=tf(G.sessionId),Z=F,U=S.size>0&&(S.has(G.id)||S.has(G.parentId)),ae=b!=null&&!b.has(G.id)&&!b.has(G.parentId),le=G.state==="active"?2:1.5,ge=U?le+1.5:le,Ne=Z?.2:ae?.12:1,Ie=["sess-edge",G.state==="active"?"sess-live":"sess-idle",Z?"rf-edge-exiting":"",U?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${G.parentId}->${G.id}`,source:G.parentId,target:G.id,animated:(G.state==="active"||U)&&!Z,type:"smoothstep",style:{"--session-hue":z,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:Ne,transition:"var(--edge-transition)"},className:Ie})}const K=G.kind==="root"?Cf(G):null,re=K?fM(G.sessionId,K.at):null;if(K&&re&&!uF(re)){const z=Tb(G.id),Z=tf(G.sessionId),U=l.get(z);j.push({id:z,type:"recapNote",position:{x:0,y:0},data:{sessionId:G.sessionId,parentId:G.id,recap:K,noteKey:re,hue:Z},className:L?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${G.label}`,...U?{width:U.width,height:U.height}:null}),E.push({id:`e:recap:${G.id}`,source:z,target:G.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Z}})}}const R=W0(e),I=`${y}#lanes:${C9(R)}`,$=new Set(j.filter(G=>G.type==="recapNote").map(G=>G.id));for(const G of Array.from(h.keys()))pF(G)&&!$.has(G)&&!s.has(G)&&(h.delete(G),m.delete(G));const q=j.filter(G=>P9(G.id,s,h,m));if(q.length>0||I!==v.current){if(q.length>0){const G=O9(M9(j,E,{direction:"LR",pinned:s,measured:l,availableWidth:n,availableHeight:r,lanes:R}),s,F=>zh(F,h,m)?void 0:h.get(F));for(const F of G)zh(F.id,h,m)&&C2(F.id,F.position,h,m);$9(j,h,s,l,new Set(q.filter(F=>F.type!=="recapNote").map(F=>F.id)),R,{width:n,height:r});for(const F of q){if(F.type!=="recapNote")continue;const L=(ee=F.data)==null?void 0:ee.parentId;if(!L)continue;const H=s.get(L)??(zh(L,h,m)?void 0:h.get(L));if(!H)continue;const D=((M=l.get(F.id))==null?void 0:M.width)??G9,K=((X=l.get(F.id))==null?void 0:X.height)??T2,re=((V=l.get(L))==null?void 0:V.height)??T2;C2(F.id,{x:H.x-K9-D,y:H.y+(re-K)/2},h,m)}}I9(j,h,s,l,R),v.current=I}const B=L9(j,h,s,l,c,!f||p,R);B.length>0&&u(B);const P=W9(e.agents.values());Eh(h,P),Eh(m,P),Eh(s,P),Eh(l,H9(e.agents.values()));const W=[];let ne=!1;for(const G of j){let F=s.get(G.id)??h.get(G.id);F||(F=D9(G.id,h,m),ne=!0),W.push({...G,position:F})}return ne&&(v.current=""),{nodes:W,edges:E}}const Z9=1;function Q9(e){return{id:e.id,name:e.name,inputPreview:e.inputPreview,startedAt:e.startedAt,endedAt:e.endedAt,ok:e.ok,errorPreview:e.errorPreview,usage:e.usage}}function J9(e,t,n){const r=e.agents.get(t);if(!r)return null;const s=[];for(const l of e.agents.values())l.sessionId===t&&s.push(l);return{schemaVersion:Z9,exportedAt:n,sessionId:t,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:s.map(l=>({id:l.id,kind:l.kind,label:l.label,parentId:l.parentId,state:l.state,startedAt:l.startedAt,endedAt:l.endedAt,model:l.model,cwd:l.cwd,usage:l.usage,prompts:l.prompts,tools:l.tools.map(Q9)}))}}function eV(e,t){const n=(e||"session").replace(/[^a-z0-9._-]/gi,"_");return`${hn}-${n}-${t.slice(0,8)}.json`}function tV(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function nV(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.decks!="number"||typeof t.mine!="boolean")return null;const n=t.owner&&typeof t.owner=="object"?t.owner.port:null;return{path:typeof t.path=="string"&&t.path!==""?t.path:null,decks:t.decks,mine:t.mine,ownerPort:typeof n=="number"?n:null}}function rV(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function sV(e,t){const n=rV(e),r=(...c)=>[n?`${n} on the canvas`:null,...c,"layout, pins and selection"].filter(u=>u!==null),s="This cannot be undone.";if(!t)return{goes:r("the event log on disk — the file a restarted deck replays to rebuild what you see, and the file every deck on this machine shares unless one was told otherwise"),stays:[],final:s,confirm:"Clear everything"};if(!t.path)return{goes:r(),stays:[],final:`This deck keeps no event log, so nothing on disk changes — and nothing can bring the canvas back. ${s}`,confirm:"Clear everything"};if(!t.mine){const c=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,u=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${c}${u}`,"restart this deck and the log replays back onto it"],final:null,confirm:"Clear this canvas"}}if(t.decks<=1)return{goes:r("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:s,confirm:"Clear everything"};const l=t.decks-1;return{goes:r(`the event log ${l===1?"1 other running deck shares":`${l} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[l===1?"what that deck shows, until it restarts — then it is gone there too":"what those decks show, until they restart — then it is gone there too"],final:s,confirm:"Clear everything"}}function aV({agentCount:e,onConfirm:t,onCancel:n}){const r=w.useRef(null),s=mn(n,{focusRef:r,layer:L6}),[l,c]=w.useState(null);w.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c(nV(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=sV(e,l);return o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{className:"status-dot err","aria-hidden":!0}),o.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsxs("dl",{className:"cc-plan",children:[o.jsx("dt",{children:"Goes"}),o.jsx("dd",{children:u.map(m=>o.jsx("span",{children:m},m))}),o.jsx("dt",{children:"Stays"}),o.jsx("dd",{children:f.length>0?f.map(m=>o.jsx("span",{children:m},m)):o.jsx("span",{children:"nothing"})})]}),p&&o.jsx("p",{className:"cc-final",children:p}),o.jsxs("div",{className:"cc-actions",children:[o.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),o.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const oV="Press Esc first if a key does nothing.",iV=[{title:"Canvas",rows:[{cap:"Space",action:"pause or resume the stream",binds:[" "]},{cap:"J",action:"next agent",binds:["j","J"]},{cap:"K",action:"previous agent",binds:["k","K"]},{cap:"W",action:"the session waiting on you — oldest first, again for the next",binds:["w","W"]},{cap:"F",action:"fit every agent on screen",binds:["f","F"]},{cap:"Z",action:"zoom to the selected agent and its session",binds:["z","Z"]},{cap:"Delete",action:"take the selected card off the board — Undo brings it back",binds:["Delete"]},{cap:"R",action:"re-arrange the canvas and drop the pins",binds:["r","R"]},{cap:"C",action:"clear the canvas and the event log — asks first",binds:["c","C"]}]},{title:"Panels and dialogs",rows:[{cap:"U",action:"usage panel",binds:["u","U"]},{cap:"L",action:"session list",binds:["l","L"]},{cap:"D",action:"detail panel",binds:["d","D"]},{cap:"H",action:"usage history",binds:["h","H"]},{cap:"A",action:"Claude accounts, where Claude Code is installed",binds:["a","A"]},{cap:"S",action:"this machine — cores, memory, temperature",binds:["s","S"]},{cap:"B",action:"Browser Watch",binds:["b","B"]},{cap:"V",action:"the sound menu — volume, tones, notifications",binds:["v","V"]},{cap:"?",action:"this sheet",binds:["?"]}]},{title:"Settings",rows:[{cap:"M",action:"sound on or off",binds:["m","M"]},{cap:"T",action:"light or dark theme",binds:["t","T"]}]},{title:"Focus and selection",rows:[{cap:"Tab",action:"reach the agent cards",binds:[]},{cap:"Enter",action:"select the focused card",binds:["Enter"]},{cap:"Shift + Enter",action:"add the focused card to the selection",binds:["Enter"]},{cap:"Esc",action:"close what is open, deselect, release focus",binds:["Escape"]}]},{title:"Mouse",rows:[{cap:"drag",action:"move a node, and pin it where you dropped it",binds:[]},{cap:"shift-click",action:"add an agent to the selection",binds:[]},{cap:"click",action:"a card: go to it and its session",binds:[]},{cap:"double-click",action:"a card: its prompt, every tool call, tokens and timing",binds:[]},{cap:"hover",action:"zoomed out, a card's name, state and numbers",binds:[]},{cap:"click",action:"the topbar speaker opens volume and sound settings",binds:[]}]}];function lV({onClose:e,onTour:t}){const n=mn(e);return o.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:o.jsxs("div",{ref:n,className:"modal key-help",onClick:r=>r.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[t&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Eight pictures of what the deck shows."}),o.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),o.jsx("div",{className:"shortcuts",children:iV.map(r=>o.jsxs(w.Fragment,{children:[o.jsx("h3",{className:"kh-group",children:r.title}),r.rows.map(s=>o.jsxs("div",{className:"sc",children:[o.jsx("kbd",{children:s.cap}),o.jsx("span",{children:s.action})]},`${r.title}:${s.cap}:${s.action}`))]},r.title))}),o.jsx("p",{className:"kh-foot",children:oV})]})]})})}const cV=1024*1024,A2=5,n$=.8,V0=24,uV="agent-dag.soundCustom.done",dV="agent-dag.soundCustom.needs-input",vu={done:uV,"needs-input":dV};function Du(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function M2(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function hV(e){return{done:M2(e(vu.done)),"needs-input":M2(e(vu["needs-input"]))}}function fV(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function pV(e){return e.done&&e.done===e["needs-input"]?e.done:null}const mV={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},r$=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function s$(e,t){const n=t.toLowerCase().split(";")[0].trim();if(r$.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return mV[r]??n}function I2(e,t){const n=s$(e.name,e.type);if(!r$.has(n))return"Use a WAV, MP3, OGG, or browser-recorded audio file.";if(!Number.isFinite(e.size)||e.size<=0)return"The audio file is empty.";if(e.size>cV)return"Audio must be 1 MB or smaller.";if(t!==void 0){if(!Number.isFinite(t)||t<=0)return"The audio file could not be decoded.";if(t>A2)return`Audio must be ${A2} seconds or shorter.`}return null}function G0(e){return e>=V0?`There are already ${V0} custom sounds. Delete one first.`:null}function gV(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function yV(e){let t=0;for(const n of e)for(let r=0;r<n.length;r++)t=Math.max(t,Math.abs(n[r]));return t<=1e-5?1:Math.min(16,n$/t)}function a$(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}async function wV(e,t,n=a$()){var p;const r=((p=e.name)==null?void 0:p.trim())||"Custom sound",s=I2({name:r,type:e.type,size:e.size});if(s)throw new Error(s);const l=await e.arrayBuffer();let c;try{c=await t(l.slice(0))}catch{throw new Error("The audio file could not be decoded.")}const u=I2({name:r,type:e.type,size:e.size},c.duration);if(u)throw new Error(u);const f=Array.from({length:c.numberOfChannels},(h,m)=>c.getChannelData(m));return{id:n,name:r.replace(/\.(wav|wave|mp3|ogg|oga|webm|m4a|mp4)$/i,"")||"Custom sound",kind:"audio",mime:s$(r,e.type),duration:c.duration,normalizationGain:yV(f),bytes:l}}function vV(e,t=a$()){const n=e.name.trim()||"Custom voice",r=e.text.trim();if(!r)throw new Error("Enter the words this voice should say.");const s=Number.isFinite(e.rate)?e.rate:1,l=Number.isFinite(e.pitch)?e.pitch:1;return{id:t,name:n,kind:"tts",text:r.slice(0,180),voiceURI:e.voiceURI??"",rate:Math.min(2,Math.max(.5,s)),pitch:Math.min(2,Math.max(.5,l))}}const xV="ccdeck-notification-audio",bV=2,vs="assets",Bs="summaries";function Zu(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function kV(){return new Promise((e,t)=>{const n=indexedDB.open(xV,bV);n.onupgradeneeded=r=>{const s=n.result,l=s.objectStoreNames.contains(vs)?n.transaction.objectStore(vs):s.createObjectStore(vs,{keyPath:"id"});if(s.objectStoreNames.contains(Bs))return;const c=s.createObjectStore(Bs,{keyPath:"id"});if(r.oldVersion<1)return;const u=l.openCursor();u.onsuccess=()=>{const f=u.result;f&&(c.put(Du(f.value)),f.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function Qu(e,t,n){const r=await kV();try{return await new Promise((s,l)=>{const c=r.transaction(e,t),u=n(c),f=()=>l(c.error??new Error("Local audio storage failed."));c.oncomplete=()=>s(u?u.result:void 0),c.onerror=f,c.onabort=f})}finally{r.close()}}async function NV(){const e=Zu();return e?e.list():typeof indexedDB>"u"?[]:await Qu([Bs],"readonly",t=>t.objectStore(Bs).getAll())??[]}async function SV(e){const t=Zu();return t?t.get(e):typeof indexedDB>"u"?null:await Qu([vs],"readonly",n=>n.objectStore(vs).get(e))??null}async function $2(e){const t=Zu();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Qu([vs,Bs],"readwrite",n=>{n.objectStore(vs).put(e),n.objectStore(Bs).put(Du(e))})}async function jV(e,t){const n=Zu();if(n){const r=await n.get(e);r&&await n.put({...r,name:t});return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Qu([vs,Bs],"readwrite",r=>{const s=r.objectStore(vs),l=s.get(e);l.onsuccess=()=>{const c=l.result;if(!c)return;const u={...c,name:t};s.put(u),r.objectStore(Bs).put(Du(u))}})}async function _V(e){const t=Zu();if(t){await t.remove(e);return}typeof indexedDB>"u"||await Qu([vs,Bs],"readwrite",n=>{n.objectStore(vs).delete(e),n.objectStore(Bs).delete(e)})}const Uh=["done","needs-input"],EV=[{id:"two",label:"Two notes",notes:[{at:0,hz:740,ms:90},{at:.085,hz:440,ms:150}]},{id:"arc",label:"Descent",notes:[{at:0,hz:988,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:440,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:740,ms:55},{at:.055,hz:740,ms:55},{at:.165,hz:440,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:988,ms:110},{at:0,hz:740,ms:110},{at:.1,hz:440,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:740,ms:120},{at:.11,hz:440,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:740,ms:55},{at:.06,hz:440,ms:90}]}],CV=[{id:"two",label:"Two notes",notes:[{at:0,hz:440,ms:90},{at:.085,hz:740,ms:150}]},{id:"arc",label:"Ascent",notes:[{at:0,hz:440,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:988,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:440,ms:55},{at:.055,hz:440,ms:55},{at:.165,hz:740,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:440,ms:110},{at:.1,hz:740,ms:170},{at:.1,hz:988,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:440,ms:120},{at:.11,hz:740,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:440,ms:55},{at:.06,hz:740,ms:90}]}],ck={done:EV,"needs-input":CV},wr="two";function K0(e,t){const n=ck[e];return n.find(r=>r.id===t)??n.find(r=>r.id===wr)??n[0]}function o$(e,t){return ck[e].some(r=>r.id===t)?t:wr}K0("done",wr).notes,K0("needs-input",wr).notes;const O2=.04,i$=.24,di=0,Zl=100,df=5,bi=50;function Ql(e){if(!Number.isFinite(e))return bi;const t=Math.round(e/df)*df;return Math.min(Zl,Math.max(di,t))}function l$(e){if(e==null)return bi;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Ql(Number(t)):bi}function Y0(e){const t=Ql(e),n=O2+(i$-O2)*(t/Zl);return Math.round(n*1e4)/1e4}function TV(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(Y0(e)*r*1e4)/1e4}const RV=160,AV="agent-dag.soundLevel.done",MV="agent-dag.soundLevel.needs-input",IV="agent-dag.soundFigure.done",$V="agent-dag.soundFigure.needs-input",c$={done:AV,"needs-input":MV},Hh={done:IV,"needs-input":$V},X0={done:{level:bi,figure:wr},"needs-input":{level:bi,figure:wr}};function OV(e){const t=n=>({level:l$(e(c$[n])),figure:o$(n,e(Hh[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const L2={Stop:"done",Notification:"needs-input"};function LV(e,t){var r;if(t)return null;const n=(r=e==null?void 0:e.payload)==null?void 0:r.hook_event_name;return typeof n!="string"?null:Object.hasOwn(L2,n)?L2[n]:null}function PV(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,r=!1;const s=()=>e.enabled()?r&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",l=()=>{var m;return(m=e.onState)==null?void 0:m.call(e,s())};function c(){var m;if(!(!t||r))try{n=n??new t,(m=n.resume)==null||m.call(n).then(l,()=>{}),r=!0,l()}catch{}}function u(m,y,v=y.figure){if(!n||n.state!=="running")return!1;const S=K0(m,v),b=TV(y.level,S),_=n.currentTime;for(const k of S.notes){const j=n.createOscillator(),E=n.createGain();j.type=S.type??"sine",j.frequency.value=k.hz;const C=_+k.at,R=C+k.ms/1e3;E.gain.setValueAtTime(1e-4,C),E.gain.exponentialRampToValueAtTime(b,C+.012),E.gain.exponentialRampToValueAtTime(1e-4,R),j.connect(E).connect(n.destination),j.start(C),j.stop(R+.02)}return!0}async function f(m,y){if(!e.loadCustom)return"unavailable";let v;try{v=await e.loadCustom(m)}catch{return"unavailable"}if(!v)return"missing";if(v.kind==="tts"){if(typeof window>"u"||!("speechSynthesis"in window)||typeof SpeechSynthesisUtterance>"u")return"unavailable";const b=new SpeechSynthesisUtterance(v.text),_=window.speechSynthesis.getVoices();b.voice=_.find(k=>k.voiceURI===v.voiceURI)??null,b.rate=v.rate,b.pitch=v.pitch,b.volume=Math.min(1,Y0(y.level)/i$);try{return window.speechSynthesis.cancel(),window.speechSynthesis.speak(b),"played"}catch{return"unavailable"}}if(!n||n.state!=="running")return"locked";let S;try{S=await n.decodeAudioData(v.bytes.slice(0))}catch{return"broken"}try{const b=n.createBufferSource(),_=n.createGain();b.buffer=S;const k=v.normalizationGain*(Y0(y.level)/n$);return _.gain.setValueAtTime(Math.max(1e-4,k),n.currentTime),b.connect(_).connect(n.destination),b.start(n.currentTime),"played"}catch{return"unavailable"}}function p(m,y=!1){var b,_;if(!y&&!e.enabled())return!1;const v=(((b=e.prefs)==null?void 0:b.call(e))??X0)[m]??X0[m],S=((_=e.customSelection)==null?void 0:_.call(e)[m])??null;return S&&e.loadCustom?(f(S,v).then(k=>{var j;k==="played"||k==="locked"||((k==="missing"||k==="broken")&&((j=e.onCustomFailure)==null||j.call(e,m,S)),u(m,{...v,figure:wr},wr))}),!0):!n||n.state!=="running"?!1:u(m,v)}function h(m,y=bi){return f(m,{level:Ql(y),figure:wr}),!0}return{unlock:c,play:p,previewCustom:h,state:s,get context(){return n}}}const DV="With no deck tab open, get a notification wherever a sound would have played.",FV="With the ccdeck window closed, get a notification wherever a sound would have played.";function qV(e){return e?FV:DV}const BV="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",P2="Get notified when you're away from this tab.";function zV(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:P2};case"default":return{status:null,ask:!0,ok:!1,note:P2};case"denied":return{status:"Blocked",ask:!1,ok:!1,note:"Your browser is blocking them; only its own site settings can undo that. You'll still be told once this tab is closed."};default:return{status:"Unavailable",ask:!1,ok:!1,note:"This browser cannot show them. You'll still be told once this tab is closed."}}}function pu(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const D2={done:"Turn finished","needs-input":"Claude is asking"},UV={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function HV({onClose:e,soundOn:t,onToggleSound:n,prefs:r,onLevel:s,onFigure:l,onPreview:c,openerRef:u,customAssets:f,customSelections:p,onBuiltInSelected:h,onCustomSelected:m,onImportCustom:y,onCreateVoice:v,onRenameCustom:S,onPreviewCustom:b,onDeleteCustom:_,notifyOn:k,onToggleNotify:j,notifyVetoed:E,notifyPermission:C,onAskNotify:R}){var Ce;const I=zV(C),$=pu(),q=k&&!E&&!$,[B,P]=w.useState(""),[W,ne]=w.useState("Custom voice"),[ee,M]=w.useState("Your turn"),[X,V]=w.useState(""),[G,F]=w.useState("1"),[L,H]=w.useState("1"),[D,K]=w.useState([]),[re,z]=w.useState(!1),Z=w.useRef(null),U=w.useRef(null),ae=pV(p),le=((Ce=f.find(pe=>pe.id===ae))==null?void 0:Ce.name)??"the same custom sound",ge=f.length,Ne=G0(ge),Ie=Ne!==null,Ge=Ie?{"aria-disabled":!0,"aria-describedby":"sm-custom-full"}:{},[Pe,ze]=w.useState(null),Re=w.useRef(0),st=w.useRef(new Map),ue=w.useRef(null);w.useEffect(()=>{if(!Pe)return;const pe=window.setTimeout(()=>ze(null),4e3);return()=>window.clearTimeout(pe)},[Pe]),w.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const pe=()=>{const _e=window.speechSynthesis.getVoices();K(_e),V(Ye=>{var qe;return Ye||((qe=_e[0])==null?void 0:qe.voiceURI)||""})};return pe(),window.speechSynthesis.addEventListener("voiceschanged",pe),()=>window.speechSynthesis.removeEventListener("voiceschanged",pe)},[]);const ce=async pe=>{P("");try{await pe()}catch(_e){P(_e instanceof Error?_e.message:"Custom audio could not be saved.")}},se=(pe,_e)=>{const Ye=Date.now(),qe=Au({armedFor:Pe,target:pe,armedAt:Re.current,now:Ye,gapMs:Ou});if(qe==="arm"){ze(pe),Re.current=Ye;return}if(qe==="ignore")return;ze(null);const ke=gV(f.map(Ae=>Ae.id),pe);ce(async()=>{var Ue;await _(pe);const Ae=document.activeElement;Ae!==_e&&!$0((Ae==null?void 0:Ae.tagName)??null)||(Ue=ke?st.current.get(ke):ue.current)==null||Ue.focus()})},be=()=>{var pe;U.current!==null&&clearTimeout(U.current),U.current=null,((pe=Z.current)==null?void 0:pe.state)==="recording"&&Z.current.stop()},Le=async()=>{var _e;if(Ie)return;if(P(""),!((_e=navigator.mediaDevices)!=null&&_e.getUserMedia)||typeof MediaRecorder>"u"){P("Microphone recording is unavailable in this browser.");return}let pe;try{pe=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{P("Microphone access was denied or unavailable.");return}if(Z.current){pe.getTracks().forEach(Ye=>Ye.stop());return}try{const Ye=["audio/webm;codecs=opus","audio/ogg;codecs=opus","audio/mp4"].find(Ae=>MediaRecorder.isTypeSupported(Ae)),qe=new MediaRecorder(pe,Ye?{mimeType:Ye}:void 0),ke=[];Z.current=qe,qe.ondataavailable=Ae=>{Ae.data.size&&ke.push(Ae.data)},qe.onerror=()=>P("Recording failed. Please try again."),qe.onstop=()=>{pe.getTracks().forEach(rt=>rt.stop()),U.current!==null&&clearTimeout(U.current),U.current=null;const Ae=Z.current===qe;if(Ae&&(Z.current=null),z(!1),!Ae||!ke.length)return;const Ue=qe.mimeType.split(";")[0],Fe=Ue==="audio/mp4"?"m4a":Ue==="audio/ogg"?"ogg":"webm",Ve=new File(ke,`Recorded voice.${Fe}`,{type:Ue});ce(()=>y(Ve))},qe.start(200),z(!0),U.current=setTimeout(be,4400)}catch{Z.current=null,pe.getTracks().forEach(Ye=>Ye.stop()),P("This browser cannot record a supported audio format.")}};w.useEffect(()=>()=>{U.current!==null&&clearTimeout(U.current);const pe=Z.current;Z.current=null,(pe==null?void 0:pe.state)==="recording"&&pe.stop()},[]);const de=mn(e,{popover:!0}),fe=w.useRef(e);return fe.current=e,w.useEffect(()=>{const pe=_e=>{var qe,ke;const Ye=_e.target;Ye&&((qe=de.current)!=null&&qe.contains(Ye)||(ke=u.current)!=null&&ke.contains(Ye)||fe.current())};return window.addEventListener("pointerdown",pe,!0),()=>window.removeEventListener("pointerdown",pe,!0)},[de,u]),o.jsxs("div",{ref:de,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[o.jsxs("div",{className:"sm-switches",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),o.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-labelledby":"sm-sound-label",className:"switch",onClick:n,title:"A tone when a turn finishes, and when Claude asks for something",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"sm-setting",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications while closed"}),o.jsx("button",{type:"button",role:"switch","aria-checked":k,"aria-labelledby":"sm-notify-label",className:"switch",onClick:j,title:"With no deck tab open, a notification wherever a sound would play",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsx("p",{className:"sm-note",children:E?BV:qV($)})]})]}),q&&o.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[o.jsxs("div",{className:"sm-channel-head",children:[o.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),I.ask?o.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:R,children:"Enable"}):o.jsxs("span",{className:"sm-channel-state","data-ok":I.ok||void 0,children:[I.ok&&o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),I.status]})]}),o.jsx("p",{className:"sm-note",children:I.note})]}),!t&&o.jsx("span",{id:"sm-preview-note",className:"vis-hidden",children:"Plays even when Sounds is off, so you can set a tone before turning sounds back on."}),o.jsx("div",{className:"sm-tones",children:Uh.map(pe=>{const _e=r[pe],Ye=`sm-level-${pe}`,qe=`sm-figure-${pe}`;return o.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${pe}`,children:[o.jsxs("div",{className:"sm-tone-head",children:[o.jsx("h3",{className:"sm-tone-name",id:`sm-name-${pe}`,children:D2[pe]}),o.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(pe),"aria-label":`Hear the ${D2[pe].toLowerCase()} tone`,title:t?"Play this tone now, at what it is set to":"Plays even when Sounds is off","aria-describedby":t?void 0:"sm-preview-note",children:[o.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:o.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:Ye,children:"Volume"}),o.jsx("input",{id:Ye,type:"range",min:di,max:Zl,step:df,value:_e.level,onChange:ke=>s(pe,Number(ke.target.value)),style:{"--sm-level":`${(_e.level-di)/(Zl-di)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[_e.level,"%"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:qe,children:"Tone"}),o.jsxs("select",{id:qe,className:"sm-select",value:p[pe]?`custom:${p[pe]}`:_e.figure,onChange:ke=>{const Ae=ke.target.value;Ae.startsWith("custom:")?m(pe,Ae.slice(7)):(h(pe),l(pe,Ae))},children:[ck[pe].map(ke=>o.jsx("option",{value:ke.id,children:ke.label},ke.id)),f.length>0&&o.jsx("optgroup",{label:"Custom",children:f.map(ke=>o.jsx("option",{value:`custom:${ke.id}`,children:ke.name},ke.id))})]})]}),o.jsx("p",{className:"sm-note",children:UV[pe]})]},pe)})}),ae&&o.jsxs("p",{className:"sm-note",role:"status",children:["Both tones use “",le,"”. They may be harder to tell apart."]}),o.jsxs("section",{className:"sm-custom","aria-labelledby":"sm-custom-title",children:[o.jsxs("div",{className:"sm-custom-head",children:[o.jsx("h3",{className:"sm-tone-name",id:"sm-custom-title",children:"Custom sounds"}),o.jsxs("span",{children:[ge," of ",V0,", kept on this machine"]})]}),Ie&&o.jsx("p",{className:"sm-note",id:"sm-custom-full",children:Ne}),o.jsxs("div",{className:"sm-custom-actions",children:[o.jsxs("label",{className:"sm-custom-card sm-file",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Import audio"}),o.jsx("span",{children:"WAV, MP3 or OGG"})]}),o.jsx("span",{className:"btn sm-custom-action","aria-hidden":"true",children:"Choose file"}),o.jsx("input",{ref:ue,type:"file",accept:"audio/wav,audio/x-wav,audio/mpeg,audio/mp3,audio/ogg,.wav,.mp3,.ogg",...Ge,onClick:pe=>{Ie&&pe.preventDefault()},onChange:pe=>{var Ye;const _e=(Ye=pe.target.files)==null?void 0:Ye[0];pe.currentTarget.value="",_e&&!Ie&&ce(()=>y(_e))}})]}),o.jsxs("div",{className:"sm-custom-card",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Record a clip"}),o.jsx("span",{children:re?"Recording…":"Up to 5 seconds"})]}),re?o.jsx("button",{type:"button",className:"btn sm-custom-action",onClick:be,children:"Stop & save"}):o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>void Le(),children:"Record"})]})]}),o.jsxs("details",{className:"sm-voice",children:[o.jsxs("summary",{...Ge,onClick:pe=>{const _e=pe.currentTarget.parentElement;Ie&&_e&&!_e.open&&pe.preventDefault()},children:[o.jsx("span",{children:"Spoken voice"}),o.jsx("span",{children:"Create from text"})]}),o.jsxs("div",{className:"sm-voice-fields",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Name"}),o.jsx("input",{className:"ap-manage-input",value:W,maxLength:80,onChange:pe=>ne(pe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Text"}),o.jsx("input",{className:"ap-manage-input",value:ee,maxLength:180,onChange:pe=>M(pe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Voice"}),o.jsxs("select",{className:"sm-select",value:X,onChange:pe=>V(pe.target.value),children:[o.jsx("option",{value:"",children:"System default"}),D.map(pe=>o.jsx("option",{value:pe.voiceURI,children:pe.name},pe.voiceURI))]})]}),o.jsxs("div",{className:"sm-voice-pair",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Rate"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:G,onChange:pe=>F(pe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Pitch"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:L,onChange:pe=>H(pe.target.value)})]})]}),o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>{Ie||ce(async()=>{await v({name:W,text:ee,voiceURI:X,rate:parseFloat(G),pitch:parseFloat(L)}),M("Your turn")})},children:"Add spoken voice"})]})]}),f.length>0&&o.jsx("div",{className:"sm-custom-list",children:f.map(pe=>o.jsxs("div",{className:"sm-custom-item",children:[o.jsx("input",{className:"ap-manage-input","aria-label":`Rename ${pe.name}`,defaultValue:pe.name,maxLength:80,onBlur:_e=>{if(!_e.target.value.trim()){_e.target.value=pe.name;return}ce(()=>S(pe.id,_e.target.value))},onKeyDown:_e=>{_e.key==="Enter"&&_e.currentTarget.blur()}}),o.jsx("span",{children:pe.kind==="audio"?`${pe.duration.toFixed(1)}s`:"Voice"}),o.jsx("button",{type:"button",className:"btn sm-custom-icon","aria-label":`Play ${pe.name}`,onClick:()=>b(pe.id),children:"Play"}),o.jsx("button",{type:"button",ref:_e=>{_e?st.current.set(pe.id,_e):st.current.delete(pe.id)},className:`btn sm-custom-icon${Pe===pe.id?" armed":""}`,onKeyDown:_e=>{_e.repeat&&_e.preventDefault()},onClick:_e=>se(pe.id,_e.currentTarget),"aria-label":Pe===pe.id?`Confirm deleting ${pe.name}`:`Delete ${pe.name}`,title:Pe===pe.id?"Press again to delete this sound. It cannot be brought back.":"Delete this sound",children:Pe===pe.id?"Confirm":"Delete"})]},pe.id))}),B&&o.jsx("p",{className:"sm-custom-error",role:"alert",children:B})]}),o.jsxs("p",{className:"sm-foot",children:[o.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const u$="agent-dag.character-enabled",d$="agent-dag.fm-volume",F2="agent-dag.fm-source",WV=[{value:"claude-fm",label:"🎧 Claude FM"},{group:"📻 Lofi Girl",value:"lofi-relax",label:"📚 Relax / study"},{group:"📻 Lofi Girl",value:"lofi-game",label:"🎮 Chill / game"},{group:"📻 Lofi Girl",value:"lofi-vibe",label:"🌅 Vibe / chill"},{group:"📻 Lofi Girl",value:"lofi-sleep",label:"💤 Sleep / chill"},{group:"📻 Radio Mix",value:"radio-mix",label:"📡 Live radio mix"},{group:"📻 Best of Nostalgia",value:"best-of-nostalgia",label:"📼 Best of nostalgia live"},{group:"📻 The Good Life Radio",value:"good-life-radio",label:"🌴 The Good Life Radio"},{group:"☕ Cafe Music BGM",value:"cafe-music-bgm",label:"☕ Cafe music BGM"}];function VV(e){return e==="lofi-relax"||e==="lofi-game"||e==="lofi-vibe"||e==="lofi-sleep"||e==="radio-mix"||e==="best-of-nostalgia"||e==="good-life-radio"||e==="cafe-music-bgm"?e:"claude-fm"}function GV(e){return e!=="0"}function KV(){return GV(yr(u$))}function YV(e){return l$(e)}function XV(){return YV(yr(d$))}const q2="agent-dag.fm-custom-stations",B2="agent-dag.fm-muted",Z0="custom:",ZV=/^UC[A-Za-z0-9_-]{22}$/,QV=/^[A-Za-z0-9_-]{11}$/,uk=/^[A-Za-z0-9_-]{1,80}$/,JV=/\.(mp3|aac|ogg)$/i,eG=/\.m3u8$/i,h$=2048,Fu=80;function ki(e){return`${Z0}${e}`}function Jl(e){if(!e.startsWith(Z0))return null;const t=e.slice(Z0.length);return uk.test(t)?t:null}function z2(e){return Jl(e)??e}function tG(e){return e?"This station could not be played. Check its link, pick another, or pick it again to retry.":"This station is not live right now. Pick another, or pick it again later to retry."}function dk(e){var c,u;const t=e.trim();if(t.length>h$)return null;let n;try{n=new URL(t)}catch{return null}if(n.protocol!=="https:"||n.username||n.password)return null;const r=n.toString(),s=n.hostname.toLowerCase();if(s==="youtube.com"||s==="www.youtube.com"||s==="m.youtube.com"){if(n.port)return null;const f=(c=/^\/channel\/([^/]+)(?:\/live)?\/?$/.exec(n.pathname))==null?void 0:c[1];if(f&&ZV.test(f))return{kind:"youtube-channel",url:r,channel:f};const p=(u=/^\/@([^/]+)\/live\/?$/.exec(n.pathname))==null?void 0:u[1];if(p&&/^[A-Za-z0-9._-]{1,64}$/.test(p))return{kind:"youtube-handle",url:r,handle:p};if(n.pathname==="/watch"){const h=n.searchParams.get("v")??"";if(QV.test(h))return{kind:"youtube-video",url:r,video:h}}return null}return eG.test(n.pathname)?{kind:"direct-audio",url:r,format:"hls"}:JV.test(n.pathname)?{kind:"direct-audio",url:r,format:"audio"}:null}function nG(e){return e==="1"}function rG(e){if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];const n=new Set,r=[];for(const s of t){if(!s||typeof s!="object")continue;const l=typeof s.id=="string"?s.id:"",c=typeof s.name=="string"?s.name.trim():"",u=typeof s.url=="string"?s.url.trim():"",f=dk(u);!uk.test(l)||n.has(l)||!c||c.length>Fu||!f||(n.add(l),r.push({id:l,name:c,url:f.url}))}return r}function sG(e,t,n){const r=Jl(e??"");return r&&t.some(s=>s.id===r)?ki(r):n(e)}function aG(e,t){return e===ki(t)?"claude-fm":e}function oG(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function iG(e,t,n=oG()){const r=e.trim(),s=dk(t);return!r||r.length>Fu||!uk.test(n)||!s?null:{id:n,name:r,url:s.url}}const Tl=["light","dark"],lG={light:"Light",dark:"Dark"},U2=WV,Rl="Give the station a name.",cG="Use an https YouTube live or channel link, or a .mp3, .aac, .ogg or .m3u8 stream.";function uG({theme:e}){return o.jsx("span",{className:"appearance-preview","data-swatch":e,children:o.jsxs("svg",{viewBox:"0 0 112 56","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{className:"tp-canvas",width:"112",height:"56"}),o.jsx("rect",{className:"tp-surface",width:"112",height:"7"}),o.jsx("rect",{className:"tp-rule",y:"7",width:"112",height:"1"}),o.jsx("rect",{className:"tp-surface",y:"8",width:"25",height:"48"}),o.jsx("rect",{className:"tp-rule",x:"25",y:"8",width:"1",height:"48"}),o.jsx("rect",{className:"tp-card",x:"36.5",y:"27.5",width:"28",height:"14",rx:"2.5"}),o.jsx("rect",{className:"tp-tag",x:"39.5",y:"25.5",width:"13",height:"4",rx:"2"}),o.jsx("rect",{className:"tp-card",x:"76.5",y:"14.5",width:"29",height:"20",rx:"2.5"}),o.jsx("rect",{className:"tp-rule",x:"81",y:"23",width:"20",height:"2",rx:"1"}),o.jsx("rect",{className:"tp-accent",x:"81",y:"23",width:"12",height:"2",rx:"1"})]})})}function dG({theme:e,onTheme:t,characterEnabled:n,onToggleCharacter:r,fmVolume:s,onFmVolume:l,fmMuted:c,onFmMuted:u,fmSource:f,onFmSource:p,customFmStations:h,unavailableFmStations:m,onAddFmStation:y,onRenameFmStation:v,onRemoveFmStation:S,onClose:b}){var ce;const _=mn(b),k=[...U2.map(se=>({...se,label:m.has(se.value)?`${se.label} · not live`:se.label,unavailable:m.has(se.value)})),...h.map(se=>({group:"🎵 Your stations",value:ki(se.id),label:m.has(se.id)?`${se.name} · unavailable`:se.name,unavailable:m.has(se.id)}))],j=k.some(se=>se.value===f&&se.unavailable),E=[];k.forEach((se,be)=>{const Le=E[E.length-1];Le&&Le.group===se.group?Le.indexes.push(be):E.push({group:se.group,indexes:[be]})});const[C,R]=w.useState(!1),[I,$]=w.useState(()=>Math.max(0,k.findIndex(se=>se.value===f))),[q,B]=w.useState(!1),[P,W]=w.useState(""),[ne,ee]=w.useState(""),[M,X]=w.useState(""),[V,G]=w.useState(!1),[F,L]=w.useState(""),[H,D]=w.useState(""),K=w.useRef(null),re=w.useRef(null),z=w.useRef(null),Z=w.useRef(null),U=w.useRef(null),ae=Jl(f),le=ae?h.find(se=>se.id===ae):void 0;w.useEffect(()=>{const se=k.findIndex(be=>be.value===f);$(se<0?0:se)},[f,h,m]),w.useEffect(()=>{G(!1),L((le==null?void 0:le.name)??"")},[le==null?void 0:le.id,le==null?void 0:le.name]),w.useEffect(()=>{var se;C&&((se=document.getElementById(`appearance-fm-option-${I}`))==null||se.scrollIntoView({block:"nearest"}))},[I,C]),w.useEffect(()=>{if(!C)return;const se=be=>{var de,fe;const Le=be.target;!((de=K.current)!=null&&de.contains(Le))&&!((fe=U.current)!=null&&fe.contains(Le))&&R(!1)};return document.addEventListener("pointerdown",se),()=>document.removeEventListener("pointerdown",se)},[C]);const ge=se=>{const be=se.relatedTarget;be&&!se.currentTarget.contains(be)&&R(!1)},Ne=se=>{var Le;const be=k[se];be&&($(se),p(be.value),R(!1),(Le=K.current)==null||Le.focus())},Ie=se=>{if(D6(se.key)){if(!C)return;se.preventDefault(),se.stopPropagation(),R(!1);return}if(se.key==="Tab"){R(!1);return}if(se.key==="Enter"||se.key===" "){se.preventDefault(),C?Ne(I):R(!0);return}se.key!=="ArrowDown"&&se.key!=="ArrowUp"&&se.key!=="Home"&&se.key!=="End"||(se.preventDefault(),R(!0),$(be=>se.key==="Home"?0:se.key==="End"?k.length-1:Math.min(k.length-1,Math.max(0,be+(se.key==="ArrowDown"?1:-1)))))},Ge=()=>{var se;return(se=K.current)==null?void 0:se.focus()},Pe=se=>{var Le,de;if(se.preventDefault(),!P.trim()){X(Rl),(Le=re.current)==null||Le.focus();return}const be=iG(P,ne);if(!be){X(cG),(de=z.current)==null||de.focus();return}y(be),p(ki(be.id)),W(""),ee(""),X(""),B(!1),Ge()},ze=se=>{var be;if(se.preventDefault(),!!ae){if(!F.trim()){D(Rl),(be=Z.current)==null||be.focus();return}v(ae,F),G(!1),Ge()}},Re=se=>{var de;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(se.key))return;se.preventDefault();const Le=(Tl.indexOf(e)+(se.key==="ArrowLeft"||se.key==="ArrowUp"?-1:1)+Tl.length)%Tl.length;t(Tl[Le]),(de=se.currentTarget.querySelectorAll('[role="radio"]')[Le])==null||de.focus()},st=se=>{var Le;if(se.key===" "){se.stopPropagation();return}if(Ef(se.target)||se.key!=="t"&&se.key!=="T"||se.ctrlKey||se.metaKey||se.altKey)return;se.preventDefault(),se.stopPropagation();const be=e==="dark"?"light":"dark";t(be),se.target.getAttribute("role")==="radio"&&((Le=se.currentTarget.querySelectorAll('[role="radio"]')[Tl.indexOf(be)])==null||Le.focus())},ue=se=>{const be=k[se],Le="unavailable"in be&&be.unavailable;return o.jsxs("div",{className:"appearance-source-option",role:"option",id:`appearance-fm-option-${se}`,"aria-selected":f===be.value,"data-highlighted":I===se||void 0,"data-unavailable":Le||void 0,onMouseEnter:()=>$(se),onClick:()=>Ne(se),children:[o.jsx("span",{children:be.label}),f===be.value&&o.jsx("span",{"aria-hidden":!0,children:"✓"})]},be.value)};return On.createPortal(o.jsx("div",{className:"modal-backdrop appearance-backdrop",onClick:b,role:"presentation",children:o.jsxs("div",{ref:_,id:"appearance-menu",className:"modal appearance-menu appearance-modal",role:"dialog","aria-modal":"true","aria-labelledby":"appearance-title",onClick:se=>se.stopPropagation(),onKeyDown:st,children:[o.jsxs("div",{className:"appearance-head",children:[o.jsxs("div",{className:"appearance-heading",children:[o.jsx("h2",{id:"appearance-title",className:"appearance-title",children:"Appearance"}),o.jsx("p",{className:"appearance-subtitle",children:"Tune the deck to your workspace."})]}),o.jsx("button",{type:"button",className:"glyph-btn appearance-close",onClick:b,"aria-label":"Close appearance settings",title:"Close (Esc)",children:"×"})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-theme-caption",children:[o.jsxs("div",{className:"appearance-caption",children:[o.jsxs("div",{children:[o.jsx("h3",{id:"appearance-theme-caption",children:"Color theme"}),o.jsx("p",{className:"appearance-section-note",children:"Choose how the dashboard looks."})]}),o.jsx("kbd",{className:"appearance-key","aria-hidden":!0,title:"Press T anywhere to switch themes",children:"T"})]}),o.jsx("div",{className:"appearance-themes",role:"radiogroup","aria-labelledby":"appearance-theme-caption","aria-keyshortcuts":"T",onKeyDown:Re,children:Tl.map(se=>o.jsxs("button",{type:"button",className:"appearance-theme",role:"radio","aria-checked":e===se,tabIndex:e===se?0:-1,onClick:()=>t(se),children:[o.jsx(uG,{theme:se}),o.jsxs("span",{className:"appearance-theme-name",children:[lG[se],o.jsx("svg",{className:"appearance-check",viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"M2.5 6.4 4.9 8.7 9.5 3.6"})})]})]},se))})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-fm-caption",children:[o.jsx("div",{className:"appearance-caption",children:o.jsx("h3",{id:"appearance-fm-caption",children:"Music source"})}),o.jsxs("div",{className:"appearance-controls",children:[o.jsxs("div",{className:"appearance-source-row",children:[o.jsx("label",{htmlFor:"appearance-fm-source",children:"Station"}),o.jsxs("div",{className:`appearance-source-picker${C?" is-open":""}`,onBlur:ge,children:[o.jsxs("button",{ref:K,type:"button",id:"appearance-fm-source",className:"appearance-source-trigger",role:"combobox","aria-haspopup":"listbox","aria-expanded":C,"aria-controls":C?"appearance-fm-source-list":void 0,"aria-activedescendant":C?`appearance-fm-option-${I}`:void 0,"aria-describedby":"appearance-fm-source-note",onClick:()=>R(se=>!se),onKeyDown:Ie,children:[o.jsx("span",{children:((ce=k.find(se=>se.value===f))==null?void 0:ce.label)??U2[0].label}),o.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"m2.5 4.5 3.5 3 3.5-3"})})]}),C&&o.jsx("div",{ref:U,id:"appearance-fm-source-list",className:"appearance-source-list",role:"listbox","aria-label":"Music stations",children:E.map((se,be)=>se.group?o.jsxs("div",{role:"group","aria-labelledby":`appearance-fm-group-${be}`,children:[o.jsx("div",{id:`appearance-fm-group-${be}`,className:"appearance-source-group",role:"presentation",children:se.group}),se.indexes.map(ue)]},`group-${be}`):se.indexes.map(ue))})]})]}),o.jsx("span",{id:"appearance-fm-source-note",className:"vis-hidden",children:"Changing station starts live playback automatically."}),o.jsx("p",{className:"appearance-fm-status",role:"status",children:j?tG(Jl(f)!==null):""}),o.jsxs("div",{className:"appearance-station-manage",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action","aria-expanded":q,onClick:()=>{B(se=>!se),X("")},children:q?"Cancel":"+ Add station"}),le&&!V&&o.jsxs("span",{className:"appearance-station-edit",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action",onClick:()=>{L(le.name),D(""),G(!0)},children:"Rename"}),o.jsx("button",{type:"button",className:"btn danger appearance-station-action",onClick:()=>{S(le.id),Ge()},children:"Remove"})]})]}),q&&o.jsxs("form",{className:"appearance-station-form",onSubmit:Pe,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:re,className:"ap-manage-input",value:P,onChange:se=>W(se.target.value),"aria-invalid":M===Rl||void 0,"aria-describedby":M===Rl?"appearance-station-error":void 0,maxLength:Fu,autoFocus:!0})]}),o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Link"}),o.jsx("input",{ref:z,className:"ap-manage-input",value:ne,onChange:se=>ee(se.target.value),placeholder:"https://…","aria-invalid":M!==""&&M!==Rl||void 0,"aria-describedby":M&&M!==Rl?"appearance-station-error":void 0,inputMode:"url",autoComplete:"off",spellCheck:!1,maxLength:h$})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Add"}),M&&o.jsx("p",{id:"appearance-station-error",className:"appearance-station-error",role:"alert",children:M})]}),le&&V&&o.jsxs("form",{className:"appearance-station-form is-rename",onSubmit:ze,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:Z,className:"ap-manage-input",value:F,onChange:se=>L(se.target.value),"aria-invalid":H!==""||void 0,"aria-describedby":H?"appearance-rename-error":void 0,maxLength:Fu,autoFocus:!0})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Save"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{G(!1),Ge()},children:"Cancel"}),H&&o.jsx("p",{id:"appearance-rename-error",className:"appearance-station-error",role:"alert",children:H})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-character-label",children:"Show character on minimap"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":n,"aria-labelledby":"appearance-character-label","aria-describedby":"appearance-character-note",onClick:r,children:o.jsx("span",{className:"switch-knob"})}),o.jsx("span",{id:"appearance-character-note",className:"vis-hidden",children:"Shows the animated minimap character and enables music playback."})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:"appearance-fm-volume",children:"Volume"}),o.jsx("input",{id:"appearance-fm-volume",type:"range",min:di,max:Zl,step:df,value:s,"aria-describedby":"appearance-fm-volume-note",onChange:se=>l(Number(se.target.value)),style:{"--sm-level":`${(s-di)/(Zl-di)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[s,"%"]})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-fm-mute-label",children:"Mute music"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":c,"aria-labelledby":"appearance-fm-mute-label",onClick:u,children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsx("span",{id:"appearance-fm-volume-note",className:"vis-hidden",children:"Controls live music volume."})]})]})}),document.body)}const Q0="https://www.youtube-nocookie.com";function hG(e,t,n){const r=new URLSearchParams({...n?{}:{channel:e},enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Q0}/embed/${n?encodeURIComponent(n):"live_stream"}?${r.toString()}`}function Al(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function fG(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const pG=[1,3],mG=[0,2],gG=[2,5,100,101,150];function yG(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{event:n,info:r}=t;if(n==="onReady")return{kind:"ready"};if(n==="onError"){const s=typeof r=="number"?r:Number(r==null?void 0:r.errorCode);return Number.isFinite(s)?{kind:"error",code:s}:null}if(n==="onStateChange"||n==="infoDelivery"){const s=typeof r=="number"?r:r==null?void 0:r.playerState;return typeof s!="number"||!Number.isFinite(s)?null:pG.includes(s)?{kind:"playing",playing:!0}:mG.includes(s)?{kind:"playing",playing:!1}:null}return null}const f$=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],H2=18,wG=f$.length,p$=new Set(["a","c","p"]);function Jf(e=f$){const t=[];return e.forEach((n,r)=>{let s=0;for(;s<n.length;){const l=n[s];if(l==="."){s+=1;continue}let c=1;for(;s+c<n.length&&n[s+c]===l;)c+=1;t.push({x:s,y:r,w:c,cell:l}),s+=c}}),t}const hi=148,W2=6e3,vG=16e3,m$=46,ro=34;function xG(e,t,n=hi){let r=-Math.round(t()*n);if(Math.abs(r-e)<ro){const s=e-ro>=-n?-ro:ro;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return{to:r,ms:Math.round(Math.abs(r-e)*m$)}}function bG(e){return Math.round(W2+e()*(vG-W2))}const V2=[{kind:"stroll",weight:44},{kind:"tidy",weight:17},{kind:"kick",weight:17},{kind:"sit",weight:12},{kind:"watch",weight:16},{kind:"leave",weight:7},{kind:"fish",weight:12},{kind:"skip",weight:10}];function kG(e){const t=V2.reduce((r,s)=>r+s.weight,0);let n=e()*t;for(const r of V2)if(n-=r.weight,n<0)return r.kind;return"stroll"}const NG=720,SG=260,jG=620,_G=220,G2=520,g$=1600,K2=7e3,EG=15e3,Y2=6e3,CG=14e3;function Ml(e,t,n=hi){let r=-Math.round(t()*n);if(Math.abs(r-e)<ro){const s=e-ro>=-n?-ro:ro;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return r}const fn=(e,t)=>Math.round(Math.abs(t-e)*m$),TG=120,Ch=0;function RG(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:fn(e,t)},{x:t,prop:n({}),act:"stoop",ms:NG},{x:Ch,prop:n({held:!0}),act:"carry",ms:fn(t,Ch)},{x:Ch,prop:n({held:!0}),act:"windup",ms:SG},{x:Ch,prop:n({held:!0,leaving:!0}),act:"toss",ms:jG}]}function AG(e,t){const n=t>e?1:-1,r=t-n*Math.min(15,Math.abs(t-e)),s=(l={})=>({kind:"ball",at:t,...l});return[{x:r,prop:s(),act:"walk",ms:fn(e,r)},{x:r,prop:s(),act:"windup",ms:_G,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"kick",ms:G2,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"stand",ms:g$-G2}]}const y$=640;function MG(e,t,n){const r=Math.max(-70,Math.min(-20,t)),s={x:r,prop:null,facing:"left"};return[{x:r,prop:null,act:"walk",ms:fn(e,r)},{...s,act:"sit",ms:600},{...s,act:"cast",ms:900},{...s,act:"fish",ms:6e3+Math.round(n()*4e3)},{...s,act:"reel",ms:1200},{...s,act:"stow",ms:500},{...s,act:"stand",ms:400},{x:0,prop:null,act:"walk",ms:fn(r,0)}]}function IG(e,t,n){const r=Math.max(-110,Math.min(-30,t)),s={x:r,prop:null};return[{...s,act:"walk",ms:fn(e,r)},{...s,act:"skip-ready",ms:500},{...s,act:"skip",ms:y$*(6+Math.floor(n()*5))},{...s,act:"skip-rest",ms:600},{...s,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:fn(r,0)}]}function $G(e,t,n){return[{x:t,prop:null,act:"walk",ms:fn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(Y2+n()*(CG-Y2))},{x:t,prop:null,act:"stand",ms:400}]}function OG(e,t,n){t=Math.max(-110,Math.min(0,t));const r=()=>({kind:"scope",at:t,held:!0});return[{x:t,prop:null,act:"walk",ms:fn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(K2+n()*(EG-K2))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function Qx(e,t,n){return e.facing?e.facing:e.act==="watch"||e.act==="scope-pack"?"left":e.x===t?n:e.x>t?"right":"left"}const LG=1500,PG=e=>Math.round(1e3*Math.sqrt(2*e/LG)),DG=115,FG=e=>Math.round(e/DG*1e3),qG=620,BG=200,zG=760,UG=600,HG=240;function WG(e,t,n){const s=-(t.ledgeSpan??hi),l=PG(t.ledgeH),c=FG(t.ledgeH),u=n(),f=n(),p=-Math.round(u*t.floorSpan),h=-Math.round(f*t.floorSpan);return[{x:s,act:"walk",prop:null,ms:fn(e,s)},{x:s,act:"peer",prop:null,ms:qG},{x:s,act:"fall",prop:null,ms:l,place:"floor"},{x:s,act:"land",prop:null,ms:BG,place:"floor"},{x:p,act:"walk",prop:null,ms:fn(s,p),place:"floor",floorFrac:u},{x:h,act:"walk",prop:null,ms:fn(p,h),place:"floor",floorFrac:f},{x:s,act:"walk",prop:null,ms:fn(h,s),place:"floor"},{x:s,act:"lasso",prop:null,ms:zG,place:"floor"},{x:s,act:"rope-throw",prop:null,ms:UG,place:"floor"},{x:s,act:"rope-catch",prop:null,ms:HG,place:"floor"},{x:s,act:"climb",prop:null,ms:c},{x:s,act:"pull-up",prop:null,ms:480}]}function VG(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??hi;switch(kG(t)){case"tidy":return RG(e,Ml(e,t,r));case"kick":return AG(e,Ml(e,t,r));case"sit":return $G(e,Ml(e,t,r),t);case"watch":return OG(e,Ml(e,t,r),t);case"fish":return MG(e,Ml(e,t,r),t);case"skip":return IG(e,Ml(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return WG(e,n,t)}}const l=xG(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const GG=[".xx.","xxxx",".xx."],KG=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],YG=["...xx...............","..xaax..............",".xaallx.............","xaallllx............",".xllllllx...........","..xllllllx..........","...xllllllx.........","....xllllllxx.......",".....xllllxsxx..xx..","......xllxsssx.xllxx",".......xxssssxxxllxx","........xssssssxx...",".........xssssx.....","..........xxxx......","..........xax.......",".........xxxxx......","........xx.x.xx.....","........xl.x.lx.....",".......xl..x..lx....",".......xl..x..lx....","......xl...x...lx...","......xl...x...lx...",".....xl....x....lx..","....xxx...xxx...xxx."],Jx={litter:GG,ball:KG,scope:YG},w$=["bob","sway","groove"],X2=9e3,XG=16e3,v$=1e3,ZG=.08;function QG(e,t){const n=w$.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],s=(t()*2-1)*ZG;return{dance:r,beatMs:Math.round(v$*(1+s))}}function JG(e){return Math.round(X2+e()*(XG-X2))}const eK=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],tK=3,nK=-1,J0=11,Z2=9,rK=420;function sK(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(rK,Math.max(0,r))}const aK=260,oK=200;function iK(e,t,n){const r=(h,m=fn(e,h))=>({x:h,prop:null,act:"walk",ms:m,place:"floor"});if(!n||n.height<=0)return[r(t)];const s=Math.min(e,t);if(Math.max(e,t)<=n.left||s>=n.right)return[r(t)];const c=t>e,u=c?n.left:n.right,f=c?n.right:n.left,p={place:"floor",riser:n.height,prop:null};return[r(u,fn(e,u)),{...p,x:u,act:"mount",ms:aK},{...p,x:f,act:"walk",ms:fn(u,f)},{x:f,prop:null,act:"dismount",ms:oK,place:"floor"},{x:t,prop:null,act:"walk",ms:fn(f,t),place:"floor"}]}function Q2(e){let t=null,n=null,r=0,s=0,l=!1;const c=()=>{t!==null&&clearTimeout(t),t=null},u=()=>{l||e.hidden||!n||t!==null||(s=performance.now(),t=setTimeout(()=>{t=null;const p=n;n=null,p==null||p()},r))},f=()=>{e.hidden&&t!==null?(r=Math.max(0,r-(performance.now()-s)),c()):e.hidden||u()};return e.addEventListener("visibilitychange",f),{schedule(p,h){l||(c(),n=p,r=Math.max(0,h),u())},dispose(){l=!0,c(),n=null,e.removeEventListener("visibilitychange",f)}}}const lK={"claude-fm":"Claude FM","lofi-relax":"Lofi Girl relax/study","lofi-game":"Lofi Girl chill/game","lofi-vibe":"Lofi Girl vibe/chill","lofi-sleep":"Lofi Girl sleep/chill","radio-mix":"Radio Mix Live","best-of-nostalgia":"Best of Nostalgia Live","good-life-radio":"The Good Life Radio Live","cafe-music-bgm":"Cafe Music BGM Live"};function cK(e,t){return t&&ki(t.id)===e?t.name:Jl(e)?"Custom FM":lK[e]}const uK={"claude-fm":null,"lofi-relax":null,"lofi-game":null,"lofi-vibe":null,"lofi-sleep":null,"radio-mix":"/api/live-radio-mix","best-of-nostalgia":"/api/best-of-nostalgia","good-life-radio":"/api/good-life-radio","cafe-music-bgm":"/api/cafe-music-bgm"};function e0(e,t){var r;const n=((r=e[0])==null?void 0:r.length)??0;return o.jsx("svg",{viewBox:`0 0 ${n} ${e.length}`,shapeRendering:"crispEdges","aria-hidden":!0,children:Jf(e).map(s=>o.jsx("rect",{x:s.x,y:s.y,width:s.w,height:1,fill:s.cell==="s"?"var(--fm-prop-shadow, var(--bg))":s.cell==="l"?"var(--fm-prop-light, var(--text))":s.cell==="a"?"var(--accent)":void 0},`${t}${s.y}-${s.x}`))})}const t0={e:"fm-eye",s:"fm-shade",p:"fm-pad"},hf=Jf().filter(e=>!p$.has(e.cell)),dK=Jf().filter(e=>p$.has(e.cell)),J2=hf.filter(e=>e.cell==="e"),hK=Jf(eK),fK=hf.filter(e=>e.y<J0&&e.cell!=="e").map(e=>{if(e.y!==8&&e.y!==9)return e;const t=Math.max(6,e.x);return{...e,x:t,w:Math.max(0,Math.min(12,e.x+e.w)-t)}}).filter(e=>e.w>0),pK={left:hf.filter(e=>e.y>=J0&&e.x<Z2),right:hf.filter(e=>e.y>=J0&&e.x>=Z2)},eR={litter:e0(Jx.litter,"litter"),ball:e0(Jx.ball,"ball"),scope:e0(Jx.scope,"scope")};function mK(e){try{return new URL(e).host}catch{return"the station's server"}}const gK=w.memo(function({fetchImpl:t,volume:n,muted:r=!1,source:s="claude-fm",playRequest:l=0,customStation:c,onAvailabilityChange:u}){const[f,p]=w.useState(null),[h,m]=w.useState(!1),[y,v]=w.useState(!1),[S,b]=w.useState(!1),_=w.useRef(l),k=w.useRef(null),j=w.useRef(null),[E,C]=w.useState(0),[R,I]=w.useState(0),[$,q]=w.useState(null),[B,P]=w.useState(null),[W,ne]=w.useState({x:0,drop:0}),[ee,M]=w.useState("ledge"),[X,V]=w.useState("left"),[G,F]=w.useState(0),L=w.useRef(null),[H,D]=w.useState(()=>document.hidden);w.useEffect(()=>{const ue=new Set,ce=()=>{var se;if(document.hidden){for(const be of((se=L.current)==null?void 0:se.getAnimations({subtree:!0}))??[])if(be.playState==="running"||be.pending){const Le=be.currentTime;be.pause(),Le!==null&&(be.currentTime=Le),ue.add(be)}}else{for(const be of ue)be.playState==="paused"&&be.play();ue.clear()}D(document.hidden)};return ce(),document.addEventListener("visibilitychange",ce),()=>document.removeEventListener("visibilitychange",ce)},[f,h]);const[K,re]=w.useState(null),[z,Z]=w.useState(v$),[U,ae]=w.useState(()=>{var ue;return((ue=window.matchMedia)==null?void 0:ue.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});w.useEffect(()=>{var se;const ue=(se=window.matchMedia)==null?void 0:se.call(window,"(prefers-reduced-motion: reduce)");if(!ue)return;const ce=()=>ae(ue.matches);return ce(),ue.addEventListener("change",ce),()=>ue.removeEventListener("change",ce)},[]);const le=w.useRef(null),ge=w.useCallback(()=>{var ce;(ce=j.current)==null||ce.destroy(),j.current=null;const ue=k.current;ue&&(ue.pause(),ue.removeAttribute("src"),ue.load(),k.current=null)},[]),Ne=w.useCallback(ue=>{var ce,se;(se=(ce=le.current)==null?void 0:ce.contentWindow)==null||se.postMessage(ue,Q0)},[]),Ie=w.useRef(n);Ie.current=n;const Ge=w.useRef(r);Ge.current=r;const Pe=w.useCallback((ue,ce,se)=>{ge();const be=new Audio;be.preload="none",be.volume=Ie.current/100,be.muted=Ge.current,k.current=be,v(!0),b(!0);const Le=()=>k.current===be,de=()=>{ge(),v(!1),b(!1)},fe=()=>{Le()&&(de(),m(!0),u==null||u(se,!0))},Ce=pe=>{if(Le()){if(pe instanceof DOMException&&pe.name==="NotAllowedError"){de();return}fe()}};be.addEventListener("playing",()=>{Le()&&(b(!0),u==null||u(se,!1))}),be.addEventListener("ended",()=>{Le()&&de()}),be.addEventListener("error",fe,{once:!0}),ce&&!be.canPlayType("application/vnd.apple.mpegurl")?ab(async()=>{const{default:pe}=await import("./hls-BFpXDghs.js");return{default:pe}},[]).then(({default:pe})=>{if(!Le())return;if(!pe.isSupported()){fe();return}const _e=new pe;j.current=_e,_e.on(pe.Events.ERROR,(Ye,qe)=>{qe.fatal&&fe()}),_e.on(pe.Events.MEDIA_ATTACHED,()=>_e.loadSource(ue)),_e.on(pe.Events.MANIFEST_PARSED,()=>{be.play().catch(Ce)}),_e.attachMedia(be)},fe):(be.src=ue,be.play().catch(Ce))},[u,ge]);if(w.useEffect(()=>{y&&(Ne(Al("setVolume",[n])),Ne(Al(r?"mute":"unMute")),k.current&&(k.current.volume=n/100,k.current.muted=r))},[n,r,y,Ne]),w.useEffect(()=>{let ue=!0;const ce=t??fetch,se=_.current!==l;_.current=l,p(null),m(!1),v(se),b(se),ge();const be=c&&ki(c.id)===s?dk(c.url):null;if(be)return be.kind==="direct-audio"?(p({live:!0,channel:"",audio:be.url,hls:be.format==="hls"}),u==null||u(s,!1),se&&Pe(be.url,be.format==="hls",s),()=>{ue=!1}):(ce(`/api/fm-station?url=${encodeURIComponent(be.url)}`).then(fe=>fe.ok?fe.json():null).then(fe=>{ue&&(fe!=null&&fe.channel||fe!=null&&fe.video?(p({live:!0,channel:fe.channel??"",video:fe.video??void 0}),u==null||u(s,!1)):(m(!0),u==null||u(s,!0)))}).catch(()=>{ue&&(m(!0),u==null||u(s,!0))}),()=>{ue=!1});if(Jl(s))return m(!0),u==null||u(s,!0),()=>{ue=!1};const Le=s,de=uK[Le];if(de)ce(de).then(fe=>fe.ok?fe.json():null).then(fe=>{ue&&(fe!=null&&fe.video&&p({live:!0,channel:"",video:fe.video}),u==null||u(s,!(fe!=null&&fe.video)))}).catch(()=>{ue&&(u==null||u(s,!0))});else if(Le!=="claude-fm"){const fe=Le.replace("lofi-","");ce(`/api/lofi-girl?station=${encodeURIComponent(fe)}`).then(Ce=>Ce.ok?Ce.json():null).then(Ce=>{ue&&(Ce!=null&&Ce.video&&p({live:!0,channel:"",video:Ce.video}),u==null||u(s,!(Ce!=null&&Ce.video)))}).catch(()=>{ue&&(u==null||u(s,!0))})}else ce("/api/claude-fm").then(fe=>fe.ok?fe.json():null).then(fe=>{if(!ue)return;const Ce=!!(fe!=null&&fe.live&&(fe!=null&&fe.channel));Ce&&p({live:!0,channel:fe.channel}),u==null||u(s,!Ce)}).catch(()=>{ue&&(u==null||u(s,!0))});return()=>{ue=!1}},[c==null?void 0:c.id,c==null?void 0:c.url,t,u,l,s,Pe,ge]),w.useEffect(()=>()=>ge(),[ge]),w.useEffect(()=>{if(!y)return;const ue=ce=>{var be;if(ce.origin!==Q0||ce.source!==((be=le.current)==null?void 0:be.contentWindow))return;const se=yG(ce.data);if(se){if(se.kind==="ready"){Ne(Al("setVolume",[Ie.current])),Ne(Al(r?"mute":"unMute")),Ne(Al("playVideo"));return}if(se.kind==="playing"){b(se.playing);return}gG.includes(se.code)&&(v(!1),b(!1),m(!0),u==null||u(s,!0))}};return window.addEventListener("message",ue),()=>window.removeEventListener("message",ue)},[y,r,u,Ne,s]),w.useEffect(()=>{var Ue;if(!f||h||U)return;const ue=Q2(document);let ce=0;C(Fe=>ce=Fe);let se=null,be=0,Le=0;const de=Fe=>{var yt,It;const[Ve,...rt]=Fe;if(!Ve){se=null,q(null),P(null),qe();return}q(Ve.act),P(Ve.prop),M(Ve.place??"ledge"),F(Ve.riser??0);const ut=ce,ct=_e(Ve);if(Ve.act==="kick"){const zt=(It=(yt=L.current)==null?void 0:yt.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:It.getBoundingClientRect();zt&&ne({x:sK(zt.x,Qx(Ve,ut,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-zt.y+24)})}Le=Ve.act==="walk"?Math.max(fn(ut,ct),TG):Ve.ms,Ve.act==="carry"&&(Le=fn(ut,ct)),I(Le),V(zt=>Qx({...Ve,x:ct},ut,zt)),C(ct),ce=ct,se=Ve,be=Date.now(),ue.schedule(()=>de(rt),Le)},fe=()=>{const Fe=L.current,Ve=Fe==null?void 0:Fe.querySelector(".fm-sprite"),rt=Fe==null?void 0:Fe.parentElement;if(!Fe||!Ve||!rt)return null;const ut=Fe.getBoundingClientRect(),ct=rt.getBoundingClientRect(),yt=ct.right-ut.right,It=ct.width-yt*2-Ve.offsetWidth;return It>0?It:null},Ce=()=>{const Fe=L.current,Ve=Fe==null?void 0:Fe.querySelector(".fm-walker"),rt=fe();if(!Fe||!Ve||rt==null)return;const ut=Fe.getBoundingClientRect().bottom-Ve.getBoundingClientRect().bottom;if(ut>0)return{ledgeH:ut,floorSpan:rt}},pe=()=>{const Fe=L.current,Ve=document.querySelector(".autofit-chip");if(!Fe||!Ve)return null;const rt=Fe.getBoundingClientRect(),ut=Ve.getBoundingClientRect();return ut.width<=0||ut.height<=0?null:{left:ut.left-rt.right,right:ut.right-rt.right,height:ut.height}},_e=Fe=>{const Ve=(Fe.place??"ledge")==="floor",rt=Ve?fe()??hi:hi,ut=Ve&&Fe.floorFrac!=null?-Math.round(Fe.floorFrac*rt):Fe.x;return Math.max(-rt,Math.min(0,ut))},Ye=()=>{if(!se)return;const Fe=_e(se);Fe!==ce&&(I(Math.max(0,be+Le-Date.now())),V(Ve=>Qx({...se,x:Fe},ce,Ve)),C(Fe),ce=Fe)},qe=()=>{ue.schedule(()=>{const Fe=VG(ce,Math.random,Ce()),Ve=Fe.some(ct=>ct.place==="floor")?pe():null;let rt=ce;const ut=Fe.flatMap(ct=>{const yt=rt;if(rt=ct.x,!(ct.place==="floor"&&ct.act==="walk"))return[ct];const It=iK(yt,ct.x,Ve),zt=It.length-1;return ct.floorFrac==null?It:It.map((Xt,Ft)=>Ft===zt?{...Xt,floorFrac:ct.floorFrac}:Xt)});de(ut)},bG(Math.random))},ke=(Ue=L.current)==null?void 0:Ue.parentElement,Ae=typeof ResizeObserver>"u"?null:new ResizeObserver(Ye);return ke&&Ae&&Ae.observe(ke),qe(),()=>{ue.dispose(),Ae==null||Ae.disconnect(),M("ledge"),C(Fe=>Math.max(-hi,Math.min(0,Fe))),I(0),q(null),P(null),F(0)}},[f,h,U]),w.useEffect(()=>{if(!S||U){re(null);return}const ue=Q2(document),ce=se=>{const be=QG(se,Math.random);re(be.dance),Z(be.beatMs),ue.schedule(()=>ce(be.dance),JG(Math.random))};return ce(null),()=>ue.dispose()},[S,U]),!f||h)return null;const ze=()=>{if(f.audio){if(y){ge(),v(!1),b(!1);return}Pe(f.audio,f.hls===!0,s);return}if(!y){v(!0),b(!0);return}const ue=!S;b(ue),Ne(Al(ue?"playVideo":"pauseVideo")),ue||v(!1)},Re=cK(s,c),st=f.audio?mK(f.audio):"YouTube";return o.jsxs("div",{ref:L,className:"fm","data-suspended":H?"":void 0,"data-place":ee,style:{"--fm-beat":`${z}ms`},children:[B&&!B.held&&o.jsx("div",{className:"fm-prop","data-prop":B.kind,"data-leaving":B.leaving?"":void 0,style:{"--fm-prop-x":`${B.at}px`,"--fm-roll-to":`${W.x}px`,"--fm-ball-drop":`${W.drop}px`,"--fm-ball-flight-ms":`${g$}ms`,"--fm-ball-turn":X==="right"?"1080deg":"-1080deg"},children:eR[B.kind]}),($==="lasso"||$==="rope-throw"||$==="rope-catch"||$==="climb"||$==="pull-up")&&o.jsxs("div",{className:"fm-rope","data-act":$,style:{"--fm-rope-x":`${E}px`,"--fm-rope-ms":`${R}ms`},children:[o.jsx("div",{className:"fm-rope-line"}),o.jsxs("svg",{className:"fm-rope-hook",viewBox:"0 0 9 9",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{d:"M4 8V3H3V1H1V3H0V5H2V4H3V6H5V4H6V5H8V3H7V1H5V3H4"}),o.jsx("rect",{className:"fm-rope-knot",x:"3",y:"6",width:"3",height:"2"})]})]}),o.jsxs("div",{className:"fm-walker","data-act":$??void 0,"data-place":ee,"data-facing":X,style:{"--fm-x":`${E}px`,"--fm-walk-ms":`${R}ms`,"--fm-riser":`${G}px`,"--fm-skip-beat":`${y$}ms`},children:[(B==null?void 0:B.held)&&o.jsx("div",{className:"fm-held","data-prop":B.kind,"data-toss":B.leaving?"":void 0,children:eR[B.kind]}),["cast","fish","reel","stow"].includes($)&&o.jsxs("svg",{className:"fm-fishing",viewBox:"0 0 24 32",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsxs("g",{children:[o.jsx("path",{d:"M24 11H22V9H20V7H18V5H16V3H13V2H8"}),o.jsx("rect",{className:"fm-fishing-grip",x:"21",y:"9",width:"3",height:"3"})]}),o.jsxs("g",{className:"fm-fishing-line",children:[o.jsx("path",{d:"M8 2V26"}),o.jsxs("g",{className:"fm-float",children:[o.jsx("rect",{x:"7",y:"25",width:"3",height:"2"}),o.jsx("rect",{x:"8",y:"24",width:"1",height:"1"})]})]}),o.jsx("path",{className:"fm-ripple",d:"M3 28H6M10 28H14M5 30H12"})]}),["skip-ready","skip","skip-rest"].includes($)&&o.jsxs("svg",{className:"fm-skipping-rope",viewBox:"0 0 26 26",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{className:"fm-skip-back",d:"M5 18H3V8H5V5H8V2H18V5H21V8H23V18H21"}),o.jsx("path",{className:"fm-skip-forward",d:"M5 18H3V14H5V11H8V9H18V11H21V14H23V18H21"}),o.jsx("path",{className:"fm-skip-front",d:"M5 18H3V21H5V23H8V25H18V23H21V21H23V18H21"}),o.jsx("path",{className:"fm-skip-return",d:"M5 18H3V19H8V20H18V19H23V18H21"}),o.jsx("path",{className:"fm-skip-handles",d:"M5 17V19M21 17V19"})]}),o.jsx("button",{type:"button",className:"fm-sprite","data-playing":S?"":void 0,"data-dance":S?K??w$[0]:void 0,onClick:ze,title:S?`Stop ${Re}`:`Play ${Re} — streams from ${st}`,"aria-label":S?`Stop ${Re}`:`Play ${Re}`,children:o.jsxs("svg",{viewBox:`0 0 ${H2} ${wG}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("g",{className:"fm-gear",children:o.jsx("g",{className:"fm-gear-motion",children:dK.map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:t0[ue.cell]},`g${ue.y}-${ue.x}`))})}),o.jsxs("g",{className:"fm-body",children:[J2.map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,fill:"var(--accent)"},`eye-bed-${ue.x}`)),fK.map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:t0[ue.cell]},`b${ue.y}-${ue.x}`)),o.jsxs("g",{className:"fm-arms",children:[o.jsx("rect",{x:4,y:8,width:2,height:2}),o.jsx("rect",{x:12,y:8,width:1,height:2}),o.jsx("rect",{x:13,y:8,width:1,height:2,className:"fm-shade"})]}),J2.map(ue=>o.jsx("rect",{x:ue.x-(ue.x>=H2/2?1:0)+(X==="right"?1:0),y:ue.y,width:ue.w,height:1,className:"fm-eye"},`eye-${ue.x}`))]}),o.jsx("g",{className:"fm-hat",children:hK.map(ue=>o.jsx("rect",{x:tK+ue.x,y:nK+ue.y,width:ue.w,height:1,className:ue.cell==="k"?"fm-hatband":void 0},`h${ue.y}-${ue.x}`))}),($==="climb"||$==="rope-throw"||$==="rope-catch"||$==="pull-up")&&o.jsxs("g",{className:"fm-grip",children:[o.jsx("path",{className:"fm-grip-left",d:"M5 9H4V4H7V3H9V5H6V9Z"}),o.jsx("path",{className:"fm-grip-right",d:"M12 9H14V6H11V5H9V7H12Z"})]}),($==="land"||$==="dismount")&&o.jsxs("g",{className:"fm-crouch-legs",children:[o.jsx("path",{d:"M6 11H8V13H6Z"}),o.jsx("path",{d:"M10 11H12V13H10Z"})]}),["sit","cast","fish","reel","stow"].includes($)&&o.jsxs("g",{className:"fm-seated-legs",children:[o.jsx("path",{className:"fm-seated-far",d:"M10 10H12V11H11V14H8V13H9V11H10Z"}),o.jsx("path",{d:"M6 10H9V11H7V15H4V14H5V11H6Z"})]}),["left","right"].map(ue=>o.jsx("g",{className:"fm-leg","data-side":ue,children:pK[ue].map(ce=>o.jsx("rect",{x:ce.x,y:ce.y,width:ce.w,height:1,className:t0[ce.cell]},`${ue}${ce.y}-${ce.x}`))},ue))]})})]}),y&&!f.audio&&(f.channel||f.video)&&o.jsx("iframe",{ref:le,className:"fm-frame",title:Re,src:hG(f.channel,window.location.origin,f.video),onLoad:()=>Ne(fG()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),yK=15e3;function wK(e){return e.visibilityState==="visible"&&e.hasFocus()}function vK(e,t){return t||e===!0}function xK(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}const bK={"//":["What a user would NOTICE. One key per version that has something to say,","and no key at all for a version that has nothing — which is most of them.","","The rule this file exists to serve: before every release, ask 'what would a","user notice?' and write the answer here. 'Nothing user-visible' is a valid","and expected answer, and it is spelled by adding no key. A release with no","key shows no modal, and that silence is what keeps the modal worth reading","on the day it is not silent.","","What belongs here: something that changed on the user's machine or under","their hands — a hook written to or removed from settings.json, a default","that flipped, a control that moved or went away, a stored preference that","changed meaning. What does not: bounds, races, assertions that could not","fire, anything that is invisible when it is correct.","","Write it for the person running the deck, not for the person reading the","diff. `title` is the sentence they scan; `body` is what they need in order","to act on it, or to stop worrying about it.","","Keys are versions exactly as package.json spells them. A key that is not a","version, or an entry missing either field, fails the suite rather than","being quietly dropped — see src/web/__tests__/release-notes-file.test.ts.","Ordering here is for humans; the deck sorts by version itself.","","A title may open with an emoji, and if it does, put exactly ONE space after","it. Not two: the dialog gives a leading emoji its own optical gap, because","a colour glyph is drawn edge to edge inside its advance and one word space","after one reads as none. A second space here would be a lie in the data","about a defect in the type, and the suite refuses both it and no space at","all.","","A release that genuinely has nothing to say is spelled TWICE: no key here,",'and its version written into "//nothing-to-say" below. One spelling on its',"own is ambiguous — a missing key reads the same whether it was a decision","or a forgotten step, and five releases in a row were once forgotten. The list","is what tells the two apart, and release-notes-current-version.test.ts fails","the release whose version is in neither place. Any key opening with // is a","note to the author and never a release."],"//nothing-to-say":["3.23.1","3.23.2","3.23.3","3.23.4","3.26.0","3.26.1","3.26.3","3.26.4","3.26.5","3.27.6","3.27.7","3.28.0","3.28.1","3.29.3","3.29.4","3.29.6","3.29.7","3.29.9"],"3.29.10":[{title:"💲 Claude Opus 5.5 has a price",body:`Sessions on Claude Opus 5.5 showed "not priced" on the board, and the Projects report counted them as costing nothing, so its totals read far too low. They are now priced at Anthropic's published rate. If a model still has no price, Projects shows its total as a minimum, like $11.19+, and names the model, instead of a total that looks complete.`}],"3.29.8":[{title:"🔁 Removed cards come back when their agent works again",body:"Remove from board is for finished work. If the agent behind a card you removed starts a tool call, gets a new prompt or starts a subagent, the card returns on its own, together with the card it hangs from, and it stays back after a reload. Cards whose agents stay idle stay removed."}],"3.29.1":[{title:"🗂️ One row per project in Projects",body:"The Projects report now counts a session's work under the folder you started it in, the same name its card has on the canvas, instead of adding a row for every folder the agent moved into. The first start after updating re-reads your transcripts once to regroup the report."},{title:"🔔 Tidier custom sounds",body:"Importing a sound, recording one and choosing a spoken voice now sit in compact cards that respond to clicks and focus like the rest of the deck."}],"3.29.0":[{title:"🎵 Your own stations in Claude FM",body:"Add any YouTube live link or radio stream as a station in Appearance, next to the built-in ones, and mute the music without losing your volume. When a station is not live, the picker now says so instead of staying silent."},{title:"🔔 Notification sounds and voices of your own",body:"Pick a local audio file or a spoken voice for each alert, so the sound that means an agent is waiting is one you will recognise."},{title:"🗑️ Drag a card off the board to remove it",body:"Drag a card to the target at the bottom of the canvas to take it off the board, or use Remove from board in the detail panel (Delete). The session keeps running, and the session list (L) brings it back."},{title:"🔐 Optional invite-only pairing",body:"Pairing works as before, with or without an invite. If you want, Local network can now be set to accept only decks that join with an invite you created, so a nearby machine cannot ask to pair on its own."},{title:"🌐 Account sharing between your machines is more reliable",body:"A locked macOS Keychain is explained instead of failing silently, a login that is broken or belongs to another account is never shared, and a sync that stops partway keeps what already arrived."},{title:"📅 Projects opens on Today",body:"The Projects report per account starts with today's work, and an empty window offers the next wider one. The topbar also shows this month's usage, and the desktop app can restart into an update from its own window."}],"3.27.0":[{title:"📊 Projects: where each account spent its work",body:"Each account card's ⋯ menu now breaks its cost down by project, over 7d / 30d / all."}],"3.27.1":[{title:"🎨 Make Appearance easier to tune",body:"The Appearance dialog now has clearer sections, stronger selection states, and a calmer layout for choosing a theme and configuring music. Your existing settings and keyboard shortcuts continue to work."}],"3.27.2":[{title:"💰 Project costs now match Usage",body:"Project cost totals no longer count the same Claude request once for every content block. Existing project history is rebuilt automatically so the totals align with the Usage panel."}],"3.27.3":[{title:"🎵 Station selection works in the desktop app",body:"The music station picker now opens inside ccdeck instead of relying on the operating system popup, so choosing a station works reliably in the Electron app."}],"3.27.4":[{title:"✅ Desktop picker release checks are green",body:"The station picker now keeps the same keyboard, motion, focus, and layout behavior as the rest of ccdeck across desktop and browser builds."}],"3.27.5":[{title:"🧭 The welcome tour stays dismissed",body:"Electron now remembers that you completed the onboarding tour at the deck level, so an update or loopback port change no longer shows the same tour again."},{title:"🎵 The station picker has a clearer finish",body:"The music selector has a tighter trigger, a purposeful chevron, and more deliberate option spacing so it reads like a native part of Appearance."}],"3.25.0":[{title:"🖱️ A click goes to the session, a double-click opens the details",body:"Clicking a card frames it with the rest of its session and leaves the detail panel shut. Double-click a card to open its details; `j`/`k`, the session list, Enter and `D` still open them too."},{title:"🔭 Cards stay readable when you zoom out",body:"At every zoom a card shows its name, its state and anything waiting on you, instead of shrinking to a coloured pill. Hover or focus a card to see it whole. Recap notes read at a distance too, and show the full recap on hover."},{title:"🌐 The Machine panel shows your network",body:"A new Network section shows download, upload and the round trip to Claude's API, and names the route when traffic goes through a VPN or a Tailscale exit node. Those checks run only while the panel is open. The panel is regrouped into CPU, Memory, Network and Thermal, with a flag at the top when something needs attention."},{title:"🎨 See each theme before you pick it",body:"The Appearance menu shows a small preview of the deck in Light and in Dark. Claude FM also keeps its volume when a notification chime plays, instead of dipping under it."}],"3.24.1":[{title:"🎛️ Appearance is one small menu now",body:"The topbar's appearance control opens a compact menu where you can choose Light or Dark and show or hide the character. The character stays on by default, and your choice is remembered."}],"3.24.0":[{title:"🎧 Claude FM plays from the minimap",body:"A small character stands on the minimap's top edge. Press it and the Claude channel's live stream plays; press it again and it stops. It only turns up when the channel is actually broadcasting, so a deck with no network never shows it at all."},{title:"🤠 And it gets on with its day",body:"It walks that edge, tidies up what it finds, kicks a ball along it, sits with its legs over the side, and watches the board through a scope. Now and then it drops onto the canvas and ropes its way back up. Headphones on while the music plays, a hat when it does not."}],"3.23.5":[{title:"🧭 The accounts panel opens on the account you are on",body:"Its windows, its resets and how old the numbers are — whole, at the top of the column. Every other account stands behind one row that says how many of them a switch could actually reach; press it to see them, or rest on it to be shown their names and how much room each has left."},{title:"⚙️ Auto-switch moved in there with them",body:"It is behind that same row now, after the accounts it switches between, rather than at the foot of the panel. The row says `auto 90%` or `auto off` so you can tell what the policy is doing without opening it — and says so in amber when it is armed with nowhere left to go."}],"3.23.0":[{title:"🧭 The accounts column leads with accounts",body:`The live account is the open row: its windows as bars, when each one resets, and how old the numbers are. Every other account rests on the two figures a switch is decided by, and opens with a click when you want the rest.
92
+ `)})}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void c(),title:u?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}async function Am(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const Dz={not_an_invite:"That is not an invite — paste the whole line they sent you.",expired:"That invite has run out. Ask them for a fresh one.",not_running:"This deck is not on the network yet. Turn Local network on, then try again."},Fz={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function VS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||dn(n,t)}function qz({status:e,manual:t,startWith:n,onClose:r,onChanged:s}){const l=w.useRef(null),c=w.useRef(null),u=w.useRef(null),f=e.pairingMode==="invite",p=mn(r,{focusRef:f?c:l}),[h,m]=w.useState(""),[y,v]=w.useState(""),[S,b]=w.useState(null),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(null),[I,$]=w.useState(()=>Date.now());w.useEffect(()=>{const re=window.setInterval(()=>$(Date.now()),1e3);return()=>window.clearInterval(re)},[]);const q=w.useRef(!0);w.useEffect(()=>()=>{q.current=!1},[]);const B=w.useRef(null),P=w.useCallback(re=>Mf(B.current)?(B.current=re,E(re),!0):!1,[]),W=w.useCallback(()=>{B.current=null,q.current&&E(null)},[]),ne=re=>{const z=lo(j,re);return{disabled:z.disabled,"aria-busy":z.busy}},ee=re=>(S==null?void 0:S.field)===re?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},M=re=>b(z=>z&&z.field===re?null:z),X=w.useCallback(async()=>{if(f)return;const re=tU(h);if(!re){b({text:Bz(h),field:"addr"});return}const z=`${re.addr}:${re.port}`,Z=e.peers.find(U=>U.addr===re.addr&&U.port===re.port&&U.paired);if(Z){b({text:`Already paired with ${Z.name} at that address.`,field:"addr"});return}if(t.includes(z)){b({text:"This deck already calls that address.",field:"addr"});return}if(P("add"))try{const U=await Am("/api/prefs",{lan:{manual:[...t,z]}});if(!q.current)return;U!=null&&U.ok?(b(null),m(""),s(),r()):b({text:dn("add that address",U),field:"addr"})}catch{q.current&&b({text:dn("add that address",null),field:"addr"})}finally{W()}},[h,f,t,e.peers,s,r,P,W]),V=w.useCallback(async re=>{if(!P(`invite:${re}`))return;const z=re==="make"?"make an invite":"cancel that invite";try{const Z=await Am("/api/lan/invite",{action:re});if(!q.current)return;Z!=null&&Z.ok?(b(null),k(null),s()):b({text:VS(Fz,Z,z)})}catch{q.current&&b({text:dn(z,null)})}finally{W()}},[s,P,W]),G=w.useCallback(async()=>{const re=y.trim();if(!(!re||!P("join"))){R(null);try{const z=await Am("/api/lan/invite",{action:"join",token:re});if(!q.current)return;z!=null&&z.ok?(v(""),b(null),s(),r()):(z==null?void 0:z.reason)==="unreachable"&&Array.isArray(z.tried)&&z.tried.length?(R(z.tried),b(null)):(R(null),b({text:VS(Dz,z,"use that invite"),field:"join"}))}catch{q.current&&b({text:dn("use that invite",null),field:"join"})}finally{W()}}},[y,s,r,P,W]),F=w.useCallback(async(re,z)=>{try{await navigator.clipboard.writeText(re),k(z),window.setTimeout(()=>{q.current&&k(Z=>Z===z?null:Z)},1600)}catch{b({text:"Could not copy it — select the text and copy it by hand."})}},[]),L=e.invite&&e.invite.expiresAt>I?e.invite:null,H=w.useRef(!1);w.useEffect(()=>{n!=="invite"||H.current||L||(H.current=!0,V("make"))},[n,L,V]);const D=w.useRef(!1);w.useEffect(()=>{var re;n!=="invite"||D.current||!L||(D.current=!0,(re=u.current)==null||re.focus())},[n,L]);const K=e.port!=null?(e.addrs??[]).map(re=>`${re}:${e.port}`):[];return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:r,role:"presentation",children:o.jsxs("div",{ref:p,className:"modal lan-add",onClick:re=>re.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:r,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[S&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:S.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>b(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsx(GM,{reach:e.reach,where:"dialog"}),f&&o.jsx("div",{className:"modal-section",children:o.jsx("p",{className:"lan-note",children:"Adding by address is off while this deck pairs only by invite."})}),!f&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"By address"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:l,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:h,placeholder:"192.168.1.5:54340",spellCheck:!1,...ee("addr"),onChange:re=>{m(re.target.value),M("addr")},onKeyDown:re=>{re.key==="Enter"&&X()}}),h.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("add"),onClick:()=>void X(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),o.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&K.length>0&&o.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",K.map((re,z)=>o.jsxs("span",{children:[z>0&&" or ",o.jsx("code",{className:"ap-lan-code",children:re})]},re)),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...ne("copy:mine"),onClick:()=>void F(K.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:_==="mine"?"copied":"copy"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:["With an invite",!L&&o.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...ne("invite:make"),onClick:()=>void V("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:j==="invite:make"?"making…":"make one to send"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("input",{ref:c,className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:y,placeholder:"paste one you were sent",spellCheck:!1,...ee("join"),onChange:re=>{v(re.target.value),R(null),M("join")},onKeyDown:re=>{re.key==="Enter"&&G()}}),y.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("join"),onClick:()=>void G(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:j==="join"?"joining…":"join"})]}),o.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),C&&o.jsxs("div",{className:"ap-lan-tried",children:[o.jsx("span",{className:"lan-note",children:"Nothing answered at any address in that invite. Check that deck is running with its Local network switch on."}),C.map(re=>o.jsxs("span",{className:"ap-lan-tried-row",children:[o.jsx("code",{className:"ap-lan-code",children:re.addr}),o.jsx("span",{className:"ap-lan-bad",children:re.why})]},re.addr))]}),L&&o.jsxs("div",{className:"ap-lan-invite",children:[o.jsxs("div",{className:"ap-lan-invite-head",children:[o.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),o.jsxs("span",{className:"ap-lan-invite-left",id:"lan-invite-left",children:[lU(L.expiresAt,I)," left"]})]}),o.jsx("code",{className:"ap-lan-token",children:L.token}),o.jsxs("div",{className:"ap-lan-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:u,...ne("copy:invite"),"aria-label":_==="invite"?"Invite copied":"Copy invite","aria-describedby":"lan-invite-left",onClick:()=>void F(L.token,"invite"),title:"Copy it, and send it however you already talk to them",children:_==="invite"?"copied":"copy"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("invite:withdraw"),onClick:()=>void V("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),o.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function Bz(e){const t=(e??"").trim();if(t==="")return"Type an address and a port, like 192.168.1.5:54340.";if(!t.startsWith("[")&&(t.match(/:/g)??[]).length>1)return"Too many colons to split. Use that deck's IPv4 address or its name, like 192.168.1.5:54340.";if(!t.includes(":"))return`Add the port too, like ${t}:54340.`;const n=t.slice(t.lastIndexOf(":")+1).trim();return n===""?"That is missing its port — try 192.168.1.5:54340.":/^\d+$/.test(n)?`A port runs from 1 to 65535, and this one is ${n}.`:`A port is a number, and this one is "${n}".`}const zz=1e3;function Uz(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=qs(e,t);return`${n} · ${r==="now"?"just now":r}`}function GS(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function Hz(){return o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),o.jsx("path",{d:"M8.4 3.6l2 2"})]})}function KS(){return o.jsxs("svg",{className:"lan-machine",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),o.jsx("path",{d:"M1 13h14"})]})}function Sh({dir:e,gate:t=!1}){const n=t?12:8;return o.jsx("svg",{className:"lan-chev","data-dir":e,"data-gate":t||void 0,width:n,height:"8",viewBox:`0 0 ${n} 8`,fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":t?"M1 1v6M9.6 1L6.4 4l3.2 3":"M5.2 1L2 4l3.2 3"})})}const Wz={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},Vz={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function Gz(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Wz[e.here]}, ${Vz[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Kz({row:e,source:t,status:n,accounts:r,now:s,busy:l,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,onInvite:m,twins:y=[],onUnpair:v}){var It,zt,Xt,Ft,rn;const S=w.useRef(null),b=mn(c,{focusRef:S}),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(!1),I=w.useRef(0),[$,q]=w.useState(null),[B,P]=w.useState(!1),[W,ne]=w.useState(0),ee=w.useRef(null),M=w.useRef(!0);w.useEffect(()=>()=>{M.current=!1},[]);const X=_!=null;w.useEffect(()=>{var Se;X&&((Se=ee.current)==null||Se.select())},[X]),w.useEffect(()=>{if(!C)return;const Se=window.setTimeout(()=>R(!1),4e3);return()=>window.clearTimeout(Se)},[C]),w.useEffect(()=>{if(!$)return;const Se=window.setTimeout(()=>q(null),4e3);return()=>window.clearTimeout(Se)},[$]);const V=Se=>{const vt=lo(l,Se);return{disabled:vt.disabled,"aria-busy":vt.busy}},G=async Se=>{const vt=await Se();return M.current&&E(vt),vt==null},{peer:F,stranger:L}=t,H=e.kind==="paired",D=e.self??e.name,K=e.kind!=="dialling",re=e.kind==="dialling"?null:e.fp,z=F?F.addr?`${F.addr}:${F.port}`:"":L?L.port?`${L.addr}:${L.port}`:L.addr:e.addr,Z=(F==null?void 0:F.about)??null,U=((It=n.about)==null?void 0:It.version)??null,ae=async Se=>{const vt=Se.trim()===D?"":Se;await G(()=>u(vt))&&k(null)},le=async()=>{if(re)try{if(await navigator.clipboard.writeText(re),!M.current)return;P(!0),window.setTimeout(()=>{M.current&&P(!1)},1600)}catch{M.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},ge=H?F!=null&&F.waiting?F.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":F!=null&&F.offers?"not said — it runs an older version":"not reached yet":"shown once paired",Ne=GS(n.about),Ie=GS(Z),Ge=Z!=null&&Z.version&&U?yU(Z.version,U):null,Pe=F?Ub(F.last,s):null,ze=F&&((zt=F.last)!=null&&zt.error)?eU({error:F.last.error,host:F.addr,port:F.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(Se=>!Se.manual&&Se.addr).map(Se=>({fp:Se.fp,name:Se.name,addr:Se.addr,port:Se.port,at:Se.lastSeen??0}))],s):null,Re=(Xt=F==null?void 0:F.last)!=null&&Xt.error&&Pe&&Pe.text!==F.last.error?F.last.error:null,st=((Ft=F==null?void 0:F.last)==null?void 0:Ft.done)??[],ue=!!Pe&&!!Re&&!e.quiet&&e.state.startsWith(Pe.text),ce=H||e.kind==="dialling",se=((F==null?void 0:F.via)??e.via)==="tailscale",be=F?F.waiting?null:F.manual?se?"added by its Tailscale address":"added by address":se?"over Tailscale":"on this network":e.kind==="nearby"?se?"heard over Tailscale":"heard on this network":se?"asked this deck to pair, over Tailscale":"asked this deck to pair",Le=e.tone==="bad"?"bad":H?e.here?"up":"down":"loose",de=l===`check:${e.fp}`,fe=(F==null?void 0:F.offers)??null,Ce=Le==="up"?(fe==null?void 0:fe.current)??null:null,pe=Ce&&"key"in Ce?Ce.key:null,_e=!!Ce&&"hidden"in Ce,Ye=!!Ce&&"other"in Ce,qe=H?vU((fe==null?void 0:fe.accounts)??null,r,n.shared??[],pe):[],ke=qe.filter(Se=>Se.in==null&&Se.out==="cut"),Ae=qe.some(Se=>Se.in!=null),Ue=qe.some(Se=>Se.out!=null),Fe=new Map(st.map(Se=>[Se.email,Se])),Ve=st.filter(Se=>!qe.some(vt=>vt.email===Se.email)),rt=H?fe?fe.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:F!=null&&F.waiting?"What that deck offers is not known yet. A deck that calls in says so each time it calls — one on an older version never does.":(rn=F==null?void 0:F.last)!=null&&rn.error?"What that deck offers is not known — the last attempt to ask it did not get through.":"Nobody has asked that deck what it offers yet. The next round asks it.":null,ut=fe&&(F!=null&&F.last)&&F.last.at-fe.at>zz?qs(fe.at,s):null,ct=[];H&&(F!=null&&F.pairedAt)?ct.push({label:"Paired",value:Uz(F.pairedAt,s),tone:"meta"}):e.kind==="declined"&&L&&ct.push({label:"Paired",value:`no · you said no ${Hb(L.at,s)}`,tone:"meta"}),ct.push({label:"Fingerprint",value:re?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:re}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void le(),"aria-label":B?"Fingerprint copied":"Copy the fingerprint",children:B?"copied":"copy"})]}):"not known — nothing has answered there",tone:re?void 0:"quiet"});const yt=y.length?[{row:e,peer:F??null},...y]:[];return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:o.jsxs("div",{ref:b,className:"modal lan-peer","data-tone":e.tone,onClick:Se=>Se.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[o.jsxs("header",{className:"modal-head lan-peer-head",children:[o.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("div",{className:"lan-peer-id",children:[X?o.jsxs("form",{className:"lan-peer-edit",onSubmit:Se=>{Se.preventDefault(),ae(_??"")},children:[o.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),o.jsx("input",{ref:ee,className:"ap-manage-input lan-peer-input",value:_??"",maxLength:48,placeholder:D,"aria-label":"Name for this deck, shown on this deck only",onChange:Se=>k(Se.target.value)}),o.jsx("button",{type:"submit",className:"ap-manage-btn",...V(`alias:${e.fp}`),children:"save"}),o.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>k(null),children:"cancel"})]}):o.jsxs("span",{className:"lan-peer-title",children:[o.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),K&&o.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{E(null),k(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:o.jsx(Hz,{})})]}),o.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&o.jsxs(o.Fragment,{children:["calls itself ",o.jsx("span",{className:"lan-peer-self",children:e.self}),X&&o.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...V(`alias:${e.fp}`),onClick:()=>void ae(""),children:"use this name"}),o.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&o.jsx("span",{"aria-hidden":!0,children:" · "})]}),o.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{ref:S,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body lan-peer-body",children:[j&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:j}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>E(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"lan-map","data-link":Le,"data-asking":de||void 0,"data-bus":qe.length>0||void 0,children:[o.jsxs("div",{className:"lan-ends",children:[o.jsxs("p",{className:"lan-end",children:[o.jsx("span",{className:"lan-end-name",children:"This deck"}),Ne&&o.jsx("span",{className:"lan-end-runs",children:Ne}),H&&n.shareActive===!1&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),o.jsxs("p",{className:"lan-end","data-side":"there",children:[o.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&o.jsxs("span",{className:"lan-end-runs",children:[Ie??(Z?"not said":ge),Ge?` · ${Ge<0?"older":"newer"}`:null]}),_e&&o.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ye&&o.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),o.jsxs("div",{className:"lan-link",children:[o.jsx(KS,{}),o.jsxs("span",{className:"lan-span",children:[o.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[o.jsx("i",{className:"lan-glint","data-dir":"out"}),o.jsx("i",{className:"lan-glint","data-dir":"in"})]}),o.jsx("span",{className:"lan-link-label",children:z?o.jsx("code",{className:"ap-lan-code",children:z}):"none here — it calls this deck"})]}),o.jsx(KS,{}),(z&&be||ce)&&o.jsxs("p",{className:"lan-link-sub",children:[z&&be,z&&be&&ce&&" · ",ce&&(Pe?ue?o.jsx("code",{className:"ap-lan-code",children:Re}):o.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),ce&&Re&&!ue&&o.jsx("code",{className:"lan-fact-raw",children:Re})]}),Ve.length>0&&o.jsx("ul",{className:"lan-done",children:Ve.map(Se=>{const vt=z0(Se);return o.jsxs("li",{"data-ok":Se.ok&&!vt,children:[Se.email," ",o.jsxs("span",{className:"lan-done-what",children:[Se.ok?"arrived":"did not arrive",vt&&` — ${vt.long}`]})]},`${Se.email}:${Se.action}`)})}),ze&&o.jsx("p",{className:"lan-note lan-link-note",children:ze}),(F==null?void 0:F.waiting)&&o.jsx("p",{className:"lan-note lan-link-note",children:e.hint}),(Pe==null?void 0:Pe.hint)&&o.jsx("p",{className:"lan-note lan-link-note",children:Pe.hint})]}),qe.length>0&&o.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:qe.map((Se,vt)=>{const kt=Fe.get(Se.email),_n=kt?z0(kt):null,Ut=Se.out==="live"||Se.in!=null&&Se.in!=="cut";return o.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":Se.tone,"data-draw":Se.in&&Se.out?"both":Se.in?"in":"out","data-used-there":Se.usedThere||void 0,style:{"--i":vt},children:[o.jsx("i",{className:"lan-pip","data-end":"here","data-state":Se.here,"aria-hidden":!0}),o.jsxs("span",{className:"lan-track",children:[o.jsxs("span",{className:"lan-wire","data-flow":Ut?"live":"cut","aria-hidden":!0,children:[(Se.in==="live"||Se.in==="wait")&&o.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":Se.in}),Se.out==="live"&&o.jsx("i",{className:"lan-glint","data-dir":"out"})]}),Se.in&&Se.in!=="cut"&&o.jsx(Sh,{dir:"in",gate:Se.in==="blocked"}),Se.out==="live"&&o.jsx(Sh,{dir:"out"}),o.jsx("span",{className:"lan-lane-email",children:Se.email})]}),o.jsx("i",{className:"lan-pip","data-end":"there","data-state":Se.there,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:Gz(Se)}),(Se.caption||kt)&&o.jsxs("span",{className:"lan-lane-note",children:[Se.caption,Se.caption&&kt&&" · ",kt&&o.jsxs("span",{className:"lan-lane-done","data-ok":kt.ok&&!_n,children:[kt.ok?"arrived last round":"did not arrive last round",_n&&` — ${_n.long}`]})]})]},Se.key)})},W),H&&o.jsxs(o.Fragment,{children:[ke.length>0&&o.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ke.length===1?ke[0].email:"the expired ones"," until you sign in again here."]}),rt&&o.jsx("p",{className:"lan-empty",children:rt}),ut&&o.jsxs("p",{className:"lan-stale",children:["As of ",ut==="now"?"just now":ut,", when it last answered."]}),o.jsxs("div",{className:"lan-legend",children:[Ae&&o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:o.jsx(Sh,{dir:"in"})}),"from ",e.name]}),Ue?o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:o.jsx(Sh,{dir:"out"})}),"from this deck, to every paired deck"]}):o.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),o.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),o.jsx("dl",{className:"lan-facts",children:ct.map(Se=>o.jsxs("div",{className:"lan-fact","data-tone":Se.tone,children:[o.jsx("dt",{children:Se.label}),o.jsx("dd",{children:Se.value})]},Se.label))}),yt.length>1&&o.jsxs("div",{className:"modal-section",children:[o.jsxs("h3",{className:"lan-h",children:[yt.length," decks on this machine"]}),o.jsx("ul",{className:"lan-twins",role:"list",children:yt.map((Se,vt)=>{var $t,Zt,Ln,Ur;const kt=($t=Se.peer)!=null&&$t.addr?`${Se.peer.addr}:${Se.peer.port}`:Se.row.addr,_n=kt||Se.row.fp,Ut=(Zt=Se.peer)!=null&&Zt.pairedAt?qs(Se.peer.pairedAt,s):null,Vn=[(Ur=(Ln=Se.peer)==null?void 0:Ln.about)!=null&&Ur.version?`runs ${Se.peer.about.version}`:null,Ut?`paired ${Ut==="now"?"just now":Ut}`:null,Se.row.state].filter(Boolean).join(" · "),Vt=Se.row.fp;return o.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":Se.row.tone,children:[o.jsx("i",{className:Se.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),kt?o.jsx("code",{className:"ap-lan-code lan-twin-at",children:kt}):o.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),o.jsx("code",{className:"ap-lan-code lan-twin-fp",children:Vt}),vt>0&&v&&o.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${$===Vt?" armed":""}`,...V(`unpair:${Vt}`),onKeyDown:xe=>{xe.repeat&&xe.preventDefault()},onClick:()=>{const xe=Date.now(),ir=Au({armedFor:$,target:Vt,armedAt:I.current,now:xe,gapMs:Ou});if(ir==="arm"){q(Vt),I.current=xe;return}ir!=="ignore"&&(q(null),G(()=>v(Vt)))},"aria-label":$===Vt?`Confirm unpairing ${_n}`:`Unpair ${_n}`,title:$===Vt?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this one of the machine's decks",children:l===`unpair:${Vt}`?"unpairing…":$===Vt?"confirm":"unpair"}),o.jsx("span",{className:"lan-twin-meta",children:vt===0?`${Vn} · shown above`:Vn})]},Vt)})})]})]}),o.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&o.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),H&&!(F!=null&&F.waiting)&&o.jsx("button",{type:"button",className:"btn",...V(`check:${e.fp}`),onClick:()=>void G(f).then(Se=>{Se&&M.current&&ne(vt=>vt+1)}),title:"Ask this deck now instead of waiting for the next round",children:l===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&o.jsx("button",{type:"button",className:`btn danger lan-peer-verb${C?" armed":""}`,...V(`unpair:${e.fp}`),onKeyDown:Se=>{Se.repeat&&Se.preventDefault()},onClick:()=>{const Se=Date.now(),vt=Au({armedFor:C?e.fp:null,target:e.fp,armedAt:I.current,now:Se,gapMs:Ou});if(vt==="arm"){R(!0),I.current=Se;return}vt!=="ignore"&&(R(!1),G(p))},"aria-label":C?`Confirm unpairing ${e.name}`:`Unpair ${e.name}`,title:C?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:l===`unpair:${e.fp}`?"Unpairing…":C?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...V(`accept:${e.fp}`),onClick:()=>void G(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:l===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...V(`drop:${e.fp}`),onClick:()=>void G(p),title:"Stop trying this address. Nothing was ever paired here.",children:l===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&n.pairingMode!=="invite"&&o.jsx("button",{type:"button",className:"btn lan-peer-verb",...V(`allow:${e.fp}`),onClick:()=>void G(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:l===`allow:${e.fp}`?"Allowing…":"Let it ask again"}),(e.kind==="nearby"||e.kind==="declined")&&n.pairingMode==="invite"&&m&&o.jsx("button",{type:"button",className:"btn primary lan-peer-verb",onClick:m,title:"This deck pairs only by invite. Make one and send it to whoever is at that machine.",children:"Invite to pair"})]})]})}),document.body)}function Yz(e){if(!e.running)return`Tailscale is ${e.state==="Stopped"?"turned off":e.state==="NeedsLogin"||e.state==="NeedsMachineAuth"?"signed out":e.state==="Starting"?"still starting":"not answering"} on this machine`;const t=e.login??"your Tailscale account";return e.on?`${e.devices} online · ${t}`:t}const jh="Paused while this deck pairs only by invite. Turn that off above to use it.";function Xz({status:e,accounts:t,onClose:n,onChanged:r}){const s=mn(n),[l,c]=w.useState(null),[u,f]=w.useState(null),[p,h]=w.useState(!1),[m,y]=w.useState(null),v=w.useRef(null),S=M=>{const X=lo(m,M);return{disabled:X.disabled,"aria-busy":X.busy}},b=w.useRef(null),_=w.useRef(!0);w.useEffect(()=>()=>{_.current=!1},[]),w.useEffect(()=>{b.current=ZS(b.current,e.shared??[],null)},[e.shared]);const k=w.useCallback(async(M,X,V="write")=>{v.current=V,y(V);try{const F=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:M})})).json().catch(()=>null);return _.current?(F!=null&&F.ok?f(null):f(dn(X,F)),r(),(F==null?void 0:F.ok)===!0):!1}catch{return _.current&&f(dn(X,null)),!1}finally{v.current=null,_.current&&y(null)}},[r]),j=w.useCallback(async()=>{if(l!=null&&l!==(e.name??"")){if(!await k({name:l},"save the name","name"))return;_.current&&c(null)}n()},[l,e.name,k,n]),E=async()=>{if(!e.fp)return;const M=await yi(e.fp);if(_.current){if(!M){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{_.current&&h(!1)},1600)}},C=new Set(b.current??e.shared??[]),R=e.autoAsk!==!1,I=e.autoAccept!==!1,$=e.pairingMode==="invite",q=M=>{const X=S(M);return{...X,disabled:X.disabled||$}},B=e.shareActive!==!1,P=e.tailscale??null,W=!!(P!=null&&P.on),ne=(P==null?void 0:P.ask)!==!1,ee=(P==null?void 0:P.accept)!==!1;return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal lan-modal",onClick:M=>M.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[u&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:u}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Name"}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"appear as"}),o.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:M=>c(M.target.value),onKeyDown:M=>{M.key!=="Enter"||l==null||(k({name:l},"save the name","name"),c(null))}}),l!=null&&l!==(e.name??"")&&o.jsx("button",{type:"button",className:"ap-manage-btn",...S("name"),onClick:()=>{k({name:l},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),o.jsxs("div",{className:"ap-lan-row",children:[o.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?o.jsxs("span",{className:"lan-fp",children:[o.jsx("code",{className:"ap-lan-code",children:e.fp}),o.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void E(),"aria-label":p?"Fingerprint copied":"Copy this deck's fingerprint",children:p?"copied":"copy"})]}):o.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Share these accounts"}),o.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&o.jsx("span",{className:"ap-lan-empty",children:"No Claude accounts on this deck yet — add one with + at the top of this panel."}),t.map(M=>o.jsxs("label",{className:"ap-lan-pick",title:M.alive?"Offer this account to the decks you have paired with, so one whose copy has died can heal from yours. Unticking stops it being offered from now on; it does not take back a copy somebody already has.":"This deck cannot use this login, so it has nothing to offer — a deck that can will heal it",children:[o.jsx("input",{type:"checkbox",checked:C.has(M.key),onChange:X=>{const V=iU(b.current,e.shared??[],M.key,X.target.checked);b.current=V,k({shared:V},X.target.checked?"share that account":"stop sharing that account").then(G=>{b.current===V&&(b.current=ZS(V,e.shared??[],{ok:G}))})}}),o.jsx("span",{className:"ap-lan-pick-name",children:M.email}),!M.alive&&o.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},M.key))]}),t.length>0&&o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":B,"aria-label":"Show paired decks which of these this deck is using",...S("current"),onClick:()=>void k({shareActive:!B},B?"stop showing which account this deck is using":"show which account this deck is using","current"),title:B?"Stop telling paired decks which account this one is on. They read “current account hidden” instead.":"Tell paired decks which of the ticked accounts this one is on. An unticked account is never named.",children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",id:"lan-pairing-h",children:"Pairing"}),o.jsx("div",{className:"lan-switches lan-switches-lead",role:"group","aria-labelledby":"lan-pairing-h",children:o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Pair new decks only by invite",$&&o.jsx("span",{id:"lan-invite-only-detail",className:"lan-switch-detail",children:"A new deck needs an invite from + in the panel. Paired decks stay paired."})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":$,"aria-label":"Pair new decks only by invite","aria-describedby":$?"lan-invite-only-detail":void 0,...S("mode"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({pairingMode:$?"automatic":"invite"},$?"let decks pair on their own again":"pair new decks only by invite","mode"),title:$?"Let decks on this network pair as the two switches below say again.":"Only a deck you send an invite to can pair with this one. Nearby decks can't ask, and requests waiting now are turned away.",children:o.jsx("span",{className:"switch-knob"})})]})}),o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-auto-h",children:["Automatic pairing",$&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches","data-paused":$||void 0,children:[o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":R,"aria-label":"Ask every deck this one finds",...q("ask"),onClick:()=>void k({autoAsk:!R},R?"stop asking automatically":"ask every deck this one finds","ask"),title:$?jh:R?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck heard on this network. Somebody over there still has to say yes.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch",children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Say yes to every deck that asks","data-tone":"warn",...q("accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({autoAccept:!I},I?"stop accepting automatically":"accept every deck that asks","accept"),title:$?jh:I?"Stop saying yes for you. A deck that asks waits in the panel again.":"Say yes for you. Every deck on this network that asks is paired without anybody being asked here.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]}),(P==null?void 0:P.found)&&o.jsxs("div",{className:"modal-section",children:[o.jsx("h3",{className:"lan-h",children:"Tailscale"}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch",children:[o.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",o.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:Yz(P)})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":W,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...S("tailscale"),onClick:()=>void k({tailscale:!W},W?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:W?"Stop. Nothing is looked for or answered over the tailnet; decks already paired stay paired.":"Find the decks on your other machines on Tailscale, wherever they are. Only machines signed in to your Tailscale account are asked.",children:o.jsx("span",{className:"switch-knob"})})]}),W&&o.jsxs("div",{className:"lan-auto",role:"group","aria-labelledby":"lan-ts-auto-h",children:[o.jsxs("p",{className:"lan-sub",id:"lan-ts-auto-h",children:["Automatic pairing with my devices",$&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches",children:[o.jsxs("div",{className:"lan-switch","data-paused":$||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ne,"aria-label":"Ask each of my devices it finds over Tailscale",...q("tailscale-ask"),onClick:()=>void k({tailscaleAsk:!ne},ne?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:$?jh:ne?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck found on your devices over Tailscale.",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"lan-switch","data-paused":$||void 0,children:[o.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ee,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",...q("tailscale-accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({tailscaleAccept:!ee},ee?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:$?jh:ee?"Stop saying yes for you. A device that asks waits in the panel again.":"Say yes for you when a deck on one of your own devices asks. Anybody else on the tailnet still waits for a press.",children:o.jsx("span",{className:"switch-knob"})})]})]})]})]})]})]}),o.jsxs("footer",{className:"lan-setup-foot",children:[o.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),o.jsx("button",{type:"button",className:"btn primary",...S("name"),onClick:()=>void j(),children:"Done"})]})]})}),document.body)}function qs(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const s=Math.round(r/60);return s<48?`${s}h ago`:`${Math.round(s/24)}d ago`}const YS={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${Fb}. The next round brings it.`}};function z0(e){return e.why?Object.hasOwn(YS,e.why)?YS[e.why]:sf(e.why):null}const zb={"waiting for the other deck to accept this one":{text:"waiting for them to say yes",tone:"idle"},"that deck said no":{text:"it said no",tone:"bad"},"that deck pairs only by invite":{text:"it pairs only by invite",tone:"idle"},"this deck pairs only by invite":{text:"needs an invite · your setting",tone:"idle"}},Zz={ECONNREFUSED:"not listening",EHOSTUNREACH:"no route to it",ENETUNREACH:"no network here",ETIMEDOUT:"no answer",ECONNRESET:"it hung up",EHOSTDOWN:"it is down",ENOTFOUND:"name not found",EACCES:"blocked here",EPIPE:"it hung up"};function XS(e){var r;const t=Qz[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&Zz[n]||e}const Qz={"handshake timed out":"no answer","peer closed the connection":"it hung up","peer went quiet":"it stopped mid-sentence","bad reply":"it answered with nonsense","no manifest":"it would not say what it has","bad challenge":"it answered as somebody else","a different deck is answering at that address":"a different deck is at that address","that deck could not prove its own key":"it could not prove who it is","the other deck refused this one's proof":"it would not take this deck's word","the other deck refused this handshake":"it turned this deck away","that deck has this one pinned under a different key":"it knows this deck by another key"};function Ub(e,t){var h;if(!e)return null;if(e.error&&((h=e.done)!=null&&h.length)){const m=Ub({...e,error:void 0},t),y=` · ${qs(e.at,t)}`;return{...m,text:`${m.text.slice(0,-y.length)}, then ${XS(e.error)}${y}`,tone:"bad"}}if(e.error)return zb[e.error]??{text:XS(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${qs(e.at,t)}`,tone:"idle"};const r=n.filter(m=>m.ok),s=r.length===1?"login":"logins",l=n.map(m=>({d:m,why:z0(m)})).filter(m=>m.why),c=[...new Set(l.map(m=>m.why.short))],u=c.length?`, ${c.join(", ")}`:"",f=l.length?l.map(m=>`${m.d.email}: ${m.why.long}`).join(" "):void 0,p=qs(e.at,t);return r.length===n.length?{text:`${r.length} ${s} arrived${u} · ${p}`,tone:l.length?"warn":"ok",...f?{hint:f}:{}}:{text:`${r.length} of ${n.length} logins arrived${u} · ${p}`,tone:"bad",...f?{hint:f}:{}}}const Jz=9e4;function eU({error:e,host:t,port:n},r,s,l=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=r.filter(p=>p.addr===c&&p.port&&p.at>0&&s-p.at<Jz);if(!u.length)return null;const f=[...new Set(u.map(p=>p.port))];if(n!=null&&!f.includes(n)){const p=f.length===1?`port ${f[0]}`:`ports ${f.join(" and ")}`;return`A deck at ${c} is announcing itself on ${p}, not on ${n}. This deck already hears it and dials it there, so this typed row has nothing to reach.`}return`That machine is running the deck — its beacon arrives here every half minute — and what this deck sends back never gets there. That is a firewall on ${c}, not a network fault. Whoever uses it can allow two ports: UDP ${l} and TCP ${n??f[0]}.`}const U0=5e3,KM=6e4,Ou=400;function tU(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const r=t.slice(0,n).trim(),s=Number(t.slice(n+1).trim());return!r||!Number.isInteger(s)||s<1||s>65535||r.includes(":")&&!(r.startsWith("[")&&r.endsWith("]"))?null:{addr:r,port:s}}function dn(e,t){if(t==null)return`Could not ${e} — the deck did not answer.`;const n=t.reason?sU(t.reason,t.detail):void 0;return n?`Could not ${e} — ${n}`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}const nU={prefs_unreadable:"this deck cannot read its settings file, so it will not write over it. The file may belong to another user, for example after ccdeck was run with sudo. The deck's log names the file.",prefs_not_writable:"this deck is not allowed to save its settings. The settings folder may belong to another user, for example after ccdeck was run with sudo, or another program may be holding the file. The deck's log names the folder."},rU=new Set(["EACCES","EPERM"]);function sU(e,t){const n=nU[e];if(!n)return;const r=e==="prefs_unreadable"&&t?aU(t):void 0,s=t!=null&&t.code&&t.code!=="BADJSON"?` Error code: ${t.code}.`:"";return(r??n)+s}function aU({code:e,owner:t,on:n}){if(e==="BADJSON")return"its settings file is damaged and could not be moved aside, so it will not write over it. The deck's log names the file.";if(n==="folder"&&t==="other")return"this deck cannot open its settings folder, which belongs to another user, for example after ccdeck was run with sudo. The deck's log has the command that gives it back.";if(n==="folder"&&t==="you")return"this deck cannot open its own settings folder, so it will not write over what is in it. The deck's log names the folder.";if(t==="other")return"its settings file belongs to another user and could not be moved aside, so it will not write over it. The deck's log names the file.";if(t==="you")return"this deck cannot read its settings file although the file is yours, so it will not write over it. Something on this machine is blocking the read; the deck's log names the file.";if(e&&!rU.has(e))return"this deck cannot read its settings file, so it will not write over it. The deck's log names the file."}function oU(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function iU(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function ZS(e,t,n){return e==null||n!=null&&!n.ok||oU(e,t)?null:e}function lU(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function YM(e,t){var n,r;return(n=e.last)!=null&&n.error&&!zb[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<of||e.lastSeen!=null&&t-e.lastSeen<of)}const of=95e3,XM=160,cU=6,ZM=140;function uU(e,t){const n=[],r=[];for(const s of e??[])(YM(s,t)?n:r).push(s);return{online:n,offline:r}}function dU(e){var t;return(t=e.tailscale)!=null&&t.exitNode?"Tailscale sends this machine's local network through an exit node, so decks on this network cannot find this one. Turn on Allow local network access in Tailscale's exit node menu to bring them back.":"This machine sends its local network through a VPN, so decks on this network cannot find this one. Allowing local network access in the VPN brings them back."}function hU(e,t){if(!e)return{text:"checking…",tone:"idle"};if(!e.enabled)return{text:"",tone:"idle"};if(e.stalled)return{text:`could not start — ${e.stalled}`,tone:"bad"};if(!e.running)return{text:"starting…",tone:"wait"};const n=(e.pending??[]).length;if(n)return{text:n===1?"1 deck is waiting for your answer":`${n} decks are waiting for your answer`,tone:"wait"};const r=(e.peers??[]).filter(v=>v.paired!==!1||v.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const s=r.filter(v=>v.waiting),l=r.filter(v=>!v.waiting),c=s.filter(v=>{var S;return!((S=v.last)!=null&&S.error)&&v.lastSeen!=null&&t-v.lastSeen<of}),{online:u,offline:f}=uU(l,t),p=[...f,...s.filter(v=>!c.includes(v))],h=u.length+c.length,m=u.filter(v=>{var S;return((S=v.last)==null?void 0:S.error)==="waiting for the other deck to accept this one"});if(h&&m.length===h)return{text:h===1?"1 deck found · waiting for them to accept":`${h} decks found · waiting for them to accept`,tone:"wait"};if(!h)return{text:p.length===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${p.length} decks`,tone:"bad"};const y=h===1?"1 deck ready":`${h} decks ready`;return{text:p.length?`${y} · ${p.length} away`:y,tone:"ok"}}function fU(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=qs(e,t);return r==="now"?"checked just now":`checked ${r}`}function Hb(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const r=Math.round(n/60);return r<60?`${r}m ago`:`${Math.round(r/60)}h ago`}function pU(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<of;return{text:n?"online · one-way, it calls in":`one-way · last online ${qs(e,t)}`,here:n}}function QS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${qs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function mU(e,t){var y,v,S,b,_;if(!e)return[];const n=[],r=new Set,s=(k,j)=>k.name.localeCompare(j.name,void 0,{numeric:!0}),l=e.aliases??{},c=(k,j)=>{const E=k?l[k]:void 0;return E&&E!==j?{name:E,self:j}:{name:j}};for(const k of e.pending??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);n.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"asks",state:`wants to pair · ${Hb(k.at,t)}`,tone:"wait",here:!0,hint:`${j.name} at ${k.addr}${k.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}const u=[],f=[];for(const k of e.peers??[]){const j=k.peerFp??k.fp;if(!j||r.has(j))continue;r.add(j);const E=Ub(k.last,t),C=YM(k,t),R=k.addr?`${k.addr}:${k.port}`:"";if(!k.paired&&k.manual&&!k.met){f.push({fp:R,name:R||k.name||j,addr:k.addr??"",kind:"dialling",state:E?E.text.replace(/ · .*$/,""):"trying…",tone:E?E.tone:"idle",here:!1,hint:(y=k.last)!=null&&y.error?`Nothing has answered at ${R} yet — ${k.last.error}.`:`Dialling ${R} until something answers.`,...k.via==="tailscale"?{via:"tailscale"}:{}});continue}const I=k.waiting?pU(k.lastSeen,t):null,$=I?I.here:C,q=!I&&E?$?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${QS(k,$,t)}`:I?I.text:QS(k,$,t),B=(v=k.last)!=null&&v.error?zb[k.last.error]:null,P=!I&&$&&!((S=k.last)!=null&&S.error)&&!(((b=k.last)==null?void 0:b.done)??[]).length,W=k.manual&&!k.met?{name:R}:c(j,k.name||j);u.push({fp:j,name:W.name,...W.self?{self:W.self}:{},addr:k.addr??"",kind:"paired",state:q,quiet:P,tone:B?B.tone==="bad"?"bad":"wait":E?E.tone:$?"ok":"idle",here:I?I.here:C,...k.via==="tailscale"?{via:"tailscale"}:{},hint:I?`${W.name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. ${k.lastSeen==null?"It has not called since this deck started.":`It last called ${qs(k.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${W.name}${R?` at ${R}`:""}${(_=k.last)!=null&&_.error?` — ${k.last.error}`:""}${E!=null&&E.hint?` — ${E.hint}`:""}`})}n.push(...gU(u).sort(s),...f.sort(s));const p=[];for(const k of e.strangers??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);p.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"nearby",state:e.pairingMode==="invite"?"needs an invite":"not paired yet",tone:"idle",here:!0,hint:k.via==="tailscale"?`${j.name} at ${k.addr} is on your tailnet and nothing is shared with it.`:`${j.name} at ${k.addr} is on this network and nothing is shared with it.`,...k.via==="tailscale"?{via:"tailscale"}:{}})}n.push(...p.sort(s));const h=[];for(const k of e.declined??[]){if(!(k!=null&&k.fp)||r.has(k.fp))continue;r.add(k.fp);const j=c(k.fp,k.name||k.fp);h.push({fp:k.fp,name:j.name,...j.self?{self:j.self}:{},addr:k.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${j.name} asked and was turned away. It is not asking any more.`})}n.push(...h.sort(s));const m=new Map;for(const k of n)m.set(k.name,(m.get(k.name)??0)+1);for(const k of n)(m.get(k.name)??0)<2||!k.addr||(k.state=k.quiet||!k.state?k.addr:`${k.addr} · ${k.state}`,k.quiet=!1);return n}function gU(e){const t=new Map;for(const r of e){const s=t.get(r.name);s?s.push(r):t.set(r.name,[r])}const n=[];for(const r of t.values()){const s=[...new Set(r.filter(l=>l.addr).map(l=>l.addr))];if(s.length>1){for(const l of s)n.push(JS(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(JS(r))}return n}function JS(e){const[t,...n]=[...e].sort((r,s)=>Number(s.here)-Number(r.here)||+!!s.addr-+!!r.addr);return n.length?{...t,twins:n}:t}function ej(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function tj(e,t){if(!e)return{};switch(t.kind){case"paired":return{peer:(e.peers??[]).find(n=>(n.peerFp??n.fp)===t.fp)??null};case"dialling":return{peer:(e.peers??[]).find(n=>n.manual&&!n.met&&`${n.addr}:${n.port}`===t.fp)??null};case"nearby":return{stranger:(e.strangers??[]).find(n=>n.fp===t.fp)??null};case"declined":return{stranger:(e.declined??[]).find(n=>n.fp===t.fp)??null};case"asks":return{stranger:(e.pending??[]).find(n=>n.fp===t.fp)??null}}}function yU(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!r)return null;for(let s=1;s<=3;s++){const l=Number(n[s])-Number(r[s]);if(l)return Math.sign(l)}return 0}function wU(e,t,n){const r=t?t.alive?t.shareable===!1?"cannot share here":"works here":"expired here":"not on this deck";if(e.alive&&e.shareable===!1)return{there:"cannot share there",here:r,note:null,tone:"idle"};if(!e.alive){const s=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:r,note:s,tone:s?"bad":"idle"}}return t?t.alive?{there:"works there",here:r,note:null,tone:t.shareable===!1?"idle":"ok"}:n?{there:"works there",here:r,note:"repairs next round",tone:"wait"}:{there:"works there",here:r,note:"share it to repair",tone:"bad"}:{there:"works there",here:r,note:"arrives next round",tone:"wait"}}function vU(e,t,n,r=null){var f;const s=new Map;for(const p of t)(f=s.get(p.key))!=null&&f.alive||s.set(p.key,p);const l=new Set(n),c=[],u=new Set;for(const p of e??[]){if(u.has(p.key))continue;u.add(p.key);const h=s.get(p.key)??null,m=l.has(p.key),y=wU(p,h,m),v=h?h.alive?h.shareable===!1?"unavailable":"works":"expired":"missing",S=!p.alive&&h&&!h.alive?y.note:[v==="works"?null:y.here,p.alive&&p.shareable!==!1?null:y.there,y.note].filter(Boolean).join(" · ")||null;c.push({key:p.key,email:p.email,here:v,there:p.alive?p.shareable===!1?"unavailable":"works":"broken",in:!p.alive||p.shareable===!1?"cut":y.tone==="wait"?"wait":y.tone==="bad"?"blocked":"live",out:m&&h?h.alive&&h.shareable!==!1?"live":"cut":null,caption:S,tone:y.tone,usedThere:r===p.key})}for(const p of n){const h=s.get(p);!h||u.has(p)||(u.add(p),c.push({key:p,email:h.email,here:h.alive?h.shareable===!1?"unavailable":"works":"expired",there:"unknown",in:null,out:h.alive&&h.shareable!==!1?"live":"cut",caption:h.alive?h.shareable===!1?"cannot share here":null:"expired here",tone:h.alive?h.shareable===!1?"idle":"ok":"bad",usedThere:!1}))}return c}async function Cl(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function xU({anchorId:e,id:t,rows:n,onHold:r,onLet:s}){const l=w.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,cU),p=c.length-u.length,h=u.length>f.length?`and ${u.length-f.length} more`:p>0?`${p} not on right now`:null,m=w.useCallback(()=>{const y=l.current,v=document.getElementById(e);if(!y||!v)return;const S=Pb(v.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${S.top}px`,y.style.left=`${S.left}px`,y.style.maxHeight=S.maxHeight==null?"":`${S.maxHeight}px`,y.dataset.side=S.side},[e]);return w.useLayoutEffect(()=>{m()}),w.useEffect(()=>(window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[m]),On.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&o.jsx("div",{className:"ap-peek-list",children:f.map(y=>o.jsxs("span",{className:"ap-peek-who",children:[o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),o.jsxs("span",{children:[y.name,y.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${y.kind}:${y.fp}`))}),h&&o.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function bU(e,t){var l;if(!e)return{text:"checking…",tone:"idle",live:!1};if(!e.enabled)return{text:"Off",tone:"idle",live:!1};if(e.stalled)return{text:"could not start",tone:"bad",live:!1};if(!e.running)return{text:"starting…",tone:"wait",live:!1};const n=t.filter(c=>c.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((l=e.reach)!=null&&l.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(c=>c.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const s=r.filter(c=>c.here).length;return s?s===r.length?{text:`${s} online`,tone:"ok",live:!0}:{text:`${s} of ${r.length} online`,tone:"ok",live:!0}:{text:`none of ${r.length} online`,tone:"idle",live:!1}}function kU({accounts:e,onChanged:t,view:n,onOpen:r,onBack:s,closeButton:l}){const[c,u]=w.useState(null),[f,p]=w.useState([]),[h,m]=w.useState(null),[y,v]=w.useState(!1),[S,b]=w.useState(null),_=w.useRef(0),[k,j]=w.useState(!1),[E,C]=w.useState(!1),[R,I]=w.useState(!1),$=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout($.current),[]);const[q,B]=w.useState(!1),[P,W]=w.useState(null),ne=w.useRef(null),ee=w.useCallback(de=>Mf(ne.current)?(ne.current=de,m(de),!0):!1,[]),M=w.useCallback(()=>{ne.current=null,F.current&&m(null)},[]),X=de=>{const fe=lo(h,de);return{disabled:fe.disabled,"aria-busy":fe.busy}},[V,G]=w.useState(()=>Date.now()),F=w.useRef(!0),L=w.useRef(U0),H=w.useCallback(async()=>{var de,fe;try{const[Ce,pe]=await Promise.all([fetch("/api/lan").then(_e=>_e.json()),fetch("/api/prefs").then(_e=>_e.json())]);if(!F.current)return;Ce!=null&&Ce.ok&&u(Ce),pe!=null&&pe.ok&&p(Array.isArray((fe=(de=pe.prefs)==null?void 0:de.lan)==null?void 0:fe.manual)?pe.prefs.lan.manual:[]),L.current=(Ce==null?void 0:Ce.enabled)===!0?U0:KM}catch{}},[]);w.useEffect(()=>{F.current=!0;let de=0;const fe=async()=>{G(Date.now()),await H(),F.current&&(de=window.setTimeout(fe,L.current))};return fe(),()=>{F.current=!1,window.clearTimeout(de)}},[H]);const D=w.useCallback(async()=>{const de=(c==null?void 0:c.enabled)===!0;if(ee("switch"))try{const fe=await Cl("/api/prefs",{lan:{enabled:!de}});if(!F.current)return;fe!=null&&fe.ok?(W(null),de||v(!0)):W(dn(de?"turn this off":"turn this on",fe)),await H()}catch{F.current&&W(dn(de?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,H,ee,M]),K=w.useCallback(async(de,fe,Ce)=>{if(!ee(`${de}:${fe}`))return null;let pe=null;try{const _e=await Cl("/api/lan/peer",{action:de,fp:fe});if(!F.current)return null;_e!=null&&_e.ok?(u(_e),W(null)):(pe=dn(Ce,_e),W(pe)),await H()}catch{pe=dn(Ce,null),F.current&&W(pe)}finally{M()}return pe},[H,ee,M]),re=w.useCallback(async de=>{if(!ee(`drop:${de}`))return null;let fe=null;try{const Ce=await Cl("/api/prefs",{lan:{manual:f.filter(pe=>pe!==de)}});if(!F.current)return null;Ce!=null&&Ce.ok?(W(null),t()):(fe=dn("stop dialling that address",Ce),W(fe)),await H()}catch{fe=dn("stop dialling that address",null),F.current&&W(fe)}finally{M()}return fe},[f,H,t,ee,M]),[z,Z]=w.useState(null),U=w.useCallback(async(de,fe)=>{if(!ee(`alias:${de}`))return"Something else is still being saved. Try again in a moment.";try{const Ce=await Cl("/api/lan/peer",{action:"alias",fp:de,name:fe});return F.current?Ce!=null&&Ce.ok?(u(Ce),null):dn("rename that deck",Ce):null}catch{return dn("rename that deck",null)}finally{M()}},[ee,M]),ae=w.useCallback(async de=>{if(!ee(`check:${de}`))return null;try{const fe=await Cl("/api/lan/sync",{fp:de});return F.current?fe!=null&&fe.ok?(u(fe),t(),null):(fe==null?void 0:fe.reason)==="no_address"?"There is no address here to call it on. It calls this deck, and it is up to date each time it does.":dn("check that deck",fe):null}catch{return dn("check that deck",null)}finally{M()}},[ee,M,t]),le=w.useCallback(async()=>{if(ee("check"))try{const de=await Cl("/api/lan/sync",{});if(!F.current)return;de!=null&&de.ok?(u(de),W(null)):W(dn("check the other decks",de)),t()}catch{F.current&&W(dn("check the other decks",null))}finally{M()}},[ee,M,t]),ge=(c==null?void 0:c.enabled)===!0,Ne=mU((c==null?void 0:c.pairingMode)==="invite"&&c?{...c,pending:[]}:c,V),Ie=z?Ne.find(de=>{var fe;return de.fp===z||((fe=de.twins)==null?void 0:fe.some(Ce=>Ce.fp===z))})??null:null;w.useEffect(()=>{z&&c&&!Ie&&Z(null)},[z,c,Ie]);const Ge=Ne.filter(de=>de.kind==="asks"),Pe=Ne.filter(de=>de.kind!=="asks"),ze=Pe.filter(de=>de.here),Re=Pe.filter(de=>!de.here),st=Re.filter(de=>de.tone==="bad").length,ue=q||ze.length===0,ce=hU(c,V),se=Pe.filter(de=>de.kind==="paired").length,be=bU(c,Ne),Le=o.jsxs(o.Fragment,{children:[k&&c&&o.jsx(qz,{status:c,manual:f,startWith:k==="invite"?"invite":void 0,onClose:()=>j(!1),onChanged:()=>{H(),t()}}),E&&o.jsx(WM,{title:"How Local network works",steps:$z,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),D()}},onClose:()=>C(!1)}),y&&c&&o.jsx(Xz,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>v(!1),onChanged:()=>{H(),t()}}),Ie&&c&&o.jsx(Kz,{row:Ie,source:tj(c,Ie),status:c,accounts:e,now:V,busy:h,onClose:()=>Z(null),onRename:de=>U(Ie.fp,de),onCheck:()=>ae(Ie.fp),onVerb:()=>{switch(Ie.kind){case"paired":return K("unpair",Ie.fp,"unpair that deck");case"nearby":return K("accept",Ie.fp,"reach that deck");case"declined":return K("allow",Ie.fp,"let that deck ask again");case"dialling":return re(Ie.fp);default:return Promise.resolve(null)}},onSettings:()=>{Z(null),v(!0)},onInvite:()=>{Z(null),j("invite")},twins:(Ie.twins??[]).map(de=>({row:de,peer:tj(c,de).peer??null})),onUnpair:de=>K("unpair",de,"unpair that deck")})]});if(!n){const de=_e=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>I(!0),_e)},fe=()=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>I(!1),ZM)},Ce=()=>window.clearTimeout($.current),pe=()=>{window.clearTimeout($.current),I(!1)};return o.jsxs("div",{className:"ap-foot",children:[o.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{pe(),r()},"aria-describedby":R?"ap-lan-peek":void 0,onPointerEnter:_e=>{_e.pointerType==="mouse"&&de(XM)},onPointerLeave:fe,onFocus:_e=>{_e.target.matches(":focus-visible")&&de(0)},onBlur:fe,children:[o.jsxs("svg",{className:"ap-nav-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),o.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Local network"}),o.jsxs("span",{className:"ap-nav-state","data-tone":be.tone,children:[be.live&&o.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),be.text]})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),R&&o.jsx(xU,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:Ne,onHold:Ce,onLet:fe}),o.jsx("p",{className:"vis-hidden",role:"status",children:ce.tone==="ok"?"":ce.text}),Le]})}return o.jsxs("div",{className:"ap-lan-view",children:[o.jsxs("div",{className:"ap-header",children:[o.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:s,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),o.jsx("h2",{id:"ap-lan-title",children:"Local network"}),o.jsxs("div",{className:"ap-header-right",children:[ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>j("add"),"aria-label":"Add a deck",title:(c==null?void 0:c.pairingMode)==="invite"?"Send an invite, or use one you were sent. This deck pairs only by invite.":"Reach a deck that has not turned up on its own — by address, or with an invite",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M6.1 7.9a2.6 2.6 0 0 0 3.7 0l1.9-1.9a2.6 2.6 0 0 0-3.7-3.7l-.9.9"}),o.jsx("path",{d:"M7.9 6.1a2.6 2.6 0 0 0-3.7 0L2.3 8a2.6 2.6 0 0 0 3.7 3.7l.9-.9"})]})}),ge&&se>0&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...X("check"),onClick:()=>void le(),"aria-label":h==="check"?"Checking every paired deck":"Check every paired deck now",title:"Ask every paired deck now for anything this deck's expired logins need, instead of waiting for the next round",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),o.jsx("path",{d:"M4.6 4.6a3.4 3.4 0 0 0 0 4.8M9.4 4.6a3.4 3.4 0 0 1 0 4.8"}),o.jsx("path",{d:"M2.6 2.6a6.2 6.2 0 0 0 0 8.8M11.4 2.6a6.2 6.2 0 0 1 0 8.8"})]})}),ge&&o.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...X("setup"),onClick:()=>v(!0),"aria-label":"This deck's name and shared logins",title:"This deck's name on the network, and which of its logins it offers",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),o.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),o.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),l]})]}),o.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:o.jsxs("div",{className:"ap-lan",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ge,"aria-label":"Sync with paired decks",...X("switch"),onClick:()=>void D(),title:ge?"Stop talking to other decks. Nothing is shared while this is off.":"Let the decks you pair with repair this one's expired logins",children:o.jsx("span",{className:"switch-knob"})})]}),ge&&o.jsx(GM,{reach:c==null?void 0:c.reach,where:"panel"}),ge&&(c==null?void 0:c.deaf)&&o.jsx("p",{className:"ap-lan-fine",children:c.deaf}),ge&&(c==null?void 0:c.lanTunneled)&&o.jsx("p",{className:"ap-lan-fine",children:dU(c)}),!ge&&o.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>C(!0),title:"Four pictures: what this does, and what to do on each machine",children:[o.jsx(Oz,{}),o.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),o.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),o.jsx("p",{className:`ap-lan-status ${ce.tone}`,role:"status",children:ce.tone==="ok"?"":ce.text}),P&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:P}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>W(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ge&&o.jsxs(o.Fragment,{children:[Ge.length>0&&o.jsx("div",{className:"ap-lan-asks",role:"alert",children:Ge.map(de=>o.jsxs("div",{className:"ap-lan-ask",children:[o.jsxs("span",{className:"ap-lan-ask-what",children:[o.jsx("strong",{className:"ap-lan-peer-name",children:de.name})," at ",o.jsx("code",{className:"ap-lan-code",children:de.addr})," wants to pair"]}),o.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",o.jsx("code",{className:"ap-lan-code",children:de.fp})]}),o.jsxs("span",{className:"ap-lan-ask-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",...X(`accept:${de.fp}`),onClick:()=>void K("accept",de.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${de.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...X(`dismiss:${de.fp}`),onClick:()=>void K("dismiss",de.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},de.fp))}),(ue?[...ze,...Re]:ze).length>0&&o.jsx("ul",{className:"ap-lan-here",children:(ue?[...ze,...Re]:ze).map((de,fe)=>o.jsxs("li",{className:"ap-lan-who","data-tone":de.tone,children:[o.jsx("i",{className:de.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[de.name,de.via==="tailscale"&&o.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),o.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${fe}`,onClick:()=>Z(de.fp),children:o.jsxs("span",{className:"vis-hidden",children:[de.name,de.via==="tailscale"?", over Tailscale":"",", details"]})}),o.jsx("span",{id:`lan-who-state-${fe}`,className:de.quiet?"vis-hidden":"ap-lan-who-when",children:de.state}),de.kind==="nearby"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`accept:${de.fp}`),onClick:()=>void K("accept",de.fp,"reach that deck"),"aria-label":`Ask ${de.name} to pair`,title:`Send ${de.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${de.fp}.`,children:"ask"}),(de.kind==="nearby"||de.kind==="declined")&&(c==null?void 0:c.pairingMode)==="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do","aria-haspopup":"dialog",onClick:()=>j("invite"),"aria-label":`Invite ${de.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${de.name}.`,children:"invite"}),de.kind==="paired"&&o.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${S===de.fp?" armed":""}`,...X(`unpair:${de.fp}`),onClick:()=>{const Ce=Date.now(),pe=Au({armedFor:S,target:de.fp,armedAt:_.current,now:Ce,gapMs:Ou});if(pe==="arm"){b(de.fp),_.current=Ce,window.setTimeout(()=>b(_e=>_e===de.fp?null:_e),4e3);return}pe!=="ignore"&&(b(null),K("unpair",de.fp,"unpair that deck"))},"aria-label":S===de.fp?`Confirm unpairing ${de.name}`:`Unpair ${de.name}`,title:S===de.fp?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:S===de.fp?"confirm":"unpair"}),de.kind==="dialling"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`drop:${de.fp}`),onClick:()=>void re(de.fp),"aria-label":`Stop dialling ${de.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),de.kind==="declined"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`allow:${de.fp}`),onClick:()=>void K("allow",de.fp,"let that deck ask again"),"aria-label":`Let ${de.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${de.kind}:${de.fp}`))}),(ze.length>0&&Re.length>0||ge&&se>0)&&o.jsxs("div",{className:"ap-lan-tail",children:[ze.length>0&&Re.length>0&&o.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":q,onClick:()=>B(de=>!de),title:q?"Show only the decks that are on":`Show the ${Re.length} deck${Re.length===1?"":"s"} that are not responding right now`,children:[o.jsx("span",{className:`ap-lan-chev${q?" open":""}`,"aria-hidden":!0,children:"›"}),q?"fewer":`${Re.length} more`,!q&&st>0&&o.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",st," not responding"]})]}),ge&&se>0&&o.jsx("span",{className:"ap-lan-checked",children:fU(c==null?void 0:c.checkedAt,V,h==="check")})]}),Pe.length===0&&Ge.length===0&&!(c!=null&&c.stalled)&&!(c!=null&&c.deaf)&&!(c!=null&&c.lanTunneled)&&o.jsxs(o.Fragment,{children:[o.jsx("p",{className:"ap-lan-fine",children:"No other deck yet. Decks on one network usually find each other on their own; when that has not happened, the link at the top of this view reaches one by address or by invite."}),o.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),Le]})}function NU({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const l=w.useRef(null),{title:c,shown:u,rest:f}=xz(n),p=w.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=Pb(m.getBoundingClientRect(),{width:h.offsetWidth,height:h.offsetHeight},{width:window.innerWidth,height:window.innerHeight});h.style.top=`${y.top}px`,h.style.left=`${y.left}px`,h.style.maxHeight=y.maxHeight==null?"":`${y.maxHeight}px`,h.dataset.side=y.side},[e]);return w.useLayoutEffect(()=>{p()}),w.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),On.createPortal(o.jsxs("div",{ref:l,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:s,children:[o.jsx("p",{className:"ap-peek-title",children:c}),o.jsx("div",{className:"ap-peek-list",children:u.map(h=>o.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[o.jsx("span",{className:"ap-fold-name",children:h.name}),o.jsx("span",{className:"ap-fold-state","data-tone":h.ready?"ok":h.warn?"warn":"idle",children:h.ready?h.headroom==null?"not read yet":`${h.headroom}% free`:h.why})]},h.key))}),f&&o.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function SU({peers:e,strained:t,armed:n,threshold:r,open:s,onToggle:l}){const[c,u]=w.useState(!1),f=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(f.current),[]),w.useEffect(()=>{s&&(window.clearTimeout(f.current),u(!1))},[s]);const p=S=>{s||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!0),S))},h=()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!1),ZM)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},v=wz(e,{strained:t&&!s,armed:n,threshold:r});return o.jsxs("div",{className:"ap-rest",children:[o.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":s,"aria-controls":s?"ap-rest-panel":void 0,"aria-describedby":c?"ap-rest-peek":void 0,onClick:()=>{y(),l()},onPointerEnter:S=>{S.pointerType==="mouse"&&p(XM)},onPointerLeave:h,onFocus:S=>{S.target.matches(":focus-visible")&&p(0)},onBlur:h,children:[o.jsxs("span",{className:"ap-nav-text",children:[o.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),o.jsx("span",{className:"ap-nav-state","data-tone":v.tone,children:v.text})]}),o.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),c&&o.jsx(NU,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function jU(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const _U=1800;function EU({accounts:e,onClose:t,copyText:n}){const[r,s]=w.useState([]),[l,c]=w.useState(null),[u,f]=w.useState(!1),[p,h]=w.useState(null),[m,y]=w.useState(!1),[v,S]=w.useState(()=>Math.floor(Date.now()/1e3)),b=w.useRef(null),_=w.useRef(!1),k=mn(t,{focusRef:b});w.useEffect(()=>{if(!l)return;S(Math.floor(Date.now()/1e3));const P=window.setInterval(()=>S(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval(P)},[l]);const j=iz(e),E=lz(e,r),C=E.length===e.length,R=P=>s(W=>cz(W,P)),I=w.useCallback(async()=>{const P=uz(E);if(!Ps(_.current)||!P)return;_.current=!0,f(!0),h(null),y(!1);const W=await jU(P).catch(()=>null);if(_.current=!1,f(!1),!(W!=null&&W.ok)){h(Ol(W,"the share could not be made"));return}c({blob:W.blob,expiresAt:W.expiresAt,shared:W.shared??[],failed:W.failed??[]})},[e,E]),$=l?HM(l.expiresAt,v):null,q=($==null?void 0:$.tone)==="gone",B=(l==null?void 0:l.shared.length)??0;return On.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:k,className:"modal sa-modal",onClick:P=>P.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("h3",{children:"Share accounts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsx("section",{className:"modal-body sa-body",children:l?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:q?"This share has expired":B===1?"1 account, ready to paste":`${B} accounts, ready to paste`}),o.jsx("code",{className:`ap-share-blob${q?" sa-dead":""}`,children:l.blob}),o.jsxs("div",{className:"ap-share-foot",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",ref:b,onClick:async()=>{if(q){c(null),I();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),_U))},children:q?"make a new share":m?"copied":`copy ${B===1?"the share":"all "+B}`}),o.jsxs("span",{className:"ap-manage-hint",title:"This text is the sign-in for every account in it. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the logins themselves are in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign those accounts out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:B===1?"this is the password":`this is ${B} passwords`})," · ",o.jsx("span",{className:`ap-share-expiry ${$==null?void 0:$.tone}`,children:$==null?void 0:$.text})]})]}),l.failed.length>0&&o.jsxs("div",{className:"sa-failed",role:"alert",children:[o.jsx("p",{className:"sa-failed-head",children:l.failed.length===1?"One account is not in this bundle:":`${l.failed.length} accounts are not in this bundle:`}),o.jsx("ul",{className:"sa-list",children:l.failed.map(P=>{var ne;const W=!!(P.email&&((ne=P.detail)!=null&&ne.includes(P.email)));return o.jsxs("li",{children:[!W&&o.jsx("span",{className:"sa-who",children:P.email||`account ${P.num}`}),o.jsx("span",{className:"sa-why",children:P.detail||"could not be exported"})]},`${P.num}-${P.email}`)})})]}),o.jsx("p",{className:"sa-note",children:q?o.jsx(o.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):o.jsxs(o.Fragment,{children:["Paste it into the other deck with ",o.jsx("strong",{children:"+"})," → ",o.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),o.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?o.jsxs("div",{className:"sa-step",children:[o.jsx("h4",{children:"Nothing to share"}),o.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",o.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),o.jsx("div",{className:"sa-actions",children:o.jsx("button",{type:"button",className:"btn primary",ref:b,onClick:t,children:"Close"})})]}):o.jsxs("div",{className:"sa-step",children:[o.jsxs("h4",{children:["Which accounts go to the other ",hn,"?"]}),o.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:dz(E.length)}),o.jsx("ul",{className:"sa-list sa-pick",children:j.map(P=>o.jsx("li",{children:o.jsxs("label",{className:"sa-row",children:[o.jsx("input",{type:"checkbox",checked:E.includes(P.num),onChange:()=>R(P.num)}),o.jsx("span",{className:"sa-who",children:P.label}),P.sub&&o.jsx("span",{className:"sa-sub",children:P.sub})]})},P.num))}),p&&o.jsx("p",{className:"aa-err",children:p}),o.jsxs("div",{className:"sa-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>s(C?e.map(P=>P.num):[]),children:C?"Clear all":"Select all"}),o.jsx("button",{type:"button",className:"btn primary",ref:b,...to(u,!E.length),onClick:I,children:u?"making the share…":E.length===0?"Share":E.length===1?"Share 1 account":`Share ${E.length} accounts`})]})]})})]})}),document.body)}function CU(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((s,l)=>s-l).map(s=>{const l=s===t?"here":n.has(s)?"swap":"free";return{slot:s,kind:l,label:l==="here"?`slot ${s}`:`slot ${s} · ${l}`}})}function TU(e,t,n){if(!(n!=null&&n.ok))return null;const r=Number.isInteger(n.to)?n.to:null;if(r==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const s=n.swapped===!0&&r!==t;return{menuFor:e.menuFor===t?r:s&&e.menuFor===r?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:s?{at:r,displaced:t}:null}}function RU(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function AU(e,t,n){var s;const r=((s=e.find(l=>l.slot===t))==null?void 0:s.kind)??"here";return r==="swap"?{label:"swap",done:"swapped",sends:!0,swaps:!0,title:`Send this account to slot ${t}. That slot is taken, so the two accounts trade places and the one standing there moves to slot ${n}.`}:r==="free"?{label:"move",done:"moved",sends:!0,swaps:!1,title:`Send this account to slot ${t}. That slot is empty, so no other account moves.`}:{label:"move",done:"here",sends:!1,swaps:!1,title:`This account already holds slot ${n}.`}}function MU(e,t){return{label:"save",done:"saved",sends:e!==t,swaps:!1,title:`Switch the active account out once it passes ${e}% of its limit.`}}function nj(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function IU(e){const t=e.filter(u=>!nj(u)),n=e.filter(u=>nj(u)),r=t.length?t:n,s=t.length?n:[],l=r.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of s)l&&u.pct<=l.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:r,rest:s,fuller:c,peak:c??l}}const $U="\0";function lf(e){const t=typeof e.email=="string"?e.email.trim():"";if(!t)return`slot:${e.num}`;const n=typeof e.org=="string"?e.org.trim():"";return`acct:${t}${$U}${n}`}function OU(e,t){const n=lf(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function LU(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(lf)),r=e.filter(s=>n.has(s));return r.length===e.length?e:r}const PU=64;function DU(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function FU(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}const qU=Object.freeze({text:"couldn't reach the deck server",reload:!0}),BU=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function rj(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function zU(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=$u(t.body);return{text:D0(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function sj(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}const aj=15e3,UU=8e3,HU=1800,WU=3e4,Mm=[70,80,85,90,95];function Im(e,t){return NM(t-Math.floor(e/1e3))}function VU(e,t){if(!e)return"";const n=Math.floor(e/1e3)-t;return n<=0?" · due":n<60?` · next in ${n}s`:` · next in ${Math.round(n/60)}m`}function uu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function GU(e,t){const n="The deck can still see this account — its live usage is being read — but claude-swap's own stored copy of the login was rejected, so these numbers stopped updating.";if((e==null?void 0:e.state)==="running")return{text:"resuming…",hint:`${n} The deck is re-capturing it from the login you already have. No sign-in, no switch.`};if((e==null?void 0:e.state)==="failed"){const r=Math.max(1,Math.ceil((e.retryAt/1e3-t)/60)),s=e.reason?`Re-capturing it from the login you already have did not work (${e.reason}).`:"The deck re-captured it from the login you already have, and claude-swap still cannot read it.";return{text:"numbers paused",hint:`${n} ${s} It tries again in ${r}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function KU(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function YU(e){switch(e){case"no_credentials":return{text:"no stored login",hint:"claude-swap holds no credentials for this account, so there is nothing to read its usage with and nothing to switch to. A paired deck that has them sends them on its own; signing in as this account puts them there by hand.",fix:"sign in"};case"relogin_required":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fix:"sign in again"};case"keychain_unavailable":return{text:"keychain unreadable",hint:"This is about the deck, not the account: claude-swap could not open your keychain, so it cannot read any account's stored login. A deck started from a background session cannot reach the keychain at all — start it from a terminal, or let it start at login, and this clears."};case"token_expired":return{text:"token expired",hint:"The access token ran out and the refresh was deferred. The next collection retries."};case"foreign_credential":return{text:"wrong credential",hint:"The live credential belongs to a different account. Switching to this one repairs it."};case null:case void 0:return null;default:return{text:e,hint:`claude-swap reported "${e}" for this account.`}}}function _h(e,t){if(e.staleCopy){const n=GU(e.repair??null,t);return{text:uu(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=YU(e.collector??null);if(!n)return{text:"Not collecting",hint:"claude-swap has collected nothing for this account in over half a day and has not said why. A paired deck holding a working copy of this account will replace it on its own. To do it by hand, sign in as this account from + Add.",fix:null,tone:"quiet",blocksSwitch:!1};const r=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:uu(n.text),hint:n.hint,fix:n.fix?uu(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=KU(e.error);return{text:uu(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function $m(){return o.jsxs("svg",{className:"ap-warn-glyph",width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),o.jsx("path",{d:"M7 5.6v2.9"}),o.jsx("path",{d:"M7 10.3v.05"})]})}function XU(e){return e>=90?"hi":e>=70?"mid":void 0}function ZU(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Mm.includes(t)?[...Mm,t]:Mm].sort((r,s)=>r-s)}function QU({lane:e,nowSec:t,frozen:n}){const r=Math.min(100,Math.max(0,e.pct)),s=n?"var(--muted)":r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",l=e.resetAt&&!n?SM(e.resetAt,t):null;return o.jsxs("div",{className:"ap-lane",children:[o.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),o.jsx("div",{className:"ap-lane-track",children:o.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:s,opacity:r===0||n?.4:1}})}),o.jsxs("span",{className:"ap-lane-pct",style:{color:s},children:[r,"%"]}),o.jsx("span",{className:"ap-lane-reset",title:l?`${e.label} resets in ${l}`:void 0,children:l&&o.jsxs(o.Fragment,{children:[o.jsx("span",{className:"vis-hidden",children:"resets in "}),l]})})]})}function JU({onClose:e,leaving:t}){var xr,Pn,Hs;const[n,r]=w.useState(null),[s,l]=w.useState(null),[c,u]=w.useState(null),[f,p]=w.useState(!1),[h,m]=w.useState(null),[y,v]=w.useState(null),[S,b]=w.useState("accounts"),[_,k]=w.useState(!1),[j,E]=w.useState(null),C=w.useRef(j);C.current=j;const[R,I]=w.useState(()=>Math.floor(Date.now()/1e3)),$=w.useRef(null),[q,B]=w.useState(null),P=(q==null?void 0:q.num)??null,W=w.useRef(q);W.current=q;const[ne,ee]=w.useState(null),[M,X]=w.useState(!1),[V,G]=w.useState(""),[F,L]=w.useState(null),H=w.useRef(0),[D,K]=w.useState(null),[re,z]=w.useState(!1),[Z,U]=w.useState(!1),[ae,le]=w.useState(null),[ge,Ne]=w.useState(null),[Ie,Ge]=w.useState(null),[Pe,ze]=w.useState(null),[Re,st]=w.useState(!1),ue=w.useRef(null),ce=w.useRef(null),[se,be]=w.useState([]),[Le,de]=w.useState(!1),fe=w.useRef(null),Ce=w.useCallback(Q=>Mf(fe.current)?(fe.current=Q,u(Q),!0):!1,[]),pe=w.useCallback(()=>{fe.current=null,u(null)},[]),_e=(Q,De=!1)=>{const Je=lo(c,Q);return{disabled:Je.disabled,"aria-busy":Je.busy||De}},Ye=w.useCallback(Q=>{window.requestAnimationFrame(()=>{var De;if($0(((De=document.activeElement)==null?void 0:De.tagName)??null))for(const Je of h8(Q)){const He=document.querySelector(Je);if(He){He.focus();return}}})},[]),qe=w.useCallback(async(Q=!1)=>{Q&&p(!0);const De=new AbortController,Je=window.setTimeout(()=>De.abort(),WU);try{const[He,tt]=await Promise.all([fetch(`/api/claude-accounts${Q?"?refresh=1":""}`,{signal:De.signal}),fetch("/api/cswap-auto",{signal:De.signal})]);if(He.ok){const gt=await He.json();r(gt),be(At=>LU(At,gt.accounts))}tt.ok&&l(await tt.json());const wt=zU([await rj(He),await rj(tt)]);m(gt=>sj(gt,wt))}catch{m(He=>sj(He,De.signal.aborted?BU:qU))}finally{window.clearTimeout(Je),Q&&p(!1)}},[]),ke=w.useCallback(async(Q,De,Je="panel")=>{if(!Ce(De))return null;const He=Je==="menu"?ee:m;He(null);try{const tt=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),wt=await tt.json().catch(()=>null);return wt!=null&&wt.ok||He({text:D0(wt,"command failed",tt.status),raw:$u(wt)}),wt}catch{return He({text:"server unreachable"}),null}finally{pe()}},[Ce,pe]),Ae=w.useCallback(async(Q,De)=>{if(!Ce(De))return null;m(null),ee(null);try{const Je=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),He=await Je.json().catch(()=>null);return He!=null&&He.ok||ee({text:Ol(He,"command failed",Je.status)}),He}catch{return ee({text:"server unreachable"}),null}finally{pe()}},[Ce,pe]);w.useEffect(()=>(qe(!0),$.current=window.setInterval(()=>qe(!1),aj),()=>{$.current!=null&&window.clearInterval($.current)}),[qe]),w.useEffect(()=>{!(n!=null&&n.ok)||!n.accounts||v(Q=>FU(Q,n.accounts))},[n]),w.useEffect(()=>{const Q=window.setInterval(()=>I(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(Q)},[]);const Ue=((xr=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:xr.value)??"90",Fe=Pe??Ue,Ve=MU(Fe,Ue),rt=(Pn=n==null?void 0:n.accounts)==null?void 0:Pn.find(Q=>Q.active),ut=rt?_h(rt,R):null,ct=(n==null?void 0:n.accounts)??[],yt=rt?ct.filter(Q=>!Q.active):[],It=yt.length?ct.filter(Q=>Q.active):ct,zt=yt.map(Q=>{const De=_h(Q,R);return{key:lf(Q),name:Q.alias??Q.email??`account ${Q.num}`,ready:!Q.disabled&&!(De!=null&&De.blocksSwitch),why:Q.disabled?"held out":De!=null&&De.blocksSwitch?De.text:null,warn:(De==null?void 0:De.tone)==="warn",headroom:Q.headroom}}),Xt=Number(Ue),Ft=(rt==null?void 0:rt.headroom)!=null&&Number.isFinite(Xt)&&100-rt.headroom>=Xt,rn=(s==null?void 0:s.ok)===!0&&(s.enabled||s.external),Se=Q=>Le&&yt.some(De=>De.num===Q)?"ap-rest-list":"ap-scroll",vt=async(Q,De)=>{if(Ce(`switch-${Q}`)){m(null),v(null);try{const He=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:Q})})).json().catch(()=>null);He!=null&&He.ok?v({num:Q,name:De}):m({text:D0(He,"the switch failed"),raw:$u(He),row:Q}),await qe(!0)}catch{m({text:"server unreachable",row:Q})}finally{pe(),Ye(Q)}}},kt=w.useCallback(()=>{B(null),ee(null),L(null),K(null),U(!1)},[]),_n=(Q,De="first")=>{kt(),E(null),Ge(null),B({num:Q,view:"menu",start:De})},Ut=(Q,De)=>{kt(),E(Je=>(Je==null?void 0:Je.anchor)===De?null:{num:Q,anchor:De})},Vn=w.useCallback((Q=!1)=>{var Je;const De=C.current;Q&&De&&((Je=document.getElementById(De.anchor))==null||Je.focus()),E(null)},[]),Vt=()=>{kt(),E(null),b("lan")},$t=w.useRef(S);w.useEffect(()=>{$t.current!==S&&($t.current=S,window.requestAnimationFrame(()=>{var Q;(Q=document.getElementById(S==="lan"?"ap-lan-back":"ap-lan-entry"))==null||Q.focus()}))},[S]),w.useEffect(()=>{n!=null&&n.ok&&k(!0)},[n==null?void 0:n.ok]);const Zt=w.useCallback(Q=>{var He,tt;const De=W.current;if(!De||Q!=null&&De.num!==Q)return;const Je=document.getElementById(`ap-menu-${De.num}`);(Je!=null&&Je.contains(document.activeElement)||$0(((He=document.activeElement)==null?void 0:He.tagName)??null))&&((tt=document.getElementById(`ap-more-${De.num}`))==null||tt.focus()),kt()},[kt]);w.useEffect(()=>{t&&(kt(),E(null))},[t,kt]),w.useEffect(()=>{q&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===q.num)&&kt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===j.num)&&E(null)},[n,q,j,kt]);const Ln=async Q=>{var Je;U(!1);const De=await Ae({action:"share",account:Q},`share-${Q}`);!(De!=null&&De.ok)||((Je=W.current)==null?void 0:Je.num)!==Q||(K({num:Q,blob:De.blob,expiresAt:De.expiresAt}),B({num:Q,view:"share"}))},Ur=async(Q,De)=>{const{commit:Je,alias:He}=DU(V,De);if(Je){const tt=await Ae({action:"alias",account:Q,alias:He},`alias-${Q}`);if(await qe(!0),!(tt!=null&&tt.ok))return}Zt(Q)},xe=async(Q,De)=>{var tt,wt;const Je=await Ae({action:"move",account:Q,slot:De},`move-${Q}`),He=TU({menuFor:((tt=W.current)==null?void 0:tt.num)??null,shareFor:(D==null?void 0:D.num)??null},Q,Je);if(await qe(!0),He){((wt=W.current)==null?void 0:wt.num)===Q&&kt(),L(He.confirmRemove),He.shareFor==null&&(K(null),U(!1)),Ne(He.swapNote);const gt=He.swapNote;gt&&window.setTimeout(()=>Ne(At=>At===gt?null:At),UU),Ge(null),Ye(He.menuFor)}return Je},ir=async(Q,De,Je)=>{if(!Je.sends){Zt(Q);return}await xe(Q,De)},Ns=async(Q,De)=>{if(De.sends){const Je=await ke({action:"setting",key:"autoswitch.threshold",value:Q},"threshold");if(await qe(!0),!(Je!=null&&Je.ok))return;ze(null)}st(!0),window.setTimeout(()=>{var Je;document.activeElement===ce.current&&((Je=ue.current)==null||Je.focus()),st(!1)},HU)},Hr=o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),ma=Q=>{const{shown:De,fuller:Je}=IU(Q.lanes),He=_h(Q,R),tt=Q.active||se.includes(lf(Q)),wt=Q.alias??Q.email??`account ${Q.num}`,gt=Q.alias&&Q.email?`${Q.alias} · ${Q.email}`:wt,At=Q.stale||(He==null?void 0:He.blocksSwitch)===!0,Ct=Je?[...De,Je]:De,Qt=Q.fetchedAt?Im(Q.fetchedAt,R):null;return o.jsxs("li",{className:`ap-account${Q.active?" active":""}`,"aria-current":Q.active?"true":void 0,"data-open":tt?"":void 0,"data-frozen":At?"":void 0,children:[!Q.active&&o.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${Q.num}`,title:gt,"aria-expanded":tt,"aria-controls":tt?`ap-detail-${Q.num}`:void 0,"aria-describedby":[Q.alias&&Q.email?`ap-email-${Q.num}`:null,!tt&&!(He!=null&&He.blocksSwitch)?`ap-quota-${Q.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>be(St=>OU(St,Q)),children:o.jsxs("span",{className:"vis-hidden",children:[wt,", ",tt?"hide details":"details"]})}),o.jsxs("div",{className:"ap-account-head",children:[Q.active?o.jsx("span",{className:"ap-live",title:`Active account · slot ${Q.num}`,children:o.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",Q.num,":"]})}):o.jsx("span",{className:"ap-num",children:Q.num}),Q.alias&&o.jsx("span",{className:"ap-alias",title:Q.alias,children:Q.alias}),o.jsx("span",{className:"ap-email",id:`ap-email-${Q.num}`,title:Q.email??void 0,children:Q.email}),Q.disabled&&o.jsx("span",{className:"ap-held",children:"held out"}),!Q.active&&!Q.disabled&&!(He!=null&&He.blocksSwitch)&&o.jsx("button",{type:"button",className:"ap-switch",..._e(`switch-${Q.num}`),onClick:()=>vt(Q.num,wt),"aria-label":`Switch to ${wt}`,title:`Switch to ${Q.alias??Q.email}`,children:c===`switch-${Q.num}`?"…":"Switch"}),o.jsx("button",{type:"button",id:`ap-more-${Q.num}`,className:"ap-more","aria-label":`More actions for ${Q.email??Q.alias??`account ${Q.num}`}`,"aria-haspopup":"menu","aria-expanded":P===Q.num,"aria-controls":P===Q.num?`ap-menu-${Q.num}`:void 0,title:"More actions",onClick:()=>P===Q.num?Zt():_n(Q.num),onKeyDown:St=>{St.key!=="ArrowDown"&&St.key!=="ArrowUp"||(St.preventDefault(),_n(Q.num,St.key==="ArrowUp"?"last":"first"))},children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[o.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),o.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===Q.num&&o.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),Q.active&&(y==null?void 0:y.num)===Q.num&&o.jsx("p",{className:"ap-switched",children:"Now active. New sessions start on it; ones already running pick it up on their next message, up to about 30 seconds later on macOS."}),(ge==null?void 0:ge.at)===Q.num&&(()=>{const St=ct.find(lr=>lr.num===ge.displaced),br=(St==null?void 0:St.alias)??(St==null?void 0:St.email)??"the account that was there";return o.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${ge.at} was taken, so the two accounts traded places: ${br} now holds slot ${ge.displaced}.`,children:["swapped with slot ",ge.displaced]})})(),He&&o.jsxs("div",{className:"ap-issue-line",children:[o.jsxs("button",{type:"button",id:`ap-issue-${Q.num}`,className:"ap-issue","data-tone":He.tone,"aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`,"aria-controls":(j==null?void 0:j.anchor)===`ap-issue-${Q.num}`?"ap-issue-pop":void 0,onClick:()=>Ut(Q.num,`ap-issue-${Q.num}`),children:[He.tone==="warn"&&o.jsx($m,{}),o.jsx("span",{className:"ap-issue-text",children:He.text})]}),!tt&&o.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),!tt&&!(He!=null&&He.blocksSwitch)&&o.jsxs("p",{className:"ap-quota",id:`ap-quota-${Q.num}`,children:[Ct.length?Ct.map(St=>o.jsxs("span",{className:"ap-q",children:[o.jsx("span",{className:"ap-q-label",children:St.label})," ",o.jsxs("span",{className:"ap-q-pct","data-level":At?void 0:XU(St.pct),children:[Math.round(St.pct),"%"]})]},St.id)):o.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),Q.stale&&!He&&o.jsx("span",{className:"ap-q-age","data-never":Qt?void 0:"",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),tt&&o.jsxs("div",{className:"ap-detail",id:`ap-detail-${Q.num}`,children:[o.jsx("div",{className:"ap-lanes",children:Q.lanes.length?Q.lanes.map(St=>o.jsx(QU,{lane:St,nowSec:R,frozen:At},St.id)):o.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),o.jsx("div",{className:"ap-meta",children:Q.fetchedAt?o.jsxs("span",{className:`ap-age${Q.stale&&!He?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",Im(Q.fetchedAt,R),He!=null&&He.blocksSwitch?"":VU(Q.nextAt,R)]}):o.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},Q.num)},Ss=n!=null&&n.ok&&(s!=null&&s.ok)?o.jsxs("div",{className:"ap-policy-block",children:[o.jsxs("div",{className:"ap-policy",children:[o.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),o.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:o.jsx("select",{ref:ue,"aria-label":"Switch threshold",value:Fe,..._e("threshold"),onChange:Q=>ze(Q.target.value),children:ZU(Ue).map(Q=>o.jsxs("option",{value:Q,children:[Q,"%"]},Q))})}),(Ve.sends||Re)&&o.jsx("button",{ref:ce,type:"button",className:"ap-manage-btn",..._e("threshold"),title:Ve.title,onClick:()=>Ns(Fe,Ve),children:Re&&!Ve.sends?Ve.done:Ve.label}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":s.enabled,"aria-label":"Auto-switch",..._e("enable"),onClick:()=>ke({action:"enable",enabled:!s.enabled},"enable").then(()=>qe(!0)),title:s.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:o.jsx("span",{className:"switch-knob"})})]}),s.external&&o.jsxs("p",{className:"ap-auto-note",children:[o.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",o.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",s.enabled?" — this toggle takes over when you stop it.":"."]})]}):null;return o.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[S==="accounts"&&o.jsxs("div",{className:"ap-header",children:[o.jsx("h2",{children:"Claude accounts"}),o.jsxs("div",{className:"ap-header-right",children:[o.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>X(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:o.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((Hs=n==null?void 0:n.accounts)==null?void 0:Hs.length)??0)>0&&o.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>z(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${hn} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),o.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),o.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>qe(!0),..._e("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),o.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),Hr]})]}),S==="accounts"&&o.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?o.jsxs("div",{className:"ap-empty",role:"alert",children:[o.jsx("span",{title:h.raw||void 0,children:h.text}),o.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",aj/1e3," seconds."]}),o.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>qe(!0),children:f?"trying…":"try again"})]}):o.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?o.jsxs(o.Fragment,{children:[rt&&(ut==null?void 0:ut.tone)==="warn"&&o.jsxs("div",{className:"ap-notice",children:[o.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)==="ap-notice","aria-controls":(j==null?void 0:j.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>Ut(rt.num,"ap-notice"),children:[o.jsx($m,{}),o.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),ut.fix&&o.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>X(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),o.jsx("ul",{className:"ap-list",children:It.map(ma)}),yt.length>0&&o.jsx(SU,{peers:zt,strained:Ft,armed:rn,threshold:s!=null&&s.ok?Ue:null,open:Le,onToggle:()=>de(Q=>!Q)}),yt.length>0&&Le&&o.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[o.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",children:yt.map(ma)}),Ss]}),yt.length===0&&Ss,h&&h.row==null&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),q&&(()=>{var He;const Q=(He=n.accounts)==null?void 0:He.find(tt=>tt.num===q.num);if(!Q)return null;const De=`ap-pop-title-${Q.num}`,Je=ne&&o.jsx("p",{className:"ap-pop-error",role:"alert",title:ne.raw||void 0,children:ne.text});return o.jsxs(O0,{anchorId:`ap-more-${Q.num}`,boundaryId:Se(Q.num),id:`ap-menu-${Q.num}`,className:"ap-pop",role:q.view==="menu"?"menu":"dialog",labelledBy:q.view==="menu"?`ap-more-${Q.num}`:De,start:q.start,onClose:kt,children:[q.view==="menu"&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{G(Q.alias??""),ee(null),B({num:Q.num,view:"rename"})},children:"Rename"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{Ge(null),ee(null),B({num:Q.num,view:"move"})},children:"Move to slot…"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",..._e(`share-${Q.num}`),title:`Copy this account to another ${hn}. Anyone who has the text can use the account — treat it as the password. The other deck stops accepting it after 10 minutes; that does not make an escaped copy safe.`,onClick:()=>Ln(Q.num),children:c===`share-${Q.num}`?"Sharing…":"Share"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",title:"See how much this account worked in each project",onClick:()=>{le(Q.num),Zt(Q.num)},children:"Projects"}),(((s==null?void 0:s.enabled)||(s==null?void 0:s.external))&&!Q.active||Q.disabled)&&o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",..._e(`rot-${Q.num}`),title:Q.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>ke({action:"account",account:Q.num,enabled:Q.disabled},`rot-${Q.num}`,"menu").then(tt=>{qe(!0),tt!=null&&tt.ok&&Zt(Q.num)}),children:Q.disabled?"Put back in rotation":"Hold out of rotation"}),o.jsx("div",{role:"separator",className:"ap-menu-sep"}),o.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${F===Q.num?" armed":""}`,..._e(`rm-${Q.num}`),"aria-label":F===Q.num?"Confirm remove":void 0,title:F===Q.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{const tt=Date.now(),wt=Au({armedFor:F,target:Q.num,armedAt:H.current,now:tt,gapMs:Ou});if(wt==="arm"){L(Q.num),H.current=tt,window.setTimeout(()=>L(gt=>gt===Q.num?null:gt),4e3);return}wt!=="ignore"&&(L(null),Ae({action:"remove",account:Q.num},`rm-${Q.num}`).then(gt=>{var At;qe(!0),gt!=null&&gt.ok&&(((At=W.current)==null?void 0:At.num)===Q.num&&kt(),Ye(null))}))},children:c===`rm-${Q.num}`?"Removing…":F===Q.num?"Confirm":"Remove"}),Je]}),q.view==="rename"&&o.jsxs("form",{className:"ap-pop-form",onSubmit:tt=>{tt.preventDefault(),Ur(Q.num,Q.alias)},children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-alias-${Q.num}`,children:"Rename account"}),o.jsx("input",{id:`ap-alias-${Q.num}`,className:"ap-manage-input",type:"text",value:V,onChange:tt=>G(tt.target.value),maxLength:PU,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:tt=>tt.currentTarget.select()}),Je,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"submit",className:"btn primary",..._e(`alias-${Q.num}`),title:"A short name to show instead of the email",children:c===`alias-${Q.num}`?"…":"Save"})]})]}),q.view==="move"&&(()=>{const tt=CU((n.accounts??[]).map(At=>At.num),Q.num),wt=RU(tt,Ie,Q.num),gt=AU(tt,wt,Q.num);return o.jsxs("div",{className:"ap-pop-form",children:[o.jsx("label",{className:"ap-pop-title",id:De,htmlFor:`ap-slot-${Q.num}`,children:"Move to slot"}),o.jsx("span",{className:"ap-field",children:o.jsx("select",{id:`ap-slot-${Q.num}`,value:String(wt),..._e(`move-${Q.num}`),onChange:At=>Ge(Number(At.target.value)),autoFocus:!0,children:tt.map(At=>o.jsx("option",{value:At.slot,children:At.label},At.slot))})}),Je,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Cancel"}),o.jsx("button",{type:"button",className:"btn primary",..._e(`move-${Q.num}`),title:gt.title,onClick:()=>ir(Q.num,wt,gt),children:c===`move-${Q.num}`?"…":uu(gt.label)})]})]})})(),q.view==="share"&&(D==null?void 0:D.num)===Q.num&&(()=>{const tt=HM(D.expiresAt,R),wt=tt.tone==="gone";return o.jsxs("div",{className:`ap-pop-form ap-share${wt?" expired":""}`,children:[o.jsx("p",{className:"ap-pop-title",id:De,children:"Share account"}),o.jsx("code",{className:"ap-share-blob",children:D.blob}),o.jsxs("p",{className:"ap-pop-note",title:"This text is the account's password. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the login itself is in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign the account out and back in.",children:[o.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",o.jsx("span",{className:`ap-share-expiry ${tt.tone}`,children:tt.text})]}),Je,o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Zt(),children:"Done"}),o.jsx("button",{type:"button",className:"btn primary",..._e(`share-${Q.num}`),autoFocus:!0,onClick:async()=>{if(wt){await Ln(Q.num);return}await yi(D.blob)&&(U(!0),window.setTimeout(()=>U(!1),1800))},children:wt?"Make a new share":Z?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var Je;const Q=(Je=n.accounts)==null?void 0:Je.find(He=>He.num===j.num),De=Q?_h(Q,R):null;return!Q||!De?null:o.jsx(O0,{anchorId:j.anchor,boundaryId:j.anchor==="ap-notice"?"ap-scroll":Se(Q.num),id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>Vn(),children:o.jsxs("div",{className:"ap-pop-form",children:[o.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":De.tone,children:[De.tone==="warn"&&o.jsx($m,{}),De.text]}),o.jsx("p",{className:"ap-pop-note ap-issue-hint",children:De.hint}),o.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[o.jsx("span",{className:"ap-issue-who",children:Q.alias??Q.email??`account ${Q.num}`})," · ",Q.fetchedAt?`last collected ${Im(Q.fetchedAt,R)}`:"never collected"]}),o.jsxs("div",{className:"ap-pop-actions",children:[o.jsx("button",{type:"button",className:"btn",onClick:()=>Vn(!0),children:"Done"}),De.fix&&o.jsx("button",{type:"button",className:"btn primary",onClick:()=>{Vn(!0),X(!0)},title:"Open the sign-in dialog. Signing in as this account puts its login back in this slot — it keeps its slot, its alias and its history.",children:De.fix})]})]})})})()]}):o.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"claude-swap isn't installed."}),o.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&o.jsx("code",{className:"ap-cmd",children:n.hint}),o.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",o.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"No accounts added yet."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",o.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):o.jsxs(o.Fragment,{children:[o.jsx("span",{children:"Couldn't read the account store."}),o.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),_&&o.jsx(kU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({key:`${String(Q.email??"").trim().toLowerCase()}@@${Q.orgUuid??""}`,email:Q.email??"",alive:Q.alive===!0,shareable:Q.collector==="ok"||Q.collector==null&&!Q.active})),onChanged:()=>qe(!0),view:S==="lan",onOpen:Vt,onBack:()=>b("accounts"),closeButton:Hr}),M&&o.jsx(gz,{onClose:()=>X(!1),onChanged:()=>qe(!0)}),re&&o.jsx(EU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({num:Q.num,email:Q.email,alias:Q.alias,org:Q.org})),onClose:()=>z(!1),copyText:yi}),ae!=null&&(()=>{const Q=((n==null?void 0:n.accounts)??[]).find(De=>De.num===ae);return Q?o.jsx(LB,{num:Q.num,name:Q.alias??Q.email??`account ${Q.num}`,onClose:()=>le(null)}):(le(null),null)})()]})}const eH=3e4;function tH({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function nH({bundle:e,running:t,pending:n,lastTried:r}){return t?tH({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function rH(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function sH({asked:e,reported:t}){return t?t!==e:!1}function QM(e){const t=e.thresholdMs??eH;return!e.enabled||e.kind!=="restart"||!e.canRestart||!e.noticeOpen||!e.visible||e.busy?null:e.idleSince==null||e.now<e.idleSince?t:Math.max(0,t-(e.now-e.idleSince))}function aH(e){const t=Math.max(0,Math.ceil(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function oH(e,t){return e?t==null?"auto when idle":`auto in ${aH(t)}`:"auto-restart off"}function oj(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function iH(e){return e<=0?{label:"Restart now",clause:"nothing is running"}:{label:"Restart anyway",clause:`${e===1?"1 agent is running":`${e} agents are running`} — their events during the restart are lost`}}function lH(e){const t=QM(e);return t==null?{idleSince:null,restart:!1,remainingMs:null}:e.idleSince==null||e.now<e.idleSince?{idleSince:e.now,restart:!1,remainingMs:t}:{idleSince:e.idleSince,restart:t===0,remainingMs:t}}function Wb(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var Om,ij;function cH(){if(ij)return Om;ij=1;function e(){this.__data__=[],this.size=0}return Om=e,Om}var Lm,lj;function sc(){if(lj)return Lm;lj=1;function e(t,n){return t===n||t!==t&&n!==n}return Lm=e,Lm}var Pm,cj;function Of(){if(cj)return Pm;cj=1;var e=sc();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return Pm=t,Pm}var Dm,uj;function uH(){if(uj)return Dm;uj=1;var e=Of(),t=Array.prototype,n=t.splice;function r(s){var l=this.__data__,c=e(l,s);if(c<0)return!1;var u=l.length-1;return c==u?l.pop():n.call(l,c,1),--this.size,!0}return Dm=r,Dm}var Fm,dj;function dH(){if(dj)return Fm;dj=1;var e=Of();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Fm=t,Fm}var qm,hj;function hH(){if(hj)return qm;hj=1;var e=Of();function t(n){return e(this.__data__,n)>-1}return qm=t,qm}var Bm,fj;function fH(){if(fj)return Bm;fj=1;var e=Of();function t(n,r){var s=this.__data__,l=e(s,n);return l<0?(++this.size,s.push([n,r])):s[l][1]=r,this}return Bm=t,Bm}var zm,pj;function Lf(){if(pj)return zm;pj=1;var e=cH(),t=uH(),n=dH(),r=hH(),s=fH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,zm=l,zm}var Um,mj;function pH(){if(mj)return Um;mj=1;var e=Lf();function t(){this.__data__=new e,this.size=0}return Um=t,Um}var Hm,gj;function mH(){if(gj)return Hm;gj=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Hm=e,Hm}var Wm,yj;function gH(){if(yj)return Wm;yj=1;function e(t){return this.__data__.get(t)}return Wm=e,Wm}var Vm,wj;function yH(){if(wj)return Vm;wj=1;function e(t){return this.__data__.has(t)}return Vm=e,Vm}var Gm,vj;function JM(){if(vj)return Gm;vj=1;var e=typeof rh=="object"&&rh&&rh.Object===Object&&rh;return Gm=e,Gm}var Km,xj;function ks(){if(xj)return Km;xj=1;var e=JM(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Km=n,Km}var Ym,bj;function ac(){if(bj)return Ym;bj=1;var e=ks(),t=e.Symbol;return Ym=t,Ym}var Xm,kj;function wH(){if(kj)return Xm;kj=1;var e=ac(),t=Object.prototype,n=t.hasOwnProperty,r=t.toString,s=e?e.toStringTag:void 0;function l(c){var u=n.call(c,s),f=c[s];try{c[s]=void 0;var p=!0}catch{}var h=r.call(c);return p&&(u?c[s]=f:delete c[s]),h}return Xm=l,Xm}var Zm,Nj;function vH(){if(Nj)return Zm;Nj=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Zm=n,Zm}var Qm,Sj;function Si(){if(Sj)return Qm;Sj=1;var e=ac(),t=wH(),n=vH(),r="[object Null]",s="[object Undefined]",l=e?e.toStringTag:void 0;function c(u){return u==null?u===void 0?s:r:l&&l in Object(u)?t(u):n(u)}return Qm=c,Qm}var Jm,jj;function Br(){if(jj)return Jm;jj=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return Jm=e,Jm}var eg,_j;function Vu(){if(_j)return eg;_j=1;var e=Si(),t=Br(),n="[object AsyncFunction]",r="[object Function]",s="[object GeneratorFunction]",l="[object Proxy]";function c(u){if(!t(u))return!1;var f=e(u);return f==r||f==s||f==n||f==l}return eg=c,eg}var tg,Ej;function xH(){if(Ej)return tg;Ej=1;var e=ks(),t=e["__core-js_shared__"];return tg=t,tg}var ng,Cj;function bH(){if(Cj)return ng;Cj=1;var e=xH(),t=(function(){var r=/[^.]+$/.exec(e&&e.keys&&e.keys.IE_PROTO||"");return r?"Symbol(src)_1."+r:""})();function n(r){return!!t&&t in r}return ng=n,ng}var rg,Tj;function eI(){if(Tj)return rg;Tj=1;var e=Function.prototype,t=e.toString;function n(r){if(r!=null){try{return t.call(r)}catch{}try{return r+""}catch{}}return""}return rg=n,rg}var sg,Rj;function kH(){if(Rj)return sg;Rj=1;var e=Vu(),t=bH(),n=Br(),r=eI(),s=/[\\^$.*+?()[\]{}|]/g,l=/^\[object .+?Constructor\]$/,c=Function.prototype,u=Object.prototype,f=c.toString,p=u.hasOwnProperty,h=RegExp("^"+f.call(p).replace(s,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function m(y){if(!n(y)||t(y))return!1;var v=e(y)?h:l;return v.test(r(y))}return sg=m,sg}var ag,Aj;function NH(){if(Aj)return ag;Aj=1;function e(t,n){return t==null?void 0:t[n]}return ag=e,ag}var og,Mj;function ji(){if(Mj)return og;Mj=1;var e=kH(),t=NH();function n(r,s){var l=t(r,s);return e(l)?l:void 0}return og=n,og}var ig,Ij;function Vb(){if(Ij)return ig;Ij=1;var e=ji(),t=ks(),n=e(t,"Map");return ig=n,ig}var lg,$j;function Pf(){if($j)return lg;$j=1;var e=ji(),t=e(Object,"create");return lg=t,lg}var cg,Oj;function SH(){if(Oj)return cg;Oj=1;var e=Pf();function t(){this.__data__=e?e(null):{},this.size=0}return cg=t,cg}var ug,Lj;function jH(){if(Lj)return ug;Lj=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return ug=e,ug}var dg,Pj;function _H(){if(Pj)return dg;Pj=1;var e=Pf(),t="__lodash_hash_undefined__",n=Object.prototype,r=n.hasOwnProperty;function s(l){var c=this.__data__;if(e){var u=c[l];return u===t?void 0:u}return r.call(c,l)?c[l]:void 0}return dg=s,dg}var hg,Dj;function EH(){if(Dj)return hg;Dj=1;var e=Pf(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var l=this.__data__;return e?l[s]!==void 0:n.call(l,s)}return hg=r,hg}var fg,Fj;function CH(){if(Fj)return fg;Fj=1;var e=Pf(),t="__lodash_hash_undefined__";function n(r,s){var l=this.__data__;return this.size+=this.has(r)?0:1,l[r]=e&&s===void 0?t:s,this}return fg=n,fg}var pg,qj;function TH(){if(qj)return pg;qj=1;var e=SH(),t=jH(),n=_H(),r=EH(),s=CH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,pg=l,pg}var mg,Bj;function RH(){if(Bj)return mg;Bj=1;var e=TH(),t=Lf(),n=Vb();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return mg=r,mg}var gg,zj;function AH(){if(zj)return gg;zj=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return gg=e,gg}var yg,Uj;function Df(){if(Uj)return yg;Uj=1;var e=AH();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return yg=t,yg}var wg,Hj;function MH(){if(Hj)return wg;Hj=1;var e=Df();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return wg=t,wg}var vg,Wj;function IH(){if(Wj)return vg;Wj=1;var e=Df();function t(n){return e(this,n).get(n)}return vg=t,vg}var xg,Vj;function $H(){if(Vj)return xg;Vj=1;var e=Df();function t(n){return e(this,n).has(n)}return xg=t,xg}var bg,Gj;function OH(){if(Gj)return bg;Gj=1;var e=Df();function t(n,r){var s=e(this,n),l=s.size;return s.set(n,r),this.size+=s.size==l?0:1,this}return bg=t,bg}var kg,Kj;function Gb(){if(Kj)return kg;Kj=1;var e=RH(),t=MH(),n=IH(),r=$H(),s=OH();function l(c){var u=-1,f=c==null?0:c.length;for(this.clear();++u<f;){var p=c[u];this.set(p[0],p[1])}}return l.prototype.clear=e,l.prototype.delete=t,l.prototype.get=n,l.prototype.has=r,l.prototype.set=s,kg=l,kg}var Ng,Yj;function LH(){if(Yj)return Ng;Yj=1;var e=Lf(),t=Vb(),n=Gb(),r=200;function s(l,c){var u=this.__data__;if(u instanceof e){var f=u.__data__;if(!t||f.length<r-1)return f.push([l,c]),this.size=++u.size,this;u=this.__data__=new n(f)}return u.set(l,c),this.size=u.size,this}return Ng=s,Ng}var Sg,Xj;function Ff(){if(Xj)return Sg;Xj=1;var e=Lf(),t=pH(),n=mH(),r=gH(),s=yH(),l=LH();function c(u){var f=this.__data__=new e(u);this.size=f.size}return c.prototype.clear=t,c.prototype.delete=n,c.prototype.get=r,c.prototype.has=s,c.prototype.set=l,Sg=c,Sg}var jg,Zj;function Kb(){if(Zj)return jg;Zj=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s&&n(t[r],r,t)!==!1;);return t}return jg=e,jg}var _g,Qj;function tI(){if(Qj)return _g;Qj=1;var e=ji(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return _g=t,_g}var Eg,Jj;function qf(){if(Jj)return Eg;Jj=1;var e=tI();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Eg=t,Eg}var Cg,e_;function Bf(){if(e_)return Cg;e_=1;var e=qf(),t=sc(),n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u){var f=l[c];(!(r.call(l,c)&&t(f,u))||u===void 0&&!(c in l))&&e(l,c,u)}return Cg=s,Cg}var Tg,t_;function Gu(){if(t_)return Tg;t_=1;var e=Bf(),t=qf();function n(r,s,l,c){var u=!l;l||(l={});for(var f=-1,p=s.length;++f<p;){var h=s[f],m=c?c(l[h],r[h],h,l,r):void 0;m===void 0&&(m=r[h]),u?t(l,h,m):e(l,h,m)}return l}return Tg=n,Tg}var Rg,n_;function PH(){if(n_)return Rg;n_=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Rg=e,Rg}var Ag,r_;function Us(){if(r_)return Ag;r_=1;function e(t){return t!=null&&typeof t=="object"}return Ag=e,Ag}var Mg,s_;function DH(){if(s_)return Mg;s_=1;var e=Si(),t=Us(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Mg=r,Mg}var Ig,a_;function Ku(){if(a_)return Ig;a_=1;var e=DH(),t=Us(),n=Object.prototype,r=n.hasOwnProperty,s=n.propertyIsEnumerable,l=e((function(){return arguments})())?e:function(c){return t(c)&&r.call(c,"callee")&&!s.call(c,"callee")};return Ig=l,Ig}var $g,o_;function nn(){if(o_)return $g;o_=1;var e=Array.isArray;return $g=e,$g}var du={exports:{}},Og,i_;function FH(){if(i_)return Og;i_=1;function e(){return!1}return Og=e,Og}du.exports;var l_;function oc(){return l_||(l_=1,(function(e,t){var n=ks(),r=FH(),s=t&&!t.nodeType&&t,l=s&&!0&&e&&!e.nodeType&&e,c=l&&l.exports===s,u=c?n.Buffer:void 0,f=u?u.isBuffer:void 0,p=f||r;e.exports=p})(du,du.exports)),du.exports}var Lg,c_;function zf(){if(c_)return Lg;c_=1;var e=9007199254740991,t=/^(?:0|[1-9]\d*)$/;function n(r,s){var l=typeof r;return s=s??e,!!s&&(l=="number"||l!="symbol"&&t.test(r))&&r>-1&&r%1==0&&r<s}return Lg=n,Lg}var Pg,u_;function Yb(){if(u_)return Pg;u_=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return Pg=t,Pg}var Dg,d_;function qH(){if(d_)return Dg;d_=1;var e=Si(),t=Yb(),n=Us(),r="[object Arguments]",s="[object Array]",l="[object Boolean]",c="[object Date]",u="[object Error]",f="[object Function]",p="[object Map]",h="[object Number]",m="[object Object]",y="[object RegExp]",v="[object Set]",S="[object String]",b="[object WeakMap]",_="[object ArrayBuffer]",k="[object DataView]",j="[object Float32Array]",E="[object Float64Array]",C="[object Int8Array]",R="[object Int16Array]",I="[object Int32Array]",$="[object Uint8Array]",q="[object Uint8ClampedArray]",B="[object Uint16Array]",P="[object Uint32Array]",W={};W[j]=W[E]=W[C]=W[R]=W[I]=W[$]=W[q]=W[B]=W[P]=!0,W[r]=W[s]=W[_]=W[l]=W[k]=W[c]=W[u]=W[f]=W[p]=W[h]=W[m]=W[y]=W[v]=W[S]=W[b]=!1;function ne(ee){return n(ee)&&t(ee.length)&&!!W[e(ee)]}return Dg=ne,Dg}var Fg,h_;function Uf(){if(h_)return Fg;h_=1;function e(t){return function(n){return t(n)}}return Fg=e,Fg}var hu={exports:{}};hu.exports;var f_;function Xb(){return f_||(f_=1,(function(e,t){var n=JM(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l&&n.process,u=(function(){try{var f=s&&s.require&&s.require("util").types;return f||c&&c.binding&&c.binding("util")}catch{}})();e.exports=u})(hu,hu.exports)),hu.exports}var qg,p_;function Yu(){if(p_)return qg;p_=1;var e=qH(),t=Uf(),n=Xb(),r=n&&n.isTypedArray,s=r?t(r):e;return qg=s,qg}var Bg,m_;function nI(){if(m_)return Bg;m_=1;var e=PH(),t=Ku(),n=nn(),r=oc(),s=zf(),l=Yu(),c=Object.prototype,u=c.hasOwnProperty;function f(p,h){var m=n(p),y=!m&&t(p),v=!m&&!y&&r(p),S=!m&&!y&&!v&&l(p),b=m||y||v||S,_=b?e(p.length,String):[],k=_.length;for(var j in p)(h||u.call(p,j))&&!(b&&(j=="length"||v&&(j=="offset"||j=="parent")||S&&(j=="buffer"||j=="byteLength"||j=="byteOffset")||s(j,k)))&&_.push(j);return _}return Bg=f,Bg}var zg,g_;function Hf(){if(g_)return zg;g_=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return zg=t,zg}var Ug,y_;function rI(){if(y_)return Ug;y_=1;function e(t,n){return function(r){return t(n(r))}}return Ug=e,Ug}var Hg,w_;function BH(){if(w_)return Hg;w_=1;var e=rI(),t=e(Object.keys,Object);return Hg=t,Hg}var Wg,v_;function Zb(){if(v_)return Wg;v_=1;var e=Hf(),t=BH(),n=Object.prototype,r=n.hasOwnProperty;function s(l){if(!e(l))return t(l);var c=[];for(var u in Object(l))r.call(l,u)&&u!="constructor"&&c.push(u);return c}return Wg=s,Wg}var Vg,x_;function fa(){if(x_)return Vg;x_=1;var e=Vu(),t=Yb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Vg=n,Vg}var Gg,b_;function co(){if(b_)return Gg;b_=1;var e=nI(),t=Zb(),n=fa();function r(s){return n(s)?e(s):t(s)}return Gg=r,Gg}var Kg,k_;function zH(){if(k_)return Kg;k_=1;var e=Gu(),t=co();function n(r,s){return r&&e(s,t(s),r)}return Kg=n,Kg}var Yg,N_;function UH(){if(N_)return Yg;N_=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Yg=e,Yg}var Xg,S_;function HH(){if(S_)return Xg;S_=1;var e=Br(),t=Hf(),n=UH(),r=Object.prototype,s=r.hasOwnProperty;function l(c){if(!e(c))return n(c);var u=t(c),f=[];for(var p in c)p=="constructor"&&(u||!s.call(c,p))||f.push(p);return f}return Xg=l,Xg}var Zg,j_;function _i(){if(j_)return Zg;j_=1;var e=nI(),t=HH(),n=fa();function r(s){return n(s)?e(s,!0):t(s)}return Zg=r,Zg}var Qg,__;function WH(){if(__)return Qg;__=1;var e=Gu(),t=_i();function n(r,s){return r&&e(s,t(s),r)}return Qg=n,Qg}var fu={exports:{}};fu.exports;var E_;function sI(){return E_||(E_=1,(function(e,t){var n=ks(),r=t&&!t.nodeType&&t,s=r&&!0&&e&&!e.nodeType&&e,l=s&&s.exports===r,c=l?n.Buffer:void 0,u=c?c.allocUnsafe:void 0;function f(p,h){if(h)return p.slice();var m=p.length,y=u?u(m):new p.constructor(m);return p.copy(y),y}e.exports=f})(fu,fu.exports)),fu.exports}var Jg,C_;function aI(){if(C_)return Jg;C_=1;function e(t,n){var r=-1,s=t.length;for(n||(n=Array(s));++r<s;)n[r]=t[r];return n}return Jg=e,Jg}var ey,T_;function oI(){if(T_)return ey;T_=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=0,c=[];++r<s;){var u=t[r];n(u,r,t)&&(c[l++]=u)}return c}return ey=e,ey}var ty,R_;function iI(){if(R_)return ty;R_=1;function e(){return[]}return ty=e,ty}var ny,A_;function Qb(){if(A_)return ny;A_=1;var e=oI(),t=iI(),n=Object.prototype,r=n.propertyIsEnumerable,s=Object.getOwnPropertySymbols,l=s?function(c){return c==null?[]:(c=Object(c),e(s(c),function(u){return r.call(c,u)}))}:t;return ny=l,ny}var ry,M_;function VH(){if(M_)return ry;M_=1;var e=Gu(),t=Qb();function n(r,s){return e(r,t(r),s)}return ry=n,ry}var sy,I_;function Jb(){if(I_)return sy;I_=1;function e(t,n){for(var r=-1,s=n.length,l=t.length;++r<s;)t[l+r]=n[r];return t}return sy=e,sy}var ay,$_;function Wf(){if($_)return ay;$_=1;var e=rI(),t=e(Object.getPrototypeOf,Object);return ay=t,ay}var oy,O_;function lI(){if(O_)return oy;O_=1;var e=Jb(),t=Wf(),n=Qb(),r=iI(),s=Object.getOwnPropertySymbols,l=s?function(c){for(var u=[];c;)e(u,n(c)),c=t(c);return u}:r;return oy=l,oy}var iy,L_;function GH(){if(L_)return iy;L_=1;var e=Gu(),t=lI();function n(r,s){return e(r,t(r),s)}return iy=n,iy}var ly,P_;function cI(){if(P_)return ly;P_=1;var e=Jb(),t=nn();function n(r,s,l){var c=s(r);return t(r)?c:e(c,l(r))}return ly=n,ly}var cy,D_;function uI(){if(D_)return cy;D_=1;var e=cI(),t=Qb(),n=co();function r(s){return e(s,n,t)}return cy=r,cy}var uy,F_;function KH(){if(F_)return uy;F_=1;var e=cI(),t=lI(),n=_i();function r(s){return e(s,n,t)}return uy=r,uy}var dy,q_;function YH(){if(q_)return dy;q_=1;var e=ji(),t=ks(),n=e(t,"DataView");return dy=n,dy}var hy,B_;function XH(){if(B_)return hy;B_=1;var e=ji(),t=ks(),n=e(t,"Promise");return hy=n,hy}var fy,z_;function dI(){if(z_)return fy;z_=1;var e=ji(),t=ks(),n=e(t,"Set");return fy=n,fy}var py,U_;function ZH(){if(U_)return py;U_=1;var e=ji(),t=ks(),n=e(t,"WeakMap");return py=n,py}var my,H_;function ic(){if(H_)return my;H_=1;var e=YH(),t=Vb(),n=XH(),r=dI(),s=ZH(),l=Si(),c=eI(),u="[object Map]",f="[object Object]",p="[object Promise]",h="[object Set]",m="[object WeakMap]",y="[object DataView]",v=c(e),S=c(t),b=c(n),_=c(r),k=c(s),j=l;return(e&&j(new e(new ArrayBuffer(1)))!=y||t&&j(new t)!=u||n&&j(n.resolve())!=p||r&&j(new r)!=h||s&&j(new s)!=m)&&(j=function(E){var C=l(E),R=C==f?E.constructor:void 0,I=R?c(R):"";if(I)switch(I){case v:return y;case S:return u;case b:return p;case _:return h;case k:return m}return C}),my=j,my}var gy,W_;function QH(){if(W_)return gy;W_=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r){var s=r.length,l=new r.constructor(s);return s&&typeof r[0]=="string"&&t.call(r,"index")&&(l.index=r.index,l.input=r.input),l}return gy=n,gy}var yy,V_;function hI(){if(V_)return yy;V_=1;var e=ks(),t=e.Uint8Array;return yy=t,yy}var wy,G_;function ek(){if(G_)return wy;G_=1;var e=hI();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return wy=t,wy}var vy,K_;function JH(){if(K_)return vy;K_=1;var e=ek();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return vy=t,vy}var xy,Y_;function eW(){if(Y_)return xy;Y_=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return xy=t,xy}var by,X_;function tW(){if(X_)return by;X_=1;var e=ac(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return by=r,by}var ky,Z_;function fI(){if(Z_)return ky;Z_=1;var e=ek();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return ky=t,ky}var Ny,Q_;function nW(){if(Q_)return Ny;Q_=1;var e=ek(),t=JH(),n=eW(),r=tW(),s=fI(),l="[object Boolean]",c="[object Date]",u="[object Map]",f="[object Number]",p="[object RegExp]",h="[object Set]",m="[object String]",y="[object Symbol]",v="[object ArrayBuffer]",S="[object DataView]",b="[object Float32Array]",_="[object Float64Array]",k="[object Int8Array]",j="[object Int16Array]",E="[object Int32Array]",C="[object Uint8Array]",R="[object Uint8ClampedArray]",I="[object Uint16Array]",$="[object Uint32Array]";function q(B,P,W){var ne=B.constructor;switch(P){case v:return e(B);case l:case c:return new ne(+B);case S:return t(B,W);case b:case _:case k:case j:case E:case C:case R:case I:case $:return s(B,W);case u:return new ne;case f:case m:return new ne(B);case p:return n(B);case h:return new ne;case y:return r(B)}}return Ny=q,Ny}var Sy,J_;function pI(){if(J_)return Sy;J_=1;var e=Br(),t=Object.create,n=(function(){function r(){}return function(s){if(!e(s))return{};if(t)return t(s);r.prototype=s;var l=new r;return r.prototype=void 0,l}})();return Sy=n,Sy}var jy,eE;function mI(){if(eE)return jy;eE=1;var e=pI(),t=Wf(),n=Hf();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return jy=r,jy}var _y,tE;function rW(){if(tE)return _y;tE=1;var e=ic(),t=Us(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return _y=r,_y}var Ey,nE;function sW(){if(nE)return Ey;nE=1;var e=rW(),t=Uf(),n=Xb(),r=n&&n.isMap,s=r?t(r):e;return Ey=s,Ey}var Cy,rE;function aW(){if(rE)return Cy;rE=1;var e=ic(),t=Us(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return Cy=r,Cy}var Ty,sE;function oW(){if(sE)return Ty;sE=1;var e=aW(),t=Uf(),n=Xb(),r=n&&n.isSet,s=r?t(r):e;return Ty=s,Ty}var Ry,aE;function gI(){if(aE)return Ry;aE=1;var e=Ff(),t=Kb(),n=Bf(),r=zH(),s=WH(),l=sI(),c=aI(),u=VH(),f=GH(),p=uI(),h=KH(),m=ic(),y=QH(),v=nW(),S=mI(),b=nn(),_=oc(),k=sW(),j=Br(),E=oW(),C=co(),R=_i(),I=1,$=2,q=4,B="[object Arguments]",P="[object Array]",W="[object Boolean]",ne="[object Date]",ee="[object Error]",M="[object Function]",X="[object GeneratorFunction]",V="[object Map]",G="[object Number]",F="[object Object]",L="[object RegExp]",H="[object Set]",D="[object String]",K="[object Symbol]",re="[object WeakMap]",z="[object ArrayBuffer]",Z="[object DataView]",U="[object Float32Array]",ae="[object Float64Array]",le="[object Int8Array]",ge="[object Int16Array]",Ne="[object Int32Array]",Ie="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Pe="[object Uint16Array]",ze="[object Uint32Array]",Re={};Re[B]=Re[P]=Re[z]=Re[Z]=Re[W]=Re[ne]=Re[U]=Re[ae]=Re[le]=Re[ge]=Re[Ne]=Re[V]=Re[G]=Re[F]=Re[L]=Re[H]=Re[D]=Re[K]=Re[Ie]=Re[Ge]=Re[Pe]=Re[ze]=!0,Re[ee]=Re[M]=Re[re]=!1;function st(ue,ce,se,be,Le,de){var fe,Ce=ce&I,pe=ce&$,_e=ce&q;if(se&&(fe=Le?se(ue,be,Le,de):se(ue)),fe!==void 0)return fe;if(!j(ue))return ue;var Ye=b(ue);if(Ye){if(fe=y(ue),!Ce)return c(ue,fe)}else{var qe=m(ue),ke=qe==M||qe==X;if(_(ue))return l(ue,Ce);if(qe==F||qe==B||ke&&!Le){if(fe=pe||ke?{}:S(ue),!Ce)return pe?f(ue,s(fe,ue)):u(ue,r(fe,ue))}else{if(!Re[qe])return Le?ue:{};fe=v(ue,qe,Ce)}}de||(de=new e);var Ae=de.get(ue);if(Ae)return Ae;de.set(ue,fe),E(ue)?ue.forEach(function(Ve){fe.add(st(Ve,ce,se,Ve,ue,de))}):k(ue)&&ue.forEach(function(Ve,rt){fe.set(rt,st(Ve,ce,se,rt,ue,de))});var Ue=_e?pe?h:p:pe?R:C,Fe=Ye?void 0:Ue(ue);return t(Fe||ue,function(Ve,rt){Fe&&(rt=Ve,Ve=ue[rt]),n(fe,rt,st(Ve,ce,se,rt,ue,de))}),fe}return Ry=st,Ry}var Ay,oE;function iW(){if(oE)return Ay;oE=1;var e=gI(),t=4;function n(r){return e(r,t)}return Ay=n,Ay}var My,iE;function tk(){if(iE)return My;iE=1;function e(t){return function(){return t}}return My=e,My}var Iy,lE;function lW(){if(lE)return Iy;lE=1;function e(t){return function(n,r,s){for(var l=-1,c=Object(n),u=s(n),f=u.length;f--;){var p=u[t?f:++l];if(r(c[p],p,c)===!1)break}return n}}return Iy=e,Iy}var $y,cE;function nk(){if(cE)return $y;cE=1;var e=lW(),t=e();return $y=t,$y}var Oy,uE;function rk(){if(uE)return Oy;uE=1;var e=nk(),t=co();function n(r,s){return r&&e(r,s,t)}return Oy=n,Oy}var Ly,dE;function cW(){if(dE)return Ly;dE=1;var e=fa();function t(n,r){return function(s,l){if(s==null)return s;if(!e(s))return n(s,l);for(var c=s.length,u=r?c:-1,f=Object(s);(r?u--:++u<c)&&l(f[u],u,f)!==!1;);return s}}return Ly=t,Ly}var Py,hE;function Vf(){if(hE)return Py;hE=1;var e=rk(),t=cW(),n=t(e);return Py=n,Py}var Dy,fE;function Ei(){if(fE)return Dy;fE=1;function e(t){return t}return Dy=e,Dy}var Fy,pE;function yI(){if(pE)return Fy;pE=1;var e=Ei();function t(n){return typeof n=="function"?n:e}return Fy=t,Fy}var qy,mE;function wI(){if(mE)return qy;mE=1;var e=Kb(),t=Vf(),n=yI(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c))}return qy=s,qy}var By,gE;function vI(){return gE||(gE=1,By=wI()),By}var zy,yE;function uW(){if(yE)return zy;yE=1;var e=Vf();function t(n,r){var s=[];return e(n,function(l,c,u){r(l,c,u)&&s.push(l)}),s}return zy=t,zy}var Uy,wE;function dW(){if(wE)return Uy;wE=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return Uy=t,Uy}var Hy,vE;function hW(){if(vE)return Hy;vE=1;function e(t){return this.__data__.has(t)}return Hy=e,Hy}var Wy,xE;function xI(){if(xE)return Wy;xE=1;var e=Gb(),t=dW(),n=hW();function r(s){var l=-1,c=s==null?0:s.length;for(this.__data__=new e;++l<c;)this.add(s[l])}return r.prototype.add=r.prototype.push=t,r.prototype.has=n,Wy=r,Wy}var Vy,bE;function fW(){if(bE)return Vy;bE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length;++r<s;)if(n(t[r],r,t))return!0;return!1}return Vy=e,Vy}var Gy,kE;function bI(){if(kE)return Gy;kE=1;function e(t,n){return t.has(n)}return Gy=e,Gy}var Ky,NE;function kI(){if(NE)return Ky;NE=1;var e=xI(),t=fW(),n=bI(),r=1,s=2;function l(c,u,f,p,h,m){var y=f&r,v=c.length,S=u.length;if(v!=S&&!(y&&S>v))return!1;var b=m.get(c),_=m.get(u);if(b&&_)return b==u&&_==c;var k=-1,j=!0,E=f&s?new e:void 0;for(m.set(c,u),m.set(u,c);++k<v;){var C=c[k],R=u[k];if(p)var I=y?p(R,C,k,u,c,m):p(C,R,k,c,u,m);if(I!==void 0){if(I)continue;j=!1;break}if(E){if(!t(u,function($,q){if(!n(E,q)&&(C===$||h(C,$,f,p,m)))return E.push(q)})){j=!1;break}}else if(!(C===R||h(C,R,f,p,m))){j=!1;break}}return m.delete(c),m.delete(u),j}return Ky=l,Ky}var Yy,SE;function pW(){if(SE)return Yy;SE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,l){r[++n]=[l,s]}),r}return Yy=e,Yy}var Xy,jE;function sk(){if(jE)return Xy;jE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return Xy=e,Xy}var Zy,_E;function mW(){if(_E)return Zy;_E=1;var e=ac(),t=hI(),n=sc(),r=kI(),s=pW(),l=sk(),c=1,u=2,f="[object Boolean]",p="[object Date]",h="[object Error]",m="[object Map]",y="[object Number]",v="[object RegExp]",S="[object Set]",b="[object String]",_="[object Symbol]",k="[object ArrayBuffer]",j="[object DataView]",E=e?e.prototype:void 0,C=E?E.valueOf:void 0;function R(I,$,q,B,P,W,ne){switch(q){case j:if(I.byteLength!=$.byteLength||I.byteOffset!=$.byteOffset)return!1;I=I.buffer,$=$.buffer;case k:return!(I.byteLength!=$.byteLength||!W(new t(I),new t($)));case f:case p:case y:return n(+I,+$);case h:return I.name==$.name&&I.message==$.message;case v:case b:return I==$+"";case m:var ee=s;case S:var M=B&c;if(ee||(ee=l),I.size!=$.size&&!M)return!1;var X=ne.get(I);if(X)return X==$;B|=u,ne.set(I,$);var V=r(ee(I),ee($),B,P,W,ne);return ne.delete(I),V;case _:if(C)return C.call(I)==C.call($)}return!1}return Zy=R,Zy}var Qy,EE;function gW(){if(EE)return Qy;EE=1;var e=uI(),t=1,n=Object.prototype,r=n.hasOwnProperty;function s(l,c,u,f,p,h){var m=u&t,y=e(l),v=y.length,S=e(c),b=S.length;if(v!=b&&!m)return!1;for(var _=v;_--;){var k=y[_];if(!(m?k in c:r.call(c,k)))return!1}var j=h.get(l),E=h.get(c);if(j&&E)return j==c&&E==l;var C=!0;h.set(l,c),h.set(c,l);for(var R=m;++_<v;){k=y[_];var I=l[k],$=c[k];if(f)var q=m?f($,I,k,c,l,h):f(I,$,k,l,c,h);if(!(q===void 0?I===$||p(I,$,u,f,h):q)){C=!1;break}R||(R=k=="constructor")}if(C&&!R){var B=l.constructor,P=c.constructor;B!=P&&"constructor"in l&&"constructor"in c&&!(typeof B=="function"&&B instanceof B&&typeof P=="function"&&P instanceof P)&&(C=!1)}return h.delete(l),h.delete(c),C}return Qy=s,Qy}var Jy,CE;function yW(){if(CE)return Jy;CE=1;var e=Ff(),t=kI(),n=mW(),r=gW(),s=ic(),l=nn(),c=oc(),u=Yu(),f=1,p="[object Arguments]",h="[object Array]",m="[object Object]",y=Object.prototype,v=y.hasOwnProperty;function S(b,_,k,j,E,C){var R=l(b),I=l(_),$=R?h:s(b),q=I?h:s(_);$=$==p?m:$,q=q==p?m:q;var B=$==m,P=q==m,W=$==q;if(W&&c(b)){if(!c(_))return!1;R=!0,B=!1}if(W&&!B)return C||(C=new e),R||u(b)?t(b,_,k,j,E,C):n(b,_,$,k,j,E,C);if(!(k&f)){var ne=B&&v.call(b,"__wrapped__"),ee=P&&v.call(_,"__wrapped__");if(ne||ee){var M=ne?b.value():b,X=ee?_.value():_;return C||(C=new e),E(M,X,k,j,C)}}return W?(C||(C=new e),r(b,_,k,j,E,C)):!1}return Jy=S,Jy}var ew,TE;function NI(){if(TE)return ew;TE=1;var e=yW(),t=Us();function n(r,s,l,c,u){return r===s?!0:r==null||s==null||!t(r)&&!t(s)?r!==r&&s!==s:e(r,s,l,c,n,u)}return ew=n,ew}var tw,RE;function wW(){if(RE)return tw;RE=1;var e=Ff(),t=NI(),n=1,r=2;function s(l,c,u,f){var p=u.length,h=p,m=!f;if(l==null)return!h;for(l=Object(l);p--;){var y=u[p];if(m&&y[2]?y[1]!==l[y[0]]:!(y[0]in l))return!1}for(;++p<h;){y=u[p];var v=y[0],S=l[v],b=y[1];if(m&&y[2]){if(S===void 0&&!(v in l))return!1}else{var _=new e;if(f)var k=f(S,b,v,l,c,_);if(!(k===void 0?t(b,S,n|r,f,_):k))return!1}}return!0}return tw=s,tw}var nw,AE;function SI(){if(AE)return nw;AE=1;var e=Br();function t(n){return n===n&&!e(n)}return nw=t,nw}var rw,ME;function vW(){if(ME)return rw;ME=1;var e=SI(),t=co();function n(r){for(var s=t(r),l=s.length;l--;){var c=s[l],u=r[c];s[l]=[c,u,e(u)]}return s}return rw=n,rw}var sw,IE;function jI(){if(IE)return sw;IE=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return sw=e,sw}var aw,$E;function xW(){if($E)return aw;$E=1;var e=wW(),t=vW(),n=jI();function r(s){var l=t(s);return l.length==1&&l[0][2]?n(l[0][0],l[0][1]):function(c){return c===s||e(c,s,l)}}return aw=r,aw}var ow,OE;function lc(){if(OE)return ow;OE=1;var e=Si(),t=Us(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return ow=r,ow}var iw,LE;function ak(){if(LE)return iw;LE=1;var e=nn(),t=lc(),n=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,r=/^\w*$/;function s(l,c){if(e(l))return!1;var u=typeof l;return u=="number"||u=="symbol"||u=="boolean"||l==null||t(l)?!0:r.test(l)||!n.test(l)||c!=null&&l in Object(c)}return iw=s,iw}var lw,PE;function bW(){if(PE)return lw;PE=1;var e=Gb(),t="Expected a function";function n(r,s){if(typeof r!="function"||s!=null&&typeof s!="function")throw new TypeError(t);var l=function(){var c=arguments,u=s?s.apply(this,c):c[0],f=l.cache;if(f.has(u))return f.get(u);var p=r.apply(this,c);return l.cache=f.set(u,p)||f,p};return l.cache=new(n.Cache||e),l}return n.Cache=e,lw=n,lw}var cw,DE;function kW(){if(DE)return cw;DE=1;var e=bW(),t=500;function n(r){var s=e(r,function(c){return l.size===t&&l.clear(),c}),l=s.cache;return s}return cw=n,cw}var uw,FE;function NW(){if(FE)return uw;FE=1;var e=kW(),t=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,n=/\\(\\)?/g,r=e(function(s){var l=[];return s.charCodeAt(0)===46&&l.push(""),s.replace(t,function(c,u,f,p){l.push(f?p.replace(n,"$1"):u||c)}),l});return uw=r,uw}var dw,qE;function Gf(){if(qE)return dw;qE=1;function e(t,n){for(var r=-1,s=t==null?0:t.length,l=Array(s);++r<s;)l[r]=n(t[r],r,t);return l}return dw=e,dw}var hw,BE;function SW(){if(BE)return hw;BE=1;var e=ac(),t=Gf(),n=nn(),r=lc(),s=e?e.prototype:void 0,l=s?s.toString:void 0;function c(u){if(typeof u=="string")return u;if(n(u))return t(u,c)+"";if(r(u))return l?l.call(u):"";var f=u+"";return f=="0"&&1/u==-1/0?"-0":f}return hw=c,hw}var fw,zE;function _I(){if(zE)return fw;zE=1;var e=SW();function t(n){return n==null?"":e(n)}return fw=t,fw}var pw,UE;function Kf(){if(UE)return pw;UE=1;var e=nn(),t=ak(),n=NW(),r=_I();function s(l,c){return e(l)?l:t(l,c)?[l]:n(r(l))}return pw=s,pw}var mw,HE;function Xu(){if(HE)return mw;HE=1;var e=lc();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return mw=t,mw}var gw,WE;function Yf(){if(WE)return gw;WE=1;var e=Kf(),t=Xu();function n(r,s){s=e(s,r);for(var l=0,c=s.length;r!=null&&l<c;)r=r[t(s[l++])];return l&&l==c?r:void 0}return gw=n,gw}var yw,VE;function jW(){if(VE)return yw;VE=1;var e=Yf();function t(n,r,s){var l=n==null?void 0:e(n,r);return l===void 0?s:l}return yw=t,yw}var ww,GE;function _W(){if(GE)return ww;GE=1;function e(t,n){return t!=null&&n in Object(t)}return ww=e,ww}var vw,KE;function EI(){if(KE)return vw;KE=1;var e=Kf(),t=Ku(),n=nn(),r=zf(),s=Yb(),l=Xu();function c(u,f,p){f=e(f,u);for(var h=-1,m=f.length,y=!1;++h<m;){var v=l(f[h]);if(!(y=u!=null&&p(u,v)))break;u=u[v]}return y||++h!=m?y:(m=u==null?0:u.length,!!m&&s(m)&&r(v,m)&&(n(u)||t(u)))}return vw=c,vw}var xw,YE;function CI(){if(YE)return xw;YE=1;var e=_W(),t=EI();function n(r,s){return r!=null&&t(r,s,e)}return xw=n,xw}var bw,XE;function EW(){if(XE)return bw;XE=1;var e=NI(),t=jW(),n=CI(),r=ak(),s=SI(),l=jI(),c=Xu(),u=1,f=2;function p(h,m){return r(h)&&s(m)?l(c(h),m):function(y){var v=t(y,h);return v===void 0&&v===m?n(y,h):e(m,v,u|f)}}return bw=p,bw}var kw,ZE;function TI(){if(ZE)return kw;ZE=1;function e(t){return function(n){return n==null?void 0:n[t]}}return kw=e,kw}var Nw,QE;function CW(){if(QE)return Nw;QE=1;var e=Yf();function t(n){return function(r){return e(r,n)}}return Nw=t,Nw}var Sw,JE;function TW(){if(JE)return Sw;JE=1;var e=TI(),t=CW(),n=ak(),r=Xu();function s(l){return n(l)?e(r(l)):t(l)}return Sw=s,Sw}var jw,eC;function pa(){if(eC)return jw;eC=1;var e=xW(),t=EW(),n=Ei(),r=nn(),s=TW();function l(c){return typeof c=="function"?c:c==null?n:typeof c=="object"?r(c)?t(c[0],c[1]):e(c):s(c)}return jw=l,jw}var _w,tC;function RI(){if(tC)return _w;tC=1;var e=oI(),t=uW(),n=pa(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c,3))}return _w=s,_w}var Ew,nC;function RW(){if(nC)return Ew;nC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Ew=n,Ew}var Cw,rC;function AI(){if(rC)return Cw;rC=1;var e=RW(),t=EI();function n(r,s){return r!=null&&t(r,s,e)}return Cw=n,Cw}var Tw,sC;function AW(){if(sC)return Tw;sC=1;var e=Zb(),t=ic(),n=Ku(),r=nn(),s=fa(),l=oc(),c=Hf(),u=Yu(),f="[object Map]",p="[object Set]",h=Object.prototype,m=h.hasOwnProperty;function y(v){if(v==null)return!0;if(s(v)&&(r(v)||typeof v=="string"||typeof v.splice=="function"||l(v)||u(v)||n(v)))return!v.length;var S=t(v);if(S==f||S==p)return!v.size;if(c(v))return!e(v).length;for(var b in v)if(m.call(v,b))return!1;return!0}return Tw=y,Tw}var Rw,aC;function MI(){if(aC)return Rw;aC=1;function e(t){return t===void 0}return Rw=e,Rw}var Aw,oC;function II(){if(oC)return Aw;oC=1;var e=Vf(),t=fa();function n(r,s){var l=-1,c=t(r)?Array(r.length):[];return e(r,function(u,f,p){c[++l]=s(u,f,p)}),c}return Aw=n,Aw}var Mw,iC;function $I(){if(iC)return Mw;iC=1;var e=Gf(),t=pa(),n=II(),r=nn();function s(l,c){var u=r(l)?e:n;return u(l,t(c,3))}return Mw=s,Mw}var Iw,lC;function MW(){if(lC)return Iw;lC=1;function e(t,n,r,s){var l=-1,c=t==null?0:t.length;for(s&&c&&(r=t[++l]);++l<c;)r=n(r,t[l],l,t);return r}return Iw=e,Iw}var $w,cC;function IW(){if(cC)return $w;cC=1;function e(t,n,r,s,l){return l(t,function(c,u,f){r=s?(s=!1,c):n(r,c,u,f)}),r}return $w=e,$w}var Ow,uC;function OI(){if(uC)return Ow;uC=1;var e=MW(),t=Vf(),n=pa(),r=IW(),s=nn();function l(c,u,f){var p=s(c)?e:r,h=arguments.length<3;return p(c,n(u,4),f,h,t)}return Ow=l,Ow}var Lw,dC;function $W(){if(dC)return Lw;dC=1;var e=Si(),t=nn(),n=Us(),r="[object String]";function s(l){return typeof l=="string"||!t(l)&&n(l)&&e(l)==r}return Lw=s,Lw}var Pw,hC;function OW(){if(hC)return Pw;hC=1;var e=TI(),t=e("length");return Pw=t,Pw}var Dw,fC;function LW(){if(fC)return Dw;fC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="\\u200d",u=RegExp("["+c+e+s+l+"]");function f(p){return u.test(p)}return Dw=f,Dw}var Fw,pC;function PW(){if(pC)return Fw;pC=1;var e="\\ud800-\\udfff",t="\\u0300-\\u036f",n="\\ufe20-\\ufe2f",r="\\u20d0-\\u20ff",s=t+n+r,l="\\ufe0e\\ufe0f",c="["+e+"]",u="["+s+"]",f="\\ud83c[\\udffb-\\udfff]",p="(?:"+u+"|"+f+")",h="[^"+e+"]",m="(?:\\ud83c[\\udde6-\\uddff]){2}",y="[\\ud800-\\udbff][\\udc00-\\udfff]",v="\\u200d",S=p+"?",b="["+l+"]?",_="(?:"+v+"(?:"+[h,m,y].join("|")+")"+b+S+")*",k=b+S+_,j="(?:"+[h+u+"?",u,m,y,c].join("|")+")",E=RegExp(f+"(?="+f+")|"+j+k,"g");function C(R){for(var I=E.lastIndex=0;E.test(R);)++I;return I}return Fw=C,Fw}var qw,mC;function DW(){if(mC)return qw;mC=1;var e=OW(),t=LW(),n=PW();function r(s){return t(s)?n(s):e(s)}return qw=r,qw}var Bw,gC;function FW(){if(gC)return Bw;gC=1;var e=Zb(),t=ic(),n=fa(),r=$W(),s=DW(),l="[object Map]",c="[object Set]";function u(f){if(f==null)return 0;if(n(f))return r(f)?s(f):f.length;var p=t(f);return p==l||p==c?f.size:e(f).length}return Bw=u,Bw}var zw,yC;function qW(){if(yC)return zw;yC=1;var e=Kb(),t=pI(),n=rk(),r=pa(),s=Wf(),l=nn(),c=oc(),u=Vu(),f=Br(),p=Yu();function h(m,y,v){var S=l(m),b=S||c(m)||p(m);if(y=r(y,4),v==null){var _=m&&m.constructor;b?v=S?new _:[]:f(m)?v=u(_)?t(s(m)):{}:v={}}return(b?e:n)(m,function(k,j,E){return y(v,k,j,E)}),v}return zw=h,zw}var Uw,wC;function BW(){if(wC)return Uw;wC=1;var e=ac(),t=Ku(),n=nn(),r=e?e.isConcatSpreadable:void 0;function s(l){return n(l)||t(l)||!!(r&&l&&l[r])}return Uw=s,Uw}var Hw,vC;function ok(){if(vC)return Hw;vC=1;var e=Jb(),t=BW();function n(r,s,l,c,u){var f=-1,p=r.length;for(l||(l=t),u||(u=[]);++f<p;){var h=r[f];s>0&&l(h)?s>1?n(h,s-1,l,c,u):e(u,h):c||(u[u.length]=h)}return u}return Hw=n,Hw}var Ww,xC;function zW(){if(xC)return Ww;xC=1;function e(t,n,r){switch(r.length){case 0:return t.call(n);case 1:return t.call(n,r[0]);case 2:return t.call(n,r[0],r[1]);case 3:return t.call(n,r[0],r[1],r[2])}return t.apply(n,r)}return Ww=e,Ww}var Vw,bC;function LI(){if(bC)return Vw;bC=1;var e=zW(),t=Math.max;function n(r,s,l){return s=t(s===void 0?r.length-1:s,0),function(){for(var c=arguments,u=-1,f=t(c.length-s,0),p=Array(f);++u<f;)p[u]=c[s+u];u=-1;for(var h=Array(s+1);++u<s;)h[u]=c[u];return h[s]=l(p),e(r,this,h)}}return Vw=n,Vw}var Gw,kC;function UW(){if(kC)return Gw;kC=1;var e=tk(),t=tI(),n=Ei(),r=t?function(s,l){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:n;return Gw=r,Gw}var Kw,NC;function HW(){if(NC)return Kw;NC=1;var e=800,t=16,n=Date.now;function r(s){var l=0,c=0;return function(){var u=n(),f=t-(u-c);if(c=u,f>0){if(++l>=e)return arguments[0]}else l=0;return s.apply(void 0,arguments)}}return Kw=r,Kw}var Yw,SC;function PI(){if(SC)return Yw;SC=1;var e=UW(),t=HW(),n=t(e);return Yw=n,Yw}var Xw,jC;function Xf(){if(jC)return Xw;jC=1;var e=Ei(),t=LI(),n=PI();function r(s,l){return n(t(s,l,e),s+"")}return Xw=r,Xw}var Zw,_C;function DI(){if(_C)return Zw;_C=1;function e(t,n,r,s){for(var l=t.length,c=r+(s?1:-1);s?c--:++c<l;)if(n(t[c],c,t))return c;return-1}return Zw=e,Zw}var Qw,EC;function WW(){if(EC)return Qw;EC=1;function e(t){return t!==t}return Qw=e,Qw}var Jw,CC;function VW(){if(CC)return Jw;CC=1;function e(t,n,r){for(var s=r-1,l=t.length;++s<l;)if(t[s]===n)return s;return-1}return Jw=e,Jw}var ev,TC;function GW(){if(TC)return ev;TC=1;var e=DI(),t=WW(),n=VW();function r(s,l,c){return l===l?n(s,l,c):e(s,t,c)}return ev=r,ev}var tv,RC;function KW(){if(RC)return tv;RC=1;var e=GW();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return tv=t,tv}var nv,AC;function YW(){if(AC)return nv;AC=1;function e(t,n,r){for(var s=-1,l=t==null?0:t.length;++s<l;)if(r(n,t[s]))return!0;return!1}return nv=e,nv}var rv,MC;function XW(){if(MC)return rv;MC=1;function e(){}return rv=e,rv}var sv,IC;function ZW(){if(IC)return sv;IC=1;var e=dI(),t=XW(),n=sk(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(l){return new e(l)}:t;return sv=s,sv}var av,$C;function QW(){if($C)return av;$C=1;var e=xI(),t=KW(),n=YW(),r=bI(),s=ZW(),l=sk(),c=200;function u(f,p,h){var m=-1,y=t,v=f.length,S=!0,b=[],_=b;if(h)S=!1,y=n;else if(v>=c){var k=p?null:s(f);if(k)return l(k);S=!1,y=r,_=new e}else _=p?[]:b;e:for(;++m<v;){var j=f[m],E=p?p(j):j;if(j=h||j!==0?j:0,S&&E===E){for(var C=_.length;C--;)if(_[C]===E)continue e;p&&_.push(E),b.push(j)}else y(_,E,h)||(_!==b&&_.push(E),b.push(j))}return b}return av=u,av}var ov,OC;function FI(){if(OC)return ov;OC=1;var e=fa(),t=Us();function n(r){return t(r)&&e(r)}return ov=n,ov}var iv,LC;function JW(){if(LC)return iv;LC=1;var e=ok(),t=Xf(),n=QW(),r=FI(),s=t(function(l){return n(e(l,1,r,!0))});return iv=s,iv}var lv,PC;function e7(){if(PC)return lv;PC=1;var e=Gf();function t(n,r){return e(r,function(s){return n[s]})}return lv=t,lv}var cv,DC;function qI(){if(DC)return cv;DC=1;var e=e7(),t=co();function n(r){return r==null?[]:e(r,t(r))}return cv=n,cv}var uv,FC;function zr(){if(FC)return uv;FC=1;var e;if(typeof Wb=="function")try{e={clone:iW(),constant:tk(),each:vI(),filter:RI(),has:AI(),isArray:nn(),isEmpty:AW(),isFunction:Vu(),isUndefined:MI(),keys:co(),map:$I(),reduce:OI(),size:FW(),transform:qW(),union:JW(),values:qI()}}catch{}return e||(e=window._),uv=e,uv}var dv,qC;function ik(){if(qC)return dv;qC=1;var e=zr();dv=s;var t="\0",n="\0",r="";function s(h){this._isDirected=e.has(h,"directed")?h.directed:!0,this._isMultigraph=e.has(h,"multigraph")?h.multigraph:!1,this._isCompound=e.has(h,"compound")?h.compound:!1,this._label=void 0,this._defaultNodeLabelFn=e.constant(void 0),this._defaultEdgeLabelFn=e.constant(void 0),this._nodes={},this._isCompound&&(this._parent={},this._children={},this._children[n]={}),this._in={},this._preds={},this._out={},this._sucs={},this._edgeObjs={},this._edgeLabels={}}s.prototype._nodeCount=0,s.prototype._edgeCount=0,s.prototype.isDirected=function(){return this._isDirected},s.prototype.isMultigraph=function(){return this._isMultigraph},s.prototype.isCompound=function(){return this._isCompound},s.prototype.setGraph=function(h){return this._label=h,this},s.prototype.graph=function(){return this._label},s.prototype.setDefaultNodeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultNodeLabelFn=h,this},s.prototype.nodeCount=function(){return this._nodeCount},s.prototype.nodes=function(){return e.keys(this._nodes)},s.prototype.sources=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._in[m])})},s.prototype.sinks=function(){var h=this;return e.filter(this.nodes(),function(m){return e.isEmpty(h._out[m])})},s.prototype.setNodes=function(h,m){var y=arguments,v=this;return e.each(h,function(S){y.length>1?v.setNode(S,m):v.setNode(S)}),this},s.prototype.setNode=function(h,m){return e.has(this._nodes,h)?(arguments.length>1&&(this._nodes[h]=m),this):(this._nodes[h]=arguments.length>1?m:this._defaultNodeLabelFn(h),this._isCompound&&(this._parent[h]=n,this._children[h]={},this._children[n][h]=!0),this._in[h]={},this._preds[h]={},this._out[h]={},this._sucs[h]={},++this._nodeCount,this)},s.prototype.node=function(h){return this._nodes[h]},s.prototype.hasNode=function(h){return e.has(this._nodes,h)},s.prototype.removeNode=function(h){var m=this;if(e.has(this._nodes,h)){var y=function(v){m.removeEdge(m._edgeObjs[v])};delete this._nodes[h],this._isCompound&&(this._removeFromParentsChildList(h),delete this._parent[h],e.each(this.children(h),function(v){m.setParent(v)}),delete this._children[h]),e.each(e.keys(this._in[h]),y),delete this._in[h],delete this._preds[h],e.each(e.keys(this._out[h]),y),delete this._out[h],delete this._sucs[h],--this._nodeCount}return this},s.prototype.setParent=function(h,m){if(!this._isCompound)throw new Error("Cannot set parent in a non-compound graph");if(e.isUndefined(m))m=n;else{m+="";for(var y=m;!e.isUndefined(y);y=this.parent(y))if(y===h)throw new Error("Setting "+m+" as parent of "+h+" would create a cycle");this.setNode(m)}return this.setNode(h),this._removeFromParentsChildList(h),this._parent[h]=m,this._children[m][h]=!0,this},s.prototype._removeFromParentsChildList=function(h){delete this._children[this._parent[h]][h]},s.prototype.parent=function(h){if(this._isCompound){var m=this._parent[h];if(m!==n)return m}},s.prototype.children=function(h){if(e.isUndefined(h)&&(h=n),this._isCompound){var m=this._children[h];if(m)return e.keys(m)}else{if(h===n)return this.nodes();if(this.hasNode(h))return[]}},s.prototype.predecessors=function(h){var m=this._preds[h];if(m)return e.keys(m)},s.prototype.successors=function(h){var m=this._sucs[h];if(m)return e.keys(m)},s.prototype.neighbors=function(h){var m=this.predecessors(h);if(m)return e.union(m,this.successors(h))},s.prototype.isLeaf=function(h){var m;return this.isDirected()?m=this.successors(h):m=this.neighbors(h),m.length===0},s.prototype.filterNodes=function(h){var m=new this.constructor({directed:this._isDirected,multigraph:this._isMultigraph,compound:this._isCompound});m.setGraph(this.graph());var y=this;e.each(this._nodes,function(b,_){h(_)&&m.setNode(_,b)}),e.each(this._edgeObjs,function(b){m.hasNode(b.v)&&m.hasNode(b.w)&&m.setEdge(b,y.edge(b))});var v={};function S(b){var _=y.parent(b);return _===void 0||m.hasNode(_)?(v[b]=_,_):_ in v?v[_]:S(_)}return this._isCompound&&e.each(m.nodes(),function(b){m.setParent(b,S(b))}),m},s.prototype.setDefaultEdgeLabel=function(h){return e.isFunction(h)||(h=e.constant(h)),this._defaultEdgeLabelFn=h,this},s.prototype.edgeCount=function(){return this._edgeCount},s.prototype.edges=function(){return e.values(this._edgeObjs)},s.prototype.setPath=function(h,m){var y=this,v=arguments;return e.reduce(h,function(S,b){return v.length>1?y.setEdge(S,b,m):y.setEdge(S,b),b}),this},s.prototype.setEdge=function(){var h,m,y,v,S=!1,b=arguments[0];typeof b=="object"&&b!==null&&"v"in b?(h=b.v,m=b.w,y=b.name,arguments.length===2&&(v=arguments[1],S=!0)):(h=b,m=arguments[1],y=arguments[3],arguments.length>2&&(v=arguments[2],S=!0)),h=""+h,m=""+m,e.isUndefined(y)||(y=""+y);var _=u(this._isDirected,h,m,y);if(e.has(this._edgeLabels,_))return S&&(this._edgeLabels[_]=v),this;if(!e.isUndefined(y)&&!this._isMultigraph)throw new Error("Cannot set a named edge when isMultigraph = false");this.setNode(h),this.setNode(m),this._edgeLabels[_]=S?v:this._defaultEdgeLabelFn(h,m,y);var k=f(this._isDirected,h,m,y);return h=k.v,m=k.w,Object.freeze(k),this._edgeObjs[_]=k,l(this._preds[m],h),l(this._sucs[h],m),this._in[m][_]=k,this._out[h][_]=k,this._edgeCount++,this},s.prototype.edge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return this._edgeLabels[v]},s.prototype.hasEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y);return e.has(this._edgeLabels,v)},s.prototype.removeEdge=function(h,m,y){var v=arguments.length===1?p(this._isDirected,arguments[0]):u(this._isDirected,h,m,y),S=this._edgeObjs[v];return S&&(h=S.v,m=S.w,delete this._edgeLabels[v],delete this._edgeObjs[v],c(this._preds[m],h),c(this._sucs[h],m),delete this._in[m][v],delete this._out[h][v],this._edgeCount--),this},s.prototype.inEdges=function(h,m){var y=this._in[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.v===m}):v}},s.prototype.outEdges=function(h,m){var y=this._out[h];if(y){var v=e.values(y);return m?e.filter(v,function(S){return S.w===m}):v}},s.prototype.nodeEdges=function(h,m){var y=this.inEdges(h,m);if(y)return y.concat(this.outEdges(h,m))};function l(h,m){h[m]?h[m]++:h[m]=1}function c(h,m){--h[m]||delete h[m]}function u(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}return S+r+b+r+(e.isUndefined(v)?t:v)}function f(h,m,y,v){var S=""+m,b=""+y;if(!h&&S>b){var _=S;S=b,b=_}var k={v:S,w:b};return v&&(k.name=v),k}function p(h,m){return u(h,m.v,m.w,m.name)}return dv}var hv,BC;function t7(){return BC||(BC=1,hv="2.1.8"),hv}var fv,zC;function n7(){return zC||(zC=1,fv={Graph:ik(),version:t7()}),fv}var pv,UC;function r7(){if(UC)return pv;UC=1;var e=zr(),t=ik();pv={write:n,read:l};function n(c){var u={options:{directed:c.isDirected(),multigraph:c.isMultigraph(),compound:c.isCompound()},nodes:r(c),edges:s(c)};return e.isUndefined(c.graph())||(u.value=e.clone(c.graph())),u}function r(c){return e.map(c.nodes(),function(u){var f=c.node(u),p=c.parent(u),h={v:u};return e.isUndefined(f)||(h.value=f),e.isUndefined(p)||(h.parent=p),h})}function s(c){return e.map(c.edges(),function(u){var f=c.edge(u),p={v:u.v,w:u.w};return e.isUndefined(u.name)||(p.name=u.name),e.isUndefined(f)||(p.value=f),p})}function l(c){var u=new t(c.options).setGraph(c.value);return e.each(c.nodes,function(f){u.setNode(f.v,f.value),f.parent&&u.setParent(f.v,f.parent)}),e.each(c.edges,function(f){u.setEdge({v:f.v,w:f.w,name:f.name},f.value)}),u}return pv}var mv,HC;function s7(){if(HC)return mv;HC=1;var e=zr();mv=t;function t(n){var r={},s=[],l;function c(u){e.has(r,u)||(r[u]=!0,l.push(u),e.each(n.successors(u),c),e.each(n.predecessors(u),c))}return e.each(n.nodes(),function(u){l=[],c(u),l.length&&s.push(l)}),s}return mv}var gv,WC;function BI(){if(WC)return gv;WC=1;var e=zr();gv=t;function t(){this._arr=[],this._keyIndices={}}return t.prototype.size=function(){return this._arr.length},t.prototype.keys=function(){return this._arr.map(function(n){return n.key})},t.prototype.has=function(n){return e.has(this._keyIndices,n)},t.prototype.priority=function(n){var r=this._keyIndices[n];if(r!==void 0)return this._arr[r].priority},t.prototype.min=function(){if(this.size()===0)throw new Error("Queue underflow");return this._arr[0].key},t.prototype.add=function(n,r){var s=this._keyIndices;if(n=String(n),!e.has(s,n)){var l=this._arr,c=l.length;return s[n]=c,l.push({key:n,priority:r}),this._decrease(c),!0}return!1},t.prototype.removeMin=function(){this._swap(0,this._arr.length-1);var n=this._arr.pop();return delete this._keyIndices[n.key],this._heapify(0),n.key},t.prototype.decrease=function(n,r){var s=this._keyIndices[n];if(r>this._arr[s].priority)throw new Error("New priority is greater than current priority. Key: "+n+" Old: "+this._arr[s].priority+" New: "+r);this._arr[s].priority=r,this._decrease(s)},t.prototype._heapify=function(n){var r=this._arr,s=2*n,l=s+1,c=n;s<r.length&&(c=r[s].priority<r[c].priority?s:c,l<r.length&&(c=r[l].priority<r[c].priority?l:c),c!==n&&(this._swap(n,c),this._heapify(c)))},t.prototype._decrease=function(n){for(var r=this._arr,s=r[n].priority,l;n!==0&&(l=n>>1,!(r[l].priority<s));)this._swap(n,l),n=l},t.prototype._swap=function(n,r){var s=this._arr,l=this._keyIndices,c=s[n],u=s[r];s[n]=u,s[r]=c,l[u.key]=n,l[c.key]=r},gv}var yv,VC;function zI(){if(VC)return yv;VC=1;var e=zr(),t=BI();yv=r;var n=e.constant(1);function r(l,c,u,f){return s(l,String(c),u||n,f||function(p){return l.outEdges(p)})}function s(l,c,u,f){var p={},h=new t,m,y,v=function(S){var b=S.v!==m?S.v:S.w,_=p[b],k=u(S),j=y.distance+k;if(k<0)throw new Error("dijkstra does not allow negative edge weights. Bad edge: "+S+" Weight: "+k);j<_.distance&&(_.distance=j,_.predecessor=m,h.decrease(b,j))};for(l.nodes().forEach(function(S){var b=S===c?0:Number.POSITIVE_INFINITY;p[S]={distance:b},h.add(S,b)});h.size()>0&&(m=h.removeMin(),y=p[m],y.distance!==Number.POSITIVE_INFINITY);)f(m).forEach(v);return p}return yv}var wv,GC;function a7(){if(GC)return wv;GC=1;var e=zI(),t=zr();wv=n;function n(r,s,l){return t.transform(r.nodes(),function(c,u){c[u]=e(r,u,s,l)},{})}return wv}var vv,KC;function UI(){if(KC)return vv;KC=1;var e=zr();vv=t;function t(n){var r=0,s=[],l={},c=[];function u(f){var p=l[f]={onStack:!0,lowlink:r,index:r++};if(s.push(f),n.successors(f).forEach(function(y){e.has(l,y)?l[y].onStack&&(p.lowlink=Math.min(p.lowlink,l[y].index)):(u(y),p.lowlink=Math.min(p.lowlink,l[y].lowlink))}),p.lowlink===p.index){var h=[],m;do m=s.pop(),l[m].onStack=!1,h.push(m);while(f!==m);c.push(h)}}return n.nodes().forEach(function(f){e.has(l,f)||u(f)}),c}return vv}var xv,YC;function o7(){if(YC)return xv;YC=1;var e=zr(),t=UI();xv=n;function n(r){return e.filter(t(r),function(s){return s.length>1||s.length===1&&r.hasEdge(s[0],s[0])})}return xv}var bv,XC;function i7(){if(XC)return bv;XC=1;var e=zr();bv=n;var t=e.constant(1);function n(s,l,c){return r(s,l||t,c||function(u){return s.outEdges(u)})}function r(s,l,c){var u={},f=s.nodes();return f.forEach(function(p){u[p]={},u[p][p]={distance:0},f.forEach(function(h){p!==h&&(u[p][h]={distance:Number.POSITIVE_INFINITY})}),c(p).forEach(function(h){var m=h.v===p?h.w:h.v,y=l(h);u[p][m]={distance:y,predecessor:p}})}),f.forEach(function(p){var h=u[p];f.forEach(function(m){var y=u[m];f.forEach(function(v){var S=y[p],b=h[v],_=y[v],k=S.distance+b.distance;k<_.distance&&(_.distance=k,_.predecessor=b.predecessor)})})}),u}return bv}var kv,ZC;function HI(){if(ZC)return kv;ZC=1;var e=zr();kv=t,t.CycleException=n;function t(r){var s={},l={},c=[];function u(f){if(e.has(l,f))throw new n;e.has(s,f)||(l[f]=!0,s[f]=!0,e.each(r.predecessors(f),u),delete l[f],c.push(f))}if(e.each(r.sinks(),u),e.size(s)!==r.nodeCount())throw new n;return c}function n(){}return n.prototype=new Error,kv}var Nv,QC;function l7(){if(QC)return Nv;QC=1;var e=HI();Nv=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return Nv}var Sv,JC;function WI(){if(JC)return Sv;JC=1;var e=zr();Sv=t;function t(r,s,l){e.isArray(s)||(s=[s]);var c=(r.isDirected()?r.successors:r.neighbors).bind(r),u=[],f={};return e.each(s,function(p){if(!r.hasNode(p))throw new Error("Graph does not have node: "+p);n(r,p,l==="post",f,c,u)}),u}function n(r,s,l,c,u,f){e.has(c,s)||(c[s]=!0,l||f.push(s),e.each(u(s),function(p){n(r,p,l,c,u,f)}),l&&f.push(s))}return Sv}var jv,eT;function c7(){if(eT)return jv;eT=1;var e=WI();jv=t;function t(n,r){return e(n,r,"post")}return jv}var _v,tT;function u7(){if(tT)return _v;tT=1;var e=WI();_v=t;function t(n,r){return e(n,r,"pre")}return _v}var Ev,nT;function d7(){if(nT)return Ev;nT=1;var e=zr(),t=ik(),n=BI();Ev=r;function r(s,l){var c=new t,u={},f=new n,p;function h(y){var v=y.v===p?y.w:y.v,S=f.priority(v);if(S!==void 0){var b=l(y);b<S&&(u[v]=p,f.decrease(v,b))}}if(s.nodeCount()===0)return c;e.each(s.nodes(),function(y){f.add(y,Number.POSITIVE_INFINITY),c.setNode(y)}),f.decrease(s.nodes()[0],0);for(var m=!1;f.size()>0;){if(p=f.removeMin(),e.has(u,p))c.setEdge(p,u[p]);else{if(m)throw new Error("Input graph is not connected: "+s);m=!0}s.nodeEdges(p).forEach(h)}return c}return Ev}var Cv,rT;function h7(){return rT||(rT=1,Cv={components:s7(),dijkstra:zI(),dijkstraAll:a7(),findCycles:o7(),floydWarshall:i7(),isAcyclic:l7(),postorder:c7(),preorder:u7(),prim:d7(),tarjan:UI(),topsort:HI()}),Cv}var Tv,sT;function f7(){if(sT)return Tv;sT=1;var e=n7();return Tv={Graph:e.Graph,json:r7(),alg:h7(),version:e.version},Tv}var Rv,aT;function xs(){if(aT)return Rv;aT=1;var e;if(typeof Wb=="function")try{e=f7()}catch{}return e||(e=window.graphlib),Rv=e,Rv}var Av,oT;function p7(){if(oT)return Av;oT=1;var e=gI(),t=1,n=4;function r(s){return e(s,t|n)}return Av=r,Av}var Mv,iT;function Zf(){if(iT)return Mv;iT=1;var e=sc(),t=fa(),n=zf(),r=Br();function s(l,c,u){if(!r(u))return!1;var f=typeof c;return(f=="number"?t(u)&&n(c,u.length):f=="string"&&c in u)?e(u[c],l):!1}return Mv=s,Mv}var Iv,lT;function m7(){if(lT)return Iv;lT=1;var e=Xf(),t=sc(),n=Zf(),r=_i(),s=Object.prototype,l=s.hasOwnProperty,c=e(function(u,f){u=Object(u);var p=-1,h=f.length,m=h>2?f[2]:void 0;for(m&&n(f[0],f[1],m)&&(h=1);++p<h;)for(var y=f[p],v=r(y),S=-1,b=v.length;++S<b;){var _=v[S],k=u[_];(k===void 0||t(k,s[_])&&!l.call(u,_))&&(u[_]=y[_])}return u});return Iv=c,Iv}var $v,cT;function g7(){if(cT)return $v;cT=1;var e=pa(),t=fa(),n=co();function r(s){return function(l,c,u){var f=Object(l);if(!t(l)){var p=e(c,3);l=n(l),c=function(m){return p(f[m],m,f)}}var h=s(l,c,u);return h>-1?f[p?l[h]:h]:void 0}}return $v=r,$v}var Ov,uT;function y7(){if(uT)return Ov;uT=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Ov=t,Ov}var Lv,dT;function w7(){if(dT)return Lv;dT=1;var e=y7(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Lv=n,Lv}var Pv,hT;function v7(){if(hT)return Pv;hT=1;var e=w7(),t=Br(),n=lc(),r=NaN,s=/^[-+]0x[0-9a-f]+$/i,l=/^0b[01]+$/i,c=/^0o[0-7]+$/i,u=parseInt;function f(p){if(typeof p=="number")return p;if(n(p))return r;if(t(p)){var h=typeof p.valueOf=="function"?p.valueOf():p;p=t(h)?h+"":h}if(typeof p!="string")return p===0?p:+p;p=e(p);var m=l.test(p);return m||c.test(p)?u(p.slice(2),m?2:8):s.test(p)?r:+p}return Pv=f,Pv}var Dv,fT;function VI(){if(fT)return Dv;fT=1;var e=v7(),t=1/0,n=17976931348623157e292;function r(s){if(!s)return s===0?s:0;if(s=e(s),s===t||s===-t){var l=s<0?-1:1;return l*n}return s===s?s:0}return Dv=r,Dv}var Fv,pT;function x7(){if(pT)return Fv;pT=1;var e=VI();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Fv=t,Fv}var qv,mT;function b7(){if(mT)return qv;mT=1;var e=DI(),t=pa(),n=x7(),r=Math.max;function s(l,c,u){var f=l==null?0:l.length;if(!f)return-1;var p=u==null?0:n(u);return p<0&&(p=r(f+p,0)),e(l,t(c,3),p)}return qv=s,qv}var Bv,gT;function k7(){if(gT)return Bv;gT=1;var e=g7(),t=b7(),n=e(t);return Bv=n,Bv}var zv,yT;function GI(){if(yT)return zv;yT=1;var e=ok();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return zv=t,zv}var Uv,wT;function N7(){if(wT)return Uv;wT=1;var e=nk(),t=yI(),n=_i();function r(s,l){return s==null?s:e(s,t(l),n)}return Uv=r,Uv}var Hv,vT;function S7(){if(vT)return Hv;vT=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Hv=e,Hv}var Wv,xT;function j7(){if(xT)return Wv;xT=1;var e=qf(),t=rk(),n=pa();function r(s,l){var c={};return l=n(l,3),t(s,function(u,f,p){e(c,f,l(u,f,p))}),c}return Wv=r,Wv}var Vv,bT;function lk(){if(bT)return Vv;bT=1;var e=lc();function t(n,r,s){for(var l=-1,c=n.length;++l<c;){var u=n[l],f=r(u);if(f!=null&&(p===void 0?f===f&&!e(f):s(f,p)))var p=f,h=u}return h}return Vv=t,Vv}var Gv,kT;function _7(){if(kT)return Gv;kT=1;function e(t,n){return t>n}return Gv=e,Gv}var Kv,NT;function E7(){if(NT)return Kv;NT=1;var e=lk(),t=_7(),n=Ei();function r(s){return s&&s.length?e(s,n,t):void 0}return Kv=r,Kv}var Yv,ST;function KI(){if(ST)return Yv;ST=1;var e=qf(),t=sc();function n(r,s,l){(l!==void 0&&!t(r[s],l)||l===void 0&&!(s in r))&&e(r,s,l)}return Yv=n,Yv}var Xv,jT;function C7(){if(jT)return Xv;jT=1;var e=Si(),t=Wf(),n=Us(),r="[object Object]",s=Function.prototype,l=Object.prototype,c=s.toString,u=l.hasOwnProperty,f=c.call(Object);function p(h){if(!n(h)||e(h)!=r)return!1;var m=t(h);if(m===null)return!0;var y=u.call(m,"constructor")&&m.constructor;return typeof y=="function"&&y instanceof y&&c.call(y)==f}return Xv=p,Xv}var Zv,_T;function YI(){if(_T)return Zv;_T=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Zv=e,Zv}var Qv,ET;function T7(){if(ET)return Qv;ET=1;var e=Gu(),t=_i();function n(r){return e(r,t(r))}return Qv=n,Qv}var Jv,CT;function R7(){if(CT)return Jv;CT=1;var e=KI(),t=sI(),n=fI(),r=aI(),s=mI(),l=Ku(),c=nn(),u=FI(),f=oc(),p=Vu(),h=Br(),m=C7(),y=Yu(),v=YI(),S=T7();function b(_,k,j,E,C,R,I){var $=v(_,j),q=v(k,j),B=I.get(q);if(B){e(_,j,B);return}var P=R?R($,q,j+"",_,k,I):void 0,W=P===void 0;if(W){var ne=c(q),ee=!ne&&f(q),M=!ne&&!ee&&y(q);P=q,ne||ee||M?c($)?P=$:u($)?P=r($):ee?(W=!1,P=t(q,!0)):M?(W=!1,P=n(q,!0)):P=[]:m(q)||l(q)?(P=$,l($)?P=S($):(!h($)||p($))&&(P=s(q))):W=!1}W&&(I.set(q,P),C(P,q,E,R,I),I.delete(q)),e(_,j,P)}return Jv=b,Jv}var ex,TT;function A7(){if(TT)return ex;TT=1;var e=Ff(),t=KI(),n=nk(),r=R7(),s=Br(),l=_i(),c=YI();function u(f,p,h,m,y){f!==p&&n(p,function(v,S){if(y||(y=new e),s(v))r(f,p,S,h,u,m,y);else{var b=m?m(c(f,S),v,S+"",f,p,y):void 0;b===void 0&&(b=v),t(f,S,b)}},l)}return ex=u,ex}var tx,RT;function M7(){if(RT)return tx;RT=1;var e=Xf(),t=Zf();function n(r){return e(function(s,l){var c=-1,u=l.length,f=u>1?l[u-1]:void 0,p=u>2?l[2]:void 0;for(f=r.length>3&&typeof f=="function"?(u--,f):void 0,p&&t(l[0],l[1],p)&&(f=u<3?void 0:f,u=1),s=Object(s);++c<u;){var h=l[c];h&&r(s,h,c,f)}return s})}return tx=n,tx}var nx,AT;function I7(){if(AT)return nx;AT=1;var e=A7(),t=M7(),n=t(function(r,s,l){e(r,s,l)});return nx=n,nx}var rx,MT;function XI(){if(MT)return rx;MT=1;function e(t,n){return t<n}return rx=e,rx}var sx,IT;function $7(){if(IT)return sx;IT=1;var e=lk(),t=XI(),n=Ei();function r(s){return s&&s.length?e(s,n,t):void 0}return sx=r,sx}var ax,$T;function O7(){if($T)return ax;$T=1;var e=lk(),t=pa(),n=XI();function r(s,l){return s&&s.length?e(s,t(l,2),n):void 0}return ax=r,ax}var ox,OT;function L7(){if(OT)return ox;OT=1;var e=ks(),t=function(){return e.Date.now()};return ox=t,ox}var ix,LT;function P7(){if(LT)return ix;LT=1;var e=Bf(),t=Kf(),n=zf(),r=Br(),s=Xu();function l(c,u,f,p){if(!r(c))return c;u=t(u,c);for(var h=-1,m=u.length,y=m-1,v=c;v!=null&&++h<m;){var S=s(u[h]),b=f;if(S==="__proto__"||S==="constructor"||S==="prototype")return c;if(h!=y){var _=v[S];b=p?p(_,S,v):void 0,b===void 0&&(b=r(_)?_:n(u[h+1])?[]:{})}e(v,S,b),v=v[S]}return c}return ix=l,ix}var lx,PT;function D7(){if(PT)return lx;PT=1;var e=Yf(),t=P7(),n=Kf();function r(s,l,c){for(var u=-1,f=l.length,p={};++u<f;){var h=l[u],m=e(s,h);c(m,h)&&t(p,n(h,s),m)}return p}return lx=r,lx}var cx,DT;function F7(){if(DT)return cx;DT=1;var e=D7(),t=CI();function n(r,s){return e(r,s,function(l,c){return t(r,c)})}return cx=n,cx}var ux,FT;function q7(){if(FT)return ux;FT=1;var e=GI(),t=LI(),n=PI();function r(s){return n(t(s,void 0,e),s+"")}return ux=r,ux}var dx,qT;function B7(){if(qT)return dx;qT=1;var e=F7(),t=q7(),n=t(function(r,s){return r==null?{}:e(r,s)});return dx=n,dx}var hx,BT;function z7(){if(BT)return hx;BT=1;var e=Math.ceil,t=Math.max;function n(r,s,l,c){for(var u=-1,f=t(e((s-r)/(l||1)),0),p=Array(f);f--;)p[c?f:++u]=r,r+=l;return p}return hx=n,hx}var fx,zT;function U7(){if(zT)return fx;zT=1;var e=z7(),t=Zf(),n=VI();function r(s){return function(l,c,u){return u&&typeof u!="number"&&t(l,c,u)&&(c=u=void 0),l=n(l),c===void 0?(c=l,l=0):c=n(c),u=u===void 0?l<c?1:-1:n(u),e(l,c,u,s)}}return fx=r,fx}var px,UT;function H7(){if(UT)return px;UT=1;var e=U7(),t=e();return px=t,px}var mx,HT;function W7(){if(HT)return mx;HT=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return mx=e,mx}var gx,WT;function V7(){if(WT)return gx;WT=1;var e=lc();function t(n,r){if(n!==r){var s=n!==void 0,l=n===null,c=n===n,u=e(n),f=r!==void 0,p=r===null,h=r===r,m=e(r);if(!p&&!m&&!u&&n>r||u&&f&&h&&!p&&!m||l&&f&&h||!s&&h||!c)return 1;if(!l&&!u&&!m&&n<r||m&&s&&c&&!l&&!u||p&&s&&c||!f&&c||!h)return-1}return 0}return gx=t,gx}var yx,VT;function G7(){if(VT)return yx;VT=1;var e=V7();function t(n,r,s){for(var l=-1,c=n.criteria,u=r.criteria,f=c.length,p=s.length;++l<f;){var h=e(c[l],u[l]);if(h){if(l>=p)return h;var m=s[l];return h*(m=="desc"?-1:1)}}return n.index-r.index}return yx=t,yx}var wx,GT;function K7(){if(GT)return wx;GT=1;var e=Gf(),t=Yf(),n=pa(),r=II(),s=W7(),l=Uf(),c=G7(),u=Ei(),f=nn();function p(h,m,y){m.length?m=e(m,function(b){return f(b)?function(_){return t(_,b.length===1?b[0]:b)}:b}):m=[u];var v=-1;m=e(m,l(n));var S=r(h,function(b,_,k){var j=e(m,function(E){return E(b)});return{criteria:j,index:++v,value:b}});return s(S,function(b,_){return c(b,_,y)})}return wx=p,wx}var vx,KT;function Y7(){if(KT)return vx;KT=1;var e=ok(),t=K7(),n=Xf(),r=Zf(),s=n(function(l,c){if(l==null)return[];var u=c.length;return u>1&&r(l,c[0],c[1])?c=[]:u>2&&r(c[0],c[1],c[2])&&(c=[c[0]]),t(l,e(c,1),[])});return vx=s,vx}var xx,YT;function X7(){if(YT)return xx;YT=1;var e=_I(),t=0;function n(r){var s=++t;return e(r)+s}return xx=n,xx}var bx,XT;function Z7(){if(XT)return bx;XT=1;function e(t,n,r){for(var s=-1,l=t.length,c=n.length,u={};++s<l;){var f=s<c?n[s]:void 0;r(u,t[s],f)}return u}return bx=e,bx}var kx,ZT;function Q7(){if(ZT)return kx;ZT=1;var e=Bf(),t=Z7();function n(r,s){return t(r||[],s||[],e)}return kx=n,kx}var Nx,QT;function Dt(){if(QT)return Nx;QT=1;var e;if(typeof Wb=="function")try{e={cloneDeep:p7(),constant:tk(),defaults:m7(),each:vI(),filter:RI(),find:k7(),flatten:GI(),forEach:wI(),forIn:N7(),has:AI(),isUndefined:MI(),last:S7(),map:$I(),mapValues:j7(),max:E7(),merge:I7(),min:$7(),minBy:O7(),now:L7(),pick:B7(),range:H7(),reduce:OI(),sortBy:Y7(),uniqueId:X7(),values:qI(),zipObject:Q7()}}catch{}return e||(e=window._),Nx=e,Nx}var Sx,JT;function J7(){if(JT)return Sx;JT=1,Sx=e;function e(){var r={};r._next=r._prev=r,this._sentinel=r}e.prototype.dequeue=function(){var r=this._sentinel,s=r._prev;if(s!==r)return t(s),s},e.prototype.enqueue=function(r){var s=this._sentinel;r._prev&&r._next&&t(r),r._next=s._next,s._next._prev=r,s._next=r,r._prev=s},e.prototype.toString=function(){for(var r=[],s=this._sentinel,l=s._prev;l!==s;)r.push(JSON.stringify(l,n)),l=l._prev;return"["+r.join(", ")+"]"};function t(r){r._prev._next=r._next,r._next._prev=r._prev,delete r._next,delete r._prev}function n(r,s){if(r!=="_next"&&r!=="_prev")return s}return Sx}var jx,e2;function e9(){if(e2)return jx;e2=1;var e=Dt(),t=xs().Graph,n=J7();jx=s;var r=e.constant(1);function s(p,h){if(p.nodeCount()<=1)return[];var m=u(p,h||r),y=l(m.graph,m.buckets,m.zeroIdx);return e.flatten(e.map(y,function(v){return p.outEdges(v.v,v.w)}),!0)}function l(p,h,m){for(var y=[],v=h[h.length-1],S=h[0],b;p.nodeCount();){for(;b=S.dequeue();)c(p,h,m,b);for(;b=v.dequeue();)c(p,h,m,b);if(p.nodeCount()){for(var _=h.length-2;_>0;--_)if(b=h[_].dequeue(),b){y=y.concat(c(p,h,m,b,!0));break}}}return y}function c(p,h,m,y,v){var S=v?[]:void 0;return e.forEach(p.inEdges(y.v),function(b){var _=p.edge(b),k=p.node(b.v);v&&S.push({v:b.v,w:b.w}),k.out-=_,f(h,m,k)}),e.forEach(p.outEdges(y.v),function(b){var _=p.edge(b),k=b.w,j=p.node(k);j.in-=_,f(h,m,j)}),p.removeNode(y.v),S}function u(p,h){var m=new t,y=0,v=0;e.forEach(p.nodes(),function(_){m.setNode(_,{v:_,in:0,out:0})}),e.forEach(p.edges(),function(_){var k=m.edge(_.v,_.w)||0,j=h(_),E=k+j;m.setEdge(_.v,_.w,E),v=Math.max(v,m.node(_.v).out+=j),y=Math.max(y,m.node(_.w).in+=j)});var S=e.range(v+y+3).map(function(){return new n}),b=y+1;return e.forEach(m.nodes(),function(_){f(S,b,m.node(_))}),{graph:m,buckets:S,zeroIdx:b}}function f(p,h,m){m.out?m.in?p[m.out-m.in+h].enqueue(m):p[p.length-1].enqueue(m):p[0].enqueue(m)}return jx}var _x,t2;function t9(){if(t2)return _x;t2=1;var e=Dt(),t=e9();_x={run:n,undo:s};function n(l){var c=l.graph().acyclicer==="greedy"?t(l,u(l)):r(l);e.forEach(c,function(f){var p=l.edge(f);l.removeEdge(f),p.forwardName=f.name,p.reversed=!0,l.setEdge(f.w,f.v,p,e.uniqueId("rev"))});function u(f){return function(p){return f.edge(p).weight}}}function r(l){var c=[],u={},f={};function p(h){e.has(f,h)||(f[h]=!0,u[h]=!0,e.forEach(l.outEdges(h),function(m){e.has(u,m.w)?c.push(m):p(m.w)}),delete u[h])}return e.forEach(l.nodes(),p),c}function s(l){e.forEach(l.edges(),function(c){var u=l.edge(c);if(u.reversed){l.removeEdge(c);var f=u.forwardName;delete u.reversed,delete u.forwardName,l.setEdge(c.w,c.v,u,f)}})}return _x}var Ex,n2;function ar(){if(n2)return Ex;n2=1;var e=Dt(),t=xs().Graph;Ex={addDummyNode:n,simplify:r,asNonCompoundGraph:s,successorWeights:l,predecessorWeights:c,intersectRect:u,buildLayerMatrix:f,normalizeRanks:p,removeEmptyRanks:h,addBorderNode:m,maxRank:y,partition:v,time:S,notime:b};function n(_,k,j,E){var C;do C=e.uniqueId(E);while(_.hasNode(C));return j.dummy=k,_.setNode(C,j),C}function r(_){var k=new t().setGraph(_.graph());return e.forEach(_.nodes(),function(j){k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){var E=k.edge(j.v,j.w)||{weight:0,minlen:1},C=_.edge(j);k.setEdge(j.v,j.w,{weight:E.weight+C.weight,minlen:Math.max(E.minlen,C.minlen)})}),k}function s(_){var k=new t({multigraph:_.isMultigraph()}).setGraph(_.graph());return e.forEach(_.nodes(),function(j){_.children(j).length||k.setNode(j,_.node(j))}),e.forEach(_.edges(),function(j){k.setEdge(j,_.edge(j))}),k}function l(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.outEdges(j),function(C){E[C.w]=(E[C.w]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function c(_){var k=e.map(_.nodes(),function(j){var E={};return e.forEach(_.inEdges(j),function(C){E[C.v]=(E[C.v]||0)+_.edge(C).weight}),E});return e.zipObject(_.nodes(),k)}function u(_,k){var j=_.x,E=_.y,C=k.x-j,R=k.y-E,I=_.width/2,$=_.height/2;if(!C&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var q,B;return Math.abs(R)*I>Math.abs(C)*$?(R<0&&($=-$),q=$*C/R,B=$):(C<0&&(I=-I),q=I,B=I*R/C),{x:j+q,y:E+B}}function f(_){var k=e.map(e.range(y(_)+1),function(){return[]});return e.forEach(_.nodes(),function(j){var E=_.node(j),C=E.rank;e.isUndefined(C)||(k[C][E.order]=j)}),k}function p(_){var k=e.min(e.map(_.nodes(),function(j){return _.node(j).rank}));e.forEach(_.nodes(),function(j){var E=_.node(j);e.has(E,"rank")&&(E.rank-=k)})}function h(_){var k=e.min(e.map(_.nodes(),function(R){return _.node(R).rank})),j=[];e.forEach(_.nodes(),function(R){var I=_.node(R).rank-k;j[I]||(j[I]=[]),j[I].push(R)});var E=0,C=_.graph().nodeRankFactor;e.forEach(j,function(R,I){e.isUndefined(R)&&I%C!==0?--E:E&&e.forEach(R,function($){_.node($).rank+=E})})}function m(_,k,j,E){var C={width:0,height:0};return arguments.length>=4&&(C.rank=j,C.order=E),n(_,"border",C,k)}function y(_){return e.max(e.map(_.nodes(),function(k){var j=_.node(k).rank;if(!e.isUndefined(j))return j}))}function v(_,k){var j={lhs:[],rhs:[]};return e.forEach(_,function(E){k(E)?j.lhs.push(E):j.rhs.push(E)}),j}function S(_,k){var j=e.now();try{return k()}finally{console.log(_+" time: "+(e.now()-j)+"ms")}}function b(_,k){return k()}return Ex}var Cx,r2;function n9(){if(r2)return Cx;r2=1;var e=Dt(),t=ar();Cx={run:n,undo:s};function n(l){l.graph().dummyChains=[],e.forEach(l.edges(),function(c){r(l,c)})}function r(l,c){var u=c.v,f=l.node(u).rank,p=c.w,h=l.node(p).rank,m=c.name,y=l.edge(c),v=y.labelRank;if(h!==f+1){l.removeEdge(c);var S,b,_;for(_=0,++f;f<h;++_,++f)y.points=[],b={width:0,height:0,edgeLabel:y,edgeObj:c,rank:f},S=t.addDummyNode(l,"edge",b,"_d"),f===v&&(b.width=y.width,b.height=y.height,b.dummy="edge-label",b.labelpos=y.labelpos),l.setEdge(u,S,{weight:y.weight},m),_===0&&l.graph().dummyChains.push(S),u=S;l.setEdge(u,p,{weight:y.weight},m)}}function s(l){e.forEach(l.graph().dummyChains,function(c){var u=l.node(c),f=u.edgeLabel,p;for(l.setEdge(u.edgeObj,f);u.dummy;)p=l.successors(c)[0],l.removeNode(c),f.points.push({x:u.x,y:u.y}),u.dummy==="edge-label"&&(f.x=u.x,f.y=u.y,f.width=u.width,f.height=u.height),c=p,u=l.node(c)})}return Cx}var Tx,s2;function cf(){if(s2)return Tx;s2=1;var e=Dt();Tx={longestPath:t,slack:n};function t(r){var s={};function l(c){var u=r.node(c);if(e.has(s,c))return u.rank;s[c]=!0;var f=e.min(e.map(r.outEdges(c),function(p){return l(p.w)-r.edge(p).minlen}));return(f===Number.POSITIVE_INFINITY||f===void 0||f===null)&&(f=0),u.rank=f}e.forEach(r.sources(),l)}function n(r,s){return r.node(s.w).rank-r.node(s.v).rank-r.edge(s).minlen}return Tx}var Rx,a2;function ZI(){if(a2)return Rx;a2=1;var e=Dt(),t=xs().Graph,n=cf().slack;Rx=r;function r(u){var f=new t({directed:!1}),p=u.nodes()[0],h=u.nodeCount();f.setNode(p,{});for(var m,y;s(f,u)<h;)m=l(f,u),y=f.hasNode(m.v)?n(u,m):-n(u,m),c(f,u,y);return f}function s(u,f){function p(h){e.forEach(f.nodeEdges(h),function(m){var y=m.v,v=h===y?m.w:y;!u.hasNode(v)&&!n(f,m)&&(u.setNode(v,{}),u.setEdge(h,v,{}),p(v))})}return e.forEach(u.nodes(),p),u.nodeCount()}function l(u,f){return e.minBy(f.edges(),function(p){if(u.hasNode(p.v)!==u.hasNode(p.w))return n(f,p)})}function c(u,f,p){e.forEach(u.nodes(),function(h){f.node(h).rank+=p})}return Rx}var Ax,o2;function r9(){if(o2)return Ax;o2=1;var e=Dt(),t=ZI(),n=cf().slack,r=cf().longestPath,s=xs().alg.preorder,l=xs().alg.postorder,c=ar().simplify;Ax=u,u.initLowLimValues=m,u.initCutValues=f,u.calcCutValue=h,u.leaveEdge=v,u.enterEdge=S,u.exchangeEdges=b;function u(E){E=c(E),r(E);var C=t(E);m(C),f(C,E);for(var R,I;R=v(C);)I=S(C,E,R),b(C,E,R,I)}function f(E,C){var R=l(E,E.nodes());R=R.slice(0,R.length-1),e.forEach(R,function(I){p(E,C,I)})}function p(E,C,R){var I=E.node(R),$=I.parent;E.edge(R,$).cutvalue=h(E,C,R)}function h(E,C,R){var I=E.node(R),$=I.parent,q=!0,B=C.edge(R,$),P=0;return B||(q=!1,B=C.edge($,R)),P=B.weight,e.forEach(C.nodeEdges(R),function(W){var ne=W.v===R,ee=ne?W.w:W.v;if(ee!==$){var M=ne===q,X=C.edge(W).weight;if(P+=M?X:-X,k(E,R,ee)){var V=E.edge(R,ee).cutvalue;P+=M?-V:V}}}),P}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,R,I,$){var q=R,B=E.node(I);return C[I]=!0,e.forEach(E.neighbors(I),function(P){e.has(C,P)||(R=y(E,C,R,P,I))}),B.low=q,B.lim=R++,$?B.parent=$:delete B.parent,R}function v(E){return e.find(E.edges(),function(C){return E.edge(C).cutvalue<0})}function S(E,C,R){var I=R.v,$=R.w;C.hasEdge(I,$)||(I=R.w,$=R.v);var q=E.node(I),B=E.node($),P=q,W=!1;q.lim>B.lim&&(P=B,W=!0);var ne=e.filter(C.edges(),function(ee){return W===j(E,E.node(ee.v),P)&&W!==j(E,E.node(ee.w),P)});return e.minBy(ne,function(ee){return n(C,ee)})}function b(E,C,R,I){var $=R.v,q=R.w;E.removeEdge($,q),E.setEdge(I.v,I.w,{}),m(E),f(E,C),_(E,C)}function _(E,C){var R=e.find(E.nodes(),function($){return!C.node($).parent}),I=s(E,R);I=I.slice(1),e.forEach(I,function($){var q=E.node($).parent,B=C.edge($,q),P=!1;B||(B=C.edge(q,$),P=!0),C.node($).rank=C.node(q).rank+(P?B.minlen:-B.minlen)})}function k(E,C,R){return E.hasEdge(C,R)}function j(E,C,R){return R.low<=C.lim&&C.lim<=R.lim}return Ax}var Mx,i2;function s9(){if(i2)return Mx;i2=1;var e=cf(),t=e.longestPath,n=ZI(),r=r9();Mx=s;function s(f){switch(f.graph().ranker){case"network-simplex":u(f);break;case"tight-tree":c(f);break;case"longest-path":l(f);break;default:u(f)}}var l=t;function c(f){t(f),n(f)}function u(f){r(f)}return Mx}var Ix,l2;function a9(){if(l2)return Ix;l2=1;var e=Dt();Ix=t;function t(s){var l=r(s);e.forEach(s.graph().dummyChains,function(c){for(var u=s.node(c),f=u.edgeObj,p=n(s,l,f.v,f.w),h=p.path,m=p.lca,y=0,v=h[y],S=!0;c!==f.w;){if(u=s.node(c),S){for(;(v=h[y])!==m&&s.node(v).maxRank<u.rank;)y++;v===m&&(S=!1)}if(!S){for(;y<h.length-1&&s.node(v=h[y+1]).minRank<=u.rank;)y++;v=h[y]}s.setParent(c,v),c=s.successors(c)[0]}})}function n(s,l,c,u){var f=[],p=[],h=Math.min(l[c].low,l[u].low),m=Math.max(l[c].lim,l[u].lim),y,v;y=c;do y=s.parent(y),f.push(y);while(y&&(l[y].low>h||m>l[y].lim));for(v=y,y=u;(y=s.parent(y))!==v;)p.push(y);return{path:f.concat(p.reverse()),lca:v}}function r(s){var l={},c=0;function u(f){var p=c;e.forEach(s.children(f),u),l[f]={low:p,lim:c++}}return e.forEach(s.children(),u),l}return Ix}var $x,c2;function o9(){if(c2)return $x;c2=1;var e=Dt(),t=ar();$x={run:n,cleanup:c};function n(u){var f=t.addDummyNode(u,"root",{},"_root"),p=s(u),h=e.max(e.values(p))-1,m=2*h+1;u.graph().nestingRoot=f,e.forEach(u.edges(),function(v){u.edge(v).minlen*=m});var y=l(u)+1;e.forEach(u.children(),function(v){r(u,f,m,y,h,p,v)}),u.graph().nodeRankFactor=m}function r(u,f,p,h,m,y,v){var S=u.children(v);if(!S.length){v!==f&&u.setEdge(f,v,{weight:0,minlen:p});return}var b=t.addBorderNode(u,"_bt"),_=t.addBorderNode(u,"_bb"),k=u.node(v);u.setParent(b,v),k.borderTop=b,u.setParent(_,v),k.borderBottom=_,e.forEach(S,function(j){r(u,f,p,h,m,y,j);var E=u.node(j),C=E.borderTop?E.borderTop:j,R=E.borderBottom?E.borderBottom:j,I=E.borderTop?h:2*h,$=C!==R?1:m-y[v]+1;u.setEdge(b,C,{weight:I,minlen:$,nestingEdge:!0}),u.setEdge(R,_,{weight:I,minlen:$,nestingEdge:!0})}),u.parent(v)||u.setEdge(f,b,{weight:0,minlen:m+y[v]})}function s(u){var f={};function p(h,m){var y=u.children(h);y&&y.length&&e.forEach(y,function(v){p(v,m+1)}),f[h]=m}return e.forEach(u.children(),function(h){p(h,1)}),f}function l(u){return e.reduce(u.edges(),function(f,p){return f+u.edge(p).weight},0)}function c(u){var f=u.graph();u.removeNode(f.nestingRoot),delete f.nestingRoot,e.forEach(u.edges(),function(p){var h=u.edge(p);h.nestingEdge&&u.removeEdge(p)})}return $x}var Ox,u2;function i9(){if(u2)return Ox;u2=1;var e=Dt(),t=ar();Ox=n;function n(s){function l(c){var u=s.children(c),f=s.node(c);if(u.length&&e.forEach(u,l),e.has(f,"minRank")){f.borderLeft=[],f.borderRight=[];for(var p=f.minRank,h=f.maxRank+1;p<h;++p)r(s,"borderLeft","_bl",c,f,p),r(s,"borderRight","_br",c,f,p)}}e.forEach(s.children(),l)}function r(s,l,c,u,f,p){var h={width:0,height:0,rank:p,borderType:l},m=f[l][p-1],y=t.addDummyNode(s,"border",h,c);f[l][p]=y,s.setParent(y,u),m&&s.setEdge(m,y,{weight:1})}return Ox}var Lx,d2;function l9(){if(d2)return Lx;d2=1;var e=Dt();Lx={adjust:t,undo:n};function t(p){var h=p.graph().rankdir.toLowerCase();(h==="lr"||h==="rl")&&r(p)}function n(p){var h=p.graph().rankdir.toLowerCase();(h==="bt"||h==="rl")&&l(p),(h==="lr"||h==="rl")&&(u(p),r(p))}function r(p){e.forEach(p.nodes(),function(h){s(p.node(h))}),e.forEach(p.edges(),function(h){s(p.edge(h))})}function s(p){var h=p.width;p.width=p.height,p.height=h}function l(p){e.forEach(p.nodes(),function(h){c(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,c),e.has(m,"y")&&c(m)})}function c(p){p.y=-p.y}function u(p){e.forEach(p.nodes(),function(h){f(p.node(h))}),e.forEach(p.edges(),function(h){var m=p.edge(h);e.forEach(m.points,f),e.has(m,"x")&&f(m)})}function f(p){var h=p.x;p.x=p.y,p.y=h}return Lx}var Px,h2;function c9(){if(h2)return Px;h2=1;var e=Dt();Px=t;function t(n){var r={},s=e.filter(n.nodes(),function(p){return!n.children(p).length}),l=e.max(e.map(s,function(p){return n.node(p).rank})),c=e.map(e.range(l+1),function(){return[]});function u(p){if(!e.has(r,p)){r[p]=!0;var h=n.node(p);c[h.rank].push(p),e.forEach(n.successors(p),u)}}var f=e.sortBy(s,function(p){return n.node(p).rank});return e.forEach(f,u),c}return Px}var Dx,f2;function u9(){if(f2)return Dx;f2=1;var e=Dt();Dx=t;function t(r,s){for(var l=0,c=1;c<s.length;++c)l+=n(r,s[c-1],s[c]);return l}function n(r,s,l){for(var c=e.zipObject(l,e.map(l,function(y,v){return v})),u=e.flatten(e.map(s,function(y){return e.sortBy(e.map(r.outEdges(y),function(v){return{pos:c[v.w],weight:r.edge(v).weight}}),"pos")}),!0),f=1;f<l.length;)f<<=1;var p=2*f-1;f-=1;var h=e.map(new Array(p),function(){return 0}),m=0;return e.forEach(u.forEach(function(y){var v=y.pos+f;h[v]+=y.weight;for(var S=0;v>0;)v%2&&(S+=h[v+1]),v=v-1>>1,h[v]+=y.weight;m+=y.weight*S})),m}return Dx}var Fx,p2;function d9(){if(p2)return Fx;p2=1;var e=Dt();Fx=t;function t(n,r){return e.map(r,function(s){var l=n.inEdges(s);if(l.length){var c=e.reduce(l,function(u,f){var p=n.edge(f),h=n.node(f.v);return{sum:u.sum+p.weight*h.order,weight:u.weight+p.weight}},{sum:0,weight:0});return{v:s,barycenter:c.sum/c.weight,weight:c.weight}}else return{v:s}})}return Fx}var qx,m2;function h9(){if(m2)return qx;m2=1;var e=Dt();qx=t;function t(s,l){var c={};e.forEach(s,function(f,p){var h=c[f.v]={indegree:0,in:[],out:[],vs:[f.v],i:p};e.isUndefined(f.barycenter)||(h.barycenter=f.barycenter,h.weight=f.weight)}),e.forEach(l.edges(),function(f){var p=c[f.v],h=c[f.w];!e.isUndefined(p)&&!e.isUndefined(h)&&(h.indegree++,p.out.push(c[f.w]))});var u=e.filter(c,function(f){return!f.indegree});return n(u)}function n(s){var l=[];function c(p){return function(h){h.merged||(e.isUndefined(h.barycenter)||e.isUndefined(p.barycenter)||h.barycenter>=p.barycenter)&&r(p,h)}}function u(p){return function(h){h.in.push(p),--h.indegree===0&&s.push(h)}}for(;s.length;){var f=s.pop();l.push(f),e.forEach(f.in.reverse(),c(f)),e.forEach(f.out,u(f))}return e.map(e.filter(l,function(p){return!p.merged}),function(p){return e.pick(p,["vs","i","barycenter","weight"])})}function r(s,l){var c=0,u=0;s.weight&&(c+=s.barycenter*s.weight,u+=s.weight),l.weight&&(c+=l.barycenter*l.weight,u+=l.weight),s.vs=l.vs.concat(s.vs),s.barycenter=c/u,s.weight=u,s.i=Math.min(l.i,s.i),l.merged=!0}return qx}var Bx,g2;function f9(){if(g2)return Bx;g2=1;var e=Dt(),t=ar();Bx=n;function n(l,c){var u=t.partition(l,function(b){return e.has(b,"barycenter")}),f=u.lhs,p=e.sortBy(u.rhs,function(b){return-b.i}),h=[],m=0,y=0,v=0;f.sort(s(!!c)),v=r(h,p,v),e.forEach(f,function(b){v+=b.vs.length,h.push(b.vs),m+=b.barycenter*b.weight,y+=b.weight,v=r(h,p,v)});var S={vs:e.flatten(h,!0)};return y&&(S.barycenter=m/y,S.weight=y),S}function r(l,c,u){for(var f;c.length&&(f=e.last(c)).i<=u;)c.pop(),l.push(f.vs),u++;return u}function s(l){return function(c,u){return c.barycenter<u.barycenter?-1:c.barycenter>u.barycenter?1:l?u.i-c.i:c.i-u.i}}return Bx}var zx,y2;function p9(){if(y2)return zx;y2=1;var e=Dt(),t=d9(),n=h9(),r=f9();zx=s;function s(u,f,p,h){var m=u.children(f),y=u.node(f),v=y?y.borderLeft:void 0,S=y?y.borderRight:void 0,b={};v&&(m=e.filter(m,function(R){return R!==v&&R!==S}));var _=t(u,m);e.forEach(_,function(R){if(u.children(R.v).length){var I=s(u,R.v,p,h);b[R.v]=I,e.has(I,"barycenter")&&c(R,I)}});var k=n(_,p);l(k,b);var j=r(k,h);if(v&&(j.vs=e.flatten([v,j.vs,S],!0),u.predecessors(v).length)){var E=u.node(u.predecessors(v)[0]),C=u.node(u.predecessors(S)[0]);e.has(j,"barycenter")||(j.barycenter=0,j.weight=0),j.barycenter=(j.barycenter*j.weight+E.order+C.order)/(j.weight+2),j.weight+=2}return j}function l(u,f){e.forEach(u,function(p){p.vs=e.flatten(p.vs.map(function(h){return f[h]?f[h].vs:h}),!0)})}function c(u,f){e.isUndefined(u.barycenter)?(u.barycenter=f.barycenter,u.weight=f.weight):(u.barycenter=(u.barycenter*u.weight+f.barycenter*f.weight)/(u.weight+f.weight),u.weight+=f.weight)}return zx}var Ux,w2;function m9(){if(w2)return Ux;w2=1;var e=Dt(),t=xs().Graph;Ux=n;function n(s,l,c){var u=r(s),f=new t({compound:!0}).setGraph({root:u}).setDefaultNodeLabel(function(p){return s.node(p)});return e.forEach(s.nodes(),function(p){var h=s.node(p),m=s.parent(p);(h.rank===l||h.minRank<=l&&l<=h.maxRank)&&(f.setNode(p),f.setParent(p,m||u),e.forEach(s[c](p),function(y){var v=y.v===p?y.w:y.v,S=f.edge(v,p),b=e.isUndefined(S)?0:S.weight;f.setEdge(v,p,{weight:s.edge(y).weight+b})}),e.has(h,"minRank")&&f.setNode(p,{borderLeft:h.borderLeft[l],borderRight:h.borderRight[l]}))}),f}function r(s){for(var l;s.hasNode(l=e.uniqueId("_root")););return l}return Ux}var Hx,v2;function g9(){if(v2)return Hx;v2=1;var e=Dt();Hx=t;function t(n,r,s){var l={},c;e.forEach(s,function(u){for(var f=n.parent(u),p,h;f;){if(p=n.parent(f),p?(h=l[p],l[p]=f):(h=c,c=f),h&&h!==f){r.setEdge(h,f);return}f=p}})}return Hx}var Wx,x2;function y9(){if(x2)return Wx;x2=1;var e=Dt(),t=c9(),n=u9(),r=p9(),s=m9(),l=g9(),c=xs().Graph,u=ar();Wx=f;function f(y){var v=u.maxRank(y),S=p(y,e.range(1,v+1),"inEdges"),b=p(y,e.range(v-1,-1,-1),"outEdges"),_=t(y);m(y,_);for(var k=Number.POSITIVE_INFINITY,j,E=0,C=0;C<4;++E,++C){h(E%2?S:b,E%4>=2),_=u.buildLayerMatrix(y);var R=n(y,_);R<k&&(C=0,j=e.cloneDeep(_),k=R)}m(y,j)}function p(y,v,S){return e.map(v,function(b){return s(y,b,S)})}function h(y,v){var S=new c;e.forEach(y,function(b){var _=b.graph().root,k=r(b,_,S,v);e.forEach(k.vs,function(j,E){b.node(j).order=E}),l(b,S,k.vs)})}function m(y,v){e.forEach(v,function(S){e.forEach(S,function(b,_){y.node(b).order=_})})}return Wx}var Vx,b2;function w9(){if(b2)return Vx;b2=1;var e=Dt(),t=xs().Graph,n=ar();Vx={positionX:S,findType1Conflicts:r,findType2Conflicts:s,addConflict:c,hasConflict:u,verticalAlignment:f,horizontalCompaction:p,alignCoordinates:y,findSmallestWidthAlignment:m,balance:v};function r(k,j){var E={};function C(R,I){var $=0,q=0,B=R.length,P=e.last(I);return e.forEach(I,function(W,ne){var ee=l(k,W),M=ee?k.node(ee).order:B;(ee||W===P)&&(e.forEach(I.slice(q,ne+1),function(X){e.forEach(k.predecessors(X),function(V){var G=k.node(V),F=G.order;(F<$||M<F)&&!(G.dummy&&k.node(X).dummy)&&c(E,V,X)})}),q=ne+1,$=M)}),I}return e.reduce(j,C),E}function s(k,j){var E={};function C(I,$,q,B,P){var W;e.forEach(e.range($,q),function(ne){W=I[ne],k.node(W).dummy&&e.forEach(k.predecessors(W),function(ee){var M=k.node(ee);M.dummy&&(M.order<B||M.order>P)&&c(E,ee,W)})})}function R(I,$){var q=-1,B,P=0;return e.forEach($,function(W,ne){if(k.node(W).dummy==="border"){var ee=k.predecessors(W);ee.length&&(B=k.node(ee[0]).order,C($,P,ne,q,B),P=ne,q=B)}C($,P,$.length,B,I.length)}),$}return e.reduce(j,R),E}function l(k,j){if(k.node(j).dummy)return e.find(k.predecessors(j),function(E){return k.node(E).dummy})}function c(k,j,E){if(j>E){var C=j;j=E,E=C}var R=k[j];R||(k[j]=R={}),R[E]=!0}function u(k,j,E){if(j>E){var C=j;j=E,E=C}return e.has(k[j],E)}function f(k,j,E,C){var R={},I={},$={};return e.forEach(j,function(q){e.forEach(q,function(B,P){R[B]=B,I[B]=B,$[B]=P})}),e.forEach(j,function(q){var B=-1;e.forEach(q,function(P){var W=C(P);if(W.length){W=e.sortBy(W,function(V){return $[V]});for(var ne=(W.length-1)/2,ee=Math.floor(ne),M=Math.ceil(ne);ee<=M;++ee){var X=W[ee];I[P]===P&&B<$[X]&&!u(E,P,X)&&(I[X]=P,I[P]=R[P]=R[X],B=$[X])}}})}),{root:R,align:I}}function p(k,j,E,C,R){var I={},$=h(k,j,E,R),q=R?"borderLeft":"borderRight";function B(ne,ee){for(var M=$.nodes(),X=M.pop(),V={};X;)V[X]?ne(X):(V[X]=!0,M.push(X),M=M.concat(ee(X))),X=M.pop()}function P(ne){I[ne]=$.inEdges(ne).reduce(function(ee,M){return Math.max(ee,I[M.v]+$.edge(M))},0)}function W(ne){var ee=$.outEdges(ne).reduce(function(X,V){return Math.min(X,I[V.w]-$.edge(V))},Number.POSITIVE_INFINITY),M=k.node(ne);ee!==Number.POSITIVE_INFINITY&&M.borderType!==q&&(I[ne]=Math.max(I[ne],ee))}return B(P,$.predecessors.bind($)),B(W,$.successors.bind($)),e.forEach(C,function(ne){I[ne]=I[E[ne]]}),I}function h(k,j,E,C){var R=new t,I=k.graph(),$=b(I.nodesep,I.edgesep,C);return e.forEach(j,function(q){var B;e.forEach(q,function(P){var W=E[P];if(R.setNode(W),B){var ne=E[B],ee=R.edge(ne,W);R.setEdge(ne,W,Math.max($(k,P,B),ee||0))}B=P})}),R}function m(k,j){return e.minBy(e.values(j),function(E){var C=Number.NEGATIVE_INFINITY,R=Number.POSITIVE_INFINITY;return e.forIn(E,function(I,$){var q=_(k,$)/2;C=Math.max(I+q,C),R=Math.min(I-q,R)}),C-R})}function y(k,j){var E=e.values(j),C=e.min(E),R=e.max(E);e.forEach(["u","d"],function(I){e.forEach(["l","r"],function($){var q=I+$,B=k[q],P;if(B!==j){var W=e.values(B);P=$==="l"?C-e.min(W):R-e.max(W),P&&(k[q]=e.mapValues(B,function(ne){return ne+P}))}})})}function v(k,j){return e.mapValues(k.ul,function(E,C){if(j)return k[j.toLowerCase()][C];var R=e.sortBy(e.map(k,C));return(R[1]+R[2])/2})}function S(k){var j=n.buildLayerMatrix(k),E=e.merge(r(k,j),s(k,j)),C={},R;e.forEach(["u","d"],function($){R=$==="u"?j:e.values(j).reverse(),e.forEach(["l","r"],function(q){q==="r"&&(R=e.map(R,function(ne){return e.values(ne).reverse()}));var B=($==="u"?k.predecessors:k.successors).bind(k),P=f(k,R,E,B),W=p(k,R,P.root,P.align,q==="r");q==="r"&&(W=e.mapValues(W,function(ne){return-ne})),C[$+q]=W})});var I=m(k,C);return y(C,I),v(C,k.graph().align)}function b(k,j,E){return function(C,R,I){var $=C.node(R),q=C.node(I),B=0,P;if(B+=$.width/2,e.has($,"labelpos"))switch($.labelpos.toLowerCase()){case"l":P=-$.width/2;break;case"r":P=$.width/2;break}if(P&&(B+=E?P:-P),P=0,B+=($.dummy?j:k)/2,B+=(q.dummy?j:k)/2,B+=q.width/2,e.has(q,"labelpos"))switch(q.labelpos.toLowerCase()){case"l":P=q.width/2;break;case"r":P=-q.width/2;break}return P&&(B+=E?P:-P),P=0,B}}function _(k,j){return k.node(j).width}return Vx}var Gx,k2;function v9(){if(k2)return Gx;k2=1;var e=Dt(),t=ar(),n=w9().positionX;Gx=r;function r(l){l=t.asNonCompoundGraph(l),s(l),e.forEach(n(l),function(c,u){l.node(u).x=c})}function s(l){var c=t.buildLayerMatrix(l),u=l.graph().ranksep,f=0;e.forEach(c,function(p){var h=e.max(e.map(p,function(m){return l.node(m).height}));e.forEach(p,function(m){l.node(m).y=f+h/2}),f+=h+u})}return Gx}var Kx,N2;function x9(){if(N2)return Kx;N2=1;var e=Dt(),t=t9(),n=n9(),r=s9(),s=ar().normalizeRanks,l=a9(),c=ar().removeEmptyRanks,u=o9(),f=i9(),p=l9(),h=y9(),m=v9(),y=ar(),v=xs().Graph;Kx=S;function S(z,Z){var U=Z&&Z.debugTiming?y.time:y.notime;U("layout",function(){var ae=U(" buildLayoutGraph",function(){return B(z)});U(" runLayout",function(){b(ae,U)}),U(" updateInputGraph",function(){_(z,ae)})})}function b(z,Z){Z(" makeSpaceForEdgeLabels",function(){P(z)}),Z(" removeSelfEdges",function(){L(z)}),Z(" acyclic",function(){t.run(z)}),Z(" nestingGraph.run",function(){u.run(z)}),Z(" rank",function(){r(y.asNonCompoundGraph(z))}),Z(" injectEdgeLabelProxies",function(){W(z)}),Z(" removeEmptyRanks",function(){c(z)}),Z(" nestingGraph.cleanup",function(){u.cleanup(z)}),Z(" normalizeRanks",function(){s(z)}),Z(" assignRankMinMax",function(){ne(z)}),Z(" removeEdgeLabelProxies",function(){ee(z)}),Z(" normalize.run",function(){n.run(z)}),Z(" parentDummyChains",function(){l(z)}),Z(" addBorderSegments",function(){f(z)}),Z(" order",function(){h(z)}),Z(" insertSelfEdges",function(){H(z)}),Z(" adjustCoordinateSystem",function(){p.adjust(z)}),Z(" position",function(){m(z)}),Z(" positionSelfEdges",function(){D(z)}),Z(" removeBorderNodes",function(){F(z)}),Z(" normalize.undo",function(){n.undo(z)}),Z(" fixupEdgeLabelCoords",function(){V(z)}),Z(" undoCoordinateSystem",function(){p.undo(z)}),Z(" translateGraph",function(){M(z)}),Z(" assignNodeIntersects",function(){X(z)}),Z(" reversePoints",function(){G(z)}),Z(" acyclic.undo",function(){t.undo(z)})}function _(z,Z){e.forEach(z.nodes(),function(U){var ae=z.node(U),le=Z.node(U);ae&&(ae.x=le.x,ae.y=le.y,Z.children(U).length&&(ae.width=le.width,ae.height=le.height))}),e.forEach(z.edges(),function(U){var ae=z.edge(U),le=Z.edge(U);ae.points=le.points,e.has(le,"x")&&(ae.x=le.x,ae.y=le.y)}),z.graph().width=Z.graph().width,z.graph().height=Z.graph().height}var k=["nodesep","edgesep","ranksep","marginx","marginy"],j={ranksep:50,edgesep:20,nodesep:50,rankdir:"tb"},E=["acyclicer","ranker","rankdir","align"],C=["width","height"],R={width:0,height:0},I=["minlen","weight","width","height","labeloffset"],$={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},q=["labelpos"];function B(z){var Z=new v({multigraph:!0,compound:!0}),U=re(z.graph());return Z.setGraph(e.merge({},j,K(U,k),e.pick(U,E))),e.forEach(z.nodes(),function(ae){var le=re(z.node(ae));Z.setNode(ae,e.defaults(K(le,C),R)),Z.setParent(ae,z.parent(ae))}),e.forEach(z.edges(),function(ae){var le=re(z.edge(ae));Z.setEdge(ae,e.merge({},$,K(le,I),e.pick(le,q)))}),Z}function P(z){var Z=z.graph();Z.ranksep/=2,e.forEach(z.edges(),function(U){var ae=z.edge(U);ae.minlen*=2,ae.labelpos.toLowerCase()!=="c"&&(Z.rankdir==="TB"||Z.rankdir==="BT"?ae.width+=ae.labeloffset:ae.height+=ae.labeloffset)})}function W(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z);if(U.width&&U.height){var ae=z.node(Z.v),le=z.node(Z.w),ge={rank:(le.rank-ae.rank)/2+ae.rank,e:Z};y.addDummyNode(z,"edge-proxy",ge,"_ep")}})}function ne(z){var Z=0;e.forEach(z.nodes(),function(U){var ae=z.node(U);ae.borderTop&&(ae.minRank=z.node(ae.borderTop).rank,ae.maxRank=z.node(ae.borderBottom).rank,Z=e.max(Z,ae.maxRank))}),z.graph().maxRank=Z}function ee(z){e.forEach(z.nodes(),function(Z){var U=z.node(Z);U.dummy==="edge-proxy"&&(z.edge(U.e).labelRank=U.rank,z.removeNode(Z))})}function M(z){var Z=Number.POSITIVE_INFINITY,U=0,ae=Number.POSITIVE_INFINITY,le=0,ge=z.graph(),Ne=ge.marginx||0,Ie=ge.marginy||0;function Ge(Pe){var ze=Pe.x,Re=Pe.y,st=Pe.width,ue=Pe.height;Z=Math.min(Z,ze-st/2),U=Math.max(U,ze+st/2),ae=Math.min(ae,Re-ue/2),le=Math.max(le,Re+ue/2)}e.forEach(z.nodes(),function(Pe){Ge(z.node(Pe))}),e.forEach(z.edges(),function(Pe){var ze=z.edge(Pe);e.has(ze,"x")&&Ge(ze)}),Z-=Ne,ae-=Ie,e.forEach(z.nodes(),function(Pe){var ze=z.node(Pe);ze.x-=Z,ze.y-=ae}),e.forEach(z.edges(),function(Pe){var ze=z.edge(Pe);e.forEach(ze.points,function(Re){Re.x-=Z,Re.y-=ae}),e.has(ze,"x")&&(ze.x-=Z),e.has(ze,"y")&&(ze.y-=ae)}),ge.width=U-Z+Ne,ge.height=le-ae+Ie}function X(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z),ae=z.node(Z.v),le=z.node(Z.w),ge,Ne;U.points?(ge=U.points[0],Ne=U.points[U.points.length-1]):(U.points=[],ge=le,Ne=ae),U.points.unshift(y.intersectRect(ae,ge)),U.points.push(y.intersectRect(le,Ne))})}function V(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z);if(e.has(U,"x"))switch((U.labelpos==="l"||U.labelpos==="r")&&(U.width-=U.labeloffset),U.labelpos){case"l":U.x-=U.width/2+U.labeloffset;break;case"r":U.x+=U.width/2+U.labeloffset;break}})}function G(z){e.forEach(z.edges(),function(Z){var U=z.edge(Z);U.reversed&&U.points.reverse()})}function F(z){e.forEach(z.nodes(),function(Z){if(z.children(Z).length){var U=z.node(Z),ae=z.node(U.borderTop),le=z.node(U.borderBottom),ge=z.node(e.last(U.borderLeft)),Ne=z.node(e.last(U.borderRight));U.width=Math.abs(Ne.x-ge.x),U.height=Math.abs(le.y-ae.y),U.x=ge.x+U.width/2,U.y=ae.y+U.height/2}}),e.forEach(z.nodes(),function(Z){z.node(Z).dummy==="border"&&z.removeNode(Z)})}function L(z){e.forEach(z.edges(),function(Z){if(Z.v===Z.w){var U=z.node(Z.v);U.selfEdges||(U.selfEdges=[]),U.selfEdges.push({e:Z,label:z.edge(Z)}),z.removeEdge(Z)}})}function H(z){var Z=y.buildLayerMatrix(z);e.forEach(Z,function(U){var ae=0;e.forEach(U,function(le,ge){var Ne=z.node(le);Ne.order=ge+ae,e.forEach(Ne.selfEdges,function(Ie){y.addDummyNode(z,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Ne.rank,order:ge+ ++ae,e:Ie.e,label:Ie.label},"_se")}),delete Ne.selfEdges})})}function D(z){e.forEach(z.nodes(),function(Z){var U=z.node(Z);if(U.dummy==="selfedge"){var ae=z.node(U.e.v),le=ae.x+ae.width/2,ge=ae.y,Ne=U.x-le,Ie=ae.height/2;z.setEdge(U.e,U.label),z.removeNode(Z),U.label.points=[{x:le+2*Ne/3,y:ge-Ie},{x:le+5*Ne/6,y:ge-Ie},{x:le+Ne,y:ge},{x:le+5*Ne/6,y:ge+Ie},{x:le+2*Ne/3,y:ge+Ie}],U.label.x=U.x,U.label.y=U.y}})}function K(z,Z){return e.mapValues(e.pick(z,Z),Number)}function re(z){var Z={};return e.forEach(z,function(U,ae){Z[ae.toLowerCase()]=U}),Z}return Kx}var Yx,S2;function b9(){if(S2)return Yx;S2=1;var e=Dt(),t=ar(),n=xs().Graph;Yx={debugOrdering:r};function r(s){var l=t.buildLayerMatrix(s),c=new n({compound:!0,multigraph:!0}).setGraph({});return e.forEach(s.nodes(),function(u){c.setNode(u,{label:u}),c.setParent(u,"layer"+s.node(u).rank)}),e.forEach(s.edges(),function(u){c.setEdge(u.v,u.w,{},u.name)}),e.forEach(l,function(u,f){var p="layer"+f;c.setNode(p,{rank:"same"}),e.reduce(u,function(h,m){return c.setEdge(h,m,{style:"invis"}),m})}),c}return Yx}var Xx,j2;function k9(){return j2||(j2=1,Xx="0.8.5"),Xx}var Zx,_2;function N9(){return _2||(_2=1,Zx={graphlib:xs(),layout:x9(),debug:b9(),util:{time:ar().time,notime:ar().notime},version:k9()}),Zx}var S9=N9();const E2=sb(S9),vi=240,Lu=130,zl=74,Qf=72,wu=zl+Qf;function QI(e,t){var r;let n=vi;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??vi);return n}const uf=420,JI=1;function j9(e,t,n,r){return Math.min(JI,n/Math.max(1,e),r/Math.max(1,t))}function xi(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function _9(e,t){return((t==null?void 0:t.get(e))??0)>0?uf:0}function E9(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function Pu(e,t,n){const r=t.get(e);return{w:((r==null?void 0:r.width)??vi)+_9(e,n),h:Math.max((r==null?void 0:r.height)??Lu,E9(e,n))}}function C9(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function T9(e,t,n,r,s,l){const c=new E2.graphlib.Graph;c.setDefaultEdgeLabel(()=>({})),c.setGraph({rankdir:n,marginx:0,marginy:0,nodesep:70,ranksep:160,edgesep:30});const u=e.filter(k=>!s.has(k)),f=new Set(u);for(const k of u){const{w:j,h:E}=Pu(k,r,l);c.setNode(k,{width:j,height:E})}for(const k of t)f.has(k.source)&&f.has(k.target)&&c.setEdge(k.source,k.target);E2.layout(c);const p=new Map;let h=1/0,m=1/0,y=-1/0,v=-1/0;for(const k of u){const j=c.node(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??vi,R=(E==null?void 0:E.height)??Lu,I=Pu(k,r,l),$=j.x-I.w/2,q=j.y-I.h/2;p.set(k,{x:$,y:q}),$<h&&(h=$),q<m&&(m=q),$+C>y&&(y=$+C),q+R>v&&(v=q+R)}if(Number.isFinite(h)&&Number.isFinite(m))for(const[k,j]of p)p.set(k,{x:j.x-h,y:j.y-m});const S=Number.isFinite(y)?y-h:0,b=Number.isFinite(v)?v-m:0;let _=null;for(const k of e){const j=s.get(k);if(!j)continue;const E=r.get(k),C=(E==null?void 0:E.width)??vi,R=(E==null?void 0:E.height)??Lu;_=_===null?{minX:j.x,minY:j.y,maxX:j.x+C,maxY:j.y+R}:{minX:Math.min(_.minX,j.x),minY:Math.min(_.minY,j.y),maxX:Math.max(_.maxX,j.x+C),maxY:Math.max(_.maxY,j.y+R)}}return{positions:p,width:S,height:b,pinnedBox:_}}function e$(e,t,n){const r=n.direction??"LR",s=n.pinned??new Map,l=n.measured??new Map,c=n.lanes,u=new Map;for(const h of e){const m=xi(h),y=u.get(m);y?y.push(h.id):u.set(m,[h.id])}return{laid:Array.from(u.keys()).sort().map(h=>({sid:h,...T9(u.get(h),t,r,l,s,c)})),gap:QI(e,l)}}const t$=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+uf,R9=e=>e.reduce((t,n)=>t+n.height,0)+wu*Math.max(0,e.length-1);function H0(e,t,n,r){const s=f=>{const p=[[]];let h=0;for(const m of e)h>0&&h+m.height>f&&(p.push([]),h=0),p[p.length-1].push(m),h+=m.height+wu;return p},l=[];for(let f=0;f<e.length;f++){let p=-wu;for(let h=f;h<e.length;h++)l.push(p+=e[h].height+wu)}l.sort((f,p)=>f-p);const c=f=>{let p=0,h=l.length-1;for(;p<h;){const m=p+h>>1;s(l[m]).length<=f?h=m:p=m+1}return s(l[p])};let u=[e];if(n>0&&r>0){const f=h=>j9(h.reduce((m,y)=>m+t$(y),0)+t*(h.length-1),Math.max(...h.map(R9)),n,r);let p=f(u);for(let h=2;h<=e.length;h++){const m=c(h),y=f(m);y>p+1e-9&&(p=y,u=m)}}return u}function A9(e,t,n,r,s){if(!(r.width>0&&r.height>0&&s.width>0&&s.height>0))return!1;const{laid:l,gap:c}=e$(e,t,n);return l.length<2?!1:H0(l,c,r.width,r.height).length!==H0(l,c,s.width,s.height).length}function M9(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:l}=e$(e,t,n),c=H0(s,l,n.availableWidth??0,n.availableHeight??0),u=new Map;let f=0;for(const p of c){const h=t$(p);let m=0;for(const{positions:y,height:v,pinnedBox:S}of p){for(const[_,k]of y)u.set(_,{x:k.x+f,y:k.y+m});let b=m+v;S&&S.maxY>b&&S.minX<f+h&&f<S.maxX&&(b=S.maxY),m=b+wu}f+=h+l}return e.map(p=>{const h=r.get(p.id);if(h)return{...p,position:h};const m=u.get(p.id);return m?{...p,position:m}:p})}function I9(e,t,n,r,s){const c=zl+Qf,u=60,f=v=>Pu(v,r,s),p=new Map(e.map(v=>[v.id,xi(v)])),h=[],m=e.map(v=>({id:v.id,pos:n.get(v.id)??t.get(v.id)})).filter(v=>v.pos!=null).sort((v,S)=>v.pos.y-S.pos.y||v.pos.x-S.pos.x||v.id.localeCompare(S.id)),y=[];for(const{id:v,pos:S}of m){const{w:b,h:_}=f(v),k=p.get(v)??"_default";if(n.has(v)){h.push({x:S.x,y:S.y,w:b,h:_,sid:k});continue}let j=S.y;for(let E=0;E<h.length+1;E++){const C=h.find(R=>{const I=R.sid===k?24:u,$=R.sid===k?24:c;return S.x<R.x+R.w+I&&R.x<S.x+b+I&&j<R.y+R.h+$&&R.y<j+_+$});if(!C)break;j=C.y+C.h+(C.sid===k?24:c)}j!==S.y&&(t.set(v,{x:S.x,y:j}),y.push(v)),h.push({x:S.x,y:j,w:b,h:_,sid:k})}return y}function $9(e,t,n,r,s,l,c){const u=E=>Pu(E,r,l),f=E=>n.get(E)??t.get(E),p=E=>{const C=r.get(E);return{cw:(C==null?void 0:C.width)??vi,ch:(C==null?void 0:C.height)??Lu}},h=c!=null&&c.width>0&&c.height>0,m=new Map;for(const E of e){if(!f(E.id))continue;const C=xi(E),R=m.get(C);R?R.push(E):m.set(C,[E])}const y=new Set;for(const[E,C]of m)C.every(R=>s.has(R.id)&&!n.has(R.id))&&y.add(E);const v=new Map,S=[];for(const E of e){const C=f(E.id);if(!C)continue;const{w:R,h:I}=u(E.id),$=xi(E);y.has($)?(v.get($)??v.set($,[]).get($)).push(E):S.push({x:C.x,y:C.y,w:R,h:I,...p(E.id)})}if(v.size===0||h&&S.length===0)return[];const b=zl+Qf,_=(E,C,R,I)=>S.some($=>E<$.x+$.w+zl&&$.x<E+R+zl&&C<$.y+$.h+b&&$.y<C+I+b),k=QI(e,r),j=[];for(const E of[...v.keys()].sort()){const C=v.get(E);let R=1/0,I=1/0,$=-1/0,q=-1/0,B=-1/0,P=-1/0;for(const G of C){const F=f(G.id),{w:L,h:H}=u(G.id),{cw:D,ch:K}=p(G.id);R=Math.min(R,F.x),I=Math.min(I,F.y),$=Math.max($,F.x+L),q=Math.max(q,F.y+H),B=Math.max(B,F.x+D),P=Math.max(P,F.y+K)}const W=$-R,ne=q-I,ee=[...new Set(S.map(G=>Math.round(G.x)))].sort((G,F)=>G-F),M=ee.length?ee:[R],X=[0,...S.map(G=>G.y+G.h+b)].sort((G,F)=>G-F);let V=null;if(h){let G=1/0,F=1/0,L=-1/0,H=-1/0;for(const U of S)G=Math.min(G,U.x),F=Math.min(F,U.y),L=Math.max(L,U.x+U.cw),H=Math.max(H,U.y+U.ch);const D=(U,ae)=>{const le=c.width/(Math.max(L,U+B-R)-Math.min(G,U)+uf),ge=c.height/(Math.max(H,ae+P-I)-Math.min(F,ae));return[Math.min(JI,le,ge),Math.min(le,ge),Math.max(le,ge)]},K=(U,ae)=>{for(let le=0;le<U.length;le++){if(U[le]>ae[le]+1e-9)return!0;if(U[le]<ae[le]-1e-9)return!1}return!1},re=Math.round(L+uf+k),z=[...new Set([...X,F])].sort((U,ae)=>U-ae);let Z=null;for(const U of[...M,re])for(const ae of z){if(_(U,ae,W,ne))continue;const le=D(U,ae);(Z===null||K(le,Z))&&(Z=le,V={x:U,y:ae})}V&&V.x===R&&V.y===I&&(V=null)}else e:for(const G of M)for(const F of X){if(F>=I)break;if(!_(G,F,W,ne)){V={x:G,y:F};break e}}if(V){const G=V.x-R,F=V.y-I;for(const L of C){const H=f(L.id);t.set(L.id,{x:H.x+G,y:H.y+F})}j.push(E)}for(const G of C){const F=f(G.id),{w:L,h:H}=u(G.id);S.push({x:F.x,y:F.y,w:L,h:H,...p(G.id)})}}return j}function O9(e,t,n){const r=new Map;for(const s of e){if(t.has(s.id)||!n(s.id))continue;const l=xi(s);(r.get(l)??r.set(l,[]).get(l)).push(s)}if(r.size===0)return e;for(const s of r.values())s.sort((l,c)=>l.id.localeCompare(c.id));return e.map(s=>{var p;if(t.has(s.id)||n(s.id))return s;const l=r.get(xi(s));if(!l)return s;const c=(p=s.data)==null?void 0:p.parentId,u=l.find(h=>h.id===c)??l[0],f=n(u.id);return{...s,position:{x:s.position.x+f.x-u.position.x,y:s.position.y+f.y-u.position.y}}})}function L9(e,t,n,r,s,l=!1,c){const p=zl+Qf+1,h=8,m=1.75,y=200,v=.7,S=.01,b=P=>Pu(P,r,c),_=P=>n.get(P)??t.get(P),k=new Map;for(const P of e){if(!_(P.id))continue;const W=xi(P),ne=k.get(W);ne?ne.push(P):k.set(W,[P])}const j=[],E=new Set,C=new Set,R=s.size===0;for(const P of[...k.keys()].sort()){const W=k.get(P);let ne=1/0,ee=1/0,M=-1/0,X=-1/0,V=!1;for(const H of W){const D=_(H.id),{w:K,h:re}=b(H.id);ne=Math.min(ne,D.x),ee=Math.min(ee,D.y),M=Math.max(M,D.x+K),X=Math.max(X,D.y+re),n.has(H.id)&&(V=!0)}const G=M-ne,F=X-ee;C.add(P);const L=s.get(P);L&&(G>L.w+h||F>L.h+h)&&E.add(P),s.set(P,{w:G,h:F}),j.push({sid:P,members:W.map(H=>H.id),x:ne,y:ee,w:G,h:F,anchored:V,mass:1})}for(const P of[...s.keys()])C.has(P)||s.delete(P);if(l||R)return[];let I=!1;for(let P=0;P<j.length&&!I;P++)for(let W=P+1;W<j.length;W++){const ne=j[P],ee=j[W];if(!(ne.anchored&&ee.anchored)&&Math.abs(ne.x+ne.w/2-(ee.x+ee.w/2))<(ne.w+ee.w)/2+61&&Math.abs(ne.y+ne.h/2-(ee.y+ee.h/2))<(ne.h+ee.h)/2+p){I=!0;break}}if(E.size===0&&!I)return[];if(E.size>0)for(const P of j)E.has(P.sid)&&(P.mass=8);else for(const P of j)P.mass=Math.max(1,P.w*P.h/(vi*Lu));const $=new Map(j.map(P=>[P.sid,P.x])),q=new Map(j.map(P=>[P.sid,P.y]));for(let P=0;P<y;P++){const W=new Map,ne=new Map;let ee=0;for(let M=0;M<j.length;M++)for(let X=M+1;X<j.length;X++){const V=j[M],G=j[X];if(V.anchored&&G.anchored)continue;const F=V.x+V.w/2,L=V.y+V.h/2,H=G.x+G.w/2,D=G.y+G.h/2,K=(V.w+G.w)/2+61-Math.abs(F-H),re=(V.h+G.h)/2+p-Math.abs(L-D);if(K<=0||re<=0)continue;const z=(fe,Ce)=>!fe.anchored&&!(Ce<0&&fe.x<=0),Z=(fe,Ce)=>!fe.anchored&&!(Ce<0&&fe.y<=0),U=(fe,Ce,pe)=>{const _e=fe===Ce,Ye=_e?V.sid<G.sid?-1:1:Math.sign(fe-Ce);return pe(V,Ye)||pe(G,-Ye)?Ye:_e&&(pe(V,-Ye)||pe(G,Ye))?-Ye:0},ae=U(F,H,z),le=U(L,D,Z),ge=ae!==0,Ne=le!==0;if(!ge&&!Ne)continue;const Ie=ge&&(!Ne||K*m<re),[Ge,Pe,ze,Re]=Ie?[ae,K,W,z]:[le,re,ne,Z],st=Re(V,Ge),ue=Re(G,-Ge),ce=V.mass,se=G.mass,be=st?ue?se/(ce+se):1:0,Le=ue?st?ce/(ce+se):1:0,de=Pe*v;ze.set(V.sid,(ze.get(V.sid)??0)+Ge*de*be),ze.set(G.sid,(ze.get(G.sid)??0)-Ge*de*Le),ee+=de}for(const M of j)M.anchored||(M.x=Math.max(0,M.x+(W.get(M.sid)??0)),M.y=Math.max(0,M.y+(ne.get(M.sid)??0)));if(ee<S)break}const B=[];for(const P of j){const W=P.x-$.get(P.sid),ne=P.y-q.get(P.sid);if(!(Math.abs(W)<1&&Math.abs(ne)<1)){for(const ee of P.members){if(n.has(ee))continue;const M=t.get(ee);M&&t.set(ee,{x:M.x+W,y:M.y+ne})}B.push(P.sid)}}return B}function zh(e,t,n){return!t.has(e)||n.has(e)}function P9(e,t,n,r){return!t.has(e)&&zh(e,n,r)}function D9(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function C2(e,t,n,r){n.set(e,t),r.delete(e)}const F9=200,q9=5*6e4,B9=6,z9=2*6e4;function Eh(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function U9(e,t){let n=!1;for(const s of e)if(!t.has(s)){n=!0;break}if(!n)return e;const r=new Set;for(const s of e)t.has(s)&&r.add(s);return r}function H9(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(Tb(n.id));return t}function W9(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(Tb(n.id));return t}function V9(e,t){let n=o6(e,t,HN);i6(e,t,HN)&&(n=!0);const r=[],s=l=>{r.push(l)};return n6(e,t,F9,q9,s)&&(n=!0),r6(e,t,B9,z9,s)&&(n=!0),{changed:n,forgotten:r}}const G9=300,T2=130,K9=160,R2=new WeakMap;function Y9(e,t){let n=R2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:gF(e.agents.values())},R2.set(e,n));const{byId:r,branches:s}=n;return l=>{let c=r.get(l.id);if(!c){const u=l.kind==="root"?s.get(l.sessionId):void 0;c=u?{...l,onOpenContext:t,branch:u}:{...l,onOpenContext:t},r.set(l.id,c)}return c}}function W0(e){const t=new Map;for(const n of e.agents.values())n.tools.length>0&&t.set(n.id,Math.min(4,n.tools.length));return t}function X9(e,t,n,r,s,l,c,u,f,p,h,m,y,v,S,b,_,k){var ee,M,X,V;const j=[],E=[],C=Y9(e,k);for(const G of e.agents.values()){if(!_.has(G.id))continue;const F=G.exitAt!=null,L=b!=null&&!b.has(G.id),H=[F?"rf-exiting":"",L?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,D=l.get(G.id);if(j.push({id:G.id,type:"agent",position:{x:0,y:0},data:C(G),className:H,ariaLabel:oq(G,t,S.has(G.id)),...D?{width:D.width,height:D.height}:null}),G.parentId&&_.has(G.parentId)){const z=tf(G.sessionId),Z=F,U=S.size>0&&(S.has(G.id)||S.has(G.parentId)),ae=b!=null&&!b.has(G.id)&&!b.has(G.parentId),le=G.state==="active"?2:1.5,ge=U?le+1.5:le,Ne=Z?.2:ae?.12:1,Ie=["sess-edge",G.state==="active"?"sess-live":"sess-idle",Z?"rf-edge-exiting":"",U?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${G.parentId}->${G.id}`,source:G.parentId,target:G.id,animated:(G.state==="active"||U)&&!Z,type:"smoothstep",style:{"--session-hue":z,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:Ne,transition:"var(--edge-transition)"},className:Ie})}const K=G.kind==="root"?Cf(G):null,re=K?fM(G.sessionId,K.at):null;if(K&&re&&!uF(re)){const z=Tb(G.id),Z=tf(G.sessionId),U=l.get(z);j.push({id:z,type:"recapNote",position:{x:0,y:0},data:{sessionId:G.sessionId,parentId:G.id,recap:K,noteKey:re,hue:Z},className:L?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${G.label}`,...U?{width:U.width,height:U.height}:null}),E.push({id:`e:recap:${G.id}`,source:z,target:G.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Z}})}}const R=W0(e),I=`${y}#lanes:${C9(R)}`,$=new Set(j.filter(G=>G.type==="recapNote").map(G=>G.id));for(const G of Array.from(h.keys()))pF(G)&&!$.has(G)&&!s.has(G)&&(h.delete(G),m.delete(G));const q=j.filter(G=>P9(G.id,s,h,m));if(q.length>0||I!==v.current){if(q.length>0){const G=O9(M9(j,E,{direction:"LR",pinned:s,measured:l,availableWidth:n,availableHeight:r,lanes:R}),s,F=>zh(F,h,m)?void 0:h.get(F));for(const F of G)zh(F.id,h,m)&&C2(F.id,F.position,h,m);$9(j,h,s,l,new Set(q.filter(F=>F.type!=="recapNote").map(F=>F.id)),R,{width:n,height:r});for(const F of q){if(F.type!=="recapNote")continue;const L=(ee=F.data)==null?void 0:ee.parentId;if(!L)continue;const H=s.get(L)??(zh(L,h,m)?void 0:h.get(L));if(!H)continue;const D=((M=l.get(F.id))==null?void 0:M.width)??G9,K=((X=l.get(F.id))==null?void 0:X.height)??T2,re=((V=l.get(L))==null?void 0:V.height)??T2;C2(F.id,{x:H.x-K9-D,y:H.y+(re-K)/2},h,m)}}I9(j,h,s,l,R),v.current=I}const B=L9(j,h,s,l,c,!f||p,R);B.length>0&&u(B);const P=W9(e.agents.values());Eh(h,P),Eh(m,P),Eh(s,P),Eh(l,H9(e.agents.values()));const W=[];let ne=!1;for(const G of j){let F=s.get(G.id)??h.get(G.id);F||(F=D9(G.id,h,m),ne=!0),W.push({...G,position:F})}return ne&&(v.current=""),{nodes:W,edges:E}}const Z9=1;function Q9(e){return{id:e.id,name:e.name,inputPreview:e.inputPreview,startedAt:e.startedAt,endedAt:e.endedAt,ok:e.ok,errorPreview:e.errorPreview,usage:e.usage}}function J9(e,t,n){const r=e.agents.get(t);if(!r)return null;const s=[];for(const l of e.agents.values())l.sessionId===t&&s.push(l);return{schemaVersion:Z9,exportedAt:n,sessionId:t,label:r.label,cwd:r.cwd,startedAt:r.startedAt,endedAt:r.endedAt,model:r.model,agents:s.map(l=>({id:l.id,kind:l.kind,label:l.label,parentId:l.parentId,state:l.state,startedAt:l.startedAt,endedAt:l.endedAt,model:l.model,cwd:l.cwd,usage:l.usage,prompts:l.prompts,tools:l.tools.map(Q9)}))}}function eV(e,t){const n=(e||"session").replace(/[^a-z0-9._-]/gi,"_");return`${hn}-${n}-${t.slice(0,8)}.json`}function tV(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function nV(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.decks!="number"||typeof t.mine!="boolean")return null;const n=t.owner&&typeof t.owner=="object"?t.owner.port:null;return{path:typeof t.path=="string"&&t.path!==""?t.path:null,decks:t.decks,mine:t.mine,ownerPort:typeof n=="number"?n:null}}function rV(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function sV(e,t){const n=rV(e),r=(...c)=>[n?`${n} on the canvas`:null,...c,"layout, pins and selection"].filter(u=>u!==null),s="This cannot be undone.";if(!t)return{goes:r("the event log on disk — the file a restarted deck replays to rebuild what you see, and the file every deck on this machine shares unless one was told otherwise"),stays:[],final:s,confirm:"Clear everything"};if(!t.path)return{goes:r(),stays:[],final:`This deck keeps no event log, so nothing on disk changes — and nothing can bring the canvas back. ${s}`,confirm:"Clear everything"};if(!t.mine){const c=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,u=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${c}${u}`,"restart this deck and the log replays back onto it"],final:null,confirm:"Clear this canvas"}}if(t.decks<=1)return{goes:r("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:s,confirm:"Clear everything"};const l=t.decks-1;return{goes:r(`the event log ${l===1?"1 other running deck shares":`${l} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[l===1?"what that deck shows, until it restarts — then it is gone there too":"what those decks show, until they restart — then it is gone there too"],final:s,confirm:"Clear everything"}}function aV({agentCount:e,onConfirm:t,onCancel:n}){const r=w.useRef(null),s=mn(n,{focusRef:r,layer:L6}),[l,c]=w.useState(null);w.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c(nV(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=sV(e,l);return o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:s,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsxs("div",{className:"modal-title",children:[o.jsx("span",{className:"status-dot err","aria-hidden":!0}),o.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[o.jsxs("dl",{className:"cc-plan",children:[o.jsx("dt",{children:"Goes"}),o.jsx("dd",{children:u.map(m=>o.jsx("span",{children:m},m))}),o.jsx("dt",{children:"Stays"}),o.jsx("dd",{children:f.length>0?f.map(m=>o.jsx("span",{children:m},m)):o.jsx("span",{children:"nothing"})})]}),p&&o.jsx("p",{className:"cc-final",children:p}),o.jsxs("div",{className:"cc-actions",children:[o.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),o.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const oV="Press Esc first if a key does nothing.",iV=[{title:"Canvas",rows:[{cap:"Space",action:"pause or resume the stream",binds:[" "]},{cap:"J",action:"next agent",binds:["j","J"]},{cap:"K",action:"previous agent",binds:["k","K"]},{cap:"W",action:"the session waiting on you — oldest first, again for the next",binds:["w","W"]},{cap:"F",action:"fit every agent on screen",binds:["f","F"]},{cap:"Z",action:"zoom to the selected agent and its session",binds:["z","Z"]},{cap:"Delete",action:"take the selected card off the board — Undo brings it back",binds:["Delete"]},{cap:"R",action:"re-arrange the canvas and drop the pins",binds:["r","R"]},{cap:"C",action:"clear the canvas and the event log — asks first",binds:["c","C"]}]},{title:"Panels and dialogs",rows:[{cap:"U",action:"usage panel",binds:["u","U"]},{cap:"L",action:"session list",binds:["l","L"]},{cap:"D",action:"detail panel",binds:["d","D"]},{cap:"H",action:"usage history",binds:["h","H"]},{cap:"A",action:"Claude accounts, where Claude Code is installed",binds:["a","A"]},{cap:"S",action:"this machine — cores, memory, temperature",binds:["s","S"]},{cap:"B",action:"Browser Watch",binds:["b","B"]},{cap:"V",action:"the sound menu — volume, tones, notifications",binds:["v","V"]},{cap:"?",action:"this sheet",binds:["?"]}]},{title:"Settings",rows:[{cap:"M",action:"sound on or off",binds:["m","M"]},{cap:"T",action:"light or dark theme",binds:["t","T"]}]},{title:"Focus and selection",rows:[{cap:"Tab",action:"reach the agent cards",binds:[]},{cap:"Enter",action:"select the focused card",binds:["Enter"]},{cap:"Shift + Enter",action:"add the focused card to the selection",binds:["Enter"]},{cap:"Esc",action:"close what is open, deselect, release focus",binds:["Escape"]}]},{title:"Mouse",rows:[{cap:"drag",action:"move a node, and pin it where you dropped it",binds:[]},{cap:"shift-click",action:"add an agent to the selection",binds:[]},{cap:"click",action:"a card: go to it and its session",binds:[]},{cap:"double-click",action:"a card: its prompt, every tool call, tokens and timing",binds:[]},{cap:"hover",action:"zoomed out, a card's name, state and numbers",binds:[]},{cap:"click",action:"the topbar speaker opens volume and sound settings",binds:[]}]}];function lV({onClose:e,onTour:t}){const n=mn(e);return o.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:o.jsxs("div",{ref:n,className:"modal key-help",onClick:r=>r.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[o.jsxs("header",{className:"modal-head",children:[o.jsx("div",{className:"modal-title",children:o.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),o.jsx("div",{className:"modal-actions",children:o.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),o.jsxs("section",{className:"modal-body",children:[t&&o.jsxs("div",{className:"guide-door",children:[o.jsx("span",{children:"Eight pictures of what the deck shows."}),o.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),o.jsx("div",{className:"shortcuts",children:iV.map(r=>o.jsxs(w.Fragment,{children:[o.jsx("h3",{className:"kh-group",children:r.title}),r.rows.map(s=>o.jsxs("div",{className:"sc",children:[o.jsx("kbd",{children:s.cap}),o.jsx("span",{children:s.action})]},`${r.title}:${s.cap}:${s.action}`))]},r.title))}),o.jsx("p",{className:"kh-foot",children:oV})]})]})})}const cV=1024*1024,A2=5,n$=.8,V0=24,uV="agent-dag.soundCustom.done",dV="agent-dag.soundCustom.needs-input",vu={done:uV,"needs-input":dV};function Du(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function M2(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function hV(e){return{done:M2(e(vu.done)),"needs-input":M2(e(vu["needs-input"]))}}function fV(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function pV(e){return e.done&&e.done===e["needs-input"]?e.done:null}const mV={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},r$=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function s$(e,t){const n=t.toLowerCase().split(";")[0].trim();if(r$.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return mV[r]??n}function I2(e,t){const n=s$(e.name,e.type);if(!r$.has(n))return"Use a WAV, MP3, OGG, or browser-recorded audio file.";if(!Number.isFinite(e.size)||e.size<=0)return"The audio file is empty.";if(e.size>cV)return"Audio must be 1 MB or smaller.";if(t!==void 0){if(!Number.isFinite(t)||t<=0)return"The audio file could not be decoded.";if(t>A2)return`Audio must be ${A2} seconds or shorter.`}return null}function G0(e){return e>=V0?`There are already ${V0} custom sounds. Delete one first.`:null}function gV(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function yV(e){let t=0;for(const n of e)for(let r=0;r<n.length;r++)t=Math.max(t,Math.abs(n[r]));return t<=1e-5?1:Math.min(16,n$/t)}function a$(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}async function wV(e,t,n=a$()){var p;const r=((p=e.name)==null?void 0:p.trim())||"Custom sound",s=I2({name:r,type:e.type,size:e.size});if(s)throw new Error(s);const l=await e.arrayBuffer();let c;try{c=await t(l.slice(0))}catch{throw new Error("The audio file could not be decoded.")}const u=I2({name:r,type:e.type,size:e.size},c.duration);if(u)throw new Error(u);const f=Array.from({length:c.numberOfChannels},(h,m)=>c.getChannelData(m));return{id:n,name:r.replace(/\.(wav|wave|mp3|ogg|oga|webm|m4a|mp4)$/i,"")||"Custom sound",kind:"audio",mime:s$(r,e.type),duration:c.duration,normalizationGain:yV(f),bytes:l}}function vV(e,t=a$()){const n=e.name.trim()||"Custom voice",r=e.text.trim();if(!r)throw new Error("Enter the words this voice should say.");const s=Number.isFinite(e.rate)?e.rate:1,l=Number.isFinite(e.pitch)?e.pitch:1;return{id:t,name:n,kind:"tts",text:r.slice(0,180),voiceURI:e.voiceURI??"",rate:Math.min(2,Math.max(.5,s)),pitch:Math.min(2,Math.max(.5,l))}}const xV="ccdeck-notification-audio",bV=2,vs="assets",Bs="summaries";function Zu(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function kV(){return new Promise((e,t)=>{const n=indexedDB.open(xV,bV);n.onupgradeneeded=r=>{const s=n.result,l=s.objectStoreNames.contains(vs)?n.transaction.objectStore(vs):s.createObjectStore(vs,{keyPath:"id"});if(s.objectStoreNames.contains(Bs))return;const c=s.createObjectStore(Bs,{keyPath:"id"});if(r.oldVersion<1)return;const u=l.openCursor();u.onsuccess=()=>{const f=u.result;f&&(c.put(Du(f.value)),f.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function Qu(e,t,n){const r=await kV();try{return await new Promise((s,l)=>{const c=r.transaction(e,t),u=n(c),f=()=>l(c.error??new Error("Local audio storage failed."));c.oncomplete=()=>s(u?u.result:void 0),c.onerror=f,c.onabort=f})}finally{r.close()}}async function NV(){const e=Zu();return e?e.list():typeof indexedDB>"u"?[]:await Qu([Bs],"readonly",t=>t.objectStore(Bs).getAll())??[]}async function SV(e){const t=Zu();return t?t.get(e):typeof indexedDB>"u"?null:await Qu([vs],"readonly",n=>n.objectStore(vs).get(e))??null}async function $2(e){const t=Zu();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Qu([vs,Bs],"readwrite",n=>{n.objectStore(vs).put(e),n.objectStore(Bs).put(Du(e))})}async function jV(e,t){const n=Zu();if(n){const r=await n.get(e);r&&await n.put({...r,name:t});return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Qu([vs,Bs],"readwrite",r=>{const s=r.objectStore(vs),l=s.get(e);l.onsuccess=()=>{const c=l.result;if(!c)return;const u={...c,name:t};s.put(u),r.objectStore(Bs).put(Du(u))}})}async function _V(e){const t=Zu();if(t){await t.remove(e);return}typeof indexedDB>"u"||await Qu([vs,Bs],"readwrite",n=>{n.objectStore(vs).delete(e),n.objectStore(Bs).delete(e)})}const Uh=["done","needs-input"],EV=[{id:"two",label:"Two notes",notes:[{at:0,hz:740,ms:90},{at:.085,hz:440,ms:150}]},{id:"arc",label:"Descent",notes:[{at:0,hz:988,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:440,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:740,ms:55},{at:.055,hz:740,ms:55},{at:.165,hz:440,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:988,ms:110},{at:0,hz:740,ms:110},{at:.1,hz:440,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:740,ms:120},{at:.11,hz:440,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:740,ms:55},{at:.06,hz:440,ms:90}]}],CV=[{id:"two",label:"Two notes",notes:[{at:0,hz:440,ms:90},{at:.085,hz:740,ms:150}]},{id:"arc",label:"Ascent",notes:[{at:0,hz:440,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:988,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:440,ms:55},{at:.055,hz:440,ms:55},{at:.165,hz:740,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:440,ms:110},{at:.1,hz:740,ms:170},{at:.1,hz:988,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:440,ms:120},{at:.11,hz:740,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:440,ms:55},{at:.06,hz:740,ms:90}]}],ck={done:EV,"needs-input":CV},wr="two";function K0(e,t){const n=ck[e];return n.find(r=>r.id===t)??n.find(r=>r.id===wr)??n[0]}function o$(e,t){return ck[e].some(r=>r.id===t)?t:wr}K0("done",wr).notes,K0("needs-input",wr).notes;const O2=.04,i$=.24,di=0,Zl=100,df=5,bi=50;function Ql(e){if(!Number.isFinite(e))return bi;const t=Math.round(e/df)*df;return Math.min(Zl,Math.max(di,t))}function l$(e){if(e==null)return bi;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Ql(Number(t)):bi}function Y0(e){const t=Ql(e),n=O2+(i$-O2)*(t/Zl);return Math.round(n*1e4)/1e4}function TV(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(Y0(e)*r*1e4)/1e4}const RV=160,AV="agent-dag.soundLevel.done",MV="agent-dag.soundLevel.needs-input",IV="agent-dag.soundFigure.done",$V="agent-dag.soundFigure.needs-input",c$={done:AV,"needs-input":MV},Hh={done:IV,"needs-input":$V},X0={done:{level:bi,figure:wr},"needs-input":{level:bi,figure:wr}};function OV(e){const t=n=>({level:l$(e(c$[n])),figure:o$(n,e(Hh[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const L2={Stop:"done",Notification:"needs-input"};function LV(e,t){var r;if(t)return null;const n=(r=e==null?void 0:e.payload)==null?void 0:r.hook_event_name;return typeof n!="string"?null:Object.hasOwn(L2,n)?L2[n]:null}function PV(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,r=!1;const s=()=>e.enabled()?r&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",l=()=>{var m;return(m=e.onState)==null?void 0:m.call(e,s())};function c(){var m;if(!(!t||r))try{n=n??new t,(m=n.resume)==null||m.call(n).then(l,()=>{}),r=!0,l()}catch{}}function u(m,y,v=y.figure){if(!n||n.state!=="running")return!1;const S=K0(m,v),b=TV(y.level,S),_=n.currentTime;for(const k of S.notes){const j=n.createOscillator(),E=n.createGain();j.type=S.type??"sine",j.frequency.value=k.hz;const C=_+k.at,R=C+k.ms/1e3;E.gain.setValueAtTime(1e-4,C),E.gain.exponentialRampToValueAtTime(b,C+.012),E.gain.exponentialRampToValueAtTime(1e-4,R),j.connect(E).connect(n.destination),j.start(C),j.stop(R+.02)}return!0}async function f(m,y){if(!e.loadCustom)return"unavailable";let v;try{v=await e.loadCustom(m)}catch{return"unavailable"}if(!v)return"missing";if(v.kind==="tts"){if(typeof window>"u"||!("speechSynthesis"in window)||typeof SpeechSynthesisUtterance>"u")return"unavailable";const b=new SpeechSynthesisUtterance(v.text),_=window.speechSynthesis.getVoices();b.voice=_.find(k=>k.voiceURI===v.voiceURI)??null,b.rate=v.rate,b.pitch=v.pitch,b.volume=Math.min(1,Y0(y.level)/i$);try{return window.speechSynthesis.cancel(),window.speechSynthesis.speak(b),"played"}catch{return"unavailable"}}if(!n||n.state!=="running")return"locked";let S;try{S=await n.decodeAudioData(v.bytes.slice(0))}catch{return"broken"}try{const b=n.createBufferSource(),_=n.createGain();b.buffer=S;const k=v.normalizationGain*(Y0(y.level)/n$);return _.gain.setValueAtTime(Math.max(1e-4,k),n.currentTime),b.connect(_).connect(n.destination),b.start(n.currentTime),"played"}catch{return"unavailable"}}function p(m,y=!1){var b,_;if(!y&&!e.enabled())return!1;const v=(((b=e.prefs)==null?void 0:b.call(e))??X0)[m]??X0[m],S=((_=e.customSelection)==null?void 0:_.call(e)[m])??null;return S&&e.loadCustom?(f(S,v).then(k=>{var j;k==="played"||k==="locked"||((k==="missing"||k==="broken")&&((j=e.onCustomFailure)==null||j.call(e,m,S)),u(m,{...v,figure:wr},wr))}),!0):!n||n.state!=="running"?!1:u(m,v)}function h(m,y=bi){return f(m,{level:Ql(y),figure:wr}),!0}return{unlock:c,play:p,previewCustom:h,state:s,get context(){return n}}}const DV="With no deck tab open, get a notification wherever a sound would have played.",FV="With the ccdeck window closed, get a notification wherever a sound would have played.";function qV(e){return e?FV:DV}const BV="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",P2="Get notified when you're away from this tab.";function zV(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:P2};case"default":return{status:null,ask:!0,ok:!1,note:P2};case"denied":return{status:"Blocked",ask:!1,ok:!1,note:"Your browser is blocking them; only its own site settings can undo that. You'll still be told once this tab is closed."};default:return{status:"Unavailable",ask:!1,ok:!1,note:"This browser cannot show them. You'll still be told once this tab is closed."}}}function pu(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const D2={done:"Turn finished","needs-input":"Claude is asking"},UV={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function HV({onClose:e,soundOn:t,onToggleSound:n,prefs:r,onLevel:s,onFigure:l,onPreview:c,openerRef:u,customAssets:f,customSelections:p,onBuiltInSelected:h,onCustomSelected:m,onImportCustom:y,onCreateVoice:v,onRenameCustom:S,onPreviewCustom:b,onDeleteCustom:_,notifyOn:k,onToggleNotify:j,notifyVetoed:E,notifyPermission:C,onAskNotify:R}){var Ce;const I=zV(C),$=pu(),q=k&&!E&&!$,[B,P]=w.useState(""),[W,ne]=w.useState("Custom voice"),[ee,M]=w.useState("Your turn"),[X,V]=w.useState(""),[G,F]=w.useState("1"),[L,H]=w.useState("1"),[D,K]=w.useState([]),[re,z]=w.useState(!1),Z=w.useRef(null),U=w.useRef(null),ae=pV(p),le=((Ce=f.find(pe=>pe.id===ae))==null?void 0:Ce.name)??"the same custom sound",ge=f.length,Ne=G0(ge),Ie=Ne!==null,Ge=Ie?{"aria-disabled":!0,"aria-describedby":"sm-custom-full"}:{},[Pe,ze]=w.useState(null),Re=w.useRef(0),st=w.useRef(new Map),ue=w.useRef(null);w.useEffect(()=>{if(!Pe)return;const pe=window.setTimeout(()=>ze(null),4e3);return()=>window.clearTimeout(pe)},[Pe]),w.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const pe=()=>{const _e=window.speechSynthesis.getVoices();K(_e),V(Ye=>{var qe;return Ye||((qe=_e[0])==null?void 0:qe.voiceURI)||""})};return pe(),window.speechSynthesis.addEventListener("voiceschanged",pe),()=>window.speechSynthesis.removeEventListener("voiceschanged",pe)},[]);const ce=async pe=>{P("");try{await pe()}catch(_e){P(_e instanceof Error?_e.message:"Custom audio could not be saved.")}},se=(pe,_e)=>{const Ye=Date.now(),qe=Au({armedFor:Pe,target:pe,armedAt:Re.current,now:Ye,gapMs:Ou});if(qe==="arm"){ze(pe),Re.current=Ye;return}if(qe==="ignore")return;ze(null);const ke=gV(f.map(Ae=>Ae.id),pe);ce(async()=>{var Ue;await _(pe);const Ae=document.activeElement;Ae!==_e&&!$0((Ae==null?void 0:Ae.tagName)??null)||(Ue=ke?st.current.get(ke):ue.current)==null||Ue.focus()})},be=()=>{var pe;U.current!==null&&clearTimeout(U.current),U.current=null,((pe=Z.current)==null?void 0:pe.state)==="recording"&&Z.current.stop()},Le=async()=>{var _e;if(Ie)return;if(P(""),!((_e=navigator.mediaDevices)!=null&&_e.getUserMedia)||typeof MediaRecorder>"u"){P("Microphone recording is unavailable in this browser.");return}let pe;try{pe=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{P("Microphone access was denied or unavailable.");return}if(Z.current){pe.getTracks().forEach(Ye=>Ye.stop());return}try{const Ye=["audio/webm;codecs=opus","audio/ogg;codecs=opus","audio/mp4"].find(Ae=>MediaRecorder.isTypeSupported(Ae)),qe=new MediaRecorder(pe,Ye?{mimeType:Ye}:void 0),ke=[];Z.current=qe,qe.ondataavailable=Ae=>{Ae.data.size&&ke.push(Ae.data)},qe.onerror=()=>P("Recording failed. Please try again."),qe.onstop=()=>{pe.getTracks().forEach(rt=>rt.stop()),U.current!==null&&clearTimeout(U.current),U.current=null;const Ae=Z.current===qe;if(Ae&&(Z.current=null),z(!1),!Ae||!ke.length)return;const Ue=qe.mimeType.split(";")[0],Fe=Ue==="audio/mp4"?"m4a":Ue==="audio/ogg"?"ogg":"webm",Ve=new File(ke,`Recorded voice.${Fe}`,{type:Ue});ce(()=>y(Ve))},qe.start(200),z(!0),U.current=setTimeout(be,4400)}catch{Z.current=null,pe.getTracks().forEach(Ye=>Ye.stop()),P("This browser cannot record a supported audio format.")}};w.useEffect(()=>()=>{U.current!==null&&clearTimeout(U.current);const pe=Z.current;Z.current=null,(pe==null?void 0:pe.state)==="recording"&&pe.stop()},[]);const de=mn(e,{popover:!0}),fe=w.useRef(e);return fe.current=e,w.useEffect(()=>{const pe=_e=>{var qe,ke;const Ye=_e.target;Ye&&((qe=de.current)!=null&&qe.contains(Ye)||(ke=u.current)!=null&&ke.contains(Ye)||fe.current())};return window.addEventListener("pointerdown",pe,!0),()=>window.removeEventListener("pointerdown",pe,!0)},[de,u]),o.jsxs("div",{ref:de,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[o.jsxs("div",{className:"sm-switches",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),o.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-labelledby":"sm-sound-label",className:"switch",onClick:n,title:"A tone when a turn finishes, and when Claude asks for something",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsxs("div",{className:"sm-setting",children:[o.jsxs("label",{className:"sm-switch",children:[o.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications while closed"}),o.jsx("button",{type:"button",role:"switch","aria-checked":k,"aria-labelledby":"sm-notify-label",className:"switch",onClick:j,title:"With no deck tab open, a notification wherever a sound would play",children:o.jsx("span",{className:"switch-knob"})})]}),o.jsx("p",{className:"sm-note",children:E?BV:qV($)})]})]}),q&&o.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[o.jsxs("div",{className:"sm-channel-head",children:[o.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),I.ask?o.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:R,children:"Enable"}):o.jsxs("span",{className:"sm-channel-state","data-ok":I.ok||void 0,children:[I.ok&&o.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),I.status]})]}),o.jsx("p",{className:"sm-note",children:I.note})]}),!t&&o.jsx("span",{id:"sm-preview-note",className:"vis-hidden",children:"Plays even when Sounds is off, so you can set a tone before turning sounds back on."}),o.jsx("div",{className:"sm-tones",children:Uh.map(pe=>{const _e=r[pe],Ye=`sm-level-${pe}`,qe=`sm-figure-${pe}`;return o.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${pe}`,children:[o.jsxs("div",{className:"sm-tone-head",children:[o.jsx("h3",{className:"sm-tone-name",id:`sm-name-${pe}`,children:D2[pe]}),o.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(pe),"aria-label":`Hear the ${D2[pe].toLowerCase()} tone`,title:t?"Play this tone now, at what it is set to":"Plays even when Sounds is off","aria-describedby":t?void 0:"sm-preview-note",children:[o.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:o.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:Ye,children:"Volume"}),o.jsx("input",{id:Ye,type:"range",min:di,max:Zl,step:df,value:_e.level,onChange:ke=>s(pe,Number(ke.target.value)),style:{"--sm-level":`${(_e.level-di)/(Zl-di)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[_e.level,"%"]})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:qe,children:"Tone"}),o.jsxs("select",{id:qe,className:"sm-select",value:p[pe]?`custom:${p[pe]}`:_e.figure,onChange:ke=>{const Ae=ke.target.value;Ae.startsWith("custom:")?m(pe,Ae.slice(7)):(h(pe),l(pe,Ae))},children:[ck[pe].map(ke=>o.jsx("option",{value:ke.id,children:ke.label},ke.id)),f.length>0&&o.jsx("optgroup",{label:"Custom",children:f.map(ke=>o.jsx("option",{value:`custom:${ke.id}`,children:ke.name},ke.id))})]})]}),o.jsx("p",{className:"sm-note",children:UV[pe]})]},pe)})}),ae&&o.jsxs("p",{className:"sm-note",role:"status",children:["Both tones use “",le,"”. They may be harder to tell apart."]}),o.jsxs("section",{className:"sm-custom","aria-labelledby":"sm-custom-title",children:[o.jsxs("div",{className:"sm-custom-head",children:[o.jsx("h3",{className:"sm-tone-name",id:"sm-custom-title",children:"Custom sounds"}),o.jsxs("span",{children:[ge," of ",V0,", kept on this machine"]})]}),Ie&&o.jsx("p",{className:"sm-note",id:"sm-custom-full",children:Ne}),o.jsxs("div",{className:"sm-custom-actions",children:[o.jsxs("label",{className:"sm-custom-card sm-file",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Import audio"}),o.jsx("span",{children:"WAV, MP3 or OGG"})]}),o.jsx("span",{className:"btn sm-custom-action","aria-hidden":"true",children:"Choose file"}),o.jsx("input",{ref:ue,type:"file",accept:"audio/wav,audio/x-wav,audio/mpeg,audio/mp3,audio/ogg,.wav,.mp3,.ogg",...Ge,onClick:pe=>{Ie&&pe.preventDefault()},onChange:pe=>{var Ye;const _e=(Ye=pe.target.files)==null?void 0:Ye[0];pe.currentTarget.value="",_e&&!Ie&&ce(()=>y(_e))}})]}),o.jsxs("div",{className:"sm-custom-card",children:[o.jsxs("span",{className:"sm-custom-card-copy",children:[o.jsx("strong",{children:"Record a clip"}),o.jsx("span",{children:re?"Recording…":"Up to 5 seconds"})]}),re?o.jsx("button",{type:"button",className:"btn sm-custom-action",onClick:be,children:"Stop & save"}):o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>void Le(),children:"Record"})]})]}),o.jsxs("details",{className:"sm-voice",children:[o.jsxs("summary",{...Ge,onClick:pe=>{const _e=pe.currentTarget.parentElement;Ie&&_e&&!_e.open&&pe.preventDefault()},children:[o.jsx("span",{children:"Spoken voice"}),o.jsx("span",{children:"Create from text"})]}),o.jsxs("div",{className:"sm-voice-fields",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Name"}),o.jsx("input",{className:"ap-manage-input",value:W,maxLength:80,onChange:pe=>ne(pe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Text"}),o.jsx("input",{className:"ap-manage-input",value:ee,maxLength:180,onChange:pe=>M(pe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Voice"}),o.jsxs("select",{className:"sm-select",value:X,onChange:pe=>V(pe.target.value),children:[o.jsx("option",{value:"",children:"System default"}),D.map(pe=>o.jsx("option",{value:pe.voiceURI,children:pe.name},pe.voiceURI))]})]}),o.jsxs("div",{className:"sm-voice-pair",children:[o.jsxs("label",{children:[o.jsx("span",{children:"Rate"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:G,onChange:pe=>F(pe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Pitch"}),o.jsx("input",{className:"ap-manage-input",type:"number",min:"0.5",max:"2",step:"0.1",value:L,onChange:pe=>H(pe.target.value)})]})]}),o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>{Ie||ce(async()=>{await v({name:W,text:ee,voiceURI:X,rate:parseFloat(G),pitch:parseFloat(L)}),M("Your turn")})},children:"Add spoken voice"})]})]}),f.length>0&&o.jsx("div",{className:"sm-custom-list",children:f.map(pe=>o.jsxs("div",{className:"sm-custom-item",children:[o.jsx("input",{className:"ap-manage-input","aria-label":`Rename ${pe.name}`,defaultValue:pe.name,maxLength:80,onBlur:_e=>{if(!_e.target.value.trim()){_e.target.value=pe.name;return}ce(()=>S(pe.id,_e.target.value))},onKeyDown:_e=>{_e.key==="Enter"&&_e.currentTarget.blur()}}),o.jsx("span",{children:pe.kind==="audio"?`${pe.duration.toFixed(1)}s`:"Voice"}),o.jsx("button",{type:"button",className:"btn sm-custom-icon","aria-label":`Play ${pe.name}`,onClick:()=>b(pe.id),children:"Play"}),o.jsx("button",{type:"button",ref:_e=>{_e?st.current.set(pe.id,_e):st.current.delete(pe.id)},className:`btn sm-custom-icon${Pe===pe.id?" armed":""}`,onKeyDown:_e=>{_e.repeat&&_e.preventDefault()},onClick:_e=>se(pe.id,_e.currentTarget),"aria-label":Pe===pe.id?`Confirm deleting ${pe.name}`:`Delete ${pe.name}`,title:Pe===pe.id?"Press again to delete this sound. It cannot be brought back.":"Delete this sound",children:Pe===pe.id?"Confirm":"Delete"})]},pe.id))}),B&&o.jsx("p",{className:"sm-custom-error",role:"alert",children:B})]}),o.jsxs("p",{className:"sm-foot",children:[o.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const u$="agent-dag.character-enabled",d$="agent-dag.fm-volume",F2="agent-dag.fm-source",WV=[{value:"claude-fm",label:"🎧 Claude FM"},{group:"📻 Lofi Girl",value:"lofi-relax",label:"📚 Relax / study"},{group:"📻 Lofi Girl",value:"lofi-game",label:"🎮 Chill / game"},{group:"📻 Lofi Girl",value:"lofi-vibe",label:"🌅 Vibe / chill"},{group:"📻 Lofi Girl",value:"lofi-sleep",label:"💤 Sleep / chill"},{group:"📻 Radio Mix",value:"radio-mix",label:"📡 Live radio mix"},{group:"📻 Best of Nostalgia",value:"best-of-nostalgia",label:"📼 Best of nostalgia live"},{group:"📻 The Good Life Radio",value:"good-life-radio",label:"🌴 The Good Life Radio"},{group:"☕ Cafe Music BGM",value:"cafe-music-bgm",label:"☕ Cafe music BGM"}];function VV(e){return e==="lofi-relax"||e==="lofi-game"||e==="lofi-vibe"||e==="lofi-sleep"||e==="radio-mix"||e==="best-of-nostalgia"||e==="good-life-radio"||e==="cafe-music-bgm"?e:"claude-fm"}function GV(e){return e!=="0"}function KV(){return GV(yr(u$))}function YV(e){return l$(e)}function XV(){return YV(yr(d$))}const q2="agent-dag.fm-custom-stations",B2="agent-dag.fm-muted",Z0="custom:",ZV=/^UC[A-Za-z0-9_-]{22}$/,QV=/^[A-Za-z0-9_-]{11}$/,uk=/^[A-Za-z0-9_-]{1,80}$/,JV=/\.(mp3|aac|ogg)$/i,eG=/\.m3u8$/i,h$=2048,Fu=80;function ki(e){return`${Z0}${e}`}function Jl(e){if(!e.startsWith(Z0))return null;const t=e.slice(Z0.length);return uk.test(t)?t:null}function z2(e){return Jl(e)??e}function tG(e){return e?"This station could not be played. Check its link, pick another, or pick it again to retry.":"This station is not live right now. Pick another, or pick it again later to retry."}function dk(e){var c,u;const t=e.trim();if(t.length>h$)return null;let n;try{n=new URL(t)}catch{return null}if(n.protocol!=="https:"||n.username||n.password)return null;const r=n.toString(),s=n.hostname.toLowerCase();if(s==="youtube.com"||s==="www.youtube.com"||s==="m.youtube.com"){if(n.port)return null;const f=(c=/^\/channel\/([^/]+)(?:\/live)?\/?$/.exec(n.pathname))==null?void 0:c[1];if(f&&ZV.test(f))return{kind:"youtube-channel",url:r,channel:f};const p=(u=/^\/@([^/]+)\/live\/?$/.exec(n.pathname))==null?void 0:u[1];if(p&&/^[A-Za-z0-9._-]{1,64}$/.test(p))return{kind:"youtube-handle",url:r,handle:p};if(n.pathname==="/watch"){const h=n.searchParams.get("v")??"";if(QV.test(h))return{kind:"youtube-video",url:r,video:h}}return null}return eG.test(n.pathname)?{kind:"direct-audio",url:r,format:"hls"}:JV.test(n.pathname)?{kind:"direct-audio",url:r,format:"audio"}:null}function nG(e){return e==="1"}function rG(e){if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];const n=new Set,r=[];for(const s of t){if(!s||typeof s!="object")continue;const l=typeof s.id=="string"?s.id:"",c=typeof s.name=="string"?s.name.trim():"",u=typeof s.url=="string"?s.url.trim():"",f=dk(u);!uk.test(l)||n.has(l)||!c||c.length>Fu||!f||(n.add(l),r.push({id:l,name:c,url:f.url}))}return r}function sG(e,t,n){const r=Jl(e??"");return r&&t.some(s=>s.id===r)?ki(r):n(e)}function aG(e,t){return e===ki(t)?"claude-fm":e}function oG(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function iG(e,t,n=oG()){const r=e.trim(),s=dk(t);return!r||r.length>Fu||!uk.test(n)||!s?null:{id:n,name:r,url:s.url}}const Tl=["light","dark"],lG={light:"Light",dark:"Dark"},U2=WV,Rl="Give the station a name.",cG="Use an https YouTube live or channel link, or a .mp3, .aac, .ogg or .m3u8 stream.";function uG({theme:e}){return o.jsx("span",{className:"appearance-preview","data-swatch":e,children:o.jsxs("svg",{viewBox:"0 0 112 56","aria-hidden":!0,focusable:"false",children:[o.jsx("rect",{className:"tp-canvas",width:"112",height:"56"}),o.jsx("rect",{className:"tp-surface",width:"112",height:"7"}),o.jsx("rect",{className:"tp-rule",y:"7",width:"112",height:"1"}),o.jsx("rect",{className:"tp-surface",y:"8",width:"25",height:"48"}),o.jsx("rect",{className:"tp-rule",x:"25",y:"8",width:"1",height:"48"}),o.jsx("rect",{className:"tp-card",x:"36.5",y:"27.5",width:"28",height:"14",rx:"2.5"}),o.jsx("rect",{className:"tp-tag",x:"39.5",y:"25.5",width:"13",height:"4",rx:"2"}),o.jsx("rect",{className:"tp-card",x:"76.5",y:"14.5",width:"29",height:"20",rx:"2.5"}),o.jsx("rect",{className:"tp-rule",x:"81",y:"23",width:"20",height:"2",rx:"1"}),o.jsx("rect",{className:"tp-accent",x:"81",y:"23",width:"12",height:"2",rx:"1"})]})})}function dG({theme:e,onTheme:t,characterEnabled:n,onToggleCharacter:r,fmVolume:s,onFmVolume:l,fmMuted:c,onFmMuted:u,fmSource:f,onFmSource:p,customFmStations:h,unavailableFmStations:m,onAddFmStation:y,onRenameFmStation:v,onRemoveFmStation:S,onClose:b}){var ce;const _=mn(b),k=[...U2.map(se=>({...se,label:m.has(se.value)?`${se.label} · not live`:se.label,unavailable:m.has(se.value)})),...h.map(se=>({group:"🎵 Your stations",value:ki(se.id),label:m.has(se.id)?`${se.name} · unavailable`:se.name,unavailable:m.has(se.id)}))],j=k.some(se=>se.value===f&&se.unavailable),E=[];k.forEach((se,be)=>{const Le=E[E.length-1];Le&&Le.group===se.group?Le.indexes.push(be):E.push({group:se.group,indexes:[be]})});const[C,R]=w.useState(!1),[I,$]=w.useState(()=>Math.max(0,k.findIndex(se=>se.value===f))),[q,B]=w.useState(!1),[P,W]=w.useState(""),[ne,ee]=w.useState(""),[M,X]=w.useState(""),[V,G]=w.useState(!1),[F,L]=w.useState(""),[H,D]=w.useState(""),K=w.useRef(null),re=w.useRef(null),z=w.useRef(null),Z=w.useRef(null),U=w.useRef(null),ae=Jl(f),le=ae?h.find(se=>se.id===ae):void 0;w.useEffect(()=>{const se=k.findIndex(be=>be.value===f);$(se<0?0:se)},[f,h,m]),w.useEffect(()=>{G(!1),L((le==null?void 0:le.name)??"")},[le==null?void 0:le.id,le==null?void 0:le.name]),w.useEffect(()=>{var se;C&&((se=document.getElementById(`appearance-fm-option-${I}`))==null||se.scrollIntoView({block:"nearest"}))},[I,C]),w.useEffect(()=>{if(!C)return;const se=be=>{var de,fe;const Le=be.target;!((de=K.current)!=null&&de.contains(Le))&&!((fe=U.current)!=null&&fe.contains(Le))&&R(!1)};return document.addEventListener("pointerdown",se),()=>document.removeEventListener("pointerdown",se)},[C]);const ge=se=>{const be=se.relatedTarget;be&&!se.currentTarget.contains(be)&&R(!1)},Ne=se=>{var Le;const be=k[se];be&&($(se),p(be.value),R(!1),(Le=K.current)==null||Le.focus())},Ie=se=>{if(D6(se.key)){if(!C)return;se.preventDefault(),se.stopPropagation(),R(!1);return}if(se.key==="Tab"){R(!1);return}if(se.key==="Enter"||se.key===" "){se.preventDefault(),C?Ne(I):R(!0);return}se.key!=="ArrowDown"&&se.key!=="ArrowUp"&&se.key!=="Home"&&se.key!=="End"||(se.preventDefault(),R(!0),$(be=>se.key==="Home"?0:se.key==="End"?k.length-1:Math.min(k.length-1,Math.max(0,be+(se.key==="ArrowDown"?1:-1)))))},Ge=()=>{var se;return(se=K.current)==null?void 0:se.focus()},Pe=se=>{var Le,de;if(se.preventDefault(),!P.trim()){X(Rl),(Le=re.current)==null||Le.focus();return}const be=iG(P,ne);if(!be){X(cG),(de=z.current)==null||de.focus();return}y(be),p(ki(be.id)),W(""),ee(""),X(""),B(!1),Ge()},ze=se=>{var be;if(se.preventDefault(),!!ae){if(!F.trim()){D(Rl),(be=Z.current)==null||be.focus();return}v(ae,F),G(!1),Ge()}},Re=se=>{var de;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(se.key))return;se.preventDefault();const Le=(Tl.indexOf(e)+(se.key==="ArrowLeft"||se.key==="ArrowUp"?-1:1)+Tl.length)%Tl.length;t(Tl[Le]),(de=se.currentTarget.querySelectorAll('[role="radio"]')[Le])==null||de.focus()},st=se=>{var Le;if(se.key===" "){se.stopPropagation();return}if(Ef(se.target)||se.key!=="t"&&se.key!=="T"||se.ctrlKey||se.metaKey||se.altKey)return;se.preventDefault(),se.stopPropagation();const be=e==="dark"?"light":"dark";t(be),se.target.getAttribute("role")==="radio"&&((Le=se.currentTarget.querySelectorAll('[role="radio"]')[Tl.indexOf(be)])==null||Le.focus())},ue=se=>{const be=k[se],Le="unavailable"in be&&be.unavailable;return o.jsxs("div",{className:"appearance-source-option",role:"option",id:`appearance-fm-option-${se}`,"aria-selected":f===be.value,"data-highlighted":I===se||void 0,"data-unavailable":Le||void 0,onMouseEnter:()=>$(se),onClick:()=>Ne(se),children:[o.jsx("span",{children:be.label}),f===be.value&&o.jsx("span",{"aria-hidden":!0,children:"✓"})]},be.value)};return On.createPortal(o.jsx("div",{className:"modal-backdrop appearance-backdrop",onClick:b,role:"presentation",children:o.jsxs("div",{ref:_,id:"appearance-menu",className:"modal appearance-menu appearance-modal",role:"dialog","aria-modal":"true","aria-labelledby":"appearance-title",onClick:se=>se.stopPropagation(),onKeyDown:st,children:[o.jsxs("div",{className:"appearance-head",children:[o.jsxs("div",{className:"appearance-heading",children:[o.jsx("h2",{id:"appearance-title",className:"appearance-title",children:"Appearance"}),o.jsx("p",{className:"appearance-subtitle",children:"Tune the deck to your workspace."})]}),o.jsx("button",{type:"button",className:"glyph-btn appearance-close",onClick:b,"aria-label":"Close appearance settings",title:"Close (Esc)",children:"×"})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-theme-caption",children:[o.jsxs("div",{className:"appearance-caption",children:[o.jsxs("div",{children:[o.jsx("h3",{id:"appearance-theme-caption",children:"Color theme"}),o.jsx("p",{className:"appearance-section-note",children:"Choose how the dashboard looks."})]}),o.jsx("kbd",{className:"appearance-key","aria-hidden":!0,title:"Press T anywhere to switch themes",children:"T"})]}),o.jsx("div",{className:"appearance-themes",role:"radiogroup","aria-labelledby":"appearance-theme-caption","aria-keyshortcuts":"T",onKeyDown:Re,children:Tl.map(se=>o.jsxs("button",{type:"button",className:"appearance-theme",role:"radio","aria-checked":e===se,tabIndex:e===se?0:-1,onClick:()=>t(se),children:[o.jsx(uG,{theme:se}),o.jsxs("span",{className:"appearance-theme-name",children:[lG[se],o.jsx("svg",{className:"appearance-check",viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"M2.5 6.4 4.9 8.7 9.5 3.6"})})]})]},se))})]}),o.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-fm-caption",children:[o.jsx("div",{className:"appearance-caption",children:o.jsx("h3",{id:"appearance-fm-caption",children:"Music source"})}),o.jsxs("div",{className:"appearance-controls",children:[o.jsxs("div",{className:"appearance-source-row",children:[o.jsx("label",{htmlFor:"appearance-fm-source",children:"Station"}),o.jsxs("div",{className:`appearance-source-picker${C?" is-open":""}`,onBlur:ge,children:[o.jsxs("button",{ref:K,type:"button",id:"appearance-fm-source",className:"appearance-source-trigger",role:"combobox","aria-haspopup":"listbox","aria-expanded":C,"aria-controls":C?"appearance-fm-source-list":void 0,"aria-activedescendant":C?`appearance-fm-option-${I}`:void 0,"aria-describedby":"appearance-fm-source-note",onClick:()=>R(se=>!se),onKeyDown:Ie,children:[o.jsx("span",{children:((ce=k.find(se=>se.value===f))==null?void 0:ce.label)??U2[0].label}),o.jsx("svg",{viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:o.jsx("path",{d:"m2.5 4.5 3.5 3 3.5-3"})})]}),C&&o.jsx("div",{ref:U,id:"appearance-fm-source-list",className:"appearance-source-list",role:"listbox","aria-label":"Music stations",children:E.map((se,be)=>se.group?o.jsxs("div",{role:"group","aria-labelledby":`appearance-fm-group-${be}`,children:[o.jsx("div",{id:`appearance-fm-group-${be}`,className:"appearance-source-group",role:"presentation",children:se.group}),se.indexes.map(ue)]},`group-${be}`):se.indexes.map(ue))})]})]}),o.jsx("span",{id:"appearance-fm-source-note",className:"vis-hidden",children:"Changing station starts live playback automatically."}),o.jsx("p",{className:"appearance-fm-status",role:"status",children:j?tG(Jl(f)!==null):""}),o.jsxs("div",{className:"appearance-station-manage",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action","aria-expanded":q,onClick:()=>{B(se=>!se),X("")},children:q?"Cancel":"+ Add station"}),le&&!V&&o.jsxs("span",{className:"appearance-station-edit",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action",onClick:()=>{L(le.name),D(""),G(!0)},children:"Rename"}),o.jsx("button",{type:"button",className:"btn danger appearance-station-action",onClick:()=>{S(le.id),Ge()},children:"Remove"})]})]}),q&&o.jsxs("form",{className:"appearance-station-form",onSubmit:Pe,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:re,className:"ap-manage-input",value:P,onChange:se=>W(se.target.value),"aria-invalid":M===Rl||void 0,"aria-describedby":M===Rl?"appearance-station-error":void 0,maxLength:Fu,autoFocus:!0})]}),o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Link"}),o.jsx("input",{ref:z,className:"ap-manage-input",value:ne,onChange:se=>ee(se.target.value),placeholder:"https://…","aria-invalid":M!==""&&M!==Rl||void 0,"aria-describedby":M&&M!==Rl?"appearance-station-error":void 0,inputMode:"url",autoComplete:"off",spellCheck:!1,maxLength:h$})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Add"}),M&&o.jsx("p",{id:"appearance-station-error",className:"appearance-station-error",role:"alert",children:M})]}),le&&V&&o.jsxs("form",{className:"appearance-station-form is-rename",onSubmit:ze,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:Z,className:"ap-manage-input",value:F,onChange:se=>L(se.target.value),"aria-invalid":H!==""||void 0,"aria-describedby":H?"appearance-rename-error":void 0,maxLength:Fu,autoFocus:!0})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Save"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{G(!1),Ge()},children:"Cancel"}),H&&o.jsx("p",{id:"appearance-rename-error",className:"appearance-station-error",role:"alert",children:H})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-character-label",children:"Show character on minimap"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":n,"aria-labelledby":"appearance-character-label","aria-describedby":"appearance-character-note",onClick:r,children:o.jsx("span",{className:"switch-knob"})}),o.jsx("span",{id:"appearance-character-note",className:"vis-hidden",children:"Shows the animated minimap character and enables music playback."})]}),o.jsxs("div",{className:"sm-row",children:[o.jsx("label",{htmlFor:"appearance-fm-volume",children:"Volume"}),o.jsx("input",{id:"appearance-fm-volume",type:"range",min:di,max:Zl,step:df,value:s,"aria-describedby":"appearance-fm-volume-note",onChange:se=>l(Number(se.target.value)),style:{"--sm-level":`${(s-di)/(Zl-di)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[s,"%"]})]}),o.jsxs("label",{className:"appearance-row",children:[o.jsx("span",{className:"appearance-row-label",id:"appearance-fm-mute-label",children:"Mute music"}),o.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":c,"aria-labelledby":"appearance-fm-mute-label",onClick:u,children:o.jsx("span",{className:"switch-knob"})})]})]}),o.jsx("span",{id:"appearance-fm-volume-note",className:"vis-hidden",children:"Controls live music volume."})]})]})}),document.body)}const Q0="https://www.youtube-nocookie.com";function hG(e,t,n){const r=new URLSearchParams({...n?{}:{channel:e},enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Q0}/embed/${n?encodeURIComponent(n):"live_stream"}?${r.toString()}`}function Al(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function fG(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const pG=[1,3],mG=[0,2],gG=[2,5,100,101,150];function yG(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{event:n,info:r}=t;if(n==="onReady")return{kind:"ready"};if(n==="onError"){const s=typeof r=="number"?r:Number(r==null?void 0:r.errorCode);return Number.isFinite(s)?{kind:"error",code:s}:null}if(n==="onStateChange"||n==="infoDelivery"){const s=typeof r=="number"?r:r==null?void 0:r.playerState;return typeof s!="number"||!Number.isFinite(s)?null:pG.includes(s)?{kind:"playing",playing:!0}:mG.includes(s)?{kind:"playing",playing:!1}:null}return null}const f$=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],H2=18,wG=f$.length,p$=new Set(["a","c","p"]);function Jf(e=f$){const t=[];return e.forEach((n,r)=>{let s=0;for(;s<n.length;){const l=n[s];if(l==="."){s+=1;continue}let c=1;for(;s+c<n.length&&n[s+c]===l;)c+=1;t.push({x:s,y:r,w:c,cell:l}),s+=c}}),t}const hi=148,W2=6e3,vG=16e3,m$=46,ro=34;function xG(e,t,n=hi){let r=-Math.round(t()*n);if(Math.abs(r-e)<ro){const s=e-ro>=-n?-ro:ro;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return{to:r,ms:Math.round(Math.abs(r-e)*m$)}}function bG(e){return Math.round(W2+e()*(vG-W2))}const V2=[{kind:"stroll",weight:44},{kind:"tidy",weight:17},{kind:"kick",weight:17},{kind:"sit",weight:12},{kind:"watch",weight:16},{kind:"leave",weight:7},{kind:"fish",weight:12},{kind:"skip",weight:10}];function kG(e){const t=V2.reduce((r,s)=>r+s.weight,0);let n=e()*t;for(const r of V2)if(n-=r.weight,n<0)return r.kind;return"stroll"}const NG=720,SG=260,jG=620,_G=220,G2=520,g$=1600,K2=7e3,EG=15e3,Y2=6e3,CG=14e3;function Ml(e,t,n=hi){let r=-Math.round(t()*n);if(Math.abs(r-e)<ro){const s=e-ro>=-n?-ro:ro;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return r}const fn=(e,t)=>Math.round(Math.abs(t-e)*m$),TG=120,Ch=0;function RG(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:fn(e,t)},{x:t,prop:n({}),act:"stoop",ms:NG},{x:Ch,prop:n({held:!0}),act:"carry",ms:fn(t,Ch)},{x:Ch,prop:n({held:!0}),act:"windup",ms:SG},{x:Ch,prop:n({held:!0,leaving:!0}),act:"toss",ms:jG}]}function AG(e,t){const n=t>e?1:-1,r=t-n*Math.min(15,Math.abs(t-e)),s=(l={})=>({kind:"ball",at:t,...l});return[{x:r,prop:s(),act:"walk",ms:fn(e,r)},{x:r,prop:s(),act:"windup",ms:_G,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"kick",ms:G2,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"stand",ms:g$-G2}]}const y$=640;function MG(e,t,n){const r=Math.max(-70,Math.min(-20,t)),s={x:r,prop:null,facing:"left"};return[{x:r,prop:null,act:"walk",ms:fn(e,r)},{...s,act:"sit",ms:600},{...s,act:"cast",ms:900},{...s,act:"fish",ms:6e3+Math.round(n()*4e3)},{...s,act:"reel",ms:1200},{...s,act:"stow",ms:500},{...s,act:"stand",ms:400},{x:0,prop:null,act:"walk",ms:fn(r,0)}]}function IG(e,t,n){const r=Math.max(-110,Math.min(-30,t)),s={x:r,prop:null};return[{...s,act:"walk",ms:fn(e,r)},{...s,act:"skip-ready",ms:500},{...s,act:"skip",ms:y$*(6+Math.floor(n()*5))},{...s,act:"skip-rest",ms:600},{...s,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:fn(r,0)}]}function $G(e,t,n){return[{x:t,prop:null,act:"walk",ms:fn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(Y2+n()*(CG-Y2))},{x:t,prop:null,act:"stand",ms:400}]}function OG(e,t,n){t=Math.max(-110,Math.min(0,t));const r=()=>({kind:"scope",at:t,held:!0});return[{x:t,prop:null,act:"walk",ms:fn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(K2+n()*(EG-K2))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function Qx(e,t,n){return e.facing?e.facing:e.act==="watch"||e.act==="scope-pack"?"left":e.x===t?n:e.x>t?"right":"left"}const LG=1500,PG=e=>Math.round(1e3*Math.sqrt(2*e/LG)),DG=115,FG=e=>Math.round(e/DG*1e3),qG=620,BG=200,zG=760,UG=600,HG=240;function WG(e,t,n){const s=-(t.ledgeSpan??hi),l=PG(t.ledgeH),c=FG(t.ledgeH),u=n(),f=n(),p=-Math.round(u*t.floorSpan),h=-Math.round(f*t.floorSpan);return[{x:s,act:"walk",prop:null,ms:fn(e,s)},{x:s,act:"peer",prop:null,ms:qG},{x:s,act:"fall",prop:null,ms:l,place:"floor"},{x:s,act:"land",prop:null,ms:BG,place:"floor"},{x:p,act:"walk",prop:null,ms:fn(s,p),place:"floor",floorFrac:u},{x:h,act:"walk",prop:null,ms:fn(p,h),place:"floor",floorFrac:f},{x:s,act:"walk",prop:null,ms:fn(h,s),place:"floor"},{x:s,act:"lasso",prop:null,ms:zG,place:"floor"},{x:s,act:"rope-throw",prop:null,ms:UG,place:"floor"},{x:s,act:"rope-catch",prop:null,ms:HG,place:"floor"},{x:s,act:"climb",prop:null,ms:c},{x:s,act:"pull-up",prop:null,ms:480}]}function VG(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??hi;switch(kG(t)){case"tidy":return RG(e,Ml(e,t,r));case"kick":return AG(e,Ml(e,t,r));case"sit":return $G(e,Ml(e,t,r),t);case"watch":return OG(e,Ml(e,t,r),t);case"fish":return MG(e,Ml(e,t,r),t);case"skip":return IG(e,Ml(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return WG(e,n,t)}}const l=xG(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const GG=[".xx.","xxxx",".xx."],KG=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],YG=["...xx...............","..xaax..............",".xaallx.............","xaallllx............",".xllllllx...........","..xllllllx..........","...xllllllx.........","....xllllllxx.......",".....xllllxsxx..xx..","......xllxsssx.xllxx",".......xxssssxxxllxx","........xssssssxx...",".........xssssx.....","..........xxxx......","..........xax.......",".........xxxxx......","........xx.x.xx.....","........xl.x.lx.....",".......xl..x..lx....",".......xl..x..lx....","......xl...x...lx...","......xl...x...lx...",".....xl....x....lx..","....xxx...xxx...xxx."],Jx={litter:GG,ball:KG,scope:YG},w$=["bob","sway","groove"],X2=9e3,XG=16e3,v$=1e3,ZG=.08;function QG(e,t){const n=w$.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],s=(t()*2-1)*ZG;return{dance:r,beatMs:Math.round(v$*(1+s))}}function JG(e){return Math.round(X2+e()*(XG-X2))}const eK=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],tK=3,nK=-1,J0=11,Z2=9,rK=420;function sK(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(rK,Math.max(0,r))}const aK=260,oK=200;function iK(e,t,n){const r=(h,m=fn(e,h))=>({x:h,prop:null,act:"walk",ms:m,place:"floor"});if(!n||n.height<=0)return[r(t)];const s=Math.min(e,t);if(Math.max(e,t)<=n.left||s>=n.right)return[r(t)];const c=t>e,u=c?n.left:n.right,f=c?n.right:n.left,p={place:"floor",riser:n.height,prop:null};return[r(u,fn(e,u)),{...p,x:u,act:"mount",ms:aK},{...p,x:f,act:"walk",ms:fn(u,f)},{x:f,prop:null,act:"dismount",ms:oK,place:"floor"},{x:t,prop:null,act:"walk",ms:fn(f,t),place:"floor"}]}function Q2(e){let t=null,n=null,r=0,s=0,l=!1;const c=()=>{t!==null&&clearTimeout(t),t=null},u=()=>{l||e.hidden||!n||t!==null||(s=performance.now(),t=setTimeout(()=>{t=null;const p=n;n=null,p==null||p()},r))},f=()=>{e.hidden&&t!==null?(r=Math.max(0,r-(performance.now()-s)),c()):e.hidden||u()};return e.addEventListener("visibilitychange",f),{schedule(p,h){l||(c(),n=p,r=Math.max(0,h),u())},dispose(){l=!0,c(),n=null,e.removeEventListener("visibilitychange",f)}}}const lK={"claude-fm":"Claude FM","lofi-relax":"Lofi Girl relax/study","lofi-game":"Lofi Girl chill/game","lofi-vibe":"Lofi Girl vibe/chill","lofi-sleep":"Lofi Girl sleep/chill","radio-mix":"Radio Mix Live","best-of-nostalgia":"Best of Nostalgia Live","good-life-radio":"The Good Life Radio Live","cafe-music-bgm":"Cafe Music BGM Live"};function cK(e,t){return t&&ki(t.id)===e?t.name:Jl(e)?"Custom FM":lK[e]}const uK={"claude-fm":null,"lofi-relax":null,"lofi-game":null,"lofi-vibe":null,"lofi-sleep":null,"radio-mix":"/api/live-radio-mix","best-of-nostalgia":"/api/best-of-nostalgia","good-life-radio":"/api/good-life-radio","cafe-music-bgm":"/api/cafe-music-bgm"};function e0(e,t){var r;const n=((r=e[0])==null?void 0:r.length)??0;return o.jsx("svg",{viewBox:`0 0 ${n} ${e.length}`,shapeRendering:"crispEdges","aria-hidden":!0,children:Jf(e).map(s=>o.jsx("rect",{x:s.x,y:s.y,width:s.w,height:1,fill:s.cell==="s"?"var(--fm-prop-shadow, var(--bg))":s.cell==="l"?"var(--fm-prop-light, var(--text))":s.cell==="a"?"var(--accent)":void 0},`${t}${s.y}-${s.x}`))})}const t0={e:"fm-eye",s:"fm-shade",p:"fm-pad"},hf=Jf().filter(e=>!p$.has(e.cell)),dK=Jf().filter(e=>p$.has(e.cell)),J2=hf.filter(e=>e.cell==="e"),hK=Jf(eK),fK=hf.filter(e=>e.y<J0&&e.cell!=="e").map(e=>{if(e.y!==8&&e.y!==9)return e;const t=Math.max(6,e.x);return{...e,x:t,w:Math.max(0,Math.min(12,e.x+e.w)-t)}}).filter(e=>e.w>0),pK={left:hf.filter(e=>e.y>=J0&&e.x<Z2),right:hf.filter(e=>e.y>=J0&&e.x>=Z2)},eR={litter:e0(Jx.litter,"litter"),ball:e0(Jx.ball,"ball"),scope:e0(Jx.scope,"scope")};function mK(e){try{return new URL(e).host}catch{return"the station's server"}}const gK=w.memo(function({fetchImpl:t,volume:n,muted:r=!1,source:s="claude-fm",playRequest:l=0,customStation:c,onAvailabilityChange:u}){const[f,p]=w.useState(null),[h,m]=w.useState(!1),[y,v]=w.useState(!1),[S,b]=w.useState(!1),_=w.useRef(l),k=w.useRef(null),j=w.useRef(null),[E,C]=w.useState(0),[R,I]=w.useState(0),[$,q]=w.useState(null),[B,P]=w.useState(null),[W,ne]=w.useState({x:0,drop:0}),[ee,M]=w.useState("ledge"),[X,V]=w.useState("left"),[G,F]=w.useState(0),L=w.useRef(null),[H,D]=w.useState(()=>document.hidden);w.useEffect(()=>{const ue=new Set,ce=()=>{var se;if(document.hidden){for(const be of((se=L.current)==null?void 0:se.getAnimations({subtree:!0}))??[])if(be.playState==="running"||be.pending){const Le=be.currentTime;be.pause(),Le!==null&&(be.currentTime=Le),ue.add(be)}}else{for(const be of ue)be.playState==="paused"&&be.play();ue.clear()}D(document.hidden)};return ce(),document.addEventListener("visibilitychange",ce),()=>document.removeEventListener("visibilitychange",ce)},[f,h]);const[K,re]=w.useState(null),[z,Z]=w.useState(v$),[U,ae]=w.useState(()=>{var ue;return((ue=window.matchMedia)==null?void 0:ue.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});w.useEffect(()=>{var se;const ue=(se=window.matchMedia)==null?void 0:se.call(window,"(prefers-reduced-motion: reduce)");if(!ue)return;const ce=()=>ae(ue.matches);return ce(),ue.addEventListener("change",ce),()=>ue.removeEventListener("change",ce)},[]);const le=w.useRef(null),ge=w.useCallback(()=>{var ce;(ce=j.current)==null||ce.destroy(),j.current=null;const ue=k.current;ue&&(ue.pause(),ue.removeAttribute("src"),ue.load(),k.current=null)},[]),Ne=w.useCallback(ue=>{var ce,se;(se=(ce=le.current)==null?void 0:ce.contentWindow)==null||se.postMessage(ue,Q0)},[]),Ie=w.useRef(n);Ie.current=n;const Ge=w.useRef(r);Ge.current=r;const Pe=w.useCallback((ue,ce,se)=>{ge();const be=new Audio;be.preload="none",be.volume=Ie.current/100,be.muted=Ge.current,k.current=be,v(!0),b(!0);const Le=()=>k.current===be,de=()=>{ge(),v(!1),b(!1)},fe=()=>{Le()&&(de(),m(!0),u==null||u(se,!0))},Ce=pe=>{if(Le()){if(pe instanceof DOMException&&pe.name==="NotAllowedError"){de();return}fe()}};be.addEventListener("playing",()=>{Le()&&(b(!0),u==null||u(se,!1))}),be.addEventListener("ended",()=>{Le()&&de()}),be.addEventListener("error",fe,{once:!0}),ce&&!be.canPlayType("application/vnd.apple.mpegurl")?ab(async()=>{const{default:pe}=await import("./hls-BFpXDghs.js");return{default:pe}},[]).then(({default:pe})=>{if(!Le())return;if(!pe.isSupported()){fe();return}const _e=new pe;j.current=_e,_e.on(pe.Events.ERROR,(Ye,qe)=>{qe.fatal&&fe()}),_e.on(pe.Events.MEDIA_ATTACHED,()=>_e.loadSource(ue)),_e.on(pe.Events.MANIFEST_PARSED,()=>{be.play().catch(Ce)}),_e.attachMedia(be)},fe):(be.src=ue,be.play().catch(Ce))},[u,ge]);if(w.useEffect(()=>{y&&(Ne(Al("setVolume",[n])),Ne(Al(r?"mute":"unMute")),k.current&&(k.current.volume=n/100,k.current.muted=r))},[n,r,y,Ne]),w.useEffect(()=>{let ue=!0;const ce=t??fetch,se=_.current!==l;_.current=l,p(null),m(!1),v(se),b(se),ge();const be=c&&ki(c.id)===s?dk(c.url):null;if(be)return be.kind==="direct-audio"?(p({live:!0,channel:"",audio:be.url,hls:be.format==="hls"}),u==null||u(s,!1),se&&Pe(be.url,be.format==="hls",s),()=>{ue=!1}):(ce(`/api/fm-station?url=${encodeURIComponent(be.url)}`).then(fe=>fe.ok?fe.json():null).then(fe=>{ue&&(fe!=null&&fe.channel||fe!=null&&fe.video?(p({live:!0,channel:fe.channel??"",video:fe.video??void 0}),u==null||u(s,!1)):(m(!0),u==null||u(s,!0)))}).catch(()=>{ue&&(m(!0),u==null||u(s,!0))}),()=>{ue=!1});if(Jl(s))return m(!0),u==null||u(s,!0),()=>{ue=!1};const Le=s,de=uK[Le];if(de)ce(de).then(fe=>fe.ok?fe.json():null).then(fe=>{ue&&(fe!=null&&fe.video&&p({live:!0,channel:"",video:fe.video}),u==null||u(s,!(fe!=null&&fe.video)))}).catch(()=>{ue&&(u==null||u(s,!0))});else if(Le!=="claude-fm"){const fe=Le.replace("lofi-","");ce(`/api/lofi-girl?station=${encodeURIComponent(fe)}`).then(Ce=>Ce.ok?Ce.json():null).then(Ce=>{ue&&(Ce!=null&&Ce.video&&p({live:!0,channel:"",video:Ce.video}),u==null||u(s,!(Ce!=null&&Ce.video)))}).catch(()=>{ue&&(u==null||u(s,!0))})}else ce("/api/claude-fm").then(fe=>fe.ok?fe.json():null).then(fe=>{if(!ue)return;const Ce=!!(fe!=null&&fe.live&&(fe!=null&&fe.channel));Ce&&p({live:!0,channel:fe.channel}),u==null||u(s,!Ce)}).catch(()=>{ue&&(u==null||u(s,!0))});return()=>{ue=!1}},[c==null?void 0:c.id,c==null?void 0:c.url,t,u,l,s,Pe,ge]),w.useEffect(()=>()=>ge(),[ge]),w.useEffect(()=>{if(!y)return;const ue=ce=>{var be;if(ce.origin!==Q0||ce.source!==((be=le.current)==null?void 0:be.contentWindow))return;const se=yG(ce.data);if(se){if(se.kind==="ready"){Ne(Al("setVolume",[Ie.current])),Ne(Al(r?"mute":"unMute")),Ne(Al("playVideo"));return}if(se.kind==="playing"){b(se.playing);return}gG.includes(se.code)&&(v(!1),b(!1),m(!0),u==null||u(s,!0))}};return window.addEventListener("message",ue),()=>window.removeEventListener("message",ue)},[y,r,u,Ne,s]),w.useEffect(()=>{var Ue;if(!f||h||U)return;const ue=Q2(document);let ce=0;C(Fe=>ce=Fe);let se=null,be=0,Le=0;const de=Fe=>{var yt,It;const[Ve,...rt]=Fe;if(!Ve){se=null,q(null),P(null),qe();return}q(Ve.act),P(Ve.prop),M(Ve.place??"ledge"),F(Ve.riser??0);const ut=ce,ct=_e(Ve);if(Ve.act==="kick"){const zt=(It=(yt=L.current)==null?void 0:yt.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:It.getBoundingClientRect();zt&&ne({x:sK(zt.x,Qx(Ve,ut,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-zt.y+24)})}Le=Ve.act==="walk"?Math.max(fn(ut,ct),TG):Ve.ms,Ve.act==="carry"&&(Le=fn(ut,ct)),I(Le),V(zt=>Qx({...Ve,x:ct},ut,zt)),C(ct),ce=ct,se=Ve,be=Date.now(),ue.schedule(()=>de(rt),Le)},fe=()=>{const Fe=L.current,Ve=Fe==null?void 0:Fe.querySelector(".fm-sprite"),rt=Fe==null?void 0:Fe.parentElement;if(!Fe||!Ve||!rt)return null;const ut=Fe.getBoundingClientRect(),ct=rt.getBoundingClientRect(),yt=ct.right-ut.right,It=ct.width-yt*2-Ve.offsetWidth;return It>0?It:null},Ce=()=>{const Fe=L.current,Ve=Fe==null?void 0:Fe.querySelector(".fm-walker"),rt=fe();if(!Fe||!Ve||rt==null)return;const ut=Fe.getBoundingClientRect().bottom-Ve.getBoundingClientRect().bottom;if(ut>0)return{ledgeH:ut,floorSpan:rt}},pe=()=>{const Fe=L.current,Ve=document.querySelector(".autofit-chip");if(!Fe||!Ve)return null;const rt=Fe.getBoundingClientRect(),ut=Ve.getBoundingClientRect();return ut.width<=0||ut.height<=0?null:{left:ut.left-rt.right,right:ut.right-rt.right,height:ut.height}},_e=Fe=>{const Ve=(Fe.place??"ledge")==="floor",rt=Ve?fe()??hi:hi,ut=Ve&&Fe.floorFrac!=null?-Math.round(Fe.floorFrac*rt):Fe.x;return Math.max(-rt,Math.min(0,ut))},Ye=()=>{if(!se)return;const Fe=_e(se);Fe!==ce&&(I(Math.max(0,be+Le-Date.now())),V(Ve=>Qx({...se,x:Fe},ce,Ve)),C(Fe),ce=Fe)},qe=()=>{ue.schedule(()=>{const Fe=VG(ce,Math.random,Ce()),Ve=Fe.some(ct=>ct.place==="floor")?pe():null;let rt=ce;const ut=Fe.flatMap(ct=>{const yt=rt;if(rt=ct.x,!(ct.place==="floor"&&ct.act==="walk"))return[ct];const It=iK(yt,ct.x,Ve),zt=It.length-1;return ct.floorFrac==null?It:It.map((Xt,Ft)=>Ft===zt?{...Xt,floorFrac:ct.floorFrac}:Xt)});de(ut)},bG(Math.random))},ke=(Ue=L.current)==null?void 0:Ue.parentElement,Ae=typeof ResizeObserver>"u"?null:new ResizeObserver(Ye);return ke&&Ae&&Ae.observe(ke),qe(),()=>{ue.dispose(),Ae==null||Ae.disconnect(),M("ledge"),C(Fe=>Math.max(-hi,Math.min(0,Fe))),I(0),q(null),P(null),F(0)}},[f,h,U]),w.useEffect(()=>{if(!S||U){re(null);return}const ue=Q2(document),ce=se=>{const be=QG(se,Math.random);re(be.dance),Z(be.beatMs),ue.schedule(()=>ce(be.dance),JG(Math.random))};return ce(null),()=>ue.dispose()},[S,U]),!f||h)return null;const ze=()=>{if(f.audio){if(y){ge(),v(!1),b(!1);return}Pe(f.audio,f.hls===!0,s);return}if(!y){v(!0),b(!0);return}const ue=!S;b(ue),Ne(Al(ue?"playVideo":"pauseVideo")),ue||v(!1)},Re=cK(s,c),st=f.audio?mK(f.audio):"YouTube";return o.jsxs("div",{ref:L,className:"fm","data-suspended":H?"":void 0,"data-place":ee,style:{"--fm-beat":`${z}ms`},children:[B&&!B.held&&o.jsx("div",{className:"fm-prop","data-prop":B.kind,"data-leaving":B.leaving?"":void 0,style:{"--fm-prop-x":`${B.at}px`,"--fm-roll-to":`${W.x}px`,"--fm-ball-drop":`${W.drop}px`,"--fm-ball-flight-ms":`${g$}ms`,"--fm-ball-turn":X==="right"?"1080deg":"-1080deg"},children:eR[B.kind]}),($==="lasso"||$==="rope-throw"||$==="rope-catch"||$==="climb"||$==="pull-up")&&o.jsxs("div",{className:"fm-rope","data-act":$,style:{"--fm-rope-x":`${E}px`,"--fm-rope-ms":`${R}ms`},children:[o.jsx("div",{className:"fm-rope-line"}),o.jsxs("svg",{className:"fm-rope-hook",viewBox:"0 0 9 9",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{d:"M4 8V3H3V1H1V3H0V5H2V4H3V6H5V4H6V5H8V3H7V1H5V3H4"}),o.jsx("rect",{className:"fm-rope-knot",x:"3",y:"6",width:"3",height:"2"})]})]}),o.jsxs("div",{className:"fm-walker","data-act":$??void 0,"data-place":ee,"data-facing":X,style:{"--fm-x":`${E}px`,"--fm-walk-ms":`${R}ms`,"--fm-riser":`${G}px`,"--fm-skip-beat":`${y$}ms`},children:[(B==null?void 0:B.held)&&o.jsx("div",{className:"fm-held","data-prop":B.kind,"data-toss":B.leaving?"":void 0,children:eR[B.kind]}),["cast","fish","reel","stow"].includes($)&&o.jsxs("svg",{className:"fm-fishing",viewBox:"0 0 24 32",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsxs("g",{children:[o.jsx("path",{d:"M24 11H22V9H20V7H18V5H16V3H13V2H8"}),o.jsx("rect",{className:"fm-fishing-grip",x:"21",y:"9",width:"3",height:"3"})]}),o.jsxs("g",{className:"fm-fishing-line",children:[o.jsx("path",{d:"M8 2V26"}),o.jsxs("g",{className:"fm-float",children:[o.jsx("rect",{x:"7",y:"25",width:"3",height:"2"}),o.jsx("rect",{x:"8",y:"24",width:"1",height:"1"})]})]}),o.jsx("path",{className:"fm-ripple",d:"M3 28H6M10 28H14M5 30H12"})]}),["skip-ready","skip","skip-rest"].includes($)&&o.jsxs("svg",{className:"fm-skipping-rope",viewBox:"0 0 26 26",shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("path",{className:"fm-skip-back",d:"M5 18H3V8H5V5H8V2H18V5H21V8H23V18H21"}),o.jsx("path",{className:"fm-skip-forward",d:"M5 18H3V14H5V11H8V9H18V11H21V14H23V18H21"}),o.jsx("path",{className:"fm-skip-front",d:"M5 18H3V21H5V23H8V25H18V23H21V21H23V18H21"}),o.jsx("path",{className:"fm-skip-return",d:"M5 18H3V19H8V20H18V19H23V18H21"}),o.jsx("path",{className:"fm-skip-handles",d:"M5 17V19M21 17V19"})]}),o.jsx("button",{type:"button",className:"fm-sprite","data-playing":S?"":void 0,"data-dance":S?K??w$[0]:void 0,onClick:ze,title:S?`Stop ${Re}`:`Play ${Re} — streams from ${st}`,"aria-label":S?`Stop ${Re}`:`Play ${Re}`,children:o.jsxs("svg",{viewBox:`0 0 ${H2} ${wG}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("g",{className:"fm-gear",children:o.jsx("g",{className:"fm-gear-motion",children:dK.map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:t0[ue.cell]},`g${ue.y}-${ue.x}`))})}),o.jsxs("g",{className:"fm-body",children:[J2.map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,fill:"var(--accent)"},`eye-bed-${ue.x}`)),fK.map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:t0[ue.cell]},`b${ue.y}-${ue.x}`)),o.jsxs("g",{className:"fm-arms",children:[o.jsx("rect",{x:4,y:8,width:2,height:2}),o.jsx("rect",{x:12,y:8,width:1,height:2}),o.jsx("rect",{x:13,y:8,width:1,height:2,className:"fm-shade"})]}),J2.map(ue=>o.jsx("rect",{x:ue.x-(ue.x>=H2/2?1:0)+(X==="right"?1:0),y:ue.y,width:ue.w,height:1,className:"fm-eye"},`eye-${ue.x}`))]}),o.jsx("g",{className:"fm-hat",children:hK.map(ue=>o.jsx("rect",{x:tK+ue.x,y:nK+ue.y,width:ue.w,height:1,className:ue.cell==="k"?"fm-hatband":void 0},`h${ue.y}-${ue.x}`))}),($==="climb"||$==="rope-throw"||$==="rope-catch"||$==="pull-up")&&o.jsxs("g",{className:"fm-grip",children:[o.jsx("path",{className:"fm-grip-left",d:"M5 9H4V4H7V3H9V5H6V9Z"}),o.jsx("path",{className:"fm-grip-right",d:"M12 9H14V6H11V5H9V7H12Z"})]}),($==="land"||$==="dismount")&&o.jsxs("g",{className:"fm-crouch-legs",children:[o.jsx("path",{d:"M6 11H8V13H6Z"}),o.jsx("path",{d:"M10 11H12V13H10Z"})]}),["sit","cast","fish","reel","stow"].includes($)&&o.jsxs("g",{className:"fm-seated-legs",children:[o.jsx("path",{className:"fm-seated-far",d:"M10 10H12V11H11V14H8V13H9V11H10Z"}),o.jsx("path",{d:"M6 10H9V11H7V15H4V14H5V11H6Z"})]}),["left","right"].map(ue=>o.jsx("g",{className:"fm-leg","data-side":ue,children:pK[ue].map(ce=>o.jsx("rect",{x:ce.x,y:ce.y,width:ce.w,height:1,className:t0[ce.cell]},`${ue}${ce.y}-${ce.x}`))},ue))]})})]}),y&&!f.audio&&(f.channel||f.video)&&o.jsx("iframe",{ref:le,className:"fm-frame",title:Re,src:hG(f.channel,window.location.origin,f.video),onLoad:()=>Ne(fG()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),yK=15e3;function wK(e){return e.visibilityState==="visible"&&e.hasFocus()}function vK(e,t){return t||e===!0}function xK(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}const bK={"//":["What a user would NOTICE. One key per version that has something to say,","and no key at all for a version that has nothing — which is most of them.","","The rule this file exists to serve: before every release, ask 'what would a","user notice?' and write the answer here. 'Nothing user-visible' is a valid","and expected answer, and it is spelled by adding no key. A release with no","key shows no modal, and that silence is what keeps the modal worth reading","on the day it is not silent.","","What belongs here: something that changed on the user's machine or under","their hands — a hook written to or removed from settings.json, a default","that flipped, a control that moved or went away, a stored preference that","changed meaning. What does not: bounds, races, assertions that could not","fire, anything that is invisible when it is correct.","","Write it for the person running the deck, not for the person reading the","diff. `title` is the sentence they scan; `body` is what they need in order","to act on it, or to stop worrying about it.","","Keys are versions exactly as package.json spells them. A key that is not a","version, or an entry missing either field, fails the suite rather than","being quietly dropped — see src/web/__tests__/release-notes-file.test.ts.","Ordering here is for humans; the deck sorts by version itself.","","A title may open with an emoji, and if it does, put exactly ONE space after","it. Not two: the dialog gives a leading emoji its own optical gap, because","a colour glyph is drawn edge to edge inside its advance and one word space","after one reads as none. A second space here would be a lie in the data","about a defect in the type, and the suite refuses both it and no space at","all.","","A release that genuinely has nothing to say is spelled TWICE: no key here,",'and its version written into "//nothing-to-say" below. One spelling on its',"own is ambiguous — a missing key reads the same whether it was a decision","or a forgotten step, and five releases in a row were once forgotten. The list","is what tells the two apart, and release-notes-current-version.test.ts fails","the release whose version is in neither place. Any key opening with // is a","note to the author and never a release."],"//nothing-to-say":["3.23.1","3.23.2","3.23.3","3.23.4","3.26.0","3.26.1","3.26.3","3.26.4","3.26.5","3.27.6","3.27.7","3.28.0","3.28.1","3.29.3","3.29.4","3.29.6","3.29.7","3.29.9"],"3.29.11":[{title:"💲 Claude Sonnet 5.5 has a price",body:`Sessions on Claude Sonnet 5.5 showed "not priced" on the board, and the Projects report could only show a minimum for them. They are now priced at Anthropic's published rate, the same as Sonnet 5: $2 per million input tokens and $10 per million output tokens.`}],"3.29.10":[{title:"💲 Claude Opus 5.5 has a price",body:`Sessions on Claude Opus 5.5 showed "not priced" on the board, and the Projects report counted them as costing nothing, so its totals read far too low. They are now priced at Anthropic's published rate. If a model still has no price, Projects shows its total as a minimum, like $11.19+, and names the model, instead of a total that looks complete.`}],"3.29.8":[{title:"🔁 Removed cards come back when their agent works again",body:"Remove from board is for finished work. If the agent behind a card you removed starts a tool call, gets a new prompt or starts a subagent, the card returns on its own, together with the card it hangs from, and it stays back after a reload. Cards whose agents stay idle stay removed."}],"3.29.1":[{title:"🗂️ One row per project in Projects",body:"The Projects report now counts a session's work under the folder you started it in, the same name its card has on the canvas, instead of adding a row for every folder the agent moved into. The first start after updating re-reads your transcripts once to regroup the report."},{title:"🔔 Tidier custom sounds",body:"Importing a sound, recording one and choosing a spoken voice now sit in compact cards that respond to clicks and focus like the rest of the deck."}],"3.29.0":[{title:"🎵 Your own stations in Claude FM",body:"Add any YouTube live link or radio stream as a station in Appearance, next to the built-in ones, and mute the music without losing your volume. When a station is not live, the picker now says so instead of staying silent."},{title:"🔔 Notification sounds and voices of your own",body:"Pick a local audio file or a spoken voice for each alert, so the sound that means an agent is waiting is one you will recognise."},{title:"🗑️ Drag a card off the board to remove it",body:"Drag a card to the target at the bottom of the canvas to take it off the board, or use Remove from board in the detail panel (Delete). The session keeps running, and the session list (L) brings it back."},{title:"🔐 Optional invite-only pairing",body:"Pairing works as before, with or without an invite. If you want, Local network can now be set to accept only decks that join with an invite you created, so a nearby machine cannot ask to pair on its own."},{title:"🌐 Account sharing between your machines is more reliable",body:"A locked macOS Keychain is explained instead of failing silently, a login that is broken or belongs to another account is never shared, and a sync that stops partway keeps what already arrived."},{title:"📅 Projects opens on Today",body:"The Projects report per account starts with today's work, and an empty window offers the next wider one. The topbar also shows this month's usage, and the desktop app can restart into an update from its own window."}],"3.27.0":[{title:"📊 Projects: where each account spent its work",body:"Each account card's ⋯ menu now breaks its cost down by project, over 7d / 30d / all."}],"3.27.1":[{title:"🎨 Make Appearance easier to tune",body:"The Appearance dialog now has clearer sections, stronger selection states, and a calmer layout for choosing a theme and configuring music. Your existing settings and keyboard shortcuts continue to work."}],"3.27.2":[{title:"💰 Project costs now match Usage",body:"Project cost totals no longer count the same Claude request once for every content block. Existing project history is rebuilt automatically so the totals align with the Usage panel."}],"3.27.3":[{title:"🎵 Station selection works in the desktop app",body:"The music station picker now opens inside ccdeck instead of relying on the operating system popup, so choosing a station works reliably in the Electron app."}],"3.27.4":[{title:"✅ Desktop picker release checks are green",body:"The station picker now keeps the same keyboard, motion, focus, and layout behavior as the rest of ccdeck across desktop and browser builds."}],"3.27.5":[{title:"🧭 The welcome tour stays dismissed",body:"Electron now remembers that you completed the onboarding tour at the deck level, so an update or loopback port change no longer shows the same tour again."},{title:"🎵 The station picker has a clearer finish",body:"The music selector has a tighter trigger, a purposeful chevron, and more deliberate option spacing so it reads like a native part of Appearance."}],"3.25.0":[{title:"🖱️ A click goes to the session, a double-click opens the details",body:"Clicking a card frames it with the rest of its session and leaves the detail panel shut. Double-click a card to open its details; `j`/`k`, the session list, Enter and `D` still open them too."},{title:"🔭 Cards stay readable when you zoom out",body:"At every zoom a card shows its name, its state and anything waiting on you, instead of shrinking to a coloured pill. Hover or focus a card to see it whole. Recap notes read at a distance too, and show the full recap on hover."},{title:"🌐 The Machine panel shows your network",body:"A new Network section shows download, upload and the round trip to Claude's API, and names the route when traffic goes through a VPN or a Tailscale exit node. Those checks run only while the panel is open. The panel is regrouped into CPU, Memory, Network and Thermal, with a flag at the top when something needs attention."},{title:"🎨 See each theme before you pick it",body:"The Appearance menu shows a small preview of the deck in Light and in Dark. Claude FM also keeps its volume when a notification chime plays, instead of dipping under it."}],"3.24.1":[{title:"🎛️ Appearance is one small menu now",body:"The topbar's appearance control opens a compact menu where you can choose Light or Dark and show or hide the character. The character stays on by default, and your choice is remembered."}],"3.24.0":[{title:"🎧 Claude FM plays from the minimap",body:"A small character stands on the minimap's top edge. Press it and the Claude channel's live stream plays; press it again and it stops. It only turns up when the channel is actually broadcasting, so a deck with no network never shows it at all."},{title:"🤠 And it gets on with its day",body:"It walks that edge, tidies up what it finds, kicks a ball along it, sits with its legs over the side, and watches the board through a scope. Now and then it drops onto the canvas and ropes its way back up. Headphones on while the music plays, a hat when it does not."}],"3.23.5":[{title:"🧭 The accounts panel opens on the account you are on",body:"Its windows, its resets and how old the numbers are — whole, at the top of the column. Every other account stands behind one row that says how many of them a switch could actually reach; press it to see them, or rest on it to be shown their names and how much room each has left."},{title:"⚙️ Auto-switch moved in there with them",body:"It is behind that same row now, after the accounts it switches between, rather than at the foot of the panel. The row says `auto 90%` or `auto off` so you can tell what the policy is doing without opening it — and says so in amber when it is armed with nowhere left to go."}],"3.23.0":[{title:"🧭 The accounts column leads with accounts",body:`The live account is the open row: its windows as bars, when each one resets, and how old the numbers are. Every other account rests on the two figures a switch is decided by, and opens with a click when you want the rest.
93
93
 
94
94
  A problem stays on the row — an expired login, one that was never stored, a keychain the deck cannot open — with the reason and the sign-in one press away. Auto-switch is one row now: its threshold and its switch. Local network moved out of the column into a view of its own, reached from a row at the foot that says how many of the paired machines are on right now, and shows which ones when you hover it.`},{title:"💬 A resting session shows Claude Code's recap beside its card",body:"When a session stops, Claude Code's own recap of what it did is drawn beside the card — so a board you come back to says what happened without opening anything."},{title:"🪟 The chrome went quiet",body:`The topbar is borderless, one set of corners runs through the app, the canvas ground is flat, and the minimap, the zoom controls, the type filter and the Machine and Usage panels read as tooling rather than as cards.
95
95
 
@@ -287,7 +287,7 @@ Both CLIs get the finish tone. The second tone — Claude is waiting for you —
287
287
 
288
288
  Waiting for a click: this browser plays no sound until the page has been used at least once. Anything you press unlocks it.`:"";return c+u+f+`
289
289
 
290
- Click to set the volume and the sound of each tone, and to hear either one.`}function pf(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const gR=99;function _X(e){const t=Math.max(0,Math.floor(e));return t>gR?`${gR}+`:String(t)}const EX="Pause the canvas";function CX(e){if(!e.paused)return"Pause live updates — events keep arriving and are applied when you resume (Space)";const t=Math.max(0,Math.floor(e.dropped??0));return t>0?`The pause is full — ${pf(e.held)} held and ${t} older ${t===1?"one":"ones"} already dropped. Resume to follow the canvas again (Space)`:e.held<=0?"Nothing has arrived since you paused. Resume to follow the canvas again (Space)":`${pf(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function TX(e){return e.connected||!e.paused?null:"The canvas is paused as well — Space resumes it, but nothing new arrives until the stream is back."}const P$="paused · full",RX=(e,t)=>t>0?P$:e>0?`paused · ${_X(e)}`:"paused";function AX(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:RX(e.held,t),widest:P$,title:t>0?`Connected — the pause is full at ${pf(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${pf(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",resting:!0,label:"live",widest:"live",title:"Receiving events"}:{tone:"dead",resting:!1,label:"offline",widest:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}const MX=w.lazy(()=>ab(()=>import("./UsageHistoryModal-C-sPhsKT.js"),[])),IX=w.lazy(()=>ab(()=>import("./BrowserWatchModal-CMn28FHb.js"),[]));function yR(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const $X={agent:nq,sessionGroup:$q,recapNote:Lq},OX={recapTie:Pq},D$="react-flow__node";function a0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,D$))===!0}const o0=80,i0=.86;function wR(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const r of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const s=r.getBoundingClientRect();s.width>0&&s.left>t.left&&(n=Math.min(n,s.left))}return Math.max(0,t.right-n)}function LX(e){try{const t=document.querySelector(`.${D$}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const PX=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),DX=420,Mh=18,vR=400,l0=450,mk="agent-dag.layout",gk="agent-dag.layoutFrame",yk="agent-dag.viewport",F$="agent-dag.sessionListOpen",q$="agent-dag.detailOpen",B$="agent-dag.usagePanelOpen",z$="agent-dag.systemPanelOpen",xR="agent-dag.accountsPanelOpen",c0="agent-dag.versionNoticeDismissed",bR="agent-dag.oldNameNoticeDismissed",FX=15*6e4,u0={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:",retired_name:"this install came from a name that is no longer published — run:"},Ih="agent-dag.autoRestart",kR="agent-dag.bundleReloadedFor";function qX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(F$)==="1"}catch{return!1}}function BX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(F$,e?"1":"0")}catch{}}function zX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(q$)==="1"}catch{return!1}}function UX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(q$,e?"1":"0")}catch{}}function HX(){const e=yr(B$);return e===null?!0:e==="1"}function WX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(B$,e?"1":"0")}catch{}}function VX(){const e=yr(z$);return e===null?!0:e==="1"}function GX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(z$,e?"1":"0")}catch{}}function KX(){if(typeof window>"u")return{positions:[],pins:[]};try{return qY(window.localStorage.getItem(mk))}catch{return{positions:[],pins:[]}}}function $h(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(mk,BY(e,t))}catch{}}function YX(){if(typeof window>"u")return null;try{return zY(window.localStorage.getItem(gk))}catch{return null}}function XX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(gk,JSON.stringify(e))}catch{}}function ZX(){if(typeof window>"u")return null;try{return UY(window.localStorage.getItem(yk))}catch{return null}}function QX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(yk,JSON.stringify(e))}catch{}}function NR(){if(!(typeof window>"u")){try{window.localStorage.removeItem(mk)}catch{}try{window.localStorage.removeItem(yk)}catch{}try{window.localStorage.removeItem(gk)}catch{}}}function JX(e,t){const n=J9(e,t,new Date().toISOString());if(!n)return;const r=JSON.stringify(n,null,2),s=new Blob([r],{type:"application/json"}),l=URL.createObjectURL(s),c=document.createElement("a");c.href=l,c.download=eV(n.label,t),document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(l),1e3)}const U$={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},eZ={file:"M3.4 1.8h4.5l2.7 2.7v7.7H3.4z M7.9 1.8v2.7h2.7",shell:"M2.4 3.8 5.6 7l-3.2 3.2 M7.4 10.6h4.2",web:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M1.8 7h10.4 M7 1.8c-1.5 1.4-2.3 3.1-2.3 5.2s.8 3.8 2.3 5.2c1.5-1.4 2.3-3.1 2.3-5.2S8.5 3.2 7 1.8z",agent:"M3.3 4.8h7.4a1.2 1.2 0 0 1 1.2 1.2v4.8a1.2 1.2 0 0 1-1.2 1.2H3.3a1.2 1.2 0 0 1-1.2-1.2V6a1.2 1.2 0 0 1 1.2-1.2z M7 4.8V2.4 M5.3 8.2h.01 M8.7 8.2h.01",task:"M2.2 4l1.2 1.2 2-2.2 M7.4 4.2h4.4 M2.2 9.4l1.2 1.2 2-2.2 M7.4 9.6h4.4",plan:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M9 5 8 8 5 9l1-3z",mcp:"M5 1.8v2.6 M9 1.8v2.6 M3.6 4.4h6.8v2.2a3.4 3.4 0 0 1-6.8 0z M7 10v2.2",other:"M3.5 7h.01 M7 7h.01 M10.5 7h.01"};function tZ({cat:e}){return o.jsx("svg",{className:"cat-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:eZ[e]})})}const mf={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},H$=gM;function nZ(){return o.jsx(Nb,{children:o.jsx(aZ,{})})}const rZ=e=>e.transform[2]>=e.maxZoom,sZ=e=>e.transform[2]<=e.minZoom;function aZ(){var qc,ra,Bc,Ko;const e=Nf(),t=Et(rZ),n=Et(sZ),r=tn(),s=w.useState(E0)[0],l=w.useRef(s),[c,u]=w.useState(()=>ZK(typeof window>"u"?null:window.localStorage)),[f,p]=w.useState(null),[,h]=w.useState(0),m=w.useCallback(()=>h(T=>T+1),[]),[y,v]=w.useState(zX);w.useEffect(()=>{UX(y)},[y]);const[S,b]=w.useState(()=>new Set),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useCallback((T,A,Y=!A)=>{b(te=>{if(!A)return new Set([T]);const ye=new Set(te);return ye.has(T)?ye.delete(T):ye.add(T),ye}),k(te=>A&&te===T?te:T),!A&&Y&&v(!0)},[]),R=w.useCallback(()=>{b(new Set),k(null)},[]),[I,$]=w.useState(null),[q,B]=w.useState(null),P=w.useCallback(T=>B(T),[]),[W,ne]=w.useState(!1),[ee,M]=w.useState(!1),[X,V]=w.useState(!1),G=w.useRef(null),[F,L]=w.useState(qX);w.useEffect(()=>{BX(F)},[F]);const[H,D]=w.useState(HX);w.useEffect(()=>{WX(H)},[H]);const[K,re]=w.useState(null),[z,Z]=w.useState(!1),U=w.useRef(null);w.useEffect(()=>{let T=!0,A=!1,Y=null,te=null,ye="";const je=xt=>{T&&(Z(!0),xt!==ye&&re(null))},Oe=()=>{if(A)return;A=!0,Y=Date.now();const xt=fR();te=xt,fetch(`/api/ccusage?since=${xt}`).then(ft=>ft.ok?ft.json():null).then(ft=>{if(T){if(!(ft!=null&&ft.ok)){je(xt);return}ye=xt,re(fX(ft)),Z(!1)}}).catch(()=>je(xt)).finally(()=>{A=!1})},Be=()=>{const xt=U.current;hX({shown:!!xt&&xt.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:te,since:fR(),lastReadAt:Y,now:Date.now()})&&Oe()};Be();const lt=window.setInterval(Be,dX);document.addEventListener("visibilitychange",Be);let et=null;return U.current&&typeof ResizeObserver<"u"&&(et=new ResizeObserver(Be),et.observe(U.current)),()=>{T=!1,window.clearInterval(lt),document.removeEventListener("visibilitychange",Be),et==null||et.disconnect()}},[]);const[ae,le]=w.useState(VX);w.useEffect(()=>{GX(ae)},[ae]);const ge=w.useRef(!1),[Ne,Ie]=w.useState(()=>{const T=(()=>{try{const A=window.localStorage.getItem(xR);return A===null?!0:A==="1"}catch{return!0}})();return T&&F?(ge.current=!0,!1):T});w.useEffect(()=>{if(!(!Ne&&ge.current))try{window.localStorage.setItem(xR,Ne?"1":"0")}catch{}},[Ne]),w.useEffect(()=>{!F&&ge.current&&(ge.current=!1,Ie(!0))},[F]);const Ge=wh(Ne,200),Pe=wh(H,130),ze=wh(ae,130),[Re,st]=w.useState(null);w.useEffect(()=>{let T=null;try{T=localStorage.getItem("agent-dag.sound")}catch{}st(T===null?!0:T==="on")},[]);const ue=w.useCallback(()=>{st(T=>{var Y;const A=T!==!0;try{localStorage.setItem("agent-dag.sound",A?"on":"off")}catch{}return A&&((Y=Ut.current)==null||Y.unlock()),A})},[]),ce=w.useCallback(T=>{ue()},[ue]),se=w.useRef(ce);se.current=ce;const be=w.useRef(Re);be.current=Re;const[Le,de]=w.useState(()=>OV(yr)),fe=w.useRef(Le);fe.current=Le;const[Ce,pe]=w.useState(()=>hV(yr)),_e=w.useRef(Ce);_e.current=Ce;const[Ye,qe]=w.useState([]),ke=w.useCallback(T=>{pe(A=>{const Y={...A,[T]:null};return _e.current=Y,Y});try{localStorage.removeItem(vu[T])}catch{}},[]),Ae=w.useCallback((T,A)=>{const Y=_e.current[T];if(!(A&&Y!==A)){ke(T),de(te=>{const ye={...te,[T]:{...te[T],figure:wr}};return fe.current=ye,ye});try{localStorage.setItem(Hh[T],wr)}catch{}}},[ke]),Ue=w.useRef(Ae);Ue.current=Ae,w.useEffect(()=>{let T=!0;return NV().then(A=>{if(!T)return;qe(A);const Y=new Set(A.map(te=>te.id));for(const te of Uh){const ye=_e.current[te];ye&&!Y.has(ye)&&Ue.current(te,ye)}},()=>{}),()=>{T=!1}},[]);const Fe=w.useRef(null),Ve=w.useCallback((T,A=!1)=>{var Y,te;if((Y=Ut.current)==null||Y.unlock(),Fe.current!==null&&clearTimeout(Fe.current),Fe.current=null,!A){(te=Ut.current)==null||te.play(T,!0);return}Fe.current=setTimeout(()=>{var ye;Fe.current=null,(ye=Ut.current)==null||ye.play(T,!0)},RV)},[]),rt=w.useCallback((T,A)=>{de(Y=>{const te={level:Ql(A.level??Y[T].level),figure:o$(T,A.figure??Y[T].figure)};try{localStorage.setItem(c$[T],String(te.level)),localStorage.setItem(Hh[T],te.figure)}catch{}return{...Y,[T]:te}}),Ve(T,!0)},[Ve]),ut=w.useCallback((T,A)=>{if(!Ye.some(te=>te.id===A))return;const Y={..._e.current,[T]:A};_e.current=Y,pe(Y);try{localStorage.setItem(vu[T],A)}catch{}Ve(T,!0)},[Ye,Ve]),ct=w.useCallback(async T=>{var ye;const A=G0(Ye.length);if(A)throw new Error(A);const Y=window.AudioContext??window.webkitAudioContext;if(!Y)throw new Error("This browser cannot decode audio files.");const te=new Y;try{const je=await wV(T,Be=>te.decodeAudioData(Be));await $2(je);const Oe=Du(je);qe(Be=>[...Be.filter(lt=>lt.id!==Oe.id),Oe])}finally{(ye=te.close)==null||ye.call(te)}},[Ye.length]),yt=w.useCallback(async T=>{const A=G0(Ye.length);if(A)throw new Error(A);const Y=vV(T);await $2(Y);const te=Du(Y);qe(ye=>[...ye.filter(je=>je.id!==te.id),te])},[Ye.length]),It=w.useCallback(async(T,A)=>{const Y=Ye.find(ye=>ye.id===T),te=A.trim().slice(0,80);!Y||!te||te===Y.name||(await jV(T,te),qe(ye=>ye.map(je=>je.id===T?{...je,name:te}:je)))},[Ye]),zt=w.useCallback(async T=>{await _V(T),qe(ye=>ye.filter(je=>je.id!==T));const A=_e.current,Y=fV(A,T);_e.current=Y,pe(Y);const te=Uh.filter(ye=>A[ye]===T);for(const ye of te)try{localStorage.removeItem(vu[ye]),localStorage.setItem(Hh[ye],wr)}catch{}te.length>0&&de(ye=>{const je={...ye};for(const Oe of te)je[Oe]={...je[Oe],figure:wr};return fe.current=je,je})},[]),Xt=w.useCallback(T=>{var te,ye;const A=Uh.find(je=>_e.current[je]===T),Y=A?fe.current[A].level:bi;(te=Ut.current)==null||te.unlock(),(ye=Ut.current)==null||ye.previewCustom(T,Y)},[]);w.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const[Ft,rn]=w.useState(!1),Se=w.useRef(null),[vt,kt]=w.useState(!1),_n=w.useRef(null);w.useEffect(()=>{Ft&&kt(!1)},[Ft]);const Ut=w.useRef(null),[Vn,Vt]=w.useState("locked");w.useEffect(()=>{const T=PV({enabled:()=>be.current===!0,prefs:()=>fe.current,customSelection:()=>_e.current,loadCustom:SV,onCustomFailure:(Y,te)=>Ue.current(Y,te),onState:Vt});Ut.current=T,Vt(T.state());const A=()=>T.unlock();return window.addEventListener("pointerdown",A,{once:!0,capture:!0}),window.addEventListener("keydown",A,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("keydown",A,{capture:!0})}},[]);const[$t,Zt]=w.useState(!1),[Ln,Ur]=w.useState(!1),[xe,ir]=w.useState(null),[Ns,Hr]=w.useState(null),[ma,Ss]=w.useState(!1),[xr,Pn]=w.useState(null),[Hs,Q]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(c0)??""}catch{return""}}),[De,Je]=w.useState(!1),He=w.useRef(0),[tt,wt]=w.useState(!1),gt=w.useCallback((T=!1)=>(T&&(He.current=Date.now(),wt(!0)),fetch(T?"/api/version?refresh=1":"/api/version").then(A=>A.ok?A.json():null).then(A=>{A&&ir(A)}).catch(()=>{}).finally(()=>{T&&wt(!1)})),[]),At=w.useCallback(()=>{gt(Date.now()-He.current>=FX)},[gt]);w.useEffect(()=>{gt();const T=window.setInterval(At,5*6e4),A=()=>{document.visibilityState==="visible"&&At()};return document.addEventListener("visibilitychange",A),()=>{window.clearInterval(T),document.removeEventListener("visibilitychange",A)}},[gt,At]),w.useEffect(()=>{$t&&gt()},[$t,gt]);const Ct=w.useRef(0);w.useEffect(()=>{if(!$t||!pu())return;let T=!1;const A=Ct.current;return fetch("/api/desktop-update").then(Y=>Y.ok?Y.json():null).then(Y=>{if(T||Ct.current!==A)return;const te=sR(Y);te&&Hr(te)}).catch(()=>{}),()=>{T=!0}},[$t]);const Qt=DK(Ns),St=w.useRef(!1),br=w.useRef(0),lr=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(br.current),[]);const Ci=w.useCallback(async T=>{if(!Ps(St.current))return;const A=++lr.current;window.clearTimeout(br.current),St.current=!0,Ss(!0),Pn(null);const Y=te=>{A===lr.current&&(window.clearTimeout(br.current),St.current=!1,Ss(!1),Pn({failure:te,version:T}))};try{const te=await fetch("/api/desktop-update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:T})});if(!te.ok)return Y(zK(await te.json().catch(()=>null)))}catch{return Y("unreachable")}A===lr.current&&(br.current=window.setTimeout(()=>Y("timeout"),N$))},[]);w.useEffect(()=>{const T=xK();let A=null;const Y=Oe=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:T,looking:Oe}),keepalive:!0}).catch(()=>{})},te=()=>{const Oe=wK(document);vK(A,Oe)&&Y(Oe),A=Oe},ye=()=>{A&&Y(!1),A=!1};te();const je=window.setInterval(te,yK);return window.addEventListener("focus",te),window.addEventListener("blur",te),document.addEventListener("visibilitychange",te),window.addEventListener("pagehide",ye),()=>{window.clearInterval(je),window.removeEventListener("focus",te),window.removeEventListener("blur",te),document.removeEventListener("visibilitychange",te),window.removeEventListener("pagehide",ye),ye()}},[]);const dt=(xe==null?void 0:xe.notice)??null,[cr,sn]=w.useState(null),Wr=cr&&Qt?Qt.version:null,Gn=w.useRef(null);w.useEffect(()=>{!Wr||Gn.current===Wr||(Gn.current=Wr,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:Wr})}).catch(()=>{}))},[Wr]);const Ju=w.useRef(!1);w.useEffect(()=>{if(Ju.current)return;const T=rR(),A=TK(T),Y=OK({stored:A,running:(xe==null?void 0:xe.running)??null,notes:nR,remembers:RK(T)});if(Y.reason==="no-version")return;Ju.current=!0,Y.record&&AK(T,Y.record);let te=!0;return(async()=>{var lt;let je=MK(T);if(pu())try{const et=await fetch("/api/prefs");if(!et.ok)throw new Error("desktop tour preferences unavailable");const xt=await et.json();if(!(xt!=null&&xt.ok))throw new Error("desktop tour preferences unavailable");const ft=((lt=xt.prefs)==null?void 0:lt.tourSeen)===!0;je&&!ft&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),je=je||ft}catch{je=!0}if(!te)return;const Oe=$K({tourSeen:je,decision:Y}),Be=Y.show.length?{entries:Y.show,since:A,firstRun:!1}:null;Oe.tour&&V(!0),Oe.notes==="now"?sn(Be):Oe.notes==="after"&&(G.current=Be)})(),()=>{te=!1}},[xe==null?void 0:xe.running]);const uo=(xe==null?void 0:xe.running)??"3.29.10",ed=w.useMemo(()=>x$(nR,null,uo),[uo]),ga=w.useCallback(()=>{sn({entries:ed,since:null,firstRun:!1})},[ed]),[Ti,ho]=w.useState(null),[Kn,ep]=w.useState(rb);w.useEffect(()=>{let T=!1;return fetch("/api/health").then(A=>A.ok?A.json():null).then(A=>{T||(ep(xX(A)),!(!A||typeof A.workspace!="string")&&ho(A.workspace))}).catch(()=>{}),()=>{T=!0}},[$t]);const Ri=w.useRef(Kn);Ri.current=Kn;const fo=L$(dt),ya=wX(dt,Hs),cc=w.useCallback(()=>{Q("");try{window.localStorage.setItem(c0,"")}catch{}},[]),po=w.useCallback(()=>{if(dt){Q(fo);try{window.localStorage.setItem(c0,fo)}catch{}}},[dt,fo]),[tp,uc]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(bR)??""}catch{return""}}),ht=xe!=null&&xe.invokedAs&&xe.invokedAs!==hn?xe.invokedAs:null,td=ht!=null&&tp!==ht,nd=w.useCallback(()=>{if(ht){uc(ht);try{window.localStorage.setItem(bR,ht)}catch{}}},[ht]),Dn=((qc=xe==null?void 0:xe.upgrade)==null?void 0:qc.state)??"idle",mo=rH(xe==null?void 0:xe.upgrade),Ai=w.useRef(!1),rd=w.useCallback(async()=>{if(Ps(Ai.current||Dn==="running")){Ai.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await gt(),Ai.current=!1}},[Dn,gt]);w.useEffect(()=>{if(Dn!=="running")return;const T=window.setInterval(gt,3e3);return()=>window.clearInterval(T)},[Dn,gt]);const dc=w.useCallback(async()=>{const T=xe==null?void 0:xe.command;!T||!await yi(T)||(Je(!0),window.setTimeout(()=>Je(!1),1600))},[xe==null?void 0:xe.command]),go=w.useCallback(()=>{L(T=>(T||Ie(A=>(A&&(ge.current=!0),!1)),!T))},[]),Vr=w.useCallback(()=>{ge.current=!1,Ie(T=>(T||L(!1),!T))},[]),[Gr,kr]=w.useState(!1),[wa,Ws]=w.useState(!1),[Kr,np]=w.useState(()=>{try{return Number(localStorage.getItem(iR))||0}catch{return 0}}),[hc,yo]=w.useState([]),[fc,pc]=w.useState(!1);w.useEffect(()=>{let T=!0;const A=()=>{fetch("/api/browser-watch?live=0").then(te=>te.ok?te.json():null).then(te=>{var ye;!T||!(te!=null&&te.ok)||(yo(te.episodes??[]),pc(((ye=te.settings)==null?void 0:ye.enabled)===!0))}).catch(()=>{})};A();const Y=setInterval(A,5*6e4);return()=>{T=!1,clearInterval(Y)}},[]);const[Mi,wo]=w.useState([]),sd=w.useRef(new Set),[js,va]=w.useState(null);w.useEffect(()=>{let T=!0,A=0;const Y=()=>{fetch("/api/lan").then(te=>te.ok?te.json():null).then(te=>T?(te!=null&&te.ok&&wo(ej(Array.isArray(te.pending)?te.pending:[],te.aliases)),te):null).catch(()=>null).then(te=>{T&&(A=window.setTimeout(Y,(te==null?void 0:te.enabled)===!0?U0:KM))})};return Y(),()=>{T=!1,window.clearTimeout(A)}},[]);const Vs=w.useCallback(async(T,A)=>{if(!js){va(T);try{const te=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:T,fp:A})})).json().catch(()=>null);te&&Array.isArray(te.pending)?wo(ej(te.pending,te.aliases)):wo(ye=>ye.filter(je=>je.fp!==A))}catch{}finally{va(null)}}},[js]),ur=w.useMemo(()=>TY(hc,Kr).length,[hc,Kr]),[rp,ad]=w.useState(0),Ii=w.useRef(null),[$i,Oi]=w.useState(!1),xa=w.useRef(null),[_s,Li]=w.useState(0),En=w.useState(()=>yY({protect:T=>s6(l.current,T)}))[0],[vo,Pi]=w.useState(!1),ba=w.useCallback(()=>{const T=En.paused&&En.dropped>0,A=En.setPaused(!En.paused);T&&a6(l.current);for(const Y of A)l.current=WN(l.current,Y);Pi(En.paused)},[En]),[Jt,Fn]=w.useState(Date.now()),[qn,ka]=w.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Ih)!=="0"}catch{return!0}}),Na=w.useRef(!1),sp=w.useCallback(()=>{const T=!qn;Na.current=!0;try{window.localStorage.removeItem(Ih)}catch{}ka(T),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:T})}).then(A=>A.ok?A.json():null).then(A=>{var Y;A!=null&&A.ok&&ka(((Y=A.prefs)==null?void 0:Y.autoUpdate)!==!1)}).catch(()=>{})},[qn]),[Nr,Sa]=w.useState(!1),[xo,Di]=w.useState("restart"),[mc,od]=w.useState(null),ja=w.useRef(!1),id=w.useRef(null),Fi=w.useRef(0),bo=w.useCallback(async T=>{if(!Ps(ja.current))return;const A=(T==null?void 0:T.upgrade)===!0;ja.current=!0,id.current=mo;const Y=++Fi.current;Di(A?"npx":"restart"),Sa(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(dt==null?void 0:dt.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:A})})}catch{}window.setTimeout(()=>{if(Fi.current===Y&&ja.current){ja.current=!1,Sa(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},A?18e4:3e4)},[dt==null?void 0:dt.to,mo]),gc=w.useRef(null);w.useEffect(()=>{const T=oj(l.current.agents.values())>0,A=lH({enabled:qn,kind:dt==null?void 0:dt.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ya,visible:document.visibilityState==="visible",busy:T,idleSince:gc.current,now:Jt});gc.current=A.idleSince,A.restart&&bo()},[qn,dt==null?void 0:dt.kind,xe==null?void 0:xe.canRestart,ya,Jt,bo]);const ld=oj(l.current.agents.values()),cd=iH(ld),ud=QM({enabled:qn,kind:dt==null?void 0:dt.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ya,visible:document.visibilityState==="visible",busy:ld>0,idleSince:gc.current,now:Jt});w.useEffect(()=>{const T=xe==null?void 0:xe.running;let A=null,Y=null;try{A=window.sessionStorage.getItem("agent-dag.restartPending"),Y=window.sessionStorage.getItem(kR)}catch{return}const te=nH({bundle:"3.29.10",running:T,pending:A,lastTried:Y});if(te==="reload"){try{window.sessionStorage.setItem(kR,T??"")}catch{return}window.location.reload();return}if(te!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}ja.current=!1,Sa(!1),od(T??null);const ye=window.setTimeout(()=>od(null),6e3);return()=>window.clearTimeout(ye)},[xe==null?void 0:xe.running]),w.useEffect(()=>{if(Nr&&sH({asked:id.current,reported:mo})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}ja.current=!1,Sa(!1)}},[Nr,mo]);const yc=w.useState(()=>FY(KX()))[0],Gt=w.useRef(yc.pinned),qi=w.useRef(null),Bi=w.useState(()=>ZX())[0],[wc,vc]=w.useState(()=>new Set),[_a,dd]=w.useState(xY),[ko,hd]=w.useState(KV),[zi,ap]=w.useState(XV),[No,xc]=w.useState(()=>rG(yr(q2))),[Ui,op]=w.useState(()=>nG(yr(B2))),[Gs,Hi]=w.useState(()=>sG(yr(F2),No,VV)),[Ks,Wi]=w.useState(()=>new Set),[fd,pd]=w.useState(0),[Yr,md]=w.useState(()=>lR(yR)),bc=w.useMemo(()=>PY(Yr),[Yr]),Ea=w.useCallback(T=>LY(T,bc),[bc]),[gd,ip]=w.useState(!1);w.useEffect(()=>{document.documentElement.dataset.theme=_a;try{window.localStorage.setItem(_$,_a)}catch{}md(T=>{const A=lR(yR);return DY(T,A)?T:A})},[_a]),w.useEffect(()=>{try{window.localStorage.setItem(u$,ko?"1":"0")}catch{}},[ko]),w.useEffect(()=>{try{window.localStorage.setItem(d$,String(zi))}catch{}},[zi]),w.useEffect(()=>{try{window.localStorage.setItem(B2,Ui?"1":"0")}catch{}},[Ui]),w.useEffect(()=>{try{window.localStorage.setItem(q2,JSON.stringify(No))}catch{}},[No]),w.useEffect(()=>{try{window.localStorage.setItem(F2,Gs)}catch{}},[Gs]);const lp=w.useCallback(T=>{xc(A=>A.some(Y=>Y.id===T.id)?A:[...A,T]),Wi(A=>{if(!A.has(T.id))return A;const Y=new Set(A);return Y.delete(T.id),Y})},[]),yd=w.useCallback((T,A)=>{const Y=A.trim();!Y||Y.length>Fu||xc(te=>te.map(ye=>ye.id===T?{...ye,name:Y}:ye))},[]),wd=w.useCallback(T=>{xc(A=>A.filter(Y=>Y.id!==T)),Hi(A=>aG(A,T)),Wi(A=>{if(!A.has(T))return A;const Y=new Set(A);return Y.delete(T),Y})},[]),So=w.useCallback(T=>{const A=z2(T),Y=Ks.has(A);T===Gs&&!Y||(Y&&Wi(te=>{const ye=new Set(te);return ye.delete(A),ye}),Hi(T),pd(te=>te+1))},[Gs,Ks]),jo=w.useCallback((T,A)=>{const Y=z2(T);Wi(te=>{if(te.has(Y)===A)return te;const je=new Set(te);return A?je.add(Y):je.delete(Y),je})},[]);w.useEffect(()=>{const T=document.querySelector('meta[name="theme-color"]'),A=Yr["--panel"];T&&A&&T.setAttribute("content",A)},[Yr]);const dr=w.useCallback((T,A)=>{if(Ah({durationMs:A,documentHidden:document.hidden})){e.setViewport(T,{duration:A});return}const{d3Zoom:Y,d3Selection:te}=r.getState(),ye=te==null?void 0:te.property("__zoom");if(Y&&te&&ye&&ye.k>0&&T.zoom>0){Y.transform(te,ye.scale(T.zoom/ye.k).translate((T.x-ye.x)/T.zoom,(T.y-ye.y)/T.zoom));return}e.setViewport(T,{duration:0})},[e,r]),Xr=w.useRef(null),_o=w.useRef(0),Eo=w.useRef(null),Vi=w.useRef(()=>{});w.useEffect(()=>{if(!Bi)return;const T=window.setTimeout(()=>{try{dr(Bi,0)}catch{}Ys.current=Date.now()},60);return()=>window.clearTimeout(T)},[dr,Bi]);const Gi=w.useRef(!0),[Ca,kc]=w.useState(null);w.useEffect(()=>{const T=new EventSource("/events"),A=mY(m,{now:()=>Date.now(),setTimeout:(je,Oe)=>window.setTimeout(je,Oe),clearTimeout:je=>window.clearTimeout(je)});let Y=!1;const te=typeof BroadcastChannel=="function"?SY(new BroadcastChannel(kY),Math.random().toString(36).slice(2),()=>Y):null,ye=window.setInterval(()=>{Y||!te||te.ask(600).then(je=>{Y||Ur(NY(je))})},3e3);return T.addEventListener("open",()=>{Zt(!0),ip(!0)}),T.addEventListener("error",()=>{Zt(!1),kc(null)}),T.addEventListener("open",()=>{Y=!0,Ur(!1)}),T.addEventListener("error",()=>{Y=!1}),T.addEventListener("replay-end",()=>{Gi.current=!1,A.flush(),kc(Date.now())}),T.addEventListener("desktop-update",je=>{if(pu())try{const Oe=sR(JSON.parse(je.data));Oe&&(Ct.current++,Hr(Oe),Oe.status!=="ready"&&(lr.current++,window.clearTimeout(br.current),St.current=!1,Ss(!1)))}catch{}}),T.addEventListener("hook",je=>{var Oe;try{const Be=JSON.parse(je.data);if(!En.accept(Be))return;l.current=WN(l.current,Be);const lt=Be.replay===!0||Gi.current||Date.now()-Be.receivedAt>3e4;lt?A.replay():A.live();const et=LV(Be,lt);et&&((Oe=Ut.current)==null||Oe.play(et))}catch{}}),()=>{T.close(),A.cancel(),window.clearInterval(ye),te==null||te.leave()}},[m]),w.useEffect(()=>{const T=setInterval(()=>{const A=Date.now();Fn(A);const{changed:Y,forgotten:te}=V9(l.current,A);te.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:te})}).catch(()=>{}),b(ye=>U9(ye,l.current.agents)),k(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),B(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),$(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),Y&&m()},250);return()=>clearInterval(T)},[m]);const Ki=w.useRef(null),Ys=w.useRef(0),vd=420,Yn=w.useCallback((T=500)=>{const A=o0,Y=1,te=.2,ye=i0;try{const je=document.querySelector(".canvas-wrap"),Oe=Array.from(document.querySelectorAll(".react-flow__node")).filter(Lt=>Lt.offsetWidth>0);if(!je||Oe.length===0)return;const Be=je.getBoundingClientRect(),lt=e.getViewport();if(!Number.isFinite(lt.zoom)||lt.zoom<=0)return;const et=Lt=>(Lt-Be.left-lt.x)/lt.zoom,xt=Lt=>(Lt-Be.top-lt.y)/lt.zoom,ft=Oe.map(Lt=>Lt.getBoundingClientRect()),An=Math.min(...ft.map(Lt=>et(Lt.left))),sa=Math.max(...ft.map(Lt=>et(Lt.right))),Yo=Math.min(...ft.map(Lt=>xt(Lt.top))),as=Math.max(...ft.map(Lt=>xt(Lt.bottom))),os=sa-An,Da=as-Yo;if(!(os>0&&Da>0))return;const Td=wR(je),Xo=Lt=>Math.max(te,Math.min(Y,(Be.width-Td-A*2)/(os+Lt)*ye,(Be.height-A*2)/Da*ye)),Fa=eX(Xo(vd),Xo(0)),is={x:A-An*Fa,y:Math.max(A,(Be.height-Da*Fa)/2)-Yo*Fa,zoom:Fa},Rr=++_o.current;dr(is,T),Ys.current=Date.now(),Xr.current=Ah({durationMs:T,documentHidden:document.hidden})?{target:is,until:Date.now()+T+60}:null,window.setTimeout(()=>{var Lt;try{if(((Lt=Xr.current)==null?void 0:Lt.target)===is&&(Xr.current=null),_o.current!==Rr)return;const qa=e.getViewport();(Math.abs(qa.zoom-Fa)>.01||Math.abs(qa.x-is.x)>2)&&dr(is,0)}catch{}},T+60)}catch{}},[e,dr]);w.useEffect(()=>{const T=()=>{if(!document.hidden)return;const A=Xr.current;if(Xr.current=null,!(!A||Date.now()>A.until)){try{dr(A.target,0)}catch{}Ys.current=Date.now()}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[dr]);const Nc=w.useRef(""),Sc=w.useRef(null),Xn=w.useRef(0),Es=w.useCallback(()=>{Xn.current=Date.now()},[]),Yi=w.useRef(null),jc=w.useRef(0),Xi=w.useCallback(()=>{jc.current=Date.now()},[]),Zi=w.useCallback(T=>({hasSourceEvent:!!T,at:Date.now(),lastDeckFitAt:Ys.current,lastCanvasInputAt:jc.current}),[]),_c="agent-dag.autoFitDisabled",Xs=w.useRef(!1),[Ec,Zs]=w.useState(!1);w.useEffect(()=>{try{window.localStorage.removeItem(_c)}catch{}},[]);const Qs=w.useCallback(()=>{Xs.current||(Xs.current=!0,Zs(!0))},[]),Ta=w.useCallback(()=>{Xs.current=!1,Zs(!1),Yn(400)},[e,Yn]);w.useEffect(()=>{const T=setInterval(()=>{if(Xs.current||Date.now()-Xn.current<800)return;const A=l.current,Y=Date.now(),te=[];for(const je of A.agents.values())eb(je,Y)&&te.push({id:je.id});if(te.length===0)return;const ye=[];for(const{id:je}of te){const Oe=Sr.current.get(je),Be=Gt.current.get(je)??Kt.current.get(je);!Oe||!Be||ye.push({x:Be.x,y:Be.y,width:Oe.width,height:Oe.height})}KY({pane:Yi.current,viewport:e.getViewport(),boxes:ye})&&Yn(600)},1500);return()=>clearInterval(T)},[e]);const Ra=w.useRef(!1),Sr=w.useRef(new Map),Aa=w.useRef(0),Ma=w.useCallback(T=>{const A=Sr.current;let Y=!1;for(const te of T.nodeInternals.values()){const ye=te.width,je=te.height;if(ye==null||je==null)continue;const Oe=A.get(te.id);Oe?(Math.abs(Oe.height-je)>4||Math.abs(Oe.width-ye)>4)&&(A.set(te.id,{width:ye,height:je}),Y=!0):(A.set(te.id,{width:ye,height:je}),Y=!0)}return Y&&(Aa.current+=1),Aa.current},[]),Qi=Et(Ma),[Cc,Ji]=w.useState(0);w.useEffect(()=>{let T=0;const A=()=>{const te=Sr.current;let ye=!1;for(const je of document.querySelectorAll(".react-flow__node[data-id]")){const Oe=je.getAttribute("data-id");if(!Oe)continue;const Be=je.offsetWidth,lt=je.offsetHeight;if(!Be||!lt)continue;const et=te.get(Oe);(!et||Math.abs(et.width-Be)>4||Math.abs(et.height-lt)>4)&&(te.set(Oe,{width:Be,height:lt}),ye=!0)}ye&&Ji(je=>je+1)};if(Ra.current)return;let Y=0;return document.visibilityState==="hidden"?Y=window.setTimeout(A,32):T=requestAnimationFrame(A),()=>{cancelAnimationFrame(T),window.clearTimeout(Y)}});const Kt=w.useRef(yc.positions),Tc=w.useRef(new Set),Co=w.useRef(""),hr=w.useMemo(()=>QK(l.current.agents.values(),c),[l.current,l.current.revision,c]),Js=w.useMemo(()=>{const T=[];for(const A of l.current.agents.values())!eb(A,Jt)||hr.has(A.id)||T.push(A.id+(A.parentId?`>${A.parentId}`:""));return T.sort(),`${T.join("|")}#sv${Qi}.${Cc}`},[l.current,l.current.revision,Jt,Qi,Cc,hr]),Ia=w.useRef(null);w.useEffect(()=>(Ia.current!=null&&window.clearTimeout(Ia.current),Ia.current=window.setTimeout(()=>{$h(Kt.current,Gt.current)},1500),()=>{Ia.current!=null&&window.clearTimeout(Ia.current)}),[Js]),w.useEffect(()=>{if(Nc.current===Js)return;const T=Nc.current;if(Nc.current=Js,!T||Xs.current)return;Date.now()-Ys.current>1200&&Yn(400),Ki.current&&window.clearTimeout(Ki.current),Ki.current=window.setTimeout(()=>{Xs.current||Yn(500)},280)},[Js,e,Yn]);const jr=w.useMemo(()=>hY(l.current,S),[l.current,l.current.revision,S]),To=w.useMemo(()=>{const T=IY(l.current,Jt);for(const A of hr)T.delete(A);return T},[l.current,l.current.revision,Jt,hr]),_r=w.useRef(null),[Ro,xd]=w.useState({w:0,h:0});w.useEffect(()=>{const T=_r.current;if(!T||typeof ResizeObserver>"u")return;const A=new ResizeObserver(Y=>{var ye;const te=(ye=Y[0])==null?void 0:ye.contentRect;te&&(Yi.current={width:te.width,height:te.height},xd(je=>Math.abs(je.w-te.width)>40||Math.abs(je.h-te.height)>40?{w:te.width,h:te.height}:je))});return A.observe(T),Yi.current={width:T.clientWidth,height:T.clientHeight},xd({w:T.clientWidth,h:T.clientHeight}),()=>A.disconnect()},[]);const Ao=w.useCallback(T=>{var Y,te;const A=T.target;!(A!=null&&A.closest)||A.closest(PX)!==T.currentTarget||(T.preventDefault(),(te=(Y=document.activeElement)==null?void 0:Y.blur)==null||te.call(Y))},[]),cp=w.useRef(new Map),[Mo,bd]=w.useState(!1);w.useEffect(()=>{const T=window.setTimeout(()=>bd(!0),2500);return()=>window.clearTimeout(T)},[]);const[Mt,Io]=w.useState(!1),fr=w.useRef(null),[Zr,Rc]=w.useState(!1),[el,$a]=w.useState(!1),[tl,Oa]=w.useState(""),[$o,kd]=w.useState("far"),Nd=w.useRef(null),Ac=wh(el,140),Oo=w.useCallback(T=>{var te;const A=(te=Nd.current)==null?void 0:te.getBoundingClientRect(),Y=uY(T);return A&&Y?cY(Y,A):"far"},[]),[nl,Mc]=w.useState("detail"),Qr=w.useRef(null),Lo=w.useRef(null),Ic=w.useCallback(()=>{var te;const T=Aa.current;if(((te=Lo.current)==null?void 0:te.version)===T)return Lo.current.card;const A=[];for(const ye of l.current.agents.keys()){const je=Sr.current.get(ye);je&&A.push(je)}const Y=XY(A);return Lo.current={version:T,card:Y},Y},[]),up=w.useCallback(()=>{fr.current&&(window.clearTimeout(fr.current),fr.current=null),Io(!1)},[]),Sd=w.useCallback(T=>{T.length!==0&&queueMicrotask(()=>{Io(!0),fr.current&&window.clearTimeout(fr.current),fr.current=window.setTimeout(()=>Io(!1),DX+80)})},[]);w.useEffect(()=>()=>{fr.current&&window.clearTimeout(fr.current)},[]);const Cn=_?l.current.agents.get(_):null,jd=y&&Cn!=null,[Po,Cs]=w.useState(0);w.useEffect(()=>{const T=wR(_r.current);Cs(A=>Math.abs(A-T)>40?T:A)},[ze,Pe,H,jd,Ro.w]);const rl=w.useRef(Po);rl.current=Po;const Jr=Ro.w>0?Math.max(0,(Ro.w-Po-o0*2)*i0):0,Bn=Ro.h>0?Math.max(0,(Ro.h-o0*2)*i0):0,Do=mF(),{nodes:gn,edges:sl}=w.useMemo(()=>{const T=X9(l.current,Jt,Jr,Bn,Gt.current,Sr.current,cp.current,Sd,Mo,Zr,Kt.current,Tc.current,Js,Co,S,jr,To,P);return JK(T.nodes,T.edges,c)},[l.current,l.current.revision,Jt,Jr,Bn,Mo,Zr,Js,S,jr,To,P,rp,Do,c]),dp=w.useState(YX)[0],_d=w.useRef(dp);w.useEffect(()=>{if(!Mo||Zr)return;const T={width:Jr,height:Bn};if(!(T.width>0&&T.height>0))return;const A=_d.current;if(_d.current=T,XX(T),!A||A.width===T.width&&A.height===T.height)return;const Y={direction:"LR",pinned:Gt.current,measured:Sr.current,lanes:W0(l.current)};if(!A9(gn,sl,Y,A,T))return;const te=Eo.current&&Date.now()-Eo.current.at<1500?Eo.current.id:null,ye=te??As.current,je=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;for(const Oe of Array.from(Kt.current.keys()))Gt.current.has(Oe)||Kt.current.delete(Oe);Tc.current.clear(),Co.current="",m(),window.setTimeout(()=>{if($h(Kt.current,Gt.current),Xs.current){if(te){Vi.current(te);return}const Oe=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;if(je&&Oe&&(Oe.x!==je.x||Oe.y!==je.y)){const Be=e.getViewport();_o.current+=1,dr({x:Be.x-(Oe.x-je.x)*Be.zoom,y:Be.y-(Oe.y-je.y)*Be.zoom,zoom:Be.zoom},0),Ys.current=Date.now()}return}Yn(500)},80)},[Jr,Bn,Mo,Zr,m,Yn,e,dr]);const Ts=w.useMemo(()=>{const T=new Map;for(const Y of gn){const te=Y.data;if(!(te!=null&&te.sessionId)||te.exitAt!=null)continue;const ye=Y.width,je=Y.height;if(ye==null||je==null)continue;const Oe=Y.position.x,Be=Y.position.y,lt=Oe+ye,et=Be+je,xt=T.get(te.sessionId);xt?(xt.minX=Math.min(xt.minX,Oe),xt.minY=Math.min(xt.minY,Be),xt.maxX=Math.max(xt.maxX,lt),xt.maxY=Math.max(xt.maxY,et)):T.set(te.sessionId,{minX:Oe,minY:Be,maxX:lt,maxY:et})}const A=[];for(const[Y,te]of T){const ye=te.maxX-te.minX+Mh*2,je=te.maxY-te.minY+Mh*2;A.push({id:`group:${Y}`,type:E$,position:{x:te.minX-Mh,y:te.minY-Mh},data:{sessionId:Y,w:ye,h:je},width:ye,height:je,style:{width:ye,height:je},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return A},[gn]),Fo=w.useMemo(()=>{const T=[...Ts,...gn],A=xa.current;return!A||A.size===0?T:T.map(Y=>{const te=A.get(Y.id);return te?{...Y,position:te}:Y})},[Ts,gn,_s]),es=w.useMemo(()=>{const T=new Set;for(const A of l.current.agents.values())for(const Y of A.tools)T.add(H$(Y.name));return Object.keys(U$).filter(A=>T.has(A))},[l.current,l.current.revision]);w.useEffect(()=>{if(es.length<=1){Oi(!1);return}let T=0;const A=()=>{const Y=Ii.current;if(Y&&!document.hidden){const te=Y.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Oe=>Oe.getBoundingClientRect()),je=OY(te,ye,8);Oi(Oe=>Oe===je?Oe:je)}T=window.setTimeout(A,300)};return A(),()=>window.clearTimeout(T)},[es.length]);const al=w.useCallback(T=>{vc(A=>{const Y=new Set(A);return Y.has(T)?Y.delete(T):Y.add(T),Y})},[]),qo=j?X5(l.current.agents,j):null,ea=w.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=E0(),Gt.current.clear(),Sr.current.clear(),Kt.current.clear(),Co.current="",NR(),u(new Set),p(null);try{window.localStorage.removeItem(fk)}catch{}R(),m()},[m,R]),Er=w.useCallback(T=>{const A=l.current.agents.get(T);A&&(u(Y=>{const te=new Set(Y);return te.add(T),aR(window.localStorage,te),te}),p({id:T,label:A.label}),Gt.current.delete(T),Kt.current.delete(T),R())},[R]),Tt=w.useCallback(()=>{_&&Er(_)},[_,Er]),Rt=f&&c.has(f.id)?f:null;w.useEffect(()=>{var T;f&&((T=_r.current)==null||T.focus())},[f]);const Zn=w.useCallback(T=>{const A=[...T];u(Y=>{const te=eY(Y,A);return te!==Y&&aR(window.localStorage,te),te})},[]),an=w.useRef(W);an.current=W;const kn=w.useRef(ee);kn.current=ee;const ts=w.useRef(!1);ts.current=qo!=null||Gr||q!=null||X||I!=null||wa||ee||cr!=null;const ns=w.useCallback(T=>{const A=tV(T,{confirmOpen:an.current,modalOpen:ts.current});A==="confirm"?ne(!0):A==="clear"&&(ne(!1),ea())},[ea]),yn=w.useCallback(()=>{Gt.current.clear(),Kt.current.clear(),Co.current="",NR(),m(),window.setTimeout(()=>Yn(500),80)},[m,e,Yn]),Bo=w.useCallback(()=>Yn(500),[Yn]),Rs=w.useRef(gn);Rs.current=gn;const zn=w.useCallback(T=>{var xt;const A=_r.current,Y=l.current.agents.get(T);if(!A||!Y)return;const te=W0(l.current),ye=(ft,An)=>{const sa=Sr.current.get(ft.id);if(!sa)return null;const Yo=An&&te.has(ft.id)?vd:0;return{x:ft.position.x,y:ft.position.y,width:sa.width+Yo,height:sa.height}},je=Rs.current.find(ft=>ft.id===T),Oe=je?ye(je,!1):null;if(!Oe)return;const Be=[];for(const ft of Rs.current){if(ft.type!=="agent"&&ft.type!=="recapNote"||((xt=ft.data)==null?void 0:xt.sessionId)!==Y.sessionId)continue;const An=ye(ft,ft.type==="agent");An&&Be.push(An)}const lt=A.getBoundingClientRect(),et=rX({pane:{width:lt.width,height:lt.height},insets:{top:56,left:72,bottom:32,right:rl.current+32},context:sX(Be)??Oe,anchor:Oe});Za(),Qs(),Eo.current={id:T,at:Date.now()},_o.current+=1,dr(et,l0),Ys.current=Date.now(),Xr.current=Ah({durationMs:l0,documentHidden:document.hidden})?{target:et,until:Date.now()+l0+60}:null},[dr,Qs]);Vi.current=zn;const ol=w.useCallback(T=>{const A=Rs.current.find(Y=>Y.id===T&&Y.type==="agent");return A?A.data:void 0},[]),Ed=w.useCallback(T=>{var A;return(A=l.current.agents.get(T))==null?void 0:A.label},[]),rs=w.useCallback(T=>{var te;const A=Rs.current.find(ye=>ye.id===T&&ye.type==="recapNote");if(!A)return;const Y=A.data;return{recap:Y.recap,hue:Y.hue,sessionLabel:(te=l.current.agents.get(Y.parentId))==null?void 0:te.label}},[]),il=w.useCallback(()=>{var Y;const T=(Y=_r.current)==null?void 0:Y.getBoundingClientRect(),A=document.documentElement;return T?{width:T.right-rl.current,height:T.bottom}:{width:A.clientWidth,height:A.clientHeight}},[]),As=w.useRef(_);As.current=_;const $c=w.useRef(Tt);$c.current=Tt;const ll=w.useCallback(T=>{const A=Rs.current.filter(je=>je.type==="agent"),Y=VK(A.map(je=>({id:je.id,x:je.position.x,y:je.position.y})),As.current,T),te=Y?A.find(je=>je.id===Y):void 0;if(!te)return;const ye=a0(document.activeElement);C(te.id,!1),window.setTimeout(()=>{try{zn(te.id)}catch{}ye&&LX(te.id)},30)},[C,zn]),Cr=w.useRef(null),Qn=w.useCallback(T=>{C(T,!1),window.setTimeout(()=>{try{zn(T)}catch{}},60)},[C,zn]),La=w.useCallback(T=>{hr.has(T)&&Zn([T]),Qn(T)},[hr,Zn,Qn]),zo=w.useRef(null);w.useEffect(()=>{let T=-1/0;const A=()=>{T=performance.now()},Y=te=>{zo.current=performance.now()-T<250?te.target:null};return window.addEventListener("pointerdown",A,!0),window.addEventListener("focusin",Y,!0),()=>{window.removeEventListener("pointerdown",A,!0),window.removeEventListener("focusin",Y,!0)}},[]),w.useEffect(()=>{const T=A=>{var Be,lt;const Y=A.target,te={tagName:Y==null?void 0:Y.tagName,isContentEditable:Y==null?void 0:Y.isContentEditable,role:(Be=Y==null?void 0:Y.getAttribute)==null?void 0:Be.call(Y,"role"),type:Y==null?void 0:Y.type,pointerFocused:Y!=null&&Y===zo.current};if(A.key==="Escape"){const et=F6({overlayOpen:gu.depth()>0,typing:Ef(te)});et==="dismiss"?gu.dismissTop():et==="blur"?Y==null||Y.blur():(XK(te)&&(Y==null||Y.blur()),R());return}if(_f(A))return;const ye=a0(Y)?(lt=Y==null?void 0:Y.getAttribute)==null?void 0:lt.call(Y,"data-id"):null,je=ye&&Rs.current.some(et=>et.id===ye)?ye:null,Oe=KK(A,je);if(Oe.kind==="activate"){A.preventDefault(),C(Oe.nodeId,Oe.additive);return}if(Oe.kind!=="node"&&!(Oe.nodeId==null&&K6(te,A.key))&&!Y6({key:A.key,modalOpen:X6({appModal:ts.current,dialogDepth:gu.dialogDepth()}),sheetOpen:kn.current})){if(A.key===" "&&(A.preventDefault(),ba()),(A.key==="c"||A.key==="C")&&ns("shortcut"),(A.key==="r"||A.key==="R")&&yn(),(A.key==="f"||A.key==="F")&&Bo(),(A.key==="z"||A.key==="Z")&&As.current&&zn(As.current),A.key==="Delete"&&$c.current(),(A.key==="l"||A.key==="L")&&go(),A.key==="d"||A.key==="D")if(As.current)v(et=>!et);else{const et=km(l.current.agents.values());et.length>0?Qn(et[0].id):ll(1)}if((A.key==="h"||A.key==="H")&&kr(et=>!et),(A.key==="u"||A.key==="U")&&D(et=>!et),(A.key==="a"||A.key==="A")&&Ri.current.claude&&Vr(),(A.key==="j"||A.key==="J")&&ll(1),(A.key==="k"||A.key==="K")&&ll(-1),A.key==="w"||A.key==="W"){const et=C6(km(l.current.agents.values()),Cr.current);et&&(Cr.current=et.id,Qn(et.id))}(A.key==="t"||A.key==="T")&&dd(et=>et==="dark"?"light":"dark"),(A.key==="m"||A.key==="M")&&Ri.current.claude&&be.current!==null&&se.current(A.shiftKey),(A.key==="s"||A.key==="S")&&le(et=>!et),(A.key==="b"||A.key==="B")&&Ws(et=>!et),(A.key==="v"||A.key==="V")&&Ri.current.claude&&be.current!==null&&rn(et=>!et),A.key==="?"&&M(et=>!et)}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[ns,yn,Bo,R,C,ll,Qn,zn,ba]);const Uo=l.current.agents.size,_t=w.useMemo(()=>km(l.current.agents.values()),[l.current,l.current.revision]),Tn=w.useRef(new Map);w.useEffect(()=>{Tn.current=rY(Tn.current,c,Date.now());const T=[...tY(_t,hr),...sY(l.current.agents,hr,c,Tn.current)];T.length>0&&Zn(T)},[_t,hr,c,Zn]);const Ms=w.useMemo(()=>T6(l.current.agents.values()),[l.current,l.current.revision]),Tr=w.useRef(null);w.useEffect(()=>{const T=jY({waiting:_t.length,running:Ms,connected:$t}),A=Tr.current;if(Tr.current=T,(A==null?void 0:A.title)!==T.title&&(document.title=T.title),(A==null?void 0:A.icon)!==T.icon){const Y=document.querySelector('link[rel="icon"]');Y&&(Y.href=_Y[T.icon])}},[_t.length,Ms,$t]);const[ss,ta]=w.useState(""),Oc=CY(_t);w.useEffect(()=>{ta(T=>oR(T,Oc))},[Oc]);const[Lc,cl]=w.useState(""),Rn=ur>0?`Browser watch has ${ur} unread ${ur===1?"finding":"findings"}.`:"";w.useEffect(()=>{cl(T=>oR(T,Rn,"Browser watch has no unread findings."))},[Rn]);const[wn,Ot]=w.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[on,ul]=w.useState(null),[Ho,Wo]=w.useState(!1),[Pc,Dc]=w.useState(!1);w.useEffect(()=>{let T=!0;return fetch("/api/prefs").then(A=>A.ok?A.json():null).then(A=>{var Y,te,ye;if(!(!T||!(A!=null&&A.ok))){if(!Na.current){let je=!1;try{je=window.localStorage.getItem(Ih)==="0",window.localStorage.removeItem(Ih)}catch{}je&&((Y=A.prefs)==null?void 0:Y.autoUpdate)!==!1?(ka(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):ka(((te=A.prefs)==null?void 0:te.autoUpdate)!==!1)}Wo(((ye=A.prefs)==null?void 0:ye.notifications)===!0),Dc(A.notificationsVetoed===!0)}}).catch(()=>{}),()=>{T=!1}},[]);const Vo=w.useRef(()=>{}),Cd=w.useCallback(()=>{const T=!Ho;Wo(T),T&&typeof Notification<"u"&&Notification.permission==="default"&&Vo.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:T})}).then(A=>A.ok?A.json():null).then(A=>{var Y;A!=null&&A.ok&&(Wo(((Y=A.prefs)==null?void 0:Y.notifications)===!0),Dc(A.notificationsVetoed===!0))}).catch(()=>{})},[Ho]),Pa=typeof Notification<"u";w.useEffect(()=>{if(!on)return;const A=setTimeout(()=>ul(null),on==="blocked"?8e3:4e3);return()=>clearTimeout(A)},[on]);const dl=w.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(T=>{const A=T;Ot(A),A==="granted"?ul("on"):A==="denied"&&ul("blocked")})},[]);Vo.current=dl;const Go=w.useRef(new Set),na=w.useRef(null),hl=_t.map(T=>jf(T.id,T.waiting)).join("|");w.useEffect(()=>{I6(na.current,wn)&&(na.current=wn,Go.current=Nm(_t))},[wn]);const Fc=w.useRef(!1);return w.useEffect(()=>{$6(Fc.current,Ca)&&(Fc.current=!0,Go.current=Nm(_t))},[Ca]),w.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!O6(na.current,Ca))return;const T=typeof document>"u"||!document.hidden,A=A6(_t,Go.current,T,Ho);for(const Y of A)try{const te=new Notification(Y.title,{body:Y.body,tag:Y.key});te.onclick=()=>{window.focus(),Qn(Y.sessionId),te.close()}}catch{}Go.current=T?Nm(_t):M6(_t,A,Go.current)},[hl,Ca]),o.jsxs("div",{className:"app",children:[o.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),o.jsxs("header",{className:"topbar",children:[o.jsxs("div",{className:"readout",children:[o.jsxs("div",{className:"brand",children:[o.jsx("span",{className:"logo"}),o.jsx("h1",{children:hn}),Qt?(()=>{const T=BK(FK()??uo,Qt.version);return o.jsxs("button",{type:"button",className:"v ready",onClick:ga,"aria-haspopup":"dialog","aria-label":T.label,title:T.title,children:[T.text,o.jsx("span",{className:"v-dot","aria-hidden":!0})]})})():dt?o.jsxs("button",{type:"button",className:"v stale",onClick:()=>{ga(),cc()},"aria-haspopup":"dialog","aria-label":yX({...dt,open:ya}),title:dt.kind==="restart"?`Running v${dt.from}; v${dt.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${dt.from}; v${dt.to} is on npm · click for what's new`,children:["v",dt.from,o.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const T={running:uo,latest:xe==null?void 0:xe.latest,latestPending:xe==null?void 0:xe.latestPending,checkedAgo:xe!=null&&xe.checkedAt?qh(Jt-xe.checkedAt):null,checkFailedAgo:xe!=null&&xe.checkFailedAt&&xe.checkFailedAt>(xe.checkedAt??0)?qh(Jt-xe.checkFailedAt):null,checkDisabled:xe==null?void 0:xe.checkDisabled,checking:tt};return o.jsxs("button",{type:"button",className:tt?"v checking":"v",onClick:()=>{ga(),gt(!0)},"aria-busy":tt||void 0,"aria-haspopup":"dialog","aria-label":gX(T),title:mX(T),children:["v",T.running]})})()]}),o.jsxs("span",{className:"status",children:[(()=>{const T=AX({connected:$t,paused:vo,held:En.size,dropped:En.dropped});return T.resting?null:o.jsx("span",{className:`pill ${T.tone}`,title:T.title,children:o.jsxs("span",{className:"pill-box",children:[o.jsx("span",{className:"pill-widest","aria-hidden":!0,children:T.widest}),o.jsx("span",{className:"pill-label",children:T.label})]})})})(),o.jsxs("span",{ref:U,className:"month-usage",title:K?`${K.tokens.toLocaleString()} tokens · ${pR(K.cost)} spent since the 1st of this local calendar month`:z?"Monthly usage is unavailable — ccusage could not be read":"Loading usage since the 1st of this local calendar month",children:[o.jsx("span",{className:"month-usage-label",children:"this month"}),K?o.jsxs(o.Fragment,{children:[o.jsx("b",{children:Pt(K.tokens)}),o.jsx("span",{className:"month-usage-unit",children:"tokens"}),o.jsx("span",{className:"month-usage-sep","aria-hidden":!0,children:"·"}),o.jsx("b",{children:pR(K.cost)})]}):o.jsx("span",{className:"month-usage-pending",children:z?"unavailable":"…"})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:ss}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Lc}),_t.length>0&&o.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{Cr.current=_t[0].id,Qn(_t[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
290
+ Click to set the volume and the sound of each tone, and to hear either one.`}function pf(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const gR=99;function _X(e){const t=Math.max(0,Math.floor(e));return t>gR?`${gR}+`:String(t)}const EX="Pause the canvas";function CX(e){if(!e.paused)return"Pause live updates — events keep arriving and are applied when you resume (Space)";const t=Math.max(0,Math.floor(e.dropped??0));return t>0?`The pause is full — ${pf(e.held)} held and ${t} older ${t===1?"one":"ones"} already dropped. Resume to follow the canvas again (Space)`:e.held<=0?"Nothing has arrived since you paused. Resume to follow the canvas again (Space)":`${pf(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function TX(e){return e.connected||!e.paused?null:"The canvas is paused as well — Space resumes it, but nothing new arrives until the stream is back."}const P$="paused · full",RX=(e,t)=>t>0?P$:e>0?`paused · ${_X(e)}`:"paused";function AX(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:RX(e.held,t),widest:P$,title:t>0?`Connected — the pause is full at ${pf(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${pf(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",resting:!0,label:"live",widest:"live",title:"Receiving events"}:{tone:"dead",resting:!1,label:"offline",widest:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}const MX=w.lazy(()=>ab(()=>import("./UsageHistoryModal-KJfli0oa.js"),[])),IX=w.lazy(()=>ab(()=>import("./BrowserWatchModal-CyAFTvAY.js"),[]));function yR(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const $X={agent:nq,sessionGroup:$q,recapNote:Lq},OX={recapTie:Pq},D$="react-flow__node";function a0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,D$))===!0}const o0=80,i0=.86;function wR(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const r of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const s=r.getBoundingClientRect();s.width>0&&s.left>t.left&&(n=Math.min(n,s.left))}return Math.max(0,t.right-n)}function LX(e){try{const t=document.querySelector(`.${D$}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const PX=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),DX=420,Mh=18,vR=400,l0=450,mk="agent-dag.layout",gk="agent-dag.layoutFrame",yk="agent-dag.viewport",F$="agent-dag.sessionListOpen",q$="agent-dag.detailOpen",B$="agent-dag.usagePanelOpen",z$="agent-dag.systemPanelOpen",xR="agent-dag.accountsPanelOpen",c0="agent-dag.versionNoticeDismissed",bR="agent-dag.oldNameNoticeDismissed",FX=15*6e4,u0={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:",retired_name:"this install came from a name that is no longer published — run:"},Ih="agent-dag.autoRestart",kR="agent-dag.bundleReloadedFor";function qX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(F$)==="1"}catch{return!1}}function BX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(F$,e?"1":"0")}catch{}}function zX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(q$)==="1"}catch{return!1}}function UX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(q$,e?"1":"0")}catch{}}function HX(){const e=yr(B$);return e===null?!0:e==="1"}function WX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(B$,e?"1":"0")}catch{}}function VX(){const e=yr(z$);return e===null?!0:e==="1"}function GX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(z$,e?"1":"0")}catch{}}function KX(){if(typeof window>"u")return{positions:[],pins:[]};try{return qY(window.localStorage.getItem(mk))}catch{return{positions:[],pins:[]}}}function $h(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(mk,BY(e,t))}catch{}}function YX(){if(typeof window>"u")return null;try{return zY(window.localStorage.getItem(gk))}catch{return null}}function XX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(gk,JSON.stringify(e))}catch{}}function ZX(){if(typeof window>"u")return null;try{return UY(window.localStorage.getItem(yk))}catch{return null}}function QX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(yk,JSON.stringify(e))}catch{}}function NR(){if(!(typeof window>"u")){try{window.localStorage.removeItem(mk)}catch{}try{window.localStorage.removeItem(yk)}catch{}try{window.localStorage.removeItem(gk)}catch{}}}function JX(e,t){const n=J9(e,t,new Date().toISOString());if(!n)return;const r=JSON.stringify(n,null,2),s=new Blob([r],{type:"application/json"}),l=URL.createObjectURL(s),c=document.createElement("a");c.href=l,c.download=eV(n.label,t),document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(l),1e3)}const U$={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},eZ={file:"M3.4 1.8h4.5l2.7 2.7v7.7H3.4z M7.9 1.8v2.7h2.7",shell:"M2.4 3.8 5.6 7l-3.2 3.2 M7.4 10.6h4.2",web:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M1.8 7h10.4 M7 1.8c-1.5 1.4-2.3 3.1-2.3 5.2s.8 3.8 2.3 5.2c1.5-1.4 2.3-3.1 2.3-5.2S8.5 3.2 7 1.8z",agent:"M3.3 4.8h7.4a1.2 1.2 0 0 1 1.2 1.2v4.8a1.2 1.2 0 0 1-1.2 1.2H3.3a1.2 1.2 0 0 1-1.2-1.2V6a1.2 1.2 0 0 1 1.2-1.2z M7 4.8V2.4 M5.3 8.2h.01 M8.7 8.2h.01",task:"M2.2 4l1.2 1.2 2-2.2 M7.4 4.2h4.4 M2.2 9.4l1.2 1.2 2-2.2 M7.4 9.6h4.4",plan:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M9 5 8 8 5 9l1-3z",mcp:"M5 1.8v2.6 M9 1.8v2.6 M3.6 4.4h6.8v2.2a3.4 3.4 0 0 1-6.8 0z M7 10v2.2",other:"M3.5 7h.01 M7 7h.01 M10.5 7h.01"};function tZ({cat:e}){return o.jsx("svg",{className:"cat-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:eZ[e]})})}const mf={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},H$=gM;function nZ(){return o.jsx(Nb,{children:o.jsx(aZ,{})})}const rZ=e=>e.transform[2]>=e.maxZoom,sZ=e=>e.transform[2]<=e.minZoom;function aZ(){var qc,ra,Bc,Ko;const e=Nf(),t=Et(rZ),n=Et(sZ),r=tn(),s=w.useState(E0)[0],l=w.useRef(s),[c,u]=w.useState(()=>ZK(typeof window>"u"?null:window.localStorage)),[f,p]=w.useState(null),[,h]=w.useState(0),m=w.useCallback(()=>h(T=>T+1),[]),[y,v]=w.useState(zX);w.useEffect(()=>{UX(y)},[y]);const[S,b]=w.useState(()=>new Set),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useCallback((T,A,Y=!A)=>{b(te=>{if(!A)return new Set([T]);const ye=new Set(te);return ye.has(T)?ye.delete(T):ye.add(T),ye}),k(te=>A&&te===T?te:T),!A&&Y&&v(!0)},[]),R=w.useCallback(()=>{b(new Set),k(null)},[]),[I,$]=w.useState(null),[q,B]=w.useState(null),P=w.useCallback(T=>B(T),[]),[W,ne]=w.useState(!1),[ee,M]=w.useState(!1),[X,V]=w.useState(!1),G=w.useRef(null),[F,L]=w.useState(qX);w.useEffect(()=>{BX(F)},[F]);const[H,D]=w.useState(HX);w.useEffect(()=>{WX(H)},[H]);const[K,re]=w.useState(null),[z,Z]=w.useState(!1),U=w.useRef(null);w.useEffect(()=>{let T=!0,A=!1,Y=null,te=null,ye="";const je=xt=>{T&&(Z(!0),xt!==ye&&re(null))},Oe=()=>{if(A)return;A=!0,Y=Date.now();const xt=fR();te=xt,fetch(`/api/ccusage?since=${xt}`).then(ft=>ft.ok?ft.json():null).then(ft=>{if(T){if(!(ft!=null&&ft.ok)){je(xt);return}ye=xt,re(fX(ft)),Z(!1)}}).catch(()=>je(xt)).finally(()=>{A=!1})},Be=()=>{const xt=U.current;hX({shown:!!xt&&xt.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:te,since:fR(),lastReadAt:Y,now:Date.now()})&&Oe()};Be();const lt=window.setInterval(Be,dX);document.addEventListener("visibilitychange",Be);let et=null;return U.current&&typeof ResizeObserver<"u"&&(et=new ResizeObserver(Be),et.observe(U.current)),()=>{T=!1,window.clearInterval(lt),document.removeEventListener("visibilitychange",Be),et==null||et.disconnect()}},[]);const[ae,le]=w.useState(VX);w.useEffect(()=>{GX(ae)},[ae]);const ge=w.useRef(!1),[Ne,Ie]=w.useState(()=>{const T=(()=>{try{const A=window.localStorage.getItem(xR);return A===null?!0:A==="1"}catch{return!0}})();return T&&F?(ge.current=!0,!1):T});w.useEffect(()=>{if(!(!Ne&&ge.current))try{window.localStorage.setItem(xR,Ne?"1":"0")}catch{}},[Ne]),w.useEffect(()=>{!F&&ge.current&&(ge.current=!1,Ie(!0))},[F]);const Ge=wh(Ne,200),Pe=wh(H,130),ze=wh(ae,130),[Re,st]=w.useState(null);w.useEffect(()=>{let T=null;try{T=localStorage.getItem("agent-dag.sound")}catch{}st(T===null?!0:T==="on")},[]);const ue=w.useCallback(()=>{st(T=>{var Y;const A=T!==!0;try{localStorage.setItem("agent-dag.sound",A?"on":"off")}catch{}return A&&((Y=Ut.current)==null||Y.unlock()),A})},[]),ce=w.useCallback(T=>{ue()},[ue]),se=w.useRef(ce);se.current=ce;const be=w.useRef(Re);be.current=Re;const[Le,de]=w.useState(()=>OV(yr)),fe=w.useRef(Le);fe.current=Le;const[Ce,pe]=w.useState(()=>hV(yr)),_e=w.useRef(Ce);_e.current=Ce;const[Ye,qe]=w.useState([]),ke=w.useCallback(T=>{pe(A=>{const Y={...A,[T]:null};return _e.current=Y,Y});try{localStorage.removeItem(vu[T])}catch{}},[]),Ae=w.useCallback((T,A)=>{const Y=_e.current[T];if(!(A&&Y!==A)){ke(T),de(te=>{const ye={...te,[T]:{...te[T],figure:wr}};return fe.current=ye,ye});try{localStorage.setItem(Hh[T],wr)}catch{}}},[ke]),Ue=w.useRef(Ae);Ue.current=Ae,w.useEffect(()=>{let T=!0;return NV().then(A=>{if(!T)return;qe(A);const Y=new Set(A.map(te=>te.id));for(const te of Uh){const ye=_e.current[te];ye&&!Y.has(ye)&&Ue.current(te,ye)}},()=>{}),()=>{T=!1}},[]);const Fe=w.useRef(null),Ve=w.useCallback((T,A=!1)=>{var Y,te;if((Y=Ut.current)==null||Y.unlock(),Fe.current!==null&&clearTimeout(Fe.current),Fe.current=null,!A){(te=Ut.current)==null||te.play(T,!0);return}Fe.current=setTimeout(()=>{var ye;Fe.current=null,(ye=Ut.current)==null||ye.play(T,!0)},RV)},[]),rt=w.useCallback((T,A)=>{de(Y=>{const te={level:Ql(A.level??Y[T].level),figure:o$(T,A.figure??Y[T].figure)};try{localStorage.setItem(c$[T],String(te.level)),localStorage.setItem(Hh[T],te.figure)}catch{}return{...Y,[T]:te}}),Ve(T,!0)},[Ve]),ut=w.useCallback((T,A)=>{if(!Ye.some(te=>te.id===A))return;const Y={..._e.current,[T]:A};_e.current=Y,pe(Y);try{localStorage.setItem(vu[T],A)}catch{}Ve(T,!0)},[Ye,Ve]),ct=w.useCallback(async T=>{var ye;const A=G0(Ye.length);if(A)throw new Error(A);const Y=window.AudioContext??window.webkitAudioContext;if(!Y)throw new Error("This browser cannot decode audio files.");const te=new Y;try{const je=await wV(T,Be=>te.decodeAudioData(Be));await $2(je);const Oe=Du(je);qe(Be=>[...Be.filter(lt=>lt.id!==Oe.id),Oe])}finally{(ye=te.close)==null||ye.call(te)}},[Ye.length]),yt=w.useCallback(async T=>{const A=G0(Ye.length);if(A)throw new Error(A);const Y=vV(T);await $2(Y);const te=Du(Y);qe(ye=>[...ye.filter(je=>je.id!==te.id),te])},[Ye.length]),It=w.useCallback(async(T,A)=>{const Y=Ye.find(ye=>ye.id===T),te=A.trim().slice(0,80);!Y||!te||te===Y.name||(await jV(T,te),qe(ye=>ye.map(je=>je.id===T?{...je,name:te}:je)))},[Ye]),zt=w.useCallback(async T=>{await _V(T),qe(ye=>ye.filter(je=>je.id!==T));const A=_e.current,Y=fV(A,T);_e.current=Y,pe(Y);const te=Uh.filter(ye=>A[ye]===T);for(const ye of te)try{localStorage.removeItem(vu[ye]),localStorage.setItem(Hh[ye],wr)}catch{}te.length>0&&de(ye=>{const je={...ye};for(const Oe of te)je[Oe]={...je[Oe],figure:wr};return fe.current=je,je})},[]),Xt=w.useCallback(T=>{var te,ye;const A=Uh.find(je=>_e.current[je]===T),Y=A?fe.current[A].level:bi;(te=Ut.current)==null||te.unlock(),(ye=Ut.current)==null||ye.previewCustom(T,Y)},[]);w.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const[Ft,rn]=w.useState(!1),Se=w.useRef(null),[vt,kt]=w.useState(!1),_n=w.useRef(null);w.useEffect(()=>{Ft&&kt(!1)},[Ft]);const Ut=w.useRef(null),[Vn,Vt]=w.useState("locked");w.useEffect(()=>{const T=PV({enabled:()=>be.current===!0,prefs:()=>fe.current,customSelection:()=>_e.current,loadCustom:SV,onCustomFailure:(Y,te)=>Ue.current(Y,te),onState:Vt});Ut.current=T,Vt(T.state());const A=()=>T.unlock();return window.addEventListener("pointerdown",A,{once:!0,capture:!0}),window.addEventListener("keydown",A,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",A,{capture:!0}),window.removeEventListener("keydown",A,{capture:!0})}},[]);const[$t,Zt]=w.useState(!1),[Ln,Ur]=w.useState(!1),[xe,ir]=w.useState(null),[Ns,Hr]=w.useState(null),[ma,Ss]=w.useState(!1),[xr,Pn]=w.useState(null),[Hs,Q]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(c0)??""}catch{return""}}),[De,Je]=w.useState(!1),He=w.useRef(0),[tt,wt]=w.useState(!1),gt=w.useCallback((T=!1)=>(T&&(He.current=Date.now(),wt(!0)),fetch(T?"/api/version?refresh=1":"/api/version").then(A=>A.ok?A.json():null).then(A=>{A&&ir(A)}).catch(()=>{}).finally(()=>{T&&wt(!1)})),[]),At=w.useCallback(()=>{gt(Date.now()-He.current>=FX)},[gt]);w.useEffect(()=>{gt();const T=window.setInterval(At,5*6e4),A=()=>{document.visibilityState==="visible"&&At()};return document.addEventListener("visibilitychange",A),()=>{window.clearInterval(T),document.removeEventListener("visibilitychange",A)}},[gt,At]),w.useEffect(()=>{$t&&gt()},[$t,gt]);const Ct=w.useRef(0);w.useEffect(()=>{if(!$t||!pu())return;let T=!1;const A=Ct.current;return fetch("/api/desktop-update").then(Y=>Y.ok?Y.json():null).then(Y=>{if(T||Ct.current!==A)return;const te=sR(Y);te&&Hr(te)}).catch(()=>{}),()=>{T=!0}},[$t]);const Qt=DK(Ns),St=w.useRef(!1),br=w.useRef(0),lr=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(br.current),[]);const Ci=w.useCallback(async T=>{if(!Ps(St.current))return;const A=++lr.current;window.clearTimeout(br.current),St.current=!0,Ss(!0),Pn(null);const Y=te=>{A===lr.current&&(window.clearTimeout(br.current),St.current=!1,Ss(!1),Pn({failure:te,version:T}))};try{const te=await fetch("/api/desktop-update/restart",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:T})});if(!te.ok)return Y(zK(await te.json().catch(()=>null)))}catch{return Y("unreachable")}A===lr.current&&(br.current=window.setTimeout(()=>Y("timeout"),N$))},[]);w.useEffect(()=>{const T=xK();let A=null;const Y=Oe=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:T,looking:Oe}),keepalive:!0}).catch(()=>{})},te=()=>{const Oe=wK(document);vK(A,Oe)&&Y(Oe),A=Oe},ye=()=>{A&&Y(!1),A=!1};te();const je=window.setInterval(te,yK);return window.addEventListener("focus",te),window.addEventListener("blur",te),document.addEventListener("visibilitychange",te),window.addEventListener("pagehide",ye),()=>{window.clearInterval(je),window.removeEventListener("focus",te),window.removeEventListener("blur",te),document.removeEventListener("visibilitychange",te),window.removeEventListener("pagehide",ye),ye()}},[]);const dt=(xe==null?void 0:xe.notice)??null,[cr,sn]=w.useState(null),Wr=cr&&Qt?Qt.version:null,Gn=w.useRef(null);w.useEffect(()=>{!Wr||Gn.current===Wr||(Gn.current=Wr,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:Wr})}).catch(()=>{}))},[Wr]);const Ju=w.useRef(!1);w.useEffect(()=>{if(Ju.current)return;const T=rR(),A=TK(T),Y=OK({stored:A,running:(xe==null?void 0:xe.running)??null,notes:nR,remembers:RK(T)});if(Y.reason==="no-version")return;Ju.current=!0,Y.record&&AK(T,Y.record);let te=!0;return(async()=>{var lt;let je=MK(T);if(pu())try{const et=await fetch("/api/prefs");if(!et.ok)throw new Error("desktop tour preferences unavailable");const xt=await et.json();if(!(xt!=null&&xt.ok))throw new Error("desktop tour preferences unavailable");const ft=((lt=xt.prefs)==null?void 0:lt.tourSeen)===!0;je&&!ft&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),je=je||ft}catch{je=!0}if(!te)return;const Oe=$K({tourSeen:je,decision:Y}),Be=Y.show.length?{entries:Y.show,since:A,firstRun:!1}:null;Oe.tour&&V(!0),Oe.notes==="now"?sn(Be):Oe.notes==="after"&&(G.current=Be)})(),()=>{te=!1}},[xe==null?void 0:xe.running]);const uo=(xe==null?void 0:xe.running)??"3.29.11",ed=w.useMemo(()=>x$(nR,null,uo),[uo]),ga=w.useCallback(()=>{sn({entries:ed,since:null,firstRun:!1})},[ed]),[Ti,ho]=w.useState(null),[Kn,ep]=w.useState(rb);w.useEffect(()=>{let T=!1;return fetch("/api/health").then(A=>A.ok?A.json():null).then(A=>{T||(ep(xX(A)),!(!A||typeof A.workspace!="string")&&ho(A.workspace))}).catch(()=>{}),()=>{T=!0}},[$t]);const Ri=w.useRef(Kn);Ri.current=Kn;const fo=L$(dt),ya=wX(dt,Hs),cc=w.useCallback(()=>{Q("");try{window.localStorage.setItem(c0,"")}catch{}},[]),po=w.useCallback(()=>{if(dt){Q(fo);try{window.localStorage.setItem(c0,fo)}catch{}}},[dt,fo]),[tp,uc]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(bR)??""}catch{return""}}),ht=xe!=null&&xe.invokedAs&&xe.invokedAs!==hn?xe.invokedAs:null,td=ht!=null&&tp!==ht,nd=w.useCallback(()=>{if(ht){uc(ht);try{window.localStorage.setItem(bR,ht)}catch{}}},[ht]),Dn=((qc=xe==null?void 0:xe.upgrade)==null?void 0:qc.state)??"idle",mo=rH(xe==null?void 0:xe.upgrade),Ai=w.useRef(!1),rd=w.useCallback(async()=>{if(Ps(Ai.current||Dn==="running")){Ai.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await gt(),Ai.current=!1}},[Dn,gt]);w.useEffect(()=>{if(Dn!=="running")return;const T=window.setInterval(gt,3e3);return()=>window.clearInterval(T)},[Dn,gt]);const dc=w.useCallback(async()=>{const T=xe==null?void 0:xe.command;!T||!await yi(T)||(Je(!0),window.setTimeout(()=>Je(!1),1600))},[xe==null?void 0:xe.command]),go=w.useCallback(()=>{L(T=>(T||Ie(A=>(A&&(ge.current=!0),!1)),!T))},[]),Vr=w.useCallback(()=>{ge.current=!1,Ie(T=>(T||L(!1),!T))},[]),[Gr,kr]=w.useState(!1),[wa,Ws]=w.useState(!1),[Kr,np]=w.useState(()=>{try{return Number(localStorage.getItem(iR))||0}catch{return 0}}),[hc,yo]=w.useState([]),[fc,pc]=w.useState(!1);w.useEffect(()=>{let T=!0;const A=()=>{fetch("/api/browser-watch?live=0").then(te=>te.ok?te.json():null).then(te=>{var ye;!T||!(te!=null&&te.ok)||(yo(te.episodes??[]),pc(((ye=te.settings)==null?void 0:ye.enabled)===!0))}).catch(()=>{})};A();const Y=setInterval(A,5*6e4);return()=>{T=!1,clearInterval(Y)}},[]);const[Mi,wo]=w.useState([]),sd=w.useRef(new Set),[js,va]=w.useState(null);w.useEffect(()=>{let T=!0,A=0;const Y=()=>{fetch("/api/lan").then(te=>te.ok?te.json():null).then(te=>T?(te!=null&&te.ok&&wo(ej(Array.isArray(te.pending)?te.pending:[],te.aliases)),te):null).catch(()=>null).then(te=>{T&&(A=window.setTimeout(Y,(te==null?void 0:te.enabled)===!0?U0:KM))})};return Y(),()=>{T=!1,window.clearTimeout(A)}},[]);const Vs=w.useCallback(async(T,A)=>{if(!js){va(T);try{const te=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:T,fp:A})})).json().catch(()=>null);te&&Array.isArray(te.pending)?wo(ej(te.pending,te.aliases)):wo(ye=>ye.filter(je=>je.fp!==A))}catch{}finally{va(null)}}},[js]),ur=w.useMemo(()=>TY(hc,Kr).length,[hc,Kr]),[rp,ad]=w.useState(0),Ii=w.useRef(null),[$i,Oi]=w.useState(!1),xa=w.useRef(null),[_s,Li]=w.useState(0),En=w.useState(()=>yY({protect:T=>s6(l.current,T)}))[0],[vo,Pi]=w.useState(!1),ba=w.useCallback(()=>{const T=En.paused&&En.dropped>0,A=En.setPaused(!En.paused);T&&a6(l.current);for(const Y of A)l.current=WN(l.current,Y);Pi(En.paused)},[En]),[Jt,Fn]=w.useState(Date.now()),[qn,ka]=w.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Ih)!=="0"}catch{return!0}}),Na=w.useRef(!1),sp=w.useCallback(()=>{const T=!qn;Na.current=!0;try{window.localStorage.removeItem(Ih)}catch{}ka(T),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:T})}).then(A=>A.ok?A.json():null).then(A=>{var Y;A!=null&&A.ok&&ka(((Y=A.prefs)==null?void 0:Y.autoUpdate)!==!1)}).catch(()=>{})},[qn]),[Nr,Sa]=w.useState(!1),[xo,Di]=w.useState("restart"),[mc,od]=w.useState(null),ja=w.useRef(!1),id=w.useRef(null),Fi=w.useRef(0),bo=w.useCallback(async T=>{if(!Ps(ja.current))return;const A=(T==null?void 0:T.upgrade)===!0;ja.current=!0,id.current=mo;const Y=++Fi.current;Di(A?"npx":"restart"),Sa(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(dt==null?void 0:dt.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:A})})}catch{}window.setTimeout(()=>{if(Fi.current===Y&&ja.current){ja.current=!1,Sa(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},A?18e4:3e4)},[dt==null?void 0:dt.to,mo]),gc=w.useRef(null);w.useEffect(()=>{const T=oj(l.current.agents.values())>0,A=lH({enabled:qn,kind:dt==null?void 0:dt.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ya,visible:document.visibilityState==="visible",busy:T,idleSince:gc.current,now:Jt});gc.current=A.idleSince,A.restart&&bo()},[qn,dt==null?void 0:dt.kind,xe==null?void 0:xe.canRestart,ya,Jt,bo]);const ld=oj(l.current.agents.values()),cd=iH(ld),ud=QM({enabled:qn,kind:dt==null?void 0:dt.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ya,visible:document.visibilityState==="visible",busy:ld>0,idleSince:gc.current,now:Jt});w.useEffect(()=>{const T=xe==null?void 0:xe.running;let A=null,Y=null;try{A=window.sessionStorage.getItem("agent-dag.restartPending"),Y=window.sessionStorage.getItem(kR)}catch{return}const te=nH({bundle:"3.29.11",running:T,pending:A,lastTried:Y});if(te==="reload"){try{window.sessionStorage.setItem(kR,T??"")}catch{return}window.location.reload();return}if(te!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}ja.current=!1,Sa(!1),od(T??null);const ye=window.setTimeout(()=>od(null),6e3);return()=>window.clearTimeout(ye)},[xe==null?void 0:xe.running]),w.useEffect(()=>{if(Nr&&sH({asked:id.current,reported:mo})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}ja.current=!1,Sa(!1)}},[Nr,mo]);const yc=w.useState(()=>FY(KX()))[0],Gt=w.useRef(yc.pinned),qi=w.useRef(null),Bi=w.useState(()=>ZX())[0],[wc,vc]=w.useState(()=>new Set),[_a,dd]=w.useState(xY),[ko,hd]=w.useState(KV),[zi,ap]=w.useState(XV),[No,xc]=w.useState(()=>rG(yr(q2))),[Ui,op]=w.useState(()=>nG(yr(B2))),[Gs,Hi]=w.useState(()=>sG(yr(F2),No,VV)),[Ks,Wi]=w.useState(()=>new Set),[fd,pd]=w.useState(0),[Yr,md]=w.useState(()=>lR(yR)),bc=w.useMemo(()=>PY(Yr),[Yr]),Ea=w.useCallback(T=>LY(T,bc),[bc]),[gd,ip]=w.useState(!1);w.useEffect(()=>{document.documentElement.dataset.theme=_a;try{window.localStorage.setItem(_$,_a)}catch{}md(T=>{const A=lR(yR);return DY(T,A)?T:A})},[_a]),w.useEffect(()=>{try{window.localStorage.setItem(u$,ko?"1":"0")}catch{}},[ko]),w.useEffect(()=>{try{window.localStorage.setItem(d$,String(zi))}catch{}},[zi]),w.useEffect(()=>{try{window.localStorage.setItem(B2,Ui?"1":"0")}catch{}},[Ui]),w.useEffect(()=>{try{window.localStorage.setItem(q2,JSON.stringify(No))}catch{}},[No]),w.useEffect(()=>{try{window.localStorage.setItem(F2,Gs)}catch{}},[Gs]);const lp=w.useCallback(T=>{xc(A=>A.some(Y=>Y.id===T.id)?A:[...A,T]),Wi(A=>{if(!A.has(T.id))return A;const Y=new Set(A);return Y.delete(T.id),Y})},[]),yd=w.useCallback((T,A)=>{const Y=A.trim();!Y||Y.length>Fu||xc(te=>te.map(ye=>ye.id===T?{...ye,name:Y}:ye))},[]),wd=w.useCallback(T=>{xc(A=>A.filter(Y=>Y.id!==T)),Hi(A=>aG(A,T)),Wi(A=>{if(!A.has(T))return A;const Y=new Set(A);return Y.delete(T),Y})},[]),So=w.useCallback(T=>{const A=z2(T),Y=Ks.has(A);T===Gs&&!Y||(Y&&Wi(te=>{const ye=new Set(te);return ye.delete(A),ye}),Hi(T),pd(te=>te+1))},[Gs,Ks]),jo=w.useCallback((T,A)=>{const Y=z2(T);Wi(te=>{if(te.has(Y)===A)return te;const je=new Set(te);return A?je.add(Y):je.delete(Y),je})},[]);w.useEffect(()=>{const T=document.querySelector('meta[name="theme-color"]'),A=Yr["--panel"];T&&A&&T.setAttribute("content",A)},[Yr]);const dr=w.useCallback((T,A)=>{if(Ah({durationMs:A,documentHidden:document.hidden})){e.setViewport(T,{duration:A});return}const{d3Zoom:Y,d3Selection:te}=r.getState(),ye=te==null?void 0:te.property("__zoom");if(Y&&te&&ye&&ye.k>0&&T.zoom>0){Y.transform(te,ye.scale(T.zoom/ye.k).translate((T.x-ye.x)/T.zoom,(T.y-ye.y)/T.zoom));return}e.setViewport(T,{duration:0})},[e,r]),Xr=w.useRef(null),_o=w.useRef(0),Eo=w.useRef(null),Vi=w.useRef(()=>{});w.useEffect(()=>{if(!Bi)return;const T=window.setTimeout(()=>{try{dr(Bi,0)}catch{}Ys.current=Date.now()},60);return()=>window.clearTimeout(T)},[dr,Bi]);const Gi=w.useRef(!0),[Ca,kc]=w.useState(null);w.useEffect(()=>{const T=new EventSource("/events"),A=mY(m,{now:()=>Date.now(),setTimeout:(je,Oe)=>window.setTimeout(je,Oe),clearTimeout:je=>window.clearTimeout(je)});let Y=!1;const te=typeof BroadcastChannel=="function"?SY(new BroadcastChannel(kY),Math.random().toString(36).slice(2),()=>Y):null,ye=window.setInterval(()=>{Y||!te||te.ask(600).then(je=>{Y||Ur(NY(je))})},3e3);return T.addEventListener("open",()=>{Zt(!0),ip(!0)}),T.addEventListener("error",()=>{Zt(!1),kc(null)}),T.addEventListener("open",()=>{Y=!0,Ur(!1)}),T.addEventListener("error",()=>{Y=!1}),T.addEventListener("replay-end",()=>{Gi.current=!1,A.flush(),kc(Date.now())}),T.addEventListener("desktop-update",je=>{if(pu())try{const Oe=sR(JSON.parse(je.data));Oe&&(Ct.current++,Hr(Oe),Oe.status!=="ready"&&(lr.current++,window.clearTimeout(br.current),St.current=!1,Ss(!1)))}catch{}}),T.addEventListener("hook",je=>{var Oe;try{const Be=JSON.parse(je.data);if(!En.accept(Be))return;l.current=WN(l.current,Be);const lt=Be.replay===!0||Gi.current||Date.now()-Be.receivedAt>3e4;lt?A.replay():A.live();const et=LV(Be,lt);et&&((Oe=Ut.current)==null||Oe.play(et))}catch{}}),()=>{T.close(),A.cancel(),window.clearInterval(ye),te==null||te.leave()}},[m]),w.useEffect(()=>{const T=setInterval(()=>{const A=Date.now();Fn(A);const{changed:Y,forgotten:te}=V9(l.current,A);te.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:te})}).catch(()=>{}),b(ye=>U9(ye,l.current.agents)),k(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),B(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),$(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),Y&&m()},250);return()=>clearInterval(T)},[m]);const Ki=w.useRef(null),Ys=w.useRef(0),vd=420,Yn=w.useCallback((T=500)=>{const A=o0,Y=1,te=.2,ye=i0;try{const je=document.querySelector(".canvas-wrap"),Oe=Array.from(document.querySelectorAll(".react-flow__node")).filter(Lt=>Lt.offsetWidth>0);if(!je||Oe.length===0)return;const Be=je.getBoundingClientRect(),lt=e.getViewport();if(!Number.isFinite(lt.zoom)||lt.zoom<=0)return;const et=Lt=>(Lt-Be.left-lt.x)/lt.zoom,xt=Lt=>(Lt-Be.top-lt.y)/lt.zoom,ft=Oe.map(Lt=>Lt.getBoundingClientRect()),An=Math.min(...ft.map(Lt=>et(Lt.left))),sa=Math.max(...ft.map(Lt=>et(Lt.right))),Yo=Math.min(...ft.map(Lt=>xt(Lt.top))),as=Math.max(...ft.map(Lt=>xt(Lt.bottom))),os=sa-An,Da=as-Yo;if(!(os>0&&Da>0))return;const Td=wR(je),Xo=Lt=>Math.max(te,Math.min(Y,(Be.width-Td-A*2)/(os+Lt)*ye,(Be.height-A*2)/Da*ye)),Fa=eX(Xo(vd),Xo(0)),is={x:A-An*Fa,y:Math.max(A,(Be.height-Da*Fa)/2)-Yo*Fa,zoom:Fa},Rr=++_o.current;dr(is,T),Ys.current=Date.now(),Xr.current=Ah({durationMs:T,documentHidden:document.hidden})?{target:is,until:Date.now()+T+60}:null,window.setTimeout(()=>{var Lt;try{if(((Lt=Xr.current)==null?void 0:Lt.target)===is&&(Xr.current=null),_o.current!==Rr)return;const qa=e.getViewport();(Math.abs(qa.zoom-Fa)>.01||Math.abs(qa.x-is.x)>2)&&dr(is,0)}catch{}},T+60)}catch{}},[e,dr]);w.useEffect(()=>{const T=()=>{if(!document.hidden)return;const A=Xr.current;if(Xr.current=null,!(!A||Date.now()>A.until)){try{dr(A.target,0)}catch{}Ys.current=Date.now()}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[dr]);const Nc=w.useRef(""),Sc=w.useRef(null),Xn=w.useRef(0),Es=w.useCallback(()=>{Xn.current=Date.now()},[]),Yi=w.useRef(null),jc=w.useRef(0),Xi=w.useCallback(()=>{jc.current=Date.now()},[]),Zi=w.useCallback(T=>({hasSourceEvent:!!T,at:Date.now(),lastDeckFitAt:Ys.current,lastCanvasInputAt:jc.current}),[]),_c="agent-dag.autoFitDisabled",Xs=w.useRef(!1),[Ec,Zs]=w.useState(!1);w.useEffect(()=>{try{window.localStorage.removeItem(_c)}catch{}},[]);const Qs=w.useCallback(()=>{Xs.current||(Xs.current=!0,Zs(!0))},[]),Ta=w.useCallback(()=>{Xs.current=!1,Zs(!1),Yn(400)},[e,Yn]);w.useEffect(()=>{const T=setInterval(()=>{if(Xs.current||Date.now()-Xn.current<800)return;const A=l.current,Y=Date.now(),te=[];for(const je of A.agents.values())eb(je,Y)&&te.push({id:je.id});if(te.length===0)return;const ye=[];for(const{id:je}of te){const Oe=Sr.current.get(je),Be=Gt.current.get(je)??Kt.current.get(je);!Oe||!Be||ye.push({x:Be.x,y:Be.y,width:Oe.width,height:Oe.height})}KY({pane:Yi.current,viewport:e.getViewport(),boxes:ye})&&Yn(600)},1500);return()=>clearInterval(T)},[e]);const Ra=w.useRef(!1),Sr=w.useRef(new Map),Aa=w.useRef(0),Ma=w.useCallback(T=>{const A=Sr.current;let Y=!1;for(const te of T.nodeInternals.values()){const ye=te.width,je=te.height;if(ye==null||je==null)continue;const Oe=A.get(te.id);Oe?(Math.abs(Oe.height-je)>4||Math.abs(Oe.width-ye)>4)&&(A.set(te.id,{width:ye,height:je}),Y=!0):(A.set(te.id,{width:ye,height:je}),Y=!0)}return Y&&(Aa.current+=1),Aa.current},[]),Qi=Et(Ma),[Cc,Ji]=w.useState(0);w.useEffect(()=>{let T=0;const A=()=>{const te=Sr.current;let ye=!1;for(const je of document.querySelectorAll(".react-flow__node[data-id]")){const Oe=je.getAttribute("data-id");if(!Oe)continue;const Be=je.offsetWidth,lt=je.offsetHeight;if(!Be||!lt)continue;const et=te.get(Oe);(!et||Math.abs(et.width-Be)>4||Math.abs(et.height-lt)>4)&&(te.set(Oe,{width:Be,height:lt}),ye=!0)}ye&&Ji(je=>je+1)};if(Ra.current)return;let Y=0;return document.visibilityState==="hidden"?Y=window.setTimeout(A,32):T=requestAnimationFrame(A),()=>{cancelAnimationFrame(T),window.clearTimeout(Y)}});const Kt=w.useRef(yc.positions),Tc=w.useRef(new Set),Co=w.useRef(""),hr=w.useMemo(()=>QK(l.current.agents.values(),c),[l.current,l.current.revision,c]),Js=w.useMemo(()=>{const T=[];for(const A of l.current.agents.values())!eb(A,Jt)||hr.has(A.id)||T.push(A.id+(A.parentId?`>${A.parentId}`:""));return T.sort(),`${T.join("|")}#sv${Qi}.${Cc}`},[l.current,l.current.revision,Jt,Qi,Cc,hr]),Ia=w.useRef(null);w.useEffect(()=>(Ia.current!=null&&window.clearTimeout(Ia.current),Ia.current=window.setTimeout(()=>{$h(Kt.current,Gt.current)},1500),()=>{Ia.current!=null&&window.clearTimeout(Ia.current)}),[Js]),w.useEffect(()=>{if(Nc.current===Js)return;const T=Nc.current;if(Nc.current=Js,!T||Xs.current)return;Date.now()-Ys.current>1200&&Yn(400),Ki.current&&window.clearTimeout(Ki.current),Ki.current=window.setTimeout(()=>{Xs.current||Yn(500)},280)},[Js,e,Yn]);const jr=w.useMemo(()=>hY(l.current,S),[l.current,l.current.revision,S]),To=w.useMemo(()=>{const T=IY(l.current,Jt);for(const A of hr)T.delete(A);return T},[l.current,l.current.revision,Jt,hr]),_r=w.useRef(null),[Ro,xd]=w.useState({w:0,h:0});w.useEffect(()=>{const T=_r.current;if(!T||typeof ResizeObserver>"u")return;const A=new ResizeObserver(Y=>{var ye;const te=(ye=Y[0])==null?void 0:ye.contentRect;te&&(Yi.current={width:te.width,height:te.height},xd(je=>Math.abs(je.w-te.width)>40||Math.abs(je.h-te.height)>40?{w:te.width,h:te.height}:je))});return A.observe(T),Yi.current={width:T.clientWidth,height:T.clientHeight},xd({w:T.clientWidth,h:T.clientHeight}),()=>A.disconnect()},[]);const Ao=w.useCallback(T=>{var Y,te;const A=T.target;!(A!=null&&A.closest)||A.closest(PX)!==T.currentTarget||(T.preventDefault(),(te=(Y=document.activeElement)==null?void 0:Y.blur)==null||te.call(Y))},[]),cp=w.useRef(new Map),[Mo,bd]=w.useState(!1);w.useEffect(()=>{const T=window.setTimeout(()=>bd(!0),2500);return()=>window.clearTimeout(T)},[]);const[Mt,Io]=w.useState(!1),fr=w.useRef(null),[Zr,Rc]=w.useState(!1),[el,$a]=w.useState(!1),[tl,Oa]=w.useState(""),[$o,kd]=w.useState("far"),Nd=w.useRef(null),Ac=wh(el,140),Oo=w.useCallback(T=>{var te;const A=(te=Nd.current)==null?void 0:te.getBoundingClientRect(),Y=uY(T);return A&&Y?cY(Y,A):"far"},[]),[nl,Mc]=w.useState("detail"),Qr=w.useRef(null),Lo=w.useRef(null),Ic=w.useCallback(()=>{var te;const T=Aa.current;if(((te=Lo.current)==null?void 0:te.version)===T)return Lo.current.card;const A=[];for(const ye of l.current.agents.keys()){const je=Sr.current.get(ye);je&&A.push(je)}const Y=XY(A);return Lo.current={version:T,card:Y},Y},[]),up=w.useCallback(()=>{fr.current&&(window.clearTimeout(fr.current),fr.current=null),Io(!1)},[]),Sd=w.useCallback(T=>{T.length!==0&&queueMicrotask(()=>{Io(!0),fr.current&&window.clearTimeout(fr.current),fr.current=window.setTimeout(()=>Io(!1),DX+80)})},[]);w.useEffect(()=>()=>{fr.current&&window.clearTimeout(fr.current)},[]);const Cn=_?l.current.agents.get(_):null,jd=y&&Cn!=null,[Po,Cs]=w.useState(0);w.useEffect(()=>{const T=wR(_r.current);Cs(A=>Math.abs(A-T)>40?T:A)},[ze,Pe,H,jd,Ro.w]);const rl=w.useRef(Po);rl.current=Po;const Jr=Ro.w>0?Math.max(0,(Ro.w-Po-o0*2)*i0):0,Bn=Ro.h>0?Math.max(0,(Ro.h-o0*2)*i0):0,Do=mF(),{nodes:gn,edges:sl}=w.useMemo(()=>{const T=X9(l.current,Jt,Jr,Bn,Gt.current,Sr.current,cp.current,Sd,Mo,Zr,Kt.current,Tc.current,Js,Co,S,jr,To,P);return JK(T.nodes,T.edges,c)},[l.current,l.current.revision,Jt,Jr,Bn,Mo,Zr,Js,S,jr,To,P,rp,Do,c]),dp=w.useState(YX)[0],_d=w.useRef(dp);w.useEffect(()=>{if(!Mo||Zr)return;const T={width:Jr,height:Bn};if(!(T.width>0&&T.height>0))return;const A=_d.current;if(_d.current=T,XX(T),!A||A.width===T.width&&A.height===T.height)return;const Y={direction:"LR",pinned:Gt.current,measured:Sr.current,lanes:W0(l.current)};if(!A9(gn,sl,Y,A,T))return;const te=Eo.current&&Date.now()-Eo.current.at<1500?Eo.current.id:null,ye=te??As.current,je=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;for(const Oe of Array.from(Kt.current.keys()))Gt.current.has(Oe)||Kt.current.delete(Oe);Tc.current.clear(),Co.current="",m(),window.setTimeout(()=>{if($h(Kt.current,Gt.current),Xs.current){if(te){Vi.current(te);return}const Oe=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;if(je&&Oe&&(Oe.x!==je.x||Oe.y!==je.y)){const Be=e.getViewport();_o.current+=1,dr({x:Be.x-(Oe.x-je.x)*Be.zoom,y:Be.y-(Oe.y-je.y)*Be.zoom,zoom:Be.zoom},0),Ys.current=Date.now()}return}Yn(500)},80)},[Jr,Bn,Mo,Zr,m,Yn,e,dr]);const Ts=w.useMemo(()=>{const T=new Map;for(const Y of gn){const te=Y.data;if(!(te!=null&&te.sessionId)||te.exitAt!=null)continue;const ye=Y.width,je=Y.height;if(ye==null||je==null)continue;const Oe=Y.position.x,Be=Y.position.y,lt=Oe+ye,et=Be+je,xt=T.get(te.sessionId);xt?(xt.minX=Math.min(xt.minX,Oe),xt.minY=Math.min(xt.minY,Be),xt.maxX=Math.max(xt.maxX,lt),xt.maxY=Math.max(xt.maxY,et)):T.set(te.sessionId,{minX:Oe,minY:Be,maxX:lt,maxY:et})}const A=[];for(const[Y,te]of T){const ye=te.maxX-te.minX+Mh*2,je=te.maxY-te.minY+Mh*2;A.push({id:`group:${Y}`,type:E$,position:{x:te.minX-Mh,y:te.minY-Mh},data:{sessionId:Y,w:ye,h:je},width:ye,height:je,style:{width:ye,height:je},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return A},[gn]),Fo=w.useMemo(()=>{const T=[...Ts,...gn],A=xa.current;return!A||A.size===0?T:T.map(Y=>{const te=A.get(Y.id);return te?{...Y,position:te}:Y})},[Ts,gn,_s]),es=w.useMemo(()=>{const T=new Set;for(const A of l.current.agents.values())for(const Y of A.tools)T.add(H$(Y.name));return Object.keys(U$).filter(A=>T.has(A))},[l.current,l.current.revision]);w.useEffect(()=>{if(es.length<=1){Oi(!1);return}let T=0;const A=()=>{const Y=Ii.current;if(Y&&!document.hidden){const te=Y.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Oe=>Oe.getBoundingClientRect()),je=OY(te,ye,8);Oi(Oe=>Oe===je?Oe:je)}T=window.setTimeout(A,300)};return A(),()=>window.clearTimeout(T)},[es.length]);const al=w.useCallback(T=>{vc(A=>{const Y=new Set(A);return Y.has(T)?Y.delete(T):Y.add(T),Y})},[]),qo=j?X5(l.current.agents,j):null,ea=w.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=E0(),Gt.current.clear(),Sr.current.clear(),Kt.current.clear(),Co.current="",NR(),u(new Set),p(null);try{window.localStorage.removeItem(fk)}catch{}R(),m()},[m,R]),Er=w.useCallback(T=>{const A=l.current.agents.get(T);A&&(u(Y=>{const te=new Set(Y);return te.add(T),aR(window.localStorage,te),te}),p({id:T,label:A.label}),Gt.current.delete(T),Kt.current.delete(T),R())},[R]),Tt=w.useCallback(()=>{_&&Er(_)},[_,Er]),Rt=f&&c.has(f.id)?f:null;w.useEffect(()=>{var T;f&&((T=_r.current)==null||T.focus())},[f]);const Zn=w.useCallback(T=>{const A=[...T];u(Y=>{const te=eY(Y,A);return te!==Y&&aR(window.localStorage,te),te})},[]),an=w.useRef(W);an.current=W;const kn=w.useRef(ee);kn.current=ee;const ts=w.useRef(!1);ts.current=qo!=null||Gr||q!=null||X||I!=null||wa||ee||cr!=null;const ns=w.useCallback(T=>{const A=tV(T,{confirmOpen:an.current,modalOpen:ts.current});A==="confirm"?ne(!0):A==="clear"&&(ne(!1),ea())},[ea]),yn=w.useCallback(()=>{Gt.current.clear(),Kt.current.clear(),Co.current="",NR(),m(),window.setTimeout(()=>Yn(500),80)},[m,e,Yn]),Bo=w.useCallback(()=>Yn(500),[Yn]),Rs=w.useRef(gn);Rs.current=gn;const zn=w.useCallback(T=>{var xt;const A=_r.current,Y=l.current.agents.get(T);if(!A||!Y)return;const te=W0(l.current),ye=(ft,An)=>{const sa=Sr.current.get(ft.id);if(!sa)return null;const Yo=An&&te.has(ft.id)?vd:0;return{x:ft.position.x,y:ft.position.y,width:sa.width+Yo,height:sa.height}},je=Rs.current.find(ft=>ft.id===T),Oe=je?ye(je,!1):null;if(!Oe)return;const Be=[];for(const ft of Rs.current){if(ft.type!=="agent"&&ft.type!=="recapNote"||((xt=ft.data)==null?void 0:xt.sessionId)!==Y.sessionId)continue;const An=ye(ft,ft.type==="agent");An&&Be.push(An)}const lt=A.getBoundingClientRect(),et=rX({pane:{width:lt.width,height:lt.height},insets:{top:56,left:72,bottom:32,right:rl.current+32},context:sX(Be)??Oe,anchor:Oe});Za(),Qs(),Eo.current={id:T,at:Date.now()},_o.current+=1,dr(et,l0),Ys.current=Date.now(),Xr.current=Ah({durationMs:l0,documentHidden:document.hidden})?{target:et,until:Date.now()+l0+60}:null},[dr,Qs]);Vi.current=zn;const ol=w.useCallback(T=>{const A=Rs.current.find(Y=>Y.id===T&&Y.type==="agent");return A?A.data:void 0},[]),Ed=w.useCallback(T=>{var A;return(A=l.current.agents.get(T))==null?void 0:A.label},[]),rs=w.useCallback(T=>{var te;const A=Rs.current.find(ye=>ye.id===T&&ye.type==="recapNote");if(!A)return;const Y=A.data;return{recap:Y.recap,hue:Y.hue,sessionLabel:(te=l.current.agents.get(Y.parentId))==null?void 0:te.label}},[]),il=w.useCallback(()=>{var Y;const T=(Y=_r.current)==null?void 0:Y.getBoundingClientRect(),A=document.documentElement;return T?{width:T.right-rl.current,height:T.bottom}:{width:A.clientWidth,height:A.clientHeight}},[]),As=w.useRef(_);As.current=_;const $c=w.useRef(Tt);$c.current=Tt;const ll=w.useCallback(T=>{const A=Rs.current.filter(je=>je.type==="agent"),Y=VK(A.map(je=>({id:je.id,x:je.position.x,y:je.position.y})),As.current,T),te=Y?A.find(je=>je.id===Y):void 0;if(!te)return;const ye=a0(document.activeElement);C(te.id,!1),window.setTimeout(()=>{try{zn(te.id)}catch{}ye&&LX(te.id)},30)},[C,zn]),Cr=w.useRef(null),Qn=w.useCallback(T=>{C(T,!1),window.setTimeout(()=>{try{zn(T)}catch{}},60)},[C,zn]),La=w.useCallback(T=>{hr.has(T)&&Zn([T]),Qn(T)},[hr,Zn,Qn]),zo=w.useRef(null);w.useEffect(()=>{let T=-1/0;const A=()=>{T=performance.now()},Y=te=>{zo.current=performance.now()-T<250?te.target:null};return window.addEventListener("pointerdown",A,!0),window.addEventListener("focusin",Y,!0),()=>{window.removeEventListener("pointerdown",A,!0),window.removeEventListener("focusin",Y,!0)}},[]),w.useEffect(()=>{const T=A=>{var Be,lt;const Y=A.target,te={tagName:Y==null?void 0:Y.tagName,isContentEditable:Y==null?void 0:Y.isContentEditable,role:(Be=Y==null?void 0:Y.getAttribute)==null?void 0:Be.call(Y,"role"),type:Y==null?void 0:Y.type,pointerFocused:Y!=null&&Y===zo.current};if(A.key==="Escape"){const et=F6({overlayOpen:gu.depth()>0,typing:Ef(te)});et==="dismiss"?gu.dismissTop():et==="blur"?Y==null||Y.blur():(XK(te)&&(Y==null||Y.blur()),R());return}if(_f(A))return;const ye=a0(Y)?(lt=Y==null?void 0:Y.getAttribute)==null?void 0:lt.call(Y,"data-id"):null,je=ye&&Rs.current.some(et=>et.id===ye)?ye:null,Oe=KK(A,je);if(Oe.kind==="activate"){A.preventDefault(),C(Oe.nodeId,Oe.additive);return}if(Oe.kind!=="node"&&!(Oe.nodeId==null&&K6(te,A.key))&&!Y6({key:A.key,modalOpen:X6({appModal:ts.current,dialogDepth:gu.dialogDepth()}),sheetOpen:kn.current})){if(A.key===" "&&(A.preventDefault(),ba()),(A.key==="c"||A.key==="C")&&ns("shortcut"),(A.key==="r"||A.key==="R")&&yn(),(A.key==="f"||A.key==="F")&&Bo(),(A.key==="z"||A.key==="Z")&&As.current&&zn(As.current),A.key==="Delete"&&$c.current(),(A.key==="l"||A.key==="L")&&go(),A.key==="d"||A.key==="D")if(As.current)v(et=>!et);else{const et=km(l.current.agents.values());et.length>0?Qn(et[0].id):ll(1)}if((A.key==="h"||A.key==="H")&&kr(et=>!et),(A.key==="u"||A.key==="U")&&D(et=>!et),(A.key==="a"||A.key==="A")&&Ri.current.claude&&Vr(),(A.key==="j"||A.key==="J")&&ll(1),(A.key==="k"||A.key==="K")&&ll(-1),A.key==="w"||A.key==="W"){const et=C6(km(l.current.agents.values()),Cr.current);et&&(Cr.current=et.id,Qn(et.id))}(A.key==="t"||A.key==="T")&&dd(et=>et==="dark"?"light":"dark"),(A.key==="m"||A.key==="M")&&Ri.current.claude&&be.current!==null&&se.current(A.shiftKey),(A.key==="s"||A.key==="S")&&le(et=>!et),(A.key==="b"||A.key==="B")&&Ws(et=>!et),(A.key==="v"||A.key==="V")&&Ri.current.claude&&be.current!==null&&rn(et=>!et),A.key==="?"&&M(et=>!et)}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[ns,yn,Bo,R,C,ll,Qn,zn,ba]);const Uo=l.current.agents.size,_t=w.useMemo(()=>km(l.current.agents.values()),[l.current,l.current.revision]),Tn=w.useRef(new Map);w.useEffect(()=>{Tn.current=rY(Tn.current,c,Date.now());const T=[...tY(_t,hr),...sY(l.current.agents,hr,c,Tn.current)];T.length>0&&Zn(T)},[_t,hr,c,Zn]);const Ms=w.useMemo(()=>T6(l.current.agents.values()),[l.current,l.current.revision]),Tr=w.useRef(null);w.useEffect(()=>{const T=jY({waiting:_t.length,running:Ms,connected:$t}),A=Tr.current;if(Tr.current=T,(A==null?void 0:A.title)!==T.title&&(document.title=T.title),(A==null?void 0:A.icon)!==T.icon){const Y=document.querySelector('link[rel="icon"]');Y&&(Y.href=_Y[T.icon])}},[_t.length,Ms,$t]);const[ss,ta]=w.useState(""),Oc=CY(_t);w.useEffect(()=>{ta(T=>oR(T,Oc))},[Oc]);const[Lc,cl]=w.useState(""),Rn=ur>0?`Browser watch has ${ur} unread ${ur===1?"finding":"findings"}.`:"";w.useEffect(()=>{cl(T=>oR(T,Rn,"Browser watch has no unread findings."))},[Rn]);const[wn,Ot]=w.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[on,ul]=w.useState(null),[Ho,Wo]=w.useState(!1),[Pc,Dc]=w.useState(!1);w.useEffect(()=>{let T=!0;return fetch("/api/prefs").then(A=>A.ok?A.json():null).then(A=>{var Y,te,ye;if(!(!T||!(A!=null&&A.ok))){if(!Na.current){let je=!1;try{je=window.localStorage.getItem(Ih)==="0",window.localStorage.removeItem(Ih)}catch{}je&&((Y=A.prefs)==null?void 0:Y.autoUpdate)!==!1?(ka(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):ka(((te=A.prefs)==null?void 0:te.autoUpdate)!==!1)}Wo(((ye=A.prefs)==null?void 0:ye.notifications)===!0),Dc(A.notificationsVetoed===!0)}}).catch(()=>{}),()=>{T=!1}},[]);const Vo=w.useRef(()=>{}),Cd=w.useCallback(()=>{const T=!Ho;Wo(T),T&&typeof Notification<"u"&&Notification.permission==="default"&&Vo.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:T})}).then(A=>A.ok?A.json():null).then(A=>{var Y;A!=null&&A.ok&&(Wo(((Y=A.prefs)==null?void 0:Y.notifications)===!0),Dc(A.notificationsVetoed===!0))}).catch(()=>{})},[Ho]),Pa=typeof Notification<"u";w.useEffect(()=>{if(!on)return;const A=setTimeout(()=>ul(null),on==="blocked"?8e3:4e3);return()=>clearTimeout(A)},[on]);const dl=w.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(T=>{const A=T;Ot(A),A==="granted"?ul("on"):A==="denied"&&ul("blocked")})},[]);Vo.current=dl;const Go=w.useRef(new Set),na=w.useRef(null),hl=_t.map(T=>jf(T.id,T.waiting)).join("|");w.useEffect(()=>{I6(na.current,wn)&&(na.current=wn,Go.current=Nm(_t))},[wn]);const Fc=w.useRef(!1);return w.useEffect(()=>{$6(Fc.current,Ca)&&(Fc.current=!0,Go.current=Nm(_t))},[Ca]),w.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!O6(na.current,Ca))return;const T=typeof document>"u"||!document.hidden,A=A6(_t,Go.current,T,Ho);for(const Y of A)try{const te=new Notification(Y.title,{body:Y.body,tag:Y.key});te.onclick=()=>{window.focus(),Qn(Y.sessionId),te.close()}}catch{}Go.current=T?Nm(_t):M6(_t,A,Go.current)},[hl,Ca]),o.jsxs("div",{className:"app",children:[o.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),o.jsxs("header",{className:"topbar",children:[o.jsxs("div",{className:"readout",children:[o.jsxs("div",{className:"brand",children:[o.jsx("span",{className:"logo"}),o.jsx("h1",{children:hn}),Qt?(()=>{const T=BK(FK()??uo,Qt.version);return o.jsxs("button",{type:"button",className:"v ready",onClick:ga,"aria-haspopup":"dialog","aria-label":T.label,title:T.title,children:[T.text,o.jsx("span",{className:"v-dot","aria-hidden":!0})]})})():dt?o.jsxs("button",{type:"button",className:"v stale",onClick:()=>{ga(),cc()},"aria-haspopup":"dialog","aria-label":yX({...dt,open:ya}),title:dt.kind==="restart"?`Running v${dt.from}; v${dt.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${dt.from}; v${dt.to} is on npm · click for what's new`,children:["v",dt.from,o.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const T={running:uo,latest:xe==null?void 0:xe.latest,latestPending:xe==null?void 0:xe.latestPending,checkedAgo:xe!=null&&xe.checkedAt?qh(Jt-xe.checkedAt):null,checkFailedAgo:xe!=null&&xe.checkFailedAt&&xe.checkFailedAt>(xe.checkedAt??0)?qh(Jt-xe.checkFailedAt):null,checkDisabled:xe==null?void 0:xe.checkDisabled,checking:tt};return o.jsxs("button",{type:"button",className:tt?"v checking":"v",onClick:()=>{ga(),gt(!0)},"aria-busy":tt||void 0,"aria-haspopup":"dialog","aria-label":gX(T),title:mX(T),children:["v",T.running]})})()]}),o.jsxs("span",{className:"status",children:[(()=>{const T=AX({connected:$t,paused:vo,held:En.size,dropped:En.dropped});return T.resting?null:o.jsx("span",{className:`pill ${T.tone}`,title:T.title,children:o.jsxs("span",{className:"pill-box",children:[o.jsx("span",{className:"pill-widest","aria-hidden":!0,children:T.widest}),o.jsx("span",{className:"pill-label",children:T.label})]})})})(),o.jsxs("span",{ref:U,className:"month-usage",title:K?`${K.tokens.toLocaleString()} tokens · ${pR(K.cost)} spent since the 1st of this local calendar month`:z?"Monthly usage is unavailable — ccusage could not be read":"Loading usage since the 1st of this local calendar month",children:[o.jsx("span",{className:"month-usage-label",children:"this month"}),K?o.jsxs(o.Fragment,{children:[o.jsx("b",{children:Pt(K.tokens)}),o.jsx("span",{className:"month-usage-unit",children:"tokens"}),o.jsx("span",{className:"month-usage-sep","aria-hidden":!0,children:"·"}),o.jsx("b",{children:pR(K.cost)})]}):o.jsx("span",{className:"month-usage-pending",children:z?"unavailable":"…"})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:ss}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Lc}),_t.length>0&&o.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{Cr.current=_t[0].id,Qn(_t[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
291
291
  ${_t.map(T=>` ${T.label}: ${Xl(T.waiting)} (${qh(Jt-T.waiting.since)})`).join(`
292
292
  `)}`,"aria-label":`${_t.length} session${_t.length===1?"":"s"} waiting for you`,children:[o.jsx("span",{className:"ap-pulse","aria-hidden":!0}),o.jsx("b",{children:_t.length})," ",o.jsx("span",{className:"ws-word",children:"waiting"})]}),on&&o.jsx("span",{className:on==="on"?"notify-said":"notify-said notify-said-blocked",role:"status",title:on==="on"?"The deck will raise a system notification when a session blocks on you and this tab is in the background":"Notifications are blocked for this page. Only your browser can undo that — its site settings for this address",children:on==="on"?"notifications on":"notifications blocked"})]}),Cn&&(()=>{const T=or(Cn),A=Math.max(0,((Cn.endedAt??Jt)-Cn.startedAt)/1e3),Y=Cn.state==="active"?_b(T.total,A):null,te=S.size-1;return o.jsxs("button",{type:"button",className:"selected-ribbon",title:`Zoom to ${Cn.label} and its session (Z)${T.total>0?`
293
293
  ${bt(T.total)} spent${Y?` · ${Y}`:""}`:""}`,onClick:()=>{try{zn(Cn.id)}catch{}},children:[o.jsx("span",{className:`state-pill state-${Cn.state}`,children:Cn.state==="active"?"live":Cn.state}),o.jsx("span",{className:"selected-label",children:Cn.label}),T.total>0&&o.jsxs("span",{className:"selected-cost",children:[bt(T.total),Y?o.jsxs("span",{className:"selected-rate",children:[" · ",Y]}):null]}),te>0&&o.jsxs("span",{className:"selected-extra",children:["+",te]}),o.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:ye=>{ye.stopPropagation(),R()},children:"×"})]})})(),o.jsxs("div",{className:"actions",children:[o.jsxs("div",{className:"action-run",children:[o.jsxs("button",{className:"btn icon-btn",onClick:go,title:`${F?"Hide":"Show"} session list (L)`,"aria-label":"Toggle session list","aria-expanded":F,"aria-controls":F?"session-list":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M5.4 3.6h6.6M5.4 7h6.6M5.4 10.4h6.6"}),o.jsx("path",{d:"M2.2 3.6h.2M2.2 7h.2M2.2 10.4h.2"})]}),o.jsx("span",{className:"tb-word",children:"Session list"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>D(T=>!T),title:`${H?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel","aria-expanded":H,"aria-controls":H?"usage-panel":void 0,children:[o.jsxs("svg",{className:"tb-glyph-narrow",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M9.4 4.5C9 3.6 8.1 3.1 7 3.1c-1.4 0-2.4.8-2.4 1.9 0 1.2 1.2 1.6 2.4 2s2.4.8 2.4 2c0 1.1-1 1.9-2.4 1.9-1.1 0-2-.5-2.4-1.4"}),o.jsx("path",{d:"M7 1.6v1.5M7 10.9v1.5"})]}),o.jsx("span",{className:"tb-word",children:"Usage"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>kr(T=>!T),title:"Usage history — ccusage (H)","aria-label":"Open usage history","aria-haspopup":"dialog",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("line",{x1:"3",y1:"11.5",x2:"3",y2:"7"}),o.jsx("line",{x1:"7",y1:"11.5",x2:"7",y2:"3"}),o.jsx("line",{x1:"11",y1:"11.5",x2:"11",y2:"8.5"})]}),o.jsx("span",{className:"tb-word",children:"History"})]})]}),o.jsxs("div",{className:"action-run",children:[Kn.claude&&o.jsxs("button",{className:"btn icon-btn",onClick:Vr,title:`${Ne?"Hide":"Show"} accounts (A)`,"aria-label":"Toggle accounts panel","aria-expanded":Ne,"aria-controls":Ne?"accounts-panel":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"4.6",r:"2.4"}),o.jsx("path",{d:"M2.4 12c0-2.3 2.1-3.7 4.6-3.7s4.6 1.4 4.6 3.7"})]}),o.jsx("span",{className:"tb-word",children:"Accounts"})]}),o.jsxs("button",{className:"btn icon-btn",onClick:()=>le(T=>!T),title:`${ae?"Hide":"Show"} this machine — cores, memory, temperature (S)`,"aria-label":"Toggle machine detail","aria-expanded":ae,"aria-controls":ae?"system-panel":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("rect",{x:"3.6",y:"3.6",width:"6.8",height:"6.8",rx:"1.2"}),o.jsx("path",{d:"M5.8 1.4v2.2M8.2 1.4v2.2M5.8 10.4v2.2M8.2 10.4v2.2M1.4 5.8h2.2M1.4 8.2h2.2M10.4 5.8h2.2M10.4 8.2h2.2"})]}),o.jsx("span",{className:"tb-word",children:"Machine"})]}),o.jsxs("button",{className:"btn icon-btn bw-btn",onClick:()=>Ws(T=>!T),title:fc?"Browser watch — watching; the deck is keeping its own copy (B)":"Browser watch — not watching; reading the browser's history live (B)","aria-label":`Browser watch, ${fc?"watching":"not watching"}`+(ur>0?`, ${ur} unread`:""),"aria-haspopup":"dialog",children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M0.9 7s2.2-4 6.1-4 6.1 4 6.1 4-2.2 4-6.1 4S0.9 7 0.9 7Z"}),fc||ur>0?o.jsx("circle",{cx:"7",cy:"7",r:"1.8",fill:"currentColor",stroke:"none"}):o.jsx("line",{x1:"2.4",y1:"11.6",x2:"11.6",y2:"2.4"})]}),o.jsx("span",{className:"tb-word",children:"Browser watch"}),ur>0&&o.jsx("span",{className:"bw-badge","aria-hidden":!0,children:ur})]})]}),o.jsxs("div",{className:"action-run action-run-utility",children:[Kn.claude&&Re!==null&&o.jsxs("div",{className:"sound-slot",children:[o.jsxs("button",{ref:Se,className:"btn icon-btn",onClick:()=>rn(T=>!T),...to(!1),title:jX(Kn,{on:Re===!0,locked:Vn==="locked",prefs:Le}),"aria-label":`Sound settings, ${Re?"on":"off"}`,"aria-haspopup":"dialog","aria-expanded":Ft,"aria-controls":Ft?"sound-menu":void 0,children:[o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("path",{d:"M3.2 5.2h2L7.8 3v8L5.2 8.8h-2z"}),Re?o.jsxs(o.Fragment,{children:[o.jsx("path",{d:"M9.8 5.4a2.4 2.4 0 0 1 0 3.2"}),o.jsx("path",{d:"M11.3 3.9a4.6 4.6 0 0 1 0 6.2"})]}):o.jsxs(o.Fragment,{children:[o.jsx("path",{d:"M10 5.6l2.6 2.8"}),o.jsx("path",{d:"M12.6 5.6L10 8.4"})]})]}),o.jsx("span",{className:"tb-word",children:"Sound"})]}),Ft&&o.jsx(HV,{onClose:()=>rn(!1),soundOn:Re===!0,onToggleSound:ue,prefs:Le,onLevel:(T,A)=>rt(T,{level:A}),onFigure:(T,A)=>rt(T,{figure:A}),onPreview:T=>Ve(T),customAssets:Ye,customSelections:Ce,onBuiltInSelected:ke,onCustomSelected:ut,onImportCustom:ct,onCreateVoice:yt,onRenameCustom:It,onPreviewCustom:Xt,onDeleteCustom:zt,notifyOn:Ho,onToggleNotify:Cd,notifyVetoed:Pc,notifyPermission:Pa?wn:"unsupported",onAskNotify:dl,openerRef:Se})]}),o.jsxs("div",{className:"appearance-slot",children:[o.jsx("button",{ref:_n,className:"btn icon-btn",onClick:()=>{rn(!1),kt(T=>!T)},title:"Appearance settings","aria-label":`Appearance settings, ${_a} theme, character ${ko?"shown":"hidden"}`,"aria-haspopup":"dialog","aria-expanded":vt,"aria-controls":vt?"appearance-menu":void 0,children:_a==="dark"?o.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[o.jsx("circle",{cx:"7",cy:"7",r:"2.5"}),o.jsx("path",{d:"M7 1.5v1.2M7 11.3v1.2M1.5 7h1.2M11.3 7h1.2M3.1 3.1l.85.85M10.05 10.05l.85.85M3.1 10.9l.85-.85M10.05 3.95l.85-.85"})]}):o.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:o.jsx("path",{d:"M11.8 8.4A5 5 0 1 1 5.6 2.2a4 4 0 0 0 6.2 6.2Z"})})}),vt&&o.jsx(dG,{theme:_a,onTheme:dd,characterEnabled:ko,onToggleCharacter:()=>hd(T=>!T),fmVolume:zi,onFmVolume:ap,fmMuted:Ui,onFmMuted:()=>op(T=>!T),fmSource:Gs,onFmSource:So,customFmStations:No,unavailableFmStations:Ks,onAddFmStation:lp,onRenameFmStation:yd,onRemoveFmStation:wd,onClose:()=>kt(!1)})]})]})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Rt?`${Rt.label} removed from the board.`:""}),mc?o.jsxs("div",{className:"ver-banner done",role:"status",children:[o.jsx("span",{className:"ver-dot"}),o.jsxs("strong",{children:["Restarted — now running v",mc,"."]}),o.jsx("span",{className:"ver-sub",children:"The canvas replayed from the event log."})]}):gd&&!$t?o.jsxs("div",{className:"conn-banner",role:"alert",children:[o.jsx("span",{className:"conn-dot"}),Nr?xo==="npx"?"Fetching the new version with npx — this can take a minute…":`Restarting ${hn}…`:(()=>{const T=TX({connected:$t,paused:vo});return o.jsxs(o.Fragment,{children:[`Lost connection to the ${hn} server. Reconnecting…`,T&&o.jsx("span",{className:"conn-sub",children:T})]})})()]}):ya&&dt?o.jsxs("div",{className:`ver-banner ${dt.kind}`,role:"status",children:[o.jsx("span",{className:`ver-dot${ud==null?"":" armed"}`}),dt.kind==="restart"?o.jsxs(o.Fragment,{children:[o.jsxs("strong",{children:["v",dt.to," is installed — this deck still runs v",dt.from,"."]}),xe!=null&&xe.canRestart?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"ver-act",onClick:()=>bo(),...to(Nr),title:`Stop this process and bring it back on the same port. The canvas replays from the event log.