@agent-plan/server 0.2.19-next.25 → 0.2.19-next.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-plan/server",
3
- "version": "0.2.19-next.25",
3
+ "version": "0.2.19-next.26",
4
4
  "private": false,
5
5
  "description": "Local HTTP/WebSocket server for Agent Plan dashboards and planner APIs.",
6
6
  "license": "MIT",
@@ -41,7 +41,7 @@
41
41
  "@hono/node-server": "^1.14.0",
42
42
  "hono": "^4.7.0",
43
43
  "ws": "^8.18.0",
44
- "@agent-plan/core": "0.2.19-next.25"
44
+ "@agent-plan/core": "0.2.19-next.26"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@types/ws": "^8.18.0"
@@ -268,7 +268,7 @@ Please change the parent <Route path="${R}"> to <Route path="${R==="/"?"*":`${R}
268
268
  *
269
269
  * This source code is licensed under the ISC license.
270
270
  * See the LICENSE file in the root directory of this source tree.
271
- */const uR=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],cR=Et("x",uR),dR="/api",fR=120,hR=40;function Gc(t){return{...t,number:t.number??0,decisions:t.decisions??[],acceptedDecisions:t.acceptedDecisions??[],checklist:t.checklist??[],subtasks:t.subtasks??[],startedAt:t.startedAt??"",completedAt:t.completedAt??""}}function Xc(t){return{...t,discussedAt:t.discussedAt??"",contextReady:t.contextReady??!1,contextReadyReason:t.contextReadyReason??"",notes:t.notes??"",goals:t.goals??[],nonGoals:t.nonGoals??[],dependencies:t.dependencies??[],risks:t.risks??[],openQuestions:t.openQuestions??[],decisions:t.decisions??[],acceptedDecisions:t.acceptedDecisions??[],completionCriteria:t.completionCriteria??[],taskIds:t.taskIds??[],tasks:(t.tasks??[]).map(Gc),linkedRequirements:t.linkedRequirements??[],handoff:t.handoff??"",handoffUpdatedAt:t.handoffUpdatedAt??""}}function Qc(t){return{...t,number:t.number??0,discussedAt:t.discussedAt??"",contextReady:t.contextReady??!1,contextReadyReason:t.contextReadyReason??"",acceptedDecisions:t.acceptedDecisions??[],phaseIds:t.phaseIds??[]}}function qb(t){var a,l,s;return{...t,scope:t.scope??[],outOfScope:t.outOfScope??[],decisions:t.decisions??[],globalRules:t.globalRules??[],technologies:t.technologies??[],tools:t.tools??[],acceptedDecisions:t.acceptedDecisions??[],planRoot:t.planRoot??"",projectRoot:t.projectRoot??"",workflowRules:{beforePhaseStart:((a=t.workflowRules)==null?void 0:a.beforePhaseStart)??[],beforeTaskStart:((l=t.workflowRules)==null?void 0:l.beforeTaskStart)??[],afterPhaseComplete:((s=t.workflowRules)==null?void 0:s.afterPhaseComplete)??[]}}}function gm(t){return{...t,description:t.description??"",macroTasks:t.macroTasks??[],linkedPhaseIds:t.linkedPhaseIds??[]}}async function tx(t,a){try{return await fetch(`${dR}${t}`,{headers:{"Content-Type":"application/json"},...a})}catch{throw new Response("Planner web server unavailable. Pi or planner-web may have stopped. Restart the planner web UI or Pi, then reload this page.",{status:503,statusText:"Planner web server unavailable"})}}async function Gt(t,a){let l=await tx(t,a),s=0;for(;l.status===503&&s<hR;)await new Promise(o=>setTimeout(o,fR)),s+=1,l=await tx(t,a);if(!l.ok){const o=await l.text().catch(()=>l.statusText);throw new Response(o||l.statusText,{status:l.status,statusText:l.statusText})}return l.json()}async function Ib(){return qb(await Gt("/project"))}async function mR(t){return qb(await Gt("/project",{method:"PUT",body:JSON.stringify(t)}))}async function pR(){return Gt("/ui-config")}async function Vb(){return(await Gt("/features")).map(Qc)}async function Io(t){return Qc(await Gt(`/features/${t}`))}async function gR(t){return Qc(await Gt("/features",{method:"POST",body:JSON.stringify(t)}))}async function Yb(t){return Qc(await Gt(`/features/${t.id}`,{method:"PUT",body:JSON.stringify(t)}))}async function vR(t){return Gt(`/features/${t}`,{method:"DELETE"})}async function vm(){return(await Gt("/requirements")).requirements.map(gm)}async function yR(t){const a=new Date().toISOString();return gm(await Gt("/requirements",{method:"POST",body:JSON.stringify({...t,macroTasks:[],createdAt:a,updatedAt:a})}))}async function xR(t){return gm(await Gt(`/requirements/${t.id}`,{method:"PUT",body:JSON.stringify({...t,updatedAt:new Date().toISOString()})}))}async function bR(t){return Gt(`/requirements/${t}`,{method:"DELETE"})}async function Kc(t){const a=t?`?featureId=${encodeURIComponent(t)}`:"";return(await Gt(`/phases${a}`)).map(Xc)}async function Zc(t){return Xc(await Gt(`/phases/${t}`))}async function SR(t){return Xc(await Gt("/phases",{method:"POST",body:JSON.stringify(t)}))}async function Fb(t){return Xc(await Gt(`/phases/${t.id}`,{method:"PUT",body:JSON.stringify(t)}))}async function wR(t){return Gt(`/phases/${t}`,{method:"DELETE"})}async function ER(t,a){return Gc(await Gt(`/phases/${t}/tasks`,{method:"POST",body:JSON.stringify(a)}))}async function Jc(t){return Gc(await Gt(`/tasks/${t}`))}async function ym(t){return Gc(await Gt(`/tasks/${t.id}`,{method:"PUT",body:JSON.stringify(t)}))}async function NR(t){return Gt(`/tasks/${t}`,{method:"DELETE"})}async function Pb(){return Gt("/tasks/active")}async function Yh(){return(await Gt("/handoffs")).handoffs??[]}async function RR(){return(await Gt("/handoffs/archive")).archived??[]}async function Gb(t){return Gt(`/phases/${t}/handoff`,{method:"DELETE"})}async function jR(t=!1){return Gt(`/export?full=${t?"true":"false"}`)}async function TR(){return Gt("/repair",{method:"POST"})}async function bh(t,a,l,s){return Gt("/reorder",{method:"POST",body:JSON.stringify({kind:t,movedId:a,beforeId:l,afterId:s})})}function CR(){const[t,a]=v.useState(()=>{if(typeof window>"u")return"dark";const l=window.localStorage.getItem("plan-ui-theme");return l||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")});return v.useEffect(()=>{document.documentElement.setAttribute("data-theme",t),window.localStorage.setItem("plan-ui-theme",t)},[t]),{theme:t,toggleTheme:()=>a(l=>l==="dark"?"light":"dark")}}function DR({liveStatus:t}){const a=t==="live"?{label:"Live",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",dotClassName:"bg-emerald-500"}:t==="reconnecting"?{label:"Reconnecting…",className:"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-400",dotClassName:"bg-amber-500 animate-pulse"}:t==="disconnected"?{label:"Disconnected",className:"border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-400",dotClassName:"bg-rose-500"}:{label:"Connecting…",className:"border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-400",dotClassName:"bg-sky-500 animate-pulse"};return c.jsxs("span",{className:`inline-flex min-h-9 items-center gap-2 rounded-[12px] border px-2.5 py-1.5 text-sm font-semibold sm:min-h-11 sm:rounded-[14px] sm:px-3 sm:py-2 ${a.className}`,children:[c.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${a.dotClassName}`}),c.jsx("span",{className:"hidden sm:inline",children:a.label})]})}function AR({projectName:t,projectRoot:a,planRoot:l,liveStatus:s}){const{theme:o,toggleTheme:u}=CR(),[f,m]=v.useState(!1),[p,g]=v.useState(!1),[x,y]=v.useState(null),N=[{to:"/",label:"Dashboard",icon:YN},{to:"/features",label:"Features",icon:Cc},{to:"/requirements",label:"Requirements",icon:qo},{to:"/handoff",label:"Handoff",icon:$b}];async function w(S){y(S?"full":"summary");try{const R=await jR(S),L=new Blob([R.markdown],{type:"text/markdown;charset=utf-8"}),I=URL.createObjectURL(L),q=document.createElement("a");q.href=I,q.download=S?"EXPORT-full.md":R.filePath||"EXPORT.md",document.body.appendChild(q),q.click(),q.remove(),URL.revokeObjectURL(I),g(!1)}catch(R){window.alert(`Export failed: ${R instanceof Error?R.message:String(R)}`)}finally{y(null)}}return c.jsx("div",{className:"relative z-20 overflow-visible border-b border-[var(--border)] bg-[var(--surface-elevated)] backdrop-blur-xl backdrop-saturate-150",children:c.jsxs("div",{className:"page-container flex flex-col gap-3 py-2.5 md:flex-row md:items-center md:justify-between sm:gap-4 sm:py-3",children:[c.jsxs(Ye,{to:"/",className:"flex min-w-0 items-center gap-3",children:[c.jsx("div",{className:"surface-card flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl border border-[var(--border)] text-[var(--accent)]",children:c.jsx(Cc,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("div",{className:"truncate text-sm font-black tracking-tight",children:t??"Agent Plan"})}),a?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("div",{className:"truncate text-[11px] text-[var(--text-subtle)]",title:a,children:a}),c.jsx("button",{type:"button",onClick:async S=>{S.preventDefault(),S.stopPropagation(),a&&(await navigator.clipboard.writeText(a).catch(()=>{}),m(!0),window.setTimeout(()=>m(!1),1200))},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-[var(--text-subtle)] transition hover:text-[var(--text)]",title:f?"Copied":"Copy project path","aria-label":f?"Copied":"Copy project path",children:f?c.jsx(_b,{className:"h-3.5 w-3.5"}):c.jsx(Bb,{className:"h-3.5 w-3.5"})})]}):null]})]}),c.jsxs("div",{className:"flex items-center justify-end gap-2 sm:gap-3",children:[c.jsx("div",{className:"flex flex-wrap items-center gap-2",children:c.jsx(DR,{liveStatus:s})}),c.jsx("nav",{className:"flex items-center gap-1.5 sm:gap-2",children:N.map(S=>c.jsxs(Ab,{to:S.to,end:S.to==="/",className:({isActive:D})=>`inline-flex min-h-9 items-center gap-2 rounded-[12px] border px-2.5 py-1.5 text-sm font-semibold transition sm:min-h-11 sm:rounded-[14px] sm:px-3 sm:py-2 sm:px-4 ${D?"border-transparent bg-[var(--accent-soft)] text-[var(--accent)]":"border-transparent text-[var(--text-muted)] hover:bg-[var(--accent-soft)] hover:text-[var(--text)]"}`,children:[c.jsx(S.icon,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:S.label})]},S.to))}),c.jsxs("div",{className:"relative z-30",children:[c.jsxs("button",{type:"button","aria-haspopup":"menu","aria-expanded":p,onClick:()=>g(S=>!S),className:"inline-flex min-h-9 items-center gap-2 rounded-[12px] border border-[var(--border-strong)] bg-[var(--surface-elevated)] px-2.5 py-1.5 text-sm font-semibold text-[var(--text-muted)] transition hover:text-[var(--text)] sm:min-h-11 sm:rounded-[14px] sm:px-3 sm:py-2 sm:px-4",children:[c.jsx(BN,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:"Export"}),c.jsx(vs,{className:`h-4 w-4 transition-transform ${p?"rotate-180":""}`})]}),p?c.jsxs("div",{role:"menu",onKeyDown:S=>{var I;const D=Array.from(S.currentTarget.querySelectorAll("[role=menuitem]")).filter(q=>!q.hasAttribute("disabled"));if(D.length===0)return;const R=D.indexOf(document.activeElement);let L=R;if(S.key==="ArrowDown")L=R===-1?0:(R+1)%D.length;else if(S.key==="ArrowUp")L=R===-1?D.length-1:(R-1+D.length)%D.length;else if(S.key==="Home")L=0;else if(S.key==="End")L=D.length-1;else return;S.preventDefault(),(I=D[L])==null||I.focus()},className:"absolute right-0 top-full z-[200] mt-2 min-w-44 overflow-hidden rounded-[14px] border border-[var(--border)] bg-[var(--surface-elevated)] p-1 shadow-xl",children:[c.jsxs("button",{type:"button",role:"menuitem",disabled:x!==null,onClick:()=>void w(!1),className:"flex w-full items-center justify-between rounded-[10px] px-3 py-2 text-left text-sm font-semibold text-[var(--text)] transition hover:bg-[var(--accent-soft)] disabled:cursor-wait disabled:opacity-60",children:["Summary",x==="summary"?c.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"…"}):null]}),c.jsxs("button",{type:"button",role:"menuitem",disabled:x!==null,onClick:()=>void w(!0),className:"flex w-full items-center justify-between rounded-[10px] px-3 py-2 text-left text-sm font-semibold text-[var(--text)] transition hover:bg-[var(--accent-soft)] disabled:cursor-wait disabled:opacity-60",children:["Full",x==="full"?c.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"…"}):null]})]}):null]}),c.jsx("button",{type:"button",onClick:u,"aria-label":o==="dark"?"Switch to light theme":"Switch to dark theme",title:o==="dark"?"Switch to light theme":"Switch to dark theme",className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-[12px] border border-[var(--border-strong)] bg-[var(--surface-elevated)] text-[var(--text-muted)] transition hover:text-[var(--text)] sm:h-11 sm:w-11 sm:rounded-[14px]",children:o==="dark"?c.jsx(lR,{className:"h-4 w-4"}):c.jsx(KN,{className:"h-4 w-4"})})]})]})})}function nx(t,a,l){t.split(`
271
+ */const uR=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],cR=Et("x",uR),dR="/api",fR=120,hR=40;function Gc(t){return{...t,number:t.number??0,decisions:t.decisions??[],acceptedDecisions:t.acceptedDecisions??[],checklist:t.checklist??[],subtasks:t.subtasks??[],startedAt:t.startedAt??"",completedAt:t.completedAt??""}}function Xc(t){return{...t,discussedAt:t.discussedAt??"",contextReady:t.contextReady??!1,contextReadyReason:t.contextReadyReason??"",notes:t.notes??"",goals:t.goals??[],nonGoals:t.nonGoals??[],dependencies:t.dependencies??[],risks:t.risks??[],openQuestions:t.openQuestions??[],decisions:t.decisions??[],acceptedDecisions:t.acceptedDecisions??[],completionCriteria:t.completionCriteria??[],taskIds:t.taskIds??[],tasks:(t.tasks??[]).map(Gc),linkedRequirements:t.linkedRequirements??[],handoff:t.handoff??"",handoffUpdatedAt:t.handoffUpdatedAt??""}}function Qc(t){return{...t,number:t.number??0,discussedAt:t.discussedAt??"",contextReady:t.contextReady??!1,contextReadyReason:t.contextReadyReason??"",acceptedDecisions:t.acceptedDecisions??[],phaseIds:t.phaseIds??[]}}function qb(t){var a,l,s;return{...t,scope:t.scope??[],outOfScope:t.outOfScope??[],decisions:t.decisions??[],globalRules:t.globalRules??[],technologies:t.technologies??[],tools:t.tools??[],acceptedDecisions:t.acceptedDecisions??[],planRoot:t.planRoot??"",projectRoot:t.projectRoot??"",workflowRules:{beforePhaseStart:((a=t.workflowRules)==null?void 0:a.beforePhaseStart)??[],beforeTaskStart:((l=t.workflowRules)==null?void 0:l.beforeTaskStart)??[],afterPhaseComplete:((s=t.workflowRules)==null?void 0:s.afterPhaseComplete)??[]}}}function gm(t){return{...t,description:t.description??"",macroTasks:t.macroTasks??[],linkedPhaseIds:t.linkedPhaseIds??[]}}async function tx(t,a){try{return await fetch(`${dR}${t}`,{headers:{"Content-Type":"application/json"},...a})}catch{throw new Response("Planner web server unavailable. Pi or planner-web may have stopped. Restart the planner web UI or Pi, then reload this page.",{status:503,statusText:"Planner web server unavailable"})}}async function Gt(t,a){let l=await tx(t,a),s=0;for(;l.status===503&&s<hR;)await new Promise(o=>setTimeout(o,fR)),s+=1,l=await tx(t,a);if(!l.ok){const o=await l.text().catch(()=>l.statusText);throw new Response(o||l.statusText,{status:l.status,statusText:l.statusText})}return l.json()}async function Ib(){return qb(await Gt("/project"))}async function mR(t){return qb(await Gt("/project",{method:"PUT",body:JSON.stringify(t)}))}async function pR(){return Gt("/ui-config")}async function Vb(){return(await Gt("/features")).map(Qc)}async function Io(t){return Qc(await Gt(`/features/${t}`))}async function gR(t){return Qc(await Gt("/features",{method:"POST",body:JSON.stringify(t)}))}async function Yb(t){return Qc(await Gt(`/features/${t.id}`,{method:"PUT",body:JSON.stringify(t)}))}async function vR(t){return Gt(`/features/${t}`,{method:"DELETE"})}async function vm(){return(await Gt("/requirements")).requirements.map(gm)}async function yR(t){const a=new Date().toISOString();return gm(await Gt("/requirements",{method:"POST",body:JSON.stringify({...t,macroTasks:[],createdAt:a,updatedAt:a})}))}async function xR(t){return gm(await Gt(`/requirements/${t.id}`,{method:"PUT",body:JSON.stringify({...t,updatedAt:new Date().toISOString()})}))}async function bR(t){return Gt(`/requirements/${t}`,{method:"DELETE"})}async function Kc(t){const a=t?`?featureId=${encodeURIComponent(t)}`:"";return(await Gt(`/phases${a}`)).map(Xc)}async function Zc(t){return Xc(await Gt(`/phases/${t}`))}async function SR(t){return Xc(await Gt("/phases",{method:"POST",body:JSON.stringify(t)}))}async function Fb(t){return Xc(await Gt(`/phases/${t.id}`,{method:"PUT",body:JSON.stringify(t)}))}async function wR(t){return Gt(`/phases/${t}`,{method:"DELETE"})}async function ER(t,a){return Gc(await Gt(`/phases/${t}/tasks`,{method:"POST",body:JSON.stringify(a)}))}async function Jc(t){return Gc(await Gt(`/tasks/${t}`))}async function ym(t){return Gc(await Gt(`/tasks/${t.id}`,{method:"PUT",body:JSON.stringify(t)}))}async function NR(t){return Gt(`/tasks/${t}`,{method:"DELETE"})}async function Pb(){return Gt("/tasks/active")}async function Yh(){return(await Gt("/handoffs")).handoffs??[]}async function RR(){return(await Gt("/handoffs/archive")).archived??[]}async function Gb(t){return Gt(`/phases/${t}/handoff`,{method:"DELETE"})}async function jR(t=!1){return Gt(`/export?full=${t?"true":"false"}`)}async function TR(){return Gt("/repair",{method:"POST"})}async function bh(t,a,l,s){return Gt("/reorder",{method:"POST",body:JSON.stringify({kind:t,movedId:a,beforeId:l,afterId:s})})}function CR(){const[t,a]=v.useState(()=>{if(typeof window>"u")return"dark";const l=window.localStorage.getItem("plan-ui-theme");return l||(window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light")});return v.useEffect(()=>{document.documentElement.setAttribute("data-theme",t),window.localStorage.setItem("plan-ui-theme",t)},[t]),{theme:t,toggleTheme:()=>a(l=>l==="dark"?"light":"dark")}}function DR({liveStatus:t}){const a=t==="live"?{label:"Live",className:"border-emerald-500/30 bg-emerald-500/10 text-emerald-600 dark:text-emerald-400",dotClassName:"bg-emerald-500"}:t==="reconnecting"?{label:"Reconnecting…",className:"border-amber-500/30 bg-amber-500/10 text-amber-700 dark:text-amber-400",dotClassName:"bg-amber-500 animate-pulse"}:t==="disconnected"?{label:"Disconnected",className:"border-rose-500/30 bg-rose-500/10 text-rose-700 dark:text-rose-400",dotClassName:"bg-rose-500"}:{label:"Connecting…",className:"border-sky-500/30 bg-sky-500/10 text-sky-700 dark:text-sky-400",dotClassName:"bg-sky-500 animate-pulse"};return c.jsxs("span",{className:`inline-flex min-h-9 items-center gap-2 rounded-[12px] border px-2.5 py-1.5 text-sm font-semibold sm:min-h-11 sm:rounded-[14px] sm:px-3 sm:py-2 ${a.className}`,children:[c.jsx("span",{className:`h-2.5 w-2.5 rounded-full ${a.dotClassName}`}),c.jsx("span",{className:"hidden sm:inline",children:a.label})]})}function AR({projectName:t,projectRoot:a,planRoot:l,liveStatus:s}){const{theme:o,toggleTheme:u}=CR(),[f,m]=v.useState(!1),[p,g]=v.useState(!1),[x,y]=v.useState(null),N=[{to:"/",label:"Dashboard",icon:YN},{to:"/features",label:"Features",icon:Cc},{to:"/requirements",label:"Requirements",icon:qo},{to:"/handoff",label:"Handoff",icon:$b}];async function w(S){y(S?"full":"summary");try{const R=await jR(S),L=new Blob([R.markdown],{type:"text/markdown;charset=utf-8"}),I=URL.createObjectURL(L),q=document.createElement("a");q.href=I,q.download=S?"EXPORT-full.md":R.filePath||"EXPORT.md",document.body.appendChild(q),q.click(),q.remove(),URL.revokeObjectURL(I),g(!1)}catch(R){window.alert(`Export failed: ${R instanceof Error?R.message:String(R)}`)}finally{y(null)}}return c.jsx("div",{className:"relative z-20 overflow-visible border-b border-[var(--border)] bg-[var(--surface-elevated)] backdrop-blur-xl backdrop-saturate-150",children:c.jsxs("div",{className:"page-container flex flex-col gap-3 py-2.5 md:flex-row md:items-center md:justify-between sm:gap-4 sm:py-3",children:[c.jsxs(Ye,{to:"/",className:"flex min-w-0 items-center gap-3",children:[c.jsx("div",{className:"surface-card flex h-10 w-10 shrink-0 items-center justify-center rounded-2xl border border-[var(--border)] text-[var(--accent)]",children:c.jsx(Cc,{className:"h-4 w-4"})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("div",{className:"truncate text-sm font-black tracking-tight",children:t??"Agent Plan"})}),a?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("div",{className:"truncate text-[11px] text-[var(--text-subtle)]",title:a,children:a}),c.jsx("button",{type:"button",onClick:async S=>{S.preventDefault(),S.stopPropagation(),a&&(await navigator.clipboard.writeText(a).catch(()=>{}),m(!0),window.setTimeout(()=>m(!1),1200))},className:"inline-flex h-5 w-5 shrink-0 items-center justify-center rounded text-[var(--text-subtle)] transition hover:text-[var(--text)]",title:f?"Copied":"Copy project path","aria-label":f?"Copied":"Copy project path",children:f?c.jsx(_b,{className:"h-3.5 w-3.5"}):c.jsx(Bb,{className:"h-3.5 w-3.5"})})]}):null]})]}),c.jsxs("div",{className:"flex items-center justify-end gap-2 sm:gap-3",children:[c.jsx("div",{className:"flex flex-wrap items-center gap-2",children:c.jsx(DR,{liveStatus:s})}),c.jsx("nav",{className:"flex items-center gap-1.5 sm:gap-2",children:N.map(S=>c.jsxs(Ab,{to:S.to,end:S.to==="/","aria-label":S.label,className:({isActive:D})=>`inline-flex min-h-9 items-center gap-2 rounded-[12px] border px-2.5 py-1.5 text-sm font-semibold transition sm:min-h-11 sm:rounded-[14px] sm:px-3 sm:py-2 sm:px-4 ${D?"border-transparent bg-[var(--accent-soft)] text-[var(--accent)]":"border-transparent text-[var(--text-muted)] hover:bg-[var(--accent-soft)] hover:text-[var(--text)]"}`,children:[c.jsx(S.icon,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:S.label})]},S.to))}),c.jsxs("div",{className:"relative z-30",children:[c.jsxs("button",{type:"button","aria-haspopup":"menu","aria-expanded":p,"aria-label":"Export",onClick:()=>g(S=>!S),className:"inline-flex min-h-9 items-center gap-2 rounded-[12px] border border-[var(--border-strong)] bg-[var(--surface-elevated)] px-2.5 py-1.5 text-sm font-semibold text-[var(--text-muted)] transition hover:text-[var(--text)] sm:min-h-11 sm:rounded-[14px] sm:px-3 sm:py-2 sm:px-4",children:[c.jsx(BN,{className:"h-4 w-4"}),c.jsx("span",{className:"hidden sm:inline",children:"Export"}),c.jsx(vs,{className:`h-4 w-4 transition-transform ${p?"rotate-180":""}`})]}),p?c.jsxs("div",{role:"menu",onKeyDown:S=>{var I;const D=Array.from(S.currentTarget.querySelectorAll("[role=menuitem]")).filter(q=>!q.hasAttribute("disabled"));if(D.length===0)return;const R=D.indexOf(document.activeElement);let L=R;if(S.key==="ArrowDown")L=R===-1?0:(R+1)%D.length;else if(S.key==="ArrowUp")L=R===-1?D.length-1:(R-1+D.length)%D.length;else if(S.key==="Home")L=0;else if(S.key==="End")L=D.length-1;else return;S.preventDefault(),(I=D[L])==null||I.focus()},className:"absolute right-0 top-full z-[200] mt-2 min-w-44 overflow-hidden rounded-[14px] border border-[var(--border)] bg-[var(--surface-elevated)] p-1 shadow-xl",children:[c.jsxs("button",{type:"button",role:"menuitem",disabled:x!==null,onClick:()=>void w(!1),className:"flex w-full items-center justify-between rounded-[10px] px-3 py-2 text-left text-sm font-semibold text-[var(--text)] transition hover:bg-[var(--accent-soft)] disabled:cursor-wait disabled:opacity-60",children:["Summary",x==="summary"?c.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"…"}):null]}),c.jsxs("button",{type:"button",role:"menuitem",disabled:x!==null,onClick:()=>void w(!0),className:"flex w-full items-center justify-between rounded-[10px] px-3 py-2 text-left text-sm font-semibold text-[var(--text)] transition hover:bg-[var(--accent-soft)] disabled:cursor-wait disabled:opacity-60",children:["Full",x==="full"?c.jsx("span",{className:"text-xs text-[var(--text-muted)]",children:"…"}):null]})]}):null]}),c.jsx("button",{type:"button",onClick:u,"aria-label":o==="dark"?"Switch to light theme":"Switch to dark theme",title:o==="dark"?"Switch to light theme":"Switch to dark theme",className:"inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-[12px] border border-[var(--border-strong)] bg-[var(--surface-elevated)] text-[var(--text-muted)] transition hover:text-[var(--text)] sm:h-11 sm:w-11 sm:rounded-[14px]",children:o==="dark"?c.jsx(lR,{className:"h-4 w-4"}):c.jsx(KN,{className:"h-4 w-4"})})]})]})})}function nx(t,a,l){t.split(`
272
272
  `).forEach((o,u)=>{u>0&&a.push(c.jsx("br",{},`${l}-br-${u}`)),o&&a.push(o)})}function fo(t,a){const l=[],s=/(\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)|\*\*([^*]+)\*\*|`([^`]+)`|\*([^*]+)\*)/g;let o=0,u=null,f=0;for(;(u=s.exec(t))!==null;)u.index>o&&nx(t.slice(o,u.index),l,`${a}-${f}`),u[2]&&u[3]?l.push(c.jsx("a",{href:u[3],target:"_blank",rel:"noreferrer",className:"font-semibold text-[var(--accent)] underline-offset-4 hover:underline",children:u[2]},`${a}-link-${f}`)):u[4]?l.push(c.jsx("strong",{className:"font-semibold text-[var(--text)]",children:u[4]},`${a}-strong-${f}`)):u[5]?l.push(c.jsx("code",{className:"rounded-md border border-[var(--border)] px-1.5 py-0.5 font-mono text-[0.95em] text-[var(--text)]",children:u[5]},`${a}-code-${f}`)):u[6]&&l.push(c.jsx("em",{className:"italic",children:u[6]},`${a}-em-${f}`)),o=s.lastIndex,f+=1;return o<t.length&&nx(t.slice(o),l,`${a}-tail`),l}function kR(t,a){var o;const l=t.split(`
273
273
  `);if(t.startsWith("```")){const u=t.replace(/^```[a-zA-Z]*\n?/,"").replace(/```\s*$/,"");return c.jsx("pre",{className:"overflow-x-auto rounded-lg border border-[var(--border)] bg-[var(--surface-elevated)] p-3 text-sm font-mono text-[var(--text)]",children:c.jsx("code",{children:u})},`code-${a}`)}const s=t.match(/^(#{1,6})\s+(.+)$/);if(s&&s[2]){const u=((o=s[1])==null?void 0:o.length)??1,f=s[2],m=u<=2?"text-base font-bold text-[var(--text)]":"text-sm font-bold text-[var(--text)]";return c.jsx("p",{className:m,children:fo(f,`h-${a}`)},`h-${a}`)}return l.every(u=>/^\s*>\s?/.test(u))?c.jsx("blockquote",{className:"border-l-2 border-[var(--accent)] pl-4 text-sm italic text-[var(--text-muted)]",children:l.map((u,f)=>c.jsx("div",{children:fo(u.replace(/^\s*>\s?/,""),`bq-${a}-${f}`)},`bq-${a}-${f}`))},`bq-${a}`):/^\s*([-*_])\1{2,}\s*$/.test(t.trim())?c.jsx("hr",{className:"border-[var(--border)]"},`hr-${a}`):l.every(u=>/^\s*[-*]\s+/.test(u))?c.jsx("ul",{className:"grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:l.map((u,f)=>c.jsx("li",{className:"list-disc",children:fo(u.replace(/^\s*[-*]\s+/,""),`ul-${a}-${f}`)},`ul-${a}-${f}`))},`ul-${a}`):l.every(u=>/^\s*\d+\.\s+/.test(u))?c.jsx("ol",{className:"grid gap-2 pl-5 text-sm text-[var(--text-muted)] list-decimal",children:l.map((u,f)=>c.jsx("li",{children:fo(u.replace(/^\s*\d+\.\s+/,""),`ol-${a}-${f}`)},`ol-${a}-${f}`))},`ol-${a}`):c.jsx("p",{className:"text-sm leading-6 text-[var(--text-muted)] whitespace-pre-wrap",children:fo(t,`p-${a}`)},`p-${a}`)}function xn({text:t,className:a=""}){if(!(t!=null&&t.trim()))return null;const l=t.trim().split(/\n\s*\n/).filter(Boolean);return c.jsx("div",{className:`formatted-text grid grid-cols-1 gap-3 ${a}`,children:l.map((s,o)=>kR(s,o))})}const ax={feature:{soft:"rgba(139, 92, 246, 0.16)",strong:"var(--color-entity-feature)"},phase:{soft:"rgba(6, 182, 212, 0.16)",strong:"var(--color-entity-phase)"},task:{soft:"rgba(16, 185, 129, 0.16)",strong:"var(--color-entity-task)"}};function Cr(t){return String(t&&t>0?t:0).padStart(3,"0")}function Bl({featureNum:t,phaseNum:a,taskNum:l}){const s=[];return t!==void 0&&s.push(`F${Cr(t)}`),a!==void 0&&s.push(`P${Cr(a)}`),l!==void 0&&s.push(`T${Cr(l)}`),s.join("/")}async function OR(t){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(t),!0}catch{}try{const a=document.createElement("textarea");a.value=t,a.style.position="fixed",a.style.top="-1000px",a.style.opacity="0",document.body.appendChild(a),a.focus(),a.select();const l=document.execCommand("copy");return a.remove(),l}catch{return!1}}function Xb({type:t,number:a}){const l=ax[t]||ax.task,s=(l==null?void 0:l.soft)||"transparent",o=(l==null?void 0:l.strong)||"inherit";return c.jsxs("span",{className:"shrink-0 inline-flex items-center justify-center font-mono text-[11px] font-bold leading-none px-2 py-1 rounded-md transition-colors",style:{backgroundColor:s,color:o},children:[t?t.charAt(0).toUpperCase():"?",Cr(a)]})}function Dc({type:t,phaseNum:a,featureNum:l}){return t==="feature"?null:t==="phase"?l===void 0?null:c.jsx("div",{className:"shrink-0 inline-flex items-stretch font-mono text-[10.5px] font-semibold rounded-md overflow-hidden border border-[var(--border)] bg-[var(--surface-elevated)]",children:c.jsxs("span",{className:"px-2 py-1 text-[var(--text-muted)]",children:["F",Cr(l)]})}):t==="task"?a===void 0?null:c.jsxs("div",{className:"shrink-0 inline-flex items-stretch font-mono text-[10.5px] font-semibold rounded-md overflow-hidden border border-[var(--border)] bg-[var(--surface-elevated)]",children:[c.jsxs("span",{className:"px-2 py-1 text-[var(--text-muted)]",children:["P",Cr(a)]}),l!==void 0&&c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"w-[1px] bg-[var(--border)]"}),c.jsxs("span",{className:"px-2 py-1 text-[var(--text-subtle)]",children:["F",Cr(l)]})]})]}):null}function cr({featureNum:t,phaseNum:a,taskNum:l,featureId:s,phaseId:o,taskId:u}){const f=s?({children:g})=>c.jsx(Ye,{to:`/features/${s}`,className:"entity-path-seg entity-path-seg--feature entity-path-seg--link",children:g}):({children:g})=>c.jsx("span",{className:"entity-path-seg entity-path-seg--feature",children:g}),m=o?({children:g})=>c.jsx(Ye,{to:`/features/${s}/phases/${o}`,className:"entity-path-seg entity-path-seg--phase entity-path-seg--link",children:g}):({children:g})=>c.jsx("span",{className:"entity-path-seg entity-path-seg--phase",children:g}),p=u?({children:g})=>c.jsx(Ye,{to:`/features/${s}/phases/${o}/tasks/${u}`,className:"entity-path-seg entity-path-seg--task entity-path-seg--link",children:g}):({children:g})=>c.jsx("span",{className:"entity-path-seg entity-path-seg--task",children:g});return c.jsxs("span",{className:"entity-path-badge",children:[t!==void 0?c.jsxs(f,{children:["F",Cr(t)]}):null,a!==void 0?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"entity-path-sep","aria-hidden":"true",children:"/"}),c.jsxs(m,{children:["P",Cr(a)]})]}):null,l!==void 0?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"entity-path-sep","aria-hidden":"true",children:"/"}),c.jsxs(p,{children:["T",Cr(l)]})]}):null]})}function mr({id:t,children:a}){const[l,s]=v.useState(!1);return c.jsxs("button",{type:"button",onClick:async o=>{o.preventDefault(),o.stopPropagation(),await OR(t)&&(s(!0),window.setTimeout(()=>s(!1),1200))},title:l?"Copied":`Copy ${t}`,"aria-label":l?"Copied":`Copy ${t}`,className:"copyable-id group inline-flex items-center gap-1.5",children:[a,c.jsx("span",{className:"copyable-id__icon","aria-hidden":"true",children:l?c.jsx(_b,{className:"h-3 w-3 text-emerald-500"}):c.jsx(Bb,{className:"h-3 w-3"})})]})}function Hl({shortId:t}){return c.jsx(mr,{id:t,children:c.jsx("span",{className:"short-id-badge",children:t})})}function xm({phaseId:t,updatedAt:a}){const l=`Phase handoff pending${a?` · updated ${new Date(a).toLocaleString()}`:""}`;return c.jsxs("a",{href:`/handoff#${t}`,className:"handoff-badge flex items-center gap-1 ml-2 shrink-0",title:l,"aria-label":l,children:[c.jsxs("svg",{viewBox:"0 0 16 16",width:"14",height:"14","aria-hidden":"true",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M4 2h5l3 3v9a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z"}),c.jsx("path",{d:"M9 2v3h3"}),c.jsx("path",{d:"M5.5 8h5M5.5 10.5h5"})]}),c.jsx("span",{className:"handoff-badge__label",children:"handoff"})]})}function MR({activeTasks:t}){const a=kr(),l=v.useMemo(()=>{const s=new Set;return t.filter(o=>{const u=`${o.id}-${o.title}-${o.phaseId}`;return s.has(u)?!1:(s.add(u),!0)})},[t]);return l.length===0?null:c.jsx("div",{className:"relative z-10 border-t border-[var(--border)] bg-[var(--surface-elevated)]/95 backdrop-blur-xl",children:c.jsx("div",{className:"page-container py-2.5",children:c.jsxs("div",{className:"grid gap-2",children:[c.jsxs("span",{className:"text-[10px] font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:["In-progress tasks (",l.length,")"]}),c.jsx("div",{className:"grid grid-cols-1 max-h-[35vh] gap-1.5 overflow-y-auto pr-1",children:l.map(s=>{const o=s.featureId?`/features/${s.featureId}/phases/${s.phaseId}/tasks/${s.id}`:"/features";return c.jsxs("div",{className:"flex min-w-0 items-center gap-2 rounded-[10px] border border-[var(--border)] bg-[var(--surface-card)] px-3 py-2 text-sm text-[var(--text)] transition-colors hover:border-[var(--accent)] hover:bg-[var(--accent-soft)] hover:text-[var(--accent)]",children:[s.status==="in-progress"?c.jsx("span",{"aria-hidden":"true",className:"inline-block h-2 w-2 shrink-0 rounded-full bg-[var(--accent)]","aria-label":"In progress"}):null,c.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2",children:[c.jsx(cr,{featureNum:s.featureNumber,phaseNum:s.phaseNumber,taskNum:s.number,featureId:s.featureId,phaseId:s.phaseId,taskId:s.id}),c.jsx(mr,{id:Bl({featureNum:s.featureNumber,phaseNum:s.phaseNumber,taskNum:s.number}),children:c.jsx("span",{className:"sr-only",children:"Copy task path"})}),s.shortId?c.jsx(Hl,{shortId:s.shortId}):null,c.jsx(Ye,{to:o,className:"min-w-0 flex-1 truncate font-medium",children:s.title})]}),c.jsx("button",{type:"button",onClick:u=>{u.preventDefault(),u.stopPropagation(),a(`/?locate=T${s.number}`)},"aria-label":`Locate T${s.number} in work tree`,title:"Locate in work tree",className:"inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-[8px] text-[var(--text-subtle)] transition-colors hover:bg-[var(--accent)] hover:text-[var(--text)]",children:c.jsx(XN,{className:"h-4 w-4"})})]},s.id)})})]})})})}function _R({project:t,activeTasks:a,serverInfo:l}){const s=Or(),[o,u]=v.useState("connecting");return v.useEffect(()=>{const f=m=>{var g;const p=(g=m.detail)==null?void 0:g.status;p&&u(p)};return window.addEventListener("agent-plan:ws-status",f),()=>window.removeEventListener("agent-plan:ws-status",f)},[]),c.jsxs("div",{className:"page-shell",children:[c.jsxs("header",{className:"sticky top-0 z-30 overflow-visible",children:[c.jsx(AR,{projectName:t==null?void 0:t.name,projectRoot:t==null?void 0:t.projectRoot,planRoot:t==null?void 0:t.planRoot,liveStatus:o}),c.jsx(MR,{activeTasks:a})]}),c.jsxs("div",{className:"page-container py-8",children:[c.jsxs("div",{className:"mb-8 flex flex-col gap-3 md:flex-row md:items-end md:justify-between md:gap-6",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.24em] text-[var(--text-subtle)]",children:"Current project"}),c.jsx("h1",{className:"text-2xl font-black tracking-tight text-[var(--text)] md:text-3xl",children:c.jsx(Ye,{to:"/",className:"hover:text-[var(--accent)]",children:(t==null?void 0:t.name)??"Agent Plan"})}),t!=null&&t.projectRoot?c.jsx("p",{className:"mt-2 truncate font-mono text-xs text-[var(--text-subtle)]",title:t.projectRoot,children:t.projectRoot}):null,l?c.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2 text-xs",children:[c.jsxs("span",{className:`inline-flex items-center gap-1.5 rounded-full px-2.5 py-1 font-semibold uppercase tracking-[0.12em] ${l.mode==="lan"?"bg-[color:color-mix(in_srgb,var(--accent)_16%,transparent)] text-[var(--accent)]":"bg-[var(--surface-elevated)] text-[var(--text-muted)]"}`,children:[c.jsx("span",{"aria-hidden":"true",className:"inline-block h-1.5 w-1.5 rounded-full bg-current"}),l.mode==="lan"?"LAN visible":"Local only"]}),c.jsx("a",{href:l.localUrl,target:"_blank",rel:"noreferrer",className:"font-mono text-[var(--text-subtle)] underline-offset-2 hover:text-[var(--accent)] hover:underline",children:l.localUrl}),l.lanUrl?c.jsxs(c.Fragment,{children:[c.jsx("span",{className:"text-[var(--text-subtle)]",children:"·"}),c.jsx("a",{href:l.lanUrl,target:"_blank",rel:"noreferrer",className:"font-mono text-[var(--text-subtle)] underline-offset-2 hover:text-[var(--accent)] hover:underline",children:l.lanUrl})]}):null]}):null,t!=null&&t.description?c.jsx(xn,{text:t.description,className:"mt-2 max-w-3xl"}):null]}),s.state!=="idle"?c.jsx("div",{className:"text-sm font-semibold text-[var(--accent)]",children:"Updating…"}):null]}),c.jsx(hi,{})]})]})}const Ra=32,Qb=4,LR=Math.PI*1.2;function Kb(){if(typeof document>"u")return"#7b68ee";const t=document.createElement("div");t.style.color="var(--accent, #7b68ee)",document.body.appendChild(t);const a=getComputedStyle(t).color||"#7b68ee";return t.remove(),a}function zR(){const t=document.createElement("canvas");t.width=Ra,t.height=Ra;const a=t.getContext("2d");if(!a)return"";const l=Kb();return a.beginPath(),a.arc(Ra/2,Ra/2,Ra/2-Qb,0,Math.PI*2),a.fillStyle=l,a.fill(),a.fillStyle="#ffffff",a.font="bold 16px system-ui, sans-serif",a.textAlign="center",a.textBaseline="middle",a.fillText("A",Ra/2,Ra/2+1),t.toDataURL("image/png")}function UR(t,a){const l=t.getContext("2d");if(!l)return"";const s=Kb();l.clearRect(0,0,Ra,Ra);const o=Ra/2,u=Ra/2,f=Ra/2-Qb;return l.beginPath(),l.arc(o,u,f,0,Math.PI*2),l.fillStyle=s,l.globalAlpha=.85,l.fill(),l.globalAlpha=1,l.beginPath(),l.arc(o,u,f-3,a,a+LR),l.strokeStyle="#ffffff",l.lineWidth=3,l.lineCap="round",l.stroke(),l.fillStyle="#ffffff",l.font="bold 14px system-ui, sans-serif",l.textAlign="center",l.textBaseline="middle",l.fillText("A",o,u+1),t.toDataURL("image/png")}function BR(){let t=document.querySelector("link[rel~='icon']");return t||(t=document.createElement("link"),t.rel="icon",t.type="image/png",document.head.appendChild(t)),t}function HR(t){const a=v.useRef(null),l=v.useRef(null),s=v.useRef(null),o=v.useRef(0);v.useEffect(()=>{if(a.current||(a.current=BR()),s.current||(s.current=zR()),!l.current){const m=document.createElement("canvas");m.width=Ra,m.height=Ra,l.current=m}const u=a.current;if(!t){u.href=s.current;return}const f=window.setInterval(()=>{document.hidden||(o.current+=Math.PI/10,u.href=UR(l.current,o.current))},100);return()=>{window.clearInterval(f),u.href=s.current}},[t])}const bo={create:{key:"n",primary:!0},edit:{key:"e",primary:!0},delete:{key:"d",primary:!0},submit:{key:"Enter",primary:!0}},Zb=v.createContext(bo);function Jb(){return typeof navigator<"u"&&/Mac|iPhone|iPad|iPod/.test(navigator.platform)}function $R(t){return typeof t!="string"}function qR(t){return{create:(t==null?void 0:t.create)??bo.create,edit:(t==null?void 0:t.edit)??bo.edit,delete:(t==null?void 0:t.delete)??bo.delete,submit:(t==null?void 0:t.submit)??bo.submit}}function IR(t){const a=[],l=Jb();t.primary&&a.push(l?"⌘":"Ctrl"),t.meta&&a.push(l?"⌘":"Meta"),t.ctrl&&a.push(l?"⌃":"Ctrl"),t.shift&&a.push(l?"⇧":"Shift"),t.alt&&a.push(l?"⌥":"Alt");const s=t.key==="Backspace"?l?"⌫":"Backspace":t.key==="Enter"?l?"↩":"Enter":t.key.length===1?t.key.toUpperCase():t.key;return a.push(s),l?a.join(""):a.join("+")}function VR(t){return t instanceof HTMLElement?!!t.closest("input, textarea, select, [contenteditable='true']"):!1}function YR(t,a){const l=a.key.length===1?a.key.toLowerCase():a.key,s=t.key.length===1?t.key.toLowerCase():t.key,o=Jb(),u=a.meta??(a.primary?o:!1),f=a.ctrl??(a.primary?!o:!1);return s===l&&!!u===t.metaKey&&!!f===t.ctrlKey&&!!a.shift===t.shiftKey&&!!a.alt===t.altKey}function FR({shortcuts:t,children:a}){return v.createElement(Zb.Provider,{value:qR(t)},a)}function Wb(t){const a=v.useContext(Zb);if(t)return $R(t)?t:a[t]}function An(t,a,l){const s=Wb(t);v.useEffect(()=>{if(!s||(l==null?void 0:l.enabled)===!1)return;const o=u=>{!(l!=null&&l.allowInEditable)&&VR(u.target)||YR(u,s)&&(u.preventDefault(),a())};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[a,l==null?void 0:l.allowInEditable,l==null?void 0:l.enabled,s])}const PR=1500,GR=80,XR=12e3,QR=5e3;function KR(){const{revalidate:t}=hE(),a=v.useRef(null),l=v.useRef(null),s=v.useRef(null),o=v.useRef(null),u=v.useRef(null);return v.useEffect(()=>{let f=!0;const m=X=>{window.dispatchEvent(new CustomEvent("agent-plan:ws-status",{detail:{status:X}}))},p=()=>{l.current!==null&&(window.clearTimeout(l.current),l.current=null)},g=()=>{s.current!==null&&(window.clearTimeout(s.current),s.current=null)},x=()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},y=()=>{o.current!==null&&(window.clearInterval(o.current),o.current=null)},N=()=>{g(),s.current=window.setTimeout(()=>{t()},GR)},w=()=>{!f||l.current!==null||(m("reconnecting"),l.current=window.setTimeout(()=>{l.current=null,R()},PR))},S=()=>{y(),x();const X=a.current;if(a.current=null,X&&(X.readyState===WebSocket.OPEN||X.readyState===WebSocket.CONNECTING))try{X.close()}catch{}},D=()=>{y(),x(),o.current=window.setInterval(()=>{const X=a.current;if(!(!X||X.readyState!==WebSocket.OPEN)){try{X.send(JSON.stringify({type:"ping"}))}catch{S(),w();return}x(),u.current=window.setTimeout(()=>{S(),w()},QR)}},XR)},R=()=>{if(!f)return;const X=a.current;if(X&&(X.readyState===WebSocket.OPEN||X.readyState===WebSocket.CONNECTING))return;m(l.current!==null?"reconnecting":"connecting"),p();const W=window.location.protocol==="https:"?"wss":"ws",ae=new WebSocket(`${W}://${window.location.host}/ws`);a.current=ae,ae.onopen=()=>{p(),m("live"),D()},ae.onmessage=z=>{x();try{const T=JSON.parse(z.data);if(!T.type||T.type==="pong"||T.type==="connected")return;switch(window.dispatchEvent(new CustomEvent("agent-plan:ws-event",{detail:T})),T.type){case"project-updated":case"features-updated":case"phases-updated":case"requirements-updated":case"plan-rendered":case"file-changed":case"handoffUpdated":case"handoffCleared":N();break;default:break}}catch{}},ae.onclose=()=>{y(),x(),a.current===ae&&(a.current=null),f&&w()},ae.onerror=()=>{try{ae.close()}catch{}}},L=()=>{const X=a.current;(!X||X.readyState===WebSocket.CLOSED||X.readyState===WebSocket.CLOSING)&&R()},I=()=>{document.visibilityState==="visible"&&L()},q=()=>{L()};return m("connecting"),R(),window.addEventListener("online",q),document.addEventListener("visibilitychange",I),()=>{f=!1,m("disconnected"),window.removeEventListener("online",q),document.removeEventListener("visibilitychange",I),p(),g(),y(),x(),S()}},[t]),null}async function ZR(){const[t,a,l]=await Promise.all([Ib(),pR(),Pb()]);return{project:t,uiConfig:a,activeTasks:l}}function JR(){const{project:t,uiConfig:a,activeTasks:l}=ll();return v.useEffect(()=>{var f,m;const s=(f=t==null?void 0:t.name)==null?void 0:f.trim(),o=(m=t==null?void 0:t.projectRoot)==null?void 0:m.trim(),u=o?o.split(/[/\\]/).filter(Boolean).pop():void 0;s?u&&u!==s?document.title=`${s} · ${u}`:document.title=`${s} · Agent Plan`:document.title="Agent Plan"},[t==null?void 0:t.name,t==null?void 0:t.projectRoot]),HR(l.length>0),c.jsxs(FR,{shortcuts:a.shortcuts,children:[c.jsx(KR,{}),c.jsx(_R,{project:t,activeTasks:l,serverInfo:a.server})]})}function WR(){const t=Tb(),a=ci(t),l=a&&t.status===503,s=a?l?"Planner web UI disconnected":`Request failed (${t.status})`:"Planner web UI unavailable",o=a?t.data||t.statusText:t instanceof Error?t.message:"The planner web UI could not reach its local server.";return v.useEffect(()=>{document.title="Agent Plan"},[]),c.jsx("div",{className:"page-shell min-h-screen",children:c.jsx("div",{className:"page-container flex min-h-screen items-center justify-center py-12",children:c.jsxs("div",{className:"surface-card max-w-2xl rounded-[24px] px-8 py-8",children:[c.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.24em] text-[var(--text-subtle)]",children:"Agent Plan"}),c.jsx("h1",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] md:text-3xl",children:s}),c.jsx("p",{className:"mt-4 text-sm text-[var(--text-muted)]",children:String(o)}),c.jsx("div",{className:"mt-6 grid gap-2 text-sm text-[var(--text-muted)]",children:l?c.jsxs(c.Fragment,{children:[c.jsx("p",{children:"Possible cause: Pi was closed or the local planner web server stopped."}),c.jsx("p",{children:"What to do:"}),c.jsxs("ul",{className:"grid gap-1 pl-5",children:[c.jsxs("li",{className:"list-disc",children:["restart Pi or run ",c.jsx("code",{children:"planner-web start"})]}),c.jsx("li",{className:"list-disc",children:"reopen this planner UI from the new session if needed"}),c.jsx("li",{className:"list-disc",children:"then reload this page"})]})]}):c.jsxs(c.Fragment,{children:[c.jsx("p",{children:"The request reached the planner server, but the server rejected it."}),c.jsx("p",{children:"Fix the validation issue above, then try again."})]})}),c.jsx("div",{className:"mt-6 flex flex-wrap gap-3",children:c.jsx("button",{type:"button",onClick:()=>window.location.reload(),className:"inline-flex min-h-9 items-center whitespace-nowrap rounded-[12px] bg-[var(--accent)] px-3 py-1.5 text-sm font-semibold text-white transition hover:opacity-90 sm:min-h-11 sm:rounded-[14px] sm:px-4 sm:py-2",children:"Reload page"})})]})})})}async function e2(){const[t,a,l]=await Promise.all([Vb(),Kc(),Pb()]);return{features:t,phases:a,activeTasks:l}}function t2({shortcut:t}){const a=Wb(t);return a?c.jsx("span",{className:"hidden rounded-md border border-[var(--border-strong)] bg-[var(--surface-elevated)] px-2 py-0.5 text-[11px] font-bold tracking-wide text-[var(--text-muted)] sm:inline-block",children:IR(a)}):null}const n2={primary:"border-transparent bg-[var(--accent)] text-white hover:bg-[var(--accent-hover)]",secondary:"border-[var(--border-strong)] bg-[var(--surface-elevated)] text-[var(--text)] hover:bg-[var(--accent-soft)] hover:text-[var(--text)]",ghost:"border-transparent bg-transparent text-[var(--text-muted)] hover:bg-[var(--accent-soft)] hover:text-[var(--text)]",danger:"border-transparent bg-[var(--danger-soft)] text-[var(--color-status-blocked)] hover:bg-[color-mix(in_srgb,var(--danger-soft)_88%,black_12%)]"};function gt({variant:t="secondary",className:a="",children:l,shortcut:s,...o}){return c.jsxs("button",{className:`inline-flex min-h-9 items-center justify-center gap-1.5 whitespace-nowrap rounded-[12px] border px-3 py-1.5 text-sm font-semibold transition-colors motion-reduce:transition-none focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)] focus-visible:ring-offset-2 focus-visible:ring-offset-[var(--surface)] disabled:cursor-not-allowed disabled:opacity-60 sm:min-h-11 sm:rounded-[14px] sm:px-4 sm:py-2 sm:gap-2 ${n2[t]} ${a}`,...o,children:[c.jsx("span",{className:"inline-flex items-center gap-1.5 sm:gap-2",children:l}),s?c.jsx(t2,{shortcut:s}):null]})}function Pt({className:t="",children:a,...l}){return c.jsx("div",{className:`surface-card p-6 ${t}`,...l,children:a})}function a2({decisions:t}){return t.length===0?null:c.jsxs("details",{className:"group rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-4 py-4",children:[c.jsxs("summary",{className:"cursor-pointer select-none font-semibold text-[var(--text)]",children:["Accepted decisions (",t.length,")"]}),c.jsx("div",{className:"mt-4 grid gap-3",children:t.map(a=>c.jsxs("div",{className:"rounded-[14px] border border-[var(--border)] bg-[var(--surface-elevated)] px-4 py-3",children:[c.jsx("p",{className:"text-sm font-semibold text-[var(--text)]",children:a.title}),a.decision?c.jsxs("div",{className:"mt-2 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Decision:"})," ",c.jsx(xn,{text:a.decision})]}):null,a.rationale?c.jsxs("div",{className:"mt-1 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Rationale:"})," ",c.jsx(xn,{text:a.rationale})]}):null,a.implementationNotes?c.jsxs("div",{className:"mt-1 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Implementation:"})," ",c.jsx(xn,{text:a.implementationNotes})]}):null]},a.id))})]})}function r2({project:t}){var x,y,N;const a=t.scope??[],l=t.outOfScope??[],s=t.technologies??[],o=t.tools??[],u=t.globalRules??[],f=t.decisions??[],m=t.acceptedDecisions??[],p={beforePhaseStart:((x=t.workflowRules)==null?void 0:x.beforePhaseStart)??[],beforeTaskStart:((y=t.workflowRules)==null?void 0:y.beforeTaskStart)??[],afterPhaseComplete:((N=t.workflowRules)==null?void 0:N.afterPhaseComplete)??[]};return a.length>0||l.length>0||s.length>0||o.length>0||u.length>0||f.length>0||m.length>0||p.beforePhaseStart.length>0||p.beforeTaskStart.length>0||p.afterPhaseComplete.length>0?c.jsx(Pt,{className:"grid gap-4",children:c.jsxs("details",{className:"group",children:[c.jsx("summary",{className:"cursor-pointer select-none text-lg font-bold text-[var(--text)]",children:"AI Consolidated Context"}),c.jsxs("div",{className:"mt-4 grid gap-4",children:[a.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"In scope"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:a.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,l.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Out of scope"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:l.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,s.length>0||o.length>0?c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[s.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Technologies"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:s.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,o.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Tools"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:o.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null]}):null,u.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"text-sm font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Global rules"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:u.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,p.beforePhaseStart.length>0||p.beforeTaskStart.length>0||p.afterPhaseComplete.length>0?c.jsxs("details",{className:"group rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-4 py-4",children:[c.jsx("summary",{className:"cursor-pointer select-none font-semibold text-[var(--text)]",children:"Workflow rules"}),c.jsxs("div",{className:"mt-4 grid gap-4 text-sm text-[var(--text-muted)]",children:[p.beforePhaseStart.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"font-semibold text-[var(--text)]",children:"Before phase start"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5",children:p.beforePhaseStart.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,p.beforeTaskStart.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"font-semibold text-[var(--text)]",children:"Before task start"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5",children:p.beforeTaskStart.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,p.afterPhaseComplete.length>0?c.jsxs("div",{children:[c.jsx("h3",{className:"font-semibold text-[var(--text)]",children:"After phase complete"}),c.jsx("ul",{className:"mt-2 grid gap-2 pl-5",children:p.afterPhaseComplete.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null]})]}):null,f.length>0?c.jsxs("details",{className:"group rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-4 py-4",children:[c.jsxs("summary",{className:"cursor-pointer select-none font-semibold text-[var(--text)]",children:["Legacy decisions (",f.length,")"]}),c.jsx("ul",{className:"mt-4 grid gap-2 pl-5 text-sm text-[var(--text-muted)]",children:f.map(w=>c.jsx("li",{className:"list-disc",children:w},w))})]}):null,c.jsx(a2,{decisions:m})]})]})}):null}const Fh={planned:{colorVar:"--color-status-planned",icon:"circle",pattern:"",label:"Planned",description:"Not started",borderStyle:"solid",bgOpacity:10,borderOpacity:30},started:{colorVar:"--color-status-started",icon:"play-start",pattern:"dashed",label:"Started",description:"Begun but not active now",borderStyle:"dashed",bgOpacity:10,borderOpacity:30},"in-progress":{colorVar:"--color-status-in-progress",icon:"play",pattern:"pulse",label:"In progress",description:"Active now",borderStyle:"solid",bgOpacity:12,borderOpacity:30},waiting:{colorVar:"--color-status-waiting",icon:"clock",pattern:"dashed",label:"Waiting",description:"Waiting on a dependency",borderStyle:"dashed",bgOpacity:10,borderOpacity:30},blocked:{colorVar:"--color-status-blocked",icon:"stop",pattern:"",label:"Blocked",description:"Impediment",borderStyle:"solid",bgOpacity:12,borderOpacity:30},deferred:{colorVar:"--color-status-deferred",icon:"pause",pattern:"dashed",label:"Deferred",description:"Postponed",borderStyle:"dashed",bgOpacity:10,borderOpacity:30},done:{colorVar:"--color-status-done",icon:"check",pattern:"",label:"Done",description:"Completed",borderStyle:"solid",bgOpacity:14,borderOpacity:30},closed:{colorVar:"--color-status-closed",icon:"check-mixed",pattern:"",label:"Closed",description:"Closed with mixed outcomes",borderStyle:"solid",bgOpacity:14,borderOpacity:30},canceled:{colorVar:"--color-status-canceled",icon:"ban",pattern:"hatch",label:"Canceled",description:"Canceled",borderStyle:"solid",bgOpacity:8,borderOpacity:30},rejected:{colorVar:"--color-status-rejected",icon:"x",pattern:"crosshatch",label:"Rejected",description:"Rejected",borderStyle:"solid",bgOpacity:10,borderOpacity:30}};function $l(t){return Fh[t]??Fh.planned}function Ac(t,a,l){switch(a){case"bg":return`color-mix(in srgb, var(${t.colorVar}) ${t.bgOpacity}%, transparent)`;case"border":return`color-mix(in srgb, var(${t.colorVar}) ${t.borderOpacity}%, transparent)`}}function l2(t){const a=$l(t);return{backgroundColor:Ac(a,"bg"),borderStyle:a.borderStyle,borderColor:Ac(a,"border"),borderWidth:"1px"}}function s2(t){const a=$l(t);return{backgroundColor:Ac(a,"bg"),borderStyle:a.borderStyle,borderColor:Ac(a,"border"),borderWidth:"1px"}}function bm(t){const{pattern:a}=$l(t);return a?a==="dashed"?`status-pattern-dashed status-pattern-dashed-${t}`:`status-pattern-${a}`:""}function e0(t){return`status-${t}`}function t0(t,a=30){return`color-mix(in srgb, var(${$l(t).colorVar}) ${a}%, transparent)`}function n0(t){return t in Fh?t:"planned"}function i2(t,a){const s=[$l(t).label],o=[["done",a.done],["in-progress",a.inProgress],["planned",a.planned],["waiting",a.waiting],["blocked",a.blocked],["deferred",a.deferred],["canceled",a.canceled],["rejected",a.rejected]];for(const[u,f]of o)f>0&&s.push(`${f} ${u}`);return s.join(" · ")}const a0={circle:Pc,"play-start":eR,play:Ub,clock:LN,stop:Hb,pause:zb,check:pm,"check-mixed":EN,ban:Mb,x:ON};function o2({status:t,className:a=""}){const l=$l(t),s=a0[l.icon]??Pc;return c.jsx(s,{className:`h-4 w-4 shrink-0 ${a}`.trim(),"aria-hidden":"true"})}function ur({status:t}){const a=n0(t),l=$l(a);return c.jsxs("span",{className:`status-chip ${e0(a)} ${bm(a)}`,title:l.description,"aria-label":l.description,children:[c.jsx(o2,{status:a,className:"h-3.5 w-3.5"}),c.jsx("span",{children:l.label})]})}function Vo({status:t,breakdown:a,size:l="md",children:s}){const o=$l(t),u=a0[o.icon]??Pc,f=bm(t),m=a?i2(t,a):o.description,p=l==="sm"?"px-2 py-0.5 text-[10px]":"px-2.5 py-1 text-[11px]";return c.jsxs("span",{className:`status-chip ${e0(t)} ${f} ${p}`,title:m,"aria-label":m,children:[c.jsx(u,{className:"h-3.5 w-3.5"}),c.jsx("span",{children:o.label}),s]})}function kc({status:t,breakdown:a,doneTasks:l,totalTasks:s,recentlyChanged:o,className:u}){const f=l!=null&&s!=null;return c.jsxs("div",{className:u,children:[o?c.jsx("span",{className:"rounded-full bg-[color:color-mix(in_srgb,var(--accent)_16%,transparent)] px-2 py-0.5 text-[10px] font-semibold uppercase tracking-[0.12em] text-[var(--accent)]",children:"Updated"}):null,f?c.jsxs("span",{className:"text-xs text-[var(--text-muted)]",children:["(",l,"/",s||0,")"]}):null,c.jsx(Vo,{status:t,breakdown:a})]})}function u2(t){try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}function c2({features:t,phases:a}){const l=v.useMemo(()=>{const s=new Map(t.map(o=>[o.id,o.name]));return a.flatMap(o=>o.tasks.filter(u=>u.status==="done").map(u=>({task:u,phase:o,feature:t.find(f=>f.id===o.featureId),featureName:o.featureId?s.get(o.featureId)??o.featureId:"Unlinked feature",completedAt:u.completedAt||u.updatedAt}))).sort((o,u)=>u.completedAt.localeCompare(o.completedAt)).slice(0,3)},[t,a]);return c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-bold text-[var(--text)]",children:"Latest completed tasks"}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Most recently completed tasks, ordered by completion timestamp."})]}),c.jsx("div",{className:"grid gap-3",children:l.length>0?l.map(({task:s,phase:o,feature:u,featureName:f,completedAt:m})=>c.jsxs(Ye,{to:o.featureId?`/features/${o.featureId}/phases/${o.id}/tasks/${s.id}`:"/features",className:"surface-card grid min-w-0 grid-cols-1 gap-1 px-4 py-3 transition hover:border-[var(--accent)] hover:bg-[var(--accent-soft)]",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(Xb,{type:"task",number:s.number}),c.jsx(Dc,{type:"task",phaseNum:o.number,featureNum:u==null?void 0:u.number}),c.jsx("span",{className:"shrink-0",children:c.jsx(ur,{status:s.status})})]}),c.jsx("span",{className:"entity-link--task min-w-0 break-words text-sm font-semibold underline-offset-4 [overflow-wrap:anywhere]",children:s.title}),c.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-[var(--text-muted)]",children:[c.jsx(Dc,{type:"phase",featureNum:u==null?void 0:u.number}),c.jsxs("span",{className:"min-w-0 truncate",children:[f," · ",o.title]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-subtle)]",children:["Completed ",u2(m)]})]},s.id)):c.jsx("p",{className:"py-4 text-center text-sm text-[var(--text-muted)]",children:"No completed tasks yet."})})]})}const rx=1440*60*1e3;function d2(t){const a=Date.now()-new Date(t).getTime();if(a<0)return"just now";const l=Math.floor(a/1e3);if(l<60)return`${l}s ago`;const s=Math.floor(l/60);return s<60?`${s}m ago`:new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}function f2({features:t,phases:a}){const[,l]=v.useState(0),s=Date.now(),o=v.useMemo(()=>{const u=new Map(t.map(f=>[f.id,f.name]));return a.flatMap(f=>f.tasks.map(m=>({task:m,phase:f,feature:t.find(p=>p.id===f.featureId),featureName:f.featureId?u.get(f.featureId)??f.featureId:"Unlinked feature",createdAt:m.createdAt}))).filter(f=>{const m=new Date(f.createdAt).getTime();return Number.isFinite(m)&&s-m<rx&&s-m>=0&&f.task.status==="planned"&&!f.task.startedAt}).sort((f,m)=>m.createdAt.localeCompare(f.createdAt)).slice(0,10)},[t,a,s]);return v.useEffect(()=>{if(o.length===0)return;const u=o.reduce((m,p)=>{const g=new Date(p.createdAt).getTime()+rx-Date.now();return Math.min(m,g)},1/0);if(!Number.isFinite(u)||u<=0)return;const f=window.setTimeout(()=>l(m=>m+1),u+50);return()=>window.clearTimeout(f)},[o]),o.length===0?null:c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-bold text-[var(--text)]",children:"New Added Tasks"}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Tasks created in the last 24 hours."})]}),c.jsx("div",{className:"grid gap-3",children:o.map(({task:u,phase:f,feature:m,featureName:p,createdAt:g})=>c.jsxs(Ye,{to:f.featureId?`/features/${f.featureId}/phases/${f.id}/tasks/${u.id}`:"/features",className:"surface-card grid min-w-0 grid-cols-1 gap-1 border-[color:color-mix(in_srgb,var(--color-status-done)_0%,transparent)] px-4 py-3 transition hover:border-[var(--accent)] hover:bg-[var(--accent-soft)]",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(Xb,{type:"task",number:u.number}),c.jsx(Dc,{type:"task",phaseNum:f.number,featureNum:m==null?void 0:m.number}),c.jsx("span",{className:"inline-flex items-center rounded-full bg-[color:color-mix(in_srgb,var(--accent)_18%,transparent)] px-2 py-0.5 text-[10px] font-bold uppercase tracking-wider text-[var(--accent)]",children:"New"}),c.jsx("span",{className:"shrink-0",children:c.jsx(ur,{status:u.status})})]}),c.jsx("span",{className:"entity-link--task min-w-0 break-words text-sm font-semibold underline-offset-4 [overflow-wrap:anywhere]",children:u.title}),c.jsxs("div",{className:"flex min-w-0 items-center gap-2 text-xs text-[var(--text-muted)]",children:[c.jsx(Dc,{type:"phase",featureNum:m==null?void 0:m.number}),c.jsxs("span",{className:"min-w-0 truncate",children:[p," · ",f.title]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-subtle)]",children:["Added ",d2(g)]})]},u.id))})]})}const h2=new Set(["in-progress"]),m2=new Set(["planned","waiting","blocked","deferred"]),p2=new Set(["done","canceled","rejected"]);function r0(t){return t==="discovery"?"in-progress":t==="draft"?"planned":t}function g2(t){const a={planned:0,inProgress:0,waiting:0,blocked:0,deferred:0,done:0,canceled:0,rejected:0};for(const l of t)switch(l){case"planned":a.planned++;break;case"in-progress":a.inProgress++;break;case"waiting":a.waiting++;break;case"blocked":a.blocked++;break;case"deferred":a.deferred++;break;case"done":a.done++;break;case"canceled":a.canceled++;break;case"rejected":a.rejected++;break}return a}function v2(){return{planned:0,inProgress:0,waiting:0,blocked:0,deferred:0,done:0,canceled:0,rejected:0}}function l0(t){const a=t,l=g2(a),s=a.length;if(s===0)return{displayStatus:"planned",breakdown:v2(),hasStarted:!1,totalChildren:0,meaningfulChildren:0};const o=a.filter(g=>g!=="canceled"&&g!=="rejected"),u=o.length,f=o.some(g=>g!=="planned");if(o.some(g=>h2.has(g)))return{displayStatus:"in-progress",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u};if(a.every(g=>p2.has(g)))return a.every(g=>g==="done")?{displayStatus:"done",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:a.every(g=>g==="canceled")?{displayStatus:"canceled",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:a.every(g=>g==="rejected")?{displayStatus:"rejected",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:{displayStatus:"closed",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u};const m=o.filter(g=>m2.has(g));return m.length>0&&m.every(g=>g==="waiting")?{displayStatus:"waiting",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:m.length>0&&m.every(g=>g==="blocked")?{displayStatus:"blocked",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:m.length>0&&m.every(g=>g==="deferred")?{displayStatus:"deferred",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:m.length>0&&m.every(g=>g==="planned")&&!f?{displayStatus:"planned",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}:{displayStatus:"started",breakdown:l,hasStarted:f,totalChildren:s,meaningfulChildren:u}}function Sm(t){const a=t.map(l=>r0(l.status));return l0(a)}function wm(t){const a=t.map(l=>r0(l.status));return l0(a)}function s0(t){return wm(t)}function i0(t){return Sm(t)}const So={key:"priority",direction:"asc"},y2=4200;function x2(t){return t.reduce((a,l)=>a+l.tasks.length,0)}function b2(t){return t.reduce((a,l)=>a+l.tasks.filter(s=>s.status==="done").length,0)}function S2(t){return String(t&&t>0?t:0).padStart(3,"0")}const w2={draft:0,discovery:1,planned:2,waiting:3,blocked:4,deferred:5,"in-progress":6,done:7,canceled:8,rejected:9};function lx(t,a){if(a==="title")return"name"in t?t.name:t.title;if(a==="status")return w2[t.status]??99;if(a==="startedAt"){if("startedAt"in t){const l=t.startedAt;return l?new Date(l).getTime():Number.MAX_SAFE_INTEGER}return Number.MAX_SAFE_INTEGER}if(a==="completedAt"){if("completedAt"in t){const l=t.completedAt;return l?new Date(l).getTime():Number.MAX_SAFE_INTEGER}return Number.MAX_SAFE_INTEGER}if(a==="shortId")return t.shortId??"";if(a==="priority"||a==="number")return t[a]??0;if(a==="createdAt"||a==="updatedAt"){const l=t[a];return l?new Date(l).getTime():0}return 0}function Eo(t,a,l,s){const o=lx(t,l),u=lx(a,l);let f;return typeof o=="number"&&typeof u=="number"?f=o-u:f=String(o).localeCompare(String(u)),f===0&&(f=(t.priority??0)-(a.priority??0)||t.number-a.number||t.createdAt.localeCompare(a.createdAt)),s==="desc"?-f:f}function E2(t,a,l=So){const s=new Map;for(const o of a){if(!o.featureId)continue;const u=s.get(o.featureId)??[];u.push(o),s.set(o.featureId,u)}return t.map(o=>{const u=s.get(o.id)??[],f=u.reduce((x,y)=>x+y.tasks.length,0),m=u.reduce((x,y)=>x+y.tasks.filter(N=>N.status==="done").length,0),p=u.map(x=>{const y=[...x.tasks].sort((w,S)=>Eo(w,S,l.key,l.direction)),N=y.some(w=>w.status==="in-progress");return{phase:x,totalTasks:x.tasks.length,doneTasks:x.tasks.filter(w=>w.status==="done").length,allTasks:y,hasActiveTask:N,display:Sm(y)}}),g=p.some(({phase:x,allTasks:y})=>x.status==="in-progress"||x.status==="discovery"||y.some(N=>N.status==="in-progress"));return{feature:o,totalTasks:f,doneTasks:m,allPhases:p.sort((x,y)=>Eo(x.phase,y.phase,l.key,l.direction)),hasActiveTask:p.some(x=>x.hasActiveTask),isActive:g,display:wm(p.map(x=>x.phase))}}).sort((o,u)=>Eo(o.feature,u.feature,l.key,l.direction))}function uc({title:t,value:a,valueSuffix:l,subtitle:s,icon:o,valueClassName:u,iconClassName:f}){return c.jsxs(Pt,{className:"flex items-start justify-between gap-4",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:t}),c.jsxs("div",{className:"mt-2 flex items-end gap-2",children:[c.jsx("p",{className:`text-3xl font-black tracking-tight ${u??"text-[var(--text)]"}`,children:a}),l?c.jsx("span",{className:"pb-1 text-sm font-semibold text-[var(--text-muted)]",children:l}):null]}),c.jsx("p",{className:"mt-1 text-sm text-[var(--text-muted)]",children:s})]}),c.jsx("div",{className:`surface-card flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl border border-[var(--border)] bg-[var(--accent-soft)] ${f??"text-[var(--accent)]"}`,children:o})]})}function sx(t){return t>=80?"text-emerald-600 dark:text-emerald-400":t>=30?"text-amber-600 dark:text-amber-400":"text-rose-600 dark:text-rose-400"}function N2({features:t,phases:a}){const l=new Map;for(const y of a)y.featureId&&l.set(y.featureId,[...l.get(y.featureId)??[],y]);const s=t.filter(y=>{const N=l.get(y.id)??[];return wm(N).displayStatus==="done"}).length,o=Math.max(t.length-s,0),u=a.filter(y=>Sm(y.tasks).displayStatus==="done").length,f=Math.max(a.length-u,0),m=x2(a),p=b2(a),g=Math.max(m-p,0),x=m>0?Math.round(p/m*100):0;return c.jsxs("div",{className:"grid gap-4 lg:grid-cols-4",children:[c.jsx(uc,{title:"Features",value:String(t.length),valueSuffix:"total",subtitle:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"font-semibold text-emerald-600 dark:text-emerald-400",children:[s," done"]}),c.jsx("span",{children:" · "}),c.jsxs("span",{className:"font-semibold text-amber-600 dark:text-amber-400",children:[o," left"]})]}),icon:c.jsx(Cc,{className:"h-4 w-4"})}),c.jsx(uc,{title:"Phases",value:String(a.length),valueSuffix:"total",subtitle:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"font-semibold text-emerald-600 dark:text-emerald-400",children:[u," done"]}),c.jsx("span",{children:" · "}),c.jsxs("span",{className:"font-semibold text-amber-600 dark:text-amber-400",children:[f," left"]})]}),icon:c.jsx(yN,{className:"h-4 w-4"})}),c.jsx(uc,{title:"Tasks",value:String(m),valueSuffix:"total",subtitle:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"font-semibold text-emerald-600 dark:text-emerald-400",children:[p," done"]}),c.jsx("span",{children:" · "}),c.jsxs("span",{className:"font-semibold text-amber-600 dark:text-amber-400",children:[g," left"]})]}),icon:c.jsx(qo,{className:"h-4 w-4"})}),c.jsx(uc,{title:"Completion",value:`${x}%`,subtitle:"Task completion rate",valueClassName:sx(x),iconClassName:sx(x),icon:c.jsx(pm,{className:"h-4 w-4"})})]})}function R2(){for(var t=arguments.length,a=new Array(t),l=0;l<t;l++)a[l]=arguments[l];return v.useMemo(()=>s=>{a.forEach(o=>o(s))},a)}const Wc=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function mi(t){const a=Object.prototype.toString.call(t);return a==="[object Window]"||a==="[object global]"}function Em(t){return"nodeType"in t}function pa(t){var a,l;return t?mi(t)?t:Em(t)&&(a=(l=t.ownerDocument)==null?void 0:l.defaultView)!=null?a:window:window}function Nm(t){const{Document:a}=pa(t);return t instanceof a}function Yo(t){return mi(t)?!1:t instanceof pa(t).HTMLElement}function o0(t){return t instanceof pa(t).SVGElement}function pi(t){return t?mi(t)?t.document:Em(t)?Nm(t)?t:Yo(t)||o0(t)?t.ownerDocument:document:document:document}const dr=Wc?v.useLayoutEffect:v.useEffect;function ed(t){const a=v.useRef(t);return dr(()=>{a.current=t}),v.useCallback(function(){for(var l=arguments.length,s=new Array(l),o=0;o<l;o++)s[o]=arguments[o];return a.current==null?void 0:a.current(...s)},[])}function j2(){const t=v.useRef(null),a=v.useCallback((s,o)=>{t.current=setInterval(s,o)},[]),l=v.useCallback(()=>{t.current!==null&&(clearInterval(t.current),t.current=null)},[]);return[a,l]}function ko(t,a){a===void 0&&(a=[t]);const l=v.useRef(t);return dr(()=>{l.current!==t&&(l.current=t)},a),l}function Fo(t,a){const l=v.useRef();return v.useMemo(()=>{const s=t(l.current);return l.current=s,s},[...a])}function Oc(t){const a=ed(t),l=v.useRef(null),s=v.useCallback(o=>{o!==l.current&&(a==null||a(o,l.current)),l.current=o},[]);return[l,s]}function Mc(t){const a=v.useRef();return v.useEffect(()=>{a.current=t},[t]),a.current}let Sh={};function Po(t,a){return v.useMemo(()=>{if(a)return a;const l=Sh[t]==null?0:Sh[t]+1;return Sh[t]=l,t+"-"+l},[t,a])}function u0(t){return function(a){for(var l=arguments.length,s=new Array(l>1?l-1:0),o=1;o<l;o++)s[o-1]=arguments[o];return s.reduce((u,f)=>{const m=Object.entries(f);for(const[p,g]of m){const x=u[p];x!=null&&(u[p]=x+t*g)}return u},{...a})}}const ui=u0(1),_c=u0(-1);function T2(t){return"clientX"in t&&"clientY"in t}function td(t){if(!t)return!1;const{KeyboardEvent:a}=pa(t.target);return a&&t instanceof a}function C2(t){if(!t)return!1;const{TouchEvent:a}=pa(t.target);return a&&t instanceof a}function Lc(t){if(C2(t)){if(t.touches&&t.touches.length){const{clientX:a,clientY:l}=t.touches[0];return{x:a,y:l}}else if(t.changedTouches&&t.changedTouches.length){const{clientX:a,clientY:l}=t.changedTouches[0];return{x:a,y:l}}}return T2(t)?{x:t.clientX,y:t.clientY}:null}const Ul=Object.freeze({Translate:{toString(t){if(!t)return;const{x:a,y:l}=t;return"translate3d("+(a?Math.round(a):0)+"px, "+(l?Math.round(l):0)+"px, 0)"}},Scale:{toString(t){if(!t)return;const{scaleX:a,scaleY:l}=t;return"scaleX("+a+") scaleY("+l+")"}},Transform:{toString(t){if(t)return[Ul.Translate.toString(t),Ul.Scale.toString(t)].join(" ")}},Transition:{toString(t){let{property:a,duration:l,easing:s}=t;return a+" "+l+"ms "+s}}}),ix="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function D2(t){return t.matches(ix)?t:t.querySelector(ix)}const A2={display:"none"};function k2(t){let{id:a,value:l}=t;return un.createElement("div",{id:a,style:A2},l)}function O2(t){let{id:a,announcement:l,ariaLiveType:s="assertive"}=t;const o={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return un.createElement("div",{id:a,style:o,role:"status","aria-live":s,"aria-atomic":!0},l)}function M2(){const[t,a]=v.useState("");return{announce:v.useCallback(s=>{s!=null&&a(s)},[]),announcement:t}}const c0=v.createContext(null);function _2(t){const a=v.useContext(c0);v.useEffect(()=>{if(!a)throw new Error("useDndMonitor must be used within a children of <DndContext>");return a(t)},[t,a])}function L2(){const[t]=v.useState(()=>new Set),a=v.useCallback(s=>(t.add(s),()=>t.delete(s)),[t]);return[v.useCallback(s=>{let{type:o,event:u}=s;t.forEach(f=>{var m;return(m=f[o])==null?void 0:m.call(f,u)})},[t]),a]}const z2={draggable:`
274
274
  To pick up a draggable item, press the space bar.
@@ -285,9 +285,9 @@ ${TC(Rc(t.expression,a+1,l,s,o),a+1,s)}
285
285
  ${u})`;return t.boost!=null&&(f+=`^${t.boost}`),f}case"FieldGroup":{let f=`${t.field}:(${Tr(t.expression,o)})`;return t.boost!=null&&(f+=`^${t.boost}`),f}case"Not":{const{op:f,sep:m}=q0(t,o);return`${f}${m}${Rc(t.expression,a,l,s,o)}`}default:return Tr(t,o)}}function TC(t,a,l){const s=l.repeat(a);return t.split(`
286
286
  `).map(o=>o.startsWith(s)?o:s+o).join(`
287
287
  `)}function CC(t){return t?Co(t):[]}function Bx(t){return t.type==="BooleanExpr"}function Co(t){switch(t.type){case"BooleanExpr":return Zh(t);case"Group":{const a=[],l=t.expression;return Bx(l)?(a.push({start:t.start,end:t.end}),a.push(...Co(l)),a.push({start:t.start,end:t.end})):a.push({start:t.start,end:t.end}),a}case"FieldGroup":{const a=[];a.push({start:t.start,end:t.end});const l=t.expression;return Bx(l)&&a.push(...Co(l)),a}case"Not":{const a=[];return a.push({start:t.start,end:t.end}),a.push(...Co(t.expression)),a}case"FieldValue":case"BareTerm":case"SavedSearch":case"HistoryRef":case"Regex":case"Range":case"Error":return[{start:t.start,end:t.end}]}}function Zh(t){return t.type==="BooleanExpr"?[...Zh(t.left),...Zh(t.right)]:Co(t)}function DC(t,a,l,s){if(t.length===0)return null;if(a>=0&&a<t.length){const o=s==="forward"?a+1:a-1;return o>=0&&o<t.length?{stop:t[o],index:o}:null}if(s==="forward"){for(let o=0;o<t.length;o++)if(t[o].start>=l)return{stop:t[o],index:o};return{stop:t[t.length-1],index:t.length-1}}else{for(let o=t.length-1;o>=0;o--)if(t[o].end<=l)return{stop:t[o],index:o};return{stop:t[0],index:0}}}var AC=class{constructor(t=100){hn(this,"stack",[]);hn(this,"index",-1);hn(this,"maxSize");this.maxSize=t}push(t){if(this.index>=0&&this.stack[this.index].value===t.value){this.stack[this.index].cursorPos=t.cursorPos;return}this.stack=this.stack.slice(0,this.index+1),this.stack.push(t),this.stack.length>this.maxSize&&this.stack.shift(),this.index=this.stack.length-1}replaceCurrent(t){this.index>=0?this.stack[this.index]=t:this.push(t)}undo(){return this.index<=0?null:(this.index--,this.stack[this.index])}redo(){return this.index>=this.stack.length-1?null:(this.index++,this.stack[this.index])}canUndo(){return this.index>0}canRedo(){return this.index<this.stack.length-1}current(){return this.index>=0?this.stack[this.index]:null}clear(){this.stack=[],this.index=-1}get length(){return this.stack.length}};function kC(t,a){const l=s=>(a==null?void 0:a(s))??BT(s);if(t.type==="RANGE"&&t.token){const s=t.token.value,o=(s.endsWith("]")||s.endsWith("}")?s.slice(1,-1):s.slice(1)).match(/^(.*?)\s+[Tt][Oo]\s+(.*)$/);if(o)return{mode:"range",start:l(o[1].trim()),end:l(o[2].trim())}}if(t.type==="FIELD_VALUE"&&t.partial){const s=l(t.partial);if(s)return{mode:"single",start:s,end:null}}return null}function OC(t,a){var l,s,o,u;return((t==null?void 0:t.mode)??"single")!==((a==null?void 0:a.mode)??"single")||(((l=t==null?void 0:t.start)==null?void 0:l.getTime())??0)!==(((s=a==null?void 0:a.start)==null?void 0:s.getTime())??0)?!0:(((o=t==null?void 0:t.end)==null?void 0:o.getTime())??0)!==(((u=a==null?void 0:a.end)==null?void 0:u.getTime())??0)}function MC({position:t,colors:a,onSelect:l,colorConfig:s,styleConfig:o,datePickerInit:u,fixedWidth:f,datePresets:m,datePickerClassName:p}){const g=v.useRef(null),[x,y]=v.useState(!1);if(v.useEffect(()=>{const S=document.createElement("div");return document.body.appendChild(S),g.current=S,y(!0),()=>{document.body.removeChild(S),g.current=null}},[]),!x||!g.current)return null;const N=Ko(o),w={position:"absolute",zIndex:N.dropdownZIndex,...B0(a,N),top:`${t.top}px`,left:`${t.left}px`,maxHeight:"none",overflowY:"visible",...f!=null?{width:`${f}px`,minWidth:"unset",maxWidth:"unset"}:{}};return rl.createPortal(v.createElement("div",{className:"ei-datepicker-portal",style:w,onMouseDown:S=>S.preventDefault()},v.createElement(sC,{onSelect:l,colors:s,styles:o,initialMode:u==null?void 0:u.mode,initialStart:u==null?void 0:u.start,initialEnd:u==null?void 0:u.end,presets:m,className:p})),g.current)}function _C(t){const{fields:a,onSearch:l,onChange:s,onValidationChange:o,value:u,defaultValue:f,savedSearches:m,searchHistory:p,fetchSuggestions:g,colors:x,styles:y,placeholder:N,className:w,classNames:S,style:D,dropdown:R,features:L,inputRef:I,datePresets:q,onKeyDown:X,onFocus:W,onBlur:ae,onTab:z,validateValue:T,parseDate:ee,plainModeLength:fe,interceptPaste:be,defaultField:ye,trailingSpaceOnAccept:te=!0,collapseOnBlur:re=!1}=t,ge=typeof ye=="string"?{name:ye,showFieldSuggestions:!1}:ye?{showFieldSuggestions:!1,...ye}:void 0,U=ge==null?void 0:ge.name,B=(R==null?void 0:R.open)??(R==null?void 0:R.mode)??"always",ue=typeof B=="function",de=ue?null:B,we=(R==null?void 0:R.alignToInput)??!1,C=R==null?void 0:R.maxSuggestions,V=C||10,ne=R==null?void 0:R.suggestDebounceMs,me=parseInt((y==null?void 0:y.dropdownMaxHeight)||"300",10)||300,Ne=(L==null?void 0:L.savedSearches)??!!m,je=(L==null?void 0:L.historySearch)??!!p,ze=(R==null?void 0:R.showSavedSearchHint)??Ne,ut=(R==null?void 0:R.showHistoryHint)??je,Ge=(R==null?void 0:R.showOperators)!==!1,nt=(ue||de!=="input")&&(R==null?void 0:R.onNavigation)!==!1,Sn=(R==null?void 0:R.navigationDelay)??0,Xt=(R==null?void 0:R.loadingDelay)??0,ft=R==null?void 0:R.renderFieldHint,oe=R==null?void 0:R.renderHistoryItem,$e=R==null?void 0:R.renderSavedSearchItem,at=R==null?void 0:R.renderHeader,Ut=R==null?void 0:R.renderNoResults,pn=R==null?void 0:R.renderType,jt=(R==null?void 0:R.autoSelect)??!1,_t=(R==null?void 0:R.homeEndKeys)??!1,Qt=(L==null?void 0:L.multiline)!==!1,Hn=(L==null?void 0:L.smartSelectAll)??!1,$n=(L==null?void 0:L.expandSelection)??!1,tn=(L==null?void 0:L.wildcardWrap)??!1,da=(L==null?void 0:L.clauseNavigation)??!1,fa=L==null?void 0:L.formatQuery,Wn=!!fa,qn=typeof fa=="object"?fa:void 0,he=v.useMemo(()=>({savedSearches:Ne,historySearch:je}),[Ne,je]),Ce=Array.isArray(a)?a:[],[De,Pe]=v.useState(Ce);v.useEffect(()=>{if(Array.isArray(a)){Pe(a);return}let j=!1;return a().then(P=>{j||Pe(P)}),()=>{j=!0}},[a]);const qe=v.useMemo(()=>{const j=new Map;for(const P of De)if(j.set(P.name.toLowerCase(),P.type),P.aliases)for(const Ee of P.aliases)j.set(Ee.toLowerCase(),P.type);return j},[De]),Z=v.useRef(null),[Tt,Kt]=v.useState(null),Yn=v.useCallback(j=>{Z.current=j,Kt(j)},[]),gn=v.useRef(null),Ba=v.useRef(null),Me=v.useRef(u||f||""),vt=v.useRef(null),yt=v.useRef(!1),St=v.useRef(!1),Bt=v.useRef(new AC),Ct=v.useRef(null),nn=v.useRef(new Set),Zt=v.useRef(null),Ht=v.useRef(null),ht=v.useRef(null),Je=v.useRef(null),wn=v.useRef(!1),kn=v.useRef(null),A=v.useRef(null),M=v.useRef(null),$=v.useRef("input"),K=v.useRef(null),se=v.useRef(-1),Te=v.useRef(()=>{}),ve=v.useRef(new Ah(Ce,[],[],C||10,{showSavedSearchHint:ze,showHistoryHint:ut,hasSavedSearchProvider:typeof m=="function",hasHistoryProvider:typeof p=="function"}));ve.current.setDefaultField(ge);const Ae=v.useRef(new Dx(Ce)),Re=v.useRef(T);Re.current=T;const[_e,Ue]=v.useState([]),[Xe,ke]=v.useState(null),[Ze,Ie]=v.useState([]),[$t,We]=v.useState(-1),[ct,it]=v.useState(!1),[dt,Jt]=v.useState(!1),[Fn,En]=v.useState(null),[On,Mn]=v.useState([]),[Pn,ga]=v.useState(!1),[sl,ea]=v.useState(!Me.current),[pr,Qe]=v.useState(fe!=null&&Me.current.length>=fe),[Nt,Wt]=v.useState(0),[ta,_n]=v.useState(0),[Mr,Rt]=v.useState(""),[ja,Gn]=v.useState(null),[Vl,yi]=v.useState(null),Dt=v.useRef({tokens:_e,ast:Xe,suggestions:Ze,selectedSuggestionIndex:$t,showDropdown:ct,showDatePicker:dt,cursorOffset:Nt,selectionEnd:ta,autocompleteContext:Mr,validationErrors:On,cursorContext:ja});Dt.current={tokens:_e,ast:Xe,suggestions:Ze,selectedSuggestionIndex:$t,showDropdown:ct,showDatePicker:dt,cursorOffset:Nt,selectionEnd:ta,autocompleteContext:Mr,validationErrors:On,cursorContext:ja};const gr=v.useCallback((j,P)=>{if(we&&gn.current){const xe=gn.current.getBoundingClientRect();return{top:xe.bottom+window.scrollY+4,left:xe.left+window.scrollX}}const Ee=Lh();return Ee?zh(Ee,j,P):null},[we]),Zo=v.useCallback(()=>{if(!(!we||!gn.current))return gn.current.getBoundingClientRect().width},[we]),nr=v.useCallback((j,P,Ee="dropdown")=>{const xe=Ee==="datePicker"?j:Ux(j,me);if(we&&Ee!=="datePicker"){it(!0),En(gr(xe,P));return}const Fe=requestAnimationFrame(()=>{nn.current.delete(Fe),Ee==="datePicker"?Jt(!0):it(!0);const ce=Lh();En(ce?zh(ce,xe,P):null)});nn.current.add(Fe)},[we,gr,me]),il=80,od=60,xs=v.useCallback((j,P)=>{if(!Z.current)return;const Ee=ei(j,x,{cursorOffset:P,tokenClassName:S==null?void 0:S.token,fieldTypeMap:qe});Z.current.innerHTML=Ee,document.activeElement===Z.current&&al(Z.current,P)},[x]),va=v.useCallback((j,P)=>{const Ee=fe!=null&&j.length>=fe;if(Qe(Ee),Ee){if(Ue([]),ke(null),Mn([]),ea(j.length===0),Ie([]),Dt.current.tokens=[],it(!1),Jt(!1),Z.current){const Se=kl(Z.current);Z.current.querySelector("span")&&(Z.current.textContent=j,al(Z.current,Se)),Wt(Se),_n(Se)}s&&s(j,null),o&&o([]);return}const xe=new ii(j,he).tokenize(),Fe=new fs(xe),ce=Fe.parse(),pe=gc([...Fe.getErrors().map(Se=>({message:Se.message,start:Se.start,end:Se.end,type:"SYNTAX_ERROR"})),...Ae.current.validate(ce,Re.current,ee,U)]);if(Z.current){const Se=kl(Z.current);P&&xe.length>il?(Ht.current&&clearTimeout(Ht.current),Ht.current=setTimeout(()=>{Ht.current=null,Z.current&&xs(xe,kl(Z.current))},od)):(Ht.current&&(clearTimeout(Ht.current),Ht.current=null),xs(xe,Se)),Ue(xe),ke(ce),Mn(pe),ea(j.length===0),Wt(Se),_n(Se),Dt.current.tokens=xe,P&&Te.current(xe,Se)}else Ue(xe),ke(ce),Mn(pe),ea(j.length===0),Dt.current.tokens=xe;s&&s(j,ce),o&&o(pe)},[x,s,o,xs,fe]),Yl=v.useCallback((j,P)=>{if(!ft||P.type!=="FIELD_VALUE"||!P.fieldName)return j;const Ee=ve.current.resolveField(P.fieldName);if(!Ee)return j;const xe=ft(Ee,P.partial);return xe==null?j:j.some(Fe=>Fe.type==="hint")?j.map(Fe=>Fe.type==="hint"?{...Fe,customContent:xe}:Fe):[{text:"",label:"",type:"hint",customContent:xe,replaceStart:P.start??0,replaceEnd:P.end??0},...j]},[ft]),bs=v.useCallback(j=>{if(!Ut)return!1;const P=Ut({cursorContext:j,partial:j.partial});return P==null?!1:(Ie([{text:"",label:"",type:"noResults",customContent:P,replaceStart:0,replaceEnd:0}]),We(-1),Jt(!1),nr(32,300),!0)},[Ut]),ya=v.useCallback((j,P,Ee)=>{var Se,Ke,rt;const xe=ve.current.getSuggestions(j,P);Ge||(xe.suggestions=xe.suggestions.filter(Be=>Be.type!=="operator"));const Fe=xe.context.type;if(Gn(xe.context),ue){if(B({trigger:$.current,context:xe.context,suggestions:xe.suggestions,isOpen:Dt.current.showDropdown||Dt.current.showDatePicker,value:Me.current,selectionStart:P,selectionEnd:Ee??P})===!1){it(!1),Jt(!1),Ie([]);return}}else{if(de==="never"){it(!1),Jt(!1),Ie([]);return}if(de==="manual"){if(M.current&&M.current!==Fe){M.current=null,it(!1),Jt(!1),Ie([]);return}if(!M.current){it(!1),Jt(!1),Ie([]);return}}if(de==="input"&&$.current!=="input"&&$.current!=="ctrlSpace"){it(!1),Jt(!1),Ie([]);return}if(de==="always"&&j.some(Be=>(Be.type===O.AND||Be.type===O.OR||Be.type===O.NOT||Be.type===O.TILDE||Be.type===O.BOOST)&&P>=Be.start&&P<=Be.end)){it(!1),Jt(!1),Ie([]);return}}const ce=xe.context.fieldName?ve.current.resolveField(xe.context.fieldName):void 0,pe=!!(g&&xe.context.type==="FIELD_VALUE"&&xe.context.fieldName&&(ce==null?void 0:ce.type)!=="boolean"&&(ce==null?void 0:ce.suggestions)!==!1)||typeof m=="function"&&xe.context.type==="SAVED_SEARCH"||typeof p=="function"&&xe.context.type==="HISTORY_REF";if(xe.showDatePicker){wn.current=!1,(Se=Zt.current)==null||Se.abort(),vt.current&&clearTimeout(vt.current),Je.current&&(clearTimeout(Je.current),Je.current=null);const Be=kC(xe.context,ee),Nn=kn.current;kn.current=Be,yi(Be);const Lt=xe.context.token;Lt&&(Lt.type==="COLON"||Lt.type==="COMPARISON_OP")?A.current={start:Lt.end,end:Lt.end}:Lt?A.current={start:Lt.start,end:Lt.end}:A.current={start:P,end:P},Dt.current.showDatePicker&&OC(Nn,Be)&&Jt(!1),Ie([]),we||it(!1),Rt(Fe),nr(350,300,"datePicker");return}if(pe){const Be=xe.context.token,Nn=Be?Be.start:P,Lt=Be?Be.end:P,ra=()=>{Je.current=null,Ie([{text:"",label:"Searching...",type:"loading",replaceStart:Nn,replaceEnd:Lt}]),we||it(!1),Jt(!1),We(-1),nr(32,300)};Je.current&&clearTimeout(Je.current),Xt>0?Je.current=setTimeout(ra,Xt):ra(),Rt(Fe)}else{wn.current=!1,(Ke=Zt.current)==null||Ke.abort(),vt.current&&clearTimeout(vt.current),Je.current&&(clearTimeout(Je.current),Je.current=null);const Be=Yl(xe.suggestions,xe.context);Be.length>0?(Ie(Be),we||it(!1),Jt(!1),We(xe.context.partial||jt?0:-1),Rt(Fe),nr(Be.length*32,300)):(Rt(Fe),bs(xe.context)||(it(!1),Jt(!1),Ie([])))}if(pe){const Be=xe.context.partial,Nn=ne||200;wn.current=!0,vt.current&&clearTimeout(vt.current),(rt=Zt.current)==null||rt.abort();const Lt=new AbortController;Zt.current=Lt,vt.current=setTimeout(async()=>{const ra=xe.context.token,la=ra?ra.start:P,xa=ra?ra.end:P;try{let Rn;if(xe.context.type==="SAVED_SEARCH"&&typeof m=="function"){const cn=await m(Be);if(Lt.signal.aborted)return;Rn=cn.map(zt=>({text:zt.query,label:zt.label||zt.query,description:zt.description,type:"savedSearch",replaceStart:la,replaceEnd:xa,matchPartial:Be,sourceData:zt}))}else if(xe.context.type==="HISTORY_REF"&&typeof p=="function"){const cn=await p(Be);if(Lt.signal.aborted)return;Rn=cn.map(zt=>({text:Ah.wrapHistoryQuery(zt.query),label:zt.label||zt.query,description:zt.description,type:"history",replaceStart:la,replaceEnd:xa,matchPartial:Be,sourceData:zt}))}else{const cn=xe.context.fieldName,zt=ve.current.resolveField(cn),Xl=await g(zt?zt.name:cn,Be);if(Lt.signal.aborted)return;Rn=Xl.map(xr=>({text:xr.text,label:xr.label||xr.text,description:xr.description,type:xr.type,replaceStart:la,replaceEnd:xa,matchPartial:Be}))}if(Je.current&&(clearTimeout(Je.current),Je.current=null),Rn=Rn.slice(0,V),Rn.length>0){if(ge!=null&&ge.showFieldSuggestions){const cn=ve.current.getFieldSuggestions(Be,la,xa);Rn=[...Rn,...cn].slice(0,V)}Ie(Rn),We(Be||jt?0:-1),nr(Rn.length*32,300)}else{const cn=ve.current.getSuggestions(Dt.current.tokens,Dt.current.cursorOffset);if(!(Be&&bs(cn.context))){const zt=Yl(cn.suggestions.filter(Xl=>Xl.type==="hint"),cn.context);zt.length>0?(Ie(zt),We(cn.context.partial||jt?0:-1),nr(zt.length*32,300)):bs(cn.context)||(it(!1),Ie([]))}}}catch(Rn){Je.current&&(clearTimeout(Je.current),Je.current=null),Lt.signal.aborted||(Ie([{text:"",label:Rn instanceof Error?Rn.message:"Error loading suggestions",type:"error",replaceStart:la,replaceEnd:xa}]),We(-1),nr(32,300),wn.current=!1)}},Nn)}},[g,m,p,ne,Yl,gr,nr,we,B,ue,de,Ge,V,Xt,jt,bs]);Te.current=ya;const an=v.useCallback(()=>{var j;it(!1),Jt(!1),yi(null),kn.current=null,A.current=null,Ie([]),We(-1),wn.current=!1,(j=Zt.current)==null||j.abort(),vt.current&&(clearTimeout(vt.current),vt.current=null),ht.current&&(clearTimeout(ht.current),ht.current=null),M.current=null},[]),na=v.useCallback((j,P,Ee)=>{if(ht.current&&(clearTimeout(ht.current),ht.current=null),!nt){(Dt.current.showDropdown||Dt.current.showDatePicker)&&an();return}$.current="navigation",Sn>0?ht.current=setTimeout(()=>{ht.current=null,ya(j,P,Ee)},Sn):ya(j,P,Ee)},[nt,Sn,ya,an]),Ta=v.useCallback((j,P,Ee)=>{Me.current=j,Ct.current&&(clearTimeout(Ct.current),Ct.current=null),Bt.current.push({value:j,cursorPos:P});const xe=new ii(j,he).tokenize(),Fe=new fs(xe),ce=Fe.parse(),pe=gc([...Fe.getErrors().map(Se=>({message:Se.message,start:Se.start,end:Se.end,type:"SYNTAX_ERROR"})),...Ae.current.validate(ce,Re.current,ee,U)]);if(Z.current){const Se=ei(xe,x,{cursorOffset:P,tokenClassName:S==null?void 0:S.token,fieldTypeMap:qe});Z.current.innerHTML=Se,al(Z.current,P)}if(Ue(xe),ke(ce),Mn(pe),ea(j.length===0),Wt(P),_n(P),it(!1),Jt(!1),s&&s(j,ce),o&&o(pe),Ee){const Se=requestAnimationFrame(()=>{nn.current.delete(Se),Ee(xe,ce)});nn.current.add(Se)}},[x,s,o]),_r=v.useCallback((j,P="Enter",Ee,xe)=>{if(!j)return;const Fe=Dt.current,ce=Fe.autocompleteContext,pe=ce==="FIELD_VALUE"||ce==="SAVED_SEARCH"||ce==="HISTORY_REF";if(pe&&($.current="navigation"),j.type==="hint"&&(j.text==="#"||j.text==="!")){const cn=j.text,zt=j.replaceStart,Xl=Math.max(j.replaceEnd,Fe.selectionEnd),xr=Me.current.slice(0,zt),cd=Me.current.slice(Xl),tu=xr+cn+cd,nu=xr.length+cn.length;Ta(tu,nu,(dd,fd)=>{Ee?Ee(tu,fd):ya(dd,nu)});return}if(j.type==="hint")return;const Se=Fe.autocompleteContext==="FIELD_VALUE",Ke=Math.min(j.replaceStart,Fe.cursorOffset),rt=Math.max(j.replaceEnd,Fe.selectionEnd),Be=Me.current.slice(0,Ke),Nn=Me.current.slice(rt);let Lt="",ra=Nn;pe&&te&&(Nn.length===0?Lt=" ":/^[ \t\r\n]+$/.test(Nn)&&!Nn.startsWith("\\ ")&&(Lt=" ",ra=""));const la=Be+j.text+Lt+ra,xa=Be.length+j.text.length+Lt.length,Rn=P==="Enter"&&Se;Ta(la,xa,(cn,zt)=>{Ee?Ee(la,zt):Rn?l&&l(la,zt,xe):ya(cn,xa)})},[Ta,ya,l,te]);v.useEffect(()=>{Array.isArray(m)&&ve.current.updateSavedSearches(m),Array.isArray(p)&&ve.current.updateSearchHistory(p)},[m,p]),v.useEffect(()=>{ve.current=new Ah(De,[],[],C||10,{showSavedSearchHint:ze,showHistoryHint:ut,hasSavedSearchProvider:typeof m=="function",hasHistoryProvider:typeof p=="function"}),ve.current.setDefaultField(ge),Ae.current=new Dx(De),Array.isArray(m)&&ve.current.updateSavedSearches(m),Array.isArray(p)&&ve.current.updateSearchHistory(p),Me.current&&va(Me.current,!1)},[De,C,ze,ut]),v.useEffect(()=>{I&&I({getValue:()=>Me.current,setValue:j=>{Me.current=j,va(j,!1)},focus:()=>{var j;return(j=Z.current)==null?void 0:j.focus()},blur:()=>{var j;return(j=Z.current)==null?void 0:j.blur()},getAST:()=>Dt.current.ast,getValidationErrors:()=>Dt.current.validationErrors,setSelection:(j,P)=>{Z.current&&(Z.current.focus(),nl(Z.current,j,P),Wt(j),_n(P))}})},[I,va]),v.useEffect(()=>{const j=Me.current;Bt.current.push({value:j,cursorPos:j.length}),j&&va(j,!1)},[]),v.useEffect(()=>{u!==void 0&&u!==Me.current&&(Me.current=u,va(u,!1))},[u,va]),v.useEffect(()=>()=>{var j;vt.current&&clearTimeout(vt.current),Ht.current&&clearTimeout(Ht.current),ht.current&&clearTimeout(ht.current),Je.current&&clearTimeout(Je.current),nn.current.forEach(P=>cancelAnimationFrame(P)),nn.current.clear(),(j=Zt.current)==null||j.abort()},[]),v.useEffect(()=>{if(ue){const j=Dt.current;j.cursorContext&&B({trigger:"modeChange",context:j.cursorContext,suggestions:j.suggestions,isOpen:j.showDropdown||j.showDatePicker,value:Me.current,selectionStart:j.cursorOffset,selectionEnd:j.selectionEnd})===!1&&(it(!1),Jt(!1),Ie([]))}else de==="never"&&(it(!1),Jt(!1),Ie([]));M.current=null},[B]);const vr=v.useRef(!1);v.useLayoutEffect(()=>{if(vr.current){vr.current=!1;return}const j=Ba.current;if(!j||!Fn)return;const P=j.getBoundingClientRect(),Ee=window.innerWidth;if(P.right>Ee-8){const xe=P.right-Ee+8;vr.current=!0,En(Fe=>Fe&&{...Fe,left:Math.max(8,Fe.left-xe)})}},[Fn,ct,dt,Ze]),v.useEffect(()=>{const j=()=>{const P=Dt.current;if(!(!P.showDropdown&&!P.showDatePicker))if(P.showDropdown&&we&&gn.current){const Ee=gn.current.getBoundingClientRect();En({top:Ee.bottom+window.scrollY+4,left:Ee.left+window.scrollX})}else{const Ee=Lh();Ee&&En(zh(Ee,P.showDatePicker?350:Ux(P.suggestions.length*32,me),300))}};return window.addEventListener("resize",j),window.addEventListener("scroll",j,!0),()=>{window.removeEventListener("resize",j),window.removeEventListener("scroll",j,!0)}},[we,me]),v.useEffect(()=>{const j=Z.current;if(!j)return;const P=()=>{(Dt.current.showDropdown||Dt.current.showDatePicker)&&an()};return j.addEventListener("scroll",P),()=>j.removeEventListener("scroll",P)},[an]);const Lr=v.useRef(null),xi=v.useRef(x);v.useEffect(()=>{if(!Z.current)return;const j=Dt.current.tokens;if(j.length===0||Pn&&ta!==Nt)return;const P=Pn?Nt:-1,Ee=x!==xi.current;xi.current=x;const xe=H0(j,P),Fe=xe?`${xe.openStart},${xe.closeStart}`:null;if(Fe===Lr.current&&!Ee)return;Lr.current=Fe;const ce=Pn?kl(Z.current):-1,pe=ei(j,x,{cursorOffset:P,tokenClassName:S==null?void 0:S.token,fieldTypeMap:qe});Z.current.innerHTML=pe,Pn&&ce>=0&&al(Z.current,ce)},[Nt,ta,Pn,x]);const yr=re&&!Pn,bi=v.useRef(yr);v.useEffect(()=>{if(!Z.current)return;const j=bi.current;if(bi.current=yr,j!==yr)if(yr)Z.current.innerHTML=Z.current.innerHTML.replace(/<br\s*\/?>/gi," ");else{const P=Dt.current.tokens;if(P.length>0){const Ee=Pn?kl(Z.current):-1,xe=ei(P,x,{cursorOffset:Ee,tokenClassName:S==null?void 0:S.token,fieldTypeMap:qe});Z.current.innerHTML=xe,Pn&&Ee>=0&&al(Z.current,Ee)}}},[yr,x]);const Ha=v.useCallback(()=>{if(yt.current||!Z.current)return;K.current=null,se.current=-1,ht.current&&(clearTimeout(ht.current),ht.current=null);let j=_T(Z.current);if(j===Me.current)return;let P=kl(Z.current);const Ee=Nx(j);Ee!==j&&(j=Ee,P=Math.min(P,j.length)),Me.current=j;const xe=Bt.current,Fe=xe.current();if(Fe&&Math.abs(j.length-Fe.value.length)<=2&&Ct.current?xe.replaceCurrent({value:j,cursorPos:P}):xe.push({value:j,cursorPos:P}),Ct.current&&clearTimeout(Ct.current),Ct.current=setTimeout(()=>{Ct.current=null},300),$.current="input",!ue&&de==="input"){const ce=P>0?j[P-1]:"";if(!ce||ce.trim()===""){va(j,!1),an(),Z.current&&vc(Z.current);return}}va(j,!0),Z.current&&vc(Z.current)},[va,ue,de,an]),ar=v.useCallback(()=>{yt.current=!0},[]),Si=v.useCallback(()=>{yt.current=!1,Ha()},[Ha]),zr=v.useCallback(j=>{if(!j)return;Me.current=j.value;const P=new ii(j.value,he).tokenize(),Ee=new fs(P),xe=Ee.parse(),Fe=gc([...Ee.getErrors().map(pe=>({message:pe.message,start:pe.start,end:pe.end,type:"SYNTAX_ERROR"})),...Ae.current.validate(xe,Re.current,ee,U)]),ce=j.selStart!=null&&j.selStart!==j.cursorPos;if(Z.current){const pe=ei(P,x,{cursorOffset:j.cursorPos,tokenClassName:S==null?void 0:S.token,fieldTypeMap:qe});Z.current.innerHTML=pe,ce?nl(Z.current,j.selStart,j.cursorPos):al(Z.current,j.cursorPos)}Ue(P),ke(xe),Mn(Fe),ea(j.value.length===0),Wt(ce?j.selStart:j.cursorPos),_n(j.cursorPos),an(),s&&s(j.value,xe),o&&o(Fe)},[x,s,o,an]),$a=v.useCallback(()=>{const j=Ba.current;if(!j)return 10;const P=j.clientHeight,Ee=j.querySelectorAll(".ei-dropdown-item")[0];if(!Ee)return 10;const xe=Ee.offsetHeight;return xe<=0?10:Math.max(1,Math.floor(P/xe))},[]),wi=v.useCallback(j=>{var xe,Fe;if(X&&X(j),j.defaultPrevented)return;const P=Dt.current,Ee=j.nativeEvent.code;if(Wn&&Ee==="KeyF"&&j.altKey&&j.shiftKey&&!j.ctrlKey&&!j.metaKey){j.preventDefault();const ce=wC(Me.current,qn);ce!==Me.current&&Ta(ce,ce.length);return}if(Z.current&&Z.current.childNodes.length>40){const ce=window.getSelection();if(ce!=null&&!ce.isCollapsed){const pe=Rr(Z.current);if(pe.end-pe.start>20){const Se=j.key==="Backspace"||j.key==="Delete"||j.key==="x"&&(j.ctrlKey||j.metaKey),Ke=!j.ctrlKey&&!j.metaKey&&!j.altKey&&j.key.length===1;(Se||Ke)&&(Z.current.textContent=Me.current,nl(Z.current,pe.start,pe.end))}}}{let ce=null,pe=null;if(Rx[j.key])ce=j.key,pe=Rx[j.key];else if(tn&&j.key==="*"&&Z.current){const Se=Rr(Z.current);if(Se.start!==Se.end){const[Ke,rt]=jx(P.tokens,Se.start,Se.end);if(Ke>=0&&Ke===rt){const Be=P.tokens[Ke];(Be.type===O.VALUE||Be.type===O.WILDCARD)&&(ce="*",pe="*")}}}if(ce&&pe&&Z.current){const Se=Rr(Z.current);if(Se.start!==Se.end){j.preventDefault();const{newValue:Ke,newSelStart:rt,newSelEnd:Be}=MT(Me.current,Se.start,Se.end,ce,pe),Nn=Bt.current,Lt=Nn.current();Lt&&Lt.value===Me.current&&(Lt.selStart=Se.start,Lt.cursorPos=Se.end),Me.current=Ke,Ct.current&&(clearTimeout(Ct.current),Ct.current=null),Nn.push({value:Ke,cursorPos:Be,selStart:rt});const ra=new ii(Ke,he).tokenize(),la=new fs(ra),xa=la.parse(),Rn=gc([...la.getErrors().map(zt=>({message:zt.message,start:zt.start,end:zt.end,type:"SYNTAX_ERROR"})),...Ae.current.validate(xa,Re.current,ee,U)]),cn=ei(ra,x,{cursorOffset:Be,tokenClassName:S==null?void 0:S.token,fieldTypeMap:qe});Z.current.innerHTML=cn,nl(Z.current,rt,Be),Ue(ra),ke(xa),Mn(Rn),ea(!1),Wt(rt),_n(Be),an(),s&&s(Ke,xa),o&&o(Rn);return}}}if(j.key==="z"&&(j.ctrlKey||j.metaKey)&&!j.shiftKey){j.preventDefault(),zr(Bt.current.undo());return}if(j.key==="y"&&(j.ctrlKey||j.metaKey)||j.key==="z"&&(j.ctrlKey||j.metaKey)&&j.shiftKey){j.preventDefault(),zr(Bt.current.redo());return}if(j.key==="a"&&(j.ctrlKey||j.metaKey)&&Hn&&Z.current){const ce=Rr(Z.current),pe=gC(P.tokens,ce.start,ce.end);if(pe){j.preventDefault(),nl(Z.current,pe.start,pe.end),Wt(pe.start),_n(pe.end);return}}if($n&&j.altKey&&j.shiftKey&&(Ee==="ArrowRight"||Ee==="ArrowLeft")&&Z.current){const ce=Ee==="ArrowRight";let pe=K.current;if(!pe){const Ke=Rr(Z.current),rt=yC(P.ast,P.tokens,Ke.start);if(rt.length===0)return;pe={ranges:rt,level:-1},K.current=pe}const Se=ce?Math.min(pe.level+1,pe.ranges.length-1):Math.max(pe.level-1,-1);if(Se===pe.level)return;if(pe.level=Se,Se<0){const Ke=Rr(Z.current);al(Z.current,Ke.start),K.current=null}else{j.preventDefault();const Ke=pe.ranges[Se];nl(Z.current,Ke.start,Ke.end),Wt(Ke.start),_n(Ke.end)}return}if(K.current=null,da&&j.ctrlKey&&j.altKey&&(Ee==="ArrowRight"||Ee==="ArrowLeft")&&Z.current){j.preventDefault();const ce=Ee==="ArrowRight"?"forward":"backward",pe=CC(P.ast),Se=Rr(Z.current),Ke=ce==="forward"?Se.end:Se.start,rt=DC(pe,se.current,Ke,ce);rt&&(se.current=rt.index,nl(Z.current,rt.stop.start,rt.stop.end),Wt(rt.stop.start),_n(rt.stop.end));return}if(se.current=-1,j.key===" "&&(j.ctrlKey||j.metaKey)){j.preventDefault(),$.current="ctrlSpace",!ue&&de==="manual"&&(M.current=ve.current.getSuggestions(P.tokens,P.cursorOffset).context.type),ya(P.tokens,P.cursorOffset);return}if(j.key==="Enter"&&(j.ctrlKey||j.metaKey)){j.preventDefault(),an(),l&&l(Me.current,P.ast,j);return}if(j.key==="Enter"&&j.shiftKey&&Qt){j.preventDefault(),mC();const ce=Z.current?kl(Z.current):Me.current.length+1,pe=Me.current,Se=pe.slice(0,ce-1)+`
288
- `+pe.slice(ce-1);Me.current=Se,K.current=null,ht.current&&(clearTimeout(ht.current),ht.current=null),$.current="input",Bt.current.push({value:Se,cursorPos:ce}),va(Se,!0),Z.current&&vc(Z.current);return}if((j.key==="Backspace"||j.key==="Delete")&&Z.current&&!Z.current.textContent){const ce=Me.current;if(!ce)return;const{start:pe,end:Se}=Rr(Z.current);let Ke,rt;if(pe!==Se)Ke=ce.slice(0,pe)+ce.slice(Se),rt=pe;else if(j.key==="Backspace"&&pe>0)Ke=ce.slice(0,pe-1)+ce.slice(pe),rt=pe-1;else if(j.key==="Delete"&&pe<ce.length)Ke=ce.slice(0,pe)+ce.slice(pe+1),rt=pe;else return;j.preventDefault(),Me.current=Ke,K.current=null,ht.current&&(clearTimeout(ht.current),ht.current=null),$.current="input",Bt.current.push({value:Ke,cursorPos:rt}),al(Z.current,rt),va(Ke,!0),Z.current&&vc(Z.current);return}if(St.current=!1,P.showDropdown&&P.suggestions.length>0)switch(j.key){case"ArrowDown":j.preventDefault(),St.current=!0,We(ce=>ce>=P.suggestions.length-1?0:ce+1);return;case"ArrowUp":j.preventDefault(),St.current=!0,We(ce=>ce<=0?P.suggestions.length-1:ce-1);return;case"PageDown":{j.preventDefault(),St.current=!0;const ce=$a();We(pe=>Math.min(pe+ce,P.suggestions.length-1));return}case"PageUp":{j.preventDefault(),St.current=!0;const ce=$a();We(pe=>Math.max(pe-ce,0));return}case"Home":if(_t&&P.selectedSuggestionIndex>=0){j.preventDefault(),St.current=!0,We(0);return}break;case"End":if(_t&&P.selectedSuggestionIndex>=0){j.preventDefault(),St.current=!0,We(P.suggestions.length-1);return}break;case"Enter":if(P.selectedSuggestionIndex>=0){const ce=P.suggestions[P.selectedSuggestionIndex];if(ce.type==="loading"||ce.type==="error"){j.preventDefault(),an(),l&&l(Me.current,P.ast,j);return}if(ce.type==="hint"&&ce.text!=="#"&&ce.text!=="!"){j.preventDefault(),an();const pe=Me.current,Se=P.cursorOffset;if(Se<=pe.length&&pe[Se]!==" "){const Ke=pe.slice(0,Se),rt=pe.slice(Se),Be=Ke+" "+rt;Ta(Be,Se+1,()=>{l&&l(Be,P.ast,j)})}else l&&l(pe,P.ast,j);return}j.preventDefault(),_r(ce,"Enter",void 0,j);return}j.preventDefault(),an(),l&&l(Me.current,P.ast,j);return;case"Tab":if(z){j.preventDefault();const ce=P.selectedSuggestionIndex>=0?P.suggestions[P.selectedSuggestionIndex]:null,pe=ce&&ce.type!=="loading"&&ce.type!=="error"&&!(ce.type==="hint"&&ce.text!=="#"&&ce.text!=="!")?ce:null,Se=z({suggestion:pe,cursorContext:P.cursorContext||{type:"EMPTY",partial:""},query:Me.current});Se.accept&&pe?_r(pe,"Tab",(Ke,rt)=>{var Be;Se.submit&&l&&l(Ke,rt,j),Se.blur&&((Be=Z.current)==null||Be.blur())},j):(an(),Se.submit&&l&&l(Me.current,P.ast,j),Se.blur&&((xe=Z.current)==null||xe.blur()));return}if(P.selectedSuggestionIndex>=0){const ce=P.suggestions[P.selectedSuggestionIndex];if(ce.type==="hint"&&ce.text!=="#"&&ce.text!=="!"){j.preventDefault(),an();const pe=Me.current,Se=P.cursorOffset;if(Se<=pe.length&&pe[Se]!==" "){const Ke=pe.slice(0,Se),rt=pe.slice(Se),Be=Ke+" "+rt,Nn=Se+1;Ta(Be,Nn,Lt=>{ya(Lt,Nn)})}return}j.preventDefault(),_r(ce,"Tab",void 0,j);return}break;case"Escape":j.preventDefault(),an();return}if(j.key==="Tab"&&z){j.preventDefault();const ce=z({suggestion:null,cursorContext:P.cursorContext||{type:"EMPTY",partial:""},query:Me.current});ce.submit&&l&&l(Me.current,P.ast,j),ce.blur&&((Fe=Z.current)==null||Fe.blur());return}if(P.showDatePicker&&j.key==="Escape"){j.preventDefault(),an();return}if(j.key==="Enter"&&!P.showDropdown&&!P.showDatePicker){j.preventDefault(),l&&l(Me.current,P.ast,j);return}},[l,an,_r,Ta,zr,Qt,ue,de,ya,X,z,Hn,$n,da,_t,$a,Wn]),Ss=v.useCallback(j=>{if(St.current){St.current=!1;return}if(["ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"].includes(j.key)){if(!Z.current)return;const P=Rr(Z.current);Wt(P.start),_n(P.end),na(Dt.current.tokens,P.start,P.end)}},[na]),Jo=v.useCallback(()=>{ga(!0),W==null||W();const j=requestAnimationFrame(()=>{if(nn.current.delete(j),Z.current){const P=Dt.current.tokens,Ee=P.length>0?kl(Z.current):0;Wt(Ee),_n(Ee),na(P,Ee)}});nn.current.add(j)},[Ha,na,W]),ws=v.useCallback(()=>{var j;ga(!1),it(!1),Jt(!1),Ie([]),wn.current=!1,(j=Zt.current)==null||j.abort(),vt.current&&(clearTimeout(vt.current),vt.current=null),Je.current&&(clearTimeout(Je.current),Je.current=null),Wt(-1),ae==null||ae()},[ae]),Ur=v.useRef(!1),Wo=v.useCallback(j=>{if(!Z.current||j.detail!==2&&j.detail!==3)return;if(j.detail===3){if(!Dt.current.ast)return;const Se=document.caretRangeFromPoint(j.clientX,j.clientY);if(!Se)return;const Ke=Mo(Z.current,Se.startContainer,Se.startOffset),rt=DT(Dt.current.ast,Me.current,Ke);if(!rt||rt.start>=rt.end)return;j.preventDefault(),Ur.current=!0,nl(Z.current,rt.start,rt.end);return}j.preventDefault(),Ur.current=!0;const P=document.caretRangeFromPoint(j.clientX,j.clientY);if(!P)return;const Ee=Mo(Z.current,P.startContainer,P.startOffset),xe=Me.current,Fe=Se=>!/[\s:()[\]{}"<>!,;|&=~^+\-*/\\]/.test(Se);let ce=Ee;for(;ce>0&&Fe(xe[ce-1]);)ce--;let pe=Ee;for(;pe<xe.length&&Fe(xe[pe]);)pe++;ce<pe&&nl(Z.current,ce,pe)},[]),aa=v.useCallback(j=>{Ur.current&&(j.preventDefault(),Ur.current=!1)},[]),Br=v.useCallback(()=>{if(!Z.current)return;const j=Rr(Z.current);if(Wt(j.start),_n(j.end),j.start!==j.end){const[P,Ee]=jx(Dt.current.tokens,j.start,j.end);if(P!==Ee){an();return}}na(Dt.current.tokens,j.start,j.end)},[na,an]),Hr=v.useCallback(j=>{Ct.current&&(clearTimeout(Ct.current),Ct.current=null),hC(j),Ha()},[Ha]),Fl=v.useCallback(j=>{j.preventDefault();const P=Nx(j.clipboardData.getData("text/plain"));if(be){const Ee=be(P,j);Ee!=null&&typeof(Ee==null?void 0:Ee.then)=="function"?Ee.then(xe=>{xe!=null&&Hr(xe)}).catch(()=>{}):Ee!=null&&Hr(Ee)}else Hr(P)},[be,Hr]),ud=v.useCallback(j=>{$.current="navigation";const P=Dt.current,Ee=A.current,xe=Ee?Ee.start:P.cursorOffset,Fe=Ee?Ee.end:P.cursorOffset,ce=Me.current.slice(0,xe),pe=Me.current.slice(Fe);let Se="",Ke=pe;te&&j.length>0&&(pe.length===0?Se=" ":/^[ \t\r\n]+$/.test(pe)&&!pe.startsWith("\\ ")&&(Se=" ",Ke=""));const rt=ce+j+Se+Ke,Be=ce.length+j.length+Se.length;Ta(rt,Be,Nn=>{Z.current&&Z.current.focus(),ya(Nn,Be)})},[Ta,ya,te]),ol=Qo(x),Pl=Ko(y),Gl=IT(ol,D),$r={...VT(ol,Pl),...Pn?YT(Pl):{}};yr&&($r.whiteSpace="nowrap",$r.overflow="hidden",$r.textOverflow="ellipsis");const eu=FT(ol,Pl);return v.createElement("div",{ref:gn,style:Gl,className:za("ei-container",w,S==null?void 0:S.container)},v.createElement("div",{ref:Yn,contentEditable:!0,suppressContentEditableWarning:!0,className:za("ei-editor",S==null?void 0:S.editor),style:$r,onInput:Ha,onKeyDown:wi,onKeyUp:Ss,onMouseDown:Wo,onMouseUp:aa,onFocus:Jo,onBlur:ws,onClick:Br,onPaste:Fl,onCompositionStart:ar,onCompositionEnd:Si,spellCheck:!1}),sl&&!Pn?v.createElement("div",{className:za("ei-placeholder",S==null?void 0:S.placeholder),style:eu},N):null,v.createElement(fC,{errors:On,editorRef:Tt,cursorOffset:Nt,colors:x,styles:y,containerRef:gn.current,classNames:S?{squiggly:S.squiggly,tooltip:S.tooltip}:void 0}),v.createElement(rC,{suggestions:Ze,selectedIndex:$t,onSelect:j=>_r(j,"Tab"),position:Fn,colors:x,styles:y,visible:ct,fixedWidth:Zo(),renderHistoryItem:oe,renderSavedSearchItem:$e,renderDropdownHeader:at,cursorContext:ja,listRefCallback:j=>{Ba.current=j},renderType:pn,classNames:S?{dropdown:S.dropdown,dropdownHeader:S.dropdownHeader,dropdownItem:S.dropdownItem}:void 0}),dt&&Fn?v.createElement(MC,{position:Fn,colors:ol,onSelect:ud,colorConfig:x,styleConfig:y,datePickerInit:Vl,fixedWidth:void 0,datePresets:q,datePickerClassName:S==null?void 0:S.datePicker}):null)}const LC=["planned","in-progress","done","blocked","canceled","rejected","deferred","waiting"];function Hx(t){var o;const a=window.getSelection();if(!a||a.rangeCount===0)return((o=t.textContent)==null?void 0:o.length)??0;const l=a.getRangeAt(0),s=l.cloneRange();return s.selectNodeContents(t),s.setEnd(l.endContainer,l.endOffset),s.toString().length}function zC(t){return a=>{if(!(a.ctrlKey&&!a.metaKey&&!a.altKey))return;const l=a.key.toLowerCase(),s=a.currentTarget,o=s.isContentEditable?s:s.querySelector("[contenteditable='true'], [contenteditable]")??s,u=t.current;if(l==="h"&&u){a.preventDefault();const m=u.getValue();let p=Hx(o);(p<0||p>m.length)&&(p=m.length),p>0&&(u.setValue(m.slice(0,p-1)+m.slice(p)),u.setSelection(p-1,p-1));return}if(l==="u"&&u){a.preventDefault();const m=u.getValue();let p=Hx(o);if((p<0||p>m.length)&&(p=m.length),p===0)return;let g=p;for(;g>0&&/\s/.test(m[g-1]??"");)g--;if(g===p)for(;g>0&&!/\s/.test(m[g-1]??"");)g--;g<p&&(u.setValue(m.slice(0,g)+m.slice(p)),u.setSelection(g,g));return}const f=l==="j"?"ArrowDown":l==="k"?"ArrowUp":null;f&&(a.preventDefault(),o.dispatchEvent(new KeyboardEvent("keydown",{key:f,bubbles:!0,cancelable:!0})))}}function Uh(t){return String(t>0?t:0).padStart(3,"0")}function UC({features:t,phases:a,query:l,onQuery:s}){const o=v.useRef(null),u=zC(o),f=v.useMemo(()=>[{name:"feature",label:"Feature",type:"number",description:"Feature number, e.g. 1 (F001)"},{name:"phase",label:"Phase",type:"number",description:"Phase number, e.g. 2 (P002)"},{name:"task",label:"Task",type:"number",description:"Task number, e.g. 10 (T010). Comma-list supported."},{name:"id",label:"Short ID",type:"string",description:"Global 5-char short id, e.g. UUXD1"},{name:"status",label:"Status",type:"string",description:"Task status"},{name:"feature-status",label:"Feature status",type:"string",description:"Status of the feature"},{name:"phase-status",label:"Phase status",type:"string",description:"Status of the phase"},{name:"title",label:"Title",type:"string",description:"Substring match on title"}],[]),m=v.useMemo(()=>{const y=[...new Set(t.map(R=>R.number))].sort((R,L)=>R-L),N=[...new Set(a.map(R=>R.number))].sort((R,L)=>R-L),w=[...new Set(a.flatMap(R=>R.tasks.map(L=>L.number)))].sort((R,L)=>R-L),S=[...new Set([...t.map(R=>R.shortId),...a.flatMap(R=>[R.shortId,...R.tasks.map(L=>L.shortId)])].filter(Boolean))],D=[...new Set(a.flatMap(R=>R.tasks.map(L=>L.title)))];return{featureNums:y,phaseNums:N,taskNums:w,shortIds:S,titles:D}},[t,a]),p=v.useCallback(async(y,N)=>{const w=N.toLowerCase();return y==="feature"?m.featureNums.filter(S=>String(S).startsWith(N)).slice(0,20).map(S=>({text:String(S),label:`F${Uh(S)}`})):y==="phase"?m.phaseNums.filter(S=>String(S).startsWith(N)).slice(0,20).map(S=>({text:String(S),label:`P${Uh(S)}`})):y==="task"?m.taskNums.filter(S=>String(S).startsWith(N)).slice(0,20).map(S=>({text:String(S),label:`T${Uh(S)}`})):y==="id"?m.shortIds.filter(S=>S.toLowerCase().startsWith(w)).slice(0,20).map(S=>({text:S,label:S})):y==="status"||y==="feature-status"||y==="phase-status"?LC.filter(S=>S.startsWith(w)).map(S=>({text:S,label:S})):y==="title"?m.titles.filter(S=>S.toLowerCase().includes(w)).slice(0,20).map(S=>({text:S,label:S.length>44?S.slice(0,44)+"…":S})):[]},[m]),g=v.useCallback(y=>s(y),[s]),x=v.useCallback(y=>{o.current=y},[]);return c.jsx("div",{className:"search-bar",children:c.jsx(_C,{fields:f,value:l,onChange:g,onSearch:g,fetchSuggestions:p,onKeyDown:u,inputRef:x,placeholder:"Search Work Tree… e.g. feature:1 id:UUXD1 title:auth status:in-progress"})})}function BC(t,a){if(Object.keys(a).length===0)return t;const l=u=>{const f=a[u];return f?new Map(f.map((m,p)=>[m,p])):null},s=l("__features__");return(s?[...t].sort((u,f)=>(s.get(u.feature.id)??1/0)-(s.get(f.feature.id)??1/0)):t).map(u=>{const f=l(`phase-scope:${u.feature.id}`),m=f?[...u.allPhases].sort((p,g)=>(f.get(p.phase.id)??1/0)-(f.get(g.phase.id)??1/0)):u.allPhases;return{...u,allPhases:m.map(p=>{const g=l(`task-scope:${p.phase.id}`),x=g?[...p.allTasks].sort((y,N)=>(g.get(y.id)??1/0)-(g.get(N.id)??1/0)):p.allTasks;return{...p,allTasks:x}})}})}function ti({active:t=!1,disabled:a=!1,onClick:l,children:s}){return c.jsx("button",{type:"button",disabled:a,onClick:l,className:`inline-flex h-8 min-h-8 w-full items-center justify-center rounded-[10px] border px-2.5 py-1 text-xs font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)] ${t?"border-transparent bg-[var(--accent)] text-white":"border-[var(--border)] bg-[var(--surface-card)] text-[var(--text-muted)] hover:bg-[var(--accent-soft)] hover:text-[var(--text)]"} ${a?"cursor-not-allowed opacity-60":""}`,children:s})}function HC({features:t,phases:a,activeTasks:l,projectStorageScope:s}){const o=NT({features:t,phases:a,projectStorageScope:s}),[u,f]=v.useState({});v.useEffect(()=>{f({})},[o.displayedWorkTree]);const m=v.useMemo(()=>BC(o.displayedWorkTree,u),[o.displayedWorkTree,u]),[p,g]=v.useState(!1),[x,y]=v.useState(null),[N,w]=v.useState(null),S=te=>w(String(te.active.id)),[D,R]=v.useState(0);v.useEffect(()=>{const te=document.querySelector("header");if(!te)return;const re=()=>R(te.offsetHeight);re();const ge=new ResizeObserver(re);return ge.observe(te),window.addEventListener("resize",re),()=>{ge.disconnect(),window.removeEventListener("resize",re)}},[]),v.useEffect(()=>{const te=window.setTimeout(()=>{const re=document.querySelector(".ap-search-sticky"),ge=document.querySelector("header");if(!re||!ge)return;const U=re.getBoundingClientRect();if(U.top<0){const B=U.top+window.scrollY-ge.offsetHeight;window.scrollTo({top:Math.max(0,B),behavior:"smooth"})}},60);return()=>window.clearTimeout(te)},[o.searchQuery,o.hideDone,o.hidePlanned,o.onlyActiveBranches]);const L=$2(H2(Cm,{activationConstraint:{distance:5}})),I=async te=>{const{active:re,over:ge}=te;if(w(null),!ge||re.id===ge.id)return;const U=String(re.id),B=String(ge.id),ue=m.map(de=>de.feature.id);if(ue.includes(U)&&ue.includes(B)){const de=To(ue,ue.indexOf(U),ue.indexOf(B)),we=de.indexOf(U),C=we>0?de[we-1]??null:null,V=we<de.length-1?de[we+1]??null:null;f(ne=>({...ne,__features__:de})),await bh("feature",U,C,V).catch(()=>{});return}for(const de of m){const we=de.allPhases.map(C=>C.phase.id);if(we.includes(U)&&we.includes(B)){const C=To(we,we.indexOf(U),we.indexOf(B)),V=C.indexOf(U),ne=V>0?C[V-1]??null:null,me=V<C.length-1?C[V+1]??null:null;f(Ne=>({...Ne,[`phase-scope:${de.feature.id}`]:C})),await bh("phase",U,ne,me).catch(()=>{});return}}for(const de of m)for(const we of de.allPhases){const C=we.allTasks.map(V=>V.id);if(C.includes(U)&&C.includes(B)){const V=To(C,C.indexOf(U),C.indexOf(B)),ne=V.indexOf(U),me=ne>0?V[ne-1]??null:null,Ne=ne<V.length-1?V[ne+1]??null:null;f(je=>({...je,[`task-scope:${we.phase.id}`]:V})),await bh("task",U,me,Ne).catch(()=>{});return}}},q=te=>o.expandedPhaseIds.includes(te),X=te=>o.recentPhaseIds.includes(te),W=te=>o.recentTaskIds.includes(te),[ae,z]=$o(),[T,ee]=v.useState(null),fe=ae.get("locate"),be=fe?parseInt(fe.replace(/^T/i,""),10):null;v.useEffect(()=>{if(be==null||Number.isNaN(be))return;const te=a.flatMap(B=>B.tasks.map(ue=>({t:ue,p:B}))).find(({t:B})=>B.number===be);if(!te){z(B=>(B.delete("locate"),B),{replace:!0});return}const{t:re,p:ge}=te;if(o.onlyActiveBranches&&o.setOnlyActiveBranches(!1),o.hideDone&&o.setHideDone(!1),o.searchQuery&&o.setSearchQuery(""),o.setTreeOpenMode("smart"),ge.featureId){const B=ge.featureId;o.expandedFeatureIds.includes(B)||o.setExpandedFeatureIds(ue=>ue.includes(B)?ue:[...ue,B])}o.expandedPhaseIds.includes(ge.id)||o.setExpandedPhaseIds(B=>B.includes(ge.id)?B:[...B,ge.id]);const U=document.getElementById(`task-row-${be}`);if(U){const B=document.querySelector("header"),ue=document.querySelector(".ap-search-sticky"),de=((B==null?void 0:B.offsetHeight)??0)+((ue==null?void 0:ue.offsetHeight)??0)+12,we=U.getBoundingClientRect().top+window.scrollY-de;window.scrollTo({top:Math.max(0,we),behavior:"smooth"}),ee(re.id);const C=window.setTimeout(()=>ee(null),2500);return z(V=>(V.delete("locate"),V),{replace:!0}),()=>window.clearTimeout(C)}},[be,a,o.expandedFeatureIds,o.expandedPhaseIds,o.onlyActiveBranches,o.hideDone,o.searchQuery,o.treeOpenMode]);const ye=()=>{if(!N)return null;for(const te of m){if(te.feature.id===N)return c.jsxs("div",{className:"ap-drag-overlay surface-card min-w-0 max-w-md px-3 py-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:te.feature.number}),c.jsx(ur,{status:te.feature.status})]}),c.jsx("div",{className:"mt-1 break-words font-mono text-sm font-semibold [overflow-wrap:anywhere]",children:te.feature.name})]});for(const re of te.allPhases){if(re.phase.id===N)return c.jsxs("div",{className:"ap-drag-overlay surface-card min-w-0 max-w-md px-3 py-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:te.feature.number,phaseNum:re.phase.number}),c.jsx(ur,{status:re.phase.status})]}),c.jsx("div",{className:"mt-1 break-words font-mono text-sm font-semibold [overflow-wrap:anywhere]",children:re.phase.title})]});for(const ge of re.allTasks)if(ge.id===N)return c.jsxs("div",{className:"ap-drag-overlay surface-card min-w-0 max-w-md px-3 py-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:te.feature.number,phaseNum:re.phase.number,taskNum:ge.number}),c.jsx(ur,{status:ge.status})]}),c.jsx("div",{className:"mt-1 break-words font-mono text-sm font-semibold [overflow-wrap:anywhere]",children:ge.title})]})}}return null};return c.jsxs(Pt,{className:"grid gap-4",children:[c.jsx("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-bold text-[var(--text)]",children:"Work Tree"}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Collapsible feature → phase → task tree. Click a feature or phase row to collapse/expand."})]})}),c.jsxs("div",{className:"ap-search-sticky z-20 grid gap-3",style:{top:D},children:[c.jsx(UC,{features:t,phases:a,query:o.searchQuery,onQuery:o.setSearchQuery}),c.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[c.jsx(Om,{sort:o.sort,onChange:o.setSort}),o.searchActive?c.jsxs("p",{className:"text-xs text-[var(--text-muted)]",children:[o.matchedTaskIds.size," match",o.matchedTaskIds.size===1?"":"es"," — clear the box to reset."]}):null]}),c.jsxs("div",{className:"grid grid-cols-2 gap-2 rounded-[14px] border border-[var(--border)] bg-[var(--surface-card)] px-3 py-2 sm:grid-cols-3 sm:rounded-[18px] sm:px-4 sm:py-3 lg:grid-cols-6",children:[c.jsx(ti,{active:o.isAllExpanded,onClick:()=>o.isAllExpanded?o.collapseAll():o.expandAll(),children:o.isAllExpanded?"Collapse all":"Expand all"}),c.jsx(ti,{active:o.hideDone,onClick:()=>o.setHideDone(te=>!te),children:"Hide done"}),c.jsx(ti,{active:o.hidePlanned,onClick:()=>o.setHidePlanned(te=>!te),children:"Hide planned"}),c.jsx(ti,{active:o.onlyActiveBranches,onClick:()=>o.setOnlyActiveBranches(te=>!te),children:"Only active"}),c.jsx(ti,{onClick:o.resetFilters,children:"Reset"}),c.jsx(ti,{disabled:p,onClick:async()=>{g(!0),y(null);try{const te=await TR(),re=te.migrated,ge=te.integrity.duplicatePhaseIds.length,U=te.integrity.danglingPhaseIds.length;y(`Repair done: renamed ${re.renamed}, repaired ${re.repaired} refs, inferred ${re.inferred}, archived ${te.handoffs.archived} stale handoff(s). Integrity: ${ge} duplicate, ${U} dangling.`)}catch(te){y(`Repair failed: ${te instanceof Error?te.message:String(te)}`)}finally{g(!1)}},children:p?"Repairing…":"Repair"}),x?c.jsx("span",{className:"hidden text-xs text-[var(--text-muted)] sm:inline sm:truncate",children:x}):null]})]}),c.jsx("div",{className:"grid gap-3",children:m.length>0?c.jsxs($j,{sensors:L,collisionDetection:P2,onDragStart:S,onDragEnd:I,children:[c.jsx(km,{items:m.map(te=>te.feature.id),strategy:Am,children:m.map(te=>c.jsx(Mm,{id:te.feature.id,children:c.jsx(jT,{entry:te,expanded:o.expandedFeatureIds.includes(te.feature.id),recentlyChanged:o.recentFeatureIds.includes(te.feature.id),onToggle:()=>o.toggleExpandedFeature(te.feature.id),isPhaseExpanded:q,onTogglePhase:o.toggleExpandedPhase,isPhaseRecentlyChanged:X,isTaskRecentlyChanged:W,highlightedTaskIds:(()=>{const re=o.searchActive?o.matchedTaskIds:void 0;if(!T)return re;const ge=new Set(re??[]);return ge.add(T),ge})()})},te.feature.id))}),c.jsx(lT,{dropAnimation:{duration:150,easing:"ease"},children:ye()})]}):l.length>0?l.map(te=>{const re=te.featureId?`/features/${te.featureId}/phases/${te.phaseId}/tasks/${te.id}`:"/features";return c.jsxs(Ye,{to:re,className:"surface-card grid gap-1 px-4 py-3 transition hover:border-[var(--accent)] hover:bg-[var(--accent-soft)]",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2 truncate text-sm font-semibold text-[var(--text)]",children:[te.status==="in-progress"?c.jsx("span",{"aria-hidden":"true",className:"ap-progress-dot"}):null,c.jsxs("span",{className:"truncate",children:["T",S2(te.number)," — ",te.title]})]}),c.jsx(ur,{status:te.status})]}),c.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[var(--text-muted)]",children:te.phaseId})]},te.id)}):c.jsx("p",{className:"py-4 text-center text-sm text-[var(--text-muted)]",children:"No work items match the current filters."})})]})}function $C(){const{features:t,phases:a,activeTasks:l}=ll(),{project:s}=gs("root"),o=kr(),u=()=>o("/project/edit");An("edit",u);const f=s.projectRoot||s.planRoot||s.name||"default";return c.jsxs("div",{className:"grid grid-cols-1 gap-8",children:[c.jsxs(Pt,{className:"grid grid-cols-1 gap-4",children:[c.jsxs("div",{className:"flex items-center justify-between gap-4",children:[c.jsx("h2",{className:"min-w-0 text-lg font-bold text-[var(--text)]",children:"Project Goal"}),c.jsxs(gt,{type:"button",shortcut:"edit",onClick:u,className:"shrink-0",children:[c.jsx(ms,{className:"h-4 w-4"}),"Edit project"]})]}),s.goal?c.jsx(xn,{text:s.goal,className:"max-w-4xl"}):c.jsx("p",{className:"max-w-4xl text-sm text-[var(--text-muted)]",children:"Add a project goal to define the main objective."})]}),c.jsx(r2,{project:s}),c.jsx(N2,{features:t,phases:a}),c.jsx(HC,{features:t,phases:a,activeTasks:l,projectStorageScope:f}),c.jsx(c2,{features:t,phases:a}),c.jsx(f2,{features:t,phases:a})]})}async function qC(){const[t,a]=await Promise.all([Vb(),Kc()]);return{features:t,phases:a}}function _o(){return{active:0,planned:0,done:0,blocked:0,canceled:0}}function Bc(t){const a=[];return t.active&&a.push(`${t.active} active`),t.planned&&a.push(`${t.planned} planned`),t.done&&a.push(`${t.done} done`),t.blocked&&a.push(`${t.blocked} blocked`),t.canceled&&a.push(`${t.canceled} canceled`),a.join(" · ")}function IC(t){const a=_o();for(const l of t){if(l.status==="in-progress"||l.status==="discovery"){a.active+=1;continue}if(l.status==="planned"||l.status==="draft"){a.planned+=1;continue}if(l.status==="done"){a.done+=1;continue}if(l.status==="blocked"){a.blocked+=1;continue}l.status==="canceled"&&(a.canceled+=1)}return a}function I0(t){const a=_o();for(const l of t){if(l.status==="in-progress"){a.active+=1;continue}if(l.status==="planned"){a.planned+=1;continue}if(l.status==="done"){a.done+=1;continue}if(l.status==="blocked"){a.blocked+=1;continue}l.status==="canceled"&&(a.canceled+=1)}return a}function VC(t){const a=_o();for(const l of t){if(l.status==="in-progress"){a.active+=1;continue}if(l.status==="planned"){a.planned+=1;continue}if(l.status==="done"){a.done+=1;continue}if(l.status==="blocked"){a.blocked+=1;continue}l.status==="canceled"&&(a.canceled+=1)}return a}function YC({feature:t,phases:a,phasesCount:l,tasksCount:s,phaseSummary:o,taskSummary:u,activity:f}){var L;const m=hs(),p=hs(),x=((L=m.formData)==null?void 0:L.get("status"))??t.status,y=m.state!=="idle",N=p.state!=="idle",w=Bc(o),S=Bc(u),D=s0(a??[]),R=t.description||(f?`${f.doneTasks}/${s} done · ${f.remainingTasks} left${f.blockedTasks?` · ${f.blockedTasks} blocked`:""}`:"");return c.jsxs(vi,{variant:"surface",status:D.displayStatus,className:"px-4 py-2",children:[c.jsxs("div",{className:"grid gap-2 xl:grid-cols-[minmax(0,1fr)_minmax(0,132px)_minmax(0,152px)_124px_44px_44px] xl:items-center",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1 xl:contents",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(cr,{featureNum:t.number,featureId:t.id}),c.jsx(mr,{id:Bl({featureNum:t.number}),children:c.jsx("span",{className:"sr-only",children:"Copy feature path"})}),t.shortId?c.jsx(Hl,{shortId:t.shortId}):null,c.jsx("span",{className:"shrink-0",children:c.jsx(Vo,{status:D.displayStatus,breakdown:D.breakdown})})]}),c.jsx(Ye,{to:`/features/${t.id}`,className:"entity-link--feature min-w-0 w-full break-words text-sm font-semibold underline-offset-4 hover:underline [overflow-wrap:anywhere]",children:t.name})]}),c.jsxs("div",{className:"flex items-center gap-2 self-end xl:hidden",children:[c.jsx(Ye,{to:`/features/${t.id}/edit`,"aria-label":`Edit feature ${t.name}`,children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(p.Form,{method:"post",action:`/features/${t.id}/delete`,onSubmit:I=>{window.confirm(`Delete feature “${t.name}”? This cannot be undone.`)||I.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:N||y,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete feature ${t.name}`,children:c.jsx(di,{className:"h-4 w-4"})})})]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[l," phases"]}),w?c.jsx("div",{className:"mt-0.5 break-words",children:w}):null]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[s," tasks"]}),S?c.jsx("div",{className:"mt-0.5 break-words",children:S}):null]}),c.jsx(m.Form,{method:"post",action:`/features/${t.id}/status`,className:"w-full xl:w-auto",children:c.jsxs("div",{className:"relative",children:[c.jsx("select",{name:"status",value:x,disabled:y||N,"aria-busy":y,className:"field-control min-h-8 appearance-none py-1 pr-8 text-[11px]",onChange:I=>m.submit(I.currentTarget.form),children:rd.map(I=>c.jsx("option",{value:I.value,children:I.label},I.value))}),c.jsx(vs,{className:"pointer-events-none absolute right-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-[var(--text-muted)]"})]})}),c.jsx(Ye,{to:`/features/${t.id}/edit`,"aria-label":`Edit feature ${t.name}`,className:"hidden xl:block",children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(p.Form,{method:"post",action:`/features/${t.id}/delete`,className:"hidden xl:block",onSubmit:I=>{window.confirm(`Delete feature “${t.name}”? This cannot be undone.`)||I.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:N||y,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete feature ${t.name}`,children:c.jsx(di,{className:"h-4 w-4"})})})]}),R?c.jsx("div",{className:"mt-1 min-w-0 break-words line-clamp-2 text-[11px] text-[var(--text-muted)]",children:R}):null]})}const FC={feature:{label:"Feature",Icon:Cc},phase:{label:"Phase",Icon:$N},task:{label:"Task",Icon:qo},requirement:{label:"Requirement",Icon:$b}};function V0({kind:t,label:a}){const{Icon:l,label:s}=FC[t];return c.jsxs("span",{className:`entity-badge entity-badge--${t}`,children:[c.jsx(l,{className:"h-3.5 w-3.5"}),c.jsx("span",{children:a??s})]})}function ma({className:t="",...a}){return c.jsx("input",{className:`field-control ${t}`,...a})}function ys({className:t="",...a}){return c.jsx("select",{className:`field-control ${t}`,...a})}function sd({query:t,status:a,statusOptions:l,placeholder:s,clearTo:o,resultsLabel:u}){const f=mm(),m=((l==null?void 0:l.length)??0)>0;return c.jsxs(ca,{method:"get",className:`surface-card grid gap-3 p-3 md:items-end sm:p-4 ${m?"md:grid-cols-[minmax(0,1fr)_200px_auto_auto]":"md:grid-cols-[minmax(0,1fr)_auto_auto]"}`,children:[c.jsxs("div",{children:[c.jsx("label",{htmlFor:"list-filter-query",className:"mb-1 block text-xs font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Name"}),c.jsx(ma,{id:"list-filter-query",name:"q",defaultValue:t,placeholder:s,className:"min-h-9 py-2 sm:min-h-11 sm:py-2.5",onChange:p=>f(p.currentTarget.form)})]}),m?c.jsxs("div",{children:[c.jsx("label",{htmlFor:"list-filter-status",className:"mb-1 block text-xs font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Status"}),c.jsxs("div",{className:"relative",children:[c.jsxs(ys,{id:"list-filter-status",name:"status",defaultValue:a,className:"min-h-9 appearance-none py-2 sm:min-h-11 sm:py-2.5 pr-8",children:[c.jsx("option",{value:"",children:"All statuses"}),l==null?void 0:l.map(p=>c.jsx("option",{value:p.value,children:p.label},p.value))]}),c.jsx(vs,{className:"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--text-muted)]"})]})]}):null,c.jsx(gt,{type:"submit",variant:"secondary",children:"Apply filters"}),c.jsx(Ye,{to:o,className:"inline-flex min-h-9 items-center justify-center rounded-[12px] px-3 text-sm font-semibold text-[var(--text-muted)] transition hover:bg-[var(--accent-soft)] hover:text-[var(--text)] sm:min-h-11 sm:rounded-[14px]",children:"Clear"}),c.jsx("div",{className:`text-sm text-[var(--text-muted)] ${m?"md:col-span-4":"md:col-span-3"}`,children:u})]})}function id(t,a){const l=t.trim().toLowerCase();return l?a.some(s=>s==null?void 0:s.toLowerCase().includes(l)):!0}function PC(t){const a=new Map;for(const f of t)f.featureId&&a.set(f.featureId,[...a.get(f.featureId)??[],f]);const l=new Map,s=new Map,o=new Map,u=new Map;for(const[f,m]of a)l.set(f,m.length),s.set(f,m.reduce((p,g)=>p+g.tasks.length,0)),o.set(f,IC(m)),u.set(f,I0(m.flatMap(p=>p.tasks)));return{phasesByFeature:a,phasesCountByFeature:l,tasksCountByFeature:s,phaseSummaryByFeature:o,taskSummaryByFeature:u}}function GC(){var w,S;const{features:t,phases:a}=ll(),{phasesByFeature:l,phasesCountByFeature:s,tasksCountByFeature:o,phaseSummaryByFeature:u,taskSummaryByFeature:f}=PC(a),m=kr(),[p]=$o(),g=((w=p.get("q"))==null?void 0:w.trim())??"",x=((S=p.get("status"))==null?void 0:S.trim())??"",y=v.useCallback(()=>m("new"),[m]);An("create",y);const N=v.useMemo(()=>t.filter(D=>(!x||D.status===x)&&id(g,[D.name,D.id,D.description])),[t,g,x]);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Pt,{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[c.jsxs("div",{children:[c.jsx(V0,{kind:"feature",label:"Features"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Filter by name or status, then inspect child phases and tasks directly from the rows."})]}),c.jsx(Ye,{to:"new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create feature"})})]}),c.jsx(sd,{query:g,status:x,statusOptions:rd,placeholder:"Search feature name, id, or description",clearTo:"/features",resultsLabel:N.length===t.length?`${t.length} features`:`${N.length} of ${t.length} features`}),c.jsx("div",{className:"grid gap-3",children:t.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No features yet. ",c.jsx(Ye,{to:"/features/new",className:"font-semibold text-[var(--accent)] hover:underline",children:"Create your first feature"})]}):N.length>0?N.map(D=>c.jsx(YC,{feature:D,phases:l.get(D.id),phasesCount:s.get(D.id)??0,tasksCount:o.get(D.id)??0,phaseSummary:u.get(D.id)??_o(),taskSummary:f.get(D.id)??_o()},D.id)):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No features match the current filters."})})]}),c.jsx(hi,{})]})}async function XC(){const[t,a]=await Promise.all([vm(),Kc()]);return{requirements:t,phases:a}}function vo(...t){return t.filter(Boolean).join(" ")}function QC(){return c.jsx("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-[var(--border-strong)] bg-[var(--surface-elevated)] text-[var(--text)] shadow-sm transition group-open:rotate-180 group-hover:border-[var(--accent)] group-hover:text-[var(--accent)]",children:c.jsx(vs,{className:"h-5 w-5"})})}function ua({title:t,subtitle:a,leading:l,actions:s,defaultOpen:o=!0,count:u,className:f,summaryClassName:m,contentClassName:p,titleClassName:g,subtitleClassName:x,children:y}){return c.jsxs("details",{className:vo("group mt-4 overflow-hidden rounded-[10px] border border-[var(--border)]",f),open:o,children:[c.jsxs("summary",{className:vo("flex min-w-0 list-none cursor-pointer items-start justify-between gap-3 bg-[var(--surface-elevated)] p-4 text-left text-[var(--text)] transition-colors select-none hover:bg-[var(--surface-strong)] [&::-webkit-details-marker]:hidden",m),children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[l?c.jsx("div",{className:"shrink-0 pt-0.5",children:l}):null,c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:vo("flex flex-wrap items-center gap-2 text-sm font-semibold",g),children:[t,u!==void 0?c.jsxs("span",{className:"text-[var(--text-subtle)]",children:["(",u,")"]}):null]}),a?c.jsx("div",{className:vo("mt-2 text-sm text-[var(--text-muted)] [overflow-wrap:anywhere]",x),children:a}):null]})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s,c.jsx(QC,{})]})]}),c.jsx("div",{className:vo("border-t border-[var(--border)] bg-[var(--surface)] p-4",p),children:y})]})}function KC(t,a){const l=new Set(a.map(u=>u.id)),s=a.map(u=>({phase:u,requirements:t.filter(f=>f.linkedPhaseIds.includes(u.id))})).filter(u=>u.requirements.length>0).sort((u,f)=>u.phase.priority-f.phase.priority||u.phase.number-f.phase.number),o=t.filter(u=>!u.linkedPhaseIds.some(f=>l.has(f)));return{phaseGroups:s,unlinkedRequirements:o}}function $x(t){return`P${String(t.number??0).padStart(3,"0")}`}function qx({requirement:t}){return c.jsx(Pt,{className:"overflow-hidden p-0",children:c.jsx(ua,{defaultOpen:!1,title:c.jsx("h2",{className:"min-w-0 text-lg font-black tracking-tight text-[var(--text)] [overflow-wrap:anywhere]",children:t.title}),count:t.linkedPhaseIds.length,subtitle:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:[t.linkedPhaseIds.length," linked phase",t.linkedPhaseIds.length===1?"":"s"]}),t.linkedPhaseIds.length>0&&t.macroTasks.length>0?c.jsx("span",{className:"mx-2 text-[var(--text-subtle)]",children:"•"}):null,t.macroTasks.length>0?c.jsxs("span",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:[t.macroTasks.length," macro task",t.macroTasks.length===1?"":"s"]}):null]}),contentClassName:"grid gap-4",summaryClassName:"hover:bg-[var(--surface-elevated)]/65",children:c.jsxs("div",{className:"flex min-w-0 flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[c.jsx("div",{className:"min-w-0",children:t.description?c.jsx("p",{className:"min-w-0 text-sm text-[var(--text-muted)] [overflow-wrap:anywhere]",children:t.description}):null}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:justify-end",children:[c.jsx(Ye,{to:`${t.id}/edit`,children:c.jsx(gt,{type:"button",variant:"secondary",children:"Edit"})}),c.jsx(ca,{method:"post",action:`/requirements/${t.id}/delete`,onSubmit:a=>{window.confirm(`Delete requirement "${t.title}"?`)||a.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",children:"Delete"})})]})]})})})}function ZC(){var x;const{requirements:t,phases:a}=ll(),l=kr(),[s]=$o(),o=((x=s.get("q"))==null?void 0:x.trim())??"",u=v.useCallback(()=>l("new"),[l]);An("create",u);const f=v.useMemo(()=>new Map(a.map(y=>[y.id,y])),[a]),m=v.useMemo(()=>t.filter(y=>{const N=y.linkedPhaseIds.map(w=>{const S=f.get(w);return S?`${$x(S)} ${S.title} ${S.summary}`:w});return id(o,[y.title,y.description,y.id,...N])}),[t,f,o]),{phaseGroups:p,unlinkedRequirements:g}=v.useMemo(()=>KC(m,a),[m,a]);return v.useEffect(()=>{const y=window.location.hash.slice(1);y&&requestAnimationFrame(()=>{var N;return(N=document.getElementById(y))==null?void 0:N.scrollIntoView({block:"start"})})},[p]),c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Pt,{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[c.jsxs("div",{children:[c.jsx(V0,{kind:"requirement",label:"Requirements"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Track top-level outcomes independently from features, grouped below by the phases that deliver them."})]}),c.jsx(Ye,{to:"new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create requirement"})})]}),c.jsx(sd,{query:o,placeholder:"Search requirement title, description, id, or linked phase",clearTo:"/requirements",resultsLabel:m.length===t.length?`${t.length} requirements`:`${m.length} of ${t.length} requirements`}),c.jsx("div",{className:"grid gap-6",children:t.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No requirements yet. ",c.jsx(Ye,{to:"/requirements/new",className:"font-semibold text-[var(--accent)] hover:underline",children:"Create your first requirement"})]}):m.length>0?c.jsxs(c.Fragment,{children:[p.map(({phase:y,requirements:N})=>{const w=y.featureId?`/features/${y.featureId}/phases/${y.id}`:"/features";return c.jsxs("section",{id:`phase-${y.id}`,className:"scroll-mt-28","aria-labelledby":`phase-${y.id}-heading`,children:[c.jsxs("div",{className:"mb-3 flex min-w-0 flex-wrap items-center justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:"Linked phase"}),c.jsxs(Ye,{id:`phase-${y.id}-heading`,to:w,className:"min-w-0 break-words text-base font-black text-[var(--text)] underline-offset-4 hover:text-[var(--accent)] hover:underline [overflow-wrap:anywhere]",children:[$x(y)," — ",y.title]})]}),c.jsxs("span",{className:"shrink-0 rounded-full bg-[var(--surface-elevated)] px-2.5 py-1 text-xs font-semibold text-[var(--text-muted)]",children:[N.length," requirement",N.length===1?"":"s"]})]}),c.jsx("div",{className:"grid gap-3",children:N.map(S=>c.jsx(qx,{requirement:S},S.id))})]},y.id)}),g.length>0?c.jsxs("section",{id:"unlinked-requirements",className:"scroll-mt-28","aria-labelledby":"unlinked-requirements-heading",children:[c.jsxs("div",{className:"mb-3 flex min-w-0 flex-wrap items-center justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:"Unlinked"}),c.jsx("h2",{id:"unlinked-requirements-heading",className:"text-base font-black text-[var(--text)]",children:"Requirements without a valid phase"})]}),c.jsx("span",{className:"shrink-0 rounded-full bg-[var(--surface-elevated)] px-2.5 py-1 text-xs font-semibold text-[var(--text-muted)]",children:g.length})]}),c.jsx("div",{className:"grid gap-3",children:g.map(y=>c.jsx(qx,{requirement:y},y.id))})]}):null]}):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No requirements match the current filters."})})]}),c.jsx(hi,{})]})}async function JC({params:t}){const a=t.featureId;if(!a)throw new Response("featureId required",{status:400});const[l,s]=await Promise.all([Io(a),Kc(a)]);return{feature:l,phases:s}}function WC({featureId:t,feature:a,phase:l}){var y,N;const s=hs(),o=hs(),f=((y=s.formData)==null?void 0:y.get("status"))??l.status,m=s.state!=="idle",p=o.state!=="idle",g=Bc(I0(l.tasks)),x=i0(l.tasks);return c.jsxs(vi,{variant:"surface",status:x.displayStatus,className:"px-4 py-2",children:[c.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_minmax(0,150px)_124px_44px_44px] lg:items-center",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1 lg:contents",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(cr,{featureNum:a.number,phaseNum:l.number,featureId:a.id,phaseId:l.id}),c.jsx(mr,{id:Bl({featureNum:a.number,phaseNum:l.number}),children:c.jsx("span",{className:"sr-only",children:"Copy phase path"})}),l.shortId?c.jsx(Hl,{shortId:l.shortId}):null,l.handoff?c.jsx(xm,{phaseId:l.id,updatedAt:l.handoffUpdatedAt}):null,c.jsx(z0,{phaseId:l.id,phaseTitle:l.title,count:((N=l.linkedRequirements)==null?void 0:N.length)??0}),c.jsx("span",{className:"shrink-0",children:c.jsx(Vo,{status:x.displayStatus,breakdown:x.breakdown})})]}),c.jsx(Ye,{to:`/features/${t}/phases/${l.id}`,className:"entity-link--phase min-w-0 w-full break-words text-sm font-semibold underline-offset-4 hover:underline [overflow-wrap:anywhere]",children:l.title})]}),c.jsxs("div",{className:"flex items-center gap-2 self-end lg:hidden",children:[c.jsx(Ye,{to:`/features/${t}/phases/${l.id}/edit`,"aria-label":`Edit phase ${l.title}`,children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(o.Form,{method:"post",action:`/features/${t}/phases/${l.id}/delete`,onSubmit:w=>{window.confirm(`Delete phase “${l.title}”? This cannot be undone.`)||w.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:p||m,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete phase ${l.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[l.tasks.length," tasks"]}),g?c.jsx("div",{className:"mt-0.5 break-words",children:g}):null]}),c.jsx(s.Form,{method:"post",action:`/features/${t}/phases/${l.id}/status`,className:"w-full lg:w-auto",children:c.jsxs("div",{className:"relative",children:[c.jsx("select",{name:"status",value:f,disabled:m||p,"aria-busy":m,className:"field-control min-h-8 appearance-none py-1 pr-8 text-[11px]",onChange:w=>s.submit(w.currentTarget.form),children:ld.map(w=>c.jsx("option",{value:w.value,children:w.label},w.value))}),c.jsx(vs,{className:"pointer-events-none absolute right-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-[var(--text-muted)]"})]})}),c.jsx(Ye,{to:`/features/${t}/phases/${l.id}/edit`,"aria-label":`Edit phase ${l.title}`,className:"hidden lg:block",children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(o.Form,{method:"post",action:`/features/${t}/phases/${l.id}/delete`,className:"hidden lg:block",onSubmit:w=>{window.confirm(`Delete phase “${l.title}”? This cannot be undone.`)||w.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:p||m,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete phase ${l.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]}),l.summary?c.jsx("div",{className:"mt-1 min-w-0 break-words line-clamp-2 text-[11px] text-[var(--text-muted)]",children:l.summary}):null]})}function zm({items:t,className:a="",stacked:l=!1}){return l?c.jsx("nav",{"aria-label":"Breadcrumb",className:`grid gap-1 text-sm ${a}`,children:t.map((s,o)=>{const u=o===t.length-1,f=s.to&&!u?c.jsx(Ye,{to:s.to,className:"font-semibold text-[var(--accent)] hover:underline break-words min-w-0",children:s.label}):c.jsx("span",{className:`break-words min-w-0 ${u?"text-[var(--text)] font-semibold":"text-[var(--text-muted)]"}`,children:s.label});return c.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.kind?c.jsxs("span",{className:"shrink-0 text-[var(--text-subtle)] font-medium",children:[s.kind,":"]}):null,c.jsx("span",{className:"min-w-0",children:f})]},`${s.label}-${o}`)})}):c.jsx("nav",{"aria-label":"Breadcrumb",className:`flex flex-wrap items-center gap-2 text-sm ${a}`,children:t.map((s,o)=>{const u=o===t.length-1,f=s.to&&!u?c.jsx(Ye,{to:s.to,className:"font-semibold text-[var(--accent)] hover:underline",children:s.label}):c.jsx("span",{className:u?"text-[var(--text)]":"text-[var(--text-muted)]",children:s.label});return c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2",children:[o>0?c.jsx("span",{className:"text-[var(--text-subtle)]",children:"/"}):null,c.jsx("span",{className:"min-w-0 break-words",children:f})]},`${s.label}-${o}`)})})}function Um({featureNum:t,phaseNum:a,taskNum:l,featureId:s,phaseId:o,taskId:u,shortId:f,children:m}){return c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:t,phaseNum:a,taskNum:l,featureId:s,phaseId:o,taskId:u}),c.jsx(mr,{id:Bl({featureNum:t,phaseNum:a,taskNum:l}),children:c.jsx("span",{className:"sr-only",children:"Copy path"})}),f?c.jsx(Hl,{shortId:f}):null,m]})}function zn({className:t="",children:a,...l}){return c.jsx("div",{className:`surface-card p-4 ${t}`,...l,children:a})}function Ix(...t){return t.filter(Boolean).join(" ")}function Bm({items:t,className:a}){const l=t.filter(s=>s.visible!==!1);return l.length===0?null:c.jsx("div",{className:Ix("grid gap-4 md:grid-cols-2 xl:grid-cols-4",a),children:l.map(s=>c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:s.label}),c.jsx("div",{className:Ix("mt-2 text-sm font-semibold break-words text-[var(--text)] [overflow-wrap:anywhere]",s.valueClassName),children:s.value})]},s.label))})}function Hm(t){return t&&t>0?`P${t}`:""}function eD(t,a){return!t&&!a?"":`${t||"Start not set"} → ${a||"End not set"}`}function $m({decisions:t}){return t.length===0?null:c.jsxs("details",{className:"group mt-4",children:[c.jsx("summary",{className:"flex cursor-pointer select-none items-center gap-2 font-semibold text-[var(--text)]",children:c.jsxs("span",{children:["Accepted decisions (",t.length,")"]})}),c.jsx("div",{className:"mt-2 grid gap-3",children:t.map(a=>c.jsxs("div",{className:"surface-card px-4 py-3",children:[c.jsx("p",{className:"text-sm font-semibold text-[var(--text)]",children:a.title}),a.decision?c.jsxs("div",{className:"mt-2 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Decision:"}),c.jsx(xn,{text:a.decision,className:"mt-1"})]}):null,a.rationale?c.jsxs("div",{className:"mt-1 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Rationale:"}),c.jsx(xn,{text:a.rationale,className:"mt-1"})]}):null,a.implementationNotes?c.jsxs("div",{className:"mt-1 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Implementation:"}),c.jsx(xn,{text:a.implementationNotes,className:"mt-1"})]}):null]},a.id))})]})}const tD={draft:jN,discovery:aR,planned:qo,"in-progress":Ub,done:pm,blocked:Hb,waiting:zb,deferred:iR,canceled:Mb,rejected:CN};function Bh(t){return t.split(/[-\s]+/).filter(Boolean).map(a=>a==="and"?"and":a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function Vx(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"short",timeStyle:"short"}).format(new Date(t))}catch{return t}}const nD=new Set(["canceled","rejected"]);function qm({statusLog:t,currentStatus:a,backbone:l,createdAt:s,updatedAt:o,startedAt:u,completedAt:f}){const m=[];if(t.length===0){const S=l.indexOf(a);if(S>=0)for(let D=0;D<=S;D++)m.push(l[D]);else m.push(a)}else{const S=t[0];S&&m.push(S.fromStatus);for(const D of t)m[m.length-1]!==D.toStatus&&m.push(D.toStatus)}m[m.length-1]!==a&&m.push(a);const p=new Set(m),g=a==="done"||nD.has(a),x=S=>{var R,L;if(t.length>0){if(S===((R=t[0])==null?void 0:R.fromStatus))return((L=t[0])==null?void 0:L.date)??"";for(const I of t)if(I.toStatus===S)return I.date;return""}const D=l[0];return S===D?s??"":S==="in-progress"?u??o??"":S==="done"?f??o??"":""},y=[...m];if(!g){const S=l.indexOf(a);if(S>=0&&S+1<l.length){const D=l[S+1];p.has(D)||y.push(D)}}const N=t.length===0?y.filter((S,D)=>D===0||S===a||!!x(S)):y,w=S=>p.has(S)?S===a&&!g?"current":"completed":"pending";return c.jsx("ol",{className:"status-stepper",role:"list","aria-label":"Status progress",children:N.map((S,D)=>{const R=w(S),L=tD[S]??Pc,I=p.has(S),q=x(S),X=q?`${Bh(S)} — ${Vx(q)}`:Bh(S),W=D===0?null:I?"traveled":"pending";return c.jsxs("li",{className:`status-step status-step--${R}`,role:"listitem","aria-current":R==="current"?"step":void 0,style:{"--step-color":`var(--color-status-${S})`},children:[W?c.jsx("span",{className:`status-connector status-connector--${W}`,"aria-hidden":"true"}):null,c.jsx("span",{className:"status-node",title:X,children:c.jsx(L,{className:"status-node-icon"})}),c.jsx("span",{className:"status-step-label",children:Bh(S)}),q?c.jsx("span",{className:"status-step-date",children:Vx(q)}):null]},`${S}-${D}`)})})}function Yx(t){return t.split(/[-\s]+/).filter(Boolean).map(a=>a==="and"?"and":a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function aD(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"short",timeStyle:"short"}).format(new Date(t))}catch{return t}}function rD(t,a,l,s,o){if(t.length>0)return t.map(m=>({date:m.date,fromStatus:m.fromStatus,toStatus:m.toStatus,inferred:!1}));const u=l.indexOf(a);if(u<0)return[];const f=[];for(let m=1;m<=u;m++){const p=l[m-1],g=l[m],x=g==="in-progress"?s??"":g==="done"?o??"":"";f.push({date:x,fromStatus:p,toStatus:g,inferred:!0})}return f}function Im({statusLog:t,currentStatus:a,backbone:l,startedAt:s,completedAt:o}){const u=rD(t??[],a??"",l??[],s,o);return c.jsx(ua,{title:"Status history",count:u.length,defaultOpen:u.length>0,contentClassName:"grid gap-2.5",children:u.length===0?c.jsx("p",{className:"text-sm text-[var(--text-muted)] italic",children:"No status changes recorded."}):u.map((f,m)=>c.jsxs("div",{className:"text-sm flex flex-wrap items-center gap-2",children:[c.jsx("span",{className:"text-xs font-mono text-[var(--text-subtle)]",children:aD(f.date)}),c.jsx("span",{className:"font-semibold text-[var(--text-muted)]",children:Yx(f.fromStatus)}),c.jsx("span",{className:"text-[var(--text-subtle)]",children:"→"}),c.jsx("span",{className:"font-semibold text-[var(--text)]",children:Yx(f.toStatus)})]},m))})}function lD(t){return t.reduce((a,l)=>a+l.tasks.length,0)}function sD(t){let a=0,l=0,s=0,o=0;for(const u of t)for(const f of u.tasks)f.status==="in-progress"&&(a+=1),f.status==="done"&&(l+=1),f.status==="blocked"&&(s+=1),["done","canceled"].includes(f.status)||(o+=1);return{inProgress:a,done:l,blocked:s,remaining:o}}function iD(t){return t.find(a=>["in-progress","discovery","planned","draft"].includes(a.status))}function oD(){var W,ae,z,T;const{feature:t,phases:a}=ll(),l=t.acceptedDecisions??[],s=lD(a),o=sD(a),u=iD(a),f=s0(a),[m,p]=$o(),g=((W=m.get("q"))==null?void 0:W.trim())??"",x=((ae=m.get("status"))==null?void 0:ae.trim())??"",y=((z=m.get("sort"))==null?void 0:z.trim())??"priority",N=((T=m.get("dir"))==null?void 0:T.trim())??"asc",w={key:y==="priority"||y==="number"||y==="createdAt"||y==="updatedAt"||y==="title"||y==="shortId"||y==="status"||y==="startedAt"||y==="completedAt"?y:"priority",direction:N==="desc"?"desc":"asc"},S=v.useMemo(()=>[...a].sort((ee,fe)=>Eo(ee,fe,w.key,w.direction)),[a,w]),D=v.useMemo(()=>S.filter(ee=>(!x||ee.status===x)&&id(g,[ee.title,ee.id,ee.summary,ee.description])),[S,g,x]),R=kr(),L=v.useRef(null),I=v.useCallback(()=>R("edit"),[R]),q=v.useCallback(()=>R("phases/new"),[R]),X=v.useCallback(()=>{var ee;(ee=L.current)==null||ee.requestSubmit()},[]);return An("edit",I),An("create",q),An("delete",X),c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:"/features",className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to features"]}),c.jsxs("div",{className:"min-w-0",children:[c.jsx(zm,{stacked:!0,items:[{label:t.name,kind:"Feature"}]}),c.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:c.jsx(Um,{featureNum:t.number,featureId:t.id,shortId:t.shortId,children:c.jsx(Vo,{status:f.displayStatus,breakdown:f.breakdown})})}),c.jsx("h2",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] min-w-0 break-words [overflow-wrap:anywhere] sm:text-3xl",children:t.name}),t.description?c.jsx(ua,{title:"Description",children:c.jsx(xn,{text:t.description,className:"plan-description max-w-4xl"})}):null,c.jsx("div",{className:"mt-4",children:c.jsx(qm,{statusLog:t.statusLog??[],currentStatus:t.status,backbone:["planned","in-progress","done"],createdAt:t.createdAt,updatedAt:t.updatedAt})}),c.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[c.jsx(Ye,{to:"edit",children:c.jsx(gt,{type:"button",shortcut:"edit",children:"Edit feature"})}),c.jsx(ca,{ref:L,method:"post",action:`/features/${t.id}/delete`,className:"inline-flex",onSubmit:ee=>{window.confirm(`Delete feature "${t.name}"?`)||ee.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",shortcut:"delete",children:"Delete feature"})})]})]}),c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Current phase"}),c.jsx("p",{className:"mt-2 text-sm font-semibold text-[var(--text)] break-words",children:(u==null?void 0:u.title)||"No active phase"})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Phases"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:a.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Tasks"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:s})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Current phase"}),c.jsx("p",{className:"mt-2 text-sm font-semibold text-[var(--text)] break-words",children:(u==null?void 0:u.title)||"No active phase"})]})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"In progress"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.inProgress})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Remaining"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.remaining})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Done"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.done})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Blocked"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.blocked})]})]}),c.jsx(Bm,{items:[{label:"Priority",value:Hm(t.priority),visible:t.priority>0},{label:"Timeline",value:eD(t.startDate,t.endDate),visible:!!(t.startDate||t.endDate)}]}),t.workDone||t.workRemaining?c.jsx(ua,{title:"Planning notes",defaultOpen:!1,children:c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[t.workDone?c.jsxs("div",{children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Work done"}),c.jsx(xn,{text:t.workDone,className:"mt-2"})]}):null,t.workRemaining?c.jsxs("div",{children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Work remaining"}),c.jsx(xn,{text:t.workRemaining,className:"mt-2"})]}):null]})}):null,l.length>0?c.jsx($m,{decisions:l}):null,c.jsx(Im,{statusLog:t.statusLog??[],currentStatus:t.status,backbone:["planned","in-progress","done"]})]}),c.jsxs(Pt,{className:"grid gap-5",children:[c.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Phases"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Filter and sort this feature's phases."})]}),c.jsx(Ye,{to:"phases/new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create phase"})})]}),c.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[c.jsx(Om,{sort:w,onChange:ee=>p(fe=>(fe.set("sort",ee.key),fe.set("dir",ee.direction),fe))}),c.jsx(sd,{query:g,status:x,statusOptions:ld,placeholder:"Search phase title, id, or summary",clearTo:`/features/${t.id}`,resultsLabel:D.length===a.length?`${a.length} phases`:`${D.length} of ${a.length} phases`})]}),c.jsx("div",{className:"grid gap-3",children:a.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No phases yet. ",c.jsx(Ye,{to:`/features/${t.id}/phases/new`,className:"font-semibold text-[var(--accent)] hover:underline",children:"Add a phase"})]}):D.length>0?D.map(ee=>c.jsx(WC,{featureId:t.id,feature:t,phase:ee},ee.id)):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No phases match the current filters."})})]}),c.jsx(hi,{})]})}async function uD({params:t}){const{featureId:a,phaseId:l}=t;if(!a||!l)throw new Response("featureId and phaseId required",{status:400});const[s,o,u]=await Promise.all([Io(a),Zc(l),vm()]),f=u.filter(m=>m.linkedPhaseIds.includes(l));return{feature:s,phase:{...o,linkedRequirements:f}}}function Fx(t){try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}function cD({featureId:t,featureNum:a,phaseId:l,phaseNum:s,task:o}){var w;const u=hs(),f=hs(),p=((w=u.formData)==null?void 0:w.get("status"))??o.status,g=u.state!=="idle",x=f.state!=="idle",y=Bc(VC(o.subtasks)),N=n0(p);return c.jsxs(vi,{variant:"surface",status:N,className:"px-4 py-2",children:[c.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_minmax(0,168px)_124px_44px_44px] lg:items-center",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1 lg:contents",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(cr,{featureNum:a,phaseNum:s,taskNum:o.number,featureId:t,phaseId:l,taskId:o.id}),c.jsx(mr,{id:Bl({featureNum:a,phaseNum:s,taskNum:o.number}),children:c.jsx("span",{className:"sr-only",children:"Copy task path"})}),o.shortId?c.jsx(Hl,{shortId:o.shortId}):null,c.jsx("span",{className:"shrink-0",children:c.jsx(ur,{status:p})})]}),c.jsx(Ye,{to:`/features/${t}/phases/${l}/tasks/${o.id}`,className:"entity-link--task min-w-0 w-full break-words text-sm font-semibold underline-offset-4 hover:underline [overflow-wrap:anywhere]",children:o.title})]}),c.jsxs("div",{className:"flex items-center gap-2 self-end lg:hidden",children:[c.jsx(Ye,{to:`/features/${t}/phases/${l}/tasks/${o.id}/edit`,"aria-label":`Edit task ${o.title}`,children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(f.Form,{method:"post",action:`/features/${t}/phases/${l}/tasks/${o.id}/delete`,onSubmit:S=>{window.confirm(`Delete task “${o.title}”? This cannot be undone.`)||S.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:x||g,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete task ${o.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[o.subtasks.length," subtasks · ",o.checklist.length," checklist"]}),y?c.jsx("div",{className:"mt-0.5 break-words",children:y}):c.jsx("div",{className:"mt-0.5 break-words",children:"No subtask statuses yet"})]}),c.jsx(u.Form,{method:"post",action:`/features/${t}/phases/${l}/tasks/${o.id}/status`,className:"w-full lg:w-auto",children:c.jsxs("div",{className:"relative",children:[c.jsx("select",{name:"status",value:p,disabled:g||x,"aria-busy":g,className:"field-control min-h-8 appearance-none py-1 pr-8 text-[11px]",onChange:S=>u.submit(S.currentTarget.form),children:Xo.map(S=>c.jsx("option",{value:S.value,children:S.label},S.value))}),c.jsx(vs,{className:"pointer-events-none absolute right-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-[var(--text-muted)]"})]})}),c.jsx(Ye,{to:`/features/${t}/phases/${l}/tasks/${o.id}/edit`,"aria-label":`Edit task ${o.title}`,className:"hidden lg:block",children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(f.Form,{method:"post",action:`/features/${t}/phases/${l}/tasks/${o.id}/delete`,className:"hidden lg:block",onSubmit:S=>{window.confirm(`Delete task “${o.title}”? This cannot be undone.`)||S.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:x||g,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete task ${o.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-[var(--text-subtle)]",children:[o.startedAt?c.jsxs("span",{children:["Started ",Fx(o.startedAt)]}):null,o.completedAt?c.jsxs("span",{children:["Completed ",Fx(o.completedAt)]}):null]}),o.description?c.jsx("div",{className:"mt-1 min-w-0 break-words line-clamp-2 text-[11px] text-[var(--text-muted)]",children:o.description}):null]})}function dD(t){let a=0,l=0,s=0,o=0;for(const u of t.tasks)u.status==="in-progress"&&(a+=1),u.status==="done"&&(l+=1),u.status==="blocked"&&(s+=1),["done","canceled"].includes(u.status)||(o+=1);return{inProgress:a,done:l,blocked:s,remaining:o}}function fD(){var fe,be,ye,te;const{feature:t,phase:a}=ll(),l=a.decisions??[],s=a.acceptedDecisions??[],o=a.linkedRequirements??[],u=dD(a),f=i0(a.tasks),[m,p]=$o(),g=((fe=m.get("q"))==null?void 0:fe.trim())??"",x=((be=m.get("status"))==null?void 0:be.trim())??"",y=((ye=m.get("sort"))==null?void 0:ye.trim())??"priority",N=((te=m.get("dir"))==null?void 0:te.trim())??"asc",w={key:y==="priority"||y==="number"||y==="createdAt"||y==="updatedAt"||y==="title"||y==="shortId"||y==="status"||y==="startedAt"||y==="completedAt"?y:"priority",direction:N==="desc"?"desc":"asc"},S=v.useMemo(()=>[...a.tasks].sort((re,ge)=>Eo(re,ge,w.key,w.direction)),[a.tasks,w]),D=v.useMemo(()=>S.filter(re=>(!x||re.status===x)&&id(g,[re.title,re.id,re.description,re.shortName])),[S,g,x]),R=kr(),L=v.useRef(null),[I,q]=v.useState(a.handoff??""),[X,W]=v.useState(!1),ae=v.useCallback(()=>R("edit"),[R]),z=v.useCallback(()=>R("tasks/new"),[R]),T=v.useCallback(()=>{var re;(re=L.current)==null||re.requestSubmit()},[]),ee=v.useCallback(async()=>{if(window.confirm("Clear this phase's handoff?")){W(!0);try{await Gb(a.id),q("")}catch{}finally{W(!1)}}},[a.id]);return An("edit",ae),An("create",z),An("delete",T),c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:`/features/${t.id}`,className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to feature"]}),c.jsxs("div",{className:"min-w-0",children:[c.jsx(zm,{stacked:!0,items:[{label:t.name,to:`/features/${t.id}`,kind:"Feature"},{label:a.title,kind:"Phase"}]}),c.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:c.jsxs(Um,{featureNum:t.number,phaseNum:a.number,featureId:t.id,phaseId:a.id,shortId:a.shortId,children:[I?c.jsx(xm,{phaseId:a.id,updatedAt:a.handoffUpdatedAt}):null,c.jsx(Vo,{status:f.displayStatus,breakdown:f.breakdown})]})}),c.jsx("h2",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] min-w-0 break-words [overflow-wrap:anywhere] sm:text-3xl",children:a.title}),a.summary?c.jsx(xn,{text:a.summary,className:"mt-3 max-w-4xl"}):null,c.jsx(qm,{statusLog:a.statusLog??[],currentStatus:a.status,backbone:["draft","discovery","planned","in-progress","done"],createdAt:a.createdAt,updatedAt:a.updatedAt}),c.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[c.jsx(Ye,{to:"edit",children:c.jsx(gt,{type:"button",shortcut:"edit",children:"Edit phase"})}),c.jsx(Ye,{to:"tasks/new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create task"})}),c.jsx(ca,{ref:L,method:"post",action:`/features/${t.id}/phases/${a.id}/delete`,className:"inline-flex",onSubmit:re=>{window.confirm(`Delete phase "${a.title}"?`)||re.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",shortcut:"delete",children:"Delete phase"})})]})]}),c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Tasks"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:a.tasks.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"In progress"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.inProgress})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Remaining"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.remaining})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Done"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.done})]})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Blocked"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.blocked})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Goals"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:a.goals.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Dependencies"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:a.dependencies.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Completion criteria"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:a.completionCriteria.length})]})]}),c.jsx(Bm,{items:[{label:"Priority",value:Hm(a.priority),visible:a.priority>0},{label:"Linked requirements",value:o.length,visible:o.length>0,valueClassName:"text-2xl font-black"},{label:"Risks",value:a.risks.length,visible:a.risks.length>0,valueClassName:"text-2xl font-black"},{label:"Open questions",value:a.openQuestions.length,visible:a.openQuestions.length>0,valueClassName:"text-2xl font-black"}]}),a.notes?c.jsx(ua,{title:"Notes",defaultOpen:!1,children:c.jsx(xn,{text:a.notes,className:"plan-description"})}):null,c.jsx(ua,{title:"Linked requirements",count:o.length,defaultOpen:!1,children:o.length>0?c.jsx("div",{className:"grid gap-3",children:o.map(re=>c.jsx("div",{className:"min-w-0 rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-4 py-4",children:c.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(ur,{status:re.status}),re.macroTasks.length>0?c.jsxs("span",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:[re.macroTasks.length," macro task",re.macroTasks.length===1?"":"s"]}):null]}),c.jsx("h3",{className:"mt-2 text-lg font-black tracking-tight text-[var(--text)] [overflow-wrap:anywhere]",children:re.title}),re.description?c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)] [overflow-wrap:anywhere]",children:re.description}):null]}),c.jsx(Ye,{to:`/requirements#phase-${a.id}`,className:"text-sm font-semibold text-[var(--accent)] hover:underline sm:shrink-0",children:"Open phase requirements →"})]})},re.id))}):c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"No linked requirements yet."})}),a.description?c.jsx(ua,{title:"Description",children:c.jsx(xn,{text:a.description,className:"plan-description"})}):null,l.length>0?c.jsx(ua,{title:"Decisions",count:l.length,defaultOpen:!1,children:c.jsx("div",{className:"grid gap-2 border-l-2 border-[var(--border)] pl-4 ml-1",children:l.map((re,ge)=>c.jsx("div",{className:"text-sm text-[var(--text-muted)]",children:c.jsx(xn,{text:re})},ge))})}):null,s.length>0?c.jsx($m,{decisions:s}):null,c.jsx(Im,{statusLog:a.statusLog??[],currentStatus:a.status,backbone:["draft","discovery","planned","in-progress","done"]})]}),I?c.jsx(Pt,{className:"grid gap-4",children:c.jsx(ua,{title:"Handoff",actions:c.jsx("button",{type:"button",onClick:ee,disabled:X,className:"rounded-lg border border-[var(--border)] px-3 py-1.5 text-sm text-[var(--text-muted)] hover:bg-[var(--surface-card)] disabled:opacity-60",children:X?"Clearing…":"Clear handoff"}),children:c.jsx("div",{className:"rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-5 py-5",children:c.jsx(xn,{text:I,className:"formatted-text max-w-none"})})})}):null,c.jsxs(Pt,{className:"grid gap-5",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Tasks"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Filter and sort this phase's tasks."})]}),c.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[c.jsx(Om,{sort:w,onChange:re=>p(ge=>(ge.set("sort",re.key),ge.set("dir",re.direction),ge))}),c.jsx(sd,{query:g,status:x,statusOptions:Xo,placeholder:"Search task title, id, or description",clearTo:`/features/${t.id}/phases/${a.id}`,resultsLabel:D.length===a.tasks.length?`${a.tasks.length} tasks`:`${D.length} of ${a.tasks.length} tasks`})]}),c.jsx("div",{className:"grid gap-3",children:a.tasks.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No tasks yet. ",c.jsx(Ye,{to:"tasks/new",className:"font-semibold text-[var(--accent)] hover:underline",children:"Add a task"})]}):D.length>0?D.map(re=>c.jsx(cD,{featureId:t.id,featureNum:t.number,phaseId:a.id,phaseNum:a.number,task:re},re.id)):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No tasks match the current filters."})})]}),c.jsx(hi,{})]})}async function hD({params:t}){const{featureId:a,phaseId:l,taskId:s}=t;if(!a||!l||!s)throw new Response("featureId, phaseId and taskId required",{status:400});const[o,u,f]=await Promise.all([Io(a),Zc(l),Jc(s)]);return{feature:o,phase:u,task:f}}function Px(t){try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}function mD({featureId:t,phaseId:a,taskId:l,item:s}){const o=hs(),u=o.formData?o.formData.get("checked")==="true":s.checked,f=o.state!=="idle";return c.jsxs("div",{className:"surface-card flex items-start gap-3 px-4 py-3",children:[c.jsx("input",{type:"checkbox",checked:u,onChange:()=>o.submit({checked:s.checked?"false":"true"},{method:"post",action:`/features/${t}/phases/${a}/tasks/${l}/checklist/${s.id}/toggle`}),disabled:f,className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent)]","aria-label":`Toggle checklist item ${s.title}`}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"checklist-num",children:s.number})," ",c.jsx("span",{className:`text-sm ${u?"text-[var(--text-muted)] line-through":"font-medium text-[var(--text)]"}`,children:s.title})]})]})}function pD(){var x,y;const{feature:t,phase:a,task:l}=ll(),s=l.decisions??[],o=l.acceptedDecisions??[],u=l.checklist??[],f=kr(),m=v.useRef(null),p=v.useCallback(()=>f("edit"),[f]),g=v.useCallback(()=>{var N;(N=m.current)==null||N.requestSubmit()},[]);return An("edit",p),An("delete",g),c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:`/features/${t.id}/phases/${a.id}`,className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to phase"]}),c.jsxs("div",{className:"min-w-0",children:[c.jsx(zm,{stacked:!0,items:[{label:t.name,to:`/features/${t.id}`,kind:"Feature"},{label:a.title,to:`/features/${t.id}/phases/${a.id}`,kind:"Phase"},{label:l.title,kind:"Task"}]}),c.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:c.jsx(Um,{featureNum:t.number,phaseNum:a.number,taskNum:l.number,featureId:t.id,phaseId:a.id,taskId:l.id,shortId:l.shortId,children:c.jsx(ur,{status:l.status})})}),c.jsx("h2",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] min-w-0 break-words [overflow-wrap:anywhere] sm:text-3xl",children:l.title}),c.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[c.jsx(Ye,{to:"edit",children:c.jsx(gt,{type:"button",shortcut:"edit",children:"Edit task"})}),c.jsx(ca,{ref:m,method:"post",action:`/features/${t.id}/phases/${a.id}/tasks/${l.id}/delete`,className:"inline-flex",onSubmit:N=>{window.confirm(`Delete task "${l.title}"?`)||N.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",shortcut:"delete",children:"Delete task"})})]})]}),c.jsx(qm,{statusLog:l.statusLog??[],currentStatus:l.status,backbone:["planned","in-progress","done"],createdAt:l.createdAt,updatedAt:l.updatedAt,startedAt:l.startedAt,completedAt:l.completedAt}),c.jsxs(Pt,{className:"grid gap-4",children:[l.description?c.jsx(ua,{title:"Description",children:c.jsx(xn,{text:l.description,className:"plan-description"})}):null,l.notes?c.jsx(ua,{title:"Notes",defaultOpen:!1,children:c.jsx(xn,{text:l.notes})}):null,c.jsx(Im,{statusLog:l.statusLog??[],currentStatus:l.status,backbone:["planned","in-progress","done"],startedAt:l.startedAt,completedAt:l.completedAt}),s.length>0?c.jsx(ua,{title:"Decisions",count:s.length,defaultOpen:!1,children:c.jsx("div",{className:"grid gap-2 border-l-2 border-[var(--border)] pl-4 ml-1",children:s.map((N,w)=>c.jsx("div",{className:"text-sm text-[var(--text-muted)]",children:c.jsx(xn,{text:N})},w))})}):null,o.length>0?c.jsx($m,{decisions:o}):null,c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-5",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Checklist items"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:u.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Subtasks"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:((x=l.subtasks)==null?void 0:x.length)??0})]})]}),c.jsx(Bm,{items:[{label:"Priority",value:Hm(l.priority),visible:l.priority>0},{label:"Short name",value:l.shortName,visible:!!l.shortName},{label:"Started",value:Px(l.startedAt),visible:!!l.startedAt},{label:"Completed",value:Px(l.completedAt),visible:!!l.completedAt},{label:"Phase",value:a.title}]}),c.jsxs("div",{className:"grid gap-3",children:[c.jsx("div",{children:c.jsxs("h3",{className:"text-sm font-bold text-[var(--text)]",children:["Steps (",u.length,")"]})}),u.length?c.jsx("div",{className:"grid gap-2",children:u.map(N=>c.jsx(mD,{featureId:t.id,phaseId:a.id,taskId:l.id,item:N},N.id))}):c.jsx("p",{className:"text-sm text-[var(--text-muted)] italic",children:"No steps defined."})]}),(y=l.subtasks)!=null&&y.length?c.jsx(ua,{title:"Subtasks",count:l.subtasks.length,defaultOpen:!1,contentClassName:"grid gap-2",children:l.subtasks.map(N=>c.jsxs("div",{className:"surface-card flex items-center justify-between gap-4 px-4 py-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-sm font-semibold text-[var(--text)]",children:N.title}),c.jsx("p",{className:"mt-1 text-xs text-[var(--text-muted)]",children:N.id})]}),c.jsx(ur,{status:N.status})]},N.id))}):null]}),c.jsx(hi,{})]})}const gD=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","[tabindex]:not([tabindex='-1'])"].join(",");function ql({title:t,description:a,children:l}){const s=kr(),o=v.useRef(null),u=v.useRef(null);return v.useEffect(()=>{var g;const f=o.current;if(!f)return;const m=document.activeElement;(g=u.current)==null||g.focus();const p=x=>{if(x.key==="Escape"){x.preventDefault(),s(-1);return}if(x.key!=="Tab")return;const y=Array.from(f.querySelectorAll(gD)).filter(D=>D.offsetParent!==null);if(y.length===0){x.preventDefault(),f.focus();return}const N=y[0],w=y[y.length-1],S=document.activeElement;x.shiftKey?(S===N||!f.contains(S))&&(x.preventDefault(),w.focus()):S===w&&(x.preventDefault(),N.focus())};return window.addEventListener("keydown",p),()=>{var x;window.removeEventListener("keydown",p),(x=m==null?void 0:m.focus)==null||x.call(m)}},[s]),c.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto p-4 md:p-6",children:[c.jsx("button",{type:"button",className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>s(-1),"aria-label":"Close modal",tabIndex:-1}),c.jsx("div",{className:"relative z-10 flex min-h-full items-start justify-center",children:c.jsxs("div",{ref:o,role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,className:"surface-panel flex max-h-[calc(100vh-2rem)] w-full max-w-2xl flex-col overflow-hidden p-6 outline-none md:max-h-[calc(100vh-3rem)] md:p-8",children:[c.jsxs("div",{className:"mb-6 flex shrink-0 items-start justify-between gap-4",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-xl font-black tracking-tight text-[var(--text)]",children:t}),a?c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:a}):null]}),c.jsx("button",{ref:u,type:"button",onClick:()=>s(-1),className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-[14px] border border-[var(--border-strong)] text-[var(--text-muted)] transition hover:text-[var(--text)]","aria-label":"Close modal",children:c.jsx(cR,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:l})]})})]})}function Il({className:t="",children:a,...l}){return c.jsx("div",{className:`sticky bottom-0 mt-2 flex justify-end gap-3 border-t border-[var(--border)] bg-[var(--surface)] px-1 pt-4 pb-1 backdrop-blur-xl ${t}`,...l,children:a})}function lt({label:t,children:a}){return c.jsxs("label",{className:"grid gap-2",children:[c.jsx("span",{className:"text-sm font-semibold text-[var(--text-muted)]",children:t}),a]})}function mn(t){return c.jsx("textarea",{className:"field-control field-textarea",...t})}function vD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var o;return(o=l.current)==null?void 0:o.requestSubmit()},[]);return An("submit",s,{allowInEditable:!0}),c.jsx(ql,{title:"Create feature",description:"Top-level container for phases and tasks.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Feature name",children:c.jsx(ma,{name:"name",placeholder:"Products page implementation",required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",placeholder:"Short context for the feature"})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Creating…":"Create feature"})})]})})}function yD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var f;return(f=l.current)==null?void 0:f.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const u=gs("feature-detail").feature;return c.jsx(ql,{title:"Edit feature",description:"Update metadata, planning notes and timeline.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Name",children:c.jsx(ma,{name:"name",defaultValue:u.name,required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",defaultValue:u.description})}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsx(lt,{label:"Start date",children:c.jsx(ma,{type:"date",name:"startDate",defaultValue:u.startDate})}),c.jsx(lt,{label:"End date",children:c.jsx(ma,{type:"date",name:"endDate",defaultValue:u.endDate})})]}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:u.status,children:rd.map(f=>c.jsx("option",{value:f.value,children:f.label},f.value))})}),c.jsx(lt,{label:"Priority",children:c.jsx(ma,{type:"number",name:"priority",defaultValue:u.priority??0,min:0})}),c.jsx(ua,{title:"Planning notes",subtitle:"Optional agent-maintained notes for progress tracking.",defaultOpen:!1,className:"mt-0",children:c.jsxs("div",{className:"grid gap-4",children:[c.jsx(lt,{label:"Work done",children:c.jsx(mn,{name:"workDone",defaultValue:u.workDone})}),c.jsx(lt,{label:"Work remaining",children:c.jsx(mn,{name:"workRemaining",defaultValue:u.workRemaining})})]})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Saving…":"Save feature"})})]})})}function xD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var o;return(o=l.current)==null?void 0:o.requestSubmit()},[]);return An("submit",s,{allowInEditable:!0}),c.jsx(ql,{title:"Create phase",description:"A phase belongs to the current feature.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Phase title",children:c.jsx(ma,{name:"title",placeholder:"API creation",required:!0})}),c.jsx(lt,{label:"Summary",children:c.jsx(mn,{name:"summary",placeholder:"Brief phase summary"})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",placeholder:"Initial implementation notes"})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Creating…":"Create phase"})})]})})}function ni(t){return t.join(`
288
+ `+pe.slice(ce-1);Me.current=Se,K.current=null,ht.current&&(clearTimeout(ht.current),ht.current=null),$.current="input",Bt.current.push({value:Se,cursorPos:ce}),va(Se,!0),Z.current&&vc(Z.current);return}if((j.key==="Backspace"||j.key==="Delete")&&Z.current&&!Z.current.textContent){const ce=Me.current;if(!ce)return;const{start:pe,end:Se}=Rr(Z.current);let Ke,rt;if(pe!==Se)Ke=ce.slice(0,pe)+ce.slice(Se),rt=pe;else if(j.key==="Backspace"&&pe>0)Ke=ce.slice(0,pe-1)+ce.slice(pe),rt=pe-1;else if(j.key==="Delete"&&pe<ce.length)Ke=ce.slice(0,pe)+ce.slice(pe+1),rt=pe;else return;j.preventDefault(),Me.current=Ke,K.current=null,ht.current&&(clearTimeout(ht.current),ht.current=null),$.current="input",Bt.current.push({value:Ke,cursorPos:rt}),al(Z.current,rt),va(Ke,!0),Z.current&&vc(Z.current);return}if(St.current=!1,P.showDropdown&&P.suggestions.length>0)switch(j.key){case"ArrowDown":j.preventDefault(),St.current=!0,We(ce=>ce>=P.suggestions.length-1?0:ce+1);return;case"ArrowUp":j.preventDefault(),St.current=!0,We(ce=>ce<=0?P.suggestions.length-1:ce-1);return;case"PageDown":{j.preventDefault(),St.current=!0;const ce=$a();We(pe=>Math.min(pe+ce,P.suggestions.length-1));return}case"PageUp":{j.preventDefault(),St.current=!0;const ce=$a();We(pe=>Math.max(pe-ce,0));return}case"Home":if(_t&&P.selectedSuggestionIndex>=0){j.preventDefault(),St.current=!0,We(0);return}break;case"End":if(_t&&P.selectedSuggestionIndex>=0){j.preventDefault(),St.current=!0,We(P.suggestions.length-1);return}break;case"Enter":if(P.selectedSuggestionIndex>=0){const ce=P.suggestions[P.selectedSuggestionIndex];if(ce.type==="loading"||ce.type==="error"){j.preventDefault(),an(),l&&l(Me.current,P.ast,j);return}if(ce.type==="hint"&&ce.text!=="#"&&ce.text!=="!"){j.preventDefault(),an();const pe=Me.current,Se=P.cursorOffset;if(Se<=pe.length&&pe[Se]!==" "){const Ke=pe.slice(0,Se),rt=pe.slice(Se),Be=Ke+" "+rt;Ta(Be,Se+1,()=>{l&&l(Be,P.ast,j)})}else l&&l(pe,P.ast,j);return}j.preventDefault(),_r(ce,"Enter",void 0,j);return}j.preventDefault(),an(),l&&l(Me.current,P.ast,j);return;case"Tab":if(z){j.preventDefault();const ce=P.selectedSuggestionIndex>=0?P.suggestions[P.selectedSuggestionIndex]:null,pe=ce&&ce.type!=="loading"&&ce.type!=="error"&&!(ce.type==="hint"&&ce.text!=="#"&&ce.text!=="!")?ce:null,Se=z({suggestion:pe,cursorContext:P.cursorContext||{type:"EMPTY",partial:""},query:Me.current});Se.accept&&pe?_r(pe,"Tab",(Ke,rt)=>{var Be;Se.submit&&l&&l(Ke,rt,j),Se.blur&&((Be=Z.current)==null||Be.blur())},j):(an(),Se.submit&&l&&l(Me.current,P.ast,j),Se.blur&&((xe=Z.current)==null||xe.blur()));return}if(P.selectedSuggestionIndex>=0){const ce=P.suggestions[P.selectedSuggestionIndex];if(ce.type==="hint"&&ce.text!=="#"&&ce.text!=="!"){j.preventDefault(),an();const pe=Me.current,Se=P.cursorOffset;if(Se<=pe.length&&pe[Se]!==" "){const Ke=pe.slice(0,Se),rt=pe.slice(Se),Be=Ke+" "+rt,Nn=Se+1;Ta(Be,Nn,Lt=>{ya(Lt,Nn)})}return}j.preventDefault(),_r(ce,"Tab",void 0,j);return}break;case"Escape":j.preventDefault(),an();return}if(j.key==="Tab"&&z){j.preventDefault();const ce=z({suggestion:null,cursorContext:P.cursorContext||{type:"EMPTY",partial:""},query:Me.current});ce.submit&&l&&l(Me.current,P.ast,j),ce.blur&&((Fe=Z.current)==null||Fe.blur());return}if(P.showDatePicker&&j.key==="Escape"){j.preventDefault(),an();return}if(j.key==="Enter"&&!P.showDropdown&&!P.showDatePicker){j.preventDefault(),l&&l(Me.current,P.ast,j);return}},[l,an,_r,Ta,zr,Qt,ue,de,ya,X,z,Hn,$n,da,_t,$a,Wn]),Ss=v.useCallback(j=>{if(St.current){St.current=!1;return}if(["ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"].includes(j.key)){if(!Z.current)return;const P=Rr(Z.current);Wt(P.start),_n(P.end),na(Dt.current.tokens,P.start,P.end)}},[na]),Jo=v.useCallback(()=>{ga(!0),W==null||W();const j=requestAnimationFrame(()=>{if(nn.current.delete(j),Z.current){const P=Dt.current.tokens,Ee=P.length>0?kl(Z.current):0;Wt(Ee),_n(Ee),na(P,Ee)}});nn.current.add(j)},[Ha,na,W]),ws=v.useCallback(()=>{var j;ga(!1),it(!1),Jt(!1),Ie([]),wn.current=!1,(j=Zt.current)==null||j.abort(),vt.current&&(clearTimeout(vt.current),vt.current=null),Je.current&&(clearTimeout(Je.current),Je.current=null),Wt(-1),ae==null||ae()},[ae]),Ur=v.useRef(!1),Wo=v.useCallback(j=>{if(!Z.current||j.detail!==2&&j.detail!==3)return;if(j.detail===3){if(!Dt.current.ast)return;const Se=document.caretRangeFromPoint(j.clientX,j.clientY);if(!Se)return;const Ke=Mo(Z.current,Se.startContainer,Se.startOffset),rt=DT(Dt.current.ast,Me.current,Ke);if(!rt||rt.start>=rt.end)return;j.preventDefault(),Ur.current=!0,nl(Z.current,rt.start,rt.end);return}j.preventDefault(),Ur.current=!0;const P=document.caretRangeFromPoint(j.clientX,j.clientY);if(!P)return;const Ee=Mo(Z.current,P.startContainer,P.startOffset),xe=Me.current,Fe=Se=>!/[\s:()[\]{}"<>!,;|&=~^+\-*/\\]/.test(Se);let ce=Ee;for(;ce>0&&Fe(xe[ce-1]);)ce--;let pe=Ee;for(;pe<xe.length&&Fe(xe[pe]);)pe++;ce<pe&&nl(Z.current,ce,pe)},[]),aa=v.useCallback(j=>{Ur.current&&(j.preventDefault(),Ur.current=!1)},[]),Br=v.useCallback(()=>{if(!Z.current)return;const j=Rr(Z.current);if(Wt(j.start),_n(j.end),j.start!==j.end){const[P,Ee]=jx(Dt.current.tokens,j.start,j.end);if(P!==Ee){an();return}}na(Dt.current.tokens,j.start,j.end)},[na,an]),Hr=v.useCallback(j=>{Ct.current&&(clearTimeout(Ct.current),Ct.current=null),hC(j),Ha()},[Ha]),Fl=v.useCallback(j=>{j.preventDefault();const P=Nx(j.clipboardData.getData("text/plain"));if(be){const Ee=be(P,j);Ee!=null&&typeof(Ee==null?void 0:Ee.then)=="function"?Ee.then(xe=>{xe!=null&&Hr(xe)}).catch(()=>{}):Ee!=null&&Hr(Ee)}else Hr(P)},[be,Hr]),ud=v.useCallback(j=>{$.current="navigation";const P=Dt.current,Ee=A.current,xe=Ee?Ee.start:P.cursorOffset,Fe=Ee?Ee.end:P.cursorOffset,ce=Me.current.slice(0,xe),pe=Me.current.slice(Fe);let Se="",Ke=pe;te&&j.length>0&&(pe.length===0?Se=" ":/^[ \t\r\n]+$/.test(pe)&&!pe.startsWith("\\ ")&&(Se=" ",Ke=""));const rt=ce+j+Se+Ke,Be=ce.length+j.length+Se.length;Ta(rt,Be,Nn=>{Z.current&&Z.current.focus(),ya(Nn,Be)})},[Ta,ya,te]),ol=Qo(x),Pl=Ko(y),Gl=IT(ol,D),$r={...VT(ol,Pl),...Pn?YT(Pl):{}};yr&&($r.whiteSpace="nowrap",$r.overflow="hidden",$r.textOverflow="ellipsis");const eu=FT(ol,Pl);return v.createElement("div",{ref:gn,style:Gl,className:za("ei-container",w,S==null?void 0:S.container)},v.createElement("div",{ref:Yn,contentEditable:!0,suppressContentEditableWarning:!0,className:za("ei-editor",S==null?void 0:S.editor),style:$r,onInput:Ha,onKeyDown:wi,onKeyUp:Ss,onMouseDown:Wo,onMouseUp:aa,onFocus:Jo,onBlur:ws,onClick:Br,onPaste:Fl,onCompositionStart:ar,onCompositionEnd:Si,spellCheck:!1}),sl&&!Pn?v.createElement("div",{className:za("ei-placeholder",S==null?void 0:S.placeholder),style:eu},N):null,v.createElement(fC,{errors:On,editorRef:Tt,cursorOffset:Nt,colors:x,styles:y,containerRef:gn.current,classNames:S?{squiggly:S.squiggly,tooltip:S.tooltip}:void 0}),v.createElement(rC,{suggestions:Ze,selectedIndex:$t,onSelect:j=>_r(j,"Tab"),position:Fn,colors:x,styles:y,visible:ct,fixedWidth:Zo(),renderHistoryItem:oe,renderSavedSearchItem:$e,renderDropdownHeader:at,cursorContext:ja,listRefCallback:j=>{Ba.current=j},renderType:pn,classNames:S?{dropdown:S.dropdown,dropdownHeader:S.dropdownHeader,dropdownItem:S.dropdownItem}:void 0}),dt&&Fn?v.createElement(MC,{position:Fn,colors:ol,onSelect:ud,colorConfig:x,styleConfig:y,datePickerInit:Vl,fixedWidth:void 0,datePresets:q,datePickerClassName:S==null?void 0:S.datePicker}):null)}const LC=["planned","in-progress","done","blocked","canceled","rejected","deferred","waiting"];function Hx(t){var o;const a=window.getSelection();if(!a||a.rangeCount===0)return((o=t.textContent)==null?void 0:o.length)??0;const l=a.getRangeAt(0),s=l.cloneRange();return s.selectNodeContents(t),s.setEnd(l.endContainer,l.endOffset),s.toString().length}function zC(t){return a=>{if(!(a.ctrlKey&&!a.metaKey&&!a.altKey))return;const l=a.key.toLowerCase(),s=a.currentTarget,o=s.isContentEditable?s:s.querySelector("[contenteditable='true'], [contenteditable]")??s,u=t.current;if(l==="h"&&u){a.preventDefault();const m=u.getValue();let p=Hx(o);(p<0||p>m.length)&&(p=m.length),p>0&&(u.setValue(m.slice(0,p-1)+m.slice(p)),u.setSelection(p-1,p-1));return}if(l==="u"&&u){a.preventDefault();const m=u.getValue();let p=Hx(o);if((p<0||p>m.length)&&(p=m.length),p===0)return;let g=p;for(;g>0&&/\s/.test(m[g-1]??"");)g--;if(g===p)for(;g>0&&!/\s/.test(m[g-1]??"");)g--;g<p&&(u.setValue(m.slice(0,g)+m.slice(p)),u.setSelection(g,g));return}const f=l==="j"?"ArrowDown":l==="k"?"ArrowUp":null;f&&(a.preventDefault(),o.dispatchEvent(new KeyboardEvent("keydown",{key:f,bubbles:!0,cancelable:!0})))}}function Uh(t){return String(t>0?t:0).padStart(3,"0")}function UC({features:t,phases:a,query:l,onQuery:s}){const o=v.useRef(null),u=zC(o),f=v.useMemo(()=>[{name:"feature",label:"Feature",type:"number",description:"Feature number, e.g. 1 (F001)"},{name:"phase",label:"Phase",type:"number",description:"Phase number, e.g. 2 (P002)"},{name:"task",label:"Task",type:"number",description:"Task number, e.g. 10 (T010). Comma-list supported."},{name:"id",label:"Short ID",type:"string",description:"Global 5-char short id, e.g. UUXD1"},{name:"status",label:"Status",type:"string",description:"Task status"},{name:"feature-status",label:"Feature status",type:"string",description:"Status of the feature"},{name:"phase-status",label:"Phase status",type:"string",description:"Status of the phase"},{name:"title",label:"Title",type:"string",description:"Substring match on title"}],[]),m=v.useMemo(()=>{const y=[...new Set(t.map(R=>R.number))].sort((R,L)=>R-L),N=[...new Set(a.map(R=>R.number))].sort((R,L)=>R-L),w=[...new Set(a.flatMap(R=>R.tasks.map(L=>L.number)))].sort((R,L)=>R-L),S=[...new Set([...t.map(R=>R.shortId),...a.flatMap(R=>[R.shortId,...R.tasks.map(L=>L.shortId)])].filter(Boolean))],D=[...new Set(a.flatMap(R=>R.tasks.map(L=>L.title)))];return{featureNums:y,phaseNums:N,taskNums:w,shortIds:S,titles:D}},[t,a]),p=v.useCallback(async(y,N)=>{const w=N.toLowerCase();return y==="feature"?m.featureNums.filter(S=>String(S).startsWith(N)).slice(0,20).map(S=>({text:String(S),label:`F${Uh(S)}`})):y==="phase"?m.phaseNums.filter(S=>String(S).startsWith(N)).slice(0,20).map(S=>({text:String(S),label:`P${Uh(S)}`})):y==="task"?m.taskNums.filter(S=>String(S).startsWith(N)).slice(0,20).map(S=>({text:String(S),label:`T${Uh(S)}`})):y==="id"?m.shortIds.filter(S=>S.toLowerCase().startsWith(w)).slice(0,20).map(S=>({text:S,label:S})):y==="status"||y==="feature-status"||y==="phase-status"?LC.filter(S=>S.startsWith(w)).map(S=>({text:S,label:S})):y==="title"?m.titles.filter(S=>S.toLowerCase().includes(w)).slice(0,20).map(S=>({text:S,label:S.length>44?S.slice(0,44)+"…":S})):[]},[m]),g=v.useCallback(y=>s(y),[s]),x=v.useCallback(y=>{o.current=y},[]);return c.jsx("div",{className:"search-bar",children:c.jsx(_C,{fields:f,value:l,onChange:g,onSearch:g,fetchSuggestions:p,onKeyDown:u,inputRef:x,placeholder:"Search Work Tree… e.g. feature:1 id:UUXD1 title:auth status:in-progress"})})}function BC(t,a){if(Object.keys(a).length===0)return t;const l=u=>{const f=a[u];return f?new Map(f.map((m,p)=>[m,p])):null},s=l("__features__");return(s?[...t].sort((u,f)=>(s.get(u.feature.id)??1/0)-(s.get(f.feature.id)??1/0)):t).map(u=>{const f=l(`phase-scope:${u.feature.id}`),m=f?[...u.allPhases].sort((p,g)=>(f.get(p.phase.id)??1/0)-(f.get(g.phase.id)??1/0)):u.allPhases;return{...u,allPhases:m.map(p=>{const g=l(`task-scope:${p.phase.id}`),x=g?[...p.allTasks].sort((y,N)=>(g.get(y.id)??1/0)-(g.get(N.id)??1/0)):p.allTasks;return{...p,allTasks:x}})}})}function ti({active:t=!1,disabled:a=!1,onClick:l,children:s}){return c.jsx("button",{type:"button",disabled:a,onClick:l,className:`inline-flex h-8 min-h-8 w-full items-center justify-center rounded-[10px] border px-2.5 py-1 text-xs font-semibold transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--accent)] ${t?"border-transparent bg-[var(--accent)] text-white":"border-[var(--border)] bg-[var(--surface-card)] text-[var(--text-muted)] hover:bg-[var(--accent-soft)] hover:text-[var(--text)]"} ${a?"cursor-not-allowed opacity-60":""}`,children:s})}function HC({features:t,phases:a,activeTasks:l,projectStorageScope:s}){const o=NT({features:t,phases:a,projectStorageScope:s}),[u,f]=v.useState({});v.useEffect(()=>{f({})},[o.displayedWorkTree]);const m=v.useMemo(()=>BC(o.displayedWorkTree,u),[o.displayedWorkTree,u]),[p,g]=v.useState(!1),[x,y]=v.useState(null),[N,w]=v.useState(null),S=te=>w(String(te.active.id)),[D,R]=v.useState(0);v.useEffect(()=>{const te=document.querySelector("header");if(!te)return;const re=()=>R(te.offsetHeight);re();const ge=new ResizeObserver(re);return ge.observe(te),window.addEventListener("resize",re),()=>{ge.disconnect(),window.removeEventListener("resize",re)}},[]),v.useEffect(()=>{const te=window.setTimeout(()=>{const re=document.querySelector(".ap-search-sticky"),ge=document.querySelector("header");if(!re||!ge)return;const U=re.getBoundingClientRect();if(U.top<0){const B=U.top+window.scrollY-ge.offsetHeight;window.scrollTo({top:Math.max(0,B),behavior:"smooth"})}},60);return()=>window.clearTimeout(te)},[o.searchQuery,o.hideDone,o.hidePlanned,o.onlyActiveBranches]);const L=$2(H2(Cm,{activationConstraint:{distance:5}})),I=async te=>{const{active:re,over:ge}=te;if(w(null),!ge||re.id===ge.id)return;const U=String(re.id),B=String(ge.id),ue=m.map(de=>de.feature.id);if(ue.includes(U)&&ue.includes(B)){const de=To(ue,ue.indexOf(U),ue.indexOf(B)),we=de.indexOf(U),C=we>0?de[we-1]??null:null,V=we<de.length-1?de[we+1]??null:null;f(ne=>({...ne,__features__:de})),await bh("feature",U,C,V).catch(()=>{});return}for(const de of m){const we=de.allPhases.map(C=>C.phase.id);if(we.includes(U)&&we.includes(B)){const C=To(we,we.indexOf(U),we.indexOf(B)),V=C.indexOf(U),ne=V>0?C[V-1]??null:null,me=V<C.length-1?C[V+1]??null:null;f(Ne=>({...Ne,[`phase-scope:${de.feature.id}`]:C})),await bh("phase",U,ne,me).catch(()=>{});return}}for(const de of m)for(const we of de.allPhases){const C=we.allTasks.map(V=>V.id);if(C.includes(U)&&C.includes(B)){const V=To(C,C.indexOf(U),C.indexOf(B)),ne=V.indexOf(U),me=ne>0?V[ne-1]??null:null,Ne=ne<V.length-1?V[ne+1]??null:null;f(je=>({...je,[`task-scope:${we.phase.id}`]:V})),await bh("task",U,me,Ne).catch(()=>{});return}}},q=te=>o.expandedPhaseIds.includes(te),X=te=>o.recentPhaseIds.includes(te),W=te=>o.recentTaskIds.includes(te),[ae,z]=$o(),[T,ee]=v.useState(null),fe=ae.get("locate"),be=fe?parseInt(fe.replace(/^T/i,""),10):null;v.useEffect(()=>{if(be==null||Number.isNaN(be))return;const te=a.flatMap(B=>B.tasks.map(ue=>({t:ue,p:B}))).find(({t:B})=>B.number===be);if(!te){z(B=>(B.delete("locate"),B),{replace:!0});return}const{t:re,p:ge}=te;if(o.onlyActiveBranches&&o.setOnlyActiveBranches(!1),o.hideDone&&o.setHideDone(!1),o.searchQuery&&o.setSearchQuery(""),o.setTreeOpenMode("smart"),ge.featureId){const B=ge.featureId;o.expandedFeatureIds.includes(B)||o.setExpandedFeatureIds(ue=>ue.includes(B)?ue:[...ue,B])}o.expandedPhaseIds.includes(ge.id)||o.setExpandedPhaseIds(B=>B.includes(ge.id)?B:[...B,ge.id]);const U=document.getElementById(`task-row-${be}`);if(U){const B=document.querySelector("header"),ue=document.querySelector(".ap-search-sticky"),de=((B==null?void 0:B.offsetHeight)??0)+((ue==null?void 0:ue.offsetHeight)??0)+12,we=U.getBoundingClientRect().top+window.scrollY-de;window.scrollTo({top:Math.max(0,we),behavior:"smooth"}),ee(re.id);const C=window.setTimeout(()=>ee(null),2500);return z(V=>(V.delete("locate"),V),{replace:!0}),()=>window.clearTimeout(C)}},[be,a,o.expandedFeatureIds,o.expandedPhaseIds,o.onlyActiveBranches,o.hideDone,o.searchQuery,o.treeOpenMode]);const ye=()=>{if(!N)return null;for(const te of m){if(te.feature.id===N)return c.jsxs("div",{className:"ap-drag-overlay surface-card min-w-0 max-w-md px-3 py-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:te.feature.number}),c.jsx(ur,{status:te.feature.status})]}),c.jsx("div",{className:"mt-1 break-words font-mono text-sm font-semibold [overflow-wrap:anywhere]",children:te.feature.name})]});for(const re of te.allPhases){if(re.phase.id===N)return c.jsxs("div",{className:"ap-drag-overlay surface-card min-w-0 max-w-md px-3 py-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:te.feature.number,phaseNum:re.phase.number}),c.jsx(ur,{status:re.phase.status})]}),c.jsx("div",{className:"mt-1 break-words font-mono text-sm font-semibold [overflow-wrap:anywhere]",children:re.phase.title})]});for(const ge of re.allTasks)if(ge.id===N)return c.jsxs("div",{className:"ap-drag-overlay surface-card min-w-0 max-w-md px-3 py-2",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:te.feature.number,phaseNum:re.phase.number,taskNum:ge.number}),c.jsx(ur,{status:ge.status})]}),c.jsx("div",{className:"mt-1 break-words font-mono text-sm font-semibold [overflow-wrap:anywhere]",children:ge.title})]})}}return null};return c.jsxs(Pt,{className:"grid gap-4",children:[c.jsx("div",{className:"flex flex-col gap-3 md:flex-row md:items-start md:justify-between",children:c.jsxs("div",{children:[c.jsx("h2",{className:"text-lg font-bold text-[var(--text)]",children:"Work Tree"}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Collapsible feature → phase → task tree. Click a feature or phase row to collapse/expand."})]})}),c.jsxs("div",{className:"ap-search-sticky z-20 grid gap-3",style:{top:D},children:[c.jsx(UC,{features:t,phases:a,query:o.searchQuery,onQuery:o.setSearchQuery}),c.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[c.jsx(Om,{sort:o.sort,onChange:o.setSort}),o.searchActive?c.jsxs("p",{className:"text-xs text-[var(--text-muted)]",children:[o.matchedTaskIds.size," match",o.matchedTaskIds.size===1?"":"es"," — clear the box to reset."]}):null]}),c.jsxs("div",{className:"grid grid-cols-2 gap-2 rounded-[14px] border border-[var(--border)] bg-[var(--surface-card)] px-3 py-2 sm:grid-cols-3 sm:rounded-[18px] sm:px-4 sm:py-3 lg:grid-cols-6",children:[c.jsx(ti,{active:o.isAllExpanded,onClick:()=>o.isAllExpanded?o.collapseAll():o.expandAll(),children:o.isAllExpanded?"Collapse all":"Expand all"}),c.jsx(ti,{active:o.hideDone,onClick:()=>o.setHideDone(te=>!te),children:"Hide done"}),c.jsx(ti,{active:o.hidePlanned,onClick:()=>o.setHidePlanned(te=>!te),children:"Hide planned"}),c.jsx(ti,{active:o.onlyActiveBranches,onClick:()=>o.setOnlyActiveBranches(te=>!te),children:"Only active"}),c.jsx(ti,{onClick:o.resetFilters,children:"Reset"}),c.jsx(ti,{disabled:p,onClick:async()=>{g(!0),y(null);try{const te=await TR(),re=te.migrated,ge=te.integrity.duplicatePhaseIds.length,U=te.integrity.danglingPhaseIds.length;y(`Repair done: renamed ${re.renamed}, repaired ${re.repaired} refs, inferred ${re.inferred}, archived ${te.handoffs.archived} stale handoff(s). Integrity: ${ge} duplicate, ${U} dangling.`)}catch(te){y(`Repair failed: ${te instanceof Error?te.message:String(te)}`)}finally{g(!1)}},children:p?"Repairing…":"Repair"}),x?c.jsx("span",{className:"hidden text-xs text-[var(--text-muted)] sm:inline sm:truncate",children:x}):null]})]}),c.jsx("div",{className:"grid gap-3",children:m.length>0?c.jsxs($j,{sensors:L,collisionDetection:P2,onDragStart:S,onDragEnd:I,children:[c.jsx(km,{items:m.map(te=>te.feature.id),strategy:Am,children:m.map(te=>c.jsx(Mm,{id:te.feature.id,children:c.jsx(jT,{entry:te,expanded:o.expandedFeatureIds.includes(te.feature.id),recentlyChanged:o.recentFeatureIds.includes(te.feature.id),onToggle:()=>o.toggleExpandedFeature(te.feature.id),isPhaseExpanded:q,onTogglePhase:o.toggleExpandedPhase,isPhaseRecentlyChanged:X,isTaskRecentlyChanged:W,highlightedTaskIds:(()=>{const re=o.searchActive?o.matchedTaskIds:void 0;if(!T)return re;const ge=new Set(re??[]);return ge.add(T),ge})()})},te.feature.id))}),c.jsx(lT,{dropAnimation:{duration:150,easing:"ease"},children:ye()})]}):l.length>0?l.map(te=>{const re=te.featureId?`/features/${te.featureId}/phases/${te.phaseId}/tasks/${te.id}`:"/features";return c.jsxs(Ye,{to:re,className:"surface-card grid gap-1 px-4 py-3 transition hover:border-[var(--accent)] hover:bg-[var(--accent-soft)]",children:[c.jsxs("div",{className:"flex items-center justify-between gap-2",children:[c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2 truncate text-sm font-semibold text-[var(--text)]",children:[te.status==="in-progress"?c.jsx("span",{"aria-hidden":"true",className:"ap-progress-dot"}):null,c.jsxs("span",{className:"truncate",children:["T",S2(te.number)," — ",te.title]})]}),c.jsx(ur,{status:te.status})]}),c.jsx("div",{className:"text-[10px] uppercase tracking-wider text-[var(--text-muted)]",children:te.phaseId})]},te.id)}):c.jsx("p",{className:"py-4 text-center text-sm text-[var(--text-muted)]",children:"No work items match the current filters."})})]})}function $C(){const{features:t,phases:a,activeTasks:l}=ll(),{project:s}=gs("root"),o=kr(),u=()=>o("/project/edit");An("edit",u);const f=s.projectRoot||s.planRoot||s.name||"default";return c.jsxs("div",{className:"grid grid-cols-1 gap-8",children:[c.jsxs(Pt,{className:"grid grid-cols-1 gap-4",children:[c.jsxs("div",{className:"flex items-center justify-between gap-4",children:[c.jsx("h2",{className:"min-w-0 text-lg font-bold text-[var(--text)]",children:"Project Goal"}),c.jsxs(gt,{type:"button",shortcut:"edit",onClick:u,className:"shrink-0",children:[c.jsx(ms,{className:"h-4 w-4"}),"Edit project"]})]}),s.goal?c.jsx(xn,{text:s.goal,className:"max-w-4xl"}):c.jsx("p",{className:"max-w-4xl text-sm text-[var(--text-muted)]",children:"Add a project goal to define the main objective."})]}),c.jsx(r2,{project:s}),c.jsx(N2,{features:t,phases:a}),c.jsx(HC,{features:t,phases:a,activeTasks:l,projectStorageScope:f}),c.jsx(c2,{features:t,phases:a}),c.jsx(f2,{features:t,phases:a})]})}async function qC(){const[t,a]=await Promise.all([Vb(),Kc()]);return{features:t,phases:a}}function _o(){return{active:0,planned:0,done:0,blocked:0,canceled:0}}function Bc(t){const a=[];return t.active&&a.push(`${t.active} active`),t.planned&&a.push(`${t.planned} planned`),t.done&&a.push(`${t.done} done`),t.blocked&&a.push(`${t.blocked} blocked`),t.canceled&&a.push(`${t.canceled} canceled`),a.join(" · ")}function IC(t){const a=_o();for(const l of t){if(l.status==="in-progress"||l.status==="discovery"){a.active+=1;continue}if(l.status==="planned"||l.status==="draft"){a.planned+=1;continue}if(l.status==="done"){a.done+=1;continue}if(l.status==="blocked"){a.blocked+=1;continue}l.status==="canceled"&&(a.canceled+=1)}return a}function I0(t){const a=_o();for(const l of t){if(l.status==="in-progress"){a.active+=1;continue}if(l.status==="planned"){a.planned+=1;continue}if(l.status==="done"){a.done+=1;continue}if(l.status==="blocked"){a.blocked+=1;continue}l.status==="canceled"&&(a.canceled+=1)}return a}function VC(t){const a=_o();for(const l of t){if(l.status==="in-progress"){a.active+=1;continue}if(l.status==="planned"){a.planned+=1;continue}if(l.status==="done"){a.done+=1;continue}if(l.status==="blocked"){a.blocked+=1;continue}l.status==="canceled"&&(a.canceled+=1)}return a}function YC({feature:t,phases:a,phasesCount:l,tasksCount:s,phaseSummary:o,taskSummary:u,activity:f}){var L;const m=hs(),p=hs(),x=((L=m.formData)==null?void 0:L.get("status"))??t.status,y=m.state!=="idle",N=p.state!=="idle",w=Bc(o),S=Bc(u),D=s0(a??[]),R=t.description||(f?`${f.doneTasks}/${s} done · ${f.remainingTasks} left${f.blockedTasks?` · ${f.blockedTasks} blocked`:""}`:"");return c.jsxs(vi,{variant:"surface",status:D.displayStatus,className:"px-4 py-2",children:[c.jsxs("div",{className:"grid gap-2 xl:grid-cols-[minmax(0,1fr)_minmax(0,132px)_minmax(0,152px)_124px_44px_44px] xl:items-center",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1 xl:contents",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(cr,{featureNum:t.number,featureId:t.id}),c.jsx(mr,{id:Bl({featureNum:t.number}),children:c.jsx("span",{className:"sr-only",children:"Copy feature path"})}),t.shortId?c.jsx(Hl,{shortId:t.shortId}):null,c.jsx("span",{className:"shrink-0",children:c.jsx(Vo,{status:D.displayStatus,breakdown:D.breakdown})})]}),c.jsx(Ye,{to:`/features/${t.id}`,className:"entity-link--feature min-w-0 w-full break-words text-sm font-semibold underline-offset-4 hover:underline [overflow-wrap:anywhere]",children:t.name})]}),c.jsxs("div",{className:"flex items-center gap-2 self-end xl:hidden",children:[c.jsx(Ye,{to:`/features/${t.id}/edit`,"aria-label":`Edit feature ${t.name}`,children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(p.Form,{method:"post",action:`/features/${t.id}/delete`,onSubmit:I=>{window.confirm(`Delete feature “${t.name}”? This cannot be undone.`)||I.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:N||y,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete feature ${t.name}`,children:c.jsx(di,{className:"h-4 w-4"})})})]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[l," phases"]}),w?c.jsx("div",{className:"mt-0.5 break-words",children:w}):null]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[s," tasks"]}),S?c.jsx("div",{className:"mt-0.5 break-words",children:S}):null]}),c.jsx(m.Form,{method:"post",action:`/features/${t.id}/status`,className:"w-full xl:w-auto",children:c.jsxs("div",{className:"relative",children:[c.jsx("select",{name:"status",value:x,disabled:y||N,"aria-busy":y,className:"field-control min-h-8 appearance-none py-1 pr-8 text-[11px]",onChange:I=>m.submit(I.currentTarget.form),children:rd.map(I=>c.jsx("option",{value:I.value,children:I.label},I.value))}),c.jsx(vs,{className:"pointer-events-none absolute right-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-[var(--text-muted)]"})]})}),c.jsx(Ye,{to:`/features/${t.id}/edit`,"aria-label":`Edit feature ${t.name}`,className:"hidden xl:block",children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(p.Form,{method:"post",action:`/features/${t.id}/delete`,className:"hidden xl:block",onSubmit:I=>{window.confirm(`Delete feature “${t.name}”? This cannot be undone.`)||I.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:N||y,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete feature ${t.name}`,children:c.jsx(di,{className:"h-4 w-4"})})})]}),R?c.jsx("div",{className:"mt-1 min-w-0 break-words line-clamp-2 text-[11px] text-[var(--text-muted)]",children:R}):null]})}const FC={feature:{label:"Feature",Icon:Cc},phase:{label:"Phase",Icon:$N},task:{label:"Task",Icon:qo},requirement:{label:"Requirement",Icon:$b}};function V0({kind:t,label:a}){const{Icon:l,label:s}=FC[t];return c.jsxs("span",{className:`entity-badge entity-badge--${t}`,children:[c.jsx(l,{className:"h-3.5 w-3.5"}),c.jsx("span",{children:a??s})]})}function ma({className:t="",...a}){return c.jsx("input",{className:`field-control ${t}`,...a})}function ys({className:t="",...a}){return c.jsx("select",{className:`field-control ${t}`,...a})}function sd({query:t,status:a,statusOptions:l,placeholder:s,clearTo:o,resultsLabel:u}){const f=mm(),m=((l==null?void 0:l.length)??0)>0;return c.jsxs(ca,{method:"get",className:`surface-card grid gap-3 p-3 md:items-end sm:p-4 ${m?"md:grid-cols-[minmax(0,1fr)_200px_auto_auto]":"md:grid-cols-[minmax(0,1fr)_auto_auto]"}`,children:[c.jsxs("div",{children:[c.jsx("label",{htmlFor:"list-filter-query",className:"mb-1 block text-xs font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Name"}),c.jsx(ma,{id:"list-filter-query",name:"q",defaultValue:t,placeholder:s,className:"min-h-9 py-2 sm:min-h-11 sm:py-2.5",onChange:p=>f(p.currentTarget.form)})]}),m?c.jsxs("div",{children:[c.jsx("label",{htmlFor:"list-filter-status",className:"mb-1 block text-xs font-semibold uppercase tracking-[0.18em] text-[var(--text-subtle)]",children:"Status"}),c.jsxs("div",{className:"relative",children:[c.jsxs(ys,{id:"list-filter-status",name:"status",defaultValue:a,className:"min-h-9 appearance-none py-2 sm:min-h-11 sm:py-2.5 pr-8",children:[c.jsx("option",{value:"",children:"All statuses"}),l==null?void 0:l.map(p=>c.jsx("option",{value:p.value,children:p.label},p.value))]}),c.jsx(vs,{className:"pointer-events-none absolute right-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[var(--text-muted)]"})]})]}):null,c.jsx(gt,{type:"submit",variant:"secondary",children:"Apply filters"}),c.jsx(Ye,{to:o,className:"inline-flex min-h-9 items-center justify-center rounded-[12px] px-3 text-sm font-semibold text-[var(--text-muted)] transition hover:bg-[var(--accent-soft)] hover:text-[var(--text)] sm:min-h-11 sm:rounded-[14px]",children:"Clear"}),c.jsx("div",{className:`text-sm text-[var(--text-muted)] ${m?"md:col-span-4":"md:col-span-3"}`,children:u})]})}function id(t,a){const l=t.trim().toLowerCase();return l?a.some(s=>s==null?void 0:s.toLowerCase().includes(l)):!0}function PC(t){const a=new Map;for(const f of t)f.featureId&&a.set(f.featureId,[...a.get(f.featureId)??[],f]);const l=new Map,s=new Map,o=new Map,u=new Map;for(const[f,m]of a)l.set(f,m.length),s.set(f,m.reduce((p,g)=>p+g.tasks.length,0)),o.set(f,IC(m)),u.set(f,I0(m.flatMap(p=>p.tasks)));return{phasesByFeature:a,phasesCountByFeature:l,tasksCountByFeature:s,phaseSummaryByFeature:o,taskSummaryByFeature:u}}function GC(){var w,S;const{features:t,phases:a}=ll(),{phasesByFeature:l,phasesCountByFeature:s,tasksCountByFeature:o,phaseSummaryByFeature:u,taskSummaryByFeature:f}=PC(a),m=kr(),[p]=$o(),g=((w=p.get("q"))==null?void 0:w.trim())??"",x=((S=p.get("status"))==null?void 0:S.trim())??"",y=v.useCallback(()=>m("new"),[m]);An("create",y);const N=v.useMemo(()=>t.filter(D=>(!x||D.status===x)&&id(g,[D.name,D.id,D.description])),[t,g,x]);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Pt,{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[c.jsxs("div",{children:[c.jsx(V0,{kind:"feature",label:"Features"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Filter by name or status, then inspect child phases and tasks directly from the rows."})]}),c.jsx(Ye,{to:"new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create feature"})})]}),c.jsx(sd,{query:g,status:x,statusOptions:rd,placeholder:"Search feature name, id, or description",clearTo:"/features",resultsLabel:N.length===t.length?`${t.length} features`:`${N.length} of ${t.length} features`}),c.jsx("div",{className:"grid gap-3",children:t.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No features yet. ",c.jsx(Ye,{to:"/features/new",className:"font-semibold text-[var(--accent)] hover:underline",children:"Create your first feature"})]}):N.length>0?N.map(D=>c.jsx(YC,{feature:D,phases:l.get(D.id),phasesCount:s.get(D.id)??0,tasksCount:o.get(D.id)??0,phaseSummary:u.get(D.id)??_o(),taskSummary:f.get(D.id)??_o()},D.id)):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No features match the current filters."})})]}),c.jsx(hi,{})]})}async function XC(){const[t,a]=await Promise.all([vm(),Kc()]);return{requirements:t,phases:a}}function vo(...t){return t.filter(Boolean).join(" ")}function QC(){return c.jsx("span",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-[var(--border-strong)] bg-[var(--surface-elevated)] text-[var(--text)] shadow-sm transition group-open:rotate-180 group-hover:border-[var(--accent)] group-hover:text-[var(--accent)]",children:c.jsx(vs,{className:"h-5 w-5"})})}function ua({title:t,subtitle:a,leading:l,actions:s,defaultOpen:o=!0,count:u,className:f,summaryClassName:m,contentClassName:p,titleClassName:g,subtitleClassName:x,children:y}){return c.jsxs("details",{className:vo("group mt-4 overflow-hidden rounded-[10px] border border-[var(--border)]",f),open:o,children:[c.jsxs("summary",{className:vo("flex min-w-0 list-none cursor-pointer items-start justify-between gap-3 bg-[var(--surface-elevated)] p-4 text-left text-[var(--text)] transition-colors select-none hover:bg-[var(--surface-strong)] [&::-webkit-details-marker]:hidden",m),children:[c.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[l?c.jsx("div",{className:"shrink-0 pt-0.5",children:l}):null,c.jsxs("div",{className:"min-w-0 flex-1",children:[c.jsxs("div",{className:vo("flex flex-wrap items-center gap-2 text-sm font-semibold",g),children:[t,u!==void 0?c.jsxs("span",{className:"text-[var(--text-subtle)]",children:["(",u,")"]}):null]}),a?c.jsx("div",{className:vo("mt-2 text-sm text-[var(--text-muted)] [overflow-wrap:anywhere]",x),children:a}):null]})]}),c.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[s,c.jsx(QC,{})]})]}),c.jsx("div",{className:vo("border-t border-[var(--border)] bg-[var(--surface)] p-4",p),children:y})]})}function KC(t,a){const l=new Set(a.map(u=>u.id)),s=a.map(u=>({phase:u,requirements:t.filter(f=>f.linkedPhaseIds.includes(u.id))})).filter(u=>u.requirements.length>0).sort((u,f)=>u.phase.priority-f.phase.priority||u.phase.number-f.phase.number),o=t.filter(u=>!u.linkedPhaseIds.some(f=>l.has(f)));return{phaseGroups:s,unlinkedRequirements:o}}function $x(t){return`P${String(t.number??0).padStart(3,"0")}`}function qx({requirement:t}){return c.jsx(Pt,{className:"overflow-hidden p-0",children:c.jsx(ua,{defaultOpen:!1,title:c.jsx("h2",{className:"min-w-0 text-lg font-black tracking-tight text-[var(--text)] [overflow-wrap:anywhere]",children:t.title}),count:t.linkedPhaseIds.length,subtitle:c.jsxs(c.Fragment,{children:[c.jsxs("span",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:[t.linkedPhaseIds.length," linked phase",t.linkedPhaseIds.length===1?"":"s"]}),t.linkedPhaseIds.length>0&&t.macroTasks.length>0?c.jsx("span",{className:"mx-2 text-[var(--text-subtle)]",children:"•"}):null,t.macroTasks.length>0?c.jsxs("span",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:[t.macroTasks.length," macro task",t.macroTasks.length===1?"":"s"]}):null]}),contentClassName:"grid gap-4",summaryClassName:"hover:bg-[var(--surface-elevated)]/65",children:c.jsxs("div",{className:"flex min-w-0 flex-col gap-3 md:flex-row md:items-start md:justify-between",children:[c.jsx("div",{className:"min-w-0",children:t.description?c.jsx("p",{className:"min-w-0 text-sm text-[var(--text-muted)] [overflow-wrap:anywhere]",children:t.description}):null}),c.jsxs("div",{className:"flex flex-wrap items-center gap-2 md:justify-end",children:[c.jsx(Ye,{to:`${t.id}/edit`,children:c.jsx(gt,{type:"button",variant:"secondary",children:"Edit"})}),c.jsx(ca,{method:"post",action:`/requirements/${t.id}/delete`,onSubmit:a=>{window.confirm(`Delete requirement "${t.title}"?`)||a.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",children:"Delete"})})]})]})})})}function ZC(){var x;const{requirements:t,phases:a}=ll(),l=kr(),[s]=$o(),o=((x=s.get("q"))==null?void 0:x.trim())??"",u=v.useCallback(()=>l("new"),[l]);An("create",u);const f=v.useMemo(()=>new Map(a.map(y=>[y.id,y])),[a]),m=v.useMemo(()=>t.filter(y=>{const N=y.linkedPhaseIds.map(w=>{const S=f.get(w);return S?`${$x(S)} ${S.title} ${S.summary}`:w});return id(o,[y.title,y.description,y.id,...N])}),[t,f,o]),{phaseGroups:p,unlinkedRequirements:g}=v.useMemo(()=>KC(m,a),[m,a]);return v.useEffect(()=>{const y=window.location.hash.slice(1);y&&requestAnimationFrame(()=>{var N;return(N=document.getElementById(y))==null?void 0:N.scrollIntoView({block:"start"})})},[p]),c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Pt,{className:"flex flex-col gap-4 md:flex-row md:items-center md:justify-between",children:[c.jsxs("div",{children:[c.jsx(V0,{kind:"requirement",label:"Requirements"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Track top-level outcomes independently from features, grouped below by the phases that deliver them."})]}),c.jsx(Ye,{to:"new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create requirement"})})]}),c.jsx(sd,{query:o,placeholder:"Search requirement title, description, id, or linked phase",clearTo:"/requirements",resultsLabel:m.length===t.length?`${t.length} requirements`:`${m.length} of ${t.length} requirements`}),c.jsx("div",{className:"grid gap-6",children:t.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No requirements yet. ",c.jsx(Ye,{to:"/requirements/new",className:"font-semibold text-[var(--accent)] hover:underline",children:"Create your first requirement"})]}):m.length>0?c.jsxs(c.Fragment,{children:[p.map(({phase:y,requirements:N})=>{const w=y.featureId?`/features/${y.featureId}/phases/${y.id}`:"/features";return c.jsxs("section",{id:`phase-${y.id}`,className:"scroll-mt-28","aria-labelledby":`phase-${y.id}-heading`,children:[c.jsxs("div",{className:"mb-3 flex min-w-0 flex-wrap items-center justify-between gap-2",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:"Linked phase"}),c.jsxs(Ye,{id:`phase-${y.id}-heading`,to:w,className:"min-w-0 break-words text-base font-black text-[var(--text)] underline-offset-4 hover:text-[var(--accent)] hover:underline [overflow-wrap:anywhere]",children:[$x(y)," — ",y.title]})]}),c.jsxs("span",{className:"shrink-0 rounded-full bg-[var(--surface-elevated)] px-2.5 py-1 text-xs font-semibold text-[var(--text-muted)]",children:[N.length," requirement",N.length===1?"":"s"]})]}),c.jsx("div",{className:"grid gap-3",children:N.map(S=>c.jsx(qx,{requirement:S},S.id))})]},y.id)}),g.length>0?c.jsxs("section",{id:"unlinked-requirements",className:"scroll-mt-28","aria-labelledby":"unlinked-requirements-heading",children:[c.jsxs("div",{className:"mb-3 flex min-w-0 flex-wrap items-center justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:"Unlinked"}),c.jsx("h2",{id:"unlinked-requirements-heading",className:"text-base font-black text-[var(--text)]",children:"Requirements without a valid phase"})]}),c.jsx("span",{className:"shrink-0 rounded-full bg-[var(--surface-elevated)] px-2.5 py-1 text-xs font-semibold text-[var(--text-muted)]",children:g.length})]}),c.jsx("div",{className:"grid gap-3",children:g.map(y=>c.jsx(qx,{requirement:y},y.id))})]}):null]}):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No requirements match the current filters."})})]}),c.jsx(hi,{})]})}async function JC({params:t}){const a=t.featureId;if(!a)throw new Response("featureId required",{status:400});const[l,s]=await Promise.all([Io(a),Kc(a)]);return{feature:l,phases:s}}function WC({featureId:t,feature:a,phase:l}){var y,N;const s=hs(),o=hs(),f=((y=s.formData)==null?void 0:y.get("status"))??l.status,m=s.state!=="idle",p=o.state!=="idle",g=Bc(I0(l.tasks)),x=i0(l.tasks);return c.jsxs(vi,{variant:"surface",status:x.displayStatus,className:"px-4 py-2",children:[c.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_minmax(0,150px)_124px_44px_44px] lg:items-center",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1 lg:contents",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(cr,{featureNum:a.number,phaseNum:l.number,featureId:a.id,phaseId:l.id}),c.jsx(mr,{id:Bl({featureNum:a.number,phaseNum:l.number}),children:c.jsx("span",{className:"sr-only",children:"Copy phase path"})}),l.shortId?c.jsx(Hl,{shortId:l.shortId}):null,l.handoff?c.jsx(xm,{phaseId:l.id,updatedAt:l.handoffUpdatedAt}):null,c.jsx(z0,{phaseId:l.id,phaseTitle:l.title,count:((N=l.linkedRequirements)==null?void 0:N.length)??0}),c.jsx("span",{className:"shrink-0",children:c.jsx(Vo,{status:x.displayStatus,breakdown:x.breakdown})})]}),c.jsx(Ye,{to:`/features/${t}/phases/${l.id}`,className:"entity-link--phase min-w-0 w-full break-words text-sm font-semibold underline-offset-4 hover:underline [overflow-wrap:anywhere]",children:l.title})]}),c.jsxs("div",{className:"flex items-center gap-2 self-end lg:hidden",children:[c.jsx(Ye,{to:`/features/${t}/phases/${l.id}/edit`,"aria-label":`Edit phase ${l.title}`,children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(o.Form,{method:"post",action:`/features/${t}/phases/${l.id}/delete`,onSubmit:w=>{window.confirm(`Delete phase “${l.title}”? This cannot be undone.`)||w.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:p||m,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete phase ${l.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[l.tasks.length," tasks"]}),g?c.jsx("div",{className:"mt-0.5 break-words",children:g}):null]}),c.jsx(s.Form,{method:"post",action:`/features/${t}/phases/${l.id}/status`,className:"w-full lg:w-auto",children:c.jsxs("div",{className:"relative",children:[c.jsx("select",{name:"status",value:f,disabled:m||p,"aria-busy":m,className:"field-control min-h-8 appearance-none py-1 pr-8 text-[11px]",onChange:w=>s.submit(w.currentTarget.form),children:ld.map(w=>c.jsx("option",{value:w.value,children:w.label},w.value))}),c.jsx(vs,{className:"pointer-events-none absolute right-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-[var(--text-muted)]"})]})}),c.jsx(Ye,{to:`/features/${t}/phases/${l.id}/edit`,"aria-label":`Edit phase ${l.title}`,className:"hidden lg:block",children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(o.Form,{method:"post",action:`/features/${t}/phases/${l.id}/delete`,className:"hidden lg:block",onSubmit:w=>{window.confirm(`Delete phase “${l.title}”? This cannot be undone.`)||w.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:p||m,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete phase ${l.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]}),l.summary?c.jsx("div",{className:"mt-1 min-w-0 break-words line-clamp-2 text-[11px] text-[var(--text-muted)]",children:l.summary}):null]})}function zm({items:t,className:a="",stacked:l=!1}){return l?c.jsx("nav",{"aria-label":"Breadcrumb",className:`grid gap-1 text-sm ${a}`,children:t.map((s,o)=>{const u=o===t.length-1,f=s.to&&!u?c.jsx(Ye,{to:s.to,className:"font-semibold text-[var(--accent)] hover:underline break-words min-w-0",children:s.label}):c.jsx("span",{className:`break-words min-w-0 ${u?"text-[var(--text)] font-semibold":"text-[var(--text-muted)]"}`,children:s.label});return c.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[s.kind?c.jsxs("span",{className:"shrink-0 text-[var(--text-subtle)] font-medium",children:[s.kind,":"]}):null,c.jsx("span",{className:"min-w-0",children:f})]},`${s.label}-${o}`)})}):c.jsx("nav",{"aria-label":"Breadcrumb",className:`flex flex-wrap items-center gap-2 text-sm ${a}`,children:t.map((s,o)=>{const u=o===t.length-1,f=s.to&&!u?c.jsx(Ye,{to:s.to,className:"font-semibold text-[var(--accent)] hover:underline",children:s.label}):c.jsx("span",{className:u?"text-[var(--text)]":"text-[var(--text-muted)]",children:s.label});return c.jsxs("span",{className:"inline-flex min-w-0 items-center gap-2",children:[o>0?c.jsx("span",{className:"text-[var(--text-subtle)]",children:"/"}):null,c.jsx("span",{className:"min-w-0 break-words",children:f})]},`${s.label}-${o}`)})})}function Um({featureNum:t,phaseNum:a,taskNum:l,featureId:s,phaseId:o,taskId:u,shortId:f,children:m}){return c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(cr,{featureNum:t,phaseNum:a,taskNum:l,featureId:s,phaseId:o,taskId:u}),c.jsx(mr,{id:Bl({featureNum:t,phaseNum:a,taskNum:l}),children:c.jsx("span",{className:"sr-only",children:"Copy path"})}),f?c.jsx(Hl,{shortId:f}):null,m]})}function zn({className:t="",children:a,...l}){return c.jsx("div",{className:`surface-card p-4 ${t}`,...l,children:a})}function Ix(...t){return t.filter(Boolean).join(" ")}function Bm({items:t,className:a}){const l=t.filter(s=>s.visible!==!1);return l.length===0?null:c.jsx("div",{className:Ix("grid gap-4 md:grid-cols-2 xl:grid-cols-4",a),children:l.map(s=>c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:s.label}),c.jsx("div",{className:Ix("mt-2 text-sm font-semibold break-words text-[var(--text)] [overflow-wrap:anywhere]",s.valueClassName),children:s.value})]},s.label))})}function Hm(t){return t&&t>0?`P${t}`:""}function eD(t,a){return!t&&!a?"":`${t||"Start not set"} → ${a||"End not set"}`}function $m({decisions:t}){return t.length===0?null:c.jsxs("details",{className:"group mt-4",children:[c.jsx("summary",{className:"flex cursor-pointer select-none items-center gap-2 font-semibold text-[var(--text)]",children:c.jsxs("span",{children:["Accepted decisions (",t.length,")"]})}),c.jsx("div",{className:"mt-2 grid gap-3",children:t.map(a=>c.jsxs("div",{className:"surface-card px-4 py-3",children:[c.jsx("p",{className:"text-sm font-semibold text-[var(--text)]",children:a.title}),a.decision?c.jsxs("div",{className:"mt-2 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Decision:"}),c.jsx(xn,{text:a.decision,className:"mt-1"})]}):null,a.rationale?c.jsxs("div",{className:"mt-1 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Rationale:"}),c.jsx(xn,{text:a.rationale,className:"mt-1"})]}):null,a.implementationNotes?c.jsxs("div",{className:"mt-1 text-sm text-[var(--text-muted)]",children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Implementation:"}),c.jsx(xn,{text:a.implementationNotes,className:"mt-1"})]}):null]},a.id))})]})}const tD={draft:jN,discovery:aR,planned:qo,"in-progress":Ub,done:pm,blocked:Hb,waiting:zb,deferred:iR,canceled:Mb,rejected:CN};function Bh(t){return t.split(/[-\s]+/).filter(Boolean).map(a=>a==="and"?"and":a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function Vx(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"short",timeStyle:"short"}).format(new Date(t))}catch{return t}}const nD=new Set(["canceled","rejected"]);function qm({statusLog:t,currentStatus:a,backbone:l,createdAt:s,updatedAt:o,startedAt:u,completedAt:f}){const m=[];if(t.length===0){const S=l.indexOf(a);if(S>=0)for(let D=0;D<=S;D++)m.push(l[D]);else m.push(a)}else{const S=t[0];S&&m.push(S.fromStatus);for(const D of t)m[m.length-1]!==D.toStatus&&m.push(D.toStatus)}m[m.length-1]!==a&&m.push(a);const p=new Set(m),g=a==="done"||nD.has(a),x=S=>{var R,L;if(t.length>0){if(S===((R=t[0])==null?void 0:R.fromStatus))return((L=t[0])==null?void 0:L.date)??"";for(const I of t)if(I.toStatus===S)return I.date;return""}const D=l[0];return S===D?s??"":S==="in-progress"?u??o??"":S==="done"?f??o??"":""},y=[...m];if(!g){const S=l.indexOf(a);if(S>=0&&S+1<l.length){const D=l[S+1];p.has(D)||y.push(D)}}const N=t.length===0?y.filter((S,D)=>D===0||S===a||!!x(S)):y,w=S=>p.has(S)?S===a&&!g?"current":"completed":"pending";return c.jsx("ol",{className:"status-stepper",role:"list","aria-label":"Status progress",children:N.map((S,D)=>{const R=w(S),L=tD[S]??Pc,I=p.has(S),q=x(S),X=q?`${Bh(S)} — ${Vx(q)}`:Bh(S),W=D===0?null:I?"traveled":"pending";return c.jsxs("li",{className:`status-step status-step--${R}`,role:"listitem","aria-current":R==="current"?"step":void 0,style:{"--step-color":`var(--color-status-${S})`},children:[W?c.jsx("span",{className:`status-connector status-connector--${W}`,"aria-hidden":"true"}):null,c.jsx("span",{className:"status-node",title:X,children:c.jsx(L,{className:"status-node-icon"})}),c.jsx("span",{className:"status-step-label",children:Bh(S)}),q?c.jsx("span",{className:"status-step-date",children:Vx(q)}):null]},`${S}-${D}`)})})}function Yx(t){return t.split(/[-\s]+/).filter(Boolean).map(a=>a==="and"?"and":a.charAt(0).toUpperCase()+a.slice(1)).join(" ")}function aD(t){if(!t)return"";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"short",timeStyle:"short"}).format(new Date(t))}catch{return t}}function rD(t,a,l,s,o){if(t.length>0)return t.map(m=>({date:m.date,fromStatus:m.fromStatus,toStatus:m.toStatus,inferred:!1}));const u=l.indexOf(a);if(u<0)return[];const f=[];for(let m=1;m<=u;m++){const p=l[m-1],g=l[m],x=g==="in-progress"?s??"":g==="done"?o??"":"";f.push({date:x,fromStatus:p,toStatus:g,inferred:!0})}return f}function Im({statusLog:t,currentStatus:a,backbone:l,startedAt:s,completedAt:o}){const u=rD(t??[],a??"",l??[],s,o);return c.jsx(ua,{title:"Status history",count:u.length,defaultOpen:u.length>0,contentClassName:"grid gap-2.5",children:u.length===0?c.jsx("p",{className:"text-sm text-[var(--text-muted)] italic",children:"No status changes recorded."}):u.map((f,m)=>c.jsxs("div",{className:"text-sm flex flex-wrap items-center gap-2",children:[c.jsx("span",{className:"text-xs font-mono text-[var(--text-subtle)]",children:aD(f.date)}),c.jsx("span",{className:"font-semibold text-[var(--text-muted)]",children:Yx(f.fromStatus)}),c.jsx("span",{className:"text-[var(--text-subtle)]",children:"→"}),c.jsx("span",{className:"font-semibold text-[var(--text)]",children:Yx(f.toStatus)})]},m))})}function lD(t){return t.reduce((a,l)=>a+l.tasks.length,0)}function sD(t){let a=0,l=0,s=0,o=0;for(const u of t)for(const f of u.tasks)f.status==="in-progress"&&(a+=1),f.status==="done"&&(l+=1),f.status==="blocked"&&(s+=1),["done","canceled"].includes(f.status)||(o+=1);return{inProgress:a,done:l,blocked:s,remaining:o}}function iD(t){return t.find(a=>["in-progress","discovery","planned","draft"].includes(a.status))}function oD(){var W,ae,z,T;const{feature:t,phases:a}=ll(),l=t.acceptedDecisions??[],s=lD(a),o=sD(a),u=iD(a),f=s0(a),[m,p]=$o(),g=((W=m.get("q"))==null?void 0:W.trim())??"",x=((ae=m.get("status"))==null?void 0:ae.trim())??"",y=((z=m.get("sort"))==null?void 0:z.trim())??"priority",N=((T=m.get("dir"))==null?void 0:T.trim())??"asc",w={key:y==="priority"||y==="number"||y==="createdAt"||y==="updatedAt"||y==="title"||y==="shortId"||y==="status"||y==="startedAt"||y==="completedAt"?y:"priority",direction:N==="desc"?"desc":"asc"},S=v.useMemo(()=>[...a].sort((ee,fe)=>Eo(ee,fe,w.key,w.direction)),[a,w]),D=v.useMemo(()=>S.filter(ee=>(!x||ee.status===x)&&id(g,[ee.title,ee.id,ee.summary,ee.description])),[S,g,x]),R=kr(),L=v.useRef(null),I=v.useCallback(()=>R("edit"),[R]),q=v.useCallback(()=>R("phases/new"),[R]),X=v.useCallback(()=>{var ee;(ee=L.current)==null||ee.requestSubmit()},[]);return An("edit",I),An("create",q),An("delete",X),c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:"/features",className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to features"]}),c.jsxs("div",{className:"min-w-0",children:[c.jsx(zm,{stacked:!0,items:[{label:t.name,kind:"Feature"}]}),c.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:c.jsx(Um,{featureNum:t.number,featureId:t.id,shortId:t.shortId,children:c.jsx(Vo,{status:f.displayStatus,breakdown:f.breakdown})})}),c.jsx("h2",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] min-w-0 break-words [overflow-wrap:anywhere] sm:text-3xl",children:t.name}),t.description?c.jsx(ua,{title:"Description",children:c.jsx(xn,{text:t.description,className:"plan-description max-w-4xl"})}):null,c.jsx("div",{className:"mt-4",children:c.jsx(qm,{statusLog:t.statusLog??[],currentStatus:t.status,backbone:["planned","in-progress","done"],createdAt:t.createdAt,updatedAt:t.updatedAt})}),c.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[c.jsx(Ye,{to:"edit",children:c.jsx(gt,{type:"button",shortcut:"edit",children:"Edit feature"})}),c.jsx(ca,{ref:L,method:"post",action:`/features/${t.id}/delete`,className:"inline-flex",onSubmit:ee=>{window.confirm(`Delete feature "${t.name}"?`)||ee.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",shortcut:"delete",children:"Delete feature"})})]})]}),c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Current phase"}),c.jsx("p",{className:"mt-2 text-sm font-semibold text-[var(--text)] break-words",children:(u==null?void 0:u.title)||"No active phase"})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Phases"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:a.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Tasks"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:s})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Current phase"}),c.jsx("p",{className:"mt-2 text-sm font-semibold text-[var(--text)] break-words",children:(u==null?void 0:u.title)||"No active phase"})]})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"In progress"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.inProgress})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Remaining"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.remaining})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Done"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.done})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Blocked"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:o.blocked})]})]}),c.jsx(Bm,{items:[{label:"Priority",value:Hm(t.priority),visible:t.priority>0},{label:"Timeline",value:eD(t.startDate,t.endDate),visible:!!(t.startDate||t.endDate)}]}),t.workDone||t.workRemaining?c.jsx(ua,{title:"Planning notes",defaultOpen:!1,children:c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[t.workDone?c.jsxs("div",{children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Work done"}),c.jsx(xn,{text:t.workDone,className:"mt-2"})]}):null,t.workRemaining?c.jsxs("div",{children:[c.jsx("span",{className:"font-semibold text-[var(--text)]",children:"Work remaining"}),c.jsx(xn,{text:t.workRemaining,className:"mt-2"})]}):null]})}):null,l.length>0?c.jsx($m,{decisions:l}):null,c.jsx(Im,{statusLog:t.statusLog??[],currentStatus:t.status,backbone:["planned","in-progress","done"]})]}),c.jsxs(Pt,{className:"grid gap-5",children:[c.jsxs("div",{className:"flex flex-col gap-4 md:flex-row md:items-start md:justify-between",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Phases"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Filter and sort this feature's phases."})]}),c.jsx(Ye,{to:"phases/new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create phase"})})]}),c.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[c.jsx(Om,{sort:w,onChange:ee=>p(fe=>(fe.set("sort",ee.key),fe.set("dir",ee.direction),fe))}),c.jsx(sd,{query:g,status:x,statusOptions:ld,placeholder:"Search phase title, id, or summary",clearTo:`/features/${t.id}`,resultsLabel:D.length===a.length?`${a.length} phases`:`${D.length} of ${a.length} phases`})]}),c.jsx("div",{className:"grid gap-3",children:a.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No phases yet. ",c.jsx(Ye,{to:`/features/${t.id}/phases/new`,className:"font-semibold text-[var(--accent)] hover:underline",children:"Add a phase"})]}):D.length>0?D.map(ee=>c.jsx(WC,{featureId:t.id,feature:t,phase:ee},ee.id)):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No phases match the current filters."})})]}),c.jsx(hi,{})]})}async function uD({params:t}){const{featureId:a,phaseId:l}=t;if(!a||!l)throw new Response("featureId and phaseId required",{status:400});const[s,o,u]=await Promise.all([Io(a),Zc(l),vm()]),f=u.filter(m=>m.linkedPhaseIds.includes(l));return{feature:s,phase:{...o,linkedRequirements:f}}}function Fx(t){try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}function cD({featureId:t,featureNum:a,phaseId:l,phaseNum:s,task:o}){var w;const u=hs(),f=hs(),p=((w=u.formData)==null?void 0:w.get("status"))??o.status,g=u.state!=="idle",x=f.state!=="idle",y=Bc(VC(o.subtasks)),N=n0(p);return c.jsxs(vi,{variant:"surface",status:N,className:"px-4 py-2",children:[c.jsxs("div",{className:"grid gap-2 lg:grid-cols-[minmax(0,1fr)_minmax(0,168px)_124px_44px_44px] lg:items-center",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1 lg:contents",children:[c.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-1",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx(cr,{featureNum:a,phaseNum:s,taskNum:o.number,featureId:t,phaseId:l,taskId:o.id}),c.jsx(mr,{id:Bl({featureNum:a,phaseNum:s,taskNum:o.number}),children:c.jsx("span",{className:"sr-only",children:"Copy task path"})}),o.shortId?c.jsx(Hl,{shortId:o.shortId}):null,c.jsx("span",{className:"shrink-0",children:c.jsx(ur,{status:p})})]}),c.jsx(Ye,{to:`/features/${t}/phases/${l}/tasks/${o.id}`,className:"entity-link--task min-w-0 w-full break-words text-sm font-semibold underline-offset-4 hover:underline [overflow-wrap:anywhere]",children:o.title})]}),c.jsxs("div",{className:"flex items-center gap-2 self-end lg:hidden",children:[c.jsx(Ye,{to:`/features/${t}/phases/${l}/tasks/${o.id}/edit`,"aria-label":`Edit task ${o.title}`,children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(f.Form,{method:"post",action:`/features/${t}/phases/${l}/tasks/${o.id}/delete`,onSubmit:S=>{window.confirm(`Delete task “${o.title}”? This cannot be undone.`)||S.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:x||g,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete task ${o.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]})]}),c.jsxs("div",{className:"text-[11px] text-[var(--text-muted)]",children:[c.jsxs("div",{className:"font-semibold text-[var(--text)]",children:[o.subtasks.length," subtasks · ",o.checklist.length," checklist"]}),y?c.jsx("div",{className:"mt-0.5 break-words",children:y}):c.jsx("div",{className:"mt-0.5 break-words",children:"No subtask statuses yet"})]}),c.jsx(u.Form,{method:"post",action:`/features/${t}/phases/${l}/tasks/${o.id}/status`,className:"w-full lg:w-auto",children:c.jsxs("div",{className:"relative",children:[c.jsx("select",{name:"status",value:p,disabled:g||x,"aria-busy":g,className:"field-control min-h-8 appearance-none py-1 pr-8 text-[11px]",onChange:S=>u.submit(S.currentTarget.form),children:Xo.map(S=>c.jsx("option",{value:S.value,children:S.label},S.value))}),c.jsx(vs,{className:"pointer-events-none absolute right-2.5 top-1/2 h-3 w-3 -translate-y-1/2 text-[var(--text-muted)]"})]})}),c.jsx(Ye,{to:`/features/${t}/phases/${l}/tasks/${o.id}/edit`,"aria-label":`Edit task ${o.title}`,className:"hidden lg:block",children:c.jsx(gt,{type:"button",variant:"secondary",className:"min-h-8 w-8 rounded-[10px] px-0 text-[var(--text-muted)] hover:text-[var(--text)]",children:c.jsx(ms,{className:"h-3.5 w-3.5"})})}),c.jsx(f.Form,{method:"post",action:`/features/${t}/phases/${l}/tasks/${o.id}/delete`,className:"hidden lg:block",onSubmit:S=>{window.confirm(`Delete task “${o.title}”? This cannot be undone.`)||S.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",disabled:x||g,className:"min-h-8 w-8 rounded-[10px] px-0","aria-label":`Delete task ${o.title}`,children:c.jsx(di,{className:"h-4 w-4"})})})]}),c.jsxs("div",{className:"mt-1 flex flex-wrap gap-x-3 gap-y-1 text-[11px] text-[var(--text-subtle)]",children:[o.startedAt?c.jsxs("span",{children:["Started ",Fx(o.startedAt)]}):null,o.completedAt?c.jsxs("span",{children:["Completed ",Fx(o.completedAt)]}):null]}),o.description?c.jsx("div",{className:"mt-1 min-w-0 break-words line-clamp-2 text-[11px] text-[var(--text-muted)]",children:o.description}):null]})}function dD(t){let a=0,l=0,s=0,o=0;for(const u of t.tasks)u.status==="in-progress"&&(a+=1),u.status==="done"&&(l+=1),u.status==="blocked"&&(s+=1),["done","canceled"].includes(u.status)||(o+=1);return{inProgress:a,done:l,blocked:s,remaining:o}}function fD(){var fe,be,ye,te;const{feature:t,phase:a}=ll(),l=a.decisions??[],s=a.acceptedDecisions??[],o=a.linkedRequirements??[],u=dD(a),f=i0(a.tasks),[m,p]=$o(),g=((fe=m.get("q"))==null?void 0:fe.trim())??"",x=((be=m.get("status"))==null?void 0:be.trim())??"",y=((ye=m.get("sort"))==null?void 0:ye.trim())??"priority",N=((te=m.get("dir"))==null?void 0:te.trim())??"asc",w={key:y==="priority"||y==="number"||y==="createdAt"||y==="updatedAt"||y==="title"||y==="shortId"||y==="status"||y==="startedAt"||y==="completedAt"?y:"priority",direction:N==="desc"?"desc":"asc"},S=v.useMemo(()=>[...a.tasks].sort((re,ge)=>Eo(re,ge,w.key,w.direction)),[a.tasks,w]),D=v.useMemo(()=>S.filter(re=>(!x||re.status===x)&&id(g,[re.title,re.id,re.description,re.shortName])),[S,g,x]),R=kr(),L=v.useRef(null),[I,q]=v.useState(a.handoff??""),[X,W]=v.useState(!1),ae=v.useCallback(()=>R("edit"),[R]),z=v.useCallback(()=>R("tasks/new"),[R]),T=v.useCallback(()=>{var re;(re=L.current)==null||re.requestSubmit()},[]),ee=v.useCallback(async()=>{if(window.confirm("Clear this phase's handoff?")){W(!0);try{await Gb(a.id),q("")}catch{}finally{W(!1)}}},[a.id]);return An("edit",ae),An("create",z),An("delete",T),c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:`/features/${t.id}`,className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to feature"]}),c.jsxs("div",{className:"min-w-0",children:[c.jsx(zm,{stacked:!0,items:[{label:t.name,to:`/features/${t.id}`,kind:"Feature"},{label:a.title,kind:"Phase"}]}),c.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:c.jsxs(Um,{featureNum:t.number,phaseNum:a.number,featureId:t.id,phaseId:a.id,shortId:a.shortId,children:[I?c.jsx(xm,{phaseId:a.id,updatedAt:a.handoffUpdatedAt}):null,c.jsx(Vo,{status:f.displayStatus,breakdown:f.breakdown})]})}),c.jsx("h2",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] min-w-0 break-words [overflow-wrap:anywhere] sm:text-3xl",children:a.title}),a.summary?c.jsx(xn,{text:a.summary,className:"mt-3 max-w-4xl"}):null,c.jsx(qm,{statusLog:a.statusLog??[],currentStatus:a.status,backbone:["draft","discovery","planned","in-progress","done"],createdAt:a.createdAt,updatedAt:a.updatedAt}),c.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[c.jsx(Ye,{to:"edit",children:c.jsx(gt,{type:"button",shortcut:"edit",children:"Edit phase"})}),c.jsx(Ye,{to:"tasks/new",children:c.jsx(gt,{type:"button",variant:"primary",shortcut:"create",children:"Create task"})}),c.jsx(ca,{ref:L,method:"post",action:`/features/${t.id}/phases/${a.id}/delete`,className:"inline-flex",onSubmit:re=>{window.confirm(`Delete phase "${a.title}"?`)||re.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",shortcut:"delete",children:"Delete phase"})})]})]}),c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Tasks"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:a.tasks.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"In progress"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.inProgress})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Remaining"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.remaining})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Done"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.done})]})]}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Blocked"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:u.blocked})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Goals"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:a.goals.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Dependencies"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:a.dependencies.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Completion criteria"}),c.jsx("p",{className:"mt-2 text-2xl font-black text-[var(--text)]",children:a.completionCriteria.length})]})]}),c.jsx(Bm,{items:[{label:"Priority",value:Hm(a.priority),visible:a.priority>0},{label:"Linked requirements",value:o.length,visible:o.length>0,valueClassName:"text-2xl font-black"},{label:"Risks",value:a.risks.length,visible:a.risks.length>0,valueClassName:"text-2xl font-black"},{label:"Open questions",value:a.openQuestions.length,visible:a.openQuestions.length>0,valueClassName:"text-2xl font-black"}]}),a.notes?c.jsx(ua,{title:"Notes",defaultOpen:!1,children:c.jsx(xn,{text:a.notes,className:"plan-description"})}):null,c.jsx(ua,{title:"Linked requirements",count:o.length,defaultOpen:!1,children:o.length>0?c.jsx("div",{className:"grid gap-3",children:o.map(re=>c.jsx("div",{className:"min-w-0 rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-4 py-4",children:c.jsxs("div",{className:"flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c.jsx(ur,{status:re.status}),re.macroTasks.length>0?c.jsxs("span",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[var(--text-subtle)]",children:[re.macroTasks.length," macro task",re.macroTasks.length===1?"":"s"]}):null]}),c.jsx("h3",{className:"mt-2 text-lg font-black tracking-tight text-[var(--text)] [overflow-wrap:anywhere]",children:re.title}),re.description?c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)] [overflow-wrap:anywhere]",children:re.description}):null]}),c.jsx(Ye,{to:`/requirements#phase-${a.id}`,className:"text-sm font-semibold text-[var(--accent)] hover:underline sm:shrink-0",children:"Open phase requirements →"})]})},re.id))}):c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"No linked requirements yet."})}),a.description?c.jsx(ua,{title:"Description",children:c.jsx(xn,{text:a.description,className:"plan-description"})}):null,l.length>0?c.jsx(ua,{title:"Decisions",count:l.length,defaultOpen:!1,children:c.jsx("div",{className:"grid gap-2 border-l-2 border-[var(--border)] pl-4 ml-1",children:l.map((re,ge)=>c.jsx("div",{className:"text-sm text-[var(--text-muted)]",children:c.jsx(xn,{text:re})},ge))})}):null,s.length>0?c.jsx($m,{decisions:s}):null,c.jsx(Im,{statusLog:a.statusLog??[],currentStatus:a.status,backbone:["draft","discovery","planned","in-progress","done"]})]}),I?c.jsx(Pt,{className:"grid gap-4",children:c.jsx(ua,{title:"Handoff",actions:c.jsx("button",{type:"button",onClick:ee,disabled:X,className:"rounded-lg border border-[var(--border)] px-3 py-1.5 text-sm text-[var(--text-muted)] hover:bg-[var(--surface-card)] disabled:opacity-60",children:X?"Clearing…":"Clear handoff"}),children:c.jsx("div",{className:"rounded-[18px] border border-[var(--border)] bg-[var(--surface-card)] px-5 py-5",children:c.jsx(xn,{text:I,className:"formatted-text max-w-none"})})})}):null,c.jsxs(Pt,{className:"grid gap-5",children:[c.jsxs("div",{children:[c.jsx("p",{className:"text-sm font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Tasks"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Filter and sort this phase's tasks."})]}),c.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between",children:[c.jsx(Om,{sort:w,onChange:re=>p(ge=>(ge.set("sort",re.key),ge.set("dir",re.direction),ge))}),c.jsx(sd,{query:g,status:x,statusOptions:Xo,placeholder:"Search task title, id, or description",clearTo:`/features/${t.id}/phases/${a.id}`,resultsLabel:D.length===a.tasks.length?`${a.tasks.length} tasks`:`${D.length} of ${a.tasks.length} tasks`})]}),c.jsx("div",{className:"grid gap-3",children:a.tasks.length===0?c.jsxs(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:["No tasks yet. ",c.jsx(Ye,{to:"tasks/new",className:"font-semibold text-[var(--accent)] hover:underline",children:"Add a task"})]}):D.length>0?D.map(re=>c.jsx(cD,{featureId:t.id,featureNum:t.number,phaseId:a.id,phaseNum:a.number,task:re},re.id)):c.jsx(Pt,{className:"p-4 text-sm text-[var(--text-muted)]",children:"No tasks match the current filters."})})]}),c.jsx(hi,{})]})}async function hD({params:t}){const{featureId:a,phaseId:l,taskId:s}=t;if(!a||!l||!s)throw new Response("featureId, phaseId and taskId required",{status:400});const[o,u,f]=await Promise.all([Io(a),Zc(l),Jc(s)]);return{feature:o,phase:u,task:f}}function Px(t){try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}function mD({featureId:t,phaseId:a,taskId:l,item:s}){const o=hs(),u=o.formData?o.formData.get("checked")==="true":s.checked,f=o.state!=="idle";return c.jsxs("div",{className:"surface-card flex items-start gap-3 px-4 py-3",children:[c.jsx("input",{type:"checkbox",checked:u,onChange:()=>o.submit({checked:s.checked?"false":"true"},{method:"post",action:`/features/${t}/phases/${a}/tasks/${l}/checklist/${s.id}/toggle`}),disabled:f,className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent)]","aria-label":`Toggle checklist item ${s.title}`}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("span",{className:"checklist-num",children:s.number})," ",c.jsx("span",{className:`text-sm ${u?"text-[var(--text-muted)] line-through":"font-medium text-[var(--text)]"}`,children:s.title})]})]})}function pD(){var x,y;const{feature:t,phase:a,task:l}=ll(),s=l.decisions??[],o=l.acceptedDecisions??[],u=l.checklist??[],f=kr(),m=v.useRef(null),p=v.useCallback(()=>f("edit"),[f]),g=v.useCallback(()=>{var N;(N=m.current)==null||N.requestSubmit()},[]);return An("edit",p),An("delete",g),c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:`/features/${t.id}/phases/${a.id}`,className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to phase"]}),c.jsxs("div",{className:"min-w-0",children:[c.jsx(zm,{stacked:!0,items:[{label:t.name,to:`/features/${t.id}`,kind:"Feature"},{label:a.title,to:`/features/${t.id}/phases/${a.id}`,kind:"Phase"},{label:l.title,kind:"Task"}]}),c.jsx("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:c.jsx(Um,{featureNum:t.number,phaseNum:a.number,taskNum:l.number,featureId:t.id,phaseId:a.id,taskId:l.id,shortId:l.shortId,children:c.jsx(ur,{status:l.status})})}),c.jsx("h2",{className:"mt-2 text-2xl font-black tracking-tight text-[var(--text)] min-w-0 break-words [overflow-wrap:anywhere] sm:text-3xl",children:l.title}),c.jsxs("div",{className:"mt-4 flex flex-wrap items-center gap-2",children:[c.jsx(Ye,{to:"edit",children:c.jsx(gt,{type:"button",shortcut:"edit",children:"Edit task"})}),c.jsx(ca,{ref:m,method:"post",action:`/features/${t.id}/phases/${a.id}/tasks/${l.id}/delete`,className:"inline-flex",onSubmit:N=>{window.confirm(`Delete task "${l.title}"?`)||N.preventDefault()},children:c.jsx(gt,{type:"submit",variant:"danger",shortcut:"delete",children:"Delete task"})})]})]}),c.jsx(qm,{statusLog:l.statusLog??[],currentStatus:l.status,backbone:["planned","in-progress","done"],createdAt:l.createdAt,updatedAt:l.updatedAt,startedAt:l.startedAt,completedAt:l.completedAt}),c.jsxs(Pt,{className:"grid gap-4",children:[l.description?c.jsx(ua,{title:"Description",children:c.jsx(xn,{text:l.description,className:"plan-description"})}):null,l.notes?c.jsx(ua,{title:"Notes",defaultOpen:!1,children:c.jsx(xn,{text:l.notes})}):null,c.jsx(Im,{statusLog:l.statusLog??[],currentStatus:l.status,backbone:["planned","in-progress","done"],startedAt:l.startedAt,completedAt:l.completedAt}),s.length>0?c.jsx(ua,{title:"Decisions",count:s.length,defaultOpen:!1,children:c.jsx("div",{className:"grid gap-2 border-l-2 border-[var(--border)] pl-4 ml-1",children:s.map((N,w)=>c.jsx("div",{className:"text-sm text-[var(--text-muted)]",children:c.jsx(xn,{text:N})},w))})}):null,o.length>0?c.jsx($m,{decisions:o}):null,c.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-5",children:[c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Checklist items"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:u.length})]}),c.jsxs(zn,{children:[c.jsx("p",{className:"text-xs font-semibold uppercase tracking-[0.22em] text-[var(--text-subtle)]",children:"Subtasks"}),c.jsx("p",{className:"mt-2 text-3xl font-black text-[var(--text)]",children:((x=l.subtasks)==null?void 0:x.length)??0})]})]}),c.jsx(Bm,{items:[{label:"Priority",value:Hm(l.priority),visible:l.priority>0},{label:"Short name",value:l.shortName,visible:!!l.shortName},{label:"Started",value:Px(l.startedAt),visible:!!l.startedAt},{label:"Completed",value:Px(l.completedAt),visible:!!l.completedAt},{label:"Phase",value:a.title}]}),c.jsxs("div",{className:"grid gap-3",children:[c.jsx("div",{children:c.jsxs("h3",{className:"text-sm font-bold text-[var(--text)]",children:["Steps (",u.length,")"]})}),u.length?c.jsx("div",{className:"grid gap-2",children:u.map(N=>c.jsx(mD,{featureId:t.id,phaseId:a.id,taskId:l.id,item:N},N.id))}):c.jsx("p",{className:"text-sm text-[var(--text-muted)] italic",children:"No steps defined."})]}),(y=l.subtasks)!=null&&y.length?c.jsx(ua,{title:"Subtasks",count:l.subtasks.length,defaultOpen:!1,contentClassName:"grid gap-2",children:l.subtasks.map(N=>c.jsxs("div",{className:"surface-card flex items-center justify-between gap-4 px-4 py-3",children:[c.jsxs("div",{className:"min-w-0",children:[c.jsx("p",{className:"text-sm font-semibold text-[var(--text)]",children:N.title}),c.jsx("p",{className:"mt-1 text-xs text-[var(--text-muted)]",children:N.id})]}),c.jsx(ur,{status:N.status})]},N.id))}):null]}),c.jsx(hi,{})]})}const gD=["a[href]","button:not([disabled])","input:not([disabled])","select:not([disabled])","textarea:not([disabled])","[tabindex]:not([tabindex='-1'])"].join(",");function ql({title:t,description:a,children:l}){const s=kr(),o=v.useRef(null),u=v.useRef(null);return v.useEffect(()=>{var g;const f=o.current;if(!f)return;const m=document.activeElement;(g=u.current)==null||g.focus();const p=x=>{if(x.key==="Escape"){x.preventDefault(),s(-1);return}if(x.key!=="Tab")return;const y=Array.from(f.querySelectorAll(gD)).filter(D=>D.offsetParent!==null);if(y.length===0){x.preventDefault(),f.focus();return}const N=y[0],w=y[y.length-1],S=document.activeElement;x.shiftKey?(S===N||!f.contains(S))&&(x.preventDefault(),w.focus()):S===w&&(x.preventDefault(),N.focus())};return window.addEventListener("keydown",p),()=>{var x;window.removeEventListener("keydown",p),(x=m==null?void 0:m.focus)==null||x.call(m)}},[s]),c.jsxs("div",{className:"fixed inset-0 z-50 overflow-y-auto p-4 md:p-6",children:[c.jsx("button",{type:"button",className:"absolute inset-0 bg-black/50 backdrop-blur-sm",onClick:()=>s(-1),"aria-hidden":"true",tabIndex:-1}),c.jsx("div",{className:"relative z-10 flex min-h-full items-start justify-center",children:c.jsxs("div",{ref:o,role:"dialog","aria-modal":"true","aria-label":t,tabIndex:-1,className:"surface-panel flex max-h-[calc(100vh-2rem)] w-full max-w-2xl flex-col overflow-hidden p-6 outline-none md:max-h-[calc(100vh-3rem)] md:p-8",children:[c.jsxs("div",{className:"mb-6 flex shrink-0 items-start justify-between gap-4",children:[c.jsxs("div",{children:[c.jsx("h3",{className:"text-xl font-black tracking-tight text-[var(--text)]",children:t}),a?c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:a}):null]}),c.jsx("button",{ref:u,type:"button",onClick:()=>s(-1),className:"inline-flex h-10 w-10 shrink-0 items-center justify-center rounded-[14px] border border-[var(--border-strong)] text-[var(--text-muted)] transition hover:text-[var(--text)]","aria-label":"Close modal",children:c.jsx(cR,{className:"h-4 w-4"})})]}),c.jsx("div",{className:"min-h-0 flex-1 overflow-y-auto pr-1",children:l})]})})]})}function Il({className:t="",children:a,...l}){return c.jsx("div",{className:`sticky bottom-0 mt-2 flex justify-end gap-3 border-t border-[var(--border)] bg-[var(--surface)] px-1 pt-4 pb-1 backdrop-blur-xl ${t}`,...l,children:a})}function lt({label:t,children:a}){return c.jsxs("label",{className:"grid gap-2",children:[c.jsx("span",{className:"text-sm font-semibold text-[var(--text-muted)]",children:t}),a]})}function mn(t){return c.jsx("textarea",{className:"field-control field-textarea",...t})}function vD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var o;return(o=l.current)==null?void 0:o.requestSubmit()},[]);return An("submit",s,{allowInEditable:!0}),c.jsx(ql,{title:"Create feature",description:"Top-level container for phases and tasks.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Feature name",children:c.jsx(ma,{name:"name",placeholder:"Products page implementation",required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",placeholder:"Short context for the feature"})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Creating…":"Create feature"})})]})})}function yD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var f;return(f=l.current)==null?void 0:f.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const u=gs("feature-detail").feature;return c.jsx(ql,{title:"Edit feature",description:"Update metadata, planning notes and timeline.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Name",children:c.jsx(ma,{name:"name",defaultValue:u.name,required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",defaultValue:u.description})}),c.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[c.jsx(lt,{label:"Start date",children:c.jsx(ma,{type:"date",name:"startDate",defaultValue:u.startDate})}),c.jsx(lt,{label:"End date",children:c.jsx(ma,{type:"date",name:"endDate",defaultValue:u.endDate})})]}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:u.status,children:rd.map(f=>c.jsx("option",{value:f.value,children:f.label},f.value))})}),c.jsx(lt,{label:"Priority",children:c.jsx(ma,{type:"number",name:"priority",defaultValue:u.priority??0,min:0})}),c.jsx(ua,{title:"Planning notes",subtitle:"Optional agent-maintained notes for progress tracking.",defaultOpen:!1,className:"mt-0",children:c.jsxs("div",{className:"grid gap-4",children:[c.jsx(lt,{label:"Work done",children:c.jsx(mn,{name:"workDone",defaultValue:u.workDone})}),c.jsx(lt,{label:"Work remaining",children:c.jsx(mn,{name:"workRemaining",defaultValue:u.workRemaining})})]})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Saving…":"Save feature"})})]})})}function xD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var o;return(o=l.current)==null?void 0:o.requestSubmit()},[]);return An("submit",s,{allowInEditable:!0}),c.jsx(ql,{title:"Create phase",description:"A phase belongs to the current feature.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Phase title",children:c.jsx(ma,{name:"title",placeholder:"API creation",required:!0})}),c.jsx(lt,{label:"Summary",children:c.jsx(mn,{name:"summary",placeholder:"Brief phase summary"})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",placeholder:"Initial implementation notes"})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Creating…":"Create phase"})})]})})}function ni(t){return t.join(`
289
289
  `)}function bD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var f;return(f=l.current)==null?void 0:f.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const u=gs("phase-detail").phase;return c.jsx(ql,{title:"Edit phase",description:"Update scope, constraints and delivery criteria.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Title",children:c.jsx(ma,{name:"title",defaultValue:u.title,required:!0})}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:u.status,children:ld.map(f=>c.jsx("option",{value:f.value,children:f.label},f.value))})}),c.jsx(lt,{label:"Priority",children:c.jsx(ma,{type:"number",name:"priority",defaultValue:u.priority??0,min:0})}),c.jsx(lt,{label:"Summary",children:c.jsx(mn,{name:"summary",defaultValue:u.summary})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",defaultValue:u.description})}),c.jsx(lt,{label:"Goals (one per line)",children:c.jsx(mn,{name:"goals",defaultValue:ni(u.goals)})}),c.jsx(lt,{label:"Non-goals (one per line)",children:c.jsx(mn,{name:"nonGoals",defaultValue:ni(u.nonGoals)})}),c.jsx(lt,{label:"Dependencies (one per line)",children:c.jsx(mn,{name:"dependencies",defaultValue:ni(u.dependencies)})}),c.jsx(lt,{label:"Risks (one per line)",children:c.jsx(mn,{name:"risks",defaultValue:ni(u.risks)})}),c.jsx(lt,{label:"Open questions (one per line)",children:c.jsx(mn,{name:"openQuestions",defaultValue:ni(u.openQuestions)})}),c.jsx(lt,{label:"Completion criteria (one per line)",children:c.jsx(mn,{name:"completionCriteria",defaultValue:ni(u.completionCriteria)})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Saving…":"Save phase"})})]})})}function SD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var o;return(o=l.current)==null?void 0:o.requestSubmit()},[]);return An("submit",s,{allowInEditable:!0}),c.jsx(ql,{title:"Create task",description:"A task belongs to the current phase.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Task title",children:c.jsx(ma,{name:"title",placeholder:"Custom fetcher integration",required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",placeholder:"Initial task context"})}),c.jsx(lt,{label:"Checklist (one per line)",children:c.jsx(mn,{name:"checklist",placeholder:`Step one
290
290
  Step two
291
291
  Step three`})}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:"planned",children:Xo.map(o=>c.jsx("option",{value:o.value,children:o.label},o.value))})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Creating…":"Create task"})})]})})}function wD(t){return t.map(a=>a.title).join(`
292
292
  `)}function ED(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var f;return(f=l.current)==null?void 0:f.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const u=gs("task-detail").task;return c.jsx(ql,{title:"Edit task",description:"Update execution details and checklist items.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Title",children:c.jsx(ma,{name:"title",defaultValue:u.title,required:!0})}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:u.status,children:Xo.map(f=>c.jsx("option",{value:f.value,children:f.label},f.value))})}),c.jsx(lt,{label:"Priority",children:c.jsx(ma,{type:"number",name:"priority",defaultValue:u.priority??0,min:0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",defaultValue:u.description})}),c.jsx(lt,{label:"Checklist (one per line)",children:c.jsx(mn,{name:"checklist",defaultValue:wD(u.checklist)})}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Saving…":"Save task"})})]})})}function ND(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var u;return(u=l.current)==null?void 0:u.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const{project:o}=gs("root");return c.jsxs("div",{className:"grid gap-8",children:[c.jsxs(Ye,{to:"/",className:"inline-flex items-center gap-2 text-sm font-semibold text-[var(--accent)] hover:underline",children:[c.jsx(Fc,{className:"h-4 w-4"})," Back to dashboard"]}),c.jsxs(Pt,{className:"grid gap-5",children:[c.jsxs("div",{children:[c.jsx("h2",{className:"text-xl font-black tracking-tight text-[var(--text)]",children:"Edit project overview"}),c.jsx("p",{className:"mt-2 text-sm text-[var(--text-muted)]",children:"Update the short dashboard summary and the longer project goal without changing the rest of the project metadata."})]}),c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Project name",children:c.jsx(ma,{name:"name",defaultValue:o.name,placeholder:"Project name",required:!0})}),c.jsx(lt,{label:"Short description",children:c.jsx(mn,{name:"description",defaultValue:o.description,placeholder:"Summarize the project in a few lines for the dashboard overview"})}),c.jsx(lt,{label:"Project goal",children:c.jsx(mn,{name:"goal",defaultValue:o.goal,placeholder:"Define the main objective, success criteria, and overall direction of the project"})}),c.jsxs("div",{className:"flex justify-end gap-3",children:[c.jsx(Ye,{to:"/",children:c.jsx(gt,{type:"button",variant:"ghost",children:"Cancel"})}),c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Saving…":"Save project overview"})]})]})]})]})}function RD(t){return`P${String(t.number??0).padStart(3,"0")}`}function Y0({phases:t,selectedIds:a=[]}){const l=new Set(a);return c.jsx(lt,{label:"Linked phases",children:t.length===0?c.jsx("div",{className:"rounded-[14px] border border-dashed border-[var(--border)] bg-[var(--surface-elevated)] px-4 py-3 text-sm text-[var(--text-muted)]",children:"No phases available yet. Create phases first if you want to link this requirement to delivery work."}):c.jsxs("div",{className:"grid gap-2 rounded-[16px] border border-[var(--border)] bg-[var(--surface-elevated)] p-3",children:[c.jsx("p",{className:"text-xs text-[var(--text-muted)]",children:"Select the phases that directly implement or track this requirement."}),c.jsx("div",{className:"grid gap-2 max-h-[32dvh] overflow-y-auto pr-1",children:t.map(s=>c.jsxs("label",{className:"flex items-start gap-3 rounded-[12px] border border-[var(--border)] bg-[var(--surface-card)] px-3 py-2 text-sm text-[var(--text)] transition hover:border-[var(--accent)] hover:bg-[var(--accent-soft)]",children:[c.jsx("input",{type:"checkbox",name:"linkedPhaseIds",value:s.id,defaultChecked:l.has(s.id),className:"mt-0.5 h-4 w-4 shrink-0 accent-[var(--accent)]"}),c.jsxs("span",{className:"min-w-0",children:[c.jsxs("span",{className:"block font-semibold",children:[RD(s)," — ",s.title]}),s.summary?c.jsx("span",{className:"mt-0.5 block text-xs text-[var(--text-muted)]",children:s.summary}):null]})]},s.id))})]})})}function jD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var u;return(u=l.current)==null?void 0:u.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const{phases:o}=gs("requirements");return c.jsx(ql,{title:"Create requirement",description:"Capture a top-level outcome that phases can implement and track.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Requirement title",children:c.jsx(ma,{name:"title",placeholder:"Self-hosted Claude Code plugin marketplace distribution",required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",placeholder:"Describe the user/business outcome this requirement represents"})}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:"planned",children:O0.map(u=>c.jsx("option",{value:u.value,children:u.label},u.value))})}),c.jsx(Y0,{phases:o}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Creating…":"Create requirement"})})]})})}function TD(){const a=Or().state!=="idle",l=v.useRef(null),s=v.useCallback(()=>{var p;return(p=l.current)==null?void 0:p.requestSubmit()},[]);An("submit",s,{allowInEditable:!0});const{requirementId:o}=rE(),{phases:u,requirements:f}=gs("requirements"),m=f.find(p=>p.id===o);return m?c.jsx(ql,{title:"Edit requirement",description:"Update status, scope notes, and linked delivery phases.",children:c.jsxs(ca,{ref:l,method:"post",className:"grid gap-4",children:[c.jsx(lt,{label:"Requirement title",children:c.jsx(ma,{name:"title",defaultValue:m.title,required:!0})}),c.jsx(lt,{label:"Description",children:c.jsx(mn,{name:"description",defaultValue:m.description})}),c.jsx(lt,{label:"Status",children:c.jsx(ys,{name:"status",defaultValue:m.status,children:O0.map(p=>c.jsx("option",{value:p.value,children:p.label},p.value))})}),c.jsx(Y0,{phases:u,selectedIds:m.linkedPhaseIds}),c.jsx("div",{className:"rounded-[14px] border border-[var(--border)] bg-[var(--surface-elevated)] px-4 py-3 text-sm text-[var(--text-muted)]",children:"Macro tasks are preserved automatically on save. This screen does not edit the nested macro-task list yet."}),c.jsx(Il,{children:c.jsx(gt,{type:"submit",variant:"primary",disabled:a,shortcut:"submit",children:a?"Saving…":"Save requirement"})})]})}):null}function Jn(t,a){const l=t.get(a);if(typeof l!="string"||l.trim()==="")throw new Response(`Missing field: ${a}`,{status:400});return l.trim()}function Bn(t,a){const l=t.get(a);return typeof l=="string"?l.trim():""}function Vm(t,a){const l=t.get(a);if(typeof l!="string")return 0;const s=l.trim();if(s==="")return 0;const o=Number(s);return Number.isFinite(o)?o:0}function _l(t,a){return Bn(t,a).split(`
293
- `).map(l=>l.trim()).filter(Boolean)}function sn(t,a){const l=t[a];if(!l)throw new Response(`Missing route param: ${a}`,{status:400});return l}async function CD({request:t}){const a=await t.formData();return await gR({name:Jn(a,"name"),description:Bn(a,"description")}),Ua("/features")}async function DD({request:t,params:a}){const l=sn(a,"featureId"),s=await Io(l),o=await t.formData();return await Yb({...s,name:Jn(o,"name"),description:Bn(o,"description"),startDate:Bn(o,"startDate"),endDate:Bn(o,"endDate"),status:Jn(o,"status"),priority:Vm(o,"priority"),workDone:Bn(o,"workDone"),workRemaining:Bn(o,"workRemaining")}),Ua(`/features/${l}`)}async function AD({params:t}){return await vR(sn(t,"featureId")),Ua("/features")}async function kD({request:t,params:a}){const l=sn(a,"featureId"),s=await Io(l),o=await t.formData();return await Yb({...s,status:Jn(o,"status")}),null}async function OD({request:t,params:a}){const l=sn(a,"featureId"),s=await t.formData();return await SR({featureId:l,title:Jn(s,"title"),summary:Bn(s,"summary"),description:Bn(s,"description")}),Ua(`/features/${l}`)}async function MD({request:t,params:a}){const l=sn(a,"featureId"),s=sn(a,"phaseId"),o=await Zc(s),u=await t.formData();return await Fb({...o,title:Jn(u,"title"),status:Jn(u,"status"),priority:Vm(u,"priority"),summary:Bn(u,"summary"),description:Bn(u,"description"),goals:_l(u,"goals"),nonGoals:_l(u,"nonGoals"),dependencies:_l(u,"dependencies"),risks:_l(u,"risks"),openQuestions:_l(u,"openQuestions"),completionCriteria:_l(u,"completionCriteria")}),Ua(`/features/${l}/phases/${s}`)}async function _D({params:t}){const a=sn(t,"featureId"),l=sn(t,"phaseId");return await wR(l),Ua(`/features/${a}`)}async function LD({request:t,params:a}){const l=sn(a,"phaseId"),s=await Zc(l),o=await t.formData();return await Fb({...s,status:Jn(o,"status")}),null}async function zD({request:t,params:a}){const l=sn(a,"featureId"),s=sn(a,"phaseId"),o=await t.formData(),u=_l(o,"checklist");return await ER(s,{title:Jn(o,"title"),description:Bn(o,"description"),status:Bn(o,"status")||"planned",...u.length?{checklist:u}:{}}),Ua(`/features/${l}/phases/${s}`)}function UD(t,a){const l=new Map(t.map(o=>[o.id,o])),s=new Map(t.map(o=>[o.title.trim().toLowerCase(),o]));return a.map((o,u)=>{var p;const f=o.trim().toLowerCase(),m=l.get(((p=t[u])==null?void 0:p.id)??"")??s.get(f);return m?{...m,number:u+1,title:o.trim()}:{id:`check-${u+1}-${f.replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"item"}`,number:u+1,title:o.trim(),checked:!1}})}async function BD({request:t,params:a}){const l=sn(a,"featureId"),s=sn(a,"phaseId"),o=sn(a,"taskId"),u=await Jc(o),f=await t.formData();return await ym({...u,phaseId:s,title:Jn(f,"title"),status:Jn(f,"status"),priority:Vm(f,"priority"),description:Bn(f,"description"),checklist:UD(u.checklist,_l(f,"checklist"))}),Ua(`/features/${l}/phases/${s}/tasks/${o}`)}async function HD({params:t}){const a=sn(t,"featureId"),l=sn(t,"phaseId"),s=sn(t,"taskId");return await NR(s),Ua(`/features/${a}/phases/${l}`)}async function $D({request:t,params:a}){const l=sn(a,"phaseId"),s=sn(a,"taskId"),o=await Jc(s),u=await t.formData();return await ym({...o,phaseId:l,status:Jn(u,"status")}),null}async function qD({request:t}){const a=await Ib(),l=await t.formData();return await mR({...a,name:Bn(l,"name")||a.name,description:Bn(l,"description"),goal:Bn(l,"goal")}),Ua("/")}async function ID({request:t}){const a=await t.formData();return await yR({id:crypto.randomUUID(),title:Jn(a,"title"),description:Bn(a,"description"),status:Jn(a,"status"),linkedPhaseIds:a.getAll("linkedPhaseIds").filter(l=>typeof l=="string").map(l=>l.trim()).filter(Boolean)}),Ua("/requirements")}async function VD({request:t,params:a}){const l=sn(a,"requirementId"),s=(await vm()).find(u=>u.id===l);if(!s)throw new Response(`Requirement not found: ${l}`,{status:404});const o=await t.formData();return await xR({...s,title:Jn(o,"title"),description:Bn(o,"description"),status:Jn(o,"status"),linkedPhaseIds:o.getAll("linkedPhaseIds").filter(u=>typeof u=="string").map(u=>u.trim()).filter(Boolean)}),Ua("/requirements")}async function YD({params:t}){return await bR(sn(t,"requirementId")),Ua("/requirements")}function FD(t){if(!t)return"—";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}async function PD(){return{handoffs:await Yh()}}function GD(){const{handoffs:t}=ll(),[a,l]=v.useState(t),[s,o]=v.useState(null),[u,f]=v.useState(""),m=hr();async function p(g){if(!(s||!window.confirm(`Clear handoff for ${g.compositeRef}?`))){o(g.phaseId),f("");try{await Gb(g.phaseId),l(y=>y.filter(N=>N.phaseId!==g.phaseId)),Yh().then(l).catch(()=>{})}catch(y){const N=y instanceof Error?y.message:String(y);f(N||`Failed to clear handoff for ${g.compositeRef}.`)}finally{o(null)}}}return v.useEffect(()=>{const g=x=>{const y=x.detail;((y==null?void 0:y.type)==="handoffUpdated"||(y==null?void 0:y.type)==="handoffCleared")&&Yh().then(l).catch(()=>{})};return window.addEventListener("agent-plan:ws-event",g),()=>window.removeEventListener("agent-plan:ws-event",g)},[]),v.useEffect(()=>{if(!m.hash)return;const g=m.hash.slice(1),x=document.getElementById(g);x&&x.scrollIntoView({behavior:"smooth",block:"start"})},[m.hash,a]),a.length===0?c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Phase handoffs"}),c.jsx(Ye,{to:"/handoff/archive",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"View archive →"})]}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Pending entity-scoped handoffs on non-completed phases."})]}),u?c.jsx("p",{className:"rounded-[12px] border border-[var(--danger-soft)] bg-[var(--danger-soft)]/50 px-3 py-2 text-sm text-[var(--color-status-blocked)]",children:u}):null,c.jsx("p",{className:"py-8 text-center text-sm text-[var(--text-muted)]",children:"No pending phase handoffs."})]}):c.jsxs("div",{className:"grid gap-4",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Phase handoffs"}),c.jsx(Ye,{to:"/handoff/archive",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"View archive →"})]}),c.jsxs("p",{className:"text-sm text-[var(--text-muted)]",children:["Pending entity-scoped handoffs on non-completed phases. ",a.length," pending."]})]}),u?c.jsx("p",{className:"rounded-[12px] border border-[var(--danger-soft)] bg-[var(--danger-soft)]/50 px-3 py-2 text-sm text-[var(--color-status-blocked)]",children:u}):null,a.map(g=>c.jsx("section",{id:g.phaseId,className:"scroll-mt-20",children:c.jsx(Pt,{className:"overflow-hidden p-0",children:c.jsx(ua,{defaultOpen:!1,title:c.jsxs(c.Fragment,{children:[c.jsx(mr,{id:g.compositeRef,children:g.compositeRef}),c.jsxs("span",{className:"text-xs font-normal text-[var(--text-muted)]",children:["Updated ",FD(g.updatedAt)]})]}),subtitle:g.firstLine||"Empty handoff content.",summaryClassName:"hover:bg-[var(--surface-hover)]/60 focus-visible:bg-[var(--surface-hover)]/60",actions:c.jsxs(c.Fragment,{children:[c.jsx(gt,{type:"button",variant:"danger",className:"min-h-8 px-2.5 py-1 text-xs sm:min-h-9",disabled:s===g.phaseId,onClick:x=>{x.preventDefault(),x.stopPropagation(),p(g)},children:s===g.phaseId?"Clearing…":"Clear"}),c.jsx(Ye,{to:g.featureId?`/features/${g.featureId}/phases/${g.phaseId}`:"/features",className:"text-xs text-[var(--text-muted)] underline-offset-2 hover:text-[var(--text)] hover:underline",onClick:x=>x.stopPropagation(),children:g.featureId?"Open phase →":"Browse features →"})]}),contentClassName:"px-5 py-5",children:g.firstLine?c.jsx(xn,{text:g.content,className:"formatted-text max-w-none"}):c.jsx("p",{className:"text-sm italic text-[var(--text-muted)]",children:"Empty handoff content."})})})},g.phaseId))]})}function XD(t){if(!t)return"—";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}async function QD(){return{archived:await RR()}}function KD(){const{archived:t}=ll();return t.length===0?c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Archived handoffs"}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Completed, superseded, and manually cleared handoffs."})]}),c.jsx(Ye,{to:"/handoff",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"← Pending handoffs"})]}),c.jsx("p",{className:"py-8 text-center text-sm text-[var(--text-muted)]",children:"No archived handoffs."})]}):c.jsxs("div",{className:"grid gap-4",children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Archived handoffs"}),c.jsxs("p",{className:"text-sm text-[var(--text-muted)]",children:[t.length," archived entries. These are history, not pending resume context."]})]}),c.jsx(Ye,{to:"/handoff",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"← Pending handoffs"})]}),t.map(a=>c.jsx(Pt,{className:"overflow-hidden p-0",children:c.jsxs(ua,{defaultOpen:!1,title:c.jsxs(c.Fragment,{children:[c.jsx(mr,{id:a.compositeRef,children:a.compositeRef}),c.jsxs("span",{className:"text-xs font-normal text-[var(--text-muted)]",children:["Archived ",XD(a.archivedAt)]})]}),subtitle:a.firstLine||"Empty archived handoff.",contentClassName:"px-5 py-5",children:[c.jsxs("div",{className:"mb-3 flex flex-wrap gap-2 text-xs text-[var(--text-muted)]",children:[c.jsxs("span",{children:["Reason: ",a.reason||"unknown"]}),c.jsxs("span",{className:"break-all",children:["File: ",a.file]})]}),c.jsx(xn,{text:a.content||"(archive file unavailable)",className:"formatted-text max-w-none"})]})},`${a.phaseId}:${a.file}`))]})}async function ZD({request:t,params:a}){sn(a,"featureId");const l=sn(a,"phaseId"),s=sn(a,"taskId"),o=sn(a,"itemId"),u=await t.formData(),f=Jn(u,"checked")==="true",m=await Jc(s);return await ym({...m,phaseId:l,checklist:m.checklist.map(p=>p.id===o?{...p,checked:f}:p)}),Response.json({ok:!0,taskId:s,itemId:o,checked:f})}const JD=QE([{id:"root",path:"/",loader:ZR,element:c.jsx(JR,{}),errorElement:c.jsx(WR,{}),children:[{index:!0,loader:e2,element:c.jsx($C,{})},{path:"features",id:"features",loader:qC,element:c.jsx(GC,{}),children:[{path:"new",element:c.jsx(vD,{}),action:CD}]},{path:"features/:featureId",id:"feature-detail",loader:JC,element:c.jsx(oD,{}),children:[{path:"edit",element:c.jsx(yD,{}),action:DD},{path:"phases/new",element:c.jsx(xD,{}),action:OD}]},{path:"requirements",id:"requirements",loader:XC,element:c.jsx(ZC,{}),children:[{path:"new",element:c.jsx(jD,{}),action:ID},{path:":requirementId/edit",element:c.jsx(TD,{}),action:VD}]},{path:"project/edit",element:c.jsx(ND,{}),action:qD},{path:"handoff",loader:PD,element:c.jsx(GD,{})},{path:"handoff/archive",loader:QD,element:c.jsx(KD,{})},{path:"features/:featureId/delete",action:AD},{path:"requirements/:requirementId/delete",action:YD},{path:"features/:featureId/status",action:kD},{path:"features/:featureId/phases/:phaseId",id:"phase-detail",loader:uD,element:c.jsx(fD,{}),children:[{path:"edit",element:c.jsx(bD,{}),action:MD},{path:"tasks/new",element:c.jsx(SD,{}),action:zD}]},{path:"features/:featureId/phases/:phaseId/delete",action:_D},{path:"features/:featureId/phases/:phaseId/status",action:LD},{path:"features/:featureId/phases/:phaseId/tasks/:taskId",id:"task-detail",loader:hD,element:c.jsx(pD,{}),children:[{path:"edit",element:c.jsx(ED,{}),action:BD}]},{path:"features/:featureId/phases/:phaseId/tasks/:taskId/delete",action:HD},{path:"features/:featureId/phases/:phaseId/tasks/:taskId/status",action:$D},{path:"features/:featureId/phases/:phaseId/tasks/:taskId/checklist/:itemId/toggle",action:ZD}]}]),F0=document.getElementById("root");if(!F0)throw new Error("#root not found");BS.createRoot(F0).render(c.jsx(v.StrictMode,{children:c.jsx(rN,{router:JD})}));
293
+ `).map(l=>l.trim()).filter(Boolean)}function sn(t,a){const l=t[a];if(!l)throw new Response(`Missing route param: ${a}`,{status:400});return l}async function CD({request:t}){const a=await t.formData();return await gR({name:Jn(a,"name"),description:Bn(a,"description")}),Ua("/features")}async function DD({request:t,params:a}){const l=sn(a,"featureId"),s=await Io(l),o=await t.formData();return await Yb({...s,name:Jn(o,"name"),description:Bn(o,"description"),startDate:Bn(o,"startDate"),endDate:Bn(o,"endDate"),status:Jn(o,"status"),priority:Vm(o,"priority"),workDone:Bn(o,"workDone"),workRemaining:Bn(o,"workRemaining")}),Ua(`/features/${l}`)}async function AD({params:t}){return await vR(sn(t,"featureId")),Ua("/features")}async function kD({request:t,params:a}){const l=sn(a,"featureId"),s=await Io(l),o=await t.formData();return await Yb({...s,status:Jn(o,"status")}),null}async function OD({request:t,params:a}){const l=sn(a,"featureId"),s=await t.formData();return await SR({featureId:l,title:Jn(s,"title"),summary:Bn(s,"summary"),description:Bn(s,"description")}),Ua(`/features/${l}`)}async function MD({request:t,params:a}){const l=sn(a,"featureId"),s=sn(a,"phaseId"),o=await Zc(s),u=await t.formData();return await Fb({...o,title:Jn(u,"title"),status:Jn(u,"status"),priority:Vm(u,"priority"),summary:Bn(u,"summary"),description:Bn(u,"description"),goals:_l(u,"goals"),nonGoals:_l(u,"nonGoals"),dependencies:_l(u,"dependencies"),risks:_l(u,"risks"),openQuestions:_l(u,"openQuestions"),completionCriteria:_l(u,"completionCriteria")}),Ua(`/features/${l}/phases/${s}`)}async function _D({params:t}){const a=sn(t,"featureId"),l=sn(t,"phaseId");return await wR(l),Ua(`/features/${a}`)}async function LD({request:t,params:a}){const l=sn(a,"phaseId"),s=await Zc(l),o=await t.formData();return await Fb({...s,status:Jn(o,"status")}),null}async function zD({request:t,params:a}){const l=sn(a,"featureId"),s=sn(a,"phaseId"),o=await t.formData(),u=_l(o,"checklist");return await ER(s,{title:Jn(o,"title"),description:Bn(o,"description"),status:Bn(o,"status")||"planned",...u.length?{checklist:u}:{}}),Ua(`/features/${l}/phases/${s}`)}function UD(t,a){const l=new Map(t.map(o=>[o.id,o])),s=new Map(t.map(o=>[o.title.trim().toLowerCase(),o]));return a.map((o,u)=>{var p;const f=o.trim().toLowerCase(),m=l.get(((p=t[u])==null?void 0:p.id)??"")??s.get(f);return m?{...m,number:u+1,title:o.trim()}:{id:`check-${u+1}-${f.replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"item"}`,number:u+1,title:o.trim(),checked:!1}})}async function BD({request:t,params:a}){const l=sn(a,"featureId"),s=sn(a,"phaseId"),o=sn(a,"taskId"),u=await Jc(o),f=await t.formData();return await ym({...u,phaseId:s,title:Jn(f,"title"),status:Jn(f,"status"),priority:Vm(f,"priority"),description:Bn(f,"description"),checklist:UD(u.checklist,_l(f,"checklist"))}),Ua(`/features/${l}/phases/${s}/tasks/${o}`)}async function HD({params:t}){const a=sn(t,"featureId"),l=sn(t,"phaseId"),s=sn(t,"taskId");return await NR(s),Ua(`/features/${a}/phases/${l}`)}async function $D({request:t,params:a}){const l=sn(a,"phaseId"),s=sn(a,"taskId"),o=await Jc(s),u=await t.formData();return await ym({...o,phaseId:l,status:Jn(u,"status")}),null}async function qD({request:t}){const a=await Ib(),l=await t.formData();return await mR({...a,name:Bn(l,"name")||a.name,description:Bn(l,"description"),goal:Bn(l,"goal")}),Ua("/")}async function ID({request:t}){const a=await t.formData();return await yR({id:crypto.randomUUID(),title:Jn(a,"title"),description:Bn(a,"description"),status:Jn(a,"status"),linkedPhaseIds:a.getAll("linkedPhaseIds").filter(l=>typeof l=="string").map(l=>l.trim()).filter(Boolean)}),Ua("/requirements")}async function VD({request:t,params:a}){const l=sn(a,"requirementId"),s=(await vm()).find(u=>u.id===l);if(!s)throw new Response(`Requirement not found: ${l}`,{status:404});const o=await t.formData();return await xR({...s,title:Jn(o,"title"),description:Bn(o,"description"),status:Jn(o,"status"),linkedPhaseIds:o.getAll("linkedPhaseIds").filter(u=>typeof u=="string").map(u=>u.trim()).filter(Boolean)}),Ua("/requirements")}async function YD({params:t}){return await bR(sn(t,"requirementId")),Ua("/requirements")}function FD(t){if(!t)return"—";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}async function PD(){return{handoffs:await Yh()}}function GD(){const{handoffs:t}=ll(),[a,l]=v.useState(t),[s,o]=v.useState(null),[u,f]=v.useState(""),m=hr();async function p(g){if(!(s||!window.confirm(`Clear handoff for ${g.compositeRef}?`))){o(g.phaseId),f("");try{await Gb(g.phaseId),l(y=>y.filter(N=>N.phaseId!==g.phaseId)),Yh().then(l).catch(()=>{})}catch(y){const N=y instanceof Response?await y.text().catch(()=>""):y instanceof Error?y.message:String(y);f(N||`Failed to clear handoff for ${g.compositeRef}.`)}finally{o(null)}}}return v.useEffect(()=>{const g=x=>{const y=x.detail;((y==null?void 0:y.type)==="handoffUpdated"||(y==null?void 0:y.type)==="handoffCleared")&&Yh().then(l).catch(()=>{})};return window.addEventListener("agent-plan:ws-event",g),()=>window.removeEventListener("agent-plan:ws-event",g)},[]),v.useEffect(()=>{if(!m.hash)return;const g=m.hash.slice(1),x=document.getElementById(g);x&&x.scrollIntoView({behavior:"smooth",block:"start"})},[m.hash,a]),a.length===0?c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Phase handoffs"}),c.jsx(Ye,{to:"/handoff/archive",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"View archive →"})]}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Pending entity-scoped handoffs on non-completed phases."})]}),u?c.jsx("p",{className:"rounded-[12px] border border-[var(--danger-soft)] bg-[var(--danger-soft)]/50 px-3 py-2 text-sm text-[var(--color-status-blocked)]",children:u}):null,c.jsx("p",{className:"py-8 text-center text-sm text-[var(--text-muted)]",children:"No pending phase handoffs."})]}):c.jsxs("div",{className:"grid gap-4",children:[c.jsxs("div",{children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Phase handoffs"}),c.jsx(Ye,{to:"/handoff/archive",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"View archive →"})]}),c.jsxs("p",{className:"text-sm text-[var(--text-muted)]",children:["Pending entity-scoped handoffs on non-completed phases. ",a.length," pending."]})]}),u?c.jsx("p",{className:"rounded-[12px] border border-[var(--danger-soft)] bg-[var(--danger-soft)]/50 px-3 py-2 text-sm text-[var(--color-status-blocked)]",children:u}):null,a.map(g=>c.jsx("section",{id:g.phaseId,className:"scroll-mt-20",children:c.jsx(Pt,{className:"overflow-hidden p-0",children:c.jsx(ua,{defaultOpen:!1,title:c.jsxs(c.Fragment,{children:[c.jsx(mr,{id:g.compositeRef,children:g.compositeRef}),c.jsxs("span",{className:"text-xs font-normal text-[var(--text-muted)]",children:["Updated ",FD(g.updatedAt)]})]}),subtitle:g.firstLine||"Empty handoff content.",summaryClassName:"hover:bg-[var(--surface-hover)]/60 focus-visible:bg-[var(--surface-hover)]/60",actions:c.jsxs(c.Fragment,{children:[c.jsx(gt,{type:"button",variant:"danger",className:"min-h-8 px-2.5 py-1 text-xs sm:min-h-9",disabled:s===g.phaseId,onClick:x=>{x.preventDefault(),x.stopPropagation(),p(g)},children:s===g.phaseId?"Clearing…":"Clear"}),c.jsx(Ye,{to:g.featureId?`/features/${g.featureId}/phases/${g.phaseId}`:"/features",className:"text-xs text-[var(--text-muted)] underline-offset-2 hover:text-[var(--text)] hover:underline",onClick:x=>x.stopPropagation(),children:g.featureId?"Open phase →":"Browse features →"})]}),contentClassName:"px-5 py-5",children:g.firstLine?c.jsx(xn,{text:g.content,className:"formatted-text max-w-none"}):c.jsx("p",{className:"text-sm italic text-[var(--text-muted)]",children:"Empty handoff content."})})})},g.phaseId))]})}function XD(t){if(!t)return"—";try{return new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}).format(new Date(t))}catch{return t}}async function QD(){return{archived:await RR()}}function KD(){const{archived:t}=ll();return t.length===0?c.jsxs(Pt,{className:"grid gap-4",children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Archived handoffs"}),c.jsx("p",{className:"text-sm text-[var(--text-muted)]",children:"Completed, superseded, and manually cleared handoffs."})]}),c.jsx(Ye,{to:"/handoff",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"← Pending handoffs"})]}),c.jsx("p",{className:"py-8 text-center text-sm text-[var(--text-muted)]",children:"No archived handoffs."})]}):c.jsxs("div",{className:"grid gap-4",children:[c.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[c.jsxs("div",{children:[c.jsx("h1",{className:"text-lg font-bold text-[var(--text)]",children:"Archived handoffs"}),c.jsxs("p",{className:"text-sm text-[var(--text-muted)]",children:[t.length," archived entries. These are history, not pending resume context."]})]}),c.jsx(Ye,{to:"/handoff",className:"text-sm text-[var(--accent)] underline-offset-2 hover:underline",children:"← Pending handoffs"})]}),t.map(a=>c.jsx(Pt,{className:"overflow-hidden p-0",children:c.jsxs(ua,{defaultOpen:!1,title:c.jsxs(c.Fragment,{children:[c.jsx(mr,{id:a.compositeRef,children:a.compositeRef}),c.jsxs("span",{className:"text-xs font-normal text-[var(--text-muted)]",children:["Archived ",XD(a.archivedAt)]})]}),subtitle:a.firstLine||"Empty archived handoff.",contentClassName:"px-5 py-5",children:[c.jsxs("div",{className:"mb-3 flex flex-wrap gap-2 text-xs text-[var(--text-muted)]",children:[c.jsxs("span",{children:["Reason: ",a.reason||"unknown"]}),c.jsxs("span",{className:"break-all",children:["File: ",a.file]})]}),c.jsx(xn,{text:a.content||"(archive file unavailable)",className:"formatted-text max-w-none"})]})},`${a.phaseId}:${a.file}`))]})}async function ZD({request:t,params:a}){sn(a,"featureId");const l=sn(a,"phaseId"),s=sn(a,"taskId"),o=sn(a,"itemId"),u=await t.formData(),f=Jn(u,"checked")==="true",m=await Jc(s);return await ym({...m,phaseId:l,checklist:m.checklist.map(p=>p.id===o?{...p,checked:f}:p)}),Response.json({ok:!0,taskId:s,itemId:o,checked:f})}const JD=QE([{id:"root",path:"/",loader:ZR,element:c.jsx(JR,{}),errorElement:c.jsx(WR,{}),children:[{index:!0,loader:e2,element:c.jsx($C,{})},{path:"features",id:"features",loader:qC,element:c.jsx(GC,{}),children:[{path:"new",element:c.jsx(vD,{}),action:CD}]},{path:"features/:featureId",id:"feature-detail",loader:JC,element:c.jsx(oD,{}),children:[{path:"edit",element:c.jsx(yD,{}),action:DD},{path:"phases/new",element:c.jsx(xD,{}),action:OD}]},{path:"requirements",id:"requirements",loader:XC,element:c.jsx(ZC,{}),children:[{path:"new",element:c.jsx(jD,{}),action:ID},{path:":requirementId/edit",element:c.jsx(TD,{}),action:VD}]},{path:"project/edit",element:c.jsx(ND,{}),action:qD},{path:"handoff",loader:PD,element:c.jsx(GD,{})},{path:"handoff/archive",loader:QD,element:c.jsx(KD,{})},{path:"features/:featureId/delete",action:AD},{path:"requirements/:requirementId/delete",action:YD},{path:"features/:featureId/status",action:kD},{path:"features/:featureId/phases/:phaseId",id:"phase-detail",loader:uD,element:c.jsx(fD,{}),children:[{path:"edit",element:c.jsx(bD,{}),action:MD},{path:"tasks/new",element:c.jsx(SD,{}),action:zD}]},{path:"features/:featureId/phases/:phaseId/delete",action:_D},{path:"features/:featureId/phases/:phaseId/status",action:LD},{path:"features/:featureId/phases/:phaseId/tasks/:taskId",id:"task-detail",loader:hD,element:c.jsx(pD,{}),children:[{path:"edit",element:c.jsx(ED,{}),action:BD}]},{path:"features/:featureId/phases/:phaseId/tasks/:taskId/delete",action:HD},{path:"features/:featureId/phases/:phaseId/tasks/:taskId/status",action:$D},{path:"features/:featureId/phases/:phaseId/tasks/:taskId/checklist/:itemId/toggle",action:ZD}]}]),F0=document.getElementById("root");if(!F0)throw new Error("#root not found");BS.createRoot(F0).render(c.jsx(v.StrictMode,{children:c.jsx(rN,{router:JD})}));
@@ -5,7 +5,7 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <title>Agent Plan</title>
7
7
  <link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Ccircle cx='16' cy='16' r='13' fill='%237b68ee'/%3E%3Ctext x='16' y='17' text-anchor='middle' dominant-baseline='middle' font-size='16' font-weight='bold' fill='white'%3EA%3C/text%3E%3C/svg%3E" />
8
- <script type="module" crossorigin src="/assets/index-DN-Mv6Vq.js"></script>
8
+ <script type="module" crossorigin src="/assets/index-rFM0JSW_.js"></script>
9
9
  <link rel="stylesheet" crossorigin href="/assets/index-CTAfas5X.css">
10
10
  </head>
11
11
  <body>