@useorgx/openclaw-plugin 0.4.0 → 0.4.3

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 (105) hide show
  1. package/README.md +4 -0
  2. package/dashboard/dist/assets/BqukHQH-.js +8 -0
  3. package/dashboard/dist/assets/{motion-x9c01cgK.js → CE5pVdev.js} +1 -1
  4. package/dashboard/dist/assets/Cpr7n8fE.js +1 -0
  5. package/dashboard/dist/assets/Nip3CrNC.js +1 -0
  6. package/dashboard/dist/assets/TN5wE36J.js +1 -0
  7. package/dashboard/dist/assets/X6IcjS74.js +212 -0
  8. package/dashboard/dist/assets/jyFhCND-.css +1 -0
  9. package/dashboard/dist/index.html +9 -6
  10. package/dist/adapters/outbox.d.ts +0 -1
  11. package/dist/adapters/outbox.js +0 -1
  12. package/dist/agent-context-store.d.ts +0 -1
  13. package/dist/agent-context-store.js +0 -1
  14. package/dist/agent-run-store.d.ts +0 -1
  15. package/dist/agent-run-store.js +0 -1
  16. package/dist/api.d.ts +0 -1
  17. package/dist/api.js +0 -1
  18. package/dist/auth-store.d.ts +0 -1
  19. package/dist/auth-store.js +0 -1
  20. package/dist/byok-store.d.ts +0 -1
  21. package/dist/byok-store.js +181 -55
  22. package/dist/contracts/client.d.ts +0 -1
  23. package/dist/contracts/client.js +0 -1
  24. package/dist/contracts/types.d.ts +0 -1
  25. package/dist/contracts/types.js +0 -1
  26. package/dist/dashboard-api.d.ts +0 -1
  27. package/dist/dashboard-api.js +0 -1
  28. package/dist/fs-utils.d.ts +0 -1
  29. package/dist/fs-utils.js +0 -1
  30. package/dist/gateway-watchdog-runner.d.ts +1 -0
  31. package/dist/gateway-watchdog-runner.js +6 -0
  32. package/dist/gateway-watchdog.d.ts +11 -0
  33. package/dist/gateway-watchdog.js +221 -0
  34. package/dist/http-handler.d.ts +0 -1
  35. package/dist/http-handler.js +729 -79
  36. package/dist/index.d.ts +0 -1
  37. package/dist/index.js +7 -1
  38. package/dist/local-openclaw.d.ts +0 -1
  39. package/dist/local-openclaw.js +0 -1
  40. package/dist/openclaw-settings.d.ts +17 -0
  41. package/dist/openclaw-settings.js +118 -0
  42. package/dist/outbox.d.ts +0 -1
  43. package/dist/outbox.js +0 -1
  44. package/dist/paths.d.ts +0 -1
  45. package/dist/paths.js +0 -1
  46. package/dist/reporting/outbox-replay.d.ts +0 -1
  47. package/dist/reporting/outbox-replay.js +0 -1
  48. package/dist/reporting/rollups.d.ts +0 -1
  49. package/dist/reporting/rollups.js +0 -1
  50. package/dist/runtime-instance-store.d.ts +0 -1
  51. package/dist/runtime-instance-store.js +0 -1
  52. package/dist/snapshot-store.d.ts +0 -1
  53. package/dist/snapshot-store.js +0 -1
  54. package/dist/types.d.ts +0 -1
  55. package/dist/types.js +0 -1
  56. package/package.json +2 -2
  57. package/dashboard/dist/assets/MissionControlView-DVNfDWKZ.js +0 -1
  58. package/dashboard/dist/assets/SessionInspector-BaqnAys4.js +0 -1
  59. package/dashboard/dist/assets/index-B4Yix84X.js +0 -212
  60. package/dashboard/dist/assets/index-BWSvw1HR.css +0 -1
  61. package/dashboard/dist/assets/react-vendor-C2t2w4r2.js +0 -32
  62. package/dashboard/dist/assets/vendor-C-AHK0Ly.js +0 -9
  63. package/dist/adapters/outbox.d.ts.map +0 -1
  64. package/dist/adapters/outbox.js.map +0 -1
  65. package/dist/agent-context-store.d.ts.map +0 -1
  66. package/dist/agent-context-store.js.map +0 -1
  67. package/dist/agent-run-store.d.ts.map +0 -1
  68. package/dist/agent-run-store.js.map +0 -1
  69. package/dist/api.d.ts.map +0 -1
  70. package/dist/api.js.map +0 -1
  71. package/dist/auth-store.d.ts.map +0 -1
  72. package/dist/auth-store.js.map +0 -1
  73. package/dist/byok-store.d.ts.map +0 -1
  74. package/dist/byok-store.js.map +0 -1
  75. package/dist/contracts/client.d.ts.map +0 -1
  76. package/dist/contracts/client.js.map +0 -1
  77. package/dist/contracts/types.d.ts.map +0 -1
  78. package/dist/contracts/types.js.map +0 -1
  79. package/dist/dashboard-api.d.ts.map +0 -1
  80. package/dist/dashboard-api.js.map +0 -1
  81. package/dist/fs-utils.d.ts.map +0 -1
  82. package/dist/fs-utils.js.map +0 -1
  83. package/dist/http-handler.d.ts.map +0 -1
  84. package/dist/http-handler.js.map +0 -1
  85. package/dist/index.d.ts.map +0 -1
  86. package/dist/index.js.map +0 -1
  87. package/dist/local-openclaw.d.ts.map +0 -1
  88. package/dist/local-openclaw.js.map +0 -1
  89. package/dist/mcp-apps/orgx-live.html +0 -690
  90. package/dist/outbox.d.ts.map +0 -1
  91. package/dist/outbox.js.map +0 -1
  92. package/dist/paths.d.ts.map +0 -1
  93. package/dist/paths.js.map +0 -1
  94. package/dist/reporting/outbox-replay.d.ts.map +0 -1
  95. package/dist/reporting/outbox-replay.js.map +0 -1
  96. package/dist/reporting/rollups.d.ts.map +0 -1
  97. package/dist/reporting/rollups.js.map +0 -1
  98. package/dist/runtime-instance-store.d.ts.map +0 -1
  99. package/dist/runtime-instance-store.js.map +0 -1
  100. package/dist/snapshot-store.d.ts.map +0 -1
  101. package/dist/snapshot-store.js.map +0 -1
  102. package/dist/types.d.ts.map +0 -1
  103. package/dist/types.js.map +0 -1
  104. /package/dashboard/dist/assets/{tanstack-C-KIc3Wc.js → C-KIc3Wc.js} +0 -0
  105. /package/dashboard/dist/assets/{orgx-logo-Fm0FhtnV.png → Fm0FhtnV.png} +0 -0
@@ -1 +0,0 @@
1
- import{r as n,u as ps,b as xs,c as Ye,j as e}from"./react-vendor-C2t2w4r2.js";import{q as bt,b as wt,c as Ds,a as O,A as zt,d as Es,E as Pe,u as Nt,P as As,M as Bs,e as Ms,f as Is,N as Xt}from"./index-B4Yix84X.js";import{A as Le,m as le,L as $s}from"./motion-x9c01cgK.js";import"./tanstack-C-KIc3Wc.js";import"./vendor-C-AHK0Ly.js";function _s({activities:t,agents:s,initiatives:r}){return n.useMemo(()=>{const x=new Map,o=(h,i,j,y)=>{const F=x.get(h)??[];F.some(d=>d.id===i)||(F.push({id:i,name:j,confidence:y}),x.set(h,F))};return t.forEach(h=>{const i="metadata"in h&&h.metadata&&typeof h.metadata=="object"?h.metadata:null,j=i&&typeof i=="object"?i:{},y=("initiativeId"in h&&typeof h.initiativeId=="string"?h.initiativeId:void 0)??j.initiativeId??void 0,F=h.agentId??void 0,d=("agentName"in h&&typeof h.agentName=="string"?h.agentName:"agent"in h&&typeof h.agent=="string"?h.agent:void 0)??F??"Unknown";y&&F&&o(y,F,d,"high")}),r.forEach(h=>{var i;(i=h.avatars)!=null&&i.length&&h.avatars.forEach(j=>{const y=s.find(F=>F.name.toLowerCase()===j.toLowerCase());y?o(h.id,y.id,y.name,"medium"):o(h.id,`avatar:${j}`,j,"medium")})}),s.forEach(h=>{if(!h.task)return;const i=h.task.toLowerCase();r.forEach(j=>{j.name.toLowerCase().split(/\s+/).filter(M=>M.length>3).some(M=>i.includes(M))&&o(j.id,h.id,h.name,"low")})}),x},[t,s,r])}function Ts({initiativeId:t=null,authToken:s=null,embedMode:r=!1,enabled:x=!0}){var _,m,l;const o=ps(),h=n.useMemo(()=>bt.autoContinueStatus({initiativeId:t??"__global__",authToken:s,embedMode:r}),[t,s,r]),i=xs({queryKey:h,enabled:x&&(!!t||t===null),queryFn:async()=>{const g=new URLSearchParams;t&&g.set("initiative_id",t);const b=await fetch(`/orgx/api/mission-control/auto-continue/status?${g.toString()}`,{headers:wt({authToken:s,embedMode:r})}),u=await b.json().catch(()=>null);if(!b.ok){const C=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to load auto-continue status (${b.status})`;return{ok:!1,initiativeId:t,run:null,defaults:{tokenBudget:0,tickMs:0},error:C}}return u},refetchInterval:g=>{var v,B;const b=g.state.data;if((b==null?void 0:b.ok)===!1)return!1;const u=((v=b==null?void 0:b.error)==null?void 0:v.toLowerCase())??"";if(u.includes("404")||u.includes("400")||u.includes("not found")||u.includes("bad request"))return!1;const p=((B=b==null?void 0:b.run)==null?void 0:B.status)??null;return p==="running"||p==="stopping"?2500:12e3}}),j=async()=>{await o.invalidateQueries({queryKey:h}),await o.invalidateQueries({queryKey:bt.missionControlGraph({initiativeId:t,authToken:s,embedMode:r})}),await o.invalidateQueries({queryKey:bt.liveData({authToken:s,embedMode:r})})},y=Ye({mutationFn:async g=>{const b={};t&&(b.initiativeId=t),g&&typeof g=="object"&&(typeof g.tokenBudgetTokens=="number"&&(b.tokenBudgetTokens=g.tokenBudgetTokens),typeof g.agentId=="string"&&g.agentId.trim().length>0&&(b.agentId=g.agentId.trim()));const u=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:wt({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(b)}),C=await u.json().catch(()=>null);if(!u.ok){const p=typeof(C==null?void 0:C.error)=="string"&&C.error||typeof(C==null?void 0:C.message)=="string"&&C.message||`Failed to start auto-continue (${u.status})`;throw new Error(p)}if(C&&typeof C=="object"&&"run"in C){const p=i.data??null;return{ok:!0,initiativeId:t,run:C.run??null,defaults:(p==null?void 0:p.defaults)??{tokenBudget:0,tickMs:0}}}return C},onSuccess:()=>{j()}}),F=Ye({mutationFn:async()=>{const g={};t&&(g.initiativeId=t);const b=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:wt({authToken:s,embedMode:r,contentTypeJson:!0}),body:JSON.stringify(g)}),u=await b.json().catch(()=>null);if(!b.ok){const C=typeof(u==null?void 0:u.error)=="string"&&u.error||typeof(u==null?void 0:u.message)=="string"&&u.message||`Failed to stop auto-continue (${b.status})`;throw new Error(C)}if(u&&typeof u=="object"&&"run"in u){const C=i.data??null;return{ok:!0,initiativeId:t,run:u.run??null,defaults:(C==null?void 0:C.defaults)??{tokenBudget:0,tickMs:0}}}return u},onSuccess:()=>{j()}}),d=((_=i.data)==null?void 0:_.run)??null,M=(d==null?void 0:d.status)==="running"||(d==null?void 0:d.status)==="stopping";return{status:i.data??null,run:d,isRunning:M,isLoading:i.isLoading,error:((m=i.data)==null?void 0:m.error)??((l=i.error)==null?void 0:l.message)??null,start:y.mutateAsync,stop:F.mutateAsync,isStarting:y.isPending,isStopping:F.isPending,refetch:i.refetch}}function hs({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-white/35",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:x=>s(x.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-[13px] text-white placeholder:text-white/35 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-white/40 transition-colors hover:text-white/70","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"})})})]})}function ut({className:t=""}){return e.jsx("div",{className:Ds("shimmer-skeleton",t),"aria-hidden":"true"})}async function Je(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(r)}return t}function Ls(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 $t(t){const s=t.trim().toLowerCase();return s==="deleted"||s==="archived"||s==="cancelled"}function Ps(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 Rs(t){const s=ps(),r=wt({authToken:t.authToken,embedMode:t.embedMode,contentTypeJson:!0}),x=()=>{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"]})},o=(m,l)=>{s.setQueryData(["initiative-tombstones"],g=>{const b=Array.isArray(g)?g.filter(C=>typeof C=="string"):[],u=b.includes(m);return l?u?b:[...b,m]:u?b.filter(C=>C!==m):b})},h=(m,l)=>{const g=Ls(l),b=new Date().toISOString(),u=$t(l);o(m,u);const C=p=>{if(!Array.isArray(p))return p;if(u){const W=p.filter(X=>{if(!X||typeof X!="object")return!0;const K=X;return!(typeof K.id=="string"&&K.id===m)});return W.length===p.length?p:W}let v=!1;const B=p.map(W=>{if(!W||typeof W!="object")return W;const X=W;return typeof X.id!="string"||X.id!==m?W:(v=!0,{...X,status:g,rawStatus:l,updatedAt:b})});return v?B:p};s.setQueriesData({queryKey:["entities"]},C),s.setQueriesData({queryKey:["live-initiatives"]},C)},i=(m,l,g="status")=>{const b=Ps(l);s.setQueriesData({queryKey:["live-data"]},u=>{if(!u||typeof u!="object")return u;const C=u,p=C.sessions;if(!p||typeof p!="object")return u;const v=p,B=v.nodes;if(!Array.isArray(B))return u;let W=!1;const X=g==="delete"?B.filter(N=>{if(!N||typeof N!="object")return!0;const z=N,ne=(typeof z.initiativeId=="string"?z.initiativeId:null)===m;return ne&&(W=!0),!ne}):B.map(N=>{if(!N||typeof N!="object")return N;const z=N;return(typeof z.initiativeId=="string"?z.initiativeId:null)!==m||z.status===b?N:(W=!0,{...z,status:b})});if(!W)return u;const K=new Set,q=new Set;for(const N of X){if(!N||typeof N!="object")continue;const z=N;typeof z.id=="string"&&K.add(z.id),typeof z.groupId=="string"&&q.add(z.groupId)}const T=Array.isArray(v.edges)?v.edges.filter(N=>{if(!N||typeof N!="object")return!1;const z=N,U=typeof z.parentId=="string"?z.parentId:null,ne=typeof z.childId=="string"?z.childId:null;return U!==null&&ne!==null&&K.has(U)&&K.has(ne)}):v.edges,Q=Array.isArray(v.groups)?v.groups.filter(N=>{if(!N||typeof N!="object")return!1;const z=N;return typeof z.id=="string"&&q.has(z.id)}):v.groups;return{...C,sessions:{...v,nodes:X,edges:T,groups:Q}}})},j={start:"in_progress",complete:"done",block:"blocked",unblock:"in_progress",pause:"paused",resume:"active"},y=Ye({mutationFn:async m=>{const{type:l,...g}=m,b=await fetch("/orgx/api/entities",{method:"POST",headers:r,body:JSON.stringify({type:l,...g})});return await Je(b),b.json()},onSuccess:x}),F=Ye({mutationFn:async m=>{const{type:l,id:g,...b}=m,u=await fetch("/orgx/api/entities",{method:"PATCH",headers:r,body:JSON.stringify({type:l,id:g,...b})});return await Je(u),u.json()},onSuccess:(m,l)=>{l.type.trim().toLowerCase()==="initiative"&&typeof l.status=="string"&&l.status.trim().length>0&&(h(l.id,l.status),i(l.id,l.status,$t(l.status)?"delete":"status")),x()}}),d=Ye({mutationFn:async m=>{const l=await fetch(`/orgx/api/entities/${encodeURIComponent(m.type)}/${encodeURIComponent(m.id)}/delete`,{method:"POST",headers:r,body:"{}"});return await Je(l),l.json()},onSuccess:(m,l)=>{l.type.trim().toLowerCase()==="initiative"&&(h(l.id,"archived"),i(l.id,"archived","delete")),x()}}),M=Ye({mutationFn:async m=>{const l=await fetch(`/orgx/api/entities/${encodeURIComponent(m.type)}/${encodeURIComponent(m.id)}/${encodeURIComponent(m.action)}`,{method:"POST",headers:r,body:JSON.stringify({force:m.force??!1})});return await Je(l),l.json()},onSuccess:(m,l)=>{if(l.type.trim().toLowerCase()==="initiative"){const g=j[l.action.trim().toLowerCase()];g&&(h(l.id,g),i(l.id,g,"status"))}x()}}),_=Ye({mutationFn:async m=>{const l=Array.from(new Map((m.items??[]).filter(v=>typeof(v==null?void 0:v.type)=="string"&&v.type.trim().length>0&&typeof(v==null?void 0:v.id)=="string"&&v.id.trim().length>0).map(v=>[`${v.type}:${v.id}`,v])).values());if(l.length===0)return{updated:0,failed:0,errors:[]};if(m.mode==="action"&&!m.action)throw new Error("bulk action requires an action name");const g=async v=>{try{if(m.mode==="delete"){const W=await fetch(`/orgx/api/entities/${encodeURIComponent(v.type)}/${encodeURIComponent(v.id)}/delete`,{method:"POST",headers:r,body:"{}"});return await Je(W),{ok:!0}}if(m.mode==="update"){const W=await fetch("/orgx/api/entities",{method:"PATCH",headers:r,body:JSON.stringify({type:v.type,id:v.id,...m.updates??{}})});return await Je(W),{ok:!0}}const B=await fetch(`/orgx/api/entities/${encodeURIComponent(v.type)}/${encodeURIComponent(v.id)}/${encodeURIComponent(m.action)}`,{method:"POST",headers:r,body:JSON.stringify({force:m.force??!1})});return await Je(B),{ok:!0}}catch(B){return{ok:!1,error:B instanceof Error?B.message:"Unknown bulk mutation failure"}}},b=await Promise.all(l.map(v=>g(v)));let u=0,C=0;const p=[];for(const v of b)v.ok?u+=1:(C+=1,p.push(v.error));return{updated:u,failed:C,errors:p}},onSuccess:(m,l)=>{var b;const g=(l.items??[]).filter(u=>u.type.trim().toLowerCase()==="initiative");if(g.length>0){if(l.mode==="update"&&typeof((b=l.updates)==null?void 0:b.status)=="string"&&l.updates.status.trim().length>0)for(const u of g)h(u.id,l.updates.status),i(u.id,l.updates.status,$t(l.updates.status)?"delete":"status");else if(l.mode==="delete")for(const u of g)h(u.id,"archived"),i(u.id,"archived","delete");else if(l.mode==="action"&&l.action){const u=j[l.action.trim().toLowerCase()];if(u)for(const C of g)h(C.id,u),i(C.id,u,"status")}}x()}});return{createEntity:y,updateEntity:F,deleteEntity:d,entityAction:M,bulkEntityMutation:_}}const ms=n.createContext(null);function Ze(){const t=n.useContext(ms);if(!t)throw new Error("useMissionControl must be used within MissionControlProvider");return t}function zs({children:t,agentEntityMap:s,authToken:r,embedMode:x}){const[o,h]=n.useState(new Set),[i,j]=n.useState(null),[y,F]=n.useState(""),[d,M]=n.useState([]),[_,m]=n.useState("target"),[l,g]=n.useState("any"),[b,u]=n.useState(""),[C,p]=n.useState(""),[v,B]=n.useState("status"),[W,X]=n.useState("default"),K=Rs({authToken:r,embedMode:x}),q=n.useCallback(Z=>{h(E=>{const se=new Set(E);return se.has(Z)?se.delete(Z):se.add(Z),se})},[]),T=n.useCallback(Z=>{h(E=>{if(E.has(Z))return E;const se=new Set(E);return se.add(Z),se})},[]),Q=n.useCallback(Z=>{h(new Set(Z))},[]),N=n.useCallback(()=>{h(new Set)},[]),z=n.useCallback(Z=>{j(Z)},[]),U=n.useCallback(()=>{j(null)},[]),ne=n.useCallback(Z=>{const E=Array.from(new Set((Z??[]).map(se=>se.trim().toLowerCase()).filter(Boolean)));M(E)},[]),L=n.useCallback(Z=>{M(E=>{const se=Z.trim().toLowerCase();return se?E.includes(se)?E.filter(ge=>ge!==se):[...E,se]:E})},[]),Y=n.useCallback(()=>{F(""),M([]),m("target"),g("any"),u(""),p("")},[]),oe=b.trim().length>0||C.trim().length>0,c=l!=="any"&&(l!=="custom_range"||oe),te=d.length+(c?1:0),J=y.trim().length>0||te>0,G=n.useMemo(()=>({agentEntityMap:s,expandedInitiatives:o,modalTarget:i,searchQuery:y,statusFilters:d,dateField:_,datePreset:l,dateStart:b,dateEnd:C,activeFilterCount:te,hasActiveFilters:J,groupBy:v,sortBy:W,authToken:r,embedMode:x,mutations:K,toggleExpanded:q,expandInitiative:T,expandAll:Q,collapseAll:N,openModal:z,closeModal:U,setSearchQuery:F,setStatusFilters:ne,toggleStatusFilter:L,setDateField:m,setDatePreset:g,setDateStart:u,setDateEnd:p,setGroupBy:B,setSortBy:X,clearFilters:Y}),[s,o,i,y,d,_,l,b,C,te,J,v,W,r,x,K,q,T,Q,N,z,U,ne,L,m,g,u,p,B,X,Y]);return e.jsx(ms.Provider,{value:G,children:t})}const yt={active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",paused:"text-[#F5B700] bg-[#F5B700]/10 border-[#F5B700]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20"},Os={done:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",completed:"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20",in_progress:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",active:"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20",blocked:"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20",todo:"text-white/60 bg-white/5 border-white/10"},Ot=t=>Os[t.toLowerCase()]??"text-white/60 bg-white/5 border-white/10",fs=t=>{const s=t.toLowerCase();return s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":s==="blocked"?"text-[#FF6B88] bg-[#FF6B88]/10 border-[#FF6B88]/20":s==="completed"||s==="done"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":"text-white/60 bg-white/5 border-white/10"},gs=t=>{const s=t.toLowerCase();return s==="done"||s==="completed"?"text-[#14B8A6] bg-[#14B8A6]/10 border-[#14B8A6]/20":s==="active"||s==="in_progress"?"text-[#BFFF00] bg-[#BFFF00]/10 border-[#BFFF00]/20":"text-white/60 bg-white/5 border-white/10"},ke=t=>t.replace(/[_-]+/g," ").replace(/\s+/g," ").trim().replace(/\b\w/g,s=>s.toUpperCase()),jt=t=>{const s=t.toLowerCase();return s==="blocked"?0:s==="in_progress"||s==="active"?1:s==="todo"||s==="planned"?2:s==="done"||s==="completed"?3:4},Zt=t=>{const s=t.toLowerCase();return s==="blocked"?O.red:s==="active"||s==="in_progress"?O.lime:s==="done"||s==="completed"?O.teal:s==="paused"?O.amber:"rgba(255,255,255,0.35)"};function kt({agents:t,max:s=4}){if(!t.length)return null;const r=t.slice(0,s),x=t.length-s;return e.jsxs("div",{className:"inline-flex min-w-0 items-center justify-end -space-x-1.5 pl-1",children:[r.map(o=>e.jsx("div",{className:"relative flex-shrink-0",title:`${o.name} (${o.confidence} confidence)`,style:{borderRadius:"9999px",border:o.confidence==="high"?"1.5px solid rgba(255,255,255,0.25)":o.confidence==="medium"?"1.5px dashed rgba(255,255,255,0.15)":"1.5px dotted rgba(255,255,255,0.10)"},children:e.jsx(zt,{name:o.name,size:"xs"})},o.id)),x>0&&e.jsxs("span",{className:"ml-1 flex-shrink-0 text-[9px] text-white/40",children:["+",x]})]})}function _t(t){return{initiative:{id:t,title:"Initiative",status:"active",summary:null,assignedAgents:[]},nodes:[],edges:[],recentTodos:[]}}function qs({initiativeId:t,authToken:s=null,embedMode:r=!1,enabled:x=!0}){var y,F;const o=Es(t),h=n.useMemo(()=>bt.missionControlGraph({initiativeId:t,authToken:s,embedMode:r}),[t,s,r]),i=xs({queryKey:h,enabled:x&&!!t&&o,queryFn:async()=>{if(!t)throw new Error("initiativeId is required");if(!o)return _t(t);const d=new URLSearchParams({initiative_id:t}),M={};r&&(M["X-Orgx-Embed"]="true"),s&&(M.Authorization=`Bearer ${s}`);const _=Object.keys(M).length>0?M:void 0,m=await fetch(`/orgx/api/mission-control/graph?${d.toString()}`,{headers:_});if(!m.ok){const l=await m.json().catch(()=>null),g=typeof(l==null?void 0:l.error)=="string"&&l.error||typeof(l==null?void 0:l.message)=="string"&&l.message||`Failed to fetch Mission Control graph (${m.status})`;return console.warn(`[useMissionControlGraph] ${g}`),{..._t(t),degraded:[g]}}return await m.json()}});return{graph:i.data??(t?_t(t):null),isLoading:o?i.isLoading:!1,error:o?((y=i.error)==null?void 0:y.message)??null:null,degraded:o?((F=i.data)==null?void 0:F.degraded)??[]:[],refetch:i.refetch}}function vt({type:t,className:s=""}){return e.jsx(Pe,{type:t,className:s,size:14})}function Us(t){return t==="initiative"?"Initiatives":t==="workstream"?"Workstreams":t==="milestone"?"Milestones":"Tasks"}function Ws({nodes:t,edges:s,selectedNodeId:r,focusedWorkstreamId:x,onSelectNode:o}){const h=n.useMemo(()=>new Map(t.map(p=>[p.id,p])),[t]),[i,j]=n.useState(""),[y,F]=n.useState(!1),d=i.trim().toLowerCase(),M=n.useMemo(()=>{if(!x)return new Set(t.map(B=>B.id));const p=new Set;for(const B of t)(B.type==="initiative"||B.id===x||B.workstreamId===x)&&p.add(B.id);let v=!0;for(;v;){v=!1;for(const B of s)(p.has(B.from)||p.has(B.to))&&(!p.has(B.from)||!p.has(B.to))&&(p.add(B.from),p.add(B.to),v=!0)}return p},[x,t,s]),_=t.filter(p=>M.has(p.id)),m=s.filter(p=>M.has(p.from)&&M.has(p.to)),l=n.useMemo(()=>{if(!r)return new Set;const p=new Set([r]);for(const v of m)v.from===r&&p.add(v.to),v.to===r&&p.add(v.from);return p},[r,m]),g=n.useMemo(()=>{let p=new Set(Array.from(M));return y&&r&&(p=new Set(Array.from(p).filter(v=>l.has(v)))),d.length>0&&(p=new Set(Array.from(p).filter(v=>{const B=h.get(v);return B?B.title.toLowerCase().includes(d):!1}))),p},[h,d,l,y,r,M]),b=t.filter(p=>g.has(p.id)),u=s.filter(p=>g.has(p.from)&&g.has(p.to)),C={initiative:b.filter(p=>p.type==="initiative"),workstream:b.filter(p=>p.type==="workstream"),milestone:b.filter(p=>p.type==="milestone"),task:b.filter(p=>p.type==="task")};return _.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-[10px] uppercase tracking-[0.08em] text-white/42",children:[b.length," nodes · ",u.length," links"]}),x&&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:i,onChange:p=>j(p.target.value),placeholder:"Filter nodes...",className:"h-9 flex-1 min-w-[200px] rounded-lg border border-white/[0.12] bg-black/30 px-3 text-[11px] text-white/80 placeholder:text-white/25 transition-colors focus:border-[#BFFF00]/35 focus:outline-none"}),r&&e.jsx("button",{type:"button",onClick:()=>F(p=>!p),"aria-pressed":y,"data-state":y?"active":"idle",className:"control-pill px-3 text-[11px] font-semibold",title:"Show only the selected node and its direct neighbors",children:"Related only"}),(i.trim().length>0||y)&&e.jsx("button",{type:"button",onClick:()=>{j(""),F(!1)},className:"control-pill px-3 text-[11px]",children:"Reset"})]}),b.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-3 py-3 text-[11px] text-white/48",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(C).filter(p=>p.length>0).length<=2?"grid-cols-1 sm:grid-cols-2":"md:grid-cols-2 xl:grid-cols-4"}`,children:Object.keys(C).filter(p=>C[p].length>0).map(p=>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-[10px] uppercase tracking-[0.09em] text-white/45",children:[Us(p)," (",C[p].length,")"]}),e.jsxs("div",{className:"space-y-1",children:[C[p].slice(0,10).map(v=>{const B=r===v.id,W=!B&&l.has(v.id);return e.jsxs("button",{type:"button",onClick:()=>o(v.id),title:v.title,className:`flex w-full items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors ${B?"border-[#BFFF00]/35 bg-[#BFFF00]/12":W?"border-[#14B8A6]/35 bg-[#14B8A6]/12":"border-white/[0.12] bg-white/[0.03] hover:bg-white/[0.08]"}`,children:[e.jsx(vt,{type:v.type}),e.jsx("span",{className:"truncate text-[11px] text-white/80",children:v.title})]},v.id)}),C[p].length>10&&e.jsxs("div",{className:"px-1 text-[10px] text-white/35",children:["+",C[p].length-10," more"]})]})]},p))}),u.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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Dependency links"}),e.jsx("div",{className:"max-h-[110px] space-y-1 overflow-auto pr-1",children:u.slice(0,36).map(p=>{const v=h.get(p.from),B=h.get(p.to);if(!v||!B)return null;const W=r===v.id||r===B.id;return e.jsxs("button",{type:"button",onClick:()=>o(B.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:W?O.lime:"rgba(255,255,255,0.35)"}}),e.jsx("span",{className:"truncate text-[10px] text-white/70",children:v.title}),e.jsx("span",{className:"text-[10px] text-white/30",children:"→"}),e.jsx("span",{className:"truncate text-[10px] text-white/70",children:B.title})]},`${p.from}-${p.to}`)})})]})]})}function Hs(t){return t.trim().toLowerCase().replace(/[\s-]+/g,"_")}const Vs=new Set(["done","completed","complete","cancelled","canceled","archived","deleted"]);function Ae(t){return Vs.has(Hs(t))}function Ct(t){return Number.isFinite(t)?Math.max(0,Math.min(100,Math.round(t))):0}function Xe(t,s){return s<=0?0:Ct(t/s*100)}function Gs({dependencies:t,allNodes:s,disabled:r=!1,onSave:x}){const[o,h]=n.useState(!1),[i,j]=n.useState(""),[y,F]=n.useState(t),d=n.useMemo(()=>new Map(s.map(l=>[l.id,l])),[s]),M=n.useMemo(()=>{const l=i.trim().toLowerCase(),g=[...s].sort((b,u)=>b.title.localeCompare(u.title));return l?g.filter(b=>b.title.toLowerCase().includes(l)||b.id.toLowerCase().includes(l)).slice(0,16):g.slice(0,16)},[s,i]),_=()=>{x(Array.from(new Set(y))),h(!1)},m=l=>{F(g=>g.includes(l)?g.filter(b=>b!==l):[...g,l])};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",disabled:r,onClick:()=>{j(""),F(t),h(l=>!l)},className:"rounded-md border border-white/[0.12] bg-white/[0.04] px-2 py-1 text-[10px] text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-40",children:t.length>0?`${t.length} linked`:"Set links"}),o&&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-[10px] uppercase tracking-[0.08em] text-white/45",children:"Link dependencies"}),e.jsx("input",{value:i,onChange:l=>j(l.target.value),placeholder:"Search by title or id...",className:"mt-1.5 h-9 w-full rounded-md border border-white/[0.12] bg-black/25 px-2.5 text-[11px] text-white/85 outline-none transition-colors placeholder:text-white/35 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:y.length===0?e.jsx("span",{className:"text-[10px] text-white/40",children:"No links selected"}):y.map(l=>{var b;const g=((b=d.get(l))==null?void 0:b.title)??l;return e.jsxs("button",{type:"button",onClick:()=>m(l),className:"inline-flex items-center gap-1 rounded-full border border-white/[0.16] bg-white/[0.05] px-2 py-0.5 text-[10px] text-white/70 transition-colors hover:bg-white/[0.1]",title:g,children:[e.jsx("span",{className:"max-w-[180px] truncate",children:g}),e.jsx("span",{className:"text-white/45",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:M.length===0?e.jsx("div",{className:"px-1 text-[10px] text-white/40",children:"No matching nodes"}):M.map(l=>{const g=y.includes(l.id);return e.jsxs("button",{type:"button",onClick:()=>m(l.id),className:`flex w-full items-center justify-between rounded-md border px-2 py-1 text-left text-[10px] transition-colors ${g?"border-[#BFFF00]/32 bg-[#BFFF00]/12 text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03] text-white/70 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-white/40",children:[l.id.slice(0,8),"…"]})]}),e.jsx("span",{className:"font-semibold",children:g?"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:()=>h(!1),className:"rounded-md border border-white/[0.12] px-2 py-1 text-[10px] text-white/60 transition-colors hover:bg-white/[0.08]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:_,className:"rounded-md border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2 py-1 text-[10px] text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/22",children:"Save links"})]})]})]})}function Ks(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const r=s.getFullYear(),x=String(s.getMonth()+1).padStart(2,"0"),o=String(s.getDate()).padStart(2,"0"),h=String(s.getHours()).padStart(2,"0"),i=String(s.getMinutes()).padStart(2,"0");return`${r}-${x}-${o}T${h}:${i}`}const es=["not_started","planned","todo","in_progress","active","blocked","done"];function Qs(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 ht(t){const s=t.trim().toLowerCase();return s==="completed"?"done":s==="running"||s==="queued"?"active":s==="pending"||s==="backlog"?"todo":s}function Js(t,s){return s==="all"?!0:s==="blocked"?t==="blocked":s==="done"?t==="done":t!=="blocked"&&t!=="done"}function Ys(t,s){const r=new Map(s.map(h=>[h.id,h])),x=new Set,o=[t];for(;o.length>0;){const h=o.shift(),i=r.get(h);i&&(i.parentId&&!x.has(i.parentId)&&(x.add(i.parentId),o.push(i.parentId)),i.workstreamId&&!x.has(i.workstreamId)&&(x.add(i.workstreamId),o.push(i.workstreamId)),i.milestoneId&&!x.has(i.milestoneId)&&(x.add(i.milestoneId),o.push(i.milestoneId)))}return x}function Xs(t,s,r,x){let o=0;if(r==="title")o=t.title.localeCompare(s.title);else if(r==="status")o=jt(t.status)-jt(s.status);else if(r==="priority")o=t.priorityNum-s.priorityNum;else if(r==="eta"){const h=t.etaEndAt?Date.parse(t.etaEndAt):1/0,i=s.etaEndAt?Date.parse(s.etaEndAt):1/0;o=h-i}return x==="desc"?-o:o}function Zs({nodes:t,edges:s,selectedNodeId:r,highlightedNodeIds:x,editMode:o,onToggleEditMode:h,onSelectNode:i,onFocusWorkstream:j,onOpenNode:y,onUpdateNode:F,mutations:d}){const[M,_]=n.useState(""),[m,l]=n.useState(new Set),[g,b]=n.useState("all"),[u,C]=n.useState(!1),[p,v]=n.useState(null),[B,W]=n.useState("asc"),[X,K]=n.useState(new Set),[q,T]=n.useState(!1),[Q,N]=n.useState(null),z=n.useRef(null),U=n.useRef(null),ne=n.useMemo(()=>new Map(t.map(a=>[a.id,a])),[t]),L=n.useMemo(()=>t.map(a=>({id:a.id,title:a.title})),[t]),Y=n.useMemo(()=>{const a=new Map;for(const k of t){const S=ht(k.status);a.set(S,(a.get(S)??0)+1)}return a},[t]),oe=n.useMemo(()=>{let a=0,k=0,S=0;for(const $ of t){const ee=ht($.status);ee==="blocked"?k+=1:ee==="done"?S+=1:a+=1}return{all:t.length,open:a,blocked:k,done:S}},[t]),c=n.useMemo(()=>{const a=M.trim().toLowerCase(),k=a.length>0,S=m.size>0;if(!k&&!S&&!(g!=="all"))return null;const ee=new Set;for(const xe of t){const Se=ht(xe.status),he=!k||xe.title.toLowerCase().includes(a)||xe.assignedAgents.some(I=>I.name.toLowerCase().includes(a)),D=!S||m.has(Se),P=Js(Se,g);he&&D&&P&&ee.add(xe.id)}const je=new Set(ee);for(const xe of ee)for(const Se of Ys(xe,t))je.add(Se);return je},[m,t,M,g]),te=n.useMemo(()=>t.filter(a=>a.type==="workstream").sort((a,k)=>a.priorityNum-k.priorityNum||a.title.localeCompare(k.title)),[t]),J=n.useMemo(()=>{const a=new Map;for(const k of t.filter(S=>S.type==="milestone")){const S=k.workstreamId??"unscoped",$=a.get(S)??[];$.push(k),a.set(S,$)}for(const k of a.values())k.sort((S,$)=>S.priorityNum-$.priorityNum||S.title.localeCompare($.title));return a},[t]),G=n.useMemo(()=>{const a=new Map;for(const k of t.filter(S=>S.type==="task"&&S.milestoneId)){const S=k.milestoneId??"unscoped",$=a.get(S)??[];$.push(k),a.set(S,$)}for(const k of a.values())k.sort((S,$)=>S.priorityNum-$.priorityNum||S.title.localeCompare($.title));return a},[t]),Z=n.useMemo(()=>{const a=new Map;for(const k of t.filter(S=>S.type==="task"&&!S.milestoneId)){const S=k.workstreamId??"unscoped",$=a.get(S)??[];$.push(k),a.set(S,$)}for(const k of a.values())k.sort((S,$)=>S.priorityNum-$.priorityNum||S.title.localeCompare($.title));return a},[t]),E=n.useMemo(()=>{const a=new Set;for(const k of te)a.add(k.id);for(const k of t.filter(S=>S.type==="milestone"))a.add(k.id);return a},[t,te]),[se,ge]=n.useState(E);n.useEffect(()=>{ge(E)},[E]);const ye=a=>p?[...a].sort((k,S)=>Xs(k,S,p,B)):a,ue=n.useMemo(()=>{const a=[],k=ee=>c===null||c.has(ee);for(const ee of ye(te)){if(!k(ee.id))continue;const je=ye(J.get(ee.id)??[]),xe=ye(Z.get(ee.id)??[]),Se=je.length>0||xe.length>0;if(a.push({node:ee,depth:0,canCollapse:Se}),!!se.has(ee.id)){for(const he of je){if(!k(he.id))continue;const D=ye(G.get(he.id)??[]);if(a.push({node:he,depth:1,canCollapse:D.length>0}),se.has(he.id))for(const P of D)k(P.id)&&a.push({node:P,depth:2,canCollapse:!1})}for(const he of xe)k(he.id)&&a.push({node:he,depth:1,canCollapse:!1})}}const S=ye(J.get("unscoped")??[]),$=ye(Z.get("unscoped")??[]);for(const ee of S)if(k(ee.id)&&(a.push({node:ee,depth:0,canCollapse:(G.get(ee.id)??[]).length>0}),se.has(ee.id)))for(const je of ye(G.get(ee.id)??[]))k(je.id)&&a.push({node:je,depth:1,canCollapse:!1});for(const ee of $)k(ee.id)&&a.push({node:ee,depth:0,canCollapse:!1});return a},[Z,se,c,J,p,B,G,te]),Be=n.useMemo(()=>ue.map(({node:a})=>a.id),[ue]),Qe=n.useMemo(()=>new Set(Be),[Be]),Me=n.useMemo(()=>ue.filter(({node:a})=>X.has(a.id)),[ue,X]),Re=(g!=="all"?1:0)+m.size,et=M.trim().length>0||g!=="all"||m.size>0,me=Me.length,be=ue.length>0&&me===ue.length,pe=(d==null?void 0:d.bulkEntityMutation.isPending)??!1;n.useEffect(()=>{K(a=>{if(a.size===0)return a;const k=new Set(Array.from(a).filter(S=>Qe.has(S)));return k.size===a.size?a:k})},[Qe]),n.useEffect(()=>{z.current&&(z.current.indeterminate=me>0&&!be)},[be,me]),n.useEffect(()=>{me===0&&q&&T(!1)},[q,me]),n.useEffect(()=>{if(!u)return;const a=S=>{var ee;const $=S.target;$&&((ee=U.current)!=null&&ee.contains($)||C(!1))},k=S=>{S.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",a),document.addEventListener("touchstart",a),document.addEventListener("keydown",k),()=>{document.removeEventListener("mousedown",a),document.removeEventListener("touchstart",a),document.removeEventListener("keydown",k)}},[u]);const ze=a=>a.dependencyIds.length,Oe=n.useMemo(()=>{const a=new Map,k=(S,$)=>{if(S.length>0){const ee=S.filter(je=>Ae(je.status)).length;return Xe(ee,S.length)}return Ae($)?100:0};for(const S of t.filter($=>$.type==="milestone")){const $=G.get(S.id)??[];a.set(S.id,k($,S.status))}for(const S of te){const ee=(J.get(S.id)??[]).flatMap(xe=>G.get(xe.id)??[]),je=Z.get(S.id)??[];a.set(S.id,k([...je,...ee],S.status))}return a},[Z,J,t,G,te]),Ie=a=>{p===a?W(k=>k==="asc"?"desc":"asc"):(v(a),W("asc"))},Ee=a=>{l(k=>{const S=new Set(k);return S.has(a)?S.delete(a):S.add(a),S})},Ve=()=>{_(""),b("all"),l(new Set)},we=(a,k)=>{N(null),T(!1),K(S=>{const $=new Set(S);return k?$.add(a):$.delete(a),$})},Ge=()=>{N(null),T(!1),K(()=>ue.length===0||be?new Set:new Set(Be))},re=()=>{T(!1),K(new Set)},$e=async a=>{if(!(!d||Me.length===0)){T(!1),N(null);try{const k=await d.bulkEntityMutation.mutateAsync({items:Me.map(({node:S})=>({type:S.type,id:S.id})),mode:"update",updates:{status:a}});k.failed>0?N({tone:"error",message:`Updated ${k.updated}, failed ${k.failed}.`}):N({tone:"success",message:`Updated ${k.updated} item${k.updated===1?"":"s"} to ${ke(a)}.`})}catch(k){N({tone:"error",message:k instanceof Error?k.message:"Bulk status update failed."})}}},_e=async()=>{if(!(!d||Me.length===0)){N(null);try{const a=await d.bulkEntityMutation.mutateAsync({items:Me.map(({node:k})=>({type:k.type,id:k.id})),mode:"delete"});a.failed>0?N({tone:"error",message:`Deleted ${a.updated}, failed ${a.failed}.`}):(N({tone:"success",message:`Deleted ${a.updated} item${a.updated===1?"":"s"}.`}),K(new Set),T(!1))}catch(a){N({tone:"error",message:a instanceof Error?a.message:"Bulk delete failed."})}}},Ce=({field:a})=>p!==a?e.jsx("span",{className:"text-white/20 ml-0.5",children:"↕"}):e.jsx("span",{className:"text-[#BFFF00] ml-0.5",children:B==="asc"?"↑":"↓"});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(hs,{value:M,onChange:_,placeholder:"Search items or agents..."})}),e.jsxs("div",{className:"flex min-h-[40px] min-w-0 flex-wrap items-center gap-2.5",children:[h&&e.jsxs("button",{type:"button",onClick:h,"data-state":o?"active":"idle",className:`control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-[11px] font-semibold ${o?"text-[#D8FFA1]":"text-white/65 hover:text-white/85"}`,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"})}),o?"Editing":"Edit"]}),e.jsxs("div",{ref:U,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>C(a=>!a),"data-state":u||Re>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3.5 text-[11px] 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"}),Re>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-[10px] leading-4",children:Re})]}),e.jsx(Le,{children:u&&e.jsxs(le.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-[10px] font-semibold uppercase tracking-[0.08em] text-white/38",children:"Scope"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[{id:"all",label:"All",count:oe.all},{id:"open",label:"Open",count:oe.open},{id:"blocked",label:"Blocked",count:oe.blocked},{id:"done",label:"Done",count:oe.done}].map(a=>{const k=g===a.id;return e.jsxs("button",{type:"button",onClick:()=>b(a.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full border px-2.5 text-[10px] font-semibold transition-colors ${k?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-[#D8FFA1]":"border-white/[0.12] bg-white/[0.03] text-white/60 hover:bg-white/[0.07] hover:text-white/82"}`,children:[e.jsx("span",{children:a.label}),e.jsx("span",{className:"text-[9px] text-current/80",children:a.count})]},a.id)})})]}),e.jsxs("div",{className:"mb-2 border-t border-white/[0.08] pt-2",children:[e.jsx("div",{className:"text-[10px] font-semibold uppercase tracking-[0.08em] text-white/38",children:"Status"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:es.map(a=>{const k=m.has(a),S=Y.get(a)??0;return e.jsxs("button",{type:"button",onClick:()=>Ee(a),className:`inline-flex h-7 items-center gap-1 rounded-full border px-2.5 text-[10px] transition-colors ${k?"border-[#14B8A6]/35 bg-[#14B8A6]/12 text-[#8FF7EC]":"border-white/[0.12] bg-white/[0.03] text-white/58 hover:bg-white/[0.07] hover:text-white/85"}`,children:[e.jsx("span",{children:ke(a)}),e.jsx("span",{className:"text-[9px] text-current/75",children:S})]},a)})})]}),(g!=="all"||m.size>0)&&e.jsx("button",{type:"button",onClick:()=>{b("all"),l(new Set)},className:"text-[10px] text-white/45 transition-colors hover:text-white/75",children:"Reset filters"})]})})]}),e.jsx(Le,{initial:!1,children:et&&e.jsx(le.button,{type:"button",onClick:Ve,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-[11px] font-medium text-white/70 hover:text-white/88",children:"Clear"},"hierarchy-clear-filters")}),e.jsx("button",{type:"button",onClick:Ge,"data-state":be?"active":"idle",className:"control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-[11px] font-semibold",children:be?"Clear visible":"Select visible"})]})]}),e.jsx("div",{className:`rounded-xl border px-3 ${me>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-[11px] text-white/75",children:[e.jsx("input",{ref:z,type:"checkbox",checked:be,onChange:Ge,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"}),"Select all visible"]}),e.jsx("span",{className:"flex-shrink-0 text-[11px] text-white/58",children:me>0?`${me} selected`:`${ue.length} visible`}),me>0&&e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2 whitespace-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>{$e("planned")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Plan"}),e.jsx("button",{type:"button",onClick:()=>{$e("in_progress")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:"Start"}),e.jsx("button",{type:"button",onClick:()=>{$e("blocked")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{$e("done")},disabled:pe,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Complete"}),q?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{_e()},disabled:pe,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-[11px] font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>T(!1),disabled:pe,className:"control-pill h-8 flex-shrink-0 px-2.5 text-[11px] disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>T(!0),disabled:pe,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-[11px] font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:re,disabled:pe,className:"text-[11px] text-white/55 transition-colors hover:text-white/80 disabled:opacity-45",children:"Clear"})]})]})}),Q&&e.jsx("div",{className:`rounded-lg border px-3 py-2 text-[11px] ${Q.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:Q.message}),o&&e.jsx("div",{className:"mb-2 text-[10px] text-white/45",children:"Edit mode: select a row to edit its fields inline."}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-white/[0.07] bg-black/[0.14] p-2",children:e.jsxs("table",{className:"w-full min-w-[1180px] border-separate border-spacing-y-1.5",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[10px] uppercase tracking-[0.08em] text-white/42",children:[e.jsx("th",{className:"w-10 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:()=>Ie("title"),children:["Item ",e.jsx(Ce,{field:"title"})]}),e.jsx("th",{className:"w-[188px] px-2 py-1.5",children:"Assigned"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>Ie("status"),children:["Status ",e.jsx(Ce,{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:()=>Ie("priority"),children:["Priority ",e.jsx(Ce,{field:"priority"})]}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none",onClick:()=>Ie("eta"),children:["ETA ",e.jsx(Ce,{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("tbody",{children:ue.map(({node:a,depth:k,canCollapse:S})=>{var P;const $=r===a.id,ee=x.has(a.id),je=X.has(a.id),xe=a.assignedAgents.map(I=>I.name).join(", "),Se=a.dependencyIds.map(I=>{var de;return((de=ne.get(I))==null?void 0:de.title)??I}).slice(0,3).join(", "),he=Oe.get(a.id),D=o&&$;return e.jsxs("tr",{onClick:()=>{i(a.id),a.type==="workstream"&&j(a.id)},className:`group/row cursor-pointer rounded-lg border transition-colors ${$?"border-[#BFFF00]/[0.22] bg-[#BFFF00]/[0.08]":ee?"border-[#14B8A6]/[0.2] bg-[#14B8A6]/[0.08]":"border-white/[0.06] bg-white/[0.02] hover:border-white/[0.14] 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:je,onChange:I=>{I.stopPropagation(),we(a.id,I.currentTarget.checked)},onClick:I=>I.stopPropagation(),"aria-label":`Select ${a.type}: ${a.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 items-center gap-1.5",children:[e.jsx("div",{style:{width:k*14}}),S?e.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),ge(de=>{const w=new Set(de);return w.has(a.id)?w.delete(a.id):w.add(a.id),w})},"aria-label":`${se.has(a.id)?"Collapse":"Expand"} ${a.type}: ${a.title}`,className:"rounded text-white/50 focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:se.has(a.id)?"▾":"▸"}):e.jsx("span",{className:"w-2.5"}),e.jsx(vt,{type:a.type}),e.jsx("button",{type:"button",onClick:I=>{I.stopPropagation(),y(a)},"aria-label":`Open ${a.type} details: ${a.title}`,className:"max-w-[320px] truncate rounded text-[12px] text-white/88 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:a.title}),a.type==="task"&&d&&!o&&e.jsx("div",{className:"flex items-center gap-0.5 opacity-0 group-hover/row:opacity-100 transition-opacity ml-1",children:["not_started","todo","planned","pending","backlog"].includes(a.status.toLowerCase())?e.jsx("button",{type:"button",title:"Start",onClick:I=>{I.stopPropagation(),F(a,{status:"in_progress"})},"aria-label":`Start task: ${a.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-white/40 transition-colors hover:text-[#BFFF00] hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}):["in_progress","active"].includes(a.status.toLowerCase())?e.jsx("button",{type:"button",title:"Mark done",onClick:I=>{I.stopPropagation(),F(a,{status:"done"})},"aria-label":`Mark task done: ${a.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-white/40 transition-colors hover:text-emerald-400 hover:bg-white/[0.06] focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})})}):null})]})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75 whitespace-nowrap",children:D?e.jsx("input",{type:"text",defaultValue:xe,placeholder:"Agent A, Agent B",onClick:I=>I.stopPropagation(),onBlur:I=>{const de=I.currentTarget.value.split(",").map(w=>w.trim()).filter(Boolean);F(a,{assigned_agent_names:de,assigned_agent_ids:de.map(w=>`name:${w}`),assignment_source:"manual"})},className:"w-[190px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("div",{className:"flex items-center gap-2",children:a.assignedAgents.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center -space-x-1.5",children:a.assignedAgents.slice(0,3).map(I=>e.jsx("div",{title:I.name,className:"rounded-full ring-1 ring-[#02040A]",children:e.jsx(zt,{name:I.name,hint:`${I.id} ${a.title}`,size:"xs"})},`${a.id}:${I.id}`))}),e.jsxs("span",{className:"max-w-[110px] truncate text-[10px] text-white/62",title:xe,children:[(P=a.assignedAgents[0])==null?void 0:P.name,a.assignedAgents.length>1?` +${a.assignedAgents.length-1}`:""]})]}):e.jsx("span",{className:"text-white/35",children:"Unassigned"})})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("select",{defaultValue:ht(a.status),onClick:I=>I.stopPropagation(),onChange:I=>{F(a,{status:I.target.value})},className:"rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82",children:es.map(I=>e.jsx("option",{value:I,children:ke(I)},I))}):e.jsx("span",{className:"status-pill whitespace-nowrap","data-tone":Qs(a.status),children:ke(a.status)})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:he!==void 0&&(a.type==="workstream"||a.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:`${he}%`,backgroundColor:a.type==="milestone"?O.teal:O.lime}})}),e.jsxs("span",{className:"text-[10px] text-white/60",style:{fontVariantNumeric:"tabular-nums"},children:[he,"%"]})]}):e.jsx("span",{className:"text-white/35",children:"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("input",{type:"number",min:1,max:100,defaultValue:a.priorityNum,onClick:I=>I.stopPropagation(),onBlur:I=>{const de=Number(I.currentTarget.value);Number.isFinite(de)&&F(a,{priority_num:de})},className:"w-[72px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsxs("span",{children:["P",a.priorityNum]})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("input",{type:"datetime-local",defaultValue:Ks(a.etaEndAt),onClick:I=>I.stopPropagation(),onBlur:I=>{const de=I.currentTarget.value;F(a,{eta_end_at:de?new Date(de).toISOString():null})},className:"w-[176px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("span",{children:a.etaEndAt?new Date(a.etaEndAt).toLocaleString():"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D&&a.type!=="task"?e.jsx("input",{type:"number",min:0,step:.5,defaultValue:a.expectedDurationHours,onClick:I=>I.stopPropagation(),onBlur:I=>{const de=Number(I.currentTarget.value);Number.isFinite(de)&&F(a,{expected_duration_hours:de})},className:"w-[82px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsx("span",{children:a.expectedDurationHours})}),e.jsx("td",{className:"px-2 py-1.5 text-[11px] text-white/75",children:D&&a.type!=="task"?e.jsx("input",{type:"number",min:0,step:1,defaultValue:a.expectedBudgetUsd,onClick:I=>I.stopPropagation(),onBlur:I=>{const de=Number(I.currentTarget.value);Number.isFinite(de)&&F(a,{expected_budget_usd:de})},className:"w-[92px] rounded border border-white/[0.16] bg-white/[0.06] px-2 py-1 text-[10px] text-white/82"}):e.jsxs("span",{children:["$",a.expectedBudgetUsd.toLocaleString(),D&&a.type==="task"?" (from task spec)":""]})}),e.jsx("td",{className:"rounded-r-lg px-2 py-1.5 text-[11px] text-white/75",children:D?e.jsx("div",{onClick:I=>I.stopPropagation(),children:e.jsx(Gs,{dependencies:a.dependencyIds,allNodes:L,onSave:I=>void F(a,{depends_on:I})})}):e.jsx("div",{className:"max-w-[250px] truncate",children:ze(a)>0?`${ze(a)} · ${Se}`:"—"})})]},a.id)})})]})}),ue.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-white/20",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-[13px] font-medium text-white/50",children:M||m.size>0||g!=="all"?"No items match the current filters":"No work items yet"}),e.jsx("div",{className:"mt-1 text-[11px] text-white/30",children:M||m.size>0||g!=="all"?"Try adjusting your search or filter criteria.":"Workstreams, milestones, and tasks will appear here."})]})]})}function ts(t){if(!t)return"No target date";const s=new Date(t);return Number.isNaN(s.getTime())?"No target date":`Due ${s.toLocaleDateString()}`}function en({recentTodoIds:t,nodesById:s,selectedNodeId:r,onSelectNode:x}){const o=t.map(j=>s.get(j)).filter(j=>!!j).sort((j,y)=>{if(j.priorityNum!==y.priorityNum)return j.priorityNum-y.priorityNum;const F=j.dueDate?Date.parse(j.dueDate):Number.POSITIVE_INFINITY,d=y.dueDate?Date.parse(y.dueDate):Number.POSITIVE_INFINITY;return F-d}).slice(0,14);if(o.length===0)return null;const h=o[0],i=o.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-[10px] uppercase tracking-[0.08em] text-white/42",children:"Queue overview"}),e.jsxs("span",{className:"rounded-full border border-white/15 bg-black/20 px-2 py-0.5 text-[10px] text-white/65",children:[o.length," in queue"]})]}),e.jsx("button",{type:"button",onClick:()=>x(h.id),className:`surface-hero group w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${r===h.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-[10px] uppercase tracking-[0.1em] text-white/50",children:[e.jsx(vt,{type:h.type}),e.jsx("span",{children:"Priority task"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-[13px] font-semibold leading-snug text-white",children:h.title}),e.jsx("p",{className:"mt-1 text-[11px] text-white/60",children:ts(h.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full border px-2 py-0.5 text-[10px] font-semibold",style:{borderColor:`${O.amber}44`,backgroundColor:`${O.amber}22`,color:O.amber},children:["P",h.priorityNum]})]})}),i.length>0&&e.jsx("div",{className:"space-y-1.5",children:i.map(j=>e.jsxs("button",{type:"button",onClick:()=>x(j.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===j.id?"border-[#BFFF00]/30 bg-[#BFFF00]/12":"border-white/[0.14] 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-[9px] uppercase tracking-[0.08em] text-white/45",children:[e.jsx(vt,{type:j.type}),e.jsx("span",{children:"Queued"})]}),e.jsx("p",{className:"mt-1 line-clamp-1 break-words text-[11px] leading-snug text-white/85",title:j.title,children:j.title}),e.jsx("p",{className:"mt-1 text-[10px] text-white/50",children:ts(j.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full px-1.5 py-0.5 text-[9px]",style:{backgroundColor:`${O.amber}22`,color:`${O.amber}`},children:["P",j.priorityNum]})]},j.id))})]})}function tn(t,s){try{const r=localStorage.getItem(`orgx.section.${t}`);if(r==="0")return!1;if(r==="1")return!0}catch{}return s}function sn(t,s){try{localStorage.setItem(`orgx.section.${t}`,s?"1":"0")}catch{}}function mt({title:t,defaultOpen:s=!0,storageKey:r,sticky:x=!1,stickyOffsetClass:o="top-0",stickyTop:h,children:i}){const[j,y]=n.useState(()=>r?tn(r,s):s),F=n.useRef(null),[d,M]=n.useState(40),_=()=>{const m=!j;y(m),r&&sn(r,m)};return n.useEffect(()=>{if(!x)return;const m=F.current;if(!m)return;const l=()=>{const b=Math.max(34,m.offsetHeight);M(u=>u===b?u:b)};if(l(),typeof ResizeObserver>"u")return;const g=new ResizeObserver(()=>l());return g.observe(m),()=>g.disconnect()},[x,h,t]),e.jsxs("div",{style:x?{"--mc-collapsible-header-offset":`${d}px`}:void 0,children:[e.jsxs("button",{ref:x?F:void 0,type:"button","data-mc-section-header":t,onClick:_,className:`flex w-full items-center gap-2 rounded-lg border px-2 py-2 text-left transition-colors ${x?`sticky ${o} 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-white/[0.06] hover:bg-white/[0.03]"}`,style:x&&h?{top:h}:void 0,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-white/30 transition-transform duration-200 ${j?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsx("span",{className:"text-[11px] font-semibold tracking-[0.02em] text-white/68",children:t})]}),e.jsx(Le,{initial:!1,children:j&&e.jsx(le.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},exit:{height:0,opacity:0},transition:{type:"spring",stiffness:400,damping:35},className:"overflow-hidden",children:i})})]})}function nn(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 an(t){const s=t.toLowerCase();return["todo","not_started","planned","pending","backlog"].includes(s)}function rn(t){const s=t.toLowerCase();return["in_progress","active","running","queued"].includes(s)}function ln(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},o=(s.workstreams.length>0?s.workstreams:(t.workstreams??[]).map(d=>({id:d.id,name:d.name,summary:null,status:d.status,progress:null,initiativeId:t.id,createdAt:null}))).map(d=>({id:d.id,type:"workstream",title:d.name,status:d.status,parentId:t.id,initiativeId:t.id,workstreamId:d.id,milestoneId:null,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:null,etaEndAt:null,expectedDurationHours:16,expectedBudgetUsd:300,assignedAgents:[],updatedAt:d.createdAt})),h=new Set(o.map(d=>d.id)),i=s.milestones.map(d=>({id:d.id,type:"milestone",title:d.title,status:d.status,parentId:d.workstreamId&&h.has(d.workstreamId)?d.workstreamId:t.id,initiativeId:t.id,workstreamId:d.workstreamId&&h.has(d.workstreamId)?d.workstreamId:null,milestoneId:d.id,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:d.dueDate,etaEndAt:d.dueDate,expectedDurationHours:6,expectedBudgetUsd:120,assignedAgents:[],updatedAt:d.createdAt})),j=new Set(i.map(d=>d.id)),y=s.tasks.map(d=>{const M=nn(d.priority),_=d.milestoneId&&j.has(d.milestoneId),m=d.workstreamId&&h.has(d.workstreamId);return{id:d.id,type:"task",title:d.title,status:d.status,parentId:_?d.milestoneId:m?d.workstreamId:t.id,initiativeId:t.id,workstreamId:m?d.workstreamId:null,milestoneId:_?d.milestoneId:null,priorityNum:M.priorityNum,priorityLabel:M.priorityLabel,dependencyIds:[],dueDate:d.dueDate,etaEndAt:d.dueDate,expectedDurationHours:2,expectedBudgetUsd:40,assignedAgents:[],updatedAt:d.createdAt}}),F=y.filter(d=>["todo","not_started","planned","pending","backlog"].includes(d.status.toLowerCase())).sort((d,M)=>{const _=d.priorityNum-M.priorityNum;if(_!==0)return _;const m=d.etaEndAt?Date.parse(d.etaEndAt):1/0,l=M.etaEndAt?Date.parse(M.etaEndAt):1/0;if(m!==l)return m-l;const g=d.updatedAt?Date.parse(d.updatedAt):0;return(M.updatedAt?Date.parse(M.updatedAt):0)-g}).map(d=>d.id);return{nodes:[r,...o,...i,...y],edges:[],recentTodos:F}}function on(t,s){if(!t)return new Set;const r=new Map(s.map(i=>[i.id,i])),x=new Map;for(const i of s)for(const j of i.dependencyIds){const y=x.get(j)??[];y.push(i.id),x.set(j,y)}const o=new Set,h=[t];for(;h.length>0;){const i=h.shift();if(o.has(i))continue;o.add(i);const j=r.get(i);if(j){for(const y of j.dependencyIds)o.has(y)||h.push(y);for(const y of x.get(i)??[])o.has(y)||h.push(y)}}return o}function cn(t,s){return{id:t.id,name:t.title,summary:null,status:t.status,progress:null,initiativeId:s.id,createdAt:t.updatedAt}}function dn(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 un(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}}function pn(t){return/unknown api endpoint/i.test(t)?"Graph API unavailable — showing session-derived data":/401|unauthorized/i.test(t)?"Auth expired — reconnect to load full data":/failed to list initiative/i.test(t)?"Initiative data unavailable":/failed to list workstream/i.test(t)?"Workstream data unavailable":/failed to list milestone/i.test(t)?"Milestone data unavailable":/failed to list task/i.test(t)?"Task data unavailable":/500 internal server/i.test(t)?"Server error — some data may be incomplete":/entity data partially unavailable/i.test(t)?"Entity data partially unavailable":t.length>80?t.slice(0,72).replace(/[^a-zA-Z0-9]$/,"")+"...":t}const ct={hidden:{opacity:0},show:{opacity:1}};function ft({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-[10px] text-white/45",children:t}),e.jsx("div",{className:"mt-0.5 text-[12px] font-semibold text-white/85",children:s})]})}function xn({initiative:t,selected:s=!1,onSelectionChange:r,runtimeActivity:x=null}){var de;const{expandedInitiatives:o,toggleExpanded:h,openModal:i,agentEntityMap:j,authToken:y,embedMode:F,mutations:d}=Ze(),[M,_]=n.useState(!1),[m,l]=n.useState(null),[g,b]=n.useState(null),[u,C]=n.useState(!1),[p,v]=n.useState(!1),B=n.useRef(null),[W,X]=n.useState(52),[K,q]=n.useState(0),T=o.has(t.id),{graph:Q,isLoading:N,degraded:z,error:U}=qs({initiativeId:t.id,authToken:y,embedMode:F,enabled:T}),{details:ne,isLoading:L,error:Y}=Nt({initiativeId:t.id,authToken:y,embedMode:F,enabled:T}),oe=n.useMemo(()=>ln(t,ne),[t,ne]),c=!!(Q&&Q.nodes.length>0),te=oe.nodes.length>0,J=!c&&te,G=J?oe.nodes:c?(Q==null?void 0:Q.nodes)??[]:oe.nodes,Z=J?oe.edges:c?(Q==null?void 0:Q.edges)??[]:oe.edges,E=J?oe.recentTodos:c?(Q==null?void 0:Q.recentTodos)??[]:oe.recentTodos,se=z.some(w=>/401|unauthorized/i.test(w))||!!(U&&/401|unauthorized/i.test(U))||!!(Y&&/401|unauthorized/i.test(Y)),ge=U&&/unknown api endpoint/i.test(U)?"Graph API unavailable. Showing session-derived data.":U,ye=Y,ue=[...z,...ge?[ge]:[],...ye?[`Entity data partially unavailable: ${ye}`]:[],...se?["OrgX auth is missing or expired in this local plugin instance. Reconnect in onboarding to load full workstreams/milestones/tasks."]:[]],Be=n.useMemo(()=>new Map(G.map(w=>[w.id,w])),[G]),Qe=n.useMemo(()=>on(m,G),[m,G]),Me=n.useMemo(()=>E.some(w=>Be.has(w)),[Be,E]);n.useEffect(()=>{const w=B.current;if(!w||!T)return;const ie=()=>{const Ue=Math.max(48,w.offsetHeight);X(He=>He===Ue?He:Ue)};if(ie(),typeof ResizeObserver>"u")return;const qe=new ResizeObserver(()=>ie());return qe.observe(w),()=>qe.disconnect()},[T,t.status,t.targetDate,t.name]),n.useEffect(()=>{const w=B.current;if(!w||!T){q(0);return}const ie=w.closest('[data-mc-scroll-host="true"]')??w.closest(".h-full.overflow-y-auto.overflow-x-hidden"),qe=ie??window;let Ue=0;const He=()=>{Ue=0;const Fe=Number.parseFloat(getComputedStyle(w).top||"0"),st=w.getBoundingClientRect(),ot=(ie==null?void 0:ie.getBoundingClientRect().top)??0,De=1-(st.top-ot-Fe)/56,nt=Math.pow(Math.max(0,Math.min(1,De)),1.2);q(xt=>Math.abs(xt-nt)<.015?xt:nt)},tt=()=>{Ue||(Ue=window.requestAnimationFrame(He))};return He(),qe.addEventListener("scroll",tt,{passive:!0}),window.addEventListener("resize",tt),()=>{Ue&&window.cancelAnimationFrame(Ue),qe.removeEventListener("scroll",tt),window.removeEventListener("resize",tt)}},[T,t.id]),n.useEffect(()=>{var w;T&&!m&&G.length>0&&l(((w=G[0])==null?void 0:w.id)??null)},[T,G,m]);const Re=((Q==null?void 0:Q.initiative.assignedAgents)??[]).map(w=>({id:w.id,name:w.name,confidence:"high"})),et=j.get(t.id)??[],me=Re.length>0?Re:et,be=G.filter(w=>w.type==="task"),pe=be.filter(w=>rn(w.status)).length,ze=be.filter(w=>an(w.status)).length,Oe=be.filter(w=>Ae(w.status)).length,Ie=(x==null?void 0:x.activeCount)??0,Ee=(x==null?void 0:x.totalCount)??0,Ve=pe>0||Ie>0,we=t.status==="active"&&Ve?"in_progress":t.status,Ge=we==="in_progress"?yt.active:yt[we],re=we==="in_progress"?"In Progress":ke(we),$e=be.length>0?be:G.some(w=>w.type==="milestone")?G.filter(w=>w.type==="milestone"):G.filter(w=>w.type==="workstream"),_e=Math.round($e.reduce((w,ie)=>w+(ie.expectedDurationHours||0),0)*10)/10,Ce=Math.round($e.reduce((w,ie)=>w+(ie.expectedBudgetUsd||0),0)*100)/100,a=G.filter(w=>w.type==="milestone"),k=G.filter(w=>w.type==="workstream"),S=T&&(c||ne.workstreams.length>0||ne.milestones.length>0||ne.tasks.length>0),$=be.length>0?Xe(Oe,be.length):a.length>0?Xe(a.filter(w=>Ae(w.status)).length,a.length):S&&k.length>0?Xe(k.filter(w=>Ae(w.status)).length,k.length):null,ee=Ct($===null?t.health:$),je=ee===0?2:ee,xe=Math.pow(K,.82),Se=Math.max(0,Number((16*(1-xe)).toFixed(2))),he=`0 10px 26px rgba(0,0,0,${(.18+xe*.24).toFixed(3)}), 0 1px 0 rgba(191,255,0,${(xe*.09).toFixed(3)})`,D=w=>{if(w.type==="initiative"){i({type:"initiative",entity:t});return}if(w.type==="workstream"){i({type:"workstream",entity:cn(w,t),initiative:t});return}if(w.type==="milestone"){i({type:"milestone",entity:dn(w,t),initiative:t});return}i({type:"task",entity:un(w,t),initiative:t})},P=async(w,ie)=>{await d.updateEntity.mutateAsync({type:w.type,id:w.id,...ie})},I=w=>ie=>{ie.stopPropagation(),d.entityAction.mutate({type:"initiative",id:t.id,action:w})};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 ${T?"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":`${W}px`},children:[e.jsxs("div",{ref:B,role:"button",tabIndex:0,"aria-expanded":T,onClick:()=>h(t.id),onKeyDown:w=>{(w.key==="Enter"||w.key===" ")&&(w.preventDefault(),h(t.id))},className:`group flex min-h-[66px] w-full min-w-0 items-center gap-2.5 overflow-hidden 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 ${T?"sticky z-30 border-b border-white/[0.06] bg-[#0C0E14]/95 shadow-[0_8px_20px_rgba(0,0,0,0.3)] backdrop-blur-xl":""}`,style:T?{top:"var(--mc-toolbar-offset, 88px)",borderTopLeftRadius:`${Se}px`,borderTopRightRadius:`${Se}px`,boxShadow:he}:void 0,children:[e.jsx(le.div,{animate:{rotate:T?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-white/40",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:w=>r(t.id,w.currentTarget.checked),onClick:w=>w.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 ${Ve?"status-breathe":""}`,style:{backgroundColor:Zt(we)}}),e.jsx("div",{className:"min-w-0 flex-[1_1_auto] overflow-hidden pr-2 sm:pr-3",children:e.jsx("button",{type:"button",onClick:w=>{w.stopPropagation(),i({type:"initiative",entity:t})},className:"block w-full max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-left text-[13px] font-semibold text-white transition-colors hover:text-white/80 sm:text-[14px]",title:t.name,children:t.name})}),e.jsx("div",{className:"ml-1 flex w-[90px] min-w-[90px] flex-shrink-0 justify-start sm:w-[102px] sm:min-w-[102px]",children:e.jsx("span",{className:`w-full truncate text-center text-[10px] px-2 py-0.5 rounded-full border uppercase tracking-[0.08em] leading-none whitespace-nowrap ${Ge}`,children:re})}),e.jsxs("div",{className:"ml-1.5 flex w-[148px] min-w-[148px] flex-shrink-0 items-center justify-end gap-2.5 pr-0.5 sm:w-[182px] sm:min-w-[182px] sm:pr-1 md:w-[206px] md:min-w-[206px]",children:[e.jsx("div",{className:"min-w-[88px] flex-1 sm:min-w-[112px] md:min-w-[140px]",children:e.jsx("div",{className:"h-[2px] w-full overflow-hidden rounded-full bg-white/[0.06]",children:e.jsx(le.div,{className:"h-full rounded-full transition-all",initial:!1,animate:{width:`${je}%`,opacity:ee===0?.45:1},transition:{type:"spring",stiffness:260,damping:34,mass:.75},style:{backgroundColor:Zt(we)}})})}),e.jsxs("span",{className:"w-[42px] text-right text-[10px] text-white/40 sm:w-[48px] sm:text-[11px]",style:{fontVariantNumeric:"tabular-nums"},children:[ee,"%"]})]}),e.jsx("div",{className:"ml-2 flex w-[104px] min-w-[104px] flex-shrink-0 items-center justify-end border-l border-white/[0.05] pl-2 sm:w-[116px] sm:min-w-[116px] sm:pl-2.5 md:w-[132px] md:min-w-[132px]",children:Ie>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-[10px] font-semibold text-[#D8FFA1]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00] status-breathe"}),Ie," live"]}):me.length>0?e.jsx(kt,{agents:me,max:3}):Ee>0?e.jsxs("span",{className:"w-full text-right text-[10px] text-white/35",children:[Ee," idle"]}):e.jsx("span",{className:"w-full text-right text-[10px] 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:I("pause"),title:"Pause",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 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:I("resume"),title:"Resume",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 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:w=>{w.stopPropagation(),i({type:"initiative",entity:t})},title:"Details",className:"flex items-center justify-center w-6 h-6 rounded-lg text-white/50 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"})]})})]})]}),e.jsx(Le,{children:T&&e.jsx(le.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:()=>v(!0),onAnimationComplete:()=>v(!1),className:p?"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"}),N||!c&&L?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((w,ie)=>e.jsx(ut,{className:"h-24 w-full rounded-xl"},`mc-loading-${ie}`))}):e.jsxs(le.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.08}}},className:"space-y-3.5",children:[ue.length>0&&e.jsxs(le.div,{variants:ct,className:"overflow-hidden rounded-lg border border-amber-300/15 bg-amber-500/[0.06]",children:[e.jsxs("button",{type:"button",onClick:()=>C(w=>!w),className:"flex w-full items-center justify-between px-3 py-2 text-left transition-colors hover:bg-white/[0.03]",children:[e.jsxs("span",{className:"text-[11px] text-amber-100/85",children:[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:`text-amber-100/55 transition-transform ${u?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsx(Le,{children:u&&e.jsx(le.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:"px-3 pb-2 space-y-1",children:ue.map((w,ie)=>e.jsx("div",{className:"text-[10px] text-amber-100/72",children:pn(w)},ie))})})})]}),(ze>0||pe>0||_e>0||Ce>0)&&e.jsx(le.div,{variants:ct,children:e.jsx(mt,{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(ft,{label:"Queue",value:`${ze} todo · ${pe} active`}),e.jsx(ft,{label:"Completed",value:`${Oe}/${be.length||0}`}),e.jsx(ft,{label:"Duration",value:`${_e}h`}),e.jsx(ft,{label:"Budget",value:`$${Ce.toLocaleString()}`})]})})}),g&&e.jsxs("div",{className:"subsection-shell flex items-center justify-between rounded-lg px-3 py-2 text-[11px] text-[#D8FFA1]",children:[e.jsxs("span",{children:["Focused on workstream ",((de=Be.get(g))==null?void 0:de.title)??g]}),e.jsx("button",{type:"button",onClick:()=>b(null),className:"text-[10px] underline underline-offset-2",children:"Clear focus"})]}),e.jsx(le.div,{variants:ct,children:e.jsx(mt,{title:"Dependency Map",storageKey:`depmap.${t.id}`,defaultOpen:!0,children:e.jsx(Ws,{nodes:G,edges:Z,selectedNodeId:m,focusedWorkstreamId:g,onSelectNode:w=>{l(w);const ie=Be.get(w);(ie==null?void 0:ie.type)==="workstream"&&b(ie.id)}})})}),Me&&e.jsx(le.div,{variants:ct,children:e.jsx(mt,{title:"Next Up",storageKey:`nextup.${t.id}`,defaultOpen:!0,children:e.jsx(en,{recentTodoIds:E,nodesById:Be,selectedNodeId:m,onSelectNode:w=>{l(w);const ie=Be.get(w);(ie==null?void 0:ie.type)==="workstream"&&b(ie.id)}})})}),e.jsx(le.div,{variants:ct,children:e.jsx(mt,{title:"Hierarchy",storageKey:`hierarchy.${t.id}`,defaultOpen:!0,sticky:!p,stickyTop:"calc(var(--mc-toolbar-offset, 88px) + var(--mc-initiative-header-offset, 52px))",children:e.jsx(Zs,{nodes:G,edges:Z,selectedNodeId:m,highlightedNodeIds:Qe,editMode:M,onSelectNode:l,onFocusWorkstream:b,onOpenNode:D,onUpdateNode:P,onToggleEditMode:()=>_(w=>!w),mutations:d})})})]}),e.jsxs("button",{type:"button",onClick:()=>h(t.id),className:"flex w-full items-center justify-center gap-1.5 py-1.5 text-[10px] text-white/35 transition-colors hover:text-white/65",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 hn={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.045,delayChildren:.02}}},mn={hidden:{opacity:0,y:10,scale:.995},show:{opacity:1,y:0,scale:1,transition:{type:"spring",stiffness:320,damping:28,mass:.7}}};function ss({initiatives:t,selectedInitiativeIds:s,onToggleInitiativeSelection:r,runtimeActivityByInitiativeId:x}){return e.jsx(le.div,{variants:hn,initial:"hidden",animate:"show",className:"space-y-2",children:t.map(o=>e.jsx(le.div,{variants:mn,layout:!0,transition:{type:"spring",stiffness:280,damping:32,mass:.75},children:e.jsx(xn,{initiative:o,selected:(s==null?void 0:s.has(o.id))??!1,onSelectionChange:r,runtimeActivity:(x==null?void 0:x.get(o.id))??null})},o.id))})}function fn(){return e.jsx("div",{className:"flex-1 flex items-center justify-center p-12",children:e.jsx(As,{className:"max-w-sm p-8",children:e.jsxs("div",{className:"flex flex-col items-center text-center gap-4",children:[e.jsx("div",{className:"relative flex items-center justify-center h-16 w-16 rounded-2xl",style:{backgroundColor:`${O.iris}1a`,border:`1px solid ${O.iris}33`},children:e.jsxs("svg",{width:"28",height:"28",viewBox:"0 0 24 24",fill:"none",stroke:O.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:"space-y-1.5",children:[e.jsx("h3",{className:"text-[14px] font-semibold text-white",children:"No initiatives yet"}),e.jsx("p",{className:"text-[12px] text-white/50 leading-relaxed",children:"Create initiatives in OrgX to see them here. Mission Control shows your full initiative hierarchy with workstreams, milestones, and tasks."})]})]})})})}function V({label:t,icon:s,color:r="#BFFF00",variant:x="secondary",size:o="md",className:h="",type:i="button",...j}){const y=o==="sm"?"px-2.5 py-1 text-[10px]":"px-3 py-1.5 text-[11px]",F=x==="primary"?{backgroundColor:r,color:"#05060A",borderColor:`${r}CC`}:x==="destructive"?{backgroundColor:`${r}18`,color:r,borderColor:`${r}45`}:x==="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:i,className:`inline-flex items-center gap-1.5 rounded-lg border transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${y} ${h}`,style:F,...j,children:[s,t&&e.jsx("span",{children:t})]})}function gn({initiative:t}){const{agentEntityMap:s,openModal:r,closeModal:x,authToken:o,embedMode:h,mutations:i}=Ze(),j=s.get(t.id)??[],[y,F]=n.useState(!1),[d,M]=n.useState(""),[_,m]=n.useState(!1),[l,g]=n.useState(!1),[b,u]=n.useState(null),[C,p]=n.useState(t.name),[v,B]=n.useState(t.description??""),[W,X]=n.useState(dt(t.priority)),[K,q]=n.useState(Tt(t.targetDate)),[T,Q]=n.useState(null),{details:N,isLoading:z}=Nt({initiativeId:t.id,authToken:o,embedMode:h}),U=N.tasks.filter(E=>["active","in_progress"].includes(E.status.toLowerCase())).length,ne=N.tasks.filter(E=>E.status.toLowerCase()==="blocked").length,L=N.tasks.filter(E=>Ae(E.status)).length,Y=T??t.status,oe=bn(T??t.rawStatus??t.status),c=["active","in_progress","running","queued"].includes(oe),te=["paused","draft","planned","todo","backlog","pending","not_started"].includes(oe),J=i.entityAction.isPending||i.createEntity.isPending||i.updateEntity.isPending||i.deleteEntity.isPending;n.useEffect(()=>{_||(p(t.name),B(t.description??""),q(Tt(t.targetDate)),X(dt(t.priority)))},[_,t.description,t.name,t.priority,t.targetDate]),n.useEffect(()=>{Q(null),g(!1)},[t.id,t.status,t.rawStatus]);const G=(E,se,ge)=>{u(null),i.entityAction.mutate({type:"initiative",id:t.id,action:E},{onSuccess:()=>{Q(se),u(ge)},onError:ye=>{u(ye instanceof Error?ye.message:`Failed to ${E} initiative.`)}})},Z=()=>{const E=C.trim();if(!E){u("Initiative title is required.");return}u(null),i.updateEntity.mutate({type:"initiative",id:t.id,title:E,summary:v.trim()||null,priority:W,target_date:K||null},{onSuccess:()=>{m(!1),u("Initiative updated.")},onError:se=>{u(se instanceof Error?se.message:"Failed to update initiative.")}})};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(Pe,{type:"initiative",size:16}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${yt[Y]??yt.active}`,children:ke(Y)}),e.jsx("span",{className:"rounded-full border border-white/[0.14] bg-white/[0.04] px-2 py-0.5 text-[10px] uppercase tracking-[0.08em] text-white/68",children:wn(t.priority)})]}),_?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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Title"}),e.jsx("input",{type:"text",value:C,onChange:E=>p(E.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Summary"}),e.jsx("textarea",{value:v,onChange:E=>B(E.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-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Target date"}),e.jsx("input",{type:"date",value:K,onChange:E=>q(E.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsxs("select",{value:W,onChange:E=>X(dt(E.target.value)),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 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-[13px] text-white/50 leading-relaxed",children:t.description}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No summary yet."}),j.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(kt,{agents:j,max:6})]}),b&&e.jsx("div",{className:"text-[11px] text-white/55",children:b})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(gt,{label:"Workstreams",value:`${N.workstreams.length}`}),e.jsx(gt,{label:"Milestones",value:`${N.milestones.length}`}),e.jsx(gt,{label:"Active Tasks",value:`${U}`,accent:U>0?O.lime:void 0}),e.jsx(gt,{label:"Blocked",value:`${ne}`,accent:ne>0?O.red:void 0})]}),z?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((E,se)=>e.jsx(ut,{className:"h-14 w-full rounded-lg"},`init-detail-${se}`))}):e.jsxs(e.Fragment,{children:[N.workstreams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ns,{title:"Workstreams",count:N.workstreams.length}),N.workstreams.map(E=>{const se=N.tasks.filter(ue=>ue.workstreamId===E.id),ge=se.filter(ue=>Ae(ue.status)).length,ye=se.length>0?Xe(ge,se.length):typeof E.progress=="number"?Ct(E.progress<=1?E.progress*100:E.progress):Ae(E.status)?100:null;return e.jsxs("button",{onClick:()=>r({type:"workstream",entity:E,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-[12px] text-white/90 break-words",children:E.name}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${fs(E.status)}`,children:ke(E.status)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-3 text-[10px] text-white/35 uppercase tracking-[0.08em]",children:[e.jsxs("span",{children:[se.length," tasks"]}),ye!==null&&e.jsxs("span",{children:[ye,"%"]})]})]},E.id)})]}),N.milestones.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ns,{title:"Milestones",count:N.milestones.length}),N.milestones.map(E=>e.jsxs("button",{onClick:()=>r({type:"milestone",entity:E,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-[12px] text-white/90 break-words",children:E.title}),e.jsx("span",{className:"text-[10px] text-white/40 uppercase tracking-[0.08em]",children:ke(E.status)})]}),E.dueDate&&e.jsxs("span",{className:"text-[10px] text-white/30 mt-0.5 block",children:["Due: ",new Date(E.dueDate).toLocaleDateString()]})]},E.id))]}),e.jsxs("div",{className:"text-[10px] uppercase tracking-[0.08em] text-white/30 pt-2 border-t border-white/[0.06]",children:[N.tasks.length," total tasks · ",L," done"]})]})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[c&&e.jsx(V,{label:"Pause",color:O.amber,onClick:()=>G("pause","paused","Initiative paused."),disabled:J}),te&&e.jsx(V,{label:oe==="paused"?"Resume":"Start",color:O.lime,variant:"primary",onClick:()=>G("resume","active",oe==="paused"?"Initiative resumed.":"Initiative started."),disabled:J}),_?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:Z,disabled:J||!C.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{m(!1),p(t.name),B(t.description??""),X(dt(t.priority)),q(Tt(t.targetDate)),u(null)},disabled:J})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{m(!0),u(null)},disabled:J}),e.jsx("div",{className:"flex-1"}),l?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/60",children:"Delete initiative?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>i.deleteEntity.mutate({type:"initiative",id:t.id},{onSuccess:()=>x(),onError:E=>u(E instanceof Error?E.message:"Failed to delete initiative.")}),disabled:J}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>g(!1),disabled:J})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>g(!0),disabled:J}),y?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:E=>{E.preventDefault(),d.trim()&&i.createEntity.mutate({type:"workstream",title:d.trim(),initiative_id:t.id,status:"not_started"},{onSuccess:()=>{M(""),F(!1)}})},children:[e.jsx("input",{type:"text",value:d,onChange:E=>M(E.target.value),placeholder:"Workstream name...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[180px] outline-none focus:border-white/25"}),e.jsx(V,{type:"submit",label:"Add",color:O.lime,disabled:!d.trim()||i.createEntity.isPending,size:"sm"}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{F(!1),M("")},size:"sm"})]}):e.jsx(V,{label:"+ Workstream",variant:"ghost",onClick:()=>F(!0),disabled:J})]})})]})}function Tt(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function bn(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function dt(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 wn(t){const s=dt(t);return s==="critical"?"Priority: Critical":s==="high"?"Priority: High":s==="low"?"Priority: Low":"Priority: Medium"}function gt({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-[10px] uppercase tracking-[0.08em] text-white/35",children:t}),e.jsx("div",{className:"text-[15px] font-medium mt-0.5",style:{color:r??"rgba(255,255,255,0.8)"},children:s})]})}function ns({title:t,count:s}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:t}),e.jsx("span",{className:"text-[10px] text-white/30",children:s})]})}function yn({workstream:t,initiative:s}){const{agentEntityMap:r,openModal:x,closeModal:o,authToken:h,embedMode:i,mutations:j}=Ze(),y=r.get(t.id)??r.get(s.id)??[],[F,d]=n.useState(!1),[M,_]=n.useState(""),[m,l]=n.useState(!1),[g,b]=n.useState(!1),[u,C]=n.useState(null),[p,v]=n.useState(t.name),[B,W]=n.useState(t.summary??""),[X,K]=n.useState(t.status),{details:q,isLoading:T}=Nt({initiativeId:s.id,authToken:h,embedMode:i}),Q=n.useMemo(()=>q.milestones.filter(c=>c.workstreamId===t.id),[q.milestones,t.id]),N=n.useMemo(()=>new Set(Q.map(c=>c.id)),[Q]),z=n.useMemo(()=>q.tasks.filter(c=>c.workstreamId===t.id||c.milestoneId!==null&&N.has(c.milestoneId)).sort((c,te)=>{const J=jt(c.status)-jt(te.status);if(J!==0)return J;const G=c.createdAt?Date.parse(c.createdAt):0;return(te.createdAt?Date.parse(te.createdAt):0)-G}),[q.tasks,N,t.id]),U=z.filter(c=>Ae(c.status)).length,ne=z.length>0?Xe(U,z.length):typeof t.progress=="number"?Ct(t.progress<=1?t.progress*100:t.progress):Ae(t.status)?100:null,L=t.status.toLowerCase(),Y=j.entityAction.isPending||j.createEntity.isPending||j.updateEntity.isPending||j.deleteEntity.isPending,oe=()=>{const c=p.trim();if(!c){C("Workstream name is required.");return}C(null),j.updateEntity.mutate({type:"workstream",id:t.id,title:c,summary:B.trim()||null,status:X},{onSuccess:()=>{l(!1),C("Workstream updated.")},onError:te=>{C(te instanceof Error?te.message:"Failed to update 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-[11px]",children:[e.jsx(Pe,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>x({type:"initiative",entity:s}),className:"break-words text-white/45 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-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Pe,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{type:"workstream",size:16}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${fs(t.status)}`,children:ke(t.status)})]}),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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Name"}),e.jsx("input",{type:"text",value:p,onChange:c=>v(c.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Summary"}),e.jsx("textarea",{value:B,onChange:c=>W(c.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-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("select",{value:X,onChange:c=>K(c.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30",children:["not_started","planned","active","in_progress","paused","blocked","done"].map(c=>e.jsx("option",{value:c,children:ke(c)},c))})]})]}):t.summary?e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.summary}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No summary yet."}),y.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(kt,{agents:y,max:6})]}),u&&e.jsx("div",{className:"text-[11px] text-white/55",children:u})]}),ne!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Progress"}),e.jsxs("span",{className:"text-[12px] text-white/60",children:[ne,"%"]})]}),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:`${ne}%`,backgroundColor:O.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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Tasks"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:z.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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Milestones"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:Q.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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Progress"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:ne!==null?`${ne}%`:"-"})]})]}),T?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((c,te)=>e.jsx(ut,{className:"h-12 w-full rounded-lg"},`ws-detail-${te}`))}):e.jsxs(e.Fragment,{children:[Q.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:"Milestones"}),Q.map(c=>e.jsx("button",{onClick:()=>x({type:"milestone",entity:c,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-[12px] text-white/90",children:c.title}),e.jsx("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${gs(c.status)}`,children:ke(c.status)})]})},c.id))]}),z.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:["Tasks (",z.length,")"]}),z.map(c=>e.jsxs("button",{onClick:()=>x({type:"task",entity:c,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-[12px] text-white/90",children:c.title}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ot(c.status)}`,children:ke(c.status)})]}),c.priority&&e.jsxs("span",{className:"text-[10px] text-white/30 mt-0.5 block uppercase tracking-wider",children:["Priority: ",c.priority]})]},c.id))]})]})]}),e.jsx("div",{className:"border-t border-white/[0.06] 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(V,{label:"Start",color:O.lime,variant:"primary",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"start"}),disabled:Y}),["active","in_progress"].includes(L)&&e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Complete",color:O.teal,variant:"primary",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"complete"}),disabled:Y}),e.jsx(V,{label:"Pause",color:O.amber,onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"pause"}),disabled:Y}),e.jsx(V,{label:"Block",color:O.red,variant:"destructive",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"block"}),disabled:Y})]}),["paused","blocked"].includes(L)&&e.jsx(V,{label:"Resume",color:O.lime,variant:"primary",onClick:()=>j.entityAction.mutate({type:"workstream",id:t.id,action:"resume"}),disabled:Y}),m?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:oe,disabled:Y||!p.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{l(!1),v(t.name),W(t.summary??""),K(t.status),C(null)},disabled:Y})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{l(!0),C(null)},disabled:Y}),e.jsx("div",{className:"flex-1"}),g?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/60",children:"Delete workstream?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>j.deleteEntity.mutate({type:"workstream",id:t.id},{onSuccess:()=>o(),onError:c=>C(c instanceof Error?c.message:"Failed to delete workstream.")}),disabled:Y}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>b(!1),disabled:Y})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>b(!0),disabled:Y}),F?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:c=>{c.preventDefault(),M.trim()&&j.createEntity.mutate({type:"task",title:M.trim(),workstream_id:t.id,initiative_id:s.id,status:"todo"},{onSuccess:()=>{_(""),d(!1)},onError:te=>{C(te instanceof Error?te.message:"Failed to create task.")}})},children:[e.jsx("input",{type:"text",value:M,onChange:c=>_(c.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(V,{label:"Add",color:O.lime,type:"submit",size:"sm",disabled:!M.trim()||j.createEntity.isPending}),e.jsx(V,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{d(!1),_("")}})]}):e.jsx(V,{label:"+ Task",variant:"ghost",onClick:()=>d(!0),disabled:Y})]})})]})}function jn({milestone:t,initiative:s}){const{openModal:r,closeModal:x,authToken:o,embedMode:h,mutations:i}=Ze(),[j,y]=n.useState(!1),[F,d]=n.useState(!1),[M,_]=n.useState(!1),[m,l]=n.useState(""),[g,b]=n.useState(null),[u,C]=n.useState(t.title),[p,v]=n.useState(t.description??""),[B,W]=n.useState(as(t.dueDate)),[X,K]=n.useState(t.status),{details:q}=Nt({initiativeId:s.id,authToken:o,embedMode:h}),T=q.tasks.filter(L=>L.milestoneId===t.id),Q=t.status.toLowerCase()==="done"||t.status.toLowerCase()==="completed",N=T.filter(L=>Ae(L.status)).length,z=T.length>0?Xe(N,T.length):Q?100:0,U=i.entityAction.isPending||i.createEntity.isPending||i.updateEntity.isPending||i.deleteEntity.isPending,ne=()=>{const L=u.trim();if(!L){b("Milestone title is required.");return}b(null),i.updateEntity.mutate({type:"milestone",id:t.id,title:L,description:p.trim()||null,due_date:B||null,status:X},{onSuccess:()=>{y(!1),b("Milestone updated.")},onError:Y=>{b(Y instanceof Error?Y.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-[11px]",children:[e.jsx(Pe,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>r({type:"initiative",entity:s}),className:"break-words text-white/45 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-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Pe,{type:"milestone",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-white/70",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Pe,{type:"milestone",size:16}),e.jsx("h2",{className:"text-[16px] font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${gs(t.status)}`,children:ke(t.status)})]}),j?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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Title"}),e.jsx("input",{type:"text",value:u,onChange:L=>C(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Description"}),e.jsx("textarea",{value:p,onChange:L=>v(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-[12px] text-white/90 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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due date"}),e.jsx("input",{type:"date",value:B,onChange:L=>W(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("select",{value:X,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-[12px] text-white/90 outline-none focus:border-white/30",children:["planned","active","in_progress","at_risk","blocked","done"].map(L=>e.jsx("option",{value:L,children:ke(L)},L))})]})]})]}):t.description?e.jsx("p",{className:"text-[13px] text-white/50 leading-relaxed",children:t.description}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No description yet."}),g&&e.jsx("div",{className:"text-[11px] text-white/55",children:g})]}),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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due Date"}),e.jsx("div",{className:"text-[13px] text-white/80 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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Associated Tasks"}),e.jsx("div",{className:"text-[15px] font-medium text-white/80 mt-0.5",children:T.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-[10px] uppercase tracking-[0.08em] text-white/35",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:`${z}%`,backgroundColor:O.teal}})}),e.jsxs("div",{className:"text-[12px] text-white/75",style:{fontVariantNumeric:"tabular-nums"},children:[z,"%"]})]}),e.jsxs("div",{className:"mt-1 text-[10px] text-white/35",children:[N,"/",T.length," done"]})]})]}),T.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-[11px] uppercase tracking-[0.08em] text-white/35",children:"Tasks"}),T.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-[12px] text-white/90",children:L.title}),e.jsx("span",{className:`text-[9px] px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Ot(L.status)}`,children:ke(L.status)})]})},L.id))]})]}),e.jsx("div",{className:"border-t border-white/[0.06] 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(V,{label:"Start",color:O.lime,variant:"primary",onClick:()=>i.entityAction.mutate({type:"milestone",id:t.id,action:"start"}),disabled:U}),!Q&&(t.status.toLowerCase()==="in_progress"||t.status.toLowerCase()==="at_risk")&&e.jsx(V,{label:T.length>0&&!T.every(L=>Ae(L.status))?"Complete (force)":"Complete",color:O.teal,variant:"primary",onClick:()=>{const L=T.length===0||T.every(Y=>Ae(Y.status));i.entityAction.mutate({type:"milestone",id:t.id,action:"complete",force:!L})},disabled:U}),j?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:ne,disabled:U||!u.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{y(!1),C(t.title),v(t.description??""),W(as(t.dueDate)),K(t.status),b(null)},disabled:U})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{y(!0),b(null)},disabled:U}),e.jsx("div",{className:"flex-1"}),F?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px] text-white/60",children:"Delete milestone?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>i.deleteEntity.mutate({type:"milestone",id:t.id},{onSuccess:()=>x(),onError:L=>b(L instanceof Error?L.message:"Failed to delete milestone.")}),disabled:U}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>d(!1),disabled:U})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>d(!0),disabled:U}),M?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:L=>{L.preventDefault(),m.trim()&&i.createEntity.mutate({type:"task",title:m.trim(),milestone_id:t.id,workstream_id:t.workstreamId??void 0,initiative_id:s.id,status:"todo"},{onSuccess:()=>{l(""),_(!1)},onError:Y=>{b(Y instanceof Error?Y.message:"Failed to create task.")}})},children:[e.jsx("input",{type:"text",value:m,onChange:L=>l(L.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-[12px] bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-white/80 placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(V,{label:"Add",color:O.lime,type:"submit",size:"sm",disabled:!m.trim()||i.createEntity.isPending}),e.jsx(V,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{_(!1),l("")}})]}):e.jsx(V,{label:"+ Task",variant:"ghost",onClick:()=>_(!0),disabled:U})]})})]})}function as(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function vn({task:t,initiative:s}){const{agentEntityMap:r,openModal:x,mutations:o,closeModal:h}=Ze(),i=r.get(t.id)??r.get(s.id)??[],[j,y]=n.useState(!1),[F,d]=n.useState(!1),[M,_]=n.useState(null),[m,l]=n.useState(t.title),[g,b]=n.useState(t.description??""),[u,C]=n.useState(t.priority??""),[p,v]=n.useState(is(t.dueDate)),[B,W]=n.useState(t.status),X=t.status.toLowerCase(),K=o.entityAction.isPending||o.updateEntity.isPending||o.deleteEntity.isPending,q=N=>{_(null),o.entityAction.mutate({type:"task",id:t.id,action:N},{onError:z=>{_(z instanceof Error?z.message:"Task action failed.")}})},T=()=>{const N=m.trim();if(!N){_("Task title is required.");return}_(null),o.updateEntity.mutate({type:"task",id:t.id,title:N,description:g.trim()||null,priority:u.trim()||null,due_date:p||null,status:B},{onSuccess:()=>{d(!1),_("Task updated.")},onError:z=>{_(z instanceof Error?z.message:"Failed to update task.")}})},Q=()=>{_(null),o.deleteEntity.mutate({type:"task",id:t.id},{onSuccess:()=>h(),onError:N=>{_(N instanceof Error?N.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-[11px]",children:[e.jsx(Pe,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>x({type:"initiative",entity:s}),className:"break-words text-white/45 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-white/20",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Pe,{type:"task",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-white/70",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(Pe,{type:"task",size:16}),e.jsx("h2",{className:"break-words text-[16px] font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-[10px] px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ot(t.status)}`,children:ke(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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Title"}),e.jsx("input",{type:"text",value:m,onChange:N=>l(N.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Description"}),e.jsx("textarea",{value:g,onChange:N=>b(N.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-[12px] text-white/90 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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsx("input",{type:"text",value:u,onChange:N=>C(N.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-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due date"}),e.jsx("input",{type:"date",value:p,onChange:N=>v(N.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("select",{value:B,onChange:N=>W(N.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-[12px] text-white/90 outline-none focus:border-white/30",children:["not_started","planned","todo","in_progress","active","blocked","done"].map(N=>e.jsx("option",{value:N,children:ke(N)},N))})]})]})]}):t.description?e.jsx(Bs,{text:t.description,mode:"block",className:"text-[13px] text-white/50 leading-relaxed"}):e.jsx("p",{className:"text-[12px] text-white/35",children:"No description yet."}),i.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/30 uppercase tracking-wider",children:"Agents"}),e.jsx(kt,{agents:i,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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Status"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:ke(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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Priority"}),e.jsx("div",{className:"text-[13px] text-white/80 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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Due Date"}),e.jsx("div",{className:"text-[13px] text-white/80 mt-0.5",children:t.dueDate?new Date(t.dueDate).toLocaleDateString():"-"})]})]}),M&&e.jsx("div",{className:"text-[11px] px-1",style:{color:`${O.red}b3`},children:M})]}),e.jsx("div",{className:"border-t border-white/[0.06] bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[X==="todo"&&e.jsx(V,{label:"Start",color:O.lime,variant:"primary",onClick:()=>q("start"),disabled:K}),(X==="in_progress"||X==="active")&&e.jsx(V,{label:"Complete",color:O.teal,variant:"primary",onClick:()=>q("complete"),disabled:K}),(X==="todo"||X==="in_progress"||X==="active")&&e.jsx(V,{label:"Block",color:O.red,variant:"destructive",onClick:()=>q("block"),disabled:K}),X==="blocked"&&e.jsx(V,{label:"Unblock",color:O.amber,onClick:()=>q("unblock"),disabled:K}),F?e.jsxs(e.Fragment,{children:[e.jsx(V,{label:"Save",color:O.teal,variant:"primary",onClick:T,disabled:K||!m.trim()}),e.jsx(V,{label:"Cancel",variant:"ghost",onClick:()=>{d(!1),_(null),l(t.title),b(t.description??""),C(t.priority??""),v(is(t.dueDate)),W(t.status)},disabled:K})]}):e.jsx(V,{label:"Edit",variant:"ghost",onClick:()=>{d(!0),_(null)},disabled:K}),e.jsx("div",{className:"flex-1"}),j?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[11px]",style:{color:`${O.red}b3`},children:"Delete?"}),e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:Q,disabled:K}),e.jsx(V,{label:"Keep",variant:"ghost",onClick:()=>y(!1),disabled:K})]}):e.jsx(V,{label:"Delete",color:O.red,variant:"destructive",onClick:()=>y(!0),disabled:K})]})})]})}function is(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function Nn(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 kn({target:t,onClose:s}){return e.jsx(Ms,{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-white/[0.06] px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-white/50",children:[Nn(t).map((r,x,o)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[x>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-white/25",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:`truncate ${x===o.length-1?"text-white/80 font-medium":""}`,children:r})]},x)),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-[10px] uppercase tracking-[0.06em] text-white/52",children:[e.jsx(Pe,{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-white/[0.12] bg-white/[0.03] text-white/70 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(gn,{initiative:t.entity}),t.type==="workstream"&&e.jsx(yn,{workstream:t.entity,initiative:t.initiative}),t.type==="milestone"&&e.jsx(jn,{milestone:t.entity,initiative:t.initiative}),t.type==="task"&&e.jsx(vn,{task:t.entity,initiative:t.initiative})]})]})})}function rs(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Cn(t){return t.split("_").map(s=>s.slice(0,1).toUpperCase()+s.slice(1)).join(" ")}const Lt=["active","in_progress","not_started","planned","blocked","at_risk","paused","completed","done","backlog","todo","pending","draft"],Sn=[{value:"target",label:"Target date"},{value:"created",label:"Created at"},{value:"updated",label:"Updated at"}],Fn=[{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"}],Dn=[{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 En({initiatives:t,visibleCount:s}){const{statusFilters:r,dateField:x,datePreset:o,dateStart:h,dateEnd:i,activeFilterCount:j,groupBy:y,setGroupBy:F,sortBy:d,setSortBy:M,setStatusFilters:_,toggleStatusFilter:m,setDateField:l,setDatePreset:g,setDateStart:b,setDateEnd:u,clearFilters:C}=Ze(),[p,v]=n.useState(!1),[B,W]=n.useState(!1),X=n.useRef(null);n.useEffect(()=>{if(!p)return;const c=J=>{var Z;const G=J.target;G&&((Z=X.current)!=null&&Z.contains(G)||v(!1))},te=J=>{J.key==="Escape"&&v(!1)};return document.addEventListener("mousedown",c),document.addEventListener("keydown",te),()=>{document.removeEventListener("mousedown",c),document.removeEventListener("keydown",te)}},[p]);const K=n.useMemo(()=>{const c=new Map;for(const J of t){const G=new Set([rs(J.status),rs(J.rawStatus)]);for(const Z of G)Z&&c.set(Z,(c.get(Z)??0)+1)}for(const J of Lt)c.has(J)||c.set(J,0);return Array.from(c.entries()).sort((J,G)=>{const Z=Lt.indexOf(J[0]),E=Lt.indexOf(G[0]);return Z>=0&&E>=0?Z-E:Z>=0?-1:E>=0?1:J[0].localeCompare(G[0])}).map(([J,G])=>({key:J,count:G}))},[t]),q=r.length,T=n.useMemo(()=>K.filter(c=>B||c.count>0||r.includes(c.key)),[B,r,K]),Q=K.length-T.length,N=n.useMemo(()=>x==="target"?Fn:Dn,[x]);n.useEffect(()=>{N.some(c=>c.value===o)||g("any")},[o,N,g]);const z=[{value:"none",label:"None"},{value:"status",label:"Status"},{value:"date",label:"Date"},{value:"category",label:"Category"}],U=[{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)"}],ne=y!=="status"||d!=="default",L=j>0,Y=j,oe=L||ne;return e.jsxs("div",{ref:X,className:"relative flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{v(c=>{const te=!c;return te||W(!1),te})},"data-state":p||Y>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3 text-[11px] 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"}),Y>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-[10px] leading-4",children:Y})]}),s<t.length&&e.jsxs("span",{className:"text-[10px] text-white/35 whitespace-nowrap",children:[s,"/",t.length]}),e.jsx(Le,{initial:!1,children:L&&e.jsx(le.button,{type:"button",onClick:C,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-[10px] text-white/40 transition-colors whitespace-nowrap hover:text-white/70",children:"Clear"})}),e.jsx(Le,{children:p&&e.jsxs(le.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 right-0 top-12 z-30 w-[360px] max-w-[94vw] rounded-xl p-3.5 shadow-[0_16px_40px_rgba(0,0,0,0.45)] backdrop-blur-xl",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-[11px] font-semibold tracking-[0.01em] text-white/85",children:"Filters"}),e.jsx("div",{className:"text-[10px] text-white/45",children:"Scope the Mission Control list view"})]}),L?e.jsxs("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/70",children:[Y," active"]}):ne?e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/60",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-[10px] uppercase tracking-[0.08em] text-white/35",children:"Group"}),e.jsx("select",{value:y,onChange:c=>F(c.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-[11px] text-white/80 focus:border-[#BFFF00]/40 focus:outline-none",children:z.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/35",children:"Sort"}),e.jsx("select",{value:d,onChange:c=>M(c.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-[11px] text-white/80 focus:border-[#BFFF00]/40 focus:outline-none",children:U.map(c=>e.jsx("option",{value:c.value,children:c.label},c.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:()=>W(c=>!c),className:"text-[10px] text-white/42 transition-colors hover:text-white/72",children:B?"Hide empty":`Show empty (${Q})`})]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-auto pr-1",children:T.map(c=>{const te=r.includes(c.key);return e.jsxs("label",{className:`flex cursor-pointer items-center justify-between rounded-md border px-2.5 py-1.5 text-[11px] transition-colors ${te?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-white/88":"border-white/[0.08] bg-white/[0.02] text-white/78 hover:border-white/[0.15]"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:te,onChange:()=>m(c.key),className:"h-3.5 w-3.5 accent-[#BFFF00]"}),e.jsx("span",{children:Cn(c.key)})]}),e.jsx("span",{className:"text-[10px] text-white/48",children:c.count})]},c.key)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>_([]),className:`text-[10px] uppercase tracking-[0.08em] ${q>0?"text-white/70 hover:text-white":"text-white/35"}`,disabled:q===0,children:"Clear status"}),e.jsxs("div",{className:"text-[10px] text-white/45",children:[q," 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-[10px] uppercase tracking-[0.08em] text-white/45",children:"Field"}),e.jsx("select",{value:x,onChange:c=>l(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none",children:Sn.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"Condition"}),e.jsx("select",{value:o,onChange:c=>g(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none",children:N.map(c=>e.jsx("option",{value:c.value,children:c.label},c.value))})]})]}),o==="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-[10px] uppercase tracking-[0.08em] text-white/45",children:"Start"}),e.jsx("input",{type:"date",value:h,onChange:c=>b(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-[0.08em] text-white/45",children:"End"}),e.jsx("input",{type:"date",value:i,onChange:c=>u(c.target.value),className:"h-9 rounded-lg border border-white/[0.12] bg-black/30 px-2 text-[11px] text-white focus:border-[#BFFF00]/40 focus:outline-none"})]})]})]}),oe&&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:[ne&&e.jsx("button",{type:"button",onClick:()=>{F("status"),M("default")},className:"text-[10px] uppercase tracking-[0.09em] text-white/55 transition-colors hover:text-white/85",children:"Reset layout"}),L&&e.jsx("button",{type:"button",onClick:C,className:"text-[10px] uppercase tracking-[0.09em] text-white/55 transition-colors hover:text-white/85",children:"Clear filters"})]})]})]})})]})}function Pt(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Rt(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}function ls(t){if(!t)return null;const s=Date.parse(`${t}T00:00:00`);return Number.isFinite(s)?s:null}function An(t,s){return s==="target"?t.targetDate??null:s==="created"?t.createdAt??null:t.updatedAt??t.createdAt??null}function os(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 cs(t){return t==="active"?0:t==="blocked"?1:t==="paused"?2:3}function ds(t,s){if(s==="status"){const r=new Map,x=["active","blocked","paused","completed"];for(const o of t){const h=o.status??"active",i=r.get(h)??[];i.push(o),r.set(h,i)}return x.filter(o=>r.has(o)).concat(Array.from(r.keys()).filter(o=>!x.includes(o))).map(o=>{var h;return{key:o,label:o.charAt(0).toUpperCase()+o.slice(1),count:((h=r.get(o))==null?void 0:h.length)??0,initiatives:r.get(o)??[]}})}if(s==="category"){const r=new Map;for(const x of t){const o=x.category??"Uncategorized",h=r.get(o)??[];h.push(x),r.set(o,h)}return Array.from(r.entries()).sort((x,o)=>x[0].localeCompare(o[0])).map(([x,o])=>({key:x,label:x,count:o.length,initiatives:o}))}if(s==="date"){const x=Rt(new Date),o=x+7*864e5,h=x+30*864e5,i={overdue:[],this_week:[],this_month:[],later:[],no_date:[]};for(const y of t){const F=y.targetDate?Date.parse(y.targetDate):null;F===null||!Number.isFinite(F)?i.no_date.push(y):F<x?i.overdue.push(y):F<o?i.this_week.push(y):F<h?i.this_month.push(y):i.later.push(y)}const j={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(y=>i[y].length>0).map(y=>({key:y,label:j[y],count:i[y].length,initiatives:i[y]}))}return[]}function lt(t,s){return`${t}:${s}`}function Bn(t){return`mc-group-${t}`.toLowerCase().replace(/[^a-z0-9_-]+/g,"-")}function us(t,s){if(t.size!==s.size)return!1;for(const r of t)if(!s.has(r))return!1;return!0}function Mn(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 In(t){return t==="running"?"border-teal-300/35 bg-teal-400/[0.12] text-teal-100":t==="blocked"?"border-red-400/35 bg-red-500/[0.12] text-red-100":t==="queued"||t==="startable"?"border-[#BFFF00]/30 bg-[#BFFF00]/12 text-[#E1FFB2]":t==="completed"?"border-white/[0.16] bg-white/[0.05] text-white/60":"border-white/[0.16] bg-white/[0.05] text-white/68"}function On({initiatives:t,activities:s,agents:r,runtimeInstances:x=[],isLoading:o,authToken:h,embedMode:i,initialInitiativeId:j,connection:y,lastSnapshotAt:F,error:d,hasApiKey:M,onOpenSettings:_,onRefresh:m,onFollowWorkstream:l}){const g=_s({activities:s,agents:r,initiatives:t});return e.jsx(zs,{agentEntityMap:g,authToken:h,embedMode:i,children:e.jsx(_n,{initiatives:t,runtimeInstances:x,isLoading:o,initialInitiativeId:j,connection:y,lastSnapshotAt:F,error:d,hasApiKey:M,onOpenSettings:_,onRefresh:m,onFollowWorkstream:l})})}function $n(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 _n({initiatives:t,runtimeInstances:s,isLoading:r,initialInitiativeId:x,connection:o,lastSnapshotAt:h,error:i,hasApiKey:j,onOpenSettings:y,onRefresh:F,onFollowWorkstream:d}){var Jt;const{searchQuery:M,setSearchQuery:_,statusFilters:m,setStatusFilters:l,dateField:g,setDateField:b,datePreset:u,setDatePreset:C,dateStart:p,setDateStart:v,dateEnd:B,setDateEnd:W,clearFilters:X,hasActiveFilters:K,groupBy:q,sortBy:T,expandedInitiatives:Q,expandAll:N,collapseAll:z,modalTarget:U,closeModal:ne,expandInitiative:L,authToken:Y,embedMode:oe,mutations:c}=Ze(),te=n.useRef(!1),J=n.useRef(null),G=n.useRef(0),[Z,E]=n.useState(0),[se,ge]=n.useState(new Set),[ye,ue]=n.useState(!1),[Be,Qe]=n.useState(!1),[Me,Re]=n.useState(!1),[et,me]=n.useState(!1),[be,pe]=n.useState(null),[ze,Oe]=n.useState(new Set),[Ie,Ee]=n.useState(!1),[Ve,we]=n.useState(null),Ge=n.useMemo(()=>{const A=Rt(new Date),R=M.toLowerCase().trim().split(/\s+/).filter(Boolean);return t.filter(H=>{if(m.length>0&&![Pt(H.status),Pt(H.rawStatus)].filter(Boolean).some(Te=>m.includes(Te)))return!1;const ce=An(H,g),fe=ce?Date.parse(ce):Number.NaN,Ne=Number.isFinite(fe)?Rt(new Date(fe)):null,ae=Ne===null?null:Math.round((Ne-A)/864e5);if(u==="missing"&&Ne!==null||u==="overdue"&&!(ae!==null&&ae<0)||u==="today"&&ae!==0||u==="next_7_days"&&!(ae!==null&&ae>=0&&ae<=7)||u==="next_30_days"&&!(ae!==null&&ae>=0&&ae<=30)||u==="past_7_days"&&!(ae!==null&&ae<=0&&ae>=-7)||u==="past_30_days"&&!(ae!==null&&ae<=0&&ae>=-30))return!1;if(u==="custom_range"){const We=ls(p),Te=ls(B);if(Ne===null||We!==null&&Ne<We||Te!==null&&Ne>Te)return!1}if(R.length===0)return!0;const it=[H.name,H.description??"",H.status,H.rawStatus??"",H.category??""].join(" ").toLowerCase();return R.every(We=>it.includes(We))})},[t,M,m,g,u,p,B]),re=n.useMemo(()=>{const f=(A,R,H)=>{const ce=A.targetDate?Date.parse(A.targetDate):Number.NaN,fe=R.targetDate?Date.parse(R.targetDate):Number.NaN,Ne=Number.isFinite(ce),ae=Number.isFinite(fe);return!Ne&&!ae?0:Ne?ae?H==="asc"?ce-fe:fe-ce:-1:1};return[...Ge].sort((A,R)=>{if(T==="date_asc")return f(A,R,"asc");if(T==="date_desc")return f(A,R,"desc");const H=os(A.priority),ce=os(R.priority);if(T==="priority_high"&&H!==ce)return H-ce;if(T==="priority_low"&&H!==ce)return ce-H;if(T==="default"){const ae=cs(A.status)-cs(R.status);if(ae!==0)return ae;if(H!==ce)return H-ce}const fe=A.updatedAt?Date.parse(A.updatedAt):0,Ne=R.updatedAt?Date.parse(R.updatedAt):0;return fe!==Ne?Ne-fe:A.name.localeCompare(R.name)})},[Ge,T]),$e=n.useMemo(()=>new Set(re.map(f=>f.id)),[re]),_e=n.useMemo(()=>re.filter(f=>ze.has(f.id)),[ze,re]),Ce=_e.length,a=re.length>0&&Ce===re.length,k=c.bulkEntityMutation.isPending,S=n.useMemo(()=>{var R;const f=new Map;for(const H of s){const ce=(R=H.initiativeId)==null?void 0:R.trim();if(!ce)continue;const fe=f.get(ce)??{activeCount:0,totalCount:0,lastHeartbeatAt:null,lastHeartbeatMs:0};fe.totalCount+=1,H.state==="active"&&(fe.activeCount+=1);const Ne=H.lastHeartbeatAt??H.lastEventAt??null,ae=Ne?Date.parse(Ne):Number.NaN;Number.isFinite(ae)&&ae>fe.lastHeartbeatMs&&(fe.lastHeartbeatMs=ae,fe.lastHeartbeatAt=new Date(ae).toISOString()),f.set(ce,fe)}const A=new Map;for(const[H,ce]of f.entries())A.set(H,{activeCount:ce.activeCount,totalCount:ce.totalCount,lastHeartbeatAt:ce.lastHeartbeatAt});return A},[s]),$=n.useMemo(()=>q!=="none"?ds(re,q):null,[re,q]),ee=n.useMemo(()=>($==null?void 0:$.map(f=>lt(q,f.key)))??[],[q,$]),je=n.useCallback(f=>{ge(A=>{const R=new Set(A);return R.has(f)?R.delete(f):R.add(f),R})},[]);n.useEffect(()=>{if(!$||$.length===0){ge(A=>A.size===0?A:new Set);return}const f=new Set($.map(A=>lt(q,A.key)));ge(A=>{const R=new Set(Array.from(A).filter(H=>f.has(H)));return R.size===0&&R.add(lt(q,$[0].key)),us(R,A)?A:R})},[q,$]),n.useEffect(()=>{Oe(f=>{if(f.size===0)return f;const A=new Set(Array.from(f).filter(R=>$e.has(R)));return us(A,f)?f:A})},[$e]),n.useEffect(()=>{if(x&&!te.current&&!r&&t.length>0){if(L(x),$){const f=$.find(A=>A.initiatives.some(R=>R.id===x));if(f){const A=lt(q,f.key);ge(R=>{if(R.has(A))return R;const H=new Set(R);return H.add(A),H})}}te.current=!0,requestAnimationFrame(()=>{const f=document.getElementById(`initiative-${x}`);f==null||f.scrollIntoView({behavior:"smooth",block:"start"})})}},[x,r,t.length,L,q,$]),n.useEffect(()=>{Ce===0&&Ie&&Ee(!1)},[Ie,Ce]);const xe=re.length>0&&Q.size>=re.length,Se=n.useMemo(()=>re.find(f=>f.status!=="completed")??re[0]??null,[re]),he=Is({initiativeId:null,authToken:Y,embedMode:oe,enabled:t.length>0}),D=he.items[0]??null,P=n.useMemo(()=>D?t.find(f=>f.id===D.initiativeId)??Se:Se,[Se,t,D]),I=(P==null?void 0:P.id)??null,de=n.useCallback((f,A)=>{we(null),Ee(!1),Oe(R=>{const H=new Set(R);return A?H.add(f):H.delete(f),H})},[]),w=n.useCallback(()=>{we(null),Ee(!1),Oe(f=>re.length===0?f:a?new Set:new Set(re.map(A=>A.id)))},[a,re]),ie=n.useCallback(()=>{Ee(!1),Oe(new Set)},[]),qe=n.useCallback(async f=>{if(_e.length!==0){Ee(!1),we(null);try{const A=await c.bulkEntityMutation.mutateAsync({items:_e.map(R=>({type:"initiative",id:R.id})),mode:"update",updates:{status:f}});A.failed>0?we({tone:"error",message:`Updated ${A.updated}, failed ${A.failed}.`}):we({tone:"success",message:`Updated ${A.updated} initiative${A.updated===1?"":"s"} to ${f}.`})}catch(A){we({tone:"error",message:A instanceof Error?A.message:"Bulk initiative update failed."})}}},[c.bulkEntityMutation,_e]),Ue=n.useCallback(async()=>{if(_e.length!==0){we(null);try{const f=await c.bulkEntityMutation.mutateAsync({items:_e.map(A=>({type:"initiative",id:A.id})),mode:"delete"});f.failed>0?we({tone:"error",message:`Deleted ${f.updated}, failed ${f.failed}.`}):(we({tone:"success",message:`Deleted ${f.updated} initiative${f.updated===1?"":"s"}.`}),Oe(new Set),Ee(!1))}catch(f){we({tone:"error",message:f instanceof Error?f.message:"Bulk initiative delete failed."})}}},[c.bulkEntityMutation,_e]),He=n.useCallback(()=>{G.current+=1,ue(!1)},[]),tt=n.useCallback(f=>{if(f.length===0){He();return}const A=1,R=G.current+1;G.current=R,ue(!0);const H=ce=>{if(G.current===R){if(N(f.slice(0,ce)),ce>=f.length){ue(!1);return}requestAnimationFrame(()=>H(Math.min(f.length,ce+A)))}};H(Math.min(A,f.length))},[He,N]),Fe=Ts({initiativeId:I,authToken:Y,embedMode:oe,enabled:!!I}),st=Fe.run,ot=((Jt=Fe.error)==null?void 0:Jt.toLowerCase())??"",pt=!I||ot.includes("404")||ot.includes("400")||ot.includes("not found"),De=I?S.get(I)??null:null,nt=((De==null?void 0:De.activeCount)??0)>0,xt=((De==null?void 0:De.totalCount)??0)>0,qt=I?Fe.isRunning?nt?`Running · ${(De==null?void 0:De.activeCount)??0} live`:xt?`Enabled · ${(De==null?void 0:De.totalCount)??0} idle`:"Enabled · waiting":st!=null&&st.stopReason?`Idle · ${st.stopReason.replace(/_/g," ")}`:"Idle":"No target";n.useEffect(()=>{const f=J.current;if(!f)return;const A=()=>{E(Math.max(64,f.offsetHeight))};if(A(),typeof ResizeObserver>"u")return;const R=new ResizeObserver(()=>A());return R.observe(f),()=>R.disconnect()},[qt,o,i,r,re.length]);const St=!!(!r&&j&&(o==="disconnected"||i)),Ut=!!(o==="disconnected"||i);n.useEffect(()=>{if(!St){Qe(!1);return}Ut&&Qe(!0)},[St,Ut]);const Wt=o==="disconnected"||i?"critical":"info",bs=Wt==="critical"?"border-red-400/30 bg-red-500/14 text-red-100":"border-white/[0.14] bg-white/[0.08] text-white/75",ws=o==="disconnected"?"Offline":i?"Live degraded":"Connected",Ht=i||(o==="disconnected"?"Data may be stale":`Last snapshot ${$n(h)}`),Ke=n.useCallback((f,A)=>{if(!t.find(ae=>ae.id===f))return pe({tone:"error",message:A?`${A} is unavailable in the current initiative list.`:"Initiative is unavailable in the current initiative list."}),!1;pe(null);const H=$e.has(f),ce=!H;if(ce&&(_(""),l([]),b("target"),C("any"),v(""),W("")),L(f),q!=="none"){const We=ds(H?re:t,q).find(Te=>Te.initiatives.some(rt=>rt.id===f));if(We){const Te=lt(q,We.key);ge(rt=>{if(rt.has(Te))return rt;const Yt=new Set(rt);return Yt.add(Te),Yt})}}const fe=(ae=0)=>{const it=document.getElementById(`initiative-${f}`);if(it){it.scrollIntoView({behavior:ae===0?"smooth":"auto",block:"start"});const We=Math.max(72,Z)+8,Te=it.getBoundingClientRect();!(Te.top>=We&&Te.top<=window.innerHeight-72)&&ae<18&&window.setTimeout(()=>fe(ae+1),90);return}ae>=60||requestAnimationFrame(()=>fe(ae+1))},Ne=()=>requestAnimationFrame(()=>fe());return ce?window.setTimeout(Ne,90):Ne(),!0},[t,$e,pe,_,l,b,C,v,W,L,q,re,Z]),Ft=n.useCallback(f=>{d==null||d(f),me(!1)},[d]),ys=n.useCallback(()=>{P&&(pe(null),c.updateEntity.mutateAsync({type:"initiative",id:P.id,status:"active"}).then(()=>{pe({tone:"success",message:`Started ${P.name}.`}),Ke(P.id,P.name)}).catch(f=>{pe({tone:"error",message:f instanceof Error?f.message:"Failed to start initiative."})}))},[c.updateEntity,P,Ke]),Vt=n.useCallback(()=>{if(!D){P&&Ke(P.id,P.name);return}pe(null),he.playWorkstream({initiativeId:D.initiativeId,workstreamId:D.workstreamId,agentId:D.runnerAgentId}).then(()=>{pe({tone:"success",message:`Dispatched ${D.workstreamTitle}.`})}).catch(f=>{pe({tone:"error",message:f instanceof Error?f.message:"Failed to dispatch next workstream."})})},[he,D,P,Ke]),js=n.useCallback(()=>{P&&(Ke(P.id,P.name),typeof window<"u"&&window.innerWidth>=1280&&Re(!0))},[P,Ke]),Dt=n.useCallback(()=>{if(typeof window<"u"&&window.innerWidth>=1280){me(!1),Re(f=>!f);return}me(!0)},[]),at=Pt((P==null?void 0:P.rawStatus)??(P==null?void 0:P.status)??null),Gt=n.useMemo(()=>new Set(["paused","draft","planned","todo","backlog","queued"]),[]),ve=n.useMemo(()=>{var f;return P?(D==null?void 0:D.queueState)==="running"||((f=D==null?void 0:D.autoContinue)==null?void 0:f.status)==="running"?"running":(D==null?void 0:D.queueState)==="blocked"||P.status==="blocked"?"blocked":D?"queued":Gt.has(at)?"startable":at==="completed"||at==="done"?"completed":"active_no_queue":"none"},[P,D,Gt,at]),Et=n.useMemo(()=>P?ve==="running"&&D?{headline:`${D.workstreamTitle} is running`,detail:`Runner: ${D.runnerAgentName}. Follow live updates in Activity.`}:ve==="queued"&&D?{headline:D.workstreamTitle,detail:`Ready to dispatch${D.nextTaskTitle?` · ${D.nextTaskTitle}`:""}.`}:ve==="startable"?{headline:at==="paused"?`${P.name} is paused`:`${P.name} is ready to start`,detail:"Start initiative to queue and dispatch the next workstream."}:ve==="blocked"?{headline:(D==null?void 0:D.queueState)==="blocked"?`${D.workstreamTitle} is blocked`:`${P.name} is blocked`,detail:(D==null?void 0:D.blockReason)??"Resolve blockers or approvals before dispatching more work."}:ve==="completed"?{headline:`${P.name} is complete`,detail:"Choose another active initiative or queue new workstreams."}:{headline:P.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."},[P,ve,D,at]),At=he.isPlaying||he.isStartingAutoContinue||he.isStoppingAutoContinue||c.updateEntity.isPending,vs=n.useMemo(()=>ve==="blocked"?"Review blockers":ve==="active_no_queue"?"Open and queue work":ve==="completed"?"Review initiative":"Open initiative",[ve]),Kt=D?D.workstreamTitle:"No queued workstream",Ns=(D==null?void 0:D.initiativeTitle)??(P==null?void 0:P.name)??"No initiative selected",Bt=(D==null?void 0:D.nextTaskTitle)??Et.detail,ks=Mn(ve),Cs=In(ve),Mt="next-up-surface",It=n.useMemo(()=>({type:"spring",stiffness:340,damping:38,mass:.72}),[]),Ss=n.useMemo(()=>({backgroundColor:"rgba(18, 26, 39, 0.9)",borderColor:"rgba(191, 255, 0, 0.24)"}),[]),Qt=n.useMemo(()=>({backgroundColor:"rgba(10, 14, 21, 0.95)",borderColor:"rgba(255, 255, 255, 0.11)"}),[]),Fs=n.useMemo(()=>{if(!U)return null;const f=R=>t.find(H=>H.id===R)??null;if(U.type==="initiative"){const R=f(U.entity.id);return R?{...U,entity:R}:U}const A=f(U.initiative.id);return A?{...U,initiative:A}:U},[t,U]);return n.useEffect(()=>{pe(null)},[P==null?void 0:P.id,D==null?void 0:D.initiativeId,D==null?void 0:D.workstreamId]),n.useEffect(()=>{if(!U)return;const f=U.type==="initiative"?U.entity.id:U.initiative.id;t.some(R=>R.id===f)||ne()},[ne,t,U]),n.useEffect(()=>{if(typeof window>"u")return;const f=()=>{window.innerWidth>=1280?me(!1):Re(!1)};return f(),window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[]),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":`${Z}px`},children:[e.jsxs($s,{id:"next-up-morph",children:[e.jsxs("div",{ref:J,className:"sticky top-0 z-40 relative -mx-4 border-b border-white/[0.05] bg-[#02040A]/78 px-4 pb-2.5 pt-3.5 backdrop-blur-xl sm:-mx-6 sm:px-6",children:[e.jsx(Le,{initial:!1,children:Be&&St&&e.jsx(le.div,{initial:{opacity:0,y:-6,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-6,scale:.98},transition:{duration:.18,ease:[.22,1,.36,1]},className:"pointer-events-none absolute right-4 top-2.5 z-50 sm:right-6",children:e.jsxs("div",{className:`pointer-events-auto inline-flex max-w-[540px] items-center gap-2 rounded-full border px-2.5 py-1.5 shadow-[0_10px_24px_rgba(0,0,0,0.35)] ${bs}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${Wt==="critical"?"bg-red-300":"bg-white/70"}`}),e.jsx("span",{className:"text-[10px] font-semibold uppercase tracking-[0.08em]",children:ws}),e.jsx("span",{className:"max-w-[280px] truncate text-[11px] opacity-85",title:Ht,children:Ht}),e.jsxs("div",{className:"flex items-center gap-1",children:[F&&e.jsx("button",{type:"button",onClick:F,className:"h-6 rounded-full border border-white/[0.16] bg-white/[0.08] px-2 text-[10px] font-semibold text-current transition-colors hover:bg-white/[0.15]",children:"Refresh"}),y&&e.jsx("button",{type:"button",onClick:y,className:"h-6 rounded-full border border-white/[0.16] bg-white/[0.08] px-2 text-[10px] font-semibold text-current transition-colors hover:bg-white/[0.15]",children:"Settings"})]})]})})}),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(hs,{value:M,onChange:_,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(En,{initiatives:t,visibleCount:Ge.length}),e.jsxs("div",{className:"hidden min-w-[220px] max-w-[320px] items-center gap-2 rounded-lg border border-white/[0.12] bg-white/[0.03] px-2.5 py-1.5 xl:flex",title:(P==null?void 0:P.name)??void 0,children:[e.jsx("span",{className:"text-[10px] 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-[10px] text-white/72",children:qt}),P&&e.jsx("div",{className:"truncate text-[10px] text-white/44",children:P.name})]})]}),e.jsxs("button",{type:"button",onClick:()=>{if(pt||!I)return;(Fe.isRunning?Fe.stop:Fe.start)().catch(A=>{console.warn("[autopilot] toggle failed",A)})},disabled:pt||Fe.isStarting||Fe.isStopping,title:pt?"Select an initiative to run Autopilot":Fe.isRunning?"Stop Autopilot":`Start Autopilot${P?` for ${P.name}`:""}`,"data-state":Fe.isRunning?"active":"idle","data-tone":"teal",className:"control-pill flex items-center gap-1.5 px-3 text-[11px] font-semibold disabled:opacity-40",children:[Fe.isRunning?nt?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.jsxs("span",{children:[Fe.isRunning?"Stop":"Start"," Autopilot"]}),Fe.isRunning&&nt&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0AD4C4] status-breathe"})]}),re.length>0&&e.jsx("button",{type:"button",onClick:()=>{xe?(He(),z(),$&&ee.length>0&&ge(new Set)):(tt(re.map(f=>f.id)),$&&ee.length>0&&ge(new Set(ee)))},title:xe?"Collapse all":"Expand all","aria-busy":ye&&!xe,className:"control-pill flex h-8 w-8 flex-shrink-0 items-center justify-center text-white/55",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:xe?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"})]})})})]})]}),re.length>0&&e.jsxs("div",{"data-mc-selection-bar":"true",className:`mt-2.5 flex min-h-12 flex-nowrap items-center gap-2 overflow-x-auto rounded-xl border px-3 py-1 whitespace-nowrap ${Ce>0?"border-[#BFFF00]/24 bg-[#BFFF00]/[0.08]":"border-white/[0.08] bg-white/[0.02]"}`,children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-[11px] text-white/75",children:[e.jsx("input",{type:"checkbox",checked:a,onChange:w,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"}),"Select visible"]}),e.jsx("span",{className:"flex-shrink-0 text-[11px] text-white/58",children:Ce>0?`${Ce} selected`:`${re.length} visible`}),Ce>0&&e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{qe("active")},disabled:k,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:"Mark active"}),e.jsx("button",{type:"button",onClick:()=>{qe("paused")},disabled:k,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Pause"}),e.jsx("button",{type:"button",onClick:()=>{qe("blocked")},disabled:k,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{qe("completed")},disabled:k,className:"control-pill h-8 flex-shrink-0 px-3 text-[11px] font-semibold disabled:opacity-45",children:"Complete"}),Ie?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{Ue()},disabled:k,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-[11px] font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>Ee(!1),disabled:k,className:"control-pill h-8 flex-shrink-0 px-2.5 text-[11px] disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>Ee(!0),disabled:k,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-[11px] font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:ie,disabled:k,className:"text-[11px] text-white/55 transition-colors hover:text-white/80 disabled:opacity-45",children:"Clear"})]}),e.jsx(Le,{initial:!1,mode:"popLayout",children:!Me&&!et&&e.jsxs(le.div,{layout:"position",layoutId:Mt,initial:{opacity:0,y:4},animate:{opacity:1,y:0,...Ss},exit:{opacity:0,y:-4},transition:{layout:It,duration:.2,ease:[.22,1,.36,1]},className:"ml-auto flex min-w-[320px] max-w-[640px] flex-shrink-0 items-center gap-3 overflow-hidden rounded-xl border px-2.5 py-2 shadow-[0_14px_30px_rgba(0,0,0,0.32)] backdrop-blur-[10px]",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2.5",children:[D?e.jsx(zt,{name:D.runnerAgentName,hint:`${D.runnerAgentId} ${D.runnerSource}`,size:"xs"}):e.jsx("div",{className:"h-6 w-6 rounded-full border border-white/[0.16] 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-[10px] font-semibold uppercase tracking-[0.08em] text-white/76",children:"Next Up"}),e.jsx("span",{className:`rounded-full border px-1.5 py-[1px] text-[9px] uppercase tracking-[0.07em] ${Cs}`,children:ks})]}),e.jsx("p",{className:"truncate text-[11px] font-semibold text-white/92",title:Kt,children:Kt}),e.jsxs("p",{className:"truncate text-[9px] text-white/56",title:Bt,children:[Ns,Bt?` · ${Bt}`:""]})]})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[e.jsx("button",{type:"button",onClick:Vt,disabled:!D||At,className:"control-pill h-7 flex-shrink-0 px-2 text-[10px] font-semibold disabled:opacity-45",title:D?`Dispatch ${D.workstreamTitle}`:"No queued workstream to dispatch",children:"▶ Play"}),e.jsx("button",{type:"button",onClick:Dt,className:"control-pill h-7 flex-shrink-0 px-2 text-[10px] font-semibold",title:"Expand Next Up rail",children:"Open"})]})]},"next-up-inline-card")})]}),Ve&&e.jsx("div",{className:`mt-2 rounded-lg border px-3 py-2 text-[11px] ${Ve.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:Ve.message})]}),e.jsxs(le.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},className:`grid gap-4 pb-8 ${Me?"xl:grid-cols-[minmax(0,1fr)_320px]":"grid-cols-1"}`,children:[e.jsxs(le.div,{layout:!0,className:"min-w-0",children:[!r&&P&&e.jsx(le.div,{initial:{opacity:0,y:6,scale:.995},animate:{opacity:1,y:0,scale:1},transition:{type:"spring",stiffness:280,damping:30},className:"surface-hero mb-3.5 rounded-2xl p-3.5",children: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:"Next action"}),e.jsx("p",{className:"mt-1 text-[14px] font-semibold text-white",children:Et.headline}),e.jsx("p",{className:"mt-1 text-[12px] text-white/65",children:Et.detail}),be&&e.jsx("div",{className:`mt-2 inline-flex max-w-[520px] items-center gap-1 rounded-full border px-2.5 py-1 text-[10px] ${be.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:be.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[(ve==="queued"||ve==="running")&&D?e.jsx("button",{type:"button",onClick:ve==="running"?()=>Ft(D):Vt,disabled:At,className:"control-pill px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:ve==="running"?"Follow workstream":"Play next workstream"}):ve==="startable"?e.jsx("button",{type:"button",onClick:ys,disabled:At,className:"control-pill px-3 text-[11px] font-semibold disabled:opacity-45","data-state":"active",children:"Start initiative"}):e.jsx("button",{type:"button",onClick:js,className:"control-pill px-3 text-[11px] font-semibold","data-state":ve==="blocked"?"active":"idle",children:vs}),e.jsx("button",{type:"button",onClick:Dt,className:"control-pill px-3 text-[11px] font-semibold",children:Me?"Hide Next Up":"Open Next Up"})]})]})}),r?e.jsx("div",{className:"space-y-3 pb-8",children:Array.from({length:4}).map((f,A)=>e.jsxs("div",{className:"bg-[--orgx-surface] border border-[--orgx-border] soft-shadow rounded-2xl p-4",children:[e.jsx(ut,{className:"h-4 w-2/5 rounded"}),e.jsx(ut,{className:"h-1 w-full rounded mt-3"})]},`mc-skeleton-${A}`))}):t.length===0?j?e.jsx("div",{className:"pb-8",children:e.jsx(fn,{})}):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-[14px] font-semibold text-white/85",children:"Connect OrgX to get started"}),e.jsx("div",{className:"mt-1 text-[12px] text-white/55",children:"Mission Control shows your initiative hierarchy once a user-scoped API key is configured."}),y&&e.jsx("div",{className:"mt-4 flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:y,className:"h-10 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-4 text-[12px] font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/20",children:"Open settings"})})]})}):re.length===0?e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-4 py-8 text-center pb-8",children:[e.jsx("div",{className:"text-[13px] font-medium text-white/85",children:"No initiatives match the current filters"}),e.jsx("div",{className:"mt-1 text-[12px] text-white/50",children:K?"Try adjusting status/date filters or clear them.":"Try a broader search phrase."})]}):$?e.jsx("div",{className:"space-y-4 pb-8",children:$.map(f=>{const A=lt(q,f.key),R=Bn(A),H=se.has(A);return e.jsxs(le.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},children:[e.jsxs("button",{type:"button","aria-expanded":H,"aria-controls":R,onClick:()=>je(A),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-white/[0.16] 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-white/[0.12] bg-white/[0.04] text-[11px] text-white/55 transition-transform ${H?"rotate-90":""}`,children:"▶"}),e.jsx("span",{className:"text-[12px] font-semibold text-white/80",children:f.label}),e.jsx("span",{className:"rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-[10px] text-white/55",children:f.count}),e.jsx("span",{className:"ml-auto text-[10px] uppercase tracking-[0.08em] text-white/45",children:H?"Hide":"Show"})]}),e.jsx(Le,{initial:!1,children:H&&e.jsx(le.div,{id:R,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(ss,{initiatives:f.initiatives,selectedInitiativeIds:ze,onToggleInitiativeSelection:de,runtimeActivityByInitiativeId:S})})})})]},f.key)})}):e.jsx("div",{className:"pb-8",children:e.jsx(ss,{initiatives:re,selectedInitiativeIds:ze,onToggleInitiativeSelection:de,runtimeActivityByInitiativeId:S})})]}),e.jsx(Le,{initial:!1,children:Me&&e.jsx(le.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(le.div,{layout:"position",layoutId:Mt,initial:{borderRadius:12},animate:{borderRadius:16,...Qt},transition:{layout:It,type:"spring",stiffness:340,damping:38,mass:.72},className:"origin-top-right overflow-hidden rounded-2xl border shadow-[0_18px_40px_rgba(0,0,0,0.42)] backdrop-blur-[12px]",children:e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:Dt,className:"control-pill absolute right-3 top-3 z-20 h-7 px-2 text-[10px] font-semibold",title:"Collapse Next Up rail",children:"Hide"}),e.jsx(Xt,{title:"Next Up",compact:!0,className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,authToken:Y,embedMode:oe,onFollowWorkstream:Ft,onOpenInitiative:Ke})]})})})})})]})]}),e.jsx(Le,{children:et&&e.jsxs(e.Fragment,{children:[e.jsx(le.button,{type:"button","aria-label":"Close next up panel",onClick:()=>me(!1),initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"fixed bottom-0 left-0 right-0 top-[64px] z-[220] hidden bg-black/45 lg:block xl:hidden"},"next-up-backdrop"),e.jsx(le.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 bottom-0 right-0 top-[64px] z-[230] hidden w-[360px] max-w-[94vw] p-3 lg:block xl:hidden",children:e.jsxs("div",{className:"relative flex h-full flex-col",children:[e.jsx("button",{type:"button",onClick:()=>me(!1),className:"absolute right-2 top-16 z-20 inline-flex h-8 w-8 items-center justify-center rounded-full border border-white/[0.14] bg-[#080d14]/85 text-white/72 transition-colors hover:text-white","aria-label":"Close next up drawer",children:"✕"}),e.jsx(le.div,{layout:"position",layoutId:Mt,initial:{borderRadius:12},animate:{borderRadius:16,...Qt},transition:{layout:It,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.jsx(Xt,{title:"Next Up",className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,authToken:Y,embedMode:oe,onFollowWorkstream:Ft,onOpenInitiative:(f,A)=>{Ke(f,A),me(!1)}})})]})},"next-up-drawer")]})})]})})]}),e.jsx(kn,{target:Fs,onClose:ne})]})}export{On as MissionControlView};
@@ -1 +0,0 @@
1
- import{r as o,j as e}from"./react-vendor-C2t2w4r2.js";import{r as P,P as T,c as C,g as D,h as K,a as _}from"./index-B4Yix84X.js";import"./tanstack-C-KIc3Wc.js";import"./vendor-C-AHK0Ly.js";import"./motion-x9c01cgK.js";const O=/^[0-9a-f-]{20,}$/i;function X(h){if(h.runId)return h.runId;const t=h.metadata;if(!t)return null;const u=["runId","run_id","sessionId","session_id","agentRunId"];for(const p of u){const c=t[p];if(typeof c=="string"&&c.trim().length>0)return c.trim()}return null}const ee=o.memo(function({session:t,activity:u,initiatives:p=[],onContinueHighestPriority:c,onDispatchSession:b,onPauseSession:g,onResumeSession:f,onCancelSession:w,onCreateCheckpoint:j,onRollbackSession:v,onStartInitiative:B,onStartWorkstream:N}){const[i,L]=o.useState(null),[y,E]=o.useState(null),[m,q]=o.useState(!1),x=o.useMemo(()=>t?u.filter(r=>X(r)===t.runId).sort((r,l)=>Date.parse(l.timestamp)-Date.parse(r.timestamp)).slice(0,8):[],[u,t]),A=o.useMemo(()=>{var n;if(!t)return[];const r=[],l=t.initiativeId??t.groupId;if(l){const a=p.find(M=>M.id===l);a?r.push({label:"Initiative",value:a.name}):t.groupLabel&&t.groupLabel.trim().length>0&&r.push({label:"Initiative",value:t.groupLabel})}if(t.workstreamId){let a=null;for(const M of p){const U=(n=M.workstreams)==null?void 0:n.find(J=>J.id===t.workstreamId);if(U){a=U.name;break}}!a&&!O.test(t.workstreamId)&&(a=t.workstreamId),a&&r.push({label:"Workstream",value:a})}const d=t.phase??null;return d&&r.push({label:"Milestone",value:String(d)}),t.title&&r.push({label:"Task",value:t.title}),r},[p,t]),k=o.useMemo(()=>{var n,a;if(!t)return null;const r=((n=x[0])==null?void 0:n.summary)??((a=x[0])==null?void 0:a.description)??null,d=t.lastEventSummary??r??null;return d&&d.trim().length>0?d.trim():null},[x,t]),R=o.useMemo(()=>{var r;return t?P(t.agentName,t.title,t.lastEventSummary,k,(r=x[0])==null?void 0:r.metadata):P()},[x,t,k]),s=async(r,l,d)=>{if(!(!d||i)){L(r),E(null);try{await d(),E(`${l} requested.`)}catch(n){E(n instanceof Error?n.message:`${l} failed.`)}finally{L(null)}}};if(!t)return e.jsxs(T,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/[0.06] px-4 py-3.5",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Session Detail"}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-white/40 transition-colors hover:text-white/70","aria-label":m?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",m?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]}),e.jsx("div",{className:C("transition-all",m?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-2 overflow-y-auto p-4 text-[12px] text-white/45",children:[e.jsx("p",{children:"Select a session to inspect summary, breadcrumbs, blockers, and recent messages."}),e.jsx("button",{onClick:()=>s("continue-priority","Continue highest priority",c),disabled:!c||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.04] px-3 py-1.5 text-[11px] text-white/70 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="continue-priority"?"Dispatching…":"Continue highest priority"}),y&&e.jsx("p",{className:"text-[11px] text-white/55",children:y})]})})]});const $=t.progress===null?null:Math.round(t.progress),I=t.status.toLowerCase(),z=["running","active","queued","pending"].includes(I),Q=["paused","blocked","queued","pending"].includes(I),V=!["completed","archived","cancelled"].includes(I),F=!["archived","cancelled"].includes(I),G=[{label:"Started",value:t.startedAt?D(t.startedAt):"—"},{label:"Updated",value:t.updatedAt?D(t.updatedAt):"—"},{label:"ETA",value:t.eta??"—"},{label:"Checkpoints",value:t.checkpointCount!==null&&t.checkpointCount!==void 0?String(t.checkpointCount):"—"}];return e.jsxs(T,{className:"flex h-full min-h-0 flex-col card-enter",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-white/[0.06] px-4 py-3.5",children:[e.jsx("h2",{className:"text-[14px] font-semibold text-white",children:"Session Detail"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"chip text-[11px] uppercase",children:t.status}),e.jsx("button",{onClick:()=>q(r=>!r),className:"text-white/40 transition-colors hover:text-white/70","aria-label":m?"Expand session detail":"Collapse session detail",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:C("transition-transform",m?"-rotate-90":"rotate-0"),children:e.jsx("path",{d:"m6 9 6 6 6-6"})})})]})]}),e.jsx("div",{className:C("transition-all",m?"max-h-0 overflow-hidden":"min-h-0 flex-1"),children:e.jsxs("div",{className:"space-y-3 overflow-y-auto p-4",children:[e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsx(K,{provider:R.id,size:"sm"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-[13px] font-medium text-white",children:t.title}),e.jsxs("p",{className:"mt-0.5 text-[11px] text-white/45",children:[t.agentName??"Unassigned"," · ",R.label]})]})]}),A.length>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] p-2.5",children:[e.jsx("p",{className:"mb-1.5 text-[10px] uppercase tracking-[0.1em] text-white/35",children:"Breadcrumb"}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[11px]",children:A.map((r,l)=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx("span",{className:"rounded-full border border-white/[0.12] bg-white/[0.02] px-1.5 py-0.5 text-white/65",children:r.value}),l<A.length-1&&e.jsx("span",{className:"text-[11px] text-white/40",children:"›"})]},`${r.label}-${r.value}`))})]}),k&&e.jsx("p",{className:"rounded-xl border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-[12px] leading-relaxed text-white/65",children:k}),$!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between text-[11px] text-white/55",children:[e.jsx("span",{children:"Progress"}),e.jsxs("span",{children:[$,"%"]})]}),e.jsx("div",{className:"h-2 rounded-full bg-white/[0.08]",children:e.jsx("div",{className:"h-2 rounded-full",style:{width:`${$}%`,background:`linear-gradient(90deg, ${_.lime}, ${_.teal})`}})})]}),e.jsx("dl",{className:"grid grid-cols-1 gap-1 text-[11px] text-white/55 sm:grid-cols-2",children:G.map(r=>e.jsxs("div",{children:[e.jsx("dt",{className:"text-white/35",children:r.label}),e.jsx("dd",{className:"font-medium",children:r.value})]},r.label))}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/40",children:"Quick actions"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>s("continue-priority","Continue highest priority",c),disabled:!c||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="continue-priority"?"Dispatching…":"Continue Priority"}),e.jsx("button",{onClick:()=>s("dispatch-session","Dispatch session",()=>b==null?void 0:b(t)),disabled:!b||!!i,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-[11px] font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:i==="dispatch-session"?"Dispatching…":"Dispatch Session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/40",children:"Session controls"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>s("pause-session","Pause session",()=>g==null?void 0:g(t)),disabled:!g||!z||!!i,className:"rounded-md border border-amber-400/30 bg-amber-400/10 px-3 py-2 text-[11px] font-semibold text-amber-300 transition-colors hover:bg-amber-400/20 disabled:opacity-45",children:i==="pause-session"?"Pausing…":"Pause"}),e.jsx("button",{onClick:()=>s("resume-session","Resume session",()=>f==null?void 0:f(t)),disabled:!f||!Q||!!i,className:"rounded-md border border-lime/25 bg-lime/10 px-3 py-2 text-[11px] font-semibold text-lime transition-colors hover:bg-lime/20 disabled:opacity-45",children:i==="resume-session"?"Resuming…":"Resume"}),e.jsx("button",{onClick:()=>s("checkpoint-session","Checkpoint created",()=>j==null?void 0:j(t)),disabled:!j||!!i,className:"rounded-md border border-sky-400/30 bg-sky-400/10 px-3 py-2 text-[11px] font-semibold text-sky-300 transition-colors hover:bg-sky-400/20 disabled:opacity-45",children:i==="checkpoint-session"?"Creating…":"Checkpoint"}),e.jsx("button",{onClick:()=>s("rollback-session","Rollback requested",()=>v==null?void 0:v(t)),disabled:!v||!F||!!i,className:"rounded-md border border-fuchsia-400/30 bg-fuchsia-400/10 px-3 py-2 text-[11px] font-semibold text-fuchsia-300 transition-colors hover:bg-fuchsia-400/20 disabled:opacity-45",children:i==="rollback-session"?"Rolling back…":"Rollback"}),e.jsx("button",{onClick:()=>s("cancel-session","Cancel session",()=>w==null?void 0:w(t)),disabled:!w||!V||!!i,className:"col-span-2 rounded-md border border-red-400/30 bg-red-400/10 px-3 py-2 text-[11px] font-semibold text-red-300 transition-colors hover:bg-red-400/20 disabled:opacity-45",children:i==="cancel-session"?"Cancelling…":"Cancel session"})]})]}),e.jsxs("div",{children:[e.jsx("p",{className:"mb-1 text-[10px] uppercase tracking-[0.12em] text-white/40",children:"Planning"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{onClick:()=>s("start-initiative","Start initiative",B),disabled:!B||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="start-initiative"?"Creating…":"New initiative"}),e.jsx("button",{onClick:()=>s("start-workstream","Start workstream",()=>N==null?void 0:N(t.initiativeId)),disabled:!N||!!i,className:"rounded-md border border-white/[0.12] bg-white/[0.03] px-3 py-2 text-[11px] text-white/75 transition-colors hover:bg-white/[0.08] disabled:opacity-45",children:i==="start-workstream"?"Creating…":"New workstream"})]})]})]}),y&&e.jsx("p",{className:"rounded-md border border-white/[0.08] bg-white/[0.02] px-2.5 py-1.5 text-[11px] text-white/55",children:y}),t.blockers.length>0&&e.jsxs("div",{className:"rounded-xl border border-red-500/30 bg-red-500/10 p-3",children:[e.jsx("h3",{className:"mb-1 text-[11px] uppercase tracking-[0.12em] text-red-200/70",children:"Blockers"}),e.jsx("ul",{className:"space-y-1 text-[12px] text-red-100/90",children:t.blockers.map(r=>e.jsxs("li",{children:["• ",r]},r))})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"mb-2 text-[11px] uppercase tracking-[0.12em] text-white/45",children:"Recent Messages"}),x.length===0&&e.jsx("p",{className:"text-[12px] text-white/45",children:"No recent messages for this run."}),e.jsx("div",{className:"space-y-2",children:x.map(r=>e.jsxs("article",{className:"rounded-lg border border-white/[0.06] bg-white/[0.02] px-2.5 py-2",children:[e.jsx("p",{className:"text-[11px] text-white/85",children:r.title}),(r.summary||r.description)&&e.jsx("p",{className:"mt-0.5 line-clamp-2 text-[11px] text-white/55",children:r.summary??r.description}),e.jsxs("p",{className:"mt-1 text-[10px] text-white/35",children:[new Date(r.timestamp).toLocaleString()," · ",D(r.timestamp)]})]},r.id))})]})]})})]})});export{ee as SessionInspector};