@useorgx/openclaw-plugin 0.7.0 → 0.7.2

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.
Files changed (122) hide show
  1. package/README.md +42 -11
  2. package/dashboard/dist/assets/6mILZQ2a.js +1 -0
  3. package/dashboard/dist/assets/6mILZQ2a.js.br +0 -0
  4. package/dashboard/dist/assets/6mILZQ2a.js.gz +0 -0
  5. package/dashboard/dist/assets/{DG6y9wJI.js → 8dksYiq4.js} +1 -1
  6. package/dashboard/dist/assets/8dksYiq4.js.br +0 -0
  7. package/dashboard/dist/assets/8dksYiq4.js.gz +0 -0
  8. package/dashboard/dist/assets/{PAUiij_z.js → B5zYRHc3.js} +1 -1
  9. package/dashboard/dist/assets/B5zYRHc3.js.br +0 -0
  10. package/dashboard/dist/assets/B5zYRHc3.js.gz +0 -0
  11. package/dashboard/dist/assets/{CFGKRAzG.js → B6wPWJ35.js} +1 -1
  12. package/dashboard/dist/assets/B6wPWJ35.js.br +0 -0
  13. package/dashboard/dist/assets/B6wPWJ35.js.gz +0 -0
  14. package/dashboard/dist/assets/BWEwjt1W.js +1 -0
  15. package/dashboard/dist/assets/BWEwjt1W.js.br +0 -0
  16. package/dashboard/dist/assets/BWEwjt1W.js.gz +0 -0
  17. package/dashboard/dist/assets/BzRbDCAD.css +1 -0
  18. package/dashboard/dist/assets/BzRbDCAD.css.br +0 -0
  19. package/dashboard/dist/assets/BzRbDCAD.css.gz +0 -0
  20. package/dashboard/dist/assets/{DNxKz-GV.js → C8uM3AX8.js} +1 -1
  21. package/dashboard/dist/assets/C8uM3AX8.js.br +0 -0
  22. package/dashboard/dist/assets/C8uM3AX8.js.gz +0 -0
  23. package/dashboard/dist/assets/C9jy61eu.js +212 -0
  24. package/dashboard/dist/assets/C9jy61eu.js.br +0 -0
  25. package/dashboard/dist/assets/C9jy61eu.js.gz +0 -0
  26. package/dashboard/dist/assets/{CE38zU4U.js → CC63EwFD.js} +1 -1
  27. package/dashboard/dist/assets/CC63EwFD.js.br +0 -0
  28. package/dashboard/dist/assets/CC63EwFD.js.gz +0 -0
  29. package/dashboard/dist/assets/{nByHNHoW.js → CZaT3ob_.js} +1 -1
  30. package/dashboard/dist/assets/CZaT3ob_.js.br +0 -0
  31. package/dashboard/dist/assets/CZaT3ob_.js.gz +0 -0
  32. package/dashboard/dist/assets/{tS9mbYZi.js → CgaottFX.js} +1 -1
  33. package/dashboard/dist/assets/CgaottFX.js.br +0 -0
  34. package/dashboard/dist/assets/CgaottFX.js.gz +0 -0
  35. package/dashboard/dist/assets/CzCxAZlW.js +1 -0
  36. package/dashboard/dist/assets/CzCxAZlW.js.br +0 -0
  37. package/dashboard/dist/assets/CzCxAZlW.js.gz +0 -0
  38. package/dashboard/dist/assets/D3iMTYEj.js +1 -0
  39. package/dashboard/dist/assets/D3iMTYEj.js.br +0 -0
  40. package/dashboard/dist/assets/D3iMTYEj.js.gz +0 -0
  41. package/dashboard/dist/assets/{DjcdE6jC.js → D8JNX8kq.js} +1 -1
  42. package/dashboard/dist/assets/D8JNX8kq.js.br +0 -0
  43. package/dashboard/dist/assets/D8JNX8kq.js.gz +0 -0
  44. package/dashboard/dist/assets/DnA8dpj6.js +1 -0
  45. package/dashboard/dist/assets/DnA8dpj6.js.br +0 -0
  46. package/dashboard/dist/assets/DnA8dpj6.js.gz +0 -0
  47. package/dashboard/dist/assets/{DbNoijHm.js → IUexzymk.js} +1 -1
  48. package/dashboard/dist/assets/IUexzymk.js.br +0 -0
  49. package/dashboard/dist/assets/IUexzymk.js.gz +0 -0
  50. package/dashboard/dist/assets/{CZZTvkQZ.js → rttbDbEx.js} +1 -1
  51. package/dashboard/dist/assets/rttbDbEx.js.br +0 -0
  52. package/dashboard/dist/assets/rttbDbEx.js.gz +0 -0
  53. package/dashboard/dist/index.html +2 -2
  54. package/dashboard/dist/index.html.br +0 -0
  55. package/dashboard/dist/index.html.gz +0 -0
  56. package/dist/contracts/practice-exercise-schema.d.ts +216 -0
  57. package/dist/contracts/practice-exercise-schema.js +314 -0
  58. package/dist/contracts/shared-types.d.ts +2 -2
  59. package/dist/contracts/shared-types.js +22 -0
  60. package/dist/contracts/types.d.ts +20 -0
  61. package/dist/fs-utils.js +1 -13
  62. package/dist/http/helpers/auto-continue-engine.js +638 -24
  63. package/dist/http/helpers/autopilot-runtime.js +22 -7
  64. package/dist/http/helpers/autopilot-slice-utils.js +0 -2
  65. package/dist/http/helpers/kickoff-context.js +30 -0
  66. package/dist/http/helpers/slice-run-projections.js +19 -2
  67. package/dist/http/index.js +151 -93
  68. package/dist/http/routes/agent-suite.js +87 -0
  69. package/dist/http/routes/entities.js +1 -63
  70. package/dist/http/routes/live-snapshot.d.ts +1 -0
  71. package/dist/http/routes/live-snapshot.js +15 -4
  72. package/dist/http/routes/live-terminal.js +1 -108
  73. package/dist/http/routes/live-triage.js +1 -57
  74. package/dist/http/routes/mission-control-actions.js +0 -88
  75. package/dist/http/routes/mission-control-read.js +73 -8
  76. package/dist/mcp-http-handler.d.ts +3 -0
  77. package/dist/mcp-http-handler.js +2 -2
  78. package/dist/paths.js +14 -2
  79. package/dist/reporting/rollups.d.ts +0 -12
  80. package/dist/reporting/rollups.js +0 -35
  81. package/package.json +7 -3
  82. package/dashboard/dist/assets/BXWDRGm-.js +0 -1
  83. package/dashboard/dist/assets/BXWDRGm-.js.br +0 -0
  84. package/dashboard/dist/assets/BXWDRGm-.js.gz +0 -0
  85. package/dashboard/dist/assets/CE38zU4U.js.br +0 -0
  86. package/dashboard/dist/assets/CE38zU4U.js.gz +0 -0
  87. package/dashboard/dist/assets/CFGKRAzG.js.br +0 -0
  88. package/dashboard/dist/assets/CFGKRAzG.js.gz +0 -0
  89. package/dashboard/dist/assets/CGGR2GZh.js +0 -1
  90. package/dashboard/dist/assets/CGGR2GZh.js.br +0 -0
  91. package/dashboard/dist/assets/CGGR2GZh.js.gz +0 -0
  92. package/dashboard/dist/assets/CPFiTmlw.js +0 -8
  93. package/dashboard/dist/assets/CPFiTmlw.js.br +0 -0
  94. package/dashboard/dist/assets/CPFiTmlw.js.gz +0 -0
  95. package/dashboard/dist/assets/CZZTvkQZ.js.br +0 -0
  96. package/dashboard/dist/assets/CZZTvkQZ.js.gz +0 -0
  97. package/dashboard/dist/assets/D-bf6hEI.js +0 -213
  98. package/dashboard/dist/assets/D-bf6hEI.js.br +0 -0
  99. package/dashboard/dist/assets/D-bf6hEI.js.gz +0 -0
  100. package/dashboard/dist/assets/DG6y9wJI.js.br +0 -0
  101. package/dashboard/dist/assets/DG6y9wJI.js.gz +0 -0
  102. package/dashboard/dist/assets/DNxKz-GV.js.br +0 -0
  103. package/dashboard/dist/assets/DNxKz-GV.js.gz +0 -0
  104. package/dashboard/dist/assets/DW_rKUic.js +0 -11
  105. package/dashboard/dist/assets/DW_rKUic.js.br +0 -0
  106. package/dashboard/dist/assets/DW_rKUic.js.gz +0 -0
  107. package/dashboard/dist/assets/DbNoijHm.js.br +0 -0
  108. package/dashboard/dist/assets/DbNoijHm.js.gz +0 -0
  109. package/dashboard/dist/assets/DjcdE6jC.js.br +0 -0
  110. package/dashboard/dist/assets/DjcdE6jC.js.gz +0 -0
  111. package/dashboard/dist/assets/FZYuCDnt.js +0 -1
  112. package/dashboard/dist/assets/FZYuCDnt.js.br +0 -0
  113. package/dashboard/dist/assets/FZYuCDnt.js.gz +0 -0
  114. package/dashboard/dist/assets/PAUiij_z.js.br +0 -0
  115. package/dashboard/dist/assets/PAUiij_z.js.gz +0 -0
  116. package/dashboard/dist/assets/h5biQs2I.css +0 -1
  117. package/dashboard/dist/assets/h5biQs2I.css.br +0 -0
  118. package/dashboard/dist/assets/h5biQs2I.css.gz +0 -0
  119. package/dashboard/dist/assets/nByHNHoW.js.br +0 -0
  120. package/dashboard/dist/assets/nByHNHoW.js.gz +0 -0
  121. package/dashboard/dist/assets/tS9mbYZi.js.br +0 -0
  122. package/dashboard/dist/assets/tS9mbYZi.js.gz +0 -0
@@ -0,0 +1 @@
1
+ import{r as a,u as Vs,a as Zt,b as Nt,j as e}from"./cNrhgGc1.js";import{i as os,q as Ot,b as xt,p as Nr,a as Sr,t as Cr,h as ct,c as Fr,E as Ge,d as Y,n as Er,u as ls,f as Oe,A as Vn,s as gs,e as ws,g as Ps,j as bs,I as vs,P as Ar,k as Ir,l as Kn,m as Gn,o as Ks,M as Dr,r as Mr,v as gn,w as Lt,x as es,y as Gs,z as Jn,B as $r,C as bn,U as Tr,D as _r}from"./C9jy61eu.js";import{I as Yn,o as Br,N as yn}from"./6mILZQ2a.js";import{S as yt}from"./CZaT3ob_.js";import{A as pt,m as ge,R as Lr,a as Pr,L as Rr}from"./CxQ08qFN.js";import{E as js}from"./C8uM3AX8.js";import"./C-KIc3Wc.js";import"./BJgZIVUQ.js";function qr({activities:t,agents:s,initiatives:r}){return a.useMemo(()=>{const n=new Map,c=(o,d,h,b)=>{const j=n.get(o)??[];j.some(x=>x.id===d)||(j.push({id:d,name:h,confidence:b}),n.set(o,j))};return t.forEach(o=>{const d="metadata"in o&&o.metadata&&typeof o.metadata=="object"?o.metadata:null,h=d&&typeof d=="object"?d:{},b=("initiativeId"in o&&typeof o.initiativeId=="string"?o.initiativeId:void 0)??h.initiativeId??void 0,j=o.agentId??void 0,x=("agentName"in o&&typeof o.agentName=="string"?o.agentName:"agent"in o&&typeof o.agent=="string"?o.agent:void 0)??j??"Unknown";b&&j&&c(b,j,x,"high")}),r.forEach(o=>{var d;(d=o.avatars)!=null&&d.length&&o.avatars.forEach(h=>{const b=s.find(j=>j.name.toLowerCase()===h.toLowerCase());b?c(o.id,b.id,b.name,"medium"):c(o.id,`avatar:${h}`,h,"medium")})}),s.forEach(o=>{if(!o.task)return;const d=o.task.toLowerCase();r.forEach(h=>{h.name.toLowerCase().split(/\s+/).filter(F=>F.length>3).some(F=>d.includes(F))&&c(h.id,o.id,o.name,"low")})}),n},[t,s,r])}function Or({initiativeId:t=null,authToken:s=null,embedMode:r=!1,enabled:n=!0}){var N,l,y;const c=Vs(),o=os(),d=a.useMemo(()=>Ot.autoContinueStatus({initiativeId:t??"__global__",authToken:s,embedMode:r}),[t,s,r]),h=Zt({queryKey:d,enabled:n&&(!!t||t===null),queryFn:async()=>{if(o)return{ok:!0,initiativeId:t,run:null,defaults:{tokenBudget:null,tickMs:0}};const u=new URLSearchParams;t&&u.set("initiative_id",t);const w=await fetch(`/orgx/api/mission-control/auto-continue/status?${u.toString()}`,{headers:xt({authToken:s,embedMode:r})}),k=await w.json().catch(()=>null);if(!w.ok){const g=typeof(k==null?void 0:k.error)=="string"&&k.error||typeof(k==null?void 0:k.message)=="string"&&k.message||`Failed to load auto-continue status (${w.status})`;return{ok:!1,initiativeId:t,run:null,defaults:{tokenBudget:null,tickMs:0},error:g}}return k},refetchInterval:u=>{var T,U;const w=u.state.data;if((w==null?void 0:w.ok)===!1)return!1;const k=((T=w==null?void 0:w.error)==null?void 0:T.toLowerCase())??"";if(k.includes("404")||k.includes("400")||k.includes("not found")||k.includes("bad request"))return!1;const C=((U=w==null?void 0:w.run)==null?void 0:U.status)??null;return C==="running"||C==="stopping"?2500:12e3}}),b=async()=>{await c.invalidateQueries({queryKey:d}),await c.invalidateQueries({queryKey:Ot.missionControlGraph({initiativeId:t,authToken:s,embedMode:r})}),await c.invalidateQueries({queryKey:Ot.liveData({authToken:s,embedMode:r})})},j=Nt({mutationFn:async u=>{if(o){const C=h.data??null;return{ok:!0,initiativeId:t,run:(C==null?void 0:C.run)??null,defaults:(C==null?void 0:C.defaults)??{tokenBudget:null,tickMs:0}}}const w={};t&&(w.initiativeId=t),w.ignoreSpawnGuardRateLimit=!0,u&&typeof u=="object"&&(typeof u.tokenBudgetTokens=="number"&&(w.tokenBudgetTokens=u.tokenBudgetTokens),typeof u.agentId=="string"&&u.agentId.trim().length>0&&(w.agentId=u.agentId.trim()),typeof u.maxParallelSlices=="number"&&Number.isFinite(u.maxParallelSlices)&&(w.maxParallelSlices=u.maxParallelSlices),u.parallelMode==="iwmt"&&(w.parallelMode=u.parallelMode));const k=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:xt({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(w)}),g=await k.json().catch(()=>null);if(!k.ok){const C=Nr(g);if(C)throw C;const T=typeof(g==null?void 0:g.error)=="string"&&g.error||typeof(g==null?void 0:g.message)=="string"&&g.message||`Failed to start auto-continue (${k.status})`;throw new Error(T)}if(g&&typeof g=="object"&&"run"in g){const C=h.data??null;return{ok:!0,initiativeId:t,run:g.run??null,defaults:(C==null?void 0:C.defaults)??{tokenBudget:null,tickMs:0}}}return g},onSuccess:()=>{b()}}),x=Nt({mutationFn:async()=>{if(o){const g=h.data??null;return{ok:!0,initiativeId:t,run:null,defaults:(g==null?void 0:g.defaults)??{tokenBudget:null,tickMs:0}}}const u={};t&&(u.initiativeId=t);const w=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:xt({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(u)}),k=await w.json().catch(()=>null);if(!w.ok){const g=typeof(k==null?void 0:k.error)=="string"&&k.error||typeof(k==null?void 0:k.message)=="string"&&k.message||`Failed to stop auto-continue (${w.status})`;throw new Error(g)}if(k&&typeof k=="object"&&"run"in k){const g=h.data??null;return{ok:!0,initiativeId:t,run:k.run??null,defaults:(g==null?void 0:g.defaults)??{tokenBudget:null,tickMs:0}}}return k},onSuccess:()=>{b()}}),F=((N=h.data)==null?void 0:N.run)??null,M=(F==null?void 0:F.status)==="running"||(F==null?void 0:F.status)==="stopping";return{status:h.data??null,run:F,isRunning:M,isLoading:h.isLoading,error:((l=h.data)==null?void 0:l.error)??((y=h.error)==null?void 0:y.message)??null,start:j.mutateAsync,stop:x.mutateAsync,isStarting:j.isPending,isStopping:x.isPending,refetch:h.refetch}}function Xn(t){const s=a.useRef(null),r=a.useCallback((n,c,o,d)=>{if(o&&s.current!==null){const h=t.indexOf(s.current),b=t.indexOf(n);if(h!==-1&&b!==-1){const j=Math.min(h,b),x=Math.max(h,b),F=t.slice(j,x+1);d(M=>{const N=new Set(M);for(const l of F)c?N.add(l):N.delete(l);return N});return}}d(h=>{const b=new Set(h);return c?b.add(n):b.delete(n),b}),s.current=n},[t]);return{lastClickedId:s,handleSelect:r}}const zr=100,Ur=5,Wr=75,Qr=3,Hr=["workstream","milestone","task"],Vr=60;function ms(t){const s=Date.parse(t??"");return Number.isFinite(s)?s:0}function Kr(t){return t.toLowerCase().trim().split(/\s+/).filter(Boolean)}function Gr(t,s){const r=[];for(let n=0;n<t.length;n+=s)r.push(t.slice(n,n+s));return r}async function wn(t,s,r){var o;const n=[];let c=0;for(let d=0;d<r;d+=1){const h=new URLSearchParams(t);h.set("limit",String(s)),h.set("offset",String(c));const b=await fetch(`/orgx/api/entities?${h.toString()}`);if(!b.ok)break;const j=await b.json(),x=j.data??[];if(n.push(...x),!!!((o=j.pagination)!=null&&o.has_more)||x.length===0)break;c+=s}return n}function vn(t,s,r,n){const c=t.name.toLowerCase(),o=(t.description??"").toLowerCase();let d=0;n&&(d+=65),c===s&&(d+=140),c.startsWith(s)&&(d+=100),c.includes(s)&&(d+=80),o.includes(s)&&(d+=40);for(const h of r)c.includes(h)&&(d+=22),o.includes(h)&&(d+=8);return d}function Jr(t,s,r=null){const n=t.trim().toLowerCase(),c=(r==null?void 0:r.trim())??"";return Zt({queryKey:Ot.initiativeSearch({query:n,projectId:c||null}),enabled:s&&n.length>=2,queryFn:async()=>{var N;if(n.length<2||os())return[];const o=l=>{const y=new URLSearchParams(l);return c.length>0&&y.set("workspace_id",c),y},d=await wn(o({type:"initiative",search:n}),zr,Ur),h=await Promise.all(Hr.map(l=>wn(o({type:l,search:n}),Wr,Qr))),b=new Set;for(const l of h)for(const y of l){const u=(N=y.initiative_id)==null?void 0:N.trim();u&&b.add(u)}const j=[];for(const l of Gr(Array.from(b),Vr)){if(l.length===0)continue;const y=o({type:"initiative",ids:l.join(","),limit:String(l.length),offset:"0"}),u=await fetch(`/orgx/api/entities?${y.toString()}`);if(!u.ok)continue;const w=await u.json();j.push(...w.data??[])}const x=[...d,...j],F=new Map;for(const l of x){const y=F.get(l.id);if(!y){F.set(l.id,l);continue}ms(l.updated_at??l.created_at)>ms(y.updated_at??y.created_at)&&F.set(l.id,l)}const M=Kr(n);return Array.from(F.values()).filter(l=>Sr(l.status)).map(Cr).filter(l=>{if(b.has(l.id))return!0;const y=[l.name,l.description??"",l.rawStatus??"",l.status].join(" ").toLowerCase();return M.every(u=>y.includes(u))}).sort((l,y)=>{const u=vn(y,n,M,b.has(y.id))-vn(l,n,M,b.has(l.id));return u!==0?u:ms(y.updatedAt??y.createdAt)-ms(l.updatedAt??l.createdAt)})},staleTime:15e3})}function Js({value:t,onChange:s,placeholder:r}){return e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:r}),e.jsxs("svg",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.3-4.3"})]}),e.jsx("input",{type:"text",value:t,onChange:n=>s(n.target.value),placeholder:r,className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.03] py-2.5 pl-10 pr-8 text-body text-white placeholder:text-muted transition-all focus:border-[#BFFF00]/30 focus:bg-white/[0.05] focus:outline-none"}),t.length>0&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-full p-0.5 text-muted transition-colors hover:text-primary","aria-label":"Clear search",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]})}async function Pt(t){if(!t.ok){const s=await t.json().catch(()=>null),r=typeof(s==null?void 0:s.error)=="string"&&s.error||typeof(s==null?void 0:s.message)=="string"&&s.message||`Request failed (${t.status})`;throw new Error(ct(r))}return t}function Yr(t){const s=t.trim().toLowerCase();return s==="completed"||s==="done"?"completed":s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":s==="deleted"||s==="archived"||s==="cancelled"?"completed":"active"}function Rs(t){const s=t.trim().toLowerCase();return s==="deleted"||s==="archived"||s==="cancelled"}function Xr(t){const s=t.trim().toLowerCase();return s==="blocked"||s==="at_risk"?"blocked":s==="paused"||s==="hold"?"paused":s==="completed"||s==="done"?"completed":"running"}function Zr(t){const s=Vs(),r=xt({authToken:t.authToken,embedMode:t.embedMode,contentTypeJson:!0}),n=()=>{s.invalidateQueries({queryKey:["live-data"]}),s.invalidateQueries({queryKey:["live-initiatives"]}),s.invalidateQueries({queryKey:["initiative-details"]}),s.invalidateQueries({queryKey:["entities"]}),s.invalidateQueries({queryKey:["mission-control-graph"]}),s.invalidateQueries({queryKey:["mission-control-next-up"]})},c=(N,l)=>{s.setQueryData(["initiative-tombstones"],y=>{const u=Array.isArray(y)?y.filter(k=>typeof k=="string"):[],w=u.includes(N);return l?w?u:[...u,N]:w?u.filter(k=>k!==N):u})},o=(N,l)=>{const y=Yr(l),u=new Date().toISOString(),w=Rs(l);c(N,w);const k=g=>{if(!Array.isArray(g))return g;if(w){const U=g.filter(P=>{if(!P||typeof P!="object")return!0;const J=P;return!(typeof J.id=="string"&&J.id===N)});return U.length===g.length?g:U}let C=!1;const T=g.map(U=>{if(!U||typeof U!="object")return U;const P=U;return typeof P.id!="string"||P.id!==N?U:(C=!0,{...P,status:y,rawStatus:l,updatedAt:u})});return C?T:g};s.setQueriesData({queryKey:["entities"]},k),s.setQueriesData({queryKey:["live-initiatives"]},k)},d=(N,l,y="status")=>{const u=Xr(l);s.setQueriesData({queryKey:["live-data"]},w=>{if(!w||typeof w!="object")return w;const k=w,g=k.sessions;if(!g||typeof g!="object")return w;const C=g,T=C.nodes;if(!Array.isArray(T))return w;let U=!1;const P=y==="delete"?T.filter($=>{if(!$||typeof $!="object")return!0;const v=$,S=(typeof v.initiativeId=="string"?v.initiativeId:null)===N;return S&&(U=!0),!S}):T.map($=>{if(!$||typeof $!="object")return $;const v=$;return(typeof v.initiativeId=="string"?v.initiativeId:null)!==N||v.status===u?$:(U=!0,{...v,status:u})});if(!U)return w;const J=new Set,ee=new Set;for(const $ of P){if(!$||typeof $!="object")continue;const v=$;typeof v.id=="string"&&J.add(v.id),typeof v.groupId=="string"&&ee.add(v.groupId)}const te=Array.isArray(C.edges)?C.edges.filter($=>{if(!$||typeof $!="object")return!1;const v=$,H=typeof v.parentId=="string"?v.parentId:null,S=typeof v.childId=="string"?v.childId:null;return H!==null&&S!==null&&J.has(H)&&J.has(S)}):C.edges,q=Array.isArray(C.groups)?C.groups.filter($=>{if(!$||typeof $!="object")return!1;const v=$;return typeof v.id=="string"&&ee.has(v.id)}):C.groups;return{...k,sessions:{...C,nodes:P,edges:te,groups:q}}})},h={start:"in_progress",complete:"done",block:"blocked",unblock:"in_progress",pause:"paused",resume:"active"},b=Nt({mutationFn:async N=>{const{type:l,...y}=N,u=await fetch("/orgx/api/entities",{method:"POST",headers:r,body:JSON.stringify({type:l,...y})});return await Pt(u),u.json()},onSuccess:n}),j=Nt({mutationFn:async N=>{const{type:l,id:y,...u}=N,w=await fetch("/orgx/api/entities",{method:"PATCH",headers:r,body:JSON.stringify({type:l,id:y,...u})});return await Pt(w),w.json()},onSuccess:(N,l)=>{l.type.trim().toLowerCase()==="initiative"&&typeof l.status=="string"&&l.status.trim().length>0&&(o(l.id,l.status),d(l.id,l.status,Rs(l.status)?"delete":"status")),n()}}),x=Nt({mutationFn:async N=>{const l=await fetch(`/orgx/api/entities/${encodeURIComponent(N.type)}/${encodeURIComponent(N.id)}/delete`,{method:"POST",headers:r,body:"{}"});return await Pt(l),l.json()},onSuccess:(N,l)=>{l.type.trim().toLowerCase()==="initiative"&&(o(l.id,"archived"),d(l.id,"archived","delete")),n()}}),F=Nt({mutationFn:async N=>{const l=await fetch(`/orgx/api/entities/${encodeURIComponent(N.type)}/${encodeURIComponent(N.id)}/${encodeURIComponent(N.action)}`,{method:"POST",headers:r,body:JSON.stringify({force:N.force??!1})});return await Pt(l),l.json()},onSuccess:(N,l)=>{if(l.type.trim().toLowerCase()==="initiative"){const y=h[l.action.trim().toLowerCase()];y&&(o(l.id,y),d(l.id,y,"status"))}n()}}),M=Nt({mutationFn:async N=>{const l=Array.from(new Map((N.items??[]).filter(C=>typeof(C==null?void 0:C.type)=="string"&&C.type.trim().length>0&&typeof(C==null?void 0:C.id)=="string"&&C.id.trim().length>0).map(C=>[`${C.type}:${C.id}`,C])).values());if(l.length===0)return{updated:0,failed:0,errors:[]};if(N.mode==="action"&&!N.action)throw new Error("bulk action requires an action name");const y=async C=>{try{if(N.mode==="delete"){const U=await fetch(`/orgx/api/entities/${encodeURIComponent(C.type)}/${encodeURIComponent(C.id)}/delete`,{method:"POST",headers:r,body:"{}"});return await Pt(U),{ok:!0}}if(N.mode==="update"){const U=await fetch("/orgx/api/entities",{method:"PATCH",headers:r,body:JSON.stringify({type:C.type,id:C.id,...N.updates??{}})});return await Pt(U),{ok:!0}}const T=await fetch(`/orgx/api/entities/${encodeURIComponent(C.type)}/${encodeURIComponent(C.id)}/${encodeURIComponent(N.action)}`,{method:"POST",headers:r,body:JSON.stringify({force:N.force??!1})});return await Pt(T),{ok:!0}}catch(T){return{ok:!1,error:T instanceof Error?T.message:"Unknown bulk mutation failure"}}},u=await Promise.all(l.map(C=>y(C)));let w=0,k=0;const g=[];for(const C of u)C.ok?w+=1:(k+=1,g.push(C.error));return{updated:w,failed:k,errors:g}},onSuccess:(N,l)=>{var u;const y=(l.items??[]).filter(w=>w.type.trim().toLowerCase()==="initiative");if(y.length>0){if(l.mode==="update"&&typeof((u=l.updates)==null?void 0:u.status)=="string"&&l.updates.status.trim().length>0)for(const w of y)o(w.id,l.updates.status),d(w.id,l.updates.status,Rs(l.updates.status)?"delete":"status");else if(l.mode==="delete")for(const w of y)o(w.id,"archived"),d(w.id,"archived","delete");else if(l.mode==="action"&&l.action){const w=h[l.action.trim().toLowerCase()];if(w)for(const k of y)o(k.id,w),d(k.id,w,"status")}}n()}});return{createEntity:b,updateEntity:j,deleteEntity:x,entityAction:F,bulkEntityMutation:M}}const Zn=a.createContext(null);function Dt(){const t=a.useContext(Zn);if(!t)throw new Error("useMissionControl must be used within MissionControlProvider");return t}function ea({children:t,agentEntityMap:s,authToken:r,embedMode:n}){const[c,o]=a.useState(new Set),[d,h]=a.useState(null),[b,j]=a.useState(""),[x,F]=a.useState([]),[M,N]=a.useState("target"),[l,y]=a.useState("any"),[u,w]=a.useState(""),[k,g]=a.useState(""),[C,T]=a.useState("status"),[U,P]=a.useState("default"),J=Zr({authToken:r,embedMode:n}),ee=a.useCallback(I=>{o(Q=>{const oe=new Set(Q);return oe.has(I)?oe.delete(I):oe.add(I),oe})},[]),te=a.useCallback(I=>{o(Q=>{if(Q.has(I))return Q;const oe=new Set(Q);return oe.add(I),oe})},[]),q=a.useCallback(I=>{o(new Set(I))},[]),$=a.useCallback(()=>{o(new Set)},[]),v=a.useCallback(I=>{h(I)},[]),H=a.useCallback(()=>{h(null)},[]),S=a.useCallback(I=>{const Q=Array.from(new Set((I??[]).map(oe=>oe.trim().toLowerCase()).filter(Boolean)));F(Q)},[]),W=a.useCallback(I=>{F(Q=>{const oe=I.trim().toLowerCase();return oe?Q.includes(oe)?Q.filter(Ie=>Ie!==oe):[...Q,oe]:Q})},[]),L=a.useCallback(()=>{j(""),F([]),N("target"),y("any"),w(""),g("")},[]),se=u.trim().length>0||k.trim().length>0,R=l!=="any"&&(l!=="custom_range"||se),X=x.length+(R?1:0),ie=b.trim().length>0||X>0,de=a.useMemo(()=>({agentEntityMap:s,expandedInitiatives:c,modalTarget:d,searchQuery:b,statusFilters:x,dateField:M,datePreset:l,dateStart:u,dateEnd:k,activeFilterCount:X,hasActiveFilters:ie,groupBy:C,sortBy:U,authToken:r,embedMode:n,mutations:J,toggleExpanded:ee,expandInitiative:te,expandAll:q,collapseAll:$,openModal:v,closeModal:H,setSearchQuery:j,setStatusFilters:S,toggleStatusFilter:W,setDateField:N,setDatePreset:y,setDateStart:w,setDateEnd:g,setGroupBy:T,setSortBy:P,clearFilters:L}),[s,c,d,b,x,M,l,u,k,X,ie,C,U,r,n,J,ee,te,q,$,v,H,S,W,N,y,w,g,T,P,L]);return e.jsx(Zn.Provider,{value:de,children:t})}function qs(t){return{initiative:{id:t,title:"Initiative",status:"active",summary:null,assignedAgents:[]},nodes:[],edges:[],recentTodos:[]}}function ta(t){const s=new Date().toISOString(),r=t==="init-2"?"Black Friday Email":"Q4 Feature Ship",n=`${t}:ws:design`,c=`${t}:ms:polish`,o=`${t}:task:tokens`,d=`${t}:task:qa`;return{initiative:{id:t,title:r,status:"active",summary:"Demo mode graph from local fixture data.",assignedAgents:[{id:"dana",name:"Dana",domain:"design"}]},nodes:[{id:n,type:"workstream",title:"Dashboard UI pass",status:"active",parentId:t,initiativeId:t,workstreamId:n,milestoneId:null,priorityNum:1,priorityLabel:"P1",dependencyIds:[],dueDate:null,etaEndAt:null,expectedDurationHours:8,expectedBudgetUsd:1500,assignedAgents:[{id:"dana",name:"Dana",domain:"design"}],updatedAt:s},{id:c,type:"milestone",title:"Polish pass",status:"active",parentId:n,initiativeId:t,workstreamId:n,milestoneId:c,priorityNum:1,priorityLabel:"P1",dependencyIds:[n],dueDate:null,etaEndAt:null,expectedDurationHours:4,expectedBudgetUsd:900,assignedAgents:[{id:"dana",name:"Dana",domain:"design"}],updatedAt:s},{id:o,type:"task",title:"Refine queue action ergonomics",status:"todo",parentId:c,initiativeId:t,workstreamId:n,milestoneId:c,priorityNum:1,priorityLabel:"P1",dependencyIds:[c],dueDate:null,etaEndAt:null,expectedDurationHours:2,expectedBudgetUsd:450,assignedAgents:[{id:"dana",name:"Dana",domain:"design"}],updatedAt:s},{id:d,type:"task",title:"Mobile QA sweep",status:"active",parentId:c,initiativeId:t,workstreamId:n,milestoneId:c,priorityNum:2,priorityLabel:"P2",dependencyIds:[o],dueDate:null,etaEndAt:null,expectedDurationHours:2,expectedBudgetUsd:420,assignedAgents:[{id:"mark",name:"Mark",domain:"engineering"}],updatedAt:s}],edges:[{from:n,to:c,kind:"depends_on"},{from:c,to:o,kind:"depends_on"},{from:o,to:d,kind:"depends_on"}],recentTodos:[o,d]}}function sa({initiativeId:t,authToken:s=null,embedMode:r=!1,enabled:n=!0}){var j,x;const c=os(),o=Fr(t),d=a.useMemo(()=>Ot.missionControlGraph({initiativeId:t,authToken:s,embedMode:r}),[t,s,r]),h=Zt({queryKey:d,enabled:n&&!!t&&o,queryFn:async()=>{if(!t)throw new Error("initiativeId is required");if(c)return ta(t);if(!o)return qs(t);const F=new URLSearchParams({initiative_id:t}),M={};r&&(M["X-Orgx-Embed"]="true"),s&&(M.Authorization=`Bearer ${s}`);const N=Object.keys(M).length>0?M:void 0,l=await fetch(`/orgx/api/mission-control/graph?${F.toString()}`,{headers:N});if(!l.ok){const y=await l.json().catch(()=>null),u=typeof(y==null?void 0:y.error)=="string"&&y.error||typeof(y==null?void 0:y.message)=="string"&&y.message||`Failed to fetch Mission Control graph (${l.status})`;return{...qs(t),degraded:[u]}}return await l.json()}});return{graph:h.data??(t?qs(t):null),isLoading:o?h.isLoading:!1,error:o?((j=h.error)==null?void 0:j.message)??null:null,degraded:o?((x=h.data)==null?void 0:x.degraded)??[]:[],refetch:h.refetch}}function ys({type:t,className:s=""}){return e.jsx(Ge,{type:t,className:s,size:14})}function na(t){return t==="initiative"?"Initiatives":t==="workstream"?"Workstreams":t==="milestone"?"Milestones":"Tasks"}function ra({nodes:t,edges:s,selectedNodeId:r,focusedWorkstreamId:n,onSelectNode:c}){const o=a.useMemo(()=>new Map(t.map(g=>[g.id,g])),[t]),[d,h]=a.useState(""),[b,j]=a.useState(!1),x=d.trim().toLowerCase(),F=a.useMemo(()=>{if(!n)return new Set(t.map(T=>T.id));const g=new Set;for(const T of t)(T.type==="initiative"||T.id===n||T.workstreamId===n)&&g.add(T.id);let C=!0;for(;C;){C=!1;for(const T of s)(g.has(T.from)||g.has(T.to))&&(!g.has(T.from)||!g.has(T.to))&&(g.add(T.from),g.add(T.to),C=!0)}return g},[n,t,s]),M=t.filter(g=>F.has(g.id)),N=s.filter(g=>F.has(g.from)&&F.has(g.to)),l=a.useMemo(()=>{if(!r)return new Set;const g=new Set([r]);for(const C of N)C.from===r&&g.add(C.to),C.to===r&&g.add(C.from);return g},[r,N]),y=a.useMemo(()=>{let g=new Set(Array.from(F));return b&&r&&(g=new Set(Array.from(g).filter(C=>l.has(C)))),x.length>0&&(g=new Set(Array.from(g).filter(C=>{const T=o.get(C);return T?T.title.toLowerCase().includes(x):!1}))),g},[o,x,l,b,r,F]),u=t.filter(g=>y.has(g.id)),w=s.filter(g=>y.has(g.from)&&y.has(g.to)),k={initiative:u.filter(g=>g.type==="initiative"),workstream:u.filter(g=>g.type==="workstream"),milestone:u.filter(g=>g.type==="milestone"),task:u.filter(g=>g.type==="task")};return M.length===0?null:e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:[u.length," nodes · ",w.length," links"]}),n&&e.jsx("span",{className:"status-pill","data-tone":"active",children:"Focused workstream"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{value:d,onChange:g=>h(g.target.value),placeholder:"Filter nodes...",className:"h-9 flex-1 min-w-[200px] rounded-lg border border-strong bg-black/30 px-3 text-caption text-primary placeholder:text-faint transition-colors focus:border-[#BFFF00]/35 focus:outline-none"}),r&&e.jsx("button",{type:"button",onClick:()=>j(g=>!g),"aria-pressed":b,"data-state":b?"active":"idle",className:"control-pill px-3 text-caption font-semibold",title:"Show only the selected node and its direct neighbors",children:"Related only"}),(d.trim().length>0||b)&&e.jsx("button",{type:"button",onClick:()=>{h(""),j(!1)},className:"control-pill px-3 text-caption",children:"Reset"})]}),u.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-3 py-3 text-caption text-secondary",children:"No nodes match this view. Clear filters or select a different node to see connected work."}):e.jsx("div",{className:`grid gap-2 ${Object.values(k).filter(g=>g.length>0).length<=2?"grid-cols-1 sm:grid-cols-2":"md:grid-cols-2 xl:grid-cols-4"}`,children:Object.keys(k).filter(g=>k[g].length>0).map(g=>e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] p-2.5",children:[e.jsxs("div",{className:"mb-1.5 text-micro uppercase tracking-[0.09em] text-secondary",children:[na(g)," (",k[g].length,")"]}),e.jsxs("div",{className:"space-y-1",children:[k[g].slice(0,10).map(C=>{const T=r===C.id,U=!T&&l.has(C.id);return e.jsxs("button",{type:"button",onClick:()=>c(C.id),title:C.title,className:`flex w-full items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors ${T?"border-[#BFFF00]/35 bg-[#BFFF00]/12":U?"border-[#14B8A6]/35 bg-[#14B8A6]/12":"border-strong bg-white/[0.03] hover:bg-white/[0.08]"}`,children:[e.jsx(ys,{type:C.type}),e.jsx("span",{className:"truncate text-caption text-primary",children:C.title})]},C.id)}),k[g].length>10&&e.jsxs("div",{className:"px-1 text-micro text-muted",children:["+",k[g].length-10," more"]})]})]},g))}),w.length>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-2.5 py-2",children:[e.jsx("div",{className:"mb-1 text-micro uppercase tracking-[0.08em] text-muted",children:"Dependency links"}),e.jsx("div",{className:"max-h-[110px] space-y-1 overflow-auto pr-1",children:w.slice(0,36).map(g=>{const C=o.get(g.from),T=o.get(g.to);if(!C||!T)return null;const U=r===C.id||r===T.id;return e.jsxs("button",{type:"button",onClick:()=>c(T.id),className:"flex w-full items-center gap-1 rounded-md px-1.5 py-1 text-left hover:bg-white/[0.06]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full",style:{backgroundColor:U?Y.lime:"rgba(255,255,255,0.35)"}}),e.jsx("span",{className:"truncate text-micro text-primary",children:C.title}),e.jsx("span",{className:"text-micro text-muted",children:"→"}),e.jsx("span",{className:"truncate text-micro text-primary",children:T.title})]},`${g.from}-${g.to}`)})})]})]})}const aa=new Set(["completed","complete","done","resolved","success","succeeded","archived","cancelled","canceled","stopped","deleted"]);function ia(t){return aa.has(Er(t))}function Ze(t){return ia(t)}function ks(t){return Number.isFinite(t)?Math.max(0,Math.min(100,Math.round(t))):0}function zt(t,s){return s<=0?0:ks(t/s*100)}function oa({dependencies:t,allNodes:s,disabled:r=!1,onSave:n}){const[c,o]=a.useState(!1),[d,h]=a.useState(""),[b,j]=a.useState(t),x=a.useMemo(()=>new Map(s.map(l=>[l.id,l])),[s]),F=a.useMemo(()=>{const l=d.trim().toLowerCase(),y=[...s].sort((u,w)=>u.title.localeCompare(w.title));return l?y.filter(u=>u.title.toLowerCase().includes(l)||u.id.toLowerCase().includes(l)).slice(0,16):y.slice(0,16)},[s,d]),M=()=>{n(Array.from(new Set(b))),o(!1)},N=l=>{j(y=>y.includes(l)?y.filter(u=>u!==l):[...y,l])};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",disabled:r,onClick:()=>{h(""),j(t),o(l=>!l)},className:"rounded-md border border-strong bg-white/[0.04] px-2 py-1 text-micro text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-40",children:t.length>0?`${t.length} linked`:"Set links"}),c&&e.jsxs("div",{className:"surface-tier-2 absolute right-0 z-20 mt-1.5 w-[320px] rounded-xl p-2.5 shadow-[0_20px_40px_rgba(0,0,0,0.45)]",children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Link dependencies"}),e.jsx("input",{value:d,onChange:l=>h(l.target.value),placeholder:"Search by title or id...",className:"mt-1.5 h-9 w-full rounded-md border border-strong bg-black/25 px-2.5 text-caption text-bright outline-none transition-colors placeholder:text-muted focus:border-[#BFFF00]/35"}),e.jsx("div",{className:"mt-2 flex max-h-[84px] flex-wrap gap-1.5 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:b.length===0?e.jsx("span",{className:"text-micro text-muted",children:"No links selected"}):b.map(l=>{var u;const y=((u=x.get(l))==null?void 0:u.title)??l;return e.jsxs("button",{type:"button",onClick:()=>N(l),className:"inline-flex items-center gap-1 rounded-full border border-strong bg-white/[0.05] px-2 py-0.5 text-micro text-primary transition-colors hover:bg-white/[0.1]",title:y,children:[e.jsx("span",{className:"max-w-[180px] truncate",children:y}),e.jsx("span",{className:"text-secondary",children:"×"})]},l)})}),e.jsx("div",{className:"mt-2 max-h-[150px] space-y-1 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:F.length===0?e.jsx("div",{className:"px-1 text-micro text-muted",children:"No matching nodes"}):F.map(l=>{const y=b.includes(l.id);return e.jsxs("button",{type:"button",onClick:()=>N(l.id),className:`flex w-full items-center justify-between rounded-md border px-2 py-1 text-left text-micro transition-colors ${y?"border-[#BFFF00]/32 bg-[#BFFF00]/12 text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03] text-primary hover:bg-white/[0.08]"}`,children:[e.jsxs("span",{className:"min-w-0 pr-2",children:[e.jsx("span",{className:"block truncate",children:l.title}),e.jsxs("span",{className:"block truncate text-muted",children:[l.id.slice(0,8),"…"]})]}),e.jsx("span",{className:"font-semibold",children:y?"Linked":"Link"})]},l.id)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>o(!1),className:"rounded-md border border-strong px-2 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.08]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:M,className:"rounded-md border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2 py-1 text-micro text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/22",children:"Save links"})]})]})]})}const la={bottom:"Add to queue"},ca=[{scope:"task",label:"Play next",description:"task scope"},{scope:"milestone",label:"Play milestone",description:"milestone scope"},{scope:"workstream",label:"Play workstream",description:"workstream scope"}];function da({scope:t,size:s=12}){const r=s,n=Math.round(r*.14),c=Math.round(r*.06);if(t==="task")return e.jsx("svg",{width:r,height:r,viewBox:`0 0 ${r} ${r}`,fill:"currentColor","aria-hidden":!0,children:e.jsx("circle",{cx:r/2,cy:r/2,r:n+1})});if(t==="milestone"){const d=r/2;return e.jsxs("svg",{width:r,height:r,viewBox:`0 0 ${r} ${r}`,fill:"currentColor","aria-hidden":!0,children:[e.jsx("circle",{cx:d,cy:n+c,r:n}),e.jsx("circle",{cx:d,cy:r/2,r:n}),e.jsx("circle",{cx:d,cy:r-n-c,r:n})]})}const o=n+c+1;return e.jsxs("svg",{width:r,height:r,viewBox:`0 0 ${r} ${r}`,fill:"currentColor","aria-hidden":!0,children:[e.jsx("circle",{cx:o,cy:o,r:n}),e.jsx("circle",{cx:r-o,cy:o,r:n}),e.jsx("circle",{cx:o,cy:r-o,r:n}),e.jsx("circle",{cx:r-o,cy:r-o,r:n})]})}function Ns({label:t="Queue",defaultPlacement:s="bottom",size:r="sm",align:n="right",menuDirection:c="up",disabled:o=!1,busy:d=!1,className:h="",menuClassName:b="",title:j,stopPropagation:x=!1,onSelectPlacement:F}){const[M,N]=a.useState(!1),l=a.useRef(null),y=a.useRef(`queue-placement-${Math.random().toString(36).slice(2,10)}`),u=o||d,w=r==="md"?"h-8 text-caption":"h-7 text-micro",k=r==="md"?"px-3":"px-2.5",g=r==="md"?"h-8 w-8":"h-7 w-7",C=n==="left"?"left-0":"right-0",T=c==="up"?"bottom-[calc(100%+6px)]":"top-[calc(100%+6px)]";a.useEffect(()=>{if(!M)return;const P=ee=>{var q;const te=ee.target;te&&((q=l.current)!=null&&q.contains(te)||N(!1))},J=ee=>{ee.key==="Escape"&&N(!1)};return document.addEventListener("mousedown",P),document.addEventListener("touchstart",P),document.addEventListener("keydown",J),()=>{document.removeEventListener("mousedown",P),document.removeEventListener("touchstart",P),document.removeEventListener("keydown",J)}},[M]);const U=(P,J,ee)=>{x&&P.stopPropagation(),N(!1),F(J,ee)};return e.jsxs("div",{ref:l,className:`relative inline-flex items-center ${h}`,children:[e.jsxs("button",{type:"button",title:j??`Queue ${s==="top"?"to top":"to end"}`,onClick:P=>U(P,s),disabled:u,className:`control-pill ${w} ${k} rounded-r-none border-r-0 font-semibold text-primary disabled:opacity-45`,children:[e.jsxs("svg",{width:r==="md"?13:12,height:r==="md"?13:12,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-90","aria-hidden":!0,children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M4 12h11"}),e.jsx("path",{d:"M4 18h9"}),e.jsx("path",{d:"m17 15 3 3 3-3"}),e.jsx("path",{d:"M20 8v10"})]}),e.jsx("span",{children:d?"Queueing...":t})]}),e.jsx("button",{type:"button","aria-label":"Choose queue placement","aria-haspopup":"menu","aria-expanded":M,"aria-controls":y.current,onClick:P=>{x&&P.stopPropagation(),!u&&N(J=>!J)},disabled:u,className:`control-pill ${g} rounded-l-none px-0 text-secondary disabled:opacity-45`,children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.4",strokeLinecap:"round",strokeLinejoin:"round",className:`transition-transform ${M?"rotate-180":""}`,"aria-hidden":!0,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})}),M&&e.jsxs("div",{id:y.current,role:"menu",className:`absolute ${C} ${T} z-[260] min-w-[196px] rounded-lg border border-strong bg-[#0B0F16]/95 p-1 shadow-[0_16px_32px_rgba(0,0,0,0.38)] backdrop-blur ${b}`,children:[ca.map(P=>e.jsxs("button",{type:"button",role:"menuitem",onClick:J=>U(J,"top",P.scope),className:"flex w-full items-center gap-2 rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.07]",children:[e.jsx(da,{scope:P.scope,size:12}),e.jsx("span",{className:"text-caption font-medium text-primary",children:P.label}),e.jsx("span",{className:"ml-auto text-micro text-tertiary",children:P.description})]},P.scope)),e.jsx("div",{className:"my-1 border-t border-strong"}),e.jsx("button",{type:"button",role:"menuitem",onClick:P=>U(P,"bottom"),className:"flex w-full items-center rounded-md px-2.5 py-1.5 text-left transition-colors hover:bg-white/[0.07]",children:e.jsx("span",{className:"text-caption font-medium text-primary",children:la.bottom})})]})]})}function ua(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const r=s.getFullYear(),n=String(s.getMonth()+1).padStart(2,"0"),c=String(s.getDate()).padStart(2,"0"),o=String(s.getHours()).padStart(2,"0"),d=String(s.getMinutes()).padStart(2,"0");return`${r}-${n}-${c}T${o}:${d}`}const jn=["not_started","planned","todo","in_progress","active","blocked","done"];function ma(t){const s=t.trim().toLowerCase();return s==="blocked"?"blocked":s==="done"||s==="completed"?"done":s==="in_progress"||s==="active"||s==="running"||s==="queued"?"active":"planned"}function ps(t){const s=t.trim().toLowerCase();return s==="completed"?"done":s==="running"||s==="queued"?"active":s==="pending"||s==="backlog"?"todo":s}function pa(t,s){return s==="all"?!0:s==="blocked"?t==="blocked":s==="done"?t==="done":t!=="blocked"&&t!=="done"}function xa(t){const s=Number.isFinite(t)?Math.max(1,Math.min(100,Math.round(t))):50;return s<=12?{label:"P1 Urgent",toneClass:"border-red-300/35 bg-red-500/[0.14] text-red-100"}:s<=30?{label:"P2 High",toneClass:"border-amber-300/35 bg-amber-500/[0.14] text-amber-100"}:s<=60?{label:"P3 Medium",toneClass:"border-[#BFFF00]/35 bg-[#BFFF00]/14 text-[#E1FFB2]"}:{label:"P4 Low",toneClass:"border-white/[0.2] bg-white/[0.08] text-white/70"}}function ha(t,s){const r=new Map(s.map(o=>[o.id,o])),n=new Set,c=[t];for(;c.length>0;){const o=c.shift(),d=r.get(o);d&&(d.parentId&&!n.has(d.parentId)&&(n.add(d.parentId),c.push(d.parentId)),d.workstreamId&&!n.has(d.workstreamId)&&(n.add(d.workstreamId),c.push(d.workstreamId)),d.milestoneId&&!n.has(d.milestoneId)&&(n.add(d.milestoneId),c.push(d.milestoneId)))}return n}function fa(t,s,r,n){let c=0;if(r==="title")c=t.title.localeCompare(s.title);else if(r==="status")c=gs(t.status)-gs(s.status);else if(r==="priority")c=t.priorityNum-s.priorityNum;else if(r==="eta"){const o=t.etaEndAt?Date.parse(t.etaEndAt):1/0,d=s.etaEndAt?Date.parse(s.etaEndAt):1/0;c=o-d}return n==="desc"?-c:c}function ss(t,s){return!t||t.trim().length===0?s:ct(t.trim())||s}function ga({nodes:t,edges:s,selectedNodeId:r,highlightedNodeIds:n,editMode:c,onToggleEditMode:o,onSelectNode:d,onFocusWorkstream:h,onOpenNode:b,onUpdateNode:j,mutations:x}){const{authToken:F,embedMode:M}=Dt(),N=ls({authToken:F,embedMode:M}),[l,y]=a.useState(""),[u,w]=a.useState(new Set),[k,g]=a.useState("all"),[C,T]=a.useState(!1),[U,P]=a.useState(null),[J,ee]=a.useState("asc"),[te,q]=a.useState(new Set),[$,v]=a.useState(!1),[H,S]=a.useState(null),W=a.useRef(null),L=a.useRef(null),se=a.useRef(null),R=a.useRef(null),X=a.useRef(null),ie=a.useRef(null),[de,I]=a.useState(!1);a.useEffect(()=>{if(!H)return;const i=H.tone==="success"?6500:9e3,E=window.setTimeout(()=>S(null),i);return()=>window.clearTimeout(E)},[H==null?void 0:H.message,H==null?void 0:H.tone]);const Q=a.useMemo(()=>new Map(t.map(i=>[i.id,i])),[t]),oe=a.useMemo(()=>t.map(i=>({id:i.id,title:i.title})),[t]),Ie=a.useMemo(()=>{const i=new Map;for(const E of t){const A=ps(E.status);i.set(A,(i.get(A)??0)+1)}return i},[t]),He=a.useMemo(()=>{let i=0,E=0,A=0;for(const z of t){const G=ps(z.status);G==="blocked"?E+=1:G==="done"?A+=1:i+=1}return{all:t.length,open:i,blocked:E,done:A}},[t]),ze=a.useMemo(()=>{const i=l.trim().toLowerCase(),E=i.length>0,A=u.size>0;if(!E&&!A&&!(k!=="all"))return null;const G=new Set;for(const we of t){const Fe=ps(we.status),Se=!E||we.title.toLowerCase().includes(i)||we.assignedAgents.some(it=>it.name.toLowerCase().includes(i)),_e=!A||u.has(Fe),be=pa(Fe,k);Se&&_e&&be&&G.add(we.id)}const ue=new Set(G);for(const we of G)for(const Fe of ha(we,t))ue.add(Fe);return ue},[u,t,l,k]),f=a.useMemo(()=>t.filter(i=>i.type==="workstream").sort((i,E)=>i.priorityNum-E.priorityNum||i.title.localeCompare(E.title)),[t]),re=a.useMemo(()=>{const i=new Map;for(const E of t.filter(A=>A.type==="milestone")){const A=E.workstreamId??"unscoped",z=i.get(A)??[];z.push(E),i.set(A,z)}for(const E of i.values())E.sort((A,z)=>A.priorityNum-z.priorityNum||A.title.localeCompare(z.title));return i},[t]),V=a.useMemo(()=>{const i=new Map;for(const E of t.filter(A=>A.type==="task"&&A.milestoneId)){const A=E.milestoneId??"unscoped",z=i.get(A)??[];z.push(E),i.set(A,z)}for(const E of i.values())E.sort((A,z)=>A.priorityNum-z.priorityNum||A.title.localeCompare(z.title));return i},[t]),pe=a.useMemo(()=>{const i=new Map;for(const E of t.filter(A=>A.type==="task"&&!A.milestoneId)){const A=E.workstreamId??"unscoped",z=i.get(A)??[];z.push(E),i.set(A,z)}for(const E of i.values())E.sort((A,z)=>A.priorityNum-z.priorityNum||A.title.localeCompare(z.title));return i},[t]),Ce=a.useMemo(()=>{const i=new Set;for(const E of f)i.add(E.id);for(const E of t.filter(A=>A.type==="milestone"))i.add(E.id);return i},[t,f]),[De,Ue]=a.useState(Ce);a.useEffect(()=>{Ue(Ce)},[Ce]);const Le=i=>U?[...i].sort((E,A)=>fa(E,A,U,J)):i,fe=a.useMemo(()=>{const i=[],E=G=>ze===null||ze.has(G);for(const G of Le(f)){if(!E(G.id))continue;const ue=Le(re.get(G.id)??[]),we=Le(pe.get(G.id)??[]),Fe=ue.length>0||we.length>0;if(i.push({node:G,depth:0,canCollapse:Fe}),!!De.has(G.id)){for(const Se of ue){if(!E(Se.id))continue;const _e=Le(V.get(Se.id)??[]);if(i.push({node:Se,depth:1,canCollapse:_e.length>0}),De.has(Se.id))for(const be of _e)E(be.id)&&i.push({node:be,depth:2,canCollapse:!1})}for(const Se of we)E(Se.id)&&i.push({node:Se,depth:1,canCollapse:!1})}}const A=Le(re.get("unscoped")??[]),z=Le(pe.get("unscoped")??[]);for(const G of A)if(E(G.id)&&(i.push({node:G,depth:0,canCollapse:(V.get(G.id)??[]).length>0}),De.has(G.id)))for(const ue of Le(V.get(G.id)??[]))E(ue.id)&&i.push({node:ue,depth:1,canCollapse:!1});for(const G of z)E(G.id)&&i.push({node:G,depth:0,canCollapse:!1});return i},[pe,De,ze,re,U,J,V,f]),Pe=a.useMemo(()=>fe.map(({node:i})=>i.id),[fe]),{handleSelect:Re}=Xn(Pe),Ne=a.useMemo(()=>new Set(Pe),[Pe]),Me=a.useMemo(()=>fe.filter(({node:i})=>te.has(i.id)),[fe,te]),ht=(k!=="all"?1:0)+u.size,St=l.trim().length>0||k!=="all"||u.size>0,je=Me.length,Je=fe.length>0&&je===fe.length,$e=(x==null?void 0:x.bulkEntityMutation.isPending)??!1;a.useEffect(()=>{q(i=>{if(i.size===0)return i;const E=new Set(Array.from(i).filter(A=>Ne.has(A)));return E.size===i.size?i:E})},[Ne]),a.useEffect(()=>{W.current&&(W.current.indeterminate=je>0&&!Je)},[Je,je]),a.useEffect(()=>{je===0&&$&&v(!1)},[$,je]),a.useEffect(()=>{if(!C)return;const i=A=>{var G;const z=A.target;z&&((G=L.current)!=null&&G.contains(z)||T(!1))},E=A=>{A.key==="Escape"&&T(!1)};return document.addEventListener("mousedown",i),document.addEventListener("touchstart",i),document.addEventListener("keydown",E),()=>{document.removeEventListener("mousedown",i),document.removeEventListener("touchstart",i),document.removeEventListener("keydown",E)}},[C]);const et=i=>i.dependencyIds.length,ft=N.isPinning||N.isMoving,wt=async i=>{await N.pin({initiativeId:i.initiativeId,workstreamId:i.workstreamId,taskId:i.taskId??null,milestoneId:i.milestoneId??null}),await N.move({initiativeId:i.initiativeId,workstreamId:i.workstreamId,placement:i.placement})},Ye=async(i,E="bottom")=>{if(i.type==="initiative"){const we=f.filter(it=>it.initiativeId===i.id);if(we.length===0){S({tone:"error",message:"Cannot queue initiative: no workstreams found."});return}const Fe=E==="top"?[...we].reverse():we;let Se=0,_e=0,be=null;for(const it of Fe)try{await wt({initiativeId:i.id,workstreamId:it.id,placement:E}),Se+=1}catch(ye){_e+=1,be||(be=ss(ye instanceof Error?ye.message:"","Failed to add initiative workstream to queue."))}_e>0?S({tone:Se>0?"success":"error",message:Se>0?`Queued ${Se}/${we.length} workstreams (${_e} failed). ${be??""}`.trim():be??"Failed to queue initiative workstreams."}):S({tone:"success",message:`Queued ${Se} workstream${Se===1?"":"s"} to ${E==="top"?"top":"end"}.`}),window.setTimeout(()=>S(null),_e>0?4200:2400);return}const A=i.initiativeId??"",z=i.type==="workstream"?i.id:i.workstreamId??"",G=i.type==="task"?i.id:null,ue=i.type==="milestone"?i.id:null;if(!A||!z){S({tone:"error",message:"Cannot add to queue: missing initiative/workstream id."});return}try{await wt({initiativeId:A,workstreamId:z,taskId:G,milestoneId:ue,placement:E}),S({tone:"success",message:i.type==="task"?`Queued task workstream to ${E==="top"?"top":"end"}.`:i.type==="milestone"?`Queued milestone workstream to ${E==="top"?"top":"end"}.`:`Queued workstream to ${E==="top"?"top":"end"}.`}),window.setTimeout(()=>S(null),2e3)}catch(we){S({tone:"error",message:ss(we instanceof Error?we.message:"","Failed to add workstream to queue.")}),window.setTimeout(()=>S(null),2400)}},Qe=i=>{if(i.type==="workstream")return i.id;if(i.type==="milestone"||i.type==="task")return i.workstreamId??null;if(i.type==="initiative"){const E=f.filter(z=>z.initiativeId===i.id);if(E.length===0)return null;const A=E.find(z=>!Ze(z.status))??E[0];return(A==null?void 0:A.id)??null}return null},We=async(i,E)=>{const A=i.type==="initiative"?i.id:i.initiativeId??"",z=E??(i.type==="workstream"?i.id:i.workstreamId??"");if(!A||!z){S({tone:"error",message:"Cannot start now: missing initiative/workstream id."});return}try{const G=await fetch("/orgx/api/mission-control/next-up/play",{method:"POST",headers:xt({authToken:F,embedMode:M,contentTypeJson:!0}),body:JSON.stringify({initiativeId:A,workstreamId:z,fastAck:!0,ignoreSpawnGuardRateLimit:!0})}),ue=await G.json().catch(()=>null);if(!G.ok)throw new Error((ue==null?void 0:ue.error)??(ue==null?void 0:ue.message)??`Failed to start workstream (${G.status})`);S({tone:"success",message:`Started ${i.title}.`}),window.setTimeout(()=>S(null),1800)}catch(G){S({tone:"error",message:ss(G instanceof Error?G.message:"","Failed to start workstream now.")}),window.setTimeout(()=>S(null),2400)}},dt=a.useMemo(()=>{const i=new Map,E=(A,z)=>{if(A.length>0){const G=A.filter(ue=>Ze(ue.status)).length;return zt(G,A.length)}return Ze(z)?100:0};for(const A of t.filter(z=>z.type==="milestone")){const z=V.get(A.id)??[];i.set(A.id,E(z,A.status))}for(const A of f){const G=(re.get(A.id)??[]).flatMap(we=>V.get(we.id)??[]),ue=pe.get(A.id)??[];i.set(A.id,E([...ue,...G],A.status))}return i},[pe,re,t,V,f]),tt=i=>{U===i?ee(E=>E==="asc"?"desc":"asc"):(P(i),ee("asc"))},st=i=>{w(E=>{const A=new Set(E);return A.has(i)?A.delete(i):A.add(i),A})},Ut=()=>{y(""),g("all"),w(new Set)},vt=(i,E,A)=>{S(null),v(!1),Re(i,E,A,q)},ut=()=>{S(null),v(!1),q(()=>fe.length===0||Je?new Set:new Set(Pe))},Ct=()=>{v(!1),q(new Set)},nt=async i=>{if(!(!x||Me.length===0)){v(!1),S(null);try{const E=await x.bulkEntityMutation.mutateAsync({items:Me.map(({node:A})=>({type:A.type,id:A.id})),mode:"update",updates:{status:i}});E.failed>0?S({tone:"error",message:`Updated ${E.updated}, failed ${E.failed}.`}):S({tone:"success",message:`Updated ${E.updated} item${E.updated===1?"":"s"} to ${Oe(i)}.`})}catch(E){S({tone:"error",message:ss(E instanceof Error?E.message:"","Bulk status update failed.")})}}},Mt=async()=>{if(!(!x||Me.length===0)){S(null);try{const i=await x.bulkEntityMutation.mutateAsync({items:Me.map(({node:E})=>({type:E.type,id:E.id})),mode:"delete"});i.failed>0?S({tone:"error",message:`Deleted ${i.updated}, failed ${i.failed}.`}):(S({tone:"success",message:`Deleted ${i.updated} item${i.updated===1?"":"s"}.`}),q(new Set),v(!1))}catch(i){S({tone:"error",message:ss(i instanceof Error?i.message:"","Bulk delete failed.")})}}},ke=({field:i})=>U!==i?e.jsx("span",{className:"text-faint ml-0.5",children:"↕"}):e.jsx("span",{className:"text-[#BFFF00] ml-0.5",children:J==="asc"?"↑":"↓"}),rt=de?"0px":"calc(var(--mc-toolbar-offset, 0px) + 12px)",Xe=i=>{if(ie.current==="body"){ie.current=null;return}const E=i.currentTarget.scrollLeft,A=R.current;!A||A.scrollLeft===E||(ie.current="header",A.scrollLeft=E)},at=i=>{if(ie.current==="header"){ie.current=null;return}const E=i.currentTarget.scrollLeft,A=se.current;!A||A.scrollLeft===E||(ie.current="body",A.scrollLeft=E)};a.useEffect(()=>{const i=R.current,E=se.current;!i||!E||E.scrollLeft!==i.scrollLeft&&(E.scrollLeft=i.scrollLeft)},[fe.length]),a.useEffect(()=>{if(typeof window>"u")return;const i=X.current;if(!i)return;const E=()=>{const z=Math.min(window.innerHeight*.62,560),G=i.scrollHeight;I(G>z+1)};E();const A=typeof ResizeObserver<"u"?new ResizeObserver(()=>E()):null;return A==null||A.observe(i),window.addEventListener("resize",E),()=>{A==null||A.disconnect(),window.removeEventListener("resize",E)}},[fe.length]);const jt=()=>e.jsxs("colgroup",{children:[e.jsx("col",{style:{width:40}}),e.jsx("col",{style:{width:360}}),e.jsx("col",{style:{width:188}}),e.jsx("col",{style:{width:124}}),e.jsx("col",{style:{width:120}}),e.jsx("col",{style:{width:96}}),e.jsx("col",{style:{width:156}}),e.jsx("col",{style:{width:100}}),e.jsx("col",{style:{width:100}}),e.jsx("col",{style:{width:180}})]});return e.jsxs("section",{className:"space-y-2.5",children:[e.jsxs("div",{className:"mb-3.5 flex flex-col gap-3 xl:flex-row xl:items-center xl:justify-between",children:[e.jsx("div",{className:"w-full xl:max-w-[380px]",children:e.jsx(Js,{value:l,onChange:y,placeholder:"Search items or agents..."})}),e.jsxs("div",{className:"flex min-h-[40px] min-w-0 flex-wrap items-center gap-2.5",children:[o&&e.jsxs("button",{type:"button",onClick:o,"data-state":c?"active":"idle",className:`control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-caption font-semibold ${c?"text-[#D8FFA1]":"text-secondary hover:text-bright"}`,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),c?"Editing":"Edit"]}),e.jsxs("div",{ref:L,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>T(i=>!i),"data-state":C||ht>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3.5 text-caption font-semibold",children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),ht>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-micro leading-4",children:ht})]}),e.jsx(pt,{children:C&&e.jsxs(ge.div,{initial:{opacity:0,y:-4,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.97},transition:{duration:.16,ease:[.22,1,.36,1]},className:"surface-tier-2 absolute left-0 top-10 z-30 w-[360px] max-w-[86vw] rounded-xl p-3 shadow-[0_16px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("div",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Scope"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[{id:"all",label:"All",count:He.all},{id:"open",label:"Open",count:He.open},{id:"blocked",label:"Blocked",count:He.blocked},{id:"done",label:"Done",count:He.done}].map(i=>{const E=k===i.id;return e.jsxs("button",{type:"button",onClick:()=>g(i.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full border px-2.5 text-micro font-semibold transition-colors ${E?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-[#D8FFA1]":"border-strong bg-white/[0.03] text-secondary hover:bg-white/[0.07] hover:text-white/82"}`,children:[e.jsx("span",{children:i.label}),e.jsx("span",{className:"text-micro text-current/80",children:i.count})]},i.id)})})]}),e.jsxs("div",{className:"mb-2 border-t border-white/[0.08] pt-2",children:[e.jsx("div",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:jn.map(i=>{const E=u.has(i),A=Ie.get(i)??0;return e.jsxs("button",{type:"button",onClick:()=>st(i),className:`inline-flex h-7 items-center gap-1 rounded-full border px-2.5 text-micro transition-colors ${E?"border-[#14B8A6]/35 bg-[#14B8A6]/12 text-[#8FF7EC]":"border-strong bg-white/[0.03] text-white/58 hover:bg-white/[0.07] hover:text-bright"}`,children:[e.jsx("span",{children:Oe(i)}),e.jsx("span",{className:"text-micro text-current/75",children:A})]},i)})})]}),(k!=="all"||u.size>0)&&e.jsx("button",{type:"button",onClick:()=>{g("all"),w(new Set)},className:"text-micro text-secondary transition-colors hover:text-primary",children:"Reset filters"})]})})]}),e.jsx(pt,{initial:!1,children:St&&e.jsx(ge.button,{type:"button",onClick:Ut,initial:{opacity:0,x:-4},animate:{opacity:1,x:0},exit:{opacity:0,x:-4},transition:{duration:.16,ease:[.22,1,.36,1]},className:"control-pill inline-flex h-8 items-center px-2.5 text-caption font-medium text-primary hover:text-bright",children:"Clear"},"hierarchy-clear-filters")}),e.jsx("button",{type:"button",onClick:ut,"data-state":Je?"active":"idle",className:"control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-caption font-semibold",children:Je?"Clear all":"Select all"})]})]}),e.jsx("div",{className:"mb-1.5",children:e.jsx("div",{className:`rounded-xl border px-3 ${je>0?"border-[#BFFF00]/24 bg-[#BFFF00]/[0.08]":"border-white/[0.08] bg-white/[0.02]"}`,children:e.jsxs("div",{className:"flex h-[48px] min-w-max flex-nowrap items-center gap-2 overflow-x-auto py-1 whitespace-nowrap",children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-caption text-primary",children:[e.jsx("input",{ref:W,type:"checkbox",checked:Je,onChange:ut,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"}),"Select all"]}),e.jsx("span",{className:"flex-shrink-0 text-caption text-white/58",children:je>0?`${je} selected`:`${fe.length} visible`}),je>0&&e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2 whitespace-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>{nt("planned")},disabled:$e,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Plan"}),e.jsx("button",{type:"button",onClick:()=>{nt("in_progress")},disabled:$e,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45","data-state":"active",children:"Start"}),e.jsx("button",{type:"button",onClick:()=>{nt("blocked")},disabled:$e,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{nt("done")},disabled:$e,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Complete"}),$?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{Mt()},disabled:$e,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-caption font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>v(!1),disabled:$e,className:"control-pill h-8 flex-shrink-0 px-2.5 text-caption disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>v(!0),disabled:$e,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-caption font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:Ct,disabled:$e,className:"text-caption text-secondary transition-colors hover:text-primary disabled:opacity-45",children:"Clear"})]})]})})}),H&&e.jsx("div",{role:"status","aria-live":"polite",className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-white/72",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:`mt-[3px] h-1.5 w-1.5 flex-shrink-0 rounded-full ${H.tone==="success"?"bg-emerald-300/90":"bg-amber-300/90"}`}),e.jsx("span",{className:"min-w-0 leading-snug",children:H.message})]}),e.jsx("button",{type:"button",onClick:()=>S(null),className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary","aria-label":"Dismiss notice",title:"Dismiss",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})}),c&&e.jsx("div",{className:"mb-2 text-micro text-secondary",children:"Edit mode: select a row to edit its fields inline."}),e.jsx("div",{className:"relative min-w-0 max-w-full overflow-visible rounded-xl border border-white/[0.07] bg-black/[0.14] p-2",children:e.jsxs("div",{ref:X,"data-hierarchy-table-viewport":!0,className:`${de?"max-h-[min(62vh,560px)] overflow-y-auto":"overflow-visible"} overflow-x-hidden rounded-lg`,children:[e.jsx("div",{"data-hierarchy-table-header":!0,className:"sticky z-30 rounded-t-lg border-b border-subtle bg-[#090B11]/92 backdrop-blur-xl",style:{top:rt},children:e.jsx("div",{ref:se,onScroll:Xe,className:"overflow-x-auto overflow-y-hidden [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",children:e.jsxs("table",{className:"w-full min-w-[1464px] table-fixed border-separate border-spacing-y-0",children:[jt(),e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-micro uppercase tracking-[0.08em] text-muted",children:[e.jsx("th",{className:"px-2 py-1.5",children:e.jsx("span",{className:"sr-only",children:"Select rows"})}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>tt("title"),children:["Item ",e.jsx(ke,{field:"title"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Assigned"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>tt("status"),children:["Status ",e.jsx(ke,{field:"status"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Progress"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>tt("priority"),children:["Priority ",e.jsx(ke,{field:"priority"})]}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>tt("eta"),children:["ETA ",e.jsx(ke,{field:"eta"})]}),e.jsx("th",{className:"px-2 py-1.5",children:"Duration (h)"}),e.jsx("th",{className:"px-2 py-1.5",children:"Budget ($)"}),e.jsx("th",{className:"px-2 py-1.5",children:"Dependencies"})]})})]})})}),e.jsx("div",{ref:R,onScroll:at,className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[1464px] table-fixed border-separate border-spacing-y-1.5",children:[jt(),e.jsx("tbody",{children:fe.map(({node:i,depth:E,canCollapse:A})=>{var $t;const z=r===i.id,G=n.has(i.id),ue=te.has(i.id),we=i.assignedAgents.map(p=>p.name).join(", "),Fe=i.dependencyIds.map(p=>{var _;return((_=Q.get(p))==null?void 0:_.title)??p}).slice(0,3).join(", "),Se=dt.get(i.id),_e=xa(i.priorityNum),be=c&&z,it=i.type==="initiative"||i.type==="workstream"||i.type==="milestone"||i.type==="task",ye=Qe(i),kt=!!ye;return e.jsxs("tr",{onClick:()=>{d(i.id),i.type==="workstream"&&h(i.id)},className:`group/row cursor-pointer rounded-lg border transition-colors ${z?"border-[#BFFF00]/[0.22] bg-[#BFFF00]/[0.08]":G?"border-[#14B8A6]/[0.2] bg-[#14B8A6]/[0.08]":"border-subtle bg-white/[0.02] hover:border-strong hover:bg-white/[0.05]"}`,children:[e.jsx("td",{className:"rounded-l-lg px-2 py-1.5",children:e.jsx("input",{type:"checkbox",checked:ue,onChange:p=>{p.stopPropagation();const _=p.nativeEvent.shiftKey??!1;vt(i.id,p.currentTarget.checked,_)},onClick:p=>p.stopPropagation(),"aria-label":`Select ${i.type}: ${i.title}`,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"})}),e.jsx("td",{className:"px-2 py-1.5",children:e.jsxs("div",{className:"flex min-w-0 items-center",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-1.5 pr-2",children:[e.jsx("div",{style:{width:E*14}}),A?e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),Ue(_=>{const me=new Set(_);return me.has(i.id)?me.delete(i.id):me.add(i.id),me})},"aria-label":`${De.has(i.id)?"Collapse":"Expand"} ${i.type}: ${i.title}`,className:"rounded text-secondary focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:De.has(i.id)?"▾":"▸"}):e.jsx("span",{className:"w-2.5"}),e.jsx(ys,{type:i.type}),e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),b(i)},"aria-label":`Open ${i.type} details: ${i.title}`,className:"min-w-0 max-w-[560px] flex-1 truncate rounded text-left text-body text-bright hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:i.title})]}),!c&&e.jsxs("div",{className:"ml-1 grid w-[168px] min-w-[168px] grid-cols-[124px_34px] items-center justify-end gap-2",children:[it?e.jsx(Ns,{label:"Queue",size:"sm",busy:ft,stopPropagation:!0,title:`Queue ${i.type}: ${i.title}`,onSelectPlacement:p=>Ye(i,p)}):e.jsx("span",{className:"h-7 w-[124px]"}),e.jsx("button",{type:"button",disabled:!kt,title:kt?"Start":"No runnable workstream",onClick:p=>{p.stopPropagation(),ye&&We(i,ye)},"aria-label":kt?`Start ${i.type}: ${i.title}`:`${i.type} has no runnable workstream`,className:"control-pill flex h-7 w-[34px] items-center justify-center px-0 text-[#D8FFA1] hover:text-[#E9FFBD] disabled:cursor-not-allowed disabled:text-white/25 disabled:hover:text-white/25",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})})]})]})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary whitespace-nowrap",children:be?e.jsx("input",{type:"text",defaultValue:we,placeholder:"Agent A, Agent B",onClick:p=>p.stopPropagation(),onBlur:p=>{const _=p.currentTarget.value.split(",").map(me=>me.trim()).filter(Boolean);j(i,{assigned_agent_names:_,assigned_agent_ids:_.map(me=>`name:${me}`),assignment_source:"manual"})},className:"w-[190px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("div",{className:"flex items-center gap-2",children:i.assignedAgents.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center -space-x-1.5",children:i.assignedAgents.slice(0,3).map(p=>e.jsx("div",{title:p.name,className:"rounded-full ring-1 ring-[#02040A]",children:e.jsx(Vn,{name:p.name,hint:`${p.id} ${i.title}`,size:"xs"})},`${i.id}:${p.id}`))}),e.jsxs("span",{className:"max-w-[110px] truncate text-micro text-white/62",title:we,children:[($t=i.assignedAgents[0])==null?void 0:$t.name,i.assignedAgents.length>1?` +${i.assignedAgents.length-1}`:""]})]}):e.jsx("span",{className:"text-muted",children:"Unassigned"})})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:be?e.jsx("select",{defaultValue:ps(i.status),onClick:p=>p.stopPropagation(),onChange:p=>{j(i,{status:p.target.value})},className:"rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82",children:jn.map(p=>e.jsx("option",{value:p,children:Oe(p)},p))}):e.jsx("span",{className:"status-pill whitespace-nowrap","data-tone":ma(i.status),children:Oe(i.status)})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:Se!==void 0&&(i.type==="workstream"||i.type==="milestone")?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-1 w-[72px] rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${Se}%`,backgroundColor:i.type==="milestone"?Y.teal:Y.lime}})}),e.jsxs("span",{className:"text-micro text-secondary",style:{fontVariantNumeric:"tabular-nums"},children:[Se,"%"]})]}):e.jsx("span",{className:"text-muted",children:"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:be?e.jsx("input",{type:"number",min:1,max:100,defaultValue:i.priorityNum,onClick:p=>p.stopPropagation(),onBlur:p=>{const _=Number(p.currentTarget.value);Number.isFinite(_)&&j(i,{priority_num:_})},className:"w-[72px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("span",{className:`inline-flex items-center rounded-full border px-2 py-0.5 text-micro font-semibold uppercase tracking-[0.08em] ${_e.toneClass}`,title:`Priority ${_e.label}`,children:_e.label})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:be?e.jsx("input",{type:"datetime-local",defaultValue:ua(i.etaEndAt),onClick:p=>p.stopPropagation(),onBlur:p=>{const _=p.currentTarget.value;j(i,{eta_end_at:_?new Date(_).toISOString():null})},className:"w-[176px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("span",{children:i.etaEndAt?new Date(i.etaEndAt).toLocaleString():"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:be&&i.type!=="task"?e.jsx("input",{type:"number",min:0,step:.5,defaultValue:i.expectedDurationHours,onClick:p=>p.stopPropagation(),onBlur:p=>{const _=Number(p.currentTarget.value);Number.isFinite(_)&&j(i,{expected_duration_hours:_})},className:"w-[82px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("span",{children:i.expectedDurationHours})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:be&&i.type!=="task"?e.jsx("input",{type:"number",min:0,step:1,defaultValue:i.expectedBudgetUsd,onClick:p=>p.stopPropagation(),onBlur:p=>{const _=Number(p.currentTarget.value);Number.isFinite(_)&&j(i,{expected_budget_usd:_})},className:"w-[92px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsxs("span",{children:["$",i.expectedBudgetUsd.toLocaleString(),be&&i.type==="task"?" (from task spec)":""]})}),e.jsx("td",{className:"rounded-r-lg px-2 py-1.5 text-caption text-primary",children:be?e.jsx("div",{onClick:p=>p.stopPropagation(),children:e.jsx(oa,{dependencies:i.dependencyIds,allNodes:oe,onSave:p=>void j(i,{depends_on:p})})}):e.jsx("div",{className:"max-w-[250px] truncate",children:et(i)>0?`${et(i)} · ${Fe}`:"—"})})]},i.id)})})]})})]})}),fe.length===0&&e.jsxs("div",{className:"flex flex-col items-center py-10",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-faint",children:[e.jsx("path",{d:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"}),e.jsx("rect",{x:"9",y:"3",width:"6",height:"4",rx:"1"}),e.jsx("path",{d:"M9 14h6M9 18h4"})]}),e.jsx("div",{className:"mt-3 text-body font-medium text-secondary",children:l||u.size>0||k!=="all"?"No items match the current filters":"No work items yet"}),e.jsx("div",{className:"mt-1 text-caption text-muted",children:l||u.size>0||k!=="all"?"Try adjusting your search or filter criteria.":"Workstreams, milestones, and tasks will appear here."})]})]})}function kn(t){if(!t)return"No target date";const s=new Date(t);return Number.isNaN(s.getTime())?"No target date":`Due ${s.toLocaleDateString()}`}function ba({recentTodoIds:t,nodesById:s,selectedNodeId:r,onSelectNode:n}){const c=t.map(h=>s.get(h)).filter(h=>!!h).sort((h,b)=>{if(h.priorityNum!==b.priorityNum)return h.priorityNum-b.priorityNum;const j=h.dueDate?Date.parse(h.dueDate):Number.POSITIVE_INFINITY,x=b.dueDate?Date.parse(b.dueDate):Number.POSITIVE_INFINITY;return j-x}).slice(0,14);if(c.length===0)return null;const o=c[0],d=c.slice(1,7);return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Queue overview"}),e.jsxs("span",{className:"rounded-full border border-white/15 bg-black/20 px-2 py-0.5 text-micro text-secondary",children:[c.length," in queue"]})]}),e.jsx("button",{type:"button",onClick:()=>n(o.id),className:`surface-hero group w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${r===o.id?"border-[#BFFF00]/35 bg-[#BFFF00]/14":"border-white/15 bg-black/25 hover:border-white/30 hover:bg-white/[0.08]"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-micro uppercase tracking-[0.1em] text-secondary",children:[e.jsx(ys,{type:o.type}),e.jsx("span",{children:"Priority task"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-body font-semibold leading-snug text-white",children:o.title}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:kn(o.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold",style:{borderColor:`${Y.amber}44`,backgroundColor:`${Y.amber}22`,color:Y.amber},children:["P",o.priorityNum]})]})}),d.length>0&&e.jsx("div",{className:"space-y-1.5",children:d.map(h=>e.jsxs("button",{type:"button",onClick:()=>n(h.id),className:`flex min-h-[62px] min-w-0 items-start justify-between gap-2 rounded-lg border px-2.5 py-2 text-left transition-colors ${r===h.id?"border-[#BFFF00]/30 bg-[#BFFF00]/12":"border-strong bg-black/20 hover:bg-white/[0.08]"}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-micro uppercase tracking-[0.08em] text-secondary",children:[e.jsx(ys,{type:h.type}),e.jsx("span",{children:"Queued"})]}),e.jsx("p",{className:"mt-1 line-clamp-1 break-words text-caption leading-snug text-bright",title:h.title,children:h.title}),e.jsx("p",{className:"mt-1 text-micro text-secondary",children:kn(h.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full px-1.5 py-0.5 text-micro",style:{backgroundColor:`${Y.amber}22`,color:`${Y.amber}`},children:["P",h.priorityNum]})]},h.id))})]})}function ya(t,s){try{const r=localStorage.getItem(`orgx.section.${t}`);if(r==="0")return!1;if(r==="1")return!0}catch{}return s}function wa(t,s){try{localStorage.setItem(`orgx.section.${t}`,s?"1":"0")}catch{}}function xs({title:t,defaultOpen:s=!0,storageKey:r,sticky:n=!1,stickyOffsetClass:c="top-0",stickyTop:o,contentOverflowVisible:d=!1,children:h}){const[b,j]=a.useState(()=>r?ya(r,s):s),[x,F]=a.useState(!1),M=a.useRef(null),[N,l]=a.useState(40),y=()=>{const u=!b;j(u),r&&wa(r,u)};return a.useEffect(()=>{if(!n)return;const u=M.current;if(!u)return;const w=()=>{const g=Math.max(34,u.offsetHeight);l(C=>C===g?C:g)};if(w(),typeof ResizeObserver>"u")return;const k=new ResizeObserver(()=>w());return k.observe(u),()=>k.disconnect()},[n,o,t]),e.jsxs("div",{style:n?{"--mc-collapsible-header-offset":`${N}px`}:void 0,children:[e.jsxs("button",{ref:n?M:void 0,type:"button","data-mc-section-header":t,onClick:y,className:`flex w-full items-center gap-2 rounded-lg border px-2 py-2 text-left transition-colors ${n?`sticky ${c} z-20 border-white/[0.08] bg-[#090B11]/92 shadow-[0_8px_18px_rgba(0,0,0,0.24)] backdrop-blur-xl`:"border-transparent hover:border-subtle hover:bg-white/[0.03]"}`,style:n&&o?{top:o}:void 0,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-muted transition-transform duration-200 ${b?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsx("span",{className:"text-caption font-semibold tracking-[0.02em] text-white/68",children:t})]}),e.jsx(pt,{initial:!1,children:b&&e.jsx(ge.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{type:"spring",stiffness:400,damping:35},onAnimationStart:()=>F(!0),onAnimationComplete:()=>F(!1),className:d&&!x?"overflow-visible":"overflow-hidden",children:h})})]})}function va(t){if(!t)return{priorityNum:60,priorityLabel:null};const s=t.trim().toLowerCase();if(s==="urgent"||s==="p0")return{priorityNum:10,priorityLabel:"urgent"};if(s==="high"||s==="p1")return{priorityNum:25,priorityLabel:"high"};if(s==="medium"||s==="p2")return{priorityNum:50,priorityLabel:"medium"};if(s==="low"||s==="p3"||s==="p4")return{priorityNum:75,priorityLabel:"low"};const r=Number(s.replace(/^p/,""));return Number.isFinite(r)?{priorityNum:Math.max(1,Math.min(100,Math.round(r))),priorityLabel:null}:{priorityNum:60,priorityLabel:null}}function ja(t){const s=t.toLowerCase();return["todo","not_started","planned","pending","backlog"].includes(s)}function ka(t){const s=t.toLowerCase();return["in_progress","active","running","queued"].includes(s)}function Na(t,s){const r={id:t.id,type:"initiative",title:t.name,status:t.rawStatus??t.status,parentId:null,initiativeId:t.id,workstreamId:null,milestoneId:null,priorityNum:60,priorityLabel:null,dependencyIds:[],dueDate:t.targetDate??null,etaEndAt:t.targetDate??null,expectedDurationHours:40,expectedBudgetUsd:1500,assignedAgents:[],updatedAt:t.updatedAt??t.createdAt??null},c=(s.workstreams.length>0?s.workstreams:(t.workstreams??[]).map(x=>({id:x.id,name:x.name,summary:null,status:x.status,progress:null,initiativeId:t.id,createdAt:null}))).map(x=>({id:x.id,type:"workstream",title:x.name,status:x.status,parentId:t.id,initiativeId:t.id,workstreamId:x.id,milestoneId:null,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:null,etaEndAt:null,expectedDurationHours:16,expectedBudgetUsd:300,assignedAgents:[],updatedAt:x.createdAt})),o=new Set(c.map(x=>x.id)),d=s.milestones.map(x=>({id:x.id,type:"milestone",title:x.title,status:x.status,parentId:x.workstreamId&&o.has(x.workstreamId)?x.workstreamId:t.id,initiativeId:t.id,workstreamId:x.workstreamId&&o.has(x.workstreamId)?x.workstreamId:null,milestoneId:x.id,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:x.dueDate,etaEndAt:x.dueDate,expectedDurationHours:6,expectedBudgetUsd:120,assignedAgents:[],updatedAt:x.createdAt})),h=new Set(d.map(x=>x.id)),b=s.tasks.map(x=>{const F=va(x.priority),M=x.milestoneId&&h.has(x.milestoneId),N=x.workstreamId&&o.has(x.workstreamId);return{id:x.id,type:"task",title:x.title,status:x.status,parentId:M?x.milestoneId:N?x.workstreamId:t.id,initiativeId:t.id,workstreamId:N?x.workstreamId:null,milestoneId:M?x.milestoneId:null,priorityNum:F.priorityNum,priorityLabel:F.priorityLabel,dependencyIds:[],dueDate:x.dueDate,etaEndAt:x.dueDate,expectedDurationHours:2,expectedBudgetUsd:40,assignedAgents:[],updatedAt:x.createdAt}}),j=b.filter(x=>["todo","not_started","planned","pending","backlog"].includes(x.status.toLowerCase())).sort((x,F)=>{const M=x.priorityNum-F.priorityNum;if(M!==0)return M;const N=x.etaEndAt?Date.parse(x.etaEndAt):1/0,l=F.etaEndAt?Date.parse(F.etaEndAt):1/0;if(N!==l)return N-l;const y=x.updatedAt?Date.parse(x.updatedAt):0;return(F.updatedAt?Date.parse(F.updatedAt):0)-y}).map(x=>x.id);return{nodes:[r,...c,...d,...b],edges:[],recentTodos:j}}function Sa(t,s){if(!t)return new Set;const r=new Map(s.map(d=>[d.id,d])),n=new Map;for(const d of s)for(const h of d.dependencyIds){const b=n.get(h)??[];b.push(d.id),n.set(h,b)}const c=new Set,o=[t];for(;o.length>0;){const d=o.shift();if(c.has(d))continue;c.add(d);const h=r.get(d);if(h){for(const b of h.dependencyIds)c.has(b)||o.push(b);for(const b of n.get(d)??[])c.has(b)||o.push(b)}}return c}function Ca(t,s){return{id:t.id,name:t.title,summary:null,status:t.status,progress:null,initiativeId:s.id,createdAt:t.updatedAt}}function Fa(t,s){return{id:t.id,title:t.title,description:null,status:t.status,dueDate:t.dueDate,initiativeId:s.id,workstreamId:t.workstreamId,createdAt:t.updatedAt}}function Ea(t,s){return{id:t.id,title:t.title,description:null,status:t.status,priority:t.priorityLabel??`p${t.priorityNum}`,dueDate:t.dueDate,initiativeId:s.id,milestoneId:t.milestoneId,workstreamId:t.workstreamId,createdAt:t.updatedAt}}const ns={hidden:{opacity:0},show:{opacity:1}};function hs({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.03] px-2.5 py-2",children:[e.jsx("div",{className:"text-micro text-secondary",children:t}),e.jsx("div",{className:"mt-0.5 text-body font-semibold text-bright",children:s})]})}function Aa({initiative:t,selected:s=!1,onSelectionChange:r,isSquished:n=!1,runtimeActivity:c=null}){var $t;const{expandedInitiatives:o,toggleExpanded:d,openModal:h,agentEntityMap:b,authToken:j,embedMode:x,mutations:F}=Dt(),[M,N]=a.useState(!1),[l,y]=a.useState(null),[u,w]=a.useState(null),[k,g]=a.useState(!1),[C,T]=a.useState(!1),[U,P]=a.useState(null),[J,ee]=a.useState(!1),te=a.useRef(null),[q,$]=a.useState(52),[v,H]=a.useState(0),S=o.has(t.id),{graph:W,isLoading:L,degraded:se,error:R,refetch:X}=sa({initiativeId:t.id,authToken:j,embedMode:x,enabled:S}),{details:ie,isLoading:de,error:I}=ws({initiativeId:t.id,authToken:j,embedMode:x,enabled:S}),Q=ls({authToken:j,embedMode:x}),oe=a.useMemo(()=>Na(t,ie),[t,ie]),Ie=!!(W&&W.nodes.length>0),He=oe.nodes.length>0,ze=!Ie&&He,f=ze?oe.nodes:Ie?(W==null?void 0:W.nodes)??[]:oe.nodes,re=ze?oe.edges:Ie?(W==null?void 0:W.edges)??[]:oe.edges,V=ze?oe.recentTodos:Ie?(W==null?void 0:W.recentTodos)??[]:oe.recentTodos,pe=se.some(p=>/401|unauthorized/i.test(p))||!!(R&&/401|unauthorized/i.test(R))||!!(I&&/401|unauthorized/i.test(I)),Ce=R&&/unknown api endpoint/i.test(R)?"Graph API unavailable. Showing session-derived data.":R,De=I,Ue=[...se,...Ce?[Ce]:[],...De?[`Entity data partially unavailable: ${De}`]:[],...pe?["OrgX auth is missing or expired in this local plugin instance. Reconnect in onboarding to load full workstreams/milestones/tasks."]:[]],Le=Ue.filter(p=>/cyclic dependency edge/i.test(p)),fe=Le.reduce((p,_)=>{const me=/detected\s+(\d+)\s+cyclic dependency edge/i.exec(_);return p+(me&&Number(me[1])||0)},0),Pe=Le.length>0,Re=async()=>{if(!J){ee(!0);try{const p=await fetch("/orgx/api/mission-control/graph/cycles/auto-fix",{method:"POST",headers:xt({authToken:j,embedMode:x,contentTypeJson:!0}),body:JSON.stringify({initiativeId:t.id})}),_=await p.json().catch(()=>null);if(!p.ok)throw new Error((_==null?void 0:_.error)??(_==null?void 0:_.message)??`Failed to auto-fix dependency cycles (${p.status})`);const me=typeof(_==null?void 0:_.cycleEdgesDetected)=="number"?_.cycleEdgesDetected:fe,Be=typeof(_==null?void 0:_.nodesUpdated)=="number"?_.nodesUpdated:0,Ve=typeof(_==null?void 0:_.nodesFailed)=="number"?_.nodesFailed:0;P({tone:Ve>0?"error":"success",message:Ve>0?`Auto-fix removed ${me} cyclic edge${me===1?"":"s"} and updated ${Be} nodes (${Ve} failed).`:`Auto-fix removed ${me} cyclic edge${me===1?"":"s"} and updated ${Be} nodes.`}),X()}catch(p){P({tone:"error",message:p instanceof Error?p.message:"Failed to auto-fix dependency cycles."})}finally{ee(!1)}}},Ne=a.useMemo(()=>new Map(f.map(p=>[p.id,p])),[f]),Me=a.useMemo(()=>Sa(l,f),[l,f]),ht=a.useMemo(()=>V.some(p=>Ne.has(p)),[Ne,V]);a.useEffect(()=>{const p=te.current;if(!p||!S)return;const _=()=>{const Be=Math.max(48,p.offsetHeight);$(Ve=>Ve===Be?Ve:Be)};if(_(),typeof ResizeObserver>"u")return;const me=new ResizeObserver(()=>_());return me.observe(p),()=>me.disconnect()},[S,t.status,t.targetDate,t.name]),a.useEffect(()=>{const p=te.current;if(!p||!S){H(0);return}const _=p.closest('[data-mc-scroll-host="true"]')??p.closest(".h-full.overflow-y-auto.overflow-x-hidden"),me=_??window;let Be=0;const Ve=()=>{Be=0;const Wt=Number.parseFloat(getComputedStyle(p).top||"0"),mt=p.getBoundingClientRect(),le=(_==null?void 0:_.getBoundingClientRect().top)??0,Qt=1-(mt.top-le-Wt)/56,ts=Math.pow(Math.max(0,Math.min(1,Qt)),1.2);H(O=>Math.abs(O-ts)<.015?O:ts)},xe=()=>{Be||(Be=window.requestAnimationFrame(Ve))};return Ve(),me.addEventListener("scroll",xe,{passive:!0}),window.addEventListener("resize",xe),()=>{Be&&window.cancelAnimationFrame(Be),me.removeEventListener("scroll",xe),window.removeEventListener("resize",xe)}},[S,t.id]),a.useEffect(()=>{var p;S&&!l&&f.length>0&&y(((p=f[0])==null?void 0:p.id)??null)},[S,f,l]),a.useEffect(()=>{if(!U)return;const p=window.setTimeout(()=>P(null),U.tone==="success"?2800:4200);return()=>window.clearTimeout(p)},[U]);const St=((W==null?void 0:W.initiative.assignedAgents)??[]).map(p=>({id:p.id,name:p.name,confidence:"high"})),je=b.get(t.id)??[],Je=St.length>0?St:je,$e=f.filter(p=>p.type==="task"),et=$e.filter(p=>ka(p.status)).length,ft=$e.filter(p=>ja(p.status)).length,wt=$e.filter(p=>Ze(p.status)).length,Ye=(c==null?void 0:c.activeCount)??0,Qe=(c==null?void 0:c.totalCount)??0,We=et>0||Ye>0,dt=t.status==="active"&&We?"in_progress":t.status,tt=dt==="in_progress"?bs.active:bs[dt],st=dt==="in_progress"?"In Progress":Oe(dt),Ut=$e.length>0?$e:f.some(p=>p.type==="milestone")?f.filter(p=>p.type==="milestone"):f.filter(p=>p.type==="workstream"),vt=Math.round(Ut.reduce((p,_)=>p+(_.expectedDurationHours||0),0)*10)/10,ut=Math.round(Ut.reduce((p,_)=>p+(_.expectedBudgetUsd||0),0)*100)/100,Ct=f.filter(p=>p.type==="milestone"),nt=f.filter(p=>p.type==="workstream"),Mt=Q.isPinning||Q.isMoving,ke=(t.rawStatus??t.status??"").trim().toLowerCase().replace(/[\s-]+/g,"_"),rt=new Set(["paused","draft","planned","todo","backlog","queued"]).has(ke),Xe=ke==="paused"?"Resume":"Start",at=!n,jt=at||rt,i=n,E=a.useMemo(()=>nt.filter(p=>p.initiativeId===t.id).sort((p,_)=>p.priorityNum-_.priorityNum||p.title.localeCompare(_.title)),[t.id,nt]),A=S&&(Ie||ie.workstreams.length>0||ie.milestones.length>0||ie.tasks.length>0),z=$e.length>0?zt(wt,$e.length):Ct.length>0?zt(Ct.filter(p=>Ze(p.status)).length,Ct.length):A&&nt.length>0?zt(nt.filter(p=>Ze(p.status)).length,nt.length):null,G=ks(z===null?t.health:z),ue=G===0?2:G,we=Math.pow(v,.82),Fe=Math.max(0,Number((16*(1-we)).toFixed(2))),Se=`0 10px 26px rgba(0,0,0,${(.18+we*.24).toFixed(3)}), 0 1px 0 rgba(191,255,0,${(we*.09).toFixed(3)})`,_e=async p=>{if(E.length===0){P({tone:"error",message:"No workstreams available to queue for this initiative."});return}const _=p==="top"?[...E].reverse():E;let me=0,Be=0,Ve=null;for(const xe of _)try{await Q.pin({initiativeId:t.id,workstreamId:xe.id}),await Q.move({initiativeId:t.id,workstreamId:xe.id,placement:p}),me+=1}catch(Wt){Be+=1,Ve||(Ve=Wt instanceof Error?Wt.message:"Failed to queue this initiative.")}if(Be>0){P({tone:me>0?"success":"error",message:me>0?`Queued ${me}/${E.length} workstreams (${Be} failed).`:Ve??"Failed to queue initiative workstreams."});return}P({tone:"success",message:`Queued ${me} workstream${me===1?"":"s"} to ${p==="top"?"top":"end"}.`})},be=p=>{if(p.type==="initiative"){h({type:"initiative",entity:t});return}if(p.type==="workstream"){h({type:"workstream",entity:Ca(p,t),initiative:t});return}if(p.type==="milestone"){h({type:"milestone",entity:Fa(p,t),initiative:t});return}h({type:"task",entity:Ea(p,t),initiative:t})},it=async(p,_)=>{await F.updateEntity.mutateAsync({type:p.type,id:p.id,..._})},ye=p=>_=>{_.stopPropagation(),F.entityAction.mutate({type:"initiative",id:t.id,action:p})},kt=p=>{p.stopPropagation(),F.updateEntity.mutate({type:"initiative",id:t.id,status:"active"})};return e.jsxs("div",{id:`initiative-${t.id}`,className:`surface-tier-1 overflow-visible rounded-2xl transition-[background-color,border-color,box-shadow] duration-200 ${S?"bg-[--orgx-surface-elevated]":"bg-[--orgx-surface]"} ${s?"ring-1 ring-[#BFFF00]/30 shadow-[0_0_0_1px_rgba(191,255,0,0.12)]":""}`,style:{"--mc-initiative-header-offset":`${q}px`},children:[e.jsxs("div",{ref:te,role:"button",tabIndex:0,"aria-expanded":S,onClick:()=>d(t.id),onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),d(t.id))},className:`group flex min-h-[66px] w-full min-w-0 items-center gap-2.5 overflow-visible px-3 py-3 text-left transition-[background-color,border-radius,box-shadow] duration-300 hover:bg-white/[0.035] sm:gap-3 sm:px-4 ${S?"sticky z-30 border-b border-subtle bg-[#0C0E14]/95 shadow-[0_8px_20px_rgba(0,0,0,0.3)] backdrop-blur-xl":""}`,style:S?{top:"var(--mc-toolbar-offset, 88px)",borderTopLeftRadius:`${Fe}px`,borderTopRightRadius:`${Fe}px`,boxShadow:Se}:void 0,children:[e.jsx(ge.div,{animate:{rotate:S?90:0},transition:{type:"spring",stiffness:400,damping:25},className:"flex-shrink-0 flex items-center justify-center w-6 h-6 rounded-md transition-colors group-hover:bg-white/[0.06]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-muted",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),r&&e.jsx("div",{className:"flex h-6 w-6 flex-shrink-0 items-center justify-center",children:e.jsx("input",{type:"checkbox",checked:s,onChange:p=>{const _=p.nativeEvent.shiftKey??!1;r(t.id,p.currentTarget.checked,_)},onClick:p=>p.stopPropagation(),"aria-label":`Select initiative ${t.name}`,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"})}),e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${We?"status-breathe":""}`,style:{backgroundColor:Ps(dt)}}),e.jsx("div",{className:"min-w-0 flex-[1_1_auto] overflow-hidden pr-1.5 sm:pr-2",children:e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),h({type:"initiative",entity:t})},className:"block w-full max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-left text-body font-semibold text-white transition-colors hover:text-primary sm:text-heading",title:t.name,children:t.name})}),e.jsx("div",{className:`ml-1 flex flex-shrink-0 justify-start ${n?"w-[80px] min-w-[80px]":"w-[90px] min-w-[90px] sm:w-[102px] sm:min-w-[102px]"}`,children:e.jsx("span",{className:`w-full truncate text-center text-micro rounded-full border py-0.5 uppercase tracking-[0.08em] leading-none whitespace-nowrap ${n?"px-1.5":"px-2"} ${tt}`,children:st})}),e.jsx("div",{className:`ml-1.5 flex-shrink-0 ${i?"flex":"lg:hidden"}`,title:`${G}% complete`,children:e.jsxs("svg",{viewBox:"0 0 36 36",className:"h-9 w-9","aria-label":`${G}% complete`,children:[e.jsx("circle",{cx:"18",cy:"18",r:"15",fill:"none",stroke:"rgba(255,255,255,0.06)",strokeWidth:"3"}),e.jsx(ge.circle,{cx:"18",cy:"18",r:"15",fill:"none",stroke:Ps(dt),strokeWidth:"3",strokeLinecap:"round",initial:!1,animate:{strokeDasharray:`${ue/100*94.25} 94.25`,opacity:G===0?.45:1},transition:{type:"spring",stiffness:260,damping:34,mass:.75},transform:"rotate(-90 18 18)"}),e.jsxs("text",{x:"18",y:"19",textAnchor:"middle",dominantBaseline:"central",fill:"currentColor",fontSize:"9",fontWeight:"600",className:"text-muted",children:[G,"%"]})]})}),e.jsxs("div",{className:`ml-1.5 hidden w-[148px] min-w-[148px] flex-shrink-0 items-center justify-end gap-2.5 pr-0.5 xl:w-[182px] xl:min-w-[182px] xl:pr-1 2xl:w-[206px] 2xl:min-w-[206px] ${i?"hidden":"lg:flex"}`,children:[e.jsx("div",{className:"min-w-[88px] flex-1 xl:min-w-[112px] 2xl:min-w-[140px]",children:e.jsx("div",{className:"h-[2px] w-full overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx(ge.div,{className:"h-full rounded-full transition-all",initial:!1,animate:{width:`${ue}%`,opacity:G===0?.45:1},transition:{type:"spring",stiffness:260,damping:34,mass:.75},style:{backgroundColor:Ps(dt)}})})}),e.jsxs("span",{className:"w-[42px] text-right text-micro text-muted xl:w-[48px] xl:text-caption",style:{fontVariantNumeric:"tabular-nums"},children:[G,"%"]})]}),jt&&e.jsxs("div",{className:`ml-1 hidden flex-shrink-0 items-center justify-end gap-1.5 lg:flex ${n?"w-[40px] min-w-[40px]":"w-[180px] min-w-[180px]"}`,children:[at&&e.jsx(Ns,{label:"Queue",size:"sm",busy:Mt,disabled:E.length===0,stopPropagation:!0,title:`Queue initiative: ${t.name}`,onSelectPlacement:_e}),rt&&e.jsxs("button",{type:"button",onClick:kt,disabled:F.updateEntity.isPending,title:`${Xe} initiative`,className:`control-pill inline-flex items-center justify-center gap-1.5 text-micro font-semibold text-[#D8FFA1] disabled:opacity-45 ${n?"h-8 w-8 px-0":"h-8 px-2.5"}`,"data-state":"active",children:[e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),!n&&e.jsx("span",{children:Xe})]})]}),e.jsx("div",{className:`ml-2 w-[104px] min-w-[104px] flex-shrink-0 items-center justify-end border-l border-subtle pl-2 lg:w-[116px] lg:min-w-[116px] lg:pl-2.5 xl:w-[132px] xl:min-w-[132px] ${n?"hidden":"hidden md:flex"}`,children:Ye>0?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/14 px-2 py-0.5 text-micro font-semibold text-[#D8FFA1]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00] status-breathe"}),Ye," live"]}):Je.length>0?e.jsx(vs,{agents:Je,max:3}):Qe>0?e.jsxs("span",{className:"w-full text-right text-micro text-muted",children:[Qe," idle"]}):e.jsx("span",{className:"w-full text-right text-micro text-white/28",children:"—"})}),e.jsxs("div",{className:"hidden w-[46px] flex-shrink-0 translate-x-1 items-center justify-end gap-1 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 group-focus-within:translate-x-0 group-focus-within:opacity-100 2xl:flex",children:[t.status==="active"&&e.jsx("button",{type:"button",onClick:ye("pause"),title:"Pause",className:"flex items-center justify-center w-6 h-6 rounded-lg text-secondary hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})}),t.status==="paused"&&e.jsx("button",{type:"button",onClick:ye("resume"),title:"Resume",className:"flex items-center justify-center w-6 h-6 rounded-lg text-secondary hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}),e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),h({type:"initiative",entity:t})},title:"Details",className:"flex items-center justify-center w-6 h-6 rounded-lg text-secondary hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4M12 8h.01"})]})})]})]}),U&&e.jsx("div",{role:"status","aria-live":"polite",className:`mx-3 mb-2 rounded-lg border px-2.5 py-1.5 text-micro ${U.tone==="success"?"border-[#BFFF00]/24 bg-[#BFFF00]/[0.1] text-[#D8FFA1]":"border-red-400/24 bg-red-500/[0.1] text-red-100"}`,children:U.message}),e.jsx(pt,{children:S&&e.jsx(ge.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.2,ease:[.22,1,.36,1]},onAnimationStart:()=>T(!0),onAnimationComplete:()=>T(!1),className:C?"overflow-hidden":"overflow-visible",children:e.jsxs("div",{className:"space-y-2.5 px-4 pb-4 pt-2.5",children:[e.jsx("div",{className:"section-divider"}),L||!Ie&&de?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((p,_)=>e.jsx(yt,{className:"h-24 w-full rounded-xl"},`mc-loading-${_}`))}):e.jsxs(ge.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.08}}},className:"space-y-3.5",children:[Ue.length>0&&e.jsxs(ge.div,{variants:ns,className:"overflow-hidden rounded-lg border border-amber-300/15 bg-amber-500/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>g(p=>!p),className:"flex min-w-0 flex-1 items-center justify-between text-left transition-colors hover:text-white",children:[e.jsx("span",{className:"truncate text-caption text-amber-100/85",children:Pe?`Dependency loop detected (${fe||Le.length} edges)`:`${Ue.length} data source${Ue.length>1?"s":""} unavailable`}),e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`ml-2 text-amber-100/55 transition-transform ${k?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),Pe?e.jsx("button",{type:"button",onClick:Re,disabled:J,className:"control-pill h-7 flex-shrink-0 px-2.5 text-micro font-semibold text-[#D8FFA1] disabled:opacity-45",children:J?"Fixing…":"Auto-fix"}):null]}),e.jsx(pt,{children:k&&e.jsx(ge.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{duration:.15},className:"overflow-hidden",children:e.jsx("div",{className:"space-y-1 px-3 pb-2",children:Ue.map((p,_)=>e.jsx("div",{className:"text-micro text-amber-100/72",children:ct(p)},_))})})})]}),(ft>0||et>0||vt>0||ut>0)&&e.jsx(ge.div,{variants:ns,children:e.jsx(xs,{title:"Stats",storageKey:`stats.${t.id}`,defaultOpen:!0,children:e.jsxs("div",{className:"grid gap-2 py-0.5 sm:grid-cols-2 lg:grid-cols-4",children:[e.jsx(hs,{label:"Queue",value:`${ft} todo · ${et} active`}),e.jsx(hs,{label:"Completed",value:`${wt}/${$e.length||0}`}),e.jsx(hs,{label:"Duration",value:`${vt}h`}),e.jsx(hs,{label:"Budget",value:`$${ut.toLocaleString()}`})]})})}),u&&e.jsxs("div",{className:"subsection-shell flex items-center justify-between rounded-lg px-3 py-2 text-caption text-[#D8FFA1]",children:[e.jsxs("span",{children:["Focused on workstream ",(($t=Ne.get(u))==null?void 0:$t.title)??u]}),e.jsx("button",{type:"button",onClick:()=>w(null),className:"text-micro underline underline-offset-2",children:"Clear focus"})]}),e.jsx(ge.div,{variants:ns,children:e.jsx(xs,{title:"Dependency Map",storageKey:`depmap.${t.id}`,defaultOpen:!0,children:e.jsx(ra,{nodes:f,edges:re,selectedNodeId:l,focusedWorkstreamId:u,onSelectNode:p=>{y(p);const _=Ne.get(p);(_==null?void 0:_.type)==="workstream"&&w(_.id)}})})}),ht&&e.jsx(ge.div,{variants:ns,children:e.jsx(xs,{title:"Next Up",storageKey:`nextup.${t.id}`,defaultOpen:!0,children:e.jsx(ba,{recentTodoIds:V,nodesById:Ne,selectedNodeId:l,onSelectNode:p=>{y(p);const _=Ne.get(p);(_==null?void 0:_.type)==="workstream"&&w(_.id)}})})}),e.jsx(ge.div,{variants:ns,children:e.jsx(xs,{title:"Hierarchy",storageKey:`hierarchy.${t.id}`,defaultOpen:!0,contentOverflowVisible:!0,children:e.jsx(ga,{nodes:f,edges:re,selectedNodeId:l,highlightedNodeIds:Me,editMode:M,onSelectNode:y,onFocusWorkstream:w,onOpenNode:be,onUpdateNode:it,onToggleEditMode:()=>N(p=>!p),mutations:F})})})]}),e.jsxs("button",{type:"button",onClick:()=>d(t.id),className:"flex w-full items-center justify-center gap-1.5 py-1.5 text-micro text-muted transition-colors hover:text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"m18 15-6-6-6 6"})}),"Collapse"]})]})})})]})}const Ia={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.045,delayChildren:.02}}},Da={hidden:{opacity:0,y:10,scale:.995},show:{opacity:1,y:0,scale:1,transition:{type:"spring",stiffness:320,damping:28,mass:.7}}};function Nn({initiatives:t,selectedInitiativeIds:s,onToggleInitiativeSelection:r,isSquished:n=!1,runtimeActivityByInitiativeId:c}){return e.jsx(ge.div,{variants:Ia,initial:"hidden",animate:"show",className:"space-y-2",children:t.map(o=>e.jsx(ge.div,{variants:Da,layout:!0,transition:{type:"spring",stiffness:280,damping:32,mass:.75},children:e.jsx(Aa,{initiative:o,selected:(s==null?void 0:s.has(o.id))??!1,onSelectionChange:r,isSquished:n,runtimeActivity:(c==null?void 0:c.get(o.id))??null})},o.id))})}function Os({mode:t="empty",hasActiveFilters:s=!1,detail:r=null,onClearFilters:n,onCreateInitiative:c,onPlayNextUp:o,onStartAutopilot:d,onRefresh:h,onOpenSettings:b}){const[j,x]=a.useState(null),[F,M]=a.useState(null),N=a.useCallback(async(u,w)=>{if(w){M(null),x(u);try{await w()}catch(k){const g=k instanceof Error?k.message:"";M(g?ct(g):"Action failed")}finally{x(k=>k===u?null:k)}}},[]),l=t==="filtered"?"No initiatives match this view":t==="degraded"?"Initiatives are temporarily unavailable":"No initiatives yet",y=t==="filtered"?s?"Adjust filters or clear them to return to the full hierarchy.":"Try a broader search or create a new initiative.":t==="degraded"?"Live sync is reconnecting, so initiative and Next Up data may be stale.":"Create an initiative to unlock hierarchy, Next Up routing, and slice-level tracking.";return e.jsx("div",{className:"flex-1 flex items-center justify-center p-6 sm:p-10",children:e.jsx(Ar,{className:"w-full max-w-xl p-6 sm:p-7",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3.5",children:[e.jsx("div",{className:"relative flex h-12 w-12 items-center justify-center rounded-xl",style:{backgroundColor:`${Y.iris}1a`,border:`1px solid ${Y.iris}33`},children:e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:Y.iris,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 6v6l4 2"})]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:l}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:y})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t==="filtered"&&n&&e.jsx("button",{type:"button",onClick:n,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08]",children:"Clear filters"}),t==="degraded"&&b&&e.jsx("button",{type:"button",onClick:b,className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08]",children:"Open settings"}),c&&e.jsx("button",{type:"button",onClick:c,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/12 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1] transition hover:bg-[#BFFF00]/18",children:"Create initiative"}),o&&e.jsx("button",{type:"button",onClick:()=>void N("play",o),disabled:j!==null,className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08] disabled:opacity-45",children:j==="play"?"Dispatching...":"Play Next Up"}),d&&e.jsx("button",{type:"button",onClick:()=>void N("autopilot",d),disabled:j!==null,className:"rounded-full border border-[#0AD4C4]/30 bg-[#0AD4C4]/10 px-3 py-1.5 text-caption font-semibold text-[#98FFF5] transition hover:bg-[#0AD4C4]/16 disabled:opacity-45",children:j==="autopilot"?"Starting...":"Start Autopilot"}),h&&e.jsx("button",{type:"button",onClick:h,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-secondary transition hover:bg-white/[0.08] hover:text-primary",children:"Refresh"})]}),t==="degraded"&&r&&e.jsx("p",{className:"text-caption text-secondary",children:ct(r)}),F&&e.jsx("p",{className:"text-caption text-amber-200/80",children:F})]})})})}function ne({label:t,icon:s,color:r="#BFFF00",variant:n="secondary",size:c="md",className:o="",type:d="button",...h}){const b=c==="sm"?"px-2.5 py-1 text-micro":"px-3 py-1.5 text-caption",j=n==="primary"?{backgroundColor:r,color:"#05060A",borderColor:`${r}CC`}:n==="destructive"?{backgroundColor:`${r}18`,color:r,borderColor:`${r}45`}:n==="ghost"?{backgroundColor:"rgba(255,255,255,0.03)",color:"rgba(255,255,255,0.75)",borderColor:"rgba(255,255,255,0.12)"}:{backgroundColor:`${r}20`,color:r,borderColor:`${r}30`};return e.jsxs("button",{type:d,className:`inline-flex items-center gap-1.5 rounded-lg border transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${b} ${o}`,style:j,...h,children:[s,t&&e.jsx("span",{children:t})]})}const Sn={draft:Y.textMuted,in_review:Y.amber,approved:Y.lime,changes_requested:Y.red,superseded:Y.textMuted,archived:Y.textMuted};function Ma(t,s){const r=new Date().toISOString();return t==="initiative"&&s==="init-1"?[{id:"artifact-demo-init-1-brief",name:"Q4 dashboard polish brief",description:"Summary of final polish checklist and open items.",artifact_url:"#",artifact_type:"shared.project_handbook",status:"approved",metadata:{source:"demo"},created_at:r,updated_at:r},{id:"artifact-demo-init-1-copy",name:"Launch copy variants",description:"Three launch-ready copy variants for review.",artifact_url:"#",artifact_type:"document",status:"in_review",metadata:{source:"demo"},created_at:r,updated_at:r}]:t==="initiative"&&s==="init-2"?[{id:"artifact-demo-init-2-subjects",name:"Subject line variants",description:"Email subject line candidates with performance notes.",artifact_url:"#",artifact_type:"document",status:"approved",metadata:{source:"demo"},created_at:r,updated_at:r}]:[]}function $a(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-80",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}async function Cn(t,s,r){if(os())return Ma(t,s);try{const n=xt(r),c=new URLSearchParams({entity_type:t,entity_id:s,limit:"20"}),o=await fetch(`/orgx/api/work-artifacts/by-entity?${c.toString()}`,{headers:n});if(!o.ok)return[];const d=await o.json();return(d==null?void 0:d.artifacts)??[]}catch{return[]}}function Ss({entityType:t,entityId:s,title:r="Artifacts",authToken:n=null,embedMode:c=!1,finalOnly:o=!1,milestoneIds:d}){const{open:h}=Ir(),[b,j]=a.useState(!o),x=!!(d!=null&&d.length),F=Zt({queryKey:Ot.artifactsByEntity({entityType:t,entityId:s,authToken:n,embedMode:c}),enabled:!x&&!!s,queryFn:()=>Cn(t,s,{authToken:n,embedMode:c})}),M=Zt({queryKey:["artifacts-by-milestones",d,n,c],enabled:x,queryFn:async()=>{if(!(d!=null&&d.length))return[];const u=await Promise.all(d.map(k=>Cn("milestone",k,{authToken:n,embedMode:c}))),w=new Map;for(const k of u)for(const g of k)w.has(g.id)||w.set(g.id,g);return[...w.values()].sort((k,g)=>Date.parse(g.updated_at)-Date.parse(k.updated_at))}}),N=x?M:F,l=N.data??[],y=b?l:l.filter(u=>u.status==="approved");return N.isLoading?e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-caption font-medium text-secondary",children:r}),e.jsx("div",{className:"shimmer-skeleton h-10 w-full rounded-lg"})]}):l.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"text-caption font-medium text-secondary",children:[r," (",y.length,")"]}),o&&e.jsx("button",{type:"button",onClick:()=>j(u=>!u),className:"text-micro text-faint transition-colors hover:text-secondary",children:b?"Final only":"Show all"})]}),e.jsxs("div",{className:"space-y-1.5",children:[y.slice(0,10).map(u=>e.jsxs("button",{type:"button",onClick:()=>h(u.id,{entityType:t,entityId:s}),className:"flex w-full items-center gap-2.5 rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-left transition-colors hover:bg-white/[0.05]",children:[e.jsx($a,{}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body text-primary",children:u.name}),e.jsx("span",{className:"text-micro text-faint",children:u.artifact_type})]}),e.jsx("span",{className:"flex-shrink-0 rounded-full px-1.5 py-0.5 text-micro font-medium uppercase tracking-wider",style:{color:Sn[u.status]??Y.textMuted,backgroundColor:`${Sn[u.status]??Y.textMuted}15`},children:u.status})]},u.id)),y.length>10&&e.jsxs("p",{className:"text-micro text-faint pl-2",children:["+",y.length-10," more"]})]})]})}function Ta({initiative:t}){const{agentEntityMap:s,openModal:r,closeModal:n,authToken:c,embedMode:o,mutations:d}=Dt(),h=s.get(t.id)??[],[b,j]=a.useState(!1),[x,F]=a.useState(""),[M,N]=a.useState(!1),[l,y]=a.useState(!1),[u,w]=a.useState(null),[k,g]=a.useState(t.name),[C,T]=a.useState(t.description??""),[U,P]=a.useState(rs(t.priority)),[J,ee]=a.useState(zs(t.targetDate)),[te,q]=a.useState(null),{details:$,isLoading:v}=ws({initiativeId:t.id,authToken:c,embedMode:o}),H=ls({authToken:c,embedMode:o}),S=$.tasks.filter(f=>["active","in_progress"].includes(f.status.toLowerCase())).length,W=$.tasks.filter(f=>f.status.toLowerCase()==="blocked").length,L=$.tasks.filter(f=>Ze(f.status)).length,se=te??t.status,R=_a(te??t.rawStatus??t.status),X=["active","in_progress","running","queued"].includes(R),ie=["paused","draft","planned","todo","backlog","pending","not_started"].includes(R),de=d.entityAction.isPending||d.createEntity.isPending||d.updateEntity.isPending||d.deleteEntity.isPending,I=H.isPinning||H.isMoving,Q=a.useMemo(()=>$.workstreams.length>0?$.workstreams.map(f=>({id:f.id,name:f.name})):(t.workstreams??[]).map(f=>({id:f.id,name:f.name})),[$.workstreams,t.workstreams]),oe=(f,re)=>f&&f.trim().length>0?ct(f.trim()):re;a.useEffect(()=>{M||(g(t.name),T(t.description??""),ee(zs(t.targetDate)),P(rs(t.priority)))},[M,t.description,t.name,t.priority,t.targetDate]),a.useEffect(()=>{q(null),y(!1)},[t.id,t.status,t.rawStatus]);const Ie=(f,re,V)=>{w(null),d.entityAction.mutate({type:"initiative",id:t.id,action:f},{onSuccess:()=>{q(re),w(V)},onError:pe=>{w(oe(pe instanceof Error?pe.message:"",`Failed to ${f} initiative.`))}})},He=()=>{const f=k.trim();if(!f){w("Initiative title is required.");return}w(null),d.updateEntity.mutate({type:"initiative",id:t.id,title:f,summary:C.trim()||null,priority:U,target_date:J||null},{onSuccess:()=>{N(!1),w("Initiative updated.")},onError:re=>{w(oe(re instanceof Error?re.message:"","Failed to update initiative."))}})},ze=async f=>{if(Q.length===0){w("No workstreams available to queue.");return}const re=f==="top"?[...Q].reverse():Q;let V=0,pe=0,Ce=null;for(const De of re)try{await H.pin({initiativeId:t.id,workstreamId:De.id}),await H.move({initiativeId:t.id,workstreamId:De.id,placement:f}),V+=1}catch(Ue){pe+=1,Ce||(Ce=oe(Ue instanceof Error?Ue.message:"","Failed to queue initiative workstream."))}if(pe>0){w(V>0?`Queued ${V}/${Q.length} workstreams (${pe} failed).`:Ce??"Failed to queue initiative workstreams.");return}w(`Queued ${V} workstream${V===1?"":"s"} to ${f==="top"?"top":"end"}.`)};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{type:"initiative",size:16}),e.jsx("h2",{className:"text-title font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${bs[se]??bs.active}`,children:Oe(se)}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-white/68",children:Ba(t.priority)})]}),M?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Title"}),e.jsx("input",{type:"text",value:k,onChange:f=>g(f.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Summary"}),e.jsx("textarea",{value:C,onChange:f=>T(f.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Target date"}),e.jsx("input",{type:"date",value:J,onChange:f=>ee(f.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Priority"}),e.jsxs("select",{value:U,onChange:f=>P(rs(f.target.value)),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:[e.jsx("option",{value:"critical",children:"Critical (P0)"}),e.jsx("option",{value:"high",children:"High (P1)"}),e.jsx("option",{value:"medium",children:"Medium (P2)"}),e.jsx("option",{value:"low",children:"Low (P3)"})]})]})]}):t.description?e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:t.description}):e.jsx("p",{className:"text-body text-muted",children:"No summary yet."}),h.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Agents"}),e.jsx(vs,{agents:h,max:6})]}),u&&e.jsx("div",{className:"text-caption text-secondary",children:u})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(fs,{label:"Workstreams",value:`${$.workstreams.length}`}),e.jsx(fs,{label:"Milestones",value:`${$.milestones.length}`}),e.jsx(fs,{label:"Active Tasks",value:`${S}`,accent:S>0?Y.lime:void 0}),e.jsx(fs,{label:"Blocked",value:`${W}`,accent:W>0?Y.red:void 0})]}),v?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((f,re)=>e.jsx(yt,{className:"h-14 w-full rounded-lg"},`init-detail-${re}`))}):e.jsxs(e.Fragment,{children:[$.workstreams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fn,{title:"Workstreams",count:$.workstreams.length}),$.workstreams.map(f=>{const re=$.tasks.filter(Ce=>Ce.workstreamId===f.id),V=re.filter(Ce=>Ze(Ce.status)).length,pe=re.length>0?zt(V,re.length):typeof f.progress=="number"?ks(f.progress<=1?f.progress*100:f.progress):Ze(f.status)?100:null;return e.jsxs("button",{onClick:()=>r({type:"workstream",entity:f,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3.5 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-body text-bright break-words",children:f.name}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Kn(f.status)}`,children:Oe(f.status)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-3 text-micro text-muted uppercase tracking-[0.08em]",children:[e.jsxs("span",{children:[re.length," tasks"]}),pe!==null&&e.jsxs("span",{children:[pe,"%"]})]})]},f.id)})]}),$.milestones.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(Fn,{title:"Milestones",count:$.milestones.length}),$.milestones.map(f=>e.jsxs("button",{onClick:()=>r({type:"milestone",entity:f,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-body text-bright break-words",children:f.title}),e.jsx("span",{className:"text-micro text-muted uppercase tracking-[0.08em]",children:Oe(f.status)})]}),f.dueDate&&e.jsxs("span",{className:"text-micro text-muted mt-0.5 block",children:["Due: ",new Date(f.dueDate).toLocaleDateString()]})]},f.id))]}),e.jsxs("div",{className:"text-micro uppercase tracking-[0.08em] text-muted pt-2 border-t border-subtle",children:[$.tasks.length," total tasks · ",L," done"]}),e.jsx(Ss,{entityType:"initiative",entityId:t.id,authToken:c,embedMode:o}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-subtle",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted mb-2",children:"Notes"}),e.jsx(js,{entityType:"initiative",entityId:t.id,authToken:c,embedMode:o,variant:"inline"})]})]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[X&&e.jsx(ne,{label:"Pause",color:Y.amber,onClick:()=>Ie("pause","paused","Initiative paused."),disabled:de}),ie&&e.jsx(ne,{label:R==="paused"?"Resume":"Start",color:Y.lime,variant:"primary",onClick:()=>Ie("resume","active",R==="paused"?"Initiative resumed.":"Initiative started."),disabled:de}),e.jsx(Ns,{label:"Queue",size:"md",busy:I,disabled:de||Q.length===0,title:`Queue initiative: ${t.name}`,onSelectPlacement:ze}),M?e.jsxs(e.Fragment,{children:[e.jsx(ne,{label:"Save",color:Y.teal,variant:"primary",onClick:He,disabled:de||!k.trim()}),e.jsx(ne,{label:"Cancel",variant:"ghost",onClick:()=>{N(!1),g(t.name),T(t.description??""),P(rs(t.priority)),ee(zs(t.targetDate)),w(null)},disabled:de})]}):e.jsx(ne,{label:"Edit",variant:"ghost",onClick:()=>{N(!0),w(null)},disabled:de}),e.jsx("div",{className:"flex-1"}),l?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"Delete initiative?"}),e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>d.deleteEntity.mutate({type:"initiative",id:t.id},{onSuccess:()=>n(),onError:f=>w(f instanceof Error?f.message:"Failed to delete initiative.")}),disabled:de}),e.jsx(ne,{label:"Keep",variant:"ghost",onClick:()=>y(!1),disabled:de})]}):e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>y(!0),disabled:de}),b?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:f=>{f.preventDefault(),x.trim()&&d.createEntity.mutate({type:"workstream",title:x.trim(),initiative_id:t.id,status:"not_started"},{onSuccess:()=>{F(""),j(!1)}})},children:[e.jsx("input",{type:"text",value:x,onChange:f=>F(f.target.value),placeholder:"Workstream name...",autoFocus:!0,className:"text-body bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-primary placeholder-white/30 w-[180px] outline-none focus:border-white/25"}),e.jsx(ne,{type:"submit",label:"Add",color:Y.lime,disabled:!x.trim()||d.createEntity.isPending,size:"sm"}),e.jsx(ne,{label:"Cancel",variant:"ghost",onClick:()=>{j(!1),F("")},size:"sm"})]}):e.jsx(ne,{label:"+ Workstream",variant:"ghost",onClick:()=>j(!0),disabled:de})]})})]})}function zs(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function _a(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function rs(t){const s=(t??"").trim().toLowerCase();return s==="critical"||s==="p0"||s==="urgent"?"critical":s==="high"||s==="p1"?"high":s==="medium"||s==="normal"||s==="p2"?"medium":s==="low"||s==="p3"?"low":"medium"}function Ba(t){const s=rs(t);return s==="critical"?"Priority: Critical":s==="high"?"Priority: High":s==="low"?"Priority: Low":"Priority: Medium"}function fs({label:t,value:s,accent:r}){return e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",style:r?{borderTopColor:`${r}50`,borderTopWidth:2}:void 0,children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:t}),e.jsx("div",{className:"text-heading font-medium mt-0.5",style:{color:r??"rgba(255,255,255,0.8)"},children:s})]})}function Fn({title:t,count:s}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:t}),e.jsx("span",{className:"text-micro text-muted",children:s})]})}function La({workstream:t,initiative:s}){const{agentEntityMap:r,openModal:n,closeModal:c,authToken:o,embedMode:d,mutations:h}=Dt(),b=r.get(t.id)??r.get(s.id)??[],[j,x]=a.useState(!1),[F,M]=a.useState(""),[N,l]=a.useState(!1),[y,u]=a.useState(!1),[w,k]=a.useState(null),[g,C]=a.useState(t.name),[T,U]=a.useState(t.summary??""),[P,J]=a.useState(t.status),{details:ee,isLoading:te}=ws({initiativeId:s.id,authToken:o,embedMode:d}),q=ls({authToken:o,embedMode:d}),$=a.useMemo(()=>ee.milestones.filter(I=>I.workstreamId===t.id),[ee.milestones,t.id]),v=a.useMemo(()=>new Set($.map(I=>I.id)),[$]),H=a.useMemo(()=>ee.tasks.filter(I=>I.workstreamId===t.id||I.milestoneId!==null&&v.has(I.milestoneId)).sort((I,Q)=>{const oe=gs(I.status)-gs(Q.status);if(oe!==0)return oe;const Ie=I.createdAt?Date.parse(I.createdAt):0;return(Q.createdAt?Date.parse(Q.createdAt):0)-Ie}),[ee.tasks,v,t.id]),S=H.filter(I=>Ze(I.status)).length,W=H.length>0?zt(S,H.length):typeof t.progress=="number"?ks(t.progress<=1?t.progress*100:t.progress):Ze(t.status)?100:null,L=t.status.toLowerCase(),se=h.entityAction.isPending||h.createEntity.isPending||h.updateEntity.isPending||h.deleteEntity.isPending,R=q.isPinning||q.isMoving,X=(I,Q)=>I&&I.trim().length>0?ct(I.trim()):Q,ie=()=>{const I=g.trim();if(!I){k("Workstream name is required.");return}k(null),h.updateEntity.mutate({type:"workstream",id:t.id,title:I,summary:T.trim()||null,status:P},{onSuccess:()=>{l(!1),k("Workstream updated.")},onError:Q=>{k(X(Q instanceof Error?Q.message:"","Failed to update workstream."))}})},de=async I=>{k(null);try{await q.pin({initiativeId:s.id,workstreamId:t.id}),await q.move({initiativeId:s.id,workstreamId:t.id,placement:I}),k(`Queued workstream to ${I==="top"?"top":"end"}.`)}catch(Q){k(X(Q instanceof Error?Q.message:"","Failed to queue workstream."))}};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-caption",children:[e.jsx(Ge,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>n({type:"initiative",entity:s}),className:"break-words text-secondary transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Ge,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-primary",children:t.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{type:"workstream",size:16}),e.jsx("h2",{className:"text-title font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Kn(t.status)}`,children:Oe(t.status)})]}),N?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Name"}),e.jsx("input",{type:"text",value:g,onChange:I=>C(I.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Summary"}),e.jsx("textarea",{value:T,onChange:I=>U(I.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("select",{value:P,onChange:I=>J(I.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:["not_started","planned","active","in_progress","paused","blocked","done"].map(I=>e.jsx("option",{value:I,children:Oe(I)},I))})]})]}):t.summary?e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:t.summary}):e.jsx("p",{className:"text-body text-muted",children:"No summary yet."}),b.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Agents"}),e.jsx(vs,{agents:b,max:6})]}),w&&e.jsx("div",{className:"text-caption text-secondary",children:w})]}),W!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Progress"}),e.jsxs("span",{className:"text-body text-secondary",children:[W,"%"]})]}),e.jsx("div",{className:"h-1.5 w-full rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${W}%`,backgroundColor:Y.lime}})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Tasks"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:H.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Milestones"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:$.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Progress"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:W!==null?`${W}%`:"-"})]})]}),te?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((I,Q)=>e.jsx(yt,{className:"h-12 w-full rounded-lg"},`ws-detail-${Q}`))}):e.jsxs(e.Fragment,{children:[$.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"Milestones"}),$.map(I=>e.jsx("button",{onClick:()=>n({type:"milestone",entity:I,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-body text-bright",children:I.title}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Gn(I.status)}`,children:Oe(I.status)})]})},I.id))]}),H.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:["Tasks (",H.length,")"]}),H.map(I=>e.jsxs("button",{onClick:()=>n({type:"task",entity:I,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-body text-bright",children:I.title}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ks(I.status)}`,children:Oe(I.status)})]}),I.priority&&e.jsxs("span",{className:"text-micro text-muted mt-0.5 block uppercase tracking-wider",children:["Priority: ",I.priority]})]},I.id))]}),e.jsx(Ss,{entityType:"workstream",entityId:t.id,title:"Artifacts (from milestones)",authToken:o,embedMode:d,finalOnly:!0,milestoneIds:$.map(I=>I.id)}),e.jsxs("div",{className:"mt-2 pt-4 border-t border-subtle",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted mb-2",children:"Notes"}),e.jsx(js,{entityType:"workstream",entityId:t.id,authToken:o,embedMode:d,variant:"inline"})]})]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["not_started","planned","todo"].includes(L)&&e.jsx(ne,{label:"Start",color:Y.lime,variant:"primary",onClick:()=>h.entityAction.mutate({type:"workstream",id:t.id,action:"start"}),disabled:se}),["active","in_progress"].includes(L)&&e.jsxs(e.Fragment,{children:[e.jsx(ne,{label:"Complete",color:Y.teal,variant:"primary",onClick:()=>h.entityAction.mutate({type:"workstream",id:t.id,action:"complete"}),disabled:se}),e.jsx(ne,{label:"Pause",color:Y.amber,onClick:()=>h.entityAction.mutate({type:"workstream",id:t.id,action:"pause"}),disabled:se}),e.jsx(ne,{label:"Block",color:Y.red,variant:"destructive",onClick:()=>h.entityAction.mutate({type:"workstream",id:t.id,action:"block"}),disabled:se})]}),["paused","blocked"].includes(L)&&e.jsx(ne,{label:"Resume",color:Y.lime,variant:"primary",onClick:()=>h.entityAction.mutate({type:"workstream",id:t.id,action:"resume"}),disabled:se}),e.jsx(Ns,{label:"Queue",size:"md",busy:R,disabled:se,title:`Queue workstream: ${t.name}`,onSelectPlacement:de}),N?e.jsxs(e.Fragment,{children:[e.jsx(ne,{label:"Save",color:Y.teal,variant:"primary",onClick:ie,disabled:se||!g.trim()}),e.jsx(ne,{label:"Cancel",variant:"ghost",onClick:()=>{l(!1),C(t.name),U(t.summary??""),J(t.status),k(null)},disabled:se})]}):e.jsx(ne,{label:"Edit",variant:"ghost",onClick:()=>{l(!0),k(null)},disabled:se}),e.jsx("div",{className:"flex-1"}),y?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"Delete workstream?"}),e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>h.deleteEntity.mutate({type:"workstream",id:t.id},{onSuccess:()=>c(),onError:I=>k(X(I instanceof Error?I.message:"","Failed to delete workstream."))}),disabled:se}),e.jsx(ne,{label:"Keep",variant:"ghost",onClick:()=>u(!1),disabled:se})]}):e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>u(!0),disabled:se}),j?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:I=>{I.preventDefault(),F.trim()&&h.createEntity.mutate({type:"task",title:F.trim(),workstream_id:t.id,initiative_id:s.id,status:"todo"},{onSuccess:()=>{M(""),x(!1)},onError:Q=>{k(X(Q instanceof Error?Q.message:"","Failed to create task."))}})},children:[e.jsx("input",{type:"text",value:F,onChange:I=>M(I.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-body bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-primary placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(ne,{label:"Add",color:Y.lime,type:"submit",size:"sm",disabled:!F.trim()||h.createEntity.isPending}),e.jsx(ne,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{x(!1),M("")}})]}):e.jsx(ne,{label:"+ Task",variant:"ghost",onClick:()=>x(!0),disabled:se})]})})]})}function Pa({milestone:t,initiative:s}){const{openModal:r,closeModal:n,authToken:c,embedMode:o,mutations:d}=Dt(),[h,b]=a.useState(!1),[j,x]=a.useState(!1),[F,M]=a.useState(!1),[N,l]=a.useState(""),[y,u]=a.useState(null),[w,k]=a.useState(t.title),[g,C]=a.useState(t.description??""),[T,U]=a.useState(En(t.dueDate)),[P,J]=a.useState(t.status),{details:ee}=ws({initiativeId:s.id,authToken:c,embedMode:o}),te=ee.tasks.filter(L=>L.milestoneId===t.id),q=t.status.toLowerCase()==="done"||t.status.toLowerCase()==="completed",$=te.filter(L=>Ze(L.status)).length,v=te.length>0?zt($,te.length):q?100:0,H=d.entityAction.isPending||d.createEntity.isPending||d.updateEntity.isPending||d.deleteEntity.isPending,S=(L,se)=>L&&L.trim().length>0?ct(L.trim()):se,W=()=>{const L=w.trim();if(!L){u("Milestone title is required.");return}u(null),d.updateEntity.mutate({type:"milestone",id:t.id,title:L,description:g.trim()||null,due_date:T||null,status:P},{onSuccess:()=>{b(!1),u("Milestone updated.")},onError:se=>{u(S(se instanceof Error?se.message:"","Failed to update milestone."))}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-caption",children:[e.jsx(Ge,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>r({type:"initiative",entity:s}),className:"break-words text-secondary transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Ge,{type:"milestone",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-primary",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ge,{type:"milestone",size:16}),e.jsx("h2",{className:"text-title font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Gn(t.status)}`,children:Oe(t.status)})]}),h?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Title"}),e.jsx("input",{type:"text",value:w,onChange:L=>k(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Description"}),e.jsx("textarea",{value:g,onChange:L=>C(L.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due date"}),e.jsx("input",{type:"date",value:T,onChange:L=>U(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("select",{value:P,onChange:L=>J(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:["planned","active","in_progress","at_risk","blocked","done"].map(L=>e.jsx("option",{value:L,children:Oe(L)},L))})]})]})]}):t.description?e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:t.description}):e.jsx("p",{className:"text-body text-muted",children:"No description yet."}),y&&e.jsx("div",{className:"text-caption text-secondary",children:y})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[t.dueDate&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due Date"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:new Date(t.dueDate).toLocaleDateString()})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Associated Tasks"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:te.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Completion"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-1.5 flex-1 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${v}%`,backgroundColor:Y.teal}})}),e.jsxs("div",{className:"text-body text-primary",style:{fontVariantNumeric:"tabular-nums"},children:[v,"%"]})]}),e.jsxs("div",{className:"mt-1 text-micro text-muted",children:[$,"/",te.length," done"]})]})]}),te.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"Tasks"}),te.map(L=>e.jsx("button",{onClick:()=>r({type:"task",entity:L,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-body text-bright",children:L.title}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ks(L.status)}`,children:Oe(L.status)})]})},L.id))]}),e.jsx(Ss,{entityType:"milestone",entityId:t.id,authToken:c,embedMode:o}),e.jsxs("div",{className:"mt-2 pt-4 border-t border-subtle",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted mb-2",children:"Notes"}),e.jsx(js,{entityType:"milestone",entityId:t.id,authToken:c,embedMode:o,variant:"inline"})]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!q&&t.status.toLowerCase()==="planned"&&e.jsx(ne,{label:"Start",color:Y.lime,variant:"primary",onClick:()=>d.entityAction.mutate({type:"milestone",id:t.id,action:"start"}),disabled:H}),!q&&(t.status.toLowerCase()==="in_progress"||t.status.toLowerCase()==="at_risk")&&e.jsx(ne,{label:te.length>0&&!te.every(L=>Ze(L.status))?"Complete (force)":"Complete",color:Y.teal,variant:"primary",onClick:()=>{const L=te.length===0||te.every(se=>Ze(se.status));d.entityAction.mutate({type:"milestone",id:t.id,action:"complete",force:!L})},disabled:H}),h?e.jsxs(e.Fragment,{children:[e.jsx(ne,{label:"Save",color:Y.teal,variant:"primary",onClick:W,disabled:H||!w.trim()}),e.jsx(ne,{label:"Cancel",variant:"ghost",onClick:()=>{b(!1),k(t.title),C(t.description??""),U(En(t.dueDate)),J(t.status),u(null)},disabled:H})]}):e.jsx(ne,{label:"Edit",variant:"ghost",onClick:()=>{b(!0),u(null)},disabled:H}),e.jsx("div",{className:"flex-1"}),j?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"Delete milestone?"}),e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>d.deleteEntity.mutate({type:"milestone",id:t.id},{onSuccess:()=>n(),onError:L=>u(S(L instanceof Error?L.message:"","Failed to delete milestone."))}),disabled:H}),e.jsx(ne,{label:"Keep",variant:"ghost",onClick:()=>x(!1),disabled:H})]}):e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>x(!0),disabled:H}),F?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:L=>{L.preventDefault(),N.trim()&&d.createEntity.mutate({type:"task",title:N.trim(),milestone_id:t.id,workstream_id:t.workstreamId??void 0,initiative_id:s.id,status:"todo"},{onSuccess:()=>{l(""),M(!1)},onError:se=>{u(S(se instanceof Error?se.message:"","Failed to create task."))}})},children:[e.jsx("input",{type:"text",value:N,onChange:L=>l(L.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-body bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-primary placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(ne,{label:"Add",color:Y.lime,type:"submit",size:"sm",disabled:!N.trim()||d.createEntity.isPending}),e.jsx(ne,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{M(!1),l("")}})]}):e.jsx(ne,{label:"+ Task",variant:"ghost",onClick:()=>M(!0),disabled:H})]})})]})}function En(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function Ra({task:t,initiative:s}){const{agentEntityMap:r,openModal:n,mutations:c,closeModal:o,authToken:d,embedMode:h}=Dt(),b=r.get(t.id)??r.get(s.id)??[],[j,x]=a.useState(!1),[F,M]=a.useState(!1),[N,l]=a.useState(null),[y,u]=a.useState(t.title),[w,k]=a.useState(t.description??""),[g,C]=a.useState(t.priority??""),[T,U]=a.useState(An(t.dueDate)),[P,J]=a.useState(t.status),ee=t.status.toLowerCase(),te=(S,W)=>S&&S.trim().length>0?ct(S.trim()):W,q=c.entityAction.isPending||c.updateEntity.isPending||c.deleteEntity.isPending,$=S=>{l(null),c.entityAction.mutate({type:"task",id:t.id,action:S},{onError:W=>{l(te(W instanceof Error?W.message:"","Task action failed."))}})},v=()=>{const S=y.trim();if(!S){l("Task title is required.");return}l(null),c.updateEntity.mutate({type:"task",id:t.id,title:S,description:w.trim()||null,priority:g.trim()||null,due_date:T||null,status:P},{onSuccess:()=>{M(!1),l("Task updated.")},onError:W=>{l(te(W instanceof Error?W.message:"","Failed to update task."))}})},H=()=>{l(null),c.deleteEntity.mutate({type:"task",id:t.id},{onSuccess:()=>o(),onError:S=>{l(te(S instanceof Error?S.message:"","Failed to delete task."))}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-caption",children:[e.jsx(Ge,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>n({type:"initiative",entity:s}),className:"break-words text-secondary transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Ge,{type:"task",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-primary",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(Ge,{type:"task",size:16}),e.jsx("h2",{className:"break-words text-title font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ks(t.status)}`,children:Oe(t.status)})]}),F?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Title"}),e.jsx("input",{type:"text",value:y,onChange:S=>u(S.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Description"}),e.jsx("textarea",{value:w,onChange:S=>k(S.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Priority"}),e.jsx("input",{type:"text",value:g,onChange:S=>C(S.target.value),placeholder:"p1, high, p50",className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due date"}),e.jsx("input",{type:"date",value:T,onChange:S=>U(S.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("select",{value:P,onChange:S=>J(S.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:["not_started","planned","todo","in_progress","active","blocked","done"].map(S=>e.jsx("option",{value:S,children:Oe(S)},S))})]})]})]}):t.description?e.jsx(Dr,{text:t.description,mode:"block",className:"text-body text-secondary leading-relaxed"}):e.jsx("p",{className:"text-body text-muted",children:"No description yet."}),b.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Agents"}),e.jsx(vs,{agents:b,max:4})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:Oe(t.status)})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Priority"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:t.priority??"-"})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due Date"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:t.dueDate?new Date(t.dueDate).toLocaleDateString():"-"})]})]}),N&&e.jsx("div",{className:"text-caption px-1",style:{color:`${Y.red}b3`},children:N}),e.jsx(Ss,{entityType:"task",entityId:t.id,authToken:d,embedMode:h}),e.jsxs("div",{className:"mt-4 pt-4 border-t border-subtle",children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted mb-2",children:"Notes"}),e.jsx(js,{entityType:"task",entityId:t.id,authToken:d,embedMode:h,variant:"inline"})]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[ee==="todo"&&e.jsx(ne,{label:"Start",color:Y.lime,variant:"primary",onClick:()=>$("start"),disabled:q}),(ee==="in_progress"||ee==="active")&&e.jsx(ne,{label:"Complete",color:Y.teal,variant:"primary",onClick:()=>$("complete"),disabled:q}),(ee==="todo"||ee==="in_progress"||ee==="active")&&e.jsx(ne,{label:"Block",color:Y.red,variant:"destructive",onClick:()=>$("block"),disabled:q}),ee==="blocked"&&e.jsx(ne,{label:"Unblock",color:Y.amber,onClick:()=>$("unblock"),disabled:q}),F?e.jsxs(e.Fragment,{children:[e.jsx(ne,{label:"Save",color:Y.teal,variant:"primary",onClick:v,disabled:q||!y.trim()}),e.jsx(ne,{label:"Cancel",variant:"ghost",onClick:()=>{M(!1),l(null),u(t.title),k(t.description??""),C(t.priority??""),U(An(t.dueDate)),J(t.status)},disabled:q})]}):e.jsx(ne,{label:"Edit",variant:"ghost",onClick:()=>{M(!0),l(null)},disabled:q}),e.jsx("div",{className:"flex-1"}),j?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption",style:{color:`${Y.red}b3`},children:"Delete?"}),e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:H,disabled:q}),e.jsx(ne,{label:"Keep",variant:"ghost",onClick:()=>x(!1),disabled:q})]}):e.jsx(ne,{label:"Delete",color:Y.red,variant:"destructive",onClick:()=>x(!0),disabled:q})]})})]})}function An(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function qa(t){const s=[];return t.type!=="initiative"&&t.initiative&&s.push(t.initiative.name),t.type==="initiative"||t.type==="workstream"?s.push(t.entity.name):(t.type==="milestone"||t.type==="task")&&s.push(t.entity.title),s}function Oa({target:t,onClose:s}){return e.jsx(Mr,{open:t!==null,onClose:s,maxWidth:"max-w-5xl",children:t&&e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-body text-secondary",children:[qa(t).map((r,n,c)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[n>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:`truncate ${n===c.length-1?"text-primary font-medium":""}`,children:r})]},n)),e.jsxs("span",{className:"ml-1 inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.06em] text-secondary",children:[e.jsx(Ge,{type:t.type,size:11,className:"opacity-90"}),t.type]})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[t.type==="initiative"&&e.jsx(Ta,{initiative:t.entity}),t.type==="workstream"&&e.jsx(La,{workstream:t.entity,initiative:t.initiative}),t.type==="milestone"&&e.jsx(Pa,{milestone:t.entity,initiative:t.initiative}),t.type==="task"&&e.jsx(Ra,{task:t.entity,initiative:t.initiative})]})]})})}function In(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function za(t){return t.split("_").map(s=>s.slice(0,1).toUpperCase()+s.slice(1)).join(" ")}const Us=["active","in_progress","not_started","planned","blocked","at_risk","paused","completed","done","backlog","todo","pending","draft"],Ua=[{value:"target",label:"Target date"},{value:"created",label:"Created at"},{value:"updated",label:"Updated at"}],Wa=[{value:"any",label:"Any time"},{value:"missing",label:"No target date"},{value:"overdue",label:"Overdue"},{value:"today",label:"Today"},{value:"next_7_days",label:"Next 7 days"},{value:"next_30_days",label:"Next 30 days"},{value:"custom_range",label:"Custom range"}],Qa=[{value:"any",label:"Any time"},{value:"missing",label:"No timestamp"},{value:"today",label:"Today"},{value:"past_7_days",label:"Past 7 days"},{value:"past_30_days",label:"Past 30 days"},{value:"custom_range",label:"Custom range"}];function Ha({initiatives:t,visibleCount:s}){const{statusFilters:r,dateField:n,datePreset:c,dateStart:o,dateEnd:d,activeFilterCount:h,groupBy:b,setGroupBy:j,sortBy:x,setSortBy:F,setStatusFilters:M,toggleStatusFilter:N,setDateField:l,setDatePreset:y,setDateStart:u,setDateEnd:w,clearFilters:k}=Dt(),[g,C]=a.useState(!1),[T,U]=a.useState(!1),P=a.useRef(null);a.useEffect(()=>{if(!g)return;const R=ie=>{var I;const de=ie.target;de&&((I=P.current)!=null&&I.contains(de)||C(!1))},X=ie=>{ie.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",R),document.addEventListener("keydown",X),()=>{document.removeEventListener("mousedown",R),document.removeEventListener("keydown",X)}},[g]);const J=a.useMemo(()=>{const R=new Map;for(const ie of t){const de=new Set([In(ie.status),In(ie.rawStatus)]);for(const I of de)I&&R.set(I,(R.get(I)??0)+1)}for(const ie of Us)R.has(ie)||R.set(ie,0);return Array.from(R.entries()).sort((ie,de)=>{const I=Us.indexOf(ie[0]),Q=Us.indexOf(de[0]);return I>=0&&Q>=0?I-Q:I>=0?-1:Q>=0?1:ie[0].localeCompare(de[0])}).map(([ie,de])=>({key:ie,count:de}))},[t]),ee=r.length,te=a.useMemo(()=>J.filter(R=>T||R.count>0||r.includes(R.key)),[T,r,J]),q=J.length-te.length,$=a.useMemo(()=>n==="target"?Wa:Qa,[n]);a.useEffect(()=>{$.some(R=>R.value===c)||y("any")},[c,$,y]);const v=[{value:"none",label:"None"},{value:"status",label:"Status"},{value:"date",label:"Date"},{value:"category",label:"Category"}],H=[{value:"default",label:"Default"},{value:"date_asc",label:"Date (earliest)"},{value:"date_desc",label:"Date (latest)"},{value:"priority_high",label:"Priority (high first)"},{value:"priority_low",label:"Priority (low first)"}],S=b!=="status"||x!=="default",W=h>0,L=h,se=W||S;return e.jsxs("div",{ref:P,className:"relative flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{C(R=>{const X=!R;return X||U(!1),X})},"data-state":g||L>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3 text-caption font-semibold",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),L>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-micro leading-4",children:L})]}),s<t.length&&e.jsxs("span",{className:"text-micro text-muted whitespace-nowrap",children:[s,"/",t.length]}),e.jsx(pt,{initial:!1,children:W&&e.jsx(ge.button,{type:"button",onClick:k,initial:{opacity:0,x:-4},animate:{opacity:1,x:0},exit:{opacity:0,x:-4},transition:{duration:.15,ease:[.22,1,.36,1]},className:"text-micro text-muted transition-colors whitespace-nowrap hover:text-primary",children:"Clear"})}),e.jsx(pt,{children:g&&e.jsxs(ge.div,{initial:{opacity:0,y:-4,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.97},transition:{duration:.16,ease:[.22,1,.36,1]},className:"surface-tier-2 fixed left-3 right-3 top-[calc(env(safe-area-inset-top)+72px)] z-[340] max-h-[calc(100dvh-104px)] overflow-y-auto overscroll-contain rounded-xl p-3.5 shadow-[0_16px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl sm:absolute sm:left-auto sm:right-0 sm:top-12 sm:z-30 sm:w-[360px] sm:max-w-[94vw] sm:max-h-[min(78vh,680px)]",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-2",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("div",{className:"text-caption font-semibold tracking-[0.01em] text-bright",children:"Filters"}),e.jsx("div",{className:"text-micro text-secondary",children:"Scope the Mission Control list view"})]}),W?e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro text-primary",children:[L," active"]}):S?e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro text-secondary",children:"view modified"}):null]}),e.jsxs("div",{className:"subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Layout"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Group"}),e.jsx("select",{value:b,onChange:R=>j(R.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-caption text-primary focus:border-[#BFFF00]/40 focus:outline-none",children:v.map(R=>e.jsx("option",{value:R.value,children:R.label},R.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Sort"}),e.jsx("select",{value:x,onChange:R=>F(R.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-caption text-primary focus:border-[#BFFF00]/40 focus:outline-none",children:H.map(R=>e.jsx("option",{value:R.value,children:R.label},R.value))})]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[e.jsx("div",{className:"section-kicker",children:"Status"}),q>0&&e.jsx("button",{type:"button",onClick:()=>U(R=>!R),className:"text-micro text-muted transition-colors hover:text-white/72",children:T?"Hide empty":`Show empty (${q})`})]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-auto pr-1",children:te.map(R=>{const X=r.includes(R.key);return e.jsxs("label",{className:`flex cursor-pointer items-center justify-between rounded-md border px-2.5 py-1.5 text-caption transition-colors ${X?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-bright":"border-white/[0.08] bg-white/[0.02] text-primary hover:border-white/[0.15]"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:X,onChange:()=>N(R.key),className:"h-3.5 w-3.5 accent-[#BFFF00]"}),e.jsx("span",{children:za(R.key)})]}),e.jsx("span",{className:"text-micro text-secondary",children:R.count})]},R.key)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>M([]),className:`text-micro uppercase tracking-[0.08em] ${ee>0?"text-primary hover:text-white":"text-muted"}`,disabled:ee===0,children:"Clear status"}),e.jsxs("div",{className:"text-micro text-secondary",children:[ee," selected"]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Date"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Field"}),e.jsx("select",{value:n,onChange:R=>l(R.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none",children:Ua.map(R=>e.jsx("option",{value:R.value,children:R.label},R.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Condition"}),e.jsx("select",{value:c,onChange:R=>y(R.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none",children:$.map(R=>e.jsx("option",{value:R.value,children:R.label},R.value))})]})]}),c==="custom_range"&&e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Start"}),e.jsx("input",{type:"date",value:o,onChange:R=>u(R.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"End"}),e.jsx("input",{type:"date",value:d,onChange:R=>w(R.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none"})]})]})]}),se&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 section-divider"}),e.jsxs("div",{className:"mt-2 flex flex-wrap justify-end gap-2",children:[S&&e.jsx("button",{type:"button",onClick:()=>{j("status"),F("default")},className:"text-micro uppercase tracking-[0.09em] text-secondary transition-colors hover:text-bright",children:"Reset layout"}),W&&e.jsx("button",{type:"button",onClick:k,className:"text-micro uppercase tracking-[0.09em] text-secondary transition-colors hover:text-bright",children:"Clear filters"})]})]})]})})]})}function bt(t){return!t||typeof t!="object"||Array.isArray(t)?null:t}function ce(t){if(typeof t!="string")return null;const s=t.trim();return s.length>0?s:null}function ve(t){if(typeof t=="number"&&Number.isFinite(t))return t;if(typeof t=="string"&&t.trim().length>0){const s=Number(t);if(Number.isFinite(s))return s}return null}function Va(t){const s=(ce(t)??"").toLowerCase();return s==="assigned"||s==="inferred"||s==="fallback"?s:null}function is(t){const s=ce(t);if(!s)return null;const r=s.toLowerCase();return r==="undefined"||r==="null"||r==="main"||r==="unassigned"?null:s}function er(t){return is(t)}function Ka(t,s,r){if(!Array.isArray(t)){if(s||r){const o=s??r??"",d=r??s??"";if(o.trim().length>0&&d.trim().length>0)return[{id:o,name:d}]}return[]}const n=[],c=new Set;for(const o of t){const d=bt(o);if(!d)continue;const h=er(d.id)??is(d.name),b=is(d.name)??h;if(!h||!b)continue;const j=h.toLowerCase();c.has(j)||(c.add(j),n.push({id:h,name:b}))}if(n.length===0&&(s||r)){const o=s??r??"",d=r??s??"";if(o.trim().length>0&&d.trim().length>0)return[{id:o,name:d}]}return n}function Qs(t,s){const r=(ce(t)??"").toLowerCase();return r==="initiative"?"initiative":r==="milestone"?"milestone":r==="task"?"task":r==="workstream"?"workstream":s}function Ga(t){return(ce(t)??"").toLowerCase()==="algorithmic"?"algorithmic":"manual"}function Rt(t){return Array.isArray(t)?t.map(s=>ce(s)).filter(s=>!!s):[]}function Ja(t,s,r){const n=bt(t);if(!n)return null;const c=ce(n.sliceId)??ce(n.id);if(!c)return null;const o=Qs(n.level??n.scope,s),d=ce(n.title)??ce(n.workstreamTitle)??ce(n.milestoneTitle)??ce(n.taskTitle)??ce(n.initiativeTitle)??c,h=bt(n.order),b=bt(n.dispatch),j=bt(n.objectiveSnapshot??n.objective??n.ranking),x=bt(n.factors),F=bt(n.iwmt),M=bt(n.lineage),N=er(n.runnerAgentId??n.agentId),l=is(n.runnerAgentName??n.agentName)??is(n.runner),y=Ka(n.runnerAgents,N,l??N),u=y[0]??null;return{sliceId:c,level:o,title:d,initiativeId:ce(n.initiativeId),initiativeTitle:ce(n.initiativeTitle),workstreamId:ce(n.workstreamId),workstreamTitle:ce(n.workstreamTitle),milestoneId:ce(n.milestoneId),milestoneTitle:ce(n.milestoneTitle),taskId:ce(n.taskId),taskTitle:ce(n.taskTitle),status:ce(n.status)??ce(n.queueState)??(b&&b.runnable===!1?"blocked":"queued"),priorityNum:ve(n.priorityNum??n.nextTaskPriority),dueAt:ce(n.dueAt??n.nextTaskDueAt),dependencyState:ce(n.dependencyState),objectiveScore:ve(n.objectiveScore)??ve(j==null?void 0:j.objectiveScore)??ve(n.mixScore),roiPerToken:ve(n.roiPerToken)??ve(j==null?void 0:j.roiPerToken),expectedTokens:ve(n.expectedTokens)??ve(j==null?void 0:j.expectedTokens),expectedValueUsd:ve(n.expectedValueUsd)??ve(j==null?void 0:j.expectedValueUsd),goalAlignment:ve(n.goalAlignment)??ve(x==null?void 0:x.goalAlignment),riskPenalty:ve(n.riskPenalty)??ve(x==null?void 0:x.riskPenalty),runnable:typeof(b==null?void 0:b.runnable)=="boolean"?b.runnable:void 0,blockReason:ce((b==null?void 0:b.blockReason)??n.blockReason),suggestedScope:b&&b.suggestedScope?Qs(b.suggestedScope,o):null,manualRank:ve(n.manualRank)??ve(h==null?void 0:h.manualRank),algorithmRank:ve(n.algorithmRank)??ve(h==null?void 0:h.algorithmRank)??r,finalRank:ve(n.finalRank)??ve(h==null?void 0:h.finalRank)??r,iwmt:F?{laneId:ce(F.laneId),mixScore:ve(F.mixScore),factors:Array.isArray(F.factors)?F.factors.map(w=>{const k=bt(w);return k?{key:ce(k.key)??void 0,label:ce(k.label)??ce(k.key)??void 0,value:ve(k.value)??void 0,weight:ve(k.weight)??void 0}:null}).filter(w=>!!w):void 0}:null,lineage:M?{initiativeIds:Rt(M.initiativeIds),workstreamIds:Rt(M.workstreamIds),milestoneIds:Rt(M.milestoneIds),taskIds:Rt(M.taskIds),iwmtIds:Rt(M.iwmtIds)}:null,sourceWorkstreamIds:Rt(n.sourceWorkstreamIds),queueState:ce(n.queueState),sliceTaskIds:Rt(n.sliceTaskIds),sliceTaskCount:ve(n.sliceTaskCount),sliceMilestoneId:ce(n.sliceMilestoneId),runnerAgentId:(u==null?void 0:u.id)??N,runnerAgentName:(u==null?void 0:u.name)??l,runnerAgents:y,runnerSource:Va(n.runnerSource)??((u==null?void 0:u.id)??N?"inferred":"fallback"),updatedAt:ce(n.updatedAt)}}function Ya(t,s,r,n){return{ok:!0,generatedAt:new Date().toISOString(),level:t,orderMode:s,mixPolicy:"iwmt_v1",total:0,items:[],degraded:["Demo mode: slice explorer uses fixture data only."],source:"local",pagination:{offset:r,limit:n,total:0,nextCursor:null,hasMore:!1}}}function Xa(t){const s=t.offset+t.limit,r=s<t.total;return{offset:t.offset,limit:t.limit,total:t.total,nextCursor:r?String(s):null,hasMore:r}}function Za({workspaceId:t=null,initiativeId:s=null,level:r,orderMode:n=null,includeCompleted:c=!1,search:o="",offset:d=0,limit:h=24,authToken:b=null,embedMode:j=!1,enabled:x=!0}){var k,g,C,T,U,P,J,ee,te;const F=os(),M=Math.max(0,d),N=Math.max(1,Math.min(300,h)),l=o.trim(),y=a.useMemo(()=>Ot.missionControlSlices({workspaceId:t,initiativeId:s,level:r,orderMode:n,includeCompleted:c,search:l,offset:M,limit:N,authToken:b,embedMode:j}),[b,j,c,s,r,N,M,l,n,t]),u=Zt({queryKey:y,enabled:x,queryFn:async()=>{if(F)return Ya(r,n??"manual",M,N);const q=new URLSearchParams;gn(q,t,{allTokenWhenMissing:!0}),s&&q.set("initiative_id",s),q.set("level",r),q.set("include_completed",c?"1":"0"),q.set("offset",String(M)),q.set("limit",String(N)),q.set("mix_policy","iwmt_v1"),n&&q.set("order_mode",n),l.length>0&&q.set("q",l);const $=await fetch(`/orgx/api/mission-control/slices?${q.toString()}`,{headers:xt({authToken:b,embedMode:j})}),v=await $.json().catch(()=>null);if(!$.ok){const X=v&&typeof v.error=="string"&&v.error||v&&typeof v.message=="string"&&v.message||`Failed to fetch mission-control slices (${$.status})`;throw new Error(X)}const H=Array.isArray(v==null?void 0:v.items)?v.items:[],S=Qs((v==null?void 0:v.level)??(v==null?void 0:v.scope),r),W=H.map((X,ie)=>Ja(X,S,ie+1)).filter(X=>!!X),L=bt(v==null?void 0:v.pagination),se=ve(v==null?void 0:v.total)??ve(L==null?void 0:L.total)??W.length,R=L?{offset:ve(L.offset)??M,limit:ve(L.limit)??N,total:se,nextCursor:ce(L.nextCursor),hasMore:typeof L.hasMore=="boolean"?L.hasMore:!1}:Xa({offset:M,limit:N,total:se});return{ok:!0,generatedAt:ce(v==null?void 0:v.generatedAt)??new Date().toISOString(),workspaceId:ce((v==null?void 0:v.workspaceId)??(v==null?void 0:v.workspace_id)),initiativeId:ce((v==null?void 0:v.initiativeId)??(v==null?void 0:v.initiative_id)??s),level:S,mixPolicy:ce((v==null?void 0:v.mixPolicy)??(v==null?void 0:v.mix_policy))??"iwmt_v1",orderMode:Ga((v==null?void 0:v.orderMode)??(v==null?void 0:v.order_mode)??(v==null?void 0:v.order)),total:se,items:W,degraded:Array.isArray(v==null?void 0:v.degraded)?v.degraded.map(X=>ce(X)).filter(X=>!!X):void 0,source:ce(v==null?void 0:v.source)==="canonical"?"canonical":ce(v==null?void 0:v.source)==="local_fallback"?"local_fallback":"local",pagination:R}}}),w=a.useRef(null);return a.useEffect(()=>{var H;const q=(H=u.data)==null?void 0:H.pagination;if(!x||!(q!=null&&q.hasMore)||!q.nextCursor||w.current===q.nextCursor)return;const $=Number.parseInt(q.nextCursor,10);if(!Number.isFinite($))return;w.current=q.nextCursor;const v=new URLSearchParams;gn(v,t,{allTokenWhenMissing:!0}),s&&v.set("initiative_id",s),v.set("level",r),v.set("include_completed",c?"1":"0"),v.set("offset",String($)),v.set("limit",String(N)),v.set("mix_policy","iwmt_v1"),n&&v.set("order_mode",n),l.length>0&&v.set("q",l),fetch(`/orgx/api/mission-control/slices?${v.toString()}`,{headers:xt({authToken:b,embedMode:j})}).catch(()=>{})},[x,(g=(k=u.data)==null?void 0:k.pagination)==null?void 0:g.hasMore,(T=(C=u.data)==null?void 0:C.pagination)==null?void 0:T.nextCursor,t,s,r,n,c,l,N,b,j]),{...u,slices:((U=u.data)==null?void 0:U.items)??[],orderMode:((P=u.data)==null?void 0:P.orderMode)??n??"manual",degraded:((J=u.data)==null?void 0:J.degraded)??[],source:((ee=u.data)==null?void 0:ee.source)??null,pagination:((te=u.data)==null?void 0:te.pagination)??null}}function Dn(t,s){if(!s||s.trim().length===0)return;const r=s.trim();t.workspace_id=r}async function Mn(t){const s=await t.json().catch(()=>null);if(!t.ok){const r=s&&typeof s.error=="string"&&s.error||s&&typeof s.message=="string"&&s.message||`Request failed (${t.status})`;throw new Error(r)}return s??{}}function ei({workspaceId:t=null,initiativeId:s=null,level:r,authToken:n=null,embedMode:c=!1}){const o=Vs(),d=Nt({mutationFn:async b=>{const j={level:r,order:b.map(F=>({sliceId:F}))};Dn(j,t),s&&(j.initiative_id=s);const x=await fetch("/orgx/api/mission-control/slices/reorder",{method:"POST",headers:xt({authToken:n,embedMode:c,contentTypeJson:!0,workspaceId:t}),body:JSON.stringify(j)});return Mn(x)},onMutate:async b=>{const j=o.getQueriesData({queryKey:["mission-control-slices"]});for(const[x,F]of j){if(!F||F.level!==r||s&&F.initiativeId&&F.initiativeId!==s)continue;const M=new Map(F.items.map(y=>[y.sliceId,y])),N=b.map(y=>M.get(y)??null).filter(y=>!!y);if(N.length===0)continue;const l=new Set(N.map(y=>y.sliceId));for(const y of F.items)l.has(y.sliceId)||N.push(y);o.setQueryData(x,{...F,items:N.map((y,u)=>({...y,manualRank:u+1,finalRank:u+1})),orderMode:"manual"})}return{snapshots:j}},onError:(b,j,x)=>{for(const[F,M]of(x==null?void 0:x.snapshots)??[])o.setQueryData(F,M)},onSettled:()=>{o.invalidateQueries({queryKey:["mission-control-slices"]})}}),h=Nt({mutationFn:async b=>{const j={level:r,order_mode:b};Dn(j,t),s&&(j.initiative_id=s);const x=await fetch("/orgx/api/mission-control/slices/order-mode",{method:"POST",headers:xt({authToken:n,embedMode:c,contentTypeJson:!0,workspaceId:t}),body:JSON.stringify(j)});return Mn(x)},onMutate:async b=>{const j=o.getQueriesData({queryKey:["mission-control-slices"]});for(const[x,F]of j)!F||F.level!==r||s&&F.initiativeId&&F.initiativeId!==s||o.setQueryData(x,{...F,orderMode:b});return{snapshots:j}},onError:(b,j,x)=>{for(const[F,M]of(x==null?void 0:x.snapshots)??[])o.setQueryData(F,M)},onSettled:()=>{o.invalidateQueries({queryKey:["mission-control-slices"]})}});return{reorder:d.mutateAsync,setOrderMode:h.mutateAsync,isReordering:d.isPending,isSettingOrderMode:h.isPending,error:(d.error instanceof Error?d.error.message:null)??(h.error instanceof Error?h.error.message:null)}}const Ys=[{value:"initiative",label:"Initiative"},{value:"workstream",label:"Workstream"},{value:"milestone",label:"Milestone"},{value:"task",label:"Task"}],ti=Ys.filter(t=>t.value!=="task");function $n(t){var s;return((s=Ys.find(r=>r.value===t))==null?void 0:s.label)??"Workstream"}function Tn(t){const s=t.trim().toLowerCase();return s==="running"||s==="active"||s==="in_progress"?"border-teal-300/28 bg-teal-400/[0.09] text-teal-100/90":s==="blocked"||s==="failed"||s==="error"?"border-red-400/26 bg-red-500/[0.08] text-red-100/90":s==="completed"||s==="done"||s==="resolved"?"border-strong bg-white/[0.05] text-secondary":"border-[#BFFF00]/24 bg-[#BFFF00]/[0.08] text-[#E8FFD0]/92"}function _n(t){const s=t.trim().toLowerCase();return s==="running"||s==="active"||s==="in_progress"?"from-teal-300/0 via-teal-300/65 to-teal-300/0":s==="blocked"||s==="failed"||s==="error"?"from-red-300/0 via-red-300/65 to-red-300/0":s==="completed"||s==="done"||s==="resolved"?"from-white/0 via-white/45 to-white/0":"from-[#BFFF00]/0 via-[#BFFF00]/70 to-[#BFFF00]/0"}function Yt(t,s=2){return typeof t!="number"||!Number.isFinite(t)?"—":t.toFixed(s)}function as(t,s){if(!t)return s;const r=t.trim();return r?Gs(r)?`${s} ${Jn(r)}`:r:s}function Bn(t){var r,n,c,o;const s=t.title.trim()||((r=t.taskTitle)==null?void 0:r.trim())||((n=t.milestoneTitle)==null?void 0:n.trim())||((c=t.workstreamTitle)==null?void 0:c.trim())||((o=t.initiativeTitle)==null?void 0:o.trim())||"";return s&&!Gs(s)?es(s):t.level==="task"?as(t.taskId??t.sliceId,"Task"):t.level==="milestone"?as(t.milestoneId??t.sliceId,"Milestone"):t.level==="initiative"?as(t.initiativeId??t.sliceId,"Initiative"):as(t.workstreamId??t.sliceId,"Workstream")}function Ln(t){const s=[t.initiativeTitle,t.workstreamTitle,t.milestoneTitle,t.taskTitle].filter(n=>!!(n&&n.trim().length>0));return s.length===0?es(as(t.sliceId,"Slice")):s.map(n=>es(n)).filter(n=>n.length>0).join(" / ")}function Pn(t){var c,o;const s=((c=t.runnerAgentName)==null?void 0:c.trim())??"",r=((o=t.runnerAgentId)==null?void 0:o.trim().toLowerCase())??"";if(!s)return r&&r!=="main"?es(r):"Unassigned";const n=s.toLowerCase();return n==="undefined"||n==="null"||n==="main"&&(r==="main"||t.runnerSource==="fallback")?"Unassigned":es(s)}function Rn(t){const s=typeof t.sliceTaskCount=="number"&&Number.isFinite(t.sliceTaskCount)?Math.max(0,Math.floor(t.sliceTaskCount)):0;return s<=0?"No task":s===1?"1 task":`${s} tasks`}function qn(t,s){return!t||t.trim().length===0?s:ct(t.trim())||s}function On({workspaceId:t=null,initiativeId:s=null,authToken:r=null,embedMode:n=!1,className:c="",title:o="Slice Explorer",compact:d=!1,onOpenInitiative:h}){var ze;const[b,j]=a.useState("workstream"),[x,F]=a.useState(""),[M,N]=a.useState(0),[l]=a.useState(d?18:28),[y,u]=a.useState(null),[w,k]=a.useState([]),[g,C]=a.useState(!1),[T,U]=a.useState(null),[P,J]=a.useState(!1),ee=a.useRef(null),te=f=>{j(f),N(0)},q=Za({workspaceId:t,initiativeId:s,level:b,orderMode:T,includeCompleted:!1,search:x,offset:M,limit:l,authToken:r,embedMode:n,enabled:!!(t||s)}),$=ei({workspaceId:t,initiativeId:s,level:b,authToken:r,embedMode:n}),v=q.slices,H=q.source,S=q.pagination,W=q.orderMode??"manual",L=(S==null?void 0:S.offset)??M,se=(S==null?void 0:S.total)??((ze=q.data)==null?void 0:ze.total)??v.length,R=v.length===0?0:L+1,X=v.length===0?0:L+v.length;a.useEffect(()=>{if(!y)return;const f=window.setTimeout(()=>u(null),5e3);return()=>window.clearTimeout(f)},[y]),a.useEffect(()=>{if(!P)return;const f=V=>{var Ce;const pe=V.target;pe&&((Ce=ee.current)!=null&&Ce.contains(pe)||J(!1))},re=V=>{V.key==="Escape"&&J(!1)};return document.addEventListener("mousedown",f),document.addEventListener("touchstart",f),document.addEventListener("keydown",re),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("touchstart",f),document.removeEventListener("keydown",re)}},[P]),a.useEffect(()=>{N(0)},[b,x]);const ie=a.useMemo(()=>v.map(f=>f.sliceId).join("|"),[v]);a.useEffect(()=>{k(v.map(f=>f.sliceId)),C(!1)},[ie,W]);const de=a.useMemo(()=>new Map(v.map(f=>[f.sliceId,f])),[v]),I=a.useMemo(()=>{if(!g||w.length!==v.length)return v;const f=w.map(re=>de.get(re)??null).filter(re=>!!re);return f.length!==v.length?v:f},[g,w,v,de]),Q=W==="manual"&&v.length>1&&!$.isReordering&&L===0&&!((S==null?void 0:S.hasMore)??!1),oe=async()=>{if(!(!Q||!g))try{await $.reorder(w),C(!1),u({tone:"success",message:`Saved ${w.length} slice positions.`})}catch(f){u({tone:"error",message:qn(f instanceof Error?f.message:"","Failed to save slice order.")})}},Ie=async f=>{if(!(f===W&&T===null)){U(f);try{await $.setOrderMode(f),u({tone:"success",message:`Slice ordering set to ${f}.`})}catch(re){u({tone:"error",message:qn(re instanceof Error?re.message:"",`Failed to set ${f} ordering.`)})}finally{U(null)}}},He=f=>{!h||!f.initiativeId||h(f.initiativeId,f.initiativeTitle??void 0)};return e.jsxs("section",{className:Lt("flex min-h-0 flex-col rounded-2xl border border-strong bg-[#070b12]/88",c),children:[e.jsxs("div",{className:"flex flex-col gap-2 border-b border-strong px-3 py-3",children:[e.jsxs("div",{className:"flex min-h-[34px] items-center gap-2",children:[e.jsx("div",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70"}),e.jsx("h3",{className:"text-caption font-semibold uppercase tracking-[0.1em] text-secondary",children:o}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro text-secondary",children:se}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[e.jsxs("div",{ref:ee,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>J(f=>!f),className:"control-pill h-8 px-2.5 text-micro font-semibold","aria-haspopup":"menu","aria-expanded":P,children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"opacity-85","aria-hidden":!0,children:[e.jsx("path",{d:"M4 6h16"}),e.jsx("path",{d:"M7 12h10"}),e.jsx("path",{d:"M10 18h4"})]}),e.jsx("span",{children:"Filters"})]}),P?e.jsx("div",{className:"surface-tier-2 absolute right-0 top-[calc(100%+8px)] z-[260] w-[300px] max-w-[88vw] rounded-xl p-3 shadow-[0_16px_40px_rgba(0,0,0,0.46)] backdrop-blur-xl",children:e.jsxs("div",{className:"space-y-2.5",children:[e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Entity level"}),e.jsx("div",{className:"mt-1.5 grid grid-cols-2 gap-1.5",children:Ys.map(f=>e.jsxs("button",{type:"button",onClick:()=>{te(f.value),J(!1)},className:Lt("control-pill flex h-8 items-center gap-1.5 px-2 text-micro font-semibold",b===f.value?"border-[#BFFF00]/34 bg-[#BFFF00]/[0.12] text-[#E8FFD0]":"text-secondary"),children:[e.jsx(Ge,{type:f.value,size:10,className:"opacity-80"}),e.jsx("span",{children:f.label})]},f.value))})]}),e.jsxs("div",{children:[e.jsx("p",{className:"section-kicker",children:"Ordering"}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("button",{type:"button",className:Lt("control-pill h-8 px-2.5 text-micro font-semibold",W==="manual"?"border-[#BFFF00]/34 bg-[#BFFF00]/[0.12] text-[#E8FFD0]":"text-secondary"),disabled:$.isSettingOrderMode,onClick:()=>void Ie("manual"),children:"Manual"}),e.jsx("button",{type:"button",className:Lt("control-pill h-8 px-2.5 text-micro font-semibold",W==="algorithmic"?"border-teal-300/34 bg-teal-400/[0.13] text-teal-100":"text-secondary"),disabled:$.isSettingOrderMode,onClick:()=>void Ie("algorithmic"),children:"Algorithmic"})]})]})]})}):null]}),W==="manual"&&e.jsx("button",{type:"button",className:"control-pill h-8 px-2.5 text-micro font-semibold disabled:opacity-45",disabled:!g||!Q,onClick:()=>void oe(),children:"Save order"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("div",{className:"inline-flex flex-wrap items-center gap-1.5 rounded-xl border border-strong bg-white/[0.03] p-1",children:[ti.map(f=>e.jsx("button",{type:"button",onClick:()=>te(f.value),className:Lt("control-pill h-8 px-3 text-caption font-semibold",b===f.value?"border-[#BFFF00]/34 bg-[#BFFF00]/[0.12] text-[#E8FFD0]":"text-secondary"),children:f.label},`primary-level-${f.value}`)),b==="task"?e.jsx("span",{className:"chip text-micro text-secondary",children:"Task"}):null]}),e.jsx("div",{className:"min-w-[220px] flex-1",children:e.jsx(Js,{value:x,onChange:F,placeholder:"Search slices, entities, or IDs..."})})]}),(H==="local_fallback"||q.degraded.length>0)&&e.jsx("div",{className:"rounded-xl border border-amber-300/24 bg-amber-400/[0.08] px-2.5 py-1.5 text-micro text-amber-100/90",children:H==="local_fallback"?"Canonical slices unavailable; showing local fallback.":q.degraded[0]})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto px-2 pb-2 pt-2",children:q.isLoading?e.jsx("div",{className:"space-y-2 px-1",children:Array.from({length:d?4:7}).map((f,re)=>e.jsxs("div",{className:"rounded-xl border border-strong bg-white/[0.02] px-3 py-2",children:[e.jsx(yt,{className:"h-3.5 w-1/2 rounded-full"}),e.jsx(yt,{className:"mt-2 h-3 w-4/5 rounded-full"})]},`slice-loading-${re}`))}):I.length===0?e.jsx("div",{className:"rounded-xl border border-strong bg-white/[0.02] px-3 py-3 text-caption text-secondary",children:"No slices match this view."}):Q?e.jsx(Lr,{axis:"y",values:w,onReorder:f=>{k(f),C(!0)},className:"space-y-2",children:w.map((f,re)=>{var Re;const V=de.get(f);if(!V)return null;const pe=V.finalRank??V.manualRank??V.algorithmRank??re+1,De=(((Re=V.iwmt)==null?void 0:Re.factors)??[]).filter(Ne=>typeof Ne.value=="number"&&Number.isFinite(Ne.value)),Ue=typeof V.roiPerToken=="number"&&Number.isFinite(V.roiPerToken),Le=typeof V.objectiveScore=="number"&&Number.isFinite(V.objectiveScore),fe=Pn(V),Pe=Ln(V);return e.jsxs(Pr,{value:V.sliceId,className:"group hover-lift relative overflow-hidden rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 transition-colors hover:border-white/[0.14]",children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${_n(V.status)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("button",{type:"button",className:"mt-0.5 inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md border border-strong bg-white/[0.04] text-caption text-secondary","aria-label":"Drag to reorder",title:"Drag to reorder",children:"⋮⋮"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"rounded-md border border-[#BFFF00]/22 bg-[#BFFF00]/[0.08] px-1.5 py-0.5 text-micro font-semibold text-[#DFFFB5]",children:["#",pe]}),e.jsx("div",{className:"min-w-0 flex-1",children:e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[e.jsx(Ge,{type:V.level,size:11,className:"mt-0.5 flex-shrink-0 opacity-80"}),e.jsx("p",{className:"min-w-0 flex-1 line-clamp-2 text-caption font-semibold leading-snug text-primary",children:Bn(V)})]})}),e.jsxs("div",{className:"ml-auto flex flex-shrink-0 items-center gap-1.5",children:[e.jsx("span",{className:Lt("rounded-full border px-2 py-0.5 text-micro uppercase tracking-[0.08em]",Tn(V.status)),children:V.status.replace(/_/g," ")}),V.initiativeId&&h?e.jsx("button",{type:"button",className:"control-pill h-6 px-2 text-micro font-semibold",onClick:()=>He(V),children:"Open"}):null]})]}),e.jsx("p",{className:"mt-1 inline-flex min-w-0 items-center gap-1 truncate text-micro text-secondary",title:Pe,children:e.jsx("span",{className:"truncate",children:Pe})}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-micro text-secondary",children:[e.jsx("span",{className:"chip text-micro",children:$n(V.level)}),e.jsx("span",{className:"chip text-micro",children:Rn(V)}),e.jsxs("span",{className:"chip text-micro",children:["Agent ",fe]}),Ue?e.jsxs("span",{className:"chip text-micro",children:["ROI/token ",Yt(V.roiPerToken,3)]}):null,Le?e.jsxs("span",{className:"chip text-micro",children:["Obj ",Yt(V.objectiveScore,2)]}):null]}),De.length>0&&e.jsxs("details",{className:"mt-1.5",children:[e.jsx("summary",{className:"cursor-pointer text-micro text-secondary",children:"Why this slice"}),e.jsx("div",{className:"mt-1 space-y-1 text-micro text-secondary",children:De.slice(0,3).map((Ne,Me)=>e.jsxs("p",{children:[(Ne.label??Ne.key??"factor").replace(/_/g," "),":"," ",Yt(Ne.value,2)]},`${V.sliceId}-factor-${Me}`))})]})]})]})]},V.sliceId)})}):e.jsx("div",{className:"space-y-2",children:I.map((f,re)=>{var Pe;const V=f.finalRank??f.manualRank??f.algorithmRank??re+1,Ce=(((Pe=f.iwmt)==null?void 0:Pe.factors)??[]).filter(Re=>typeof Re.value=="number"&&Number.isFinite(Re.value)),De=typeof f.roiPerToken=="number"&&Number.isFinite(f.roiPerToken),Ue=typeof f.objectiveScore=="number"&&Number.isFinite(f.objectiveScore),Le=Pn(f),fe=Ln(f);return e.jsxs(ge.article,{initial:{opacity:0,y:10,scale:.985},animate:{opacity:1,y:0,scale:1},transition:{duration:.22,delay:Math.min(re,7)*.02,ease:[.22,1,.36,1]},className:"group hover-lift relative overflow-hidden rounded-2xl border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 transition-colors hover:border-white/[0.14]",children:[e.jsx("div",{className:`pointer-events-none absolute inset-x-3 top-0 h-px bg-gradient-to-r ${_n(f.status)}`,"aria-hidden":!0}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsxs("span",{className:"rounded-md border border-[#BFFF00]/22 bg-[#BFFF00]/[0.08] px-1.5 py-0.5 text-micro font-semibold text-[#DFFFB5]",children:["#",V]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-1.5",children:[e.jsx(Ge,{type:f.level,size:11,className:"mt-0.5 flex-shrink-0 opacity-80"}),e.jsx("p",{className:"min-w-0 flex-1 line-clamp-2 text-caption font-semibold leading-snug text-primary",children:Bn(f)})]}),e.jsx("p",{className:"mt-1 inline-flex min-w-0 items-center gap-1 truncate text-micro text-secondary",title:fe,children:e.jsx("span",{className:"truncate",children:fe})}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-1.5 text-micro text-secondary",children:[e.jsx("span",{className:"chip text-micro",children:$n(f.level)}),e.jsx("span",{className:"chip text-micro",children:Rn(f)}),e.jsxs("span",{className:"chip text-micro",children:["Agent ",Le]}),De?e.jsxs("span",{className:"chip text-micro",children:["ROI/token ",Yt(f.roiPerToken,3)]}):null,Ue?e.jsxs("span",{className:"chip text-micro",children:["Obj ",Yt(f.objectiveScore,2)]}):null,e.jsx("span",{className:Lt("rounded-full border px-2 py-0.5 uppercase tracking-[0.08em]",Tn(f.status)),children:f.status.replace(/_/g," ")})]}),Ce.length>0&&e.jsxs("details",{className:"mt-1.5",children:[e.jsx("summary",{className:"cursor-pointer text-micro text-secondary",children:"Why this slice"}),e.jsx("div",{className:"mt-1 space-y-1 text-micro text-secondary",children:Ce.slice(0,3).map((Re,Ne)=>e.jsxs("p",{children:[(Re.label??Re.key??"factor").replace(/_/g," "),":"," ",Yt(Re.value,2)]},`${f.sliceId}-factor-static-${Ne}`))})]})]}),f.initiativeId&&h?e.jsx("button",{type:"button",className:"control-pill h-7 px-2 text-micro font-semibold",onClick:()=>He(f),children:"Open"}):null]})]},f.sliceId)})})}),e.jsxs("div",{className:"flex items-center gap-2 border-t border-strong px-3 py-2",children:[e.jsxs("p",{className:"text-micro text-secondary",children:[R,"-",X," of ",se]}),e.jsx("button",{type:"button",className:"control-pill ml-auto h-7 px-2 text-micro font-semibold disabled:opacity-40",disabled:L===0,onClick:()=>N(Math.max(0,L-l)),children:"Prev"}),e.jsx("button",{type:"button",className:"control-pill h-7 px-2 text-micro font-semibold disabled:opacity-40",disabled:!((S==null?void 0:S.hasMore)??!1),onClick:()=>N(L+l),children:"Next"})]}),y&&e.jsx("div",{className:"border-t border-strong px-3 py-2",children:e.jsx(Yn,{open:!0,tone:y.tone==="error"?"error":"success",title:y.tone==="error"?"Slice explorer error":"Slice explorer updated",message:y.message,onDismiss:()=>u(null),autoDismissMs:4200})})]})}function Ws(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Hs(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}function zn(t){if(!t)return null;const s=Date.parse(`${t}T00:00:00`);return Number.isFinite(s)?s:null}function si(t,s){return s==="target"?t.targetDate??null:s==="created"?t.createdAt??null:t.updatedAt??t.createdAt??null}function Un(t){const s=(t??"").trim().toLowerCase();return s?s==="critical"||s==="p0"||s==="urgent"?0:s==="high"||s==="p1"?1:s==="medium"||s==="normal"||s==="p2"?2:s==="low"||s==="p3"?3:4:4}function Wn(t){return t==="active"?0:t==="blocked"?1:t==="paused"?2:3}function Qn(t,s){if(s==="status"){const r=new Map,n=["active","blocked","paused","completed"];for(const c of t){const o=c.status??"active",d=r.get(o)??[];d.push(c),r.set(o,d)}return n.filter(c=>r.has(c)).concat(Array.from(r.keys()).filter(c=>!n.includes(c))).map(c=>{var o;return{key:c,label:c.charAt(0).toUpperCase()+c.slice(1),count:((o=r.get(c))==null?void 0:o.length)??0,initiatives:r.get(c)??[]}})}if(s==="category"){const r=new Map;for(const n of t){const c=n.category??"Uncategorized",o=r.get(c)??[];o.push(n),r.set(c,o)}return Array.from(r.entries()).sort((n,c)=>n[0].localeCompare(c[0])).map(([n,c])=>({key:n,label:n,count:c.length,initiatives:c}))}if(s==="date"){const n=Hs(new Date),c=n+7*864e5,o=n+30*864e5,d={overdue:[],this_week:[],this_month:[],later:[],no_date:[]};for(const b of t){const j=b.targetDate?Date.parse(b.targetDate):null;j===null||!Number.isFinite(j)?d.no_date.push(b):j<n?d.overdue.push(b):j<c?d.this_week.push(b):j<o?d.this_month.push(b):d.later.push(b)}const h={overdue:"Overdue",this_week:"This Week",this_month:"This Month",later:"Later",no_date:"No Date"};return["overdue","this_week","this_month","later","no_date"].filter(b=>d[b].length>0).map(b=>({key:b,label:h[b],count:d[b].length,initiatives:d[b]}))}return[]}function qt(t,s){return`${t}:${s}`}function ni(t){return`mc-group-${t}`.toLowerCase().replace(/[^a-z0-9_-]+/g,"-")}function Hn(t,s){if(t.size!==s.size)return!1;for(const r of t)if(!s.has(r))return!1;return!0}function ri(t){return t==="running"?"Running":t==="blocked"?"Blocked":t==="queued"?"Queued":t==="startable"?"Startable":t==="completed"?"Complete":t==="active_no_queue"?"Idle":"No target"}function ai(t){return t==="running"?"border-teal-300/24 bg-teal-400/[0.08] text-teal-100/90":t==="blocked"?"border-red-400/24 bg-red-500/[0.08] text-red-100/90":t==="queued"||t==="startable"?"border-[#BFFF00]/18 bg-[#BFFF00]/[0.06] text-[#E8FFD0]/95":t==="completed"?"border-strong bg-white/[0.05] text-secondary":"border-strong bg-white/[0.04] text-white/68"}function ii(t){const s=t.trim().toLowerCase();if(s.includes("timed out")||s.includes("timeout")||s.includes("request cancelled")||s.includes("signal is aborted"))return"Live sync is taking longer than expected. Initiatives and Next Up will repopulate as soon as sync completes.";if(s.includes("unauthorized")||s.includes("forbidden")||s.includes("api key")||s.includes("auth"))return"OrgX authentication needs attention. Reconnect your API key in Settings.";if(s.includes("unknown api endpoint")||s.includes("missing required live routes"))return"This runtime is missing required live routes. Restart and update the plugin build.";const r=t.split("|").map(n=>n.trim()).filter(Boolean).map(n=>n.replace(/^[^:]+:\s*/,"").trim()).filter(Boolean).slice(0,2).join(" ");return ct(r||t)||"Live data is temporarily unavailable."}function Xt(t,s){return!t||t.trim().length===0?s:ct(t.trim())||s}const oi=[12,24,36,48,72];function yi({initiatives:t,activities:s,agents:r,runtimeInstances:n=[],workspaceInitiativeId:c=null,isLoading:o,authToken:d,embedMode:h,initialInitiativeId:b,connection:j,lastSnapshotAt:x,error:F,hasApiKey:M,onOpenSettings:N,onRefresh:l,onCreateInitiative:y,onPlayNextUp:u,onStartAutopilot:w,nextUpQueueModel:k,nextUpActionsModel:g,snapshotVersion:C=null}){const T=qr({activities:s,agents:r,initiatives:t});return e.jsx(ea,{agentEntityMap:T,authToken:d,embedMode:h,children:e.jsx(di,{initiatives:t,runtimeInstances:n,workspaceInitiativeId:c,isLoading:o,initialInitiativeId:b,connection:j,lastSnapshotAt:x,error:F,hasApiKey:M,onOpenSettings:N,onRefresh:l,onCreateInitiative:y,onPlayNextUp:u,onStartAutopilot:w,nextUpQueueModel:k,nextUpActionsModel:g,snapshotVersion:C})})}function li(t){if(!t)return"unknown";const s=Date.parse(t);if(!Number.isFinite(s))return"unknown";try{return new Date(s).toLocaleString()}catch{return"unknown"}}function ci(t,s){var r,n;return{...s,...t,rawStatus:t.rawStatus??s.rawStatus??null,priority:t.priority??s.priority??null,targetDate:t.targetDate??s.targetDate??null,createdAt:t.createdAt??s.createdAt??null,updatedAt:t.updatedAt??s.updatedAt??null,description:t.description??s.description,activeAgents:Math.max(t.activeAgents,s.activeAgents),totalAgents:Math.max(t.totalAgents,s.totalAgents),avatars:(r=t.avatars)!=null&&r.length?t.avatars:s.avatars,workstreams:(n=t.workstreams)!=null&&n.length?t.workstreams:s.workstreams,health:t.health>0?t.health:s.health}}function di({initiatives:t,runtimeInstances:s,workspaceInitiativeId:r=null,isLoading:n,initialInitiativeId:c,connection:o,lastSnapshotAt:d,error:h,hasApiKey:b,onOpenSettings:j,onRefresh:x,onCreateInitiative:F,onPlayNextUp:M,onStartAutopilot:N,nextUpQueueModel:l,nextUpActionsModel:y,snapshotVersion:u=null}){var un,mn,pn,xn,hn;const{searchQuery:w,setSearchQuery:k,statusFilters:g,setStatusFilters:C,dateField:T,setDateField:U,datePreset:P,setDatePreset:J,dateStart:ee,setDateStart:te,dateEnd:q,setDateEnd:$,clearFilters:v,hasActiveFilters:H,groupBy:S,sortBy:W,expandedInitiatives:L,expandAll:se,collapseAll:R,modalTarget:X,closeModal:ie,expandInitiative:de,authToken:I,embedMode:Q,mutations:oe}=Dt(),Ie=a.useRef(!1),He=a.useRef(null),ze=a.useRef(0),[f,re]=a.useState(0),[V,pe]=a.useState(new Set),[Ce,De]=a.useState(!1),[Ue,Le]=a.useState(!1),[fe,Pe]=a.useState(!1),[Re,Ne]=a.useState(!1),[Me,ht]=a.useState("next-up"),[St,je]=a.useState(null),[Je,$e]=a.useState(null),[et,ft]=a.useState(new Set),[wt,Ye]=a.useState(!1),[Qe,We]=a.useState(null),[dt,tt]=a.useState(0),[st,Ut]=a.useState(24),vt=w.trim(),ut=Jr(vt,vt.length>=2,r),Ct=a.useMemo(()=>{var D;if(vt.length<2||!((D=ut.data)!=null&&D.length))return t;const m=new Map;for(const B of t)m.set(B.id,B);for(const B of ut.data){const K=m.get(B.id);m.set(B.id,K?ci(K,B):B)}return Array.from(m.values())},[ut.data,t,vt.length]),nt=a.useMemo(()=>new Set((ut.data??[]).map(m=>m.id)),[ut.data]);a.useEffect(()=>{if(!Qe)return;const m=Qe.tone==="success"?6500:9e3,D=window.setTimeout(()=>We(null),m);return()=>window.clearTimeout(D)},[Qe==null?void 0:Qe.message,Qe==null?void 0:Qe.tone]);const Mt=a.useMemo(()=>{const D=Hs(new Date),B=w.toLowerCase().trim().split(/\s+/).filter(Boolean);return Ct.filter(K=>{if(g.length>0&&![Ws(K.status),Ws(K.rawStatus)].filter(Boolean).some(lt=>g.includes(lt)))return!1;const he=si(K,T),Te=he?Date.parse(he):Number.NaN,qe=Number.isFinite(Te)?Hs(new Date(Te)):null,ae=qe===null?null:Math.round((qe-D)/864e5);if(P==="missing"&&qe!==null||P==="overdue"&&!(ae!==null&&ae<0)||P==="today"&&ae!==0||P==="next_7_days"&&!(ae!==null&&ae>=0&&ae<=7)||P==="next_30_days"&&!(ae!==null&&ae>=0&&ae<=30)||P==="past_7_days"&&!(ae!==null&&ae<=0&&ae>=-7)||P==="past_30_days"&&!(ae!==null&&ae<=0&&ae>=-30))return!1;if(P==="custom_range"){const gt=zn(ee),lt=zn(q);if(qe===null||gt!==null&&qe<gt||lt!==null&&qe>lt)return!1}if(B.length===0||nt.has(K.id))return!0;const It=[K.name,K.description??"",K.status,K.rawStatus??"",K.category??""].join(" ").toLowerCase();return B.every(gt=>It.includes(gt))})},[Ct,w,nt,g,T,P,ee,q]),ke=a.useMemo(()=>{const m=(D,B,K)=>{const he=D.targetDate?Date.parse(D.targetDate):Number.NaN,Te=B.targetDate?Date.parse(B.targetDate):Number.NaN,qe=Number.isFinite(he),ae=Number.isFinite(Te);return!qe&&!ae?0:qe?ae?K==="asc"?he-Te:Te-he:-1:1};return[...Mt].sort((D,B)=>{if(W==="date_asc")return m(D,B,"asc");if(W==="date_desc")return m(D,B,"desc");const K=Un(D.priority),he=Un(B.priority);if(W==="priority_high"&&K!==he)return K-he;if(W==="priority_low"&&K!==he)return he-K;if(W==="default"){const ae=Wn(D.status)-Wn(B.status);if(ae!==0)return ae;if(K!==he)return K-he}const Te=D.updatedAt?Date.parse(D.updatedAt):0,qe=B.updatedAt?Date.parse(B.updatedAt):0;return Te!==qe?qe-Te:D.name.localeCompare(B.name)})},[Mt,W]),rt=ke.length,Xe=Math.max(1,Math.ceil(rt/st)),at=rt===0?0:Math.min(dt,Xe-1),jt=at*st,i=Math.min(rt,jt+st),E=rt===0?0:jt+1,A=rt===0?0:i,z=a.useMemo(()=>ke.slice(jt,i),[i,jt,ke]),G=a.useMemo(()=>new Set(ke.map(m=>m.id)),[ke]),ue=a.useMemo(()=>ke.filter(m=>et.has(m.id)),[et,ke]),we=a.useMemo(()=>z.filter(m=>et.has(m.id)),[z,et]),Fe=ue.length,Se=we.length,_e=z.length>0&&Se===z.length,be=oe.bulkEntityMutation.isPending,it=a.useMemo(()=>{var B;const m=new Map;for(const K of s){const he=(B=K.initiativeId)==null?void 0:B.trim();if(!he)continue;const Te=m.get(he)??{activeCount:0,totalCount:0,lastHeartbeatAt:null,lastHeartbeatMs:0};Te.totalCount+=1,K.state==="active"&&(Te.activeCount+=1);const qe=K.lastHeartbeatAt??K.lastEventAt??null,ae=qe?Date.parse(qe):Number.NaN;Number.isFinite(ae)&&ae>Te.lastHeartbeatMs&&(Te.lastHeartbeatMs=ae,Te.lastHeartbeatAt=new Date(ae).toISOString()),m.set(he,Te)}const D=new Map;for(const[K,he]of m.entries())D.set(K,{activeCount:he.activeCount,totalCount:he.totalCount,lastHeartbeatAt:he.lastHeartbeatAt});return D},[s]),ye=a.useMemo(()=>S!=="none"?Qn(z,S):null,[S,z]),kt=a.useMemo(()=>(ye==null?void 0:ye.map(m=>qt(S,m.key)))??[],[S,ye]),$t=a.useMemo(()=>{if(!ye)return z.map(D=>D.id);const m=[];for(const D of ye){const B=qt(S,D.key);if(V.has(B))for(const K of D.initiatives)m.push(K.id)}return m},[V,S,ye,z]),{handleSelect:p}=Xn($t),_=a.useCallback(m=>{pe(D=>{const B=new Set(D);return B.has(m)?B.delete(m):B.add(m),B})},[]);a.useEffect(()=>{if(!ye||ye.length===0){pe(D=>D.size===0?D:new Set);return}const m=new Set(ye.map(D=>qt(S,D.key)));pe(D=>{const B=new Set(Array.from(D).filter(K=>m.has(K)));return B.size===0&&B.add(qt(S,ye[0].key)),Hn(B,D)?D:B})},[S,ye]),a.useEffect(()=>{ft(m=>{if(m.size===0)return m;const D=new Set(Array.from(m).filter(B=>G.has(B)));return Hn(D,m)?m:D})},[G]),a.useEffect(()=>{if(c&&!Ie.current&&!n&&t.length>0){const m=ke.findIndex(D=>D.id===c);if(m>=0&&tt(Math.floor(m/st)),de(c),ye){const D=ye.find(B=>B.initiatives.some(K=>K.id===c));if(D){const B=qt(S,D.key);pe(K=>{if(K.has(B))return K;const he=new Set(K);return he.add(B),he})}}Ie.current=!0,requestAnimationFrame(()=>{const D=document.getElementById(`initiative-${c}`);D==null||D.scrollIntoView({behavior:"smooth",block:"start"})})}},[c,n,t.length,de,st,S,ye,ke]),a.useEffect(()=>{Fe===0&&wt&&Ye(!1)},[wt,Fe]),a.useEffect(()=>{tt(m=>Math.min(m,Math.max(Xe-1,0)))},[Xe]),a.useEffect(()=>{tt(0)},[w,g,T,P,ee,q,S,W,st]);const me=z.length>0&&z.every(m=>L.has(m.id)),Be=a.useMemo(()=>ke.find(m=>m.status!=="completed")??ke[0]??null,[ke]),Ve=$r({projectId:r,authToken:I,embedMode:Q,enabled:l?!1:t.length>0,snapshotVersion:u}),xe=l??Ve,Wt=ls({authToken:I,embedMode:Q}),mt=y??Wt,le=xe.items[0]??null,Cs=xe.items.length,Qt=a.useMemo(()=>xe.items.filter(m=>m.queueState==="running").length,[xe.items]),ts=xe.isFetching&&!xe.isLoading,O=a.useMemo(()=>xe.items.find(m=>m.playbackState==="running"||m.playbackState==="blocked")??xe.items.find(m=>m.queueState==="running"||m.queueState==="blocked")??null,[xe.items]),Ee=a.useMemo(()=>xe.items.find(m=>O&&m.initiativeId===O.initiativeId&&m.workstreamId===O.workstreamId?!1:m.playbackState==="queued"||m.playbackState==="idle"||m.queueState==="queued"||m.queueState==="idle")??null,[xe.items,O]),Z=a.useMemo(()=>le?t.find(m=>m.id===le.initiativeId)??Be:Be,[Be,t,le]),Tt=O??Ee??le??null,Ft=(Tt==null?void 0:Tt.initiativeId)??(Z==null?void 0:Z.id)??null,Xs=a.useCallback((m,D,B)=>{We(null),Ye(!1),p(m,D,B,ft)},[p]),tr=a.useCallback(()=>{We(null),Ye(!1),ft(m=>{if(z.length===0)return m;const D=new Set(m);if(_e)for(const B of z)D.delete(B.id);else for(const B of z)D.add(B.id);return D})},[_e,z]),sr=a.useCallback(()=>{Ye(!1),ft(new Set)},[]),Zs=at>0,en=at<Xe-1,Et=a.useCallback(m=>{tt(Math.max(0,Math.min(m,Xe-1)))},[Xe]),nr=a.useCallback(()=>{Et(0)},[Et]),rr=a.useCallback(()=>{Et(at-1)},[at,Et]),ar=a.useCallback(()=>{Et(at+1)},[at,Et]),ir=a.useCallback(()=>{Et(Xe-1)},[Et,Xe]),cs=a.useCallback(async m=>{if(ue.length!==0){Ye(!1),We(null);try{const D=await oe.bulkEntityMutation.mutateAsync({items:ue.map(B=>({type:"initiative",id:B.id})),mode:"update",updates:{status:m}});D.failed>0?We({tone:"error",message:`Updated ${D.updated}, failed ${D.failed}.`}):We({tone:"success",message:`Updated ${D.updated} initiative${D.updated===1?"":"s"} to ${m}.`})}catch(D){We({tone:"error",message:Xt(D instanceof Error?D.message:"","Bulk initiative update failed.")})}}},[oe.bulkEntityMutation,ue]),or=a.useCallback(async()=>{if(ue.length!==0){We(null);try{const m=await oe.bulkEntityMutation.mutateAsync({items:ue.map(D=>({type:"initiative",id:D.id})),mode:"delete"});m.failed>0?We({tone:"error",message:`Deleted ${m.updated}, failed ${m.failed}.`}):(We({tone:"success",message:`Deleted ${m.updated} initiative${m.updated===1?"":"s"}.`}),ft(new Set),Ye(!1))}catch(m){We({tone:"error",message:Xt(m instanceof Error?m.message:"","Bulk initiative delete failed.")})}}},[oe.bulkEntityMutation,ue]),Fs=a.useCallback(()=>{ze.current+=1,De(!1)},[]),lr=a.useCallback(m=>{if(m.length===0){Fs();return}const D=1,B=ze.current+1;ze.current=B,De(!0);const K=he=>{if(ze.current===B){if(se(m.slice(0,he)),he>=m.length){De(!1);return}requestAnimationFrame(()=>K(Math.min(m.length,he+D)))}};K(Math.min(D,m.length))},[Fs,se]),Ae=Or({initiativeId:Ft,authToken:I,embedMode:Q,enabled:!!Ft}),[_t,Ht]=a.useState(null),ds=Ae.run,Es=((un=Ae.error)==null?void 0:un.toLowerCase())??"",As=!Ft||Es.includes("404")||Es.includes("400")||Es.includes("not found"),ot=Ft?it.get(Ft)??null:null,Is=((ot==null?void 0:ot.activeCount)??0)>0,cr=((ot==null?void 0:ot.totalCount)??0)>0,tn=_t?`Upgrade required · ${bn(_t.currentPlan)} → ${bn(_t.requiredPlan)}`:Ft?Ae.isRunning?Is?`Running · ${(ot==null?void 0:ot.activeCount)??0} live`:cr?`Enabled · ${(ot==null?void 0:ot.totalCount)??0} idle`:"Enabled · waiting":ds!=null&&ds.stopReason?`Idle · ${ds.stopReason.replace(/_/g," ")}`:"Idle":"No target",Vt=!!_t&&!Ae.isRunning,dr=Vt?"amber":"teal",ur=a.useMemo(()=>{const m=new URL("https://www.useorgx.com/integrations/openclaw");return m.searchParams.set("utm_source",Q?"live_share":"orgx_openclaw_plugin"),m.searchParams.set("utm_medium","mission_control"),m.searchParams.set("utm_campaign","live_link_dashboard"),m.searchParams.set("utm_content","install_cta"),m.toString()},[Q]);a.useEffect(()=>{Ht(null)},[Ft]),a.useEffect(()=>{const m=He.current;if(!m)return;const D=()=>{re(Math.max(64,m.offsetHeight))};if(D(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(()=>D());return B.observe(m),()=>B.disconnect()},[tn,o,h,n,ke.length]);const Ds=!!(!n&&b&&(o==="disconnected"||h)),mr=o==="disconnected"||h?"critical":"info",pr=o==="disconnected"?"Offline":h?"Live degraded":"Connected",sn=h?ii(h):o==="disconnected"?"Live updates are offline. Data may be stale until reconnect.":`Last snapshot ${li(d)}`;a.useEffect(()=>{Ds||Le(!1)},[Ds]);const At=a.useCallback((m,D)=>{if(!t.find(ae=>ae.id===m)){const ae=(D??"").trim(),It=ae?Gs(ae)?`Initiative ${Jn(ae)}`:es(ae):"This initiative";return je({tone:"error",message:`${It} is not in this workspace view. Switch workspace or clear filters to find it.`}),!1}je(null);const K=ke.findIndex(ae=>ae.id===m),he=K<0;if(K>=0&&tt(Math.floor(K/st)),he&&(k(""),C([]),U("target"),J("any"),te(""),$("")),de(m),S!=="none"){const ae=K>=0?ke:t,gt=Qn(ae,S).find(lt=>lt.initiatives.some(Jt=>Jt.id===m));if(gt){const lt=qt(S,gt.key);pe(Jt=>{if(Jt.has(lt))return Jt;const fn=new Set(Jt);return fn.add(lt),fn})}}const Te=(ae=0)=>{const It=document.getElementById(`initiative-${m}`);if(It){It.scrollIntoView({behavior:ae===0?"smooth":"auto",block:"start"});const gt=Math.max(72,f)+8,lt=It.getBoundingClientRect();!(lt.top>=gt&&lt.top<=window.innerHeight-72)&&ae<18&&window.setTimeout(()=>Te(ae+1),90);return}ae>=60||requestAnimationFrame(()=>Te(ae+1))},qe=()=>requestAnimationFrame(()=>Te());return he?window.setTimeout(qe,90):qe(),!0},[t,st,je,tt,k,C,U,J,te,$,de,S,ke,f]),xr=a.useCallback(()=>{Z&&(je(null),oe.updateEntity.mutateAsync({type:"initiative",id:Z.id,status:"active"}).then(()=>{je({tone:"success",message:`Started ${Z.name}.`}),At(Z.id,Z.name)}).catch(m=>{je({tone:"error",message:Xt(m instanceof Error?m.message:"","Failed to start initiative.")})}))},[oe.updateEntity,Z,At]),Bt=a.useCallback(async(m,D,B)=>{$e(m),je(null);try{await D(),je({tone:"success",message:B})}catch(K){je({tone:"error",message:Xt(K instanceof Error?K.message:"","Action failed.")})}finally{$e(null)}},[]),hr=a.useCallback(()=>O?Bt("pause",()=>mt.stopTriage({initiativeId:O.initiativeId,workstreamId:O.workstreamId,placement:"bottom",resetToTodo:!1}),`Paused ${O.workstreamTitle} and moved it to bottom of queue.`):Promise.resolve(),[mt,O,Bt]),fr=a.useCallback(()=>{if(!O)return Promise.resolve();const m=O.playbackState==="running"||O.playbackState==="blocked"||O.queueState==="running"||O.queueState==="blocked";return Bt("defer",()=>m?mt.stopTriage({initiativeId:O.initiativeId,workstreamId:O.workstreamId,placement:"bottom",resetToTodo:!1}):mt.move({initiativeId:O.initiativeId,workstreamId:O.workstreamId,placement:"bottom"}),`Deferred ${O.workstreamTitle} to bottom of queue.`)},[mt,O,Bt]),gr=a.useCallback(()=>{const m=O??Ee??le;if(!m)return Promise.resolve();const D=m.autoIntentEnabled===!0&&(m.autoRuntimeState==="running"||m.autoRuntimeState==="stopping");return Bt("auto",()=>D?xe.stopInitiativeAutoContinue({initiativeId:m.initiativeId}):(async()=>(await mt.move({initiativeId:m.initiativeId,workstreamId:m.workstreamId,placement:"top"}),xe.startWorkstreamAutoContinue({initiativeId:m.initiativeId,workstreamId:m.workstreamId,agentId:m.runnerAgentId,scope:"initiative"})))(),D?`Stopped auto-continue for ${m.initiativeTitle}.`:`Auto-continue enabled for ${m.initiativeTitle}; starting with ${m.workstreamTitle}.`)},[xe,le,Ee,mt,O,Bt]),nn=a.useCallback(()=>{Z&&(At(Z.id,Z.name),typeof window<"u"&&window.innerWidth>=1280&&Pe(!0))},[Z,At]),Ms=a.useCallback(()=>{if(typeof window>"u")return;if(window.innerWidth>=1280){const D=!fe;Ne(!1),Pe(D),je({tone:"success",message:D?"Opened queue rail.":"Closed queue rail."});return}const m=!Re;Pe(!1),Ne(m),je({tone:"success",message:m?"Opened queue panel.":"Closed queue panel."})},[Re,fe]),Kt=Ws((Z==null?void 0:Z.rawStatus)??(Z==null?void 0:Z.status)??null),rn=a.useMemo(()=>new Set(["paused","draft","planned","todo","backlog","queued"]),[]),Ke=a.useMemo(()=>Z?(O==null?void 0:O.queueState)==="running"||(O==null?void 0:O.playbackState)==="running"||(le==null?void 0:le.autoIntentEnabled)===!0&&(le.autoRuntimeState==="running"||le.autoRuntimeState==="stopping")?"running":(le==null?void 0:le.queueState)==="blocked"||Z.status==="blocked"?"blocked":le?"queued":rn.has(Kt)?"startable":Kt==="completed"||Kt==="done"?"completed":"active_no_queue":"none",[Z,le,rn,Kt,O]),$s=a.useMemo(()=>Z?Ke==="running"&&le?{headline:`${le.workstreamTitle} is running`,detail:`Runner: ${le.runnerAgentName}. Follow live updates in Activity.`}:Ke==="queued"&&le?{headline:le.workstreamTitle,detail:`Ready to dispatch${le.nextTaskTitle?` · ${le.nextTaskTitle}`:""}.`}:Ke==="startable"?{headline:Kt==="paused"?`${Z.name} is paused`:`${Z.name} is ready to start`,detail:"Start initiative to queue and dispatch the next workstream."}:Ke==="blocked"?{headline:(le==null?void 0:le.queueState)==="blocked"?`${le.workstreamTitle} is blocked`:`${Z.name} is blocked`,detail:(le==null?void 0:le.blockReason)??"Resolve blockers or approvals before dispatching more work."}:Ke==="completed"?{headline:`${Z.name} is complete`,detail:"Choose another active initiative or queue new workstreams."}:{headline:Z.name,detail:"No queued workstream detected yet. Use Next Up to choose what runs next."}:{headline:"No initiative selected",detail:"Create or select an initiative to queue work."},[Z,Ke,le,Kt]),us=xe.isPlaying||xe.isStartingAutoContinue||xe.isStoppingAutoContinue||oe.updateEntity.isPending,br=a.useMemo(()=>Ke==="blocked"?"Review blockers":Ke==="active_no_queue"?"Open and queue work":Ke==="completed"?"Review initiative":"Open initiative",[Ke]),an=a.useMemo(()=>(O==null?void 0:O.playbackState)==="running"||(O==null?void 0:O.queueState)==="running"?"running":(O==null?void 0:O.playbackState)==="blocked"||(O==null?void 0:O.queueState)==="blocked"?"blocked":Ee?"queued":Ke==="startable"?"startable":Ke==="completed"?"completed":Z?"active_no_queue":"none",[Z,Ke,Ee,O]),on=(O==null?void 0:O.workstreamTitle)??"No active workstream",yr=(O==null?void 0:O.initiativeTitle)??(Z==null?void 0:Z.name)??"No initiative selected",Ts=O?[O.nextTaskTitle?`Next: ${O.nextTaskTitle}`:null,O.blockReason?`Blocked: ${O.blockReason}`:null].filter(Boolean).join(" · "):Ee?`Next up: ${Ee.workstreamTitle}`:$s.detail,ln=(Ee==null?void 0:Ee.workstreamTitle)??"Queue is empty",cn=Ee!=null&&Ee.nextTaskTitle?`Next task: ${Ee.nextTaskTitle}`:"Add or reorder workstreams in queue.",wr=ri(an),vr=ai(an),Gt=O??Ee??le,_s=(Gt==null?void 0:Gt.autoIntentEnabled)===!0&&(Gt.autoRuntimeState==="running"||Gt.autoRuntimeState==="stopping"),Bs="next-up-surface",Ls=a.useMemo(()=>({type:"spring",stiffness:340,damping:38,mass:.72}),[]),jr=a.useMemo(()=>({backgroundColor:"rgba(10, 14, 21, 0.66)",borderColor:"rgba(255, 255, 255, 0.10)"}),[]),dn=a.useMemo(()=>({backgroundColor:"rgba(10, 14, 21, 0.95)",borderColor:"rgba(255, 255, 255, 0.11)"}),[]),kr=a.useMemo(()=>{if(!X)return null;const m=B=>t.find(K=>K.id===B)??null;if(X.type==="initiative"){const B=m(X.entity.id);return B?{...X,entity:B}:X}const D=m(X.initiative.id);return D?{...X,initiative:D}:X},[t,X]);return a.useEffect(()=>{je(null)},[Z==null?void 0:Z.id,le==null?void 0:le.initiativeId,le==null?void 0:le.workstreamId,O==null?void 0:O.initiativeId,O==null?void 0:O.workstreamId,Ee==null?void 0:Ee.initiativeId,Ee==null?void 0:Ee.workstreamId]),a.useEffect(()=>{if(!X)return;const m=X.type==="initiative"?X.entity.id:X.initiative.id;t.some(B=>B.id===m)||ie()},[ie,t,X]),a.useEffect(()=>{if(typeof window>"u")return;const m=()=>{window.innerWidth>=1280?Ne(!1):Pe(!1)};return m(),window.addEventListener("resize",m),()=>window.removeEventListener("resize",m)},[]),e.jsxs("div",{className:"flex-1 min-h-0 flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("div",{className:"pointer-events-none absolute top-0 left-0 right-0 h-6 bg-gradient-to-b from-[#02040A] to-transparent z-10"}),e.jsx("div",{className:"pointer-events-none absolute bottom-0 left-0 right-0 h-12 bg-gradient-to-t from-[#02040A] to-transparent z-10"}),e.jsx("div",{"data-mc-scroll-host":"true",className:"h-full overflow-y-auto overflow-x-hidden",children:e.jsxs("div",{className:"mx-auto max-w-6xl px-4 sm:px-6",style:{"--mc-toolbar-offset":`${f}px`},children:[e.jsxs(Rr,{id:"next-up-morph",children:[e.jsxs("div",{ref:He,className:"sticky top-0 z-40 relative -mx-4 border-b border-subtle bg-[#02040A]/78 px-4 pb-2.5 pt-3.5 backdrop-blur-xl sm:-mx-6 sm:px-6",children:[e.jsx("div",{className:"pointer-events-none absolute right-4 top-2.5 z-50 sm:right-6",children:e.jsx(Yn,{open:Ds&&!Ue,tone:mr==="critical"?"error":"warning",title:pr,message:sn,onDismiss:()=>Le(!0),primaryAction:x?{label:"Refresh",onClick:x}:null,secondaryAction:j?{label:"Settings",onClick:j}:null})}),e.jsxs("div",{className:"toolbar-shell flex flex-col gap-2.5 md:flex-row md:items-center",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx(Js,{value:w,onChange:k,placeholder:"Search initiatives..."})}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2.5 md:ml-auto md:flex-nowrap",children:[e.jsx(Ha,{initiatives:t,visibleCount:Mt.length}),e.jsxs("div",{className:"hidden min-w-[220px] max-w-[320px] items-center gap-2 rounded-lg border border-strong bg-white/[0.03] px-2.5 py-1.5 xl:flex",title:(Z==null?void 0:Z.name)??void 0,children:[e.jsx("span",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-white/44",children:"Autopilot"}),e.jsxs("div",{className:"min-w-0 flex-1 text-right",children:[e.jsx("div",{className:"truncate text-micro text-white/72",children:tn}),Z&&e.jsx("div",{className:"truncate text-micro text-white/44",children:Z.name})]})]}),e.jsxs("button",{type:"button",onClick:()=>{if(As||!Ft)return;if(Vt&&_t){Br({actions:_t.actions,requiredPlan:_t.requiredPlan}).catch(B=>{je({tone:"error",message:Xt(B instanceof Error?B.message:"","Unable to open checkout right now.")})});return}const m=Ae.isRunning;(m?Ae.stop:Ae.start)().then(()=>{Ht(null);const B=(Z==null?void 0:Z.name)??"selected initiative";je({tone:"success",message:m?`Stopped Autopilot for ${B}.`:`Started Autopilot for ${B}.`})}).catch(B=>{B instanceof Tr?Ht(B):(Ht(null),je({tone:"error",message:Xt(B instanceof Error?B.message:"","Autopilot action failed.")}))})},disabled:As||Ae.isStarting||Ae.isStopping,title:As?"Select an initiative to run Autopilot":Vt?"Upgrade to enable auto-continue for BYOK agents":Ae.isRunning?"Stop Autopilot":`Start Autopilot${Z?` for ${Z.name}`:""}`,"data-state":Ae.isRunning||Vt?"active":"idle","data-tone":dr,className:"control-pill flex items-center gap-1.5 px-3 text-caption font-semibold disabled:opacity-40",children:[Vt?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M18 11l-6-6-6 6"})]}):Ae.isRunning?Is?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",className:"status-breathe",children:e.jsx("rect",{x:"7",y:"7",width:"10",height:"10",rx:"2"})}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8"}),e.jsx("path",{d:"M12 8v4l3 2"})]}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),e.jsx("span",{children:Vt?"Upgrade Autopilot":`${Ae.isRunning?"Stop":"Start"} Autopilot`}),Ae.isRunning&&Is&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0AD4C4] status-breathe"})]}),Ae.isRunning&&e.jsxs("div",{className:"autopilot-rail autopilot-rail-pulse flex items-center gap-2 rounded-lg px-3 py-1.5 mt-1.5","data-state":(mn=Ae.run)!=null&&mn.lastError?"error":((pn=Ae.run)==null?void 0:pn.stopReason)==="blocked"?"blocked":"running",children:[e.jsxs("span",{className:"relative flex h-2 w-2 flex-shrink-0",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-[#0AD4C4] opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-[#0AD4C4]"})]}),e.jsx("span",{className:"text-micro font-semibold text-[#7AEDE5]",children:"Autopilot Active"}),((xn=Ae.run)==null?void 0:xn.tokensUsed)!=null&&((hn=Ae.run)==null?void 0:hn.tokenBudget)!=null&&Ae.run.tokenBudget>0&&e.jsxs("span",{className:"text-micro text-[#7AEDE5]/60 tabular-nums",children:[Math.round(Ae.run.tokensUsed/Ae.run.tokenBudget*100),"% budget"]})]}),Q&&e.jsxs("a",{href:ur,target:"_blank",rel:"noreferrer noopener",onClick:()=>{try{_r("live_install_cta_click",{surface:"mission_control",embedMode:!0,initiativeId:(Z==null?void 0:Z.id)??null})}catch{}},className:"control-pill flex items-center gap-1.5 px-3 text-caption font-semibold","data-tone":"amber",title:"Install OrgX for OpenClaw",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 3v12"}),e.jsx("path",{d:"M8 11l4 4 4-4"}),e.jsx("path",{d:"M5 21h14"})]}),e.jsx("span",{children:"Install OrgX"})]}),z.length>0&&e.jsx("button",{type:"button",onClick:()=>{me?(Fs(),R(),ye&&kt.length>0&&pe(new Set)):(lr(z.map(m=>m.id)),ye&&kt.length>0&&pe(new Set(kt)))},title:me?"Collapse all":"Expand all","aria-busy":Ce&&!me,className:"control-pill flex h-8 w-8 flex-shrink-0 items-center justify-center text-secondary",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:me?e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 14h16"}),e.jsx("path",{d:"M4 10h16"})]}):e.jsxs(e.Fragment,{children:[e.jsx("path",{d:"M4 12h16"}),e.jsx("path",{d:"M12 4v16"})]})})})]})]})]}),ke.length>0&&e.jsxs("div",{"data-mc-selection-bar":"true",className:`mt-3 relative grid overflow-hidden rounded-xl border xl:grid-cols-[minmax(0,1fr)_560px] xl:gap-0 xl:items-center ${Fe>0?"border-[#BFFF00]/14 bg-[#0A0E15]/72":"border-white/[0.10] bg-[#0A0E15]/66"}`,children:[Fe>0&&e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 top-0 h-px",style:{background:"linear-gradient(90deg, rgba(191,255,0,0.22), rgba(10,212,196,0.16), transparent 72%)"}}),e.jsx("div",{className:`min-w-0 px-3 py-2 transition-[padding,min-height] duration-200 ease-out xl:flex ${Fe>0?"xl:min-h-[92px] xl:items-start":"xl:min-h-[70px] xl:items-center"}`,children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-caption text-primary",children:[e.jsx("input",{type:"checkbox",checked:_e,onChange:tr,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"}),"Select page"]}),e.jsx("span",{className:"flex-shrink-0 text-caption text-white/58",children:Fe>0?`${Fe} selected`:rt===0?"0 visible":`${E}-${A} of ${rt}`}),Fe>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{cs("active")},disabled:be,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45","data-state":"active",children:"Mark active"}),e.jsx("button",{type:"button",onClick:()=>{cs("paused")},disabled:be,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Pause"}),e.jsx("button",{type:"button",onClick:()=>{cs("blocked")},disabled:be,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{cs("completed")},disabled:be,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Complete"}),wt?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{or()},disabled:be,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-caption font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>Ye(!1),disabled:be,className:"control-pill h-8 flex-shrink-0 px-2.5 text-caption disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>Ye(!0),disabled:be,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-caption font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:sr,disabled:be,className:"text-caption text-secondary transition-colors hover:text-primary disabled:opacity-45",children:"Clear"})]})]})}),e.jsx(pt,{initial:!1,mode:"popLayout",children:!fe&&!Re&&e.jsxs(ge.div,{layout:"position",layoutId:Bs,initial:{opacity:0,y:4},animate:{opacity:1,y:0,...jr},exit:{opacity:0,y:-4},transition:{layout:Ls,duration:.2,ease:[.22,1,.36,1]},className:"flex w-full min-w-0 flex-col gap-2 overflow-hidden rounded-xl border border-strong px-2.5 py-2 shadow-[0_10px_24px_rgba(0,0,0,0.22)] backdrop-blur-[10px] sm:flex-row sm:items-center xl:h-full xl:rounded-none xl:border-b-0 xl:border-l xl:border-r-0 xl:border-t-0 xl:border-white/[0.10] xl:bg-transparent xl:px-3 xl:py-2 xl:shadow-none xl:backdrop-blur-none",children:[e.jsxs("div",{className:"flex min-w-0 w-full flex-1 items-center gap-2.5",children:[xe.isLoading?e.jsx(yt,{className:"h-6 w-6 rounded-full"}):Tt?e.jsx(Vn,{name:Tt.runnerAgentName,hint:`${Tt.runnerAgentId} ${Tt.runnerSource}`,size:"xs"}):e.jsx("div",{className:"h-6 w-6 rounded-full border border-strong bg-white/[0.05]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-white/76",children:"Now Working"}),xe.isLoading?e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-strong bg-white/[0.04] px-1.5 py-[1px] text-micro uppercase tracking-[0.07em] text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70 status-breathe"}),"Syncing"]}):e.jsx("span",{className:`rounded-full border px-1.5 py-[1px] text-micro uppercase tracking-[0.07em] ${vr}`,children:wr})]}),xe.isLoading?e.jsxs("div",{className:"mt-1.5 space-y-1",children:[e.jsx(yt,{className:"h-3 w-56 rounded"}),e.jsx(yt,{className:"h-3 w-44 rounded"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"truncate text-body font-semibold leading-snug text-bright",title:on,children:on}),e.jsxs("p",{className:"truncate text-caption leading-snug text-secondary",title:Ts,children:[yr,Ts?` · ${Ts}`:""]}),e.jsxs("p",{className:"hidden truncate text-micro leading-snug text-secondary/85 sm:block",title:ln,children:["Up next: ",ln,cn?` · ${cn}`:""]})]})]})]}),e.jsxs("div",{className:"ml-auto flex w-full flex-wrap items-center justify-end gap-2 sm:w-auto",children:[e.jsx("button",{type:"button",onClick:()=>{const m=Ee??le;if(O){hr();return}if(m){Bt("start",()=>xe.playWorkstream({initiativeId:m.initiativeId,workstreamId:m.workstreamId,agentId:m.runnerAgentId}),`Started ${m.workstreamTitle}.`);return}nn()},disabled:us||Je==="start"||Je==="pause",className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",title:O?`Pause ${O.workstreamTitle}`:"Start next workstream",children:O?"Pause":"Start"}),e.jsx("button",{type:"button",onClick:()=>void fr(),disabled:!O||Je==="defer"||us,className:"control-pill hidden h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45 sm:inline-flex",title:"Send current workstream to the bottom of queue",children:"Defer"}),e.jsx("button",{type:"button",onClick:()=>void gr(),disabled:!Gt||Je==="auto"||us,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45","data-state":_s?"active":"idle","data-tone":"teal",title:_s?"Stop automatic continuation":"Continue automatically for this initiative",children:_s?"Auto on":"Auto"}),e.jsx("button",{type:"button",onClick:Ms,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold",title:"Open queue",children:"Open queue"})]})]},"next-up-inline-card")})]}),Qe&&e.jsxs("div",{role:"status","aria-live":"polite",className:"mt-2 flex items-start justify-between gap-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-white/72",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:`mt-[3px] h-1.5 w-1.5 flex-shrink-0 rounded-full ${Qe.tone==="success"?"bg-emerald-300/90":"bg-amber-300/90"}`}),e.jsx("span",{className:"min-w-0 leading-snug",children:Qe.message})]}),e.jsx("button",{type:"button",onClick:()=>We(null),className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary","aria-label":"Dismiss notice",title:"Dismiss",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]}),e.jsxs(ge.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},className:`mt-3 grid gap-4 pb-8 ${fe?"xl:grid-cols-[minmax(0,1fr)_320px] xl:gap-0":"grid-cols-1"}`,children:[e.jsxs(ge.div,{layout:!0,className:`min-w-0 ${fe?"xl:pr-4":""}`,children:[!n&&Z&&e.jsxs(ge.div,{initial:{opacity:0,y:6,scale:.995},animate:{opacity:1,y:0,scale:1},transition:{type:"spring",stiffness:280,damping:30},className:"surface-tier-2 relative mb-3.5 overflow-hidden rounded-2xl p-4",children:[e.jsx("div",{"aria-hidden":!0,className:"absolute inset-x-0 top-0 h-px",style:{background:"linear-gradient(90deg, rgba(191,255,0,0.14), rgba(10,212,196,0.12), transparent 72%)"}}),e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-[240px]",children:[e.jsx("p",{className:"section-kicker",children:"Current context"}),e.jsx("p",{className:"mt-1 text-heading font-semibold leading-snug tracking-tight text-bright",children:$s.headline}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:$s.detail}),St&&e.jsx("div",{className:`mt-2 inline-flex max-w-[520px] items-center gap-1 rounded-full border px-2.5 py-1 text-micro ${St.tone==="success"?"border-emerald-400/24 bg-emerald-500/[0.1] text-emerald-100":"border-amber-400/24 bg-amber-500/[0.1] text-amber-100"}`,children:St.message})]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center gap-2.5 xl:self-end",children:[Ke==="startable"?e.jsx("button",{type:"button",onClick:xr,disabled:us,className:"control-pill h-9 px-4 text-body font-semibold disabled:opacity-45","data-state":"active",children:"Start initiative"}):e.jsx("button",{type:"button",onClick:nn,className:"control-pill h-9 px-4 text-body font-semibold","data-state":Ke==="blocked"?"active":"idle",children:br}),e.jsx("button",{type:"button",onClick:Ms,className:"control-pill h-9 px-4 text-body font-semibold",children:fe?"Hide Queue":"Open Queue"})]})]})]}),n?e.jsx("div",{className:"space-y-3 pb-8",children:Array.from({length:4}).map((m,D)=>e.jsxs("div",{className:"bg-[--orgx-surface] border border-[--orgx-border] soft-shadow rounded-2xl p-4",children:[e.jsx(yt,{className:"h-4 w-2/5 rounded"}),e.jsx(yt,{className:"h-1 w-full rounded mt-3"})]},`mc-skeleton-${D}`))}):t.length===0?b?o==="disconnected"||h?e.jsx("div",{className:"pb-8",children:e.jsx(Os,{mode:"degraded",detail:sn,onCreateInitiative:F,onPlayNextUp:M,onStartAutopilot:N,onRefresh:x,onOpenSettings:j})}):e.jsx("div",{className:"pb-8",children:e.jsx(Os,{mode:"empty",onCreateInitiative:F,onPlayNextUp:M,onStartAutopilot:N,onRefresh:x})}):e.jsx("div",{className:"pb-8",children:e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-6 py-8 text-center",children:[e.jsx("div",{className:"text-heading font-semibold text-bright",children:"Connect OrgX to get started"}),e.jsx("div",{className:"mt-1 text-body text-secondary",children:"Mission Control shows your initiative hierarchy once a user-scoped API key is configured."}),j&&e.jsx("div",{className:"mt-4 flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:j,className:"h-10 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-4 text-body font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/20",children:"Open settings"})})]})}):ke.length===0?e.jsx("div",{className:"pb-8",children:e.jsx(Os,{mode:"filtered",hasActiveFilters:H,onClearFilters:H?v:void 0,onCreateInitiative:F,onPlayNextUp:M,onStartAutopilot:N,onRefresh:x})}):ye?e.jsx("div",{className:"space-y-4 pb-8",children:ye.map(m=>{const D=qt(S,m.key),B=ni(D),K=V.has(D);return e.jsxs(ge.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},children:[e.jsxs("button",{type:"button","aria-expanded":K,"aria-controls":B,onClick:()=>_(D),className:"mb-2 flex w-full items-center gap-2 rounded-xl border border-white/[0.075] bg-white/[0.016] px-3 py-2.5 text-left transition-colors hover:border-strong hover:bg-white/[0.04]",children:[e.jsx("span",{"aria-hidden":!0,className:`inline-flex h-5 w-5 items-center justify-center rounded-md border border-strong bg-white/[0.04] text-caption text-secondary transition-transform ${K?"rotate-90":""}`,children:"▶"}),e.jsx("span",{className:"text-body font-semibold text-primary",children:m.label}),e.jsx("span",{className:"rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro text-secondary",children:m.count}),e.jsx("span",{className:"ml-auto text-micro uppercase tracking-[0.08em] text-secondary",children:K?"Hide":"Show"})]}),e.jsx(pt,{initial:!1,children:K&&e.jsx(ge.div,{id:B,initial:{opacity:0,y:-4},animate:{opacity:1,y:0},exit:{opacity:0,y:-4},transition:{duration:.2,ease:[.22,1,.36,1]},children:e.jsx("div",{className:"pt-0.5",children:e.jsx(Nn,{initiatives:m.initiatives,selectedInitiativeIds:et,onToggleInitiativeSelection:Xs,isSquished:fe,runtimeActivityByInitiativeId:it})})})})]},m.key)})}):e.jsx("div",{className:"pb-8",children:e.jsx(Nn,{initiatives:z,selectedInitiativeIds:et,onToggleInitiativeSelection:Xs,isSquished:fe,runtimeActivityByInitiativeId:it})}),ke.length>0&&e.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center justify-between gap-2 rounded-xl border border-white/[0.08] bg-white/[0.02] px-3 py-2",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2 text-caption text-white/70",children:[e.jsxs("span",{className:"font-medium text-white/80",children:["Showing ",E,"-",A]}),e.jsx("span",{className:"text-white/50",children:"of"}),e.jsx("span",{className:"font-medium text-white/80",children:rt}),e.jsx("span",{className:"text-white/50",children:"initiatives"})]}),e.jsxs("div",{className:"ml-auto flex flex-wrap items-center justify-end gap-2",children:[e.jsxs("label",{className:"inline-flex items-center gap-1.5 rounded-lg border border-white/[0.08] bg-black/25 px-2 py-1 text-micro text-white/68",children:[e.jsx("span",{children:"Per page"}),e.jsx("select",{value:st,onChange:m=>{const D=Number.parseInt(m.target.value,10);Number.isFinite(D)&&Ut(D)},className:"h-6 rounded-md border border-transparent bg-transparent px-1 text-caption text-white/90 outline-none",children:oi.map(m=>e.jsx("option",{value:m,children:m},m))})]}),e.jsxs("div",{className:"inline-flex items-center gap-1 rounded-lg border border-white/[0.08] bg-black/25 p-1",children:[e.jsx("button",{type:"button",onClick:nr,disabled:!Zs,className:"control-pill h-7 px-2 text-micro font-semibold disabled:opacity-40",title:"First page",children:"«"}),e.jsx("button",{type:"button",onClick:rr,disabled:!Zs,className:"control-pill h-7 px-2 text-micro font-semibold disabled:opacity-40",title:"Previous page",children:"‹"}),e.jsxs("span",{className:"px-1.5 text-micro text-white/64",children:["Page ",at+1," / ",Xe]}),e.jsx("button",{type:"button",onClick:ar,disabled:!en,className:"control-pill h-7 px-2 text-micro font-semibold disabled:opacity-40",title:"Next page",children:"›"}),e.jsx("button",{type:"button",onClick:ir,disabled:!en,className:"control-pill h-7 px-2 text-micro font-semibold disabled:opacity-40",title:"Last page",children:"»"})]})]})]})]}),e.jsx(pt,{initial:!1,children:fe&&e.jsx(ge.aside,{layout:!0,initial:{opacity:0,x:14},animate:{opacity:1,x:0},exit:{opacity:0,x:14},transition:{duration:.2,ease:[.22,1,.36,1]},className:"hidden xl:block",children:e.jsx("div",{className:"sticky",style:{top:"calc(var(--mc-toolbar-offset) + 12px)"},children:e.jsx(ge.div,{layout:"position",layoutId:Bs,initial:{borderRadius:12},animate:{borderRadius:16,...dn},transition:{layout:Ls,type:"spring",stiffness:340,damping:38,mass:.72},className:"origin-top-right flex h-[calc(100vh-var(--mc-toolbar-offset)-24px)] min-h-0 flex-col overflow-hidden rounded-2xl border shadow-[0_18px_40px_rgba(0,0,0,0.42)] backdrop-blur-[12px] xl:rounded-l-none",children:e.jsxs("div",{className:"relative flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-strong px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>ht("next-up"),className:`control-pill h-7 px-2 text-micro font-semibold ${Me==="next-up"?"border-[#BFFF00]/34 bg-[#BFFF00]/[0.12] text-[#E8FFD0]":"text-secondary"}`,children:["Next Up",e.jsx("span",{className:"ml-1 rounded-full border border-white/[0.16] bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold tabular-nums text-white/80",children:Cs})]}),e.jsx("button",{type:"button",onClick:()=>ht("slices"),className:`control-pill h-7 px-2 text-micro font-semibold ${Me==="slices"?"border-teal-300/34 bg-teal-400/[0.12] text-teal-100":"text-secondary"}`,children:"Slices"}),Me==="next-up"&&Qt>0?e.jsxs("span",{className:"chip ml-1 whitespace-nowrap text-micro text-secondary",children:[Qt," active elsewhere"]}):null,Me==="next-up"?e.jsx("span",{className:`ml-auto text-micro text-muted transition-opacity ${ts?"opacity-100":"opacity-0"}`,"aria-live":"polite",children:"refreshing…"}):e.jsx("span",{className:"ml-auto"})]}),e.jsx("div",{className:"min-h-0 flex-1",children:Me==="next-up"?e.jsx(yn,{title:"Next Up",showHeader:!1,panelStyle:"flat",className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,projectId:r,authToken:I,embedMode:Q,queueModel:xe,queueActions:mt,snapshotVersion:u,onOpenInitiative:At,onOpenSettings:j,onUpgradeGate:Ht}):e.jsx(On,{title:"Slice Explorer",className:"h-full !rounded-none !border-0 !bg-transparent",workspaceId:r,authToken:I,embedMode:Q,compact:!0,onOpenInitiative:(m,D)=>{At(m,D)}})}),e.jsx("button",{type:"button",onClick:Ms,className:"control-pill absolute right-3 top-3 z-20 h-7 px-2 text-micro font-semibold",title:"Collapse Next Up rail",children:"Hide"})]})})})})})]})]}),e.jsx(pt,{children:Re&&e.jsxs(e.Fragment,{children:[e.jsx(ge.button,{type:"button","aria-label":"Close next up panel",onClick:()=>Ne(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed bottom-0 left-0 right-0 top-[64px] z-[240] bg-black/45 xl:hidden"},"next-up-backdrop"),e.jsx(ge.aside,{initial:{x:"100%",opacity:.85},animate:{x:0,opacity:1},exit:{x:"100%",opacity:.9},transition:{type:"spring",stiffness:320,damping:34},className:"fixed inset-x-0 bottom-0 top-[60vh] z-[250] p-2 sm:top-[64px] sm:left-auto sm:right-0 sm:w-[min(84vw,360px)] sm:p-3 lg:w-[360px] lg:max-w-[94vw] xl:hidden",children:e.jsxs("div",{className:"relative flex h-full flex-col",children:[e.jsx("button",{type:"button",onClick:()=>Ne(!1),className:"absolute right-2 top-3 z-20 inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-[#080d14]/85 text-white/72 transition-colors hover:text-white","aria-label":"Close next up drawer",children:"✕"}),e.jsx(ge.div,{layout:"position",layoutId:Bs,initial:{borderRadius:12},animate:{borderRadius:16,...dn},transition:{layout:Ls,type:"spring",stiffness:340,damping:38,mass:.72},className:"h-full overflow-hidden rounded-2xl border shadow-[0_18px_40px_rgba(0,0,0,0.42)] backdrop-blur-[12px]",children:e.jsxs("div",{className:"flex h-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center gap-1 border-b border-strong px-3 py-2",children:[e.jsxs("button",{type:"button",onClick:()=>ht("next-up"),className:`control-pill h-7 px-2 text-micro font-semibold ${Me==="next-up"?"border-[#BFFF00]/34 bg-[#BFFF00]/[0.12] text-[#E8FFD0]":"text-secondary"}`,children:["Next Up",e.jsx("span",{className:"ml-1 rounded-full border border-white/[0.16] bg-white/[0.06] px-1.5 py-0.5 text-[10px] font-semibold tabular-nums text-white/80",children:Cs})]}),e.jsx("button",{type:"button",onClick:()=>ht("slices"),className:`control-pill h-7 px-2 text-micro font-semibold ${Me==="slices"?"border-teal-300/34 bg-teal-400/[0.12] text-teal-100":"text-secondary"}`,children:"Slices"}),Me==="next-up"&&Qt>0?e.jsxs("span",{className:"chip ml-1 whitespace-nowrap text-micro text-secondary",children:[Qt," active elsewhere"]}):null,Me==="next-up"?e.jsx("span",{className:`ml-auto text-micro text-muted transition-opacity ${ts?"opacity-100":"opacity-0"}`,"aria-live":"polite",children:"refreshing…"}):e.jsx("span",{className:"ml-auto"})]}),e.jsx("div",{className:"min-h-0 flex-1",children:Me==="next-up"?e.jsx(yn,{title:"Next Up",showHeader:!1,panelStyle:"flat",className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,projectId:r,authToken:I,embedMode:Q,queueModel:xe,queueActions:mt,snapshotVersion:u,onOpenInitiative:(m,D)=>{At(m,D),Ne(!1)},onOpenSettings:j,onUpgradeGate:Ht}):e.jsx(On,{title:"Slice Explorer",className:"h-full !rounded-none !border-0 !bg-transparent",workspaceId:r,authToken:I,embedMode:Q,compact:!0,onOpenInitiative:(m,D)=>{At(m,D),Ne(!1)}})})]})})]})},"next-up-drawer")]})})]})})]}),e.jsx(Oa,{target:kr,onClose:ie})]})}export{yi as MissionControlView};