@useorgx/openclaw-plugin 0.4.8 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/README.md +35 -0
  2. package/dashboard/dist/assets/BJgZIVUQ.js +53 -0
  3. package/dashboard/dist/assets/BJgZIVUQ.js.br +0 -0
  4. package/dashboard/dist/assets/BJgZIVUQ.js.gz +0 -0
  5. package/dashboard/dist/assets/BXWDRGm-.js +1 -0
  6. package/dashboard/dist/assets/BXWDRGm-.js.br +0 -0
  7. package/dashboard/dist/assets/BXWDRGm-.js.gz +0 -0
  8. package/dashboard/dist/assets/BgOYB78t.js +4 -0
  9. package/dashboard/dist/assets/BgOYB78t.js.br +0 -0
  10. package/dashboard/dist/assets/BgOYB78t.js.gz +0 -0
  11. package/dashboard/dist/assets/C-KIc3Wc.js.br +0 -0
  12. package/dashboard/dist/assets/C-KIc3Wc.js.gz +0 -0
  13. package/dashboard/dist/assets/CE38zU4U.js +1 -0
  14. package/dashboard/dist/assets/CE38zU4U.js.br +0 -0
  15. package/dashboard/dist/assets/CE38zU4U.js.gz +0 -0
  16. package/dashboard/dist/assets/CFGKRAzG.js +1 -0
  17. package/dashboard/dist/assets/CFGKRAzG.js.br +0 -0
  18. package/dashboard/dist/assets/CFGKRAzG.js.gz +0 -0
  19. package/dashboard/dist/assets/CGGR2GZh.js +1 -0
  20. package/dashboard/dist/assets/CGGR2GZh.js.br +0 -0
  21. package/dashboard/dist/assets/CGGR2GZh.js.gz +0 -0
  22. package/dashboard/dist/assets/CL_wXqR7.js +1 -0
  23. package/dashboard/dist/assets/CL_wXqR7.js.br +0 -0
  24. package/dashboard/dist/assets/CL_wXqR7.js.gz +0 -0
  25. package/dashboard/dist/assets/CPFiTmlw.js +8 -0
  26. package/dashboard/dist/assets/CPFiTmlw.js.br +0 -0
  27. package/dashboard/dist/assets/CPFiTmlw.js.gz +0 -0
  28. package/dashboard/dist/assets/CZZTvkQZ.js +1 -0
  29. package/dashboard/dist/assets/CZZTvkQZ.js.br +0 -0
  30. package/dashboard/dist/assets/CZZTvkQZ.js.gz +0 -0
  31. package/dashboard/dist/assets/{CpJsfbXo.js → CxQ08qFN.js} +2 -2
  32. package/dashboard/dist/assets/CxQ08qFN.js.br +0 -0
  33. package/dashboard/dist/assets/CxQ08qFN.js.gz +0 -0
  34. package/dashboard/dist/assets/D-bf6hEI.js +213 -0
  35. package/dashboard/dist/assets/D-bf6hEI.js.br +0 -0
  36. package/dashboard/dist/assets/D-bf6hEI.js.gz +0 -0
  37. package/dashboard/dist/assets/DG6y9wJI.js +2 -0
  38. package/dashboard/dist/assets/DG6y9wJI.js.br +0 -0
  39. package/dashboard/dist/assets/DG6y9wJI.js.gz +0 -0
  40. package/dashboard/dist/assets/DNxKz-GV.js +1 -0
  41. package/dashboard/dist/assets/DNxKz-GV.js.br +0 -0
  42. package/dashboard/dist/assets/DNxKz-GV.js.gz +0 -0
  43. package/dashboard/dist/assets/DW_rKUic.js +11 -0
  44. package/dashboard/dist/assets/DW_rKUic.js.br +0 -0
  45. package/dashboard/dist/assets/DW_rKUic.js.gz +0 -0
  46. package/dashboard/dist/assets/DbNoijHm.js +1 -0
  47. package/dashboard/dist/assets/DbNoijHm.js.br +0 -0
  48. package/dashboard/dist/assets/DbNoijHm.js.gz +0 -0
  49. package/dashboard/dist/assets/DjcdE6jC.js +2 -0
  50. package/dashboard/dist/assets/DjcdE6jC.js.br +0 -0
  51. package/dashboard/dist/assets/DjcdE6jC.js.gz +0 -0
  52. package/dashboard/dist/assets/FZYuCDnt.js +1 -0
  53. package/dashboard/dist/assets/FZYuCDnt.js.br +0 -0
  54. package/dashboard/dist/assets/FZYuCDnt.js.gz +0 -0
  55. package/dashboard/dist/assets/PAUiij_z.js +1 -0
  56. package/dashboard/dist/assets/PAUiij_z.js.br +0 -0
  57. package/dashboard/dist/assets/PAUiij_z.js.gz +0 -0
  58. package/dashboard/dist/assets/cNrhgGc1.js +8 -0
  59. package/dashboard/dist/assets/cNrhgGc1.js.br +0 -0
  60. package/dashboard/dist/assets/cNrhgGc1.js.gz +0 -0
  61. package/dashboard/dist/assets/h5biQs2I.css +1 -0
  62. package/dashboard/dist/assets/h5biQs2I.css.br +0 -0
  63. package/dashboard/dist/assets/h5biQs2I.css.gz +0 -0
  64. package/dashboard/dist/assets/ic2FaMnh.js +1 -0
  65. package/dashboard/dist/assets/ic2FaMnh.js.br +0 -0
  66. package/dashboard/dist/assets/ic2FaMnh.js.gz +0 -0
  67. package/dashboard/dist/assets/nByHNHoW.js +1 -0
  68. package/dashboard/dist/assets/nByHNHoW.js.br +0 -0
  69. package/dashboard/dist/assets/nByHNHoW.js.gz +0 -0
  70. package/dashboard/dist/assets/qm8xLgv-.css +1 -0
  71. package/dashboard/dist/assets/qm8xLgv-.css.br +0 -0
  72. package/dashboard/dist/assets/qm8xLgv-.css.gz +0 -0
  73. package/dashboard/dist/assets/tS9mbYZi.js +1 -0
  74. package/dashboard/dist/assets/tS9mbYZi.js.br +0 -0
  75. package/dashboard/dist/assets/tS9mbYZi.js.gz +0 -0
  76. package/dashboard/dist/brand/anthropic-mark.svg.br +0 -0
  77. package/dashboard/dist/brand/anthropic-mark.svg.gz +0 -0
  78. package/dashboard/dist/brand/openai-mark.svg.br +0 -0
  79. package/dashboard/dist/brand/openai-mark.svg.gz +0 -0
  80. package/dashboard/dist/brand/openclaw-mark.svg.br +0 -0
  81. package/dashboard/dist/brand/openclaw-mark.svg.gz +0 -0
  82. package/dashboard/dist/brand/xandy-orchestrator.png +0 -0
  83. package/dashboard/dist/index.html +7 -5
  84. package/dashboard/dist/index.html.br +0 -0
  85. package/dashboard/dist/index.html.gz +0 -0
  86. package/dist/activity-actor-fields.js +26 -4
  87. package/dist/activity-store.js +38 -26
  88. package/dist/agent-context-store.js +84 -42
  89. package/dist/agent-run-store.js +49 -28
  90. package/dist/agent-suite.d.ts +9 -0
  91. package/dist/agent-suite.js +150 -17
  92. package/dist/artifacts/artifact-domain-schemas.d.ts +66 -0
  93. package/dist/artifacts/artifact-domain-schemas.js +357 -0
  94. package/dist/artifacts/register-artifact.d.ts +4 -3
  95. package/dist/artifacts/register-artifact.js +170 -57
  96. package/dist/auth/flows.d.ts +47 -0
  97. package/dist/auth/flows.js +169 -0
  98. package/dist/auth-store.js +6 -26
  99. package/dist/byok-store.js +5 -19
  100. package/dist/chat-store.d.ts +157 -0
  101. package/dist/chat-store.js +586 -0
  102. package/dist/cli/orgx.d.ts +66 -0
  103. package/dist/cli/orgx.js +102 -0
  104. package/dist/config/refresh.d.ts +32 -0
  105. package/dist/config/refresh.js +55 -0
  106. package/dist/config/resolution.d.ts +37 -0
  107. package/dist/config/resolution.js +178 -0
  108. package/dist/contracts/client.d.ts +43 -3
  109. package/dist/contracts/client.js +159 -30
  110. package/dist/contracts/retro-schema.d.ts +81 -0
  111. package/dist/contracts/retro-schema.js +80 -0
  112. package/dist/contracts/shared-types.d.ts +306 -0
  113. package/dist/contracts/shared-types.js +179 -0
  114. package/dist/contracts/skill-pack-schema.d.ts +192 -0
  115. package/dist/contracts/skill-pack-schema.js +180 -0
  116. package/dist/contracts/types.d.ts +224 -132
  117. package/dist/contracts/types.js +5 -0
  118. package/dist/entities/auto-assignment.d.ts +36 -0
  119. package/dist/entities/auto-assignment.js +141 -0
  120. package/dist/entity-comment-store.js +5 -25
  121. package/dist/event-sanitization.d.ts +11 -0
  122. package/dist/event-sanitization.js +113 -0
  123. package/dist/fs-utils.js +13 -1
  124. package/dist/gateway-watchdog.d.ts +5 -0
  125. package/dist/gateway-watchdog.js +50 -0
  126. package/dist/hash-utils.d.ts +2 -0
  127. package/dist/hash-utils.js +12 -0
  128. package/dist/hooks/post-reporting-event.mjs +1 -5
  129. package/dist/http/helpers/activity-headline.d.ts +10 -0
  130. package/dist/http/helpers/activity-headline.js +73 -0
  131. package/dist/http/helpers/artifact-fallback.d.ts +13 -0
  132. package/dist/http/helpers/artifact-fallback.js +148 -0
  133. package/dist/http/helpers/auto-continue-engine.d.ts +486 -0
  134. package/dist/http/helpers/auto-continue-engine.js +3563 -0
  135. package/dist/http/helpers/autopilot-operations.d.ts +176 -0
  136. package/dist/http/helpers/autopilot-operations.js +554 -0
  137. package/dist/http/helpers/autopilot-runtime.d.ts +43 -0
  138. package/dist/http/helpers/autopilot-runtime.js +607 -0
  139. package/dist/http/helpers/autopilot-slice-utils.d.ts +56 -0
  140. package/dist/http/helpers/autopilot-slice-utils.js +899 -0
  141. package/dist/http/helpers/decision-mapper.d.ts +52 -0
  142. package/dist/http/helpers/decision-mapper.js +260 -0
  143. package/dist/http/helpers/dispatch-lifecycle.d.ts +119 -0
  144. package/dist/http/helpers/dispatch-lifecycle.js +809 -0
  145. package/dist/http/helpers/hash-utils.d.ts +1 -0
  146. package/dist/http/helpers/hash-utils.js +1 -0
  147. package/dist/http/helpers/kickoff-context.d.ts +12 -0
  148. package/dist/http/helpers/kickoff-context.js +228 -0
  149. package/dist/http/helpers/llm-client.d.ts +47 -0
  150. package/dist/http/helpers/llm-client.js +256 -0
  151. package/dist/http/helpers/mission-control.d.ts +193 -0
  152. package/dist/http/helpers/mission-control.js +1383 -0
  153. package/dist/http/helpers/openclaw-cli.d.ts +37 -0
  154. package/dist/http/helpers/openclaw-cli.js +283 -0
  155. package/dist/http/helpers/runtime-sse.d.ts +20 -0
  156. package/dist/http/helpers/runtime-sse.js +110 -0
  157. package/dist/http/helpers/sentinel-catalog.d.ts +23 -0
  158. package/dist/http/helpers/sentinel-catalog.js +193 -0
  159. package/dist/http/helpers/session-classification.d.ts +9 -0
  160. package/dist/http/helpers/session-classification.js +564 -0
  161. package/dist/http/helpers/slice-experience-v2.d.ts +137 -0
  162. package/dist/http/helpers/slice-experience-v2.js +677 -0
  163. package/dist/http/helpers/slice-run-projections.d.ts +72 -0
  164. package/dist/http/helpers/slice-run-projections.js +860 -0
  165. package/dist/http/helpers/triage-mapper.d.ts +43 -0
  166. package/dist/http/helpers/triage-mapper.js +549 -0
  167. package/dist/http/helpers/value-utils.d.ts +6 -0
  168. package/dist/http/helpers/value-utils.js +72 -0
  169. package/dist/http/helpers/workspace-scope.d.ts +15 -0
  170. package/dist/http/helpers/workspace-scope.js +170 -0
  171. package/dist/http/index.d.ts +88 -0
  172. package/dist/http/index.js +3610 -0
  173. package/dist/http/router.d.ts +23 -0
  174. package/dist/http/router.js +23 -0
  175. package/dist/http/routes/agent-control.d.ts +79 -0
  176. package/dist/http/routes/agent-control.js +684 -0
  177. package/dist/http/routes/agent-suite.d.ts +38 -0
  178. package/dist/http/routes/agent-suite.js +397 -0
  179. package/dist/http/routes/agents-catalog.d.ts +40 -0
  180. package/dist/http/routes/agents-catalog.js +128 -0
  181. package/dist/http/routes/billing.d.ts +23 -0
  182. package/dist/http/routes/billing.js +55 -0
  183. package/dist/http/routes/chat.d.ts +19 -0
  184. package/dist/http/routes/chat.js +522 -0
  185. package/dist/http/routes/debug.d.ts +14 -0
  186. package/dist/http/routes/debug.js +21 -0
  187. package/dist/http/routes/decision-actions.d.ts +20 -0
  188. package/dist/http/routes/decision-actions.js +103 -0
  189. package/dist/http/routes/delegation.d.ts +19 -0
  190. package/dist/http/routes/delegation.js +32 -0
  191. package/dist/http/routes/dispatch-gateway-envelope.d.ts +25 -0
  192. package/dist/http/routes/dispatch-gateway-envelope.js +26 -0
  193. package/dist/http/routes/entities.d.ts +63 -0
  194. package/dist/http/routes/entities.js +440 -0
  195. package/dist/http/routes/entity-dynamic.d.ts +25 -0
  196. package/dist/http/routes/entity-dynamic.js +191 -0
  197. package/dist/http/routes/health.d.ts +22 -0
  198. package/dist/http/routes/health.js +49 -0
  199. package/dist/http/routes/live-legacy.d.ts +115 -0
  200. package/dist/http/routes/live-legacy.js +112 -0
  201. package/dist/http/routes/live-misc.d.ts +81 -0
  202. package/dist/http/routes/live-misc.js +426 -0
  203. package/dist/http/routes/live-snapshot.d.ts +136 -0
  204. package/dist/http/routes/live-snapshot.js +916 -0
  205. package/dist/http/routes/live-terminal.d.ts +11 -0
  206. package/dist/http/routes/live-terminal.js +261 -0
  207. package/dist/http/routes/live-triage.d.ts +61 -0
  208. package/dist/http/routes/live-triage.js +248 -0
  209. package/dist/http/routes/mission-control-actions.d.ts +131 -0
  210. package/dist/http/routes/mission-control-actions.js +1791 -0
  211. package/dist/http/routes/mission-control-read.d.ts +73 -0
  212. package/dist/http/routes/mission-control-read.js +1640 -0
  213. package/dist/http/routes/onboarding.d.ts +34 -0
  214. package/dist/http/routes/onboarding.js +101 -0
  215. package/dist/http/routes/realtime-orchestrator.d.ts +10 -0
  216. package/dist/http/routes/realtime-orchestrator.js +74 -0
  217. package/dist/http/routes/run-control.d.ts +27 -0
  218. package/dist/http/routes/run-control.js +96 -0
  219. package/dist/http/routes/runtime-hooks.d.ts +69 -0
  220. package/dist/http/routes/runtime-hooks.js +437 -0
  221. package/dist/http/routes/sentinels-catalog.d.ts +7 -0
  222. package/dist/http/routes/sentinels-catalog.js +24 -0
  223. package/dist/http/routes/settings-byok.d.ts +23 -0
  224. package/dist/http/routes/settings-byok.js +163 -0
  225. package/dist/http/routes/summary.d.ts +18 -0
  226. package/dist/http/routes/summary.js +49 -0
  227. package/dist/http/routes/usage.d.ts +24 -0
  228. package/dist/http/routes/usage.js +362 -0
  229. package/dist/http/routes/work-artifacts.d.ts +9 -0
  230. package/dist/http/routes/work-artifacts.js +55 -0
  231. package/dist/http/shared-state.d.ts +16 -0
  232. package/dist/http/shared-state.js +1 -0
  233. package/dist/http-handler.d.ts +1 -88
  234. package/dist/http-handler.js +1 -10605
  235. package/dist/index.js +287 -2284
  236. package/dist/json-utils.d.ts +1 -0
  237. package/dist/json-utils.js +8 -0
  238. package/dist/local-openclaw.js +29 -6
  239. package/dist/mcp-client-setup.js +3 -3
  240. package/dist/mcp-http-handler.js +33 -59
  241. package/dist/next-up-queue-store.d.ts +16 -1
  242. package/dist/next-up-queue-store.js +93 -25
  243. package/dist/outbox.d.ts +5 -0
  244. package/dist/outbox.js +113 -9
  245. package/dist/paths.js +24 -5
  246. package/dist/reporting/rollups.d.ts +53 -0
  247. package/dist/reporting/rollups.js +148 -0
  248. package/dist/retro/domain-templates.d.ts +45 -0
  249. package/dist/retro/domain-templates.js +297 -0
  250. package/dist/retro/quality-rubric.d.ts +33 -0
  251. package/dist/retro/quality-rubric.js +213 -0
  252. package/dist/runtime-cleanup.d.ts +18 -0
  253. package/dist/runtime-cleanup.js +87 -0
  254. package/dist/runtime-instance-store.js +5 -31
  255. package/dist/services/background.d.ts +34 -0
  256. package/dist/services/background.js +45 -0
  257. package/dist/services/experiment-randomization.d.ts +21 -0
  258. package/dist/services/experiment-randomization.js +63 -0
  259. package/dist/services/instrumentation.d.ts +29 -0
  260. package/dist/services/instrumentation.js +136 -0
  261. package/dist/skill-pack-state.d.ts +36 -5
  262. package/dist/skill-pack-state.js +273 -29
  263. package/dist/snapshot-store.js +5 -25
  264. package/dist/stores/json-store.d.ts +11 -0
  265. package/dist/stores/json-store.js +42 -0
  266. package/dist/sync/local-agent-telemetry.d.ts +13 -0
  267. package/dist/sync/local-agent-telemetry.js +128 -0
  268. package/dist/sync/outbox-replay.d.ts +55 -0
  269. package/dist/sync/outbox-replay.js +621 -0
  270. package/dist/team-context-store.d.ts +23 -0
  271. package/dist/team-context-store.js +116 -0
  272. package/dist/telemetry/posthog.js +4 -2
  273. package/dist/tools/core-tools.d.ts +72 -0
  274. package/dist/tools/core-tools.js +2270 -0
  275. package/dist/types.d.ts +2 -0
  276. package/dist/types.js +2 -0
  277. package/dist/worker-supervisor.js +23 -0
  278. package/package.json +14 -4
  279. package/dashboard/dist/assets/B3ziCA02.js +0 -8
  280. package/dashboard/dist/assets/BNeJ0kpF.js +0 -1
  281. package/dashboard/dist/assets/BzkiMPmM.js +0 -215
  282. package/dashboard/dist/assets/CUV9IHHi.js +0 -1
  283. package/dashboard/dist/assets/Ie7d9Iq2.css +0 -1
  284. package/dashboard/dist/assets/sAhvFnpk.js +0 -4
@@ -1 +0,0 @@
1
- import{r as n,u as Ss,b as vt,c as rt,j as e}from"./B3ziCA02.js";import{q as xt,b as ht,p as Hs,A as Jt,c as Vs,E as Ue,a as q,n as Ks,u as Gs,f as ke,s as Nt,d as St,e as ls,i as kt,S as Ze,P as Qs,g as Js,h as Fs,j as Ft,k as Ds,l as Yt,M as Ys,m as Xs,o as Zs,r as cs,t as er,U as tr,N as ds}from"./BzkiMPmM.js";import{v as sr}from"./sAhvFnpk.js";import{A as Oe,m as le,L as rr}from"./CpJsfbXo.js";import"./C-KIc3Wc.js";function nr({activities:t,agents:s,initiatives:o}){return n.useMemo(()=>{const u=new Map,l=(c,a,b,f)=>{const F=u.get(c)??[];F.some(p=>p.id===a)||(F.push({id:a,name:b,confidence:f}),u.set(c,F))};return t.forEach(c=>{const a="metadata"in c&&c.metadata&&typeof c.metadata=="object"?c.metadata:null,b=a&&typeof a=="object"?a:{},f=("initiativeId"in c&&typeof c.initiativeId=="string"?c.initiativeId:void 0)??b.initiativeId??void 0,F=c.agentId??void 0,p=("agentName"in c&&typeof c.agentName=="string"?c.agentName:"agent"in c&&typeof c.agent=="string"?c.agent:void 0)??F??"Unknown";f&&F&&l(f,F,p,"high")}),o.forEach(c=>{var a;(a=c.avatars)!=null&&a.length&&c.avatars.forEach(b=>{const f=s.find(F=>F.name.toLowerCase()===b.toLowerCase());f?l(c.id,f.id,f.name,"medium"):l(c.id,`avatar:${b}`,b,"medium")})}),s.forEach(c=>{if(!c.task)return;const a=c.task.toLowerCase();o.forEach(b=>{b.name.toLowerCase().split(/\s+/).filter(A=>A.length>3).some(A=>a.includes(A))&&l(b.id,c.id,c.name,"low")})}),u},[t,s,o])}function ar({initiativeId:t=null,authToken:s=null,embedMode:o=!1,enabled:u=!0}){var R,w,i;const l=Ss(),c=n.useMemo(()=>xt.autoContinueStatus({initiativeId:t??"__global__",authToken:s,embedMode:o}),[t,s,o]),a=vt({queryKey:c,enabled:u&&(!!t||t===null),queryFn:async()=>{const v=new URLSearchParams;t&&v.set("initiative_id",t);const d=await fetch(`/orgx/api/mission-control/auto-continue/status?${v.toString()}`,{headers:ht({authToken:s,embedMode:o})}),x=await d.json().catch(()=>null);if(!d.ok){const N=typeof(x==null?void 0:x.error)=="string"&&x.error||typeof(x==null?void 0:x.message)=="string"&&x.message||`Failed to load auto-continue status (${d.status})`;return{ok:!1,initiativeId:t,run:null,defaults:{tokenBudget:0,tickMs:0},error:N}}return x},refetchInterval:v=>{var g,I;const d=v.state.data;if((d==null?void 0:d.ok)===!1)return!1;const x=((g=d==null?void 0:d.error)==null?void 0:g.toLowerCase())??"";if(x.includes("404")||x.includes("400")||x.includes("not found")||x.includes("bad request"))return!1;const m=((I=d==null?void 0:d.run)==null?void 0:I.status)??null;return m==="running"||m==="stopping"?2500:12e3}}),b=async()=>{await l.invalidateQueries({queryKey:c}),await l.invalidateQueries({queryKey:xt.missionControlGraph({initiativeId:t,authToken:s,embedMode:o})}),await l.invalidateQueries({queryKey:xt.liveData({authToken:s,embedMode:o})})},f=rt({mutationFn:async v=>{const d={};t&&(d.initiativeId=t),v&&typeof v=="object"&&(typeof v.tokenBudgetTokens=="number"&&(d.tokenBudgetTokens=v.tokenBudgetTokens),typeof v.agentId=="string"&&v.agentId.trim().length>0&&(d.agentId=v.agentId.trim()));const x=await fetch("/orgx/api/mission-control/auto-continue/start",{method:"POST",headers:ht({authToken:s,embedMode:o,contentTypeJson:!0}),body:JSON.stringify(d)}),N=await x.json().catch(()=>null);if(!x.ok){const m=Hs(N);if(m)throw m;const g=typeof(N==null?void 0:N.error)=="string"&&N.error||typeof(N==null?void 0:N.message)=="string"&&N.message||`Failed to start auto-continue (${x.status})`;throw new Error(g)}if(N&&typeof N=="object"&&"run"in N){const m=a.data??null;return{ok:!0,initiativeId:t,run:N.run??null,defaults:(m==null?void 0:m.defaults)??{tokenBudget:0,tickMs:0}}}return N},onSuccess:()=>{b()}}),F=rt({mutationFn:async()=>{const v={};t&&(v.initiativeId=t);const d=await fetch("/orgx/api/mission-control/auto-continue/stop",{method:"POST",headers:ht({authToken:s,embedMode:o,contentTypeJson:!0}),body:JSON.stringify(v)}),x=await d.json().catch(()=>null);if(!d.ok){const N=typeof(x==null?void 0:x.error)=="string"&&x.error||typeof(x==null?void 0:x.message)=="string"&&x.message||`Failed to stop auto-continue (${d.status})`;throw new Error(N)}if(x&&typeof x=="object"&&"run"in x){const N=a.data??null;return{ok:!0,initiativeId:t,run:x.run??null,defaults:(N==null?void 0:N.defaults)??{tokenBudget:0,tickMs:0}}}return x},onSuccess:()=>{b()}}),p=((R=a.data)==null?void 0:R.run)??null,A=(p==null?void 0:p.status)==="running"||(p==null?void 0:p.status)==="stopping";return{status:a.data??null,run:p,isRunning:A,isLoading:a.isLoading,error:((w=a.data)==null?void 0:w.error)??((i=a.error)==null?void 0:i.message)??null,start:f.mutateAsync,stop:F.mutateAsync,isStarting:f.isPending,isStopping:F.isPending,refetch:a.refetch}}function Es(t){const s=n.useRef(null),o=n.useCallback((u,l,c,a)=>{if(c&&s.current!==null){const b=t.indexOf(s.current),f=t.indexOf(u);if(b!==-1&&f!==-1){const F=Math.min(b,f),p=Math.max(b,f),A=t.slice(F,p+1);a(R=>{const w=new Set(R);for(const i of A)l?w.add(i):w.delete(i);return w});return}}a(b=>{const f=new Set(b);return l?f.add(u):f.delete(u),f}),s.current=u},[t]);return{lastClickedId:s,handleSelect:o}}function Ms({value:t,onChange:s,placeholder:o}){return e.jsxs("label",{className:"relative block",children:[e.jsx("span",{className:"sr-only",children:o}),e.jsxs("svg",{className:"pointer-events-none absolute left-3 top-1/2 -translate-y-1/2 text-muted",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("path",{d:"m21 21-4.3-4.3"})]}),e.jsx("input",{type:"text",value:t,onChange:u=>s(u.target.value),placeholder:o,className:"w-full rounded-xl border border-white/[0.08] bg-white/[0.03] py-2.5 pl-10 pr-8 text-body text-white placeholder:text-muted transition-all focus:border-[#BFFF00]/30 focus:bg-white/[0.05] focus:outline-none"}),t.length>0&&e.jsx("button",{type:"button",onClick:()=>s(""),className:"absolute right-2.5 top-1/2 -translate-y-1/2 rounded-full p-0.5 text-muted transition-colors hover:text-primary","aria-label":"Clear search",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M18 6 6 18M6 6l12 12"})})})]})}async function tt(t){if(!t.ok){const s=await t.json().catch(()=>null),o=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(o)}return t}function ir(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 Wt(t){const s=t.trim().toLowerCase();return s==="deleted"||s==="archived"||s==="cancelled"}function or(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 lr(t){const s=Ss(),o=ht({authToken:t.authToken,embedMode:t.embedMode,contentTypeJson:!0}),u=()=>{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"]})},l=(w,i)=>{s.setQueryData(["initiative-tombstones"],v=>{const d=Array.isArray(v)?v.filter(N=>typeof N=="string"):[],x=d.includes(w);return i?x?d:[...d,w]:x?d.filter(N=>N!==w):d})},c=(w,i)=>{const v=ir(i),d=new Date().toISOString(),x=Wt(i);l(w,x);const N=m=>{if(!Array.isArray(m))return m;if(x){const K=m.filter(ee=>{if(!ee||typeof ee!="object")return!0;const se=ee;return!(typeof se.id=="string"&&se.id===w)});return K.length===m.length?m:K}let g=!1;const I=m.map(K=>{if(!K||typeof K!="object")return K;const ee=K;return typeof ee.id!="string"||ee.id!==w?K:(g=!0,{...ee,status:v,rawStatus:i,updatedAt:d})});return g?I:m};s.setQueriesData({queryKey:["entities"]},N),s.setQueriesData({queryKey:["live-initiatives"]},N)},a=(w,i,v="status")=>{const d=or(i);s.setQueriesData({queryKey:["live-data"]},x=>{if(!x||typeof x!="object")return x;const N=x,m=N.sessions;if(!m||typeof m!="object")return x;const g=m,I=g.nodes;if(!Array.isArray(I))return x;let K=!1;const ee=v==="delete"?I.filter(D=>{if(!D||typeof D!="object")return!0;const _=D,z=(typeof _.initiativeId=="string"?_.initiativeId:null)===w;return z&&(K=!0),!z}):I.map(D=>{if(!D||typeof D!="object")return D;const _=D;return(typeof _.initiativeId=="string"?_.initiativeId:null)!==w||_.status===d?D:(K=!0,{..._,status:d})});if(!K)return x;const se=new Set,ie=new Set;for(const D of ee){if(!D||typeof D!="object")continue;const _=D;typeof _.id=="string"&&se.add(_.id),typeof _.groupId=="string"&&ie.add(_.groupId)}const X=Array.isArray(g.edges)?g.edges.filter(D=>{if(!D||typeof D!="object")return!1;const _=D,W=typeof _.parentId=="string"?_.parentId:null,z=typeof _.childId=="string"?_.childId:null;return W!==null&&z!==null&&se.has(W)&&se.has(z)}):g.edges,V=Array.isArray(g.groups)?g.groups.filter(D=>{if(!D||typeof D!="object")return!1;const _=D;return typeof _.id=="string"&&ie.has(_.id)}):g.groups;return{...N,sessions:{...g,nodes:ee,edges:X,groups:V}}})},b={start:"in_progress",complete:"done",block:"blocked",unblock:"in_progress",pause:"paused",resume:"active"},f=rt({mutationFn:async w=>{const{type:i,...v}=w,d=await fetch("/orgx/api/entities",{method:"POST",headers:o,body:JSON.stringify({type:i,...v})});return await tt(d),d.json()},onSuccess:u}),F=rt({mutationFn:async w=>{const{type:i,id:v,...d}=w,x=await fetch("/orgx/api/entities",{method:"PATCH",headers:o,body:JSON.stringify({type:i,id:v,...d})});return await tt(x),x.json()},onSuccess:(w,i)=>{i.type.trim().toLowerCase()==="initiative"&&typeof i.status=="string"&&i.status.trim().length>0&&(c(i.id,i.status),a(i.id,i.status,Wt(i.status)?"delete":"status")),u()}}),p=rt({mutationFn:async w=>{const i=await fetch(`/orgx/api/entities/${encodeURIComponent(w.type)}/${encodeURIComponent(w.id)}/delete`,{method:"POST",headers:o,body:"{}"});return await tt(i),i.json()},onSuccess:(w,i)=>{i.type.trim().toLowerCase()==="initiative"&&(c(i.id,"archived"),a(i.id,"archived","delete")),u()}}),A=rt({mutationFn:async w=>{const i=await fetch(`/orgx/api/entities/${encodeURIComponent(w.type)}/${encodeURIComponent(w.id)}/${encodeURIComponent(w.action)}`,{method:"POST",headers:o,body:JSON.stringify({force:w.force??!1})});return await tt(i),i.json()},onSuccess:(w,i)=>{if(i.type.trim().toLowerCase()==="initiative"){const v=b[i.action.trim().toLowerCase()];v&&(c(i.id,v),a(i.id,v,"status"))}u()}}),R=rt({mutationFn:async w=>{const i=Array.from(new Map((w.items??[]).filter(g=>typeof(g==null?void 0:g.type)=="string"&&g.type.trim().length>0&&typeof(g==null?void 0:g.id)=="string"&&g.id.trim().length>0).map(g=>[`${g.type}:${g.id}`,g])).values());if(i.length===0)return{updated:0,failed:0,errors:[]};if(w.mode==="action"&&!w.action)throw new Error("bulk action requires an action name");const v=async g=>{try{if(w.mode==="delete"){const K=await fetch(`/orgx/api/entities/${encodeURIComponent(g.type)}/${encodeURIComponent(g.id)}/delete`,{method:"POST",headers:o,body:"{}"});return await tt(K),{ok:!0}}if(w.mode==="update"){const K=await fetch("/orgx/api/entities",{method:"PATCH",headers:o,body:JSON.stringify({type:g.type,id:g.id,...w.updates??{}})});return await tt(K),{ok:!0}}const I=await fetch(`/orgx/api/entities/${encodeURIComponent(g.type)}/${encodeURIComponent(g.id)}/${encodeURIComponent(w.action)}`,{method:"POST",headers:o,body:JSON.stringify({force:w.force??!1})});return await tt(I),{ok:!0}}catch(I){return{ok:!1,error:I instanceof Error?I.message:"Unknown bulk mutation failure"}}},d=await Promise.all(i.map(g=>v(g)));let x=0,N=0;const m=[];for(const g of d)g.ok?x+=1:(N+=1,m.push(g.error));return{updated:x,failed:N,errors:m}},onSuccess:(w,i)=>{var d;const v=(i.items??[]).filter(x=>x.type.trim().toLowerCase()==="initiative");if(v.length>0){if(i.mode==="update"&&typeof((d=i.updates)==null?void 0:d.status)=="string"&&i.updates.status.trim().length>0)for(const x of v)c(x.id,i.updates.status),a(x.id,i.updates.status,Wt(i.updates.status)?"delete":"status");else if(i.mode==="delete")for(const x of v)c(x.id,"archived"),a(x.id,"archived","delete");else if(i.mode==="action"&&i.action){const x=b[i.action.trim().toLowerCase()];if(x)for(const N of v)c(N.id,x),a(N.id,x,"status")}}u()}});return{createEntity:f,updateEntity:F,deleteEntity:p,entityAction:A,bulkEntityMutation:R}}const As=n.createContext(null);function et(){const t=n.useContext(As);if(!t)throw new Error("useMissionControl must be used within MissionControlProvider");return t}function cr({children:t,agentEntityMap:s,authToken:o,embedMode:u}){const[l,c]=n.useState(new Set),[a,b]=n.useState(null),[f,F]=n.useState(""),[p,A]=n.useState([]),[R,w]=n.useState("target"),[i,v]=n.useState("any"),[d,x]=n.useState(""),[N,m]=n.useState(""),[g,I]=n.useState("status"),[K,ee]=n.useState("default"),se=lr({authToken:o,embedMode:u}),ie=n.useCallback(H=>{c(re=>{const ne=new Set(re);return ne.has(H)?ne.delete(H):ne.add(H),ne})},[]),X=n.useCallback(H=>{c(re=>{if(re.has(H))return re;const ne=new Set(re);return ne.add(H),ne})},[]),V=n.useCallback(H=>{c(new Set(H))},[]),D=n.useCallback(()=>{c(new Set)},[]),_=n.useCallback(H=>{b(H)},[]),W=n.useCallback(()=>{b(null)},[]),z=n.useCallback(H=>{const re=Array.from(new Set((H??[]).map(ne=>ne.trim().toLowerCase()).filter(Boolean)));A(re)},[]),O=n.useCallback(H=>{A(re=>{const ne=H.trim().toLowerCase();return ne?re.includes(ne)?re.filter(T=>T!==ne):[...re,ne]:re})},[]),G=n.useCallback(()=>{F(""),A([]),w("target"),v("any"),x(""),m("")},[]),L=d.trim().length>0||N.trim().length>0,k=i!=="any"&&(i!=="custom_range"||L),oe=p.length+(k?1:0),C=f.trim().length>0||oe>0,U=n.useMemo(()=>({agentEntityMap:s,expandedInitiatives:l,modalTarget:a,searchQuery:f,statusFilters:p,dateField:R,datePreset:i,dateStart:d,dateEnd:N,activeFilterCount:oe,hasActiveFilters:C,groupBy:g,sortBy:K,authToken:o,embedMode:u,mutations:se,toggleExpanded:ie,expandInitiative:X,expandAll:V,collapseAll:D,openModal:_,closeModal:W,setSearchQuery:F,setStatusFilters:z,toggleStatusFilter:O,setDateField:w,setDatePreset:v,setDateStart:x,setDateEnd:m,setGroupBy:I,setSortBy:ee,clearFilters:G}),[s,l,a,f,p,R,i,d,N,oe,C,g,K,o,u,se,ie,X,V,D,_,W,z,O,w,v,x,m,I,ee,G]);return e.jsx(As.Provider,{value:U,children:t})}function Dt({agents:t,max:s=4}){if(!t.length)return null;const o=t.slice(0,s),u=t.length-s;return e.jsxs("div",{className:"inline-flex min-w-0 items-center justify-end -space-x-1.5 pl-1",children:[o.map(l=>e.jsx("div",{className:"relative flex-shrink-0",title:`${l.name} (${l.confidence} confidence)`,style:{borderRadius:"9999px",border:l.confidence==="high"?"1.5px solid rgba(255,255,255,0.25)":l.confidence==="medium"?"1.5px dashed rgba(255,255,255,0.15)":"1.5px dotted rgba(255,255,255,0.10)"},children:e.jsx(Jt,{name:l.name,size:"xs"})},l.id)),u>0&&e.jsxs("span",{className:"ml-1 flex-shrink-0 text-micro text-muted",children:["+",u]})]})}function Ht(t){return{initiative:{id:t,title:"Initiative",status:"active",summary:null,assignedAgents:[]},nodes:[],edges:[],recentTodos:[]}}function dr({initiativeId:t,authToken:s=null,embedMode:o=!1,enabled:u=!0}){var f,F;const l=Vs(t),c=n.useMemo(()=>xt.missionControlGraph({initiativeId:t,authToken:s,embedMode:o}),[t,s,o]),a=vt({queryKey:c,enabled:u&&!!t&&l,queryFn:async()=>{if(!t)throw new Error("initiativeId is required");if(!l)return Ht(t);const p=new URLSearchParams({initiative_id:t}),A={};o&&(A["X-Orgx-Embed"]="true"),s&&(A.Authorization=`Bearer ${s}`);const R=Object.keys(A).length>0?A:void 0,w=await fetch(`/orgx/api/mission-control/graph?${p.toString()}`,{headers:R});if(!w.ok){const i=await w.json().catch(()=>null),v=typeof(i==null?void 0:i.error)=="string"&&i.error||typeof(i==null?void 0:i.message)=="string"&&i.message||`Failed to fetch Mission Control graph (${w.status})`;return{...Ht(t),degraded:[v]}}return await w.json()}});return{graph:a.data??(t?Ht(t):null),isLoading:l?a.isLoading:!1,error:l?((f=a.error)==null?void 0:f.message)??null:null,degraded:l?((F=a.data)==null?void 0:F.degraded)??[]:[],refetch:a.refetch}}function Ct({type:t,className:s=""}){return e.jsx(Ue,{type:t,className:s,size:14})}function ur(t){return t==="initiative"?"Initiatives":t==="workstream"?"Workstreams":t==="milestone"?"Milestones":"Tasks"}function pr({nodes:t,edges:s,selectedNodeId:o,focusedWorkstreamId:u,onSelectNode:l}){const c=n.useMemo(()=>new Map(t.map(m=>[m.id,m])),[t]),[a,b]=n.useState(""),[f,F]=n.useState(!1),p=a.trim().toLowerCase(),A=n.useMemo(()=>{if(!u)return new Set(t.map(I=>I.id));const m=new Set;for(const I of t)(I.type==="initiative"||I.id===u||I.workstreamId===u)&&m.add(I.id);let g=!0;for(;g;){g=!1;for(const I of s)(m.has(I.from)||m.has(I.to))&&(!m.has(I.from)||!m.has(I.to))&&(m.add(I.from),m.add(I.to),g=!0)}return m},[u,t,s]),R=t.filter(m=>A.has(m.id)),w=s.filter(m=>A.has(m.from)&&A.has(m.to)),i=n.useMemo(()=>{if(!o)return new Set;const m=new Set([o]);for(const g of w)g.from===o&&m.add(g.to),g.to===o&&m.add(g.from);return m},[o,w]),v=n.useMemo(()=>{let m=new Set(Array.from(A));return f&&o&&(m=new Set(Array.from(m).filter(g=>i.has(g)))),p.length>0&&(m=new Set(Array.from(m).filter(g=>{const I=c.get(g);return I?I.title.toLowerCase().includes(p):!1}))),m},[c,p,i,f,o,A]),d=t.filter(m=>v.has(m.id)),x=s.filter(m=>v.has(m.from)&&v.has(m.to)),N={initiative:d.filter(m=>m.type==="initiative"),workstream:d.filter(m=>m.type==="workstream"),milestone:d.filter(m=>m.type==="milestone"),task:d.filter(m=>m.type==="task")};return R.length===0?null:e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:[d.length," nodes · ",x.length," links"]}),u&&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:a,onChange:m=>b(m.target.value),placeholder:"Filter nodes...",className:"h-9 flex-1 min-w-[200px] rounded-lg border border-strong bg-black/30 px-3 text-caption text-primary placeholder:text-faint transition-colors focus:border-[#BFFF00]/35 focus:outline-none"}),o&&e.jsx("button",{type:"button",onClick:()=>F(m=>!m),"aria-pressed":f,"data-state":f?"active":"idle",className:"control-pill px-3 text-caption font-semibold",title:"Show only the selected node and its direct neighbors",children:"Related only"}),(a.trim().length>0||f)&&e.jsx("button",{type:"button",onClick:()=>{b(""),F(!1)},className:"control-pill px-3 text-caption",children:"Reset"})]}),d.length===0?e.jsx("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-3 py-3 text-caption text-secondary",children:"No nodes match this view. Clear filters or select a different node to see connected work."}):e.jsx("div",{className:`grid gap-2 ${Object.values(N).filter(m=>m.length>0).length<=2?"grid-cols-1 sm:grid-cols-2":"md:grid-cols-2 xl:grid-cols-4"}`,children:Object.keys(N).filter(m=>N[m].length>0).map(m=>e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] p-2.5",children:[e.jsxs("div",{className:"mb-1.5 text-micro uppercase tracking-[0.09em] text-secondary",children:[ur(m)," (",N[m].length,")"]}),e.jsxs("div",{className:"space-y-1",children:[N[m].slice(0,10).map(g=>{const I=o===g.id,K=!I&&i.has(g.id);return e.jsxs("button",{type:"button",onClick:()=>l(g.id),title:g.title,className:`flex w-full items-center gap-1.5 rounded-md border px-2 py-1 text-left transition-colors ${I?"border-[#BFFF00]/35 bg-[#BFFF00]/12":K?"border-[#14B8A6]/35 bg-[#14B8A6]/12":"border-strong bg-white/[0.03] hover:bg-white/[0.08]"}`,children:[e.jsx(Ct,{type:g.type}),e.jsx("span",{className:"truncate text-caption text-primary",children:g.title})]},g.id)}),N[m].length>10&&e.jsxs("div",{className:"px-1 text-micro text-muted",children:["+",N[m].length-10," more"]})]})]},m))}),x.length>0&&e.jsxs("div",{className:"rounded-xl border border-white/[0.07] bg-black/[0.14] px-2.5 py-2",children:[e.jsx("div",{className:"mb-1 text-micro uppercase tracking-[0.08em] text-muted",children:"Dependency links"}),e.jsx("div",{className:"max-h-[110px] space-y-1 overflow-auto pr-1",children:x.slice(0,36).map(m=>{const g=c.get(m.from),I=c.get(m.to);if(!g||!I)return null;const K=o===g.id||o===I.id;return e.jsxs("button",{type:"button",onClick:()=>l(I.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:K?q.lime:"rgba(255,255,255,0.35)"}}),e.jsx("span",{className:"truncate text-micro text-primary",children:g.title}),e.jsx("span",{className:"text-micro text-muted",children:"→"}),e.jsx("span",{className:"truncate text-micro text-primary",children:I.title})]},`${m.from}-${m.to}`)})})]})]})}const mr=new Set(["done","completed","complete","cancelled","canceled","archived","deleted"]);function $e(t){return mr.has(Ks(t))}function Et(t){return Number.isFinite(t)?Math.max(0,Math.min(100,Math.round(t))):0}function nt(t,s){return s<=0?0:Et(t/s*100)}function xr({dependencies:t,allNodes:s,disabled:o=!1,onSave:u}){const[l,c]=n.useState(!1),[a,b]=n.useState(""),[f,F]=n.useState(t),p=n.useMemo(()=>new Map(s.map(i=>[i.id,i])),[s]),A=n.useMemo(()=>{const i=a.trim().toLowerCase(),v=[...s].sort((d,x)=>d.title.localeCompare(x.title));return i?v.filter(d=>d.title.toLowerCase().includes(i)||d.id.toLowerCase().includes(i)).slice(0,16):v.slice(0,16)},[s,a]),R=()=>{u(Array.from(new Set(f))),c(!1)},w=i=>{F(v=>v.includes(i)?v.filter(d=>d!==i):[...v,i])};return e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",disabled:o,onClick:()=>{b(""),F(t),c(i=>!i)},className:"rounded-md border border-strong bg-white/[0.04] px-2 py-1 text-micro text-primary transition-colors hover:bg-white/[0.08] disabled:opacity-40",children:t.length>0?`${t.length} linked`:"Set links"}),l&&e.jsxs("div",{className:"surface-tier-2 absolute right-0 z-20 mt-1.5 w-[320px] rounded-xl p-2.5 shadow-[0_20px_40px_rgba(0,0,0,0.45)]",children:[e.jsx("label",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Link dependencies"}),e.jsx("input",{value:a,onChange:i=>b(i.target.value),placeholder:"Search by title or id...",className:"mt-1.5 h-9 w-full rounded-md border border-strong bg-black/25 px-2.5 text-caption text-bright outline-none transition-colors placeholder:text-muted focus:border-[#BFFF00]/35"}),e.jsx("div",{className:"mt-2 flex max-h-[84px] flex-wrap gap-1.5 overflow-y-auto rounded-md border border-white/[0.08] bg-black/20 p-1.5",children:f.length===0?e.jsx("span",{className:"text-micro text-muted",children:"No links selected"}):f.map(i=>{var d;const v=((d=p.get(i))==null?void 0:d.title)??i;return e.jsxs("button",{type:"button",onClick:()=>w(i),className:"inline-flex items-center gap-1 rounded-full border border-strong bg-white/[0.05] px-2 py-0.5 text-micro text-primary transition-colors hover:bg-white/[0.1]",title:v,children:[e.jsx("span",{className:"max-w-[180px] truncate",children:v}),e.jsx("span",{className:"text-secondary",children:"×"})]},i)})}),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:A.length===0?e.jsx("div",{className:"px-1 text-micro text-muted",children:"No matching nodes"}):A.map(i=>{const v=f.includes(i.id);return e.jsxs("button",{type:"button",onClick:()=>w(i.id),className:`flex w-full items-center justify-between rounded-md border px-2 py-1 text-left text-micro transition-colors ${v?"border-[#BFFF00]/32 bg-[#BFFF00]/12 text-[#D8FFA1]":"border-white/[0.1] bg-white/[0.03] text-primary hover:bg-white/[0.08]"}`,children:[e.jsxs("span",{className:"min-w-0 pr-2",children:[e.jsx("span",{className:"block truncate",children:i.title}),e.jsxs("span",{className:"block truncate text-muted",children:[i.id.slice(0,8),"…"]})]}),e.jsx("span",{className:"font-semibold",children:v?"Linked":"Link"})]},i.id)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-end gap-1.5",children:[e.jsx("button",{type:"button",onClick:()=>c(!1),className:"rounded-md border border-strong px-2 py-1 text-micro text-secondary transition-colors hover:bg-white/[0.08]",children:"Cancel"}),e.jsx("button",{type:"button",onClick:R,className:"rounded-md border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-2 py-1 text-micro text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/22",children:"Save links"})]})]})]})}function hr(t){if(!t)return"";const s=new Date(t);if(Number.isNaN(s.getTime()))return"";const o=s.getFullYear(),u=String(s.getMonth()+1).padStart(2,"0"),l=String(s.getDate()).padStart(2,"0"),c=String(s.getHours()).padStart(2,"0"),a=String(s.getMinutes()).padStart(2,"0");return`${o}-${u}-${l}T${c}:${a}`}const us=["not_started","planned","todo","in_progress","active","blocked","done"];function fr(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 gt(t){const s=t.trim().toLowerCase();return s==="completed"?"done":s==="running"||s==="queued"?"active":s==="pending"||s==="backlog"?"todo":s}function br(t,s){return s==="all"?!0:s==="blocked"?t==="blocked":s==="done"?t==="done":t!=="blocked"&&t!=="done"}function gr(t,s){const o=new Map(s.map(c=>[c.id,c])),u=new Set,l=[t];for(;l.length>0;){const c=l.shift(),a=o.get(c);a&&(a.parentId&&!u.has(a.parentId)&&(u.add(a.parentId),l.push(a.parentId)),a.workstreamId&&!u.has(a.workstreamId)&&(u.add(a.workstreamId),l.push(a.workstreamId)),a.milestoneId&&!u.has(a.milestoneId)&&(u.add(a.milestoneId),l.push(a.milestoneId)))}return u}function yr(t,s,o,u){let l=0;if(o==="title")l=t.title.localeCompare(s.title);else if(o==="status")l=Nt(t.status)-Nt(s.status);else if(o==="priority")l=t.priorityNum-s.priorityNum;else if(o==="eta"){const c=t.etaEndAt?Date.parse(t.etaEndAt):1/0,a=s.etaEndAt?Date.parse(s.etaEndAt):1/0;l=c-a}return u==="desc"?-l:l}function wr({nodes:t,edges:s,selectedNodeId:o,highlightedNodeIds:u,editMode:l,onToggleEditMode:c,onSelectNode:a,onFocusWorkstream:b,onOpenNode:f,onUpdateNode:F,mutations:p}){const{authToken:A,embedMode:R}=et(),w=Gs({authToken:A,embedMode:R}),[i,v]=n.useState(""),[d,x]=n.useState(new Set),[N,m]=n.useState("all"),[g,I]=n.useState(!1),[K,ee]=n.useState(null),[se,ie]=n.useState("asc"),[X,V]=n.useState(new Set),[D,_]=n.useState(!1),[W,z]=n.useState(null),O=n.useRef(null),G=n.useRef(null);n.useEffect(()=>{if(!W)return;const r=W.tone==="success"?6500:9e3,S=window.setTimeout(()=>z(null),r);return()=>window.clearTimeout(S)},[W==null?void 0:W.message,W==null?void 0:W.tone]);const L=n.useMemo(()=>new Map(t.map(r=>[r.id,r])),[t]),k=n.useMemo(()=>t.map(r=>({id:r.id,title:r.title})),[t]),oe=n.useMemo(()=>{const r=new Map;for(const S of t){const M=gt(S.status);r.set(M,(r.get(M)??0)+1)}return r},[t]),C=n.useMemo(()=>{let r=0,S=0,M=0;for(const Y of t){const Z=gt(Y.status);Z==="blocked"?S+=1:Z==="done"?M+=1:r+=1}return{all:t.length,open:r,blocked:S,done:M}},[t]),U=n.useMemo(()=>{const r=i.trim().toLowerCase(),S=r.length>0,M=d.size>0;if(!S&&!M&&!(N!=="all"))return null;const Z=new Set;for(const he of t){const y=gt(he.status),j=!S||he.title.toLowerCase().includes(r)||he.assignedAgents.some($=>$.name.toLowerCase().includes(r)),B=!M||d.has(y),pe=br(y,N);j&&B&&pe&&Z.add(he.id)}const ue=new Set(Z);for(const he of Z)for(const y of gr(he,t))ue.add(y);return ue},[d,t,i,N]),H=n.useMemo(()=>t.filter(r=>r.type==="workstream").sort((r,S)=>r.priorityNum-S.priorityNum||r.title.localeCompare(S.title)),[t]),re=n.useMemo(()=>{const r=new Map;for(const S of t.filter(M=>M.type==="milestone")){const M=S.workstreamId??"unscoped",Y=r.get(M)??[];Y.push(S),r.set(M,Y)}for(const S of r.values())S.sort((M,Y)=>M.priorityNum-Y.priorityNum||M.title.localeCompare(Y.title));return r},[t]),ne=n.useMemo(()=>{const r=new Map;for(const S of t.filter(M=>M.type==="task"&&M.milestoneId)){const M=S.milestoneId??"unscoped",Y=r.get(M)??[];Y.push(S),r.set(M,Y)}for(const S of r.values())S.sort((M,Y)=>M.priorityNum-Y.priorityNum||M.title.localeCompare(Y.title));return r},[t]),T=n.useMemo(()=>{const r=new Map;for(const S of t.filter(M=>M.type==="task"&&!M.milestoneId)){const M=S.workstreamId??"unscoped",Y=r.get(M)??[];Y.push(S),r.set(M,Y)}for(const S of r.values())S.sort((M,Y)=>M.priorityNum-Y.priorityNum||M.title.localeCompare(Y.title));return r},[t]),fe=n.useMemo(()=>{const r=new Set;for(const S of H)r.add(S.id);for(const S of t.filter(M=>M.type==="milestone"))r.add(S.id);return r},[t,H]),[ge,me]=n.useState(fe);n.useEffect(()=>{me(fe)},[fe]);const Ae=r=>K?[...r].sort((S,M)=>yr(S,M,K,se)):r,Fe=n.useMemo(()=>{const r=[],S=Z=>U===null||U.has(Z);for(const Z of Ae(H)){if(!S(Z.id))continue;const ue=Ae(re.get(Z.id)??[]),he=Ae(T.get(Z.id)??[]),y=ue.length>0||he.length>0;if(r.push({node:Z,depth:0,canCollapse:y}),!!ge.has(Z.id)){for(const j of ue){if(!S(j.id))continue;const B=Ae(ne.get(j.id)??[]);if(r.push({node:j,depth:1,canCollapse:B.length>0}),ge.has(j.id))for(const pe of B)S(pe.id)&&r.push({node:pe,depth:2,canCollapse:!1})}for(const j of he)S(j.id)&&r.push({node:j,depth:1,canCollapse:!1})}}const M=Ae(re.get("unscoped")??[]),Y=Ae(T.get("unscoped")??[]);for(const Z of M)if(S(Z.id)&&(r.push({node:Z,depth:0,canCollapse:(ne.get(Z.id)??[]).length>0}),ge.has(Z.id)))for(const ue of Ae(ne.get(Z.id)??[]))S(ue.id)&&r.push({node:ue,depth:1,canCollapse:!1});for(const Z of Y)S(Z.id)&&r.push({node:Z,depth:0,canCollapse:!1});return r},[T,ge,U,re,K,se,ne,H]),Qe=n.useMemo(()=>Fe.map(({node:r})=>r.id),[Fe]),{handleSelect:at}=Es(Qe),qe=n.useMemo(()=>new Set(Qe),[Qe]),ye=n.useMemo(()=>Fe.filter(({node:r})=>X.has(r.id)),[Fe,X]),Ve=(N!=="all"?1:0)+d.size,_e=i.trim().length>0||N!=="all"||d.size>0,De=ye.length,xe=Fe.length>0&&De===Fe.length,Ee=(p==null?void 0:p.bulkEntityMutation.isPending)??!1;n.useEffect(()=>{V(r=>{if(r.size===0)return r;const S=new Set(Array.from(r).filter(M=>qe.has(M)));return S.size===r.size?r:S})},[qe]),n.useEffect(()=>{O.current&&(O.current.indeterminate=De>0&&!xe)},[xe,De]),n.useEffect(()=>{De===0&&D&&_(!1)},[D,De]),n.useEffect(()=>{if(!g)return;const r=M=>{var Z;const Y=M.target;Y&&((Z=G.current)!=null&&Z.contains(Y)||I(!1))},S=M=>{M.key==="Escape"&&I(!1)};return document.addEventListener("mousedown",r),document.addEventListener("touchstart",r),document.addEventListener("keydown",S),()=>{document.removeEventListener("mousedown",r),document.removeEventListener("touchstart",r),document.removeEventListener("keydown",S)}},[g]);const We=r=>r.dependencyIds.length,Te=async r=>{const S=r.initiativeId??"",M=r.type==="workstream"?r.id:r.workstreamId??"",Y=r.type==="task"?r.id:null,Z=r.type==="milestone"?r.id:null;if(!S||!M){z({tone:"error",message:"Cannot add to Next Up: missing initiative/workstream id."});return}try{await w.pin({initiativeId:S,workstreamId:M,taskId:Y,milestoneId:Z}),z({tone:"success",message:r.type==="task"?"Pinned task workstream to Next Up.":r.type==="milestone"?"Pinned milestone workstream to Next Up.":"Pinned workstream to Next Up."}),window.setTimeout(()=>z(null),1800)}catch(ue){z({tone:"error",message:ue instanceof Error?ue.message:"Failed to pin to Next Up."}),window.setTimeout(()=>z(null),2400)}},Le=n.useMemo(()=>{const r=new Map,S=(M,Y)=>{if(M.length>0){const Z=M.filter(ue=>$e(ue.status)).length;return nt(Z,M.length)}return $e(Y)?100:0};for(const M of t.filter(Y=>Y.type==="milestone")){const Y=ne.get(M.id)??[];r.set(M.id,S(Y,M.status))}for(const M of H){const Z=(re.get(M.id)??[]).flatMap(he=>ne.get(he.id)??[]),ue=T.get(M.id)??[];r.set(M.id,S([...ue,...Z],M.status))}return r},[T,re,t,ne,H]),we=r=>{K===r?ie(S=>S==="asc"?"desc":"asc"):(ee(r),ie("asc"))},Ce=r=>{x(S=>{const M=new Set(S);return M.has(r)?M.delete(r):M.add(r),M})},Je=()=>{v(""),m("all"),x(new Set)},ae=(r,S,M)=>{z(null),_(!1),at(r,S,M,V)},He=()=>{z(null),_(!1),V(()=>Fe.length===0||xe?new Set:new Set(Qe))},Be=()=>{_(!1),V(new Set)},Ie=async r=>{if(!(!p||ye.length===0)){_(!1),z(null);try{const S=await p.bulkEntityMutation.mutateAsync({items:ye.map(({node:M})=>({type:M.type,id:M.id})),mode:"update",updates:{status:r}});S.failed>0?z({tone:"error",message:`Updated ${S.updated}, failed ${S.failed}.`}):z({tone:"success",message:`Updated ${S.updated} item${S.updated===1?"":"s"} to ${ke(r)}.`})}catch(S){z({tone:"error",message:S instanceof Error?S.message:"Bulk status update failed."})}}},Ye=async()=>{if(!(!p||ye.length===0)){z(null);try{const r=await p.bulkEntityMutation.mutateAsync({items:ye.map(({node:S})=>({type:S.type,id:S.id})),mode:"delete"});r.failed>0?z({tone:"error",message:`Deleted ${r.updated}, failed ${r.failed}.`}):(z({tone:"success",message:`Deleted ${r.updated} item${r.updated===1?"":"s"}.`}),V(new Set),_(!1))}catch(r){z({tone:"error",message:r instanceof Error?r.message:"Bulk delete failed."})}}},je=({field:r})=>K!==r?e.jsx("span",{className:"text-faint ml-0.5",children:"↕"}):e.jsx("span",{className:"text-[#BFFF00] ml-0.5",children:se==="asc"?"↑":"↓"}),Me="calc(var(--mc-toolbar-offset, 88px) + var(--mc-initiative-header-offset, 52px))";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(Ms,{value:i,onChange:v,placeholder:"Search items or agents..."})}),e.jsxs("div",{className:"flex min-h-[40px] min-w-0 flex-wrap items-center gap-2.5",children:[c&&e.jsxs("button",{type:"button",onClick:c,"data-state":l?"active":"idle",className:`control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-caption font-semibold ${l?"text-[#D8FFA1]":"text-secondary hover:text-bright"}`,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"})}),l?"Editing":"Edit"]}),e.jsxs("div",{ref:G,className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>I(r=>!r),"data-state":g||Ve>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3.5 text-caption font-semibold",children:[e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),Ve>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-micro leading-4",children:Ve})]}),e.jsx(Oe,{children:g&&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-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Scope"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:[{id:"all",label:"All",count:C.all},{id:"open",label:"Open",count:C.open},{id:"blocked",label:"Blocked",count:C.blocked},{id:"done",label:"Done",count:C.done}].map(r=>{const S=N===r.id;return e.jsxs("button",{type:"button",onClick:()=>m(r.id),className:`inline-flex h-7 items-center gap-1.5 rounded-full border px-2.5 text-micro font-semibold transition-colors ${S?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-[#D8FFA1]":"border-strong bg-white/[0.03] text-secondary hover:bg-white/[0.07] hover:text-white/82"}`,children:[e.jsx("span",{children:r.label}),e.jsx("span",{className:"text-micro text-current/80",children:r.count})]},r.id)})})]}),e.jsxs("div",{className:"mb-2 border-t border-white/[0.08] pt-2",children:[e.jsx("div",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("div",{className:"mt-1.5 flex flex-wrap gap-1.5",children:us.map(r=>{const S=d.has(r),M=oe.get(r)??0;return e.jsxs("button",{type:"button",onClick:()=>Ce(r),className:`inline-flex h-7 items-center gap-1 rounded-full border px-2.5 text-micro transition-colors ${S?"border-[#14B8A6]/35 bg-[#14B8A6]/12 text-[#8FF7EC]":"border-strong bg-white/[0.03] text-white/58 hover:bg-white/[0.07] hover:text-bright"}`,children:[e.jsx("span",{children:ke(r)}),e.jsx("span",{className:"text-micro text-current/75",children:M})]},r)})})]}),(N!=="all"||d.size>0)&&e.jsx("button",{type:"button",onClick:()=>{m("all"),x(new Set)},className:"text-micro text-secondary transition-colors hover:text-primary",children:"Reset filters"})]})})]}),e.jsx(Oe,{initial:!1,children:_e&&e.jsx(le.button,{type:"button",onClick:Je,initial:{opacity:0,x:-4},animate:{opacity:1,x:0},exit:{opacity:0,x:-4},transition:{duration:.16,ease:[.22,1,.36,1]},className:"control-pill inline-flex h-8 items-center px-2.5 text-caption font-medium text-primary hover:text-bright",children:"Clear"},"hierarchy-clear-filters")}),e.jsx("button",{type:"button",onClick:He,"data-state":xe?"active":"idle",className:"control-pill inline-flex h-8 items-center gap-1.5 px-3.5 text-caption font-semibold",children:xe?"Clear visible":"Select visible"})]})]}),e.jsx("div",{className:"mb-1.5",children:e.jsx("div",{className:`rounded-xl border px-3 ${De>0?"border-[#BFFF00]/24 bg-[#BFFF00]/[0.08]":"border-white/[0.08] bg-white/[0.02]"}`,children:e.jsxs("div",{className:"flex h-[48px] min-w-max flex-nowrap items-center gap-2 overflow-x-auto py-1 whitespace-nowrap",children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-caption text-primary",children:[e.jsx("input",{ref:O,type:"checkbox",checked:xe,onChange:He,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-caption text-white/58",children:De>0?`${De} selected`:`${Fe.length} visible`}),De>0&&e.jsxs("div",{className:"flex flex-shrink-0 items-center gap-2 whitespace-nowrap",children:[e.jsx("button",{type:"button",onClick:()=>{Ie("planned")},disabled:Ee,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Plan"}),e.jsx("button",{type:"button",onClick:()=>{Ie("in_progress")},disabled:Ee,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45","data-state":"active",children:"Start"}),e.jsx("button",{type:"button",onClick:()=>{Ie("blocked")},disabled:Ee,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{Ie("done")},disabled:Ee,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Complete"}),D?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{Ye()},disabled:Ee,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-caption font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>_(!1),disabled:Ee,className:"control-pill h-8 flex-shrink-0 px-2.5 text-caption disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>_(!0),disabled:Ee,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-caption font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:Be,disabled:Ee,className:"text-caption text-secondary transition-colors hover:text-primary disabled:opacity-45",children:"Clear"})]})]})})}),W&&e.jsx("div",{role:"status","aria-live":"polite",className:"rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-white/72",children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:`mt-[3px] h-1.5 w-1.5 flex-shrink-0 rounded-full ${W.tone==="success"?"bg-emerald-300/90":"bg-amber-300/90"}`}),e.jsx("span",{className:"min-w-0 leading-snug",children:W.message})]}),e.jsx("button",{type:"button",onClick:()=>z(null),className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary","aria-label":"Dismiss notice",title:"Dismiss",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]})}),l&&e.jsx("div",{className:"mb-2 text-micro text-secondary",children:"Edit mode: select a row to edit its fields inline."}),e.jsx("div",{className:"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-micro uppercase tracking-[0.08em] text-muted",children:[e.jsx("th",{className:"w-10 px-2 py-1.5 sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},children:e.jsx("span",{className:"sr-only",children:"Select rows"})}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},onClick:()=>we("title"),children:["Item ",e.jsx(je,{field:"title"})]}),e.jsx("th",{className:"w-[188px] px-2 py-1.5 sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},children:"Assigned"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},onClick:()=>we("status"),children:["Status ",e.jsx(je,{field:"status"})]}),e.jsx("th",{className:"px-2 py-1.5 sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},children:"Progress"}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},onClick:()=>we("priority"),children:["Priority ",e.jsx(je,{field:"priority"})]}),e.jsxs("th",{className:"px-2 py-1.5 cursor-pointer select-none sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},onClick:()=>we("eta"),children:["ETA ",e.jsx(je,{field:"eta"})]}),e.jsx("th",{className:"px-2 py-1.5 sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},children:"Duration (h)"}),e.jsx("th",{className:"px-2 py-1.5 sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},children:"Budget ($)"}),e.jsx("th",{className:"px-2 py-1.5 sticky z-10 bg-[#090B11]/92 backdrop-blur-xl border-b border-subtle",style:{top:Me},children:"Dependencies"})]})}),e.jsx("tbody",{children:Fe.map(({node:r,depth:S,canCollapse:M})=>{var pe;const Y=o===r.id,Z=u.has(r.id),ue=X.has(r.id),he=r.assignedAgents.map($=>$.name).join(", "),y=r.dependencyIds.map($=>{var ce;return((ce=L.get($))==null?void 0:ce.title)??$}).slice(0,3).join(", "),j=Le.get(r.id),B=l&&Y;return e.jsxs("tr",{onClick:()=>{a(r.id),r.type==="workstream"&&b(r.id)},className:`group/row cursor-pointer rounded-lg border transition-colors ${Y?"border-[#BFFF00]/[0.22] bg-[#BFFF00]/[0.08]":Z?"border-[#14B8A6]/[0.2] bg-[#14B8A6]/[0.08]":"border-subtle bg-white/[0.02] hover:border-strong hover:bg-white/[0.05]"}`,children:[e.jsx("td",{className:"rounded-l-lg px-2 py-1.5",children:e.jsx("input",{type:"checkbox",checked:ue,onChange:$=>{$.stopPropagation();const ce=$.nativeEvent.shiftKey??!1;ae(r.id,$.currentTarget.checked,ce)},onClick:$=>$.stopPropagation(),"aria-label":`Select ${r.type}: ${r.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:S*14}}),M?e.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),me(ce=>{const Pe=new Set(ce);return Pe.has(r.id)?Pe.delete(r.id):Pe.add(r.id),Pe})},"aria-label":`${ge.has(r.id)?"Collapse":"Expand"} ${r.type}: ${r.title}`,className:"rounded text-secondary focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:ge.has(r.id)?"▾":"▸"}):e.jsx("span",{className:"w-2.5"}),e.jsx(Ct,{type:r.type}),e.jsx("button",{type:"button",onClick:$=>{$.stopPropagation(),f(r)},"aria-label":`Open ${r.type} details: ${r.title}`,className:"max-w-[320px] truncate rounded text-body text-bright hover:text-white focus:outline-none focus-visible:ring-2 focus-visible:ring-[#BFFF00]/35 focus-visible:ring-offset-2 focus-visible:ring-offset-[#02040A]",children:r.title}),!l&&(r.type==="workstream"||r.type==="milestone"||r.type==="task")&&e.jsxs("div",{className:"flex items-center gap-0.5 opacity-0 group-hover/row:opacity-100 transition-opacity ml-1",children:[r.type==="task"&&p?e.jsx(e.Fragment,{children:["not_started","todo","planned","pending","backlog"].includes(r.status.toLowerCase())?e.jsx("button",{type:"button",title:"Start",onClick:$=>{$.stopPropagation(),F(r,{status:"in_progress"})},"aria-label":`Start task: ${r.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-muted 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(r.status.toLowerCase())?e.jsx("button",{type:"button",title:"Mark done",onClick:$=>{$.stopPropagation(),F(r,{status:"done"})},"aria-label":`Mark task done: ${r.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-muted 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}):null,e.jsx("button",{type:"button",title:"Add to Next Up",onClick:$=>{$.stopPropagation(),Te(r)},"aria-label":`Add to Next Up: ${r.type} ${r.title}`,className:"flex items-center justify-center w-5 h-5 rounded text-muted 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.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.8",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})})]})]})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary whitespace-nowrap",children:B?e.jsx("input",{type:"text",defaultValue:he,placeholder:"Agent A, Agent B",onClick:$=>$.stopPropagation(),onBlur:$=>{const ce=$.currentTarget.value.split(",").map(Pe=>Pe.trim()).filter(Boolean);F(r,{assigned_agent_names:ce,assigned_agent_ids:ce.map(Pe=>`name:${Pe}`),assignment_source:"manual"})},className:"w-[190px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("div",{className:"flex items-center gap-2",children:r.assignedAgents.length>0?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center -space-x-1.5",children:r.assignedAgents.slice(0,3).map($=>e.jsx("div",{title:$.name,className:"rounded-full ring-1 ring-[#02040A]",children:e.jsx(Jt,{name:$.name,hint:`${$.id} ${r.title}`,size:"xs"})},`${r.id}:${$.id}`))}),e.jsxs("span",{className:"max-w-[110px] truncate text-micro text-white/62",title:he,children:[(pe=r.assignedAgents[0])==null?void 0:pe.name,r.assignedAgents.length>1?` +${r.assignedAgents.length-1}`:""]})]}):e.jsx("span",{className:"text-muted",children:"Unassigned"})})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:B?e.jsx("select",{defaultValue:gt(r.status),onClick:$=>$.stopPropagation(),onChange:$=>{F(r,{status:$.target.value})},className:"rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82",children:us.map($=>e.jsx("option",{value:$,children:ke($)},$))}):e.jsx("span",{className:"status-pill whitespace-nowrap","data-tone":fr(r.status),children:ke(r.status)})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:j!==void 0&&(r.type==="workstream"||r.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:`${j}%`,backgroundColor:r.type==="milestone"?q.teal:q.lime}})}),e.jsxs("span",{className:"text-micro text-secondary",style:{fontVariantNumeric:"tabular-nums"},children:[j,"%"]})]}):e.jsx("span",{className:"text-muted",children:"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:B?e.jsx("input",{type:"number",min:1,max:100,defaultValue:r.priorityNum,onClick:$=>$.stopPropagation(),onBlur:$=>{const ce=Number($.currentTarget.value);Number.isFinite(ce)&&F(r,{priority_num:ce})},className:"w-[72px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsxs("span",{children:["P",r.priorityNum]})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:B?e.jsx("input",{type:"datetime-local",defaultValue:hr(r.etaEndAt),onClick:$=>$.stopPropagation(),onBlur:$=>{const ce=$.currentTarget.value;F(r,{eta_end_at:ce?new Date(ce).toISOString():null})},className:"w-[176px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("span",{children:r.etaEndAt?new Date(r.etaEndAt).toLocaleString():"—"})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:B&&r.type!=="task"?e.jsx("input",{type:"number",min:0,step:.5,defaultValue:r.expectedDurationHours,onClick:$=>$.stopPropagation(),onBlur:$=>{const ce=Number($.currentTarget.value);Number.isFinite(ce)&&F(r,{expected_duration_hours:ce})},className:"w-[82px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsx("span",{children:r.expectedDurationHours})}),e.jsx("td",{className:"px-2 py-1.5 text-caption text-primary",children:B&&r.type!=="task"?e.jsx("input",{type:"number",min:0,step:1,defaultValue:r.expectedBudgetUsd,onClick:$=>$.stopPropagation(),onBlur:$=>{const ce=Number($.currentTarget.value);Number.isFinite(ce)&&F(r,{expected_budget_usd:ce})},className:"w-[92px] rounded border border-strong bg-white/[0.06] px-2 py-1 text-micro text-white/82"}):e.jsxs("span",{children:["$",r.expectedBudgetUsd.toLocaleString(),B&&r.type==="task"?" (from task spec)":""]})}),e.jsx("td",{className:"rounded-r-lg px-2 py-1.5 text-caption text-primary",children:B?e.jsx("div",{onClick:$=>$.stopPropagation(),children:e.jsx(xr,{dependencies:r.dependencyIds,allNodes:k,onSave:$=>void F(r,{depends_on:$})})}):e.jsx("div",{className:"max-w-[250px] truncate",children:We(r)>0?`${We(r)} · ${y}`:"—"})})]},r.id)})})]})}),Fe.length===0&&e.jsxs("div",{className:"flex flex-col items-center py-10",children:[e.jsxs("svg",{width:"32",height:"32",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-faint",children:[e.jsx("path",{d:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2"}),e.jsx("rect",{x:"9",y:"3",width:"6",height:"4",rx:"1"}),e.jsx("path",{d:"M9 14h6M9 18h4"})]}),e.jsx("div",{className:"mt-3 text-body font-medium text-secondary",children:i||d.size>0||N!=="all"?"No items match the current filters":"No work items yet"}),e.jsx("div",{className:"mt-1 text-caption text-muted",children:i||d.size>0||N!=="all"?"Try adjusting your search or filter criteria.":"Workstreams, milestones, and tasks will appear here."})]})]})}function ps(t){if(!t)return"No target date";const s=new Date(t);return Number.isNaN(s.getTime())?"No target date":`Due ${s.toLocaleDateString()}`}function jr({recentTodoIds:t,nodesById:s,selectedNodeId:o,onSelectNode:u}){const l=t.map(b=>s.get(b)).filter(b=>!!b).sort((b,f)=>{if(b.priorityNum!==f.priorityNum)return b.priorityNum-f.priorityNum;const F=b.dueDate?Date.parse(b.dueDate):Number.POSITIVE_INFINITY,p=f.dueDate?Date.parse(f.dueDate):Number.POSITIVE_INFINITY;return F-p}).slice(0,14);if(l.length===0)return null;const c=l[0],a=l.slice(1,7);return e.jsxs("section",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Queue overview"}),e.jsxs("span",{className:"rounded-full border border-white/15 bg-black/20 px-2 py-0.5 text-micro text-secondary",children:[l.length," in queue"]})]}),e.jsx("button",{type:"button",onClick:()=>u(c.id),className:`surface-hero group w-full rounded-xl border px-3.5 py-3 text-left transition-colors ${o===c.id?"border-[#BFFF00]/35 bg-[#BFFF00]/14":"border-white/15 bg-black/25 hover:border-white/30 hover:bg-white/[0.08]"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-micro uppercase tracking-[0.1em] text-secondary",children:[e.jsx(Ct,{type:c.type}),e.jsx("span",{children:"Priority task"})]}),e.jsx("p",{className:"mt-1 line-clamp-2 text-body font-semibold leading-snug text-white",children:c.title}),e.jsx("p",{className:"mt-1 text-caption text-secondary",children:ps(c.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full border px-2 py-0.5 text-micro font-semibold",style:{borderColor:`${q.amber}44`,backgroundColor:`${q.amber}22`,color:q.amber},children:["P",c.priorityNum]})]})}),a.length>0&&e.jsx("div",{className:"space-y-1.5",children:a.map(b=>e.jsxs("button",{type:"button",onClick:()=>u(b.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 ${o===b.id?"border-[#BFFF00]/30 bg-[#BFFF00]/12":"border-strong bg-black/20 hover:bg-white/[0.08]"}`,children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"inline-flex items-center gap-1.5 text-micro uppercase tracking-[0.08em] text-secondary",children:[e.jsx(Ct,{type:b.type}),e.jsx("span",{children:"Queued"})]}),e.jsx("p",{className:"mt-1 line-clamp-1 break-words text-caption leading-snug text-bright",title:b.title,children:b.title}),e.jsx("p",{className:"mt-1 text-micro text-secondary",children:ps(b.dueDate)})]}),e.jsxs("span",{className:"inline-flex flex-shrink-0 rounded-full px-1.5 py-0.5 text-micro",style:{backgroundColor:`${q.amber}22`,color:`${q.amber}`},children:["P",b.priorityNum]})]},b.id))})]})}function vr(t,s){try{const o=localStorage.getItem(`orgx.section.${t}`);if(o==="0")return!1;if(o==="1")return!0}catch{}return s}function Nr(t,s){try{localStorage.setItem(`orgx.section.${t}`,s?"1":"0")}catch{}}function yt({title:t,defaultOpen:s=!0,storageKey:o,sticky:u=!1,stickyOffsetClass:l="top-0",stickyTop:c,contentOverflowVisible:a=!1,children:b}){const[f,F]=n.useState(()=>o?vr(o,s):s),[p,A]=n.useState(!1),R=n.useRef(null),[w,i]=n.useState(40),v=()=>{const d=!f;F(d),o&&Nr(o,d)};return n.useEffect(()=>{if(!u)return;const d=R.current;if(!d)return;const x=()=>{const m=Math.max(34,d.offsetHeight);i(g=>g===m?g:m)};if(x(),typeof ResizeObserver>"u")return;const N=new ResizeObserver(()=>x());return N.observe(d),()=>N.disconnect()},[u,c,t]),e.jsxs("div",{style:u?{"--mc-collapsible-header-offset":`${w}px`}:void 0,children:[e.jsxs("button",{ref:u?R:void 0,type:"button","data-mc-section-header":t,onClick:v,className:`flex w-full items-center gap-2 rounded-lg border px-2 py-2 text-left transition-colors ${u?`sticky ${l} z-20 border-white/[0.08] bg-[#090B11]/92 shadow-[0_8px_18px_rgba(0,0,0,0.24)] backdrop-blur-xl`:"border-transparent hover:border-subtle hover:bg-white/[0.03]"}`,style:u&&c?{top:c}:void 0,children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:`text-muted transition-transform duration-200 ${f?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})}),e.jsx("span",{className:"text-caption font-semibold tracking-[0.02em] text-white/68",children:t})]}),e.jsx(Oe,{initial:!1,children:f&&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},onAnimationStart:()=>A(!0),onAnimationComplete:()=>A(!1),className:a&&!p?"overflow-visible":"overflow-hidden",children:b})})]})}function kr(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 o=Number(s.replace(/^p/,""));return Number.isFinite(o)?{priorityNum:Math.max(1,Math.min(100,Math.round(o))),priorityLabel:null}:{priorityNum:60,priorityLabel:null}}function Cr(t){const s=t.toLowerCase();return["todo","not_started","planned","pending","backlog"].includes(s)}function Sr(t){const s=t.toLowerCase();return["in_progress","active","running","queued"].includes(s)}function Fr(t,s){const o={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},l=(s.workstreams.length>0?s.workstreams:(t.workstreams??[]).map(p=>({id:p.id,name:p.name,summary:null,status:p.status,progress:null,initiativeId:t.id,createdAt:null}))).map(p=>({id:p.id,type:"workstream",title:p.name,status:p.status,parentId:t.id,initiativeId:t.id,workstreamId:p.id,milestoneId:null,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:null,etaEndAt:null,expectedDurationHours:16,expectedBudgetUsd:300,assignedAgents:[],updatedAt:p.createdAt})),c=new Set(l.map(p=>p.id)),a=s.milestones.map(p=>({id:p.id,type:"milestone",title:p.title,status:p.status,parentId:p.workstreamId&&c.has(p.workstreamId)?p.workstreamId:t.id,initiativeId:t.id,workstreamId:p.workstreamId&&c.has(p.workstreamId)?p.workstreamId:null,milestoneId:p.id,priorityNum:50,priorityLabel:"medium",dependencyIds:[],dueDate:p.dueDate,etaEndAt:p.dueDate,expectedDurationHours:6,expectedBudgetUsd:120,assignedAgents:[],updatedAt:p.createdAt})),b=new Set(a.map(p=>p.id)),f=s.tasks.map(p=>{const A=kr(p.priority),R=p.milestoneId&&b.has(p.milestoneId),w=p.workstreamId&&c.has(p.workstreamId);return{id:p.id,type:"task",title:p.title,status:p.status,parentId:R?p.milestoneId:w?p.workstreamId:t.id,initiativeId:t.id,workstreamId:w?p.workstreamId:null,milestoneId:R?p.milestoneId:null,priorityNum:A.priorityNum,priorityLabel:A.priorityLabel,dependencyIds:[],dueDate:p.dueDate,etaEndAt:p.dueDate,expectedDurationHours:2,expectedBudgetUsd:40,assignedAgents:[],updatedAt:p.createdAt}}),F=f.filter(p=>["todo","not_started","planned","pending","backlog"].includes(p.status.toLowerCase())).sort((p,A)=>{const R=p.priorityNum-A.priorityNum;if(R!==0)return R;const w=p.etaEndAt?Date.parse(p.etaEndAt):1/0,i=A.etaEndAt?Date.parse(A.etaEndAt):1/0;if(w!==i)return w-i;const v=p.updatedAt?Date.parse(p.updatedAt):0;return(A.updatedAt?Date.parse(A.updatedAt):0)-v}).map(p=>p.id);return{nodes:[o,...l,...a,...f],edges:[],recentTodos:F}}function Dr(t,s){if(!t)return new Set;const o=new Map(s.map(a=>[a.id,a])),u=new Map;for(const a of s)for(const b of a.dependencyIds){const f=u.get(b)??[];f.push(a.id),u.set(b,f)}const l=new Set,c=[t];for(;c.length>0;){const a=c.shift();if(l.has(a))continue;l.add(a);const b=o.get(a);if(b){for(const f of b.dependencyIds)l.has(f)||c.push(f);for(const f of u.get(a)??[])l.has(f)||c.push(f)}}return l}function Er(t,s){return{id:t.id,name:t.title,summary:null,status:t.status,progress:null,initiativeId:s.id,createdAt:t.updatedAt}}function Mr(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 Ar(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 Ir(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 pt={hidden:{opacity:0},show:{opacity:1}};function wt({label:t,value:s}){return e.jsxs("div",{className:"rounded-lg border border-white/[0.08] bg-white/[0.03] px-2.5 py-2",children:[e.jsx("div",{className:"text-micro text-secondary",children:t}),e.jsx("div",{className:"mt-0.5 text-body font-semibold text-bright",children:s})]})}function Br({initiative:t,selected:s=!1,onSelectionChange:o,runtimeActivity:u=null}){var he;const{expandedInitiatives:l,toggleExpanded:c,openModal:a,agentEntityMap:b,authToken:f,embedMode:F,mutations:p}=et(),[A,R]=n.useState(!1),[w,i]=n.useState(null),[v,d]=n.useState(null),[x,N]=n.useState(!1),[m,g]=n.useState(!1),I=n.useRef(null),[K,ee]=n.useState(52),[se,ie]=n.useState(0),X=l.has(t.id),{graph:V,isLoading:D,degraded:_,error:W}=dr({initiativeId:t.id,authToken:f,embedMode:F,enabled:X}),{details:z,isLoading:O,error:G}=St({initiativeId:t.id,authToken:f,embedMode:F,enabled:X}),L=n.useMemo(()=>Fr(t,z),[t,z]),k=!!(V&&V.nodes.length>0),oe=L.nodes.length>0,C=!k&&oe,U=C?L.nodes:k?(V==null?void 0:V.nodes)??[]:L.nodes,H=C?L.edges:k?(V==null?void 0:V.edges)??[]:L.edges,re=C?L.recentTodos:k?(V==null?void 0:V.recentTodos)??[]:L.recentTodos,ne=_.some(y=>/401|unauthorized/i.test(y))||!!(W&&/401|unauthorized/i.test(W))||!!(G&&/401|unauthorized/i.test(G)),T=W&&/unknown api endpoint/i.test(W)?"Graph API unavailable. Showing session-derived data.":W,fe=G,ge=[..._,...T?[T]:[],...fe?[`Entity data partially unavailable: ${fe}`]:[],...ne?["OrgX auth is missing or expired in this local plugin instance. Reconnect in onboarding to load full workstreams/milestones/tasks."]:[]],me=n.useMemo(()=>new Map(U.map(y=>[y.id,y])),[U]),Ae=n.useMemo(()=>Dr(w,U),[w,U]),Fe=n.useMemo(()=>re.some(y=>me.has(y)),[me,re]);n.useEffect(()=>{const y=I.current;if(!y||!X)return;const j=()=>{const pe=Math.max(48,y.offsetHeight);ee($=>$===pe?$:pe)};if(j(),typeof ResizeObserver>"u")return;const B=new ResizeObserver(()=>j());return B.observe(y),()=>B.disconnect()},[X,t.status,t.targetDate,t.name]),n.useEffect(()=>{const y=I.current;if(!y||!X){ie(0);return}const j=y.closest('[data-mc-scroll-host="true"]')??y.closest(".h-full.overflow-y-auto.overflow-x-hidden"),B=j??window;let pe=0;const $=()=>{pe=0;const Pe=Number.parseFloat(getComputedStyle(y).top||"0"),it=y.getBoundingClientRect(),At=(j==null?void 0:j.getBoundingClientRect().top)??0,It=1-(it.top-At-Pe)/56,Se=Math.pow(Math.max(0,Math.min(1,It)),1.2);ie(Ke=>Math.abs(Ke-Se)<.015?Ke:Se)},ce=()=>{pe||(pe=window.requestAnimationFrame($))};return $(),B.addEventListener("scroll",ce,{passive:!0}),window.addEventListener("resize",ce),()=>{pe&&window.cancelAnimationFrame(pe),B.removeEventListener("scroll",ce),window.removeEventListener("resize",ce)}},[X,t.id]),n.useEffect(()=>{var y;X&&!w&&U.length>0&&i(((y=U[0])==null?void 0:y.id)??null)},[X,U,w]);const Qe=((V==null?void 0:V.initiative.assignedAgents)??[]).map(y=>({id:y.id,name:y.name,confidence:"high"})),at=b.get(t.id)??[],qe=Qe.length>0?Qe:at,ye=U.filter(y=>y.type==="task"),Ve=ye.filter(y=>Sr(y.status)).length,_e=ye.filter(y=>Cr(y.status)).length,De=ye.filter(y=>$e(y.status)).length,xe=(u==null?void 0:u.activeCount)??0,Ee=(u==null?void 0:u.totalCount)??0,We=Ve>0||xe>0,Te=t.status==="active"&&We?"in_progress":t.status,Le=Te==="in_progress"?kt.active:kt[Te],we=Te==="in_progress"?"In Progress":ke(Te),Ce=ye.length>0?ye:U.some(y=>y.type==="milestone")?U.filter(y=>y.type==="milestone"):U.filter(y=>y.type==="workstream"),Je=Math.round(Ce.reduce((y,j)=>y+(j.expectedDurationHours||0),0)*10)/10,ae=Math.round(Ce.reduce((y,j)=>y+(j.expectedBudgetUsd||0),0)*100)/100,He=U.filter(y=>y.type==="milestone"),Be=U.filter(y=>y.type==="workstream"),Ie=X&&(k||z.workstreams.length>0||z.milestones.length>0||z.tasks.length>0),Ye=ye.length>0?nt(De,ye.length):He.length>0?nt(He.filter(y=>$e(y.status)).length,He.length):Ie&&Be.length>0?nt(Be.filter(y=>$e(y.status)).length,Be.length):null,je=Et(Ye===null?t.health:Ye),Me=je===0?2:je,r=Math.pow(se,.82),S=Math.max(0,Number((16*(1-r)).toFixed(2))),M=`0 10px 26px rgba(0,0,0,${(.18+r*.24).toFixed(3)}), 0 1px 0 rgba(191,255,0,${(r*.09).toFixed(3)})`,Y=y=>{if(y.type==="initiative"){a({type:"initiative",entity:t});return}if(y.type==="workstream"){a({type:"workstream",entity:Er(y,t),initiative:t});return}if(y.type==="milestone"){a({type:"milestone",entity:Mr(y,t),initiative:t});return}a({type:"task",entity:Ar(y,t),initiative:t})},Z=async(y,j)=>{await p.updateEntity.mutateAsync({type:y.type,id:y.id,...j})},ue=y=>j=>{j.stopPropagation(),p.entityAction.mutate({type:"initiative",id:t.id,action:y})};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 ${X?"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":`${K}px`},children:[e.jsxs("div",{ref:I,role:"button",tabIndex:0,"aria-expanded":X,onClick:()=>c(t.id),onKeyDown:y=>{(y.key==="Enter"||y.key===" ")&&(y.preventDefault(),c(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 ${X?"sticky z-30 border-b border-subtle bg-[#0C0E14]/95 shadow-[0_8px_20px_rgba(0,0,0,0.3)] backdrop-blur-xl":""}`,style:X?{top:"var(--mc-toolbar-offset, 88px)",borderTopLeftRadius:`${S}px`,borderTopRightRadius:`${S}px`,boxShadow:M}:void 0,children:[e.jsx(le.div,{animate:{rotate:X?90:0},transition:{type:"spring",stiffness:400,damping:25},className:"flex-shrink-0 flex items-center justify-center w-6 h-6 rounded-md transition-colors group-hover:bg-white/[0.06]",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-muted",children:e.jsx("path",{d:"m9 18 6-6-6-6"})})}),o&&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:y=>{const j=y.nativeEvent.shiftKey??!1;o(t.id,y.currentTarget.checked,j)},onClick:y=>y.stopPropagation(),"aria-label":`Select initiative ${t.name}`,className:"h-3.5 w-3.5 rounded border-white/20 bg-black/40 text-[#BFFF00] focus:ring-[#BFFF00]/35"})}),e.jsx("span",{className:`w-2 h-2 rounded-full flex-shrink-0 ${We?"status-breathe":""}`,style:{backgroundColor:ls(Te)}}),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:y=>{y.stopPropagation(),a({type:"initiative",entity:t})},className:"block w-full max-w-full overflow-hidden text-ellipsis whitespace-nowrap text-left text-body font-semibold text-white transition-colors hover:text-primary sm:text-heading",title:t.name,children:t.name})}),e.jsx("div",{className:"ml-1 flex 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-micro px-2 py-0.5 rounded-full border uppercase tracking-[0.08em] leading-none whitespace-nowrap ${Le}`,children:we})}),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:`${Me}%`,opacity:je===0?.45:1},transition:{type:"spring",stiffness:260,damping:34,mass:.75},style:{backgroundColor:ls(Te)}})})}),e.jsxs("span",{className:"w-[42px] text-right text-micro text-muted sm:w-[48px] sm:text-caption",style:{fontVariantNumeric:"tabular-nums"},children:[je,"%"]})]}),e.jsx("div",{className:"ml-2 flex w-[104px] min-w-[104px] flex-shrink-0 items-center justify-end border-l border-subtle pl-2 sm:w-[116px] sm:min-w-[116px] sm:pl-2.5 md:w-[132px] md:min-w-[132px]",children:xe>0?e.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/14 px-2 py-0.5 text-micro font-semibold text-[#D8FFA1]",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00] status-breathe"}),xe," live"]}):qe.length>0?e.jsx(Dt,{agents:qe,max:3}):Ee>0?e.jsxs("span",{className:"w-full text-right text-micro text-muted",children:[Ee," idle"]}):e.jsx("span",{className:"w-full text-right text-micro text-white/28",children:"—"})}),e.jsxs("div",{className:"hidden w-[46px] flex-shrink-0 translate-x-1 items-center justify-end gap-1 opacity-0 transition-all duration-200 group-hover:translate-x-0 group-hover:opacity-100 group-focus-within:translate-x-0 group-focus-within:opacity-100 2xl:flex",children:[t.status==="active"&&e.jsx("button",{type:"button",onClick:ue("pause"),title:"Pause",className:"flex items-center justify-center w-6 h-6 rounded-lg text-secondary hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:[e.jsx("rect",{x:"6",y:"4",width:"4",height:"16",rx:"1"}),e.jsx("rect",{x:"14",y:"4",width:"4",height:"16",rx:"1"})]})}),t.status==="paused"&&e.jsx("button",{type:"button",onClick:ue("resume"),title:"Resume",className:"flex items-center justify-center w-6 h-6 rounded-lg text-secondary hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})})}),e.jsx("button",{type:"button",onClick:y=>{y.stopPropagation(),a({type:"initiative",entity:t})},title:"Details",className:"flex items-center justify-center w-6 h-6 rounded-lg text-secondary hover:text-white hover:bg-white/[0.08] transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 16v-4M12 8h.01"})]})})]})]}),e.jsx(Oe,{children:X&&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:()=>g(!0),onAnimationComplete:()=>g(!1),className:m?"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"}),D||!k&&O?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((y,j)=>e.jsx(Ze,{className:"h-24 w-full rounded-xl"},`mc-loading-${j}`))}):e.jsxs(le.div,{initial:"hidden",animate:"show",variants:{hidden:{},show:{transition:{staggerChildren:.08}}},className:"space-y-3.5",children:[ge.length>0&&e.jsxs(le.div,{variants:pt,className:"overflow-hidden rounded-lg border border-amber-300/15 bg-amber-500/[0.06]",children:[e.jsxs("button",{type:"button",onClick:()=>N(y=>!y),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-caption text-amber-100/85",children:[ge.length," data source",ge.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 ${x?"rotate-180":""}`,children:e.jsx("path",{d:"m6 9 6 6 6-6"})})]}),e.jsx(Oe,{children:x&&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:ge.map((y,j)=>e.jsx("div",{className:"text-micro text-amber-100/72",children:Ir(y)},j))})})})]}),(_e>0||Ve>0||Je>0||ae>0)&&e.jsx(le.div,{variants:pt,children:e.jsx(yt,{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(wt,{label:"Queue",value:`${_e} todo · ${Ve} active`}),e.jsx(wt,{label:"Completed",value:`${De}/${ye.length||0}`}),e.jsx(wt,{label:"Duration",value:`${Je}h`}),e.jsx(wt,{label:"Budget",value:`$${ae.toLocaleString()}`})]})})}),v&&e.jsxs("div",{className:"subsection-shell flex items-center justify-between rounded-lg px-3 py-2 text-caption text-[#D8FFA1]",children:[e.jsxs("span",{children:["Focused on workstream ",((he=me.get(v))==null?void 0:he.title)??v]}),e.jsx("button",{type:"button",onClick:()=>d(null),className:"text-micro underline underline-offset-2",children:"Clear focus"})]}),e.jsx(le.div,{variants:pt,children:e.jsx(yt,{title:"Dependency Map",storageKey:`depmap.${t.id}`,defaultOpen:!0,children:e.jsx(pr,{nodes:U,edges:H,selectedNodeId:w,focusedWorkstreamId:v,onSelectNode:y=>{i(y);const j=me.get(y);(j==null?void 0:j.type)==="workstream"&&d(j.id)}})})}),Fe&&e.jsx(le.div,{variants:pt,children:e.jsx(yt,{title:"Next Up",storageKey:`nextup.${t.id}`,defaultOpen:!0,children:e.jsx(jr,{recentTodoIds:re,nodesById:me,selectedNodeId:w,onSelectNode:y=>{i(y);const j=me.get(y);(j==null?void 0:j.type)==="workstream"&&d(j.id)}})})}),e.jsx(le.div,{variants:pt,children:e.jsx(yt,{title:"Hierarchy",storageKey:`hierarchy.${t.id}`,defaultOpen:!0,contentOverflowVisible:!0,children:e.jsx(wr,{nodes:U,edges:H,selectedNodeId:w,highlightedNodeIds:Ae,editMode:A,onSelectNode:i,onFocusWorkstream:d,onOpenNode:Y,onUpdateNode:Z,onToggleEditMode:()=>R(y=>!y),mutations:p})})})]}),e.jsxs("button",{type:"button",onClick:()=>c(t.id),className:"flex w-full items-center justify-center gap-1.5 py-1.5 text-micro text-muted transition-colors hover:text-secondary",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("path",{d:"m18 15-6-6-6 6"})}),"Collapse"]})]})})})]})}const $r={hidden:{opacity:0},show:{opacity:1,transition:{staggerChildren:.045,delayChildren:.02}}},_r={hidden:{opacity:0,y:10,scale:.995},show:{opacity:1,y:0,scale:1,transition:{type:"spring",stiffness:320,damping:28,mass:.7}}};function ms({initiatives:t,selectedInitiativeIds:s,onToggleInitiativeSelection:o,runtimeActivityByInitiativeId:u}){return e.jsx(le.div,{variants:$r,initial:"hidden",animate:"show",className:"space-y-2",children:t.map(l=>e.jsx(le.div,{variants:_r,layout:!0,transition:{type:"spring",stiffness:280,damping:32,mass:.75},children:e.jsx(Br,{initiative:l,selected:(s==null?void 0:s.has(l.id))??!1,onSelectionChange:o,runtimeActivity:(u==null?void 0:u.get(l.id))??null})},l.id))})}function xs({mode:t="empty",hasActiveFilters:s=!1,onClearFilters:o,onCreateInitiative:u,onPlayNextUp:l,onStartAutopilot:c,onRefresh:a}){const[b,f]=n.useState(null),[F,p]=n.useState(null),A=n.useCallback(async(i,v)=>{if(v){p(null),f(i);try{await v()}catch(d){p(d instanceof Error?d.message:"Action failed")}finally{f(d=>d===i?null:d)}}},[]),R=t==="filtered"?"No initiatives match this view":"No initiatives yet",w=t==="filtered"?s?"Adjust filters or clear them to return to the full hierarchy.":"Try a broader search or create a new initiative.":"Create an initiative to unlock hierarchy, Next Up routing, and slice-level tracking.";return e.jsx("div",{className:"flex-1 flex items-center justify-center p-6 sm:p-10",children:e.jsx(Qs,{className:"w-full max-w-xl p-6 sm:p-7",children:e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-start gap-3.5",children:[e.jsx("div",{className:"relative flex h-12 w-12 items-center justify-center rounded-xl",style:{backgroundColor:`${q.iris}1a`,border:`1px solid ${q.iris}33`},children:e.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:q.iris,strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"12",cy:"12",r:"10"}),e.jsx("path",{d:"M12 6v6l4 2"})]})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("h3",{className:"text-heading font-semibold text-white",children:R}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:w})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t==="filtered"&&o&&e.jsx("button",{type:"button",onClick:o,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08]",children:"Clear filters"}),u&&e.jsx("button",{type:"button",onClick:u,className:"rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/12 px-3 py-1.5 text-caption font-semibold text-[#D8FFA1] transition hover:bg-[#BFFF00]/18",children:"Create initiative"}),l&&e.jsx("button",{type:"button",onClick:()=>void A("play",l),disabled:b!==null,className:"rounded-full border border-white/[0.12] bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-primary transition hover:bg-white/[0.08] disabled:opacity-45",children:b==="play"?"Dispatching...":"Play Next Up"}),c&&e.jsx("button",{type:"button",onClick:()=>void A("autopilot",c),disabled:b!==null,className:"rounded-full border border-[#0AD4C4]/30 bg-[#0AD4C4]/10 px-3 py-1.5 text-caption font-semibold text-[#98FFF5] transition hover:bg-[#0AD4C4]/16 disabled:opacity-45",children:b==="autopilot"?"Starting...":"Start Autopilot"}),a&&e.jsx("button",{type:"button",onClick:a,className:"rounded-full border border-strong bg-white/[0.03] px-3 py-1.5 text-caption font-semibold text-secondary transition hover:bg-white/[0.08] hover:text-primary",children:"Refresh"})]}),F&&e.jsx("p",{className:"text-caption text-amber-200/80",children:F})]})})})}function Q({label:t,icon:s,color:o="#BFFF00",variant:u="secondary",size:l="md",className:c="",type:a="button",...b}){const f=l==="sm"?"px-2.5 py-1 text-micro":"px-3 py-1.5 text-caption",F=u==="primary"?{backgroundColor:o,color:"#05060A",borderColor:`${o}CC`}:u==="destructive"?{backgroundColor:`${o}18`,color:o,borderColor:`${o}45`}:u==="ghost"?{backgroundColor:"rgba(255,255,255,0.03)",color:"rgba(255,255,255,0.75)",borderColor:"rgba(255,255,255,0.12)"}:{backgroundColor:`${o}20`,color:o,borderColor:`${o}30`};return e.jsxs("button",{type:a,className:`inline-flex items-center gap-1.5 rounded-lg border transition-colors disabled:cursor-not-allowed disabled:opacity-50 ${f} ${c}`,style:F,...b,children:[s,t&&e.jsx("span",{children:t})]})}const hs={draft:q.textMuted,in_review:q.amber,approved:q.lime,changes_requested:q.red,superseded:q.textMuted,archived:q.textMuted};function Tr(){return e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"flex-shrink-0 opacity-80",children:[e.jsx("path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"}),e.jsx("path",{d:"M14 2v4a2 2 0 0 0 2 2h4"})]})}async function fs(t,s,o){try{const u=ht(o),l=new URLSearchParams({entity_type:t,entity_id:s,limit:"20"}),c=await fetch(`/orgx/api/work-artifacts/by-entity?${l.toString()}`,{headers:u});if(!c.ok)return[];const a=await c.json();return(a==null?void 0:a.artifacts)??[]}catch{return[]}}function Mt({entityType:t,entityId:s,title:o="Artifacts",authToken:u=null,embedMode:l=!1,finalOnly:c=!1,milestoneIds:a}){const{open:b}=Js(),[f,F]=n.useState(!c),p=!!(a!=null&&a.length),A=vt({queryKey:xt.artifactsByEntity({entityType:t,entityId:s,authToken:u,embedMode:l}),enabled:!p&&!!s,queryFn:()=>fs(t,s,{authToken:u,embedMode:l})}),R=vt({queryKey:["artifacts-by-milestones",a,u,l],enabled:p,queryFn:async()=>{if(!(a!=null&&a.length))return[];const d=await Promise.all(a.map(N=>fs("milestone",N,{authToken:u,embedMode:l}))),x=new Map;for(const N of d)for(const m of N)x.has(m.id)||x.set(m.id,m);return[...x.values()].sort((N,m)=>Date.parse(m.updated_at)-Date.parse(N.updated_at))}}),w=p?R:A,i=w.data??[],v=f?i:i.filter(d=>d.status==="approved");return w.isLoading?e.jsxs("div",{className:"space-y-2",children:[e.jsx("h4",{className:"text-caption font-medium text-secondary",children:o}),e.jsx("div",{className:"shimmer-skeleton h-10 w-full rounded-lg"})]}):i.length===0?null:e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("h4",{className:"text-caption font-medium text-secondary",children:[o," (",v.length,")"]}),c&&e.jsx("button",{type:"button",onClick:()=>F(d=>!d),className:"text-micro text-faint transition-colors hover:text-secondary",children:f?"Final only":"Show all"})]}),e.jsxs("div",{className:"space-y-1.5",children:[v.slice(0,10).map(d=>e.jsxs("button",{type:"button",onClick:()=>b(d.id,{entityType:t,entityId:s}),className:"flex w-full items-center gap-2.5 rounded-lg border border-white/[0.06] bg-white/[0.02] px-3 py-2 text-left transition-colors hover:bg-white/[0.05]",children:[e.jsx(Tr,{}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"truncate text-body text-primary",children:d.name}),e.jsx("span",{className:"text-micro text-faint",children:d.artifact_type})]}),e.jsx("span",{className:"flex-shrink-0 rounded-full px-1.5 py-0.5 text-micro font-medium uppercase tracking-wider",style:{color:hs[d.status]??q.textMuted,backgroundColor:`${hs[d.status]??q.textMuted}15`},children:d.status})]},d.id)),v.length>10&&e.jsxs("p",{className:"text-micro text-faint pl-2",children:["+",v.length-10," more"]})]})]})}function Lr({initiative:t}){const{agentEntityMap:s,openModal:o,closeModal:u,authToken:l,embedMode:c,mutations:a}=et(),b=s.get(t.id)??[],[f,F]=n.useState(!1),[p,A]=n.useState(""),[R,w]=n.useState(!1),[i,v]=n.useState(!1),[d,x]=n.useState(null),[N,m]=n.useState(!1),[g,I]=n.useState(t.name),[K,ee]=n.useState(t.description??""),[se,ie]=n.useState(mt(t.priority)),[X,V]=n.useState(Vt(t.targetDate)),[D,_]=n.useState(null),{details:W,isLoading:z}=St({initiativeId:t.id,authToken:l,embedMode:c}),O=W.tasks.filter(T=>["active","in_progress"].includes(T.status.toLowerCase())).length,G=W.tasks.filter(T=>T.status.toLowerCase()==="blocked").length,L=W.tasks.filter(T=>$e(T.status)).length,k=D??t.status,oe=Pr(D??t.rawStatus??t.status),C=["active","in_progress","running","queued"].includes(oe),U=["paused","draft","planned","todo","backlog","pending","not_started"].includes(oe),H=a.entityAction.isPending||a.createEntity.isPending||a.updateEntity.isPending||a.deleteEntity.isPending;n.useEffect(()=>{R||(I(t.name),ee(t.description??""),V(Vt(t.targetDate)),ie(mt(t.priority)))},[R,t.description,t.name,t.priority,t.targetDate]),n.useEffect(()=>{_(null),v(!1)},[t.id,t.status,t.rawStatus]);const re=(T,fe,ge)=>{x(null),a.entityAction.mutate({type:"initiative",id:t.id,action:T},{onSuccess:()=>{_(fe),x(ge)},onError:me=>{x(me instanceof Error?me.message:`Failed to ${T} initiative.`)}})},ne=()=>{const T=g.trim();if(!T){x("Initiative title is required.");return}x(null),a.updateEntity.mutate({type:"initiative",id:t.id,title:T,summary:K.trim()||null,priority:se,target_date:X||null},{onSuccess:()=>{w(!1),x("Initiative updated.")},onError:fe=>{x(fe instanceof Error?fe.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(Ue,{type:"initiative",size:16}),e.jsx("h2",{className:"text-title font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${kt[k]??kt.active}`,children:ke(k)}),e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.08em] text-white/68",children:Rr(t.priority)})]}),R?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Title"}),e.jsx("input",{type:"text",value:g,onChange:T=>I(T.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Summary"}),e.jsx("textarea",{value:K,onChange:T=>ee(T.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Target date"}),e.jsx("input",{type:"date",value:X,onChange:T=>V(T.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Priority"}),e.jsxs("select",{value:se,onChange:T=>ie(mt(T.target.value)),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:[e.jsx("option",{value:"critical",children:"Critical (P0)"}),e.jsx("option",{value:"high",children:"High (P1)"}),e.jsx("option",{value:"medium",children:"Medium (P2)"}),e.jsx("option",{value:"low",children:"Low (P3)"})]})]})]}):t.description?e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:t.description}):e.jsx("p",{className:"text-body text-muted",children:"No summary yet."}),b.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Agents"}),e.jsx(Dt,{agents:b,max:6})]}),d&&e.jsx("div",{className:"text-caption text-secondary",children:d})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 sm:grid-cols-4",children:[e.jsx(jt,{label:"Workstreams",value:`${W.workstreams.length}`}),e.jsx(jt,{label:"Milestones",value:`${W.milestones.length}`}),e.jsx(jt,{label:"Active Tasks",value:`${O}`,accent:O>0?q.lime:void 0}),e.jsx(jt,{label:"Blocked",value:`${G}`,accent:G>0?q.red:void 0})]}),z?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((T,fe)=>e.jsx(Ze,{className:"h-14 w-full rounded-lg"},`init-detail-${fe}`))}):e.jsxs(e.Fragment,{children:[W.workstreams.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(bs,{title:"Workstreams",count:W.workstreams.length}),W.workstreams.map(T=>{const fe=W.tasks.filter(Ae=>Ae.workstreamId===T.id),ge=fe.filter(Ae=>$e(Ae.status)).length,me=fe.length>0?nt(ge,fe.length):typeof T.progress=="number"?Et(T.progress<=1?T.progress*100:T.progress):$e(T.status)?100:null;return e.jsxs("button",{onClick:()=>o({type:"workstream",entity:T,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3.5 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-body text-bright break-words",children:T.name}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Fs(T.status)}`,children:ke(T.status)})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-3 text-micro text-muted uppercase tracking-[0.08em]",children:[e.jsxs("span",{children:[fe.length," tasks"]}),me!==null&&e.jsxs("span",{children:[me,"%"]})]})]},T.id)})]}),W.milestones.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(bs,{title:"Milestones",count:W.milestones.length}),W.milestones.map(T=>e.jsxs("button",{onClick:()=>o({type:"milestone",entity:T,initiative:t}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-body text-bright break-words",children:T.title}),e.jsx("span",{className:"text-micro text-muted uppercase tracking-[0.08em]",children:ke(T.status)})]}),T.dueDate&&e.jsxs("span",{className:"text-micro text-muted mt-0.5 block",children:["Due: ",new Date(T.dueDate).toLocaleDateString()]})]},T.id))]}),e.jsxs("div",{className:"text-micro uppercase tracking-[0.08em] text-muted pt-2 border-t border-subtle",children:[W.tasks.length," total tasks · ",L," done"]}),e.jsx(Mt,{entityType:"initiative",entityId:t.id,authToken:l,embedMode:c}),e.jsxs("div",{className:"mt-4 space-y-2 rounded-2xl border border-white/[0.08] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.14em] text-muted",children:"Notes"}),e.jsx("p",{className:"mt-1 text-caption text-muted",children:"Lightweight context for humans and agents on this initiative."})]}),e.jsx("button",{type:"button",onClick:()=>m(T=>!T),className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09]",children:N?"Hide":"Show"})]}),N?e.jsx("div",{className:"pt-3 border-t border-subtle",children:e.jsx(Ft,{entityType:"initiative",entityId:t.id,authToken:l,embedMode:c})}):null]})]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[C&&e.jsx(Q,{label:"Pause",color:q.amber,onClick:()=>re("pause","paused","Initiative paused."),disabled:H}),U&&e.jsx(Q,{label:oe==="paused"?"Resume":"Start",color:q.lime,variant:"primary",onClick:()=>re("resume","active",oe==="paused"?"Initiative resumed.":"Initiative started."),disabled:H}),R?e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:"Save",color:q.teal,variant:"primary",onClick:ne,disabled:H||!g.trim()}),e.jsx(Q,{label:"Cancel",variant:"ghost",onClick:()=>{w(!1),I(t.name),ee(t.description??""),ie(mt(t.priority)),V(Vt(t.targetDate)),x(null)},disabled:H})]}):e.jsx(Q,{label:"Edit",variant:"ghost",onClick:()=>{w(!0),x(null)},disabled:H}),e.jsx("div",{className:"flex-1"}),i?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"Delete initiative?"}),e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>a.deleteEntity.mutate({type:"initiative",id:t.id},{onSuccess:()=>u(),onError:T=>x(T instanceof Error?T.message:"Failed to delete initiative.")}),disabled:H}),e.jsx(Q,{label:"Keep",variant:"ghost",onClick:()=>v(!1),disabled:H})]}):e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>v(!0),disabled:H}),f?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:T=>{T.preventDefault(),p.trim()&&a.createEntity.mutate({type:"workstream",title:p.trim(),initiative_id:t.id,status:"not_started"},{onSuccess:()=>{A(""),F(!1)}})},children:[e.jsx("input",{type:"text",value:p,onChange:T=>A(T.target.value),placeholder:"Workstream name...",autoFocus:!0,className:"text-body bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-primary placeholder-white/30 w-[180px] outline-none focus:border-white/25"}),e.jsx(Q,{type:"submit",label:"Add",color:q.lime,disabled:!p.trim()||a.createEntity.isPending,size:"sm"}),e.jsx(Q,{label:"Cancel",variant:"ghost",onClick:()=>{F(!1),A("")},size:"sm"})]}):e.jsx(Q,{label:"+ Workstream",variant:"ghost",onClick:()=>F(!0),disabled:H})]})})]})}function Vt(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function Pr(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function mt(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 Rr(t){const s=mt(t);return s==="critical"?"Priority: Critical":s==="high"?"Priority: High":s==="low"?"Priority: Low":"Priority: Medium"}function jt({label:t,value:s,accent:o}){return e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",style:o?{borderTopColor:`${o}50`,borderTopWidth:2}:void 0,children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:t}),e.jsx("div",{className:"text-heading font-medium mt-0.5",style:{color:o??"rgba(255,255,255,0.8)"},children:s})]})}function bs({title:t,count:s}){return e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:t}),e.jsx("span",{className:"text-micro text-muted",children:s})]})}function zr({workstream:t,initiative:s}){const{agentEntityMap:o,openModal:u,closeModal:l,authToken:c,embedMode:a,mutations:b}=et(),f=o.get(t.id)??o.get(s.id)??[],[F,p]=n.useState(!1),[A,R]=n.useState(""),[w,i]=n.useState(!1),[v,d]=n.useState(!1),[x,N]=n.useState(null),[m,g]=n.useState(!1),[I,K]=n.useState(t.name),[ee,se]=n.useState(t.summary??""),[ie,X]=n.useState(t.status),{details:V,isLoading:D}=St({initiativeId:s.id,authToken:c,embedMode:a}),_=n.useMemo(()=>V.milestones.filter(C=>C.workstreamId===t.id),[V.milestones,t.id]),W=n.useMemo(()=>new Set(_.map(C=>C.id)),[_]),z=n.useMemo(()=>V.tasks.filter(C=>C.workstreamId===t.id||C.milestoneId!==null&&W.has(C.milestoneId)).sort((C,U)=>{const H=Nt(C.status)-Nt(U.status);if(H!==0)return H;const re=C.createdAt?Date.parse(C.createdAt):0;return(U.createdAt?Date.parse(U.createdAt):0)-re}),[V.tasks,W,t.id]),O=z.filter(C=>$e(C.status)).length,G=z.length>0?nt(O,z.length):typeof t.progress=="number"?Et(t.progress<=1?t.progress*100:t.progress):$e(t.status)?100:null,L=t.status.toLowerCase(),k=b.entityAction.isPending||b.createEntity.isPending||b.updateEntity.isPending||b.deleteEntity.isPending,oe=()=>{const C=I.trim();if(!C){N("Workstream name is required.");return}N(null),b.updateEntity.mutate({type:"workstream",id:t.id,title:C,summary:ee.trim()||null,status:ie},{onSuccess:()=>{i(!1),N("Workstream updated.")},onError:U=>{N(U instanceof Error?U.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-caption",children:[e.jsx(Ue,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>u({type:"initiative",entity:s}),className:"break-words text-secondary transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Ue,{type:"workstream",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-primary",children:t.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ue,{type:"workstream",size:16}),e.jsx("h2",{className:"text-title font-semibold text-white",children:t.name}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Fs(t.status)}`,children:ke(t.status)})]}),w?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Name"}),e.jsx("input",{type:"text",value:I,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-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Summary"}),e.jsx("textarea",{value:ee,onChange:C=>se(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-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("select",{value:ie,onChange:C=>X(C.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:["not_started","planned","active","in_progress","paused","blocked","done"].map(C=>e.jsx("option",{value:C,children:ke(C)},C))})]})]}):t.summary?e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:t.summary}):e.jsx("p",{className:"text-body text-muted",children:"No summary yet."}),f.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Agents"}),e.jsx(Dt,{agents:f,max:6})]}),x&&e.jsx("div",{className:"text-caption text-secondary",children:x})]}),G!==null&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Progress"}),e.jsxs("span",{className:"text-body text-secondary",children:[G,"%"]})]}),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:`${G}%`,backgroundColor:q.lime}})})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Tasks"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children: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-micro uppercase tracking-[0.08em] text-muted",children:"Milestones"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:_.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Progress"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:G!==null?`${G}%`:"-"})]})]}),D?e.jsx("div",{className:"space-y-2",children:Array.from({length:3}).map((C,U)=>e.jsx(Ze,{className:"h-12 w-full rounded-lg"},`ws-detail-${U}`))}):e.jsxs(e.Fragment,{children:[_.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"Milestones"}),_.map(C=>e.jsx("button",{onClick:()=>u({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-body text-bright",children:C.title}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ds(C.status)}`,children:ke(C.status)})]})},C.id))]}),z.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:["Tasks (",z.length,")"]}),z.map(C=>e.jsxs("button",{onClick:()=>u({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-body text-bright",children:C.title}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Yt(C.status)}`,children:ke(C.status)})]}),C.priority&&e.jsxs("span",{className:"text-micro text-muted mt-0.5 block uppercase tracking-wider",children:["Priority: ",C.priority]})]},C.id))]}),e.jsx(Mt,{entityType:"workstream",entityId:t.id,title:"Artifacts (from milestones)",authToken:c,embedMode:a,finalOnly:!0,milestoneIds:_.map(C=>C.id)}),e.jsxs("div",{className:"mt-2 space-y-2 rounded-2xl border border-white/[0.08] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.14em] text-muted",children:"Notes"}),e.jsx("p",{className:"mt-1 text-caption text-muted",children:"Commentary thread for humans and agents on this workstream."})]}),e.jsx("button",{type:"button",onClick:()=>g(C=>!C),className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09]",children:m?"Hide":"Show"})]}),m?e.jsx("div",{className:"pt-3 border-t border-subtle",children:e.jsx(Ft,{entityType:"workstream",entityId:t.id,authToken:c,embedMode:a})}):null]})]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[["not_started","planned","todo"].includes(L)&&e.jsx(Q,{label:"Start",color:q.lime,variant:"primary",onClick:()=>b.entityAction.mutate({type:"workstream",id:t.id,action:"start"}),disabled:k}),["active","in_progress"].includes(L)&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:"Complete",color:q.teal,variant:"primary",onClick:()=>b.entityAction.mutate({type:"workstream",id:t.id,action:"complete"}),disabled:k}),e.jsx(Q,{label:"Pause",color:q.amber,onClick:()=>b.entityAction.mutate({type:"workstream",id:t.id,action:"pause"}),disabled:k}),e.jsx(Q,{label:"Block",color:q.red,variant:"destructive",onClick:()=>b.entityAction.mutate({type:"workstream",id:t.id,action:"block"}),disabled:k})]}),["paused","blocked"].includes(L)&&e.jsx(Q,{label:"Resume",color:q.lime,variant:"primary",onClick:()=>b.entityAction.mutate({type:"workstream",id:t.id,action:"resume"}),disabled:k}),w?e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:"Save",color:q.teal,variant:"primary",onClick:oe,disabled:k||!I.trim()}),e.jsx(Q,{label:"Cancel",variant:"ghost",onClick:()=>{i(!1),K(t.name),se(t.summary??""),X(t.status),N(null)},disabled:k})]}):e.jsx(Q,{label:"Edit",variant:"ghost",onClick:()=>{i(!0),N(null)},disabled:k}),e.jsx("div",{className:"flex-1"}),v?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"Delete workstream?"}),e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>b.deleteEntity.mutate({type:"workstream",id:t.id},{onSuccess:()=>l(),onError:C=>N(C instanceof Error?C.message:"Failed to delete workstream.")}),disabled:k}),e.jsx(Q,{label:"Keep",variant:"ghost",onClick:()=>d(!1),disabled:k})]}):e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>d(!0),disabled:k}),F?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:C=>{C.preventDefault(),A.trim()&&b.createEntity.mutate({type:"task",title:A.trim(),workstream_id:t.id,initiative_id:s.id,status:"todo"},{onSuccess:()=>{R(""),p(!1)},onError:U=>{N(U instanceof Error?U.message:"Failed to create task.")}})},children:[e.jsx("input",{type:"text",value:A,onChange:C=>R(C.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-body bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-primary placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(Q,{label:"Add",color:q.lime,type:"submit",size:"sm",disabled:!A.trim()||b.createEntity.isPending}),e.jsx(Q,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{p(!1),R("")}})]}):e.jsx(Q,{label:"+ Task",variant:"ghost",onClick:()=>p(!0),disabled:k})]})})]})}function Or({milestone:t,initiative:s}){const{openModal:o,closeModal:u,authToken:l,embedMode:c,mutations:a}=et(),[b,f]=n.useState(!1),[F,p]=n.useState(!1),[A,R]=n.useState(!1),[w,i]=n.useState(""),[v,d]=n.useState(null),[x,N]=n.useState(!1),[m,g]=n.useState(t.title),[I,K]=n.useState(t.description??""),[ee,se]=n.useState(gs(t.dueDate)),[ie,X]=n.useState(t.status),{details:V}=St({initiativeId:s.id,authToken:l,embedMode:c}),D=V.tasks.filter(L=>L.milestoneId===t.id),_=t.status.toLowerCase()==="done"||t.status.toLowerCase()==="completed",W=D.filter(L=>$e(L.status)).length,z=D.length>0?nt(W,D.length):_?100:0,O=a.entityAction.isPending||a.createEntity.isPending||a.updateEntity.isPending||a.deleteEntity.isPending,G=()=>{const L=m.trim();if(!L){d("Milestone title is required.");return}d(null),a.updateEntity.mutate({type:"milestone",id:t.id,title:L,description:I.trim()||null,due_date:ee||null,status:ie},{onSuccess:()=>{f(!1),d("Milestone updated.")},onError:k=>{d(k instanceof Error?k.message:"Failed to update milestone.")}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-caption",children:[e.jsx(Ue,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>o({type:"initiative",entity:s}),className:"break-words text-secondary transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Ue,{type:"milestone",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-primary",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Ue,{type:"milestone",size:16}),e.jsx("h2",{className:"text-title font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Ds(t.status)}`,children:ke(t.status)})]}),b?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Title"}),e.jsx("input",{type:"text",value:m,onChange:L=>g(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Description"}),e.jsx("textarea",{value:I,onChange:L=>K(L.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-2",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due date"}),e.jsx("input",{type:"date",value:ee,onChange:L=>se(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("select",{value:ie,onChange:L=>X(L.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:["planned","active","in_progress","at_risk","blocked","done"].map(L=>e.jsx("option",{value:L,children:ke(L)},L))})]})]})]}):t.description?e.jsx("p",{className:"text-body text-secondary leading-relaxed",children:t.description}):e.jsx("p",{className:"text-body text-muted",children:"No description yet."}),v&&e.jsx("div",{className:"text-caption text-secondary",children:v})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[t.dueDate&&e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due Date"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:new Date(t.dueDate).toLocaleDateString()})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Associated Tasks"}),e.jsx("div",{className:"text-heading font-medium text-primary mt-0.5",children:D.length})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Completion"}),e.jsxs("div",{className:"mt-1 flex items-center gap-2",children:[e.jsx("div",{className:"h-1.5 flex-1 rounded-full bg-white/[0.06] overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all",style:{width:`${z}%`,backgroundColor:q.teal}})}),e.jsxs("div",{className:"text-body text-primary",style:{fontVariantNumeric:"tabular-nums"},children:[z,"%"]})]}),e.jsxs("div",{className:"mt-1 text-micro text-muted",children:[W,"/",D.length," done"]})]})]}),D.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("span",{className:"text-caption uppercase tracking-[0.08em] text-muted",children:"Tasks"}),D.map(L=>e.jsx("button",{onClick:()=>o({type:"task",entity:L,initiative:s}),className:"w-full text-left rounded-xl border border-white/[0.08] bg-white/[0.03] p-3 transition-colors hover:bg-white/[0.06]",children:e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("span",{className:"text-body text-bright",children:L.title}),e.jsx("span",{className:`text-micro px-1.5 py-0.5 rounded-full border uppercase tracking-[0.08em] flex-shrink-0 ${Yt(L.status)}`,children:ke(L.status)})]})},L.id))]}),e.jsx(Mt,{entityType:"milestone",entityId:t.id,authToken:l,embedMode:c}),e.jsxs("div",{className:"mt-2 space-y-2 rounded-2xl border border-white/[0.08] bg-white/[0.02] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.14em] text-muted",children:"Notes"}),e.jsx("p",{className:"mt-1 text-caption text-muted",children:"Commentary thread for humans and agents on this milestone."})]}),e.jsx("button",{type:"button",onClick:()=>N(L=>!L),className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09]",children:x?"Hide":"Show"})]}),x?e.jsx("div",{className:"pt-3 border-t border-subtle",children:e.jsx(Ft,{entityType:"milestone",entityId:t.id,authToken:l,embedMode:c})}):null]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[!_&&t.status.toLowerCase()==="planned"&&e.jsx(Q,{label:"Start",color:q.lime,variant:"primary",onClick:()=>a.entityAction.mutate({type:"milestone",id:t.id,action:"start"}),disabled:O}),!_&&(t.status.toLowerCase()==="in_progress"||t.status.toLowerCase()==="at_risk")&&e.jsx(Q,{label:D.length>0&&!D.every(L=>$e(L.status))?"Complete (force)":"Complete",color:q.teal,variant:"primary",onClick:()=>{const L=D.length===0||D.every(k=>$e(k.status));a.entityAction.mutate({type:"milestone",id:t.id,action:"complete",force:!L})},disabled:O}),b?e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:"Save",color:q.teal,variant:"primary",onClick:G,disabled:O||!m.trim()}),e.jsx(Q,{label:"Cancel",variant:"ghost",onClick:()=>{f(!1),g(t.title),K(t.description??""),se(gs(t.dueDate)),X(t.status),d(null)},disabled:O})]}):e.jsx(Q,{label:"Edit",variant:"ghost",onClick:()=>{f(!0),d(null)},disabled:O}),e.jsx("div",{className:"flex-1"}),F?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption text-secondary",children:"Delete milestone?"}),e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>a.deleteEntity.mutate({type:"milestone",id:t.id},{onSuccess:()=>u(),onError:L=>d(L instanceof Error?L.message:"Failed to delete milestone.")}),disabled:O}),e.jsx(Q,{label:"Keep",variant:"ghost",onClick:()=>p(!1),disabled:O})]}):e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>p(!0),disabled:O}),A?e.jsxs("form",{className:"flex flex-wrap items-center gap-2",onSubmit:L=>{L.preventDefault(),w.trim()&&a.createEntity.mutate({type:"task",title:w.trim(),milestone_id:t.id,workstream_id:t.workstreamId??void 0,initiative_id:s.id,status:"todo"},{onSuccess:()=>{i(""),R(!1)},onError:k=>{d(k instanceof Error?k.message:"Failed to create task.")}})},children:[e.jsx("input",{type:"text",value:w,onChange:L=>i(L.target.value),placeholder:"Task title...",autoFocus:!0,className:"text-body bg-white/5 border border-white/10 rounded-lg px-2.5 py-1.5 text-primary placeholder-white/30 w-[160px] outline-none focus:border-white/25"}),e.jsx(Q,{label:"Add",color:q.lime,type:"submit",size:"sm",disabled:!w.trim()||a.createEntity.isPending}),e.jsx(Q,{label:"Cancel",variant:"ghost",size:"sm",onClick:()=>{R(!1),i("")}})]}):e.jsx(Q,{label:"+ Task",variant:"ghost",onClick:()=>R(!0),disabled:O})]})})]})}function gs(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function Ur({task:t,initiative:s}){const{agentEntityMap:o,openModal:u,mutations:l,closeModal:c,authToken:a,embedMode:b}=et(),f=o.get(t.id)??o.get(s.id)??[],[F,p]=n.useState(!1),[A,R]=n.useState(!1),[w,i]=n.useState(null),[v,d]=n.useState(!1),[x,N]=n.useState(t.title),[m,g]=n.useState(t.description??""),[I,K]=n.useState(t.priority??""),[ee,se]=n.useState(ys(t.dueDate)),[ie,X]=n.useState(t.status),V=t.status.toLowerCase(),D=l.entityAction.isPending||l.updateEntity.isPending||l.deleteEntity.isPending,_=O=>{i(null),l.entityAction.mutate({type:"task",id:t.id,action:O},{onError:G=>{i(G instanceof Error?G.message:"Task action failed.")}})},W=()=>{const O=x.trim();if(!O){i("Task title is required.");return}i(null),l.updateEntity.mutate({type:"task",id:t.id,title:O,description:m.trim()||null,priority:I.trim()||null,due_date:ee||null,status:ie},{onSuccess:()=>{R(!1),i("Task updated.")},onError:G=>{i(G instanceof Error?G.message:"Failed to update task.")}})},z=()=>{i(null),l.deleteEntity.mutate({type:"task",id:t.id},{onSuccess:()=>c(),onError:O=>{i(O instanceof Error?O.message:"Failed to delete task.")}})};return e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"min-h-0 flex-1 space-y-5 overflow-y-auto p-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-caption",children:[e.jsx(Ue,{type:"initiative",size:12,className:"flex-shrink-0 opacity-80"}),e.jsx("button",{onClick:()=>u({type:"initiative",entity:s}),className:"break-words text-secondary transition-colors hover:text-white",children:s.name}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx(Ue,{type:"task",size:12,className:"flex-shrink-0 opacity-95"}),e.jsx("span",{className:"break-words font-medium text-primary",children:t.title})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(Ue,{type:"task",size:16}),e.jsx("h2",{className:"break-words text-title font-semibold text-white",children:t.title}),e.jsx("span",{className:`text-micro px-2.5 py-0.5 rounded-full border uppercase tracking-[0.08em] ${Yt(t.status)}`,children:ke(t.status)})]}),A?e.jsxs("div",{className:"space-y-2 rounded-xl border border-white/[0.08] bg-white/[0.02] p-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Title"}),e.jsx("input",{type:"text",value:x,onChange:O=>N(O.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Description"}),e.jsx("textarea",{value:m,onChange:O=>g(O.target.value),rows:3,className:"mt-1 w-full resize-y rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Priority"}),e.jsx("input",{type:"text",value:I,onChange:O=>K(O.target.value),placeholder:"p1, high, p50",className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due date"}),e.jsx("input",{type:"date",value:ee,onChange:O=>se(O.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("select",{value:ie,onChange:O=>X(O.target.value),className:"mt-1 w-full rounded-lg border border-white/15 bg-white/[0.06] px-3 py-2 text-body text-bright outline-none focus:border-white/30",children:["not_started","planned","todo","in_progress","active","blocked","done"].map(O=>e.jsx("option",{value:O,children:ke(O)},O))})]})]})]}):t.description?e.jsx(Ys,{text:t.description,mode:"block",className:"text-body text-secondary leading-relaxed"}):e.jsx("p",{className:"text-body text-muted",children:"No description yet."}),f.length>0&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-muted uppercase tracking-wider",children:"Agents"}),e.jsx(Dt,{agents:f,max:4})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Status"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children: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-micro uppercase tracking-[0.08em] text-muted",children:"Priority"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:t.priority??"-"})]}),e.jsxs("div",{className:"rounded-xl border border-white/[0.08] bg-white/[0.03] px-3 py-2.5",children:[e.jsx("div",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Due Date"}),e.jsx("div",{className:"text-body text-primary mt-0.5",children:t.dueDate?new Date(t.dueDate).toLocaleDateString():"-"})]})]}),w&&e.jsx("div",{className:"text-caption px-1",style:{color:`${q.red}b3`},children:w}),e.jsxs("div",{className:"mt-2 space-y-2 rounded-2xl border border-white/[0.08] bg-white/[0.02] p-4",children:[e.jsx(Mt,{entityType:"task",entityId:t.id,authToken:a,embedMode:b}),e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-micro font-semibold uppercase tracking-[0.14em] text-muted",children:"Notes"}),e.jsx("p",{className:"mt-1 text-caption text-muted",children:"Commentary thread for humans and agents on this task."})]}),e.jsx("button",{type:"button",onClick:()=>d(O=>!O),className:"inline-flex items-center justify-center rounded-full border border-strong bg-white/[0.05] px-3 py-1.5 text-caption font-semibold tracking-wide text-primary transition-colors hover:bg-white/[0.09]",children:v?"Hide":"Show"})]}),v?e.jsx("div",{className:"pt-3 border-t border-subtle",children:e.jsx(Ft,{entityType:"task",entityId:t.id,authToken:a,embedMode:b})}):null]})]}),e.jsx("div",{className:"border-t border-subtle bg-[#070b12]/85 px-6 py-3 backdrop-blur",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[V==="todo"&&e.jsx(Q,{label:"Start",color:q.lime,variant:"primary",onClick:()=>_("start"),disabled:D}),(V==="in_progress"||V==="active")&&e.jsx(Q,{label:"Complete",color:q.teal,variant:"primary",onClick:()=>_("complete"),disabled:D}),(V==="todo"||V==="in_progress"||V==="active")&&e.jsx(Q,{label:"Block",color:q.red,variant:"destructive",onClick:()=>_("block"),disabled:D}),V==="blocked"&&e.jsx(Q,{label:"Unblock",color:q.amber,onClick:()=>_("unblock"),disabled:D}),A?e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:"Save",color:q.teal,variant:"primary",onClick:W,disabled:D||!x.trim()}),e.jsx(Q,{label:"Cancel",variant:"ghost",onClick:()=>{R(!1),i(null),N(t.title),g(t.description??""),K(t.priority??""),se(ys(t.dueDate)),X(t.status)},disabled:D})]}):e.jsx(Q,{label:"Edit",variant:"ghost",onClick:()=>{R(!0),i(null)},disabled:D}),e.jsx("div",{className:"flex-1"}),F?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-caption",style:{color:`${q.red}b3`},children:"Delete?"}),e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:z,disabled:D}),e.jsx(Q,{label:"Keep",variant:"ghost",onClick:()=>p(!1),disabled:D})]}):e.jsx(Q,{label:"Delete",color:q.red,variant:"destructive",onClick:()=>p(!0),disabled:D})]})})]})}function ys(t){if(!t)return"";const s=Date.parse(t);return Number.isFinite(s)?new Date(s).toISOString().slice(0,10):""}function qr(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 Wr({target:t,onClose:s}){return e.jsx(Xs,{open:t!==null,onClose:s,maxWidth:"max-w-5xl",children:t&&e.jsxs("div",{className:"flex h-full w-full min-h-0 flex-col",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 border-b border-subtle px-5 py-3 sm:px-6",children:[e.jsxs("div",{className:"flex items-center gap-1.5 min-w-0 text-body text-secondary",children:[qr(t).map((o,u,l)=>e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0",children:[u>0&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"flex-shrink-0 text-faint",children:e.jsx("path",{d:"m9 18 6-6-6-6"})}),e.jsx("span",{className:`truncate ${u===l.length-1?"text-primary font-medium":""}`,children:o})]},u)),e.jsxs("span",{className:"ml-1 inline-flex items-center gap-1 rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro uppercase tracking-[0.06em] text-secondary",children:[e.jsx(Ue,{type:t.type,size:11,className:"opacity-90"}),t.type]})]}),e.jsx("button",{type:"button",onClick:s,"aria-label":"Close detail",className:"inline-flex h-9 w-9 flex-shrink-0 items-center justify-center rounded-full border border-strong bg-white/[0.03] text-primary transition-colors hover:bg-white/[0.08] hover:text-white",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 6L6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]}),e.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto",children:[t.type==="initiative"&&e.jsx(Lr,{initiative:t.entity}),t.type==="workstream"&&e.jsx(zr,{workstream:t.entity,initiative:t.initiative}),t.type==="milestone"&&e.jsx(Or,{milestone:t.entity,initiative:t.initiative}),t.type==="task"&&e.jsx(Ur,{task:t.entity,initiative:t.initiative})]})]})})}function ws(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Hr(t){return t.split("_").map(s=>s.slice(0,1).toUpperCase()+s.slice(1)).join(" ")}const Kt=["active","in_progress","not_started","planned","blocked","at_risk","paused","completed","done","backlog","todo","pending","draft"],Vr=[{value:"target",label:"Target date"},{value:"created",label:"Created at"},{value:"updated",label:"Updated at"}],Kr=[{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"}],Gr=[{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 Qr({initiatives:t,visibleCount:s}){const{statusFilters:o,dateField:u,datePreset:l,dateStart:c,dateEnd:a,activeFilterCount:b,groupBy:f,setGroupBy:F,sortBy:p,setSortBy:A,setStatusFilters:R,toggleStatusFilter:w,setDateField:i,setDatePreset:v,setDateStart:d,setDateEnd:x,clearFilters:N}=et(),[m,g]=n.useState(!1),[I,K]=n.useState(!1),ee=n.useRef(null);n.useEffect(()=>{if(!m)return;const k=C=>{var H;const U=C.target;U&&((H=ee.current)!=null&&H.contains(U)||g(!1))},oe=C=>{C.key==="Escape"&&g(!1)};return document.addEventListener("mousedown",k),document.addEventListener("keydown",oe),()=>{document.removeEventListener("mousedown",k),document.removeEventListener("keydown",oe)}},[m]);const se=n.useMemo(()=>{const k=new Map;for(const C of t){const U=new Set([ws(C.status),ws(C.rawStatus)]);for(const H of U)H&&k.set(H,(k.get(H)??0)+1)}for(const C of Kt)k.has(C)||k.set(C,0);return Array.from(k.entries()).sort((C,U)=>{const H=Kt.indexOf(C[0]),re=Kt.indexOf(U[0]);return H>=0&&re>=0?H-re:H>=0?-1:re>=0?1:C[0].localeCompare(U[0])}).map(([C,U])=>({key:C,count:U}))},[t]),ie=o.length,X=n.useMemo(()=>se.filter(k=>I||k.count>0||o.includes(k.key)),[I,o,se]),V=se.length-X.length,D=n.useMemo(()=>u==="target"?Kr:Gr,[u]);n.useEffect(()=>{D.some(k=>k.value===l)||v("any")},[l,D,v]);const _=[{value:"none",label:"None"},{value:"status",label:"Status"},{value:"date",label:"Date"},{value:"category",label:"Category"}],W=[{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)"}],z=f!=="status"||p!=="default",O=b>0,G=b,L=O||z;return e.jsxs("div",{ref:ee,className:"relative flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>{g(k=>{const oe=!k;return oe||K(!1),oe})},"data-state":m||G>0?"active":"idle",className:"control-pill flex items-center gap-1.5 px-3 text-caption font-semibold",children:[e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("path",{d:"M22 3H2l8 9.46V19l4 2v-8.54L22 3z"})}),e.jsx("span",{children:"Filters"}),G>0&&e.jsx("span",{className:"inline-flex min-w-[16px] items-center justify-center rounded-full border border-current/30 bg-black/25 px-1 text-micro leading-4",children:G})]}),s<t.length&&e.jsxs("span",{className:"text-micro text-muted whitespace-nowrap",children:[s,"/",t.length]}),e.jsx(Oe,{initial:!1,children:O&&e.jsx(le.button,{type:"button",onClick:N,initial:{opacity:0,x:-4},animate:{opacity:1,x:0},exit:{opacity:0,x:-4},transition:{duration:.15,ease:[.22,1,.36,1]},className:"text-micro text-muted transition-colors whitespace-nowrap hover:text-primary",children:"Clear"})}),e.jsx(Oe,{children:m&&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-caption font-semibold tracking-[0.01em] text-bright",children:"Filters"}),e.jsx("div",{className:"text-micro text-secondary",children:"Scope the Mission Control list view"})]}),O?e.jsxs("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro text-primary",children:[G," active"]}):z?e.jsx("span",{className:"rounded-full border border-strong bg-white/[0.04] px-2 py-0.5 text-micro text-secondary",children:"view modified"}):null]}),e.jsxs("div",{className:"subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Layout"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Group"}),e.jsx("select",{value:f,onChange:k=>F(k.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-caption text-primary focus:border-[#BFFF00]/40 focus:outline-none",children:_.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-muted",children:"Sort"}),e.jsx("select",{value:p,onChange:k=>A(k.target.value),className:"h-9 rounded-lg border border-white/[0.08] bg-black/30 px-2 text-caption text-primary focus:border-[#BFFF00]/40 focus:outline-none",children:W.map(k=>e.jsx("option",{value:k.value,children:k.label},k.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"}),V>0&&e.jsx("button",{type:"button",onClick:()=>K(k=>!k),className:"text-micro text-muted transition-colors hover:text-white/72",children:I?"Hide empty":`Show empty (${V})`})]}),e.jsx("div",{className:"max-h-40 space-y-1 overflow-auto pr-1",children:X.map(k=>{const oe=o.includes(k.key);return e.jsxs("label",{className:`flex cursor-pointer items-center justify-between rounded-md border px-2.5 py-1.5 text-caption transition-colors ${oe?"border-[#BFFF00]/30 bg-[#BFFF00]/10 text-bright":"border-white/[0.08] bg-white/[0.02] text-primary hover:border-white/[0.15]"}`,children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:oe,onChange:()=>w(k.key),className:"h-3.5 w-3.5 accent-[#BFFF00]"}),e.jsx("span",{children:Hr(k.key)})]}),e.jsx("span",{className:"text-micro text-secondary",children:k.count})]},k.key)})}),e.jsxs("div",{className:"mt-2 flex items-center justify-between",children:[e.jsx("button",{type:"button",onClick:()=>R([]),className:`text-micro uppercase tracking-[0.08em] ${ie>0?"text-primary hover:text-white":"text-muted"}`,disabled:ie===0,children:"Clear status"}),e.jsxs("div",{className:"text-micro text-secondary",children:[ie," selected"]})]})]}),e.jsxs("div",{className:"mt-2.5 subsection-shell p-2.5",children:[e.jsx("div",{className:"section-kicker mb-2",children:"Date"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Field"}),e.jsx("select",{value:u,onChange:k=>i(k.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none",children:Vr.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Condition"}),e.jsx("select",{value:l,onChange:k=>v(k.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none",children:D.map(k=>e.jsx("option",{value:k.value,children:k.label},k.value))})]})]}),l==="custom_range"&&e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"Start"}),e.jsx("input",{type:"date",value:c,onChange:k=>d(k.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none"})]}),e.jsxs("label",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-micro uppercase tracking-[0.08em] text-secondary",children:"End"}),e.jsx("input",{type:"date",value:a,onChange:k=>x(k.target.value),className:"h-9 rounded-lg border border-strong bg-black/30 px-2 text-caption text-white focus:border-[#BFFF00]/40 focus:outline-none"})]})]})]}),L&&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:[z&&e.jsx("button",{type:"button",onClick:()=>{F("status"),A("default")},className:"text-micro uppercase tracking-[0.09em] text-secondary transition-colors hover:text-bright",children:"Reset layout"}),O&&e.jsx("button",{type:"button",onClick:N,className:"text-micro uppercase tracking-[0.09em] text-secondary transition-colors hover:text-bright",children:"Clear filters"})]})]})]})})]})}function Gt(t){return(t??"").trim().toLowerCase().replace(/[\s-]+/g,"_")}function Qt(t){return new Date(t.getFullYear(),t.getMonth(),t.getDate()).getTime()}function js(t){if(!t)return null;const s=Date.parse(`${t}T00:00:00`);return Number.isFinite(s)?s:null}function Jr(t,s){return s==="target"?t.targetDate??null:s==="created"?t.createdAt??null:t.updatedAt??t.createdAt??null}function vs(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 Ns(t){return t==="active"?0:t==="blocked"?1:t==="paused"?2:3}function ks(t,s){if(s==="status"){const o=new Map,u=["active","blocked","paused","completed"];for(const l of t){const c=l.status??"active",a=o.get(c)??[];a.push(l),o.set(c,a)}return u.filter(l=>o.has(l)).concat(Array.from(o.keys()).filter(l=>!u.includes(l))).map(l=>{var c;return{key:l,label:l.charAt(0).toUpperCase()+l.slice(1),count:((c=o.get(l))==null?void 0:c.length)??0,initiatives:o.get(l)??[]}})}if(s==="category"){const o=new Map;for(const u of t){const l=u.category??"Uncategorized",c=o.get(l)??[];c.push(u),o.set(l,c)}return Array.from(o.entries()).sort((u,l)=>u[0].localeCompare(l[0])).map(([u,l])=>({key:u,label:u,count:l.length,initiatives:l}))}if(s==="date"){const u=Qt(new Date),l=u+7*864e5,c=u+30*864e5,a={overdue:[],this_week:[],this_month:[],later:[],no_date:[]};for(const f of t){const F=f.targetDate?Date.parse(f.targetDate):null;F===null||!Number.isFinite(F)?a.no_date.push(f):F<u?a.overdue.push(f):F<l?a.this_week.push(f):F<c?a.this_month.push(f):a.later.push(f)}const b={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(f=>a[f].length>0).map(f=>({key:f,label:b[f],count:a[f].length,initiatives:a[f]}))}return[]}function st(t,s){return`${t}:${s}`}function Yr(t){return`mc-group-${t}`.toLowerCase().replace(/[^a-z0-9_-]+/g,"-")}function Cs(t,s){if(t.size!==s.size)return!1;for(const o of t)if(!s.has(o))return!1;return!0}function Xr(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 Zr(t){return t==="running"?"border-teal-300/24 bg-teal-400/[0.08] text-teal-100/90":t==="blocked"?"border-red-400/24 bg-red-500/[0.08] text-red-100/90":t==="queued"||t==="startable"?"border-[#BFFF00]/18 bg-[#BFFF00]/[0.06] text-[#E8FFD0]/95":t==="completed"?"border-strong bg-white/[0.05] text-secondary":"border-strong bg-white/[0.04] text-white/68"}function ln({initiatives:t,activities:s,agents:o,runtimeInstances:u=[],isLoading:l,authToken:c,embedMode:a,initialInitiativeId:b,connection:f,lastSnapshotAt:F,error:p,hasApiKey:A,onOpenSettings:R,onRefresh:w,onCreateInitiative:i,onPlayNextUp:v,onStartAutopilot:d,onFollowWorkstream:x}){const N=nr({activities:s,agents:o,initiatives:t});return e.jsx(cr,{agentEntityMap:N,authToken:c,embedMode:a,children:e.jsx(tn,{initiatives:t,runtimeInstances:u,isLoading:l,initialInitiativeId:b,connection:f,lastSnapshotAt:F,error:p,hasApiKey:A,onOpenSettings:R,onRefresh:w,onCreateInitiative:i,onPlayNextUp:v,onStartAutopilot:d,onFollowWorkstream:x})})}function en(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 tn({initiatives:t,runtimeInstances:s,isLoading:o,initialInitiativeId:u,connection:l,lastSnapshotAt:c,error:a,hasApiKey:b,onOpenSettings:f,onRefresh:F,onCreateInitiative:p,onPlayNextUp:A,onStartAutopilot:R,onFollowWorkstream:w}){var is;const{searchQuery:i,setSearchQuery:v,statusFilters:d,setStatusFilters:x,dateField:N,setDateField:m,datePreset:g,setDatePreset:I,dateStart:K,setDateStart:ee,dateEnd:se,setDateEnd:ie,clearFilters:X,hasActiveFilters:V,groupBy:D,sortBy:_,expandedInitiatives:W,expandAll:z,collapseAll:O,modalTarget:G,closeModal:L,expandInitiative:k,authToken:oe,embedMode:C,mutations:U}=et(),H=n.useRef(!1),re=n.useRef(null),ne=n.useRef(0),[T,fe]=n.useState(0),[ge,me]=n.useState(new Set),[Ae,Fe]=n.useState(!1),[Qe,at]=n.useState(!1),[qe,ye]=n.useState(!1),[Ve,_e]=n.useState(!1),[De,xe]=n.useState(null),[Ee,We]=n.useState(new Set),[Te,Le]=n.useState(!1),[we,Ce]=n.useState(null);n.useEffect(()=>{if(!we)return;const h=we.tone==="success"?6500:9e3,E=window.setTimeout(()=>Ce(null),h);return()=>window.clearTimeout(E)},[we==null?void 0:we.message,we==null?void 0:we.tone]);const Je=n.useMemo(()=>{const E=Qt(new Date),P=i.toLowerCase().trim().split(/\s+/).filter(Boolean);return t.filter(J=>{if(d.length>0&&![Gt(J.status),Gt(J.rawStatus)].filter(Boolean).some(ze=>d.includes(ze)))return!1;const de=Jr(J,N),be=de?Date.parse(de):Number.NaN,Ne=Number.isFinite(be)?Qt(new Date(be)):null,te=Ne===null?null:Math.round((Ne-E)/864e5);if(g==="missing"&&Ne!==null||g==="overdue"&&!(te!==null&&te<0)||g==="today"&&te!==0||g==="next_7_days"&&!(te!==null&&te>=0&&te<=7)||g==="next_30_days"&&!(te!==null&&te>=0&&te<=30)||g==="past_7_days"&&!(te!==null&&te<=0&&te>=-7)||g==="past_30_days"&&!(te!==null&&te<=0&&te>=-30))return!1;if(g==="custom_range"){const Ge=js(K),ze=js(se);if(Ne===null||Ge!==null&&Ne<Ge||ze!==null&&Ne>ze)return!1}if(P.length===0)return!0;const dt=[J.name,J.description??"",J.status,J.rawStatus??"",J.category??""].join(" ").toLowerCase();return P.every(Ge=>dt.includes(Ge))})},[t,i,d,N,g,K,se]),ae=n.useMemo(()=>{const h=(E,P,J)=>{const de=E.targetDate?Date.parse(E.targetDate):Number.NaN,be=P.targetDate?Date.parse(P.targetDate):Number.NaN,Ne=Number.isFinite(de),te=Number.isFinite(be);return!Ne&&!te?0:Ne?te?J==="asc"?de-be:be-de:-1:1};return[...Je].sort((E,P)=>{if(_==="date_asc")return h(E,P,"asc");if(_==="date_desc")return h(E,P,"desc");const J=vs(E.priority),de=vs(P.priority);if(_==="priority_high"&&J!==de)return J-de;if(_==="priority_low"&&J!==de)return de-J;if(_==="default"){const te=Ns(E.status)-Ns(P.status);if(te!==0)return te;if(J!==de)return J-de}const be=E.updatedAt?Date.parse(E.updatedAt):0,Ne=P.updatedAt?Date.parse(P.updatedAt):0;return be!==Ne?Ne-be:E.name.localeCompare(P.name)})},[Je,_]),He=n.useMemo(()=>new Set(ae.map(h=>h.id)),[ae]),Be=n.useMemo(()=>ae.filter(h=>Ee.has(h.id)),[Ee,ae]),Ie=Be.length,Ye=ae.length>0&&Ie===ae.length,je=U.bulkEntityMutation.isPending,Me=n.useMemo(()=>{var P;const h=new Map;for(const J of s){const de=(P=J.initiativeId)==null?void 0:P.trim();if(!de)continue;const be=h.get(de)??{activeCount:0,totalCount:0,lastHeartbeatAt:null,lastHeartbeatMs:0};be.totalCount+=1,J.state==="active"&&(be.activeCount+=1);const Ne=J.lastHeartbeatAt??J.lastEventAt??null,te=Ne?Date.parse(Ne):Number.NaN;Number.isFinite(te)&&te>be.lastHeartbeatMs&&(be.lastHeartbeatMs=te,be.lastHeartbeatAt=new Date(te).toISOString()),h.set(de,be)}const E=new Map;for(const[J,de]of h.entries())E.set(J,{activeCount:de.activeCount,totalCount:de.totalCount,lastHeartbeatAt:de.lastHeartbeatAt});return E},[s]),r=n.useMemo(()=>D!=="none"?ks(ae,D):null,[ae,D]),S=n.useMemo(()=>(r==null?void 0:r.map(h=>st(D,h.key)))??[],[D,r]),M=n.useMemo(()=>{if(!r)return ae.map(E=>E.id);const h=[];for(const E of r){const P=st(D,E.key);if(ge.has(P))for(const J of E.initiatives)h.push(J.id)}return h},[r,ae,D,ge]),{handleSelect:Y}=Es(M),Z=n.useCallback(h=>{me(E=>{const P=new Set(E);return P.has(h)?P.delete(h):P.add(h),P})},[]);n.useEffect(()=>{if(!r||r.length===0){me(E=>E.size===0?E:new Set);return}const h=new Set(r.map(E=>st(D,E.key)));me(E=>{const P=new Set(Array.from(E).filter(J=>h.has(J)));return P.size===0&&P.add(st(D,r[0].key)),Cs(P,E)?E:P})},[D,r]),n.useEffect(()=>{We(h=>{if(h.size===0)return h;const E=new Set(Array.from(h).filter(P=>He.has(P)));return Cs(E,h)?h:E})},[He]),n.useEffect(()=>{if(u&&!H.current&&!o&&t.length>0){if(k(u),r){const h=r.find(E=>E.initiatives.some(P=>P.id===u));if(h){const E=st(D,h.key);me(P=>{if(P.has(E))return P;const J=new Set(P);return J.add(E),J})}}H.current=!0,requestAnimationFrame(()=>{const h=document.getElementById(`initiative-${u}`);h==null||h.scrollIntoView({behavior:"smooth",block:"start"})})}},[u,o,t.length,k,D,r]),n.useEffect(()=>{Ie===0&&Te&&Le(!1)},[Te,Ie]);const ue=ae.length>0&&W.size>=ae.length,he=n.useMemo(()=>ae.find(h=>h.status!=="completed")??ae[0]??null,[ae]),y=Zs({initiativeId:null,authToken:oe,embedMode:C,enabled:t.length>0}),j=y.items[0]??null,B=n.useMemo(()=>j?t.find(h=>h.id===j.initiativeId)??he:he,[he,t,j]),pe=(B==null?void 0:B.id)??null,$=n.useCallback((h,E,P)=>{Ce(null),Le(!1),Y(h,E,P,We)},[Y]),ce=n.useCallback(()=>{Ce(null),Le(!1),We(h=>ae.length===0?h:Ye?new Set:new Set(ae.map(E=>E.id)))},[Ye,ae]),Pe=n.useCallback(()=>{Le(!1),We(new Set)},[]),it=n.useCallback(async h=>{if(Be.length!==0){Le(!1),Ce(null);try{const E=await U.bulkEntityMutation.mutateAsync({items:Be.map(P=>({type:"initiative",id:P.id})),mode:"update",updates:{status:h}});E.failed>0?Ce({tone:"error",message:`Updated ${E.updated}, failed ${E.failed}.`}):Ce({tone:"success",message:`Updated ${E.updated} initiative${E.updated===1?"":"s"} to ${h}.`})}catch(E){Ce({tone:"error",message:E instanceof Error?E.message:"Bulk initiative update failed."})}}},[U.bulkEntityMutation,Be]),At=n.useCallback(async()=>{if(Be.length!==0){Ce(null);try{const h=await U.bulkEntityMutation.mutateAsync({items:Be.map(E=>({type:"initiative",id:E.id})),mode:"delete"});h.failed>0?Ce({tone:"error",message:`Deleted ${h.updated}, failed ${h.failed}.`}):(Ce({tone:"success",message:`Deleted ${h.updated} initiative${h.updated===1?"":"s"}.`}),We(new Set),Le(!1))}catch(h){Ce({tone:"error",message:h instanceof Error?h.message:"Bulk initiative delete failed."})}}},[U.bulkEntityMutation,Be]),ft=n.useCallback(()=>{ne.current+=1,Fe(!1)},[]),It=n.useCallback(h=>{if(h.length===0){ft();return}const E=1,P=ne.current+1;ne.current=P,Fe(!0);const J=de=>{if(ne.current===P){if(z(h.slice(0,de)),de>=h.length){Fe(!1);return}requestAnimationFrame(()=>J(Math.min(h.length,de+E)))}};J(Math.min(E,h.length))},[ft,z]),Se=ar({initiativeId:pe,authToken:oe,embedMode:C,enabled:!!pe}),[Ke,ot]=n.useState(null),bt=Se.run,Bt=((is=Se.error)==null?void 0:is.toLowerCase())??"",$t=!pe||Bt.includes("404")||Bt.includes("400")||Bt.includes("not found"),Re=pe?Me.get(pe)??null:null,_t=((Re==null?void 0:Re.activeCount)??0)>0,Is=((Re==null?void 0:Re.totalCount)??0)>0,Xt=Ke?`Upgrade required · ${cs(Ke.currentPlan)} → ${cs(Ke.requiredPlan)}`:pe?Se.isRunning?_t?`Running · ${(Re==null?void 0:Re.activeCount)??0} live`:Is?`Enabled · ${(Re==null?void 0:Re.totalCount)??0} idle`:"Enabled · waiting":bt!=null&&bt.stopReason?`Idle · ${bt.stopReason.replace(/_/g," ")}`:"Idle":"No target",lt=!!Ke&&!Se.isRunning,Bs=lt?"amber":"teal",$s=n.useMemo(()=>{const h=new URL("https://www.useorgx.com/integrations/openclaw");return h.searchParams.set("utm_source",C?"live_share":"orgx_openclaw_plugin"),h.searchParams.set("utm_medium","mission_control"),h.searchParams.set("utm_campaign","live_link_dashboard"),h.searchParams.set("utm_content","install_cta"),h.toString()},[C]);n.useEffect(()=>{ot(null)},[pe]),n.useEffect(()=>{const h=re.current;if(!h)return;const E=()=>{fe(Math.max(64,h.offsetHeight))};if(E(),typeof ResizeObserver>"u")return;const P=new ResizeObserver(()=>E());return P.observe(h),()=>P.disconnect()},[Xt,l,a,o,ae.length]);const Tt=!!(!o&&b&&(l==="disconnected"||a)),Zt=!!(l==="disconnected"||a);n.useEffect(()=>{if(!Tt){at(!1);return}Zt&&at(!0)},[Tt,Zt]);const es=l==="disconnected"||a?"critical":"info",_s=es==="critical"?"border-red-400/30 bg-red-500/14 text-red-100":"border-strong bg-white/[0.08] text-primary",Ts=l==="disconnected"?"Offline":a?"Live degraded":"Connected",ts=a||(l==="disconnected"?"Data may be stale":`Last snapshot ${en(c)}`),Xe=n.useCallback((h,E)=>{if(!t.find(te=>te.id===h))return xe({tone:"error",message:E?`${E} is unavailable in the current initiative list.`:"Initiative is unavailable in the current initiative list."}),!1;xe(null);const J=He.has(h),de=!J;if(de&&(v(""),x([]),m("target"),I("any"),ee(""),ie("")),k(h),D!=="none"){const Ge=ks(J?ae:t,D).find(ze=>ze.initiatives.some(ut=>ut.id===h));if(Ge){const ze=st(D,Ge.key);me(ut=>{if(ut.has(ze))return ut;const os=new Set(ut);return os.add(ze),os})}}const be=(te=0)=>{const dt=document.getElementById(`initiative-${h}`);if(dt){dt.scrollIntoView({behavior:te===0?"smooth":"auto",block:"start"});const Ge=Math.max(72,T)+8,ze=dt.getBoundingClientRect();!(ze.top>=Ge&&ze.top<=window.innerHeight-72)&&te<18&&window.setTimeout(()=>be(te+1),90);return}te>=60||requestAnimationFrame(()=>be(te+1))},Ne=()=>requestAnimationFrame(()=>be());return de?window.setTimeout(Ne,90):Ne(),!0},[t,He,xe,v,x,m,I,ee,ie,k,D,ae,T]),Lt=n.useCallback(h=>{w==null||w(h),_e(!1)},[w]),Ls=n.useCallback(()=>{B&&(xe(null),U.updateEntity.mutateAsync({type:"initiative",id:B.id,status:"active"}).then(()=>{xe({tone:"success",message:`Started ${B.name}.`}),Xe(B.id,B.name)}).catch(h=>{xe({tone:"error",message:h instanceof Error?h.message:"Failed to start initiative."})}))},[U.updateEntity,B,Xe]),ss=n.useCallback(()=>{if(!j){B&&Xe(B.id,B.name);return}xe(null),y.playWorkstream({initiativeId:j.initiativeId,workstreamId:j.workstreamId,agentId:j.runnerAgentId}).then(()=>{xe({tone:"success",message:`Dispatched ${j.workstreamTitle}.`})}).catch(h=>{xe({tone:"error",message:h instanceof Error?h.message:"Failed to dispatch next workstream."})})},[y,j,B,Xe]),Ps=n.useCallback(()=>{B&&(Xe(B.id,B.name),typeof window<"u"&&window.innerWidth>=1280&&ye(!0))},[B,Xe]),Pt=n.useCallback(()=>{if(typeof window<"u"&&window.innerWidth>=1280){_e(!1),ye(h=>!h);return}_e(!0)},[]),ct=Gt((B==null?void 0:B.rawStatus)??(B==null?void 0:B.status)??null),rs=n.useMemo(()=>new Set(["paused","draft","planned","todo","backlog","queued"]),[]),ve=n.useMemo(()=>{var h;return B?(j==null?void 0:j.queueState)==="running"||((h=j==null?void 0:j.autoContinue)==null?void 0:h.status)==="running"?"running":(j==null?void 0:j.queueState)==="blocked"||B.status==="blocked"?"blocked":j?"queued":rs.has(ct)?"startable":ct==="completed"||ct==="done"?"completed":"active_no_queue":"none"},[B,j,rs,ct]),Rt=n.useMemo(()=>B?ve==="running"&&j?{headline:`${j.workstreamTitle} is running`,detail:`Runner: ${j.runnerAgentName}. Follow live updates in Activity.`}:ve==="queued"&&j?{headline:j.workstreamTitle,detail:`Ready to dispatch${j.nextTaskTitle?` · ${j.nextTaskTitle}`:""}.`}:ve==="startable"?{headline:ct==="paused"?`${B.name} is paused`:`${B.name} is ready to start`,detail:"Start initiative to queue and dispatch the next workstream."}:ve==="blocked"?{headline:(j==null?void 0:j.queueState)==="blocked"?`${j.workstreamTitle} is blocked`:`${B.name} is blocked`,detail:(j==null?void 0:j.blockReason)??"Resolve blockers or approvals before dispatching more work."}:ve==="completed"?{headline:`${B.name} is complete`,detail:"Choose another active initiative or queue new workstreams."}:{headline:B.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."},[B,ve,j,ct]),zt=y.isPlaying||y.isStartingAutoContinue||y.isStoppingAutoContinue||U.updateEntity.isPending,Rs=n.useMemo(()=>ve==="blocked"?"Review blockers":ve==="active_no_queue"?"Open and queue work":ve==="completed"?"Review initiative":"Open initiative",[ve]),ns=j?j.workstreamTitle:"No queued workstream",zs=(j==null?void 0:j.initiativeTitle)??(B==null?void 0:B.name)??"No initiative selected",Ot=(j==null?void 0:j.nextTaskTitle)??Rt.detail,Os=Xr(ve),Us=Zr(ve),Ut="next-up-surface",qt=n.useMemo(()=>({type:"spring",stiffness:340,damping:38,mass:.72}),[]),qs=n.useMemo(()=>({backgroundColor:"rgba(10, 14, 21, 0.66)",borderColor:"rgba(255, 255, 255, 0.10)"}),[]),as=n.useMemo(()=>({backgroundColor:"rgba(10, 14, 21, 0.95)",borderColor:"rgba(255, 255, 255, 0.11)"}),[]),Ws=n.useMemo(()=>{if(!G)return null;const h=P=>t.find(J=>J.id===P)??null;if(G.type==="initiative"){const P=h(G.entity.id);return P?{...G,entity:P}:G}const E=h(G.initiative.id);return E?{...G,initiative:E}:G},[t,G]);return n.useEffect(()=>{xe(null)},[B==null?void 0:B.id,j==null?void 0:j.initiativeId,j==null?void 0:j.workstreamId]),n.useEffect(()=>{if(!G)return;const h=G.type==="initiative"?G.entity.id:G.initiative.id;t.some(P=>P.id===h)||L()},[L,t,G]),n.useEffect(()=>{if(typeof window>"u")return;const h=()=>{window.innerWidth>=1280?_e(!1):ye(!1)};return h(),window.addEventListener("resize",h),()=>window.removeEventListener("resize",h)},[]),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":`${T}px`},children:[e.jsxs(rr,{id:"next-up-morph",children:[e.jsxs("div",{ref:re,className:"sticky top-0 z-40 relative -mx-4 border-b border-subtle bg-[#02040A]/78 px-4 pb-2.5 pt-3.5 backdrop-blur-xl sm:-mx-6 sm:px-6",children:[e.jsx(Oe,{initial:!1,children:Qe&&Tt&&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)] ${_s}`,children:[e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${es==="critical"?"bg-red-300":"bg-white/70"}`}),e.jsx("span",{className:"text-micro font-semibold uppercase tracking-[0.08em]",children:Ts}),e.jsx("span",{className:"max-w-[280px] truncate text-caption opacity-85",title:ts,children:ts}),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-strong bg-white/[0.08] px-2 text-micro font-semibold text-current transition-colors hover:bg-white/[0.15]",children:"Refresh"}),f&&e.jsx("button",{type:"button",onClick:f,className:"h-6 rounded-full border border-strong bg-white/[0.08] px-2 text-micro 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(Ms,{value:i,onChange:v,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(Qr,{initiatives:t,visibleCount:Je.length}),e.jsxs("div",{className:"hidden min-w-[220px] max-w-[320px] items-center gap-2 rounded-lg border border-strong bg-white/[0.03] px-2.5 py-1.5 xl:flex",title:(B==null?void 0:B.name)??void 0,children:[e.jsx("span",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-white/44",children:"Autopilot"}),e.jsxs("div",{className:"min-w-0 flex-1 text-right",children:[e.jsx("div",{className:"truncate text-micro text-white/72",children:Xt}),B&&e.jsx("div",{className:"truncate text-micro text-white/44",children:B.name})]})]}),e.jsxs("button",{type:"button",onClick:()=>{if($t||!pe)return;if(lt&&Ke){er({actions:Ke.actions,requiredPlan:Ke.requiredPlan}).catch(E=>{});return}(Se.isRunning?Se.stop:Se.start)().then(()=>ot(null)).catch(E=>{E instanceof tr?ot(E):ot(null)})},disabled:$t||Se.isStarting||Se.isStopping,title:$t?"Select an initiative to run Autopilot":lt?"Upgrade to enable auto-continue for BYOK agents":Se.isRunning?"Stop Autopilot":`Start Autopilot${B?` for ${B.name}`:""}`,"data-state":Se.isRunning||lt?"active":"idle","data-tone":Bs,className:"control-pill flex items-center gap-1.5 px-3 text-caption font-semibold disabled:opacity-40",children:[lt?e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M18 11l-6-6-6 6"})]}):Se.isRunning?_t?e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",className:"status-breathe",children:e.jsx("rect",{x:"7",y:"7",width:"10",height:"10",rx:"2"})}):e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("circle",{cx:"12",cy:"12",r:"8"}),e.jsx("path",{d:"M12 8v4l3 2"})]}):e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("path",{d:"M8 5v14l11-7z"})}),e.jsx("span",{children:lt?"Upgrade Autopilot":`${Se.isRunning?"Stop":"Start"} Autopilot`}),Se.isRunning&&_t&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#0AD4C4] status-breathe"})]}),C&&e.jsxs("a",{href:$s,target:"_blank",rel:"noreferrer noopener",onClick:()=>{try{sr.capture("live_install_cta_click",{surface:"mission_control",embedMode:!0,initiativeId:(B==null?void 0:B.id)??null})}catch{}},className:"control-pill flex items-center gap-1.5 px-3 text-caption font-semibold","data-tone":"amber",title:"Install OrgX for OpenClaw",children:[e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M12 3v12"}),e.jsx("path",{d:"M8 11l4 4 4-4"}),e.jsx("path",{d:"M5 21h14"})]}),e.jsx("span",{children:"Install OrgX"})]}),ae.length>0&&e.jsx("button",{type:"button",onClick:()=>{ue?(ft(),O(),r&&S.length>0&&me(new Set)):(It(ae.map(h=>h.id)),r&&S.length>0&&me(new Set(S)))},title:ue?"Collapse all":"Expand all","aria-busy":Ae&&!ue,className:"control-pill flex h-8 w-8 flex-shrink-0 items-center justify-center text-secondary",children:e.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:ue?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"})]})})})]})]})]}),ae.length>0&&e.jsxs("div",{"data-mc-selection-bar":"true",className:`mt-3 relative grid overflow-hidden rounded-xl border xl:grid-cols-[minmax(0,1fr)_560px] xl:gap-0 xl:items-stretch ${Ie>0?"border-[#BFFF00]/14 bg-[#0A0E15]/72":"border-white/[0.10] bg-[#0A0E15]/66"}`,children:[Ie>0&&e.jsx("div",{"aria-hidden":!0,className:"pointer-events-none absolute inset-x-0 top-0 h-px",style:{background:"linear-gradient(90deg, rgba(191,255,0,0.22), rgba(10,212,196,0.16), transparent 72%)"}}),e.jsx("div",{className:"min-w-0 px-3 py-2",children:e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("label",{className:"inline-flex flex-shrink-0 items-center gap-2 text-caption text-primary",children:[e.jsx("input",{type:"checkbox",checked:Ye,onChange:ce,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-caption text-white/58",children:Ie>0?`${Ie} selected`:`${ae.length} visible`}),Ie>0&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("button",{type:"button",onClick:()=>{it("active")},disabled:je,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45","data-state":"active",children:"Mark active"}),e.jsx("button",{type:"button",onClick:()=>{it("paused")},disabled:je,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Pause"}),e.jsx("button",{type:"button",onClick:()=>{it("blocked")},disabled:je,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Block"}),e.jsx("button",{type:"button",onClick:()=>{it("completed")},disabled:je,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",children:"Complete"}),Te?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-micro text-white/58",children:"Delete selected?"}),e.jsx("button",{type:"button",onClick:()=>{At()},disabled:je,className:"control-pill h-8 flex-shrink-0 border-red-400/35 bg-red-500/14 px-3 text-caption font-semibold text-red-100 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:()=>Le(!1),disabled:je,className:"control-pill h-8 flex-shrink-0 px-2.5 text-caption disabled:opacity-45",children:"Keep"})]}):e.jsx("button",{type:"button",onClick:()=>Le(!0),disabled:je,className:"control-pill h-8 flex-shrink-0 border-red-400/24 bg-red-500/[0.08] px-3 text-caption font-semibold text-red-100/85 disabled:opacity-45",children:"Delete"}),e.jsx("button",{type:"button",onClick:Pe,disabled:je,className:"text-caption text-secondary transition-colors hover:text-primary disabled:opacity-45",children:"Clear"})]})]})}),e.jsx(Oe,{initial:!1,mode:"popLayout",children:!qe&&!Ve&&e.jsxs(le.div,{layout:"position",layoutId:Ut,initial:{opacity:0,y:4},animate:{opacity:1,y:0,...qs},exit:{opacity:0,y:-4},transition:{layout:qt,duration:.2,ease:[.22,1,.36,1]},className:"flex w-full min-w-0 items-center gap-3 overflow-hidden rounded-xl border border-strong px-2.5 py-2 shadow-[0_10px_24px_rgba(0,0,0,0.22)] backdrop-blur-[10px] xl:h-full xl:rounded-none xl:border-b-0 xl:border-l xl:border-r-0 xl:border-t-0 xl:border-white/[0.10] xl:bg-transparent xl:px-3 xl:py-2 xl:shadow-none xl:backdrop-blur-none",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-center gap-2.5",children:[y.isLoading?e.jsx(Ze,{className:"h-6 w-6 rounded-full"}):j?e.jsx(Jt,{name:j.runnerAgentName,hint:`${j.runnerAgentId} ${j.runnerSource}`,size:"xs"}):e.jsx("div",{className:"h-6 w-6 rounded-full border border-strong bg-white/[0.05]"}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:"text-micro font-semibold uppercase tracking-[0.08em] text-white/76",children:"Next Up"}),y.isLoading?e.jsxs("span",{className:"inline-flex items-center gap-1.5 rounded-full border border-strong bg-white/[0.04] px-1.5 py-[1px] text-micro uppercase tracking-[0.07em] text-secondary",children:[e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-[#BFFF00]/70 status-breathe"}),"Syncing"]}):e.jsx("span",{className:`rounded-full border px-1.5 py-[1px] text-micro uppercase tracking-[0.07em] ${Us}`,children:Os})]}),y.isLoading?e.jsxs("div",{className:"mt-1.5 space-y-1",children:[e.jsx(Ze,{className:"h-3 w-56 rounded"}),e.jsx(Ze,{className:"h-3 w-44 rounded"})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"truncate text-body font-semibold leading-snug text-bright",title:ns,children:ns}),e.jsxs("p",{className:"truncate text-caption leading-snug text-secondary",title:Ot,children:[zs,Ot?` · ${Ot}`:""]})]})]})]}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[e.jsx("button",{type:"button",onClick:ss,disabled:!j||zt,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold disabled:opacity-45",title:j?`Dispatch ${j.workstreamTitle}`:"No queued workstream to dispatch",children:"Play"}),e.jsx("button",{type:"button",onClick:Pt,className:"control-pill h-8 flex-shrink-0 px-3 text-caption font-semibold",title:"Expand Next Up rail",children:"Open"})]})]},"next-up-inline-card")})]}),we&&e.jsxs("div",{role:"status","aria-live":"polite",className:"mt-2 flex items-start justify-between gap-3 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2 text-caption text-white/72",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-2",children:[e.jsx("span",{"aria-hidden":!0,className:`mt-[3px] h-1.5 w-1.5 flex-shrink-0 rounded-full ${we.tone==="success"?"bg-emerald-300/90":"bg-amber-300/90"}`}),e.jsx("span",{className:"min-w-0 leading-snug",children:we.message})]}),e.jsx("button",{type:"button",onClick:()=>Ce(null),className:"inline-flex h-6 w-6 flex-shrink-0 items-center justify-center rounded-md text-secondary transition-colors hover:bg-white/[0.06] hover:text-primary","aria-label":"Dismiss notice",title:"Dismiss",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"m6 6 12 12"})]})})]}),e.jsxs(le.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},className:`grid gap-4 pb-8 ${qe?"xl:grid-cols-[minmax(0,1fr)_320px] xl:gap-0":"grid-cols-1"}`,children:[e.jsxs(le.div,{layout:!0,className:`min-w-0 ${qe?"xl:pr-4":""}`,children:[!o&&B&&e.jsxs(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-tier-2 relative mb-3.5 overflow-hidden rounded-2xl p-4",children:[e.jsx("div",{"aria-hidden":!0,className:"absolute inset-x-0 top-0 h-px",style:{background:"linear-gradient(90deg, rgba(191,255,0,0.14), rgba(10,212,196,0.12), transparent 72%)"}}),e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-[240px]",children:[e.jsx("p",{className:"section-kicker",children:"Next action"}),e.jsx("p",{className:"mt-1 text-heading font-semibold leading-snug tracking-tight text-bright",children:Rt.headline}),e.jsx("p",{className:"mt-1 text-body leading-relaxed text-secondary",children:Rt.detail}),De&&e.jsx("div",{className:`mt-2 inline-flex max-w-[520px] items-center gap-1 rounded-full border px-2.5 py-1 text-micro ${De.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:De.message})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[(ve==="queued"||ve==="running")&&j?e.jsx("button",{type:"button",onClick:ve==="running"?()=>Lt(j):ss,disabled:zt,className:"control-pill h-9 px-4 text-body font-semibold disabled:opacity-45","data-state":"active",children:ve==="running"?"Follow workstream":"Play next workstream"}):ve==="startable"?e.jsx("button",{type:"button",onClick:Ls,disabled:zt,className:"control-pill h-9 px-4 text-body font-semibold disabled:opacity-45","data-state":"active",children:"Start initiative"}):e.jsx("button",{type:"button",onClick:Ps,className:"control-pill h-9 px-4 text-body font-semibold","data-state":ve==="blocked"?"active":"idle",children:Rs}),e.jsx("button",{type:"button",onClick:Pt,className:"control-pill h-9 px-4 text-body font-semibold",children:qe?"Hide Next Up":"Open Next Up"})]})]})]}),o?e.jsx("div",{className:"space-y-3 pb-8",children:Array.from({length:4}).map((h,E)=>e.jsxs("div",{className:"bg-[--orgx-surface] border border-[--orgx-border] soft-shadow rounded-2xl p-4",children:[e.jsx(Ze,{className:"h-4 w-2/5 rounded"}),e.jsx(Ze,{className:"h-1 w-full rounded mt-3"})]},`mc-skeleton-${E}`))}):t.length===0?b?e.jsx("div",{className:"pb-8",children:e.jsx(xs,{mode:"empty",onCreateInitiative:p,onPlayNextUp:A,onStartAutopilot:R,onRefresh:F})}):e.jsx("div",{className:"pb-8",children:e.jsxs("div",{className:"rounded-2xl border border-white/[0.08] bg-white/[0.02] px-6 py-8 text-center",children:[e.jsx("div",{className:"text-heading font-semibold text-bright",children:"Connect OrgX to get started"}),e.jsx("div",{className:"mt-1 text-body text-secondary",children:"Mission Control shows your initiative hierarchy once a user-scoped API key is configured."}),f&&e.jsx("div",{className:"mt-4 flex items-center justify-center",children:e.jsx("button",{type:"button",onClick:f,className:"h-10 rounded-full border border-[#BFFF00]/30 bg-[#BFFF00]/15 px-4 text-body font-semibold text-[#D8FFA1] transition-colors hover:bg-[#BFFF00]/20",children:"Open settings"})})]})}):ae.length===0?e.jsx("div",{className:"pb-8",children:e.jsx(xs,{mode:"filtered",hasActiveFilters:V,onClearFilters:V?X:void 0,onCreateInitiative:p,onPlayNextUp:A,onStartAutopilot:R,onRefresh:F})}):r?e.jsx("div",{className:"space-y-4 pb-8",children:r.map(h=>{const E=st(D,h.key),P=Yr(E),J=ge.has(E);return e.jsxs(le.div,{layout:!0,transition:{type:"spring",stiffness:260,damping:30},children:[e.jsxs("button",{type:"button","aria-expanded":J,"aria-controls":P,onClick:()=>Z(E),className:"mb-2 flex w-full items-center gap-2 rounded-xl border border-white/[0.075] bg-white/[0.016] px-3 py-2.5 text-left transition-colors hover:border-strong hover:bg-white/[0.04]",children:[e.jsx("span",{"aria-hidden":!0,className:`inline-flex h-5 w-5 items-center justify-center rounded-md border border-strong bg-white/[0.04] text-caption text-secondary transition-transform ${J?"rotate-90":""}`,children:"▶"}),e.jsx("span",{className:"text-body font-semibold text-primary",children:h.label}),e.jsx("span",{className:"rounded-full border border-white/[0.1] bg-white/[0.04] px-2 py-0.5 text-micro text-secondary",children:h.count}),e.jsx("span",{className:"ml-auto text-micro uppercase tracking-[0.08em] text-secondary",children:J?"Hide":"Show"})]}),e.jsx(Oe,{initial:!1,children:J&&e.jsx(le.div,{id:P,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(ms,{initiatives:h.initiatives,selectedInitiativeIds:Ee,onToggleInitiativeSelection:$,runtimeActivityByInitiativeId:Me})})})})]},h.key)})}):e.jsx("div",{className:"pb-8",children:e.jsx(ms,{initiatives:ae,selectedInitiativeIds:Ee,onToggleInitiativeSelection:$,runtimeActivityByInitiativeId:Me})})]}),e.jsx(Oe,{initial:!1,children:qe&&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:Ut,initial:{borderRadius:12},animate:{borderRadius:16,...as},transition:{layout:qt,type:"spring",stiffness:340,damping:38,mass:.72},className:"origin-top-right flex h-[calc(100vh-var(--mc-toolbar-offset)-24px)] min-h-0 flex-col overflow-hidden rounded-2xl border shadow-[0_18px_40px_rgba(0,0,0,0.42)] backdrop-blur-[12px] xl:rounded-l-none",children:e.jsxs("div",{className:"relative flex-1 min-h-0",children:[e.jsx("button",{type:"button",onClick:Pt,className:"control-pill absolute right-3 top-3 z-20 h-7 px-2 text-micro font-semibold",title:"Collapse Next Up rail",children:"Hide"}),e.jsx(ds,{title:"Next Up",className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,authToken:oe,embedMode:C,onFollowWorkstream:Lt,onOpenInitiative:Xe,onOpenSettings:f,onUpgradeGate:ot})]})})})})})]})]}),e.jsx(Oe,{children:Ve&&e.jsxs(e.Fragment,{children:[e.jsx(le.button,{type:"button","aria-label":"Close next up panel",onClick:()=>_e(!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:()=>_e(!1),className:"absolute right-2 top-16 z-20 inline-flex h-8 w-8 items-center justify-center rounded-full border border-strong bg-[#080d14]/85 text-white/72 transition-colors hover:text-white","aria-label":"Close next up drawer",children:"✕"}),e.jsx(le.div,{layout:"position",layoutId:Ut,initial:{borderRadius:12},animate:{borderRadius:16,...as},transition:{layout:qt,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(ds,{title:"Next Up",className:"!bg-transparent !shadow-none !border-transparent",disableEnterAnimation:!0,authToken:oe,embedMode:C,onFollowWorkstream:Lt,onOpenInitiative:(h,E)=>{Xe(h,E),_e(!1)},onOpenSettings:f,onUpgradeGate:ot})})]})},"next-up-drawer")]})})]})})]}),e.jsx(Wr,{target:Ws,onClose:L})]})}export{ln as MissionControlView};