@software-dlc/cli 0.199.7 → 0.199.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -425,7 +425,7 @@ ${s??""}
|
|
|
425
425
|
${(t==null?void 0:t.kind)??""}
|
|
426
426
|
${t&&"thread"in t?t.thread:""}`,[w,_]=u.useState(x),S=u.useRef(x);if(S.current=x,w!==x&&(_(x),m(!1),y(!1),b(null)),u.useEffect(()=>{if(!g)return;const I=()=>b(null);return document.addEventListener("pointerdown",I,!0),document.addEventListener("click",I,!0),()=>{document.removeEventListener("pointerdown",I,!0),document.removeEventListener("click",I,!0)}},[g]),!t)return{button:null,panel:null};const k=JI(t,n,s);if(t.kind==="open"||t.kind==="card"){const I=t.title,L=r?i.jsxs(i.Fragment,{children:[i.jsx(Cc,{className:"mr-2 size-4","aria-hidden":"true"}),"Open thread"]}):i.jsx(Cc,{className:"size-4","aria-hidden":"true"}),$=r?"default":"icon";if(t.kind==="card"||!a)return{button:i.jsx(Zw,{text:`Open thread: ${I}`,children:i.jsx("span",{className:"inline-flex",children:i.jsx(U,{asChild:!0,variant:"outline",size:$,children:i.jsx(l,{href:o(ib(e,t.thread)),"aria-label":`Open thread: ${I}`,children:L})})})}),panel:null};const A=async()=>{if(p)return;const E=x,R=()=>S.current===E;b(null),y(!0);const C=await a(t.thread,async M=>{y(!1);const H=await c({title:`Reopen ${I} in Terminal?`,description:`Its session is closed. It opens in a new Terminal window in ${M??"the thread's folder"}, running claude --resume.`,action_label:"Reopen"});return H&&R()&&y(!0),H});R()&&(y(!1),"note"in C&&b(C.note))},D=p?Xw:(g==null?void 0:g.role)==="muted"?CD(g,h):"";return{button:i.jsxs(i.Fragment,{children:[i.jsx(Zw,{text:`Open thread: ${I}`,children:i.jsx(U,{type:"button",variant:"outline",size:$,"aria-label":`Open thread: ${I}`,"aria-busy":p||void 0,"aria-disabled":p||void 0,onClick:()=>void A(),children:L})}),i.jsx("span",{role:"status",className:"sr-only",children:D}),d]}),panel:p?i.jsxs(pe,{variant:"info",role:"presentation",className:"mt-2",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{className:"text-current",children:Xw})]}):g?i.jsx(e3,{note:g,outdated_step:h}):null}}if(!k)return{button:null,panel:null};const j=t.kind==="continue"?"Continue":"Start a thread",N=t.kind==="continue"?`Continue ${t.title}`:t.kind==="start"?`Start a thread for ${t.issue}`:j,O=t.kind==="continue"?`Run in a terminal to continue ${t.title}:`:t.kind==="start"?`Run in a terminal to start a thread for ${t.issue}:`:"Run in a terminal in this checkout:",T=t.kind==="start"?za:sz;return{button:i.jsxs(U,{type:"button",variant:"outline",size:r?"default":"sm","aria-label":N,"aria-expanded":f,"aria-controls":f?v:void 0,onClick:()=>m(I=>!I),children:[i.jsx(T,{className:"mr-2 size-4","aria-hidden":"true"}),j]}),panel:f?i.jsx(t3,{id:v,lead:O,command:k}):null}}function Zw({text:e,children:t}){return i.jsx(sb,{children:i.jsxs(wd,{children:[i.jsx(_d,{asChild:!0,children:t}),i.jsx(ol,{children:e})]})})}function CD(e,t){return e.outdated?`${e.text} ${t}`:e.text}function e3({note:e,outdated_step:t}){const n=CD(e,t);return e.role==="muted"?i.jsxs(pe,{variant:"default",role:"presentation",className:"mt-2",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{children:n})]}):e.role==="you"?i.jsxs(pe,{variant:"warning",className:"mt-2",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{className:"text-current",children:n})]}):i.jsxs(pe,{variant:"destructive",className:"mt-2",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{className:"text-current",children:n})]})}function t3({id:e,lead:t,command:n}){return i.jsxs("div",{id:e,className:"mt-2 grid max-w-full gap-1 text-left",children:[i.jsx("span",{className:"text-muted-foreground text-sm",children:t}),i.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[i.jsx("pre",{className:"bg-muted min-w-0 flex-1 overflow-x-auto rounded-md border px-2 py-1 text-sm whitespace-pre",children:i.jsx("code",{className:"font-mono",children:n})}),i.jsx(Ug,{text:n,label:"Copy",aria_label:"Copy the command",what:"the command"})]})]})}function Ug({text:e,label:t,aria_label:n,what:s,variant:a="outline",size:r="sm"}){const[o,l]=u.useState("idle");u.useEffect(()=>{if(o!=="copied")return;const d=()=>l("idle");return document.addEventListener("pointerdown",d,!0),document.addEventListener("keydown",d,!0),()=>{document.removeEventListener("pointerdown",d,!0),document.removeEventListener("keydown",d,!0)}},[o]);const c=async()=>{try{await navigator.clipboard.writeText(e),l("copied")}catch{l("failed")}};return i.jsxs("span",{className:"inline-flex flex-wrap items-center gap-2",children:[i.jsxs(U,{type:"button",variant:a,size:r,"aria-label":o==="copied"?void 0:n,onClick:()=>void c(),children:[o==="copied"?i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}):i.jsx(gv,{className:"mr-2 size-4","aria-hidden":"true"}),o==="copied"?"Copied":t]}),i.jsxs("span",{role:"status","aria-live":"polite",className:"text-muted-foreground text-xs",children:[o==="failed"?`Copy failed: select ${s}`:null,o==="copied"?i.jsxs("span",{className:"sr-only",children:["Copied ",s]}):null]})]})}const Qw=["none","read","comment","write","manage","admin"];function Nh(e,t){return Qw.indexOf(e??"none")>=Qw.indexOf(t)}function ab(e){return e==="api_key"?"API key":e==="sdlc_login"?"sdlc login":null}function ap(e,t){const n=ab(e);return e==="sdlc_login"&&t?`${n} on ${DD(t)}`:n}const n3=String.fromCodePoint(8296),s3=String.fromCodePoint(8297);function DD(e){return`${n3}${e}${s3}`}const zc={blocked:{label:"Blocked",tone:"warning"},waiting_for_user:{label:"Waiting for a member",tone:"warning"},waiting_for_external:{label:"Waiting outside",tone:"warning"},paused:{label:"Paused",tone:"neutral"}},i3={backlog:"neutral",planned:"neutral",in_progress:"info",completed:"success",canceled:"neutral"};function ED(e){return e.name==="Blocked"?"warning":i3[e.category]}const Jw=1800;function Fs(e){return new Date(e).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}function As(e){return new Date(e).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1})}function rb(e){return`${Rs(e)}, ${As(e)}`}function El(e){return e<90?`${Math.round(e)} s`:e<5400?`${Math.round(e/60)} min`:`${(e/3600).toFixed(1).replace(/\.0$/,"")} h`}function Rs(e){return new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric"})}function AD(e){return new Date(e).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})}function a3(e){if(e.open_holds===0)return null;if(e.released_holds===e.open_holds)return{label:`${e.released_holds} ready to resolve`,tone:"neutral"};const t=e.open_holds-e.released_holds;return{label:e.released_holds>0?`${t} open · ${e.released_holds} ready`:`${t} open`,tone:"warning"}}function r3(e){return{"task.created":"Created the task","task.title_changed":"Changed the title","task.description_changed":"Changed the description","task.status_changed":"Changed the status","task.priority_changed":"Changed the priority","task.primary_changed":"Changed the primary","task.custom_fields_changed":"Changed a field","task.archived":"Archived the task","task.restored":"Restored the task","task.reordered":"Moved the task","task.reparented":"Moved the task under another","task.contributor_added":"Added a contributor","task.contributor_removed":"Removed a contributor","task.checklist_item_added":"Added a checklist item","task.checklist_item_edited":"Edited a checklist item","task.checklist_item_toggled":"Checked off a checklist item","task.checklist_item_moved":"Moved a checklist item","task.checklist_item_archived":"Removed a checklist item","task.hold_opened":"Opened a hold","task.hold_released":"Released a hold","task.hold_resolved":"Resolved a hold","task.claimed":"Claimed the task","task.claim_released":"Released a claim","task.claim_completed":"Finished a claim","task.claim_expired":"Ended a lapsed claim","task.relation_added":"Linked a task","task.relation_archived":"Unlinked a task","task.project_linked":"Linked a project","task.project_unlinked":"Unlinked a project"}[e.event_type]??"Changed the task"}const Ji="not_set";function o3({open:e,commands:t,list_id:n,list_revision:s,default_status_id:a,statuses:r,priorities:o,members:l,on_close:c,on_created:d}){var L;const h=Ga(),[f,m]=u.useState(""),[p,y]=u.useState(""),[g,b]=u.useState(a??((L=r[0])==null?void 0:L.id)??""),[v,x]=u.useState(Ji),[w,_]=u.useState(Ji),[S,k]=u.useState(!1),[j,N]=u.useState(null),[O,T]=u.useState(!1);u.useEffect(()=>{var $;e&&(m(""),y(""),b(a??(($=r[0])==null?void 0:$.id)??""),x(Ji),_(Ji),k(!1),N(null))},[e,a,r]);const I=async $=>{if($.preventDefault(),!f.trim()){k(!0);return}T(!0),N(null);try{const A=await t.run("create_task",{list_id:n,expected_list_revision:s,title:f.trim(),description:p.trim()||null,status_id:g||null,priority_id:v===Ji?null:v,primary_user_id:w===Ji?null:w});if(!A.ok){N(A.refusal.message);return}h.success("Task created."),await d()}finally{T(!1)}};return i.jsx(yn,{open:e,onOpenChange:$=>$?null:c(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:$=>void I($),noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"New task"}),i.jsx(kn,{children:"Add a task to this List."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[j&&i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{children:j})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"new-task-title",children:"Title"}),i.jsx(bt,{id:"new-task-title",placeholder:"What needs doing",value:f,required:!0,"aria-invalid":S,"aria-describedby":S?"new-task-title-error":void 0,onChange:$=>{m($.target.value),k(!1)}}),S&&i.jsx("p",{id:"new-task-title-error",className:"text-destructive text-xs",children:"Give the task a title."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"new-task-description",children:"Description (optional)"}),i.jsx(Gn,{id:"new-task-description",rows:4,value:p,onChange:$=>y($.target.value)})]}),i.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"new-task-status",children:"Status"}),i.jsxs(St,{value:g,onValueChange:b,children:[i.jsx(wt,{id:"new-task-status",children:i.jsx(Ct,{})}),i.jsx(_t,{children:r.map($=>i.jsx(Ue,{value:$.id,children:$.name},$.id))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"new-task-priority",children:"Priority"}),i.jsxs(St,{value:v,onValueChange:x,children:[i.jsx(wt,{id:"new-task-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Ji,children:"Not set"}),o.map($=>i.jsx(Ue,{value:$.id,children:$.name},$.id))]})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"new-task-primary",children:"Primary"}),i.jsxs(St,{value:w,onValueChange:_,children:[i.jsx(wt,{id:"new-task-primary",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Ji,children:"Not set"}),l.map($=>i.jsx(Ue,{value:$.user_id,children:$.label},$.user_id))]})]})]})]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",onClick:c,children:"Cancel"}),i.jsx(U,{type:"submit",disabled:O,children:O?"Creating…":"Create task"})]})]})})})}const l3="Your organization's work, in queue order. Claim a task to show you are working on it.",Vl="any",RD="none",c3=1,d3=250;function ob(){const e=Vn().tasks;if(!e)throw new Error("The Tasks page rendered without the tasks seam.");return e}function u3({org:e}){var y,g;const t=ob(),{href:n,Link:s}=lt(),[a,r]=u.useState({state:"loading"}),[o,l]=u.useState([]),[c,d]=u.useState(null),h=u.useRef(0),f=u.useCallback(async b=>{const v=h.current+=1;b&&r({state:"loading"});const x=await t.availability({fresh:b});v===h.current&&r(x)},[t.availability]);u.useEffect(()=>{f(!1)},[f]);const m=u.useCallback(()=>void f(!0),[f]);if(u.useEffect(()=>{let b=!0;return t.members().then(v=>{b&&v.ok&&l(v.data)}),()=>{b=!1}},[t.members]),u.useEffect(()=>{if(!t.access)return;let b=!0;return t.access().then(v=>{b&&v.ok&&d(v.data)}),()=>{b=!1}},[t.access]),a.state==="off"&&((y=a.refusal)==null?void 0:y.reason)!=="engine_missing")return i.jsx(Ha,{title:"Page not found",description:"This page does not exist, or you do not have access to it.",backHref:n(`/org/${e}`),backLabel:"Back to the organization",link:s});const p=(c==null?void 0:c.read_only_reason)??l3;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:a.state==="active"?i.jsx(f3,{active:a,org:e,members:o,description:p,read_only_reason:c==null?void 0:c.read_only_reason,reload_configuration:m}):a.state==="off"&&((g=a.refusal)==null?void 0:g.reason)==="engine_missing"?i.jsx(yi,{page:"Tasks"}):i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:"Tasks",description:p}),a.state==="loading"&&i.jsx(TD,{}),(a.state==="error"||a.state==="off")&&i.jsx(OD,{refusal:a.refusal,on_retry:m}),a.state==="available"&&i.jsx(h3,{on_done:m})]})})}function TD(){return i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading tasks",children:Array.from({length:6},(e,t)=>i.jsx(Tt,{className:t===5?"h-10 w-2/3":"h-10 w-full"},t))})}function OD({refusal:e,on_retry:t}){const n=ns();return(e==null?void 0:e.reason)==="view_outdated"?i.jsxs(pe,{variant:"warning",className:"mt-6",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:n})]}):i.jsxs(pe,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Tasks could not be loaded"}),i.jsxs(ge,{children:[i.jsx("p",{children:e!=null&&e.reason?e.message:"Check your connection and try again."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]})}function h3({on_done:e}){const{commands:t}=ob(),n=Ga(),[s,a]=u.useState(!1),r=t==null?void 0:t.activate,o=async()=>{if(!r)return;a(!0);const l=await r();if(a(!1),!l.ok){n.error(l.refusal.message);return}n.success("Tasks are on."),e()};return i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Tasks are not on for this organization"}),i.jsxs(ge,{children:[i.jsx("p",{children:"Turning them on creates one List with the default workflow. Members then see tasks as their access allows. It needs two-factor sign-in."}),r?i.jsx(U,{type:"button",size:"sm",className:"mt-2",disabled:s,onClick:()=>void o(),children:"Turn on Tasks"}):null]})]})}const rp=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function f3({active:e,org:t,members:n,description:s,read_only_reason:a,reload_configuration:r}){var De;const{commands:o,listTasks:l,waitingOnYou:c,hierarchyRevision:d}=ob(),{href:h,Link:f}=lt(),{self_id:m}=af(),p=Ga(),{list:y,workspace:g}=e,b=y.offers,v=b!==void 0,x=u.useMemo(()=>{var V;return((V=g.workflows.find(ue=>ue.id===y.workflow_id))==null?void 0:V.statuses)??[]},[g,y]),w=g.priorities,_=!!o&&Nh(y.permission,"write"),S=_&&Nh(y.permission,"manage"),k=u.useMemo(()=>new Map(n.map(V=>[V.user_id,V])),[n]),j=V=>{var ue;return V?V===m?"You":((ue=k.get(V))==null?void 0:ue.label)??"A member":""},[N,O]=u.useState("active"),[T,I]=u.useState(!1),[L,$]=u.useState(""),[A,D]=u.useState("");u.useEffect(()=>{const V=setTimeout(()=>D(L),d3);return()=>clearTimeout(V)},[L]);const[E,R]=u.useState(null),[C,M]=u.useState(Vl),[H,z]=u.useState(!1),[K,oe]=u.useState(!1),[re,Ne]=u.useState({}),[Se,ae]=u.useState([]),[F,ie]=u.useState(null),[W,se]=u.useState([]),[Z,de]=u.useState(null),[J,G]=u.useState(0),[Y,te]=u.useState(!1),[ce,be]=u.useState(null),[fe,$e]=u.useState(null),ze=ns(),[q,ve]=u.useState(!1),[Ve,Ft]=u.useState(null),[Qt,ht]=u.useState({}),[it,Lt]=u.useState(""),{confirm:Dt,confirm_dialog:On}=tl(),mn=u.useRef(null),Sn=u.useRef(null),xe=u.useRef(null),ne=u.useRef(null),[ye,qe]=u.useState(void 0),xt=!!(A.trim()||E||C!==Vl||H||K),ss=u.useRef(0),zn=u.useRef(0),B=u.useCallback(async(V,ue=!1)=>{if(ue&&zn.current>0)return;const Be=V?ss.current:ss.current+=1,at={state:N,assigned_to_me:T||void 0,cursor:V,search:A.trim()||void 0,group:E??void 0,owner:C===Vl?void 0:C===RD?"":C,urgent:H||void 0,over_estimate:K||void 0,...m3(re,Se)},rn=on=>l(y.id,{...at,cursor:on});V||(zn.current+=1);let At=await rn(V).finally(()=>{V||(zn.current-=1)}),Nt=!!V;if(!At.ok&&At.refusal.code==="cursor_stale"&&(At=await rn(),Nt=!1),Be!==ss.current)return;if(!At.ok){de(At.refusal),G(on=>on+1);return}const Pt=At.data;de(null),G(0),!(ue&&rp(Pt,xe.current))&&(xe.current=Pt,ie(Pt),Pt.facets&&qe(Pt.facets),se(on=>Nt?[...on,...Pt.tasks]:Pt.tasks))},[l,y.id,N,T,A,E,C,H,K,re,Se]),Le=u.useCallback(async()=>{const V=await c();if($e(Be=>V.ok?null:rp(Be,V.refusal)?Be:V.refusal),!V.ok&&v)return;const ue=V.ok?V.data:null;rp(ue,ne.current)||(ne.current=ue,be(ue))},[c,v]);u.useEffect(()=>{xe.current=null,ie(null)},[N,T]),u.useEffect(()=>{B()},[B]),u.useEffect(()=>{Le()},[Le]);const Fe=u.useCallback(async()=>{await Promise.all([B(),Le()])},[B,Le]),Et=u.useRef(Fe);Et.current=Fe;const gs=b==null?void 0:b.refresh_ms;u.useEffect(()=>{if(!gs)return;const V=setInterval(()=>{B(void 0,!0),Le()},gs);return()=>clearInterval(V)},[gs,B,Le]);const Yi=u.useCallback(async(V,ue,Be)=>{if(!o)return;const at=await o.run(V,ue);at.ok?Be&&p.success(Be):(p.error(at.refusal.message),at.refusal.code==="revision_conflict"&&r()),await Fe()},[o,p,Fe,r]),wi=x.find(V=>V.category==="completed"),Xi=async(V,ue,Be)=>{const at=ue+Be,rn=W[at];if(!rn||!F||!o)return;const At=async(Nt,Pt)=>{const on=await o.run(Nt,Pt);if(!on.ok)throw on.refusal;return on.data};try{let Nt=F.list.order_revision,Pt=V.revision;if(rn.queue_rank===null){const on=W.findIndex(Wn=>Wn.queue_rank===null);for(const Wn of W.slice(on,at+1)){const bl=await At("reorder",{task_id:Wn.id,expected_revision:Wn.revision,expected_order_revision:Nt,placement:"end"});Nt=bl.list.order_revision,Wn.id===V.id&&(Pt=bl.task.revision)}}await At("reorder",{task_id:V.id,expected_revision:Pt,expected_order_revision:Nt,placement:Be<0?"before":"after",anchor_task_id:rn.id})}catch(Nt){p.error(Nt.message)}await Fe()},zr=V=>{wi&&Yi("update_task",{task_id:V.id,expected_revision:V.revision,changes:{status_id:wi.id}},`${V.title} completed.`)},Mr=async V=>{if(!F||!await Dt({title:"Archive this task?",description:"It leaves the queue and becomes read-only. Its claim, holds and history stay, and a manager can restore it.",action_label:"Archive task",destructive:!0}))return;const[Be,at]=await Promise.all([l(y.id,{limit:1}),d(g.id)]);if(!Be.ok||!at.ok){p.error(Be.ok?at.ok?"":at.refusal.message:Be.refusal.message);return}await Yi("archive_task",{task_id:V.id,expected_revision:V.revision,expected_order_revision:Be.data.list.order_revision,expected_hierarchy_revision:at.data},`${V.title} archived.`)},$r=async V=>{await Yi("release_hold",{hold_id:V},"Hold released.")},Te=async(V,ue,Be,at)=>{if(!(o!=null&&o.complete)||!await Dt({title:`Mark ${ue} done?`,description:Be.reason?`“${Be.reason}”
|
|
427
427
|
|
|
428
|
-
It leaves the open tasks.`:"It leaves the open tasks.",action_label:"Mark done"}))return;Ft(V);const At=await o.complete(Be);if(Ft(null),!At.ok){ht(Nt=>({...Nt,[V]:At.refusal.message}));return}ht(({[V]:Nt,...Pt})=>Pt),Lt(`${ue} marked done.`),await Et.current(),an({next:at})},[et,an]=u.useState(null);u.useEffect(()=>{var at;if(!et)return;an(null);const V=Sn.current,ue=typeof et.next=="function"?et.next():et.next;(at=(ue?(V==null?void 0:V.querySelector(`[data-done-key="${CSS.escape(ue)}"]`))??(V==null?void 0:V.querySelector(`[data-title-key="${CSS.escape(ue)}"] a`)):null)??mn.current)==null||at.focus()},[et]);const Mn=()=>{var V;$(""),D(""),R(null),M(Vl),z(!1),oe(!1),(V=mn.current)==null||V.focus()},Bn=new Map(x.map(V=>[V.id,V])),xs=new Map(w.map(V=>[V.id,V])),_i=new Map(W.map(V=>[V.id,V.title])),ji=_&&N==="active",vs=W.some(V=>V.local_done),pl=W.some(V=>V.local_action),gl=ji||vs||pl,xl=!v||w.length>0,lm=!T&&!xt,Lr=5+(xl?1:0)+(gl?1:0),cm=Z!==null&&(Z.reason==="store_locked"||Z.reason==="engine_failed")&&J<=c3,Fa=(ce==null?void 0:ce.holds)??[],vl=F==null?void 0:F.groups,dm=p3(W,vl,re,(F==null?void 0:F.matched)===void 0?Se:[]),qa=vl?vl.length===0:W.length===0,P=(V,ue)=>Ne(Be=>({...Be,[V]:!ue})),he=V=>ae(ue=>ue.includes(V)?ue.filter(Be=>Be!==V):[...ue,V]),me=Fa.map(V=>V.id);return i.jsxs("div",{ref:Sn,className:"contents",children:[i.jsx(bn,{title:"Tasks",description:s,actions:_?i.jsxs(U,{type:"button",onClick:()=>ve(!0),children:[i.jsx(za,{className:"mr-2 size-4","aria-hidden":"true"}),"New task"]}):null}),v&&(F!=null&&F.open)?i.jsxs("p",{className:"text-muted-foreground mt-1 text-sm",children:[F.open," open"]}):null,gs?i.jsx("p",{className:"text-muted-foreground mt-1 text-xs",role:"status",children:Z?`Not reading · trying again every ${Math.round(gs/1e3)}s`:F?`Live · refreshes every ${Math.round(gs/1e3)}s`:"Connecting…"}):null,v?i.jsx("p",{className:"sr-only",role:"status",children:it}):null,(v||Fa.length>0)&&i.jsxs(yt,{as:"section","aria-labelledby":"waiting-title",className:"mt-4 p-4","data-testid":"tasks-waiting",children:[i.jsx("h2",{id:"waiting-title",className:"text-lg font-semibold",children:"Waiting on you"}),Fa.length>0?i.jsx("ul",{className:"mt-2 divide-y","aria-labelledby":"waiting-title",children:Fa.map((V,ue)=>{var At,Nt;const Be=zc[V.hold_type],at=V.target.kind==="task"?`Because you claim ${_i.get(V.target.task_id)??"the task it waits on"} · `:"",rn=V.local_done;return i.jsxs("li",{id:`waiting-${V.id}`,"data-title-key":V.id,className:"flex flex-wrap items-center gap-3 py-2",children:[V.task?i.jsx(f,{className:"text-primary min-w-40 flex-1 hover:underline",href:h(`/org/${t}/tasks/${V.task.id}`),children:V.task.title}):i.jsx("span",{className:"min-w-40 flex-1",children:V.reason}),i.jsx(we,{variant:Be.tone,children:V.local_label??Be.label}),i.jsxs("div",{className:"min-w-48 flex-2",children:[V.task?i.jsx("div",{className:"text-sm",children:V.reason}):null,i.jsxs("div",{className:"text-muted-foreground text-xs",children:[at,"From ",j(V.opened_by)," · ",Rs(V.opened_at)]}),(At=V.local_threads)!=null&&At.length?i.jsxs("div",{className:"text-muted-foreground text-xs",children:["Answer it in"," ",i.jsx(f,{className:"text-primary hover:underline",href:h(`/org/${t}/threads`),children:"Threads"}),": ",V.local_threads.join(" · ")]}):null,Qt[V.id]?i.jsx("div",{className:"text-destructive text-xs",role:"alert",children:Qt[V.id]}):null]}),rn&&(o!=null&&o.complete)?i.jsx(U,{type:"button",variant:"outline",size:"sm","data-done-key":V.id,"aria-label":`Mark ${((Nt=V.task)==null?void 0:Nt.title)??V.reason} done`,loading:Ve===V.id,onClick:()=>{var Pt;return void Te(V.id,((Pt=V.task)==null?void 0:Pt.title)??V.reason,rn,me[ue+1]??null)},children:"Done"}):null,v?null:i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void $r(V.id),children:"Release"})]},V.id)})}):ce?i.jsx("p",{className:"text-muted-foreground mt-2 text-sm",children:"Nothing in this checkout waits on you."}):null,v&&fe?i.jsx("p",{className:"text-muted-foreground mt-2 text-sm",role:"status",children:fe.reason==="view_outdated"?`Waiting on you is not read here. ${ze}`:"Waiting on you could not be read. It is read again with the list."}):null,i.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:v?"This checkout only. Teammates' agents are not listed here.":"Release a hold when you have done your part. Whoever can edit the task then resolves it."})]}),!_&&!a&&i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can view these tasks"}),i.jsx(ge,{children:"Ask an organization admin for write access to change them."})]}),i.jsxs("div",{className:"mt-6 flex flex-wrap items-center gap-4",children:[(b==null?void 0:b.archived)!==!1?i.jsx(EI,{value:N,onValueChange:V=>O(V),children:i.jsxs(xD,{"aria-label":"Which tasks",children:[i.jsx(Gg,{value:"active",children:"Active"}),i.jsx(Gg,{value:"archived",children:"Archived"})]})}):null,(b==null?void 0:b.assigned_to_me)!==!1?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nl,{id:"tasks-mine",checked:T,onCheckedChange:V=>I(V===!0)}),i.jsx(Ie,{htmlFor:"tasks-mine",children:"Assigned to me"})]}):null,b!=null&&b.search?i.jsx(bt,{ref:mn,type:"search",className:"w-64","aria-label":"Search tasks",placeholder:"Search title, ID or detail",value:L,onChange:V=>$(V.target.value)}):null,ye!=null&&ye.owners?i.jsx(_3,{owners:ye.owners,no_owner:ye.no_owner,value:C,on_change:M}):null]}),(De=ye==null?void 0:ye.groups)!=null&&De.length?i.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",role:"group","aria-label":"Status",children:[ye.groups.map(V=>i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":E===V.id,onClick:()=>R(ue=>ue===V.id?null:V.id),children:[V.label," ",V.count]},V.id)),ye.marks?i.jsxs(i.Fragment,{children:[i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":H,onClick:()=>z(V=>!V),children:["Urgent ",ye.marks.urgent]}),i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":K,onClick:()=>oe(V=>!V),children:["Over estimate ",ye.marks.over_estimate]})]}):null]}):null,xt&&(F==null?void 0:F.matched)!==void 0&&F.total!==void 0?i.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:[F.matched," of ",F.total," match ·"," ",i.jsx(U,{type:"button",variant:"link",size:"inline-sm",onClick:Mn,children:"Clear"})]}):null,cm?i.jsx("p",{className:"text-muted-foreground mt-4 text-sm",children:"Tasks are busy. Reading them again…"}):Z?i.jsx(OD,{refusal:Z,on_retry:()=>void B()}):null,!F&&!Z&&i.jsx(TD,{}),F&&qa&&xt?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(uf,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No tasks match"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing open matches these filters."}),i.jsx(U,{type:"button",variant:"outline",onClick:Mn,children:"Clear filters"})]}):F&&qa&&N==="active"&&!T&&v?i.jsx("p",{className:"text-muted-foreground mt-6 text-sm",children:"No tasks recorded yet."}):F&&qa&&N==="active"&&!T?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(lf,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No tasks yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Create the first task, or ask an agent to create one with the SDLC MCP tools."}),_&&i.jsxs(U,{type:"button",onClick:()=>ve(!0),children:[i.jsx(za,{className:"mr-2 size-4","aria-hidden":"true"}),"New task"]})]}):F?i.jsxs(i.Fragment,{children:[i.jsx(yt,{className:"mt-4 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Tasks",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Title"}),i.jsx(Q,{children:"Status"}),xl?i.jsx(Q,{className:"hidden md:table-cell",children:"Priority"}):null,i.jsx(Q,{className:"hidden md:table-cell",children:"Primary"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Holds"}),i.jsx(Q,{children:"Claimed by"}),gl?i.jsx(Q,{className:"text-right",children:"Actions"}):null]})}),i.jsxs(st,{children:[dm.map(V=>{if(V.kind==="group")return i.jsx(x3,{group:V.group,open:V.open,columns:Lr,on_toggle:()=>P(V.group.id,V.open)},`group:${V.group.id}`);if(V.kind==="more")return i.jsx(v3,{group:V.group,whole:Se.includes(V.group.id),columns:Lr,on_toggle:()=>he(V.group.id)},`more:${V.group.id}`);const{row:ue,index:Be}=V,at=Bn.get(ue.status_id),rn=a3(ue),At=ue.local_done;return i.jsx(y3,{columns:Lr,thread:{org:t,action:ue.local_action,task_id:ue.no_page?null:ue.id,open_thread:o==null?void 0:o.open_thread},children:(Nt,Pt)=>{var on,Wn;return i.jsxs(_e,{"data-testid":"tasks-row",className:Pt?"border-b-0":void 0,children:[i.jsxs(X,{"data-title-key":ue.id,children:[ue.no_page&&ue.local_thread?i.jsxs(f,{className:"text-primary inline-flex items-center gap-1 hover:underline",href:h(ib(t,ue.local_thread.key)),"aria-label":`${ue.title}: open ${ue.local_thread.title} in Threads`,children:[ue.title,i.jsx(Cc,{className:"size-3.5 shrink-0","aria-hidden":"true"})]}):ue.no_page?i.jsx("span",{children:ue.title}):i.jsx(f,{className:"text-primary hover:underline",href:h(`/org/${t}/tasks/${ue.id}`),children:ue.title}),ue.parent_task_id&&_i.get(ue.parent_task_id)?i.jsx("div",{className:"text-muted-foreground text-xs",children:_i.get(ue.parent_task_id)}):null,v?i.jsx(w3,{row:ue}):null,Qt[ue.id]?i.jsx("div",{className:"text-destructive text-xs",role:"alert",children:Qt[ue.id]}):null]}),i.jsx(X,{children:at?i.jsx(we,{variant:ED(at),children:at.name}):null}),xl?i.jsx(X,{className:"hidden md:table-cell",children:ue.priority_id?((on=xs.get(ue.priority_id))==null?void 0:on.name)??"":i.jsx("span",{className:"text-muted-foreground",children:"Not set"})}):null,i.jsx(X,{className:"hidden md:table-cell",children:ue.owner_title?ue.owner_title:ue.primary_user_id?j(ue.primary_user_id):i.jsx("span",{className:"text-muted-foreground",children:"Unassigned"})}),i.jsx(X,{className:"hidden md:table-cell",children:rn?i.jsx(we,{variant:rn.tone,children:rn.label}):i.jsx("span",{className:"text-muted-foreground",children:"None"})}),i.jsx(X,{"data-testid":"tasks-claim",children:i.jsx(j3,{row:ue,holder:j((Wn=ue.claim)==null?void 0:Wn.user_id)})}),gl?i.jsx(X,{className:"text-right whitespace-nowrap",children:i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[At&&"hold"in At?i.jsx("a",{className:"text-primary text-sm hover:underline",href:`#waiting-${At.hold}`,children:"In Waiting on you"}):At&&(o!=null&&o.complete)?i.jsx(U,{type:"button",variant:"outline",size:"sm","data-done-key":ue.id,"aria-label":`Mark ${ue.title} done`,loading:Ve===ue.id,onClick:()=>void Te(ue.id,ue.title,At,()=>{var bl;return(((bl=xe.current)==null?void 0:bl.tasks)??[]).map(um=>um.id).filter(um=>um!==ue.id)[Be]??null}),children:"Done"}):null,Nt,ji&&lm?i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",variant:"outline",size:"icon","aria-label":`Move ${ue.title} up`,disabled:Be===0,onClick:()=>void Xi(ue,Be,-1),children:i.jsx(Q2,{className:"size-4","aria-hidden":"true"})}),i.jsx(U,{type:"button",variant:"outline",size:"icon","aria-label":`Move ${ue.title} down`,disabled:Be===W.length-1,onClick:()=>void Xi(ue,Be,1),children:i.jsx(X2,{className:"size-4","aria-hidden":"true"})})]}):null,ji?i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsx(U,{type:"button",variant:"outline",size:"icon","aria-label":`More actions for ${ue.title}`,children:i.jsx(xv,{className:"size-4","aria-hidden":"true"})})}),i.jsxs(bd,{align:"end",children:[wi&&ue.status_id!==wi.id?i.jsx(Uo,{onSelect:()=>zr(ue),children:"Complete"}):null,S?i.jsx(Uo,{className:"text-destructive focus:text-destructive",onSelect:()=>void Mr(ue),children:"Archive"}):null]})]}):null]})}):null]})}},ue.id)}),qa&&i.jsx(_e,{children:i.jsx(X,{colSpan:Lr,className:"text-muted-foreground h-24 text-center",children:N==="archived"?"No archived tasks.":"No tasks are assigned to you."})})]})]})}),F.next_cursor?i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2 self-start",disabled:Y,onClick:async()=>{te(!0),await B(F.next_cursor??void 0),te(!1)},children:"Load more"}):null]}):null,_&&o&&i.jsx(o3,{open:q,commands:o,list_id:y.id,list_revision:(F==null?void 0:F.list.revision)??y.revision,default_status_id:y.default_status_id,statuses:x,priorities:w,members:n,on_close:()=>ve(!1),on_created:async()=>{ve(!1),await Fe()}}),On]})}function m3(e,t){const n=Object.keys(e).filter(a=>e[a]),s=Object.keys(e).filter(a=>!e[a]);return{...n.length?{opened_groups:n}:{},...s.length?{closed_groups:s}:{},...t.length?{all_groups:t}:{}}}function p3(e,t,n,s){if(!t)return e.map((r,o)=>({kind:"row",row:r,index:o}));const a=[];for(const r of t){const o=n[r.id]??r.open;if(a.push({kind:"group",group:r,open:o}),!o||!r.open)continue;let l=0;e.forEach((c,d)=>{c.local_state===r.id&&(a.push({kind:"row",row:c,index:d}),l+=1)}),(r.hidden>0||s.includes(r.id)&&l>g3)&&a.push({kind:"more",group:r})}return a}const g3=10;function x3({group:e,open:t,columns:n,on_toggle:s}){const a=t?rf:ld;return i.jsx(_e,{"data-testid":"tasks-group",children:i.jsx(X,{colSpan:n,className:"p-1",children:i.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"w-full justify-start font-semibold","aria-expanded":t,onClick:s,children:[i.jsx(a,{className:"size-4","aria-hidden":"true"}),e.label," ",e.count]})})})}function v3({group:e,whole:t,columns:n,on_toggle:s}){return i.jsx(_e,{"data-testid":"tasks-group-more",children:i.jsx(X,{colSpan:n,children:i.jsx(U,{type:"button",variant:"link",size:"sm",className:"px-0","aria-expanded":t,onClick:s,children:t?"Show fewer":`Show all ${e.count}`})})})}const b3={you:"text-warning",ok:"text-info",waiting:"text-info",blocked:"text-warning",neutral:"text-muted-foreground",muted:"text-muted-foreground"};function y3({thread:e,columns:t,children:n}){const{button:s,panel:a}=Vf(e);return i.jsxs(i.Fragment,{children:[n(s,!!a),a?i.jsx(_e,{"data-testid":"tasks-row-panel",className:"hover:bg-transparent",children:i.jsx(X,{colSpan:t,className:"pt-0",children:i.jsx("div",{className:"max-w-180 pl-4 text-left whitespace-normal",children:a})})}):null]})}function w3({row:e}){var s;const t=e.local_after,n=e.local_detail;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"text-muted-foreground font-mono text-xs",children:[e.id,e.match?` · matched in ${e.match}`:""]}),t||n?i.jsxs("div",{className:"text-muted-foreground text-xs",children:[t,t&&n?" · ":"",n?i.jsx("span",{className:b3[e.local_tone??"muted"],children:n}):null]}):null,(s=e.local_marks)!=null&&s.length?i.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.local_marks.map(a=>i.jsx(we,{variant:a.tone??"neutral",children:a.label},a.label))}):null]})}function _3({owners:e,no_owner:t,value:n,on_change:s}){return i.jsxs(St,{value:n,onValueChange:s,children:[i.jsx(wt,{className:"w-56","aria-label":"Owner",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Vl,children:"Any owner"}),e.map(a=>i.jsxs(Ue,{value:a.id,children:[a.label," (",a.count,")"]},a.id)),t!==void 0?i.jsxs(Ue,{value:RD,children:["No owner (",t,")"]}):null]})]})}function j3({row:e,holder:t}){const n=e.claim;if(!n)return i.jsx("span",{className:"text-muted-foreground",children:"Nobody"});if(n.lapsed){const s=new Date(n.lease_expires_at)<=new Date;return i.jsxs("div",{children:[i.jsxs("div",{className:"text-warning",children:["Lapsed · ",t]}),i.jsx("div",{className:"text-muted-foreground text-xs",children:s?`Ran out at ${Fs(n.lease_expires_at)}`:"Can no longer edit it"})]})}return i.jsxs("div",{className:"max-w-64",children:[i.jsxs("div",{children:[t,n.via?` · ${ab(n.via)}`:""]}),i.jsxs("div",{className:"text-muted-foreground truncate text-xs",title:n.via==="sdlc_login"&&n.via_device?DD(n.via_device):void 0,children:["Until ",Fs(n.lease_expires_at),n.via==="sdlc_login"&&n.via_device?i.jsxs(i.Fragment,{children:[" · ",i.jsx("bdi",{children:n.via_device})]}):null]})]})}const N3={waiting_for_user:{label:"Waiting for",help:"The member who must act. They see this hold under Waiting on you."},blocked:{label:"Blocked by",help:"The task that must finish first."},waiting_for_external:{label:"Waiting for",help:"Who or what outside the organization."},paused:null};function k3({open:e,members:t,tasks:n,holds_my_web_claim:s,on_close:a,on_submit:r}){const[o,l]=u.useState("waiting_for_user"),[c,d]=u.useState(""),[h,f]=u.useState(""),[m,p]=u.useState(!1),[y,g]=u.useState({}),[b,v]=u.useState(null),[x,w]=u.useState(!1);u.useEffect(()=>{e&&(l("waiting_for_user"),d(""),f(""),p(!1),g({}),v(null))},[e]);const _=N3[o],S=async k=>{k.preventDefault();const j={target:_!==null&&!c.trim(),reason:!h.trim()};if(g(j),j.target||j.reason)return;w(!0);const N={hold_type:o,reason:h.trim(),release_claim:m};o==="waiting_for_user"&&(N.target_user_id=c),o==="blocked"&&(N.target_task_id=c),o==="waiting_for_external"&&(N.target_label=c.trim());const O=await r(N);w(!1),v(O)};return i.jsx(yn,{open:e,onOpenChange:k=>k?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:k=>void S(k),noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Add hold"}),i.jsx(kn,{children:"Say what this task is waiting for."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[b&&i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{children:b})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"hold-type",children:"Type"}),i.jsxs(St,{value:o,onValueChange:k=>{l(k),d(""),g({})},children:[i.jsx(wt,{id:"hold-type",children:i.jsx(Ct,{})}),i.jsx(_t,{children:Object.keys(zc).map(k=>i.jsx(Ue,{value:k,children:zc[k].label},k))})]})]}),_?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"hold-target",children:_.label}),o==="waiting_for_external"?i.jsx(bt,{id:"hold-target",value:c,"aria-invalid":y.target,onChange:k=>d(k.target.value)}):i.jsxs(St,{value:c,onValueChange:d,children:[i.jsx(wt,{id:"hold-target","aria-invalid":y.target,children:i.jsx(Ct,{placeholder:o==="blocked"?"Choose a task":"Choose a member"})}),i.jsx(_t,{children:o==="blocked"?n.map(k=>i.jsx(Ue,{value:k.id,children:k.title},k.id)):t.map(k=>i.jsx(Ue,{value:k.user_id,children:k.label},k.user_id))})]}),i.jsx("p",{className:y.target?"text-destructive text-xs":"text-muted-foreground text-xs",children:y.target?"Choose what it waits for.":_.help})]}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"You resume it yourself."}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"hold-reason",children:"Reason"}),i.jsx(Gn,{id:"hold-reason",rows:3,placeholder:"What the task is waiting for",value:h,"aria-invalid":y.reason,onChange:k=>f(k.target.value)}),y.reason&&i.jsx("p",{className:"text-destructive text-xs",children:"Give a reason."})]}),s&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nl,{id:"hold-release-claim",checked:m,onCheckedChange:k=>p(k===!0)}),i.jsx(Ie,{htmlFor:"hold-release-claim",children:"Also release my claim"})]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",onClick:a,children:"Cancel"}),i.jsx(U,{type:"submit",disabled:x,children:x?"Adding…":"Add hold"})]})]})})})}function jd(){const e=Vn().tasks;if(!e)throw new Error("The Task page rendered without the tasks seam.");return e}function lb(){return i.jsxs("div",{className:"grid gap-3",role:"status","aria-label":"Loading task",children:[i.jsx(Tt,{className:"h-8 w-1/2"}),Array.from({length:7},(e,t)=>i.jsx(Tt,{className:t===6?"h-6 w-2/3":"h-6 w-full"},t))]})}function kh({back:e,description:t}){const{href:n,Link:s}=lt();return i.jsx(Ha,{title:"Task not found",description:t??"It may have been removed, or you may not have access to it.",backHref:n(e),backLabel:"Back to tasks",link:s})}const Br="not_set",S3=10*60*1e3,e_=20;function C3(){const{members:e}=jd(),[t,n]=u.useState([]);u.useEffect(()=>{let r=!0;return e().then(o=>{r&&o.ok&&n(o.data)}),()=>{r=!1}},[e]);const s=u.useMemo(()=>new Map(t.map(r=>[r.user_id,r])),[t]),a=u.useCallback((r,o)=>{var l;return r?r===o?"You":((l=s.get(r))==null?void 0:l.label)??"A member":""},[s]);return{members:t,name:a}}function D3({active:e,task_id:t,back:n}){const s=jd(),{task:a,activity:r,listTasks:o,hierarchyRevision:l,commands:c}=s,{href:d,Link:h}=lt(),f=Ga(),{self_id:m}=af(),{members:p,name:y}=C3(),{workspace:g}=e,{confirm:b,confirm_dialog:v}=tl(),[x,w]=u.useState(null),[_,S]=u.useState(!1),[k,j]=u.useState(!1),[N,O]=u.useState(null),[T,I]=u.useState([]),[L,$]=u.useState(e_),[A,D]=u.useState([]),[E,R]=u.useState(!1),[C,M]=u.useState(null),[H,z]=u.useState(null),[K,oe]=u.useState(""),[re,Ne]=u.useState(null),Se=u.useCallback(async()=>{if(!a)return;const B=await a(t);B.ok?(w(B.data),j(!1)):B.refusal.status===404||B.refusal.status===400?S(!0):j(!0)},[a,t]),ae=u.useRef(0),F=u.useCallback(async()=>{if(!r)return;const B=ae.current+=1;let Le=[],Fe;for(;;){const Et=await r(t,Fe);if(B!==ae.current||!Et.ok)return;if(Le=[...Le,...Et.data.events].slice(-1e3),!Et.data.more||!Et.data.next_cursor)break;Fe=Et.data.next_cursor}B===ae.current&&I(Le.reverse())},[r,t]);u.useEffect(()=>{Se(),F()},[Se,F]);const ie=x?g.lists.find(B=>B.id===x.task.list_id):void 0,W=u.useMemo(()=>{var B;return((B=g.workflows.find(Le=>Le.id===(x==null?void 0:x.task.workflow_id)))==null?void 0:B.statuses)??[]},[g,x==null?void 0:x.task.workflow_id]);u.useEffect(()=>{if(!x)return;let B=!0;return o(x.task.list_id,{limit:100}).then(Le=>{B&&D(Le.ok?Le.data.tasks.filter(Fe=>Fe.id!==x.task.id).map(Fe=>({id:Fe.id,title:Fe.title})):[])}),()=>{B=!1}},[o,x==null?void 0:x.task.list_id,x==null?void 0:x.task.id,x]);const se=u.useCallback(async()=>{await Promise.all([Se(),F()])},[Se,F]),Z=u.useCallback((B,Le)=>c?c.run(B,Le):Promise.resolve({ok:!1,refusal:{status:0,message:"This page cannot change tasks."}}),[c]),de=u.useCallback(async(B,Le,Fe)=>{const Et=await Z(B,Le);return Et.ok?(Fe&&f.success(Fe),await se(),Et.data):(Et.refusal.code==="revision_conflict"?O({tone:"warning",title:"This task changed while you were editing",body:"We reloaded it. Check the change, then save again."}):Et.refusal.code==="claim_held"?(await Se(),O({tone:"destructive",title:"Someone else claimed this task first",body:"Their claim is shown below. You can take it over if it lapses."})):f.error(Et.refusal.message),await se(),null)},[Z,f,se,Se]),J=(x==null?void 0:x.claim)??null,G=J!==null&&J.id===re&&!J.lapsed&&!J.via?J.id:null;if(u.useEffect(()=>{if(!G)return;const B=window.setInterval(()=>{Z("renew_claim",{claim_id:G,lease_seconds:Jw}).then(()=>Se())},S3);return()=>window.clearInterval(B)},[G,Z,Se]),_)return i.jsx(kh,{back:n});if(k&&!x)return i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This task could not be loaded"}),i.jsxs(ge,{children:[i.jsx("p",{children:"Check your connection and try again."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>void Se(),children:"Retry"})]})]});if(!x)return i.jsx(lb,{});const{task:Y}=x,te=Y.archived_at!==null,ce=Nh(x.permission,"write")&&!te,be=Nh(x.permission,"manage"),fe=W.find(B=>B.id===Y.status_id),$e=W.find(B=>B.category==="completed"),ze=g.priorities.find(B=>B.id===Y.priority_id),q=x.contributors.map(B=>B.user_id),ve=J!==null&&J.user_id===m,Ve=J!==null&&!J.lapsed,Ft=x.checklist.filter(B=>B.is_complete).length,Qt=async()=>{const[B,Le]=await Promise.all([o(Y.list_id,{limit:1}),l(g.id)]);return B.ok?Le.ok?{ok:!0,data:{task_id:Y.id,expected_revision:Y.revision,expected_order_revision:B.data.list.order_revision,expected_hierarchy_revision:Le.data}}:Le:B},ht=(B,Le)=>de("update_task",{task_id:Y.id,expected_revision:Y.revision,changes:B},Le),it=B=>b(B.via==="sdlc_login"?{title:"Release this claim?",description:`You claimed it via ${ap(B.via,B.via_device)}. Its next renewal will be refused, and it will stop holding the task.`,action_label:"Release claim",destructive:!0}:{title:"Release your agent's claim?",description:"Your agent is still working on this task. Its next renewal will be refused, and it will stop holding the task.",action_label:"Release claim",destructive:!0}),Lt=async()=>{if(!$e)return;if(Ve&&(!ve||J.via)){const Le=J.via==="api_key"?`${ve?"Your":`${y(J.user_id)}'s`} agent is still working on it.`:J.via==="sdlc_login"?`${ve?"You are":`${y(J.user_id)} is`} still working on it via ${ap(J.via,J.via_device)}.`:`${y(J.user_id)} is still working on it.`;if(!await b({title:"Complete this task?",description:Le,action_label:"Mark complete"}))return}await ht({status_id:$e.id},"Task completed.")!==null&&J&&ve&&Ve&&await de("end_claim",{claim_id:J.id,outcome:"completed"})},Dt=async(B,Le)=>{const Fe=await Qt();if(!Fe.ok){f.error(Fe.refusal.message);return}await de(B,Fe.data,Le)},On=async()=>{await b({title:"Archive this task?",description:"It leaves the queue and becomes read-only. Its claim, holds and history stay, and a manager can restore it.",action_label:"Archive task",destructive:!0})&&await Dt("archive_task","Task archived.")},mn=async()=>{await Dt("restore_task","Task restored.")},Sn=async()=>{var Et;const B=J,Le=await de("claim_task",{task_id:Y.id,lease_seconds:Jw}),Fe=(Et=Le==null?void 0:Le.claim)==null?void 0:Et.id;Fe&&!(B&&B.id===Fe&&B.via)&&Ne(Fe)},xe=async()=>{J&&(J.via&&!await it(J)||(await de("end_claim",{claim_id:J.id,outcome:"released"},"Claim released."),Ne(null)))},ne=async()=>{J&&await de("end_claim",{claim_id:J.id,outcome:"expired"},"Claim cleared.")},ye=async B=>{B.hold_type==="paused"&&m&&(B={...B,target_user_id:m});const Le=await Z("open_hold",{task_id:Y.id,hold_type:B.hold_type,reason:B.reason,...B.target_user_id?{target_user_id:B.target_user_id}:{},...B.target_task_id?{target_task_id:B.target_task_id}:{},...B.target_label?{target_label:B.target_label}:{}});return Le.ok?(R(!1),f.success("Hold added."),B.release_claim&&J&&ve&&!J.via&&(await de("end_claim",{claim_id:J.id,outcome:"released"}),Ne(null)),await se(),null):Le.refusal.message},qe=B=>de("checklist",{task_id:Y.id,expected_revision:Y.revision,...B}),xt=async B=>{for(const Le of B.filter(Fe=>!q.includes(Fe)))await de("set_contributor",{task_id:Y.id,expected_revision:Y.revision,user_id:Le,action:"add"});for(const Le of x.contributors.filter(Fe=>!B.includes(Fe.user_id)))await de("set_contributor",{task_id:Y.id,expected_revision:Y.revision,user_id:Le.user_id,action:"remove",expected_contributor_revision:Le.revision})},ss=B=>{var Fe;if(B.target.kind==="user")return y(B.target.user_id,m);if(B.target.kind==="external")return B.target.label;if(B.target.hidden||!B.target.task_id)return"A task you cannot see";const Le=B.target.task_id;return i.jsx(h,{className:"text-primary hover:underline",href:d(`${n}/${Le}`),children:((Fe=A.find(Et=>Et.id===Le))==null?void 0:Fe.title)??"Another task"})},zn=B=>B.target.kind==="user"&&B.target.user_id===m&&!B.released_at?i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void de("release_hold",{hold_id:B.id},"Hold released."),children:"Release"}):ce?i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void de("resolve_hold",{hold_id:B.id},"Hold resolved."),children:"Resolve"}):null;return i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:Y.title,description:`Created ${Rs(Y.created_at)} by ${y(Y.created_by,m)}`,actions:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ce&&i.jsxs(i.Fragment,{children:[i.jsxs(U,{type:"button",variant:"outline",onClick:()=>M(Y.title),children:[i.jsx(df,{className:"mr-2 size-4","aria-hidden":"true"}),"Edit title"]}),$e&&Y.status_id!==$e.id&&i.jsxs(U,{type:"button",variant:"outline",onClick:()=>void Lt(),children:[i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}),"Mark complete"]})]}),be&&!te&&i.jsxs(U,{type:"button",variant:"outline",onClick:()=>void On(),children:[i.jsx(xw,{className:"mr-2 size-4","aria-hidden":"true"}),"Archive"]})]}),children:C!==null?i.jsxs("form",{className:"flex flex-wrap items-center gap-2 pt-1",onSubmit:async B=>{B.preventDefault(),C.trim()&&await ht({title:C.trim()})!==null&&M(null)},children:[i.jsx(Ie,{htmlFor:"task-title",className:"sr-only",children:"Title"}),i.jsx(bt,{id:"task-title",className:"max-w-xl",value:C,onChange:B=>M(B.target.value)}),i.jsx(U,{type:"submit",size:"sm",children:"Save"}),i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:()=>M(null),children:"Cancel"})]}):null}),N&&i.jsxs(pe,{variant:N.tone,className:"mt-4","data-testid":"task-notice",children:[N.tone==="warning"?i.jsx(Er,{className:"size-4","aria-hidden":"true"}):i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:N.title}),i.jsx(ge,{children:N.body})]}),te?i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(xw,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This task is archived"}),i.jsx(ge,{children:be?i.jsxs(i.Fragment,{children:[i.jsx("p",{children:"It is out of the queue and cannot be claimed. Restore it to work on it again."}),i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>void mn(),children:[i.jsx(F2,{className:"mr-2 size-4","aria-hidden":"true"}),"Restore"]})]}):i.jsx("p",{children:"It is out of the queue and cannot be claimed. A manager can restore it."})})]}):ce?null:i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can view this task"}),i.jsx(ge,{children:"Ask an organization admin for write access to change it."})]}),ce?i.jsxs("div",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-status",children:"Status"}),i.jsxs(St,{value:Y.status_id,onValueChange:B=>void ht({status_id:B}),children:[i.jsx(wt,{id:"task-status",children:i.jsx(Ct,{})}),i.jsx(_t,{children:W.map(B=>i.jsx(Ue,{value:B.id,children:B.name},B.id))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-priority",children:"Priority"}),i.jsxs(St,{value:Y.priority_id??Br,onValueChange:B=>void ht({priority_id:B===Br?null:B}),children:[i.jsx(wt,{id:"task-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Br,children:"Not set"}),g.priorities.map(B=>i.jsx(Ue,{value:B.id,children:B.name},B.id))]})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-primary",children:"Primary"}),i.jsxs(St,{value:Y.primary_user_id??Br,onValueChange:B=>void ht({primary_user_id:B===Br?null:B}),children:[i.jsx(wt,{id:"task-primary",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Br,children:"Not set"}),p.map(B=>i.jsx(Ue,{value:B.user_id,children:B.label},B.user_id))]})]})]}),i.jsx(E3,{members:p,selected:q,on_change:B=>void xt(B)})]}):i.jsxs("dl",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[i.jsx(Kd,{label:"Status",value:(fe==null?void 0:fe.name)??""}),i.jsx(Kd,{label:"Priority",value:(ze==null?void 0:ze.name)??"Not set"}),i.jsx(Kd,{label:"Primary",value:Y.primary_user_id?y(Y.primary_user_id,m):"Not set"}),i.jsx(Kd,{label:"Contributors",value:q.map(B=>y(B,m)).join(", ")||"None"})]}),!te&&i.jsx(A3,{claim:J,mine:ve,holder:J?y(J.user_id):"",own:J!==null&&J.id===re,can_write:ce,on_claim:()=>void Sn(),on_release:()=>void xe(),on_clear:()=>void ne()}),i.jsxs("section",{className:"mt-6","aria-labelledby":"task-description-title",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("h2",{id:"task-description-title",className:"text-lg font-semibold",children:"Description"}),ce&&H===null&&i.jsx(U,{type:"button",variant:"ghost",size:"sm",onClick:()=>z(Y.description??""),children:"Edit description"})]}),H!==null?i.jsxs("form",{className:"mt-2 grid gap-2",onSubmit:async B=>{B.preventDefault(),await ht({description:H})!==null&&z(null)},children:[i.jsx(Ie,{htmlFor:"task-description",className:"sr-only",children:"Description"}),i.jsx(Gn,{id:"task-description",rows:5,value:H,onChange:B=>z(B.target.value)}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(U,{type:"submit",size:"sm",children:"Save"}),i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:()=>z(null),children:"Cancel"})]})]}):i.jsx("p",{className:"mt-2 text-sm whitespace-pre-wrap",children:Y.description||i.jsx("span",{className:"text-muted-foreground",children:"No description."})})]}),i.jsxs("section",{className:"mt-6","aria-labelledby":"task-checklist-title",children:[i.jsxs("h2",{id:"task-checklist-title",className:"text-lg font-semibold",children:["Checklist",x.checklist.length>0?` · ${Ft} of ${x.checklist.length} done`:""]}),i.jsx("ul",{className:"mt-2 grid gap-1",children:x.checklist.map(B=>i.jsxs("li",{className:"flex items-center justify-between gap-2 py-1","data-testid":"task-checklist-item",children:[ce?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nl,{id:`check-${B.id}`,checked:B.is_complete,onCheckedChange:Le=>void qe({action:"toggle",item_id:B.id,expected_item_revision:B.revision,is_complete:Le===!0})}),i.jsx(Ie,{htmlFor:`check-${B.id}`,className:"font-normal",children:B.label})]}):i.jsxs("span",{className:"text-sm",children:[B.is_complete?"Done: ":"To do: ",B.label]}),ce&&i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"icon","aria-label":`Item actions for ${B.label}`,children:i.jsx(xv,{className:"size-4","aria-hidden":"true"})})}),i.jsx(bd,{align:"end",children:i.jsx(Uo,{className:"text-destructive focus:text-destructive",onSelect:()=>void qe({action:"archive",item_id:B.id,expected_item_revision:B.revision}),children:"Remove"})})]})]},B.id))}),x.checklist.length===0&&!ce&&i.jsx("p",{className:"text-muted-foreground text-sm",children:"No checklist items."}),ce&&i.jsxs("form",{className:"mt-2 grid gap-2",onSubmit:async B=>{B.preventDefault(),K.trim()&&await qe({action:"add",label:K.trim()})!==null&&oe("")},children:[i.jsx(Ie,{htmlFor:"task-new-item",children:"Add an item"}),i.jsx(bt,{id:"task-new-item",placeholder:"Add an item and press Enter",value:K,onChange:B=>oe(B.target.value)})]})]}),i.jsxs("section",{className:"mt-6","aria-labelledby":"task-holds-title",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("h2",{id:"task-holds-title",className:"text-lg font-semibold",children:"Holds"}),ce&&i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:()=>R(!0),children:[i.jsx(Bk,{className:"mr-2 size-4","aria-hidden":"true"}),"Add hold"]})]}),i.jsx("div",{className:"mt-2 shrink-0 overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Holds",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Type"}),i.jsx(Q,{children:"Reason"}),i.jsx(Q,{children:"Waiting on"}),i.jsx(Q,{className:"text-right",children:"Actions"})]})}),i.jsxs(st,{children:[x.holds.map(B=>{const Le=zc[B.hold_type];return i.jsxs(_e,{"data-testid":"task-hold",children:[i.jsx(X,{children:i.jsx(we,{variant:Le.tone,children:Le.label})}),i.jsxs(X,{children:[i.jsx("div",{children:B.reason}),i.jsx("div",{className:"text-muted-foreground text-xs",children:B.released_at?`Released by ${y(B.released_by,m)} · ${Rs(B.released_at)} · Ready to resolve`:`Opened by ${y(B.opened_by,m)} · ${Rs(B.opened_at)} · Open`})]}),i.jsx(X,{children:ss(B)}),i.jsx(X,{className:"text-right",children:zn(B)})]},B.id)}),x.holds.length===0&&i.jsx(_e,{children:i.jsx(X,{colSpan:4,className:"text-muted-foreground h-16 text-center",children:"Nothing is holding this task."})})]})]})}),i.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:"A hold does not change the task's status. The person it waits on releases it; whoever can edit the task resolves it."})]}),i.jsxs("section",{className:"mt-6 pb-8","aria-labelledby":"task-activity-title",children:[i.jsx("h2",{id:"task-activity-title",className:"text-lg font-semibold",children:"Activity"}),i.jsxs("ul",{className:"mt-2 divide-y rounded-lg border",children:[T.slice(0,L).map(B=>i.jsxs("li",{className:"grid grid-cols-[1fr_auto] gap-x-4 px-3 py-2 text-sm sm:grid-cols-[2fr_1fr_10rem]","data-testid":"task-activity",children:[i.jsx("span",{children:r3(B)}),i.jsxs("span",{className:"min-w-0 text-right sm:text-left",children:[i.jsx("span",{children:B.actor_id?y(B.actor_id,m):"The system"}),B.via?i.jsxs("span",{className:"text-muted-foreground block max-w-64 truncate text-xs sm:max-w-none",title:`via ${ap(B.via,B.via_device)}`,children:["via ",ab(B.via),i.jsx(zD,{via:B.via,device:B.via_device})]}):null]}),i.jsx("span",{className:"text-muted-foreground col-span-2 sm:col-span-1 sm:text-right",children:AD(B.created_at)})]},B.id)),T.length===0&&i.jsx("li",{className:"text-muted-foreground px-3 py-2 text-sm",children:"No activity yet."})]}),T.length>L&&i.jsx(U,{type:"button",variant:"ghost",size:"sm",className:"mt-2",onClick:()=>$(B=>B+e_),children:"Load more"})]}),ce&&ie&&i.jsx(k3,{open:E,members:p,tasks:A,holds_my_web_claim:ve&&Ve&&!(J!=null&&J.via),on_close:()=>R(!1),on_submit:ye}),v]})}function Kd({label:e,value:t}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("dt",{className:"text-muted-foreground text-xs",children:e}),i.jsx("dd",{className:"text-sm",children:t})]})}function E3({members:e,selected:t,on_change:n}){return i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-contributors",children:"Contributors"}),i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsxs(U,{id:"task-contributors",type:"button",variant:"outline",className:"justify-between font-normal",children:[t.length===0?i.jsx("span",{className:"text-muted-foreground",children:"Add a contributor"}):i.jsx("span",{className:"truncate",children:e.filter(s=>t.includes(s.user_id)).map(s=>s.label).join(", ")}),i.jsx(Lk,{className:"text-muted-foreground size-4","aria-hidden":"true"})]})}),i.jsx(bd,{align:"start",children:e.map(s=>{const a=t.includes(s.user_id);return i.jsxs(Uo,{onSelect:()=>n(a?t.filter(r=>r!==s.user_id):[...t,s.user_id]),children:[a?i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}):i.jsx("span",{className:"mr-2 size-4"}),s.label]},s.user_id)})})]})]})}function zD({via:e,device:t}){return e!=="sdlc_login"||!t?null:i.jsxs(i.Fragment,{children:[" on ",i.jsx("bdi",{children:t})]})}function A3({claim:e,mine:t,holder:n,own:s,can_write:a,on_claim:r,on_release:o,on_clear:l}){let c=i.jsx(yv,{className:"size-4","aria-hidden":"true"}),d="Nobody is working on this",h=a?"Claim it to show others you are.":"",f=a?i.jsx(U,{type:"button",size:"sm",onClick:r,children:"Claim"}):null;if(e&&e.lapsed){const m=new Date(e.lease_expires_at)<=new Date;c=i.jsx(Pk,{className:"size-4","aria-hidden":"true"}),d=m?`${t?"Your":`${n}'s`} claim lapsed at ${Fs(e.lease_expires_at)}`:`${t?"Your":`${n}'s`} claim lapsed`,h=m?"Its time ran out.":`${n} can no longer edit this task.`,a&&(h+=" Take it over to work on it yourself, or clear it so anyone can claim it."),f=a?i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:l,children:"Clear claim"}),i.jsx(U,{type:"button",size:"sm",onClick:r,children:"Take over"})]}):null}else if(e){const m=Fs(e.lease_expires_at);c=e.via==="api_key"?i.jsx(pv,{className:"size-4","aria-hidden":"true"}):e.via==="sdlc_login"?i.jsx(PO,{className:"size-4","aria-hidden":"true"}):i.jsx(_z,{className:"size-4","aria-hidden":"true"});const p=i.jsxs(i.Fragment,{children:["Claimed via sdlc login",i.jsx(zD,{via:e.via,device:e.via_device}),"."]});t&&e.via==="api_key"?(d=`Your agent is working on this until ${m}`,h="Claimed through one of your API keys. This page does not renew it. Releasing it, or Mark complete, ends the agent's claim after asking."):t&&e.via==="sdlc_login"?(d=`You are working on this until ${m}`,h=i.jsxs(i.Fragment,{children:[p," This page does not renew it. Releasing it, or Mark complete, ends that claim after asking."]})):e.via==="sdlc_login"?(d=`${n} is working on this until ${m}`,h=p):t?(d=`You are working on this until ${m}`,h=s?"Claimed on the web, and renewed while this page is open. Marking the task complete ends your claim.":"Claimed on the web. Marking the task complete ends your claim."):e.via==="api_key"?(d=`${n}'s agent is working on this until ${m}`,h="Claimed through an API key."):(d=`${n} is working on this until ${m}`,h=a?"Claimed on the web. You can take it over if the claim lapses.":"Claimed on the web."),f=t?i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:o,children:"Release claim"}):null}return i.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3 rounded-lg border p-3","data-testid":"task-claim",children:[c,i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-medium",children:d}),h?i.jsx("div",{className:"text-muted-foreground text-xs break-words",children:h}):null]}),f?i.jsx("div",{className:"flex items-center gap-2",children:f}):null]})}function cb(e){const t=u.useRef(null),n=u.useRef(!1),[s,a]=u.useState(0),r=u.useCallback(o=>{var l;!o&&((l=t.current)!=null&&l.contains(document.activeElement))&&(n.current=!0,a(c=>c+1)),t.current=o},[]);return u.useEffect(()=>{var c;if(!n.current)return;n.current=!1;const o=document.activeElement;if(o&&o!==document.body)return;const l=(c=e.current)==null?void 0:c.querySelector("h1");l&&(l.tabIndex=-1,l.focus())},[s,e]),r}function MD(){const e=u.useRef(null);return u.useCallback(t=>{const n=e.current;if(e.current=t,t||!(n!=null&&n.contains(document.activeElement)))return;const s=(n.closest("main")??document).querySelector("h1");s&&Promise.resolve().then(()=>{const a=document.activeElement;a&&a!==document.body||!s.isConnected||(s.tabIndex=-1,s.focus())})},[])}const R3=10,$D=5,T3=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,LD="Not available",O3={added:"Added",changed:"Changed",removed:"Removed"},z3={thread:"Thread",task:"Task",issue:"Issue",release:"Release",test:"Test"},t_=/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/;function M3(e,t){const n=t!=null&&t.startsWith("task:")?t.slice(5):null;if(n&&T3.test(n))return{label:n,path:`/org/${e}/tasks/${n}`};const s=t!=null&&t.startsWith("issue:")?t.slice(6):null;if(s&&/^iss-\d{1,9}$/.test(s))return{label:s,path:`/org/${e}/issues/${s}`};const a=t!=null&&t.startsWith("release:")?t.slice(8):null;if(a&&t_.test(a))return{label:a==="candidate"?"Candidate":`Release ${a}`,path:`/releases?release=${a}`};const r=t!=null&&t.startsWith("planned:")?t.slice(8):null;return r&&t_.test(r)?{label:`Planned Release ${r}`,path:`/releases?planned=${r}`}:{label:"Tasks",path:`/org/${e}/tasks`}}const PD=e=>e.status===0||e.reason==="store_locked"||e.reason==="engine_failed"||e.status>=500;function $3({org:e,task_id:t,from:n}){var mn,Sn;const s=jd(),{href:a,Link:r}=lt(),{confirm:o,confirm_dialog:l}=tl(),c=M3(e,n),[d,h]=u.useState({state:"loading"}),[f,m]=u.useState([]),[p,y]=u.useState([]),[g,b]=u.useState(null),[v,x]=u.useState(null),[w,_]=u.useState({state:"loading"}),[S,k]=u.useState({state:"loading"}),[j,N]=u.useState(null),[O,T]=u.useState(null),[I,L]=u.useState(!1),$=u.useRef(null),A=ns(),D=Vf({org:e,action:d.state==="ok"?d.detail.local_action:void 0,task_id:t,open_thread:(mn=s.commands)==null?void 0:mn.open_thread,labelled:!0}),E=u.useRef(null),R=u.useRef(null),C=u.useRef(null),M=u.useRef(null),H=u.useRef(!1),z=u.useRef(0),K=u.useRef(0),oe=u.useCallback(async()=>{if(!s.taskSections)return;_({state:"loading"});const xe=await s.taskSections(t);_(xe.ok?{state:"ok",data:xe.data}:{state:"failed",refusal:xe.refusal})},[s.taskSections,t]),re=u.useCallback(async()=>{if(!s.taskRelated)return;k({state:"loading"});const xe=await s.taskRelated(t);k(xe.ok?{state:"ok",data:xe.data}:{state:"failed",refusal:xe.refusal})},[s.taskRelated,t]),Ne=u.useCallback(async()=>{var xt,ss;const xe=K.current+=1;x(null),oe(),re();const[ne,ye]=await Promise.all([s.availability(),s.task?s.task(t):Promise.resolve(null)]);if(xe!==K.current)return;ne.state==="active"&&m(((xt=ne.workspace.workflows.find(zn=>zn.id===ne.list.workflow_id))==null?void 0:xt.statuses)??[]);const qe=ne.state==="off"&&((ss=ne.refusal)==null?void 0:ss.reason)==="engine_missing"?ne.refusal:null;if(!ye||!ye.ok&&ye.refusal.reason==="engine_missing"||qe){h({state:"engine_missing",refusal:qe??(ye&&!ye.ok?ye.refusal:{status:0,message:""})});return}if(ye.ok){z.current=0,b(null),T(null),h({state:"ok",detail:ye.data,at:new Date().toISOString()});return}if(ye.refusal.status===404||ye.refusal.reason==="not_found"){h({state:"missing"});return}if(z.current+=1,z.current===1&&PD(ye.refusal)){x(ye.refusal.retry_after??R3);return}b(ye.refusal),h(zn=>zn.state==="loading"?{state:"loading"}:zn)},[s,t,oe,re]);u.useEffect(()=>{Ne()},[Ne]),u.useEffect(()=>{if(v===null)return;const xe=setTimeout(()=>void Ne(),v*1e3);return()=>clearTimeout(xe)},[v,Ne]),u.useEffect(()=>{let xe=!0;return s.members().then(ne=>{xe&&ne.ok&&y(ne.data)}),()=>{xe=!1}},[s.members]),u.useEffect(()=>{var ne;if(H.current||d.state!=="ok")return;H.current=!0;const xe=(ne=$.current)==null?void 0:ne.querySelector("h1");xe&&(xe.tabIndex=-1,xe.focus())},[d.state]),u.useEffect(()=>{var xe;j&&((xe=R.current)==null||xe.focus())},[j]),u.useEffect(()=>{if(O===null)return;const xe=setTimeout(()=>{var ne;return(ne=E.current)==null?void 0:ne.focus()},0);return()=>clearTimeout(xe)},[O]);const Se=u.useMemo(()=>new Map(p.map(xe=>[xe.user_id,xe.label])),[p]),ae=xe=>xe?Se.get(xe)??xe:"",F=()=>{N(null),Ne()},ie=u.useRef(null),W=xe=>(ie.current=xe,xe==="graph"?oe():re());if(u.useEffect(()=>{var ye;const xe=ie.current;if(xe===null||(xe==="graph"?w:S).state==="loading")return;ie.current=null;const ne=(xe==="graph"?C:M).current??((ye=$.current)==null?void 0:ye.querySelector("h1"));ne==null||ne.focus()},[w,S]),d.state==="missing")return i.jsx(ma,{children:i.jsx(kh,{back:`/org/${e}/tasks`,description:`No task ${t} in this checkout. It may have finished and been archived, or never been recorded.`})});const se=i.jsx(U,{asChild:!0,variant:"link",size:"sm",className:"px-0",children:i.jsxs(r,{href:a(c.path),children:[i.jsx($k,{className:"size-4","aria-hidden":"true"}),c.label]})});if(d.state==="engine_missing")return i.jsx(ma,{children:i.jsx("div",{ref:$,className:"contents",children:i.jsx(yi,{page:"Task",header:i.jsx(oc,{back:se,id:null,title:t})})})});const Z=g?i.jsxs(pe,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not read this task"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[g.message,g.since?` Since ${As(g.since)}.`:"",d.state==="ok"?` This page was read at ${As(d.at)}.`:""," See the sdlc viewer terminal for more."]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:F,children:"Retry"})]})]}):null,de=v!==null?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"Could not read this task. Trying again in ",v," seconds."]}):null,J=i.jsx("div",{role:"status","aria-live":"polite",children:de});if(d.state==="loading")return i.jsxs(ma,{children:[J,Z,!g&&v===null?i.jsx(lb,{}):null]});const{detail:G,at:Y}=d,{task:te}=G,ce=f.find(xe=>xe.id===te.status_id),be=G.local_done&&"task"in G.local_done?G.local_done:null,fe=G.local_waits??[],$e=be?fe[0]??null:null,ze=$e?ae($e.opened_by):G.owner_title??ae(G.thread),q=w.state==="ok"?w.data:null,ve=(q==null?void 0:q.lifecycle)==="finished",Ve=ve&&(q==null?void 0:q.outcome)==="cancelled",Ft=ve&&(q==null?void 0:q.outcome)==="complete",Qt=!!te.created_at,ht=G.acceptance??[],it=G.local_owner_thread,Lt=it?i.jsx(r,{className:"text-primary hover:underline",href:a(ib(e,it.key)),children:it.title}):G.owner_title??(ae(G.thread)||"None"),Dt=async()=>{var ye;if(!be||!((ye=s.commands)!=null&&ye.complete)||!await o({title:`Mark ${te.title} done?`,description:$e?`This answers ${ze}'s ask, “${$e.reason}”, closes that wait, and tells ${ze} to check and continue.`:`This tells ${ze||"its thread"} to check and continue.`,action_label:"Mark done"}))return;L(!0);const ne=await s.commands.complete(be);if(L(!1),!ne.ok){T(ne.refusal.message);return}await Ne(),N({title:te.title,asker:ze||"Its thread"})},On=i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[be&&!j?i.jsxs(i.Fragment,{children:[i.jsxs(U,{ref:E,type:"button",variant:"outline",disabled:I,"aria-disabled":O!==null?!0:void 0,"aria-describedby":O!==null?"task-done-why":void 0,onClick:()=>{O===null&&Dt()},children:[i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}),"Done"]}),O!==null?i.jsx("span",{id:"task-done-why",className:"text-muted-foreground text-xs",children:"Read again first"}):null]}):null,D.button,i.jsxs("span",{className:"text-muted-foreground text-sm",children:["Read at ",As(Y)]}),i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:F,children:[i.jsx(Er,{className:"mr-2 size-4","aria-hidden":"true"}),"Read again"]})]});return i.jsxs(ma,{children:[i.jsxs("div",{ref:$,className:"contents",children:[i.jsx(oc,{back:se,id:te.id,copy:i.jsx(Ug,{text:te.id,label:"Copy ID",what:"the ID",variant:"ghost"}),badge:ce?i.jsx(we,{variant:ED(ce),children:ce.name}):null,title:te.title,created:Qt?`Created ${Rs(te.created_at)}${ze||G.owner_title?` by ${G.owner_title??ze}`:""}`:null,actions:On}),D.panel?i.jsx("div",{className:"mt-1 max-w-180",children:D.panel}):null,J,Z,j?i.jsx("div",{ref:R,tabIndex:-1,role:"status","aria-live":"polite",className:"outline-none",children:i.jsxs(pe,{variant:"success",className:"mt-4",children:[i.jsx(of,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Marked ",j.title," done"]}),i.jsxs(ge,{children:[j.asker," is told to check and continue."]})]})}):null,O!==null?i.jsxs(pe,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Done was not recorded"}),i.jsxs(ge,{children:[O," Read again to see the task as it is now."]})]}):null,$e&&!j?i.jsxs(pe,{variant:"warning",className:"mt-4",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:[ze," asks: ",$e.reason]}),i.jsxs(ge,{children:["Waiting on you since ",rb($e.opened_at),". Done answers it and tells ",ze," to check and continue."]})]}):null,G.view_outdated?i.jsxs(pe,{variant:"warning",className:"mt-4",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsxs(ge,{children:[A," Until then this page cannot read the claim and holds."]})]}):null,i.jsxs("dl",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[i.jsx(ai,{label:"Owner thread",value:Lt}),i.jsx(ai,{label:"Release",value:G.release??"None"}),i.jsx(ai,{label:"Session",value:w.state==="loading"?"Loading…":w.state==="failed"?"Not available":q!=null&&q.session?i.jsxs(i.Fragment,{children:[q.session.provider," ",i.jsx("span",{className:"font-mono break-all",children:q.session.id})]}):"None"}),i.jsx(ai,{label:"Now",value:G.local_detail??(ce==null?void 0:ce.name)??""})]}),i.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:"Local tasks have no priority or contributors."}),i.jsx(L3,{detail:G,holder:ae((Sn=G.claim)==null?void 0:Sn.user_id),finished_at:ve?(q==null?void 0:q.finished_at)??null:null,read_at:Y}),i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"text-info size-4","aria-hidden":"true"}),be?i.jsxs(i.Fragment,{children:[i.jsx(ke,{children:"Done is the one change this page makes"}),i.jsx(ge,{children:"Everything else about this task changes through its thread."})]}):i.jsxs(i.Fragment,{children:[i.jsx(ke,{children:"This page only reads tasks"}),i.jsx(ge,{children:"A task changes through the agent thread working on it."})]})]}),Qt?q!=null&&q.record?i.jsxs("p",{className:"mt-4 flex flex-wrap items-center gap-2 text-sm",children:[i.jsxs("span",{children:["Record ",i.jsx("code",{className:"font-mono break-all",children:q.record})]}),i.jsx(Ug,{text:q.record,label:"Copy path",what:"the path",variant:"ghost"})]}):null:i.jsx("p",{className:"mt-4 text-sm",children:"No task record yet. This page shows what the threads and plans in this checkout say about it."}),be?i.jsx(Yt,{id:"task-done-needs",title:"What Done needs",children:ht.length>0?i.jsxs(i.Fragment,{children:[i.jsxs("p",{className:"text-muted-foreground text-xs",children:["The task's acceptance; ",ze||"its thread"," checks these after Done."]}),i.jsx("ul",{className:"mt-2 grid list-disc gap-1 pl-5 text-sm",children:ht.map(xe=>i.jsx("li",{children:xe},xe))})]}):i.jsxs("p",{className:"text-sm",children:["Its thread gave no acceptance. Ask ",ze||"its thread"," what Done needs before marking it."]})}):ht.length>0?i.jsxs(Yt,{id:"task-acceptance",title:"Acceptance",children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:Ft?"All met: the task finished complete":Ve&&(q!=null&&q.finished_at)?`Cancelled ${Rs(q.finished_at)}`:"Met when the task finishes complete"}),i.jsx("ul",{className:"mt-2 grid list-disc gap-1 pl-5 text-sm",children:ht.map(xe=>i.jsx("li",{children:Ft?`Met: ${xe}`:xe},xe))})]}):null,i.jsx(P3,{detail:G,waits:fe,given:be!==null,threadName:ae,threadsLink:i.jsx(r,{className:"text-primary hover:underline",href:a(`/org/${e}/threads`),children:"Threads"})}),w.state==="loading"?i.jsxs("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading the task's sections",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"})]}):null,q?i.jsx(Yt,{id:"task-stands",title:"Where it stands",children:i.jsxs("p",{className:"text-sm",children:[(ce==null?void 0:ce.name)??te.status_id,G.local_detail?` · ${G.local_detail}`:""]})}):null,q!=null&&q.time?i.jsx(I3,{time:q.time}):null,i.jsx(G3,{sections:w,heading_ref:C,on_retry:()=>void W("graph"),taskLink:xe=>i.jsx(r,{className:"text-primary hover:underline",href:a(`/org/${e}/tasks/${xe}?from=task:${te.id}`),children:xe})}),q!=null&&q.files?i.jsx(H3,{files:q.files,finished:ve}):null,q!=null&&q.proof?i.jsx(V3,{proof:q.proof,finished_at:q.finished_at,who:G.owner_title??null}):null,q&&q.history.length>0?i.jsx(U3,{history:q.history}):null,i.jsx(ID,{related:S,heading_ref:M,on_retry:()=>void W("related"),link:xe=>{const ne=xe.kind==="thread"?`${e?`/org/${e}`:""}/threads#thread-${encodeURIComponent(xe.id)}`:xe.kind==="task"?`/org/${e}/tasks/${xe.id}?from=task:${te.id}`:xe.kind==="issue"?`/org/${e}/issues/${encodeURIComponent(xe.id)}?from=task:${te.id}`:xe.kind==="release"?`/releases?${xe.planned?"planned":"release"}=${encodeURIComponent(xe.id)}`:null;return ne?i.jsx(r,{className:je("text-primary hover:underline",xe.kind!=="thread"&&xe.label===xe.id&&"font-mono"),href:a(ne),children:xe.label}):xe.label}})]}),l]})}function ma({children:e}){return i.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 pb-8 sm:px-6 lg:px-8",children:e})}function oc({back:e,id:t,copy:n,badge:s,title:a,created:r,actions:o}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("div",{children:e}),t?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[i.jsx("code",{className:"font-mono",children:t}),n,s]}):null,i.jsx(bn,{title:a,description:r??void 0,actions:o})]})}function ai({label:e,value:t}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("dt",{className:"text-muted-foreground text-xs",children:e}),i.jsx("dd",{className:"m-0 text-sm break-words",children:t})]})}function Yt({id:e,title:t,aside:n,heading_ref:s,children:a}){return i.jsxs("section",{className:"mt-6","aria-labelledby":`${e}-title`,children:[i.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[i.jsx("h2",{id:`${e}-title`,ref:s,tabIndex:s?-1:void 0,className:"text-lg font-semibold outline-none",children:t}),n?i.jsx("span",{className:"text-muted-foreground text-sm",children:n}):null]}),i.jsx("div",{className:"mt-2",children:a})]})}function L3({detail:e,holder:t,finished_at:n,read_at:s}){const a=e.claim,[,r]=u.useReducer(h=>h+1,0),o=a&&!e.view_outdated?new Date(a.lease_expires_at).getTime():null;u.useEffect(()=>{if(o===null||!Number.isFinite(o))return;const h=o-Date.now();if(h<=0)return;const f=setTimeout(r,Math.min(h+50,2147483647));return()=>clearTimeout(f)},[o]);let l=i.jsx(yv,{className:"size-4","aria-hidden":"true"}),c="Nobody is working on this",d=null;if(e.view_outdated)c=`Claimed by: ${LD}`;else if(a){const h=new Date(a.lease_expires_at)<=new Date(Math.max(Date.now(),new Date(s).getTime()));l=i.jsx(pv,{className:"size-4","aria-hidden":"true"}),c=`${t} is working on this until ${As(a.lease_expires_at)}${h||a.lapsed?" · passed":""}`,d="Claimed in the coordination registry; its thread renews the claim."}else n&&(l=i.jsx(of,{className:"size-4","aria-hidden":"true"}),d=`Finished ${Rs(n)}. Its claim ended when it finished.`);return i.jsxs(yt,{className:"mt-4 flex flex-wrap items-center gap-3 p-3","data-testid":"task-claim",children:[l,i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-medium",children:c}),d?i.jsx("div",{className:"text-muted-foreground text-xs break-words",children:d}):null]})]})}function P3({detail:e,waits:t,given:n,threadName:s,threadsLink:a}){if(e.view_outdated)return i.jsx(Yt,{id:"task-holds",title:"Holds",children:i.jsx("p",{className:"text-sm",children:LD})});if(e.holds.length===0)return null;const r=new Map(t.map(o=>[o.id,o]));return i.jsxs(Yt,{id:"task-holds",title:`Holds · ${e.holds.length} open`,children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:"A hold does not change the task's status."}),i.jsx(yt,{className:"mt-2 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Holds",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Type"}),i.jsx(Q,{children:"Reason"}),i.jsx(Q,{children:"Waiting on"}),i.jsx(Q,{children:"Opened"})]})}),i.jsx(st,{children:e.holds.map(o=>{var h;const l=r.get(o.id),c=zc[o.hold_type],d=n?"Done above answers it":l!=null&&l.local_done?"In Waiting on you":(h=l==null?void 0:l.local_threads)!=null&&h.length?i.jsxs(i.Fragment,{children:["Answer it in ",a,": ",l.local_threads.join(" · ")]}):null;return i.jsxs(_e,{"data-testid":"task-hold",children:[i.jsx(X,{children:i.jsx(we,{variant:c.tone,children:(l==null?void 0:l.local_label)??c.label})}),i.jsxs(X,{children:[i.jsx("div",{children:o.reason}),i.jsxs("div",{className:"text-muted-foreground text-xs",children:["Opened by ",s(o.opened_by)]})]}),i.jsxs(X,{children:[i.jsx("div",{children:o.target.kind==="user"?"You":o.target.kind==="external"?o.target.label:"Another task"}),d?i.jsx("div",{className:"text-muted-foreground text-xs",children:d}):null]}),i.jsx(X,{children:rb(o.opened_at)})]},o.id)})})]})})]})}function I3({time:e}){return i.jsx(Yt,{id:"task-time",title:"Time",children:i.jsxs("dl",{className:"grid gap-4 sm:grid-cols-3",children:[i.jsx(ai,{label:"Estimate",value:e.estimate?`${El(e.estimate.low)}–${El(e.estimate.high)}`:e.unknown_reason??"None"}),i.jsx(ai,{label:"Time taken",value:e.elapsed!==null?`${El(e.elapsed)}${e.over_estimate?" · over estimate":""}`:"Not started"}),e.forecast?i.jsx(ai,{label:"Reforecast",value:i.jsxs("span",{className:"text-muted-foreground",children:[El(e.forecast.low),"–",El(e.forecast.high)," left",e.forecast.reason?` · ${e.forecast.reason}`:""]})}):null]})})}function db({what:e,again:t,refusal:n,on_retry:s}){const a=MD();return i.jsxs(pe,{variant:"destructive",ref:a,children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Could not read ",e]}),i.jsxs(ge,{children:[i.jsx("p",{children:n.message}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:s,children:t})]})]})}function G3({sections:e,heading_ref:t,on_retry:n,taskLink:s}){const[a,r]=u.useState(!1);if(e.state==="loading")return null;const o=e.state==="failed"?e.refusal:e.data.graph.ok?null:e.data.graph.refusal;if(o)return i.jsx(Yt,{id:"task-graph",title:"Graph changes",heading_ref:t,children:i.jsx(db,{what:"graph changes",again:"Read graph changes again",refusal:o,on_retry:n})});const l=e.state==="ok"&&e.data.graph.ok?e.data.graph.data:null;if(!l)return null;if(l.exempt)return i.jsx(Yt,{id:"task-graph",title:"Graph changes",heading_ref:t,children:i.jsxs("p",{className:"text-sm",children:["This task changes no modeled design. Its plan says why: ",l.exempt,"."]})});if(l.changes.length===0)return null;const c=a?l.changes:l.changes.slice(0,$D),d=l.changes.length-c.length;return i.jsxs(Yt,{id:"task-graph",title:"Graph changes",aside:l.document,heading_ref:t,children:[i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Graph changes",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Change"}),i.jsx(Q,{children:"Kind of change"}),i.jsx(Q,{children:"Also in"}),i.jsx(Q,{children:"In the plan"})]})}),i.jsx(st,{children:c.map(h=>i.jsxs(_e,{children:[i.jsxs(X,{children:[i.jsx("div",{children:h.label}),i.jsx("div",{className:"text-muted-foreground text-xs",children:h.type})]}),i.jsx(X,{children:O3[h.change]}),i.jsx(X,{children:h.also_in.length===0?"No other task":h.also_in.map((f,m)=>i.jsxs(u.Fragment,{children:[m>0?", ":null,s(f.id)]},f.id))}),i.jsx(X,{children:h.planned?"Yes":i.jsx(we,{variant:"warning",children:"No longer planned"})})]},`${h.id}:${h.planned}`))})]})}),d>0?i.jsxs("p",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[d," more changes in this task's plan slice.",i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!0),children:["Show all ",l.changes.length]})]}):null]})}function H3({files:e,finished:t}){const[n,s]=u.useState(!1),a=n?e.paths:e.paths.slice(0,$D);return i.jsxs(Yt,{id:"task-files",title:"Files",children:[a.length>0?i.jsx("ul",{className:"grid gap-1 text-sm",children:a.map(r=>i.jsx("li",{children:i.jsx("span",{className:"font-mono break-all",children:r})},r))}):null,e.paths.length>a.length?i.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"mt-1",onClick:()=>s(!0),children:["Show all ",e.paths.length]}):null,e.landed?i.jsxs("p",{className:"mt-2 text-sm",children:["Landed ",i.jsx("span",{className:"font-mono",children:e.landed.sha.slice(0,10)})," · ",e.landed.files," files",t?"":" · becomes the proof when the task finishes"]}):null]})}function V3({proof:e,finished_at:t,who:n}){return i.jsxs(Yt,{id:"task-proof",title:"Evidence and proof",children:[e.evidence?i.jsx("p",{className:"text-sm whitespace-pre-wrap",children:e.evidence}):null,e.no_code?i.jsxs("p",{className:"mt-2 text-sm",children:["No code: ",e.no_code]}):e.commit?i.jsxs("p",{className:"mt-2 text-sm",children:["Proof ",i.jsx("span",{className:"font-mono",children:e.commit.slice(0,10)})," ·"," ",e.on_main?"on main":"not yet on main"]}):null,t?i.jsxs("p",{className:"text-muted-foreground mt-2 text-xs",children:["Finished ",Rs(t),n?` by ${n}`:""]}):null]})}function U3({history:e}){return i.jsxs(Yt,{id:"task-history",title:"History",children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:"From the task record, newest first"}),i.jsx(yt,{className:"mt-2 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"History",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"What"}),i.jsx(Q,{children:"Who"}),i.jsx(Q,{children:"When"})]})}),i.jsx(st,{children:e.map((t,n)=>i.jsxs(_e,{children:[i.jsx(X,{children:t.what}),i.jsx(X,{children:t.who??"Its thread"}),i.jsx(X,{children:rb(t.at)})]},`${t.at}:${n}`))})]})})]})}function ID({id:e="task-related",related:t,heading_ref:n,on_retry:s,link:a,fixed:r=!1}){return t.state==="ok"&&t.data.length===0?null:i.jsx(Yt,{id:e,title:"Related",heading_ref:n,children:t.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"})]}):t.state==="failed"?i.jsx(db,{what:"related work",again:"Read related work again",refusal:t.refusal,on_retry:s}):i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Related",className:r?"table-fixed":void 0,children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{className:r?"w-[14%]":void 0,children:"Kind"}),i.jsx(Q,{className:r?"w-[45%]":void 0,children:"Item"}),i.jsx(Q,{className:r?"w-[41%]":void 0,children:"How it relates"})]})}),i.jsx(st,{children:t.data.map(o=>i.jsxs(_e,{children:[i.jsx(X,{children:z3[o.kind]}),i.jsx(X,{className:r?"break-words":void 0,children:a(o)}),i.jsx(X,{className:r?"break-words":void 0,children:o.relation})]},`${o.kind}:${o.planned?"planned:":""}${o.id}`))})]})})})}function B3({org:e,task_id:t,from:n}){const s=jd(),a=`/org/${e}/tasks`;return s.taskSections?i.jsx($3,{org:e,task_id:t,from:n??null}):i.jsx(W3,{task_id:t,back:a})}function W3({task_id:e,back:t}){const{availability:n}=jd(),[s,a]=u.useState({state:"loading"});return u.useEffect(()=>{let r=!0;return n().then(o=>{r&&a(o)}),()=>{r=!1}},[n]),s.state==="off"?i.jsx(kh,{back:t}):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:s.state==="active"?i.jsx(D3,{active:s,task_id:e,back:t}):s.state==="error"?i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This task could not be loaded"}),i.jsx(ge,{children:"Check your connection and try again."})]}):s.state==="available"?i.jsx(kh,{back:t}):i.jsx(lb,{})})}function Kn({children:e}){return i.jsx("p",{role:"alert",className:"text-destructive text-sm",children:e})}const F3=["open","triaged","resolved","closed"],ub=["low","normal","high","urgent"],q3=["fixed","works_as_intended","planned","duplicate","wont_fix","cannot_reproduce"],Y3=["title","description","external_reference"],Sh={open:"Open",triaged:"Triaged",escalated:"Escalated",waiting_on_fix:"Waiting on fix",resolved:"Resolved",closed:"Closed"},GD={open:"warning",triaged:"info",escalated:"info",waiting_on_fix:"info",resolved:"success",closed:"neutral"},Mc={low:"Low",normal:"Normal",high:"High",urgent:"Urgent"},hb={fixed:"Fixed",works_as_intended:"Works as intended",planned:"Planned",duplicate:"Duplicate",wont_fix:"Won't fix",cannot_reproduce:"Cannot reproduce"},HD={title:"Title",description:"Description",external_reference:"External reference"},X3=[["year",365*24*3600],["month",30*24*3600],["week",7*24*3600],["day",24*3600],["hour",3600],["minute",60]];function Au(e,t=Date.now()){const n=Math.round((new Date(e).getTime()-t)/1e3),s=new Intl.RelativeTimeFormat("en",{numeric:"auto"});for(const[a,r]of X3)if(Math.abs(n)>=r)return s.format(Math.round(n/r),a);return"just now"}function Bg(e,t,n){const s=`/org/${encodeURIComponent(e)}/proj/${encodeURIComponent(t)}/support`;return n?`${s}/${encodeURIComponent(n)}`:s}function fb(e,t){return e?t??"Not available":"A former member"}const K3="the issue integration";function Z3(e){return!e.created_by&&e.reporter_kind==="customer"?K3:fb(e.created_by,e.created_by_username)}function Q3(e,t){return!e.actor_id&&e.kind==="created"&&t.reporter_kind==="customer"?"The issue integration":fb(e.actor_id,e.actor_username)}const Zd="not_set",J3="Do not paste personal data. Leave out names, such as borrower names, and loan numbers; text shaped like an email address, phone number, or social security number is refused.";function eG({create:e,open:t,onOpenChange:n,onCreated:s}){const[a,r]=u.useState(""),[o,l]=u.useState(""),[c,d]=u.useState(!1),[h,f]=u.useState(""),[m,p]=u.useState(Zd),[y,g]=u.useState(!1),[b,v]=u.useState(null),x=u.useRef(null),w=()=>{r(""),l(""),d(!1),f(""),p(Zd),v(null),x.current=null},_=j=>{var N;return((N=b==null?void 0:b.personal_data)==null?void 0:N.field)===j?b.message:void 0},S=async j=>{if(j.preventDefault(),y)return;g(!0),x.current??(x.current=crypto.randomUUID());const N=await e({request_id:x.current,title:o.trim()||void 0,description:h||void 0,external_reference:a.trim()||void 0,priority:m===Zd?null:m});if(g(!1),!N.ok){N.refusal.status!==0&&(x.current=null),v(N.refusal);return}w(),s(N.data.issue,N.data.duplicates)},k=b&&!b.personal_data?b.message:void 0;return i.jsx(yn,{open:t,onOpenChange:j=>{j||w(),n(j)},children:i.jsx(wn,{className:"sm:max-w-2xl",children:i.jsxs("form",{onSubmit:S,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"New support issue"}),i.jsx(kn,{children:"Log one help-desk report. Text is shown exactly as entered."})]}),i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{}),i.jsx(ge,{children:J3})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-reference",children:"External reference"}),i.jsx(bt,{id:"maintain-issue-reference",value:a,"aria-invalid":!!_("external_reference"),onChange:j=>{r(j.target.value),c||l(j.target.value)}}),_("external_reference")?i.jsx(Kn,{children:_("external_reference")}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"The help-desk ticket number."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-title",children:"Title"}),i.jsx(bt,{id:"maintain-issue-title",value:o,"aria-invalid":!!_("title"),onChange:j=>{l(j.target.value),d(!0)}}),_("title")?i.jsx(Kn,{children:_("title")}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"Prefilled from the external reference; edit it if you like."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-description",children:"Description"}),i.jsx(Gn,{id:"maintain-issue-description",rows:4,placeholder:"What the end user reported, without personal data",value:h,"aria-invalid":!!_("description"),onChange:j=>f(j.target.value)}),_("description")?i.jsx(Kn,{children:_("description")}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-priority",children:"Priority"}),i.jsxs(St,{value:m,onValueChange:p,children:[i.jsx(wt,{id:"maintain-issue-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Zd,children:"Not set"}),ub.map(j=>i.jsx(Ue,{value:j,children:Mc[j]},j))]})]})]}),k?i.jsx(Kn,{children:k}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>{w(),n(!1)},children:"Cancel"}),i.jsx(U,{type:"submit",loading:y,disabled:!o.trim()&&!a.trim(),children:"Log issue"})]})]})})})}const tG=["supportAccess","assigneeCandidates","create","update","assign","transition","redact"];function VD(){return nG(Vn().issues)}function nG(e){return e&&tG.every(t=>typeof e[t]=="function")?e:null}function UD(e){const[t,n]=u.useState(null);return u.useEffect(()=>{if(!e)return;let s=!1;return e.supportAccess().then(a=>{s||n({contract:e,state:a.ok?{state:"ready",access:a.data}:{state:"error"}})}),()=>{s=!0}},[e]),t&&e&&t.contract===e?t.state:{state:"loading"}}function BD({access:e,header:t,back_href:n,children:s}){const{href:a,Link:r}=lt();return e.state==="loading"?i.jsxs("div",{className:"flex flex-1 items-center justify-center py-24",children:[i.jsx(vn,{className:"size-5"}),i.jsx("span",{className:"sr-only",children:"Loading…"})]}):e.state==="error"||!e.access.enabled?i.jsx(Ha,{title:"Page not found",description:"This page does not exist or you do not have access to it.",backHref:a(n),backLabel:"Back to the project",link:r}):e.access.can_view?i.jsx(i.Fragment,{children:s(e.access)}):i.jsxs(i.Fragment,{children:[t,i.jsxs("div",{className:"flex flex-col items-center gap-3 py-24 text-center",children:[i.jsx(FO,{className:"text-muted-foreground size-8","aria-hidden":!0}),i.jsx("h2",{className:"text-lg font-semibold",children:"Support needs a Maintain seat"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:e.access.seat?"You need read permission on this project to see its support issues; ask an organization admin.":"You need a Maintain seat to see this project's support issues; ask an organization admin."})]})]})}function WD(){const e=lt();return t=>{e.navigate?e.navigate(t):window.location.assign(e.href(t))}}const rs="all",Qd=25;function Wg({action:e}){return i.jsx(bn,{title:"Support",description:"Help-desk reports logged against this project.",actions:e})}function sG({org:e,project:t,query:n}){const s=VD(),a=UD(s),r=`/org/${e}/proj/${t}`;return i.jsx("div",{className:"flex w-full flex-1 flex-col gap-6 px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(BD,{access:a,header:i.jsx(Wg,{}),back_href:r,children:o=>s?i.jsx(iG,{contract:s,access:o,org_name:e,proj_name:t,query:n}):null})})}function iG({contract:e,access:t,org_name:n,proj_name:s,query:a}){const{href:r,Link:o}=lt(),l=WD(),[c,d]=u.useState(()=>new URLSearchParams(a).get("external_reference")??""),[h,f]=u.useState(rs),[m,p]=u.useState(rs),[y,g]=u.useState(rs),[b,v]=u.useState(0),[x,w]=u.useState(null),[_,S]=u.useState(0),[k,j]=u.useState(null),[N,O]=u.useState([]),[T,I]=u.useState(!1),L=c.trim()!==""||h!==rs||m!==rs||y!==rs,$=u.useCallback(async()=>{const C=await e.list({external_reference:c.trim()||void 0,status:h===rs?void 0:h,priority:m===rs?void 0:m,assignee:y===rs?void 0:y,limit:Qd,offset:b*Qd});if(!C.ok){j(C.refusal.message);return}j(null),w(C.data.issues),S(C.data.total)},[e,c,h,m,y,b]);u.useEffect(()=>{const C=setTimeout(()=>void $(),200);return()=>clearTimeout(C)},[$]),u.useEffect(()=>{e.assigneeCandidates().then(C=>{C.ok&&O(C.data.candidates)})},[e]);const A=t.can_change?i.jsxs(U,{onClick:()=>I(!0),children:[i.jsx(za,{className:"mr-2 size-4"}),"New issue"]}):void 0,D=i.jsx(eG,{create:e.create,open:T,onOpenChange:I,onCreated:(C,M)=>{I(!1);const H=Bg(n,s,C.id);l(M.length?`${H}?duplicates=${M.length}`:H)}});if(x!==null&&_===0&&!L&&b===0)return i.jsxs(i.Fragment,{children:[i.jsx(Wg,{}),i.jsxs("div",{className:"flex flex-col items-center gap-3 py-24 text-center",children:[i.jsx(GO,{className:"text-muted-foreground size-8","aria-hidden":!0}),i.jsx("h2",{className:"text-lg font-semibold",children:"No support issues yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Log a help-desk report under its ticket number, so every report is counted once."}),t.can_change?i.jsxs(U,{onClick:()=>I(!0),children:[i.jsx(za,{className:"mr-2 size-4"}),"Log the first issue"]}):null]}),D]});const E=_===0?0:b*Qd+1,R=Math.min(_,(b+1)*Qd);return i.jsxs(i.Fragment,{children:[i.jsx(Wg,{action:A}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsxs("div",{className:"relative w-full max-w-sm",children:[i.jsx(hz,{className:"text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2","aria-hidden":!0}),i.jsx(bt,{"aria-label":"Filter by external reference",placeholder:"Filter by external reference",className:"pl-9",value:c,onChange:C=>{d(C.target.value),v(0)}})]}),i.jsx(op,{label:"Status",value:h,onChange:C=>{f(C),v(0)},options:F3.map(C=>({value:C,label:Sh[C]}))}),i.jsx(op,{label:"Priority",value:m,onChange:C=>{p(C),v(0)},options:ub.map(C=>({value:C,label:Mc[C]}))}),i.jsx(op,{label:"Assignee",value:y,onChange:C=>{g(C),v(0)},options:[{value:"unassigned",label:"Unassigned"},{value:"cannot_act",label:"Assignee cannot act"},...N.map(C=>({value:C.user_id,label:C.username??"Not available"}))]})]}),k?i.jsx(Kn,{children:k}):null,i.jsx("div",{className:"rounded-md border",children:i.jsxs(nt,{children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Title"}),i.jsx(Q,{children:"External reference"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Priority"}),i.jsx(Q,{children:"Assignee"}),i.jsx(Q,{children:"Updated"})]})}),i.jsx(st,{children:x===null?i.jsx(_e,{children:i.jsx(X,{colSpan:6,className:"h-24 text-center",children:"Loading…"})}):x.length===0?i.jsx(_e,{children:i.jsx(X,{colSpan:6,className:"h-24 text-center",children:"No issues match these filters."})}):x.map(C=>i.jsxs(_e,{children:[i.jsx(X,{className:"max-w-md",children:i.jsx(o,{href:r(Bg(n,s,C.id)),className:"font-medium hover:underline",children:C.title})}),i.jsx(X,{className:"font-mono text-xs",children:C.external_reference??""}),i.jsx(X,{children:i.jsx(we,{variant:GD[C.status],children:Sh[C.status]})}),i.jsx(X,{children:C.priority?Mc[C.priority]:""}),i.jsx(X,{children:i.jsx(aG,{issue:C})}),i.jsx(X,{className:"text-muted-foreground",children:Au(C.updated_at)})]},C.id))})]})}),i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-muted-foreground text-sm",children:_===0?"No issues.":`Showing ${E}–${R} of ${_} issue${_===1?"":"s"}.`}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(U,{variant:"outline",size:"sm",disabled:b===0,onClick:()=>v(C=>Math.max(0,C-1)),children:"Previous"}),i.jsx(U,{variant:"outline",size:"sm",disabled:R>=_,onClick:()=>v(C=>C+1),children:"Next"})]})]}),D]})}function aG({issue:e}){return e.assignee_id?i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{children:e.assignee_username??"Not available"}),e.assignee_can_act===!1?i.jsx(we,{variant:"error",children:"Assignee cannot act"}):null]}):i.jsx("span",{className:"text-muted-foreground",children:"Unassigned"})}function op({label:e,value:t,onChange:n,options:s}){var r;const a=u.useMemo(()=>t===rs||s.some(o=>o.value===t),[s,t]);return i.jsxs(St,{value:a?t:rs,onValueChange:n,children:[i.jsx(wt,{className:"w-44","aria-label":e,children:i.jsx(Ct,{placeholder:e,children:t===rs?e:(r=s.find(o=>o.value===t))==null?void 0:r.label})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:rs,children:"All"}),s.map(o=>i.jsx(Ue,{value:o.value,children:o.label},o.value))]})]})}function Wi(e,t){u.useEffect(()=>{const n=setInterval(()=>{document.visibilityState==="visible"&&e("tick")},t),s=()=>{document.visibilityState==="visible"&&e("shown")};return document.addEventListener("visibilitychange",s),()=>{clearInterval(n),document.removeEventListener("visibilitychange",s)}},[e,t])}const rG=5e3;function Ts(){const e=u.useRef(0),t=u.useRef(null);return u.useEffect(()=>()=>{t.current!==null&&clearTimeout(t.current)},[]),u.useMemo(()=>({owed:()=>e.current>0,busy:()=>e.current>0||t.current!==null,track:async n=>{e.current+=1;try{return await n}finally{e.current-=1,t.current!==null&&clearTimeout(t.current),t.current=setTimeout(()=>{t.current=null},rG)}}}),[])}function Uf(e,t){return n=>{(n==="shown"?e.owed():e.busy())||t()}}const FD=[{key:"local",label:"Local"},{key:"staging",label:"Staging"},{key:"production",label:"Production"}],oG=/^iss-\d{1,9}$/,lG=/^col-\d{1,9}$/,cG=e=>e&&e[0].toUpperCase()+e.slice(1);function qD(e){const t=cG(e.status_word??e.status.replace(/_/g," ")),n=e.group??(e.status==="resolved"?"resolved":"unplaced");return n==="resolved"?{label:t,tone:e.resolution_reason==="fixed"?"success":"neutral"}:n==="unowned"||n==="routed"?{label:t,tone:"warning"}:n==="fixing"?{label:t,tone:"info"}:{label:t,tone:"neutral"}}function lc(e,t=Date.now()){if(!e)return"";const n=Math.max(0,(t-Date.parse(e))/1e3);return Number.isFinite(n)?n<60?"just now":n<3600?`${Math.round(n/60)}m ago`:n<86400?`${Math.round(n/3600)}h ago`:`${Math.round(n/86400)}d ago`:""}const Fg={search:"",owner:null,urgent:!1,seen:[],label:null,collection:null};function Ru(e){const t=new URLSearchParams(e),n=t.getAll("seen").filter(a=>FD.some(r=>r.key===a)),s=t.get("collection");return{search:t.get("search")??"",owner:t.get("owner")||null,urgent:t.get("urgent")==="1",seen:[...new Set(n)],label:t.get("label")||null,collection:s&&lG.test(s)?s:null}}function mb(e){const t=new URLSearchParams;e.search&&t.set("search",e.search),e.owner&&t.set("owner",e.owner),e.urgent&&t.set("urgent","1");for(const n of e.seen)t.append("seen",n);return e.label&&t.set("label",e.label),e.collection&&t.set("collection",e.collection),t.toString()}const YD=new Set(["resolved"]),lp=10,dG=new Set(["unplaced","unowned","routed","fixing","resolved"]),uG=["open","fold","all"];function XD(e){const t=new URLSearchParams(e),n=s=>[...new Set(t.getAll(s).filter(a=>dG.has(a)))];return{open:n("open"),fold:n("fold"),all:n("all")}}const hG=(e,t)=>YD.has(t)?!e.open.includes(t):e.fold.includes(t);function fG(e,t,n){const s=e.open.filter(o=>o!==t),a=e.fold.filter(o=>o!==t),r=YD.has(t);return n&&!r&&a.push(t),!n&&r&&s.push(t),{...e,open:s,fold:a}}const mG=(e,t,n)=>({...e,all:n?[...e.all.filter(s=>s!==t),t]:e.all.filter(s=>s!==t)});function eo(e,t){const n=new URLSearchParams(mb(e));for(const s of uG)for(const a of t[s])n.append(s,a);return n.toString()}function pG(e){return{search:e.search.trim()||void 0,owner:e.owner??void 0,urgent:e.urgent||void 0,seen:e.seen.length?e.seen:void 0,label:e.label?[e.label]:void 0,collection:e.collection??void 0}}const n_=e=>!!(e.search.trim()||e.owner||e.urgent||e.seen.length||e.label||e.collection),gG={agent:"Filed by an agent",user:"Filed by you",tool:"Filed by a tool"},xG={graph:"Placed on the graph by its anchors",files:"Placed by its files",unplaced:"Triaged, not placed yet"},vG={handoff:"Handed to its owner",backlog:"Sent to the unowned backlog",batch:"Routed to a batch"};function bG(e,t=""){const n=(e??t).trim();if(!n)return"";const s=n.indexOf(": "),a=(s===-1?n:n.slice(0,s)).trim(),r=s===-1?"":n.slice(s+2).trim(),o=l=>r?`${l} ${r}`:l;switch(a){case"filed":return gG[r]??o("Filed by");case"labelled":return o("Labelled");case"unlabelled":return r?`Label removed: ${r}`:"Label removed";case"anchored":return r?`Anchored to ${r}`:"Anchored";case"triaged":return xG[r]??(r?`Triaged: ${r}`:"Triaged");case"routed":return vG[r]??(r?`Routed: ${r}`:"Routed");case"route closed":return r==="backlog"?"Taken off the unowned backlog":r?`Route closed: ${r}`:"Route closed";case"released":return r?`Released by its owner (task ${r})`:"Released by its owner";case"resolved":return r==="duplicate"?"Resolved as a duplicate":r?`Resolved · ${r.replace(/_/g," ")}`:"Resolved";case"reopened":return r?`Reopened: ${r}`:"Reopened";case"fix landed":return r?`Fix landed in ${r.slice(0,10)}`:"Fix landed";case"merged":return r?`Merged ${r} into this issue`:"Merged a duplicate into this issue";default:return n}}const yG=e=>e.replace(/`+/g,"").replace(/\s+/g," ").trim(),s_={report:{title:"Triage places what you report",body:"Report an issue here and triage places it and suggests an owner. Route and resolve issues with the issue command or through the thread working on them."},read_only:{title:"This page only reads issues",body:"File, route and resolve issues with the issue command or through the thread working on them."}},i_={title:"This page only reads issues",body:"Route and resolve issues with the issue command or through the thread working on them."},wG=e=>e?"Issues you report here, or file with the issue command, appear here.":"Issues filed in this repository with the issue command appear here.";function KD(e){const t=new Set;for(const n of e.split(",")){const s=n.trim().toLowerCase().replace(/[\s_]+/g,"-");s&&t.add(s)}return[...t]}const _G=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,a_=40,qg=10,r_=40,jG=200,cp="not_set",ZD=[{value:"not_set",label:"Not set"},{value:"local",label:"Local"},{value:"staging",label:"Staging"},{value:"production",label:"Production"}],Ln={title:"Report an issue",description:"Triage places it and suggests an owner; you'll see where it went.",needs_what:"Say what is wrong to report it.",refused:"The issue was not reported",kept:"Your draft is kept: report it again.",maybe_filed:"The report may have been filed",timeout:"The issue command did not answer within 1 minute, so the report may have been filed. Look for it in the list before you report it again.",failed:"The issue command failed, so the report may have been filed. Look for it in the list before you report it again; the sdlc viewer terminal says what failed.",kept_only:"Your draft is kept.",too_long:"The report is too long to send; shorten What happens or What should happen.",no_answer:"The viewer did not answer.",reporting:"Reporting…"},po={what:"",actual:"",expected:"",env:"not_set",shows:"",collection:"",ref:"",labels:""},Yg=e=>`sdlc.issue-report-draft:${e}`;function NG(e){try{const t=JSON.parse(window.sessionStorage.getItem(Yg(e))??"null");if(!t||typeof t!="object")return po;const n={...po};for(const s of Object.keys(po))typeof t[s]=="string"&&(n[s]=t[s]);return ZD.some(s=>s.value===n.env)||(n.env="not_set"),n}catch{return po}}function dp(e,t){try{t?window.sessionStorage.setItem(Yg(e),JSON.stringify(t)):window.sessionStorage.removeItem(Yg(e))}catch{}}function kG(e){const t=KD(e);if(t.length>qg)return`At most ${qg} labels; this has ${t.length}.`;const n=t.find(s=>!_G.test(s)||s.length>a_);return n?`'${n}' is not a label: use a-z, 0-9 and single hyphens, at most ${a_} characters.`:null}function SG(e){return e.status===504||e.code==="timeout"?Ln.timeout:e.status===500?Ln.failed:e.status===413?Ln.too_long:[400,422].includes(e.status)&&e.message?e.message:Ln.no_answer}function up(e){return e===Ln.timeout||e===Ln.failed}function CG(e){const t={what:e.what.trim()};e.actual.trim()&&(t.actual=e.actual),e.expected.trim()&&(t.expected=e.expected),e.env!=="not_set"&&(t.env=e.env),e.shows.trim()&&(t.shows=e.shows.trim()),e.collection&&(t.collection=e.collection,e.ref.trim()&&(t.ref=e.ref.trim()));const n=KD(e.labels);return n.length&&(t.labels=n.join(",")),t}function DG({project:e,report:t,reportCollections:n,open:s,onOpenChange:a,onFiled:r,onMaybeFiled:o}){const[l,c]=u.useState(po),[d,h]=u.useState(null),[f,m]=u.useState(!1),[p,y]=u.useState(null),[g,b]=u.useState(null),v=u.useRef(null),x=u.useRef(null),w=u.useRef(null),_=u.useRef(!1),S=u.useId(),k=A=>`${S}-report-${A}`;u.useEffect(()=>{if(!s||(c(NG(e)),y(null),b(null),h(null),!n))return;let A=!0;return n().then(D=>{A&&h(D.ok?D.data.collections:[])}),()=>{A=!1}},[s,e,n]);const j=A=>c(D=>{const E={...D,...A};return dp(e,E),E}),N=u.useMemo(()=>{const A=d??[];return l.collection&&!A.some(D=>D.collection===l.collection)?[...A,{collection:l.collection,title:l.collection}]:A},[d,l.collection]),O=N.length>0,T=A=>{f||(A&&dp(e,null),a(!1))},I=async A=>{var R,C;if(A.preventDefault(),_.current)return;if(!l.what.trim()){(R=v.current)==null||R.focus();return}const D=kG(l.labels);if(b(D),D){(C=x.current)==null||C.focus();return}_.current=!0,m(!0),y(null);const E=await t(CG(l));if(_.current=!1,m(!1),!E.ok){const M=SG(E.refusal);y(M),up(M)&&(o==null||o());return}dp(e,null),c(po),a(!1),r(E.data)};u.useEffect(()=>{var A,D,E;p&&((D=(A=w.current)==null?void 0:A.scrollIntoView)==null||D.call(A,{block:"nearest"}),(E=v.current)==null||E.focus())},[p]);const L=!l.what.trim(),$=[k("what-help"),p?k("refused"):null].filter(Boolean).join(" ");return i.jsx(yn,{open:s,onOpenChange:A=>A?a(!0):T(!1),children:i.jsx(wn,{className:"max-h-[90vh] overflow-y-auto sm:max-w-2xl",onOpenAutoFocus:A=>{var D;A.preventDefault(),(D=v.current)==null||D.focus()},children:i.jsxs("form",{onSubmit:I,className:"grid gap-4",noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:Ln.title}),i.jsx(kn,{children:Ln.description})]}),p?i.jsxs(pe,{ref:w,variant:"destructive",id:k("refused"),children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:up(p)?Ln.maybe_filed:Ln.refused}),i.jsxs(ge,{children:[/[.!?]$/.test(p)?p:`${p}.`," ",up(p)?Ln.kept_only:Ln.kept]})]}):null,i.jsxs("fieldset",{disabled:f,className:"grid min-w-0 gap-4",children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsxs(Ie,{htmlFor:k("what"),children:["What is wrong ",i.jsx("span",{"aria-hidden":"true",children:"*"})]}),i.jsx(bt,{id:k("what"),ref:v,"aria-required":"true",maxLength:jG,placeholder:"One line: what you saw",value:l.what,"aria-describedby":$,onChange:A=>j({what:A.target.value})}),i.jsx("p",{id:k("what-help"),className:"text-muted-foreground text-xs",children:"It becomes the issue's title."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("actual"),children:"What happens"}),i.jsx(Gn,{id:k("actual"),rows:3,placeholder:"What you see, step by step",value:l.actual,onChange:A=>j({actual:A.target.value})})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("expected"),children:"What should happen"}),i.jsx(Gn,{id:k("expected"),rows:3,placeholder:"What you expected instead",value:l.expected,onChange:A=>j({expected:A.target.value})})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("env"),children:"Where you saw it"}),i.jsxs(St,{value:l.env,disabled:f,onValueChange:A=>j({env:A}),children:[i.jsx(wt,{id:k("env"),children:i.jsx(Ct,{})}),i.jsx(_t,{children:ZD.map(A=>i.jsx(Ue,{value:A.value,children:A.label},A.value))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("shows"),children:"Shows in"}),i.jsx(bt,{id:k("shows"),placeholder:"packages/app/page.tsx or Report button",value:l.shows,"aria-describedby":k("shows-help"),onChange:A=>j({shows:A.target.value})}),i.jsx("p",{id:k("shows-help"),className:"text-muted-foreground text-xs",children:"A file path in this repository, or the words you saw on the screen."})]}),O?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("collection"),children:"Collection"}),i.jsxs(St,{value:l.collection||cp,disabled:f,onValueChange:A=>j({collection:A===cp?"":A}),children:[i.jsx(wt,{id:k("collection"),children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:cp,children:"Not set"}),N.map(A=>i.jsx(Ue,{value:A.collection,children:A.title===A.collection?A.collection:`${A.title} (${A.collection})`},A.collection))]})]})]}):null,O&&l.collection?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("ref"),children:"Place in the collection"}),i.jsx(bt,{id:k("ref"),maxLength:r_,placeholder:"Like item 5",value:l.ref,"aria-describedby":k("ref-help"),onChange:A=>j({ref:A.target.value})}),i.jsxs("p",{id:k("ref-help"),className:"text-muted-foreground text-xs",children:["At most ",r_," characters."]})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("labels"),children:"Labels"}),i.jsx(bt,{id:k("labels"),ref:x,placeholder:"viewer, report form",value:l.labels,"aria-invalid":g?!0:void 0,"aria-describedby":k(g?"labels-error":"labels-help"),onChange:A=>{j({labels:A.target.value}),g&&b(null)}}),g?i.jsx("div",{id:k("labels-error"),children:i.jsx(Kn,{children:g})}):i.jsxs("p",{id:k("labels-help"),className:"text-muted-foreground text-xs",children:["Up to ",qg," words to find it by, separated by commas."]})]})]}),i.jsx("p",{id:k("needs-what"),className:"sr-only",children:Ln.needs_what}),i.jsx("div",{role:"status","aria-live":"polite",className:"sr-only",children:f?Ln.reporting:""}),i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",disabled:f,onClick:()=>T(!0),children:"Cancel"}),i.jsx(U,{type:"submit",loading:f,"aria-disabled":L?!0:void 0,"aria-describedby":k("needs-what"),children:f?Ln.reporting:"Report"})]})]})})})}function EG(e,t){const n=new URLSearchParams(e).get("reported");return n&&(n===`Seen before: added to ${t}`||n.startsWith(`Filed ${t} · `)&&n.length<=200&&!/[\n\r]/.test(n))?n:null}const AG=10,QD=1e4,RG=250,Wr="__all",TG="none",OG=e=>e.status===0||e.reason==="store_locked"||e.reason==="engine_failed"||e.status>=500;function JD(){const e=Vn().issues;if(!e)throw new Error("The Issues page rendered without the issues seam.");return e}const zG=e=>({read_at:e,scope:"project",folder:null,groups:[],facets:{owners:[],labels:[],urgent:0,seen:{local:0,staging:0,production:0}},listed:0,collections:[]});function MG({org:e,project:t,query:n,onQuery:s}){var $e,ze;const a=JD(),r=($e=a.commands)==null?void 0:$e.open_thread,o=u.useMemo(()=>r?{org:e,open_thread:r}:void 0,[e,r]),{href:l,Link:c}=lt(),d=WD(),[h,f]=u.useState(!1),m=u.useMemo(()=>Ru(n),[n]),p=u.useMemo(()=>XD(n),[n]),y=mb(m),g=n_(m),b=eo(m,p),[v,x]=u.useState({state:"loading"}),[w,_]=u.useState(null),[S,k]=u.useState(null),j=u.useRef(0),N=u.useRef(0),O=u.useRef(null),T=u.useRef(null),I=ns(),L=u.useRef(!1),[$,A]=u.useState(m.search),D=u.useCallback(q=>s(eo({...m,...q},p)),[m,p,s]),E=u.useCallback(q=>s(eo(m,q)),[m,s]),R=Ts(),C=u.useCallback(async()=>{const q=N.current+=1;k(null);const ve=await R.track(a.list(pG(Ru(y))));if(q!==N.current)return;if(ve.ok){j.current=0,_(null),x({state:"ok",list:ve.data,local:ve.data.local??zG(new Date().toISOString()),key:y});return}const Ve=ve.refusal.reason;if(Ve==="engine_missing")return x({state:"engine_missing",refusal:ve.refusal});if(Ve==="view_outdated")return x({state:"view_outdated"});if(j.current+=1,j.current===1&&OG(ve.refusal)){k(ve.refusal.retry_after??AG);return}_(ve.refusal)},[a.list,y,R]);u.useEffect(()=>{C()},[C]);const M=u.useMemo(()=>Uf(R,()=>void C()),[C,R]);Wi(M,QD),u.useEffect(()=>{if(S===null)return;const q=setTimeout(()=>{document.visibilityState==="visible"&&C()},S*1e3);return()=>clearTimeout(q)},[S,C]),u.useEffect(()=>{document.activeElement!==O.current&&A(m.search)},[m.search]),u.useEffect(()=>{if($===m.search)return;const q=setTimeout(()=>D({search:$}),RG);return()=>clearTimeout(q)},[$,m.search,D]),u.useEffect(()=>{const q=ve=>{if(ve.key!=="/"||ve.metaKey||ve.ctrlKey||ve.altKey)return;const Ve=ve.target;Ve&&(Ve.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(Ve.tagName))||O.current&&(ve.preventDefault(),O.current.focus())};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[]);const H=()=>{var q;A(""),s(eo(Fg,p)),(q=O.current)==null||q.focus()},z=()=>{j.current=0,C()},K=()=>{L.current=!0,z()};u.useEffect(()=>{var ve;if(!L.current||v.state==="loading"||S!==null)return;L.current=!1;const q=(ve=T.current)==null?void 0:ve.querySelector("h1");q&&(q.tabIndex=-1,q.focus())},[v,w,S]);const oe=cb(T),re=q=>`/proj/${encodeURIComponent(t)}/issues${q?`?${q}`:""}`,Ne=q=>`/proj/${encodeURIComponent(t)}/issues/${encodeURIComponent(q)}?from=issues${b?`&${b}`:""}`,Se=i.jsx("div",{role:"status","aria-live":"polite",children:S!==null?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"Issues are busy. Reading them again…"]}):null}),ae=w?i.jsxs(pe,{ref:oe,variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Issues could not be loaded"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[w.message,w.since?` Since ${As(w.since)}.`:"",v.state==="ok"?` The list below was read at ${As(v.local.read_at)}.`:"",w.message.includes(vr)?"":` ${vr}`]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:K,children:"Retry"})]})]}):null,F=!!a.report,ie=F?s_.report:s_.read_only,W=i.jsx(bn,{title:"Issues",description:"This repository's local issues: what agents and you reported, where triage placed each, and what fixes it.",actions:v.state==="ok"?i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsxs("span",{className:"text-muted-foreground text-sm",children:["Read at ",As(v.local.read_at)]}),i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:z,children:[i.jsx(Er,{className:"mr-2 size-4","aria-hidden":"true"}),"Read again"]}),F?i.jsxs(U,{type:"button",size:"sm",onClick:()=>f(!0),children:[i.jsx(za,{className:"mr-2 size-4","aria-hidden":"true"}),"Report an issue"]}):null]}):null}),se=a.report?i.jsx(DG,{project:t,report:a.report,reportCollections:a.reportCollections,open:h,onOpenChange:f,onMaybeFiled:z,onFiled:q=>{z(),d(`/proj/${encodeURIComponent(t)}/issues/${encodeURIComponent(q.issue)}?${new URLSearchParams({from:"issues",reported:q.note}).toString()}`)}}):null;if(v.state==="engine_missing")return i.jsx(Jd,{ref:T,children:i.jsx(yi,{page:"Issues"})});if(v.state==="view_outdated")return i.jsxs(Jd,{ref:T,children:[W,i.jsxs(pe,{variant:"warning",className:"mt-6",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:I})]})]});if(v.state==="loading")return i.jsxs(Jd,{ref:T,children:[W,Se,ae,!w&&S===null?i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading issues",children:Array.from({length:6},(q,ve)=>i.jsx(Tt,{className:ve===5?"h-10 w-2/3":"h-10 w-full"},ve))}):null]});const{list:Z,local:de}=v,J=!w&&S===null&&(v.key!==y||$!==m.search),G=n_(Ru(v.key)),Y=de.scope==="folder",te=de.listed===0&&!g,ce=Math.max(0,de.listed-de.facets.owners.reduce((q,ve)=>q+ve.count,0)),be=m.collection?((ze=de.collections.find(q=>q.collection===m.collection))==null?void 0:ze.title)??m.collection:null,fe=new Map;for(const q of Z.issues){const ve=q.group??"unplaced";fe.set(ve,[...fe.get(ve)??[],q])}return i.jsxs(Jd,{ref:T,children:[W,Y&&de.folder?i.jsxs("p",{className:"text-muted-foreground mt-1 text-sm",children:["Issues of the folder ",de.folder,", from its issue store."]}):null,se,i.jsxs(pe,{variant:"info",className:"mt-4",children:[F?i.jsx(fn,{className:"size-4","aria-hidden":"true"}):i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:ie.title}),i.jsx(ge,{children:ie.body})]}),Se,ae,te?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(MO,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No issues yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:wG(F)})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"mt-6 flex flex-wrap items-center gap-3",children:[i.jsx(bt,{ref:O,type:"search",className:"w-64","aria-label":"Search issues",placeholder:"Search issues",value:$,onChange:q=>A(q.target.value)}),i.jsxs(St,{value:m.owner??Wr,onValueChange:q=>D({owner:q===Wr?null:q}),children:[i.jsx(wt,{className:"w-56","aria-label":"Owner",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Wr,children:"All owners"}),i.jsxs(Ue,{value:TG,children:["Unowned (",ce,")"]}),de.facets.owners.map(q=>i.jsxs(Ue,{value:q.key,children:[q.title," (",q.count,")"]},q.key))]})]}),i.jsxs(St,{value:m.label??Wr,onValueChange:q=>D({label:q===Wr?null:q}),children:[i.jsx(wt,{className:"w-48","aria-label":"Label",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Wr,children:"All labels"}),de.facets.labels.map(q=>i.jsxs(Ue,{value:q.label,children:[q.label," (",q.count,")"]},q.label))]})]})]}),i.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-4 gap-y-2",children:[i.jsx("div",{className:"flex flex-wrap items-center gap-2",role:"group","aria-label":"Marks",children:i.jsx(o_,{pressed:m.urgent,count:de.facets.urgent,onClick:()=>D({urgent:!m.urgent}),children:"Urgent"})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",role:"group","aria-label":"Seen on",children:[i.jsx("span",{className:"text-muted-foreground text-xs",children:"Seen on"}),FD.map(q=>{const ve=m.seen.includes(q.key);return i.jsx(o_,{pressed:ve,count:de.facets.seen[q.key],onClick:()=>D({seen:ve?m.seen.filter(Ve=>Ve!==q.key):[...m.seen,q.key]}),children:q.label},q.key)}),be!==null?i.jsxs("span",{className:"inline-flex items-center gap-1",children:[i.jsxs("span",{"data-testid":"issues-collection-chip",className:je(vf({variant:"outline",size:"sm"}),Z$),children:["Collection ",be]}),i.jsx(U,{type:"button",variant:"ghost",size:"sm-icon","aria-label":"Remove the collection filter",onClick:()=>{var q;D({collection:null}),(q=O.current)==null||q.focus()},children:i.jsx(dd,{className:"size-4","aria-hidden":"true"})})]}):null]})]}),i.jsx("div",{role:"status","aria-live":"polite",children:J?i.jsxs("p",{className:"text-muted-foreground mt-3 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"Searching…"]}):g&&Z.total>0?i.jsxs("p",{className:"text-muted-foreground mt-3 text-sm",children:[Z.total," of ",de.listed," issues ·"," ",i.jsx(U,{type:"button",variant:"link",size:"sm",className:"px-0",onClick:H,children:"Clear"})]}):null}),i.jsx("div",{"data-testid":"issues-results","aria-busy":J||void 0,className:"shrink-0 transition-opacity aria-busy:opacity-50",children:G&&Z.total===0?i.jsxs("p",{className:"mt-6 flex items-center gap-2 text-sm",children:[i.jsx(uf,{className:"text-muted-foreground size-4","aria-hidden":"true"}),"No issues match."," ",i.jsx(U,{type:"button",variant:"link",size:"sm",className:"px-0",onClick:H,children:"Clear"})]}):i.jsxs(i.Fragment,{children:[!G&&de.groups.length>0&&de.groups.every(q=>q.key==="resolved")?i.jsx("p",{className:"text-muted-foreground mt-6 text-sm","data-testid":"issues-none-open",children:"No open issues."}):null,de.groups.map(q=>i.jsx(LG,{id:`issues-${q.key}`,title:`${q.label} · ${q.count}`,issues:fe.get(q.key)??[],folder:Y,threads:o,fold:G?void 0:{folded:hG(p,q.key),whole:p.all.includes(q.key),onFold:ve=>E(fG(p,q.key,ve)),onWhole:ve=>E(mG(p,q.key,ve))},link:ve=>i.jsx(c,{className:"text-primary hover:underline",href:l(Ne(ve.id)),children:ve.title})},q.key))]})}),!g&&de.collections.length>0?i.jsxs("section",{className:"mt-8","aria-labelledby":"issues-collections-title",children:[i.jsxs("h2",{id:"issues-collections-title",className:"text-lg font-semibold",children:["Collections · ",de.collections.length]}),i.jsx(yt,{className:"mt-2 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Collections",className:"table-fixed",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{className:"w-1/2",children:"Collection"}),i.jsx(Q,{className:"w-1/4",children:"Resolved"}),i.jsx(Q,{className:"w-1/4",children:"Updated"})]})}),i.jsx(st,{children:de.collections.map(q=>i.jsxs(_e,{children:[i.jsxs(X,{children:[i.jsx(c,{className:"text-primary hover:underline",href:l(re(eo({...Fg,collection:q.collection},p))),children:q.title}),i.jsx("div",{className:"text-muted-foreground font-mono text-xs",children:q.collection})]}),i.jsxs(X,{children:[q.resolved," of ",q.total," resolved"]}),i.jsx(X,{className:"text-muted-foreground",children:lc(q.updated_at)})]},q.collection))})]})})]}):null]})]})}const Jd=u.forwardRef(function({children:t},n){return i.jsx("div",{ref:n,className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 pb-8 sm:px-6 lg:px-8",children:t})}),$G={plain:{title:"w-[36%]",issue:"w-[10%]",project:"",status:"w-[16%]",urgent:"w-[8%]",owner:"w-[18%]",updated:"w-[12%]"},folder:{title:"w-[30%]",issue:"w-[10%]",project:"w-[12%]",status:"w-[16%]",urgent:"w-[8%]",owner:"w-[14%]",updated:"w-[12%]"},actions:{title:"w-[30%]",issue:"w-[9%]",project:"",status:"w-[14%]",urgent:"w-[7%]",owner:"w-[16%]",updated:"w-[10%]"},folderActions:{title:"w-[26%]",issue:"w-[8%]",project:"w-[11%]",status:"w-[13%]",urgent:"w-[7%]",owner:"w-[12%]",updated:"w-[9%]"}};function o_({pressed:e,count:t,onClick:n,children:s}){const[a,r]=u.useState(!1);return i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":e,disabled:t===0&&!e&&!a,onFocus:()=>r(!0),onBlur:()=>r(!1),onClick:n,children:[s," ",t]})}function LG({id:e,title:t,issues:n,folder:s,link:a,threads:r,fold:o}){const l=$G[r?s?"folderActions":"actions":s?"folder":"plain"],c=6+(s?1:0)+(r?1:0),d=`${e}-panel`,h=!(o!=null&&o.folded),f=o!==void 0&&!o.whole&&n.length>lp,m=f?n.slice(0,lp):n,p=h?rf:ld,[y,g]=u.useState(!1),b=o!==void 0&&(f||o.whole&&n.length>lp||y);return i.jsxs("section",{className:"mt-6","aria-labelledby":`${e}-title`,"data-testid":"issues-group",children:[i.jsx("h2",{id:`${e}-title`,className:"text-lg font-semibold",children:o?i.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"-ml-2 text-lg font-semibold","aria-expanded":h,"aria-controls":h?d:void 0,onClick:()=>o.onFold(h),children:[i.jsx(p,{className:"size-4","aria-hidden":"true"}),t]}):t}),h?i.jsxs("div",{id:d,children:[i.jsx(PG,{title:t,issues:m,folder:s,link:a,threads:r,widths:l,columns:c}),o&&b?i.jsx(U,{type:"button",variant:"link",size:"sm",className:"mt-1 px-0","aria-expanded":o.whole,"aria-describedby":`${e}-title`,onFocus:()=>g(!0),onBlur:()=>g(!1),onClick:()=>o.onWhole(!o.whole),children:o.whole?"Show fewer":`Show all ${n.length}`}):null]}):null]})}function PG({title:e,issues:t,folder:n,link:s,threads:a,widths:r,columns:o}){return i.jsx(i.Fragment,{children:i.jsx(yt,{className:"mt-2 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:e,className:je("table-fixed",a&&"min-w-5xl"),children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{className:r.title,children:"Title"}),i.jsx(Q,{className:r.issue,children:"Issue"}),n?i.jsx(Q,{className:r.project,children:"Project"}):null,i.jsx(Q,{className:r.status,children:"Status"}),i.jsx(Q,{className:r.urgent,children:"Urgent"}),i.jsx(Q,{className:r.owner,children:"Owner"}),i.jsx(Q,{className:r.updated,children:"Updated"}),a?i.jsx(Q,{className:"w-[14%] text-right",children:"Actions"}):null]})}),i.jsx(st,{children:t.map(l=>i.jsx(IG,{issue:l,folder:n,link:s,threads:a,columns:o},l.id))})]})})})}function IG({issue:e,folder:t,link:n,threads:s,columns:a}){var d;const{button:r,panel:o}=Vf({org:(s==null?void 0:s.org)??"",action:s?e.local_action:void 0,task_id:null,issue:e.id,open_thread:s==null?void 0:s.open_thread}),l=qD(e),c=[e.reported_by_you?"you reported":"",e.standing??""].filter(Boolean).join(" · ");return i.jsxs(i.Fragment,{children:[i.jsxs(_e,{"data-testid":"issues-row",className:o?"border-b-0":void 0,children:[i.jsxs(X,{className:"break-words",children:[n(e),c?i.jsx("div",{"data-testid":"issues-row-standing",className:"text-muted-foreground mt-0.5 text-xs",children:c}):null,(d=e.labels)!=null&&d.length?i.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.labels.map(h=>i.jsx(we,{variant:"neutral",size:"dense",children:h},h))}):null]}),i.jsx(X,{className:"font-mono text-xs",children:e.id}),t?i.jsx(X,{className:"break-words",children:e.project_id??"Folder"}):null,i.jsx(X,{children:i.jsx(we,{variant:l.tone,children:l.label})}),i.jsx(X,{children:e.urgent&&e.status!=="resolved"&&e.group!=="resolved"?i.jsx(we,{variant:"warning",children:"Urgent"}):null}),i.jsx(X,{className:"break-words",children:e.owner_title?e.owner_title:i.jsx("span",{className:"text-muted-foreground",children:"Unowned"})}),i.jsx(X,{className:"text-muted-foreground",children:lc(e.updated_at)}),s?i.jsx(X,{className:"text-right whitespace-nowrap",children:r}):null]}),o?i.jsx(_e,{"data-testid":"issues-row-panel",className:"hover:bg-transparent",children:i.jsx(X,{colSpan:a,className:"pt-0",children:i.jsx("div",{className:"max-w-180 pl-4 text-left whitespace-normal",children:o})})}):null]})}function GG(e){var t;return(t=Vn().issues)!=null&&t.issueSections?i.jsx(MG,{...e}):i.jsx(sG,{org:e.org,project:e.project,query:e.query})}function HG({update:e,issue:t,open:n,onOpenChange:s,onDone:a,onReload:r}){const[o,l]=u.useState(t.title),[c,d]=u.useState(t.description),[h,f]=u.useState(t.external_reference??""),[m,p]=u.useState(t),[y,g]=u.useState(null),[b,v]=u.useState(!1);u.useEffect(()=>{n&&(l(t.title),d(t.description),f(t.external_reference??""),p(t),g(null))},[n]);const x=S=>{var k;return((k=y==null?void 0:y.personal_data)==null?void 0:k.field)===S?y.message:void 0},w=async S=>{S.preventDefault(),v(!0);const k=await e(m.id,m.revision,{title:o,description:c,external_reference:h.trim()||null});if(v(!1),!k.ok){g(k.refusal);return}a(k.data.issue)},_=async()=>{const S=await r();S&&(p(S),g(null))};return i.jsx(yn,{open:n,onOpenChange:s,children:i.jsx(wn,{className:"sm:max-w-2xl",children:i.jsxs("form",{onSubmit:w,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Edit issue"}),i.jsx(kn,{children:"Text is shown exactly as entered."})]}),y!=null&&y.conflict?i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{}),i.jsx(ge,{children:"Someone else saved this issue after you opened it, so nothing was saved. Your text is kept below; reload the latest issue, then save to apply it."})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-edit-title",children:"Title"}),i.jsx(bt,{id:"maintain-edit-title",value:o,"aria-invalid":!!x("title"),onChange:S=>l(S.target.value)}),x("title")?i.jsx(Kn,{children:x("title")}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-edit-description",children:"Description"}),i.jsx(Gn,{id:"maintain-edit-description",rows:4,value:c,"aria-invalid":!!x("description"),onChange:S=>d(S.target.value)}),x("description")?i.jsx(Kn,{children:x("description")}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-edit-reference",children:"External reference"}),i.jsx(bt,{id:"maintain-edit-reference",value:h,"aria-invalid":!!x("external_reference"),onChange:S=>f(S.target.value)}),x("external_reference")?i.jsx(Kn,{children:x("external_reference")}):null]}),y&&!y.conflict&&!y.personal_data?i.jsx(Kn,{children:y.message}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),y!=null&&y.conflict?i.jsxs(U,{type:"button",variant:"outline",onClick:_,children:[i.jsx(Er,{className:"mr-2 size-4"}),"Reload latest"]}):null,i.jsx(U,{type:"submit",loading:b,disabled:!!(y!=null&&y.conflict),children:"Save"})]})]})})})}function l_(e){return e.map(t=>HD[t].toLowerCase()).join(", ")}function VG(e){switch(e.kind){case"created":return"Logged the issue";case"updated":return`Edited the ${l_(e.fields)}`;case"redacted":return`Redacted the ${l_(e.fields)}`;case"priority_set":return e.priority?`Set priority to ${Mc[e.priority]}`:"Cleared the priority";case"assigned":return`Assigned to ${e.assignee_id?e.assignee_username??"someone whose name is not available":"a former member"}`;case"unassigned":return"Unassigned the issue";case"transitioned":{if(e.from_status==="resolved"&&e.to_status==="open")return"Reopened the issue";const t=e.to_status?Sh[e.to_status]:"";return e.resolution_reason?`Moved to ${t}: ${hb[e.resolution_reason]}`:`Moved to ${t}`}}}function c_(e,t){return t==="external_reference"?e.external_reference??"":e[t]}function UG({redact:e,issue:t,open:n,onOpenChange:s,onDone:a,onReload:r}){const[o,l]=u.useState("description"),[c,d]=u.useState(""),[h,f]=u.useState(!1),[m,p]=u.useState(null),[y,g]=u.useState(t);u.useEffect(()=>{n&&(g(t),d(c_(t,o)),p(null))},[n]);const b=async v=>{v.preventDefault(),f(!0);const x=await e(y.id,y.revision,o,c);if(f(!1),!x.ok){if(x.refusal.conflict){const w=await r();w&&g(w),p("Someone else saved this issue after you opened it. The latest issue is loaded and your replacement is kept; redact again to apply it.");return}p(x.refusal.message);return}a(x.data.issue)};return i.jsx(yn,{open:n,onOpenChange:s,children:i.jsx(wn,{className:"sm:max-w-2xl",children:i.jsxs("form",{onSubmit:b,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Redact text"}),i.jsx(kn,{children:"Replace text that holds personal data, such as a name."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-redact-field",children:"Field"}),i.jsxs(St,{value:o,onValueChange:v=>{const x=v;l(x),d(c_(y,x))},children:[i.jsx(wt,{id:"maintain-redact-field",children:i.jsx(Ct,{})}),i.jsx(_t,{children:Y3.map(v=>i.jsx(Ue,{value:v,children:HD[v]},v))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-redact-replacement",children:"Replacement text"}),i.jsx(Gn,{id:"maintain-redact-replacement",rows:4,value:c,onChange:v=>d(v.target.value)})]}),i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{}),i.jsx(ge,{children:"This cannot be undone: the original text is removed for good. History records only that this field was redacted."})]}),m?i.jsx(Kn,{children:m}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),i.jsx(U,{type:"submit",variant:"destructive",loading:h,children:"Redact"})]})]})})})}function BG({transition:e,issue:t,open:n,onOpenChange:s,onDone:a}){const[r,o]=u.useState("fixed"),[l,c]=u.useState(!1),[d,h]=u.useState(null),f=async m=>{m.preventDefault(),c(!0);const p=await e(t.id,t.revision,"resolved",r);if(c(!1),!p.ok){if(p.refusal.conflict){a(null);return}h(p.refusal.message);return}h(null),a(p.data.issue)};return i.jsx(yn,{open:n,onOpenChange:s,children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:f,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Resolve issue"}),i.jsx(kn,{children:"Choose how this report ended."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-resolution-reason",children:"Resolution reason *"}),i.jsxs(St,{value:r,onValueChange:m=>o(m),children:[i.jsx(wt,{id:"maintain-resolution-reason",children:i.jsx(Ct,{})}),i.jsx(_t,{children:q3.map(m=>i.jsx(Ue,{value:m,children:hb[m]},m))})]}),i.jsx("p",{className:"text-muted-foreground text-xs",children:"Reopening the issue clears its reason."})]}),d?i.jsx(Kn,{children:d}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),i.jsx(U,{type:"submit",loading:l,children:"Resolve"})]})]})})})}const Fr="not_set";function WG({org:e,project:t,issue_id:n,query:s}){const a=VD(),r=UD(a),o=Bg(e,t);return i.jsx("div",{className:"flex w-full flex-1 flex-col gap-6 px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(BD,{access:r,header:i.jsx(bn,{title:"Support"}),back_href:o,children:l=>a?i.jsx(FG,{contract:a,issue_id:n,access:l,list_href:o,duplicates:Number(new URLSearchParams(s).get("duplicates")??0)}):null})})}function FG({contract:e,issue_id:t,access:n,list_href:s,duplicates:a}){const{href:r,Link:o}=lt(),l=Ga(),[c,d]=u.useState(null),[h,f]=u.useState([]),[m,p]=u.useState(!1),[y,g]=u.useState([]),[b,v]=u.useState(null),x=u.useCallback(async()=>{const j=await e.issue(t);return j.ok?(d(j.data.issue),f(j.data.events),j.data.issue):(j.refusal.status===404?p(!0):l.error(j.refusal.message),null)},[e,t,l]);u.useEffect(()=>{let j=!1;return e.issue(t).then(N=>{if(!j){if(!N.ok){N.refusal.status===404?p(!0):l.error(N.refusal.message);return}d(N.data.issue),f(N.data.events)}}),()=>{j=!0}},[e,t]),u.useEffect(()=>{n.can_change&&e.assigneeCandidates().then(j=>{j.ok&&g(j.data.candidates)})},[e,n.can_change]);const w=async j=>{const N=await j;if(!N.ok){l.error(N.refusal.message),N.refusal.conflict&&await x();return}await x()};if(m)return i.jsx(Ha,{title:"Support issue not found",description:"This issue does not exist in this project.",backHref:r(s),backLabel:"Back to Support",link:o});if(!c)return i.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading…"});const _=c.status==="closed",S=n.can_change,k=j=>w(e.transition(c.id,c.revision,j));return i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:c.title,actions:S?i.jsxs(i.Fragment,{children:[_?null:i.jsxs(U,{variant:"outline",onClick:()=>v("edit"),children:[i.jsx(df,{className:"mr-2 size-4"}),"Edit"]}),i.jsxs(U,{variant:"outline",onClick:()=>v("redact"),children:[i.jsx(yO,{className:"mr-2 size-4"}),"Redact"]}),c.status==="open"?i.jsx(U,{variant:"outline",disabled:!c.priority,"aria-description":c.priority?void 0:"Set a priority first.",onClick:()=>void k("triaged"),children:"Triage"}):null,c.status==="open"||c.status==="triaged"?i.jsxs(U,{onClick:()=>v("resolve"),children:[i.jsx(of,{className:"mr-2 size-4"}),"Resolve"]}):null,c.status==="resolved"?i.jsxs(i.Fragment,{children:[i.jsxs(U,{variant:"outline",onClick:()=>void k("open"),children:[i.jsx(oz,{className:"mr-2 size-4"}),"Reopen"]}),i.jsx(U,{onClick:()=>void k("closed"),children:"Close"})]}):null]}):void 0,children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(we,{variant:GD[c.status],children:Sh[c.status]}),i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Logged by ",Z3(c)," ",Au(c.created_at)]})]})}),i.jsxs("div",{className:"flex flex-col gap-8 lg:flex-row lg:items-start",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-6",children:[a>0&&c.external_reference?i.jsxs(pe,{variant:"info",children:[i.jsx(fn,{}),i.jsxs(ge,{className:"flex flex-row flex-wrap items-center justify-between gap-2",children:[i.jsxs("span",{children:[c.external_reference," is already logged on"," ",a===1?"another issue":`${a} other issues`," in this project."]}),i.jsx(U,{asChild:!0,variant:"outline",size:"sm",children:i.jsx(o,{href:r(`${s}?external_reference=${encodeURIComponent(c.external_reference)}`),children:"Show both"})})]})]}):null,i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:"Description"}),c.description?i.jsx("p",{className:"text-sm break-words whitespace-pre-wrap",children:c.description}):i.jsx("p",{className:"text-muted-foreground text-sm",children:"No description."})]}),i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:"History"}),i.jsx("div",{className:"rounded-md border",children:i.jsxs(nt,{children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"When"}),i.jsx(Q,{children:"Who"}),i.jsx(Q,{children:"What"})]})}),i.jsx(st,{children:h.map(j=>i.jsxs(_e,{children:[i.jsx(X,{className:"text-muted-foreground",children:Au(j.created_at)}),i.jsx(X,{children:Q3(j,c)}),i.jsx(X,{children:VG(j)})]},j.id))})]})})]})]}),i.jsxs("aside",{className:"flex w-full shrink-0 flex-col gap-5 lg:w-72",children:[i.jsx(Al,{label:"External reference",children:c.external_reference?i.jsx("span",{className:"font-mono text-sm",children:c.external_reference}):i.jsx("span",{className:"text-muted-foreground text-sm",children:"None"})}),c.resolution_reason?i.jsx(Al,{label:"Resolution",children:i.jsx("span",{className:"text-sm",children:hb[c.resolution_reason]})}):null,i.jsx(Al,{label:"Priority",id:"maintain-issue-priority",children:i.jsxs(St,{value:c.priority??Fr,disabled:!S||_,onValueChange:j=>void w(e.update(c.id,c.revision,{priority:j===Fr?null:j})),children:[i.jsx(wt,{id:"maintain-issue-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Fr,children:"Not set"}),ub.map(j=>i.jsx(Ue,{value:j,children:Mc[j]},j))]})]})}),i.jsxs(Al,{label:"Assignee",id:"maintain-issue-assignee",children:[i.jsxs(St,{value:c.assignee_id??Fr,disabled:!S||_,onValueChange:j=>void w(e.assign(c.id,c.revision,j===Fr?null:j)),children:[i.jsx(wt,{id:"maintain-issue-assignee",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Fr,children:"Not set"}),c.assignee_id&&!y.some(j=>j.user_id===c.assignee_id)?i.jsx(Ue,{value:c.assignee_id,children:fb(c.assignee_id,c.assignee_username)}):null,y.map(j=>i.jsx(Ue,{value:j.user_id,children:j.username??"Not available"},j.user_id))]})]}),c.assignee_can_act===!1?i.jsx(we,{variant:"error",className:"self-start",children:"Assignee cannot act"}):null]}),i.jsx(Al,{label:"Updated",children:i.jsx("span",{className:"text-sm",children:Au(c.updated_at)})})]})]}),i.jsx(HG,{update:e.update,issue:c,open:b==="edit",onOpenChange:j=>v(j?"edit":null),onReload:x,onDone:()=>{v(null),x()}}),i.jsx(UG,{redact:e.redact,issue:c,open:b==="redact",onOpenChange:j=>v(j?"redact":null),onReload:x,onDone:()=>{v(null),l.success("The text was redacted."),x()}}),i.jsx(BG,{transition:e.transition,issue:c,open:b==="resolve",onOpenChange:j=>v(j?"resolve":null),onDone:j=>{v(null),j||l.error("Someone else changed this issue; it is reloaded."),x()}})]})}function Al({label:e,id:t,children:n}){return i.jsxs("div",{className:"flex flex-col gap-1.5",children:[t?i.jsx("label",{htmlFor:t,className:"text-muted-foreground text-2xs font-medium tracking-wide uppercase",children:e}):i.jsx("span",{className:"text-muted-foreground text-2xs font-medium tracking-wide uppercase",children:e}),n]})}const qG=10,YG=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,d_=/^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/;function XG(e,t,n,s=""){const a=n!=null&&n.startsWith("task:")?n.slice(5):null;if(a&&YG.test(a))return{label:a,path:`/org/${e}/tasks/${a}`};const r=`/proj/${encodeURIComponent(t)}/releases`,o=n!=null&&n.startsWith("release:")?n.slice(8):null;if(o&&d_.test(o))return{label:o==="candidate"?"Candidate":o,path:`${r}?release=${encodeURIComponent(o)}`};const l=n!=null&&n.startsWith("planned:")?n.slice(8):null;if(l&&d_.test(l))return{label:l,path:`${r}?planned=${encodeURIComponent(l)}`};const c=eo(Ru(s),XD(s));return{label:"Issues",path:`/proj/${encodeURIComponent(t)}/issues${c?`?${c}`:""}`}}const KG=["Fixed in","Being fixed in","The release planned to fix it"];function ZG(e){const t=e.filter(n=>n.kind==="release");for(const n of KG){const s=t.find(a=>a.relation===n);if(s)return s}return t[0]??null}function QG(e,t){const n=e.filter(s=>s.kind==="thread"&&(s.label===t||s.id===t));return n.find(s=>s.owns)??n[0]??null}function JG(e,t){const n=e.toLowerCase();return n==="file"&&t.trim()?{kind:"file",path:t}:n==="commit"&&/^[0-9a-f]{7,40}$/i.test(t)?{kind:"commit",sha:t}:null}function eH({org:e,project:t,issue_id:n,from:s,query:a=""}){var mn,Sn,xe;const r=JD(),{href:o,Link:l}=lt(),c=XG(e,t,s,a),d=EG(a,n),h=`/proj/${encodeURIComponent(t)}/issues`,f=ne=>`${h}/${encodeURIComponent(ne)}`,m=ne=>`${e?`/org/${e}`:""}/threads#thread-${encodeURIComponent(ne)}`,p=ne=>`/proj/${encodeURIComponent(t)}/releases?${ne.planned?"planned":"release"}=${encodeURIComponent(ne.id)}`,[y,g]=u.useState({state:"loading"}),[b,v]=u.useState(null),[x,w]=u.useState(null),[_,S]=u.useState({state:"loading"}),[k,j]=u.useState({state:"loading"}),[N,O]=u.useState(null),T=u.useRef(0),I=u.useCallback(async ne=>{if(!r.openAnchor)return;const ye=ne.kind==="file"?ne.path:ne.sha,qe=T.current+=1;O({value:ye,state:"opening",words:`Opening ${ye}…`});const xt=await r.openAnchor(ne);qe===T.current&&O(xt.ok?{value:ye,state:"opened",words:`Opened ${ye} in ${xt.data.with}`}:{value:ye,state:"failed",words:`Could not open ${ye}: ${xt.refusal.message}`})},[r]);u.useEffect(()=>{T.current+=1,O(null)},[n]);const L=u.useRef(null),$=ns(),A=u.useRef(null),D=u.useRef(!1),E=u.useRef(0),R=u.useRef(0),C=u.useRef(!1),M=Ts(),H=u.useRef(0),z=u.useRef(0),K=u.useCallback(async(ne=!1)=>{if(!r.issueSections)return;const ye=H.current+=1;ne||S({state:"loading"});const qe=await M.track(r.issueSections(n));ye===H.current&&S(xt=>qe.ok?{state:"ok",data:qe.data}:ne&&xt.state==="ok"?xt:{state:"failed",refusal:qe.refusal})},[r.issueSections,n,M]),oe=u.useCallback(async(ne=!1)=>{if(!r.issueRelated)return;const ye=z.current+=1;ne||j({state:"loading"});const qe=await M.track(r.issueRelated(n));ye===z.current&&j(xt=>qe.ok?{state:"ok",data:qe.data}:ne&&xt.state==="ok"?xt:{state:"failed",refusal:qe.refusal})},[r.issueRelated,n,M]),re=u.useCallback(async(ne=!1)=>{const ye=R.current+=1;if(w(null),!oG.test(n)){g({state:"missing"});return}K(ne),oe(ne);const qe=await M.track(r.issue(n));if(ye!==R.current)return;if(qe.ok){E.current=0,v(null),g({state:"ok",issue:qe.data.issue,events:qe.data.events,at:new Date().toISOString()});return}const xt=qe.refusal.reason;if(qe.refusal.status===404||xt==="not_found")return g({state:"missing"});if(xt==="engine_missing")return g({state:"engine_missing",refusal:qe.refusal});if(xt==="view_outdated")return g({state:"view_outdated"});if(E.current+=1,E.current===1&&PD(qe.refusal)){C.current=ne,w(qe.refusal.retry_after??qG);return}v(qe.refusal)},[r.issue,n,K,oe,M]);u.useEffect(()=>{re()},[re]);const Ne=u.useMemo(()=>Uf(M,()=>void re(!0)),[re,M]);Wi(Ne,QD),u.useEffect(()=>{if(x===null)return;const ne=setTimeout(()=>{document.visibilityState==="visible"&&re(C.current)},x*1e3);return()=>clearTimeout(ne)},[x,re]),u.useEffect(()=>{var ye;if(D.current||y.state!=="ok")return;D.current=!0;const ne=(ye=L.current)==null?void 0:ye.querySelector("h1");ne&&(ne.tabIndex=-1,ne.focus())},[y.state]);const Se=u.useRef(null);u.useEffect(()=>{var qe;const ne=Se.current;if(ne===null||(ne==="sections"?_:k).state==="loading")return;Se.current=null;const ye=(ne==="related"?A.current:null)??((qe=L.current)==null?void 0:qe.querySelector("h1"));ye==null||ye.focus()},[_,k]);const ae=ne=>{Se.current=ne,ne==="sections"?K():oe()},F=()=>{E.current=0,re()},ie=cb(L),W=u.useRef(!1),se=()=>{W.current=!0,F()};u.useEffect(()=>{var ye;if(!W.current||y.state==="loading"||x!==null)return;W.current=!1;const ne=(ye=L.current)==null?void 0:ye.querySelector("h1");ne&&(ne.tabIndex=-1,ne.focus())},[y,b,x]);const Z=Vf({org:e,labelled:!0,action:(mn=r.commands)!=null&&mn.open_thread&&y.state==="ok"?y.issue.local_action:void 0,task_id:null,issue:n,open_thread:(Sn=r.commands)==null?void 0:Sn.open_thread});if(y.state==="missing")return i.jsx(ma,{children:i.jsx(Ha,{icon:i.jsx(uf,{"aria-hidden":"true"}),title:"Issue not found",description:`No issue ${n} in this repository's issue store.`,backHref:o(s==="issues"?c.path:h),backLabel:"Back to issues",link:l})});const de=i.jsx(U,{asChild:!0,variant:"link",size:"sm",className:"px-0",children:i.jsxs(l,{href:o(c.path),children:[i.jsx($k,{className:"size-4","aria-hidden":"true"}),c.label]})});if(y.state==="engine_missing"||y.state==="view_outdated")return i.jsx(ma,{children:y.state==="engine_missing"?i.jsx(yi,{page:"Issue",header:i.jsx(oc,{back:de,id:null,title:n})}):i.jsxs(i.Fragment,{children:[i.jsx(oc,{back:de,id:null,title:n}),i.jsxs(pe,{variant:"warning",className:"mt-4",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:$})]})]})});const J=b?i.jsxs(pe,{ref:ie,variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This issue could not be loaded"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[b.message,b.since?` Since ${As(b.since)}.`:"",y.state==="ok"?` This page was read at ${As(y.at)}.`:"",b.message.includes(vr)?"":` ${vr}`]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:se,children:"Retry"})]})]}):null,G=i.jsx("div",{role:"status","aria-live":"polite",children:x!==null?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"This issue is busy. Reading it again…"]}):null});if(y.state==="loading")return i.jsxs(ma,{children:[i.jsx("div",{children:de}),G,J,!b&&x===null?i.jsxs("div",{className:"mt-4 grid gap-3",role:"status","aria-label":"Loading issue",children:[i.jsx(Tt,{className:"h-6 w-40"}),i.jsx(Tt,{className:"h-9 w-2/3"}),i.jsx(Tt,{className:"h-24 w-full"})]}):null]});const{issue:Y,events:te,at:ce}=y,be=qD(Y),fe=_.state==="ok"?_.data:null,$e=(fe==null?void 0:fe.reporter)??Y.created_by_username??null,ze=k.state==="ok"?ZG(k.data):null,q=Y.status==="resolved"||Y.group==="resolved",ve=!!(fe!=null&&fe.duplicate_of),Ve=(fe==null?void 0:fe.routing.owner)??Y.owner_title??null,Ft=Ve&&k.state==="ok"?QG(k.data,Ve):null,Qt=_.state==="loading"?"Loading…":Ft?i.jsx(l,{className:"text-primary hover:underline",href:o(m(Ft.id)),children:Ve}):Ve??i.jsx("span",{className:"text-muted-foreground",children:"Unowned"}),ht=ne=>`${h}?${mb({...Fg,collection:ne})}`,it=fe==null?void 0:fe.report,Lt=!!(it&&(it.actual||it.expected||it.steps.length||it.where)),Dt=[...te].reverse(),On=i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[Z.button,i.jsxs("span",{className:"text-muted-foreground text-sm",children:["Read at ",As(ce)]}),i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:F,children:[i.jsx(Er,{className:"mr-2 size-4","aria-hidden":"true"}),"Read again"]})]});return i.jsx(ma,{children:i.jsxs("div",{ref:L,className:"contents",children:[i.jsx(oc,{back:de,id:Y.id,badge:i.jsxs(i.Fragment,{children:[i.jsx(we,{variant:be.tone,children:be.label}),Y.urgent&&!q?i.jsx(we,{variant:"warning",children:"Urgent"}):null]}),title:Y.title,created:`Reported${$e?` by ${$e}`:""} · ${lc(Y.created_at)}`,actions:On}),fe!=null&&fe.duplicate_of?i.jsxs("p",{className:"mt-1 text-sm",children:["Duplicate of"," ",i.jsx(l,{className:"text-primary font-mono hover:underline",href:o(f(fe.duplicate_of)),children:fe.duplicate_of})]}):null,Z.panel?i.jsx("div",{className:"mt-1 max-w-180",children:Z.panel}):null,i.jsx("div",{role:"status","aria-live":"polite",children:d?i.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:d}):null}),G,J,_.state==="loading"?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",role:"status",children:[i.jsx(vn,{"aria-hidden":"true"}),"Loading the issue's sections"]}):null,i.jsxs("dl",{className:"mt-4 mb-0 flex flex-wrap gap-x-12 gap-y-4","data-testid":"issue-facts",children:[i.jsx(ai,{label:"Owner",value:Qt}),ve?null:i.jsx(ai,{label:"Release",value:k.state==="loading"?"Loading…":ze?i.jsx(l,{className:je("text-primary hover:underline",ze.label===ze.id&&"font-mono"),href:o(p(ze)),children:ze.label}):i.jsx("span",{className:"text-muted-foreground",children:"No release yet"})}),i.jsx(ai,{label:"Reported",value:[$e,Y.created_at?Rs(Y.created_at):null].filter(Boolean).join(" · ")})]}),i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:i_.title}),i.jsx(ge,{children:i_.body})]}),_.state==="failed"?i.jsx("div",{className:"mt-6",children:i.jsx(db,{what:"this issue's sections",again:"Read the issue again",refusal:_.refusal,on_retry:()=>ae("sections")})}):null,fe&&Lt&&it?i.jsxs(Yt,{id:"issue-report",title:"What happens",children:[it.actual?i.jsx("p",{className:"text-sm whitespace-pre-wrap",children:it.actual}):null,it.expected?i.jsxs("div",{className:"mt-3",children:[i.jsx("h3",{className:"text-sm font-semibold",children:"Expected"}),i.jsx("p",{className:"text-sm whitespace-pre-wrap",children:it.expected})]}):null,it.steps.length?i.jsxs("div",{className:"mt-3",children:[i.jsx("h3",{className:"text-sm font-semibold",children:"Steps"}),i.jsx("ol",{className:"list-decimal pl-5 text-sm",children:it.steps.map((ne,ye)=>i.jsx("li",{children:ne},ye))})]}):null,(xe=it.where)!=null&&xe.env?i.jsxs("p",{className:"text-muted-foreground mt-3 text-sm",children:["Seen on ",it.where.env,it.where.sha?i.jsxs(i.Fragment,{children:[" ","at ",i.jsx("span",{className:"font-mono",children:it.where.sha})]}):null]}):null]}):null,fe&&(fe.placement.placed||fe.placement.unplaced_why)?i.jsx(Yt,{id:"issue-placement",title:"Placement",children:fe.placement.placed?i.jsxs("p",{className:"text-sm",children:["Placed in ",fe.placement.placed]}):i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Not placed yet: ",fe.placement.unplaced_why]})]})}):null,fe&&(fe.routing.route||fe.routing.owner||fe.routing.none)?i.jsxs(Yt,{id:"issue-routing",title:"Routing",children:[fe.routing.route?i.jsx("p",{className:"text-sm",children:fe.routing.route}):null,fe.routing.owner?i.jsxs("p",{className:"text-sm",children:["Owner: ",fe.routing.owner]}):i.jsx("p",{className:"text-muted-foreground text-sm",children:"Owner: none yet"})]}):null,fe&&(fe.labels.length>0||fe.collections.length>0)?i.jsxs(Yt,{id:"issue-labels",title:"Labels and collections",children:[fe.labels.length?i.jsx("div",{className:"flex flex-wrap gap-1",children:fe.labels.map(ne=>i.jsx(we,{variant:"neutral",size:"dense",children:ne},ne))}):null,fe.collections.length?i.jsx("ul",{className:"mt-2 grid gap-1 text-sm",children:fe.collections.map(ne=>i.jsxs("li",{children:[i.jsx(l,{className:"text-primary hover:underline",href:o(ht(ne.collection)),children:ne.title}),ne.ref?i.jsxs("span",{className:"text-muted-foreground",children:[" · ",ne.ref]}):null,i.jsxs("span",{className:"text-muted-foreground",children:[" ","· ",ne.resolved," of ",ne.total," resolved"]})]},ne.collection))}):null]}):null,fe&&fe.anchors.length>0?i.jsxs(Yt,{id:"issue-anchors",title:"Anchors",children:[i.jsx(hp,{label:"Anchors",heads:["Kind","Value","By"],rows:fe.anchors.map(ne=>{const ye=r.openAnchor?JG(ne.kind,ne.value):null;return[ne.kind,ye?i.jsx(U,{type:"button",variant:"link",size:"control",className:"h-auto min-h-7 justify-start px-0 text-left font-mono text-xs font-normal break-all whitespace-normal","aria-label":ye.kind==="file"?`Open ${ne.value}`:`Show commit ${ne.value}`,onClick:()=>void I(ye),children:ne.value}):i.jsx("span",{className:"font-mono text-xs break-all",children:ne.value}),ne.by??""]})}),r.openAnchor?i.jsx("p",{role:"status","aria-live":"polite","data-testid":"issue-anchor-status",className:je("mt-2 text-sm empty:hidden",(N==null?void 0:N.state)==="failed"?"text-destructive":(N==null?void 0:N.state)==="opened"?"text-success":"text-muted-foreground"),children:(N==null?void 0:N.words)??""}):null]}):null,fe&&fe.seen.length>0?i.jsx(Yt,{id:"issue-seen",title:"Seen",aside:`${fe.seen.length} of ${Math.max(Y.occurrences??0,fe.seen.length)} sightings`,children:i.jsx(hp,{label:"Seen",heads:["When","Where","Who","Note"],rows:fe.seen.map(ne=>[lc(ne.at),i.jsxs(i.Fragment,{children:[ne.sha?i.jsx("div",{className:"font-mono text-xs",children:ne.sha}):null,ne.env?i.jsx("div",{className:"text-muted-foreground text-xs",children:ne.env}):null]}),ne.who??"",ne.note??""])})}):null,Dt.length>0?i.jsx(Yt,{id:"issue-history",title:"History",aside:"From the issue store, newest first",children:i.jsx(hp,{label:"History",heads:["When","Who","What"],rows:Dt.map(ne=>[lc(ne.created_at),ne.actor_username??"",bG(ne.note,ne.kind)])})}):null,i.jsx(ID,{id:"issue-related",related:k,heading_ref:A,on_retry:()=>ae("related"),fixed:!0,link:ne=>{const ye=ne.kind==="thread"?m(ne.id):ne.kind==="task"?`/org/${e}/tasks/${encodeURIComponent(ne.id)}?from=issue:${Y.id}`:ne.kind==="issue"?f(ne.id):ne.kind==="release"?p(ne):null;if(ne.kind==="task"&&ye){const qe=yG(ne.label);return i.jsxs("div",{className:"min-w-0",children:[i.jsx(l,{className:"text-primary font-mono text-xs hover:underline",href:o(ye),children:ne.id}),qe&&qe!==ne.id?i.jsx("div",{className:"text-muted-foreground line-clamp-1 text-xs",title:qe,"data-testid":"related-task-title",children:qe}):null]})}return ye?i.jsx(l,{className:je("text-primary hover:underline",ne.kind!=="thread"&&ne.label===ne.id&&"font-mono"),href:o(ye),children:ne.label}):ne.label}})]})})}function hp({label:e,heads:t,rows:n}){return i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:e,children:[i.jsx(ot,{children:i.jsx(_e,{children:t.map(s=>i.jsx(Q,{children:s},s))})}),i.jsx(st,{children:n.map((s,a)=>i.jsx(_e,{children:s.map((r,o)=>i.jsx(X,{className:"break-words",children:r},o))},a))})]})})}function tH({org:e,project:t,issue_id:n,from:s,query:a}){var r;return(r=Vn().issues)!=null&&r.issueSections?i.jsx(eH,{org:e,project:t,issue_id:n,from:s,query:a}):i.jsx(WG,{org:e,project:t,issue_id:n,query:a})}const fi={label:"Stalled",tone:"error"},nH="A stalled turn passes on at the next queue command.",sH=e=>e.charAt(0).toUpperCase()+e.slice(1);function iH(e){return e==="starts now"?"Now":e==="rides the same deploy"?"With the same deploy":sH(e.replace(/^starts /,""))}const aH=e=>e.replace(/ after its turn came$/," after its turn"),eE={integration:"Integration",deploy:"Deploy",publish:"Publish",accept:"Accept",custom:"Custom"},rH={self_service:"Self-service",managed:"Managed",manager_only:"Manager only"},oH={self_service:"Self-service: each entry takes its own turn",managed:"Managed: a manager batches entries that allow it",manager_only:"Manager only: the manager runs every turn"},lH={in_batch:{label:"In the batch",tone:"info"},done:{label:"Done",tone:"success"},failed:{label:"Failed",tone:"error"},released:{label:"Released",tone:"neutral"},left:{label:"Left",tone:"neutral"},gone:{label:"Ended",tone:"neutral"},skipped:{label:"Skipped",tone:"neutral"},lapsed:{label:"Lapsed",tone:"warning"}};function cH(e){return lH[e??"in_batch"]}function dH(e,t=!1){if(t)return fi;const n=e.turn==="next",s=n?"Next":"Waiting",a=e.batching==="managed"||e.batching==="released"?` · ${e.batching}`:"";return{label:`${s}${a}`,tone:n?"info":"neutral"}}const tE=(e,t)=>`Holds ${e.toLowerCase()}${t?`: ${t}`:""}`;function uH(e,t,n,s=!0,a=!1){return a?fi:e.fixing_since!==void 0?{label:`Fixing forward since ${Xn(e.fixing_since)}`,tone:"warning"}:e.ref===t?{label:"Landing",tone:"info"}:s&&e.hold?{label:tE(n),tone:"info"}:{label:"Running",tone:"info"}}function Xn(e){return new Date(e*1e3).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}function qr(e){const t=Math.round(e/60);if(t<60)return`${t} min`;const n=Math.floor(t/60),s=t%60;return s?`${n} h ${s} min`:`${n} h`}function hH(e){var n;const t=e.binding;return(t==null?void 0:t.kind)==="repository_branch"?`${t.repository} · ${t.branch}`:(t==null?void 0:t.kind)==="label"?t.label:((n=e.layer)==null?void 0:n.kind)==="release"&&e.layer.promotes_to?`Promotes to ${e.layer.promotes_to}`:null}function fH(e,t){switch(e.kind){case"any_thread":return"Any thread in this checkout";case"task_writers":return"Anyone who can edit the entry's task";case"any_joiner":return"Anyone who may join";case"managers":return"Whoever may manage";case"admins":return"Workspace admins";case"none":return"Nobody";case"listed":{const n=e.users.map(t),s=e.teams.length;return s&&n.push(s===1?"1 team":`${s} teams`),n.length?n.join(", "):"Nobody"}}}function mH(e,t){var l,c;const{policy:n,management:s}=e,a=(l=e.layer)==null?void 0:l.kind,r=d=>fH(d,t),o=[["Mode",oH[s.mode]],["Who can join",r(s.joiners)]];return a==="implement"&&o.push(["Managers",r(s.managers)],["Manager lease",qr(s.manager_lease_seconds)],["Batches",n.batch.enabled?`Up to ${n.batch.max_members} entries`:"Off"]),((c=e.layer)==null?void 0:c.kind)==="release"&&(e.layer.promotes_to&&o.push(["Promotes to",e.layer.promotes_to]),o.push(["Carries waiting entries",n.ride?"Yes: a done turn carries entries already contained in it":"No"],["Freeze",n.freeze.enabled?`Up to ${qr(n.freeze.max_seconds)}, ${qr(n.freeze.default_seconds)} by default`+(e.layer.freezers?` · ${r(e.layer.freezers)}`:""):"Off"],["Fix forward",n.fix_forward?"Yes: a failed turn keeps its turn until fixed":"No"],["Stalled turns",s.stall_takers.kind==="none"?"Nobody takes one":`${r(s.stall_takers)} may take one after ${qr(n.stall_seconds)}`])),o.push(["Reorder",r(s.reorderers)]),n.max_turns>1&&o.push(["Turns at once",`Up to ${n.max_turns} independent turns`]),o.push(["Turn lease",qr(n.lease_seconds)],["Time to start",`${qr(n.start_grace_seconds)} after the turn comes`]),n.entry_limit!==null&&o.push(["Waiting entries",`Up to ${n.entry_limit}`]),n.footprint!=="off"&&o.push(["Footprint",n.footprint==="required"?"Required":"Optional"]),o}const Ch="heavy",nE="Heavy checks",pH="Every worktree, admitted by memory",gH="Typechecks, builds, test suites and dev servers from every worktree of this repository wait here for memory.",xH="A smaller turn may pass one that does not fit, so the order can change; a passing turn reused on identical code never waits.",vH="Heavy checks are admitted by this machine's memory; there are no settings here.",sE="Where your organization's agents take turns at a shared branch, environment or proposal. One turn runs at a time in each queue.",iE="A task you cannot see",bH="A former member",yH="A member";function aE(){const e=Vn().queues;if(!e)throw new Error("The Queues page rendered without the queues seam.");return e}function wH({org:e,open:t,path:n}){var f,m;const s=aE(),{href:a,Link:r}=lt(),o=s.availability,[l,c]=u.useState({state:"loading"}),d=u.useCallback(async p=>{o&&(p&&c({state:"loading"}),c(await o({fresh:p})))},[o]);u.useEffect(()=>{d(!1)},[d]);const h=!o||l.state==="active";return l.state==="off"&&((f=l.refusal)==null?void 0:f.reason)!=="engine_missing"?i.jsx(Ha,{title:"Page not found",description:"This page does not exist, or you do not have access to it.",backHref:a(`/org/${e}`),backLabel:"Back to the organization",link:r}):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:h?i.jsx(jH,{org:e,open:t??null,path:n??`/org/${e}/tasks/queues`}):l.state==="off"&&((m=l.refusal)==null?void 0:m.reason)==="engine_missing"?i.jsx(yi,{page:"Queues"}):i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:"Queues",description:s.description??sE}),l.state==="loading"&&i.jsx(rE,{}),(l.state==="error"||l.state==="off")&&i.jsx(Tu,{refusal:l.refusal,on_retry:()=>void d(!0)}),l.state==="available"&&i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Tasks are not on for this organization"}),i.jsxs(ge,{children:["Queues hold turns for tasks, so they show once Tasks are on."," ",i.jsx(r,{className:"text-primary hover:underline",href:a(`/org/${e}/tasks`),children:"Go to Tasks"})]})]})]})})}function rE(){return i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading queues",children:Array.from({length:3},(e,t)=>i.jsx(Tt,{className:t===2?"h-10 w-2/3":"h-10 w-full"},t))})}function Tu({refusal:e,on_retry:t}){const n=ns();return(e==null?void 0:e.reason)==="store_locked"?i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"The local stores are busy"}),i.jsxs(ge,{children:[i.jsx("p",{children:e.message}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]}):(e==null?void 0:e.reason)==="view_outdated"?i.jsxs(pe,{variant:"warning",className:"mt-6",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:n})]}):i.jsxs(pe,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Queues could not be loaded"}),i.jsxs(ge,{children:[i.jsx("p",{children:"The read did not answer. Try again in a moment."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]})}const fp=e=>e.status===404||e.reason==="not_found"||e.code==="not_found";function _H(e,t,n,s){return t?e===null?`Not reading · trying again every ${n}s`:`Not reading since ${Xn(e)} · trying again every ${n}s`:e===null?"Connecting…":`Live · read ${Xn(e)} · refreshes every ${n}s${s?` · ${s}`:""}`}function jH({org:e,open:t,path:n}){var G;const{listQueues:s,queue:a,members:r,refresh_ms:o,settings_note:l,description:c,read_scope:d,subject_label:h="Task",thread_subjects:f=!1,timing:m}=aE(),{self_id:p}=af(),y=!!m&&t===Ch,[g,b]=u.useState(null),[v,x]=u.useState(null),[w,_]=u.useState(null),[S,k]=u.useState(null),[j,N]=u.useState({state:"pending",members:[]});u.useEffect(()=>{let Y=!0;return r().then(te=>{Y&&N(ce=>te.ok?{state:"answered",members:te.data}:{state:"failed",members:ce.members})}),()=>{Y=!1}},[r]);const O=u.useMemo(()=>new Map(j.members.map(Y=>[Y.user_id,Y])),[j.members]),T=j.state==="answered"?bH:yH,I=u.useCallback((Y,te)=>{var ce;return(te==null?void 0:te.title)??(f?(te==null?void 0:te.id)??Y:Y===p?"You":((ce=O.get(Y))==null?void 0:ce.label)??T)},[O,T,p,f]),L=u.useRef({list:{last:null,fresh:!1},detail:{last:null,fresh:!1}}),[$,A]=u.useState(null),[D,E]=u.useState(!1),R=u.useCallback((Y,te)=>{L.current[Y]={last:te,fresh:!0};const{list:ce,detail:be}=L.current;E(ce.last==="failed"||be.last==="failed"),ce.fresh&&be.fresh&&ce.last==="ok"&&be.last==="ok"&&A(Date.now()/1e3)},[]),C=t??((G=g==null?void 0:g.queues[0])==null?void 0:G.id)??null,M=u.useRef(C);u.useEffect(()=>{M.current=C},[C]);const H=u.useRef(0),z=u.useCallback(async()=>{var ce;const Y=H.current+=1;L.current.list.fresh=!1;const te=await s();if(Y===H.current)if(te.ok){if(b(te.data),x(null),!t){const be=((ce=te.data.queues[0])==null?void 0:ce.id)??null;be===null?L.current.detail={last:"ok",fresh:!0}:be!==M.current&&(L.current.detail.fresh=!1)}R("list","ok")}else x(te.refusal),R("list","failed")},[s,t,R]),K=u.useRef(0),oe=u.useCallback(async()=>{const Y=K.current+=1;if(!C)return;if(y){L.current.detail.fresh=!1;return}L.current.detail.fresh=!1;const te=await a(C);Y===K.current&&(te.ok?(_(te.data),k(null),R("detail","ok")):(k(te.refusal),fp(te.refusal)&&_(null),R("detail",fp(te.refusal)?"ok":"failed")))},[y,C,a,R]),[re,Ne]=u.useState({state:"pending",data:null}),Se=u.useRef(0),ae=u.useCallback(async()=>{if(!m)return;const Y=Se.current+=1,te=await m();Y===Se.current&&(Ne(te.ok?{state:"answered",data:te.data}:{state:"failed",data:null}),y&&R("detail",te.ok?"ok":"failed"))},[m,y,R]);u.useEffect(()=>{z()},[z]),u.useEffect(()=>{_(null),k(null),oe()},[oe]),u.useEffect(()=>{ae()},[ae]);const F=u.useCallback(()=>{z(),oe(),ae()},[z,oe,ae]),ie=u.useMemo(()=>{var Y;return new Map((((Y=re.data)==null?void 0:Y.queues)??[]).map(te=>[te.key,te]))},[re.data]),W=ie.get(Ch),se=!g&&(v==null?void 0:v.reason)==="engine_missing",Z=u.useCallback(()=>{se||F()},[se,F]);if(Wi(Z,o),se)return i.jsx(yi,{page:"Queues"});const de=Math.round(o/1e3),J=S!==null&&fp(S);return i.jsxs(i.Fragment,{children:[i.jsxs(bn,{title:"Queues",description:c??sE,children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:_H($,D,de,d)}),i.jsx("span",{className:"sr-only",role:"status",children:D?"Not reading":$===null?"Connecting":"Live"})]}),!g&&!v&&i.jsx(rE,{}),!g&&v&&i.jsx(Tu,{refusal:v,on_retry:F}),g&&g.queues.length===0?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(bv,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No queues yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Queues are created through the sdlc CLI, the MCP tools or the API. Once one exists, its turns and waiting work show here."})]}):g?i.jsxs(i.Fragment,{children:[i.jsx(CH,{path:n,queues:g.queues,open_id:C,name:I,held:f,timing_of:ie,heavy:W}),y?W?i.jsx(AH,{org:e,timing:W}):re.data?i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Heavy checks are not available"}),i.jsx(ge,{children:"This checkout reads no heavy queue. Pick another queue above."})]}):re.state==="failed"?i.jsx(Tu,{on_retry:()=>void ae()}):i.jsx(Tt,{className:"mt-6 h-40 w-full shrink-0",role:"status","aria-label":"Loading the queue"}):J?i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This queue is no longer available"}),i.jsx(ge,{children:"It was archived, or you can no longer read its Workspace. Pick another queue above."})]}):w&&w.queue.id===C?i.jsx(RH,{org:e,detail:w,name:I,settings_note:l,subject_label:h,thread_subjects:f,timing:ie.get(w.queue.id)}):S?i.jsx(Tu,{refusal:S,on_retry:()=>void oe()}):i.jsx(Tt,{className:"mt-6 h-40 w-full shrink-0",role:"status","aria-label":"Loading the queue"})]}):null]})}function Dh({org:e,subject:t,link:n}){const{href:s,Link:a}=lt();return!t||t.hidden?i.jsx("span",{className:"text-muted-foreground",children:iE}):t.kind==="task"&&n?i.jsx(a,{className:"text-primary hover:underline",href:s(`/org/${e}/tasks/${t.id}`),children:t.title??t.id}):t.kind==="thread"&&!n&&t.id&&!t.id.startsWith("exec-")?i.jsx(a,{className:"text-primary hover:underline",href:s(`${e?`/org/${e}`:""}/threads#thread-${encodeURIComponent(t.id)}`),children:t.title??t.id}):i.jsx("span",{children:t.title??t.id})}function NH(e,t,n){const s=e.freeze?`frozen until ${Xn(e.freeze.lease_until)}`:null;if(e.batch)return{primary:`Batch of ${e.batch.size} · ${t(e.batch.holder,e.batch.holder_subject)}`,secondary:[`Opened ${Xn(e.batch.opened_at)}`,s].filter(Boolean).join(" · "),warn:!1};if(e.turn){const a=e.turn.subject,r=a.hidden?iE:a.title??a.id,o=(e.running_count??1)>1?`${e.running_count} turns · `:"",l=e.turn.landing?" landing":"",c=n&&!!e.turn.hold,d=[c?tE(e.name,e.turn.note):null,e.turn.fixing_since!==void 0?"Fixing forward":null,s].filter(Boolean);return c&&e.turn.fixing_since===void 0&&!s?{primary:`${o}${r}${l}`,secondary:Da(d.join(" · ")),warn:!1}:{primary:`${o}${r}${l}`,secondary:d.length?Da(d.join(" · ")):null,warn:d.length>0}}return{primary:"Nothing running",secondary:s?Da(s):null,warn:!!s}}const Da=e=>e.charAt(0).toUpperCase()+e.slice(1),oE=e=>(e==null?void 0:e.rows.filter(t=>t.turn===fi.label).length)??0;function kH({timing:e}){return e!=null&&e.clears?i.jsx("div",{className:"text-muted-foreground text-xs",children:Da(e.clears)}):null}function SH({timing:e}){const t=oE(e);return t?i.jsx(we,{variant:fi.tone,children:`${t} stalled`}):null}function CH({path:e,queues:t,open_id:n,name:s,held:a,timing_of:r,heavy:o}){const{href:l,Link:c}=lt();return i.jsx(yt,{className:"mt-4 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Queues",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Queue"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Step"}),i.jsx(Q,{children:"Running turn"}),i.jsx(Q,{className:"hidden text-right md:table-cell",children:"Waiting"})]})}),i.jsxs(st,{children:[t.map(d=>{var g;const h=d.id===n,f=hH(d),m=NH(d,s,a),p=d.waiting-(((g=d.batch)==null?void 0:g.remaining)??0),y=r.get(d.id);return i.jsxs(_e,{"data-testid":"queues-row",className:je(h&&"bg-accent"),children:[i.jsxs(X,{children:[i.jsx(c,{className:"text-primary hover:underline",href:l(`${e}?queue=${encodeURIComponent(d.id)}`),"aria-current":h?"page":void 0,children:d.name}),f?i.jsx("div",{className:"text-muted-foreground text-xs",children:f}):null,i.jsxs("div",{className:"text-muted-foreground text-xs md:hidden",children:[p," waiting"]})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(we,{variant:"neutral",children:eE[d.policy.step]})}),i.jsxs(X,{children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:je(!d.batch&&!d.turn&&"text-muted-foreground"),children:m.primary}),i.jsx(SH,{timing:y})]}),m.secondary?i.jsx("div",{className:je("text-xs",m.warn?"text-warning":"text-muted-foreground"),children:m.secondary}):null,i.jsx(kH,{timing:y})]}),i.jsx(X,{className:"hidden text-right md:table-cell",children:p})]},d.id)}),o?i.jsx(DH,{path:e,timing:o,current:n===Ch}):null]})]})})}const Xg=e=>e.turn==="Running";function DH({path:e,timing:t,current:n}){const{href:s,Link:a}=lt(),r=t.rows.filter(Xg).length,o=t.rows.length-r,l=t.error?"Not available":r?[`${r} running`,t.memory].filter(Boolean).join(" · "):"Nothing running";return i.jsxs(_e,{"data-testid":"queues-row",className:je(n&&"bg-accent"),children:[i.jsxs(X,{children:[i.jsx(a,{className:"text-primary hover:underline",href:s(`${e}?queue=${Ch}`),"aria-current":n?"page":void 0,children:nE}),i.jsx("div",{className:"text-muted-foreground text-xs",children:pH}),t.error?null:i.jsxs("div",{className:"text-muted-foreground text-xs md:hidden",children:[o," waiting"]})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(we,{variant:"neutral",children:"Checks"})}),i.jsxs(X,{children:[i.jsx("div",{className:je(!r&&"text-muted-foreground"),children:l}),!r&&!t.error&&t.memory?i.jsx("div",{className:"text-muted-foreground text-xs",children:Da(t.memory)}):null]}),i.jsx(X,{className:"hidden text-right md:table-cell",children:t.error?"—":o})]})}function EH(e){if(!e)return()=>{};const t=new Map(e.rows.filter(s=>s.execution).map(s=>[s.execution,s])),n=new Map;for(const s of e.rows)s.key&&n.set(s.key,n.has(s.key)?null:s);return s=>t.get(s.ref)??n.get(s.subject.id)??void 0}const Kg="No estimate yet";function lE(e){return e?e.turn===fi.label?e.elapsed:[e.elapsed,e.estimate].filter(Boolean).join(" · "):Kg}function cE(e){return e?e.turn===fi.label?aH(e.elapsed):e.estimate?iH(e.estimate):Kg:Kg}function go({id:e,title:t,side:n,children:s}){return i.jsxs("section",{"aria-labelledby":e,className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h3",{id:e,className:"text-sm font-semibold",children:t}),n?i.jsx("span",{className:"text-muted-foreground text-xs",children:n}):null]}),s]})}function u_({org:e,entries:t,landing:n,queue_name:s,subject_label:a,held:r,label:o,time_of:l}){return i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:o,children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:a}),i.jsx(Q,{children:"State"}),l?i.jsx(Q,{children:"Time"}):null]})}),i.jsx(st,{children:t.map(c=>{const d=l==null?void 0:l(c),h=uH(c,n,s,r,(d==null?void 0:d.turn)===fi.label);return i.jsxs(_e,{"data-testid":"queues-running",children:[i.jsxs(X,{children:[i.jsx(Dh,{org:e,subject:c.subject,link:!r}),r&&c.hold&&c.note&&!c.subject.hidden?i.jsx("div",{className:"text-muted-foreground text-xs",children:c.note}):null]}),i.jsx(X,{children:i.jsx(we,{variant:h.tone,children:h.label})}),l?i.jsx(X,{className:"text-muted-foreground text-xs",title:d==null?void 0:d.basis,children:lE(d)}):null]},c.ref)})})]})})}function h_({org:e,row:t}){return t.key?i.jsx(Dh,{org:e,subject:{kind:"thread",id:t.key,title:t.title},link:!1}):i.jsx("span",{children:t.title})}function f_({command:e}){return e?i.jsx("span",{className:"block max-w-xs truncate font-mono text-xs",title:e,children:e}):null}function AH({org:e,timing:t}){const n=t.rows.filter(Xg),s=t.rows.filter(a=>!Xg(a));return i.jsxs(yt,{as:"section","aria-labelledby":"queue-title",className:"mt-6 flex shrink-0 flex-col gap-4 p-4","data-testid":"queues-detail",children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h2",{id:"queue-title",className:"text-lg font-semibold",children:nE}),i.jsx("p",{className:"text-muted-foreground text-sm",children:gH}),t.memory&&!t.error?i.jsx("p",{className:"text-muted-foreground text-xs font-medium",children:Da(t.memory)}):null,i.jsx("p",{className:"text-muted-foreground text-xs",children:xH})]}),t.error?i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Heavy checks could not be read"}),i.jsx(ge,{children:Da(t.error)})]}):t.rows.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running, and nothing waits in this queue."}):i.jsxs(i.Fragment,{children:[i.jsx(go,{id:"queue-running",title:n.length>1?"Running turns":"Running turn",children:n.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running."}):i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Running turns",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Thread"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Command"}),i.jsx(Q,{className:"hidden text-right md:table-cell",children:"Memory"}),i.jsx(Q,{children:"Time"})]})}),i.jsx(st,{children:n.map(a=>i.jsxs(_e,{"data-testid":"queues-running",children:[i.jsxs(X,{children:[i.jsx(h_,{org:e,row:a}),i.jsx("div",{className:"text-muted-foreground text-xs break-all md:hidden",children:[a.command,a.memory].filter(Boolean).join(" · ")})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(f_,{command:a.command})}),i.jsx(X,{className:"hidden text-right tabular-nums md:table-cell",children:a.memory}),i.jsx(X,{className:"text-muted-foreground text-xs",title:a.basis,children:lE(a)})]},a.position))})]})})}),i.jsx(go,{id:"queue-waiting",title:"Waiting",children:s.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing waits."}):i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Waiting entries",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Position"}),i.jsx(Q,{children:"Thread"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Command"}),i.jsx(Q,{className:"hidden text-right md:table-cell",children:"Memory"}),i.jsx(Q,{children:"Turn"}),i.jsx(Q,{children:"Starts"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Note"})]})}),i.jsx(st,{children:s.map(a=>{const r=a.turn===fi.label?fi:{label:a.turn,tone:a.turn==="Next"?"info":"neutral"};return i.jsxs(_e,{"data-testid":"queues-waiting",children:[i.jsx(X,{children:a.position}),i.jsxs(X,{children:[i.jsx(h_,{org:e,row:a}),i.jsx("div",{className:"text-muted-foreground text-xs break-all md:hidden",children:[a.command,a.memory].filter(Boolean).join(" · ")})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(f_,{command:a.command})}),i.jsx(X,{className:"hidden text-right tabular-nums md:table-cell",children:a.memory}),i.jsx(X,{children:i.jsx(we,{variant:r.tone,children:r.label})}),i.jsx(X,{className:"text-muted-foreground text-xs",title:a.basis,children:cE(a)}),i.jsx(X,{className:"hidden md:table-cell",children:a.reason?Da(a.reason):""})]},a.position)})})]})})})]}),i.jsx("p",{className:"text-muted-foreground text-xs",children:vH})]})}function RH({org:e,detail:t,name:n,settings_note:s,subject_label:a,thread_subjects:r,timing:o}){var j;const{queue:l,state:c}=t,d=o?EH(o):void 0,h=oE(o)>0,f=N=>n(N),m=new Map(c.entries.map(N=>[N.ref,N.subject])),p=c.entries.filter(N=>N.turn==="running"),y=c.entries.filter(N=>N.turn!=="running"&&N.batching!=="in_batch"),g=c.batch,b=Math.max(1,p.filter(N=>N.batching!=="in_batch").length),v=g&&l.policy.independent_turns?p.filter(N=>N.batching!=="in_batch"&&N.ref!==g.holder):[],x=c.manager,w=c.freeze,_=((j=l.layer)==null?void 0:j.kind)==="release"?l.layer.stall_hold:void 0,S=_?{who:n(_.by),why:_.reason,until:_.until}:x!=null&&x.hold?{who:n(x.holder,x.holder_subject),why:x.hold.why,until:x.hold.until}:null,k=!g&&p.length===0&&y.length===0;return i.jsxs(yt,{as:"section","aria-labelledby":"queue-title",className:"mt-6 flex shrink-0 flex-col gap-4 p-4","data-testid":"queues-detail",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",{id:"queue-title",className:"text-lg font-semibold",children:l.name}),i.jsx(we,{variant:"neutral",children:eE[l.policy.step]}),i.jsx(we,{variant:"neutral",children:rH[l.management.mode]})]}),l.purpose?i.jsx("p",{className:"text-muted-foreground text-sm",children:l.purpose}):null,o!=null&&o.basis?i.jsx("p",{className:"text-muted-foreground text-xs",children:o.basis}):null,h?i.jsx("p",{className:"text-muted-foreground text-xs",children:nH}):null]}),x?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm","data-testid":"queues-manager",children:[i.jsx(Nz,{className:"text-muted-foreground size-4","aria-hidden":"true"}),i.jsx("span",{className:"text-muted-foreground",children:"Manager"}),i.jsx("span",{className:"font-medium",children:n(x.holder,x.holder_subject)}),i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Lease until ",Xn(x.lease_until),x.serving_until!==void 0?" · serving now":""]})]}):null,w?i.jsxs(pe,{variant:"warning",children:[i.jsx(gz,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Frozen until ",Xn(w.lease_until)]}),i.jsxs(ge,{children:[n(w.holder,w.holder_subject)," froze this queue at ",Xn(w.since),w.label?`: ${w.label}`:"",". Only ",n(w.holder,w.holder_subject),"'s entries start until it thaws."]})]}):null,S?i.jsxs(pe,{variant:"info",children:[i.jsx(Bk,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Stall hold until ",Xn(S.until)]}),i.jsxs(ge,{children:[S.who,S.why?`: ${S.why}`:"",". The first entry is not treated as stalled while it lasts."]})]}):null,k?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running, and nothing waits in this queue."}):i.jsxs(i.Fragment,{children:[g?i.jsxs(go,{id:"queue-running",title:"Running turn",side:`Batch opened by ${n(g.holder,g.holder_subject)} at ${Xn(g.opened_at)}`,children:[i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Batch members",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Landing order"}),i.jsx(Q,{children:a}),i.jsx(Q,{children:"Outcome"})]})}),i.jsx(st,{children:g.members.map((N,O)=>{const T=cH(N.outcome);return i.jsxs(_e,{"data-testid":"queues-member",children:[i.jsx(X,{children:O+1}),i.jsx(X,{children:i.jsx(Dh,{org:e,subject:N.subject??m.get(N.ref)??(r?{kind:"thread",id:N.ref}:void 0),link:!r})}),i.jsx(X,{children:i.jsx(we,{variant:T.tone,children:T.label})})]},N.ref)})})]})}),v.length>0?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-muted-foreground text-xs font-medium",children:"Also running"}),i.jsx(u_,{org:e,entries:v,landing:c.landing,queue_name:l.name,subject_label:a,held:r,label:"Turns running beside the batch",time_of:d})]}):null]}):i.jsx(go,{id:"queue-running",title:p.length>1?"Running turns":"Running turn",children:p.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running."}):i.jsx(u_,{org:e,entries:p,landing:c.landing,queue_name:l.name,subject_label:a,held:r,label:"Running turns",time_of:d})}),i.jsx(go,{id:"queue-waiting",title:"Waiting",children:y.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing waits."}):i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Waiting entries",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Position"}),i.jsx(Q,{children:a}),i.jsx(Q,{className:"hidden md:table-cell",children:"Joined"}),i.jsx(Q,{children:"Turn"}),d?i.jsx(Q,{children:"Starts"}):null,i.jsx(Q,{className:"hidden md:table-cell",children:"Note"})]})}),i.jsx(st,{children:y.map((N,O)=>{const T=d==null?void 0:d(N),I=dH(N,(T==null?void 0:T.turn)===fi.label),L=N.subject.hidden?"":N.note??"";return i.jsxs(_e,{"data-testid":"queues-waiting",children:[i.jsx(X,{children:g?b+O+1:N.position}),i.jsx(X,{children:i.jsx(Dh,{org:e,subject:N.subject,link:!r})}),i.jsx(X,{className:"hidden md:table-cell",children:Xn(N.joined_at)}),i.jsx(X,{children:i.jsx(we,{variant:I.tone,children:I.label})}),d?i.jsx(X,{className:"text-muted-foreground text-xs",title:T==null?void 0:T.basis,children:cE(T)}):null,i.jsx(X,{className:"hidden md:table-cell",children:L})]},N.ref)})})]})})})]}),i.jsx(go,{id:"queue-settings",title:"Settings",children:i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsx(nt,{containerAriaLabel:"Queue settings",children:i.jsx(st,{children:mH(l,f).map(([N,O])=>i.jsxs(_e,{children:[i.jsx(Q,{scope:"row",className:"h-auto w-48 py-2 font-normal",children:N}),i.jsx(X,{children:O})]},N))})})})}),i.jsx("p",{className:"text-muted-foreground text-xs",children:s})]})}const ti="__no_parent__";function dE(e,t){const n=new Set([t]);for(let s=!0;s;){s=!1;for(const a of e)a.parent&&n.has(a.parent)&&!n.has(a.key)&&(n.add(a.key),s=!0)}return n}const $c=(e,t)=>(e.label||e.key).localeCompare(t.label||t.key);function Zn({id:e,label:t,help:n,error:s,children:a}){const r=[n?`${e}-help`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0;return i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:e,children:t}),a(r),n?i.jsx("p",{id:`${e}-help`,className:"text-muted-foreground text-xs",children:n}):null,s?i.jsx("p",{id:`${e}-error`,className:"text-destructive text-sm",children:s}):null]})}function Zg({label:e,children:t}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("span",{className:"text-sm leading-none font-medium",children:e}),i.jsx("span",{className:"text-muted-foreground text-sm break-words",children:t})]})}function m_({id:e,label:t,help:n,checked:s,on_change:a}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(nl,{id:e,className:"mt-0.5",checked:s,"aria-describedby":n?`${e}-help`:void 0,onCheckedChange:r=>a(r===!0)}),i.jsx(Ie,{htmlFor:e,className:"font-normal",children:t})]}),n?i.jsx("p",{id:`${e}-help`,className:"text-muted-foreground pl-6 text-xs",children:n}):null]})}function uE({id:e,legend:t,help:n,error:s,options:a,checked:r,on_change:o,empty:l,notes:c,scroll:d}){const h=[c!=null&&c.length?`${e}-notes`:null,n?`${e}-help`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0;return i.jsxs("fieldset",{className:"m-0 grid min-w-0 gap-2 border-0 p-0","aria-describedby":h,"aria-invalid":s?!0:void 0,children:[i.jsx("legend",{className:"mb-2 text-sm leading-none font-medium",children:t}),c!=null&&c.length?i.jsxs("div",{id:`${e}-notes`,className:"text-warning flex items-start gap-2 text-xs",children:[i.jsx(jt,{className:"mt-0.5 size-3.5 shrink-0","aria-hidden":"true"}),i.jsx("div",{className:"grid gap-0.5",children:c.map(f=>i.jsx("p",{children:f},f))})]}):null,a.length===0&&l?i.jsx("p",{className:"text-muted-foreground text-sm",children:l}):null,i.jsx("div",{className:d?"grid max-h-[200px] grid-cols-1 gap-2 overflow-y-auto rounded-md border p-3 sm:grid-cols-2":"grid grid-cols-1 gap-2 sm:grid-cols-2",tabIndex:d?0:void 0,role:d?"group":void 0,"aria-label":d?`${t} list`:void 0,children:a.map((f,m)=>i.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[i.jsx(nl,{id:`${e}-${m}`,className:"mt-0.5",checked:r.has(f.value),onCheckedChange:p=>{const y=new Set(r);p===!0?y.add(f.value):y.delete(f.value),o(y)}}),i.jsx(Ie,{htmlFor:`${e}-${m}`,className:"min-w-0 font-normal break-words",children:f.label})]},f.value))}),n?i.jsx("p",{id:`${e}-help`,className:"text-muted-foreground text-xs",children:n}):null,s?i.jsx("p",{id:`${e}-error`,className:"text-destructive text-sm",children:s}):null]})}function Lc({context:e,action:t,title:n="Two-factor sign-in needed",changing:s="Changing the org"}){const a=e.two_factor==="enroll";return i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(mz,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:n}),i.jsxs(ge,{children:[i.jsx("p",{children:a?`Turn on two-factor sign-in in Account Settings, then come back here and ${t}.`:`${s} needs a two-factor sign-in. Sign in again with your authenticator in Account Settings, then come back here and ${t}.`}),i.jsx(U,{asChild:!0,variant:"outline",size:"sm",className:"mt-2 h-auto min-h-8 py-1.5 whitespace-normal text-left",children:i.jsx("a",{href:e.settings_href,target:"_blank",rel:"noreferrer",children:"Open Account Settings in a new tab"})})]})]})}const Ba=e=>e.two_factor==="ok";function ll({refusal:e,context:t,subject:n,action:s,changing:a,authority_title:r}){if((e==null?void 0:e.kind)==="two_factor")return i.jsx(Lc,{context:t,action:s,changing:a,title:`Could not save ${n}`});const o=Ba(t)?null:i.jsx(Lc,{context:t,action:s,changing:a});if(!e)return o;const l=e.kind==="changed"?"The org changed since you opened this":e.kind==="authority"?r??`Could not save ${n}`:null;return i.jsxs(i.Fragment,{children:[o,i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),l?i.jsx(ke,{children:l}):null,i.jsx(ge,{children:e.message})]})]})}function hE({id:e,value:t,on_change:n,none:s,options:a,described_by:r}){return i.jsxs(St,{value:t,onValueChange:n,children:[i.jsx(wt,{id:e,"aria-describedby":r,children:i.jsx(Ct,{placeholder:"Choose a team"})}),i.jsxs(_t,{children:[s?i.jsx(Ue,{value:ti,children:s}):null,a.map(o=>i.jsx(Ue,{value:o.key,children:o.label||o.key},o.key))]})]})}function cl(e){const[t,n]=u.useState(!1),[s,a]=u.useState(null);return{saving:t,refusal:s,set_refusal:a,run:async o=>{n(!0),a(null);try{const l=await o();l?a(l):e()}finally{n(!1)}}}}function dl({saving:e,blocked:t,described_by:n,children:s}){return i.jsx(U,{type:"submit",disabled:e,"aria-disabled":t||void 0,"aria-describedby":t?n:void 0,children:s})}const fE=(e,t)=>t==="hosted"?`Lowercase letters, digits, _ and -, starting with a letter. It names the ${e} in posts, and cannot change later.`:`Lowercase letters, digits, _ and -, starting with a letter. It names the ${e} in posts and in sdlc org, and cannot change later.`;function TH({open:e,chart:t,team:n,save:s,on_close:a,context:r=ul,scope:o="full",parents:l}){var C;const c=r.host==="hosted",[d,h]=u.useState(""),[f,m]=u.useState(""),[p,y]=u.useState(""),[g,b]=u.useState(ti),[v,x]=u.useState({}),{saving:w,refusal:_,set_refusal:S,run:k}=cl(a),j=((C=t.teams.find(M=>M.parent===null))==null?void 0:C.key)??null;u.useEffect(()=>{e&&(h(""),m((n==null?void 0:n.label)??""),y((n==null?void 0:n.description)??""),b((n==null?void 0:n.parent)??(c&&j&&(!l||l.includes(j))?j:ti)),x({}),S(null))},[e,n,S,c,j,l]);const N=M=>{const H=t.teams.find(z=>z.key===M);return H?H.label||H.key:M??""},O=n?dE(t.teams,n.key):new Set,T=[...t.teams].filter(M=>!O.has(M.key)&&(!l||l.includes(M.key))).sort((M,H)=>M.key===j?-1:H.key===j?1:$c(M,H)),I=n?n.label||n.key:"",L=o==="description",$=!Ba(r),A=n?L?"save the description":"save the team":"add the team",D=M=>{if(M.preventDefault(),$)return;if(!n){const K=c?f.trim():d.trim();if(!K){x(c?{label:"Give the team a name."}:{key:"Give the team a key."});return}if(c&&g===ti){x({parent:"Choose the parent team."});return}const oe=c?K:f.trim()||K;k(()=>s({action:"add",kind:"team",key:K,...f.trim()?{label:f.trim()}:{},...p.trim()?{description:p.trim()}:{},...g!==ti?{parent:g}:{}},`Team ${oe} added.`));return}if(!L&&!f.trim()){x({label:c?"Give the team a name.":"Give the team a label."});return}const H=g===ti?null:g,z={...!L&&f.trim()!==n.label.trim()?{label:f.trim()}:{},...p.trim()!==(n.description??"").trim()?{description:p.trim()}:{},...!c&&H!==n.parent?{parent:H}:{}};if(Object.keys(z).length===0){a();return}k(()=>s({action:"edit",kind:"team",key:n.key,...z},L?`Saved the description of ${I}.`:`Team ${f.trim()} saved.`))},E=n?L?`Edit the description of ${I}`:`Edit team ${I}`:"Add team";let R;return L?R="Say what the team works on. Only the description is yours to change here.":c?R=n?"Rename the team or say what it works on.":"Add a team to the organization.":n?R=i.jsxs(i.Fragment,{children:["Its key, ",i.jsx("span",{className:"font-mono",children:n.key}),", names it in posts and in sdlc org and does not change."]}):R="Add a team to this repository's local org.",i.jsx(yn,{open:e,onOpenChange:M=>M||w?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:D,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:E}),i.jsx(kn,{children:R})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:_,context:r,subject:L?"the description":"the team",action:A}),!n&&!c?i.jsx(Zn,{id:"org-team-key",label:"Key",help:fE("team",r.host),error:v.key,children:M=>i.jsx(bt,{id:"org-team-key",className:"font-mono",value:d,autoComplete:"off","aria-invalid":v.key?!0:void 0,"aria-describedby":M,onChange:H=>{h(H.target.value),x({})}})}):null,L&&n?i.jsx(Zg,{label:"Name",children:n.parent?`${I} · under ${N(n.parent)}`:I}):i.jsx(Zn,{id:"org-team-label",label:c?"Name":n?"Label":"Label (optional)",help:c?n?void 0:"Its key is made from the name.":n?void 0:"Shown on the chart; the key when left empty.",error:v.label,children:M=>i.jsx(bt,{id:"org-team-label",value:f,"aria-invalid":v.label?!0:void 0,"aria-describedby":M,onChange:H=>{m(H.target.value),x({})}})}),i.jsx(Zn,{id:"org-team-description",label:L?"Description":"Description (optional)",children:()=>i.jsx(Gn,{id:"org-team-description",rows:3,placeholder:"What the team does",value:p,onChange:M=>y(M.target.value)})}),L?null:c&&n?i.jsx(Zg,{label:"Parent team",children:n.parent?N(n.parent):"None: the organization itself"}):i.jsx(Zn,{id:"org-team-parent",label:"Parent team",help:"Where the team sits; its posts report up through the team above.",error:v.parent,children:M=>i.jsx(hE,{id:"org-team-parent",value:g,on_change:H=>{b(H),x({})},none:c?void 0:"No parent (a root team)",options:T,described_by:M})})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:w,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:w,blocked:$,children:n?w?"Saving…":"Save":w?"Adding…":"Add team"})]})]})})})}const OH=(e,t)=>e.length===t.size&&e.every(n=>t.has(n));function zH({open:e,chart:t,job:n,save:s,on_close:a,context:r=ul}){const[o,l]=u.useState(""),[c,d]=u.useState(""),[h,f]=u.useState(""),[m,p]=u.useState(ti),[y,g]=u.useState(new Set),[b,v]=u.useState(!1),[x,w]=u.useState(!0),[_,S]=u.useState({}),{saving:k,refusal:j,set_refusal:N,run:O}=cl(a);u.useEffect(()=>{e&&(l(""),d((n==null?void 0:n.label)??""),f((n==null?void 0:n.description)??""),p((n==null?void 0:n.parent)??ti),g(new Set((n==null?void 0:n.fills)??[])),v((n==null?void 0:n.requires_person)??!1),w((n==null?void 0:n.escalable)??!0),S({}),N(null))},[e,n,N]);const T=n?dE(t.job_functions,n.key):new Set,I=[...t.job_functions].filter(E=>!T.has(E.key)).sort($c),L=[...t.slots].sort($c).map(E=>({value:E.key,label:E.label||E.key})),$=!Ba(r),A=n?"save the job function":"add the job function",D=E=>{if(E.preventDefault(),$)return;if(!n){if(!o.trim()){S({key:"Give the job function a key."});return}O(()=>s({action:"add",kind:"job_function",key:o.trim(),...c.trim()?{label:c.trim()}:{},...h.trim()?{description:h.trim()}:{},...m!==ti?{parent:m}:{},fills:[...y],requires_person:b,escalable:x},`Job function ${c.trim()||o.trim()} added.`));return}if(!c.trim()){S({label:"Give the job function a label."});return}const R=m===ti?null:m,C={...c.trim()!==n.label.trim()?{label:c.trim()}:{},...h.trim()!==(n.description??"").trim()?{description:h.trim()}:{},...R!==n.parent?{parent:R}:{},...OH(n.fills,y)?{}:{fills:[...y]},...b!==n.requires_person?{requires_person:b}:{},...x!==n.escalable?{escalable:x}:{}};if(Object.keys(C).length===0){a();return}O(()=>s({action:"edit",kind:"job_function",key:n.key,...C},`Job function ${c.trim()} saved.`))};return i.jsx(yn,{open:e,onOpenChange:E=>E||k?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:D,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:n?`Edit job function ${n.label||n.key}`:"Add job function"}),i.jsxs(kn,{children:["Its job description: what it does, the slots it fills and who may hold its posts.",n?i.jsxs(i.Fragment,{children:[" ","Its key, ",i.jsx("span",{className:"font-mono",children:n.key}),", does not change."]}):null]})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:j,context:r,subject:"the job function",action:A}),n?null:i.jsx(Zn,{id:"org-function-key",label:"Key",help:fE("job function",r.host),error:_.key,children:E=>i.jsx(bt,{id:"org-function-key",className:"font-mono",value:o,autoComplete:"off","aria-invalid":_.key?!0:void 0,"aria-describedby":E,onChange:R=>{l(R.target.value),S({})}})}),i.jsx(Zn,{id:"org-function-label",label:n?"Label":"Label (optional)",error:_.label,children:E=>i.jsx(bt,{id:"org-function-label",value:c,"aria-invalid":_.label?!0:void 0,"aria-describedby":E,onChange:R=>{d(R.target.value),S({})}})}),i.jsx(Zn,{id:"org-function-description",label:"Job description (optional)",children:()=>i.jsx(Gn,{id:"org-function-description",rows:3,placeholder:"What this job function does",value:h,onChange:E=>f(E.target.value)})}),i.jsx(Zn,{id:"org-function-parent",label:"Parent function",help:"Its posts report to the post of the parent function.",children:E=>i.jsx(hE,{id:"org-function-parent",value:m,on_change:p,none:"No parent (a root function)",options:I,described_by:E})}),i.jsx(uE,{id:"org-function-fills",legend:"Slots it fills",options:L,checked:y,on_change:g,empty:r.host==="hosted"?"This organization has no slots yet.":"This org has no slots yet; add them with sdlc org add slot."}),i.jsx(m_,{id:"org-function-requires-person",label:"Requires a person",help:"Only a person may hold its posts.",checked:b,on_change:v}),i.jsx(m_,{id:"org-function-escalable",label:"Escalable",help:"When no holder can decide, the decision goes up the reporting line. Off, it waits for a holder of this function.",checked:x,on_change:w})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:k,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:k,blocked:$,children:n?k?"Saving…":"Save":k?"Adding…":"Add job function"})]})]})})})}const MH=/^[a-z][a-z0-9_-]{0,63}$/;function $H(e){return e.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^[^a-z]+/,"").slice(0,64).replace(/-+$/,"")}function LH({open:e,chart:t,slot:n,save:s,on_close:a,context:r=ul}){const[o,l]=u.useState(""),[c,d]=u.useState(""),[h,f]=u.useState(!1),[m,p]=u.useState(""),[y,g]=u.useState({}),{saving:b,refusal:v,set_refusal:x,run:w}=cl(a);u.useEffect(()=>{e&&(l((n==null?void 0:n.label)??""),d((n==null?void 0:n.key)??""),f(!1),p((n==null?void 0:n.description)??""),g({}),x(null))},[e,n,x]);const _=!Ba(r),S=n?"save the slot":"add the slot",k=j=>{if(j.preventDefault(),_)return;const N=o.trim();if(n){if(!N){g({label:"Give the slot a label."});return}const T={...N!==(n.label??"").trim()?{label:N}:{},...m.trim()!==(n.description??"").trim()?{description:m.trim()}:{}};if(Object.keys(T).length===0){a();return}w(()=>s({action:"edit",kind:"slot",key:n.key,...T},`Saved slot ${N}.`));return}const O={...N?{}:{label:"Give the slot a label."},...MH.test(c)?t.slots.some(T=>T.key===c)?{key:`Slot ${c} already exists.`}:{}:{key:"Use lowercase letters, digits, _ and -, starting with a letter, at most 64 characters."}};g(O),!(O.label||O.key)&&w(()=>s({action:"add",kind:"slot",key:c,label:N,...m.trim()?{description:m.trim()}:{}},`Added slot ${N}.`))};return i.jsx(yn,{open:e,onOpenChange:j=>j||b?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:k,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:n?`Edit ${n.label||n.key}`:"Add slot"}),i.jsx(kn,{children:"A slot is a workflow role a project fills from its team's posts. Job functions name the slots they fill."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:v,context:r,subject:"the slot",action:S}),i.jsx(Zn,{id:"org-slot-label",label:"Label",help:"How the slot is named on the chart and in project settings.",error:y.label,children:j=>i.jsx(bt,{id:"org-slot-label",value:o,"aria-invalid":y.label?!0:void 0,"aria-describedby":j,onChange:N=>{l(N.target.value),!n&&!h&&d($H(N.target.value)),g({})}})}),n?i.jsx(Zg,{label:"Key",children:i.jsx("span",{className:"font-mono",children:n.key})}):i.jsx(Zn,{id:"org-slot-key",label:"Key",help:"Lowercase letters, digits, _ and -, starting with a letter, at most 64 characters. It can't be changed after you save.",error:y.key,children:j=>i.jsx(bt,{id:"org-slot-key",className:"font-mono",value:c,autoComplete:"off","aria-invalid":y.key?!0:void 0,"aria-describedby":j,onChange:N=>{d(N.target.value),f(!0),g({})}})}),i.jsx(Zn,{id:"org-slot-description",label:"Description (optional)",children:()=>i.jsx(Gn,{id:"org-slot-description",rows:3,placeholder:"What this role does",value:m,onChange:j=>p(j.target.value)})})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:b,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:b,blocked:_,children:n?b?"Saving…":"Save":b?"Adding…":"Add slot"})]})]})})})}function PH({open:e,chart:t,binding:n,names:s,save:a,confirm:r,on_close:o,context:l=ul,hosted:c}){var $;const[d,h]=u.useState(new Set),[f,m]=u.useState(""),[p,y]=u.useState({}),{saving:g,refusal:b,set_refusal:v,run:x}=cl(o),w=(n==null?void 0:n.slot)??null;if(u.useEffect(()=>{!e||!n||(h(new Set(c&&n.source!=="override"?[]:n.posts.map(A=>A.post))),m(n.source==="override"?n.reason??"":""),y({}),v(null))},[e,w,v]),!n)return null;const _=s.slot(n.slot),S=($=t.project)!=null&&$.team?t.teams.find(A=>{var D;return A.key===((D=t.project)==null?void 0:D.team)}):void 0,k=S?S.label||S.key:"the owning team",j=new Set(t.job_functions.filter(A=>A.fills.includes(n.slot)).map(A=>A.key)),N=[...t.posts].map(A=>A.post).sort(s.byPost).map(A=>{const D=j.has(A.split("/")[1]??"")?`${s.post(A)} (fills ${_})`:s.post(A),E=c==null?void 0:c.holders(A);return{value:A,label:c?E?`${D}: ${E}`:`${D} (no holder)`:D}}),O=c?[...d].sort(s.byPost).flatMap(A=>[...j.has(A.split("/")[1]??"")?[]:[`${s.post(A)} is not in the job description of ${_}.`],...c.chain.has(A.split("/")[0]??"")?[]:[`${s.post(A)} is outside ${c.owner} and the teams above it.`]]):[],T=!Ba(l),I=A=>{A.preventDefault();const D={...d.size===0?{posts:"Choose at least one post."}:{},...f.trim()?{}:{reason:"Give the reason for the override."}};y(D),!(D.posts||D.reason||T)&&x(()=>a({action:"bind",slot:n.slot,posts:[...d],reason:f.trim()},`Override of ${_} saved.`))},L=async()=>{await r({title:`Clear the override of ${_}?`,description:c?`${_} goes back to its team's posts: ${c.baseline}. The override and its reason stay in the audit trail.`:"It goes back to the posts its job descriptions name, and its reason is not kept.",action_label:c?"Clear override":"Clear",destructive:!0})&&x(()=>a({action:"unbind",slot:n.slot},`Override of ${_} cleared.`))};return i.jsx(yn,{open:e,onOpenChange:A=>A||g?null:o(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:I,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsxs(Nn,{children:["Override ",_]}),i.jsxs(kn,{children:["Bind ",_," in this project to the posts you choose instead of its"," ",c?"team’s":"job descriptions’"," posts. The override is reported with its reason, who set it and when."]})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[b||T?i.jsx("div",{id:"org-override-refusal",className:"grid gap-4",children:i.jsx(ll,{refusal:b,context:l,subject:"the override",action:c?"save":"save the override",changing:c?"Changing this project’s slots":void 0,authority_title:c?"Your changes were not saved":void 0})}):null,i.jsx(uE,{id:"org-override-posts",legend:"Posts",help:c?`(fills ${_}) marks the posts whose job function fills ${_}.`:"A post outside its job description is marked on the chart.",notes:O,scroll:!!c,error:p.posts,options:N,checked:d,on_change:A=>{h(A),y(D=>({...D,posts:void 0}))}}),i.jsx(Zn,{id:"org-override-reason",label:"Reason",error:p.reason,children:A=>i.jsx(Gn,{id:"org-override-reason",rows:2,placeholder:"Why this slot needs other posts",value:f,"aria-invalid":p.reason?!0:void 0,"aria-describedby":A,onChange:D=>{m(D.target.value),y(E=>({...E,reason:void 0}))}})}),c?null:i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Made as ",i.jsx("span",{className:"font-mono",children:"person:user"}),", who must hold the lead post of ",k," or of a team above it."]})]}),i.jsxs(jn,{className:"mt-6",children:[n.source==="override"?i.jsx(U,{type:"button",variant:"ghost",className:"sm:mr-auto",disabled:g,onClick:()=>void L(),children:"Clear override"}):null,i.jsx(U,{type:"button",variant:"outline",disabled:g,onClick:o,children:"Cancel"}),i.jsx(dl,{saving:g,blocked:T,described_by:"org-override-refusal",children:g?"Saving…":"Save override"})]})]})})})}function IH(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} or ${e[e.length-1]}`}function GH({open:e,chart:t,names:n,save:s,on_close:a,context:r}){var A;const o=t.authority,l=u.useMemo(()=>o?new Set(o.post_pairs):null,[o]),c=D=>!l||l.has(D),d=((A=t.teams.find(D=>D.parent===null))==null?void 0:A.key)??null,h=[...t.teams].filter(D=>!l||[...l].some(E=>E.startsWith(`${D.key}/`))).sort((D,E)=>D.key===d?-1:E.key===d?1:$c(D,E)),[f,m]=u.useState(""),[p,y]=u.useState(""),[g,b]=u.useState({}),{saving:v,refusal:x,set_refusal:w,run:_}=cl(a);u.useEffect(()=>{var D;e&&(m(((D=h[0])==null?void 0:D.key)??""),y(""),b({}),w(null))},[e,w]);const S=new Set(t.posts.filter(D=>D.post.startsWith(`${f}/`)).map(D=>D.post.split("/")[1])),k=[],j=D=>{for(const E of[...t.job_functions].filter(R=>R.parent===D).sort($c))k.push(E),j(E.key)};j(null);const N=k.filter(D=>c(`${f}/${D.key}`)&&!S.has(D.key)),O=f!==""&&N.length===0,T=!Ba(r)||O,I=D=>{if(D.preventDefault(),T)return;const E={...f?{}:{team:"Choose a team."},...p?{}:{job:"Choose a job function."}};b(E),!(E.team||E.job)&&_(()=>s({action:"add",kind:"post",key:`${f}/${p}`},`Added post ${n.job(p)} · ${n.team(f)}.`))},L=O?"Every job function already has a post in this team.":"A team has one post per job function; functions already staffed in this team are left out.",$=(o==null?void 0:o.ask)??[];return i.jsx(yn,{open:e,onOpenChange:D=>D||v?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:I,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Add post"}),i.jsx(kn,{children:"A post is a job function staffed in a team. People in this post report to the post above it."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:x,context:r,subject:"the post",action:"add the post"}),i.jsx(Zn,{id:"org-post-team",label:"Team",help:"The team the post is in.",error:g.team,children:D=>i.jsxs(St,{value:f,onValueChange:E=>{m(E),y(""),b({})},children:[i.jsx(wt,{id:"org-post-team","aria-describedby":D,"aria-invalid":g.team?!0:void 0,children:i.jsx(Ct,{placeholder:"Choose a team"})}),i.jsx(_t,{children:h.map(E=>i.jsx(Ue,{value:E.key,children:E.label||E.key},E.key))})]})}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Zn,{id:"org-post-function",label:"Job function",help:L,error:g.job,children:D=>i.jsxs(St,{value:p,disabled:O,onValueChange:E=>{y(E),b({})},children:[i.jsx(wt,{id:"org-post-function","aria-describedby":D,"aria-invalid":g.job?!0:void 0,children:i.jsx(Ct,{placeholder:O?"Every job function has a post here":"Choose a job function"})}),i.jsx(_t,{children:N.map(E=>i.jsx(Ue,{value:E.key,children:E.label||E.key},E.key))})]})}),o&&!o.administer?i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Only the job functions directly below a post you hold are listed.",$.length?` For others, ask ${IH($)}.`:""]}):null]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:v,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:v,blocked:T,described_by:O?"org-post-function-help":void 0,children:v?"Adding…":"Add post"})]})]})})})}function HH({open:e,chart:t,post:n,names:s,members:a,save:r,on_close:o,context:l}){const[c,d]=u.useState({state:"loading"}),[h,f]=u.useState(""),[m,p]=u.useState(null),[y,g]=u.useState(-1),{saving:b,refusal:v,set_refusal:x,run:w}=cl(o),_=u.useRef(0),S=u.useCallback(async()=>{const z=_.current+=1;d({state:"loading"});const K=await a();z===_.current&&d(K.ok?{state:"read",members:K.data}:{state:"failed"})},[a]);u.useEffect(()=>{e&&(f(""),p(null),g(-1),x(null),S())},[e,S,x]);const k=t.posts.find(z=>z.post===n);if(!n||!k)return null;const j=s.post(n),N=new Set(k.holders.map(z=>z.id)),T=t.posts.some(z=>z.reports_to===n)&&k.holders.length>0?k.holders[0]:null,I=h.trim().toLowerCase(),L=c.state==="read"?c.members.filter(z=>!N.has(z.id)).filter(z=>!I||[z.label,z.detail,z.email].some(K=>K==null?void 0:K.toLowerCase().includes(I))):[],$=c.state==="read"&&c.members.every(z=>N.has(z.id)),A=c.state==="read"&&!$&&L.length>0,D=A&&y>=0&&y<L.length?L[y]:null,E=z=>`org-holder-option-${z.id}`,R=!Ba(l)||!m||T!==null,C=z=>{if(!A)return;const K=L.length-1,oe=re=>{var Ne,Se;z.preventDefault(),g(re),(Se=(Ne=document.getElementById(E(L[re])))==null?void 0:Ne.scrollIntoView)==null||Se.call(Ne,{block:"nearest"})};z.key==="ArrowDown"?oe(Math.min(D?y+1:0,K)):z.key==="ArrowUp"?oe(D?Math.max(y-1,0):K):z.key==="Home"&&D?oe(0):z.key==="End"&&D?oe(K):z.key==="Enter"&&D&&(m==null?void 0:m.id)!==D.id&&(z.preventDefault(),p(D))},M=T?void 0:m?"Only members of the organization can hold its posts. Members who already hold it are left out.":"Choose a member to add.",H=z=>{z.preventDefault(),!(R||!m)&&w(()=>r({action:"hold",post:n,member:m.id},`Added ${m.label} to ${j}.`))};return i.jsx(yn,{open:e,onOpenChange:z=>z||b?null:o(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:H,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsxs(Nn,{children:["Add holder to ",j]}),i.jsx(kn,{children:"The member holds this post and reports as it does."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:v,context:l,subject:"the holder",action:"add the holder"}),T?i.jsxs(pe,{variant:"info",id:"org-holder-one",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ge,{children:["This post takes one holder. Remove ",s.member(T)," first, then add the new holder."]})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-holder-member",children:"Member"}),i.jsx(bt,{id:"org-holder-member",role:"combobox","aria-expanded":A,"aria-controls":A?"org-holder-members":void 0,"aria-activedescendant":D?E(D):void 0,"aria-autocomplete":"list","aria-describedby":M?"org-holder-member-help":void 0,placeholder:"Search members by name, username or email",autoComplete:"off",value:h,disabled:T!==null,onChange:z=>{f(z.target.value),g(-1)},onKeyDown:C}),i.jsx("div",{className:"max-h-56 overflow-y-auto rounded-md border",children:c.state==="loading"?i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 px-3 py-2 text-sm",role:"status",children:[i.jsx(vn,{className:"size-4","aria-hidden":"true"}),"Loading members…"]}):c.state==="failed"?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-3 py-2",children:[i.jsx("p",{className:"text-destructive text-sm",children:"Could not read the members."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void S(),children:"Retry"})]}):$?i.jsx("p",{className:"text-muted-foreground px-3 py-2 text-sm",children:"Every member already holds this post."}):L.length===0?i.jsxs("p",{className:"text-muted-foreground px-3 py-2 text-sm",children:["No member matches “",h.trim(),"”."]}):i.jsx("ul",{id:"org-holder-members",role:"listbox","aria-label":"Members",className:"m-0 list-none p-1",children:L.map((z,K)=>{const oe=(m==null?void 0:m.id)===z.id,re=(D==null?void 0:D.id)===z.id;return i.jsxs("li",{id:E(z),role:"option","aria-selected":oe,className:`cursor-pointer rounded-sm px-2 py-1.5 ${oe?"bg-accent text-accent-foreground":re?"bg-muted":"hover:bg-muted"} ${re?"ring-ring ring-2 ring-inset":""}`,onClick:()=>{T||(g(K),p(z))},children:[i.jsxs("div",{className:"text-sm font-medium break-words",children:[z.label,z.detail&&L.filter(Ne=>Ne.label===z.label).length>1?` (${z.detail})`:""]}),z.email?i.jsx("div",{className:"text-muted-foreground text-xs break-all",children:z.email}):null]},z.id)})})}),M?i.jsx("p",{id:"org-holder-member-help",className:"text-muted-foreground text-xs",children:M}):null]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:b,onClick:o,children:"Cancel"}),i.jsx(dl,{saving:b,blocked:R,described_by:T?"org-holder-one":M?"org-holder-member-help":void 0,children:b?"Adding…":"Add holder"})]})]})})})}function mE(e){const[t,n]=u.useState(null),s=u.useRef(t);u.useEffect(()=>{s.current=t},[t]);const a=u.useCallback(c=>{var d;(d=s.current)==null||d.resolve(c),n(null)},[]),r=u.useCallback(c=>new Promise(d=>{var h;(h=s.current)==null||h.resolve(!1),n({...c,resolve:d})}),[]);u.useEffect(()=>()=>{var c;return(c=s.current)==null?void 0:c.resolve(!1)},[]);const o=!Ba(e),l=i.jsx(bf,{open:t!==null,onOpenChange:c=>c?null:a(!1),children:i.jsxs(yf,{children:[i.jsxs(wf,{children:[i.jsx(jf,{children:t==null?void 0:t.title}),i.jsx(Nf,{className:"whitespace-pre-line",children:t==null?void 0:t.description})]}),t&&o?i.jsx(Lc,{context:e,action:t.action}):null,i.jsxs(_f,{children:[i.jsx(Ev,{children:(t==null?void 0:t.cancel_label)??"Cancel"}),i.jsx(GS,{variant:t!=null&&t.destructive?"destructive":"default","aria-disabled":o||void 0,onClick:c=>{if(o){c.preventDefault();return}a(!0)},children:t==null?void 0:t.action_label})]})]})});return{confirm:r,confirm_dialog:l}}function Do({label:e,on_edit:t,on_remove:n,items:s}){const a=s??[...t?[{label:"Edit",on_select:t}]:[],...n?[{label:"Remove",on_select:n,destructive:!0}]:[]];return i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon",className:"-my-1 shrink-0","aria-label":`More actions for ${e}`,children:i.jsx(xv,{className:"size-3.5","aria-hidden":"true"})})}),i.jsx(bd,{align:"end",children:a.map(r=>i.jsx(Uo,{className:r.destructive?"text-destructive focus:text-destructive":void 0,onSelect:r.on_select,children:r.label},r.label))})]})}function VH({label:e,message:t,bound:n,on_dismiss:s}){return i.jsxs(pe,{variant:"destructive",role:"alert",className:"mb-3",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:[e," was not removed"]}),i.jsxs(ge,{children:[i.jsx("p",{children:t}),n!=null&&n.projects.length?i.jsx("ul",{role:"list",className:"bg-card text-foreground m-0 mt-2 grid list-none gap-3 rounded-md border p-3",children:n.projects.map(a=>i.jsxs("li",{className:"grid gap-0.5",children:[i.jsxs("a",{className:"text-primary text-sm underline underline-offset-2",href:a.href,children:["Settings of ",a.name]}),i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Override set by ",a.set_by??"a former member"]})]},a.href))}):null,n&&n.more>0?i.jsxs("p",{className:"mt-2",children:["And ",n.more," more ",n.more===1?"project":"projects",". Clear these and try again to see the rest. An org owner can open any project you cannot."]}):null,i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:s,children:"Dismiss"})]})]})}const ul={host:"local",two_factor:"ok",settings_href:""},Eh={open:{label:"Open",tone:"info"},accepted:{label:"Accepted",tone:"success"},rejected:{label:"Rejected",tone:"error"},withdrawn:{label:"Withdrawn",tone:"neutral"}},UH={added:{label:"Added",tone:"success"},changed:{label:"Changed",tone:"warning"},removed:{label:"Removed",tone:"error"}},BH={team:["team","teams"],job_function:["job function","job functions"],slot:["slot","slots"],post:["post","posts"],fill:["fill","fills"]},WH=["team","job_function","slot","post","fill"];function pb(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function FH(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} or ${e[e.length-1]}`}function p_(e){return e.charAt(0).toLowerCase()+e.slice(1)}function pa(e){const t=s=>pb(WH.filter(a=>e[a][s]>0).map(a=>{const r=e[a][s];return`${r} ${BH[a][r===1?0:1]}`}));return[["Adds","adds",t("added")],["Changes","changes",t("changed")],["Removes","removes",t("removed")]].filter(([,,s])=>s).map(([s,a,r],o)=>`${o===0?s:a} ${r}`).join("; ")||"No changes"}function mi(e){return new Date(e).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function qH(e){const t=e.requested_at?`Proposed by ${e.requested_by} on ${mi(e.requested_at)}`:`Proposed by ${e.requested_by}`;return e.status==="open"||!e.decided_at?t:`${t} · ${Eh[e.status].label} by ${e.decided_by??"a former member"} on ${mi(e.decided_at)}`}function YH({source:e}){return i.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1","data-testid":"org-proposal-source",children:[i.jsx("span",{className:"shrink-0",children:"From package"}),e.href?i.jsx("a",{className:"min-h-6 min-w-0 break-words leading-6 text-primary underline underline-offset-2",href:e.href,children:e.label}):i.jsx("span",{className:"min-w-0 break-words text-foreground",children:e.label}),e.withdrawn&&e.readable!==!1?i.jsx(we,{className:"shrink-0",variant:"warning",children:"Version withdrawn"}):null]})}const XH={team:"team",job_function:"job function",slot:"slot"};function pE(e,t){return e==="own"?"this org's package":e==="softwaredlc"?"SoftwareDLC's package":t?`another organization's package (${t})`:"another organization's package"}function KH(e){return e&&`${e[0].toUpperCase()}${e.slice(1)}`}function Pc({children:e}){return i.jsx("span",{className:"font-mono",children:e})}function cc({title:e,heading:t="strong",children:n}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("h3",{className:t==="muted"?"text-muted-foreground text-sm font-medium":"text-sm font-semibold",children:e}),i.jsx("div",{className:"grid gap-1 text-sm break-words",children:n})]})}function ZH(e){const t=XH[e.kind],n=i.jsx(Pc,{children:e.key??e.label}),s=e.org_key?i.jsx(Pc,{children:e.org_key}):e.org_label,a=i.jsxs(i.Fragment,{children:[` If it is the same ${t}, give it the key `,s," in the package and publish again."]});return e.reason==="key"?i.jsxs(i.Fragment,{children:[n,` will be added as a new ${t}; its key is close to the org's `,s,` (${e.org_label}).`,a]}):i.jsxs(i.Fragment,{children:[n,` will be added as a new ${t}; the org's `,s,` has the same name ${e.label}.`,a]})}function gE({matches:e}){return i.jsxs(i.Fragment,{children:[e.matches.map(t=>i.jsx("p",{"data-testid":"org-package-match",children:ZH(t)},`${t.kind}:${t.key??t.label}:${t.org_key??t.org_label}`)),e.truncated?i.jsx("p",{children:"More may match; check the chart."}):null]})}function g_(e){return e?i.jsxs(i.Fragment,{children:["under ",i.jsx(Pc,{children:e})]}):"at the top level"}function Qg(e){return e.field==="name"?i.jsxs(i.Fragment,{children:[i.jsx(Pc,{children:e.key}),` keeps its name ${e.org??""}; the package names it ${e.package??""}. Propose a rename on the chart, or change the package.`]}):i.jsxs(i.Fragment,{children:[i.jsx(Pc,{children:e.key})," stays ",g_(e.org),"; the package has it ",g_(e.package),". Change the package to propose this: team moves are not available in a proposal."]})}const er=e=>`${e.kind}:${e.key}:${e.field}:${e.org??""}:${e.package??""}`;function xE({items:e}){return i.jsx(i.Fragment,{children:e.map(t=>i.jsx("p",{"data-testid":"org-package-not-proposed",children:Qg(t)},er(t)))})}function QH({placements:e}){return i.jsx(i.Fragment,{children:e.map(t=>i.jsx("p",{"data-testid":"org-package-placement",children:t.under?`${t.name} will be added under ${t.under.name}.`:`${t.name} will be added at the top level.`},t.key??t.name))})}function gb(e){return e==="key"?"by API key":"in the app"}function JH(e,t){const[n,s]=u.useState(e?{state:"loading"}:{state:"off"});return u.useEffect(()=>{if(!e||!t){e||s({state:"off"});return}let a=!0;return e.list().then(r=>{a&&(r.ok?s({state:"read",proposals:r.data}):r.refusal.status===404||r.refusal.reason==="not_found"?s({state:"off"}):s({state:"failed",message:r.refusal.message}))}),()=>{a=!1}},[e,t]),n}function x_({proposal:e,on_open:t}){const n=Eh[e.status];return i.jsxs("li",{className:"border-b px-4 py-2.5 last:border-b-0","data-testid":"org-proposal",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(U,{type:"button",variant:"link",size:"sm",className:"h-auto p-0 text-left whitespace-normal",onClick:t,children:e.title}),i.jsx(we,{variant:n.tone,children:n.label})]}),i.jsxs("p",{className:"text-muted-foreground mt-1 text-xs",children:[e.status==="open"?`Proposed by ${e.requested_by} on ${mi(e.requested_at)}`:`${n.label} by ${e.decided_by??"a former member"} on ${mi(e.decided_at??e.requested_at)}`,e.via==="key"?" by API key":null,e.source?` · From ${e.source.label}`:null,` · ${pa(e.counts)}`]})]})}const eV="Changes members propose to the org's teams, job functions, posts and slots. Nothing changes until someone who may make the change accepts it.";function tV({listed:e,on_propose:t,on_propose_package:n,on_open:s}){const[a,r]=u.useState(!1);if(e.state==="off"||e.state==="loading")return null;const o=e.state==="read"?e.proposals:[],l=o.filter(d=>d.status==="open"),c=o.filter(d=>d.status!=="open");return i.jsxs("section",{"aria-labelledby":"org-chart-proposals",className:"mt-6 min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[i.jsxs("div",{className:"min-w-0 flex-1 basis-64",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{id:"org-chart-proposals",className:"text-lg font-semibold",children:"Proposals"}),l.length?i.jsx(we,{variant:"info",children:`${l.length} open`}):null]}),i.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:eV})]}),i.jsxs("div",{className:"flex flex-wrap gap-2",children:[i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:t,children:[i.jsx(jg,{className:"size-4","aria-hidden":"true"}),"Propose a change"]}),n?i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:n,children:[i.jsx(cf,{className:"size-4","aria-hidden":"true"}),"Propose from a package…"]}):null]})]}),i.jsxs("div",{className:"mt-3 grid gap-2",children:[e.state==="failed"?i.jsxs("p",{className:"text-destructive text-sm",role:"alert",children:["Could not read the proposals. ",e.message]}):null,e.state==="read"&&o.length===0?i.jsxs(yt,{className:"flex flex-col items-center gap-2 p-6 text-center",children:[i.jsx(jg,{className:"text-muted-foreground size-5","aria-hidden":"true"}),i.jsx("p",{className:"text-sm font-medium",children:"No proposals yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Propose a change to the org's structure for someone with the authority to accept."})]}):null,l.length?i.jsx(yt,{className:"overflow-hidden",children:i.jsx("ul",{role:"list",className:"m-0 list-none p-0","aria-label":"Open proposals",children:l.map(d=>i.jsx(x_,{proposal:d,on_open:()=>s(d)},d.id))})}):null,c.length?i.jsxs("div",{children:[i.jsxs(U,{type:"button",variant:"ghost",size:"sm","aria-expanded":a,"aria-controls":"org-chart-proposals-decided",onClick:()=>r(d=>!d),children:[a?i.jsx(rf,{className:"size-4","aria-hidden":"true"}):i.jsx(ld,{className:"size-4","aria-hidden":"true"}),`Decided (${c.length})`]}),a?i.jsx(yt,{className:"mt-2 overflow-hidden",children:i.jsx("ul",{id:"org-chart-proposals-decided",role:"list",className:"m-0 list-none p-0","aria-label":"Decided proposals",children:c.map(d=>i.jsx(x_,{proposal:d,on_open:()=>s(d)},d.id))})}):null]}):null]})]})}const nV="Nothing you change here is saved to the organization. Submit the proposal for review, or discard it. A proposal can add teams but not rename, move or remove them, and it never changes who holds a post.";function sV({draft:e,on_submit:t,on_discard:n}){var c;const s=((c=e.moved)==null?void 0:c.state)==="conflict"?e.moved.names:null,a=!!e.moved,r=e.total===0?"No changes yet":`${e.total} ${e.total===1?"change":"changes"}`,o=e.total===0||!!s,l=a?jt:jg;return i.jsxs(pe,{variant:a?"warning":"info",role:"status",className:"mt-6",children:[i.jsx(l,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:a?"The org changed while you drafted":"You are drafting a proposal"}),i.jsxs(ge,{children:[i.jsx("p",{id:"org-draft-why",children:s?`The org changed what your draft changes: ${pb(s)}. Discard the draft and start again from the org as it is now.`:a?"We moved your draft onto the org as it is now and kept your changes. Check the chart, then submit again.":nV}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[i.jsx(U,{type:"button",size:"sm","aria-disabled":o||void 0,"aria-describedby":o?s?"org-draft-why":"org-draft-count":void 0,onClick:()=>o?void 0:t(),children:"Submit proposal"}),i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:n,children:"Discard draft"}),i.jsx("span",{id:"org-draft-count",className:"text-muted-foreground text-xs",children:r})]})]})]})}const vE={proposal_empty:"The proposal changes nothing in the org."};function iV(e,t){const n=`${e.coordinate} ${e.version}`;if(t.code==="proposal_duplicate"&&t.duplicate){const{duplicate:s}=t;return`${s.requested_by} already proposed this version: '${s.title}', opened ${gb(s.via)}.`}return t.code==="package_version_withdrawn"?t.newest_version?`${n} was withdrawn. Choose ${t.newest_version}, its newest usable version.`:`${n} was withdrawn. It has no usable version now.`:t.code==="not_found"||t.reason==="not_found"?"This package or version can no longer be read.":vE[t.code??""]??t.message}function aV({open:e,draft:t,submit:n,on_close:s,on_done:a,on_open_proposal:r}){const[o,l]=u.useState(""),[c,d]=u.useState(""),[h,f]=u.useState(null),[m,p]=u.useState(null),[y,g]=u.useState(null),b=t.package,[v,x]=u.useState(!1),w=u.useRef(!1);u.useEffect(()=>{e&&(f(null),p(null),g(null))},[e]);const _=async S=>{if(S.preventDefault(),w.current)return;const k=o.trim();if(!k||k.length>200){f("Give the proposal a title of at most 200 characters.");return}f(null),p(null),g(null),x(!0),w.current=!0;try{const j=await n({title:k,...c.trim()?{note:c.trim()}:{}});if(!j.ok){p(b?iV(b,j.refusal):vE[j.refusal.code??""]??j.refusal.message),b&&j.refusal.code==="proposal_duplicate"&&g(j.refusal.duplicate??null);return}j.data.state==="proposed"&&(l(""),d("")),a(j.data,k)}finally{w.current=!1,x(!1)}};return i.jsx(yn,{open:e,onOpenChange:S=>S?null:s(),children:i.jsx(wn,{className:"sm:max-w-lg",children:i.jsxs("form",{onSubmit:S=>void _(S),className:"grid gap-4",noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Submit proposal"}),i.jsx(kn,{children:"Someone who may make these changes reviews it. Nothing in the organization changes until it is accepted."})]}),m?i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not submit the proposal"}),i.jsxs(ge,{children:[i.jsx("p",{children:m}),y&&r?i.jsx("div",{className:"mt-2",children:i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>r(y),children:"Open proposal"})}):null]})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-proposal-title",children:"Title"}),i.jsx(bt,{id:"org-proposal-title",value:o,maxLength:200,"aria-invalid":h?!0:void 0,"aria-describedby":h?"org-proposal-title-error":void 0,onChange:S=>l(S.target.value)}),h?i.jsx("p",{id:"org-proposal-title-error",className:"text-destructive text-sm",children:h}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-proposal-note",children:"Note (optional)"}),i.jsx(Gn,{id:"org-proposal-note",value:c,rows:3,maxLength:4e3,placeholder:"Why the org should make this change","aria-describedby":"org-proposal-note-help",onChange:S=>d(S.target.value)}),i.jsx("p",{id:"org-proposal-note-help",className:"text-muted-foreground text-xs",children:"At most 4000 characters."})]}),i.jsx("p",{className:"text-muted-foreground text-xs break-words",children:b?`From ${b.coordinate} ${b.version} · ${pa(t.counts)}`:pa(t.counts)}),i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:s,children:"Cancel"}),i.jsxs(U,{type:"submit","aria-disabled":v||void 0,children:[v?i.jsx(vn,{className:"size-4","aria-hidden":"true"}):null,v?"Submitting…":"Submit proposal"]})]})]})})})}const rV=[{kind:"team",title:"Teams"},{kind:"job_function",title:"Job functions"},{kind:"slot",title:"Slots"},{kind:"post",title:"Posts"},{kind:"fill",title:"Fills"}];function oV({entry:e,decided:t}){const n=!t&&e.state==="settled",s=UH[e.change];return i.jsxs("li",{className:"grid gap-1 border-b py-2","data-testid":"org-proposal-entry",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.change==="added"?null:i.jsx(we,{variant:s.tone,children:s.label}),i.jsx("span",{className:"text-sm font-medium",children:e.name}),n?i.jsx(we,{variant:"neutral",children:"Already in the org"}):null,!t&&e.state==="conflict"?i.jsx(we,{variant:"error",children:"Changed in the org since"}):null]}),[...e.where,...e.fields,...!t&&e.now?[e.now]:[]].map(a=>i.jsx("p",{className:"text-muted-foreground text-xs break-words",children:a},a))]})}function v_(e,t){if(t.code==="proposal_conflict"&&e){const n=e.entries.filter(s=>s.state==="conflict").map(s=>s.name);if(n.length){const s=`The org changed what this proposal changes: ${pb(n)}.`,a=e.proposal.source&&!e.proposal.source.withdrawn?e.proposal.source:void 0;if(a)return e.proposal.mine?`${s} Withdraw it, then propose it again.`:e.may_reject?`${s} Reject it, then propose ${a.label} again.`:`${s} You can ask ${e.proposal.requested_by} to withdraw it and propose ${a.label} again.`;if(e.proposal.mine)return`${s} Withdraw it and propose again from the org as it is now.`;const r=`ask ${e.proposal.requested_by} to withdraw it and propose again.`;return e.may_reject?`${s} Reject it, or ${r}`:`${s} You can ${r}`}}return t.code==="revision_conflict"?"Someone else changed the org. We read it again; check the proposal and accept again.":t.message}function lV({source:e,via:t}){const n=Ga(),s=e.content_hash,a=async()=>{if(s)try{await navigator.clipboard.writeText(s),n.success("Copied the content hash.")}catch{n.error("Could not copy the content hash. Select it in the tooltip instead.")}},r=e.readable!==!1&&e.owner,o=r&&e.published_at?` on ${mi(e.published_at)}`:"",l=[r?KH(pE(e.owner,e.organization_name)):null,r&&e.published_by_name?`published by ${e.published_by_name}${o}`:o?`published${o}`:null,t?`proposed ${gb(t)}`:null].filter(Boolean),c=s?s.replace(/^sha256:/,"").slice(0,7):"";return i.jsxs("p",{className:"text-muted-foreground text-xs break-words","data-testid":"org-proposal-provenance",children:[s?i.jsxs(i.Fragment,{children:[i.jsxs(wd,{children:[i.jsx(_d,{asChild:!0,children:i.jsx("span",{className:"font-mono",tabIndex:0,children:c})}),i.jsx(ol,{className:"break-all font-mono",children:s})]}),i.jsx(U,{type:"button",variant:"ghost",size:"xs-icon",className:"mx-0.5 align-middle","aria-label":"Copy content hash",onClick:()=>void a(),children:i.jsx(gv,{className:"size-3.5","aria-hidden":"true"})})," · "]}):null,l.join(" · ")]})}function cV(e){var a,r;const t=((a=e.proposal.source)==null?void 0:a.newest_version)??null,n="There is no usable version now.";if(e.may_reject&&!e.proposal.mine)return t?`Reject it, then propose ${t} if the org still wants it.`:`Reject it. ${n}`;if(e.proposal.mine)return t?`Withdraw it, then propose ${t}.`:`Withdraw it. ${n}`;const s=(r=e.ask)!=null&&r.length?FH(e.ask):"an org admin";return t?`Ask ${s} to reject it.`:`Ask ${s} to reject it. ${n}`}function dV(e){var r,o;const t=(r=e.source)==null?void 0:r.withdrawn_at;if(!((o=e.source)!=null&&o.withdrawn)||!t)return null;const n=`Version withdrawn ${mi(t)}`;if(!e.decided_at)return`${n}.`;const s=Date.parse(t)<Date.parse(e.decided_at)?"before":"after",a=e.status==="accepted"?"this proposal was accepted":e.status==="rejected"?"it was rejected":"it was withdrawn";return`${n}, ${s} ${a}.`}function uV({since:e}){const{previewed:t,opened:n}=e;if(t.revision===n.revision)return null;const s=new Set(t.not_proposed.map(er)),a=new Set(n.not_proposed.map(er)),r=n.not_proposed.filter(d=>!s.has(er(d))),o=t.not_proposed.filter(d=>!a.has(er(d))),c=pa(t.counts)===pa(n.counts)&&r.length===0&&o.length===0;return i.jsxs(pe,{variant:"info",role:"status","data-testid":"org-proposal-since-preview",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"The org changed since the preview"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[`This proposal opened at revision ${n.revision}; you previewed it at revision ${t.revision}, so its change was worked out again.`,c?" The counts are the same as previewed.":` Previewed: ${p_(pa(t.counts))}. Opened: ${p_(pa(n.counts))}.`]}),r.map(d=>i.jsxs("p",{children:["Now not part of this proposal: ",Qg(d)]},`now-not:${er(d)}`)),o.map(d=>i.jsxs("p",{children:["Now part of this proposal: ",Qg(d)]},`now:${er(d)}`))]})]})}function hV({proposal:e,contract:t,context:n,check_two_factor:s,on_close:a,on_decided:r,since:o=null,on_preview_version:l}){const[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),[y,g]=u.useState(!1),[b,v]=u.useState(null),[x,w]=u.useState("ok"),[_,S]=u.useState(null),[k,j]=u.useState(""),N=(e==null?void 0:e.id)??null,O=u.useRef(N);O.current=N;const T=u.useCallback(async()=>{if(!N)return;const W=await t.read(N);O.current===N&&(W.ok?(d(W.data),f(null)):f(W.refusal.message))},[t,N]);u.useEffect(()=>{if(d(null),f(null),p(null),g(!1),j(""),!N)return;T(),s().then(w);const W=()=>void s().then(se=>O.current===N&&w(se));return window.addEventListener("focus",W),()=>window.removeEventListener("focus",W)},[N,T,s]);const I=(c==null?void 0:c.proposal)??e,L=(I==null?void 0:I.title)??"",$=(I==null?void 0:I.status)==="open",A=(c==null?void 0:c.entries.some(W=>W.state==="conflict"))??!1,D=!!c&&(c.may_accept||c.may_reject),E=x==="ok",R={...n,two_factor:x},C=async W=>{if(N){v(W),p(null);try{const se=W==="accept"?await t.accept(N):W==="reject"?await t.reject(N,k.trim()||void 0):await t.withdraw(N);if(se.ok){S(null),r(W==="accept"?`Accepted ${L}.`:W==="reject"?`Rejected ${L}.`:`Withdrew ${L}.`);return}if(S(null),se.refusal.code==="mfa_challenge_required"||se.refusal.code==="mfa_enrollment_required"){w(se.refusal.code==="mfa_enrollment_required"?"enroll":"challenge");return}W==="accept"&&g(!0);const Z=await t.read(N);if(O.current!==N)return;const de=Z.ok?Z.data:c;Z.ok&&d(Z.data),p({title:`${L} was not ${W==="accept"?"accepted":W==="reject"?"rejected":"withdrawn"}`,message:v_(de,se.refusal)})}finally{v(null)}}},M=c&&A&&!m?v_(c,{code:"proposal_conflict",message:""}):null,H=(c==null?void 0:c.proposal.source)??null,z=!!H&&H.readable!==!1,K=$&&!!c&&z&&!!(H!=null&&H.withdrawn),oe=(H==null?void 0:H.newest_version)??null,re=$&&c&&c.may_reject&&!c.may_accept&&!A&&!K?c.accept_refusal??null:null,Ne=!E||A||!!re||K||b!==null,Se=[E?null:"org-proposal-two-factor",A?"org-proposal-refusal":null,re?"org-proposal-accept-refusal":null,K?"org-proposal-withdrawn":null].filter(Boolean).join(" "),ae=!$&&c&&z?dV(c.proposal):null,F=H?(c==null?void 0:c.not_proposed)??[]:[],ie=$&&H?(c==null?void 0:c.possible_matches)??null:null;return i.jsxs(i.Fragment,{children:[i.jsx(yn,{open:e!==null,onOpenChange:W=>W?null:a(),children:i.jsxs(wn,{className:"flex max-h-[90vh] flex-col overflow-hidden sm:max-w-2xl",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:L}),i.jsx(kn,{asChild:!0,children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[I?i.jsx(we,{variant:Eh[I.status].tone,children:Eh[I.status].label}):null,i.jsx("span",{children:I?qH(I):null}),c!=null&&c.proposal.source?i.jsx(YH,{source:c.proposal.source}):null]})}),H?i.jsx(lV,{source:H,via:c==null?void 0:c.proposal.via}):null,H&&!z?i.jsx("p",{className:"text-muted-foreground text-xs",children:"You can't read this package, so its version's state isn't shown."}):null,ae?i.jsx("p",{className:"text-muted-foreground text-xs",children:ae}):null]}),i.jsxs("div",{className:"-mx-1 grid min-h-0 flex-1 gap-4 overflow-y-auto px-1","data-testid":"org-proposal-body",children:[o?i.jsx(uV,{since:o}):null,K&&c?i.jsxs(pe,{id:"org-proposal-withdrawn",variant:"warning",role:"status",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This proposal can't be accepted"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[H!=null&&H.withdrawn_at?`Version withdrawn ${mi(H.withdrawn_at)}, after this proposal opened; it can't be accepted.`:"Its version was withdrawn after this proposal opened; it can't be accepted."," ",cV(c)]}),oe&&(H!=null&&H.package_id)&&l?i.jsx("div",{className:"mt-2",children:i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:()=>l({package_id:H.package_id,version:oe}),children:[i.jsx(cf,{className:"size-4","aria-hidden":"true"}),`Preview ${oe}`]})}):null]})]}):null,I!=null&&I.note?i.jsx("p",{className:"text-sm whitespace-pre-line",children:I.note}):null,I!=null&&I.decision_note?i.jsxs("div",{className:"grid gap-1",children:[i.jsx("span",{className:"text-sm font-medium",children:"Decision note"}),i.jsx("p",{className:"text-muted-foreground text-sm whitespace-pre-line",children:I.decision_note})]}):null,h?i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not read the proposal"}),i.jsx(ge,{children:i.jsx("p",{children:h})})]}):null,!c&&!h?i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:"Reading the proposal…"}):null,c?rV.map(W=>{const se=c.entries.filter(Z=>Z.kind===W.kind);return se.length?i.jsxs("div",{className:"grid",children:[i.jsx("h3",{className:"text-muted-foreground text-sm font-medium",children:W.title}),i.jsx("ul",{role:"list",className:"m-0 list-none p-0",children:se.map(Z=>i.jsx(oV,{entry:Z,decided:!$},`${Z.kind}:${Z.name}`))})]},W.kind):null}):null,ie&&ie.matches.length?i.jsx(cc,{title:"Possible matches",heading:"muted",children:i.jsx(gE,{matches:ie})}):null,F.length?i.jsx(cc,{title:"Not part of this proposal",heading:"muted",children:i.jsx(xE,{items:F})}):null,$&&c&&!D&&c.decide_refusal?i.jsxs(pe,{variant:"info",role:"status",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can't accept or reject this proposal"}),i.jsx(ge,{children:i.jsx("p",{children:c.decide_refusal})})]}):null,re?i.jsxs(pe,{id:"org-proposal-accept-refusal",variant:"info",role:"status",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can't accept this proposal"}),i.jsx(ge,{children:i.jsx("p",{children:re})})]}):null,$&&D&&!E?i.jsx("div",{id:"org-proposal-two-factor",children:i.jsx(Lc,{context:R,action:"decide the proposal",changing:"Accepting or rejecting a proposal"})}):null,m||M?i.jsxs(pe,{id:"org-proposal-refusal",variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:(m==null?void 0:m.title)??(y?`${L} was not accepted`:`${L} can't be accepted`)}),i.jsx(ge,{children:i.jsx("p",{children:(m==null?void 0:m.message)??M})})]}):null]}),i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:a,children:"Close"}),$&&(c!=null&&c.may_withdraw)?i.jsx(U,{type:"button",variant:"outline",onClick:()=>S("withdraw"),children:"Withdraw proposal"}):null,$&&(c!=null&&c.may_reject)?i.jsx(U,{type:"button",variant:"outline",onClick:()=>S("reject"),children:"Reject"}):null,$&&c&&(c.may_accept||c.may_reject&&(A||re||K))?i.jsxs(U,{type:"button","aria-disabled":Ne||void 0,"aria-describedby":Se||void 0,onClick:()=>Ne?void 0:void C("accept"),children:[b==="accept"?i.jsx(vn,{className:"size-4","aria-hidden":"true"}):null,b==="accept"?"Accepting…":"Accept"]}):null]})]})}),i.jsx(bf,{open:_!==null,onOpenChange:W=>W?null:S(null),children:i.jsxs(yf,{children:[i.jsxs(wf,{children:[i.jsx(jf,{children:_==="reject"?`Reject ${L}?`:`Withdraw ${L}?`}),i.jsx(Nf,{children:_==="reject"?`${(I==null?void 0:I.requested_by)??"The requester"} sees your note on the proposal.`:"Nobody can accept it after this."})]}),_==="reject"&&!E?i.jsx("div",{id:"org-proposal-reject-two-factor",children:i.jsx(Lc,{context:R,action:"reject the proposal",changing:"Accepting or rejecting a proposal"})}):null,_==="reject"?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-proposal-reject-note",children:"Note (optional)"}),i.jsx(Gn,{id:"org-proposal-reject-note",value:k,rows:2,maxLength:4e3,placeholder:"Why you are rejecting it",onChange:W=>j(W.target.value)})]}):null,i.jsxs(_f,{children:[i.jsx(Ev,{children:"Cancel"}),_==="reject"?i.jsx(U,{type:"button",variant:"destructive","aria-disabled":!E||b!==null||void 0,"aria-describedby":E?void 0:"org-proposal-reject-two-factor",onClick:()=>!E||b?void 0:void C("reject"),children:b==="reject"?"Rejecting…":"Reject proposal"}):i.jsx(U,{type:"button","aria-disabled":b!==null||void 0,onClick:()=>b?void 0:void C("withdraw"),children:b==="withdraw"?"Withdrawing…":"Withdraw"})]})]})})]})}const b_="Packages you can't read aren't listed. A read grant to a team reaches its own members, not its sub-teams; ask an org admin or the package's publisher for read access.",fV=100,mV=20;function pV(e){if(!e.truncated)return null;const t=e.packages.length>=fV,n=e.packages.some(s=>s.versions.length>=mV);return t&&n?"Showing the first 100 packages and each package's 20 newest versions":n?"Showing each package's 20 newest versions":"Showing the first 100 packages"}function gV(e){return[e.status==="deprecated"?`${e.version} · Deprecated`:e.version,e.published_at?mi(e.published_at):null,e.published_by_name??null].filter(Boolean).join(" · ")}function xV(e,t){return e.code==="package_version_withdrawn"?e.newest_version?`${t} was withdrawn. Choose ${e.newest_version}, its newest usable version.`:`${t} was withdrawn. It has no usable version now.`:e.code==="not_found"||e.reason==="not_found"?"This package or version can no longer be read.":e.message}function vV({open:e,contract:t,packages_href:n,initial:s,preview:a,on_close:r,on_previewed:o}){const[l,c]=u.useState({state:"loading"}),[d,h]=u.useState(""),[f,m]=u.useState(""),[p,y]=u.useState(!1),[g,b]=u.useState(null),v=u.useRef(0),x=u.useCallback(async()=>{var R;const L=v.current+=1;c({state:"loading"}),b(null),y(!1);const $=t.packageChoices?await t.packageChoices():{ok:!1,refusal:{message:"This organization offers no package choices."}};if(L!==v.current)return;if(!$.ok){c({state:"failed",message:$.refusal.message});return}const A=$.data;c({state:"read",choices:A});const D=s&&A.packages.find(C=>C.package_id===s.package_id)||A.packages[0];h((D==null?void 0:D.package_id)??"");const E=s&&D&&D.package_id===s.package_id?D.versions.find(C=>C.version===s.version):void 0;m((E==null?void 0:E.version)??((R=D==null?void 0:D.versions[0])==null?void 0:R.version)??"")},[t,s]);u.useEffect(()=>{if(!e){v.current+=1,y(!1);return}x()},[e,x]);const w=l.state==="read"?l.choices:null,_=(w==null?void 0:w.packages.find(L=>L.package_id===d))??null,S=(w==null?void 0:w.packages.filter(L=>L.owner==="own"))??[],k=(w==null?void 0:w.packages.filter(L=>L.owner==="softwaredlc"))??[],j=w?pV(w):null,N=!!w&&w.packages.length===0,O=L=>{var $,A;h(L),b(null),m(((A=($=w==null?void 0:w.packages.find(D=>D.package_id===L))==null?void 0:$.versions[0])==null?void 0:A.version)??"")},T=async L=>{if(L.preventDefault(),p||!_||!f)return;const $=v.current;y(!0),b(null);try{const A=await a({package_id:_.package_id,version:f});if($!==v.current)return;if(!A.ok){b(xV(A.refusal,`${_.coordinate} ${f}`));return}o(A.data)}finally{$===v.current&&y(!1)}},I=l.state==="failed"?l.message:g;return i.jsx(yn,{open:e,onOpenChange:L=>L?null:r(),children:i.jsx(wn,{className:"sm:max-w-lg",children:i.jsxs("form",{className:"grid gap-4",onSubmit:L=>void T(L),noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Propose from a package"}),i.jsx(kn,{children:"Choose a published version of an org structure package. You see what it adds and changes in the org before you submit."})]}),I?i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:l.state==="failed"?"Could not read the packages":"Could not preview this version"}),i.jsxs(ge,{children:[i.jsx("p",{children:I}),l.state==="failed"?i.jsx("div",{className:"mt-2",children:i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void x(),children:"Retry"})}):null]})]}):null,l.state==="loading"?i.jsxs("div",{className:"grid gap-4",role:"status","aria-label":"Reading the packages",children:[i.jsx(Tt,{className:"h-9 w-full"}),i.jsx(Tt,{className:"h-9 w-full"})]}):null,N?i.jsxs("div",{className:"grid justify-items-center gap-2 py-4 text-center",children:[i.jsx(cf,{className:"text-muted-foreground size-5","aria-hidden":"true"}),i.jsx("p",{className:"text-sm font-medium",children:"No org structure packages to propose from"}),i.jsx("p",{className:"text-muted-foreground text-xs",children:b_}),i.jsx("a",{className:"text-primary text-sm underline underline-offset-2",href:n,children:"Go to Packages"})]}):null,w&&_?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-package-choice",children:"Package"}),i.jsxs(St,{value:d,onValueChange:O,children:[i.jsx(wt,{id:"org-package-choice","aria-describedby":"org-package-coordinate",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[S.length?i.jsxs(Yw,{children:[i.jsx(Ig,{children:"This org"}),S.map(L=>i.jsx(Ue,{value:L.package_id,children:L.name},L.package_id))]}):null,k.length?i.jsxs(Yw,{children:[i.jsx(Ig,{children:"SoftwareDLC"}),k.map(L=>i.jsx(Ue,{value:L.package_id,children:L.name},L.package_id))]}):null]})]}),i.jsxs("p",{id:"org-package-coordinate",className:"text-muted-foreground text-xs break-words",children:[i.jsx("span",{className:"font-mono",children:_.coordinate}),_.organization_name?` · ${_.organization_name}`:null]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-package-version",children:"Version"}),i.jsxs(St,{value:f,onValueChange:L=>{m(L),b(null)},children:[i.jsx(wt,{id:"org-package-version",children:i.jsx(Ct,{})}),i.jsx(_t,{children:_.versions.map(L=>i.jsx(Ue,{value:L.version,children:gV(L)},L.version))})]})]})]}):null,w&&!N?i.jsxs("div",{className:"grid gap-1",children:[j?i.jsx("p",{className:"text-muted-foreground text-xs",children:j}):null,i.jsx("p",{className:"text-muted-foreground text-xs",children:b_})]}):null,i.jsx(jn,{children:w&&_?i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:r,children:"Cancel"}),i.jsxs(U,{type:"submit","aria-disabled":p||void 0,children:[p?i.jsx(vn,{className:"size-4","aria-hidden":"true"}):null,p?"Loading…":"Preview proposal"]})]}):i.jsx(U,{type:"button",variant:"outline",onClick:r,children:"Close"})})]})})})}function bV({draft:e,org:t,duplicate_day:n,on_submit:s,on_choose:a,on_discard:r,on_open_proposal:o}){const l=e.package,c=`${l.coordinate} ${l.version}`,d=l.open_duplicate,h=!d&&e.total===0,f=i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:a,children:"Choose another version"}),i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:r,children:"Discard preview"})]});if(d)return i.jsxs(pe,{variant:"warning",role:"status",className:"mt-6","data-testid":"org-package-banner",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:`Already proposed: '${d.title}' by ${d.requested_by}`}),i.jsxs(ge,{children:[i.jsx("p",{children:`${d.requested_by} proposed this version ${gb(d.via)}${n?` on ${mi(n)}`:""}. Review that proposal instead of proposing it again.`}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[i.jsx(U,{type:"button",size:"sm",onClick:()=>o(d),children:"Open proposal"}),f]})]})]});const m=[`From ${pE(l.owner,l.organization_name)}`,l.published_by_name?`, published by ${l.published_by_name}`:"",l.published_at?` on ${mi(l.published_at)}`:"",`, laid over ${t} as it was at revision ${l.revision}.`].join("");return i.jsxs(pe,{variant:"info",role:"status",className:"mt-6","data-testid":"org-package-banner",children:[i.jsx(cf,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{className:"break-words",children:h?`This version adds and changes nothing in ${t}`:i.jsxs(i.Fragment,{children:["You are proposing ",l.href?i.jsx("a",{className:"text-primary underline underline-offset-2",href:l.href,children:c}):c]})}),i.jsxs(ge,{children:[i.jsx("p",{children:h?"Choose another version, or discard this preview.":`${m} A package proposal adds and changes; it never removes. Nothing is saved to the organization until someone accepts it.`}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[h?null:i.jsx(U,{type:"button",size:"sm",onClick:s,children:"Submit proposal"}),f,h?null:i.jsx("span",{className:"text-muted-foreground text-xs",children:pa(e.counts)})]})]})]})}function yV({draft:e}){const t=e.package,n=e.total>0,s=n?t.placements:[],a=n?t.possible_matches:{matches:[],truncated:!1};return!s.length&&!a.matches.length&&!t.not_proposed.length?null:i.jsxs("section",{"aria-labelledby":"org-package-before",className:"mt-6 min-w-0",children:[i.jsx("h2",{id:"org-package-before",className:"text-lg font-semibold",children:"Before you submit"}),i.jsxs(yt,{className:"mt-3 grid gap-4 p-4",children:[s.length?i.jsx(cc,{title:"Where new teams go",children:i.jsx(QH,{placements:s})}):null,a.matches.length?i.jsx(cc,{title:"Possible matches",children:i.jsx(gE,{matches:a})}):null,t.not_proposed.length?i.jsx(cc,{title:"Not part of this proposal",children:i.jsx(xE,{items:t.not_proposed})}):null]})]})}function wV(e){return!!(e!=null&&e.package)}const y_={title:"Discard your draft?",description:"Your changes to the draft are lost. Nothing in the organization changed.",action_label:"Discard draft",destructive:!0,action:"discard the draft"},w_=e=>({title:"Leave this package preview?",description:`Leaving drops this preview of ${e}. Nothing was proposed and nothing in the organization changed.`,action_label:"Leave preview",cancel_label:"Stay",destructive:!1,action:"leave the preview"}),_V={local:"Who holds each post and who reports to whom in this repository's local org, worked out from its teams, job functions and posts.",hosted:"Who holds each post and who reports to whom in this organization, worked out from its teams, job functions and posts."},jV="Covered: someone holds a post that fills the slot. Vacant: posts fill it but nobody holds them. Uncovered: no job function fills it.",NV=4,xb=e=>({paddingLeft:16+24*Math.min(e,NV)}),Ah={covered:{label:"Covered",tone:"success"},vacant:{label:"Vacant",tone:"warning"},uncovered:{label:"Uncovered",tone:"error"}};function kV(){const e=Vn().org;if(!e)throw new Error("The Org chart page rendered without the org seam.");return e}function SV({host:e="local",org:t=""}={}){var de;const n=kV(),[s,a]=u.useState({state:"loading"}),[r,o]=u.useState(null),l=u.useRef(0),c=u.useRef(null),d=u.useCallback(J=>{const G=async Y=>{const te=l.current+=1;c.current&&clearTimeout(c.current);const ce=await n.chart();if(te!==l.current)return;if(ce.ok){o({chart:ce.data,at:new Date().toISOString()}),a({state:"read"});return}const{refusal:be}=ce;if(be.reason==="no_local_org"){o(null),a({state:"none",seedable:be.seedable!==!1});return}if(e==="hosted"&&(be.reason==="not_found"||be.status===404)){o(null),a({state:"missing"});return}if(be.retry&&be.reason==="store_locked"&&Y>0){const fe=be.retry_after??10;a({state:"busy",retry_after:fe}),c.current=setTimeout(()=>void G(Y-1),fe*1e3);return}a({state:"failed",refusal:be})};return G(J)},[n,e]);u.useEffect(()=>(d(1),()=>{l.current+=1,c.current&&clearTimeout(c.current)}),[d]);const h=()=>void d(1),f=s.state==="none"||s.state==="missing"?null:r,{href:m}=lt(),p=Ga(),y=m("/settings/account"),g=n.proposals,b=JH(g,(f==null?void 0:f.at)??null),v=!!g&&b.state!=="off",[x,w]=u.useState(null),[_,S]=u.useState(!1),[k,j]=u.useState(null),{confirm:N,confirm_dialog:O}=mE(ul),T=wV(x)?x:null,[I,L]=u.useState(null),[$,A]=u.useState(null),D=g!=null&&g.packageChoices&&g.draft.beginFromPackage?g:null,E=u.useMemo(()=>x&&!x.package&&g?{draft:x,change:g.draft.change,on_draft:w}:null,[x,g]),R=$V(n,h,(x==null?void 0:x.chart)??(f==null?void 0:f.chart)??EV,e,y,E),C=T?null:R,M=n.twoFactor,H=u.useCallback(async()=>M?M():"ok",[M]),z=!!x&&(x.total>0||!!x.package),K=T?`${T.package.coordinate} ${T.package.version}`:null,oe=u.useMemo(()=>K?w_(K):y_,[K]),re=u.useRef(null),Ne=u.useRef(()=>{});Ne.current=()=>{g==null||g.draft.discard(),w(null)},u.useEffect(()=>{var fe;if(!z)return;let J=!0;const G=((fe=re.current)==null?void 0:fe.closest("[data-dock-pane]"))??null,Y=$e=>{$e.preventDefault()},te=()=>{J=!1,window.removeEventListener("beforeunload",Y),document.removeEventListener("click",ce,!0),G==null||G.removeEventListener(__,be)},ce=$e=>{var Qt,ht,it;if(!J||$e.defaultPrevented||$e.button!==0||$e.metaKey||$e.ctrlKey||$e.shiftKey||$e.altKey)return;const ze=$e.target;if(G&&(((Qt=ze==null?void 0:ze.closest)==null?void 0:Qt.call(ze,"[data-dock-pane]"))??document.querySelector("[data-dock-active]"))!==G)return;const q=(ht=ze==null?void 0:ze.closest)==null?void 0:ht.call(ze,"a[href]"),ve=q?null:(it=ze==null?void 0:ze.closest)==null?void 0:it.call(ze,CV);let Ve=null;if(q&&q.target!=="_blank"&&!q.hasAttribute("download")){const Lt=new URL(q.href,window.location.href),Dt=G?new URL(G.getAttribute("data-dock-address")??"",window.location.href):window.location,On=Lt.pathname===Dt.pathname&&Lt.search===Dt.search;Lt.origin===window.location.origin&&!On&&(Ve=G?()=>q.click():()=>window.location.assign(Lt.href))}else ve&&ve.getAttribute("aria-current")!=="page"&&ve.getAttribute("aria-disabled")!=="true"&&!ve.hasAttribute("disabled")&&(Ve=()=>ve.click());if(!Ve)return;$e.preventDefault(),$e.stopPropagation();const Ft=Ve;N(oe).then(Lt=>{Lt&&(te(),Ne.current(),Ft())})},be=$e=>{var q;const ze=(q=$e.detail)==null?void 0:q.close;!J||typeof ze!="function"||($e.preventDefault(),N(oe).then(ve=>{ve&&(te(),Ne.current(),ze())}))};return window.addEventListener("beforeunload",Y),document.addEventListener("click",ce,!0),G==null||G.addEventListener(__,be),te},[z,N,oe]);const Se=async()=>{if(!g)return;const J=await g.draft.begin();J.ok?w(J.data):p.error(J.refusal.message)},ae=async()=>x?x.package?N(w_(`${x.package.coordinate} ${x.package.version}`)):x.total>0?N(y_):!0:!0,F=async()=>{await ae()&&(g==null||g.draft.discard(),w(null))},ie=async()=>{x&&!x.package&&!await ae()||(x&&!x.package&&(g==null||g.draft.discard(),w(null)),L({initial:null}))},W=async J=>{if(!(D!=null&&D.draft.beginFromPackage)||!await ae())return;const G=await D.draft.beginFromPackage(J);if(!G.ok){G.refusal.code!=="preview_replaced"&&p.error(G.refusal.message);return}j(null),A(null),w(G.data)},se=J=>{const G=b.state==="read"?b.proposals.find(Y=>Y.id===J.proposal_id):void 0;g==null||g.draft.discard(),S(!1),w(null),A(null),j(G??{id:J.proposal_id,title:J.title,status:"open",requested_by:J.requested_by,requested_at:"",mine:!1,counts:(x==null?void 0:x.counts)??DV})},Z=T!=null&&T.package.open_duplicate&&b.state==="read"?((de=b.proposals.find(J=>J.id===T.package.open_duplicate.proposal_id))==null?void 0:de.requested_at)??null:null;return s.state==="missing"?i.jsx(IV,{org:t}):i.jsx(sb,{children:i.jsxs("div",{ref:re,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(bn,{title:"Org chart",description:_V[e]}),s.state==="busy"&&!f?i.jsxs("p",{className:"text-muted-foreground mt-4 text-sm",role:"status",children:["Another sdlc command holds the repository store; reading again in ",s.retry_after," s."]}):null,(s.state==="loading"||s.state==="busy")&&!f?i.jsx(LV,{quiet:s.state==="busy"}):null,s.state==="none"?i.jsx(PV,{edit:(C==null?void 0:C.actions)??null,seedable:s.seedable}):null,s.state==="failed"?i.jsx(HV,{host:e,kept_at:(f==null?void 0:f.at)??null,on_retry:h}):null,f&&T?i.jsxs(i.Fragment,{children:[i.jsx(bV,{draft:T,org:f.chart.org,duplicate_day:Z,on_submit:()=>S(!0),on_choose:()=>L({initial:{package_id:T.package.package_id,version:T.package.version}}),on_discard:()=>void F(),on_open_proposal:se}),i.jsx(yV,{draft:T})]}):f&&x?i.jsx(sV,{draft:x,on_submit:()=>S(!0),on_discard:()=>void F()}):f&&v?i.jsx(tV,{listed:b,on_propose:()=>void Se(),...D?{on_propose_package:()=>void ie()}:{},on_open:j}):null,f?i.jsx(VV,{chart:(x==null?void 0:x.chart)??f.chart,host:e,edit:(C==null?void 0:C.actions)??null,...T?{marks:T.marks}:{}}):null,(C==null?void 0:C.dialogs)??null,D!=null&&D.draft.beginFromPackage?i.jsx(vV,{open:I!==null,contract:D,packages_href:m(`/org/${encodeURIComponent(t)}/packages`),initial:(I==null?void 0:I.initial)??null,preview:D.draft.beginFromPackage,on_close:()=>{var J,G;(G=(J=D.draft).dropPending)==null||G.call(J),L(null)},on_previewed:J=>{L(null),w(J)}}):null,g&&x?i.jsx(aV,{open:_,draft:x,submit:g.draft.submit,on_close:()=>S(!1),on_open_proposal:se,on_done:(J,G)=>{if(S(!1),J.state==="moved"){w(J.draft);return}w(null),p.success(`Proposed ${G}.`),h(),J.proposal&&(A(J.previewed&&J.opened?{previewed:J.previewed,opened:J.opened}:null),j(J.proposal))}}):null,g&&v?i.jsx(hV,{proposal:k,contract:g,context:{host:e,two_factor:"ok",settings_href:y},check_two_factor:H,since:$,...D?{on_preview_version:J=>void W(J)}:{},on_close:()=>{j(null),A(null)},on_decided:J=>{p.success(J),j(null),A(null),h()}}):null,O]})})}const CV='[data-sidebar="menu-button"]:not([aria-expanded]), [data-sidebar="menu-sub-button"]',__="sdlc-dock-pane-close",Rl={added:0,changed:0,removed:0},DV={team:Rl,job_function:Rl,slot:Rl,post:Rl,fill:Rl},EV={org:"",workflow:!1,teams:[],job_functions:[],slots:[],posts:[],members:[],slot_resolution:[],project:{team:null,roots:[]}};function AV(e){var o;const t=e.authority;if(!t)return{functions:!0,team_add:!0,team:()=>"full",post_add:!1,post:()=>!1,override:!0,slots:!1};const n=((o=e.teams.find(l=>l.parent===null))==null?void 0:o.key)??null,s=new Set(t.teams),a=new Set(t.team_descriptions),r=new Set(t.posts);return{functions:t.administer,team_add:s.size>0,team:l=>l===n?t.administer?"root":a.has(l)?"description":null:s.has(l)?"full":a.has(l)?"description":null,post_add:t.post_pairs.length>0,post:l=>r.has(l),override:!1,slots:t.administer}}function RV(e){const t=e.authority;return t?t.administer||t.teams.length>0||t.team_descriptions.length>0||t.posts.length>0||t.post_pairs.length>0:!0}const TV={functions:!0,team_add:!0,team:()=>"description",post_add:!0,post:()=>!0,override:!1,slots:!0};function Bf({mark:e}){return e?e==="added"?i.jsx(we,{variant:"success",children:"Added"}):i.jsx(we,{variant:"warning",children:"Changed"}):null}const OV={local:"It leaves this repository's local org. If a post, a team or function under it, a holder, an override or the project still needs it, nothing is removed and you are told what needs it.",hosted:"It leaves the organization. If a post, a team or job function under it, or a holder still needs it, nothing is removed and you are told what needs it."},zV={mfa_challenge_required:"challenge",mfa_enrollment_required:"enroll"};function MV(e,t,n){var c;const s=t==="hosted"&&!!n.authority,a=((c=n.authority)==null?void 0:c.two_factor)??!0,[r,o]=u.useState("ok"),l=u.useCallback(async()=>{s&&o(e.twoFactor?await e.twoFactor():a?"ok":"challenge")},[e,s,a]);return u.useEffect(()=>{if(!s){o("ok");return}a?o("ok"):l();const d=()=>void l();return window.addEventListener("focus",d),()=>window.removeEventListener("focus",d)},[s,a,l]),{state:r,set_state:o,check:l}}function $V(e,t,n,s,a,r=null){const o=Ga(),l=bE(n),c=MV(e,s,n),d=r?{host:s,two_factor:"ok",settings_href:a}:s==="hosted"?{host:s,two_factor:c.state,settings_href:a}:ul,{confirm:h,confirm_dialog:f}=mE(d),[m,p]=u.useState(null),[y,g]=u.useState({}),b=R=>g(C=>{if(!C[R])return C;const{[R]:M,...H}=C;return H}),v=e.members,x=u.useCallback(async()=>{if(!v)return{ok:!1};const R=await v();return R.ok?{ok:!0,data:R.data}:{ok:!1}},[v]),w=r?async R=>{const C=await r.change(R);return C.ok?(r.on_draft(C.data),{ok:!0,data:{}}):C}:e.change;if(!w||!r&&s==="hosted"&&(!n.authority||!RV(n)))return null;const _=r?TV:AV(n),S=R=>{const C=R.code?zV[R.code]:void 0;return C?(c.set_state(C),{kind:"two_factor",message:R.message}):R.code==="revision_conflict"?(t(),{kind:"changed",message:R.message}):R.code==="outside_authority"?(t(),{kind:"authority",message:R.message}):{message:R.message}},k=R=>R.action==="hold"||R.action==="release"?"posts":"kind"in R?R.kind==="team"?"teams":R.kind==="post"?"posts":R.kind==="slot"?"slots":"functions":null,j=(R,C)=>{if(r)return;const M=R==null?void 0:R.warning;M?o.error(M):o.success(C),t()},N=async(R,C)=>{const M=await w(R);if(!M.ok)return S(M.refusal);const H=k(R);return H&&b(H),j(M.data,C),null},O=R=>{c.check(),p(R)},T=async(R,C,M,H)=>{const z=await w(M);if(!z.ok){const K=S(z.refusal),oe=z.refusal.bound,re=oe?oe.projects.length+oe.more:0,Ne=oe?`${oe.kind==="slot"?"Slot":"Post"} ${C} is still needed by the ${re===1?"override of 1 project that binds":`overrides of ${re} projects that bind`} it. Clear ${re===1?"it":"them"} on each project's Settings first.`:K.message;g(Se=>({...Se,[R]:{label:C,message:Ne,...oe?{bound:oe}:{}}}));return}b(R),j(z.data,H)},I=async(R,C,M)=>{const H=R==="team"?"team":"job function";c.check(),(r||await h({title:`Remove ${H} ${M}?`,description:OV[s],action_label:"Remove",destructive:!0,action:`remove the ${H}`}))&&await T(R==="team"?"teams":"functions",M,{action:"remove",kind:R,key:C},`${R==="team"?"Team":"Job function"} ${M} removed.`)},L=async R=>{const C=R.label||R.key;c.check(),(r||await h({title:`Remove slot ${C}?`,description:"Projects stop showing it. This can't be undone.",action_label:"Remove slot",destructive:!0,action:"remove the slot"}))&&await T("slots",C,{action:"remove",kind:"slot",key:R.key},`Removed slot ${C}.`)},$=async R=>{const C=l.post(R);c.check(),(r||await h({title:`Remove post ${C}?`,description:"The post leaves the organization's chart. A post with holders is refused; remove its holders first.",action_label:"Remove",destructive:!0,action:"remove the post"}))&&await T("posts",C,{action:"remove",kind:"post",key:R},`Removed post ${C}.`)},A=async(R,C)=>{const M=l.post(R),H=l.member(C),z=n.posts.find(Se=>Se.post===R),oe=((z==null?void 0:z.holders.length)??0)<=1?z!=null&&z.escalates_to?` The post becomes vacant. Until someone holds it, its reports and the slots it fills go to ${l.manager(z.escalates_to)}.`:" The post becomes vacant.":"";if(c.check(),!await h({title:`Remove ${H} from ${M}?`,description:`They stop holding this post and no longer report through it.${oe}`,action_label:"Remove",action:"remove the holder"}))return;const Ne=await w({action:"release",post:R,member:C.id});if(!Ne.ok){o.error(S(Ne.refusal).message),t();return}b("posts"),j(Ne.data,`Removed ${H} from ${M}.`)},D=()=>p(null),E=(m==null?void 0:m.kind)==="override"&&n.project&&n.project.team!==null?n.project.slots.find(R=>R.slot===m.slot)??null:null;return{actions:{can:_,host:s,drafting:!!r,...r?{marks:r.draft.marks}:{},team:(R,C="full")=>O({kind:"team",team:R,scope:C}),job:R=>O({kind:"function",job:R}),override:R=>O({kind:"override",slot:R}),slot:R=>O({kind:"slot",slot:R}),slot_remove:R=>void L(R),remove:(R,C,M)=>void I(R,C,M),post_add:()=>O({kind:"post"}),post_remove:R=>void $(R),holder_add:R=>O({kind:"holder",post:R}),holder_remove:(R,C)=>void A(R,C),refused:R=>{const C=y[R];return C?i.jsx(VH,{label:C.label,message:C.message,bound:C.bound,on_dismiss:()=>b(R)}):null}},dialogs:i.jsxs(i.Fragment,{children:[i.jsx(TH,{open:(m==null?void 0:m.kind)==="team",chart:n,team:(m==null?void 0:m.kind)==="team"?m.team:null,scope:(m==null?void 0:m.kind)==="team"?m.scope:"full",parents:!r&&n.authority?n.authority.teams:void 0,save:N,on_close:D,context:d}),i.jsx(zH,{open:(m==null?void 0:m.kind)==="function",chart:n,job:(m==null?void 0:m.kind)==="function"?m.job:null,save:N,on_close:D,context:d}),i.jsx(PH,{open:E!==null,chart:n,binding:E,names:l,save:N,confirm:R=>h({...R,action:"clear the override"}),on_close:D}),i.jsx(LH,{open:(m==null?void 0:m.kind)==="slot",chart:n,slot:(m==null?void 0:m.kind)==="slot"?m.slot:null,save:N,on_close:D,context:d}),i.jsx(GH,{open:(m==null?void 0:m.kind)==="post",chart:n,names:l,save:N,on_close:D,context:d}),i.jsx(HH,{open:(m==null?void 0:m.kind)==="holder",chart:n,post:(m==null?void 0:m.kind)==="holder"?m.post:null,names:l,members:x,save:N,on_close:D,context:d}),f]})}}function LV({quiet:e=!1}){return i.jsx("div",{className:"mt-6 grid gap-2",...e?{"aria-hidden":!0}:{role:"status","aria-label":"Loading the org chart"},children:Array.from({length:4},(t,n)=>i.jsx(Tt,{className:n===3?"h-10 w-2/3":"h-10 w-full"},n))})}function Eo({children:e}){return i.jsx("pre",{className:"bg-muted text-foreground m-0 overflow-x-auto rounded-md border px-3 py-2 font-mono text-sm",children:i.jsx("code",{children:e})})}function PV({edit:e,seedable:t}){const n=t?e?"Plan one from this checkout's workflow roles with sdlc org seed, or start one with a team. This page shows it as soon as it exists.":"Plan one from this checkout's workflow roles, or start one with a team. This page shows it as soon as it exists.":"Start one with a team. This page shows it as soon as it exists.";return i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This repository has no local org yet"}),i.jsxs(ge,{children:[i.jsx("p",{children:n}),t||!e?i.jsxs("div",{className:"mt-2 grid w-full gap-2",children:[t?i.jsx(Eo,{children:"sdlc org seed"}):null,e?null:i.jsx(Eo,{children:"sdlc org add team <key>"})]}):null,e?i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>e.team(null),children:[i.jsx(za,{className:"size-4","aria-hidden":"true"}),"Add team"]}):null]})]})}function IV({org:e}){const{href:t,Link:n}=lt();return i.jsx(Ha,{title:"Page not found",description:e?`There is no organization ${e}, or you are not one of its members.`:"This organization does not exist, or you are not one of its members.",backHref:t("/org"),backLabel:"Back to Organizations",link:n})}function GV(e){return new Date(e).toDateString()===new Date().toDateString()?`today at ${Fs(e)}`:`on ${Rs(e)} at ${Fs(e)}`}function HV({host:e,kept_at:t,on_retry:n}){const s=t?`The chart read ${GV(t)} is kept below. `:"";return i.jsxs(pe,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:e==="hosted"?"Could not read the org chart":"Could not read the local org"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[s,e==="hosted"?s?"Try again in a moment.":"Try again in a moment. If it keeps failing, ask an organization owner.":"Details are in the terminal running sdlc viewer."]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:n,children:"Retry"})]})]})}function bE(e){return u.useMemo(()=>{const t=new Map(e.teams.map(b=>[b.key,b.label||b.key])),n=new Map(e.job_functions.map(b=>[b.key,b.label||b.key])),s=new Map(e.slots.map(b=>[b.key,b.label||b.key])),a=new Map(e.posts.map(b=>[b.post,b.holders])),r=b=>b.label||b.id,o=new Map;for(const b of[...e.members,...e.posts.flatMap(v=>v.holders)]){const v=r(b);o.set(v,(o.get(v)??new Set).add(`${b.kind}:${b.id}`))}const l=b=>{var v;return(((v=o.get(r(b)))==null?void 0:v.size)??0)>1},c=b=>{const v=l(b)?b.detail??b.id:null;return v&&v!==r(b)?v:null},d=b=>{const v=c(b);return v&&v!==r(b)?`${r(b)} (${v})`:r(b)},h=b=>{const[v="",x=""]=b.split("/");return{team:t.get(v)??v,job:n.get(x)??x}},f=b=>{const{team:v,job:x}=h(b);return`${x} · ${v}`},m=b=>{if(b==="top")return"Top of the org";if(typeof b!="string")return`A vacant ${n.get(b.vacant)??b.vacant}`;const v=(a.get(b)??[]).map(d);return v.length?`${f(b)} (${v.join(", ")})`:f(b)},p=new Map(e.teams.map(b=>[b.key,b.parent])),y=b=>{let v=0;for(let x=p.get(b);x&&v<e.teams.length;x=p.get(x))v+=1;return v};return{parts:h,post:f,member:d,memberLabel:r,memberDetail:c,manager:m,byPost:(b,v)=>{const[x="",w=""]=[b.split("/")[0],v.split("/")[0]],[_,S]=[h(b),h(v)];return y(x)-y(w)||_.team.localeCompare(S.team)||_.job.localeCompare(S.job)},slot:b=>s.get(b)??b,job:b=>n.get(b)??b,team:b=>t.get(b)??b}},[e])}function tr({id:e,title:t,description:n,actions:s,children:a,anchor:r}){const o=u.useRef(null);return u.useEffect(()=>{var l,c;!r||typeof window>"u"||window.location.hash!==`#${r}`||((l=o.current)==null||l.scrollIntoView({block:"start"}),(c=o.current)==null||c.focus({preventScroll:!0}))},[r]),i.jsxs("section",{id:r,"aria-labelledby":e,className:"mt-8 min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[i.jsxs("div",{className:"min-w-0 flex-1 basis-64",children:[i.jsx("h2",{id:e,ref:o,tabIndex:r?-1:void 0,className:"text-lg font-semibold",children:t}),i.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:n})]}),s?i.jsx("div",{className:"flex shrink-0 gap-2",children:s}):null]}),i.jsx("div",{className:"mt-3",children:a})]})}function Ul({children:e,on_click:t}){return i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:t,children:[i.jsx(za,{className:"size-4","aria-hidden":"true"}),e]})}const j_={local:"A member's primary manager comes from the post highest in the function tree; the others are dotted lines.",hosted:"Members who hold a post. A member's primary manager comes from the post highest in the function tree; the others are dotted lines."};function VV({chart:e,host:t,edit:n,marks:s}){const a=bE(e),r=s??(n==null?void 0:n.marks),o=e.members.some(l=>l.kind==="agent");return i.jsxs(i.Fragment,{children:[i.jsxs(tr,{id:"org-chart-lines",title:"Reporting lines",description:"Each post reports to the post of its parent job function in the same team, or else in the nearest team above it that has one.",actions:n!=null&&n.can.post_add?i.jsx(Ul,{on_click:n.post_add,children:"Add post"}):void 0,children:[n==null?void 0:n.refused("posts"),i.jsx(WV,{chart:e,names:a,agents:o,host:t,edit:n,marks:r})]}),i.jsx(tr,{id:"org-chart-members",title:"Members",description:o?`${j_[t]} Each agent answers to the nearest person in its reporting chain.`:j_[t],children:i.jsx(KV,{chart:e,names:a,host:t,agents:o})}),n||s?i.jsxs(tr,{id:"org-chart-teams",title:"Teams",description:"Each team under its parent. A post is one of its job functions staffed in it.",actions:n!=null&&n.can.team_add?i.jsx(Ul,{on_click:()=>n.team(null),children:"Add team"}):void 0,children:[n==null?void 0:n.refused("teams"),i.jsx(UV,{chart:e,host:t,edit:n,marks:r})]}):null,i.jsxs("div",{className:"grid items-start gap-x-6 xl:grid-cols-2",children:[i.jsxs(tr,{id:"org-chart-functions",title:"Function tree",description:"Each job function under its parent, with the slots it fills.",actions:n!=null&&n.can.functions?i.jsx(Ul,{on_click:()=>n.job(null),children:"Add job function"}):void 0,children:[n!=null&&n.can.functions?n.refused("functions"):null,i.jsx(ZV,{chart:e,names:a,edit:n!=null&&n.can.functions?n:null,marks:r})]}),i.jsxs(tr,{id:"org-chart-slots",anchor:"slots",title:"Slots",description:jV,actions:n!=null&&n.can.slots&&e.slot_resolution.length>0?i.jsx(Ul,{on_click:()=>n.slot(null),children:"Add slot"}):void 0,children:[n!=null&&n.can.slots?n.refused("slots"):null,e.workflow===!1?i.jsx("p",{className:"text-muted-foreground mb-3 text-xs",children:"This checkout has no workflow file, so no slot is marked as a gate."}):null,i.jsx(JV,{chart:e,names:a,host:t,edit:n!=null&&n.can.slots?n:null,marks:r})]})]}),e.project?i.jsx(t6,{project:e.project,chart:e,names:a,edit:n!=null&&n.can.override?n:null}):null]})}function UV({chart:e,host:t,edit:n,marks:s}){var h;const a=vb([...e.teams].sort((f,m)=>(f.label||f.key).localeCompare(m.label||m.key)),f=>f.key,f=>f.parent);if(a.length===0)return i.jsx("p",{className:"text-muted-foreground text-sm",children:"No teams yet."});const r=((h=e.project)==null?void 0:h.team)??null,o=t==="hosted",l=(f,m)=>{if(!n)return null;const p=n.can.team(f.key);return p==="full"?i.jsx(Do,{label:m,on_edit:()=>n.team(f),on_remove:()=>n.remove("team",f.key,m)}):p==="root"?i.jsx(Do,{label:m,on_edit:()=>n.team(f,"description")}):p==="description"&&n.drafting?i.jsx(Do,{label:m,items:[{label:"Edit description",on_select:()=>n.team(f,"description")}]}):p==="description"?i.jsx(U,{type:"button",variant:"ghost",size:"control-icon",className:"-my-1 shrink-0","aria-label":`Edit the description of ${m}`,onClick:()=>n.team(f,"description"),children:i.jsx(df,{className:"size-3.5","aria-hidden":"true"})}):null},c=(f,m)=>i.jsx("ul",{role:"list",className:m===0?"m-0 -mb-px list-none p-0":"m-0 list-none p-0",children:f.map(({item:p,children:y})=>{const g=p.label||p.key;return i.jsxs("li",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b py-2 pr-4",style:xb(m),"data-testid":"org-chart-team",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium",children:g}),i.jsx(Bf,{mark:s==null?void 0:s.teams[p.key]})]}),i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[o?null:i.jsx("span",{className:"text-muted-foreground font-mono text-xs",children:p.key}),r===p.key?i.jsx(we,{variant:"neutral",children:"Owns this project"}):null,l(p,g)]})]}),y.length>0?c(y,m+1):null]},p.key)})}),d=o&&e.teams.length===1;return i.jsxs(i.Fragment,{children:[i.jsx(yt,{className:"overflow-hidden",children:c(a,0)}),d?i.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["No teams below ",e.teams[0].label||e.teams[0].key," yet."]}):null]})}function vb(e,t,n){const s=new Set(e.map(t)),a=new Map(e.map(o=>[t(o),{item:o,children:[]}])),r=[];for(const o of e){const l=n(o),c=a.get(t(o));l&&s.has(l)&&l!==t(o)?a.get(l).children.push(c):r.push(c)}return r}const BV={local:"No posts yet.",hosted:"No posts yet. An org admin can add them."};function WV({chart:e,names:t,agents:n,host:s,edit:a,marks:r}){const o=vb([...e.posts].sort((d,h)=>t.byPost(d.post,h.post)),d=>d.post,d=>typeof d.reports_to=="string"&&d.reports_to!=="top"?d.reports_to:null);if(o.length===0){const d=s==="hosted"&&(a==null?void 0:a.can.functions)&&!a.can.post_add;return i.jsx("p",{className:"text-muted-foreground text-sm",children:a!=null&&a.can.post_add?"No posts yet. Add a post to staff a job function in a team.":d?"No posts yet. Add a job function under Function tree first, then add a post to staff it in a team.":BV[s]})}const l=new Map(e.members.map(d=>[`${d.kind}:${d.id}`,d])),c=(d,h)=>i.jsx("ul",{role:"list",className:h===0?"m-0 -mb-px list-none p-0":"m-0 list-none p-0",children:d.map(({item:f,children:m})=>{const{team:p}=t.parts(f.post),y=typeof f.reports_to=="object"?f.reports_to:null,g=!!(a!=null&&a.can.post(f.post));return i.jsxs("li",{children:[i.jsxs("div",{className:"border-b py-2 pr-4",style:xb(h),"data-testid":"org-chart-post",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(tO,{className:"text-muted-foreground size-4 shrink-0","aria-hidden":"true"}),i.jsx("span",{className:"text-sm font-medium",children:t.parts(f.post).job}),i.jsx("span",{className:"text-muted-foreground text-xs",children:y?`${p} · Reports to a vacant ${t.job(y.vacant)}`:p}),i.jsx(Bf,{mark:r==null?void 0:r.posts[f.post]}),g&&a?i.jsx("span",{className:"ml-auto",children:i.jsx(Do,{label:t.post(f.post),items:[...a.drafting?[]:[{label:"Add holder",on_select:()=>a.holder_add(f.post)}],{label:"Remove post",on_select:()=>a.post_remove(f.post),destructive:!0}]})}):null]}),i.jsx("div",{className:"mt-1 grid min-w-0 gap-1 pl-6",children:f.holders.length===0?i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(we,{variant:Ah.vacant.tone,children:Ah.vacant.label}),i.jsx("span",{className:"text-muted-foreground text-xs",children:f.escalates_to?`No one holds this post. Its work goes to ${t.manager(f.escalates_to)}.`:"No one holds this post."})]}):f.holders.map(b=>i.jsx(YV,{holder:b,post:f.post,member:l.get(`${b.kind}:${b.id}`),names:t,agents:n,host:s,on_remove:g&&a&&!a.drafting?()=>a.holder_remove(f.post,b):void 0},`${b.kind}:${b.id}`))})]}),m.length>0?c(m,h+1):null]},f.post)})});return i.jsx(yt,{className:"overflow-hidden",children:c(o,0)})}function FV(e){return new Date(e).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function qV(e){if(!e.held_since)return null;const t=FV(e.held_since);return e.added_by?e.added_by==="former_member"?`Added on ${t} by a former member`:`Added by ${e.added_by.name} on ${t}`:`Added on ${t}`}function YV({holder:e,post:t,member:n,names:s,agents:a,host:r,on_remove:o}){const l=e.kind==="person"?yv:pv,c=n==null?void 0:n.posts.find(y=>y.post===t),d=n==null?void 0:n.posts.find(y=>y.primary),h=s.memberDetail(e);let f=null;c!=null&&c.dotted&&d?f=`Dotted line: primary manager is ${s.manager(d.reports_to)}`:e.kind==="agent"&&n&&"accountable_person"in n&&(f=n.accountable_person?`Accountable person ${s.member(n.accountable_person)}`:"No accountable person");const m=r==="hosted"?qV(e):null,p=s.memberLabel(e);return i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",children:[i.jsx(l,{className:"text-muted-foreground size-3.5 shrink-0","aria-hidden":"true"}),i.jsx("span",{className:"text-sm font-medium break-all",children:p}),o?i.jsxs(wd,{children:[i.jsx(_d,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon",className:"-my-1 shrink-0","aria-label":`Remove ${s.member(e)} from ${s.post(t)}`,onClick:o,children:i.jsx(dd,{className:"size-3.5","aria-hidden":"true"})})}),i.jsxs(ol,{children:["Remove ",p]})]}):null,h?i.jsx("span",{className:"text-muted-foreground text-xs break-all",children:h}):null,a?i.jsx("span",{className:"text-muted-foreground text-xs",children:e.kind==="person"?"Person":"Agent"}):null]}),f?i.jsx("div",{className:"pl-5.5 text-xs",children:f}):null,m?i.jsx("div",{className:"text-muted-foreground pl-5.5 text-xs",children:m}):null]})}const XV=["sdlc org hold <team>/<function> --person <id>","sdlc org hold <team>/<function> --agent <id>"];function KV({chart:e,names:t,host:n,agents:s}){if(e.members.length===0)return n==="hosted"?i.jsx("p",{className:"text-muted-foreground text-sm",children:"No one holds a post yet."}):i.jsxs("div",{className:"grid max-w-2xl gap-2",children:[i.jsx("p",{className:"text-muted-foreground text-sm",children:"No one holds a post yet. Give a post to a person or an agent:"}),XV.map(r=>i.jsx(Eo,{children:r},r))]});const a=[...e.members].sort((r,o)=>r.kind===o.kind?t.memberLabel(r).localeCompare(t.memberLabel(o))||r.id.localeCompare(o.id):r.kind==="person"?-1:1);return i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Members",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Member"}),i.jsx(Q,{children:"Posts"}),i.jsx(Q,{children:"Primary manager"}),i.jsx(Q,{children:"Dotted lines"}),s?i.jsx(Q,{children:"Accountable person"}):null]})}),i.jsx(st,{children:a.map(r=>{const o=r.posts.find(d=>d.primary),l=r.posts.filter(d=>d.dotted),c=t.memberDetail(r);return i.jsxs(_e,{"data-testid":"org-chart-member",children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-medium",children:t.memberLabel(r)}),c?i.jsx("div",{className:"text-muted-foreground text-xs",children:c}):null,s?i.jsx("div",{className:"text-muted-foreground text-xs",children:r.kind==="person"?"Person":"Agent"}):null]}),i.jsx(X,{children:r.posts.map(d=>t.post(d.post)).join(", ")}),i.jsx(X,{children:o?t.manager(o.reports_to):"None"}),i.jsx(X,{children:l.length?l.map(d=>t.manager(d.reports_to)).join(", "):"None"}),s?i.jsx(X,{children:r.kind==="person"?"Not an agent":r.accountable_person?t.member(r.accountable_person):"None"}):null]},`${r.kind}:${r.id}`)})})]})})}function ZV({chart:e,names:t,edit:n,marks:s}){const a=vb([...e.job_functions].sort((o,l)=>(o.label||o.key).localeCompare(l.label||l.key)),o=>o.key,o=>o.parent);if(a.length===0)return i.jsx("p",{className:"text-muted-foreground text-sm",children:(n==null?void 0:n.host)==="hosted"?"No job functions yet. Add one to start the chart.":"No job functions yet."});const r=(o,l)=>i.jsx("ul",{role:"list",className:l===0?"m-0 -mb-px list-none p-0":"m-0 list-none p-0",children:o.map(({item:c,children:d})=>i.jsxs("li",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b py-2 pr-4",style:xb(l),"data-testid":"org-chart-function",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium",children:c.label||c.key}),i.jsx(Bf,{mark:s==null?void 0:s.job_functions[c.key]})]}),i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-muted-foreground text-xs",children:c.fills.length?`Fills ${c.fills.map(t.slot).join(", ")}`:"No slot"}),c.requires_person?i.jsx(we,{variant:"neutral",children:"Requires a person"}):null,n?i.jsx(Do,{label:c.label||c.key,on_edit:()=>n.job(c),on_remove:()=>n.remove("job_function",c.key,c.label||c.key)}):null]})]}),d.length>0?r(d,l+1):null]},c.key))});return i.jsx(yt,{className:"overflow-hidden",children:r(a,0)})}function QV(e,t){return e.status==="uncovered"?"No job function fills this slot":e.status==="vacant"?`${e.posts.map(t.post).join(", ")} has no holder`:e.posts.map(n=>`${t.post(n.post)}: ${n.holders.map(t.member).join(", ")}`).join("; ")}const Rh={covered:0,vacant:1,uncovered:2};function yE(e){return new Map(e.slots.filter(t=>t.gate).map(t=>{var n;return[t.key,(n=t.gates)!=null&&n.length?`Gate: ${t.gates.join(", ")}`:"Gate slot"]}))}function JV({chart:e,names:t,host:n,edit:s,marks:a}){var l;const r=yE(e),o=new Map(e.slots.map(c=>[c.key,c]));if(n==="hosted"&&e.slot_resolution.length===0){const c=((l=e.authority)==null?void 0:l.ask)??[];return i.jsxs(yt,{className:"grid justify-items-center gap-2 p-6 text-center",children:[i.jsx("span",{className:"text-sm font-medium",children:"No slots yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Add the workflow roles your projects fill, such as Implementer or Approver."}),s?i.jsx(Ul,{on_click:()=>s.slot(null),children:"Add slot"}):i.jsxs("p",{className:"text-muted-foreground text-sm",children:["Only an org owner or admin adds slots."," ",c.length?`Ask ${c.slice(0,3).join(", ")} to make this change.`:"Ask an org owner to make this change."]})]})}return i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Slots",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Slot"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Resolves to"}),s?i.jsx(Q,{className:"text-right",children:i.jsx("span",{className:"sr-only",children:"Actions"})}):null]})}),i.jsxs(st,{children:[[...e.slot_resolution].sort((c,d)=>Rh[c.status]-Rh[d.status]||t.slot(c.slot).localeCompare(t.slot(d.slot))).map(c=>{var h,f;const d=Ah[c.status];return i.jsxs(_e,{"data-testid":"org-chart-slot",children:[i.jsxs(X,{children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"font-medium",children:t.slot(c.slot)}),i.jsx(Bf,{mark:a==null?void 0:a.slots[c.slot]})]}),n==="hosted"?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"text-muted-foreground font-mono text-xs",children:c.slot}),(h=o.get(c.slot))!=null&&h.description?i.jsx("div",{className:"text-muted-foreground text-xs break-words",children:(f=o.get(c.slot))==null?void 0:f.description}):null]}):null,r.has(c.slot)?i.jsx("div",{className:"text-muted-foreground text-xs",children:r.get(c.slot)}):null]}),i.jsx(X,{children:i.jsx(we,{variant:d.tone,children:d.label})}),i.jsxs(X,{children:[QV(c,t),c.status==="covered"&&c.needs_person?i.jsx("div",{className:"text-muted-foreground text-xs",children:"Needs a person"}):null]}),s&&o.has(c.slot)?i.jsx(X,{className:"text-right",children:i.jsx(Do,{label:t.slot(c.slot),on_edit:()=>s.slot(o.get(c.slot)),on_remove:()=>s.slot_remove(o.get(c.slot))})}):null]},c.slot)}),e.slot_resolution.length===0?i.jsx(_e,{children:i.jsx(X,{colSpan:3,className:"text-muted-foreground h-24 text-center",children:"This org has no slots yet."})}):null]})]})})}const e6="Who fills each workflow slot for this repository's project: the posts of the owning team's job functions, else of the nearest team above, unless an override names other posts.",mp=["sdlc org own <team>","sdlc org bind <slot> <team>/<function>... --reason <text>","sdlc org unbind <slot>"];function t6({project:e,chart:t,names:n,edit:s}){if(e.team===null){const o=e.roots.map(n.team);return i.jsx(tr,{id:"org-chart-project",title:"This project",description:o.length?`This org has several root teams (${o.join(", ")}), so no team owns this repository's project yet and its slots are not bound. Name the owning team:`:"This org has no team yet, so no team owns this repository's project. Start one:",children:i.jsx("div",{className:"max-w-2xl",children:i.jsx(Eo,{children:o.length?mp[0]:"sdlc org add team <key>"})})})}const a=yE(t),r=[...e.slots].sort((o,l)=>Rh[o.status]-Rh[l.status]||n.slot(o.slot).localeCompare(n.slot(l.slot)));return i.jsxs(tr,{id:"org-chart-project",title:"This project",description:e6,children:[i.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[i.jsx("span",{className:"text-muted-foreground text-xs",children:"Owning team"}),i.jsx("span",{className:"text-sm font-medium",children:n.team(e.team)})]}),i.jsx(yt,{className:"mt-3 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Slots in this project",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Slot"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Bound to"}),i.jsx(Q,{children:"Source"}),s?i.jsx(Q,{className:"text-right",children:i.jsx("span",{className:"sr-only",children:"Actions"})}):null]})}),i.jsxs(st,{children:[r.map(o=>{const l=Ah[o.status];return i.jsxs(_e,{"data-testid":"org-chart-project-slot",children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-medium",children:n.slot(o.slot)}),a.has(o.slot)?i.jsx("div",{className:"text-muted-foreground text-xs",children:a.get(o.slot)}):null]}),i.jsx(X,{children:i.jsx(we,{variant:l.tone,children:l.label})}),i.jsx(X,{children:i.jsx(n6,{binding:o,names:n})}),i.jsx(X,{children:i.jsx(s6,{binding:o})}),s?i.jsx(X,{className:"text-right",children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon","aria-label":o.source==="override"?`Edit the override of ${n.slot(o.slot)}`:`Override ${n.slot(o.slot)}`,onClick:()=>s.override(o.slot),children:i.jsx(df,{className:"size-3.5","aria-hidden":"true"})})}):null]},o.slot)}),r.length===0?i.jsx(_e,{children:i.jsx(X,{colSpan:s?5:4,className:"text-muted-foreground h-24 text-center",children:"This org has no slots yet."})}):null]})]})}),s?i.jsxs("div",{className:"mt-3 grid max-w-2xl gap-2",children:[i.jsxs("p",{className:"text-muted-foreground text-sm",children:["Overrides made here are made as ",i.jsx("span",{className:"font-mono",children:"person:user"}),", as sdlc org makes them without --as: that person must hold the lead post of the owning team or of a team above it."]}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Change the owning team with sdlc org:"}),i.jsx(Eo,{children:mp[0]})]}):i.jsxs("div",{className:"mt-3 grid max-w-2xl gap-2",children:[i.jsx("p",{className:"text-muted-foreground text-sm",children:"Change the owning team or a slot's binding with sdlc org; a lead post of the owning team or a team above it may:"}),mp.map(o=>i.jsx(Eo,{children:o},o))]})]})}function n6({binding:e,names:t}){const n=[];e.status==="covered"&&e.needs_person&&n.push("Needs a person");for(const a of e.posts)a.off_description&&n.push(`${t.post(a.post)} does not fill ${t.slot(e.slot)} in its job description`);e.stale_posts&&n.push(e.stale_posts===1?"One post this override names is no longer in the org":`${e.stale_posts} posts this override names are no longer in the org`);let s;return e.posts.length===0?s=e.source==="override"?"The override names no post the org still has":"No job function fills this slot":e.status==="vacant"?s=`${e.posts.map(a=>t.post(a.post)).join(", ")} has no holder`:s=e.posts.map(a=>a.holders.length?`${t.post(a.post)}: ${a.holders.map(t.member).join(", ")}`:`${t.post(a.post)}: no holder`).join("; "),i.jsxs(i.Fragment,{children:[s,n.map(a=>i.jsx("div",{className:"text-muted-foreground text-xs",children:a},a))]})}function s6({binding:e}){var s;if(e.source==="baseline")return i.jsx(i.Fragment,{children:"From job descriptions"});const t=(s=e.set_by)==null?void 0:s.split(":").slice(1).join(":"),n=[e.reason,[t,e.set_at?Rs(e.set_at):null].filter(Boolean).join(", ")].filter(Boolean).join(" · ");return i.jsxs(i.Fragment,{children:["Override",n?i.jsx("div",{className:"text-muted-foreground text-xs",children:n}):null]})}const i6={breaking:"Breaking",new:"New",improved:"Improved",other:"Other changes"},a6=["breaking","new","improved","other"],r6={http_operation:"API",rpc_operation:"API",graphql_operation:"API",async_operation:"Event",page:"Page",ui_frame:"Screen",ui_component_definition:"Component",table:"Data",function:"Function"};function wE(e){return r6[e]??e.replace(/_/g," ")}function o6(e){return e.bump==="major"?"breaking":e.change==="added"?"new":e.change==="changed"?"improved":"other"}function Ic(e){const t=new Map;let n=0,s=0;for(const r of e){if(r.modeling_only){s+=1;continue}if(!r.bump){n+=1;continue}const o=o6(r);t.set(o,[...t.get(o)??[],r])}return{sections:a6.filter(r=>t.has(r)).map(r=>({key:r,label:i6[r],lines:t.get(r)})),breaking:t.has("breaking"),unlisted_count:n,modeling_only_count:s}}function l6(e,t){const n=[`## ${e}`];t.sections.length===0&&n.push("","No change affects the version.");for(const s of t.sections){n.push("",`### ${s.label}`,"");for(const a of s.lines){const r=a.why?`: ${a.why}`:"";n.push(`- ${a.label} (${wE(a.node_type)})${r}`)}}return`${n.join(`
|
|
428
|
+
It leaves the open tasks.`:"It leaves the open tasks.",action_label:"Mark done"}))return;Ft(V);const At=await o.complete(Be);if(Ft(null),!At.ok){ht(Nt=>({...Nt,[V]:At.refusal.message}));return}ht(({[V]:Nt,...Pt})=>Pt),Lt(`${ue} marked done.`),await Et.current(),an({next:at})},[et,an]=u.useState(null);u.useEffect(()=>{var at;if(!et)return;an(null);const V=Sn.current,ue=typeof et.next=="function"?et.next():et.next;(at=(ue?(V==null?void 0:V.querySelector(`[data-done-key="${CSS.escape(ue)}"]`))??(V==null?void 0:V.querySelector(`[data-title-key="${CSS.escape(ue)}"] a`)):null)??mn.current)==null||at.focus()},[et]);const Mn=()=>{var V;$(""),D(""),R(null),M(Vl),z(!1),oe(!1),(V=mn.current)==null||V.focus()},Bn=new Map(x.map(V=>[V.id,V])),xs=new Map(w.map(V=>[V.id,V])),_i=new Map(W.map(V=>[V.id,V.title])),ji=_&&N==="active",vs=W.some(V=>V.local_done),pl=W.some(V=>V.local_action),gl=ji||vs||pl,xl=!v||w.length>0,lm=!T&&!xt,Lr=5+(xl?1:0)+(gl?1:0),cm=Z!==null&&(Z.reason==="store_locked"||Z.reason==="engine_failed")&&J<=c3,Fa=(ce==null?void 0:ce.holds)??[],vl=F==null?void 0:F.groups,dm=p3(W,vl,re,(F==null?void 0:F.matched)===void 0?Se:[]),qa=vl?vl.length===0:W.length===0,P=(V,ue)=>Ne(Be=>({...Be,[V]:!ue})),he=V=>ae(ue=>ue.includes(V)?ue.filter(Be=>Be!==V):[...ue,V]),me=Fa.map(V=>V.id);return i.jsxs("div",{ref:Sn,className:"contents",children:[i.jsx(bn,{title:"Tasks",description:s,actions:_?i.jsxs(U,{type:"button",onClick:()=>ve(!0),children:[i.jsx(za,{className:"mr-2 size-4","aria-hidden":"true"}),"New task"]}):null}),v&&(F!=null&&F.open)?i.jsxs("p",{className:"text-muted-foreground mt-1 text-sm",children:[F.open," open"]}):null,gs?i.jsx("p",{className:"text-muted-foreground mt-1 text-xs",role:"status",children:Z?`Not reading · trying again every ${Math.round(gs/1e3)}s`:F?`Live · refreshes every ${Math.round(gs/1e3)}s`:"Connecting…"}):null,v?i.jsx("p",{className:"sr-only",role:"status",children:it}):null,(v||Fa.length>0)&&i.jsxs(yt,{as:"section","aria-labelledby":"waiting-title",className:"mt-4 p-4","data-testid":"tasks-waiting",children:[i.jsx("h2",{id:"waiting-title",className:"text-lg font-semibold",children:"Waiting on you"}),Fa.length>0?i.jsx("ul",{className:"mt-2 divide-y","aria-labelledby":"waiting-title",children:Fa.map((V,ue)=>{var At,Nt;const Be=zc[V.hold_type],at=V.target.kind==="task"?`Because you claim ${_i.get(V.target.task_id)??"the task it waits on"} · `:"",rn=V.local_done;return i.jsxs("li",{id:`waiting-${V.id}`,"data-title-key":V.id,className:"flex flex-wrap items-center gap-3 py-2",children:[V.task?i.jsx(f,{className:"text-primary min-w-40 flex-1 hover:underline",href:h(`/org/${t}/tasks/${V.task.id}`),children:V.task.title}):i.jsx("span",{className:"min-w-40 flex-1",children:V.reason}),i.jsx(we,{variant:Be.tone,children:V.local_label??Be.label}),i.jsxs("div",{className:"min-w-48 flex-2",children:[V.task?i.jsx("div",{className:"text-sm",children:V.reason}):null,i.jsxs("div",{className:"text-muted-foreground text-xs",children:[at,"From ",j(V.opened_by)," · ",Rs(V.opened_at)]}),(At=V.local_threads)!=null&&At.length?i.jsxs("div",{className:"text-muted-foreground text-xs",children:["Answer it in"," ",i.jsx(f,{className:"text-primary hover:underline",href:h(`/org/${t}/threads`),children:"Threads"}),": ",V.local_threads.join(" · ")]}):null,Qt[V.id]?i.jsx("div",{className:"text-destructive text-xs",role:"alert",children:Qt[V.id]}):null]}),rn&&(o!=null&&o.complete)?i.jsx(U,{type:"button",variant:"outline",size:"sm","data-done-key":V.id,"aria-label":`Mark ${((Nt=V.task)==null?void 0:Nt.title)??V.reason} done`,loading:Ve===V.id,onClick:()=>{var Pt;return void Te(V.id,((Pt=V.task)==null?void 0:Pt.title)??V.reason,rn,me[ue+1]??null)},children:"Done"}):null,v?null:i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void $r(V.id),children:"Release"})]},V.id)})}):ce?i.jsx("p",{className:"text-muted-foreground mt-2 text-sm",children:"Nothing in this checkout waits on you."}):null,v&&fe?i.jsx("p",{className:"text-muted-foreground mt-2 text-sm",role:"status",children:fe.reason==="view_outdated"?`Waiting on you is not read here. ${ze}`:"Waiting on you could not be read. It is read again with the list."}):null,i.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:v?"This checkout only. Teammates' agents are not listed here.":"Release a hold when you have done your part. Whoever can edit the task then resolves it."})]}),!_&&!a&&i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can view these tasks"}),i.jsx(ge,{children:"Ask an organization admin for write access to change them."})]}),i.jsxs("div",{className:"mt-6 flex flex-wrap items-center gap-4",children:[(b==null?void 0:b.archived)!==!1?i.jsx(EI,{value:N,onValueChange:V=>O(V),children:i.jsxs(xD,{"aria-label":"Which tasks",children:[i.jsx(Gg,{value:"active",children:"Active"}),i.jsx(Gg,{value:"archived",children:"Archived"})]})}):null,(b==null?void 0:b.assigned_to_me)!==!1?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nl,{id:"tasks-mine",checked:T,onCheckedChange:V=>I(V===!0)}),i.jsx(Ie,{htmlFor:"tasks-mine",children:"Assigned to me"})]}):null,b!=null&&b.search?i.jsx(bt,{ref:mn,type:"search",className:"w-64","aria-label":"Search tasks",placeholder:"Search title, ID or detail",value:L,onChange:V=>$(V.target.value)}):null,ye!=null&&ye.owners?i.jsx(_3,{owners:ye.owners,no_owner:ye.no_owner,value:C,on_change:M}):null]}),(De=ye==null?void 0:ye.groups)!=null&&De.length?i.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",role:"group","aria-label":"Status",children:[ye.groups.map(V=>i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":E===V.id,onClick:()=>R(ue=>ue===V.id?null:V.id),children:[V.label," ",V.count]},V.id)),ye.marks?i.jsxs(i.Fragment,{children:[i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":H,onClick:()=>z(V=>!V),children:["Urgent ",ye.marks.urgent]}),i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":K,onClick:()=>oe(V=>!V),children:["Over estimate ",ye.marks.over_estimate]})]}):null]}):null,xt&&(F==null?void 0:F.matched)!==void 0&&F.total!==void 0?i.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:[F.matched," of ",F.total," match ·"," ",i.jsx(U,{type:"button",variant:"link",size:"inline-sm",onClick:Mn,children:"Clear"})]}):null,cm?i.jsx("p",{className:"text-muted-foreground mt-4 text-sm",children:"Tasks are busy. Reading them again…"}):Z?i.jsx(OD,{refusal:Z,on_retry:()=>void B()}):null,!F&&!Z&&i.jsx(TD,{}),F&&qa&&xt?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(uf,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No tasks match"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing open matches these filters."}),i.jsx(U,{type:"button",variant:"outline",onClick:Mn,children:"Clear filters"})]}):F&&qa&&N==="active"&&!T&&v?i.jsx("p",{className:"text-muted-foreground mt-6 text-sm",children:"No tasks recorded yet."}):F&&qa&&N==="active"&&!T?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(lf,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No tasks yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Create the first task, or ask an agent to create one with the SDLC MCP tools."}),_&&i.jsxs(U,{type:"button",onClick:()=>ve(!0),children:[i.jsx(za,{className:"mr-2 size-4","aria-hidden":"true"}),"New task"]})]}):F?i.jsxs(i.Fragment,{children:[i.jsx(yt,{className:"mt-4 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Tasks",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Title"}),i.jsx(Q,{children:"Status"}),xl?i.jsx(Q,{className:"hidden md:table-cell",children:"Priority"}):null,i.jsx(Q,{className:"hidden md:table-cell",children:"Primary"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Holds"}),i.jsx(Q,{children:"Claimed by"}),gl?i.jsx(Q,{className:"text-right",children:"Actions"}):null]})}),i.jsxs(st,{children:[dm.map(V=>{if(V.kind==="group")return i.jsx(x3,{group:V.group,open:V.open,columns:Lr,on_toggle:()=>P(V.group.id,V.open)},`group:${V.group.id}`);if(V.kind==="more")return i.jsx(v3,{group:V.group,whole:Se.includes(V.group.id),columns:Lr,on_toggle:()=>he(V.group.id)},`more:${V.group.id}`);const{row:ue,index:Be}=V,at=Bn.get(ue.status_id),rn=a3(ue),At=ue.local_done;return i.jsx(y3,{columns:Lr,thread:{org:t,action:ue.local_action,task_id:ue.no_page?null:ue.id,open_thread:o==null?void 0:o.open_thread},children:(Nt,Pt)=>{var on,Wn;return i.jsxs(_e,{"data-testid":"tasks-row",className:Pt?"border-b-0":void 0,children:[i.jsxs(X,{"data-title-key":ue.id,children:[ue.no_page&&ue.local_thread?i.jsxs(f,{className:"text-primary inline-flex items-center gap-1 hover:underline",href:h(ib(t,ue.local_thread.key)),"aria-label":`${ue.title}: open ${ue.local_thread.title} in Threads`,children:[ue.title,i.jsx(Cc,{className:"size-3.5 shrink-0","aria-hidden":"true"})]}):ue.no_page?i.jsx("span",{children:ue.title}):i.jsx(f,{className:"text-primary hover:underline",href:h(`/org/${t}/tasks/${ue.id}`),children:ue.title}),ue.parent_task_id&&_i.get(ue.parent_task_id)?i.jsx("div",{className:"text-muted-foreground text-xs",children:_i.get(ue.parent_task_id)}):null,v?i.jsx(w3,{row:ue}):null,Qt[ue.id]?i.jsx("div",{className:"text-destructive text-xs",role:"alert",children:Qt[ue.id]}):null]}),i.jsx(X,{children:at?i.jsx(we,{variant:ED(at),children:at.name}):null}),xl?i.jsx(X,{className:"hidden md:table-cell",children:ue.priority_id?((on=xs.get(ue.priority_id))==null?void 0:on.name)??"":i.jsx("span",{className:"text-muted-foreground",children:"Not set"})}):null,i.jsx(X,{className:"hidden md:table-cell",children:ue.owner_title?ue.owner_title:ue.primary_user_id?j(ue.primary_user_id):i.jsx("span",{className:"text-muted-foreground",children:"Unassigned"})}),i.jsx(X,{className:"hidden md:table-cell",children:rn?i.jsx(we,{variant:rn.tone,children:rn.label}):i.jsx("span",{className:"text-muted-foreground",children:"None"})}),i.jsx(X,{"data-testid":"tasks-claim",children:i.jsx(j3,{row:ue,holder:j((Wn=ue.claim)==null?void 0:Wn.user_id)})}),gl?i.jsx(X,{className:"text-right whitespace-nowrap",children:i.jsxs("div",{className:"flex items-center justify-end gap-2",children:[At&&"hold"in At?i.jsx("a",{className:"text-primary text-sm hover:underline",href:`#waiting-${At.hold}`,children:"In Waiting on you"}):At&&(o!=null&&o.complete)?i.jsx(U,{type:"button",variant:"outline",size:"sm","data-done-key":ue.id,"aria-label":`Mark ${ue.title} done`,loading:Ve===ue.id,onClick:()=>void Te(ue.id,ue.title,At,()=>{var bl;return(((bl=xe.current)==null?void 0:bl.tasks)??[]).map(um=>um.id).filter(um=>um!==ue.id)[Be]??null}),children:"Done"}):null,Nt,ji&&lm?i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",variant:"outline",size:"icon","aria-label":`Move ${ue.title} up`,disabled:Be===0,onClick:()=>void Xi(ue,Be,-1),children:i.jsx(Q2,{className:"size-4","aria-hidden":"true"})}),i.jsx(U,{type:"button",variant:"outline",size:"icon","aria-label":`Move ${ue.title} down`,disabled:Be===W.length-1,onClick:()=>void Xi(ue,Be,1),children:i.jsx(X2,{className:"size-4","aria-hidden":"true"})})]}):null,ji?i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsx(U,{type:"button",variant:"outline",size:"icon","aria-label":`More actions for ${ue.title}`,children:i.jsx(xv,{className:"size-4","aria-hidden":"true"})})}),i.jsxs(bd,{align:"end",children:[wi&&ue.status_id!==wi.id?i.jsx(Uo,{onSelect:()=>zr(ue),children:"Complete"}):null,S?i.jsx(Uo,{className:"text-destructive focus:text-destructive",onSelect:()=>void Mr(ue),children:"Archive"}):null]})]}):null]})}):null]})}},ue.id)}),qa&&i.jsx(_e,{children:i.jsx(X,{colSpan:Lr,className:"text-muted-foreground h-24 text-center",children:N==="archived"?"No archived tasks.":"No tasks are assigned to you."})})]})]})}),F.next_cursor?i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2 self-start",disabled:Y,onClick:async()=>{te(!0),await B(F.next_cursor??void 0),te(!1)},children:"Load more"}):null]}):null,_&&o&&i.jsx(o3,{open:q,commands:o,list_id:y.id,list_revision:(F==null?void 0:F.list.revision)??y.revision,default_status_id:y.default_status_id,statuses:x,priorities:w,members:n,on_close:()=>ve(!1),on_created:async()=>{ve(!1),await Fe()}}),On]})}function m3(e,t){const n=Object.keys(e).filter(a=>e[a]),s=Object.keys(e).filter(a=>!e[a]);return{...n.length?{opened_groups:n}:{},...s.length?{closed_groups:s}:{},...t.length?{all_groups:t}:{}}}function p3(e,t,n,s){if(!t)return e.map((r,o)=>({kind:"row",row:r,index:o}));const a=[];for(const r of t){const o=n[r.id]??r.open;if(a.push({kind:"group",group:r,open:o}),!o||!r.open)continue;let l=0;e.forEach((c,d)=>{c.local_state===r.id&&(a.push({kind:"row",row:c,index:d}),l+=1)}),(r.hidden>0||s.includes(r.id)&&l>g3)&&a.push({kind:"more",group:r})}return a}const g3=10;function x3({group:e,open:t,columns:n,on_toggle:s}){const a=t?rf:ld;return i.jsx(_e,{"data-testid":"tasks-group",children:i.jsx(X,{colSpan:n,className:"p-1",children:i.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"w-full justify-start font-semibold","aria-expanded":t,onClick:s,children:[i.jsx(a,{className:"size-4","aria-hidden":"true"}),e.label," ",e.count]})})})}function v3({group:e,whole:t,columns:n,on_toggle:s}){return i.jsx(_e,{"data-testid":"tasks-group-more",children:i.jsx(X,{colSpan:n,children:i.jsx(U,{type:"button",variant:"link",size:"sm",className:"px-0","aria-expanded":t,onClick:s,children:t?"Show fewer":`Show all ${e.count}`})})})}const b3={you:"text-warning",ok:"text-info",waiting:"text-info",blocked:"text-warning",neutral:"text-muted-foreground",muted:"text-muted-foreground"};function y3({thread:e,columns:t,children:n}){const{button:s,panel:a}=Vf(e);return i.jsxs(i.Fragment,{children:[n(s,!!a),a?i.jsx(_e,{"data-testid":"tasks-row-panel",className:"hover:bg-transparent",children:i.jsx(X,{colSpan:t,className:"pt-0",children:i.jsx("div",{className:"max-w-180 pl-4 text-left whitespace-normal",children:a})})}):null]})}function w3({row:e}){var s;const t=e.local_after,n=e.local_detail;return i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"text-muted-foreground font-mono text-xs",children:[e.id,e.match?` · matched in ${e.match}`:""]}),t||n?i.jsxs("div",{className:"text-muted-foreground text-xs",children:[t,t&&n?" · ":"",n?i.jsx("span",{className:b3[e.local_tone??"muted"],children:n}):null]}):null,(s=e.local_marks)!=null&&s.length?i.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.local_marks.map(a=>i.jsx(we,{variant:a.tone??"neutral",children:a.label},a.label))}):null]})}function _3({owners:e,no_owner:t,value:n,on_change:s}){return i.jsxs(St,{value:n,onValueChange:s,children:[i.jsx(wt,{className:"w-56","aria-label":"Owner",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Vl,children:"Any owner"}),e.map(a=>i.jsxs(Ue,{value:a.id,children:[a.label," (",a.count,")"]},a.id)),t!==void 0?i.jsxs(Ue,{value:RD,children:["No owner (",t,")"]}):null]})]})}function j3({row:e,holder:t}){const n=e.claim;if(!n)return i.jsx("span",{className:"text-muted-foreground",children:"Nobody"});if(n.lapsed){const s=new Date(n.lease_expires_at)<=new Date;return i.jsxs("div",{children:[i.jsxs("div",{className:"text-warning",children:["Lapsed · ",t]}),i.jsx("div",{className:"text-muted-foreground text-xs",children:s?`Ran out at ${Fs(n.lease_expires_at)}`:"Can no longer edit it"})]})}return i.jsxs("div",{className:"max-w-64",children:[i.jsxs("div",{children:[t,n.via?` · ${ab(n.via)}`:""]}),i.jsxs("div",{className:"text-muted-foreground truncate text-xs",title:n.via==="sdlc_login"&&n.via_device?DD(n.via_device):void 0,children:["Until ",Fs(n.lease_expires_at),n.via==="sdlc_login"&&n.via_device?i.jsxs(i.Fragment,{children:[" · ",i.jsx("bdi",{children:n.via_device})]}):null]})]})}const N3={waiting_for_user:{label:"Waiting for",help:"The member who must act. They see this hold under Waiting on you."},blocked:{label:"Blocked by",help:"The task that must finish first."},waiting_for_external:{label:"Waiting for",help:"Who or what outside the organization."},paused:null};function k3({open:e,members:t,tasks:n,holds_my_web_claim:s,on_close:a,on_submit:r}){const[o,l]=u.useState("waiting_for_user"),[c,d]=u.useState(""),[h,f]=u.useState(""),[m,p]=u.useState(!1),[y,g]=u.useState({}),[b,v]=u.useState(null),[x,w]=u.useState(!1);u.useEffect(()=>{e&&(l("waiting_for_user"),d(""),f(""),p(!1),g({}),v(null))},[e]);const _=N3[o],S=async k=>{k.preventDefault();const j={target:_!==null&&!c.trim(),reason:!h.trim()};if(g(j),j.target||j.reason)return;w(!0);const N={hold_type:o,reason:h.trim(),release_claim:m};o==="waiting_for_user"&&(N.target_user_id=c),o==="blocked"&&(N.target_task_id=c),o==="waiting_for_external"&&(N.target_label=c.trim());const O=await r(N);w(!1),v(O)};return i.jsx(yn,{open:e,onOpenChange:k=>k?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:k=>void S(k),noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Add hold"}),i.jsx(kn,{children:"Say what this task is waiting for."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[b&&i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ge,{children:b})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"hold-type",children:"Type"}),i.jsxs(St,{value:o,onValueChange:k=>{l(k),d(""),g({})},children:[i.jsx(wt,{id:"hold-type",children:i.jsx(Ct,{})}),i.jsx(_t,{children:Object.keys(zc).map(k=>i.jsx(Ue,{value:k,children:zc[k].label},k))})]})]}),_?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"hold-target",children:_.label}),o==="waiting_for_external"?i.jsx(bt,{id:"hold-target",value:c,"aria-invalid":y.target,onChange:k=>d(k.target.value)}):i.jsxs(St,{value:c,onValueChange:d,children:[i.jsx(wt,{id:"hold-target","aria-invalid":y.target,children:i.jsx(Ct,{placeholder:o==="blocked"?"Choose a task":"Choose a member"})}),i.jsx(_t,{children:o==="blocked"?n.map(k=>i.jsx(Ue,{value:k.id,children:k.title},k.id)):t.map(k=>i.jsx(Ue,{value:k.user_id,children:k.label},k.user_id))})]}),i.jsx("p",{className:y.target?"text-destructive text-xs":"text-muted-foreground text-xs",children:y.target?"Choose what it waits for.":_.help})]}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"You resume it yourself."}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"hold-reason",children:"Reason"}),i.jsx(Gn,{id:"hold-reason",rows:3,placeholder:"What the task is waiting for",value:h,"aria-invalid":y.reason,onChange:k=>f(k.target.value)}),y.reason&&i.jsx("p",{className:"text-destructive text-xs",children:"Give a reason."})]}),s&&i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nl,{id:"hold-release-claim",checked:m,onCheckedChange:k=>p(k===!0)}),i.jsx(Ie,{htmlFor:"hold-release-claim",children:"Also release my claim"})]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",onClick:a,children:"Cancel"}),i.jsx(U,{type:"submit",disabled:x,children:x?"Adding…":"Add hold"})]})]})})})}function jd(){const e=Vn().tasks;if(!e)throw new Error("The Task page rendered without the tasks seam.");return e}function lb(){return i.jsxs("div",{className:"grid gap-3",role:"status","aria-label":"Loading task",children:[i.jsx(Tt,{className:"h-8 w-1/2"}),Array.from({length:7},(e,t)=>i.jsx(Tt,{className:t===6?"h-6 w-2/3":"h-6 w-full"},t))]})}function kh({back:e,description:t}){const{href:n,Link:s}=lt();return i.jsx(Ha,{title:"Task not found",description:t??"It may have been removed, or you may not have access to it.",backHref:n(e),backLabel:"Back to tasks",link:s})}const Br="not_set",S3=10*60*1e3,e_=20;function C3(){const{members:e}=jd(),[t,n]=u.useState([]);u.useEffect(()=>{let r=!0;return e().then(o=>{r&&o.ok&&n(o.data)}),()=>{r=!1}},[e]);const s=u.useMemo(()=>new Map(t.map(r=>[r.user_id,r])),[t]),a=u.useCallback((r,o)=>{var l;return r?r===o?"You":((l=s.get(r))==null?void 0:l.label)??"A member":""},[s]);return{members:t,name:a}}function D3({active:e,task_id:t,back:n}){const s=jd(),{task:a,activity:r,listTasks:o,hierarchyRevision:l,commands:c}=s,{href:d,Link:h}=lt(),f=Ga(),{self_id:m}=af(),{members:p,name:y}=C3(),{workspace:g}=e,{confirm:b,confirm_dialog:v}=tl(),[x,w]=u.useState(null),[_,S]=u.useState(!1),[k,j]=u.useState(!1),[N,O]=u.useState(null),[T,I]=u.useState([]),[L,$]=u.useState(e_),[A,D]=u.useState([]),[E,R]=u.useState(!1),[C,M]=u.useState(null),[H,z]=u.useState(null),[K,oe]=u.useState(""),[re,Ne]=u.useState(null),Se=u.useCallback(async()=>{if(!a)return;const B=await a(t);B.ok?(w(B.data),j(!1)):B.refusal.status===404||B.refusal.status===400?S(!0):j(!0)},[a,t]),ae=u.useRef(0),F=u.useCallback(async()=>{if(!r)return;const B=ae.current+=1;let Le=[],Fe;for(;;){const Et=await r(t,Fe);if(B!==ae.current||!Et.ok)return;if(Le=[...Le,...Et.data.events].slice(-1e3),!Et.data.more||!Et.data.next_cursor)break;Fe=Et.data.next_cursor}B===ae.current&&I(Le.reverse())},[r,t]);u.useEffect(()=>{Se(),F()},[Se,F]);const ie=x?g.lists.find(B=>B.id===x.task.list_id):void 0,W=u.useMemo(()=>{var B;return((B=g.workflows.find(Le=>Le.id===(x==null?void 0:x.task.workflow_id)))==null?void 0:B.statuses)??[]},[g,x==null?void 0:x.task.workflow_id]);u.useEffect(()=>{if(!x)return;let B=!0;return o(x.task.list_id,{limit:100}).then(Le=>{B&&D(Le.ok?Le.data.tasks.filter(Fe=>Fe.id!==x.task.id).map(Fe=>({id:Fe.id,title:Fe.title})):[])}),()=>{B=!1}},[o,x==null?void 0:x.task.list_id,x==null?void 0:x.task.id,x]);const se=u.useCallback(async()=>{await Promise.all([Se(),F()])},[Se,F]),Z=u.useCallback((B,Le)=>c?c.run(B,Le):Promise.resolve({ok:!1,refusal:{status:0,message:"This page cannot change tasks."}}),[c]),de=u.useCallback(async(B,Le,Fe)=>{const Et=await Z(B,Le);return Et.ok?(Fe&&f.success(Fe),await se(),Et.data):(Et.refusal.code==="revision_conflict"?O({tone:"warning",title:"This task changed while you were editing",body:"We reloaded it. Check the change, then save again."}):Et.refusal.code==="claim_held"?(await Se(),O({tone:"destructive",title:"Someone else claimed this task first",body:"Their claim is shown below. You can take it over if it lapses."})):f.error(Et.refusal.message),await se(),null)},[Z,f,se,Se]),J=(x==null?void 0:x.claim)??null,G=J!==null&&J.id===re&&!J.lapsed&&!J.via?J.id:null;if(u.useEffect(()=>{if(!G)return;const B=window.setInterval(()=>{Z("renew_claim",{claim_id:G,lease_seconds:Jw}).then(()=>Se())},S3);return()=>window.clearInterval(B)},[G,Z,Se]),_)return i.jsx(kh,{back:n});if(k&&!x)return i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This task could not be loaded"}),i.jsxs(ge,{children:[i.jsx("p",{children:"Check your connection and try again."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>void Se(),children:"Retry"})]})]});if(!x)return i.jsx(lb,{});const{task:Y}=x,te=Y.archived_at!==null,ce=Nh(x.permission,"write")&&!te,be=Nh(x.permission,"manage"),fe=W.find(B=>B.id===Y.status_id),$e=W.find(B=>B.category==="completed"),ze=g.priorities.find(B=>B.id===Y.priority_id),q=x.contributors.map(B=>B.user_id),ve=J!==null&&J.user_id===m,Ve=J!==null&&!J.lapsed,Ft=x.checklist.filter(B=>B.is_complete).length,Qt=async()=>{const[B,Le]=await Promise.all([o(Y.list_id,{limit:1}),l(g.id)]);return B.ok?Le.ok?{ok:!0,data:{task_id:Y.id,expected_revision:Y.revision,expected_order_revision:B.data.list.order_revision,expected_hierarchy_revision:Le.data}}:Le:B},ht=(B,Le)=>de("update_task",{task_id:Y.id,expected_revision:Y.revision,changes:B},Le),it=B=>b(B.via==="sdlc_login"?{title:"Release this claim?",description:`You claimed it via ${ap(B.via,B.via_device)}. Its next renewal will be refused, and it will stop holding the task.`,action_label:"Release claim",destructive:!0}:{title:"Release your agent's claim?",description:"Your agent is still working on this task. Its next renewal will be refused, and it will stop holding the task.",action_label:"Release claim",destructive:!0}),Lt=async()=>{if(!$e)return;if(Ve&&(!ve||J.via)){const Le=J.via==="api_key"?`${ve?"Your":`${y(J.user_id)}'s`} agent is still working on it.`:J.via==="sdlc_login"?`${ve?"You are":`${y(J.user_id)} is`} still working on it via ${ap(J.via,J.via_device)}.`:`${y(J.user_id)} is still working on it.`;if(!await b({title:"Complete this task?",description:Le,action_label:"Mark complete"}))return}await ht({status_id:$e.id},"Task completed.")!==null&&J&&ve&&Ve&&await de("end_claim",{claim_id:J.id,outcome:"completed"})},Dt=async(B,Le)=>{const Fe=await Qt();if(!Fe.ok){f.error(Fe.refusal.message);return}await de(B,Fe.data,Le)},On=async()=>{await b({title:"Archive this task?",description:"It leaves the queue and becomes read-only. Its claim, holds and history stay, and a manager can restore it.",action_label:"Archive task",destructive:!0})&&await Dt("archive_task","Task archived.")},mn=async()=>{await Dt("restore_task","Task restored.")},Sn=async()=>{var Et;const B=J,Le=await de("claim_task",{task_id:Y.id,lease_seconds:Jw}),Fe=(Et=Le==null?void 0:Le.claim)==null?void 0:Et.id;Fe&&!(B&&B.id===Fe&&B.via)&&Ne(Fe)},xe=async()=>{J&&(J.via&&!await it(J)||(await de("end_claim",{claim_id:J.id,outcome:"released"},"Claim released."),Ne(null)))},ne=async()=>{J&&await de("end_claim",{claim_id:J.id,outcome:"expired"},"Claim cleared.")},ye=async B=>{B.hold_type==="paused"&&m&&(B={...B,target_user_id:m});const Le=await Z("open_hold",{task_id:Y.id,hold_type:B.hold_type,reason:B.reason,...B.target_user_id?{target_user_id:B.target_user_id}:{},...B.target_task_id?{target_task_id:B.target_task_id}:{},...B.target_label?{target_label:B.target_label}:{}});return Le.ok?(R(!1),f.success("Hold added."),B.release_claim&&J&&ve&&!J.via&&(await de("end_claim",{claim_id:J.id,outcome:"released"}),Ne(null)),await se(),null):Le.refusal.message},qe=B=>de("checklist",{task_id:Y.id,expected_revision:Y.revision,...B}),xt=async B=>{for(const Le of B.filter(Fe=>!q.includes(Fe)))await de("set_contributor",{task_id:Y.id,expected_revision:Y.revision,user_id:Le,action:"add"});for(const Le of x.contributors.filter(Fe=>!B.includes(Fe.user_id)))await de("set_contributor",{task_id:Y.id,expected_revision:Y.revision,user_id:Le.user_id,action:"remove",expected_contributor_revision:Le.revision})},ss=B=>{var Fe;if(B.target.kind==="user")return y(B.target.user_id,m);if(B.target.kind==="external")return B.target.label;if(B.target.hidden||!B.target.task_id)return"A task you cannot see";const Le=B.target.task_id;return i.jsx(h,{className:"text-primary hover:underline",href:d(`${n}/${Le}`),children:((Fe=A.find(Et=>Et.id===Le))==null?void 0:Fe.title)??"Another task"})},zn=B=>B.target.kind==="user"&&B.target.user_id===m&&!B.released_at?i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void de("release_hold",{hold_id:B.id},"Hold released."),children:"Release"}):ce?i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void de("resolve_hold",{hold_id:B.id},"Hold resolved."),children:"Resolve"}):null;return i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:Y.title,description:`Created ${Rs(Y.created_at)} by ${y(Y.created_by,m)}`,actions:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ce&&i.jsxs(i.Fragment,{children:[i.jsxs(U,{type:"button",variant:"outline",onClick:()=>M(Y.title),children:[i.jsx(df,{className:"mr-2 size-4","aria-hidden":"true"}),"Edit title"]}),$e&&Y.status_id!==$e.id&&i.jsxs(U,{type:"button",variant:"outline",onClick:()=>void Lt(),children:[i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}),"Mark complete"]})]}),be&&!te&&i.jsxs(U,{type:"button",variant:"outline",onClick:()=>void On(),children:[i.jsx(xw,{className:"mr-2 size-4","aria-hidden":"true"}),"Archive"]})]}),children:C!==null?i.jsxs("form",{className:"flex flex-wrap items-center gap-2 pt-1",onSubmit:async B=>{B.preventDefault(),C.trim()&&await ht({title:C.trim()})!==null&&M(null)},children:[i.jsx(Ie,{htmlFor:"task-title",className:"sr-only",children:"Title"}),i.jsx(bt,{id:"task-title",className:"max-w-xl",value:C,onChange:B=>M(B.target.value)}),i.jsx(U,{type:"submit",size:"sm",children:"Save"}),i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:()=>M(null),children:"Cancel"})]}):null}),N&&i.jsxs(pe,{variant:N.tone,className:"mt-4","data-testid":"task-notice",children:[N.tone==="warning"?i.jsx(Er,{className:"size-4","aria-hidden":"true"}):i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:N.title}),i.jsx(ge,{children:N.body})]}),te?i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(xw,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This task is archived"}),i.jsx(ge,{children:be?i.jsxs(i.Fragment,{children:[i.jsx("p",{children:"It is out of the queue and cannot be claimed. Restore it to work on it again."}),i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>void mn(),children:[i.jsx(F2,{className:"mr-2 size-4","aria-hidden":"true"}),"Restore"]})]}):i.jsx("p",{children:"It is out of the queue and cannot be claimed. A manager can restore it."})})]}):ce?null:i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can view this task"}),i.jsx(ge,{children:"Ask an organization admin for write access to change it."})]}),ce?i.jsxs("div",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-status",children:"Status"}),i.jsxs(St,{value:Y.status_id,onValueChange:B=>void ht({status_id:B}),children:[i.jsx(wt,{id:"task-status",children:i.jsx(Ct,{})}),i.jsx(_t,{children:W.map(B=>i.jsx(Ue,{value:B.id,children:B.name},B.id))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-priority",children:"Priority"}),i.jsxs(St,{value:Y.priority_id??Br,onValueChange:B=>void ht({priority_id:B===Br?null:B}),children:[i.jsx(wt,{id:"task-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Br,children:"Not set"}),g.priorities.map(B=>i.jsx(Ue,{value:B.id,children:B.name},B.id))]})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-primary",children:"Primary"}),i.jsxs(St,{value:Y.primary_user_id??Br,onValueChange:B=>void ht({primary_user_id:B===Br?null:B}),children:[i.jsx(wt,{id:"task-primary",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Br,children:"Not set"}),p.map(B=>i.jsx(Ue,{value:B.user_id,children:B.label},B.user_id))]})]})]}),i.jsx(E3,{members:p,selected:q,on_change:B=>void xt(B)})]}):i.jsxs("dl",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[i.jsx(Kd,{label:"Status",value:(fe==null?void 0:fe.name)??""}),i.jsx(Kd,{label:"Priority",value:(ze==null?void 0:ze.name)??"Not set"}),i.jsx(Kd,{label:"Primary",value:Y.primary_user_id?y(Y.primary_user_id,m):"Not set"}),i.jsx(Kd,{label:"Contributors",value:q.map(B=>y(B,m)).join(", ")||"None"})]}),!te&&i.jsx(A3,{claim:J,mine:ve,holder:J?y(J.user_id):"",own:J!==null&&J.id===re,can_write:ce,on_claim:()=>void Sn(),on_release:()=>void xe(),on_clear:()=>void ne()}),i.jsxs("section",{className:"mt-6","aria-labelledby":"task-description-title",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("h2",{id:"task-description-title",className:"text-lg font-semibold",children:"Description"}),ce&&H===null&&i.jsx(U,{type:"button",variant:"ghost",size:"sm",onClick:()=>z(Y.description??""),children:"Edit description"})]}),H!==null?i.jsxs("form",{className:"mt-2 grid gap-2",onSubmit:async B=>{B.preventDefault(),await ht({description:H})!==null&&z(null)},children:[i.jsx(Ie,{htmlFor:"task-description",className:"sr-only",children:"Description"}),i.jsx(Gn,{id:"task-description",rows:5,value:H,onChange:B=>z(B.target.value)}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(U,{type:"submit",size:"sm",children:"Save"}),i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:()=>z(null),children:"Cancel"})]})]}):i.jsx("p",{className:"mt-2 text-sm whitespace-pre-wrap",children:Y.description||i.jsx("span",{className:"text-muted-foreground",children:"No description."})})]}),i.jsxs("section",{className:"mt-6","aria-labelledby":"task-checklist-title",children:[i.jsxs("h2",{id:"task-checklist-title",className:"text-lg font-semibold",children:["Checklist",x.checklist.length>0?` · ${Ft} of ${x.checklist.length} done`:""]}),i.jsx("ul",{className:"mt-2 grid gap-1",children:x.checklist.map(B=>i.jsxs("li",{className:"flex items-center justify-between gap-2 py-1","data-testid":"task-checklist-item",children:[ce?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsx(nl,{id:`check-${B.id}`,checked:B.is_complete,onCheckedChange:Le=>void qe({action:"toggle",item_id:B.id,expected_item_revision:B.revision,is_complete:Le===!0})}),i.jsx(Ie,{htmlFor:`check-${B.id}`,className:"font-normal",children:B.label})]}):i.jsxs("span",{className:"text-sm",children:[B.is_complete?"Done: ":"To do: ",B.label]}),ce&&i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"icon","aria-label":`Item actions for ${B.label}`,children:i.jsx(xv,{className:"size-4","aria-hidden":"true"})})}),i.jsx(bd,{align:"end",children:i.jsx(Uo,{className:"text-destructive focus:text-destructive",onSelect:()=>void qe({action:"archive",item_id:B.id,expected_item_revision:B.revision}),children:"Remove"})})]})]},B.id))}),x.checklist.length===0&&!ce&&i.jsx("p",{className:"text-muted-foreground text-sm",children:"No checklist items."}),ce&&i.jsxs("form",{className:"mt-2 grid gap-2",onSubmit:async B=>{B.preventDefault(),K.trim()&&await qe({action:"add",label:K.trim()})!==null&&oe("")},children:[i.jsx(Ie,{htmlFor:"task-new-item",children:"Add an item"}),i.jsx(bt,{id:"task-new-item",placeholder:"Add an item and press Enter",value:K,onChange:B=>oe(B.target.value)})]})]}),i.jsxs("section",{className:"mt-6","aria-labelledby":"task-holds-title",children:[i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("h2",{id:"task-holds-title",className:"text-lg font-semibold",children:"Holds"}),ce&&i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:()=>R(!0),children:[i.jsx(Bk,{className:"mr-2 size-4","aria-hidden":"true"}),"Add hold"]})]}),i.jsx("div",{className:"mt-2 shrink-0 overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Holds",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Type"}),i.jsx(Q,{children:"Reason"}),i.jsx(Q,{children:"Waiting on"}),i.jsx(Q,{className:"text-right",children:"Actions"})]})}),i.jsxs(st,{children:[x.holds.map(B=>{const Le=zc[B.hold_type];return i.jsxs(_e,{"data-testid":"task-hold",children:[i.jsx(X,{children:i.jsx(we,{variant:Le.tone,children:Le.label})}),i.jsxs(X,{children:[i.jsx("div",{children:B.reason}),i.jsx("div",{className:"text-muted-foreground text-xs",children:B.released_at?`Released by ${y(B.released_by,m)} · ${Rs(B.released_at)} · Ready to resolve`:`Opened by ${y(B.opened_by,m)} · ${Rs(B.opened_at)} · Open`})]}),i.jsx(X,{children:ss(B)}),i.jsx(X,{className:"text-right",children:zn(B)})]},B.id)}),x.holds.length===0&&i.jsx(_e,{children:i.jsx(X,{colSpan:4,className:"text-muted-foreground h-16 text-center",children:"Nothing is holding this task."})})]})]})}),i.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:"A hold does not change the task's status. The person it waits on releases it; whoever can edit the task resolves it."})]}),i.jsxs("section",{className:"mt-6 pb-8","aria-labelledby":"task-activity-title",children:[i.jsx("h2",{id:"task-activity-title",className:"text-lg font-semibold",children:"Activity"}),i.jsxs("ul",{className:"mt-2 divide-y rounded-lg border",children:[T.slice(0,L).map(B=>i.jsxs("li",{className:"grid grid-cols-[1fr_auto] gap-x-4 px-3 py-2 text-sm sm:grid-cols-[2fr_1fr_10rem]","data-testid":"task-activity",children:[i.jsx("span",{children:r3(B)}),i.jsxs("span",{className:"min-w-0 text-right sm:text-left",children:[i.jsx("span",{children:B.actor_id?y(B.actor_id,m):"The system"}),B.via?i.jsxs("span",{className:"text-muted-foreground block max-w-64 truncate text-xs sm:max-w-none",title:`via ${ap(B.via,B.via_device)}`,children:["via ",ab(B.via),i.jsx(zD,{via:B.via,device:B.via_device})]}):null]}),i.jsx("span",{className:"text-muted-foreground col-span-2 sm:col-span-1 sm:text-right",children:AD(B.created_at)})]},B.id)),T.length===0&&i.jsx("li",{className:"text-muted-foreground px-3 py-2 text-sm",children:"No activity yet."})]}),T.length>L&&i.jsx(U,{type:"button",variant:"ghost",size:"sm",className:"mt-2",onClick:()=>$(B=>B+e_),children:"Load more"})]}),ce&&ie&&i.jsx(k3,{open:E,members:p,tasks:A,holds_my_web_claim:ve&&Ve&&!(J!=null&&J.via),on_close:()=>R(!1),on_submit:ye}),v]})}function Kd({label:e,value:t}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("dt",{className:"text-muted-foreground text-xs",children:e}),i.jsx("dd",{className:"text-sm",children:t})]})}function E3({members:e,selected:t,on_change:n}){return i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"task-contributors",children:"Contributors"}),i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsxs(U,{id:"task-contributors",type:"button",variant:"outline",className:"justify-between font-normal",children:[t.length===0?i.jsx("span",{className:"text-muted-foreground",children:"Add a contributor"}):i.jsx("span",{className:"truncate",children:e.filter(s=>t.includes(s.user_id)).map(s=>s.label).join(", ")}),i.jsx(Lk,{className:"text-muted-foreground size-4","aria-hidden":"true"})]})}),i.jsx(bd,{align:"start",children:e.map(s=>{const a=t.includes(s.user_id);return i.jsxs(Uo,{onSelect:()=>n(a?t.filter(r=>r!==s.user_id):[...t,s.user_id]),children:[a?i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}):i.jsx("span",{className:"mr-2 size-4"}),s.label]},s.user_id)})})]})]})}function zD({via:e,device:t}){return e!=="sdlc_login"||!t?null:i.jsxs(i.Fragment,{children:[" on ",i.jsx("bdi",{children:t})]})}function A3({claim:e,mine:t,holder:n,own:s,can_write:a,on_claim:r,on_release:o,on_clear:l}){let c=i.jsx(yv,{className:"size-4","aria-hidden":"true"}),d="Nobody is working on this",h=a?"Claim it to show others you are.":"",f=a?i.jsx(U,{type:"button",size:"sm",onClick:r,children:"Claim"}):null;if(e&&e.lapsed){const m=new Date(e.lease_expires_at)<=new Date;c=i.jsx(Pk,{className:"size-4","aria-hidden":"true"}),d=m?`${t?"Your":`${n}'s`} claim lapsed at ${Fs(e.lease_expires_at)}`:`${t?"Your":`${n}'s`} claim lapsed`,h=m?"Its time ran out.":`${n} can no longer edit this task.`,a&&(h+=" Take it over to work on it yourself, or clear it so anyone can claim it."),f=a?i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:l,children:"Clear claim"}),i.jsx(U,{type:"button",size:"sm",onClick:r,children:"Take over"})]}):null}else if(e){const m=Fs(e.lease_expires_at);c=e.via==="api_key"?i.jsx(pv,{className:"size-4","aria-hidden":"true"}):e.via==="sdlc_login"?i.jsx(PO,{className:"size-4","aria-hidden":"true"}):i.jsx(_z,{className:"size-4","aria-hidden":"true"});const p=i.jsxs(i.Fragment,{children:["Claimed via sdlc login",i.jsx(zD,{via:e.via,device:e.via_device}),"."]});t&&e.via==="api_key"?(d=`Your agent is working on this until ${m}`,h="Claimed through one of your API keys. This page does not renew it. Releasing it, or Mark complete, ends the agent's claim after asking."):t&&e.via==="sdlc_login"?(d=`You are working on this until ${m}`,h=i.jsxs(i.Fragment,{children:[p," This page does not renew it. Releasing it, or Mark complete, ends that claim after asking."]})):e.via==="sdlc_login"?(d=`${n} is working on this until ${m}`,h=p):t?(d=`You are working on this until ${m}`,h=s?"Claimed on the web, and renewed while this page is open. Marking the task complete ends your claim.":"Claimed on the web. Marking the task complete ends your claim."):e.via==="api_key"?(d=`${n}'s agent is working on this until ${m}`,h="Claimed through an API key."):(d=`${n} is working on this until ${m}`,h=a?"Claimed on the web. You can take it over if the claim lapses.":"Claimed on the web."),f=t?i.jsx(U,{type:"button",size:"sm",variant:"outline",onClick:o,children:"Release claim"}):null}return i.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-3 rounded-lg border p-3","data-testid":"task-claim",children:[c,i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-medium",children:d}),h?i.jsx("div",{className:"text-muted-foreground text-xs break-words",children:h}):null]}),f?i.jsx("div",{className:"flex items-center gap-2",children:f}):null]})}function cb(e){const t=u.useRef(null),n=u.useRef(!1),[s,a]=u.useState(0),r=u.useCallback(o=>{var l;!o&&((l=t.current)!=null&&l.contains(document.activeElement))&&(n.current=!0,a(c=>c+1)),t.current=o},[]);return u.useEffect(()=>{var c;if(!n.current)return;n.current=!1;const o=document.activeElement;if(o&&o!==document.body)return;const l=(c=e.current)==null?void 0:c.querySelector("h1");l&&(l.tabIndex=-1,l.focus())},[s,e]),r}function MD(){const e=u.useRef(null);return u.useCallback(t=>{const n=e.current;if(e.current=t,t||!(n!=null&&n.contains(document.activeElement)))return;const s=(n.closest("main")??document).querySelector("h1");s&&Promise.resolve().then(()=>{const a=document.activeElement;a&&a!==document.body||!s.isConnected||(s.tabIndex=-1,s.focus())})},[])}const R3=10,$D=5,T3=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,LD="Not available",O3={added:"Added",changed:"Changed",removed:"Removed"},z3={thread:"Thread",task:"Task",issue:"Issue",release:"Release",test:"Test"},t_=/^[A-Za-z0-9][A-Za-z0-9._+-]{0,127}$/;function M3(e,t){const n=t!=null&&t.startsWith("task:")?t.slice(5):null;if(n&&T3.test(n))return{label:n,path:`/org/${e}/tasks/${n}`};const s=t!=null&&t.startsWith("issue:")?t.slice(6):null;if(s&&/^iss-\d{1,9}$/.test(s))return{label:s,path:`/org/${e}/issues/${s}`};const a=t!=null&&t.startsWith("release:")?t.slice(8):null;if(a&&t_.test(a))return{label:a==="candidate"?"Candidate":`Release ${a}`,path:`/releases?release=${a}`};const r=t!=null&&t.startsWith("planned:")?t.slice(8):null;return r&&t_.test(r)?{label:`Planned Release ${r}`,path:`/releases?planned=${r}`}:{label:"Tasks",path:`/org/${e}/tasks`}}const PD=e=>e.status===0||e.reason==="store_locked"||e.reason==="engine_failed"||e.status>=500;function $3({org:e,task_id:t,from:n}){var mn,Sn;const s=jd(),{href:a,Link:r}=lt(),{confirm:o,confirm_dialog:l}=tl(),c=M3(e,n),[d,h]=u.useState({state:"loading"}),[f,m]=u.useState([]),[p,y]=u.useState([]),[g,b]=u.useState(null),[v,x]=u.useState(null),[w,_]=u.useState({state:"loading"}),[S,k]=u.useState({state:"loading"}),[j,N]=u.useState(null),[O,T]=u.useState(null),[I,L]=u.useState(!1),$=u.useRef(null),A=ns(),D=Vf({org:e,action:d.state==="ok"?d.detail.local_action:void 0,task_id:t,open_thread:(mn=s.commands)==null?void 0:mn.open_thread,labelled:!0}),E=u.useRef(null),R=u.useRef(null),C=u.useRef(null),M=u.useRef(null),H=u.useRef(!1),z=u.useRef(0),K=u.useRef(0),oe=u.useCallback(async()=>{if(!s.taskSections)return;_({state:"loading"});const xe=await s.taskSections(t);_(xe.ok?{state:"ok",data:xe.data}:{state:"failed",refusal:xe.refusal})},[s.taskSections,t]),re=u.useCallback(async()=>{if(!s.taskRelated)return;k({state:"loading"});const xe=await s.taskRelated(t);k(xe.ok?{state:"ok",data:xe.data}:{state:"failed",refusal:xe.refusal})},[s.taskRelated,t]),Ne=u.useCallback(async()=>{var xt,ss;const xe=K.current+=1;x(null),oe(),re();const[ne,ye]=await Promise.all([s.availability(),s.task?s.task(t):Promise.resolve(null)]);if(xe!==K.current)return;ne.state==="active"&&m(((xt=ne.workspace.workflows.find(zn=>zn.id===ne.list.workflow_id))==null?void 0:xt.statuses)??[]);const qe=ne.state==="off"&&((ss=ne.refusal)==null?void 0:ss.reason)==="engine_missing"?ne.refusal:null;if(!ye||!ye.ok&&ye.refusal.reason==="engine_missing"||qe){h({state:"engine_missing",refusal:qe??(ye&&!ye.ok?ye.refusal:{status:0,message:""})});return}if(ye.ok){z.current=0,b(null),T(null),h({state:"ok",detail:ye.data,at:new Date().toISOString()});return}if(ye.refusal.status===404||ye.refusal.reason==="not_found"){h({state:"missing"});return}if(z.current+=1,z.current===1&&PD(ye.refusal)){x(ye.refusal.retry_after??R3);return}b(ye.refusal),h(zn=>zn.state==="loading"?{state:"loading"}:zn)},[s,t,oe,re]);u.useEffect(()=>{Ne()},[Ne]),u.useEffect(()=>{if(v===null)return;const xe=setTimeout(()=>void Ne(),v*1e3);return()=>clearTimeout(xe)},[v,Ne]),u.useEffect(()=>{let xe=!0;return s.members().then(ne=>{xe&&ne.ok&&y(ne.data)}),()=>{xe=!1}},[s.members]),u.useEffect(()=>{var ne;if(H.current||d.state!=="ok")return;H.current=!0;const xe=(ne=$.current)==null?void 0:ne.querySelector("h1");xe&&(xe.tabIndex=-1,xe.focus())},[d.state]),u.useEffect(()=>{var xe;j&&((xe=R.current)==null||xe.focus())},[j]),u.useEffect(()=>{if(O===null)return;const xe=setTimeout(()=>{var ne;return(ne=E.current)==null?void 0:ne.focus()},0);return()=>clearTimeout(xe)},[O]);const Se=u.useMemo(()=>new Map(p.map(xe=>[xe.user_id,xe.label])),[p]),ae=xe=>xe?Se.get(xe)??xe:"",F=()=>{N(null),Ne()},ie=u.useRef(null),W=xe=>(ie.current=xe,xe==="graph"?oe():re());if(u.useEffect(()=>{var ye;const xe=ie.current;if(xe===null||(xe==="graph"?w:S).state==="loading")return;ie.current=null;const ne=(xe==="graph"?C:M).current??((ye=$.current)==null?void 0:ye.querySelector("h1"));ne==null||ne.focus()},[w,S]),d.state==="missing")return i.jsx(ma,{children:i.jsx(kh,{back:`/org/${e}/tasks`,description:`No task ${t} in this checkout. It may have finished and been archived, or never been recorded.`})});const se=i.jsx(U,{asChild:!0,variant:"link",size:"sm",className:"px-0",children:i.jsxs(r,{href:a(c.path),children:[i.jsx($k,{className:"size-4","aria-hidden":"true"}),c.label]})});if(d.state==="engine_missing")return i.jsx(ma,{children:i.jsx("div",{ref:$,className:"contents",children:i.jsx(yi,{page:"Task",header:i.jsx(oc,{back:se,id:null,title:t})})})});const Z=g?i.jsxs(pe,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not read this task"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[g.message,g.since?` Since ${As(g.since)}.`:"",d.state==="ok"?` This page was read at ${As(d.at)}.`:""," See the sdlc viewer terminal for more."]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:F,children:"Retry"})]})]}):null,de=v!==null?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"Could not read this task. Trying again in ",v," seconds."]}):null,J=i.jsx("div",{role:"status","aria-live":"polite",children:de});if(d.state==="loading")return i.jsxs(ma,{children:[J,Z,!g&&v===null?i.jsx(lb,{}):null]});const{detail:G,at:Y}=d,{task:te}=G,ce=f.find(xe=>xe.id===te.status_id),be=G.local_done&&"task"in G.local_done?G.local_done:null,fe=G.local_waits??[],$e=be?fe[0]??null:null,ze=$e?ae($e.opened_by):G.owner_title??ae(G.thread),q=w.state==="ok"?w.data:null,ve=(q==null?void 0:q.lifecycle)==="finished",Ve=ve&&(q==null?void 0:q.outcome)==="cancelled",Ft=ve&&(q==null?void 0:q.outcome)==="complete",Qt=!!te.created_at,ht=G.acceptance??[],it=G.local_owner_thread,Lt=it?i.jsx(r,{className:"text-primary hover:underline",href:a(ib(e,it.key)),children:it.title}):G.owner_title??(ae(G.thread)||"None"),Dt=async()=>{var ye;if(!be||!((ye=s.commands)!=null&&ye.complete)||!await o({title:`Mark ${te.title} done?`,description:$e?`This answers ${ze}'s ask, “${$e.reason}”, closes that wait, and tells ${ze} to check and continue.`:`This tells ${ze||"its thread"} to check and continue.`,action_label:"Mark done"}))return;L(!0);const ne=await s.commands.complete(be);if(L(!1),!ne.ok){T(ne.refusal.message);return}await Ne(),N({title:te.title,asker:ze||"Its thread"})},On=i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[be&&!j?i.jsxs(i.Fragment,{children:[i.jsxs(U,{ref:E,type:"button",variant:"outline",disabled:I,"aria-disabled":O!==null?!0:void 0,"aria-describedby":O!==null?"task-done-why":void 0,onClick:()=>{O===null&&Dt()},children:[i.jsx(Dr,{className:"mr-2 size-4","aria-hidden":"true"}),"Done"]}),O!==null?i.jsx("span",{id:"task-done-why",className:"text-muted-foreground text-xs",children:"Read again first"}):null]}):null,D.button,i.jsxs("span",{className:"text-muted-foreground text-sm",children:["Read at ",As(Y)]}),i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:F,children:[i.jsx(Er,{className:"mr-2 size-4","aria-hidden":"true"}),"Read again"]})]});return i.jsxs(ma,{children:[i.jsxs("div",{ref:$,className:"contents",children:[i.jsx(oc,{back:se,id:te.id,copy:i.jsx(Ug,{text:te.id,label:"Copy ID",what:"the ID",variant:"ghost"}),badge:ce?i.jsx(we,{variant:ED(ce),children:ce.name}):null,title:te.title,created:Qt?`Created ${Rs(te.created_at)}${ze||G.owner_title?` by ${G.owner_title??ze}`:""}`:null,actions:On}),D.panel?i.jsx("div",{className:"mt-1 max-w-180",children:D.panel}):null,J,Z,j?i.jsx("div",{ref:R,tabIndex:-1,role:"status","aria-live":"polite",className:"outline-none",children:i.jsxs(pe,{variant:"success",className:"mt-4",children:[i.jsx(of,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Marked ",j.title," done"]}),i.jsxs(ge,{children:[j.asker," is told to check and continue."]})]})}):null,O!==null?i.jsxs(pe,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Done was not recorded"}),i.jsxs(ge,{children:[O," Read again to see the task as it is now."]})]}):null,$e&&!j?i.jsxs(pe,{variant:"warning",className:"mt-4",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:[ze," asks: ",$e.reason]}),i.jsxs(ge,{children:["Waiting on you since ",rb($e.opened_at),". Done answers it and tells ",ze," to check and continue."]})]}):null,G.view_outdated?i.jsxs(pe,{variant:"warning",className:"mt-4",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsxs(ge,{children:[A," Until then this page cannot read the claim and holds."]})]}):null,i.jsxs("dl",{className:"mt-4 grid gap-4 sm:grid-cols-2 lg:grid-cols-4",children:[i.jsx(ai,{label:"Owner thread",value:Lt}),i.jsx(ai,{label:"Release",value:G.release??"None"}),i.jsx(ai,{label:"Session",value:w.state==="loading"?"Loading…":w.state==="failed"?"Not available":q!=null&&q.session?i.jsxs(i.Fragment,{children:[q.session.provider," ",i.jsx("span",{className:"font-mono break-all",children:q.session.id})]}):"None"}),i.jsx(ai,{label:"Now",value:G.local_detail??(ce==null?void 0:ce.name)??""})]}),i.jsx("p",{className:"text-muted-foreground mt-2 text-xs",children:"Local tasks have no priority or contributors."}),i.jsx(L3,{detail:G,holder:ae((Sn=G.claim)==null?void 0:Sn.user_id),finished_at:ve?(q==null?void 0:q.finished_at)??null:null,read_at:Y}),i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"text-info size-4","aria-hidden":"true"}),be?i.jsxs(i.Fragment,{children:[i.jsx(ke,{children:"Done is the one change this page makes"}),i.jsx(ge,{children:"Everything else about this task changes through its thread."})]}):i.jsxs(i.Fragment,{children:[i.jsx(ke,{children:"This page only reads tasks"}),i.jsx(ge,{children:"A task changes through the agent thread working on it."})]})]}),Qt?q!=null&&q.record?i.jsxs("p",{className:"mt-4 flex flex-wrap items-center gap-2 text-sm",children:[i.jsxs("span",{children:["Record ",i.jsx("code",{className:"font-mono break-all",children:q.record})]}),i.jsx(Ug,{text:q.record,label:"Copy path",what:"the path",variant:"ghost"})]}):null:i.jsx("p",{className:"mt-4 text-sm",children:"No task record yet. This page shows what the threads and plans in this checkout say about it."}),be?i.jsx(Yt,{id:"task-done-needs",title:"What Done needs",children:ht.length>0?i.jsxs(i.Fragment,{children:[i.jsxs("p",{className:"text-muted-foreground text-xs",children:["The task's acceptance; ",ze||"its thread"," checks these after Done."]}),i.jsx("ul",{className:"mt-2 grid list-disc gap-1 pl-5 text-sm",children:ht.map(xe=>i.jsx("li",{children:xe},xe))})]}):i.jsxs("p",{className:"text-sm",children:["Its thread gave no acceptance. Ask ",ze||"its thread"," what Done needs before marking it."]})}):ht.length>0?i.jsxs(Yt,{id:"task-acceptance",title:"Acceptance",children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:Ft?"All met: the task finished complete":Ve&&(q!=null&&q.finished_at)?`Cancelled ${Rs(q.finished_at)}`:"Met when the task finishes complete"}),i.jsx("ul",{className:"mt-2 grid list-disc gap-1 pl-5 text-sm",children:ht.map(xe=>i.jsx("li",{children:Ft?`Met: ${xe}`:xe},xe))})]}):null,i.jsx(P3,{detail:G,waits:fe,given:be!==null,threadName:ae,threadsLink:i.jsx(r,{className:"text-primary hover:underline",href:a(`/org/${e}/threads`),children:"Threads"})}),w.state==="loading"?i.jsxs("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading the task's sections",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"})]}):null,q?i.jsx(Yt,{id:"task-stands",title:"Where it stands",children:i.jsxs("p",{className:"text-sm",children:[(ce==null?void 0:ce.name)??te.status_id,G.local_detail?` · ${G.local_detail}`:""]})}):null,q!=null&&q.time?i.jsx(I3,{time:q.time}):null,i.jsx(G3,{sections:w,heading_ref:C,on_retry:()=>void W("graph"),taskLink:xe=>i.jsx(r,{className:"text-primary hover:underline",href:a(`/org/${e}/tasks/${xe}?from=task:${te.id}`),children:xe})}),q!=null&&q.files?i.jsx(H3,{files:q.files,finished:ve}):null,q!=null&&q.proof?i.jsx(V3,{proof:q.proof,finished_at:q.finished_at,who:G.owner_title??null}):null,q&&q.history.length>0?i.jsx(U3,{history:q.history}):null,i.jsx(ID,{related:S,heading_ref:M,on_retry:()=>void W("related"),link:xe=>{const ne=xe.kind==="thread"?`${e?`/org/${e}`:""}/threads#thread-${encodeURIComponent(xe.id)}`:xe.kind==="task"?`/org/${e}/tasks/${xe.id}?from=task:${te.id}`:xe.kind==="issue"?`/org/${e}/issues/${encodeURIComponent(xe.id)}?from=task:${te.id}`:xe.kind==="release"?`/releases?${xe.planned?"planned":"release"}=${encodeURIComponent(xe.id)}`:null;return ne?i.jsx(r,{className:je("text-primary hover:underline",xe.kind!=="thread"&&xe.label===xe.id&&"font-mono"),href:a(ne),children:xe.label}):xe.label}})]}),l]})}function ma({children:e}){return i.jsx("div",{className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 pb-8 sm:px-6 lg:px-8",children:e})}function oc({back:e,id:t,copy:n,badge:s,title:a,created:r,actions:o}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("div",{children:e}),t?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[i.jsx("code",{className:"font-mono",children:t}),n,s]}):null,i.jsx(bn,{title:a,description:r??void 0,actions:o})]})}function ai({label:e,value:t}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("dt",{className:"text-muted-foreground text-xs",children:e}),i.jsx("dd",{className:"m-0 text-sm break-words",children:t})]})}function Yt({id:e,title:t,aside:n,heading_ref:s,children:a}){return i.jsxs("section",{className:"mt-6","aria-labelledby":`${e}-title`,children:[i.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[i.jsx("h2",{id:`${e}-title`,ref:s,tabIndex:s?-1:void 0,className:"text-lg font-semibold outline-none",children:t}),n?i.jsx("span",{className:"text-muted-foreground text-sm",children:n}):null]}),i.jsx("div",{className:"mt-2",children:a})]})}function L3({detail:e,holder:t,finished_at:n,read_at:s}){const a=e.claim,[,r]=u.useReducer(h=>h+1,0),o=a&&!e.view_outdated?new Date(a.lease_expires_at).getTime():null;u.useEffect(()=>{if(o===null||!Number.isFinite(o))return;const h=o-Date.now();if(h<=0)return;const f=setTimeout(r,Math.min(h+50,2147483647));return()=>clearTimeout(f)},[o]);let l=i.jsx(yv,{className:"size-4","aria-hidden":"true"}),c="Nobody is working on this",d=null;if(e.view_outdated)c=`Claimed by: ${LD}`;else if(a){const h=new Date(a.lease_expires_at)<=new Date(Math.max(Date.now(),new Date(s).getTime()));l=i.jsx(pv,{className:"size-4","aria-hidden":"true"}),c=`${t} is working on this until ${As(a.lease_expires_at)}${h||a.lapsed?" · passed":""}`,d="Claimed in the coordination registry; its thread renews the claim."}else n&&(l=i.jsx(of,{className:"size-4","aria-hidden":"true"}),d=`Finished ${Rs(n)}. Its claim ended when it finished.`);return i.jsxs(yt,{className:"mt-4 flex flex-wrap items-center gap-3 p-3","data-testid":"task-claim",children:[l,i.jsxs("div",{className:"min-w-0 flex-1",children:[i.jsx("div",{className:"text-sm font-medium",children:c}),d?i.jsx("div",{className:"text-muted-foreground text-xs break-words",children:d}):null]})]})}function P3({detail:e,waits:t,given:n,threadName:s,threadsLink:a}){if(e.view_outdated)return i.jsx(Yt,{id:"task-holds",title:"Holds",children:i.jsx("p",{className:"text-sm",children:LD})});if(e.holds.length===0)return null;const r=new Map(t.map(o=>[o.id,o]));return i.jsxs(Yt,{id:"task-holds",title:`Holds · ${e.holds.length} open`,children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:"A hold does not change the task's status."}),i.jsx(yt,{className:"mt-2 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Holds",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Type"}),i.jsx(Q,{children:"Reason"}),i.jsx(Q,{children:"Waiting on"}),i.jsx(Q,{children:"Opened"})]})}),i.jsx(st,{children:e.holds.map(o=>{var h;const l=r.get(o.id),c=zc[o.hold_type],d=n?"Done above answers it":l!=null&&l.local_done?"In Waiting on you":(h=l==null?void 0:l.local_threads)!=null&&h.length?i.jsxs(i.Fragment,{children:["Answer it in ",a,": ",l.local_threads.join(" · ")]}):null;return i.jsxs(_e,{"data-testid":"task-hold",children:[i.jsx(X,{children:i.jsx(we,{variant:c.tone,children:(l==null?void 0:l.local_label)??c.label})}),i.jsxs(X,{children:[i.jsx("div",{children:o.reason}),i.jsxs("div",{className:"text-muted-foreground text-xs",children:["Opened by ",s(o.opened_by)]})]}),i.jsxs(X,{children:[i.jsx("div",{children:o.target.kind==="user"?"You":o.target.kind==="external"?o.target.label:"Another task"}),d?i.jsx("div",{className:"text-muted-foreground text-xs",children:d}):null]}),i.jsx(X,{children:rb(o.opened_at)})]},o.id)})})]})})]})}function I3({time:e}){return i.jsx(Yt,{id:"task-time",title:"Time",children:i.jsxs("dl",{className:"grid gap-4 sm:grid-cols-3",children:[i.jsx(ai,{label:"Estimate",value:e.estimate?`${El(e.estimate.low)}–${El(e.estimate.high)}`:e.unknown_reason??"None"}),i.jsx(ai,{label:"Time taken",value:e.elapsed!==null?`${El(e.elapsed)}${e.over_estimate?" · over estimate":""}`:"Not started"}),e.forecast?i.jsx(ai,{label:"Reforecast",value:i.jsxs("span",{className:"text-muted-foreground",children:[El(e.forecast.low),"–",El(e.forecast.high)," left",e.forecast.reason?` · ${e.forecast.reason}`:""]})}):null]})})}function db({what:e,again:t,refusal:n,on_retry:s}){const a=MD();return i.jsxs(pe,{variant:"destructive",ref:a,children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Could not read ",e]}),i.jsxs(ge,{children:[i.jsx("p",{children:n.message}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:s,children:t})]})]})}function G3({sections:e,heading_ref:t,on_retry:n,taskLink:s}){const[a,r]=u.useState(!1);if(e.state==="loading")return null;const o=e.state==="failed"?e.refusal:e.data.graph.ok?null:e.data.graph.refusal;if(o)return i.jsx(Yt,{id:"task-graph",title:"Graph changes",heading_ref:t,children:i.jsx(db,{what:"graph changes",again:"Read graph changes again",refusal:o,on_retry:n})});const l=e.state==="ok"&&e.data.graph.ok?e.data.graph.data:null;if(!l)return null;if(l.exempt)return i.jsx(Yt,{id:"task-graph",title:"Graph changes",heading_ref:t,children:i.jsxs("p",{className:"text-sm",children:["This task changes no modeled design. Its plan says why: ",l.exempt,"."]})});if(l.changes.length===0)return null;const c=a?l.changes:l.changes.slice(0,$D),d=l.changes.length-c.length;return i.jsxs(Yt,{id:"task-graph",title:"Graph changes",aside:l.document,heading_ref:t,children:[i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Graph changes",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Change"}),i.jsx(Q,{children:"Kind of change"}),i.jsx(Q,{children:"Also in"}),i.jsx(Q,{children:"In the plan"})]})}),i.jsx(st,{children:c.map(h=>i.jsxs(_e,{children:[i.jsxs(X,{children:[i.jsx("div",{children:h.label}),i.jsx("div",{className:"text-muted-foreground text-xs",children:h.type})]}),i.jsx(X,{children:O3[h.change]}),i.jsx(X,{children:h.also_in.length===0?"No other task":h.also_in.map((f,m)=>i.jsxs(u.Fragment,{children:[m>0?", ":null,s(f.id)]},f.id))}),i.jsx(X,{children:h.planned?"Yes":i.jsx(we,{variant:"warning",children:"No longer planned"})})]},`${h.id}:${h.planned}`))})]})}),d>0?i.jsxs("p",{className:"mt-2 flex flex-wrap items-center gap-2 text-sm",children:[d," more changes in this task's plan slice.",i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:()=>r(!0),children:["Show all ",l.changes.length]})]}):null]})}function H3({files:e,finished:t}){const[n,s]=u.useState(!1),a=n?e.paths:e.paths.slice(0,$D);return i.jsxs(Yt,{id:"task-files",title:"Files",children:[a.length>0?i.jsx("ul",{className:"grid gap-1 text-sm",children:a.map(r=>i.jsx("li",{children:i.jsx("span",{className:"font-mono break-all",children:r})},r))}):null,e.paths.length>a.length?i.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"mt-1",onClick:()=>s(!0),children:["Show all ",e.paths.length]}):null,e.landed?i.jsxs("p",{className:"mt-2 text-sm",children:["Landed ",i.jsx("span",{className:"font-mono",children:e.landed.sha.slice(0,10)})," · ",e.landed.files," files",t?"":" · becomes the proof when the task finishes"]}):null]})}function V3({proof:e,finished_at:t,who:n}){return i.jsxs(Yt,{id:"task-proof",title:"Evidence and proof",children:[e.evidence?i.jsx("p",{className:"text-sm whitespace-pre-wrap",children:e.evidence}):null,e.no_code?i.jsxs("p",{className:"mt-2 text-sm",children:["No code: ",e.no_code]}):e.commit?i.jsxs("p",{className:"mt-2 text-sm",children:["Proof ",i.jsx("span",{className:"font-mono",children:e.commit.slice(0,10)})," ·"," ",e.on_main?"on main":"not yet on main"]}):null,t?i.jsxs("p",{className:"text-muted-foreground mt-2 text-xs",children:["Finished ",Rs(t),n?` by ${n}`:""]}):null]})}function U3({history:e}){return i.jsxs(Yt,{id:"task-history",title:"History",children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:"From the task record, newest first"}),i.jsx(yt,{className:"mt-2 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"History",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"What"}),i.jsx(Q,{children:"Who"}),i.jsx(Q,{children:"When"})]})}),i.jsx(st,{children:e.map((t,n)=>i.jsxs(_e,{children:[i.jsx(X,{children:t.what}),i.jsx(X,{children:t.who??"Its thread"}),i.jsx(X,{children:rb(t.at)})]},`${t.at}:${n}`))})]})})]})}function ID({id:e="task-related",related:t,heading_ref:n,on_retry:s,link:a,fixed:r=!1}){return t.state==="ok"&&t.data.length===0?null:i.jsx(Yt,{id:e,title:"Related",heading_ref:n,children:t.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"})]}):t.state==="failed"?i.jsx(db,{what:"related work",again:"Read related work again",refusal:t.refusal,on_retry:s}):i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Related",className:r?"table-fixed":void 0,children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{className:r?"w-[14%]":void 0,children:"Kind"}),i.jsx(Q,{className:r?"w-[45%]":void 0,children:"Item"}),i.jsx(Q,{className:r?"w-[41%]":void 0,children:"How it relates"})]})}),i.jsx(st,{children:t.data.map(o=>i.jsxs(_e,{children:[i.jsx(X,{children:z3[o.kind]}),i.jsx(X,{className:r?"break-words":void 0,children:a(o)}),i.jsx(X,{className:r?"break-words":void 0,children:o.relation})]},`${o.kind}:${o.planned?"planned:":""}${o.id}`))})]})})})}function B3({org:e,task_id:t,from:n}){const s=jd(),a=`/org/${e}/tasks`;return s.taskSections?i.jsx($3,{org:e,task_id:t,from:n??null}):i.jsx(W3,{task_id:t,back:a})}function W3({task_id:e,back:t}){const{availability:n}=jd(),[s,a]=u.useState({state:"loading"});return u.useEffect(()=>{let r=!0;return n().then(o=>{r&&a(o)}),()=>{r=!1}},[n]),s.state==="off"?i.jsx(kh,{back:t}):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:s.state==="active"?i.jsx(D3,{active:s,task_id:e,back:t}):s.state==="error"?i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This task could not be loaded"}),i.jsx(ge,{children:"Check your connection and try again."})]}):s.state==="available"?i.jsx(kh,{back:t}):i.jsx(lb,{})})}function Kn({children:e}){return i.jsx("p",{role:"alert",className:"text-destructive text-sm",children:e})}const F3=["open","triaged","resolved","closed"],ub=["low","normal","high","urgent"],q3=["fixed","works_as_intended","planned","duplicate","wont_fix","cannot_reproduce"],Y3=["title","description","external_reference"],Sh={open:"Open",triaged:"Triaged",escalated:"Escalated",waiting_on_fix:"Waiting on fix",resolved:"Resolved",closed:"Closed"},GD={open:"warning",triaged:"info",escalated:"info",waiting_on_fix:"info",resolved:"success",closed:"neutral"},Mc={low:"Low",normal:"Normal",high:"High",urgent:"Urgent"},hb={fixed:"Fixed",works_as_intended:"Works as intended",planned:"Planned",duplicate:"Duplicate",wont_fix:"Won't fix",cannot_reproduce:"Cannot reproduce"},HD={title:"Title",description:"Description",external_reference:"External reference"},X3=[["year",365*24*3600],["month",30*24*3600],["week",7*24*3600],["day",24*3600],["hour",3600],["minute",60]];function Au(e,t=Date.now()){const n=Math.round((new Date(e).getTime()-t)/1e3),s=new Intl.RelativeTimeFormat("en",{numeric:"auto"});for(const[a,r]of X3)if(Math.abs(n)>=r)return s.format(Math.round(n/r),a);return"just now"}function Bg(e,t,n){const s=`/org/${encodeURIComponent(e)}/proj/${encodeURIComponent(t)}/support`;return n?`${s}/${encodeURIComponent(n)}`:s}function fb(e,t){return e?t??"Not available":"A former member"}const K3="the issue integration";function Z3(e){return!e.created_by&&e.reporter_kind==="customer"?K3:fb(e.created_by,e.created_by_username)}function Q3(e,t){return!e.actor_id&&e.kind==="created"&&t.reporter_kind==="customer"?"The issue integration":fb(e.actor_id,e.actor_username)}const Zd="not_set",J3="Do not paste personal data. Leave out names, such as borrower names, and loan numbers; text shaped like an email address, phone number, or social security number is refused.";function eG({create:e,open:t,onOpenChange:n,onCreated:s}){const[a,r]=u.useState(""),[o,l]=u.useState(""),[c,d]=u.useState(!1),[h,f]=u.useState(""),[m,p]=u.useState(Zd),[y,g]=u.useState(!1),[b,v]=u.useState(null),x=u.useRef(null),w=()=>{r(""),l(""),d(!1),f(""),p(Zd),v(null),x.current=null},_=j=>{var N;return((N=b==null?void 0:b.personal_data)==null?void 0:N.field)===j?b.message:void 0},S=async j=>{if(j.preventDefault(),y)return;g(!0),x.current??(x.current=crypto.randomUUID());const N=await e({request_id:x.current,title:o.trim()||void 0,description:h||void 0,external_reference:a.trim()||void 0,priority:m===Zd?null:m});if(g(!1),!N.ok){N.refusal.status!==0&&(x.current=null),v(N.refusal);return}w(),s(N.data.issue,N.data.duplicates)},k=b&&!b.personal_data?b.message:void 0;return i.jsx(yn,{open:t,onOpenChange:j=>{j||w(),n(j)},children:i.jsx(wn,{className:"sm:max-w-2xl",children:i.jsxs("form",{onSubmit:S,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"New support issue"}),i.jsx(kn,{children:"Log one help-desk report. Text is shown exactly as entered."})]}),i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{}),i.jsx(ge,{children:J3})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-reference",children:"External reference"}),i.jsx(bt,{id:"maintain-issue-reference",value:a,"aria-invalid":!!_("external_reference"),onChange:j=>{r(j.target.value),c||l(j.target.value)}}),_("external_reference")?i.jsx(Kn,{children:_("external_reference")}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"The help-desk ticket number."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-title",children:"Title"}),i.jsx(bt,{id:"maintain-issue-title",value:o,"aria-invalid":!!_("title"),onChange:j=>{l(j.target.value),d(!0)}}),_("title")?i.jsx(Kn,{children:_("title")}):i.jsx("p",{className:"text-muted-foreground text-xs",children:"Prefilled from the external reference; edit it if you like."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-description",children:"Description"}),i.jsx(Gn,{id:"maintain-issue-description",rows:4,placeholder:"What the end user reported, without personal data",value:h,"aria-invalid":!!_("description"),onChange:j=>f(j.target.value)}),_("description")?i.jsx(Kn,{children:_("description")}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-issue-priority",children:"Priority"}),i.jsxs(St,{value:m,onValueChange:p,children:[i.jsx(wt,{id:"maintain-issue-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Zd,children:"Not set"}),ub.map(j=>i.jsx(Ue,{value:j,children:Mc[j]},j))]})]})]}),k?i.jsx(Kn,{children:k}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>{w(),n(!1)},children:"Cancel"}),i.jsx(U,{type:"submit",loading:y,disabled:!o.trim()&&!a.trim(),children:"Log issue"})]})]})})})}const tG=["supportAccess","assigneeCandidates","create","update","assign","transition","redact"];function VD(){return nG(Vn().issues)}function nG(e){return e&&tG.every(t=>typeof e[t]=="function")?e:null}function UD(e){const[t,n]=u.useState(null);return u.useEffect(()=>{if(!e)return;let s=!1;return e.supportAccess().then(a=>{s||n({contract:e,state:a.ok?{state:"ready",access:a.data}:{state:"error"}})}),()=>{s=!0}},[e]),t&&e&&t.contract===e?t.state:{state:"loading"}}function BD({access:e,header:t,back_href:n,children:s}){const{href:a,Link:r}=lt();return e.state==="loading"?i.jsxs("div",{className:"flex flex-1 items-center justify-center py-24",children:[i.jsx(vn,{className:"size-5"}),i.jsx("span",{className:"sr-only",children:"Loading…"})]}):e.state==="error"||!e.access.enabled?i.jsx(Ha,{title:"Page not found",description:"This page does not exist or you do not have access to it.",backHref:a(n),backLabel:"Back to the project",link:r}):e.access.can_view?i.jsx(i.Fragment,{children:s(e.access)}):i.jsxs(i.Fragment,{children:[t,i.jsxs("div",{className:"flex flex-col items-center gap-3 py-24 text-center",children:[i.jsx(FO,{className:"text-muted-foreground size-8","aria-hidden":!0}),i.jsx("h2",{className:"text-lg font-semibold",children:"Support needs a Maintain seat"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:e.access.seat?"You need read permission on this project to see its support issues; ask an organization admin.":"You need a Maintain seat to see this project's support issues; ask an organization admin."})]})]})}function WD(){const e=lt();return t=>{e.navigate?e.navigate(t):window.location.assign(e.href(t))}}const rs="all",Qd=25;function Wg({action:e}){return i.jsx(bn,{title:"Support",description:"Help-desk reports logged against this project.",actions:e})}function sG({org:e,project:t,query:n}){const s=VD(),a=UD(s),r=`/org/${e}/proj/${t}`;return i.jsx("div",{className:"flex w-full flex-1 flex-col gap-6 px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(BD,{access:a,header:i.jsx(Wg,{}),back_href:r,children:o=>s?i.jsx(iG,{contract:s,access:o,org_name:e,proj_name:t,query:n}):null})})}function iG({contract:e,access:t,org_name:n,proj_name:s,query:a}){const{href:r,Link:o}=lt(),l=WD(),[c,d]=u.useState(()=>new URLSearchParams(a).get("external_reference")??""),[h,f]=u.useState(rs),[m,p]=u.useState(rs),[y,g]=u.useState(rs),[b,v]=u.useState(0),[x,w]=u.useState(null),[_,S]=u.useState(0),[k,j]=u.useState(null),[N,O]=u.useState([]),[T,I]=u.useState(!1),L=c.trim()!==""||h!==rs||m!==rs||y!==rs,$=u.useCallback(async()=>{const C=await e.list({external_reference:c.trim()||void 0,status:h===rs?void 0:h,priority:m===rs?void 0:m,assignee:y===rs?void 0:y,limit:Qd,offset:b*Qd});if(!C.ok){j(C.refusal.message);return}j(null),w(C.data.issues),S(C.data.total)},[e,c,h,m,y,b]);u.useEffect(()=>{const C=setTimeout(()=>void $(),200);return()=>clearTimeout(C)},[$]),u.useEffect(()=>{e.assigneeCandidates().then(C=>{C.ok&&O(C.data.candidates)})},[e]);const A=t.can_change?i.jsxs(U,{onClick:()=>I(!0),children:[i.jsx(za,{className:"mr-2 size-4"}),"New issue"]}):void 0,D=i.jsx(eG,{create:e.create,open:T,onOpenChange:I,onCreated:(C,M)=>{I(!1);const H=Bg(n,s,C.id);l(M.length?`${H}?duplicates=${M.length}`:H)}});if(x!==null&&_===0&&!L&&b===0)return i.jsxs(i.Fragment,{children:[i.jsx(Wg,{}),i.jsxs("div",{className:"flex flex-col items-center gap-3 py-24 text-center",children:[i.jsx(GO,{className:"text-muted-foreground size-8","aria-hidden":!0}),i.jsx("h2",{className:"text-lg font-semibold",children:"No support issues yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Log a help-desk report under its ticket number, so every report is counted once."}),t.can_change?i.jsxs(U,{onClick:()=>I(!0),children:[i.jsx(za,{className:"mr-2 size-4"}),"Log the first issue"]}):null]}),D]});const E=_===0?0:b*Qd+1,R=Math.min(_,(b+1)*Qd);return i.jsxs(i.Fragment,{children:[i.jsx(Wg,{action:A}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsxs("div",{className:"relative w-full max-w-sm",children:[i.jsx(hz,{className:"text-muted-foreground pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2","aria-hidden":!0}),i.jsx(bt,{"aria-label":"Filter by external reference",placeholder:"Filter by external reference",className:"pl-9",value:c,onChange:C=>{d(C.target.value),v(0)}})]}),i.jsx(op,{label:"Status",value:h,onChange:C=>{f(C),v(0)},options:F3.map(C=>({value:C,label:Sh[C]}))}),i.jsx(op,{label:"Priority",value:m,onChange:C=>{p(C),v(0)},options:ub.map(C=>({value:C,label:Mc[C]}))}),i.jsx(op,{label:"Assignee",value:y,onChange:C=>{g(C),v(0)},options:[{value:"unassigned",label:"Unassigned"},{value:"cannot_act",label:"Assignee cannot act"},...N.map(C=>({value:C.user_id,label:C.username??"Not available"}))]})]}),k?i.jsx(Kn,{children:k}):null,i.jsx("div",{className:"rounded-md border",children:i.jsxs(nt,{children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Title"}),i.jsx(Q,{children:"External reference"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Priority"}),i.jsx(Q,{children:"Assignee"}),i.jsx(Q,{children:"Updated"})]})}),i.jsx(st,{children:x===null?i.jsx(_e,{children:i.jsx(X,{colSpan:6,className:"h-24 text-center",children:"Loading…"})}):x.length===0?i.jsx(_e,{children:i.jsx(X,{colSpan:6,className:"h-24 text-center",children:"No issues match these filters."})}):x.map(C=>i.jsxs(_e,{children:[i.jsx(X,{className:"max-w-md",children:i.jsx(o,{href:r(Bg(n,s,C.id)),className:"font-medium hover:underline",children:C.title})}),i.jsx(X,{className:"font-mono text-xs",children:C.external_reference??""}),i.jsx(X,{children:i.jsx(we,{variant:GD[C.status],children:Sh[C.status]})}),i.jsx(X,{children:C.priority?Mc[C.priority]:""}),i.jsx(X,{children:i.jsx(aG,{issue:C})}),i.jsx(X,{className:"text-muted-foreground",children:Au(C.updated_at)})]},C.id))})]})}),i.jsxs("div",{className:"flex items-center justify-between gap-2",children:[i.jsx("p",{className:"text-muted-foreground text-sm",children:_===0?"No issues.":`Showing ${E}–${R} of ${_} issue${_===1?"":"s"}.`}),i.jsxs("div",{className:"flex gap-2",children:[i.jsx(U,{variant:"outline",size:"sm",disabled:b===0,onClick:()=>v(C=>Math.max(0,C-1)),children:"Previous"}),i.jsx(U,{variant:"outline",size:"sm",disabled:R>=_,onClick:()=>v(C=>C+1),children:"Next"})]})]}),D]})}function aG({issue:e}){return e.assignee_id?i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{children:e.assignee_username??"Not available"}),e.assignee_can_act===!1?i.jsx(we,{variant:"error",children:"Assignee cannot act"}):null]}):i.jsx("span",{className:"text-muted-foreground",children:"Unassigned"})}function op({label:e,value:t,onChange:n,options:s}){var r;const a=u.useMemo(()=>t===rs||s.some(o=>o.value===t),[s,t]);return i.jsxs(St,{value:a?t:rs,onValueChange:n,children:[i.jsx(wt,{className:"w-44","aria-label":e,children:i.jsx(Ct,{placeholder:e,children:t===rs?e:(r=s.find(o=>o.value===t))==null?void 0:r.label})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:rs,children:"All"}),s.map(o=>i.jsx(Ue,{value:o.value,children:o.label},o.value))]})]})}function Wi(e,t){u.useEffect(()=>{const n=setInterval(()=>{document.visibilityState==="visible"&&e("tick")},t),s=()=>{document.visibilityState==="visible"&&e("shown")};return document.addEventListener("visibilitychange",s),()=>{clearInterval(n),document.removeEventListener("visibilitychange",s)}},[e,t])}const rG=5e3;function Ts(){const e=u.useRef(0),t=u.useRef(null);return u.useEffect(()=>()=>{t.current!==null&&clearTimeout(t.current)},[]),u.useMemo(()=>({owed:()=>e.current>0,busy:()=>e.current>0||t.current!==null,track:async n=>{e.current+=1;try{return await n}finally{e.current-=1,t.current!==null&&clearTimeout(t.current),t.current=setTimeout(()=>{t.current=null},rG)}}}),[])}function Uf(e,t){return n=>{(n==="shown"?e.owed():e.busy())||t()}}const FD=[{key:"local",label:"Local"},{key:"staging",label:"Staging"},{key:"production",label:"Production"}],oG=/^iss-\d{1,9}$/,lG=/^col-\d{1,9}$/,cG=e=>e&&e[0].toUpperCase()+e.slice(1);function qD(e){const t=cG(e.status_word??e.status.replace(/_/g," ")),n=e.group??(e.status==="resolved"?"resolved":"unplaced");return n==="resolved"?{label:t,tone:e.resolution_reason==="fixed"?"success":"neutral"}:n==="unowned"||n==="routed"?{label:t,tone:"warning"}:n==="fixing"?{label:t,tone:"info"}:{label:t,tone:"neutral"}}function lc(e,t=Date.now()){if(!e)return"";const n=Math.max(0,(t-Date.parse(e))/1e3);return Number.isFinite(n)?n<60?"just now":n<3600?`${Math.round(n/60)}m ago`:n<86400?`${Math.round(n/3600)}h ago`:`${Math.round(n/86400)}d ago`:""}const Fg={search:"",owner:null,urgent:!1,seen:[],label:null,collection:null};function Ru(e){const t=new URLSearchParams(e),n=t.getAll("seen").filter(a=>FD.some(r=>r.key===a)),s=t.get("collection");return{search:t.get("search")??"",owner:t.get("owner")||null,urgent:t.get("urgent")==="1",seen:[...new Set(n)],label:t.get("label")||null,collection:s&&lG.test(s)?s:null}}function mb(e){const t=new URLSearchParams;e.search&&t.set("search",e.search),e.owner&&t.set("owner",e.owner),e.urgent&&t.set("urgent","1");for(const n of e.seen)t.append("seen",n);return e.label&&t.set("label",e.label),e.collection&&t.set("collection",e.collection),t.toString()}const YD=new Set(["resolved"]),lp=10,dG=new Set(["unplaced","unowned","routed","fixing","resolved"]),uG=["open","fold","all"];function XD(e){const t=new URLSearchParams(e),n=s=>[...new Set(t.getAll(s).filter(a=>dG.has(a)))];return{open:n("open"),fold:n("fold"),all:n("all")}}const hG=(e,t)=>YD.has(t)?!e.open.includes(t):e.fold.includes(t);function fG(e,t,n){const s=e.open.filter(o=>o!==t),a=e.fold.filter(o=>o!==t),r=YD.has(t);return n&&!r&&a.push(t),!n&&r&&s.push(t),{...e,open:s,fold:a}}const mG=(e,t,n)=>({...e,all:n?[...e.all.filter(s=>s!==t),t]:e.all.filter(s=>s!==t)});function eo(e,t){const n=new URLSearchParams(mb(e));for(const s of uG)for(const a of t[s])n.append(s,a);return n.toString()}function pG(e){return{search:e.search.trim()||void 0,owner:e.owner??void 0,urgent:e.urgent||void 0,seen:e.seen.length?e.seen:void 0,label:e.label?[e.label]:void 0,collection:e.collection??void 0}}const n_=e=>!!(e.search.trim()||e.owner||e.urgent||e.seen.length||e.label||e.collection),gG={agent:"Filed by an agent",user:"Filed by you",tool:"Filed by a tool"},xG={graph:"Placed on the graph by its anchors",files:"Placed by its files",unplaced:"Triaged, not placed yet"},vG={handoff:"Handed to its owner",backlog:"Sent to the unowned backlog",batch:"Routed to a batch"};function bG(e,t=""){const n=(e??t).trim();if(!n)return"";const s=n.indexOf(": "),a=(s===-1?n:n.slice(0,s)).trim(),r=s===-1?"":n.slice(s+2).trim(),o=l=>r?`${l} ${r}`:l;switch(a){case"filed":return gG[r]??o("Filed by");case"labelled":return o("Labelled");case"unlabelled":return r?`Label removed: ${r}`:"Label removed";case"anchored":return r?`Anchored to ${r}`:"Anchored";case"triaged":return xG[r]??(r?`Triaged: ${r}`:"Triaged");case"routed":return vG[r]??(r?`Routed: ${r}`:"Routed");case"route closed":return r==="backlog"?"Taken off the unowned backlog":r?`Route closed: ${r}`:"Route closed";case"released":return r?`Released by its owner (task ${r})`:"Released by its owner";case"resolved":return r==="duplicate"?"Resolved as a duplicate":r?`Resolved · ${r.replace(/_/g," ")}`:"Resolved";case"reopened":return r?`Reopened: ${r}`:"Reopened";case"fix landed":return r?`Fix landed in ${r.slice(0,10)}`:"Fix landed";case"merged":return r?`Merged ${r} into this issue`:"Merged a duplicate into this issue";default:return n}}const yG=e=>e.replace(/`+/g,"").replace(/\s+/g," ").trim(),s_={report:{title:"Triage places what you report",body:"Report an issue here and triage places it and suggests an owner. Route and resolve issues with the issue command or through the thread working on them."},read_only:{title:"This page only reads issues",body:"File, route and resolve issues with the issue command or through the thread working on them."}},i_={title:"This page only reads issues",body:"Route and resolve issues with the issue command or through the thread working on them."},wG=e=>e?"Issues you report here, or file with the issue command, appear here.":"Issues filed in this repository with the issue command appear here.";function KD(e){const t=new Set;for(const n of e.split(",")){const s=n.trim().toLowerCase().replace(/[\s_]+/g,"-");s&&t.add(s)}return[...t]}const _G=/^[a-z0-9]+(?:-[a-z0-9]+)*$/,a_=40,qg=10,r_=40,jG=200,cp="not_set",ZD=[{value:"not_set",label:"Not set"},{value:"local",label:"Local"},{value:"staging",label:"Staging"},{value:"production",label:"Production"}],Ln={title:"Report an issue",description:"Triage places it and suggests an owner; you'll see where it went.",needs_what:"Say what is wrong to report it.",refused:"The issue was not reported",kept:"Your draft is kept: report it again.",maybe_filed:"The report may have been filed",timeout:"The issue command did not answer within 1 minute, so the report may have been filed. Look for it in the list before you report it again.",failed:"The issue command failed, so the report may have been filed. Look for it in the list before you report it again; the sdlc viewer terminal says what failed.",kept_only:"Your draft is kept.",too_long:"The report is too long to send; shorten What happens or What should happen.",no_answer:"The viewer did not answer.",reporting:"Reporting…"},po={what:"",actual:"",expected:"",env:"not_set",shows:"",collection:"",ref:"",labels:""},Yg=e=>`sdlc.issue-report-draft:${e}`;function NG(e){try{const t=JSON.parse(window.sessionStorage.getItem(Yg(e))??"null");if(!t||typeof t!="object")return po;const n={...po};for(const s of Object.keys(po))typeof t[s]=="string"&&(n[s]=t[s]);return ZD.some(s=>s.value===n.env)||(n.env="not_set"),n}catch{return po}}function dp(e,t){try{t?window.sessionStorage.setItem(Yg(e),JSON.stringify(t)):window.sessionStorage.removeItem(Yg(e))}catch{}}function kG(e){const t=KD(e);if(t.length>qg)return`At most ${qg} labels; this has ${t.length}.`;const n=t.find(s=>!_G.test(s)||s.length>a_);return n?`'${n}' is not a label: use a-z, 0-9 and single hyphens, at most ${a_} characters.`:null}function SG(e){return e.status===504||e.code==="timeout"?Ln.timeout:e.status===500?Ln.failed:e.status===413?Ln.too_long:[400,422].includes(e.status)&&e.message?e.message:Ln.no_answer}function up(e){return e===Ln.timeout||e===Ln.failed}function CG(e){const t={what:e.what.trim()};e.actual.trim()&&(t.actual=e.actual),e.expected.trim()&&(t.expected=e.expected),e.env!=="not_set"&&(t.env=e.env),e.shows.trim()&&(t.shows=e.shows.trim()),e.collection&&(t.collection=e.collection,e.ref.trim()&&(t.ref=e.ref.trim()));const n=KD(e.labels);return n.length&&(t.labels=n.join(",")),t}function DG({project:e,report:t,reportCollections:n,open:s,onOpenChange:a,onFiled:r,onMaybeFiled:o}){const[l,c]=u.useState(po),[d,h]=u.useState(null),[f,m]=u.useState(!1),[p,y]=u.useState(null),[g,b]=u.useState(null),v=u.useRef(null),x=u.useRef(null),w=u.useRef(null),_=u.useRef(!1),S=u.useId(),k=A=>`${S}-report-${A}`;u.useEffect(()=>{if(!s||(c(NG(e)),y(null),b(null),h(null),!n))return;let A=!0;return n().then(D=>{A&&h(D.ok?D.data.collections:[])}),()=>{A=!1}},[s,e,n]);const j=A=>c(D=>{const E={...D,...A};return dp(e,E),E}),N=u.useMemo(()=>{const A=d??[];return l.collection&&!A.some(D=>D.collection===l.collection)?[...A,{collection:l.collection,title:l.collection}]:A},[d,l.collection]),O=N.length>0,T=A=>{f||(A&&dp(e,null),a(!1))},I=async A=>{var R,C;if(A.preventDefault(),_.current)return;if(!l.what.trim()){(R=v.current)==null||R.focus();return}const D=kG(l.labels);if(b(D),D){(C=x.current)==null||C.focus();return}_.current=!0,m(!0),y(null);const E=await t(CG(l));if(_.current=!1,m(!1),!E.ok){const M=SG(E.refusal);y(M),up(M)&&(o==null||o());return}dp(e,null),c(po),a(!1),r(E.data)};u.useEffect(()=>{var A,D,E;p&&((D=(A=w.current)==null?void 0:A.scrollIntoView)==null||D.call(A,{block:"nearest"}),(E=v.current)==null||E.focus())},[p]);const L=!l.what.trim(),$=[k("what-help"),p?k("refused"):null].filter(Boolean).join(" ");return i.jsx(yn,{open:s,onOpenChange:A=>A?a(!0):T(!1),children:i.jsx(wn,{className:"max-h-[90vh] overflow-y-auto sm:max-w-2xl",onOpenAutoFocus:A=>{var D;A.preventDefault(),(D=v.current)==null||D.focus()},children:i.jsxs("form",{onSubmit:I,className:"grid gap-4",noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:Ln.title}),i.jsx(kn,{children:Ln.description})]}),p?i.jsxs(pe,{ref:w,variant:"destructive",id:k("refused"),children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:up(p)?Ln.maybe_filed:Ln.refused}),i.jsxs(ge,{children:[/[.!?]$/.test(p)?p:`${p}.`," ",up(p)?Ln.kept_only:Ln.kept]})]}):null,i.jsxs("fieldset",{disabled:f,className:"grid min-w-0 gap-4",children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsxs(Ie,{htmlFor:k("what"),children:["What is wrong ",i.jsx("span",{"aria-hidden":"true",children:"*"})]}),i.jsx(bt,{id:k("what"),ref:v,"aria-required":"true",maxLength:jG,placeholder:"One line: what you saw",value:l.what,"aria-describedby":$,onChange:A=>j({what:A.target.value})}),i.jsx("p",{id:k("what-help"),className:"text-muted-foreground text-xs",children:"It becomes the issue's title."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("actual"),children:"What happens"}),i.jsx(Gn,{id:k("actual"),rows:3,placeholder:"What you see, step by step",value:l.actual,onChange:A=>j({actual:A.target.value})})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("expected"),children:"What should happen"}),i.jsx(Gn,{id:k("expected"),rows:3,placeholder:"What you expected instead",value:l.expected,onChange:A=>j({expected:A.target.value})})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("env"),children:"Where you saw it"}),i.jsxs(St,{value:l.env,disabled:f,onValueChange:A=>j({env:A}),children:[i.jsx(wt,{id:k("env"),children:i.jsx(Ct,{})}),i.jsx(_t,{children:ZD.map(A=>i.jsx(Ue,{value:A.value,children:A.label},A.value))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("shows"),children:"Shows in"}),i.jsx(bt,{id:k("shows"),placeholder:"packages/app/page.tsx or Report button",value:l.shows,"aria-describedby":k("shows-help"),onChange:A=>j({shows:A.target.value})}),i.jsx("p",{id:k("shows-help"),className:"text-muted-foreground text-xs",children:"A file path in this repository, or the words you saw on the screen."})]}),O?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("collection"),children:"Collection"}),i.jsxs(St,{value:l.collection||cp,disabled:f,onValueChange:A=>j({collection:A===cp?"":A}),children:[i.jsx(wt,{id:k("collection"),children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:cp,children:"Not set"}),N.map(A=>i.jsx(Ue,{value:A.collection,children:A.title===A.collection?A.collection:`${A.title} (${A.collection})`},A.collection))]})]})]}):null,O&&l.collection?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("ref"),children:"Place in the collection"}),i.jsx(bt,{id:k("ref"),maxLength:r_,placeholder:"Like item 5",value:l.ref,"aria-describedby":k("ref-help"),onChange:A=>j({ref:A.target.value})}),i.jsxs("p",{id:k("ref-help"),className:"text-muted-foreground text-xs",children:["At most ",r_," characters."]})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:k("labels"),children:"Labels"}),i.jsx(bt,{id:k("labels"),ref:x,placeholder:"viewer, report form",value:l.labels,"aria-invalid":g?!0:void 0,"aria-describedby":k(g?"labels-error":"labels-help"),onChange:A=>{j({labels:A.target.value}),g&&b(null)}}),g?i.jsx("div",{id:k("labels-error"),children:i.jsx(Kn,{children:g})}):i.jsxs("p",{id:k("labels-help"),className:"text-muted-foreground text-xs",children:["Up to ",qg," words to find it by, separated by commas."]})]})]}),i.jsx("p",{id:k("needs-what"),className:"sr-only",children:Ln.needs_what}),i.jsx("div",{role:"status","aria-live":"polite",className:"sr-only",children:f?Ln.reporting:""}),i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",disabled:f,onClick:()=>T(!0),children:"Cancel"}),i.jsx(U,{type:"submit",loading:f,"aria-disabled":L?!0:void 0,"aria-describedby":k("needs-what"),children:f?Ln.reporting:"Report"})]})]})})})}function EG(e,t){const n=new URLSearchParams(e).get("reported");return n&&(n===`Seen before: added to ${t}`||n.startsWith(`Filed ${t} · `)&&n.length<=200&&!/[\n\r]/.test(n))?n:null}const AG=10,QD=1e4,RG=250,Wr="__all",TG="none",OG=e=>e.status===0||e.reason==="store_locked"||e.reason==="engine_failed"||e.status>=500;function JD(){const e=Vn().issues;if(!e)throw new Error("The Issues page rendered without the issues seam.");return e}const zG=e=>({read_at:e,scope:"project",folder:null,groups:[],facets:{owners:[],labels:[],urgent:0,seen:{local:0,staging:0,production:0}},listed:0,collections:[]});function MG({org:e,project:t,query:n,onQuery:s}){var $e,ze;const a=JD(),r=($e=a.commands)==null?void 0:$e.open_thread,o=u.useMemo(()=>r?{org:e,open_thread:r}:void 0,[e,r]),{href:l,Link:c}=lt(),d=WD(),[h,f]=u.useState(!1),m=u.useMemo(()=>Ru(n),[n]),p=u.useMemo(()=>XD(n),[n]),y=mb(m),g=n_(m),b=eo(m,p),[v,x]=u.useState({state:"loading"}),[w,_]=u.useState(null),[S,k]=u.useState(null),j=u.useRef(0),N=u.useRef(0),O=u.useRef(null),T=u.useRef(null),I=ns(),L=u.useRef(!1),[$,A]=u.useState(m.search),D=u.useCallback(q=>s(eo({...m,...q},p)),[m,p,s]),E=u.useCallback(q=>s(eo(m,q)),[m,s]),R=Ts(),C=u.useCallback(async()=>{const q=N.current+=1;k(null);const ve=await R.track(a.list(pG(Ru(y))));if(q!==N.current)return;if(ve.ok){j.current=0,_(null),x({state:"ok",list:ve.data,local:ve.data.local??zG(new Date().toISOString()),key:y});return}const Ve=ve.refusal.reason;if(Ve==="engine_missing")return x({state:"engine_missing",refusal:ve.refusal});if(Ve==="view_outdated")return x({state:"view_outdated"});if(j.current+=1,j.current===1&&OG(ve.refusal)){k(ve.refusal.retry_after??AG);return}_(ve.refusal)},[a.list,y,R]);u.useEffect(()=>{C()},[C]);const M=u.useMemo(()=>Uf(R,()=>void C()),[C,R]);Wi(M,QD),u.useEffect(()=>{if(S===null)return;const q=setTimeout(()=>{document.visibilityState==="visible"&&C()},S*1e3);return()=>clearTimeout(q)},[S,C]),u.useEffect(()=>{document.activeElement!==O.current&&A(m.search)},[m.search]),u.useEffect(()=>{if($===m.search)return;const q=setTimeout(()=>D({search:$}),RG);return()=>clearTimeout(q)},[$,m.search,D]),u.useEffect(()=>{const q=ve=>{if(ve.key!=="/"||ve.metaKey||ve.ctrlKey||ve.altKey)return;const Ve=ve.target;Ve&&(Ve.isContentEditable||["INPUT","TEXTAREA","SELECT"].includes(Ve.tagName))||O.current&&(ve.preventDefault(),O.current.focus())};return window.addEventListener("keydown",q),()=>window.removeEventListener("keydown",q)},[]);const H=()=>{var q;A(""),s(eo(Fg,p)),(q=O.current)==null||q.focus()},z=()=>{j.current=0,C()},K=()=>{L.current=!0,z()};u.useEffect(()=>{var ve;if(!L.current||v.state==="loading"||S!==null)return;L.current=!1;const q=(ve=T.current)==null?void 0:ve.querySelector("h1");q&&(q.tabIndex=-1,q.focus())},[v,w,S]);const oe=cb(T),re=q=>`/proj/${encodeURIComponent(t)}/issues${q?`?${q}`:""}`,Ne=q=>`/proj/${encodeURIComponent(t)}/issues/${encodeURIComponent(q)}?from=issues${b?`&${b}`:""}`,Se=i.jsx("div",{role:"status","aria-live":"polite",children:S!==null?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"Issues are busy. Reading them again…"]}):null}),ae=w?i.jsxs(pe,{ref:oe,variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Issues could not be loaded"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[w.message,w.since?` Since ${As(w.since)}.`:"",v.state==="ok"?` The list below was read at ${As(v.local.read_at)}.`:"",w.message.includes(vr)?"":` ${vr}`]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:K,children:"Retry"})]})]}):null,F=!!a.report,ie=F?s_.report:s_.read_only,W=i.jsx(bn,{title:"Issues",description:"This repository's local issues: what agents and you reported, where triage placed each, and what fixes it.",actions:v.state==="ok"?i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsxs("span",{className:"text-muted-foreground text-sm",children:["Read at ",As(v.local.read_at)]}),i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:z,children:[i.jsx(Er,{className:"mr-2 size-4","aria-hidden":"true"}),"Read again"]}),F?i.jsxs(U,{type:"button",size:"sm",onClick:()=>f(!0),children:[i.jsx(za,{className:"mr-2 size-4","aria-hidden":"true"}),"Report an issue"]}):null]}):null}),se=a.report?i.jsx(DG,{project:t,report:a.report,reportCollections:a.reportCollections,open:h,onOpenChange:f,onMaybeFiled:z,onFiled:q=>{z(),d(`/proj/${encodeURIComponent(t)}/issues/${encodeURIComponent(q.issue)}?${new URLSearchParams({from:"issues",reported:q.note}).toString()}`)}}):null;if(v.state==="engine_missing")return i.jsx(Jd,{ref:T,children:i.jsx(yi,{page:"Issues"})});if(v.state==="view_outdated")return i.jsxs(Jd,{ref:T,children:[W,i.jsxs(pe,{variant:"warning",className:"mt-6",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:I})]})]});if(v.state==="loading")return i.jsxs(Jd,{ref:T,children:[W,Se,ae,!w&&S===null?i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading issues",children:Array.from({length:6},(q,ve)=>i.jsx(Tt,{className:ve===5?"h-10 w-2/3":"h-10 w-full"},ve))}):null]});const{list:Z,local:de}=v,J=!w&&S===null&&(v.key!==y||$!==m.search),G=n_(Ru(v.key)),Y=de.scope==="folder",te=de.listed===0&&!g,ce=Math.max(0,de.listed-de.facets.owners.reduce((q,ve)=>q+ve.count,0)),be=m.collection?((ze=de.collections.find(q=>q.collection===m.collection))==null?void 0:ze.title)??m.collection:null,fe=new Map;for(const q of Z.issues){const ve=q.group??"unplaced";fe.set(ve,[...fe.get(ve)??[],q])}return i.jsxs(Jd,{ref:T,children:[W,Y&&de.folder?i.jsxs("p",{className:"text-muted-foreground mt-1 text-sm",children:["Issues of the folder ",de.folder,", from its issue store."]}):null,se,i.jsxs(pe,{variant:"info",className:"mt-4",children:[F?i.jsx(fn,{className:"size-4","aria-hidden":"true"}):i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:ie.title}),i.jsx(ge,{children:ie.body})]}),Se,ae,te?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(MO,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No issues yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:wG(F)})]}):i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"mt-6 flex flex-wrap items-center gap-3",children:[i.jsx(bt,{ref:O,type:"search",className:"w-64","aria-label":"Search issues",placeholder:"Search issues",value:$,onChange:q=>A(q.target.value)}),i.jsxs(St,{value:m.owner??Wr,onValueChange:q=>D({owner:q===Wr?null:q}),children:[i.jsx(wt,{className:"w-56","aria-label":"Owner",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Wr,children:"All owners"}),i.jsxs(Ue,{value:TG,children:["Unowned (",ce,")"]}),de.facets.owners.map(q=>i.jsxs(Ue,{value:q.key,children:[q.title," (",q.count,")"]},q.key))]})]}),i.jsxs(St,{value:m.label??Wr,onValueChange:q=>D({label:q===Wr?null:q}),children:[i.jsx(wt,{className:"w-48","aria-label":"Label",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Wr,children:"All labels"}),de.facets.labels.map(q=>i.jsxs(Ue,{value:q.label,children:[q.label," (",q.count,")"]},q.label))]})]})]}),i.jsxs("div",{className:"mt-3 flex flex-wrap items-center gap-x-4 gap-y-2",children:[i.jsx("div",{className:"flex flex-wrap items-center gap-2",role:"group","aria-label":"Marks",children:i.jsx(o_,{pressed:m.urgent,count:de.facets.urgent,onClick:()=>D({urgent:!m.urgent}),children:"Urgent"})}),i.jsxs("div",{className:"flex flex-wrap items-center gap-2",role:"group","aria-label":"Seen on",children:[i.jsx("span",{className:"text-muted-foreground text-xs",children:"Seen on"}),FD.map(q=>{const ve=m.seen.includes(q.key);return i.jsx(o_,{pressed:ve,count:de.facets.seen[q.key],onClick:()=>D({seen:ve?m.seen.filter(Ve=>Ve!==q.key):[...m.seen,q.key]}),children:q.label},q.key)}),be!==null?i.jsxs("span",{className:"inline-flex items-center gap-1",children:[i.jsxs("span",{"data-testid":"issues-collection-chip",className:je(vf({variant:"outline",size:"sm"}),Z$),children:["Collection ",be]}),i.jsx(U,{type:"button",variant:"ghost",size:"sm-icon","aria-label":"Remove the collection filter",onClick:()=>{var q;D({collection:null}),(q=O.current)==null||q.focus()},children:i.jsx(dd,{className:"size-4","aria-hidden":"true"})})]}):null]})]}),i.jsx("div",{role:"status","aria-live":"polite",children:J?i.jsxs("p",{className:"text-muted-foreground mt-3 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"Searching…"]}):g&&Z.total>0?i.jsxs("p",{className:"text-muted-foreground mt-3 text-sm",children:[Z.total," of ",de.listed," issues ·"," ",i.jsx(U,{type:"button",variant:"link",size:"sm",className:"px-0",onClick:H,children:"Clear"})]}):null}),i.jsx("div",{"data-testid":"issues-results","aria-busy":J||void 0,className:"shrink-0 transition-opacity aria-busy:opacity-50",children:G&&Z.total===0?i.jsxs("p",{className:"mt-6 flex items-center gap-2 text-sm",children:[i.jsx(uf,{className:"text-muted-foreground size-4","aria-hidden":"true"}),"No issues match."," ",i.jsx(U,{type:"button",variant:"link",size:"sm",className:"px-0",onClick:H,children:"Clear"})]}):i.jsxs(i.Fragment,{children:[!G&&de.groups.length>0&&de.groups.every(q=>q.key==="resolved")?i.jsx("p",{className:"text-muted-foreground mt-6 text-sm","data-testid":"issues-none-open",children:"No open issues."}):null,de.groups.map(q=>i.jsx(LG,{id:`issues-${q.key}`,title:`${q.label} · ${q.count}`,issues:fe.get(q.key)??[],folder:Y,threads:o,fold:G?void 0:{folded:hG(p,q.key),whole:p.all.includes(q.key),onFold:ve=>E(fG(p,q.key,ve)),onWhole:ve=>E(mG(p,q.key,ve))},link:ve=>i.jsx(c,{className:"text-primary hover:underline",href:l(Ne(ve.id)),children:ve.title})},q.key))]})}),!g&&de.collections.length>0?i.jsxs("section",{className:"mt-8","aria-labelledby":"issues-collections-title",children:[i.jsxs("h2",{id:"issues-collections-title",className:"text-lg font-semibold",children:["Collections · ",de.collections.length]}),i.jsx(yt,{className:"mt-2 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Collections",className:"table-fixed",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{className:"w-1/2",children:"Collection"}),i.jsx(Q,{className:"w-1/4",children:"Resolved"}),i.jsx(Q,{className:"w-1/4",children:"Updated"})]})}),i.jsx(st,{children:de.collections.map(q=>i.jsxs(_e,{children:[i.jsxs(X,{children:[i.jsx(c,{className:"text-primary hover:underline",href:l(re(eo({...Fg,collection:q.collection},p))),children:q.title}),i.jsx("div",{className:"text-muted-foreground font-mono text-xs",children:q.collection})]}),i.jsxs(X,{children:[q.resolved," of ",q.total," resolved"]}),i.jsx(X,{className:"text-muted-foreground",children:lc(q.updated_at)})]},q.collection))})]})})]}):null]})]})}const Jd=u.forwardRef(function({children:t},n){return i.jsx("div",{ref:n,className:"flex h-full min-h-0 flex-1 flex-col overflow-auto px-4 py-4 pb-8 sm:px-6 lg:px-8",children:t})}),$G={plain:{title:"w-[36%]",issue:"w-[10%]",project:"",status:"w-[16%]",urgent:"w-[8%]",owner:"w-[18%]",updated:"w-[12%]"},folder:{title:"w-[30%]",issue:"w-[10%]",project:"w-[12%]",status:"w-[16%]",urgent:"w-[8%]",owner:"w-[14%]",updated:"w-[12%]"},actions:{title:"w-[30%]",issue:"w-[9%]",project:"",status:"w-[14%]",urgent:"w-[7%]",owner:"w-[16%]",updated:"w-[10%]"},folderActions:{title:"w-[26%]",issue:"w-[8%]",project:"w-[11%]",status:"w-[13%]",urgent:"w-[7%]",owner:"w-[12%]",updated:"w-[9%]"}};function o_({pressed:e,count:t,onClick:n,children:s}){const[a,r]=u.useState(!1);return i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:rc,"aria-pressed":e,disabled:t===0&&!e&&!a,onFocus:()=>r(!0),onBlur:()=>r(!1),onClick:n,children:[s," ",t]})}function LG({id:e,title:t,issues:n,folder:s,link:a,threads:r,fold:o}){const l=$G[r?s?"folderActions":"actions":s?"folder":"plain"],c=6+(s?1:0)+(r?1:0),d=`${e}-panel`,h=!(o!=null&&o.folded),f=o!==void 0&&!o.whole&&n.length>lp,m=f?n.slice(0,lp):n,p=h?rf:ld,[y,g]=u.useState(!1),b=o!==void 0&&(f||o.whole&&n.length>lp||y);return i.jsxs("section",{className:"mt-6","aria-labelledby":`${e}-title`,"data-testid":"issues-group",children:[i.jsx("h2",{id:`${e}-title`,className:"text-lg font-semibold",children:o?i.jsxs(U,{type:"button",variant:"ghost",size:"sm",className:"-ml-2 text-lg font-semibold","aria-expanded":h,"aria-controls":h?d:void 0,onClick:()=>o.onFold(h),children:[i.jsx(p,{className:"size-4","aria-hidden":"true"}),t]}):t}),h?i.jsxs("div",{id:d,children:[i.jsx(PG,{title:t,issues:m,folder:s,link:a,threads:r,widths:l,columns:c}),o&&b?i.jsx(U,{type:"button",variant:"link",size:"sm",className:"mt-1 px-0","aria-expanded":o.whole,"aria-describedby":`${e}-title`,onFocus:()=>g(!0),onBlur:()=>g(!1),onClick:()=>o.onWhole(!o.whole),children:o.whole?"Show fewer":`Show all ${n.length}`}):null]}):null]})}function PG({title:e,issues:t,folder:n,link:s,threads:a,widths:r,columns:o}){return i.jsx(i.Fragment,{children:i.jsx(yt,{className:"mt-2 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:e,className:je("table-fixed",a&&"min-w-5xl"),children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{className:r.title,children:"Title"}),i.jsx(Q,{className:r.issue,children:"Issue"}),n?i.jsx(Q,{className:r.project,children:"Project"}):null,i.jsx(Q,{className:r.status,children:"Status"}),i.jsx(Q,{className:r.urgent,children:"Urgent"}),i.jsx(Q,{className:r.owner,children:"Owner"}),i.jsx(Q,{className:r.updated,children:"Updated"}),a?i.jsx(Q,{className:"w-[14%] text-right",children:"Actions"}):null]})}),i.jsx(st,{children:t.map(l=>i.jsx(IG,{issue:l,folder:n,link:s,threads:a,columns:o},l.id))})]})})})}function IG({issue:e,folder:t,link:n,threads:s,columns:a}){var d;const{button:r,panel:o}=Vf({org:(s==null?void 0:s.org)??"",action:s?e.local_action:void 0,task_id:null,issue:e.id,open_thread:s==null?void 0:s.open_thread}),l=qD(e),c=[e.reported_by_you?"you reported":"",e.standing??""].filter(Boolean).join(" · ");return i.jsxs(i.Fragment,{children:[i.jsxs(_e,{"data-testid":"issues-row",className:o?"border-b-0":void 0,children:[i.jsxs(X,{className:"break-words",children:[n(e),c?i.jsx("div",{"data-testid":"issues-row-standing",className:"text-muted-foreground mt-0.5 text-xs",children:c}):null,(d=e.labels)!=null&&d.length?i.jsx("div",{className:"mt-1 flex flex-wrap gap-1",children:e.labels.map(h=>i.jsx(we,{variant:"neutral",size:"dense",children:h},h))}):null]}),i.jsx(X,{className:"font-mono text-xs",children:e.id}),t?i.jsx(X,{className:"break-words",children:e.project_id??"Folder"}):null,i.jsx(X,{children:i.jsx(we,{variant:l.tone,children:l.label})}),i.jsx(X,{children:e.urgent&&e.status!=="resolved"&&e.group!=="resolved"?i.jsx(we,{variant:"warning",children:"Urgent"}):null}),i.jsx(X,{className:"break-words",children:e.owner_title?e.owner_title:i.jsx("span",{className:"text-muted-foreground",children:"Unowned"})}),i.jsx(X,{className:"text-muted-foreground",children:lc(e.updated_at)}),s?i.jsx(X,{className:"text-right whitespace-nowrap",children:r}):null]}),o?i.jsx(_e,{"data-testid":"issues-row-panel",className:"hover:bg-transparent",children:i.jsx(X,{colSpan:a,className:"pt-0",children:i.jsx("div",{className:"max-w-180 pl-4 text-left whitespace-normal",children:o})})}):null]})}function GG(e){var t;return(t=Vn().issues)!=null&&t.issueSections?i.jsx(MG,{...e}):i.jsx(sG,{org:e.org,project:e.project,query:e.query})}function HG({update:e,issue:t,open:n,onOpenChange:s,onDone:a,onReload:r}){const[o,l]=u.useState(t.title),[c,d]=u.useState(t.description),[h,f]=u.useState(t.external_reference??""),[m,p]=u.useState(t),[y,g]=u.useState(null),[b,v]=u.useState(!1);u.useEffect(()=>{n&&(l(t.title),d(t.description),f(t.external_reference??""),p(t),g(null))},[n]);const x=S=>{var k;return((k=y==null?void 0:y.personal_data)==null?void 0:k.field)===S?y.message:void 0},w=async S=>{S.preventDefault(),v(!0);const k=await e(m.id,m.revision,{title:o,description:c,external_reference:h.trim()||null});if(v(!1),!k.ok){g(k.refusal);return}a(k.data.issue)},_=async()=>{const S=await r();S&&(p(S),g(null))};return i.jsx(yn,{open:n,onOpenChange:s,children:i.jsx(wn,{className:"sm:max-w-2xl",children:i.jsxs("form",{onSubmit:w,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Edit issue"}),i.jsx(kn,{children:"Text is shown exactly as entered."})]}),y!=null&&y.conflict?i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{}),i.jsx(ge,{children:"Someone else saved this issue after you opened it, so nothing was saved. Your text is kept below; reload the latest issue, then save to apply it."})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-edit-title",children:"Title"}),i.jsx(bt,{id:"maintain-edit-title",value:o,"aria-invalid":!!x("title"),onChange:S=>l(S.target.value)}),x("title")?i.jsx(Kn,{children:x("title")}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-edit-description",children:"Description"}),i.jsx(Gn,{id:"maintain-edit-description",rows:4,value:c,"aria-invalid":!!x("description"),onChange:S=>d(S.target.value)}),x("description")?i.jsx(Kn,{children:x("description")}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-edit-reference",children:"External reference"}),i.jsx(bt,{id:"maintain-edit-reference",value:h,"aria-invalid":!!x("external_reference"),onChange:S=>f(S.target.value)}),x("external_reference")?i.jsx(Kn,{children:x("external_reference")}):null]}),y&&!y.conflict&&!y.personal_data?i.jsx(Kn,{children:y.message}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),y!=null&&y.conflict?i.jsxs(U,{type:"button",variant:"outline",onClick:_,children:[i.jsx(Er,{className:"mr-2 size-4"}),"Reload latest"]}):null,i.jsx(U,{type:"submit",loading:b,disabled:!!(y!=null&&y.conflict),children:"Save"})]})]})})})}function l_(e){return e.map(t=>HD[t].toLowerCase()).join(", ")}function VG(e){switch(e.kind){case"created":return"Logged the issue";case"updated":return`Edited the ${l_(e.fields)}`;case"redacted":return`Redacted the ${l_(e.fields)}`;case"priority_set":return e.priority?`Set priority to ${Mc[e.priority]}`:"Cleared the priority";case"assigned":return`Assigned to ${e.assignee_id?e.assignee_username??"someone whose name is not available":"a former member"}`;case"unassigned":return"Unassigned the issue";case"transitioned":{if(e.from_status==="resolved"&&e.to_status==="open")return"Reopened the issue";const t=e.to_status?Sh[e.to_status]:"";return e.resolution_reason?`Moved to ${t}: ${hb[e.resolution_reason]}`:`Moved to ${t}`}}}function c_(e,t){return t==="external_reference"?e.external_reference??"":e[t]}function UG({redact:e,issue:t,open:n,onOpenChange:s,onDone:a,onReload:r}){const[o,l]=u.useState("description"),[c,d]=u.useState(""),[h,f]=u.useState(!1),[m,p]=u.useState(null),[y,g]=u.useState(t);u.useEffect(()=>{n&&(g(t),d(c_(t,o)),p(null))},[n]);const b=async v=>{v.preventDefault(),f(!0);const x=await e(y.id,y.revision,o,c);if(f(!1),!x.ok){if(x.refusal.conflict){const w=await r();w&&g(w),p("Someone else saved this issue after you opened it. The latest issue is loaded and your replacement is kept; redact again to apply it.");return}p(x.refusal.message);return}a(x.data.issue)};return i.jsx(yn,{open:n,onOpenChange:s,children:i.jsx(wn,{className:"sm:max-w-2xl",children:i.jsxs("form",{onSubmit:b,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Redact text"}),i.jsx(kn,{children:"Replace text that holds personal data, such as a name."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-redact-field",children:"Field"}),i.jsxs(St,{value:o,onValueChange:v=>{const x=v;l(x),d(c_(y,x))},children:[i.jsx(wt,{id:"maintain-redact-field",children:i.jsx(Ct,{})}),i.jsx(_t,{children:Y3.map(v=>i.jsx(Ue,{value:v,children:HD[v]},v))})]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-redact-replacement",children:"Replacement text"}),i.jsx(Gn,{id:"maintain-redact-replacement",rows:4,value:c,onChange:v=>d(v.target.value)})]}),i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{}),i.jsx(ge,{children:"This cannot be undone: the original text is removed for good. History records only that this field was redacted."})]}),m?i.jsx(Kn,{children:m}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),i.jsx(U,{type:"submit",variant:"destructive",loading:h,children:"Redact"})]})]})})})}function BG({transition:e,issue:t,open:n,onOpenChange:s,onDone:a}){const[r,o]=u.useState("fixed"),[l,c]=u.useState(!1),[d,h]=u.useState(null),f=async m=>{m.preventDefault(),c(!0);const p=await e(t.id,t.revision,"resolved",r);if(c(!1),!p.ok){if(p.refusal.conflict){a(null);return}h(p.refusal.message);return}h(null),a(p.data.issue)};return i.jsx(yn,{open:n,onOpenChange:s,children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:f,className:"grid gap-4",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Resolve issue"}),i.jsx(kn,{children:"Choose how this report ended."})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"maintain-resolution-reason",children:"Resolution reason *"}),i.jsxs(St,{value:r,onValueChange:m=>o(m),children:[i.jsx(wt,{id:"maintain-resolution-reason",children:i.jsx(Ct,{})}),i.jsx(_t,{children:q3.map(m=>i.jsx(Ue,{value:m,children:hb[m]},m))})]}),i.jsx("p",{className:"text-muted-foreground text-xs",children:"Reopening the issue clears its reason."})]}),d?i.jsx(Kn,{children:d}):null,i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:()=>s(!1),children:"Cancel"}),i.jsx(U,{type:"submit",loading:l,children:"Resolve"})]})]})})})}const Fr="not_set";function WG({org:e,project:t,issue_id:n,query:s}){const a=VD(),r=UD(a),o=Bg(e,t);return i.jsx("div",{className:"flex w-full flex-1 flex-col gap-6 px-4 py-4 sm:px-6 lg:px-8",children:i.jsx(BD,{access:r,header:i.jsx(bn,{title:"Support"}),back_href:o,children:l=>a?i.jsx(FG,{contract:a,issue_id:n,access:l,list_href:o,duplicates:Number(new URLSearchParams(s).get("duplicates")??0)}):null})})}function FG({contract:e,issue_id:t,access:n,list_href:s,duplicates:a}){const{href:r,Link:o}=lt(),l=Ga(),[c,d]=u.useState(null),[h,f]=u.useState([]),[m,p]=u.useState(!1),[y,g]=u.useState([]),[b,v]=u.useState(null),x=u.useCallback(async()=>{const j=await e.issue(t);return j.ok?(d(j.data.issue),f(j.data.events),j.data.issue):(j.refusal.status===404?p(!0):l.error(j.refusal.message),null)},[e,t,l]);u.useEffect(()=>{let j=!1;return e.issue(t).then(N=>{if(!j){if(!N.ok){N.refusal.status===404?p(!0):l.error(N.refusal.message);return}d(N.data.issue),f(N.data.events)}}),()=>{j=!0}},[e,t]),u.useEffect(()=>{n.can_change&&e.assigneeCandidates().then(j=>{j.ok&&g(j.data.candidates)})},[e,n.can_change]);const w=async j=>{const N=await j;if(!N.ok){l.error(N.refusal.message),N.refusal.conflict&&await x();return}await x()};if(m)return i.jsx(Ha,{title:"Support issue not found",description:"This issue does not exist in this project.",backHref:r(s),backLabel:"Back to Support",link:o});if(!c)return i.jsx("p",{className:"text-muted-foreground text-sm",children:"Loading…"});const _=c.status==="closed",S=n.can_change,k=j=>w(e.transition(c.id,c.revision,j));return i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:c.title,actions:S?i.jsxs(i.Fragment,{children:[_?null:i.jsxs(U,{variant:"outline",onClick:()=>v("edit"),children:[i.jsx(df,{className:"mr-2 size-4"}),"Edit"]}),i.jsxs(U,{variant:"outline",onClick:()=>v("redact"),children:[i.jsx(yO,{className:"mr-2 size-4"}),"Redact"]}),c.status==="open"?i.jsx(U,{variant:"outline",disabled:!c.priority,"aria-description":c.priority?void 0:"Set a priority first.",onClick:()=>void k("triaged"),children:"Triage"}):null,c.status==="open"||c.status==="triaged"?i.jsxs(U,{onClick:()=>v("resolve"),children:[i.jsx(of,{className:"mr-2 size-4"}),"Resolve"]}):null,c.status==="resolved"?i.jsxs(i.Fragment,{children:[i.jsxs(U,{variant:"outline",onClick:()=>void k("open"),children:[i.jsx(oz,{className:"mr-2 size-4"}),"Reopen"]}),i.jsx(U,{onClick:()=>void k("closed"),children:"Close"})]}):null]}):void 0,children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(we,{variant:GD[c.status],children:Sh[c.status]}),i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Logged by ",Z3(c)," ",Au(c.created_at)]})]})}),i.jsxs("div",{className:"flex flex-col gap-8 lg:flex-row lg:items-start",children:[i.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-6",children:[a>0&&c.external_reference?i.jsxs(pe,{variant:"info",children:[i.jsx(fn,{}),i.jsxs(ge,{className:"flex flex-row flex-wrap items-center justify-between gap-2",children:[i.jsxs("span",{children:[c.external_reference," is already logged on"," ",a===1?"another issue":`${a} other issues`," in this project."]}),i.jsx(U,{asChild:!0,variant:"outline",size:"sm",children:i.jsx(o,{href:r(`${s}?external_reference=${encodeURIComponent(c.external_reference)}`),children:"Show both"})})]})]}):null,i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:"Description"}),c.description?i.jsx("p",{className:"text-sm break-words whitespace-pre-wrap",children:c.description}):i.jsx("p",{className:"text-muted-foreground text-sm",children:"No description."})]}),i.jsxs("section",{className:"flex flex-col gap-2",children:[i.jsx("h2",{className:"text-lg font-semibold",children:"History"}),i.jsx("div",{className:"rounded-md border",children:i.jsxs(nt,{children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"When"}),i.jsx(Q,{children:"Who"}),i.jsx(Q,{children:"What"})]})}),i.jsx(st,{children:h.map(j=>i.jsxs(_e,{children:[i.jsx(X,{className:"text-muted-foreground",children:Au(j.created_at)}),i.jsx(X,{children:Q3(j,c)}),i.jsx(X,{children:VG(j)})]},j.id))})]})})]})]}),i.jsxs("aside",{className:"flex w-full shrink-0 flex-col gap-5 lg:w-72",children:[i.jsx(Al,{label:"External reference",children:c.external_reference?i.jsx("span",{className:"font-mono text-sm",children:c.external_reference}):i.jsx("span",{className:"text-muted-foreground text-sm",children:"None"})}),c.resolution_reason?i.jsx(Al,{label:"Resolution",children:i.jsx("span",{className:"text-sm",children:hb[c.resolution_reason]})}):null,i.jsx(Al,{label:"Priority",id:"maintain-issue-priority",children:i.jsxs(St,{value:c.priority??Fr,disabled:!S||_,onValueChange:j=>void w(e.update(c.id,c.revision,{priority:j===Fr?null:j})),children:[i.jsx(wt,{id:"maintain-issue-priority",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Fr,children:"Not set"}),ub.map(j=>i.jsx(Ue,{value:j,children:Mc[j]},j))]})]})}),i.jsxs(Al,{label:"Assignee",id:"maintain-issue-assignee",children:[i.jsxs(St,{value:c.assignee_id??Fr,disabled:!S||_,onValueChange:j=>void w(e.assign(c.id,c.revision,j===Fr?null:j)),children:[i.jsx(wt,{id:"maintain-issue-assignee",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[i.jsx(Ue,{value:Fr,children:"Not set"}),c.assignee_id&&!y.some(j=>j.user_id===c.assignee_id)?i.jsx(Ue,{value:c.assignee_id,children:fb(c.assignee_id,c.assignee_username)}):null,y.map(j=>i.jsx(Ue,{value:j.user_id,children:j.username??"Not available"},j.user_id))]})]}),c.assignee_can_act===!1?i.jsx(we,{variant:"error",className:"self-start",children:"Assignee cannot act"}):null]}),i.jsx(Al,{label:"Updated",children:i.jsx("span",{className:"text-sm",children:Au(c.updated_at)})})]})]}),i.jsx(HG,{update:e.update,issue:c,open:b==="edit",onOpenChange:j=>v(j?"edit":null),onReload:x,onDone:()=>{v(null),x()}}),i.jsx(UG,{redact:e.redact,issue:c,open:b==="redact",onOpenChange:j=>v(j?"redact":null),onReload:x,onDone:()=>{v(null),l.success("The text was redacted."),x()}}),i.jsx(BG,{transition:e.transition,issue:c,open:b==="resolve",onOpenChange:j=>v(j?"resolve":null),onDone:j=>{v(null),j||l.error("Someone else changed this issue; it is reloaded."),x()}})]})}function Al({label:e,id:t,children:n}){return i.jsxs("div",{className:"flex flex-col gap-1.5",children:[t?i.jsx("label",{htmlFor:t,className:"text-muted-foreground text-2xs font-medium tracking-wide uppercase",children:e}):i.jsx("span",{className:"text-muted-foreground text-2xs font-medium tracking-wide uppercase",children:e}),n]})}const qG=10,YG=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/,d_=/^[A-Za-z0-9][A-Za-z0-9._+-]{0,63}$/;function XG(e,t,n,s=""){const a=n!=null&&n.startsWith("task:")?n.slice(5):null;if(a&&YG.test(a))return{label:a,path:`/org/${e}/tasks/${a}`};const r=`/proj/${encodeURIComponent(t)}/releases`,o=n!=null&&n.startsWith("release:")?n.slice(8):null;if(o&&d_.test(o))return{label:o==="candidate"?"Candidate":o,path:`${r}?release=${encodeURIComponent(o)}`};const l=n!=null&&n.startsWith("planned:")?n.slice(8):null;if(l&&d_.test(l))return{label:l,path:`${r}?planned=${encodeURIComponent(l)}`};const c=eo(Ru(s),XD(s));return{label:"Issues",path:`/proj/${encodeURIComponent(t)}/issues${c?`?${c}`:""}`}}const KG=["Fixed in","Being fixed in","The release planned to fix it"];function ZG(e){const t=e.filter(n=>n.kind==="release");for(const n of KG){const s=t.find(a=>a.relation===n);if(s)return s}return t[0]??null}function QG(e,t){const n=e.filter(s=>s.kind==="thread"&&(s.label===t||s.id===t));return n.find(s=>s.owns)??n[0]??null}function JG(e,t){const n=e.toLowerCase();return n==="file"&&t.trim()?{kind:"file",path:t}:n==="commit"&&/^[0-9a-f]{7,40}$/i.test(t)?{kind:"commit",sha:t}:null}function eH({org:e,project:t,issue_id:n,from:s,query:a=""}){var mn,Sn,xe;const r=JD(),{href:o,Link:l}=lt(),c=XG(e,t,s,a),d=EG(a,n),h=`/proj/${encodeURIComponent(t)}/issues`,f=ne=>`${h}/${encodeURIComponent(ne)}`,m=ne=>`${e?`/org/${e}`:""}/threads#thread-${encodeURIComponent(ne)}`,p=ne=>`/proj/${encodeURIComponent(t)}/releases?${ne.planned?"planned":"release"}=${encodeURIComponent(ne.id)}`,[y,g]=u.useState({state:"loading"}),[b,v]=u.useState(null),[x,w]=u.useState(null),[_,S]=u.useState({state:"loading"}),[k,j]=u.useState({state:"loading"}),[N,O]=u.useState(null),T=u.useRef(0),I=u.useCallback(async ne=>{if(!r.openAnchor)return;const ye=ne.kind==="file"?ne.path:ne.sha,qe=T.current+=1;O({value:ye,state:"opening",words:`Opening ${ye}…`});const xt=await r.openAnchor(ne);qe===T.current&&O(xt.ok?{value:ye,state:"opened",words:`Opened ${ye} in ${xt.data.with}`}:{value:ye,state:"failed",words:`Could not open ${ye}: ${xt.refusal.message}`})},[r]);u.useEffect(()=>{T.current+=1,O(null)},[n]);const L=u.useRef(null),$=ns(),A=u.useRef(null),D=u.useRef(!1),E=u.useRef(0),R=u.useRef(0),C=u.useRef(!1),M=Ts(),H=u.useRef(0),z=u.useRef(0),K=u.useCallback(async(ne=!1)=>{if(!r.issueSections)return;const ye=H.current+=1;ne||S({state:"loading"});const qe=await M.track(r.issueSections(n));ye===H.current&&S(xt=>qe.ok?{state:"ok",data:qe.data}:ne&&xt.state==="ok"?xt:{state:"failed",refusal:qe.refusal})},[r.issueSections,n,M]),oe=u.useCallback(async(ne=!1)=>{if(!r.issueRelated)return;const ye=z.current+=1;ne||j({state:"loading"});const qe=await M.track(r.issueRelated(n));ye===z.current&&j(xt=>qe.ok?{state:"ok",data:qe.data}:ne&&xt.state==="ok"?xt:{state:"failed",refusal:qe.refusal})},[r.issueRelated,n,M]),re=u.useCallback(async(ne=!1)=>{const ye=R.current+=1;if(w(null),!oG.test(n)){g({state:"missing"});return}K(ne),oe(ne);const qe=await M.track(r.issue(n));if(ye!==R.current)return;if(qe.ok){E.current=0,v(null),g({state:"ok",issue:qe.data.issue,events:qe.data.events,at:new Date().toISOString()});return}const xt=qe.refusal.reason;if(qe.refusal.status===404||xt==="not_found")return g({state:"missing"});if(xt==="engine_missing")return g({state:"engine_missing",refusal:qe.refusal});if(xt==="view_outdated")return g({state:"view_outdated"});if(E.current+=1,E.current===1&&PD(qe.refusal)){C.current=ne,w(qe.refusal.retry_after??qG);return}v(qe.refusal)},[r.issue,n,K,oe,M]);u.useEffect(()=>{re()},[re]);const Ne=u.useMemo(()=>Uf(M,()=>void re(!0)),[re,M]);Wi(Ne,QD),u.useEffect(()=>{if(x===null)return;const ne=setTimeout(()=>{document.visibilityState==="visible"&&re(C.current)},x*1e3);return()=>clearTimeout(ne)},[x,re]),u.useEffect(()=>{var ye;if(D.current||y.state!=="ok")return;D.current=!0;const ne=(ye=L.current)==null?void 0:ye.querySelector("h1");ne&&(ne.tabIndex=-1,ne.focus())},[y.state]);const Se=u.useRef(null);u.useEffect(()=>{var qe;const ne=Se.current;if(ne===null||(ne==="sections"?_:k).state==="loading")return;Se.current=null;const ye=(ne==="related"?A.current:null)??((qe=L.current)==null?void 0:qe.querySelector("h1"));ye==null||ye.focus()},[_,k]);const ae=ne=>{Se.current=ne,ne==="sections"?K():oe()},F=()=>{E.current=0,re()},ie=cb(L),W=u.useRef(!1),se=()=>{W.current=!0,F()};u.useEffect(()=>{var ye;if(!W.current||y.state==="loading"||x!==null)return;W.current=!1;const ne=(ye=L.current)==null?void 0:ye.querySelector("h1");ne&&(ne.tabIndex=-1,ne.focus())},[y,b,x]);const Z=Vf({org:e,labelled:!0,action:(mn=r.commands)!=null&&mn.open_thread&&y.state==="ok"?y.issue.local_action:void 0,task_id:null,issue:n,open_thread:(Sn=r.commands)==null?void 0:Sn.open_thread});if(y.state==="missing")return i.jsx(ma,{children:i.jsx(Ha,{icon:i.jsx(uf,{"aria-hidden":"true"}),title:"Issue not found",description:`No issue ${n} in this repository's issue store.`,backHref:o(s==="issues"?c.path:h),backLabel:"Back to issues",link:l})});const de=i.jsx(U,{asChild:!0,variant:"link",size:"sm",className:"px-0",children:i.jsxs(l,{href:o(c.path),children:[i.jsx($k,{className:"size-4","aria-hidden":"true"}),c.label]})});if(y.state==="engine_missing"||y.state==="view_outdated")return i.jsx(ma,{children:y.state==="engine_missing"?i.jsx(yi,{page:"Issue",header:i.jsx(oc,{back:de,id:null,title:n})}):i.jsxs(i.Fragment,{children:[i.jsx(oc,{back:de,id:null,title:n}),i.jsxs(pe,{variant:"warning",className:"mt-4",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:$})]})]})});const J=b?i.jsxs(pe,{ref:ie,variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This issue could not be loaded"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[b.message,b.since?` Since ${As(b.since)}.`:"",y.state==="ok"?` This page was read at ${As(y.at)}.`:"",b.message.includes(vr)?"":` ${vr}`]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:se,children:"Retry"})]})]}):null,G=i.jsx("div",{role:"status","aria-live":"polite",children:x!==null?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",children:[i.jsx(vn,{"aria-hidden":"true"}),"This issue is busy. Reading it again…"]}):null});if(y.state==="loading")return i.jsxs(ma,{children:[i.jsx("div",{children:de}),G,J,!b&&x===null?i.jsxs("div",{className:"mt-4 grid gap-3",role:"status","aria-label":"Loading issue",children:[i.jsx(Tt,{className:"h-6 w-40"}),i.jsx(Tt,{className:"h-9 w-2/3"}),i.jsx(Tt,{className:"h-24 w-full"})]}):null]});const{issue:Y,events:te,at:ce}=y,be=qD(Y),fe=_.state==="ok"?_.data:null,$e=(fe==null?void 0:fe.reporter)??Y.created_by_username??null,ze=k.state==="ok"?ZG(k.data):null,q=Y.status==="resolved"||Y.group==="resolved",ve=!!(fe!=null&&fe.duplicate_of),Ve=(fe==null?void 0:fe.routing.owner)??Y.owner_title??null,Ft=Ve&&k.state==="ok"?QG(k.data,Ve):null,Qt=_.state==="loading"?"Loading…":Ft?i.jsx(l,{className:"text-primary hover:underline",href:o(m(Ft.id)),children:Ve}):Ve??i.jsx("span",{className:"text-muted-foreground",children:"Unowned"}),ht=ne=>`${h}?${mb({...Fg,collection:ne})}`,it=fe==null?void 0:fe.report,Lt=!!(it&&(it.actual||it.expected||it.steps.length||it.where)),Dt=[...te].reverse(),On=i.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-2",children:[Z.button,i.jsxs("span",{className:"text-muted-foreground text-sm",children:["Read at ",As(ce)]}),i.jsxs(U,{type:"button",variant:"ghost",size:"sm",onClick:F,children:[i.jsx(Er,{className:"mr-2 size-4","aria-hidden":"true"}),"Read again"]})]});return i.jsx(ma,{children:i.jsxs("div",{ref:L,className:"contents",children:[i.jsx(oc,{back:de,id:Y.id,badge:i.jsxs(i.Fragment,{children:[i.jsx(we,{variant:be.tone,children:be.label}),Y.urgent&&!q?i.jsx(we,{variant:"warning",children:"Urgent"}):null]}),title:Y.title,created:`Reported${$e?` by ${$e}`:""} · ${lc(Y.created_at)}`,actions:On}),fe!=null&&fe.duplicate_of?i.jsxs("p",{className:"mt-1 text-sm",children:["Duplicate of"," ",i.jsx(l,{className:"text-primary font-mono hover:underline",href:o(f(fe.duplicate_of)),children:fe.duplicate_of})]}):null,Z.panel?i.jsx("div",{className:"mt-1 max-w-180",children:Z.panel}):null,i.jsx("div",{role:"status","aria-live":"polite",children:d?i.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:d}):null}),G,J,_.state==="loading"?i.jsxs("p",{className:"text-muted-foreground mt-2 flex items-center gap-2 text-sm",role:"status",children:[i.jsx(vn,{"aria-hidden":"true"}),"Loading the issue's sections"]}):null,i.jsxs("dl",{className:"mt-4 mb-0 flex flex-wrap gap-x-12 gap-y-4","data-testid":"issue-facts",children:[i.jsx(ai,{label:"Owner",value:Qt}),ve?null:i.jsx(ai,{label:"Release",value:k.state==="loading"?"Loading…":ze?i.jsx(l,{className:je("text-primary hover:underline",ze.label===ze.id&&"font-mono"),href:o(p(ze)),children:ze.label}):i.jsx("span",{className:"text-muted-foreground",children:"No release yet"})}),i.jsx(ai,{label:"Reported",value:[$e,Y.created_at?Rs(Y.created_at):null].filter(Boolean).join(" · ")})]}),i.jsxs(pe,{variant:"info",className:"mt-4",children:[i.jsx(cd,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:i_.title}),i.jsx(ge,{children:i_.body})]}),_.state==="failed"?i.jsx("div",{className:"mt-6",children:i.jsx(db,{what:"this issue's sections",again:"Read the issue again",refusal:_.refusal,on_retry:()=>ae("sections")})}):null,fe&&Lt&&it?i.jsxs(Yt,{id:"issue-report",title:"What happens",children:[it.actual?i.jsx("p",{className:"text-sm whitespace-pre-wrap",children:it.actual}):null,it.expected?i.jsxs("div",{className:"mt-3",children:[i.jsx("h3",{className:"text-sm font-semibold",children:"Expected"}),i.jsx("p",{className:"text-sm whitespace-pre-wrap",children:it.expected})]}):null,it.steps.length?i.jsxs("div",{className:"mt-3",children:[i.jsx("h3",{className:"text-sm font-semibold",children:"Steps"}),i.jsx("ol",{className:"list-decimal pl-5 text-sm",children:it.steps.map((ne,ye)=>i.jsx("li",{children:ne},ye))})]}):null,(xe=it.where)!=null&&xe.env?i.jsxs("p",{className:"text-muted-foreground mt-3 text-sm",children:["Seen on ",it.where.env,it.where.sha?i.jsxs(i.Fragment,{children:[" ","at ",i.jsx("span",{className:"font-mono",children:it.where.sha})]}):null]}):null]}):null,fe&&(fe.placement.placed||fe.placement.unplaced_why)?i.jsx(Yt,{id:"issue-placement",title:"Placement",children:fe.placement.placed?i.jsxs("p",{className:"text-sm",children:["Placed in ",fe.placement.placed]}):i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Not placed yet: ",fe.placement.unplaced_why]})]})}):null,fe&&(fe.routing.route||fe.routing.owner||fe.routing.none)?i.jsxs(Yt,{id:"issue-routing",title:"Routing",children:[fe.routing.route?i.jsx("p",{className:"text-sm",children:fe.routing.route}):null,fe.routing.owner?i.jsxs("p",{className:"text-sm",children:["Owner: ",fe.routing.owner]}):i.jsx("p",{className:"text-muted-foreground text-sm",children:"Owner: none yet"})]}):null,fe&&(fe.labels.length>0||fe.collections.length>0)?i.jsxs(Yt,{id:"issue-labels",title:"Labels and collections",children:[fe.labels.length?i.jsx("div",{className:"flex flex-wrap gap-1",children:fe.labels.map(ne=>i.jsx(we,{variant:"neutral",size:"dense",children:ne},ne))}):null,fe.collections.length?i.jsx("ul",{className:"mt-2 grid gap-1 text-sm",children:fe.collections.map(ne=>i.jsxs("li",{children:[i.jsx(l,{className:"text-primary hover:underline",href:o(ht(ne.collection)),children:ne.title}),ne.ref?i.jsxs("span",{className:"text-muted-foreground",children:[" · ",ne.ref]}):null,i.jsxs("span",{className:"text-muted-foreground",children:[" ","· ",ne.resolved," of ",ne.total," resolved"]})]},ne.collection))}):null]}):null,fe&&fe.anchors.length>0?i.jsxs(Yt,{id:"issue-anchors",title:"Anchors",children:[i.jsx(hp,{label:"Anchors",heads:["Kind","Value","By"],rows:fe.anchors.map(ne=>{const ye=r.openAnchor?JG(ne.kind,ne.value):null;return[ne.kind,ye?i.jsx(U,{type:"button",variant:"link",size:"control",className:"h-auto min-h-7 justify-start px-0 text-left font-mono text-xs font-normal break-all whitespace-normal","aria-label":ye.kind==="file"?`Open ${ne.value}`:`Show commit ${ne.value}`,onClick:()=>void I(ye),children:ne.value}):i.jsx("span",{className:"font-mono text-xs break-all",children:ne.value}),ne.by??""]})}),r.openAnchor?i.jsx("p",{role:"status","aria-live":"polite","data-testid":"issue-anchor-status",className:je("mt-2 text-sm empty:hidden",(N==null?void 0:N.state)==="failed"?"text-destructive":(N==null?void 0:N.state)==="opened"?"text-success":"text-muted-foreground"),children:(N==null?void 0:N.words)??""}):null]}):null,fe&&fe.seen.length>0?i.jsx(Yt,{id:"issue-seen",title:"Seen",aside:`${fe.seen.length} of ${Math.max(Y.occurrences??0,fe.seen.length)} sightings`,children:i.jsx(hp,{label:"Seen",heads:["When","Where","Who","Note"],rows:fe.seen.map(ne=>[lc(ne.at),i.jsxs(i.Fragment,{children:[ne.sha?i.jsx("div",{className:"font-mono text-xs",children:ne.sha}):null,ne.env?i.jsx("div",{className:"text-muted-foreground text-xs",children:ne.env}):null]}),ne.who??"",ne.note??""])})}):null,Dt.length>0?i.jsx(Yt,{id:"issue-history",title:"History",aside:"From the issue store, newest first",children:i.jsx(hp,{label:"History",heads:["When","Who","What"],rows:Dt.map(ne=>[lc(ne.created_at),ne.actor_username??"",bG(ne.note,ne.kind)])})}):null,i.jsx(ID,{id:"issue-related",related:k,heading_ref:A,on_retry:()=>ae("related"),fixed:!0,link:ne=>{const ye=ne.kind==="thread"?m(ne.id):ne.kind==="task"?`/org/${e}/tasks/${encodeURIComponent(ne.id)}?from=issue:${Y.id}`:ne.kind==="issue"?f(ne.id):ne.kind==="release"?p(ne):null;if(ne.kind==="task"&&ye){const qe=yG(ne.label);return i.jsxs("div",{className:"min-w-0",children:[i.jsx(l,{className:"text-primary font-mono text-xs hover:underline",href:o(ye),children:ne.id}),qe&&qe!==ne.id?i.jsx("div",{className:"text-muted-foreground line-clamp-1 text-xs",title:qe,"data-testid":"related-task-title",children:qe}):null]})}return ye?i.jsx(l,{className:je("text-primary hover:underline",ne.kind!=="thread"&&ne.label===ne.id&&"font-mono"),href:o(ye),children:ne.label}):ne.label}})]})})}function hp({label:e,heads:t,rows:n}){return i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:e,children:[i.jsx(ot,{children:i.jsx(_e,{children:t.map(s=>i.jsx(Q,{children:s},s))})}),i.jsx(st,{children:n.map((s,a)=>i.jsx(_e,{children:s.map((r,o)=>i.jsx(X,{className:"break-words",children:r},o))},a))})]})})}function tH({org:e,project:t,issue_id:n,from:s,query:a}){var r;return(r=Vn().issues)!=null&&r.issueSections?i.jsx(eH,{org:e,project:t,issue_id:n,from:s,query:a}):i.jsx(WG,{org:e,project:t,issue_id:n,query:a})}const fi={label:"Stalled",tone:"error"},nH="A stalled turn passes on at the next queue command.",sH=e=>e.charAt(0).toUpperCase()+e.slice(1);function iH(e){return e==="starts now"?"Now":e==="rides the same deploy"?"With the same deploy":sH(e.replace(/^starts /,""))}const aH=e=>e.replace(/ after its turn came$/," after its turn"),eE={integration:"Integration",deploy:"Deploy",publish:"Publish",accept:"Accept",custom:"Custom"},rH={self_service:"Self-service",managed:"Managed",manager_only:"Manager only"},oH={self_service:"Self-service: each entry takes its own turn",managed:"Managed: a manager batches entries that allow it",manager_only:"Manager only: the manager runs every turn"},lH={in_batch:{label:"In the batch",tone:"info"},done:{label:"Done",tone:"success"},failed:{label:"Failed",tone:"error"},released:{label:"Released",tone:"neutral"},left:{label:"Left",tone:"neutral"},gone:{label:"Ended",tone:"neutral"},skipped:{label:"Skipped",tone:"neutral"},lapsed:{label:"Lapsed",tone:"warning"}};function cH(e){return lH[e??"in_batch"]}function dH(e,t=!1){if(t)return fi;const n=e.turn==="next",s=n?"Next":"Waiting",a=e.batching==="managed"||e.batching==="released"?` · ${e.batching}`:"";return{label:`${s}${a}`,tone:n?"info":"neutral"}}const tE=(e,t)=>`Holds ${e.toLowerCase()}${t?`: ${t}`:""}`;function uH(e,t,n,s=!0,a=!1){return a?fi:e.fixing_since!==void 0?{label:`Fixing forward since ${Xn(e.fixing_since)}`,tone:"warning"}:e.ref===t?{label:"Landing",tone:"info"}:s&&e.hold?{label:tE(n),tone:"info"}:{label:"Running",tone:"info"}}function Xn(e){return new Date(e*1e3).toLocaleTimeString(void 0,{hour:"numeric",minute:"2-digit"})}function qr(e){const t=Math.round(e/60);if(t<60)return`${t} min`;const n=Math.floor(t/60),s=t%60;return s?`${n} h ${s} min`:`${n} h`}function hH(e){var n;const t=e.binding;return(t==null?void 0:t.kind)==="repository_branch"?`${t.repository} · ${t.branch}`:(t==null?void 0:t.kind)==="label"?t.label:((n=e.layer)==null?void 0:n.kind)==="release"&&e.layer.promotes_to?`Promotes to ${e.layer.promotes_to}`:null}function fH(e,t){switch(e.kind){case"any_thread":return"Any thread in this checkout";case"task_writers":return"Anyone who can edit the entry's task";case"any_joiner":return"Anyone who may join";case"managers":return"Whoever may manage";case"admins":return"Workspace admins";case"none":return"Nobody";case"listed":{const n=e.users.map(t),s=e.teams.length;return s&&n.push(s===1?"1 team":`${s} teams`),n.length?n.join(", "):"Nobody"}}}function mH(e,t){var l,c;const{policy:n,management:s}=e,a=(l=e.layer)==null?void 0:l.kind,r=d=>fH(d,t),o=[["Mode",oH[s.mode]],["Who can join",r(s.joiners)]];return a==="implement"&&o.push(["Managers",r(s.managers)],["Manager lease",qr(s.manager_lease_seconds)],["Batches",n.batch.enabled?`Up to ${n.batch.max_members} entries`:"Off"]),((c=e.layer)==null?void 0:c.kind)==="release"&&(e.layer.promotes_to&&o.push(["Promotes to",e.layer.promotes_to]),o.push(["Carries waiting entries",n.ride?"Yes: a done turn carries entries already contained in it":"No"],["Freeze",n.freeze.enabled?`Up to ${qr(n.freeze.max_seconds)}, ${qr(n.freeze.default_seconds)} by default`+(e.layer.freezers?` · ${r(e.layer.freezers)}`:""):"Off"],["Fix forward",n.fix_forward?"Yes: a failed turn keeps its turn until fixed":"No"],["Stalled turns",s.stall_takers.kind==="none"?"Nobody takes one":`${r(s.stall_takers)} may take one after ${qr(n.stall_seconds)}`])),o.push(["Reorder",r(s.reorderers)]),n.max_turns>1&&o.push(["Turns at once",`Up to ${n.max_turns} independent turns`]),o.push(["Turn lease",qr(n.lease_seconds)],["Time to start",`${qr(n.start_grace_seconds)} after the turn comes`]),n.entry_limit!==null&&o.push(["Waiting entries",`Up to ${n.entry_limit}`]),n.footprint!=="off"&&o.push(["Footprint",n.footprint==="required"?"Required":"Optional"]),o}const Ch="heavy",nE="Heavy checks",pH="Every worktree, admitted by memory",gH="Typechecks, builds, test suites and dev servers from every worktree of this repository wait here for memory.",xH="A smaller turn may pass one that does not fit, so the order can change; a passing turn reused on identical code never waits.",vH="Heavy checks are admitted by this machine's memory; there are no settings here.",sE="Where your organization's agents take turns at a shared branch, environment or proposal. One turn runs at a time in each queue.",iE="A task you cannot see",bH="A former member",yH="A member";function aE(){const e=Vn().queues;if(!e)throw new Error("The Queues page rendered without the queues seam.");return e}function wH({org:e,open:t,path:n}){var f,m;const s=aE(),{href:a,Link:r}=lt(),o=s.availability,[l,c]=u.useState({state:"loading"}),d=u.useCallback(async p=>{o&&(p&&c({state:"loading"}),c(await o({fresh:p})))},[o]);u.useEffect(()=>{d(!1)},[d]);const h=!o||l.state==="active";return l.state==="off"&&((f=l.refusal)==null?void 0:f.reason)!=="engine_missing"?i.jsx(Ha,{title:"Page not found",description:"This page does not exist, or you do not have access to it.",backHref:a(`/org/${e}`),backLabel:"Back to the organization",link:r}):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:h?i.jsx(jH,{org:e,open:t??null,path:n??`/org/${e}/tasks/queues`}):l.state==="off"&&((m=l.refusal)==null?void 0:m.reason)==="engine_missing"?i.jsx(yi,{page:"Queues"}):i.jsxs(i.Fragment,{children:[i.jsx(bn,{title:"Queues",description:s.description??sE}),l.state==="loading"&&i.jsx(rE,{}),(l.state==="error"||l.state==="off")&&i.jsx(Tu,{refusal:l.refusal,on_retry:()=>void d(!0)}),l.state==="available"&&i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Tasks are not on for this organization"}),i.jsxs(ge,{children:["Queues hold turns for tasks, so they show once Tasks are on."," ",i.jsx(r,{className:"text-primary hover:underline",href:a(`/org/${e}/tasks`),children:"Go to Tasks"})]})]})]})})}function rE(){return i.jsx("div",{className:"mt-6 grid gap-2",role:"status","aria-label":"Loading queues",children:Array.from({length:3},(e,t)=>i.jsx(Tt,{className:t===2?"h-10 w-2/3":"h-10 w-full"},t))})}function Tu({refusal:e,on_retry:t}){const n=ns();return(e==null?void 0:e.reason)==="store_locked"?i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"The local stores are busy"}),i.jsxs(ge,{children:[i.jsx("p",{children:e.message}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]}):(e==null?void 0:e.reason)==="view_outdated"?i.jsxs(pe,{variant:"warning",className:"mt-6",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{children:n})]}):i.jsxs(pe,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Queues could not be loaded"}),i.jsxs(ge,{children:[i.jsx("p",{children:"The read did not answer. Try again in a moment."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]})}const fp=e=>e.status===404||e.reason==="not_found"||e.code==="not_found";function _H(e,t,n,s){return t?e===null?`Not reading · trying again every ${n}s`:`Not reading since ${Xn(e)} · trying again every ${n}s`:e===null?"Connecting…":`Live · read ${Xn(e)} · refreshes every ${n}s${s?` · ${s}`:""}`}function jH({org:e,open:t,path:n}){var G;const{listQueues:s,queue:a,members:r,refresh_ms:o,settings_note:l,description:c,read_scope:d,subject_label:h="Task",thread_subjects:f=!1,timing:m}=aE(),{self_id:p}=af(),y=!!m&&t===Ch,[g,b]=u.useState(null),[v,x]=u.useState(null),[w,_]=u.useState(null),[S,k]=u.useState(null),[j,N]=u.useState({state:"pending",members:[]});u.useEffect(()=>{let Y=!0;return r().then(te=>{Y&&N(ce=>te.ok?{state:"answered",members:te.data}:{state:"failed",members:ce.members})}),()=>{Y=!1}},[r]);const O=u.useMemo(()=>new Map(j.members.map(Y=>[Y.user_id,Y])),[j.members]),T=j.state==="answered"?bH:yH,I=u.useCallback((Y,te)=>{var ce;return(te==null?void 0:te.title)??(f?(te==null?void 0:te.id)??Y:Y===p?"You":((ce=O.get(Y))==null?void 0:ce.label)??T)},[O,T,p,f]),L=u.useRef({list:{last:null,fresh:!1},detail:{last:null,fresh:!1}}),[$,A]=u.useState(null),[D,E]=u.useState(!1),R=u.useCallback((Y,te)=>{L.current[Y]={last:te,fresh:!0};const{list:ce,detail:be}=L.current;E(ce.last==="failed"||be.last==="failed"),ce.fresh&&be.fresh&&ce.last==="ok"&&be.last==="ok"&&A(Date.now()/1e3)},[]),C=t??((G=g==null?void 0:g.queues[0])==null?void 0:G.id)??null,M=u.useRef(C);u.useEffect(()=>{M.current=C},[C]);const H=u.useRef(0),z=u.useCallback(async()=>{var ce;const Y=H.current+=1;L.current.list.fresh=!1;const te=await s();if(Y===H.current)if(te.ok){if(b(te.data),x(null),!t){const be=((ce=te.data.queues[0])==null?void 0:ce.id)??null;be===null?L.current.detail={last:"ok",fresh:!0}:be!==M.current&&(L.current.detail.fresh=!1)}R("list","ok")}else x(te.refusal),R("list","failed")},[s,t,R]),K=u.useRef(0),oe=u.useCallback(async()=>{const Y=K.current+=1;if(!C)return;if(y){L.current.detail.fresh=!1;return}L.current.detail.fresh=!1;const te=await a(C);Y===K.current&&(te.ok?(_(te.data),k(null),R("detail","ok")):(k(te.refusal),fp(te.refusal)&&_(null),R("detail",fp(te.refusal)?"ok":"failed")))},[y,C,a,R]),[re,Ne]=u.useState({state:"pending",data:null}),Se=u.useRef(0),ae=u.useCallback(async()=>{if(!m)return;const Y=Se.current+=1,te=await m();Y===Se.current&&(Ne(te.ok?{state:"answered",data:te.data}:{state:"failed",data:null}),y&&R("detail",te.ok?"ok":"failed"))},[m,y,R]);u.useEffect(()=>{z()},[z]),u.useEffect(()=>{_(null),k(null),oe()},[oe]),u.useEffect(()=>{ae()},[ae]);const F=u.useCallback(()=>{z(),oe(),ae()},[z,oe,ae]),ie=u.useMemo(()=>{var Y;return new Map((((Y=re.data)==null?void 0:Y.queues)??[]).map(te=>[te.key,te]))},[re.data]),W=ie.get(Ch),se=!g&&(v==null?void 0:v.reason)==="engine_missing",Z=u.useCallback(()=>{se||F()},[se,F]);if(Wi(Z,o),se)return i.jsx(yi,{page:"Queues"});const de=Math.round(o/1e3),J=S!==null&&fp(S);return i.jsxs(i.Fragment,{children:[i.jsxs(bn,{title:"Queues",description:c??sE,children:[i.jsx("p",{className:"text-muted-foreground text-xs",children:_H($,D,de,d)}),i.jsx("span",{className:"sr-only",role:"status",children:D?"Not reading":$===null?"Connecting":"Live"})]}),!g&&!v&&i.jsx(rE,{}),!g&&v&&i.jsx(Tu,{refusal:v,on_retry:F}),g&&g.queues.length===0?i.jsxs("div",{className:"mt-12 flex flex-col items-center gap-2 text-center",children:[i.jsx(bv,{className:"text-muted-foreground size-8","aria-hidden":"true"}),i.jsx("h2",{className:"text-lg font-semibold",children:"No queues yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Queues are created through the sdlc CLI, the MCP tools or the API. Once one exists, its turns and waiting work show here."})]}):g?i.jsxs(i.Fragment,{children:[i.jsx(CH,{path:n,queues:g.queues,open_id:C,name:I,held:f,timing_of:ie,heavy:W}),y?W?i.jsx(AH,{org:e,timing:W}):re.data?i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Heavy checks are not available"}),i.jsx(ge,{children:"This checkout reads no heavy queue. Pick another queue above."})]}):re.state==="failed"?i.jsx(Tu,{on_retry:()=>void ae()}):i.jsx(Tt,{className:"mt-6 h-40 w-full shrink-0",role:"status","aria-label":"Loading the queue"}):J?i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This queue is no longer available"}),i.jsx(ge,{children:"It was archived, or you can no longer read its Workspace. Pick another queue above."})]}):w&&w.queue.id===C?i.jsx(RH,{org:e,detail:w,name:I,settings_note:l,subject_label:h,thread_subjects:f,timing:ie.get(w.queue.id)}):S?i.jsx(Tu,{refusal:S,on_retry:()=>void oe()}):i.jsx(Tt,{className:"mt-6 h-40 w-full shrink-0",role:"status","aria-label":"Loading the queue"})]}):null]})}function Dh({org:e,subject:t,link:n}){const{href:s,Link:a}=lt();return!t||t.hidden?i.jsx("span",{className:"text-muted-foreground",children:iE}):t.kind==="task"&&n?i.jsx(a,{className:"text-primary hover:underline",href:s(`/org/${e}/tasks/${t.id}`),children:t.title??t.id}):t.kind==="thread"&&!n&&t.id&&!t.id.startsWith("exec-")?i.jsx(a,{className:"text-primary hover:underline",href:s(`${e?`/org/${e}`:""}/threads#thread-${encodeURIComponent(t.id)}`),children:t.title??t.id}):i.jsx("span",{children:t.title??t.id})}function NH(e,t,n){const s=e.freeze?`frozen until ${Xn(e.freeze.lease_until)}`:null;if(e.batch)return{primary:`Batch of ${e.batch.size} · ${t(e.batch.holder,e.batch.holder_subject)}`,secondary:[`Opened ${Xn(e.batch.opened_at)}`,s].filter(Boolean).join(" · "),warn:!1};if(e.turn){const a=e.turn.subject,r=a.hidden?iE:a.title??a.id,o=(e.running_count??1)>1?`${e.running_count} turns · `:"",l=e.turn.landing?" landing":"",c=n&&!!e.turn.hold,d=[c?tE(e.name,e.turn.note):null,e.turn.fixing_since!==void 0?"Fixing forward":null,s].filter(Boolean);return c&&e.turn.fixing_since===void 0&&!s?{primary:`${o}${r}${l}`,secondary:Da(d.join(" · ")),warn:!1}:{primary:`${o}${r}${l}`,secondary:d.length?Da(d.join(" · ")):null,warn:d.length>0}}return{primary:"Nothing running",secondary:s?Da(s):null,warn:!!s}}const Da=e=>e.charAt(0).toUpperCase()+e.slice(1),oE=e=>(e==null?void 0:e.rows.filter(t=>t.turn===fi.label).length)??0;function kH({timing:e}){return e!=null&&e.clears?i.jsx("div",{className:"text-muted-foreground text-xs",children:Da(e.clears)}):null}function SH({timing:e}){const t=oE(e);return t?i.jsx(we,{variant:fi.tone,children:`${t} stalled`}):null}function CH({path:e,queues:t,open_id:n,name:s,held:a,timing_of:r,heavy:o}){const{href:l,Link:c}=lt();return i.jsx(yt,{className:"mt-4 shrink-0 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Queues",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Queue"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Step"}),i.jsx(Q,{children:"Running turn"}),i.jsx(Q,{className:"hidden text-right md:table-cell",children:"Waiting"})]})}),i.jsxs(st,{children:[t.map(d=>{var g;const h=d.id===n,f=hH(d),m=NH(d,s,a),p=d.waiting-(((g=d.batch)==null?void 0:g.remaining)??0),y=r.get(d.id);return i.jsxs(_e,{"data-testid":"queues-row",className:je(h&&"bg-accent"),children:[i.jsxs(X,{children:[i.jsx(c,{className:"text-primary hover:underline",href:l(`${e}?queue=${encodeURIComponent(d.id)}`),"aria-current":h?"page":void 0,children:d.name}),f?i.jsx("div",{className:"text-muted-foreground text-xs",children:f}):null,i.jsxs("div",{className:"text-muted-foreground text-xs md:hidden",children:[p," waiting"]})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(we,{variant:"neutral",children:eE[d.policy.step]})}),i.jsxs(X,{children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:je(!d.batch&&!d.turn&&"text-muted-foreground"),children:m.primary}),i.jsx(SH,{timing:y})]}),m.secondary?i.jsx("div",{className:je("text-xs",m.warn?"text-warning":"text-muted-foreground"),children:m.secondary}):null,i.jsx(kH,{timing:y})]}),i.jsx(X,{className:"hidden text-right md:table-cell",children:p})]},d.id)}),o?i.jsx(DH,{path:e,timing:o,current:n===Ch}):null]})]})})}const Xg=e=>e.turn==="Running";function DH({path:e,timing:t,current:n}){const{href:s,Link:a}=lt(),r=t.rows.filter(Xg).length,o=t.rows.length-r,l=t.error?"Not available":r?[`${r} running`,t.memory].filter(Boolean).join(" · "):"Nothing running";return i.jsxs(_e,{"data-testid":"queues-row",className:je(n&&"bg-accent"),children:[i.jsxs(X,{children:[i.jsx(a,{className:"text-primary hover:underline",href:s(`${e}?queue=${Ch}`),"aria-current":n?"page":void 0,children:nE}),i.jsx("div",{className:"text-muted-foreground text-xs",children:pH}),t.error?null:i.jsxs("div",{className:"text-muted-foreground text-xs md:hidden",children:[o," waiting"]})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(we,{variant:"neutral",children:"Checks"})}),i.jsxs(X,{children:[i.jsx("div",{className:je(!r&&"text-muted-foreground"),children:l}),!r&&!t.error&&t.memory?i.jsx("div",{className:"text-muted-foreground text-xs",children:Da(t.memory)}):null]}),i.jsx(X,{className:"hidden text-right md:table-cell",children:t.error?"—":o})]})}function EH(e){if(!e)return()=>{};const t=new Map(e.rows.filter(s=>s.execution).map(s=>[s.execution,s])),n=new Map;for(const s of e.rows)s.key&&n.set(s.key,n.has(s.key)?null:s);return s=>t.get(s.ref)??n.get(s.subject.id)??void 0}const Kg="No estimate yet";function lE(e){return e?e.turn===fi.label?e.elapsed:[e.elapsed,e.estimate].filter(Boolean).join(" · "):Kg}function cE(e){return e?e.turn===fi.label?aH(e.elapsed):e.estimate?iH(e.estimate):Kg:Kg}function go({id:e,title:t,side:n,children:s}){return i.jsxs("section",{"aria-labelledby":e,className:"flex flex-col gap-2",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h3",{id:e,className:"text-sm font-semibold",children:t}),n?i.jsx("span",{className:"text-muted-foreground text-xs",children:n}):null]}),s]})}function u_({org:e,entries:t,landing:n,queue_name:s,subject_label:a,held:r,label:o,time_of:l}){return i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:o,children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:a}),i.jsx(Q,{children:"State"}),l?i.jsx(Q,{children:"Time"}):null]})}),i.jsx(st,{children:t.map(c=>{const d=l==null?void 0:l(c),h=uH(c,n,s,r,(d==null?void 0:d.turn)===fi.label);return i.jsxs(_e,{"data-testid":"queues-running",children:[i.jsxs(X,{children:[i.jsx(Dh,{org:e,subject:c.subject,link:!r}),r&&c.hold&&c.note&&!c.subject.hidden?i.jsx("div",{className:"text-muted-foreground text-xs",children:c.note}):null]}),i.jsx(X,{children:i.jsx(we,{variant:h.tone,children:h.label})}),l?i.jsx(X,{className:"text-muted-foreground text-xs",title:d==null?void 0:d.basis,children:lE(d)}):null]},c.ref)})})]})})}function h_({org:e,row:t}){return t.key?i.jsx(Dh,{org:e,subject:{kind:"thread",id:t.key,title:t.title},link:!1}):i.jsx("span",{children:t.title})}function f_({command:e}){return e?i.jsx("span",{className:"block max-w-xs truncate font-mono text-xs",title:e,children:e}):null}function AH({org:e,timing:t}){const n=t.rows.filter(Xg),s=t.rows.filter(a=>!Xg(a));return i.jsxs(yt,{as:"section","aria-labelledby":"queue-title",className:"mt-6 flex shrink-0 flex-col gap-4 p-4","data-testid":"queues-detail",children:[i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h2",{id:"queue-title",className:"text-lg font-semibold",children:nE}),i.jsx("p",{className:"text-muted-foreground text-sm",children:gH}),t.memory&&!t.error?i.jsx("p",{className:"text-muted-foreground text-xs font-medium",children:Da(t.memory)}):null,i.jsx("p",{className:"text-muted-foreground text-xs",children:xH})]}),t.error?i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Heavy checks could not be read"}),i.jsx(ge,{children:Da(t.error)})]}):t.rows.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running, and nothing waits in this queue."}):i.jsxs(i.Fragment,{children:[i.jsx(go,{id:"queue-running",title:n.length>1?"Running turns":"Running turn",children:n.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running."}):i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Running turns",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Thread"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Command"}),i.jsx(Q,{className:"hidden text-right md:table-cell",children:"Memory"}),i.jsx(Q,{children:"Time"})]})}),i.jsx(st,{children:n.map(a=>i.jsxs(_e,{"data-testid":"queues-running",children:[i.jsxs(X,{children:[i.jsx(h_,{org:e,row:a}),i.jsx("div",{className:"text-muted-foreground text-xs break-all md:hidden",children:[a.command,a.memory].filter(Boolean).join(" · ")})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(f_,{command:a.command})}),i.jsx(X,{className:"hidden text-right tabular-nums md:table-cell",children:a.memory}),i.jsx(X,{className:"text-muted-foreground text-xs",title:a.basis,children:lE(a)})]},a.position))})]})})}),i.jsx(go,{id:"queue-waiting",title:"Waiting",children:s.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing waits."}):i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Waiting entries",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Position"}),i.jsx(Q,{children:"Thread"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Command"}),i.jsx(Q,{className:"hidden text-right md:table-cell",children:"Memory"}),i.jsx(Q,{children:"Turn"}),i.jsx(Q,{children:"Starts"}),i.jsx(Q,{className:"hidden md:table-cell",children:"Note"})]})}),i.jsx(st,{children:s.map(a=>{const r=a.turn===fi.label?fi:{label:a.turn,tone:a.turn==="Next"?"info":"neutral"};return i.jsxs(_e,{"data-testid":"queues-waiting",children:[i.jsx(X,{children:a.position}),i.jsxs(X,{children:[i.jsx(h_,{org:e,row:a}),i.jsx("div",{className:"text-muted-foreground text-xs break-all md:hidden",children:[a.command,a.memory].filter(Boolean).join(" · ")})]}),i.jsx(X,{className:"hidden md:table-cell",children:i.jsx(f_,{command:a.command})}),i.jsx(X,{className:"hidden text-right tabular-nums md:table-cell",children:a.memory}),i.jsx(X,{children:i.jsx(we,{variant:r.tone,children:r.label})}),i.jsx(X,{className:"text-muted-foreground text-xs",title:a.basis,children:cE(a)}),i.jsx(X,{className:"hidden md:table-cell",children:a.reason?Da(a.reason):""})]},a.position)})})]})})})]}),i.jsx("p",{className:"text-muted-foreground text-xs",children:vH})]})}function RH({org:e,detail:t,name:n,settings_note:s,subject_label:a,thread_subjects:r,timing:o}){var j;const{queue:l,state:c}=t,d=o?EH(o):void 0,h=oE(o)>0,f=N=>n(N),m=new Map(c.entries.map(N=>[N.ref,N.subject])),p=c.entries.filter(N=>N.turn==="running"),y=c.entries.filter(N=>N.turn!=="running"&&N.batching!=="in_batch"),g=c.batch,b=Math.max(1,p.filter(N=>N.batching!=="in_batch").length),v=g&&l.policy.independent_turns?p.filter(N=>N.batching!=="in_batch"&&N.ref!==g.holder):[],x=c.manager,w=c.freeze,_=((j=l.layer)==null?void 0:j.kind)==="release"?l.layer.stall_hold:void 0,S=_?{who:n(_.by),why:_.reason,until:_.until}:x!=null&&x.hold?{who:n(x.holder,x.holder_subject),why:x.hold.why,until:x.hold.until}:null,k=!g&&p.length===0&&y.length===0;return i.jsxs(yt,{as:"section","aria-labelledby":"queue-title",className:"mt-6 flex shrink-0 flex-col gap-4 p-4","data-testid":"queues-detail",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",{id:"queue-title",className:"text-lg font-semibold",children:l.name}),i.jsx(we,{variant:"neutral",children:eE[l.policy.step]}),i.jsx(we,{variant:"neutral",children:rH[l.management.mode]})]}),l.purpose?i.jsx("p",{className:"text-muted-foreground text-sm",children:l.purpose}):null,o!=null&&o.basis?i.jsx("p",{className:"text-muted-foreground text-xs",children:o.basis}):null,h?i.jsx("p",{className:"text-muted-foreground text-xs",children:nH}):null]}),x?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm","data-testid":"queues-manager",children:[i.jsx(Nz,{className:"text-muted-foreground size-4","aria-hidden":"true"}),i.jsx("span",{className:"text-muted-foreground",children:"Manager"}),i.jsx("span",{className:"font-medium",children:n(x.holder,x.holder_subject)}),i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Lease until ",Xn(x.lease_until),x.serving_until!==void 0?" · serving now":""]})]}):null,w?i.jsxs(pe,{variant:"warning",children:[i.jsx(gz,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Frozen until ",Xn(w.lease_until)]}),i.jsxs(ge,{children:[n(w.holder,w.holder_subject)," froze this queue at ",Xn(w.since),w.label?`: ${w.label}`:"",". Only ",n(w.holder,w.holder_subject),"'s entries start until it thaws."]})]}):null,S?i.jsxs(pe,{variant:"info",children:[i.jsx(Bk,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:["Stall hold until ",Xn(S.until)]}),i.jsxs(ge,{children:[S.who,S.why?`: ${S.why}`:"",". The first entry is not treated as stalled while it lasts."]})]}):null,k?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running, and nothing waits in this queue."}):i.jsxs(i.Fragment,{children:[g?i.jsxs(go,{id:"queue-running",title:"Running turn",side:`Batch opened by ${n(g.holder,g.holder_subject)} at ${Xn(g.opened_at)}`,children:[i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Batch members",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Landing order"}),i.jsx(Q,{children:a}),i.jsx(Q,{children:"Outcome"})]})}),i.jsx(st,{children:g.members.map((N,O)=>{const T=cH(N.outcome);return i.jsxs(_e,{"data-testid":"queues-member",children:[i.jsx(X,{children:O+1}),i.jsx(X,{children:i.jsx(Dh,{org:e,subject:N.subject??m.get(N.ref)??(r?{kind:"thread",id:N.ref}:void 0),link:!r})}),i.jsx(X,{children:i.jsx(we,{variant:T.tone,children:T.label})})]},N.ref)})})]})}),v.length>0?i.jsxs(i.Fragment,{children:[i.jsx("h4",{className:"text-muted-foreground text-xs font-medium",children:"Also running"}),i.jsx(u_,{org:e,entries:v,landing:c.landing,queue_name:l.name,subject_label:a,held:r,label:"Turns running beside the batch",time_of:d})]}):null]}):i.jsx(go,{id:"queue-running",title:p.length>1?"Running turns":"Running turn",children:p.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing running."}):i.jsx(u_,{org:e,entries:p,landing:c.landing,queue_name:l.name,subject_label:a,held:r,label:"Running turns",time_of:d})}),i.jsx(go,{id:"queue-waiting",title:"Waiting",children:y.length===0?i.jsx("p",{className:"text-muted-foreground text-sm",children:"Nothing waits."}):i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsxs(nt,{containerAriaLabel:"Waiting entries",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Position"}),i.jsx(Q,{children:a}),i.jsx(Q,{className:"hidden md:table-cell",children:"Joined"}),i.jsx(Q,{children:"Turn"}),d?i.jsx(Q,{children:"Starts"}):null,i.jsx(Q,{className:"hidden md:table-cell",children:"Note"})]})}),i.jsx(st,{children:y.map((N,O)=>{const T=d==null?void 0:d(N),I=dH(N,(T==null?void 0:T.turn)===fi.label),L=N.subject.hidden?"":N.note??"";return i.jsxs(_e,{"data-testid":"queues-waiting",children:[i.jsx(X,{children:g?b+O+1:N.position}),i.jsx(X,{children:i.jsx(Dh,{org:e,subject:N.subject,link:!r})}),i.jsx(X,{className:"hidden md:table-cell",children:Xn(N.joined_at)}),i.jsx(X,{children:i.jsx(we,{variant:I.tone,children:I.label})}),d?i.jsx(X,{className:"text-muted-foreground text-xs",title:T==null?void 0:T.basis,children:cE(T)}):null,i.jsx(X,{className:"hidden md:table-cell",children:L})]},N.ref)})})]})})})]}),i.jsx(go,{id:"queue-settings",title:"Settings",children:i.jsx("div",{className:"overflow-x-auto rounded-lg border",children:i.jsx(nt,{containerAriaLabel:"Queue settings",children:i.jsx(st,{children:mH(l,f).map(([N,O])=>i.jsxs(_e,{children:[i.jsx(Q,{scope:"row",className:"h-auto w-48 py-2 font-normal",children:N}),i.jsx(X,{children:O})]},N))})})})}),i.jsx("p",{className:"text-muted-foreground text-xs",children:s})]})}const ti="__no_parent__";function dE(e,t){const n=new Set([t]);for(let s=!0;s;){s=!1;for(const a of e)a.parent&&n.has(a.parent)&&!n.has(a.key)&&(n.add(a.key),s=!0)}return n}const $c=(e,t)=>(e.label||e.key).localeCompare(t.label||t.key);function Zn({id:e,label:t,help:n,error:s,children:a}){const r=[n?`${e}-help`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0;return i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:e,children:t}),a(r),n?i.jsx("p",{id:`${e}-help`,className:"text-muted-foreground text-xs",children:n}):null,s?i.jsx("p",{id:`${e}-error`,className:"text-destructive text-sm",children:s}):null]})}function Zg({label:e,children:t}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("span",{className:"text-sm leading-none font-medium",children:e}),i.jsx("span",{className:"text-muted-foreground text-sm break-words",children:t})]})}function m_({id:e,label:t,help:n,checked:s,on_change:a}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsxs("div",{className:"flex items-start gap-2",children:[i.jsx(nl,{id:e,className:"mt-0.5",checked:s,"aria-describedby":n?`${e}-help`:void 0,onCheckedChange:r=>a(r===!0)}),i.jsx(Ie,{htmlFor:e,className:"font-normal",children:t})]}),n?i.jsx("p",{id:`${e}-help`,className:"text-muted-foreground pl-6 text-xs",children:n}):null]})}function uE({id:e,legend:t,help:n,error:s,options:a,checked:r,on_change:o,empty:l,notes:c,scroll:d}){const h=[c!=null&&c.length?`${e}-notes`:null,n?`${e}-help`:null,s?`${e}-error`:null].filter(Boolean).join(" ")||void 0;return i.jsxs("fieldset",{className:"m-0 grid min-w-0 gap-2 border-0 p-0","aria-describedby":h,"aria-invalid":s?!0:void 0,children:[i.jsx("legend",{className:"mb-2 text-sm leading-none font-medium",children:t}),c!=null&&c.length?i.jsxs("div",{id:`${e}-notes`,className:"text-warning flex items-start gap-2 text-xs",children:[i.jsx(jt,{className:"mt-0.5 size-3.5 shrink-0","aria-hidden":"true"}),i.jsx("div",{className:"grid gap-0.5",children:c.map(f=>i.jsx("p",{children:f},f))})]}):null,a.length===0&&l?i.jsx("p",{className:"text-muted-foreground text-sm",children:l}):null,i.jsx("div",{className:d?"grid max-h-[200px] grid-cols-1 gap-2 overflow-y-auto rounded-md border p-3 sm:grid-cols-2":"grid grid-cols-1 gap-2 sm:grid-cols-2",tabIndex:d?0:void 0,role:d?"group":void 0,"aria-label":d?`${t} list`:void 0,children:a.map((f,m)=>i.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[i.jsx(nl,{id:`${e}-${m}`,className:"mt-0.5",checked:r.has(f.value),onCheckedChange:p=>{const y=new Set(r);p===!0?y.add(f.value):y.delete(f.value),o(y)}}),i.jsx(Ie,{htmlFor:`${e}-${m}`,className:"min-w-0 font-normal break-words",children:f.label})]},f.value))}),n?i.jsx("p",{id:`${e}-help`,className:"text-muted-foreground text-xs",children:n}):null,s?i.jsx("p",{id:`${e}-error`,className:"text-destructive text-sm",children:s}):null]})}function Lc({context:e,action:t,title:n="Two-factor sign-in needed",changing:s="Changing the org"}){const a=e.two_factor==="enroll";return i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(mz,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:n}),i.jsxs(ge,{children:[i.jsx("p",{children:a?`Turn on two-factor sign-in in Account Settings, then come back here and ${t}.`:`${s} needs a two-factor sign-in. Sign in again with your authenticator in Account Settings, then come back here and ${t}.`}),i.jsx(U,{asChild:!0,variant:"outline",size:"sm",className:"mt-2 h-auto min-h-8 py-1.5 whitespace-normal text-left",children:i.jsx("a",{href:e.settings_href,target:"_blank",rel:"noreferrer",children:"Open Account Settings in a new tab"})})]})]})}const Ba=e=>e.two_factor==="ok";function ll({refusal:e,context:t,subject:n,action:s,changing:a,authority_title:r}){if((e==null?void 0:e.kind)==="two_factor")return i.jsx(Lc,{context:t,action:s,changing:a,title:`Could not save ${n}`});const o=Ba(t)?null:i.jsx(Lc,{context:t,action:s,changing:a});if(!e)return o;const l=e.kind==="changed"?"The org changed since you opened this":e.kind==="authority"?r??`Could not save ${n}`:null;return i.jsxs(i.Fragment,{children:[o,i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),l?i.jsx(ke,{children:l}):null,i.jsx(ge,{children:e.message})]})]})}function hE({id:e,value:t,on_change:n,none:s,options:a,described_by:r}){return i.jsxs(St,{value:t,onValueChange:n,children:[i.jsx(wt,{id:e,"aria-describedby":r,children:i.jsx(Ct,{placeholder:"Choose a team"})}),i.jsxs(_t,{children:[s?i.jsx(Ue,{value:ti,children:s}):null,a.map(o=>i.jsx(Ue,{value:o.key,children:o.label||o.key},o.key))]})]})}function cl(e){const[t,n]=u.useState(!1),[s,a]=u.useState(null);return{saving:t,refusal:s,set_refusal:a,run:async o=>{n(!0),a(null);try{const l=await o();l?a(l):e()}finally{n(!1)}}}}function dl({saving:e,blocked:t,described_by:n,children:s}){return i.jsx(U,{type:"submit",disabled:e,"aria-disabled":t||void 0,"aria-describedby":t?n:void 0,children:s})}const fE=(e,t)=>t==="hosted"?`Lowercase letters, digits, _ and -, starting with a letter. It names the ${e} in posts, and cannot change later.`:`Lowercase letters, digits, _ and -, starting with a letter. It names the ${e} in posts and in sdlc org, and cannot change later.`;function TH({open:e,chart:t,team:n,save:s,on_close:a,context:r=ul,scope:o="full",parents:l}){var C;const c=r.host==="hosted",[d,h]=u.useState(""),[f,m]=u.useState(""),[p,y]=u.useState(""),[g,b]=u.useState(ti),[v,x]=u.useState({}),{saving:w,refusal:_,set_refusal:S,run:k}=cl(a),j=((C=t.teams.find(M=>M.parent===null))==null?void 0:C.key)??null;u.useEffect(()=>{e&&(h(""),m((n==null?void 0:n.label)??""),y((n==null?void 0:n.description)??""),b((n==null?void 0:n.parent)??(c&&j&&(!l||l.includes(j))?j:ti)),x({}),S(null))},[e,n,S,c,j,l]);const N=M=>{const H=t.teams.find(z=>z.key===M);return H?H.label||H.key:M??""},O=n?dE(t.teams,n.key):new Set,T=[...t.teams].filter(M=>!O.has(M.key)&&(!l||l.includes(M.key))).sort((M,H)=>M.key===j?-1:H.key===j?1:$c(M,H)),I=n?n.label||n.key:"",L=o==="description",$=!Ba(r),A=n?L?"save the description":"save the team":"add the team",D=M=>{if(M.preventDefault(),$)return;if(!n){const K=c?f.trim():d.trim();if(!K){x(c?{label:"Give the team a name."}:{key:"Give the team a key."});return}if(c&&g===ti){x({parent:"Choose the parent team."});return}const oe=c?K:f.trim()||K;k(()=>s({action:"add",kind:"team",key:K,...f.trim()?{label:f.trim()}:{},...p.trim()?{description:p.trim()}:{},...g!==ti?{parent:g}:{}},`Team ${oe} added.`));return}if(!L&&!f.trim()){x({label:c?"Give the team a name.":"Give the team a label."});return}const H=g===ti?null:g,z={...!L&&f.trim()!==n.label.trim()?{label:f.trim()}:{},...p.trim()!==(n.description??"").trim()?{description:p.trim()}:{},...!c&&H!==n.parent?{parent:H}:{}};if(Object.keys(z).length===0){a();return}k(()=>s({action:"edit",kind:"team",key:n.key,...z},L?`Saved the description of ${I}.`:`Team ${f.trim()} saved.`))},E=n?L?`Edit the description of ${I}`:`Edit team ${I}`:"Add team";let R;return L?R="Say what the team works on. Only the description is yours to change here.":c?R=n?"Rename the team or say what it works on.":"Add a team to the organization.":n?R=i.jsxs(i.Fragment,{children:["Its key, ",i.jsx("span",{className:"font-mono",children:n.key}),", names it in posts and in sdlc org and does not change."]}):R="Add a team to this repository's local org.",i.jsx(yn,{open:e,onOpenChange:M=>M||w?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:D,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:E}),i.jsx(kn,{children:R})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:_,context:r,subject:L?"the description":"the team",action:A}),!n&&!c?i.jsx(Zn,{id:"org-team-key",label:"Key",help:fE("team",r.host),error:v.key,children:M=>i.jsx(bt,{id:"org-team-key",className:"font-mono",value:d,autoComplete:"off","aria-invalid":v.key?!0:void 0,"aria-describedby":M,onChange:H=>{h(H.target.value),x({})}})}):null,L&&n?i.jsx(Zg,{label:"Name",children:n.parent?`${I} · under ${N(n.parent)}`:I}):i.jsx(Zn,{id:"org-team-label",label:c?"Name":n?"Label":"Label (optional)",help:c?n?void 0:"Its key is made from the name.":n?void 0:"Shown on the chart; the key when left empty.",error:v.label,children:M=>i.jsx(bt,{id:"org-team-label",value:f,"aria-invalid":v.label?!0:void 0,"aria-describedby":M,onChange:H=>{m(H.target.value),x({})}})}),i.jsx(Zn,{id:"org-team-description",label:L?"Description":"Description (optional)",children:()=>i.jsx(Gn,{id:"org-team-description",rows:3,placeholder:"What the team does",value:p,onChange:M=>y(M.target.value)})}),L?null:c&&n?i.jsx(Zg,{label:"Parent team",children:n.parent?N(n.parent):"None: the organization itself"}):i.jsx(Zn,{id:"org-team-parent",label:"Parent team",help:"Where the team sits; its posts report up through the team above.",error:v.parent,children:M=>i.jsx(hE,{id:"org-team-parent",value:g,on_change:H=>{b(H),x({})},none:c?void 0:"No parent (a root team)",options:T,described_by:M})})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:w,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:w,blocked:$,children:n?w?"Saving…":"Save":w?"Adding…":"Add team"})]})]})})})}const OH=(e,t)=>e.length===t.size&&e.every(n=>t.has(n));function zH({open:e,chart:t,job:n,save:s,on_close:a,context:r=ul}){const[o,l]=u.useState(""),[c,d]=u.useState(""),[h,f]=u.useState(""),[m,p]=u.useState(ti),[y,g]=u.useState(new Set),[b,v]=u.useState(!1),[x,w]=u.useState(!0),[_,S]=u.useState({}),{saving:k,refusal:j,set_refusal:N,run:O}=cl(a);u.useEffect(()=>{e&&(l(""),d((n==null?void 0:n.label)??""),f((n==null?void 0:n.description)??""),p((n==null?void 0:n.parent)??ti),g(new Set((n==null?void 0:n.fills)??[])),v((n==null?void 0:n.requires_person)??!1),w((n==null?void 0:n.escalable)??!0),S({}),N(null))},[e,n,N]);const T=n?dE(t.job_functions,n.key):new Set,I=[...t.job_functions].filter(E=>!T.has(E.key)).sort($c),L=[...t.slots].sort($c).map(E=>({value:E.key,label:E.label||E.key})),$=!Ba(r),A=n?"save the job function":"add the job function",D=E=>{if(E.preventDefault(),$)return;if(!n){if(!o.trim()){S({key:"Give the job function a key."});return}O(()=>s({action:"add",kind:"job_function",key:o.trim(),...c.trim()?{label:c.trim()}:{},...h.trim()?{description:h.trim()}:{},...m!==ti?{parent:m}:{},fills:[...y],requires_person:b,escalable:x},`Job function ${c.trim()||o.trim()} added.`));return}if(!c.trim()){S({label:"Give the job function a label."});return}const R=m===ti?null:m,C={...c.trim()!==n.label.trim()?{label:c.trim()}:{},...h.trim()!==(n.description??"").trim()?{description:h.trim()}:{},...R!==n.parent?{parent:R}:{},...OH(n.fills,y)?{}:{fills:[...y]},...b!==n.requires_person?{requires_person:b}:{},...x!==n.escalable?{escalable:x}:{}};if(Object.keys(C).length===0){a();return}O(()=>s({action:"edit",kind:"job_function",key:n.key,...C},`Job function ${c.trim()} saved.`))};return i.jsx(yn,{open:e,onOpenChange:E=>E||k?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:D,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:n?`Edit job function ${n.label||n.key}`:"Add job function"}),i.jsxs(kn,{children:["Its job description: what it does, the slots it fills and who may hold its posts.",n?i.jsxs(i.Fragment,{children:[" ","Its key, ",i.jsx("span",{className:"font-mono",children:n.key}),", does not change."]}):null]})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:j,context:r,subject:"the job function",action:A}),n?null:i.jsx(Zn,{id:"org-function-key",label:"Key",help:fE("job function",r.host),error:_.key,children:E=>i.jsx(bt,{id:"org-function-key",className:"font-mono",value:o,autoComplete:"off","aria-invalid":_.key?!0:void 0,"aria-describedby":E,onChange:R=>{l(R.target.value),S({})}})}),i.jsx(Zn,{id:"org-function-label",label:n?"Label":"Label (optional)",error:_.label,children:E=>i.jsx(bt,{id:"org-function-label",value:c,"aria-invalid":_.label?!0:void 0,"aria-describedby":E,onChange:R=>{d(R.target.value),S({})}})}),i.jsx(Zn,{id:"org-function-description",label:"Job description (optional)",children:()=>i.jsx(Gn,{id:"org-function-description",rows:3,placeholder:"What this job function does",value:h,onChange:E=>f(E.target.value)})}),i.jsx(Zn,{id:"org-function-parent",label:"Parent function",help:"Its posts report to the post of the parent function.",children:E=>i.jsx(hE,{id:"org-function-parent",value:m,on_change:p,none:"No parent (a root function)",options:I,described_by:E})}),i.jsx(uE,{id:"org-function-fills",legend:"Slots it fills",options:L,checked:y,on_change:g,empty:r.host==="hosted"?"This organization has no slots yet.":"This org has no slots yet; add them with sdlc org add slot."}),i.jsx(m_,{id:"org-function-requires-person",label:"Requires a person",help:"Only a person may hold its posts.",checked:b,on_change:v}),i.jsx(m_,{id:"org-function-escalable",label:"Escalable",help:"When no holder can decide, the decision goes up the reporting line. Off, it waits for a holder of this function.",checked:x,on_change:w})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:k,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:k,blocked:$,children:n?k?"Saving…":"Save":k?"Adding…":"Add job function"})]})]})})})}const MH=/^[a-z][a-z0-9_-]{0,63}$/;function $H(e){return e.toLowerCase().replace(/[^a-z0-9_-]+/g,"-").replace(/^[^a-z]+/,"").slice(0,64).replace(/-+$/,"")}function LH({open:e,chart:t,slot:n,save:s,on_close:a,context:r=ul}){const[o,l]=u.useState(""),[c,d]=u.useState(""),[h,f]=u.useState(!1),[m,p]=u.useState(""),[y,g]=u.useState({}),{saving:b,refusal:v,set_refusal:x,run:w}=cl(a);u.useEffect(()=>{e&&(l((n==null?void 0:n.label)??""),d((n==null?void 0:n.key)??""),f(!1),p((n==null?void 0:n.description)??""),g({}),x(null))},[e,n,x]);const _=!Ba(r),S=n?"save the slot":"add the slot",k=j=>{if(j.preventDefault(),_)return;const N=o.trim();if(n){if(!N){g({label:"Give the slot a label."});return}const T={...N!==(n.label??"").trim()?{label:N}:{},...m.trim()!==(n.description??"").trim()?{description:m.trim()}:{}};if(Object.keys(T).length===0){a();return}w(()=>s({action:"edit",kind:"slot",key:n.key,...T},`Saved slot ${N}.`));return}const O={...N?{}:{label:"Give the slot a label."},...MH.test(c)?t.slots.some(T=>T.key===c)?{key:`Slot ${c} already exists.`}:{}:{key:"Use lowercase letters, digits, _ and -, starting with a letter, at most 64 characters."}};g(O),!(O.label||O.key)&&w(()=>s({action:"add",kind:"slot",key:c,label:N,...m.trim()?{description:m.trim()}:{}},`Added slot ${N}.`))};return i.jsx(yn,{open:e,onOpenChange:j=>j||b?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:k,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:n?`Edit ${n.label||n.key}`:"Add slot"}),i.jsx(kn,{children:"A slot is a workflow role a project fills from its team's posts. Job functions name the slots they fill."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:v,context:r,subject:"the slot",action:S}),i.jsx(Zn,{id:"org-slot-label",label:"Label",help:"How the slot is named on the chart and in project settings.",error:y.label,children:j=>i.jsx(bt,{id:"org-slot-label",value:o,"aria-invalid":y.label?!0:void 0,"aria-describedby":j,onChange:N=>{l(N.target.value),!n&&!h&&d($H(N.target.value)),g({})}})}),n?i.jsx(Zg,{label:"Key",children:i.jsx("span",{className:"font-mono",children:n.key})}):i.jsx(Zn,{id:"org-slot-key",label:"Key",help:"Lowercase letters, digits, _ and -, starting with a letter, at most 64 characters. It can't be changed after you save.",error:y.key,children:j=>i.jsx(bt,{id:"org-slot-key",className:"font-mono",value:c,autoComplete:"off","aria-invalid":y.key?!0:void 0,"aria-describedby":j,onChange:N=>{d(N.target.value),f(!0),g({})}})}),i.jsx(Zn,{id:"org-slot-description",label:"Description (optional)",children:()=>i.jsx(Gn,{id:"org-slot-description",rows:3,placeholder:"What this role does",value:m,onChange:j=>p(j.target.value)})})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:b,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:b,blocked:_,children:n?b?"Saving…":"Save":b?"Adding…":"Add slot"})]})]})})})}function PH({open:e,chart:t,binding:n,names:s,save:a,confirm:r,on_close:o,context:l=ul,hosted:c}){var $;const[d,h]=u.useState(new Set),[f,m]=u.useState(""),[p,y]=u.useState({}),{saving:g,refusal:b,set_refusal:v,run:x}=cl(o),w=(n==null?void 0:n.slot)??null;if(u.useEffect(()=>{!e||!n||(h(new Set(c&&n.source!=="override"?[]:n.posts.map(A=>A.post))),m(n.source==="override"?n.reason??"":""),y({}),v(null))},[e,w,v]),!n)return null;const _=s.slot(n.slot),S=($=t.project)!=null&&$.team?t.teams.find(A=>{var D;return A.key===((D=t.project)==null?void 0:D.team)}):void 0,k=S?S.label||S.key:"the owning team",j=new Set(t.job_functions.filter(A=>A.fills.includes(n.slot)).map(A=>A.key)),N=[...t.posts].map(A=>A.post).sort(s.byPost).map(A=>{const D=j.has(A.split("/")[1]??"")?`${s.post(A)} (fills ${_})`:s.post(A),E=c==null?void 0:c.holders(A);return{value:A,label:c?E?`${D}: ${E}`:`${D} (no holder)`:D}}),O=c?[...d].sort(s.byPost).flatMap(A=>[...j.has(A.split("/")[1]??"")?[]:[`${s.post(A)} is not in the job description of ${_}.`],...c.chain.has(A.split("/")[0]??"")?[]:[`${s.post(A)} is outside ${c.owner} and the teams above it.`]]):[],T=!Ba(l),I=A=>{A.preventDefault();const D={...d.size===0?{posts:"Choose at least one post."}:{},...f.trim()?{}:{reason:"Give the reason for the override."}};y(D),!(D.posts||D.reason||T)&&x(()=>a({action:"bind",slot:n.slot,posts:[...d],reason:f.trim()},`Override of ${_} saved.`))},L=async()=>{await r({title:`Clear the override of ${_}?`,description:c?`${_} goes back to its team's posts: ${c.baseline}. The override and its reason stay in the audit trail.`:"It goes back to the posts its job descriptions name, and its reason is not kept.",action_label:c?"Clear override":"Clear",destructive:!0})&&x(()=>a({action:"unbind",slot:n.slot},`Override of ${_} cleared.`))};return i.jsx(yn,{open:e,onOpenChange:A=>A||g?null:o(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:I,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsxs(Nn,{children:["Override ",_]}),i.jsxs(kn,{children:["Bind ",_," in this project to the posts you choose instead of its"," ",c?"team’s":"job descriptions’"," posts. The override is reported with its reason, who set it and when."]})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[b||T?i.jsx("div",{id:"org-override-refusal",className:"grid gap-4",children:i.jsx(ll,{refusal:b,context:l,subject:"the override",action:c?"save":"save the override",changing:c?"Changing this project’s slots":void 0,authority_title:c?"Your changes were not saved":void 0})}):null,i.jsx(uE,{id:"org-override-posts",legend:"Posts",help:c?`(fills ${_}) marks the posts whose job function fills ${_}.`:"A post outside its job description is marked on the chart.",notes:O,scroll:!!c,error:p.posts,options:N,checked:d,on_change:A=>{h(A),y(D=>({...D,posts:void 0}))}}),i.jsx(Zn,{id:"org-override-reason",label:"Reason",error:p.reason,children:A=>i.jsx(Gn,{id:"org-override-reason",rows:2,placeholder:"Why this slot needs other posts",value:f,"aria-invalid":p.reason?!0:void 0,"aria-describedby":A,onChange:D=>{m(D.target.value),y(E=>({...E,reason:void 0}))}})}),c?null:i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Made as ",i.jsx("span",{className:"font-mono",children:"person:user"}),", who must hold the lead post of ",k," or of a team above it."]})]}),i.jsxs(jn,{className:"mt-6",children:[n.source==="override"?i.jsx(U,{type:"button",variant:"ghost",className:"sm:mr-auto",disabled:g,onClick:()=>void L(),children:"Clear override"}):null,i.jsx(U,{type:"button",variant:"outline",disabled:g,onClick:o,children:"Cancel"}),i.jsx(dl,{saving:g,blocked:T,described_by:"org-override-refusal",children:g?"Saving…":"Save override"})]})]})})})}function IH(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} or ${e[e.length-1]}`}function GH({open:e,chart:t,names:n,save:s,on_close:a,context:r}){var A;const o=t.authority,l=u.useMemo(()=>o?new Set(o.post_pairs):null,[o]),c=D=>!l||l.has(D),d=((A=t.teams.find(D=>D.parent===null))==null?void 0:A.key)??null,h=[...t.teams].filter(D=>!l||[...l].some(E=>E.startsWith(`${D.key}/`))).sort((D,E)=>D.key===d?-1:E.key===d?1:$c(D,E)),[f,m]=u.useState(""),[p,y]=u.useState(""),[g,b]=u.useState({}),{saving:v,refusal:x,set_refusal:w,run:_}=cl(a);u.useEffect(()=>{var D;e&&(m(((D=h[0])==null?void 0:D.key)??""),y(""),b({}),w(null))},[e,w]);const S=new Set(t.posts.filter(D=>D.post.startsWith(`${f}/`)).map(D=>D.post.split("/")[1])),k=[],j=D=>{for(const E of[...t.job_functions].filter(R=>R.parent===D).sort($c))k.push(E),j(E.key)};j(null);const N=k.filter(D=>c(`${f}/${D.key}`)&&!S.has(D.key)),O=f!==""&&N.length===0,T=!Ba(r)||O,I=D=>{if(D.preventDefault(),T)return;const E={...f?{}:{team:"Choose a team."},...p?{}:{job:"Choose a job function."}};b(E),!(E.team||E.job)&&_(()=>s({action:"add",kind:"post",key:`${f}/${p}`},`Added post ${n.job(p)} · ${n.team(f)}.`))},L=O?"Every job function already has a post in this team.":"A team has one post per job function; functions already staffed in this team are left out.",$=(o==null?void 0:o.ask)??[];return i.jsx(yn,{open:e,onOpenChange:D=>D||v?null:a(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:I,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Add post"}),i.jsx(kn,{children:"A post is a job function staffed in a team. People in this post report to the post above it."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:x,context:r,subject:"the post",action:"add the post"}),i.jsx(Zn,{id:"org-post-team",label:"Team",help:"The team the post is in.",error:g.team,children:D=>i.jsxs(St,{value:f,onValueChange:E=>{m(E),y(""),b({})},children:[i.jsx(wt,{id:"org-post-team","aria-describedby":D,"aria-invalid":g.team?!0:void 0,children:i.jsx(Ct,{placeholder:"Choose a team"})}),i.jsx(_t,{children:h.map(E=>i.jsx(Ue,{value:E.key,children:E.label||E.key},E.key))})]})}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Zn,{id:"org-post-function",label:"Job function",help:L,error:g.job,children:D=>i.jsxs(St,{value:p,disabled:O,onValueChange:E=>{y(E),b({})},children:[i.jsx(wt,{id:"org-post-function","aria-describedby":D,"aria-invalid":g.job?!0:void 0,children:i.jsx(Ct,{placeholder:O?"Every job function has a post here":"Choose a job function"})}),i.jsx(_t,{children:N.map(E=>i.jsx(Ue,{value:E.key,children:E.label||E.key},E.key))})]})}),o&&!o.administer?i.jsxs("p",{className:"text-muted-foreground text-xs",children:["Only the job functions directly below a post you hold are listed.",$.length?` For others, ask ${IH($)}.`:""]}):null]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:v,onClick:a,children:"Cancel"}),i.jsx(dl,{saving:v,blocked:T,described_by:O?"org-post-function-help":void 0,children:v?"Adding…":"Add post"})]})]})})})}function HH({open:e,chart:t,post:n,names:s,members:a,save:r,on_close:o,context:l}){const[c,d]=u.useState({state:"loading"}),[h,f]=u.useState(""),[m,p]=u.useState(null),[y,g]=u.useState(-1),{saving:b,refusal:v,set_refusal:x,run:w}=cl(o),_=u.useRef(0),S=u.useCallback(async()=>{const z=_.current+=1;d({state:"loading"});const K=await a();z===_.current&&d(K.ok?{state:"read",members:K.data}:{state:"failed"})},[a]);u.useEffect(()=>{e&&(f(""),p(null),g(-1),x(null),S())},[e,S,x]);const k=t.posts.find(z=>z.post===n);if(!n||!k)return null;const j=s.post(n),N=new Set(k.holders.map(z=>z.id)),T=t.posts.some(z=>z.reports_to===n)&&k.holders.length>0?k.holders[0]:null,I=h.trim().toLowerCase(),L=c.state==="read"?c.members.filter(z=>!N.has(z.id)).filter(z=>!I||[z.label,z.detail,z.email].some(K=>K==null?void 0:K.toLowerCase().includes(I))):[],$=c.state==="read"&&c.members.every(z=>N.has(z.id)),A=c.state==="read"&&!$&&L.length>0,D=A&&y>=0&&y<L.length?L[y]:null,E=z=>`org-holder-option-${z.id}`,R=!Ba(l)||!m||T!==null,C=z=>{if(!A)return;const K=L.length-1,oe=re=>{var Ne,Se;z.preventDefault(),g(re),(Se=(Ne=document.getElementById(E(L[re])))==null?void 0:Ne.scrollIntoView)==null||Se.call(Ne,{block:"nearest"})};z.key==="ArrowDown"?oe(Math.min(D?y+1:0,K)):z.key==="ArrowUp"?oe(D?Math.max(y-1,0):K):z.key==="Home"&&D?oe(0):z.key==="End"&&D?oe(K):z.key==="Enter"&&D&&(m==null?void 0:m.id)!==D.id&&(z.preventDefault(),p(D))},M=T?void 0:m?"Only members of the organization can hold its posts. Members who already hold it are left out.":"Choose a member to add.",H=z=>{z.preventDefault(),!(R||!m)&&w(()=>r({action:"hold",post:n,member:m.id},`Added ${m.label} to ${j}.`))};return i.jsx(yn,{open:e,onOpenChange:z=>z||b?null:o(),children:i.jsx(wn,{children:i.jsxs("form",{onSubmit:H,noValidate:!0,children:[i.jsxs(_n,{children:[i.jsxs(Nn,{children:["Add holder to ",j]}),i.jsx(kn,{children:"The member holds this post and reports as it does."})]}),i.jsxs("div",{className:"mt-4 grid gap-4",children:[i.jsx(ll,{refusal:v,context:l,subject:"the holder",action:"add the holder"}),T?i.jsxs(pe,{variant:"info",id:"org-holder-one",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ge,{children:["This post takes one holder. Remove ",s.member(T)," first, then add the new holder."]})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-holder-member",children:"Member"}),i.jsx(bt,{id:"org-holder-member",role:"combobox","aria-expanded":A,"aria-controls":A?"org-holder-members":void 0,"aria-activedescendant":D?E(D):void 0,"aria-autocomplete":"list","aria-describedby":M?"org-holder-member-help":void 0,placeholder:"Search members by name, username or email",autoComplete:"off",value:h,disabled:T!==null,onChange:z=>{f(z.target.value),g(-1)},onKeyDown:C}),i.jsx("div",{className:"max-h-56 overflow-y-auto rounded-md border",children:c.state==="loading"?i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 px-3 py-2 text-sm",role:"status",children:[i.jsx(vn,{className:"size-4","aria-hidden":"true"}),"Loading members…"]}):c.state==="failed"?i.jsxs("div",{className:"flex flex-wrap items-center gap-2 px-3 py-2",children:[i.jsx("p",{className:"text-destructive text-sm",children:"Could not read the members."}),i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void S(),children:"Retry"})]}):$?i.jsx("p",{className:"text-muted-foreground px-3 py-2 text-sm",children:"Every member already holds this post."}):L.length===0?i.jsxs("p",{className:"text-muted-foreground px-3 py-2 text-sm",children:["No member matches “",h.trim(),"”."]}):i.jsx("ul",{id:"org-holder-members",role:"listbox","aria-label":"Members",className:"m-0 list-none p-1",children:L.map((z,K)=>{const oe=(m==null?void 0:m.id)===z.id,re=(D==null?void 0:D.id)===z.id;return i.jsxs("li",{id:E(z),role:"option","aria-selected":oe,className:`cursor-pointer rounded-sm px-2 py-1.5 ${oe?"bg-accent text-accent-foreground":re?"bg-muted":"hover:bg-muted"} ${re?"ring-ring ring-2 ring-inset":""}`,onClick:()=>{T||(g(K),p(z))},children:[i.jsxs("div",{className:"text-sm font-medium break-words",children:[z.label,z.detail&&L.filter(Ne=>Ne.label===z.label).length>1?` (${z.detail})`:""]}),z.email?i.jsx("div",{className:"text-muted-foreground text-xs break-all",children:z.email}):null]},z.id)})})}),M?i.jsx("p",{id:"org-holder-member-help",className:"text-muted-foreground text-xs",children:M}):null]})]}),i.jsxs(jn,{className:"mt-6",children:[i.jsx(U,{type:"button",variant:"outline",disabled:b,onClick:o,children:"Cancel"}),i.jsx(dl,{saving:b,blocked:R,described_by:T?"org-holder-one":M?"org-holder-member-help":void 0,children:b?"Adding…":"Add holder"})]})]})})})}function mE(e){const[t,n]=u.useState(null),s=u.useRef(t);u.useEffect(()=>{s.current=t},[t]);const a=u.useCallback(c=>{var d;(d=s.current)==null||d.resolve(c),n(null)},[]),r=u.useCallback(c=>new Promise(d=>{var h;(h=s.current)==null||h.resolve(!1),n({...c,resolve:d})}),[]);u.useEffect(()=>()=>{var c;return(c=s.current)==null?void 0:c.resolve(!1)},[]);const o=!Ba(e),l=i.jsx(bf,{open:t!==null,onOpenChange:c=>c?null:a(!1),children:i.jsxs(yf,{children:[i.jsxs(wf,{children:[i.jsx(jf,{children:t==null?void 0:t.title}),i.jsx(Nf,{className:"whitespace-pre-line",children:t==null?void 0:t.description})]}),t&&o?i.jsx(Lc,{context:e,action:t.action}):null,i.jsxs(_f,{children:[i.jsx(Ev,{children:(t==null?void 0:t.cancel_label)??"Cancel"}),i.jsx(GS,{variant:t!=null&&t.destructive?"destructive":"default","aria-disabled":o||void 0,onClick:c=>{if(o){c.preventDefault();return}a(!0)},children:t==null?void 0:t.action_label})]})]})});return{confirm:r,confirm_dialog:l}}function Do({label:e,on_edit:t,on_remove:n,items:s}){const a=s??[...t?[{label:"Edit",on_select:t}]:[],...n?[{label:"Remove",on_select:n,destructive:!0}]:[]];return i.jsxs(zf,{children:[i.jsx(Mf,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon",className:"-my-1 shrink-0","aria-label":`More actions for ${e}`,children:i.jsx(xv,{className:"size-3.5","aria-hidden":"true"})})}),i.jsx(bd,{align:"end",children:a.map(r=>i.jsx(Uo,{className:r.destructive?"text-destructive focus:text-destructive":void 0,onSelect:r.on_select,children:r.label},r.label))})]})}function VH({label:e,message:t,bound:n,on_dismiss:s}){return i.jsxs(pe,{variant:"destructive",role:"alert",className:"mb-3",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsxs(ke,{children:[e," was not removed"]}),i.jsxs(ge,{children:[i.jsx("p",{children:t}),n!=null&&n.projects.length?i.jsx("ul",{role:"list",className:"bg-card text-foreground m-0 mt-2 grid list-none gap-3 rounded-md border p-3",children:n.projects.map(a=>i.jsxs("li",{className:"grid gap-0.5",children:[i.jsxs("a",{className:"text-primary text-sm underline underline-offset-2",href:a.href,children:["Settings of ",a.name]}),i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Override set by ",a.set_by??"a former member"]})]},a.href))}):null,n&&n.more>0?i.jsxs("p",{className:"mt-2",children:["And ",n.more," more ",n.more===1?"project":"projects",". Clear these and try again to see the rest. An org owner can open any project you cannot."]}):null,i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:s,children:"Dismiss"})]})]})}const ul={host:"local",two_factor:"ok",settings_href:""},Eh={open:{label:"Open",tone:"info"},accepted:{label:"Accepted",tone:"success"},rejected:{label:"Rejected",tone:"error"},withdrawn:{label:"Withdrawn",tone:"neutral"}},UH={added:{label:"Added",tone:"success"},changed:{label:"Changed",tone:"warning"},removed:{label:"Removed",tone:"error"}},BH={team:["team","teams"],job_function:["job function","job functions"],slot:["slot","slots"],post:["post","posts"],fill:["fill","fills"]},WH=["team","job_function","slot","post","fill"];function pb(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function FH(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} or ${e[e.length-1]}`}function p_(e){return e.charAt(0).toLowerCase()+e.slice(1)}function pa(e){const t=s=>pb(WH.filter(a=>e[a][s]>0).map(a=>{const r=e[a][s];return`${r} ${BH[a][r===1?0:1]}`}));return[["Adds","adds",t("added")],["Changes","changes",t("changed")],["Removes","removes",t("removed")]].filter(([,,s])=>s).map(([s,a,r],o)=>`${o===0?s:a} ${r}`).join("; ")||"No changes"}function mi(e){return new Date(e).toLocaleDateString("en-GB",{day:"numeric",month:"short",year:"numeric"})}function qH(e){const t=e.requested_at?`Proposed by ${e.requested_by} on ${mi(e.requested_at)}`:`Proposed by ${e.requested_by}`;return e.status==="open"||!e.decided_at?t:`${t} · ${Eh[e.status].label} by ${e.decided_by??"a former member"} on ${mi(e.decided_at)}`}function YH({source:e}){return i.jsxs("span",{className:"inline-flex min-w-0 max-w-full items-center gap-1","data-testid":"org-proposal-source",children:[i.jsx("span",{className:"shrink-0",children:"From package"}),e.href?i.jsx("a",{className:"min-h-6 min-w-0 break-words leading-6 text-primary underline underline-offset-2",href:e.href,children:e.label}):i.jsx("span",{className:"min-w-0 break-words text-foreground",children:e.label}),e.withdrawn&&e.readable!==!1?i.jsx(we,{className:"shrink-0",variant:"warning",children:"Version withdrawn"}):null]})}const XH={team:"team",job_function:"job function",slot:"slot"};function pE(e,t){return e==="own"?"this org's package":e==="softwaredlc"?"SoftwareDLC's package":t?`another organization's package (${t})`:"another organization's package"}function KH(e){return e&&`${e[0].toUpperCase()}${e.slice(1)}`}function Pc({children:e}){return i.jsx("span",{className:"font-mono",children:e})}function cc({title:e,heading:t="strong",children:n}){return i.jsxs("div",{className:"grid gap-1",children:[i.jsx("h3",{className:t==="muted"?"text-muted-foreground text-sm font-medium":"text-sm font-semibold",children:e}),i.jsx("div",{className:"grid gap-1 text-sm break-words",children:n})]})}function ZH(e){const t=XH[e.kind],n=i.jsx(Pc,{children:e.key??e.label}),s=e.org_key?i.jsx(Pc,{children:e.org_key}):e.org_label,a=i.jsxs(i.Fragment,{children:[` If it is the same ${t}, give it the key `,s," in the package and publish again."]});return e.reason==="key"?i.jsxs(i.Fragment,{children:[n,` will be added as a new ${t}; its key is close to the org's `,s,` (${e.org_label}).`,a]}):i.jsxs(i.Fragment,{children:[n,` will be added as a new ${t}; the org's `,s,` has the same name ${e.label}.`,a]})}function gE({matches:e}){return i.jsxs(i.Fragment,{children:[e.matches.map(t=>i.jsx("p",{"data-testid":"org-package-match",children:ZH(t)},`${t.kind}:${t.key??t.label}:${t.org_key??t.org_label}`)),e.truncated?i.jsx("p",{children:"More may match; check the chart."}):null]})}function g_(e){return e?i.jsxs(i.Fragment,{children:["under ",i.jsx(Pc,{children:e})]}):"at the top level"}function Qg(e){return e.field==="name"?i.jsxs(i.Fragment,{children:[i.jsx(Pc,{children:e.key}),` keeps its name ${e.org??""}; the package names it ${e.package??""}. Propose a rename on the chart, or change the package.`]}):i.jsxs(i.Fragment,{children:[i.jsx(Pc,{children:e.key})," stays ",g_(e.org),"; the package has it ",g_(e.package),". Change the package to propose this: team moves are not available in a proposal."]})}const er=e=>`${e.kind}:${e.key}:${e.field}:${e.org??""}:${e.package??""}`;function xE({items:e}){return i.jsx(i.Fragment,{children:e.map(t=>i.jsx("p",{"data-testid":"org-package-not-proposed",children:Qg(t)},er(t)))})}function QH({placements:e}){return i.jsx(i.Fragment,{children:e.map(t=>i.jsx("p",{"data-testid":"org-package-placement",children:t.under?`${t.name} will be added under ${t.under.name}.`:`${t.name} will be added at the top level.`},t.key??t.name))})}function gb(e){return e==="key"?"by API key":"in the app"}function JH(e,t){const[n,s]=u.useState(e?{state:"loading"}:{state:"off"});return u.useEffect(()=>{if(!e||!t){e||s({state:"off"});return}let a=!0;return e.list().then(r=>{a&&(r.ok?s({state:"read",proposals:r.data}):r.refusal.status===404||r.refusal.reason==="not_found"?s({state:"off"}):s({state:"failed",message:r.refusal.message}))},()=>{a&&s({state:"failed",message:"Try again in a moment."})}),()=>{a=!1}},[e,t]),n}function x_({proposal:e,on_open:t}){const n=Eh[e.status];return i.jsxs("li",{className:"border-b px-4 py-2.5 last:border-b-0","data-testid":"org-proposal",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(U,{type:"button",variant:"link",size:"sm",className:"h-auto p-0 text-left whitespace-normal",onClick:t,children:e.title}),i.jsx(we,{variant:n.tone,children:n.label})]}),i.jsxs("p",{className:"text-muted-foreground mt-1 text-xs",children:[e.status==="open"?`Proposed by ${e.requested_by} on ${mi(e.requested_at)}`:`${n.label} by ${e.decided_by??"a former member"} on ${mi(e.decided_at??e.requested_at)}`,e.via==="key"?" by API key":null,e.source?` · From ${e.source.label}`:null,` · ${pa(e.counts)}`]})]})}const eV="Changes members propose to the org's teams, job functions, posts and slots. Nothing changes until someone who may make the change accepts it.";function tV({listed:e,on_propose:t,on_propose_package:n,on_open:s}){const[a,r]=u.useState(!1);if(e.state==="off"||e.state==="loading")return null;const o=e.state==="read"?e.proposals:[],l=o.filter(d=>d.status==="open"),c=o.filter(d=>d.status!=="open");return i.jsxs("section",{"aria-labelledby":"org-chart-proposals",className:"mt-6 min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[i.jsxs("div",{className:"min-w-0 flex-1 basis-64",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("h2",{id:"org-chart-proposals",className:"text-lg font-semibold",children:"Proposals"}),l.length?i.jsx(we,{variant:"info",children:`${l.length} open`}):null]}),i.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:eV})]}),i.jsxs("div",{className:"flex flex-wrap gap-2",children:[i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:t,children:[i.jsx(jg,{className:"size-4","aria-hidden":"true"}),"Propose a change"]}),n?i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:n,children:[i.jsx(cf,{className:"size-4","aria-hidden":"true"}),"Propose from a package…"]}):null]})]}),i.jsxs("div",{className:"mt-3 grid gap-2",children:[e.state==="failed"?i.jsxs("p",{className:"text-destructive text-sm",role:"alert",children:["Could not read the proposals. ",e.message]}):null,e.state==="read"&&o.length===0?i.jsxs(yt,{className:"flex flex-col items-center gap-2 p-6 text-center",children:[i.jsx(jg,{className:"text-muted-foreground size-5","aria-hidden":"true"}),i.jsx("p",{className:"text-sm font-medium",children:"No proposals yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Propose a change to the org's structure for someone with the authority to accept."})]}):null,l.length?i.jsx(yt,{className:"overflow-hidden",children:i.jsx("ul",{role:"list",className:"m-0 list-none p-0","aria-label":"Open proposals",children:l.map(d=>i.jsx(x_,{proposal:d,on_open:()=>s(d)},d.id))})}):null,c.length?i.jsxs("div",{children:[i.jsxs(U,{type:"button",variant:"ghost",size:"sm","aria-expanded":a,"aria-controls":"org-chart-proposals-decided",onClick:()=>r(d=>!d),children:[a?i.jsx(rf,{className:"size-4","aria-hidden":"true"}):i.jsx(ld,{className:"size-4","aria-hidden":"true"}),`Decided (${c.length})`]}),a?i.jsx(yt,{className:"mt-2 overflow-hidden",children:i.jsx("ul",{id:"org-chart-proposals-decided",role:"list",className:"m-0 list-none p-0","aria-label":"Decided proposals",children:c.map(d=>i.jsx(x_,{proposal:d,on_open:()=>s(d)},d.id))})}):null]}):null]})]})}const nV="Nothing you change here is saved to the organization. Submit the proposal for review, or discard it. A proposal can add teams but not rename, move or remove them, and it never changes who holds a post.";function sV({draft:e,on_submit:t,on_discard:n}){var c;const s=((c=e.moved)==null?void 0:c.state)==="conflict"?e.moved.names:null,a=!!e.moved,r=e.total===0?"No changes yet":`${e.total} ${e.total===1?"change":"changes"}`,o=e.total===0||!!s,l=a?jt:jg;return i.jsxs(pe,{variant:a?"warning":"info",role:"status",className:"mt-6",children:[i.jsx(l,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:a?"The org changed while you drafted":"You are drafting a proposal"}),i.jsxs(ge,{children:[i.jsx("p",{id:"org-draft-why",children:s?`The org changed what your draft changes: ${pb(s)}. Discard the draft and start again from the org as it is now.`:a?"We moved your draft onto the org as it is now and kept your changes. Check the chart, then submit again.":nV}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[i.jsx(U,{type:"button",size:"sm","aria-disabled":o||void 0,"aria-describedby":o?s?"org-draft-why":"org-draft-count":void 0,onClick:()=>o?void 0:t(),children:"Submit proposal"}),i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:n,children:"Discard draft"}),i.jsx("span",{id:"org-draft-count",className:"text-muted-foreground text-xs",children:r})]})]})]})}const vE={proposal_empty:"The proposal changes nothing in the org."};function iV(e,t){const n=`${e.coordinate} ${e.version}`;if(t.code==="proposal_duplicate"&&t.duplicate){const{duplicate:s}=t;return`${s.requested_by} already proposed this version: '${s.title}', opened ${gb(s.via)}.`}return t.code==="package_version_withdrawn"?t.newest_version?`${n} was withdrawn. Choose ${t.newest_version}, its newest usable version.`:`${n} was withdrawn. It has no usable version now.`:t.code==="not_found"||t.reason==="not_found"?"This package or version can no longer be read.":vE[t.code??""]??t.message}function aV({open:e,draft:t,submit:n,on_close:s,on_done:a,on_open_proposal:r}){const[o,l]=u.useState(""),[c,d]=u.useState(""),[h,f]=u.useState(null),[m,p]=u.useState(null),[y,g]=u.useState(null),b=t.package,[v,x]=u.useState(!1),w=u.useRef(!1);u.useEffect(()=>{e&&(f(null),p(null),g(null))},[e]);const _=async S=>{if(S.preventDefault(),w.current)return;const k=o.trim();if(!k||k.length>200){f("Give the proposal a title of at most 200 characters.");return}f(null),p(null),g(null),x(!0),w.current=!0;try{const j=await n({title:k,...c.trim()?{note:c.trim()}:{}});if(!j.ok){p(b?iV(b,j.refusal):vE[j.refusal.code??""]??j.refusal.message),b&&j.refusal.code==="proposal_duplicate"&&g(j.refusal.duplicate??null);return}j.data.state==="proposed"&&(l(""),d("")),a(j.data,k)}finally{w.current=!1,x(!1)}};return i.jsx(yn,{open:e,onOpenChange:S=>S?null:s(),children:i.jsx(wn,{className:"sm:max-w-lg",children:i.jsxs("form",{onSubmit:S=>void _(S),className:"grid gap-4",noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Submit proposal"}),i.jsx(kn,{children:"Someone who may make these changes reviews it. Nothing in the organization changes until it is accepted."})]}),m?i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not submit the proposal"}),i.jsxs(ge,{children:[i.jsx("p",{children:m}),y&&r?i.jsx("div",{className:"mt-2",children:i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>r(y),children:"Open proposal"})}):null]})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-proposal-title",children:"Title"}),i.jsx(bt,{id:"org-proposal-title",value:o,maxLength:200,"aria-invalid":h?!0:void 0,"aria-describedby":h?"org-proposal-title-error":void 0,onChange:S=>l(S.target.value)}),h?i.jsx("p",{id:"org-proposal-title-error",className:"text-destructive text-sm",children:h}):null]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-proposal-note",children:"Note (optional)"}),i.jsx(Gn,{id:"org-proposal-note",value:c,rows:3,maxLength:4e3,placeholder:"Why the org should make this change","aria-describedby":"org-proposal-note-help",onChange:S=>d(S.target.value)}),i.jsx("p",{id:"org-proposal-note-help",className:"text-muted-foreground text-xs",children:"At most 4000 characters."})]}),i.jsx("p",{className:"text-muted-foreground text-xs break-words",children:b?`From ${b.coordinate} ${b.version} · ${pa(t.counts)}`:pa(t.counts)}),i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:s,children:"Cancel"}),i.jsxs(U,{type:"submit","aria-disabled":v||void 0,children:[v?i.jsx(vn,{className:"size-4","aria-hidden":"true"}):null,v?"Submitting…":"Submit proposal"]})]})]})})})}const rV=[{kind:"team",title:"Teams"},{kind:"job_function",title:"Job functions"},{kind:"slot",title:"Slots"},{kind:"post",title:"Posts"},{kind:"fill",title:"Fills"}];function oV({entry:e,decided:t}){const n=!t&&e.state==="settled",s=UH[e.change];return i.jsxs("li",{className:"grid gap-1 border-b py-2","data-testid":"org-proposal-entry",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[n&&e.change==="added"?null:i.jsx(we,{variant:s.tone,children:s.label}),i.jsx("span",{className:"text-sm font-medium",children:e.name}),n?i.jsx(we,{variant:"neutral",children:"Already in the org"}):null,!t&&e.state==="conflict"?i.jsx(we,{variant:"error",children:"Changed in the org since"}):null]}),[...e.where,...e.fields,...!t&&e.now?[e.now]:[]].map(a=>i.jsx("p",{className:"text-muted-foreground text-xs break-words",children:a},a))]})}function v_(e,t){if(t.code==="proposal_conflict"&&e){const n=e.entries.filter(s=>s.state==="conflict").map(s=>s.name);if(n.length){const s=`The org changed what this proposal changes: ${pb(n)}.`,a=e.proposal.source&&!e.proposal.source.withdrawn?e.proposal.source:void 0;if(a)return e.proposal.mine?`${s} Withdraw it, then propose it again.`:e.may_reject?`${s} Reject it, then propose ${a.label} again.`:`${s} You can ask ${e.proposal.requested_by} to withdraw it and propose ${a.label} again.`;if(e.proposal.mine)return`${s} Withdraw it and propose again from the org as it is now.`;const r=`ask ${e.proposal.requested_by} to withdraw it and propose again.`;return e.may_reject?`${s} Reject it, or ${r}`:`${s} You can ${r}`}}return t.code==="revision_conflict"?"Someone else changed the org. We read it again; check the proposal and accept again.":t.message}function lV({source:e,via:t}){const n=Ga(),s=e.content_hash,a=async()=>{if(s)try{await navigator.clipboard.writeText(s),n.success("Copied the content hash.")}catch{n.error("Could not copy the content hash. Select it in the tooltip instead.")}},r=e.readable!==!1&&e.owner,o=r&&e.published_at?` on ${mi(e.published_at)}`:"",l=[r?KH(pE(e.owner,e.organization_name)):null,r&&e.published_by_name?`published by ${e.published_by_name}${o}`:o?`published${o}`:null,t?`proposed ${gb(t)}`:null].filter(Boolean),c=s?s.replace(/^sha256:/,"").slice(0,7):"";return i.jsxs("p",{className:"text-muted-foreground text-xs break-words","data-testid":"org-proposal-provenance",children:[s?i.jsxs(i.Fragment,{children:[i.jsxs(wd,{children:[i.jsx(_d,{asChild:!0,children:i.jsx("span",{className:"font-mono",tabIndex:0,children:c})}),i.jsx(ol,{className:"break-all font-mono",children:s})]}),i.jsx(U,{type:"button",variant:"ghost",size:"xs-icon",className:"mx-0.5 align-middle","aria-label":"Copy content hash",onClick:()=>void a(),children:i.jsx(gv,{className:"size-3.5","aria-hidden":"true"})})," · "]}):null,l.join(" · ")]})}function cV(e){var a,r;const t=((a=e.proposal.source)==null?void 0:a.newest_version)??null,n="There is no usable version now.";if(e.may_reject&&!e.proposal.mine)return t?`Reject it, then propose ${t} if the org still wants it.`:`Reject it. ${n}`;if(e.proposal.mine)return t?`Withdraw it, then propose ${t}.`:`Withdraw it. ${n}`;const s=(r=e.ask)!=null&&r.length?FH(e.ask):"an org admin";return t?`Ask ${s} to reject it.`:`Ask ${s} to reject it. ${n}`}function dV(e){var r,o;const t=(r=e.source)==null?void 0:r.withdrawn_at;if(!((o=e.source)!=null&&o.withdrawn)||!t)return null;const n=`Version withdrawn ${mi(t)}`;if(!e.decided_at)return`${n}.`;const s=Date.parse(t)<Date.parse(e.decided_at)?"before":"after",a=e.status==="accepted"?"this proposal was accepted":e.status==="rejected"?"it was rejected":"it was withdrawn";return`${n}, ${s} ${a}.`}function uV({since:e}){const{previewed:t,opened:n}=e;if(t.revision===n.revision)return null;const s=new Set(t.not_proposed.map(er)),a=new Set(n.not_proposed.map(er)),r=n.not_proposed.filter(d=>!s.has(er(d))),o=t.not_proposed.filter(d=>!a.has(er(d))),c=pa(t.counts)===pa(n.counts)&&r.length===0&&o.length===0;return i.jsxs(pe,{variant:"info",role:"status","data-testid":"org-proposal-since-preview",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"The org changed since the preview"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[`This proposal opened at revision ${n.revision}; you previewed it at revision ${t.revision}, so its change was worked out again.`,c?" The counts are the same as previewed.":` Previewed: ${p_(pa(t.counts))}. Opened: ${p_(pa(n.counts))}.`]}),r.map(d=>i.jsxs("p",{children:["Now not part of this proposal: ",Qg(d)]},`now-not:${er(d)}`)),o.map(d=>i.jsxs("p",{children:["Now part of this proposal: ",Qg(d)]},`now:${er(d)}`))]})]})}function hV({proposal:e,contract:t,context:n,check_two_factor:s,on_close:a,on_decided:r,since:o=null,on_preview_version:l}){const[c,d]=u.useState(null),[h,f]=u.useState(null),[m,p]=u.useState(null),[y,g]=u.useState(!1),[b,v]=u.useState(null),[x,w]=u.useState("ok"),[_,S]=u.useState(null),[k,j]=u.useState(""),N=(e==null?void 0:e.id)??null,O=u.useRef(N);O.current=N;const T=u.useCallback(async()=>{if(!N)return;const W=await t.read(N);O.current===N&&(W.ok?(d(W.data),f(null)):f(W.refusal.message))},[t,N]);u.useEffect(()=>{if(d(null),f(null),p(null),g(!1),j(""),!N)return;T(),s().then(w);const W=()=>void s().then(se=>O.current===N&&w(se));return window.addEventListener("focus",W),()=>window.removeEventListener("focus",W)},[N,T,s]);const I=(c==null?void 0:c.proposal)??e,L=(I==null?void 0:I.title)??"",$=(I==null?void 0:I.status)==="open",A=(c==null?void 0:c.entries.some(W=>W.state==="conflict"))??!1,D=!!c&&(c.may_accept||c.may_reject),E=x==="ok",R={...n,two_factor:x},C=async W=>{if(N){v(W),p(null);try{const se=W==="accept"?await t.accept(N):W==="reject"?await t.reject(N,k.trim()||void 0):await t.withdraw(N);if(se.ok){S(null),r(W==="accept"?`Accepted ${L}.`:W==="reject"?`Rejected ${L}.`:`Withdrew ${L}.`);return}if(S(null),se.refusal.code==="mfa_challenge_required"||se.refusal.code==="mfa_enrollment_required"){w(se.refusal.code==="mfa_enrollment_required"?"enroll":"challenge");return}W==="accept"&&g(!0);const Z=await t.read(N);if(O.current!==N)return;const de=Z.ok?Z.data:c;Z.ok&&d(Z.data),p({title:`${L} was not ${W==="accept"?"accepted":W==="reject"?"rejected":"withdrawn"}`,message:v_(de,se.refusal)})}finally{v(null)}}},M=c&&A&&!m?v_(c,{code:"proposal_conflict",message:""}):null,H=(c==null?void 0:c.proposal.source)??null,z=!!H&&H.readable!==!1,K=$&&!!c&&z&&!!(H!=null&&H.withdrawn),oe=(H==null?void 0:H.newest_version)??null,re=$&&c&&c.may_reject&&!c.may_accept&&!A&&!K?c.accept_refusal??null:null,Ne=!E||A||!!re||K||b!==null,Se=[E?null:"org-proposal-two-factor",A?"org-proposal-refusal":null,re?"org-proposal-accept-refusal":null,K?"org-proposal-withdrawn":null].filter(Boolean).join(" "),ae=!$&&c&&z?dV(c.proposal):null,F=H?(c==null?void 0:c.not_proposed)??[]:[],ie=$&&H?(c==null?void 0:c.possible_matches)??null:null;return i.jsxs(i.Fragment,{children:[i.jsx(yn,{open:e!==null,onOpenChange:W=>W?null:a(),children:i.jsxs(wn,{className:"flex max-h-[90vh] flex-col overflow-hidden sm:max-w-2xl",children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:L}),i.jsx(kn,{asChild:!0,children:i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[I?i.jsx(we,{variant:Eh[I.status].tone,children:Eh[I.status].label}):null,i.jsx("span",{children:I?qH(I):null}),c!=null&&c.proposal.source?i.jsx(YH,{source:c.proposal.source}):null]})}),H?i.jsx(lV,{source:H,via:c==null?void 0:c.proposal.via}):null,H&&!z?i.jsx("p",{className:"text-muted-foreground text-xs",children:"You can't read this package, so its version's state isn't shown."}):null,ae?i.jsx("p",{className:"text-muted-foreground text-xs",children:ae}):null]}),i.jsxs("div",{className:"-mx-1 grid min-h-0 flex-1 gap-4 overflow-y-auto px-1","data-testid":"org-proposal-body",children:[o?i.jsx(uV,{since:o}):null,K&&c?i.jsxs(pe,{id:"org-proposal-withdrawn",variant:"warning",role:"status",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This proposal can't be accepted"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[H!=null&&H.withdrawn_at?`Version withdrawn ${mi(H.withdrawn_at)}, after this proposal opened; it can't be accepted.`:"Its version was withdrawn after this proposal opened; it can't be accepted."," ",cV(c)]}),oe&&(H!=null&&H.package_id)&&l?i.jsx("div",{className:"mt-2",children:i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:()=>l({package_id:H.package_id,version:oe}),children:[i.jsx(cf,{className:"size-4","aria-hidden":"true"}),`Preview ${oe}`]})}):null]})]}):null,I!=null&&I.note?i.jsx("p",{className:"text-sm whitespace-pre-line",children:I.note}):null,I!=null&&I.decision_note?i.jsxs("div",{className:"grid gap-1",children:[i.jsx("span",{className:"text-sm font-medium",children:"Decision note"}),i.jsx("p",{className:"text-muted-foreground text-sm whitespace-pre-line",children:I.decision_note})]}):null,h?i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not read the proposal"}),i.jsx(ge,{children:i.jsx("p",{children:h})})]}):null,!c&&!h?i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:"Reading the proposal…"}):null,c?rV.map(W=>{const se=c.entries.filter(Z=>Z.kind===W.kind);return se.length?i.jsxs("div",{className:"grid",children:[i.jsx("h3",{className:"text-muted-foreground text-sm font-medium",children:W.title}),i.jsx("ul",{role:"list",className:"m-0 list-none p-0",children:se.map(Z=>i.jsx(oV,{entry:Z,decided:!$},`${Z.kind}:${Z.name}`))})]},W.kind):null}):null,ie&&ie.matches.length?i.jsx(cc,{title:"Possible matches",heading:"muted",children:i.jsx(gE,{matches:ie})}):null,F.length?i.jsx(cc,{title:"Not part of this proposal",heading:"muted",children:i.jsx(xE,{items:F})}):null,$&&c&&!D&&c.decide_refusal?i.jsxs(pe,{variant:"info",role:"status",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can't accept or reject this proposal"}),i.jsx(ge,{children:i.jsx("p",{children:c.decide_refusal})})]}):null,re?i.jsxs(pe,{id:"org-proposal-accept-refusal",variant:"info",role:"status",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"You can't accept this proposal"}),i.jsx(ge,{children:i.jsx("p",{children:re})})]}):null,$&&D&&!E?i.jsx("div",{id:"org-proposal-two-factor",children:i.jsx(Lc,{context:R,action:"decide the proposal",changing:"Accepting or rejecting a proposal"})}):null,m||M?i.jsxs(pe,{id:"org-proposal-refusal",variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:(m==null?void 0:m.title)??(y?`${L} was not accepted`:`${L} can't be accepted`)}),i.jsx(ge,{children:i.jsx("p",{children:(m==null?void 0:m.message)??M})})]}):null]}),i.jsxs(jn,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:a,children:"Close"}),$&&(c!=null&&c.may_withdraw)?i.jsx(U,{type:"button",variant:"outline",onClick:()=>S("withdraw"),children:"Withdraw proposal"}):null,$&&(c!=null&&c.may_reject)?i.jsx(U,{type:"button",variant:"outline",onClick:()=>S("reject"),children:"Reject"}):null,$&&c&&(c.may_accept||c.may_reject&&(A||re||K))?i.jsxs(U,{type:"button","aria-disabled":Ne||void 0,"aria-describedby":Se||void 0,onClick:()=>Ne?void 0:void C("accept"),children:[b==="accept"?i.jsx(vn,{className:"size-4","aria-hidden":"true"}):null,b==="accept"?"Accepting…":"Accept"]}):null]})]})}),i.jsx(bf,{open:_!==null,onOpenChange:W=>W?null:S(null),children:i.jsxs(yf,{children:[i.jsxs(wf,{children:[i.jsx(jf,{children:_==="reject"?`Reject ${L}?`:`Withdraw ${L}?`}),i.jsx(Nf,{children:_==="reject"?`${(I==null?void 0:I.requested_by)??"The requester"} sees your note on the proposal.`:"Nobody can accept it after this."})]}),_==="reject"&&!E?i.jsx("div",{id:"org-proposal-reject-two-factor",children:i.jsx(Lc,{context:R,action:"reject the proposal",changing:"Accepting or rejecting a proposal"})}):null,_==="reject"?i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-proposal-reject-note",children:"Note (optional)"}),i.jsx(Gn,{id:"org-proposal-reject-note",value:k,rows:2,maxLength:4e3,placeholder:"Why you are rejecting it",onChange:W=>j(W.target.value)})]}):null,i.jsxs(_f,{children:[i.jsx(Ev,{children:"Cancel"}),_==="reject"?i.jsx(U,{type:"button",variant:"destructive","aria-disabled":!E||b!==null||void 0,"aria-describedby":E?void 0:"org-proposal-reject-two-factor",onClick:()=>!E||b?void 0:void C("reject"),children:b==="reject"?"Rejecting…":"Reject proposal"}):i.jsx(U,{type:"button","aria-disabled":b!==null||void 0,onClick:()=>b?void 0:void C("withdraw"),children:b==="withdraw"?"Withdrawing…":"Withdraw"})]})]})})]})}const b_="Packages you can't read aren't listed. A read grant to a team reaches its own members, not its sub-teams; ask an org admin or the package's publisher for read access.",fV=100,mV=20;function pV(e){if(!e.truncated)return null;const t=e.packages.length>=fV,n=e.packages.some(s=>s.versions.length>=mV);return t&&n?"Showing the first 100 packages and each package's 20 newest versions":n?"Showing each package's 20 newest versions":"Showing the first 100 packages"}function gV(e){return[e.status==="deprecated"?`${e.version} · Deprecated`:e.version,e.published_at?mi(e.published_at):null,e.published_by_name??null].filter(Boolean).join(" · ")}function xV(e,t){return e.code==="package_version_withdrawn"?e.newest_version?`${t} was withdrawn. Choose ${e.newest_version}, its newest usable version.`:`${t} was withdrawn. It has no usable version now.`:e.code==="not_found"||e.reason==="not_found"?"This package or version can no longer be read.":e.message}function vV({open:e,contract:t,packages_href:n,initial:s,preview:a,on_close:r,on_previewed:o}){const[l,c]=u.useState({state:"loading"}),[d,h]=u.useState(""),[f,m]=u.useState(""),[p,y]=u.useState(!1),[g,b]=u.useState(null),v=u.useRef(0),x=u.useCallback(async()=>{var R;const L=v.current+=1;c({state:"loading"}),b(null),y(!1);const $=t.packageChoices?await t.packageChoices():{ok:!1,refusal:{message:"This organization offers no package choices."}};if(L!==v.current)return;if(!$.ok){c({state:"failed",message:$.refusal.message});return}const A=$.data;c({state:"read",choices:A});const D=s&&A.packages.find(C=>C.package_id===s.package_id)||A.packages[0];h((D==null?void 0:D.package_id)??"");const E=s&&D&&D.package_id===s.package_id?D.versions.find(C=>C.version===s.version):void 0;m((E==null?void 0:E.version)??((R=D==null?void 0:D.versions[0])==null?void 0:R.version)??"")},[t,s]);u.useEffect(()=>{if(!e){v.current+=1,y(!1);return}x()},[e,x]);const w=l.state==="read"?l.choices:null,_=(w==null?void 0:w.packages.find(L=>L.package_id===d))??null,S=(w==null?void 0:w.packages.filter(L=>L.owner==="own"))??[],k=(w==null?void 0:w.packages.filter(L=>L.owner==="softwaredlc"))??[],j=w?pV(w):null,N=!!w&&w.packages.length===0,O=L=>{var $,A;h(L),b(null),m(((A=($=w==null?void 0:w.packages.find(D=>D.package_id===L))==null?void 0:$.versions[0])==null?void 0:A.version)??"")},T=async L=>{if(L.preventDefault(),p||!_||!f)return;const $=v.current;y(!0),b(null);try{const A=await a({package_id:_.package_id,version:f});if($!==v.current)return;if(!A.ok){b(xV(A.refusal,`${_.coordinate} ${f}`));return}o(A.data)}finally{$===v.current&&y(!1)}},I=l.state==="failed"?l.message:g;return i.jsx(yn,{open:e,onOpenChange:L=>L?null:r(),children:i.jsx(wn,{className:"sm:max-w-lg",children:i.jsxs("form",{className:"grid gap-4",onSubmit:L=>void T(L),noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:"Propose from a package"}),i.jsx(kn,{children:"Choose a published version of an org structure package. You see what it adds and changes in the org before you submit."})]}),I?i.jsxs(pe,{variant:"destructive",role:"alert",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:l.state==="failed"?"Could not read the packages":"Could not preview this version"}),i.jsxs(ge,{children:[i.jsx("p",{children:I}),l.state==="failed"?i.jsx("div",{className:"mt-2",children:i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:()=>void x(),children:"Retry"})}):null]})]}):null,l.state==="loading"?i.jsxs("div",{className:"grid gap-4",role:"status","aria-label":"Reading the packages",children:[i.jsx(Tt,{className:"h-9 w-full"}),i.jsx(Tt,{className:"h-9 w-full"})]}):null,N?i.jsxs("div",{className:"grid justify-items-center gap-2 py-4 text-center",children:[i.jsx(cf,{className:"text-muted-foreground size-5","aria-hidden":"true"}),i.jsx("p",{className:"text-sm font-medium",children:"No org structure packages to propose from"}),i.jsx("p",{className:"text-muted-foreground text-xs",children:b_}),i.jsx("a",{className:"text-primary text-sm underline underline-offset-2",href:n,children:"Go to Packages"})]}):null,w&&_?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-package-choice",children:"Package"}),i.jsxs(St,{value:d,onValueChange:O,children:[i.jsx(wt,{id:"org-package-choice","aria-describedby":"org-package-coordinate",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[S.length?i.jsxs(Yw,{children:[i.jsx(Ig,{children:"This org"}),S.map(L=>i.jsx(Ue,{value:L.package_id,children:L.name},L.package_id))]}):null,k.length?i.jsxs(Yw,{children:[i.jsx(Ig,{children:"SoftwareDLC"}),k.map(L=>i.jsx(Ue,{value:L.package_id,children:L.name},L.package_id))]}):null]})]}),i.jsxs("p",{id:"org-package-coordinate",className:"text-muted-foreground text-xs break-words",children:[i.jsx("span",{className:"font-mono",children:_.coordinate}),_.organization_name?` · ${_.organization_name}`:null]})]}),i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"org-package-version",children:"Version"}),i.jsxs(St,{value:f,onValueChange:L=>{m(L),b(null)},children:[i.jsx(wt,{id:"org-package-version",children:i.jsx(Ct,{})}),i.jsx(_t,{children:_.versions.map(L=>i.jsx(Ue,{value:L.version,children:gV(L)},L.version))})]})]})]}):null,w&&!N?i.jsxs("div",{className:"grid gap-1",children:[j?i.jsx("p",{className:"text-muted-foreground text-xs",children:j}):null,i.jsx("p",{className:"text-muted-foreground text-xs",children:b_})]}):null,i.jsx(jn,{children:w&&_?i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",variant:"outline",onClick:r,children:"Cancel"}),i.jsxs(U,{type:"submit","aria-disabled":p||void 0,children:[p?i.jsx(vn,{className:"size-4","aria-hidden":"true"}):null,p?"Loading…":"Preview proposal"]})]}):i.jsx(U,{type:"button",variant:"outline",onClick:r,children:"Close"})})]})})})}function bV({draft:e,org:t,duplicate_day:n,on_submit:s,on_choose:a,on_discard:r,on_open_proposal:o}){const l=e.package,c=`${l.coordinate} ${l.version}`,d=l.open_duplicate,h=!d&&e.total===0,f=i.jsxs(i.Fragment,{children:[i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:a,children:"Choose another version"}),i.jsx(U,{type:"button",variant:"outline",size:"sm",onClick:r,children:"Discard preview"})]});if(d)return i.jsxs(pe,{variant:"warning",role:"status",className:"mt-6","data-testid":"org-package-banner",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:`Already proposed: '${d.title}' by ${d.requested_by}`}),i.jsxs(ge,{children:[i.jsx("p",{children:`${d.requested_by} proposed this version ${gb(d.via)}${n?` on ${mi(n)}`:""}. Review that proposal instead of proposing it again.`}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[i.jsx(U,{type:"button",size:"sm",onClick:()=>o(d),children:"Open proposal"}),f]})]})]});const m=[`From ${pE(l.owner,l.organization_name)}`,l.published_by_name?`, published by ${l.published_by_name}`:"",l.published_at?` on ${mi(l.published_at)}`:"",`, laid over ${t} as it was at revision ${l.revision}.`].join("");return i.jsxs(pe,{variant:"info",role:"status",className:"mt-6","data-testid":"org-package-banner",children:[i.jsx(cf,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{className:"break-words",children:h?`This version adds and changes nothing in ${t}`:i.jsxs(i.Fragment,{children:["You are proposing ",l.href?i.jsx("a",{className:"text-primary underline underline-offset-2",href:l.href,children:c}):c]})}),i.jsxs(ge,{children:[i.jsx("p",{children:h?"Choose another version, or discard this preview.":`${m} A package proposal adds and changes; it never removes. Nothing is saved to the organization until someone accepts it.`}),i.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[h?null:i.jsx(U,{type:"button",size:"sm",onClick:s,children:"Submit proposal"}),f,h?null:i.jsx("span",{className:"text-muted-foreground text-xs",children:pa(e.counts)})]})]})]})}function yV({draft:e}){const t=e.package,n=e.total>0,s=n?t.placements:[],a=n?t.possible_matches:{matches:[],truncated:!1};return!s.length&&!a.matches.length&&!t.not_proposed.length?null:i.jsxs("section",{"aria-labelledby":"org-package-before",className:"mt-6 min-w-0",children:[i.jsx("h2",{id:"org-package-before",className:"text-lg font-semibold",children:"Before you submit"}),i.jsxs(yt,{className:"mt-3 grid gap-4 p-4",children:[s.length?i.jsx(cc,{title:"Where new teams go",children:i.jsx(QH,{placements:s})}):null,a.matches.length?i.jsx(cc,{title:"Possible matches",children:i.jsx(gE,{matches:a})}):null,t.not_proposed.length?i.jsx(cc,{title:"Not part of this proposal",children:i.jsx(xE,{items:t.not_proposed})}):null]})]})}function wV(e){return!!(e!=null&&e.package)}const y_={title:"Discard your draft?",description:"Your changes to the draft are lost. Nothing in the organization changed.",action_label:"Discard draft",destructive:!0,action:"discard the draft"},w_=e=>({title:"Leave this package preview?",description:`Leaving drops this preview of ${e}. Nothing was proposed and nothing in the organization changed.`,action_label:"Leave preview",cancel_label:"Stay",destructive:!1,action:"leave the preview"}),_V={local:"Who holds each post and who reports to whom in this repository's local org, worked out from its teams, job functions and posts.",hosted:"Who holds each post and who reports to whom in this organization, worked out from its teams, job functions and posts."},jV="Covered: someone holds a post that fills the slot. Vacant: posts fill it but nobody holds them. Uncovered: no job function fills it.",NV=4,xb=e=>({paddingLeft:16+24*Math.min(e,NV)}),Ah={covered:{label:"Covered",tone:"success"},vacant:{label:"Vacant",tone:"warning"},uncovered:{label:"Uncovered",tone:"error"}};function kV(){const e=Vn().org;if(!e)throw new Error("The Org chart page rendered without the org seam.");return e}function SV({host:e="local",org:t=""}={}){var de;const n=kV(),[s,a]=u.useState({state:"loading"}),[r,o]=u.useState(null),l=u.useRef(0),c=u.useRef(null),d=u.useCallback(J=>{const G=async Y=>{const te=l.current+=1;c.current&&clearTimeout(c.current);const ce=await n.chart();if(te!==l.current)return;if(ce.ok){o({chart:ce.data,at:new Date().toISOString()}),a({state:"read"});return}const{refusal:be}=ce;if(be.reason==="no_local_org"){o(null),a({state:"none",seedable:be.seedable!==!1});return}if(e==="hosted"&&(be.reason==="not_found"||be.status===404)){o(null),a({state:"missing"});return}if(be.retry&&be.reason==="store_locked"&&Y>0){const fe=be.retry_after??10;a({state:"busy",retry_after:fe}),c.current=setTimeout(()=>void G(Y-1),fe*1e3);return}a({state:"failed",refusal:be})};return G(J)},[n,e]);u.useEffect(()=>(d(1),()=>{l.current+=1,c.current&&clearTimeout(c.current)}),[d]);const h=()=>void d(1),f=s.state==="none"||s.state==="missing"?null:r,{href:m}=lt(),p=Ga(),y=m("/settings/account"),g=n.proposals,b=JH(g,(f==null?void 0:f.at)??null),v=!!g&&b.state!=="off",[x,w]=u.useState(null),[_,S]=u.useState(!1),[k,j]=u.useState(null),{confirm:N,confirm_dialog:O}=mE(ul),T=wV(x)?x:null,[I,L]=u.useState(null),[$,A]=u.useState(null),D=g!=null&&g.packageChoices&&g.draft.beginFromPackage?g:null,E=u.useMemo(()=>x&&!x.package&&g?{draft:x,change:g.draft.change,on_draft:w}:null,[x,g]),R=$V(n,h,(x==null?void 0:x.chart)??(f==null?void 0:f.chart)??EV,e,y,E),C=T?null:R,M=n.twoFactor,H=u.useCallback(async()=>M?M():"ok",[M]),z=!!x&&(x.total>0||!!x.package),K=T?`${T.package.coordinate} ${T.package.version}`:null,oe=u.useMemo(()=>K?w_(K):y_,[K]),re=u.useRef(null),Ne=u.useRef(()=>{});Ne.current=()=>{g==null||g.draft.discard(),w(null)},u.useEffect(()=>{var fe;if(!z)return;let J=!0;const G=((fe=re.current)==null?void 0:fe.closest("[data-dock-pane]"))??null,Y=$e=>{$e.preventDefault()},te=()=>{J=!1,window.removeEventListener("beforeunload",Y),document.removeEventListener("click",ce,!0),G==null||G.removeEventListener(__,be)},ce=$e=>{var Qt,ht,it;if(!J||$e.defaultPrevented||$e.button!==0||$e.metaKey||$e.ctrlKey||$e.shiftKey||$e.altKey)return;const ze=$e.target;if(G&&(((Qt=ze==null?void 0:ze.closest)==null?void 0:Qt.call(ze,"[data-dock-pane]"))??document.querySelector("[data-dock-active]"))!==G)return;const q=(ht=ze==null?void 0:ze.closest)==null?void 0:ht.call(ze,"a[href]"),ve=q?null:(it=ze==null?void 0:ze.closest)==null?void 0:it.call(ze,CV);let Ve=null;if(q&&q.target!=="_blank"&&!q.hasAttribute("download")){const Lt=new URL(q.href,window.location.href),Dt=G?new URL(G.getAttribute("data-dock-address")??"",window.location.href):window.location,On=Lt.pathname===Dt.pathname&&Lt.search===Dt.search;Lt.origin===window.location.origin&&!On&&(Ve=G?()=>q.click():()=>window.location.assign(Lt.href))}else ve&&ve.getAttribute("aria-current")!=="page"&&ve.getAttribute("aria-disabled")!=="true"&&!ve.hasAttribute("disabled")&&(Ve=()=>ve.click());if(!Ve)return;$e.preventDefault(),$e.stopPropagation();const Ft=Ve;N(oe).then(Lt=>{Lt&&(te(),Ne.current(),Ft())})},be=$e=>{var q;const ze=(q=$e.detail)==null?void 0:q.close;!J||typeof ze!="function"||($e.preventDefault(),N(oe).then(ve=>{ve&&(te(),Ne.current(),ze())}))};return window.addEventListener("beforeunload",Y),document.addEventListener("click",ce,!0),G==null||G.addEventListener(__,be),te},[z,N,oe]);const Se=async()=>{if(!g)return;const J=await g.draft.begin();J.ok?w(J.data):p.error(J.refusal.message)},ae=async()=>x?x.package?N(w_(`${x.package.coordinate} ${x.package.version}`)):x.total>0?N(y_):!0:!0,F=async()=>{await ae()&&(g==null||g.draft.discard(),w(null))},ie=async()=>{x&&!x.package&&!await ae()||(x&&!x.package&&(g==null||g.draft.discard(),w(null)),L({initial:null}))},W=async J=>{if(!(D!=null&&D.draft.beginFromPackage)||!await ae())return;const G=await D.draft.beginFromPackage(J);if(!G.ok){G.refusal.code!=="preview_replaced"&&p.error(G.refusal.message);return}j(null),A(null),w(G.data)},se=J=>{const G=b.state==="read"?b.proposals.find(Y=>Y.id===J.proposal_id):void 0;g==null||g.draft.discard(),S(!1),w(null),A(null),j(G??{id:J.proposal_id,title:J.title,status:"open",requested_by:J.requested_by,requested_at:"",mine:!1,counts:(x==null?void 0:x.counts)??DV})},Z=T!=null&&T.package.open_duplicate&&b.state==="read"?((de=b.proposals.find(J=>J.id===T.package.open_duplicate.proposal_id))==null?void 0:de.requested_at)??null:null;return s.state==="missing"?i.jsx(IV,{org:t}):i.jsx(sb,{children:i.jsxs("div",{ref:re,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(bn,{title:"Org chart",description:_V[e]}),s.state==="busy"&&!f?i.jsxs("p",{className:"text-muted-foreground mt-4 text-sm",role:"status",children:["Another sdlc command holds the repository store; reading again in ",s.retry_after," s."]}):null,(s.state==="loading"||s.state==="busy")&&!f?i.jsx(LV,{quiet:s.state==="busy"}):null,s.state==="none"?i.jsx(PV,{edit:(C==null?void 0:C.actions)??null,seedable:s.seedable}):null,s.state==="failed"?i.jsx(HV,{host:e,kept_at:(f==null?void 0:f.at)??null,on_retry:h}):null,f&&T?i.jsxs(i.Fragment,{children:[i.jsx(bV,{draft:T,org:f.chart.org,duplicate_day:Z,on_submit:()=>S(!0),on_choose:()=>L({initial:{package_id:T.package.package_id,version:T.package.version}}),on_discard:()=>void F(),on_open_proposal:se}),i.jsx(yV,{draft:T})]}):f&&x?i.jsx(sV,{draft:x,on_submit:()=>S(!0),on_discard:()=>void F()}):f&&v?i.jsx(tV,{listed:b,on_propose:()=>void Se(),...D?{on_propose_package:()=>void ie()}:{},on_open:j}):null,f?i.jsx(VV,{chart:(x==null?void 0:x.chart)??f.chart,host:e,edit:(C==null?void 0:C.actions)??null,...T?{marks:T.marks}:{}}):null,(C==null?void 0:C.dialogs)??null,D!=null&&D.draft.beginFromPackage?i.jsx(vV,{open:I!==null,contract:D,packages_href:m(`/org/${encodeURIComponent(t)}/packages`),initial:(I==null?void 0:I.initial)??null,preview:D.draft.beginFromPackage,on_close:()=>{var J,G;(G=(J=D.draft).dropPending)==null||G.call(J),L(null)},on_previewed:J=>{L(null),w(J)}}):null,g&&x?i.jsx(aV,{open:_,draft:x,submit:g.draft.submit,on_close:()=>S(!1),on_open_proposal:se,on_done:(J,G)=>{if(S(!1),J.state==="moved"){w(J.draft);return}w(null),p.success(`Proposed ${G}.`),h(),J.proposal&&(A(J.previewed&&J.opened?{previewed:J.previewed,opened:J.opened}:null),j(J.proposal))}}):null,g&&v?i.jsx(hV,{proposal:k,contract:g,context:{host:e,two_factor:"ok",settings_href:y},check_two_factor:H,since:$,...D?{on_preview_version:J=>void W(J)}:{},on_close:()=>{j(null),A(null)},on_decided:J=>{p.success(J),j(null),A(null),h()}}):null,O]})})}const CV='[data-sidebar="menu-button"]:not([aria-expanded]), [data-sidebar="menu-sub-button"]',__="sdlc-dock-pane-close",Rl={added:0,changed:0,removed:0},DV={team:Rl,job_function:Rl,slot:Rl,post:Rl,fill:Rl},EV={org:"",workflow:!1,teams:[],job_functions:[],slots:[],posts:[],members:[],slot_resolution:[],project:{team:null,roots:[]}};function AV(e){var o;const t=e.authority;if(!t)return{functions:!0,team_add:!0,team:()=>"full",post_add:!1,post:()=>!1,override:!0,slots:!1};const n=((o=e.teams.find(l=>l.parent===null))==null?void 0:o.key)??null,s=new Set(t.teams),a=new Set(t.team_descriptions),r=new Set(t.posts);return{functions:t.administer,team_add:s.size>0,team:l=>l===n?t.administer?"root":a.has(l)?"description":null:s.has(l)?"full":a.has(l)?"description":null,post_add:t.post_pairs.length>0,post:l=>r.has(l),override:!1,slots:t.administer}}function RV(e){const t=e.authority;return t?t.administer||t.teams.length>0||t.team_descriptions.length>0||t.posts.length>0||t.post_pairs.length>0:!0}const TV={functions:!0,team_add:!0,team:()=>"description",post_add:!0,post:()=>!0,override:!1,slots:!0};function Bf({mark:e}){return e?e==="added"?i.jsx(we,{variant:"success",children:"Added"}):i.jsx(we,{variant:"warning",children:"Changed"}):null}const OV={local:"It leaves this repository's local org. If a post, a team or function under it, a holder, an override or the project still needs it, nothing is removed and you are told what needs it.",hosted:"It leaves the organization. If a post, a team or job function under it, or a holder still needs it, nothing is removed and you are told what needs it."},zV={mfa_challenge_required:"challenge",mfa_enrollment_required:"enroll"};function MV(e,t,n){var c;const s=t==="hosted"&&!!n.authority,a=((c=n.authority)==null?void 0:c.two_factor)??!0,[r,o]=u.useState("ok"),l=u.useCallback(async()=>{s&&o(e.twoFactor?await e.twoFactor():a?"ok":"challenge")},[e,s,a]);return u.useEffect(()=>{if(!s){o("ok");return}a?o("ok"):l();const d=()=>void l();return window.addEventListener("focus",d),()=>window.removeEventListener("focus",d)},[s,a,l]),{state:r,set_state:o,check:l}}function $V(e,t,n,s,a,r=null){const o=Ga(),l=bE(n),c=MV(e,s,n),d=r?{host:s,two_factor:"ok",settings_href:a}:s==="hosted"?{host:s,two_factor:c.state,settings_href:a}:ul,{confirm:h,confirm_dialog:f}=mE(d),[m,p]=u.useState(null),[y,g]=u.useState({}),b=R=>g(C=>{if(!C[R])return C;const{[R]:M,...H}=C;return H}),v=e.members,x=u.useCallback(async()=>{if(!v)return{ok:!1};const R=await v();return R.ok?{ok:!0,data:R.data}:{ok:!1}},[v]),w=r?async R=>{const C=await r.change(R);return C.ok?(r.on_draft(C.data),{ok:!0,data:{}}):C}:e.change;if(!w||!r&&s==="hosted"&&(!n.authority||!RV(n)))return null;const _=r?TV:AV(n),S=R=>{const C=R.code?zV[R.code]:void 0;return C?(c.set_state(C),{kind:"two_factor",message:R.message}):R.code==="revision_conflict"?(t(),{kind:"changed",message:R.message}):R.code==="outside_authority"?(t(),{kind:"authority",message:R.message}):{message:R.message}},k=R=>R.action==="hold"||R.action==="release"?"posts":"kind"in R?R.kind==="team"?"teams":R.kind==="post"?"posts":R.kind==="slot"?"slots":"functions":null,j=(R,C)=>{if(r)return;const M=R==null?void 0:R.warning;M?o.error(M):o.success(C),t()},N=async(R,C)=>{const M=await w(R);if(!M.ok)return S(M.refusal);const H=k(R);return H&&b(H),j(M.data,C),null},O=R=>{c.check(),p(R)},T=async(R,C,M,H)=>{const z=await w(M);if(!z.ok){const K=S(z.refusal),oe=z.refusal.bound,re=oe?oe.projects.length+oe.more:0,Ne=oe?`${oe.kind==="slot"?"Slot":"Post"} ${C} is still needed by the ${re===1?"override of 1 project that binds":`overrides of ${re} projects that bind`} it. Clear ${re===1?"it":"them"} on each project's Settings first.`:K.message;g(Se=>({...Se,[R]:{label:C,message:Ne,...oe?{bound:oe}:{}}}));return}b(R),j(z.data,H)},I=async(R,C,M)=>{const H=R==="team"?"team":"job function";c.check(),(r||await h({title:`Remove ${H} ${M}?`,description:OV[s],action_label:"Remove",destructive:!0,action:`remove the ${H}`}))&&await T(R==="team"?"teams":"functions",M,{action:"remove",kind:R,key:C},`${R==="team"?"Team":"Job function"} ${M} removed.`)},L=async R=>{const C=R.label||R.key;c.check(),(r||await h({title:`Remove slot ${C}?`,description:"Projects stop showing it. This can't be undone.",action_label:"Remove slot",destructive:!0,action:"remove the slot"}))&&await T("slots",C,{action:"remove",kind:"slot",key:R.key},`Removed slot ${C}.`)},$=async R=>{const C=l.post(R);c.check(),(r||await h({title:`Remove post ${C}?`,description:"The post leaves the organization's chart. A post with holders is refused; remove its holders first.",action_label:"Remove",destructive:!0,action:"remove the post"}))&&await T("posts",C,{action:"remove",kind:"post",key:R},`Removed post ${C}.`)},A=async(R,C)=>{const M=l.post(R),H=l.member(C),z=n.posts.find(Se=>Se.post===R),oe=((z==null?void 0:z.holders.length)??0)<=1?z!=null&&z.escalates_to?` The post becomes vacant. Until someone holds it, its reports and the slots it fills go to ${l.manager(z.escalates_to)}.`:" The post becomes vacant.":"";if(c.check(),!await h({title:`Remove ${H} from ${M}?`,description:`They stop holding this post and no longer report through it.${oe}`,action_label:"Remove",action:"remove the holder"}))return;const Ne=await w({action:"release",post:R,member:C.id});if(!Ne.ok){o.error(S(Ne.refusal).message),t();return}b("posts"),j(Ne.data,`Removed ${H} from ${M}.`)},D=()=>p(null),E=(m==null?void 0:m.kind)==="override"&&n.project&&n.project.team!==null?n.project.slots.find(R=>R.slot===m.slot)??null:null;return{actions:{can:_,host:s,drafting:!!r,...r?{marks:r.draft.marks}:{},team:(R,C="full")=>O({kind:"team",team:R,scope:C}),job:R=>O({kind:"function",job:R}),override:R=>O({kind:"override",slot:R}),slot:R=>O({kind:"slot",slot:R}),slot_remove:R=>void L(R),remove:(R,C,M)=>void I(R,C,M),post_add:()=>O({kind:"post"}),post_remove:R=>void $(R),holder_add:R=>O({kind:"holder",post:R}),holder_remove:(R,C)=>void A(R,C),refused:R=>{const C=y[R];return C?i.jsx(VH,{label:C.label,message:C.message,bound:C.bound,on_dismiss:()=>b(R)}):null}},dialogs:i.jsxs(i.Fragment,{children:[i.jsx(TH,{open:(m==null?void 0:m.kind)==="team",chart:n,team:(m==null?void 0:m.kind)==="team"?m.team:null,scope:(m==null?void 0:m.kind)==="team"?m.scope:"full",parents:!r&&n.authority?n.authority.teams:void 0,save:N,on_close:D,context:d}),i.jsx(zH,{open:(m==null?void 0:m.kind)==="function",chart:n,job:(m==null?void 0:m.kind)==="function"?m.job:null,save:N,on_close:D,context:d}),i.jsx(PH,{open:E!==null,chart:n,binding:E,names:l,save:N,confirm:R=>h({...R,action:"clear the override"}),on_close:D}),i.jsx(LH,{open:(m==null?void 0:m.kind)==="slot",chart:n,slot:(m==null?void 0:m.kind)==="slot"?m.slot:null,save:N,on_close:D,context:d}),i.jsx(GH,{open:(m==null?void 0:m.kind)==="post",chart:n,names:l,save:N,on_close:D,context:d}),i.jsx(HH,{open:(m==null?void 0:m.kind)==="holder",chart:n,post:(m==null?void 0:m.kind)==="holder"?m.post:null,names:l,members:x,save:N,on_close:D,context:d}),f]})}}function LV({quiet:e=!1}){return i.jsx("div",{className:"mt-6 grid gap-2",...e?{"aria-hidden":!0}:{role:"status","aria-label":"Loading the org chart"},children:Array.from({length:4},(t,n)=>i.jsx(Tt,{className:n===3?"h-10 w-2/3":"h-10 w-full"},n))})}function Eo({children:e}){return i.jsx("pre",{className:"bg-muted text-foreground m-0 overflow-x-auto rounded-md border px-3 py-2 font-mono text-sm",children:i.jsx("code",{children:e})})}function PV({edit:e,seedable:t}){const n=t?e?"Plan one from this checkout's workflow roles with sdlc org seed, or start one with a team. This page shows it as soon as it exists.":"Plan one from this checkout's workflow roles, or start one with a team. This page shows it as soon as it exists.":"Start one with a team. This page shows it as soon as it exists.";return i.jsxs(pe,{variant:"info",className:"mt-6",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"This repository has no local org yet"}),i.jsxs(ge,{children:[i.jsx("p",{children:n}),t||!e?i.jsxs("div",{className:"mt-2 grid w-full gap-2",children:[t?i.jsx(Eo,{children:"sdlc org seed"}):null,e?null:i.jsx(Eo,{children:"sdlc org add team <key>"})]}):null,e?i.jsxs(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:()=>e.team(null),children:[i.jsx(za,{className:"size-4","aria-hidden":"true"}),"Add team"]}):null]})]})}function IV({org:e}){const{href:t,Link:n}=lt();return i.jsx(Ha,{title:"Page not found",description:e?`There is no organization ${e}, or you are not one of its members.`:"This organization does not exist, or you are not one of its members.",backHref:t("/org"),backLabel:"Back to Organizations",link:n})}function GV(e){return new Date(e).toDateString()===new Date().toDateString()?`today at ${Fs(e)}`:`on ${Rs(e)} at ${Fs(e)}`}function HV({host:e,kept_at:t,on_retry:n}){const s=t?`The chart read ${GV(t)} is kept below. `:"";return i.jsxs(pe,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:e==="hosted"?"Could not read the org chart":"Could not read the local org"}),i.jsxs(ge,{children:[i.jsxs("p",{children:[s,e==="hosted"?s?"Try again in a moment.":"Try again in a moment. If it keeps failing, ask an organization owner.":"Details are in the terminal running sdlc viewer."]}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:n,children:"Retry"})]})]})}function bE(e){return u.useMemo(()=>{const t=new Map(e.teams.map(b=>[b.key,b.label||b.key])),n=new Map(e.job_functions.map(b=>[b.key,b.label||b.key])),s=new Map(e.slots.map(b=>[b.key,b.label||b.key])),a=new Map(e.posts.map(b=>[b.post,b.holders])),r=b=>b.label||b.id,o=new Map;for(const b of[...e.members,...e.posts.flatMap(v=>v.holders)]){const v=r(b);o.set(v,(o.get(v)??new Set).add(`${b.kind}:${b.id}`))}const l=b=>{var v;return(((v=o.get(r(b)))==null?void 0:v.size)??0)>1},c=b=>{const v=l(b)?b.detail??b.id:null;return v&&v!==r(b)?v:null},d=b=>{const v=c(b);return v&&v!==r(b)?`${r(b)} (${v})`:r(b)},h=b=>{const[v="",x=""]=b.split("/");return{team:t.get(v)??v,job:n.get(x)??x}},f=b=>{const{team:v,job:x}=h(b);return`${x} · ${v}`},m=b=>{if(b==="top")return"Top of the org";if(typeof b!="string")return`A vacant ${n.get(b.vacant)??b.vacant}`;const v=(a.get(b)??[]).map(d);return v.length?`${f(b)} (${v.join(", ")})`:f(b)},p=new Map(e.teams.map(b=>[b.key,b.parent])),y=b=>{let v=0;for(let x=p.get(b);x&&v<e.teams.length;x=p.get(x))v+=1;return v};return{parts:h,post:f,member:d,memberLabel:r,memberDetail:c,manager:m,byPost:(b,v)=>{const[x="",w=""]=[b.split("/")[0],v.split("/")[0]],[_,S]=[h(b),h(v)];return y(x)-y(w)||_.team.localeCompare(S.team)||_.job.localeCompare(S.job)},slot:b=>s.get(b)??b,job:b=>n.get(b)??b,team:b=>t.get(b)??b}},[e])}function tr({id:e,title:t,description:n,actions:s,children:a,anchor:r}){const o=u.useRef(null);return u.useEffect(()=>{var l,c;!r||typeof window>"u"||window.location.hash!==`#${r}`||((l=o.current)==null||l.scrollIntoView({block:"start"}),(c=o.current)==null||c.focus({preventScroll:!0}))},[r]),i.jsxs("section",{id:r,"aria-labelledby":e,className:"mt-8 min-w-0",children:[i.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-x-4 gap-y-2",children:[i.jsxs("div",{className:"min-w-0 flex-1 basis-64",children:[i.jsx("h2",{id:e,ref:o,tabIndex:r?-1:void 0,className:"text-lg font-semibold",children:t}),i.jsx("p",{className:"text-muted-foreground mt-1 text-sm",children:n})]}),s?i.jsx("div",{className:"flex shrink-0 gap-2",children:s}):null]}),i.jsx("div",{className:"mt-3",children:a})]})}function Ul({children:e,on_click:t}){return i.jsxs(U,{type:"button",variant:"outline",size:"sm",onClick:t,children:[i.jsx(za,{className:"size-4","aria-hidden":"true"}),e]})}const j_={local:"A member's primary manager comes from the post highest in the function tree; the others are dotted lines.",hosted:"Members who hold a post. A member's primary manager comes from the post highest in the function tree; the others are dotted lines."};function VV({chart:e,host:t,edit:n,marks:s}){const a=bE(e),r=s??(n==null?void 0:n.marks),o=e.members.some(l=>l.kind==="agent");return i.jsxs(i.Fragment,{children:[i.jsxs(tr,{id:"org-chart-lines",title:"Reporting lines",description:"Each post reports to the post of its parent job function in the same team, or else in the nearest team above it that has one.",actions:n!=null&&n.can.post_add?i.jsx(Ul,{on_click:n.post_add,children:"Add post"}):void 0,children:[n==null?void 0:n.refused("posts"),i.jsx(WV,{chart:e,names:a,agents:o,host:t,edit:n,marks:r})]}),i.jsx(tr,{id:"org-chart-members",title:"Members",description:o?`${j_[t]} Each agent answers to the nearest person in its reporting chain.`:j_[t],children:i.jsx(KV,{chart:e,names:a,host:t,agents:o})}),n||s?i.jsxs(tr,{id:"org-chart-teams",title:"Teams",description:"Each team under its parent. A post is one of its job functions staffed in it.",actions:n!=null&&n.can.team_add?i.jsx(Ul,{on_click:()=>n.team(null),children:"Add team"}):void 0,children:[n==null?void 0:n.refused("teams"),i.jsx(UV,{chart:e,host:t,edit:n,marks:r})]}):null,i.jsxs("div",{className:"grid items-start gap-x-6 xl:grid-cols-2",children:[i.jsxs(tr,{id:"org-chart-functions",title:"Function tree",description:"Each job function under its parent, with the slots it fills.",actions:n!=null&&n.can.functions?i.jsx(Ul,{on_click:()=>n.job(null),children:"Add job function"}):void 0,children:[n!=null&&n.can.functions?n.refused("functions"):null,i.jsx(ZV,{chart:e,names:a,edit:n!=null&&n.can.functions?n:null,marks:r})]}),i.jsxs(tr,{id:"org-chart-slots",anchor:"slots",title:"Slots",description:jV,actions:n!=null&&n.can.slots&&e.slot_resolution.length>0?i.jsx(Ul,{on_click:()=>n.slot(null),children:"Add slot"}):void 0,children:[n!=null&&n.can.slots?n.refused("slots"):null,e.workflow===!1?i.jsx("p",{className:"text-muted-foreground mb-3 text-xs",children:"This checkout has no workflow file, so no slot is marked as a gate."}):null,i.jsx(JV,{chart:e,names:a,host:t,edit:n!=null&&n.can.slots?n:null,marks:r})]})]}),e.project?i.jsx(t6,{project:e.project,chart:e,names:a,edit:n!=null&&n.can.override?n:null}):null]})}function UV({chart:e,host:t,edit:n,marks:s}){var h;const a=vb([...e.teams].sort((f,m)=>(f.label||f.key).localeCompare(m.label||m.key)),f=>f.key,f=>f.parent);if(a.length===0)return i.jsx("p",{className:"text-muted-foreground text-sm",children:"No teams yet."});const r=((h=e.project)==null?void 0:h.team)??null,o=t==="hosted",l=(f,m)=>{if(!n)return null;const p=n.can.team(f.key);return p==="full"?i.jsx(Do,{label:m,on_edit:()=>n.team(f),on_remove:()=>n.remove("team",f.key,m)}):p==="root"?i.jsx(Do,{label:m,on_edit:()=>n.team(f,"description")}):p==="description"&&n.drafting?i.jsx(Do,{label:m,items:[{label:"Edit description",on_select:()=>n.team(f,"description")}]}):p==="description"?i.jsx(U,{type:"button",variant:"ghost",size:"control-icon",className:"-my-1 shrink-0","aria-label":`Edit the description of ${m}`,onClick:()=>n.team(f,"description"),children:i.jsx(df,{className:"size-3.5","aria-hidden":"true"})}):null},c=(f,m)=>i.jsx("ul",{role:"list",className:m===0?"m-0 -mb-px list-none p-0":"m-0 list-none p-0",children:f.map(({item:p,children:y})=>{const g=p.label||p.key;return i.jsxs("li",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b py-2 pr-4",style:xb(m),"data-testid":"org-chart-team",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium",children:g}),i.jsx(Bf,{mark:s==null?void 0:s.teams[p.key]})]}),i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[o?null:i.jsx("span",{className:"text-muted-foreground font-mono text-xs",children:p.key}),r===p.key?i.jsx(we,{variant:"neutral",children:"Owns this project"}):null,l(p,g)]})]}),y.length>0?c(y,m+1):null]},p.key)})}),d=o&&e.teams.length===1;return i.jsxs(i.Fragment,{children:[i.jsx(yt,{className:"overflow-hidden",children:c(a,0)}),d?i.jsxs("p",{className:"text-muted-foreground mt-2 text-sm",children:["No teams below ",e.teams[0].label||e.teams[0].key," yet."]}):null]})}function vb(e,t,n){const s=new Set(e.map(t)),a=new Map(e.map(o=>[t(o),{item:o,children:[]}])),r=[];for(const o of e){const l=n(o),c=a.get(t(o));l&&s.has(l)&&l!==t(o)?a.get(l).children.push(c):r.push(c)}return r}const BV={local:"No posts yet.",hosted:"No posts yet. An org admin can add them."};function WV({chart:e,names:t,agents:n,host:s,edit:a,marks:r}){const o=vb([...e.posts].sort((d,h)=>t.byPost(d.post,h.post)),d=>d.post,d=>typeof d.reports_to=="string"&&d.reports_to!=="top"?d.reports_to:null);if(o.length===0){const d=s==="hosted"&&(a==null?void 0:a.can.functions)&&!a.can.post_add;return i.jsx("p",{className:"text-muted-foreground text-sm",children:a!=null&&a.can.post_add?"No posts yet. Add a post to staff a job function in a team.":d?"No posts yet. Add a job function under Function tree first, then add a post to staff it in a team.":BV[s]})}const l=new Map(e.members.map(d=>[`${d.kind}:${d.id}`,d])),c=(d,h)=>i.jsx("ul",{role:"list",className:h===0?"m-0 -mb-px list-none p-0":"m-0 list-none p-0",children:d.map(({item:f,children:m})=>{const{team:p}=t.parts(f.post),y=typeof f.reports_to=="object"?f.reports_to:null,g=!!(a!=null&&a.can.post(f.post));return i.jsxs("li",{children:[i.jsxs("div",{className:"border-b py-2 pr-4",style:xb(h),"data-testid":"org-chart-post",children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(tO,{className:"text-muted-foreground size-4 shrink-0","aria-hidden":"true"}),i.jsx("span",{className:"text-sm font-medium",children:t.parts(f.post).job}),i.jsx("span",{className:"text-muted-foreground text-xs",children:y?`${p} · Reports to a vacant ${t.job(y.vacant)}`:p}),i.jsx(Bf,{mark:r==null?void 0:r.posts[f.post]}),g&&a?i.jsx("span",{className:"ml-auto",children:i.jsx(Do,{label:t.post(f.post),items:[...a.drafting?[]:[{label:"Add holder",on_select:()=>a.holder_add(f.post)}],{label:"Remove post",on_select:()=>a.post_remove(f.post),destructive:!0}]})}):null]}),i.jsx("div",{className:"mt-1 grid min-w-0 gap-1 pl-6",children:f.holders.length===0?i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx(we,{variant:Ah.vacant.tone,children:Ah.vacant.label}),i.jsx("span",{className:"text-muted-foreground text-xs",children:f.escalates_to?`No one holds this post. Its work goes to ${t.manager(f.escalates_to)}.`:"No one holds this post."})]}):f.holders.map(b=>i.jsx(YV,{holder:b,post:f.post,member:l.get(`${b.kind}:${b.id}`),names:t,agents:n,host:s,on_remove:g&&a&&!a.drafting?()=>a.holder_remove(f.post,b):void 0},`${b.kind}:${b.id}`))})]}),m.length>0?c(m,h+1):null]},f.post)})});return i.jsx(yt,{className:"overflow-hidden",children:c(o,0)})}function FV(e){return new Date(e).toLocaleDateString(void 0,{day:"numeric",month:"short",year:"numeric"})}function qV(e){if(!e.held_since)return null;const t=FV(e.held_since);return e.added_by?e.added_by==="former_member"?`Added on ${t} by a former member`:`Added by ${e.added_by.name} on ${t}`:`Added on ${t}`}function YV({holder:e,post:t,member:n,names:s,agents:a,host:r,on_remove:o}){const l=e.kind==="person"?yv:pv,c=n==null?void 0:n.posts.find(y=>y.post===t),d=n==null?void 0:n.posts.find(y=>y.primary),h=s.memberDetail(e);let f=null;c!=null&&c.dotted&&d?f=`Dotted line: primary manager is ${s.manager(d.reports_to)}`:e.kind==="agent"&&n&&"accountable_person"in n&&(f=n.accountable_person?`Accountable person ${s.member(n.accountable_person)}`:"No accountable person");const m=r==="hosted"?qV(e):null,p=s.memberLabel(e);return i.jsxs("div",{className:"min-w-0",children:[i.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",children:[i.jsx(l,{className:"text-muted-foreground size-3.5 shrink-0","aria-hidden":"true"}),i.jsx("span",{className:"text-sm font-medium break-all",children:p}),o?i.jsxs(wd,{children:[i.jsx(_d,{asChild:!0,children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon",className:"-my-1 shrink-0","aria-label":`Remove ${s.member(e)} from ${s.post(t)}`,onClick:o,children:i.jsx(dd,{className:"size-3.5","aria-hidden":"true"})})}),i.jsxs(ol,{children:["Remove ",p]})]}):null,h?i.jsx("span",{className:"text-muted-foreground text-xs break-all",children:h}):null,a?i.jsx("span",{className:"text-muted-foreground text-xs",children:e.kind==="person"?"Person":"Agent"}):null]}),f?i.jsx("div",{className:"pl-5.5 text-xs",children:f}):null,m?i.jsx("div",{className:"text-muted-foreground pl-5.5 text-xs",children:m}):null]})}const XV=["sdlc org hold <team>/<function> --person <id>","sdlc org hold <team>/<function> --agent <id>"];function KV({chart:e,names:t,host:n,agents:s}){if(e.members.length===0)return n==="hosted"?i.jsx("p",{className:"text-muted-foreground text-sm",children:"No one holds a post yet."}):i.jsxs("div",{className:"grid max-w-2xl gap-2",children:[i.jsx("p",{className:"text-muted-foreground text-sm",children:"No one holds a post yet. Give a post to a person or an agent:"}),XV.map(r=>i.jsx(Eo,{children:r},r))]});const a=[...e.members].sort((r,o)=>r.kind===o.kind?t.memberLabel(r).localeCompare(t.memberLabel(o))||r.id.localeCompare(o.id):r.kind==="person"?-1:1);return i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Members",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Member"}),i.jsx(Q,{children:"Posts"}),i.jsx(Q,{children:"Primary manager"}),i.jsx(Q,{children:"Dotted lines"}),s?i.jsx(Q,{children:"Accountable person"}):null]})}),i.jsx(st,{children:a.map(r=>{const o=r.posts.find(d=>d.primary),l=r.posts.filter(d=>d.dotted),c=t.memberDetail(r);return i.jsxs(_e,{"data-testid":"org-chart-member",children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-medium",children:t.memberLabel(r)}),c?i.jsx("div",{className:"text-muted-foreground text-xs",children:c}):null,s?i.jsx("div",{className:"text-muted-foreground text-xs",children:r.kind==="person"?"Person":"Agent"}):null]}),i.jsx(X,{children:r.posts.map(d=>t.post(d.post)).join(", ")}),i.jsx(X,{children:o?t.manager(o.reports_to):"None"}),i.jsx(X,{children:l.length?l.map(d=>t.manager(d.reports_to)).join(", "):"None"}),s?i.jsx(X,{children:r.kind==="person"?"Not an agent":r.accountable_person?t.member(r.accountable_person):"None"}):null]},`${r.kind}:${r.id}`)})})]})})}function ZV({chart:e,names:t,edit:n,marks:s}){const a=vb([...e.job_functions].sort((o,l)=>(o.label||o.key).localeCompare(l.label||l.key)),o=>o.key,o=>o.parent);if(a.length===0)return i.jsx("p",{className:"text-muted-foreground text-sm",children:(n==null?void 0:n.host)==="hosted"?"No job functions yet. Add one to start the chart.":"No job functions yet."});const r=(o,l)=>i.jsx("ul",{role:"list",className:l===0?"m-0 -mb-px list-none p-0":"m-0 list-none p-0",children:o.map(({item:c,children:d})=>i.jsxs("li",{children:[i.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-x-3 gap-y-1 border-b py-2 pr-4",style:xb(l),"data-testid":"org-chart-function",children:[i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-sm font-medium",children:c.label||c.key}),i.jsx(Bf,{mark:s==null?void 0:s.job_functions[c.key]})]}),i.jsxs("span",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"text-muted-foreground text-xs",children:c.fills.length?`Fills ${c.fills.map(t.slot).join(", ")}`:"No slot"}),c.requires_person?i.jsx(we,{variant:"neutral",children:"Requires a person"}):null,n?i.jsx(Do,{label:c.label||c.key,on_edit:()=>n.job(c),on_remove:()=>n.remove("job_function",c.key,c.label||c.key)}):null]})]}),d.length>0?r(d,l+1):null]},c.key))});return i.jsx(yt,{className:"overflow-hidden",children:r(a,0)})}function QV(e,t){return e.status==="uncovered"?"No job function fills this slot":e.status==="vacant"?`${e.posts.map(t.post).join(", ")} has no holder`:e.posts.map(n=>`${t.post(n.post)}: ${n.holders.map(t.member).join(", ")}`).join("; ")}const Rh={covered:0,vacant:1,uncovered:2};function yE(e){return new Map(e.slots.filter(t=>t.gate).map(t=>{var n;return[t.key,(n=t.gates)!=null&&n.length?`Gate: ${t.gates.join(", ")}`:"Gate slot"]}))}function JV({chart:e,names:t,host:n,edit:s,marks:a}){var l;const r=yE(e),o=new Map(e.slots.map(c=>[c.key,c]));if(n==="hosted"&&e.slot_resolution.length===0){const c=((l=e.authority)==null?void 0:l.ask)??[];return i.jsxs(yt,{className:"grid justify-items-center gap-2 p-6 text-center",children:[i.jsx("span",{className:"text-sm font-medium",children:"No slots yet"}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Add the workflow roles your projects fill, such as Implementer or Approver."}),s?i.jsx(Ul,{on_click:()=>s.slot(null),children:"Add slot"}):i.jsxs("p",{className:"text-muted-foreground text-sm",children:["Only an org owner or admin adds slots."," ",c.length?`Ask ${c.slice(0,3).join(", ")} to make this change.`:"Ask an org owner to make this change."]})]})}return i.jsx(yt,{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Slots",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Slot"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Resolves to"}),s?i.jsx(Q,{className:"text-right",children:i.jsx("span",{className:"sr-only",children:"Actions"})}):null]})}),i.jsxs(st,{children:[[...e.slot_resolution].sort((c,d)=>Rh[c.status]-Rh[d.status]||t.slot(c.slot).localeCompare(t.slot(d.slot))).map(c=>{var h,f;const d=Ah[c.status];return i.jsxs(_e,{"data-testid":"org-chart-slot",children:[i.jsxs(X,{children:[i.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{className:"font-medium",children:t.slot(c.slot)}),i.jsx(Bf,{mark:a==null?void 0:a.slots[c.slot]})]}),n==="hosted"?i.jsxs(i.Fragment,{children:[i.jsx("div",{className:"text-muted-foreground font-mono text-xs",children:c.slot}),(h=o.get(c.slot))!=null&&h.description?i.jsx("div",{className:"text-muted-foreground text-xs break-words",children:(f=o.get(c.slot))==null?void 0:f.description}):null]}):null,r.has(c.slot)?i.jsx("div",{className:"text-muted-foreground text-xs",children:r.get(c.slot)}):null]}),i.jsx(X,{children:i.jsx(we,{variant:d.tone,children:d.label})}),i.jsxs(X,{children:[QV(c,t),c.status==="covered"&&c.needs_person?i.jsx("div",{className:"text-muted-foreground text-xs",children:"Needs a person"}):null]}),s&&o.has(c.slot)?i.jsx(X,{className:"text-right",children:i.jsx(Do,{label:t.slot(c.slot),on_edit:()=>s.slot(o.get(c.slot)),on_remove:()=>s.slot_remove(o.get(c.slot))})}):null]},c.slot)}),e.slot_resolution.length===0?i.jsx(_e,{children:i.jsx(X,{colSpan:3,className:"text-muted-foreground h-24 text-center",children:"This org has no slots yet."})}):null]})]})})}const e6="Who fills each workflow slot for this repository's project: the posts of the owning team's job functions, else of the nearest team above, unless an override names other posts.",mp=["sdlc org own <team>","sdlc org bind <slot> <team>/<function>... --reason <text>","sdlc org unbind <slot>"];function t6({project:e,chart:t,names:n,edit:s}){if(e.team===null){const o=e.roots.map(n.team);return i.jsx(tr,{id:"org-chart-project",title:"This project",description:o.length?`This org has several root teams (${o.join(", ")}), so no team owns this repository's project yet and its slots are not bound. Name the owning team:`:"This org has no team yet, so no team owns this repository's project. Start one:",children:i.jsx("div",{className:"max-w-2xl",children:i.jsx(Eo,{children:o.length?mp[0]:"sdlc org add team <key>"})})})}const a=yE(t),r=[...e.slots].sort((o,l)=>Rh[o.status]-Rh[l.status]||n.slot(o.slot).localeCompare(n.slot(l.slot)));return i.jsxs(tr,{id:"org-chart-project",title:"This project",description:e6,children:[i.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[i.jsx("span",{className:"text-muted-foreground text-xs",children:"Owning team"}),i.jsx("span",{className:"text-sm font-medium",children:n.team(e.team)})]}),i.jsx(yt,{className:"mt-3 overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Slots in this project",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Slot"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Bound to"}),i.jsx(Q,{children:"Source"}),s?i.jsx(Q,{className:"text-right",children:i.jsx("span",{className:"sr-only",children:"Actions"})}):null]})}),i.jsxs(st,{children:[r.map(o=>{const l=Ah[o.status];return i.jsxs(_e,{"data-testid":"org-chart-project-slot",children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-medium",children:n.slot(o.slot)}),a.has(o.slot)?i.jsx("div",{className:"text-muted-foreground text-xs",children:a.get(o.slot)}):null]}),i.jsx(X,{children:i.jsx(we,{variant:l.tone,children:l.label})}),i.jsx(X,{children:i.jsx(n6,{binding:o,names:n})}),i.jsx(X,{children:i.jsx(s6,{binding:o})}),s?i.jsx(X,{className:"text-right",children:i.jsx(U,{type:"button",variant:"ghost",size:"control-icon","aria-label":o.source==="override"?`Edit the override of ${n.slot(o.slot)}`:`Override ${n.slot(o.slot)}`,onClick:()=>s.override(o.slot),children:i.jsx(df,{className:"size-3.5","aria-hidden":"true"})})}):null]},o.slot)}),r.length===0?i.jsx(_e,{children:i.jsx(X,{colSpan:s?5:4,className:"text-muted-foreground h-24 text-center",children:"This org has no slots yet."})}):null]})]})}),s?i.jsxs("div",{className:"mt-3 grid max-w-2xl gap-2",children:[i.jsxs("p",{className:"text-muted-foreground text-sm",children:["Overrides made here are made as ",i.jsx("span",{className:"font-mono",children:"person:user"}),", as sdlc org makes them without --as: that person must hold the lead post of the owning team or of a team above it."]}),i.jsx("p",{className:"text-muted-foreground text-sm",children:"Change the owning team with sdlc org:"}),i.jsx(Eo,{children:mp[0]})]}):i.jsxs("div",{className:"mt-3 grid max-w-2xl gap-2",children:[i.jsx("p",{className:"text-muted-foreground text-sm",children:"Change the owning team or a slot's binding with sdlc org; a lead post of the owning team or a team above it may:"}),mp.map(o=>i.jsx(Eo,{children:o},o))]})]})}function n6({binding:e,names:t}){const n=[];e.status==="covered"&&e.needs_person&&n.push("Needs a person");for(const a of e.posts)a.off_description&&n.push(`${t.post(a.post)} does not fill ${t.slot(e.slot)} in its job description`);e.stale_posts&&n.push(e.stale_posts===1?"One post this override names is no longer in the org":`${e.stale_posts} posts this override names are no longer in the org`);let s;return e.posts.length===0?s=e.source==="override"?"The override names no post the org still has":"No job function fills this slot":e.status==="vacant"?s=`${e.posts.map(a=>t.post(a.post)).join(", ")} has no holder`:s=e.posts.map(a=>a.holders.length?`${t.post(a.post)}: ${a.holders.map(t.member).join(", ")}`:`${t.post(a.post)}: no holder`).join("; "),i.jsxs(i.Fragment,{children:[s,n.map(a=>i.jsx("div",{className:"text-muted-foreground text-xs",children:a},a))]})}function s6({binding:e}){var s;if(e.source==="baseline")return i.jsx(i.Fragment,{children:"From job descriptions"});const t=(s=e.set_by)==null?void 0:s.split(":").slice(1).join(":"),n=[e.reason,[t,e.set_at?Rs(e.set_at):null].filter(Boolean).join(", ")].filter(Boolean).join(" · ");return i.jsxs(i.Fragment,{children:["Override",n?i.jsx("div",{className:"text-muted-foreground text-xs",children:n}):null]})}const i6={breaking:"Breaking",new:"New",improved:"Improved",other:"Other changes"},a6=["breaking","new","improved","other"],r6={http_operation:"API",rpc_operation:"API",graphql_operation:"API",async_operation:"Event",page:"Page",ui_frame:"Screen",ui_component_definition:"Component",table:"Data",function:"Function"};function wE(e){return r6[e]??e.replace(/_/g," ")}function o6(e){return e.bump==="major"?"breaking":e.change==="added"?"new":e.change==="changed"?"improved":"other"}function Ic(e){const t=new Map;let n=0,s=0;for(const r of e){if(r.modeling_only){s+=1;continue}if(!r.bump){n+=1;continue}const o=o6(r);t.set(o,[...t.get(o)??[],r])}return{sections:a6.filter(r=>t.has(r)).map(r=>({key:r,label:i6[r],lines:t.get(r)})),breaking:t.has("breaking"),unlisted_count:n,modeling_only_count:s}}function l6(e,t){const n=[`## ${e}`];t.sections.length===0&&n.push("","No change affects the version.");for(const s of t.sections){n.push("",`### ${s.label}`,"");for(const a of s.lines){const r=a.why?`: ${a.why}`:"";n.push(`- ${a.label} (${wE(a.node_type)})${r}`)}}return`${n.join(`
|
|
429
429
|
`)}
|
|
430
430
|
`}const Zs="candidate";function bb(e){return new Date(e).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})}const c6="Versioned records of this project's release branch, with notes from its graph changes.";function _E({description:e=c6,actions:t}){return i.jsx(bn,{title:"Releases",description:e,actions:t})}function jE(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 Ou({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:je("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 Cs({children:e}){return i.jsx("section",{className:"border-border flex flex-col gap-4 rounded-xl border p-4",children:e})}function Qn({title:e,error:t,onRetry:n}){const s=MD();return i.jsxs(pe,{variant:"destructive",ref:s,children:[i.jsx(jt,{}),e?i.jsx(ke,{children:e}):null,i.jsxs(ge,{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 d6({title:e,text:t}){return i.jsx(Cs,{children:i.jsxs("div",{className:"flex flex-col items-center gap-2 py-10 text-center",children:[i.jsx(of,{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 u6(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 Th({changes:e}){const t=u.useMemo(()=>Ic(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(N_,{line:l},`${l.node_id}:${l.change}`))});return r.key==="breaking"?i.jsxs(pe,{variant:"destructive",className:"border-destructive/40",children:[i.jsx(jt,{}),i.jsx(ke,{children:i.jsx("h3",{className:"text-destructive text-sm font-semibold",children:r.label})}),i.jsx(ge,{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(N_,{line:r,detail:!0},`all:${r.node_id}:${r.change}:${r.modeling_only}`))}):null]})}function N_({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(we,{variant:"outline",children:wE(e.node_type)})]}),n?i.jsx("span",{className:"text-muted-foreground text-xs",children:n}):null]})}const h6={ok:"success",alert:"error",you:"warning",neutral:"neutral"},f6={ok:"bg-success",alert:"bg-destructive",you:"bg-warning",neutral:"bg-muted-foreground"},m6={ok:"text-success",alert:"text-destructive",you:"text-warning",neutral:""},eu="None in this release",NE="Not computed yet",cr=({chip:e})=>i.jsx(we,{variant:h6[e.tone],children:e.label});function kE({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":f6[n.tone],style:e.length===1?{width:`${Math.round(n.share*100)}%`}:{flexGrow:n.share}},s))})}function Wf({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 ca=({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}),xo=({children:e})=>i.jsx("p",{className:"text-muted-foreground text-sm",children:e}),dr=({children:e})=>i.jsx("p",{className:"text-muted-foreground text-xs",children:e});function Ff({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 k_({counted:e,what:t}){return i.jsx(Ff,{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(kE,{parts:[{tone:"primary",share:s.share}]})]},`${s.name}:${a}`))})})}function p6({view:e,heading_ref:t}){const n=e.readiness;return i.jsxs(Wf,{title:"Readiness",heading_ref:t,children:[e.alert?i.jsxs(pe,{variant:e.alert.tone==="alert"?"destructive":"default",role:e.alert.tone==="alert"?"alert":"status",children:[i.jsx(jt,{}),i.jsx(ke,{children:e.alert.title}),e.alert.text?i.jsx(ge,{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(cr,{chip:n.accepted_note}):null,i.jsx(g6,{line:n.contract,verdict:n.verdict.label})]}):i.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm",children:[i.jsx(cr,{chip:n.verdict}),n.accepted_note?i.jsx(cr,{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(dr,{children:n.note}):null]}):i.jsx("p",{className:"text-sm",children:n.text})]})}function g6({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 x6({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 v6(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 b6({view:e,version:t,onDecide:n}){const s=e.obligations,a=e.landings;return i.jsxs(Wf,{title:"Test completeness",children:[i.jsx(ca,{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(kE,{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(cr,{chip:{label:r.label,tone:r.tone}},r.label))})]}):null,s.open.length>0?i.jsxs(i.Fragment,{children:[i.jsx(ca,{title:"Tests not yet satisfied",id:SE}),i.jsx(Ff,{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?v6(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(cr,{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(dr,{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(dr,{children:NE}),i.jsx(ca,{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(cr,{chip:r},r.label))}):null,a.headline?i.jsx("p",{className:`text-sm ${m6[a.headline.tone]}`,children:a.headline.text}):null,a.orphans?i.jsx(dr,{children:a.orphans}):null]})}function y6({view:e}){const t=e.impact;return i.jsxs(Wf,{title:"Impact",children:[i.jsx(ca,{title:"Files by area"}),t.areas.rows.length===0?i.jsx(xo,{children:eu}):i.jsx(k_,{counted:t.areas,what:"areas"}),i.jsx(ca,{title:"In the graph"}),t.graph?i.jsxs(i.Fragment,{children:[t.graph.features.length>0?i.jsx(Ff,{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(dr,{children:t.graph.coverage}):null]}):i.jsx(dr,{children:NE}),i.jsx(ca,{title:"Migrations"}),t.migrations?i.jsx(k_,{counted:t.migrations,what:"days"}):i.jsx(xo,{children:eu}),i.jsx(ca,{title:"Drop or truncate"}),t.drops.length===0?i.jsx(xo,{children:eu}):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(jt,{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(ca,{title:"Feature flags added"}),t.flags.length===0?i.jsx(xo,{children:eu}):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 w6({view:e}){const t=e.threads.rows;return i.jsxs(Wf,{title:"Threads",count:t.length,children:[t.length===0?i.jsx(xo,{children:"None in this release"}):i.jsx(Ff,{items:t,shown:e.threads.shown,what:"threads",children:n=>i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Threads in this release",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{scope:"col",children:"Thread"}),i.jsx(Q,{scope:"col",className:"text-right",children:"Landings"}),i.jsx(Q,{scope:"col",children:"Staging evidence"}),i.jsx(Q,{scope:"col",children:"Local checks"})]})}),i.jsx(st,{children:n.map(s=>i.jsxs(_e,{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(cr,{chip:s.staging})}),i.jsx(X,{children:s.local})]},s.thread))})]})})}),i.jsx(dr,{children:"Thread names come from their objectives; plans open in the VS Code Release tab."})]})}const S_=500;function _6(e){return e.trim()?[...e.trim()].length>S_?`A reason is at most ${S_} characters.`:null:"A reason is required."}const C_={accept:"Why it may ship failing, e.g. the issue that tracks it",revoke:"Why it may no longer ship failing"};function j6({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,I;if(k.preventDefault(),!e||f)return;const j=_6(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),(I=p.current)==null||I.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(yn,{open:e!==null,onOpenChange:k=>{k||w()},children:i.jsx(wn,{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(SE)??document.getElementById(k6)??document.getElementById(CE))==null||O.focus()},children:i.jsxs("form",{onSubmit:_,className:"grid gap-4",noValidate:!0,children:[i.jsxs(_n,{children:[i.jsx(Nn,{children:v?"Accept for release":"Revoke acceptance"}),i.jsx(kn,{children:S})]}),d?i.jsxs(pe,{variant:d.variant,children:[d.variant==="info"?i.jsx(fn,{"aria-hidden":!0}):i.jsx(jt,{"aria-hidden":!0}),i.jsx(ke,{children:d.title}),i.jsx(ge,{children:d.text})]}):null,i.jsxs("div",{className:"grid gap-2",children:[i.jsx(Ie,{htmlFor:"this-release-decision-reason",children:"Reason *"}),i.jsx(bt,{id:"this-release-decision-reason",ref:p,value:r,readOnly:f,placeholder:v?C_.accept:C_.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(Kn,{children:l})}):null]}),i.jsxs(jn,{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 N6({read:e,version:t,onRetry:n,notAvailable:s,decide:a,onDecided:r}){const[o,l]=u.useState(null),c=i.jsx(S6,{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(j6,{target:o,version:t,decide:a,onDecided:r,onClose:()=>l(null)})]})}const SE="this-release-tests-not-yet-satisfied",k6="this-release-readiness",CE="this-release-message";function S6({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(vn,{"aria-hidden":!0})," Reading what this release ships…"]});const c=h=>i.jsx("div",{ref:o,id:CE,tabIndex:-1,className:"outline-none",children:h});if(e.state==="failed")return c(i.jsx(Qn,{title:"This release could not be read",error:e.error,onRetry:()=>{l.current=!0,n()}}));if(e.state==="unread")return c(i.jsx(Qn,{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(pe,{variant:"destructive",children:[i.jsx(jt,{}),i.jsx(ke,{children:"This release could not be worked out"}),i.jsx(ge,{children:"The local records did not assemble into a release view."})]}));const d=e.view;return d.state==="empty"?c(i.jsx(xo,{children:d.empty})):d.state!=="ready"?null:i.jsxs(i.Fragment,{children:[i.jsx(p6,{view:d,heading_ref:r}),i.jsx(x6,{figures:d.figures}),i.jsx(b6,{view:d,version:t,onDecide:a}),i.jsx(y6,{view:d}),i.jsx(w6,{view:d})]})}const DE="Releases of this checkout: the roadmap of open Planned Releases, the next candidate, and each production release with its notes.",qf=u.createContext(0);function Gc(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 D_=e=>(e==null?void 0:e.status)===404||(e==null?void 0:e.reason)==="not_found",E_=5,Jg="Not available",ex="planned:";function yb(){const e=ns();return i.jsx("p",{className:"text-muted-foreground text-sm",children:`${Jg}. ${e}`})}const Us=e=>`${ex}${e}`,C6=e=>e!=null&&e.startsWith(ex)?e.slice(ex.length):null,wb=e=>e?e.slice(0,7):"";function D6(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 E6(){return i.jsxs(pe,{variant:"info",children:[i.jsx(fn,{}),i.jsx(ke,{children:"Releases come from production"}),i.jsx(ge,{className:"text-info",children:"A Release is written when production runs a release candidate, once its commit is merged into origin/main."})]})}function A6(e){if(e.state==="unreadable")return{badges:i.jsx(we,{variant:"error",children:"Could not be read"}),caption:""};if(e.state==="withdrawn")return{badges:i.jsx(we,{variant:"warning",children:"Withdrawn"}),caption:e.replaced_by?`Replaced by ${e.replaced_by}`:"Withdrawn"};const t=i.jsxs(i.Fragment,{children:[i.jsx(we,{variant:"neutral",children:e.app_changed===!1?"App unchanged":e.previous_release_id?e.bump??"patch":"First"}),e.breaking?i.jsx(we,{variant:"error",children:"Breaking"}):null]}),n=e.written_at?bb(e.written_at):"",s=e.tracks&&e.tracks.length>0?` · ${e.tracks.join(", ")}`:"";return{badges:t,caption:`${n}${s}`}}function ur({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 Yf({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 di=({children:e})=>i.jsx("code",{className:"font-mono text-xs",children:e});function EE(e,t){if(e.judged_commit&&t&&e.judged_commit!==t)return`Judged ${wb(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 Xf({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 R6={ready:"success",verifying:"info",fixing:"warning",abandoned:"warning",ready_older:"neutral",none:"neutral",unknown:"neutral"};function T6({batch:e}){if(e.state==="loading")return i.jsxs(pe,{children:[i.jsx(Dc,{}),i.jsxs(ge,{className:"flex flex-row items-center gap-2",role:"status",children:[i.jsx(vn,{"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(pe,{children:[i.jsx(Dc,{}),i.jsxs(ke,{className:"flex flex-wrap items-center gap-2",children:[i.jsx("span",{children:t.text}),i.jsx(we,{variant:R6[t.state],children:t.chip})]}),t.help?i.jsx(ge,{children:t.help}):null]})}const A_="The release batch could not be read. The sdlc viewer log says why.",O6="What this release ships could not be read: git could not compare staging with production.",tu=e=>{var t;return e.read_failed===!0||((t=e.this_release)==null?void 0:t.state)==="loading"};function z6(e,t,n){return`/org/${e}/issues/${encodeURIComponent(t)}?from=${encodeURIComponent(n)}`}function AE({issues:e,error:t}){return t?i.jsx(Qn,{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(Xf,{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(di,{children:n.file}):null]},n.key))})]})}function RE({tracks:e,error:t}){return t?i.jsx(Qn,{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(Xf,{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(di,{children:n.version}):null,n.bump?i.jsx(we,{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(di,{children:s.name}),i.jsxs(di,{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 TE({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(Xf,{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(nt,{containerAriaLabel:"Planned Releases",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Planned Release"}),i.jsx(Q,{children:"Delivered"}),i.jsx(Q,{children:"Not delivered"})]})}),i.jsx(st,{children:e.planned.map(a=>i.jsxs(_e,{children:[i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[a.open&&t?i.jsx(ur,{query:`planned=${encodeURIComponent(a.id)}`,select:Us(a.id),onSelect:n,children:a.name}):i.jsx("span",{children:a.name}),i.jsx(di,{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 M6={thread:"Thread",task:"Task",issue:"Issue",test:"Test"};function OE({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,E_),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(z6(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(nt,{containerAriaLabel:"Related",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Kind"}),i.jsx(Q,{children:"Item"}),i.jsx(Q,{children:"How it relates"})]})}),i.jsx(st,{children:c.map(h=>i.jsxs(_e,{children:[i.jsx(X,{children:M6[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>E_?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 zE=e=>(e==null?void 0:e.status)===409&&e.reason==="view_outdated";function ME(e){const t=_b(),[n,s]=u.useState(t!=null&&t.related?{state:"loading"}:null),a=u.useRef(0),r=Ts(),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]),Gc(u.useContext(qf),()=>void o(!1,!0)),{related:n,read:o}}function $E({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"?zE(e.refusal)?i.jsx(yb,{}):i.jsx(Qn,{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(OE,{rows:e.value.rows,org:t,from:n,untasked:e.value.untasked})]})}function $6(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 LE({planned:e,onSelect:t}){return e?e.open?i.jsx(ur,{query:`planned=${encodeURIComponent(e.id)}`,select:Us(e.id),onSelect:t,children:e.name}):i.jsxs("span",{children:[e.name," ",i.jsx(di,{children:e.id})]}):null}function L6({candidate:e,org:t,onSelect:n,notes:s,onChanged:a}){var w;const r=_b(),{related:o,read:l}=ME("candidate"),[c,d]=u.useState(r!=null&&r.candidateBatch?{state:"loading"}:null),h=u.useRef(0),f=Ts(),[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||tu(N.data))){p(!0),d({state:"error",error:N.ok?A_:N.refusal.message});return}N.ok&&!tu(N.data)&&p(!1),N.ok?tu(N.data)?d(O=>_&&(O==null?void 0:O.state)==="ready"&&!tu(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:A_}:!("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:O6}:{state:"answered",view:c.value.this_release};u.useEffect(()=>(y(!1),()=>{h.current+=1}),[y]),Gc(u.useContext(qf),()=>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(Yf,{pairs:[["Environment",e.environment??"staging"],["Commit",i.jsx(di,{children:wb(e.head_commit_id)},"commit")],["Notes",((w=e.notes)==null?void 0:w.page)??null],["Readiness",v&&!x?EE(v,e.head_commit_id):null],["Planned",e.planned_release?i.jsx(LE,{planned:e.planned_release,onSelect:n}):null]]}),g?i.jsx(T6,{batch:g}):null,b?i.jsx(N6,{read:b,version:e.version,onRetry:()=>y(!1,!0),notAvailable:i.jsx(yb,{}),decide:r==null?void 0:r.decideAcceptance,onDecided:async _=>{a==null||a(),await y(!0,!0,_?"recorded":"unknown")}}):null,s,i.jsx(AE,{issues:e.known_issues,error:e.known_issues_error}),i.jsx(RE,{tracks:e.tracks,error:e.tracks_error}),i.jsx(TE,{delivery:e.planned_delivery,candidate:!0,onSelect:n}),i.jsx($E,{related:o,org:t,from:"release:candidate",onRetry:()=>l(!0)})]})}function P6({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(we,{variant:"warning",children:"Withdrawn"}):i.jsx(we,{variant:"neutral",children:e.app_changed===!1?"App unchanged":s?"First":e.bump}),e.breaking?i.jsx(we,{variant:"error",children:"Breaking"}):null]}),e.state==="withdrawn"&&e.replaced_by?i.jsxs("p",{className:"text-sm",children:["Replaced by"," ",i.jsx(ur,{query:`release=${encodeURIComponent(e.replaced_by)}`,select:e.replaced_by,onSelect:t,inline:!0,children:e.replaced_by})]}):null]})}function I6({release:e,org:t,onSelect:n,notes:s}){const a=e.label??e.version,{related:r,read:o}=ME(a),l=(r==null?void 0:r.state)==="ready"?$6(r.value.previews):null;return i.jsxs(i.Fragment,{children:[i.jsx(Yf,{pairs:[["Environment",e.environment??"production"],["Commit",e.commit?i.jsx(di,{children:wb(e.commit)},"commit"):null],["Readiness",e.readiness?`${EE(e.readiness)} on staging`:null],["Previews",l],["Planned",e.planned_release?i.jsx(LE,{planned:e.planned_release,onSelect:n}):null]]}),s,i.jsx(AE,{issues:e.known_issues,error:e.known_issues_error}),i.jsx(RE,{tracks:e.tracks,error:e.tracks_error}),i.jsx(TE,{delivery:e.planned_delivery,candidate:!1,onSelect:n}),i.jsx($E,{related:r,org:t,from:`release:${a}`,onRetry:()=>o(!0)})]})}function G6({id:e,summary:t,org:n,onNotFound:s,forecast:a}){const r=_b(),[o,l]=u.useState({state:"loading"}),c=u.useRef(0),d=Ts(),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:Jg,refusal:{status:409,message:Jg,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"&&!D_(v.refusal)?x:{state:"error",error:v.refusal.message,refusal:v.refusal})},[r,e,d]);u.useEffect(()=>{h()},[h]),Gc(u.useContext(qf),()=>void h(!1,!0));const f=o.state==="error"&&D_(o.refusal);if(u.useEffect(()=>{f&&s()},[f,s]),o.state==="loading")return i.jsxs(Cs,{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(we,{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(Cs,{children:[i.jsx("h2",{className:"text-lg font-semibold",children:(t==null?void 0:t.name)??e}),zE(o.refusal)?i.jsx(yb,{}):f?null:i.jsx(Qn,{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(Cs,{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(we,{variant:"neutral",children:"Planned"})]}),m.goal?i.jsx("p",{className:"text-muted-foreground text-sm",children:m.goal}):null]}),i.jsx(Yf,{pairs:[["Planned Release",i.jsx(di,{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(Xf,{title:"Members",count:m.members.length}),m.members.length>0?i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Members",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Member"}),i.jsx(Q,{children:"Level"}),i.jsx(Q,{children:"Tasks"}),i.jsx(Q,{children:"State"})]})}),i.jsx(st,{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(_e,{children:[i.jsx(X,{children:y.label}),i.jsx(X,{children:y.level?i.jsx(we,{variant:"neutral",children:H6(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(di,{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(OE,{rows:m.related,org:n,from:`planned:${m.id}`})]})]})}const H6=e=>e.charAt(0).toUpperCase()+e.slice(1);function _b(){return Vn().releases}const zu=5,jb=300,nu="candidate-notes-heading",Ks="candidate-note-field",$n={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 ${jb} 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."},PE=e=>[...e].length;function V6(e,t){var s;const n=e.trim();return n?/[\r\n\0]/.test(n)||PE(n)>jb?$n.long:n===(((s=t.edit)==null?void 0:s.value)??"").trim()?$n.same:null:$n.empty}function R_(e,t,n){return e===503?{variant:"info",...$n.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 IE({notice:e,id:t}){return i.jsxs(pe,{variant:e.variant,id:t,children:[e.variant==="info"?i.jsx(fn,{"aria-hidden":!0}):e.late?i.jsx(Pk,{"aria-hidden":!0}):i.jsx(jt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:e.title}),i.jsx(ge,{children:e.text})]})}function U6({gone:e,onDismiss:t,alert_ref:n}){return i.jsx("div",{ref:n,tabIndex:-1,className:"outline-none",children:i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:e.title}),i.jsxs(ge,{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 B6({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?`${Ks}-notice`:null,s?`${Ks}-problem`:null,`${Ks}-hint`,`${Ks}-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(IE,{notice:a,id:`${Ks}-notice`}):null,i.jsx(Ie,{htmlFor:Ks,children:"Note line"}),i.jsx(bt,{id:Ks,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:`${Ks}-problem`,children:i.jsx(Kn,{children:s})}):null,i.jsxs("p",{className:"text-muted-foreground flex flex-wrap gap-x-3 text-xs",children:[i.jsx("span",{id:`${Ks}-hint`,children:$n.hint}),i.jsx("span",{id:`${Ks}-count`,children:`${PE(t)} of ${jb}`})]}),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 T_({count:e,shown:t,onShow:n}){return t||e<=zu?null:i.jsxs(U,{variant:"link",size:"inline-sm",className:"self-start",onClick:n,children:["Show all ",e]})}function W6({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),I=u.useRef(null),L=u.useRef(null),$=u.useRef(null),A=u.useRef(!1),D=u.useRef(null),E=u.useRef(null),R=u.useRef(null),C=u.useRef(null),M=h||y,H=!!t&&!e.alert,z=u.useMemo(()=>new Map(e.sections.flatMap(G=>G.lines.map(Y=>[Y.key,Y]))),[e]),K=u.useMemo(()=>{var Y;const G=new Map;for(const te of e.sections)for(const ce of te.lines)(Y=ce.edit)!=null&&Y.clear&&G.set(ce.key,ce.text);for(const te of e.unapplied)for(const ce of te.lines)ce.clear&&G.set(ce.key,ce.text);return G},[e]),oe=u.useId(),re=u.useMemo(()=>new Map([...z.keys()].map((G,Y)=>[G,`${oe}-blocked-${Y}`])),[z,oe]);u.useEffect(()=>{var be,fe;if(!a||h)return;const G=z.get(a.key),Y=a.draft.trim(),te=Y?`What was typed: ${Y}`:"Nothing was typed.",ce=G&&!H?`${((be=e.alert)==null?void 0:be.title)??"Edits cannot be made now"}.`:((fe=G==null?void 0:G.edit)==null?void 0:fe.blocked)??null;!(G!=null&&G.edit)||ce?(r(null),w(ce?{title:$n.blocked,text:`${ce} ${te}`,typed:!!Y}:{title:$n.left,text:te,typed:!!Y}),E.current="gone"):a.start!==e.edit_start&&(r(null),E.current={key:a.key,then:"edit"})},[z,e,a,h,H]),u.useEffect(()=>{if(!m||y)return;const G=K.get(m.key);if(!(G===m.text&&H)){if(p(null),C.current===m.key&&G===void 0&&H){C.current=null,j($n.cleared),R.current={key:m.key,then:"edit"};return}C.current=null,w(Y=>{var te;return Y!=null&&Y.typed?Y:{title:H?G===void 0?$n.clear_gone:$n.changed:$n.unclearable,text:H?`Nothing was cleared: “${m.text}”`:`${((te=e.alert)==null?void 0:te.title)??"Edits cannot be made now"}. Nothing was cleared: “${m.text}”`}}),R.current="gone"}},[K,m,y,H,e]);const Ne=u.useRef(e);u.useEffect(()=>{e!==Ne.current&&S(null),Ne.current=e},[e]);const Se=u.useCallback(G=>{if(G==="gone"||G==="unread"){const be=(G==="gone"?I:L).current;return be==null||be.focus(),!!be}if(G==="field")return T.current?(T.current.focus(),T.current.select(),!0):!1;if(T.current)return!1;const Y=D.current,te=be=>Array.from((Y==null?void 0:Y.querySelectorAll(`[${be}]`))??[]).find(fe=>fe.getAttribute(be)===G.key)??null,ce=(G.then==="clear"?te("data-note-clear"):null)??te("data-note-edit")??(Y==null?void 0:Y.querySelector('[data-note-edit]:not([aria-disabled="true"]),[data-note-clear]'))??document.getElementById(nu);return ce==null||ce.focus(),!0},[]);u.useEffect(()=>{const G=E.current;G&&Se(G)&&(E.current=null)});const ae=G=>{M||!G.edit||G.edit.blocked||(r({key:G.key,draft:G.edit.value,start:e.edit_start}),l(null),d(null),j(""),E.current="field")},F=()=>{a&&(E.current={key:a.key,then:"edit"},r(null),l(null),d(null))},ie=async()=>{var fe,$e;if(!a||!t)return;const G=z.get(a.key);if(!G)return;const Y=V6(a.draft,G);if(l(Y),Y){d(null),(fe=T.current)==null||fe.focus();return}d(null),f(!0),s(!0);const te=a.key,ce=await t({key:te,text:a.draft.trim()});if(ce.ok){const ze=await n();s(!1),f(!1),r(null),S(ze===null?null:{write:"saved",error:ze}),j($n.saved),E.current=ze===null?{key:te,then:"edit"}:"unread";return}s(!1),f(!1);const be=ce.refusal;be.status===400?l(be.message):(d(R_(be.status,be.message,!1)),be.status===504&&n()),($e=T.current)==null||$e.focus()},W=G=>{M||(C.current=null,v(null),j(""),p(G))},se=async()=>{if(!m||!t||y)return;v(null),g(!0),s(!0);const G=m.key,Y=await t({key:G,clear:!0});if(Y.ok){const te=await n();s(!1),g(!1);const ce=Y.data.edit.cleared!==!1||C.current===G;C.current=null;const be=ce&&te!==null;S(be?{write:"cleared",error:te}:null),j(ce?$n.cleared:$n.nothing),R.current=be?"unread":{key:G,then:"edit"},p(null);return}s(!1),g(!1),v(R_(Y.refusal.status,Y.refusal.message,!0)),C.current=Y.refusal.status===504?G:null,Y.refusal.status===504&&n(),A.current=!0};u.useEffect(()=>{var G;!A.current||y||(A.current=!1,(G=$.current)==null||G.focus())});const Z=()=>{y||!m||(R.current={key:m.key,then:"clear"},p(null))},de=G=>{var be,fe,$e;if((a==null?void 0:a.key)===G.key&&G.edit)return i.jsx("li",{className:"border-b last:border-b-0",children:i.jsx(B6,{line:G,draft:a.draft,saving:h,problem:o,notice:c,onDraft:ze=>{r({...a,draft:ze}),o&&l(null)},onSave:()=>void ie(),onCancel:F,field_ref:T})},G.key);const Y=((be=G.edit)==null?void 0:be.blocked)??null,te=re.get(G.key),ce=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:[G.no_note?i.jsx("span",{className:"text-muted-foreground mr-2 text-xs",children:"no note"}):null,G.text]}),H&&G.edit?i.jsx(U,{variant:"link",size:"inline-sm","data-note-edit":G.key,"aria-label":`Edit: ${G.text}`,"aria-disabled":Y||ce?!0:void 0,"aria-describedby":Y?te:void 0,onClick:()=>!ce&&ae(G),children:"Edit"}):null]}),G.source?i.jsx("span",{className:"text-muted-foreground text-xs",children:G.source}):null,(G.issues??[]).map((ze,q)=>i.jsx("span",{className:"text-muted-foreground text-xs",children:ze},`issue:${q}`)),(G.served??[]).map((ze,q)=>i.jsx("span",{className:"text-muted-foreground text-xs",children:ze},`served:${q}`)),G.edited?i.jsxs("span",{className:"text-muted-foreground flex flex-wrap items-center gap-x-2 text-xs",children:[i.jsx("span",{children:G.edited.text}),H&&((fe=G.edit)!=null&&fe.clear)?i.jsx(U,{variant:"link",size:"inline-sm",className:"text-xs","data-note-clear":G.key,"aria-label":`Clear edit: ${G.text}`,"aria-disabled":ce||void 0,onClick:()=>!ce&&W({key:G.key,text:G.text,ask:`“${G.text}” goes back to its generated text, and the edit's text is lost.`}),children:"Clear edit"}):null]}):null,($e=G.edited)!=null&&$e.changed?i.jsxs("span",{className:"flex flex-wrap items-center gap-2 text-xs",children:[i.jsx(we,{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,Y?i.jsx("span",{id:te,className:"text-muted-foreground text-xs",children:Y}):null]},G.key)},J=G=>{const Y=N.has(`u:${G.key}`),te=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:[G.title," ",i.jsx("span",{className:"text-muted-foreground text-xs font-normal",children:G.count})]}),i.jsx("p",{className:"text-xs",children:G.summary}),G.start?i.jsxs("p",{className:"text-xs",children:[G.start.label," ",i.jsx("code",{className:"font-mono",children:G.start.sha})]}):null,i.jsx("ul",{className:"flex flex-col",children:(Y?G.lines:G.lines.slice(0,zu)).map(ce=>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:ce.text}),H&&ce.clear?i.jsx(U,{variant:"link",size:"inline-sm","data-note-clear":ce.key,"aria-label":`Clear edit: ${ce.text}`,"aria-disabled":te||void 0,onClick:()=>!te&&W({key:ce.key,text:ce.text,ask:G.key==="range"?`“${ce.text}”: its text is lost, and no Release can apply it afterwards.`:`“${ce.text}”: its text is lost.`}),children:"Clear edit"}):null]}),i.jsxs("span",{className:"text-xs",children:[ce.who,ce.range?` · made for the range from ${ce.range} · ${ce.key}`:` · ${ce.key}`]})]},ce.key))}),i.jsx(T_,{count:G.lines.length,shown:Y,onShow:()=>O(ce=>new Set(ce).add(`u:${G.key}`))})]},G.key)};return i.jsxs("section",{ref:D,className:"flex flex-col gap-3","aria-labelledby":nu,children:[i.jsxs("div",{className:"flex flex-wrap items-baseline gap-2",children:[i.jsx("h2",{id:nu,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(pe,{variant:"destructive",children:[i.jsx(jt,{"aria-hidden":!0}),i.jsx("p",{"data-slot":"alert-title",className:"col-start-2 font-medium",children:e.alert.title}),i.jsx(ge,{children:e.alert.text})]}):null,x?i.jsx(U6,{gone:x,alert_ref:I,onDismiss:()=>{var G;w(null),(G=document.getElementById(nu))==null||G.focus()}}):null,_?i.jsx("div",{ref:L,tabIndex:-1,className:"outline-none",children:i.jsxs(pe,{variant:"warning",children:[i.jsx(jt,{"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(ge,{children:$n.refresh})]})}):null,e.none?i.jsx("p",{className:"text-muted-foreground text-sm",children:e.none}):null,e.sections.map(G=>{const Y=N.has(G.key)||G.lines.slice(zu).some(te=>te.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:[G.title," ",G.count?i.jsx("span",{className:"text-muted-foreground text-xs font-normal",children:G.count}):null]}),G.summary?i.jsx("p",{className:"text-muted-foreground text-xs",children:G.summary}):null,i.jsx("ul",{className:"flex flex-col",children:(Y?G.lines:G.lines.slice(0,zu)).map(de)}),i.jsx(T_,{count:G.lines.length,shown:Y,onShow:()=>O(te=>new Set(te).add(G.key))})]},G.key)}),e.unapplied.map(J),i.jsx(bf,{open:m!==null,onOpenChange:G=>{G||Z()},children:i.jsxs(yf,{onEscapeKeyDown:G=>{y&&G.preventDefault()},onCloseAutoFocus:G=>{G.preventDefault();const Y=R.current;R.current=null,Y&&!Se(Y)&&(E.current=Y)},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(IE,{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:Z,children:"Cancel"}),i.jsx(U,{ref:$,type:"button",variant:"destructive",size:"sm",loading:y,onClick:()=>void se(),children:y?"Clearing…":"Clear"})]})]})})]})}const Is={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"},O_=3,F6=["in_progress","not_started","planned","blocked"],Nb="Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" "),Kt=e=>e.charAt(0).toUpperCase()+e.slice(1);function pp(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(String(e??""));return t?`${Number(t[3])} ${Nb[Number(t[2])-1]}`:String(e??"")}function GE(e){if(typeof e!="number")return"";const t=new Date(e*1e3);return Number.isNaN(t.getTime())?"":`${t.getDate()} ${Nb[t.getMonth()]} ${String(t.getHours()).padStart(2,"0")}:${String(t.getMinutes()).padStart(2,"0")}`}function q6(e){if(typeof e!="number")return"";const t=new Date(e*1e3);return Number.isNaN(t.getTime())?"":`${t.getDate()} ${Nb[t.getMonth()]}`}function Ei(e){return e?e.from===e.to&&e.or_later?`${pp(e.from)} or later`:`${pp(e.from)} to ${pp(e.to)}${e.or_later?", or later":""}`:""}function Y6(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 HE(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??"")?"":Y6(t)].filter(Boolean).join(" · "),r=t.projected?Ei(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 ${Ei({...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?Kt(r):"",caption:h}}function X6(e){const t=e.kinds??[];return[t.includes("range")?"Not promised":"",e.goal??(t.includes("major")?"No goal yet":"")].filter(Boolean).join(" · ")}function K6(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 VE=e=>String(e??"").replace(/_/g," ");function Z6(e){const t=e??{},n=t.kinds??[],s=n.includes("slipped"),a=!s&&t.was&&t.now?Ei(t.was)===Ei(t.now)?`, range still ${Ei(t.now)}`:`, range was ${Ei(t.was)}, now ${Ei(t.now)}`:"",r=[s&&t.was?`was ${Ei(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?Kt(r.join(" · ")):"",what:o}}const Ao="roadmap",z_={reading:!1,value:null,refusal:null};function Q6(e){const[t,n]=u.useState({all:z_,mine:z_}),s=u.useRef({all:0,mine:0}),a=Ts(),r=Ts(),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 J6(e,t){return`${e} open${t.length?` · ${t.join(", ")} moved since you looked`:""}`}function dc({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 UE=({level:e})=>e?i.jsx(we,{variant:"neutral",children:Kt(e)}):null;function BE({state:e}){const t=Kt(VE(e));return F6.includes(String(e))?i.jsx("span",{className:"font-medium",children:t}):i.jsx("span",{children:t})}function eU({reads:e,scope:t,onScope:n,onRead:s,org:a,onSelect:r}){var p,y;const o=e[t],l=o.value,c=ns(),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 ${GE(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(Cs,{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(vn,{"aria-hidden":!0,className:"size-4"})," ",Kt(Is.pending),"…"]}):null}),o.refusal&&!o.reading?o.refusal.reason==="no_roadmap"?i.jsx(Qn,{title:Is.failedLead,error:`${Kt(Is.noEngineLead)}. ${c}`}):o.refusal.reason==="refused"?i.jsx(Qn,{title:Is.failedLead,error:o.refusal.message}):i.jsx(Qn,{title:Is.failedLead,error:o.refusal.message,onRetry:f}):null,l?t==="mine"?i.jsx(oU,{mine:l.mine,org:a,onSelect:r}):i.jsx(nU,{read:l,org:a,onSelect:r}):null]})}function tU(e){if(!e||typeof e.seconds_per_day!="number")return"No rate";const t=q6(e.as_of);return`${Math.round(e.seconds_per_day/3600)} task hours a day over the ${e.days} days${t?` to ${t}`:""}`}function nU({read:e,org:t,onSelect:n}){var a,r;const s=e.releases??[];if(!s.length){const[o,l]=Is.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(dc,{children:l})]})}return i.jsxs(i.Fragment,{children:[i.jsx(Yf,{pairs:[["Forecast from",Kt(`${((a=e.source)==null?void 0:a.machine)||"this machine"}'s task records and rate`)],["Rate",tU(e.rate)],["Not counted",Kt(((r=e.source)==null?void 0:r.not_counted)||"other machines' work")]]}),s.map(o=>i.jsx(sU,{row:o,org:t,onSelect:n},o.id))]})}function sU({row:e,org:t,onSelect:n}){var f,m,p;const s=HE(e.forecast),a=K6(e),r=X6(e),o=`roadmap-${e.id}`,l=e.moved?Z6(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(ur,{query:`planned=${encodeURIComponent(e.id)}`,select:Us(e.id),onSelect:n,children:e.name})}),e.kinds.map(y=>i.jsx(we,{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:Kt(s.caption.join(" · "))}):null]}):null,h?i.jsx("p",{className:"text-muted-foreground text-sm",children:h}):null,l?i.jsxs(pe,{variant:"info",children:[i.jsx(RO,{"aria-hidden":!0}),i.jsx(ke,{children:"Moved since you looked"}),i.jsxs(ge,{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:Kt(e.stale_unchecked.words)}):null,e.for_you&&e.kinds.includes("major")?i.jsx(iU,{row:e}):null,i.jsx(rU,{row:e,org:t})]})}function iU({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?`${Kt(a).replace(/\.$/,"")}. `:"","Accept or reject in the terminal:"]}),i.jsx(dc,{children:s.accept}),i.jsx(dc,{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(dc,{children:t.set_goal})]}):null]})}function WE({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 aU(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?Kt(e.nobody):""}function rU({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_),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(nt,{containerAriaLabel:`Next in ${e.name}`,children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Member"}),i.jsx(Q,{children:"Level"}),i.jsx(Q,{children:"State"}),i.jsx(Q,{children:"Who is on it"})]})}),i.jsx(st,{children:r.map(l=>{const c=o.get(l.item);return i.jsxs(_e,{children:[i.jsx(X,{children:i.jsxs("div",{className:"flex flex-col gap-0.5",children:[i.jsx(WE,{next:l,org:t}),c?i.jsxs("span",{className:"text-muted-foreground text-xs",children:[Kt(c.words),c.estimate_as_of?` (estimated ${GE(c.estimate_as_of)})`:""]}):null]})}),i.jsx(X,{children:i.jsx(UE,{level:l.level})}),i.jsx(X,{children:i.jsx(BE,{state:l.state})}),i.jsx(X,{children:aU(l,e)})]},l.item)})})]})}),a.length>O_&&!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 oU({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:Kt(Is.noTask)}):i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Your work",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Task"}),i.jsx(Q,{children:"Release"}),i.jsx(Q,{children:"Member"})]})}),i.jsx(st,{children:e.tasks.map(o=>{var l,c;return i.jsxs(_e,{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,Kt(VE(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(ur,{query:`planned=${encodeURIComponent(d.planned_release)}`,select:Us(d.planned_release),onSelect:n,children:d.name})},d.planned_release)):o.release?i.jsx(ur,{query:`planned=${encodeURIComponent(o.release.planned_release)}`,select:Us(o.release.planned_release),onSelect:n,children:o.release.name}):i.jsx("span",{className:"text-muted-foreground",children:o.words?Kt(o.words):"—"})}),i.jsx(X,{children:(c=o.members)!=null&&c.length?o.members.map(d=>i.jsx(UE,{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(dc,{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:Kt(Is.noNext)}):i.jsx("div",{className:"overflow-x-auto",children:i.jsxs(nt,{containerAriaLabel:"Your next members",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Release"}),i.jsx(Q,{children:"Member"}),i.jsx(Q,{children:"State"})]})}),i.jsx(st,{children:e.next.map(o=>i.jsxs(_e,{children:[i.jsx(X,{children:i.jsx(ur,{query:`planned=${encodeURIComponent(o.release)}`,select:Us(o.release),onSelect:n,children:o.name})}),i.jsx(X,{children:i.jsx(WE,{next:o,org:t})}),i.jsx(X,{children:i.jsx(BE,{state:o.state})})]},`${o.release}:${o.item}`))})]})})]})]})}function lU({state:e,id:t}){var r;const n=ns();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(vn,{"aria-hidden":!0,className:"size-4"})," ",Kt(Is.pending),"…"]});if(e.refusal){const o=e.refusal.reason==="no_roadmap"?`${Kt(Is.noEngineLead)}. ${n}`:e.refusal.message;return i.jsx("p",{className:"text-muted-foreground text-xs",children:`${Is.failedLead}: ${o}`})}return null}const a=HE(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:Kt(a.caption.join(" · "))}):null]})}function kb(){const e=Vn().releases;if(!e)throw new Error("The Releases page rendered without a Releases contract.");return e}function cU({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 Le,Fe,Et,gs,Yi,wi,Xi,zr,Mr,$r;const m=kb(),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,I]=u.useState(null),[L,$]=u.useState(!1),[A,D]=u.useState(null),[E,R]=u.useState(null),C=u.useRef(null),M=p?{fresh:!0}:void 0,H=u.useRef(0),z=Ts(),K=u.useCallback(async(Te,et=!1,an=!1)=>{if(et&&!an&&z.busy())return"A read is still running.";const Mn=++H.current,Bn=await z.track(m.candidate(Te)),xs=Bn.ok?null:Bn.refusal.message;return Mn!==H.current||j(_i=>Bn.ok?{state:"ready",value:Bn.data.candidate}:et&&_i.state==="ready"?_i:{state:"error",error:Bn.refusal.message,refusal:Bn.refusal}),xs},[m,z]),oe=u.useRef(!1),re=u.useCallback(async()=>{j({state:"loading"}),await K(M)},[K,y]),Ne=u.useCallback(async()=>{const Te=await m.list();Te.ok&&b(Te.data)},[m]),Se=((Le=g.release_branch)==null?void 0:Le.id)??null;u.useEffect(()=>{if(!(!y&&!Se))return K(),()=>{H.current+=1}},[Se,K,y]);const ae=u.useRef(new Set),F=u.useCallback((Te,et)=>O(an=>({...an,[Te]:et.ok?{state:"ready",value:et.data.release}:{state:"error",error:et.refusal.message,refusal:et.refusal}})),[]),ie=async Te=>{O(et=>({...et,[Te]:{state:"loading"}})),ae.current.add(Te),F(Te,await m.release(Te,M))},W=k.state!=="ready"||k.value!==null,se=C6(w),Z=Q6(p?m:void 0),de=Z.available&&w===Ao,[J,G]=u.useState("all"),Y=g.release_branch||p?W?Zs:null:((Fe=g.releases[0])==null?void 0:Fe.version)??null,te=se!==null||de?null:w===Zs?W?Zs:null:w??Y,[ce,be]=u.useState([]),fe=u.useRef(0),$e=u.useRef(0),ze=Ts(),q=u.useCallback(()=>{if(!y||!m.roadmapMoved)return;const Te=$e.current,et=fe.current;ze.track(m.roadmapMoved()).then(an=>{Te===$e.current&&an.ok&&et===fe.current&&be(an.data.moved.map(Mn=>Mn.name))})},[m,y,ze]);u.useEffect(()=>(q(),()=>{$e.current+=1}),[q]),Gc(f,()=>{ze.busy()||q()});const ve=Z.reads.all,Ve=Z.read;u.useEffect(()=>{se===null||!Z.available||!ve.value&&!ve.reading&&!ve.refusal&&Ve("all")},[se,Z.available,ve,Ve]);const[Ft,Qt]=u.useState(0),ht=u.useRef(0),it=Te=>{Te===Ao&&Qt(et=>et+1),_(Te)};u.useEffect(()=>{if(Ft!==ht.current){if(!de){ht.current=Ft;return}J!=="all"||ve.reading||!ve.value||!m.roadmapSeen||(ht.current=Ft,m.roadmapSeen(ve.value.as_of).then(Te=>{Te.ok&&(fe.current+=1,be([]))}))}},[Ft,de,J,ve,m]);const Lt=new Map((((Et=ve.value)==null?void 0:Et.releases)??[]).map(Te=>[Te.id,[Te.kinds.includes("range")?"range":"",Te.forecast.projected?Ei(Te.forecast.projected):"no date"].filter(Boolean).join(" · ")])),Dt=te===null||te===Zs||g.releases.some(Te=>Te.version===te);u.useEffect(()=>{!p||!c||te!==null&&te!==Zs&&!Dt&&c({kind:"release",id:te})},[p,c,te,Dt]),u.useEffect(()=>{!te||te===Zs||ae.current.has(te)||p&&!Dt||(ae.current.add(te),m.release(te).then(Te=>F(te,Te)))},[te,m,F,Dt]);const On=Ts();Gc(f,()=>{if(p){if(oe.current||K(void 0,!0),te&&te!==Zs&&Dt&&!On.busy()){const Te=te;On.track(m.release(Te)).then(et=>{et.ok&&F(Te,et)})}de?Ve(J,!1,!0):se!==null&&ve.value&&Ve("all",!1,!0)}});const mn=u.useRef(w),Sn=u.useRef(!1),xe=u.useRef(!!h),ne=u.useRef(null);u.useEffect(()=>{var et,an;if(!p)return;if(xe.current){const Mn=(et=ne.current)==null?void 0:et.querySelector('[aria-current="true"]');if(Mn){xe.current=!1,mn.current=w,Mn.focus();return}}if(mn.current!==w&&(mn.current=w,Sn.current=!0),!Sn.current)return;const Te=(an=C.current)==null?void 0:an.querySelector("h2");Te&&(Sn.current=!1,Te.tabIndex=-1,Te.focus())});const ye=async Te=>{if(!s)return;I(null);const et=await s(Te);if(!et.ok){I(et.error);return}x(null),j({state:"loading"}),await Ne()},qe=async()=>{if(!g.next_before)return;R(null);const Te=await m.list({before:g.next_before});if(!Te.ok){R(Te.refusal.message);return}b(et=>({...Te.data,releases:[...et.releases,...Te.data.releases]}))},xt=g.release_branch?i.jsx(dU,{value:g.release_branch.id,label:g.release_branch.name,options:n??[],can_write:g.can_write,onChange:ye}):null,ss=p?i.jsxs("div",{className:"flex items-center gap-2",children:[i.jsxs("span",{className:"text-muted-foreground text-xs",children:["Read at ",As(p.read_at)]}),l?i.jsxs(U,{variant:"ghost",size:"sm",onClick:l,children:[i.jsx(Er,{className:"mr-1 size-4","aria-hidden":!0}),"Read again"]}):null]}):xt,zn=p?D6(((gs=g.releases[0])==null?void 0:gs.label)??((Yi=g.releases[0])==null?void 0:Yi.version)??null):u6(((wi=g.releases[0])==null?void 0:wi.version)??null,((Xi=g.release_branch)==null?void 0:Xi.name)??null),B={org:o??""};return i.jsxs(qf.Provider,{value:f,children:[i.jsx(_E,{description:p?DE:void 0,actions:ss}),d,p?i.jsx(E6,{}):null,T?i.jsx(Qn,{error:T}):null,p?null:t,!p&&!g.release_branch?i.jsx(uU,{can_write:g.can_write,options:n??[],onChoose:ye}):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(hU,{list:g,candidate:S?k:null,shown:de?Ao:se!==null?Us(se):te,onSelect:it,roadmap:Z.available?J6(((zr=g.planned)==null?void 0:zr.length)??0,ce):null,planned_ranges:Lt,can_load_older:!!g.next_before,older_error:E,onLoadOlder:qe}),i.jsx("div",{className:"min-w-0 flex-1",ref:C,children:de?i.jsx(eU,{reads:Z.reads,scope:J,onScope:G,onRead:Ve,org:B.org,onSelect:_}):se!==null?i.jsx(G6,{id:se,summary:((Mr=g.planned)==null?void 0:Mr.find(Te=>Te.id===se))??null,org:B.org,onNotFound:()=>c==null?void 0:c({kind:"planned",id:se}),forecast:Z.available?i.jsx(lU,{state:ve,id:se}):null}):te===Zs?i.jsx(mU,{candidate:k,branch_name:(($r=g.release_branch)==null?void 0:$r.name)??null,can_write:g.can_write&&!!a,local:!!p,org:B.org,onSelect:_,onRetry:re,onWrite:()=>$(!0),onChanged:()=>void K(M,!0,!0),onReread:()=>K(M,!0,!0),onNotesBusy:Te=>{oe.current=Te}}):te?i.jsx(pU,{detail:N[te]??{state:"loading"},summary:g.releases.find(Te=>Te.version===te)??null,local:!!p,org:B.org,onSelect:_,onRetry:()=>ie(te)}):(g.release_branch||p)&&k.state==="ready"?i.jsx(d6,{title:zn.title,text:zn.text}):null})]}):null,a&&k.state==="ready"&&k.value?a({candidate:k.value,open:L,notice:A,onOpenChange:Te=>{Te||D(null),$(Te)},onStale:async Te=>{D(Te),await K()},onWritten:async Te=>{$(!1),D(null),await Ne(),x(Te),await re()}}):null]})}function dU({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(wt,{id:"release-branch",children:i.jsx(Ct,{})}),i.jsxs(_t,{children:[r?null:i.jsx(Ue,{value:e,children:t??"Unnamed branch"}),n.map(o=>i.jsx(Ue,{value:o.id,children:o.label},o.id))]})]}),s?null:i.jsx(FE,{})]})}function FE(){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 uU({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(Dc,{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(wt,{id:"release-branch-first",children:i.jsx(Ct,{placeholder:"Choose a branch"})}),i.jsx(_t,{children:t.map(s=>i.jsx(Ue,{value:s.id,children:s.label},s.id))})]})]}),e?null:i.jsx(FE,{})]})}function qE({children:e}){return i.jsx("p",{className:"text-muted-foreground px-3 pt-3 text-xs font-medium tracking-wide uppercase",children:e})}function hU({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?Ic(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(Ou,{active:n===Ao,onClick:()=>s(Ao),version:"Roadmap",badges:null,caption:a}):null,t&&(t.state!=="ready"||t.value)?i.jsx(Ou,{active:n===Zs,onClick:()=>s(Zs),version:t.state==="ready"&&t.value?t.value.version:"Next release",badges:i.jsxs(i.Fragment,{children:[i.jsx(we,{variant:"info",children:"Candidate"}),h!=null&&h.breaking?i.jsx(we,{variant:"error",children:"Breaking"}):t.state==="ready"&&((f=t.value)==null?void 0:f.app_changed)===!1?i.jsx(we,{variant:"neutral",children:"App unchanged"}):t.state==="ready"&&((m=t.value)!=null&&m.classification)?i.jsx(we,{variant:"neutral",children:t.value.classification.bump}):null]}),caption:t.state==="loading"?"Classifying…":t.state==="error"?"Could not be read":jE(t.value)}):null,d?i.jsx(fU,{list:e,shown:n,onSelect:s,ranges:r}):null,d&&e.releases.length>0?i.jsx(qE,{children:"Released"}):null,e.releases.map(p=>{const y=d?A6(p):null;return i.jsx(Ou,{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(we,{variant:"neutral",children:p.previous_release_id?p.bump??"patch":"First"}),p.breaking?i.jsx(we,{variant:"error",children:"Breaking"}):null]}),caption:(y==null?void 0:y.caption)??bb(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 fU({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(qE,{children:"Planned"}),e.planned_error?i.jsx(Qn,{title:"Planned Releases could not be read",error:e.planned_error}):null,(e.planned??[]).map((a,r)=>i.jsx(Ou,{active:t===Us(a.id),onClick:()=>n(Us(a.id)),version:a.name,badges:i.jsx(we,{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 mU({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=kb(),m=ns();if(e.state==="loading")return i.jsx(Cs,{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(Cs,{children:i.jsx(Qn,{error:e.error,onRetry:o})});const p=e.value;if(!p)return null;const y=Ic(p.changes),g=!p.previous_release,b=t??"the release branch";return i.jsxs(Cs,{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(we,{variant:"info",children:"Candidate"}),y.breaking?i.jsx(we,{variant:"error",children:"Breaking"}):p.app_changed===!1?i.jsx(we,{variant:"neutral",children:"App unchanged"}):p.classification?i.jsx(we,{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: `,jE(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(Dc,{className:"mr-2 size-4"}),"Write Release ",p.next_version]}):null]}),s?i.jsx(L6,{candidate:p,org:a,onSelect:r,onChanged:c,notes:g?null:p.notes?i.jsx(W6,{notes:p.notes,edit:f.editNote,reread:d,onBusy:h}):i.jsxs(i.Fragment,{children:[i.jsx(Th,{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(Th,{changes:p.changes})]})}function pU({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(Cs,{children:[i.jsx("h2",{className:"text-lg font-semibold",children:t.label??t.version}),i.jsx(Qn,{title:"This Release could not be read",error:t.error??"Its record cannot be read."})]});if(e.state==="loading")return i.jsx(Cs,{children:i.jsx("p",{className:"text-muted-foreground text-sm",role:"status",children:"Loading the Release…"})});if(e.state==="error")return i.jsx(Cs,{children:i.jsx(Qn,{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(l6(f,Ic(c.changes))),l(!0)};return i.jsxs(Cs,{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(P6,{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(we,{variant:"neutral",children:d?"First":c.bump}),Ic(c.changes).breaking?i.jsx(we,{variant:"error",children:"Breaking"}):null]}),i.jsxs("p",{className:"text-muted-foreground text-sm",children:["Written ",bb(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(gv,{className:"mr-2 size-4"}),o?"Copied":"Copy notes"]})]}),n?i.jsx(I6,{release:c,org:s,onSelect:a,notes:d?null:i.jsx(Th,{changes:c.changes})}):d?null:i.jsx(Th,{changes:c.changes})]})}const gU=5,xU=1e4,vU=e=>e.retry===!0||e.reason==="store_locked"||e.status===503;function bU({org:e,query:t,onSelect:n,home:s}){var C;const a=kb(),{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),_=cb(v),S=Ts(),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&&vU(K.refusal)){w.current=H,m(K.refusal.retry_after??gU);return}h(K.refusal)}},[a,S]);u.useEffect(()=>{k(!1)},[k]);const j=u.useMemo(()=>Uf(S,()=>void k(!1,!0)),[k,S]);Wi(j,xU),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?Ao:t.planned!==null?t.planned===""?(C=O==null?void 0:O.planned)!=null&&C[0]?Us(O.planned[0].id):null:Us(t.planned):t.release,I=`${t.release??""}|${t.planned??""}|${t.roadmap?"roadmap":""}`,L=u.useRef(I);u.useEffect(()=>{L.current!==I&&(L.current=I,y(null))},[I]);const $=u.useRef(!1),A=u.useCallback(M=>{$.current=!0,y(M)},[]),D=!p&&l.state==="ok"&&$.current;if(u.useEffect(()=>{D&&($.current=!1)},[D]),p)return i.jsx(Ha,{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 E=f!==null?i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status","aria-live":"polite",children:[i.jsx(vn,{"aria-hidden":!0})," The release records are busy; reading again in ",f," s…"]}):null,R=d?i.jsxs(pe,{ref:_,variant:"destructive",children:[i.jsx(jt,{}),i.jsx(ke,{children:"Releases could not be read"}),i.jsxs(ge,{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(cU,{initial:l.list,tick:l.tick,org:e,selection:{selected:T,onSelect:n},onReadAgain:N,onNotFound:A,notice:E||R?i.jsxs(i.Fragment,{children:[E,R]}):null,focusOnMount:D},l.gen):l.state==="engine_missing"?i.jsx(yi,{page:"Releases"}):i.jsxs(i.Fragment,{children:[i.jsx(_E,{description:DE}),R??E??i.jsxs("p",{className:"text-muted-foreground flex items-center gap-2 text-sm",role:"status","aria-live":"polite",children:[i.jsx(vn,{"aria-hidden":!0})," Loading Releases…"]})]})})}const yU=1e4;function YE(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]),Wi(u.useCallback(()=>void r(),[r]),yU),t}const wU={threads:"Threads",tasks:"Tasks",queues:"Queues",blockers:"Blockers",worktrees:"Worktrees",workspaces:"Workspaces",chart:"Org chart"},_U={tasks:"Tasks",issues:"Issues",releases:"Releases"};function uc(e,t){return e.kind==="home"?"Home":e.kind==="org"?wU[e.page]:e.kind==="project"?e.page?_U[e.page]:t??e.project:"Not found"}const jU="(max-width: 767px)";function NU(){const e=typeof window<"u"&&window.matchMedia?window.matchMedia(jU):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 su({className:e=""}){return i.jsx("span",{"aria-hidden":"true",className:`block animate-pulse rounded-md bg-sidebar-accent ${e}`})}function M_({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 XE(e){return`${e} open ${e===1?"issue":"issues"}`}const KE="ml-auto shrink-0 text-2xs font-medium tabular-nums text-muted-foreground";function kU(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 $_({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:` · ${XE(e.open)}`}),i.jsx("span",{"aria-hidden":"true",className:KE,children:e.open})]})]})});return i.jsx("li",{children:a?i.jsxs(wd,{children:[i.jsx(_d,{asChild:!0,children:r}),i.jsx(ol,{side:"right",children:a})]}):r})}const L_="m-0 flex list-none flex-col gap-1 p-0";function P_({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 I_({page:e,collapsed:t,sheet:n=!1}){var C,M;const{href:s}=lt(),{worktrees:a,blockers:r,issues:o}=Vn(),l=ts(),{org:c,projects:d,loading:h,none:f,about:m,aboutFailed:p,domains:y,engine:g}=l,b=YE(o==null?void 0:o.summary),v=kU(b,((C=c==null?void 0:c.source)==null?void 0:C.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,I=[{label:"Home",href:s(w||"/"),icon:Vk,current:e.kind==="home"},...x?[]:[{label:"Threads",href:s(`${w}/threads`),icon:Cc,current:e.kind==="org"&&e.page==="threads"}],...y.includes("tasks")&&!x?[{label:N,title:T(N),href:s(`${w}/tasks`),icon:lf,current:e.kind==="org"&&e.page==="tasks"}]:[],...x?[]:[{label:O,title:T(O),href:s(`${w}/queues`),icon:bv,current:e.kind==="org"&&e.page==="queues"}],...r&&!x?[{label:"Blockers",href:s(`${w}/blockers`),icon:Hk,current:e.kind==="org"&&e.page==="blockers"}]:[],...a&&!x?[{label:"Worktrees",href:s(`${w}/worktrees`),icon:vv,current:e.kind==="org"&&e.page==="worktrees"}]:[],{label:j,title:T(j),href:s(`${w}/workspaces`),icon:Gk,current:e.kind==="org"&&e.page==="workspaces"},{label:"Org chart",href:s(`${w}/chart`),icon:Uk,current:e.kind==="org"&&e.page==="chart"}],L=h?null:f?"No organization":(c==null?void 0:c.name)??"Organization",$=c?Tz(c):null,A=m==null?void 0:m.version,D=A?t?A:`sdlc ${A}`:p?ph:hf,E=p||(m==null?void 0:m.sync.state)==="unknown"?Ez:m===void 0?Dz:Cz;let R;return h?R=i.jsx("div",{className:"px-2 py-1",children:i.jsxs(M_,{label:"Loading projects",children:[i.jsx(su,{className:"h-4 w-32"}),i.jsx(su,{className:"h-4 w-24"})]})}):d?R=i.jsx("ul",{className:L_,children:d.map(H=>i.jsx($_,{collapsed:t,item:{label:H.name,title:H.name,href:s(`/proj/${encodeURIComponent(H.id)}`),icon:Ik,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":ph}),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(sO,{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(M_,{label:"Loading organization",children:[i.jsx(su,{className:"h-4 w-28"}),i.jsx(su,{className:"h-3 w-24"})]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"truncate font-semibold",title:L,children:L}),$&&i.jsxs("span",{className:"truncate text-xs text-sidebar-foreground/70",children:[$,v.header!==void 0&&i.jsx("span",{className:"sr-only",children:` · ${XE(v.header)} in the folder`})]})]})}),!t&&L!==null&&v.header!==void 0&&i.jsx("span",{"aria-hidden":"true",className:`${KE} px-2`,children:v.header})]}),i.jsxs("nav",{"aria-label":"App",className:"min-h-0 flex-1 overflow-y-auto",children:[i.jsx(P_,{label:"Organization",collapsed:t,children:i.jsx("ul",{className:L_,children:I.map(H=>i.jsx($_,{item:H,collapsed:t},H.label))})}),!t&&i.jsx(P_,{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(EO,{className:"mt-0.5 size-4 shrink-0","aria-hidden":"true"}),i.jsx("span",{children:E})]})]})]})}const SU="outline-hidden rounded-sm focus-visible:ring-2 focus-visible:ring-ring";function CU({page:e}){var c;const{href:t,Link:n}=lt(),{org:s,projects:a,loading:r,none:o}=ts(),l=[];if(r)l.push({label:hf});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:uc(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:uc(e),href:t(h)}),l.push({label:e.item})}else e.kind!=="home"&&!(e.kind==="project"&&!e.page)&&l.push({label:uc(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(ld,{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 ${SU}`,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 DU({action:e}){const t=e.icon;return i.jsxs(wd,{children:[i.jsx(_d,{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(ol,{side:"bottom",children:e.label})]})}function ZE({page:e,headerActions:t,children:n}){var x;const s=NU(),[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}=ts(),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?hf:p?"No organization":(h==null?void 0:h.name)??"Organization",_=(e.kind==="org"||e.kind==="project")&&e.item!==void 0?`${e.item} · `:"";document.title=`${_}${uc(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 I;if(k.key==="Escape"){l(!1),(I=c.current)==null||I.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(sb,{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(I_,{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(I_,{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(dd,{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(JO,{className:"size-4","aria-hidden":"true"})}),i.jsx("span",{"aria-hidden":"true",className:"mr-2 h-4 w-px bg-border"}),i.jsx(CU,{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(DU,{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 Sb="m-0 text-2xl font-semibold tracking-tight",Cb="outline-hidden focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",Db=`rounded-sm font-medium text-primary no-underline hover:underline ${Cb}`;function gp({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 EU({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(gp,{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(gp,{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(gp,{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?vr:Rz})]})}const G_=`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 ${Cb}`;function AU(){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 hl(){const{href:e,Link:t}=lt(),{loading:n,projects:s,none:a,failure:r,readAt:o,refresh:l,reading:c}=ts(),[d,h]=u.useState(""),f=i.jsxs("div",{className:"flex flex-col gap-1",children:[i.jsx("h1",{className:Sb,children:"Projects"}),!a&&i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:Az})]});if(a)return i.jsxs("div",{className:"flex flex-col gap-4 p-6",children:[f,i.jsx(EU,{why:a==="not_in_git"?{kind:"not_in_git"}:$z(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:Wk(m.refusal,o)}),i.jsx("div",{children:i.jsx("button",{type:"button",className:G_,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 ${Cb}`}),!m&&i.jsx("button",{type:"button",className:`${G_} 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 ${Il(o)}; reading again in ${r.retryInSeconds??10} seconds.`})]}),n?i.jsx(AU,{}):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:Db,children:y.name})}),i.jsx("td",{className:"px-3 py-2 font-mono text-muted-foreground",children:y.location??ph}),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 QE({title:e,children:t}){const{href:n,Link:s}=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:Sb,children:e}),i.jsx("p",{className:"m-0 text-sm text-muted-foreground",children:t}),i.jsx("div",{children:i.jsx(s,{href:n("/"),className:`text-sm ${Db}`,children:"Back to the organization's Home"})})]})})}const RU={tasks:"Tasks",issues:"Issues",releases:"Releases"};function Hc({project:e}){const{href:t,Link:n}=lt(),{org:s,projects:a,loading:r,domains:o}=ts(),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:hf}):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:Sb,children:l.name}),i.jsx("p",{className:"m-0 font-mono text-sm text-muted-foreground",children:l.location??ph})]}),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:Db,children:RU[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.jsx(QE,{title:"Project not found",children:`There is no project '${e}' in this organization.`}):i.jsx(hl,{})}const Nd=e=>e instanceof Error?e.message:String(e);async function JE(e=!1){try{const t=await fetch(e?"api/threads?archived=1":"api/threads",{cache:"no-store"});return t.status===404?{none:!0}:t.ok?{data:await t.json()}:{error:await t.text()||`HTTP ${t.status}`}}catch(t){return{error:Nd(t)}}}async function TU(){var e;try{const t=await fetch("api/release-links?threads",{cache:"no-store"});if(!t.ok)return 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 OU(){try{return(await fetch("api/pin",{method:"HEAD",cache:"no-store"})).ok}catch{return!1}}async function zU(){try{const e=await fetch("api/sessions",{cache:"no-store"});if(!e.ok)return 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 MU(){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:Nd(e)}}}async function eA(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:Nd(n)}}}}async function $U(){try{return(await fetch("api/threads/archive",{method:"HEAD",cache:"no-store"})).ok}catch{return!1}}async function LU(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 PU(e){try{const t=await fetch(`api/threads/archive?key=${encodeURIComponent(e)}`,{cache:"no-store"});if(!t.ok)return 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 IU(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?null:await LU(n)}catch(n){return Nd(n)}}async function GU(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?null:await n.text()||`HTTP ${n.status}`}catch(n){return Nd(n)}}const HU={probe:{source:async()=>{const e=await JE();if("error"in e)throw new Error(e.error);return{label:"Local workspace"}}}},Mu={href:e=>e.replace(/^\/+/,"")||"./",Link:({href:e,className:t,children:n,...s})=>i.jsx("a",{href:e,className:t,...s,children:n})},VU={label:"Local viewer",can:()=>!1};function UU(){return u.useEffect(()=>{document.title="Shared app UI · SDLC Workspace Viewer"},[]),i.jsx("div",{className:"app-ui dark",children:i.jsx(_g,{data:HU,router:Mu,identity:VU,children:i.jsx(I2,{})})})}const H_="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.",$u=15,BU="New waits that would close a loop are refused. One thread hands its part over or asks the user.",WU="Threads in line for a queue are on Queues; threads that wait on you are marked Needs you on Threads.";function FU(){const e=Vn().blockers;if(!e)throw new Error("The Blockers page rendered without the blockers seam.");return e}const hr=(e,t,n)=>`${e} ${e===1?t:n}`;function tx(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 qU(e,t){return t?e===null?`Not reading · trying again every ${$u}s`:`Not reading since ${Xn(e/1e3)} · trying again every ${$u}s`:e===null?"Connecting…":`Live · read ${Xn(e/1e3)} · refreshes every ${$u}s`}function YU(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 ${tx(e.heard_hours)}`):e.heard_hours!==null&&t.push(`heard ${tx(e.heard_hours)} ago`),t.join(" · ")}function XU(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 KU(e,t){const n=hr(e.blocked_threads,"thread waits","threads wait"),s=`in ${hr(t,"wait loop","wait loops")}`;return e.blockers?`${n} on ${hr(e.blockers,"blocker","blockers")}${t?` and ${s}`:""}`:`${n} ${s}`}const ZU=e=>e.replace(/\s*\(status release\)$/,"");function QU({org:e}){const t=FU(),n=ns(),[s,a]=u.useState(null),[r,o]=u.useState(null),l=Ts(),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(()=>Uf(l,()=>void d(!1)),[d,l]);if(Wi(h,$u*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(yi,{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(bn,{title:"Blockers",description:H_}),i.jsxs(pe,{variant:"warning",className:"mt-6",children:[i.jsx(jt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:Ar}),i.jsx(ge,{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(bn,{title:"Blockers",description:H_}),i.jsx("p",{className:"text-muted-foreground mt-1 text-xs",children:qU(f,m!==null)}),!s&&!r?i.jsx(JU,{}):null,m?i.jsx(eB,{refusal:m,on_retry:()=>void d(!0)}):null,s?i.jsx(tB,{org:e,report:s,stale:m!==null}):null]})}function JU(){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 eB({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(pe,{variant:"info",className:"mt-4",children:[i.jsx(fn,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"The local stores are busy"}),i.jsxs(ge,{children:[i.jsx("p",{children:e.message}),n]})]}):i.jsxs(pe,{variant:"destructive",className:"mt-4",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Blockers could not be read"}),i.jsxs(ge,{children:[i.jsx("p",{children:e.message||"The read did not answer. Try again in a moment."}),n]})]})}function Kf(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 tB({org:e,report:t,stale:n}){const{href:s,Link:a}=Kf(e),{summary:r}=t,o=n?` · last read ${Xn(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:`${KU(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:[WU,o]})]})}),t.loops.map(d=>i.jsx(nB,{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(we,{variant:"neutral",children:t.blockers.length})]}),t.blockers.map(d=>i.jsx(iB,{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: ${hr(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: ${hr(h,"thread","threads")} in the main queue`:`In line for ${d}: ${hr(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 nB({org:e,loop:t}){const{href:n,Link:s}=Kf(e),a=sB(t.waiters);return i.jsxs("div",{className:"mt-4 flex flex-col gap-3",children:[i.jsxs(pe,{variant:"destructive",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:XU(t)}),i.jsxs(ge,{children:[i.jsx("p",{children:BU}),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: ${hr(a,"thread","threads")}`}),i.jsx(Eb,{org:e,waiters:t.waiters})]}):null]})}const sB=e=>new Set(function t(n){return n.flatMap(s=>[s.thread,...t(s.waiters??[])])}(e)).size;function iB({org:e,card:t}){const{name:n}=Kf(e),s=YU(t.state);return i.jsxs(yt,{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(we,{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 ${ZU(t.clears)}`}),i.jsx("div",{className:"mt-1",children:i.jsx(Eb,{org:e,waiters:t.waiters})})]})}function Eb({org:e,waiters:t,via:n}){const{name:s}=Kf(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 ${tx(a.age_hours)} · ${[n?`via ${n}`:"",a.reason.trim()].filter(Boolean).join(" · ")||"no reason given"}`}),(r=a.waiters)!=null&&r.length?i.jsx(Eb,{org:e,waiters:a.waiters,via:a.title}):null]},`${a.hold}-${a.thread}`)})})}const aB="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.",rB=3e4,oB="Reading the workspaces. On a plan workspace this can take a few minutes.",lB="The read failed. Details are in the terminal running sdlc viewer.",cB={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"}},dB=e=>cB[e]??{label:e,tone:"neutral"},ga=e=>e.slice(0,8),tA={human:"Human",ai:"AI"},nx=(e,t)=>`${e} ${t}${e===1?"":"s"}`;function uB(){const e=Vn().workspaces;if(!e)throw new Error("The Workspaces page rendered without the workspaces seam.");return e}function hB(e){const t=uB(),[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]),Wi(()=>void f(),rB),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?fB(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(bn,{title:"Workspaces",description:aB,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(Er,{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?nA(n,o):""})]})}),i.jsxs("div",{ref:c,tabIndex:-1,className:"outline-none",children:[p?i.jsx(mB,{}):null,y&&a?i.jsx(pB,{refusal:a,on_retry:m}):null,n?i.jsx(gB,{overview:n}):null]})]})}function nA(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 fB(e,t){const n=`Read at ${Fs(new Date(e.read_at).toISOString())}`,s=nA(e,t);return s?`${n} · ${s}`:n}function mB(){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:oB})]})}function pB({refusal:e,on_retry:t}){const n=e.reason==="store_locked"?Wk(e,null):lB;return i.jsxs(pe,{variant:"destructive",className:"mt-6",children:[i.jsx(rt,{className:"size-4","aria-hidden":"true"}),i.jsx(ke,{children:"Could not read workspaces"}),i.jsxs(ge,{children:[i.jsx("p",{children:n}),i.jsx(U,{type:"button",variant:"outline",size:"sm",className:"mt-2",onClick:t,children:"Retry"})]})]})}function gB({overview:e}){const{counts:t}=e,n=[nx(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(iu,{id:"workspaces-lineage",title:"Lineage",caption:"Each workspace under the one it forked from",children:i.jsx(xB,{rows:e.workspaces})}),i.jsx(iu,{id:"workspaces-authority",title:"Authority and resolver",caption:"What this checkout's workspace may change",children:i.jsx(vB,{authority:e.authority})})]}),i.jsx(iu,{id:"workspaces-activity",className:"mt-4",title:"Integration activity",caption:"Newest first",children:e.activity.length===0?i.jsx(V_,{children:"No integration or reconciliation attempts yet."}):i.jsx(yB,{rows:e.activity})}),i.jsx(iu,{id:"workspaces-handoffs",className:"mt-4",title:"Handoffs",children:e.handoffs.length===0?i.jsx(V_,{children:"No Handoffs prepared yet."}):i.jsx(wB,{rows:e.handoffs})})]})}function iu({id:e,title:t,caption:n,className:s,children:a}){return i.jsxs("section",{"aria-labelledby":e,className:je("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 V_=({children:e})=>i.jsx("p",{className:"text-muted-foreground text-sm",children:e}),Oh=({children:e,tone:t})=>i.jsx("div",{className:je("text-xs",t==="error"?"text-destructive":"text-muted-foreground"),children:e});function Vc({status:e}){const t=dB(e);return i.jsx(we,{variant:t.tone,children:t.label})}function Zf({label:e,children:t}){return i.jsx(yt,{role:"group","aria-label":e,tabIndex:0,className:"overflow-x-auto outline-hidden focus-visible:ring-2 focus-visible:ring-ring",children:t})}function xB({rows:e}){return i.jsx(Zf,{label:"Workspaces",children:i.jsxs(nt,{containerClassName:"overflow-visible",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Workspace"}),i.jsx(Q,{children:"Actor"}),i.jsx(Q,{children:"Forked from"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Projection"})]})}),i.jsx(st,{children:e.map(t=>i.jsxs(_e,{"data-testid":"workspaces-row",children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-mono font-medium",children:t.short_id}),i.jsx(Oh,{children:t.current?`${t.path} · This checkout`:t.path}),t.projection==="unreadable"&&t.projection_error&&i.jsx(Oh,{children:t.projection_error})]}),i.jsx(X,{children:tA[t.actor]}),i.jsx(X,{children:t.source_id?i.jsx("span",{className:"font-mono",children:ga(t.source_id)}):i.jsx("span",{className:"text-muted-foreground",children:"No source"})}),i.jsx(X,{children:i.jsx(Vc,{status:t.status})}),i.jsx(X,{children:i.jsx(Vc,{status:t.projection})})]},t.id))})]})})}function vB({authority:e}){const t=e.resolver,n=[["Workspace",i.jsx("span",{className:"font-mono",children:ga(e.workspace_id)},"id")],["Actor",tA[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(Vc,{status:t.state==="ready"?"ready":"needs_attention"},"resolver")]),t.state==="needs_attention"&&t.issue&&n.push(["Resolver issue",t.issue]),i.jsx(Zf,{label:"Authority and resolver",children:i.jsx(nt,{containerClassName:"overflow-visible",children:i.jsx(st,{children:n.map(([s,a])=>i.jsxs(_e,{children:[i.jsx(Q,{scope:"row",className:"text-muted-foreground font-normal",children:s}),i.jsx(X,{children:a})]},s))})})})}function bB(e){const t=[e.merge_attempts?nx(e.merge_attempts,"merge attempt"):null,e.resolver_attempts?nx(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 yB({rows:e}){return i.jsx(Zf,{label:"Integration activity",children:i.jsxs(nt,{containerClassName:"overflow-visible",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"Change"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Attempts"}),i.jsx(Q,{children:"Updated"})]})}),i.jsx(st,{children:e.map((t,n)=>i.jsxs(_e,{children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-medium",children:t.kind==="integration"?`Integrate ${ga(t.child_id)} into ${ga(t.other_id)}`:`Reconcile ${ga(t.child_id)} from ${ga(t.other_id)}`}),i.jsx(Oh,{children:t.kind==="integration"?"Integration":"Source reconciliation"})]}),i.jsx(X,{children:i.jsx(Vc,{status:t.status})}),i.jsx(X,{children:bB(t)}),i.jsx(X,{children:AD(t.updated_at)})]},`${t.kind}-${t.child_id}-${t.other_id}-${t.updated_at}-${n}`))})]})})}function wB({rows:e}){return i.jsx(Zf,{label:"Handoffs",children:i.jsxs(nt,{containerClassName:"overflow-visible",children:[i.jsx(ot,{children:i.jsxs(_e,{children:[i.jsx(Q,{children:"From"}),i.jsx(Q,{children:"To"}),i.jsx(Q,{children:"Status"}),i.jsx(Q,{children:"Pinned"})]})}),i.jsx(st,{children:e.map(t=>i.jsxs(_e,{children:[i.jsxs(X,{children:[i.jsx("div",{className:"font-mono font-medium",children:ga(t.child_id)}),t.error?i.jsx(Oh,{children:t.error}):null]}),i.jsx(X,{className:"font-mono",children:ga(t.source_id)}),i.jsx(X,{children:i.jsx(Vc,{status:t.status})}),i.jsx(X,{children:`${t.child_commit} onto ${t.source_commit}`})]},t.id))})]})})}const U_="This machine's worktrees of this repository.",_B="Merge sends one whose thread is at rest to the main queue.",jB=3e4,NB=3e3,kB=6e5,xp=[{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"}],Tl={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"}},SB="no thread to land it",Ab="its thread waits on you",sA="its thread is done",iA="its thread is retired",Rb=e=>e.archivable&&e.cleanup==="user",CB=e=>e.queue!==null||e.merge.offered===!1&&e.merge.why==="already in a promotion queue",DB=e=>!e.merge.offered&&(e.merge.why===sA||e.merge.why.startsWith(iA)),Tb=e=>!e.merge.offered&&e.merge.why===SB||DB(e),vp=(e,t)=>t==="all"?!0:t==="decide"?Rb(e):(e.landed!==null?"landed":CB(e)?"queued":Tb(e)?"orphan":"needs")===t,EB=e=>e.landed!==null?e.threads.some(t=>t.phase!=="done"):e.threads.length>0&&!Tb(e);function Lu(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 aA(e){const t=e%100,n=t>=11&&t<=13?"th":{1:"st",2:"nd",3:"rd"}[e%10]??"th";return`${e}${n}`}function AB(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 bp=e=>Fs(new Date(e*1e3).toISOString()),Bl=e=>e.charAt(0).toUpperCase()+e.slice(1);function RB(e,t){var a;const n=t.phase?Bl(t.phase):"No phase",s=e.merge;if(!s.offered&&s.why.startsWith(iA)){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===sA?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===Ab?`${n} · waits on you`:s.why.startsWith("its session is not running")?`${n} · session not running`:n}function TB(){const e=Vn().worktrees;if(!e)throw new Error("The Worktrees page rendered without the worktrees seam.");return e}function OB({org:e}){var M,H;const t=TB(),[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}=tl(),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;Wi(()=>void _(),k?NB:jB),Wi(()=>void S(),kB);const j=(n==null?void 0:n.rows)??[],N=z=>o==null?void 0:o.sizes[z.path],O=j.filter(Rb),T=o?O.reduce((z,K)=>z+(N(K)??0),0):null,I=j.length===0?U_:`${U_} ${_B}${O.length?` ${O.length} ${O.length===1?"is":"are"} yours to decide${T!==null?`: removing them frees about ${Lu(T)}`:""}.`:""}`,L=m.trim().toLowerCase(),$=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=>vp(z,h)&&$(z)).sort((z,K)=>{if(h==="decide")return(N(K)??0)-(N(z)??0);const oe=re=>EB(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,...Ne})=>Ne):g(re=>({...re,[K.path]:oe.refusal.message})),await _()},E=async z=>{if(!z.merge.offered)return;const K=z.threads.find(F=>F.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",Ne=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",Se=z.merge.caveat?`
|
|
431
431
|
|