@software-dlc/cli 0.204.9 → 0.206.0

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.
@@ -430,4 +430,4 @@ It leaves the open tasks.`:"It leaves the open tasks.",action_label:"Mark done"}
430
430
  `}const ei="candidate";function _b(e){return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}const b6="Versioned records of this project's release branch, with notes from its graph changes.";function DE({description:e=b6,actions:t}){return i.jsx(_n,{title:"Releases",description:e,actions:t})}function EE(e){var r;if(!e)return"";const t=(r=e.previous_release)==null?void 0:r.version,n=Number(e.version.split("-rc.")[1]??0),s=e.commits_since??n,a=`${e.commits_since===null?"At least ":""}${s} commit${s===1?"":"s"}`;return t?`${a} since ${t}`:`${a} before the first Release`}function Lu({active:e,onClick:t,version:n,badges:s,caption:a,item_ref:r}){return i.jsxs("button",{ref:r,type:"button","aria-current":e?"true":void 0,onClick:t,className:we("focus-visible:ring-ring flex flex-col gap-0.5 rounded-md px-3 py-2 text-left outline-none focus-visible:ring-2",e?"bg-muted":"hover:bg-muted/60"),children:[i.jsxs("span",{className:"flex min-w-0 items-center gap-2 text-sm font-medium",children:[i.jsx("span",{className:"truncate",children:n}),s]}),i.jsx("span",{className:"text-muted-foreground text-xs",children:a})]})}function Ds({children:e}){return i.jsx("section",{className:"border-border flex flex-col gap-4 rounded-xl border p-4",children:e})}function es({title:e,error:t,onRetry:n}){const s=HD();return i.jsxs(me,{variant:"destructive",ref:s,children:[i.jsx(Nt,{}),e?i.jsx(je,{children:e}):null,i.jsxs(pe,{className:"flex flex-col items-start gap-2",children:[t,n?i.jsx(U,{variant:"outline",size:"sm",onClick:n,children:"Try again"}):null]})]})}function y6({title:e,text:t}){return i.jsx(Ds,{children:i.jsxs("div",{className:"flex flex-col items-center gap-2 py-10 text-center",children:[i.jsx(ff,{className:"text-muted-foreground size-8","aria-hidden":!0}),i.jsx("h2",{className:"text-lg font-semibold",tabIndex:-1,children:e}),i.jsx("p",{className:"text-muted-foreground max-w-md text-sm",children:t})]})})}function w6(e,t){const n=t??"The release branch";return{title:e?`Nothing new since ${e}`:"Nothing to release yet",text:e?`${n}'s head is the commit ${e} was written at. Commits to ${n} make the next candidate.`:`${n} has no commits yet.`}}function Mh({changes:e}){const t=u.useMemo(()=>Uc(e),[e]),[n,s]=u.useState(!1),a=t.unlisted_count+t.modeling_only_count;return i.jsxs("div",{className:"flex flex-col gap-4",children:[t.sections.map(r=>{const o=i.jsx("ul",{className:"flex flex-col gap-2",children:r.lines.map(l=>i.jsx(C_,{line:l},`${l.node_id}:${l.change}`))});return r.key==="breaking"?i.jsxs(me,{variant:"destructive",className:"border-destructive/40",children:[i.jsx(Nt,{}),i.jsx(je,{children:i.jsx("h3",{className:"text-destructive text-sm font-semibold",children:r.label})}),i.jsx(pe,{className:"text-foreground",children:o})]},r.key):i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx("h3",{className:"text-sm font-semibold",children:r.label}),o]},r.key)}),i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h3",{className:"text-sm font-semibold",children:"Fixed"}),i.jsx("p",{className:"text-muted-foreground text-xs",children:"Fixes that changed no part of the graph are not recorded yet; they arrive with landing notes."})]}),t.sections.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"No change affects the version."}):null,a>0?i.jsxs("p",{className:"text-muted-foreground text-sm",children:[a," more change",a===1?"":"s"," do",a===1?"es":""," not affect the version."]}):null,e.length>0?i.jsx(U,{variant:"link",size:"sm",className:"self-start px-0","aria-expanded":n,onClick:()=>s(r=>!r),children:n?"Hide all changes":"Show all changes"}):null,n?i.jsx("ul",{className:"flex flex-col gap-2",children:e.map(r=>i.jsx(C_,{line:r,detail:!0},`all:${r.node_id}:${r.change}:${r.modeling_only}`))}):null]})}function C_({line:e,detail:t=!1}){const n=t?e.modeling_only?"modeling only: shipped before, left out of the version":e.why??`${e.change}; does not affect the version`:e.why;return i.jsxs("li",{className:"flex flex-col gap-0.5",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium",children:[e.label,i.jsx(be,{variant:"outline",children:CE(e.node_type)})]}),n?i.jsx("span",{className:"text-muted-foreground text-xs",children:n}):null]})}const _6={ok:"success",alert:"error",you:"warning",neutral:"neutral"},j6={ok:"bg-success",alert:"bg-destructive",you:"bg-warning",neutral:"bg-muted-foreground"},N6={ok:"text-success",alert:"text-destructive",you:"text-warning",neutral:""},iu="None in this release",AE="Not computed yet",mr=({chip:e})=>i.jsx(be,{variant:_6[e.tone],children:e.label});function RE({parts:e,className:t}){return i.jsx("div",{"aria-hidden":!0,className:`bg-muted flex gap-0.5 overflow-hidden rounded-full ${t??"h-1.5 w-40"}`,children:e.map((n,s)=>i.jsx("span",{className:n.tone==="primary"?"bg-primary":j6[n.tone],style:e.length===1?{width:`${Math.round(n.share*100)}%`}:{flexGrow:n.share}},s))})}function Yf({title:e,count:t,children:n,heading_ref:s}){const a=`this-release-${e.toLowerCase().replace(/\s+/g,"-")}`;return i.jsxs("section",{className:"flex flex-col gap-2","aria-labelledby":a,children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("h2",{id:a,ref:s,tabIndex:-1,className:"text-lg font-semibold outline-none",children:e}),t!==void 0?i.jsx("span",{className:"text-muted-foreground text-xs",children:t}):null]}),n]})}const ha=({title:e,id:t})=>i.jsx("h3",{id:t,tabIndex:t?-1:void 0,className:"mt-2 text-sm font-semibold outline-none",children:e}),wo=({children:e})=>i.jsx("p",{className:"text-muted-foreground text-sm",children:e}),pr=({children:e})=>i.jsx("p",{className:"text-muted-foreground text-xs",children:e});function Xf({items:e,shown:t,what:n,children:s}){const[a,r]=u.useState(!1),o=t>0?t:e.length,l=e.length>o;return i.jsxs(i.Fragment,{children:[s(a||!l?e:e.slice(0,o)),l?i.jsx(U,{variant:"link",size:"sm",className:"self-start px-0","aria-expanded":a,"aria-label":a?`Show fewer ${n}`:`Show all ${e.length} ${n}`,onClick:()=>r(c=>!c),children:a?"Show fewer":`Show all ${e.length}`}):null]})}function D_({counted:e,what:t}){return i.jsx(Xf,{items:e.rows,shown:e.shown,what:t,children:n=>i.jsx("ul",{className:"flex flex-col gap-2",children:n.map((s,a)=>i.jsxs("li",{className:"flex flex-wrap items-center gap-3 text-sm",children:[i.jsx("code",{className:"w-48 truncate font-mono text-xs",title:s.name,children:s.name}),i.jsx("span",{className:"w-24 text-right tabular-nums",children:s.text}),i.jsx(RE,{parts:[{tone:"primary",share:s.share}]})]},`${s.name}:${a}`))})})}function k6({view:e,heading_ref:t}){const n=e.readiness;return i.jsxs(Yf,{title:"Readiness",heading_ref:t,children:[e.alert?i.jsxs(me,{variant:e.alert.tone==="alert"?"destructive":"default",role:e.alert.tone==="alert"?"alert":"status",children:[i.jsx(Nt,{}),i.jsx(je,{children:e.alert.title}),e.alert.text?i.jsx(pe,{children:e.alert.text}):null]}):null,n.computed?i.jsxs(i.Fragment,{children:[n.contract?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[n.accepted_note?i.jsx(mr,{chip:n.accepted_note}):null,i.jsx(S6,{line:n.contract,verdict:n.verdict.label})]}):i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[i.jsx(mr,{chip:n.verdict}),n.accepted_note?i.jsx(mr,{chip:n.accepted_note}):null,i.jsx("span",{children:n.detail})]}),n.gaps.map((s,a)=>i.jsx("p",{className:"text-sm",children:s},`${s}:${a}`)),n.errors.map((s,a)=>i.jsx("p",{className:"text-sm",children:s},`${s}:${a}`)),n.note?i.jsx(pr,{children:n.note}):null]}):i.jsx("p",{className:"text-sm",children:n.text})]})}function S6({line:e,verdict:t}){const n=`Environment verification says ${t}`;return e.startsWith(n)?i.jsxs("span",{children:["Environment verification says ",i.jsx("span",{className:"font-medium",children:t}),e.slice(n.length)]}):i.jsx("span",{children:e})}function C6({figures:e}){return e.length===0?null:i.jsx("dl",{className:"flex flex-wrap gap-6",children:e.map(t=>i.jsxs("div",{className:"flex min-w-28 flex-col-reverse",children:[i.jsx("dt",{className:"text-muted-foreground text-xs",children:t.label}),i.jsx("dd",{className:"text-2xl font-semibold tabular-nums",children:t.value})]},t.label))})}function D6(e){const t=e.action;return!t||!e.test?null:t.kind==="accept"?e.env?{name:e.name,key:e.test,decision:{kind:"accept",test:e.test,env:e.env}}:null:{name:e.name,key:e.test,decision:{kind:"revoke",acceptance:t.acceptance}}}function E6({view:e,version:t,onDecide:n}){const s=e.obligations,a=e.landings;return i.jsxs(Yf,{title:"Test completeness",children:[i.jsx(ha,{title:"Obligations"}),s?i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-sm",children:s.summary}),s.segments.length>0?i.jsxs(i.Fragment,{children:[i.jsx(RE,{className:"h-2 w-full max-w-xl",parts:s.segments.map(r=>({tone:r.tone,share:r.count}))}),i.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.segments.map(r=>i.jsx(mr,{chip:{label:r.label,tone:r.tone}},r.label))})]}):null,s.open.length>0?i.jsxs(i.Fragment,{children:[i.jsx(ha,{title:"Tests not yet satisfied",id:TE}),i.jsx(Xf,{items:s.open,shown:s.shown,what:"tests not yet satisfied",children:r=>i.jsx("ul",{className:"flex flex-col",children:r.map((o,l)=>{const c=n?D6(o):null;return i.jsxs("li",{className:"flex flex-col gap-0.5 border-b py-1.5",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[i.jsx(mr,{chip:o.chip}),i.jsx("span",{children:o.name}),o.kind?i.jsx("span",{className:"text-muted-foreground text-xs",children:o.kind}):null,c&&o.action&&n?i.jsx(U,{variant:"outline",size:"sm",className:"ml-auto","data-decision-row":c.key,"aria-label":`${o.action.label}: ${o.name}`,onClick:()=>n(c),children:o.action.label}):null]}),o.locator?i.jsx("code",{className:"font-mono text-xs",children:o.locator}):null,o.why?i.jsx(pr,{children:o.why}):null,o.accepted?i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Accepted by ",i.jsx("strong",{className:"text-foreground font-semibold",children:o.accepted.by})," for the next release",t?i.jsxs(i.Fragment,{children:[" ","(",i.jsx("code",{className:"font-mono",children:t}),")"]}):null,": ",o.accepted.reason]}):null]},`${o.test??o.name}:${l}`)})})})]}):null]}):i.jsx(pr,{children:AE}),i.jsx(ha,{title:"Landings"}),i.jsx("p",{className:`text-sm ${a.chips.length===0&&!a.headline?"text-muted-foreground":""}`,children:a.summary}),a.chips.length>0?i.jsx("div",{className:"flex flex-wrap gap-1.5",children:a.chips.map(r=>i.jsx(mr,{chip:r},r.label))}):null,a.headline?i.jsx("p",{className:`text-sm ${N6[a.headline.tone]}`,children:a.headline.text}):null,a.orphans?i.jsx(pr,{children:a.orphans}):null]})}function A6({view:e}){const t=e.impact;return i.jsxs(Yf,{title:"Impact",children:[i.jsx(ha,{title:"Files by area"}),t.areas.rows.length===0?i.jsx(wo,{children:iu}):i.jsx(D_,{counted:t.areas,what:"areas"}),i.jsx(ha,{title:"In the graph"}),t.graph?i.jsxs(i.Fragment,{children:[t.graph.features.length>0?i.jsx(Xf,{items:t.graph.features,shown:t.graph.shown,what:"features",children:n=>i.jsx("ul",{className:"list-disc pl-5 text-sm",children:n.map((s,a)=>i.jsx("li",{children:s},`${s}:${a}`))})}):null,i.jsx("p",{className:"text-sm",children:t.graph.counts}),t.graph.coverage?i.jsx(pr,{children:t.graph.coverage}):null]}):i.jsx(pr,{children:AE}),i.jsx(ha,{title:"Migrations"}),t.migrations?i.jsx(D_,{counted:t.migrations,what:"days"}):i.jsx(wo,{children:iu}),i.jsx(ha,{title:"Drop or truncate"}),t.drops.length===0?i.jsx(wo,{children:iu}):i.jsx("ul",{className:"flex flex-col gap-1",children:t.drops.map(n=>i.jsxs("li",{className:"flex items-center gap-1.5",children:[i.jsx(Nt,{className:"text-warning size-4 shrink-0","aria-hidden":!0}),i.jsx("code",{className:"font-mono text-xs break-all",children:n})]},n))}),i.jsx(ha,{title:"Feature flags added"}),t.flags.length===0?i.jsx(wo,{children:iu}):i.jsx("ul",{className:"flex flex-col gap-1",children:t.flags.map(n=>i.jsx("li",{children:i.jsx("code",{className:"font-mono text-xs",children:n})},n))})]})}function R6({view:e}){const t=e.threads.rows;return i.jsxs(Yf,{title:"Threads",count:t.length,children:[t.length===0?i.jsx(wo,{children:"None in this release"}):i.jsx(Xf,{items:t,shown:e.threads.shown,what:"threads",children:n=>i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Threads in this release",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{scope:"col",children:"Thread"}),i.jsx(J,{scope:"col",className:"text-right",children:"Landings"}),i.jsx(J,{scope:"col",children:"Staging evidence"}),i.jsx(J,{scope:"col",children:"Local checks"})]})}),i.jsx(at,{children:n.map(s=>i.jsxs(ye,{children:[i.jsx(X,{className:"max-w-md truncate",title:s.thread,children:s.thread}),i.jsx(X,{className:"text-right tabular-nums",children:s.landings}),i.jsx(X,{children:i.jsx(mr,{chip:s.staging})}),i.jsx(X,{children:s.local})]},s.thread))})]})})}),i.jsx(pr,{children:"Thread names come from their objectives; plans open in the VS Code Release tab."})]})}const E_=500;function T6(e){return e.trim()?[...e.trim()].length>E_?`A reason is at most ${E_} characters.`:null:"A reason is required."}const A_={accept:"Why it may ship failing, e.g. the issue that tracks it",revoke:"Why it may no longer ship failing"};function O6({target:e,version:t,decide:n,onDecided:s,onClose:a}){const[r,o]=u.useState(""),[l,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState(!1),p=u.useRef(null),y=u.useRef(!1),g=u.useRef(null);e&&(g.current=e),u.useEffect(()=>{e&&(o(""),c(null),h(null),m(!1),y.current=!1)},[e]);const b=e??g.current,v=(b==null?void 0:b.decision.kind)==="accept",x=(b==null?void 0:b.name)??"",w=()=>{f||a()},_=async k=>{var T,P;if(k.preventDefault(),!e||f)return;const j=T6(r);if(c(j),j){h(null),(T=p.current)==null||T.focus();return}h(null),m(!0);const N=await n({...e.decision,reason:r.trim()});if(N.ok){await s(!0),y.current=!0,m(!1),a();return}const O=N.refusal;O.status===400?c(O.message):O.status===503?h({variant:"info",title:"The local stores are busy",text:"Try again in a moment."}):O.status===504?(h({variant:"warning",title:"No answer in time",text:"It may have been recorded. The section is reading again; check the row before trying again."}),s(!1)):h({variant:"destructive",title:v?"Not accepted":"Not revoked",text:O.message}),m(!1),(P=p.current)==null||P.focus()},S=v?`“${x}” may ship failing in the next release${t?` (${t})`:""}. Recorded as yours and listed under Known issues.`:`“${x}” reads failed again and holds the release back.`;return i.jsx(jn,{open:e!==null,onOpenChange:k=>{k||w()},children:i.jsx(Nn,{onEscapeKeyDown:k=>{f&&k.preventDefault()},onInteractOutside:k=>{f&&k.preventDefault()},onCloseAutoFocus:k=>{var O;if(!g.current)return;k.preventDefault();const j=g.current.key;(O=[...document.querySelectorAll("[data-decision-row]")].find(T=>T.dataset.decisionRow===j)??document.getElementById(TE)??document.getElementById(M6)??document.getElementById(OE))==null||O.focus()},children:i.jsxs("form",{onSubmit:_,className:"grid gap-4",noValidate:!0,children:[i.jsxs(kn,{children:[i.jsx(Cn,{children:v?"Accept for release":"Revoke acceptance"}),i.jsx(Dn,{children:S})]}),d?i.jsxs(me,{variant:d.variant,children:[d.variant==="info"?i.jsx(pn,{"aria-hidden":!0}):i.jsx(Nt,{"aria-hidden":!0}),i.jsx(je,{children:d.title}),i.jsx(pe,{children:d.text})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"this-release-decision-reason",children:"Reason *"}),i.jsx(yt,{id:"this-release-decision-reason",ref:p,value:r,readOnly:f,placeholder:v?A_.accept:A_.revoke,"aria-invalid":l?!0:void 0,"aria-describedby":l?"this-release-decision-problem":void 0,onChange:k=>o(k.target.value)}),l?i.jsx("div",{id:"this-release-decision-problem",children:i.jsx(Qn,{children:l})}):null]}),i.jsxs(Sn,{children:[i.jsx(U,{type:"button",variant:"outline",size:"sm","aria-disabled":f||void 0,onClick:w,children:"Cancel"}),i.jsx(U,{type:"submit",size:"sm",loading:f,children:f?v?"Accepting…":"Revoking…":v?"Accept for release":"Revoke acceptance"})]})]})})})}function z6({read:e,version:t,onRetry:n,notAvailable:s,decide:a,onDecided:r}){const[o,l]=u.useState(null),c=i.jsx($6,{read:e,version:t,onRetry:n,notAvailable:s,onDecide:a&&r?l:void 0});return!a||!r?c:i.jsxs(i.Fragment,{children:[c,i.jsx(O6,{target:o,version:t,decide:a,onDecided:r,onClose:()=>l(null)})]})}const TE="this-release-tests-not-yet-satisfied",M6="this-release-readiness",OE="this-release-message";function $6({read:e,version:t,onRetry:n,notAvailable:s,onDecide:a}){const r=u.useRef(null),o=u.useRef(null),l=u.useRef(!1);if(u.useEffect(()=>{var h;!l.current||e.state==="reading"||(l.current=!1,(h=r.current??o.current)==null||h.focus())},[e]),e.state==="reading")return i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status",children:[i.jsx(wn,{"aria-hidden":!0})," Reading what this release ships…"]});const c=h=>i.jsx("div",{ref:o,id:OE,tabIndex:-1,className:"outline-none",children:h});if(e.state==="failed")return c(i.jsx(es,{title:"This release could not be read",error:e.error,onRetry:()=>{l.current=!0,n()}}));if(e.state==="unread")return c(i.jsx(es,{title:"This release could not be read",error:`What this release ships could not be read: ${e.text}.`,onRetry:e.retry?()=>{l.current=!0,n()}:void 0}));if(e.state==="outdated")return c(s);if(e.state==="unassembled")return c(i.jsxs(me,{variant:"destructive",children:[i.jsx(Nt,{}),i.jsx(je,{children:"This release could not be worked out"}),i.jsx(pe,{children:"The local records did not assemble into a release view."})]}));const d=e.view;return d.state==="empty"?c(i.jsx(wo,{children:d.empty})):d.state!=="ready"?null:i.jsxs(i.Fragment,{children:[i.jsx(k6,{view:d,heading_ref:r}),i.jsx(C6,{figures:d.figures}),i.jsx(E6,{view:d,version:t,onDecide:a}),i.jsx(A6,{view:d}),i.jsx(R6,{view:d})]})}const zE="Releases of this checkout: the roadmap of open Planned Releases, the next candidate, and each production release with its notes.",Kf=u.createContext(0);function Bc(e,t){const n=u.useRef(e),s=u.useRef(t);u.useEffect(()=>{s.current=t}),u.useEffect(()=>{n.current!==e&&(n.current=e,s.current())},[e])}const R_=e=>(e==null?void 0:e.status)===404||(e==null?void 0:e.reason)==="not_found",T_=5,nx="Not available",sx="planned:";function jb(){const e=is();return i.jsx("p",{className:"text-muted-foreground text-sm",children:`${nx}. ${e}`})}const Ws=e=>`${sx}${e}`,L6=e=>e!=null&&e.startsWith(sx)?e.slice(sx.length):null,Nb=e=>e?e.slice(0,7):"";function P6(e){return e?{title:`Nothing new since ${e}`,text:"Production runs what staging runs. Landings promoted to staging make the next candidate."}:{title:"Nothing to release yet",text:"Staging has run nothing production lacks."}}function I6(){return i.jsxs(me,{variant:"info",children:[i.jsx(pn,{}),i.jsx(je,{children:"Releases come from production"}),i.jsx(pe,{className:"text-info",children:"A Release is written when production runs a release candidate, once its commit is merged into origin/main."})]})}function G6(e){if(e.state==="unreadable")return{badges:i.jsx(be,{variant:"error",children:"Could not be read"}),caption:""};if(e.state==="withdrawn")return{badges:i.jsx(be,{variant:"warning",children:"Withdrawn"}),caption:e.replaced_by?`Replaced by ${e.replaced_by}`:"Withdrawn"};const t=i.jsxs(i.Fragment,{children:[i.jsx(be,{variant:"neutral",children:e.app_changed===!1?"App unchanged":e.previous_release_id?e.bump??"patch":"First"}),e.breaking?i.jsx(be,{variant:"error",children:"Breaking"}):null]}),n=e.written_at?_b(e.written_at):"",s=e.tracks&&e.tracks.length>0?` · ${e.tracks.join(", ")}`:"";return{badges:t,caption:`${n}${s}`}}function gr({query:e,select:t,onSelect:n,children:s,inline:a=!1}){return i.jsx("a",{href:`?${e}`,className:a?"text-primary underline":"text-primary hover:underline",onClick:r=>{r.preventDefault(),n(t)},children:s})}function Zf({pairs:e}){const t=e.filter(([,n])=>n!=null&&n!=="");return t.length===0?null:i.jsx("dl",{className:"grid grid-cols-[max-content_1fr] gap-x-6 gap-y-1 text-sm",children:t.map(([n,s])=>i.jsxs(u.Fragment,{children:[i.jsx("dt",{className:"text-muted-foreground",children:n}),i.jsx("dd",{className:"min-w-0",children:s})]},n))})}const fi=({children:e})=>i.jsx("code",{className:"font-mono text-xs",children:e});function ME(e,t){if(e.judged_commit&&t&&e.judged_commit!==t)return`Judged ${Nb(e.judged_commit)}, not this commit`;const n=e.verdict==="ready"?"Ready":e.verdict==="untested"?"Nothing tested yet":"Not ready",s=e.accepted>0?` · ${e.accepted} failed, accepted`:"";return`${n} · ${e.satisfied} of ${e.total} satisfied${s}`}function Qf({title:e,count:t,heading_ref:n}){return i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("h2",{ref:n,tabIndex:-1,className:"text-lg font-semibold outline-none",children:e}),t!==void 0?i.jsx("span",{className:"text-muted-foreground text-xs",children:t}):null]})}const H6={ready:"success",verifying:"info",fixing:"warning",abandoned:"warning",ready_older:"neutral",none:"neutral",unknown:"neutral"};function V6({batch:e}){if(e.state==="loading")return i.jsxs(me,{children:[i.jsx(Tc,{}),i.jsxs(pe,{className:"flex flex-row items-center gap-2",role:"status",children:[i.jsx(wn,{"aria-hidden":!0})," Reading the release batch…"]})]});const t=e.state==="ready"?e.value:{state:"unknown",chip:"Batch unknown",text:`The release batch could not be read: ${e.error}`,help:null};return i.jsxs(me,{children:[i.jsx(Tc,{}),i.jsxs(je,{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{children:t.text}),i.jsx(be,{variant:H6[t.state],children:t.chip})]}),t.help?i.jsx(pe,{children:t.help}):null]})}const O_="The release batch could not be read. The sdlc viewer log says why.",U6="What this release ships could not be read: git could not compare staging with production.",au=e=>{var t;return e.read_failed===!0||((t=e.this_release)==null?void 0:t.state)==="loading"};function B6(e,t,n){return`/org/${e}/issues/${encodeURIComponent(t)}?from=${encodeURIComponent(n)}`}function $E({issues:e,error:t}){return t?i.jsx(es,{title:"Known issues could not be read",error:t}):!e||e.length===0?null:i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx(Qf,{title:"Known issues",count:e.length}),i.jsx("ul",{className:"flex flex-col gap-2",children:e.map(n=>i.jsxs("li",{className:"flex flex-col gap-0.5 text-sm",children:[i.jsxs("span",{children:[n.id,": ",n.title]}),n.accepted_by?i.jsxs("span",{className:"text-muted-foreground text-xs",children:["accepted by ",n.accepted_by]}):null,n.file?i.jsx(fi,{children:n.file}):null]},n.key))})]})}function LE({tracks:e,error:t}){return t?i.jsx(es,{title:"Tracks could not be read",error:t}):!e||e.length===0||e.length===1&&e[0].key==="app"?null:i.jsxs("section",{className:"flex flex-col gap-3",children:[i.jsx(Qf,{title:"Tracks",count:e.length}),e.map(n=>n.key==="app"||n.released_by==="release_batch"?i.jsxs("div",{className:"flex flex-col gap-0.5",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium",children:[n.label,n.version?i.jsx(fi,{children:n.version}):null,n.bump?i.jsx(be,{variant:"neutral",children:n.bump}):null]}),i.jsx("span",{className:"text-muted-foreground text-xs",children:"Released with the release batch"})]},n.key):i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-sm font-medium",children:[n.label,i.jsxs("span",{className:"text-muted-foreground text-xs",children:[n.packages.length," package",n.packages.length===1?"":"s"]})]}),i.jsx("ul",{className:"flex flex-col gap-1",children:n.packages.map(s=>i.jsxs("li",{className:"flex flex-col gap-0.5",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(fi,{children:s.name}),i.jsxs(fi,{children:[s.from??"—"," → ",s.to??"—"]})]}),s.changes.map((a,r)=>i.jsxs("span",{className:"text-muted-foreground text-xs",children:[a.feature,": ",a.entry]},r))]},s.name))}),n.published&&!n.published.recorded?i.jsxs("span",{className:"text-muted-foreground text-xs",children:[n.released_by??"Publish",": Not available. This Release does not say whether or when it moved latest."]}):null]},n.key))]})}function PE({delivery:e,candidate:t,onSelect:n}){if(!e||e.planned.length===0&&e.outside===0)return null;const s=a=>a.length===0?"—":a.map(r=>r.went?`${r.label} (${r.went})`:r.label).join(", ");return i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx(Qf,{title:"Planned Releases",count:e.planned.length}),i.jsx("p",{className:"text-muted-foreground text-xs",children:t?"What this candidate would deliver":"What this Release delivered"}),e.planned.length>0?i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Planned Releases",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Planned Release"}),i.jsx(J,{children:"Delivered"}),i.jsx(J,{children:"Not delivered"})]})}),i.jsx(at,{children:e.planned.map(a=>i.jsxs(ye,{children:[i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[a.open&&t?i.jsx(gr,{query:`planned=${encodeURIComponent(a.id)}`,select:Ws(a.id),onSelect:n,children:a.name}):i.jsx("span",{children:a.name}),i.jsx(fi,{children:a.id})]})}),i.jsx(X,{children:s(a.delivered)}),i.jsx(X,{children:s(a.not_delivered)})]},a.id))})]})}):null,e.outside>0?i.jsxs("p",{className:"text-muted-foreground text-xs",children:[e.outside," landing",e.outside===1?"":"s"," served no Planned Release."]}):null]})}const W6={thread:"Thread",task:"Task",issue:"Issue",test:"Test"};function IE({rows:e,org:t,from:n,untasked:s}){const{href:a,Link:r}=lt(),[o,l]=u.useState(!1),c=o?e:e.slice(0,T_),d=h=>h.kind==="task"?i.jsx(r,{className:"text-primary font-mono text-xs hover:underline",href:a(`/org/${t}/tasks/${encodeURIComponent(h.id)}?from=${encodeURIComponent(n)}`),children:h.id}):h.kind==="issue"?i.jsx(r,{className:"text-primary font-mono text-xs hover:underline",href:a(B6(t,h.id,n)),children:h.id}):h.kind==="thread"?i.jsx(r,{className:"text-primary hover:underline",href:a(`${t?`/org/${t}`:""}/threads#thread-${encodeURIComponent(h.id)}`),children:h.label}):h.kind==="test"&&h.url?i.jsx("a",{className:"text-primary hover:underline",href:h.url,target:"_blank",rel:"noreferrer",children:h.label}):i.jsx("span",{children:h.label});return i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Related",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Kind"}),i.jsx(J,{children:"Item"}),i.jsx(J,{children:"How it relates"})]})}),i.jsx(at,{children:c.map(h=>i.jsxs(ye,{children:[i.jsx(X,{children:W6[h.kind]}),i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[d(h),h.state&&h.kind!=="thread"?i.jsx("span",{className:"text-muted-foreground text-xs",children:h.state}):null]})}),i.jsx(X,{children:h.relation})]},`${h.kind}:${h.id}`))})]})}),e.length>T_?i.jsx(U,{variant:"link",size:"sm",className:"self-start px-0","aria-expanded":o,onClick:()=>l(h=>!h),children:o?"Show fewer":`Show all ${e.length}`}):null,s?i.jsxs("p",{className:"text-muted-foreground text-xs",children:[s," landing",s===1?"":"s"," not tied to a task"]}):null]})}const GE=e=>(e==null?void 0:e.status)===409&&e.reason==="view_outdated";function HE(e){const t=kb(),[n,s]=u.useState(t!=null&&t.related?{state:"loading"}:null),a=u.useRef(0),r=Os(),o=u.useCallback(async(l=!1,c=!1)=>{if(!(t!=null&&t.related)||c&&r.busy())return;const d=++a.current;c||s({state:"loading"});const h=await r.track(t.related(e,l?{fresh:!0}:void 0));d===a.current&&s(f=>h.ok?{state:"ready",value:h.data}:c&&(f==null?void 0:f.state)==="ready"?f:{state:"error",error:h.refusal.message,refusal:h.refusal})},[t,e,r]);return u.useEffect(()=>{o()},[o]),Bc(u.useContext(Kf),()=>void o(!1,!0)),{related:n,read:o}}function VE({related:e,org:t,from:n,onRetry:s}){const a=u.useRef(null),r=u.useRef(!1);if(u.useEffect(()=>{var l;r.current&&(e==null?void 0:e.state)!=="loading"&&(r.current=!1,(l=a.current)==null||l.focus())},[e]),!e)return null;const o=e.state==="ready"?e.value.rows.length:void 0;return i.jsxs("section",{className:"flex flex-col gap-2","aria-labelledby":"release-related",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("h2",{id:"release-related",ref:a,tabIndex:-1,className:"text-lg font-semibold outline-none",children:"Related"}),o!==void 0?i.jsx("span",{className:"text-muted-foreground text-xs",children:o}):null]}),e.state==="loading"?i.jsxs("div",{className:"grid gap-2",role:"status","aria-label":"Loading related work",children:[i.jsx(Tt,{className:"h-8 w-full"}),i.jsx(Tt,{className:"h-8 w-full"}),i.jsx(Tt,{className:"h-8 w-2/3"})]}):e.state==="error"?GE(e.refusal)?i.jsx(jb,{}):i.jsx(es,{title:"Related work could not be read",error:e.error,onRetry:()=>{r.current=!0,s()}}):e.value.rows.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing related yet."}):i.jsx(IE,{rows:e.value.rows,org:t,from:n,untasked:e.value.untasked})]})}function F6(e){if(!e||e.of===0)return null;if(e.tasks===0)return i.jsx("span",{className:"text-muted-foreground",children:"none"});const t=Object.entries(e.outcomes);return i.jsxs("span",{children:[e.tasks," of ",e.of," tasks",t.map(([n,s])=>i.jsxs("span",{className:n==="failed"?"text-destructive":void 0,children:[" · ",s," ",n]},n))]})}function UE({planned:e,onSelect:t}){return e?e.open?i.jsx(gr,{query:`planned=${encodeURIComponent(e.id)}`,select:Ws(e.id),onSelect:t,children:e.name}):i.jsxs("span",{children:[e.name," ",i.jsx(fi,{children:e.id})]}):null}function q6({candidate:e,org:t,onSelect:n,notes:s,onChanged:a}){var w;const r=kb(),{related:o,read:l}=HE("candidate"),[c,d]=u.useState(r!=null&&r.candidateBatch?{state:"loading"}:null),h=u.useRef(0),f=Os(),[m,p]=u.useState(!1),y=u.useCallback(async(_,S=!1,k=null)=>{if(!(r!=null&&r.candidateBatch)||_&&!k&&f.busy())return;const j=++h.current;_||d({state:"loading"});const N=await f.track(r.candidateBatch(S?{fresh:!0}:void 0));if(j===h.current){if(k==="recorded"&&(!N.ok||au(N.data))){p(!0),d({state:"error",error:N.ok?O_:N.refusal.message});return}N.ok&&!au(N.data)&&p(!1),N.ok?au(N.data)?d(O=>_&&(O==null?void 0:O.state)==="ready"&&!au(O.value)?O:{state:"ready",value:N.data}):d({state:"ready",value:N.data}):d(O=>_&&(O==null?void 0:O.state)==="ready"?O:{state:"error",error:N.refusal.message})}},[r,f]),g=c===null||c.state!=="ready"?c:c.value.batch===null?null:{state:"ready",value:c.value.batch},b=c===null?null:c.state==="loading"?{state:"reading"}:c.state==="error"?{state:"failed",error:m?`The decision was recorded, but the section could not read it again (${c.error})`:c.error}:c.value.read_failed?{state:"failed",error:O_}:!("this_release"in c.value)||c.value.this_release===void 0?{state:"outdated"}:c.value.this_release===null?c.value.unread?{state:"unread",text:c.value.unread.text,retry:c.value.unread.retry}:{state:"unassembled"}:c.value.this_release.state==="loading"?{state:"failed",error:U6}:{state:"answered",view:c.value.this_release};u.useEffect(()=>(y(!1),()=>{h.current+=1}),[y]),Bc(u.useContext(Kf),()=>void y(!0));const v=e.readiness??((o==null?void 0:o.state)==="ready"?o.value.readiness:null)??null,x=(b==null?void 0:b.state)==="answered"&&b.view.state==="ready";return i.jsxs(i.Fragment,{children:[i.jsx(Zf,{pairs:[["Environment",e.environment??"staging"],["Commit",i.jsx(fi,{children:Nb(e.head_commit_id)},"commit")],["Notes",((w=e.notes)==null?void 0:w.page)??null],["Readiness",v&&!x?ME(v,e.head_commit_id):null],["Planned",e.planned_release?i.jsx(UE,{planned:e.planned_release,onSelect:n}):null]]}),g?i.jsx(V6,{batch:g}):null,b?i.jsx(z6,{read:b,version:e.version,onRetry:()=>y(!1,!0),notAvailable:i.jsx(jb,{}),decide:r==null?void 0:r.decideAcceptance,onDecided:async _=>{a==null||a(),await y(!0,!0,_?"recorded":"unknown")}}):null,s,i.jsx($E,{issues:e.known_issues,error:e.known_issues_error}),i.jsx(LE,{tracks:e.tracks,error:e.tracks_error}),i.jsx(PE,{delivery:e.planned_delivery,candidate:!0,onSelect:n}),i.jsx(VE,{related:o,org:t,from:"release:candidate",onRetry:()=>l(!0)})]})}function Y6({release:e,onSelect:t}){const n=e.label??e.version,s=!e.previous_release_id;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:n}),e.state==="withdrawn"?i.jsx(be,{variant:"warning",children:"Withdrawn"}):i.jsx(be,{variant:"neutral",children:e.app_changed===!1?"App unchanged":s?"First":e.bump}),e.breaking?i.jsx(be,{variant:"error",children:"Breaking"}):null]}),e.state==="withdrawn"&&e.replaced_by?i.jsxs("p",{className:"text-sm",children:["Replaced by"," ",i.jsx(gr,{query:`release=${encodeURIComponent(e.replaced_by)}`,select:e.replaced_by,onSelect:t,inline:!0,children:e.replaced_by})]}):null]})}function X6({release:e,org:t,onSelect:n,notes:s}){const a=e.label??e.version,{related:r,read:o}=HE(a),l=(r==null?void 0:r.state)==="ready"?F6(r.value.previews):null;return i.jsxs(i.Fragment,{children:[i.jsx(Zf,{pairs:[["Environment",e.environment??"production"],["Commit",e.commit?i.jsx(fi,{children:Nb(e.commit)},"commit"):null],["Readiness",e.readiness?`${ME(e.readiness)} on staging`:null],["Previews",l],["Planned",e.planned_release?i.jsx(UE,{planned:e.planned_release,onSelect:n}):null]]}),s,i.jsx($E,{issues:e.known_issues,error:e.known_issues_error}),i.jsx(LE,{tracks:e.tracks,error:e.tracks_error}),i.jsx(PE,{delivery:e.planned_delivery,candidate:!1,onSelect:n}),i.jsx(VE,{related:r,org:t,from:`release:${a}`,onRetry:()=>o(!0)})]})}function K6({id:e,summary:t,org:n,onNotFound:s,forecast:a}){const r=kb(),[o,l]=u.useState({state:"loading"}),c=u.useRef(0),d=Os(),h=u.useCallback(async(y=!1,g=!1)=>{if(g&&d.busy())return;const b=++c.current;if(!(r!=null&&r.plannedRelease)){l({state:"error",error:nx,refusal:{status:409,message:nx,reason:"view_outdated"}});return}g||l({state:"loading"});const v=await d.track(r.plannedRelease(e,y?{fresh:!0}:void 0));b===c.current&&l(x=>v.ok?{state:"ready",value:v.data}:g&&x.state==="ready"&&!R_(v.refusal)?x:{state:"error",error:v.refusal.message,refusal:v.refusal})},[r,e,d]);u.useEffect(()=>{h()},[h]),Bc(u.useContext(Kf),()=>void h(!1,!0));const f=o.state==="error"&&R_(o.refusal);if(u.useEffect(()=>{f&&s()},[f,s]),o.state==="loading")return i.jsxs(Ds,{children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:(t==null?void 0:t.name)??e}),i.jsx(be,{variant:"neutral",children:"Planned"})]}),i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:"Loading the Planned Release…"})]});if(o.state==="error")return i.jsxs(Ds,{children:[i.jsx("h2",{className:"text-lg font-semibold",children:(t==null?void 0:t.name)??e}),GE(o.refusal)?i.jsx(jb,{}):f?null:i.jsx(es,{error:o.error,onRetry:()=>void h(!0)})]});const m=o.value,p=m.order===null?null:m.order===1?`Next of ${m.open} open`:`${m.order} of ${m.open} open`;return i.jsxs(Ds,{children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:m.name}),i.jsx(be,{variant:"neutral",children:"Planned"})]}),m.goal?i.jsx("p",{className:"text-muted-foreground text-sm",children:m.goal}):null]}),i.jsx(Zf,{pairs:[["Planned Release",i.jsx(fi,{children:m.id},"id")],["Date",m.date],["Order",p],["Members",String(m.members.length)]]}),a,i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:"A Planned Release changes through release_plan.py:"}),i.jsxs("pre",{className:"bg-muted rounded-md px-3 py-2 font-mono text-xs",children:["sdlc view --planned ",m.id]})]}),i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx(Qf,{title:"Members",count:m.members.length}),m.members.length>0?i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Members",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Member"}),i.jsx(J,{children:"Level"}),i.jsx(J,{children:"Tasks"}),i.jsx(J,{children:"State"})]})}),i.jsx(at,{children:m.members.map(y=>{const g=y.tasks.filter(v=>v.state==="done").length,b=y.tasks.filter(v=>v.state!=="done").map(v=>v.id);return i.jsxs(ye,{children:[i.jsx(X,{children:y.label}),i.jsx(X,{children:y.level?i.jsx(be,{variant:"neutral",children:Z6(y.level)}):null}),i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[y.tasks.length>0?i.jsxs("span",{children:[g," of ",y.tasks.length," done"]}):null,b.length>0?i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Open: ",i.jsx(fi,{children:b.join(", ")})]}):null,y.untracked>0?i.jsxs("span",{className:"text-muted-foreground text-xs",children:[y.untracked," slice",y.untracked===1?" has":"s have"," no task yet"]}):null]})}),i.jsx(X,{children:y.state})]},y.item)})})]})}):null]}),i.jsxs("section",{className:"flex flex-col gap-2","aria-labelledby":"planned-related",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("h2",{id:"planned-related",className:"text-lg font-semibold",children:"Related"}),i.jsx("span",{className:"text-muted-foreground text-xs",children:m.related.length})]}),m.related.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing related yet."}):i.jsx(IE,{rows:m.related,org:n,from:`planned:${m.id}`})]})]})}const Z6=e=>e.charAt(0).toUpperCase()+e.slice(1);function kb(){return Wn().releases}const Pu=5,Sb=300,ru="candidate-notes-heading",Js="candidate-note-field",Pn={hint:"One line. Enter saves, Escape cancels.",empty:"Type the note line, or use Clear edit to go back to the generated text.",same:"The line is unchanged: change it, or Cancel.",long:`A note line is one line of at most ${Sb} characters.`,saved:"The edit was saved.",cleared:"The edit was cleared.",nothing:"There was no edit to clear.",busy:{title:"The local stores are busy",text:"Try again in a moment."},left:"The line is no longer in the candidate",blocked:"The line can no longer be edited here",changed:"The edit changed since Clear edit was opened",clear_gone:"The edit is no longer there",unclearable:"The edit can no longer be cleared here",refresh:"They are read again each time the view refreshes."},BE=e=>[...e].length;function Q6(e,t){var s;const n=e.trim();return n?/[\r\n\0]/.test(n)||BE(n)>Sb?Pn.long:n===(((s=t.edit)==null?void 0:s.value)??"").trim()?Pn.same:null:Pn.empty}function z_(e,t,n){return e===503?{variant:"info",...Pn.busy}:e===504?{variant:"warning",title:"No answer in time",text:`It may still have been ${n?"cleared":"saved"}: check the line.`,late:!0}:{variant:"destructive",title:n?"The edit was not cleared":"The edit was not saved",text:t}}function WE({notice:e,id:t}){return i.jsxs(me,{variant:e.variant,id:t,children:[e.variant==="info"?i.jsx(pn,{"aria-hidden":!0}):e.late?i.jsx(TS,{"aria-hidden":!0}):i.jsx(Nt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:e.title}),i.jsx(pe,{children:e.text})]})}function J6({gone:e,onDismiss:t,alert_ref:n}){return i.jsx("div",{ref:n,tabIndex:-1,className:"outline-none",children:i.jsxs(me,{variant:"warning",children:[i.jsx(Nt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:e.title}),i.jsxs(pe,{className:"flex flex-col items-start gap-2",children:[i.jsx("span",{children:e.text}),i.jsx(U,{variant:"outline",size:"sm",onClick:t,children:"Dismiss"})]})]})})}function eU({line:e,draft:t,saving:n,problem:s,notice:a,onDraft:r,onSave:o,onCancel:l,field_ref:c}){const d=e.edit,h=[a?`${Js}-notice`:null,s?`${Js}-problem`:null,`${Js}-hint`,`${Js}-count`].filter(Boolean).join(" ");return i.jsxs("form",{className:"flex flex-col gap-2 py-2",noValidate:!0,onSubmit:f=>{f.preventDefault(),n||o()},children:[a?i.jsx(WE,{notice:a,id:`${Js}-notice`}):null,i.jsx(Ie,{htmlFor:Js,children:"Note line"}),i.jsx(yt,{id:Js,ref:c,value:t,readOnly:n,placeholder:(d==null?void 0:d.placeholder)??void 0,"aria-invalid":s?!0:void 0,"aria-describedby":h,onChange:f=>r(f.target.value),onKeyDown:f=>{f.key==="Escape"&&!n&&(f.preventDefault(),l())}}),s?i.jsx("div",{id:`${Js}-problem`,children:i.jsx(Qn,{children:s})}):null,i.jsxs("p",{className:"text-muted-foreground flex flex-wrap gap-x-3 text-xs",children:[i.jsx("span",{id:`${Js}-hint`,children:Pn.hint}),i.jsx("span",{id:`${Js}-count`,children:`${BE(t)} of ${Sb}`})]}),d!=null&&d.generated?i.jsxs("p",{className:"text-muted-foreground text-xs",children:["generated: ",d.generated]}):null,i.jsxs("div",{className:"flex gap-2",children:[i.jsx(U,{type:"submit",size:"sm",loading:n,children:n?"Saving…":"Save"}),i.jsx(U,{type:"button",variant:"outline",size:"sm","aria-disabled":n||void 0,onClick:()=>!n&&l(),children:"Cancel"})]})]})}function M_({count:e,shown:t,onShow:n}){return t||e<=Pu?null:i.jsxs(U,{variant:"link",size:"inline-sm",className:"self-start",onClick:n,children:["Show all ",e]})}function tU({notes:e,edit:t,reread:n,onBusy:s}){const[a,r]=u.useState(null),[o,l]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(!1),[m,p]=u.useState(null),[y,g]=u.useState(!1),[b,v]=u.useState(null),[x,w]=u.useState(null),[_,S]=u.useState(null),[k,j]=u.useState(""),[N,O]=u.useState(new Set),T=u.useRef(null),P=u.useRef(null),L=u.useRef(null),G=u.useRef(null),A=u.useRef(!1),D=u.useRef(null),C=u.useRef(null),R=u.useRef(null),E=u.useRef(null),M=h||y,H=!!t&&!e.alert,z=u.useMemo(()=>new Map(e.sections.flatMap($=>$.lines.map(F=>[F.key,F]))),[e]),K=u.useMemo(()=>{var F;const $=new Map;for(const ee of e.sections)for(const se of ee.lines)(F=se.edit)!=null&&F.clear&&$.set(se.key,se.text);for(const ee of e.unapplied)for(const se of ee.lines)se.clear&&$.set(se.key,se.text);return $},[e]),oe=u.useId(),re=u.useMemo(()=>new Map([...z.keys()].map(($,F)=>[$,`${oe}-blocked-${F}`])),[z,oe]);u.useEffect(()=>{var ge,de;if(!a||h)return;const $=z.get(a.key),F=a.draft.trim(),ee=F?`What was typed: ${F}`:"Nothing was typed.",se=$&&!H?`${((ge=e.alert)==null?void 0:ge.title)??"Edits cannot be made now"}.`:((de=$==null?void 0:$.edit)==null?void 0:de.blocked)??null;!($!=null&&$.edit)||se?(r(null),w(se?{title:Pn.blocked,text:`${se} ${ee}`,typed:!!F}:{title:Pn.left,text:ee,typed:!!F}),C.current="gone"):a.start!==e.edit_start&&(r(null),C.current={key:a.key,then:"edit"})},[z,e,a,h,H]),u.useEffect(()=>{if(!m||y)return;const $=K.get(m.key);if(!($===m.text&&H)){if(p(null),E.current===m.key&&$===void 0&&H){E.current=null,j(Pn.cleared),R.current={key:m.key,then:"edit"};return}E.current=null,w(F=>{var ee;return F!=null&&F.typed?F:{title:H?$===void 0?Pn.clear_gone:Pn.changed:Pn.unclearable,text:H?`Nothing was cleared: “${m.text}”`:`${((ee=e.alert)==null?void 0:ee.title)??"Edits cannot be made now"}. Nothing was cleared: “${m.text}”`}}),R.current="gone"}},[K,m,y,H,e]);const ve=u.useRef(e);u.useEffect(()=>{e!==ve.current&&S(null),ve.current=e},[e]);const ke=u.useCallback($=>{if($==="gone"||$==="unread"){const ge=($==="gone"?P:L).current;return ge==null||ge.focus(),!!ge}if($==="field")return T.current?(T.current.focus(),T.current.select(),!0):!1;if(T.current)return!1;const F=D.current,ee=ge=>Array.from((F==null?void 0:F.querySelectorAll(`[${ge}]`))??[]).find(de=>de.getAttribute(ge)===$.key)??null,se=($.then==="clear"?ee("data-note-clear"):null)??ee("data-note-edit")??(F==null?void 0:F.querySelector('[data-note-edit]:not([aria-disabled="true"]),[data-note-clear]'))??document.getElementById(ru);return se==null||se.focus(),!0},[]);u.useEffect(()=>{const $=C.current;$&&ke($)&&(C.current=null)});const ae=$=>{M||!$.edit||$.edit.blocked||(r({key:$.key,draft:$.edit.value,start:e.edit_start}),l(null),d(null),j(""),C.current="field")},Ne=()=>{a&&(C.current={key:a.key,then:"edit"},r(null),l(null),d(null))},q=async()=>{var de,Le;if(!a||!t)return;const $=z.get(a.key);if(!$)return;const F=Q6(a.draft,$);if(l(F),F){d(null),(de=T.current)==null||de.focus();return}d(null),f(!0),s(!0);const ee=a.key,se=await t({key:ee,text:a.draft.trim()});if(se.ok){const Ee=await n();s(!1),f(!1),r(null),S(Ee===null?null:{write:"saved",error:Ee}),j(Pn.saved),C.current=Ee===null?{key:ee,then:"edit"}:"unread";return}s(!1),f(!1);const ge=se.refusal;ge.status===400?l(ge.message):(d(z_(ge.status,ge.message,!1)),ge.status===504&&n()),(Le=T.current)==null||Le.focus()},B=$=>{M||(E.current=null,v(null),j(""),p($))},Z=async()=>{if(!m||!t||y)return;v(null),g(!0),s(!0);const $=m.key,F=await t({key:$,clear:!0});if(F.ok){const ee=await n();s(!1),g(!1);const se=F.data.edit.cleared!==!1||E.current===$;E.current=null;const ge=se&&ee!==null;S(ge?{write:"cleared",error:ee}:null),j(se?Pn.cleared:Pn.nothing),R.current=ge?"unread":{key:$,then:"edit"},p(null);return}s(!1),g(!1),v(z_(F.refusal.status,F.refusal.message,!0)),E.current=F.refusal.status===504?$:null,F.refusal.status===504&&n(),A.current=!0};u.useEffect(()=>{var $;!A.current||y||(A.current=!1,($=G.current)==null||$.focus())});const Q=()=>{y||!m||(R.current={key:m.key,then:"clear"},p(null))},ie=$=>{var ge,de,Le;if((a==null?void 0:a.key)===$.key&&$.edit)return i.jsx("li",{className:"border-b last:border-b-0",children:i.jsx(eU,{line:$,draft:a.draft,saving:h,problem:o,notice:c,onDraft:Ee=>{r({...a,draft:Ee}),o&&l(null)},onSave:()=>void q(),onCancel:Ne,field_ref:T})},$.key);const F=((ge=$.edit)==null?void 0:ge.blocked)??null,ee=re.get($.key),se=M||!!a;return i.jsxs("li",{className:"flex flex-col gap-0.5 border-b py-2 text-sm last:border-b-0",children:[i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsxs("span",{className:"min-w-0 flex-1 break-words",children:[$.no_note?i.jsx("span",{className:"text-muted-foreground mr-2 text-xs",children:"no note"}):null,$.text]}),H&&$.edit?i.jsx(U,{variant:"link",size:"inline-sm","data-note-edit":$.key,"aria-label":`Edit: ${$.text}`,"aria-disabled":F||se?!0:void 0,"aria-describedby":F?ee:void 0,onClick:()=>!se&&ae($),children:"Edit"}):null]}),$.source?i.jsx("span",{className:"text-muted-foreground text-xs",children:$.source}):null,($.issues??[]).map((Ee,W)=>i.jsx("span",{className:"text-muted-foreground text-xs",children:Ee},`issue:${W}`)),($.served??[]).map((Ee,W)=>i.jsx("span",{className:"text-muted-foreground text-xs",children:Ee},`served:${W}`)),$.edited?i.jsxs("span",{className:"text-muted-foreground flex flex-wrap items-center gap-x-2 text-xs",children:[i.jsx("span",{children:$.edited.text}),H&&((de=$.edit)!=null&&de.clear)?i.jsx(U,{variant:"link",size:"inline-sm",className:"text-xs","data-note-clear":$.key,"aria-label":`Clear edit: ${$.text}`,"aria-disabled":se||void 0,onClick:()=>!se&&B({key:$.key,text:$.text,ask:`“${$.text}” goes back to its generated text, and the edit's text is lost.`}),children:"Clear edit"}):null]}):null,(Le=$.edited)!=null&&Le.changed?i.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-xs",children:[i.jsx(be,{variant:"warning",children:"source changed"}),i.jsx("span",{className:"text-warning",children:"since this edit: check that it still says what the line does"})]}):null,F?i.jsx("span",{id:ee,className:"text-muted-foreground text-xs",children:F}):null]},$.key)},ce=$=>{const F=N.has(`u:${$.key}`),ee=M||!!a;return i.jsxs("section",{className:"text-muted-foreground flex flex-col gap-1",children:[i.jsxs("h4",{className:"text-foreground text-sm font-medium",children:[$.title," ",i.jsx("span",{className:"text-muted-foreground text-xs font-normal",children:$.count})]}),i.jsx("p",{className:"text-xs",children:$.summary}),$.start?i.jsxs("p",{className:"text-xs",children:[$.start.label," ",i.jsx("code",{className:"font-mono",children:$.start.sha})]}):null,i.jsx("ul",{className:"flex flex-col",children:(F?$.lines:$.lines.slice(0,Pu)).map(se=>i.jsxs("li",{className:"flex flex-col gap-0.5 border-b py-2 text-sm last:border-b-0",children:[i.jsxs("div",{className:"flex items-start gap-3",children:[i.jsx("span",{className:"text-foreground min-w-0 flex-1 break-words",children:se.text}),H&&se.clear?i.jsx(U,{variant:"link",size:"inline-sm","data-note-clear":se.key,"aria-label":`Clear edit: ${se.text}`,"aria-disabled":ee||void 0,onClick:()=>!ee&&B({key:se.key,text:se.text,ask:$.key==="range"?`“${se.text}”: its text is lost, and no Release can apply it afterwards.`:`“${se.text}”: its text is lost.`}),children:"Clear edit"}):null]}),i.jsxs("span",{className:"text-xs",children:[se.who,se.range?` · made for the range from ${se.range} · ${se.key}`:` · ${se.key}`]})]},se.key))}),i.jsx(M_,{count:$.lines.length,shown:F,onShow:()=>O(se=>new Set(se).add(`u:${$.key}`))})]},$.key)};return i.jsxs("section",{ref:D,className:"flex flex-col gap-3","aria-labelledby":ru,children:[i.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[i.jsx("h2",{id:ru,tabIndex:-1,className:"text-lg font-semibold outline-none",children:"Notes"}),e.page?i.jsx("span",{className:"text-muted-foreground text-xs",children:e.page}):null,i.jsx("span",{role:"status","aria-live":"polite",className:"text-success text-xs",children:k})]}),e.alert?i.jsxs(me,{variant:"destructive",children:[i.jsx(Nt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:e.alert.title}),i.jsx(pe,{children:e.alert.text})]}):null,x?i.jsx(J6,{gone:x,alert_ref:P,onDismiss:()=>{var $;w(null),($=document.getElementById(ru))==null||$.focus()}}):null,_?i.jsx("div",{ref:L,tabIndex:-1,className:"outline-none",children:i.jsxs(me,{variant:"warning",children:[i.jsx(Nt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:`The edit was ${_.write}, but the notes could not be read again (${_.error})`}),i.jsx(pe,{children:Pn.refresh})]})}):null,e.none?i.jsx("p",{className:"text-muted-foreground text-sm",children:e.none}):null,e.sections.map($=>{const F=N.has($.key)||$.lines.slice(Pu).some(ee=>ee.key===(a==null?void 0:a.key));return i.jsxs("section",{className:"flex flex-col gap-1",children:[i.jsxs("h3",{className:"text-base font-semibold",children:[$.title," ",$.count?i.jsx("span",{className:"text-muted-foreground text-xs font-normal",children:$.count}):null]}),$.summary?i.jsx("p",{className:"text-muted-foreground text-xs",children:$.summary}):null,i.jsx("ul",{className:"flex flex-col",children:(F?$.lines:$.lines.slice(0,Pu)).map(ie)}),i.jsx(M_,{count:$.lines.length,shown:F,onShow:()=>O(ee=>new Set(ee).add($.key))})]},$.key)}),e.unapplied.map(ce),i.jsx(bf,{open:m!==null,onOpenChange:$=>{$||Q()},children:i.jsxs(yf,{onEscapeKeyDown:$=>{y&&$.preventDefault()},onCloseAutoFocus:$=>{$.preventDefault();const F=R.current;R.current=null,F&&!ke(F)&&(C.current=F)},children:[i.jsxs(wf,{children:[i.jsx(jf,{children:"Clear this edit?"}),i.jsx(Nf,{children:m==null?void 0:m.ask})]}),b?i.jsx(WE,{notice:b}):null,i.jsxs(_f,{children:[i.jsx(U,{type:"button",variant:"outline",size:"sm","data-slot":"alert-dialog-cancel","aria-disabled":y||void 0,onClick:Q,children:"Cancel"}),i.jsx(U,{ref:G,type:"button",variant:"destructive",size:"sm",loading:y,onClick:()=>void Z(),children:y?"Clearing…":"Clear"})]})]})})]})}const Hs={noRelease:"No open Planned Release. Create one: release_plan.py create --name <version>",noTask:"no open task of yours",noNext:"none",pending:"reading the roadmap",failedLead:"The roadmap could not be read",noEngineLead:"this engine has no roadmap read"},$_=3,nU=["in_progress","not_started","planned","blocked"],Cb="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),Qt=e=>e.charAt(0).toUpperCase()+e.slice(1);function bp(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(String(e??""));return t?`${Number(t[3])} ${Cb[Number(t[2])-1]}`:String(e??"")}function FE(e){if(typeof e!="number")return"";const t=new Date(e*1e3);return Number.isNaN(t.getTime())?"":`${t.getDate()} ${Cb[t.getMonth()]} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function sU(e){if(typeof e!="number")return"";const t=new Date(e*1e3);return Number.isNaN(t.getTime())?"":`${t.getDate()} ${Cb[t.getMonth()]}`}function Ri(e){return e?e.from===e.to&&e.or_later?`${bp(e.from)} or later`:`${bp(e.from)} to ${bp(e.to)}${e.or_later?", or later":""}`:""}function iU(e){if(!e||!e.members)return"";const t=[`${e.sized??0} of ${e.members} members sized (${e.estimated??0} estimated, ${e.predicted??0} predicted)`];return e.not_sized&&t.push(`${e.not_sized} not sized`),t.join(" · ")}function qE(e){var f;const t=e??{},n=t.source??{},a=[t.no_date==="no date: no rate"&&n.rate_why?n.rate_why:"",/members estimated$/.test(t.no_date??"")?"":iU(t)].filter(Boolean).join(" · "),r=t.projected?Ri(t.projected):t.no_date??"",o=(f=t.projected)==null?void 0:f.raw,l=!!(o&&t.projected&&(o.from!==t.projected.from||o.to!==t.projected.to)),c=t.projected?n.rate_basis==="release"?"at this release's own rate":n.rate_basis==="machine"?`at the machine's rate${n.rate_why?`: ${n.rate_why}`:""}`:"":"",d=t.track_record,h=[a,c,l&&o&&t.projected?`corrected for past estimates: raw ${Ri({...o,or_later:t.projected.or_later})}`:"",d?`past forecasts at this coverage: ${d.inside} of ${d.of} inside their range`:""].filter(Boolean);return{lead:r?Qt(r):"",caption:h}}function aU(e){const t=e.kinds??[];return[t.includes("range")?"Not promised":"",e.goal??(t.includes("major")?"No goal yet":"")].filter(Boolean).join(" · ")}function rU(e){var c,d,h,f;const t=((c=e.counts)==null?void 0:c.members)??0,n=`${((d=e.counts)==null?void 0:d.done)??0} of ${t} member${t===1?"":"s"} done`,s=(e.blocked??[]).length,a=(e.needs_user??[]).length,r=!s&&!a?["none blocked · none waiting on you"]:[s?`${s} blocked`:"",a?`${a} waiting on you`:""],o=((h=e.tasks)==null?void 0:h.untracked_slices)??0;o&&r.push(`${o} slice${o===1?"":"s"} not tasks yet`);const l=((f=e.not_a_member)==null?void 0:f.count)??0;return l&&r.push(`${l} not a member yet`),{lead:n,rest:r.filter(Boolean).join(" · ")}}const YE=e=>String(e??"").replace(/_/g," ");function oU(e){const t=e??{},n=t.kinds??[],s=n.includes("slipped"),a=!s&&t.was&&t.now?Ri(t.was)===Ri(t.now)?`, range still ${Ri(t.now)}`:`, range was ${Ri(t.was)}, now ${Ri(t.now)}`:"",r=[s&&t.was?`was ${Ri(t.was)}`:"",n.includes("scope changed")?`scope changed${a}`:""].filter(Boolean),o=(t.what??[]).slice(-3).map(l=>{const c=l.by&&(l.by.title||l.by.thread||l.by.person);return`${[l.kind,l.label||l.item].filter(Boolean).join(" ")}${c?` by ${c}`:""}${l.why?`: ${l.why}`:""}`});return{head:r.length?Qt(r.join(" · ")):"",what:o}}const zo="roadmap",L_={reading:!1,value:null,refusal:null};function lU(e){const[t,n]=u.useState({all:L_,mine:L_}),s=u.useRef({all:0,mine:0}),a=Os(),r=Os(),o=u.useCallback(async(l,c=!1,d=!1)=>{if(!(e!=null&&e.roadmap))return;const h=l==="mine"?r:a;if(d&&h.busy())return;const f=++s.current[l];d||n(p=>({...p,[l]:{...p[l],reading:!0}}));const m=await h.track(e.roadmap({...c?{fresh:!0}:{},...l==="mine"?{mine:!0}:{}}));f===s.current[l]&&n(p=>({...p,[l]:m.ok?{reading:!1,value:m.data,refusal:null}:d?{...p[l],reading:!1}:{reading:!1,value:p[l].value,refusal:m.refusal}}))},[e,a,r]);return{reads:t,read:o,available:!!(e!=null&&e.roadmap)}}function cU(e,t){return`${e} open${t.length?` · ${t.join(", ")} moved since you looked`:""}`}function fc({children:e}){return i.jsx("pre",{className:"bg-muted text-foreground rounded-md px-3 py-2 font-mono text-xs break-all whitespace-pre-wrap",children:e})}const XE=({level:e})=>e?i.jsx(be,{variant:"neutral",children:Qt(e)}):null;function KE({state:e}){const t=Qt(YE(e));return nU.includes(String(e))?i.jsx("span",{className:"font-medium",children:t}):i.jsx("span",{children:t})}function dU({reads:e,scope:t,onScope:n,onRead:s,org:a,onSelect:r}){var p,y;const o=e[t],l=o.value,c=is(),d=u.useRef(null),h=u.useRef(!1);u.useEffect(()=>{!o.reading&&!o.value&&!o.refusal&&s(t)},[t,o.reading,o.value,o.refusal,s]),u.useEffect(()=>{var g;h.current&&!o.reading&&(h.current=!1,(g=d.current)==null||g.focus())},[o.reading]);const f=()=>{h.current=!0,s(t,!0)},m=l?[l.as_of?`as of ${FE(l.as_of)}`:"",`${((p=l.source)==null?void 0:p.machine)||"this machine"}'s records`,((y=l.decider)==null?void 0:y.words)??""].filter(Boolean).join(" · "):"";return i.jsxs(Ds,{children:[i.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-start",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[i.jsx("h2",{ref:d,tabIndex:-1,className:"text-lg font-semibold outline-none",children:"Roadmap"}),m?i.jsx("p",{className:"text-muted-foreground text-xs",children:m}):null]}),i.jsx("div",{role:"group","aria-label":"Roadmap scope",className:"flex gap-2",children:["all","mine"].map(g=>i.jsx(U,{variant:"outline",size:"sm","aria-pressed":t===g,onClick:()=>n(g),children:g==="all"?"All":"Mine"},g))})]}),i.jsx("div",{"aria-live":"polite",children:o.reading?i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status",children:[i.jsx(wn,{"aria-hidden":!0,className:"size-4"})," ",Qt(Hs.pending),"…"]}):null}),o.refusal&&!o.reading?o.refusal.reason==="no_roadmap"?i.jsx(es,{title:Hs.failedLead,error:`${Qt(Hs.noEngineLead)}. ${c}`}):o.refusal.reason==="refused"?i.jsx(es,{title:Hs.failedLead,error:o.refusal.message}):i.jsx(es,{title:Hs.failedLead,error:o.refusal.message,onRetry:f}):null,l?t==="mine"?i.jsx(xU,{mine:l.mine,org:a,onSelect:r}):i.jsx(hU,{read:l,org:a,onSelect:r}):null]})}function uU(e){if(!e||typeof e.seconds_per_day!="number")return"No rate";const t=sU(e.as_of);return`${Math.round(e.seconds_per_day/3600)} task hours a day over the ${e.days} days${t?` to ${t}`:""}`}function hU({read:e,org:t,onSelect:n}){var a,r;const s=e.releases??[];if(!s.length){const[o,l]=Hs.noRelease.split(" Create one: ");return i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx("p",{className:"text-sm",children:o}),i.jsx("p",{className:"text-muted-foreground text-xs",children:"Create one in the terminal:"}),i.jsx(fc,{children:l})]})}return i.jsxs(i.Fragment,{children:[i.jsx(Zf,{pairs:[["Forecast from",Qt(`${((a=e.source)==null?void 0:a.machine)||"this machine"}'s task records and rate`)],["Rate",uU(e.rate)],["Not counted",Qt(((r=e.source)==null?void 0:r.not_counted)||"other machines' work")]]}),s.map(o=>i.jsx(fU,{row:o,org:t,onSelect:n},o.id))]})}function fU({row:e,org:t,onSelect:n}){var f,m,p;const s=qE(e.forecast),a=rU(e),r=aU(e),o=`roadmap-${e.id}`,l=e.moved?oU(e.told):null,c=(((f=e.counts)==null?void 0:f.members)??0)===0,d=((m=e.not_a_member)==null?void 0:m.count)??0,h=[r,c&&d?`${d} not a member yet`:""].filter(Boolean).join(" · ");return i.jsxs("section",{"aria-labelledby":o,className:"flex flex-col gap-2 border-t pt-4",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h3",{id:o,className:"text-base font-semibold",children:i.jsx(gr,{query:`planned=${encodeURIComponent(e.id)}`,select:Ws(e.id),onSelect:n,children:e.name})}),e.kinds.map(y=>i.jsx(be,{variant:"neutral",children:y},y))]}),s.lead||s.caption.length?i.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.lead?i.jsx("p",{className:"text-sm",children:s.lead}):null,s.caption.length?i.jsx("p",{className:"text-muted-foreground text-xs",children:Qt(s.caption.join(" · "))}):null]}):null,h?i.jsx("p",{className:"text-muted-foreground text-sm",children:h}):null,l?i.jsxs(me,{variant:"info",children:[i.jsx(UM,{"aria-hidden":!0}),i.jsx(je,{children:"Moved since you looked"}),i.jsxs(pe,{className:"text-info flex flex-col gap-0.5",children:[l.head?i.jsx("span",{children:l.head}):null,l.what.map((y,g)=>i.jsx("span",{className:"text-xs",children:y},g))]})]}):null,c?null:i.jsxs("p",{className:"text-sm",children:[a.lead,a.rest?i.jsxs("span",{className:"text-muted-foreground",children:[" · ",a.rest]}):null]}),(p=e.stale_unchecked)!=null&&p.words?i.jsx("p",{className:"text-muted-foreground text-xs",children:Qt(e.stale_unchecked.words)}):null,e.for_you&&e.kinds.includes("major")?i.jsx(mU,{row:e}):null,i.jsx(gU,{row:e,org:t})]})}function mU({row:e}){const t=e.for_you;return!t||!t.proposals.length&&!t.committed_nobody_on.length&&!t.widens_most&&!t.set_goal?null:i.jsxs("div",{className:"flex flex-col gap-2",children:[i.jsx("h4",{className:"text-sm font-semibold",children:"For you"}),t.proposals.map(s=>{const a=[s.proposed_by_title||s.proposed_by?`by ${s.proposed_by_title||s.proposed_by}`:"",s.reason??""].filter(Boolean).join(": ");return i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("p",{className:"text-sm",children:["Proposed: ",s.label||s.item]}),i.jsxs("p",{className:"text-muted-foreground text-xs",children:[a?`${Qt(a).replace(/\.$/,"")}. `:"","Accept or reject in the terminal:"]}),i.jsx(fc,{children:s.accept}),i.jsx(fc,{children:s.reject})]},s.item)}),t.committed_nobody_on.map(s=>i.jsxs("p",{className:"text-sm",children:["Nobody on this machine is on ",s.label||s.item,s.level?` (${s.level})`:""]},s.item)),t.widens_most?i.jsxs("p",{className:"text-sm",children:["Widens the range most: ",t.widens_most.label||t.widens_most.item,t.widens_most.high_seconds?i.jsxs("span",{className:"text-muted-foreground",children:[" · +",Math.round(t.widens_most.high_seconds/3600)," h of work at the late end"]}):null]}):null,t.set_goal?i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("p",{className:"text-sm",children:"Set its goal:"}),i.jsx(fc,{children:t.set_goal})]}):null]})}function ZE({next:e,org:t}){const{href:n,Link:s}=lt(),a=e.tasks[0],r=e.label||e.item;return a?i.jsx(s,{className:"text-primary hover:underline",href:n(`/org/${t}/tasks/${encodeURIComponent(a.id)}?from=roadmap`),children:r}):i.jsx("span",{children:r})}function pU(e,t){return e.threads.length?e.threads.map(n=>n.title||n.thread).join(", "):t.kinds.includes("range")?(t.tagged_threads??[]).map(n=>`${n.title}: ${n.words}`).join(", "):e.nobody?Qt(e.nobody):""}function gU({row:e,org:t}){const[n,s]=u.useState(!1),a=e.next??[];if(!a.length){const l=e.kinds.includes("range")?e.tagged_threads??[]:[];return l.length?i.jsx("p",{className:"text-muted-foreground text-sm",children:l.map(c=>`${c.title}: ${c.words}`).join(", ")}):null}const r=n?a:a.slice(0,$_),o=new Map((e.stale_estimates??[]).map(l=>[l.item,l]));return i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h4",{className:"text-sm font-semibold",children:"Next"}),i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:`Next in ${e.name}`,children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Member"}),i.jsx(J,{children:"Level"}),i.jsx(J,{children:"State"}),i.jsx(J,{children:"Who is on it"})]})}),i.jsx(at,{children:r.map(l=>{const c=o.get(l.item);return i.jsxs(ye,{children:[i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[i.jsx(ZE,{next:l,org:t}),c?i.jsxs("span",{className:"text-muted-foreground text-xs",children:[Qt(c.words),c.estimate_as_of?` (estimated ${FE(c.estimate_as_of)})`:""]}):null]})}),i.jsx(X,{children:i.jsx(XE,{level:l.level})}),i.jsx(X,{children:i.jsx(KE,{state:l.state})}),i.jsx(X,{children:pU(l,e)})]},l.item)})})]})}),a.length>$_&&!n?i.jsxs(U,{variant:"outline",size:"sm",className:"self-start",onClick:()=>s(!0),children:["Show all ",a.length]}):null,r.some(l=>o.has(l.item))?i.jsx("p",{className:"text-muted-foreground text-xs",children:"Re-forecast it in the terminal: task-record reforecast"}):null]})}function xU({mine:e,org:t,onSelect:n}){const{href:s,Link:a}=lt();if(!e)return null;const r=e.tasks.filter(o=>o.propose);return i.jsxs(i.Fragment,{children:[i.jsxs("section",{"aria-labelledby":"roadmap-your-work",className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex items-baseline gap-2",children:[i.jsx("h3",{id:"roadmap-your-work",className:"text-base font-semibold",children:"Your work"}),i.jsx("span",{className:"text-muted-foreground text-xs",children:e.title})]}),e.tasks.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:Qt(Hs.noTask)}):i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Your work",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Task"}),i.jsx(J,{children:"Release"}),i.jsx(J,{children:"Member"})]})}),i.jsx(at,{children:e.tasks.map(o=>{var l,c;return i.jsxs(ye,{children:[i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[i.jsx(a,{className:"text-primary font-mono text-xs hover:underline",href:s(`/org/${t}/tasks/${encodeURIComponent(o.id)}?from=roadmap`),children:o.id}),i.jsx("span",{className:"text-muted-foreground text-xs",children:[o.title||o.thread,Qt(YE(o.state))].filter(Boolean).join(" · ")})]})}),i.jsx(X,{children:(l=o.members)!=null&&l.length?o.members.map(d=>i.jsx("div",{children:i.jsx(gr,{query:`planned=${encodeURIComponent(d.planned_release)}`,select:Ws(d.planned_release),onSelect:n,children:d.name})},d.planned_release)):o.release?i.jsx(gr,{query:`planned=${encodeURIComponent(o.release.planned_release)}`,select:Ws(o.release.planned_release),onSelect:n,children:o.release.name}):i.jsx("span",{className:"text-muted-foreground",children:o.words?Qt(o.words):"—"})}),i.jsx(X,{children:(c=o.members)!=null&&c.length?o.members.map(d=>i.jsx(XE,{level:d.level},d.planned_release)):o.not_a_member?i.jsx("span",{className:"text-muted-foreground",children:"Not a member yet"}):null})]},o.id)})})]})}),r.map(o=>{var l;return i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Propose ",o.id,"'s plan to ",((l=o.release)==null?void 0:l.name)??"its release"," in the terminal:"]}),i.jsx(fc,{children:o.propose??""})]},o.id)})]}),i.jsxs("section",{"aria-labelledby":"roadmap-your-next",className:"flex flex-col gap-2",children:[i.jsx("h3",{id:"roadmap-your-next",className:"text-base font-semibold",children:"Your next members"}),e.next.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:Qt(Hs.noNext)}):i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Your next members",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Release"}),i.jsx(J,{children:"Member"}),i.jsx(J,{children:"State"})]})}),i.jsx(at,{children:e.next.map(o=>i.jsxs(ye,{children:[i.jsx(X,{children:i.jsx(gr,{query:`planned=${encodeURIComponent(o.release)}`,select:Ws(o.release),onSelect:n,children:o.name})}),i.jsx(X,{children:i.jsx(ZE,{next:o,org:t})}),i.jsx(X,{children:i.jsx(KE,{state:o.state})})]},`${o.release}:${o.item}`))})]})})]})]})}function vU({state:e,id:t}){var r;const n=is();if(!e)return null;const s=(r=e.value)==null?void 0:r.releases.find(o=>o.id===t);if(!s){if(e.reading)return i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status",children:[i.jsx(wn,{"aria-hidden":!0,className:"size-4"})," ",Qt(Hs.pending),"…"]});if(e.refusal){const o=e.refusal.reason==="no_roadmap"?`${Qt(Hs.noEngineLead)}. ${n}`:e.refusal.message;return i.jsx("p",{className:"text-muted-foreground text-xs",children:`${Hs.failedLead}: ${o}`})}return null}const a=qE(s.forecast);return i.jsxs("div",{className:"flex flex-col gap-0.5",children:[a.lead?i.jsx("p",{className:"text-sm",children:a.lead}):null,a.caption.length?i.jsx("p",{className:"text-muted-foreground text-xs",children:Qt(a.caption.join(" · "))}):null]})}function Db(){const e=Wn().releases;if(!e)throw new Error("The Releases page rendered without a Releases contract.");return e}function bU({initial:e,environments:t,branch_options:n,chooseBranch:s,renderWrite:a,selection:r,org:o,onReadAgain:l,onNotFound:c,notice:d,focusOnMount:h,tick:f=0}){var Zs,V,$e,Xe,Mt,Ls,Ni,ki,Xa,Ir;const m=Db(),p=e.local??null,y=!!p,[g,b]=u.useState(e);u.useEffect(()=>{e.local&&b(e)},[e]);const[v,x]=u.useState(null),w=r?r.selected:v,_=r?r.onSelect:x,S=!!(p||g.release_branch),[k,j]=u.useState(p||e.release_branch?{state:"loading"}:{state:"ready",value:null}),[N,O]=u.useState({}),[T,P]=u.useState(null),[L,G]=u.useState(!1),[A,D]=u.useState(null),[C,R]=u.useState(null),E=u.useRef(null),M=p?{fresh:!0}:void 0,H=u.useRef(0),z=Os(),K=u.useCallback(async(Oe,ht=!1,ln=!1)=>{if(ht&&!ln&&z.busy())return"A read is still running.";const cn=++H.current,Ln=await z.track(m.candidate(Oe)),os=Ln.ok?null:Ln.refusal.message;return cn!==H.current||j(Ka=>Ln.ok?{state:"ready",value:Ln.data.candidate}:ht&&Ka.state==="ready"?Ka:{state:"error",error:Ln.refusal.message,refusal:Ln.refusal}),os},[m,z]),oe=u.useRef(!1),re=u.useCallback(async()=>{j({state:"loading"}),await K(M)},[K,y]),ve=u.useCallback(async()=>{const Oe=await m.list();Oe.ok&&b(Oe.data)},[m]),ke=((Zs=g.release_branch)==null?void 0:Zs.id)??null;u.useEffect(()=>{if(!(!y&&!ke))return K(),()=>{H.current+=1}},[ke,K,y]);const ae=u.useRef(new Set),Ne=u.useCallback((Oe,ht)=>O(ln=>({...ln,[Oe]:ht.ok?{state:"ready",value:ht.data.release}:{state:"error",error:ht.refusal.message,refusal:ht.refusal}})),[]),q=async Oe=>{O(ht=>({...ht,[Oe]:{state:"loading"}})),ae.current.add(Oe),Ne(Oe,await m.release(Oe,M))},B=k.state!=="ready"||k.value!==null,Z=L6(w),Q=lU(p?m:void 0),ie=Q.available&&w===zo,[ce,$]=u.useState("all"),F=g.release_branch||p?B?ei:null:((V=g.releases[0])==null?void 0:V.version)??null,ee=Z!==null||ie?null:w===ei?B?ei:null:w??F,[se,ge]=u.useState([]),de=u.useRef(0),Le=u.useRef(0),Ee=Os(),W=u.useCallback(()=>{if(!y||!m.roadmapMoved)return;const Oe=Le.current,ht=de.current;Ee.track(m.roadmapMoved()).then(ln=>{Oe===Le.current&&ln.ok&&ht===de.current&&ge(ln.data.moved.map(cn=>cn.name))})},[m,y,Ee]);u.useEffect(()=>(W(),()=>{Le.current+=1}),[W]),Bc(f,()=>{Ee.busy()||W()});const _e=Q.reads.all,He=Q.read;u.useEffect(()=>{Z===null||!Q.available||!_e.value&&!_e.reading&&!_e.refusal&&He("all")},[Z,Q.available,_e,He]);const[Dt,en]=u.useState(0),zt=u.useRef(0),tt=Oe=>{Oe===zo&&en(ht=>ht+1),_(Oe)};u.useEffect(()=>{if(Dt!==zt.current){if(!ie){zt.current=Dt;return}ce!=="all"||_e.reading||!_e.value||!m.roadmapSeen||(zt.current=Dt,m.roadmapSeen(_e.value.as_of).then(Oe=>{Oe.ok&&(de.current+=1,ge([]))}))}},[Dt,ie,ce,_e,m]);const ft=new Map(((($e=_e.value)==null?void 0:$e.releases)??[]).map(Oe=>[Oe.id,[Oe.kinds.includes("range")?"range":"",Oe.forecast.projected?Ri(Oe.forecast.projected):"no date"].filter(Boolean).join(" · ")])),It=ee===null||ee===ei||g.releases.some(Oe=>Oe.version===ee);u.useEffect(()=>{!p||!c||ee!==null&&ee!==ei&&!It&&c({kind:"release",id:ee})},[p,c,ee,It]),u.useEffect(()=>{!ee||ee===ei||ae.current.has(ee)||p&&!It||(ae.current.add(ee),m.release(ee).then(Oe=>Ne(ee,Oe)))},[ee,m,Ne,It]);const zn=Os();Bc(f,()=>{if(p){if(oe.current||K(void 0,!0),ee&&ee!==ei&&It&&!zn.busy()){const Oe=ee;zn.track(m.release(Oe)).then(ht=>{ht.ok&&Ne(Oe,ht)})}ie?He(ce,!1,!0):Z!==null&&_e.value&&He("all",!1,!0)}});const gn=u.useRef(w),Mn=u.useRef(!1),xe=u.useRef(!!h),ne=u.useRef(null);u.useEffect(()=>{var ht,ln;if(!p)return;if(xe.current){const cn=(ht=ne.current)==null?void 0:ht.querySelector('[aria-current="true"]');if(cn){xe.current=!1,gn.current=w,cn.focus();return}}if(gn.current!==w&&(gn.current=w,Mn.current=!0),!Mn.current)return;const Oe=(ln=E.current)==null?void 0:ln.querySelector("h2");Oe&&(Mn.current=!1,Oe.tabIndex=-1,Oe.focus())});const Se=async Oe=>{if(!s)return;P(null);const ht=await s(Oe);if(!ht.ok){P(ht.error);return}x(null),j({state:"loading"}),await ve()},Ye=async()=>{if(!g.next_before)return;R(null);const Oe=await m.list({before:g.next_before});if(!Oe.ok){R(Oe.refusal.message);return}b(ht=>({...Oe.data,releases:[...ht.releases,...Oe.data.releases]}))},nt=g.release_branch?i.jsx(yU,{value:g.release_branch.id,label:g.release_branch.name,options:n??[],can_write:g.can_write,onChange:Se}):null,as=p?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Read at ",Rs(p.read_at)]}),l?i.jsxs(U,{variant:"ghost",size:"sm",onClick:l,children:[i.jsx(zr,{className:"mr-1 size-4","aria-hidden":!0}),"Read again"]}):null]}):nt,$n=p?P6(((Xe=g.releases[0])==null?void 0:Xe.label)??((Mt=g.releases[0])==null?void 0:Mt.version)??null):w6(((Ls=g.releases[0])==null?void 0:Ls.version)??null,((Ni=g.release_branch)==null?void 0:Ni.name)??null),rs={org:o??""};return i.jsxs(Kf.Provider,{value:f,children:[i.jsx(DE,{description:p?zE:void 0,actions:as}),d,p?i.jsx(I6,{}):null,T?i.jsx(es,{error:T}):null,p?null:t,!p&&!g.release_branch?i.jsx(wU,{can_write:g.can_write,options:n??[],onChoose:Se}):null,g.release_branch||g.releases.length>0||p?i.jsxs("div",{ref:ne,className:"flex flex-col gap-6 md:flex-row md:items-start",children:[i.jsx(_U,{list:g,candidate:S?k:null,shown:ie?zo:Z!==null?Ws(Z):ee,onSelect:tt,roadmap:Q.available?cU(((ki=g.planned)==null?void 0:ki.length)??0,se):null,planned_ranges:ft,can_load_older:!!g.next_before,older_error:C,onLoadOlder:Ye}),i.jsx("div",{className:"min-w-0 flex-1",ref:E,children:ie?i.jsx(dU,{reads:Q.reads,scope:ce,onScope:$,onRead:He,org:rs.org,onSelect:_}):Z!==null?i.jsx(K6,{id:Z,summary:((Xa=g.planned)==null?void 0:Xa.find(Oe=>Oe.id===Z))??null,org:rs.org,onNotFound:()=>c==null?void 0:c({kind:"planned",id:Z}),forecast:Q.available?i.jsx(vU,{state:_e,id:Z}):null}):ee===ei?i.jsx(NU,{candidate:k,branch_name:((Ir=g.release_branch)==null?void 0:Ir.name)??null,can_write:g.can_write&&!!a,local:!!p,org:rs.org,onSelect:_,onRetry:re,onWrite:()=>G(!0),onChanged:()=>void K(M,!0,!0),onReread:()=>K(M,!0,!0),onNotesBusy:Oe=>{oe.current=Oe}}):ee?i.jsx(kU,{detail:N[ee]??{state:"loading"},summary:g.releases.find(Oe=>Oe.version===ee)??null,local:!!p,org:rs.org,onSelect:_,onRetry:()=>q(ee)}):(g.release_branch||p)&&k.state==="ready"?i.jsx(y6,{title:$n.title,text:$n.text}):null})]}):null,a&&k.state==="ready"&&k.value?a({candidate:k.value,open:L,notice:A,onOpenChange:Oe=>{Oe||D(null),G(Oe)},onStale:async Oe=>{D(Oe),await K()},onWritten:async Oe=>{G(!1),D(null),await ve(),x(Oe),await re()}}):null]})}function yU({value:e,label:t,options:n,can_write:s,onChange:a}){const r=n.some(o=>o.id===e);return i.jsxs("div",{className:"grid w-56 gap-2",children:[i.jsx(Ie,{htmlFor:"release-branch",children:"Release branch"}),i.jsxs(St,{value:e,onValueChange:a,disabled:!s,children:[i.jsx(_t,{id:"release-branch",children:i.jsx(Ct,{})}),i.jsxs(jt,{children:[r?null:i.jsx(Be,{value:e,children:t??"Unnamed branch"}),n.map(o=>i.jsx(Be,{value:o.id,children:o.label},o.id))]})]}),s?null:i.jsx(QE,{})]})}function QE(){return i.jsx("p",{className:"text-muted-foreground text-xs",children:"You have read access; ask a member with write access to change it or write a Release."})}function wU({can_write:e,options:t,onChoose:n}){return i.jsxs("section",{className:"flex flex-col items-center gap-3 py-16 text-center",children:[i.jsx(Tc,{className:"text-muted-foreground size-8","aria-hidden":!0}),i.jsx("h2",{className:"text-lg font-semibold",children:"Choose a release branch"}),i.jsx("p",{className:"text-muted-foreground max-w-md text-sm",children:"A Release records the graph change between two commits of one branch. Choose the branch you release from; you can change it later."}),i.jsxs("div",{className:"grid w-64 gap-2 text-left",children:[i.jsx(Ie,{htmlFor:"release-branch-first",children:"Release branch"}),i.jsxs(St,{onValueChange:n,disabled:!e,children:[i.jsx(_t,{id:"release-branch-first",children:i.jsx(Ct,{placeholder:"Choose a branch"})}),i.jsx(jt,{children:t.map(s=>i.jsx(Be,{value:s.id,children:s.label},s.id))})]})]}),e?null:i.jsx(QE,{})]})}function JE({children:e}){return i.jsx("p",{className:"text-muted-foreground px-3 pt-3 text-xs font-medium tracking-wide uppercase",children:e})}function _U({list:e,candidate:t,shown:n,onSelect:s,roadmap:a,planned_ranges:r,can_load_older:o,older_error:l,onLoadOlder:c}){var f,m;const d=!!e.local,h=(t==null?void 0:t.state)==="ready"&&t.value?Uc(t.value.changes):null;return i.jsxs("nav",{"aria-label":"Releases",className:"flex w-full flex-col gap-1 md:sticky md:top-0 md:max-h-[calc(100vh-3.5rem)] md:w-72 md:shrink-0 md:overflow-y-auto",children:[d&&a?i.jsx(Lu,{active:n===zo,onClick:()=>s(zo),version:"Roadmap",badges:null,caption:a}):null,t&&(t.state!=="ready"||t.value)?i.jsx(Lu,{active:n===ei,onClick:()=>s(ei),version:t.state==="ready"&&t.value?t.value.version:"Next release",badges:i.jsxs(i.Fragment,{children:[i.jsx(be,{variant:"info",children:"Candidate"}),h!=null&&h.breaking?i.jsx(be,{variant:"error",children:"Breaking"}):t.state==="ready"&&((f=t.value)==null?void 0:f.app_changed)===!1?i.jsx(be,{variant:"neutral",children:"App unchanged"}):t.state==="ready"&&((m=t.value)!=null&&m.classification)?i.jsx(be,{variant:"neutral",children:t.value.classification.bump}):null]}),caption:t.state==="loading"?"Classifying…":t.state==="error"?"Could not be read":EE(t.value)}):null,d?i.jsx(jU,{list:e,shown:n,onSelect:s,ranges:r}):null,d&&e.releases.length>0?i.jsx(JE,{children:"Released"}):null,e.releases.map(p=>{const y=d?G6(p):null;return i.jsx(Lu,{active:n===p.version,onClick:()=>s(p.version),version:p.label??p.version,badges:(y==null?void 0:y.badges)??i.jsxs(i.Fragment,{children:[i.jsx(be,{variant:"neutral",children:p.previous_release_id?p.bump??"patch":"First"}),p.breaking?i.jsx(be,{variant:"error",children:"Breaking"}):null]}),caption:(y==null?void 0:y.caption)??_b(p.written_at)},p.version)}),o?i.jsx(U,{variant:"link",size:"sm",className:"self-start",onClick:c,children:"Show older Releases"}):null,l?i.jsx("p",{className:"text-destructive text-xs",role:"alert",children:l}):null]})}function jU({list:e,shown:t,onSelect:n,ranges:s}){return!e.planned_error&&!(e.planned&&e.planned.length>0)?null:i.jsxs(i.Fragment,{children:[i.jsx(JE,{children:"Planned"}),e.planned_error?i.jsx(es,{title:"Planned Releases could not be read",error:e.planned_error}):null,(e.planned??[]).map((a,r)=>i.jsx(Lu,{active:t===Ws(a.id),onClick:()=>n(Ws(a.id)),version:a.name,badges:i.jsx(be,{variant:"neutral",children:"Planned"}),caption:`${a.members===0?"no members":`${a.members} member${a.members===1?"":"s"}`}${r===0?" · next":""}${s!=null&&s.get(a.id)?` · ${s.get(a.id)}`:""}`},a.id))]})}function NU({candidate:e,branch_name:t,can_write:n,local:s,org:a,onSelect:r,onRetry:o,onWrite:l,onChanged:c,onReread:d,onNotesBusy:h}){var v;const f=Db(),m=is();if(e.state==="loading")return i.jsx(Ds,{children:i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:"Classifying the changes since the last Release…"})});if(e.state==="error")return i.jsx(Ds,{children:i.jsx(es,{error:e.error,onRetry:o})});const p=e.value;if(!p)return null;const y=Uc(p.changes),g=!p.previous_release,b=t??"the release branch";return i.jsxs(Ds,{children:[i.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:p.version}),i.jsx(be,{variant:"info",children:"Candidate"}),y.breaking?i.jsx(be,{variant:"error",children:"Breaking"}):p.app_changed===!1?i.jsx(be,{variant:"neutral",children:"App unchanged"}):p.classification?i.jsx(be,{variant:"neutral",children:p.classification.bump}):null]}),i.jsxs("p",{className:"text-muted-foreground text-sm",children:[s?"What staging runs over production: ":`What the next Release holds at ${b}'s head: `,EE(p),". It is computed when you open it and never stored.",y.breaking&&p.next_version.startsWith("0.")?" Before 1.0.0 a major change raises the minor number.":""]}),g?i.jsxs("p",{className:"text-muted-foreground text-xs",children:["The first Release, ",p.next_version,", records the starting point and lists no changes."]}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"Only graph changes are judged, so code that changed without a graph change is not counted."}),(v=p.classification)!=null&&v.marks_approximate?i.jsx("p",{className:"text-muted-foreground text-xs",children:"Modeling-only marks could not all be read, so these notes may leave out a change made after a mark."}):null,p.commits_since===null?i.jsx("p",{className:"text-muted-foreground text-xs",children:"Not every commit since the last Release could be walked, so the count and the rc number are at least what is shown."}):null]}),n?i.jsxs(U,{onClick:l,children:[i.jsx(Tc,{className:"mr-2 size-4"}),"Write Release ",p.next_version]}):null]}),s?i.jsx(q6,{candidate:p,org:a,onSelect:r,onChanged:c,notes:g?null:p.notes?i.jsx(tU,{notes:p.notes,edit:f.editNote,reread:d,onBusy:h}):i.jsxs(i.Fragment,{children:[i.jsx(Mh,{changes:p.changes}),p.notes_unavailable==="view_outdated"?i.jsx("p",{className:"text-muted-foreground text-xs",children:`Editing these notes needs a newer engine: ${m}`}):null]})}):g?null:i.jsx(Mh,{changes:p.changes})]})}function kU({detail:e,summary:t,local:n,org:s,onSelect:a,onRetry:r}){const[o,l]=u.useState(!1);if((t==null?void 0:t.state)==="unreadable")return i.jsxs(Ds,{children:[i.jsx("h2",{className:"text-lg font-semibold",children:t.label??t.version}),i.jsx(es,{title:"This Release could not be read",error:t.error??"Its record cannot be read."})]});if(e.state==="loading")return i.jsx(Ds,{children:i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:"Loading the Release…"})});if(e.state==="error")return i.jsx(Ds,{children:i.jsx(es,{error:e.error,onRetry:r})});const c=e.value,d=!c.previous_release_id,h=c.bump&&c.computed_bump&&c.bump!==c.computed_bump,f=c.label??c.version,m=async()=>{await navigator.clipboard.writeText(v6(f,Uc(c.changes))),l(!0)};return i.jsxs(Ds,{children:[i.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-start",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-1",children:[n?i.jsx(Y6,{release:c,onSelect:a}):i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:c.version}),i.jsx(be,{variant:"neutral",children:d?"First":c.bump}),Uc(c.changes).breaking?i.jsx(be,{variant:"error",children:"Breaking"}):null]}),i.jsxs("p",{className:"text-muted-foreground text-sm",children:["Written ",_b(c.written_at),c.written_by_name?` by ${c.written_by_name}`:"",". A Release is permanent; a correction is a new Release."]}),n&&c.batch?i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Released when production ran release batch ",i.jsx("code",{className:"font-mono",children:c.batch}),".",c.app_changed===!1?` The app's version stays ${c.app_version??c.version}.`:""]}):null,h?i.jsxs("p",{className:"text-sm",children:["Computed ",c.computed_bump,", declared ",c.bump,c.declared_by_name?` by ${c.declared_by_name}`:"",c.declared_reason?`: “${c.declared_reason}”`:"."]}):null,c.version_line?i.jsx("p",{className:"text-sm",children:c.version_line}):null,c.marks_approximate?i.jsx("p",{className:"text-muted-foreground text-xs",children:"Modeling-only marks could not all be read when it was written, so its notes may leave out a change made after a mark."}):null,d?i.jsx("p",{className:"text-muted-foreground text-xs",children:"The first Release records the starting point and lists no changes."}):c.source_judged?null:i.jsx("p",{className:"text-muted-foreground text-xs",children:"Only graph changes were judged, so code that changed without a graph change is not counted."})]}),d?null:i.jsxs(U,{variant:"outline",onClick:m,children:[i.jsx(Sv,{className:"mr-2 size-4"}),o?"Copied":"Copy notes"]})]}),n?i.jsx(X6,{release:c,org:s,onSelect:a,notes:d?null:i.jsx(Mh,{changes:c.changes})}):d?null:i.jsx(Mh,{changes:c.changes})]})}const SU=5,CU=1e4,DU=e=>e.retry===!0||e.reason==="store_locked"||e.status===503;function EU({org:e,query:t,onSelect:n,home:s}){var E;const a=Db(),{href:r,Link:o}=lt(),[l,c]=u.useState({state:"loading"}),[d,h]=u.useState(null),[f,m]=u.useState(null),[p,y]=u.useState(null),g=u.useRef(0),b=u.useRef(0),v=u.useRef(null),x=u.useRef(!1),w=u.useRef(!1),_=hb(v),S=Os(),k=u.useCallback(async(M,H=!1)=>{const z=b.current+=1;m(null);const K=await S.track(a.list(M?{fresh:!0}:void 0));if(z===b.current){if(K.ok){g.current=0,h(null);const oe=document.visibilityState==="visible"?1:0;c(re=>re.state==="ok"?H?{state:"ok",list:K.data,gen:re.gen,tick:re.tick+oe}:{state:"ok",list:K.data,gen:re.gen+1,tick:re.tick}:{state:"ok",list:K.data,gen:0,tick:0});return}if(K.refusal.reason==="engine_missing"){c({state:"engine_missing",refusal:K.refusal});return}if(g.current+=1,g.current===1&&DU(K.refusal)){w.current=H,m(K.refusal.retry_after??SU);return}h(K.refusal)}},[a,S]);u.useEffect(()=>{k(!1)},[k]);const j=u.useMemo(()=>Ff(S,()=>void k(!1,!0)),[k,S]);qi(j,CU),u.useEffect(()=>{if(f===null)return;const M=setTimeout(()=>{document.visibilityState==="visible"&&k(!1,w.current)},f*1e3);return()=>clearTimeout(M)},[f,k]),u.useEffect(()=>{var H;if(!x.current||l.state==="loading"||d||f!==null)return;x.current=!1;const M=(H=v.current)==null?void 0:H.querySelector("h1");M&&(M.tabIndex=-1,M.focus())});const N=()=>{x.current=!0,g.current=0,h(null),k(!0)},O=l.state==="ok"?l.list:null,T=t.roadmap?zo:t.planned!==null?t.planned===""?(E=O==null?void 0:O.planned)!=null&&E[0]?Ws(O.planned[0].id):null:Ws(t.planned):t.release,P=`${t.release??""}|${t.planned??""}|${t.roadmap?"roadmap":""}`,L=u.useRef(P);u.useEffect(()=>{L.current!==P&&(L.current=P,y(null))},[P]);const G=u.useRef(!1),A=u.useCallback(M=>{G.current=!0,y(M)},[]),D=!p&&l.state==="ok"&&G.current;if(u.useEffect(()=>{D&&(G.current=!1)},[D]),p)return i.jsx(Ua,{title:p.kind==="release"?`No Release ${p.id}`:`No open Planned Release ${p.id}`,description:"This project has no Release, candidate or open Planned Release by that name.",backHref:r(s),backLabel:"All Releases",link:o});const C=f!==null?i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status","aria-live":"polite",children:[i.jsx(wn,{"aria-hidden":!0})," The release records are busy; reading again in ",f," s…"]}):null,R=d?i.jsxs(me,{ref:_,variant:"destructive",children:[i.jsx(Nt,{}),i.jsx(je,{children:"Releases could not be read"}),i.jsxs(pe,{className:"flex flex-col items-start gap-2",children:[i.jsxs("span",{children:[d.message,O?" The last Releases read stays below.":""]}),i.jsx(U,{variant:"outline",size:"sm",onClick:N,children:"Try again"})]})]}):null;return i.jsx("div",{ref:v,className:"flex w-full flex-1 flex-col gap-6 px-4 py-4 sm:px-6 lg:px-8",children:l.state==="ok"?i.jsx(bU,{initial:l.list,tick:l.tick,org:e,selection:{selected:T,onSelect:n},onReadAgain:N,onNotFound:A,notice:C||R?i.jsxs(i.Fragment,{children:[C,R]}):null,focusOnMount:D},l.gen):l.state==="engine_missing"?i.jsx(ji,{page:"Releases"}):i.jsxs(i.Fragment,{children:[i.jsx(DE,{description:zE}),R??C??i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status","aria-live":"polite",children:[i.jsx(wn,{"aria-hidden":!0})," Loading Releases…"]})]})})}const AU=1e4;function eA(e){const[t,n]=u.useState(()=>e?{status:"pending"}:{status:"none"}),s=u.useRef(0),a=u.useRef(!1),r=u.useCallback(async()=>{if(!e||a.current){n({status:"none"});return}const o=++s.current;let l;try{l=await e()}catch{o===s.current&&n({status:"failed"});return}if(o!==s.current)return;if(l.ok){n({status:"ok",summary:l.data});return}const{status:c,reason:d,retry:h}=l.refusal;c===404||d==="engine_missing"?(a.current=!0,n({status:"none"})):n(f=>d==="store_locked"&&f.status==="ok"?f:{status:"failed"})},[e]);return u.useEffect(()=>{a.current=!1,r()},[r]),qi(u.useCallback(()=>void r(),[r]),AU),t}const RU={threads:"Threads",tasks:"Tasks",queues:"Queues",blockers:"Blockers",worktrees:"Worktrees",workspaces:"Workspaces",chart:"Org chart"},TU={tasks:"Tasks",issues:"Issues",releases:"Releases"};function mc(e,t){return e.kind==="home"?"Home":e.kind==="org"?RU[e.page]:e.kind==="project"?e.page?TU[e.page]:t??e.project:"Not found"}const OU="(max-width: 767px)";function zU(){const e=typeof window<"u"&&window.matchMedia?window.matchMedia(OU):null,[t,n]=u.useState((e==null?void 0:e.matches)??!1);return u.useEffect(()=>{if(!e)return;const s=()=>n(e.matches);return e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[e]),t}function ou({className:e=""}){return i.jsx("span",{"aria-hidden":"true",className:`block animate-pulse rounded-md bg-sidebar-accent ${e}`})}function P_({label:e,children:t}){return i.jsxs("span",{role:"status",className:"flex flex-col gap-1",children:[i.jsx("span",{className:"sr-only",children:e}),t]})}function tA(e){return`${e} open ${e===1?"issue":"issues"}`}const nA="ml-auto shrink-0 text-2xs font-medium tabular-nums text-muted-foreground";function MU(e,t){const n=new Map;if(e.status!=="ok")return{rows:n};const s=e.summary.projects;if(t){const a=s.reduce((r,o)=>r+o.open,0);return{header:a>0?a:void 0,rows:n}}for(const a of s)a.open>0&&n.set(a.project,a.open);return{rows:n}}function I_({item:e,collapsed:t}){const{Link:n}=lt(),s=e.icon,a=e.title??(t?e.label:void 0),r=i.jsx("span",{className:"block",children:i.jsxs(n,{href:e.href,className:"flex h-8 items-center gap-2 overflow-hidden rounded-md px-2 text-sm text-sidebar-foreground no-underline outline-hidden hover:bg-sidebar-accent hover:text-sidebar-accent-foreground focus-visible:ring-2 focus-visible:ring-sidebar-ring "+(e.current?"bg-sidebar-accent font-medium text-sidebar-accent-foreground":""),"aria-current":e.current?"page":void 0,"aria-label":t?e.label:void 0,children:[i.jsx(s,{className:"size-4 shrink-0","aria-hidden":"true"}),!t&&i.jsx("span",{className:"truncate",children:e.label}),!t&&e.open!==void 0&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"sr-only",children:` · ${tA(e.open)}`}),i.jsx("span",{"aria-hidden":"true",className:nA,children:e.open})]})]})});return i.jsx("li",{children:a?i.jsxs(kd,{children:[i.jsx(Sd,{asChild:!0,children:r}),i.jsx(ul,{side:"right",children:a})]}):r})}const G_="m-0 flex list-none flex-col gap-1 p-0";function H_({label:e,collapsed:t,children:n}){return i.jsxs("div",{className:"flex flex-col gap-1 p-2",role:"group","aria-label":e,children:[!t&&i.jsx("p",{className:"m-0 px-2 text-xs font-medium text-sidebar-foreground/70",children:e}),n]})}function V_({page:e,collapsed:t,sheet:n=!1}){var E,M;const{href:s}=lt(),{worktrees:a,blockers:r,issues:o}=Wn(),l=ss(),{org:c,projects:d,loading:h,none:f,about:m,aboutFailed:p,domains:y,engine:g}=l,b=eA(o==null?void 0:o.summary),v=MU(b,((E=c==null?void 0:c.source)==null?void 0:E.kind)==="folder"),x=g===null,w=c?`/org/${c.slug}`:"",_=d==null?void 0:d.find(H=>H.current),S=((M=c==null?void 0:c.source)==null?void 0:M.kind)==="folder"&&_!==void 0,k=H=>S&&_?`${H} · ${_.name}`:H,j=k("Workspaces"),N=k("Tasks"),O=k("Queues"),T=H=>S?H:void 0,P=[{label:"Home",href:s(w||"/"),icon:$S,current:e.kind==="home"},...x?[]:[{label:"Threads",href:s(`${w}/threads`),icon:Rc,current:e.kind==="org"&&e.page==="threads"}],...y.includes("tasks")&&!x?[{label:N,title:T(N),href:s(`${w}/tasks`),icon:mf,current:e.kind==="org"&&e.page==="tasks"}]:[],...x?[]:[{label:O,title:T(O),href:s(`${w}/queues`),icon:Ev,current:e.kind==="org"&&e.page==="queues"}],...r&&!x?[{label:"Blockers",href:s(`${w}/blockers`),icon:MS,current:e.kind==="org"&&e.page==="blockers"}]:[],...a&&!x?[{label:"Worktrees",href:s(`${w}/worktrees`),icon:Dv,current:e.kind==="org"&&e.page==="worktrees"}]:[],{label:j,title:T(j),href:s(`${w}/workspaces`),icon:zS,current:e.kind==="org"&&e.page==="workspaces"},{label:"Org chart",href:s(`${w}/chart`),icon:LS,current:e.kind==="org"&&e.page==="chart"}],L=h?null:f?"No organization":(c==null?void 0:c.name)??"Organization",G=c?qI(c):null,A=m==null?void 0:m.version,D=A?t?A:`sdlc ${A}`:p?Ch:Bf,C=p||(m==null?void 0:m.sync.state)==="unknown"?BI:m===void 0?UI:VI;let R;return h?R=i.jsx("div",{className:"px-2 py-1",children:i.jsxs(P_,{label:"Loading projects",children:[i.jsx(ou,{className:"h-4 w-32"}),i.jsx(ou,{className:"h-4 w-24"})]})}):d?R=i.jsx("ul",{className:G_,children:d.map(H=>i.jsx(I_,{collapsed:t,item:{label:H.name,title:H.name,href:s(`/proj/${encodeURIComponent(H.id)}`),icon:OS,current:e.kind==="project"&&e.project===H.id,open:v.rows.get(H.id)}},H.id))}):R=i.jsx("p",{className:"m-0 px-2 text-sm text-sidebar-foreground/70",children:f?"No projects":Ch}),i.jsxs("div",{className:"flex h-full flex-col bg-sidebar text-sidebar-foreground",children:[i.jsxs("div",{className:`flex items-center gap-2 p-2 ${n?"pr-11":""}`,role:"group","aria-label":"Current organization",children:[i.jsx("div",{className:"flex aspect-square size-8 shrink-0 items-center justify-center rounded-lg bg-sidebar-primary text-sidebar-primary-foreground",children:i.jsx(pM,{className:"size-4","aria-hidden":"true"})}),!t&&i.jsx("div",{className:"grid min-w-0 flex-1 text-left text-sm leading-tight",children:L===null?i.jsxs(P_,{label:"Loading organization",children:[i.jsx(ou,{className:"h-4 w-28"}),i.jsx(ou,{className:"h-3 w-24"})]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"truncate font-semibold",title:L,children:L}),G&&i.jsxs("span",{className:"truncate text-xs text-sidebar-foreground/70",children:[G,v.header!==void 0&&i.jsx("span",{className:"sr-only",children:` · ${tA(v.header)} in the folder`})]})]})}),!t&&L!==null&&v.header!==void 0&&i.jsx("span",{"aria-hidden":"true",className:`${nA} px-2`,children:v.header})]}),i.jsxs("nav",{"aria-label":"App",className:"min-h-0 flex-1 overflow-y-auto",children:[i.jsx(H_,{label:"Organization",collapsed:t,children:i.jsx("ul",{className:G_,children:P.map(H=>i.jsx(I_,{item:H,collapsed:t},H.label))})}),!t&&i.jsx(H_,{label:"Projects",collapsed:t,children:R})]}),m!==null&&i.jsxs("div",{className:"flex flex-col gap-1 border-t border-sidebar-border p-2 text-xs text-sidebar-foreground/70",children:[i.jsx("p",{className:"m-0 truncate px-2",title:A?`sdlc ${A}`:void 0,children:D}),!t&&i.jsxs("p",{className:"m-0 flex items-start gap-2 px-2",children:[i.jsx(HM,{className:"mt-0.5 size-4 shrink-0","aria-hidden":"true"}),i.jsx("span",{children:C})]})]})]})}const $U="outline-hidden rounded-sm focus-visible:ring-2 focus-visible:ring-ring";function LU({page:e}){var c;const{href:t,Link:n}=lt(),{org:s,projects:a,loading:r,none:o}=ss(),l=[];if(r)l.push({label:Bf});else if(o)l.push({label:"No organization"});else{const d=(s==null?void 0:s.name)??"Organization";if(l.push({label:d,href:e.kind==="home"?void 0:t(s?`/org/${s.slug}`:"/")}),e.kind==="project"){const h=((c=a==null?void 0:a.find(f=>f.id===e.project))==null?void 0:c.name)??e.project;l.push({label:h,href:e.page?t(`/proj/${encodeURIComponent(e.project)}`):void 0})}if(e.kind==="org"&&e.item!==void 0)l.push({label:mc(e),href:s?t(`/org/${s.slug}/${e.page}`):void 0}),l.push({label:e.item});else if(e.kind==="project"&&e.page&&e.item!==void 0){const h=`/proj/${encodeURIComponent(e.project)}/${e.page}${e.list_query?`?${e.list_query}`:""}`;l.push({label:mc(e),href:t(h)}),l.push({label:e.item})}else e.kind!=="home"&&!(e.kind==="project"&&!e.page)&&l.push({label:mc(e)})}return i.jsx("nav",{"aria-label":"Breadcrumb",className:"min-w-0",children:i.jsx("ol",{className:"m-0 flex min-w-0 list-none items-center gap-1.5 p-0 text-sm text-muted-foreground",children:l.map((d,h)=>i.jsxs("li",{className:"flex min-w-0 items-center gap-1.5",children:[h>0&&i.jsx(pd,{className:"size-3.5 shrink-0","aria-hidden":"true"}),d.href?i.jsx(n,{href:d.href,className:`truncate text-muted-foreground no-underline hover:text-foreground ${$U}`,children:d.label}):i.jsx("span",{className:"truncate font-normal text-foreground","aria-current":h===l.length-1?"page":void 0,children:d.label})]},`${h}-${d.label}`))})})}function PU({action:e}){const t=e.icon;return i.jsxs(kd,{children:[i.jsx(Sd,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon","aria-label":e.label,disabled:e.disabled,onClick:e.onSelect,children:i.jsx(t,{className:"size-4","aria-hidden":"true"})})}),i.jsx(ul,{side:"bottom",children:e.label})]})}function sA({page:e,headerActions:t,children:n}){var x;const s=zU(),[a,r]=u.useState(!0),[o,l]=u.useState(!1),c=u.useRef(null),d=u.useRef(null),{org:h,projects:f,loading:m,none:p}=ss(),y=e.kind==="project"?(x=f==null?void 0:f.find(w=>w.id===e.project))==null?void 0:x.name:void 0;u.useEffect(()=>{const w=m?Bf:p?"No organization":(h==null?void 0:h.name)??"Organization",_=(e.kind==="org"||e.kind==="project")&&e.item!==void 0?`${e.item} · `:"";document.title=`${_}${mc(e,y)} · ${w} · sdlc viewer`},[e,y,h,m,p]);const g=()=>{var w;l(!1),(w=c.current)==null||w.focus()};u.useEffect(()=>{s||l(!1)},[s]);const b=s&&o;u.useEffect(()=>{var S;const w=d.current;if(!b||!w)return;(S=w.querySelector("a, button"))==null||S.focus();const _=k=>{var P;if(k.key==="Escape"){l(!1),(P=c.current)==null||P.focus();return}if(k.key!=="Tab")return;const j=[...w.querySelectorAll("a[href], button:not([disabled])")];if(j.length===0)return;const N=j[0],O=j[j.length-1],T=w.contains(document.activeElement);k.shiftKey&&(document.activeElement===N||!T)?(k.preventDefault(),O.focus()):!k.shiftKey&&(document.activeElement===O||!T)&&(k.preventDefault(),N.focus())};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[b]);const v=!s&&!a;return i.jsx(ab,{children:i.jsxs("div",{className:"flex h-svh min-h-0 overflow-hidden bg-background text-foreground",children:[!s&&i.jsx("aside",{"aria-label":"Sidebar",className:`shrink-0 border-r border-sidebar-border transition-[width] ${v?"w-12":"w-64"}`,children:i.jsx(V_,{page:e,collapsed:v})}),b&&i.jsxs("div",{className:"fixed inset-0 z-50 flex",children:[i.jsxs("aside",{ref:d,role:"dialog","aria-modal":"true","aria-label":"Sidebar",className:"relative w-72 max-w-[85vw] border-r border-sidebar-border",children:[i.jsx(V_,{page:e,collapsed:!1,sheet:!0}),i.jsx("button",{type:"button","aria-label":"Close the sidebar",className:"absolute top-3 right-3 inline-flex size-7 items-center justify-center rounded-md border-0 bg-transparent text-sidebar-foreground/70 outline-hidden hover:text-sidebar-foreground focus-visible:ring-2 focus-visible:ring-ring",onClick:g,children:i.jsx(xd,{className:"size-4","aria-hidden":"true"})})]}),i.jsx("button",{type:"button",tabIndex:-1,"aria-hidden":"true",className:"flex-1 border-0 bg-black/80 outline-hidden",onClick:g})]}),i.jsxs("div",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden",children:[i.jsxs("header",{className:`flex shrink-0 items-center gap-2 border-b border-border px-4 transition-[height] ${v?"h-12":"h-16"}`,children:[i.jsx("button",{ref:c,type:"button",className:"-ml-1 inline-flex size-7 items-center justify-center rounded-md border-0 bg-transparent text-foreground outline-hidden hover:bg-accent hover:text-accent-foreground focus-visible:ring-2 focus-visible:ring-ring","aria-label":"Toggle Sidebar","aria-expanded":s?o:a,onClick:()=>s?l(w=>!w):r(w=>!w),children:i.jsx(u$,{className:"size-4","aria-hidden":"true"})}),i.jsx("span",{"aria-hidden":"true",className:"mr-2 h-4 w-px bg-border"}),i.jsx(LU,{page:e}),t&&t.length>0&&i.jsx("div",{className:"ml-auto flex shrink-0 items-center gap-1",children:t.map(w=>i.jsx(PU,{action:w},w.label))})]}),i.jsx("main",{className:"flex min-h-0 min-w-0 flex-1 flex-col overflow-x-hidden overflow-y-auto",children:n})]})]})})}const Eb="m-0 text-2xl font-semibold tracking-tight",Ab="outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",Rb=`rounded-sm font-medium text-primary no-underline hover:underline ${Ab}`;function pc({children:e}){return i.jsx("pre",{className:"m-0 overflow-x-auto rounded-md border border-border bg-muted px-3 py-2 font-mono text-sm text-foreground",children:i.jsx("code",{children:e})})}function IU({why:e}){return e.kind==="not_in_git"?i.jsxs("div",{className:"flex max-w-2xl flex-col gap-2",children:[i.jsx("p",{className:"m-0 text-sm",children:"This directory is not a Git repository. Start sdlc viewer inside one:"}),i.jsx(pc,{children:"sdlc viewer"})]}):e.kind==="unlisted"?i.jsxs("div",{className:"flex max-w-2xl flex-col gap-2",children:[i.jsx("p",{className:"m-0 text-sm",children:`This repository, ${e.repository}, points to the folder ${e.folder}, but that folder no longer lists it.`}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:"To rejoin, leave the folder here:"}),i.jsx(pc,{children:"sdlc-agents folder leave"}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:`then add it back from the folder's home repository, ${e.home}:`}),i.jsx(pc,{children:`sdlc-agents folder add ${e.member_path} --name ${e.repository}`}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:"To work in this repository alone, leaving is enough."})]}):i.jsxs("div",{className:"flex max-w-2xl flex-col gap-2",children:[i.jsx("p",{className:"m-0 text-sm",children:e.cause}),e.kind==="moved_member"&&i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:"Move this repository back to where the folder records it."}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:e.kind==="other"&&!e.fix?Dr:FI})]})}const U_=`inline-flex h-9 items-center justify-center whitespace-nowrap rounded-md border border-input bg-background px-3 font-[inherit] text-sm font-medium text-foreground transition-colors hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none disabled:opacity-50 ${Ab}`;function GU(){return i.jsxs("div",{role:"status",className:"flex flex-col gap-2",children:[i.jsx("span",{className:"sr-only",children:"Loading projects"}),[0,1,2].map(e=>i.jsx("span",{"aria-hidden":"true",className:"block h-9 animate-pulse rounded-md bg-muted"},e))]})}function gl(){const{href:e,Link:t}=lt(),{loading:n,projects:s,none:a,failure:r,readAt:o,refresh:l,reading:c}=ss(),[d,h]=u.useState(""),f=i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h1",{className:Eb,children:"Projects"}),!a&&i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:WI})]});if(a)return i.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[f,i.jsx(IU,{why:a==="not_in_git"?{kind:"not_in_git"}:ZI(a)})]});const m=r!=null&&r.shown?r:null,p=(s??[]).filter(y=>y.name.toLowerCase().includes(d.trim().toLowerCase()));return i.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[f,m&&i.jsxs("div",{role:"alert",className:"flex flex-col gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-4",children:[i.jsx("p",{className:"m-0 text-sm font-medium text-destructive",children:"The projects could not be refreshed"}),i.jsx("p",{className:"m-0 text-sm",children:ED(m.refusal,o)}),i.jsx("div",{children:i.jsx("button",{type:"button",className:U_,onClick:l,disabled:c,children:"Retry"})})]}),(s||n)&&i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx("input",{type:"search","aria-label":"Filter projects",placeholder:"Filter projects",value:d,onChange:y=>h(y.target.value),className:`h-9 w-full max-w-sm rounded-md border border-input bg-transparent px-3 font-[inherit] text-sm text-foreground placeholder:text-muted-foreground ${Ab}`}),!m&&i.jsx("button",{type:"button",className:`${U_} ml-auto`,onClick:l,disabled:c||n,children:"Refresh"})]}),r&&!r.shown&&o&&i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:`Showing the list read at ${Ul(o)}; reading again in ${r.retryInSeconds??10} seconds.`})]}),n?i.jsx(GU,{}):s&&i.jsx("div",{className:"overflow-x-auto rounded-md border border-border",children:i.jsxs("table",{className:"w-full border-collapse text-sm",children:[i.jsx("thead",{className:"border-b border-border text-left text-muted-foreground",children:i.jsxs("tr",{children:[i.jsx("th",{scope:"col",className:"h-10 px-3 font-medium",children:"Name"}),i.jsx("th",{scope:"col",className:"h-10 px-3 font-medium",children:"Location"}),i.jsx("th",{scope:"col",className:"h-10 px-3",children:i.jsx("span",{className:"sr-only",children:"Where this viewer runs"})})]})}),i.jsxs("tbody",{children:[p.map(y=>i.jsxs("tr",{className:"border-b border-border last:border-0",children:[i.jsx("td",{className:"px-3 py-2",children:i.jsx(t,{href:e(`/proj/${encodeURIComponent(y.id)}`),className:Rb,children:y.name})}),i.jsx("td",{className:"px-3 py-2 font-mono text-muted-foreground",children:y.location??Ch}),i.jsx("td",{className:"px-3 py-2 text-right",children:y.current&&i.jsx("span",{className:"inline-flex items-center rounded-md border border-border px-2 py-0.5 text-xs font-medium",children:"This repository"})})]},y.id)),p.length===0&&i.jsx("tr",{children:i.jsx("td",{colSpan:3,className:"px-3 py-6 text-center text-muted-foreground",children:"No projects found."})})]})]})})]})}function iA({title:e,children:t,more:n}){const{href:s,Link:a}=lt();return i.jsx("div",{className:"p-6",children:i.jsxs("div",{className:"flex max-w-xl flex-col gap-2 rounded-xl border border-border bg-card p-6 text-card-foreground",children:[i.jsx("h1",{className:Eb,children:e}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:t}),n&&i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:n}),i.jsx("div",{children:i.jsx(a,{href:s("/"),className:`text-sm ${Rb}`,children:"Back to the organization's Home"})})]})})}const HU={tasks:"Tasks",issues:"Issues",releases:"Releases"},VU="This release of the viewer has no page that browses the graph. Read it in a terminal:";function Wc({project:e}){const{href:t,Link:n}=lt(),{org:s,projects:a,loading:r,domains:o}=ss(),l=a==null?void 0:a.find(c=>c.id===e);return r?i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:Bf}):a?l?i.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h1",{className:Eb,children:l.name}),i.jsx("p",{className:"m-0 font-mono text-sm text-muted-foreground",children:l.location??Ch})]}),l.current?o.length>0?i.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0 text-sm",children:o.map(c=>i.jsx("li",{children:i.jsx(n,{href:t(c==="tasks"?`${s?`/org/${s.slug}`:""}/tasks`:`/proj/${encodeURIComponent(l.id)}/${c}`),className:Rb,children:HU[c]})},c))}):null:i.jsx("p",{className:"m-0 max-w-2xl text-sm text-muted-foreground",children:`This viewer reads ${l.name}'s tasks, issues and Releases only from its own checkout: open it with sdlc viewer there.`}),i.jsxs("section",{"aria-labelledby":"project-graph",className:"flex max-w-2xl flex-col gap-2",children:[i.jsx("h2",{id:"project-graph",className:"m-0 text-lg font-semibold",children:"Graph"}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:VU}),i.jsx(pc,{children:"sdlc workspace find <words>"}),i.jsx(pc,{children:"sdlc workspace show <id>"})]})]}):i.jsx(iA,{title:"Project not found",children:`There is no project '${e}' in this organization.`}):i.jsx(gl,{})}const Dd=e=>e instanceof Error?e.message:String(e);async function Xi(e){await e.text().catch(()=>{})}async function aA(e=!1){try{const t=await fetch(e?"api/threads?archived=1":"api/threads",{cache:"no-store"});return t.status===404?(await Xi(t),{none:!0}):t.ok?{data:await t.json()}:{error:await t.text()||`HTTP ${t.status}`}}catch(t){return{error:Dd(t)}}}async function UU(){var e;try{const t=await fetch("api/release-links?threads",{cache:"no-store"});if(!t.ok)return await Xi(t),null;const n=await t.json(),s=(e=n==null?void 0:n.panel)==null?void 0:e.threads;if(!s||typeof s!="object"||Array.isArray(s))return null;const a={};for(const[r,o]of Object.entries(s)){const l=(Array.isArray(o)?o:[]).filter(c=>!!c&&typeof c.planned_release=="string"&&typeof c.name=="string"&&typeof c.level=="string");l.length&&(a[r]=l)}return a}catch{return null}}async function BU(){try{return(await fetch("api/pin",{method:"HEAD",cache:"no-store"})).ok}catch{return!1}}async function WU(){try{const e=await fetch("api/sessions",{cache:"no-store"});if(!e.ok)return await Xi(e),null;const t=await e.json();return!t||typeof t.idle_over!="number"||!Array.isArray(t.sessions)?null:{idle_over:t.idle_over,memory_mb:Number(t.memory_mb)||0,sessions:t.sessions}}catch{return null}}async function FU(){try{const e=await fetch("api/sessions-release",{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:"{}"});if(!e.ok)return{error:await e.text()||`HTTP ${e.status}`};const t=await e.json();return{done:{released:t.released??[],kept:t.kept??[]}}}catch(e){return{error:Dd(e)}}}async function rA(e,t){try{const n=await fetch("api/threads/open",{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e,reopen:t})}),s=await n.text();let a={};try{a=JSON.parse(s)??{}}catch{}return n.ok?{done:a}:{refused:{reason:typeof a.reason=="string"?a.reason:"failed",error:typeof a.error=="string"?a.error:s||`HTTP ${n.status}`,...typeof a.where=="string"&&a.where?{where:a.where}:{}}}}catch(n){return{refused:{reason:"failed",error:Dd(n)}}}}async function qU(){try{return(await fetch("api/threads/archive",{method:"HEAD",cache:"no-store"})).ok}catch{return!1}}async function YU(e){const t=await e.text();try{const n=JSON.parse(t);if(typeof(n==null?void 0:n.error)=="string"&&n.error)return n.error}catch{}return t||`HTTP ${e.status}`}async function XU(e){try{const t=await fetch(`api/threads/archive?key=${encodeURIComponent(e)}`,{cache:"no-store"});if(!t.ok)return await Xi(t),null;const n=await t.json();return typeof(n==null?void 0:n.detail)=="string"&&n.detail?{detail:n.detail,failed:n.failed===!0}:null}catch{return null}}async function KU(e,t){try{const n=await fetch("api/threads/archive",{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e,on:t})});return n.ok?(await Xi(n),null):await YU(n)}catch(n){return Dd(n)}}async function ZU(e,t){try{const n=await fetch("api/pin",{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify({key:e,on:t})});return n.ok?(await Xi(n),null):await n.text()||`HTTP ${n.status}`}catch(n){return Dd(n)}}const QU={probe:{source:async()=>{const e=await aA();if("error"in e)throw new Error(e.error);return{label:"Local workspace"}}}},Iu={href:e=>e.replace(/^\/+/,"")||"./",Link:({href:e,className:t,children:n,...s})=>i.jsx("a",{href:e,className:t,...s,children:n})},JU={label:"Local viewer",can:()=>!1};function eB(){return u.useEffect(()=>{document.title="Shared app UI · SDLC Workspace Viewer"},[]),i.jsx("div",{className:"app-ui dark",children:i.jsx(Wg,{data:QU,router:Iu,identity:JU,children:i.jsx(HI,{})})})}const B_="Who waits on whom among the threads here, the threads that hold up the most first. Waits in a queue and waits on you are counted apart.",Gu=15,tB="New waits that would close a loop are refused. One thread hands its part over or asks the user.",nB="Threads in line for a queue are on Queues; threads that wait on you are marked Needs you on Threads.";function sB(){const e=Wn().blockers;if(!e)throw new Error("The Blockers page rendered without the blockers seam.");return e}const xr=(e,t,n)=>`${e} ${e===1?t:n}`;function ix(e){const t=Math.max(0,Math.round(e*60));if(t<60)return`${t}m`;if(t<24*60){const n=t%60;return n?`${Math.floor(t/60)}h ${n}m`:`${Math.floor(t/60)}h`}return`${Math.floor(t/(24*60))}d`}function iB(e,t){return t?e===null?`Not reading · trying again every ${Gu}s`:`Not reading since ${Zn(e/1e3)} · trying again every ${Gu}s`:e===null?"Connecting…":`Live · read ${Zn(e/1e3)} · refreshes every ${Gu}s`}function aB(e){var n;if(e.carried_by)return`taken over by ${e.carried_by.title}`;if(e.finished)return"finished";const t=[];return(n=e.queued)!=null&&n.length&&t.push(`in the ${e.queued.join(" and ")} queue`),e.asks_user&&t.push("asks you"),e.phase&&t.push(e.phase),e.quiet&&e.heard_hours!==null?t.push(`quiet ${ix(e.heard_hours)}`):e.heard_hours!==null&&t.push(`heard ${ix(e.heard_hours)} ago`),t.join(" · ")}function rB(e){const t=new Map(e.threads.map(r=>[r.thread,r.title])),n=r=>t.get(r)??r,s=e.holds.length?[...new Set(e.holds.map(r=>`${n(r.waiter)} waits on ${n(r.on)}`))]:e.threads.map((r,o)=>`${r.title} waits on ${e.threads[(o+1)%e.threads.length].title}`),a=s.pop()??"";return`Wait loop: ${s.length?`${s.join(", ")}, and ${a}`:a}`}function oB(e,t){const n=xr(e.blocked_threads,"thread waits","threads wait"),s=`in ${xr(t,"wait loop","wait loops")}`;return e.blockers?`${n} on ${xr(e.blockers,"blocker","blockers")}${t?` and ${s}`:""}`:`${n} ${s}`}const lB=e=>e.replace(/\s*\(status release\)$/,"");function cB({org:e}){const t=sB(),n=is(),[s,a]=u.useState(null),[r,o]=u.useState(null),l=Os(),c=u.useRef(0),d=u.useCallback(async p=>{const y=c.current+=1,g=await l.track(t.report(p?{fresh:!0}:void 0));y===c.current&&(g.ok?(a(g.data),o(null)):o(g.refusal))},[t,l]);u.useEffect(()=>{d(!1)},[d]);const h=u.useMemo(()=>Ff(l,()=>void d(!1)),[d,l]);if(qi(h,Gu*1e3),(r==null?void 0:r.reason)==="engine_missing")return i.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(ji,{page:"Blockers"})});if((r==null?void 0:r.reason)==="view_outdated")return i.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:[i.jsx(_n,{title:"Blockers",description:B_}),i.jsxs(me,{variant:"warning",className:"mt-6",children:[i.jsx(Nt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:Lr}),i.jsx(pe,{children:n})]})]});const f=(s==null?void 0:s.read_at)??null,m=r??(s!=null&&s.stale?{status:200,message:s.stale.message,reason:s.stale.reason}:null);return i.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:[i.jsx(_n,{title:"Blockers",description:B_}),i.jsx("p",{className:"text-muted-foreground mt-1 text-xs",children:iB(f,m!==null)}),!s&&!r?i.jsx(dB,{}):null,m?i.jsx(uB,{refusal:m,on_retry:()=>void d(!0)}):null,s?i.jsx(hB,{org:e,report:s,stale:m!==null}):null]})}function dB(){return i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading blockers",children:Array.from({length:3},(e,t)=>i.jsx(Tt,{className:t===2?"h-10 w-2/3":"h-10 w-full"},t))})}function uB({refusal:e,on_retry:t}){const n=i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"});return e.reason==="store_locked"?i.jsxs(me,{variant:"info",className:"mt-4",children:[i.jsx(pn,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:"The local stores are busy"}),i.jsxs(pe,{children:[i.jsx("p",{children:e.message}),n]})]}):i.jsxs(me,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:"Blockers could not be read"}),i.jsxs(pe,{children:[i.jsx("p",{children:e.message||"The read did not answer. Try again in a moment."}),n]})]})}function Jf(e){const{href:t,Link:n}=lt(),s=e?`/org/${encodeURIComponent(e)}`:"";return{href:a=>t(`${s}${a}`),name:(a,r="text-primary hover:underline")=>a.thread.startsWith("exec-")?i.jsx("span",{children:a.title}):i.jsx(n,{className:r,href:t(`${s}/threads#thread-${encodeURIComponent(a.thread)}`),children:a.title}),Link:n}}function hB({org:e,report:t,stale:n}){const{href:s,Link:a}=Jf(e),{summary:r}=t,o=n?` · last read ${Zn(t.read_at/1e3)}`:"",l=Object.entries(t.queue_waits).filter(([,d])=>d>0),c=r.blocked_threads>0||t.loops.length>0;return i.jsxs(i.Fragment,{children:[i.jsx("div",{role:"status","aria-live":"polite",children:c?i.jsx("p",{className:"text-muted-foreground mt-4 text-sm",children:`${oB(r,t.loops.length)}${o}`}):i.jsxs("div",{className:"mt-2 flex flex-col gap-1",children:[i.jsx("p",{className:"text-sm font-medium",children:"Nothing is blocked"}),i.jsxs("p",{className:"text-muted-foreground text-xs",children:[nB,o]})]})}),t.loops.map(d=>i.jsx(fB,{org:e,loop:d},d.threads.map(h=>h.thread).join("|"))),t.blockers.length?i.jsxs("section",{className:"mt-4 flex flex-col gap-3","aria-labelledby":"biggest-blockers",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{id:"biggest-blockers",className:"text-lg font-semibold",children:"Biggest blockers"}),i.jsx(be,{variant:"neutral",children:t.blockers.length})]}),t.blockers.map(d=>i.jsx(pB,{org:e,card:d},d.thread))]}):null,t.user_waits>0||l.length?i.jsxs("div",{className:"mt-6 flex flex-col gap-2 text-sm",children:[t.user_waits>0?i.jsxs("p",{className:"flex flex-wrap items-baseline gap-x-2",children:[i.jsx("span",{className:"text-warning",children:`Waiting on you: ${xr(t.user_waits,"thread","threads")}`}),i.jsx(a,{className:"text-primary hover:underline",href:s("/threads"),children:"Open Threads"})]}):null,l.map(([d,h])=>i.jsxs("p",{className:"flex flex-wrap items-baseline gap-x-2",children:[i.jsx("span",{className:"text-muted-foreground",children:d==="main"?`In line to land: ${xr(h,"thread","threads")} in the main queue`:`In line for ${d}: ${xr(h,"thread","threads")} in the ${d} queue`}),i.jsx(a,{className:"text-primary hover:underline",href:s(`/queues?queue=${encodeURIComponent(d)}`),children:`Open the ${d} queue`})]},d))]}):null]})}function fB({org:e,loop:t}){const{href:n,Link:s}=Jf(e),a=mB(t.waiters);return i.jsxs("div",{className:"mt-4 flex flex-col gap-3",children:[i.jsxs(me,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:rB(t)}),i.jsxs(pe,{children:[i.jsx("p",{children:tB}),i.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:t.threads.map(r=>r.thread.startsWith("exec-")?null:i.jsx(U,{asChild:!0,variant:"outline",size:"sm",className:"h-auto min-h-8 whitespace-normal text-left no-underline",children:i.jsx(s,{href:n(`/threads#thread-${encodeURIComponent(r.thread)}`),children:`Open ${r.title}`})},r.thread))})]})]}),a?i.jsxs("div",{className:"flex flex-col gap-3",children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:`Behind the loop: ${xr(a,"thread","threads")}`}),i.jsx(Tb,{org:e,waiters:t.waiters})]}):null]})}const mB=e=>new Set(function t(n){return n.flatMap(s=>[s.thread,...t(s.waiters??[])])}(e)).size;function pB({org:e,card:t}){const{name:n}=Jf(e),s=aB(t.state);return i.jsxs(wt,{className:"flex flex-col gap-1 p-4","data-testid":"blockers-card",children:[i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[i.jsx("h3",{className:"min-w-0 text-sm font-semibold break-words",children:n(t)}),i.jsx(be,{variant:"neutral",children:`blocks ${t.weight}`})]}),s?i.jsx("p",{className:"text-muted-foreground text-xs",children:s}):null,i.jsx("p",{className:"text-muted-foreground text-xs font-medium",children:`Clears when ${lB(t.clears)}`}),i.jsx("div",{className:"mt-1",children:i.jsx(Tb,{org:e,waiters:t.waiters})})]})}function Tb({org:e,waiters:t,via:n}){const{name:s}=Jf(e);return i.jsx("ul",{className:"border-border m-0 flex list-none flex-col gap-3 border-l p-0 pl-4",children:t.map(a=>{var r;return i.jsxs("li",{className:"flex min-w-0 flex-col gap-1",children:[i.jsx("span",{className:"text-sm break-words",children:s(a)}),i.jsx("span",{className:"text-muted-foreground text-xs break-words whitespace-pre-line",children:`waits ${ix(a.age_hours)} · ${[n?`via ${n}`:"",a.reason.trim()].filter(Boolean).join(" · ")||"no reason given"}`}),(r=a.waiters)!=null&&r.length?i.jsx(Tb,{org:e,waiters:a.waiters,via:a.title}):null]},`${a.hold}-${a.thread}`)})})}const gB="This repository's local planning workspaces: which workspace each forked from, what this checkout's workspace may change, and the integrations and Handoffs between them. This page only reads them; sdlc workspace and sdlc integrate change them.",xB=3e4,vB="Reading the workspaces. On a plan workspace this can take a few minutes.",bB="The read failed. Details are in the terminal running sdlc viewer.",yB={active:{label:"Active",tone:"success"},closed:{label:"Closed",tone:"neutral"},clean:{label:"Clean",tone:"success"},dirty:{label:"Uncommitted changes",tone:"warning"},unreadable:{label:"Unreadable",tone:"error"},queued:{label:"Queued",tone:"info"},integrated:{label:"Integrated",tone:"success"},reconciled:{label:"Reconciled",tone:"success"},stale_head:{label:"Retrying",tone:"warning"},current:{label:"Current",tone:"neutral"},blocked_conflict:{label:"Blocked: conflict",tone:"warning"},blocked_validation:{label:"Blocked: validation error",tone:"warning"},ready:{label:"Ready",tone:"success"},applied:{label:"Applied",tone:"success"},stale_base:{label:"Stale base",tone:"warning"},applied_recovery_required:{label:"Needs recovery",tone:"warning"},unavailable:{label:"Unavailable",tone:"warning"},needs_attention:{label:"Needs attention",tone:"warning"}},wB=e=>yB[e]??{label:e,tone:"neutral"},ba=e=>e.slice(0,8),oA={human:"Human",ai:"AI"},ax=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function _B(){const e=Wn().workspaces;if(!e)throw new Error("The Workspaces page rendered without the workspaces seam.");return e}function jB(e){const t=_B(),[n,s]=u.useState(null),[a,r]=u.useState(null),[o,l]=u.useState(!1),c=u.useRef(null),d=u.useRef(!1),h=u.useRef(null),f=u.useCallback(()=>{if(h.current)return h.current;const b=(async()=>{const v=await t.overview();v.ok?(s(v.data),r(null),l(!1)):(r(v.refusal),l(!0))})().finally(()=>{h.current=null});return h.current=b,b},[t]);u.useEffect(()=>{f()},[f]),qi(()=>void f(),xB),u.useEffect(()=>{var b;d.current&&(n||a)&&(d.current=!1,(b=c.current)==null||b.focus())},[n,a]);const m=()=>{d.current=!0,f()},p=n===null&&a===null,y=n===null&&a!==null,g=n?NB(n,o):null;return i.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:[i.jsx(_n,{title:"Workspaces",description:gB,actions:i.jsxs(i.Fragment,{children:[g?i.jsx("p",{className:"text-muted-foreground text-xs",children:g}):null,i.jsxs(U,{type:"button",variant:"outline",size:"sm","aria-disabled":p||void 0,"aria-describedby":p?"workspaces-reading":void 0,className:"gap-2",onClick:p?void 0:()=>void f(),children:[i.jsx(zr,{className:"size-4","aria-hidden":"true"}),"Read again"]}),p?i.jsx("span",{id:"workspaces-reading",className:"sr-only",children:"Reading…"}):null,i.jsx("span",{className:"sr-only",role:"status","aria-live":"polite",children:n?lA(n,o):""})]})}),i.jsxs("div",{ref:c,tabIndex:-1,className:"outline-none",children:[p?i.jsx(kB,{}):null,y&&a?i.jsx(SB,{refusal:a,on_retry:m}):null,n?i.jsx(CB,{overview:n}):null]})]})}function lA(e,t){var n,s;return t||((n=e.stale)==null?void 0:n.reason)==="failed"?"a newer read failed":((s=e.stale)==null?void 0:s.reason)==="running"?"a newer read is still running":""}function NB(e,t){const n=`Read at ${Ys(new Date(e.read_at).toISOString())}`,s=lA(e,t);return s?`${n} · ${s}`:n}function kB(){return i.jsxs("div",{className:"mt-6",children:[i.jsx("div",{className:"grid gap-2",role:"status","aria-label":"Loading workspaces",children:Array.from({length:6},(e,t)=>i.jsx(Tt,{className:t===5?"h-10 w-2/3":"h-10 w-full"},t))}),i.jsx("p",{className:"text-muted-foreground mt-3 text-sm","aria-live":"polite",children:vB})]})}function SB({refusal:e,on_retry:t}){const n=e.reason==="store_locked"?ED(e,null):bB;return i.jsxs(me,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:"Could not read workspaces"}),i.jsxs(pe,{children:[i.jsx("p",{children:n}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]})}function CB({overview:e}){const{counts:t}=e,n=[ax(t.workspaces,"workspace"),`${t.active} active`,`${t.queued} queued`,`${t.blocked} blocked`].join(" · ");return i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"text-muted-foreground mt-2 text-sm",role:"status","aria-live":"polite",children:n}),i.jsxs("div",{className:"mt-4 grid gap-4 lg:grid-cols-[1.4fr_1fr]",children:[i.jsx(lu,{id:"workspaces-lineage",title:"Lineage",caption:"Each workspace under the one it forked from",children:i.jsx(DB,{rows:e.workspaces})}),i.jsx(lu,{id:"workspaces-authority",title:"Authority and resolver",caption:"What this checkout's workspace may change",children:i.jsx(EB,{authority:e.authority})})]}),i.jsx(lu,{id:"workspaces-activity",className:"mt-4",title:"Integration activity",caption:"Newest first",children:e.activity.length===0?i.jsx(W_,{children:"No integration or reconciliation attempts yet."}):i.jsx(RB,{rows:e.activity})}),i.jsx(lu,{id:"workspaces-handoffs",className:"mt-4",title:"Handoffs",children:e.handoffs.length===0?i.jsx(W_,{children:"No Handoffs prepared yet."}):i.jsx(TB,{rows:e.handoffs})})]})}function lu({id:e,title:t,caption:n,className:s,children:a}){return i.jsxs("section",{"aria-labelledby":e,className:we("min-w-0",s),children:[i.jsxs("div",{className:"mb-2 flex flex-wrap items-baseline gap-x-2",children:[i.jsx("h2",{id:e,className:"text-lg font-semibold",children:t}),n?i.jsx("span",{className:"text-muted-foreground text-sm",children:n}):null]}),a]})}const W_=({children:e})=>i.jsx("p",{className:"text-muted-foreground text-sm",children:e}),$h=({children:e,tone:t})=>i.jsx("div",{className:we("text-xs",t==="error"?"text-destructive":"text-muted-foreground"),children:e});function Fc({status:e}){const t=wB(e);return i.jsx(be,{variant:t.tone,children:t.label})}function em({label:e,children:t}){return i.jsx(wt,{role:"group","aria-label":e,tabIndex:0,className:"overflow-x-auto outline-hidden focus-visible:ring-2 focus-visible:ring-ring",children:t})}function DB({rows:e}){return i.jsx(em,{label:"Workspaces",children:i.jsxs(it,{containerClassName:"overflow-visible",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Workspace"}),i.jsx(J,{children:"Actor"}),i.jsx(J,{children:"Forked from"}),i.jsx(J,{children:"Status"}),i.jsx(J,{children:"Projection"})]})}),i.jsx(at,{children:e.map(t=>i.jsxs(ye,{"data-testid":"workspaces-row",children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-mono font-medium",children:t.short_id}),i.jsx($h,{children:t.current?`${t.path} · This checkout`:t.path}),t.projection==="unreadable"&&t.projection_error&&i.jsx($h,{children:t.projection_error})]}),i.jsx(X,{children:oA[t.actor]}),i.jsx(X,{children:t.source_id?i.jsx("span",{className:"font-mono",children:ba(t.source_id)}):i.jsx("span",{className:"text-muted-foreground",children:"No source"})}),i.jsx(X,{children:i.jsx(Fc,{status:t.status})}),i.jsx(X,{children:i.jsx(Fc,{status:t.projection})})]},t.id))})]})})}function EB({authority:e}){const t=e.resolver,n=[["Workspace",i.jsx("span",{className:"font-mono",children:ba(e.workspace_id)},"id")],["Actor",oA[e.actor]],["Own head","Writes it"]];return e.source_head==="handoff_only"&&n.push(["Source head","Only through a Handoff"]),n.push(["Git refs","Read only"]),n.push(["Remotes",e.remotes>0?`${e.remotes} named ${e.remotes===1?"remote":"remotes"}`:i.jsx("span",{className:"text-muted-foreground",children:"None"},"none")]),n.push(["Push to remotes",e.push==="human_only"?"Only a person":"Not allowed"]),n.push(["Resolver",t.state==="not_configured"?i.jsx("span",{className:"text-muted-foreground",children:"Not configured"},"resolver"):i.jsx(Fc,{status:t.state==="ready"?"ready":"needs_attention"},"resolver")]),t.state==="needs_attention"&&t.issue&&n.push(["Resolver issue",t.issue]),i.jsx(em,{label:"Authority and resolver",children:i.jsx(it,{containerClassName:"overflow-visible",children:i.jsx(at,{children:n.map(([s,a])=>i.jsxs(ye,{children:[i.jsx(J,{scope:"row",className:"text-muted-foreground font-normal",children:s}),i.jsx(X,{children:a})]},s))})})})}function AB(e){const t=[e.merge_attempts?ax(e.merge_attempts,"merge attempt"):null,e.resolver_attempts?ax(e.resolver_attempts,"resolver attempt"):null].filter(Boolean);if(t.length)return t.join(" · ");const n=e.kind==="reconciliation"?"No resolver attempts":"No merge attempts yet";return i.jsx("span",{className:"text-muted-foreground",children:n})}function RB({rows:e}){return i.jsx(em,{label:"Integration activity",children:i.jsxs(it,{containerClassName:"overflow-visible",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"Change"}),i.jsx(J,{children:"Status"}),i.jsx(J,{children:"Attempts"}),i.jsx(J,{children:"Updated"})]})}),i.jsx(at,{children:e.map((t,n)=>i.jsxs(ye,{children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-medium",children:t.kind==="integration"?`Integrate ${ba(t.child_id)} into ${ba(t.other_id)}`:`Reconcile ${ba(t.child_id)} from ${ba(t.other_id)}`}),i.jsx($h,{children:t.kind==="integration"?"Integration":"Source reconciliation"})]}),i.jsx(X,{children:i.jsx(Fc,{status:t.status})}),i.jsx(X,{children:AB(t)}),i.jsx(X,{children:zD(t.updated_at)})]},`${t.kind}-${t.child_id}-${t.other_id}-${t.updated_at}-${n}`))})]})})}function TB({rows:e}){return i.jsx(em,{label:"Handoffs",children:i.jsxs(it,{containerClassName:"overflow-visible",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{children:"From"}),i.jsx(J,{children:"To"}),i.jsx(J,{children:"Status"}),i.jsx(J,{children:"Pinned"})]})}),i.jsx(at,{children:e.map(t=>i.jsxs(ye,{children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-mono font-medium",children:ba(t.child_id)}),t.error?i.jsx($h,{children:t.error}):null]}),i.jsx(X,{className:"font-mono",children:ba(t.source_id)}),i.jsx(X,{children:i.jsx(Fc,{status:t.status})}),i.jsx(X,{children:`${t.child_commit} onto ${t.source_commit}`})]},t.id))})]})})}const F_="This machine's worktrees of this repository.",OB="Merge sends one whose thread is at rest to the main queue.",zB=3e4,MB=3e3,$B=6e5,yp=[{id:"all",label:"All",empty:"worktree"},{id:"needs",label:"Needs landing",empty:"worktree needing landing"},{id:"orphan",label:"No thread to land it",empty:"worktree with no thread to land it"},{id:"queued",label:"In a queue",empty:"queued worktree"},{id:"landed",label:"Landed",empty:"landed worktree"},{id:"decide",label:"Yours to decide",empty:"worktree yours to decide"}],zl={not_landed:{label:"Not landed",tone:"neutral"},main:{label:"On main",tone:"success"},production:{label:"In production",tone:"success"},queued:{label:"Main queue",tone:"info"},needs_you:{label:"Needs you",tone:"warning"}},LB="no thread to land it",Ob="its thread waits on you",cA="its thread is done",dA="its thread is retired",zb=e=>e.archivable&&e.cleanup==="user",PB=e=>e.queue!==null||e.merge.offered===!1&&e.merge.why==="already in a promotion queue",IB=e=>!e.merge.offered&&(e.merge.why===cA||e.merge.why.startsWith(dA)),Mb=e=>!e.merge.offered&&e.merge.why===LB||IB(e),wp=(e,t)=>t==="all"?!0:t==="decide"?zb(e):(e.landed!==null?"landed":PB(e)?"queued":Mb(e)?"orphan":"needs")===t,GB=e=>e.landed!==null?e.threads.some(t=>t.phase!=="done"):e.threads.length>0&&!Mb(e);function Hu(e){return e>=1e9?`${(e/1e9).toFixed(1)} GB`:e>=1e6?`${Math.round(e/1e6)} MB`:`${Math.max(1,Math.round(e/1e3))} KB`}function uA(e){const t=e%100,n=t>=11&&t<=13?"th":{1:"st",2:"nd",3:"rd"}[e%10]??"th";return`${e}${n}`}function HB(e){if(e===null)return"No commits";if(e<1)return"Today";const t=Math.floor(e);return t===1?"1 day ago":`${t} days ago`}const _p=e=>Ys(new Date(e*1e3).toISOString()),Fl=e=>e.charAt(0).toUpperCase()+e.slice(1);function VB(e,t){var a;const n=t.phase?Fl(t.phase):"No phase",s=e.merge;if(!s.offered&&s.why.startsWith(dA)){const r=(a=/; (.+) continues it$/.exec(s.why))==null?void 0:a[1];return r?`Retired · continued by ${r}`:"Retired"}return t.phase==="done"||!s.offered&&s.why===cA?e.landed===null?"Done · without landing this":"Done":s.offered?`${n} · at rest`:s.why.startsWith("its thread is at work")?`${n} · at work`:s.why===Ob?`${n} · waits on you`:s.why.startsWith("its session is not running")?`${n} · session not running`:n}function UB(){const e=Wn().worktrees;if(!e)throw new Error("The Worktrees page rendered without the worktrees seam.");return e}function BB({org:e}){var M,H;const t=UB(),[n,s]=u.useState(null),[a,r]=u.useState(null),[o,l]=u.useState(null),[c,d]=u.useState(!1),[h,f]=u.useState("all"),[m,p]=u.useState(""),[y,g]=u.useState({}),b=u.useRef({}),{confirm:v,confirm_dialog:x}=al(),w=u.useRef(!1),_=u.useCallback(async()=>{if(w.current)return;w.current=!0;const z=await t.list();w.current=!1,z.ok?(s(z.data),r(null)):r(z.refusal)},[t]),S=u.useCallback(async()=>{const z=await t.sizes();d(!z.ok),z.ok&&l(z.data)},[t]);u.useEffect(()=>{_(),S()},[_,S]);const k=(n==null?void 0:n.rows.some(z=>{var K,oe;return((K=z.write)==null?void 0:K.state)==="waiting"||((oe=z.write)==null?void 0:oe.state)==="running"}))??!1;qi(()=>void _(),k?MB:zB),qi(()=>void S(),$B);const j=(n==null?void 0:n.rows)??[],N=z=>o==null?void 0:o.sizes[z.path],O=j.filter(zb),T=o?O.reduce((z,K)=>z+(N(K)??0),0):null,P=j.length===0?F_:`${F_} ${OB}${O.length?` ${O.length} ${O.length===1?"is":"are"} yours to decide${T!==null?`: removing them frees about ${Hu(T)}`:""}.`:""}`,L=m.trim().toLowerCase(),G=z=>!L||[z.name,z.path,z.branch??"",...z.threads.map(K=>K.title??K.thread)].some(K=>K.toLowerCase().includes(L)),A=j.filter(z=>wp(z,h)&&G(z)).sort((z,K)=>{if(h==="decide")return(N(K)??0)-(N(z)??0);const oe=re=>GB(re)?re.merge.offered?0:1:2;return oe(z)-oe(K)||(z.idle_days??1/0)-(K.idle_days??1/0)}),D=async(z,K)=>{const oe=await(z==="merge"?t.merge(K.path):t.remove(K.path));oe.ok?g(({[K.path]:re,...ve})=>ve):g(re=>({...re,[K.path]:oe.refusal.message})),await _()},C=async z=>{if(!z.merge.offered)return;const K=z.threads.find(Ne=>Ne.thread===(z.merge.offered&&z.merge.thread)),oe=(K==null?void 0:K.title)??z.merge.thread,re=K!=null&&K.holds.length?`has ${K.holds.length} open hold(s) (${K.holds.join(", ")})`:"has no open holds",ve=z.merge.lands.by==="manager"?`on its turn the queue's merge manager, ${z.merge.lands.manager}, lands it on main`:"on its turn that thread lands it on main",ke=z.merge.caveat?`
431
431
 
432
432
  Its session could not be read: ${z.merge.caveat}. A turn it does not start passes on.`:"";await v({title:`Send ${z.name} to the main queue`,description:`This joins the main promotion queue for its thread, ${oe}, which ${re} and is told of the join. The queue checks the branch first, and ${ve}. Nothing reaches main before then.${ke}`,action_label:"Join the main queue"})&&await D("merge",z)},R=async z=>{const K=N(z);await v({title:`Remove ${z.name}?`,description:`This deletes the folder ${z.path}${K!==void 0?` and frees about ${Hu(K)}`:""}.${z.branch?` Its branch ${z.branch} stays, so its work can be checked out again,`:""} and its task records are saved first; a landed plan workspace in it is closed. It stays with you because ${z.cleanup_why[0]??"the Local systems manager leaves it to you"}. The worktree is checked again just before, and nothing is deleted if that check finds work in it.`,action_label:"Remove worktree",destructive:!0})&&(K!==void 0&&(b.current[z.path]=K),await D("remove",z))},E=async z=>{await t.dismiss(z),await _()};return(a==null?void 0:a.reason)==="engine_missing"?i.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(ji,{page:"Worktrees"})}):i.jsxs("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:[i.jsx(_n,{title:"Worktrees",description:P}),!n&&!a&&i.jsx(WB,{}),a?i.jsx(FB,{refusal:a,read_at:n==null?void 0:n.read_at,on_retry:()=>void _()}):null,n!=null&&n.stale?i.jsxs(me,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:"Could not read worktrees"}),i.jsxs(pe,{children:[i.jsxs("p",{children:[n.stale.message," This list was read at ",Ys(new Date(n.read_at).toISOString()),"."]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>void _(),children:"Retry"})]})]}):null,n==null?void 0:n.removals.map(z=>i.jsxs(me,{variant:"success",className:"mt-4",role:"status",children:[i.jsx(je,{children:b.current[z.path]!==void 0?`Removed ${z.name} and freed ${Hu(b.current[z.path])}`:`Removed ${z.name}`}),i.jsxs(pe,{children:[i.jsx("p",{children:z.branch?`Its branch ${z.branch} stays, and its records were saved.`:"Its records were saved."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>void E({removal:z.path}),children:"Dismiss"})]})]},z.path)),n&&j.length===0?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(Dv,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"Only the main checkout"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"No other worktrees. Agents make theirs in .sdlc-worktrees beside the main checkout."})]}):n?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[i.jsx(yt,{type:"search",className:"w-64","aria-label":"Search worktrees",placeholder:"Search worktrees",value:m,onChange:z=>p(z.target.value)}),i.jsxs("p",{className:"text-muted-foreground ml-auto text-xs",children:["Read at ",Ys(new Date(n.read_at).toISOString())," · rereads every 30 s"]})]}),i.jsx("div",{className:"mt-3 flex flex-wrap gap-2",role:"group","aria-label":"Worktree state",children:yp.map(z=>i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:lc,"aria-pressed":h===z.id,onClick:()=>f(z.id),children:[z.label," ",j.filter(K=>wp(K,z.id)).length]},z.id))}),A.length===0?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(xf,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No worktrees match"}),L?i.jsxs(i.Fragment,{children:[i.jsxs("p",{className:"text-muted-foreground text-sm",children:["No ",(M=yp.find(z=>z.id===h))==null?void 0:M.empty," matches “",m,"”. Clear the search to see all"," ",j.filter(z=>wp(z,h)).length,"."]}),i.jsx(U,{type:"button",variant:"outline",onClick:()=>p(""),children:"Clear search"})]}):i.jsxs("p",{className:"text-muted-foreground text-sm",children:["No ",(H=yp.find(z=>z.id===h))==null?void 0:H.empty," right now."]})]}):i.jsx(wt,{className:"mt-4 shrink-0 overflow-x-auto",children:i.jsxs(it,{containerAriaLabel:"Worktrees",className:"table-fixed",children:[i.jsx(ot,{children:i.jsxs(ye,{children:[i.jsx(J,{className:"w-[24%]",children:"Worktree"}),i.jsx(J,{className:"w-[24%]",children:"Threads"}),i.jsx(J,{className:"w-[12%]",children:"Landed"}),i.jsx(J,{className:"w-[18%]",children:"Cleanup"}),i.jsx(J,{className:"hidden w-[10%] md:table-cell",children:"Last commit"}),i.jsx(J,{className:"w-[12%] text-right",children:"Actions"})]})}),i.jsx(at,{children:A.map(z=>i.jsx(qB,{org:e,row:z,size:N(z),sizes:o!==null?"read":c?"failed":"measuring",can_write:n.can_write,sent:y[z.path],on_merge:()=>void C(z),on_remove:()=>void R(z),on_dismiss:K=>void E(K),on_clear_sent:()=>g(({[z.path]:K,...oe})=>oe)},z.path))})]})})]}):null,x]})}function WB(){return i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading worktrees",children:Array.from({length:6},(e,t)=>i.jsx(Tt,{className:t===5?"h-10 w-2/3":"h-10 w-full"},t))})}function FB({refusal:e,read_at:t,on_retry:n}){const s=is();return e.reason==="view_outdated"?i.jsxs(me,{variant:"warning",className:"mt-6",children:[i.jsx(Nt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:Lr}),i.jsx(pe,{children:s})]}):i.jsxs(me,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:"Could not read worktrees"}),i.jsxs(pe,{children:[i.jsxs("p",{children:[e.message,t?` This list was read at ${Ys(new Date(t).toISOString())}.`:""]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:n,children:"Retry"})]})]})}function cu({children:e,muted:t=!0}){return i.jsx("div",{className:we("truncate text-xs",t&&"text-muted-foreground"),title:e,children:e})}function qB({org:e,row:t,size:n,sizes:s,can_write:a,sent:r,on_merge:o,on_remove:l,on_dismiss:c,on_clear_sent:d}){const{href:h,Link:f}=lt(),m=e?`/org/${encodeURIComponent(e)}`:"",p=h(`${m}/threads`),y=h(`${m}/tasks`),g=zl[t.landed??"not_landed"],b=zb(t),v=t.write,x=(v==null?void 0:v.state)==="waiting"||(v==null?void 0:v.state)==="running",w=t.threads.find(P=>"thread"in t.merge&&P.thread===t.merge.thread)??t.threads[0],_=t.merge,S=!_.offered&&_.why===Ob,k=a&&t.landed===null&&!t.queue&&!S&&!Mb(t),j=n!==void 0?Hu(n):s==="measuring"?"Measuring size…":s==="failed"?"Size could not be read":null,N=b?{label:"Yours to decide",muted:!1,second:[j,t.cleanup_why[0]]}:t.archivable?{label:"The manager removes it",muted:!1,second:[j]}:{label:"Stays",muted:!0,second:[j,t.why[0]??null]},O=N.second.filter(Boolean).join(" · "),T=t.path.slice(0,t.path.length-t.name.length-1)||".";return i.jsxs(i.Fragment,{children:[i.jsxs(ye,{"data-testid":"worktrees-row",children:[i.jsxs(X,{children:[i.jsx("div",{className:"truncate font-medium",title:t.name,children:t.name}),i.jsx(cu,{children:t.branch??"Detached"}),T!==".sdlc-worktrees"?i.jsx(cu,{children:`in ${T}`}):null]}),i.jsx(X,{children:w?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"truncate",title:w.title??w.thread,children:w.title??w.thread}),i.jsx(cu,{children:`${VB(t,w)}${t.threads.length>1?` · ${t.threads.length-1} more`:""}`})]}):i.jsx("span",{className:"text-muted-foreground",children:"No thread"})}),i.jsx(X,{children:i.jsx(be,{variant:g.tone,children:g.label})}),i.jsxs(X,{children:[i.jsx("div",{className:we("truncate",N.muted&&"text-muted-foreground"),children:N.label}),O?i.jsx("div",{className:"hidden md:block",children:i.jsx(cu,{children:O})}):null]}),i.jsx(X,{className:"hidden md:table-cell",children:HB(t.idle_days)}),i.jsx(X,{className:"text-right",children:i.jsxs("div",{className:"flex justify-end gap-2",children:[x?i.jsx(U,{type:"button",variant:"outline",size:"sm",loading:!0,disabled:!0,children:(v==null?void 0:v.kind)==="merge"?v.state==="waiting"?"Waiting to join…":"Joining main…":(v==null?void 0:v.state)==="waiting"?"Waiting to remove…":"Removing…"}):t.queue?i.jsx(be,{variant:zl.queued.tone,children:`${zl.queued.label} · ${uA(t.queue.position)}`}):S?i.jsx(f,{href:y,"aria-label":`${t.name}: its thread waits on you, in Waiting on you`,children:i.jsx(be,{variant:zl.needs_you.tone,children:zl.needs_you.label})}):k?i.jsx(U,{type:"button",variant:"outline",size:"sm",title:_.offered?void 0:_.why,"aria-disabled":!_.offered||void 0,className:we(!_.offered&&"cursor-not-allowed opacity-50"),"aria-label":`Send ${t.name} to the main queue`,"aria-describedby":_.offered?void 0:`why-${t.name}`,onClick:_.offered?o:void 0,children:"Merge"}):null,b&&a&&!x?i.jsx(U,{type:"button",variant:"outline",size:"sm","aria-label":`Remove ${t.name}`,onClick:l,children:"Remove"}):null]})})]}),i.jsx(YB,{row:t,threads:p,tasks:y,merge_shown:k,sent:r,on_dismiss:c,on_clear_sent:d})]})}function YB({row:e,threads:t,tasks:n,merge_shown:s,sent:a,on_dismiss:r,on_clear_sent:o}){var y,g,b,v;const{Link:l}=lt(),c=(x="Open in Threads")=>i.jsx(l,{className:"text-primary text-sm hover:underline",href:t,children:x}),d=x=>i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:x,children:"Dismiss"}),h=e.write,f=e.threads.find(x=>x.thread===("thread"in e.merge?e.merge.thread:void 0))??e.threads[0],m=(f==null?void 0:f.title)??"Its thread";let p=null;if(a)p=i.jsxs(me,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:"It was not sent"}),i.jsxs(pe,{children:[i.jsx("p",{children:a}),d(o)]})]});else if((h==null?void 0:h.state)==="waiting")p=i.jsxs("p",{className:"text-muted-foreground text-sm",role:"status",children:["Another worktree's write runs first; ",e.name," ",h.kind==="merge"?"joins":"is removed"," next."]});else if((h==null?void 0:h.state)==="running")p=i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:h.kind==="merge"?`Joining the main queue for ${e.name}. The queue checks its branch first; this can take a few minutes.`:`Removing ${e.name}. It is checked again first.`});else if((h==null?void 0:h.state)==="joined"){const x=((y=h.lands)==null?void 0:y.by)==="manager"?`the merge manager, ${h.lands.manager}, lands it`:"it lands it on its turn";p=i.jsxs(me,{variant:h.told?"success":"warning",role:"status",children:[i.jsx(je,{children:`${e.name} joined the main queue, ${uA(h.position)}`}),i.jsxs(pe,{children:[i.jsx("p",{children:h.told?`${m} was left a notice, and ${x}.`:"Its thread could not be told, so it does not know its turn is coming. Tell it from Threads; the join itself is unchanged."}),((g=e.queue)==null?void 0:g.position)===1&&e.queue.turn==="next"&&e.queue.passes_at?i.jsx("p",{children:`It is first in the main queue. Its thread was left a notice but not woken: continue it in its session, or the turn passes on at ${_p(e.queue.passes_at)}.`}):null,i.jsxs("div",{className:"flex items-center gap-3",children:[d(()=>r({write:e.path})),!h.told||((b=e.queue)==null?void 0:b.position)===1?i.jsx("span",{className:"mt-2",children:c()}):null]})]})]})}else if(h&&(h.state==="refused"||h.state==="failed")){const x=h.kind==="merge"?`The main queue refused ${e.name}`:`${e.name} was not removed`;p=i.jsxs(me,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:h.kind==="merge"&&h.state==="failed"?`${e.name} did not join`:x}),i.jsxs(pe,{children:[i.jsx("p",{children:`${Fl(h.message)}${h.kind==="merge"?" Nothing was queued.":" Nothing was deleted."}`}),i.jsxs("div",{className:"flex items-center gap-3",children:[d(()=>r({write:e.path})),h.kind==="merge"?i.jsx("span",{className:"mt-2",children:c()}):null]})]})]})}else if(e.last_turn){const x=e.last_turn;p=i.jsxs(me,{variant:"warning",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(je,{children:`${e.name}'s turn ${x.outcome==="failed"?"failed":"passed on"} at ${_p(x.left_at)}`}),i.jsxs(pe,{children:[i.jsx("p",{children:`${Fl(x.reason)}. Continue the thread in its session; Merge sends it again once it is at rest.`}),i.jsxs("div",{className:"flex items-center gap-3",children:[d(()=>r({turn:{execution:x.execution,left_at:x.left_at}})),i.jsx("span",{className:"mt-2",children:c()})]})]})]})}else((v=e.queue)==null?void 0:v.position)===1&&e.queue.turn==="next"&&e.queue.passes_at?p=i.jsxs("p",{className:"text-sm",role:"status",children:[`Its turn now: ${e.name} is first in the main queue. Continue its thread in its session, or the turn passes on at ${_p(e.queue.passes_at)}. `,c()]}):!e.merge.offered&&e.merge.why===Ob?p=i.jsxs("p",{className:"text-sm",id:`why-${e.name}`,children:["Its thread waits on you. Merge comes back once you answer it. ",i.jsx(l,{className:"text-primary hover:underline",href:n,children:"In Waiting on you"})]}):!e.merge.offered&&e.merge.successor&&!e.queue&&e.landed===null?p=i.jsx("p",{className:"text-sm",children:c("Open its successor in Threads")}):s&&!e.merge.offered?p=i.jsxs("p",{className:"text-sm",id:`why-${e.name}`,children:[`${Fl(e.merge.why)}. `,e.merge.thread&&!e.merge.why.startsWith("its thread is at work")?c():null]}):e.merge.offered&&e.merge.caveat&&(p=i.jsx("p",{className:"text-muted-foreground text-sm",children:`${Fl(e.merge.caveat)}.`}));return p?i.jsx(ye,{className:"hover:bg-transparent",children:i.jsx(X,{colSpan:6,className:"pt-0",children:p})}):null}const XB=["reason","since","store","repository","folder","home","member_path"];function tm(e,t){const n={status:e,message:typeof(t==null?void 0:t.error)=="string"?t.error:"The read failed; see the sdlc viewer terminal."};(t==null?void 0:t.retry)===!0&&(n.retry=!0),typeof(t==null?void 0:t.retry_after)=="number"&&(n.retry_after=t.retry_after),typeof(t==null?void 0:t.seedable)=="boolean"&&(n.seedable=t.seedable);for(const s of XB){const a=t==null?void 0:t[s];typeof a=="string"&&(n[s]=a)}return n}function Ki({base:e="",fetcher:t=fetch}){return async(n,s={})=>{const a=new URLSearchParams;for(const[c,d]of Object.entries(s))if(Array.isArray(d))for(const h of d)a.append(c,h);else d!==void 0&&d!==!1&&d!==""&&a.set(c,String(d));const r=a.size>0?`?${a.toString()}`:"";let o;try{o=await t(`${e}api/app/${n}${r}`,{cache:"no-store"})}catch{return{ok:!1,refusal:{status:0,message:"The viewer did not answer. Is sdlc viewer still running?"}}}const l=await o.json().catch(()=>null);return o.ok?{ok:!0,data:l}:{ok:!1,refusal:tm(o.status,l)}}}function hA(e={}){const t=Ki(e);return()=>t("issues/summary")}function KB(e={}){const t=Ki(e),n=nm(e),s=JB(e),a=o=>async()=>{const l=await t("access");return l.ok?{ok:!0,data:l.data[o]}:l},r=encodeURIComponent;return{tasks:{access:a("tasks"),configuration:()=>t("tasks/configuration"),listTasks:o=>t(`tasks/lists/${r(o)}/tasks`),task:o=>t(`tasks/tasks/${r(o)}`)},issues:{access:a("issues"),list:(o={})=>t("issues",o),issue:o=>t(`issues/${r(o)}`),issueSections:o=>t(`issues/${r(o)}/sections`),issueRelated:o=>t(`issues/${r(o)}/related`),summary:hA(e),openAnchor:o=>n("open-anchor",o),report:o=>n("issue-report",o),reportCollections:()=>s("issue-collections")},releases:{access:a("releases"),list:()=>t("releases"),release:o=>t(`releases/${r(o)}`),candidate:()=>t("releases/candidate")},organizations:{access:a("organizations"),list:()=>t("orgs")},projects:{access:a("projects"),list:()=>t("projects")},about:{about:()=>t("about")}}}function ZB(e={}){const t=Ki(e),{base:n="",fetcher:s=fetch}=e;return{timing:async()=>{let r;try{r=await s(`${n}api/queues`,{cache:"no-store"})}catch{return ya("The viewer did not answer. Is sdlc viewer still running?")}const o=await r.json().catch(()=>null);return r.ok?(o==null?void 0:o.state)!=="ready"?ya(typeof(o==null?void 0:o.error)=="string"&&o.error?o.error:"The work queues could not be read."):{ok:!0,data:QB(o)}:{ok:!1,refusal:tm(r.status,o)}},listQueues:()=>t("queues"),queue:r=>t(`queues/${encodeURIComponent(r)}`),members:async()=>({ok:!0,data:[]}),refresh_ms:15e3,settings_note:"Local queue settings are the engine's built-in policies. Turns change through promote.",thread_subjects:!0,description:"Where this checkout's threads take turns: landing on main, deploying to staging, publishing and accepting the graph.",read_scope:"this checkout only",subject_label:"Thread"}}const ya=e=>({ok:!1,refusal:{status:0,message:e}}),xn=e=>typeof e=="string"&&e?e:void 0;function QB(e){const t=Array.isArray(e==null?void 0:e.cards)?e.cards:[];return{caption:xn(e==null?void 0:e.caption)??"",queues:t.map(n=>{var h,f,m;const s=Array.isArray(n.captions)?n.captions.filter(p=>typeof p=="string"):[],a=Array.isArray(n.notes)?n.notes:[],r=n.key==="heavy",o=xn((h=a.find(p=>p.kind==="memory"))==null?void 0:h.text),l=xn((f=a.find(p=>p.kind==="suite"))==null?void 0:f.text),c=l?`${l.charAt(0).toUpperCase()}${l.slice(1)}`:s.find(p=>p.startsWith("The last deploy's staging suite still runs")),d=(Array.isArray(n.rows)?n.rows:[]).map(p=>{var w;const y=Array.isArray(p.parts)?p.parts:[],g=_=>{var S;return xn((S=y.find(k=>k.kind===_))==null?void 0:S.text)},b=(xn(p.detail)??"").split(" · "),v=xn(p.estimate)??(y.length||!xn(p.estimateTitle)?void 0:b.at(-1)),x=r&&!y.length&&b.length>=4&&/^\d+(\.\d+)? GB$/.test(b[2]);return{position:typeof p.position=="number"?p.position:0,execution:xn(p.execution),key:xn(p.key),title:xn(p.title)??"",turn:xn(p.turn)??"Waiting",elapsed:g("elapsed")??b[0]??"",estimate:v??(x?b.at(-1):void 0),basis:xn(p.estimateTitle),command:xn((w=y.find(_=>_.kind==="command"))==null?void 0:w.title)??g("command")??(x?b[1]:void 0),memory:g("memory")??(x?b[2]:void 0),reason:g("reason")}});return{key:xn(n.key)??"",name:xn(n.name)??"",clears:xn(n.clears),basis:r?void 0:s[1],memory:r?(o==null?void 0:o.replace(/^memory: /,""))??((m=s[0])==null?void 0:m.split(" · ").at(-1)):void 0,suite:c,error:xn(n.error)??(r&&n.summary==="Not available"?"no answer":void 0),rows:d}})}}function JB({base:e="",fetcher:t=fetch}){return async n=>{let s;try{s=await t(`${e}api/${n}`,{cache:"no-store"})}catch{return ya("The viewer did not answer. Is sdlc viewer still running?")}const a=await s.json().catch(()=>null);return s.ok?{ok:!0,data:a}:{ok:!1,refusal:tm(s.status,a)}}}async function e5({base:e="",fetcher:t=fetch}={}){try{return(await t(`${e}api/issue-report`,{method:"HEAD",cache:"no-store"})).ok}catch{return!1}}function nm({base:e="",fetcher:t=fetch}){return async(n,s)=>{let a;try{a=await t(`${e}api/${n}`,{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)})}catch{return ya("The viewer did not answer. Is sdlc viewer still running?")}const r=await a.json().catch(()=>null);return a.ok?{ok:!0,data:r}:{ok:!1,refusal:tm(a.status,r)}}}function t5(e={}){const t=Ki(e),n=nm(e);return{chart:()=>t("org"),change:s=>n("org-change",s)}}function n5(e={}){const t=Ki(e),n=l=>`tasks/tasks/${encodeURIComponent(l)}`,{base:s="",fetcher:a=fetch}=e;return{access:async()=>{const l=await t("access");return l.ok?{ok:!0,data:l.data.tasks}:l},availability:async()=>{const l=await t("tasks/configuration");if(!l.ok)return l.refusal.reason==="engine_missing"?{state:"off",refusal:l.refusal}:{state:"error",refusal:l.refusal};const c=l.data;if(c.state!=="active")return{state:"available"};const d=c.workspaces.find(f=>f.is_default)??c.workspaces[0],h=d==null?void 0:d.lists[0];return!d||!h?{state:"error"}:{state:"active",configuration:c,workspace:d,list:h}},listTasks:(l,c={})=>{var d,h,f;return c.state==="archived"?Promise.resolve(ya("This checkout keeps no archived tasks.")):c.assigned_to_me?Promise.resolve(ya("Assigned to you is a status group here.")):t(`tasks/lists/${encodeURIComponent(l)}/tasks`,{search:c.search,owner:c.owner===""?"none":c.owner,group:c.group,urgent:c.urgent?"true":void 0,over_estimate:c.over_estimate?"true":void 0,opened:(d=c.opened_groups)!=null&&d.length?c.opened_groups.join(","):void 0,closed:(h=c.closed_groups)!=null&&h.length?c.closed_groups.join(","):void 0,all:(f=c.all_groups)!=null&&f.length?c.all_groups.join(","):void 0})},members:()=>t("tasks/members"),waitingOnYou:()=>t("tasks/waiting-on-you"),task:l=>t(n(l)),taskSections:l=>t(`${n(l)}/sections`),taskRelated:l=>t(`${n(l)}/related`),hierarchyRevision:async()=>({ok:!0,data:0}),commands:{run:async()=>ya("The local viewer changes tasks only with Done."),complete:async l=>{const c="task"in l?{task:l.task}:{hold:l.hold};let d;try{d=await a(`${s}api/task-done`,{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)})}catch{return ya("The viewer did not answer. Is sdlc viewer still running?")}if(d.ok)return await Xi(d),{ok:!0,data:null};const h=await d.text().catch(()=>"");return{ok:!1,refusal:{status:d.status,message:h||`It was not recorded (HTTP ${d.status}).`}}}}}}function s5(e={}){const t=Ki(e),n=nm(e),s=encodeURIComponent,a=r=>r!=null&&r.fresh?{fresh:1}:{};return{access:async()=>{const r=await t("access");return r.ok?{ok:!0,data:r.data.releases}:r},list:(r={})=>t("releases",a(r)),release:(r,o)=>t(`releases/${s(r)}`,a(o)),candidate:r=>t("releases/candidate",a(r)),candidateBatch:r=>t("releases/candidate/batch",a(r)),related:(r,o)=>t(`releases/${s(r)}/related`,a(o)),plannedRelease:(r,o)=>t(`releases/planned/${s(r)}`,a(o)),roadmap:r=>t("releases/roadmap",{...a(r),...r!=null&&r.mine?{mine:1}:{}}),roadmapMoved:r=>t("releases/roadmap/moved",a(r)),roadmapSeen:r=>n("roadmap/seen",{at:r}),decideAcceptance:r=>n("releases/acceptance",r),editNote:r=>n("releases/note-edit",r)}}function i5(e={}){const t=Ki(e),n=nm(e);return{list:()=>t("worktrees"),sizes:()=>t("worktree-sizes"),merge:s=>n("worktree-merge",{path:s}),remove:s=>n("worktree-remove",{path:s}),dismiss:s=>n("worktree-dismiss",s)}}function a5(e={}){const t=Ki(e);return{report:n=>t("blockers",n!=null&&n.fresh?{fresh:1}:{})}}function r5(e={}){const t=Ki(e);return{overview:()=>t("workspaces")}}class fA{}class Ta extends fA{constructor(t,n,s){super(),this.viewId=t,this.groupId=n,this.panelId=s}}class gc extends fA{constructor(t,n){super(),this.viewId=t,this.paneId=n}}class vi{constructor(){}static getInstance(){return vi.INSTANCE}hasData(t){return t&&t===this.proto}clearData(t){this.hasData(t)&&(this.proto=void 0,this.data=void 0)}getData(t){if(this.hasData(t))return this.data}setData(t,n){n&&(this.data=t,this.proto=n)}}vi.INSTANCE=new vi;function En(){const e=vi.getInstance();if(e.hasData(Ta.prototype))return e.getData(Ta.prototype)[0]}function Ml(){const e=vi.getInstance();if(e.hasData(gc.prototype))return e.getData(gc.prototype)[0]}var vr;(function(e){e.any=(...t)=>n=>{const s=t.map(a=>a(n));return{dispose:()=>{s.forEach(a=>{a.dispose()})}}}})(vr||(vr={}));class $b{constructor(){this._defaultPrevented=!1}get defaultPrevented(){return this._defaultPrevented}preventDefault(){this._defaultPrevented=!0}}class mA{constructor(){this._isAccepted=!1}get isAccepted(){return this._isAccepted}accept(){this._isAccepted=!0}}class o5{constructor(){this.events=new Map}get size(){return this.events.size}add(t,n){this.events.set(t,n)}delete(t){this.events.delete(t)}clear(){this.events.clear()}}class Lh{static create(){var t;return new Lh((t=new Error().stack)!==null&&t!==void 0?t:"")}constructor(t){this.value=t}print(){console.warn("dockview: stacktrace",this.value)}}class l5{constructor(t,n){this.callback=t,this.stacktrace=n}}class te{static setLeakageMonitorEnabled(t){t!==te.ENABLE_TRACKING&&te.MEMORY_LEAK_WATCHER.clear(),te.ENABLE_TRACKING=t}get value(){return this._last}constructor(t){this.options=t,this._listeners=[],this._disposed=!1}get event(){return this._event||(this._event=t=>{var n;!((n=this.options)===null||n===void 0)&&n.replay&&this._last!==void 0&&t(this._last);const s=new l5(t,te.ENABLE_TRACKING?Lh.create():void 0);return this._listeners.push(s),{dispose:()=>{const a=this._listeners.indexOf(s);a>-1&&this._listeners.splice(a,1)}}},te.ENABLE_TRACKING&&te.MEMORY_LEAK_WATCHER.add(this._event,Lh.create())),this._event}fire(t){var n;!((n=this.options)===null||n===void 0)&&n.replay&&(this._last=t);for(const s of this._listeners)s.callback(t)}dispose(){this._disposed||(this._disposed=!0,this._listeners.length>0&&(te.ENABLE_TRACKING&&queueMicrotask(()=>{var t;for(const n of this._listeners)console.warn("dockview: stacktrace",(t=n.stacktrace)===null||t===void 0?void 0:t.print())}),this._listeners=[]),te.ENABLE_TRACKING&&this._event&&te.MEMORY_LEAK_WATCHER.delete(this._event))}}te.ENABLE_TRACKING=!1;te.MEMORY_LEAK_WATCHER=new o5;function Fe(e,t,n,s){return e.addEventListener(t,n,s),{dispose:()=>{e.removeEventListener(t,n,s)}}}class q_{constructor(){this._onFired=new te,this._currentFireCount=0,this._queued=!1,this.onEvent=t=>{const n=this._currentFireCount;return this._onFired.event(()=>{this._currentFireCount>n&&t()})}}fire(){this._currentFireCount++,!this._queued&&(this._queued=!0,queueMicrotask(()=>{this._queued=!1,this._onFired.fire()}))}dispose(){this._onFired.dispose()}}var Zt;(function(e){e.NONE={dispose:()=>{}};function t(n){return{dispose:()=>{n()}}}e.from=t})(Zt||(Zt={}));class Ge{get isDisposed(){return this._isDisposed}constructor(...t){this._isDisposed=!1,this._disposables=t}addDisposables(...t){t.forEach(n=>this._disposables.push(n))}dispose(){this._isDisposed||(this._isDisposed=!0,this._disposables.forEach(t=>t.dispose()),this._disposables=[])}}class On{constructor(){this._disposable=Zt.NONE}set value(t){this._disposable&&this._disposable.dispose(),this._disposable=t}dispose(){this._disposable&&(this._disposable.dispose(),this._disposable=Zt.NONE)}}class c5 extends Ge{constructor(t){super(),this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._value=null,this.addDisposables(this._onDidChange,sm(t,n=>{const s=n.target.scrollWidth>n.target.clientWidth,a=n.target.scrollHeight>n.target.clientHeight;this._value={hasScrollX:s,hasScrollY:a},this._onDidChange.fire(this._value)}))}}function sm(e,t){const n=new ResizeObserver(s=>{requestAnimationFrame(()=>{const a=s[0];t(a)})});return n.observe(e),{dispose:()=>{n.unobserve(e),n.disconnect()}}}const qc=(e,...t)=>{for(const n of t)e.classList.contains(n)&&e.classList.remove(n)},im=(e,...t)=>{for(const n of t)e.classList.contains(n)||e.classList.add(n)},Pe=(e,t,n)=>{const s=e.classList.contains(t);n&&!s&&e.classList.add(t),!n&&s&&e.classList.remove(t)};function rx(e,t){for(;e;){if(e===t)return!0;e=e.parentNode}return!1}function pA(e){return new d5(e)}class d5 extends Ge{constructor(t){super(),this._onDidFocus=new te,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new te,this.onDidBlur=this._onDidBlur.event,this.addDisposables(this._onDidFocus,this._onDidBlur);let n=rx(document.activeElement,t),s=!1;const a=()=>{s=!1,n||(n=!0,this._onDidFocus.fire())},r=()=>{n&&(s=!0,window.setTimeout(()=>{s&&(s=!1,n=!1,this._onDidBlur.fire())},0))};this._refreshStateHandler=()=>{rx(document.activeElement,t)!==n&&(n?r():a())},this.addDisposables(Fe(t,"focus",a,!0)),this.addDisposables(Fe(t,"blur",r,!0))}refreshState(){this._refreshStateHandler()}}const gA="dv-quasiPreventDefault";function u5(e){e[gA]=!0}function Y_(e){return e[gA]}function h5(e,t){const n=Array.from(t);for(const s of n){if(s.href){const r=e.createElement("link");r.href=s.href,r.type=s.type,r.rel="stylesheet",e.head.appendChild(r)}let a=[];try{s.cssRules&&(a=Array.from(s.cssRules).map(r=>r.cssText))}catch{}for(const r of a){const o=e.createElement("style");o.appendChild(e.createTextNode(r)),e.head.appendChild(o)}}}function ox(e){const{left:t,top:n,width:s,height:a}=e.getBoundingClientRect();return{left:t+window.scrollX,top:n+window.scrollY,width:s,height:a}}function f5(e){let t=e;for(;t!=null&&t.parentNode;){if(t.parentNode===document)return!0;t.parentNode instanceof DocumentFragment?t=t.parentNode.host:t=t.parentNode}return!1}function m5(e,t){e.setAttribute("data-testid",t)}function p5(e){const t=[];function n(s){if(s.nodeType===Node.ELEMENT_NODE){e.includes(s.tagName)&&t.push(s),s.shadowRoot&&n(s.shadowRoot);for(const a of s.children)n(a)}}return n(document.documentElement),t}function Ph(e=document){const t=p5(["IFRAME","WEBVIEW"]),n=new WeakMap;for(const s of t)n.set(s,s.style.pointerEvents),s.style.pointerEvents="none";return{release:()=>{var s;for(const a of t)a.style.pointerEvents=(s=n.get(a))!==null&&s!==void 0?s:"auto";t.splice(0,t.length)}}}function g5(e){function t(a){const r=[];for(let o=0;o<a.classList.length;o++)r.push(a.classList.item(o));return r}let n,s=e;for(;s!==null&&(n=t(s).find(a=>a.startsWith("dockview-theme-")),typeof n!="string");)s=s.parentElement;return n}class am{constructor(t){this.element=t,this._classNames=[]}setClassNames(t){for(const n of this._classNames)Pe(this.element,n,!1);this._classNames=t.split(" ").filter(n=>n.trim().length>0);for(const n of this._classNames)Pe(this.element,n,!0)}}const xA=100;function x5(e,t){const n=ox(e),s=ox(t);return!(n.left<s.left||n.left+n.width>s.left+s.width)}function v5(e){const t=new te;let n=e.screenX,s=e.screenY,a;const r=()=>{if(e.closed)return;const o=e.screenX,l=e.screenY;(o!==n||l!==s)&&(clearTimeout(a),a=setTimeout(()=>{t.fire()},xA),n=o,s=l),requestAnimationFrame(r)};return r(),t}function b5(e,t){let n;return new Ge(Fe(e,"resize",()=>{clearTimeout(n),n=setTimeout(()=>{t()},xA)}))}function y5(e,t,n={buffer:10}){const s=n.buffer,a=e.getBoundingClientRect(),r=t.getBoundingClientRect();let o=0,l=0;const c=a.left-r.left,d=a.top-r.top,h=a.bottom-r.bottom,f=a.right-r.right;c<s?o=s-c:f>s&&(o=-s-f),d<s?l=s-d:h>s&&(l=-h-s),(o!==0||l!==0)&&(e.style.transform=`translate(${o}px, ${l}px)`)}function w5(e){let t=e;for(;t&&(t.style.zIndex==="auto"||t.style.zIndex==="");)t=t.parentElement;return t}function Pi(e){if(e.length===0)throw new Error("Invalid tail call");return[e.slice(0,e.length-1),e[e.length-1]]}function vA(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function jp(e,t){const n=e.indexOf(t);n>-1&&(e.splice(n,1),e.unshift(t))}function du(e,t){const n=e.indexOf(t);n>-1&&(e.splice(n,1),e.push(t))}function _5(e,t){for(let n=0;n<e.length;n++){const s=e[n];if(t(s))return n}return-1}function Np(e,t){const n=e.findIndex(s=>s===t);return n>-1?(e.splice(n,1),!0):!1}const Rt=(e,t,n)=>t>n?t:Math.min(n,Math.max(e,t)),Lb=()=>{let e=1;return{next:()=>(e++).toString()}},Ps=(e,t)=>{const n=[];if(typeof t!="number"&&(t=e,e=0),e<=t)for(let s=e;s<t;s++)n.push(s);else for(let s=e;s>t;s--)n.push(s);return n};class j5{set size(t){this._size=t}get size(){return this._size}get cachedVisibleSize(){return this._cachedVisibleSize}get visible(){return typeof this._cachedVisibleSize>"u"}get minimumSize(){return this.visible?this.view.minimumSize:0}get viewMinimumSize(){return this.view.minimumSize}get maximumSize(){return this.visible?this.view.maximumSize:0}get viewMaximumSize(){return this.view.maximumSize}get priority(){return this.view.priority}get snap(){return!!this.view.snap}set enabled(t){this.container.style.pointerEvents=t?"":"none"}constructor(t,n,s,a){this.container=t,this.view=n,this.disposable=a,this._cachedVisibleSize=void 0,typeof s=="number"?(this._size=s,this._cachedVisibleSize=void 0,t.classList.add("visible")):(this._size=0,this._cachedVisibleSize=s.cachedVisibleSize)}setVisible(t,n){var s;t!==this.visible&&(t?(this.size=Rt((s=this._cachedVisibleSize)!==null&&s!==void 0?s:0,this.viewMinimumSize,this.viewMaximumSize),this._cachedVisibleSize=void 0):(this._cachedVisibleSize=typeof n=="number"?n:this.size,this.size=0),this.container.classList.toggle("visible",t),this.view.setVisible&&this.view.setVisible(t))}dispose(){return this.disposable.dispose(),this.view}}var Me;(function(e){e.HORIZONTAL="HORIZONTAL",e.VERTICAL="VERTICAL"})(Me||(Me={}));var ys;(function(e){e[e.MAXIMUM=0]="MAXIMUM",e[e.MINIMUM=1]="MINIMUM",e[e.DISABLED=2]="DISABLED",e[e.ENABLED=3]="ENABLED"})(ys||(ys={}));var sn;(function(e){e.Low="low",e.High="high",e.Normal="normal"})(sn||(sn={}));var Es;(function(e){e.Distribute={type:"distribute"};function t(s){return{type:"split",index:s}}e.Split=t;function n(s){return{type:"invisible",cachedVisibleSize:s}}e.Invisible=n})(Es||(Es={}));class Yc{get contentSize(){return this._contentSize}get size(){return this._size}set size(t){this._size=t}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(t){this._orthogonalSize=t}get length(){return this.viewItems.length}get proportions(){return this._proportions?[...this._proportions]:void 0}get orientation(){return this._orientation}set orientation(t){this._orientation=t;const n=this.size;this.size=this.orthogonalSize,this.orthogonalSize=n,qc(this.element,"dv-horizontal","dv-vertical"),this.element.classList.add(this.orientation==Me.HORIZONTAL?"dv-horizontal":"dv-vertical")}get minimumSize(){return this.viewItems.reduce((t,n)=>t+n.minimumSize,0)}get maximumSize(){return this.length===0?Number.POSITIVE_INFINITY:this.viewItems.reduce((t,n)=>t+n.maximumSize,0)}get startSnappingEnabled(){return this._startSnappingEnabled}set startSnappingEnabled(t){this._startSnappingEnabled!==t&&(this._startSnappingEnabled=t,this.updateSashEnablement())}get endSnappingEnabled(){return this._endSnappingEnabled}set endSnappingEnabled(t){this._endSnappingEnabled!==t&&(this._endSnappingEnabled=t,this.updateSashEnablement())}get disabled(){return this._disabled}set disabled(t){this._disabled=t,Pe(this.element,"dv-splitview-disabled",t)}get margin(){return this._margin}set margin(t){this._margin=t,Pe(this.element,"dv-splitview-has-margin",t!==0)}constructor(t,n){var s,a;this.container=t,this.viewItems=[],this.sashes=[],this._size=0,this._orthogonalSize=0,this._contentSize=0,this._proportions=void 0,this._startSnappingEnabled=!0,this._endSnappingEnabled=!0,this._disabled=!1,this._margin=0,this._onDidSashEnd=new te,this.onDidSashEnd=this._onDidSashEnd.event,this._onDidAddView=new te,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new te,this.onDidRemoveView=this._onDidRemoveView.event,this.resize=(r,o,l=this.viewItems.map(y=>y.size),c,d,h=Number.NEGATIVE_INFINITY,f=Number.POSITIVE_INFINITY,m,p)=>{if(r<0||r>this.viewItems.length)return 0;const y=Ps(r,-1),g=Ps(r+1,this.viewItems.length);if(d)for(const D of d)jp(y,D),jp(g,D);if(c)for(const D of c)du(y,D),du(g,D);const b=y.map(D=>this.viewItems[D]),v=y.map(D=>l[D]),x=g.map(D=>this.viewItems[D]),w=g.map(D=>l[D]),_=y.reduce((D,C)=>D+this.viewItems[C].minimumSize-l[C],0),S=y.reduce((D,C)=>D+this.viewItems[C].maximumSize-l[C],0),k=g.length===0?Number.POSITIVE_INFINITY:g.reduce((D,C)=>D+l[C]-this.viewItems[C].minimumSize,0),j=g.length===0?Number.NEGATIVE_INFINITY:g.reduce((D,C)=>D+l[C]-this.viewItems[C].maximumSize,0),N=Math.max(_,j),O=Math.min(k,S);let T=!1;if(m){const D=this.viewItems[m.index],C=o>=m.limitDelta;T=C!==D.visible,D.setVisible(C,m.size)}if(!T&&p){const D=this.viewItems[p.index],C=o<p.limitDelta;T=C!==D.visible,D.setVisible(C,p.size)}if(T)return this.resize(r,o,l,c,d,h,f);const P=Rt(o,N,O);let L=0,G=P;for(let D=0;D<b.length;D++){const C=b[D],R=Rt(v[D]+G,C.minimumSize,C.maximumSize),E=R-v[D];L+=E,G-=E,C.size=R}let A=L;for(let D=0;D<x.length;D++){const C=x[D],R=Rt(w[D]-A,C.minimumSize,C.maximumSize),E=R-w[D];A+=E,C.size=R}return o},this._orientation=(s=n.orientation)!==null&&s!==void 0?s:Me.VERTICAL,this.element=this.createContainer(),this.margin=(a=n.margin)!==null&&a!==void 0?a:0,this.proportionalLayout=n.proportionalLayout===void 0?!0:!!n.proportionalLayout,this.viewContainer=this.createViewContainer(),this.sashContainer=this.createSashContainer(),this.element.appendChild(this.sashContainer),this.element.appendChild(this.viewContainer),this.container.appendChild(this.element),this.style(n.styles),n.descriptor&&(this._size=n.descriptor.size,n.descriptor.views.forEach((r,o)=>{const l=r.visible===void 0||r.visible?r.size:{type:"invisible",cachedVisibleSize:r.size},c=r.view;this.addView(c,l,o,!0)}),this._contentSize=this.viewItems.reduce((r,o)=>r+o.size,0),this.saveProportions())}style(t){(t==null?void 0:t.separatorBorder)==="transparent"?(qc(this.element,"dv-separator-border"),this.element.style.removeProperty("--dv-separator-border")):(im(this.element,"dv-separator-border"),t!=null&&t.separatorBorder&&this.element.style.setProperty("--dv-separator-border",t.separatorBorder))}isViewVisible(t){if(t<0||t>=this.viewItems.length)throw new Error("Index out of bounds");return this.viewItems[t].visible}setViewVisible(t,n){if(t<0||t>=this.viewItems.length)throw new Error("Index out of bounds");const s=this.viewItems[t];s.setVisible(n,s.size),this.distributeEmptySpace(t),this.layoutViews(),this.saveProportions()}getViewSize(t){return t<0||t>=this.viewItems.length?-1:this.viewItems[t].size}resizeView(t,n){if(t<0||t>=this.viewItems.length)return;const s=Ps(this.viewItems.length).filter(l=>l!==t),a=[...s.filter(l=>this.viewItems[l].priority===sn.Low),t],r=s.filter(l=>this.viewItems[l].priority===sn.High),o=this.viewItems[t];n=Math.round(n),n=Rt(n,o.minimumSize,Math.min(o.maximumSize,this._size)),o.size=n,this.relayout(a,r)}getViews(){return this.viewItems.map(t=>t.view)}onDidChange(t,n){const s=this.viewItems.indexOf(t);if(s<0||s>=this.viewItems.length)return;n=typeof n=="number"?n:t.size,n=Rt(n,t.minimumSize,t.maximumSize),t.size=n;const a=Ps(this.viewItems.length).filter(l=>l!==s),r=[...a.filter(l=>this.viewItems[l].priority===sn.Low),s],o=a.filter(l=>this.viewItems[l].priority===sn.High);this.relayout([...r,s],o)}addView(t,n={type:"distribute"},s=this.viewItems.length,a){const r=document.createElement("div");r.className="dv-view",r.appendChild(t.element);let o;typeof n=="number"?o=n:n.type==="split"?o=this.getViewSize(n.index)/2:n.type==="invisible"?o={cachedVisibleSize:n.cachedVisibleSize}:o=t.minimumSize;const l=t.onDidChange(d=>this.onDidChange(c,d.size)),c=new j5(r,t,o,{dispose:()=>{l.dispose(),this.viewContainer.removeChild(r)}});if(s===this.viewItems.length?this.viewContainer.appendChild(r):this.viewContainer.insertBefore(r,this.viewContainer.children.item(s)),this.viewItems.splice(s,0,c),this.viewItems.length>1){const d=document.createElement("div");d.className="dv-sash";const h=m=>{for(const D of this.viewItems)D.enabled=!1;const p=Ph(),y=this._orientation===Me.HORIZONTAL?m.clientX:m.clientY,g=_5(this.sashes,D=>D.container===d),b=this.viewItems.map(D=>D.size);let v,x;const w=Ps(g,-1),_=Ps(g+1,this.viewItems.length),S=w.reduce((D,C)=>D+(this.viewItems[C].minimumSize-b[C]),0),k=w.reduce((D,C)=>D+(this.viewItems[C].viewMaximumSize-b[C]),0),j=_.length===0?Number.POSITIVE_INFINITY:_.reduce((D,C)=>D+(b[C]-this.viewItems[C].minimumSize),0),N=_.length===0?Number.NEGATIVE_INFINITY:_.reduce((D,C)=>D+(b[C]-this.viewItems[C].viewMaximumSize),0),O=Math.max(S,N),T=Math.min(j,k),P=this.findFirstSnapIndex(w),L=this.findFirstSnapIndex(_);if(typeof P=="number"){const D=this.viewItems[P],C=Math.floor(D.viewMinimumSize/2);v={index:P,limitDelta:D.visible?O-C:O+C,size:D.size}}if(typeof L=="number"){const D=this.viewItems[L],C=Math.floor(D.viewMinimumSize/2);x={index:L,limitDelta:D.visible?T+C:T-C,size:D.size}}const G=D=>{const R=(this._orientation===Me.HORIZONTAL?D.clientX:D.clientY)-y;this.resize(g,R,b,void 0,void 0,O,T,v,x),this.distributeEmptySpace(),this.layoutViews()},A=()=>{for(const D of this.viewItems)D.enabled=!0;p.release(),this.saveProportions(),document.removeEventListener("pointermove",G),document.removeEventListener("pointerup",A),document.removeEventListener("pointercancel",A),this._onDidSashEnd.fire(void 0)};document.addEventListener("pointermove",G),document.addEventListener("pointerup",A),document.addEventListener("pointercancel",A)};d.addEventListener("pointerdown",h);const f={container:d,disposable:()=>{d.removeEventListener("pointerdown",h),this.sashContainer.removeChild(d)}};this.sashContainer.appendChild(d),this.sashes.push(f)}a||this.relayout([s]),!a&&typeof n!="number"&&n.type==="distribute"&&this.distributeViewSizes(),this._onDidAddView.fire(t)}distributeViewSizes(){const t=[];let n=0;for(const l of this.viewItems)l.maximumSize-l.minimumSize>0&&(t.push(l),n+=l.size);const s=Math.floor(n/t.length);for(const l of t)l.size=Rt(s,l.minimumSize,l.maximumSize);const a=Ps(this.viewItems.length),r=a.filter(l=>this.viewItems[l].priority===sn.Low),o=a.filter(l=>this.viewItems[l].priority===sn.High);this.relayout(r,o)}removeView(t,n,s=!1){const a=this.viewItems.splice(t,1)[0];if(a.dispose(),this.viewItems.length>=1){const r=Math.max(t-1,0);this.sashes.splice(r,1)[0].disposable()}return s||this.relayout(),n&&n.type==="distribute"&&this.distributeViewSizes(),this._onDidRemoveView.fire(a.view),a.view}getViewCachedVisibleSize(t){if(t<0||t>=this.viewItems.length)throw new Error("Index out of bounds");return this.viewItems[t].cachedVisibleSize}moveView(t,n){const s=this.getViewCachedVisibleSize(t),a=typeof s>"u"?this.getViewSize(t):Es.Invisible(s),r=this.removeView(t,void 0,!0);this.addView(r,a,n)}layout(t,n){const s=Math.max(this.size,this._contentSize);if(this.size=t,this.orthogonalSize=n,this.proportions){let a=0;for(let r=0;r<this.viewItems.length;r++){const o=this.viewItems[r],l=this.proportions[r];typeof l=="number"?a+=l:t-=o.size}for(let r=0;r<this.viewItems.length;r++){const o=this.viewItems[r],l=this.proportions[r];typeof l=="number"&&a>0&&(o.size=Rt(Math.round(l*t/a),o.minimumSize,o.maximumSize))}}else{const a=Ps(this.viewItems.length),r=a.filter(l=>this.viewItems[l].priority===sn.Low),o=a.filter(l=>this.viewItems[l].priority===sn.High);this.resize(this.viewItems.length-1,t-s,void 0,r,o)}this.distributeEmptySpace(),this.layoutViews()}relayout(t,n){const s=this.viewItems.reduce((a,r)=>a+r.size,0);this.resize(this.viewItems.length-1,this._size-s,void 0,t,n),this.distributeEmptySpace(),this.layoutViews(),this.saveProportions()}distributeEmptySpace(t){const n=this.viewItems.reduce((l,c)=>l+c.size,0);let s=this.size-n;const a=Ps(this.viewItems.length-1,-1),r=a.filter(l=>this.viewItems[l].priority===sn.Low),o=a.filter(l=>this.viewItems[l].priority===sn.High);for(const l of o)jp(a,l);for(const l of r)du(a,l);typeof t=="number"&&du(a,t);for(let l=0;s!==0&&l<a.length;l++){const c=this.viewItems[a[l]],d=Rt(c.size+s,c.minimumSize,c.maximumSize),h=d-c.size;s-=h,c.size=d}}saveProportions(){this.proportionalLayout&&this._contentSize>0&&(this._proportions=this.viewItems.map(t=>t.visible?t.size/this._contentSize:void 0))}layoutViews(){if(this._contentSize=this.viewItems.reduce((c,d)=>c+d.size,0),this.updateSashEnablement(),this.viewItems.length===0)return;const t=this.viewItems.filter(c=>c.visible),n=Math.max(0,t.length-1),s=this.margin*n/Math.max(1,t.length);let a=0;const r=[],o=4,l=this.viewItems.reduce((c,d,h)=>{const f=d.visible?1:0;return h===0?c.push(f):c.push(c[h-1]+f),c},[]);this.viewItems.forEach((c,d)=>{a+=this.viewItems[d].size,r.push(a);const h=c.visible?c.size-s:0,f=Math.max(0,l[d]-1),m=d===0||f===0?0:r[d-1]+f/n*s;if(d<this.viewItems.length-1){const p=c.visible?m+h-o/2+this.margin/2:m;this._orientation===Me.HORIZONTAL&&(this.sashes[d].container.style.left=`${p}px`,this.sashes[d].container.style.top="0px"),this._orientation===Me.VERTICAL&&(this.sashes[d].container.style.left="0px",this.sashes[d].container.style.top=`${p}px`)}this._orientation===Me.HORIZONTAL&&(c.container.style.width=`${h}px`,c.container.style.left=`${m}px`,c.container.style.top="",c.container.style.height=""),this._orientation===Me.VERTICAL&&(c.container.style.height=`${h}px`,c.container.style.top=`${m}px`,c.container.style.width="",c.container.style.left=""),c.view.layout(c.size-s,this._orthogonalSize)})}findFirstSnapIndex(t){for(const n of t){const s=this.viewItems[n];if(s.visible&&s.snap)return n}for(const n of t){const s=this.viewItems[n];if(s.visible&&s.maximumSize-s.minimumSize>0)return;if(!s.visible&&s.snap)return n}}updateSashEnablement(){let t=!1;const n=this.viewItems.map(c=>t=c.size-c.minimumSize>0||t);t=!1;const s=this.viewItems.map(c=>t=c.maximumSize-c.size>0||t),a=[...this.viewItems].reverse();t=!1;const r=a.map(c=>t=c.size-c.minimumSize>0||t).reverse();t=!1;const o=a.map(c=>t=c.maximumSize-c.size>0||t).reverse();let l=0;for(let c=0;c<this.sashes.length;c++){const d=this.sashes[c],h=this.viewItems[c];l+=h.size;const f=!(n[c]&&o[c+1]),m=!(s[c]&&r[c+1]);if(f&&m){const p=Ps(c,-1),y=Ps(c+1,this.viewItems.length),g=this.findFirstSnapIndex(p),b=this.findFirstSnapIndex(y),v=typeof g=="number"&&!this.viewItems[g].visible,x=typeof b=="number"&&!this.viewItems[b].visible;v&&r[c]&&(l>0||this.startSnappingEnabled)?this.updateSash(d,ys.MINIMUM):x&&n[c]&&(l<this._contentSize||this.endSnappingEnabled)?this.updateSash(d,ys.MAXIMUM):this.updateSash(d,ys.DISABLED)}else f&&!m?this.updateSash(d,ys.MINIMUM):!f&&m?this.updateSash(d,ys.MAXIMUM):this.updateSash(d,ys.ENABLED)}}updateSash(t,n){Pe(t.container,"dv-disabled",n===ys.DISABLED),Pe(t.container,"dv-enabled",n===ys.ENABLED),Pe(t.container,"dv-maximum",n===ys.MAXIMUM),Pe(t.container,"dv-minimum",n===ys.MINIMUM)}createViewContainer(){const t=document.createElement("div");return t.className="dv-view-container",t}createSashContainer(){const t=document.createElement("div");return t.className="dv-sash-container",t}createContainer(){const t=document.createElement("div"),n=this._orientation===Me.HORIZONTAL?"dv-horizontal":"dv-vertical";return t.className=`dv-split-view-container ${n}`,t}dispose(){this._onDidSashEnd.dispose(),this._onDidAddView.dispose(),this._onDidRemoveView.dispose();for(let t=0;t<this.element.children.length;t++)if(this.element.children.item(t)===this.element){this.element.removeChild(this.element);break}for(const t of this.viewItems)t.dispose();this.element.remove()}}const lx=Object.keys({orientation:void 0,descriptor:void 0,proportionalLayout:void 0,styles:void 0,margin:void 0,disableAutoResizing:void 0,className:void 0});class X_ extends Ge{get onDidAddView(){return this.splitview.onDidAddView}get onDidRemoveView(){return this.splitview.onDidRemoveView}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get orientation(){return this.splitview.orientation}get size(){return this.splitview.size}get orthogonalSize(){return this.splitview.orthogonalSize}constructor(t,n){var s;super(),this.paneItems=[],this.skipAnimation=!1,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._orientation=(s=n.orientation)!==null&&s!==void 0?s:Me.VERTICAL,this.element=document.createElement("div"),this.element.className="dv-pane-container",t.appendChild(this.element),this.splitview=new Yc(this.element,{orientation:this._orientation,proportionalLayout:!1,descriptor:n.descriptor}),this.getPanes().forEach(a=>{const r=new Ge(a.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)})),o={pane:a,disposable:{dispose:()=>{r.dispose()}}};this.paneItems.push(o),a.orthogonalSize=this.splitview.orthogonalSize}),this.addDisposables(this._onDidChange,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire(void 0)}),this.splitview.onDidAddView(()=>{this._onDidChange.fire()}),this.splitview.onDidRemoveView(()=>{this._onDidChange.fire()}))}setViewVisible(t,n){this.splitview.setViewVisible(t,n)}addPane(t,n,s=this.splitview.length,a=!1){const r=t.onDidChangeExpansionState(()=>{this.setupAnimation(),this._onDidChange.fire(void 0)}),o={pane:t,disposable:{dispose:()=>{r.dispose()}}};this.paneItems.splice(s,0,o),t.orthogonalSize=this.splitview.orthogonalSize,this.splitview.addView(t,n,s,a)}getViewSize(t){return this.splitview.getViewSize(t)}getPanes(){return this.splitview.getViews()}removePane(t,n={skipDispose:!1}){const s=this.paneItems.splice(t,1)[0];return this.splitview.removeView(t),n.skipDispose||(s.disposable.dispose(),s.pane.dispose()),s}moveView(t,n){if(t===n)return;const s=this.removePane(t,{skipDispose:!0});this.skipAnimation=!0;try{this.addPane(s.pane,s.pane.size,n,!1)}finally{this.skipAnimation=!1}}layout(t,n){this.splitview.layout(t,n)}setupAnimation(){this.skipAnimation||(this.animationTimer&&(clearTimeout(this.animationTimer),this.animationTimer=void 0),im(this.element,"dv-animated"),this.animationTimer=setTimeout(()=>{this.animationTimer=void 0,qc(this.element,"dv-animated")},200))}dispose(){super.dispose(),this.animationTimer&&(clearTimeout(this.animationTimer),this.animationTimer=void 0),this.paneItems.forEach(t=>{t.disposable.dispose(),t.pane.dispose()}),this.paneItems=[],this.splitview.dispose(),this.element.remove()}}class dn{get minimumWidth(){return this.view.minimumWidth}get maximumWidth(){return this.view.maximumWidth}get minimumHeight(){return this.view.minimumHeight}get maximumHeight(){return this.view.maximumHeight}get priority(){return this.view.priority}get snap(){return this.view.snap}get minimumSize(){return this.orientation===Me.HORIZONTAL?this.minimumHeight:this.minimumWidth}get maximumSize(){return this.orientation===Me.HORIZONTAL?this.maximumHeight:this.maximumWidth}get minimumOrthogonalSize(){return this.orientation===Me.HORIZONTAL?this.minimumWidth:this.minimumHeight}get maximumOrthogonalSize(){return this.orientation===Me.HORIZONTAL?this.maximumWidth:this.maximumHeight}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get element(){return this.view.element}get width(){return this.orientation===Me.HORIZONTAL?this.orthogonalSize:this.size}get height(){return this.orientation===Me.HORIZONTAL?this.size:this.orthogonalSize}constructor(t,n,s,a=0){this.view=t,this.orientation=n,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._orthogonalSize=s,this._size=a,this._disposable=this.view.onDidChange(r=>{r?this._onDidChange.fire({size:this.orientation===Me.VERTICAL?r.width:r.height,orthogonalSize:this.orientation===Me.VERTICAL?r.height:r.width}):this._onDidChange.fire({})})}setVisible(t){this.view.setVisible&&this.view.setVisible(t)}layout(t,n){this._size=t,this._orthogonalSize=n,this.view.layout(this.width,this.height)}dispose(){this._onDidChange.dispose(),this._disposable.dispose()}}class Bt extends Ge{get width(){return this.orientation===Me.HORIZONTAL?this.size:this.orthogonalSize}get height(){return this.orientation===Me.HORIZONTAL?this.orthogonalSize:this.size}get minimumSize(){return this.children.length===0?0:Math.max(...this.children.map((t,n)=>this.splitview.isViewVisible(n)?t.minimumOrthogonalSize:0))}get maximumSize(){return Math.min(...this.children.map((t,n)=>this.splitview.isViewVisible(n)?t.maximumOrthogonalSize:Number.POSITIVE_INFINITY))}get minimumOrthogonalSize(){return this.splitview.minimumSize}get maximumOrthogonalSize(){return this.splitview.maximumSize}get orthogonalSize(){return this._orthogonalSize}get size(){return this._size}get minimumWidth(){return this.orientation===Me.HORIZONTAL?this.minimumOrthogonalSize:this.minimumSize}get minimumHeight(){return this.orientation===Me.HORIZONTAL?this.minimumSize:this.minimumOrthogonalSize}get maximumWidth(){return this.orientation===Me.HORIZONTAL?this.maximumOrthogonalSize:this.maximumSize}get maximumHeight(){return this.orientation===Me.HORIZONTAL?this.maximumSize:this.maximumOrthogonalSize}get priority(){if(this.children.length===0)return sn.Normal;const t=this.children.map(n=>typeof n.priority>"u"?sn.Normal:n.priority);return t.some(n=>n===sn.High)?sn.High:t.some(n=>n===sn.Low)?sn.Low:sn.Normal}get disabled(){return this.splitview.disabled}set disabled(t){this.splitview.disabled=t}get margin(){return this.splitview.margin}set margin(t){this.splitview.margin=t,this.children.forEach(n=>{n instanceof Bt&&(n.margin=t)})}constructor(t,n,s,a,r,o,l,c){if(super(),this.orientation=t,this.proportionalLayout=n,this.styles=s,this._childrenDisposable=Zt.NONE,this.children=[],this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._onDidVisibilityChange=new te,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._orthogonalSize=r,this._size=a,this.element=document.createElement("div"),this.element.className="dv-branch-node",!c)this.splitview=new Yc(this.element,{orientation:this.orientation,proportionalLayout:n,styles:s,margin:l}),this.splitview.layout(this.size,this.orthogonalSize);else{const d={views:c.map(h=>({view:h.node,size:h.node.size,visible:h.node instanceof dn&&h.visible!==void 0?h.visible:!0})),size:this.orthogonalSize};this.children=c.map(h=>h.node),this.splitview=new Yc(this.element,{orientation:this.orientation,descriptor:d,proportionalLayout:n,styles:s,margin:l})}this.disabled=o,this.addDisposables(this._onDidChange,this._onDidVisibilityChange,this.splitview.onDidSashEnd(()=>{this._onDidChange.fire({})})),this.setupChildrenEvents()}setVisible(t){}isChildVisible(t){if(t<0||t>=this.children.length)throw new Error("Invalid index");return this.splitview.isViewVisible(t)}setChildVisible(t,n){if(t<0||t>=this.children.length)throw new Error("Invalid index");if(this.splitview.isViewVisible(t)===n)return;const s=this.splitview.contentSize===0;this.splitview.setViewVisible(t,n);const a=this.splitview.contentSize===0;(n&&s||!n&&a)&&this._onDidVisibilityChange.fire({visible:n})}moveChild(t,n){if(t===n)return;if(t<0||t>=this.children.length)throw new Error("Invalid from index");t<n&&n--,this.splitview.moveView(t,n);const s=this._removeChild(t);this._addChild(s,n)}getChildSize(t){if(t<0||t>=this.children.length)throw new Error("Invalid index");return this.splitview.getViewSize(t)}resizeChild(t,n){if(t<0||t>=this.children.length)throw new Error("Invalid index");this.splitview.resizeView(t,n)}layout(t,n){this._size=n,this._orthogonalSize=t,this.splitview.layout(n,t)}addChild(t,n,s,a){if(s<0||s>this.children.length)throw new Error("Invalid index");this.splitview.addView(t,n,s,a),this._addChild(t,s)}getChildCachedVisibleSize(t){if(t<0||t>=this.children.length)throw new Error("Invalid index");return this.splitview.getViewCachedVisibleSize(t)}removeChild(t,n){if(t<0||t>=this.children.length)throw new Error("Invalid index");return this.splitview.removeView(t,n),this._removeChild(t)}_addChild(t,n){this.children.splice(n,0,t),this.setupChildrenEvents()}_removeChild(t){const[n]=this.children.splice(t,1);return this.setupChildrenEvents(),n}setupChildrenEvents(){this._childrenDisposable.dispose(),this._childrenDisposable=new Ge(vr.any(...this.children.map(t=>t.onDidChange))(t=>{this._onDidChange.fire({size:t.orthogonalSize})}),...this.children.map((t,n)=>t instanceof Bt?t.onDidVisibilityChange(({visible:s})=>{this.setChildVisible(n,s)}):Zt.NONE))}dispose(){this._childrenDisposable.dispose(),this.splitview.dispose(),this.children.forEach(t=>t.dispose()),super.dispose()}}function cx(e,t){if(e instanceof dn)return e;if(e instanceof Bt)return cx(e.children[t?e.children.length-1:0],t);throw new Error("invalid node")}function bA(e,t,n){if(e instanceof Bt){const s=new Bt(e.orientation,e.proportionalLayout,e.styles,t,n,e.disabled,e.margin);for(let a=e.children.length-1;a>=0;a--){const r=e.children[a];s.addChild(bA(r,r.size,r.orthogonalSize),r.size,0,!0)}return s}else return new dn(e.view,e.orientation,n)}function dx(e,t,n){if(e instanceof Bt){const s=new Bt(ai(e.orientation),e.proportionalLayout,e.styles,t,n,e.disabled,e.margin);let a=0;for(let r=e.children.length-1;r>=0;r--){const o=e.children[r],l=o instanceof Bt?o.orthogonalSize:o.size;let c=e.size===0?0:Math.round(t*l/e.size);a+=c,r===0&&(c+=t-a),s.addChild(dx(o,n,c),c,0,!0)}return s}else return new dn(e.view,ai(e.orientation),n)}function N5(e){const t=e.parentElement;if(!t)throw new Error("Invalid grid element");let n=t.firstElementChild,s=0;for(;n!==e&&n!==t.lastElementChild&&n;)n=n.nextElementSibling,s++;return s}function Ht(e){const t=e.parentElement;if(!t)throw new Error("Invalid grid element");if(/\bdv-grid-view\b/.test(t.className))return[];const n=N5(t),s=t.parentElement.parentElement.parentElement;return[...Ht(s),n]}function ti(e,t,n){const s=S5(e,t),a=k5(n);if(s===a){const[r,o]=Pi(t);let l=o;return(n==="right"||n==="bottom")&&(l+=1),[...r,l]}else{const r=n==="right"||n==="bottom"?1:0;return[...t,r]}}function k5(e){return e==="top"||e==="bottom"?Me.VERTICAL:Me.HORIZONTAL}function S5(e,t){return t.length%2===0?ai(e):e}const ai=e=>e===Me.HORIZONTAL?Me.VERTICAL:Me.HORIZONTAL;function C5(e){return!!e.children}const ux=(e,t)=>{const n=t===Me.VERTICAL?e.box.width:e.box.height;return C5(e)?{type:"branch",data:e.children.map(s=>ux(s,ai(t))),size:n}:typeof e.cachedVisibleSize=="number"?{type:"leaf",data:e.view.toJSON(),size:e.cachedVisibleSize,visible:!1}:{type:"leaf",data:e.view.toJSON(),size:n}};class D5{get length(){return this._root?this._root.children.length:0}get orientation(){return this.root.orientation}set orientation(t){if(this.root.orientation===t)return;const{size:n,orthogonalSize:s}=this.root;this.root=dx(this.root,s,n),this.root.layout(n,s)}get width(){return this.root.width}get height(){return this.root.height}get minimumWidth(){return this.root.minimumWidth}get minimumHeight(){return this.root.minimumHeight}get maximumWidth(){return this.root.maximumHeight}get maximumHeight(){return this.root.maximumHeight}get locked(){return this._locked}set locked(t){this._locked=t;const n=[this.root];for(;n.length>0;){const s=n.pop();s instanceof Bt&&(s.disabled=t,n.push(...s.children))}}get margin(){return this._margin}set margin(t){this._margin=t,this.root.margin=t}maximizedView(){var t;return(t=this._maximizedNode)===null||t===void 0?void 0:t.leaf.view}hasMaximizedView(){return this._maximizedNode!==void 0}maximizeView(t){var n;const s=Ht(t.element),[a,r]=this.getNode(s);if(!(r instanceof dn)||((n=this._maximizedNode)===null||n===void 0?void 0:n.leaf)===r)return;this.hasMaximizedView()&&this.exitMaximizedView(),ux(this.getView(),this.orientation);const o=[];function l(c,d){for(let h=0;h<c.children.length;h++){const f=c.children[h];f instanceof dn?f!==d&&(c.isChildVisible(h)?c.setChildVisible(h,!1):o.push(f)):l(f,d)}}l(this.root,r),this._maximizedNode={leaf:r,hiddenOnMaximize:o},this._onDidMaximizedNodeChange.fire({view:r.view,isMaximized:!0})}exitMaximizedView(){if(!this._maximizedNode)return;const t=this._maximizedNode.hiddenOnMaximize;function n(a){for(let r=a.children.length-1;r>=0;r--){const o=a.children[r];o instanceof dn?t.includes(o)||a.setChildVisible(r,!0):n(o)}}n(this.root);const s=this._maximizedNode.leaf;this._maximizedNode=void 0,this._onDidMaximizedNodeChange.fire({view:s.view,isMaximized:!1})}serialize(){const t=this.maximizedView();let n;t&&(n=Ht(t.element)),this.hasMaximizedView()&&this.exitMaximizedView();const a={root:ux(this.getView(),this.orientation),width:this.width,height:this.height,orientation:this.orientation};return n&&(a.maximizedNode={location:n}),t&&this.maximizeView(t),a}dispose(){this.disposable.dispose(),this._onDidChange.dispose(),this._onDidMaximizedNodeChange.dispose(),this._onDidViewVisibilityChange.dispose(),this.root.dispose(),this._maximizedNode=void 0,this.element.remove()}clear(){const t=this.root.orientation;this.root=new Bt(t,this.proportionalLayout,this.styles,this.root.size,this.root.orthogonalSize,this.locked,this.margin)}deserialize(t,n){const s=t.orientation,a=s===Me.VERTICAL?t.height:t.width;if(this._deserialize(t.root,s,n,a),this.layout(t.width,t.height),t.maximizedNode){const r=t.maximizedNode.location,[o,l]=this.getNode(r);if(!(l instanceof dn))return;this.maximizeView(l.view)}}_deserialize(t,n,s,a){this.root=this._deserializeNode(t,n,s,a)}_deserializeNode(t,n,s,a){var r;let o;if(t.type==="branch"){const c=t.data.map(d=>({node:this._deserializeNode(d,ai(n),s,t.size),visible:d.visible}));o=new Bt(n,this.proportionalLayout,this.styles,t.size,a,this.locked,this.margin,c)}else{const l=s.fromJSON(t);typeof t.visible=="boolean"&&((r=l.setVisible)===null||r===void 0||r.call(l,t.visible)),o=new dn(l,n,a,t.size)}return o}get root(){return this._root}set root(t){const n=this._root;n&&(n.dispose(),this._maximizedNode=void 0,this.element.removeChild(n.element)),this._root=t,this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(s=>{this._onDidChange.fire(s)})}normalize(){if(!this._root||this._root.children.length!==1)return;const t=this.root,n=t.children[0];if(n instanceof dn)return;t.element.remove();const s=t.removeChild(0);t.dispose(),s.dispose(),this._root=bA(n,n.size,n.orthogonalSize),this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(a=>{this._onDidChange.fire(a)})}insertOrthogonalSplitviewAtRoot(){if(!this._root)return;const t=this.root;if(t.element.remove(),this._root=new Bt(ai(t.orientation),this.proportionalLayout,this.styles,this.root.orthogonalSize,this.root.size,this.locked,this.margin),t.children.length!==0)if(t.children.length===1){const n=t.children[0];t.removeChild(0).dispose(),t.dispose(),this._root.addChild(dx(n,n.orthogonalSize,n.size),Es.Distribute,0)}else this._root.addChild(t,Es.Distribute,0);this.element.appendChild(this._root.element),this.disposable.value=this._root.onDidChange(n=>{this._onDidChange.fire(n)})}next(t){return this.progmaticSelect(t)}previous(t){return this.progmaticSelect(t,!0)}getView(t){const n=t?this.getNode(t)[1]:this.root;return this._getViews(n,this.orientation)}_getViews(t,n,s){const a={height:t.height,width:t.width};if(t instanceof dn)return{box:a,view:t.view,cachedVisibleSize:s};const r=[];for(let o=0;o<t.children.length;o++){const l=t.children[o],c=t.getChildCachedVisibleSize(o);r.push(this._getViews(l,ai(n),c))}return{box:a,children:r}}progmaticSelect(t,n=!1){const[s,a]=this.getNode(t);if(!(a instanceof dn))throw new Error("invalid location");for(let r=s.length-1;r>-1;r--){const o=s[r],l=t[r]||0;if(n?l-1>-1:l+1<o.children.length)return cx(o.children[n?l-1:l+1],n)}return cx(this.root,n)}constructor(t,n,s,a,r){this.proportionalLayout=t,this.styles=n,this._locked=!1,this._margin=0,this._maximizedNode=void 0,this.disposable=new On,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._onDidViewVisibilityChange=new te,this.onDidViewVisibilityChange=this._onDidViewVisibilityChange.event,this._onDidMaximizedNodeChange=new te,this.onDidMaximizedNodeChange=this._onDidMaximizedNodeChange.event,this.element=document.createElement("div"),this.element.className="dv-grid-view",this._locked=a??!1,this._margin=r??0,this.root=new Bt(s,t,n,0,0,this.locked,this.margin)}isViewVisible(t){const[n,s]=Pi(t),[,a]=this.getNode(n);if(!(a instanceof Bt))throw new Error("Invalid from location");return a.isChildVisible(s)}setViewVisible(t,n){this.hasMaximizedView()&&this.exitMaximizedView();const[s,a]=Pi(t),[,r]=this.getNode(s);if(!(r instanceof Bt))throw new Error("Invalid from location");this._onDidViewVisibilityChange.fire(),r.setChildVisible(a,n)}moveView(t,n,s){this.hasMaximizedView()&&this.exitMaximizedView();const[,a]=this.getNode(t);if(!(a instanceof Bt))throw new Error("Invalid location");a.moveChild(n,s)}addView(t,n,s){this.hasMaximizedView()&&this.exitMaximizedView();const[a,r]=Pi(s),[o,l]=this.getNode(a);if(l instanceof Bt){const c=new dn(t,ai(l.orientation),l.orthogonalSize);l.addChild(c,n,r)}else{const[c,...d]=[...o].reverse(),[h,...f]=[...a].reverse();let m=0;const p=c.getChildCachedVisibleSize(h);typeof p=="number"&&(m=Es.Invisible(p)),c.removeChild(h).dispose();const g=new Bt(l.orientation,this.proportionalLayout,this.styles,l.size,l.orthogonalSize,this.locked,this.margin);c.addChild(g,l.size,h);const b=new dn(l.view,c.orientation,l.size);g.addChild(b,m,0),typeof n!="number"&&n.type==="split"&&(n={type:"split",index:0});const v=new dn(t,c.orientation,l.size);g.addChild(v,n,r)}}remove(t,n){const s=Ht(t.element);return this.removeView(s,n)}removeView(t,n){this.hasMaximizedView()&&this.exitMaximizedView();const[s,a]=Pi(t),[r,o]=this.getNode(s);if(!(o instanceof Bt))throw new Error("Invalid location");const l=o.children[a];if(!(l instanceof dn))throw new Error("Invalid location");if(o.removeChild(a,n),l.dispose(),o.children.length!==1)return l.view;const c=o.children[0];if(r.length===0)return c instanceof dn||(o.removeChild(0,n),this.root=c),l.view;const[d,...h]=[...r].reverse(),[f,...m]=[...s].reverse(),p=o.isChildVisible(0);o.removeChild(0,n);const y=d.children.map((g,b)=>d.getChildSize(b));if(d.removeChild(f,n).dispose(),c instanceof Bt){y.splice(f,1,...c.children.map(g=>g.size));for(let g=0;g<c.children.length;g++){const b=c.children[g];d.addChild(b,b.size,f+g)}for(;c.children.length>0;)c.removeChild(0)}else{const g=new dn(c.view,ai(c.orientation),c.size),b=p?c.orthogonalSize:Es.Invisible(c.orthogonalSize);d.addChild(g,b,f)}c.dispose();for(let g=0;g<y.length;g++)d.resizeChild(g,y[g]);return l.view}layout(t,n){const[s,a]=this.root.orientation===Me.HORIZONTAL?[n,t]:[t,n];this.root.layout(s,a)}getNode(t,n=this.root,s=[]){if(t.length===0)return[s,n];if(!(n instanceof Bt))throw new Error("Invalid location");const[a,...r]=t;if(a<0||a>=n.children.length)throw new Error("Invalid location");const o=n.children[a];return s.push(n),this.getNode(r,o,s)}}const hx=Object.keys({disableAutoResizing:void 0,proportionalLayout:void 0,orientation:void 0,hideBorders:void 0,className:void 0});class Pb extends Ge{get element(){return this._element}get disableResizing(){return this._disableResizing}set disableResizing(t){this._disableResizing=t}constructor(t,n=!1){super(),this._disableResizing=n,this._element=t,this.addDisposables(sm(this._element,s=>{if(this.isDisposed||this.disableResizing||!this._element.offsetParent||!f5(this._element))return;const{width:a,height:r}=s.contentRect;this.layout(a,r)}))}}const E5=Lb();function Ih(e){switch(e){case"left":return"left";case"right":return"right";case"above":return"top";case"below":return"bottom";case"within":default:return"center"}}class yA extends Pb{get id(){return this._id}get size(){return this._groups.size}get groups(){return Array.from(this._groups.values()).map(t=>t.value)}get width(){return this.gridview.width}get height(){return this.gridview.height}get minimumHeight(){return this.gridview.minimumHeight}get maximumHeight(){return this.gridview.maximumHeight}get minimumWidth(){return this.gridview.minimumWidth}get maximumWidth(){return this.gridview.maximumWidth}get activeGroup(){return this._activeGroup}get locked(){return this.gridview.locked}set locked(t){this.gridview.locked=t}constructor(t,n){var s;super(document.createElement("div"),n.disableAutoResizing),this._id=E5.next(),this._groups=new Map,this._onDidRemove=new te,this.onDidRemove=this._onDidRemove.event,this._onDidAdd=new te,this.onDidAdd=this._onDidAdd.event,this._onDidMaximizedChange=new te,this.onDidMaximizedChange=this._onDidMaximizedChange.event,this._onDidActiveChange=new te,this.onDidActiveChange=this._onDidActiveChange.event,this._bufferOnDidLayoutChange=new q_,this.onDidLayoutChange=this._bufferOnDidLayoutChange.onEvent,this._onDidViewVisibilityChangeMicroTaskQueue=new q_,this.onDidViewVisibilityChangeMicroTaskQueue=this._onDidViewVisibilityChangeMicroTaskQueue.onEvent,this.element.style.height="100%",this.element.style.width="100%",this._classNames=new am(this.element),this._classNames.setClassNames((s=n.className)!==null&&s!==void 0?s:""),t.appendChild(this.element),this.gridview=new D5(!!n.proportionalLayout,n.styles,n.orientation,n.locked,n.margin),this.gridview.locked=!!n.locked,this.element.appendChild(this.gridview.element),this.layout(0,0,!0),this.addDisposables(this.gridview.onDidMaximizedNodeChange(a=>{this._onDidMaximizedChange.fire({panel:a.view,isMaximized:a.isMaximized})}),this.gridview.onDidViewVisibilityChange(()=>this._onDidViewVisibilityChangeMicroTaskQueue.fire()),this.onDidViewVisibilityChangeMicroTaskQueue(()=>{this.layout(this.width,this.height,!0)}),Zt.from(()=>{var a;(a=this.element.parentElement)===null||a===void 0||a.removeChild(this.element)}),this.gridview.onDidChange(()=>{this._bufferOnDidLayoutChange.fire()}),vr.any(this.onDidAdd,this.onDidRemove,this.onDidActiveChange)(()=>{this._bufferOnDidLayoutChange.fire()}),this._onDidMaximizedChange,this._onDidViewVisibilityChangeMicroTaskQueue,this._bufferOnDidLayoutChange)}setVisible(t,n){this.gridview.setViewVisible(Ht(t.element),n),this._bufferOnDidLayoutChange.fire()}isVisible(t){return this.gridview.isViewVisible(Ht(t.element))}updateOptions(t){var n,s,a,r;t.proportionalLayout,t.orientation&&(this.gridview.orientation=t.orientation),"disableResizing"in t&&(this.disableResizing=(n=t.disableAutoResizing)!==null&&n!==void 0?n:!1),"locked"in t&&(this.locked=(s=t.locked)!==null&&s!==void 0?s:!1),"margin"in t&&(this.gridview.margin=(a=t.margin)!==null&&a!==void 0?a:0),"className"in t&&this._classNames.setClassNames((r=t.className)!==null&&r!==void 0?r:"")}maximizeGroup(t){this.gridview.maximizeView(t),this.doSetGroupActive(t)}isMaximizedGroup(t){return this.gridview.maximizedView()===t}exitMaximizedGroup(){this.gridview.exitMaximizedView()}hasMaximizedGroup(){return this.gridview.hasMaximizedView()}doAddGroup(t,n=[0],s){this.gridview.addView(t,s??Es.Distribute,n),this._onDidAdd.fire(t)}doRemoveGroup(t,n){if(!this._groups.has(t.id))throw new Error("invalid operation");const s=this._groups.get(t.id),a=this.gridview.remove(t,Es.Distribute);if(s&&!(n!=null&&n.skipDispose)&&(s.disposable.dispose(),s.value.dispose(),this._groups.delete(t.id),this._onDidRemove.fire(t)),!(n!=null&&n.skipActive)&&this._activeGroup===t){const r=Array.from(this._groups.values());this.doSetGroupActive(r.length>0?r[0].value:void 0)}return a}getPanel(t){var n;return(n=this._groups.get(t))===null||n===void 0?void 0:n.value}doSetGroupActive(t){this._activeGroup!==t&&(this._activeGroup&&this._activeGroup.setActive(!1),t&&t.setActive(!0),this._activeGroup=t,this._onDidActiveChange.fire(t))}removeGroup(t){this.doRemoveGroup(t)}moveToNext(t){var n;if(t||(t={}),!t.group){if(!this.activeGroup)return;t.group=this.activeGroup}const s=Ht(t.group.element),a=(n=this.gridview.next(s))===null||n===void 0?void 0:n.view;this.doSetGroupActive(a)}moveToPrevious(t){var n;if(t||(t={}),!t.group){if(!this.activeGroup)return;t.group=this.activeGroup}const s=Ht(t.group.element),a=(n=this.gridview.previous(s))===null||n===void 0?void 0:n.view;this.doSetGroupActive(a)}layout(t,n,s){(s||t!==this.width||n!==this.height)&&(this.gridview.element.style.height=`${n}px`,this.gridview.element.style.width=`${t}px`,this.gridview.layout(t,n))}dispose(){this._onDidActiveChange.dispose(),this._onDidAdd.dispose(),this._onDidRemove.dispose();for(const t of this.groups)t.dispose();this.gridview.dispose(),super.dispose()}}class wA{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get length(){return this.component.length}get orientation(){return this.component.orientation}get panels(){return this.component.panels}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}constructor(t){this.component=t}removePanel(t,n){this.component.removePanel(t,n)}focus(){this.component.focus()}getPanel(t){return this.component.getPanel(t)}layout(t,n){return this.component.layout(t,n)}addPanel(t){return this.component.addPanel(t)}movePanel(t,n){this.component.movePanel(t,n)}fromJSON(t){this.component.fromJSON(t)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(t){this.component.updateOptions(t)}dispose(){this.component.dispose()}}class Xc{get minimumSize(){return this.component.minimumSize}get maximumSize(){return this.component.maximumSize}get width(){return this.component.width}get height(){return this.component.height}get panels(){return this.component.panels}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidAddView(){return this.component.onDidAddView}get onDidRemoveView(){return this.component.onDidRemoveView}get onDidDrop(){return this.component.onDidDrop}get onUnhandledDragOverEvent(){return this.component.onUnhandledDragOverEvent}constructor(t){this.component=t}removePanel(t){this.component.removePanel(t)}getPanel(t){return this.component.getPanel(t)}movePanel(t,n){this.component.movePanel(t,n)}focus(){this.component.focus()}layout(t,n){this.component.layout(t,n)}addPanel(t){return this.component.addPanel(t)}fromJSON(t){this.component.fromJSON(t)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(t){this.component.updateOptions(t)}dispose(){this.component.dispose()}}class _A{get width(){return this.component.width}get height(){return this.component.height}get minimumHeight(){return this.component.minimumHeight}get maximumHeight(){return this.component.maximumHeight}get minimumWidth(){return this.component.minimumWidth}get maximumWidth(){return this.component.maximumWidth}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidAddPanel(){return this.component.onDidAddGroup}get onDidRemovePanel(){return this.component.onDidRemoveGroup}get onDidActivePanelChange(){return this.component.onDidActiveGroupChange}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get panels(){return this.component.groups}get orientation(){return this.component.orientation}set orientation(t){this.component.updateOptions({orientation:t})}constructor(t){this.component=t}focus(){this.component.focus()}layout(t,n,s=!1){this.component.layout(t,n,s)}addPanel(t){return this.component.addPanel(t)}removePanel(t,n){this.component.removePanel(t,n)}movePanel(t,n){this.component.movePanel(t,n)}getPanel(t){return this.component.getPanel(t)}fromJSON(t){return this.component.fromJSON(t)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}updateOptions(t){this.component.updateOptions(t)}dispose(){this.component.dispose()}}class Gh{get id(){return this.component.id}get width(){return this.component.width}get height(){return this.component.height}get minimumHeight(){return this.component.minimumHeight}get maximumHeight(){return this.component.maximumHeight}get minimumWidth(){return this.component.minimumWidth}get maximumWidth(){return this.component.maximumWidth}get size(){return this.component.size}get totalPanels(){return this.component.totalPanels}get onDidActiveGroupChange(){return this.component.onDidActiveGroupChange}get onDidAddGroup(){return this.component.onDidAddGroup}get onDidRemoveGroup(){return this.component.onDidRemoveGroup}get onDidActivePanelChange(){return this.component.onDidActivePanelChange}get onDidAddPanel(){return this.component.onDidAddPanel}get onDidRemovePanel(){return this.component.onDidRemovePanel}get onDidMovePanel(){return this.component.onDidMovePanel}get onDidLayoutFromJSON(){return this.component.onDidLayoutFromJSON}get onDidLayoutChange(){return this.component.onDidLayoutChange}get onDidDrop(){return this.component.onDidDrop}get onWillDrop(){return this.component.onWillDrop}get onWillShowOverlay(){return this.component.onWillShowOverlay}get onWillDragGroup(){return this.component.onWillDragGroup}get onWillDragPanel(){return this.component.onWillDragPanel}get onUnhandledDragOverEvent(){return this.component.onUnhandledDragOverEvent}get onDidPopoutGroupSizeChange(){return this.component.onDidPopoutGroupSizeChange}get onDidPopoutGroupPositionChange(){return this.component.onDidPopoutGroupPositionChange}get onDidOpenPopoutWindowFail(){return this.component.onDidOpenPopoutWindowFail}get panels(){return this.component.panels}get groups(){return this.component.groups}get activePanel(){return this.component.activePanel}get activeGroup(){return this.component.activeGroup}constructor(t){this.component=t}focus(){this.component.focus()}getPanel(t){return this.component.getGroupPanel(t)}layout(t,n,s=!1){this.component.layout(t,n,s)}addPanel(t){return this.component.addPanel(t)}removePanel(t){this.component.removePanel(t)}addGroup(t){return this.component.addGroup(t)}closeAllGroups(){return this.component.closeAllGroups()}removeGroup(t){this.component.removeGroup(t)}getGroup(t){return this.component.getPanel(t)}addFloatingGroup(t,n){return this.component.addFloatingGroup(t,n)}fromJSON(t){this.component.fromJSON(t)}toJSON(){return this.component.toJSON()}clear(){this.component.clear()}moveToNext(t){this.component.moveToNext(t)}moveToPrevious(t){this.component.moveToPrevious(t)}maximizeGroup(t){this.component.maximizeGroup(t.group)}hasMaximizedGroup(){return this.component.hasMaximizedGroup()}exitMaximizedGroup(){this.component.exitMaximizedGroup()}get onDidMaximizedGroupChange(){return this.component.onDidMaximizedGroupChange}addPopoutGroup(t,n){return this.component.addPopoutGroup(t,n)}updateOptions(t){this.component.updateOptions(t)}dispose(){this.component.dispose()}}class Ib extends Ge{constructor(t,n){super(),this.el=t,this.disabled=n,this.dataDisposable=new On,this.pointerEventsDisposable=new On,this._onDragStart=new te,this.onDragStart=this._onDragStart.event,this.addDisposables(this._onDragStart,this.dataDisposable,this.pointerEventsDisposable),this.configure()}setDisabled(t){this.disabled=t}isCancelled(t){return!1}configure(){this.addDisposables(this._onDragStart,Fe(this.el,"dragstart",t=>{if(t.defaultPrevented||this.isCancelled(t)||this.disabled){t.preventDefault();return}const n=Ph();this.pointerEventsDisposable.value={dispose:()=>{n.release()}},this.el.classList.add("dv-dragged"),setTimeout(()=>this.el.classList.remove("dv-dragged"),0),this.dataDisposable.value=this.getData(t),this._onDragStart.fire(t),t.dataTransfer&&(t.dataTransfer.effectAllowed="move",t.dataTransfer.items.length>0||t.dataTransfer.setData("text/plain",""))}),Fe(this.el,"dragend",()=>{this.pointerEventsDisposable.dispose(),setTimeout(()=>{this.dataDisposable.dispose()},0)}))}}class jA extends Ge{constructor(t,n){super(),this.element=t,this.callbacks=n,this.target=null,this.registerListeners()}onDragEnter(t){this.target=t.target,this.callbacks.onDragEnter(t)}onDragOver(t){t.preventDefault(),this.callbacks.onDragOver&&this.callbacks.onDragOver(t)}onDragLeave(t){this.target===t.target&&(this.target=null,this.callbacks.onDragLeave(t))}onDragEnd(t){this.target=null,this.callbacks.onDragEnd(t)}onDrop(t){this.callbacks.onDrop(t)}registerListeners(){this.addDisposables(Fe(this.element,"dragenter",t=>{this.onDragEnter(t)},!0)),this.addDisposables(Fe(this.element,"dragover",t=>{this.onDragOver(t)},!0)),this.addDisposables(Fe(this.element,"dragleave",t=>{this.onDragLeave(t)})),this.addDisposables(Fe(this.element,"dragend",t=>{this.onDragEnd(t)})),this.addDisposables(Fe(this.element,"drop",t=>{this.onDrop(t)}))}}function A5(e,t){const{top:n,left:s,width:a,height:r}=t,o=`${Math.round(n)}px`,l=`${Math.round(s)}px`,c=`${Math.round(a)}px`,d=`${Math.round(r)}px`;e.style.top=o,e.style.left=l,e.style.width=c,e.style.height=d,e.style.visibility="visible",(!e.style.transform||e.style.transform==="")&&(e.style.transform="translate3d(0, 0, 0)")}function R5(e,t){const{top:n,left:s,width:a,height:r}=t;e.style.top=n,e.style.left=s,e.style.width=a,e.style.height=r,e.style.visibility="visible",(!e.style.transform||e.style.transform==="")&&(e.style.transform="translate3d(0, 0, 0)")}function T5(e,t){const{top:n,left:s,width:a,height:r}=t,o=`${Math.round(n)}px`,l=`${Math.round(s)}px`,c=`${Math.round(a)}px`,d=`${Math.round(r)}px`;return e.style.top!==o||e.style.left!==l||e.style.width!==c||e.style.height!==d}class O5 extends $b{get nativeEvent(){return this.options.nativeEvent}get position(){return this.options.position}constructor(t){super(),this.options=t}}function K_(e){switch(e){case"above":return"top";case"below":return"bottom";case"left":return"left";case"right":return"right";case"within":return"center";default:throw new Error(`invalid direction '${e}'`)}}function NA(e){switch(e){case"top":return"above";case"bottom":return"below";case"left":return"left";case"right":return"right";case"center":return"within";default:throw new Error(`invalid position '${e}'`)}}const z5={value:20,type:"percentage"},M5={value:50,type:"percentage"},$5=100,L5=100;class Vs extends Ge{get disabled(){return this._disabled}set disabled(t){this._disabled=t}get state(){return this._state}constructor(t,n){super(),this.element=t,this.options=n,this._onDrop=new te,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new te,this.onWillShowOverlay=this._onWillShowOverlay.event,this._disabled=!1,this._acceptedTargetZonesSet=new Set(this.options.acceptedTargetZones),this.dnd=new jA(this.element,{onDragEnter:()=>{var s,a,r;(r=(a=(s=this.options).getOverrideTarget)===null||a===void 0?void 0:a.call(s))===null||r===void 0||r.getElements()},onDragOver:s=>{var a,r,o,l,c,d,h;Vs.ACTUAL_TARGET=this;const f=(r=(a=this.options).getOverrideTarget)===null||r===void 0?void 0:r.call(a);if(this._acceptedTargetZonesSet.size===0){if(f)return;this.removeDropTarget();return}const m=(c=(l=(o=this.options).getOverlayOutline)===null||l===void 0?void 0:l.call(o))!==null&&c!==void 0?c:this.element,p=m.offsetWidth,y=m.offsetHeight;if(p===0||y===0)return;const g=s.currentTarget.getBoundingClientRect(),b=((d=s.clientX)!==null&&d!==void 0?d:0)-g.left,v=((h=s.clientY)!==null&&h!==void 0?h:0)-g.top,x=this.calculateQuadrant(this._acceptedTargetZonesSet,b,v,p,y);if(this.isAlreadyUsed(s)||x===null){this.removeDropTarget();return}if(!this.options.canDisplayOverlay(s,x)){if(f)return;this.removeDropTarget();return}const w=new O5({nativeEvent:s,position:x});if(this._onWillShowOverlay.fire(w),w.defaultPrevented){this.removeDropTarget();return}this.markAsUsed(s),f||this.targetElement||(this.targetElement=document.createElement("div"),this.targetElement.className="dv-drop-target-dropzone",this.overlayElement=document.createElement("div"),this.overlayElement.className="dv-drop-target-selection",this._state="center",this.targetElement.appendChild(this.overlayElement),m.classList.add("dv-drop-target"),m.append(this.targetElement)),this.toggleClasses(x,p,y),this._state=x},onDragLeave:()=>{var s,a;!((a=(s=this.options).getOverrideTarget)===null||a===void 0)&&a.call(s)||this.removeDropTarget()},onDragEnd:s=>{var a,r;const o=(r=(a=this.options).getOverrideTarget)===null||r===void 0?void 0:r.call(a);o&&Vs.ACTUAL_TARGET===this&&this._state&&(s.stopPropagation(),this._onDrop.fire({position:this._state,nativeEvent:s})),this.removeDropTarget(),o==null||o.clear()},onDrop:s=>{var a,r,o;s.preventDefault();const l=this._state;this.removeDropTarget(),(o=(r=(a=this.options).getOverrideTarget)===null||r===void 0?void 0:r.call(a))===null||o===void 0||o.clear(),l&&(s.stopPropagation(),this._onDrop.fire({position:l,nativeEvent:s}))}}),this.addDisposables(this._onDrop,this._onWillShowOverlay,this.dnd)}setTargetZones(t){this._acceptedTargetZonesSet=new Set(t)}setOverlayModel(t){this.options.overlayModel=t}dispose(){this.removeDropTarget(),super.dispose()}markAsUsed(t){t[Vs.USED_EVENT_ID]=!0}isAlreadyUsed(t){const n=t[Vs.USED_EVENT_ID];return typeof n=="boolean"&&n}toggleClasses(t,n,s){var a,r,o,l,c,d,h;const f=(r=(a=this.options).getOverrideTarget)===null||r===void 0?void 0:r.call(a);if(!f&&!this.overlayElement)return;const m=n<$5,p=s<L5,y=t==="left",g=t==="right",b=t==="top",v=t==="bottom",x=!m&&g,w=!m&&y,_=!p&&b,S=!p&&v;let k=1;const j=(l=(o=this.options.overlayModel)===null||o===void 0?void 0:o.size)!==null&&l!==void 0?l:M5;if(j.type==="percentage"?k=Rt(j.value,0,100)/100:((x||w)&&(k=Rt(0,j.value,n)/n),(_||S)&&(k=Rt(0,j.value,s)/s)),f){const O=(h=(d=(c=this.options).getOverlayOutline)===null||d===void 0?void 0:d.call(c))!==null&&h!==void 0?h:this.element,T=O.getBoundingClientRect(),P=f.getElements(void 0,O),L=P.root,G=P.overlay,A=L.getBoundingClientRect(),D=T.top-A.top,C=T.left-A.left,R={top:D,left:C,width:n,height:s};if(x?(R.left=C+n*(1-k),R.width=n*k):w?R.width=n*k:_?R.height=s*k:S&&(R.top=D+s*(1-k),R.height=s*k),m&&y&&(R.width=4),m&&g&&(R.left=C+n-4,R.width=4),!T5(G,R))return;A5(G,R),G.className=`dv-drop-target-anchor${this.options.className?` ${this.options.className}`:""}`,Pe(G,"dv-drop-target-left",y),Pe(G,"dv-drop-target-right",g),Pe(G,"dv-drop-target-top",b),Pe(G,"dv-drop-target-bottom",v),Pe(G,"dv-drop-target-center",t==="center"),P.changed&&(Pe(G,"dv-drop-target-anchor-container-changed",!0),setTimeout(()=>{Pe(G,"dv-drop-target-anchor-container-changed",!1)},10));return}if(!this.overlayElement)return;const N={top:"0px",left:"0px",width:"100%",height:"100%"};x?(N.left=`${100*(1-k)}%`,N.width=`${100*k}%`):w?N.width=`${100*k}%`:_?N.height=`${100*k}%`:S&&(N.top=`${100*(1-k)}%`,N.height=`${100*k}%`),R5(this.overlayElement,N),Pe(this.overlayElement,"dv-drop-target-small-vertical",p),Pe(this.overlayElement,"dv-drop-target-small-horizontal",m),Pe(this.overlayElement,"dv-drop-target-left",y),Pe(this.overlayElement,"dv-drop-target-right",g),Pe(this.overlayElement,"dv-drop-target-top",b),Pe(this.overlayElement,"dv-drop-target-bottom",v),Pe(this.overlayElement,"dv-drop-target-center",t==="center")}calculateQuadrant(t,n,s,a,r){var o,l;const c=(l=(o=this.options.overlayModel)===null||o===void 0?void 0:o.activationSize)!==null&&l!==void 0?l:z5;return c.type==="percentage"?P5(t,n,s,a,r,c.value):I5(t,n,s,a,r,c.value)}removeDropTarget(){var t;this.targetElement&&(this._state=void 0,(t=this.targetElement.parentElement)===null||t===void 0||t.classList.remove("dv-drop-target"),this.targetElement.remove(),this.targetElement=void 0,this.overlayElement=void 0)}}Vs.USED_EVENT_ID="__dockview_droptarget_event_is_used__";function P5(e,t,n,s,a,r){const o=100*t/s,l=100*n/a;return e.has("left")&&o<r?"left":e.has("right")&&o>100-r?"right":e.has("top")&&l<r?"top":e.has("bottom")&&l>100-r?"bottom":e.has("center")?"center":null}function I5(e,t,n,s,a,r){return e.has("left")&&t<r?"left":e.has("right")&&t>s-r?"right":e.has("top")&&n<r?"top":e.has("bottom")&&n>a-r?"bottom":e.has("center")?"center":null}const fx=Object.keys({disableAutoResizing:void 0,disableDnd:void 0,className:void 0});class G5 extends mA{constructor(t,n,s,a){super(),this.nativeEvent=t,this.position=n,this.getData=s,this.panel=a}}class kA extends $b{constructor(){super()}}class SA extends Ge{get isFocused(){return this._isFocused}get isActive(){return this._isActive}get isVisible(){return this._isVisible}get width(){return this._width}get height(){return this._height}constructor(t,n){super(),this.id=t,this.component=n,this._isFocused=!1,this._isActive=!1,this._isVisible=!0,this._width=0,this._height=0,this._parameters={},this.panelUpdatesDisposable=new On,this._onDidDimensionChange=new te,this.onDidDimensionsChange=this._onDidDimensionChange.event,this._onDidChangeFocus=new te,this.onDidFocusChange=this._onDidChangeFocus.event,this._onWillFocus=new te,this.onWillFocus=this._onWillFocus.event,this._onDidVisibilityChange=new te,this.onDidVisibilityChange=this._onDidVisibilityChange.event,this._onWillVisibilityChange=new te,this.onWillVisibilityChange=this._onWillVisibilityChange.event,this._onDidActiveChange=new te,this.onDidActiveChange=this._onDidActiveChange.event,this._onActiveChange=new te,this.onActiveChange=this._onActiveChange.event,this._onDidParametersChange=new te,this.onDidParametersChange=this._onDidParametersChange.event,this.addDisposables(this.onDidFocusChange(s=>{this._isFocused=s.isFocused}),this.onDidActiveChange(s=>{this._isActive=s.isActive}),this.onDidVisibilityChange(s=>{this._isVisible=s.isVisible}),this.onDidDimensionsChange(s=>{this._width=s.width,this._height=s.height}),this.panelUpdatesDisposable,this._onDidDimensionChange,this._onDidChangeFocus,this._onDidVisibilityChange,this._onDidActiveChange,this._onWillFocus,this._onActiveChange,this._onWillFocus,this._onWillVisibilityChange,this._onDidParametersChange)}getParameters(){return this._parameters}initialize(t){this.panelUpdatesDisposable.value=this._onDidParametersChange.event(n=>{this._parameters=n,t.update({params:n})})}setVisible(t){this._onWillVisibilityChange.fire({isVisible:t})}setActive(){this._onActiveChange.fire()}updateParameters(t){this._onDidParametersChange.fire(t)}}class CA extends SA{constructor(t,n){super(t,n),this._onDidConstraintsChangeInternal=new te,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new te({replay:!0}),this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new te,this.onDidSizeChange=this._onDidSizeChange.event,this.addDisposables(this._onDidConstraintsChangeInternal,this._onDidConstraintsChange,this._onDidSizeChange)}setConstraints(t){this._onDidConstraintsChangeInternal.fire(t)}setSize(t){this._onDidSizeChange.fire(t)}}class H5 extends CA{set pane(t){this._pane=t}constructor(t,n){super(t,n),this._onDidExpansionChange=new te({replay:!0}),this.onDidExpansionChange=this._onDidExpansionChange.event,this._onMouseEnter=new te({}),this.onMouseEnter=this._onMouseEnter.event,this._onMouseLeave=new te({}),this.onMouseLeave=this._onMouseLeave.event,this.addDisposables(this._onDidExpansionChange,this._onMouseEnter,this._onMouseLeave)}setExpanded(t){var n;(n=this._pane)===null||n===void 0||n.setExpanded(t)}get isExpanded(){var t;return!!(!((t=this._pane)===null||t===void 0)&&t.isExpanded())}}class Gb extends Ge{get element(){return this._element}get width(){return this._width}get height(){return this._height}get params(){var t;return(t=this._params)===null||t===void 0?void 0:t.params}constructor(t,n,s){super(),this.id=t,this.component=n,this.api=s,this._height=0,this._width=0,this._element=document.createElement("div"),this._element.tabIndex=-1,this._element.style.outline="none",this._element.style.height="100%",this._element.style.width="100%",this._element.style.overflow="hidden";const a=pA(this._element);this.addDisposables(this.api,a.onDidFocus(()=>{this.api._onDidChangeFocus.fire({isFocused:!0})}),a.onDidBlur(()=>{this.api._onDidChangeFocus.fire({isFocused:!1})}),a)}focus(){const t=new kA;this.api._onWillFocus.fire(t),!t.defaultPrevented&&this._element.focus()}layout(t,n){this._width=t,this._height=n,this.api._onDidDimensionChange.fire({width:t,height:n}),this.part&&this._params&&this.part.update(this._params.params)}init(t){this._params=t,this.part=this.getComponent()}update(t){var n,s;this._params=Object.assign(Object.assign({},this._params),{params:Object.assign(Object.assign({},(n=this._params)===null||n===void 0?void 0:n.params),t.params)});for(const a of Object.keys(t.params))t.params[a]===void 0&&delete this._params.params[a];(s=this.part)===null||s===void 0||s.update({params:this._params.params})}toJSON(){var t,n;const s=(n=(t=this._params)===null||t===void 0?void 0:t.params)!==null&&n!==void 0?n:{};return{id:this.id,component:this.component,params:Object.keys(s).length>0?s:void 0}}dispose(){var t;this.api.dispose(),(t=this.part)===null||t===void 0||t.dispose(),super.dispose()}}class V5 extends Gb{set orientation(t){this._orientation=t}get orientation(){return this._orientation}get minimumSize(){const t=this.headerSize,s=this.isExpanded()?this._minimumBodySize:0;return t+s}get maximumSize(){const t=this.headerSize,s=this.isExpanded()?this._maximumBodySize:0;return t+s}get size(){return this._size}get orthogonalSize(){return this._orthogonalSize}set orthogonalSize(t){this._orthogonalSize=t}get minimumBodySize(){return this._minimumBodySize}set minimumBodySize(t){this._minimumBodySize=typeof t=="number"?t:0}get maximumBodySize(){return this._maximumBodySize}set maximumBodySize(t){this._maximumBodySize=typeof t=="number"?t:Number.POSITIVE_INFINITY}get headerVisible(){return this._headerVisible}set headerVisible(t){this._headerVisible=t,this.header.style.display=t?"":"none"}constructor(t){super(t.id,t.component,new H5(t.id,t.component)),this._onDidChangeExpansionState=new te({replay:!0}),this.onDidChangeExpansionState=this._onDidChangeExpansionState.event,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._orthogonalSize=0,this._size=0,this._isExpanded=!1,this.api.pane=this,this.api.initialize(this),this.headerSize=t.headerSize,this.headerComponent=t.headerComponent,this._minimumBodySize=t.minimumBodySize,this._maximumBodySize=t.maximumBodySize,this._isExpanded=t.isExpanded,this._headerVisible=t.isHeaderVisible,this._onDidChangeExpansionState.fire(this.isExpanded()),this._orientation=t.orientation,this.element.classList.add("dv-pane"),this.addDisposables(this.api.onWillVisibilityChange(n=>{const{isVisible:s}=n,{accessor:a}=this._params;a.setVisible(this,s)}),this.api.onDidSizeChange(n=>{this._onDidChange.fire({size:n.size})}),Fe(this.element,"mouseenter",n=>{this.api._onMouseEnter.fire(n)}),Fe(this.element,"mouseleave",n=>{this.api._onMouseLeave.fire(n)})),this.addDisposables(this._onDidChangeExpansionState,this.onDidChangeExpansionState(n=>{this.api._onDidExpansionChange.fire({isExpanded:n})}),this.api.onDidFocusChange(n=>{this.header&&(n.isFocused?im(this.header,"focused"):qc(this.header,"focused"))})),this.renderOnce()}setVisible(t){this.api._onDidVisibilityChange.fire({isVisible:t})}setActive(t){this.api._onDidActiveChange.fire({isActive:t})}isExpanded(){return this._isExpanded}setExpanded(t){this._isExpanded!==t&&(this._isExpanded=t,t?(this.animationTimer&&clearTimeout(this.animationTimer),this.body&&this.element.appendChild(this.body)):this.animationTimer=setTimeout(()=>{var n;(n=this.body)===null||n===void 0||n.remove()},200),this._onDidChange.fire(t?{size:this.width}:{}),this._onDidChangeExpansionState.fire(t))}layout(t,n){this._size=t,this._orthogonalSize=n;const[s,a]=this.orientation===Me.HORIZONTAL?[t,n]:[n,t];super.layout(s,a)}init(t){var n,s;super.init(t),typeof t.minimumBodySize=="number"&&(this.minimumBodySize=t.minimumBodySize),typeof t.maximumBodySize=="number"&&(this.maximumBodySize=t.maximumBodySize),this.bodyPart=this.getBodyComponent(),this.headerPart=this.getHeaderComponent(),this.bodyPart.init(Object.assign(Object.assign({},t),{api:this.api})),this.headerPart.init(Object.assign(Object.assign({},t),{api:this.api})),(n=this.body)===null||n===void 0||n.append(this.bodyPart.element),(s=this.header)===null||s===void 0||s.append(this.headerPart.element),typeof t.isExpanded=="boolean"&&this.setExpanded(t.isExpanded)}toJSON(){const t=this._params;return Object.assign(Object.assign({},super.toJSON()),{headerComponent:this.headerComponent,title:t.title})}renderOnce(){this.header=document.createElement("div"),this.header.tabIndex=0,this.header.className="dv-pane-header",this.header.style.height=`${this.headerSize}px`,this.header.style.lineHeight=`${this.headerSize}px`,this.header.style.minHeight=`${this.headerSize}px`,this.header.style.maxHeight=`${this.headerSize}px`,this.element.appendChild(this.header),this.body=document.createElement("div"),this.body.className="dv-pane-body",this.element.appendChild(this.body)}getComponent(){return{update:t=>{var n,s;(n=this.bodyPart)===null||n===void 0||n.update({params:t}),(s=this.headerPart)===null||s===void 0||s.update({params:t})},dispose:()=>{var t,n;(t=this.bodyPart)===null||t===void 0||t.dispose(),(n=this.headerPart)===null||n===void 0||n.dispose()}}}}class U5 extends V5{constructor(t){super({id:t.id,component:t.component,headerComponent:t.headerComponent,orientation:t.orientation,isExpanded:t.isExpanded,isHeaderVisible:!0,headerSize:t.headerSize,minimumBodySize:t.minimumBodySize,maximumBodySize:t.maximumBodySize}),this._onDidDrop=new te,this.onDidDrop=this._onDidDrop.event,this._onUnhandledDragOverEvent=new te,this.onUnhandledDragOverEvent=this._onUnhandledDragOverEvent.event,this.accessor=t.accessor,this.addDisposables(this._onDidDrop,this._onUnhandledDragOverEvent),t.disableDnd||this.initDragFeatures()}initDragFeatures(){if(!this.header)return;const t=this.id,n=this.accessor.id;this.header.draggable=!0,this.handler=new class extends Ib{getData(){return vi.getInstance().setData([new gc(n,t)],gc.prototype),{dispose:()=>{vi.getInstance().clearData(gc.prototype)}}}}(this.header),this.target=new Vs(this.element,{acceptedTargetZones:["top","bottom"],overlayModel:{activationSize:{type:"percentage",value:50}},canDisplayOverlay:(s,a)=>{const r=Ml();if(r&&r.paneId!==this.id&&r.viewId===this.accessor.id)return!0;const o=new G5(s,a,Ml,this);return this._onUnhandledDragOverEvent.fire(o),o.isAccepted}}),this.addDisposables(this._onDidDrop,this.handler,this.target,this.target.onDrop(s=>{this.onDrop(s)}))}onDrop(t){const n=Ml();if(!n||n.viewId!==this.accessor.id){this._onDidDrop.fire(Object.assign(Object.assign({},t),{panel:this,api:new Xc(this.accessor),getData:Ml}));return}const s=this._params.containerApi,a=n.paneId,r=s.getPanel(a);if(!r){this._onDidDrop.fire(Object.assign(Object.assign({},t),{panel:this,getData:Ml,api:new Xc(this.accessor)}));return}const o=s.panels,l=o.indexOf(r);let c=s.panels.indexOf(this);(t.position==="left"||t.position==="top")&&(c=Math.max(0,c-1)),(t.position==="right"||t.position==="bottom")&&(l>c&&c++,c=Math.min(o.length-1,c)),s.movePanel(l,c)}}class B5 extends Ge{get element(){return this._element}constructor(t,n){super(),this.accessor=t,this.group=n,this.disposable=new On,this._onDidFocus=new te,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new te,this.onDidBlur=this._onDidBlur.event,this._element=document.createElement("div"),this._element.className="dv-content-container",this._element.tabIndex=-1,this.addDisposables(this._onDidFocus,this._onDidBlur);const s=n.dropTargetContainer;this.dropTarget=new Vs(this.element,{getOverlayOutline:()=>{var a;return((a=t.options.theme)===null||a===void 0?void 0:a.dndPanelOverlay)==="group"?this.element.parentElement:null},className:"dv-drop-target-content",acceptedTargetZones:["top","bottom","left","right","center"],canDisplayOverlay:(a,r)=>{if(this.group.locked==="no-drop-target"||this.group.locked&&r==="center")return!1;const o=En();return!o&&a.shiftKey&&this.group.location.type!=="floating"?!1:o&&o.viewId===this.accessor.id?!0:this.group.canDisplayOverlay(a,r,"content")},getOverrideTarget:s?()=>s.model:void 0}),this.addDisposables(this.dropTarget)}show(){this.element.style.display=""}hide(){this.element.style.display="none"}renderPanel(t,n={asActive:!0}){const s=n.asActive||this.panel&&this.group.isPanelActive(this.panel);this.panel&&this.panel.view.content.element.parentElement===this._element&&this._element.removeChild(this.panel.view.content.element),this.panel=t;let a;switch(t.api.renderer){case"onlyWhenVisible":this.group.renderContainer.detatch(t),this.panel&&s&&this._element.appendChild(this.panel.view.content.element),a=this._element;break;case"always":t.view.content.element.parentElement===this._element&&this._element.removeChild(t.view.content.element),a=this.group.renderContainer.attach({panel:t,referenceContainer:this});break;default:throw new Error(`dockview: invalid renderer type '${t.api.renderer}'`)}if(s){const r=pA(a),o=new Ge;o.addDisposables(r,r.onDidFocus(()=>this._onDidFocus.fire()),r.onDidBlur(()=>this._onDidBlur.fire())),this.disposable.value=o}}openPanel(t){this.panel!==t&&this.renderPanel(t)}layout(t,n){}closePanel(){var t;this.panel&&this.panel.api.renderer==="onlyWhenVisible"&&((t=this.panel.view.content.element.parentElement)===null||t===void 0||t.removeChild(this.panel.view.content.element)),this.panel=void 0}dispose(){this.disposable.dispose(),super.dispose()}}function DA(e,t,n){var s,a;im(t,"dv-dragged"),t.style.top="-9999px",document.body.appendChild(t),e.setDragImage(t,(s=n==null?void 0:n.x)!==null&&s!==void 0?s:0,(a=n==null?void 0:n.y)!==null&&a!==void 0?a:0),setTimeout(()=>{qc(t,"dv-dragged"),t.remove()},0)}class W5 extends Ib{constructor(t,n,s,a,r){super(t,r),this.accessor=n,this.group=s,this.panel=a,this.panelTransfer=vi.getInstance()}getData(t){return this.panelTransfer.setData([new Ta(this.accessor.id,this.group.id,this.panel.id)],Ta.prototype),{dispose:()=>{this.panelTransfer.clearData(Ta.prototype)}}}}class F5 extends Ge{get element(){return this._element}constructor(t,n,s){super(),this.panel=t,this.accessor=n,this.group=s,this.content=void 0,this._onPointDown=new te,this.onPointerDown=this._onPointDown.event,this._onDropped=new te,this.onDrop=this._onDropped.event,this._onDragStart=new te,this.onDragStart=this._onDragStart.event,this._element=document.createElement("div"),this._element.className="dv-tab",this._element.tabIndex=0,this._element.draggable=!this.accessor.options.disableDnd,Pe(this.element,"dv-inactive-tab",!0),this.dragHandler=new W5(this._element,this.accessor,this.group,this.panel,!!this.accessor.options.disableDnd),this.dropTarget=new Vs(this._element,{acceptedTargetZones:["left","right"],overlayModel:{activationSize:{value:50,type:"percentage"}},canDisplayOverlay:(a,r)=>{if(this.group.locked)return!1;const o=En();return o&&this.accessor.id===o.viewId?!0:this.group.model.canDisplayOverlay(a,r,"tab")},getOverrideTarget:()=>{var a;return(a=s.model.dropTargetContainer)===null||a===void 0?void 0:a.model}}),this.onWillShowOverlay=this.dropTarget.onWillShowOverlay,this.addDisposables(this._onPointDown,this._onDropped,this._onDragStart,this.dragHandler.onDragStart(a=>{if(a.dataTransfer){const r=getComputedStyle(this.element),o=this.element.cloneNode(!0);Array.from(r).forEach(l=>o.style.setProperty(l,r.getPropertyValue(l),r.getPropertyPriority(l))),o.style.position="absolute",DA(a.dataTransfer,o,{y:-10,x:30})}this._onDragStart.fire(a)}),this.dragHandler,Fe(this._element,"pointerdown",a=>{this._onPointDown.fire(a)}),this.dropTarget.onDrop(a=>{this._onDropped.fire(a)}),this.dropTarget)}setActive(t){Pe(this.element,"dv-active-tab",t),Pe(this.element,"dv-inactive-tab",!t)}setContent(t){this.content&&this._element.removeChild(this.content.element),this.content=t,this._element.appendChild(this.content.element)}updateDragAndDropState(){this._element.draggable=!this.accessor.options.disableDnd,this.dragHandler.setDisabled(!!this.accessor.options.disableDnd)}dispose(){super.dispose()}}class rm{get kind(){return this.options.kind}get nativeEvent(){return this.event.nativeEvent}get position(){return this.event.position}get defaultPrevented(){return this.event.defaultPrevented}get panel(){return this.options.panel}get api(){return this.options.api}get group(){return this.options.group}preventDefault(){this.event.preventDefault()}getData(){return this.options.getData()}constructor(t,n){this.event=t,this.options=n}}class q5 extends Ib{constructor(t,n,s,a){super(t,a),this.accessor=n,this.group=s,this.panelTransfer=vi.getInstance(),this.addDisposables(Fe(t,"pointerdown",r=>{r.shiftKey&&u5(r)},!0))}isCancelled(t){return this.group.api.location.type==="floating"&&!t.shiftKey}getData(t){const n=t.dataTransfer;this.panelTransfer.setData([new Ta(this.accessor.id,this.group.id,null)],Ta.prototype);const s=window.getComputedStyle(this.el),a=s.getPropertyValue("--dv-activegroup-visiblepanel-tab-background-color"),r=s.getPropertyValue("--dv-activegroup-visiblepanel-tab-color");if(n){const o=document.createElement("div");o.style.backgroundColor=a,o.style.color=r,o.style.padding="2px 8px",o.style.height="24px",o.style.fontSize="11px",o.style.lineHeight="20px",o.style.borderRadius="12px",o.style.position="absolute",o.style.pointerEvents="none",o.style.top="-9999px",o.textContent=`Multiple Panels (${this.group.size})`,DA(n,o,{y:-10,x:30})}return{dispose:()=>{this.panelTransfer.clearData(Ta.prototype)}}}}class Y5 extends Ge{get element(){return this._element}constructor(t,n){super(),this.accessor=t,this.group=n,this._onDrop=new te,this.onDrop=this._onDrop.event,this._onDragStart=new te,this.onDragStart=this._onDragStart.event,this._element=document.createElement("div"),this._element.className="dv-void-container",this._element.draggable=!this.accessor.options.disableDnd,Pe(this._element,"dv-draggable",!this.accessor.options.disableDnd),this.addDisposables(this._onDrop,this._onDragStart,Fe(this._element,"pointerdown",()=>{this.accessor.doSetGroupActive(this.group)})),this.handler=new q5(this._element,t,n,!!this.accessor.options.disableDnd),this.dropTarget=new Vs(this._element,{acceptedTargetZones:["center"],canDisplayOverlay:(s,a)=>{const r=En();return r&&this.accessor.id===r.viewId?!0:n.model.canDisplayOverlay(s,a,"header_space")},getOverrideTarget:()=>{var s;return(s=n.model.dropTargetContainer)===null||s===void 0?void 0:s.model}}),this.onWillShowOverlay=this.dropTarget.onWillShowOverlay,this.addDisposables(this.handler,this.handler.onDragStart(s=>{this._onDragStart.fire(s)}),this.dropTarget.onDrop(s=>{this._onDrop.fire(s)}),this.dropTarget)}updateDragAndDropState(){this._element.draggable=!this.accessor.options.disableDnd,Pe(this._element,"dv-draggable",!this.accessor.options.disableDnd),this.handler.setDisabled(!!this.accessor.options.disableDnd)}}class om extends Ge{get element(){return this._element}constructor(t){super(),this.scrollableElement=t,this._scrollLeft=0,this._element=document.createElement("div"),this._element.className="dv-scrollable",this._horizontalScrollbar=document.createElement("div"),this._horizontalScrollbar.className="dv-scrollbar-horizontal",this.element.appendChild(t),this.element.appendChild(this._horizontalScrollbar),this.addDisposables(Fe(this.element,"wheel",n=>{this._scrollLeft+=n.deltaY*om.MouseWheelSpeed,this.calculateScrollbarStyles()}),Fe(this._horizontalScrollbar,"pointerdown",n=>{n.preventDefault(),Pe(this.element,"dv-scrollable-scrolling",!0);const s=n.clientX,a=this._scrollLeft,r=l=>{const c=l.clientX-s,{clientWidth:d}=this.element,{scrollWidth:h}=this.scrollableElement,f=d/h;this._scrollLeft=a+c/f,this.calculateScrollbarStyles()},o=()=>{Pe(this.element,"dv-scrollable-scrolling",!1),document.removeEventListener("pointermove",r),document.removeEventListener("pointerup",o),document.removeEventListener("pointercancel",o)};document.addEventListener("pointermove",r),document.addEventListener("pointerup",o),document.addEventListener("pointercancel",o)}),Fe(this.element,"scroll",()=>{this.calculateScrollbarStyles()}),Fe(this.scrollableElement,"scroll",()=>{this._scrollLeft=this.scrollableElement.scrollLeft,this.calculateScrollbarStyles()}),sm(this.element,()=>{Pe(this.element,"dv-scrollable-resizing",!0),this._animationTimer&&clearTimeout(this._animationTimer),this._animationTimer=setTimeout(()=>{clearTimeout(this._animationTimer),Pe(this.element,"dv-scrollable-resizing",!1)},500),this.calculateScrollbarStyles()}))}calculateScrollbarStyles(){const{clientWidth:t}=this.element,{scrollWidth:n}=this.scrollableElement;if(n>t){const a=t*(t/n);this._horizontalScrollbar.style.width=`${a}px`,this._scrollLeft=Rt(this._scrollLeft,0,this.scrollableElement.scrollWidth-t),this.scrollableElement.scrollLeft=this._scrollLeft;const r=this._scrollLeft/(n-t);this._horizontalScrollbar.style.left=`${(t-a)*r}px`}else this._horizontalScrollbar.style.width="0px",this._horizontalScrollbar.style.left="0px",this._scrollLeft=0}}om.MouseWheelSpeed=1;class X5 extends Ge{get showTabsOverflowControl(){return this._showTabsOverflowControl}set showTabsOverflowControl(t){if(this._showTabsOverflowControl!=t&&(this._showTabsOverflowControl=t,t)){const n=new c5(this._tabsList);this._observerDisposable.value=new Ge(n,n.onDidChange(s=>{const a=s.hasScrollX||s.hasScrollY;this.toggleDropdown({reset:!a})}),Fe(this._tabsList,"scroll",()=>{this.toggleDropdown({reset:!1})}))}}get element(){return this._element}get panels(){return this._tabs.map(t=>t.value.panel.id)}get size(){return this._tabs.length}get tabs(){return this._tabs.map(t=>t.value)}constructor(t,n,s){if(super(),this.group=t,this.accessor=n,this._observerDisposable=new On,this._tabs=[],this.selectedIndex=-1,this._showTabsOverflowControl=!1,this._onTabDragStart=new te,this.onTabDragStart=this._onTabDragStart.event,this._onDrop=new te,this.onDrop=this._onDrop.event,this._onWillShowOverlay=new te,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onOverflowTabsChange=new te,this.onOverflowTabsChange=this._onOverflowTabsChange.event,this._tabsList=document.createElement("div"),this._tabsList.className="dv-tabs-container dv-horizontal",this.showTabsOverflowControl=s.showTabsOverflowControl,n.options.scrollbars==="native")this._element=this._tabsList;else{const a=new om(this._tabsList);this._element=a.element,this.addDisposables(a)}this.addDisposables(this._onOverflowTabsChange,this._observerDisposable,this._onWillShowOverlay,this._onDrop,this._onTabDragStart,Fe(this.element,"pointerdown",a=>{if(a.defaultPrevented)return;a.button===0&&this.accessor.doSetGroupActive(this.group)}),Zt.from(()=>{for(const{value:a,disposable:r}of this._tabs)r.dispose(),a.dispose();this._tabs=[]}))}indexOf(t){return this._tabs.findIndex(n=>n.value.panel.id===t)}isActive(t){return this.selectedIndex>-1&&this._tabs[this.selectedIndex].value===t}setActivePanel(t){let n=0;for(const s of this._tabs){const a=t.id===s.value.panel.id;if(s.value.setActive(a),a){const r=s.value.element,o=r.parentElement;(n<o.scrollLeft||n+r.clientWidth>o.scrollLeft+o.clientWidth)&&(o.scrollLeft=n)}n+=s.value.element.clientWidth}}openPanel(t,n=this._tabs.length){if(this._tabs.find(o=>o.value.panel.id===t.id))return;const s=new F5(t,this.accessor,this.group);s.setContent(t.view.tab);const a=new Ge(s.onDragStart(o=>{this._onTabDragStart.fire({nativeEvent:o,panel:t})}),s.onPointerDown(o=>{if(o.defaultPrevented)return;const l=!this.accessor.options.disableFloatingGroups,c=this.group.api.location.type==="floating"&&this.size===1;if(l&&!c&&o.shiftKey){o.preventDefault();const d=this.accessor.getGroupPanel(s.panel.id),{top:h,left:f}=s.element.getBoundingClientRect(),{top:m,left:p}=this.accessor.element.getBoundingClientRect();this.accessor.addFloatingGroup(d,{x:f-p,y:h-m,inDragMode:!0});return}switch(o.button){case 0:this.group.activePanel!==t&&this.group.model.openPanel(t);break}}),s.onDrop(o=>{this._onDrop.fire({event:o.nativeEvent,index:this._tabs.findIndex(l=>l.value===s)})}),s.onWillShowOverlay(o=>{this._onWillShowOverlay.fire(new rm(o,{kind:"tab",panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:En}))})),r={value:s,disposable:a};this.addTab(r,n)}delete(t){const n=this.indexOf(t),s=this._tabs.splice(n,1)[0],{value:a,disposable:r}=s;r.dispose(),a.dispose(),a.element.remove()}addTab(t,n=this._tabs.length){if(n<0||n>this._tabs.length)throw new Error("invalid location");this._tabsList.insertBefore(t.value.element,this._tabsList.children[n]),this._tabs=[...this._tabs.slice(0,n),t,...this._tabs.slice(n)],this.selectedIndex<0&&(this.selectedIndex=n)}toggleDropdown(t){const n=t.reset?[]:this._tabs.filter(s=>!x5(s.value.element,this._tabsList)).map(s=>s.value.panel.id);this._onOverflowTabsChange.fire({tabs:n,reset:t.reset})}updateDragAndDropState(){for(const t of this._tabs)t.value.updateDragAndDropState()}}const Hb=e=>{const t=document.createElementNS("http://www.w3.org/2000/svg","svg");t.setAttributeNS(null,"height",e.height),t.setAttributeNS(null,"width",e.width),t.setAttributeNS(null,"viewBox",e.viewbox),t.setAttributeNS(null,"aria-hidden","false"),t.setAttributeNS(null,"focusable","false"),t.classList.add("dv-svg");const n=document.createElementNS("http://www.w3.org/2000/svg","path");return n.setAttributeNS(null,"d",e.path),t.appendChild(n),t},K5=()=>Hb({width:"11",height:"11",viewbox:"0 0 28 28",path:"M2.1 27.3L0 25.2L11.55 13.65L0 2.1L2.1 0L13.65 11.55L25.2 0L27.3 2.1L15.75 13.65L27.3 25.2L25.2 27.3L13.65 15.75L2.1 27.3Z"}),Z5=()=>Hb({width:"11",height:"11",viewbox:"0 0 24 15",path:"M12 14.15L0 2.15L2.15 0L12 9.9L21.85 0.0499992L24 2.2L12 14.15Z"}),EA=()=>Hb({width:"11",height:"11",viewbox:"0 0 15 25",path:"M2.15 24.1L0 21.95L9.9 12.05L0 2.15L2.15 0L14.2 12.05L2.15 24.1Z"});function Q5(){const e=document.createElement("div");e.className="dv-tabs-overflow-dropdown-default";const t=document.createElement("span");t.textContent="";const n=EA();return e.appendChild(n),e.appendChild(t),{element:e,update:s=>{t.textContent=`${s.tabs}`}}}class J5 extends Ge{get onTabDragStart(){return this.tabs.onTabDragStart}get panels(){return this.tabs.panels}get size(){return this.tabs.size}get hidden(){return this._hidden}set hidden(t){this._hidden=t,this.element.style.display=t?"none":""}get element(){return this._element}constructor(t,n){super(),this.accessor=t,this.group=n,this._hidden=!1,this.dropdownPart=null,this._overflowTabs=[],this._dropdownDisposable=new On,this._onDrop=new te,this.onDrop=this._onDrop.event,this._onGroupDragStart=new te,this.onGroupDragStart=this._onGroupDragStart.event,this._onWillShowOverlay=new te,this.onWillShowOverlay=this._onWillShowOverlay.event,this._element=document.createElement("div"),this._element.className="dv-tabs-and-actions-container",Pe(this._element,"dv-full-width-single-tab",this.accessor.options.singleTabMode==="fullwidth"),this.rightActionsContainer=document.createElement("div"),this.rightActionsContainer.className="dv-right-actions-container",this.leftActionsContainer=document.createElement("div"),this.leftActionsContainer.className="dv-left-actions-container",this.preActionsContainer=document.createElement("div"),this.preActionsContainer.className="dv-pre-actions-container",this.tabs=new X5(n,t,{showTabsOverflowControl:!t.options.disableTabsOverflowList}),this.voidContainer=new Y5(this.accessor,this.group),this._element.appendChild(this.preActionsContainer),this._element.appendChild(this.tabs.element),this._element.appendChild(this.leftActionsContainer),this._element.appendChild(this.voidContainer.element),this._element.appendChild(this.rightActionsContainer),this.addDisposables(this.tabs.onDrop(s=>this._onDrop.fire(s)),this.tabs.onWillShowOverlay(s=>this._onWillShowOverlay.fire(s)),t.onDidOptionsChange(()=>{this.tabs.showTabsOverflowControl=!t.options.disableTabsOverflowList}),this.tabs.onOverflowTabsChange(s=>{this.toggleDropdown(s)}),this.tabs,this._onWillShowOverlay,this._onDrop,this._onGroupDragStart,this.voidContainer,this.voidContainer.onDragStart(s=>{this._onGroupDragStart.fire({nativeEvent:s,group:this.group})}),this.voidContainer.onDrop(s=>{this._onDrop.fire({event:s.nativeEvent,index:this.tabs.size})}),this.voidContainer.onWillShowOverlay(s=>{this._onWillShowOverlay.fire(new rm(s,{kind:"header_space",panel:this.group.activePanel,api:this.accessor.api,group:this.group,getData:En}))}),Fe(this.voidContainer.element,"pointerdown",s=>{if(s.defaultPrevented)return;if(!this.accessor.options.disableFloatingGroups&&s.shiftKey&&this.group.api.location.type!=="floating"){s.preventDefault();const{top:r,left:o}=this.element.getBoundingClientRect(),{top:l,left:c}=this.accessor.element.getBoundingClientRect();this.accessor.addFloatingGroup(this.group,{x:o-c+20,y:r-l+20,inDragMode:!0})}}))}show(){this.hidden||(this.element.style.display="")}hide(){this._element.style.display="none"}setRightActionsElement(t){this.rightActions!==t&&(this.rightActions&&(this.rightActions.remove(),this.rightActions=void 0),t&&(this.rightActionsContainer.appendChild(t),this.rightActions=t))}setLeftActionsElement(t){this.leftActions!==t&&(this.leftActions&&(this.leftActions.remove(),this.leftActions=void 0),t&&(this.leftActionsContainer.appendChild(t),this.leftActions=t))}setPrefixActionsElement(t){this.preActions!==t&&(this.preActions&&(this.preActions.remove(),this.preActions=void 0),t&&(this.preActionsContainer.appendChild(t),this.preActions=t))}isActive(t){return this.tabs.isActive(t)}indexOf(t){return this.tabs.indexOf(t)}setActive(t){}delete(t){this.tabs.delete(t),this.updateClassnames()}setActivePanel(t){this.tabs.setActivePanel(t)}openPanel(t,n=this.tabs.size){this.tabs.openPanel(t,n),this.updateClassnames()}closePanel(t){this.delete(t.id)}updateClassnames(){Pe(this._element,"dv-single-tab",this.size===1)}toggleDropdown(t){const n=t.reset?[]:t.tabs;if(this._overflowTabs=n,this._overflowTabs.length>0&&this.dropdownPart){this.dropdownPart.update({tabs:n.length});return}if(this._overflowTabs.length===0){this._dropdownDisposable.dispose();return}const s=document.createElement("div");s.className="dv-tabs-overflow-dropdown-root";const a=Q5();a.update({tabs:n.length}),this.dropdownPart=a,s.appendChild(a.element),this.rightActionsContainer.prepend(s),this._dropdownDisposable.value=new Ge(Zt.from(()=>{var r,o;s.remove(),(o=(r=this.dropdownPart)===null||r===void 0?void 0:r.dispose)===null||o===void 0||o.call(r),this.dropdownPart=null}),Fe(s,"pointerdown",r=>{r.preventDefault()},{capture:!0}),Fe(s,"click",r=>{const o=document.createElement("div");o.style.overflow="auto",o.className="dv-tabs-overflow-container";for(const c of this.tabs.tabs.filter(d=>this._overflowTabs.includes(d.panel.id))){const d=this.group.panels.find(p=>p===c.panel),f=d.view.createTabRenderer("headerOverflow").element,m=document.createElement("div");Pe(m,"dv-tab",!0),Pe(m,"dv-active-tab",d.api.isActive),Pe(m,"dv-inactive-tab",!d.api.isActive),m.addEventListener("click",p=>{this.accessor.popupService.close(),!p.defaultPrevented&&(c.element.scrollIntoView(),c.panel.api.setActive())}),m.appendChild(f),o.appendChild(m)}const l=w5(s);this.accessor.popupService.openPopover(o,{x:r.clientX,y:r.clientY,zIndex:l!=null&&l.style.zIndex?`calc(${l.style.zIndex} * 2)`:void 0})}))}updateDragAndDropState(){this.tabs.updateDragAndDropState(),this.voidContainer.updateDragAndDropState()}}class AA extends mA{constructor(t,n,s,a,r){super(),this.nativeEvent=t,this.target=n,this.position=s,this.getData=a,this.group=r}}const mx=Object.keys({disableAutoResizing:void 0,hideBorders:void 0,singleTabMode:void 0,disableFloatingGroups:void 0,floatingGroupBounds:void 0,popoutUrl:void 0,defaultRenderer:void 0,debug:void 0,rootOverlayModel:void 0,locked:void 0,disableDnd:void 0,className:void 0,noPanelsOverlay:void 0,dndEdges:void 0,theme:void 0,disableTabsOverflowList:void 0,scrollbars:void 0});function e8(e){return!!e.referencePanel}function t8(e){return!!e.referenceGroup}function n8(e){return!!e.referencePanel}function s8(e){return!!e.referenceGroup}class Vb extends $b{get nativeEvent(){return this.options.nativeEvent}get position(){return this.options.position}get panel(){return this.options.panel}get group(){return this.options.group}get api(){return this.options.api}constructor(t){super(),this.options=t}getData(){return this.options.getData()}}class RA extends Vb{get kind(){return this._kind}constructor(t){super(t),this._kind=t.kind}}class i8 extends Ge{get element(){throw new Error("dockview: not supported")}get activePanel(){return this._activePanel}get locked(){return this._locked}set locked(t){this._locked=t,Pe(this.container,"dv-locked-groupview",t==="no-drop-target"||t)}get isActive(){return this._isGroupActive}get panels(){return this._panels}get size(){return this._panels.length}get isEmpty(){return this._panels.length===0}get hasWatermark(){return!!(this.watermark&&this.container.contains(this.watermark.element))}get header(){return this.tabsContainer}get isContentFocused(){return document.activeElement?rx(document.activeElement,this.contentContainer.element):!1}get location(){return this._location}set location(t){switch(this._location=t,Pe(this.container,"dv-groupview-floating",!1),Pe(this.container,"dv-groupview-popout",!1),t.type){case"grid":this.contentContainer.dropTarget.setTargetZones(["top","bottom","left","right","center"]);break;case"floating":this.contentContainer.dropTarget.setTargetZones(["center"]),this.contentContainer.dropTarget.setTargetZones(t?["center"]:["top","bottom","left","right","center"]),Pe(this.container,"dv-groupview-floating",!0);break;case"popout":this.contentContainer.dropTarget.setTargetZones(["center"]),Pe(this.container,"dv-groupview-popout",!0);break}this.groupPanel.api._onDidLocationChange.fire({location:this.location})}constructor(t,n,s,a,r){var o;super(),this.container=t,this.accessor=n,this.id=s,this.options=a,this.groupPanel=r,this._isGroupActive=!1,this._locked=!1,this._location={type:"grid"},this.mostRecentlyUsed=[],this._overwriteRenderContainer=null,this._overwriteDropTargetContainer=null,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._width=0,this._height=0,this._panels=[],this._panelDisposables=new Map,this._onMove=new te,this.onMove=this._onMove.event,this._onDidDrop=new te,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new te,this.onWillDrop=this._onWillDrop.event,this._onWillShowOverlay=new te,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onTabDragStart=new te,this.onTabDragStart=this._onTabDragStart.event,this._onGroupDragStart=new te,this.onGroupDragStart=this._onGroupDragStart.event,this._onDidAddPanel=new te,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPanelTitleChange=new te,this.onDidPanelTitleChange=this._onDidPanelTitleChange.event,this._onDidPanelParametersChange=new te,this.onDidPanelParametersChange=this._onDidPanelParametersChange.event,this._onDidRemovePanel=new te,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidActivePanelChange=new te,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onUnhandledDragOverEvent=new te,this.onUnhandledDragOverEvent=this._onUnhandledDragOverEvent.event,Pe(this.container,"dv-groupview",!0),this._api=new Gh(this.accessor),this.tabsContainer=new J5(this.accessor,this.groupPanel),this.contentContainer=new B5(this.accessor,this),t.append(this.tabsContainer.element,this.contentContainer.element),this.header.hidden=!!a.hideHeader,this.locked=(o=a.locked)!==null&&o!==void 0?o:!1,this.addDisposables(this._onTabDragStart,this._onGroupDragStart,this._onWillShowOverlay,this.tabsContainer.onTabDragStart(l=>{this._onTabDragStart.fire(l)}),this.tabsContainer.onGroupDragStart(l=>{this._onGroupDragStart.fire(l)}),this.tabsContainer.onDrop(l=>{this.handleDropEvent("header",l.event,"center",l.index)}),this.contentContainer.onDidFocus(()=>{this.accessor.doSetGroupActive(this.groupPanel)}),this.contentContainer.onDidBlur(()=>{}),this.contentContainer.dropTarget.onDrop(l=>{this.handleDropEvent("content",l.nativeEvent,l.position)}),this.tabsContainer.onWillShowOverlay(l=>{this._onWillShowOverlay.fire(l)}),this.contentContainer.dropTarget.onWillShowOverlay(l=>{this._onWillShowOverlay.fire(new rm(l,{kind:"content",panel:this.activePanel,api:this._api,group:this.groupPanel,getData:En}))}),this._onMove,this._onDidChange,this._onDidDrop,this._onWillDrop,this._onDidAddPanel,this._onDidRemovePanel,this._onDidActivePanelChange,this._onUnhandledDragOverEvent,this._onDidPanelTitleChange,this._onDidPanelParametersChange)}focusContent(){this.contentContainer.element.focus()}set renderContainer(t){this.panels.forEach(n=>{this.renderContainer.detatch(n)}),this._overwriteRenderContainer=t,this.panels.forEach(n=>{this.rerender(n)})}get renderContainer(){var t;return(t=this._overwriteRenderContainer)!==null&&t!==void 0?t:this.accessor.overlayRenderContainer}set dropTargetContainer(t){this._overwriteDropTargetContainer=t}get dropTargetContainer(){var t;return(t=this._overwriteDropTargetContainer)!==null&&t!==void 0?t:this.accessor.rootDropTargetContainer}initialize(){this.options.panels&&this.options.panels.forEach(t=>{this.doAddPanel(t)}),this.options.activePanel&&this.openPanel(this.options.activePanel),this.setActive(this.isActive,!0),this.updateContainer(),this.accessor.options.createRightHeaderActionComponent&&(this._rightHeaderActions=this.accessor.options.createRightHeaderActionComponent(this.groupPanel),this.addDisposables(this._rightHeaderActions),this._rightHeaderActions.init({containerApi:this._api,api:this.groupPanel.api,group:this.groupPanel}),this.tabsContainer.setRightActionsElement(this._rightHeaderActions.element)),this.accessor.options.createLeftHeaderActionComponent&&(this._leftHeaderActions=this.accessor.options.createLeftHeaderActionComponent(this.groupPanel),this.addDisposables(this._leftHeaderActions),this._leftHeaderActions.init({containerApi:this._api,api:this.groupPanel.api,group:this.groupPanel}),this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element)),this.accessor.options.createPrefixHeaderActionComponent&&(this._prefixHeaderActions=this.accessor.options.createPrefixHeaderActionComponent(this.groupPanel),this.addDisposables(this._prefixHeaderActions),this._prefixHeaderActions.init({containerApi:this._api,api:this.groupPanel.api,group:this.groupPanel}),this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element))}rerender(t){this.contentContainer.renderPanel(t,{asActive:!1})}indexOf(t){return this.tabsContainer.indexOf(t.id)}toJSON(){var t;const n={views:this.tabsContainer.panels,activeView:(t=this._activePanel)===null||t===void 0?void 0:t.id,id:this.id};return this.locked!==!1&&(n.locked=this.locked),this.header.hidden&&(n.hideHeader=!0),n}moveToNext(t){t||(t={}),t.panel||(t.panel=this.activePanel);const n=t.panel?this.panels.indexOf(t.panel):-1;let s;if(n<this.panels.length-1)s=n+1;else if(!t.suppressRoll)s=0;else return;this.openPanel(this.panels[s])}moveToPrevious(t){if(t||(t={}),t.panel||(t.panel=this.activePanel),!t.panel)return;const n=this.panels.indexOf(t.panel);let s;if(n>0)s=n-1;else if(!t.suppressRoll)s=this.panels.length-1;else return;this.openPanel(this.panels[s])}containsPanel(t){return this.panels.includes(t)}init(t){}update(t){}focus(){var t;(t=this._activePanel)===null||t===void 0||t.focus()}openPanel(t,n={}){(typeof n.index!="number"||n.index>this.panels.length)&&(n.index=this.panels.length);const s=!!n.skipSetActive;if(t.updateParentGroup(this.groupPanel,{skipSetActive:n.skipSetActive}),this.doAddPanel(t,n.index,{skipSetActive:s}),this._activePanel===t){this.contentContainer.renderPanel(t,{asActive:!0});return}s||this.doSetActivePanel(t),n.skipSetGroupActive||this.accessor.doSetGroupActive(this.groupPanel),n.skipSetActive||this.updateContainer()}removePanel(t,n={skipSetActive:!1}){const s=typeof t=="string"?t:t.id,a=this._panels.find(r=>r.id===s);if(!a)throw new Error("invalid operation");return this._removePanel(a,n)}closeAllPanels(){if(this.panels.length>0){const t=[...this.panels];for(const n of t)this.doClose(n)}else this.accessor.removeGroup(this.groupPanel)}closePanel(t){this.doClose(t)}doClose(t){const n=this.panels.length===1&&this.accessor.groups.length===1;this.accessor.removePanel(t,n&&this.accessor.options.noPanelsOverlay==="emptyGroup"?{removeEmptyGroup:!1}:void 0)}isPanelActive(t){return this._activePanel===t}updateActions(t){this.tabsContainer.setRightActionsElement(t)}setActive(t,n=!1){!n&&this.isActive===t||(this._isGroupActive=t,Pe(this.container,"dv-active-group",t),Pe(this.container,"dv-inactive-group",!t),this.tabsContainer.setActive(this.isActive),!this._activePanel&&this.panels.length>0&&this.doSetActivePanel(this.panels[0]),this.updateContainer())}layout(t,n){var s;this._width=t,this._height=n,this.contentContainer.layout(this._width,this._height),!((s=this._activePanel)===null||s===void 0)&&s.layout&&this._activePanel.layout(this._width,this._height)}_removePanel(t,n){const s=this._activePanel===t;if(this.doRemovePanel(t),s&&this.panels.length>0){const a=this.mostRecentlyUsed[0];this.openPanel(a,{skipSetActive:n.skipSetActive,skipSetGroupActive:n.skipSetActiveGroup})}return this._activePanel&&this.panels.length===0&&this.doSetActivePanel(void 0),n.skipSetActive||this.updateContainer(),t}doRemovePanel(t){const n=this.panels.indexOf(t);if(this._activePanel===t&&this.contentContainer.closePanel(),this.tabsContainer.delete(t.id),this._panels.splice(n,1),this.mostRecentlyUsed.includes(t)){const a=this.mostRecentlyUsed.indexOf(t);this.mostRecentlyUsed.splice(a,1)}const s=this._panelDisposables.get(t.id);s&&(s.dispose(),this._panelDisposables.delete(t.id)),this._onDidRemovePanel.fire({panel:t})}doAddPanel(t,n=this.panels.length,s={skipSetActive:!1}){const r=this._panels.indexOf(t)>-1;this.tabsContainer.show(),this.contentContainer.show(),this.tabsContainer.openPanel(t,n),s.skipSetActive||this.contentContainer.openPanel(t),!r&&(this.updateMru(t),this.panels.splice(n,0,t),this._panelDisposables.set(t.id,new Ge(t.api.onDidTitleChange(o=>this._onDidPanelTitleChange.fire(o)),t.api.onDidParametersChange(o=>this._onDidPanelParametersChange.fire(o)))),this._onDidAddPanel.fire({panel:t}))}doSetActivePanel(t){this._activePanel!==t&&(this._activePanel=t,t&&(this.tabsContainer.setActivePanel(t),t.layout(this._width,this._height),this.updateMru(t),this._onDidActivePanelChange.fire({panel:t})))}updateMru(t){this.mostRecentlyUsed.includes(t)&&this.mostRecentlyUsed.splice(this.mostRecentlyUsed.indexOf(t),1),this.mostRecentlyUsed=[t,...this.mostRecentlyUsed]}updateContainer(){var t,n;if(this.panels.forEach(s=>s.runEvents()),this.isEmpty&&!this.watermark){const s=this.accessor.createWatermarkComponent();s.init({containerApi:this._api,group:this.groupPanel}),this.watermark=s,Fe(this.watermark.element,"pointerdown",()=>{this.isActive||this.accessor.doSetGroupActive(this.groupPanel)}),this.contentContainer.element.appendChild(this.watermark.element)}!this.isEmpty&&this.watermark&&(this.watermark.element.remove(),(n=(t=this.watermark).dispose)===null||n===void 0||n.call(t),this.watermark=void 0)}canDisplayOverlay(t,n,s){const a=new AA(t,s,n,En,this.accessor.getPanel(this.id));return this._onUnhandledDragOverEvent.fire(a),a.isAccepted}handleDropEvent(t,n,s,a){if(this.locked==="no-drop-target")return;function r(){switch(t){case"header":return typeof a=="number"?"tab":"header_space";case"content":return"content"}}const o=typeof a=="number"?this.panels[a]:void 0,l=new RA({nativeEvent:n,position:s,panel:o,getData:()=>En(),kind:r(),group:this.groupPanel,api:this._api});if(this._onWillDrop.fire(l),l.defaultPrevented)return;const c=En();if(c&&c.viewId===this.accessor.id){if(t==="content"&&c.groupId===this.id&&(s==="center"||c.panelId===null)||t==="header"&&c.groupId===this.id&&c.panelId===null)return;if(c.panelId===null){const{groupId:p}=c;this._onMove.fire({target:s,groupId:p,index:a});return}if(this.tabsContainer.indexOf(c.panelId)!==-1&&this.tabsContainer.size===1)return;const{groupId:h,panelId:f}=c;if(this.id===h&&!s&&this.tabsContainer.indexOf(f)===a)return;this._onMove.fire({target:s,groupId:c.groupId,itemId:c.panelId,index:a})}else this._onDidDrop.fire(new Vb({nativeEvent:n,position:s,panel:o,getData:()=>En(),group:this.groupPanel,api:this._api}))}updateDragAndDropState(){this.tabsContainer.updateDragAndDropState()}dispose(){var t,n,s;super.dispose(),(t=this.watermark)===null||t===void 0||t.element.remove(),(s=(n=this.watermark)===null||n===void 0?void 0:n.dispose)===null||s===void 0||s.call(n),this.watermark=void 0;for(const a of this.panels)a.dispose();this.tabsContainer.dispose(),this.contentContainer.dispose()}}class Ub extends SA{constructor(t,n,s){super(t,n),this._onDidConstraintsChangeInternal=new te,this.onDidConstraintsChangeInternal=this._onDidConstraintsChangeInternal.event,this._onDidConstraintsChange=new te,this.onDidConstraintsChange=this._onDidConstraintsChange.event,this._onDidSizeChange=new te,this.onDidSizeChange=this._onDidSizeChange.event,this.addDisposables(this._onDidConstraintsChangeInternal,this._onDidConstraintsChange,this._onDidSizeChange),s&&this.initialize(s)}setConstraints(t){this._onDidConstraintsChangeInternal.fire(t)}setSize(t){this._onDidSizeChange.fire(t)}}class TA extends Gb{get priority(){return this._priority}get snap(){return this._snap}get minimumWidth(){return this.__minimumWidth()}get minimumHeight(){return this.__minimumHeight()}get maximumHeight(){return this.__maximumHeight()}get maximumWidth(){return this.__maximumWidth()}__minimumWidth(){const t=typeof this._minimumWidth=="function"?this._minimumWidth():this._minimumWidth;return t!==this._evaluatedMinimumWidth&&(this._evaluatedMinimumWidth=t,this.updateConstraints()),t}__maximumWidth(){const t=typeof this._maximumWidth=="function"?this._maximumWidth():this._maximumWidth;return t!==this._evaluatedMaximumWidth&&(this._evaluatedMaximumWidth=t,this.updateConstraints()),t}__minimumHeight(){const t=typeof this._minimumHeight=="function"?this._minimumHeight():this._minimumHeight;return t!==this._evaluatedMinimumHeight&&(this._evaluatedMinimumHeight=t,this.updateConstraints()),t}__maximumHeight(){const t=typeof this._maximumHeight=="function"?this._maximumHeight():this._maximumHeight;return t!==this._evaluatedMaximumHeight&&(this._evaluatedMaximumHeight=t,this.updateConstraints()),t}get isActive(){return this.api.isActive}get isVisible(){return this.api.isVisible}constructor(t,n,s,a){super(t,n,a??new Ub(t,n)),this._evaluatedMinimumWidth=0,this._evaluatedMaximumWidth=Number.MAX_SAFE_INTEGER,this._evaluatedMinimumHeight=0,this._evaluatedMaximumHeight=Number.MAX_SAFE_INTEGER,this._minimumWidth=0,this._minimumHeight=0,this._maximumWidth=Number.MAX_SAFE_INTEGER,this._maximumHeight=Number.MAX_SAFE_INTEGER,this._snap=!1,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,typeof(s==null?void 0:s.minimumWidth)=="number"&&(this._minimumWidth=s.minimumWidth),typeof(s==null?void 0:s.maximumWidth)=="number"&&(this._maximumWidth=s.maximumWidth),typeof(s==null?void 0:s.minimumHeight)=="number"&&(this._minimumHeight=s.minimumHeight),typeof(s==null?void 0:s.maximumHeight)=="number"&&(this._maximumHeight=s.maximumHeight),this.api.initialize(this),this.addDisposables(this.api.onWillVisibilityChange(r=>{const{isVisible:o}=r,{accessor:l}=this._params;l.setVisible(this,o)}),this.api.onActiveChange(()=>{const{accessor:r}=this._params;r.doSetGroupActive(this)}),this.api.onDidConstraintsChangeInternal(r=>{(typeof r.minimumWidth=="number"||typeof r.minimumWidth=="function")&&(this._minimumWidth=r.minimumWidth),(typeof r.minimumHeight=="number"||typeof r.minimumHeight=="function")&&(this._minimumHeight=r.minimumHeight),(typeof r.maximumWidth=="number"||typeof r.maximumWidth=="function")&&(this._maximumWidth=r.maximumWidth),(typeof r.maximumHeight=="number"||typeof r.maximumHeight=="function")&&(this._maximumHeight=r.maximumHeight)}),this.api.onDidSizeChange(r=>{this._onDidChange.fire({height:r.height,width:r.width})}),this._onDidChange)}setVisible(t){this.api._onDidVisibilityChange.fire({isVisible:t})}setActive(t){this.api._onDidActiveChange.fire({isActive:t})}init(t){t.maximumHeight&&(this._maximumHeight=t.maximumHeight),t.minimumHeight&&(this._minimumHeight=t.minimumHeight),t.maximumWidth&&(this._maximumWidth=t.maximumWidth),t.minimumWidth&&(this._minimumWidth=t.minimumWidth),this._priority=t.priority,this._snap=!!t.snap,super.init(t),typeof t.isVisible=="boolean"&&this.setVisible(t.isVisible)}updateConstraints(){this.api._onDidConstraintsChange.fire({minimumWidth:this._evaluatedMinimumWidth,maximumWidth:this._evaluatedMaximumWidth,minimumHeight:this._evaluatedMinimumHeight,maximumHeight:this._evaluatedMaximumHeight})}toJSON(){const t=super.toJSON(),n=a=>a===Number.MAX_SAFE_INTEGER?void 0:a,s=a=>a<=0?void 0:a;return Object.assign(Object.assign({},t),{minimumHeight:s(this.minimumHeight),maximumHeight:n(this.maximumHeight),minimumWidth:s(this.minimumWidth),maximumWidth:n(this.maximumWidth),snap:this.snap,priority:this.priority})}}const $l="dockview: DockviewGroupPanelApiImpl not initialized";class a8 extends Ub{get location(){if(!this._group)throw new Error($l);return this._group.model.location}constructor(t,n){super(t,"__dockviewgroup__"),this.accessor=n,this._onDidLocationChange=new te,this.onDidLocationChange=this._onDidLocationChange.event,this._onDidActivePanelChange=new te,this.onDidActivePanelChange=this._onDidActivePanelChange.event,this.addDisposables(this._onDidLocationChange,this._onDidActivePanelChange)}close(){if(this._group)return this.accessor.removeGroup(this._group)}getWindow(){return this.location.type==="popout"?this.location.getWindow():window}moveTo(t){var n,s,a,r;if(!this._group)throw new Error($l);const o=(n=t.group)!==null&&n!==void 0?n:this.accessor.addGroup({direction:NA((s=t.position)!==null&&s!==void 0?s:"right"),skipSetActive:(a=t.skipSetActive)!==null&&a!==void 0?a:!1});this.accessor.moveGroupOrPanel({from:{groupId:this._group.id},to:{group:o,position:t.group&&(r=t.position)!==null&&r!==void 0?r:"center",index:t.index},skipSetActive:t.skipSetActive})}maximize(){if(!this._group)throw new Error($l);this.location.type==="grid"&&this.accessor.maximizeGroup(this._group)}isMaximized(){if(!this._group)throw new Error($l);return this.accessor.isMaximizedGroup(this._group)}exitMaximized(){if(!this._group)throw new Error($l);this.isMaximized()&&this.accessor.exitMaximizedGroup()}initialize(t){this._group=t}}const r8=100,o8=100;class Z_ extends TA{get minimumWidth(){var t;const n=(t=this.activePanel)===null||t===void 0?void 0:t.minimumWidth;return typeof n=="number"?n:super.__minimumWidth()}get minimumHeight(){var t;const n=(t=this.activePanel)===null||t===void 0?void 0:t.minimumHeight;return typeof n=="number"?n:super.__minimumHeight()}get maximumWidth(){var t;const n=(t=this.activePanel)===null||t===void 0?void 0:t.maximumWidth;return typeof n=="number"?n:super.__maximumWidth()}get maximumHeight(){var t;const n=(t=this.activePanel)===null||t===void 0?void 0:t.maximumHeight;return typeof n=="number"?n:super.__maximumHeight()}get panels(){return this._model.panels}get activePanel(){return this._model.activePanel}get size(){return this._model.size}get model(){return this._model}get locked(){return this._model.locked}set locked(t){this._model.locked=t}get header(){return this._model.header}constructor(t,n,s){var a,r,o,l,c,d;super(n,"groupview_default",{minimumHeight:(r=(a=s.constraints)===null||a===void 0?void 0:a.minimumHeight)!==null&&r!==void 0?r:o8,minimumWidth:(l=(o=s.constraints)===null||o===void 0?void 0:o.maximumHeight)!==null&&l!==void 0?l:r8,maximumHeight:(c=s.constraints)===null||c===void 0?void 0:c.maximumHeight,maximumWidth:(d=s.constraints)===null||d===void 0?void 0:d.maximumWidth},new a8(n,t)),this.api.initialize(this),this._model=new i8(this.element,t,n,s,this),this.addDisposables(this.model.onDidActivePanelChange(h=>{this.api._onDidActivePanelChange.fire(h)}))}focus(){this.api.isActive||this.api.setActive(),super.focus()}initialize(){this._model.initialize()}setActive(t){super.setActive(t),this.model.setActive(t)}layout(t,n){super.layout(t,n),this.model.layout(t,n)}getComponent(){return this._model}toJSON(){return this.model.toJSON()}}const l8={className:"dockview-theme-abyss"};class c8 extends Ub{get location(){return this.group.api.location}get title(){return this.panel.title}get isGroupActive(){return this.group.isActive}get renderer(){return this.panel.renderer}set group(t){const n=this._group;this._group!==t&&(this._group=t,this._onDidGroupChange.fire({}),this.setupGroupEventListeners(n),this._onDidLocationChange.fire({location:this.group.api.location}))}get group(){return this._group}get tabComponent(){return this._tabComponent}constructor(t,n,s,a,r){super(t.id,a),this.panel=t,this.accessor=s,this._onDidTitleChange=new te,this.onDidTitleChange=this._onDidTitleChange.event,this._onDidActiveGroupChange=new te,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._onDidGroupChange=new te,this.onDidGroupChange=this._onDidGroupChange.event,this._onDidRendererChange=new te,this.onDidRendererChange=this._onDidRendererChange.event,this._onDidLocationChange=new te,this.onDidLocationChange=this._onDidLocationChange.event,this.groupEventsDisposable=new On,this._tabComponent=r,this.initialize(t),this._group=n,this.setupGroupEventListeners(),this.addDisposables(this.groupEventsDisposable,this._onDidRendererChange,this._onDidTitleChange,this._onDidGroupChange,this._onDidActiveGroupChange,this._onDidLocationChange)}getWindow(){return this.group.api.getWindow()}moveTo(t){var n,s;this.accessor.moveGroupOrPanel({from:{groupId:this._group.id,panelId:this.panel.id},to:{group:(n=t.group)!==null&&n!==void 0?n:this._group,position:t.group&&(s=t.position)!==null&&s!==void 0?s:"center",index:t.index},skipSetActive:t.skipSetActive})}setTitle(t){this.panel.setTitle(t)}setRenderer(t){this.panel.setRenderer(t)}close(){this.group.model.closePanel(this.panel)}maximize(){this.group.api.maximize()}isMaximized(){return this.group.api.isMaximized()}exitMaximized(){this.group.api.exitMaximized()}setupGroupEventListeners(t){var n;let s=(n=t==null?void 0:t.isActive)!==null&&n!==void 0?n:!1;this.groupEventsDisposable.value=new Ge(this.group.api.onDidVisibilityChange(a=>{const r=!a.isVisible&&this.isVisible,o=a.isVisible&&!this.isVisible,l=this.group.model.isPanelActive(this.panel);(r||o&&l)&&this._onDidVisibilityChange.fire(a)}),this.group.api.onDidLocationChange(a=>{this.group===this.panel.group&&this._onDidLocationChange.fire(a)}),this.group.api.onDidActiveChange(()=>{this.group===this.panel.group&&s!==this.isGroupActive&&(s=this.isGroupActive,this._onDidActiveGroupChange.fire({isActive:this.isGroupActive}))}))}}class ao extends Ge{get params(){return this._params}get title(){return this._title}get group(){return this._group}get renderer(){var t;return(t=this._renderer)!==null&&t!==void 0?t:this.accessor.renderer}get minimumWidth(){return this._minimumWidth}get minimumHeight(){return this._minimumHeight}get maximumWidth(){return this._maximumWidth}get maximumHeight(){return this._maximumHeight}constructor(t,n,s,a,r,o,l,c){super(),this.id=t,this.accessor=a,this.containerApi=r,this.view=l,this._renderer=c.renderer,this._group=o,this._minimumWidth=c.minimumWidth,this._minimumHeight=c.minimumHeight,this._maximumWidth=c.maximumWidth,this._maximumHeight=c.maximumHeight,this.api=new c8(this,this._group,a,n,s),this.addDisposables(this.api.onActiveChange(()=>{a.setActivePanel(this)}),this.api.onDidSizeChange(d=>{this.group.api.setSize(d)}),this.api.onDidRendererChange(()=>{this.group.model.rerender(this)}))}init(t){this._params=t.params,this.view.init(Object.assign(Object.assign({},t),{api:this.api,containerApi:this.containerApi})),this.setTitle(t.title)}focus(){const t=new kA;this.api._onWillFocus.fire(t),!t.defaultPrevented&&(this.api.isActive||this.api.setActive())}toJSON(){return{id:this.id,contentComponent:this.view.contentComponent,tabComponent:this.view.tabComponent,params:Object.keys(this._params||{}).length>0?this._params:void 0,title:this.title,renderer:this._renderer,minimumHeight:this._minimumHeight,maximumHeight:this._maximumHeight,minimumWidth:this._minimumWidth,maximumWidth:this._maximumWidth}}setTitle(t){t!==this.title&&(this._title=t,this.api._onDidTitleChange.fire({title:t}))}setRenderer(t){t!==this.renderer&&(this._renderer=t,this.api._onDidRendererChange.fire({renderer:t}))}update(t){var n;this._params=Object.assign(Object.assign({},(n=this._params)!==null&&n!==void 0?n:{}),t.params);for(const s of Object.keys(t.params))t.params[s]===void 0&&delete this._params[s];this.view.update({params:this._params})}updateParentGroup(t,n){this._group=t,this.api.group=this._group;const s=this._group.model.isPanelActive(this),a=this.group.api.isActive&&s;n!=null&&n.skipSetActive||this.api.isActive!==a&&this.api._onDidActiveChange.fire({isActive:this.group.api.isActive&&s}),this.api.isVisible!==s&&this.api._onDidVisibilityChange.fire({isVisible:s})}runEvents(){const t=this._group.model.isPanelActive(this),n=this.group.api.isActive&&t;this.api.isActive!==n&&this.api._onDidActiveChange.fire({isActive:this.group.api.isActive&&t}),this.api.isVisible!==t&&this.api._onDidVisibilityChange.fire({isVisible:t})}layout(t,n){this.api._onDidDimensionChange.fire({width:t,height:n}),this.view.layout(t,n)}dispose(){this.api.dispose(),this.view.dispose()}}class Q_ extends Ge{get element(){return this._element}constructor(){super(),this._element=document.createElement("div"),this._element.className="dv-default-tab",this._content=document.createElement("div"),this._content.className="dv-default-tab-content",this.action=document.createElement("div"),this.action.className="dv-default-tab-action",this.action.appendChild(K5()),this._element.appendChild(this._content),this._element.appendChild(this.action),this.render()}init(t){this._title=t.title,this.addDisposables(t.api.onDidTitleChange(n=>{this._title=n.title,this.render()}),Fe(this.action,"pointerdown",n=>{n.preventDefault()}),Fe(this.action,"click",n=>{n.defaultPrevented||(n.preventDefault(),t.api.close())})),this.render()}render(){var t;this._content.textContent!==this._title&&(this._content.textContent=(t=this._title)!==null&&t!==void 0?t:"")}}class OA{get content(){return this._content}get tab(){return this._tab}constructor(t,n,s,a){this.accessor=t,this.id=n,this.contentComponent=s,this.tabComponent=a,this._content=this.createContentComponent(this.id,s),this._tab=this.createTabComponent(this.id,a)}createTabRenderer(t){var n;const s=this.createTabComponent(this.id,this.tabComponent);return this._params&&s.init(Object.assign(Object.assign({},this._params),{tabLocation:t})),this._updateEvent&&((n=s.update)===null||n===void 0||n.call(s,this._updateEvent)),s}init(t){this._params=t,this.content.init(t),this.tab.init(Object.assign(Object.assign({},t),{tabLocation:"header"}))}layout(t,n){var s,a;(a=(s=this.content).layout)===null||a===void 0||a.call(s,t,n)}update(t){var n,s,a,r;this._updateEvent=t,(s=(n=this.content).update)===null||s===void 0||s.call(n,t),(r=(a=this.tab).update)===null||r===void 0||r.call(a,t)}dispose(){var t,n,s,a;(n=(t=this.content).dispose)===null||n===void 0||n.call(t),(a=(s=this.tab).dispose)===null||a===void 0||a.call(s)}createContentComponent(t,n){return this.accessor.options.createComponent({id:t,name:n})}createTabComponent(t,n){const s=n??this.accessor.options.defaultTabComponent;if(s){if(this.accessor.options.createTabComponent){const a=this.accessor.options.createTabComponent({id:t,name:s});return a||new Q_}console.warn(`dockview: tabComponent '${n}' was not found. falling back to the default tab.`)}return new Q_}}class d8{constructor(t){this.accessor=t}fromJSON(t,n){var s,a;const r=t.id,o=t.params,l=t.title,c=t.view,d=c?c.content.id:(s=t.contentComponent)!==null&&s!==void 0?s:"unknown",h=c?(a=c.tab)===null||a===void 0?void 0:a.id:t.tabComponent,f=new OA(this.accessor,r,d,h),m=new ao(r,d,h,this.accessor,new Gh(this.accessor),n,f,{renderer:t.renderer,minimumWidth:t.minimumWidth,minimumHeight:t.minimumHeight,maximumWidth:t.maximumWidth,maximumHeight:t.maximumHeight});return m.init({title:l??r,params:o??{}}),m}}class u8 extends Ge{get element(){return this._element}constructor(){super(),this._element=document.createElement("div"),this._element.className="dv-watermark"}init(t){}}class h8{constructor(){this._orderedList=[]}push(t){this._orderedList=[...this._orderedList.filter(n=>n!==t),t],this.update()}destroy(t){this._orderedList=this._orderedList.filter(n=>n!==t),this.update()}update(){for(let t=0;t<this._orderedList.length;t++)this._orderedList[t].setAttribute("aria-level",`${t}`),this._orderedList[t].style.zIndex=`calc(var(--dv-overlay-z-index, 999) + ${t*2})`}}const uu=new h8;class wa extends Ge{set minimumInViewportWidth(t){this.options.minimumInViewportWidth=t}set minimumInViewportHeight(t){this.options.minimumInViewportHeight=t}get element(){return this._element}get isVisible(){return this._isVisible}constructor(t){super(),this.options=t,this._element=document.createElement("div"),this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this._onDidChangeEnd=new te,this.onDidChangeEnd=this._onDidChangeEnd.event,this.addDisposables(this._onDidChange,this._onDidChangeEnd),this._element.className="dv-resize-container",this._isVisible=!0,this.setupResize("top"),this.setupResize("bottom"),this.setupResize("left"),this.setupResize("right"),this.setupResize("topleft"),this.setupResize("topright"),this.setupResize("bottomleft"),this.setupResize("bottomright"),this._element.appendChild(this.options.content),this.options.container.appendChild(this._element),this.setBounds(Object.assign(Object.assign(Object.assign(Object.assign({height:this.options.height,width:this.options.width},"top"in this.options&&{top:this.options.top}),"bottom"in this.options&&{bottom:this.options.bottom}),"left"in this.options&&{left:this.options.left}),"right"in this.options&&{right:this.options.right})),uu.push(this._element)}setVisible(t){t!==this.isVisible&&(this._isVisible=t,Pe(this.element,"dv-hidden",!this.isVisible))}bringToFront(){uu.push(this._element)}setBounds(t={}){typeof t.height=="number"&&(this._element.style.height=`${t.height}px`),typeof t.width=="number"&&(this._element.style.width=`${t.width}px`),"top"in t&&typeof t.top=="number"&&(this._element.style.top=`${t.top}px`,this._element.style.bottom="auto",this.verticalAlignment="top"),"bottom"in t&&typeof t.bottom=="number"&&(this._element.style.bottom=`${t.bottom}px`,this._element.style.top="auto",this.verticalAlignment="bottom"),"left"in t&&typeof t.left=="number"&&(this._element.style.left=`${t.left}px`,this._element.style.right="auto",this.horiziontalAlignment="left"),"right"in t&&typeof t.right=="number"&&(this._element.style.right=`${t.right}px`,this._element.style.left="auto",this.horiziontalAlignment="right");const n=this.options.container.getBoundingClientRect(),s=this._element.getBoundingClientRect(),a=Math.max(0,this.getMinimumWidth(s.width)),r=Math.max(0,this.getMinimumHeight(s.height));if(this.verticalAlignment==="top"){const o=Rt(s.top-n.top,-r,Math.max(0,n.height-s.height+r));this._element.style.top=`${o}px`,this._element.style.bottom="auto"}if(this.verticalAlignment==="bottom"){const o=Rt(n.bottom-s.bottom,-r,Math.max(0,n.height-s.height+r));this._element.style.bottom=`${o}px`,this._element.style.top="auto"}if(this.horiziontalAlignment==="left"){const o=Rt(s.left-n.left,-a,Math.max(0,n.width-s.width+a));this._element.style.left=`${o}px`,this._element.style.right="auto"}if(this.horiziontalAlignment==="right"){const o=Rt(n.right-s.right,-a,Math.max(0,n.width-s.width+a));this._element.style.right=`${o}px`,this._element.style.left="auto"}this._onDidChange.fire()}toJSON(){const t=this.options.container.getBoundingClientRect(),n=this._element.getBoundingClientRect(),s={};return this.verticalAlignment==="top"?s.top=parseFloat(this._element.style.top):this.verticalAlignment==="bottom"?s.bottom=parseFloat(this._element.style.bottom):s.top=n.top-t.top,this.horiziontalAlignment==="left"?s.left=parseFloat(this._element.style.left):this.horiziontalAlignment==="right"?s.right=parseFloat(this._element.style.right):s.left=n.left-t.left,s.width=n.width,s.height=n.height,s}setupDrag(t,n={inDragMode:!1}){const s=new On,a=()=>{let r=null;const o=Ph();s.value=new Ge({dispose:()=>{o.release()}},Fe(window,"pointermove",l=>{const c=this.options.container.getBoundingClientRect(),d=l.clientX-c.left,h=l.clientY-c.top;Pe(this._element,"dv-resize-container-dragging",!0);const f=this._element.getBoundingClientRect();r===null&&(r={x:l.clientX-f.left,y:l.clientY-f.top});const m=Math.max(0,this.getMinimumWidth(f.width)),p=Math.max(0,this.getMinimumHeight(f.height)),y=Rt(h-r.y,-p,Math.max(0,c.height-f.height+p)),g=Rt(r.y-h+c.height-f.height,-p,Math.max(0,c.height-f.height+p)),b=Rt(d-r.x,-m,Math.max(0,c.width-f.width+m)),v=Rt(r.x-d+c.width-f.width,-m,Math.max(0,c.width-f.width+m)),x={};y<=g?x.top=y:x.bottom=g,b<=v?x.left=b:x.right=v,this.setBounds(x)}),Fe(window,"pointerup",()=>{Pe(this._element,"dv-resize-container-dragging",!1),s.dispose(),this._onDidChangeEnd.fire()}))};this.addDisposables(s,Fe(t,"pointerdown",r=>{if(r.defaultPrevented){r.preventDefault();return}Y_(r)||a()}),Fe(this.options.content,"pointerdown",r=>{r.defaultPrevented||Y_(r)||r.shiftKey&&a()}),Fe(this.options.content,"pointerdown",()=>{uu.push(this._element)},!0)),n.inDragMode&&a()}setupResize(t){const n=document.createElement("div");n.className=`dv-resize-handle-${t}`,this._element.appendChild(n);const s=new On;this.addDisposables(s,Fe(n,"pointerdown",a=>{a.preventDefault();let r=null;const o=Ph();s.value=new Ge(Fe(window,"pointermove",l=>{const c=this.options.container.getBoundingClientRect(),d=this._element.getBoundingClientRect(),h=l.clientY-c.top,f=l.clientX-c.left;r===null&&(r={originalY:h,originalHeight:d.height,originalX:f,originalWidth:d.width});let m,p,y,g,b,v;const x=()=>{m=Rt(h,-Number.MAX_VALUE,r.originalY+r.originalHeight>c.height?this.getMinimumHeight(c.height):Math.max(0,r.originalY+r.originalHeight-wa.MINIMUM_HEIGHT)),y=r.originalY+r.originalHeight-m,p=c.height-m-y},w=()=>{m=r.originalY-r.originalHeight,y=Rt(h-m,m<0&&typeof this.options.minimumInViewportHeight=="number"?-m+this.options.minimumInViewportHeight:wa.MINIMUM_HEIGHT,Number.MAX_VALUE),p=c.height-m-y},_=()=>{g=Rt(f,-Number.MAX_VALUE,r.originalX+r.originalWidth>c.width?this.getMinimumWidth(c.width):Math.max(0,r.originalX+r.originalWidth-wa.MINIMUM_WIDTH)),v=r.originalX+r.originalWidth-g,b=c.width-g-v},S=()=>{g=r.originalX-r.originalWidth,v=Rt(f-g,g<0&&typeof this.options.minimumInViewportWidth=="number"?-g+this.options.minimumInViewportWidth:wa.MINIMUM_WIDTH,Number.MAX_VALUE),b=c.width-g-v};switch(t){case"top":x();break;case"bottom":w();break;case"left":_();break;case"right":S();break;case"topleft":x(),_();break;case"topright":x(),S();break;case"bottomleft":w(),_();break;case"bottomright":w(),S();break}const k={};m<=p?k.top=m:k.bottom=p,g<=b?k.left=g:k.right=b,k.height=y,k.width=v,this.setBounds(k)}),{dispose:()=>{o.release()}},Fe(window,"pointerup",()=>{s.dispose(),this._onDidChangeEnd.fire()}))}))}getMinimumWidth(t){return typeof this.options.minimumInViewportWidth=="number"?t-this.options.minimumInViewportWidth:0}getMinimumHeight(t){return typeof this.options.minimumInViewportHeight=="number"?t-this.options.minimumInViewportHeight:0}dispose(){uu.destroy(this._element),this._element.remove(),super.dispose()}}wa.MINIMUM_HEIGHT=20;wa.MINIMUM_WIDTH=20;class f8 extends Ge{constructor(t,n){super(),this.group=t,this.overlay=n,this.addDisposables(n)}position(t){this.overlay.setBounds(t)}}const hu=100,na={left:100,top:100,width:300,height:300},m8=100;class p8{constructor(){this.cache=new Map,this.currentFrameId=0,this.rafId=null}getPosition(t){const n=this.cache.get(t);if(n&&n.frameId===this.currentFrameId)return n.rect;this.scheduleFrameUpdate();const s=ox(t);return this.cache.set(t,{rect:s,frameId:this.currentFrameId}),s}invalidate(){this.currentFrameId++}scheduleFrameUpdate(){this.rafId||(this.rafId=requestAnimationFrame(()=>{this.currentFrameId++,this.rafId=null}))}}function g8(){const e=document.createElement("div");return e.tabIndex=-1,e}class J_ extends Ge{constructor(t,n){super(),this.element=t,this.accessor=n,this.map={},this._disposed=!1,this.positionCache=new p8,this.pendingUpdates=new Set,this.addDisposables(Zt.from(()=>{for(const s of Object.values(this.map))s.disposable.dispose(),s.destroy.dispose();this._disposed=!0}))}updateAllPositions(){if(!this._disposed){this.positionCache.invalidate();for(const t of Object.values(this.map))t.panel.api.isVisible&&t.resize&&t.resize()}}detatch(t){if(this.map[t.api.id]){const{disposable:n,destroy:s}=this.map[t.api.id];return n.dispose(),s.dispose(),delete this.map[t.api.id],!0}return!1}attach(t){const{panel:n,referenceContainer:s}=t;if(!this.map[n.api.id]){const h=g8();h.className="dv-render-overlay",this.map[n.api.id]={panel:n,disposable:Zt.NONE,destroy:Zt.NONE,element:h}}const a=this.map[n.api.id].element;n.view.content.element.parentElement!==a&&a.appendChild(n.view.content.element),a.parentElement!==this.element&&this.element.appendChild(a);const r=()=>{const h=n.api.id;this.pendingUpdates.has(h)||(this.pendingUpdates.add(h),requestAnimationFrame(()=>{if(this.pendingUpdates.delete(h),this.isDisposed||!this.map[h])return;const f=this.positionCache.getPosition(s.element),m=this.positionCache.getPosition(this.element),p=f.left-m.left,y=f.top-m.top,g=f.width,b=f.height;a.style.left=`${p}px`,a.style.top=`${y}px`,a.style.width=`${g}px`,a.style.height=`${b}px`,Pe(a,"dv-render-overlay-float",n.group.api.location.type==="floating")}))},o=()=>{n.api.isVisible&&(this.positionCache.invalidate(),r()),a.style.display=n.api.isVisible?"":"none"},l=new On,c=()=>{n.api.location.type==="floating"?queueMicrotask(()=>{const h=this.accessor.floatingGroups.find(y=>y.group===n.api.group);if(!h)return;const f=h.overlay.element,m=()=>{const y=Number(f.getAttribute("aria-level"));a.style.zIndex=`calc(var(--dv-overlay-z-index, 999) + ${y*2+1})`},p=new MutationObserver(()=>{m()});l.value=Zt.from(()=>p.disconnect()),p.observe(f,{attributeFilter:["aria-level"],attributes:!0}),m()}):a.style.zIndex=""},d=new Ge(l,new jA(a,{onDragEnd:h=>{s.dropTarget.dnd.onDragEnd(h)},onDragEnter:h=>{s.dropTarget.dnd.onDragEnter(h)},onDragLeave:h=>{s.dropTarget.dnd.onDragLeave(h)},onDrop:h=>{s.dropTarget.dnd.onDrop(h)},onDragOver:h=>{s.dropTarget.dnd.onDragOver(h)}}),n.api.onDidVisibilityChange(()=>{o()}),n.api.onDidDimensionsChange(()=>{n.api.isVisible&&r()}),n.api.onDidLocationChange(()=>{c()}));return this.map[n.api.id].destroy=Zt.from(()=>{var h;n.view.content.element.parentElement===a&&a.removeChild(n.view.content.element),(h=a.parentElement)===null||h===void 0||h.removeChild(a)}),c(),queueMicrotask(()=>{this.isDisposed||o()}),this.map[n.api.id].disposable.dispose(),this.map[n.api.id].disposable=d,this.map[n.api.id].resize=r,a}}var x8=function(e,t,n,s){function a(r){return r instanceof n?r:new n(function(o){o(r)})}return new(n||(n=Promise))(function(r,o){function l(h){try{d(s.next(h))}catch(f){o(f)}}function c(h){try{d(s.throw(h))}catch(f){o(f)}}function d(h){h.done?r(h.value):a(h.value).then(l,c)}d((s=s.apply(e,t||[])).next())})};class v8 extends Ge{get window(){var t,n;return(n=(t=this._window)===null||t===void 0?void 0:t.value)!==null&&n!==void 0?n:null}constructor(t,n,s){super(),this.target=t,this.className=n,this.options=s,this._onWillClose=new te,this.onWillClose=this._onWillClose.event,this._onDidClose=new te,this.onDidClose=this._onDidClose.event,this._window=null,this.addDisposables(this._onWillClose,this._onDidClose,{dispose:()=>{this.close()}})}dimensions(){if(!this._window)return null;const t=this._window.value.screenX,n=this._window.value.screenY,s=this._window.value.innerWidth,a=this._window.value.innerHeight;return{top:n,left:t,width:s,height:a}}close(){var t,n;this._window&&(this._onWillClose.fire(),(n=(t=this.options).onWillClose)===null||n===void 0||n.call(t,{id:this.target,window:this._window.value}),this._window.disposable.dispose(),this._window=null,this._onDidClose.fire())}open(){var t,n;return x8(this,void 0,void 0,function*(){if(this._window)throw new Error("instance of popout window is already open");const s=`${this.options.url}`,a=Object.entries({top:this.options.top,left:this.options.left,width:this.options.width,height:this.options.height}).map(([c,d])=>`${c}=${d}`).join(","),r=window.open(s,this.target,a);if(!r)return null;const o=new Ge;this._window={value:r,disposable:o},o.addDisposables(Zt.from(()=>{r.close()}),Fe(window,"beforeunload",()=>{this.close()}));const l=this.createPopoutWindowContainer();return this.className&&l.classList.add(this.className),(n=(t=this.options).onDidOpen)===null||n===void 0||n.call(t,{id:this.target,window:r}),new Promise((c,d)=>{r.addEventListener("unload",h=>{}),r.addEventListener("load",()=>{try{const h=r.document;h.title=document.title,h.body.appendChild(l),h5(h,window.document.styleSheets),Fe(r,"beforeunload",()=>{this.close()}),c(l)}catch(h){d(h)}})})})}createPopoutWindowContainer(){const t=document.createElement("div");return t.classList.add("dv-popout-window"),t.id="dv-popout-window",t.style.position="absolute",t.style.width="100%",t.style.height="100%",t.style.top="0px",t.style.left="0px",t}}class b8 extends Ge{constructor(t){super(),this.accessor=t,this.init()}init(){const t=new Set,n=new Set;this.addDisposables(this.accessor.onDidAddPanel(s=>{if(t.has(s.api.id))throw new Error(`dockview: Invalid event sequence. [onDidAddPanel] called for panel ${s.api.id} but panel already exists`);t.add(s.api.id)}),this.accessor.onDidRemovePanel(s=>{if(t.has(s.api.id))t.delete(s.api.id);else throw new Error(`dockview: Invalid event sequence. [onDidRemovePanel] called for panel ${s.api.id} but panel does not exists`)}),this.accessor.onDidAddGroup(s=>{if(n.has(s.api.id))throw new Error(`dockview: Invalid event sequence. [onDidAddGroup] called for group ${s.api.id} but group already exists`);n.add(s.api.id)}),this.accessor.onDidRemoveGroup(s=>{if(n.has(s.api.id))n.delete(s.api.id);else throw new Error(`dockview: Invalid event sequence. [onDidRemoveGroup] called for group ${s.api.id} but group does not exists`)}))}}class y8 extends Ge{constructor(t){super(),this.root=t,this._active=null,this._activeDisposable=new On,this._element=document.createElement("div"),this._element.className="dv-popover-anchor",this._element.style.position="relative",this.root.prepend(this._element),this.addDisposables(Zt.from(()=>{this.close()}),this._activeDisposable)}openPopover(t,n){var s;this.close();const a=document.createElement("div");a.style.position="absolute",a.style.zIndex=(s=n.zIndex)!==null&&s!==void 0?s:"var(--dv-overlay-z-index)",a.appendChild(t);const r=this._element.getBoundingClientRect(),o=r.left,l=r.top;a.style.top=`${n.y-l}px`,a.style.left=`${n.x-o}px`,this._element.appendChild(a),this._active=a,this._activeDisposable.value=new Ge(Fe(window,"pointerdown",c=>{var d;const h=c.target;if(!(h instanceof HTMLElement))return;let f=h;for(;f&&f!==a;)f=(d=f==null?void 0:f.parentElement)!==null&&d!==void 0?d:null;f||this.close()})),requestAnimationFrame(()=>{y5(a,this.root)})}close(){this._active&&(this._active.remove(),this._activeDisposable.dispose(),this._active=null)}}class ej extends Ge{get disabled(){return this._disabled}set disabled(t){var n;this.disabled!==t&&(this._disabled=t,t&&((n=this.model)===null||n===void 0||n.clear()))}get model(){if(!this.disabled)return{clear:()=>{var t;this._model&&((t=this._model.root.parentElement)===null||t===void 0||t.removeChild(this._model.root)),this._model=void 0},exists:()=>!!this._model,getElements:(t,n)=>{const s=this._outline!==n;if(this._outline=n,this._model)return this._model.changed=s,this._model;const a=this.createContainer(),r=this.createAnchor();if(this._model={root:a,overlay:r,changed:s},a.appendChild(r),this.element.appendChild(a),(t==null?void 0:t.target)instanceof HTMLElement){const o=t.target.getBoundingClientRect(),l=this.element.getBoundingClientRect();r.style.left=`${o.left-l.left}px`,r.style.top=`${o.top-l.top}px`}return this._model}}}constructor(t,n){super(),this.element=t,this._disabled=!1,this._disabled=n.disabled,this.addDisposables(Zt.from(()=>{var s;(s=this.model)===null||s===void 0||s.clear()}))}createContainer(){const t=document.createElement("div");return t.className="dv-drop-target-container",t}createAnchor(){const t=document.createElement("div");return t.className="dv-drop-target-anchor",t.style.visibility="hidden",t}}const tj={activationSize:{type:"pixels",value:10},size:{type:"pixels",value:20}};function fu(e){const t=e.from.activePanel;[...e.from.panels].map(s=>{const a=e.from.model.removePanel(s);return e.from.model.renderContainer.detatch(s),a}).forEach(s=>{e.to.model.openPanel(s,{skipSetActive:t!==s,skipSetGroupActive:!0})})}class w8 extends yA{get orientation(){return this.gridview.orientation}get totalPanels(){return this.panels.length}get panels(){return this.groups.flatMap(t=>t.panels)}get options(){return this._options}get activePanel(){const t=this.activeGroup;if(t)return t.activePanel}get renderer(){var t;return(t=this.options.defaultRenderer)!==null&&t!==void 0?t:"onlyWhenVisible"}get api(){return this._api}get floatingGroups(){return this._floatingGroups}get popoutRestorationPromise(){return this._popoutRestorationPromise}constructor(t,n){var s,a,r;super(t,{proportionalLayout:!0,orientation:Me.HORIZONTAL,styles:n.hideBorders?{separatorBorder:"transparent"}:void 0,disableAutoResizing:n.disableAutoResizing,locked:n.locked,margin:(a=(s=n.theme)===null||s===void 0?void 0:s.gap)!==null&&a!==void 0?a:0,className:n.className}),this.nextGroupId=Lb(),this._deserializer=new d8(this),this._watermark=null,this._onWillDragPanel=new te,this.onWillDragPanel=this._onWillDragPanel.event,this._onWillDragGroup=new te,this.onWillDragGroup=this._onWillDragGroup.event,this._onDidDrop=new te,this.onDidDrop=this._onDidDrop.event,this._onWillDrop=new te,this.onWillDrop=this._onWillDrop.event,this._onWillShowOverlay=new te,this.onWillShowOverlay=this._onWillShowOverlay.event,this._onUnhandledDragOverEvent=new te,this.onUnhandledDragOverEvent=this._onUnhandledDragOverEvent.event,this._onDidRemovePanel=new te,this.onDidRemovePanel=this._onDidRemovePanel.event,this._onDidAddPanel=new te,this.onDidAddPanel=this._onDidAddPanel.event,this._onDidPopoutGroupSizeChange=new te,this.onDidPopoutGroupSizeChange=this._onDidPopoutGroupSizeChange.event,this._onDidPopoutGroupPositionChange=new te,this.onDidPopoutGroupPositionChange=this._onDidPopoutGroupPositionChange.event,this._onDidOpenPopoutWindowFail=new te,this.onDidOpenPopoutWindowFail=this._onDidOpenPopoutWindowFail.event,this._onDidLayoutFromJSON=new te,this.onDidLayoutFromJSON=this._onDidLayoutFromJSON.event,this._onDidActivePanelChange=new te({replay:!0}),this.onDidActivePanelChange=this._onDidActivePanelChange.event,this._onDidMovePanel=new te,this.onDidMovePanel=this._onDidMovePanel.event,this._onDidMaximizedGroupChange=new te,this.onDidMaximizedGroupChange=this._onDidMaximizedGroupChange.event,this._floatingGroups=[],this._popoutGroups=[],this._popoutRestorationPromise=Promise.resolve(),this._onDidRemoveGroup=new te,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidAddGroup=new te,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidOptionsChange=new te,this.onDidOptionsChange=this._onDidOptionsChange.event,this._onDidActiveGroupChange=new te,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._moving=!1,this._options=n,this.popupService=new y8(this.element),this._themeClassnames=new am(this.element),this._api=new Gh(this),this.rootDropTargetContainer=new ej(this.element,{disabled:!0}),this.overlayRenderContainer=new J_(this.gridview.element,this),this._rootDropTarget=new Vs(this.element,{className:"dv-drop-target-edge",canDisplayOverlay:(o,l)=>{const c=En();if(c)return c.viewId!==this.id?!1:l==="center"?this.gridview.length===0:!0;if(l==="center"&&this.gridview.length!==0)return!1;const d=new AA(o,"edge",l,En);return this._onUnhandledDragOverEvent.fire(d),d.isAccepted},acceptedTargetZones:["top","bottom","left","right","center"],overlayModel:(r=n.rootOverlayModel)!==null&&r!==void 0?r:tj,getOverrideTarget:()=>{var o;return(o=this.rootDropTargetContainer)===null||o===void 0?void 0:o.model}}),this.updateDropTargetModel(n),Pe(this.gridview.element,"dv-dockview",!0),Pe(this.element,"dv-debug",!!n.debug),this.updateTheme(),this.updateWatermark(),n.debug&&this.addDisposables(new b8(this)),this.addDisposables(this.rootDropTargetContainer,this.overlayRenderContainer,this._onWillDragPanel,this._onWillDragGroup,this._onWillShowOverlay,this._onDidActivePanelChange,this._onDidAddPanel,this._onDidRemovePanel,this._onDidLayoutFromJSON,this._onDidDrop,this._onWillDrop,this._onDidMovePanel,this._onDidAddGroup,this._onDidRemoveGroup,this._onDidActiveGroupChange,this._onUnhandledDragOverEvent,this._onDidMaximizedGroupChange,this._onDidOptionsChange,this._onDidPopoutGroupSizeChange,this._onDidPopoutGroupPositionChange,this._onDidOpenPopoutWindowFail,this.onDidViewVisibilityChangeMicroTaskQueue(()=>{this.updateWatermark()}),this.onDidAdd(o=>{this._moving||this._onDidAddGroup.fire(o)}),this.onDidRemove(o=>{this._moving||this._onDidRemoveGroup.fire(o)}),this.onDidActiveChange(o=>{this._moving||this._onDidActiveGroupChange.fire(o)}),this.onDidMaximizedChange(o=>{this._onDidMaximizedGroupChange.fire({group:o.panel,isMaximized:o.isMaximized})}),vr.any(this.onDidAdd,this.onDidRemove)(()=>{this.updateWatermark()}),vr.any(this.onDidAddPanel,this.onDidRemovePanel,this.onDidAddGroup,this.onDidRemove,this.onDidMovePanel,this.onDidActivePanelChange,this.onDidPopoutGroupPositionChange,this.onDidPopoutGroupSizeChange)(()=>{this._bufferOnDidLayoutChange.fire()}),Zt.from(()=>{for(const o of[...this._floatingGroups])o.dispose();for(const o of[...this._popoutGroups])o.disposable.dispose()}),this._rootDropTarget,this._rootDropTarget.onWillShowOverlay(o=>{this.gridview.length>0&&o.position==="center"||this._onWillShowOverlay.fire(new rm(o,{kind:"edge",panel:void 0,api:this._api,group:void 0,getData:En}))}),this._rootDropTarget.onDrop(o=>{var l;const c=new RA({nativeEvent:o.nativeEvent,position:o.position,panel:void 0,api:this._api,group:void 0,getData:En,kind:"edge"});if(this._onWillDrop.fire(c),c.defaultPrevented)return;const d=En();d?this.moveGroupOrPanel({from:{groupId:d.groupId,panelId:(l=d.panelId)!==null&&l!==void 0?l:void 0},to:{group:this.orthogonalize(o.position),position:"center"}}):this._onDidDrop.fire(new Vb({nativeEvent:o.nativeEvent,position:o.position,panel:void 0,api:this._api,group:void 0,getData:En}))}),this._rootDropTarget)}setVisible(t,n){switch(t.api.location.type){case"grid":super.setVisible(t,n);break;case"floating":{const s=this.floatingGroups.find(a=>a.group===t);s&&(s.overlay.setVisible(n),t.api._onDidVisibilityChange.fire({isVisible:n}));break}case"popout":console.warn("dockview: You cannot hide a group that is in a popout window");break}}addPopoutGroup(t,n){var s,a,r,o,l;if(t instanceof ao&&t.group.size===1)return this.addPopoutGroup(t.group,n);const c=g5(this.gridview.element),d=this.element;function h(){return n!=null&&n.position?n.position:t instanceof Z_?t.element.getBoundingClientRect():t.group?t.group.element.getBoundingClientRect():d.getBoundingClientRect()}const f=h(),m=(a=(s=n==null?void 0:n.overridePopoutGroup)===null||s===void 0?void 0:s.id)!==null&&a!==void 0?a:this.getNextGroupId(),p=new v8(`${this.id}-${m}`,c??"",{url:(l=(r=n==null?void 0:n.popoutUrl)!==null&&r!==void 0?r:(o=this.options)===null||o===void 0?void 0:o.popoutUrl)!==null&&l!==void 0?l:"/popout.html",left:window.screenX+f.left,top:window.screenY+f.top,width:f.width,height:f.height,onDidOpen:n==null?void 0:n.onDidOpen,onWillClose:n==null?void 0:n.onWillClose}),y=new Ge(p,p.onDidClose(()=>{y.dispose()}));return p.open().then(g=>{var b;if(p.isDisposed)return!1;const v=n!=null&&n.referenceGroup?n.referenceGroup:t instanceof ao?t.group:t,x=t.api.location.type,w=v.element.parentElement!==null;let _;if(w?n!=null&&n.overridePopoutGroup?_=n.overridePopoutGroup:(_=this.createGroup({id:m}),g&&this._onDidAddGroup.fire(_)):_=v,g===null)return console.error("dockview: failed to create popout. perhaps you need to allow pop-ups for this website"),y.dispose(),this._onDidOpenPopoutWindowFail.fire(),this.movingLock(()=>fu({from:_,to:v})),v.api.isVisible||v.api.setVisible(!0),!1;const S=document.createElement("div");S.className="dv-overlay-render-container";const k=new J_(S,this);_.model.renderContainer=k,_.layout(p.window.innerWidth,p.window.innerHeight);let j;if(!(n!=null&&n.overridePopoutGroup)&&w)if(t instanceof ao)this.movingLock(()=>{const A=v.model.removePanel(t);_.model.openPanel(A)});else switch(this.movingLock(()=>fu({from:v,to:_})),x){case"grid":v.api.setVisible(!1);break;case"floating":case"popout":j=(b=this._floatingGroups.find(A=>A.group.api.id===t.api.id))===null||b===void 0?void 0:b.overlay.toJSON(),this.removeGroup(v);break}g.classList.add("dv-dockview"),g.style.overflow="hidden",g.appendChild(S),g.appendChild(_.element);const N=document.createElement("div"),O=new ej(N,{disabled:this.rootDropTargetContainer.disabled});g.appendChild(N),_.model.dropTargetContainer=O,_.model.location={type:"popout",getWindow:()=>p.window,popoutUrl:n==null?void 0:n.popoutUrl},w&&t.api.location.type==="grid"&&t.api.setVisible(!1),this.doSetGroupAndPanelActive(_),y.addDisposables(_.api.onDidActiveChange(A=>{var D;A.isActive&&((D=p.window)===null||D===void 0||D.focus())}),_.api.onWillFocus(()=>{var A;(A=p.window)===null||A===void 0||A.focus()}));let T;const P=w&&v&&this.getPanel(v.id),L={window:p,popoutGroup:_,referenceGroup:P?v.id:void 0,disposable:{dispose:()=>(y.dispose(),T)}},G=v5(p.window);return y.addDisposables(G,b5(p.window,()=>{this._onDidPopoutGroupSizeChange.fire({width:p.window.innerWidth,height:p.window.innerHeight,group:_})}),G.event(()=>{this._onDidPopoutGroupPositionChange.fire({screenX:p.window.screenX,screenY:p.window.screenX,group:_})}),Fe(p.window,"resize",()=>{_.layout(p.window.innerWidth,p.window.innerHeight)}),k,Zt.from(()=>{if(!this.isDisposed){if(w&&this.getPanel(v.id))this.movingLock(()=>fu({from:_,to:v})),v.api.isVisible||v.api.setVisible(!0),this.getPanel(_.id)&&this.doRemoveGroup(_,{skipPopoutAssociated:!0});else if(this.getPanel(_.id)){if(_.model.renderContainer=this.overlayRenderContainer,_.model.dropTargetContainer=this.rootDropTargetContainer,T=_,!this._popoutGroups.find(D=>D.popoutGroup===_))return;j?this.addFloatingGroup(_,{height:j.height,width:j.width,position:j}):(this.doRemoveGroup(_,{skipDispose:!0,skipActive:!0,skipPopoutReturn:!0}),_.model.location={type:"grid"},this.movingLock(()=>{this.doAddGroup(_,[0])})),this.doSetGroupAndPanelActive(_)}}})),this._popoutGroups.push(L),this.updateWatermark(),!0}).catch(g=>(console.error("dockview: failed to create popout.",g),!1))}addFloatingGroup(t,n){var s,a,r,o,l;let c;if(t instanceof ao)c=this.createGroup(),this._onDidAddGroup.fire(c),this.movingLock(()=>this.removePanel(t,{removeEmptyGroup:!0,skipDispose:!0,skipSetActiveGroup:!0})),this.movingLock(()=>c.model.openPanel(t,{skipSetGroupActive:!0}));else{c=t;const g=(s=this._popoutGroups.find(x=>x.popoutGroup===c))===null||s===void 0?void 0:s.referenceGroup,b=g?this.getPanel(g):void 0;typeof(n==null?void 0:n.skipRemoveGroup)=="boolean"&&n.skipRemoveGroup||(b?(this.movingLock(()=>fu({from:t,to:b})),this.doRemoveGroup(t,{skipPopoutReturn:!0,skipPopoutAssociated:!0}),this.doRemoveGroup(b,{skipDispose:!0}),c=b):this.doRemoveGroup(t,{skipDispose:!0,skipPopoutReturn:!0,skipPopoutAssociated:!1}))}function d(){if(n!=null&&n.position){const g={};return"left"in n.position?g.left=Math.max(n.position.left,0):"right"in n.position?g.right=Math.max(n.position.right,0):g.left=na.left,"top"in n.position?g.top=Math.max(n.position.top,0):"bottom"in n.position?g.bottom=Math.max(n.position.bottom,0):g.top=na.top,typeof n.width=="number"?g.width=Math.max(n.width,0):g.width=na.width,typeof n.height=="number"?g.height=Math.max(n.height,0):g.height=na.height,g}return{left:typeof(n==null?void 0:n.x)=="number"?Math.max(n.x,0):na.left,top:typeof(n==null?void 0:n.y)=="number"?Math.max(n.y,0):na.top,width:typeof(n==null?void 0:n.width)=="number"?Math.max(n.width,0):na.width,height:typeof(n==null?void 0:n.height)=="number"?Math.max(n.height,0):na.height}}const h=d(),f=new wa(Object.assign(Object.assign({container:this.gridview.element,content:c.element},h),{minimumInViewportWidth:this.options.floatingGroupBounds==="boundedWithinViewport"?void 0:(r=(a=this.options.floatingGroupBounds)===null||a===void 0?void 0:a.minimumWidthWithinViewport)!==null&&r!==void 0?r:hu,minimumInViewportHeight:this.options.floatingGroupBounds==="boundedWithinViewport"?void 0:(l=(o=this.options.floatingGroupBounds)===null||o===void 0?void 0:o.minimumHeightWithinViewport)!==null&&l!==void 0?l:hu})),m=c.element.querySelector(".dv-void-container");if(!m)throw new Error("failed to find drag handle");f.setupDrag(m,{inDragMode:typeof(n==null?void 0:n.inDragMode)=="boolean"?n.inDragMode:!1});const p=new f8(c,f),y=new Ge(c.api.onDidActiveChange(g=>{g.isActive&&f.bringToFront()}),sm(c.element,g=>{const{width:b,height:v}=g.contentRect;c.layout(b,v)}));p.addDisposables(f.onDidChange(()=>{c.layout(c.width,c.height)}),f.onDidChangeEnd(()=>{this._bufferOnDidLayoutChange.fire()}),c.onDidChange(g=>{f.setBounds({height:g==null?void 0:g.height,width:g==null?void 0:g.width})}),{dispose:()=>{y.dispose(),Np(this._floatingGroups,p),c.model.location={type:"grid"},this.updateWatermark()}}),this._floatingGroups.push(p),c.model.location={type:"floating"},n!=null&&n.skipActiveGroup||this.doSetGroupAndPanelActive(c),this.updateWatermark()}orthogonalize(t,n){switch(this.gridview.normalize(),t){case"top":case"bottom":this.gridview.orientation===Me.HORIZONTAL&&this.gridview.insertOrthogonalSplitviewAtRoot();break;case"left":case"right":this.gridview.orientation===Me.VERTICAL&&this.gridview.insertOrthogonalSplitviewAtRoot();break}switch(t){case"top":case"left":case"center":return this.createGroupAtLocation([0],void 0,n);case"bottom":case"right":return this.createGroupAtLocation([this.gridview.length],void 0,n);default:throw new Error(`unsupported position ${t}`)}}updateOptions(t){var n,s;if(super.updateOptions(t),"floatingGroupBounds"in t)for(const o of this._floatingGroups){switch(t.floatingGroupBounds){case"boundedWithinViewport":o.overlay.minimumInViewportHeight=void 0,o.overlay.minimumInViewportWidth=void 0;break;case void 0:o.overlay.minimumInViewportHeight=hu,o.overlay.minimumInViewportWidth=hu;break;default:o.overlay.minimumInViewportHeight=(n=t.floatingGroupBounds)===null||n===void 0?void 0:n.minimumHeightWithinViewport,o.overlay.minimumInViewportWidth=(s=t.floatingGroupBounds)===null||s===void 0?void 0:s.minimumWidthWithinViewport}o.overlay.setBounds()}this.updateDropTargetModel(t);const a=this.options.disableDnd;this._options=Object.assign(Object.assign({},this.options),t);const r=this.options.disableDnd;a!==r&&this.updateDragAndDropState(),"theme"in t&&this.updateTheme(),this.layout(this.gridview.width,this.gridview.height,!0)}layout(t,n,s){if(super.layout(t,n,s),this._floatingGroups)for(const a of this._floatingGroups)a.overlay.setBounds()}updateDragAndDropState(){for(const t of this.groups)t.model.updateDragAndDropState()}focus(){var t;(t=this.activeGroup)===null||t===void 0||t.focus()}getGroupPanel(t){return this.panels.find(n=>n.id===t)}setActivePanel(t){t.group.model.openPanel(t),this.doSetGroupAndPanelActive(t.group)}moveToNext(t={}){var n;if(!t.group){if(!this.activeGroup)return;t.group=this.activeGroup}if(t.includePanel&&t.group&&t.group.activePanel!==t.group.panels[t.group.panels.length-1]){t.group.model.moveToNext({suppressRoll:!0});return}const s=Ht(t.group.element),a=(n=this.gridview.next(s))===null||n===void 0?void 0:n.view;this.doSetGroupAndPanelActive(a)}moveToPrevious(t={}){var n;if(!t.group){if(!this.activeGroup)return;t.group=this.activeGroup}if(t.includePanel&&t.group&&t.group.activePanel!==t.group.panels[0]){t.group.model.moveToPrevious({suppressRoll:!0});return}const s=Ht(t.group.element),a=(n=this.gridview.previous(s))===null||n===void 0?void 0:n.view;a&&this.doSetGroupAndPanelActive(a)}toJSON(){var t;const n=this.gridview.serialize(),s=this.panels.reduce((l,c)=>(l[c.id]=c.toJSON(),l),{}),a=this._floatingGroups.map(l=>({data:l.group.toJSON(),position:l.overlay.toJSON()})),r=this._popoutGroups.map(l=>({data:l.popoutGroup.toJSON(),gridReferenceGroup:l.referenceGroup,position:l.window.dimensions(),url:l.popoutGroup.api.location.type==="popout"?l.popoutGroup.api.location.popoutUrl:void 0})),o={grid:n,panels:s,activeGroup:(t=this.activeGroup)===null||t===void 0?void 0:t.id};return a.length>0&&(o.floatingGroups=a),r.length>0&&(o.popoutGroups=r),o}fromJSON(t){var n,s;if(this.clear(),typeof t!="object"||t===null)throw new Error("serialized layout must be a non-null object");const{grid:a,panels:r,activeGroup:o}=t;if(a.root.type!=="branch"||!Array.isArray(a.root.data))throw new Error("root must be of type branch");try{const l=this.width,c=this.height,d=p=>{const{id:y,locked:g,hideHeader:b,views:v,activeView:x}=p;if(typeof y!="string")throw new Error("group id must be of type string");const w=this.createGroup({id:y,locked:!!g,hideHeader:!!b});this._onDidAddGroup.fire(w);const _=[];for(const S of v){const k=this._deserializer.fromJSON(r[S],w);_.push(k)}for(let S=0;S<v.length;S++){const k=_[S],j=typeof x=="string"&&x===k.id;w.model.openPanel(k,{skipSetActive:!j,skipSetGroupActive:!0})}return!w.activePanel&&w.panels.length>0&&w.model.openPanel(w.panels[w.panels.length-1],{skipSetGroupActive:!0}),w};this.gridview.deserialize(a,{fromJSON:p=>d(p.data)}),this.layout(l,c,!0);const h=(n=t.floatingGroups)!==null&&n!==void 0?n:[];for(const p of h){const{data:y,position:g}=p,b=d(y);this.addFloatingGroup(b,{position:g,width:g.width,height:g.height,skipRemoveGroup:!0,inDragMode:!1})}const f=(s=t.popoutGroups)!==null&&s!==void 0?s:[],m=[];f.forEach((p,y)=>{const{data:g,position:b,gridReferenceGroup:v,url:x}=p,w=d(g),_=new Promise(S=>{setTimeout(()=>{this.addPopoutGroup(w,{position:b??void 0,overridePopoutGroup:v?w:void 0,referenceGroup:v?this.getPanel(v):void 0,popoutUrl:x}),S()},y*m8)});m.push(_)}),this._popoutRestorationPromise=Promise.all(m).then(()=>{});for(const p of this._floatingGroups)p.overlay.setBounds();if(typeof o=="string"){const p=this.getPanel(o);p&&this.doSetGroupAndPanelActive(p)}}catch(l){console.error("dockview: failed to deserialize layout. Reverting changes",l);for(const c of this.groups)for(const d of c.panels)this.removePanel(d,{removeEmptyGroup:!1,skipDispose:!1});for(const c of this.groups)c.dispose(),this._groups.delete(c.id),this._onDidRemoveGroup.fire(c);for(const c of[...this._floatingGroups])c.dispose();throw this.clear(),l}this.updateWatermark(),requestAnimationFrame(()=>{this.overlayRenderContainer.updateAllPositions()}),this._onDidLayoutFromJSON.fire()}clear(){const t=Array.from(this._groups.values()).map(s=>s.value),n=!!this.activeGroup;for(const s of t)this.removeGroup(s,{skipActive:!0});n&&this.doSetGroupAndPanelActive(void 0),this.gridview.clear()}closeAllGroups(){for(const t of this._groups.entries()){const[n,s]=t;s.value.model.closeAllPanels()}}addPanel(t){var n,s;if(this.panels.find(c=>c.id===t.id))throw new Error(`panel with id ${t.id} already exists`);let a;if(t.position&&t.floating)throw new Error("you can only provide one of: position, floating as arguments to .addPanel(...)");const r={width:t.initialWidth,height:t.initialHeight};let o;if(t.position)if(e8(t.position)){const c=typeof t.position.referencePanel=="string"?this.getGroupPanel(t.position.referencePanel):t.position.referencePanel;if(o=t.position.index,!c)throw new Error(`referencePanel '${t.position.referencePanel}' does not exist`);a=this.findGroup(c)}else if(t8(t.position)){if(a=typeof t.position.referenceGroup=="string"?(n=this._groups.get(t.position.referenceGroup))===null||n===void 0?void 0:n.value:t.position.referenceGroup,o=t.position.index,!a)throw new Error(`referenceGroup '${t.position.referenceGroup}' does not exist`)}else{const c=this.orthogonalize(K_(t.position.direction)),d=this.createPanel(t,c);return c.model.openPanel(d,{skipSetActive:t.inactive,skipSetGroupActive:t.inactive,index:o}),t.inactive||this.doSetGroupAndPanelActive(c),c.api.setSize({height:r==null?void 0:r.height,width:r==null?void 0:r.width}),d}else a=this.activeGroup;let l;if(a){const c=Ih(((s=t.position)===null||s===void 0?void 0:s.direction)||"within");if(t.floating){const d=this.createGroup();this._onDidAddGroup.fire(d);const h=typeof t.floating=="object"&&t.floating!==null?t.floating:{};this.addFloatingGroup(d,Object.assign(Object.assign({},h),{inDragMode:!1,skipRemoveGroup:!0,skipActiveGroup:!0})),l=this.createPanel(t,d),d.model.openPanel(l,{skipSetActive:t.inactive,skipSetGroupActive:t.inactive,index:o})}else if(a.api.location.type==="floating"||c==="center")l=this.createPanel(t,a),a.model.openPanel(l,{skipSetActive:t.inactive,skipSetGroupActive:t.inactive,index:o}),a.api.setSize({width:r==null?void 0:r.width,height:r==null?void 0:r.height}),t.inactive||this.doSetGroupAndPanelActive(a);else{const d=Ht(a.element),h=ti(this.gridview.orientation,d,c),f=this.createGroupAtLocation(h,this.orientationAtLocation(h)===Me.VERTICAL?r==null?void 0:r.height:r==null?void 0:r.width);l=this.createPanel(t,f),f.model.openPanel(l,{skipSetActive:t.inactive,skipSetGroupActive:t.inactive,index:o}),t.inactive||this.doSetGroupAndPanelActive(f)}}else if(t.floating){const c=this.createGroup();this._onDidAddGroup.fire(c);const d=typeof t.floating=="object"&&t.floating!==null?t.floating:{};this.addFloatingGroup(c,Object.assign(Object.assign({},d),{inDragMode:!1,skipRemoveGroup:!0,skipActiveGroup:!0})),l=this.createPanel(t,c),c.model.openPanel(l,{skipSetActive:t.inactive,skipSetGroupActive:t.inactive,index:o})}else{const c=this.createGroupAtLocation([0],this.gridview.orientation===Me.VERTICAL?r==null?void 0:r.height:r==null?void 0:r.width);l=this.createPanel(t,c),c.model.openPanel(l,{skipSetActive:t.inactive,skipSetGroupActive:t.inactive,index:o}),t.inactive||this.doSetGroupAndPanelActive(c)}return l}removePanel(t,n={removeEmptyGroup:!0}){const s=t.group;if(!s)throw new Error(`cannot remove panel ${t.id}. it's missing a group.`);s.model.removePanel(t,{skipSetActiveGroup:n.skipSetActiveGroup}),n.skipDispose||(t.group.model.renderContainer.detatch(t),t.dispose()),s.size===0&&n.removeEmptyGroup&&this.removeGroup(s,{skipActive:n.skipSetActiveGroup})}createWatermarkComponent(){return this.options.createWatermarkComponent?this.options.createWatermarkComponent():new u8}updateWatermark(){var t,n;if(this.groups.filter(s=>s.api.location.type==="grid"&&s.api.isVisible).length===0){if(!this._watermark){this._watermark=this.createWatermarkComponent(),this._watermark.init({containerApi:new Gh(this)});const s=document.createElement("div");s.className="dv-watermark-container",m5(s,"watermark-component"),s.appendChild(this._watermark.element),this.gridview.element.appendChild(s)}}else this._watermark&&(this._watermark.element.parentElement.remove(),(n=(t=this._watermark).dispose)===null||n===void 0||n.call(t),this._watermark=null)}addGroup(t){var n;if(t){let s;if(n8(t)){const d=typeof t.referencePanel=="string"?this.panels.find(h=>h.id===t.referencePanel):t.referencePanel;if(!d)throw new Error(`reference panel ${t.referencePanel} does not exist`);if(s=this.findGroup(d),!s)throw new Error(`reference group for reference panel ${t.referencePanel} does not exist`)}else if(s8(t)){if(s=typeof t.referenceGroup=="string"?(n=this._groups.get(t.referenceGroup))===null||n===void 0?void 0:n.value:t.referenceGroup,!s)throw new Error(`reference group ${t.referenceGroup} does not exist`)}else{const d=this.orthogonalize(K_(t.direction),t);return t.skipSetActive||this.doSetGroupAndPanelActive(d),d}const a=Ih(t.direction||"within"),r=Ht(s.element),o=ti(this.gridview.orientation,r,a),l=this.createGroup(t),c=this.getLocationOrientation(o)===Me.VERTICAL?t.initialHeight:t.initialWidth;return this.doAddGroup(l,o,c),t.skipSetActive||this.doSetGroupAndPanelActive(l),l}else{const s=this.createGroup(t);return this.doAddGroup(s),this.doSetGroupAndPanelActive(s),s}}getLocationOrientation(t){return t.length%2==0&&this.gridview.orientation===Me.HORIZONTAL?Me.HORIZONTAL:Me.VERTICAL}removeGroup(t,n){this.doRemoveGroup(t,n)}doRemoveGroup(t,n){var s;const a=[...t.panels];if(!(n!=null&&n.skipDispose))for(const l of a)this.removePanel(l,{removeEmptyGroup:!1,skipDispose:(s=n==null?void 0:n.skipDispose)!==null&&s!==void 0?s:!1});const r=this.activePanel;if(t.api.location.type==="floating"){const l=this._floatingGroups.find(c=>c.group===t);if(l){if(n!=null&&n.skipDispose||(l.group.dispose(),this._groups.delete(t.id),this._onDidRemoveGroup.fire(t)),Np(this._floatingGroups,l),l.dispose(),!(n!=null&&n.skipActive)&&this._activeGroup===t){const c=Array.from(this._groups.values());this.doSetGroupAndPanelActive(c.length>0?c[0].value:void 0)}return l.group}throw new Error("failed to find floating group")}if(t.api.location.type==="popout"){const l=this._popoutGroups.find(c=>c.popoutGroup===t);if(l){if(!(n!=null&&n.skipDispose)){if(!(n!=null&&n.skipPopoutAssociated)){const d=l.referenceGroup?this.getPanel(l.referenceGroup):void 0;d&&d.panels.length===0&&this.removeGroup(d)}l.popoutGroup.dispose(),this._groups.delete(t.id),this._onDidRemoveGroup.fire(t)}Np(this._popoutGroups,l);const c=l.disposable.dispose();if(!(n!=null&&n.skipPopoutReturn)&&c&&(this.doAddGroup(c,[0]),this.doSetGroupAndPanelActive(c)),!(n!=null&&n.skipActive)&&this._activeGroup===t){const d=Array.from(this._groups.values());this.doSetGroupAndPanelActive(d.length>0?d[0].value:void 0)}return this.updateWatermark(),l.popoutGroup}throw new Error("failed to find popout group")}const o=super.doRemoveGroup(t,n);return n!=null&&n.skipActive||this.activePanel!==r&&this._onDidActivePanelChange.fire(this.activePanel),o}movingLock(t){const n=this._moving;try{return this._moving=!0,t()}finally{this._moving=n}}moveGroupOrPanel(t){var n;const s=t.to.group,a=t.from.groupId,r=t.from.panelId,o=t.to.position,l=t.to.index,c=a?(n=this._groups.get(a))===null||n===void 0?void 0:n.value:void 0;if(!c)throw new Error(`Failed to find group id ${a}`);if(r===void 0){this.moveGroup({from:{group:c},to:{group:s,position:o},skipSetActive:t.skipSetActive});return}if(!o||o==="center"){const d=this.movingLock(()=>c.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!d)throw new Error(`No panel with id ${r}`);c.model.size===0&&this.doRemoveGroup(c,{skipActive:!0});const h=s.model.size===0;this.movingLock(()=>{var f;return s.model.openPanel(d,{index:l,skipSetActive:((f=t.skipSetActive)!==null&&f!==void 0?f:!1)&&!h,skipSetGroupActive:!0})}),t.skipSetActive||this.doSetGroupAndPanelActive(s),this._onDidMovePanel.fire({panel:d,from:c})}else{const d=Ht(s.element),h=ti(this.gridview.orientation,d,o);if(c.size<2){const[f,m]=Pi(h);if(c.api.location.type==="grid"){const b=Ht(c.element),[v,x]=Pi(b);if(vA(v,f)){this.gridview.moveView(v,x,m),this._onDidMovePanel.fire({panel:this.getGroupPanel(r),from:c});return}}if(c.api.location.type==="popout"){const b=this._popoutGroups.find(w=>w.popoutGroup===c),v=this.movingLock(()=>b.popoutGroup.model.removePanel(b.popoutGroup.panels[0],{skipSetActive:!0,skipSetActiveGroup:!0}));this.doRemoveGroup(c,{skipActive:!0});const x=this.createGroupAtLocation(h);this.movingLock(()=>x.model.openPanel(v)),this.doSetGroupAndPanelActive(x),this._onDidMovePanel.fire({panel:this.getGroupPanel(r),from:c});return}const p=this.movingLock(()=>this.doRemoveGroup(c,{skipActive:!0,skipDispose:!0})),y=Ht(s.element),g=ti(this.gridview.orientation,y,o);this.movingLock(()=>this.doAddGroup(p,g)),this.doSetGroupAndPanelActive(p),this._onDidMovePanel.fire({panel:this.getGroupPanel(r),from:c})}else{const f=this.movingLock(()=>c.model.removePanel(r,{skipSetActive:!1,skipSetActiveGroup:!0}));if(!f)throw new Error(`No panel with id ${r}`);const m=ti(this.gridview.orientation,d,o),p=this.createGroupAtLocation(m);this.movingLock(()=>p.model.openPanel(f,{skipSetGroupActive:!0})),this.doSetGroupAndPanelActive(p),this._onDidMovePanel.fire({panel:f,from:c})}}}moveGroup(t){const n=t.from.group,s=t.to.group,a=t.to.position;if(a==="center"){const r=n.activePanel,o=this.movingLock(()=>[...n.panels].map(l=>n.model.removePanel(l.id,{skipSetActive:!0})));(n==null?void 0:n.model.size)===0&&this.doRemoveGroup(n,{skipActive:!0}),this.movingLock(()=>{for(const l of o)s.model.openPanel(l,{skipSetActive:l!==r,skipSetGroupActive:!0})}),t.skipSetActive!==!0?this.doSetGroupAndPanelActive(s):this.activePanel||this.doSetGroupAndPanelActive(s)}else{switch(n.api.location.type){case"grid":this.gridview.removeView(Ht(n.element));break;case"floating":{const r=this._floatingGroups.find(o=>o.group===n);if(!r)throw new Error("failed to find floating group");r.dispose();break}case"popout":{const r=this._popoutGroups.find(l=>l.popoutGroup===n);if(!r)throw new Error("failed to find popout group");const o=this._popoutGroups.indexOf(r);if(o>=0&&this._popoutGroups.splice(o,1),r.referenceGroup){const l=this.getPanel(r.referenceGroup);l&&!l.api.isVisible&&this.doRemoveGroup(l,{skipActive:!0})}r.window.dispose(),s.api.location.type==="grid"?(n.model.renderContainer=this.overlayRenderContainer,n.model.dropTargetContainer=this.rootDropTargetContainer,n.model.location={type:"grid"}):s.api.location.type==="floating"&&(n.model.renderContainer=this.overlayRenderContainer,n.model.dropTargetContainer=this.rootDropTargetContainer,n.model.location={type:"floating"});break}}if(s.api.location.type==="grid"){const r=Ht(s.element),o=ti(this.gridview.orientation,r,a);let l;switch(this.gridview.orientation){case Me.VERTICAL:l=r.length%2==0?n.api.width:n.api.height;break;case Me.HORIZONTAL:l=r.length%2==0?n.api.height:n.api.width;break}this.gridview.addView(n,l,o)}else if(s.api.location.type==="floating"){const r=this._floatingGroups.find(o=>o.group===s);if(r){const o=r.overlay.toJSON();let l,c;"left"in o?l=o.left+50:"right"in o?l=Math.max(0,o.right-o.width-50):l=50,"top"in o?c=o.top+50:"bottom"in o?c=Math.max(0,o.bottom-o.height-50):c=50,this.addFloatingGroup(n,{height:o.height,width:o.width,position:{left:l,top:c}})}}}if(n.panels.forEach(r=>{this._onDidMovePanel.fire({panel:r,from:n})}),t.skipSetActive===!1){const r=s??n;this.doSetGroupAndPanelActive(r)}}doSetGroupActive(t){super.doSetGroupActive(t);const n=this.activePanel;!this._moving&&n!==this._onDidActivePanelChange.value&&this._onDidActivePanelChange.fire(n)}doSetGroupAndPanelActive(t){super.doSetGroupActive(t);const n=this.activePanel;t&&this.hasMaximizedGroup()&&!this.isMaximizedGroup(t)&&this.exitMaximizedGroup(),!this._moving&&n!==this._onDidActivePanelChange.value&&this._onDidActivePanelChange.fire(n)}getNextGroupId(){let t=this.nextGroupId.next();for(;this._groups.has(t);)t=this.nextGroupId.next();return t}createGroup(t){t||(t={});let n=t==null?void 0:t.id;if(n&&this._groups.has(t.id)&&(console.warn(`dockview: Duplicate group id ${t==null?void 0:t.id}. reassigning group id to avoid errors`),n=void 0),!n)for(n=this.nextGroupId.next();this._groups.has(n);)n=this.nextGroupId.next();const s=new Z_(this,n,t);if(s.init({params:{},accessor:this}),!this._groups.has(s.id)){const a=new Ge(s.model.onTabDragStart(r=>{this._onWillDragPanel.fire(r)}),s.model.onGroupDragStart(r=>{this._onWillDragGroup.fire(r)}),s.model.onMove(r=>{const{groupId:o,itemId:l,target:c,index:d}=r;this.moveGroupOrPanel({from:{groupId:o,panelId:l},to:{group:s,position:c,index:d}})}),s.model.onDidDrop(r=>{this._onDidDrop.fire(r)}),s.model.onWillDrop(r=>{this._onWillDrop.fire(r)}),s.model.onWillShowOverlay(r=>{if(this.options.disableDnd){r.preventDefault();return}this._onWillShowOverlay.fire(r)}),s.model.onUnhandledDragOverEvent(r=>{this._onUnhandledDragOverEvent.fire(r)}),s.model.onDidAddPanel(r=>{this._moving||this._onDidAddPanel.fire(r.panel)}),s.model.onDidRemovePanel(r=>{this._moving||this._onDidRemovePanel.fire(r.panel)}),s.model.onDidActivePanelChange(r=>{this._moving||r.panel===this.activePanel&&this._onDidActivePanelChange.value!==r.panel&&this._onDidActivePanelChange.fire(r.panel)}),vr.any(s.model.onDidPanelTitleChange,s.model.onDidPanelParametersChange)(()=>{this._bufferOnDidLayoutChange.fire()}));this._groups.set(s.id,{value:s,disposable:a})}return s.initialize(),s}createPanel(t,n){var s,a,r;const o=t.component,l=(s=t.tabComponent)!==null&&s!==void 0?s:this.options.defaultTabComponent,c=new OA(this,t.id,o,l),d=new ao(t.id,o,l,this,this._api,n,c,{renderer:t.renderer,minimumWidth:t.minimumWidth,minimumHeight:t.minimumHeight,maximumWidth:t.maximumWidth,maximumHeight:t.maximumHeight});return d.init({title:(a=t.title)!==null&&a!==void 0?a:t.id,params:(r=t==null?void 0:t.params)!==null&&r!==void 0?r:{}}),d}createGroupAtLocation(t,n,s){const a=this.createGroup(s);return this.doAddGroup(a,t,n),a}findGroup(t){var n;return(n=Array.from(this._groups.values()).find(s=>s.value.model.containsPanel(t)))===null||n===void 0?void 0:n.value}orientationAtLocation(t){const n=this.gridview.orientation;return t.length%2==1?n:ai(n)}updateDropTargetModel(t){"dndEdges"in t&&(this._rootDropTarget.disabled=typeof t.dndEdges=="boolean"&&t.dndEdges===!1,typeof t.dndEdges=="object"&&t.dndEdges!==null?this._rootDropTarget.setOverlayModel(t.dndEdges):this._rootDropTarget.setOverlayModel(tj)),"rootOverlayModel"in t&&this.updateDropTargetModel({dndEdges:t.dndEdges})}updateTheme(){var t,n;const s=(t=this._options.theme)!==null&&t!==void 0?t:l8;switch(this._themeClassnames.setClassNames(s.className),this.gridview.margin=(n=s.gap)!==null&&n!==void 0?n:0,s.dndOverlayMounting){case"absolute":this.rootDropTargetContainer.disabled=!1;break;case"relative":default:this.rootDropTargetContainer.disabled=!0;break}}}class _8 extends yA{get orientation(){return this.gridview.orientation}set orientation(t){this.gridview.orientation=t}get options(){return this._options}get deserializer(){return this._deserializer}set deserializer(t){this._deserializer=t}constructor(t,n){var s;super(t,{proportionalLayout:(s=n.proportionalLayout)!==null&&s!==void 0?s:!0,orientation:n.orientation,styles:n.hideBorders?{separatorBorder:"transparent"}:void 0,disableAutoResizing:n.disableAutoResizing,className:n.className}),this._onDidLayoutfromJSON=new te,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidRemoveGroup=new te,this.onDidRemoveGroup=this._onDidRemoveGroup.event,this._onDidAddGroup=new te,this.onDidAddGroup=this._onDidAddGroup.event,this._onDidActiveGroupChange=new te,this.onDidActiveGroupChange=this._onDidActiveGroupChange.event,this._options=n,this.addDisposables(this._onDidAddGroup,this._onDidRemoveGroup,this._onDidActiveGroupChange,this.onDidAdd(a=>{this._onDidAddGroup.fire(a)}),this.onDidRemove(a=>{this._onDidRemoveGroup.fire(a)}),this.onDidActiveChange(a=>{this._onDidActiveGroupChange.fire(a)}))}updateOptions(t){super.updateOptions(t);const n=typeof t.orientation=="string"&&this.gridview.orientation!==t.orientation;this._options=Object.assign(Object.assign({},this.options),t),n&&(this.gridview.orientation=t.orientation),this.layout(this.gridview.width,this.gridview.height,!0)}removePanel(t){this.removeGroup(t)}toJSON(){var t;return{grid:this.gridview.serialize(),activePanel:(t=this.activeGroup)===null||t===void 0?void 0:t.id}}setVisible(t,n){this.gridview.setViewVisible(Ht(t.element),n)}setActive(t){this._groups.forEach((n,s)=>{n.value.setActive(t===n.value)})}focus(){var t;(t=this.activeGroup)===null||t===void 0||t.focus()}fromJSON(t){this.clear();const{grid:n,activePanel:s}=t;try{const a=[],r=this.width,o=this.height;if(this.gridview.deserialize(n,{fromJSON:l=>{const{data:c}=l,d=this.options.createComponent({id:c.id,name:c.component});return a.push(()=>d.init({params:c.params,minimumWidth:c.minimumWidth,maximumWidth:c.maximumWidth,minimumHeight:c.minimumHeight,maximumHeight:c.maximumHeight,priority:c.priority,snap:!!c.snap,accessor:this,isVisible:l.visible})),this._onDidAddGroup.fire(d),this.registerPanel(d),d}}),this.layout(r,o,!0),a.forEach(l=>l()),typeof s=="string"){const l=this.getPanel(s);l&&this.doSetGroupActive(l)}}catch(a){for(const r of this.groups)r.dispose(),this._groups.delete(r.id),this._onDidRemoveGroup.fire(r);throw this.clear(),a}this._onDidLayoutfromJSON.fire()}clear(){const t=this.activeGroup,n=Array.from(this._groups.values());for(const s of n)s.disposable.dispose(),this.doRemoveGroup(s.value,{skipActive:!0});t&&this.doSetGroupActive(void 0),this.gridview.clear()}movePanel(t,n){var s;let a;const r=this.gridview.remove(t),o=(s=this._groups.get(n.reference))===null||s===void 0?void 0:s.value;if(!o)throw new Error(`reference group ${n.reference} does not exist`);const l=Ih(n.direction);if(l==="center")throw new Error(`${l} not supported as an option`);{const c=Ht(o.element);a=ti(this.gridview.orientation,c,l)}this.doAddGroup(r,a,n.size)}addPanel(t){var n,s,a,r;let o=(n=t.location)!==null&&n!==void 0?n:[0];if(!((s=t.position)===null||s===void 0)&&s.referencePanel){const c=(a=this._groups.get(t.position.referencePanel))===null||a===void 0?void 0:a.value;if(!c)throw new Error(`reference group ${t.position.referencePanel} does not exist`);const d=Ih(t.position.direction);if(d==="center")throw new Error(`${d} not supported as an option`);{const h=Ht(c.element);o=ti(this.gridview.orientation,h,d)}}const l=this.options.createComponent({id:t.id,name:t.component});return l.init({params:(r=t.params)!==null&&r!==void 0?r:{},minimumWidth:t.minimumWidth,maximumWidth:t.maximumWidth,minimumHeight:t.minimumHeight,maximumHeight:t.maximumHeight,priority:t.priority,snap:!!t.snap,accessor:this,isVisible:!0}),this.registerPanel(l),this.doAddGroup(l,o,t.size),this.doSetGroupActive(l),l}registerPanel(t){const n=new Ge(t.api.onDidFocusChange(s=>{s.isFocused&&this._groups.forEach(a=>{const r=a.value;r!==t?r.setActive(!1):r.setActive(!0)})}));this._groups.set(t.id,{value:t,disposable:n})}moveGroup(t,n,s){const a=this.getPanel(n);if(!a)throw new Error("invalid operation");const r=Ht(t.element),o=ti(this.gridview.orientation,r,s),[l,c]=Pi(o),d=Ht(a.element),[h,f]=Pi(d);if(vA(h,l)){this.gridview.moveView(h,f,c);return}const m=this.doRemoveGroup(a,{skipActive:!0,skipDispose:!0}),p=Ht(t.element),y=ti(this.gridview.orientation,p,s);this.doAddGroup(m,y)}removeGroup(t){super.removeGroup(t)}dispose(){super.dispose(),this._onDidLayoutfromJSON.dispose()}}class j8 extends Pb{get panels(){return this.splitview.getViews()}get options(){return this._options}get length(){return this._panels.size}get orientation(){return this.splitview.orientation}get splitview(){return this._splitview}set splitview(t){this._splitview&&this._splitview.dispose(),this._splitview=t,this._splitviewChangeDisposable.value=new Ge(this._splitview.onDidSashEnd(()=>{this._onDidLayoutChange.fire(void 0)}),this._splitview.onDidAddView(n=>this._onDidAddView.fire(n)),this._splitview.onDidRemoveView(n=>this._onDidRemoveView.fire(n)))}get minimumSize(){return this.splitview.minimumSize}get maximumSize(){return this.splitview.maximumSize}get height(){return this.splitview.orientation===Me.HORIZONTAL?this.splitview.orthogonalSize:this.splitview.size}get width(){return this.splitview.orientation===Me.HORIZONTAL?this.splitview.size:this.splitview.orthogonalSize}constructor(t,n){var s;super(document.createElement("div"),n.disableAutoResizing),this._splitviewChangeDisposable=new On,this._panels=new Map,this._onDidLayoutfromJSON=new te,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidAddView=new te,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new te,this.onDidRemoveView=this._onDidRemoveView.event,this._onDidLayoutChange=new te,this.onDidLayoutChange=this._onDidLayoutChange.event,this.element.style.height="100%",this.element.style.width="100%",this._classNames=new am(this.element),this._classNames.setClassNames((s=n.className)!==null&&s!==void 0?s:""),t.appendChild(this.element),this._options=n,this.splitview=new Yc(this.element,n),this.addDisposables(this._onDidAddView,this._onDidLayoutfromJSON,this._onDidRemoveView,this._onDidLayoutChange)}updateOptions(t){var n,s;"className"in t&&this._classNames.setClassNames((n=t.className)!==null&&n!==void 0?n:""),"disableResizing"in t&&(this.disableResizing=(s=t.disableAutoResizing)!==null&&s!==void 0?s:!1),typeof t.orientation=="string"&&(this.splitview.orientation=t.orientation),this._options=Object.assign(Object.assign({},this.options),t),this.splitview.layout(this.splitview.size,this.splitview.orthogonalSize)}focus(){var t;(t=this._activePanel)===null||t===void 0||t.focus()}movePanel(t,n){this.splitview.moveView(t,n)}setVisible(t,n){const s=this.panels.indexOf(t);this.splitview.setViewVisible(s,n)}setActive(t,n){this._activePanel=t,this.panels.filter(s=>s!==t).forEach(s=>{s.api._onDidActiveChange.fire({isActive:!1}),n||s.focus()}),t.api._onDidActiveChange.fire({isActive:!0}),n||t.focus()}removePanel(t,n){const s=this._panels.get(t.id);if(!s)throw new Error(`unknown splitview panel ${t.id}`);s.dispose(),this._panels.delete(t.id);const a=this.panels.findIndex(l=>l===t);this.splitview.removeView(a,n).dispose();const o=this.panels;o.length>0&&this.setActive(o[o.length-1])}getPanel(t){return this.panels.find(n=>n.id===t)}addPanel(t){var n;if(this._panels.has(t.id))throw new Error(`panel ${t.id} already exists`);const s=this.options.createComponent({id:t.id,name:t.component});s.orientation=this.splitview.orientation,s.init({params:(n=t.params)!==null&&n!==void 0?n:{},minimumSize:t.minimumSize,maximumSize:t.maximumSize,snap:t.snap,priority:t.priority,accessor:this});const a=typeof t.size=="number"?t.size:Es.Distribute,r=typeof t.index=="number"?t.index:void 0;return this.splitview.addView(s,a,r),this.doAddView(s),this.setActive(s),s}layout(t,n){const[s,a]=this.splitview.orientation===Me.HORIZONTAL?[t,n]:[n,t];this.splitview.layout(s,a)}doAddView(t){const n=t.api.onDidFocusChange(s=>{s.isFocused&&this.setActive(t,!0)});this._panels.set(t.id,n)}toJSON(){var t;return{views:this.splitview.getViews().map((s,a)=>({size:this.splitview.getViewSize(a),data:s.toJSON(),snap:!!s.snap,priority:s.priority})),activeView:(t=this._activePanel)===null||t===void 0?void 0:t.id,size:this.splitview.size,orientation:this.splitview.orientation}}fromJSON(t){this.clear();const{views:n,orientation:s,size:a,activeView:r}=t,o=[],l=this.width,c=this.height;if(this.splitview=new Yc(this.element,{orientation:s,proportionalLayout:this.options.proportionalLayout,descriptor:{size:a,views:n.map(d=>{const h=d.data;if(this._panels.has(h.id))throw new Error(`panel ${h.id} already exists`);const f=this.options.createComponent({id:h.id,name:h.component});return o.push(()=>{var m;f.init({params:(m=h.params)!==null&&m!==void 0?m:{},minimumSize:h.minimumSize,maximumSize:h.maximumSize,snap:d.snap,priority:d.priority,accessor:this})}),f.orientation=s,this.doAddView(f),setTimeout(()=>{this._onDidAddView.fire(f)},0),{size:d.size,view:f}})}}),this.layout(l,c),o.forEach(d=>d()),typeof r=="string"){const d=this.getPanel(r);d&&this.setActive(d)}this._onDidLayoutfromJSON.fire()}clear(){for(const t of this._panels.values())t.dispose();for(this._panels.clear();this.splitview.length>0;)this.splitview.removeView(0,Es.Distribute,!0).dispose()}dispose(){for(const n of this._panels.values())n.dispose();this._panels.clear();const t=this.splitview.getViews();this._splitviewChangeDisposable.dispose(),this.splitview.dispose();for(const n of t)n.dispose();this.element.remove(),super.dispose()}}class nj extends Ge{get element(){return this._element}constructor(){super(),this._expandedIcon=Z5(),this._collapsedIcon=EA(),this.disposable=new On,this.apiRef={api:null},this._element=document.createElement("div"),this.element.className="dv-default-header",this._content=document.createElement("span"),this._expander=document.createElement("div"),this._expander.className="dv-pane-header-icon",this.element.appendChild(this._expander),this.element.appendChild(this._content),this.addDisposables(Fe(this._element,"click",()=>{var t;(t=this.apiRef.api)===null||t===void 0||t.setExpanded(!this.apiRef.api.isExpanded)}))}init(t){this.apiRef.api=t.api,this._content.textContent=t.title,this.updateIcon(),this.disposable.value=t.api.onDidExpansionChange(()=>{this.updateIcon()})}updateIcon(){var t;const n=!!(!((t=this.apiRef.api)===null||t===void 0)&&t.isExpanded);Pe(this._expander,"collapsed",!n),n?(this._expander.contains(this._collapsedIcon)&&this._collapsedIcon.remove(),this._expander.contains(this._expandedIcon)||this._expander.appendChild(this._expandedIcon)):(this._expander.contains(this._expandedIcon)&&this._expandedIcon.remove(),this._expander.contains(this._collapsedIcon)||this._expander.appendChild(this._collapsedIcon))}update(t){}dispose(){this.disposable.dispose(),super.dispose()}}const N8=Lb(),sj=22,ij=0,aj=Number.MAX_SAFE_INTEGER;class rj extends U5{constructor(t){super({accessor:t.accessor,id:t.id,component:t.component,headerComponent:t.headerComponent,orientation:t.orientation,isExpanded:t.isExpanded,disableDnd:t.disableDnd,headerSize:t.headerSize,minimumBodySize:t.minimumBodySize,maximumBodySize:t.maximumBodySize}),this.options=t}getBodyComponent(){return this.options.body}getHeaderComponent(){return this.options.header}}class k8 extends Pb{get id(){return this._id}get panels(){return this.paneview.getPanes()}set paneview(t){this._paneview=t,this._disposable.value=new Ge(this._paneview.onDidChange(()=>{this._onDidLayoutChange.fire(void 0)}),this._paneview.onDidAddView(n=>this._onDidAddView.fire(n)),this._paneview.onDidRemoveView(n=>this._onDidRemoveView.fire(n)))}get paneview(){return this._paneview}get minimumSize(){return this.paneview.minimumSize}get maximumSize(){return this.paneview.maximumSize}get height(){return this.paneview.orientation===Me.HORIZONTAL?this.paneview.orthogonalSize:this.paneview.size}get width(){return this.paneview.orientation===Me.HORIZONTAL?this.paneview.size:this.paneview.orthogonalSize}get options(){return this._options}constructor(t,n){var s;super(document.createElement("div"),n.disableAutoResizing),this._id=N8.next(),this._disposable=new On,this._viewDisposables=new Map,this._onDidLayoutfromJSON=new te,this.onDidLayoutFromJSON=this._onDidLayoutfromJSON.event,this._onDidLayoutChange=new te,this.onDidLayoutChange=this._onDidLayoutChange.event,this._onDidDrop=new te,this.onDidDrop=this._onDidDrop.event,this._onDidAddView=new te,this.onDidAddView=this._onDidAddView.event,this._onDidRemoveView=new te,this.onDidRemoveView=this._onDidRemoveView.event,this._onUnhandledDragOverEvent=new te,this.onUnhandledDragOverEvent=this._onUnhandledDragOverEvent.event,this.element.style.height="100%",this.element.style.width="100%",this.addDisposables(this._onDidLayoutChange,this._onDidLayoutfromJSON,this._onDidDrop,this._onDidAddView,this._onDidRemoveView,this._onUnhandledDragOverEvent),this._classNames=new am(this.element),this._classNames.setClassNames((s=n.className)!==null&&s!==void 0?s:""),t.appendChild(this.element),this._options=n,this.paneview=new X_(this.element,{orientation:Me.VERTICAL}),this.addDisposables(this._disposable)}setVisible(t,n){const s=this.panels.indexOf(t);this.paneview.setViewVisible(s,n)}focus(){}updateOptions(t){var n,s;"className"in t&&this._classNames.setClassNames((n=t.className)!==null&&n!==void 0?n:""),"disableResizing"in t&&(this.disableResizing=(s=t.disableAutoResizing)!==null&&s!==void 0?s:!1),this._options=Object.assign(Object.assign({},this.options),t)}addPanel(t){var n,s;const a=this.options.createComponent({id:t.id,name:t.component});let r;t.headerComponent&&this.options.createHeaderComponent&&(r=this.options.createHeaderComponent({id:t.id,name:t.headerComponent})),r||(r=new nj);const o=new rj({id:t.id,component:t.component,headerComponent:t.headerComponent,header:r,body:a,orientation:Me.VERTICAL,isExpanded:!!t.isExpanded,disableDnd:!!this.options.disableDnd,accessor:this,headerSize:(n=t.headerSize)!==null&&n!==void 0?n:sj,minimumBodySize:ij,maximumBodySize:aj});this.doAddPanel(o);const l=typeof t.size=="number"?t.size:Es.Distribute,c=typeof t.index=="number"?t.index:void 0;return o.init({params:(s=t.params)!==null&&s!==void 0?s:{},minimumBodySize:t.minimumBodySize,maximumBodySize:t.maximumBodySize,isExpanded:t.isExpanded,title:t.title,containerApi:new Xc(this),accessor:this}),this.paneview.addPane(o,l,c),o.orientation=this.paneview.orientation,o}removePanel(t){const s=this.panels.findIndex(a=>a===t);this.paneview.removePane(s),this.doRemovePanel(t)}movePanel(t,n){this.paneview.moveView(t,n)}getPanel(t){return this.panels.find(n=>n.id===t)}layout(t,n){const[s,a]=this.paneview.orientation===Me.HORIZONTAL?[t,n]:[n,t];this.paneview.layout(s,a)}toJSON(){const t=a=>a===Number.MAX_SAFE_INTEGER||a===Number.POSITIVE_INFINITY?void 0:a,n=a=>a<=0?void 0:a;return{views:this.paneview.getPanes().map((a,r)=>({size:this.paneview.getViewSize(r),data:a.toJSON(),minimumSize:n(a.minimumBodySize),maximumSize:t(a.maximumBodySize),headerSize:a.headerSize,expanded:a.isExpanded()})),size:this.paneview.size}}fromJSON(t){this.clear();const{views:n,size:s}=t,a=[],r=this.width,o=this.height;this.paneview=new X_(this.element,{orientation:Me.VERTICAL,descriptor:{size:s,views:n.map(l=>{var c,d,h;const f=l.data,m=this.options.createComponent({id:f.id,name:f.component});let p;f.headerComponent&&this.options.createHeaderComponent&&(p=this.options.createHeaderComponent({id:f.id,name:f.headerComponent})),p||(p=new nj);const y=new rj({id:f.id,component:f.component,headerComponent:f.headerComponent,header:p,body:m,orientation:Me.VERTICAL,isExpanded:!!l.expanded,disableDnd:!!this.options.disableDnd,accessor:this,headerSize:(c=l.headerSize)!==null&&c!==void 0?c:sj,minimumBodySize:(d=l.minimumSize)!==null&&d!==void 0?d:ij,maximumBodySize:(h=l.maximumSize)!==null&&h!==void 0?h:aj});return this.doAddPanel(y),a.push(()=>{var g;y.init({params:(g=f.params)!==null&&g!==void 0?g:{},minimumBodySize:l.minimumSize,maximumBodySize:l.maximumSize,title:f.title,isExpanded:!!l.expanded,containerApi:new Xc(this),accessor:this}),y.orientation=this.paneview.orientation}),setTimeout(()=>{this._onDidAddView.fire(y)},0),{size:l.size,view:y}})}}),this.layout(r,o),a.forEach(l=>l()),this._onDidLayoutfromJSON.fire()}clear(){for(const[t,n]of this._viewDisposables.entries())n.dispose();this._viewDisposables.clear(),this.paneview.dispose()}doAddPanel(t){const n=new Ge(t.onDidDrop(s=>{this._onDidDrop.fire(s)}),t.onUnhandledDragOverEvent(s=>{this._onUnhandledDragOverEvent.fire(s)}));this._viewDisposables.set(t.id,n)}doRemovePanel(t){const n=this._viewDisposables.get(t.id);n&&(n.dispose(),this._viewDisposables.delete(t.id))}dispose(){super.dispose();for(const[t,n]of this._viewDisposables.entries())n.dispose();this._viewDisposables.clear(),this.element.remove(),this.paneview.dispose()}}class S8 extends Gb{get priority(){return this._priority}set orientation(t){this._orientation=t}get orientation(){return this._orientation}get minimumSize(){const t=typeof this._minimumSize=="function"?this._minimumSize():this._minimumSize;return t!==this._evaluatedMinimumSize&&(this._evaluatedMinimumSize=t,this.updateConstraints()),t}get maximumSize(){const t=typeof this._maximumSize=="function"?this._maximumSize():this._maximumSize;return t!==this._evaluatedMaximumSize&&(this._evaluatedMaximumSize=t,this.updateConstraints()),t}get snap(){return this._snap}constructor(t,n){super(t,n,new CA(t,n)),this._evaluatedMinimumSize=0,this._evaluatedMaximumSize=Number.POSITIVE_INFINITY,this._minimumSize=0,this._maximumSize=Number.POSITIVE_INFINITY,this._snap=!1,this._onDidChange=new te,this.onDidChange=this._onDidChange.event,this.api.initialize(this),this.addDisposables(this._onDidChange,this.api.onWillVisibilityChange(s=>{const{isVisible:a}=s,{accessor:r}=this._params;r.setVisible(this,a)}),this.api.onActiveChange(()=>{const{accessor:s}=this._params;s.setActive(this)}),this.api.onDidConstraintsChangeInternal(s=>{(typeof s.minimumSize=="number"||typeof s.minimumSize=="function")&&(this._minimumSize=s.minimumSize),(typeof s.maximumSize=="number"||typeof s.maximumSize=="function")&&(this._maximumSize=s.maximumSize),this.updateConstraints()}),this.api.onDidSizeChange(s=>{this._onDidChange.fire({size:s.size})}))}setVisible(t){this.api._onDidVisibilityChange.fire({isVisible:t})}setActive(t){this.api._onDidActiveChange.fire({isActive:t})}layout(t,n){const[s,a]=this.orientation===Me.HORIZONTAL?[t,n]:[n,t];super.layout(s,a)}init(t){super.init(t),this._priority=t.priority,t.minimumSize&&(this._minimumSize=t.minimumSize),t.maximumSize&&(this._maximumSize=t.maximumSize),t.snap&&(this._snap=t.snap)}toJSON(){const t=s=>s===Number.MAX_SAFE_INTEGER||s===Number.POSITIVE_INFINITY?void 0:s,n=s=>s<=0?void 0:s;return Object.assign(Object.assign({},super.toJSON()),{minimumSize:n(this.minimumSize),maximumSize:t(this.maximumSize)})}updateConstraints(){this.api._onDidConstraintsChange.fire({maximumSize:this._evaluatedMaximumSize,minimumSize:this._evaluatedMinimumSize})}}function C8(e,t){return new w8(e,t).api}function D8(e,t){const n=new j8(e,t);return new wA(n)}function E8(e,t){const n=new _8(e,t);return new _A(n)}function A8(e,t){const n=new k8(e,t);return new Xc(n)}const zA=(e,t)=>{const[n,s]=Te.useState(),a=Te.useRef(e.componentProps);return Te.useImperativeHandle(t,()=>({update:r=>{a.current=Object.assign(Object.assign({},a.current),r),s(Date.now())}}),[]),Te.createElement(e.component,a.current)};zA.displayName="DockviewReactJsBridge";const R8=(()=>{let e=1;return{next:()=>`dockview_react_portal_key_${(e++).toString()}`}})(),T8=Te.createContext({});class Pr{constructor(t,n,s,a,r){this.parent=t,this.portalStore=n,this.component=s,this.parameters=a,this.context=r,this._initialProps={},this.disposed=!1,this.createPortal()}update(t){if(this.disposed)throw new Error("invalid operation: resource is already disposed");this.componentInstance?this.componentInstance.update(t):this._initialProps=Object.assign(Object.assign({},this._initialProps),t)}createPortal(){if(this.disposed)throw new Error("invalid operation: resource is already disposed");if(!O8(this.component))throw new Error("Dockview: Only React.memo(...), React.ForwardRef(...) and functional components are accepted as components");const t=Te.createElement(Te.forwardRef(zA),{component:this.component,componentProps:this.parameters,ref:a=>{this.componentInstance=a,Object.keys(this._initialProps).length>0&&(this.componentInstance.update(this._initialProps),this._initialProps={})}}),n=this.context?Te.createElement(T8.Provider,{value:this.context},t):t,s=t0.createPortal(n,this.parent,R8.next());this.ref={portal:s,disposable:this.portalStore.addPortal(s)}}dispose(){var t;(t=this.ref)===null||t===void 0||t.disposable.dispose(),this.disposed=!0}}const lm=()=>{const[e,t]=Te.useState([]);Te.useDebugValue(`Portal count: ${e.length}`);const n=Te.useCallback(s=>{t(r=>[...r,s]);let a=!1;return Zt.from(()=>{if(a)throw new Error("invalid operation: resource already disposed");a=!0,t(r=>r.filter(o=>o!==s))})},[]);return[e,n]};function O8(e){return typeof e=="function"||!!(e!=null&&e.$$typeof)}class oj{get element(){return this._element}constructor(t,n,s){this.id=t,this.component=n,this.reactPortalStore=s,this._onDidFocus=new te,this.onDidFocus=this._onDidFocus.event,this._onDidBlur=new te,this.onDidBlur=this._onDidBlur.event,this._element=document.createElement("div"),this._element.className="dv-react-part",this._element.style.height="100%",this._element.style.width="100%"}focus(){}init(t){this.part=new Pr(this.element,this.reactPortalStore,this.component,{params:t.params,api:t.api,containerApi:t.containerApi})}update(t){var n;(n=this.part)===null||n===void 0||n.update({params:t.params})}layout(t,n){}dispose(){var t;this._onDidFocus.dispose(),this._onDidBlur.dispose(),(t=this.part)===null||t===void 0||t.dispose()}}class lj{get element(){return this._element}constructor(t,n,s){this.id=t,this.component=n,this.reactPortalStore=s,this._element=document.createElement("div"),this._element.className="dv-react-part",this._element.style.height="100%",this._element.style.width="100%"}focus(){}init(t){this.part=new Pr(this.element,this.reactPortalStore,this.component,{params:t.params,api:t.api,containerApi:t.containerApi,tabLocation:t.tabLocation})}update(t){var n;(n=this.part)===null||n===void 0||n.update({params:t.params})}layout(t,n){}dispose(){var t;(t=this.part)===null||t===void 0||t.dispose()}}class cj{get element(){return this._element}constructor(t,n,s){this.id=t,this.component=n,this.reactPortalStore=s,this._element=document.createElement("div"),this._element.className="dv-react-part",this._element.style.height="100%",this._element.style.width="100%"}init(t){this.part=new Pr(this.element,this.reactPortalStore,this.component,{group:t.group,containerApi:t.containerApi})}focus(){}update(t){var n,s,a;this.parameters&&(this.parameters.params=t.params),(n=this.part)===null||n===void 0||n.update({params:(a=(s=this.parameters)===null||s===void 0?void 0:s.params)!==null&&a!==void 0?a:{}})}layout(t,n){}dispose(){var t;(t=this.part)===null||t===void 0||t.dispose()}}class z8{get element(){return this._element}get part(){return this._part}constructor(t,n,s){this.component=t,this.reactPortalStore=n,this._group=s,this.mutableDisposable=new On,this._element=document.createElement("div"),this._element.className="dv-react-part",this._element.style.height="100%",this._element.style.width="100%"}init(t){this.mutableDisposable.value=new Ge(this._group.model.onDidAddPanel(()=>{this.updatePanels()}),this._group.model.onDidRemovePanel(()=>{this.updatePanels()}),this._group.model.onDidActivePanelChange(()=>{this.updateActivePanel()}),t.api.onDidActiveChange(()=>{this.updateGroupActive()})),this._part=new Pr(this.element,this.reactPortalStore,this.component,{api:t.api,containerApi:t.containerApi,panels:this._group.model.panels,activePanel:this._group.model.activePanel,isGroupActive:this._group.api.isActive,group:this._group})}dispose(){var t;this.mutableDisposable.dispose(),(t=this._part)===null||t===void 0||t.dispose()}update(t){var n;(n=this._part)===null||n===void 0||n.update(t.params)}updatePanels(){this.update({params:{panels:this._group.model.panels}})}updateActivePanel(){this.update({params:{activePanel:this._group.model.activePanel}})}updateGroupActive(){this.update({params:{isGroupActive:this._group.api.isActive}})}}function Qr(e,t){return e?n=>new z8(e,t,n):void 0}const mu="props.defaultTabComponent";function M8(e){return mx.reduce((n,s)=>(s in e&&(n[s]=e[s]),n),{})}const MA=Te.forwardRef((e,t)=>{const n=Te.useRef(null),s=Te.useRef(),[a,r]=lm();Te.useImperativeHandle(t,()=>n.current,[]);const o=Te.useRef({});return Te.useEffect(()=>{const l={};mx.forEach(c=>{const d=c,h=e[d];d in e&&h!==o.current[d]&&(l[d]=h)}),s.current&&s.current.updateOptions(l),o.current=e},mx.map(l=>e[l])),Te.useEffect(()=>{var l;if(!n.current)return;const c=(l=e.tabComponents)!==null&&l!==void 0?l:{};e.defaultTabComponent&&(c[mu]=e.defaultTabComponent);const d={createLeftHeaderActionComponent:Qr(e.leftHeaderActionsComponent,{addPortal:r}),createRightHeaderActionComponent:Qr(e.rightHeaderActionsComponent,{addPortal:r}),createPrefixHeaderActionComponent:Qr(e.prefixHeaderActionsComponent,{addPortal:r}),createComponent:p=>new oj(p.id,e.components[p.name],{addPortal:r}),createTabComponent(p){return new lj(p.id,c[p.name],{addPortal:r})},createWatermarkComponent:e.watermarkComponent?()=>new cj("watermark",e.watermarkComponent,{addPortal:r}):void 0,defaultTabComponent:e.defaultTabComponent?mu:void 0},h=C8(n.current,Object.assign(Object.assign({},M8(e)),d)),{clientWidth:f,clientHeight:m}=n.current;return h.layout(f,m),e.onReady&&e.onReady({api:h}),s.current=h,()=>{s.current=void 0,h.dispose()}},[]),Te.useEffect(()=>{if(!s.current)return()=>{};const l=s.current.onDidDrop(c=>{e.onDidDrop&&e.onDidDrop(c)});return()=>{l.dispose()}},[e.onDidDrop]),Te.useEffect(()=>{if(!s.current)return()=>{};const l=s.current.onWillDrop(c=>{e.onWillDrop&&e.onWillDrop(c)});return()=>{l.dispose()}},[e.onWillDrop]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createComponent:l=>new oj(l.id,e.components[l.name],{addPortal:r})})},[e.components]),Te.useEffect(()=>{var l;if(!s.current)return;const c=(l=e.tabComponents)!==null&&l!==void 0?l:{};e.defaultTabComponent&&(c[mu]=e.defaultTabComponent),s.current.updateOptions({defaultTabComponent:e.defaultTabComponent?mu:void 0,createTabComponent(d){return new lj(d.id,c[d.name],{addPortal:r})}})},[e.tabComponents,e.defaultTabComponent]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createWatermarkComponent:e.watermarkComponent?()=>new cj("watermark",e.watermarkComponent,{addPortal:r}):void 0})},[e.watermarkComponent]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createRightHeaderActionComponent:Qr(e.rightHeaderActionsComponent,{addPortal:r})})},[e.rightHeaderActionsComponent]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createLeftHeaderActionComponent:Qr(e.leftHeaderActionsComponent,{addPortal:r})})},[e.leftHeaderActionsComponent]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createPrefixHeaderActionComponent:Qr(e.prefixHeaderActionsComponent,{addPortal:r})})},[e.prefixHeaderActionsComponent]),Te.createElement("div",{style:{height:"100%",width:"100%"},ref:n},a)});MA.displayName="DockviewComponent";class dj extends S8{constructor(t,n,s,a){super(t,n),this.reactComponent=s,this.reactPortalStore=a}getComponent(){var t,n;return new Pr(this.element,this.reactPortalStore,this.reactComponent,{params:(n=(t=this._params)===null||t===void 0?void 0:t.params)!==null&&n!==void 0?n:{},api:this.api,containerApi:new wA(this._params.accessor)})}}function $8(e){return lx.reduce((n,s)=>(s in e&&(n[s]=e[s]),n),{})}const L8=Te.forwardRef((e,t)=>{const n=Te.useRef(null),s=Te.useRef(),[a,r]=lm();Te.useImperativeHandle(t,()=>n.current,[]);const o=Te.useRef({});return Te.useEffect(()=>{const l={};lx.forEach(c=>{const d=c,h=e[d];d in e&&h!==o.current[d]&&(l[d]=h)}),s.current&&s.current.updateOptions(l),o.current=e},lx.map(l=>e[l])),Te.useEffect(()=>{if(!n.current)return()=>{};const l={createComponent:f=>new dj(f.id,f.name,e.components[f.name],{addPortal:r})},c=D8(n.current,Object.assign(Object.assign({},$8(e)),l)),{clientWidth:d,clientHeight:h}=n.current;return c.layout(d,h),e.onReady&&e.onReady({api:c}),s.current=c,()=>{s.current=void 0,c.dispose()}},[]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createComponent:l=>new dj(l.id,l.name,e.components[l.name],{addPortal:r})})},[e.components]),Te.createElement("div",{style:{height:"100%",width:"100%"},ref:n},a)});L8.displayName="SplitviewComponent";class uj extends TA{constructor(t,n,s,a){super(t,n),this.reactComponent=s,this.reactPortalStore=a}getComponent(){var t,n;return new Pr(this.element,this.reactPortalStore,this.reactComponent,{params:(n=(t=this._params)===null||t===void 0?void 0:t.params)!==null&&n!==void 0?n:{},api:this.api,containerApi:new _A(this._params.accessor)})}}function P8(e){return hx.reduce((n,s)=>(s in e&&(n[s]=e[s]),n),{})}const I8=Te.forwardRef((e,t)=>{const n=Te.useRef(null),s=Te.useRef(),[a,r]=lm();Te.useImperativeHandle(t,()=>n.current,[]);const o=Te.useRef({});return Te.useEffect(()=>{const l={};hx.forEach(c=>{const d=c,h=e[d];d in e&&h!==o.current[d]&&(l[d]=h)}),s.current&&s.current.updateOptions(l),o.current=e},hx.map(l=>e[l])),Te.useEffect(()=>{if(!n.current)return()=>{};const l={createComponent:f=>new uj(f.id,f.name,e.components[f.name],{addPortal:r})},c=E8(n.current,Object.assign(Object.assign({},P8(e)),l)),{clientWidth:d,clientHeight:h}=n.current;return c.layout(d,h),e.onReady&&e.onReady({api:c}),s.current=c,()=>{s.current=void 0,c.dispose()}},[]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createComponent:l=>new uj(l.id,l.name,e.components[l.name],{addPortal:r})})},[e.components]),Te.createElement("div",{style:{height:"100%",width:"100%"},ref:n},a)});I8.displayName="GridviewComponent";class pu{get element(){return this._element}constructor(t,n,s){this.id=t,this.component=n,this.reactPortalStore=s,this._element=document.createElement("div"),this._element.style.height="100%",this._element.style.width="100%"}init(t){this.part=new Pr(this.element,this.reactPortalStore,this.component,{params:t.params,api:t.api,title:t.title,containerApi:t.containerApi})}toJSON(){return{id:this.id}}update(t){var n;(n=this.part)===null||n===void 0||n.update(t.params)}dispose(){var t;(t=this.part)===null||t===void 0||t.dispose()}}function G8(e){return fx.reduce((n,s)=>(s in e&&(n[s]=e[s]),n),{})}const H8=Te.forwardRef((e,t)=>{const n=Te.useRef(null),s=Te.useRef(),[a,r]=lm();Te.useImperativeHandle(t,()=>n.current,[]);const o=Te.useRef({});return Te.useEffect(()=>{const l={};fx.forEach(c=>{const d=c,h=e[d];d in e&&h!==o.current[d]&&(l[d]=h)}),s.current&&s.current.updateOptions(l),o.current=e},fx.map(l=>e[l])),Te.useEffect(()=>{var l;if(!n.current)return()=>{};const c=(l=e.headerComponents)!==null&&l!==void 0?l:{},d={createComponent:p=>new pu(p.id,e.components[p.name],{addPortal:r}),createHeaderComponent:p=>new pu(p.id,c[p.name],{addPortal:r})},h=A8(n.current,Object.assign(Object.assign({},G8(e)),d)),{clientWidth:f,clientHeight:m}=n.current;return h.layout(f,m),e.onReady&&e.onReady({api:h}),s.current=h,()=>{s.current=void 0,h.dispose()}},[]),Te.useEffect(()=>{s.current&&s.current.updateOptions({createComponent:l=>new pu(l.id,e.components[l.name],{addPortal:r})})},[e.components]),Te.useEffect(()=>{var l;if(!s.current)return;const c=(l=e.headerComponents)!==null&&l!==void 0?l:{};s.current.updateOptions({createHeaderComponent:d=>new pu(d.id,c[d.name],{addPortal:r})})},[e.headerComponents]),Te.useEffect(()=>{if(!s.current)return()=>{};const l=s.current.onDidDrop(c=>{e.onDidDrop&&e.onDidDrop(c)});return()=>{l.dispose()}},[e.onDidDrop]),Te.createElement("div",{style:{height:"100%",width:"100%"},ref:n},a)});H8.displayName="PaneviewComponent";const V8={get pathname(){return window.location.pathname},get search(){return window.location.search},get hash(){return window.location.hash},replace:e=>window.location.replace(e),setSearch:e=>window.history.replaceState(window.history.state,"",`${window.location.pathname}${e}`)},Bb=u.createContext(null);function xl(){return u.useContext(Bb)??V8}const $A=u.createContext(null);function Ed(e=window.location.pathname){const[t]=e.split("/").filter(Boolean);return t?`/${t}/`:"/"}function Oa(e){const t=e.indexOf("#"),n=t<0?"":e.slice(t),s=t<0?e:e.slice(0,t),a=s.indexOf("?");return{path:a<0?s:s.slice(0,a),search:a<0?"":s.slice(a),hash:n}}const Wb=/^#(?:(releases)|release=(.+)|planned(?:=(.+))?)$/,LA=/^#task=(.+)$/,PA=/^#issue=(.+)$/;function hj(e,t){const n=Oa(e),s=Oa(t),a=r=>Wb.test(r)||LA.test(r)||PA.test(r);return n.path===s.path&&n.search===s.search&&!a(n.hash)&&!a(s.hash)}function px(e,t=document.baseURI){let n;try{n=new URL(e,t)}catch{return null}if(n.origin!==window.location.origin)return null;const s=Ed(window.location.pathname);return!n.pathname.startsWith(s)&&`${n.pathname}/`!==s?null:`${n.pathname.slice(s.length)}${n.search}${n.hash}`}const IA=1,Vu=12,Fb="page";function U8(e,t){if(!Jr(e)||e.version!==IA)return null;const n=e.dockview;if(!Jr(n)||!Jr(n.grid)||!Jr(n.panels))return null;const s=Object.entries(n.panels);if(s.length===0||s.length>Vu)return null;for(const[a,r]of s){if(!Jr(r)||r.id!==a||r.contentComponent!==Fb)return null;const o=Jr(r.params)?r.params.address:void 0;if(typeof o!="string"||!t(o))return null}return n}function B8(e){return{version:IA,dockview:e}}async function W8(e=fetch){try{const t=await e("api/dock-layout",{headers:{Accept:"application/json"}});return t.ok?{layout:(await t.json()).layout??null}:(await Xi(t),{unavailable:!0})}catch{return{unavailable:!0}}}const F8="The layout was not saved",q8="This tab keeps the layout and saves it again on your next change.",kp="The viewer did not answer.";async function Y8(e,t=fetch){let n;try{n=await t("api/dock-layout",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({layout:e})})}catch{return{failed:kp}}if((n.ok||n.status===404||n.status>=500)&&await Xi(n),n.ok)return{saved:!0};if(n.status===404)return{absent:!0};if(n.status>=500)return{failed:kp};let s="";try{const a=await n.json();typeof a.error=="string"&&(s=a.error)}catch{}return{failed:s?/[.!?]$/.test(s)?s:`${s}.`:kp}}function X8(e){const t=e.delay??500;let n,s,a=!1,r=!1,o=Promise.resolve();const l=()=>{n=void 0;const c=s;return s=void 0,!c||r||(o=o.then(async()=>{const d=c();if(!d)return;const h=await e.save(d);"absent"in h?r=!0:"saved"in h?a=!1:a||(a=!0,e.error(`${F8}. ${h.failed} ${q8}`))})),o};return{schedule(c){r||(s=c,n!==void 0&&clearTimeout(n),n=setTimeout(l,t))},flush(){return n!==void 0&&clearTimeout(n),l()},dispose(){n!==void 0&&clearTimeout(n),n=void 0,s=void 0}}}function Jr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const K8={read:()=>W8(),save:e=>Y8(e)},fj=320,mj=200,pj="sdlc-dock-pane-close";function gj(e){return px(e,`${window.location.origin}${Ed()}`)}const cm=u.createContext(null),Z8="(max-width: 767px)";function Q8(){const e=typeof window<"u"&&window.matchMedia?window.matchMedia(Z8):null,[t,n]=u.useState((e==null?void 0:e.matches)??!1);return u.useEffect(()=>{if(!e)return;const s=()=>n(e.matches);return e.addEventListener("change",s),()=>e.removeEventListener("change",s)},[e]),t}const J8={threads:Rc,tasks:mf,queues:Ev,blockers:MS,worktrees:Dv,workspaces:zS,chart:LS},e9={tasks:mf,issues:R$,releases:Tc};function t9(e){return e.kind==="home"?$S:e.kind==="org"?J8[e.page]:e.kind==="project"?e.page?e9[e.page]:OS:MM}function n9(e,t){const n=mc(e,t);return(e.kind==="org"||e.kind==="project")&&e.item!==void 0?`${e.item} · ${n}`:n}function GA(e){var s;const{projects:t}=ss(),n=e.kind==="project"?(s=t==null?void 0:t.find(a=>a.id===e.project))==null?void 0:s.name:void 0;return n9(e,n)}function Sp(){return`${window.location.pathname.slice(Ed().length)}${window.location.search}${window.location.hash}`}function xj(e,t){var r;let n;try{n=decodeURIComponent(t.slice(1))}catch{n=t.slice(1)}const s=document.querySelector(`[data-dock-pane="${e}"]`),a=[...(s==null?void 0:s.querySelectorAll("[id]"))??[]].find(o=>o.id===n);(r=a==null?void 0:a.scrollIntoView)==null||r.call(a)}function sa(e,t){var s;const n=(s=e.getPanel(t))==null?void 0:s.params;return typeof(n==null?void 0:n.address)=="string"?n.address:null}function s9(e){const t=e.toJSON(),{maximizedNode:n,...s}=t.grid;return B8({...t,grid:s})}function i9({api:e,params:t}){const n=u.useContext(cm),s=e.id,{go:a,open:r}=n,o=u.useMemo(()=>{const{path:h,search:f,hash:m}=Oa(t.address);return{pathname:`${Ed()}${h}`,search:f,hash:m,replace:p=>{const y=gj(p);y===null?window.location.assign(p):a(s,y,"replace")},setSearch:p=>a(s,`${h}${p}`,"query")}},[t.address,s,a]),l=u.useCallback(h=>{const f=gj(h);f===null?window.location.assign(h):r(s,f)},[s,r]),c=u.useCallback(h=>n.report(s,h),[n,s]),d=GA(n.pageOf(s));return i.jsx(Bb.Provider,{value:o,children:i.jsx($A.Provider,{value:c,children:i.jsx("div",{className:"dock-pane",role:"region","aria-label":d,"data-dock-pane":s,"data-dock-address":`${o.pathname}${o.search}`,"data-dock-active":n.active===s?"":void 0,children:i.jsx(a9,{navigate:o.replace,open:l},t.nav??0)})})})}function a9({navigate:e,open:t}){const n=u.useContext(cm);return i.jsx(i.Fragment,{children:n.renderPane(e,t)})}function r9({api:e}){const t=u.useContext(cm),n=t.pageOf(e.id),s=GA(n),a=t9(n);return i.jsxs("div",{className:"dock-tab",children:[i.jsx(a,{className:"dock-tab-icon","aria-hidden":"true"}),i.jsx("span",{className:"dock-tab-label",children:s}),i.jsx("button",{type:"button",className:"dock-tab-close","aria-label":`Close ${s}`,onPointerDown:r=>r.stopPropagation(),onMouseDown:r=>r.stopPropagation(),onClick:r=>{r.stopPropagation(),t.close(e.id)},children:i.jsx(xd,{"aria-hidden":"true"})})]})}const o9={[Fb]:i9},l9={name:"viewer",className:"dockview-theme-viewer"};function c9({renderPane:e,pageOf:t,known:n,error:s,store:a=K8}){const[r,o]=u.useState(null),[l,c]=u.useState(null),[d,h]=u.useState(null),[f,m]=u.useState(0),[,p]=u.useState(0),[y,g]=u.useState({}),b=Q8(),v=u.useRef(null),x=u.useRef(null),w=u.useRef(!1),_=u.useRef(1),S=u.useRef(!1),k=u.useRef(s);k.current=s;const j=u.useRef(a),N=u.useMemo(()=>X8({save:q=>j.current.save(q),error:q=>k.current(q)}),[]);u.useEffect(()=>()=>N.dispose(),[N]);const O=u.useRef(!1),T=u.useRef(n);T.current=n;const P=u.useCallback(()=>{const q=x.current;!q||!w.current||O.current||N.schedule(()=>q.panels.some(Z=>{const Q=sa(q,Z.id);return Q!==null&&!T.current(Q)})?null:s9(q))},[N]);u.useEffect(()=>{let q=!0;return j.current.read().then(B=>{q&&c(B)}),()=>{q=!1}},[]);const L=u.useCallback((q,B,Z)=>{const Q=`${Ed()}${B}`,ie={...window.history.state??{},dockPane:q};Z?window.history.pushState(ie,"",Q):window.history.replaceState(ie,"",Q)},[]),G=u.useCallback((q,B,Z)=>{const Q=x.current,ie=Q==null?void 0:Q.getPanel(q);if(!Q||!ie)return;const ce=ie.params,$=Z==="query"||Z==="hash";ie.api.updateParameters({address:B,nav:(ce.nav??0)+($?0:1)}),$||g(F=>{const{[q]:ee,...se}=F;return se}),q===v.current&&L(q,B,Z==="push"||Z==="hash"),p(F=>F+1),P()},[P,L]),A=u.useCallback((q,B,Z="push")=>{var ie;const Q=(ie=x.current)==null?void 0:ie.getPanel(q);Q&&(v.current!==q&&(Q.api.setActive(),v.current=q,h(q)),G(q,B,Z))},[G]),D=u.useCallback(q=>{const B=y[q];if(B)return B;const Z=x.current?sa(x.current,q):null;return t(Z??"")},[y,t]),C=u.useCallback((q,B)=>{g(Z=>JSON.stringify(Z[q])===JSON.stringify(B)?Z:{...Z,[q]:B})},[]),R=u.useCallback(q=>{var ce,$;const B=(ce=x.current)==null?void 0:ce.getPanel(q);if(!B||((($=x.current)==null?void 0:$.panels.length)??0)<=1)return;const Z=()=>B.api.close(),Q=document.querySelector(`[data-dock-pane="${q}"]`),ie=new CustomEvent(pj,{cancelable:!0,detail:{close:Z}});(!Q||Q.dispatchEvent(ie))&&Z()},[]),E=u.useCallback((q,B,Z,Q)=>{const ie=x.current;if(!ie||ie.panels.length>=Vu)return;let ce=`pane-${_.current}`;for(;ie.getPanel(ce);)ce=`pane-${_.current+=1}`;_.current+=1;const $=Q?{referenceGroup:Q,direction:Z}:B?{referencePanel:B,direction:Z}:{direction:Z==="within"?"right":Z};ie.addPanel({id:ce,component:Fb,params:{address:q,nav:0},position:$})},[]);u.useEffect(()=>{if(!r||!l||w.current)return;const q=Sp(),B="layout"in l?U8(l.layout,n):null;let Z=!1;if(B)try{r.fromJSON(B),Z=r.panels.length>0}catch{r.clear()}for(const ie of r.panels){const ce=/^pane-(\d+)$/.exec(ie.id);ce&&(_.current=Math.max(_.current,Number(ce[1])+1))}Z||E(q,null,"right");const Q=r.activePanel??r.panels[0];if(Q){if(v.current=Q.id,h(Q.id),Z&&sa(r,Q.id)!==q){const ie=Q.params;Q.api.updateParameters({address:q,nav:(ie.nav??0)+1})}L(Q.id,q,!1)}for(const ie of r.groups)ie.api.setConstraints({minimumWidth:fj,minimumHeight:mj});m(r.panels.length),w.current=!0},[r,l,n,E,L]);const M=u.useCallback(q=>{var Z,Q;const B=((Z=q.nativeEvent.dataTransfer)==null?void 0:Z.types)??[];!q.getData()&&Array.from(B).includes("text/uri-list")&&(((Q=x.current)==null?void 0:Q.panels.length)??0)<Vu&&q.accept()},[]);u.useEffect(()=>{if(!r)return;const q=[r.onDidAddGroup(B=>B.api.setConstraints({minimumWidth:fj,minimumHeight:mj})),r.onUnhandledDragOverEvent(M),r.onDidActivePanelChange(B=>{if(!B)return;v.current=B.id,h(B.id);const Z=sa(r,B.id);Z!==null&&!S.current&&L(B.id,Z,!1),P()}),r.onDidLayoutChange(()=>{m(r.panels.length),P()}),r.onDidRemovePanel(B=>g(Z=>{const{[B.id]:Q,...ie}=Z;return ie}))];return()=>{for(const B of q)B.dispose()}},[r,P,L,M]),u.useEffect(()=>{if(!r)return;const q=B=>{var ge,de,Le,Ee;if(B.defaultPrevented||B.button!==0||B.metaKey||B.ctrlKey||B.shiftKey)return;const Z=(de=(ge=B.target)==null?void 0:ge.closest)==null?void 0:de.call(ge,"a[href]");if(!Z||Z.target&&Z.target!=="_self"||Z.hasAttribute("download"))return;const Q=((Le=Z.closest("[data-dock-pane]"))==null?void 0:Le.dataset.dockPane)??v.current;if(!Q||!r.getPanel(Q))return;const ie=Z.getAttribute("href")??"",ce=Oa(sa(r,Q)??""),$=ie.startsWith("#")&&ie.length>1?`${ce.path}${ce.search}${ie}`:px(Z.href);if($===null||!n($))return;if(B.altKey){B.preventDefault(),E($,Q,"right");return}const F=Oa(sa(r,Q)??""),ee=Oa($),se=hj(sa(r,Q)??"",$);if(B.preventDefault(),se&&ee.hash&&F.hash===ee.hash){v.current!==Q&&((Ee=r.getPanel(Q))==null||Ee.api.setActive()),xj(Q,ee.hash);return}A(Q,$,se&&ee.hash?"hash":"push"),se&&ee.hash&&xj(Q,ee.hash)};return document.addEventListener("click",q),()=>document.removeEventListener("click",q)},[r,n,A,E]),u.useEffect(()=>{if(!r)return;const q=B=>{var ge;const Z=(ge=B.state)==null?void 0:ge.dockPane,Q=typeof Z=="string"&&r.getPanel(Z)?Z:v.current,ie=Q?r.getPanel(Q):void 0;if(!ie)return;v.current!==ie.id&&(S.current=!0,ie.api.setActive(),S.current=!1,v.current=ie.id);const ce=ie.params,$=Sp();if(ce.address===$)return;if(hj(ce.address,$)){ie.api.updateParameters({address:$,nav:ce.nav??0}),L(ie.id,$,!1),p(de=>de+1),P();return}const F=()=>{ie.api.updateParameters({address:$,nav:(ie.params.nav??0)+1}),L(ie.id,$,!1),p(de=>de+1),P()},ee=document.querySelector(`[data-dock-pane="${ie.id}"]`),se=new CustomEvent(pj,{cancelable:!0,detail:{close:F}});!ee||ee.dispatchEvent(se)?F():L(ie.id,ce.address,!0)};return window.addEventListener("popstate",q),()=>window.removeEventListener("popstate",q)},[r,P,L]),u.useEffect(()=>{if(O.current=b,!r||!w.current)return;const q=r.activePanel;b&&q&&r.groups.length>1?r.maximizeGroup(q):!b&&r.hasMaximizedGroup()&&(r.exitMaximizedGroup(),P())},[r,b,f,d,P]);const H=u.useCallback(q=>{x.current=q.api,o(q.api)},[]),z=u.useCallback(q=>{var Q,ie,ce;if(q.getData())return;const B=(ie=(Q=q.nativeEvent.dataTransfer)==null?void 0:Q.getData("text/uri-list").split(`
433
- `)[0])==null?void 0:ie.trim(),Z=B?px(B):null;Z===null||!n(Z)||E(Z,null,NA(q.position),(ce=q.group)==null?void 0:ce.id)},[n,E]),K=r&&d?sa(r,d):null,oe=d?D(d):t(Sp()),re=f>=Vu,ve=q=>()=>{d&&K!==null&&E(K,d,q)},ke=b?void 0:[{label:"Split right",icon:DM,onSelect:ve("right"),disabled:re||!d},{label:"Split down",icon:w$,onSelect:ve("below"),disabled:re||!d}],ae=u.useMemo(()=>({active:d,pageOf:D,report:C,go:G,open:A,close:R,renderPane:e}),[d,D,C,G,A,R,e]),Ne=["viewer-dock",f<=1?"dock-single":"",b?"dock-mobile":""].filter(Boolean).join(" ");return i.jsx(cm.Provider,{value:ae,children:i.jsx(sA,{page:oe,headerActions:ke,children:i.jsx("div",{className:"viewer-dock-host",children:l===null?i.jsx("div",{className:"dock-loading",children:"Loading…"}):i.jsx(MA,{className:Ne,theme:l9,components:o9,defaultTabComponent:r9,onReady:H,onDidDrop:z,disableFloatingGroups:!0,disableTabsOverflowList:!0,noPanelsOverlay:"emptyGroup"})})})})}const d9=new Set(["not_terminal","another_process","continued","no_open","pending"]);function u9(e){return e==="terminal_denied"?"you":d9.has(e)?"muted":"alert"}function h9(e){return e.replace(/\.*$/,".")}function vj(e){return e.commands?{...e,commands:{...e.commands,open_thread:(t,n)=>f9(t,n)}}:e}async function f9(e,t,n=rA){let s=!1;for(;;){const a=await n(e,s);if("done"in a)return{opened:!0};const{reason:r,error:o,where:l}=a.refused;if(r==="closed"&&!s){if(!await t(l))return{declined:!0};s=!0;continue}return{note:{text:h9(o),role:u9(r),...r==="outdated"?{outdated:!0}:{}}}}}const HA=[["stage","Stage"],["blocker","Blocker"],["recent","Recent"]],m9=10,VA="Threads you pinned; they stay first in every order";function gx(e,t,n){var L,G;const{order:s,folded:a,showAll:r,narrowed:o,max:l=m9}=n,c=new Map(e.map(A=>[A.key,A])),d=A=>A.pinned===!0,h=A=>{var C;if(d(A)||!A.blockedBy||!c.has(A.blockedBy))return!1;const D=new Set([A.key]);for(let R=A.blockedBy;R&&c.has(R);R=(C=c.get(R))==null?void 0:C.blockedBy){if(D.has(R))return!1;D.add(R)}return!0},f=new Map;for(const A of e){if(!h(A))continue;const D=f.get(A.blockedBy)??[];D.push(A),f.set(A.blockedBy,D)}const m=A=>f.get(A.key)??[],p=A=>Math.max(A.mtimeMs??0,...m(A).map(p)),y=A=>!!A.needsYou||m(A).some(y),g=A=>A.activeSince!==void 0,b=(A,D)=>g(A)!==g(D)?g(A)?-1:1:y(A)!==y(D)?y(A)?-1:1:g(A)?A.activeSince-D.activeSince||A.key.localeCompare(D.key):p(D)-p(A),v=(A,D)=>Number(g(D))-Number(g(A))||(g(A)?D.activeSince-A.activeSince:(D.mtimeMs??0)-(A.mtimeMs??0))||A.key.localeCompare(D.key),x=r||o,w=!o,_=(A,D=0)=>s==="blocker"?[{row:A,depth:D},...m(A).flatMap(C=>_(C,D+1))]:[{row:A,depth:0}],S=A=>s==="blocker"?1+m(A).reduce((D,C)=>D+S(C),0):1,k=A=>A.reduce((D,C)=>D+S(C),0),j=(A,D,C,R,E,M)=>{const H=!E||!a.has(A);return{key:A,label:D,...M?{hint:M}:{},count:R,folds:E,open:H,rows:H?C.flatMap(z=>_(z)):[]}},N=e.filter(d),O=e.filter(A=>!d(A)),T=[];N.length&&T.push(j("pinned","Pinned",N,k(N),w,VA));let P=null;if(s==="stage"){const A=new Set(t.map(([R])=>R)),D=new Map(t.map(([R])=>[R,[]]));for(const R of O)(L=D.get(R.stage&&A.has(R.stage)?R.stage:"none"))==null||L.push(R);for(const[R,E,M]of t){const H=(D.get(R)??[]).sort(b);if(!H.length)continue;const z=R==="none"&&!x?H.slice(0,l):H;T.push({...j(R,E,z,H.length,w&&R!=="none",M),count:H.length})}const C=((G=D.get("none"))==null?void 0:G.length)??0;!o&&C>l&&(P={total:C,unstaged:!0})}else{const A=s==="recent"?[...O].sort(v):O.filter(D=>!h(D)).sort(b);if(A.length){const D=x?A:A.slice(0,l),C=j("others",N.length?"Other threads":null,D,k(A),!!N.length&&w);T.push(C),!o&&C.open&&A.length>l&&(P={total:A.length,unstaged:!1})}}return{groups:T,more:P}}function p9(e,t,n,s){const r=gx(e,t,{...n,folded:new Set,showAll:!0}).groups.find(c=>c.rows.some(d=>d.row.key===s));if(!r)return null;const l=!gx(e,t,{...n,folded:new Set}).groups.some(c=>c.rows.some(d=>d.row.key===s));return{group:r.key,capped:l}}const g9=15e3,x9=10,bj="idle-sessions-list",yj="idle-sessions-heading",wj="idle-sessions-confirm-text";function UA(e){return e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}const v9=e=>`${Number.isInteger(e)?e:e.toFixed(1)} h`,BA=e=>e===1?"1 session":`${e} sessions`;function b9(e){const t=e.released.length?`Closed ${BA(e.released.length)}.`:"Closed no sessions.";return e.kept.length?`${t} Kept ${e.kept.length}:`:t}function y9({row:e}){const t=[e.name,e.retired?"continued in another session":"",`idle ${v9(e.idle_hours)}`,UA(e.memory_mb)].filter(Boolean).join(" · ");return i.jsxs("li",{children:[i.jsx("p",{className:"idle-name",children:e.title}),i.jsxs("p",{className:"caption",children:[i.jsxs("span",{className:"muted",children:[t,e.unfinished&&" ·"]}),e.unfinished&&i.jsx("span",{className:"idle-unfinished",children:" unfinished work"})]})]})}function w9(){const[e,t]=u.useState(null),[n,s]=u.useState(!1),[a,r]=u.useState(!1),[o,l]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(""),m=u.useRef(""),p=u.useRef(null),y=u.useRef(null),g=u.useRef(null),b=u.useRef(null),v=u.useRef(0),x=u.useRef(0),w=u.useCallback(async()=>{const G=++v.current,A=await WU();if(!A||G<x.current)return;x.current=G,f("");const D=JSON.stringify(A);D!==m.current&&(m.current=D,t(A))},[]);u.useEffect(()=>{const G=setTimeout(w,0),A=setInterval(w,g9);return()=>{clearTimeout(G),clearInterval(A)}},[w]),u.useEffect(()=>{var A;const G=b.current;G&&(b.current=null,(A={cancel:y,close:p,dismiss:g}[G].current)==null||A.focus())});const _=(e==null?void 0:e.sessions.length)??0;if(u.useEffect(()=>{a&&!_&&o===null&&r(!1)},[a,_,o]),!_&&!c&&!h&&o===null)return null;const S=()=>{o===null&&(r(!0),b.current="cancel")},k=()=>{o===null&&(r(!1),b.current="close")},j=async()=>{if(o!==null)return;l(_),d(null),f("");const G=await FU();x.current=v.current+1,await w(),l(null),r(!1),s(!1),"error"in G?(f(`The sessions were not closed: ${G.error.replace(/\.+$/,"")}.`),b.current="close"):(d(G.done),b.current="dismiss")},N=()=>{d(null),b.current="close"},O=G=>{G.key==="Escape"&&(G.preventDefault(),k())},T=o!==null?`Closing ${BA(o)}…`:c?b9(c):"",P=(e==null?void 0:e.sessions.slice(0,x9))??[],L=_-P.length;return i.jsxs("div",{className:"idle",role:"group",..._?{"aria-labelledby":yj}:{"aria-label":"Idle sessions"},children:[h&&i.jsx("div",{className:"alert",role:"alert",children:h}),_>0&&e&&i.jsxs("div",{className:"idle-head",children:[i.jsxs("div",{className:"idle-title",children:[i.jsxs("h2",{className:"group",id:yj,"aria-label":`Idle sessions, ${_}`,children:["Idle sessions",i.jsx("span",{className:"count",children:_})]}),i.jsxs("p",{className:"caption muted",children:["over ",e.idle_over," h · ",UA(e.memory_mb)]})]}),i.jsxs("div",{className:"tools",children:[i.jsx("button",{type:"button",className:"pin","aria-expanded":n,"aria-controls":bj,"aria-label":n?"Hide the idle sessions list":"Show the idle sessions list",onClick:()=>s(G=>!G),children:n?"Hide":"Show"}),i.jsx("button",{type:"button",className:"pin",ref:p,"aria-expanded":a,"aria-label":"Close idle sessions…",onClick:S,children:"Close idle…"})]})]}),_>0&&i.jsxs("ul",{className:"idle-list",id:bj,hidden:!n,"aria-label":`Sessions idle over ${e==null?void 0:e.idle_over} hours, longest idle first`,children:[P.map(G=>i.jsx(y9,{row:G},G.session)),L>0&&i.jsx("li",{children:i.jsxs("p",{className:"caption muted",children:["…and ",L," more"]})})]}),a&&_>0&&i.jsxs("div",{className:"idle-confirm",role:"group","aria-label":"Close idle sessions","aria-describedby":wj,onKeyDown:O,children:[i.jsxs("p",{id:wj,children:[_===1?"Close this session?":`Close these ${_} sessions?`," Each transcript stays, so reopening a conversation resumes it, and a thread with unfinished work goes on with Continue on its card. A session that is busy or has background work running is kept."]}),i.jsxs("div",{className:"tools start",children:[i.jsx("button",{type:"button",className:"pin","aria-disabled":o!==null?!0:void 0,"aria-busy":o!==null?!0:void 0,onClick:j,children:o!==null?`Closing ${o}…`:`Close ${_}`}),i.jsx("button",{type:"button",className:"pin",ref:y,"aria-disabled":o!==null?!0:void 0,onClick:k,children:"Cancel"})]})]}),i.jsx("p",{className:"idle-status",role:"status",children:T}),c&&i.jsxs(i.Fragment,{children:[c.kept.length>0&&i.jsx("ul",{className:"idle-list","aria-label":"Kept sessions",children:c.kept.map(G=>i.jsxs("li",{children:[i.jsx("p",{className:"idle-name",children:G.title}),i.jsx("p",{className:"caption muted",children:G.why})]},G.session))}),i.jsx("div",{className:"tools start",children:i.jsx("button",{type:"button",className:"pin",ref:g,"aria-label":"Dismiss the close result",onClick:N,children:"Dismiss"})})]})]})}const _j={ok:"lime",you:"amber",alert:"red",waiting:"blue",blocked:"purple",muted:"grey",plain:"grey"};function vl(e){return e&&Object.hasOwn(_j,e)?_j[e]:"grey"}function jj(e){const t=Math.max(0,e);return t<3600?`${Math.max(1,Math.round(t/60))}m`:t<86400?`${Math.round(t/3600)}h`:`${Math.round(t/86400)}d`}function _9(e){const t=Math.max(0,e),[n,s]=t<3600?[Math.max(1,Math.round(t/60)),"minute"]:t<86400?[Math.round(t/3600),"hour"]:[Math.round(t/86400),"day"];return`${n} ${s}${n===1?"":"s"}`}const WA=/ · \d+ unowned issues?, (?:oldest )?\d+[mhd](?= · |$)/;function j9(e){return WA.test(e)}function N9(e){return e.replace(WA,"")}function k9(e,t){const n=e.projects.length>1,s=r=>n?`${r}: `:"",a=[];for(const r of e.projects){if(!r.unowned||r.unowned.count<1)continue;const{count:o}=r.unowned,l=Date.parse(r.unowned.oldest_since)/1e3,c=t-(Number.isFinite(l)?l:t),d=o===1?`1 unowned issue, ${jj(c)}`:`${o} unowned issues, oldest ${jj(c)}`;a.push({project:r.project,label:`${s(r.project)}${d}`,tail:`. Oldest waited ${_9(c)}: opens Issues`,href:`proj/${encodeURIComponent(r.project)}/issues`})}return a}const S9=1e4,C9=6e4,D9=2,Cp="#thread-",E9=["pin","archive-thread","details-toggle","holds-toggle"],A9=2e4,R9=300,T9="Its work goes to whoever carries it on, or it stays in the list as left work if nobody can.",O9=AD("Threads"),z9={working:"▶",prod:"↑",planned:"○"},Nj=3,gu=2,kj=["working","ready","prod","waiting","blocked","paused","planned"],M9={ready:"results ready",prod:"ready for prod"};function $9(e){const t=kj.map(s=>[s,e.filter(a=>a.state===s).length]),n=[...new Set(e.map(s=>s.state).filter(s=>!kj.includes(s)))].map(s=>[s,e.filter(a=>a.state===s).length]);return[...t,...n].filter(([,s])=>s>0).map(([s,a])=>`${a} ${M9[s]??s}`).join(" · ")}const L9={Terminal:"Opening in Terminal · if macOS asks whether sdlc viewer may control Terminal, allow it.","VS Code":"Opening in VS Code, in the window on this thread's folder.","Claude app":"Opening in the Claude app."};function P9(e){return e.agent!=="Claude"?null:e.where==="VS Code"?"Open in VS Code":e.where==="Claude app"?e.open?"Open in Claude app":null:e.where==="Terminal"?"Open in Terminal":null}const xx=[["running","Running"],["you","Needs you"],["blocked","Blocked"],["paused","Paused"],["idle","Idle"]],vx=[["claude","Claude"],["codex","Codex"]],Sj={paused:"Parked on purpose (status paused); waiting on nothing",idle:"Not running, not asking for you, not blocked, and not paused; includes done and ready for production, and threads in line in a promotion queue"},Cj=e=>e.kind??"idle",Dj=e=>e.agent==="Codex"?"codex":"claude";function Ej(e,t,n,s){const a=n.toLowerCase().split(/\s+/).filter(Boolean),r=xx.map(([g])=>g).filter(g=>s.has(g)),o=vx.map(([g])=>g).filter(g=>s.has(g)),l=g=>!r.length||r.includes(Cj(g)),c=g=>!o.length||o.includes(Dj(g)),d=g=>{if(!a.length)return!0;const b=g.search??g.title.toLowerCase();return a.every(v=>b.includes(v))},h=e.filter(d),f={};for(const[g]of xx)f[g]=h.filter(b=>c(b)&&Cj(b)===g).length;for(const[g]of vx)f[g]=h.filter(b=>l(b)&&Dj(b)===g).length;const m=[],p=[],y=[];return e.forEach((g,b)=>{y.length=Math.min(y.length,g.depth);const v=g.depth>0?y[g.depth-1]??null:null,x=d(g)&&l(g)&&c(g);let w=null;x&&(w=v?{depth:v.depth+1,pinned:v.pinned}:{depth:0,pinned:b<t&&g.pinned!==!1},(w.pinned?m:p).push({row:g,depth:w.depth})),y.push(w)}),{rows:[...m,...p],pinned:m.length,counts:f,narrowed:a.length+r.length+o.length>0}}const FA="sdlc-viewer:threads-arrange",Aj={order:"blocker",compact:!1,folded:[],showAll:!1,archived:!1};function I9(){try{const e=JSON.parse(window.localStorage.getItem(FA)??"{}");return{order:HA.some(([t])=>t===e.order)?e.order:Aj.order,compact:e.compact===!0,folded:Array.isArray(e.folded)?e.folded.filter(t=>typeof t=="string"):[],showAll:e.showAll===!0,archived:e.archived===!0}}catch{return Aj}}function G9(e){try{window.localStorage.setItem(FA,JSON.stringify(e))}catch{}}const H9=new Set(["not_terminal","another_process","continued","no_open","pending"]);function Dp({label:e,count:t,hint:n,fold:s}){const a=n?`hint-${e.toLowerCase().replace(/\W+/g,"-")}`:void 0;return i.jsxs(i.Fragment,{children:[s?i.jsx("h2",{className:"group",children:i.jsxs("button",{type:"button",className:"group-fold","aria-expanded":s.open,"aria-label":`${e}, ${t}`,"aria-describedby":a,onClick:s.onToggle,children:[i.jsx("span",{className:"chevron","aria-hidden":"true",children:s.open?"▾":"▸"}),e,i.jsx("span",{className:"count",children:t})]})}):i.jsxs("h2",{className:"group","aria-label":`${e}, ${t}`,"aria-describedby":a,children:[e,i.jsx("span",{className:"count",children:t})]}),n&&i.jsx("span",{className:"sr-only",id:a,children:n})]})}function xu({text:e,role:t}){return i.jsx("span",{className:`badge tone-${vl(t)}`,children:e})}function V9({serves:e}){const t=e.slice(0,D9),n=e.length-t.length;return i.jsxs("p",{className:"caption muted serves",children:[t.map((s,a)=>i.jsxs("span",{children:[a>0&&", ",i.jsxs("a",{href:`releases?planned=${encodeURIComponent(s.planned_release)}`,"aria-label":`serves ${s.name}, ${s.level}: open it in Planned releases`,children:["serves ",s.name," (",s.level,")"]})]},s.planned_release)),n>0&&i.jsxs(i.Fragment,{children:[i.jsxs("span",{"aria-hidden":"true",children:[", +",n," more"]}),i.jsxs("span",{className:"sr-only",children:[", and ",n," more planned releases"]})]})]})}const U9=4;function Rj({track:e}){return i.jsxs("span",{className:"track",children:[i.jsx("span",{className:"track-dots","aria-hidden":"true",children:Array.from({length:U9},(t,n)=>i.jsx("span",{className:["track-dot",n<=e.reached?"reached":"",n===e.target?"target":""].filter(Boolean).join(" ")},n))}),e.label,e.detail&&i.jsxs("span",{className:"sr-only",children:[". ",e.detail]})]})}function B9({tags:e,track:t,brief:n=!1}){const s=t?Math.min(Math.max(t.at??e.length,0),e.length):-1,a=n?e.filter(o=>!o.full):e,r=t?s-(n?e.slice(0,s).filter(o=>o.full).length:0):-1;return i.jsxs(i.Fragment,{children:[a.map((o,l)=>i.jsxs(u.Fragment,{children:[l===r&&t&&i.jsxs(i.Fragment,{children:[" ",i.jsx(Rj,{track:t})]})," · ",i.jsxs("span",{className:`tag tone-${vl(o.role)}`,children:[o.text,o.detail&&i.jsxs("span",{className:"sr-only",children:[". ",o.detail]})]})]},`t${l}`)),r===a.length&&t&&i.jsxs(i.Fragment,{children:[" ",i.jsx(Rj,{track:t})]})]})}function Tj({id:e,href:t}){return t?i.jsx("a",{className:"id-link",href:t,children:e}):i.jsx("span",{className:"id-text",children:e})}function W9(){return u.useMemo(()=>hA({fetcher:(...e)=>fetch(...e)}),[])}function F9(e){if(e.status==="failed")return"failed";if(e.status!=="ok")return null;const t=k9(e.summary,Date.now()/1e3);return t.length?t:null}function q9({lines:e}){return e==="failed"?i.jsx("p",{className:"unowned-issues muted",children:"Unowned issues: Not available"}):e?i.jsx("ul",{className:"unowned-issues",role:"list","aria-label":"Unowned issues",children:e.map(t=>i.jsx("li",{children:i.jsxs("a",{href:t.href,children:[t.label,i.jsx("span",{className:"sr-only",children:t.tail})]})},t.project))}):null}function Y9({onConnection:e,org:t=null,project:n=null}){const[s,a]=u.useState(null),[r,o]=u.useState(!1),l=W9(),c=F9(eA(l)),d=!!(s&&j9(s.line)),h=c==="failed"&&d?null:c,f=s&&Array.isArray(h)?N9(s.line):s==null?void 0:s.line,[m,p]=u.useState(""),[y,g]=u.useState(!1),[b,v]=u.useState(null),[x,w]=u.useState(""),[_,S]=u.useState(!1),[k,j]=u.useState(null),[N,O]=u.useState(null),[T,P]=u.useState(""),L=u.useRef(null),[G,A]=u.useState(0),D=u.useRef(new Map),C=u.useRef(new Map),R=u.useRef(null),[E,M]=u.useState(null),[H,z]=u.useState(null),[K,oe]=u.useState(null),[re,ve]=u.useState(""),[ke,ae]=u.useState(()=>new Set),[Ne,q]=u.useState(null),[B,Z]=u.useState(I9),Q=I=>Z(ue=>{const fe={...ue,...I};return G9(fe),fe}),[ie,ce]=u.useState({groups:[],all:!1}),[$,F]=u.useState(()=>new Set),[ee,se]=u.useState(()=>new Set),ge=u.useRef(B.archived),de=u.useRef(0),Le=u.useRef(null),Ee=u.useRef(""),W=u.useRef(""),_e=u.useRef(""),He=u.useRef(null),Dt=I=>{var ue;return[...((ue=He.current)==null?void 0:ue.querySelectorAll('[id^="thread-"]'))??[]].find(fe=>fe.id===`thread-${I}`)??null},en=u.useContext(Bb),zt=en?en.hash:null,tt=u.useRef(null),ft=u.useRef(null),It=u.useRef(null),zn=I=>{var fe;if(!(I instanceof HTMLButtonElement)||!((fe=He.current)!=null&&fe.contains(I))||!I.dataset.key)return null;const ue=E9.find(De=>I.classList.contains(De));return ue?`${ue} ${I.dataset.key}`:null},gn=I=>{It.current=zn(I.target)},Mn=()=>{setTimeout(()=>{zn(document.activeElement)||(It.current=null)},0)},xe=u.useCallback(async()=>{const I=++de.current,ue=await aA(ge.current);if(I!==de.current)return;const fe=L.current;if(fe&&I>fe.after&&A(Ve=>Ve+1),"none"in ue){o(!0),p(""),e("live");return}if("error"in ue){p(ue.error),e("disconnected");return}o(!1),p(""),w(""),P(""),e("live");const De=JSON.stringify(ue.data);De!==Ee.current&&(Ee.current=De,a(ue.data))},[e]);u.useEffect(()=>{let I=!0;const ue=C.current;BU().then(Ve=>I&&g(Ve)),qU().then(Ve=>I&&S(Ve));const fe=setTimeout(xe,0),De=setInterval(xe,S9);return()=>{I=!1,clearTimeout(fe),clearInterval(De);for(const Ve of ue.values())clearTimeout(Ve);ue.clear()}},[xe]),u.useEffect(()=>{let I=!0;const ue=()=>UU().then(De=>{I&&De&&M(Ve=>JSON.stringify(Ve)===JSON.stringify(De)?Ve:De)});ue();const fe=setInterval(ue,C9);return()=>{I=!1,clearInterval(fe)}},[]),u.useEffect(()=>{const I=fe=>{var Y,he;if(!fe.startsWith(Cp)){oe(null);return}if(fe===W.current)return;let De;try{De=decodeURIComponent(fe.slice(Cp.length))}catch{De=fe.slice(Cp.length)}const Ve=Dt(De);if(!Ve){if(!He.current||!s)return;const Qe=_e.current!==fe;if(_e.current=fe,s.threads.some(gt=>gt.key===De)){const gt=(re||ke.size)&&!Ej(s.threads,s.pinnedCount??0,re,ke).rows.some(At=>At.row.key===De),Vt=s.stages&&(Qe||!gt)?p9(s.threads,s.stages,{order:B.order,folded:new Set,showAll:!1,narrowed:!1},De):null,Et=Vt!==null&&B.folded.includes(Vt.group)&&!ie.groups.includes(Vt.group),Ut=Vt!==null&&Vt.capped&&!B.showAll&&!ie.all;Qe&&(re||ke.size)&&(ve(""),ae(new Set)),Qe&&(re||ke.size)||Et||Ut?(Et||Ut)&&ce(At=>({groups:Et&&Vt?[...At.groups,Vt.group]:At.groups,all:At.all||Ut})):W.current=fe,oe(null);return}oe(De);return}W.current=fe,oe(null),z(De);const tn=Ve.closest("[data-dock-pane]");(!tn||tn.hasAttribute("data-dock-active"))&&((Y=Ve.querySelector(".thread-title"))==null||Y.focus({preventScroll:!0})),(he=Ve.scrollIntoView)==null||he.call(Ve,{block:"center"})},ue=()=>{W.current="",_e.current="",I(window.location.hash)};if(zt!==null){tt.current!==null&&tt.current!==zt&&(W.current="",_e.current=""),tt.current=zt,I(zt);return}return I(window.location.hash),window.addEventListener("hashchange",ue),()=>window.removeEventListener("hashchange",ue)},[s,re,ke,B,ie,zt]),u.useEffect(()=>{if(!H)return;const I=()=>z(null);return document.addEventListener("pointerdown",I,!0),document.addEventListener("keydown",I,!0),()=>{document.removeEventListener("pointerdown",I,!0),document.removeEventListener("keydown",I,!0)}},[H]),u.useLayoutEffect(()=>{const I=It.current??(ft.current?`pin ${ft.current}`:null);if(!I||!He.current)return;const[ue,fe]=[I.slice(0,I.indexOf(" ")),I.slice(I.indexOf(" ")+1)],De=document.activeElement;if(De&&De!==document.body&&!He.current.contains(De)){It.current=null;return}const Ve=[...He.current.querySelectorAll(`button.${ue}`)].find(tn=>tn.dataset.key===fe);Ve?De!==Ve&&Ve.focus({preventScroll:fe!==ft.current}):It.current=null}),u.useLayoutEffect(()=>{var Y;const I=L.current;if(!I||!He.current)return;L.current=null;const ue=[...He.current.querySelectorAll("button.archive-thread")].find(he=>he.dataset.key===I.key);if(ue){ue.focus();return}const fe=I.order.indexOf(I.key),Ve=[...I.order.slice(fe+1),...I.order.slice(0,Math.max(fe,0)).reverse()].map(Dt).find(he=>he!==null),tn=Ve==null?void 0:Ve.querySelector(".thread-title");tn?tn.focus():(Y=R.current)==null||Y.focus()},[G]);const ne=async I=>{if(b)return;const ue=!I.pinned;ft.current=I.key,v(I.key);const fe=await ZU(I.key,ue);v(null),fe||a(De=>De&&{...De,threads:De.threads.map(Ve=>Ve.key===I.key?{...Ve,pinned:ue}:Ve)}),await xe(),w(fe?`The pin was not saved: ${fe}`:""),ft.current===I.key&&(ft.current=null)},[Se,Ye]=u.useState(()=>new Set),[nt,as]=u.useState({}),$n=is(),{confirm:rs,confirm_dialog:Zs}=al(),V=(I,ue)=>as(fe=>{const{[I]:De,...Ve}=fe;return ue?{...Ve,[I]:ue}:Ve}),$e=(I,ue)=>Ye(fe=>{const De=new Set(fe);return ue?De.add(I):De.delete(I),De}),Xe=Object.keys(nt).some(I=>!Se.has(I));u.useEffect(()=>{if(!Xe)return;const I=()=>as(ue=>Object.fromEntries(Object.entries(ue).filter(([fe])=>Se.has(fe))));return document.addEventListener("pointerdown",I,!0),document.addEventListener("click",I,!0),()=>{document.removeEventListener("pointerdown",I,!0),document.removeEventListener("click",I,!0)}},[Xe,Se]);const Mt=I=>setTimeout(()=>{var ue,fe;return(fe=[...((ue=He.current)==null?void 0:ue.querySelectorAll("button.open-thread"))??[]].find(De=>De.dataset.key===I))==null?void 0:fe.focus()},0),Ls=async(I,ue)=>{const fe=await rs({title:`Reopen ${I.title} in Terminal?`,description:`Its session is closed. It opens in a new Terminal window in ${ue??"the thread's folder"}, running claude --resume.`,action_label:"Reopen"});return Mt(I.key),fe},Ni=I=>{const ue=D.current.get(I);if(ue&&Date.now()-ue.at<A9)return ue.detail;const fe=XU(I).then(De=>((De===null||De.failed)&&D.current.delete(I),(De==null?void 0:De.detail)??null));return D.current.set(I,{at:Date.now(),detail:fe}),fe},ki=I=>setTimeout(()=>{var ue,fe;return(fe=[...((ue=He.current)==null?void 0:ue.querySelectorAll("button.archive-thread"))??[]].find(De=>De.dataset.key===I))==null?void 0:fe.focus()},0),Xa=async I=>{var Ve;if(k||N)return;const ue=I.archiveAction==="archive";if(ue){O(I.key);const tn=await Ni(I.key);O(null);const Y=await rs({title:`Archive ${I.title}?`,description:tn??T9,action_label:"Archive"});if(ki(I.key),!Y){D.current.delete(I.key);return}}const fe=[...((Ve=He.current)==null?void 0:Ve.querySelectorAll("article.thread"))??[]].map(tn=>tn.id.slice(7));j(I.key);const De=await KU(I.key,ue);D.current.delete(I.key),j(null),L.current={key:I.key,order:fe,after:de.current},await xe(),P(De?`The archive was not saved: ${De.replace(/\.*$/,".")}`:"")},Ir=async I=>{if(Se.has(I.key))return;let ue=!1;for(;;){$e(I.key,!0),V(I.key,{key:I.key,text:L9[I.where??""]??"Opening.",role:"waiting"});const fe=await rA(I.key,ue);if($e(I.key,!1),"done"in fe){V(I.key,null);return}const{reason:De,error:Ve,where:tn}=fe.refused;if(De==="closed"&&!ue){if(V(I.key,null),!await Ls(I,tn))return;ue=!0;continue}const Y=De==="outdated"?`${Ve.replace(/\.*$/,".")} ${$n}`:Ve.replace(/\.*$/,"."),he=De==="terminal_denied"?"you":H9.has(De)?"muted":"alert";V(I.key,{key:I.key,text:Y,role:he});return}},Oe=(s==null?void 0:s.threads)??[],ht=!r&&Oe.length>0,ln=Ej(Oe,(s==null?void 0:s.pinnedCount)??0,re,ke),cn=ln.pinned,Ln=ln.rows,os=Array.isArray(s==null?void 0:s.stages)?s.stages:null,Ka=new Set(B.folded.filter(I=>!ie.groups.includes(I))),Za=B.showAll||ie.all,Fn=os?gx(Ln.map(I=>I.row),os,{order:B.order,folded:Ka,showAll:Za,narrowed:ln.narrowed}):null,Qa=os?(s==null?void 0:s.archived)??0:0,um=I=>{ce(ue=>({...ue,groups:ue.groups.filter(fe=>fe!==I)})),Q({folded:Ka.has(I)?B.folded.filter(ue=>ue!==I):[...B.folded.filter(ue=>ue!==I),I]})},hm=()=>{ce(I=>({...I,all:!1})),Q({showAll:!Za})},bl=()=>{const I=!B.archived;ge.current=I,Q({archived:I}),xe()},yl=I=>F(ue=>{const fe=new Set(ue);return fe.has(I)?fe.delete(I):fe.add(I),fe}),fm=I=>se(ue=>{const fe=new Set(ue);return fe.has(I)?fe.delete(I):fe.add(I),fe}),Ja=(I,ue)=>i.jsx(X9,{depth:ue,row:E!=null&&E[I.key]?{...I,serves:E[I.key]}:I,arrived:H===I.key,pinnable:y&&typeof I.pinned=="boolean",pinning:b,onPin:()=>ne(I),archiveAction:_?I.archiveAction:void 0,archiving:k,previewing:N,onArchive:()=>Xa(I),onArchiveHover:fe=>{const De=C.current,Ve=De.get(I.key);if(!fe){clearTimeout(Ve),De.delete(I.key);return}I.archiveAction!=="archive"||Ve!==void 0||De.set(I.key,setTimeout(()=>{De.delete(I.key),Ni(I.key)},R9))},opening:Se.has(I.key),note:nt[I.key]??null,onOpen:()=>Ir(I),org:t,project:n,compact:!!os&&B.compact,detailsOpen:$.has(I.key),onDetails:()=>yl(I.key),holdsOpen:ee.has(I.key),onHolds:()=>fm(I.key)});u.useEffect(()=>{if(!ht)return;const I=ue=>{var De,Ve;if(ue.key!=="/"||ue.ctrlKey||ue.metaKey||ue.altKey||ue.defaultPrevented)return;const fe=document.activeElement;fe&&(/^(INPUT|TEXTAREA|SELECT)$/.test(fe.tagName)||fe.isContentEditable)||document.querySelector('[role="dialog"], [role="alertdialog"], dialog[open]')||(ue.preventDefault(),(De=Le.current)==null||De.focus(),(Ve=Le.current)==null||Ve.select())};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[ht]);const mm=I=>ae(ue=>{const fe=new Set(ue);return fe.has(I)?fe.delete(I):fe.add(I),fe}),Gr=()=>{var I;ve(""),ae(new Set),(I=Le.current)==null||I.focus()},Hr=(I,ue)=>{const fe=ln.counts[I]??0,De=ke.has(I),Ve=Sj[I];return i.jsxs("button",{type:"button",className:"filter-chip","aria-pressed":De,"aria-describedby":Ve?`chip-hint-${I}`:void 0,disabled:fe===0&&!De&&Ne!==I,onFocus:()=>q(I),onBlur:()=>q(tn=>tn===I?null:tn),onClick:()=>mm(I),children:[ue," ",fe]},I)};return i.jsxs(i.Fragment,{children:[Zs,i.jsxs("header",{className:"main-head",children:[i.jsx("h1",{ref:R,tabIndex:-1,children:"Threads"}),s&&!r&&i.jsx("p",{className:"muted",children:f})]}),i.jsx(q9,{lines:h}),i.jsxs("section",{className:"card threads","aria-label":"Threads",children:[i.jsx(w9,{}),m&&i.jsxs("div",{className:"alert",role:"alert",children:["Threads unavailable: ",m.replace(/\.+$/,""),". Retrying every 10 s."]}),x&&i.jsx("div",{className:"alert",role:"alert",children:x}),T&&i.jsx("div",{className:"alert",role:"alert",children:T}),i.jsx("p",{className:"caption muted not-listed",role:"status",children:K!==null&&!r?os?i.jsxs(i.Fragment,{children:["Thread ",K," is not in this list.",!B.archived&&Qa>0?" Show archived lists archived threads.":null]}):i.jsxs(i.Fragment,{children:["Thread ",K," is not in this list. ",i.jsx("code",{children:"sdlc view --all"})," lists older threads."]}):null}),ht&&i.jsxs("div",{className:"threads-toolbar",children:[i.jsxs("div",{className:"threads-find",children:[i.jsxs("div",{className:"search-field",children:[i.jsx("input",{ref:Le,type:"search",placeholder:"Search threads","aria-label":"Search threads","aria-keyshortcuts":"/",value:re,onChange:I=>ve(I.target.value),onKeyDown:I=>{I.key==="Escape"&&(I.preventDefault(),re?ve(""):I.currentTarget.blur())}}),re&&i.jsx("button",{type:"button",className:"search-clear","aria-label":"Clear search",onClick:()=>{var I;ve(""),(I=Le.current)==null||I.focus()},children:i.jsx("span",{"aria-hidden":"true",children:"×"})})]}),os&&i.jsx("select",{className:"order-select","aria-label":"Order threads",value:B.order,onChange:I=>Q({order:I.target.value}),children:HA.map(([I,ue])=>i.jsx("option",{value:I,children:ue},I))})]}),i.jsxs("div",{className:"filter-row",children:[i.jsx("div",{className:"filter-group",role:"group","aria-label":"Status",children:xx.map(([I,ue])=>Hr(I,ue))}),i.jsx("div",{className:"filter-group",role:"group","aria-label":"Agent",children:vx.map(([I,ue])=>Hr(I,ue))}),os&&i.jsx("button",{type:"button",className:"filter-chip","aria-pressed":B.compact,onClick:()=>Q({compact:!B.compact}),children:"Compact"})]}),Object.entries(Sj).map(([I,ue])=>i.jsx("span",{className:"sr-only",id:`chip-hint-${I}`,children:ue},I)),i.jsx("p",{className:"caption muted narrowed",role:"status",children:ln.narrowed?i.jsxs(i.Fragment,{children:[Ln.length," of ",Oe.length," threads ·"," ",i.jsx("button",{type:"button",className:"clear-filters","aria-label":"Clear search and filters",onClick:Gr,children:"Clear"})]}):null})]}),r?i.jsx("p",{className:"muted",children:O9}):i.jsxs("div",{className:"thread-list",ref:He,onFocus:gn,onBlur:Mn,children:[Fn==null?void 0:Fn.groups.map(I=>i.jsxs("div",{children:[I.label!==null&&i.jsx(Dp,{label:I.label,count:I.count,hint:I.hint,fold:I.folds?{open:I.open,onToggle:()=>um(I.key)}:void 0}),I.rows.map(({row:ue,depth:fe})=>i.jsx("div",{children:Ja(ue,fe)},ue.key))]},`group-${I.key}`)),!Fn&&Ln.map(({row:I,depth:ue},fe)=>i.jsxs("div",{children:[cn>0&&fe===0&&i.jsx(Dp,{label:"Pinned",count:cn,hint:VA}),cn>0&&fe===cn&&i.jsx(Dp,{label:"Other threads",count:Ln.length-cn}),Ja(I,ue)]},I.key)),s&&!Oe.length&&i.jsx("p",{className:"muted empty",children:"No threads at work or waiting."}),Oe.length>0&&!Ln.length&&i.jsx("p",{className:"muted empty",children:"No threads match."}),s&&s.hidden>0&&i.jsxs("p",{className:"caption muted",children:[s.hidden," older thread(s) not shown; sdlc view --all lists them."]}),(Fn==null?void 0:Fn.more)&&i.jsx("button",{type:"button",className:"list-more","aria-expanded":Za,onClick:hm,children:Fn.more.unstaged?Za?"Show fewer without a stage":`Show all without a stage (${Fn.more.total})`:Za?"Show fewer":`Show all (${Fn.more.total})`}),Qa>0&&i.jsx("button",{type:"button",className:"list-more",onClick:bl,children:B.archived?"Hide archived":`Show ${Qa} archived`})]})]})]})}function X9({row:e,depth:t,arrived:n,pinnable:s,pinning:a,onPin:r,archiveAction:o,archiving:l=null,previewing:c=null,onArchive:d,onArchiveHover:h,opening:f,note:m,onOpen:p,org:y,project:g,compact:b=!1,detailsOpen:v=!1,onDetails:x,holdsOpen:w=!1,onHolds:_}){const S=b&&!v,k=A=>y?`org/${encodeURIComponent(y)}/tasks/${encodeURIComponent(A)}`:null,j=A=>g?`proj/${encodeURIComponent(g)}/issues/${encodeURIComponent(A)}`:null,N=[e.where||e.agent,e.phase,e.age,e.waitsOn?`waits on ${e.waitsOn}`:""].filter(Boolean).join(" · "),O=P9(e),T=l===e.key?o==="archive"?"Archiving":"Unarchiving":o==="archive"?"Archive":"Unarchive",P=`open-note-${e.key}`,[L,G]=u.useState(!1);return i.jsxs("article",{className:["thread",n?"arrived":"",b?"compact-card":""].filter(Boolean).join(" "),id:`thread-${e.key}`,style:{marginLeft:Math.min(t*22,110)},children:[b&&i.jsx("button",{type:"button",className:"details-toggle","data-key":e.key,"aria-label":`Details of ${e.title}`,"aria-expanded":v,onClick:x,children:i.jsx("span",{"aria-hidden":"true",children:v?"▾":"▸"})}),i.jsxs("div",{className:"thread-head",children:[i.jsx("p",{className:"thread-title",tabIndex:-1,children:e.title}),i.jsxs("div",{className:"tools",children:[e.carried?i.jsxs(i.Fragment,{children:[i.jsx(xu,{text:e.carried,role:"waiting"}),e.carriedBatch&&i.jsx(xu,{text:e.carriedBatch.text,role:e.carriedBatch.role})]}):i.jsx(xu,{text:e.status,role:e.role}),e.archived&&i.jsx(xu,{text:"archived",role:"muted"}),O&&i.jsx("button",{type:"button",className:"open-thread","data-key":e.key,"aria-label":`${O}: ${e.title}`,"aria-describedby":P,"aria-disabled":f?!0:void 0,"aria-busy":f?!0:void 0,onClick:()=>{f||p()},children:f?"Opening…":O}),s&&i.jsx("button",{type:"button",className:e.pinned?"pin on":"pin","data-key":e.key,"aria-label":e.pinned?`Unpin ${e.title}`:`Pin ${e.title} to the top`,"aria-disabled":a?!0:void 0,"aria-busy":a===e.key?!0:void 0,onClick:()=>{a||r()},children:e.pinned?"Unpin":"Pin"}),o&&i.jsx("button",{type:"button",className:"archive-thread","data-key":e.key,"aria-label":`${T} ${e.title}`,"aria-disabled":l||c?!0:void 0,"aria-busy":l===e.key||c===e.key?!0:void 0,onPointerEnter:()=>h==null?void 0:h(!0),onFocus:()=>h==null?void 0:h(!0),onPointerLeave:()=>h==null?void 0:h(!1),onBlur:()=>h==null?void 0:h(!1),onClick:()=>{!l&&!c&&(d==null||d())},children:l===e.key?`${T}…`:T})]})]}),i.jsxs("p",{className:S?"caption muted meta one-line":"caption muted meta",children:[N,i.jsx(B9,{tags:e.tags??[],track:e.track,brief:S})]}),O&&i.jsx("p",{id:P,className:`caption open-note tone-${vl((m==null?void 0:m.role)??"muted")}`,role:(m==null?void 0:m.role)==="alert"||(m==null?void 0:m.role)==="you"?"alert":"status",children:(m==null?void 0:m.text)??null}),!S&&e.serves&&e.serves.length>0&&i.jsx(V9,{serves:e.serves}),!S&&e.summary&&i.jsx("p",{className:"caption muted",children:e.summary}),!S&&e.carriedDetail&&i.jsx("p",{className:"line",children:e.carriedDetail}),!S&&e.step&&i.jsx(K9,{t:e}),e.lines.length>0&&i.jsx("p",{className:"caption muted lines-summary",children:$9(e.lines)}),S?null:i.jsx(Z9,{t:e,nested:t>0,allLines:L,setAllLines:G,allHolds:w,onHolds:_,taskHref:k,issueHref:j})]})}function K9({t:e}){return i.jsxs("p",{className:`caption tone-${vl(e.stepRole??"muted")}`,children:["step: ",e.step,e.stepEvidence&&i.jsxs(i.Fragment,{children:[" · ",i.jsx("span",{className:"id-text",children:e.stepEvidence})]}),e.stepRecent&&e.stepRecent.length>0&&i.jsxs("span",{className:"sr-only",children:[". Recent steps, newest first: ",e.stepRecent.join("; ")]})]})}function Oj({text:e,role:t,under:n,detail:s,nested:a}){const r=a&&n?n:void 0,o=[r?e:"",s??""].filter(Boolean).join(". ");return i.jsxs("p",{className:`line tone-${vl(t)}`,children:[r??e,o&&i.jsxs("span",{className:"sr-only",children:[". ",o]})]})}function Z9({t:e,nested:t,allLines:n,setAllLines:s,allHolds:a,onHolds:r,taskHref:o,issueHref:l}){return i.jsxs(i.Fragment,{children:[(n?e.lines:e.lines.slice(0,Nj)).map((c,d)=>i.jsxs("p",{className:`line tone-${vl(c.role)}`,children:[i.jsxs("span",{"aria-hidden":"true",children:[z9[c.state]??"•"," "]}),c.state==="working"&&i.jsx("span",{className:"sr-only",children:"Working: "}),c.task!==void 0&&i.jsx(Tj,{id:c.task,href:o(c.task)}),c.task!==void 0&&c.text?" ":null,c.text]},`l${d}`)),e.lines.length>Nj&&i.jsx("button",{type:"button",className:"lines-more","aria-expanded":n,"aria-label":n?`Show fewer lines of work of ${e.title}`:`Show all ${e.lines.length} lines of work of ${e.title}`,onClick:()=>s(c=>!c),children:n?"Show fewer":`Show all ${e.lines.length}`}),(e.routed??[]).map(c=>i.jsxs("p",{className:"line",children:["routed ",i.jsx(Tj,{id:c.issue,href:l(c.issue)}),c.title?` ${c.title}`:null]},`r${c.issue}`)),e.next&&i.jsxs("p",{className:"caption tone-amber",children:[i.jsx("span",{"aria-hidden":"true",children:"▸ "}),"next (",e.next.state,"): ",e.next.text,i.jsx("span",{className:"sr-only",children:". Say “nn” or approve it in the thread to start it."})]}),e.plannedFor&&i.jsxs("p",{className:"caption tone-grey",children:[i.jsx("span",{"aria-hidden":"true",children:"▸ "}),"planned for ",e.plannedFor.tag,": ",e.plannedFor.text]}),e.reason&&i.jsx(Oj,{...e.reason,nested:t}),(a||!e.holdsAll?e.holds:e.holds.slice(0,gu)).map((c,d)=>i.jsx(Oj,{...c,nested:t},`h${d}`)),e.holdsAll&&e.holds.length>gu&&i.jsx("button",{type:"button",className:"lines-more holds-toggle","data-key":e.key,"aria-expanded":a,"aria-label":a?`Show fewer holds of ${e.title}`:`+${e.holds.length-gu} more holds of ${e.title}`,onClick:r,children:a?"Show fewer holds":`+${e.holds.length-gu} more holds`}),(e.holdsMore??0)>0&&i.jsxs("p",{className:"caption tone-grey",children:["+",e.holdsMore," more holds"]}),e.plan&&i.jsx("p",{className:"caption muted",children:e.plan})]})}const Q9=5e3;function J9(){const[e,t]=u.useState([]),n=u.useRef(0),s=u.useRef(new Map),a=u.useCallback(c=>{const d=s.current.get(c);d&&clearTimeout(d),s.current.delete(c),t(h=>h.filter(f=>f.id!==c))},[]),r=u.useCallback((c,d)=>{const h=n.current+=1;t(f=>[...f.filter(m=>m.tone!=="error").slice(-2),{id:h,tone:c,message:d}]),c==="success"&&s.current.set(h,setTimeout(()=>a(h),Q9))},[a]);u.useEffect(()=>{const c=s.current;return()=>{for(const d of c.values())clearTimeout(d)}},[]);const o=u.useMemo(()=>({success:c=>r("success",c),error:c=>r("error",c)}),[r]),l=i.jsx("div",{"aria-live":"polite","aria-label":"Notifications",className:"pointer-events-none fixed right-4 bottom-4 z-100 flex max-w-[calc(100vw-2rem)] flex-col items-end gap-2",children:e.map(c=>i.jsxs("div",{"data-testid":"viewer-toast",className:"bg-popover text-popover-foreground pointer-events-auto flex w-80 max-w-full items-center gap-3 rounded-md border py-2 pr-2 pl-4 text-sm shadow-lg"+(c.tone==="error"?" border-destructive":""),children:[i.jsx("span",{className:"min-w-0 flex-1 break-words",children:c.message}),i.jsx(U,{type:"button",variant:"ghost",size:"control",className:"shrink-0",onClick:()=>a(c.id),children:"Dismiss"})]},c.id))});return{notify:o,toasts:l}}const eW=/^iss-\d{1,9}$/;function qb(e){return e.split("/").filter(Boolean).slice(1).join("/")}function dm(e,t=""){const n=e.split("/").filter(Boolean);if(n.length===0)return{page:{kind:"home"}};if(n.length===1){const[l]=n;return l==="threads"?{page:{kind:"org",page:"threads"},threads:!0}:l==="chat"?{forward:"threads"}:l==="tasks"?{page:{kind:"org",page:"tasks"},tasks:!0}:l==="issues"?{page:{kind:"home"},issues:!0}:l==="chart"?{page:{kind:"org",page:"chart"},chart:!0}:l==="worktrees"?{page:{kind:"org",page:"worktrees"},worktrees:!0}:l==="workspaces"?{page:{kind:"org",page:"workspaces"},workspaces:!0}:l==="queues"?{page:{kind:"org",page:"queues"},queues:!0}:l==="blockers"?{page:{kind:"org",page:"blockers"},blockers:!0}:l==="releases"?{page:{kind:"home"},releasesForward:!0}:{page:{kind:"not_found"}}}const[s,a,r,o]=n;if(s==="org"&&r==="tasks"&&o==="queues"&&n.length===4)return{forward:`org/${a}/queues${t}`};if(s==="org"&&r==="chat"&&n.length<=4)return{forward:`org/${a}/threads${o===void 0?"":`#thread-${o}`}`};if(s==="org"&&r==="tasks"&&n.length===4){const l=decodeURIComponent(o);return{page:{kind:"org",page:"tasks",item:l},org:decodeURIComponent(a),task:l}}if(s==="org"&&r==="issues"&&n.length<=4){const l=decodeURIComponent(a);return o===void 0?{page:{kind:"home"},org:l,issues:!0}:{page:{kind:"home"},org:l,issues:!0,issue:decodeURIComponent(o)}}if(s==="proj"&&r==="issues"&&n.length<=4){const l=decodeURIComponent(a),c={kind:"project",project:l,page:"issues"};if(o===void 0)return{page:c,issues:!0,project:l};const d=decodeURIComponent(o),h=new URLSearchParams(t);h.delete("from"),h.delete("reported");const f=h.toString();return{page:{...c,item:d,...f?{list_query:f}:{}},issues:!0,project:l,issue:d}}if(s==="org"&&n.length<=3){const l=decodeURIComponent(a);if(r===void 0)return{page:{kind:"home"},org:l};if(r==="threads")return{page:{kind:"org",page:"threads"},org:l,threads:!0};if(r==="tasks")return{page:{kind:"org",page:"tasks"},org:l,tasks:!0};if(r==="chart")return{page:{kind:"org",page:"chart"},org:l,chart:!0};if(r==="worktrees")return{page:{kind:"org",page:"worktrees"},org:l,worktrees:!0};if(r==="workspaces")return{page:{kind:"org",page:"workspaces"},org:l,workspaces:!0};if(r==="queues")return{page:{kind:"org",page:"queues"},org:l,queues:!0};if(r==="blockers")return{page:{kind:"org",page:"blockers"},org:l,blockers:!0};if(r==="releases")return{page:{kind:"home"},org:l,releasesForward:!0}}if(s==="proj"&&n.length<=3){const l=decodeURIComponent(a);if(r===void 0)return{page:{kind:"project",project:l}};if(r==="tasks")return{page:{kind:"project",project:l,page:"tasks"},tasks:!0};if(r==="releases")return{page:{kind:"project",project:l,page:"releases"},releases:!0}}return{page:{kind:"not_found"}}}const zj={label:"Local viewer",can:()=>!1},tW={connecting:"Connecting…",live:"Live · refreshes every 10s",disconnected:"Disconnected"},Mj=()=>i.jsx(iA,{title:"Page not found",more:"This release has no page for the graph's nodes. Read the graph in a terminal with sdlc workspace find <words> and sdlc workspace show <id>.",children:"There is no page at this address in this viewer."});function nW({routeOrg:e}){const{org:t,engine:n}=ss(),{project:s}=Ad(),[a,r]=u.useState("connecting");return n===null?i.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(ji,{page:"Threads"})}):i.jsxs("div",{className:"main viewer-panel",children:[i.jsxs("p",{className:"connection",role:"status",children:[i.jsx("span",{className:`dot ${a}`,"aria-hidden":"true"}),tW[a]]}),i.jsx(Y9,{onConnection:r,org:(t==null?void 0:t.slug)??e??null,project:s})]})}const Ya=()=>i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading…"});function sW({route:e,navigate:t}){var h;const{org:n,projects:s,loading:a,none:r}=ss(),o=e.page.kind==="project"?e.page.project:null,l=o!==null&&s!==null&&!((h=s.find(f=>f.id===o))!=null&&h.current),c=e.org===void 0&&!l&&!a&&n!==null?`org/${encodeURIComponent(n.slug)}/tasks`:null;if(u.useEffect(()=>{c&&t(c)},[c,t]),o!==null&&l)return i.jsx(Wc,{project:o});if(c||e.org===void 0&&a)return i.jsx(Ya,{});const d=(n==null?void 0:n.slug)??e.org;return d===void 0&&o!==null?i.jsx(Wc,{project:o}):d===void 0&&r?i.jsx(gl,{}):d===void 0?i.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:"Tasks open once the organization reads."}):i.jsx(w3,{org:d})}function iW({route:e,navigate:t}){const{org:n,loading:s,none:a}=ss(),r=xl(),o=e.org===void 0&&!s&&n!==null?`org/${encodeURIComponent(n.slug)}/queues${r.search}`:null;if(u.useEffect(()=>{o&&t(o)},[o,t]),o||e.org===void 0&&s)return i.jsx(Ya,{});const l=(n==null?void 0:n.slug)??e.org;if(l===void 0&&a)return i.jsx(gl,{});if(l===void 0)return i.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:"Queues open once the organization reads."});const c=new URLSearchParams(r.search).get("queue");return i.jsx(RH,{org:l,open:c,path:`/org/${encodeURIComponent(l)}/queues`})}function aW({route:e,navigate:t}){var g;const{org:n,projects:s}=ss(),{project:a,settled:r}=Ad(),o=e.project??null,l=o!==null&&s!==null&&!((g=s.find(b=>b.id===o))!=null&&g.current),c=xl(),d=c.search,h=o===null&&a!==null?`proj/${encodeURIComponent(a)}/issues${e.issue?`/${encodeURIComponent(e.issue)}`:""}${d}`:null;u.useEffect(()=>{h&&t(h)},[h,t]);const[f,m]=u.useState(()=>c.search.replace(/^\?/,"")),p=u.useCallback(b=>{c.setSearch(b?`?${b}`:""),m(b)},[c]);if(o!==null&&l)return i.jsx(Wc,{project:o});if(h||o===null&&!r)return i.jsx(Ya,{});if(o===null)return i.jsx(gl,{});const y=encodeURIComponent((n==null?void 0:n.slug)??e.org??"");if(e.issue!==void 0){const b=new URLSearchParams(f).get("from");return i.jsx(uH,{org:y,project:o,issue_id:e.issue,from:b,query:f})}return i.jsx(KG,{org:y,project:o,query:f,onQuery:p})}function rW({issue:e,navigate:t,home:n}){const{project:s,settled:a}=Ad(),r=s!==null?`proj/${encodeURIComponent(s)}/issues/${encodeURIComponent(e)}`:null;return u.useEffect(()=>{r&&t(r)},[r,t]),r||!a?i.jsx(Ya,{}):n}function Ad(){var r;const{projects:e,loading:t,none:n,failure:s}=ss();return{project:((r=e==null?void 0:e.find(o=>o.current))==null?void 0:r.id)??null,settled:!t&&(e!==null||n!==null||!!(s!=null&&s.shown))}}function oW({navigate:e}){const{project:t,settled:n}=Ad(),{search:s}=xl(),a=t!==null?`proj/${encodeURIComponent(t)}/releases${s}`:null;return u.useEffect(()=>{a&&e(a)},[a,e]),a||!n?i.jsx(Ya,{}):i.jsx(gl,{})}function $j(e){const t=new URLSearchParams(e);return{release:t.get("release"),planned:t.has("planned")?t.get("planned")??"":null}}function lW({route:e}){var f;const{org:t,projects:n,loading:s}=ss(),a=e.page.kind==="project"?e.page.project:"",r=xl(),[o,l]=u.useState(()=>$j(r.search));if(s)return i.jsx(Ya,{});if(n!==null&&!((f=n.find(m=>m.id===a))!=null&&f.current))return i.jsx(Wc,{project:a});const d=`/proj/${encodeURIComponent(a)}/releases`,h=m=>{const p=new URLSearchParams;m!=null&&m.startsWith("planned:")?p.set("planned",m.slice(8)):m&&p.set("release",m);const y=p.size>0?`?${p.toString()}`:"";r.setSearch(y),l($j(y))};return i.jsx(EU,{org:(t==null?void 0:t.slug)??"",query:o,onSelect:h,home:d})}function cW({hash:e,navigate:t,home:n}){const{project:s,settled:a}=Ad(),r=Wb.exec(e),o=r!=null&&r[2]?Hh(r[2]):null,l=r!=null&&r[3]?Hh(r[3]):null,c=o!==null?`?release=${encodeURIComponent(o)}`:e.startsWith("#planned")?`?planned${l!==null?`=${encodeURIComponent(l)}`:""}`:"",d=s!==null?`proj/${encodeURIComponent(s)}/releases${c}`:null;return u.useEffect(()=>{d&&t(d)},[d,t]),d||!a?i.jsx(Ya,{}):n}function Ep({route:e,navigate:t}){const{org:n}=ss(),s=xl(),a=u.useContext($A);let r=e.page;const o=e.org!==void 0&&n!==null&&e.org!==n.slug;o&&(r={kind:"not_found"});let l;if(o)l=i.jsx(Mj,{});else if("threads"in e)l=i.jsx(nW,{routeOrg:e.org});else if("task"in e){const d=new URLSearchParams(s.search).get("from");l=i.jsx(eG,{org:encodeURIComponent(e.org),task_id:e.task,from:d})}else"tasks"in e?l=i.jsx(sW,{route:e,navigate:t}):"issues"in e?l=i.jsx(aW,{route:e,navigate:t}):"chart"in e?l=i.jsx($V,{}):"worktrees"in e?l=i.jsx(BB,{org:(n==null?void 0:n.slug)??e.org}):"workspaces"in e?l=i.jsx(jB,{org:(n==null?void 0:n.slug)??e.org}):"queues"in e?l=i.jsx(iW,{route:e,navigate:t}):"blockers"in e?l=i.jsx(cB,{org:(n==null?void 0:n.slug)??e.org}):"releasesForward"in e?l=i.jsx(oW,{navigate:t}):"releases"in e?l=i.jsx(lW,{route:e}):r.kind==="home"?l=i.jsx(gl,{}):r.kind==="project"?l=i.jsx(Wc,{project:r.project}):l=i.jsx(Mj,{});const c=JSON.stringify(r);return u.useEffect(()=>{a==null||a(JSON.parse(c))},[a,c]),a?i.jsx(i.Fragment,{children:l}):i.jsx(sA,{page:r,children:l})}function dW({task:e,navigate:t,home:n}){const{org:s,loading:a,none:r,failure:o}=ss(),l=s!==null?`org/${encodeURIComponent(s.slug)}/tasks/${encodeURIComponent(e)}`:null,c=!a&&(r!==null||!!(o!=null&&o.shown));return u.useEffect(()=>{l&&t(l)},[l,t]),l||!c?i.jsx(Ya,{}):n}const uW=e=>window.location.replace(e);function Hh(e){try{return decodeURIComponent(e)}catch{return null}}function Lj({navigate:e}){const t=xl(),n=dm(qb(t.pathname),t.search),s=LA.exec(t.hash),a=s?Hh(s[1]):null,r=PA.exec(t.hash),o=r?Hh(r[1]):null,l=o!==null&&eW.test(o)?o:null,c=Wb.test(t.hash)?t.hash:null,d=s!==null&&a===null||r!==null&&l===null,h="forward"in n?n.forward:null;if(u.useEffect(()=>{h&&e(h)},[h,e]),"forward"in n)return null;const f=i.jsx(Ep,{route:{page:{kind:"home"}},navigate:e});return d?i.jsx(Ep,{route:{page:{kind:"not_found"}},navigate:e}):a!==null?i.jsx(dW,{task:a,navigate:e,home:f}):l!==null?i.jsx(rW,{issue:l,navigate:e,home:f}):c!==null?i.jsx(cW,{hash:c,navigate:e,home:f}):i.jsx(Ep,{route:n,navigate:e})}function hW(e){const{path:t,search:n}=Oa(e),s=dm(t,n);return"forward"in s?{kind:"home"}:s.page}function fW(e){const{path:t,search:n}=Oa(e),s=dm(t,n);return"forward"in s||s.page.kind!=="not_found"}function mW({navigate:e=uW,data:t,dock:n=!1,dockStore:s}){const a=dm(qb(window.location.pathname),window.location.search),[r,o]=u.useState(null),{notify:l,toasts:c}=J9(),d=!n&&"forward"in a?a.forward:null;u.useEffect(()=>{d&&e(d)},[d,e]);const[h,f]=u.useState(!1);u.useEffect(()=>{if(t)return;let g=!0;return e5().then(b=>{g&&f(b)}),()=>{g=!1}},[t]);const m=u.useMemo(()=>{if(t)return null;const g=KB();return{seams:{probe:{source:async()=>({label:"Local workspace"})},shell:g,tasks:vj(n5()),org:t5(),worktrees:i5(),workspaces:r5(),queues:ZB(),blockers:a5(),releases:s5()},issues:g.issues}},[t]),p=u.useMemo(()=>{if(t||!m)return t;const{report:g,reportCollections:b,...v}=m.issues;return{...m.seams,issues:vj({...v,...h?{report:g,reportCollections:b}:{},commands:{}})}},[t,m,h]),y=(g,b)=>i.jsx(Wg,{data:p,router:{...Iu,navigate:v=>b(Iu.href(v))},identity:zj,notify:l,children:i.jsx(Lj,{navigate:g})});return d||!n&&"forward"in a||!p.shell?null:i.jsx("div",{className:"app-ui dark",ref:o,children:i.jsxs(G$,{container:r,children:[i.jsx(Wg,{data:p,router:Iu,identity:zj,notify:l,children:i.jsx(t3,{shell:p.shell,children:n?i.jsx(c9,{renderPane:y,pageOf:hW,known:fW,error:l.error,store:s}):i.jsx(Lj,{navigate:e})})}),c]})})}dI();V2.createRoot(document.getElementById("root")).render(i.jsx(u.StrictMode,{children:qb(window.location.pathname)==="app-ui-probe"?i.jsx(eB,{}):i.jsx(mW,{dock:!0})}));
433
+ `)[0])==null?void 0:ie.trim(),Z=B?px(B):null;Z===null||!n(Z)||E(Z,null,NA(q.position),(ce=q.group)==null?void 0:ce.id)},[n,E]),K=r&&d?sa(r,d):null,oe=d?D(d):t(Sp()),re=f>=Vu,ve=q=>()=>{d&&K!==null&&E(K,d,q)},ke=b?void 0:[{label:"Split right",icon:DM,onSelect:ve("right"),disabled:re||!d},{label:"Split down",icon:w$,onSelect:ve("below"),disabled:re||!d}],ae=u.useMemo(()=>({active:d,pageOf:D,report:C,go:G,open:A,close:R,renderPane:e}),[d,D,C,G,A,R,e]),Ne=["viewer-dock",f<=1?"dock-single":"",b?"dock-mobile":""].filter(Boolean).join(" ");return i.jsx(cm.Provider,{value:ae,children:i.jsx(sA,{page:oe,headerActions:ke,children:i.jsx("div",{className:"viewer-dock-host",children:l===null?i.jsx("div",{className:"dock-loading",children:"Loading…"}):i.jsx(MA,{className:Ne,theme:l9,components:o9,defaultTabComponent:r9,onReady:H,onDidDrop:z,disableFloatingGroups:!0,disableTabsOverflowList:!0,noPanelsOverlay:"emptyGroup"})})})})}const d9=new Set(["not_terminal","another_process","continued","no_open","pending"]);function u9(e){return e==="terminal_denied"?"you":d9.has(e)?"muted":"alert"}function h9(e){return e.replace(/\.*$/,".")}function vj(e){return e.commands?{...e,commands:{...e.commands,open_thread:(t,n)=>f9(t,n)}}:e}async function f9(e,t,n=rA){let s=!1;for(;;){const a=await n(e,s);if("done"in a)return{opened:!0};const{reason:r,error:o,where:l}=a.refused;if(r==="closed"&&!s){if(!await t(l))return{declined:!0};s=!0;continue}return{note:{text:h9(o),role:u9(r),...r==="outdated"?{outdated:!0}:{}}}}}const HA=[["stage","Stage"],["blocker","Blocker"],["recent","Recent"]],m9=10,VA="Threads you pinned; they stay first in every order";function gx(e,t,n){var L,G;const{order:s,folded:a,showAll:r,narrowed:o,max:l=m9}=n,c=new Map(e.map(A=>[A.key,A])),d=A=>A.pinned===!0,h=A=>{var C;if(d(A)||!A.blockedBy||!c.has(A.blockedBy))return!1;const D=new Set([A.key]);for(let R=A.blockedBy;R&&c.has(R);R=(C=c.get(R))==null?void 0:C.blockedBy){if(D.has(R))return!1;D.add(R)}return!0},f=new Map;for(const A of e){if(!h(A))continue;const D=f.get(A.blockedBy)??[];D.push(A),f.set(A.blockedBy,D)}const m=A=>f.get(A.key)??[],p=A=>Math.max(A.mtimeMs??0,...m(A).map(p)),y=A=>!!A.needsYou||m(A).some(y),g=A=>A.activeSince!==void 0,b=(A,D)=>g(A)!==g(D)?g(A)?-1:1:y(A)!==y(D)?y(A)?-1:1:g(A)?A.activeSince-D.activeSince||A.key.localeCompare(D.key):p(D)-p(A),v=(A,D)=>Number(g(D))-Number(g(A))||(g(A)?D.activeSince-A.activeSince:(D.mtimeMs??0)-(A.mtimeMs??0))||A.key.localeCompare(D.key),x=r||o,w=!o,_=(A,D=0)=>s==="blocker"?[{row:A,depth:D},...m(A).flatMap(C=>_(C,D+1))]:[{row:A,depth:0}],S=A=>s==="blocker"?1+m(A).reduce((D,C)=>D+S(C),0):1,k=A=>A.reduce((D,C)=>D+S(C),0),j=(A,D,C,R,E,M)=>{const H=!E||!a.has(A);return{key:A,label:D,...M?{hint:M}:{},count:R,folds:E,open:H,rows:H?C.flatMap(z=>_(z)):[]}},N=e.filter(d),O=e.filter(A=>!d(A)),T=[];N.length&&T.push(j("pinned","Pinned",N,k(N),w,VA));let P=null;if(s==="stage"){const A=new Set(t.map(([R])=>R)),D=new Map(t.map(([R])=>[R,[]]));for(const R of O)(L=D.get(R.stage&&A.has(R.stage)?R.stage:"none"))==null||L.push(R);for(const[R,E,M]of t){const H=(D.get(R)??[]).sort(b);if(!H.length)continue;const z=R==="none"&&!x?H.slice(0,l):H;T.push({...j(R,E,z,H.length,w&&R!=="none",M),count:H.length})}const C=((G=D.get("none"))==null?void 0:G.length)??0;!o&&C>l&&(P={total:C,unstaged:!0})}else{const A=s==="recent"?[...O].sort(v):O.filter(D=>!h(D)).sort(b);if(A.length){const D=x?A:A.slice(0,l),C=j("others",N.length?"Other threads":null,D,k(A),!!N.length&&w);T.push(C),!o&&C.open&&A.length>l&&(P={total:A.length,unstaged:!1})}}return{groups:T,more:P}}function p9(e,t,n,s){const r=gx(e,t,{...n,folded:new Set,showAll:!0}).groups.find(c=>c.rows.some(d=>d.row.key===s));if(!r)return null;const l=!gx(e,t,{...n,folded:new Set}).groups.some(c=>c.rows.some(d=>d.row.key===s));return{group:r.key,capped:l}}const g9=15e3,x9=10,bj="idle-sessions-list",yj="idle-sessions-heading",wj="idle-sessions-confirm-text";function UA(e){return e>=1024?`${(e/1024).toFixed(1)} GB`:`${Math.round(e)} MB`}const v9=e=>`${Number.isInteger(e)?e:e.toFixed(1)} h`,BA=e=>e===1?"1 session":`${e} sessions`;function b9(e){const t=e.released.length?`Closed ${BA(e.released.length)}.`:"Closed no sessions.";return e.kept.length?`${t} Kept ${e.kept.length}:`:t}function y9({row:e}){const t=[e.name,e.retired?"continued in another session":"",`idle ${v9(e.idle_hours)}`,UA(e.memory_mb)].filter(Boolean).join(" · ");return i.jsxs("li",{children:[i.jsx("p",{className:"idle-name",children:e.title}),i.jsxs("p",{className:"caption",children:[i.jsxs("span",{className:"muted",children:[t,e.unfinished&&" ·"]}),e.unfinished&&i.jsx("span",{className:"idle-unfinished",children:" unfinished work"})]})]})}function w9(){const[e,t]=u.useState(null),[n,s]=u.useState(!1),[a,r]=u.useState(!1),[o,l]=u.useState(null),[c,d]=u.useState(null),[h,f]=u.useState(""),m=u.useRef(""),p=u.useRef(null),y=u.useRef(null),g=u.useRef(null),b=u.useRef(null),v=u.useRef(0),x=u.useRef(0),w=u.useCallback(async()=>{const G=++v.current,A=await WU();if(!A||G<x.current)return;x.current=G,f("");const D=JSON.stringify(A);D!==m.current&&(m.current=D,t(A))},[]);u.useEffect(()=>{const G=setTimeout(w,0),A=setInterval(w,g9);return()=>{clearTimeout(G),clearInterval(A)}},[w]),u.useEffect(()=>{var A;const G=b.current;G&&(b.current=null,(A={cancel:y,close:p,dismiss:g}[G].current)==null||A.focus())});const _=(e==null?void 0:e.sessions.length)??0;if(u.useEffect(()=>{a&&!_&&o===null&&r(!1)},[a,_,o]),!_&&!c&&!h&&o===null)return null;const S=()=>{o===null&&(r(!0),b.current="cancel")},k=()=>{o===null&&(r(!1),b.current="close")},j=async()=>{if(o!==null)return;l(_),d(null),f("");const G=await FU();x.current=v.current+1,await w(),l(null),r(!1),s(!1),"error"in G?(f(`The sessions were not closed: ${G.error.replace(/\.+$/,"")}.`),b.current="close"):(d(G.done),b.current="dismiss")},N=()=>{d(null),b.current="close"},O=G=>{G.key==="Escape"&&(G.preventDefault(),k())},T=o!==null?`Closing ${BA(o)}…`:c?b9(c):"",P=(e==null?void 0:e.sessions.slice(0,x9))??[],L=_-P.length;return i.jsxs("div",{className:"idle",role:"group",..._?{"aria-labelledby":yj}:{"aria-label":"Idle sessions"},children:[h&&i.jsx("div",{className:"alert",role:"alert",children:h}),_>0&&e&&i.jsxs("div",{className:"idle-head",children:[i.jsxs("div",{className:"idle-title",children:[i.jsxs("h2",{className:"group",id:yj,"aria-label":`Idle sessions, ${_}`,children:["Idle sessions",i.jsx("span",{className:"count",children:_})]}),i.jsxs("p",{className:"caption muted",children:["over ",e.idle_over," h · ",UA(e.memory_mb)]})]}),i.jsxs("div",{className:"tools",children:[i.jsx("button",{type:"button",className:"pin","aria-expanded":n,"aria-controls":bj,"aria-label":n?"Hide the idle sessions list":"Show the idle sessions list",onClick:()=>s(G=>!G),children:n?"Hide":"Show"}),i.jsx("button",{type:"button",className:"pin",ref:p,"aria-expanded":a,"aria-label":"Close idle sessions…",onClick:S,children:"Close idle…"})]})]}),_>0&&i.jsxs("ul",{className:"idle-list",id:bj,hidden:!n,"aria-label":`Sessions idle over ${e==null?void 0:e.idle_over} hours, longest idle first`,children:[P.map(G=>i.jsx(y9,{row:G},G.session)),L>0&&i.jsx("li",{children:i.jsxs("p",{className:"caption muted",children:["…and ",L," more"]})})]}),a&&_>0&&i.jsxs("div",{className:"idle-confirm",role:"group","aria-label":"Close idle sessions","aria-describedby":wj,onKeyDown:O,children:[i.jsxs("p",{id:wj,children:[_===1?"Close this session?":`Close these ${_} sessions?`," Each transcript stays, so reopening a conversation resumes it, and a thread with unfinished work goes on with Continue on its card. A session that is busy or has background work running is kept."]}),i.jsxs("div",{className:"tools start",children:[i.jsx("button",{type:"button",className:"pin","aria-disabled":o!==null?!0:void 0,"aria-busy":o!==null?!0:void 0,onClick:j,children:o!==null?`Closing ${o}…`:`Close ${_}`}),i.jsx("button",{type:"button",className:"pin",ref:y,"aria-disabled":o!==null?!0:void 0,onClick:k,children:"Cancel"})]})]}),i.jsx("p",{className:"idle-status",role:"status",children:T}),c&&i.jsxs(i.Fragment,{children:[c.kept.length>0&&i.jsx("ul",{className:"idle-list","aria-label":"Kept sessions",children:c.kept.map(G=>i.jsxs("li",{children:[i.jsx("p",{className:"idle-name",children:G.title}),i.jsx("p",{className:"caption muted",children:G.why})]},G.session))}),i.jsx("div",{className:"tools start",children:i.jsx("button",{type:"button",className:"pin",ref:g,"aria-label":"Dismiss the close result",onClick:N,children:"Dismiss"})})]})]})}const _j={ok:"lime",you:"amber",alert:"red",waiting:"blue",blocked:"purple",muted:"grey",plain:"grey"};function vl(e){return e&&Object.hasOwn(_j,e)?_j[e]:"grey"}function jj(e){const t=Math.max(0,e);return t<3600?`${Math.max(1,Math.round(t/60))}m`:t<86400?`${Math.round(t/3600)}h`:`${Math.round(t/86400)}d`}function _9(e){const t=Math.max(0,e),[n,s]=t<3600?[Math.max(1,Math.round(t/60)),"minute"]:t<86400?[Math.round(t/3600),"hour"]:[Math.round(t/86400),"day"];return`${n} ${s}${n===1?"":"s"}`}const WA=/ · \d+ unowned issues?, (?:oldest )?\d+[mhd](?= · |$)/;function j9(e){return WA.test(e)}function N9(e){return e.replace(WA,"")}function k9(e,t){const n=e.projects.length>1,s=r=>n?`${r}: `:"",a=[];for(const r of e.projects){if(!r.unowned||r.unowned.count<1)continue;const{count:o}=r.unowned,l=Date.parse(r.unowned.oldest_since)/1e3,c=t-(Number.isFinite(l)?l:t),d=o===1?`1 unowned issue, ${jj(c)}`:`${o} unowned issues, oldest ${jj(c)}`;a.push({project:r.project,label:`${s(r.project)}${d}`,tail:`. Oldest waited ${_9(c)}: opens Issues`,href:`proj/${encodeURIComponent(r.project)}/issues`})}return a}const S9=1e4,C9=6e4,D9=2,Cp="#thread-",E9=["pin","archive-thread","details-toggle","holds-toggle"],A9=2e4,R9=300,T9="Its work goes to whoever carries it on, or it stays in the list as left work if nobody can.",O9=AD("Threads"),z9={working:"▶",prod:"↑",planned:"○"},Nj=3,gu=2,kj=["working","ready","prod","waiting","blocked","paused","planned"],M9={ready:"results ready",prod:"ready for prod"};function $9(e){const t=kj.map(s=>[s,e.filter(a=>a.state===s).length]),n=[...new Set(e.map(s=>s.state).filter(s=>!kj.includes(s)))].map(s=>[s,e.filter(a=>a.state===s).length]);return[...t,...n].filter(([,s])=>s>0).map(([s,a])=>`${a} ${M9[s]??s}`).join(" · ")}const L9={Terminal:"Opening in Terminal · if macOS asks whether sdlc viewer may control Terminal, allow it.","VS Code":"Opening in VS Code, in the window on this thread's folder.","Claude app":"Opening in the Claude app."};function P9(e){return e.agent!=="Claude"?null:e.where==="VS Code"?"Open in VS Code":e.where==="Claude app"?e.open?"Open in Claude app":null:e.where==="Terminal"?"Open in Terminal":null}const xx=[["running","Running"],["you","Needs you"],["blocked","Blocked"],["paused","Paused"],["idle","Idle"]],vx=[["claude","Claude"],["codex","Codex"]],Sj={paused:"Parked on purpose (status paused); waiting on nothing",idle:"Not running, not asking for you, not blocked, and not paused; includes done and ready for production, and threads in line in a promotion queue"},Cj=e=>e.kind??"idle",Dj=e=>e.agent==="Codex"?"codex":"claude";function Ej(e,t,n,s){const a=n.toLowerCase().split(/\s+/).filter(Boolean),r=xx.map(([g])=>g).filter(g=>s.has(g)),o=vx.map(([g])=>g).filter(g=>s.has(g)),l=g=>!r.length||r.includes(Cj(g)),c=g=>!o.length||o.includes(Dj(g)),d=g=>{if(!a.length)return!0;const b=g.search??g.title.toLowerCase();return a.every(v=>b.includes(v))},h=e.filter(d),f={};for(const[g]of xx)f[g]=h.filter(b=>c(b)&&Cj(b)===g).length;for(const[g]of vx)f[g]=h.filter(b=>l(b)&&Dj(b)===g).length;const m=[],p=[],y=[];return e.forEach((g,b)=>{y.length=Math.min(y.length,g.depth);const v=g.depth>0?y[g.depth-1]??null:null,x=d(g)&&l(g)&&c(g);let w=null;x&&(w=v?{depth:v.depth+1,pinned:v.pinned}:{depth:0,pinned:b<t&&g.pinned!==!1},(w.pinned?m:p).push({row:g,depth:w.depth})),y.push(w)}),{rows:[...m,...p],pinned:m.length,counts:f,narrowed:a.length+r.length+o.length>0}}const FA="sdlc-viewer:threads-arrange",Aj={order:"blocker",compact:!1,folded:[],showAll:!1,archived:!1};function I9(){try{const e=JSON.parse(window.localStorage.getItem(FA)??"{}");return{order:HA.some(([t])=>t===e.order)?e.order:Aj.order,compact:e.compact===!0,folded:Array.isArray(e.folded)?e.folded.filter(t=>typeof t=="string"):[],showAll:e.showAll===!0,archived:e.archived===!0}}catch{return Aj}}function G9(e){try{window.localStorage.setItem(FA,JSON.stringify(e))}catch{}}const H9=new Set(["not_terminal","another_process","continued","no_open","pending"]);function Dp({label:e,count:t,hint:n,fold:s}){const a=n?`hint-${e.toLowerCase().replace(/\W+/g,"-")}`:void 0;return i.jsxs(i.Fragment,{children:[s?i.jsx("h2",{className:"group",children:i.jsxs("button",{type:"button",className:"group-fold","aria-expanded":s.open,"aria-label":`${e}, ${t}`,"aria-describedby":a,onClick:s.onToggle,children:[i.jsx("span",{className:"chevron","aria-hidden":"true",children:s.open?"▾":"▸"}),e,i.jsx("span",{className:"count",children:t})]})}):i.jsxs("h2",{className:"group","aria-label":`${e}, ${t}`,"aria-describedby":a,children:[e,i.jsx("span",{className:"count",children:t})]}),n&&i.jsx("span",{className:"sr-only",id:a,children:n})]})}function xu({text:e,role:t}){return i.jsx("span",{className:`badge tone-${vl(t)}`,children:e})}function V9({serves:e}){const t=e.slice(0,D9),n=e.length-t.length;return i.jsxs("p",{className:"caption muted serves",children:[t.map((s,a)=>i.jsxs("span",{children:[a>0&&", ",i.jsxs("a",{href:`releases?planned=${encodeURIComponent(s.planned_release)}`,"aria-label":`serves ${s.name}, ${s.level}: open it in Planned releases`,children:["serves ",s.name," (",s.level,")"]})]},s.planned_release)),n>0&&i.jsxs(i.Fragment,{children:[i.jsxs("span",{"aria-hidden":"true",children:[", +",n," more"]}),i.jsxs("span",{className:"sr-only",children:[", and ",n," more planned releases"]})]})]})}const U9=4;function Rj({track:e}){return i.jsxs("span",{className:"track",children:[i.jsx("span",{className:"track-dots","aria-hidden":"true",children:Array.from({length:U9},(t,n)=>i.jsx("span",{className:["track-dot",n<=e.reached?"reached":"",n===e.target?"target":""].filter(Boolean).join(" ")},n))}),e.label,e.detail&&i.jsxs("span",{className:"sr-only",children:[". ",e.detail]})]})}function B9({tags:e,track:t,brief:n=!1}){const s=t?Math.min(Math.max(t.at??e.length,0),e.length):-1,a=n?e.filter(o=>!o.full):e,r=t?s-(n?e.slice(0,s).filter(o=>o.full).length:0):-1;return i.jsxs(i.Fragment,{children:[a.map((o,l)=>i.jsxs(u.Fragment,{children:[l===r&&t&&i.jsxs(i.Fragment,{children:[" ",i.jsx(Rj,{track:t})]})," · ",i.jsxs("span",{className:`tag tone-${vl(o.role)}`,children:[o.text,o.detail&&i.jsxs("span",{className:"sr-only",children:[". ",o.detail]})]})]},`t${l}`)),r===a.length&&t&&i.jsxs(i.Fragment,{children:[" ",i.jsx(Rj,{track:t})]})]})}function Tj({id:e,href:t}){return t?i.jsx("a",{className:"id-link",href:t,children:e}):i.jsx("span",{className:"id-text",children:e})}function W9(){return u.useMemo(()=>hA({fetcher:(...e)=>fetch(...e)}),[])}function F9(e){if(e.status==="failed")return"failed";if(e.status!=="ok")return null;const t=k9(e.summary,Date.now()/1e3);return t.length?t:null}function q9({lines:e}){return e==="failed"?i.jsx("p",{className:"unowned-issues muted",children:"Unowned issues: Not available"}):e?i.jsx("ul",{className:"unowned-issues",role:"list","aria-label":"Unowned issues",children:e.map(t=>i.jsx("li",{children:i.jsxs("a",{href:t.href,children:[t.label,i.jsx("span",{className:"sr-only",children:t.tail})]})},t.project))}):null}function Y9({onConnection:e,org:t=null,project:n=null}){const[s,a]=u.useState(null),[r,o]=u.useState(!1),l=W9(),c=F9(eA(l)),d=!!(s&&j9(s.line)),h=c==="failed"&&d?null:c,f=s&&Array.isArray(h)?N9(s.line):s==null?void 0:s.line,[m,p]=u.useState(""),[y,g]=u.useState(!1),[b,v]=u.useState(null),[x,w]=u.useState(""),[_,S]=u.useState(!1),[k,j]=u.useState(null),[N,O]=u.useState(null),[T,P]=u.useState(""),L=u.useRef(null),[G,A]=u.useState(0),D=u.useRef(new Map),C=u.useRef(new Map),R=u.useRef(null),[E,M]=u.useState(null),[H,z]=u.useState(null),[K,oe]=u.useState(null),[re,ve]=u.useState(""),[ke,ae]=u.useState(()=>new Set),[Ne,q]=u.useState(null),[B,Z]=u.useState(I9),Q=I=>Z(ue=>{const fe={...ue,...I};return G9(fe),fe}),[ie,ce]=u.useState({groups:[],all:!1}),[$,F]=u.useState(()=>new Set),[ee,se]=u.useState(()=>new Set),ge=u.useRef(B.archived),de=u.useRef(0),Le=u.useRef(null),Ee=u.useRef(""),W=u.useRef(""),_e=u.useRef(""),He=u.useRef(null),Dt=I=>{var ue;return[...((ue=He.current)==null?void 0:ue.querySelectorAll('[id^="thread-"]'))??[]].find(fe=>fe.id===`thread-${I}`)??null},en=u.useContext(Bb),zt=en?en.hash:null,tt=u.useRef(null),ft=u.useRef(null),It=u.useRef(null),zn=I=>{var fe;if(!(I instanceof HTMLButtonElement)||!((fe=He.current)!=null&&fe.contains(I))||!I.dataset.key)return null;const ue=E9.find(De=>I.classList.contains(De));return ue?`${ue} ${I.dataset.key}`:null},gn=I=>{It.current=zn(I.target)},Mn=()=>{setTimeout(()=>{zn(document.activeElement)||(It.current=null)},0)},xe=u.useCallback(async()=>{const I=++de.current,ue=await aA(ge.current);if(I!==de.current)return;const fe=L.current;if(fe&&I>fe.after&&A(Ve=>Ve+1),"none"in ue){o(!0),p(""),e("live");return}if("error"in ue){p(ue.error),e("disconnected");return}o(!1),p(""),w(""),P(""),e("live");const De=JSON.stringify(ue.data);De!==Ee.current&&(Ee.current=De,a(ue.data))},[e]);u.useEffect(()=>{let I=!0;const ue=C.current;BU().then(Ve=>I&&g(Ve)),qU().then(Ve=>I&&S(Ve));const fe=setTimeout(xe,0),De=setInterval(xe,S9);return()=>{I=!1,clearTimeout(fe),clearInterval(De);for(const Ve of ue.values())clearTimeout(Ve);ue.clear()}},[xe]),u.useEffect(()=>{let I=!0;const ue=()=>UU().then(De=>{I&&De&&M(Ve=>JSON.stringify(Ve)===JSON.stringify(De)?Ve:De)});ue();const fe=setInterval(ue,C9);return()=>{I=!1,clearInterval(fe)}},[]),u.useEffect(()=>{const I=fe=>{var Y,he;if(!fe.startsWith(Cp)){oe(null);return}if(fe===W.current)return;let De;try{De=decodeURIComponent(fe.slice(Cp.length))}catch{De=fe.slice(Cp.length)}const Ve=Dt(De);if(!Ve){if(!He.current||!s)return;const Qe=_e.current!==fe;if(_e.current=fe,s.threads.some(gt=>gt.key===De)){const gt=(re||ke.size)&&!Ej(s.threads,s.pinnedCount??0,re,ke).rows.some(At=>At.row.key===De),Vt=s.stages&&(Qe||!gt)?p9(s.threads,s.stages,{order:B.order,folded:new Set,showAll:!1,narrowed:!1},De):null,Et=Vt!==null&&B.folded.includes(Vt.group)&&!ie.groups.includes(Vt.group),Ut=Vt!==null&&Vt.capped&&!B.showAll&&!ie.all;Qe&&(re||ke.size)&&(ve(""),ae(new Set)),Qe&&(re||ke.size)||Et||Ut?(Et||Ut)&&ce(At=>({groups:Et&&Vt?[...At.groups,Vt.group]:At.groups,all:At.all||Ut})):W.current=fe,oe(null);return}oe(De);return}W.current=fe,oe(null),z(De);const tn=Ve.closest("[data-dock-pane]");(!tn||tn.hasAttribute("data-dock-active"))&&((Y=Ve.querySelector(".thread-title"))==null||Y.focus({preventScroll:!0})),(he=Ve.scrollIntoView)==null||he.call(Ve,{block:"center"})},ue=()=>{W.current="",_e.current="",I(window.location.hash)};if(zt!==null){tt.current!==null&&tt.current!==zt&&(W.current="",_e.current=""),tt.current=zt,I(zt);return}return I(window.location.hash),window.addEventListener("hashchange",ue),()=>window.removeEventListener("hashchange",ue)},[s,re,ke,B,ie,zt]),u.useEffect(()=>{if(!H)return;const I=()=>z(null);return document.addEventListener("pointerdown",I,!0),document.addEventListener("keydown",I,!0),()=>{document.removeEventListener("pointerdown",I,!0),document.removeEventListener("keydown",I,!0)}},[H]),u.useLayoutEffect(()=>{const I=It.current??(ft.current?`pin ${ft.current}`:null);if(!I||!He.current)return;const[ue,fe]=[I.slice(0,I.indexOf(" ")),I.slice(I.indexOf(" ")+1)],De=document.activeElement;if(De&&De!==document.body&&!He.current.contains(De)){It.current=null;return}const Ve=[...He.current.querySelectorAll(`button.${ue}`)].find(tn=>tn.dataset.key===fe);Ve?De!==Ve&&Ve.focus({preventScroll:fe!==ft.current}):It.current=null}),u.useLayoutEffect(()=>{var Y;const I=L.current;if(!I||!He.current)return;L.current=null;const ue=[...He.current.querySelectorAll("button.archive-thread")].find(he=>he.dataset.key===I.key);if(ue){ue.focus();return}const fe=I.order.indexOf(I.key),Ve=[...I.order.slice(fe+1),...I.order.slice(0,Math.max(fe,0)).reverse()].map(Dt).find(he=>he!==null),tn=Ve==null?void 0:Ve.querySelector(".thread-title");tn?tn.focus():(Y=R.current)==null||Y.focus()},[G]);const ne=async I=>{if(b)return;const ue=!I.pinned;ft.current=I.key,v(I.key);const fe=await ZU(I.key,ue);v(null),fe||a(De=>De&&{...De,threads:De.threads.map(Ve=>Ve.key===I.key?{...Ve,pinned:ue}:Ve)}),await xe(),w(fe?`The pin was not saved: ${fe}`:""),ft.current===I.key&&(ft.current=null)},[Se,Ye]=u.useState(()=>new Set),[nt,as]=u.useState({}),$n=is(),{confirm:rs,confirm_dialog:Zs}=al(),V=(I,ue)=>as(fe=>{const{[I]:De,...Ve}=fe;return ue?{...Ve,[I]:ue}:Ve}),$e=(I,ue)=>Ye(fe=>{const De=new Set(fe);return ue?De.add(I):De.delete(I),De}),Xe=Object.keys(nt).some(I=>!Se.has(I));u.useEffect(()=>{if(!Xe)return;const I=()=>as(ue=>Object.fromEntries(Object.entries(ue).filter(([fe])=>Se.has(fe))));return document.addEventListener("pointerdown",I,!0),document.addEventListener("click",I,!0),()=>{document.removeEventListener("pointerdown",I,!0),document.removeEventListener("click",I,!0)}},[Xe,Se]);const Mt=I=>setTimeout(()=>{var ue,fe;return(fe=[...((ue=He.current)==null?void 0:ue.querySelectorAll("button.open-thread"))??[]].find(De=>De.dataset.key===I))==null?void 0:fe.focus()},0),Ls=async(I,ue)=>{const fe=await rs({title:`Reopen ${I.title} in Terminal?`,description:`Its session is closed. It opens in a new Terminal window in ${ue??"the thread's folder"}, running claude --resume.`,action_label:"Reopen"});return Mt(I.key),fe},Ni=I=>{const ue=D.current.get(I);if(ue&&Date.now()-ue.at<A9)return ue.detail;const fe=XU(I).then(De=>((De===null||De.failed)&&D.current.delete(I),(De==null?void 0:De.detail)??null));return D.current.set(I,{at:Date.now(),detail:fe}),fe},ki=I=>setTimeout(()=>{var ue,fe;return(fe=[...((ue=He.current)==null?void 0:ue.querySelectorAll("button.archive-thread"))??[]].find(De=>De.dataset.key===I))==null?void 0:fe.focus()},0),Xa=async I=>{var Ve;if(k||N)return;const ue=I.archiveAction==="archive";if(ue){O(I.key);const tn=await Ni(I.key);O(null);const Y=await rs({title:`Archive ${I.title}?`,description:tn??T9,action_label:"Archive"});if(ki(I.key),!Y){D.current.delete(I.key);return}}const fe=[...((Ve=He.current)==null?void 0:Ve.querySelectorAll("article.thread"))??[]].map(tn=>tn.id.slice(7));j(I.key);const De=await KU(I.key,ue);D.current.delete(I.key),j(null),L.current={key:I.key,order:fe,after:de.current},await xe(),P(De?`The archive was not saved: ${De.replace(/\.*$/,".")}`:"")},Ir=async I=>{if(Se.has(I.key))return;let ue=!1;for(;;){$e(I.key,!0),V(I.key,{key:I.key,text:L9[I.where??""]??"Opening.",role:"waiting"});const fe=await rA(I.key,ue);if($e(I.key,!1),"done"in fe){V(I.key,null);return}const{reason:De,error:Ve,where:tn}=fe.refused;if(De==="closed"&&!ue){if(V(I.key,null),!await Ls(I,tn))return;ue=!0;continue}const Y=De==="outdated"?`${Ve.replace(/\.*$/,".")} ${$n}`:Ve.replace(/\.*$/,"."),he=De==="terminal_denied"?"you":H9.has(De)?"muted":"alert";V(I.key,{key:I.key,text:Y,role:he});return}},Oe=(s==null?void 0:s.threads)??[],ht=!r&&Oe.length>0,ln=Ej(Oe,(s==null?void 0:s.pinnedCount)??0,re,ke),cn=ln.pinned,Ln=ln.rows,os=Array.isArray(s==null?void 0:s.stages)?s.stages:null,Ka=new Set(B.folded.filter(I=>!ie.groups.includes(I))),Za=B.showAll||ie.all,Fn=os?gx(Ln.map(I=>I.row),os,{order:B.order,folded:Ka,showAll:Za,narrowed:ln.narrowed}):null,Qa=os?(s==null?void 0:s.archived)??0:0,um=I=>{ce(ue=>({...ue,groups:ue.groups.filter(fe=>fe!==I)})),Q({folded:Ka.has(I)?B.folded.filter(ue=>ue!==I):[...B.folded.filter(ue=>ue!==I),I]})},hm=()=>{ce(I=>({...I,all:!1})),Q({showAll:!Za})},bl=()=>{const I=!B.archived;ge.current=I,Q({archived:I}),xe()},yl=I=>F(ue=>{const fe=new Set(ue);return fe.has(I)?fe.delete(I):fe.add(I),fe}),fm=I=>se(ue=>{const fe=new Set(ue);return fe.has(I)?fe.delete(I):fe.add(I),fe}),Ja=(I,ue)=>i.jsx(X9,{depth:ue,row:E!=null&&E[I.key]?{...I,serves:E[I.key]}:I,arrived:H===I.key,pinnable:y&&typeof I.pinned=="boolean",pinning:b,onPin:()=>ne(I),archiveAction:_?I.archiveAction:void 0,archiving:k,previewing:N,onArchive:()=>Xa(I),onArchiveHover:fe=>{const De=C.current,Ve=De.get(I.key);if(!fe){clearTimeout(Ve),De.delete(I.key);return}I.archiveAction!=="archive"||Ve!==void 0||De.set(I.key,setTimeout(()=>{De.delete(I.key),Ni(I.key)},R9))},opening:Se.has(I.key),note:nt[I.key]??null,onOpen:()=>Ir(I),org:t,project:n,compact:!!os&&B.compact,detailsOpen:$.has(I.key),onDetails:()=>yl(I.key),holdsOpen:ee.has(I.key),onHolds:()=>fm(I.key)});u.useEffect(()=>{if(!ht)return;const I=ue=>{var De,Ve;if(ue.key!=="/"||ue.ctrlKey||ue.metaKey||ue.altKey||ue.defaultPrevented)return;const fe=document.activeElement;fe&&(/^(INPUT|TEXTAREA|SELECT)$/.test(fe.tagName)||fe.isContentEditable)||document.querySelector('[role="dialog"], [role="alertdialog"], dialog[open]')||(ue.preventDefault(),(De=Le.current)==null||De.focus(),(Ve=Le.current)==null||Ve.select())};return document.addEventListener("keydown",I),()=>document.removeEventListener("keydown",I)},[ht]);const mm=I=>ae(ue=>{const fe=new Set(ue);return fe.has(I)?fe.delete(I):fe.add(I),fe}),Gr=()=>{var I;ve(""),ae(new Set),(I=Le.current)==null||I.focus()},Hr=(I,ue)=>{const fe=ln.counts[I]??0,De=ke.has(I),Ve=Sj[I];return i.jsxs("button",{type:"button",className:"filter-chip","aria-pressed":De,"aria-describedby":Ve?`chip-hint-${I}`:void 0,disabled:fe===0&&!De&&Ne!==I,onFocus:()=>q(I),onBlur:()=>q(tn=>tn===I?null:tn),onClick:()=>mm(I),children:[ue," ",fe]},I)};return i.jsxs(i.Fragment,{children:[Zs,i.jsxs("header",{className:"main-head",children:[i.jsx("h1",{ref:R,tabIndex:-1,children:"Threads"}),s&&!r&&i.jsx("p",{className:"muted",children:f})]}),i.jsx(q9,{lines:h}),i.jsxs("section",{className:"card threads","aria-label":"Threads",children:[i.jsx(w9,{}),m&&i.jsxs("div",{className:"alert",role:"alert",children:["Threads unavailable: ",m.replace(/\.+$/,""),". Retrying every 10 s."]}),x&&i.jsx("div",{className:"alert",role:"alert",children:x}),T&&i.jsx("div",{className:"alert",role:"alert",children:T}),i.jsx("p",{className:"caption muted not-listed",role:"status",children:K!==null&&!r?os?i.jsxs(i.Fragment,{children:["Thread ",K," is not in this list.",!B.archived&&Qa>0?" Show archived lists archived threads.":null]}):i.jsxs(i.Fragment,{children:["Thread ",K," is not in this list. ",i.jsx("code",{children:"sdlc view --all"})," lists older threads."]}):null}),ht&&i.jsxs("div",{className:"threads-toolbar",children:[i.jsxs("div",{className:"threads-find",children:[i.jsxs("div",{className:"search-field",children:[i.jsx("input",{ref:Le,type:"search",placeholder:"Search threads","aria-label":"Search threads","aria-keyshortcuts":"/",value:re,onChange:I=>ve(I.target.value),onKeyDown:I=>{I.key==="Escape"&&(I.preventDefault(),re?ve(""):I.currentTarget.blur())}}),re&&i.jsx("button",{type:"button",className:"search-clear","aria-label":"Clear search",onClick:()=>{var I;ve(""),(I=Le.current)==null||I.focus()},children:i.jsx("span",{"aria-hidden":"true",children:"×"})})]}),os&&i.jsx("select",{className:"order-select","aria-label":"Order threads",value:B.order,onChange:I=>Q({order:I.target.value}),children:HA.map(([I,ue])=>i.jsx("option",{value:I,children:ue},I))})]}),i.jsxs("div",{className:"filter-row",children:[i.jsx("div",{className:"filter-group",role:"group","aria-label":"Status",children:xx.map(([I,ue])=>Hr(I,ue))}),i.jsx("div",{className:"filter-group",role:"group","aria-label":"Agent",children:vx.map(([I,ue])=>Hr(I,ue))}),os&&i.jsx("button",{type:"button",className:"filter-chip","aria-pressed":B.compact,onClick:()=>Q({compact:!B.compact}),children:"Compact"})]}),Object.entries(Sj).map(([I,ue])=>i.jsx("span",{className:"sr-only",id:`chip-hint-${I}`,children:ue},I)),i.jsx("p",{className:"caption muted narrowed",role:"status",children:ln.narrowed?i.jsxs(i.Fragment,{children:[Ln.length," of ",Oe.length," threads ·"," ",i.jsx("button",{type:"button",className:"clear-filters","aria-label":"Clear search and filters",onClick:Gr,children:"Clear"})]}):null})]}),r?i.jsx("p",{className:"muted",children:O9}):i.jsxs("div",{className:"thread-list",ref:He,onFocus:gn,onBlur:Mn,children:[Fn==null?void 0:Fn.groups.map(I=>i.jsxs("div",{children:[I.label!==null&&i.jsx(Dp,{label:I.label,count:I.count,hint:I.hint,fold:I.folds?{open:I.open,onToggle:()=>um(I.key)}:void 0}),I.rows.map(({row:ue,depth:fe})=>i.jsx("div",{children:Ja(ue,fe)},ue.key))]},`group-${I.key}`)),!Fn&&Ln.map(({row:I,depth:ue},fe)=>i.jsxs("div",{children:[cn>0&&fe===0&&i.jsx(Dp,{label:"Pinned",count:cn,hint:VA}),cn>0&&fe===cn&&i.jsx(Dp,{label:"Other threads",count:Ln.length-cn}),Ja(I,ue)]},I.key)),s&&!Oe.length&&i.jsx("p",{className:"muted empty",children:"No threads at work or waiting."}),Oe.length>0&&!Ln.length&&i.jsx("p",{className:"muted empty",children:"No threads match."}),s&&s.hidden>0&&i.jsxs("p",{className:"caption muted",children:[s.hidden," older thread(s) not shown; sdlc view --all lists them."]}),(Fn==null?void 0:Fn.more)&&i.jsx("button",{type:"button",className:"list-more","aria-expanded":Za,onClick:hm,children:Fn.more.unstaged?Za?"Show fewer without a stage":`Show all without a stage (${Fn.more.total})`:Za?"Show fewer":`Show all (${Fn.more.total})`}),Qa>0&&i.jsx("button",{type:"button",className:"list-more",onClick:bl,children:B.archived?"Hide archived":`Show ${Qa} archived`})]})]})]})}function X9({row:e,depth:t,arrived:n,pinnable:s,pinning:a,onPin:r,archiveAction:o,archiving:l=null,previewing:c=null,onArchive:d,onArchiveHover:h,opening:f,note:m,onOpen:p,org:y,project:g,compact:b=!1,detailsOpen:v=!1,onDetails:x,holdsOpen:w=!1,onHolds:_}){const S=b&&!v,k=A=>y?`org/${encodeURIComponent(y)}/tasks/${encodeURIComponent(A)}`:null,j=A=>g?`proj/${encodeURIComponent(g)}/issues/${encodeURIComponent(A)}`:null,N=[e.where||e.agent,e.phase,e.age,e.waitsOn?`waits on ${e.waitsOn}`:""].filter(Boolean).join(" · "),O=P9(e),T=l===e.key?o==="archive"?"Archiving":"Unarchiving":o==="archive"?"Archive":"Unarchive",P=`open-note-${e.key}`,[L,G]=u.useState(!1);return i.jsxs("article",{className:["thread",n?"arrived":"",b?"compact-card":""].filter(Boolean).join(" "),id:`thread-${e.key}`,style:{marginLeft:Math.min(t*22,110)},children:[b&&i.jsx("button",{type:"button",className:"details-toggle","data-key":e.key,"aria-label":`Details of ${e.title}`,"aria-expanded":v,onClick:x,children:i.jsx("span",{"aria-hidden":"true",children:v?"▾":"▸"})}),i.jsxs("div",{className:"thread-head",children:[i.jsx("p",{className:"thread-title",tabIndex:-1,children:e.title}),i.jsxs("div",{className:"tools",children:[e.carried?i.jsxs(i.Fragment,{children:[i.jsx(xu,{text:e.carried,role:"waiting"}),e.carriedBatch&&i.jsx(xu,{text:e.carriedBatch.text,role:e.carriedBatch.role})]}):i.jsx(xu,{text:e.status,role:e.role}),e.archived&&i.jsx(xu,{text:"archived",role:"muted"}),O&&i.jsx("button",{type:"button",className:"open-thread","data-key":e.key,"aria-label":`${O}: ${e.title}`,"aria-describedby":P,"aria-disabled":f?!0:void 0,"aria-busy":f?!0:void 0,onClick:()=>{f||p()},children:f?"Opening…":O}),s&&i.jsx("button",{type:"button",className:e.pinned?"pin on":"pin","data-key":e.key,"aria-label":e.pinned?`Unpin ${e.title}`:`Pin ${e.title} to the top`,"aria-disabled":a?!0:void 0,"aria-busy":a===e.key?!0:void 0,onClick:()=>{a||r()},children:e.pinned?"Unpin":"Pin"}),o&&i.jsx("button",{type:"button",className:"archive-thread","data-key":e.key,"aria-label":`${T} ${e.title}`,"aria-disabled":l||c?!0:void 0,"aria-busy":l===e.key||c===e.key?!0:void 0,onPointerEnter:()=>h==null?void 0:h(!0),onFocus:()=>h==null?void 0:h(!0),onPointerLeave:()=>h==null?void 0:h(!1),onBlur:()=>h==null?void 0:h(!1),onClick:()=>{!l&&!c&&(d==null||d())},children:l===e.key?`${T}…`:T})]})]}),i.jsxs("p",{className:S?"caption muted meta one-line":"caption muted meta",children:[N,i.jsx(B9,{tags:e.tags??[],track:e.track,brief:S})]}),O&&i.jsx("p",{id:P,className:`caption open-note tone-${vl((m==null?void 0:m.role)??"muted")}`,role:(m==null?void 0:m.role)==="alert"||(m==null?void 0:m.role)==="you"?"alert":"status",children:(m==null?void 0:m.text)??null}),!S&&e.serves&&e.serves.length>0&&i.jsx(V9,{serves:e.serves}),!S&&e.summary&&i.jsx("p",{className:"caption muted",children:e.summary}),!S&&e.carriedDetail&&i.jsx("p",{className:"line",children:e.carriedDetail}),!S&&e.step&&i.jsx(K9,{t:e}),e.lines.length>0&&i.jsx("p",{className:"caption muted lines-summary",children:$9(e.lines)}),S?null:i.jsx(Z9,{t:e,nested:t>0,allLines:L,setAllLines:G,allHolds:w,onHolds:_,taskHref:k,issueHref:j})]})}function K9({t:e}){return i.jsxs("p",{className:`caption tone-${vl(e.stepRole??"muted")}`,children:["step: ",e.step,e.stepEvidence&&i.jsxs(i.Fragment,{children:[" · ",i.jsx("span",{className:"id-text",children:e.stepEvidence})]}),e.stepRecent&&e.stepRecent.length>0&&i.jsxs("span",{className:"sr-only",children:[". Recent steps, newest first: ",e.stepRecent.join("; ")]})]})}function Oj({text:e,role:t,under:n,detail:s,nested:a}){const r=a&&n?n:void 0,o=[r?e:"",s??""].filter(Boolean).join(". ");return i.jsxs("p",{className:`line tone-${vl(t)}`,children:[r??e,o&&i.jsxs("span",{className:"sr-only",children:[". ",o]})]})}function Z9({t:e,nested:t,allLines:n,setAllLines:s,allHolds:a,onHolds:r,taskHref:o,issueHref:l}){return i.jsxs(i.Fragment,{children:[(n?e.lines:e.lines.slice(0,Nj)).map((c,d)=>i.jsxs("p",{className:`line tone-${vl(c.role)}`,children:[i.jsxs("span",{"aria-hidden":"true",children:[z9[c.state]??"•"," "]}),c.state==="working"&&i.jsx("span",{className:"sr-only",children:"Working: "}),c.task!==void 0&&i.jsx(Tj,{id:c.task,href:o(c.task)}),c.task!==void 0&&c.text?" ":null,c.text]},`l${d}`)),e.lines.length>Nj&&i.jsx("button",{type:"button",className:"lines-more","aria-expanded":n,"aria-label":n?`Show fewer lines of work of ${e.title}`:`Show all ${e.lines.length} lines of work of ${e.title}`,onClick:()=>s(c=>!c),children:n?"Show fewer":`Show all ${e.lines.length}`}),(e.routed??[]).map(c=>i.jsxs("p",{className:"line",children:["routed ",i.jsx(Tj,{id:c.issue,href:l(c.issue)}),c.title?` ${c.title}`:null]},`r${c.issue}`)),e.next&&i.jsxs("p",{className:"caption tone-amber",children:[i.jsx("span",{"aria-hidden":"true",children:"▸ "}),"next (",e.next.state,"): ",e.next.text,i.jsx("span",{className:"sr-only",children:". Say “nn” or approve it in the thread to start it."})]}),e.plannedFor&&i.jsxs("p",{className:"caption tone-grey",children:[i.jsx("span",{"aria-hidden":"true",children:"▸ "}),"planned for ",e.plannedFor.tag,": ",e.plannedFor.text]}),e.reason&&i.jsx(Oj,{...e.reason,nested:t}),(a||!e.holdsAll?e.holds:e.holds.slice(0,gu)).map((c,d)=>i.jsx(Oj,{...c,nested:t},`h${d}`)),e.holdsAll&&e.holds.length>gu&&i.jsx("button",{type:"button",className:"lines-more holds-toggle","data-key":e.key,"aria-expanded":a,"aria-label":a?`Show fewer holds of ${e.title}`:`+${e.holds.length-gu} more holds of ${e.title}`,onClick:r,children:a?"Show fewer holds":`+${e.holds.length-gu} more holds`}),(e.holdsMore??0)>0&&i.jsxs("p",{className:"caption tone-grey",children:["+",e.holdsMore," more holds"]}),e.plan&&i.jsx("p",{className:"caption muted",children:e.plan})]})}const Q9=5e3;function J9(){const[e,t]=u.useState([]),n=u.useRef(0),s=u.useRef(new Map),a=u.useCallback(c=>{const d=s.current.get(c);d&&clearTimeout(d),s.current.delete(c),t(h=>h.filter(f=>f.id!==c))},[]),r=u.useCallback((c,d)=>{const h=n.current+=1;t(f=>[...f.filter(m=>m.tone!=="error").slice(-2),{id:h,tone:c,message:d}]),c==="success"&&s.current.set(h,setTimeout(()=>a(h),Q9))},[a]);u.useEffect(()=>{const c=s.current;return()=>{for(const d of c.values())clearTimeout(d)}},[]);const o=u.useMemo(()=>({success:c=>r("success",c),error:c=>r("error",c)}),[r]),l=i.jsx("div",{role:"region","aria-live":"polite","aria-label":"Notifications",className:"pointer-events-none fixed right-4 bottom-4 z-100 flex max-w-[calc(100vw-2rem)] flex-col items-end gap-2",children:e.map(c=>i.jsxs("div",{"data-testid":"viewer-toast",className:"bg-popover text-popover-foreground pointer-events-auto flex w-80 max-w-full items-center gap-3 rounded-md border py-2 pr-2 pl-4 text-sm shadow-lg"+(c.tone==="error"?" border-destructive":""),children:[i.jsx("span",{className:"min-w-0 flex-1 break-words",children:c.message}),i.jsx(U,{type:"button",variant:"ghost",size:"control",className:"shrink-0",onClick:()=>a(c.id),children:"Dismiss"})]},c.id))});return{notify:o,toasts:l}}const eW=/^iss-\d{1,9}$/;function qb(e){return e.split("/").filter(Boolean).slice(1).join("/")}function dm(e,t=""){const n=e.split("/").filter(Boolean);if(n.length===0)return{page:{kind:"home"}};if(n.length===1){const[l]=n;return l==="threads"?{page:{kind:"org",page:"threads"},threads:!0}:l==="chat"?{forward:"threads"}:l==="tasks"?{page:{kind:"org",page:"tasks"},tasks:!0}:l==="issues"?{page:{kind:"home"},issues:!0}:l==="chart"?{page:{kind:"org",page:"chart"},chart:!0}:l==="worktrees"?{page:{kind:"org",page:"worktrees"},worktrees:!0}:l==="workspaces"?{page:{kind:"org",page:"workspaces"},workspaces:!0}:l==="queues"?{page:{kind:"org",page:"queues"},queues:!0}:l==="blockers"?{page:{kind:"org",page:"blockers"},blockers:!0}:l==="releases"?{page:{kind:"home"},releasesForward:!0}:{page:{kind:"not_found"}}}const[s,a,r,o]=n;if(s==="org"&&r==="tasks"&&o==="queues"&&n.length===4)return{forward:`org/${a}/queues${t}`};if(s==="org"&&r==="chat"&&n.length<=4)return{forward:`org/${a}/threads${o===void 0?"":`#thread-${o}`}`};if(s==="org"&&r==="tasks"&&n.length===4){const l=decodeURIComponent(o);return{page:{kind:"org",page:"tasks",item:l},org:decodeURIComponent(a),task:l}}if(s==="org"&&r==="issues"&&n.length<=4){const l=decodeURIComponent(a);return o===void 0?{page:{kind:"home"},org:l,issues:!0}:{page:{kind:"home"},org:l,issues:!0,issue:decodeURIComponent(o)}}if(s==="proj"&&r==="issues"&&n.length<=4){const l=decodeURIComponent(a),c={kind:"project",project:l,page:"issues"};if(o===void 0)return{page:c,issues:!0,project:l};const d=decodeURIComponent(o),h=new URLSearchParams(t);h.delete("from"),h.delete("reported");const f=h.toString();return{page:{...c,item:d,...f?{list_query:f}:{}},issues:!0,project:l,issue:d}}if(s==="org"&&n.length<=3){const l=decodeURIComponent(a);if(r===void 0)return{page:{kind:"home"},org:l};if(r==="threads")return{page:{kind:"org",page:"threads"},org:l,threads:!0};if(r==="tasks")return{page:{kind:"org",page:"tasks"},org:l,tasks:!0};if(r==="chart")return{page:{kind:"org",page:"chart"},org:l,chart:!0};if(r==="worktrees")return{page:{kind:"org",page:"worktrees"},org:l,worktrees:!0};if(r==="workspaces")return{page:{kind:"org",page:"workspaces"},org:l,workspaces:!0};if(r==="queues")return{page:{kind:"org",page:"queues"},org:l,queues:!0};if(r==="blockers")return{page:{kind:"org",page:"blockers"},org:l,blockers:!0};if(r==="releases")return{page:{kind:"home"},org:l,releasesForward:!0}}if(s==="proj"&&n.length<=3){const l=decodeURIComponent(a);if(r===void 0)return{page:{kind:"project",project:l}};if(r==="tasks")return{page:{kind:"project",project:l,page:"tasks"},tasks:!0};if(r==="releases")return{page:{kind:"project",project:l,page:"releases"},releases:!0}}return{page:{kind:"not_found"}}}const zj={label:"Local viewer",can:()=>!1},tW={connecting:"Connecting…",live:"Live · refreshes every 10s",disconnected:"Disconnected"},Mj=()=>i.jsx(iA,{title:"Page not found",more:"This release has no page for the graph's nodes. Read the graph in a terminal with sdlc workspace find <words> and sdlc workspace show <id>.",children:"There is no page at this address in this viewer."});function nW({routeOrg:e}){const{org:t,engine:n}=ss(),{project:s}=Ad(),[a,r]=u.useState("connecting");return n===null?i.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(ji,{page:"Threads"})}):i.jsxs("div",{className:"main viewer-panel",children:[i.jsxs("p",{className:"connection",role:"status",children:[i.jsx("span",{className:`dot ${a}`,"aria-hidden":"true"}),tW[a]]}),i.jsx(Y9,{onConnection:r,org:(t==null?void 0:t.slug)??e??null,project:s})]})}const Ya=()=>i.jsx("div",{className:"p-6 text-sm text-muted-foreground",children:"Loading…"});function sW({route:e,navigate:t}){var h;const{org:n,projects:s,loading:a,none:r}=ss(),o=e.page.kind==="project"?e.page.project:null,l=o!==null&&s!==null&&!((h=s.find(f=>f.id===o))!=null&&h.current),c=e.org===void 0&&!l&&!a&&n!==null?`org/${encodeURIComponent(n.slug)}/tasks`:null;if(u.useEffect(()=>{c&&t(c)},[c,t]),o!==null&&l)return i.jsx(Wc,{project:o});if(c||e.org===void 0&&a)return i.jsx(Ya,{});const d=(n==null?void 0:n.slug)??e.org;return d===void 0&&o!==null?i.jsx(Wc,{project:o}):d===void 0&&r?i.jsx(gl,{}):d===void 0?i.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:"Tasks open once the organization reads."}):i.jsx(w3,{org:d})}function iW({route:e,navigate:t}){const{org:n,loading:s,none:a}=ss(),r=xl(),o=e.org===void 0&&!s&&n!==null?`org/${encodeURIComponent(n.slug)}/queues${r.search}`:null;if(u.useEffect(()=>{o&&t(o)},[o,t]),o||e.org===void 0&&s)return i.jsx(Ya,{});const l=(n==null?void 0:n.slug)??e.org;if(l===void 0&&a)return i.jsx(gl,{});if(l===void 0)return i.jsx("p",{className:"p-6 text-sm text-muted-foreground",children:"Queues open once the organization reads."});const c=new URLSearchParams(r.search).get("queue");return i.jsx(RH,{org:l,open:c,path:`/org/${encodeURIComponent(l)}/queues`})}function aW({route:e,navigate:t}){var g;const{org:n,projects:s}=ss(),{project:a,settled:r}=Ad(),o=e.project??null,l=o!==null&&s!==null&&!((g=s.find(b=>b.id===o))!=null&&g.current),c=xl(),d=c.search,h=o===null&&a!==null?`proj/${encodeURIComponent(a)}/issues${e.issue?`/${encodeURIComponent(e.issue)}`:""}${d}`:null;u.useEffect(()=>{h&&t(h)},[h,t]);const[f,m]=u.useState(()=>c.search.replace(/^\?/,"")),p=u.useCallback(b=>{c.setSearch(b?`?${b}`:""),m(b)},[c]);if(o!==null&&l)return i.jsx(Wc,{project:o});if(h||o===null&&!r)return i.jsx(Ya,{});if(o===null)return i.jsx(gl,{});const y=encodeURIComponent((n==null?void 0:n.slug)??e.org??"");if(e.issue!==void 0){const b=new URLSearchParams(f).get("from");return i.jsx(uH,{org:y,project:o,issue_id:e.issue,from:b,query:f})}return i.jsx(KG,{org:y,project:o,query:f,onQuery:p})}function rW({issue:e,navigate:t,home:n}){const{project:s,settled:a}=Ad(),r=s!==null?`proj/${encodeURIComponent(s)}/issues/${encodeURIComponent(e)}`:null;return u.useEffect(()=>{r&&t(r)},[r,t]),r||!a?i.jsx(Ya,{}):n}function Ad(){var r;const{projects:e,loading:t,none:n,failure:s}=ss();return{project:((r=e==null?void 0:e.find(o=>o.current))==null?void 0:r.id)??null,settled:!t&&(e!==null||n!==null||!!(s!=null&&s.shown))}}function oW({navigate:e}){const{project:t,settled:n}=Ad(),{search:s}=xl(),a=t!==null?`proj/${encodeURIComponent(t)}/releases${s}`:null;return u.useEffect(()=>{a&&e(a)},[a,e]),a||!n?i.jsx(Ya,{}):i.jsx(gl,{})}function $j(e){const t=new URLSearchParams(e);return{release:t.get("release"),planned:t.has("planned")?t.get("planned")??"":null}}function lW({route:e}){var f;const{org:t,projects:n,loading:s}=ss(),a=e.page.kind==="project"?e.page.project:"",r=xl(),[o,l]=u.useState(()=>$j(r.search));if(s)return i.jsx(Ya,{});if(n!==null&&!((f=n.find(m=>m.id===a))!=null&&f.current))return i.jsx(Wc,{project:a});const d=`/proj/${encodeURIComponent(a)}/releases`,h=m=>{const p=new URLSearchParams;m!=null&&m.startsWith("planned:")?p.set("planned",m.slice(8)):m&&p.set("release",m);const y=p.size>0?`?${p.toString()}`:"";r.setSearch(y),l($j(y))};return i.jsx(EU,{org:(t==null?void 0:t.slug)??"",query:o,onSelect:h,home:d})}function cW({hash:e,navigate:t,home:n}){const{project:s,settled:a}=Ad(),r=Wb.exec(e),o=r!=null&&r[2]?Hh(r[2]):null,l=r!=null&&r[3]?Hh(r[3]):null,c=o!==null?`?release=${encodeURIComponent(o)}`:e.startsWith("#planned")?`?planned${l!==null?`=${encodeURIComponent(l)}`:""}`:"",d=s!==null?`proj/${encodeURIComponent(s)}/releases${c}`:null;return u.useEffect(()=>{d&&t(d)},[d,t]),d||!a?i.jsx(Ya,{}):n}function Ep({route:e,navigate:t}){const{org:n}=ss(),s=xl(),a=u.useContext($A);let r=e.page;const o=e.org!==void 0&&n!==null&&e.org!==n.slug;o&&(r={kind:"not_found"});let l;if(o)l=i.jsx(Mj,{});else if("threads"in e)l=i.jsx(nW,{routeOrg:e.org});else if("task"in e){const d=new URLSearchParams(s.search).get("from");l=i.jsx(eG,{org:encodeURIComponent(e.org),task_id:e.task,from:d})}else"tasks"in e?l=i.jsx(sW,{route:e,navigate:t}):"issues"in e?l=i.jsx(aW,{route:e,navigate:t}):"chart"in e?l=i.jsx($V,{}):"worktrees"in e?l=i.jsx(BB,{org:(n==null?void 0:n.slug)??e.org}):"workspaces"in e?l=i.jsx(jB,{org:(n==null?void 0:n.slug)??e.org}):"queues"in e?l=i.jsx(iW,{route:e,navigate:t}):"blockers"in e?l=i.jsx(cB,{org:(n==null?void 0:n.slug)??e.org}):"releasesForward"in e?l=i.jsx(oW,{navigate:t}):"releases"in e?l=i.jsx(lW,{route:e}):r.kind==="home"?l=i.jsx(gl,{}):r.kind==="project"?l=i.jsx(Wc,{project:r.project}):l=i.jsx(Mj,{});const c=JSON.stringify(r);return u.useEffect(()=>{a==null||a(JSON.parse(c))},[a,c]),a?i.jsx(i.Fragment,{children:l}):i.jsx(sA,{page:r,children:l})}function dW({task:e,navigate:t,home:n}){const{org:s,loading:a,none:r,failure:o}=ss(),l=s!==null?`org/${encodeURIComponent(s.slug)}/tasks/${encodeURIComponent(e)}`:null,c=!a&&(r!==null||!!(o!=null&&o.shown));return u.useEffect(()=>{l&&t(l)},[l,t]),l||!c?i.jsx(Ya,{}):n}const uW=e=>window.location.replace(e);function Hh(e){try{return decodeURIComponent(e)}catch{return null}}function Lj({navigate:e}){const t=xl(),n=dm(qb(t.pathname),t.search),s=LA.exec(t.hash),a=s?Hh(s[1]):null,r=PA.exec(t.hash),o=r?Hh(r[1]):null,l=o!==null&&eW.test(o)?o:null,c=Wb.test(t.hash)?t.hash:null,d=s!==null&&a===null||r!==null&&l===null,h="forward"in n?n.forward:null;if(u.useEffect(()=>{h&&e(h)},[h,e]),"forward"in n)return null;const f=i.jsx(Ep,{route:{page:{kind:"home"}},navigate:e});return d?i.jsx(Ep,{route:{page:{kind:"not_found"}},navigate:e}):a!==null?i.jsx(dW,{task:a,navigate:e,home:f}):l!==null?i.jsx(rW,{issue:l,navigate:e,home:f}):c!==null?i.jsx(cW,{hash:c,navigate:e,home:f}):i.jsx(Ep,{route:n,navigate:e})}function hW(e){const{path:t,search:n}=Oa(e),s=dm(t,n);return"forward"in s?{kind:"home"}:s.page}function fW(e){const{path:t,search:n}=Oa(e),s=dm(t,n);return"forward"in s||s.page.kind!=="not_found"}function mW({navigate:e=uW,data:t,dock:n=!1,dockStore:s}){const a=dm(qb(window.location.pathname),window.location.search),[r,o]=u.useState(null),{notify:l,toasts:c}=J9(),d=!n&&"forward"in a?a.forward:null;u.useEffect(()=>{d&&e(d)},[d,e]);const[h,f]=u.useState(!1);u.useEffect(()=>{if(t)return;let g=!0;return e5().then(b=>{g&&f(b)}),()=>{g=!1}},[t]);const m=u.useMemo(()=>{if(t)return null;const g=KB();return{seams:{probe:{source:async()=>({label:"Local workspace"})},shell:g,tasks:vj(n5()),org:t5(),worktrees:i5(),workspaces:r5(),queues:ZB(),blockers:a5(),releases:s5()},issues:g.issues}},[t]),p=u.useMemo(()=>{if(t||!m)return t;const{report:g,reportCollections:b,...v}=m.issues;return{...m.seams,issues:vj({...v,...h?{report:g,reportCollections:b}:{},commands:{}})}},[t,m,h]),y=(g,b)=>i.jsx(Wg,{data:p,router:{...Iu,navigate:v=>b(Iu.href(v))},identity:zj,notify:l,children:i.jsx(Lj,{navigate:g})});return d||!n&&"forward"in a||!p.shell?null:i.jsx("div",{className:"app-ui dark",ref:o,children:i.jsxs(G$,{container:r,children:[i.jsx(Wg,{data:p,router:Iu,identity:zj,notify:l,children:i.jsx(t3,{shell:p.shell,children:n?i.jsx(c9,{renderPane:y,pageOf:hW,known:fW,error:l.error,store:s}):i.jsx(Lj,{navigate:e})})}),c]})})}dI();V2.createRoot(document.getElementById("root")).render(i.jsx(u.StrictMode,{children:qb(window.location.pathname)==="app-ui-probe"?i.jsx(eB,{}):i.jsx(mW,{dock:!0})}));