forge-openclaw-plugin 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (213) hide show
  1. package/dist/assets/action-bar-5Ii4UzHa.js +1 -0
  2. package/dist/assets/activity-page-CWjTKFY3.js +1 -0
  3. package/dist/assets/ai-surface-workspace-Dd2FSRom.js +1 -0
  4. package/dist/assets/{atlas-panel-G3wGxjYf.js → atlas-panel-Dinteouh.js} +1 -1
  5. package/dist/assets/{board-dIX6etHh.js → board-CLOHbg6t.js} +1 -1
  6. package/dist/assets/calendar-page-BWkXhzDf.js +1 -0
  7. package/dist/assets/calendar-rules-CjyuTu2I.js +1 -0
  8. package/dist/assets/{calendar-week-toolbar-CWSK5hJl.js → calendar-week-toolbar-D-nd9tkk.js} +1 -1
  9. package/dist/assets/{charts-DFnEuIMB.js → charts-DwTguE_x.js} +1 -1
  10. package/dist/assets/companion-sync-lab-page-G0t1TqqZ.js +1 -0
  11. package/dist/assets/daily-metrics-dashboard-DpIAdzFX.js +1 -0
  12. package/dist/assets/define-workbench-box-BIOZopF2.js +1 -0
  13. package/dist/assets/entity-link-multiselect-DZZjpL_d.js +1 -0
  14. package/dist/assets/{entity-note-count-link-ef3ZOpKM.js → entity-note-count-link-CmRRdXAr.js} +1 -1
  15. package/dist/assets/entity-notes-surface-8MPDscsu.js +1 -0
  16. package/dist/assets/execution-board-Bi8gi8J6.js +1 -0
  17. package/dist/assets/{faceted-token-search-CZmtyJTT.js → faceted-token-search-BGs4TqxT.js} +1 -1
  18. package/dist/assets/{flagship-signal-deck-DxRfmfpN.js → flagship-signal-deck-jLxHEHvb.js} +1 -1
  19. package/dist/assets/{floating-action-menu-cKjNsPYD.js → floating-action-menu-Itpm7T2_.js} +1 -1
  20. package/dist/assets/{forms-hB0SqEh-.js → forms-C5d5hTf2.js} +1 -1
  21. package/dist/assets/generic-node-view-KePoUF3Z.js +10 -0
  22. package/dist/assets/goal-detail-page-a1lEswpJ.js +1 -0
  23. package/dist/assets/goal-dialog-CYgRzl4y.js +1 -0
  24. package/dist/assets/goals-page-JY_EJq9U.js +1 -0
  25. package/dist/assets/{graph-DDUZNRsO.js → graph-Cd5WF3lw.js} +1 -1
  26. package/dist/assets/habits-page-BRI8AoaQ.js +1 -0
  27. package/dist/assets/health-boxes-DZJOFTOI.js +1 -0
  28. package/dist/assets/index-wEZUnRh0.js +2 -0
  29. package/dist/assets/inline-note-fields-CUVRzQkI.js +1 -0
  30. package/dist/assets/insight-flow-dialog-By73oG1H.js +1 -0
  31. package/dist/assets/{insights-page-DHG-o9P_.js → insights-page-DLyN-9yz.js} +3 -3
  32. package/dist/assets/kanban-boxes-M71CejV4.js +1 -0
  33. package/dist/assets/kanban-page-InKHhJQD.js +1 -0
  34. package/dist/assets/knowledge-graph-page-C-GEQGRY.js +1 -0
  35. package/dist/assets/life-force-page-Dq88NzNp.js +1 -0
  36. package/dist/assets/{life-force-workspace-sszLD-Yn.js → life-force-workspace-Bl_0slZi.js} +1 -1
  37. package/dist/assets/{maps-C-yOWiDN.js → maps-D0Mm6WPG.js} +1 -1
  38. package/dist/assets/{metric-tile-B-tDTcBt.js → metric-tile-yQJgjYrN.js} +1 -1
  39. package/dist/assets/{motion-Lt5B1XuE.js → motion-DwjmC9aq.js} +1 -1
  40. package/dist/assets/movement-boxes-C-rc3N8Z.js +1 -0
  41. package/dist/assets/movement-page-DK-d1uYa.js +1 -0
  42. package/dist/assets/{note-markdown-CCyyE85h.js → note-markdown-7czv-KMH.js} +1 -1
  43. package/dist/assets/note-tags-input-CkgkqiT3.js +1 -0
  44. package/dist/assets/notes-boxes-BQuR1MiB.js +1 -0
  45. package/dist/assets/notes-page-ec9g1mPh.js +1 -0
  46. package/dist/assets/{open-in-graph-button-CMjJZX7G.js → open-in-graph-button-B_4fdm4l.js} +1 -1
  47. package/dist/assets/{orbit-map-v2Pv9RU_.js → orbit-map-DPQNBqS-.js} +1 -1
  48. package/dist/assets/overview-page-CZjMab2o.js +1 -0
  49. package/dist/assets/page-hero-BRcqE3a4.js +1 -0
  50. package/dist/assets/pill-cluster-dy6jG_dV.js +1 -0
  51. package/dist/assets/{preference-entity-handoff-button-CKDxCnbl.js → preference-entity-handoff-button-DOV-_2Vm.js} +1 -1
  52. package/dist/assets/preferences-page-Co8w5hzp.js +1 -0
  53. package/dist/assets/{project-collections-NBwk6yV-.js → project-collections-DNgKleDl.js} +1 -1
  54. package/dist/assets/project-detail-page-C-Ib1x8w.js +1 -0
  55. package/dist/assets/project-dialog-D_hgOdB9.js +1 -0
  56. package/dist/assets/project-management-hierarchy-page-asf61KSz.js +1 -0
  57. package/dist/assets/project-management-section-nav-DAZA1oXG.js +1 -0
  58. package/dist/assets/projects-boxes-CHLr1Bs-.js +1 -0
  59. package/dist/assets/projects-page-BsM8yCqQ.js +1 -0
  60. package/dist/assets/psyche-behaviors-page-COSZeP4J.js +5 -0
  61. package/dist/assets/psyche-flashcards-page-CJmgGL9x.js +1 -0
  62. package/dist/assets/psyche-goal-map-page-avrWNSs9.js +1 -0
  63. package/dist/assets/psyche-graph-BmwbnNBY.js +1 -0
  64. package/dist/assets/psyche-metrics-page-CY0J_aMx.js +1 -0
  65. package/dist/assets/psyche-mode-guide-page-COcswIHZ.js +1 -0
  66. package/dist/assets/psyche-modes-page-BXF_GZoP.js +1 -0
  67. package/dist/assets/psyche-page-VsMBNG1F.js +1 -0
  68. package/dist/assets/psyche-patterns-page-DVoIro0Q.js +5 -0
  69. package/dist/assets/psyche-questionnaire-builder-page-CahcrbQj.js +1 -0
  70. package/dist/assets/psyche-questionnaire-detail-page-CYSgADAD.js +1 -0
  71. package/dist/assets/psyche-questionnaire-run-detail-page-D5q5URTu.js +1 -0
  72. package/dist/assets/psyche-questionnaire-run-page-DUoA-VSs.js +1 -0
  73. package/dist/assets/psyche-questionnaires-page-dbQlqbKh.js +1 -0
  74. package/dist/assets/{psyche-report-detail-page-Ci14mNUK.js → psyche-report-detail-page-D_Mmlf2D.js} +3 -3
  75. package/dist/assets/psyche-reports-page-CO3J4Js3.js +1 -0
  76. package/dist/assets/{psyche-schemas-Dxj554nU.js → psyche-schemas-Dtskzvv1.js} +1 -1
  77. package/dist/assets/psyche-schemas-beliefs-page-BUNGL4zW.js +9 -0
  78. package/dist/assets/psyche-screen-time-page-Bm18uHDg.js +1 -0
  79. package/dist/assets/psyche-self-observation-page-VdPMBuK4.js +1 -0
  80. package/dist/assets/psyche-values-page-DivSQodJ.js +5 -0
  81. package/dist/assets/question-flow-dialog-Dsnsc8be.js +2 -0
  82. package/dist/assets/{report-chain-fields-CbkT7WOO.js → report-chain-fields-Bf-WCSJQ.js} +1 -1
  83. package/dist/assets/rewards-page-CI53Cp0i.js +1 -0
  84. package/dist/assets/{scheduling-rules-editor-BUGnZJ0g.js → scheduling-rules-editor-Bg3QU_qt.js} +1 -1
  85. package/dist/assets/{schema-badge-CLAA4p-b.js → schema-badge-CRThEDqP.js} +1 -1
  86. package/dist/assets/schemas-B8-kIOFQ.js +1 -0
  87. package/dist/assets/{select-menu-Cqs5t3ng.js → select-menu-rT3Qd5t5.js} +1 -1
  88. package/dist/assets/{settings-agents-page-pmkVrOO8.js → settings-agents-page-VDUv2WuO.js} +4 -4
  89. package/dist/assets/settings-bin-page-DfuGJVqc.js +1 -0
  90. package/dist/assets/{settings-calendar-page-BBjAMOCf.js → settings-calendar-page-ex7eHB1y.js} +3 -3
  91. package/dist/assets/settings-data-page-BPWyPVGo.js +1 -0
  92. package/dist/assets/settings-logs-page-CwTT4n63.js +1 -0
  93. package/dist/assets/settings-mobile-page-B6sVk872.js +1 -0
  94. package/dist/assets/settings-models-page-Dq5XViZd.js +1 -0
  95. package/dist/assets/settings-page-BRxdAxbS.js +1 -0
  96. package/dist/assets/settings-rewards-page-DRvxTwv3.js +1 -0
  97. package/dist/assets/{settings-section-nav-Co0AaDG-.js → settings-section-nav-D_vKvOWd.js} +1 -1
  98. package/dist/assets/settings-users-page-B6oSpOaV.js +1 -0
  99. package/dist/assets/settings-wiki-page-Bkv-SS3J.js +1 -0
  100. package/dist/assets/sleep-page-DELXxo6j.js +1 -0
  101. package/dist/assets/sports-page-ByWQL0Gf.js +1 -0
  102. package/dist/assets/{state-vCcAT5Hq.js → state-BtwEvpO6.js} +1 -1
  103. package/dist/assets/strategies-page-PuUHsaSJ.js +1 -0
  104. package/dist/assets/strategy-detail-page-CSyVdv29.js +1 -0
  105. package/dist/assets/strategy-dialog-Fgpc0z1M.js +1 -0
  106. package/dist/assets/{surface-CyWI7e1R.js → surface-DzVqQDmf.js} +1 -1
  107. package/dist/assets/{table-BNqMG3_S.js → table-BuONJH1s.js} +1 -1
  108. package/dist/assets/task-detail-page-BoLvJ_4F.js +1 -0
  109. package/dist/assets/task-dialog-B2cGkhLk.js +6 -0
  110. package/dist/assets/timebox-planning-dialog-BjiC2jh0.js +1 -0
  111. package/dist/assets/today-boxes-B4f4sBXg.js +1 -0
  112. package/dist/assets/today-page-Cusp2JI8.js +1 -0
  113. package/dist/assets/training-load-page-CsZbK6rY.js +1 -0
  114. package/dist/assets/{ui-C1iwpj2-.js → ui-B9O-eUim.js} +1 -1
  115. package/dist/assets/use-anchored-overlay-position-BrQ4cqKn.js +1 -0
  116. package/dist/assets/{use-psyche-focus-target-Ct-acS9G.js → use-psyche-focus-target-Cuxni3SK.js} +1 -1
  117. package/dist/assets/user-badge-CQygGKVs.js +1 -0
  118. package/dist/assets/user-ownership-DJGl4rAj.js +1 -0
  119. package/dist/assets/user-select-field-BNqv8-wd.js +1 -0
  120. package/dist/assets/utility-widgets-DRESNarT.js +3 -0
  121. package/dist/assets/{vendor-Dnkkx2co.js → vendor-Cpmju3nw.js} +1 -1
  122. package/dist/assets/vitals-page-BlTZ4f78.js +1 -0
  123. package/dist/assets/weekly-review-page-3Pk3NeGE.js +1 -0
  124. package/dist/assets/weight-loss-page-CRCtv1fX.js +5 -0
  125. package/dist/assets/{wiki-article-markdown-Bi02AsVt.js → wiki-article-markdown-D0PWvioX.js} +2 -2
  126. package/dist/assets/{wiki-editor-page-OZf9l4Tg.js → wiki-editor-page-OZMYUgFo.js} +5 -5
  127. package/dist/assets/wiki-ingest-history-page-DXZHzAqU.js +1 -0
  128. package/dist/assets/wiki-ingest-modal-Ro0V4UMB.js +1 -0
  129. package/dist/assets/wiki-page-B1g3Rfxy.js +1 -0
  130. package/dist/assets/workbench-flow-page-qh5nItU6.js +5 -0
  131. package/dist/assets/workbench-page-CFWfAYMV.js +1 -0
  132. package/dist/assets/workout-detail-page-Cw6t6Xj9.js +2 -0
  133. package/dist/index.html +7 -9
  134. package/dist/server/server/src/app.js +10 -0
  135. package/dist/server/server/src/health-weight-loss.js +11 -3
  136. package/dist/server/server/src/services/dashboard.js +4 -4
  137. package/dist/server/server/src/services/gamification.js +71 -32
  138. package/openclaw.plugin.json +1 -1
  139. package/package.json +1 -1
  140. package/dist/assets/activity-page-DRRbpVK-.js +0 -1
  141. package/dist/assets/ai-surface-workspace-DJPt-OaW.js +0 -1
  142. package/dist/assets/calendar-page-y8G1ige8.js +0 -1
  143. package/dist/assets/calendar-rules-CRhXqGQu.js +0 -1
  144. package/dist/assets/companion-sync-lab-page-kEgOF3c6.js +0 -1
  145. package/dist/assets/daily-metrics-dashboard-BJjUIZVA.js +0 -1
  146. package/dist/assets/entity-notes-surface-CaCjjUaq.js +0 -1
  147. package/dist/assets/execution-board-RRWm2srb.js +0 -1
  148. package/dist/assets/goal-detail-page-BgQlK7yT.js +0 -1
  149. package/dist/assets/goals-page-Cz2i3pVy.js +0 -1
  150. package/dist/assets/habits-page-BmEmWCGv.js +0 -1
  151. package/dist/assets/index-QJkjKYzZ.js +0 -19
  152. package/dist/assets/insight-flow-dialog-CdYMHwMP.js +0 -1
  153. package/dist/assets/kanban-page-C6S_fJRc.js +0 -1
  154. package/dist/assets/knowledge-graph-page-juA9QCy0.js +0 -1
  155. package/dist/assets/life-force-page-ChTIA4mV.js +0 -1
  156. package/dist/assets/movement-page-Dx3T3HrG.js +0 -1
  157. package/dist/assets/note-tags-input-BS14YXHn.js +0 -1
  158. package/dist/assets/notes-page-D3yGl8TN.js +0 -1
  159. package/dist/assets/overview-page-DSOpBpHf.js +0 -1
  160. package/dist/assets/page-hero-CONuJu5J.js +0 -1
  161. package/dist/assets/pill-cluster-W2fY48OM.js +0 -1
  162. package/dist/assets/preferences-page-Br3zrLlH.js +0 -1
  163. package/dist/assets/project-detail-page-BIU9_TRN.js +0 -1
  164. package/dist/assets/project-management-hierarchy-page-C2H620xD.js +0 -1
  165. package/dist/assets/project-management-section-nav-DRPVS1Eh.js +0 -1
  166. package/dist/assets/projects-page-w7a_L2-z.js +0 -1
  167. package/dist/assets/psyche-behaviors-page-Dt4CMC-q.js +0 -5
  168. package/dist/assets/psyche-flashcards-page-rXz06dqO.js +0 -1
  169. package/dist/assets/psyche-goal-map-page-BCcD6Jkl.js +0 -1
  170. package/dist/assets/psyche-graph-CXlAj4ED.js +0 -1
  171. package/dist/assets/psyche-metrics-page-B1otiir6.js +0 -1
  172. package/dist/assets/psyche-mode-guide-page-C6AdVIAv.js +0 -1
  173. package/dist/assets/psyche-modes-page-DoUqz2mR.js +0 -1
  174. package/dist/assets/psyche-page-BJNLQn8W.js +0 -1
  175. package/dist/assets/psyche-patterns-page-CzpMSAPu.js +0 -5
  176. package/dist/assets/psyche-questionnaire-builder-page-DjzatGVZ.js +0 -1
  177. package/dist/assets/psyche-questionnaire-detail-page-B0Qfowfg.js +0 -1
  178. package/dist/assets/psyche-questionnaire-run-detail-page-B2dNj4jJ.js +0 -1
  179. package/dist/assets/psyche-questionnaire-run-page-DyD9Ui-g.js +0 -1
  180. package/dist/assets/psyche-questionnaires-page-BxfKcoi3.js +0 -1
  181. package/dist/assets/psyche-reports-page-ALhNueiV.js +0 -1
  182. package/dist/assets/psyche-schemas-beliefs-page-C0P2Vw6-.js +0 -9
  183. package/dist/assets/psyche-screen-time-page-BYnaT3cb.js +0 -1
  184. package/dist/assets/psyche-self-observation-page-eM9vpwIB.js +0 -1
  185. package/dist/assets/psyche-values-page-BqrGIDok.js +0 -5
  186. package/dist/assets/rewards-page-DpAJ8IxE.js +0 -1
  187. package/dist/assets/settings-bin-page-BwtLrweW.js +0 -1
  188. package/dist/assets/settings-data-page-Bqy5SukM.js +0 -1
  189. package/dist/assets/settings-logs-page-8khtrf4T.js +0 -1
  190. package/dist/assets/settings-mobile-page-BcyRjEU_.js +0 -1
  191. package/dist/assets/settings-models-page-DlSnO9WX.js +0 -1
  192. package/dist/assets/settings-page-CyBQ2qcB.js +0 -1
  193. package/dist/assets/settings-rewards-page-BBX2WtVM.js +0 -1
  194. package/dist/assets/settings-users-page-JSnfFFPu.js +0 -1
  195. package/dist/assets/settings-wiki-page--nT23Fdy.js +0 -1
  196. package/dist/assets/sleep-page-CGMi3MtV.js +0 -1
  197. package/dist/assets/sports-page-Kv5bBoLr.js +0 -1
  198. package/dist/assets/strategies-page-Br7RdUJO.js +0 -1
  199. package/dist/assets/strategy-detail-page-CBWXjUhC.js +0 -1
  200. package/dist/assets/strategy-dialog-BTwkaSxI.js +0 -1
  201. package/dist/assets/task-detail-page-Qis9354n.js +0 -1
  202. package/dist/assets/timebox-planning-dialog-DB8snOBD.js +0 -1
  203. package/dist/assets/today-page-D9A5PU0S.js +0 -1
  204. package/dist/assets/training-load-page-Bpd4DQAh.js +0 -1
  205. package/dist/assets/vitals-page-CVYC-4RG.js +0 -1
  206. package/dist/assets/weekly-review-page-BP7N3fNB.js +0 -1
  207. package/dist/assets/weight-loss-page-_fX3N1UK.js +0 -5
  208. package/dist/assets/wiki-ingest-history-page-CzeNSL7N.js +0 -1
  209. package/dist/assets/wiki-ingest-modal-Ig_xnyc6.js +0 -1
  210. package/dist/assets/wiki-page-B4xuNgY4.js +0 -1
  211. package/dist/assets/workbench-flow-page-BhRJCALC.js +0 -5
  212. package/dist/assets/workbench-page-DxVs2AOY.js +0 -1
  213. package/dist/assets/workout-detail-page-D4wfkE98.js +0 -2
@@ -1 +0,0 @@
1
- import{r as c,j as t}from"./vendor-Dnkkx2co.js";import{Q as N,cO as W,F as i,I as u,b as v,ah as f,j as x,T as p}from"./index-QJkjKYzZ.js";function w(e,a){return{originType:(e==null?void 0:e.originType)??"user",originAgentId:(e==null?void 0:e.originAgentId)??"",originLabel:(e==null?void 0:e.originLabel)??"",entityType:(a==null?void 0:a.entityType)??(e==null?void 0:e.entityType)??"",entityId:(a==null?void 0:a.entityId)??(e==null?void 0:e.entityId)??"",timeframeLabel:(e==null?void 0:e.timeframeLabel)??"This week",title:(e==null?void 0:e.title)??"",summary:(e==null?void 0:e.summary)??"",recommendation:(e==null?void 0:e.recommendation)??"",rationale:(e==null?void 0:e.rationale)??"",confidence:(e==null?void 0:e.confidence)??.72,ctaLabel:(e==null?void 0:e.ctaLabel)??"Review insight",targetKind:(a==null?void 0:a.entityType)??(e==null?void 0:e.entityType)??"general"}}function $({open:e,onOpenChange:a,title:j="Store insight",description:T="Capture a clear observation, its recommendation, and where it belongs without dropping into a raw admin form.",eyebrow:I="Insight",pending:L=!1,submitLabel:C="Store insight",initialValue:g,lockedEntity:h,entityCandidates:d=[],onSubmit:F}){const[s,l]=c.useState(()=>w(g,h)),[S,m]=c.useState(null);c.useEffect(()=>{e&&(l(w(g,h)),m(null))},[g,h,e]);const b=c.useMemo(()=>{const o=new Set(["general"]);return d.forEach(n=>o.add(n.entityType)),h&&o.add(h.entityType),Array.from(o)},[d,h]),y=d.filter(o=>o.entityType===s.targetKind),K=[{id:"focus",eyebrow:"Focus",title:"Name the insight and place it in the right context",description:"Start with the main observation, then decide whether this belongs to a specific entity or should stay general.",render:(o,n)=>t.jsxs(t.Fragment,{children:[t.jsx(i,{label:"Insight title",description:"Write the main idea as a clear headline.",labelHelp:"The title should sound like the recommendation or realization you want to remember, not like an internal database field.",children:t.jsx(u,{value:o.title,onChange:r=>n({title:r.target.value}),placeholder:"Weekly review needs a tighter end ritual"})}),t.jsx(i,{label:"Timeframe",description:"Keep the horizon short and readable.",children:t.jsx(u,{value:o.timeframeLabel,onChange:r=>n({timeframeLabel:r.target.value}),placeholder:"This week"})}),t.jsx(i,{label:"Where should this insight live?",description:"Use a specific entity when the insight is about one goal, project, task, or report. Keep it general when it applies to the wider system.",children:h?t.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[t.jsx(v,{kind:h.kind,label:h.label}),h.description?t.jsx(f,{className:"mt-2",children:h.description}):null]}):t.jsxs(t.Fragment,{children:[t.jsx(x,{value:o.targetKind,onChange:r=>n({targetKind:r,entityType:r==="general"?"":r,entityId:""}),options:b.map(r=>({value:r,label:r==="general"?"General insight":r==="trigger_report"?"Report":r.charAt(0).toUpperCase()+r.slice(1),description:r==="general"?"Store it in the broader insight feed.":`Attach it to a specific ${r==="trigger_report"?"report":r}.`})),columns:b.length>=3?3:2}),o.targetKind!=="general"?y.length>0?t.jsx("div",{className:"mt-4 grid gap-3 md:grid-cols-2",children:y.map(r=>{const A=o.entityType===r.entityType&&o.entityId===r.entityId;return t.jsxs("button",{type:"button",className:`rounded-[22px] border px-4 py-4 text-left transition ${A?"border-[color-mix(in_srgb,var(--primary)_34%,var(--ui-border-subtle)_66%)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)]"}`,onClick:()=>n({entityType:r.entityType,entityId:r.entityId}),children:[t.jsx(v,{kind:r.kind,label:r.label,compact:!0}),r.description?t.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-faint)]",children:r.description}):null]},`${r.entityType}:${r.entityId}`)})}):t.jsxs(f,{className:"mt-4",children:["No"," ",o.targetKind==="trigger_report"?"reports":`${o.targetKind}s`," ","are ready to attach here yet."]}):null]})})]})},{id:"observation",eyebrow:"Observation",title:"Capture what you are seeing clearly",description:"Keep the summary plain and useful. Add the why only if it helps the next action make sense.",render:(o,n)=>t.jsxs(t.Fragment,{children:[t.jsx(i,{label:"Summary",description:"Describe the pattern, problem, or opportunity in plain language.",labelHelp:"Write what is actually happening, not a slogan and not a long essay.",children:t.jsx(p,{value:o.summary,onChange:r=>n({summary:r.target.value}),placeholder:"The weekly review loses energy because the close-out is vague, so finished work never turns into clear next moves."})}),t.jsx(i,{label:"Why this matters",description:"Optional context that helps explain the recommendation.",children:t.jsx(p,{value:o.rationale,onChange:r=>n({rationale:r.target.value}),placeholder:"When the close-out is loose, important wins disappear from memory and the next week starts without momentum."})})]})},{id:"move",eyebrow:"Next move",title:"Turn the insight into a recommendation",description:"Finish with the recommendation you want the user or agent to actually act on.",render:(o,n)=>t.jsxs(t.Fragment,{children:[t.jsx(i,{label:"Recommendation",description:"Write the concrete move this insight points toward.",labelHelp:"A recommendation should be actionable. If the user read only this line, they should know what to do next.",children:t.jsx(p,{value:o.recommendation,onChange:r=>n({recommendation:r.target.value}),placeholder:"Add a fixed five-minute close-out block that turns finished tasks into one sentence of evidence and one next move."})}),t.jsx(i,{label:"Confidence",description:"Choose how strongly this recommendation holds up right now.",children:t.jsx(x,{value:String(o.confidence),onChange:r=>n({confidence:Number(r)}),options:[{value:"0.55",label:"Low",description:"Useful hunch, still early."},{value:"0.72",label:"Medium",description:"Solid pattern, worth acting on."},{value:"0.88",label:"High",description:"Clear enough to trust strongly."}],columns:3})})]})}];return t.jsx(N,{open:e,onOpenChange:a,eyebrow:I,title:j,description:T,value:s,onChange:l,draftPersistenceKey:"insights.flow",steps:K,submitLabel:C,pending:L,error:S,onSubmit:async()=>{m(null);const o=W.safeParse({originType:s.originType,originAgentId:s.originAgentId,originLabel:s.originLabel,entityType:s.targetKind==="general"?"":s.entityType,entityId:s.targetKind==="general"?"":s.entityId,timeframeLabel:s.timeframeLabel,title:s.title,summary:s.summary,recommendation:s.recommendation,rationale:s.rationale,confidence:s.confidence,ctaLabel:s.ctaLabel});if(!o.success){m("This insight still needs a title, a summary, and a recommendation before it can be stored.");return}try{await F(o.data),a(!1)}catch(n){m(n instanceof Error?n.message:"Unable to store this insight right now.")}}})}export{$ as I};
@@ -1 +0,0 @@
1
- import{b5 as Re,r as n,j as s,aC as Ce,b3 as Be,aK as _e,c9 as Oe}from"./vendor-Dnkkx2co.js";import{j as Ae,k as O}from"./state-vCcAT5Hq.js";import{P as Le,u as We,c as m,U as pe,b as A,s as Ke,as as Ue,at as ze,au as qe,B as y,a as he,av as Qe,C as G,aw as De,m as H,ax as Ve,ay as Ge,Y as He,az as Xe,I as ge,i as Ye}from"./index-QJkjKYzZ.js";import{E as Je}from"./execution-board-RRWm2srb.js";import{P as Ze}from"./project-management-section-nav-DRPVS1Eh.js";import{P as xe}from"./page-hero-CONuJu5J.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";import"./entity-note-count-link-ef3ZOpKM.js";import"./floating-action-menu-cKjNsPYD.js";const x={goal:"goal:",project:"project:",tag:"tag:"},b={user:"user:",kind:"kind:"},es=[{value:"project",label:"Project",searchText:"project initiative prd"},{value:"issue",label:"Issue",searchText:"issue vertical slice tracer bullet"},{value:"task",label:"Task",searchText:"task focused ai session"},{value:"subtask",label:"Subtask",searchText:"subtask child step"}];function X(r){return r.trim().toLowerCase()}function ss(r){return r.reduce((t,l)=>(l.startsWith(x.goal)?t.goalIds.push(l.slice(x.goal.length)):l.startsWith(x.project)?t.projectIds.push(l.slice(x.project.length)):l.startsWith(x.tag)&&t.tagIds.push(l.slice(x.tag.length)),t),{goalIds:[],projectIds:[],tagIds:[]})}function ts(r){return r.reduce((t,l)=>{if(l.startsWith(b.user))t.userIds.push(l.slice(b.user.length));else if(l.startsWith(b.kind)){const u=l.slice(b.kind.length);(u==="human"||u==="bot")&&t.kinds.push(u)}return t},{userIds:[],kinds:[]})}function fe(r,t,l,u){r([]),t([]),l(""),u(["task","subtask"])}function as(r){const t=r.trim();return t.length===0?{firstTitle:"Split task part 1",secondTitle:"Split task part 2"}:{firstTitle:`${t} - part 1`,secondTitle:`${t} - part 2`}}function fs(){var re,le,oe,de,ce,ue,me;const{t:r}=Le(),t=We(),l=Re(),u=Ae(),[$,L]=n.useState([]),[E,W]=n.useState([]),[I,F]=n.useState(""),[j,K]=n.useState(["task","subtask"]),[U,M]=n.useState(((le=(re=t.snapshot.workItems)==null?void 0:re[0])==null?void 0:le.id)??((oe=t.snapshot.tasks[0])==null?void 0:oe.id)??null),[Y,z]=n.useState(null),[ke,q]=n.useState(void 0),[J,T]=n.useState(null),[ve,R]=n.useState(void 0),[o,C]=n.useState(null),[Z,Q]=n.useState(null),[d,B]=n.useState({firstTitle:"",secondTitle:"",remainingRatio:.5}),be=n.useMemo(()=>[...t.snapshot.goals.map(e=>({value:`${x.goal}${e.id}`,label:e.title,description:"Goal",searchText:`goal ${e.title} ${e.description??""}`,kind:"goal"})),...t.snapshot.dashboard.projects.map(e=>({value:`${x.project}${e.id}`,label:e.title,description:"Project",searchText:`project ${e.title} ${e.description??""} ${e.goalTitle??""}`,kind:"project"})),...t.snapshot.tags.map(e=>({value:`${x.tag}${e.id}`,label:e.name,description:"Tag",searchText:`tag ${e.name} ${e.color??""}`,kind:"tag"}))],[t.snapshot.dashboard.projects,t.snapshot.goals,t.snapshot.tags]),je=n.useMemo(()=>{const e=t.snapshot.users.filter(i=>i.kind==="bot"),a=t.snapshot.users.filter(i=>i.kind==="human");return[{value:`${b.kind}bot`,label:"Bots",description:`${e.length} bot owner${e.length===1?"":"s"}`,searchText:`bots bot ai agents assistants ${e.map(i=>`${i.displayName} ${i.handle}`).join(" ")}`,badge:s.jsx(m,{className:"border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]",children:"Bots"}),menuBadge:s.jsx(m,{className:"border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] text-[var(--ui-ink-strong)]",children:"Bots"})},{value:`${b.kind}human`,label:"Humans",description:`${a.length} human owner${a.length===1?"":"s"}`,searchText:`humans human people operators ${a.map(i=>`${i.displayName} ${i.handle}`).join(" ")}`,badge:s.jsx(m,{className:"border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[var(--ui-warning-soft)] text-[var(--ui-ink-strong)]",children:"Humans"}),menuBadge:s.jsx(m,{className:"border-[color-mix(in_srgb,var(--warning)_28%,transparent)] bg-[var(--ui-warning-soft)] text-[var(--ui-ink-strong)]",children:"Humans"})},...t.snapshot.users.map(i=>({value:`${b.user}${i.id}`,label:i.displayName,description:`${i.kind}${i.handle?` · @${i.handle}`:""}`,searchText:`${i.displayName} ${i.handle} ${i.kind} ${i.description}`,badge:s.jsx(pe,{user:i,compact:!0}),menuBadge:s.jsx(pe,{user:i,compact:!0})}))]},[t.snapshot.users]),ye=n.useMemo(()=>es.map(e=>({value:e.value,label:e.label,searchText:e.searchText,badge:e.value==="subtask"?s.jsx(A,{kind:"task",label:"Subtask",compact:!0,gradient:!1,className:"border-[color-mix(in_srgb,var(--primary)_28%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]"}):s.jsx(A,{kind:e.kind??e.value,label:e.label,compact:!0,gradient:!1}),menuBadge:e.value==="subtask"?s.jsx(A,{kind:"task",label:"Subtask",compact:!0,gradient:!1,className:"border-[color-mix(in_srgb,var(--primary)_28%,transparent)] bg-[var(--ui-accent-soft)] text-[var(--ui-ink-strong)]"}):s.jsx(A,{kind:e.kind??e.value,label:e.label,compact:!0,gradient:!1})})),[]),p=n.useMemo(()=>ss($),[$]),f=n.useMemo(()=>ts(E),[E]),_=n.useMemo(()=>X(I),[I]),h=n.useMemo(()=>t.snapshot.workItems&&t.snapshot.workItems.length>0?t.snapshot.workItems:t.snapshot.tasks,[t.snapshot.tasks,t.snapshot.workItems]),Ie=n.useMemo(()=>new Map(t.snapshot.dashboard.projects.map(e=>[e.id,e])),[t.snapshot.dashboard.projects]),k=h.filter(e=>{var a;if(!j.includes(e.level))return!1;if(_.length>0){const i=e.projectId?Ie.get(e.projectId)??null:null;if(!X([e.title,e.description,e.level,e.aiInstructions??"",e.executionMode??"",(i==null?void 0:i.title)??"",(i==null?void 0:i.goalTitle)??"",((a=e.user)==null?void 0:a.displayName)??"",...(e.assignees??[]).map(P=>P.displayName)].join(" ")).includes(_))return!1}if(p.goalIds.length>0&&(e.goalId===null||!p.goalIds.includes(e.goalId))||p.projectIds.length>0&&(e.projectId===null||!p.projectIds.includes(e.projectId))||p.tagIds.length>0&&!p.tagIds.every(i=>e.tagIds.includes(i)))return!1;if(f.userIds.length>0||f.kinds.length>0){const i=[...e.user?[e.user]:[],...e.assignees??[]],c=i.some(v=>f.userIds.includes(v.id)),P=i.some(v=>f.kinds.includes(v.kind));if(!c&&!P)return!1}return!0}),D=t.snapshot.dashboard.projects.filter(e=>{var a;if(!j.includes("project")||_.length>0&&!X([e.title,e.description,e.goalTitle,e.productRequirementsDocument,((a=e.user)==null?void 0:a.displayName)??"",...(e.assignees??[]).map(c=>c.displayName)].join(" ")).includes(_)||p.goalIds.length>0&&!p.goalIds.includes(e.goalId)||p.projectIds.length>0&&!p.projectIds.includes(e.id))return!1;if(f.userIds.length>0||f.kinds.length>0){const i=[...e.user?[e.user]:[],...e.assignees??[]],c=i.some(v=>f.userIds.includes(v.id)),P=i.some(v=>f.kinds.includes(v.kind));if(!c&&!P)return!1}return!0}),Te=k.length+D.length,we=D.length>0||k.length>0,Ne=I.trim().length>0||$.length>0||E.length>0||j.length!==2||!j.includes("task")||!j.includes("subtask"),ee=k.find(e=>e.id===U)??h.find(e=>e.id===U)??null,w=Y?t.snapshot.dashboard.projects.find(e=>e.id===Y)??null:null,g=J?h.find(e=>e.id===J)??null:null,Se=k.filter(e=>e.status==="blocked").length,Pe=k.filter(e=>e.status==="done").length,$e=k.filter(e=>e.status==="focus"||e.status==="in_progress").length,se=t.snapshot.activeTaskRuns.length,te=Ke(t.selectedUserIds),N=Z?h.find(e=>e.id===Z)??null:null,S=async()=>{await Promise.all([t.refresh(),Ye(u),u.invalidateQueries({queryKey:["project-board"]}),u.invalidateQueries({queryKey:["task-context"]})])},Ee=O({mutationFn:({taskId:e,patch:a})=>t.patchTask(e,a),onSuccess:S}),Fe=O({mutationFn:e=>Ue(e),onSuccess:S}),Me=O({mutationFn:ze,onSuccess:S}),ae=O({mutationFn:({taskId:e,firstTitle:a,secondTitle:i,remainingRatio:c})=>qe(e,{firstTitle:a,secondTitle:i,remainingRatio:c}),onSuccess:async()=>{await S(),Q(null)}}),ie=(e,a)=>{z(e),q(a)},ne=(e,a)=>{T(e),C(null),R(a)},V=e=>{T(null),R(void 0),C(e)};return h.length===0&&t.snapshot.dashboard.projects.length===0?s.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-5",children:[s.jsx(xe,{title:"Kanban",description:"Move tasks across the board, start work quickly, and keep your next step visible.",badge:"0 visible tasks",actions:s.jsx(y,{size:"lg",onClick:()=>t.openStartWork(),children:"Start work"})}),s.jsx(he,{eyebrow:r("common.kanban.heroEyebrow"),title:r("common.kanban.emptyTitle"),description:r("common.kanban.emptyDescription"),action:s.jsx(Ce,{to:"/goals",className:"inline-flex whitespace-nowrap rounded-full bg-[var(--primary)] px-4 py-2 text-sm font-medium text-[var(--ui-ink-on-accent)] transition hover:opacity-90",children:r("common.kanban.emptyAction")})})]}):s.jsxs("div",{className:"grid min-w-0 grid-cols-1 gap-5",children:[s.jsx(Ze,{}),s.jsx(xe,{title:"Kanban",description:"Move projects, issues, tasks, and subtasks through one shared execution board, then open the right layer when you need to inspect or edit it.",badge:`${Te} visible work items`,actions:s.jsx(y,{size:"lg",onClick:()=>t.openStartWork(ee?{taskId:ee.id}:void 0),children:"Start work"})}),s.jsx(Qe,{children:s.jsx(G,{className:"min-w-0 overflow-hidden",children:s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Board"}),s.jsx("div",{className:"mt-2 text-base text-[var(--ui-ink-strong)]",children:"See projects, issues, tasks, and subtasks in the same workflow lanes, with one card language and one shared board state."})]}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[$e," ready or active"]}),s.jsxs(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[Se," blocked"]}),s.jsxs(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[Pe," done"]}),s.jsxs(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[se," live timer",se===1?"":"s"]}),s.jsxs(m,{className:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",children:[Math.round(((de=t.snapshot.lifeForce)==null?void 0:de.spentTodayAp)??0)," /"," ",Math.round(((ce=t.snapshot.lifeForce)==null?void 0:ce.dailyBudgetAp)??0)," AP"]})]})]})})}),s.jsx(De,{children:s.jsxs(G,{className:"min-w-0 overflow-hidden",children:[s.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[s.jsxs("div",{children:[s.jsx("div",{className:"type-label text-[var(--ui-ink-faint)]",children:"Filters"}),s.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Use compact entity chips for goals, projects, tags, and owner scopes instead of the wide pill rows."})]}),Ne?s.jsx(y,{variant:"secondary",size:"sm",onClick:()=>fe(L,W,F,K),children:"Reset"}):null]}),s.jsxs("div",{className:"mt-4 grid gap-3 xl:grid-cols-[minmax(0,1fr)_minmax(18rem,24rem)]",children:[s.jsx("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx(Be,{className:"size-4 text-[var(--ui-ink-faint)]"}),s.jsx("input",{value:I,onChange:e=>F(e.target.value),placeholder:"Search projects, issues, tasks, subtasks, PRDs, owners, and assignees",className:"min-w-0 flex-1 bg-transparent text-sm text-[var(--ui-ink-strong)] placeholder:text-[var(--ui-ink-faint)] focus:outline-none"}),I.trim().length>0?s.jsx("button",{type:"button",className:"rounded-full text-[var(--ui-ink-faint)] transition hover:text-[var(--ui-ink-strong)]",onClick:()=>F(""),"aria-label":"Clear board search",children:s.jsx(_e,{className:"size-4"})}):null]})}),s.jsx(H,{options:ye,selectedValues:j,onChange:e=>K(e),placeholder:"Work item types",emptyMessage:"No work-item levels.",variant:"action-bar"})]}),s.jsxs("div",{className:"mt-3 grid gap-3 xl:grid-cols-[minmax(0,1.55fr)_minmax(18rem,1fr)]",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Entity filters"}),s.jsx(H,{options:be,selectedValues:$,onChange:L,placeholder:"Filter by goal, project, or tag",emptyMessage:"No matching goals, projects, or tags."})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Owner filters"}),s.jsx(H,{options:je,selectedValues:E,onChange:W,placeholder:"Type Bo for bots, Hu for humans, or a teammate name",emptyMessage:"No matching owners."})]})]})]})}),we?s.jsx(Ve,{children:s.jsx(Je,{tasks:k,projects:D,activeRuns:t.snapshot.activeTaskRuns,goals:t.snapshot.goals,tags:t.snapshot.tags,notesSummaryByEntity:t.snapshot.dashboard.notesSummaryByEntity,selectedTaskId:U,onMove:async(e,a)=>{await t.patchTaskStatus(e,a)},onMoveProject:async(e,a)=>{await t.patchProject(e,{workflowStatus:a})},onQuickReopenTask:async e=>{await Ge(e),await S()},onDeleteTask:async e=>{await Fe.mutateAsync(e),M(a=>{var i;return a!==e?a:((i=k.find(c=>c.id!==e))==null?void 0:i.id)??null}),T(a=>a===e?null:a)},onStartTask:async e=>{await t.startTaskNow(e),M(e),await u.invalidateQueries({queryKey:["task-context",e]})},onStopTask:async e=>{await t.stopTaskRun(e),M(e.taskId),await u.invalidateQueries({queryKey:["task-context",e.taskId]})},onSelectTask:e=>{M(e)},onOpenProject:e=>{l(`/projects/${e}`)},onOpenTask:e=>{l(`/tasks/${e}`)},onEditProject:e=>{ie(e)},onEditTask:e=>{ne(e)},onLinkProject:e=>{ie(e,"anchor")},onLinkTask:e=>{ne(e,"anchor")},onCreateIssueForProject:e=>{const a=t.snapshot.dashboard.projects.find(i=>i.id===e)??null;a&&V({initialLevel:"issue",initialGoalId:a.goalId,initialProjectId:a.id})},onCreateTaskForIssue:e=>{const a=h.find(i=>i.id===e)??null;a&&V({initialLevel:"task",initialGoalId:a.goalId,initialProjectId:a.projectId,initialParentWorkItemId:a.id})},onCreateSubtaskForTask:e=>{const a=h.find(i=>i.id===e)??null;a&&V({initialLevel:"subtask",initialGoalId:a.goalId,initialProjectId:a.projectId,initialParentWorkItemId:a.id})},onSplitTask:e=>{const a=h.find(c=>c.id===e)??null;if(!a)return;const i=as(a.title);Q(e),B({firstTitle:i.firstTitle,secondTitle:i.secondTitle,remainingRatio:.5})}})}):s.jsx(he,{eyebrow:r("common.kanban.heroEyebrow"),title:r("common.kanban.noTasksMatch"),description:"No tasks match the current filters. Reset the filters to bring the full board back.",action:s.jsx(y,{variant:"secondary",onClick:()=>fe(L,W,F,K),children:"Reset"})}),s.jsx(He,{open:w!==null,goals:t.snapshot.goals,users:t.snapshot.users,editingProject:w,defaultUserId:(w==null?void 0:w.userId)??te,initialStepId:ke,onOpenChange:e=>{e||(z(null),q(void 0))},onSubmit:async(e,a)=>{a&&(await t.patchProject(a,e),z(null),q(void 0))}}),s.jsx(Xe,{open:g!==null||o!==null,goals:t.snapshot.goals,projects:t.snapshot.dashboard.projects,workItems:h,tags:t.snapshot.tags,users:t.snapshot.users,editingTask:g,initialGoalId:o==null?void 0:o.initialGoalId,initialProjectId:o==null?void 0:o.initialProjectId,initialParentWorkItemId:o==null?void 0:o.initialParentWorkItemId,initialLevel:o==null?void 0:o.initialLevel,initialStepId:ve,defaultUserId:(g==null?void 0:g.userId)??te,onRefreshEntities:t.refresh,currentCreditedSeconds:g==null?void 0:g.time.totalCreditedSeconds,onOpenChange:e=>{e||(T(null),C(null),R(void 0))},onAdjustTrackedTime:g?async e=>{await Me.mutateAsync(e)}:void 0,onSubmit:async(e,a)=>{a?await Ee.mutateAsync({taskId:a,patch:e}):await t.createTask(e),T(null),C(null),R(void 0)}}),N?s.jsx("div",{className:"surface-overlay fixed inset-0 z-[60] flex items-center justify-center p-4 backdrop-blur-xl",children:s.jsxs(G,{className:"surface-modal-panel w-full max-w-xl",children:[s.jsxs("div",{className:"flex items-start gap-3",children:[s.jsx("div",{className:"mt-1 flex size-11 shrink-0 items-center justify-center rounded-full bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:s.jsx(Oe,{className:"size-5"})}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"font-display text-[1.35rem] leading-tight text-[var(--ui-ink-strong)]",children:"Split this task"}),s.jsxs("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:[N.title," has grown beyond its expected shape. Split the remaining work into two child tasks while keeping the original history intact."]})]})]}),s.jsxs("div",{className:"mt-5 grid gap-4",children:[s.jsxs("div",{className:"grid gap-2",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"First task name"}),s.jsx(ge,{value:d.firstTitle,onChange:e=>B(a=>({...a,firstTitle:e.target.value}))})]}),s.jsxs("div",{className:"grid gap-2",children:[s.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Second task name"}),s.jsx(ge,{value:d.secondTitle,onChange:e=>B(a=>({...a,secondTitle:e.target.value}))})]}),s.jsxs("div",{className:"grid gap-3 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4",children:[s.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm text-[var(--ui-ink-soft)]",children:[s.jsx("span",{children:"Remaining work ratio"}),s.jsxs("span",{children:[Math.round(d.remainingRatio*100),"% /"," ",100-Math.round(d.remainingRatio*100),"%"]})]}),s.jsx("input",{type:"range",min:25,max:75,step:5,value:Math.round(d.remainingRatio*100),onChange:e=>B(a=>({...a,remainingRatio:Number(e.target.value)/100}))}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[Math.round((((ue=N.actionPointSummary)==null?void 0:ue.totalCostAp)??0)*d.remainingRatio)," ","AP first child"]}),s.jsxs(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",children:[Math.round((((me=N.actionPointSummary)==null?void 0:me.totalCostAp)??0)*(1-d.remainingRatio))," ","AP second child"]})]})]})]}),s.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-3",children:[s.jsx(y,{variant:"secondary",onClick:()=>{Q(null)},children:"Cancel"}),s.jsx(y,{pending:ae.isPending,disabled:d.firstTitle.trim().length===0||d.secondTitle.trim().length===0,onClick:()=>{ae.mutateAsync({taskId:N.id,firstTitle:d.firstTitle.trim(),secondTitle:d.secondTitle.trim(),remainingRatio:d.remainingRatio})},children:"Create split tasks"})]})]})}):null]})}export{fs as KanbanPage};
@@ -1 +0,0 @@
1
- import{r as h,j as r,b5 as nr,c2 as sr,cg as ir,cl as or,cm as gt,bf as ft,b4 as cr,cn as lr,co as ur,cp as dr}from"./vendor-Dnkkx2co.js";import{R as pr,P as hr,O as gr,C as fr,T as mr,D as xr,a as mt}from"./ui-C1iwpj2-.js";import{i as yr}from"./state-vCcAT5Hq.js";import{aA as br,aB as dt,aC as Ot,aD as vr,aE as wr,aF as Nr,aG as ot,aH as Be,aI as Pt,aJ as ct,aK as Tt,aL as Dt,aM as Sr,aN as Cr,b as at,V as Er,aO as _r,aP as Rr,ap as jr,u as Gr,aQ as xt,aR as Mr,L as Fr,E as kr,aS as Kr,U as yt,a8 as Ir,B as W,m as ve,I as Je,aT as bt,aU as Ar,aV as Or,aW as Pr}from"./index-QJkjKYzZ.js";import{G as Tr,S as Dr,i as zr,C as Lr,B as $r,M as Yr}from"./graph-DDUZNRsO.js";import{F as vt}from"./faceted-token-search-CZmtyJTT.js";import{A as Hr,m as Vr}from"./motion-Lt5B1XuE.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";const Br=Math.PI*(3-Math.sqrt(5)),Xr=.48;function Xe(e,t,n){return Math.min(n,Math.max(t,e))}function Wr({positions:e,point:t}){const n=[...e.values()];if(n.length===0)return{x:.5,y:.5};let s=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(const N of n)s=Math.min(s,N.x),u=Math.max(u,N.x),o=Math.min(o,N.y),c=Math.max(c,N.y);const l=Math.max(u-s,0),i=Math.max(c-o,0),m=Math.max(l,i,1),g=(1-l/m)/2,b=(1-i/m)/2,G=l||1,f=i||1;return{x:Xe((t.x-s)/G*(l/m)+g,0,1),y:Xe((t.y-o)/f*(i/m)+b,0,1)}}function Ur(e){let t=2166136261;for(let n=0;n<e.length;n+=1)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return t>>>0}function qr({nodes:e,cache:t}){const n=new Map,s=[...e].sort((l,i)=>i.importance-l.importance||l.title.localeCompare(i.title)||l.id.localeCompare(i.id));let u=0,o=0,c=0;if(s.forEach((l,i)=>{const m=t.get(l.id);if(m){n.set(l.id,m),u+=m.x,o+=m.y,c+=1;return}const g=(Ur(l.id)%1e3/1e3-.5)*.22,b=i*Br+g,G=Xr*Math.sqrt(i+1),f={x:Math.cos(b)*G,y:Math.sin(b)*G};n.set(l.id,f),u+=f.x,o+=f.y,c+=1}),c>0){const l=u/c,i=o/c;n.forEach((m,g)=>{n.set(g,{x:m.x-l,y:m.y-i})})}return n}function Qr(e,t){if(e.startsWith("rgb(")&&e.endsWith(")"))return e.replace("rgb(","rgba(").replace(")",`, ${t})`);if(e.startsWith("#")){const n=e.slice(1),s=n.length===3?n.split("").map(l=>`${l}${l}`).join(""):n,u=parseInt(s.slice(0,2),16),o=parseInt(s.slice(2,4),16),c=parseInt(s.slice(4,6),16);return`rgba(${u}, ${o}, ${c}, ${t})`}return e}function Ie(e,t){return`rgba(${e==="structural"?"125, 211, 252":e==="contextual"?"45, 212, 191":e==="taxonomy"?"192, 132, 252":e==="workspace"?"251, 191, 36":"148, 163, 184"}, ${t})`}function wt(e,t){return!t.focusNodeId||e===t.focusNodeId?0:t.detailNodeIds.has(e)?1:t.relatedNodeIds.has(e)?2:3}function Jr({nodeId:e,attributes:t,node:n,focusNodeId:s,relatedNodeIds:u,detailNodeIds:o,hoveredNodeId:c,draggedNodeId:l}){const i=s===e,m=u.has(e),g=o.has(e),b=c===e,G=l===e,f=!s||m,N=t.color;return{...t,label:i||b||G||g?n.title:"",forceLabel:i||b||G||g,highlighted:i||b||G||g,color:f?N:Qr(N,.34),size:G?t.size*2:i?t.size*1.8:b?t.size*1.35:g?t.size*1.16:m?t.size*1.06:t.size,zIndex:G?4:i?3:g||b?2:1}}function Zr({attributes:e,edge:t,focusNodeId:n,detailNodeIds:s,relatedNodeIds:u,hoveredNodeId:o}){const c=!!n&&(t.source===n||t.target===n),l=!!o&&(t.source===o||t.target===o),i={focusNodeId:n,detailNodeIds:s,relatedNodeIds:u},m=n?Math.max(wt(t.source,i),wt(t.target,i)):0,g=c?Ie(t.family,.24):l?Ie(t.family,.14):n?m<=1?Ie(t.family,.09):m===2?Ie(t.family,.05):Ie(t.family,.016):Ie(t.family,.055);return{...e,color:g,size:c?e.size*1.18:l?e.size*1.08:e.size,zIndex:c?2:l?1:0}}function Nt(e,t){const n=new Set,s=new Set;for(const u of e)u.source===t?n.add(u.target):u.target===t&&n.add(u.source);for(const u of e)u.source!==t&&n.has(u.source)&&s.add(u.target),u.target!==t&&n.has(u.target)&&s.add(u.source);return s.delete(t),n.forEach(u=>s.delete(u)),{firstRing:[...n].sort(),secondRing:[...s].sort()}}function St(e,t,n){if(!n)return e.map(()=>-1);const s=new Set(e);if(!s.has(n))return e.map(()=>-1);const u=new Map;for(const l of t){if(!s.has(l.source)||!s.has(l.target))continue;const i=u.get(l.source)??new Set;i.add(l.target),u.set(l.source,i);const m=u.get(l.target)??new Set;m.add(l.source),u.set(l.target,m)}const o=new Map([[n,0]]);let c=[n];for(;c.length>0;){const l=[];for(const i of c){const m=o.get(i);for(const g of u.get(i)??[])o.has(g)||(o.set(g,m+1),l.push(g))}c=l}return e.map(l=>o.get(l)??-1)}function ea({positions:e,focusNodeId:t,firstRingNodeIds:n,secondRingNodeIds:s,currentRatio:u}){const o=e.get(t);if(!o)return null;const c=[t,...n,...s].filter((L,me,F)=>F.indexOf(L)===me),l=c.map(L=>e.get(L)).filter(Boolean);if(l.length===0)return null;let i=Number.POSITIVE_INFINITY,m=Number.NEGATIVE_INFINITY,g=Number.POSITIVE_INFINITY,b=Number.NEGATIVE_INFINITY,G=Number.POSITIVE_INFINITY,f=Number.NEGATIVE_INFINITY,N=Number.POSITIVE_INFINITY,k=Number.NEGATIVE_INFINITY;for(const L of e.values())G=Math.min(G,L.x),f=Math.max(f,L.x),N=Math.min(N,L.y),k=Math.max(k,L.y);for(const L of l)i=Math.min(i,L.x),m=Math.max(m,L.x),g=Math.min(g,L.y),b=Math.max(b,L.y);const _=Math.max(m-i,b-g,.75),z=Math.max(f-G,k-N,_),M=l.length<=1?Xe(Math.max(u,.48),.38,.6):Xe(_/z*3.2,.42,Math.max(u,1.12));return{x:o.x,y:o.y,ratio:M,nodeIds:c}}function zt({positions:e,currentRatio:t=1}){const n=[...e.values()];if(n.length===0)return{x:0,y:0,ratio:t};let s=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY,o=Number.POSITIVE_INFINITY,c=Number.NEGATIVE_INFINITY;for(const m of n)s=Math.min(s,m.x),u=Math.max(u,m.x),o=Math.min(o,m.y),c=Math.max(c,m.y);const l=Math.max(u-s,c-o,1),i=Xe(l/6.4,.72,2.8);return{x:0,y:0,ratio:Math.max(t,i)}}let He=null;function ta(){if(He!==null)return He;if(typeof document>"u")return He=!1,!1;const e=document.createElement("canvas");return He=!!(e.getContext("webgl2")||e.getContext("webgl")||e.getContext("experimental-webgl")),He}function ra(e){if(!e||typeof window>"u")return"#c0c1ff";const t=document.body?getComputedStyle(document.body).getPropertyValue(e).trim():"",n=getComputedStyle(document.documentElement).getPropertyValue(e).trim(),s=t||n;return s?`rgb(${s})`:"#c0c1ff"}function aa(e,t){if(e.startsWith("rgb(")&&e.endsWith(")"))return e.replace("rgb(","rgba(").replace(")",`, ${t})`);if(e.startsWith("#")){const n=e.slice(1),s=n.length===3?n.split("").map(l=>`${l}${l}`).join(""):n,u=parseInt(s.slice(0,2),16),o=parseInt(s.slice(2,4),16),c=parseInt(s.slice(4,6),16);return`rgba(${u}, ${o}, ${c}, ${t})`}return e}function Ve(e,t){e.forEachNode(n=>{const s=e.getNodeAttributes(n);Number.isFinite(s.x)&&Number.isFinite(s.y)&&t.set(n,{x:s.x,y:s.y})})}function na(e,t,n){const s=new Tr,u=[...e].sort((c,l)=>l.importance-c.importance||c.title.localeCompare(l.title)||c.id.localeCompare(l.id)),o=qr({nodes:u,cache:n});return u.forEach(c=>{const l=o.get(c.id);s.addNode(c.id,{x:(l==null?void 0:l.x)??0,y:(l==null?void 0:l.y)??0,size:Math.max(2.5,c.size/14),color:ra(c.accentToken),label:c.title,hidden:!1,forceLabel:!1,highlighted:!1,zIndex:0,data:c})}),t.forEach(c=>{!s.hasNode(c.source)||!s.hasNode(c.target)||s.addEdgeWithKey(c.id,c.source,c.target,{size:Math.max(.8,c.strength*1.6),color:c.family==="structural"?"rgba(125, 211, 252, 0.055)":c.family==="contextual"?"rgba(45, 212, 191, 0.055)":c.family==="taxonomy"?"rgba(192, 132, 252, 0.055)":c.family==="workspace"?"rgba(251, 191, 36, 0.055)":"rgba(148, 163, 184, 0.055)",label:c.label,hidden:!1,forceLabel:!1,zIndex:0,data:c})}),s}function Ct(e){if(e.order===0)return;let t=0,n=0,s=0;if(e.forEachNode(c=>{const l=e.getNodeAttributes(c);t+=l.x,n+=l.y,s+=1}),s===0)return;const u=t/s,o=n/s;Math.abs(u)<1e-4&&Math.abs(o)<1e-4||e.updateEachNodeAttributes((c,l)=>({...l,x:l.x-u,y:l.y-o}),{attributes:["x","y"]})}function Et(e){const t=new Map;return e.forEachNode(n=>{const s=e.getNodeAttributes(n);t.set(n,{x:s.x,y:s.y})}),t}function Ae(e,t){return{nodes:e.nodes().map(n=>({id:n,...e.getNodeAttributes(n)})),edges:t}}function sa(e){if(e.nodes.length===0)return{minX:-1,maxX:1,minY:-1,maxY:1};let t=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY,s=Number.POSITIVE_INFINITY,u=Number.NEGATIVE_INFINITY;for(const o of e.nodes)t=Math.min(t,o.x),n=Math.max(n,o.x),s=Math.min(s,o.y),u=Math.max(u,o.y);return{minX:t,maxX:n,minY:s,maxY:u}}function ia(e){const t=zt({positions:new Map(e.nodes.map(n=>[n.id,{x:n.x,y:n.y}])),currentRatio:1});return{x:t.x,y:t.y,angle:0,ratio:t.ratio}}function oa({x:e,y:t}){const n=Array.from({length:e.length},(u,o)=>({x:e[o]??0,y:t[o]??0})),s=br(n);return s.changed?{changed:!0,offsetX:s.offset.x,offsetY:s.offset.y,x:new Float32Array(s.positions.map(u=>u.x)),y:new Float32Array(s.positions.map(u=>u.y))}:{changed:!1,offsetX:0,offsetY:0,x:new Float32Array(e),y:new Float32Array(t)}}function Lt({node:e,snapshot:t,camera:n,width:s,height:u}){const o=sa(t),c=Math.max(1,o.maxX-o.minX),l=Math.max(1,o.maxY-o.minY),i=28,g=Math.min(Math.max(1,s-i*2)/c,Math.max(1,u-i*2)/l)/Math.max(n.ratio,.08);return{x:s/2+(e.x-n.x)*g,y:u/2-(e.y-n.y)*g,size:Math.max(4,e.size*g*.12)}}function _t(e,t){if(!e)return!1;const n=e.clientWidth,s=e.clientHeight,u=e.getBoundingClientRect();return e.isConnected&&t.width>0&&t.height>0&&n>0&&s>0&&u.width>0&&u.height>0&&e.getClientRects().length>0}function ca({sigma:e,graph:t,viewportX:n,viewportY:s}){let u=null,o=Number.POSITIVE_INFINITY;return t.forEachNode(c=>{const l=t.getNodeAttributes(c),i=e.getNodeDisplayData(c);if(!i||l.hidden)return;const m=e.graphToViewport({x:l.x,y:l.y}),g=m.x-n,b=m.y-s,G=Math.hypot(g,b),f=Math.max(i.size*1.8,18);G<=f&&G<o&&(u=c,o=G)}),u}function Oe(e,t){return`rgba(${e.family==="structural"?"125, 211, 252":e.family==="contextual"?"45, 212, 191":e.family==="taxonomy"?"192, 132, 252":e.family==="workspace"?"251, 191, 36":"148, 163, 184"}, ${t})`}function $t({input:e,rendererMode:t,visibleNodeIds:n,focusPressureByNodeId:s,boundsCenter:u,focusedNodePosition:o,camera:c,nodeScreenPositions:l}){const i=Ot({centroid:e.centroid,boundsCenter:u,camera:c});window.__FORGE_KNOWLEDGE_GRAPH_DIAGNOSTICS__={datasetSignature:e.datasetSignature,visibleNodeIds:n,visibleNodeCount:n.length,focusedNodeId:e.focusNodeId,primaryFocusedNodeId:e.primaryFocusedNodeId,draggedNodeId:e.draggedNodeId,layoutGeneration:e.layoutGeneration,rendererMode:t,startupPhase:e.startupPhase,startupInvariantSatisfied:e.startupInvariantSatisfied,simulationPhase:e.simulationPhase,focusSources:e.focusSources,focusPressureByNodeId:s,graphCentroid:e.centroid,boundsCenter:u,focusedNodePosition:o,cameraTarget:e.cameraTarget,cameraFollowError:e.cameraTarget?{x:Number((c.x-e.cameraTarget.x).toFixed(4)),y:Number((c.y-e.cameraTarget.y).toFixed(4)),ratio:Number((c.ratio-e.cameraTarget.ratio).toFixed(4))}:null,camera:c,nodeScreenPositions:l,centroidDistanceFromOrigin:i.centroidDistanceFromOrigin,boundsCenterDistanceFromOrigin:i.boundsCenterDistanceFromOrigin,cameraDistanceFromOrigin:i.cameraDistanceFromOrigin,cameraToCentroidDistance:i.cameraToCentroidDistance,latestSnapshotAt:e.latestSnapshotAt,latestSnapshotNodeCount:e.latestSnapshotNodeCount}}function la(){if(typeof window>"u")return!1;if(window.__FORGE_ENABLE_GRAPH_DIAGNOSTICS__)return!0;try{return new URLSearchParams(window.location.search).get("graphDiagnostics")==="1"}catch{return!1}}function Rt(){typeof window>"u"||(delete window.__FORGE_KNOWLEDGE_GRAPH_DIAGNOSTICS__,delete window.__FORGE_KNOWLEDGE_GRAPH_TEST_API__)}function ua(e){const t=[],n={},s={};let u=null;e.graph.forEachNode(c=>{t.push(c);const l=e.sigma.getNodeDisplayData(c),i=e.graph.getNodeAttributes(c),m=e.sigma.graphToViewport({x:i.x,y:i.y});n[c]={x:m.x,y:m.y,size:(l==null?void 0:l.size)??i.size},s[c]=Number((e.focusPressure[t.length-1]??0).toFixed(4)),c===e.primaryFocusedNodeId&&(u={x:i.x,y:i.y})});const o=dt(t.map(c=>{const l=e.graph.getNodeAttributes(c);return{x:l.x,y:l.y}}));$t({input:e,rendererMode:"sigma",visibleNodeIds:t,focusPressureByNodeId:s,boundsCenter:o,focusedNodePosition:u,camera:e.sigma.getCamera().getState(),nodeScreenPositions:n})}function jt(e){const t=e.snapshot.nodes.map(o=>o.id),n={},s={};let u=null;e.snapshot.nodes.forEach((o,c)=>{n[o.id]=Lt({node:o,snapshot:e.snapshot,camera:e.camera,width:e.width,height:e.height}),s[o.id]=Number((e.focusPressure[c]??0).toFixed(4)),o.id===e.primaryFocusedNodeId&&(u={x:o.x,y:o.y})}),$t({input:e,rendererMode:"fallback",visibleNodeIds:t,focusPressureByNodeId:s,boundsCenter:dt(e.snapshot.nodes.map(o=>({x:o.x,y:o.y}))),focusedNodePosition:u,camera:e.camera,nodeScreenPositions:n})}function Gt(e){const t=ot.indexOf(e);return t>=0?t:ot.length-1}function da(e){const t=Be.find(n=>n.kinds.some(s=>s===e))??Be[Be.length-1];return{laneId:t.id,laneLabel:t.label,laneIndex:Be.findIndex(n=>n.id===t.id)}}function Ze(){return{structural:0,contextual:0,taxonomy:0,workspace:0}}function pa(e){const t=new Map;for(const n of e){const s=t.get(n.source)??new Set;s.add(n.target),t.set(n.source,s);const u=t.get(n.target)??new Set;u.add(n.source),t.set(n.target,u)}return t}function ha(e,t){return t.strength-e.strength||e.relationKind.localeCompare(t.relationKind)||e.label.localeCompare(t.label)||e.id.localeCompare(t.id)}function Yt(e){const t=new Map;for(const n of e){const s=`${n.source}→${n.target}`,u=t.get(s)??[];u.push(n),t.set(s,u)}return Array.from(t.entries()).map(([n,s])=>{const u=[...s].sort(ha),o=u[0],c=u.length,l=Math.max(...u.map(i=>i.strength))*Math.min(1.45,1+(c-1)*.12);return{id:`${n}#${o.id}`,source:o.source,target:o.target,relationKind:o.relationKind,family:o.family,label:c>1?`${o.label} +${c-1}`:o.label,strength:l,directional:o.directional,structural:o.structural,parallelCount:c,data:u}}).sort((n,s)=>n.source.localeCompare(s.source)||n.target.localeCompare(s.target)||n.id.localeCompare(s.id))}function ga(e,t){const n=Yt(t),s=[...e].sort((o,c)=>{var l;return o.id.localeCompare(c.id)||((l=o.updatedAt)==null?void 0:l.localeCompare(c.updatedAt??""))||0}).map(o=>`${o.id}:${o.title}:${o.size}:${o.importance}:${o.updatedAt??""}`).join("|"),u=n.map(o=>`${o.source}:${o.target}:${o.parallelCount}:${o.label}:${o.strength.toFixed(3)}`).join("|");return`${e.length}/${n.length}/${s}::${u}`}function Ht(e,t){const n=[...e].sort((l,i)=>{const m=Gt(l.entityKind)-Gt(i.entityKind);return m!==0?m:i.importance-l.importance||l.title.localeCompare(i.title)}),s=new Map,u=n.map(l=>{const{laneId:i,laneIndex:m,laneLabel:g}=da(l.entityKind),b=s.get(m)??0;return s.set(m,b+1),{...l,layer:m,laneId:i,laneLabel:g,row:b}}),o=new Map(u.map(l=>[l.id,l])),c=t.map(l=>{const i=o.get(l.source),m=o.get(l.target),g=(i==null?void 0:i.layer)??0,b=(m==null?void 0:m.layer)??0;return{...l,secondary:b<=g||l.family!=="structural"&&l.family!=="taxonomy"}});return{nodes:u,edges:c}}function Mt(e,t,n){const s=new Map(e.map(f=>[f.id,f])),u=n?s.get(n)??null:null;if(!u)return{generatedAt:new Date().toISOString(),focusNode:null,firstRingNodes:[],neighborhoodEdges:[],familyGroups:[],relationCounts:Ze(),secondRingCounts:Ze()};const o=t.filter(f=>f.source===u.id||f.target===u.id),c=Array.from(new Set(o.flatMap(f=>f.source===u.id?[f.target]:[f.source]))),l=c.map(f=>s.get(f)??null).filter(f=>!!f),i=new Map,m=Ze(),g=Ze(),b=pa(t);for(const f of c){const N=b.get(f)??new Set;for(const k of N){if(k===u.id||c.includes(k))continue;const _=t.filter(z=>z.source===f&&z.target===k||z.target===f&&z.source===k);for(const z of _)g[z.family]+=1}}for(const f of o){const N=f.source===u.id?f.target:f.source,k=s.get(N);if(!k)continue;m[f.family]+=1;const _=i.get(f.relationKind);if(_){_.items.some(z=>z.id===k.id)||_.items.push(k);continue}i.set(f.relationKind,{relationKind:f.relationKind,family:f.family,label:vr[f.relationKind],items:[k]})}const G=new Map;for(const f of i.values()){const N=G.get(f.family);if(N){N.relations.push({...f,items:[...f.items].sort((k,_)=>k.title.localeCompare(_.title))}),N.itemCount+=f.items.length,N.relationCount+=1;continue}G.set(f.family,{family:f.family,label:wr[f.family],relationCount:1,itemCount:f.items.length,relations:[{...f,items:[...f.items].sort((k,_)=>k.title.localeCompare(_.title))}]})}return{generatedAt:new Date().toISOString(),focusNode:u,firstRingNodes:l.sort((f,N)=>f.title.localeCompare(N.title)),neighborhoodEdges:o,familyGroups:[...G.values()].map(f=>({...f,relations:f.relations.sort((N,k)=>N.label.localeCompare(k.label))})).sort((f,N)=>f.label.localeCompare(N.label)),relationCounts:m,secondRingCounts:g}}function fa(e,t){return Nr(e,t)}function ma(e,t){if(!e)return new Set;const n=new Set([e]);for(const s of t)s.source===e?n.add(s.target):s.target===e&&n.add(s.source);return n}const xa=h.forwardRef(function({nodes:t,edges:n,focusNodeId:s,physicsSettings:u,onSelectNode:o},c){Pt(),ct(d=>d.knowledgeGraphDiagnostics.panelOpen);const l=h.useRef(null),i=h.useRef(null),m=h.useRef(null),g=h.useRef(null),b=h.useRef(new Map),G=h.useRef(new Map),f=h.useRef(new Map),N=h.useRef(o),k=h.useRef(s),_=h.useRef(null),z=h.useRef(0),M=h.useRef(null),L=h.useRef(0),me=h.useRef(!0),F=h.useRef(null),ce=h.useRef(0),A=h.useRef("global"),xe=h.useRef(null),Pe=h.useRef([]),Me=h.useRef(new Float32Array(0)),we=h.useRef({x:0,y:0}),$=h.useRef("boot"),Ne=h.useRef(!1),Y=h.useRef(!1),P=h.useRef(!1),te=h.useRef(null),le=h.useRef(null),Fe=h.useRef(0),Se=h.useRef(0);h.useRef(0),h.useRef(Tt("/knowledge-graph"));const[Q,ue]=h.useState(null),[ye,de]=h.useState(null),[pe,H]=h.useState(null),[he,V]=h.useState({x:0,y:0,angle:0,ratio:1}),[y,B]=h.useState(null),[w,We]=h.useState({width:0,height:0}),ke=Dt(),re=(d=g.current)=>zt({positions:d?Et(d):new Map,currentRatio:1}).ratio,Te=(d=g.current)=>({x:.5,y:.5,angle:0,ratio:re(d)}),De=(d=g.current)=>({x:0,y:0,angle:0,ratio:re(d)}),ze=()=>i.current?"sigma":"fallback",T=h.useMemo(()=>Yt(n),[n]),ge=h.useMemo(()=>ga(t,n),[n,t]),q=h.useMemo(()=>s?Nt(T,s):null,[s,T]),ae=h.useMemo(()=>s?new Set([s,...(q==null?void 0:q.firstRing)??[]]):new Set,[s,q]),ne=h.useMemo(()=>s?new Set([s,...(q==null?void 0:q.firstRing)??[],...(q==null?void 0:q.secondRing)??[]]):new Set,[s,q]),Ue=()=>_t(l.current,w),se=({resize:d=!1}={})=>{if(!i.current||!Ue())return!1;try{return d&&i.current.resize(),i.current.refresh(),!0}catch(x){if(x instanceof Error&&x.message.includes("Container has no width"))return!1;throw x}},Le=()=>Date.now()<L.current,D=({level:d,eventKey:x,message:v,details:E,publishBackend:C=!1})=>{},st=()=>i.current?{...i.current.getCamera().getState()}:{...he},be=({rendererMode:d})=>{if(!g.current||!_.current)return null;const x=g.current,v=x.nodes().map(S=>{const I=x.getNodeAttributes(S);return{id:S,x:I.x,y:I.y}}),E=Sr(v),C=dt(v),K=st(),O=d==="sigma"?{...K,x:Number((K.x-.5).toFixed(4)),y:Number((K.y-.5).toFixed(4))}:K,j=Ot({centroid:E,boundsCenter:C,camera:O});return{datasetSignature:_.current,route:"/knowledge-graph",rendererMode:d,startupPhase:$.current,startupInvariantSatisfied:Cr(j),visibleNodeCount:v.length,focusedNodeId:k.current,primaryFocusedNodeId:xe.current,graphCentroid:E,boundsCenter:C,camera:K,cameraTarget:F.current?{x:F.current.x,y:F.current.y,ratio:F.current.ratio}:null,driftMetrics:j,latestSnapshotAt:te.current,lastVerifiedAt:new Date().toISOString()}},qe=(d,{mirrorToConsole:x=!1}={})=>{},Qe=({rendererMode:d,publishAnomaly:x})=>{},$e=()=>{const d=i.current?Te():De();if(i.current){i.current.getCamera().setState(d);return}V(d)},a=d=>{var C;if(!g.current)return!1;const x=be({rendererMode:ze()});if(!x)return!1;const v=x.graphCentroid.x,E=x.graphCentroid.y;return Math.abs(v)<1e-4&&Math.abs(E)<1e-4?!1:(Ct(g.current),Ve(g.current,b.current),(C=m.current)==null||C.postMessage({type:"recenter-graph",offsetX:v,offsetY:E}),B(Ae(g.current,T)),$e(),$.current="startup_corrected",D({level:"warning",eventKey:"startup_corrected",message:"Corrected the knowledge graph startup bias back to graph-space origin.",publishBackend:!0,details:{datasetSignature:_.current}}),!0)},p=({phase:d,allowCorrection:x,publishBackendOnFailure:v=!1})=>{if(!g.current||!_.current)return;$.current=d;const E=i.current?"sigma":"fallback",C=be({rendererMode:E});if(!C)return;if(C.startupInvariantSatisfied){$.current="startup_verified",qe({...C},{mirrorToConsole:!0}),D({level:"info",eventKey:"startup_verified",message:"Knowledge graph startup invariant passed.",details:{datasetSignature:C.datasetSignature,driftMetrics:C.driftMetrics}});return}if(D({level:"warning",eventKey:"startup_invariant_failed",message:"Knowledge graph startup invariant failed before correction.",publishBackend:v,details:{datasetSignature:C.datasetSignature,driftMetrics:C.driftMetrics,centroid:C.graphCentroid,boundsCenter:C.boundsCenter,camera:C.camera}}),Ne.current||(Ne.current=!0,!a()))return;se();const O=be({rendererMode:E});if(O){if(O.startupInvariantSatisfied){$.current="startup_verified",qe({...O},{mirrorToConsole:!0}),D({level:"info",eventKey:"startup_verified_after_correction",message:"Knowledge graph startup invariant passed after correction.",details:{datasetSignature:O.datasetSignature,driftMetrics:O.driftMetrics}});return}D({level:"error",eventKey:"startup_correction_failed",message:"Knowledge graph startup correction did not restore the origin invariant.",publishBackend:!0,details:{datasetSignature:O.datasetSignature,driftMetrics:O.driftMetrics,centroid:O.graphCentroid,boundsCenter:O.boundsCenter,camera:O.camera}})}},R=()=>{var x,v,E,C;if(!_.current||!g.current)return;const d=Date.now();if(!(d-Se.current<1500)){if(Se.current=d,i.current){ua({datasetSignature:_.current,focusNodeId:k.current,primaryFocusedNodeId:xe.current,draggedNodeId:((x=M.current)==null?void 0:x.nodeId)??null,graph:g.current,layoutGeneration:z.current,sigma:i.current,startupPhase:$.current,startupInvariantSatisfied:((v=be({rendererMode:"sigma"}))==null?void 0:v.startupInvariantSatisfied)??!1,simulationPhase:A.current,focusSources:Pe.current,focusPressure:Me.current,centroid:we.current,cameraTarget:F.current?{x:F.current.x,y:F.current.y,ratio:F.current.ratio}:null,latestSnapshotAt:te.current,latestSnapshotNodeCount:le.current});return}y&&jt({datasetSignature:_.current,focusNodeId:k.current,primaryFocusedNodeId:xe.current,draggedNodeId:((E=M.current)==null?void 0:E.nodeId)??null,layoutGeneration:z.current,camera:he,snapshot:y,width:w.width,height:w.height,startupPhase:$.current,startupInvariantSatisfied:((C=be({rendererMode:"fallback"}))==null?void 0:C.startupInvariantSatisfied)??!1,simulationPhase:A.current,focusSources:Pe.current,focusPressure:Me.current,centroid:we.current,cameraTarget:F.current?{x:F.current.x,y:F.current.y,ratio:F.current.ratio}:null,latestSnapshotAt:te.current,latestSnapshotNodeCount:le.current})}},Ye=()=>{if(!g.current||!k.current){F.current=null;return}const d=g.current;if(!d.hasNode(k.current)){F.current=null;return}const x=Et(d),v=Nt(T,k.current),E=i.current?i.current.getCamera().getState().ratio:he.ratio,C=ea({positions:x,focusNodeId:k.current,firstRingNodeIds:v.firstRing,secondRingNodeIds:v.secondRing,currentRatio:E}),K=i.current&&C?Wr({positions:x,point:{x:C.x,y:C.y}}):null;F.current=C?{x:(K==null?void 0:K.x)??C.x,y:(K==null?void 0:K.y)??C.y,angle:0,ratio:C.ratio,nodeIds:C.nodeIds}:null},pt=(d=220)=>{if(!F.current)return;const x=F.current;if(i.current){const v=i.current.getCamera(),E=v.getState(),C=Date.now()<ce.current;v.animate({x:x.x,y:x.y,ratio:C?E.ratio:x.ratio,angle:0},{duration:d});return}V(v=>({...v,x:x.x,y:x.y,ratio:Date.now()<ce.current?v.ratio:x.ratio}))};h.useEffect(()=>{N.current=o},[o]),h.useEffect(()=>{k.current=s,F.current=null},[s]),h.useEffect(()=>{Rt()},[ke]),h.useEffect(()=>{if(!(!la()||typeof window>"u"))return window.__FORGE_KNOWLEDGE_GRAPH_TEST_API__={selectNode:d=>{var v;const x=d?f.current.get(d)??((v=g.current)!=null&&v.hasNode(d)?g.current.getNodeAttribute(d,"data")??null:null):null;N.current(x)},moveNodeBy:(d,x,v)=>{var O,j;if(!((O=g.current)!=null&&O.hasNode(d)))return;const E=g.current.getNodeAttributes(d),C=E.x+x,K=E.y+v;g.current.mergeNodeAttributes(d,{x:C,y:K}),b.current.set(d,{x:C,y:K}),(j=m.current)==null||j.postMessage({type:"nudge-node",nodeId:d,x:C,y:K}),se(),!i.current&&g.current&&B(Ae(g.current,T))},nudgeCameraBy:(d,x)=>{if(i.current){const v=i.current.getCamera(),E=v.getState();v.animate({x:E.x+d,y:E.y+x,ratio:E.ratio,angle:E.angle},{duration:140});return}V(v=>({...v,x:v.x+d,y:v.y+x}))}},()=>{delete window.__FORGE_KNOWLEDGE_GRAPH_TEST_API__}},[T]),h.useEffect(()=>{if(!l.current||typeof ResizeObserver>"u")return;const d=()=>{l.current&&We({width:l.current.clientWidth,height:l.current.clientHeight})};d();const x=new ResizeObserver(()=>{d()});return x.observe(l.current),()=>x.disconnect()},[]),h.useImperativeHandle(c,()=>({zoomIn:()=>{if(ce.current=Date.now()+1200,i.current){i.current.getCamera().animatedZoom({factor:1.25,duration:160});return}V(d=>({...d,ratio:Math.max(.08,d.ratio*.82)}))},zoomOut:()=>{if(ce.current=Date.now()+1200,i.current){i.current.getCamera().animatedUnzoom({factor:1.25,duration:160});return}V(d=>({...d,ratio:Math.min(4,d.ratio*1.22)}))},fit:()=>{if(F.current=null,i.current){i.current.getCamera().animate(Te(),{duration:220});return}y&&V(ia(y))},recenterOnFocus:()=>{Ye(),F.current&&pt(220)}}),[y,T]),h.useEffect(()=>()=>{var d,x,v;g.current&&Ve(g.current,b.current),i.current&&_.current&&G.current.set(_.current,i.current.getCamera().getState()),(d=m.current)==null||d.postMessage({type:"dispose"}),(x=m.current)==null||x.terminate(),m.current=null,(v=i.current)==null||v.kill(),i.current=null,Rt()},[ke]),h.useEffect(()=>{var K,O;if(!l.current||!_t(l.current,w))return;if(_.current===ge&&g.current!==null){se({resize:!0}),R();return}$.current="boot",Ne.current=!1,Y.current=!1,P.current=!1,te.current=null,le.current=null,Fe.current=0,F.current=null,D({level:"info",eventKey:"graph_boot",message:"Bootstrapping a fresh knowledge graph dataset.",details:{nodeCount:t.length,edgeCount:T.length}}),g.current&&Ve(g.current,b.current),i.current&&_.current&&G.current.set(_.current,i.current.getCamera().getState());const x=na(t,T,b.current);if(Ct(x),Ve(x,b.current),g.current=x,f.current=new Map(t.map(j=>[j.id,j])),_.current=ge,z.current+=1,B(Ae(x,T)),$.current="graph_built",D({level:"info",eventKey:"graph_built",message:"Built and centered the knowledge graph structure.",details:{layoutGeneration:z.current}}),!ta())(K=i.current)==null||K.kill(),i.current=null,H("WebGL is unavailable in this browser context."),V(De(x)),p({phase:"graph_built",allowCorrection:!0,publishBackendOnFailure:!0});else try{if(i.current)i.current.setGraph(x),se();else{i.current=new Dr(x,l.current,{renderEdgeLabels:!1,hideEdgesOnMove:!0,hideLabelsOnMove:!0,labelRenderedSizeThreshold:20,labelDensity:.04,labelGridCellSize:120,defaultNodeColor:"#c0c1ff",defaultEdgeColor:"rgba(125, 211, 252, 0.1)",minCameraRatio:.08,maxCameraRatio:4,autoRescale:!1,autoCenter:!1,enableEdgeEvents:!1,enableCameraPanning:!0,zIndex:!0}),D({level:"info",eventKey:"sigma_initialized",message:"Initialized Sigma for the knowledge graph.",details:{datasetSignature:ge}}),i.current.on("clickNode",({node:S})=>{if(Le())return;const I=f.current.get(S)??null;N.current(I)}),i.current.on("clickStage",({event:S})=>{if(Le())return;if(!i.current||!g.current){N.current(null);return}const I=ca({sigma:i.current,graph:g.current,viewportX:S.x,viewportY:S.y});if(I){N.current(f.current.get(I)??null);return}N.current(null)}),i.current.on("downNode",({node:S,event:I,preventSigmaDefault:ie})=>{var oe,X;if(!i.current||!((oe=g.current)!=null&&oe.hasNode(S)))return;ie();const Ke=i.current.viewportToGraph({x:I.x,y:I.y}),J=g.current.getNodeAttributes(S);M.current={nodeId:S,offsetX:J.x-Ke.x,offsetY:J.y-Ke.y,startViewportX:I.x,startViewportY:I.y,currentX:J.x,currentY:J.y,moved:!1},me.current=i.current.getSetting("enableCameraPanning")??!0,i.current.setSetting("enableCameraPanning",!1),de(S),ue(S),D({level:"debug",eventKey:"drag_start",message:"Started dragging a knowledge graph node.",details:{nodeId:S}}),(X=m.current)==null||X.postMessage({type:"drag-start",nodeId:S})}),i.current.on("moveBody",({event:S,preventSigmaDefault:I})=>{var X;if(!i.current||!g.current||!M.current)return;I();const ie=i.current.viewportToGraph({x:S.x,y:S.y});Math.hypot(S.x-M.current.startViewportX,S.y-M.current.startViewportY)>3&&(M.current={...M.current,moved:!0});const J=ie.x+M.current.offsetX,oe=ie.y+M.current.offsetY;M.current={...M.current,currentX:J,currentY:oe},g.current.mergeNodeAttributes(M.current.nodeId,{x:J,y:oe}),b.current.set(M.current.nodeId,{x:J,y:oe}),(X=m.current)==null||X.postMessage({type:"drag-move",nodeId:M.current.nodeId,x:J,y:oe}),se()});const j=()=>{var ie;if(!i.current||!M.current){M.current=null,de(null);return}const S=M.current.nodeId,I=M.current.moved;i.current.setSetting("enableCameraPanning",me.current),(ie=m.current)==null||ie.postMessage({type:"drag-end",nodeId:S}),D({level:"debug",eventKey:"drag_end",message:"Released a dragged knowledge graph node.",details:{nodeId:S,moved:I}}),M.current=null,de(null),I&&(L.current=Date.now()+220,N.current(f.current.get(S)??null))};i.current.on("upNode",j),i.current.on("upStage",j),i.current.on("leaveStage",j),i.current.on("enterNode",({node:S})=>{ue(S)}),i.current.on("leaveNode",()=>{ue(null)}),i.current.on("afterRender",()=>{Y.current||(Y.current=!0,$.current="first_frame",D({level:"info",eventKey:"first_frame",message:"Knowledge graph rendered its first frame.",details:{datasetSignature:_.current}}),p({phase:"first_frame",allowCorrection:!0,publishBackendOnFailure:!0}),Qe({rendererMode:"sigma",publishAnomaly:!0})),R()})}H(null),B(Ae(x,T)),i.current.getCamera().setState(Te(x))}catch(j){(O=i.current)==null||O.kill(),i.current=null,H(j instanceof Error?j.message:"Graph renderer unavailable."),B(Ae(x,T)),V(De(x)),D({level:"error",eventKey:"sigma_fallback",message:"Fell back from Sigma to the SVG renderer.",publishBackend:!0,details:{reason:j instanceof Error?j.message:"unknown"}}),p({phase:"graph_built",allowCorrection:!0,publishBackendOnFailure:!0})}m.current||(m.current=new Worker(new URL("/forge/assets/knowledge-graph-layout.worker-DRvzPxhP.js",import.meta.url),{type:"module"}),m.current.onmessage=j=>{var oe;if(!g.current)return;const S=j.data;if(S.type==="stats"){A.current=S.phase,xe.current=S.primaryFocusedNodeId,Pe.current=S.focusSources,Me.current=S.focusPressure,we.current=S.centroid,P.current||(P.current=!0,$.current="worker_started",D({level:"info",eventKey:"worker_started",message:"Knowledge graph worker reported its first simulation stats.",details:{datasetSignature:_.current,phase:S.phase}}),p({phase:"worker_started",allowCorrection:!0,publishBackendOnFailure:!0}));return}const I=g.current;let ie=S.x,Ke=S.y;if($.current!=="startup_verified"){const X=oa({x:S.x,y:S.y});X.changed&&(ie=X.x,Ke=X.y,(oe=m.current)==null||oe.postMessage({type:"recenter-graph",offsetX:X.offsetX,offsetY:X.offsetY}),$e(),D({level:"warning",eventKey:"worker_startup_recenter",message:"Recentering worker positions during startup because the graph drifted away from origin.",details:{datasetSignature:_.current,startupPhase:$.current,offsetX:X.offsetX,offsetY:X.offsetY}}))}let J=0;if(I.updateEachNodeAttributes((X,ar)=>({...ar,x:ie[J],y:Ke[J++]}),{attributes:["x","y"]}),M.current&&I.hasNode(M.current.nodeId)){const X=M.current.nodeId;I.mergeNodeAttributes(X,{x:M.current.currentX,y:M.current.currentY})}Ve(I,b.current),i.current?se():B(Ae(I,T))});const v=x.nodes(),E=new Map(v.map((j,S)=>[j,S])),C=St(v,T,s);m.current.postMessage({type:"init-graph",nodes:v.map(j=>{const S=x.getNodeAttributes(j);return{id:j,x:S.x,y:S.y,size:S.size,mass:Math.max(1,S.data.importance/42),importance:S.data.importance}}),edges:T.filter(j=>E.has(j.source)&&E.has(j.target)).map(j=>({source:E.get(j.source),target:E.get(j.target),weight:Math.max(.6,j.strength)})),focusNodeId:s,hopLevels:C,physics:u}),D({level:"debug",eventKey:"worker_init",message:"Posted the graph payload to the layout worker.",details:{nodeCount:v.length,edgeCount:T.length}})},[w.height,w.width,ge,s,t,u,T]),h.useEffect(()=>{if(!m.current||!g.current)return;const d=St(g.current.nodes(),T,s);m.current.postMessage({type:"set-focus",focusNodeId:s,hopLevels:d}),s||(F.current=null)},[s,T]),h.useEffect(()=>{m.current&&m.current.postMessage({type:"update-physics",physics:u})},[u]),h.useEffect(()=>{},[ge,ke]),h.useEffect(()=>{!i.current||!g.current||(i.current.setSetting("nodeReducer",(d,x)=>{var E;const v=(E=g.current)==null?void 0:E.getNodeAttribute(d,"data");return Jr({nodeId:d,attributes:x,node:v,focusNodeId:s,relatedNodeIds:ne,detailNodeIds:ae,hoveredNodeId:Q,draggedNodeId:ye})}),i.current.setSetting("edgeReducer",(d,x)=>{var E;const v=(E=g.current)==null?void 0:E.getEdgeAttribute(d,"data");return Zr({attributes:x,edge:v,focusNodeId:s,detailNodeIds:ae,relatedNodeIds:ne,hoveredNodeId:Q})}),se())},[ae,ye,s,Q,ne]),h.useEffect(()=>{var d,x;!y||!_.current||w.width<=0||w.height<=0||!pe&&i.current||(Y.current||(Y.current=!0,$.current="first_frame",D({level:"info",eventKey:"fallback_first_frame",message:"Knowledge graph rendered its first fallback frame.",details:{datasetSignature:_.current}}),p({phase:"first_frame",allowCorrection:!0,publishBackendOnFailure:!0})),jt({datasetSignature:_.current,focusNodeId:s,primaryFocusedNodeId:xe.current,draggedNodeId:((d=M.current)==null?void 0:d.nodeId)??null,layoutGeneration:z.current,camera:he,snapshot:y,width:w.width,height:w.height,startupPhase:$.current,startupInvariantSatisfied:((x=be({rendererMode:"fallback"}))==null?void 0:x.startupInvariantSatisfied)??!1,simulationPhase:A.current,focusSources:Pe.current,focusPressure:Me.current,centroid:we.current,cameraTarget:F.current?{x:F.current.x,y:F.current.y,ratio:F.current.ratio}:null,latestSnapshotAt:te.current,latestSnapshotNodeCount:le.current}))},[w.height,w.width,he,pe,y,s]);const it=h.useMemo(()=>!y||w.width<=0||w.height<=0?[]:y.nodes.map(d=>{const x=Lt({node:d,snapshot:y,camera:he,width:w.width,height:w.height});return{...d,viewportX:x.x,viewportY:x.y,viewportSize:x.size}}),[w.height,w.width,he,y]),ht=h.useMemo(()=>new Map(it.map(d=>[d.id,d])),[it]);return r.jsx("div",{className:"relative h-full w-full overflow-hidden bg-[var(--ui-surface-0)]",children:r.jsx("div",{ref:l,className:"h-full w-full touch-none","aria-label":"Knowledge graph canvas",children:pe&&y?r.jsxs("svg",{className:"h-full w-full",viewBox:`0 0 ${Math.max(w.width,1)} ${Math.max(w.height,1)}`,"aria-hidden":"true",children:[r.jsx("title",{children:"Knowledge graph fallback canvas"}),r.jsx("rect",{x:"0",y:"0",width:Math.max(w.width,1),height:Math.max(w.height,1),fill:"transparent",onClick:()=>N.current(null)}),y.edges.map(d=>{const x=ht.get(d.source),v=ht.get(d.target);if(!x||!v)return null;const E=!!s&&(d.source===s||d.target===s),C=!!Q&&(d.source===Q||d.target===Q),K=s?d.source===s?0:ae.has(d.source)?1:ne.has(d.source)?2:3:0,O=s?d.target===s?0:ae.has(d.target)?1:ne.has(d.target)?2:3:0,j=s?Math.max(K,O):0;return r.jsx("line",{x1:x.viewportX,y1:x.viewportY,x2:v.viewportX,y2:v.viewportY,stroke:E?Oe(d,.24):C?Oe(d,.14):s?j<=1?Oe(d,.09):j===2?Oe(d,.05):Oe(d,.016):Oe(d,.055),strokeWidth:E?1.7:C?1.3:.95},d.id)}),it.map(d=>{const x=s===d.id,v=ne.has(d.id),E=ae.has(d.id),C=Q===d.id,K=!s||v;return r.jsxs("g",{transform:`translate(${d.viewportX}, ${d.viewportY})`,onMouseEnter:()=>ue(d.id),onMouseLeave:()=>ue(null),onClick:O=>{O.stopPropagation();const j=f.current.get(d.id)??null;N.current(j)},style:{cursor:"pointer"},children:[r.jsx("circle",{r:x?d.viewportSize*1.9:C?d.viewportSize*1.3:E?d.viewportSize*1.15:v?d.viewportSize*1.05:d.viewportSize,fill:K?d.color:aa(d.color,.3),stroke:x?"var(--ui-border-strong)":"var(--ui-border-subtle)",strokeWidth:x?2:1}),(x||C||E)&&r.jsx("text",{x:d.viewportSize*1.5,y:4,fill:"var(--ui-ink-strong)",fontSize:"12",children:d.data.title})]},d.id)})]}):null})})}),ya=300,ba=152;function Vt(e,t){return e?ma(e,t):new Set}function va(e,t,n){const s=Ht(e,t),u=Vt(n,t);return s.nodes.map(o=>{const c=o.id===n,l=!n||u.has(o.id);return{id:o.id,draggable:!1,selectable:!1,position:{x:72+o.layer*ya,y:88+o.row*ba},data:{label:r.jsxs("div",{className:"w-[min(17rem,calc(100vw-5rem))] min-w-0 max-w-[17rem] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] transition",style:{borderColor:c?"var(--ui-border-strong)":"var(--ui-border-subtle)",background:c?"var(--ui-surface-active)":"var(--ui-surface-1)",opacity:l?1:.28},children:[r.jsx("div",{className:"flex flex-wrap items-center gap-2",children:r.jsx(at,{kind:o.entityKind,label:o.entityKind.replaceAll("_"," "),compact:!0,gradient:c})}),r.jsx("div",{className:"mt-3",children:r.jsx(Er,{kind:o.entityKind,label:o.title,className:"max-w-full",lines:2})}),o.subtitle?r.jsx("div",{className:"mt-2 break-words text-sm leading-5 text-[var(--ui-ink-soft)]",children:o.subtitle}):null]})},style:{background:"transparent",border:"none",padding:0}}})}function wa(e,t,n,s){const u=Ht(e,t),o=Vt(n,t);return u.edges.filter(c=>s||!c.secondary).map(c=>{const l=!n||o.has(c.source)||o.has(c.target);return{id:c.id,source:c.source,target:c.target,animated:!c.secondary&&c.family==="structural"&&l,markerEnd:{type:Yr.ArrowClosed,color:c.secondary?"var(--ui-border-subtle)":"var(--ui-border-strong)"},style:{opacity:l?1:.18,stroke:c.secondary?"var(--ui-border-subtle)":c.family==="taxonomy"?"var(--success)":c.family==="structural"?"var(--ui-border-strong)":"var(--primary)",strokeDasharray:c.secondary?"8 6":void 0,strokeWidth:c.secondary?1:c.family==="structural"?1.7:1.2}}})}function Na({nodes:e,edges:t,focusNodeId:n,showSecondaryEdges:s,onSelectNode:u,onOpenNode:o,onNavigateNode:c,isMobile:l}){const i=h.useMemo(()=>va(e,t,n),[t,n,e]),m=h.useMemo(()=>wa(e,t,n,s),[t,n,e,s]),g=h.useMemo(()=>new Map(e.map(b=>[b.id,b])),[e]);return r.jsxs("div",{className:"knowledge-graph-canvas relative h-[44rem] rounded-[28px]",children:[r.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 z-10 flex gap-4 overflow-x-auto px-6 py-4",children:Be.map(b=>r.jsx("div",{className:"min-w-[min(17rem,calc(100vw-5rem))] rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)] shadow-[var(--ui-shadow-soft)] backdrop-blur",children:b.label},b.id))}),r.jsxs(zr,{fitView:!0,fitViewOptions:n?{padding:.24,nodes:[{id:n}]}:{padding:.2},nodes:i,edges:m,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,attributionPosition:"bottom-left",onNodeClick:(b,G)=>{const f=g.get(G.id);f&&u(f)},onNodeDoubleClick:(b,G)=>{const f=g.get(G.id);if(f){if(l){o(f);return}c(f)}},children:[r.jsx(Lr,{showInteractive:!1}),r.jsx($r,{gap:28,size:1,color:"var(--ui-border-subtle)"})]},`${n??"all"}-${s?"all":"primary"}`)]})}const Bt=6,Xt=5,Wt=.92,Ut=5,qt=.15,Qt=2.4,Jt=2,Zt=.8,er=3,ee={focusRepulsion:2.25,focusDiffusion:1.95,focusSpringReductionMax:.34,focusSpringReductionDiffusion:1.85,edgeSpringStrength:1,gravityStrength:1,focusShellSpacing:1};function Ee(e,t,n){return Math.min(Math.max(e,t),n)}function tr(e){return{focusRepulsion:Ee((e==null?void 0:e.focusRepulsion)??ee.focusRepulsion,.6,Bt),focusDiffusion:Ee((e==null?void 0:e.focusDiffusion)??ee.focusDiffusion,.6,Xt),focusSpringReductionMax:Ee((e==null?void 0:e.focusSpringReductionMax)??ee.focusSpringReductionMax,0,Wt),focusSpringReductionDiffusion:Ee((e==null?void 0:e.focusSpringReductionDiffusion)??ee.focusSpringReductionDiffusion,.6,Ut),edgeSpringStrength:Ee((e==null?void 0:e.edgeSpringStrength)??ee.edgeSpringStrength,qt,Qt),gravityStrength:Ee((e==null?void 0:e.gravityStrength)??ee.gravityStrength,0,Jt),focusShellSpacing:Ee((e==null?void 0:e.focusShellSpacing)??ee.focusShellSpacing,Zt,er)}}const nt=2e3,lt=40,ut=2e3,rr="forge.knowledge-graph.physics";function Sa(){if(typeof window>"u")return!1;if(window.__FORGE_ENABLE_GRAPH_DIAGNOSTICS__)return!0;try{return new URLSearchParams(window.location.search).get("graphDiagnostics")==="1"}catch{return!1}}function et(e,t){return Array.from(new Set(e.getAll(t).flatMap(n=>n.split(",")).map(n=>n.trim()).filter(Boolean)))}function U(e,t,n){e.delete(t),n.forEach(s=>e.append(t,s))}function Ca(e){switch(e.entityType){case"workbench_flow":case"workbench_surface":case"wiki_space":return null;default:return jr(e.entityType,e.entityId)}}function Z(e){return e?e.slice(0,10):""}function Ea(){if(typeof window>"u")return ee;try{const e=window.localStorage.getItem(rr);return e?tr(JSON.parse(e)):ee}catch{return ee}}function _a(e){typeof window>"u"||window.localStorage.setItem(rr,JSON.stringify(e))}function Ra(e,t,n,s,u){const o=e.find(c=>c.id===t);return o||(!t||!n?null:{id:t,displayName:n,kind:s??"human",accentColor:u??"",handle:n.toLowerCase().replace(/\s+/g,"-"),description:"",createdAt:"",updatedAt:""})}function ja({entityKinds:e,relationKinds:t,tags:n,owners:s}){return[...e.map(u=>`entity:${u}`),...t.map(u=>`relation:${u}`),...n.map(u=>`tag:${u}`),...s.map(u=>`owner:${u}`)]}function Ft(e){const t=[],n=[],s=[],u=[];for(const o of e){const[c,...l]=o.split(":"),i=l.join(":").trim();i&&(c==="entity"?t.push(i):c==="relation"?n.push(i):c==="tag"?s.push(i):c==="owner"&&u.push(i))}return{entityKinds:t,relationKinds:n,tags:s,owners:u}}function Ga(e){const t=new URLSearchParams(e),n=t.get("view")==="hierarchy"?"hierarchy":"graph",s=_r(t.get("focus")),u=s?fa(s.entityType,s.entityId):null,o=et(t,"entityKind"),c=et(t,"relationKind"),l=et(t,"tag"),i=et(t,"owner"),m=t.get("q")??"",g=t.get("updatedFrom"),b=t.get("updatedTo"),G=Number(t.get("limit")??nt),f=Number.isFinite(G)?Math.max(lt,Math.min(ut,G)):nt;return{selectedView:n,focusNodeId:u,selectedKinds:o,selectedRelations:c,selectedTags:l,selectedOwners:i,showHierarchyCrossLinks:t.get("cross")==="1",queryText:m,updatedFrom:g,updatedTo:b,maxNodes:f}}function Ma(e){return{q:e.queryText.trim()||null,entityKinds:[...e.selectedKinds].sort(),relationKinds:[...e.selectedRelations].sort(),tags:[...e.selectedTags].sort(),owners:[...e.selectedOwners].sort(),updatedFrom:e.updatedFrom,updatedTo:e.updatedTo,limit:e.maxNodes,focusNodeId:null}}function kt(e,t){if(!t){e.delete("focus");return}e.set("focus",Rr(t.entityType,t.entityId))}function Fa({isMobile:e,currentFocusNodeId:t,nextNodeId:n}){return n?e?t===n?{nextFocusNodeId:n,nextMobileSheetOpen:!0,shouldUpdateFocus:!1}:{nextFocusNodeId:n,nextMobileSheetOpen:!1,shouldUpdateFocus:!0}:{nextFocusNodeId:n,nextMobileSheetOpen:!1,shouldUpdateFocus:t!==n}:{nextFocusNodeId:null,nextMobileSheetOpen:!1,shouldUpdateFocus:t!==null}}const Kt="__clear__";function ka({isMobile:e,focusNodeId:t,shellOverlayFocusNodeId:n,lastRequestedKey:s}){const u=e?null:t,o=u??Kt;return o===(n??Kt)?{action:"none",nextRequestedKey:o}:s===o?{action:"none",nextRequestedKey:o}:{action:u?"set":"clear",nextRequestedKey:o}}const It="shrink-0 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2 py-0.5 text-[9px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)] shadow-[var(--ui-shadow-soft)] backdrop-blur",At="flex shrink-0 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-0.5 shadow-[var(--ui-shadow-soft)] backdrop-blur",tt="bg-[var(--ui-accent-soft)] text-[var(--primary)] shadow-[var(--ui-shadow-soft)]",rt="text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",fe="rounded-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] shadow-[var(--ui-shadow-soft)] backdrop-blur hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",Ka="fixed inset-0 z-40 bg-[color-mix(in_srgb,var(--ui-scrim)_72%,transparent)] backdrop-blur-xl",Ia="fixed inset-x-4 top-[max(1rem,env(safe-area-inset-top))] z-50 max-h-[calc(100dvh-2rem)] overflow-y-auto rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-floating)] md:left-1/2 md:right-auto md:-translate-x-1/2",Aa="sticky top-0 z-10 flex items-start justify-between gap-4 border-b border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-5 py-4 backdrop-blur-xl",Oa="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",Pa="font-display text-2xl text-[var(--ui-ink-strong)]",Ta="text-sm leading-6 text-[var(--ui-ink-soft)]",_e="grid min-w-0 gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",Re="text-sm font-medium text-[var(--ui-ink-strong)]",je="text-xs leading-5 text-[var(--ui-ink-faint)]",Ge="rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-2.5 py-1 text-xs text-[var(--ui-ink-soft)]",Da="rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-info-soft)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-soft)]";class za extends h.Component{constructor(t){super(t),this.state={error:null}}static getDerivedStateFromError(t){return{error:t}}componentDidUpdate(t){t.resetKey!==this.props.resetKey&&this.state.error!==null&&this.setState({error:null})}render(){return this.state.error?this.props.fallback(this.state.error):this.props.children}}function qa(){var Qe,$e;const e=Gr(),t=Pt();ct(a=>a.knowledgeGraphDiagnostics);const n=ct(a=>{var p,R;return((R=(p=a.shell.knowledgeGraphOverlayFocus)==null?void 0:p.focusNode)==null?void 0:R.id)??null}),s=nr(),[u,o]=sr(),c=h.useRef(null),l=h.useRef(null),i=h.useRef(null),m=h.useRef(null),g=h.useRef(null);h.useRef(Tt("/knowledge-graph"));const[b,G]=h.useState(()=>typeof window<"u"?window.matchMedia("(max-width: 1023px)").matches:!1),[f,N]=h.useState(!1),[k,_]=h.useState(!1),[z,M]=h.useState(!1),[L,me]=h.useState(!1),[F,ce]=h.useState(""),[A,xe]=h.useState(()=>Ea()),Me=Dt(),we=({level:a,eventKey:p,message:R,details:Ye,publishBackend:pt=!1})=>{};h.useEffect(()=>{if(typeof window>"u"||typeof window.matchMedia!="function")return;const a=window.matchMedia("(max-width: 1023px)"),p=R=>G(R?R.matches:a.matches);return p(),typeof a.addEventListener=="function"?(a.addEventListener("change",p),()=>a.removeEventListener("change",p)):(a.addListener(p),()=>a.removeListener(p))},[]),h.useEffect(()=>{b||(N(!1),_(!1),l.current=null)},[b]),h.useEffect(()=>{_a(A)},[A]);const $=u.toString(),Ne=h.useMemo(()=>Ga($),[$]),{selectedView:Y,focusNodeId:P,selectedKinds:te,selectedRelations:le,selectedTags:Fe,selectedOwners:Se,showHierarchyCrossLinks:Q,queryText:ue,updatedFrom:ye,updatedTo:de,maxNodes:pe}=Ne;h.useEffect(()=>{ce(ue)},[ue]);const H=h.useMemo(()=>Ma(Ne),[Ne]),he=h.useMemo(()=>["forge-knowledge-graph",...e.selectedUserIds,JSON.stringify(H)],[H,e.selectedUserIds]),V=yr({queryKey:he,queryFn:()=>Pr(e.selectedUserIds,H),placeholderData:a=>a,staleTime:6e4,refetchOnWindowFocus:!1}),y=V.data;h.useEffect(()=>{we({level:"info",eventKey:"route_arrival",message:"Arrived on the Knowledge Graph page.",details:{search:u.toString()}})},[]),h.useEffect(()=>{if(!V.isSuccess||!y)return;const a=JSON.stringify({q:H.q,entityKinds:H.entityKinds,relationKinds:H.relationKinds,tags:H.tags,owners:H.owners,updatedFrom:H.updatedFrom,updatedTo:H.updatedTo,limit:H.limit,nodeCount:y.counts.nodeCount,edgeCount:y.counts.edgeCount,filteredNodeCount:y.counts.filteredNodeCount,limited:y.counts.limited});g.current!==a&&(g.current=a,we({level:"info",eventKey:"graph_query_resolved",message:"Knowledge graph query resolved.",details:{nodeCount:y.counts.nodeCount,edgeCount:y.counts.edgeCount,filteredNodeCount:y.counts.filteredNodeCount,limited:y.counts.limited}}))},[y,V.isSuccess,H]),h.useEffect(()=>{!y||!P||y.nodes.some(a=>a.id===P)||(o(a=>{const p=new URLSearchParams(a);return p.delete("focus"),p},{replace:!0}),N(!1),l.current=null)},[P,y,o]),h.useEffect(()=>{if(b){if(!P){l.current=null,N(!1);return}l.current===P&&!f&&(N(!0),l.current=null)}},[P,b,f]);const B=h.useMemo(()=>!y||!P?Mt([],[],null):Mt(y.nodes,y.edges,P),[P,y]);h.useEffect(()=>{var p;const a=ka({isMobile:b,focusNodeId:((p=B.focusNode)==null?void 0:p.id)??null,shellOverlayFocusNodeId:n,lastRequestedKey:m.current});if(m.current=a.nextRequestedKey,a.action!=="none"){if(a.action==="clear"){t(xt());return}t(Mr(B))}},[t,B,b,n]),h.useEffect(()=>{{i.current=null;return}},[Me,P,B,b]),h.useEffect(()=>()=>{t(xt())},[t]),h.useEffect(()=>{if(!(typeof window>"u")){if(!Sa()){delete window.__FORGE_KNOWLEDGE_GRAPH_PAGE_TEST__;return}return window.__FORGE_KNOWLEDGE_GRAPH_PAGE_TEST__={isMobile:b,mobileSheetOpen:f,focusNodeId:P,selectedView:Y,selectNodeById:a=>{if(!y)return;const p=a?y.nodes.find(R=>R.id===a)??null:null;Ce(p)},activateFocusedNode:()=>{if(!P||!y)return;const a=y.nodes.find(p=>p.id===P)??null;a&&Ce(a)}},()=>{delete window.__FORGE_KNOWLEDGE_GRAPH_PAGE_TEST__}}},[P,b,f,Y]);const w=a=>{o(p=>{const R=new URLSearchParams(p);return a(R),R},{replace:!0})},We=a=>{const p=a.trim();ce(a),w(R=>{p.length>0?R.set("q",p):R.delete("q")})},Ce=a=>{const p=Fa({isMobile:b,currentFocusNodeId:P,nextNodeId:(a==null?void 0:a.id)??null});l.current=b&&p.nextMobileSheetOpen?(a==null?void 0:a.id)??null:null,N(p.nextMobileSheetOpen),p.shouldUpdateFocus&&(w(R=>{kt(R,a)}),b&&_(!1))},ke=a=>{a.href&&s(a.href)},re=(a,p)=>{xe(R=>tr({...R,[a]:p}))},Te=a=>{const p=Ca(a);p&&s(p)},De=a=>{w(p=>{p.set("view","hierarchy"),kt(p,a)})},ze=()=>{w(a=>{["q","entityKind","relationKind","tag","owner","updatedFrom","updatedTo","focus"].forEach(p=>a.delete(p)),a.set("limit",String(nt))}),M(!1)};if(V.isLoading&&!y)return r.jsx(Fr,{eyebrow:"Knowledge Graph",title:"Loading the Forge world model",description:"Gathering goals, projects, KarpaWiki pages, psyche entities, calendar context, and Workbench flows into one graph."});if(V.isError)return r.jsx(kr,{eyebrow:"Knowledge Graph",error:V.error,onRetry:()=>void V.refetch()});if(!y)return null;const T=new Map(y.facets.entityKinds.map(a=>[a.value,a])),ge=ot.map(a=>{const p=Kr(a),R=T.get(a),Ye=(R==null?void 0:R.count)??0;return{value:a,label:(R==null?void 0:R.label)??p.label,description:Ye===1?"1 node":`${Ye} nodes`,kind:a}}),q=y.facets.relationKinds.map(a=>({value:a.value,label:a.label,description:`${a.count} links`})),ae=y.facets.tags.map(a=>({value:a.id,label:a.label,description:`${a.count} linked nodes`,badge:r.jsx(at,{kind:"tag",label:a.label,compact:!0,gradient:!1}),menuBadge:r.jsx(at,{kind:"tag",label:a.label,compact:!0,gradient:!1})})),ne=y.facets.owners.map(a=>{const p=Ra(e.snapshot.users,a.userId,a.displayName,a.kind,a.accentColor);return{value:a.userId,label:a.displayName,description:`${a.count} nodes`,badge:r.jsx(yt,{user:p,compact:!0}),menuBadge:r.jsx(yt,{user:p,compact:!0})}}),Ue=[...ge.map(a=>({id:`entity:${a.value}`,label:a.label,description:a.description,searchText:`entity kind ${a.label}`,badge:r.jsx(at,{kind:a.kind??"note",label:a.label,compact:!0,gradient:!1})})),...q.map(a=>({id:`relation:${a.value}`,label:a.label,description:a.description,searchText:`relation kind ${a.label}`})),...ae.map(a=>({id:`tag:${a.value}`,label:a.label,description:a.description,searchText:`tag ${a.label}`,badge:a.menuBadge??a.badge})),...ne.map(a=>({id:`owner:${a.value}`,label:a.label,description:a.description,searchText:`owner ${a.label}`,badge:a.menuBadge??a.badge}))],se=ja({entityKinds:te,relationKinds:le,tags:Fe,owners:Se}),Le=y.counts.limited?`${y.counts.nodeCount}/${y.counts.filteredNodeCount} nodes`:`${y.counts.nodeCount}n · ${y.counts.edgeCount}e`,D=y.counts.limited?`${y.counts.nodeCount} visible nodes from ${y.counts.filteredNodeCount} filtered matches`:`${y.counts.nodeCount} nodes and ${y.counts.edgeCount} edges`,st=ue.trim().length>0||te.length>0||le.length>0||Fe.length>0||Se.length>0||!!ye||!!de||pe!==nt,be=!b,qe=`${Y}:${y.nodes.map(a=>a.id).join("|")}::${y.edges.map(a=>a.id).join("|")}`;return r.jsxs("div",{className:"h-[calc(100dvh-var(--forge-mobile-nav-clearance)-5.25rem)] overflow-hidden lg:-mt-3 lg:h-[calc(100dvh-10rem)]",children:[r.jsxs("div",{className:"relative h-full bg-[var(--ui-surface-0)]",children:[r.jsx("div",{className:"pointer-events-auto absolute right-3 top-3 z-30 hidden md:block",children:r.jsx(Ir,{metrics:e.snapshot.metrics})}),r.jsx(za,{resetKey:qe,fallback:a=>r.jsx("div",{className:"grid h-full place-items-center p-6 text-center",children:r.jsxs("div",{className:"grid max-w-lg gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 shadow-[var(--ui-shadow-floating)]",children:[r.jsx("div",{className:"mx-auto flex size-12 items-center justify-center rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:r.jsx(ir,{className:"size-5"})}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Graph renderer fallback"}),r.jsx("h2",{className:"text-lg font-semibold text-[var(--ui-ink-strong)]",children:"The graph renderer hit a display error."}),r.jsx("p",{className:"text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Switch to the hierarchy view or reset the current graph filters. The graph will recover automatically when the dataset changes."}),r.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-left text-xs text-[var(--ui-ink-faint)]",children:a.message})]}),r.jsxs("div",{className:"flex flex-wrap justify-center gap-2",children:[r.jsxs(W,{variant:"primary",size:"sm",onClick:()=>w(p=>{p.set("view","hierarchy")}),children:[r.jsx(or,{className:"size-4"}),"Open hierarchy"]}),r.jsx(W,{variant:"secondary",size:"sm",onClick:ze,children:"Reset graph filters"})]})]})}),children:Y==="graph"?r.jsx(xa,{ref:c,nodes:y.nodes,edges:y.edges,focusNodeId:P,physicsSettings:A,onSelectNode:Ce}):r.jsx("div",{className:"h-full overflow-y-auto px-4 py-4 lg:px-6",children:r.jsx(Na,{nodes:y.nodes,edges:y.edges,focusNodeId:P,showSecondaryEdges:Q,isMobile:b,onSelectNode:Ce,onOpenNode:Ce,onNavigateNode:ke})})}),b?r.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 z-20 px-3 pt-2 lg:hidden",children:r.jsxs("div",{className:"pointer-events-auto flex items-center gap-1.5",children:[r.jsx("div",{title:D,className:It,children:Le}),r.jsxs("div",{className:"ml-auto flex items-center gap-1.5",children:[r.jsxs("div",{className:At,children:[r.jsx("button",{type:"button",className:`rounded-full px-2 py-1 text-[10px] transition ${Y==="graph"?tt:rt}`,onClick:()=>w(a=>{a.set("view","graph")}),children:"Graph"}),r.jsx("button",{type:"button",className:`rounded-full px-2 py-1 text-[10px] transition ${Y==="hierarchy"?tt:rt}`,onClick:()=>w(a=>{a.set("view","hierarchy")}),children:"Hierarchy"})]}),r.jsx(W,{variant:"secondary",size:"sm",className:`h-7 px-2 text-[10px] ${fe}`,onClick:()=>me(!0),"aria-label":"Open graph appearance settings",title:"Graph appearance settings",children:r.jsx(gt,{className:"size-3"})}),r.jsxs(W,{variant:"secondary",size:"sm",className:`h-7 px-2 text-[10px] ${fe}`,onClick:()=>{N(!1),_(!0)},"aria-label":"Open graph filters",children:[r.jsx(ft,{className:"size-3"}),"Search"]})]})]})}):null,be?r.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 z-20 px-4 pt-3 lg:px-6",children:[r.jsxs("div",{"data-testid":"knowledge-graph-desktop-toolbar",className:"pointer-events-auto flex items-center gap-1.5",children:[r.jsx("div",{"data-testid":"knowledge-graph-count-pill",title:D,className:It,children:Le}),r.jsx("div",{className:"min-w-0 flex-1",children:r.jsx(vt,{title:"",description:"",compact:!0,minimal:!0,hideSummary:!0,query:F,onQueryChange:ce,onQuerySubmit:We,submitLabel:"Search graph",options:Ue,selectedOptionIds:se,onSelectedOptionIdsChange:a=>{const p=Ft(a);w(R=>{U(R,"entityKind",p.entityKinds),U(R,"relationKind",p.relationKinds),U(R,"tag",p.tags),U(R,"owner",p.owners)})},resultSummary:"",placeholder:"Type a graph search, then press Enter or the search button"})}),r.jsxs(W,{variant:"secondary",size:"sm",className:`h-7 px-2 text-[10px] ${fe}`,onClick:()=>M(a=>!a),children:[r.jsx(ft,{className:"size-3"}),"Advanced"]}),st?r.jsx(W,{variant:"secondary",size:"sm",className:`h-7 px-2 text-[10px] ${fe}`,onClick:ze,children:"Reset"}):null]}),r.jsx(Hr,{initial:!1,children:z?r.jsx(Vr.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},transition:{duration:.18,ease:"easeOut"},className:"pointer-events-auto mt-2 ml-auto max-w-[min(54rem,calc(100%-3.5rem))] rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3 shadow-[var(--ui-shadow-floating)] backdrop-blur",children:r.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.4fr)_minmax(17rem,1fr)]",children:[r.jsxs("div",{className:"grid gap-3",children:[r.jsx(ve,{options:ge,selectedValues:te,onChange:a=>w(p=>{U(p,"entityKind",a)}),placeholder:"Filter by entity type",emptyMessage:"No entity kinds match the current graph."}),r.jsx(ve,{options:q,selectedValues:le,onChange:a=>w(p=>{U(p,"relationKind",a)}),placeholder:"Filter by relation type",emptyMessage:"No relation kinds match the current graph."}),r.jsx(ve,{options:ae,selectedValues:Fe,onChange:a=>w(p=>{U(p,"tag",a)}),placeholder:"Filter by tag",emptyMessage:"No tags are available in the current filtered graph."}),r.jsx(ve,{options:ne,selectedValues:Se,onChange:a=>w(p=>{U(p,"owner",a)}),placeholder:"Filter by owner",emptyMessage:"No owners match the current graph."})]}),r.jsxs("div",{className:"grid gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:[r.jsx("span",{children:"Max nodes shown"}),r.jsx("span",{children:pe})]}),r.jsx("input",{type:"range",min:lt,max:ut,step:20,value:pe,onChange:a=>w(p=>{p.set("limit",a.target.value)}),className:"w-full accent-[var(--secondary)]"}),r.jsx("div",{className:"text-xs text-[var(--ui-ink-faint)]",children:"The graph stays deterministic under the cap and focus mode redistributes the visible neighborhood around the selected node."})]}),r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Updated from"}),r.jsx(Je,{type:"date",value:Z(ye),min:Z(y.facets.updatedAt.min),max:Z(de??y.facets.updatedAt.max),onChange:a=>w(p=>{a.target.value?p.set("updatedFrom",a.target.value):p.delete("updatedFrom")})})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Updated to"}),r.jsx(Je,{type:"date",value:Z(de),min:Z(ye??y.facets.updatedAt.min),max:Z(y.facets.updatedAt.max),onChange:a=>w(p=>{a.target.value?p.set("updatedTo",a.target.value):p.delete("updatedTo")})})]})]}),Y==="hierarchy"?r.jsx(W,{variant:Q?"primary":"secondary",size:"sm",className:"h-8 rounded-full px-3 text-xs",onClick:()=>w(a=>{Q?a.delete("cross"):a.set("cross","1")}),children:Q?"Hide cross-links":"Show cross-links"}):null]})]})}):null})]}):null,b?null:r.jsx("div",{className:"pointer-events-none absolute bottom-5 left-4 z-20 lg:left-6",children:r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsxs("div",{className:`pointer-events-auto ${At}`,children:[r.jsx("button",{type:"button",className:`rounded-full px-2.5 py-1.5 text-[10px] transition ${Y==="graph"?tt:rt}`,onClick:()=>w(a=>{a.set("view","graph")}),children:"Graph"}),r.jsx("button",{type:"button",className:`rounded-full px-2.5 py-1.5 text-[10px] transition ${Y==="hierarchy"?tt:rt}`,onClick:()=>w(a=>{a.set("view","hierarchy")}),children:"Hierarchy"})]}),Y==="graph"?r.jsxs(r.Fragment,{children:[r.jsx(W,{variant:"secondary",size:"sm",className:`pointer-events-auto size-8 p-0 ${fe}`,onClick:()=>me(!0),title:"Graph appearance settings","aria-label":"Open graph appearance settings",children:r.jsx(gt,{className:"size-3.5"})}),r.jsx(W,{variant:"secondary",size:"sm",className:`pointer-events-auto size-8 p-0 ${fe}`,onClick:()=>{var a;return(a=c.current)==null?void 0:a.zoomIn()},title:"Zoom in","aria-label":"Zoom in",children:r.jsx(cr,{className:"size-3.5"})}),r.jsx(W,{variant:"secondary",size:"sm",className:`pointer-events-auto size-8 p-0 ${fe}`,onClick:()=>{var a;return(a=c.current)==null?void 0:a.zoomOut()},title:"Zoom out","aria-label":"Zoom out",children:r.jsx(lr,{className:"size-3.5"})}),r.jsx(W,{variant:"secondary",size:"sm",className:`pointer-events-auto size-8 p-0 ${fe}`,onClick:()=>{var a;return(a=c.current)==null?void 0:a.recenterOnFocus()},disabled:!B.focusNode,title:"Recenter","aria-label":"Recenter",children:r.jsx(ur,{className:"size-3.5"})}),r.jsx(W,{variant:"secondary",size:"sm",className:`pointer-events-auto size-8 p-0 ${fe}`,onClick:()=>{var a;return(a=c.current)==null?void 0:a.fit()},title:"Reset camera","aria-label":"Reset camera",children:r.jsx(dr,{className:"size-3.5"})}),null]}):null]})})]}),r.jsx(bt,{open:f&&!!B.focusNode,onOpenChange:N,eyebrow:"Knowledge Graph",title:((Qe=B.focusNode)==null?void 0:Qe.title)??"Focus node",description:(($e=B.focusNode)==null?void 0:$e.subtitle)??"Inspect the selected node and move deeper into the graph.",children:r.jsx(Ar,{focus:B,onOpenPage:a=>{N(!1),ke(a)},onOpenNotes:a=>{N(!1),Te(a)},onOpenHierarchy:a=>{N(!1),De(a)},onSelectNode:Ce,className:"border-0 bg-transparent p-0 shadow-none"})}),r.jsx(bt,{open:k,onOpenChange:_,eyebrow:"Knowledge Graph",title:"Filter graph",description:"Search the visible graph and adjust the focus cap without covering the canvas all the time.",children:r.jsxs("div",{className:"grid gap-4 pb-2",children:[r.jsx("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:r.jsx(vt,{title:"",description:"",compact:!0,query:F,onQueryChange:ce,onQuerySubmit:We,submitLabel:"Search graph",options:Ue,selectedOptionIds:se,onSelectedOptionIdsChange:a=>{const p=Ft(a);w(R=>{U(R,"entityKind",p.entityKinds),U(R,"relationKind",p.relationKinds),U(R,"tag",p.tags),U(R,"owner",p.owners)})},resultSummary:D,placeholder:"Type a graph search, then press Enter or the search button"})}),r.jsxs("div",{className:"grid gap-3",children:[r.jsx(ve,{options:ge,selectedValues:te,onChange:a=>w(p=>{U(p,"entityKind",a)}),placeholder:"Filter by entity type",emptyMessage:"No entity kinds match the current graph."}),r.jsx(ve,{options:q,selectedValues:le,onChange:a=>w(p=>{U(p,"relationKind",a)}),placeholder:"Filter by relation type",emptyMessage:"No relation kinds match the current graph."}),r.jsx(ve,{options:ae,selectedValues:Fe,onChange:a=>w(p=>{U(p,"tag",a)}),placeholder:"Filter by tag",emptyMessage:"No tags are available in the current filtered graph."}),r.jsx(ve,{options:ne,selectedValues:Se,onChange:a=>w(p=>{U(p,"owner",a)}),placeholder:"Filter by owner",emptyMessage:"No owners match the current graph."})]}),r.jsxs("div",{className:"grid gap-3 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:[r.jsxs("div",{className:"flex items-center justify-between gap-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:[r.jsx("span",{children:"Max nodes shown"}),r.jsx("span",{children:pe})]}),r.jsx("input",{type:"range",min:lt,max:ut,step:20,value:pe,onChange:a=>w(p=>{p.set("limit",a.target.value)}),className:"w-full accent-[var(--secondary)]"}),r.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[r.jsxs("div",{className:"grid gap-2",children:[r.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Updated from"}),r.jsx(Je,{type:"date",value:Z(ye),min:Z(y.facets.updatedAt.min),max:Z(de??y.facets.updatedAt.max),onChange:a=>w(p=>{a.target.value?p.set("updatedFrom",a.target.value):p.delete("updatedFrom")})})]}),r.jsxs("div",{className:"grid gap-2",children:[r.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Updated to"}),r.jsx(Je,{type:"date",value:Z(de),min:Z(ye??y.facets.updatedAt.min),max:Z(y.facets.updatedAt.max),onChange:a=>w(p=>{a.target.value?p.set("updatedTo",a.target.value):p.delete("updatedTo")})})]})]}),r.jsxs("div",{className:"flex gap-2",children:[r.jsx(W,{variant:"secondary",size:"sm",onClick:ze,children:"Reset"}),r.jsx(W,{variant:"primary",size:"sm",onClick:()=>_(!1),children:"Done"})]})]})]})}),r.jsx(pr,{open:L,onOpenChange:me,children:r.jsxs(hr,{children:[r.jsx(gr,{className:Ka}),r.jsxs(fr,{className:`${Ia} md:w-[min(40rem,calc(100vw-3rem))]`,children:[r.jsx(mr,{className:"sr-only",children:"Knowledge Graph appearance settings"}),r.jsx(xr,{className:"sr-only",children:"Tune the graph focus physics and appearance response."}),r.jsxs("div",{className:Aa,children:[r.jsxs("div",{className:"grid gap-1",children:[r.jsx("div",{className:Oa,children:"Graph appearance"}),r.jsx("div",{className:Pa,children:"Tune the focus field"}),r.jsx("p",{className:`max-w-xl ${Ta}`,children:"Shape how strongly a focused node opens its neighborhood and how far that pressure diffuses through connected hops."})]}),r.jsx(mt,{asChild:!0,children:r.jsx(Or,{"aria-label":"Close graph appearance settings"})})]}),r.jsxs("div",{className:"grid gap-4 px-5 py-5",children:[r.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Focused repulsion"}),r.jsx("div",{className:je,children:"Push nearby nodes apart more aggressively while the focused node stays anchored."})]}),r.jsx("div",{className:Ge,children:A.focusRepulsion.toFixed(2)})]}),r.jsx("input",{"aria-label":"Focused repulsion",type:"range",min:"0.6",max:String(Bt),step:"0.05",value:A.focusRepulsion,onChange:a=>re("focusRepulsion",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]}),r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Focus diffusion"}),r.jsx("div",{className:je,children:"Extend the focus field further through multi-hop neighbors and lengthen the reversible transition."})]}),r.jsx("div",{className:Ge,children:A.focusDiffusion.toFixed(2)})]}),r.jsx("input",{"aria-label":"Focus diffusion",type:"range",min:"0.6",max:String(Xt),step:"0.05",value:A.focusDiffusion,onChange:a=>re("focusDiffusion",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]}),r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Spring reduction max"}),r.jsx("div",{className:je,children:"Reduce edge spring constants most strongly around the focused node so its local neighborhood can open more freely."})]}),r.jsx("div",{className:Ge,children:A.focusSpringReductionMax.toFixed(2)})]}),r.jsx("input",{"aria-label":"Spring reduction max",type:"range",min:"0",max:String(Wt),step:"0.02",value:A.focusSpringReductionMax,onChange:a=>re("focusSpringReductionMax",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]}),r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Spring reduction diffusion"}),r.jsx("div",{className:je,children:"Spread that spring softening progressively through first-hop, second-hop, and more distant neighborhoods."})]}),r.jsx("div",{className:Ge,children:A.focusSpringReductionDiffusion.toFixed(2)})]}),r.jsx("input",{"aria-label":"Spring reduction diffusion",type:"range",min:"0.6",max:String(Ut),step:"0.05",value:A.focusSpringReductionDiffusion,onChange:a=>re("focusSpringReductionDiffusion",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]}),r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Edge spring strength"}),r.jsx("div",{className:je,children:"Lower this to loosen graph edges globally and let neighborhoods spread instead of snapping tightly inward."})]}),r.jsx("div",{className:Ge,children:A.edgeSpringStrength.toFixed(2)})]}),r.jsx("input",{"aria-label":"Edge spring strength",type:"range",min:String(qt),max:String(Qt),step:"0.05",value:A.edgeSpringStrength,onChange:a=>re("edgeSpringStrength",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]}),r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Gravity strength"}),r.jsx("div",{className:je,children:"Reduce this to weaken the global inward pull that compacts the whole graph toward the middle."})]}),r.jsx("div",{className:Ge,children:A.gravityStrength.toFixed(2)})]}),r.jsx("input",{"aria-label":"Gravity strength",type:"range",min:"0",max:String(Jt),step:"0.05",value:A.gravityStrength,onChange:a=>re("gravityStrength",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]}),r.jsxs("div",{className:_e,children:[r.jsxs("div",{className:"flex items-center justify-between gap-3",children:[r.jsxs("div",{children:[r.jsx("div",{className:Re,children:"Focus shell spacing"}),r.jsx("div",{className:je,children:"Increase this to push focused rings farther outward and visibly open the local structure."})]}),r.jsx("div",{className:Ge,children:A.focusShellSpacing.toFixed(2)})]}),r.jsx("input",{"aria-label":"Focus shell spacing",type:"range",min:String(Zt),max:String(er),step:"0.05",value:A.focusShellSpacing,onChange:a=>re("focusShellSpacing",Number(a.target.value)),className:"w-full accent-[var(--secondary)]"})]})]}),r.jsx("div",{className:Da,children:"The main cramming forces are the edge springs and the inward gravity pull. Lower edge spring strength or gravity strength to let the whole graph breathe more, then raise focus shell spacing and spring-reduction controls when you want a selected neighborhood to open dramatically."}),r.jsxs("div",{className:"flex flex-wrap justify-between gap-3",children:[r.jsx(W,{variant:"secondary",onClick:()=>xe(ee),children:"Reset defaults"}),r.jsx(mt,{asChild:!0,children:r.jsx(W,{variant:"primary",children:"Done"})})]})]})]})]})}),null]})}export{qa as KnowledgeGraphPage};
@@ -1 +0,0 @@
1
- import{j as t}from"./vendor-Dnkkx2co.js";import{L as i}from"./life-force-workspace-sszLD-Yn.js";import{u as o,aX as a}from"./index-QJkjKYzZ.js";import{P as s}from"./page-hero-CONuJu5J.js";import"./state-vCcAT5Hq.js";import"./floating-action-menu-cKjNsPYD.js";import"./charts-DFnEuIMB.js";import"./motion-Lt5B1XuE.js";import"./ui-C1iwpj2-.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function v(){const e=o(),r=e.snapshot.lifeForce;return r?t.jsxs("div",{className:"grid gap-4",children:[t.jsx(s,{title:"Life Force",titleText:"Life Force",description:"Edit weekday Action Point curves, inspect drains, and tune the capacity model without crowding the Overview surface.",badge:`${Math.round(r.spentTodayAp)} / ${Math.round(r.dailyBudgetAp)} AP`,actions:t.jsx(a,{users:e.snapshot.users,selectedUserIds:e.selectedUserIds,onChange:e.setSelectedUserIds})}),t.jsx(i,{selectedUserIds:e.selectedUserIds,fallbackLifeForce:r,onRefresh:e.refresh,showEditor:!0})]}):t.jsx("div",{className:"grid gap-4",children:t.jsx(s,{title:"Life Force",titleText:"Life Force",description:"Action Point capacity, weekday curves, and instant headroom editing live here.",badge:"Not calibrated yet"})})}export{v as LifeForcePage};
@@ -1 +0,0 @@
1
- import{r as x,j as e,aK as $t,c4 as It,bg as Et,cq as ga,c3 as fa,aZ as ot,cr as wt,F as Ua,bX as Wa,b4 as Ga,cs as ba,ct as Va,c7 as Ya,bc as Xa}from"./vendor-Dnkkx2co.js";import{j as ya,x as Yt,i as ae,k as Pe}from"./state-vCcAT5Hq.js";import{I as B,B as A,Z as w,c as v,C as k,aY as Xt,aZ as Zt,a_ as ja,a$ as Za,b0 as Ja,S as Na,E as ka,aT as wa,b1 as er,b2 as Jt,b3 as tr,b4 as Sa,b5 as ar,u as rr,b6 as sr,b7 as ir,b8 as at,h as ea,d as rt,b9 as nr,aq as ce,ba as lr,bb as or,bc as dr,bd as cr,be as ur,bf as mr,bg as xr,O as vr,bh as pr,bi as hr,bj as gr}from"./index-QJkjKYzZ.js";import{F as Ma}from"./faceted-token-search-CZmtyJTT.js";import{P as fr}from"./page-hero-CONuJu5J.js";import{R as Qe,P as Ue,O as We,C as Ge,T as mt,D as xt,a as vt}from"./ui-C1iwpj2-.js";import{m as ta}from"./motion-Lt5B1XuE.js";import{S as me}from"./surface-CyWI7e1R.js";import{R as br,A as yr,C as jr,X as Nr,Y as kr,T as wr,a as Sr}from"./charts-DFnEuIMB.js";import"./forms-hB0SqEh-.js";import"./board-dIX6etHh.js";import"./graph-DDUZNRsO.js";function Aa({open:t,onOpenChange:a,place:r,seed:s,onSave:l}){const[c,m]=x.useState({label:(r==null?void 0:r.label)??(s==null?void 0:s.label)??"",latitude:String((r==null?void 0:r.latitude)??(s==null?void 0:s.latitude)??""),longitude:String((r==null?void 0:r.longitude)??(s==null?void 0:s.longitude)??""),radiusMeters:String((r==null?void 0:r.radiusMeters)??(s==null?void 0:s.radiusMeters)??100),categoryTags:((r==null?void 0:r.categoryTags)??(s==null?void 0:s.categoryTags)??[]).join(", ")});return x.useEffect(()=>{m({label:(r==null?void 0:r.label)??(s==null?void 0:s.label)??"",latitude:String((r==null?void 0:r.latitude)??(s==null?void 0:s.latitude)??""),longitude:String((r==null?void 0:r.longitude)??(s==null?void 0:s.longitude)??""),radiusMeters:String((r==null?void 0:r.radiusMeters)??(s==null?void 0:s.radiusMeters)??100),categoryTags:((r==null?void 0:r.categoryTags)??(s==null?void 0:s.categoryTags)??[]).join(", ")})},[r,s]),e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(Ge,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(32rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-normal text-[var(--ui-ink-strong)]",children:r?`Edit ${r.label}`:"New known place"}),e.jsx(xt,{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Define life landmarks once so the companion and web views can reason about stays and trips consistently."})]}),e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:e.jsx($t,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(B,{value:c.label,onChange:d=>m(u=>({...u,label:d.target.value})),placeholder:"Home, Main Office, Riverside path..."}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(B,{value:c.latitude,onChange:d=>m(u=>({...u,latitude:d.target.value})),placeholder:"Latitude"}),e.jsx(B,{value:c.longitude,onChange:d=>m(u=>({...u,longitude:d.target.value})),placeholder:"Longitude"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[10rem_minmax(0,1fr)]",children:[e.jsx(B,{value:c.radiusMeters,onChange:d=>m(u=>({...u,radiusMeters:d.target.value})),placeholder:"Radius meters"}),e.jsx(B,{value:c.categoryTags,onChange:d=>m(u=>({...u,categoryTags:d.target.value})),placeholder:"home, gym, holiday, parents-house"})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(A,{variant:"ghost",onClick:()=>a(!1),className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",children:"Cancel"}),e.jsx(A,{onClick:()=>void l({id:r==null?void 0:r.id,label:c.label,latitude:Number(c.latitude),longitude:Number(c.longitude),radiusMeters:Number(c.radiusMeters),categoryTags:c.categoryTags.split(",").map(d=>d.trim()).filter(Boolean)}).then(()=>a(!1)),children:"Save place"})]})]})]})})}const St=1e3;function I(t){return new Date(t).getTime()}function Mt(t){return new Date(t).toISOString()}function aa(t,a){const r=I(t.startedAt)-I(a.startedAt);if(r!==0)return r;const s=I(t.endedAt)-I(a.endedAt);return s!==0?s:t.id.localeCompare(a.id)}function Ft(t){return t.syncSource==="sleep overlay"}function Mr(t){const a=[...t].filter(s=>I(s.endedAt)>I(s.startedAt)).sort((s,l)=>{const c=I(s.startedAt)-I(l.startedAt);if(c!==0)return c;const m=I(s.endedAt)-I(l.endedAt);return m!==0?m:s.id.localeCompare(l.id)});if(a.length===0)return[];const r=[];for(const s of a){const l=r.at(-1);if(!l){r.push(s);continue}const c=I(l.endedAt);if(I(s.startedAt)<=c+St){const d=Math.max(c,I(s.endedAt));r[r.length-1]={...l,id:`${l.id}__${s.id}`,endedAt:Mt(d),asleepSeconds:(l.asleepSeconds??0)+(s.asleepSeconds??0)||null,timeInBedSeconds:(l.timeInBedSeconds??0)+(s.timeInBedSeconds??0)||null,sleepScore:s.sleepScore??l.sleepScore,regularityScore:s.regularityScore??l.regularityScore,efficiency:s.efficiency??l.efficiency,recoveryState:s.recoveryState??l.recoveryState};continue}r.push(s)}return r}function Ar(t){const a=[];if(typeof t.asleepSeconds=="number"&&t.asleepSeconds>0){const r=t.asleepSeconds/3600;a.push(`${r.toFixed(r>=1?1:2)}h asleep`)}else if(typeof t.timeInBedSeconds=="number"&&t.timeInBedSeconds>0){const r=t.timeInBedSeconds/3600;a.push(`${r.toFixed(r>=1?1:2)}h in bed`)}return typeof t.sleepScore=="number"&&a.push(`score ${t.sleepScore}`),typeof t.regularityScore=="number"&&a.push(`regularity ${t.regularityScore}`),t.recoveryState&&a.push(t.recoveryState),a.join(" · ")||"Sleep session"}function Cr(t){const a=Math.max(60,Math.round((I(t.endedAt)-I(t.startedAt))/1e3));return{id:`sleep-overlay-${t.id}`,boxId:`sleep-overlay-${t.id}`,kind:"stay",sourceKind:"automatic",origin:"recorded",editable:!1,isInvalid:!1,startedAt:t.startedAt,endedAt:t.endedAt,trueStartedAt:t.startedAt,trueEndedAt:t.endedAt,visibleStartedAt:t.startedAt,visibleEndedAt:t.endedAt,durationSeconds:a,laneSide:"left",connectorFromLane:"left",connectorToLane:"left",title:"Sleep",subtitle:Ar(t),placeLabel:null,tags:["sleep"],syncSource:"sleep overlay",cursor:`${t.endedAt}::sleep-overlay-${t.id}`,overrideCount:0,overriddenAutomaticBoxIds:[],overriddenUserBoxIds:[],isFullyHidden:!1,rawStayIds:[],rawTripIds:[],rawPointCount:0,hasLegacyCorrections:!1,stay:null,trip:null}}function ra(t,a,r){if(r<=a)return null;const s=Mt(a),l=Mt(r),c=Math.max(60,Math.round((r-a)/1e3));return{...t,id:`${t.id}::virtual-${a}-${r}`,startedAt:s,endedAt:l,trueStartedAt:s,trueEndedAt:l,visibleStartedAt:s,visibleEndedAt:l,durationSeconds:c,cursor:`${l}::${t.id}::virtual`}}function Tr(t,a){let r=[...t].sort(aa);for(const s of Mr(a)){const l=I(s.startedAt),c=I(s.endedAt),m=Cr(s),d=[];let u=!1;for(const p of r){const g=I(p.startedAt),j=I(p.endedAt);if(j<=l||g>=c){!u&&g>=c&&(d.push(m),u=!0),d.push(p);continue}if(g<l){const P=ra(p,g,Math.min(j,l-St));P&&d.push(P)}if(u||(d.push(m),u=!0),j>c){const P=ra(p,Math.max(g,c+St),j);P&&d.push(P)}}u||d.push(m),r=d.sort(aa)}return r}const sa=24,X=64,At=360*60,Ca=5,Nt=1,Pr=104,ia=X*8;function he(t){return t.trim().toLowerCase()}function qe(t){return t>=86400?`${Math.round(t/3600)}h`:t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.max(1,Math.round(t/60))}m`}function ge(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ta(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit"}).format(new Date(t))}function Dr(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:!1}).format(t)}function $e(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const r=a.getFullYear(),s=String(a.getMonth()+1).padStart(2,"0"),l=String(a.getDate()).padStart(2,"0"),c=String(a.getHours()).padStart(2,"0"),m=String(a.getMinutes()).padStart(2,"0");return`${r}-${s}-${l}T${c}:${m}`}function dt(t){if(!t.trim())return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toISOString()}function Ie(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Y(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function na(t,a){return`${t.toFixed(3)}, ${a.toFixed(3)}`}function st(t,a){return`${t.toFixed(6)}, ${a.toFixed(6)}`}function la(t){return`${Math.max(1,Math.round(t/60))} min`}function Lr(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),r=Math.max(...t.map(d=>d.latitude)),s=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(r-a,1e-4),m=Math.max(l-s,1e-4);return t.map((d,u)=>({...d,x:12+(d.longitude-s)/m*76,y:12+(1-(d.latitude-a)/c)*76,id:`${d.recordedAt??"point"}-${u}`}))}function ct(t){return t.kind==="trip"&&t.trip!==null}function le(t){return t.kind==="stay"&&t.stay!==null}function Ct(t){return!le(t)||t.stay.place?null:{label:t.stay.label||t.title,latitude:t.stay.centerLatitude,longitude:t.stay.centerLongitude,radiusMeters:t.stay.radiusMeters,categoryTags:t.tags}}function Ee(t){var a;return t?t.kind==="stay"&&le(t)?((a=t.stay.place)==null?void 0:a.label)??t.placeLabel??t.stay.label??null:t.placeLabel??null:null}function lt(t,a,r,s){const c=(r-t)*Math.PI/180,m=(s-a)*Math.PI/180,d=t*Math.PI/180,u=r*Math.PI/180,p=Math.sin(c/2)**2+Math.cos(d)*Math.cos(u)*Math.sin(m/2)**2;return 2*6371e3*Math.asin(Math.sqrt(p))}function $r(t){return he([t.label,...t.aliases].join(" "))}function we(t,a,r){if(!t.trip)return{label:t.placeLabel??(a==="start"?"Known origin":"Known destination"),detail:Y(a==="start"?t.startedAt:t.endedAt)};const s=a==="start"?t.trip.points[0]??null:t.trip.points[t.trip.points.length-1]??null,l=a==="start"?t.trip.startPlace:t.trip.endPlace,c=(r==null?void 0:r.includeCoordinates)??!0,m=r!=null&&r.useHistoryAnchorFallback&&a==="start"?"Beginning of history":null;return{label:(l==null?void 0:l.label)??m??(c&&s?na(s.latitude,s.longitude):a==="start"?"Unknown origin":"Unknown destination"),detail:c&&s&&!l?na(s.latitude,s.longitude):Y(a==="start"?t.startedAt:t.endedAt)}}function Ir(t){const a=t.trim().toLowerCase();return a==="travel"||a==="trip"||a==="move"}function Er(t){const a=t.title.trim().toLowerCase();return a.length===0||a==="stay"||a==="continued stay"||a==="repaired stay"?t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated movement":"User-defined missing data":"Missing data":t.title}function Fr(t){const a=Ee(t),r=t.title.trim().toLowerCase(),s=r.length===0||r==="stay"||r==="continued stay"||r==="repaired stay"||r==="manual stay";return a&&s?a:t.title.trim()||a||"Stay"}function ue(t){if(Ft(t))return"Sleep";if(t.kind==="missing")return Er(t);if(t.kind==="stay")return Fr(t);if(t.kind==="trip"&&Ir(t.title)){const a=we(t,"start").label,r=we(t,"end").label;return`${a} → ${r}`}return t.title}function oa(t){return t==="left"?24:t==="right"?76:50}function _r(t,a,r){const s=Math.min(t,At)/3600,l=r==="sleep overlay",c=l?112:a==="stay"?104:92,m=l?272:a==="stay"?288:232,d=c+s*30;return Math.max(c,Math.min(m,d))}function Tt(t){var a;return{kind:t.kind,label:le(t)?t.stay.label||t.title:ct(t)&&t.trip.label||t.title,placeLabel:le(t)?((a=t.stay.place)==null?void 0:a.label)??t.placeLabel??"":"",tagsInput:t.tags.join(", "),startedAtInput:$e(t.startedAt),endedAtInput:$e(t.endedAt)}}function kt(t,a){const r=(a==null?void 0:a.startedAt)??new Date(Date.now()-36e5).toISOString(),s=(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t,label:t==="missing"?"User-defined missing data":t==="stay"?(a==null?void 0:a.placeLabel)||"Manual stay":"Manual move",placeLabel:(a==null?void 0:a.placeLabel)??"",tagsInput:t==="missing"?"user-defined, missing-data":t==="stay"?"user-defined, stay":"user-defined, move",startedAtInput:$e(r),endedAtInput:$e(s)}}function Pt(t,a){var c,m;const r=t.tagsInput.split(",").map(d=>d.trim()).filter(Boolean),s=dt(t.startedAtInput)??(a==null?void 0:a.startedAt)??new Date(Date.now()-3600*1e3).toISOString(),l=dt(t.endedAtInput)??(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t.kind,startedAt:s,endedAt:l,title:t.label.trim(),subtitle:t.kind==="missing"?"User-defined missing-data override.":"User-defined movement box.",placeLabel:t.placeLabel.trim()||null,tags:r,distanceMeters:t.kind==="trip"?Math.max(((c=a==null?void 0:a.trip)==null?void 0:c.distanceMeters)??150,150):null,averageSpeedMps:t.kind==="trip"?((m=a==null?void 0:a.trip)==null?void 0:m.averageSpeedMps)??null:null,metadata:{createdFrom:"movement-life-timeline"}}}function Rr(t,a){var l,c;const r=t.kind==="stay"?((c=(l=t.stay)==null?void 0:l.label)==null?void 0:c.trim())??"":"";if(r)return r;const s=t.title.trim();return s&&s.toLowerCase()!=="stay"?s:a.trim()||"Stay"}function zr(t,a){const r=Tt(t),s=a.trim();return Pt({...r,label:Rr(t,s),placeLabel:s},t)}function Pa(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function ut(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Or(t){var a,r,s;return he([t.kind,ue(t),t.subtitle,t.placeLabel??"",...t.tags,ut(t.startedAt),ut(t.endedAt),Pa(t.startedAt),le(t)?((a=t.stay.place)==null?void 0:a.label)??t.stay.label:ct(t)?[t.trip.label,t.trip.activityType,t.trip.travelMode,(r=t.trip.startPlace)==null?void 0:r.label,(s=t.trip.endPlace)==null?void 0:s.label].filter(Boolean).join(" "):t.kind==="trip"?[t.title,t.subtitle,t.placeLabel??""].filter(Boolean).join(" "):"missing data gap"].join(" "))}function Hr(t){const a=new Map;a.set("kind:stay",{id:"kind:stay",label:"Stay",description:"Stationary spans and place anchors."}),a.set("kind:trip",{id:"kind:trip",label:"Move",description:"Trips and movement connectors."});for(const r of["night","morning","afternoon","evening"])a.set(`time:${r}`,{id:`time:${r}`,label:r[0].toUpperCase()+r.slice(1),description:"Filter by the segment start time."});for(const r of t){for(const s of r.tags)a.set(`tag:${s}`,{id:`tag:${s}`,label:s,description:"Movement tag"});r.placeLabel&&a.set(`place:${r.placeLabel}`,{id:`place:${r.placeLabel}`,label:r.placeLabel,description:"Matched place"})}return[...a.values()].sort((r,s)=>r.label.localeCompare(s.label))}function Br(t,a){return a.every(r=>r==="kind:stay"||r==="kind:trip"?t.kind===r.slice(5):r.startsWith("time:")?Pa(t.startedAt)===r.slice(5):r.startsWith("tag:")?t.tags.includes(r.slice(4)):r.startsWith("place:")?(t.placeLabel??"")===r.slice(6):!0)}function da(t,a){return t&&{...t,pages:t.pages.map(r=>({...r,segments:r.segments.filter(s=>s.id!==a)}))}}function Kr(t,a){const r=t+(Math.sin((t-.5)*Math.PI)+1)*.5-t,s=t-.5,c=.5+(s*(1-a*.64)+s*s*s*a*2.56);return Math.max(0,Math.min(1,c-(r-t)*a*.08))}function qr(t){return t.getHours()===0?Ta(t.toISOString()):Dr(t)}function Qr(t,a){const r=new Date(t.endedAt).getTime(),s=new Date(t.startedAt).getTime(),l=Math.max(1,r-s),c=Math.max(0,Math.min(1,(a-s)/l));if(t.durationSeconds<=At)return c;const m=Math.max(0,1-Math.min(1,At/Math.max(1,t.durationSeconds)));return Kr(c,m)}function Ur(t,a,r){if(t.items.length===0)return null;const s=t.items[0];if(a<new Date(s.segment.startedAt).getTime())return t.historyHeaderHeight+t.leadHeight-(new Date(s.segment.startedAt).getTime()-a)/36e5*X;for(let m=0;m<t.items.length;m+=1){const d=t.items[m],u=new Date(d.segment.startedAt).getTime(),p=new Date(d.segment.endedAt).getTime();if(a>=u&&a<=p)return d.boxTop+Qr(d.segment,a)*d.displayHeight;const g=t.items[m+1]??null,j=g?new Date(g.segment.startedAt).getTime():r;if(a>p&&a<j)return d.boxBottom+(a-p)/36e5*X}const l=t.items[t.items.length-1],c=new Date(l.segment.endedAt).getTime();return a>=c?l.boxBottom+(a-c)/36e5*X:null}function Wr(t){const a=new Date(t);a.setMinutes(0,0,0);const r=a.getTime();return r<=t?r+36e5:r}function Gr(t,a){const r=[];if(t.items.length===0)return r;const s=t.items[0],l=new Date(s.segment.startedAt).getTime();for(let c=Wr(l-Ca*36e5);c<=a;c+=36e5){const m=Ur(t,c,a);if(m===null)continue;const d=new Date(c);r.push({y:m,label:qr(d),strong:d.getHours()===0})}return r}function Vr({segments:t,viewportHeight:a,nowMs:r=Date.now()}){var U;const s=t.length>0?Pr:0,l=t.length>0?X*Ca:0;let c=s+l,m=null;const d=t.map(b=>{const C=_r(b.durationSeconds,b.kind,b.syncSource),F=new Date(b.startedAt).getTime(),K=m===null?0:Math.max(0,(F-m)/36e5)*X;c+=K;const Z=c,z=Z+C;return c=z,m=new Date(b.endedAt).getTime(),{id:b.id,segment:b,gapBefore:K,displayHeight:C,boxTop:Z,boxBottom:z}}),u=r+Nt*36e5,p=(()=>{var F;const b=(F=t[t.length-1])==null?void 0:F.endedAt;if(!b)return X*Nt;const C=new Date(b).getTime();return Math.max(X*Nt,(u-C)/36e5*X)})(),g=(((U=d[d.length-1])==null?void 0:U.boxBottom)??s+l)+p,j=Math.max(g,a>0?a+260:960,s+l+p),P={historyHeaderHeight:s,leadHeight:l,items:d,markers:[],rangeEndMs:u,futureTailHeight:p+Math.max(0,j-g),totalHeight:j};return{...P,markers:Gr(P,u)}}const Yr="bg-[image:var(--ui-surface-section)]",Xr="bg-[image:var(--ui-surface-section)]",Zr="h-6 w-[3px] rounded-full bg-[var(--info)] shadow-[var(--ui-shadow-soft)]",Jr="relative w-[min(18rem,calc(100vw-6rem))] overflow-hidden rounded-[26px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[image:var(--ui-surface-section)] shadow-[var(--ui-shadow-soft)]",es="absolute z-10 h-7 w-8 rounded-[12px] border bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-soft)] backdrop-blur-sm",ts="group absolute top-1/2 max-w-[min(8rem,calc(100vw-8rem))] -translate-y-1/2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] px-2.5 py-2 text-left shadow-[var(--ui-shadow-soft)] backdrop-blur-sm transition hover:border-[var(--ui-border-strong)] sm:max-w-[9rem] sm:px-3",Dt="ring-1 ring-[color-mix(in_srgb,var(--info)_42%,transparent)]",as="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",Da="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",Te="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",rs="border-[color-mix(in_srgb,var(--danger)_26%,transparent)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)] hover:bg-[color-mix(in_srgb,var(--danger)_18%,transparent)]",ss="border-[color-mix(in_srgb,var(--warning)_26%,transparent)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)] hover:bg-[color-mix(in_srgb,var(--warning)_18%,transparent)]";function is({layout:t,scrollTop:a,viewportHeight:r}){const s=X*6,l=Math.max(0,a-s),c=Math.min(t.totalHeight,a+Math.max(r,X*8)+s),m=t.markers.filter(d=>d.y>=l&&d.y<=c);return e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 overflow-hidden rounded-[30px]",style:{height:`${t.totalHeight}px`},children:[e.jsx("div",{className:w("absolute inset-y-0 left-0 w-18",Yr)}),m.map((d,u)=>e.jsxs("div",{className:"absolute inset-x-0",style:{top:`${d.y}px`},children:[e.jsx("div",{className:w("border-t",(d.strong,"border-[var(--ui-border-subtle)]"))}),e.jsx("div",{className:w("absolute left-3 top-0 -translate-y-1/2 font-label text-[9px] tracking-[0.24em]",(d.strong,"text-[var(--ui-ink-muted)]")),children:d.label})]},`timeline-grid-${u}`))]})}function ns({fromSide:t,toSide:a,height:r,emphasized:s}){const l=oa(t),c=oa(a),m=`M ${l} 16 C ${l} ${Math.max(40,r*.26)}, ${c} ${Math.max(70,r*.72)}, ${c} ${r-18}`;return e.jsxs("svg",{viewBox:`0 0 100 ${r}`,className:"absolute inset-x-0 top-0 h-full w-full overflow-visible",preserveAspectRatio:"none",children:[e.jsx("path",{d:m,fill:"none",stroke:s?"color-mix(in srgb, var(--ui-ink-strong) 18%, transparent)":"color-mix(in srgb, var(--ui-ink-strong) 11%, transparent)",strokeWidth:s?"1.05":"0.85",strokeDasharray:s?"3 10":"2.5 12",strokeLinecap:"round"}),e.jsx("circle",{cx:l,cy:"16",r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"}),e.jsx("circle",{cx:c,cy:r-18,r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"})]})}function Lt({position:t}){return e.jsx("div",{className:w("absolute left-1/2 z-20 flex -translate-x-1/2 items-center justify-center",t==="top"?"-top-3":"-bottom-3"),children:e.jsx("div",{className:Zr})})}function ls({segment:t}){const a=(t==null?void 0:t.kind)==="stay"?t.placeLabel||t.title||null:(t==null?void 0:t.kind)==="trip"?we(t,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}).label:null,r=a||"Beginning of time";return e.jsx("div",{className:"pointer-events-none flex justify-center px-6 py-4",children:e.jsxs("div",{className:Jr,children:[e.jsx(Lt,{position:"bottom"}),e.jsxs("div",{className:"relative z-10 px-5 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(v,{tone:"signal",className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",children:"Start"}),e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Beginning of history"})]}),e.jsx("div",{className:"mt-5 font-display text-[1.25rem] tracking-normal text-[var(--ui-ink-strong)]",children:r}),e.jsx("div",{className:"mt-2 font-label text-[10px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:a?"Oldest loaded known stay":"Earliest known anchor"})]})]})})}function os(t,a,r){const s=a+Math.max(96,Math.min(r*.28,220)),l=t.items.find(c=>c.boxBottom>=s)??t.items[t.items.length-1]??null;return l?Ta(l.segment.startedAt):null}function ca({side:t,vertical:a,emphasized:r=!1}){return e.jsx("div",{className:w(es,r?"border-[color-mix(in_srgb,var(--info)_34%,transparent)]":"border-[var(--ui-border-subtle)]",t==="left"?"left-[8%]":t==="right"?"right-[8%]":"left-1/2 -translate-x-1/2",a==="top"?"top-0":"bottom-0")})}function ds({layout:t,selected:a,onToggle:r}){var u,p,g,j;const{segment:s}=t,l=Ft(s),c=t.displayHeight,m=s.kind==="stay"?l?"bg-[var(--ui-info-soft)] border-[color-mix(in_srgb,var(--info)_28%,transparent)]":"bg-[var(--ui-accent-soft)] border-[color-mix(in_srgb,var(--primary)_24%,transparent)]":"",d=s.kind==="trip"?{start:we(s,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}),end:we(s,"end",{includeCoordinates:!1})}:null;return e.jsxs("div",{className:w("absolute left-0 w-full px-3 sm:px-6",a?"z-40":"z-10"),"data-testid":"movement-timeline-row","data-selected":a?"true":"false",style:{top:`${t.boxTop}px`,height:`${c}px`},children:[e.jsx("div",{className:w("absolute inset-y-0 left-1/2 w-px -translate-x-1/2",Xr)}),e.jsx("div",{className:"relative h-full",children:s.kind==="trip"?e.jsxs(ta.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:240,damping:30},className:"absolute inset-x-0 top-0 z-10 h-full",children:[d&&a?e.jsxs(e.Fragment,{children:[e.jsx(ca,{side:"center",vertical:"top",emphasized:!0}),e.jsx(ca,{side:"center",vertical:"bottom",emphasized:!0})]}):null,e.jsx(ns,{fromSide:"center",toSide:"center",height:c,emphasized:a}),e.jsxs("button",{type:"button",onClick:r,className:w(ts,"left-1/2 -translate-x-1/2",a?Dt:""),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Move"}),e.jsx("div",{className:"text-[11px] tracking-[0.18em] text-[var(--ui-ink-strong)]/44",children:qe(s.durationSeconds)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:Ie(((u=s.trip)==null?void 0:u.distanceMeters)??0)}),(((p=s.trip)==null?void 0:p.stops.length)??0)>0?e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[(g=s.trip)==null?void 0:g.stops.length," stop",((j=s.trip)==null?void 0:j.stops.length)===1?"":"s"]}):null]}),e.jsxs("div",{className:"mt-2 font-label text-[9px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:[Y(s.startedAt)," →"," ",Y(s.endedAt)]})]})]}):e.jsx(ta.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:260,damping:28},className:"absolute left-1/2 top-0 z-10 w-[min(18.5rem,calc(100vw-3.25rem))] -translate-x-1/2 sm:w-[min(21rem,calc(100vw-5rem))]",children:e.jsxs("button",{type:"button",onClick:r,className:w("group relative w-full overflow-hidden rounded-[24px] border text-left shadow-[var(--ui-shadow-soft)] transition sm:rounded-[30px]",m,a?Dt:"hover:border-[var(--ui-border-strong)]"),style:{minHeight:`${c}px`},children:[e.jsx(Lt,{position:"top"}),e.jsx(Lt,{position:"bottom"}),e.jsxs("div",{className:"relative z-10 flex h-full flex-col justify-between p-3.5 sm:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(v,{tone:"signal",className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",children:l?"Sleep":"Stay"}),e.jsx("div",{className:"text-[11px] tracking-[0.16em] text-[var(--ui-ink-muted)] sm:text-xs sm:tracking-[0.18em]",children:qe(s.durationSeconds)})]}),e.jsxs("div",{className:"mt-3 min-w-0 sm:mt-5",children:[e.jsx("div",{className:"truncate font-display text-[1rem] tracking-normal text-[var(--ui-ink-strong)] sm:text-[1.12rem]",children:ue(s)}),s.kind==="stay"&&Ee(s)&&!l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(v,{className:"max-w-full truncate bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:Ee(s)})}):l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(v,{className:w("max-w-full truncate",Da),children:s.subtitle})}):null]}),e.jsx("div",{className:"mt-auto pt-4 sm:pt-8",children:e.jsxs("div",{className:"font-label text-[9px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)] sm:text-[10px] sm:tracking-[0.22em]",children:[Y(s.startedAt)," →"," ",Y(s.endedAt)]})})]})]})})})]})}const cs="rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",it="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",nt="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",ua="text-sm leading-6 text-[var(--ui-ink-medium)]",Ne="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",ma="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",xa="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",us="bg-[var(--ui-accent-soft)] text-[var(--primary)]",ms="mt-4 rounded-[18px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[var(--ui-info-soft)] p-3",xs="text-[11px] uppercase tracking-[0.18em] text-[color-mix(in_srgb,var(--info)_70%,var(--ui-ink-strong)_30%)]",vs="mt-2 text-sm leading-6 text-[var(--ui-ink-medium)]",ps="rounded-full border border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] px-4 text-[color-mix(in_srgb,var(--info)_72%,var(--ui-ink-strong)_28%)] hover:bg-[color-mix(in_srgb,var(--info)_18%,transparent)]";function hs({segment:t,onEdit:a,onOpenDetail:r,onDefinePlace:s,onClose:l}){var d;const c=Ft(t),m=Ee(t);return e.jsxs(k,{className:cs,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:c?"Sleep overlay":t.kind==="stay"?"Stay detail":t.kind==="trip"?"Move detail":"Missing data"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:ue(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{className:c?ma:t.sourceKind==="user_defined"?us:Ne,children:c?"Virtual":t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),t.overrideCount>0?e.jsxs(v,{className:xa,children:["Overrides ",t.overrideCount," automatic box",t.overrideCount===1?"":"es"]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{onClick:r,variant:"ghost",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:c,children:"Details"}),e.jsx(A,{onClick:a,variant:"ghost",className:"size-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Edit movement segment",disabled:c||t.kind==="missing"||!t.editable,children:e.jsx(It,{className:"size-4"})}),l?e.jsx("button",{type:"button",onClick:l,className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close movement segment actions",children:e.jsx($t,{className:"size-4"})}):null,e.jsx(Et,{className:"size-4 text-[var(--ui-ink-faint)]"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.startedAt)})]}),e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.endedAt)})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:qe(t.durationSeconds)}),ct(t)?e.jsxs(e.Fragment,{children:[e.jsx(v,{className:Ne,children:Ie(t.trip.distanceMeters)}),t.trip.stops.length>0?e.jsxs(v,{className:Ne,children:[t.trip.stops.length," stop",t.trip.stops.length===1?"":"s"]}):null]}):null,c?e.jsx(v,{className:ma,children:t.subtitle}):m?e.jsx(v,{className:Ne,children:m}):null]}),le(t)&&!c?e.jsxs("div",{className:ms,children:[e.jsx("div",{className:xs,children:"Location label"}),e.jsx("div",{className:vs,children:t.stay.place?`This stay is currently linked to ${t.stay.place.label}. Search saved places or relabel it from this stay center.`:"Search saved places for this stay, or create a new one from the stay center so later matching stays inherit it automatically."}),e.jsx("div",{className:"mt-3",children:e.jsx(A,{onClick:s,variant:"ghost",className:ps,children:"Label location"})})]}):null,e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Timeline summary"}),e.jsx("div",{className:`mt-2 ${ua}`,children:t.kind==="stay"?c?`Sleep overlay from ${Y(t.startedAt)} to ${Y(t.endedAt)}. Underlying movement boxes are sliced virtually while this overlay is visible.`:`Stay block from ${Y(t.startedAt)} to ${Y(t.endedAt)}.`:t.kind==="trip"?`Connector from ${we(t,"start").label} to ${we(t,"end").label}.`:`No reliable movement signal reached Forge from ${Y(t.startedAt)} to ${Y(t.endedAt)}.`})]}),e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Projection model"}),e.jsx("div",{className:`mt-2 ${ua}`,children:c?"This sleep layer is visual only. Forge does not persist these split boxes; it temporarily slices the visible movement boxes around each sleep interval.":"Raw phone measurements stay immutable. Forge derives automatic boxes from that raw movement evidence, then overlays user-defined boxes on top without mutating the imported raw data."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(v,{className:Ne,children:["Raw stays ",t.rawStayIds.length]}),e.jsxs(v,{className:Ne,children:["Raw trips ",t.rawTripIds.length]}),e.jsxs(v,{className:Ne,children:["Raw points ",t.rawPointCount]}),t.hasLegacyCorrections?e.jsx(v,{className:xa,children:"Legacy corrections present"}):null]})]})]}),e.jsx("div",{className:"mt-5 flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ga,{className:"size-4 text-[var(--info)]"}),"Sleep overlay"]}):le(t)?e.jsxs(e.Fragment,{children:[e.jsx(fa,{className:"size-4 text-[var(--primary)]"}),((d=t.stay.place)==null?void 0:d.label)??"No canonical place linked yet"]}):ct(t)?e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"size-4 text-[var(--primary)]"}),t.trip.activityType||t.trip.travelMode]}):t.kind==="trip"?e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"size-4 text-[var(--primary)]"}),"Repaired movement connector"]}):e.jsxs(e.Fragment,{children:[e.jsx(wt,{className:"size-4 text-[var(--ui-ink-soft)]"}),"Missing intervals are synthesized from long signal gaps instead of inventing fake travel."]})})]})}function va({title:t,points:a,averagePoint:r}){const s=Lr(r?[...a,r]:a),l=r?s.length-1:s.length,c=s.slice(0,l),m=r?s[s.length-1]??null:null,d=c.map((u,p)=>`${p===0?"M":"L"} ${u.x} ${u.y}`).join(" ");return e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Relative coordinates normalized into one view so we can inspect the actual captured stay or trip geometry in one glance."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"var(--ui-surface-1)"}),c.length>1?e.jsx("path",{d,fill:"none",stroke:"var(--primary)",strokeWidth:"1.6"}):null,c.map((u,p)=>e.jsx("circle",{cx:u.x,cy:u.y,r:p===0||p===c.length-1?2.2:1.4,fill:p===0||p===c.length-1?"var(--ui-ink-strong)":"var(--primary)"},u.id)),m?e.jsxs("g",{className:"text-[var(--warning)]",children:[e.jsx("circle",{cx:m.x,cy:m.y,r:3,fill:"currentColor"}),e.jsx("circle",{cx:m.x,cy:m.y,r:6,fill:"none",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"2 2",opacity:.48})]}):null]})})]})}const _t="fixed left-1/2 z-50 -translate-x-1/2 overflow-y-auto border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] text-[var(--ui-ink)] shadow-[var(--card-shadow)] backdrop-blur-xl outline-none",La="rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",Le="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]";function gs({open:t,anchor:a,items:r,onClose:s}){if(x.useEffect(()=>{if(!t)return;const u=g=>{g.key==="Escape"&&s()},p=()=>s();return window.addEventListener("keydown",u),window.addEventListener("pointerdown",p),()=>{window.removeEventListener("keydown",u),window.removeEventListener("pointerdown",p)}},[s,t]),!t||!a||typeof document>"u")return null;const l=Math.max(12,Math.min(a.top,window.innerHeight-360)),c=Math.max(220,window.innerHeight-l-96),m=Math.min(368,window.innerWidth-24),d=Math.max(12,Math.min(a.right,window.innerWidth-m-12));return Ua.createPortal(e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[70]",children:e.jsxs("div",{className:"pointer-events-auto fixed z-[71] overflow-y-auto overscroll-contain rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] p-2 shadow-[var(--card-shadow)] backdrop-blur-xl",style:{top:`${l}px`,right:`${d}px`,width:`${m}px`,maxHeight:`${c}px`},onPointerDown:u=>u.stopPropagation(),children:[e.jsxs(me,{className:"rounded-[22px] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:"Movement actions"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Add boxes, inspect raw data, and adjust timeline overlays."})]}),e.jsx("div",{className:"mt-2 grid gap-1",children:r.map(u=>{const p=u.icon;return e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[20px] bg-[var(--ui-surface-1)] px-4 py-3 text-left text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{u.onSelect(),s()},children:[e.jsx("span",{className:"rounded-[14px] bg-[var(--ui-accent-soft)] p-2 text-[var(--primary)]",children:e.jsx(p,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:u.label}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:u.description})]})]},u.id)})})]})}),document.body)}function fs({open:t,onOpenChange:a,segment:r,detail:s,loading:l,onEdit:c,onDefinePlace:m}){var g;const d=(s==null?void 0:s.segment)??r,u=(s==null?void 0:s.stayDetail)??null,p=(s==null?void 0:s.tripDetail)??null;return e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[6vh] max-h-[88vh] w-[min(60rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:d?`${ue(d)} details`:"Movement details"}),e.jsx(xt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Inspect the canonical box, the raw movement evidence behind it, and the exact coordinates Forge used to assemble this stay or trip."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d?e.jsxs(A,{onClick:c,variant:"ghost",className:w("rounded-full px-3",Le),disabled:!d.editable||d.kind==="missing",children:[e.jsx(It,{className:"size-4"}),"Edit"]}):null,e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:w(La,"p-2"),children:e.jsx(Et,{className:"size-4 rotate-45"})})})]})]}),l?e.jsx(me,{className:"mt-6 text-sm text-[var(--ui-ink-soft)]",children:"Loading the canonical box detail and raw movement evidence..."}):d?e.jsxs("div",{className:"mt-6 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(De,{label:"Started",value:ge(d.startedAt)}),e.jsx(De,{label:"Ended",value:ge(d.endedAt)}),e.jsx(De,{label:"Duration",value:qe(d.durationSeconds)}),e.jsx(De,{label:"Raw coverage",value:`${d.rawStayIds.length} stays · ${d.rawTripIds.length} trips · ${d.rawPointCount} points`})]}),u?e.jsxs(e.Fragment,{children:[e.jsxs(me,{className:"border-[var(--primary)]/20 bg-[var(--ui-accent-soft)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-strong)]",children:u.canonicalPlace?`This stay is linked to ${u.canonicalPlace.label}. Search a different saved place or relabel it from the stay center.`:"This stay has no saved place yet. Search known locations first, or create a new place directly from the stay center."}),e.jsx("div",{className:"mt-3",children:e.jsx(A,{onClick:m,variant:"ghost",className:w("rounded-full px-4",Le),children:"Label location"})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(va,{title:"Stay positions",points:u.positions,averagePoint:u.averagePosition}),e.jsxs(k,{className:"rounded-[28px] p-5",children:[e.jsx(pa,{title:"Stay metrics",rows:[["Canonical place",((g=u.canonicalPlace)==null?void 0:g.label)??"Not linked yet"],["Average position",u.averagePosition?st(u.averagePosition.latitude,u.averagePosition.longitude):"Unavailable"],["Radius",u.radiusMeters!=null?Ie(u.radiusMeters):"Unavailable"],["Samples",String(u.sampleCount)]]}),e.jsxs(me,{muted:!0,className:"mt-4 rounded-[18px] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Exact positions"}),e.jsx("div",{className:"mt-3 grid gap-2",children:u.positions.map((j,P)=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[j.label??`Position ${P+1}`,":"," ",st(j.latitude,j.longitude)]},`${j.recordedAt??"stay"}-${P}`))})]})]})]})]}):null,p?e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(va,{title:"Travel map",points:p.positions}),e.jsx(k,{className:"rounded-[28px] p-5",children:e.jsx(pa,{title:"Trip metrics",rows:[["Start position",p.startPosition?st(p.startPosition.latitude,p.startPosition.longitude):"Unavailable"],["End position",p.endPosition?st(p.endPosition.latitude,p.endPosition.longitude):"Unavailable"],["Distance",Ie(p.totalDistanceMeters)],["Moving time",la(p.movingSeconds)],["Idle time",la(p.idleSeconds)],["Average speed",p.averageSpeedMps!=null?`${p.averageSpeedMps.toFixed(2)} m/s`:"Unavailable"],["Max speed",p.maxSpeedMps!=null?`${p.maxSpeedMps.toFixed(2)} m/s`:"Unavailable"],["Stops",String(p.stopCount)]]})})]}):null]}):null]})]})})}function bs({open:t,segment:a,onOpenChange:r,onEdit:s,onOpenDetail:l,onDefinePlace:c}){return e.jsx(Qe,{open:t,onOpenChange:r,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:"fixed left-1/2 top-[6vh] z-50 max-h-[88vh] w-[min(36rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] outline-none",children:[e.jsx(mt,{className:"sr-only",children:a?`${ue(a)} actions`:"Movement actions"}),e.jsx(xt,{className:"sr-only",children:"Inspect, edit, or label the selected movement box."}),a?e.jsx(hs,{segment:a,onEdit:s,onOpenDetail:l,onDefinePlace:c,onClose:()=>r(!1)}):null]})]})})}function ys({open:t,onOpenChange:a,segment:r,places:s,loading:l,onSelectPlace:c,onCreatePlace:m}){const d=r?Ct(r):null,[u,p]=x.useState("");x.useEffect(()=>{if(!t){p("");return}p(Ee(r)??"")},[t,r]);const g=x.useMemo(()=>{if(!d)return[];const b=he(u);return[...s].filter(C=>b.length===0?!0:$r(C).includes(b)).sort((C,F)=>{const K=he(C.label),Z=he(F.label),z=b.length>0&&K.startsWith(b),J=b.length>0&&Z.startsWith(b);if(z!==J)return z?-1:1;const G=lt(d.latitude,d.longitude,C.latitude,C.longitude),ee=lt(d.latitude,d.longitude,F.latitude,F.longitude);return Math.abs(G-ee)>1?G-ee:C.label.localeCompare(F.label)}).slice(0,6)},[s,u,d]),j=he(u),P=g.some(b=>he(b.label)===j),U=Ee(r);return e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[8vh] max-h-[84vh] w-[min(38rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx($a,{title:"Label stay location",description:"Search saved locations by name first. If this stay is new, create a location from the stay center with latitude and longitude already filled in.",closeLabel:"Close location label dialog"}),d?e.jsxs(me,{className:"mt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"signal",children:"Stay center"}),U?e.jsx(v,{tone:"meta",children:U}):null]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[e.jsx(De,{label:"Latitude",value:d.latitude.toFixed(6)}),e.jsx(De,{label:"Longitude",value:d.longitude.toFixed(6)})]})]}):e.jsx(me,{className:"mt-5 border-[var(--warning)]/20 text-sm text-[var(--ui-ink-soft)]",children:"Forge can only label stays that already have a recorded stay center."}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(B,{value:u,onChange:b=>p(b.target.value),placeholder:"Type a location name or create a new one"}),e.jsxs(me,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:"Known places"}),l?e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"Loading saved places..."}):g.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:g.map(b=>{const C=d==null?null:lt(d.latitude,d.longitude,b.latitude,b.longitude);return e.jsxs("button",{type:"button",onClick:()=>void c(b).then(F=>{F&&a(!1)}),className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:border-[var(--primary)]/40 hover:bg-[var(--ui-surface-hover)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:b.label}),C!=null?e.jsxs(v,{tone:"meta",children:[Ie(C)," away"]}):null]}),b.aliases.length>0||b.categoryTags.length>0?e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:[...b.aliases,...b.categoryTags].join(" · ")}):null]},b.id)})}):e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"No saved place matches this stay yet."})]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx(A,{variant:"ghost",onClick:()=>a(!1),className:Le,children:"Cancel"}),e.jsx(A,{onClick:()=>{!r||!d||m(r,P?"":u.trim())},disabled:!r||!d,children:j.length>0&&!P?`Create "${u.trim()}"`:"Create new location"})]})]})]})})}function js({open:t,draft:a,creating:r,saving:s,preflight:l,preflightLoading:c,onDraftChange:m,onFitMissing:d,onSave:u,onOpenChange:p}){return e.jsx(Qe,{open:t,onOpenChange:p,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[8vh] w-[min(34rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx($a,{title:r?"Create movement box":"Edit movement box",description:a?r?"Create a canonical user-defined stay, move, or missing-data box without mutating raw phone measurements.":`Adjust this user-defined ${a.kind} box. Automatic boxes stay immutable and can only be invalidated.`:"No segment selected."}),a?e.jsxs("div",{className:"mt-5 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:["Kind",e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["stay","Stay"],["trip","Move"],["missing","Missing"]].map(([g,j])=>e.jsx(A,{type:"button",variant:"ghost",className:w(Le,a.kind===g?"ring-1 ring-[color-mix(in_srgb,var(--primary)_42%,transparent)]":""),onClick:()=>m({...a,kind:g}),children:j},g))})]}),e.jsx(Ke,{label:"Label",value:a.label,onChange:g=>m({...a,label:g})}),a.kind!=="trip"?e.jsx(Ke,{label:"Place",value:a.placeLabel,placeholder:"Home, Office, Riverside path...",onChange:g=>m({...a,placeLabel:g})}):null,e.jsx(Ke,{label:"Tags",value:a.tagsInput,placeholder:"movement, social, errand",onChange:g=>m({...a,tagsInput:g})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(Ke,{label:"Started",type:"datetime-local",value:a.startedAtInput,onChange:g=>m({...a,startedAtInput:g})}),e.jsx(Ke,{label:"Ended",type:"datetime-local",value:a.endedAtInput,onChange:g=>m({...a,endedAtInput:g})})]}),e.jsxs(me,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Overlap guidance"}),e.jsx(A,{type:"button",variant:"ghost",className:Le,onClick:d,disabled:!(l!=null&&l.nearestMissingStartedAt)||!(l!=null&&l.nearestMissingEndedAt),children:"Fit Missing Time"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:c?"Checking visible overlaps and missing windows...":l!=null&&l.overlapsAnything?`This box overlaps ${l.affectedAutomaticBoxIds.length} automatic and ${l.affectedUserBoxIds.length} manual boxes. Saving will fully override ${l.fullyOverriddenUserBoxIds.length} manual boxes and trim ${l.trimmedUserBoxIds.length}.`:"No overlap in the currently visible timeline window."}),e.jsxs("div",{className:"mt-3 grid gap-1 text-xs text-[var(--ui-ink-faint)]",children:[e.jsxs("div",{children:["Visible range:"," ",l!=null&&l.visibleRangeStart&&(l!=null&&l.visibleRangeEnd)?`${ge(l.visibleRangeStart)} -> ${ge(l.visibleRangeEnd)}`:"Unavailable"]}),e.jsxs("div",{children:["Suggested missing slot:"," ",l!=null&&l.nearestMissingStartedAt&&(l!=null&&l.nearestMissingEndedAt)?`${ge(l.nearestMissingStartedAt)} -> ${ge(l.nearestMissingEndedAt)}`:"No missing interval in view"]})]})]})]}):null,e.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[e.jsx(vt,{asChild:!0,children:e.jsx(A,{type:"button",variant:"ghost",className:Le,children:"Cancel"})}),e.jsxs(A,{onClick:u,disabled:!a||s,children:[e.jsx(Wa,{className:"size-4"}),s?"Saving...":r?"Create box":"Save changes"]})]})]})]})})}function $a({title:t,description:a,closeLabel:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:t}),e.jsx(xt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a})]}),e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:w(La,"p-2"),"aria-label":r,children:r?e.jsx($t,{className:"size-4"}):e.jsx(Et,{className:"size-4 rotate-45"})})})]})}function De({label:t,value:a}){return e.jsxs(me,{className:"rounded-[18px] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:a})]})}function pa({title:t,rows:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-4 grid gap-3",children:a.map(([r,s])=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("span",{className:"text-[var(--ui-ink-faint)]",children:[r,": "]}),s]},r))})]})}function Ke({label:t,value:a,onChange:r,placeholder:s,type:l="text"}){return e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:[t,e.jsx(B,{type:l,value:a,placeholder:s,onChange:c=>r(c.target.value)})]})}function Ns({userIds:t=[]}){var Wt,Gt,Vt;const a=ya(),r=x.useRef(null),s=x.useRef(null),l=x.useRef(null),c=x.useRef(!1),m=x.useRef(!1),d=x.useRef(null),[u,p]=x.useState(null),[g,j]=x.useState(!1),[P,U]=x.useState(!1),[b,C]=x.useState(null),[F,K]=x.useState({}),[Z,z]=x.useState(null),[J,G]=x.useState(null),[ee,te]=x.useState(null),[Ve,Fe]=x.useState(null),[_e,Re]=x.useState(!1),[Ye,Se]=x.useState(!1),[ht,Me]=x.useState(null),[gt,ze]=x.useState(null),[re,W]=x.useState(!1),[se,ie]=x.useState(!1),[q,xe]=x.useState(!1),[y,Xe]=x.useState(""),[fe,Ze]=x.useState([]),[ve,Je]=x.useState(0),[O,Oe]=x.useState(0),Ae=()=>{const n=r.current;n&&(Je(n.scrollTop),Oe(n.clientHeight))},D=Yt({queryKey:["forge-movement-life-timeline",...t],initialPageParam:null,queryFn:({pageParam:n})=>Jt({before:n??void 0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),N=Yt({queryKey:["forge-movement-life-timeline-data",...t],initialPageParam:null,queryFn:({pageParam:n})=>Jt({before:n??void 0,includeInvalid:!0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),be=x.useMemo(()=>{var n;return((n=D.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[D.data]),oe=x.useMemo(()=>{var n;return((n=N.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[N.data]),de=x.useMemo(()=>{var n;return((n=D.data)==null?void 0:n.pages.reduce((o,h)=>Math.max(o,h.invalidSegmentCount??0),0))??0},[D.data]),_=x.useMemo(()=>[...be].reverse(),[be]),T=x.useMemo(()=>[...oe].reverse(),[oe]),et=x.useMemo(()=>{var o;const n=new Map;for(const h of((o=D.data)==null?void 0:o.pages)??[])for(const R of h.sleepOverlays??[])n.set(R.id,R);return[...n.values()].sort((h,R)=>new Date(h.startedAt).getTime()-new Date(R.startedAt).getTime())},[D.data]),ye=x.useMemo(()=>Tr(_,et),[_,et]),S=x.useMemo(()=>q?ye:_,[_,ye,q]),He=x.useMemo(()=>ye.filter(n=>n.syncSource==="sleep overlay"),[ye]),ne=((Wt=He.at(-1))==null?void 0:Wt.id)??null,L=x.useMemo(()=>S.find(n=>n.id===ee)??null,[ee,S]),i=x.useMemo(()=>S.find(n=>n.id===u)??null,[S,u]),f=ae({queryKey:["forge-movement-box-detail",(L==null?void 0:L.boxId)??null,...t],queryFn:async()=>L!=null&&L.boxId?(await tr(L.boxId,t)).movement:null,enabled:!!(L!=null&&L.boxId)}),Q=x.useMemo(()=>_.find(n=>n.id===Ve)??null,[Ve,_]),V=ae({queryKey:["forge-movement-places",...t],queryFn:async()=>(await Sa(t)).places,retry:!1,refetchOnWindowFocus:!1}),M=x.useMemo(()=>Vr({segments:S,viewportHeight:O}),[S,O]),pe=x.useMemo(()=>new Map(M.items.map(n=>[n.segment.id,n])),[M.items]),Ce=x.useMemo(()=>{const n=Math.max(0,ve-ia),o=ve+Math.max(O,X*8)+ia;return M.items.filter(h=>h.segment.id===u?!0:h.boxBottom>=n&&h.boxTop<=o)},[ve,u,M.items,O]),zt=x.useMemo(()=>os(M,ve,O),[ve,M,O]),Ea=()=>{var o;const n=(o=l.current)==null?void 0:o.getBoundingClientRect();if(!n){U(h=>!h);return}C({top:n.bottom+10,right:Math.max(12,window.innerWidth-n.right)}),U(h=>!h)},Fa=x.useMemo(()=>[{id:"add-box",label:"Add box",description:"Create a user-defined stay, move, or missing-data interval.",icon:Ga,onSelect:()=>G(kt("stay",_.at(-1)??null))},{id:"sleep",label:q?"Hide sleep":"Show sleep",description:"Toggle sleep overlays without rewriting the movement boxes.",icon:ga,onSelect:()=>xe(n=>{const o=!n;return o&&ne&&(p(ne),j(!0)),o})},{id:"view-data",label:"View data",description:"Open the canonical loaded records and raw-data filters.",icon:wt,onSelect:()=>W(!0)}],[ne,_,q]),Ot=(n,o="smooth")=>{const h=r.current,R=pe.get(n);if(!h||!R)return;const Be=Math.max(0,R.boxTop-h.clientHeight/2+R.displayHeight/2);if(typeof h.scrollTo=="function"){h.scrollTo({top:Be,behavior:o});return}h.scrollTop=Be};x.useEffect(()=>{re&&(!N.hasNextPage||N.isFetchingNextPage||N.fetchNextPage())},[re,N.fetchNextPage,N.hasNextPage,N.isFetchingNextPage]),x.useEffect(()=>{const n=S.at(-1);!m.current&&n&&(m.current=!0,p(n.id))},[S]),x.useEffect(()=>{if(!c.current&&S.length>0){c.current=!0,requestAnimationFrame(()=>{var o;const n=(o=S[S.length-1])==null?void 0:o.id;n&&Ot(n,"auto"),requestAnimationFrame(()=>{Ae()})});return}if(d.current&&S.length>d.current.count&&r.current){const n=d.current;d.current=null,requestAnimationFrame(()=>{const o=r.current;if(!o)return;const h=M.totalHeight-n.size;o.scrollTop+=h,Ae()})}},[S.length,M.totalHeight,pe]),x.useEffect(()=>{if(!r.current)return;const o=()=>{Ae()};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),x.useEffect(()=>{if(!u)return;const n=_.find(o=>o.id===u);n&&K(o=>o[u]?o:{...o,[u]:Tt(n)})},[_,u]),x.useEffect(()=>{var n;u&&(S.some(o=>o.id===u)||(p(((n=S.at(-1))==null?void 0:n.id)??null),j(!1)))},[S,u]),x.useEffect(()=>{if(!q||!ne)return;const n=S.findIndex(o=>o.id===ne);n<0||(p(ne),requestAnimationFrame(()=>{var h;const o=(h=S[n])==null?void 0:h.id;o&&Ot(o)}))},[S,ne,q,pe]);const ft=async()=>{await Promise.all([a.invalidateQueries({queryKey:["forge-movement-life-timeline"]}),a.invalidateQueries({queryKey:["forge-movement-life-timeline-data"]}),a.invalidateQueries({queryKey:["forge-movement-box-detail"]}),a.invalidateQueries({queryKey:["forge-movement-day"]}),a.invalidateQueries({queryKey:["forge-movement-month"]}),a.invalidateQueries({queryKey:["forge-movement-all-time"]}),a.invalidateQueries({queryKey:["forge-movement-places"]}),a.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]})])},Ht=Pe({mutationFn:async n=>{const{segment:o,draft:h,creating:R}=n,Be=Pt(h,o);if(R){await Xt(Be,t);return}if(!o)throw new Error("No movement box selected.");if(o.sourceKind!=="user_defined")throw new Error("Automatic movement boxes are immutable. Invalidate them into missing data or create a user-defined override instead.");await Zt(o.boxId,{...Be,metadata:{updatedFrom:"movement-life-timeline"}},t)},onSuccess:ft}),_a=async(n,o)=>{if(n.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");const h=zr(n,o.label);if(n.sourceKind==="user_defined"){await Zt(n.boxId,{...h,metadata:{updatedFrom:"movement-life-timeline-place-label"}},t);return}await Xt({...h,metadata:{createdFrom:"movement-life-timeline-place-label"}},t)},Bt=async(n,o)=>{if(n.rawStayIds.length===0)throw new Error("This stay has no raw stay ids to relabel.");await Promise.all(n.rawStayIds.map(h=>er(h,{placeExternalUid:o.externalUid,placeLabel:o.label})))},Ra=(n,o)=>{const h=Ct(n);if(!h)return!0;const R=lt(h.latitude,h.longitude,o.latitude,o.longitude);return R<=100||typeof window>"u"||typeof window.confirm!="function"?!0:window.confirm(`"${o.label}" is ${Ie(R)} away from this stay's recorded center. Link it anyway?`)},za=Pe({mutationFn:async n=>{const{segment:o,...h}=n,R=await ja(h,t);return o&&le(o)&&await Bt(o,R.place),R},onSuccess:ft}),Oa=Pe({mutationFn:async n=>{const{segment:o,place:h}=n;if(!Ra(o,h))return{assigned:!1};if(le(o))return await Bt(o,h),{assigned:!0};if(o.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");return await _a(o,h),{assigned:!0}},onSuccess:async n=>{n.assigned&&await ft()}}),bt=Pe({mutationFn:async n=>{if(n.sourceKind==="user_defined"){await Za(n.boxId,t);return}await Ja(n.boxId,{title:"User invalidated automatic movement",subtitle:`Overrides ${ue(n)} with missing data.`},t)},onSuccess:async(n,o)=>{p(h=>h===o.id?null:h),j(!1),z(h=>h===o.id?null:h),a.setQueryData(["forge-movement-life-timeline",...t],h=>da(h,o.id)),a.setQueryData(["forge-movement-life-timeline-data",...t],h=>da(h,o.id)),await Promise.all([a.invalidateQueries({queryKey:["forge-movement-life-timeline"]}),a.invalidateQueries({queryKey:["forge-movement-life-timeline-data"]}),a.invalidateQueries({queryKey:["forge-movement-day"]}),a.invalidateQueries({queryKey:["forge-movement-month"]}),a.invalidateQueries({queryKey:["forge-movement-all-time"]}),a.invalidateQueries({queryKey:["forge-movement-selection"]}),a.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]})])}}),Ha=x.useMemo(()=>Hr(T),[T]),je=x.useMemo(()=>{const n=he(y);return[...T].sort((o,h)=>new Date(h.endedAt).getTime()-new Date(o.endedAt).getTime()).filter(o=>(n.length===0||Or(o).includes(n))&&Br(o,fe))},[T,y,fe]),Kt=x.useMemo(()=>T.length===0?"No movement records loaded yet.":je.length===T.length&&y.trim().length===0&&fe.length===0?`${T.length} loaded movement records visible`:`${je.length} of ${T.length} loaded records visible`,[T.length,je.length,y,fe.length]),yt=ba({count:je.length,getScrollElement:()=>s.current,estimateSize:()=>136,overscan:8}),$=Z?_.find(n=>n.id===Z)??null:null,Ba=$?F[$.id]??Tt($):null,tt=J!==null,E=J??Ba,qt=((Gt=_[0])==null?void 0:Gt.startedAt)??null,Qt=((Vt=_[_.length-1])==null?void 0:Vt.endedAt)??null,jt=ae({queryKey:["forge-movement-user-box-preflight",($==null?void 0:$.boxId)??"create",(E==null?void 0:E.kind)??null,(E==null?void 0:E.startedAtInput)??null,(E==null?void 0:E.endedAtInput)??null,qt,Qt,...t],enabled:E!==null&&dt(E.startedAtInput)!==null&&dt(E.endedAtInput)!==null,queryFn:async()=>{if(!E)return null;const n=Pt(E,$);return(await ar({...n,excludeBoxId:($==null?void 0:$.sourceKind)==="user_defined"?$.boxId:null,rangeStart:qt,rangeEnd:Qt},t)).preflight}}),Ut=n=>{le(n)&&(Fe(n.id),Re(!0))},Ka=(n,o)=>{const h=Ct(n);h&&(Re(!1),Fe(n.id),Me({...h,label:o.trim()||h.label}),ze(n.id),Se(!0))},qa=()=>{const n=r.current;n&&(Je(n.scrollTop),Oe(n.clientHeight),!(!D.hasNextPage||D.isFetchingNextPage)&&n.scrollTop<=960&&(d.current={count:S.length,size:M.totalHeight},D.fetchNextPage()))};if(D.isPending)return e.jsx(Na,{eyebrow:"Movement",title:"Loading life timeline",description:"Reconstructing the longer road of stays, moves, and places.",columns:1,blocks:6});if(D.isError)return e.jsx(ka,{eyebrow:"Movement",error:D.error,onRetry:()=>void D.refetch()});const Qa=M.totalHeight;return e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(k,{className:"overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-3 sm:rounded-[34px] sm:p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 px-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:"Movement"}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-2",children:[de>0?e.jsxs(v,{className:w("hidden sm:inline-flex",Te),children:[de," invalid hidden"]}):null,e.jsxs(v,{className:"hidden bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] sm:inline-flex",children:[S.length," visible"]}),e.jsx("div",{ref:l,children:e.jsxs(A,{type:"button",variant:"ghost",size:"sm","aria-expanded":P,"aria-haspopup":"dialog",className:w("h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",P?Dt:""),onClick:Ea,children:[e.jsx(Va,{className:"size-4"}),"Actions"]})})]})]}),e.jsx(gs,{open:P,anchor:b,items:Fa,onClose:()=>U(!1)}),q&&He.length===0?e.jsx("p",{className:"mb-3 px-1 text-sm text-[color-mix(in_srgb,var(--warning)_72%,var(--ui-ink-strong)_28%)]",children:"No sleep session overlaps the currently loaded timeline range yet. Scroll further back to load older history."}):null,e.jsxs("div",{ref:r,onScroll:qa,className:"relative h-[82vh] overflow-auto rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)]",children:[e.jsx(is,{layout:M,scrollTop:ve,viewportHeight:O}),zt?e.jsx("div",{className:"pointer-events-none sticky top-3 z-50 flex h-0 justify-center",children:e.jsx("div",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1.5 font-label text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-medium)] shadow-[var(--ui-shadow-soft)] backdrop-blur-xl",children:zt})}):null,e.jsxs("div",{className:"relative",style:{height:`${Qa}px`},children:[M.historyHeaderHeight>0?e.jsx("div",{className:"absolute inset-x-0 top-0",style:{height:`${M.historyHeaderHeight}px`},children:e.jsx(ls,{segment:S[0]??null})}):null,Ce.map(n=>{const o=n.segment;return e.jsx(ds,{layout:n,selected:u===o.id,onToggle:()=>{p(o.id),j(!0)}},o.id)})]})]})]}),e.jsx(js,{open:$!==null||J!==null,segment:$,draft:E,creating:tt,saving:Ht.isPending,preflight:jt.data??null,preflightLoading:jt.isFetching,onDraftChange:n=>{if(tt){G(n);return}$&&K(o=>({...o,[$.id]:n}))},onFitMissing:()=>{const n=jt.data;if(!(n!=null&&n.nearestMissingStartedAt)||!n.nearestMissingEndedAt)return;const o={...E??kt("stay",$),startedAtInput:$e(n.nearestMissingStartedAt),endedAtInput:$e(n.nearestMissingEndedAt)};if(tt){G(o);return}$&&K(h=>({...h,[$.id]:o}))},onSave:()=>{E&&Ht.mutateAsync({segment:$,draft:E,creating:tt},{onSuccess:()=>{z(null),G(null),se&&(ie(!1),W(!0))}})},onOpenChange:n=>{n||(z(null),G(null),se&&(ie(!1),W(!0)))}}),e.jsx(bs,{open:g&&i!==null,onOpenChange:n=>{j(n)},segment:i,onEdit:()=>{i!=null&&i.editable&&(z(i.id),j(!1))},onOpenDetail:()=>{i&&(te(i.id),j(!1))},onDefinePlace:()=>{i&&(Ut(i),j(!1))}}),e.jsx(fs,{open:L!==null,onOpenChange:n=>{n||te(null)},segment:L,detail:f.data??null,loading:f.isFetching,onEdit:()=>{!L||!L.editable||(z(L.id),te(null))},onDefinePlace:()=>{L&&Ut(L)}}),e.jsx(ys,{open:_e,onOpenChange:n=>{Re(n),n||Fe(null)},segment:Q,places:V.data??[],loading:V.isFetching,onSelectPlace:async n=>Q?(await Oa.mutateAsync({segment:Q,place:n})).assigned:!1,onCreatePlace:(n,o)=>{Ka(n,o)}}),e.jsx(Aa,{open:Ye,onOpenChange:n=>{Se(n),n||(Me(null),ze(null))},place:null,seed:ht,onSave:async n=>{await za.mutateAsync({...n,segment:_.find(o=>o.id===gt)??null})}}),e.jsx(wa,{open:re,onOpenChange:n=>{W(n),n||se||(Xe(""),Ze([]))},eyebrow:"Movement data",title:"View data",description:"",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ma,{title:"",description:"",query:y,onQueryChange:Xe,options:Ha,selectedOptionIds:fe,onSelectedOptionIdsChange:Ze,resultSummary:Kt,placeholder:"Search movement labels, places, times, tags, or add time and kind filters",emptyStateMessage:"Keep typing or pick filters to narrow the movement history."}),e.jsxs(k,{className:"grid min-w-0 gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Canonical boxes"}),e.jsx("div",{className:"max-w-3xl break-words text-sm leading-6 text-[var(--ui-ink-muted)]",children:"This list shows the canonical movement boxes projected by Forge. Automatic boxes are derived from immutable raw phone measurements. User-defined boxes override the projection without mutating raw movement data."})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)]",onClick:()=>{ie(!0),W(!1),G(kt("stay",je.at(-1)??null))},children:"Add box"}),e.jsx(v,{tone:"meta",children:Kt}),de>0?e.jsxs(v,{className:Te,children:[de," invalid hidden included"]}):null,N.hasNextPage?e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)]",pending:N.isFetchingNextPage,pendingLabel:"Loading…",onClick:()=>void N.fetchNextPage(),children:"Load older"}):null]})]}),e.jsx("div",{ref:s,className:"h-[36rem] overflow-y-auto rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:je.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No movement record matches the current search. Clear filters or load older timeline history."}):e.jsx("div",{className:"relative w-full",style:{height:`${yt.getTotalSize()}px`},children:yt.getVirtualItems().map(n=>{var h;const o=je[n.index];return e.jsx("div",{ref:yt.measureElement,"data-index":n.index,className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${n.start}px)`},children:e.jsxs("div",{className:"flex items-start gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left transition hover:opacity-100",onClick:()=>{o.editable&&(ie(!0),W(!1),z(o.id))},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[o.kind==="stay"?e.jsx(fa,{className:"size-3.5 shrink-0 text-[var(--primary)]"}):o.kind==="missing"?e.jsx(wt,{className:"size-3.5 shrink-0 text-[var(--ui-ink-medium)]"}):e.jsx(ot,{className:"size-3.5 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-sm font-medium",children:ue(o)})]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--ui-ink-muted)]",children:[ut(o.startedAt)," →"," ",ut(o.endedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1.5",children:[e.jsx(v,{tone:o.kind==="trip"?"signal":"meta",children:o.kind==="trip"?"Move":o.kind==="missing"?"Missing":"Stay"}),e.jsx(v,{className:o.sourceKind==="user_defined"?"bg-[var(--ui-accent-soft)] text-[var(--primary)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:o.sourceKind==="user_defined"?o.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),e.jsx(v,{tone:"meta",children:qe(o.durationSeconds)}),o.origin==="continued_stay"?e.jsx(v,{className:Da,children:"Continued stay"}):null,o.origin==="repaired_gap"?e.jsx(v,{className:Te,children:"Repaired"}):null,o.kind==="missing"?e.jsx(v,{className:as,children:"Missing"}):null,o.isInvalid?e.jsx(v,{className:Te,children:"Invalid"}):null,o.placeLabel?e.jsx(v,{tone:"default",children:o.placeLabel}):null,o.overrideCount>0?e.jsxs(v,{className:Te,children:["Overrides ",o.overrideCount]}):null,e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw stays ",o.rawStayIds.length]}),e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw trips ",o.rawTripIds.length]}),e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw points ",o.rawPointCount]}),o.hasLegacyCorrections?e.jsx(v,{className:Te,children:"Legacy corrections"}):null]})]})}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:w("h-8 shrink-0 rounded-full border px-2.5",o.sourceKind==="user_defined"?rs:ss),pending:bt.isPending&&((h=bt.variables)==null?void 0:h.id)===o.id,pendingLabel:"",onClick:()=>{window.confirm(o.sourceKind==="user_defined"?`Delete ${ue(o)} and remove this user-defined box from every synced surface?`:`Invalidate ${ue(o)} into missing data and hide the automatic box everywhere?`)&&bt.mutateAsync(o)},children:e.jsx(Ya,{className:"size-3.5"})})]})},`${o.kind}:${o.id}:${o.startedAt}:${o.endedAt}:${n.index}`)})})})]})]})})]})}function ks(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}).format(new Date(t))}function ws(t,a){const r=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${r.format(new Date(t))} - ${r.format(new Date(a))}`}function H(t){return t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.round(t/60)}m`}function ke(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Ss(t,a){return t==="distanceMeters"?ke(a):t==="caloriesKcal"?`${Math.round(a)} kcal`:H(a)}function Ia(t){return t.trim().toLowerCase()}function pt(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function Rt(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ms(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function ha(t){return{recordedAt:Ms(t.recordedAt),latitude:String(t.latitude),longitude:String(t.longitude),accuracyMeters:t.accuracyMeters!=null?String(t.accuracyMeters):"",altitudeMeters:t.altitudeMeters!=null?String(t.altitudeMeters):"",speedMps:t.speedMps!=null?String(t.speedMps):"",isStopAnchor:t.isStopAnchor}}function As(t){return Ia([Rt(t.recordedAt),t.externalUid,t.isStopAnchor?"stop anchor stop":"path trace point",t.accuracyMeters!=null?`${Math.round(t.accuracyMeters)} meters accuracy`:"",pt(t.recordedAt)].join(" "))}function Cs(t){const a=new Map;return a.set("anchor:stop",{id:"anchor:stop",label:"Stop anchors",description:"Only the canonical pause anchors",badge:e.jsx(v,{tone:"meta",children:"Stop anchors"})}),a.set("anchor:path",{id:"anchor:path",label:"Path points",description:"Non-anchor trace points",badge:e.jsx(v,{tone:"meta",children:"Path points"})}),a.set("accuracy:precise",{id:"accuracy:precise",label:"Precise",description:"GPS accuracy below 20m",badge:e.jsx(v,{tone:"meta",children:"Precise"})}),a.set("accuracy:loose",{id:"accuracy:loose",label:"Loose accuracy",description:"GPS accuracy at or above 20m",badge:e.jsx(v,{tone:"meta",children:"Loose accuracy"})}),t.forEach(r=>{const s=pt(r.recordedAt);a.has(`time:${s}`)||a.set(`time:${s}`,{id:`time:${s}`,label:s,description:"Recorded during this time band",badge:e.jsx(v,{tone:"meta",className:"capitalize",children:s})})}),[...a.values()]}function Ts(t,a){return a.every(r=>r==="anchor:stop"?t.isStopAnchor:r==="anchor:path"?!t.isStopAnchor:r==="accuracy:precise"?t.accuracyMeters!=null&&t.accuracyMeters<20:r==="accuracy:loose"?t.accuracyMeters==null||t.accuracyMeters>=20:r.startsWith("time:")?pt(t.recordedAt)===r.slice(5):!0)}function Ps(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),r=Math.max(...t.map(d=>d.latitude)),s=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(r-a,1e-4),m=Math.max(l-s,1e-4);return t.map(d=>({x:12+(d.longitude-s)/m*76,y:12+(1-(d.latitude-a)/c)*76}))}function Ds({curve:t,startLabel:a,endLabel:r,stopLabels:s}){const l=t.map((c,m)=>`${m===0?"M":"Q"} ${c.x} ${c.y}`).join(" ");return e.jsxs(k,{className:"overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Stylized trajectory"}),e.jsx(ce,{content:"This graph is a softened trip trace. It emphasizes rhythm, stops, and endpoints instead of raw GPS jitter."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"A softened path that prioritizes rhythm, stops, and landmarks over raw map noise."})]}),e.jsxs(v,{tone:"signal",children:[a," → ",r]})]}),e.jsxs("div",{className:"mt-5 rounded-[26px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("svg",{viewBox:"0 0 100 60",className:"h-48 w-full",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"movementGlow",children:[e.jsx("feGaussianBlur",{stdDeviation:"1.8",result:"blur"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"blur"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),e.jsx("path",{d:l,fill:"none",stroke:"var(--ui-ink-medium)",strokeWidth:"1.5",strokeDasharray:"2.8 2.8",filter:"url(#movementGlow)"}),t.map((c,m)=>e.jsx("g",{children:e.jsx("circle",{cx:c.x,cy:c.y,r:m===0||m===t.length-1?2.6:1.6,fill:m===0||m===t.length-1?"var(--ui-ink-strong)":"var(--info)"})},`${c.x}-${c.y}-${m}`))]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:s.map(c=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:c},c))})]})]})}function Ls({points:t}){const a=Ps(t),r=a.map((s,l)=>`${l===0?"M":"L"} ${s.x} ${s.y}`).join(" ");return e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Exact path"}),e.jsx(ce,{content:"This keeps the recent raw location points. Use it when you want the literal recorded trace instead of the cleaned movement graph."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"Recent raw points preserved by the companion before long-term simplification."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"var(--ui-surface-2)"}),e.jsx("path",{d:r,fill:"none",stroke:"var(--info)",strokeWidth:"1.6"}),a.map((s,l)=>e.jsx("circle",{cx:s.x,cy:s.y,r:l===0||l===a.length-1?2:1.1,fill:l===0||l===a.length-1?"var(--ui-ink-strong)":"var(--info)"},`${s.x}-${s.y}-${l}`))]})})]})}function $s({point:t,draft:a}){return e.jsxs(k,{className:"grid gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Raw datapoint"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Rt(t.recordedAt)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Raw phone measurements are immutable in product UI. To change the visible movement story, create or edit user-defined boxes in the Life Timeline instead."})]}),e.jsx(v,{tone:t.isStopAnchor?"signal":"meta",children:t.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Recorded at"}),e.jsx(B,{type:"datetime-local",value:a.recordedAt,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Speed (m/s)"}),e.jsx(B,{value:a.speedMps,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Latitude"}),e.jsx(B,{value:a.latitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Longitude"}),e.jsx(B,{value:a.longitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Accuracy (m)"}),e.jsx(B,{value:a.accuracyMeters,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Altitude (m)"}),e.jsx(B,{value:a.altitudeMeters,disabled:!0,placeholder:"Optional"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(A,{variant:"ghost",className:w("h-10 rounded-full border px-4",a.isStopAnchor?"border-[var(--primary)] bg-[var(--primary)]/16 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),disabled:!0,children:[e.jsx(ot,{className:"mr-2 size-4"}),a.isStopAnchor?"Stop anchor":"Path point"]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:["External id: ",e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:t.externalUid})]})]}),e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"This browser is read-only now. Raw points stay immutable so the web app and iPhone can both project the same repaired canonical boxes from the backend."})]})}function Us(){var ye,S,He,ne,L;const t=rr(),a=ya(),r=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[s,l]=x.useState("life"),[c,m]=x.useState(new Date().toISOString().slice(0,10)),[d,u]=x.useState(new Date().toISOString().slice(0,7)),[p,g]=x.useState(null),[j,P]=x.useState(!1),[U,b]=x.useState(!1),[C,F]=x.useState(""),[K,Z]=x.useState([]),[z,J]=x.useState(null),[G,ee]=x.useState(null),[te,Ve]=x.useState({stayIds:[],tripIds:[]}),[Fe,_e]=x.useState(!1),[Re,Ye]=x.useState(null),[Se,ht]=x.useState(""),[Me,gt]=x.useState("distanceMeters"),ze=x.useRef(null),re=ae({queryKey:["forge-movement-day",c,...r],queryFn:async()=>(await ur({date:c,userIds:r})).movement}),W=ae({queryKey:["forge-movement-month",d,...r],queryFn:async()=>(await mr({month:d,userIds:r})).movement}),se=ae({queryKey:["forge-movement-all-time",...r],queryFn:async()=>(await xr(r)).movement}),ie=ae({queryKey:["forge-life-force",...r],queryFn:async()=>(await vr(r)).lifeForce}),q=ae({queryKey:["forge-movement-settings",...r],queryFn:async()=>(await pr(r)).settings}),xe=ae({queryKey:["forge-movement-places",...r],queryFn:async()=>(await Sa(r)).places}),y=ae({queryKey:["forge-movement-trip",p],queryFn:async()=>p?(await hr(p)).movement:null,enabled:!!p}),Xe=ae({queryKey:["forge-movement-selection",c,te.stayIds.join(","),te.tripIds.join(","),...r],queryFn:async()=>(await gr({...te,userIds:r})).movement,enabled:te.stayIds.length>0||te.tripIds.length>0}),fe=Pe({mutationFn:async i=>sr({trackingEnabled:i},r),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-settings"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]})}}),Ze=Pe({mutationFn:async i=>i.id?ir(i.id,i):ja(i,r),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-places"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]}),await a.invalidateQueries({queryKey:["forge-movement-all-time"]})}}),ve=x.useMemo(()=>{const i=xe.data??[],f=Se.trim().toLowerCase();return f?i.filter(Q=>[Q.label,...Q.aliases,...Q.categoryTags].join(" ").toLowerCase().includes(f)):i},[Se,xe.data]),Je=x.useMemo(()=>{var i;return Cs(((i=y.data)==null?void 0:i.trip.points)??[])},[(ye=y.data)==null?void 0:ye.trip.points]),O=x.useMemo(()=>{var Q;const i=((Q=y.data)==null?void 0:Q.trip.points)??[],f=Ia(C);return[...i].sort((V,M)=>new Date(M.recordedAt).getTime()-new Date(V.recordedAt).getTime()).filter(V=>(f.length===0||As(V).includes(f))&&Ts(V,K))},[C,K,(S=y.data)==null?void 0:S.trip.points]),Oe=x.useMemo(()=>{var f;const i=((f=y.data)==null?void 0:f.trip.points.length)??0;return i===0?"No raw datapoints on this trip yet.":O.length===i&&C.trim().length===0&&K.length===0?`${i} datapoints visible`:`${O.length} of ${i} datapoints visible`},[O.length,C,K.length,(He=y.data)==null?void 0:He.trip.points.length]),Ae=ba({count:O.length,getScrollElement:()=>ze.current,estimateSize:()=>96,overscan:8}),D=O.find(i=>i.id===z)??((ne=y.data)==null?void 0:ne.trip.points.find(i=>i.id===z))??O[0]??((L=y.data)==null?void 0:L.trip.points[0])??null;if(x.useEffect(()=>{if(U){if(!D){J(null),ee(null);return}J(D.id),ee(ha(D))}},[D,U]),x.useEffect(()=>{F(""),Z([]),J(null),ee(null),b(!1)},[p]),re.isLoading||W.isLoading||se.isLoading||q.isLoading||xe.isLoading)return e.jsx(Na,{eyebrow:"Movement",title:"Loading movement workspace",description:"Reconstructing stays, trips, and place intelligence across Forge.",columns:2,blocks:8});if(re.isError||W.isError||se.isError||q.isError||xe.isError||!re.data||!W.data||!se.data||!q.data)return e.jsx(ka,{eyebrow:"Movement",error:re.error??W.error??se.error??q.error??xe.error??new Error("Movement data unavailable"),onRetry:()=>{re.refetch(),W.refetch(),se.refetch(),q.refetch(),xe.refetch()}});const N=re.data,be=W.data,oe=se.data,de=q.data,_=N.segments.filter((i,f,Q)=>{const V=`${i.kind}:${i.id}:${i.startedAt}:${i.endedAt}`;return Q.findIndex(M=>`${M.kind}:${M.id}:${M.startedAt}:${M.endedAt}`===V)===f}),T=Xe.data??N.selectionAggregate,et=N.trips.reduce((i,f)=>i+at(f).totalAp,0);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(fr,{entityKind:"project",title:"Movement",description:"Turn passive place and travel signals into a real Forge domain: day rhythm, travel arcs, known landmarks, linked work, and reflective evidence.",badge:`${N.summary.tripCount} trips today`,actions:e.jsx("div",{className:"flex flex-wrap gap-2",children:["life","day","month","all_time"].map(i=>e.jsx(A,{variant:"ghost",className:w("h-9 rounded-full border px-4 text-sm",s===i?"border-[var(--primary)] bg-[var(--primary)]/16 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),onClick:()=>l(i),children:i==="all_time"?"All time":i==="life"?"Life":i.charAt(0).toUpperCase()+i.slice(1)},i))})}),e.jsxs(k,{className:"grid gap-3 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Movement AP today"}),e.jsx("div",{className:"mt-2 text-3xl font-semibold text-[var(--ui-ink-strong)]",children:ea(et)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Trips and transitions now contribute to the same Action Point ledger as work, habits, and notes."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Typical trip drain"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:N.trips[0]?rt(at(N.trips[0]).rateApPerHour):"0 AP/h"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Movement uses a MET-like drain under the hood, translated into Forge Action Points."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Life Force sync"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:ie.data?`${Math.round(ie.data.spentTodayAp??0)}/${Math.round(ie.data.dailyBudgetAp??0)} AP`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:ie.data?`${rt(ie.data.instantFreeApPerHour)} free right now`:"Movement can now be read against today’s live capacity."})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.65fr)_minmax(20rem,0.95fr)]",children:[e.jsx(nr,{children:e.jsxs(k,{className:"overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Movement operating mode"}),e.jsx(ce,{content:"This is the passive capture state of the movement system: whether tracking is running, how much is published into Forge, and how aggressive retention is."})]}),e.jsx("div",{className:"mt-2 text-[clamp(1.05rem,1.8vw,1.35rem)] text-[var(--ui-ink-strong)]",children:"Background stays and trips as structured life evidence"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The companion samples quietly while stationary, switches to denser trip capture when you move, and keeps only simplified long-term traces."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:de.trackingEnabled?"Tracking on":"Tracking off"}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:de.publishMode.replaceAll("_"," ")}),e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4",onClick:()=>fe.mutate(!de.trackingEnabled),children:de.trackingEnabled?"Pause passive capture":"Enable passive capture"})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Distance today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:ke(N.summary.totalDistanceMeters)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Across trips, stops, and linked place changes."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Idle time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.totalIdleSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Time spent settled enough to count as a real stay."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Estimated phone time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.estimatedScreenTimeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Estimated from hourly Screen Time bins, not exact foreground traces."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:N.summary.knownPlaceCount}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Shared between Forge and the iPhone companion."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Missing data"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.missingDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.missingCount," grey gap",N.summary.missingCount===1?"":"s"," where Forge had over one hour without enough movement signal."]})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Repaired gaps"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.repairedGapDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.repairedGapCount," inferred span",N.summary.repairedGapCount===1?"":"s"," classified as stay or move instead of leaving blank holes in the day."]})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Continued stays"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.continuedStayDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.continuedStayCount," short stationary span",N.summary.continuedStayCount===1?"":"s"," carried forward so quiet home time stays continuous instead of disappearing."]})]})]})]})}),e.jsx(lr,{children:e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Selection aggregate"}),e.jsx(ce,{content:"When you select stays or trips, Forge totals their span, distance, work overlap, notes, and places here."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Select any combination of stays and trips to sum movement, time, and work evidence."}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Span"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.durationSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:ke(T.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Work overlap"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.trackedWorkSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.noteCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Estimated phone time"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.pickupCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.notificationCount})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:T.placeLabels.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i},i))}),T.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:T.topApps.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-info-soft)] text-[var(--ui-ink-medium)]",children:(i.displayName||i.bundleIdentifier)+" · "+H(i.totalActivitySeconds)},i.id))}):null,T.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:T.topCategories.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.categoryLabel},i.id))}):null]})})]}),s==="life"?e.jsx(or,{children:e.jsxs("section",{className:"grid gap-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Life graph"}),e.jsx(ce,{content:"This graph shows the movement road of your life: stays are blocks, moves connect them, and the hour/day lines live in the background. Click a segment for details, then use edit when you want to correct it."})]})}),e.jsx(Ns,{userIds:r})]})}):null,s==="day"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.55fr)_minmax(22rem,1fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Day strip"}),e.jsx(ce,{content:"A compressed 24-hour strip. Each segment keeps its true order and duration, but the whole day stays navigable on one line."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"A single-row timeline from 00:00 to 24:00, always compressed into one navigable strip."})]}),e.jsx(B,{type:"date",value:c,onChange:i=>m(i.target.value),className:"w-[11rem]"})]}),e.jsx("div",{className:"mt-6 overflow-x-auto pb-2",children:e.jsxs("div",{className:"w-full min-w-full sm:min-w-[52rem]",children:[e.jsx("div",{className:"mb-3 flex justify-between text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:["00:00","06:00","12:00","18:00","24:00"].map(i=>e.jsx("span",{children:i},i))}),e.jsx("div",{className:"flex h-28 items-stretch overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2",children:_.map((i,f)=>{const Q=Math.max(9,i.durationSeconds/86400*100),V=i.kind==="stay"?te.stayIds.includes(i.id):i.kind==="trip"?te.tripIds.includes(i.id):!1;return e.jsxs("button",{type:"button",className:w("relative flex min-w-0 flex-col justify-between rounded-[22px] border px-3 py-2 text-left transition sm:min-w-[5.5rem]",i.kind==="missing"?"border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":V?"border-[color-mix(in_srgb,var(--info)_34%,transparent)] bg-[var(--ui-info-soft)]":"border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]"),style:{width:`${Q}%`},onClick:()=>{i.kind!=="missing"&&Ve(M=>{const pe=new Set(M.stayIds),Ce=new Set(M.tripIds);return i.kind==="stay"?pe.has(i.id)?pe.delete(i.id):pe.add(i.id):Ce.has(i.id)?Ce.delete(i.id):(Ce.add(i.id),g(i.id)),{stayIds:[...pe],tripIds:[...Ce]}})},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(v,{tone:i.kind==="trip"?"signal":i.kind==="missing"?"meta":"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.kind==="missing"?"gap":i.kind}),e.jsx("span",{className:"text-[11px] text-[var(--ui-ink-muted)]",children:H(i.durationSeconds)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"line-clamp-2 text-sm font-semibold text-[var(--ui-ink-strong)]",children:i.label}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-muted)]",children:i.subtitle})]})]},`${i.kind}:${i.id}:${i.startedAt}:${i.endedAt}:${f}`)})})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:ks(c)}),e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[N.summary.tripCount," trips"]}),e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[N.summary.stayCount," stays"]}),e.jsxs(v,{tone:"meta",children:[N.summary.missingCount," gaps"]})]})]}),e.jsx("div",{className:"grid gap-4",children:y.data?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Selected trip"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4",onClick:()=>P(i=>!i),children:j?"Stylized graph":"Exact path"})})]}),j?e.jsx(Ls,{points:y.data.trip.points}):e.jsx(Ds,{curve:y.data.stylizedPath.curve,startLabel:y.data.stylizedPath.startLabel,endLabel:y.data.stylizedPath.endLabel,stopLabels:y.data.stylizedPath.stops.map(i=>i.label)}),e.jsxs(k,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Trip context"}),(()=>{const i=at(y.data.trip);return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:ke(y.data.trip.distanceMeters)}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:y.data.trip.activityType||y.data.trip.travelMode}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:H(y.data.trip.durationSeconds)}),e.jsx(v,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:rt(i.rateApPerHour)}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:ea(i.totalAp)})]})})})(),e.jsx("div",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:ws(y.data.trip.startedAt,y.data.trip.endedAt)}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Hourly estimate"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(y.data.trip.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y.data.trip.pickupCount})]}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y.data.trip.notificationCount})]})]}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-[var(--ui-ink-muted)]",children:"Derived from Screen Time hourly bins, not exact foreground traces."}),y.data.trip.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:y.data.trip.topApps.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-info-soft)] text-[var(--ui-ink-medium)]",children:(i.displayName||i.bundleIdentifier)+" · "+H(i.totalActivitySeconds)},i.id))}):null,y.data.trip.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:y.data.trip.topCategories.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.categoryLabel},i.id))}):null]})]}):e.jsx(k,{className:"rounded-[30px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-6 text-[var(--ui-ink-muted)]",children:"Select a trip segment to open the stylized trajectory card and exact path toggle."})})]}):null,s==="month"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(18rem,0.85fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Month view"}),e.jsx(ce,{content:"This chart stays quantitative. Switch the metric to compare daily distance, moving time, idle time, or calories across the month."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Switch the Y-axis between motion, idle time, and energy without losing the same monthly frame."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(B,{type:"month",value:d,onChange:i=>u(i.target.value),className:"w-[10.5rem]"}),["distanceMeters","movingSeconds","idleSeconds","caloriesKcal"].map(i=>e.jsx(A,{variant:"ghost",className:w("h-9 rounded-full border px-4 text-sm",Me===i?"border-[var(--primary)] bg-[var(--primary)]/14 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),onClick:()=>gt(i),children:i==="distanceMeters"?"Distance":i==="movingSeconds"?"Moving":i==="idleSeconds"?"Idle":"Calories"},i))]})]}),e.jsx("div",{className:"mt-6 h-[24rem]",children:e.jsx(br,{width:"100%",height:"100%",children:e.jsxs(yr,{data:be.days,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"movementMonthFill",x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--info)",stopOpacity:.7}),e.jsx("stop",{offset:"100%",stopColor:"var(--info)",stopOpacity:.08})]})}),e.jsx(jr,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(Nr,{dataKey:"dateKey",tick:{fill:"var(--ui-ink-muted)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(kr,{tick:{fill:"var(--ui-ink-muted)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(wr,{contentStyle:{background:"var(--ui-surface-modal)",border:"1px solid var(--ui-border-subtle)",borderRadius:16},itemStyle:{color:"var(--ui-ink-strong)"},labelStyle:{color:"var(--ui-ink-medium)"},formatter:i=>Ss(Me,Number(i))}),e.jsx(Sr,{type:"monotone",dataKey:Me,stroke:"var(--info)",fill:"url(#movementMonthFill)",strokeWidth:2.4})]})})})]}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Month totals"}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:ke(be.totals.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Moving time"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:H(be.totals.movingSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Settled time"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:H(be.totals.idleSeconds)})]})]})]})]}):null,s==="all_time"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(20rem,0.95fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Trips"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.tripCount})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.knownPlaceCount})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:ke(oe.summary.totalDistanceMeters)})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Countries"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.visitedCountries})]})]}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:oe.recentTrips.map(i=>e.jsx("button",{type:"button",className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-left transition hover:bg-[var(--ui-surface-3)]",onClick:()=>{l("day"),g(i.id)},children:(()=>{const f=at({startedAt:i.startedAt,endedAt:new Date(new Date(i.startedAt).getTime()+36e5).toISOString(),expectedMet:2});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent travel"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:i.label||"Untitled trip"}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[ke(i.distanceMeters)," · ",i.activityType||"travel"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(v,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:rt(f.rateApPerHour)})})]})})()},i.id))})]}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Place categories"}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:oe.categoryBreakdown.map(i=>e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[i.tag," · ",i.count]},i.tag))})]})]}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(22rem,0.95fr)]",children:[e.jsx(dr,{children:e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx(ce,{content:"Known places turn raw stationary spans into named contexts like home, work, gym, nature, or any custom place tag you want Forge to remember."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"These landmarks anchor stays, travel XP, and contextual reasoning in both Forge and the companion. Seeded tags like home, workplace, gym, holiday, grocery, or nature matter for downstream calculations, but place tags stay open-ended."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{value:Se,onChange:i=>ht(i.target.value),placeholder:"Search places",className:"w-[11rem]"}),e.jsx(A,{onClick:()=>{Ye(null),_e(!0)},children:"Add place"})]})]}),e.jsx("div",{className:"mt-5 grid gap-3",children:ve.map(i=>e.jsxs("button",{type:"button",className:"flex items-start justify-between gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-left transition hover:bg-[var(--ui-surface-3)]",onClick:()=>{Ye(i),_e(!0)},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:i.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[i.latitude.toFixed(4),", ",i.longitude.toFixed(4)," · radius ",Math.round(i.radiusMeters)," m"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:i.categoryTags.map(f=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:f},f))})]}),e.jsx(It,{className:"mt-1 size-4 text-[var(--ui-ink-muted)]"})]},i.id))})]})}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Movement help"}),e.jsx(ce,{content:"Most movement surfaces on this page have help buttons. Use them to understand the graph, the day strip, the month chart, and the place system without keeping a large prose block on screen."})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Use the small help icons across this page for graph explanations, timeline semantics, and metric meanings."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Life graph"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Day strip"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Month chart"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Known places"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Selection aggregate"})]})]})]}),y.data?e.jsx(wa,{open:U,onOpenChange:i=>{b(i),i||(F(""),Z([]),J(null),ee(null))},eyebrow:"Movement data",title:y.data.trip.label||"Trip datapoints",description:"Inspect the raw datapoints behind this trip. Raw measurements are read-only here; visible movement corrections now happen through canonical user-defined boxes.",children:e.jsx(cr,{children:e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,24rem)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ma,{title:"Datapoint browser",description:"Search raw points by time band, anchor status, or accuracy before opening the point editor.",query:C,onQueryChange:F,options:Je,selectedOptionIds:K,onSelectedOptionIdsChange:Z,resultSummary:Oe,placeholder:"Search timestamps, accuracy, point ids, or filter chips",emptyStateMessage:"Keep typing or pick a time/quality chip to narrow the trip datapoints."}),e.jsxs(k,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw datapoints"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Open a point to correct or delete it."})]}),e.jsx(v,{tone:"meta",children:Oe})]}),e.jsx("div",{ref:ze,className:"h-[34rem] overflow-y-auto rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:O.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No datapoint matches the current search. Clear some filters or search by time, anchor type, or accuracy."}):e.jsx("div",{className:"relative w-full",style:{height:`${Ae.getTotalSize()}px`},children:Ae.getVirtualItems().map(i=>{const f=O[i.index];return e.jsx("div",{className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${i.start}px)`},children:e.jsxs("button",{type:"button",className:w("grid w-full gap-3 rounded-[20px] border px-4 py-3 text-left transition",z===f.id?"border-[color-mix(in_srgb,var(--info)_34%,transparent)] bg-[var(--ui-info-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:bg-[var(--ui-surface-3)]"),onClick:()=>{J(f.id),ee(ha(f))},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Xa,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:Rt(f.recordedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[f.latitude.toFixed(5),", ",f.longitude.toFixed(5)]})]}),e.jsx(v,{tone:f.isStopAnchor?"signal":"meta",children:f.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:pt(f.recordedAt)}),f.accuracyMeters!=null?e.jsxs(v,{tone:"meta",children:[Math.round(f.accuracyMeters)," m accuracy"]}):null,f.speedMps!=null?e.jsxs(v,{tone:"meta",children:[f.speedMps.toFixed(1)," m/s"]}):null]})]})},f.id)})})})]})]}),D&&G?e.jsx($s,{point:D,draft:G}):e.jsx(k,{className:"rounded-[28px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-6 text-[var(--ui-ink-muted)]",children:"Pick a datapoint to inspect its raw measurement details. To correct what the user sees, use canonical user-defined movement boxes in the Life Timeline."})]})})}):null,e.jsx(Aa,{open:Fe,onOpenChange:_e,place:Re,onSave:async i=>{await Ze.mutateAsync(i)}})]})}export{Us as MovementPage};
@@ -1 +0,0 @@
1
- import{j as i}from"./vendor-Dnkkx2co.js";import{m as c,c as s}from"./index-QJkjKYzZ.js";const m=[{value:"Working memory",label:"Working memory",description:"What you are actively working on right now."},{value:"Short-term memory",label:"Short-term memory",description:"What just happened and still needs near-term recall."},{value:"Episodic memory",label:"Episodic memory",description:"Long-term recall for what happened or what you did."},{value:"Semantic memory",label:"Semantic memory",description:"Long-term knowledge about what something is."},{value:"Procedural memory",label:"Procedural memory",description:"Long-term know-how and repeatable how-to knowledge."}];function l(o){const r=new Set;return o.map(t=>t.trim()).filter(Boolean).filter(t=>{const a=t.toLowerCase();return r.has(a)?!1:(r.add(a),!0)})}function p(o){const r=o.trim();if(!r)return null;const t=new Date(r);return Number.isNaN(t.getTime())?null:t.toISOString()}function f(o){if(!o)return"";const r=new Date(o);if(Number.isNaN(r.getTime()))return"";const t=r.getFullYear(),a=String(r.getMonth()+1).padStart(2,"0"),e=String(r.getDate()).padStart(2,"0"),u=String(r.getHours()).padStart(2,"0"),n=String(r.getMinutes()).padStart(2,"0");return`${t}-${a}-${e}T${u}:${n}`}function v(o,r){const t=Number(o);if(!Number.isFinite(t)||t<=0)return null;const a=r==="hours"?3600*1e3:1440*60*1e3;return new Date(Date.now()+t*a).toISOString()}function d(o){const r=new Set(m.map(e=>e.value.toLowerCase())),t=m.map(e=>({value:e.value,label:e.label,description:e.description,searchText:`${e.label} ${e.description}`,badge:i.jsx(s,{className:"border border-[color-mix(in_srgb,var(--info)_32%,var(--ui-border-subtle)_68%)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_74%,var(--ui-ink-strong)_26%)]",children:e.label}),menuBadge:i.jsx(s,{className:"border border-[color-mix(in_srgb,var(--info)_32%,var(--ui-border-subtle)_68%)] bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_74%,var(--ui-ink-strong)_26%)]",children:e.label})})),a=l(o).filter(e=>!r.has(e.toLowerCase())).map(e=>({value:e,label:e,description:"Custom note tag",searchText:e,badge:i.jsx(s,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:e}),menuBadge:i.jsx(s,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:e})}));return[...t,...a]}function h({value:o,onChange:r,availableTags:t=[],placeholder:a="Add a memory tag or create a custom tag"}){const e=d([...t,...o]);return i.jsx(c,{options:e,selectedValues:l(o),onChange:u=>r(l(u)),placeholder:a,emptyMessage:"No note tags yet.",createLabel:"Add custom tag",onCreate:async u=>{const n=u.trim();return{value:n,label:n,description:"Custom note tag",searchText:n,badge:i.jsx(s,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:n}),menuBadge:i.jsx(s,{className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:n})}}})}export{h as N,v as b,f,l as n,p};