ccdeck 3.29.6 → 3.29.7
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.
- package/dist/web/assets/{BrowserWatchModal-UR0ISjic.js → BrowserWatchModal-Du5jrn6d.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-B8dnL7pR.js → UsageHistoryModal-Cc9ltAyG.js} +1 -1
- package/dist/web/assets/{index-6Mi0L2Ks.js → index-BVujS2uz.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/release-notes.json +2 -1
|
@@ -89,7 +89,7 @@ ${Re.sessionId}`:Re.sessionId,children:Re.label??Re.sessionId.slice(0,8)}),o.jsx
|
|
|
89
89
|
|
|
90
90
|
${n}`:`Sort by ${t}`,onClick:()=>s(U8(r,e)),children:[t,o.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:l==="none"?"":l==="ascending"?"↑":"↓"})]})})}const Z8=3e3;function Q8(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function J8(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}% ${eB(t.lastMs,n)}`:"running at full speed, and never held back"}}function eB(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 ru(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 tB(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 nB(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 rB(){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,Z8))},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 AS({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 sB({usageOpen:e,leaving:t,onClose:n}){const r=rB();if(!r||r.cpu==null||!r.memory)return o.jsx(AS,{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(AS,{usageOpen:e,leaving:t,sub:`up ${tB(p)} · ${f} cores`,flag:nB(r),onClose:n,children:[o.jsx(aB,{cpu:v,perCore:c,loadavg:u,cores:f}),o.jsx(oB,{memory:s,swap:l,platform:h}),y&&o.jsx(iB,{network:y}),o.jsx(uB,{thermal:m}),o.jsx(dB,{sys:r})]})}function aB({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(Ru,{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(Ru,{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(I0,{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 oB({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(Ru,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[o.jsx(ef,{label:"Physical",value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:ru(r)})," of ",ru(e.total)]}),pct:e.usedPct,tone:e.usedPct>=90?"warn":"calm",note:`${ru(e.available)} available`}),t&&t.total>0&&o.jsx(ef,{label:s,value:o.jsxs(o.Fragment,{children:[o.jsx("b",{children:ru(t.used)})," of ",ru(t.total)]}),pct:l,tone:l>=90?"warn":"calm"})]})})}function iB({network:e}){const{down:t,up:n,api:r,route:s}=e,[l,c]=w.useState(!1),u=r&&r.ms!=null?Rf(r.ms):null,f=t!=null&&n!=null;return o.jsxs("div",{className:"sd-section",role:"group","aria-label":"Network",children:[o.jsxs(Ru,{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=Mb(h);return o.jsx(I0,{value:m.value,unit:m.unit,cap:p},p)}),u&&o.jsx(I0,{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(cB,{route:s,api:r,onClose:()=>c(!1)})]})]})}function I0({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 lB(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 cB({route:e,api:t,onClose:n}){return o.jsxs(M0,{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 ",lB(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`:`${Tu(Rf(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 Ru({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(T8,{group:e,title:t,onClose:()=>f(!1)})]})}function uB({thermal:e}){if(!e)return null;const t=e.throttle?J8(e.throttle.speedLimit,e.heldBack):null;return o.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:o.jsxs(Ru,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>o.jsx(ef,{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:Q8(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(ef,{label:"Throttling",value:o.jsx("b",{children:t.value}),pct:t.pct,tone:t.tone,note:t.note})]})})}function dB({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(X8,{sys:e,onClose:()=>n(!1)})]})}function ef({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 MS(e){return{inputTokens:e.i,outputTokens:e.o,cacheReadTokens:e.cr,cacheCreateTokens:e.cc,cacheCreate1hTokens:e.c1h,cacheCreate5mTokens:e.c5m}}function IS(e){let t=0;for(const n of Object.values(e))t+=n.i+n.o+n.cr+n.cc;return t}function hB(e,t,n,r=Date.now()){const s=n.size>0,l=new Map;for(const[E,C]of n){const R=E.indexOf("|"),I=E.slice(0,R),O=E.slice(R+1),H=ri(C.usage,O,r).total,q=H>0?C.cost/H:1;let $=l.get(I);$||($=new Map,l.set(I,$)),$.set(O,q)}const c=(E,C)=>{const R=l.get(E);return(R==null?void 0:R.get(C))??(R==null?void 0:R.get(Ql(C)))??1},u=(E,C)=>{let R=0;for(const[I,O]of Object.entries(E))R+=ri(MS(O),I,r).total*c(C,I);return R},f=new Map,p=[];for(const E of e){const C=new Map;let R=0;for(const I of E.projects){const O=u(I.models,E.day);C.set(I.path,(C.get(I.path)??0)+O),R+=O;let H=f.get(I.path);H||(H={path:I.path,cost:0,tokens:0},f.set(I.path,H)),H.cost+=O,H.tokens+=IS(I.models)}p.push({day:E.day,total:R,byPath:C})}const h=[...f.values()].sort((E,C)=>C.cost-E.cost||C.tokens-E.tokens),m=h.reduce((E,C)=>E+C.cost,0),y=h.reduce((E,C)=>E+C.tokens,0);let v=0,S=0;for(const E of n.values())v+=E.cost;for(const[E,C]of n)S+=ri(C.usage,E.slice(E.indexOf("|")+1),r).total;const b=S>0?v/S:1,_=t?IS(t):0;let k=0;if(t)for(const[E,C]of Object.entries(t))k+=ri(MS(C),E,r).total*b;const j=k>0||_>0?{cost:k,tokens:_}:null;return{projects:h,totalCost:m,totalTokens:y,perDay:p,unattributed:j,reconciled:s}}function DM(e){return/^[A-Za-z]:[\\/]$/.test(e)?e:e.replace(/[\\/]+$/,"")}function jm(e){const t=DM(e).replace(/\\/g,"/");return/^[A-Za-z]:\//.test(t)?t.toLowerCase():t}function $S(e){if(!e)return e;const t=DM(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 fB(e,t){const n=jm(e);let r;for(const s of t){const l=jm(s.path);!l||l===n||!n.startsWith(`${l}/`)||(!r||jm(r.path).length<l.length)&&(r=s)}return r==null?void 0:r.label}function $0(e){return e===0?"all time":e===1?"today":`the last ${e} days`}function pB(e){return e===1?"No work attributed to this account yet today.":`No work attributed to this account in ${$0(e)}.`}function mB(e){return e===1?7:e===7?30:e===30?0:null}function gB(e,t){return e!==1&&t>0}const yB=[{days:1,label:"Today"},{days:7,label:"7d"},{days:30,label:"30d"},{days:0,label:"All"}],bl=["var(--usage-blue)","var(--usage-green)","var(--usage-amber)","var(--usage-purple)","var(--usage-indigo)","var(--usage-red)","var(--usage-orange)","var(--usage-zinc)"],wB="var(--usage-zinc)",_m=6,vB=1600;function OS(e){return`${e.getFullYear()}${String(e.getMonth()+1).padStart(2,"0")}${String(e.getDate()).padStart(2,"0")}`}function xB(e){const t=ut(e),n=/^\$(\d{4,})$/.exec(t);return n?`$${Number(n[1]).toLocaleString("en-US")}`:t}function LS(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 bB(e){const t=/^\d{4}-(\d{2})-(\d{2})$/.exec(e);return t?`${Number(t[1])}/${Number(t[2])}`:e}function kB(e){const t=Math.max(1,Math.ceil(e/6));return n=>n===0||n===e-1||n%t===0}function Em(e){if(!e)return"";try{return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}catch{return""}}function NB({num:e,name:t,onClose:n}){const[r,s]=w.useState(1),[l,c]=w.useState(null),[u,f]=w.useState(r),[p,h]=w.useState(null),[m,y]=w.useState(null),[v,S]=w.useState(()=>new Set),[b,_]=w.useState(!0),[k,j]=w.useState(null),[E,C]=w.useState(null),R=w.useRef(void 0),I=w.useRef(!0);w.useEffect(()=>()=>{I.current=!1,window.clearTimeout(R.current)},[]);const O=w.useRef(null),H=pn(n,{focusRef:O}),q=w.useRef(0);w.useEffect(()=>{const D=++q.current;_(!0),j(null),y(null),S(new Set);const P=r===0?60:r,B=OS(new Date(Date.now()-(P-1)*864e5)),W=OS(new Date),F=fetch(`/api/account-projects?num=${e}&days=${r}`,{credentials:"same-origin"}).then(re=>re.ok?re.json():Promise.reject(new Error(`HTTP ${re.status}`))),G=fetch(`/api/ccusage?since=${B}&until=${W}`,{credentials:"same-origin"}).then(re=>re.ok?re.json():null).catch(()=>null);Promise.all([F,G]).then(([re,U])=>{if(D!==q.current)return;c(re),f(r);const Y=U;h(Y&&Y.ok!==!1?Y:null),_(!1)}).catch(re=>{D===q.current&&(j(re.message||"Could not load"),c(null),_(!1))})},[e,r]);const $=w.useMemo(()=>{const D=Date.now();if(!l)return null;const P=ue=>typeof ue=="number"&&Number.isFinite(ue)?ue:0,B=new Map;if(p){const ue=Array.isArray(p.days)?p.days:[];for(const se of ue){const be=typeof se.period=="string"?se.period:"",Le=Array.isArray(se.modelBreakdowns)?se.modelBreakdowns:[];for(const ce of Le){const pe=typeof ce.modelName=="string"?ce.modelName:"";if(!be||!/claude/i.test(pe))continue;const Ae=`${be}|${pe}`,fe=B.get(Ae),Se=fe?fe.usage:{inputTokens:0,outputTokens:0,cacheReadTokens:0,cacheCreateTokens:0,cacheCreate1hTokens:0,cacheCreate5mTokens:0};Se.inputTokens+=P(ce.inputTokens),Se.outputTokens+=P(ce.outputTokens),Se.cacheReadTokens+=P(ce.cacheReadTokens),Se.cacheCreateTokens+=P(ce.cacheCreationTokens),fe?fe.cost+=P(ce.cost):B.set(Ae,{cost:P(ce.cost),usage:Se})}}}const W=hB(l.daily??[],l.unattributed,B,D),F=ue=>ue.replace(/[\\/]+$/,"").split(/[\\/]/).pop()||ue||"(unknown)",G=new Map;for(const ue of W.projects)G.set(F(ue.path),(G.get(F(ue.path))??0)+1);const re=ue=>{const se=F(ue);if((G.get(se)??0)<=1)return se;const be=ue.replace(/[\\/]+$/,"").split(/[\\/]/).slice(-2,-1)[0];return be?`${be}/${se}`:se},U=W.projects.map(ue=>({path:ue.path,label:re(ue.path)})),Y=ue=>({path:ue.path,label:re(ue.path),parentLabel:fB(ue.path,U),cost:ue.cost,tokens:ue.tokens}),z=bl[_m%bl.length],ie=new Map,le=[],ge=W.projects.slice(0,_m),Ne=W.projects.slice(_m);ge.forEach((ue,se)=>{ie.set(ue.path,bl[se%bl.length]),le.push({key:ue.path,...Y(ue),color:bl[se%bl.length]})}),Ne.length&&le.push({key:"__other__",label:`Other · ${Ne.length} project${Ne.length>1?"s":""}`,cost:Ne.reduce((ue,se)=>ue+se.cost,0),tokens:Ne.reduce((ue,se)=>ue+se.tokens,0),color:z,muted:!0,members:Ne.map(Y)});const Ie=W.totalCost,Ge=W.totalTokens,Pe=Ie>0?"cost":"tokens",Be=Pe==="cost"?Ie:Ge,Te=le.map(ue=>ue.color),st=W.perDay.map(ue=>{const se=new Map;for(const[be,Le]of ue.byPath){const ce=ie.get(be)??z;se.set(ce,(se.get(ce)??0)+Le)}return{day:ue.day,total:ue.total,costByColor:se}}),de=st.reduce((ue,se)=>Math.max(ue,se.total),0);return{rows:le,totalCost:Ie,totalTokens:Ge,basis:Pe,denom:Be,un:W.unattributed,reconciled:W.reconciled,chart:st,maxDay:de,colorOrder:Te}},[l,p]),V=(D,P)=>{hi(D).then(B=>{I.current&&(window.clearTimeout(R.current),C({path:D,label:P,ok:B}),R.current=window.setTimeout(()=>{I.current&&C(null)},vB))})},ne=D=>E!=null&&E.ok&&E.path===D?"Copied":"Copy",ee=l!=null&&l.trackedSince?`Tracked since ${Em(l.trackedSince)}`:"Tracking starts with this version",M=$0(u),Z=mB(u),K=b&&!!l;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:o.jsxs("div",{ref:H,className:"modal ap-proj-modal",onClick:D=>D.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:yB.map(D=>o.jsx("button",{type:"button",className:"uh-range-btn","aria-pressed":r===D.days,onClick:()=>s(D.days),children:D.label},D.days))}),o.jsx("button",{ref:O,className:"glyph-btn ap-proj-close",onClick:n,"aria-label":"Close",children:"×"})]}),o.jsxs("div",{className:`ap-proj-body${K?" refreshing":""}`,"aria-busy":b,children:[b&&!l&&o.jsx("div",{className:"ap-proj-state",children:"Loading…"}),!b&&k&&o.jsxs("div",{className:"ap-proj-state ap-proj-error",children:["Couldn’t load this report: ",k]}),!k&&$&&o.jsx(o.Fragment,{children:$.rows.length===0?o.jsxs("div",{className:"ap-proj-state",children:[pB(u),Z!=null&&o.jsx("div",{className:"ap-proj-widen-wrap",children:o.jsxs("button",{type:"button",className:"ap-proj-copy",onClick:()=>s(Z),children:["Show ",$0(Z)]})}),o.jsxs("div",{className:"ap-proj-note",children:[ee,". 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":`Share of ${ut($.totalCost)} across ${$.rows.length} projects`,children:$.rows.map(D=>{const P=$.basis==="cost"?D.cost:D.tokens,B=$.denom>0?P/$.denom*100:0;return B<=0?null:o.jsx("span",{className:"ap-proj-seg",style:{width:`${B}%`,background:D.color},title:`${D.label} · ${ut(D.cost)} · ${LS(D.cost,$.totalCost)}${D.tokens?` · ${Bt(D.tokens)} tokens`:""}`},D.key)})}),o.jsxs("div",{className:"ap-proj-totals",children:[o.jsx("span",{className:"ap-proj-total-cost",children:ut($.totalCost)}),o.jsxs("span",{className:"ap-proj-total-tok",children:[Bt($.totalTokens)," tokens"]}),o.jsxs("span",{className:"ap-proj-total-win",children:["· ",M]})]}),gB(u,$.chart.length)&&o.jsxs("div",{className:"ap-proj-days",children:[o.jsxs("div",{className:"ap-proj-days-cap",children:["By day",$.chart.length>1?" · click a bar":""]}),o.jsx("div",{className:"ap-proj-days-plot",role:"img","aria-label":`Spend across ${$.chart.length} day${$.chart.length>1?"s":""}`,children:$.chart.map(D=>{const P=$.maxDay>0?D.total/$.maxDay*100:0,B=m===D.day,W=$.rows.map(G=>({label:G.label,c:D.costByColor.get(G.color)??0})).filter(G=>G.c>0),F=`${Em(Date.parse(`${D.day}T00:00:00`))}, ${ut(D.total)}. ${W.map(G=>`${G.label} ${ut(G.c)}`).join(", ")}`;return o.jsx("button",{type:"button",className:`ap-proj-day${B?" selected":""}`,"aria-pressed":B,"aria-label":F,title:`${D.day} · ${ut(D.total)}`,onClick:()=>y(G=>G===D.day?null:D.day),children:o.jsx("span",{className:"ap-proj-col",style:{height:`${P}%`},children:$.colorOrder.map((G,re)=>{const U=D.costByColor.get(G)??0;return U<=0||D.total<=0?null:o.jsx("span",{className:"ap-proj-colseg",style:{height:`${U/D.total*100}%`,background:G}},re)})})},D.day)})}),(()=>{const D=kB($.chart.length);return o.jsx("div",{className:"ap-proj-days-axis","aria-hidden":"true",children:$.chart.map((P,B)=>o.jsx("div",{className:"ap-proj-axis-cell",children:D(B)?bB(P.day):""},P.day))})})(),(()=>{const D=m?$.chart.find(B=>B.day===m):null;if(!D)return null;const P=$.rows.map(B=>({r:B,c:D.costByColor.get(B.color)??0})).filter(B=>B.c>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:Em(Date.parse(`${D.day}T00:00:00`))}),o.jsx("span",{className:"ap-proj-day-detail-total",children:ut(D.total)})]}),P.map(({r:B,c:W})=>o.jsxs("div",{className:"ap-proj-day-detail-row",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:B.color},"aria-hidden":"true"}),o.jsx("span",{className:"ap-proj-day-detail-name",children:B.label}),o.jsx("span",{className:"ap-proj-day-detail-cost",children:ut(W)})]},B.key))]})})()]}),o.jsx("ul",{className:"ap-proj-list",children:$.rows.map((D,P)=>{const B=$.basis==="cost"?D.cost:D.tokens,W=$.denom>0?B/$.denom*100:0,F=v.has(D.key),G=`ap-proj-details-${P}`,re=F&&(!!D.path||!!D.members),U=D.members?`${F?"Hide":"Show"} the ${D.members.length} project${D.members.length>1?"s":""} folded into Other`:`${F?"Hide":"Show"} location for ${D.label}`;return o.jsxs("li",{className:`ap-proj-row${D.muted?" muted":""}${F?" expanded":""}`,children:[o.jsx("span",{className:"ap-proj-dot",style:{background:D.color},"aria-hidden":"true"}),o.jsxs("span",{className:"ap-proj-name",children:[D.label,D.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",D.parentLabel]})]}),o.jsx("span",{className:"ap-proj-track",title:`${LS(D.cost,$.totalCost)} of tracked cost`,children:o.jsx("span",{className:"ap-proj-fill",style:{width:`${W}%`,background:D.color}})}),o.jsx("span",{className:"ap-proj-cost",children:ut(D.cost)}),o.jsx("span",{className:"ap-proj-tok",children:Bt(D.tokens)}),o.jsx("button",{type:"button",className:"glyph-btn ap-proj-info","aria-expanded":F,"aria-controls":re?G:void 0,"aria-label":U,onClick:()=>S(Y=>{const z=new Set(Y);return z.has(D.key)?z.delete(D.key):z.add(D.key),z}),children:"ⓘ"}),F&&D.path&&o.jsxs("div",{className:"ap-proj-details",id:G,children:[o.jsx("code",{className:"ap-proj-path",children:$S(D.path)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${ne(D.path)} location for ${D.label}`,onClick:()=>V(D.path,D.label),children:ne(D.path)})]}),F&&D.members&&o.jsx("div",{className:"ap-proj-details ap-proj-other-members",id:G,children:D.members.map(Y=>o.jsxs("div",{className:"ap-proj-other-member",children:[o.jsxs("div",{className:"ap-proj-other-name",children:[Y.label,Y.parentLabel&&o.jsxs("span",{className:"ap-proj-parent",children:[" · in ",Y.parentLabel]})]}),o.jsx("code",{className:"ap-proj-path",children:$S(Y.path)}),o.jsx("span",{className:"ap-proj-cost",children:ut(Y.cost)}),o.jsx("span",{className:"ap-proj-tok",children:Bt(Y.tokens)}),o.jsx("button",{type:"button",className:"ap-proj-copy","aria-label":`${ne(Y.path)} location for ${Y.label}`,onClick:()=>V(Y.path,Y.label),children:ne(Y.path)})]},Y.path))})]},D.key)})}),$.un&&o.jsxs("div",{className:"ap-proj-unattributed",children:[o.jsx("span",{className:"ap-proj-dot",style:{background:wB},"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",children:xB($.un.cost)}),o.jsx("span",{className:"ap-proj-un-tok",children:Bt($.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:E&&(E.ok?`Copied the location of ${E.label}`:`Could not copy the location of ${E.label} — select it and copy it by hand`)}),o.jsxs("div",{className:"ap-proj-foot",children:[$.reconciled?"Dollars from ccusage · split by activity":"Dollars estimated · ccusage unavailable"," · ",ee]})]})})]})]})}),document.body)}const PS=18,SB=1100,kl=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},jB=Array.from({length:PS},(e,t)=>{const n=-72+144*t/(PS-1)+(kl(t,1)-.5)*9,r=(n-90)*(Math.PI/180),s=(54+32*Math.cos(n*Math.PI/180))*(.74+kl(t,2)*.52);return{dx:Math.cos(r)*s,dy:Math.sin(r)*s,rot:(t%2?1:-1)*(100+kl(t,3)*260),delay:Math.round(kl(t,4)*90),dur:760+Math.round(kl(t,5)*260),scale:.8+kl(t,6)*.45,hue:t%4,round:t%3===0}});function DS({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),SB);return()=>window.clearTimeout(u)},[e,r]),r||!t?null:Mn.createPortal(o.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:jB.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 FM=new Set(["awaiting_url","awaiting_code","registering"]);function _B(e){return e!=null&&FM.has(e)}function qM(e){return e!=null&&e!=="done"&&!FM.has(e)}const EB="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",CB="the sign-in did not complete";function TB({state:e,serverError:t,localError:n}){const r=e==="idle";return{title:r?"Sign-in ended":"Sign-in failed",message:n||t||(r?EB:CB)}}function RB({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 AB({started:e,state:t}){return!e||t==="done"?null:{action:"login-cancel"}}const MB="done";function IB(){let e=!1;return{shouldAnnounce(t){return t!==MB?(e=!1,!1):e?!1:(e=!0,!0)}}}function Ob(e,t){return t&&Object.hasOwn(e,t)?e[t]:void 0}const $B={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 ${dn}`,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"},OB={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"},Lb=`claude-swap could not read the login keychain — start ${dn} from a Terminal window rather than a background service`,FS={unreadable_here:{short:"Keychain locked on this Mac",long:`${Lb}.`},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 tf(e){return e&&Object.hasOwn(FS,e)?FS[e]:null}const BM={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 O0(e,t,n){const r=n==null?null:BM[n];if(r)return r;if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(Au(e)))return Lb;const s=Ob(OB,e==null?void 0:e.reason);return s||(e==null?void 0:e.reason)||t}function Au(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const LB={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"},PB="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 DB(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const FB="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",qB="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",BB=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),zB=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,UB=/[\\/]_npx[\\/]/i,HB=`the copy of ccusage ${dn} installed for itself`;function WB(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function ZX(e,t){const n=VB(e,t),r=WB(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 ${su(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${su(n)}`;case"managed":return`${HB} failed to run: ${su(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${su(n)}`:`the ccusage this deck found on your PATH failed to run: ${su(n)}`;default:return n}}const su=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function VB(e,t){const n=Au(e);if(BB(n)){if(UB.test(n))return qB;if(zB.test(n))return FB}if(DB(n))return PB;const r=Ob(LB,e==null?void 0:e.reason);return r||(e==null?void 0:e.reason)||t}function Al(e,t,n){const r=n==null?null:BM[n];if(r)return r;if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&qM(e.state))return e.error;const s=Ob($B,e==null?void 0:e.reason);return s||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function GB(e,t,n){if(n<=0||Nf(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 zM(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 KB(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 YB(e,t){return e.filter(n=>!t.includes(n.num)).map(n=>n.num)}function XB(e,t){return e.includes(t)?e.filter(n=>n!==t):[...e,t]}function ZB(e){return e.length?{action:"share",accounts:[...e]}:null}function QB(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 L0(e){return`${e.email}|${e.org??""}`}function JB(e,t,n){return e&&e.map(r=>L0(r)===t?n:r)}function ez(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 tz(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=tf(h.check))==null?void 0:m.short}).filter(h=>!!h))];return`${r.join(", ")}${p.length?`, ${p.join(", ")}`:""}.`}const nz=1500,vh=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],qS="aa-panel",BS=e=>`aa-tab-${e}`;async function au(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const P0=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"})]}));P0.displayName="SuccessMark";function rz({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),O=w.useRef(null),H=w.useRef(null),q=w.useRef(null),$=w.useRef(null),V=w.useRef([]),ne=w.useRef(!1),ee=w.useCallback(()=>{const z=AB({started:R.current,state:s==null?void 0:s.state});z&&au(z).catch(()=>{}),e()},[e,s==null?void 0:s.state]),M=pn(ee,{focusRef:q}),Z=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null),R.current=!0;const z=await au({action:"login"}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"could not start the sign-in"));return}l(z)},[]);w.useEffect(()=>{if(!_B(s==null?void 0:s.state))return;const z=window.setInterval(async()=>{try{const ie=await fetch("/api/claude-accounts/login");ie.ok&&l(await ie.json())}catch{}},nz);return()=>window.clearInterval(z)},[s]);const K=w.useRef(t);K.current=t;const D=w.useState(IB)[0];w.useEffect(()=>{var z;(s==null?void 0:s.state)==="awaiting_code"&&((z=O.current)==null||z.focus()),D.shouldAnnounce(s==null?void 0:s.state)&&K.current()},[s==null?void 0:s.state,D]),w.useEffect(()=>{var z;n==="paste"&&!ne.current&&((z=H.current)==null||z.focus()),ne.current=!1},[n]);const P=w.useCallback(z=>{var le;const ie=GB(z,vh.findIndex(ge=>ge.id===n),vh.length);ie.kind!=="pass"&&(z.preventDefault(),ne.current=!0,r(vh[ie.index].id),(le=V.current[ie.index])==null||le.focus())},[n]),B=w.useCallback(async()=>{var ie;if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const z=await au({action:"login-code",code:c}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"the code was not accepted")),z!=null&&z.state&&l(z),(ie=O.current)==null||ie.select();return}u(""),l(z)},[c,s]),W=w.useCallback(async()=>{if(!Ps(I.current))return;I.current=!0,m(!0),v(null);const z=await au({action:"import",blob:f}).catch(()=>null);if(I.current=!1,m(!1),!(z!=null&&z.ok)){v(Al(z,"the import failed"));return}C.current=f,p(""),E(null),b(z.results??[]),t()},[f,t]),F=w.useCallback(async z=>{const ie=L0(z);if(!Ps(I.current)||!C.current)return;I.current=!0,m(!0),k(ie),E(null);const le=await au({action:"import",blob:C.current,force:!0,only:{email:z.email,org:z.org??""}}).catch(()=>null);if(I.current=!1,m(!1),k(null),!(le!=null&&le.ok)){E({key:ie,text:Al(le,"that account could not be updated")});return}const ge=(le.results??[])[0];ge&&b(Ne=>JB(Ne,ie,ge)),t()},[t]),G=(s==null?void 0:s.state)==="done"?s.account:null,re=RB({restored:s==null?void 0:s.restored,activeAccount:s==null?void 0:s.activeAccount}),U=qM(s==null?void 0:s.state)||!!(y&&R.current&&!h),Y=TB({state:s==null?void 0:s.state,serverError:s==null?void 0:s.error,localError:y});return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:ee,role:"presentation",children:o.jsxs("div",{ref:M,className:"modal aa-modal",onClick:z=>z.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:P,children:vh.map((z,ie)=>o.jsx("button",{type:"button",role:"tab",id:BS(z.id),ref:le=>{V.current[ie]=le},"aria-selected":n===z.id,"aria-controls":qS,tabIndex:n===z.id?0:-1,className:`aa-tab${n===z.id?" on":""}`,onClick:()=>{ne.current=!1,r(z.id)},children:z.label},z.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:qS,role:"tabpanel","aria-labelledby":BS(n),children:n==="login"?G?o.jsxs("div",{className:"aa-done",children:[o.jsx(P0,{ref:$}),o.jsx(DS,{anchor:$}),o.jsx("h4",{children:G.added?`Account ${G.num} added`:"Credentials refreshed"}),o.jsxs("p",{className:"aa-note",children:[o.jsx("strong",{children:G.email}),G.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:O,type:"text",value:c,onChange:z=>u(z.target.value),onKeyDown:z=>{z.key==="Enter"&&c.trim()&&!h&&B()},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",...Qa(h,!c.trim()||s.state==="registering"),onClick:B,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."})]})]}):U?o.jsxs("div",{className:"aa-step",children:[o.jsx("h4",{children:Y.title}),o.jsx("p",{className:"aa-err",children:Y.message}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{R.current=!1,l(null),v(null),Z()},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:q,className:"btn primary",onClick:Z,children:"Open the sign-in page"})})]}):S?(()=>{const z=S.filter(le=>le.state==="imported").length,ie=S.some(le=>tf(le.check));return o.jsxs("div",{className:"aa-done",children:[!ie&&o.jsx(P0,{ref:$}),z>0&&!ie&&o.jsx(DS,{anchor:$}),o.jsx("h4",{children:tz(S)}),S.length>0&&o.jsx("ul",{className:"aa-results",children:S.map(le=>{const ge=L0(le),Ne=tf(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:ez(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:()=>F(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:H,type:"text",value:f,onChange:z=>p(z.target.value),onKeyDown:z=>{z.key==="Enter"&&f.trim()&&!h&&W()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),o.jsx("button",{type:"button",className:"btn primary",...Qa(h,!f.trim()),onClick:W,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 sz=6;function az(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?oz(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 oz(e){const t=e.map(n=>n.headroom).filter(n=>typeof n=="number");return t.length?Math.max(...t):null}function iz(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,sz),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 UM({title:e,steps:t,finish:n,aside:r,onClose:s}){const l=w.useRef(null),c=pn(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 Mn.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 D0={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function Br({children:e}){return o.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function qr({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 ys({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:D0[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 ${D0[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 HM({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 xh({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 zS({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 US({x:e,y:t,d:n}){return o.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function Pb({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 Db(){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 Ml({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:D0[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 Pl({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 nf({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(HM,{x:e+118,y:t-13,on:!0})]})}function lz(){return o.jsxs(Br,{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 cz(){return o.jsxs(Br,{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(Ml,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),o.jsx(Ml,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),o.jsx(Ml,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),o.jsx(Ml,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),o.jsx(Pl,{x:326,y:28,label:"Read"}),o.jsx(Pl,{x:380,y:28,label:"Grep",live:!0}),o.jsx(Pl,{x:326,y:90,label:"Bash",live:!0})]})}function HS({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 uz(){return o.jsxs(Br,{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(HS,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),o.jsx(HS,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function dz(){return o.jsxs(Br,{children:[o.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),o.jsx(Ml,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),o.jsx(Pb,{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(qr,{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(Pl,{x:214,y:122,label:"Read"}),o.jsx(Pl,{x:266,y:122,label:"Edit"}),o.jsx(Pl,{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 hz(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return o.jsxs(Br,{children:[o.jsx(qr,{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 fz(){return o.jsxs(Br,{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(Ml,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function pz(){return o.jsxs(Br,{children:[o.jsx(qr,{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(US,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),o.jsx(US,{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(ys,{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(ys,{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(Pb,{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(qr,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),o.jsx("g",{className:"ga-pop",children:o.jsx(ys,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function mz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(nf,{x:28,y:60}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ys,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ys,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(nf,{x:264,y:60}),o.jsx(ys,{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(Db,{})})]})}const gz=[{art:o.jsx(lz,{}),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(cz,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:o.jsx(dz,{}),line:"Double-click any node: its prompt, every tool call, tokens and timing."},{art:o.jsx(uz,{}),line:"What each session costs, and how much quota is left."},{art:o.jsx(hz,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:o.jsx(pz,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:o.jsx(mz,{}),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(fz,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function yz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(ys,{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(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ys,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function wz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx(nf,{x:28,y:60}),o.jsx(xh,{x:28,y:92,name:"Ana's MacBook"}),o.jsx(xh,{x:28,y:114,name:"Dorin's PC"}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(nf,{x:264,y:60}),o.jsx(xh,{x:264,y:92,name:"Your MacBook"}),o.jsx(xh,{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 vz(){return o.jsxs(Br,{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(zS,{x:106,y:88,on:!0}),o.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),o.jsx(zS,{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(HM,{x:304,y:157,on:!0}),o.jsx(Pb,{x:115,y:97})]})}function xz(){return o.jsxs(Br,{children:[o.jsx(qr,{x:14,label:"THIS MACHINE"}),o.jsx("g",{className:"ga-swap-out",children:o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),o.jsx("g",{className:"ga-swap-in",children:o.jsx(ys,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),o.jsx(qr,{x:250,label:"ANOTHER MACHINE"}),o.jsx(ys,{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(Db,{})})]})}const bz=[{art:o.jsx(yz,{}),line:"A login can expire on one machine while it still works on another."},{art:o.jsx(wz,{}),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(vz,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:o.jsx(xz,{}),line:"An expired login is copied from a paired machine within a minute."}];function kz(){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(Db,{})})]})}const Nz={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."},Sz=1600;function WM({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 hi(l.join(`
|
|
91
91
|
`))&&s.current&&(r(!0),window.setTimeout(()=>{s.current&&r(!1)},Sz))},[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:Nz[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 Cm(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const jz={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."},_z={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function WS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||un(n,t)}function Ez({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=pn(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,O]=w.useState(()=>Date.now());w.useEffect(()=>{const re=window.setInterval(()=>O(Date.now()),1e3);return()=>window.clearInterval(re)},[]);const H=w.useRef(!0);w.useEffect(()=>()=>{H.current=!1},[]);const q=w.useRef(null),$=w.useCallback(re=>Tf(q.current)?(q.current=re,E(re),!0):!1,[]),V=w.useCallback(()=>{q.current=null,H.current&&E(null)},[]),ne=re=>{const U=ao(j,re);return{disabled:U.disabled,"aria-busy":U.busy}},ee=re=>(S==null?void 0:S.field)===re?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},M=re=>b(U=>U&&U.field===re?null:U),Z=w.useCallback(async()=>{if(f)return;const re=zz(h);if(!re){b({text:Cz(h),field:"addr"});return}const U=`${re.addr}:${re.port}`,Y=e.peers.find(z=>z.addr===re.addr&&z.port===re.port&&z.paired);if(Y){b({text:`Already paired with ${Y.name} at that address.`,field:"addr"});return}if(t.includes(U)){b({text:"This deck already calls that address.",field:"addr"});return}if($("add"))try{const z=await Cm("/api/prefs",{lan:{manual:[...t,U]}});if(!H.current)return;z!=null&&z.ok?(b(null),m(""),s(),r()):b({text:un("add that address",z),field:"addr"})}catch{H.current&&b({text:un("add that address",null),field:"addr"})}finally{V()}},[h,f,t,e.peers,s,r,$,V]),K=w.useCallback(async re=>{if(!$(`invite:${re}`))return;const U=re==="make"?"make an invite":"cancel that invite";try{const Y=await Cm("/api/lan/invite",{action:re});if(!H.current)return;Y!=null&&Y.ok?(b(null),k(null),s()):b({text:WS(_z,Y,U)})}catch{H.current&&b({text:un(U,null)})}finally{V()}},[s,$,V]),D=w.useCallback(async()=>{const re=y.trim();if(!(!re||!$("join"))){R(null);try{const U=await Cm("/api/lan/invite",{action:"join",token:re});if(!H.current)return;U!=null&&U.ok?(v(""),b(null),s(),r()):(U==null?void 0:U.reason)==="unreachable"&&Array.isArray(U.tried)&&U.tried.length?(R(U.tried),b(null)):(R(null),b({text:WS(jz,U,"use that invite"),field:"join"}))}catch{H.current&&b({text:un("use that invite",null),field:"join"})}finally{V()}}},[y,s,r,$,V]),P=w.useCallback(async(re,U)=>{try{await navigator.clipboard.writeText(re),k(U),window.setTimeout(()=>{H.current&&k(Y=>Y===U?null:Y)},1600)}catch{b({text:"Could not copy it — select the text and copy it by hand."})}},[]),B=e.invite&&e.invite.expiresAt>I?e.invite:null,W=w.useRef(!1);w.useEffect(()=>{n!=="invite"||W.current||B||(W.current=!0,K("make"))},[n,B,K]);const F=w.useRef(!1);w.useEffect(()=>{var re;n!=="invite"||F.current||!B||(F.current=!0,(re=u.current)==null||re.focus())},[n,B]);const G=e.port!=null?(e.addrs??[]).map(re=>`${re}:${e.port}`):[];return Mn.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(WM,{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"&&Z()}}),h.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("add"),onClick:()=>void Z(),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&&G.length>0&&o.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",G.map((re,U)=>o.jsxs("span",{children:[U>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 P(G.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",!B&&o.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...ne("invite:make"),onClick:()=>void K("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"&&D()}}),y.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("join"),onClick:()=>void D(),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))]}),B&&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:[Yz(B.expiresAt,I)," left"]})]}),o.jsx("code",{className:"ap-lan-token",children:B.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 P(B.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 K("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 Cz(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 Tz=1e3;function Rz(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 VS(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function Az(){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 GS(){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 bh({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 Mz={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},Iz={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function $z(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Mz[e.here]}, ${Iz[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Oz({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 Ot,zt,Xt,Dt,rn;const S=w.useRef(null),b=pn(c,{focusRef:S}),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(!1),I=w.useRef(0),[O,H]=w.useState(null),[q,$]=w.useState(!1),[V,ne]=w.useState(0),ee=w.useRef(null),M=w.useRef(!0);w.useEffect(()=>()=>{M.current=!1},[]);const Z=_!=null;w.useEffect(()=>{var je;Z&&((je=ee.current)==null||je.select())},[Z]),w.useEffect(()=>{if(!C)return;const je=window.setTimeout(()=>R(!1),4e3);return()=>window.clearTimeout(je)},[C]),w.useEffect(()=>{if(!O)return;const je=window.setTimeout(()=>H(null),4e3);return()=>window.clearTimeout(je)},[O]);const K=je=>{const xt=ao(l,je);return{disabled:xt.disabled,"aria-busy":xt.busy}},D=async je=>{const xt=await je();return M.current&&E(xt),xt==null},{peer:P,stranger:B}=t,W=e.kind==="paired",F=e.self??e.name,G=e.kind!=="dialling",re=e.kind==="dialling"?null:e.fp,U=P?P.addr?`${P.addr}:${P.port}`:"":B?B.port?`${B.addr}:${B.port}`:B.addr:e.addr,Y=(P==null?void 0:P.about)??null,z=((Ot=n.about)==null?void 0:Ot.version)??null,ie=async je=>{const xt=je.trim()===F?"":je;await D(()=>u(xt))&&k(null)},le=async()=>{if(re)try{if(await navigator.clipboard.writeText(re),!M.current)return;$(!0),window.setTimeout(()=>{M.current&&$(!1)},1600)}catch{M.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},ge=W?P!=null&&P.waiting?P.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":P!=null&&P.offers?"not said — it runs an older version":"not reached yet":"shown once paired",Ne=VS(n.about),Ie=VS(Y),Ge=Y!=null&&Y.version&&z?sU(Y.version,z):null,Pe=P?qb(P.last,s):null,Be=P&&((zt=P.last)!=null&&zt.error)?Bz({error:P.last.error,host:P.addr,port:P.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(je=>!je.manual&&je.addr).map(je=>({fp:je.fp,name:je.name,addr:je.addr,port:je.port,at:je.lastSeen??0}))],s):null,Te=(Xt=P==null?void 0:P.last)!=null&&Xt.error&&Pe&&Pe.text!==P.last.error?P.last.error:null,st=((Dt=P==null?void 0:P.last)==null?void 0:Dt.done)??[],de=!!Pe&&!!Te&&!e.quiet&&e.state.startsWith(Pe.text),ue=W||e.kind==="dialling",se=((P==null?void 0:P.via)??e.via)==="tailscale",be=P?P.waiting?null:P.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":W?e.here?"up":"down":"loose",ce=l===`check:${e.fp}`,pe=(P==null?void 0:P.offers)??null,Ae=Le==="up"?(pe==null?void 0:pe.current)??null:null,fe=Ae&&"key"in Ae?Ae.key:null,Se=!!Ae&&"hidden"in Ae,Ye=!!Ae&&"other"in Ae,qe=W?oU((pe==null?void 0:pe.accounts)??null,r,n.shared??[],fe):[],ke=qe.filter(je=>je.in==null&&je.out==="cut"),Re=qe.some(je=>je.in!=null),ze=qe.some(je=>je.out!=null),Fe=new Map(st.map(je=>[je.email,je])),We=st.filter(je=>!qe.some(xt=>xt.email===je.email)),rt=W?pe?pe.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:P!=null&&P.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=P==null?void 0:P.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,dt=pe&&(P!=null&&P.last)&&P.last.at-pe.at>Tz?qs(pe.at,s):null,ct=[];W&&(P!=null&&P.pairedAt)?ct.push({label:"Paired",value:Rz(P.pairedAt,s),tone:"meta"}):e.kind==="declined"&&B&&ct.push({label:"Paired",value:`no · you said no ${Bb(B.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":q?"Fingerprint copied":"Copy the fingerprint",children:q?"copied":"copy"})]}):"not known — nothing has answered there",tone:re?void 0:"quiet"});const yt=y.length?[{row:e,peer:P??null},...y]:[];return Mn.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:je=>je.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:[Z?o.jsxs("form",{className:"lan-peer-edit",onSubmit:je=>{je.preventDefault(),ie(_??"")},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:F,"aria-label":"Name for this deck, shown on this deck only",onChange:je=>k(je.target.value)}),o.jsx("button",{type:"submit",className:"ap-manage-btn",...K(`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}),G&&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(Az,{})})]}),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}),Z&&o.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...K(`alias:${e.fp}`),onClick:()=>void ie(""),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":ce||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}),W&&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??(Y?"not said":ge),Ge?` · ${Ge<0?"older":"newer"}`:null]}),Se&&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(GS,{}),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:U?o.jsx("code",{className:"ap-lan-code",children:U}):"none here — it calls this deck"})]}),o.jsx(GS,{}),(U&&be||ue)&&o.jsxs("p",{className:"lan-link-sub",children:[U&&be,U&&be&&ue&&" · ",ue&&(Pe?de?o.jsx("code",{className:"ap-lan-code",children:Te}):o.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),ue&&Te&&!de&&o.jsx("code",{className:"lan-fact-raw",children:Te})]}),We.length>0&&o.jsx("ul",{className:"lan-done",children:We.map(je=>{const xt=F0(je);return o.jsxs("li",{"data-ok":je.ok&&!xt,children:[je.email," ",o.jsxs("span",{className:"lan-done-what",children:[je.ok?"arrived":"did not arrive",xt&&` — ${xt.long}`]})]},`${je.email}:${je.action}`)})}),Be&&o.jsx("p",{className:"lan-note lan-link-note",children:Be}),(P==null?void 0:P.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((je,xt)=>{const bt=Fe.get(je.email),_n=bt?F0(bt):null,Ut=je.out==="live"||je.in!=null&&je.in!=="cut";return o.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":je.tone,"data-draw":je.in&&je.out?"both":je.in?"in":"out","data-used-there":je.usedThere||void 0,style:{"--i":xt},children:[o.jsx("i",{className:"lan-pip","data-end":"here","data-state":je.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:[(je.in==="live"||je.in==="wait")&&o.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":je.in}),je.out==="live"&&o.jsx("i",{className:"lan-glint","data-dir":"out"})]}),je.in&&je.in!=="cut"&&o.jsx(bh,{dir:"in",gate:je.in==="blocked"}),je.out==="live"&&o.jsx(bh,{dir:"out"}),o.jsx("span",{className:"lan-lane-email",children:je.email})]}),o.jsx("i",{className:"lan-pip","data-end":"there","data-state":je.there,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:$z(je)}),(je.caption||bt)&&o.jsxs("span",{className:"lan-lane-note",children:[je.caption,je.caption&&bt&&" · ",bt&&o.jsxs("span",{className:"lan-lane-done","data-ok":bt.ok&&!_n,children:[bt.ok?"arrived last round":"did not arrive last round",_n&&` — ${_n.long}`]})]})]},je.key)})},V),W&&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}),dt&&o.jsxs("p",{className:"lan-stale",children:["As of ",dt==="now"?"just now":dt,", when it last answered."]}),o.jsxs("div",{className:"lan-legend",children:[Re&&o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:o.jsx(bh,{dir:"in"})}),"from ",e.name]}),ze?o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:o.jsx(bh,{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(je=>o.jsxs("div",{className:"lan-fact","data-tone":je.tone,children:[o.jsx("dt",{children:je.label}),o.jsx("dd",{children:je.value})]},je.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((je,xt)=>{var Lt,Zt,In,Hr;const bt=(Lt=je.peer)!=null&&Lt.addr?`${je.peer.addr}:${je.peer.port}`:je.row.addr,_n=bt||je.row.fp,Ut=(Zt=je.peer)!=null&&Zt.pairedAt?qs(je.peer.pairedAt,s):null,Vn=[(Hr=(In=je.peer)==null?void 0:In.about)!=null&&Hr.version?`runs ${je.peer.about.version}`:null,Ut?`paired ${Ut==="now"?"just now":Ut}`:null,je.row.state].filter(Boolean).join(" · "),Vt=je.row.fp;return o.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":je.row.tone,children:[o.jsx("i",{className:je.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),bt?o.jsx("code",{className:"ap-lan-code lan-twin-at",children:bt}):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}),xt>0&&v&&o.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${O===Vt?" armed":""}`,...K(`unpair:${Vt}`),onKeyDown:xe=>{xe.repeat&&xe.preventDefault()},onClick:()=>{const xe=Date.now(),lr=Cu({armedFor:O,target:Vt,armedAt:I.current,now:xe,gapMs:Mu});if(lr==="arm"){H(Vt),I.current=xe;return}lr!=="ignore"&&(H(null),D(()=>v(Vt)))},"aria-label":O===Vt?`Confirm unpairing ${_n}`:`Unpair ${_n}`,title:O===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…":O===Vt?"confirm":"unpair"}),o.jsx("span",{className:"lan-twin-meta",children:xt===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."}),W&&!(P!=null&&P.waiting)&&o.jsx("button",{type:"button",className:"btn",...K(`check:${e.fp}`),onClick:()=>void D(f).then(je=>{je&&M.current&&ne(xt=>xt+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":""}`,...K(`unpair:${e.fp}`),onKeyDown:je=>{je.repeat&&je.preventDefault()},onClick:()=>{const je=Date.now(),xt=Cu({armedFor:C?e.fp:null,target:e.fp,armedAt:I.current,now:je,gapMs:Mu});if(xt==="arm"){R(!0),I.current=je;return}xt!=="ignore"&&(R(!1),D(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",...K(`accept:${e.fp}`),onClick:()=>void D(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",...K(`drop:${e.fp}`),onClick:()=>void D(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",...K(`allow:${e.fp}`),onClick:()=>void D(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 Lz(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 kh="Paused while this deck pairs only by invite. Turn that off above to use it.";function Pz({status:e,accounts:t,onClose:n,onChanged:r}){const s=pn(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 Z=ao(m,M);return{disabled:Z.disabled,"aria-busy":Z.busy}},b=w.useRef(null),_=w.useRef(!0);w.useEffect(()=>()=>{_.current=!1},[]),w.useEffect(()=>{b.current=XS(b.current,e.shared??[],null)},[e.shared]);const k=w.useCallback(async(M,Z,K="write")=>{v.current=K,y(K);try{const P=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:M})})).json().catch(()=>null);return _.current?(P!=null&&P.ok?f(null):f(un(Z,P)),r(),(P==null?void 0:P.ok)===!0):!1}catch{return _.current&&f(un(Z,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 hi(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,O=e.pairingMode==="invite",H=M=>{const Z=S(M);return{...Z,disabled:Z.disabled||O}},q=e.shareActive!==!1,$=e.tailscale??null,V=!!($!=null&&$.on),ne=($==null?void 0:$.ask)!==!1,ee=($==null?void 0:$.accept)!==!1;return Mn.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:Z=>{const K=Kz(b.current,e.shared??[],M.key,Z.target.checked);b.current=K,k({shared:K},Z.target.checked?"share that account":"stop sharing that account").then(D=>{b.current===K&&(b.current=XS(K,e.shared??[],{ok:D}))})}}),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":q,"aria-label":"Show paired decks which of these this deck is using",...S("current"),onClick:()=>void k({shareActive:!q},q?"stop showing which account this deck is using":"show which account this deck is using","current"),title:q?"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&&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":O,"aria-label":"Pair new decks only by invite","aria-describedby":O?"lan-invite-only-detail":void 0,...S("mode"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({pairingMode:O?"automatic":"invite"},O?"let decks pair on their own again":"pair new decks only by invite","mode"),title:O?"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&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches","data-paused":O||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",...H("ask"),onClick:()=>void k({autoAsk:!R},R?"stop asking automatically":"ask every deck this one finds","ask"),title:O?kh: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",...H("accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({autoAccept:!I},I?"stop accepting automatically":"accept every deck that asks","accept"),title:O?kh: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"})})]})]})]})]}),($==null?void 0:$.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:Lz($)})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":V,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...S("tailscale"),onClick:()=>void k({tailscale:!V},V?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:V?"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"})})]}),V&&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&&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":O||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",...H("tailscale-ask"),onClick:()=>void k({tailscaleAsk:!ne},ne?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:O?kh: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":O||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",...H("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:O?kh: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 KS={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${Lb}. The next round brings it.`}};function F0(e){return e.why?Object.hasOwn(KS,e.why)?KS[e.why]:tf(e.why):null}const Fb={"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"}},Dz={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 YS(e){var r;const t=Fz[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&Dz[n]||e}const Fz={"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 qb(e,t){var h;if(!e)return null;if(e.error&&((h=e.done)!=null&&h.length)){const m=qb({...e,error:void 0},t),y=` · ${qs(e.at,t)}`;return{...m,text:`${m.text.slice(0,-y.length)}, then ${YS(e.error)}${y}`,tone:"bad"}}if(e.error)return Fb[e.error]??{text:YS(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:F0(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 qz=9e4;function Bz({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<qz);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 q0=5e3,VM=6e4,Mu=400;function zz(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 un(e,t){if(t==null)return`Could not ${e} — the deck did not answer.`;const n=t.reason?Wz(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 Uz={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."},Hz=new Set(["EACCES","EPERM"]);function Wz(e,t){const n=Uz[e];if(!n)return;const r=e==="prefs_unreadable"&&t?Vz(t):void 0,s=t!=null&&t.code&&t.code!=="BADJSON"?` Error code: ${t.code}.`:"";return(r??n)+s}function Vz({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&&!Hz.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 Gz(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function Kz(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function XS(e,t,n){return e==null||n!=null&&!n.ok||Gz(e,t)?null:e}function Yz(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function GM(e,t){var n,r;return(n=e.last)!=null&&n.error&&!Fb[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<rf||e.lastSeen!=null&&t-e.lastSeen<rf)}const rf=95e3,KM=160,Xz=6,YM=140;function Zz(e,t){const n=[],r=[];for(const s of e??[])(GM(s,t)?n:r).push(s);return{online:n,offline:r}}function Qz(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 Jz(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<rf}),{online:u,offline:f}=Zz(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 eU(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 Bb(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 tU(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<rf;return{text:n?"online · one-way, it calls in":`one-way · last online ${qs(e,t)}`,here:n}}function ZS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${qs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function nU(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 · ${Bb(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=qb(k.last,t),C=GM(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?tU(k.lastSeen,t):null,O=I?I.here:C,H=!I&&E?O?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${ZS(k,O,t)}`:I?I.text:ZS(k,O,t),q=(v=k.last)!=null&&v.error?Fb[k.last.error]:null,$=!I&&O&&!((S=k.last)!=null&&S.error)&&!(((b=k.last)==null?void 0:b.done)??[]).length,V=k.manual&&!k.met?{name:R}:c(j,k.name||j);u.push({fp:j,name:V.name,...V.self?{self:V.self}:{},addr:k.addr??"",kind:"paired",state:H,quiet:$,tone:q?q.tone==="bad"?"bad":"wait":E?E.tone:O?"ok":"idle",here:I?I.here:C,...k.via==="tailscale"?{via:"tailscale"}:{},hint:I?`${V.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.`:`${V.name}${R?` at ${R}`:""}${(_=k.last)!=null&&_.error?` — ${k.last.error}`:""}${E!=null&&E.hint?` — ${E.hint}`:""}`})}n.push(...rU(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 rU(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(QS(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(QS(r))}return n}function QS(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 JS(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function ej(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 sU(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 aU(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 oU(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=aU(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 Nl(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function iU({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,Xz),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=$b(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]),Mn.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 lU(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 cU({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),O=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(O.current),[]);const[H,q]=w.useState(!1),[$,V]=w.useState(null),ne=w.useRef(null),ee=w.useCallback(ce=>Tf(ne.current)?(ne.current=ce,m(ce),!0):!1,[]),M=w.useCallback(()=>{ne.current=null,P.current&&m(null)},[]),Z=ce=>{const pe=ao(h,ce);return{disabled:pe.disabled,"aria-busy":pe.busy}},[K,D]=w.useState(()=>Date.now()),P=w.useRef(!0),B=w.useRef(q0),W=w.useCallback(async()=>{var ce,pe;try{const[Ae,fe]=await Promise.all([fetch("/api/lan").then(Se=>Se.json()),fetch("/api/prefs").then(Se=>Se.json())]);if(!P.current)return;Ae!=null&&Ae.ok&&u(Ae),fe!=null&&fe.ok&&p(Array.isArray((pe=(ce=fe.prefs)==null?void 0:ce.lan)==null?void 0:pe.manual)?fe.prefs.lan.manual:[]),B.current=(Ae==null?void 0:Ae.enabled)===!0?q0:VM}catch{}},[]);w.useEffect(()=>{P.current=!0;let ce=0;const pe=async()=>{D(Date.now()),await W(),P.current&&(ce=window.setTimeout(pe,B.current))};return pe(),()=>{P.current=!1,window.clearTimeout(ce)}},[W]);const F=w.useCallback(async()=>{const ce=(c==null?void 0:c.enabled)===!0;if(ee("switch"))try{const pe=await Nl("/api/prefs",{lan:{enabled:!ce}});if(!P.current)return;pe!=null&&pe.ok?(V(null),ce||v(!0)):V(un(ce?"turn this off":"turn this on",pe)),await W()}catch{P.current&&V(un(ce?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,W,ee,M]),G=w.useCallback(async(ce,pe,Ae)=>{if(!ee(`${ce}:${pe}`))return null;let fe=null;try{const Se=await Nl("/api/lan/peer",{action:ce,fp:pe});if(!P.current)return null;Se!=null&&Se.ok?(u(Se),V(null)):(fe=un(Ae,Se),V(fe)),await W()}catch{fe=un(Ae,null),P.current&&V(fe)}finally{M()}return fe},[W,ee,M]),re=w.useCallback(async ce=>{if(!ee(`drop:${ce}`))return null;let pe=null;try{const Ae=await Nl("/api/prefs",{lan:{manual:f.filter(fe=>fe!==ce)}});if(!P.current)return null;Ae!=null&&Ae.ok?(V(null),t()):(pe=un("stop dialling that address",Ae),V(pe)),await W()}catch{pe=un("stop dialling that address",null),P.current&&V(pe)}finally{M()}return pe},[f,W,t,ee,M]),[U,Y]=w.useState(null),z=w.useCallback(async(ce,pe)=>{if(!ee(`alias:${ce}`))return"Something else is still being saved. Try again in a moment.";try{const Ae=await Nl("/api/lan/peer",{action:"alias",fp:ce,name:pe});return P.current?Ae!=null&&Ae.ok?(u(Ae),null):un("rename that deck",Ae):null}catch{return un("rename that deck",null)}finally{M()}},[ee,M]),ie=w.useCallback(async ce=>{if(!ee(`check:${ce}`))return null;try{const pe=await Nl("/api/lan/sync",{fp:ce});return P.current?pe!=null&&pe.ok?(u(pe),t(),null):(pe==null?void 0:pe.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.":un("check that deck",pe):null}catch{return un("check that deck",null)}finally{M()}},[ee,M,t]),le=w.useCallback(async()=>{if(ee("check"))try{const ce=await Nl("/api/lan/sync",{});if(!P.current)return;ce!=null&&ce.ok?(u(ce),V(null)):V(un("check the other decks",ce)),t()}catch{P.current&&V(un("check the other decks",null))}finally{M()}},[ee,M,t]),ge=(c==null?void 0:c.enabled)===!0,Ne=nU((c==null?void 0:c.pairingMode)==="invite"&&c?{...c,pending:[]}:c,K),Ie=U?Ne.find(ce=>{var pe;return ce.fp===U||((pe=ce.twins)==null?void 0:pe.some(Ae=>Ae.fp===U))})??null:null;w.useEffect(()=>{U&&c&&!Ie&&Y(null)},[U,c,Ie]);const Ge=Ne.filter(ce=>ce.kind==="asks"),Pe=Ne.filter(ce=>ce.kind!=="asks"),Be=Pe.filter(ce=>ce.here),Te=Pe.filter(ce=>!ce.here),st=Te.filter(ce=>ce.tone==="bad").length,de=H||Be.length===0,ue=Jz(c,K),se=Pe.filter(ce=>ce.kind==="paired").length,be=lU(c,Ne),Le=o.jsxs(o.Fragment,{children:[k&&c&&o.jsx(Ez,{status:c,manual:f,startWith:k==="invite"?"invite":void 0,onClose:()=>j(!1),onChanged:()=>{W(),t()}}),E&&o.jsx(UM,{title:"How Local network works",steps:bz,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),F()}},onClose:()=>C(!1)}),y&&c&&o.jsx(Pz,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>v(!1),onChanged:()=>{W(),t()}}),Ie&&c&&o.jsx(Oz,{row:Ie,source:ej(c,Ie),status:c,accounts:e,now:K,busy:h,onClose:()=>Y(null),onRename:ce=>z(Ie.fp,ce),onCheck:()=>ie(Ie.fp),onVerb:()=>{switch(Ie.kind){case"paired":return G("unpair",Ie.fp,"unpair that deck");case"nearby":return G("accept",Ie.fp,"reach that deck");case"declined":return G("allow",Ie.fp,"let that deck ask again");case"dialling":return re(Ie.fp);default:return Promise.resolve(null)}},onSettings:()=>{Y(null),v(!0)},onInvite:()=>{Y(null),j("invite")},twins:(Ie.twins??[]).map(ce=>({row:ce,peer:ej(c,ce).peer??null})),onUnpair:ce=>G("unpair",ce,"unpair that deck")})]});if(!n){const ce=Se=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!0),Se)},pe=()=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!1),YM)},Ae=()=>window.clearTimeout(O.current),fe=()=>{window.clearTimeout(O.current),I(!1)};return o.jsxs("div",{className:"ap-foot",children:[o.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{fe(),r()},"aria-describedby":R?"ap-lan-peek":void 0,onPointerEnter:Se=>{Se.pointerType==="mouse"&&ce(KM)},onPointerLeave:pe,onFocus:Se=>{Se.target.matches(":focus-visible")&&ce(0)},onBlur:pe,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(iU,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:Ne,onHold:Ae,onLet:pe}),o.jsx("p",{className:"vis-hidden",role:"status",children:ue.tone==="ok"?"":ue.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",...Z("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",...Z("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",...Z("switch"),onClick:()=>void F(),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(WM,{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:Qz(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(kz,{}),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 ${ue.tone}`,role:"status",children:ue.tone==="ok"?"":ue.text}),$&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:$}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>V(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(ce=>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:ce.name})," at ",o.jsx("code",{className:"ap-lan-code",children:ce.addr})," wants to pair"]}),o.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",o.jsx("code",{className:"ap-lan-code",children:ce.fp})]}),o.jsxs("span",{className:"ap-lan-ask-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${ce.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`dismiss:${ce.fp}`),onClick:()=>void G("dismiss",ce.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},ce.fp))}),(de?[...Be,...Te]:Be).length>0&&o.jsx("ul",{className:"ap-lan-here",children:(de?[...Be,...Te]:Be).map((ce,pe)=>o.jsxs("li",{className:"ap-lan-who","data-tone":ce.tone,children:[o.jsx("i",{className:ce.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[ce.name,ce.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-${pe}`,onClick:()=>Y(ce.fp),children:o.jsxs("span",{className:"vis-hidden",children:[ce.name,ce.via==="tailscale"?", over Tailscale":"",", details"]})}),o.jsx("span",{id:`lan-who-state-${pe}`,className:ce.quiet?"vis-hidden":"ap-lan-who-when",children:ce.state}),ce.kind==="nearby"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"reach that deck"),"aria-label":`Ask ${ce.name} to pair`,title:`Send ${ce.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${ce.fp}.`,children:"ask"}),(ce.kind==="nearby"||ce.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 ${ce.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${ce.name}.`,children:"invite"}),ce.kind==="paired"&&o.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${S===ce.fp?" armed":""}`,...Z(`unpair:${ce.fp}`),onClick:()=>{const Ae=Date.now(),fe=Cu({armedFor:S,target:ce.fp,armedAt:_.current,now:Ae,gapMs:Mu});if(fe==="arm"){b(ce.fp),_.current=Ae,window.setTimeout(()=>b(Se=>Se===ce.fp?null:Se),4e3);return}fe!=="ignore"&&(b(null),G("unpair",ce.fp,"unpair that deck"))},"aria-label":S===ce.fp?`Confirm unpairing ${ce.name}`:`Unpair ${ce.name}`,title:S===ce.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===ce.fp?"confirm":"unpair"}),ce.kind==="dialling"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`drop:${ce.fp}`),onClick:()=>void re(ce.fp),"aria-label":`Stop dialling ${ce.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),ce.kind==="declined"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`allow:${ce.fp}`),onClick:()=>void G("allow",ce.fp,"let that deck ask again"),"aria-label":`Let ${ce.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${ce.kind}:${ce.fp}`))}),(Be.length>0&&Te.length>0||ge&&se>0)&&o.jsxs("div",{className:"ap-lan-tail",children:[Be.length>0&&Te.length>0&&o.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":H,onClick:()=>q(ce=>!ce),title:H?"Show only the decks that are on":`Show the ${Te.length} deck${Te.length===1?"":"s"} that are not responding right now`,children:[o.jsx("span",{className:`ap-lan-chev${H?" open":""}`,"aria-hidden":!0,children:"›"}),H?"fewer":`${Te.length} more`,!H&&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:eU(c==null?void 0:c.checkedAt,K,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 uU({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const l=w.useRef(null),{title:c,shown:u,rest:f}=iz(n),p=w.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=$b(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]),Mn.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 dU({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),YM)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},v=az(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(KM)},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(uU,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function hU(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const fU=1800;function pU({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=pn(t,{focusRef:b});w.useEffect(()=>{if(!l)return;S(Math.floor(Date.now()/1e3));const $=window.setInterval(()=>S(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval($)},[l]);const j=KB(e),E=YB(e,r),C=E.length===e.length,R=$=>s(V=>XB(V,$)),I=w.useCallback(async()=>{const $=ZB(E);if(!Ps(_.current)||!$)return;_.current=!0,f(!0),h(null),y(!1);const V=await hU($).catch(()=>null);if(_.current=!1,f(!1),!(V!=null&&V.ok)){h(Al(V,"the share could not be made"));return}c({blob:V.blob,expiresAt:V.expiresAt,shared:V.shared??[],failed:V.failed??[]})},[e,E]),O=l?zM(l.expiresAt,v):null,H=(O==null?void 0:O.tone)==="gone",q=(l==null?void 0:l.shared.length)??0;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:k,className:"modal sa-modal",onClick:$=>$.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:H?"This share has expired":q===1?"1 account, ready to paste":`${q} accounts, ready to paste`}),o.jsx("code",{className:`ap-share-blob${H?" 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(H){c(null),I();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),fU))},children:H?"make a new share":m?"copied":`copy ${q===1?"the share":"all "+q}`}),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:q===1?"this is the password":`this is ${q} passwords`})," · ",o.jsx("span",{className:`ap-share-expiry ${O==null?void 0:O.tone}`,children:O==null?void 0:O.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($=>{var ne;const V=!!($.email&&((ne=$.detail)!=null&&ne.includes($.email)));return o.jsxs("li",{children:[!V&&o.jsx("span",{className:"sa-who",children:$.email||`account ${$.num}`}),o.jsx("span",{className:"sa-why",children:$.detail||"could not be exported"})]},`${$.num}-${$.email}`)})})]}),o.jsx("p",{className:"sa-note",children:H?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 ",dn,"?"]}),o.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:QB(E.length)}),o.jsx("ul",{className:"sa-list sa-pick",children:j.map($=>o.jsx("li",{children:o.jsxs("label",{className:"sa-row",children:[o.jsx("input",{type:"checkbox",checked:E.includes($.num),onChange:()=>R($.num)}),o.jsx("span",{className:"sa-who",children:$.label}),$.sub&&o.jsx("span",{className:"sa-sub",children:$.sub})]})},$.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($=>$.num):[]),children:C?"Clear all":"Select all"}),o.jsx("button",{type:"button",className:"btn primary",ref:b,...Qa(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 mU(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 gU(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 yU(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function wU(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 vU(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 tj(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function xU(e){const t=e.filter(u=>!tj(u)),n=e.filter(u=>tj(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 bU="\0";function sf(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}${bU}${n}`}function kU(e,t){const n=sf(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function NU(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(sf)),r=e.filter(s=>n.has(s));return r.length===e.length?e:r}const SU=64;function jU(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function _U(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}const EU=Object.freeze({text:"couldn't reach the deck server",reload:!0}),CU=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function nj(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function TU(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Au(t.body);return{text:O0(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function rj(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 sj=15e3,RU=8e3,AU=1800,MU=3e4,Tm=[70,80,85,90,95];function Rm(e,t){return kM(t-Math.floor(e/1e3))}function IU(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 lu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function $U(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 OU(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 LU(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 Nh(e,t){if(e.staleCopy){const n=$U(e.repair??null,t);return{text:lu(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=LU(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:lu(n.text),hint:n.hint,fix:n.fix?lu(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=OU(e.error);return{text:lu(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function Am(){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 PU(e){return e>=90?"hi":e>=70?"mid":void 0}function DU(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Tm.includes(t)?[...Tm,t]:Tm].sort((r,s)=>r-s)}function FU({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?NM(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 qU({onClose:e,leaving:t}){var xr,$n,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)),O=w.useRef(null),[H,q]=w.useState(null),$=(H==null?void 0:H.num)??null,V=w.useRef(H);V.current=H;const[ne,ee]=w.useState(null),[M,Z]=w.useState(!1),[K,D]=w.useState(""),[P,B]=w.useState(null),W=w.useRef(0),[F,G]=w.useState(null),[re,U]=w.useState(!1),[Y,z]=w.useState(!1),[ie,le]=w.useState(null),[ge,Ne]=w.useState(null),[Ie,Ge]=w.useState(null),[Pe,Be]=w.useState(null),[Te,st]=w.useState(!1),de=w.useRef(null),ue=w.useRef(null),[se,be]=w.useState([]),[Le,ce]=w.useState(!1),pe=w.useRef(null),Ae=w.useCallback(Q=>Tf(pe.current)?(pe.current=Q,u(Q),!0):!1,[]),fe=w.useCallback(()=>{pe.current=null,u(null)},[]),Se=(Q,De=!1)=>{const et=ao(c,Q);return{disabled:et.disabled,"aria-busy":et.busy||De}},Ye=w.useCallback(Q=>{window.requestAnimationFrame(()=>{var De;if(A0(((De=document.activeElement)==null?void 0:De.tagName)??null))for(const et of u8(Q)){const Ue=document.querySelector(et);if(Ue){Ue.focus();return}}})},[]),qe=w.useCallback(async(Q=!1)=>{Q&&p(!0);const De=new AbortController,et=window.setTimeout(()=>De.abort(),MU);try{const[Ue,tt]=await Promise.all([fetch(`/api/claude-accounts${Q?"?refresh=1":""}`,{signal:De.signal}),fetch("/api/cswap-auto",{signal:De.signal})]);if(Ue.ok){const gt=await Ue.json();r(gt),be(It=>NU(It,gt.accounts))}tt.ok&&l(await tt.json());const wt=TU([await nj(Ue),await nj(tt)]);m(gt=>rj(gt,wt))}catch{m(Ue=>rj(Ue,De.signal.aborted?CU:EU))}finally{window.clearTimeout(et),Q&&p(!1)}},[]),ke=w.useCallback(async(Q,De,et="panel")=>{if(!Ae(De))return null;const Ue=et==="menu"?ee:m;Ue(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||Ue({text:O0(wt,"command failed",tt.status),raw:Au(wt)}),wt}catch{return Ue({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]),Re=w.useCallback(async(Q,De)=>{if(!Ae(De))return null;m(null),ee(null);try{const et=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),Ue=await et.json().catch(()=>null);return Ue!=null&&Ue.ok||ee({text:Al(Ue,"command failed",et.status)}),Ue}catch{return ee({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]);w.useEffect(()=>(qe(!0),O.current=window.setInterval(()=>qe(!1),sj),()=>{O.current!=null&&window.clearInterval(O.current)}),[qe]),w.useEffect(()=>{!(n!=null&&n.ok)||!n.accounts||v(Q=>_U(Q,n.accounts))},[n]),w.useEffect(()=>{const Q=window.setInterval(()=>I(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(Q)},[]);const ze=((xr=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:xr.value)??"90",Fe=Pe??ze,We=vU(Fe,ze),rt=($n=n==null?void 0:n.accounts)==null?void 0:$n.find(Q=>Q.active),dt=rt?Nh(rt,R):null,ct=(n==null?void 0:n.accounts)??[],yt=rt?ct.filter(Q=>!Q.active):[],Ot=yt.length?ct.filter(Q=>Q.active):ct,zt=yt.map(Q=>{const De=Nh(Q,R);return{key:sf(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(ze),Dt=(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),je=Q=>Le&&yt.some(De=>De.num===Q)?"ap-rest-list":"ap-scroll",xt=async(Q,De)=>{if(Ae(`switch-${Q}`)){m(null),v(null);try{const Ue=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:Q})})).json().catch(()=>null);Ue!=null&&Ue.ok?v({num:Q,name:De}):m({text:O0(Ue,"the switch failed"),raw:Au(Ue),row:Q}),await qe(!0)}catch{m({text:"server unreachable",row:Q})}finally{fe(),Ye(Q)}}},bt=w.useCallback(()=>{q(null),ee(null),B(null),G(null),z(!1)},[]),_n=(Q,De="first")=>{bt(),E(null),Ge(null),q({num:Q,view:"menu",start:De})},Ut=(Q,De)=>{bt(),E(et=>(et==null?void 0:et.anchor)===De?null:{num:Q,anchor:De})},Vn=w.useCallback((Q=!1)=>{var et;const De=C.current;Q&&De&&((et=document.getElementById(De.anchor))==null||et.focus()),E(null)},[]),Vt=()=>{bt(),E(null),b("lan")},Lt=w.useRef(S);w.useEffect(()=>{Lt.current!==S&&(Lt.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 Ue,tt;const De=V.current;if(!De||Q!=null&&De.num!==Q)return;const et=document.getElementById(`ap-menu-${De.num}`);(et!=null&&et.contains(document.activeElement)||A0(((Ue=document.activeElement)==null?void 0:Ue.tagName)??null))&&((tt=document.getElementById(`ap-more-${De.num}`))==null||tt.focus()),bt()},[bt]);w.useEffect(()=>{t&&(bt(),E(null))},[t,bt]),w.useEffect(()=>{H&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===H.num)&&bt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===j.num)&&E(null)},[n,H,j,bt]);const In=async Q=>{var et;z(!1);const De=await Re({action:"share",account:Q},`share-${Q}`);!(De!=null&&De.ok)||((et=V.current)==null?void 0:et.num)!==Q||(G({num:Q,blob:De.blob,expiresAt:De.expiresAt}),q({num:Q,view:"share"}))},Hr=async(Q,De)=>{const{commit:et,alias:Ue}=jU(K,De);if(et){const tt=await Re({action:"alias",account:Q,alias:Ue},`alias-${Q}`);if(await qe(!0),!(tt!=null&&tt.ok))return}Zt(Q)},xe=async(Q,De)=>{var tt,wt;const et=await Re({action:"move",account:Q,slot:De},`move-${Q}`),Ue=gU({menuFor:((tt=V.current)==null?void 0:tt.num)??null,shareFor:(F==null?void 0:F.num)??null},Q,et);if(await qe(!0),Ue){((wt=V.current)==null?void 0:wt.num)===Q&&bt(),B(Ue.confirmRemove),Ue.shareFor==null&&(G(null),z(!1)),Ne(Ue.swapNote);const gt=Ue.swapNote;gt&&window.setTimeout(()=>Ne(It=>It===gt?null:It),RU),Ge(null),Ye(Ue.menuFor)}return et},lr=async(Q,De,et)=>{if(!et.sends){Zt(Q);return}await xe(Q,De)},ks=async(Q,De)=>{if(De.sends){const et=await ke({action:"setting",key:"autoswitch.threshold",value:Q},"threshold");if(await qe(!0),!(et!=null&&et.ok))return;Be(null)}st(!0),window.setTimeout(()=>{var et;document.activeElement===ue.current&&((et=de.current)==null||et.focus()),st(!1)},AU)},Wr=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"})})}),fa=Q=>{const{shown:De,fuller:et}=xU(Q.lanes),Ue=Nh(Q,R),tt=Q.active||se.includes(sf(Q)),wt=Q.alias??Q.email??`account ${Q.num}`,gt=Q.alias&&Q.email?`${Q.alias} · ${Q.email}`:wt,It=Q.stale||(Ue==null?void 0:Ue.blocksSwitch)===!0,Rt=et?[...De,et]:De,Qt=Q.fetchedAt?Rm(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":It?"":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&&!(Ue!=null&&Ue.blocksSwitch)?`ap-quota-${Q.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>be(Nt=>kU(Nt,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&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsx("button",{type:"button",className:"ap-switch",...Se(`switch-${Q.num}`),onClick:()=>xt(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":$===Q.num,"aria-controls":$===Q.num?`ap-menu-${Q.num}`:void 0,title:"More actions",onClick:()=>$===Q.num?Zt():_n(Q.num),onKeyDown:Nt=>{Nt.key!=="ArrowDown"&&Nt.key!=="ArrowUp"||(Nt.preventDefault(),_n(Q.num,Nt.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 Nt=ct.find(cr=>cr.num===ge.displaced),br=(Nt==null?void 0:Nt.alias)??(Nt==null?void 0:Nt.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]})})(),Ue&&o.jsxs("div",{className:"ap-issue-line",children:[o.jsxs("button",{type:"button",id:`ap-issue-${Q.num}`,className:"ap-issue","data-tone":Ue.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:[Ue.tone==="warn"&&o.jsx(Am,{}),o.jsx("span",{className:"ap-issue-text",children:Ue.text})]}),!tt&&o.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),!tt&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsxs("p",{className:"ap-quota",id:`ap-quota-${Q.num}`,children:[Rt.length?Rt.map(Nt=>o.jsxs("span",{className:"ap-q",children:[o.jsx("span",{className:"ap-q-label",children:Nt.label})," ",o.jsxs("span",{className:"ap-q-pct","data-level":It?void 0:PU(Nt.pct),children:[Math.round(Nt.pct),"%"]})]},Nt.id)):o.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),Q.stale&&!Ue&&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(Nt=>o.jsx(FU,{lane:Nt,nowSec:R,frozen:It},Nt.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&&!Ue?" 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 ",Rm(Q.fetchedAt,R),Ue!=null&&Ue.blocksSwitch?"":IU(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)},Ns=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:de,"aria-label":"Switch threshold",value:Fe,...Se("threshold"),onChange:Q=>Be(Q.target.value),children:DU(ze).map(Q=>o.jsxs("option",{value:Q,children:[Q,"%"]},Q))})}),(We.sends||Te)&&o.jsx("button",{ref:ue,type:"button",className:"ap-manage-btn",...Se("threshold"),title:We.title,onClick:()=>ks(Fe,We),children:Te&&!We.sends?We.done:We.label}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":s.enabled,"aria-label":"Auto-switch",...Se("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:()=>Z(!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:()=>U(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${dn} 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),...Se("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"})]})}),Wr]})]}),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 ",sj/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&&(dt==null?void 0:dt.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(Am,{}),o.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),dt.fix&&o.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>Z(!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:Ot.map(fa)}),yt.length>0&&o.jsx(dU,{peers:zt,strained:Dt,armed:rn,threshold:s!=null&&s.ok?ze:null,open:Le,onToggle:()=>ce(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(fa)}),Ns]}),yt.length===0&&Ns,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:"×"})]}),H&&(()=>{var Ue;const Q=(Ue=n.accounts)==null?void 0:Ue.find(tt=>tt.num===H.num);if(!Q)return null;const De=`ap-pop-title-${Q.num}`,et=ne&&o.jsx("p",{className:"ap-pop-error",role:"alert",title:ne.raw||void 0,children:ne.text});return o.jsxs(M0,{anchorId:`ap-more-${Q.num}`,boundaryId:je(Q.num),id:`ap-menu-${Q.num}`,className:"ap-pop",role:H.view==="menu"?"menu":"dialog",labelledBy:H.view==="menu"?`ap-more-${Q.num}`:De,start:H.start,onClose:bt,children:[H.view==="menu"&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{D(Q.alias??""),ee(null),q({num:Q.num,view:"rename"})},children:"Rename"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{Ge(null),ee(null),q({num:Q.num,view:"move"})},children:"Move to slot…"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Se(`share-${Q.num}`),title:`Copy this account to another ${dn}. 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:()=>In(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",...Se(`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${P===Q.num?" armed":""}`,...Se(`rm-${Q.num}`),"aria-label":P===Q.num?"Confirm remove":void 0,title:P===Q.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{const tt=Date.now(),wt=Cu({armedFor:P,target:Q.num,armedAt:W.current,now:tt,gapMs:Mu});if(wt==="arm"){B(Q.num),W.current=tt,window.setTimeout(()=>B(gt=>gt===Q.num?null:gt),4e3);return}wt!=="ignore"&&(B(null),Re({action:"remove",account:Q.num},`rm-${Q.num}`).then(gt=>{var It;qe(!0),gt!=null&>.ok&&(((It=V.current)==null?void 0:It.num)===Q.num&&bt(),Ye(null))}))},children:c===`rm-${Q.num}`?"Removing…":P===Q.num?"Confirm":"Remove"}),et]}),H.view==="rename"&&o.jsxs("form",{className:"ap-pop-form",onSubmit:tt=>{tt.preventDefault(),Hr(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:K,onChange:tt=>D(tt.target.value),maxLength:SU,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:tt=>tt.currentTarget.select()}),et,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",...Se(`alias-${Q.num}`),title:"A short name to show instead of the email",children:c===`alias-${Q.num}`?"…":"Save"})]})]}),H.view==="move"&&(()=>{const tt=mU((n.accounts??[]).map(It=>It.num),Q.num),wt=yU(tt,Ie,Q.num),gt=wU(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),...Se(`move-${Q.num}`),onChange:It=>Ge(Number(It.target.value)),autoFocus:!0,children:tt.map(It=>o.jsx("option",{value:It.slot,children:It.label},It.slot))})}),et,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",...Se(`move-${Q.num}`),title:gt.title,onClick:()=>lr(Q.num,wt,gt),children:c===`move-${Q.num}`?"…":lu(gt.label)})]})]})})(),H.view==="share"&&(F==null?void 0:F.num)===Q.num&&(()=>{const tt=zM(F.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:F.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})]}),et,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",...Se(`share-${Q.num}`),autoFocus:!0,onClick:async()=>{if(wt){await In(Q.num);return}await hi(F.blob)&&(z(!0),window.setTimeout(()=>z(!1),1800))},children:wt?"Make a new share":Y?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var et;const Q=(et=n.accounts)==null?void 0:et.find(Ue=>Ue.num===j.num),De=Q?Nh(Q,R):null;return!Q||!De?null:o.jsx(M0,{anchorId:j.anchor,boundaryId:j.anchor==="ap-notice"?"ap-scroll":je(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(Am,{}),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 ${Rm(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),Z(!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(cU,{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:Wr}),M&&o.jsx(rz,{onClose:()=>Z(!1),onChanged:()=>qe(!0)}),re&&o.jsx(pU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({num:Q.num,email:Q.email,alias:Q.alias,org:Q.org})),onClose:()=>U(!1),copyText:hi}),ie!=null&&(()=>{const Q=((n==null?void 0:n.accounts)??[]).find(De=>De.num===ie);return Q?o.jsx(NB,{num:Q.num,name:Q.alias??Q.email??`account ${Q.num}`,onClose:()=>le(null)}):(le(null),null)})()]})}const BU=3e4;function zU({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function UU({bundle:e,running:t,pending:n,lastTried:r}){return t?zU({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function HU(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function WU({asked:e,reported:t}){return t?t!==e:!1}function XM(e){const t=e.thresholdMs??BU;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 VU(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 GU(e,t){return e?t==null?"auto when idle":`auto in ${VU(t)}`:"auto-restart off"}function aj(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function KU(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 YU(e){const t=XM(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 zb(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 Mm,oj;function XU(){if(oj)return Mm;oj=1;function e(){this.__data__=[],this.size=0}return Mm=e,Mm}var Im,ij;function tc(){if(ij)return Im;ij=1;function e(t,n){return t===n||t!==t&&n!==n}return Im=e,Im}var $m,lj;function Mf(){if(lj)return $m;lj=1;var e=tc();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return $m=t,$m}var Om,cj;function ZU(){if(cj)return Om;cj=1;var e=Mf(),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 Om=r,Om}var Lm,uj;function QU(){if(uj)return Lm;uj=1;var e=Mf();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Lm=t,Lm}var Pm,dj;function JU(){if(dj)return Pm;dj=1;var e=Mf();function t(n){return e(this.__data__,n)>-1}return Pm=t,Pm}var Dm,hj;function eH(){if(hj)return Dm;hj=1;var e=Mf();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 Dm=t,Dm}var Fm,fj;function If(){if(fj)return Fm;fj=1;var e=XU(),t=ZU(),n=QU(),r=JU(),s=eH();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,Fm=l,Fm}var qm,pj;function tH(){if(pj)return qm;pj=1;var e=If();function t(){this.__data__=new e,this.size=0}return qm=t,qm}var Bm,mj;function nH(){if(mj)return Bm;mj=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Bm=e,Bm}var zm,gj;function rH(){if(gj)return zm;gj=1;function e(t){return this.__data__.get(t)}return zm=e,zm}var Um,yj;function sH(){if(yj)return Um;yj=1;function e(t){return this.__data__.has(t)}return Um=e,Um}var Hm,wj;function ZM(){if(wj)return Hm;wj=1;var e=typeof th=="object"&&th&&th.Object===Object&&th;return Hm=e,Hm}var Wm,vj;function bs(){if(vj)return Wm;vj=1;var e=ZM(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Wm=n,Wm}var Vm,xj;function nc(){if(xj)return Vm;xj=1;var e=bs(),t=e.Symbol;return Vm=t,Vm}var Gm,bj;function aH(){if(bj)return Gm;bj=1;var e=nc(),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 Gm=l,Gm}var Km,kj;function oH(){if(kj)return Km;kj=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Km=n,Km}var Ym,Nj;function wi(){if(Nj)return Ym;Nj=1;var e=nc(),t=aH(),n=oH(),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 Ym=c,Ym}var Xm,Sj;function zr(){if(Sj)return Xm;Sj=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return Xm=e,Xm}var Zm,jj;function Uu(){if(jj)return Zm;jj=1;var e=wi(),t=zr(),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 Zm=c,Zm}var Qm,_j;function iH(){if(_j)return Qm;_j=1;var e=bs(),t=e["__core-js_shared__"];return Qm=t,Qm}var Jm,Ej;function lH(){if(Ej)return Jm;Ej=1;var e=iH(),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 Jm=n,Jm}var eg,Cj;function QM(){if(Cj)return eg;Cj=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 eg=n,eg}var tg,Tj;function cH(){if(Tj)return tg;Tj=1;var e=Uu(),t=lH(),n=zr(),r=QM(),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 tg=m,tg}var ng,Rj;function uH(){if(Rj)return ng;Rj=1;function e(t,n){return t==null?void 0:t[n]}return ng=e,ng}var rg,Aj;function vi(){if(Aj)return rg;Aj=1;var e=cH(),t=uH();function n(r,s){var l=t(r,s);return e(l)?l:void 0}return rg=n,rg}var sg,Mj;function Ub(){if(Mj)return sg;Mj=1;var e=vi(),t=bs(),n=e(t,"Map");return sg=n,sg}var ag,Ij;function $f(){if(Ij)return ag;Ij=1;var e=vi(),t=e(Object,"create");return ag=t,ag}var og,$j;function dH(){if($j)return og;$j=1;var e=$f();function t(){this.__data__=e?e(null):{},this.size=0}return og=t,og}var ig,Oj;function hH(){if(Oj)return ig;Oj=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return ig=e,ig}var lg,Lj;function fH(){if(Lj)return lg;Lj=1;var e=$f(),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 lg=s,lg}var cg,Pj;function pH(){if(Pj)return cg;Pj=1;var e=$f(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var l=this.__data__;return e?l[s]!==void 0:n.call(l,s)}return cg=r,cg}var ug,Dj;function mH(){if(Dj)return ug;Dj=1;var e=$f(),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 ug=n,ug}var dg,Fj;function gH(){if(Fj)return dg;Fj=1;var e=dH(),t=hH(),n=fH(),r=pH(),s=mH();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,dg=l,dg}var hg,qj;function yH(){if(qj)return hg;qj=1;var e=gH(),t=If(),n=Ub();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return hg=r,hg}var fg,Bj;function wH(){if(Bj)return fg;Bj=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return fg=e,fg}var pg,zj;function Of(){if(zj)return pg;zj=1;var e=wH();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return pg=t,pg}var mg,Uj;function vH(){if(Uj)return mg;Uj=1;var e=Of();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return mg=t,mg}var gg,Hj;function xH(){if(Hj)return gg;Hj=1;var e=Of();function t(n){return e(this,n).get(n)}return gg=t,gg}var yg,Wj;function bH(){if(Wj)return yg;Wj=1;var e=Of();function t(n){return e(this,n).has(n)}return yg=t,yg}var wg,Vj;function kH(){if(Vj)return wg;Vj=1;var e=Of();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 wg=t,wg}var vg,Gj;function Hb(){if(Gj)return vg;Gj=1;var e=yH(),t=vH(),n=xH(),r=bH(),s=kH();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,vg=l,vg}var xg,Kj;function NH(){if(Kj)return xg;Kj=1;var e=If(),t=Ub(),n=Hb(),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 xg=s,xg}var bg,Yj;function Lf(){if(Yj)return bg;Yj=1;var e=If(),t=tH(),n=nH(),r=rH(),s=sH(),l=NH();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,bg=c,bg}var kg,Xj;function Wb(){if(Xj)return kg;Xj=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 kg=e,kg}var Ng,Zj;function JM(){if(Zj)return Ng;Zj=1;var e=vi(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return Ng=t,Ng}var Sg,Qj;function Pf(){if(Qj)return Sg;Qj=1;var e=JM();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Sg=t,Sg}var jg,Jj;function Df(){if(Jj)return jg;Jj=1;var e=Pf(),t=tc(),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 jg=s,jg}var _g,e_;function Hu(){if(e_)return _g;e_=1;var e=Df(),t=Pf();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 _g=n,_g}var Eg,t_;function SH(){if(t_)return Eg;t_=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Eg=e,Eg}var Cg,n_;function Us(){if(n_)return Cg;n_=1;function e(t){return t!=null&&typeof t=="object"}return Cg=e,Cg}var Tg,r_;function jH(){if(r_)return Tg;r_=1;var e=wi(),t=Us(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Tg=r,Tg}var Rg,s_;function Wu(){if(s_)return Rg;s_=1;var e=jH(),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 Rg=l,Rg}var Ag,a_;function nn(){if(a_)return Ag;a_=1;var e=Array.isArray;return Ag=e,Ag}var cu={exports:{}},Mg,o_;function _H(){if(o_)return Mg;o_=1;function e(){return!1}return Mg=e,Mg}cu.exports;var i_;function rc(){return i_||(i_=1,(function(e,t){var n=bs(),r=_H(),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})(cu,cu.exports)),cu.exports}var Ig,l_;function Ff(){if(l_)return Ig;l_=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 Ig=n,Ig}var $g,c_;function Vb(){if(c_)return $g;c_=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return $g=t,$g}var Og,u_;function EH(){if(u_)return Og;u_=1;var e=wi(),t=Vb(),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]",O="[object Uint8Array]",H="[object Uint8ClampedArray]",q="[object Uint16Array]",$="[object Uint32Array]",V={};V[j]=V[E]=V[C]=V[R]=V[I]=V[O]=V[H]=V[q]=V[$]=!0,V[r]=V[s]=V[_]=V[l]=V[k]=V[c]=V[u]=V[f]=V[p]=V[h]=V[m]=V[y]=V[v]=V[S]=V[b]=!1;function ne(ee){return n(ee)&&t(ee.length)&&!!V[e(ee)]}return Og=ne,Og}var Lg,d_;function qf(){if(d_)return Lg;d_=1;function e(t){return function(n){return t(n)}}return Lg=e,Lg}var uu={exports:{}};uu.exports;var h_;function Gb(){return h_||(h_=1,(function(e,t){var n=ZM(),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})(uu,uu.exports)),uu.exports}var Pg,f_;function Vu(){if(f_)return Pg;f_=1;var e=EH(),t=qf(),n=Gb(),r=n&&n.isTypedArray,s=r?t(r):e;return Pg=s,Pg}var Dg,p_;function eI(){if(p_)return Dg;p_=1;var e=SH(),t=Wu(),n=nn(),r=rc(),s=Ff(),l=Vu(),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 Dg=f,Dg}var Fg,m_;function Bf(){if(m_)return Fg;m_=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return Fg=t,Fg}var qg,g_;function tI(){if(g_)return qg;g_=1;function e(t,n){return function(r){return t(n(r))}}return qg=e,qg}var Bg,y_;function CH(){if(y_)return Bg;y_=1;var e=tI(),t=e(Object.keys,Object);return Bg=t,Bg}var zg,w_;function Kb(){if(w_)return zg;w_=1;var e=Bf(),t=CH(),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 zg=s,zg}var Ug,v_;function da(){if(v_)return Ug;v_=1;var e=Uu(),t=Vb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Ug=n,Ug}var Hg,x_;function oo(){if(x_)return Hg;x_=1;var e=eI(),t=Kb(),n=da();function r(s){return n(s)?e(s):t(s)}return Hg=r,Hg}var Wg,b_;function TH(){if(b_)return Wg;b_=1;var e=Hu(),t=oo();function n(r,s){return r&&e(s,t(s),r)}return Wg=n,Wg}var Vg,k_;function RH(){if(k_)return Vg;k_=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Vg=e,Vg}var Gg,N_;function AH(){if(N_)return Gg;N_=1;var e=zr(),t=Bf(),n=RH(),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 Gg=l,Gg}var Kg,S_;function xi(){if(S_)return Kg;S_=1;var e=eI(),t=AH(),n=da();function r(s){return n(s)?e(s,!0):t(s)}return Kg=r,Kg}var Yg,j_;function MH(){if(j_)return Yg;j_=1;var e=Hu(),t=xi();function n(r,s){return r&&e(s,t(s),r)}return Yg=n,Yg}var du={exports:{}};du.exports;var __;function nI(){return __||(__=1,(function(e,t){var n=bs(),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})(du,du.exports)),du.exports}var Xg,E_;function rI(){if(E_)return Xg;E_=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 Xg=e,Xg}var Zg,C_;function sI(){if(C_)return Zg;C_=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 Zg=e,Zg}var Qg,T_;function aI(){if(T_)return Qg;T_=1;function e(){return[]}return Qg=e,Qg}var Jg,R_;function Yb(){if(R_)return Jg;R_=1;var e=sI(),t=aI(),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 Jg=l,Jg}var ey,A_;function IH(){if(A_)return ey;A_=1;var e=Hu(),t=Yb();function n(r,s){return e(r,t(r),s)}return ey=n,ey}var ty,M_;function Xb(){if(M_)return ty;M_=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 ty=e,ty}var ny,I_;function zf(){if(I_)return ny;I_=1;var e=tI(),t=e(Object.getPrototypeOf,Object);return ny=t,ny}var ry,$_;function oI(){if($_)return ry;$_=1;var e=Xb(),t=zf(),n=Yb(),r=aI(),s=Object.getOwnPropertySymbols,l=s?function(c){for(var u=[];c;)e(u,n(c)),c=t(c);return u}:r;return ry=l,ry}var sy,O_;function $H(){if(O_)return sy;O_=1;var e=Hu(),t=oI();function n(r,s){return e(r,t(r),s)}return sy=n,sy}var ay,L_;function iI(){if(L_)return ay;L_=1;var e=Xb(),t=nn();function n(r,s,l){var c=s(r);return t(r)?c:e(c,l(r))}return ay=n,ay}var oy,P_;function lI(){if(P_)return oy;P_=1;var e=iI(),t=Yb(),n=oo();function r(s){return e(s,n,t)}return oy=r,oy}var iy,D_;function OH(){if(D_)return iy;D_=1;var e=iI(),t=oI(),n=xi();function r(s){return e(s,n,t)}return iy=r,iy}var ly,F_;function LH(){if(F_)return ly;F_=1;var e=vi(),t=bs(),n=e(t,"DataView");return ly=n,ly}var cy,q_;function PH(){if(q_)return cy;q_=1;var e=vi(),t=bs(),n=e(t,"Promise");return cy=n,cy}var uy,B_;function cI(){if(B_)return uy;B_=1;var e=vi(),t=bs(),n=e(t,"Set");return uy=n,uy}var dy,z_;function DH(){if(z_)return dy;z_=1;var e=vi(),t=bs(),n=e(t,"WeakMap");return dy=n,dy}var hy,U_;function sc(){if(U_)return hy;U_=1;var e=LH(),t=Ub(),n=PH(),r=cI(),s=DH(),l=wi(),c=QM(),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}),hy=j,hy}var fy,H_;function FH(){if(H_)return fy;H_=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 fy=n,fy}var py,W_;function uI(){if(W_)return py;W_=1;var e=bs(),t=e.Uint8Array;return py=t,py}var my,V_;function Zb(){if(V_)return my;V_=1;var e=uI();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return my=t,my}var gy,G_;function qH(){if(G_)return gy;G_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return gy=t,gy}var yy,K_;function BH(){if(K_)return yy;K_=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return yy=t,yy}var wy,Y_;function zH(){if(Y_)return wy;Y_=1;var e=nc(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return wy=r,wy}var vy,X_;function dI(){if(X_)return vy;X_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return vy=t,vy}var xy,Z_;function UH(){if(Z_)return xy;Z_=1;var e=Zb(),t=qH(),n=BH(),r=zH(),s=dI(),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]",O="[object Uint32Array]";function H(q,$,V){var ne=q.constructor;switch($){case v:return e(q);case l:case c:return new ne(+q);case S:return t(q,V);case b:case _:case k:case j:case E:case C:case R:case I:case O:return s(q,V);case u:return new ne;case f:case m:return new ne(q);case p:return n(q);case h:return new ne;case y:return r(q)}}return xy=H,xy}var by,Q_;function hI(){if(Q_)return by;Q_=1;var e=zr(),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 by=n,by}var ky,J_;function fI(){if(J_)return ky;J_=1;var e=hI(),t=zf(),n=Bf();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return ky=r,ky}var Ny,eE;function HH(){if(eE)return Ny;eE=1;var e=sc(),t=Us(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return Ny=r,Ny}var Sy,tE;function WH(){if(tE)return Sy;tE=1;var e=HH(),t=qf(),n=Gb(),r=n&&n.isMap,s=r?t(r):e;return Sy=s,Sy}var jy,nE;function VH(){if(nE)return jy;nE=1;var e=sc(),t=Us(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return jy=r,jy}var _y,rE;function GH(){if(rE)return _y;rE=1;var e=VH(),t=qf(),n=Gb(),r=n&&n.isSet,s=r?t(r):e;return _y=s,_y}var Ey,sE;function pI(){if(sE)return Ey;sE=1;var e=Lf(),t=Wb(),n=Df(),r=TH(),s=MH(),l=nI(),c=rI(),u=IH(),f=$H(),p=lI(),h=OH(),m=sc(),y=FH(),v=UH(),S=fI(),b=nn(),_=rc(),k=WH(),j=zr(),E=GH(),C=oo(),R=xi(),I=1,O=2,H=4,q="[object Arguments]",$="[object Array]",V="[object Boolean]",ne="[object Date]",ee="[object Error]",M="[object Function]",Z="[object GeneratorFunction]",K="[object Map]",D="[object Number]",P="[object Object]",B="[object RegExp]",W="[object Set]",F="[object String]",G="[object Symbol]",re="[object WeakMap]",U="[object ArrayBuffer]",Y="[object DataView]",z="[object Float32Array]",ie="[object Float64Array]",le="[object Int8Array]",ge="[object Int16Array]",Ne="[object Int32Array]",Ie="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Be="[object Uint32Array]",Te={};Te[q]=Te[$]=Te[U]=Te[Y]=Te[V]=Te[ne]=Te[z]=Te[ie]=Te[le]=Te[ge]=Te[Ne]=Te[K]=Te[D]=Te[P]=Te[B]=Te[W]=Te[F]=Te[G]=Te[Ie]=Te[Ge]=Te[Pe]=Te[Be]=!0,Te[ee]=Te[M]=Te[re]=!1;function st(de,ue,se,be,Le,ce){var pe,Ae=ue&I,fe=ue&O,Se=ue&H;if(se&&(pe=Le?se(de,be,Le,ce):se(de)),pe!==void 0)return pe;if(!j(de))return de;var Ye=b(de);if(Ye){if(pe=y(de),!Ae)return c(de,pe)}else{var qe=m(de),ke=qe==M||qe==Z;if(_(de))return l(de,Ae);if(qe==P||qe==q||ke&&!Le){if(pe=fe||ke?{}:S(de),!Ae)return fe?f(de,s(pe,de)):u(de,r(pe,de))}else{if(!Te[qe])return Le?de:{};pe=v(de,qe,Ae)}}ce||(ce=new e);var Re=ce.get(de);if(Re)return Re;ce.set(de,pe),E(de)?de.forEach(function(We){pe.add(st(We,ue,se,We,de,ce))}):k(de)&&de.forEach(function(We,rt){pe.set(rt,st(We,ue,se,rt,de,ce))});var ze=Se?fe?h:p:fe?R:C,Fe=Ye?void 0:ze(de);return t(Fe||de,function(We,rt){Fe&&(rt=We,We=de[rt]),n(pe,rt,st(We,ue,se,rt,de,ce))}),pe}return Ey=st,Ey}var Cy,aE;function KH(){if(aE)return Cy;aE=1;var e=pI(),t=4;function n(r){return e(r,t)}return Cy=n,Cy}var Ty,oE;function Qb(){if(oE)return Ty;oE=1;function e(t){return function(){return t}}return Ty=e,Ty}var Ry,iE;function YH(){if(iE)return Ry;iE=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 Ry=e,Ry}var Ay,lE;function Jb(){if(lE)return Ay;lE=1;var e=YH(),t=e();return Ay=t,Ay}var My,cE;function ek(){if(cE)return My;cE=1;var e=Jb(),t=oo();function n(r,s){return r&&e(r,s,t)}return My=n,My}var Iy,uE;function XH(){if(uE)return Iy;uE=1;var e=da();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 Iy=t,Iy}var $y,dE;function Uf(){if(dE)return $y;dE=1;var e=ek(),t=XH(),n=t(e);return $y=n,$y}var Oy,hE;function bi(){if(hE)return Oy;hE=1;function e(t){return t}return Oy=e,Oy}var Ly,fE;function mI(){if(fE)return Ly;fE=1;var e=bi();function t(n){return typeof n=="function"?n:e}return Ly=t,Ly}var Py,pE;function gI(){if(pE)return Py;pE=1;var e=Wb(),t=Uf(),n=mI(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c))}return Py=s,Py}var Dy,mE;function yI(){return mE||(mE=1,Dy=gI()),Dy}var Fy,gE;function ZH(){if(gE)return Fy;gE=1;var e=Uf();function t(n,r){var s=[];return e(n,function(l,c,u){r(l,c,u)&&s.push(l)}),s}return Fy=t,Fy}var qy,yE;function QH(){if(yE)return qy;yE=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return qy=t,qy}var By,wE;function JH(){if(wE)return By;wE=1;function e(t){return this.__data__.has(t)}return By=e,By}var zy,vE;function wI(){if(vE)return zy;vE=1;var e=Hb(),t=QH(),n=JH();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,zy=r,zy}var Uy,xE;function eW(){if(xE)return Uy;xE=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 Uy=e,Uy}var Hy,bE;function vI(){if(bE)return Hy;bE=1;function e(t,n){return t.has(n)}return Hy=e,Hy}var Wy,kE;function xI(){if(kE)return Wy;kE=1;var e=wI(),t=eW(),n=vI(),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(O,H){if(!n(E,H)&&(C===O||h(C,O,f,p,m)))return E.push(H)})){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 Wy=l,Wy}var Vy,NE;function tW(){if(NE)return Vy;NE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,l){r[++n]=[l,s]}),r}return Vy=e,Vy}var Gy,SE;function tk(){if(SE)return Gy;SE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return Gy=e,Gy}var Ky,jE;function nW(){if(jE)return Ky;jE=1;var e=nc(),t=uI(),n=tc(),r=xI(),s=tW(),l=tk(),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,O,H,q,$,V,ne){switch(H){case j:if(I.byteLength!=O.byteLength||I.byteOffset!=O.byteOffset)return!1;I=I.buffer,O=O.buffer;case k:return!(I.byteLength!=O.byteLength||!V(new t(I),new t(O)));case f:case p:case y:return n(+I,+O);case h:return I.name==O.name&&I.message==O.message;case v:case b:return I==O+"";case m:var ee=s;case S:var M=q&c;if(ee||(ee=l),I.size!=O.size&&!M)return!1;var Z=ne.get(I);if(Z)return Z==O;q|=u,ne.set(I,O);var K=r(ee(I),ee(O),q,$,V,ne);return ne.delete(I),K;case _:if(C)return C.call(I)==C.call(O)}return!1}return Ky=R,Ky}var Yy,_E;function rW(){if(_E)return Yy;_E=1;var e=lI(),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],O=c[k];if(f)var H=m?f(O,I,k,c,l,h):f(I,O,k,l,c,h);if(!(H===void 0?I===O||p(I,O,u,f,h):H)){C=!1;break}R||(R=k=="constructor")}if(C&&!R){var q=l.constructor,$=c.constructor;q!=$&&"constructor"in l&&"constructor"in c&&!(typeof q=="function"&&q instanceof q&&typeof $=="function"&&$ instanceof $)&&(C=!1)}return h.delete(l),h.delete(c),C}return Yy=s,Yy}var Xy,EE;function sW(){if(EE)return Xy;EE=1;var e=Lf(),t=xI(),n=nW(),r=rW(),s=sc(),l=nn(),c=rc(),u=Vu(),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(_),O=R?h:s(b),H=I?h:s(_);O=O==p?m:O,H=H==p?m:H;var q=O==m,$=H==m,V=O==H;if(V&&c(b)){if(!c(_))return!1;R=!0,q=!1}if(V&&!q)return C||(C=new e),R||u(b)?t(b,_,k,j,E,C):n(b,_,O,k,j,E,C);if(!(k&f)){var ne=q&&v.call(b,"__wrapped__"),ee=$&&v.call(_,"__wrapped__");if(ne||ee){var M=ne?b.value():b,Z=ee?_.value():_;return C||(C=new e),E(M,Z,k,j,C)}}return V?(C||(C=new e),r(b,_,k,j,E,C)):!1}return Xy=S,Xy}var Zy,CE;function bI(){if(CE)return Zy;CE=1;var e=sW(),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 Zy=n,Zy}var Qy,TE;function aW(){if(TE)return Qy;TE=1;var e=Lf(),t=bI(),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 Qy=s,Qy}var Jy,RE;function kI(){if(RE)return Jy;RE=1;var e=zr();function t(n){return n===n&&!e(n)}return Jy=t,Jy}var ew,AE;function oW(){if(AE)return ew;AE=1;var e=kI(),t=oo();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 ew=n,ew}var tw,ME;function NI(){if(ME)return tw;ME=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return tw=e,tw}var nw,IE;function iW(){if(IE)return nw;IE=1;var e=aW(),t=oW(),n=NI();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 nw=r,nw}var rw,$E;function ac(){if($E)return rw;$E=1;var e=wi(),t=Us(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return rw=r,rw}var sw,OE;function nk(){if(OE)return sw;OE=1;var e=nn(),t=ac(),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 sw=s,sw}var aw,LE;function lW(){if(LE)return aw;LE=1;var e=Hb(),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,aw=n,aw}var ow,PE;function cW(){if(PE)return ow;PE=1;var e=lW(),t=500;function n(r){var s=e(r,function(c){return l.size===t&&l.clear(),c}),l=s.cache;return s}return ow=n,ow}var iw,DE;function uW(){if(DE)return iw;DE=1;var e=cW(),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 iw=r,iw}var lw,FE;function Hf(){if(FE)return lw;FE=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 lw=e,lw}var cw,qE;function dW(){if(qE)return cw;qE=1;var e=nc(),t=Hf(),n=nn(),r=ac(),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 cw=c,cw}var uw,BE;function SI(){if(BE)return uw;BE=1;var e=dW();function t(n){return n==null?"":e(n)}return uw=t,uw}var dw,zE;function Wf(){if(zE)return dw;zE=1;var e=nn(),t=nk(),n=uW(),r=SI();function s(l,c){return e(l)?l:t(l,c)?[l]:n(r(l))}return dw=s,dw}var hw,UE;function Gu(){if(UE)return hw;UE=1;var e=ac();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return hw=t,hw}var fw,HE;function Vf(){if(HE)return fw;HE=1;var e=Wf(),t=Gu();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 fw=n,fw}var pw,WE;function hW(){if(WE)return pw;WE=1;var e=Vf();function t(n,r,s){var l=n==null?void 0:e(n,r);return l===void 0?s:l}return pw=t,pw}var mw,VE;function fW(){if(VE)return mw;VE=1;function e(t,n){return t!=null&&n in Object(t)}return mw=e,mw}var gw,GE;function jI(){if(GE)return gw;GE=1;var e=Wf(),t=Wu(),n=nn(),r=Ff(),s=Vb(),l=Gu();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 gw=c,gw}var yw,KE;function _I(){if(KE)return yw;KE=1;var e=fW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return yw=n,yw}var ww,YE;function pW(){if(YE)return ww;YE=1;var e=bI(),t=hW(),n=_I(),r=nk(),s=kI(),l=NI(),c=Gu(),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 ww=p,ww}var vw,XE;function EI(){if(XE)return vw;XE=1;function e(t){return function(n){return n==null?void 0:n[t]}}return vw=e,vw}var xw,ZE;function mW(){if(ZE)return xw;ZE=1;var e=Vf();function t(n){return function(r){return e(r,n)}}return xw=t,xw}var bw,QE;function gW(){if(QE)return bw;QE=1;var e=EI(),t=mW(),n=nk(),r=Gu();function s(l){return n(l)?e(r(l)):t(l)}return bw=s,bw}var kw,JE;function ha(){if(JE)return kw;JE=1;var e=iW(),t=pW(),n=bi(),r=nn(),s=gW();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 kw=l,kw}var Nw,eC;function CI(){if(eC)return Nw;eC=1;var e=sI(),t=ZH(),n=ha(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c,3))}return Nw=s,Nw}var Sw,tC;function yW(){if(tC)return Sw;tC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Sw=n,Sw}var jw,nC;function TI(){if(nC)return jw;nC=1;var e=yW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return jw=n,jw}var _w,rC;function wW(){if(rC)return _w;rC=1;var e=Kb(),t=sc(),n=Wu(),r=nn(),s=da(),l=rc(),c=Bf(),u=Vu(),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 _w=y,_w}var Ew,sC;function RI(){if(sC)return Ew;sC=1;function e(t){return t===void 0}return Ew=e,Ew}var Cw,aC;function AI(){if(aC)return Cw;aC=1;var e=Uf(),t=da();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 Cw=n,Cw}var Tw,oC;function MI(){if(oC)return Tw;oC=1;var e=Hf(),t=ha(),n=AI(),r=nn();function s(l,c){var u=r(l)?e:n;return u(l,t(c,3))}return Tw=s,Tw}var Rw,iC;function vW(){if(iC)return Rw;iC=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 Rw=e,Rw}var Aw,lC;function xW(){if(lC)return Aw;lC=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 Aw=e,Aw}var Mw,cC;function II(){if(cC)return Mw;cC=1;var e=vW(),t=Uf(),n=ha(),r=xW(),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 Mw=l,Mw}var Iw,uC;function bW(){if(uC)return Iw;uC=1;var e=wi(),t=nn(),n=Us(),r="[object String]";function s(l){return typeof l=="string"||!t(l)&&n(l)&&e(l)==r}return Iw=s,Iw}var $w,dC;function kW(){if(dC)return $w;dC=1;var e=EI(),t=e("length");return $w=t,$w}var Ow,hC;function NW(){if(hC)return Ow;hC=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 Ow=f,Ow}var Lw,fC;function SW(){if(fC)return Lw;fC=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 Lw=C,Lw}var Pw,pC;function jW(){if(pC)return Pw;pC=1;var e=kW(),t=NW(),n=SW();function r(s){return t(s)?n(s):e(s)}return Pw=r,Pw}var Dw,mC;function _W(){if(mC)return Dw;mC=1;var e=Kb(),t=sc(),n=da(),r=bW(),s=jW(),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 Dw=u,Dw}var Fw,gC;function EW(){if(gC)return Fw;gC=1;var e=Wb(),t=hI(),n=ek(),r=ha(),s=zf(),l=nn(),c=rc(),u=Uu(),f=zr(),p=Vu();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 Fw=h,Fw}var qw,yC;function CW(){if(yC)return qw;yC=1;var e=nc(),t=Wu(),n=nn(),r=e?e.isConcatSpreadable:void 0;function s(l){return n(l)||t(l)||!!(r&&l&&l[r])}return qw=s,qw}var Bw,wC;function rk(){if(wC)return Bw;wC=1;var e=Xb(),t=CW();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 Bw=n,Bw}var zw,vC;function TW(){if(vC)return zw;vC=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 zw=e,zw}var Uw,xC;function $I(){if(xC)return Uw;xC=1;var e=TW(),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 Uw=n,Uw}var Hw,bC;function RW(){if(bC)return Hw;bC=1;var e=Qb(),t=JM(),n=bi(),r=t?function(s,l){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:n;return Hw=r,Hw}var Ww,kC;function AW(){if(kC)return Ww;kC=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 Ww=r,Ww}var Vw,NC;function OI(){if(NC)return Vw;NC=1;var e=RW(),t=AW(),n=t(e);return Vw=n,Vw}var Gw,SC;function Gf(){if(SC)return Gw;SC=1;var e=bi(),t=$I(),n=OI();function r(s,l){return n(t(s,l,e),s+"")}return Gw=r,Gw}var Kw,jC;function LI(){if(jC)return Kw;jC=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 Kw=e,Kw}var Yw,_C;function MW(){if(_C)return Yw;_C=1;function e(t){return t!==t}return Yw=e,Yw}var Xw,EC;function IW(){if(EC)return Xw;EC=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 Xw=e,Xw}var Zw,CC;function $W(){if(CC)return Zw;CC=1;var e=LI(),t=MW(),n=IW();function r(s,l,c){return l===l?n(s,l,c):e(s,t,c)}return Zw=r,Zw}var Qw,TC;function OW(){if(TC)return Qw;TC=1;var e=$W();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return Qw=t,Qw}var Jw,RC;function LW(){if(RC)return Jw;RC=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 Jw=e,Jw}var ev,AC;function PW(){if(AC)return ev;AC=1;function e(){}return ev=e,ev}var tv,MC;function DW(){if(MC)return tv;MC=1;var e=cI(),t=PW(),n=tk(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(l){return new e(l)}:t;return tv=s,tv}var nv,IC;function FW(){if(IC)return nv;IC=1;var e=wI(),t=OW(),n=LW(),r=vI(),s=DW(),l=tk(),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 nv=u,nv}var rv,$C;function PI(){if($C)return rv;$C=1;var e=da(),t=Us();function n(r){return t(r)&&e(r)}return rv=n,rv}var sv,OC;function qW(){if(OC)return sv;OC=1;var e=rk(),t=Gf(),n=FW(),r=PI(),s=t(function(l){return n(e(l,1,r,!0))});return sv=s,sv}var av,LC;function BW(){if(LC)return av;LC=1;var e=Hf();function t(n,r){return e(r,function(s){return n[s]})}return av=t,av}var ov,PC;function DI(){if(PC)return ov;PC=1;var e=BW(),t=oo();function n(r){return r==null?[]:e(r,t(r))}return ov=n,ov}var iv,DC;function Ur(){if(DC)return iv;DC=1;var e;if(typeof zb=="function")try{e={clone:KH(),constant:Qb(),each:yI(),filter:CI(),has:TI(),isArray:nn(),isEmpty:wW(),isFunction:Uu(),isUndefined:RI(),keys:oo(),map:MI(),reduce:II(),size:_W(),transform:EW(),union:qW(),values:DI()}}catch{}return e||(e=window._),iv=e,iv}var lv,FC;function sk(){if(FC)return lv;FC=1;var e=Ur();lv=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 lv}var cv,qC;function zW(){return qC||(qC=1,cv="2.1.8"),cv}var uv,BC;function UW(){return BC||(BC=1,uv={Graph:sk(),version:zW()}),uv}var dv,zC;function HW(){if(zC)return dv;zC=1;var e=Ur(),t=sk();dv={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 dv}var hv,UC;function WW(){if(UC)return hv;UC=1;var e=Ur();hv=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 hv}var fv,HC;function FI(){if(HC)return fv;HC=1;var e=Ur();fv=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},fv}var pv,WC;function qI(){if(WC)return pv;WC=1;var e=Ur(),t=FI();pv=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 pv}var mv,VC;function VW(){if(VC)return mv;VC=1;var e=qI(),t=Ur();mv=n;function n(r,s,l){return t.transform(r.nodes(),function(c,u){c[u]=e(r,u,s,l)},{})}return mv}var gv,GC;function BI(){if(GC)return gv;GC=1;var e=Ur();gv=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 gv}var yv,KC;function GW(){if(KC)return yv;KC=1;var e=Ur(),t=BI();yv=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 yv}var wv,YC;function KW(){if(YC)return wv;YC=1;var e=Ur();wv=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 wv}var vv,XC;function zI(){if(XC)return vv;XC=1;var e=Ur();vv=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,vv}var xv,ZC;function YW(){if(ZC)return xv;ZC=1;var e=zI();xv=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return xv}var bv,QC;function UI(){if(QC)return bv;QC=1;var e=Ur();bv=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 bv}var kv,JC;function XW(){if(JC)return kv;JC=1;var e=UI();kv=t;function t(n,r){return e(n,r,"post")}return kv}var Nv,eT;function ZW(){if(eT)return Nv;eT=1;var e=UI();Nv=t;function t(n,r){return e(n,r,"pre")}return Nv}var Sv,tT;function QW(){if(tT)return Sv;tT=1;var e=Ur(),t=sk(),n=FI();Sv=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 Sv}var jv,nT;function JW(){return nT||(nT=1,jv={components:WW(),dijkstra:qI(),dijkstraAll:VW(),findCycles:GW(),floydWarshall:KW(),isAcyclic:YW(),postorder:XW(),preorder:ZW(),prim:QW(),tarjan:BI(),topsort:zI()}),jv}var _v,rT;function e7(){if(rT)return _v;rT=1;var e=UW();return _v={Graph:e.Graph,json:HW(),alg:JW(),version:e.version},_v}var Ev,sT;function vs(){if(sT)return Ev;sT=1;var e;if(typeof zb=="function")try{e=e7()}catch{}return e||(e=window.graphlib),Ev=e,Ev}var Cv,aT;function t7(){if(aT)return Cv;aT=1;var e=pI(),t=1,n=4;function r(s){return e(s,t|n)}return Cv=r,Cv}var Tv,oT;function Kf(){if(oT)return Tv;oT=1;var e=tc(),t=da(),n=Ff(),r=zr();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 Tv=s,Tv}var Rv,iT;function n7(){if(iT)return Rv;iT=1;var e=Gf(),t=tc(),n=Kf(),r=xi(),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 Rv=c,Rv}var Av,lT;function r7(){if(lT)return Av;lT=1;var e=ha(),t=da(),n=oo();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 Av=r,Av}var Mv,cT;function s7(){if(cT)return Mv;cT=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Mv=t,Mv}var Iv,uT;function a7(){if(uT)return Iv;uT=1;var e=s7(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Iv=n,Iv}var $v,dT;function o7(){if(dT)return $v;dT=1;var e=a7(),t=zr(),n=ac(),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 $v=f,$v}var Ov,hT;function HI(){if(hT)return Ov;hT=1;var e=o7(),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 Ov=r,Ov}var Lv,fT;function i7(){if(fT)return Lv;fT=1;var e=HI();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Lv=t,Lv}var Pv,pT;function l7(){if(pT)return Pv;pT=1;var e=LI(),t=ha(),n=i7(),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 Pv=s,Pv}var Dv,mT;function c7(){if(mT)return Dv;mT=1;var e=r7(),t=l7(),n=e(t);return Dv=n,Dv}var Fv,gT;function WI(){if(gT)return Fv;gT=1;var e=rk();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return Fv=t,Fv}var qv,yT;function u7(){if(yT)return qv;yT=1;var e=Jb(),t=mI(),n=xi();function r(s,l){return s==null?s:e(s,t(l),n)}return qv=r,qv}var Bv,wT;function d7(){if(wT)return Bv;wT=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Bv=e,Bv}var zv,vT;function h7(){if(vT)return zv;vT=1;var e=Pf(),t=ek(),n=ha();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 zv=r,zv}var Uv,xT;function ak(){if(xT)return Uv;xT=1;var e=ac();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 Uv=t,Uv}var Hv,bT;function f7(){if(bT)return Hv;bT=1;function e(t,n){return t>n}return Hv=e,Hv}var Wv,kT;function p7(){if(kT)return Wv;kT=1;var e=ak(),t=f7(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return Wv=r,Wv}var Vv,NT;function VI(){if(NT)return Vv;NT=1;var e=Pf(),t=tc();function n(r,s,l){(l!==void 0&&!t(r[s],l)||l===void 0&&!(s in r))&&e(r,s,l)}return Vv=n,Vv}var Gv,ST;function m7(){if(ST)return Gv;ST=1;var e=wi(),t=zf(),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 Gv=p,Gv}var Kv,jT;function GI(){if(jT)return Kv;jT=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Kv=e,Kv}var Yv,_T;function g7(){if(_T)return Yv;_T=1;var e=Hu(),t=xi();function n(r){return e(r,t(r))}return Yv=n,Yv}var Xv,ET;function y7(){if(ET)return Xv;ET=1;var e=VI(),t=nI(),n=dI(),r=rI(),s=fI(),l=Wu(),c=nn(),u=PI(),f=rc(),p=Uu(),h=zr(),m=m7(),y=Vu(),v=GI(),S=g7();function b(_,k,j,E,C,R,I){var O=v(_,j),H=v(k,j),q=I.get(H);if(q){e(_,j,q);return}var $=R?R(O,H,j+"",_,k,I):void 0,V=$===void 0;if(V){var ne=c(H),ee=!ne&&f(H),M=!ne&&!ee&&y(H);$=H,ne||ee||M?c(O)?$=O:u(O)?$=r(O):ee?(V=!1,$=t(H,!0)):M?(V=!1,$=n(H,!0)):$=[]:m(H)||l(H)?($=O,l(O)?$=S(O):(!h(O)||p(O))&&($=s(H))):V=!1}V&&(I.set(H,$),C($,H,E,R,I),I.delete(H)),e(_,j,$)}return Xv=b,Xv}var Zv,CT;function w7(){if(CT)return Zv;CT=1;var e=Lf(),t=VI(),n=Jb(),r=y7(),s=zr(),l=xi(),c=GI();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 Zv=u,Zv}var Qv,TT;function v7(){if(TT)return Qv;TT=1;var e=Gf(),t=Kf();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 Qv=n,Qv}var Jv,RT;function x7(){if(RT)return Jv;RT=1;var e=w7(),t=v7(),n=t(function(r,s,l){e(r,s,l)});return Jv=n,Jv}var ex,AT;function KI(){if(AT)return ex;AT=1;function e(t,n){return t<n}return ex=e,ex}var tx,MT;function b7(){if(MT)return tx;MT=1;var e=ak(),t=KI(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return tx=r,tx}var nx,IT;function k7(){if(IT)return nx;IT=1;var e=ak(),t=ha(),n=KI();function r(s,l){return s&&s.length?e(s,t(l,2),n):void 0}return nx=r,nx}var rx,$T;function N7(){if($T)return rx;$T=1;var e=bs(),t=function(){return e.Date.now()};return rx=t,rx}var sx,OT;function S7(){if(OT)return sx;OT=1;var e=Df(),t=Wf(),n=Ff(),r=zr(),s=Gu();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 sx=l,sx}var ax,LT;function j7(){if(LT)return ax;LT=1;var e=Vf(),t=S7(),n=Wf();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 ax=r,ax}var ox,PT;function _7(){if(PT)return ox;PT=1;var e=j7(),t=_I();function n(r,s){return e(r,s,function(l,c){return t(r,c)})}return ox=n,ox}var ix,DT;function E7(){if(DT)return ix;DT=1;var e=WI(),t=$I(),n=OI();function r(s){return n(t(s,void 0,e),s+"")}return ix=r,ix}var lx,FT;function C7(){if(FT)return lx;FT=1;var e=_7(),t=E7(),n=t(function(r,s){return r==null?{}:e(r,s)});return lx=n,lx}var cx,qT;function T7(){if(qT)return cx;qT=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 cx=n,cx}var ux,BT;function R7(){if(BT)return ux;BT=1;var e=T7(),t=Kf(),n=HI();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 ux=r,ux}var dx,zT;function A7(){if(zT)return dx;zT=1;var e=R7(),t=e();return dx=t,dx}var hx,UT;function M7(){if(UT)return hx;UT=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return hx=e,hx}var fx,HT;function I7(){if(HT)return fx;HT=1;var e=ac();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 fx=t,fx}var px,WT;function $7(){if(WT)return px;WT=1;var e=I7();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 px=t,px}var mx,VT;function O7(){if(VT)return mx;VT=1;var e=Hf(),t=Vf(),n=ha(),r=AI(),s=M7(),l=qf(),c=$7(),u=bi(),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 mx=p,mx}var gx,GT;function L7(){if(GT)return gx;GT=1;var e=rk(),t=O7(),n=Gf(),r=Kf(),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 gx=s,gx}var yx,KT;function P7(){if(KT)return yx;KT=1;var e=SI(),t=0;function n(r){var s=++t;return e(r)+s}return yx=n,yx}var wx,YT;function D7(){if(YT)return wx;YT=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 wx=e,wx}var vx,XT;function F7(){if(XT)return vx;XT=1;var e=Df(),t=D7();function n(r,s){return t(r||[],s||[],e)}return vx=n,vx}var xx,ZT;function Pt(){if(ZT)return xx;ZT=1;var e;if(typeof zb=="function")try{e={cloneDeep:t7(),constant:Qb(),defaults:n7(),each:yI(),filter:CI(),find:c7(),flatten:WI(),forEach:gI(),forIn:u7(),has:TI(),isUndefined:RI(),last:d7(),map:MI(),mapValues:h7(),max:p7(),merge:x7(),min:b7(),minBy:k7(),now:N7(),pick:C7(),range:A7(),reduce:II(),sortBy:L7(),uniqueId:P7(),values:DI(),zipObject:F7()}}catch{}return e||(e=window._),xx=e,xx}var bx,QT;function q7(){if(QT)return bx;QT=1,bx=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 bx}var kx,JT;function B7(){if(JT)return kx;JT=1;var e=Pt(),t=vs().Graph,n=q7();kx=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 kx}var Nx,e2;function z7(){if(e2)return Nx;e2=1;var e=Pt(),t=B7();Nx={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 Nx}var Sx,t2;function or(){if(t2)return Sx;t2=1;var e=Pt(),t=vs().Graph;Sx={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,O=_.height/2;if(!C&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var H,q;return Math.abs(R)*I>Math.abs(C)*O?(R<0&&(O=-O),H=O*C/R,q=O):(C<0&&(I=-I),H=I,q=I*R/C),{x:j+H,y:E+q}}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(O){_.node(O).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 Sx}var jx,n2;function U7(){if(n2)return jx;n2=1;var e=Pt(),t=or();jx={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 jx}var _x,r2;function af(){if(r2)return _x;r2=1;var e=Pt();_x={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 _x}var Ex,s2;function YI(){if(s2)return Ex;s2=1;var e=Pt(),t=vs().Graph,n=af().slack;Ex=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 Ex}var Cx,a2;function H7(){if(a2)return Cx;a2=1;var e=Pt(),t=YI(),n=af().slack,r=af().longestPath,s=vs().alg.preorder,l=vs().alg.postorder,c=or().simplify;Cx=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),O=I.parent;E.edge(R,O).cutvalue=h(E,C,R)}function h(E,C,R){var I=E.node(R),O=I.parent,H=!0,q=C.edge(R,O),$=0;return q||(H=!1,q=C.edge(O,R)),$=q.weight,e.forEach(C.nodeEdges(R),function(V){var ne=V.v===R,ee=ne?V.w:V.v;if(ee!==O){var M=ne===H,Z=C.edge(V).weight;if($+=M?Z:-Z,k(E,R,ee)){var K=E.edge(R,ee).cutvalue;$+=M?-K:K}}}),$}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,R,I,O){var H=R,q=E.node(I);return C[I]=!0,e.forEach(E.neighbors(I),function($){e.has(C,$)||(R=y(E,C,R,$,I))}),q.low=H,q.lim=R++,O?q.parent=O:delete q.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,O=R.w;C.hasEdge(I,O)||(I=R.w,O=R.v);var H=E.node(I),q=E.node(O),$=H,V=!1;H.lim>q.lim&&($=q,V=!0);var ne=e.filter(C.edges(),function(ee){return V===j(E,E.node(ee.v),$)&&V!==j(E,E.node(ee.w),$)});return e.minBy(ne,function(ee){return n(C,ee)})}function b(E,C,R,I){var O=R.v,H=R.w;E.removeEdge(O,H),E.setEdge(I.v,I.w,{}),m(E),f(E,C),_(E,C)}function _(E,C){var R=e.find(E.nodes(),function(O){return!C.node(O).parent}),I=s(E,R);I=I.slice(1),e.forEach(I,function(O){var H=E.node(O).parent,q=C.edge(O,H),$=!1;q||(q=C.edge(H,O),$=!0),C.node(O).rank=C.node(H).rank+($?q.minlen:-q.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 Cx}var Tx,o2;function W7(){if(o2)return Tx;o2=1;var e=af(),t=e.longestPath,n=YI(),r=H7();Tx=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 Tx}var Rx,i2;function V7(){if(i2)return Rx;i2=1;var e=Pt();Rx=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 Rx}var Ax,l2;function G7(){if(l2)return Ax;l2=1;var e=Pt(),t=or();Ax={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,O=C!==R?1:m-y[v]+1;u.setEdge(b,C,{weight:I,minlen:O,nestingEdge:!0}),u.setEdge(R,_,{weight:I,minlen:O,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 Ax}var Mx,c2;function K7(){if(c2)return Mx;c2=1;var e=Pt(),t=or();Mx=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 Mx}var Ix,u2;function Y7(){if(u2)return Ix;u2=1;var e=Pt();Ix={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 Ix}var $x,d2;function X7(){if(d2)return $x;d2=1;var e=Pt();$x=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 $x}var Ox,h2;function Z7(){if(h2)return Ox;h2=1;var e=Pt();Ox=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 Ox}var Lx,f2;function Q7(){if(f2)return Lx;f2=1;var e=Pt();Lx=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 Lx}var Px,p2;function J7(){if(p2)return Px;p2=1;var e=Pt();Px=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 Px}var Dx,m2;function e9(){if(m2)return Dx;m2=1;var e=Pt(),t=or();Dx=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 Dx}var Fx,g2;function t9(){if(g2)return Fx;g2=1;var e=Pt(),t=Q7(),n=J7(),r=e9();Fx=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 Fx}var qx,y2;function n9(){if(y2)return qx;y2=1;var e=Pt(),t=vs().Graph;qx=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 qx}var Bx,w2;function r9(){if(w2)return Bx;w2=1;var e=Pt();Bx=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 Bx}var zx,v2;function s9(){if(v2)return zx;v2=1;var e=Pt(),t=X7(),n=Z7(),r=t9(),s=n9(),l=r9(),c=vs().Graph,u=or();zx=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 zx}var Ux,x2;function a9(){if(x2)return Ux;x2=1;var e=Pt(),t=vs().Graph,n=or();Ux={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 O=0,H=0,q=R.length,$=e.last(I);return e.forEach(I,function(V,ne){var ee=l(k,V),M=ee?k.node(ee).order:q;(ee||V===$)&&(e.forEach(I.slice(H,ne+1),function(Z){e.forEach(k.predecessors(Z),function(K){var D=k.node(K),P=D.order;(P<O||M<P)&&!(D.dummy&&k.node(Z).dummy)&&c(E,K,Z)})}),H=ne+1,O=M)}),I}return e.reduce(j,C),E}function s(k,j){var E={};function C(I,O,H,q,$){var V;e.forEach(e.range(O,H),function(ne){V=I[ne],k.node(V).dummy&&e.forEach(k.predecessors(V),function(ee){var M=k.node(ee);M.dummy&&(M.order<q||M.order>$)&&c(E,ee,V)})})}function R(I,O){var H=-1,q,$=0;return e.forEach(O,function(V,ne){if(k.node(V).dummy==="border"){var ee=k.predecessors(V);ee.length&&(q=k.node(ee[0]).order,C(O,$,ne,H,q),$=ne,H=q)}C(O,$,O.length,q,I.length)}),O}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={},O={};return e.forEach(j,function(H){e.forEach(H,function(q,$){R[q]=q,I[q]=q,O[q]=$})}),e.forEach(j,function(H){var q=-1;e.forEach(H,function($){var V=C($);if(V.length){V=e.sortBy(V,function(K){return O[K]});for(var ne=(V.length-1)/2,ee=Math.floor(ne),M=Math.ceil(ne);ee<=M;++ee){var Z=V[ee];I[$]===$&&q<O[Z]&&!u(E,$,Z)&&(I[Z]=$,I[$]=R[$]=R[Z],q=O[Z])}}})}),{root:R,align:I}}function p(k,j,E,C,R){var I={},O=h(k,j,E,R),H=R?"borderLeft":"borderRight";function q(ne,ee){for(var M=O.nodes(),Z=M.pop(),K={};Z;)K[Z]?ne(Z):(K[Z]=!0,M.push(Z),M=M.concat(ee(Z))),Z=M.pop()}function $(ne){I[ne]=O.inEdges(ne).reduce(function(ee,M){return Math.max(ee,I[M.v]+O.edge(M))},0)}function V(ne){var ee=O.outEdges(ne).reduce(function(Z,K){return Math.min(Z,I[K.w]-O.edge(K))},Number.POSITIVE_INFINITY),M=k.node(ne);ee!==Number.POSITIVE_INFINITY&&M.borderType!==H&&(I[ne]=Math.max(I[ne],ee))}return q($,O.predecessors.bind(O)),q(V,O.successors.bind(O)),e.forEach(C,function(ne){I[ne]=I[E[ne]]}),I}function h(k,j,E,C){var R=new t,I=k.graph(),O=b(I.nodesep,I.edgesep,C);return e.forEach(j,function(H){var q;e.forEach(H,function($){var V=E[$];if(R.setNode(V),q){var ne=E[q],ee=R.edge(ne,V);R.setEdge(ne,V,Math.max(O(k,$,q),ee||0))}q=$})}),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,O){var H=_(k,O)/2;C=Math.max(I+H,C),R=Math.min(I-H,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(O){var H=I+O,q=k[H],$;if(q!==j){var V=e.values(q);$=O==="l"?C-e.min(V):R-e.max(V),$&&(k[H]=e.mapValues(q,function(ne){return ne+$}))}})})}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(O){R=O==="u"?j:e.values(j).reverse(),e.forEach(["l","r"],function(H){H==="r"&&(R=e.map(R,function(ne){return e.values(ne).reverse()}));var q=(O==="u"?k.predecessors:k.successors).bind(k),$=f(k,R,E,q),V=p(k,R,$.root,$.align,H==="r");H==="r"&&(V=e.mapValues(V,function(ne){return-ne})),C[O+H]=V})});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 O=C.node(R),H=C.node(I),q=0,$;if(q+=O.width/2,e.has(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":$=-O.width/2;break;case"r":$=O.width/2;break}if($&&(q+=E?$:-$),$=0,q+=(O.dummy?j:k)/2,q+=(H.dummy?j:k)/2,q+=H.width/2,e.has(H,"labelpos"))switch(H.labelpos.toLowerCase()){case"l":$=H.width/2;break;case"r":$=-H.width/2;break}return $&&(q+=E?$:-$),$=0,q}}function _(k,j){return k.node(j).width}return Ux}var Hx,b2;function o9(){if(b2)return Hx;b2=1;var e=Pt(),t=or(),n=a9().positionX;Hx=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 Hx}var Wx,k2;function i9(){if(k2)return Wx;k2=1;var e=Pt(),t=z7(),n=U7(),r=W7(),s=or().normalizeRanks,l=V7(),c=or().removeEmptyRanks,u=G7(),f=K7(),p=Y7(),h=s9(),m=o9(),y=or(),v=vs().Graph;Wx=S;function S(U,Y){var z=Y&&Y.debugTiming?y.time:y.notime;z("layout",function(){var ie=z(" buildLayoutGraph",function(){return q(U)});z(" runLayout",function(){b(ie,z)}),z(" updateInputGraph",function(){_(U,ie)})})}function b(U,Y){Y(" makeSpaceForEdgeLabels",function(){$(U)}),Y(" removeSelfEdges",function(){B(U)}),Y(" acyclic",function(){t.run(U)}),Y(" nestingGraph.run",function(){u.run(U)}),Y(" rank",function(){r(y.asNonCompoundGraph(U))}),Y(" injectEdgeLabelProxies",function(){V(U)}),Y(" removeEmptyRanks",function(){c(U)}),Y(" nestingGraph.cleanup",function(){u.cleanup(U)}),Y(" normalizeRanks",function(){s(U)}),Y(" assignRankMinMax",function(){ne(U)}),Y(" removeEdgeLabelProxies",function(){ee(U)}),Y(" normalize.run",function(){n.run(U)}),Y(" parentDummyChains",function(){l(U)}),Y(" addBorderSegments",function(){f(U)}),Y(" order",function(){h(U)}),Y(" insertSelfEdges",function(){W(U)}),Y(" adjustCoordinateSystem",function(){p.adjust(U)}),Y(" position",function(){m(U)}),Y(" positionSelfEdges",function(){F(U)}),Y(" removeBorderNodes",function(){P(U)}),Y(" normalize.undo",function(){n.undo(U)}),Y(" fixupEdgeLabelCoords",function(){K(U)}),Y(" undoCoordinateSystem",function(){p.undo(U)}),Y(" translateGraph",function(){M(U)}),Y(" assignNodeIntersects",function(){Z(U)}),Y(" reversePoints",function(){D(U)}),Y(" acyclic.undo",function(){t.undo(U)})}function _(U,Y){e.forEach(U.nodes(),function(z){var ie=U.node(z),le=Y.node(z);ie&&(ie.x=le.x,ie.y=le.y,Y.children(z).length&&(ie.width=le.width,ie.height=le.height))}),e.forEach(U.edges(),function(z){var ie=U.edge(z),le=Y.edge(z);ie.points=le.points,e.has(le,"x")&&(ie.x=le.x,ie.y=le.y)}),U.graph().width=Y.graph().width,U.graph().height=Y.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"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H=["labelpos"];function q(U){var Y=new v({multigraph:!0,compound:!0}),z=re(U.graph());return Y.setGraph(e.merge({},j,G(z,k),e.pick(z,E))),e.forEach(U.nodes(),function(ie){var le=re(U.node(ie));Y.setNode(ie,e.defaults(G(le,C),R)),Y.setParent(ie,U.parent(ie))}),e.forEach(U.edges(),function(ie){var le=re(U.edge(ie));Y.setEdge(ie,e.merge({},O,G(le,I),e.pick(le,H)))}),Y}function $(U){var Y=U.graph();Y.ranksep/=2,e.forEach(U.edges(),function(z){var ie=U.edge(z);ie.minlen*=2,ie.labelpos.toLowerCase()!=="c"&&(Y.rankdir==="TB"||Y.rankdir==="BT"?ie.width+=ie.labeloffset:ie.height+=ie.labeloffset)})}function V(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(z.width&&z.height){var ie=U.node(Y.v),le=U.node(Y.w),ge={rank:(le.rank-ie.rank)/2+ie.rank,e:Y};y.addDummyNode(U,"edge-proxy",ge,"_ep")}})}function ne(U){var Y=0;e.forEach(U.nodes(),function(z){var ie=U.node(z);ie.borderTop&&(ie.minRank=U.node(ie.borderTop).rank,ie.maxRank=U.node(ie.borderBottom).rank,Y=e.max(Y,ie.maxRank))}),U.graph().maxRank=Y}function ee(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);z.dummy==="edge-proxy"&&(U.edge(z.e).labelRank=z.rank,U.removeNode(Y))})}function M(U){var Y=Number.POSITIVE_INFINITY,z=0,ie=Number.POSITIVE_INFINITY,le=0,ge=U.graph(),Ne=ge.marginx||0,Ie=ge.marginy||0;function Ge(Pe){var Be=Pe.x,Te=Pe.y,st=Pe.width,de=Pe.height;Y=Math.min(Y,Be-st/2),z=Math.max(z,Be+st/2),ie=Math.min(ie,Te-de/2),le=Math.max(le,Te+de/2)}e.forEach(U.nodes(),function(Pe){Ge(U.node(Pe))}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.has(Be,"x")&&Ge(Be)}),Y-=Ne,ie-=Ie,e.forEach(U.nodes(),function(Pe){var Be=U.node(Pe);Be.x-=Y,Be.y-=ie}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.forEach(Be.points,function(Te){Te.x-=Y,Te.y-=ie}),e.has(Be,"x")&&(Be.x-=Y),e.has(Be,"y")&&(Be.y-=ie)}),ge.width=z-Y+Ne,ge.height=le-ie+Ie}function Z(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y),ie=U.node(Y.v),le=U.node(Y.w),ge,Ne;z.points?(ge=z.points[0],Ne=z.points[z.points.length-1]):(z.points=[],ge=le,Ne=ie),z.points.unshift(y.intersectRect(ie,ge)),z.points.push(y.intersectRect(le,Ne))})}function K(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(e.has(z,"x"))switch((z.labelpos==="l"||z.labelpos==="r")&&(z.width-=z.labeloffset),z.labelpos){case"l":z.x-=z.width/2+z.labeloffset;break;case"r":z.x+=z.width/2+z.labeloffset;break}})}function D(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);z.reversed&&z.points.reverse()})}function P(U){e.forEach(U.nodes(),function(Y){if(U.children(Y).length){var z=U.node(Y),ie=U.node(z.borderTop),le=U.node(z.borderBottom),ge=U.node(e.last(z.borderLeft)),Ne=U.node(e.last(z.borderRight));z.width=Math.abs(Ne.x-ge.x),z.height=Math.abs(le.y-ie.y),z.x=ge.x+z.width/2,z.y=ie.y+z.height/2}}),e.forEach(U.nodes(),function(Y){U.node(Y).dummy==="border"&&U.removeNode(Y)})}function B(U){e.forEach(U.edges(),function(Y){if(Y.v===Y.w){var z=U.node(Y.v);z.selfEdges||(z.selfEdges=[]),z.selfEdges.push({e:Y,label:U.edge(Y)}),U.removeEdge(Y)}})}function W(U){var Y=y.buildLayerMatrix(U);e.forEach(Y,function(z){var ie=0;e.forEach(z,function(le,ge){var Ne=U.node(le);Ne.order=ge+ie,e.forEach(Ne.selfEdges,function(Ie){y.addDummyNode(U,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Ne.rank,order:ge+ ++ie,e:Ie.e,label:Ie.label},"_se")}),delete Ne.selfEdges})})}function F(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);if(z.dummy==="selfedge"){var ie=U.node(z.e.v),le=ie.x+ie.width/2,ge=ie.y,Ne=z.x-le,Ie=ie.height/2;U.setEdge(z.e,z.label),U.removeNode(Y),z.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}],z.label.x=z.x,z.label.y=z.y}})}function G(U,Y){return e.mapValues(e.pick(U,Y),Number)}function re(U){var Y={};return e.forEach(U,function(z,ie){Y[ie.toLowerCase()]=z}),Y}return Wx}var Vx,N2;function l9(){if(N2)return Vx;N2=1;var e=Pt(),t=or(),n=vs().Graph;Vx={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 Vx}var Gx,S2;function c9(){return S2||(S2=1,Gx="0.8.5"),Gx}var Kx,j2;function u9(){return j2||(j2=1,Kx={graphlib:vs(),layout:i9(),debug:l9(),util:{time:or().time,notime:or().notime},version:c9()}),Kx}var d9=u9();const _2=tb(d9),pi=240,Iu=130,Dl=74,Yf=72,gu=Dl+Yf;function XI(e,t){var r;let n=pi;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??pi);return n}const of=420,ZI=1;function h9(e,t,n,r){return Math.min(ZI,n/Math.max(1,e),r/Math.max(1,t))}function mi(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function f9(e,t){return((t==null?void 0:t.get(e))??0)>0?of:0}function p9(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function $u(e,t,n){const r=t.get(e);return{w:((r==null?void 0:r.width)??pi)+f9(e,n),h:Math.max((r==null?void 0:r.height)??Iu,p9(e,n))}}function m9(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function g9(e,t,n,r,s,l){const c=new _2.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}=$u(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);_2.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)??pi,R=(E==null?void 0:E.height)??Iu,I=$u(k,r,l),O=j.x-I.w/2,H=j.y-I.h/2;p.set(k,{x:O,y:H}),O<h&&(h=O),H<m&&(m=H),O+C>y&&(y=O+C),H+R>v&&(v=H+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)??pi,R=(E==null?void 0:E.height)??Iu;_=_===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 QI(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=mi(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,...g9(u.get(h),t,r,l,s,c)})),gap:XI(e,l)}}const JI=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+of,y9=e=>e.reduce((t,n)=>t+n.height,0)+gu*Math.max(0,e.length-1);function B0(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+gu;return p},l=[];for(let f=0;f<e.length;f++){let p=-gu;for(let h=f;h<e.length;h++)l.push(p+=e[h].height+gu)}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=>h9(h.reduce((m,y)=>m+JI(y),0)+t*(h.length-1),Math.max(...h.map(y9)),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 w9(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}=QI(e,t,n);return l.length<2?!1:B0(l,c,r.width,r.height).length!==B0(l,c,s.width,s.height).length}function v9(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:l}=QI(e,t,n),c=B0(s,l,n.availableWidth??0,n.availableHeight??0),u=new Map;let f=0;for(const p of c){const h=JI(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+gu}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 x9(e,t,n,r,s){const c=Dl+Yf,u=60,f=v=>$u(v,r,s),p=new Map(e.map(v=>[v.id,mi(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,O=R.sid===k?24:c;return S.x<R.x+R.w+I&&R.x<S.x+b+I&&j<R.y+R.h+O&&R.y<j+_+O});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 b9(e,t,n,r,s,l,c){const u=E=>$u(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)??pi,ch:(C==null?void 0:C.height)??Iu}},h=c!=null&&c.width>0&&c.height>0,m=new Map;for(const E of e){if(!f(E.id))continue;const C=mi(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),O=mi(E);y.has(O)?(v.get(O)??v.set(O,[]).get(O)).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=Dl+Yf,_=(E,C,R,I)=>S.some(O=>E<O.x+O.w+Dl&&O.x<E+R+Dl&&C<O.y+O.h+b&&O.y<C+I+b),k=XI(e,r),j=[];for(const E of[...v.keys()].sort()){const C=v.get(E);let R=1/0,I=1/0,O=-1/0,H=-1/0,q=-1/0,$=-1/0;for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id),{cw:F,ch:G}=p(D.id);R=Math.min(R,P.x),I=Math.min(I,P.y),O=Math.max(O,P.x+B),H=Math.max(H,P.y+W),q=Math.max(q,P.x+F),$=Math.max($,P.y+G)}const V=O-R,ne=H-I,ee=[...new Set(S.map(D=>Math.round(D.x)))].sort((D,P)=>D-P),M=ee.length?ee:[R],Z=[0,...S.map(D=>D.y+D.h+b)].sort((D,P)=>D-P);let K=null;if(h){let D=1/0,P=1/0,B=-1/0,W=-1/0;for(const z of S)D=Math.min(D,z.x),P=Math.min(P,z.y),B=Math.max(B,z.x+z.cw),W=Math.max(W,z.y+z.ch);const F=(z,ie)=>{const le=c.width/(Math.max(B,z+q-R)-Math.min(D,z)+of),ge=c.height/(Math.max(W,ie+$-I)-Math.min(P,ie));return[Math.min(ZI,le,ge),Math.min(le,ge),Math.max(le,ge)]},G=(z,ie)=>{for(let le=0;le<z.length;le++){if(z[le]>ie[le]+1e-9)return!0;if(z[le]<ie[le]-1e-9)return!1}return!1},re=Math.round(B+of+k),U=[...new Set([...Z,P])].sort((z,ie)=>z-ie);let Y=null;for(const z of[...M,re])for(const ie of U){if(_(z,ie,V,ne))continue;const le=F(z,ie);(Y===null||G(le,Y))&&(Y=le,K={x:z,y:ie})}K&&K.x===R&&K.y===I&&(K=null)}else e:for(const D of M)for(const P of Z){if(P>=I)break;if(!_(D,P,V,ne)){K={x:D,y:P};break e}}if(K){const D=K.x-R,P=K.y-I;for(const B of C){const W=f(B.id);t.set(B.id,{x:W.x+D,y:W.y+P})}j.push(E)}for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id);S.push({x:P.x,y:P.y,w:B,h:W,...p(D.id)})}}return j}function k9(e,t,n){const r=new Map;for(const s of e){if(t.has(s.id)||!n(s.id))continue;const l=mi(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(mi(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 N9(e,t,n,r,s,l=!1,c){const p=Dl+Yf+1,h=8,m=1.75,y=200,v=.7,S=.01,b=$=>$u($,r,c),_=$=>n.get($)??t.get($),k=new Map;for(const $ of e){if(!_($.id))continue;const V=mi($),ne=k.get(V);ne?ne.push($):k.set(V,[$])}const j=[],E=new Set,C=new Set,R=s.size===0;for(const $ of[...k.keys()].sort()){const V=k.get($);let ne=1/0,ee=1/0,M=-1/0,Z=-1/0,K=!1;for(const W of V){const F=_(W.id),{w:G,h:re}=b(W.id);ne=Math.min(ne,F.x),ee=Math.min(ee,F.y),M=Math.max(M,F.x+G),Z=Math.max(Z,F.y+re),n.has(W.id)&&(K=!0)}const D=M-ne,P=Z-ee;C.add($);const B=s.get($);B&&(D>B.w+h||P>B.h+h)&&E.add($),s.set($,{w:D,h:P}),j.push({sid:$,members:V.map(W=>W.id),x:ne,y:ee,w:D,h:P,anchored:K,mass:1})}for(const $ of[...s.keys()])C.has($)||s.delete($);if(l||R)return[];let I=!1;for(let $=0;$<j.length&&!I;$++)for(let V=$+1;V<j.length;V++){const ne=j[$],ee=j[V];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 $ of j)E.has($.sid)&&($.mass=8);else for(const $ of j)$.mass=Math.max(1,$.w*$.h/(pi*Iu));const O=new Map(j.map($=>[$.sid,$.x])),H=new Map(j.map($=>[$.sid,$.y]));for(let $=0;$<y;$++){const V=new Map,ne=new Map;let ee=0;for(let M=0;M<j.length;M++)for(let Z=M+1;Z<j.length;Z++){const K=j[M],D=j[Z];if(K.anchored&&D.anchored)continue;const P=K.x+K.w/2,B=K.y+K.h/2,W=D.x+D.w/2,F=D.y+D.h/2,G=(K.w+D.w)/2+61-Math.abs(P-W),re=(K.h+D.h)/2+p-Math.abs(B-F);if(G<=0||re<=0)continue;const U=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.x<=0),Y=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.y<=0),z=(pe,Ae,fe)=>{const Se=pe===Ae,Ye=Se?K.sid<D.sid?-1:1:Math.sign(pe-Ae);return fe(K,Ye)||fe(D,-Ye)?Ye:Se&&(fe(K,-Ye)||fe(D,Ye))?-Ye:0},ie=z(P,W,U),le=z(B,F,Y),ge=ie!==0,Ne=le!==0;if(!ge&&!Ne)continue;const Ie=ge&&(!Ne||G*m<re),[Ge,Pe,Be,Te]=Ie?[ie,G,V,U]:[le,re,ne,Y],st=Te(K,Ge),de=Te(D,-Ge),ue=K.mass,se=D.mass,be=st?de?se/(ue+se):1:0,Le=de?st?ue/(ue+se):1:0,ce=Pe*v;Be.set(K.sid,(Be.get(K.sid)??0)+Ge*ce*be),Be.set(D.sid,(Be.get(D.sid)??0)-Ge*ce*Le),ee+=ce}for(const M of j)M.anchored||(M.x=Math.max(0,M.x+(V.get(M.sid)??0)),M.y=Math.max(0,M.y+(ne.get(M.sid)??0)));if(ee<S)break}const q=[];for(const $ of j){const V=$.x-O.get($.sid),ne=$.y-H.get($.sid);if(!(Math.abs(V)<1&&Math.abs(ne)<1)){for(const ee of $.members){if(n.has(ee))continue;const M=t.get(ee);M&&t.set(ee,{x:M.x+V,y:M.y+ne})}q.push($.sid)}}return q}function Fh(e,t,n){return!t.has(e)||n.has(e)}function S9(e,t,n,r){return!t.has(e)&&Fh(e,n,r)}function j9(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function E2(e,t,n,r){n.set(e,t),r.delete(e)}const _9=200,E9=5*6e4,C9=6,T9=2*6e4;function Sh(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function R9(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 A9(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(_b(n.id));return t}function M9(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(_b(n.id));return t}function I9(e,t){let n=s6(e,t,BN);a6(e,t,BN)&&(n=!0);const r=[],s=l=>{r.push(l)};return e6(e,t,_9,E9,s)&&(n=!0),t6(e,t,C9,T9,s)&&(n=!0),{changed:n,forgotten:r}}const $9=300,C2=130,O9=160,T2=new WeakMap;function L9(e,t){let n=T2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:pF(e.agents.values())},T2.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 z0(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 P9(e,t,n,r,s,l,c,u,f,p,h,m,y,v,S,b,_,k){var ee,M,Z,K;const j=[],E=[],C=L9(e,k);for(const D of e.agents.values()){if(!_.has(D.id))continue;const P=D.exitAt!=null,B=b!=null&&!b.has(D.id),W=[P?"rf-exiting":"",B?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,F=l.get(D.id);if(j.push({id:D.id,type:"agent",position:{x:0,y:0},data:C(D),className:W,ariaLabel:sq(D,t,S.has(D.id)),...F?{width:F.width,height:F.height}:null}),D.parentId&&_.has(D.parentId)){const U=Qh(D.sessionId),Y=P,z=S.size>0&&(S.has(D.id)||S.has(D.parentId)),ie=b!=null&&!b.has(D.id)&&!b.has(D.parentId),le=D.state==="active"?2:1.5,ge=z?le+1.5:le,Ne=Y?.2:ie?.12:1,Ie=["sess-edge",D.state==="active"?"sess-live":"sess-idle",Y?"rf-edge-exiting":"",z?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${D.parentId}->${D.id}`,source:D.parentId,target:D.id,animated:(D.state==="active"||z)&&!Y,type:"smoothstep",style:{"--session-hue":U,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:Ne,transition:"var(--edge-transition)"},className:Ie})}const G=D.kind==="root"?jf(D):null,re=G?hM(D.sessionId,G.at):null;if(G&&re&&!lF(re)){const U=_b(D.id),Y=Qh(D.sessionId),z=l.get(U);j.push({id:U,type:"recapNote",position:{x:0,y:0},data:{sessionId:D.sessionId,parentId:D.id,recap:G,noteKey:re,hue:Y},className:B?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${D.label}`,...z?{width:z.width,height:z.height}:null}),E.push({id:`e:recap:${D.id}`,source:U,target:D.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Y}})}}const R=z0(e),I=`${y}#lanes:${m9(R)}`,O=new Set(j.filter(D=>D.type==="recapNote").map(D=>D.id));for(const D of Array.from(h.keys()))hF(D)&&!O.has(D)&&!s.has(D)&&(h.delete(D),m.delete(D));const H=j.filter(D=>S9(D.id,s,h,m));if(H.length>0||I!==v.current){if(H.length>0){const D=k9(v9(j,E,{direction:"LR",pinned:s,measured:l,availableWidth:n,availableHeight:r,lanes:R}),s,P=>Fh(P,h,m)?void 0:h.get(P));for(const P of D)Fh(P.id,h,m)&&E2(P.id,P.position,h,m);b9(j,h,s,l,new Set(H.filter(P=>P.type!=="recapNote").map(P=>P.id)),R,{width:n,height:r});for(const P of H){if(P.type!=="recapNote")continue;const B=(ee=P.data)==null?void 0:ee.parentId;if(!B)continue;const W=s.get(B)??(Fh(B,h,m)?void 0:h.get(B));if(!W)continue;const F=((M=l.get(P.id))==null?void 0:M.width)??$9,G=((Z=l.get(P.id))==null?void 0:Z.height)??C2,re=((K=l.get(B))==null?void 0:K.height)??C2;E2(P.id,{x:W.x-O9-F,y:W.y+(re-G)/2},h,m)}}x9(j,h,s,l,R),v.current=I}const q=N9(j,h,s,l,c,!f||p,R);q.length>0&&u(q);const $=M9(e.agents.values());Sh(h,$),Sh(m,$),Sh(s,$),Sh(l,A9(e.agents.values()));const V=[];let ne=!1;for(const D of j){let P=s.get(D.id)??h.get(D.id);P||(P=j9(D.id,h,m),ne=!0),V.push({...D,position:P})}return ne&&(v.current=""),{nodes:V,edges:E}}const D9=1;function F9(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 q9(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:D9,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(F9)}))}}function B9(e,t){const n=(e||"session").replace(/[^a-z0-9._-]/gi,"_");return`${dn}-${n}-${t.slice(0,8)}.json`}function z9(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function U9(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 H9(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function W9(e,t){const n=H9(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 V9({agentCount:e,onConfirm:t,onCancel:n}){const r=w.useRef(null),s=pn(n,{focusRef:r,layer:$6}),[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(U9(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=W9(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 G9="Press Esc first if a key does nothing.",K9=[{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 Y9({onClose:e,onTour:t}){const n=pn(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:K9.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:G9})]})]})})}const X9=1024*1024,R2=5,e$=.8,U0=24,Z9="agent-dag.soundCustom.done",Q9="agent-dag.soundCustom.needs-input",yu={done:Z9,"needs-input":Q9};function Ou(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function A2(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function J9(e){return{done:A2(e(yu.done)),"needs-input":A2(e(yu["needs-input"]))}}function eV(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function tV(e){return e.done&&e.done===e["needs-input"]?e.done:null}const nV={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},t$=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function n$(e,t){const n=t.toLowerCase().split(";")[0].trim();if(t$.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return nV[r]??n}function M2(e,t){const n=n$(e.name,e.type);if(!t$.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>X9)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>R2)return`Audio must be ${R2} seconds or shorter.`}return null}function H0(e){return e>=U0?`There are already ${U0} custom sounds. Delete one first.`:null}function rV(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function sV(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,e$/t)}function r$(){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 aV(e,t,n=r$()){var p;const r=((p=e.name)==null?void 0:p.trim())||"Custom sound",s=M2({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=M2({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:n$(r,e.type),duration:c.duration,normalizationGain:sV(f),bytes:l}}function oV(e,t=r$()){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 iV="ccdeck-notification-audio",lV=2,ws="assets",Bs="summaries";function Ku(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function cV(){return new Promise((e,t)=>{const n=indexedDB.open(iV,lV);n.onupgradeneeded=r=>{const s=n.result,l=s.objectStoreNames.contains(ws)?n.transaction.objectStore(ws):s.createObjectStore(ws,{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(Ou(f.value)),f.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function Yu(e,t,n){const r=await cV();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 uV(){const e=Ku();return e?e.list():typeof indexedDB>"u"?[]:await Yu([Bs],"readonly",t=>t.objectStore(Bs).getAll())??[]}async function dV(e){const t=Ku();return t?t.get(e):typeof indexedDB>"u"?null:await Yu([ws],"readonly",n=>n.objectStore(ws).get(e))??null}async function I2(e){const t=Ku();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).put(e),n.objectStore(Bs).put(Ou(e))})}async function hV(e,t){const n=Ku();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 Yu([ws,Bs],"readwrite",r=>{const s=r.objectStore(ws),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(Ou(u))}})}async function fV(e){const t=Ku();if(t){await t.remove(e);return}typeof indexedDB>"u"||await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).delete(e),n.objectStore(Bs).delete(e)})}const qh=["done","needs-input"],pV=[{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}]}],mV=[{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}]}],ok={done:pV,"needs-input":mV},wr="two";function W0(e,t){const n=ok[e];return n.find(r=>r.id===t)??n.find(r=>r.id===wr)??n[0]}function s$(e,t){return ok[e].some(r=>r.id===t)?t:wr}W0("done",wr).notes,W0("needs-input",wr).notes;const $2=.04,a$=.24,oi=0,Gl=100,lf=5,gi=50;function Kl(e){if(!Number.isFinite(e))return gi;const t=Math.round(e/lf)*lf;return Math.min(Gl,Math.max(oi,t))}function o$(e){if(e==null)return gi;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Kl(Number(t)):gi}function V0(e){const t=Kl(e),n=$2+(a$-$2)*(t/Gl);return Math.round(n*1e4)/1e4}function gV(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(V0(e)*r*1e4)/1e4}const yV=160,wV="agent-dag.soundLevel.done",vV="agent-dag.soundLevel.needs-input",xV="agent-dag.soundFigure.done",bV="agent-dag.soundFigure.needs-input",i$={done:wV,"needs-input":vV},Bh={done:xV,"needs-input":bV},G0={done:{level:gi,figure:wr},"needs-input":{level:gi,figure:wr}};function kV(e){const t=n=>({level:o$(e(i$[n])),figure:s$(n,e(Bh[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const O2={Stop:"done",Notification:"needs-input"};function NV(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(O2,n)?O2[n]:null}function SV(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=W0(m,v),b=gV(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,V0(y.level)/a$);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*(V0(y.level)/e$);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))??G0)[m]??G0[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=gi){return f(m,{level:Kl(y),figure:wr}),!0}return{unlock:c,play:p,previewCustom:h,state:s,get context(){return n}}}const jV="With no deck tab open, get a notification wherever a sound would have played.",_V="With the ccdeck window closed, get a notification wherever a sound would have played.";function EV(e){return e?_V:jV}const CV="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",L2="Get notified when you're away from this tab.";function TV(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:L2};case"default":return{status:null,ask:!0,ok:!1,note:L2};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 hu(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const P2={done:"Turn finished","needs-input":"Claude is asking"},RV={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function AV({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 Ae;const I=TV(C),O=hu(),H=k&&!E&&!O,[q,$]=w.useState(""),[V,ne]=w.useState("Custom voice"),[ee,M]=w.useState("Your turn"),[Z,K]=w.useState(""),[D,P]=w.useState("1"),[B,W]=w.useState("1"),[F,G]=w.useState([]),[re,U]=w.useState(!1),Y=w.useRef(null),z=w.useRef(null),ie=tV(p),le=((Ae=f.find(fe=>fe.id===ie))==null?void 0:Ae.name)??"the same custom sound",ge=f.length,Ne=H0(ge),Ie=Ne!==null,Ge=Ie?{"aria-disabled":!0,"aria-describedby":"sm-custom-full"}:{},[Pe,Be]=w.useState(null),Te=w.useRef(0),st=w.useRef(new Map),de=w.useRef(null);w.useEffect(()=>{if(!Pe)return;const fe=window.setTimeout(()=>Be(null),4e3);return()=>window.clearTimeout(fe)},[Pe]),w.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const fe=()=>{const Se=window.speechSynthesis.getVoices();G(Se),K(Ye=>{var qe;return Ye||((qe=Se[0])==null?void 0:qe.voiceURI)||""})};return fe(),window.speechSynthesis.addEventListener("voiceschanged",fe),()=>window.speechSynthesis.removeEventListener("voiceschanged",fe)},[]);const ue=async fe=>{$("");try{await fe()}catch(Se){$(Se instanceof Error?Se.message:"Custom audio could not be saved.")}},se=(fe,Se)=>{const Ye=Date.now(),qe=Cu({armedFor:Pe,target:fe,armedAt:Te.current,now:Ye,gapMs:Mu});if(qe==="arm"){Be(fe),Te.current=Ye;return}if(qe==="ignore")return;Be(null);const ke=rV(f.map(Re=>Re.id),fe);ue(async()=>{var ze;await _(fe);const Re=document.activeElement;Re!==Se&&!A0((Re==null?void 0:Re.tagName)??null)||(ze=ke?st.current.get(ke):de.current)==null||ze.focus()})},be=()=>{var fe;z.current!==null&&clearTimeout(z.current),z.current=null,((fe=Y.current)==null?void 0:fe.state)==="recording"&&Y.current.stop()},Le=async()=>{var Se;if(Ie)return;if($(""),!((Se=navigator.mediaDevices)!=null&&Se.getUserMedia)||typeof MediaRecorder>"u"){$("Microphone recording is unavailable in this browser.");return}let fe;try{fe=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{$("Microphone access was denied or unavailable.");return}if(Y.current){fe.getTracks().forEach(Ye=>Ye.stop());return}try{const Ye=["audio/webm;codecs=opus","audio/ogg;codecs=opus","audio/mp4"].find(Re=>MediaRecorder.isTypeSupported(Re)),qe=new MediaRecorder(fe,Ye?{mimeType:Ye}:void 0),ke=[];Y.current=qe,qe.ondataavailable=Re=>{Re.data.size&&ke.push(Re.data)},qe.onerror=()=>$("Recording failed. Please try again."),qe.onstop=()=>{fe.getTracks().forEach(rt=>rt.stop()),z.current!==null&&clearTimeout(z.current),z.current=null;const Re=Y.current===qe;if(Re&&(Y.current=null),U(!1),!Re||!ke.length)return;const ze=qe.mimeType.split(";")[0],Fe=ze==="audio/mp4"?"m4a":ze==="audio/ogg"?"ogg":"webm",We=new File(ke,`Recorded voice.${Fe}`,{type:ze});ue(()=>y(We))},qe.start(200),U(!0),z.current=setTimeout(be,4400)}catch{Y.current=null,fe.getTracks().forEach(Ye=>Ye.stop()),$("This browser cannot record a supported audio format.")}};w.useEffect(()=>()=>{z.current!==null&&clearTimeout(z.current);const fe=Y.current;Y.current=null,(fe==null?void 0:fe.state)==="recording"&&fe.stop()},[]);const ce=pn(e,{popover:!0}),pe=w.useRef(e);return pe.current=e,w.useEffect(()=>{const fe=Se=>{var qe,ke;const Ye=Se.target;Ye&&((qe=ce.current)!=null&&qe.contains(Ye)||(ke=u.current)!=null&&ke.contains(Ye)||pe.current())};return window.addEventListener("pointerdown",fe,!0),()=>window.removeEventListener("pointerdown",fe,!0)},[ce,u]),o.jsxs("div",{ref:ce,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?CV:EV(O)})]})]}),H&&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:qh.map(fe=>{const Se=r[fe],Ye=`sm-level-${fe}`,qe=`sm-figure-${fe}`;return o.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${fe}`,children:[o.jsxs("div",{className:"sm-tone-head",children:[o.jsx("h3",{className:"sm-tone-name",id:`sm-name-${fe}`,children:P2[fe]}),o.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(fe),"aria-label":`Hear the ${P2[fe].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:oi,max:Gl,step:lf,value:Se.level,onChange:ke=>s(fe,Number(ke.target.value)),style:{"--sm-level":`${(Se.level-oi)/(Gl-oi)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[Se.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[fe]?`custom:${p[fe]}`:Se.figure,onChange:ke=>{const Re=ke.target.value;Re.startsWith("custom:")?m(fe,Re.slice(7)):(h(fe),l(fe,Re))},children:[ok[fe].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:RV[fe]})]},fe)})}),ie&&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 ",U0,", 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:de,type:"file",accept:"audio/wav,audio/x-wav,audio/mpeg,audio/mp3,audio/ogg,.wav,.mp3,.ogg",...Ge,onClick:fe=>{Ie&&fe.preventDefault()},onChange:fe=>{var Ye;const Se=(Ye=fe.target.files)==null?void 0:Ye[0];fe.currentTarget.value="",Se&&!Ie&&ue(()=>y(Se))}})]}),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:fe=>{const Se=fe.currentTarget.parentElement;Ie&&Se&&!Se.open&&fe.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:V,maxLength:80,onChange:fe=>ne(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Text"}),o.jsx("input",{className:"ap-manage-input",value:ee,maxLength:180,onChange:fe=>M(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Voice"}),o.jsxs("select",{className:"sm-select",value:Z,onChange:fe=>K(fe.target.value),children:[o.jsx("option",{value:"",children:"System default"}),F.map(fe=>o.jsx("option",{value:fe.voiceURI,children:fe.name},fe.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:D,onChange:fe=>P(fe.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:B,onChange:fe=>W(fe.target.value)})]})]}),o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>{Ie||ue(async()=>{await v({name:V,text:ee,voiceURI:Z,rate:parseFloat(D),pitch:parseFloat(B)}),M("Your turn")})},children:"Add spoken voice"})]})]}),f.length>0&&o.jsx("div",{className:"sm-custom-list",children:f.map(fe=>o.jsxs("div",{className:"sm-custom-item",children:[o.jsx("input",{className:"ap-manage-input","aria-label":`Rename ${fe.name}`,defaultValue:fe.name,maxLength:80,onBlur:Se=>{if(!Se.target.value.trim()){Se.target.value=fe.name;return}ue(()=>S(fe.id,Se.target.value))},onKeyDown:Se=>{Se.key==="Enter"&&Se.currentTarget.blur()}}),o.jsx("span",{children:fe.kind==="audio"?`${fe.duration.toFixed(1)}s`:"Voice"}),o.jsx("button",{type:"button",className:"btn sm-custom-icon","aria-label":`Play ${fe.name}`,onClick:()=>b(fe.id),children:"Play"}),o.jsx("button",{type:"button",ref:Se=>{Se?st.current.set(fe.id,Se):st.current.delete(fe.id)},className:`btn sm-custom-icon${Pe===fe.id?" armed":""}`,onKeyDown:Se=>{Se.repeat&&Se.preventDefault()},onClick:Se=>se(fe.id,Se.currentTarget),"aria-label":Pe===fe.id?`Confirm deleting ${fe.name}`:`Delete ${fe.name}`,title:Pe===fe.id?"Press again to delete this sound. It cannot be brought back.":"Delete this sound",children:Pe===fe.id?"Confirm":"Delete"})]},fe.id))}),q&&o.jsx("p",{className:"sm-custom-error",role:"alert",children:q})]}),o.jsxs("p",{className:"sm-foot",children:[o.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const l$="agent-dag.character-enabled",c$="agent-dag.fm-volume",D2="agent-dag.fm-source",MV=[{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 IV(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 $V(e){return e!=="0"}function OV(){return $V(yr(l$))}function LV(e){return o$(e)}function PV(){return LV(yr(c$))}const F2="agent-dag.fm-custom-stations",q2="agent-dag.fm-muted",K0="custom:",DV=/^UC[A-Za-z0-9_-]{22}$/,FV=/^[A-Za-z0-9_-]{11}$/,ik=/^[A-Za-z0-9_-]{1,80}$/,qV=/\.(mp3|aac|ogg)$/i,BV=/\.m3u8$/i,u$=2048,Lu=80;function yi(e){return`${K0}${e}`}function Yl(e){if(!e.startsWith(K0))return null;const t=e.slice(K0.length);return ik.test(t)?t:null}function B2(e){return Yl(e)??e}function zV(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 lk(e){var c,u;const t=e.trim();if(t.length>u$)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&&DV.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(FV.test(h))return{kind:"youtube-video",url:r,video:h}}return null}return BV.test(n.pathname)?{kind:"direct-audio",url:r,format:"hls"}:qV.test(n.pathname)?{kind:"direct-audio",url:r,format:"audio"}:null}function UV(e){return e==="1"}function HV(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=lk(u);!ik.test(l)||n.has(l)||!c||c.length>Lu||!f||(n.add(l),r.push({id:l,name:c,url:f.url}))}return r}function WV(e,t,n){const r=Yl(e??"");return r&&t.some(s=>s.id===r)?yi(r):n(e)}function VV(e,t){return e===yi(t)?"claude-fm":e}function GV(){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 KV(e,t,n=GV()){const r=e.trim(),s=lk(t);return!r||r.length>Lu||!ik.test(n)||!s?null:{id:n,name:r,url:s.url}}const Sl=["light","dark"],YV={light:"Light",dark:"Dark"},z2=MV,jl="Give the station a name.",XV="Use an https YouTube live or channel link, or a .mp3, .aac, .ogg or .m3u8 stream.";function ZV({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 QV({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 ue;const _=pn(b),k=[...z2.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:yi(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,O]=w.useState(()=>Math.max(0,k.findIndex(se=>se.value===f))),[H,q]=w.useState(!1),[$,V]=w.useState(""),[ne,ee]=w.useState(""),[M,Z]=w.useState(""),[K,D]=w.useState(!1),[P,B]=w.useState(""),[W,F]=w.useState(""),G=w.useRef(null),re=w.useRef(null),U=w.useRef(null),Y=w.useRef(null),z=w.useRef(null),ie=Yl(f),le=ie?h.find(se=>se.id===ie):void 0;w.useEffect(()=>{const se=k.findIndex(be=>be.value===f);O(se<0?0:se)},[f,h,m]),w.useEffect(()=>{D(!1),B((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 ce,pe;const Le=be.target;!((ce=G.current)!=null&&ce.contains(Le))&&!((pe=z.current)!=null&&pe.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&&(O(se),p(be.value),R(!1),(Le=G.current)==null||Le.focus())},Ie=se=>{if(L6(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),O(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=G.current)==null?void 0:se.focus()},Pe=se=>{var Le,ce;if(se.preventDefault(),!$.trim()){Z(jl),(Le=re.current)==null||Le.focus();return}const be=KV($,ne);if(!be){Z(XV),(ce=U.current)==null||ce.focus();return}y(be),p(yi(be.id)),V(""),ee(""),Z(""),q(!1),Ge()},Be=se=>{var be;if(se.preventDefault(),!!ie){if(!P.trim()){F(jl),(be=Y.current)==null||be.focus();return}v(ie,P),D(!1),Ge()}},Te=se=>{var ce;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(se.key))return;se.preventDefault();const Le=(Sl.indexOf(e)+(se.key==="ArrowLeft"||se.key==="ArrowUp"?-1:1)+Sl.length)%Sl.length;t(Sl[Le]),(ce=se.currentTarget.querySelectorAll('[role="radio"]')[Le])==null||ce.focus()},st=se=>{var Le;if(se.key===" "){se.stopPropagation();return}if(Sf(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"]')[Sl.indexOf(be)])==null||Le.focus())},de=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:()=>O(se),onClick:()=>Ne(se),children:[o.jsx("span",{children:be.label}),f===be.value&&o.jsx("span",{"aria-hidden":!0,children:"✓"})]},be.value)};return Mn.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:Te,children:Sl.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(ZV,{theme:se}),o.jsxs("span",{className:"appearance-theme-name",children:[YV[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:G,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:((ue=k.find(se=>se.value===f))==null?void 0:ue.label)??z2[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:z,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(de)]},`group-${be}`):se.indexes.map(de))})]})]}),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?zV(Yl(f)!==null):""}),o.jsxs("div",{className:"appearance-station-manage",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action","aria-expanded":H,onClick:()=>{q(se=>!se),Z("")},children:H?"Cancel":"+ Add station"}),le&&!K&&o.jsxs("span",{className:"appearance-station-edit",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action",onClick:()=>{B(le.name),F(""),D(!0)},children:"Rename"}),o.jsx("button",{type:"button",className:"btn danger appearance-station-action",onClick:()=>{S(le.id),Ge()},children:"Remove"})]})]}),H&&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:$,onChange:se=>V(se.target.value),"aria-invalid":M===jl||void 0,"aria-describedby":M===jl?"appearance-station-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Link"}),o.jsx("input",{ref:U,className:"ap-manage-input",value:ne,onChange:se=>ee(se.target.value),placeholder:"https://…","aria-invalid":M!==""&&M!==jl||void 0,"aria-describedby":M&&M!==jl?"appearance-station-error":void 0,inputMode:"url",autoComplete:"off",spellCheck:!1,maxLength:u$})]}),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&&K&&o.jsxs("form",{className:"appearance-station-form is-rename",onSubmit:Be,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:Y,className:"ap-manage-input",value:P,onChange:se=>B(se.target.value),"aria-invalid":W!==""||void 0,"aria-describedby":W?"appearance-rename-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Save"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{D(!1),Ge()},children:"Cancel"}),W&&o.jsx("p",{id:"appearance-rename-error",className:"appearance-station-error",role:"alert",children:W})]}),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:oi,max:Gl,step:lf,value:s,"aria-describedby":"appearance-fm-volume-note",onChange:se=>l(Number(se.target.value)),style:{"--sm-level":`${(s-oi)/(Gl-oi)*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 Y0="https://www.youtube-nocookie.com";function JV(e,t,n){const r=new URLSearchParams({...n?{}:{channel:e},enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Y0}/embed/${n?encodeURIComponent(n):"live_stream"}?${r.toString()}`}function _l(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function eG(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const tG=[1,3],nG=[0,2],rG=[2,5,100,101,150];function sG(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:tG.includes(s)?{kind:"playing",playing:!0}:nG.includes(s)?{kind:"playing",playing:!1}:null}return null}const d$=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],U2=18,aG=d$.length,h$=new Set(["a","c","p"]);function Xf(e=d$){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 ii=148,H2=6e3,oG=16e3,f$=46,eo=34;function iG(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return{to:r,ms:Math.round(Math.abs(r-e)*f$)}}function lG(e){return Math.round(H2+e()*(oG-H2))}const W2=[{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 cG(e){const t=W2.reduce((r,s)=>r+s.weight,0);let n=e()*t;for(const r of W2)if(n-=r.weight,n<0)return r.kind;return"stroll"}const uG=720,dG=260,hG=620,fG=220,V2=520,p$=1600,G2=7e3,pG=15e3,K2=6e3,mG=14e3;function El(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return r}const hn=(e,t)=>Math.round(Math.abs(t-e)*f$),gG=120,jh=0;function yG(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:hn(e,t)},{x:t,prop:n({}),act:"stoop",ms:uG},{x:jh,prop:n({held:!0}),act:"carry",ms:hn(t,jh)},{x:jh,prop:n({held:!0}),act:"windup",ms:dG},{x:jh,prop:n({held:!0,leaving:!0}),act:"toss",ms:hG}]}function wG(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:hn(e,r)},{x:r,prop:s(),act:"windup",ms:fG,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"kick",ms:V2,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"stand",ms:p$-V2}]}const m$=640;function vG(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:hn(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:hn(r,0)}]}function xG(e,t,n){const r=Math.max(-110,Math.min(-30,t)),s={x:r,prop:null};return[{...s,act:"walk",ms:hn(e,r)},{...s,act:"skip-ready",ms:500},{...s,act:"skip",ms:m$*(6+Math.floor(n()*5))},{...s,act:"skip-rest",ms:600},{...s,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:hn(r,0)}]}function bG(e,t,n){return[{x:t,prop:null,act:"walk",ms:hn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(K2+n()*(mG-K2))},{x:t,prop:null,act:"stand",ms:400}]}function kG(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:hn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(G2+n()*(pG-G2))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function Yx(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 NG=1500,SG=e=>Math.round(1e3*Math.sqrt(2*e/NG)),jG=115,_G=e=>Math.round(e/jG*1e3),EG=620,CG=200,TG=760,RG=600,AG=240;function MG(e,t,n){const s=-(t.ledgeSpan??ii),l=SG(t.ledgeH),c=_G(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:hn(e,s)},{x:s,act:"peer",prop:null,ms:EG},{x:s,act:"fall",prop:null,ms:l,place:"floor"},{x:s,act:"land",prop:null,ms:CG,place:"floor"},{x:p,act:"walk",prop:null,ms:hn(s,p),place:"floor",floorFrac:u},{x:h,act:"walk",prop:null,ms:hn(p,h),place:"floor",floorFrac:f},{x:s,act:"walk",prop:null,ms:hn(h,s),place:"floor"},{x:s,act:"lasso",prop:null,ms:TG,place:"floor"},{x:s,act:"rope-throw",prop:null,ms:RG,place:"floor"},{x:s,act:"rope-catch",prop:null,ms:AG,place:"floor"},{x:s,act:"climb",prop:null,ms:c},{x:s,act:"pull-up",prop:null,ms:480}]}function IG(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??ii;switch(cG(t)){case"tidy":return yG(e,El(e,t,r));case"kick":return wG(e,El(e,t,r));case"sit":return bG(e,El(e,t,r),t);case"watch":return kG(e,El(e,t,r),t);case"fish":return vG(e,El(e,t,r),t);case"skip":return xG(e,El(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return MG(e,n,t)}}const l=iG(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const $G=[".xx.","xxxx",".xx."],OG=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],LG=["...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."],Xx={litter:$G,ball:OG,scope:LG},g$=["bob","sway","groove"],Y2=9e3,PG=16e3,y$=1e3,DG=.08;function FG(e,t){const n=g$.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],s=(t()*2-1)*DG;return{dance:r,beatMs:Math.round(y$*(1+s))}}function qG(e){return Math.round(Y2+e()*(PG-Y2))}const BG=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],zG=3,UG=-1,X0=11,X2=9,HG=420;function WG(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(HG,Math.max(0,r))}const VG=260,GG=200;function KG(e,t,n){const r=(h,m=hn(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,hn(e,u)),{...p,x:u,act:"mount",ms:VG},{...p,x:f,act:"walk",ms:hn(u,f)},{x:f,prop:null,act:"dismount",ms:GG,place:"floor"},{x:t,prop:null,act:"walk",ms:hn(f,t),place:"floor"}]}function Z2(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 YG={"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 XG(e,t){return t&&yi(t.id)===e?t.name:Yl(e)?"Custom FM":YG[e]}const ZG={"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 Zx(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:Xf(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 Qx={e:"fm-eye",s:"fm-shade",p:"fm-pad"},cf=Xf().filter(e=>!h$.has(e.cell)),QG=Xf().filter(e=>h$.has(e.cell)),Q2=cf.filter(e=>e.cell==="e"),JG=Xf(BG),eK=cf.filter(e=>e.y<X0&&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),tK={left:cf.filter(e=>e.y>=X0&&e.x<X2),right:cf.filter(e=>e.y>=X0&&e.x>=X2)},J2={litter:Zx(Xx.litter,"litter"),ball:Zx(Xx.ball,"ball"),scope:Zx(Xx.scope,"scope")};function nK(e){try{return new URL(e).host}catch{return"the station's server"}}const rK=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),[O,H]=w.useState(null),[q,$]=w.useState(null),[V,ne]=w.useState({x:0,drop:0}),[ee,M]=w.useState("ledge"),[Z,K]=w.useState("left"),[D,P]=w.useState(0),B=w.useRef(null),[W,F]=w.useState(()=>document.hidden);w.useEffect(()=>{const de=new Set,ue=()=>{var se;if(document.hidden){for(const be of((se=B.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),de.add(be)}}else{for(const be of de)be.playState==="paused"&&be.play();de.clear()}F(document.hidden)};return ue(),document.addEventListener("visibilitychange",ue),()=>document.removeEventListener("visibilitychange",ue)},[f,h]);const[G,re]=w.useState(null),[U,Y]=w.useState(y$),[z,ie]=w.useState(()=>{var de;return((de=window.matchMedia)==null?void 0:de.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});w.useEffect(()=>{var se;const de=(se=window.matchMedia)==null?void 0:se.call(window,"(prefers-reduced-motion: reduce)");if(!de)return;const ue=()=>ie(de.matches);return ue(),de.addEventListener("change",ue),()=>de.removeEventListener("change",ue)},[]);const le=w.useRef(null),ge=w.useCallback(()=>{var ue;(ue=j.current)==null||ue.destroy(),j.current=null;const de=k.current;de&&(de.pause(),de.removeAttribute("src"),de.load(),k.current=null)},[]),Ne=w.useCallback(de=>{var ue,se;(se=(ue=le.current)==null?void 0:ue.contentWindow)==null||se.postMessage(de,Y0)},[]),Ie=w.useRef(n);Ie.current=n;const Ge=w.useRef(r);Ge.current=r;const Pe=w.useCallback((de,ue,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,ce=()=>{ge(),v(!1),b(!1)},pe=()=>{Le()&&(ce(),m(!0),u==null||u(se,!0))},Ae=fe=>{if(Le()){if(fe instanceof DOMException&&fe.name==="NotAllowedError"){ce();return}pe()}};be.addEventListener("playing",()=>{Le()&&(b(!0),u==null||u(se,!1))}),be.addEventListener("ended",()=>{Le()&&ce()}),be.addEventListener("error",pe,{once:!0}),ue&&!be.canPlayType("application/vnd.apple.mpegurl")?nb(async()=>{const{default:fe}=await import("./hls-BFpXDghs.js");return{default:fe}},[]).then(({default:fe})=>{if(!Le())return;if(!fe.isSupported()){pe();return}const Se=new fe;j.current=Se,Se.on(fe.Events.ERROR,(Ye,qe)=>{qe.fatal&&pe()}),Se.on(fe.Events.MEDIA_ATTACHED,()=>Se.loadSource(de)),Se.on(fe.Events.MANIFEST_PARSED,()=>{be.play().catch(Ae)}),Se.attachMedia(be)},pe):(be.src=de,be.play().catch(Ae))},[u,ge]);if(w.useEffect(()=>{y&&(Ne(_l("setVolume",[n])),Ne(_l(r?"mute":"unMute")),k.current&&(k.current.volume=n/100,k.current.muted=r))},[n,r,y,Ne]),w.useEffect(()=>{let de=!0;const ue=t??fetch,se=_.current!==l;_.current=l,p(null),m(!1),v(se),b(se),ge();const be=c&&yi(c.id)===s?lk(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),()=>{de=!1}):(ue(`/api/fm-station?url=${encodeURIComponent(be.url)}`).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.channel||pe!=null&&pe.video?(p({live:!0,channel:pe.channel??"",video:pe.video??void 0}),u==null||u(s,!1)):(m(!0),u==null||u(s,!0)))}).catch(()=>{de&&(m(!0),u==null||u(s,!0))}),()=>{de=!1});if(Yl(s))return m(!0),u==null||u(s,!0),()=>{de=!1};const Le=s,ce=ZG[Le];if(ce)ue(ce).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.video&&p({live:!0,channel:"",video:pe.video}),u==null||u(s,!(pe!=null&&pe.video)))}).catch(()=>{de&&(u==null||u(s,!0))});else if(Le!=="claude-fm"){const pe=Le.replace("lofi-","");ue(`/api/lofi-girl?station=${encodeURIComponent(pe)}`).then(Ae=>Ae.ok?Ae.json():null).then(Ae=>{de&&(Ae!=null&&Ae.video&&p({live:!0,channel:"",video:Ae.video}),u==null||u(s,!(Ae!=null&&Ae.video)))}).catch(()=>{de&&(u==null||u(s,!0))})}else ue("/api/claude-fm").then(pe=>pe.ok?pe.json():null).then(pe=>{if(!de)return;const Ae=!!(pe!=null&&pe.live&&(pe!=null&&pe.channel));Ae&&p({live:!0,channel:pe.channel}),u==null||u(s,!Ae)}).catch(()=>{de&&(u==null||u(s,!0))});return()=>{de=!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 de=ue=>{var be;if(ue.origin!==Y0||ue.source!==((be=le.current)==null?void 0:be.contentWindow))return;const se=sG(ue.data);if(se){if(se.kind==="ready"){Ne(_l("setVolume",[Ie.current])),Ne(_l(r?"mute":"unMute")),Ne(_l("playVideo"));return}if(se.kind==="playing"){b(se.playing);return}rG.includes(se.code)&&(v(!1),b(!1),m(!0),u==null||u(s,!0))}};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[y,r,u,Ne,s]),w.useEffect(()=>{var ze;if(!f||h||z)return;const de=Z2(document);let ue=0;C(Fe=>ue=Fe);let se=null,be=0,Le=0;const ce=Fe=>{var yt,Ot;const[We,...rt]=Fe;if(!We){se=null,H(null),$(null),qe();return}H(We.act),$(We.prop),M(We.place??"ledge"),P(We.riser??0);const dt=ue,ct=Se(We);if(We.act==="kick"){const zt=(Ot=(yt=B.current)==null?void 0:yt.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:Ot.getBoundingClientRect();zt&&ne({x:WG(zt.x,Yx(We,dt,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-zt.y+24)})}Le=We.act==="walk"?Math.max(hn(dt,ct),gG):We.ms,We.act==="carry"&&(Le=hn(dt,ct)),I(Le),K(zt=>Yx({...We,x:ct},dt,zt)),C(ct),ue=ct,se=We,be=Date.now(),de.schedule(()=>ce(rt),Le)},pe=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-sprite"),rt=Fe==null?void 0:Fe.parentElement;if(!Fe||!We||!rt)return null;const dt=Fe.getBoundingClientRect(),ct=rt.getBoundingClientRect(),yt=ct.right-dt.right,Ot=ct.width-yt*2-We.offsetWidth;return Ot>0?Ot:null},Ae=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-walker"),rt=pe();if(!Fe||!We||rt==null)return;const dt=Fe.getBoundingClientRect().bottom-We.getBoundingClientRect().bottom;if(dt>0)return{ledgeH:dt,floorSpan:rt}},fe=()=>{const Fe=B.current,We=document.querySelector(".autofit-chip");if(!Fe||!We)return null;const rt=Fe.getBoundingClientRect(),dt=We.getBoundingClientRect();return dt.width<=0||dt.height<=0?null:{left:dt.left-rt.right,right:dt.right-rt.right,height:dt.height}},Se=Fe=>{const We=(Fe.place??"ledge")==="floor",rt=We?pe()??ii:ii,dt=We&&Fe.floorFrac!=null?-Math.round(Fe.floorFrac*rt):Fe.x;return Math.max(-rt,Math.min(0,dt))},Ye=()=>{if(!se)return;const Fe=Se(se);Fe!==ue&&(I(Math.max(0,be+Le-Date.now())),K(We=>Yx({...se,x:Fe},ue,We)),C(Fe),ue=Fe)},qe=()=>{de.schedule(()=>{const Fe=IG(ue,Math.random,Ae()),We=Fe.some(ct=>ct.place==="floor")?fe():null;let rt=ue;const dt=Fe.flatMap(ct=>{const yt=rt;if(rt=ct.x,!(ct.place==="floor"&&ct.act==="walk"))return[ct];const Ot=KG(yt,ct.x,We),zt=Ot.length-1;return ct.floorFrac==null?Ot:Ot.map((Xt,Dt)=>Dt===zt?{...Xt,floorFrac:ct.floorFrac}:Xt)});ce(dt)},lG(Math.random))},ke=(ze=B.current)==null?void 0:ze.parentElement,Re=typeof ResizeObserver>"u"?null:new ResizeObserver(Ye);return ke&&Re&&Re.observe(ke),qe(),()=>{de.dispose(),Re==null||Re.disconnect(),M("ledge"),C(Fe=>Math.max(-ii,Math.min(0,Fe))),I(0),H(null),$(null),P(0)}},[f,h,z]),w.useEffect(()=>{if(!S||z){re(null);return}const de=Z2(document),ue=se=>{const be=FG(se,Math.random);re(be.dance),Y(be.beatMs),de.schedule(()=>ue(be.dance),qG(Math.random))};return ue(null),()=>de.dispose()},[S,z]),!f||h)return null;const Be=()=>{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 de=!S;b(de),Ne(_l(de?"playVideo":"pauseVideo")),de||v(!1)},Te=XG(s,c),st=f.audio?nK(f.audio):"YouTube";return o.jsxs("div",{ref:B,className:"fm","data-suspended":W?"":void 0,"data-place":ee,style:{"--fm-beat":`${U}ms`},children:[q&&!q.held&&o.jsx("div",{className:"fm-prop","data-prop":q.kind,"data-leaving":q.leaving?"":void 0,style:{"--fm-prop-x":`${q.at}px`,"--fm-roll-to":`${V.x}px`,"--fm-ball-drop":`${V.drop}px`,"--fm-ball-flight-ms":`${p$}ms`,"--fm-ball-turn":Z==="right"?"1080deg":"-1080deg"},children:J2[q.kind]}),(O==="lasso"||O==="rope-throw"||O==="rope-catch"||O==="climb"||O==="pull-up")&&o.jsxs("div",{className:"fm-rope","data-act":O,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":O??void 0,"data-place":ee,"data-facing":Z,style:{"--fm-x":`${E}px`,"--fm-walk-ms":`${R}ms`,"--fm-riser":`${D}px`,"--fm-skip-beat":`${m$}ms`},children:[(q==null?void 0:q.held)&&o.jsx("div",{className:"fm-held","data-prop":q.kind,"data-toss":q.leaving?"":void 0,children:J2[q.kind]}),["cast","fish","reel","stow"].includes(O)&&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)&&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?G??g$[0]:void 0,onClick:Be,title:S?`Stop ${Te}`:`Play ${Te} — streams from ${st}`,"aria-label":S?`Stop ${Te}`:`Play ${Te}`,children:o.jsxs("svg",{viewBox:`0 0 ${U2} ${aG}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("g",{className:"fm-gear",children:o.jsx("g",{className:"fm-gear-motion",children:QG.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`g${de.y}-${de.x}`))})}),o.jsxs("g",{className:"fm-body",children:[Q2.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,fill:"var(--accent)"},`eye-bed-${de.x}`)),eK.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`b${de.y}-${de.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"})]}),Q2.map(de=>o.jsx("rect",{x:de.x-(de.x>=U2/2?1:0)+(Z==="right"?1:0),y:de.y,width:de.w,height:1,className:"fm-eye"},`eye-${de.x}`))]}),o.jsx("g",{className:"fm-hat",children:JG.map(de=>o.jsx("rect",{x:zG+de.x,y:UG+de.y,width:de.w,height:1,className:de.cell==="k"?"fm-hatband":void 0},`h${de.y}-${de.x}`))}),(O==="climb"||O==="rope-throw"||O==="rope-catch"||O==="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"})]}),(O==="land"||O==="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)&&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(de=>o.jsx("g",{className:"fm-leg","data-side":de,children:tK[de].map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:Qx[ue.cell]},`${de}${ue.y}-${ue.x}`))},de))]})})]}),y&&!f.audio&&(f.channel||f.video)&&o.jsx("iframe",{ref:le,className:"fm-frame",title:Te,src:JV(f.channel,window.location.origin,f.video),onLoad:()=>Ne(eG()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),sK=15e3;function aK(e){return e.visibilityState==="visible"&&e.hasFocus()}function oK(e,t){return t||e===!0}function iK(){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 lK={"//":["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.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 Cm(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const jz={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."},_z={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function WS(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||un(n,t)}function Ez({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=pn(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,O]=w.useState(()=>Date.now());w.useEffect(()=>{const re=window.setInterval(()=>O(Date.now()),1e3);return()=>window.clearInterval(re)},[]);const H=w.useRef(!0);w.useEffect(()=>()=>{H.current=!1},[]);const q=w.useRef(null),$=w.useCallback(re=>Tf(q.current)?(q.current=re,E(re),!0):!1,[]),V=w.useCallback(()=>{q.current=null,H.current&&E(null)},[]),ne=re=>{const U=ao(j,re);return{disabled:U.disabled,"aria-busy":U.busy}},ee=re=>(S==null?void 0:S.field)===re?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},M=re=>b(U=>U&&U.field===re?null:U),Z=w.useCallback(async()=>{if(f)return;const re=zz(h);if(!re){b({text:Cz(h),field:"addr"});return}const U=`${re.addr}:${re.port}`,Y=e.peers.find(z=>z.addr===re.addr&&z.port===re.port&&z.paired);if(Y){b({text:`Already paired with ${Y.name} at that address.`,field:"addr"});return}if(t.includes(U)){b({text:"This deck already calls that address.",field:"addr"});return}if($("add"))try{const z=await Cm("/api/prefs",{lan:{manual:[...t,U]}});if(!H.current)return;z!=null&&z.ok?(b(null),m(""),s(),r()):b({text:un("add that address",z),field:"addr"})}catch{H.current&&b({text:un("add that address",null),field:"addr"})}finally{V()}},[h,f,t,e.peers,s,r,$,V]),K=w.useCallback(async re=>{if(!$(`invite:${re}`))return;const U=re==="make"?"make an invite":"cancel that invite";try{const Y=await Cm("/api/lan/invite",{action:re});if(!H.current)return;Y!=null&&Y.ok?(b(null),k(null),s()):b({text:WS(_z,Y,U)})}catch{H.current&&b({text:un(U,null)})}finally{V()}},[s,$,V]),D=w.useCallback(async()=>{const re=y.trim();if(!(!re||!$("join"))){R(null);try{const U=await Cm("/api/lan/invite",{action:"join",token:re});if(!H.current)return;U!=null&&U.ok?(v(""),b(null),s(),r()):(U==null?void 0:U.reason)==="unreachable"&&Array.isArray(U.tried)&&U.tried.length?(R(U.tried),b(null)):(R(null),b({text:WS(jz,U,"use that invite"),field:"join"}))}catch{H.current&&b({text:un("use that invite",null),field:"join"})}finally{V()}}},[y,s,r,$,V]),P=w.useCallback(async(re,U)=>{try{await navigator.clipboard.writeText(re),k(U),window.setTimeout(()=>{H.current&&k(Y=>Y===U?null:Y)},1600)}catch{b({text:"Could not copy it — select the text and copy it by hand."})}},[]),B=e.invite&&e.invite.expiresAt>I?e.invite:null,W=w.useRef(!1);w.useEffect(()=>{n!=="invite"||W.current||B||(W.current=!0,K("make"))},[n,B,K]);const F=w.useRef(!1);w.useEffect(()=>{var re;n!=="invite"||F.current||!B||(F.current=!0,(re=u.current)==null||re.focus())},[n,B]);const G=e.port!=null?(e.addrs??[]).map(re=>`${re}:${e.port}`):[];return Mn.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(WM,{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"&&Z()}}),h.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("add"),onClick:()=>void Z(),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&&G.length>0&&o.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",G.map((re,U)=>o.jsxs("span",{children:[U>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 P(G.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",!B&&o.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...ne("invite:make"),onClick:()=>void K("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"&&D()}}),y.trim()!==""&&o.jsx("button",{type:"button",className:"ap-manage-btn",...ne("join"),onClick:()=>void D(),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))]}),B&&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:[Yz(B.expiresAt,I)," left"]})]}),o.jsx("code",{className:"ap-lan-token",children:B.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 P(B.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 K("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 Cz(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 Tz=1e3;function Rz(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 VS(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function Az(){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 GS(){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 bh({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 Mz={works:"works here",expired:"expired here",missing:"not on this deck",unavailable:"cannot share here"},Iz={works:"works there",broken:"broken there",unavailable:"cannot share there",unknown:"not offered by that deck"};function $z(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Mz[e.here]}, ${Iz[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Oz({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 Ot,zt,Xt,Dt,rn;const S=w.useRef(null),b=pn(c,{focusRef:S}),[_,k]=w.useState(null),[j,E]=w.useState(null),[C,R]=w.useState(!1),I=w.useRef(0),[O,H]=w.useState(null),[q,$]=w.useState(!1),[V,ne]=w.useState(0),ee=w.useRef(null),M=w.useRef(!0);w.useEffect(()=>()=>{M.current=!1},[]);const Z=_!=null;w.useEffect(()=>{var je;Z&&((je=ee.current)==null||je.select())},[Z]),w.useEffect(()=>{if(!C)return;const je=window.setTimeout(()=>R(!1),4e3);return()=>window.clearTimeout(je)},[C]),w.useEffect(()=>{if(!O)return;const je=window.setTimeout(()=>H(null),4e3);return()=>window.clearTimeout(je)},[O]);const K=je=>{const xt=ao(l,je);return{disabled:xt.disabled,"aria-busy":xt.busy}},D=async je=>{const xt=await je();return M.current&&E(xt),xt==null},{peer:P,stranger:B}=t,W=e.kind==="paired",F=e.self??e.name,G=e.kind!=="dialling",re=e.kind==="dialling"?null:e.fp,U=P?P.addr?`${P.addr}:${P.port}`:"":B?B.port?`${B.addr}:${B.port}`:B.addr:e.addr,Y=(P==null?void 0:P.about)??null,z=((Ot=n.about)==null?void 0:Ot.version)??null,ie=async je=>{const xt=je.trim()===F?"":je;await D(()=>u(xt))&&k(null)},le=async()=>{if(re)try{if(await navigator.clipboard.writeText(re),!M.current)return;$(!0),window.setTimeout(()=>{M.current&&$(!1)},1600)}catch{M.current&&E("Could not copy it — select the fingerprint and copy it by hand.")}},ge=W?P!=null&&P.waiting?P.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":P!=null&&P.offers?"not said — it runs an older version":"not reached yet":"shown once paired",Ne=VS(n.about),Ie=VS(Y),Ge=Y!=null&&Y.version&&z?sU(Y.version,z):null,Pe=P?qb(P.last,s):null,Be=P&&((zt=P.last)!=null&&zt.error)?Bz({error:P.last.error,host:P.addr,port:P.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(je=>!je.manual&&je.addr).map(je=>({fp:je.fp,name:je.name,addr:je.addr,port:je.port,at:je.lastSeen??0}))],s):null,Te=(Xt=P==null?void 0:P.last)!=null&&Xt.error&&Pe&&Pe.text!==P.last.error?P.last.error:null,st=((Dt=P==null?void 0:P.last)==null?void 0:Dt.done)??[],de=!!Pe&&!!Te&&!e.quiet&&e.state.startsWith(Pe.text),ue=W||e.kind==="dialling",se=((P==null?void 0:P.via)??e.via)==="tailscale",be=P?P.waiting?null:P.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":W?e.here?"up":"down":"loose",ce=l===`check:${e.fp}`,pe=(P==null?void 0:P.offers)??null,Ae=Le==="up"?(pe==null?void 0:pe.current)??null:null,fe=Ae&&"key"in Ae?Ae.key:null,Se=!!Ae&&"hidden"in Ae,Ye=!!Ae&&"other"in Ae,qe=W?oU((pe==null?void 0:pe.accounts)??null,r,n.shared??[],fe):[],ke=qe.filter(je=>je.in==null&&je.out==="cut"),Re=qe.some(je=>je.in!=null),ze=qe.some(je=>je.out!=null),Fe=new Map(st.map(je=>[je.email,je])),We=st.filter(je=>!qe.some(xt=>xt.email===je.email)),rt=W?pe?pe.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:P!=null&&P.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=P==null?void 0:P.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,dt=pe&&(P!=null&&P.last)&&P.last.at-pe.at>Tz?qs(pe.at,s):null,ct=[];W&&(P!=null&&P.pairedAt)?ct.push({label:"Paired",value:Rz(P.pairedAt,s),tone:"meta"}):e.kind==="declined"&&B&&ct.push({label:"Paired",value:`no · you said no ${Bb(B.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":q?"Fingerprint copied":"Copy the fingerprint",children:q?"copied":"copy"})]}):"not known — nothing has answered there",tone:re?void 0:"quiet"});const yt=y.length?[{row:e,peer:P??null},...y]:[];return Mn.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:je=>je.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:[Z?o.jsxs("form",{className:"lan-peer-edit",onSubmit:je=>{je.preventDefault(),ie(_??"")},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:F,"aria-label":"Name for this deck, shown on this deck only",onChange:je=>k(je.target.value)}),o.jsx("button",{type:"submit",className:"ap-manage-btn",...K(`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}),G&&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(Az,{})})]}),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}),Z&&o.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...K(`alias:${e.fp}`),onClick:()=>void ie(""),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":ce||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}),W&&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??(Y?"not said":ge),Ge?` · ${Ge<0?"older":"newer"}`:null]}),Se&&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(GS,{}),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:U?o.jsx("code",{className:"ap-lan-code",children:U}):"none here — it calls this deck"})]}),o.jsx(GS,{}),(U&&be||ue)&&o.jsxs("p",{className:"lan-link-sub",children:[U&&be,U&&be&&ue&&" · ",ue&&(Pe?de?o.jsx("code",{className:"ap-lan-code",children:Te}):o.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),ue&&Te&&!de&&o.jsx("code",{className:"lan-fact-raw",children:Te})]}),We.length>0&&o.jsx("ul",{className:"lan-done",children:We.map(je=>{const xt=F0(je);return o.jsxs("li",{"data-ok":je.ok&&!xt,children:[je.email," ",o.jsxs("span",{className:"lan-done-what",children:[je.ok?"arrived":"did not arrive",xt&&` — ${xt.long}`]})]},`${je.email}:${je.action}`)})}),Be&&o.jsx("p",{className:"lan-note lan-link-note",children:Be}),(P==null?void 0:P.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((je,xt)=>{const bt=Fe.get(je.email),_n=bt?F0(bt):null,Ut=je.out==="live"||je.in!=null&&je.in!=="cut";return o.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":je.tone,"data-draw":je.in&&je.out?"both":je.in?"in":"out","data-used-there":je.usedThere||void 0,style:{"--i":xt},children:[o.jsx("i",{className:"lan-pip","data-end":"here","data-state":je.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:[(je.in==="live"||je.in==="wait")&&o.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":je.in}),je.out==="live"&&o.jsx("i",{className:"lan-glint","data-dir":"out"})]}),je.in&&je.in!=="cut"&&o.jsx(bh,{dir:"in",gate:je.in==="blocked"}),je.out==="live"&&o.jsx(bh,{dir:"out"}),o.jsx("span",{className:"lan-lane-email",children:je.email})]}),o.jsx("i",{className:"lan-pip","data-end":"there","data-state":je.there,"aria-hidden":!0}),o.jsx("span",{className:"vis-hidden",children:$z(je)}),(je.caption||bt)&&o.jsxs("span",{className:"lan-lane-note",children:[je.caption,je.caption&&bt&&" · ",bt&&o.jsxs("span",{className:"lan-lane-done","data-ok":bt.ok&&!_n,children:[bt.ok?"arrived last round":"did not arrive last round",_n&&` — ${_n.long}`]})]})]},je.key)})},V),W&&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}),dt&&o.jsxs("p",{className:"lan-stale",children:["As of ",dt==="now"?"just now":dt,", when it last answered."]}),o.jsxs("div",{className:"lan-legend",children:[Re&&o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:o.jsx(bh,{dir:"in"})}),"from ",e.name]}),ze?o.jsxs("span",{className:"lan-key",children:[o.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:o.jsx(bh,{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(je=>o.jsxs("div",{className:"lan-fact","data-tone":je.tone,children:[o.jsx("dt",{children:je.label}),o.jsx("dd",{children:je.value})]},je.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((je,xt)=>{var Lt,Zt,In,Hr;const bt=(Lt=je.peer)!=null&&Lt.addr?`${je.peer.addr}:${je.peer.port}`:je.row.addr,_n=bt||je.row.fp,Ut=(Zt=je.peer)!=null&&Zt.pairedAt?qs(je.peer.pairedAt,s):null,Vn=[(Hr=(In=je.peer)==null?void 0:In.about)!=null&&Hr.version?`runs ${je.peer.about.version}`:null,Ut?`paired ${Ut==="now"?"just now":Ut}`:null,je.row.state].filter(Boolean).join(" · "),Vt=je.row.fp;return o.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":je.row.tone,children:[o.jsx("i",{className:je.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),bt?o.jsx("code",{className:"ap-lan-code lan-twin-at",children:bt}):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}),xt>0&&v&&o.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${O===Vt?" armed":""}`,...K(`unpair:${Vt}`),onKeyDown:xe=>{xe.repeat&&xe.preventDefault()},onClick:()=>{const xe=Date.now(),lr=Cu({armedFor:O,target:Vt,armedAt:I.current,now:xe,gapMs:Mu});if(lr==="arm"){H(Vt),I.current=xe;return}lr!=="ignore"&&(H(null),D(()=>v(Vt)))},"aria-label":O===Vt?`Confirm unpairing ${_n}`:`Unpair ${_n}`,title:O===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…":O===Vt?"confirm":"unpair"}),o.jsx("span",{className:"lan-twin-meta",children:xt===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."}),W&&!(P!=null&&P.waiting)&&o.jsx("button",{type:"button",className:"btn",...K(`check:${e.fp}`),onClick:()=>void D(f).then(je=>{je&&M.current&&ne(xt=>xt+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":""}`,...K(`unpair:${e.fp}`),onKeyDown:je=>{je.repeat&&je.preventDefault()},onClick:()=>{const je=Date.now(),xt=Cu({armedFor:C?e.fp:null,target:e.fp,armedAt:I.current,now:je,gapMs:Mu});if(xt==="arm"){R(!0),I.current=je;return}xt!=="ignore"&&(R(!1),D(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",...K(`accept:${e.fp}`),onClick:()=>void D(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",...K(`drop:${e.fp}`),onClick:()=>void D(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",...K(`allow:${e.fp}`),onClick:()=>void D(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 Lz(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 kh="Paused while this deck pairs only by invite. Turn that off above to use it.";function Pz({status:e,accounts:t,onClose:n,onChanged:r}){const s=pn(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 Z=ao(m,M);return{disabled:Z.disabled,"aria-busy":Z.busy}},b=w.useRef(null),_=w.useRef(!0);w.useEffect(()=>()=>{_.current=!1},[]),w.useEffect(()=>{b.current=XS(b.current,e.shared??[],null)},[e.shared]);const k=w.useCallback(async(M,Z,K="write")=>{v.current=K,y(K);try{const P=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:M})})).json().catch(()=>null);return _.current?(P!=null&&P.ok?f(null):f(un(Z,P)),r(),(P==null?void 0:P.ok)===!0):!1}catch{return _.current&&f(un(Z,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 hi(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,O=e.pairingMode==="invite",H=M=>{const Z=S(M);return{...Z,disabled:Z.disabled||O}},q=e.shareActive!==!1,$=e.tailscale??null,V=!!($!=null&&$.on),ne=($==null?void 0:$.ask)!==!1,ee=($==null?void 0:$.accept)!==!1;return Mn.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:Z=>{const K=Kz(b.current,e.shared??[],M.key,Z.target.checked);b.current=K,k({shared:K},Z.target.checked?"share that account":"stop sharing that account").then(D=>{b.current===K&&(b.current=XS(K,e.shared??[],{ok:D}))})}}),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":q,"aria-label":"Show paired decks which of these this deck is using",...S("current"),onClick:()=>void k({shareActive:!q},q?"stop showing which account this deck is using":"show which account this deck is using","current"),title:q?"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&&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":O,"aria-label":"Pair new decks only by invite","aria-describedby":O?"lan-invite-only-detail":void 0,...S("mode"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({pairingMode:O?"automatic":"invite"},O?"let decks pair on their own again":"pair new decks only by invite","mode"),title:O?"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&&o.jsx("span",{className:"lan-sub-state",children:" · paused while pairing is invite-only"})]}),o.jsxs("div",{className:"lan-switches","data-paused":O||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",...H("ask"),onClick:()=>void k({autoAsk:!R},R?"stop asking automatically":"ask every deck this one finds","ask"),title:O?kh: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",...H("accept"),onKeyDown:M=>{M.repeat&&M.preventDefault()},onClick:()=>void k({autoAccept:!I},I?"stop accepting automatically":"accept every deck that asks","accept"),title:O?kh: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"})})]})]})]})]}),($==null?void 0:$.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:Lz($)})]}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":V,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",...S("tailscale"),onClick:()=>void k({tailscale:!V},V?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:V?"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"})})]}),V&&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&&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":O||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",...H("tailscale-ask"),onClick:()=>void k({tailscaleAsk:!ne},ne?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:O?kh: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":O||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",...H("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:O?kh: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 KS={keychain_unavailable:{short:"Keychain locked on the other Mac",long:`the other Mac could not export it. On that Mac: ${Lb}. The next round brings it.`}};function F0(e){return e.why?Object.hasOwn(KS,e.why)?KS[e.why]:tf(e.why):null}const Fb={"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"}},Dz={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 YS(e){var r;const t=Fz[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&Dz[n]||e}const Fz={"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 qb(e,t){var h;if(!e)return null;if(e.error&&((h=e.done)!=null&&h.length)){const m=qb({...e,error:void 0},t),y=` · ${qs(e.at,t)}`;return{...m,text:`${m.text.slice(0,-y.length)}, then ${YS(e.error)}${y}`,tone:"bad"}}if(e.error)return Fb[e.error]??{text:YS(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:F0(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 qz=9e4;function Bz({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<qz);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 q0=5e3,VM=6e4,Mu=400;function zz(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 un(e,t){if(t==null)return`Could not ${e} — the deck did not answer.`;const n=t.reason?Wz(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 Uz={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."},Hz=new Set(["EACCES","EPERM"]);function Wz(e,t){const n=Uz[e];if(!n)return;const r=e==="prefs_unreadable"&&t?Vz(t):void 0,s=t!=null&&t.code&&t.code!=="BADJSON"?` Error code: ${t.code}.`:"";return(r??n)+s}function Vz({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&&!Hz.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 Gz(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function Kz(e,t,n,r){const s=new Set(e??t);return r?s.add(n):s.delete(n),[...s]}function XS(e,t,n){return e==null||n!=null&&!n.ok||Gz(e,t)?null:e}function Yz(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function GM(e,t){var n,r;return(n=e.last)!=null&&n.error&&!Fb[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<rf||e.lastSeen!=null&&t-e.lastSeen<rf)}const rf=95e3,KM=160,Xz=6,YM=140;function Zz(e,t){const n=[],r=[];for(const s of e??[])(GM(s,t)?n:r).push(s);return{online:n,offline:r}}function Qz(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 Jz(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<rf}),{online:u,offline:f}=Zz(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 eU(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 Bb(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 tU(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<rf;return{text:n?"online · one-way, it calls in":`one-way · last online ${qs(e,t)}`,here:n}}function ZS(e,t,n){return t?"online":e.lastSeen!=null?`last online ${qs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function nU(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 · ${Bb(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=qb(k.last,t),C=GM(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?tU(k.lastSeen,t):null,O=I?I.here:C,H=!I&&E?O?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${ZS(k,O,t)}`:I?I.text:ZS(k,O,t),q=(v=k.last)!=null&&v.error?Fb[k.last.error]:null,$=!I&&O&&!((S=k.last)!=null&&S.error)&&!(((b=k.last)==null?void 0:b.done)??[]).length,V=k.manual&&!k.met?{name:R}:c(j,k.name||j);u.push({fp:j,name:V.name,...V.self?{self:V.self}:{},addr:k.addr??"",kind:"paired",state:H,quiet:$,tone:q?q.tone==="bad"?"bad":"wait":E?E.tone:O?"ok":"idle",here:I?I.here:C,...k.via==="tailscale"?{via:"tailscale"}:{},hint:I?`${V.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.`:`${V.name}${R?` at ${R}`:""}${(_=k.last)!=null&&_.error?` — ${k.last.error}`:""}${E!=null&&E.hint?` — ${E.hint}`:""}`})}n.push(...rU(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 rU(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(QS(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(QS(r))}return n}function QS(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 JS(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function ej(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 sU(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 aU(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 oU(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=aU(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 Nl(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function iU({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,Xz),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=$b(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]),Mn.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 lU(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 cU({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),O=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(O.current),[]);const[H,q]=w.useState(!1),[$,V]=w.useState(null),ne=w.useRef(null),ee=w.useCallback(ce=>Tf(ne.current)?(ne.current=ce,m(ce),!0):!1,[]),M=w.useCallback(()=>{ne.current=null,P.current&&m(null)},[]),Z=ce=>{const pe=ao(h,ce);return{disabled:pe.disabled,"aria-busy":pe.busy}},[K,D]=w.useState(()=>Date.now()),P=w.useRef(!0),B=w.useRef(q0),W=w.useCallback(async()=>{var ce,pe;try{const[Ae,fe]=await Promise.all([fetch("/api/lan").then(Se=>Se.json()),fetch("/api/prefs").then(Se=>Se.json())]);if(!P.current)return;Ae!=null&&Ae.ok&&u(Ae),fe!=null&&fe.ok&&p(Array.isArray((pe=(ce=fe.prefs)==null?void 0:ce.lan)==null?void 0:pe.manual)?fe.prefs.lan.manual:[]),B.current=(Ae==null?void 0:Ae.enabled)===!0?q0:VM}catch{}},[]);w.useEffect(()=>{P.current=!0;let ce=0;const pe=async()=>{D(Date.now()),await W(),P.current&&(ce=window.setTimeout(pe,B.current))};return pe(),()=>{P.current=!1,window.clearTimeout(ce)}},[W]);const F=w.useCallback(async()=>{const ce=(c==null?void 0:c.enabled)===!0;if(ee("switch"))try{const pe=await Nl("/api/prefs",{lan:{enabled:!ce}});if(!P.current)return;pe!=null&&pe.ok?(V(null),ce||v(!0)):V(un(ce?"turn this off":"turn this on",pe)),await W()}catch{P.current&&V(un(ce?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,W,ee,M]),G=w.useCallback(async(ce,pe,Ae)=>{if(!ee(`${ce}:${pe}`))return null;let fe=null;try{const Se=await Nl("/api/lan/peer",{action:ce,fp:pe});if(!P.current)return null;Se!=null&&Se.ok?(u(Se),V(null)):(fe=un(Ae,Se),V(fe)),await W()}catch{fe=un(Ae,null),P.current&&V(fe)}finally{M()}return fe},[W,ee,M]),re=w.useCallback(async ce=>{if(!ee(`drop:${ce}`))return null;let pe=null;try{const Ae=await Nl("/api/prefs",{lan:{manual:f.filter(fe=>fe!==ce)}});if(!P.current)return null;Ae!=null&&Ae.ok?(V(null),t()):(pe=un("stop dialling that address",Ae),V(pe)),await W()}catch{pe=un("stop dialling that address",null),P.current&&V(pe)}finally{M()}return pe},[f,W,t,ee,M]),[U,Y]=w.useState(null),z=w.useCallback(async(ce,pe)=>{if(!ee(`alias:${ce}`))return"Something else is still being saved. Try again in a moment.";try{const Ae=await Nl("/api/lan/peer",{action:"alias",fp:ce,name:pe});return P.current?Ae!=null&&Ae.ok?(u(Ae),null):un("rename that deck",Ae):null}catch{return un("rename that deck",null)}finally{M()}},[ee,M]),ie=w.useCallback(async ce=>{if(!ee(`check:${ce}`))return null;try{const pe=await Nl("/api/lan/sync",{fp:ce});return P.current?pe!=null&&pe.ok?(u(pe),t(),null):(pe==null?void 0:pe.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.":un("check that deck",pe):null}catch{return un("check that deck",null)}finally{M()}},[ee,M,t]),le=w.useCallback(async()=>{if(ee("check"))try{const ce=await Nl("/api/lan/sync",{});if(!P.current)return;ce!=null&&ce.ok?(u(ce),V(null)):V(un("check the other decks",ce)),t()}catch{P.current&&V(un("check the other decks",null))}finally{M()}},[ee,M,t]),ge=(c==null?void 0:c.enabled)===!0,Ne=nU((c==null?void 0:c.pairingMode)==="invite"&&c?{...c,pending:[]}:c,K),Ie=U?Ne.find(ce=>{var pe;return ce.fp===U||((pe=ce.twins)==null?void 0:pe.some(Ae=>Ae.fp===U))})??null:null;w.useEffect(()=>{U&&c&&!Ie&&Y(null)},[U,c,Ie]);const Ge=Ne.filter(ce=>ce.kind==="asks"),Pe=Ne.filter(ce=>ce.kind!=="asks"),Be=Pe.filter(ce=>ce.here),Te=Pe.filter(ce=>!ce.here),st=Te.filter(ce=>ce.tone==="bad").length,de=H||Be.length===0,ue=Jz(c,K),se=Pe.filter(ce=>ce.kind==="paired").length,be=lU(c,Ne),Le=o.jsxs(o.Fragment,{children:[k&&c&&o.jsx(Ez,{status:c,manual:f,startWith:k==="invite"?"invite":void 0,onClose:()=>j(!1),onChanged:()=>{W(),t()}}),E&&o.jsx(UM,{title:"How Local network works",steps:bz,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),F()}},onClose:()=>C(!1)}),y&&c&&o.jsx(Pz,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>v(!1),onChanged:()=>{W(),t()}}),Ie&&c&&o.jsx(Oz,{row:Ie,source:ej(c,Ie),status:c,accounts:e,now:K,busy:h,onClose:()=>Y(null),onRename:ce=>z(Ie.fp,ce),onCheck:()=>ie(Ie.fp),onVerb:()=>{switch(Ie.kind){case"paired":return G("unpair",Ie.fp,"unpair that deck");case"nearby":return G("accept",Ie.fp,"reach that deck");case"declined":return G("allow",Ie.fp,"let that deck ask again");case"dialling":return re(Ie.fp);default:return Promise.resolve(null)}},onSettings:()=>{Y(null),v(!0)},onInvite:()=>{Y(null),j("invite")},twins:(Ie.twins??[]).map(ce=>({row:ce,peer:ej(c,ce).peer??null})),onUnpair:ce=>G("unpair",ce,"unpair that deck")})]});if(!n){const ce=Se=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!0),Se)},pe=()=>{window.clearTimeout(O.current),O.current=window.setTimeout(()=>I(!1),YM)},Ae=()=>window.clearTimeout(O.current),fe=()=>{window.clearTimeout(O.current),I(!1)};return o.jsxs("div",{className:"ap-foot",children:[o.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{fe(),r()},"aria-describedby":R?"ap-lan-peek":void 0,onPointerEnter:Se=>{Se.pointerType==="mouse"&&ce(KM)},onPointerLeave:pe,onFocus:Se=>{Se.target.matches(":focus-visible")&&ce(0)},onBlur:pe,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(iU,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:Ne,onHold:Ae,onLet:pe}),o.jsx("p",{className:"vis-hidden",role:"status",children:ue.tone==="ok"?"":ue.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",...Z("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",...Z("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",...Z("switch"),onClick:()=>void F(),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(WM,{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:Qz(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(kz,{}),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 ${ue.tone}`,role:"status",children:ue.tone==="ok"?"":ue.text}),$&&o.jsxs("div",{className:"ap-failure",role:"alert",children:[o.jsx("span",{className:"ap-failure-text",children:$}),o.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>V(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(ce=>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:ce.name})," at ",o.jsx("code",{className:"ap-lan-code",children:ce.addr})," wants to pair"]}),o.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",o.jsx("code",{className:"ap-lan-code",children:ce.fp})]}),o.jsxs("span",{className:"ap-lan-ask-acts",children:[o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${ce.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),o.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`dismiss:${ce.fp}`),onClick:()=>void G("dismiss",ce.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},ce.fp))}),(de?[...Be,...Te]:Be).length>0&&o.jsx("ul",{className:"ap-lan-here",children:(de?[...Be,...Te]:Be).map((ce,pe)=>o.jsxs("li",{className:"ap-lan-who","data-tone":ce.tone,children:[o.jsx("i",{className:ce.here?"ap-pulse":"ap-dot","aria-hidden":!0}),o.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[ce.name,ce.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-${pe}`,onClick:()=>Y(ce.fp),children:o.jsxs("span",{className:"vis-hidden",children:[ce.name,ce.via==="tailscale"?", over Tailscale":"",", details"]})}),o.jsx("span",{id:`lan-who-state-${pe}`,className:ce.quiet?"vis-hidden":"ap-lan-who-when",children:ce.state}),ce.kind==="nearby"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`accept:${ce.fp}`),onClick:()=>void G("accept",ce.fp,"reach that deck"),"aria-label":`Ask ${ce.name} to pair`,title:`Send ${ce.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${ce.fp}.`,children:"ask"}),(ce.kind==="nearby"||ce.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 ${ce.name} to pair`,title:`This deck pairs only by invite. Make one and send it to whoever is at ${ce.name}.`,children:"invite"}),ce.kind==="paired"&&o.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${S===ce.fp?" armed":""}`,...Z(`unpair:${ce.fp}`),onClick:()=>{const Ae=Date.now(),fe=Cu({armedFor:S,target:ce.fp,armedAt:_.current,now:Ae,gapMs:Mu});if(fe==="arm"){b(ce.fp),_.current=Ae,window.setTimeout(()=>b(Se=>Se===ce.fp?null:Se),4e3);return}fe!=="ignore"&&(b(null),G("unpair",ce.fp,"unpair that deck"))},"aria-label":S===ce.fp?`Confirm unpairing ${ce.name}`:`Unpair ${ce.name}`,title:S===ce.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===ce.fp?"confirm":"unpair"}),ce.kind==="dialling"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`drop:${ce.fp}`),onClick:()=>void re(ce.fp),"aria-label":`Stop dialling ${ce.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),ce.kind==="declined"&&(c==null?void 0:c.pairingMode)!=="invite"&&o.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`allow:${ce.fp}`),onClick:()=>void G("allow",ce.fp,"let that deck ask again"),"aria-label":`Let ${ce.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${ce.kind}:${ce.fp}`))}),(Be.length>0&&Te.length>0||ge&&se>0)&&o.jsxs("div",{className:"ap-lan-tail",children:[Be.length>0&&Te.length>0&&o.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":H,onClick:()=>q(ce=>!ce),title:H?"Show only the decks that are on":`Show the ${Te.length} deck${Te.length===1?"":"s"} that are not responding right now`,children:[o.jsx("span",{className:`ap-lan-chev${H?" open":""}`,"aria-hidden":!0,children:"›"}),H?"fewer":`${Te.length} more`,!H&&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:eU(c==null?void 0:c.checkedAt,K,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 uU({anchorId:e,id:t,peers:n,onHold:r,onLet:s}){const l=w.useRef(null),{title:c,shown:u,rest:f}=iz(n),p=w.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=$b(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]),Mn.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 dU({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),YM)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},v=az(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(KM)},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(uU,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function hU(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const fU=1800;function pU({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=pn(t,{focusRef:b});w.useEffect(()=>{if(!l)return;S(Math.floor(Date.now()/1e3));const $=window.setInterval(()=>S(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval($)},[l]);const j=KB(e),E=YB(e,r),C=E.length===e.length,R=$=>s(V=>XB(V,$)),I=w.useCallback(async()=>{const $=ZB(E);if(!Ps(_.current)||!$)return;_.current=!0,f(!0),h(null),y(!1);const V=await hU($).catch(()=>null);if(_.current=!1,f(!1),!(V!=null&&V.ok)){h(Al(V,"the share could not be made"));return}c({blob:V.blob,expiresAt:V.expiresAt,shared:V.shared??[],failed:V.failed??[]})},[e,E]),O=l?zM(l.expiresAt,v):null,H=(O==null?void 0:O.tone)==="gone",q=(l==null?void 0:l.shared.length)??0;return Mn.createPortal(o.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:o.jsxs("div",{ref:k,className:"modal sa-modal",onClick:$=>$.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:H?"This share has expired":q===1?"1 account, ready to paste":`${q} accounts, ready to paste`}),o.jsx("code",{className:`ap-share-blob${H?" 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(H){c(null),I();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),fU))},children:H?"make a new share":m?"copied":`copy ${q===1?"the share":"all "+q}`}),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:q===1?"this is the password":`this is ${q} passwords`})," · ",o.jsx("span",{className:`ap-share-expiry ${O==null?void 0:O.tone}`,children:O==null?void 0:O.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($=>{var ne;const V=!!($.email&&((ne=$.detail)!=null&&ne.includes($.email)));return o.jsxs("li",{children:[!V&&o.jsx("span",{className:"sa-who",children:$.email||`account ${$.num}`}),o.jsx("span",{className:"sa-why",children:$.detail||"could not be exported"})]},`${$.num}-${$.email}`)})})]}),o.jsx("p",{className:"sa-note",children:H?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 ",dn,"?"]}),o.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:QB(E.length)}),o.jsx("ul",{className:"sa-list sa-pick",children:j.map($=>o.jsx("li",{children:o.jsxs("label",{className:"sa-row",children:[o.jsx("input",{type:"checkbox",checked:E.includes($.num),onChange:()=>R($.num)}),o.jsx("span",{className:"sa-who",children:$.label}),$.sub&&o.jsx("span",{className:"sa-sub",children:$.sub})]})},$.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($=>$.num):[]),children:C?"Clear all":"Select all"}),o.jsx("button",{type:"button",className:"btn primary",ref:b,...Qa(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 mU(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 gU(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 yU(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function wU(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 vU(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 tj(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function xU(e){const t=e.filter(u=>!tj(u)),n=e.filter(u=>tj(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 bU="\0";function sf(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}${bU}${n}`}function kU(e,t){const n=sf(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function NU(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(sf)),r=e.filter(s=>n.has(s));return r.length===e.length?e:r}const SU=64;function jU(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}function _U(e,t){return!e||!t||t.some(n=>n.num===e.num&&n.active)?e:null}const EU=Object.freeze({text:"couldn't reach the deck server",reload:!0}),CU=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function nj(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function TU(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Au(t.body);return{text:O0(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function rj(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 sj=15e3,RU=8e3,AU=1800,MU=3e4,Tm=[70,80,85,90,95];function Rm(e,t){return kM(t-Math.floor(e/1e3))}function IU(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 lu(e){return e.charAt(0).toUpperCase()+e.slice(1)}function $U(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 OU(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 LU(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 Nh(e,t){if(e.staleCopy){const n=$U(e.repair??null,t);return{text:lu(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=LU(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:lu(n.text),hint:n.hint,fix:n.fix?lu(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=OU(e.error);return{text:lu(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function Am(){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 PU(e){return e>=90?"hi":e>=70?"mid":void 0}function DU(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Tm.includes(t)?[...Tm,t]:Tm].sort((r,s)=>r-s)}function FU({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?NM(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 qU({onClose:e,leaving:t}){var xr,$n,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)),O=w.useRef(null),[H,q]=w.useState(null),$=(H==null?void 0:H.num)??null,V=w.useRef(H);V.current=H;const[ne,ee]=w.useState(null),[M,Z]=w.useState(!1),[K,D]=w.useState(""),[P,B]=w.useState(null),W=w.useRef(0),[F,G]=w.useState(null),[re,U]=w.useState(!1),[Y,z]=w.useState(!1),[ie,le]=w.useState(null),[ge,Ne]=w.useState(null),[Ie,Ge]=w.useState(null),[Pe,Be]=w.useState(null),[Te,st]=w.useState(!1),de=w.useRef(null),ue=w.useRef(null),[se,be]=w.useState([]),[Le,ce]=w.useState(!1),pe=w.useRef(null),Ae=w.useCallback(Q=>Tf(pe.current)?(pe.current=Q,u(Q),!0):!1,[]),fe=w.useCallback(()=>{pe.current=null,u(null)},[]),Se=(Q,De=!1)=>{const et=ao(c,Q);return{disabled:et.disabled,"aria-busy":et.busy||De}},Ye=w.useCallback(Q=>{window.requestAnimationFrame(()=>{var De;if(A0(((De=document.activeElement)==null?void 0:De.tagName)??null))for(const et of u8(Q)){const Ue=document.querySelector(et);if(Ue){Ue.focus();return}}})},[]),qe=w.useCallback(async(Q=!1)=>{Q&&p(!0);const De=new AbortController,et=window.setTimeout(()=>De.abort(),MU);try{const[Ue,tt]=await Promise.all([fetch(`/api/claude-accounts${Q?"?refresh=1":""}`,{signal:De.signal}),fetch("/api/cswap-auto",{signal:De.signal})]);if(Ue.ok){const gt=await Ue.json();r(gt),be(It=>NU(It,gt.accounts))}tt.ok&&l(await tt.json());const wt=TU([await nj(Ue),await nj(tt)]);m(gt=>rj(gt,wt))}catch{m(Ue=>rj(Ue,De.signal.aborted?CU:EU))}finally{window.clearTimeout(et),Q&&p(!1)}},[]),ke=w.useCallback(async(Q,De,et="panel")=>{if(!Ae(De))return null;const Ue=et==="menu"?ee:m;Ue(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||Ue({text:O0(wt,"command failed",tt.status),raw:Au(wt)}),wt}catch{return Ue({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]),Re=w.useCallback(async(Q,De)=>{if(!Ae(De))return null;m(null),ee(null);try{const et=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(Q)}),Ue=await et.json().catch(()=>null);return Ue!=null&&Ue.ok||ee({text:Al(Ue,"command failed",et.status)}),Ue}catch{return ee({text:"server unreachable"}),null}finally{fe()}},[Ae,fe]);w.useEffect(()=>(qe(!0),O.current=window.setInterval(()=>qe(!1),sj),()=>{O.current!=null&&window.clearInterval(O.current)}),[qe]),w.useEffect(()=>{!(n!=null&&n.ok)||!n.accounts||v(Q=>_U(Q,n.accounts))},[n]),w.useEffect(()=>{const Q=window.setInterval(()=>I(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(Q)},[]);const ze=((xr=s==null?void 0:s.settings["autoswitch.threshold"])==null?void 0:xr.value)??"90",Fe=Pe??ze,We=vU(Fe,ze),rt=($n=n==null?void 0:n.accounts)==null?void 0:$n.find(Q=>Q.active),dt=rt?Nh(rt,R):null,ct=(n==null?void 0:n.accounts)??[],yt=rt?ct.filter(Q=>!Q.active):[],Ot=yt.length?ct.filter(Q=>Q.active):ct,zt=yt.map(Q=>{const De=Nh(Q,R);return{key:sf(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(ze),Dt=(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),je=Q=>Le&&yt.some(De=>De.num===Q)?"ap-rest-list":"ap-scroll",xt=async(Q,De)=>{if(Ae(`switch-${Q}`)){m(null),v(null);try{const Ue=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:Q})})).json().catch(()=>null);Ue!=null&&Ue.ok?v({num:Q,name:De}):m({text:O0(Ue,"the switch failed"),raw:Au(Ue),row:Q}),await qe(!0)}catch{m({text:"server unreachable",row:Q})}finally{fe(),Ye(Q)}}},bt=w.useCallback(()=>{q(null),ee(null),B(null),G(null),z(!1)},[]),_n=(Q,De="first")=>{bt(),E(null),Ge(null),q({num:Q,view:"menu",start:De})},Ut=(Q,De)=>{bt(),E(et=>(et==null?void 0:et.anchor)===De?null:{num:Q,anchor:De})},Vn=w.useCallback((Q=!1)=>{var et;const De=C.current;Q&&De&&((et=document.getElementById(De.anchor))==null||et.focus()),E(null)},[]),Vt=()=>{bt(),E(null),b("lan")},Lt=w.useRef(S);w.useEffect(()=>{Lt.current!==S&&(Lt.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 Ue,tt;const De=V.current;if(!De||Q!=null&&De.num!==Q)return;const et=document.getElementById(`ap-menu-${De.num}`);(et!=null&&et.contains(document.activeElement)||A0(((Ue=document.activeElement)==null?void 0:Ue.tagName)??null))&&((tt=document.getElementById(`ap-more-${De.num}`))==null||tt.focus()),bt()},[bt]);w.useEffect(()=>{t&&(bt(),E(null))},[t,bt]),w.useEffect(()=>{H&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===H.num)&&bt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(Q=>Q.num===j.num)&&E(null)},[n,H,j,bt]);const In=async Q=>{var et;z(!1);const De=await Re({action:"share",account:Q},`share-${Q}`);!(De!=null&&De.ok)||((et=V.current)==null?void 0:et.num)!==Q||(G({num:Q,blob:De.blob,expiresAt:De.expiresAt}),q({num:Q,view:"share"}))},Hr=async(Q,De)=>{const{commit:et,alias:Ue}=jU(K,De);if(et){const tt=await Re({action:"alias",account:Q,alias:Ue},`alias-${Q}`);if(await qe(!0),!(tt!=null&&tt.ok))return}Zt(Q)},xe=async(Q,De)=>{var tt,wt;const et=await Re({action:"move",account:Q,slot:De},`move-${Q}`),Ue=gU({menuFor:((tt=V.current)==null?void 0:tt.num)??null,shareFor:(F==null?void 0:F.num)??null},Q,et);if(await qe(!0),Ue){((wt=V.current)==null?void 0:wt.num)===Q&&bt(),B(Ue.confirmRemove),Ue.shareFor==null&&(G(null),z(!1)),Ne(Ue.swapNote);const gt=Ue.swapNote;gt&&window.setTimeout(()=>Ne(It=>It===gt?null:It),RU),Ge(null),Ye(Ue.menuFor)}return et},lr=async(Q,De,et)=>{if(!et.sends){Zt(Q);return}await xe(Q,De)},ks=async(Q,De)=>{if(De.sends){const et=await ke({action:"setting",key:"autoswitch.threshold",value:Q},"threshold");if(await qe(!0),!(et!=null&&et.ok))return;Be(null)}st(!0),window.setTimeout(()=>{var et;document.activeElement===ue.current&&((et=de.current)==null||et.focus()),st(!1)},AU)},Wr=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"})})}),fa=Q=>{const{shown:De,fuller:et}=xU(Q.lanes),Ue=Nh(Q,R),tt=Q.active||se.includes(sf(Q)),wt=Q.alias??Q.email??`account ${Q.num}`,gt=Q.alias&&Q.email?`${Q.alias} · ${Q.email}`:wt,It=Q.stale||(Ue==null?void 0:Ue.blocksSwitch)===!0,Rt=et?[...De,et]:De,Qt=Q.fetchedAt?Rm(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":It?"":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&&!(Ue!=null&&Ue.blocksSwitch)?`ap-quota-${Q.num}`:null].filter(Boolean).join(" ")||void 0,onClick:()=>be(Nt=>kU(Nt,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&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsx("button",{type:"button",className:"ap-switch",...Se(`switch-${Q.num}`),onClick:()=>xt(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":$===Q.num,"aria-controls":$===Q.num?`ap-menu-${Q.num}`:void 0,title:"More actions",onClick:()=>$===Q.num?Zt():_n(Q.num),onKeyDown:Nt=>{Nt.key!=="ArrowDown"&&Nt.key!=="ArrowUp"||(Nt.preventDefault(),_n(Q.num,Nt.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 Nt=ct.find(cr=>cr.num===ge.displaced),br=(Nt==null?void 0:Nt.alias)??(Nt==null?void 0:Nt.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]})})(),Ue&&o.jsxs("div",{className:"ap-issue-line",children:[o.jsxs("button",{type:"button",id:`ap-issue-${Q.num}`,className:"ap-issue","data-tone":Ue.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:[Ue.tone==="warn"&&o.jsx(Am,{}),o.jsx("span",{className:"ap-issue-text",children:Ue.text})]}),!tt&&o.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qt??"never collected"})]}),!tt&&!(Ue!=null&&Ue.blocksSwitch)&&o.jsxs("p",{className:"ap-quota",id:`ap-quota-${Q.num}`,children:[Rt.length?Rt.map(Nt=>o.jsxs("span",{className:"ap-q",children:[o.jsx("span",{className:"ap-q-label",children:Nt.label})," ",o.jsxs("span",{className:"ap-q-pct","data-level":It?void 0:PU(Nt.pct),children:[Math.round(Nt.pct),"%"]})]},Nt.id)):o.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),Q.stale&&!Ue&&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(Nt=>o.jsx(FU,{lane:Nt,nowSec:R,frozen:It},Nt.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&&!Ue?" 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 ",Rm(Q.fetchedAt,R),Ue!=null&&Ue.blocksSwitch?"":IU(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)},Ns=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:de,"aria-label":"Switch threshold",value:Fe,...Se("threshold"),onChange:Q=>Be(Q.target.value),children:DU(ze).map(Q=>o.jsxs("option",{value:Q,children:[Q,"%"]},Q))})}),(We.sends||Te)&&o.jsx("button",{ref:ue,type:"button",className:"ap-manage-btn",...Se("threshold"),title:We.title,onClick:()=>ks(Fe,We),children:Te&&!We.sends?We.done:We.label}),o.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":s.enabled,"aria-label":"Auto-switch",...Se("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:()=>Z(!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:()=>U(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${dn} 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),...Se("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"})]})}),Wr]})]}),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 ",sj/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&&(dt==null?void 0:dt.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(Am,{}),o.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),dt.fix&&o.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>Z(!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:Ot.map(fa)}),yt.length>0&&o.jsx(dU,{peers:zt,strained:Dt,armed:rn,threshold:s!=null&&s.ok?ze:null,open:Le,onToggle:()=>ce(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(fa)}),Ns]}),yt.length===0&&Ns,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:"×"})]}),H&&(()=>{var Ue;const Q=(Ue=n.accounts)==null?void 0:Ue.find(tt=>tt.num===H.num);if(!Q)return null;const De=`ap-pop-title-${Q.num}`,et=ne&&o.jsx("p",{className:"ap-pop-error",role:"alert",title:ne.raw||void 0,children:ne.text});return o.jsxs(M0,{anchorId:`ap-more-${Q.num}`,boundaryId:je(Q.num),id:`ap-menu-${Q.num}`,className:"ap-pop",role:H.view==="menu"?"menu":"dialog",labelledBy:H.view==="menu"?`ap-more-${Q.num}`:De,start:H.start,onClose:bt,children:[H.view==="menu"&&o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{D(Q.alias??""),ee(null),q({num:Q.num,view:"rename"})},children:"Rename"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{Ge(null),ee(null),q({num:Q.num,view:"move"})},children:"Move to slot…"}),o.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Se(`share-${Q.num}`),title:`Copy this account to another ${dn}. 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:()=>In(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",...Se(`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${P===Q.num?" armed":""}`,...Se(`rm-${Q.num}`),"aria-label":P===Q.num?"Confirm remove":void 0,title:P===Q.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{const tt=Date.now(),wt=Cu({armedFor:P,target:Q.num,armedAt:W.current,now:tt,gapMs:Mu});if(wt==="arm"){B(Q.num),W.current=tt,window.setTimeout(()=>B(gt=>gt===Q.num?null:gt),4e3);return}wt!=="ignore"&&(B(null),Re({action:"remove",account:Q.num},`rm-${Q.num}`).then(gt=>{var It;qe(!0),gt!=null&>.ok&&(((It=V.current)==null?void 0:It.num)===Q.num&&bt(),Ye(null))}))},children:c===`rm-${Q.num}`?"Removing…":P===Q.num?"Confirm":"Remove"}),et]}),H.view==="rename"&&o.jsxs("form",{className:"ap-pop-form",onSubmit:tt=>{tt.preventDefault(),Hr(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:K,onChange:tt=>D(tt.target.value),maxLength:SU,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:tt=>tt.currentTarget.select()}),et,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",...Se(`alias-${Q.num}`),title:"A short name to show instead of the email",children:c===`alias-${Q.num}`?"…":"Save"})]})]}),H.view==="move"&&(()=>{const tt=mU((n.accounts??[]).map(It=>It.num),Q.num),wt=yU(tt,Ie,Q.num),gt=wU(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),...Se(`move-${Q.num}`),onChange:It=>Ge(Number(It.target.value)),autoFocus:!0,children:tt.map(It=>o.jsx("option",{value:It.slot,children:It.label},It.slot))})}),et,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",...Se(`move-${Q.num}`),title:gt.title,onClick:()=>lr(Q.num,wt,gt),children:c===`move-${Q.num}`?"…":lu(gt.label)})]})]})})(),H.view==="share"&&(F==null?void 0:F.num)===Q.num&&(()=>{const tt=zM(F.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:F.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})]}),et,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",...Se(`share-${Q.num}`),autoFocus:!0,onClick:async()=>{if(wt){await In(Q.num);return}await hi(F.blob)&&(z(!0),window.setTimeout(()=>z(!1),1800))},children:wt?"Make a new share":Y?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var et;const Q=(et=n.accounts)==null?void 0:et.find(Ue=>Ue.num===j.num),De=Q?Nh(Q,R):null;return!Q||!De?null:o.jsx(M0,{anchorId:j.anchor,boundaryId:j.anchor==="ap-notice"?"ap-scroll":je(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(Am,{}),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 ${Rm(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),Z(!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(cU,{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:Wr}),M&&o.jsx(rz,{onClose:()=>Z(!1),onChanged:()=>qe(!0)}),re&&o.jsx(pU,{accounts:((n==null?void 0:n.accounts)??[]).map(Q=>({num:Q.num,email:Q.email,alias:Q.alias,org:Q.org})),onClose:()=>U(!1),copyText:hi}),ie!=null&&(()=>{const Q=((n==null?void 0:n.accounts)??[]).find(De=>De.num===ie);return Q?o.jsx(NB,{num:Q.num,name:Q.alias??Q.email??`account ${Q.num}`,onClose:()=>le(null)}):(le(null),null)})()]})}const BU=3e4;function zU({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function UU({bundle:e,running:t,pending:n,lastTried:r}){return t?zU({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function HU(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function WU({asked:e,reported:t}){return t?t!==e:!1}function XM(e){const t=e.thresholdMs??BU;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 VU(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 GU(e,t){return e?t==null?"auto when idle":`auto in ${VU(t)}`:"auto-restart off"}function aj(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function KU(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 YU(e){const t=XM(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 zb(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 Mm,oj;function XU(){if(oj)return Mm;oj=1;function e(){this.__data__=[],this.size=0}return Mm=e,Mm}var Im,ij;function tc(){if(ij)return Im;ij=1;function e(t,n){return t===n||t!==t&&n!==n}return Im=e,Im}var $m,lj;function Mf(){if(lj)return $m;lj=1;var e=tc();function t(n,r){for(var s=n.length;s--;)if(e(n[s][0],r))return s;return-1}return $m=t,$m}var Om,cj;function ZU(){if(cj)return Om;cj=1;var e=Mf(),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 Om=r,Om}var Lm,uj;function QU(){if(uj)return Lm;uj=1;var e=Mf();function t(n){var r=this.__data__,s=e(r,n);return s<0?void 0:r[s][1]}return Lm=t,Lm}var Pm,dj;function JU(){if(dj)return Pm;dj=1;var e=Mf();function t(n){return e(this.__data__,n)>-1}return Pm=t,Pm}var Dm,hj;function eH(){if(hj)return Dm;hj=1;var e=Mf();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 Dm=t,Dm}var Fm,fj;function If(){if(fj)return Fm;fj=1;var e=XU(),t=ZU(),n=QU(),r=JU(),s=eH();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,Fm=l,Fm}var qm,pj;function tH(){if(pj)return qm;pj=1;var e=If();function t(){this.__data__=new e,this.size=0}return qm=t,qm}var Bm,mj;function nH(){if(mj)return Bm;mj=1;function e(t){var n=this.__data__,r=n.delete(t);return this.size=n.size,r}return Bm=e,Bm}var zm,gj;function rH(){if(gj)return zm;gj=1;function e(t){return this.__data__.get(t)}return zm=e,zm}var Um,yj;function sH(){if(yj)return Um;yj=1;function e(t){return this.__data__.has(t)}return Um=e,Um}var Hm,wj;function ZM(){if(wj)return Hm;wj=1;var e=typeof th=="object"&&th&&th.Object===Object&&th;return Hm=e,Hm}var Wm,vj;function bs(){if(vj)return Wm;vj=1;var e=ZM(),t=typeof self=="object"&&self&&self.Object===Object&&self,n=e||t||Function("return this")();return Wm=n,Wm}var Vm,xj;function nc(){if(xj)return Vm;xj=1;var e=bs(),t=e.Symbol;return Vm=t,Vm}var Gm,bj;function aH(){if(bj)return Gm;bj=1;var e=nc(),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 Gm=l,Gm}var Km,kj;function oH(){if(kj)return Km;kj=1;var e=Object.prototype,t=e.toString;function n(r){return t.call(r)}return Km=n,Km}var Ym,Nj;function wi(){if(Nj)return Ym;Nj=1;var e=nc(),t=aH(),n=oH(),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 Ym=c,Ym}var Xm,Sj;function zr(){if(Sj)return Xm;Sj=1;function e(t){var n=typeof t;return t!=null&&(n=="object"||n=="function")}return Xm=e,Xm}var Zm,jj;function Uu(){if(jj)return Zm;jj=1;var e=wi(),t=zr(),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 Zm=c,Zm}var Qm,_j;function iH(){if(_j)return Qm;_j=1;var e=bs(),t=e["__core-js_shared__"];return Qm=t,Qm}var Jm,Ej;function lH(){if(Ej)return Jm;Ej=1;var e=iH(),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 Jm=n,Jm}var eg,Cj;function QM(){if(Cj)return eg;Cj=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 eg=n,eg}var tg,Tj;function cH(){if(Tj)return tg;Tj=1;var e=Uu(),t=lH(),n=zr(),r=QM(),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 tg=m,tg}var ng,Rj;function uH(){if(Rj)return ng;Rj=1;function e(t,n){return t==null?void 0:t[n]}return ng=e,ng}var rg,Aj;function vi(){if(Aj)return rg;Aj=1;var e=cH(),t=uH();function n(r,s){var l=t(r,s);return e(l)?l:void 0}return rg=n,rg}var sg,Mj;function Ub(){if(Mj)return sg;Mj=1;var e=vi(),t=bs(),n=e(t,"Map");return sg=n,sg}var ag,Ij;function $f(){if(Ij)return ag;Ij=1;var e=vi(),t=e(Object,"create");return ag=t,ag}var og,$j;function dH(){if($j)return og;$j=1;var e=$f();function t(){this.__data__=e?e(null):{},this.size=0}return og=t,og}var ig,Oj;function hH(){if(Oj)return ig;Oj=1;function e(t){var n=this.has(t)&&delete this.__data__[t];return this.size-=n?1:0,n}return ig=e,ig}var lg,Lj;function fH(){if(Lj)return lg;Lj=1;var e=$f(),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 lg=s,lg}var cg,Pj;function pH(){if(Pj)return cg;Pj=1;var e=$f(),t=Object.prototype,n=t.hasOwnProperty;function r(s){var l=this.__data__;return e?l[s]!==void 0:n.call(l,s)}return cg=r,cg}var ug,Dj;function mH(){if(Dj)return ug;Dj=1;var e=$f(),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 ug=n,ug}var dg,Fj;function gH(){if(Fj)return dg;Fj=1;var e=dH(),t=hH(),n=fH(),r=pH(),s=mH();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,dg=l,dg}var hg,qj;function yH(){if(qj)return hg;qj=1;var e=gH(),t=If(),n=Ub();function r(){this.size=0,this.__data__={hash:new e,map:new(n||t),string:new e}}return hg=r,hg}var fg,Bj;function wH(){if(Bj)return fg;Bj=1;function e(t){var n=typeof t;return n=="string"||n=="number"||n=="symbol"||n=="boolean"?t!=="__proto__":t===null}return fg=e,fg}var pg,zj;function Of(){if(zj)return pg;zj=1;var e=wH();function t(n,r){var s=n.__data__;return e(r)?s[typeof r=="string"?"string":"hash"]:s.map}return pg=t,pg}var mg,Uj;function vH(){if(Uj)return mg;Uj=1;var e=Of();function t(n){var r=e(this,n).delete(n);return this.size-=r?1:0,r}return mg=t,mg}var gg,Hj;function xH(){if(Hj)return gg;Hj=1;var e=Of();function t(n){return e(this,n).get(n)}return gg=t,gg}var yg,Wj;function bH(){if(Wj)return yg;Wj=1;var e=Of();function t(n){return e(this,n).has(n)}return yg=t,yg}var wg,Vj;function kH(){if(Vj)return wg;Vj=1;var e=Of();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 wg=t,wg}var vg,Gj;function Hb(){if(Gj)return vg;Gj=1;var e=yH(),t=vH(),n=xH(),r=bH(),s=kH();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,vg=l,vg}var xg,Kj;function NH(){if(Kj)return xg;Kj=1;var e=If(),t=Ub(),n=Hb(),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 xg=s,xg}var bg,Yj;function Lf(){if(Yj)return bg;Yj=1;var e=If(),t=tH(),n=nH(),r=rH(),s=sH(),l=NH();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,bg=c,bg}var kg,Xj;function Wb(){if(Xj)return kg;Xj=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 kg=e,kg}var Ng,Zj;function JM(){if(Zj)return Ng;Zj=1;var e=vi(),t=(function(){try{var n=e(Object,"defineProperty");return n({},"",{}),n}catch{}})();return Ng=t,Ng}var Sg,Qj;function Pf(){if(Qj)return Sg;Qj=1;var e=JM();function t(n,r,s){r=="__proto__"&&e?e(n,r,{configurable:!0,enumerable:!0,value:s,writable:!0}):n[r]=s}return Sg=t,Sg}var jg,Jj;function Df(){if(Jj)return jg;Jj=1;var e=Pf(),t=tc(),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 jg=s,jg}var _g,e_;function Hu(){if(e_)return _g;e_=1;var e=Df(),t=Pf();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 _g=n,_g}var Eg,t_;function SH(){if(t_)return Eg;t_=1;function e(t,n){for(var r=-1,s=Array(t);++r<t;)s[r]=n(r);return s}return Eg=e,Eg}var Cg,n_;function Us(){if(n_)return Cg;n_=1;function e(t){return t!=null&&typeof t=="object"}return Cg=e,Cg}var Tg,r_;function jH(){if(r_)return Tg;r_=1;var e=wi(),t=Us(),n="[object Arguments]";function r(s){return t(s)&&e(s)==n}return Tg=r,Tg}var Rg,s_;function Wu(){if(s_)return Rg;s_=1;var e=jH(),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 Rg=l,Rg}var Ag,a_;function nn(){if(a_)return Ag;a_=1;var e=Array.isArray;return Ag=e,Ag}var cu={exports:{}},Mg,o_;function _H(){if(o_)return Mg;o_=1;function e(){return!1}return Mg=e,Mg}cu.exports;var i_;function rc(){return i_||(i_=1,(function(e,t){var n=bs(),r=_H(),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})(cu,cu.exports)),cu.exports}var Ig,l_;function Ff(){if(l_)return Ig;l_=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 Ig=n,Ig}var $g,c_;function Vb(){if(c_)return $g;c_=1;var e=9007199254740991;function t(n){return typeof n=="number"&&n>-1&&n%1==0&&n<=e}return $g=t,$g}var Og,u_;function EH(){if(u_)return Og;u_=1;var e=wi(),t=Vb(),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]",O="[object Uint8Array]",H="[object Uint8ClampedArray]",q="[object Uint16Array]",$="[object Uint32Array]",V={};V[j]=V[E]=V[C]=V[R]=V[I]=V[O]=V[H]=V[q]=V[$]=!0,V[r]=V[s]=V[_]=V[l]=V[k]=V[c]=V[u]=V[f]=V[p]=V[h]=V[m]=V[y]=V[v]=V[S]=V[b]=!1;function ne(ee){return n(ee)&&t(ee.length)&&!!V[e(ee)]}return Og=ne,Og}var Lg,d_;function qf(){if(d_)return Lg;d_=1;function e(t){return function(n){return t(n)}}return Lg=e,Lg}var uu={exports:{}};uu.exports;var h_;function Gb(){return h_||(h_=1,(function(e,t){var n=ZM(),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})(uu,uu.exports)),uu.exports}var Pg,f_;function Vu(){if(f_)return Pg;f_=1;var e=EH(),t=qf(),n=Gb(),r=n&&n.isTypedArray,s=r?t(r):e;return Pg=s,Pg}var Dg,p_;function eI(){if(p_)return Dg;p_=1;var e=SH(),t=Wu(),n=nn(),r=rc(),s=Ff(),l=Vu(),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 Dg=f,Dg}var Fg,m_;function Bf(){if(m_)return Fg;m_=1;var e=Object.prototype;function t(n){var r=n&&n.constructor,s=typeof r=="function"&&r.prototype||e;return n===s}return Fg=t,Fg}var qg,g_;function tI(){if(g_)return qg;g_=1;function e(t,n){return function(r){return t(n(r))}}return qg=e,qg}var Bg,y_;function CH(){if(y_)return Bg;y_=1;var e=tI(),t=e(Object.keys,Object);return Bg=t,Bg}var zg,w_;function Kb(){if(w_)return zg;w_=1;var e=Bf(),t=CH(),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 zg=s,zg}var Ug,v_;function da(){if(v_)return Ug;v_=1;var e=Uu(),t=Vb();function n(r){return r!=null&&t(r.length)&&!e(r)}return Ug=n,Ug}var Hg,x_;function oo(){if(x_)return Hg;x_=1;var e=eI(),t=Kb(),n=da();function r(s){return n(s)?e(s):t(s)}return Hg=r,Hg}var Wg,b_;function TH(){if(b_)return Wg;b_=1;var e=Hu(),t=oo();function n(r,s){return r&&e(s,t(s),r)}return Wg=n,Wg}var Vg,k_;function RH(){if(k_)return Vg;k_=1;function e(t){var n=[];if(t!=null)for(var r in Object(t))n.push(r);return n}return Vg=e,Vg}var Gg,N_;function AH(){if(N_)return Gg;N_=1;var e=zr(),t=Bf(),n=RH(),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 Gg=l,Gg}var Kg,S_;function xi(){if(S_)return Kg;S_=1;var e=eI(),t=AH(),n=da();function r(s){return n(s)?e(s,!0):t(s)}return Kg=r,Kg}var Yg,j_;function MH(){if(j_)return Yg;j_=1;var e=Hu(),t=xi();function n(r,s){return r&&e(s,t(s),r)}return Yg=n,Yg}var du={exports:{}};du.exports;var __;function nI(){return __||(__=1,(function(e,t){var n=bs(),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})(du,du.exports)),du.exports}var Xg,E_;function rI(){if(E_)return Xg;E_=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 Xg=e,Xg}var Zg,C_;function sI(){if(C_)return Zg;C_=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 Zg=e,Zg}var Qg,T_;function aI(){if(T_)return Qg;T_=1;function e(){return[]}return Qg=e,Qg}var Jg,R_;function Yb(){if(R_)return Jg;R_=1;var e=sI(),t=aI(),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 Jg=l,Jg}var ey,A_;function IH(){if(A_)return ey;A_=1;var e=Hu(),t=Yb();function n(r,s){return e(r,t(r),s)}return ey=n,ey}var ty,M_;function Xb(){if(M_)return ty;M_=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 ty=e,ty}var ny,I_;function zf(){if(I_)return ny;I_=1;var e=tI(),t=e(Object.getPrototypeOf,Object);return ny=t,ny}var ry,$_;function oI(){if($_)return ry;$_=1;var e=Xb(),t=zf(),n=Yb(),r=aI(),s=Object.getOwnPropertySymbols,l=s?function(c){for(var u=[];c;)e(u,n(c)),c=t(c);return u}:r;return ry=l,ry}var sy,O_;function $H(){if(O_)return sy;O_=1;var e=Hu(),t=oI();function n(r,s){return e(r,t(r),s)}return sy=n,sy}var ay,L_;function iI(){if(L_)return ay;L_=1;var e=Xb(),t=nn();function n(r,s,l){var c=s(r);return t(r)?c:e(c,l(r))}return ay=n,ay}var oy,P_;function lI(){if(P_)return oy;P_=1;var e=iI(),t=Yb(),n=oo();function r(s){return e(s,n,t)}return oy=r,oy}var iy,D_;function OH(){if(D_)return iy;D_=1;var e=iI(),t=oI(),n=xi();function r(s){return e(s,n,t)}return iy=r,iy}var ly,F_;function LH(){if(F_)return ly;F_=1;var e=vi(),t=bs(),n=e(t,"DataView");return ly=n,ly}var cy,q_;function PH(){if(q_)return cy;q_=1;var e=vi(),t=bs(),n=e(t,"Promise");return cy=n,cy}var uy,B_;function cI(){if(B_)return uy;B_=1;var e=vi(),t=bs(),n=e(t,"Set");return uy=n,uy}var dy,z_;function DH(){if(z_)return dy;z_=1;var e=vi(),t=bs(),n=e(t,"WeakMap");return dy=n,dy}var hy,U_;function sc(){if(U_)return hy;U_=1;var e=LH(),t=Ub(),n=PH(),r=cI(),s=DH(),l=wi(),c=QM(),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}),hy=j,hy}var fy,H_;function FH(){if(H_)return fy;H_=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 fy=n,fy}var py,W_;function uI(){if(W_)return py;W_=1;var e=bs(),t=e.Uint8Array;return py=t,py}var my,V_;function Zb(){if(V_)return my;V_=1;var e=uI();function t(n){var r=new n.constructor(n.byteLength);return new e(r).set(new e(n)),r}return my=t,my}var gy,G_;function qH(){if(G_)return gy;G_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.byteLength)}return gy=t,gy}var yy,K_;function BH(){if(K_)return yy;K_=1;var e=/\w*$/;function t(n){var r=new n.constructor(n.source,e.exec(n));return r.lastIndex=n.lastIndex,r}return yy=t,yy}var wy,Y_;function zH(){if(Y_)return wy;Y_=1;var e=nc(),t=e?e.prototype:void 0,n=t?t.valueOf:void 0;function r(s){return n?Object(n.call(s)):{}}return wy=r,wy}var vy,X_;function dI(){if(X_)return vy;X_=1;var e=Zb();function t(n,r){var s=r?e(n.buffer):n.buffer;return new n.constructor(s,n.byteOffset,n.length)}return vy=t,vy}var xy,Z_;function UH(){if(Z_)return xy;Z_=1;var e=Zb(),t=qH(),n=BH(),r=zH(),s=dI(),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]",O="[object Uint32Array]";function H(q,$,V){var ne=q.constructor;switch($){case v:return e(q);case l:case c:return new ne(+q);case S:return t(q,V);case b:case _:case k:case j:case E:case C:case R:case I:case O:return s(q,V);case u:return new ne;case f:case m:return new ne(q);case p:return n(q);case h:return new ne;case y:return r(q)}}return xy=H,xy}var by,Q_;function hI(){if(Q_)return by;Q_=1;var e=zr(),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 by=n,by}var ky,J_;function fI(){if(J_)return ky;J_=1;var e=hI(),t=zf(),n=Bf();function r(s){return typeof s.constructor=="function"&&!n(s)?e(t(s)):{}}return ky=r,ky}var Ny,eE;function HH(){if(eE)return Ny;eE=1;var e=sc(),t=Us(),n="[object Map]";function r(s){return t(s)&&e(s)==n}return Ny=r,Ny}var Sy,tE;function WH(){if(tE)return Sy;tE=1;var e=HH(),t=qf(),n=Gb(),r=n&&n.isMap,s=r?t(r):e;return Sy=s,Sy}var jy,nE;function VH(){if(nE)return jy;nE=1;var e=sc(),t=Us(),n="[object Set]";function r(s){return t(s)&&e(s)==n}return jy=r,jy}var _y,rE;function GH(){if(rE)return _y;rE=1;var e=VH(),t=qf(),n=Gb(),r=n&&n.isSet,s=r?t(r):e;return _y=s,_y}var Ey,sE;function pI(){if(sE)return Ey;sE=1;var e=Lf(),t=Wb(),n=Df(),r=TH(),s=MH(),l=nI(),c=rI(),u=IH(),f=$H(),p=lI(),h=OH(),m=sc(),y=FH(),v=UH(),S=fI(),b=nn(),_=rc(),k=WH(),j=zr(),E=GH(),C=oo(),R=xi(),I=1,O=2,H=4,q="[object Arguments]",$="[object Array]",V="[object Boolean]",ne="[object Date]",ee="[object Error]",M="[object Function]",Z="[object GeneratorFunction]",K="[object Map]",D="[object Number]",P="[object Object]",B="[object RegExp]",W="[object Set]",F="[object String]",G="[object Symbol]",re="[object WeakMap]",U="[object ArrayBuffer]",Y="[object DataView]",z="[object Float32Array]",ie="[object Float64Array]",le="[object Int8Array]",ge="[object Int16Array]",Ne="[object Int32Array]",Ie="[object Uint8Array]",Ge="[object Uint8ClampedArray]",Pe="[object Uint16Array]",Be="[object Uint32Array]",Te={};Te[q]=Te[$]=Te[U]=Te[Y]=Te[V]=Te[ne]=Te[z]=Te[ie]=Te[le]=Te[ge]=Te[Ne]=Te[K]=Te[D]=Te[P]=Te[B]=Te[W]=Te[F]=Te[G]=Te[Ie]=Te[Ge]=Te[Pe]=Te[Be]=!0,Te[ee]=Te[M]=Te[re]=!1;function st(de,ue,se,be,Le,ce){var pe,Ae=ue&I,fe=ue&O,Se=ue&H;if(se&&(pe=Le?se(de,be,Le,ce):se(de)),pe!==void 0)return pe;if(!j(de))return de;var Ye=b(de);if(Ye){if(pe=y(de),!Ae)return c(de,pe)}else{var qe=m(de),ke=qe==M||qe==Z;if(_(de))return l(de,Ae);if(qe==P||qe==q||ke&&!Le){if(pe=fe||ke?{}:S(de),!Ae)return fe?f(de,s(pe,de)):u(de,r(pe,de))}else{if(!Te[qe])return Le?de:{};pe=v(de,qe,Ae)}}ce||(ce=new e);var Re=ce.get(de);if(Re)return Re;ce.set(de,pe),E(de)?de.forEach(function(We){pe.add(st(We,ue,se,We,de,ce))}):k(de)&&de.forEach(function(We,rt){pe.set(rt,st(We,ue,se,rt,de,ce))});var ze=Se?fe?h:p:fe?R:C,Fe=Ye?void 0:ze(de);return t(Fe||de,function(We,rt){Fe&&(rt=We,We=de[rt]),n(pe,rt,st(We,ue,se,rt,de,ce))}),pe}return Ey=st,Ey}var Cy,aE;function KH(){if(aE)return Cy;aE=1;var e=pI(),t=4;function n(r){return e(r,t)}return Cy=n,Cy}var Ty,oE;function Qb(){if(oE)return Ty;oE=1;function e(t){return function(){return t}}return Ty=e,Ty}var Ry,iE;function YH(){if(iE)return Ry;iE=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 Ry=e,Ry}var Ay,lE;function Jb(){if(lE)return Ay;lE=1;var e=YH(),t=e();return Ay=t,Ay}var My,cE;function ek(){if(cE)return My;cE=1;var e=Jb(),t=oo();function n(r,s){return r&&e(r,s,t)}return My=n,My}var Iy,uE;function XH(){if(uE)return Iy;uE=1;var e=da();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 Iy=t,Iy}var $y,dE;function Uf(){if(dE)return $y;dE=1;var e=ek(),t=XH(),n=t(e);return $y=n,$y}var Oy,hE;function bi(){if(hE)return Oy;hE=1;function e(t){return t}return Oy=e,Oy}var Ly,fE;function mI(){if(fE)return Ly;fE=1;var e=bi();function t(n){return typeof n=="function"?n:e}return Ly=t,Ly}var Py,pE;function gI(){if(pE)return Py;pE=1;var e=Wb(),t=Uf(),n=mI(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c))}return Py=s,Py}var Dy,mE;function yI(){return mE||(mE=1,Dy=gI()),Dy}var Fy,gE;function ZH(){if(gE)return Fy;gE=1;var e=Uf();function t(n,r){var s=[];return e(n,function(l,c,u){r(l,c,u)&&s.push(l)}),s}return Fy=t,Fy}var qy,yE;function QH(){if(yE)return qy;yE=1;var e="__lodash_hash_undefined__";function t(n){return this.__data__.set(n,e),this}return qy=t,qy}var By,wE;function JH(){if(wE)return By;wE=1;function e(t){return this.__data__.has(t)}return By=e,By}var zy,vE;function wI(){if(vE)return zy;vE=1;var e=Hb(),t=QH(),n=JH();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,zy=r,zy}var Uy,xE;function eW(){if(xE)return Uy;xE=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 Uy=e,Uy}var Hy,bE;function vI(){if(bE)return Hy;bE=1;function e(t,n){return t.has(n)}return Hy=e,Hy}var Wy,kE;function xI(){if(kE)return Wy;kE=1;var e=wI(),t=eW(),n=vI(),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(O,H){if(!n(E,H)&&(C===O||h(C,O,f,p,m)))return E.push(H)})){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 Wy=l,Wy}var Vy,NE;function tW(){if(NE)return Vy;NE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s,l){r[++n]=[l,s]}),r}return Vy=e,Vy}var Gy,SE;function tk(){if(SE)return Gy;SE=1;function e(t){var n=-1,r=Array(t.size);return t.forEach(function(s){r[++n]=s}),r}return Gy=e,Gy}var Ky,jE;function nW(){if(jE)return Ky;jE=1;var e=nc(),t=uI(),n=tc(),r=xI(),s=tW(),l=tk(),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,O,H,q,$,V,ne){switch(H){case j:if(I.byteLength!=O.byteLength||I.byteOffset!=O.byteOffset)return!1;I=I.buffer,O=O.buffer;case k:return!(I.byteLength!=O.byteLength||!V(new t(I),new t(O)));case f:case p:case y:return n(+I,+O);case h:return I.name==O.name&&I.message==O.message;case v:case b:return I==O+"";case m:var ee=s;case S:var M=q&c;if(ee||(ee=l),I.size!=O.size&&!M)return!1;var Z=ne.get(I);if(Z)return Z==O;q|=u,ne.set(I,O);var K=r(ee(I),ee(O),q,$,V,ne);return ne.delete(I),K;case _:if(C)return C.call(I)==C.call(O)}return!1}return Ky=R,Ky}var Yy,_E;function rW(){if(_E)return Yy;_E=1;var e=lI(),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],O=c[k];if(f)var H=m?f(O,I,k,c,l,h):f(I,O,k,l,c,h);if(!(H===void 0?I===O||p(I,O,u,f,h):H)){C=!1;break}R||(R=k=="constructor")}if(C&&!R){var q=l.constructor,$=c.constructor;q!=$&&"constructor"in l&&"constructor"in c&&!(typeof q=="function"&&q instanceof q&&typeof $=="function"&&$ instanceof $)&&(C=!1)}return h.delete(l),h.delete(c),C}return Yy=s,Yy}var Xy,EE;function sW(){if(EE)return Xy;EE=1;var e=Lf(),t=xI(),n=nW(),r=rW(),s=sc(),l=nn(),c=rc(),u=Vu(),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(_),O=R?h:s(b),H=I?h:s(_);O=O==p?m:O,H=H==p?m:H;var q=O==m,$=H==m,V=O==H;if(V&&c(b)){if(!c(_))return!1;R=!0,q=!1}if(V&&!q)return C||(C=new e),R||u(b)?t(b,_,k,j,E,C):n(b,_,O,k,j,E,C);if(!(k&f)){var ne=q&&v.call(b,"__wrapped__"),ee=$&&v.call(_,"__wrapped__");if(ne||ee){var M=ne?b.value():b,Z=ee?_.value():_;return C||(C=new e),E(M,Z,k,j,C)}}return V?(C||(C=new e),r(b,_,k,j,E,C)):!1}return Xy=S,Xy}var Zy,CE;function bI(){if(CE)return Zy;CE=1;var e=sW(),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 Zy=n,Zy}var Qy,TE;function aW(){if(TE)return Qy;TE=1;var e=Lf(),t=bI(),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 Qy=s,Qy}var Jy,RE;function kI(){if(RE)return Jy;RE=1;var e=zr();function t(n){return n===n&&!e(n)}return Jy=t,Jy}var ew,AE;function oW(){if(AE)return ew;AE=1;var e=kI(),t=oo();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 ew=n,ew}var tw,ME;function NI(){if(ME)return tw;ME=1;function e(t,n){return function(r){return r==null?!1:r[t]===n&&(n!==void 0||t in Object(r))}}return tw=e,tw}var nw,IE;function iW(){if(IE)return nw;IE=1;var e=aW(),t=oW(),n=NI();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 nw=r,nw}var rw,$E;function ac(){if($E)return rw;$E=1;var e=wi(),t=Us(),n="[object Symbol]";function r(s){return typeof s=="symbol"||t(s)&&e(s)==n}return rw=r,rw}var sw,OE;function nk(){if(OE)return sw;OE=1;var e=nn(),t=ac(),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 sw=s,sw}var aw,LE;function lW(){if(LE)return aw;LE=1;var e=Hb(),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,aw=n,aw}var ow,PE;function cW(){if(PE)return ow;PE=1;var e=lW(),t=500;function n(r){var s=e(r,function(c){return l.size===t&&l.clear(),c}),l=s.cache;return s}return ow=n,ow}var iw,DE;function uW(){if(DE)return iw;DE=1;var e=cW(),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 iw=r,iw}var lw,FE;function Hf(){if(FE)return lw;FE=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 lw=e,lw}var cw,qE;function dW(){if(qE)return cw;qE=1;var e=nc(),t=Hf(),n=nn(),r=ac(),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 cw=c,cw}var uw,BE;function SI(){if(BE)return uw;BE=1;var e=dW();function t(n){return n==null?"":e(n)}return uw=t,uw}var dw,zE;function Wf(){if(zE)return dw;zE=1;var e=nn(),t=nk(),n=uW(),r=SI();function s(l,c){return e(l)?l:t(l,c)?[l]:n(r(l))}return dw=s,dw}var hw,UE;function Gu(){if(UE)return hw;UE=1;var e=ac();function t(n){if(typeof n=="string"||e(n))return n;var r=n+"";return r=="0"&&1/n==-1/0?"-0":r}return hw=t,hw}var fw,HE;function Vf(){if(HE)return fw;HE=1;var e=Wf(),t=Gu();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 fw=n,fw}var pw,WE;function hW(){if(WE)return pw;WE=1;var e=Vf();function t(n,r,s){var l=n==null?void 0:e(n,r);return l===void 0?s:l}return pw=t,pw}var mw,VE;function fW(){if(VE)return mw;VE=1;function e(t,n){return t!=null&&n in Object(t)}return mw=e,mw}var gw,GE;function jI(){if(GE)return gw;GE=1;var e=Wf(),t=Wu(),n=nn(),r=Ff(),s=Vb(),l=Gu();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 gw=c,gw}var yw,KE;function _I(){if(KE)return yw;KE=1;var e=fW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return yw=n,yw}var ww,YE;function pW(){if(YE)return ww;YE=1;var e=bI(),t=hW(),n=_I(),r=nk(),s=kI(),l=NI(),c=Gu(),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 ww=p,ww}var vw,XE;function EI(){if(XE)return vw;XE=1;function e(t){return function(n){return n==null?void 0:n[t]}}return vw=e,vw}var xw,ZE;function mW(){if(ZE)return xw;ZE=1;var e=Vf();function t(n){return function(r){return e(r,n)}}return xw=t,xw}var bw,QE;function gW(){if(QE)return bw;QE=1;var e=EI(),t=mW(),n=nk(),r=Gu();function s(l){return n(l)?e(r(l)):t(l)}return bw=s,bw}var kw,JE;function ha(){if(JE)return kw;JE=1;var e=iW(),t=pW(),n=bi(),r=nn(),s=gW();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 kw=l,kw}var Nw,eC;function CI(){if(eC)return Nw;eC=1;var e=sI(),t=ZH(),n=ha(),r=nn();function s(l,c){var u=r(l)?e:t;return u(l,n(c,3))}return Nw=s,Nw}var Sw,tC;function yW(){if(tC)return Sw;tC=1;var e=Object.prototype,t=e.hasOwnProperty;function n(r,s){return r!=null&&t.call(r,s)}return Sw=n,Sw}var jw,nC;function TI(){if(nC)return jw;nC=1;var e=yW(),t=jI();function n(r,s){return r!=null&&t(r,s,e)}return jw=n,jw}var _w,rC;function wW(){if(rC)return _w;rC=1;var e=Kb(),t=sc(),n=Wu(),r=nn(),s=da(),l=rc(),c=Bf(),u=Vu(),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 _w=y,_w}var Ew,sC;function RI(){if(sC)return Ew;sC=1;function e(t){return t===void 0}return Ew=e,Ew}var Cw,aC;function AI(){if(aC)return Cw;aC=1;var e=Uf(),t=da();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 Cw=n,Cw}var Tw,oC;function MI(){if(oC)return Tw;oC=1;var e=Hf(),t=ha(),n=AI(),r=nn();function s(l,c){var u=r(l)?e:n;return u(l,t(c,3))}return Tw=s,Tw}var Rw,iC;function vW(){if(iC)return Rw;iC=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 Rw=e,Rw}var Aw,lC;function xW(){if(lC)return Aw;lC=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 Aw=e,Aw}var Mw,cC;function II(){if(cC)return Mw;cC=1;var e=vW(),t=Uf(),n=ha(),r=xW(),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 Mw=l,Mw}var Iw,uC;function bW(){if(uC)return Iw;uC=1;var e=wi(),t=nn(),n=Us(),r="[object String]";function s(l){return typeof l=="string"||!t(l)&&n(l)&&e(l)==r}return Iw=s,Iw}var $w,dC;function kW(){if(dC)return $w;dC=1;var e=EI(),t=e("length");return $w=t,$w}var Ow,hC;function NW(){if(hC)return Ow;hC=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 Ow=f,Ow}var Lw,fC;function SW(){if(fC)return Lw;fC=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 Lw=C,Lw}var Pw,pC;function jW(){if(pC)return Pw;pC=1;var e=kW(),t=NW(),n=SW();function r(s){return t(s)?n(s):e(s)}return Pw=r,Pw}var Dw,mC;function _W(){if(mC)return Dw;mC=1;var e=Kb(),t=sc(),n=da(),r=bW(),s=jW(),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 Dw=u,Dw}var Fw,gC;function EW(){if(gC)return Fw;gC=1;var e=Wb(),t=hI(),n=ek(),r=ha(),s=zf(),l=nn(),c=rc(),u=Uu(),f=zr(),p=Vu();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 Fw=h,Fw}var qw,yC;function CW(){if(yC)return qw;yC=1;var e=nc(),t=Wu(),n=nn(),r=e?e.isConcatSpreadable:void 0;function s(l){return n(l)||t(l)||!!(r&&l&&l[r])}return qw=s,qw}var Bw,wC;function rk(){if(wC)return Bw;wC=1;var e=Xb(),t=CW();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 Bw=n,Bw}var zw,vC;function TW(){if(vC)return zw;vC=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 zw=e,zw}var Uw,xC;function $I(){if(xC)return Uw;xC=1;var e=TW(),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 Uw=n,Uw}var Hw,bC;function RW(){if(bC)return Hw;bC=1;var e=Qb(),t=JM(),n=bi(),r=t?function(s,l){return t(s,"toString",{configurable:!0,enumerable:!1,value:e(l),writable:!0})}:n;return Hw=r,Hw}var Ww,kC;function AW(){if(kC)return Ww;kC=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 Ww=r,Ww}var Vw,NC;function OI(){if(NC)return Vw;NC=1;var e=RW(),t=AW(),n=t(e);return Vw=n,Vw}var Gw,SC;function Gf(){if(SC)return Gw;SC=1;var e=bi(),t=$I(),n=OI();function r(s,l){return n(t(s,l,e),s+"")}return Gw=r,Gw}var Kw,jC;function LI(){if(jC)return Kw;jC=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 Kw=e,Kw}var Yw,_C;function MW(){if(_C)return Yw;_C=1;function e(t){return t!==t}return Yw=e,Yw}var Xw,EC;function IW(){if(EC)return Xw;EC=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 Xw=e,Xw}var Zw,CC;function $W(){if(CC)return Zw;CC=1;var e=LI(),t=MW(),n=IW();function r(s,l,c){return l===l?n(s,l,c):e(s,t,c)}return Zw=r,Zw}var Qw,TC;function OW(){if(TC)return Qw;TC=1;var e=$W();function t(n,r){var s=n==null?0:n.length;return!!s&&e(n,r,0)>-1}return Qw=t,Qw}var Jw,RC;function LW(){if(RC)return Jw;RC=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 Jw=e,Jw}var ev,AC;function PW(){if(AC)return ev;AC=1;function e(){}return ev=e,ev}var tv,MC;function DW(){if(MC)return tv;MC=1;var e=cI(),t=PW(),n=tk(),r=1/0,s=e&&1/n(new e([,-0]))[1]==r?function(l){return new e(l)}:t;return tv=s,tv}var nv,IC;function FW(){if(IC)return nv;IC=1;var e=wI(),t=OW(),n=LW(),r=vI(),s=DW(),l=tk(),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 nv=u,nv}var rv,$C;function PI(){if($C)return rv;$C=1;var e=da(),t=Us();function n(r){return t(r)&&e(r)}return rv=n,rv}var sv,OC;function qW(){if(OC)return sv;OC=1;var e=rk(),t=Gf(),n=FW(),r=PI(),s=t(function(l){return n(e(l,1,r,!0))});return sv=s,sv}var av,LC;function BW(){if(LC)return av;LC=1;var e=Hf();function t(n,r){return e(r,function(s){return n[s]})}return av=t,av}var ov,PC;function DI(){if(PC)return ov;PC=1;var e=BW(),t=oo();function n(r){return r==null?[]:e(r,t(r))}return ov=n,ov}var iv,DC;function Ur(){if(DC)return iv;DC=1;var e;if(typeof zb=="function")try{e={clone:KH(),constant:Qb(),each:yI(),filter:CI(),has:TI(),isArray:nn(),isEmpty:wW(),isFunction:Uu(),isUndefined:RI(),keys:oo(),map:MI(),reduce:II(),size:_W(),transform:EW(),union:qW(),values:DI()}}catch{}return e||(e=window._),iv=e,iv}var lv,FC;function sk(){if(FC)return lv;FC=1;var e=Ur();lv=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 lv}var cv,qC;function zW(){return qC||(qC=1,cv="2.1.8"),cv}var uv,BC;function UW(){return BC||(BC=1,uv={Graph:sk(),version:zW()}),uv}var dv,zC;function HW(){if(zC)return dv;zC=1;var e=Ur(),t=sk();dv={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 dv}var hv,UC;function WW(){if(UC)return hv;UC=1;var e=Ur();hv=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 hv}var fv,HC;function FI(){if(HC)return fv;HC=1;var e=Ur();fv=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},fv}var pv,WC;function qI(){if(WC)return pv;WC=1;var e=Ur(),t=FI();pv=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 pv}var mv,VC;function VW(){if(VC)return mv;VC=1;var e=qI(),t=Ur();mv=n;function n(r,s,l){return t.transform(r.nodes(),function(c,u){c[u]=e(r,u,s,l)},{})}return mv}var gv,GC;function BI(){if(GC)return gv;GC=1;var e=Ur();gv=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 gv}var yv,KC;function GW(){if(KC)return yv;KC=1;var e=Ur(),t=BI();yv=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 yv}var wv,YC;function KW(){if(YC)return wv;YC=1;var e=Ur();wv=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 wv}var vv,XC;function zI(){if(XC)return vv;XC=1;var e=Ur();vv=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,vv}var xv,ZC;function YW(){if(ZC)return xv;ZC=1;var e=zI();xv=t;function t(n){try{e(n)}catch(r){if(r instanceof e.CycleException)return!1;throw r}return!0}return xv}var bv,QC;function UI(){if(QC)return bv;QC=1;var e=Ur();bv=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 bv}var kv,JC;function XW(){if(JC)return kv;JC=1;var e=UI();kv=t;function t(n,r){return e(n,r,"post")}return kv}var Nv,eT;function ZW(){if(eT)return Nv;eT=1;var e=UI();Nv=t;function t(n,r){return e(n,r,"pre")}return Nv}var Sv,tT;function QW(){if(tT)return Sv;tT=1;var e=Ur(),t=sk(),n=FI();Sv=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 Sv}var jv,nT;function JW(){return nT||(nT=1,jv={components:WW(),dijkstra:qI(),dijkstraAll:VW(),findCycles:GW(),floydWarshall:KW(),isAcyclic:YW(),postorder:XW(),preorder:ZW(),prim:QW(),tarjan:BI(),topsort:zI()}),jv}var _v,rT;function e7(){if(rT)return _v;rT=1;var e=UW();return _v={Graph:e.Graph,json:HW(),alg:JW(),version:e.version},_v}var Ev,sT;function vs(){if(sT)return Ev;sT=1;var e;if(typeof zb=="function")try{e=e7()}catch{}return e||(e=window.graphlib),Ev=e,Ev}var Cv,aT;function t7(){if(aT)return Cv;aT=1;var e=pI(),t=1,n=4;function r(s){return e(s,t|n)}return Cv=r,Cv}var Tv,oT;function Kf(){if(oT)return Tv;oT=1;var e=tc(),t=da(),n=Ff(),r=zr();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 Tv=s,Tv}var Rv,iT;function n7(){if(iT)return Rv;iT=1;var e=Gf(),t=tc(),n=Kf(),r=xi(),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 Rv=c,Rv}var Av,lT;function r7(){if(lT)return Av;lT=1;var e=ha(),t=da(),n=oo();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 Av=r,Av}var Mv,cT;function s7(){if(cT)return Mv;cT=1;var e=/\s/;function t(n){for(var r=n.length;r--&&e.test(n.charAt(r)););return r}return Mv=t,Mv}var Iv,uT;function a7(){if(uT)return Iv;uT=1;var e=s7(),t=/^\s+/;function n(r){return r&&r.slice(0,e(r)+1).replace(t,"")}return Iv=n,Iv}var $v,dT;function o7(){if(dT)return $v;dT=1;var e=a7(),t=zr(),n=ac(),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 $v=f,$v}var Ov,hT;function HI(){if(hT)return Ov;hT=1;var e=o7(),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 Ov=r,Ov}var Lv,fT;function i7(){if(fT)return Lv;fT=1;var e=HI();function t(n){var r=e(n),s=r%1;return r===r?s?r-s:r:0}return Lv=t,Lv}var Pv,pT;function l7(){if(pT)return Pv;pT=1;var e=LI(),t=ha(),n=i7(),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 Pv=s,Pv}var Dv,mT;function c7(){if(mT)return Dv;mT=1;var e=r7(),t=l7(),n=e(t);return Dv=n,Dv}var Fv,gT;function WI(){if(gT)return Fv;gT=1;var e=rk();function t(n){var r=n==null?0:n.length;return r?e(n,1):[]}return Fv=t,Fv}var qv,yT;function u7(){if(yT)return qv;yT=1;var e=Jb(),t=mI(),n=xi();function r(s,l){return s==null?s:e(s,t(l),n)}return qv=r,qv}var Bv,wT;function d7(){if(wT)return Bv;wT=1;function e(t){var n=t==null?0:t.length;return n?t[n-1]:void 0}return Bv=e,Bv}var zv,vT;function h7(){if(vT)return zv;vT=1;var e=Pf(),t=ek(),n=ha();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 zv=r,zv}var Uv,xT;function ak(){if(xT)return Uv;xT=1;var e=ac();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 Uv=t,Uv}var Hv,bT;function f7(){if(bT)return Hv;bT=1;function e(t,n){return t>n}return Hv=e,Hv}var Wv,kT;function p7(){if(kT)return Wv;kT=1;var e=ak(),t=f7(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return Wv=r,Wv}var Vv,NT;function VI(){if(NT)return Vv;NT=1;var e=Pf(),t=tc();function n(r,s,l){(l!==void 0&&!t(r[s],l)||l===void 0&&!(s in r))&&e(r,s,l)}return Vv=n,Vv}var Gv,ST;function m7(){if(ST)return Gv;ST=1;var e=wi(),t=zf(),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 Gv=p,Gv}var Kv,jT;function GI(){if(jT)return Kv;jT=1;function e(t,n){if(!(n==="constructor"&&typeof t[n]=="function")&&n!="__proto__")return t[n]}return Kv=e,Kv}var Yv,_T;function g7(){if(_T)return Yv;_T=1;var e=Hu(),t=xi();function n(r){return e(r,t(r))}return Yv=n,Yv}var Xv,ET;function y7(){if(ET)return Xv;ET=1;var e=VI(),t=nI(),n=dI(),r=rI(),s=fI(),l=Wu(),c=nn(),u=PI(),f=rc(),p=Uu(),h=zr(),m=m7(),y=Vu(),v=GI(),S=g7();function b(_,k,j,E,C,R,I){var O=v(_,j),H=v(k,j),q=I.get(H);if(q){e(_,j,q);return}var $=R?R(O,H,j+"",_,k,I):void 0,V=$===void 0;if(V){var ne=c(H),ee=!ne&&f(H),M=!ne&&!ee&&y(H);$=H,ne||ee||M?c(O)?$=O:u(O)?$=r(O):ee?(V=!1,$=t(H,!0)):M?(V=!1,$=n(H,!0)):$=[]:m(H)||l(H)?($=O,l(O)?$=S(O):(!h(O)||p(O))&&($=s(H))):V=!1}V&&(I.set(H,$),C($,H,E,R,I),I.delete(H)),e(_,j,$)}return Xv=b,Xv}var Zv,CT;function w7(){if(CT)return Zv;CT=1;var e=Lf(),t=VI(),n=Jb(),r=y7(),s=zr(),l=xi(),c=GI();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 Zv=u,Zv}var Qv,TT;function v7(){if(TT)return Qv;TT=1;var e=Gf(),t=Kf();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 Qv=n,Qv}var Jv,RT;function x7(){if(RT)return Jv;RT=1;var e=w7(),t=v7(),n=t(function(r,s,l){e(r,s,l)});return Jv=n,Jv}var ex,AT;function KI(){if(AT)return ex;AT=1;function e(t,n){return t<n}return ex=e,ex}var tx,MT;function b7(){if(MT)return tx;MT=1;var e=ak(),t=KI(),n=bi();function r(s){return s&&s.length?e(s,n,t):void 0}return tx=r,tx}var nx,IT;function k7(){if(IT)return nx;IT=1;var e=ak(),t=ha(),n=KI();function r(s,l){return s&&s.length?e(s,t(l,2),n):void 0}return nx=r,nx}var rx,$T;function N7(){if($T)return rx;$T=1;var e=bs(),t=function(){return e.Date.now()};return rx=t,rx}var sx,OT;function S7(){if(OT)return sx;OT=1;var e=Df(),t=Wf(),n=Ff(),r=zr(),s=Gu();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 sx=l,sx}var ax,LT;function j7(){if(LT)return ax;LT=1;var e=Vf(),t=S7(),n=Wf();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 ax=r,ax}var ox,PT;function _7(){if(PT)return ox;PT=1;var e=j7(),t=_I();function n(r,s){return e(r,s,function(l,c){return t(r,c)})}return ox=n,ox}var ix,DT;function E7(){if(DT)return ix;DT=1;var e=WI(),t=$I(),n=OI();function r(s){return n(t(s,void 0,e),s+"")}return ix=r,ix}var lx,FT;function C7(){if(FT)return lx;FT=1;var e=_7(),t=E7(),n=t(function(r,s){return r==null?{}:e(r,s)});return lx=n,lx}var cx,qT;function T7(){if(qT)return cx;qT=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 cx=n,cx}var ux,BT;function R7(){if(BT)return ux;BT=1;var e=T7(),t=Kf(),n=HI();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 ux=r,ux}var dx,zT;function A7(){if(zT)return dx;zT=1;var e=R7(),t=e();return dx=t,dx}var hx,UT;function M7(){if(UT)return hx;UT=1;function e(t,n){var r=t.length;for(t.sort(n);r--;)t[r]=t[r].value;return t}return hx=e,hx}var fx,HT;function I7(){if(HT)return fx;HT=1;var e=ac();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 fx=t,fx}var px,WT;function $7(){if(WT)return px;WT=1;var e=I7();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 px=t,px}var mx,VT;function O7(){if(VT)return mx;VT=1;var e=Hf(),t=Vf(),n=ha(),r=AI(),s=M7(),l=qf(),c=$7(),u=bi(),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 mx=p,mx}var gx,GT;function L7(){if(GT)return gx;GT=1;var e=rk(),t=O7(),n=Gf(),r=Kf(),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 gx=s,gx}var yx,KT;function P7(){if(KT)return yx;KT=1;var e=SI(),t=0;function n(r){var s=++t;return e(r)+s}return yx=n,yx}var wx,YT;function D7(){if(YT)return wx;YT=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 wx=e,wx}var vx,XT;function F7(){if(XT)return vx;XT=1;var e=Df(),t=D7();function n(r,s){return t(r||[],s||[],e)}return vx=n,vx}var xx,ZT;function Pt(){if(ZT)return xx;ZT=1;var e;if(typeof zb=="function")try{e={cloneDeep:t7(),constant:Qb(),defaults:n7(),each:yI(),filter:CI(),find:c7(),flatten:WI(),forEach:gI(),forIn:u7(),has:TI(),isUndefined:RI(),last:d7(),map:MI(),mapValues:h7(),max:p7(),merge:x7(),min:b7(),minBy:k7(),now:N7(),pick:C7(),range:A7(),reduce:II(),sortBy:L7(),uniqueId:P7(),values:DI(),zipObject:F7()}}catch{}return e||(e=window._),xx=e,xx}var bx,QT;function q7(){if(QT)return bx;QT=1,bx=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 bx}var kx,JT;function B7(){if(JT)return kx;JT=1;var e=Pt(),t=vs().Graph,n=q7();kx=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 kx}var Nx,e2;function z7(){if(e2)return Nx;e2=1;var e=Pt(),t=B7();Nx={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 Nx}var Sx,t2;function or(){if(t2)return Sx;t2=1;var e=Pt(),t=vs().Graph;Sx={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,O=_.height/2;if(!C&&!R)throw new Error("Not possible to find intersection inside of the rectangle");var H,q;return Math.abs(R)*I>Math.abs(C)*O?(R<0&&(O=-O),H=O*C/R,q=O):(C<0&&(I=-I),H=I,q=I*R/C),{x:j+H,y:E+q}}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(O){_.node(O).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 Sx}var jx,n2;function U7(){if(n2)return jx;n2=1;var e=Pt(),t=or();jx={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 jx}var _x,r2;function af(){if(r2)return _x;r2=1;var e=Pt();_x={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 _x}var Ex,s2;function YI(){if(s2)return Ex;s2=1;var e=Pt(),t=vs().Graph,n=af().slack;Ex=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 Ex}var Cx,a2;function H7(){if(a2)return Cx;a2=1;var e=Pt(),t=YI(),n=af().slack,r=af().longestPath,s=vs().alg.preorder,l=vs().alg.postorder,c=or().simplify;Cx=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),O=I.parent;E.edge(R,O).cutvalue=h(E,C,R)}function h(E,C,R){var I=E.node(R),O=I.parent,H=!0,q=C.edge(R,O),$=0;return q||(H=!1,q=C.edge(O,R)),$=q.weight,e.forEach(C.nodeEdges(R),function(V){var ne=V.v===R,ee=ne?V.w:V.v;if(ee!==O){var M=ne===H,Z=C.edge(V).weight;if($+=M?Z:-Z,k(E,R,ee)){var K=E.edge(R,ee).cutvalue;$+=M?-K:K}}}),$}function m(E,C){arguments.length<2&&(C=E.nodes()[0]),y(E,{},1,C)}function y(E,C,R,I,O){var H=R,q=E.node(I);return C[I]=!0,e.forEach(E.neighbors(I),function($){e.has(C,$)||(R=y(E,C,R,$,I))}),q.low=H,q.lim=R++,O?q.parent=O:delete q.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,O=R.w;C.hasEdge(I,O)||(I=R.w,O=R.v);var H=E.node(I),q=E.node(O),$=H,V=!1;H.lim>q.lim&&($=q,V=!0);var ne=e.filter(C.edges(),function(ee){return V===j(E,E.node(ee.v),$)&&V!==j(E,E.node(ee.w),$)});return e.minBy(ne,function(ee){return n(C,ee)})}function b(E,C,R,I){var O=R.v,H=R.w;E.removeEdge(O,H),E.setEdge(I.v,I.w,{}),m(E),f(E,C),_(E,C)}function _(E,C){var R=e.find(E.nodes(),function(O){return!C.node(O).parent}),I=s(E,R);I=I.slice(1),e.forEach(I,function(O){var H=E.node(O).parent,q=C.edge(O,H),$=!1;q||(q=C.edge(H,O),$=!0),C.node(O).rank=C.node(H).rank+($?q.minlen:-q.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 Cx}var Tx,o2;function W7(){if(o2)return Tx;o2=1;var e=af(),t=e.longestPath,n=YI(),r=H7();Tx=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 Tx}var Rx,i2;function V7(){if(i2)return Rx;i2=1;var e=Pt();Rx=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 Rx}var Ax,l2;function G7(){if(l2)return Ax;l2=1;var e=Pt(),t=or();Ax={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,O=C!==R?1:m-y[v]+1;u.setEdge(b,C,{weight:I,minlen:O,nestingEdge:!0}),u.setEdge(R,_,{weight:I,minlen:O,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 Ax}var Mx,c2;function K7(){if(c2)return Mx;c2=1;var e=Pt(),t=or();Mx=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 Mx}var Ix,u2;function Y7(){if(u2)return Ix;u2=1;var e=Pt();Ix={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 Ix}var $x,d2;function X7(){if(d2)return $x;d2=1;var e=Pt();$x=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 $x}var Ox,h2;function Z7(){if(h2)return Ox;h2=1;var e=Pt();Ox=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 Ox}var Lx,f2;function Q7(){if(f2)return Lx;f2=1;var e=Pt();Lx=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 Lx}var Px,p2;function J7(){if(p2)return Px;p2=1;var e=Pt();Px=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 Px}var Dx,m2;function e9(){if(m2)return Dx;m2=1;var e=Pt(),t=or();Dx=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 Dx}var Fx,g2;function t9(){if(g2)return Fx;g2=1;var e=Pt(),t=Q7(),n=J7(),r=e9();Fx=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 Fx}var qx,y2;function n9(){if(y2)return qx;y2=1;var e=Pt(),t=vs().Graph;qx=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 qx}var Bx,w2;function r9(){if(w2)return Bx;w2=1;var e=Pt();Bx=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 Bx}var zx,v2;function s9(){if(v2)return zx;v2=1;var e=Pt(),t=X7(),n=Z7(),r=t9(),s=n9(),l=r9(),c=vs().Graph,u=or();zx=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 zx}var Ux,x2;function a9(){if(x2)return Ux;x2=1;var e=Pt(),t=vs().Graph,n=or();Ux={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 O=0,H=0,q=R.length,$=e.last(I);return e.forEach(I,function(V,ne){var ee=l(k,V),M=ee?k.node(ee).order:q;(ee||V===$)&&(e.forEach(I.slice(H,ne+1),function(Z){e.forEach(k.predecessors(Z),function(K){var D=k.node(K),P=D.order;(P<O||M<P)&&!(D.dummy&&k.node(Z).dummy)&&c(E,K,Z)})}),H=ne+1,O=M)}),I}return e.reduce(j,C),E}function s(k,j){var E={};function C(I,O,H,q,$){var V;e.forEach(e.range(O,H),function(ne){V=I[ne],k.node(V).dummy&&e.forEach(k.predecessors(V),function(ee){var M=k.node(ee);M.dummy&&(M.order<q||M.order>$)&&c(E,ee,V)})})}function R(I,O){var H=-1,q,$=0;return e.forEach(O,function(V,ne){if(k.node(V).dummy==="border"){var ee=k.predecessors(V);ee.length&&(q=k.node(ee[0]).order,C(O,$,ne,H,q),$=ne,H=q)}C(O,$,O.length,q,I.length)}),O}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={},O={};return e.forEach(j,function(H){e.forEach(H,function(q,$){R[q]=q,I[q]=q,O[q]=$})}),e.forEach(j,function(H){var q=-1;e.forEach(H,function($){var V=C($);if(V.length){V=e.sortBy(V,function(K){return O[K]});for(var ne=(V.length-1)/2,ee=Math.floor(ne),M=Math.ceil(ne);ee<=M;++ee){var Z=V[ee];I[$]===$&&q<O[Z]&&!u(E,$,Z)&&(I[Z]=$,I[$]=R[$]=R[Z],q=O[Z])}}})}),{root:R,align:I}}function p(k,j,E,C,R){var I={},O=h(k,j,E,R),H=R?"borderLeft":"borderRight";function q(ne,ee){for(var M=O.nodes(),Z=M.pop(),K={};Z;)K[Z]?ne(Z):(K[Z]=!0,M.push(Z),M=M.concat(ee(Z))),Z=M.pop()}function $(ne){I[ne]=O.inEdges(ne).reduce(function(ee,M){return Math.max(ee,I[M.v]+O.edge(M))},0)}function V(ne){var ee=O.outEdges(ne).reduce(function(Z,K){return Math.min(Z,I[K.w]-O.edge(K))},Number.POSITIVE_INFINITY),M=k.node(ne);ee!==Number.POSITIVE_INFINITY&&M.borderType!==H&&(I[ne]=Math.max(I[ne],ee))}return q($,O.predecessors.bind(O)),q(V,O.successors.bind(O)),e.forEach(C,function(ne){I[ne]=I[E[ne]]}),I}function h(k,j,E,C){var R=new t,I=k.graph(),O=b(I.nodesep,I.edgesep,C);return e.forEach(j,function(H){var q;e.forEach(H,function($){var V=E[$];if(R.setNode(V),q){var ne=E[q],ee=R.edge(ne,V);R.setEdge(ne,V,Math.max(O(k,$,q),ee||0))}q=$})}),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,O){var H=_(k,O)/2;C=Math.max(I+H,C),R=Math.min(I-H,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(O){var H=I+O,q=k[H],$;if(q!==j){var V=e.values(q);$=O==="l"?C-e.min(V):R-e.max(V),$&&(k[H]=e.mapValues(q,function(ne){return ne+$}))}})})}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(O){R=O==="u"?j:e.values(j).reverse(),e.forEach(["l","r"],function(H){H==="r"&&(R=e.map(R,function(ne){return e.values(ne).reverse()}));var q=(O==="u"?k.predecessors:k.successors).bind(k),$=f(k,R,E,q),V=p(k,R,$.root,$.align,H==="r");H==="r"&&(V=e.mapValues(V,function(ne){return-ne})),C[O+H]=V})});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 O=C.node(R),H=C.node(I),q=0,$;if(q+=O.width/2,e.has(O,"labelpos"))switch(O.labelpos.toLowerCase()){case"l":$=-O.width/2;break;case"r":$=O.width/2;break}if($&&(q+=E?$:-$),$=0,q+=(O.dummy?j:k)/2,q+=(H.dummy?j:k)/2,q+=H.width/2,e.has(H,"labelpos"))switch(H.labelpos.toLowerCase()){case"l":$=H.width/2;break;case"r":$=-H.width/2;break}return $&&(q+=E?$:-$),$=0,q}}function _(k,j){return k.node(j).width}return Ux}var Hx,b2;function o9(){if(b2)return Hx;b2=1;var e=Pt(),t=or(),n=a9().positionX;Hx=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 Hx}var Wx,k2;function i9(){if(k2)return Wx;k2=1;var e=Pt(),t=z7(),n=U7(),r=W7(),s=or().normalizeRanks,l=V7(),c=or().removeEmptyRanks,u=G7(),f=K7(),p=Y7(),h=s9(),m=o9(),y=or(),v=vs().Graph;Wx=S;function S(U,Y){var z=Y&&Y.debugTiming?y.time:y.notime;z("layout",function(){var ie=z(" buildLayoutGraph",function(){return q(U)});z(" runLayout",function(){b(ie,z)}),z(" updateInputGraph",function(){_(U,ie)})})}function b(U,Y){Y(" makeSpaceForEdgeLabels",function(){$(U)}),Y(" removeSelfEdges",function(){B(U)}),Y(" acyclic",function(){t.run(U)}),Y(" nestingGraph.run",function(){u.run(U)}),Y(" rank",function(){r(y.asNonCompoundGraph(U))}),Y(" injectEdgeLabelProxies",function(){V(U)}),Y(" removeEmptyRanks",function(){c(U)}),Y(" nestingGraph.cleanup",function(){u.cleanup(U)}),Y(" normalizeRanks",function(){s(U)}),Y(" assignRankMinMax",function(){ne(U)}),Y(" removeEdgeLabelProxies",function(){ee(U)}),Y(" normalize.run",function(){n.run(U)}),Y(" parentDummyChains",function(){l(U)}),Y(" addBorderSegments",function(){f(U)}),Y(" order",function(){h(U)}),Y(" insertSelfEdges",function(){W(U)}),Y(" adjustCoordinateSystem",function(){p.adjust(U)}),Y(" position",function(){m(U)}),Y(" positionSelfEdges",function(){F(U)}),Y(" removeBorderNodes",function(){P(U)}),Y(" normalize.undo",function(){n.undo(U)}),Y(" fixupEdgeLabelCoords",function(){K(U)}),Y(" undoCoordinateSystem",function(){p.undo(U)}),Y(" translateGraph",function(){M(U)}),Y(" assignNodeIntersects",function(){Z(U)}),Y(" reversePoints",function(){D(U)}),Y(" acyclic.undo",function(){t.undo(U)})}function _(U,Y){e.forEach(U.nodes(),function(z){var ie=U.node(z),le=Y.node(z);ie&&(ie.x=le.x,ie.y=le.y,Y.children(z).length&&(ie.width=le.width,ie.height=le.height))}),e.forEach(U.edges(),function(z){var ie=U.edge(z),le=Y.edge(z);ie.points=le.points,e.has(le,"x")&&(ie.x=le.x,ie.y=le.y)}),U.graph().width=Y.graph().width,U.graph().height=Y.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"],O={minlen:1,weight:1,width:0,height:0,labeloffset:10,labelpos:"r"},H=["labelpos"];function q(U){var Y=new v({multigraph:!0,compound:!0}),z=re(U.graph());return Y.setGraph(e.merge({},j,G(z,k),e.pick(z,E))),e.forEach(U.nodes(),function(ie){var le=re(U.node(ie));Y.setNode(ie,e.defaults(G(le,C),R)),Y.setParent(ie,U.parent(ie))}),e.forEach(U.edges(),function(ie){var le=re(U.edge(ie));Y.setEdge(ie,e.merge({},O,G(le,I),e.pick(le,H)))}),Y}function $(U){var Y=U.graph();Y.ranksep/=2,e.forEach(U.edges(),function(z){var ie=U.edge(z);ie.minlen*=2,ie.labelpos.toLowerCase()!=="c"&&(Y.rankdir==="TB"||Y.rankdir==="BT"?ie.width+=ie.labeloffset:ie.height+=ie.labeloffset)})}function V(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(z.width&&z.height){var ie=U.node(Y.v),le=U.node(Y.w),ge={rank:(le.rank-ie.rank)/2+ie.rank,e:Y};y.addDummyNode(U,"edge-proxy",ge,"_ep")}})}function ne(U){var Y=0;e.forEach(U.nodes(),function(z){var ie=U.node(z);ie.borderTop&&(ie.minRank=U.node(ie.borderTop).rank,ie.maxRank=U.node(ie.borderBottom).rank,Y=e.max(Y,ie.maxRank))}),U.graph().maxRank=Y}function ee(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);z.dummy==="edge-proxy"&&(U.edge(z.e).labelRank=z.rank,U.removeNode(Y))})}function M(U){var Y=Number.POSITIVE_INFINITY,z=0,ie=Number.POSITIVE_INFINITY,le=0,ge=U.graph(),Ne=ge.marginx||0,Ie=ge.marginy||0;function Ge(Pe){var Be=Pe.x,Te=Pe.y,st=Pe.width,de=Pe.height;Y=Math.min(Y,Be-st/2),z=Math.max(z,Be+st/2),ie=Math.min(ie,Te-de/2),le=Math.max(le,Te+de/2)}e.forEach(U.nodes(),function(Pe){Ge(U.node(Pe))}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.has(Be,"x")&&Ge(Be)}),Y-=Ne,ie-=Ie,e.forEach(U.nodes(),function(Pe){var Be=U.node(Pe);Be.x-=Y,Be.y-=ie}),e.forEach(U.edges(),function(Pe){var Be=U.edge(Pe);e.forEach(Be.points,function(Te){Te.x-=Y,Te.y-=ie}),e.has(Be,"x")&&(Be.x-=Y),e.has(Be,"y")&&(Be.y-=ie)}),ge.width=z-Y+Ne,ge.height=le-ie+Ie}function Z(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y),ie=U.node(Y.v),le=U.node(Y.w),ge,Ne;z.points?(ge=z.points[0],Ne=z.points[z.points.length-1]):(z.points=[],ge=le,Ne=ie),z.points.unshift(y.intersectRect(ie,ge)),z.points.push(y.intersectRect(le,Ne))})}function K(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);if(e.has(z,"x"))switch((z.labelpos==="l"||z.labelpos==="r")&&(z.width-=z.labeloffset),z.labelpos){case"l":z.x-=z.width/2+z.labeloffset;break;case"r":z.x+=z.width/2+z.labeloffset;break}})}function D(U){e.forEach(U.edges(),function(Y){var z=U.edge(Y);z.reversed&&z.points.reverse()})}function P(U){e.forEach(U.nodes(),function(Y){if(U.children(Y).length){var z=U.node(Y),ie=U.node(z.borderTop),le=U.node(z.borderBottom),ge=U.node(e.last(z.borderLeft)),Ne=U.node(e.last(z.borderRight));z.width=Math.abs(Ne.x-ge.x),z.height=Math.abs(le.y-ie.y),z.x=ge.x+z.width/2,z.y=ie.y+z.height/2}}),e.forEach(U.nodes(),function(Y){U.node(Y).dummy==="border"&&U.removeNode(Y)})}function B(U){e.forEach(U.edges(),function(Y){if(Y.v===Y.w){var z=U.node(Y.v);z.selfEdges||(z.selfEdges=[]),z.selfEdges.push({e:Y,label:U.edge(Y)}),U.removeEdge(Y)}})}function W(U){var Y=y.buildLayerMatrix(U);e.forEach(Y,function(z){var ie=0;e.forEach(z,function(le,ge){var Ne=U.node(le);Ne.order=ge+ie,e.forEach(Ne.selfEdges,function(Ie){y.addDummyNode(U,"selfedge",{width:Ie.label.width,height:Ie.label.height,rank:Ne.rank,order:ge+ ++ie,e:Ie.e,label:Ie.label},"_se")}),delete Ne.selfEdges})})}function F(U){e.forEach(U.nodes(),function(Y){var z=U.node(Y);if(z.dummy==="selfedge"){var ie=U.node(z.e.v),le=ie.x+ie.width/2,ge=ie.y,Ne=z.x-le,Ie=ie.height/2;U.setEdge(z.e,z.label),U.removeNode(Y),z.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}],z.label.x=z.x,z.label.y=z.y}})}function G(U,Y){return e.mapValues(e.pick(U,Y),Number)}function re(U){var Y={};return e.forEach(U,function(z,ie){Y[ie.toLowerCase()]=z}),Y}return Wx}var Vx,N2;function l9(){if(N2)return Vx;N2=1;var e=Pt(),t=or(),n=vs().Graph;Vx={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 Vx}var Gx,S2;function c9(){return S2||(S2=1,Gx="0.8.5"),Gx}var Kx,j2;function u9(){return j2||(j2=1,Kx={graphlib:vs(),layout:i9(),debug:l9(),util:{time:or().time,notime:or().notime},version:c9()}),Kx}var d9=u9();const _2=tb(d9),pi=240,Iu=130,Dl=74,Yf=72,gu=Dl+Yf;function XI(e,t){var r;let n=pi;for(const s of e)n=Math.max(n,((r=t.get(s.id))==null?void 0:r.width)??pi);return n}const of=420,ZI=1;function h9(e,t,n,r){return Math.min(ZI,n/Math.max(1,e),r/Math.max(1,t))}function mi(e){var n;return((n=e.data)==null?void 0:n.sessionId)??"_default"}function f9(e,t){return((t==null?void 0:t.get(e))??0)>0?of:0}function p9(e,t){const n=(t==null?void 0:t.get(e))??0;return n>0?6+n*36:0}function $u(e,t,n){const r=t.get(e);return{w:((r==null?void 0:r.width)??pi)+f9(e,n),h:Math.max((r==null?void 0:r.height)??Iu,p9(e,n))}}function m9(e){return[...e.keys()].sort().map(t=>`${t}:${e.get(t)}`).join("|")}function g9(e,t,n,r,s,l){const c=new _2.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}=$u(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);_2.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)??pi,R=(E==null?void 0:E.height)??Iu,I=$u(k,r,l),O=j.x-I.w/2,H=j.y-I.h/2;p.set(k,{x:O,y:H}),O<h&&(h=O),H<m&&(m=H),O+C>y&&(y=O+C),H+R>v&&(v=H+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)??pi,R=(E==null?void 0:E.height)??Iu;_=_===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 QI(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=mi(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,...g9(u.get(h),t,r,l,s,c)})),gap:XI(e,l)}}const JI=e=>e.reduce((t,n)=>Math.max(t,n.width),0)+of,y9=e=>e.reduce((t,n)=>t+n.height,0)+gu*Math.max(0,e.length-1);function B0(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+gu;return p},l=[];for(let f=0;f<e.length;f++){let p=-gu;for(let h=f;h<e.length;h++)l.push(p+=e[h].height+gu)}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=>h9(h.reduce((m,y)=>m+JI(y),0)+t*(h.length-1),Math.max(...h.map(y9)),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 w9(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}=QI(e,t,n);return l.length<2?!1:B0(l,c,r.width,r.height).length!==B0(l,c,s.width,s.height).length}function v9(e,t,n={}){const r=n.pinned??new Map,{laid:s,gap:l}=QI(e,t,n),c=B0(s,l,n.availableWidth??0,n.availableHeight??0),u=new Map;let f=0;for(const p of c){const h=JI(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+gu}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 x9(e,t,n,r,s){const c=Dl+Yf,u=60,f=v=>$u(v,r,s),p=new Map(e.map(v=>[v.id,mi(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,O=R.sid===k?24:c;return S.x<R.x+R.w+I&&R.x<S.x+b+I&&j<R.y+R.h+O&&R.y<j+_+O});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 b9(e,t,n,r,s,l,c){const u=E=>$u(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)??pi,ch:(C==null?void 0:C.height)??Iu}},h=c!=null&&c.width>0&&c.height>0,m=new Map;for(const E of e){if(!f(E.id))continue;const C=mi(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),O=mi(E);y.has(O)?(v.get(O)??v.set(O,[]).get(O)).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=Dl+Yf,_=(E,C,R,I)=>S.some(O=>E<O.x+O.w+Dl&&O.x<E+R+Dl&&C<O.y+O.h+b&&O.y<C+I+b),k=XI(e,r),j=[];for(const E of[...v.keys()].sort()){const C=v.get(E);let R=1/0,I=1/0,O=-1/0,H=-1/0,q=-1/0,$=-1/0;for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id),{cw:F,ch:G}=p(D.id);R=Math.min(R,P.x),I=Math.min(I,P.y),O=Math.max(O,P.x+B),H=Math.max(H,P.y+W),q=Math.max(q,P.x+F),$=Math.max($,P.y+G)}const V=O-R,ne=H-I,ee=[...new Set(S.map(D=>Math.round(D.x)))].sort((D,P)=>D-P),M=ee.length?ee:[R],Z=[0,...S.map(D=>D.y+D.h+b)].sort((D,P)=>D-P);let K=null;if(h){let D=1/0,P=1/0,B=-1/0,W=-1/0;for(const z of S)D=Math.min(D,z.x),P=Math.min(P,z.y),B=Math.max(B,z.x+z.cw),W=Math.max(W,z.y+z.ch);const F=(z,ie)=>{const le=c.width/(Math.max(B,z+q-R)-Math.min(D,z)+of),ge=c.height/(Math.max(W,ie+$-I)-Math.min(P,ie));return[Math.min(ZI,le,ge),Math.min(le,ge),Math.max(le,ge)]},G=(z,ie)=>{for(let le=0;le<z.length;le++){if(z[le]>ie[le]+1e-9)return!0;if(z[le]<ie[le]-1e-9)return!1}return!1},re=Math.round(B+of+k),U=[...new Set([...Z,P])].sort((z,ie)=>z-ie);let Y=null;for(const z of[...M,re])for(const ie of U){if(_(z,ie,V,ne))continue;const le=F(z,ie);(Y===null||G(le,Y))&&(Y=le,K={x:z,y:ie})}K&&K.x===R&&K.y===I&&(K=null)}else e:for(const D of M)for(const P of Z){if(P>=I)break;if(!_(D,P,V,ne)){K={x:D,y:P};break e}}if(K){const D=K.x-R,P=K.y-I;for(const B of C){const W=f(B.id);t.set(B.id,{x:W.x+D,y:W.y+P})}j.push(E)}for(const D of C){const P=f(D.id),{w:B,h:W}=u(D.id);S.push({x:P.x,y:P.y,w:B,h:W,...p(D.id)})}}return j}function k9(e,t,n){const r=new Map;for(const s of e){if(t.has(s.id)||!n(s.id))continue;const l=mi(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(mi(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 N9(e,t,n,r,s,l=!1,c){const p=Dl+Yf+1,h=8,m=1.75,y=200,v=.7,S=.01,b=$=>$u($,r,c),_=$=>n.get($)??t.get($),k=new Map;for(const $ of e){if(!_($.id))continue;const V=mi($),ne=k.get(V);ne?ne.push($):k.set(V,[$])}const j=[],E=new Set,C=new Set,R=s.size===0;for(const $ of[...k.keys()].sort()){const V=k.get($);let ne=1/0,ee=1/0,M=-1/0,Z=-1/0,K=!1;for(const W of V){const F=_(W.id),{w:G,h:re}=b(W.id);ne=Math.min(ne,F.x),ee=Math.min(ee,F.y),M=Math.max(M,F.x+G),Z=Math.max(Z,F.y+re),n.has(W.id)&&(K=!0)}const D=M-ne,P=Z-ee;C.add($);const B=s.get($);B&&(D>B.w+h||P>B.h+h)&&E.add($),s.set($,{w:D,h:P}),j.push({sid:$,members:V.map(W=>W.id),x:ne,y:ee,w:D,h:P,anchored:K,mass:1})}for(const $ of[...s.keys()])C.has($)||s.delete($);if(l||R)return[];let I=!1;for(let $=0;$<j.length&&!I;$++)for(let V=$+1;V<j.length;V++){const ne=j[$],ee=j[V];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 $ of j)E.has($.sid)&&($.mass=8);else for(const $ of j)$.mass=Math.max(1,$.w*$.h/(pi*Iu));const O=new Map(j.map($=>[$.sid,$.x])),H=new Map(j.map($=>[$.sid,$.y]));for(let $=0;$<y;$++){const V=new Map,ne=new Map;let ee=0;for(let M=0;M<j.length;M++)for(let Z=M+1;Z<j.length;Z++){const K=j[M],D=j[Z];if(K.anchored&&D.anchored)continue;const P=K.x+K.w/2,B=K.y+K.h/2,W=D.x+D.w/2,F=D.y+D.h/2,G=(K.w+D.w)/2+61-Math.abs(P-W),re=(K.h+D.h)/2+p-Math.abs(B-F);if(G<=0||re<=0)continue;const U=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.x<=0),Y=(pe,Ae)=>!pe.anchored&&!(Ae<0&&pe.y<=0),z=(pe,Ae,fe)=>{const Se=pe===Ae,Ye=Se?K.sid<D.sid?-1:1:Math.sign(pe-Ae);return fe(K,Ye)||fe(D,-Ye)?Ye:Se&&(fe(K,-Ye)||fe(D,Ye))?-Ye:0},ie=z(P,W,U),le=z(B,F,Y),ge=ie!==0,Ne=le!==0;if(!ge&&!Ne)continue;const Ie=ge&&(!Ne||G*m<re),[Ge,Pe,Be,Te]=Ie?[ie,G,V,U]:[le,re,ne,Y],st=Te(K,Ge),de=Te(D,-Ge),ue=K.mass,se=D.mass,be=st?de?se/(ue+se):1:0,Le=de?st?ue/(ue+se):1:0,ce=Pe*v;Be.set(K.sid,(Be.get(K.sid)??0)+Ge*ce*be),Be.set(D.sid,(Be.get(D.sid)??0)-Ge*ce*Le),ee+=ce}for(const M of j)M.anchored||(M.x=Math.max(0,M.x+(V.get(M.sid)??0)),M.y=Math.max(0,M.y+(ne.get(M.sid)??0)));if(ee<S)break}const q=[];for(const $ of j){const V=$.x-O.get($.sid),ne=$.y-H.get($.sid);if(!(Math.abs(V)<1&&Math.abs(ne)<1)){for(const ee of $.members){if(n.has(ee))continue;const M=t.get(ee);M&&t.set(ee,{x:M.x+V,y:M.y+ne})}q.push($.sid)}}return q}function Fh(e,t,n){return!t.has(e)||n.has(e)}function S9(e,t,n,r){return!t.has(e)&&Fh(e,n,r)}function j9(e,t,n){const r={x:0,y:0};return t.set(e,r),n.add(e),r}function E2(e,t,n,r){n.set(e,t),r.delete(e)}const _9=200,E9=5*6e4,C9=6,T9=2*6e4;function Sh(e,t){if(t.size!==0)for(const n of Array.from(e.keys()))t.has(n)||e.delete(n)}function R9(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 A9(e){const t=new Set;for(const n of e)t.add(n.id),t.add(`group:${n.sessionId}`),n.kind==="root"&&t.add(_b(n.id));return t}function M9(e){const t=new Set;for(const n of e)t.add(n.id),n.kind==="root"&&t.add(_b(n.id));return t}function I9(e,t){let n=s6(e,t,BN);a6(e,t,BN)&&(n=!0);const r=[],s=l=>{r.push(l)};return e6(e,t,_9,E9,s)&&(n=!0),t6(e,t,C9,T9,s)&&(n=!0),{changed:n,forgotten:r}}const $9=300,C2=130,O9=160,T2=new WeakMap;function L9(e,t){let n=T2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:pF(e.agents.values())},T2.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 z0(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 P9(e,t,n,r,s,l,c,u,f,p,h,m,y,v,S,b,_,k){var ee,M,Z,K;const j=[],E=[],C=L9(e,k);for(const D of e.agents.values()){if(!_.has(D.id))continue;const P=D.exitAt!=null,B=b!=null&&!b.has(D.id),W=[P?"rf-exiting":"",B?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,F=l.get(D.id);if(j.push({id:D.id,type:"agent",position:{x:0,y:0},data:C(D),className:W,ariaLabel:sq(D,t,S.has(D.id)),...F?{width:F.width,height:F.height}:null}),D.parentId&&_.has(D.parentId)){const U=Qh(D.sessionId),Y=P,z=S.size>0&&(S.has(D.id)||S.has(D.parentId)),ie=b!=null&&!b.has(D.id)&&!b.has(D.parentId),le=D.state==="active"?2:1.5,ge=z?le+1.5:le,Ne=Y?.2:ie?.12:1,Ie=["sess-edge",D.state==="active"?"sess-live":"sess-idle",Y?"rf-edge-exiting":"",z?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${D.parentId}->${D.id}`,source:D.parentId,target:D.id,animated:(D.state==="active"||z)&&!Y,type:"smoothstep",style:{"--session-hue":U,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:Ne,transition:"var(--edge-transition)"},className:Ie})}const G=D.kind==="root"?jf(D):null,re=G?hM(D.sessionId,G.at):null;if(G&&re&&!lF(re)){const U=_b(D.id),Y=Qh(D.sessionId),z=l.get(U);j.push({id:U,type:"recapNote",position:{x:0,y:0},data:{sessionId:D.sessionId,parentId:D.id,recap:G,noteKey:re,hue:Y},className:B?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${D.label}`,...z?{width:z.width,height:z.height}:null}),E.push({id:`e:recap:${D.id}`,source:U,target:D.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Y}})}}const R=z0(e),I=`${y}#lanes:${m9(R)}`,O=new Set(j.filter(D=>D.type==="recapNote").map(D=>D.id));for(const D of Array.from(h.keys()))hF(D)&&!O.has(D)&&!s.has(D)&&(h.delete(D),m.delete(D));const H=j.filter(D=>S9(D.id,s,h,m));if(H.length>0||I!==v.current){if(H.length>0){const D=k9(v9(j,E,{direction:"LR",pinned:s,measured:l,availableWidth:n,availableHeight:r,lanes:R}),s,P=>Fh(P,h,m)?void 0:h.get(P));for(const P of D)Fh(P.id,h,m)&&E2(P.id,P.position,h,m);b9(j,h,s,l,new Set(H.filter(P=>P.type!=="recapNote").map(P=>P.id)),R,{width:n,height:r});for(const P of H){if(P.type!=="recapNote")continue;const B=(ee=P.data)==null?void 0:ee.parentId;if(!B)continue;const W=s.get(B)??(Fh(B,h,m)?void 0:h.get(B));if(!W)continue;const F=((M=l.get(P.id))==null?void 0:M.width)??$9,G=((Z=l.get(P.id))==null?void 0:Z.height)??C2,re=((K=l.get(B))==null?void 0:K.height)??C2;E2(P.id,{x:W.x-O9-F,y:W.y+(re-G)/2},h,m)}}x9(j,h,s,l,R),v.current=I}const q=N9(j,h,s,l,c,!f||p,R);q.length>0&&u(q);const $=M9(e.agents.values());Sh(h,$),Sh(m,$),Sh(s,$),Sh(l,A9(e.agents.values()));const V=[];let ne=!1;for(const D of j){let P=s.get(D.id)??h.get(D.id);P||(P=j9(D.id,h,m),ne=!0),V.push({...D,position:P})}return ne&&(v.current=""),{nodes:V,edges:E}}const D9=1;function F9(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 q9(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:D9,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(F9)}))}}function B9(e,t){const n=(e||"session").replace(/[^a-z0-9._-]/gi,"_");return`${dn}-${n}-${t.slice(0,8)}.json`}function z9(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function U9(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 H9(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function W9(e,t){const n=H9(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 V9({agentCount:e,onConfirm:t,onCancel:n}){const r=w.useRef(null),s=pn(n,{focusRef:r,layer:$6}),[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(U9(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=W9(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 G9="Press Esc first if a key does nothing.",K9=[{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 Y9({onClose:e,onTour:t}){const n=pn(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:K9.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:G9})]})]})})}const X9=1024*1024,R2=5,e$=.8,U0=24,Z9="agent-dag.soundCustom.done",Q9="agent-dag.soundCustom.needs-input",yu={done:Z9,"needs-input":Q9};function Ou(e){if(e.kind!=="audio")return e;const{bytes:t,...n}=e;return n}function A2(e){return!e||!/^[a-zA-Z0-9._-]{1,96}$/.test(e)?null:e}function J9(e){return{done:A2(e(yu.done)),"needs-input":A2(e(yu["needs-input"]))}}function eV(e,t){return{done:e.done===t?null:e.done,"needs-input":e["needs-input"]===t?null:e["needs-input"]}}function tV(e){return e.done&&e.done===e["needs-input"]?e.done:null}const nV={wav:"audio/wav",wave:"audio/wav",mp3:"audio/mpeg",ogg:"audio/ogg",oga:"audio/ogg",webm:"audio/webm",m4a:"audio/mp4",mp4:"audio/mp4"},t$=new Set(["audio/wav","audio/x-wav","audio/mpeg","audio/mp3","audio/ogg","audio/webm","audio/mp4"]);function n$(e,t){const n=t.toLowerCase().split(";")[0].trim();if(t$.has(n))return n;const r=e.toLowerCase().split(".").pop()??"";return nV[r]??n}function M2(e,t){const n=n$(e.name,e.type);if(!t$.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>X9)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>R2)return`Audio must be ${R2} seconds or shorter.`}return null}function H0(e){return e>=U0?`There are already ${U0} custom sounds. Delete one first.`:null}function rV(e,t){const n=e.indexOf(t);return n<0?null:e[n+1]??e[n-1]??null}function sV(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,e$/t)}function r$(){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 aV(e,t,n=r$()){var p;const r=((p=e.name)==null?void 0:p.trim())||"Custom sound",s=M2({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=M2({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:n$(r,e.type),duration:c.duration,normalizationGain:sV(f),bytes:l}}function oV(e,t=r$()){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 iV="ccdeck-notification-audio",lV=2,ws="assets",Bs="summaries";function Ku(){return typeof window<"u"?window.ccdeckNotificationAudio??null:null}function cV(){return new Promise((e,t)=>{const n=indexedDB.open(iV,lV);n.onupgradeneeded=r=>{const s=n.result,l=s.objectStoreNames.contains(ws)?n.transaction.objectStore(ws):s.createObjectStore(ws,{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(Ou(f.value)),f.continue())}},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error??new Error("Could not open local audio storage."))})}async function Yu(e,t,n){const r=await cV();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 uV(){const e=Ku();return e?e.list():typeof indexedDB>"u"?[]:await Yu([Bs],"readonly",t=>t.objectStore(Bs).getAll())??[]}async function dV(e){const t=Ku();return t?t.get(e):typeof indexedDB>"u"?null:await Yu([ws],"readonly",n=>n.objectStore(ws).get(e))??null}async function I2(e){const t=Ku();if(t){await t.put(e);return}if(typeof indexedDB>"u")throw new Error("Local audio storage is unavailable in this browser.");await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).put(e),n.objectStore(Bs).put(Ou(e))})}async function hV(e,t){const n=Ku();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 Yu([ws,Bs],"readwrite",r=>{const s=r.objectStore(ws),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(Ou(u))}})}async function fV(e){const t=Ku();if(t){await t.remove(e);return}typeof indexedDB>"u"||await Yu([ws,Bs],"readwrite",n=>{n.objectStore(ws).delete(e),n.objectStore(Bs).delete(e)})}const qh=["done","needs-input"],pV=[{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}]}],mV=[{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}]}],ok={done:pV,"needs-input":mV},wr="two";function W0(e,t){const n=ok[e];return n.find(r=>r.id===t)??n.find(r=>r.id===wr)??n[0]}function s$(e,t){return ok[e].some(r=>r.id===t)?t:wr}W0("done",wr).notes,W0("needs-input",wr).notes;const $2=.04,a$=.24,oi=0,Gl=100,lf=5,gi=50;function Kl(e){if(!Number.isFinite(e))return gi;const t=Math.round(e/lf)*lf;return Math.min(Gl,Math.max(oi,t))}function o$(e){if(e==null)return gi;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Kl(Number(t)):gi}function V0(e){const t=Kl(e),n=$2+(a$-$2)*(t/Gl);return Math.round(n*1e4)/1e4}function gV(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(V0(e)*r*1e4)/1e4}const yV=160,wV="agent-dag.soundLevel.done",vV="agent-dag.soundLevel.needs-input",xV="agent-dag.soundFigure.done",bV="agent-dag.soundFigure.needs-input",i$={done:wV,"needs-input":vV},Bh={done:xV,"needs-input":bV},G0={done:{level:gi,figure:wr},"needs-input":{level:gi,figure:wr}};function kV(e){const t=n=>({level:o$(e(i$[n])),figure:s$(n,e(Bh[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const O2={Stop:"done",Notification:"needs-input"};function NV(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(O2,n)?O2[n]:null}function SV(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=W0(m,v),b=gV(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,V0(y.level)/a$);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*(V0(y.level)/e$);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))??G0)[m]??G0[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=gi){return f(m,{level:Kl(y),figure:wr}),!0}return{unlock:c,play:p,previewCustom:h,state:s,get context(){return n}}}const jV="With no deck tab open, get a notification wherever a sound would have played.",_V="With the ccdeck window closed, get a notification wherever a sound would have played.";function EV(e){return e?_V:jV}const CV="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",L2="Get notified when you're away from this tab.";function TV(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:L2};case"default":return{status:null,ask:!0,ok:!1,note:L2};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 hu(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const P2={done:"Turn finished","needs-input":"Claude is asking"},RV={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function AV({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 Ae;const I=TV(C),O=hu(),H=k&&!E&&!O,[q,$]=w.useState(""),[V,ne]=w.useState("Custom voice"),[ee,M]=w.useState("Your turn"),[Z,K]=w.useState(""),[D,P]=w.useState("1"),[B,W]=w.useState("1"),[F,G]=w.useState([]),[re,U]=w.useState(!1),Y=w.useRef(null),z=w.useRef(null),ie=tV(p),le=((Ae=f.find(fe=>fe.id===ie))==null?void 0:Ae.name)??"the same custom sound",ge=f.length,Ne=H0(ge),Ie=Ne!==null,Ge=Ie?{"aria-disabled":!0,"aria-describedby":"sm-custom-full"}:{},[Pe,Be]=w.useState(null),Te=w.useRef(0),st=w.useRef(new Map),de=w.useRef(null);w.useEffect(()=>{if(!Pe)return;const fe=window.setTimeout(()=>Be(null),4e3);return()=>window.clearTimeout(fe)},[Pe]),w.useEffect(()=>{if(typeof window>"u"||!("speechSynthesis"in window))return;const fe=()=>{const Se=window.speechSynthesis.getVoices();G(Se),K(Ye=>{var qe;return Ye||((qe=Se[0])==null?void 0:qe.voiceURI)||""})};return fe(),window.speechSynthesis.addEventListener("voiceschanged",fe),()=>window.speechSynthesis.removeEventListener("voiceschanged",fe)},[]);const ue=async fe=>{$("");try{await fe()}catch(Se){$(Se instanceof Error?Se.message:"Custom audio could not be saved.")}},se=(fe,Se)=>{const Ye=Date.now(),qe=Cu({armedFor:Pe,target:fe,armedAt:Te.current,now:Ye,gapMs:Mu});if(qe==="arm"){Be(fe),Te.current=Ye;return}if(qe==="ignore")return;Be(null);const ke=rV(f.map(Re=>Re.id),fe);ue(async()=>{var ze;await _(fe);const Re=document.activeElement;Re!==Se&&!A0((Re==null?void 0:Re.tagName)??null)||(ze=ke?st.current.get(ke):de.current)==null||ze.focus()})},be=()=>{var fe;z.current!==null&&clearTimeout(z.current),z.current=null,((fe=Y.current)==null?void 0:fe.state)==="recording"&&Y.current.stop()},Le=async()=>{var Se;if(Ie)return;if($(""),!((Se=navigator.mediaDevices)!=null&&Se.getUserMedia)||typeof MediaRecorder>"u"){$("Microphone recording is unavailable in this browser.");return}let fe;try{fe=await navigator.mediaDevices.getUserMedia({audio:!0})}catch{$("Microphone access was denied or unavailable.");return}if(Y.current){fe.getTracks().forEach(Ye=>Ye.stop());return}try{const Ye=["audio/webm;codecs=opus","audio/ogg;codecs=opus","audio/mp4"].find(Re=>MediaRecorder.isTypeSupported(Re)),qe=new MediaRecorder(fe,Ye?{mimeType:Ye}:void 0),ke=[];Y.current=qe,qe.ondataavailable=Re=>{Re.data.size&&ke.push(Re.data)},qe.onerror=()=>$("Recording failed. Please try again."),qe.onstop=()=>{fe.getTracks().forEach(rt=>rt.stop()),z.current!==null&&clearTimeout(z.current),z.current=null;const Re=Y.current===qe;if(Re&&(Y.current=null),U(!1),!Re||!ke.length)return;const ze=qe.mimeType.split(";")[0],Fe=ze==="audio/mp4"?"m4a":ze==="audio/ogg"?"ogg":"webm",We=new File(ke,`Recorded voice.${Fe}`,{type:ze});ue(()=>y(We))},qe.start(200),U(!0),z.current=setTimeout(be,4400)}catch{Y.current=null,fe.getTracks().forEach(Ye=>Ye.stop()),$("This browser cannot record a supported audio format.")}};w.useEffect(()=>()=>{z.current!==null&&clearTimeout(z.current);const fe=Y.current;Y.current=null,(fe==null?void 0:fe.state)==="recording"&&fe.stop()},[]);const ce=pn(e,{popover:!0}),pe=w.useRef(e);return pe.current=e,w.useEffect(()=>{const fe=Se=>{var qe,ke;const Ye=Se.target;Ye&&((qe=ce.current)!=null&&qe.contains(Ye)||(ke=u.current)!=null&&ke.contains(Ye)||pe.current())};return window.addEventListener("pointerdown",fe,!0),()=>window.removeEventListener("pointerdown",fe,!0)},[ce,u]),o.jsxs("div",{ref:ce,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?CV:EV(O)})]})]}),H&&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:qh.map(fe=>{const Se=r[fe],Ye=`sm-level-${fe}`,qe=`sm-figure-${fe}`;return o.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${fe}`,children:[o.jsxs("div",{className:"sm-tone-head",children:[o.jsx("h3",{className:"sm-tone-name",id:`sm-name-${fe}`,children:P2[fe]}),o.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(fe),"aria-label":`Hear the ${P2[fe].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:oi,max:Gl,step:lf,value:Se.level,onChange:ke=>s(fe,Number(ke.target.value)),style:{"--sm-level":`${(Se.level-oi)/(Gl-oi)*100}%`}}),o.jsxs("span",{className:"sm-read",children:[Se.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[fe]?`custom:${p[fe]}`:Se.figure,onChange:ke=>{const Re=ke.target.value;Re.startsWith("custom:")?m(fe,Re.slice(7)):(h(fe),l(fe,Re))},children:[ok[fe].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:RV[fe]})]},fe)})}),ie&&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 ",U0,", 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:de,type:"file",accept:"audio/wav,audio/x-wav,audio/mpeg,audio/mp3,audio/ogg,.wav,.mp3,.ogg",...Ge,onClick:fe=>{Ie&&fe.preventDefault()},onChange:fe=>{var Ye;const Se=(Ye=fe.target.files)==null?void 0:Ye[0];fe.currentTarget.value="",Se&&!Ie&&ue(()=>y(Se))}})]}),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:fe=>{const Se=fe.currentTarget.parentElement;Ie&&Se&&!Se.open&&fe.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:V,maxLength:80,onChange:fe=>ne(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Text"}),o.jsx("input",{className:"ap-manage-input",value:ee,maxLength:180,onChange:fe=>M(fe.target.value)})]}),o.jsxs("label",{children:[o.jsx("span",{children:"Voice"}),o.jsxs("select",{className:"sm-select",value:Z,onChange:fe=>K(fe.target.value),children:[o.jsx("option",{value:"",children:"System default"}),F.map(fe=>o.jsx("option",{value:fe.voiceURI,children:fe.name},fe.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:D,onChange:fe=>P(fe.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:B,onChange:fe=>W(fe.target.value)})]})]}),o.jsx("button",{type:"button",className:"btn sm-custom-action",...Ge,onClick:()=>{Ie||ue(async()=>{await v({name:V,text:ee,voiceURI:Z,rate:parseFloat(D),pitch:parseFloat(B)}),M("Your turn")})},children:"Add spoken voice"})]})]}),f.length>0&&o.jsx("div",{className:"sm-custom-list",children:f.map(fe=>o.jsxs("div",{className:"sm-custom-item",children:[o.jsx("input",{className:"ap-manage-input","aria-label":`Rename ${fe.name}`,defaultValue:fe.name,maxLength:80,onBlur:Se=>{if(!Se.target.value.trim()){Se.target.value=fe.name;return}ue(()=>S(fe.id,Se.target.value))},onKeyDown:Se=>{Se.key==="Enter"&&Se.currentTarget.blur()}}),o.jsx("span",{children:fe.kind==="audio"?`${fe.duration.toFixed(1)}s`:"Voice"}),o.jsx("button",{type:"button",className:"btn sm-custom-icon","aria-label":`Play ${fe.name}`,onClick:()=>b(fe.id),children:"Play"}),o.jsx("button",{type:"button",ref:Se=>{Se?st.current.set(fe.id,Se):st.current.delete(fe.id)},className:`btn sm-custom-icon${Pe===fe.id?" armed":""}`,onKeyDown:Se=>{Se.repeat&&Se.preventDefault()},onClick:Se=>se(fe.id,Se.currentTarget),"aria-label":Pe===fe.id?`Confirm deleting ${fe.name}`:`Delete ${fe.name}`,title:Pe===fe.id?"Press again to delete this sound. It cannot be brought back.":"Delete this sound",children:Pe===fe.id?"Confirm":"Delete"})]},fe.id))}),q&&o.jsx("p",{className:"sm-custom-error",role:"alert",children:q})]}),o.jsxs("p",{className:"sm-foot",children:[o.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const l$="agent-dag.character-enabled",c$="agent-dag.fm-volume",D2="agent-dag.fm-source",MV=[{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 IV(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 $V(e){return e!=="0"}function OV(){return $V(yr(l$))}function LV(e){return o$(e)}function PV(){return LV(yr(c$))}const F2="agent-dag.fm-custom-stations",q2="agent-dag.fm-muted",K0="custom:",DV=/^UC[A-Za-z0-9_-]{22}$/,FV=/^[A-Za-z0-9_-]{11}$/,ik=/^[A-Za-z0-9_-]{1,80}$/,qV=/\.(mp3|aac|ogg)$/i,BV=/\.m3u8$/i,u$=2048,Lu=80;function yi(e){return`${K0}${e}`}function Yl(e){if(!e.startsWith(K0))return null;const t=e.slice(K0.length);return ik.test(t)?t:null}function B2(e){return Yl(e)??e}function zV(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 lk(e){var c,u;const t=e.trim();if(t.length>u$)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&&DV.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(FV.test(h))return{kind:"youtube-video",url:r,video:h}}return null}return BV.test(n.pathname)?{kind:"direct-audio",url:r,format:"hls"}:qV.test(n.pathname)?{kind:"direct-audio",url:r,format:"audio"}:null}function UV(e){return e==="1"}function HV(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=lk(u);!ik.test(l)||n.has(l)||!c||c.length>Lu||!f||(n.add(l),r.push({id:l,name:c,url:f.url}))}return r}function WV(e,t,n){const r=Yl(e??"");return r&&t.some(s=>s.id===r)?yi(r):n(e)}function VV(e,t){return e===yi(t)?"claude-fm":e}function GV(){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 KV(e,t,n=GV()){const r=e.trim(),s=lk(t);return!r||r.length>Lu||!ik.test(n)||!s?null:{id:n,name:r,url:s.url}}const Sl=["light","dark"],YV={light:"Light",dark:"Dark"},z2=MV,jl="Give the station a name.",XV="Use an https YouTube live or channel link, or a .mp3, .aac, .ogg or .m3u8 stream.";function ZV({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 QV({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 ue;const _=pn(b),k=[...z2.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:yi(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,O]=w.useState(()=>Math.max(0,k.findIndex(se=>se.value===f))),[H,q]=w.useState(!1),[$,V]=w.useState(""),[ne,ee]=w.useState(""),[M,Z]=w.useState(""),[K,D]=w.useState(!1),[P,B]=w.useState(""),[W,F]=w.useState(""),G=w.useRef(null),re=w.useRef(null),U=w.useRef(null),Y=w.useRef(null),z=w.useRef(null),ie=Yl(f),le=ie?h.find(se=>se.id===ie):void 0;w.useEffect(()=>{const se=k.findIndex(be=>be.value===f);O(se<0?0:se)},[f,h,m]),w.useEffect(()=>{D(!1),B((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 ce,pe;const Le=be.target;!((ce=G.current)!=null&&ce.contains(Le))&&!((pe=z.current)!=null&&pe.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&&(O(se),p(be.value),R(!1),(Le=G.current)==null||Le.focus())},Ie=se=>{if(L6(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),O(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=G.current)==null?void 0:se.focus()},Pe=se=>{var Le,ce;if(se.preventDefault(),!$.trim()){Z(jl),(Le=re.current)==null||Le.focus();return}const be=KV($,ne);if(!be){Z(XV),(ce=U.current)==null||ce.focus();return}y(be),p(yi(be.id)),V(""),ee(""),Z(""),q(!1),Ge()},Be=se=>{var be;if(se.preventDefault(),!!ie){if(!P.trim()){F(jl),(be=Y.current)==null||be.focus();return}v(ie,P),D(!1),Ge()}},Te=se=>{var ce;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(se.key))return;se.preventDefault();const Le=(Sl.indexOf(e)+(se.key==="ArrowLeft"||se.key==="ArrowUp"?-1:1)+Sl.length)%Sl.length;t(Sl[Le]),(ce=se.currentTarget.querySelectorAll('[role="radio"]')[Le])==null||ce.focus()},st=se=>{var Le;if(se.key===" "){se.stopPropagation();return}if(Sf(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"]')[Sl.indexOf(be)])==null||Le.focus())},de=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:()=>O(se),onClick:()=>Ne(se),children:[o.jsx("span",{children:be.label}),f===be.value&&o.jsx("span",{"aria-hidden":!0,children:"✓"})]},be.value)};return Mn.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:Te,children:Sl.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(ZV,{theme:se}),o.jsxs("span",{className:"appearance-theme-name",children:[YV[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:G,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:((ue=k.find(se=>se.value===f))==null?void 0:ue.label)??z2[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:z,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(de)]},`group-${be}`):se.indexes.map(de))})]})]}),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?zV(Yl(f)!==null):""}),o.jsxs("div",{className:"appearance-station-manage",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action","aria-expanded":H,onClick:()=>{q(se=>!se),Z("")},children:H?"Cancel":"+ Add station"}),le&&!K&&o.jsxs("span",{className:"appearance-station-edit",children:[o.jsx("button",{type:"button",className:"btn appearance-station-action",onClick:()=>{B(le.name),F(""),D(!0)},children:"Rename"}),o.jsx("button",{type:"button",className:"btn danger appearance-station-action",onClick:()=>{S(le.id),Ge()},children:"Remove"})]})]}),H&&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:$,onChange:se=>V(se.target.value),"aria-invalid":M===jl||void 0,"aria-describedby":M===jl?"appearance-station-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Link"}),o.jsx("input",{ref:U,className:"ap-manage-input",value:ne,onChange:se=>ee(se.target.value),placeholder:"https://…","aria-invalid":M!==""&&M!==jl||void 0,"aria-describedby":M&&M!==jl?"appearance-station-error":void 0,inputMode:"url",autoComplete:"off",spellCheck:!1,maxLength:u$})]}),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&&K&&o.jsxs("form",{className:"appearance-station-form is-rename",onSubmit:Be,noValidate:!0,children:[o.jsxs("label",{className:"appearance-station-field",children:[o.jsx("span",{children:"Station name"}),o.jsx("input",{ref:Y,className:"ap-manage-input",value:P,onChange:se=>B(se.target.value),"aria-invalid":W!==""||void 0,"aria-describedby":W?"appearance-rename-error":void 0,maxLength:Lu,autoFocus:!0})]}),o.jsx("button",{type:"submit",className:"btn primary",children:"Save"}),o.jsx("button",{type:"button",className:"btn",onClick:()=>{D(!1),Ge()},children:"Cancel"}),W&&o.jsx("p",{id:"appearance-rename-error",className:"appearance-station-error",role:"alert",children:W})]}),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:oi,max:Gl,step:lf,value:s,"aria-describedby":"appearance-fm-volume-note",onChange:se=>l(Number(se.target.value)),style:{"--sm-level":`${(s-oi)/(Gl-oi)*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 Y0="https://www.youtube-nocookie.com";function JV(e,t,n){const r=new URLSearchParams({...n?{}:{channel:e},enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Y0}/embed/${n?encodeURIComponent(n):"live_stream"}?${r.toString()}`}function _l(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function eG(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const tG=[1,3],nG=[0,2],rG=[2,5,100,101,150];function sG(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:tG.includes(s)?{kind:"playing",playing:!0}:nG.includes(s)?{kind:"playing",playing:!1}:null}return null}const d$=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],U2=18,aG=d$.length,h$=new Set(["a","c","p"]);function Xf(e=d$){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 ii=148,H2=6e3,oG=16e3,f$=46,eo=34;function iG(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return{to:r,ms:Math.round(Math.abs(r-e)*f$)}}function lG(e){return Math.round(H2+e()*(oG-H2))}const W2=[{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 cG(e){const t=W2.reduce((r,s)=>r+s.weight,0);let n=e()*t;for(const r of W2)if(n-=r.weight,n<0)return r.kind;return"stroll"}const uG=720,dG=260,hG=620,fG=220,V2=520,p$=1600,G2=7e3,pG=15e3,K2=6e3,mG=14e3;function El(e,t,n=ii){let r=-Math.round(t()*n);if(Math.abs(r-e)<eo){const s=e-eo>=-n?-eo:eo;r=Math.max(-n,Math.min(0,Math.round(e+s)))}return r}const hn=(e,t)=>Math.round(Math.abs(t-e)*f$),gG=120,jh=0;function yG(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:hn(e,t)},{x:t,prop:n({}),act:"stoop",ms:uG},{x:jh,prop:n({held:!0}),act:"carry",ms:hn(t,jh)},{x:jh,prop:n({held:!0}),act:"windup",ms:dG},{x:jh,prop:n({held:!0,leaving:!0}),act:"toss",ms:hG}]}function wG(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:hn(e,r)},{x:r,prop:s(),act:"windup",ms:fG,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"kick",ms:V2,facing:n>0?"right":"left"},{x:r,prop:s({leaving:!0}),act:"stand",ms:p$-V2}]}const m$=640;function vG(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:hn(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:hn(r,0)}]}function xG(e,t,n){const r=Math.max(-110,Math.min(-30,t)),s={x:r,prop:null};return[{...s,act:"walk",ms:hn(e,r)},{...s,act:"skip-ready",ms:500},{...s,act:"skip",ms:m$*(6+Math.floor(n()*5))},{...s,act:"skip-rest",ms:600},{...s,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:hn(r,0)}]}function bG(e,t,n){return[{x:t,prop:null,act:"walk",ms:hn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(K2+n()*(mG-K2))},{x:t,prop:null,act:"stand",ms:400}]}function kG(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:hn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(G2+n()*(pG-G2))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function Yx(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 NG=1500,SG=e=>Math.round(1e3*Math.sqrt(2*e/NG)),jG=115,_G=e=>Math.round(e/jG*1e3),EG=620,CG=200,TG=760,RG=600,AG=240;function MG(e,t,n){const s=-(t.ledgeSpan??ii),l=SG(t.ledgeH),c=_G(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:hn(e,s)},{x:s,act:"peer",prop:null,ms:EG},{x:s,act:"fall",prop:null,ms:l,place:"floor"},{x:s,act:"land",prop:null,ms:CG,place:"floor"},{x:p,act:"walk",prop:null,ms:hn(s,p),place:"floor",floorFrac:u},{x:h,act:"walk",prop:null,ms:hn(p,h),place:"floor",floorFrac:f},{x:s,act:"walk",prop:null,ms:hn(h,s),place:"floor"},{x:s,act:"lasso",prop:null,ms:TG,place:"floor"},{x:s,act:"rope-throw",prop:null,ms:RG,place:"floor"},{x:s,act:"rope-catch",prop:null,ms:AG,place:"floor"},{x:s,act:"climb",prop:null,ms:c},{x:s,act:"pull-up",prop:null,ms:480}]}function IG(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??ii;switch(cG(t)){case"tidy":return yG(e,El(e,t,r));case"kick":return wG(e,El(e,t,r));case"sit":return bG(e,El(e,t,r),t);case"watch":return kG(e,El(e,t,r),t);case"fish":return vG(e,El(e,t,r),t);case"skip":return xG(e,El(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return MG(e,n,t)}}const l=iG(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const $G=[".xx.","xxxx",".xx."],OG=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],LG=["...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."],Xx={litter:$G,ball:OG,scope:LG},g$=["bob","sway","groove"],Y2=9e3,PG=16e3,y$=1e3,DG=.08;function FG(e,t){const n=g$.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],s=(t()*2-1)*DG;return{dance:r,beatMs:Math.round(y$*(1+s))}}function qG(e){return Math.round(Y2+e()*(PG-Y2))}const BG=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],zG=3,UG=-1,X0=11,X2=9,HG=420;function WG(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(HG,Math.max(0,r))}const VG=260,GG=200;function KG(e,t,n){const r=(h,m=hn(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,hn(e,u)),{...p,x:u,act:"mount",ms:VG},{...p,x:f,act:"walk",ms:hn(u,f)},{x:f,prop:null,act:"dismount",ms:GG,place:"floor"},{x:t,prop:null,act:"walk",ms:hn(f,t),place:"floor"}]}function Z2(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 YG={"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 XG(e,t){return t&&yi(t.id)===e?t.name:Yl(e)?"Custom FM":YG[e]}const ZG={"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 Zx(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:Xf(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 Qx={e:"fm-eye",s:"fm-shade",p:"fm-pad"},cf=Xf().filter(e=>!h$.has(e.cell)),QG=Xf().filter(e=>h$.has(e.cell)),Q2=cf.filter(e=>e.cell==="e"),JG=Xf(BG),eK=cf.filter(e=>e.y<X0&&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),tK={left:cf.filter(e=>e.y>=X0&&e.x<X2),right:cf.filter(e=>e.y>=X0&&e.x>=X2)},J2={litter:Zx(Xx.litter,"litter"),ball:Zx(Xx.ball,"ball"),scope:Zx(Xx.scope,"scope")};function nK(e){try{return new URL(e).host}catch{return"the station's server"}}const rK=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),[O,H]=w.useState(null),[q,$]=w.useState(null),[V,ne]=w.useState({x:0,drop:0}),[ee,M]=w.useState("ledge"),[Z,K]=w.useState("left"),[D,P]=w.useState(0),B=w.useRef(null),[W,F]=w.useState(()=>document.hidden);w.useEffect(()=>{const de=new Set,ue=()=>{var se;if(document.hidden){for(const be of((se=B.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),de.add(be)}}else{for(const be of de)be.playState==="paused"&&be.play();de.clear()}F(document.hidden)};return ue(),document.addEventListener("visibilitychange",ue),()=>document.removeEventListener("visibilitychange",ue)},[f,h]);const[G,re]=w.useState(null),[U,Y]=w.useState(y$),[z,ie]=w.useState(()=>{var de;return((de=window.matchMedia)==null?void 0:de.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});w.useEffect(()=>{var se;const de=(se=window.matchMedia)==null?void 0:se.call(window,"(prefers-reduced-motion: reduce)");if(!de)return;const ue=()=>ie(de.matches);return ue(),de.addEventListener("change",ue),()=>de.removeEventListener("change",ue)},[]);const le=w.useRef(null),ge=w.useCallback(()=>{var ue;(ue=j.current)==null||ue.destroy(),j.current=null;const de=k.current;de&&(de.pause(),de.removeAttribute("src"),de.load(),k.current=null)},[]),Ne=w.useCallback(de=>{var ue,se;(se=(ue=le.current)==null?void 0:ue.contentWindow)==null||se.postMessage(de,Y0)},[]),Ie=w.useRef(n);Ie.current=n;const Ge=w.useRef(r);Ge.current=r;const Pe=w.useCallback((de,ue,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,ce=()=>{ge(),v(!1),b(!1)},pe=()=>{Le()&&(ce(),m(!0),u==null||u(se,!0))},Ae=fe=>{if(Le()){if(fe instanceof DOMException&&fe.name==="NotAllowedError"){ce();return}pe()}};be.addEventListener("playing",()=>{Le()&&(b(!0),u==null||u(se,!1))}),be.addEventListener("ended",()=>{Le()&&ce()}),be.addEventListener("error",pe,{once:!0}),ue&&!be.canPlayType("application/vnd.apple.mpegurl")?nb(async()=>{const{default:fe}=await import("./hls-BFpXDghs.js");return{default:fe}},[]).then(({default:fe})=>{if(!Le())return;if(!fe.isSupported()){pe();return}const Se=new fe;j.current=Se,Se.on(fe.Events.ERROR,(Ye,qe)=>{qe.fatal&&pe()}),Se.on(fe.Events.MEDIA_ATTACHED,()=>Se.loadSource(de)),Se.on(fe.Events.MANIFEST_PARSED,()=>{be.play().catch(Ae)}),Se.attachMedia(be)},pe):(be.src=de,be.play().catch(Ae))},[u,ge]);if(w.useEffect(()=>{y&&(Ne(_l("setVolume",[n])),Ne(_l(r?"mute":"unMute")),k.current&&(k.current.volume=n/100,k.current.muted=r))},[n,r,y,Ne]),w.useEffect(()=>{let de=!0;const ue=t??fetch,se=_.current!==l;_.current=l,p(null),m(!1),v(se),b(se),ge();const be=c&&yi(c.id)===s?lk(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),()=>{de=!1}):(ue(`/api/fm-station?url=${encodeURIComponent(be.url)}`).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.channel||pe!=null&&pe.video?(p({live:!0,channel:pe.channel??"",video:pe.video??void 0}),u==null||u(s,!1)):(m(!0),u==null||u(s,!0)))}).catch(()=>{de&&(m(!0),u==null||u(s,!0))}),()=>{de=!1});if(Yl(s))return m(!0),u==null||u(s,!0),()=>{de=!1};const Le=s,ce=ZG[Le];if(ce)ue(ce).then(pe=>pe.ok?pe.json():null).then(pe=>{de&&(pe!=null&&pe.video&&p({live:!0,channel:"",video:pe.video}),u==null||u(s,!(pe!=null&&pe.video)))}).catch(()=>{de&&(u==null||u(s,!0))});else if(Le!=="claude-fm"){const pe=Le.replace("lofi-","");ue(`/api/lofi-girl?station=${encodeURIComponent(pe)}`).then(Ae=>Ae.ok?Ae.json():null).then(Ae=>{de&&(Ae!=null&&Ae.video&&p({live:!0,channel:"",video:Ae.video}),u==null||u(s,!(Ae!=null&&Ae.video)))}).catch(()=>{de&&(u==null||u(s,!0))})}else ue("/api/claude-fm").then(pe=>pe.ok?pe.json():null).then(pe=>{if(!de)return;const Ae=!!(pe!=null&&pe.live&&(pe!=null&&pe.channel));Ae&&p({live:!0,channel:pe.channel}),u==null||u(s,!Ae)}).catch(()=>{de&&(u==null||u(s,!0))});return()=>{de=!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 de=ue=>{var be;if(ue.origin!==Y0||ue.source!==((be=le.current)==null?void 0:be.contentWindow))return;const se=sG(ue.data);if(se){if(se.kind==="ready"){Ne(_l("setVolume",[Ie.current])),Ne(_l(r?"mute":"unMute")),Ne(_l("playVideo"));return}if(se.kind==="playing"){b(se.playing);return}rG.includes(se.code)&&(v(!1),b(!1),m(!0),u==null||u(s,!0))}};return window.addEventListener("message",de),()=>window.removeEventListener("message",de)},[y,r,u,Ne,s]),w.useEffect(()=>{var ze;if(!f||h||z)return;const de=Z2(document);let ue=0;C(Fe=>ue=Fe);let se=null,be=0,Le=0;const ce=Fe=>{var yt,Ot;const[We,...rt]=Fe;if(!We){se=null,H(null),$(null),qe();return}H(We.act),$(We.prop),M(We.place??"ledge"),P(We.riser??0);const dt=ue,ct=Se(We);if(We.act==="kick"){const zt=(Ot=(yt=B.current)==null?void 0:yt.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:Ot.getBoundingClientRect();zt&&ne({x:WG(zt.x,Yx(We,dt,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-zt.y+24)})}Le=We.act==="walk"?Math.max(hn(dt,ct),gG):We.ms,We.act==="carry"&&(Le=hn(dt,ct)),I(Le),K(zt=>Yx({...We,x:ct},dt,zt)),C(ct),ue=ct,se=We,be=Date.now(),de.schedule(()=>ce(rt),Le)},pe=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-sprite"),rt=Fe==null?void 0:Fe.parentElement;if(!Fe||!We||!rt)return null;const dt=Fe.getBoundingClientRect(),ct=rt.getBoundingClientRect(),yt=ct.right-dt.right,Ot=ct.width-yt*2-We.offsetWidth;return Ot>0?Ot:null},Ae=()=>{const Fe=B.current,We=Fe==null?void 0:Fe.querySelector(".fm-walker"),rt=pe();if(!Fe||!We||rt==null)return;const dt=Fe.getBoundingClientRect().bottom-We.getBoundingClientRect().bottom;if(dt>0)return{ledgeH:dt,floorSpan:rt}},fe=()=>{const Fe=B.current,We=document.querySelector(".autofit-chip");if(!Fe||!We)return null;const rt=Fe.getBoundingClientRect(),dt=We.getBoundingClientRect();return dt.width<=0||dt.height<=0?null:{left:dt.left-rt.right,right:dt.right-rt.right,height:dt.height}},Se=Fe=>{const We=(Fe.place??"ledge")==="floor",rt=We?pe()??ii:ii,dt=We&&Fe.floorFrac!=null?-Math.round(Fe.floorFrac*rt):Fe.x;return Math.max(-rt,Math.min(0,dt))},Ye=()=>{if(!se)return;const Fe=Se(se);Fe!==ue&&(I(Math.max(0,be+Le-Date.now())),K(We=>Yx({...se,x:Fe},ue,We)),C(Fe),ue=Fe)},qe=()=>{de.schedule(()=>{const Fe=IG(ue,Math.random,Ae()),We=Fe.some(ct=>ct.place==="floor")?fe():null;let rt=ue;const dt=Fe.flatMap(ct=>{const yt=rt;if(rt=ct.x,!(ct.place==="floor"&&ct.act==="walk"))return[ct];const Ot=KG(yt,ct.x,We),zt=Ot.length-1;return ct.floorFrac==null?Ot:Ot.map((Xt,Dt)=>Dt===zt?{...Xt,floorFrac:ct.floorFrac}:Xt)});ce(dt)},lG(Math.random))},ke=(ze=B.current)==null?void 0:ze.parentElement,Re=typeof ResizeObserver>"u"?null:new ResizeObserver(Ye);return ke&&Re&&Re.observe(ke),qe(),()=>{de.dispose(),Re==null||Re.disconnect(),M("ledge"),C(Fe=>Math.max(-ii,Math.min(0,Fe))),I(0),H(null),$(null),P(0)}},[f,h,z]),w.useEffect(()=>{if(!S||z){re(null);return}const de=Z2(document),ue=se=>{const be=FG(se,Math.random);re(be.dance),Y(be.beatMs),de.schedule(()=>ue(be.dance),qG(Math.random))};return ue(null),()=>de.dispose()},[S,z]),!f||h)return null;const Be=()=>{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 de=!S;b(de),Ne(_l(de?"playVideo":"pauseVideo")),de||v(!1)},Te=XG(s,c),st=f.audio?nK(f.audio):"YouTube";return o.jsxs("div",{ref:B,className:"fm","data-suspended":W?"":void 0,"data-place":ee,style:{"--fm-beat":`${U}ms`},children:[q&&!q.held&&o.jsx("div",{className:"fm-prop","data-prop":q.kind,"data-leaving":q.leaving?"":void 0,style:{"--fm-prop-x":`${q.at}px`,"--fm-roll-to":`${V.x}px`,"--fm-ball-drop":`${V.drop}px`,"--fm-ball-flight-ms":`${p$}ms`,"--fm-ball-turn":Z==="right"?"1080deg":"-1080deg"},children:J2[q.kind]}),(O==="lasso"||O==="rope-throw"||O==="rope-catch"||O==="climb"||O==="pull-up")&&o.jsxs("div",{className:"fm-rope","data-act":O,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":O??void 0,"data-place":ee,"data-facing":Z,style:{"--fm-x":`${E}px`,"--fm-walk-ms":`${R}ms`,"--fm-riser":`${D}px`,"--fm-skip-beat":`${m$}ms`},children:[(q==null?void 0:q.held)&&o.jsx("div",{className:"fm-held","data-prop":q.kind,"data-toss":q.leaving?"":void 0,children:J2[q.kind]}),["cast","fish","reel","stow"].includes(O)&&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)&&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?G??g$[0]:void 0,onClick:Be,title:S?`Stop ${Te}`:`Play ${Te} — streams from ${st}`,"aria-label":S?`Stop ${Te}`:`Play ${Te}`,children:o.jsxs("svg",{viewBox:`0 0 ${U2} ${aG}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[o.jsx("g",{className:"fm-gear",children:o.jsx("g",{className:"fm-gear-motion",children:QG.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`g${de.y}-${de.x}`))})}),o.jsxs("g",{className:"fm-body",children:[Q2.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,fill:"var(--accent)"},`eye-bed-${de.x}`)),eK.map(de=>o.jsx("rect",{x:de.x,y:de.y,width:de.w,height:1,className:Qx[de.cell]},`b${de.y}-${de.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"})]}),Q2.map(de=>o.jsx("rect",{x:de.x-(de.x>=U2/2?1:0)+(Z==="right"?1:0),y:de.y,width:de.w,height:1,className:"fm-eye"},`eye-${de.x}`))]}),o.jsx("g",{className:"fm-hat",children:JG.map(de=>o.jsx("rect",{x:zG+de.x,y:UG+de.y,width:de.w,height:1,className:de.cell==="k"?"fm-hatband":void 0},`h${de.y}-${de.x}`))}),(O==="climb"||O==="rope-throw"||O==="rope-catch"||O==="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"})]}),(O==="land"||O==="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)&&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(de=>o.jsx("g",{className:"fm-leg","data-side":de,children:tK[de].map(ue=>o.jsx("rect",{x:ue.x,y:ue.y,width:ue.w,height:1,className:Qx[ue.cell]},`${de}${ue.y}-${ue.x}`))},de))]})})]}),y&&!f.audio&&(f.channel||f.video)&&o.jsx("iframe",{ref:le,className:"fm-frame",title:Te,src:JV(f.channel,window.location.origin,f.video),onLoad:()=>Ne(eG()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),sK=15e3;function aK(e){return e.visibilityState==="visible"&&e.hasFocus()}function oK(e,t){return t||e===!0}function iK(){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 lK={"//":["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.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 df(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const mR=99;function uX(e){const t=Math.max(0,Math.floor(e));return t>mR?`${mR}+`:String(t)}const dX="Pause the canvas";function hX(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 — ${df(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)":`${df(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function fX(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 O$="paused · full",pX=(e,t)=>t>0?O$:e>0?`paused · ${uX(e)}`:"paused";function mX(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:pX(e.held,t),widest:O$,title:t>0?`Connected — the pause is full at ${df(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${df(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 gX=w.lazy(()=>nb(()=>import("./UsageHistoryModal-B8dnL7pR.js"),[])),yX=w.lazy(()=>nb(()=>import("./BrowserWatchModal-UR0ISjic.js"),[]));function gR(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const wX={agent:eq,sessionGroup:Mq,recapNote:$q},vX={recapTie:Oq},L$="react-flow__node";function n0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,L$))===!0}const r0=80,s0=.86;function yR(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 xX(e){try{const t=document.querySelector(`.${L$}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const bX=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),kX=420,Th=18,wR=400,a0=450,hk="agent-dag.layout",fk="agent-dag.layoutFrame",pk="agent-dag.viewport",P$="agent-dag.sessionListOpen",D$="agent-dag.detailOpen",F$="agent-dag.usagePanelOpen",q$="agent-dag.systemPanelOpen",vR="agent-dag.accountsPanelOpen",o0="agent-dag.versionNoticeDismissed",xR="agent-dag.oldNameNoticeDismissed",NX=15*6e4,i0={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:"},Rh="agent-dag.autoRestart",bR="agent-dag.bundleReloadedFor";function SX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(P$)==="1"}catch{return!1}}function jX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(P$,e?"1":"0")}catch{}}function _X(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(D$)==="1"}catch{return!1}}function EX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(D$,e?"1":"0")}catch{}}function CX(){const e=yr(F$);return e===null?!0:e==="1"}function TX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(F$,e?"1":"0")}catch{}}function RX(){const e=yr(q$);return e===null?!0:e==="1"}function AX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(q$,e?"1":"0")}catch{}}function MX(){if(typeof window>"u")return{positions:[],pins:[]};try{return SY(window.localStorage.getItem(hk))}catch{return{positions:[],pins:[]}}}function Ah(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(hk,jY(e,t))}catch{}}function IX(){if(typeof window>"u")return null;try{return _Y(window.localStorage.getItem(fk))}catch{return null}}function $X(e){if(!(typeof window>"u"))try{window.localStorage.setItem(fk,JSON.stringify(e))}catch{}}function OX(){if(typeof window>"u")return null;try{return EY(window.localStorage.getItem(pk))}catch{return null}}function LX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(pk,JSON.stringify(e))}catch{}}function kR(){if(!(typeof window>"u")){try{window.localStorage.removeItem(hk)}catch{}try{window.localStorage.removeItem(pk)}catch{}try{window.localStorage.removeItem(fk)}catch{}}}function PX(e,t){const n=q9(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=B9(n.label,t),document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(l),1e3)}const B$={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},DX={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 FX({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:DX[e]})})}const hf={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},z$=mM;function qX(){return o.jsx(xb,{children:o.jsx(UX,{})})}const BX=e=>e.transform[2]>=e.maxZoom,zX=e=>e.transform[2]<=e.minZoom;function UX(){var Oc,Lc,ra,Pc;const e=xf(),t=Tt(BX),n=Tt(zX),r=tn(),s=w.useState(S0)[0],l=w.useRef(s),[c,u]=w.useState(()=>DK(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(_X);w.useEffect(()=>{EX(y)},[y]);const[S,b]=w.useState(()=>new Set),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useCallback((T,A,X=!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&&X&&v(!0)},[]),R=w.useCallback(()=>{b(new Set),k(null)},[]),[I,O]=w.useState(null),[H,q]=w.useState(null),$=w.useCallback(T=>q(T),[]),[V,ne]=w.useState(!1),[ee,M]=w.useState(!1),[Z,K]=w.useState(!1),D=w.useRef(null),[P,B]=w.useState(SX);w.useEffect(()=>{jX(P)},[P]);const[W,F]=w.useState(CX);w.useEffect(()=>{TX(W)},[W]);const[G,re]=w.useState(null),[U,Y]=w.useState(!1),z=w.useRef(null);w.useEffect(()=>{let T=!0,A=!1,X=null,te=null,ye="";const _e=vt=>{T&&(Y(!0),vt!==ye&&re(null))},Oe=()=>{if(A)return;A=!0,X=Date.now();const vt=hR();te=vt,fetch(`/api/ccusage?since=${vt}`).then(Et=>Et.ok?Et.json():null).then(Et=>{if(T){if(!(Et!=null&&Et.ok)){_e(vt);return}ye=vt,re(ZY(Et)),Y(!1)}}).catch(()=>_e(vt)).finally(()=>{A=!1})},Ve=()=>{const vt=z.current;XY({shown:!!vt&&vt.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:te,since:hR(),lastReadAt:X,now:Date.now()})&&Oe()};Ve();const it=window.setInterval(Ve,YY);document.addEventListener("visibilitychange",Ve);let Ze=null;return z.current&&typeof ResizeObserver<"u"&&(Ze=new ResizeObserver(Ve),Ze.observe(z.current)),()=>{T=!1,window.clearInterval(it),document.removeEventListener("visibilitychange",Ve),Ze==null||Ze.disconnect()}},[]);const[ie,le]=w.useState(RX);w.useEffect(()=>{AX(ie)},[ie]);const ge=w.useRef(!1),[Ne,Ie]=w.useState(()=>{const T=(()=>{try{const A=window.localStorage.getItem(vR);return A===null?!0:A==="1"}catch{return!0}})();return T&&P?(ge.current=!0,!1):T});w.useEffect(()=>{if(!(!Ne&&ge.current))try{window.localStorage.setItem(vR,Ne?"1":"0")}catch{}},[Ne]),w.useEffect(()=>{!P&&ge.current&&(ge.current=!1,Ie(!0))},[P]);const Ge=gh(Ne,200),Pe=gh(W,130),Be=gh(ie,130),[Te,st]=w.useState(null);w.useEffect(()=>{let T=null;try{T=localStorage.getItem("agent-dag.sound")}catch{}st(T===null?!0:T==="on")},[]);const de=w.useCallback(()=>{st(T=>{var X;const A=T!==!0;try{localStorage.setItem("agent-dag.sound",A?"on":"off")}catch{}return A&&((X=Ut.current)==null||X.unlock()),A})},[]),ue=w.useCallback(T=>{de()},[de]),se=w.useRef(ue);se.current=ue;const be=w.useRef(Te);be.current=Te;const[Le,ce]=w.useState(()=>kV(yr)),pe=w.useRef(Le);pe.current=Le;const[Ae,fe]=w.useState(()=>J9(yr)),Se=w.useRef(Ae);Se.current=Ae;const[Ye,qe]=w.useState([]),ke=w.useCallback(T=>{fe(A=>{const X={...A,[T]:null};return Se.current=X,X});try{localStorage.removeItem(yu[T])}catch{}},[]),Re=w.useCallback((T,A)=>{const X=Se.current[T];if(!(A&&X!==A)){ke(T),ce(te=>{const ye={...te,[T]:{...te[T],figure:wr}};return pe.current=ye,ye});try{localStorage.setItem(Bh[T],wr)}catch{}}},[ke]),ze=w.useRef(Re);ze.current=Re,w.useEffect(()=>{let T=!0;return uV().then(A=>{if(!T)return;qe(A);const X=new Set(A.map(te=>te.id));for(const te of qh){const ye=Se.current[te];ye&&!X.has(ye)&&ze.current(te,ye)}},()=>{}),()=>{T=!1}},[]);const Fe=w.useRef(null),We=w.useCallback((T,A=!1)=>{var X,te;if((X=Ut.current)==null||X.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)},yV)},[]),rt=w.useCallback((T,A)=>{ce(X=>{const te={level:Kl(A.level??X[T].level),figure:s$(T,A.figure??X[T].figure)};try{localStorage.setItem(i$[T],String(te.level)),localStorage.setItem(Bh[T],te.figure)}catch{}return{...X,[T]:te}}),We(T,!0)},[We]),dt=w.useCallback((T,A)=>{if(!Ye.some(te=>te.id===A))return;const X={...Se.current,[T]:A};Se.current=X,fe(X);try{localStorage.setItem(yu[T],A)}catch{}We(T,!0)},[Ye,We]),ct=w.useCallback(async T=>{var ye;const A=H0(Ye.length);if(A)throw new Error(A);const X=window.AudioContext??window.webkitAudioContext;if(!X)throw new Error("This browser cannot decode audio files.");const te=new X;try{const _e=await aV(T,Ve=>te.decodeAudioData(Ve));await I2(_e);const Oe=Ou(_e);qe(Ve=>[...Ve.filter(it=>it.id!==Oe.id),Oe])}finally{(ye=te.close)==null||ye.call(te)}},[Ye.length]),yt=w.useCallback(async T=>{const A=H0(Ye.length);if(A)throw new Error(A);const X=oV(T);await I2(X);const te=Ou(X);qe(ye=>[...ye.filter(_e=>_e.id!==te.id),te])},[Ye.length]),Ot=w.useCallback(async(T,A)=>{const X=Ye.find(ye=>ye.id===T),te=A.trim().slice(0,80);!X||!te||te===X.name||(await hV(T,te),qe(ye=>ye.map(_e=>_e.id===T?{..._e,name:te}:_e)))},[Ye]),zt=w.useCallback(async T=>{await fV(T),qe(ye=>ye.filter(_e=>_e.id!==T));const A=Se.current,X=eV(A,T);Se.current=X,fe(X);const te=qh.filter(ye=>A[ye]===T);for(const ye of te)try{localStorage.removeItem(yu[ye]),localStorage.setItem(Bh[ye],wr)}catch{}te.length>0&&ce(ye=>{const _e={...ye};for(const Oe of te)_e[Oe]={..._e[Oe],figure:wr};return pe.current=_e,_e})},[]),Xt=w.useCallback(T=>{var te,ye;const A=qh.find(_e=>Se.current[_e]===T),X=A?pe.current[A].level:gi;(te=Ut.current)==null||te.unlock(),(ye=Ut.current)==null||ye.previewCustom(T,X)},[]);w.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const[Dt,rn]=w.useState(!1),je=w.useRef(null),[xt,bt]=w.useState(!1),_n=w.useRef(null);w.useEffect(()=>{Dt&&bt(!1)},[Dt]);const Ut=w.useRef(null),[Vn,Vt]=w.useState("locked");w.useEffect(()=>{const T=SV({enabled:()=>be.current===!0,prefs:()=>pe.current,customSelection:()=>Se.current,loadCustom:dV,onCustomFailure:(X,te)=>ze.current(X,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[Lt,Zt]=w.useState(!1),[In,Hr]=w.useState(!1),[xe,lr]=w.useState(null),[ks,Wr]=w.useState(null),[fa,Ns]=w.useState(!1),[xr,$n]=w.useState(null),[Hs,Q]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(o0)??""}catch{return""}}),[De,et]=w.useState(!1),Ue=w.useRef(0),[tt,wt]=w.useState(!1),gt=w.useCallback((T=!1)=>(T&&(Ue.current=Date.now(),wt(!0)),fetch(T?"/api/version?refresh=1":"/api/version").then(A=>A.ok?A.json():null).then(A=>{A&&lr(A)}).catch(()=>{}).finally(()=>{T&&wt(!1)})),[]),It=w.useCallback(()=>{gt(Date.now()-Ue.current>=NX)},[gt]);w.useEffect(()=>{gt();const T=window.setInterval(It,5*6e4),A=()=>{document.visibilityState==="visible"&&It()};return document.addEventListener("visibilitychange",A),()=>{window.clearInterval(T),document.removeEventListener("visibilitychange",A)}},[gt,It]),w.useEffect(()=>{Lt&>()},[Lt,gt]);const Rt=w.useRef(0);w.useEffect(()=>{if(!Lt||!hu())return;let T=!1;const A=Rt.current;return fetch("/api/desktop-update").then(X=>X.ok?X.json():null).then(X=>{if(T||Rt.current!==A)return;const te=rR(X);te&&Wr(te)}).catch(()=>{}),()=>{T=!0}},[Lt]);const Qt=jK(ks),Nt=w.useRef(!1),br=w.useRef(0),cr=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(br.current),[]);const ki=w.useCallback(async T=>{if(!Ps(Nt.current))return;const A=++cr.current;window.clearTimeout(br.current),Nt.current=!0,Ns(!0),$n(null);const X=te=>{A===cr.current&&(window.clearTimeout(br.current),Nt.current=!1,Ns(!1),$n({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 X(TK(await te.json().catch(()=>null)))}catch{return X("unreachable")}A===cr.current&&(br.current=window.setTimeout(()=>X("timeout"),b$))},[]);w.useEffect(()=>{const T=iK();let A=null;const X=Oe=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:T,looking:Oe}),keepalive:!0}).catch(()=>{})},te=()=>{const Oe=aK(document);oK(A,Oe)&&X(Oe),A=Oe},ye=()=>{A&&X(!1),A=!1};te();const _e=window.setInterval(te,sK);return window.addEventListener("focus",te),window.addEventListener("blur",te),document.addEventListener("visibilitychange",te),window.addEventListener("pagehide",ye),()=>{window.clearInterval(_e),window.removeEventListener("focus",te),window.removeEventListener("blur",te),document.removeEventListener("visibilitychange",te),window.removeEventListener("pagehide",ye),ye()}},[]);const ht=(xe==null?void 0:xe.notice)??null,[ur,sn]=w.useState(null),Vr=ur&&Qt?Qt.version:null,Gn=w.useRef(null);w.useEffect(()=>{!Vr||Gn.current===Vr||(Gn.current=Vr,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:Vr})}).catch(()=>{}))},[Vr]);const Xu=w.useRef(!1);w.useEffect(()=>{if(Xu.current)return;const T=nR(),A=gK(T),X=kK({stored:A,running:(xe==null?void 0:xe.running)??null,notes:tR,remembers:yK(T)});if(X.reason==="no-version")return;Xu.current=!0,X.record&&wK(T,X.record);let te=!0;return(async()=>{var it;let _e=vK(T);if(hu())try{const Ze=await fetch("/api/prefs");if(!Ze.ok)throw new Error("desktop tour preferences unavailable");const vt=await Ze.json();if(!(vt!=null&&vt.ok))throw new Error("desktop tour preferences unavailable");const Et=((it=vt.prefs)==null?void 0:it.tourSeen)===!0;_e&&!Et&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),_e=_e||Et}catch{_e=!0}if(!te)return;const Oe=bK({tourSeen:_e,decision:X}),Ve=X.show.length?{entries:X.show,since:A,firstRun:!1}:null;Oe.tour&&K(!0),Oe.notes==="now"?sn(Ve):Oe.notes==="after"&&(D.current=Ve)})(),()=>{te=!1}},[xe==null?void 0:xe.running]);const io=(xe==null?void 0:xe.running)??"3.29.6",Zu=w.useMemo(()=>w$(tR,null,io),[io]),pa=w.useCallback(()=>{sn({entries:Zu,since:null,firstRun:!1})},[Zu]),[Ni,lo]=w.useState(null),[Kn,Zf]=w.useState(eb);w.useEffect(()=>{let T=!1;return fetch("/api/health").then(A=>A.ok?A.json():null).then(A=>{T||(Zf(sX(A)),!(!A||typeof A.workspace!="string")&&lo(A.workspace))}).catch(()=>{}),()=>{T=!0}},[Lt]);const Si=w.useRef(Kn);Si.current=Kn;const co=$$(ht),ma=nX(ht,Hs),oc=w.useCallback(()=>{Q("");try{window.localStorage.setItem(o0,"")}catch{}},[]),uo=w.useCallback(()=>{if(ht){Q(co);try{window.localStorage.setItem(o0,co)}catch{}}},[ht,co]),[Qf,ic]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(xR)??""}catch{return""}}),ft=xe!=null&&xe.invokedAs&&xe.invokedAs!==dn?xe.invokedAs:null,Qu=ft!=null&&Qf!==ft,Ju=w.useCallback(()=>{if(ft){ic(ft);try{window.localStorage.setItem(xR,ft)}catch{}}},[ft]),On=((Oc=xe==null?void 0:xe.upgrade)==null?void 0:Oc.state)??"idle",ho=HU(xe==null?void 0:xe.upgrade),ji=w.useRef(!1),ed=w.useCallback(async()=>{if(Ps(ji.current||On==="running")){ji.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await gt(),ji.current=!1}},[On,gt]);w.useEffect(()=>{if(On!=="running")return;const T=window.setInterval(gt,3e3);return()=>window.clearInterval(T)},[On,gt]);const lc=w.useCallback(async()=>{const T=xe==null?void 0:xe.command;!T||!await hi(T)||(et(!0),window.setTimeout(()=>et(!1),1600))},[xe==null?void 0:xe.command]),fo=w.useCallback(()=>{B(T=>(T||Ie(A=>(A&&(ge.current=!0),!1)),!T))},[]),Gr=w.useCallback(()=>{ge.current=!1,Ie(T=>(T||B(!1),!T))},[]),[Kr,kr]=w.useState(!1),[ga,Ws]=w.useState(!1),[Yr,Jf]=w.useState(()=>{try{return Number(localStorage.getItem(oR))||0}catch{return 0}}),[cc,po]=w.useState([]),[uc,dc]=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)||(po(te.episodes??[]),dc(((ye=te.settings)==null?void 0:ye.enabled)===!0))}).catch(()=>{})};A();const X=setInterval(A,5*6e4);return()=>{T=!1,clearInterval(X)}},[]);const[_i,mo]=w.useState([]),td=w.useRef(new Set),[Ss,ya]=w.useState(null);w.useEffect(()=>{let T=!0,A=0;const X=()=>{fetch("/api/lan").then(te=>te.ok?te.json():null).then(te=>T?(te!=null&&te.ok&&mo(JS(Array.isArray(te.pending)?te.pending:[],te.aliases)),te):null).catch(()=>null).then(te=>{T&&(A=window.setTimeout(X,(te==null?void 0:te.enabled)===!0?q0:VM))})};return X(),()=>{T=!1,window.clearTimeout(A)}},[]);const Vs=w.useCallback(async(T,A)=>{if(!Ss){ya(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)?mo(JS(te.pending,te.aliases)):mo(ye=>ye.filter(_e=>_e.fp!==A))}catch{}finally{ya(null)}}},[Ss]),dr=w.useMemo(()=>fY(cc,Yr).length,[cc,Yr]),[ep,nd]=w.useState(0),Ei=w.useRef(null),[Ci,Ti]=w.useState(!1),wa=w.useRef(null),[js,Ri]=w.useState(0),En=w.useState(()=>tY({protect:T=>n6(l.current,T)}))[0],[go,Ai]=w.useState(!1),va=w.useCallback(()=>{const T=En.paused&&En.dropped>0,A=En.setPaused(!En.paused);T&&r6(l.current);for(const X of A)l.current=zN(l.current,X);Ai(En.paused)},[En]),[Jt,Ln]=w.useState(Date.now()),[Pn,xa]=w.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Rh)!=="0"}catch{return!0}}),ba=w.useRef(!1),tp=w.useCallback(()=>{const T=!Pn;ba.current=!0;try{window.localStorage.removeItem(Rh)}catch{}xa(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 X;A!=null&&A.ok&&xa(((X=A.prefs)==null?void 0:X.autoUpdate)!==!1)}).catch(()=>{})},[Pn]),[Nr,ka]=w.useState(!1),[yo,Mi]=w.useState("restart"),[hc,rd]=w.useState(null),Na=w.useRef(!1),sd=w.useRef(null),Ii=w.useRef(0),wo=w.useCallback(async T=>{if(!Ps(Na.current))return;const A=(T==null?void 0:T.upgrade)===!0;Na.current=!0,sd.current=ho;const X=++Ii.current;Mi(A?"npx":"restart"),ka(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ht==null?void 0:ht.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:A})})}catch{}window.setTimeout(()=>{if(Ii.current===X&&Na.current){Na.current=!1,ka(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},A?18e4:3e4)},[ht==null?void 0:ht.to,ho]),fc=w.useRef(null);w.useEffect(()=>{const T=aj(l.current.agents.values())>0,A=YU({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:T,idleSince:fc.current,now:Jt});fc.current=A.idleSince,A.restart&&wo()},[Pn,ht==null?void 0:ht.kind,xe==null?void 0:xe.canRestart,ma,Jt,wo]);const ad=aj(l.current.agents.values()),od=KU(ad),id=XM({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:ad>0,idleSince:fc.current,now:Jt});w.useEffect(()=>{const T=xe==null?void 0:xe.running;let A=null,X=null;try{A=window.sessionStorage.getItem("agent-dag.restartPending"),X=window.sessionStorage.getItem(bR)}catch{return}const te=UU({bundle:"3.29.6",running:T,pending:A,lastTried:X});if(te==="reload"){try{window.sessionStorage.setItem(bR,T??"")}catch{return}window.location.reload();return}if(te!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1),rd(T??null);const ye=window.setTimeout(()=>rd(null),6e3);return()=>window.clearTimeout(ye)},[xe==null?void 0:xe.running]),w.useEffect(()=>{if(Nr&&WU({asked:sd.current,reported:ho})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1)}},[Nr,ho]);const pc=w.useState(()=>NY(MX()))[0],Gt=w.useRef(pc.pinned),$i=w.useRef(null),Oi=w.useState(()=>OX())[0],[mc,gc]=w.useState(()=>new Set),[Sa,ld]=w.useState(sY),[vo,cd]=w.useState(OV),[Li,np]=w.useState(PV),[xo,yc]=w.useState(()=>HV(yr(F2))),[Pi,rp]=w.useState(()=>UV(yr(q2))),[Gs,Di]=w.useState(()=>WV(yr(D2),xo,IV)),[Ks,Fi]=w.useState(()=>new Set),[ud,dd]=w.useState(0),[Xr,hd]=w.useState(()=>iR(gR)),wc=w.useMemo(()=>bY(Xr),[Xr]),ja=w.useCallback(T=>xY(T,wc),[wc]),[fd,sp]=w.useState(!1);w.useEffect(()=>{document.documentElement.dataset.theme=Sa;try{window.localStorage.setItem(S$,Sa)}catch{}hd(T=>{const A=iR(gR);return kY(T,A)?T:A})},[Sa]),w.useEffect(()=>{try{window.localStorage.setItem(l$,vo?"1":"0")}catch{}},[vo]),w.useEffect(()=>{try{window.localStorage.setItem(c$,String(Li))}catch{}},[Li]),w.useEffect(()=>{try{window.localStorage.setItem(q2,Pi?"1":"0")}catch{}},[Pi]),w.useEffect(()=>{try{window.localStorage.setItem(F2,JSON.stringify(xo))}catch{}},[xo]),w.useEffect(()=>{try{window.localStorage.setItem(D2,Gs)}catch{}},[Gs]);const ap=w.useCallback(T=>{yc(A=>A.some(X=>X.id===T.id)?A:[...A,T]),Fi(A=>{if(!A.has(T.id))return A;const X=new Set(A);return X.delete(T.id),X})},[]),pd=w.useCallback((T,A)=>{const X=A.trim();!X||X.length>Lu||yc(te=>te.map(ye=>ye.id===T?{...ye,name:X}:ye))},[]),md=w.useCallback(T=>{yc(A=>A.filter(X=>X.id!==T)),Di(A=>VV(A,T)),Fi(A=>{if(!A.has(T))return A;const X=new Set(A);return X.delete(T),X})},[]),bo=w.useCallback(T=>{const A=B2(T),X=Ks.has(A);T===Gs&&!X||(X&&Fi(te=>{const ye=new Set(te);return ye.delete(A),ye}),Di(T),dd(te=>te+1))},[Gs,Ks]),ko=w.useCallback((T,A)=>{const X=B2(T);Fi(te=>{if(te.has(X)===A)return te;const _e=new Set(te);return A?_e.add(X):_e.delete(X),_e})},[]);w.useEffect(()=>{const T=document.querySelector('meta[name="theme-color"]'),A=Xr["--panel"];T&&A&&T.setAttribute("content",A)},[Xr]);const hr=w.useCallback((T,A)=>{if(Ch({durationMs:A,documentHidden:document.hidden})){e.setViewport(T,{duration:A});return}const{d3Zoom:X,d3Selection:te}=r.getState(),ye=te==null?void 0:te.property("__zoom");if(X&&te&&ye&&ye.k>0&&T.zoom>0){X.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]),Zr=w.useRef(null),No=w.useRef(0),So=w.useRef(null),qi=w.useRef(()=>{});w.useEffect(()=>{if(!Oi)return;const T=window.setTimeout(()=>{try{hr(Oi,0)}catch{}Ys.current=Date.now()},60);return()=>window.clearTimeout(T)},[hr,Oi]);const Bi=w.useRef(!0),[_a,vc]=w.useState(null);w.useEffect(()=>{const T=new EventSource("/events"),A=JK(m,{now:()=>Date.now(),setTimeout:(_e,Oe)=>window.setTimeout(_e,Oe),clearTimeout:_e=>window.clearTimeout(_e)});let X=!1;const te=typeof BroadcastChannel=="function"?lY(new BroadcastChannel(oY),Math.random().toString(36).slice(2),()=>X):null,ye=window.setInterval(()=>{X||!te||te.ask(600).then(_e=>{X||Hr(iY(_e))})},3e3);return T.addEventListener("open",()=>{Zt(!0),sp(!0)}),T.addEventListener("error",()=>{Zt(!1),vc(null)}),T.addEventListener("open",()=>{X=!0,Hr(!1)}),T.addEventListener("error",()=>{X=!1}),T.addEventListener("replay-end",()=>{Bi.current=!1,A.flush(),vc(Date.now())}),T.addEventListener("desktop-update",_e=>{if(hu())try{const Oe=rR(JSON.parse(_e.data));Oe&&(Rt.current++,Wr(Oe),Oe.status!=="ready"&&(cr.current++,window.clearTimeout(br.current),Nt.current=!1,Ns(!1)))}catch{}}),T.addEventListener("hook",_e=>{var Oe;try{const Ve=JSON.parse(_e.data);if(!En.accept(Ve))return;l.current=zN(l.current,Ve);const it=Ve.replay===!0||Bi.current||Date.now()-Ve.receivedAt>3e4;it?A.replay():A.live();const Ze=NV(Ve,it);Ze&&((Oe=Ut.current)==null||Oe.play(Ze))}catch{}}),()=>{T.close(),A.cancel(),window.clearInterval(ye),te==null||te.leave()}},[m]),w.useEffect(()=>{const T=setInterval(()=>{const A=Date.now();Ln(A);const{changed:X,forgotten:te}=I9(l.current,A);te.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:te})}).catch(()=>{}),b(ye=>R9(ye,l.current.agents)),k(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),q(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),O(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),X&&m()},250);return()=>clearInterval(T)},[m]);const zi=w.useRef(null),Ys=w.useRef(0),gd=420,Yn=w.useCallback((T=500)=>{const A=r0,X=1,te=.2,ye=s0;try{const _e=document.querySelector(".canvas-wrap"),Oe=Array.from(document.querySelectorAll(".react-flow__node")).filter(Ct=>Ct.offsetWidth>0);if(!_e||Oe.length===0)return;const Ve=_e.getBoundingClientRect(),it=e.getViewport();if(!Number.isFinite(it.zoom)||it.zoom<=0)return;const Ze=Ct=>(Ct-Ve.left-it.x)/it.zoom,vt=Ct=>(Ct-Ve.top-it.y)/it.zoom,Et=Oe.map(Ct=>Ct.getBoundingClientRect()),kn=Math.min(...Et.map(Ct=>Ze(Ct.left))),Jn=Math.max(...Et.map(Ct=>Ze(Ct.right))),Oa=Math.min(...Et.map(Ct=>vt(Ct.top))),Ed=Math.max(...Et.map(Ct=>vt(Ct.bottom))),Rr=Jn-kn,Ar=Ed-Oa;if(!(Rr>0&&Ar>0))return;const ll=yR(_e),Dc=Ct=>Math.max(te,Math.min(X,(Ve.width-ll-A*2)/(Rr+Ct)*ye,(Ve.height-A*2)/Ar*ye)),Is=DY(Dc(gd),Dc(0)),La={x:A-kn*Is,y:Math.max(A,(Ve.height-Ar*Is)/2)-Oa*Is,zoom:Is},Ho=++No.current;hr(La,T),Ys.current=Date.now(),Zr.current=Ch({durationMs:T,documentHidden:document.hidden})?{target:La,until:Date.now()+T+60}:null,window.setTimeout(()=>{var Ct;try{if(((Ct=Zr.current)==null?void 0:Ct.target)===La&&(Zr.current=null),No.current!==Ho)return;const Pa=e.getViewport();(Math.abs(Pa.zoom-Is)>.01||Math.abs(Pa.x-La.x)>2)&&hr(La,0)}catch{}},T+60)}catch{}},[e,hr]);w.useEffect(()=>{const T=()=>{if(!document.hidden)return;const A=Zr.current;if(Zr.current=null,!(!A||Date.now()>A.until)){try{hr(A.target,0)}catch{}Ys.current=Date.now()}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[hr]);const xc=w.useRef(""),bc=w.useRef(null),Xn=w.useRef(0),_s=w.useCallback(()=>{Xn.current=Date.now()},[]),Ui=w.useRef(null),kc=w.useRef(0),Hi=w.useCallback(()=>{kc.current=Date.now()},[]),Wi=w.useCallback(T=>({hasSourceEvent:!!T,at:Date.now(),lastDeckFitAt:Ys.current,lastCanvasInputAt:kc.current}),[]),Nc="agent-dag.autoFitDisabled",Xs=w.useRef(!1),[Sc,Zs]=w.useState(!1);w.useEffect(()=>{try{window.localStorage.removeItem(Nc)}catch{}},[]);const Qs=w.useCallback(()=>{Xs.current||(Xs.current=!0,Zs(!0))},[]),Ea=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,X=Date.now(),te=[];for(const _e of A.agents.values())Z0(_e,X)&&te.push({id:_e.id});if(te.length===0)return;const ye=[];for(const{id:_e}of te){const Oe=Sr.current.get(_e),Ve=Gt.current.get(_e)??Kt.current.get(_e);!Oe||!Ve||ye.push({x:Ve.x,y:Ve.y,width:Oe.width,height:Oe.height})}MY({pane:Ui.current,viewport:e.getViewport(),boxes:ye})&&Yn(600)},1500);return()=>clearInterval(T)},[e]);const Ca=w.useRef(!1),Sr=w.useRef(new Map),Ta=w.useRef(0),Ra=w.useCallback(T=>{const A=Sr.current;let X=!1;for(const te of T.nodeInternals.values()){const ye=te.width,_e=te.height;if(ye==null||_e==null)continue;const Oe=A.get(te.id);Oe?(Math.abs(Oe.height-_e)>4||Math.abs(Oe.width-ye)>4)&&(A.set(te.id,{width:ye,height:_e}),X=!0):(A.set(te.id,{width:ye,height:_e}),X=!0)}return X&&(Ta.current+=1),Ta.current},[]),Vi=Tt(Ra),[jc,Gi]=w.useState(0);w.useEffect(()=>{let T=0;const A=()=>{const te=Sr.current;let ye=!1;for(const _e of document.querySelectorAll(".react-flow__node[data-id]")){const Oe=_e.getAttribute("data-id");if(!Oe)continue;const Ve=_e.offsetWidth,it=_e.offsetHeight;if(!Ve||!it)continue;const Ze=te.get(Oe);(!Ze||Math.abs(Ze.width-Ve)>4||Math.abs(Ze.height-it)>4)&&(te.set(Oe,{width:Ve,height:it}),ye=!0)}ye&&Gi(_e=>_e+1)};if(Ca.current)return;let X=0;return document.visibilityState==="hidden"?X=window.setTimeout(A,32):T=requestAnimationFrame(A),()=>{cancelAnimationFrame(T),window.clearTimeout(X)}});const Kt=w.useRef(pc.positions),_c=w.useRef(new Set),jo=w.useRef(""),jr=w.useMemo(()=>FK(l.current.agents.values(),c),[l.current,l.current.revision,c]),Js=w.useMemo(()=>{const T=[];for(const A of l.current.agents.values())!Z0(A,Jt)||jr.has(A.id)||T.push(A.id+(A.parentId?`>${A.parentId}`:""));return T.sort(),`${T.join("|")}#sv${Vi}.${jc}`},[l.current,l.current.revision,Jt,Vi,jc,jr]),Aa=w.useRef(null);w.useEffect(()=>(Aa.current!=null&&window.clearTimeout(Aa.current),Aa.current=window.setTimeout(()=>{Ah(Kt.current,Gt.current)},1500),()=>{Aa.current!=null&&window.clearTimeout(Aa.current)}),[Js]),w.useEffect(()=>{if(xc.current===Js)return;const T=xc.current;if(xc.current=Js,!T||Xs.current)return;Date.now()-Ys.current>1200&&Yn(400),zi.current&&window.clearTimeout(zi.current),zi.current=window.setTimeout(()=>{Xs.current||Yn(500)},280)},[Js,e,Yn]);const _r=w.useMemo(()=>XK(l.current,S),[l.current,l.current.revision,S]),_o=w.useMemo(()=>{const T=yY(l.current,Jt);for(const A of jr)T.delete(A);return T},[l.current,l.current.revision,Jt,jr]),Er=w.useRef(null),[Eo,yd]=w.useState({w:0,h:0});w.useEffect(()=>{const T=Er.current;if(!T||typeof ResizeObserver>"u")return;const A=new ResizeObserver(X=>{var ye;const te=(ye=X[0])==null?void 0:ye.contentRect;te&&(Ui.current={width:te.width,height:te.height},yd(_e=>Math.abs(_e.w-te.width)>40||Math.abs(_e.h-te.height)>40?{w:te.width,h:te.height}:_e))});return A.observe(T),Ui.current={width:T.clientWidth,height:T.clientHeight},yd({w:T.clientWidth,h:T.clientHeight}),()=>A.disconnect()},[]);const Co=w.useCallback(T=>{var X,te;const A=T.target;!(A!=null&&A.closest)||A.closest(bX)!==T.currentTarget||(T.preventDefault(),(te=(X=document.activeElement)==null?void 0:X.blur)==null||te.call(X))},[]),op=w.useRef(new Map),[To,wd]=w.useState(!1);w.useEffect(()=>{const T=window.setTimeout(()=>wd(!0),2500);return()=>window.clearTimeout(T)},[]);const[$t,Ro]=w.useState(!1),fr=w.useRef(null),[Qr,Ec]=w.useState(!1),[Ki,Ma]=w.useState(!1),[Yi,Ia]=w.useState(""),[Ao,vd]=w.useState("far"),xd=w.useRef(null),Cc=gh(Ki,140),Mo=w.useCallback(T=>{var te;const A=(te=xd.current)==null?void 0:te.getBoundingClientRect(),X=KK(T);return A&&X?GK(X,A):"far"},[]),[Xi,Tc]=w.useState("detail"),Jr=w.useRef(null),Io=w.useRef(null),Rc=w.useCallback(()=>{var te;const T=Ta.current;if(((te=Io.current)==null?void 0:te.version)===T)return Io.current.card;const A=[];for(const ye of l.current.agents.keys()){const _e=Sr.current.get(ye);_e&&A.push(_e)}const X=$Y(A);return Io.current={version:T,card:X},X},[]),ip=w.useCallback(()=>{fr.current&&(window.clearTimeout(fr.current),fr.current=null),Ro(!1)},[]),bd=w.useCallback(T=>{T.length!==0&&queueMicrotask(()=>{Ro(!0),fr.current&&window.clearTimeout(fr.current),fr.current=window.setTimeout(()=>Ro(!1),kX+80)})},[]);w.useEffect(()=>()=>{fr.current&&window.clearTimeout(fr.current)},[]);const Cn=_?l.current.agents.get(_):null,kd=y&&Cn!=null,[$o,Es]=w.useState(0);w.useEffect(()=>{const T=yR(Er.current);Es(A=>Math.abs(A-T)>40?T:A)},[Be,Pe,W,kd,Eo.w]);const Zi=w.useRef($o);Zi.current=$o;const es=Eo.w>0?Math.max(0,(Eo.w-$o-r0*2)*s0):0,Dn=Eo.h>0?Math.max(0,(Eo.h-r0*2)*s0):0,Oo=fF(),{nodes:mn,edges:Qi}=w.useMemo(()=>{const T=P9(l.current,Jt,es,Dn,Gt.current,Sr.current,op.current,bd,To,Qr,Kt.current,_c.current,Js,jo,S,_r,_o,$);return qK(T.nodes,T.edges,c)},[l.current,l.current.revision,Jt,es,Dn,To,Qr,Js,S,_r,_o,$,ep,Oo,c]),lp=w.useState(IX)[0],Nd=w.useRef(lp);w.useEffect(()=>{if(!To||Qr)return;const T={width:es,height:Dn};if(!(T.width>0&&T.height>0))return;const A=Nd.current;if(Nd.current=T,$X(T),!A||A.width===T.width&&A.height===T.height)return;const X={direction:"LR",pinned:Gt.current,measured:Sr.current,lanes:z0(l.current)};if(!w9(mn,Qi,X,A,T))return;const te=So.current&&Date.now()-So.current.at<1500?So.current.id:null,ye=te??Rs.current,_e=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);_c.current.clear(),jo.current="",m(),window.setTimeout(()=>{if(Ah(Kt.current,Gt.current),Xs.current){if(te){qi.current(te);return}const Oe=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;if(_e&&Oe&&(Oe.x!==_e.x||Oe.y!==_e.y)){const Ve=e.getViewport();No.current+=1,hr({x:Ve.x-(Oe.x-_e.x)*Ve.zoom,y:Ve.y-(Oe.y-_e.y)*Ve.zoom,zoom:Ve.zoom},0),Ys.current=Date.now()}return}Yn(500)},80)},[es,Dn,To,Qr,m,Yn,e,hr]);const Cs=w.useMemo(()=>{const T=new Map;for(const X of mn){const te=X.data;if(!(te!=null&&te.sessionId)||te.exitAt!=null)continue;const ye=X.width,_e=X.height;if(ye==null||_e==null)continue;const Oe=X.position.x,Ve=X.position.y,it=Oe+ye,Ze=Ve+_e,vt=T.get(te.sessionId);vt?(vt.minX=Math.min(vt.minX,Oe),vt.minY=Math.min(vt.minY,Ve),vt.maxX=Math.max(vt.maxX,it),vt.maxY=Math.max(vt.maxY,Ze)):T.set(te.sessionId,{minX:Oe,minY:Ve,maxX:it,maxY:Ze})}const A=[];for(const[X,te]of T){const ye=te.maxX-te.minX+Th*2,_e=te.maxY-te.minY+Th*2;A.push({id:`group:${X}`,type:j$,position:{x:te.minX-Th,y:te.minY-Th},data:{sessionId:X,w:ye,h:_e},width:ye,height:_e,style:{width:ye,height:_e},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return A},[mn]),Lo=w.useMemo(()=>{const T=[...Cs,...mn],A=wa.current;return!A||A.size===0?T:T.map(X=>{const te=A.get(X.id);return te?{...X,position:te}:X})},[Cs,mn,js]),ts=w.useMemo(()=>{const T=new Set;for(const A of l.current.agents.values())for(const X of A.tools)T.add(z$(X.name));return Object.keys(B$).filter(A=>T.has(A))},[l.current,l.current.revision]);w.useEffect(()=>{if(ts.length<=1){Ti(!1);return}let T=0;const A=()=>{const X=Ei.current;if(X&&!document.hidden){const te=X.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Oe=>Oe.getBoundingClientRect()),_e=vY(te,ye,8);Ti(Oe=>Oe===_e?Oe:_e)}T=window.setTimeout(A,300)};return A(),()=>window.clearTimeout(T)},[ts.length]);const Ji=w.useCallback(T=>{gc(A=>{const X=new Set(A);return X.has(T)?X.delete(T):X.add(T),X})},[]),Po=j?K5(l.current.agents,j):null,ea=w.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=S0(),Gt.current.clear(),Sr.current.clear(),Kt.current.clear(),jo.current="",kR(),u(new Set),p(null);try{window.localStorage.removeItem(uk)}catch{}R(),m()},[m,R]),Cr=w.useCallback(T=>{const A=l.current.agents.get(T);A&&(u(X=>{const te=new Set(X);return te.add(T),sR(window.localStorage,te),te}),p({id:T,label:A.label}),Gt.current.delete(T),Kt.current.delete(T),R())},[R]),At=w.useCallback(()=>{_&&Cr(_)},[_,Cr]),Mt=f&&c.has(f.id)?f:null;w.useEffect(()=>{var T;f&&((T=Er.current)==null||T.focus())},[f]);const Zn=w.useCallback(T=>{const A=[...T];u(X=>{const te=BK(X,A);return te!==X&&sR(window.localStorage,te),te})},[]),an=w.useRef(V);an.current=V;const bn=w.useRef(ee);bn.current=ee;const ns=w.useRef(!1);ns.current=Po!=null||Kr||H!=null||Z||I!=null||ga||ee||ur!=null;const rs=w.useCallback(T=>{const A=z9(T,{confirmOpen:an.current,modalOpen:ns.current});A==="confirm"?ne(!0):A==="clear"&&(ne(!1),ea())},[ea]),gn=w.useCallback(()=>{Gt.current.clear(),Kt.current.clear(),jo.current="",kR(),m(),window.setTimeout(()=>Yn(500),80)},[m,e,Yn]),Do=w.useCallback(()=>Yn(500),[Yn]),Ts=w.useRef(mn);Ts.current=mn;const Fn=w.useCallback(T=>{var vt;const A=Er.current,X=l.current.agents.get(T);if(!A||!X)return;const te=z0(l.current),ye=(Et,kn)=>{const Jn=Sr.current.get(Et.id);if(!Jn)return null;const Oa=kn&&te.has(Et.id)?gd:0;return{x:Et.position.x,y:Et.position.y,width:Jn.width+Oa,height:Jn.height}},_e=Ts.current.find(Et=>Et.id===T),Oe=_e?ye(_e,!1):null;if(!Oe)return;const Ve=[];for(const Et of Ts.current){if(Et.type!=="agent"&&Et.type!=="recapNote"||((vt=Et.data)==null?void 0:vt.sessionId)!==X.sessionId)continue;const kn=ye(Et,Et.type==="agent");kn&&Ve.push(kn)}const it=A.getBoundingClientRect(),Ze=BY({pane:{width:it.width,height:it.height},insets:{top:56,left:72,bottom:32,right:Zi.current+32},context:zY(Ve)??Oe,anchor:Oe});Ka(),Qs(),So.current={id:T,at:Date.now()},No.current+=1,hr(Ze,a0),Ys.current=Date.now(),Zr.current=Ch({durationMs:a0,documentHidden:document.hidden})?{target:Ze,until:Date.now()+a0+60}:null},[hr,Qs]);qi.current=Fn;const el=w.useCallback(T=>{const A=Ts.current.find(X=>X.id===T&&X.type==="agent");return A?A.data:void 0},[]),Sd=w.useCallback(T=>{var A;return(A=l.current.agents.get(T))==null?void 0:A.label},[]),ss=w.useCallback(T=>{var te;const A=Ts.current.find(ye=>ye.id===T&&ye.type==="recapNote");if(!A)return;const X=A.data;return{recap:X.recap,hue:X.hue,sessionLabel:(te=l.current.agents.get(X.parentId))==null?void 0:te.label}},[]),tl=w.useCallback(()=>{var X;const T=(X=Er.current)==null?void 0:X.getBoundingClientRect(),A=document.documentElement;return T?{width:T.right-Zi.current,height:T.bottom}:{width:A.clientWidth,height:A.clientHeight}},[]),Rs=w.useRef(_);Rs.current=_;const Ac=w.useRef(At);Ac.current=At;const nl=w.useCallback(T=>{const A=Ts.current.filter(_e=>_e.type==="agent"),X=IK(A.map(_e=>({id:_e.id,x:_e.position.x,y:_e.position.y})),Rs.current,T),te=X?A.find(_e=>_e.id===X):void 0;if(!te)return;const ye=n0(document.activeElement);C(te.id,!1),window.setTimeout(()=>{try{Fn(te.id)}catch{}ye&&xX(te.id)},30)},[C,Fn]),Tr=w.useRef(null),Qn=w.useCallback(T=>{C(T,!1),window.setTimeout(()=>{try{Fn(T)}catch{}},60)},[C,Fn]),$a=w.useCallback(T=>{jr.has(T)&&Zn([T]),Qn(T)},[jr,Zn,Qn]),Fo=w.useRef(null);w.useEffect(()=>{let T=-1/0;const A=()=>{T=performance.now()},X=te=>{Fo.current=performance.now()-T<250?te.target:null};return window.addEventListener("pointerdown",A,!0),window.addEventListener("focusin",X,!0),()=>{window.removeEventListener("pointerdown",A,!0),window.removeEventListener("focusin",X,!0)}},[]),w.useEffect(()=>{const T=A=>{var Ve,it;const X=A.target,te={tagName:X==null?void 0:X.tagName,isContentEditable:X==null?void 0:X.isContentEditable,role:(Ve=X==null?void 0:X.getAttribute)==null?void 0:Ve.call(X,"role"),type:X==null?void 0:X.type,pointerFocused:X!=null&&X===Fo.current};if(A.key==="Escape"){const Ze=P6({overlayOpen:pu.depth()>0,typing:Sf(te)});Ze==="dismiss"?pu.dismissTop():Ze==="blur"?X==null||X.blur():(PK(te)&&(X==null||X.blur()),R());return}if(Nf(A))return;const ye=n0(X)?(it=X==null?void 0:X.getAttribute)==null?void 0:it.call(X,"data-id"):null,_e=ye&&Ts.current.some(Ze=>Ze.id===ye)?ye:null,Oe=OK(A,_e);if(Oe.kind==="activate"){A.preventDefault(),C(Oe.nodeId,Oe.additive);return}if(Oe.kind!=="node"&&!(Oe.nodeId==null&&V6(te,A.key))&&!G6({key:A.key,modalOpen:K6({appModal:ns.current,dialogDepth:pu.dialogDepth()}),sheetOpen:bn.current})){if(A.key===" "&&(A.preventDefault(),va()),(A.key==="c"||A.key==="C")&&rs("shortcut"),(A.key==="r"||A.key==="R")&&gn(),(A.key==="f"||A.key==="F")&&Do(),(A.key==="z"||A.key==="Z")&&Rs.current&&Fn(Rs.current),A.key==="Delete"&&Ac.current(),(A.key==="l"||A.key==="L")&&fo(),A.key==="d"||A.key==="D")if(Rs.current)v(Ze=>!Ze);else{const Ze=vm(l.current.agents.values());Ze.length>0?Qn(Ze[0].id):nl(1)}if((A.key==="h"||A.key==="H")&&kr(Ze=>!Ze),(A.key==="u"||A.key==="U")&&F(Ze=>!Ze),(A.key==="a"||A.key==="A")&&Si.current.claude&&Gr(),(A.key==="j"||A.key==="J")&&nl(1),(A.key==="k"||A.key==="K")&&nl(-1),A.key==="w"||A.key==="W"){const Ze=_6(vm(l.current.agents.values()),Tr.current);Ze&&(Tr.current=Ze.id,Qn(Ze.id))}(A.key==="t"||A.key==="T")&&ld(Ze=>Ze==="dark"?"light":"dark"),(A.key==="m"||A.key==="M")&&Si.current.claude&&be.current!==null&&se.current(A.shiftKey),(A.key==="s"||A.key==="S")&&le(Ze=>!Ze),(A.key==="b"||A.key==="B")&&Ws(Ze=>!Ze),(A.key==="v"||A.key==="V")&&Si.current.claude&&be.current!==null&&rn(Ze=>!Ze),A.key==="?"&&M(Ze=>!Ze)}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[rs,gn,Do,R,C,nl,Qn,Fn,va]);const qo=l.current.agents.size,_t=w.useMemo(()=>vm(l.current.agents.values()),[l.current,l.current.revision]);w.useEffect(()=>{const T=zK(_t,jr);T.length>0&&Zn(T)},[_t,jr,Zn]);const qn=w.useMemo(()=>E6(l.current.agents.values()),[l.current,l.current.revision]),As=w.useRef(null);w.useEffect(()=>{const T=cY({waiting:_t.length,running:qn,connected:Lt}),A=As.current;if(As.current=T,(A==null?void 0:A.title)!==T.title&&(document.title=T.title),(A==null?void 0:A.icon)!==T.icon){const X=document.querySelector('link[rel="icon"]');X&&(X.href=uY[T.icon])}},[_t.length,qn,Lt]);const[as,os]=w.useState(""),Ms=hY(_t);w.useEffect(()=>{os(T=>aR(T,Ms))},[Ms]);const[jd,rl]=w.useState(""),sl=dr>0?`Browser watch has ${dr} unread ${dr===1?"finding":"findings"}.`:"";w.useEffect(()=>{rl(T=>aR(T,sl,"Browser watch has no unread findings."))},[sl]);const[yn,Bn]=w.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[St,zn]=w.useState(null),[Bo,al]=w.useState(!1),[Mc,ol]=w.useState(!1);w.useEffect(()=>{let T=!0;return fetch("/api/prefs").then(A=>A.ok?A.json():null).then(A=>{var X,te,ye;if(!(!T||!(A!=null&&A.ok))){if(!ba.current){let _e=!1;try{_e=window.localStorage.getItem(Rh)==="0",window.localStorage.removeItem(Rh)}catch{}_e&&((X=A.prefs)==null?void 0:X.autoUpdate)!==!1?(xa(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):xa(((te=A.prefs)==null?void 0:te.autoUpdate)!==!1)}al(((ye=A.prefs)==null?void 0:ye.notifications)===!0),ol(A.notificationsVetoed===!0)}}).catch(()=>{}),()=>{T=!1}},[]);const Ic=w.useRef(()=>{}),il=w.useCallback(()=>{const T=!Bo;al(T),T&&typeof Notification<"u"&&Notification.permission==="default"&&Ic.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 X;A!=null&&A.ok&&(al(((X=A.prefs)==null?void 0:X.notifications)===!0),ol(A.notificationsVetoed===!0))}).catch(()=>{})},[Bo]),_d=typeof Notification<"u";w.useEffect(()=>{if(!St)return;const A=setTimeout(()=>zn(null),St==="blocked"?8e3:4e3);return()=>clearTimeout(A)},[St]);const ta=w.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(T=>{const A=T;Bn(A),A==="granted"?zn("on"):A==="denied"&&zn("blocked")})},[]);Ic.current=ta;const na=w.useRef(new Set),$c=w.useRef(null),zo=_t.map(T=>kf(T.id,T.waiting)).join("|");w.useEffect(()=>{A6($c.current,yn)&&($c.current=yn,na.current=xm(_t))},[yn]);const Uo=w.useRef(!1);return w.useEffect(()=>{M6(Uo.current,_a)&&(Uo.current=!0,na.current=xm(_t))},[_a]),w.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!I6($c.current,_a))return;const T=typeof document>"u"||!document.hidden,A=T6(_t,na.current,T,Bo);for(const X of A)try{const te=new Notification(X.title,{body:X.body,tag:X.key});te.onclick=()=>{window.focus(),Qn(X.sessionId),te.close()}}catch{}na.current=T?xm(_t):R6(_t,A,na.current)},[zo,_a]),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:dn}),Qt?(()=>{const T=CK(_K()??io,Qt.version);return o.jsxs("button",{type:"button",className:"v ready",onClick:pa,"aria-haspopup":"dialog","aria-label":T.label,title:T.title,children:[T.text,o.jsx("span",{className:"v-dot","aria-hidden":!0})]})})():ht?o.jsxs("button",{type:"button",className:"v stale",onClick:()=>{pa(),oc()},"aria-haspopup":"dialog","aria-label":tX({...ht,open:ma}),title:ht.kind==="restart"?`Running v${ht.from}; v${ht.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${ht.from}; v${ht.to} is on npm · click for what's new`,children:["v",ht.from,o.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const T={running:io,latest:xe==null?void 0:xe.latest,latestPending:xe==null?void 0:xe.latestPending,checkedAgo:xe!=null&&xe.checkedAt?Ph(Jt-xe.checkedAt):null,checkFailedAgo:xe!=null&&xe.checkFailedAt&&xe.checkFailedAt>(xe.checkedAt??0)?Ph(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:()=>{pa(),gt(!0)},"aria-busy":tt||void 0,"aria-haspopup":"dialog","aria-label":eX(T),title:JY(T),children:["v",T.running]})})()]}),o.jsxs("span",{className:"status",children:[(()=>{const T=mX({connected:Lt,paused:go,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:z,className:"month-usage",title:G?`${G.tokens.toLocaleString()} tokens · ${fR(G.cost)} spent since the 1st of this local calendar month`:U?"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"}),G?o.jsxs(o.Fragment,{children:[o.jsx("b",{children:Bt(G.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:fR(G.cost)})]}):o.jsx("span",{className:"month-usage-pending",children:U?"unavailable":"…"})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:as}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:jd}),_t.length>0&&o.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{Tr.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 df(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const mR=99;function uX(e){const t=Math.max(0,Math.floor(e));return t>mR?`${mR}+`:String(t)}const dX="Pause the canvas";function hX(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 — ${df(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)":`${df(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function fX(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 O$="paused · full",pX=(e,t)=>t>0?O$:e>0?`paused · ${uX(e)}`:"paused";function mX(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:pX(e.held,t),widest:O$,title:t>0?`Connected — the pause is full at ${df(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${df(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 gX=w.lazy(()=>nb(()=>import("./UsageHistoryModal-Cc9ltAyG.js"),[])),yX=w.lazy(()=>nb(()=>import("./BrowserWatchModal-Du5jrn6d.js"),[]));function gR(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const wX={agent:eq,sessionGroup:Mq,recapNote:$q},vX={recapTie:Oq},L$="react-flow__node";function n0(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,L$))===!0}const r0=80,s0=.86;function yR(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 xX(e){try{const t=document.querySelector(`.${L$}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const bX=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),kX=420,Th=18,wR=400,a0=450,hk="agent-dag.layout",fk="agent-dag.layoutFrame",pk="agent-dag.viewport",P$="agent-dag.sessionListOpen",D$="agent-dag.detailOpen",F$="agent-dag.usagePanelOpen",q$="agent-dag.systemPanelOpen",vR="agent-dag.accountsPanelOpen",o0="agent-dag.versionNoticeDismissed",xR="agent-dag.oldNameNoticeDismissed",NX=15*6e4,i0={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:"},Rh="agent-dag.autoRestart",bR="agent-dag.bundleReloadedFor";function SX(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(P$)==="1"}catch{return!1}}function jX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(P$,e?"1":"0")}catch{}}function _X(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(D$)==="1"}catch{return!1}}function EX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(D$,e?"1":"0")}catch{}}function CX(){const e=yr(F$);return e===null?!0:e==="1"}function TX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(F$,e?"1":"0")}catch{}}function RX(){const e=yr(q$);return e===null?!0:e==="1"}function AX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(q$,e?"1":"0")}catch{}}function MX(){if(typeof window>"u")return{positions:[],pins:[]};try{return SY(window.localStorage.getItem(hk))}catch{return{positions:[],pins:[]}}}function Ah(e,t){if(!(typeof window>"u"))try{window.localStorage.setItem(hk,jY(e,t))}catch{}}function IX(){if(typeof window>"u")return null;try{return _Y(window.localStorage.getItem(fk))}catch{return null}}function $X(e){if(!(typeof window>"u"))try{window.localStorage.setItem(fk,JSON.stringify(e))}catch{}}function OX(){if(typeof window>"u")return null;try{return EY(window.localStorage.getItem(pk))}catch{return null}}function LX(e){if(!(typeof window>"u"))try{window.localStorage.setItem(pk,JSON.stringify(e))}catch{}}function kR(){if(!(typeof window>"u")){try{window.localStorage.removeItem(hk)}catch{}try{window.localStorage.removeItem(pk)}catch{}try{window.localStorage.removeItem(fk)}catch{}}}function PX(e,t){const n=q9(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=B9(n.label,t),document.body.appendChild(c),c.click(),document.body.removeChild(c),setTimeout(()=>URL.revokeObjectURL(l),1e3)}const B$={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},DX={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 FX({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:DX[e]})})}const hf={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},z$=mM;function qX(){return o.jsx(xb,{children:o.jsx(UX,{})})}const BX=e=>e.transform[2]>=e.maxZoom,zX=e=>e.transform[2]<=e.minZoom;function UX(){var Oc,Lc,ra,Pc;const e=xf(),t=Tt(BX),n=Tt(zX),r=tn(),s=w.useState(S0)[0],l=w.useRef(s),[c,u]=w.useState(()=>DK(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(_X);w.useEffect(()=>{EX(y)},[y]);const[S,b]=w.useState(()=>new Set),[_,k]=w.useState(null),[j,E]=w.useState(null),C=w.useCallback((T,A,X=!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&&X&&v(!0)},[]),R=w.useCallback(()=>{b(new Set),k(null)},[]),[I,O]=w.useState(null),[H,q]=w.useState(null),$=w.useCallback(T=>q(T),[]),[V,ne]=w.useState(!1),[ee,M]=w.useState(!1),[Z,K]=w.useState(!1),D=w.useRef(null),[P,B]=w.useState(SX);w.useEffect(()=>{jX(P)},[P]);const[W,F]=w.useState(CX);w.useEffect(()=>{TX(W)},[W]);const[G,re]=w.useState(null),[U,Y]=w.useState(!1),z=w.useRef(null);w.useEffect(()=>{let T=!0,A=!1,X=null,te=null,ye="";const _e=vt=>{T&&(Y(!0),vt!==ye&&re(null))},Oe=()=>{if(A)return;A=!0,X=Date.now();const vt=hR();te=vt,fetch(`/api/ccusage?since=${vt}`).then(Et=>Et.ok?Et.json():null).then(Et=>{if(T){if(!(Et!=null&&Et.ok)){_e(vt);return}ye=vt,re(ZY(Et)),Y(!1)}}).catch(()=>_e(vt)).finally(()=>{A=!1})},Ve=()=>{const vt=z.current;XY({shown:!!vt&&vt.getClientRects().length>0,tabVisible:document.visibilityState==="visible",lastSince:te,since:hR(),lastReadAt:X,now:Date.now()})&&Oe()};Ve();const it=window.setInterval(Ve,YY);document.addEventListener("visibilitychange",Ve);let Ze=null;return z.current&&typeof ResizeObserver<"u"&&(Ze=new ResizeObserver(Ve),Ze.observe(z.current)),()=>{T=!1,window.clearInterval(it),document.removeEventListener("visibilitychange",Ve),Ze==null||Ze.disconnect()}},[]);const[ie,le]=w.useState(RX);w.useEffect(()=>{AX(ie)},[ie]);const ge=w.useRef(!1),[Ne,Ie]=w.useState(()=>{const T=(()=>{try{const A=window.localStorage.getItem(vR);return A===null?!0:A==="1"}catch{return!0}})();return T&&P?(ge.current=!0,!1):T});w.useEffect(()=>{if(!(!Ne&&ge.current))try{window.localStorage.setItem(vR,Ne?"1":"0")}catch{}},[Ne]),w.useEffect(()=>{!P&&ge.current&&(ge.current=!1,Ie(!0))},[P]);const Ge=gh(Ne,200),Pe=gh(W,130),Be=gh(ie,130),[Te,st]=w.useState(null);w.useEffect(()=>{let T=null;try{T=localStorage.getItem("agent-dag.sound")}catch{}st(T===null?!0:T==="on")},[]);const de=w.useCallback(()=>{st(T=>{var X;const A=T!==!0;try{localStorage.setItem("agent-dag.sound",A?"on":"off")}catch{}return A&&((X=Ut.current)==null||X.unlock()),A})},[]),ue=w.useCallback(T=>{de()},[de]),se=w.useRef(ue);se.current=ue;const be=w.useRef(Te);be.current=Te;const[Le,ce]=w.useState(()=>kV(yr)),pe=w.useRef(Le);pe.current=Le;const[Ae,fe]=w.useState(()=>J9(yr)),Se=w.useRef(Ae);Se.current=Ae;const[Ye,qe]=w.useState([]),ke=w.useCallback(T=>{fe(A=>{const X={...A,[T]:null};return Se.current=X,X});try{localStorage.removeItem(yu[T])}catch{}},[]),Re=w.useCallback((T,A)=>{const X=Se.current[T];if(!(A&&X!==A)){ke(T),ce(te=>{const ye={...te,[T]:{...te[T],figure:wr}};return pe.current=ye,ye});try{localStorage.setItem(Bh[T],wr)}catch{}}},[ke]),ze=w.useRef(Re);ze.current=Re,w.useEffect(()=>{let T=!0;return uV().then(A=>{if(!T)return;qe(A);const X=new Set(A.map(te=>te.id));for(const te of qh){const ye=Se.current[te];ye&&!X.has(ye)&&ze.current(te,ye)}},()=>{}),()=>{T=!1}},[]);const Fe=w.useRef(null),We=w.useCallback((T,A=!1)=>{var X,te;if((X=Ut.current)==null||X.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)},yV)},[]),rt=w.useCallback((T,A)=>{ce(X=>{const te={level:Kl(A.level??X[T].level),figure:s$(T,A.figure??X[T].figure)};try{localStorage.setItem(i$[T],String(te.level)),localStorage.setItem(Bh[T],te.figure)}catch{}return{...X,[T]:te}}),We(T,!0)},[We]),dt=w.useCallback((T,A)=>{if(!Ye.some(te=>te.id===A))return;const X={...Se.current,[T]:A};Se.current=X,fe(X);try{localStorage.setItem(yu[T],A)}catch{}We(T,!0)},[Ye,We]),ct=w.useCallback(async T=>{var ye;const A=H0(Ye.length);if(A)throw new Error(A);const X=window.AudioContext??window.webkitAudioContext;if(!X)throw new Error("This browser cannot decode audio files.");const te=new X;try{const _e=await aV(T,Ve=>te.decodeAudioData(Ve));await I2(_e);const Oe=Ou(_e);qe(Ve=>[...Ve.filter(it=>it.id!==Oe.id),Oe])}finally{(ye=te.close)==null||ye.call(te)}},[Ye.length]),yt=w.useCallback(async T=>{const A=H0(Ye.length);if(A)throw new Error(A);const X=oV(T);await I2(X);const te=Ou(X);qe(ye=>[...ye.filter(_e=>_e.id!==te.id),te])},[Ye.length]),Ot=w.useCallback(async(T,A)=>{const X=Ye.find(ye=>ye.id===T),te=A.trim().slice(0,80);!X||!te||te===X.name||(await hV(T,te),qe(ye=>ye.map(_e=>_e.id===T?{..._e,name:te}:_e)))},[Ye]),zt=w.useCallback(async T=>{await fV(T),qe(ye=>ye.filter(_e=>_e.id!==T));const A=Se.current,X=eV(A,T);Se.current=X,fe(X);const te=qh.filter(ye=>A[ye]===T);for(const ye of te)try{localStorage.removeItem(yu[ye]),localStorage.setItem(Bh[ye],wr)}catch{}te.length>0&&ce(ye=>{const _e={...ye};for(const Oe of te)_e[Oe]={..._e[Oe],figure:wr};return pe.current=_e,_e})},[]),Xt=w.useCallback(T=>{var te,ye;const A=qh.find(_e=>Se.current[_e]===T),X=A?pe.current[A].level:gi;(te=Ut.current)==null||te.unlock(),(ye=Ut.current)==null||ye.previewCustom(T,X)},[]);w.useEffect(()=>()=>{Fe.current!==null&&clearTimeout(Fe.current)},[]);const[Dt,rn]=w.useState(!1),je=w.useRef(null),[xt,bt]=w.useState(!1),_n=w.useRef(null);w.useEffect(()=>{Dt&&bt(!1)},[Dt]);const Ut=w.useRef(null),[Vn,Vt]=w.useState("locked");w.useEffect(()=>{const T=SV({enabled:()=>be.current===!0,prefs:()=>pe.current,customSelection:()=>Se.current,loadCustom:dV,onCustomFailure:(X,te)=>ze.current(X,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[Lt,Zt]=w.useState(!1),[In,Hr]=w.useState(!1),[xe,lr]=w.useState(null),[ks,Wr]=w.useState(null),[fa,Ns]=w.useState(!1),[xr,$n]=w.useState(null),[Hs,Q]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(o0)??""}catch{return""}}),[De,et]=w.useState(!1),Ue=w.useRef(0),[tt,wt]=w.useState(!1),gt=w.useCallback((T=!1)=>(T&&(Ue.current=Date.now(),wt(!0)),fetch(T?"/api/version?refresh=1":"/api/version").then(A=>A.ok?A.json():null).then(A=>{A&&lr(A)}).catch(()=>{}).finally(()=>{T&&wt(!1)})),[]),It=w.useCallback(()=>{gt(Date.now()-Ue.current>=NX)},[gt]);w.useEffect(()=>{gt();const T=window.setInterval(It,5*6e4),A=()=>{document.visibilityState==="visible"&&It()};return document.addEventListener("visibilitychange",A),()=>{window.clearInterval(T),document.removeEventListener("visibilitychange",A)}},[gt,It]),w.useEffect(()=>{Lt&>()},[Lt,gt]);const Rt=w.useRef(0);w.useEffect(()=>{if(!Lt||!hu())return;let T=!1;const A=Rt.current;return fetch("/api/desktop-update").then(X=>X.ok?X.json():null).then(X=>{if(T||Rt.current!==A)return;const te=rR(X);te&&Wr(te)}).catch(()=>{}),()=>{T=!0}},[Lt]);const Qt=jK(ks),Nt=w.useRef(!1),br=w.useRef(0),cr=w.useRef(0);w.useEffect(()=>()=>window.clearTimeout(br.current),[]);const ki=w.useCallback(async T=>{if(!Ps(Nt.current))return;const A=++cr.current;window.clearTimeout(br.current),Nt.current=!0,Ns(!0),$n(null);const X=te=>{A===cr.current&&(window.clearTimeout(br.current),Nt.current=!1,Ns(!1),$n({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 X(TK(await te.json().catch(()=>null)))}catch{return X("unreachable")}A===cr.current&&(br.current=window.setTimeout(()=>X("timeout"),b$))},[]);w.useEffect(()=>{const T=iK();let A=null;const X=Oe=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:T,looking:Oe}),keepalive:!0}).catch(()=>{})},te=()=>{const Oe=aK(document);oK(A,Oe)&&X(Oe),A=Oe},ye=()=>{A&&X(!1),A=!1};te();const _e=window.setInterval(te,sK);return window.addEventListener("focus",te),window.addEventListener("blur",te),document.addEventListener("visibilitychange",te),window.addEventListener("pagehide",ye),()=>{window.clearInterval(_e),window.removeEventListener("focus",te),window.removeEventListener("blur",te),document.removeEventListener("visibilitychange",te),window.removeEventListener("pagehide",ye),ye()}},[]);const ht=(xe==null?void 0:xe.notice)??null,[ur,sn]=w.useState(null),Vr=ur&&Qt?Qt.version:null,Gn=w.useRef(null);w.useEffect(()=>{!Vr||Gn.current===Vr||(Gn.current=Vr,fetch("/api/desktop-update/seen",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({version:Vr})}).catch(()=>{}))},[Vr]);const Xu=w.useRef(!1);w.useEffect(()=>{if(Xu.current)return;const T=nR(),A=gK(T),X=kK({stored:A,running:(xe==null?void 0:xe.running)??null,notes:tR,remembers:yK(T)});if(X.reason==="no-version")return;Xu.current=!0,X.record&&wK(T,X.record);let te=!0;return(async()=>{var it;let _e=vK(T);if(hu())try{const Ze=await fetch("/api/prefs");if(!Ze.ok)throw new Error("desktop tour preferences unavailable");const vt=await Ze.json();if(!(vt!=null&&vt.ok))throw new Error("desktop tour preferences unavailable");const Et=((it=vt.prefs)==null?void 0:it.tourSeen)===!0;_e&&!Et&&fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tourSeen:!0}),keepalive:!0}).catch(()=>{}),_e=_e||Et}catch{_e=!0}if(!te)return;const Oe=bK({tourSeen:_e,decision:X}),Ve=X.show.length?{entries:X.show,since:A,firstRun:!1}:null;Oe.tour&&K(!0),Oe.notes==="now"?sn(Ve):Oe.notes==="after"&&(D.current=Ve)})(),()=>{te=!1}},[xe==null?void 0:xe.running]);const io=(xe==null?void 0:xe.running)??"3.29.7",Zu=w.useMemo(()=>w$(tR,null,io),[io]),pa=w.useCallback(()=>{sn({entries:Zu,since:null,firstRun:!1})},[Zu]),[Ni,lo]=w.useState(null),[Kn,Zf]=w.useState(eb);w.useEffect(()=>{let T=!1;return fetch("/api/health").then(A=>A.ok?A.json():null).then(A=>{T||(Zf(sX(A)),!(!A||typeof A.workspace!="string")&&lo(A.workspace))}).catch(()=>{}),()=>{T=!0}},[Lt]);const Si=w.useRef(Kn);Si.current=Kn;const co=$$(ht),ma=nX(ht,Hs),oc=w.useCallback(()=>{Q("");try{window.localStorage.setItem(o0,"")}catch{}},[]),uo=w.useCallback(()=>{if(ht){Q(co);try{window.localStorage.setItem(o0,co)}catch{}}},[ht,co]),[Qf,ic]=w.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(xR)??""}catch{return""}}),ft=xe!=null&&xe.invokedAs&&xe.invokedAs!==dn?xe.invokedAs:null,Qu=ft!=null&&Qf!==ft,Ju=w.useCallback(()=>{if(ft){ic(ft);try{window.localStorage.setItem(xR,ft)}catch{}}},[ft]),On=((Oc=xe==null?void 0:xe.upgrade)==null?void 0:Oc.state)??"idle",ho=HU(xe==null?void 0:xe.upgrade),ji=w.useRef(!1),ed=w.useCallback(async()=>{if(Ps(ji.current||On==="running")){ji.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await gt(),ji.current=!1}},[On,gt]);w.useEffect(()=>{if(On!=="running")return;const T=window.setInterval(gt,3e3);return()=>window.clearInterval(T)},[On,gt]);const lc=w.useCallback(async()=>{const T=xe==null?void 0:xe.command;!T||!await hi(T)||(et(!0),window.setTimeout(()=>et(!1),1600))},[xe==null?void 0:xe.command]),fo=w.useCallback(()=>{B(T=>(T||Ie(A=>(A&&(ge.current=!0),!1)),!T))},[]),Gr=w.useCallback(()=>{ge.current=!1,Ie(T=>(T||B(!1),!T))},[]),[Kr,kr]=w.useState(!1),[ga,Ws]=w.useState(!1),[Yr,Jf]=w.useState(()=>{try{return Number(localStorage.getItem(oR))||0}catch{return 0}}),[cc,po]=w.useState([]),[uc,dc]=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)||(po(te.episodes??[]),dc(((ye=te.settings)==null?void 0:ye.enabled)===!0))}).catch(()=>{})};A();const X=setInterval(A,5*6e4);return()=>{T=!1,clearInterval(X)}},[]);const[_i,mo]=w.useState([]),td=w.useRef(new Set),[Ss,ya]=w.useState(null);w.useEffect(()=>{let T=!0,A=0;const X=()=>{fetch("/api/lan").then(te=>te.ok?te.json():null).then(te=>T?(te!=null&&te.ok&&mo(JS(Array.isArray(te.pending)?te.pending:[],te.aliases)),te):null).catch(()=>null).then(te=>{T&&(A=window.setTimeout(X,(te==null?void 0:te.enabled)===!0?q0:VM))})};return X(),()=>{T=!1,window.clearTimeout(A)}},[]);const Vs=w.useCallback(async(T,A)=>{if(!Ss){ya(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)?mo(JS(te.pending,te.aliases)):mo(ye=>ye.filter(_e=>_e.fp!==A))}catch{}finally{ya(null)}}},[Ss]),dr=w.useMemo(()=>fY(cc,Yr).length,[cc,Yr]),[ep,nd]=w.useState(0),Ei=w.useRef(null),[Ci,Ti]=w.useState(!1),wa=w.useRef(null),[js,Ri]=w.useState(0),En=w.useState(()=>tY({protect:T=>n6(l.current,T)}))[0],[go,Ai]=w.useState(!1),va=w.useCallback(()=>{const T=En.paused&&En.dropped>0,A=En.setPaused(!En.paused);T&&r6(l.current);for(const X of A)l.current=zN(l.current,X);Ai(En.paused)},[En]),[Jt,Ln]=w.useState(Date.now()),[Pn,xa]=w.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(Rh)!=="0"}catch{return!0}}),ba=w.useRef(!1),tp=w.useCallback(()=>{const T=!Pn;ba.current=!0;try{window.localStorage.removeItem(Rh)}catch{}xa(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 X;A!=null&&A.ok&&xa(((X=A.prefs)==null?void 0:X.autoUpdate)!==!1)}).catch(()=>{})},[Pn]),[Nr,ka]=w.useState(!1),[yo,Mi]=w.useState("restart"),[hc,rd]=w.useState(null),Na=w.useRef(!1),sd=w.useRef(null),Ii=w.useRef(0),wo=w.useCallback(async T=>{if(!Ps(Na.current))return;const A=(T==null?void 0:T.upgrade)===!0;Na.current=!0,sd.current=ho;const X=++Ii.current;Mi(A?"npx":"restart"),ka(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ht==null?void 0:ht.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:A})})}catch{}window.setTimeout(()=>{if(Ii.current===X&&Na.current){Na.current=!1,ka(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},A?18e4:3e4)},[ht==null?void 0:ht.to,ho]),fc=w.useRef(null);w.useEffect(()=>{const T=aj(l.current.agents.values())>0,A=YU({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:T,idleSince:fc.current,now:Jt});fc.current=A.idleSince,A.restart&&wo()},[Pn,ht==null?void 0:ht.kind,xe==null?void 0:xe.canRestart,ma,Jt,wo]);const ad=aj(l.current.agents.values()),od=KU(ad),id=XM({enabled:Pn,kind:ht==null?void 0:ht.kind,canRestart:(xe==null?void 0:xe.canRestart)===!0,noticeOpen:ma,visible:document.visibilityState==="visible",busy:ad>0,idleSince:fc.current,now:Jt});w.useEffect(()=>{const T=xe==null?void 0:xe.running;let A=null,X=null;try{A=window.sessionStorage.getItem("agent-dag.restartPending"),X=window.sessionStorage.getItem(bR)}catch{return}const te=UU({bundle:"3.29.7",running:T,pending:A,lastTried:X});if(te==="reload"){try{window.sessionStorage.setItem(bR,T??"")}catch{return}window.location.reload();return}if(te!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1),rd(T??null);const ye=window.setTimeout(()=>rd(null),6e3);return()=>window.clearTimeout(ye)},[xe==null?void 0:xe.running]),w.useEffect(()=>{if(Nr&&WU({asked:sd.current,reported:ho})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Na.current=!1,ka(!1)}},[Nr,ho]);const pc=w.useState(()=>NY(MX()))[0],Gt=w.useRef(pc.pinned),$i=w.useRef(null),Oi=w.useState(()=>OX())[0],[mc,gc]=w.useState(()=>new Set),[Sa,ld]=w.useState(sY),[vo,cd]=w.useState(OV),[Li,np]=w.useState(PV),[xo,yc]=w.useState(()=>HV(yr(F2))),[Pi,rp]=w.useState(()=>UV(yr(q2))),[Gs,Di]=w.useState(()=>WV(yr(D2),xo,IV)),[Ks,Fi]=w.useState(()=>new Set),[ud,dd]=w.useState(0),[Xr,hd]=w.useState(()=>iR(gR)),wc=w.useMemo(()=>bY(Xr),[Xr]),ja=w.useCallback(T=>xY(T,wc),[wc]),[fd,sp]=w.useState(!1);w.useEffect(()=>{document.documentElement.dataset.theme=Sa;try{window.localStorage.setItem(S$,Sa)}catch{}hd(T=>{const A=iR(gR);return kY(T,A)?T:A})},[Sa]),w.useEffect(()=>{try{window.localStorage.setItem(l$,vo?"1":"0")}catch{}},[vo]),w.useEffect(()=>{try{window.localStorage.setItem(c$,String(Li))}catch{}},[Li]),w.useEffect(()=>{try{window.localStorage.setItem(q2,Pi?"1":"0")}catch{}},[Pi]),w.useEffect(()=>{try{window.localStorage.setItem(F2,JSON.stringify(xo))}catch{}},[xo]),w.useEffect(()=>{try{window.localStorage.setItem(D2,Gs)}catch{}},[Gs]);const ap=w.useCallback(T=>{yc(A=>A.some(X=>X.id===T.id)?A:[...A,T]),Fi(A=>{if(!A.has(T.id))return A;const X=new Set(A);return X.delete(T.id),X})},[]),pd=w.useCallback((T,A)=>{const X=A.trim();!X||X.length>Lu||yc(te=>te.map(ye=>ye.id===T?{...ye,name:X}:ye))},[]),md=w.useCallback(T=>{yc(A=>A.filter(X=>X.id!==T)),Di(A=>VV(A,T)),Fi(A=>{if(!A.has(T))return A;const X=new Set(A);return X.delete(T),X})},[]),bo=w.useCallback(T=>{const A=B2(T),X=Ks.has(A);T===Gs&&!X||(X&&Fi(te=>{const ye=new Set(te);return ye.delete(A),ye}),Di(T),dd(te=>te+1))},[Gs,Ks]),ko=w.useCallback((T,A)=>{const X=B2(T);Fi(te=>{if(te.has(X)===A)return te;const _e=new Set(te);return A?_e.add(X):_e.delete(X),_e})},[]);w.useEffect(()=>{const T=document.querySelector('meta[name="theme-color"]'),A=Xr["--panel"];T&&A&&T.setAttribute("content",A)},[Xr]);const hr=w.useCallback((T,A)=>{if(Ch({durationMs:A,documentHidden:document.hidden})){e.setViewport(T,{duration:A});return}const{d3Zoom:X,d3Selection:te}=r.getState(),ye=te==null?void 0:te.property("__zoom");if(X&&te&&ye&&ye.k>0&&T.zoom>0){X.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]),Zr=w.useRef(null),No=w.useRef(0),So=w.useRef(null),qi=w.useRef(()=>{});w.useEffect(()=>{if(!Oi)return;const T=window.setTimeout(()=>{try{hr(Oi,0)}catch{}Ys.current=Date.now()},60);return()=>window.clearTimeout(T)},[hr,Oi]);const Bi=w.useRef(!0),[_a,vc]=w.useState(null);w.useEffect(()=>{const T=new EventSource("/events"),A=JK(m,{now:()=>Date.now(),setTimeout:(_e,Oe)=>window.setTimeout(_e,Oe),clearTimeout:_e=>window.clearTimeout(_e)});let X=!1;const te=typeof BroadcastChannel=="function"?lY(new BroadcastChannel(oY),Math.random().toString(36).slice(2),()=>X):null,ye=window.setInterval(()=>{X||!te||te.ask(600).then(_e=>{X||Hr(iY(_e))})},3e3);return T.addEventListener("open",()=>{Zt(!0),sp(!0)}),T.addEventListener("error",()=>{Zt(!1),vc(null)}),T.addEventListener("open",()=>{X=!0,Hr(!1)}),T.addEventListener("error",()=>{X=!1}),T.addEventListener("replay-end",()=>{Bi.current=!1,A.flush(),vc(Date.now())}),T.addEventListener("desktop-update",_e=>{if(hu())try{const Oe=rR(JSON.parse(_e.data));Oe&&(Rt.current++,Wr(Oe),Oe.status!=="ready"&&(cr.current++,window.clearTimeout(br.current),Nt.current=!1,Ns(!1)))}catch{}}),T.addEventListener("hook",_e=>{var Oe;try{const Ve=JSON.parse(_e.data);if(!En.accept(Ve))return;l.current=zN(l.current,Ve);const it=Ve.replay===!0||Bi.current||Date.now()-Ve.receivedAt>3e4;it?A.replay():A.live();const Ze=NV(Ve,it);Ze&&((Oe=Ut.current)==null||Oe.play(Ze))}catch{}}),()=>{T.close(),A.cancel(),window.clearInterval(ye),te==null||te.leave()}},[m]),w.useEffect(()=>{const T=setInterval(()=>{const A=Date.now();Ln(A);const{changed:X,forgotten:te}=I9(l.current,A);te.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:te})}).catch(()=>{}),b(ye=>R9(ye,l.current.agents)),k(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),q(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),O(ye=>ye!=null&&!l.current.agents.has(ye)?null:ye),X&&m()},250);return()=>clearInterval(T)},[m]);const zi=w.useRef(null),Ys=w.useRef(0),gd=420,Yn=w.useCallback((T=500)=>{const A=r0,X=1,te=.2,ye=s0;try{const _e=document.querySelector(".canvas-wrap"),Oe=Array.from(document.querySelectorAll(".react-flow__node")).filter(Ct=>Ct.offsetWidth>0);if(!_e||Oe.length===0)return;const Ve=_e.getBoundingClientRect(),it=e.getViewport();if(!Number.isFinite(it.zoom)||it.zoom<=0)return;const Ze=Ct=>(Ct-Ve.left-it.x)/it.zoom,vt=Ct=>(Ct-Ve.top-it.y)/it.zoom,Et=Oe.map(Ct=>Ct.getBoundingClientRect()),kn=Math.min(...Et.map(Ct=>Ze(Ct.left))),Jn=Math.max(...Et.map(Ct=>Ze(Ct.right))),Oa=Math.min(...Et.map(Ct=>vt(Ct.top))),Ed=Math.max(...Et.map(Ct=>vt(Ct.bottom))),Rr=Jn-kn,Ar=Ed-Oa;if(!(Rr>0&&Ar>0))return;const ll=yR(_e),Dc=Ct=>Math.max(te,Math.min(X,(Ve.width-ll-A*2)/(Rr+Ct)*ye,(Ve.height-A*2)/Ar*ye)),Is=DY(Dc(gd),Dc(0)),La={x:A-kn*Is,y:Math.max(A,(Ve.height-Ar*Is)/2)-Oa*Is,zoom:Is},Ho=++No.current;hr(La,T),Ys.current=Date.now(),Zr.current=Ch({durationMs:T,documentHidden:document.hidden})?{target:La,until:Date.now()+T+60}:null,window.setTimeout(()=>{var Ct;try{if(((Ct=Zr.current)==null?void 0:Ct.target)===La&&(Zr.current=null),No.current!==Ho)return;const Pa=e.getViewport();(Math.abs(Pa.zoom-Is)>.01||Math.abs(Pa.x-La.x)>2)&&hr(La,0)}catch{}},T+60)}catch{}},[e,hr]);w.useEffect(()=>{const T=()=>{if(!document.hidden)return;const A=Zr.current;if(Zr.current=null,!(!A||Date.now()>A.until)){try{hr(A.target,0)}catch{}Ys.current=Date.now()}};return document.addEventListener("visibilitychange",T),()=>document.removeEventListener("visibilitychange",T)},[hr]);const xc=w.useRef(""),bc=w.useRef(null),Xn=w.useRef(0),_s=w.useCallback(()=>{Xn.current=Date.now()},[]),Ui=w.useRef(null),kc=w.useRef(0),Hi=w.useCallback(()=>{kc.current=Date.now()},[]),Wi=w.useCallback(T=>({hasSourceEvent:!!T,at:Date.now(),lastDeckFitAt:Ys.current,lastCanvasInputAt:kc.current}),[]),Nc="agent-dag.autoFitDisabled",Xs=w.useRef(!1),[Sc,Zs]=w.useState(!1);w.useEffect(()=>{try{window.localStorage.removeItem(Nc)}catch{}},[]);const Qs=w.useCallback(()=>{Xs.current||(Xs.current=!0,Zs(!0))},[]),Ea=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,X=Date.now(),te=[];for(const _e of A.agents.values())Z0(_e,X)&&te.push({id:_e.id});if(te.length===0)return;const ye=[];for(const{id:_e}of te){const Oe=Sr.current.get(_e),Ve=Gt.current.get(_e)??Kt.current.get(_e);!Oe||!Ve||ye.push({x:Ve.x,y:Ve.y,width:Oe.width,height:Oe.height})}MY({pane:Ui.current,viewport:e.getViewport(),boxes:ye})&&Yn(600)},1500);return()=>clearInterval(T)},[e]);const Ca=w.useRef(!1),Sr=w.useRef(new Map),Ta=w.useRef(0),Ra=w.useCallback(T=>{const A=Sr.current;let X=!1;for(const te of T.nodeInternals.values()){const ye=te.width,_e=te.height;if(ye==null||_e==null)continue;const Oe=A.get(te.id);Oe?(Math.abs(Oe.height-_e)>4||Math.abs(Oe.width-ye)>4)&&(A.set(te.id,{width:ye,height:_e}),X=!0):(A.set(te.id,{width:ye,height:_e}),X=!0)}return X&&(Ta.current+=1),Ta.current},[]),Vi=Tt(Ra),[jc,Gi]=w.useState(0);w.useEffect(()=>{let T=0;const A=()=>{const te=Sr.current;let ye=!1;for(const _e of document.querySelectorAll(".react-flow__node[data-id]")){const Oe=_e.getAttribute("data-id");if(!Oe)continue;const Ve=_e.offsetWidth,it=_e.offsetHeight;if(!Ve||!it)continue;const Ze=te.get(Oe);(!Ze||Math.abs(Ze.width-Ve)>4||Math.abs(Ze.height-it)>4)&&(te.set(Oe,{width:Ve,height:it}),ye=!0)}ye&&Gi(_e=>_e+1)};if(Ca.current)return;let X=0;return document.visibilityState==="hidden"?X=window.setTimeout(A,32):T=requestAnimationFrame(A),()=>{cancelAnimationFrame(T),window.clearTimeout(X)}});const Kt=w.useRef(pc.positions),_c=w.useRef(new Set),jo=w.useRef(""),jr=w.useMemo(()=>FK(l.current.agents.values(),c),[l.current,l.current.revision,c]),Js=w.useMemo(()=>{const T=[];for(const A of l.current.agents.values())!Z0(A,Jt)||jr.has(A.id)||T.push(A.id+(A.parentId?`>${A.parentId}`:""));return T.sort(),`${T.join("|")}#sv${Vi}.${jc}`},[l.current,l.current.revision,Jt,Vi,jc,jr]),Aa=w.useRef(null);w.useEffect(()=>(Aa.current!=null&&window.clearTimeout(Aa.current),Aa.current=window.setTimeout(()=>{Ah(Kt.current,Gt.current)},1500),()=>{Aa.current!=null&&window.clearTimeout(Aa.current)}),[Js]),w.useEffect(()=>{if(xc.current===Js)return;const T=xc.current;if(xc.current=Js,!T||Xs.current)return;Date.now()-Ys.current>1200&&Yn(400),zi.current&&window.clearTimeout(zi.current),zi.current=window.setTimeout(()=>{Xs.current||Yn(500)},280)},[Js,e,Yn]);const _r=w.useMemo(()=>XK(l.current,S),[l.current,l.current.revision,S]),_o=w.useMemo(()=>{const T=yY(l.current,Jt);for(const A of jr)T.delete(A);return T},[l.current,l.current.revision,Jt,jr]),Er=w.useRef(null),[Eo,yd]=w.useState({w:0,h:0});w.useEffect(()=>{const T=Er.current;if(!T||typeof ResizeObserver>"u")return;const A=new ResizeObserver(X=>{var ye;const te=(ye=X[0])==null?void 0:ye.contentRect;te&&(Ui.current={width:te.width,height:te.height},yd(_e=>Math.abs(_e.w-te.width)>40||Math.abs(_e.h-te.height)>40?{w:te.width,h:te.height}:_e))});return A.observe(T),Ui.current={width:T.clientWidth,height:T.clientHeight},yd({w:T.clientWidth,h:T.clientHeight}),()=>A.disconnect()},[]);const Co=w.useCallback(T=>{var X,te;const A=T.target;!(A!=null&&A.closest)||A.closest(bX)!==T.currentTarget||(T.preventDefault(),(te=(X=document.activeElement)==null?void 0:X.blur)==null||te.call(X))},[]),op=w.useRef(new Map),[To,wd]=w.useState(!1);w.useEffect(()=>{const T=window.setTimeout(()=>wd(!0),2500);return()=>window.clearTimeout(T)},[]);const[$t,Ro]=w.useState(!1),fr=w.useRef(null),[Qr,Ec]=w.useState(!1),[Ki,Ma]=w.useState(!1),[Yi,Ia]=w.useState(""),[Ao,vd]=w.useState("far"),xd=w.useRef(null),Cc=gh(Ki,140),Mo=w.useCallback(T=>{var te;const A=(te=xd.current)==null?void 0:te.getBoundingClientRect(),X=KK(T);return A&&X?GK(X,A):"far"},[]),[Xi,Tc]=w.useState("detail"),Jr=w.useRef(null),Io=w.useRef(null),Rc=w.useCallback(()=>{var te;const T=Ta.current;if(((te=Io.current)==null?void 0:te.version)===T)return Io.current.card;const A=[];for(const ye of l.current.agents.keys()){const _e=Sr.current.get(ye);_e&&A.push(_e)}const X=$Y(A);return Io.current={version:T,card:X},X},[]),ip=w.useCallback(()=>{fr.current&&(window.clearTimeout(fr.current),fr.current=null),Ro(!1)},[]),bd=w.useCallback(T=>{T.length!==0&&queueMicrotask(()=>{Ro(!0),fr.current&&window.clearTimeout(fr.current),fr.current=window.setTimeout(()=>Ro(!1),kX+80)})},[]);w.useEffect(()=>()=>{fr.current&&window.clearTimeout(fr.current)},[]);const Cn=_?l.current.agents.get(_):null,kd=y&&Cn!=null,[$o,Es]=w.useState(0);w.useEffect(()=>{const T=yR(Er.current);Es(A=>Math.abs(A-T)>40?T:A)},[Be,Pe,W,kd,Eo.w]);const Zi=w.useRef($o);Zi.current=$o;const es=Eo.w>0?Math.max(0,(Eo.w-$o-r0*2)*s0):0,Dn=Eo.h>0?Math.max(0,(Eo.h-r0*2)*s0):0,Oo=fF(),{nodes:mn,edges:Qi}=w.useMemo(()=>{const T=P9(l.current,Jt,es,Dn,Gt.current,Sr.current,op.current,bd,To,Qr,Kt.current,_c.current,Js,jo,S,_r,_o,$);return qK(T.nodes,T.edges,c)},[l.current,l.current.revision,Jt,es,Dn,To,Qr,Js,S,_r,_o,$,ep,Oo,c]),lp=w.useState(IX)[0],Nd=w.useRef(lp);w.useEffect(()=>{if(!To||Qr)return;const T={width:es,height:Dn};if(!(T.width>0&&T.height>0))return;const A=Nd.current;if(Nd.current=T,$X(T),!A||A.width===T.width&&A.height===T.height)return;const X={direction:"LR",pinned:Gt.current,measured:Sr.current,lanes:z0(l.current)};if(!w9(mn,Qi,X,A,T))return;const te=So.current&&Date.now()-So.current.at<1500?So.current.id:null,ye=te??Rs.current,_e=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);_c.current.clear(),jo.current="",m(),window.setTimeout(()=>{if(Ah(Kt.current,Gt.current),Xs.current){if(te){qi.current(te);return}const Oe=ye?Gt.current.get(ye)??Kt.current.get(ye):void 0;if(_e&&Oe&&(Oe.x!==_e.x||Oe.y!==_e.y)){const Ve=e.getViewport();No.current+=1,hr({x:Ve.x-(Oe.x-_e.x)*Ve.zoom,y:Ve.y-(Oe.y-_e.y)*Ve.zoom,zoom:Ve.zoom},0),Ys.current=Date.now()}return}Yn(500)},80)},[es,Dn,To,Qr,m,Yn,e,hr]);const Cs=w.useMemo(()=>{const T=new Map;for(const X of mn){const te=X.data;if(!(te!=null&&te.sessionId)||te.exitAt!=null)continue;const ye=X.width,_e=X.height;if(ye==null||_e==null)continue;const Oe=X.position.x,Ve=X.position.y,it=Oe+ye,Ze=Ve+_e,vt=T.get(te.sessionId);vt?(vt.minX=Math.min(vt.minX,Oe),vt.minY=Math.min(vt.minY,Ve),vt.maxX=Math.max(vt.maxX,it),vt.maxY=Math.max(vt.maxY,Ze)):T.set(te.sessionId,{minX:Oe,minY:Ve,maxX:it,maxY:Ze})}const A=[];for(const[X,te]of T){const ye=te.maxX-te.minX+Th*2,_e=te.maxY-te.minY+Th*2;A.push({id:`group:${X}`,type:j$,position:{x:te.minX-Th,y:te.minY-Th},data:{sessionId:X,w:ye,h:_e},width:ye,height:_e,style:{width:ye,height:_e},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return A},[mn]),Lo=w.useMemo(()=>{const T=[...Cs,...mn],A=wa.current;return!A||A.size===0?T:T.map(X=>{const te=A.get(X.id);return te?{...X,position:te}:X})},[Cs,mn,js]),ts=w.useMemo(()=>{const T=new Set;for(const A of l.current.agents.values())for(const X of A.tools)T.add(z$(X.name));return Object.keys(B$).filter(A=>T.has(A))},[l.current,l.current.revision]);w.useEffect(()=>{if(ts.length<=1){Ti(!1);return}let T=0;const A=()=>{const X=Ei.current;if(X&&!document.hidden){const te=X.getBoundingClientRect(),ye=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(Oe=>Oe.getBoundingClientRect()),_e=vY(te,ye,8);Ti(Oe=>Oe===_e?Oe:_e)}T=window.setTimeout(A,300)};return A(),()=>window.clearTimeout(T)},[ts.length]);const Ji=w.useCallback(T=>{gc(A=>{const X=new Set(A);return X.has(T)?X.delete(T):X.add(T),X})},[]),Po=j?K5(l.current.agents,j):null,ea=w.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=S0(),Gt.current.clear(),Sr.current.clear(),Kt.current.clear(),jo.current="",kR(),u(new Set),p(null);try{window.localStorage.removeItem(uk)}catch{}R(),m()},[m,R]),Cr=w.useCallback(T=>{const A=l.current.agents.get(T);A&&(u(X=>{const te=new Set(X);return te.add(T),sR(window.localStorage,te),te}),p({id:T,label:A.label}),Gt.current.delete(T),Kt.current.delete(T),R())},[R]),At=w.useCallback(()=>{_&&Cr(_)},[_,Cr]),Mt=f&&c.has(f.id)?f:null;w.useEffect(()=>{var T;f&&((T=Er.current)==null||T.focus())},[f]);const Zn=w.useCallback(T=>{const A=[...T];u(X=>{const te=BK(X,A);return te!==X&&sR(window.localStorage,te),te})},[]),an=w.useRef(V);an.current=V;const bn=w.useRef(ee);bn.current=ee;const ns=w.useRef(!1);ns.current=Po!=null||Kr||H!=null||Z||I!=null||ga||ee||ur!=null;const rs=w.useCallback(T=>{const A=z9(T,{confirmOpen:an.current,modalOpen:ns.current});A==="confirm"?ne(!0):A==="clear"&&(ne(!1),ea())},[ea]),gn=w.useCallback(()=>{Gt.current.clear(),Kt.current.clear(),jo.current="",kR(),m(),window.setTimeout(()=>Yn(500),80)},[m,e,Yn]),Do=w.useCallback(()=>Yn(500),[Yn]),Ts=w.useRef(mn);Ts.current=mn;const Fn=w.useCallback(T=>{var vt;const A=Er.current,X=l.current.agents.get(T);if(!A||!X)return;const te=z0(l.current),ye=(Et,kn)=>{const Jn=Sr.current.get(Et.id);if(!Jn)return null;const Oa=kn&&te.has(Et.id)?gd:0;return{x:Et.position.x,y:Et.position.y,width:Jn.width+Oa,height:Jn.height}},_e=Ts.current.find(Et=>Et.id===T),Oe=_e?ye(_e,!1):null;if(!Oe)return;const Ve=[];for(const Et of Ts.current){if(Et.type!=="agent"&&Et.type!=="recapNote"||((vt=Et.data)==null?void 0:vt.sessionId)!==X.sessionId)continue;const kn=ye(Et,Et.type==="agent");kn&&Ve.push(kn)}const it=A.getBoundingClientRect(),Ze=BY({pane:{width:it.width,height:it.height},insets:{top:56,left:72,bottom:32,right:Zi.current+32},context:zY(Ve)??Oe,anchor:Oe});Ka(),Qs(),So.current={id:T,at:Date.now()},No.current+=1,hr(Ze,a0),Ys.current=Date.now(),Zr.current=Ch({durationMs:a0,documentHidden:document.hidden})?{target:Ze,until:Date.now()+a0+60}:null},[hr,Qs]);qi.current=Fn;const el=w.useCallback(T=>{const A=Ts.current.find(X=>X.id===T&&X.type==="agent");return A?A.data:void 0},[]),Sd=w.useCallback(T=>{var A;return(A=l.current.agents.get(T))==null?void 0:A.label},[]),ss=w.useCallback(T=>{var te;const A=Ts.current.find(ye=>ye.id===T&&ye.type==="recapNote");if(!A)return;const X=A.data;return{recap:X.recap,hue:X.hue,sessionLabel:(te=l.current.agents.get(X.parentId))==null?void 0:te.label}},[]),tl=w.useCallback(()=>{var X;const T=(X=Er.current)==null?void 0:X.getBoundingClientRect(),A=document.documentElement;return T?{width:T.right-Zi.current,height:T.bottom}:{width:A.clientWidth,height:A.clientHeight}},[]),Rs=w.useRef(_);Rs.current=_;const Ac=w.useRef(At);Ac.current=At;const nl=w.useCallback(T=>{const A=Ts.current.filter(_e=>_e.type==="agent"),X=IK(A.map(_e=>({id:_e.id,x:_e.position.x,y:_e.position.y})),Rs.current,T),te=X?A.find(_e=>_e.id===X):void 0;if(!te)return;const ye=n0(document.activeElement);C(te.id,!1),window.setTimeout(()=>{try{Fn(te.id)}catch{}ye&&xX(te.id)},30)},[C,Fn]),Tr=w.useRef(null),Qn=w.useCallback(T=>{C(T,!1),window.setTimeout(()=>{try{Fn(T)}catch{}},60)},[C,Fn]),$a=w.useCallback(T=>{jr.has(T)&&Zn([T]),Qn(T)},[jr,Zn,Qn]),Fo=w.useRef(null);w.useEffect(()=>{let T=-1/0;const A=()=>{T=performance.now()},X=te=>{Fo.current=performance.now()-T<250?te.target:null};return window.addEventListener("pointerdown",A,!0),window.addEventListener("focusin",X,!0),()=>{window.removeEventListener("pointerdown",A,!0),window.removeEventListener("focusin",X,!0)}},[]),w.useEffect(()=>{const T=A=>{var Ve,it;const X=A.target,te={tagName:X==null?void 0:X.tagName,isContentEditable:X==null?void 0:X.isContentEditable,role:(Ve=X==null?void 0:X.getAttribute)==null?void 0:Ve.call(X,"role"),type:X==null?void 0:X.type,pointerFocused:X!=null&&X===Fo.current};if(A.key==="Escape"){const Ze=P6({overlayOpen:pu.depth()>0,typing:Sf(te)});Ze==="dismiss"?pu.dismissTop():Ze==="blur"?X==null||X.blur():(PK(te)&&(X==null||X.blur()),R());return}if(Nf(A))return;const ye=n0(X)?(it=X==null?void 0:X.getAttribute)==null?void 0:it.call(X,"data-id"):null,_e=ye&&Ts.current.some(Ze=>Ze.id===ye)?ye:null,Oe=OK(A,_e);if(Oe.kind==="activate"){A.preventDefault(),C(Oe.nodeId,Oe.additive);return}if(Oe.kind!=="node"&&!(Oe.nodeId==null&&V6(te,A.key))&&!G6({key:A.key,modalOpen:K6({appModal:ns.current,dialogDepth:pu.dialogDepth()}),sheetOpen:bn.current})){if(A.key===" "&&(A.preventDefault(),va()),(A.key==="c"||A.key==="C")&&rs("shortcut"),(A.key==="r"||A.key==="R")&&gn(),(A.key==="f"||A.key==="F")&&Do(),(A.key==="z"||A.key==="Z")&&Rs.current&&Fn(Rs.current),A.key==="Delete"&&Ac.current(),(A.key==="l"||A.key==="L")&&fo(),A.key==="d"||A.key==="D")if(Rs.current)v(Ze=>!Ze);else{const Ze=vm(l.current.agents.values());Ze.length>0?Qn(Ze[0].id):nl(1)}if((A.key==="h"||A.key==="H")&&kr(Ze=>!Ze),(A.key==="u"||A.key==="U")&&F(Ze=>!Ze),(A.key==="a"||A.key==="A")&&Si.current.claude&&Gr(),(A.key==="j"||A.key==="J")&&nl(1),(A.key==="k"||A.key==="K")&&nl(-1),A.key==="w"||A.key==="W"){const Ze=_6(vm(l.current.agents.values()),Tr.current);Ze&&(Tr.current=Ze.id,Qn(Ze.id))}(A.key==="t"||A.key==="T")&&ld(Ze=>Ze==="dark"?"light":"dark"),(A.key==="m"||A.key==="M")&&Si.current.claude&&be.current!==null&&se.current(A.shiftKey),(A.key==="s"||A.key==="S")&&le(Ze=>!Ze),(A.key==="b"||A.key==="B")&&Ws(Ze=>!Ze),(A.key==="v"||A.key==="V")&&Si.current.claude&&be.current!==null&&rn(Ze=>!Ze),A.key==="?"&&M(Ze=>!Ze)}};return window.addEventListener("keydown",T),()=>window.removeEventListener("keydown",T)},[rs,gn,Do,R,C,nl,Qn,Fn,va]);const qo=l.current.agents.size,_t=w.useMemo(()=>vm(l.current.agents.values()),[l.current,l.current.revision]);w.useEffect(()=>{const T=zK(_t,jr);T.length>0&&Zn(T)},[_t,jr,Zn]);const qn=w.useMemo(()=>E6(l.current.agents.values()),[l.current,l.current.revision]),As=w.useRef(null);w.useEffect(()=>{const T=cY({waiting:_t.length,running:qn,connected:Lt}),A=As.current;if(As.current=T,(A==null?void 0:A.title)!==T.title&&(document.title=T.title),(A==null?void 0:A.icon)!==T.icon){const X=document.querySelector('link[rel="icon"]');X&&(X.href=uY[T.icon])}},[_t.length,qn,Lt]);const[as,os]=w.useState(""),Ms=hY(_t);w.useEffect(()=>{os(T=>aR(T,Ms))},[Ms]);const[jd,rl]=w.useState(""),sl=dr>0?`Browser watch has ${dr} unread ${dr===1?"finding":"findings"}.`:"";w.useEffect(()=>{rl(T=>aR(T,sl,"Browser watch has no unread findings."))},[sl]);const[yn,Bn]=w.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[St,zn]=w.useState(null),[Bo,al]=w.useState(!1),[Mc,ol]=w.useState(!1);w.useEffect(()=>{let T=!0;return fetch("/api/prefs").then(A=>A.ok?A.json():null).then(A=>{var X,te,ye;if(!(!T||!(A!=null&&A.ok))){if(!ba.current){let _e=!1;try{_e=window.localStorage.getItem(Rh)==="0",window.localStorage.removeItem(Rh)}catch{}_e&&((X=A.prefs)==null?void 0:X.autoUpdate)!==!1?(xa(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):xa(((te=A.prefs)==null?void 0:te.autoUpdate)!==!1)}al(((ye=A.prefs)==null?void 0:ye.notifications)===!0),ol(A.notificationsVetoed===!0)}}).catch(()=>{}),()=>{T=!1}},[]);const Ic=w.useRef(()=>{}),il=w.useCallback(()=>{const T=!Bo;al(T),T&&typeof Notification<"u"&&Notification.permission==="default"&&Ic.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 X;A!=null&&A.ok&&(al(((X=A.prefs)==null?void 0:X.notifications)===!0),ol(A.notificationsVetoed===!0))}).catch(()=>{})},[Bo]),_d=typeof Notification<"u";w.useEffect(()=>{if(!St)return;const A=setTimeout(()=>zn(null),St==="blocked"?8e3:4e3);return()=>clearTimeout(A)},[St]);const ta=w.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(T=>{const A=T;Bn(A),A==="granted"?zn("on"):A==="denied"&&zn("blocked")})},[]);Ic.current=ta;const na=w.useRef(new Set),$c=w.useRef(null),zo=_t.map(T=>kf(T.id,T.waiting)).join("|");w.useEffect(()=>{A6($c.current,yn)&&($c.current=yn,na.current=xm(_t))},[yn]);const Uo=w.useRef(!1);return w.useEffect(()=>{M6(Uo.current,_a)&&(Uo.current=!0,na.current=xm(_t))},[_a]),w.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!I6($c.current,_a))return;const T=typeof document>"u"||!document.hidden,A=T6(_t,na.current,T,Bo);for(const X of A)try{const te=new Notification(X.title,{body:X.body,tag:X.key});te.onclick=()=>{window.focus(),Qn(X.sessionId),te.close()}}catch{}na.current=T?xm(_t):R6(_t,A,na.current)},[zo,_a]),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:dn}),Qt?(()=>{const T=CK(_K()??io,Qt.version);return o.jsxs("button",{type:"button",className:"v ready",onClick:pa,"aria-haspopup":"dialog","aria-label":T.label,title:T.title,children:[T.text,o.jsx("span",{className:"v-dot","aria-hidden":!0})]})})():ht?o.jsxs("button",{type:"button",className:"v stale",onClick:()=>{pa(),oc()},"aria-haspopup":"dialog","aria-label":tX({...ht,open:ma}),title:ht.kind==="restart"?`Running v${ht.from}; v${ht.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${ht.from}; v${ht.to} is on npm · click for what's new`,children:["v",ht.from,o.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const T={running:io,latest:xe==null?void 0:xe.latest,latestPending:xe==null?void 0:xe.latestPending,checkedAgo:xe!=null&&xe.checkedAt?Ph(Jt-xe.checkedAt):null,checkFailedAgo:xe!=null&&xe.checkFailedAt&&xe.checkFailedAt>(xe.checkedAt??0)?Ph(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:()=>{pa(),gt(!0)},"aria-busy":tt||void 0,"aria-haspopup":"dialog","aria-label":eX(T),title:JY(T),children:["v",T.running]})})()]}),o.jsxs("span",{className:"status",children:[(()=>{const T=mX({connected:Lt,paused:go,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:z,className:"month-usage",title:G?`${G.tokens.toLocaleString()} tokens · ${fR(G.cost)} spent since the 1st of this local calendar month`:U?"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"}),G?o.jsxs(o.Fragment,{children:[o.jsx("b",{children:Bt(G.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:fR(G.cost)})]}):o.jsx("span",{className:"month-usage-pending",children:U?"unavailable":"…"})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:as}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:jd}),_t.length>0&&o.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{Tr.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}: ${Vl(T.waiting)} (${Ph(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"})]}),St&&o.jsx("span",{className:St==="on"?"notify-said":"notify-said notify-said-blocked",role:"status",title:St==="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:St==="on"?"notifications on":"notifications blocked"})]}),Cn&&(()=>{const T=ir(Cn),A=Math.max(0,((Cn.endedAt??Jt)-Cn.startedAt)/1e3),X=Cn.state==="active"?Nb(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
|
${ut(T.total)} spent${X?` · ${X}`:""}`:""}`,onClick:()=>{try{Fn(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:[ut(T.total),X?o.jsxs("span",{className:"selected-rate",children:[" · ",X]}):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:fo,title:`${P?"Hide":"Show"} session list (L)`,"aria-label":"Toggle session list","aria-expanded":P,"aria-controls":P?"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:()=>F(T=>!T),title:`${W?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel","aria-expanded":W,"aria-controls":W?"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:Gr,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:`${ie?"Hide":"Show"} this machine — cores, memory, temperature (S)`,"aria-label":"Toggle machine detail","aria-expanded":ie,"aria-controls":ie?"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:uc?"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, ${uc?"watching":"not watching"}`+(dr>0?`, ${dr} 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"}),uc||dr>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"}),dr>0&&o.jsx("span",{className:"bw-badge","aria-hidden":!0,children:dr})]})]}),o.jsxs("div",{className:"action-run action-run-utility",children:[Kn.claude&&Te!==null&&o.jsxs("div",{className:"sound-slot",children:[o.jsxs("button",{ref:je,className:"btn icon-btn",onClick:()=>rn(T=>!T),...Qa(!1),title:cX(Kn,{on:Te===!0,locked:Vn==="locked",prefs:Le}),"aria-label":`Sound settings, ${Te?"on":"off"}`,"aria-haspopup":"dialog","aria-expanded":Dt,"aria-controls":Dt?"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"}),Te?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"})]}),Dt&&o.jsx(AV,{onClose:()=>rn(!1),soundOn:Te===!0,onToggleSound:de,prefs:Le,onLevel:(T,A)=>rt(T,{level:A}),onFigure:(T,A)=>rt(T,{figure:A}),onPreview:T=>We(T),customAssets:Ye,customSelections:Ae,onBuiltInSelected:ke,onCustomSelected:dt,onImportCustom:ct,onCreateVoice:yt,onRenameCustom:Ot,onPreviewCustom:Xt,onDeleteCustom:zt,notifyOn:Bo,onToggleNotify:il,notifyVetoed:Mc,notifyPermission:_d?yn:"unsupported",onAskNotify:ta,openerRef:je})]}),o.jsxs("div",{className:"appearance-slot",children:[o.jsx("button",{ref:_n,className:"btn icon-btn",onClick:()=>{rn(!1),bt(T=>!T)},title:"Appearance settings","aria-label":`Appearance settings, ${Sa} theme, character ${vo?"shown":"hidden"}`,"aria-haspopup":"dialog","aria-expanded":xt,"aria-controls":xt?"appearance-menu":void 0,children:Sa==="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"})})}),xt&&o.jsx(QV,{theme:Sa,onTheme:ld,characterEnabled:vo,onToggleCharacter:()=>cd(T=>!T),fmVolume:Li,onFmVolume:np,fmMuted:Pi,onFmMuted:()=>rp(T=>!T),fmSource:Gs,onFmSource:bo,customFmStations:xo,unavailableFmStations:Ks,onAddFmStation:ap,onRenameFmStation:pd,onRemoveFmStation:md,onClose:()=>bt(!1)})]})]})]})]}),o.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Mt?`${Mt.label} removed from the board.`:""}),hc?o.jsxs("div",{className:"ver-banner done",role:"status",children:[o.jsx("span",{className:"ver-dot"}),o.jsxs("strong",{children:["Restarted — now running v",hc,"."]}),o.jsx("span",{className:"ver-sub",children:"The canvas replayed from the event log."})]}):fd&&!Lt?o.jsxs("div",{className:"conn-banner",role:"alert",children:[o.jsx("span",{className:"conn-dot"}),Nr?yo==="npx"?"Fetching the new version with npx — this can take a minute…":`Restarting ${dn}…`:(()=>{const T=fX({connected:Lt,paused:go});return o.jsxs(o.Fragment,{children:[`Lost connection to the ${dn} server. Reconnecting…`,T&&o.jsx("span",{className:"conn-sub",children:T})]})})()]}):ma&&ht?o.jsxs("div",{className:`ver-banner ${ht.kind}`,role:"status",children:[o.jsx("span",{className:`ver-dot${id==null?"":" armed"}`}),ht.kind==="restart"?o.jsxs(o.Fragment,{children:[o.jsxs("strong",{children:["v",ht.to," is installed — this deck still runs v",ht.from,"."]}),xe!=null&&xe.canRestart?o.jsxs(o.Fragment,{children:[o.jsx("button",{type:"button",className:"ver-act",onClick:()=>wo(),...Qa(Nr),title:`Stop this process and bring it back on the same port. The canvas replays from the event log.
|