forge-openclaw-plugin 0.2.102 → 0.2.104

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 (175) hide show
  1. package/dist/assets/activity-page-Dv6X5ZCV.js +1 -0
  2. package/dist/assets/{ai-surface-workspace-xtB5RFQu.js → ai-surface-workspace-CutiG6uS.js} +1 -1
  3. package/dist/assets/{atlas-panel-B3dPHCmZ.js → atlas-panel-jgMRyaHn.js} +1 -1
  4. package/dist/assets/{board-DqHzdCPQ.js → board-dIX6etHh.js} +1 -1
  5. package/dist/assets/calendar-page-q7Nm5E2U.js +1 -0
  6. package/dist/assets/calendar-rules-DPFsfiRl.js +1 -0
  7. package/dist/assets/{calendar-week-toolbar-BZ_-X3Wb.js → calendar-week-toolbar-nVhgB-0s.js} +1 -1
  8. package/dist/assets/{charts-FcU0F3XV.js → charts-DFnEuIMB.js} +1 -1
  9. package/dist/assets/companion-sync-lab-page-CJ8UTij8.js +1 -0
  10. package/dist/assets/{daily-metrics-dashboard-BMyL0Qr4.js → daily-metrics-dashboard-CiJkkkd1.js} +1 -1
  11. package/dist/assets/entity-note-count-link-RzBB6ujx.js +1 -0
  12. package/dist/assets/{entity-notes-surface-CBylYDwy.js → entity-notes-surface-Djz50HvD.js} +1 -1
  13. package/dist/assets/execution-board-CtPhI-58.js +1 -0
  14. package/dist/assets/{faceted-token-search-D7xPWfOl.js → faceted-token-search-DEC6ANa9.js} +1 -1
  15. package/dist/assets/{flagship-signal-deck-BEFKOhvx.js → flagship-signal-deck-CtHC3mql.js} +1 -1
  16. package/dist/assets/floating-action-menu-CKQRhff9.js +1 -0
  17. package/dist/assets/{forms-CmLAyGqz.js → forms-hB0SqEh-.js} +1 -1
  18. package/dist/assets/goal-detail-page-CF5fNQeR.js +1 -0
  19. package/dist/assets/goals-page-fsY8NzGB.js +1 -0
  20. package/dist/assets/{graph-BTa79qum.js → graph-DDUZNRsO.js} +1 -1
  21. package/dist/assets/habits-page-COoGz4kj.js +1 -0
  22. package/dist/assets/index-BAXYM89v.css +1 -0
  23. package/dist/assets/index-EqQsXoat.js +19 -0
  24. package/dist/assets/{insight-flow-dialog-BtIQXXsS.js → insight-flow-dialog-DtX_5W7g.js} +1 -1
  25. package/dist/assets/insights-page-cBd74ObU.js +8 -0
  26. package/dist/assets/kanban-page-CYav9THw.js +1 -0
  27. package/dist/assets/knowledge-graph-page-D2A-W1jE.js +1 -0
  28. package/dist/assets/{life-force-page-BGDkKfbJ.js → life-force-page-CACGlNhq.js} +1 -1
  29. package/dist/assets/life-force-workspace-BJ4N1I78.js +1 -0
  30. package/dist/assets/{maps-CF1RagUX.js → maps-C-yOWiDN.js} +1 -1
  31. package/dist/assets/{metric-tile-4iMd_WnJ.js → metric-tile-CMadwnGz.js} +1 -1
  32. package/dist/assets/{motion-CfdU2F35.js → motion-Lt5B1XuE.js} +1 -1
  33. package/dist/assets/movement-page-D5VqFd2q.js +1 -0
  34. package/dist/assets/{note-markdown-CsGQhQXF.js → note-markdown-BzK2Qlgr.js} +1 -1
  35. package/dist/assets/{note-tags-input-DdZi93tj.js → note-tags-input-CZzqJMLc.js} +1 -1
  36. package/dist/assets/notes-page-D3Hsh90C.js +1 -0
  37. package/dist/assets/{open-in-graph-button-C0TGev7c.js → open-in-graph-button-BFPKfyK3.js} +1 -1
  38. package/dist/assets/{orbit-map-DVXkfQdd.js → orbit-map-CnyfSmOG.js} +1 -1
  39. package/dist/assets/{overview-page-BwMlFQKX.js → overview-page-CXdWrOV1.js} +1 -1
  40. package/dist/assets/{page-hero-oFHaAjtL.js → page-hero-ffKzgyW3.js} +1 -1
  41. package/dist/assets/pill-cluster-C2D0h3lx.js +1 -0
  42. package/dist/assets/{preference-entity-handoff-button-DOKV9bZc.js → preference-entity-handoff-button-Dj3V6VxL.js} +1 -1
  43. package/dist/assets/preferences-page-Jo8Gw386.js +1 -0
  44. package/dist/assets/project-collections-qSqp90HN.js +1 -0
  45. package/dist/assets/{project-detail-page-DogvVNEn.js → project-detail-page-BifhiLQX.js} +1 -1
  46. package/dist/assets/project-management-hierarchy-page-DZ_9klIc.js +1 -0
  47. package/dist/assets/project-management-section-nav-BImLCVvf.js +1 -0
  48. package/dist/assets/projects-page-ptcx6H38.js +1 -0
  49. package/dist/assets/{psyche-behaviors-page-BeVlXvbj.js → psyche-behaviors-page-BDwXyDta.js} +1 -1
  50. package/dist/assets/{psyche-flashcards-page-CqAWCO4E.js → psyche-flashcards-page-DL1BP1jX.js} +1 -1
  51. package/dist/assets/{psyche-goal-map-page-IyNnbk_W.js → psyche-goal-map-page-ovcpisx1.js} +1 -1
  52. package/dist/assets/{psyche-graph-IkUQRaDK.js → psyche-graph-EP5GL612.js} +1 -1
  53. package/dist/assets/{psyche-metrics-page-uai0a7Lx.js → psyche-metrics-page-Bcu813Rg.js} +1 -1
  54. package/dist/assets/{psyche-mode-guide-page-C7p-ABiF.js → psyche-mode-guide-page-C0g27Xpt.js} +1 -1
  55. package/dist/assets/{psyche-modes-page-CLQ5V3w0.js → psyche-modes-page-BjKjX5MR.js} +1 -1
  56. package/dist/assets/{psyche-page-NQBHkkpU.js → psyche-page-F4tF2W70.js} +1 -1
  57. package/dist/assets/{psyche-patterns-page-BkRiNpI_.js → psyche-patterns-page-B-14hukK.js} +1 -1
  58. package/dist/assets/{psyche-questionnaire-builder-page-Du-7HwPC.js → psyche-questionnaire-builder-page-BdXmoHvK.js} +1 -1
  59. package/dist/assets/{psyche-questionnaire-detail-page-C5-yf8MF.js → psyche-questionnaire-detail-page-Cu5uwlJu.js} +1 -1
  60. package/dist/assets/{psyche-questionnaire-run-detail-page-CoSH5O6R.js → psyche-questionnaire-run-detail-page-C3R4PClg.js} +1 -1
  61. package/dist/assets/{psyche-questionnaire-run-page-ChI7c1wy.js → psyche-questionnaire-run-page-Div3iDdt.js} +1 -1
  62. package/dist/assets/{psyche-questionnaires-page-xUcJJzbI.js → psyche-questionnaires-page-DpqAPQCp.js} +1 -1
  63. package/dist/assets/{psyche-report-detail-page-BPrZCFZS.js → psyche-report-detail-page-BvWVDKP3.js} +1 -1
  64. package/dist/assets/{psyche-reports-page-D2EXJmm6.js → psyche-reports-page-BrbWUlAq.js} +1 -1
  65. package/dist/assets/{psyche-schemas-RcZYaokx.js → psyche-schemas-Dxj554nU.js} +1 -1
  66. package/dist/assets/{psyche-schemas-beliefs-page-h0ooZ1lp.js → psyche-schemas-beliefs-page-DYKvAtSD.js} +1 -1
  67. package/dist/assets/{psyche-screen-time-page-_3-4LikV.js → psyche-screen-time-page-CAOKCyQw.js} +1 -1
  68. package/dist/assets/{psyche-self-observation-page-BdbCsgR5.js → psyche-self-observation-page-F0MVA0UH.js} +1 -1
  69. package/dist/assets/{psyche-values-page-DuUVki5e.js → psyche-values-page-DyvX-d0o.js} +1 -1
  70. package/dist/assets/{report-chain-fields-BBMz0sGI.js → report-chain-fields-CeC1cJFS.js} +1 -1
  71. package/dist/assets/rewards-page-C2loyODo.js +1 -0
  72. package/dist/assets/scheduling-rules-editor-D40AC2jR.js +1 -0
  73. package/dist/assets/{schema-badge-D93RcG36.js → schema-badge-FY7818qB.js} +1 -1
  74. package/dist/assets/{select-menu-Cdq7foRu.js → select-menu-DJsCG6rM.js} +1 -1
  75. package/dist/assets/settings-agents-page-BFkJ5AAD.js +6 -0
  76. package/dist/assets/settings-bin-page-D3-Ab-iA.js +1 -0
  77. package/dist/assets/settings-calendar-page-ly_mSTAD.js +5 -0
  78. package/dist/assets/settings-data-page-D7QOqNf-.js +1 -0
  79. package/dist/assets/settings-logs-page-Ca87HEUx.js +1 -0
  80. package/dist/assets/settings-mobile-page-D0jejZot.js +1 -0
  81. package/dist/assets/settings-models-page-DPDsZjSc.js +1 -0
  82. package/dist/assets/settings-page-1cArlSPM.js +1 -0
  83. package/dist/assets/settings-rewards-page-Db4BV1DC.js +1 -0
  84. package/dist/assets/{settings-section-nav-Dc4IeVBt.js → settings-section-nav-DP9o4peU.js} +1 -1
  85. package/dist/assets/settings-users-page-BHFyDSsd.js +1 -0
  86. package/dist/assets/settings-wiki-page-BNaiupBm.js +1 -0
  87. package/dist/assets/sleep-page-BmOPF0yD.js +1 -0
  88. package/dist/assets/sports-page-BldIiclr.js +1 -0
  89. package/dist/assets/{state-VYvD1QVP.js → state-vCcAT5Hq.js} +1 -1
  90. package/dist/assets/strategies-page-CaTN99qj.js +1 -0
  91. package/dist/assets/strategy-detail-page-DsgFTd-U.js +1 -0
  92. package/dist/assets/{strategy-dialog-DMyRKrWf.js → strategy-dialog-7X7peRzu.js} +1 -1
  93. package/dist/assets/{surface-Bfz_sLX6.js → surface-CJI17F3n.js} +1 -1
  94. package/dist/assets/{table-C0VTeqw0.js → table-BNqMG3_S.js} +1 -1
  95. package/dist/assets/task-detail-page-M1sIIPA8.js +1 -0
  96. package/dist/assets/timebox-planning-dialog-ByojN0AN.js +1 -0
  97. package/dist/assets/today-page-BjDijtn8.js +1 -0
  98. package/dist/assets/training-load-page-BPRmaWmF.js +1 -0
  99. package/dist/assets/{ui-CsEkP2V8.js → ui-C1iwpj2-.js} +1 -1
  100. package/dist/assets/{use-psyche-focus-target-qxT5Oy_z.js → use-psyche-focus-target-Ct-acS9G.js} +1 -1
  101. package/dist/assets/{vendor-kIz9EZnX.js → vendor-Dnkkx2co.js} +3 -3
  102. package/dist/assets/{vitals-page-Dz1Jt5H8.js → vitals-page-CE9zdGLF.js} +1 -1
  103. package/dist/assets/weekly-review-page-CzhTv90n.js +1 -0
  104. package/dist/assets/weight-loss-page-Bp_cIk78.js +5 -0
  105. package/dist/assets/wiki-article-markdown-Dok2uy2p.js +4 -0
  106. package/dist/assets/wiki-editor-page-BuW32Y3f.js +26 -0
  107. package/dist/assets/wiki-ingest-history-page-DZKSBNHV.js +1 -0
  108. package/dist/assets/wiki-ingest-modal-DyqBEZcC.js +1 -0
  109. package/dist/assets/wiki-page-DqxlbLKG.js +1 -0
  110. package/dist/assets/workbench-flow-page-C4nc9jUg.js +5 -0
  111. package/dist/assets/workbench-page-BnyR7SL0.js +1 -0
  112. package/dist/assets/{workout-detail-page-DD9IGN6l.js → workout-detail-page-DT-c5cHL.js} +2 -2
  113. package/dist/index.html +9 -9
  114. package/dist/server/server/src/app.js +22 -3
  115. package/dist/server/server/src/health-weight-loss.js +114 -39
  116. package/dist/server/server/src/repositories/model-settings.js +9 -3
  117. package/dist/server/server/src/watch-mobile.js +28 -0
  118. package/dist/server/src/components/workbench-boxes/shared/generic-node-view.js +13 -5
  119. package/dist/server/src/lib/api.js +10 -1
  120. package/openclaw.plugin.json +1 -1
  121. package/package.json +1 -1
  122. package/dist/assets/activity-page-CgF7K2ww.js +0 -1
  123. package/dist/assets/calendar-page-C1Wfd2Fy.js +0 -1
  124. package/dist/assets/calendar-rules-CaZXtlxt.js +0 -1
  125. package/dist/assets/companion-sync-lab-page-NgeK-O-P.js +0 -1
  126. package/dist/assets/entity-note-count-link-BrS1-O0o.js +0 -1
  127. package/dist/assets/execution-board-CpO2ch6v.js +0 -1
  128. package/dist/assets/floating-action-menu-zzC2r0Ob.js +0 -1
  129. package/dist/assets/goal-detail-page-JK_Nva8e.js +0 -1
  130. package/dist/assets/goals-page-yeoJ06Vw.js +0 -1
  131. package/dist/assets/habits-page-Dx5EhkJi.js +0 -1
  132. package/dist/assets/index-BHIKoiZ6.js +0 -19
  133. package/dist/assets/index-H8R-ABM3.css +0 -1
  134. package/dist/assets/insights-page-CujrosD_.js +0 -8
  135. package/dist/assets/kanban-page-Q9NuIz5w.js +0 -1
  136. package/dist/assets/knowledge-graph-page-DaJmlvvM.js +0 -1
  137. package/dist/assets/life-force-workspace-CLVexVnb.js +0 -1
  138. package/dist/assets/movement-page-ClaoTNuX.js +0 -1
  139. package/dist/assets/notes-page-DYI8s3NN.js +0 -1
  140. package/dist/assets/pill-cluster-7UZd_lHp.js +0 -1
  141. package/dist/assets/preferences-page-BrKEkmfD.js +0 -1
  142. package/dist/assets/project-collections-CZagCmeH.js +0 -1
  143. package/dist/assets/project-management-hierarchy-page-Dr7hW9PW.js +0 -1
  144. package/dist/assets/project-management-section-nav-BLdAgTge.js +0 -1
  145. package/dist/assets/projects-page-UKrby_5-.js +0 -1
  146. package/dist/assets/rewards-page-PZFPa6rR.js +0 -1
  147. package/dist/assets/scheduling-rules-editor-B9KNKsQz.js +0 -1
  148. package/dist/assets/settings-agents-page-DPx2F6wf.js +0 -6
  149. package/dist/assets/settings-bin-page-COwP3gjo.js +0 -1
  150. package/dist/assets/settings-calendar-page-C-ghE0YT.js +0 -5
  151. package/dist/assets/settings-data-page-CBubzKBw.js +0 -1
  152. package/dist/assets/settings-logs-page-uOuXMeBm.js +0 -1
  153. package/dist/assets/settings-mobile-page-C5rfj8_r.js +0 -1
  154. package/dist/assets/settings-models-page-DijmUWdU.js +0 -1
  155. package/dist/assets/settings-page-B4u5TR5g.js +0 -1
  156. package/dist/assets/settings-rewards-page-COiTwkMH.js +0 -1
  157. package/dist/assets/settings-users-page-DEGa5DNn.js +0 -1
  158. package/dist/assets/settings-wiki-page-Cvsiz5_e.js +0 -1
  159. package/dist/assets/sleep-page-BnSOwkEU.js +0 -1
  160. package/dist/assets/sports-page-l1RqXzA_.js +0 -1
  161. package/dist/assets/strategies-page-DEnPlpAs.js +0 -1
  162. package/dist/assets/strategy-detail-page-Ls8bxKeH.js +0 -1
  163. package/dist/assets/task-detail-page-CgrYgQLD.js +0 -1
  164. package/dist/assets/timebox-planning-dialog-Ww0NGLLo.js +0 -1
  165. package/dist/assets/today-page-CIuFHMi1.js +0 -1
  166. package/dist/assets/training-load-page-BIwc648i.js +0 -1
  167. package/dist/assets/weekly-review-page-BFpBe1kI.js +0 -1
  168. package/dist/assets/weight-loss-page-BgMoBpBt.js +0 -5
  169. package/dist/assets/wiki-article-markdown-gsPTXTg1.js +0 -4
  170. package/dist/assets/wiki-editor-page-BpAZHooY.js +0 -26
  171. package/dist/assets/wiki-ingest-history-page-C-ig8O22.js +0 -1
  172. package/dist/assets/wiki-ingest-modal-BK4eQgqs.js +0 -1
  173. package/dist/assets/wiki-page-CMTZ60Zt.js +0 -1
  174. package/dist/assets/workbench-flow-page-BIpWUcLJ.js +0 -5
  175. package/dist/assets/workbench-page-CtCjYSRe.js +0 -1
@@ -1 +0,0 @@
1
- import{r as x,j as e,aK as Lt,c4 as It,bg as $t,cq as ga,c3 as va,aZ as nt,cr as Nt,F as Ua,bX as Wa,b4 as Ga,cs as fa,ct as Va,c7 as Ya,bc as Xa}from"./vendor-kIz9EZnX.js";import{j as ba,x as Vt,i as te,k as Ce}from"./state-VYvD1QVP.js";import{I as O,B as A,Z as k,c as h,C as N,aY as Yt,aZ as Xt,a_ as wa,a$ as Za,b0 as Ja,S as ya,E as ja,aT as Na,b1 as es,b2 as Zt,b3 as ts,b4 as Sa,b5 as as,u as ss,b6 as is,b7 as rs,b8 as et,h as Jt,d as tt,b9 as ns,aq as ce,ba as ls,bb as os,bc as ds,bd as cs,be as ms,bf as us,bg as xs,O as hs,bh as ps,bi as gs,bj as vs}from"./index-BHIKoiZ6.js";import{F as ka}from"./faceted-token-search-D7xPWfOl.js";import{P as fs}from"./page-hero-oFHaAjtL.js";import{R as qe,P as Qe,O as Ue,C as We,T as ct,D as mt,a as ut}from"./ui-CsEkP2V8.js";import{m as ea}from"./motion-CfdU2F35.js";import{S as ue}from"./surface-Bfz_sLX6.js";import{R as bs,A as ws,C as ys,X as js,Y as Ns,T as Ss,a as ks}from"./charts-FcU0F3XV.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";import"./graph-BTa79qum.js";function Ma({open:t,onOpenChange:a,place:s,seed:i,onSave:l}){const[c,u]=x.useState({label:(s==null?void 0:s.label)??(i==null?void 0:i.label)??"",latitude:String((s==null?void 0:s.latitude)??(i==null?void 0:i.latitude)??""),longitude:String((s==null?void 0:s.longitude)??(i==null?void 0:i.longitude)??""),radiusMeters:String((s==null?void 0:s.radiusMeters)??(i==null?void 0:i.radiusMeters)??100),categoryTags:((s==null?void 0:s.categoryTags)??(i==null?void 0:i.categoryTags)??[]).join(", ")});return x.useEffect(()=>{u({label:(s==null?void 0:s.label)??(i==null?void 0:i.label)??"",latitude:String((s==null?void 0:s.latitude)??(i==null?void 0:i.latitude)??""),longitude:String((s==null?void 0:s.longitude)??(i==null?void 0:i.longitude)??""),radiusMeters:String((s==null?void 0:s.radiusMeters)??(i==null?void 0:i.radiusMeters)??100),categoryTags:((s==null?void 0:s.categoryTags)??(i==null?void 0:i.categoryTags)??[]).join(", ")})},[s,i]),e.jsx(qe,{open:t,onOpenChange:a,children:e.jsxs(Qe,{children:[e.jsx(Ue,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(We,{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(ct,{className:"font-display text-[1.3rem] tracking-normal text-[var(--ui-ink-strong)]",children:s?`Edit ${s.label}`:"New known place"}),e.jsx(mt,{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(ut,{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(Lt,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(O,{value:c.label,onChange:d=>u(m=>({...m,label:d.target.value})),placeholder:"Home, Main Office, Riverside path..."}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(O,{value:c.latitude,onChange:d=>u(m=>({...m,latitude:d.target.value})),placeholder:"Latitude"}),e.jsx(O,{value:c.longitude,onChange:d=>u(m=>({...m,longitude:d.target.value})),placeholder:"Longitude"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[10rem_minmax(0,1fr)]",children:[e.jsx(O,{value:c.radiusMeters,onChange:d=>u(m=>({...m,radiusMeters:d.target.value})),placeholder:"Radius meters"}),e.jsx(O,{value:c.categoryTags,onChange:d=>u(m=>({...m,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:s==null?void 0:s.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 L(t){return new Date(t).getTime()}function kt(t){return new Date(t).toISOString()}function ta(t,a){const s=L(t.startedAt)-L(a.startedAt);if(s!==0)return s;const i=L(t.endedAt)-L(a.endedAt);return i!==0?i:t.id.localeCompare(a.id)}function Et(t){return t.syncSource==="sleep overlay"}function Ms(t){const a=[...t].filter(i=>L(i.endedAt)>L(i.startedAt)).sort((i,l)=>{const c=L(i.startedAt)-L(l.startedAt);if(c!==0)return c;const u=L(i.endedAt)-L(l.endedAt);return u!==0?u:i.id.localeCompare(l.id)});if(a.length===0)return[];const s=[];for(const i of a){const l=s.at(-1);if(!l){s.push(i);continue}const c=L(l.endedAt);if(L(i.startedAt)<=c+St){const d=Math.max(c,L(i.endedAt));s[s.length-1]={...l,id:`${l.id}__${i.id}`,endedAt:kt(d),asleepSeconds:(l.asleepSeconds??0)+(i.asleepSeconds??0)||null,timeInBedSeconds:(l.timeInBedSeconds??0)+(i.timeInBedSeconds??0)||null,sleepScore:i.sleepScore??l.sleepScore,regularityScore:i.regularityScore??l.regularityScore,efficiency:i.efficiency??l.efficiency,recoveryState:i.recoveryState??l.recoveryState};continue}s.push(i)}return s}function As(t){const a=[];if(typeof t.asleepSeconds=="number"&&t.asleepSeconds>0){const s=t.asleepSeconds/3600;a.push(`${s.toFixed(s>=1?1:2)}h asleep`)}else if(typeof t.timeInBedSeconds=="number"&&t.timeInBedSeconds>0){const s=t.timeInBedSeconds/3600;a.push(`${s.toFixed(s>=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 Cs(t){const a=Math.max(60,Math.round((L(t.endedAt)-L(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:As(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 aa(t,a,s){if(s<=a)return null;const i=kt(a),l=kt(s),c=Math.max(60,Math.round((s-a)/1e3));return{...t,id:`${t.id}::virtual-${a}-${s}`,startedAt:i,endedAt:l,trueStartedAt:i,trueEndedAt:l,visibleStartedAt:i,visibleEndedAt:l,durationSeconds:c,cursor:`${l}::${t.id}::virtual`}}function Ts(t,a){let s=[...t].sort(ta);for(const i of Ms(a)){const l=L(i.startedAt),c=L(i.endedAt),u=Cs(i),d=[];let m=!1;for(const p of s){const f=L(p.startedAt),y=L(p.endedAt);if(y<=l||f>=c){!m&&f>=c&&(d.push(u),m=!0),d.push(p);continue}if(f<l){const T=aa(p,f,Math.min(y,l-St));T&&d.push(T)}if(m||(d.push(u),m=!0),y>c){const T=aa(p,Math.max(f,c+St),y);T&&d.push(T)}}m||d.push(u),s=d.sort(ta)}return s}const sa=24,G=64,Mt=360*60,Aa=5,yt=1,Ps=104,ia=G*8;function pe(t){return t.trim().toLowerCase()}function Ke(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 Ca(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit"}).format(new Date(t))}function Ds(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:!1}).format(t)}function De(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const s=a.getFullYear(),i=String(a.getMonth()+1).padStart(2,"0"),l=String(a.getDate()).padStart(2,"0"),c=String(a.getHours()).padStart(2,"0"),u=String(a.getMinutes()).padStart(2,"0");return`${s}-${i}-${l}T${c}:${u}`}function lt(t){if(!t.trim())return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toISOString()}function Le(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function W(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function ra(t,a){return`${t.toFixed(3)}, ${a.toFixed(3)}`}function at(t,a){return`${t.toFixed(6)}, ${a.toFixed(6)}`}function na(t){return`${Math.max(1,Math.round(t/60))} min`}function Ls(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),s=Math.max(...t.map(d=>d.latitude)),i=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(s-a,1e-4),u=Math.max(l-i,1e-4);return t.map((d,m)=>({...d,x:12+(d.longitude-i)/u*76,y:12+(1-(d.latitude-a)/c)*76,id:`${d.recordedAt??"point"}-${m}`}))}function ot(t){return t.kind==="trip"&&t.trip!==null}function le(t){return t.kind==="stay"&&t.stay!==null}function At(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 Ie(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 rt(t,a,s,i){const c=(s-t)*Math.PI/180,u=(i-a)*Math.PI/180,d=t*Math.PI/180,m=s*Math.PI/180,p=Math.sin(c/2)**2+Math.cos(d)*Math.cos(m)*Math.sin(u/2)**2;return 2*6371e3*Math.asin(Math.sqrt(p))}function Is(t){return pe([t.label,...t.aliases].join(" "))}function Ne(t,a,s){if(!t.trip)return{label:t.placeLabel??(a==="start"?"Known origin":"Known destination"),detail:W(a==="start"?t.startedAt:t.endedAt)};const i=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=(s==null?void 0:s.includeCoordinates)??!0,u=s!=null&&s.useHistoryAnchorFallback&&a==="start"?"Beginning of history":null;return{label:(l==null?void 0:l.label)??u??(c&&i?ra(i.latitude,i.longitude):a==="start"?"Unknown origin":"Unknown destination"),detail:c&&i&&!l?ra(i.latitude,i.longitude):W(a==="start"?t.startedAt:t.endedAt)}}function $s(t){const a=t.trim().toLowerCase();return a==="travel"||a==="trip"||a==="move"}function Es(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 Fs(t){const a=Ie(t),s=t.title.trim().toLowerCase(),i=s.length===0||s==="stay"||s==="continued stay"||s==="repaired stay"||s==="manual stay";return a&&i?a:t.title.trim()||a||"Stay"}function me(t){if(Et(t))return"Sleep";if(t.kind==="missing")return Es(t);if(t.kind==="stay")return Fs(t);if(t.kind==="trip"&&$s(t.title)){const a=Ne(t,"start").label,s=Ne(t,"end").label;return`${a} → ${s}`}return t.title}function la(t){return t==="left"?24:t==="right"?76:50}function _s(t,a,s){const i=Math.min(t,Mt)/3600,l=s==="sleep overlay",c=l?112:a==="stay"?104:92,u=l?272:a==="stay"?288:232,d=c+i*30;return Math.max(c,Math.min(u,d))}function Ct(t){var a;return{kind:t.kind,label:le(t)?t.stay.label||t.title:ot(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:De(t.startedAt),endedAtInput:De(t.endedAt)}}function jt(t,a){const s=(a==null?void 0:a.startedAt)??new Date(Date.now()-36e5).toISOString(),i=(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:De(s),endedAtInput:De(i)}}function Tt(t,a){var c,u;const s=t.tagsInput.split(",").map(d=>d.trim()).filter(Boolean),i=lt(t.startedAtInput)??(a==null?void 0:a.startedAt)??new Date(Date.now()-3600*1e3).toISOString(),l=lt(t.endedAtInput)??(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t.kind,startedAt:i,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:s,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"?((u=a==null?void 0:a.trip)==null?void 0:u.averageSpeedMps)??null:null,metadata:{createdFrom:"movement-life-timeline"}}}function Rs(t,a){var l,c;const s=t.kind==="stay"?((c=(l=t.stay)==null?void 0:l.label)==null?void 0:c.trim())??"":"";if(s)return s;const i=t.title.trim();return i&&i.toLowerCase()!=="stay"?i:a.trim()||"Stay"}function zs(t,a){const s=Ct(t),i=a.trim();return Tt({...s,label:Rs(t,i),placeLabel:i},t)}function Ta(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function dt(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Os(t){var a,s,i;return pe([t.kind,me(t),t.subtitle,t.placeLabel??"",...t.tags,dt(t.startedAt),dt(t.endedAt),Ta(t.startedAt),le(t)?((a=t.stay.place)==null?void 0:a.label)??t.stay.label:ot(t)?[t.trip.label,t.trip.activityType,t.trip.travelMode,(s=t.trip.startPlace)==null?void 0:s.label,(i=t.trip.endPlace)==null?void 0:i.label].filter(Boolean).join(" "):t.kind==="trip"?[t.title,t.subtitle,t.placeLabel??""].filter(Boolean).join(" "):"missing data gap"].join(" "))}function Hs(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 s of["night","morning","afternoon","evening"])a.set(`time:${s}`,{id:`time:${s}`,label:s[0].toUpperCase()+s.slice(1),description:"Filter by the segment start time."});for(const s of t){for(const i of s.tags)a.set(`tag:${i}`,{id:`tag:${i}`,label:i,description:"Movement tag"});s.placeLabel&&a.set(`place:${s.placeLabel}`,{id:`place:${s.placeLabel}`,label:s.placeLabel,description:"Matched place"})}return[...a.values()].sort((s,i)=>s.label.localeCompare(i.label))}function Bs(t,a){return a.every(s=>s==="kind:stay"||s==="kind:trip"?t.kind===s.slice(5):s.startsWith("time:")?Ta(t.startedAt)===s.slice(5):s.startsWith("tag:")?t.tags.includes(s.slice(4)):s.startsWith("place:")?(t.placeLabel??"")===s.slice(6):!0)}function oa(t,a){return t&&{...t,pages:t.pages.map(s=>({...s,segments:s.segments.filter(i=>i.id!==a)}))}}function Ks(t,a){const s=t+(Math.sin((t-.5)*Math.PI)+1)*.5-t,i=t-.5,c=.5+(i*(1-a*.64)+i*i*i*a*2.56);return Math.max(0,Math.min(1,c-(s-t)*a*.08))}function qs(t){return t.getHours()===0?Ca(t.toISOString()):Ds(t)}function Qs(t,a){const s=new Date(t.endedAt).getTime(),i=new Date(t.startedAt).getTime(),l=Math.max(1,s-i),c=Math.max(0,Math.min(1,(a-i)/l));if(t.durationSeconds<=Mt)return c;const u=Math.max(0,1-Math.min(1,Mt/Math.max(1,t.durationSeconds)));return Ks(c,u)}function Us(t,a,s){if(t.items.length===0)return null;const i=t.items[0];if(a<new Date(i.segment.startedAt).getTime())return t.historyHeaderHeight+t.leadHeight-(new Date(i.segment.startedAt).getTime()-a)/36e5*G;for(let u=0;u<t.items.length;u+=1){const d=t.items[u],m=new Date(d.segment.startedAt).getTime(),p=new Date(d.segment.endedAt).getTime();if(a>=m&&a<=p)return d.boxTop+Qs(d.segment,a)*d.displayHeight;const f=t.items[u+1]??null,y=f?new Date(f.segment.startedAt).getTime():s;if(a>p&&a<y)return d.boxBottom+(a-p)/36e5*G}const l=t.items[t.items.length-1],c=new Date(l.segment.endedAt).getTime();return a>=c?l.boxBottom+(a-c)/36e5*G:null}function Ws(t){const a=new Date(t);a.setMinutes(0,0,0);const s=a.getTime();return s<=t?s+36e5:s}function Gs(t,a){const s=[];if(t.items.length===0)return s;const i=t.items[0],l=new Date(i.segment.startedAt).getTime();for(let c=Ws(l-Aa*36e5);c<=a;c+=36e5){const u=Us(t,c,a);if(u===null)continue;const d=new Date(c);s.push({y:u,label:qs(d),strong:d.getHours()===0})}return s}function Vs({segments:t,viewportHeight:a,nowMs:s=Date.now()}){var K;const i=t.length>0?Ps:0,l=t.length>0?G*Aa:0;let c=i+l,u=null;const d=t.map(b=>{const C=_s(b.durationSeconds,b.kind,b.syncSource),E=new Date(b.startedAt).getTime(),H=u===null?0:Math.max(0,(E-u)/36e5)*G;c+=H;const V=c,_=V+C;return c=_,u=new Date(b.endedAt).getTime(),{id:b.id,segment:b,gapBefore:H,displayHeight:C,boxTop:V,boxBottom:_}}),m=s+yt*36e5,p=(()=>{var E;const b=(E=t[t.length-1])==null?void 0:E.endedAt;if(!b)return G*yt;const C=new Date(b).getTime();return Math.max(G*yt,(m-C)/36e5*G)})(),f=(((K=d[d.length-1])==null?void 0:K.boxBottom)??i+l)+p,y=Math.max(f,a>0?a+260:960,i+l+p),T={historyHeaderHeight:i,leadHeight:l,items:d,markers:[],rangeEndMs:m,futureTailHeight:p+Math.max(0,y-f),totalHeight:y};return{...T,markers:Gs(T,m)}}const Ys="bg-[linear-gradient(90deg,color-mix(in_srgb,var(--canvas)_96%,transparent),color-mix(in_srgb,var(--canvas)_42%,transparent),transparent)]",Xs="bg-[linear-gradient(180deg,color-mix(in_srgb,var(--ui-ink-strong)_2%,transparent),color-mix(in_srgb,var(--ui-ink-strong)_8%,transparent),color-mix(in_srgb,var(--ui-ink-strong)_2%,transparent))]",Zs="h-6 w-[3px] rounded-full bg-[var(--info)] shadow-[0_0_14px_color-mix(in_srgb,var(--info)_36%,transparent)]",Js="relative w-[min(18rem,calc(100vw-6rem))] overflow-hidden rounded-[26px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[linear-gradient(180deg,var(--ui-accent-soft),var(--ui-info-soft))] shadow-[var(--ui-shadow-soft)]",ei="absolute z-10 h-7 w-8 rounded-[12px] border bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-soft)] backdrop-blur-sm",ti="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",Pt="ring-1 ring-[color-mix(in_srgb,var(--info)_42%,transparent)]",ai="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",Pa="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",Ae="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",si="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)]",ii="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 ri({layout:t,scrollTop:a,viewportHeight:s}){const i=G*6,l=Math.max(0,a-i),c=Math.min(t.totalHeight,a+Math.max(s,G*8)+i),u=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:k("absolute inset-y-0 left-0 w-18",Ys)}),u.map((d,m)=>e.jsxs("div",{className:"absolute inset-x-0",style:{top:`${d.y}px`},children:[e.jsx("div",{className:k("border-t",d.strong?"border-white/14":"border-white/7")}),e.jsx("div",{className:k("absolute left-3 top-0 -translate-y-1/2 font-label text-[9px] tracking-[0.24em]",d.strong?"text-white/38":"text-white/22"),children:d.label})]},`timeline-grid-${m}`))]})}function ni({fromSide:t,toSide:a,height:s,emphasized:i}){const l=la(t),c=la(a),u=`M ${l} 16 C ${l} ${Math.max(40,s*.26)}, ${c} ${Math.max(70,s*.72)}, ${c} ${s-18}`;return e.jsxs("svg",{viewBox:`0 0 100 ${s}`,className:"absolute inset-x-0 top-0 h-full w-full overflow-visible",preserveAspectRatio:"none",children:[e.jsx("path",{d:u,fill:"none",stroke:i?"color-mix(in srgb, var(--ui-ink-strong) 18%, transparent)":"color-mix(in srgb, var(--ui-ink-strong) 11%, transparent)",strokeWidth:i?"1.05":"0.85",strokeDasharray:i?"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:s-18,r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"})]})}function Dt({position:t}){return e.jsx("div",{className:k("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:Zs})})}function li({segment:t}){const a=(t==null?void 0:t.kind)==="stay"?t.placeLabel||t.title||null:(t==null?void 0:t.kind)==="trip"?Ne(t,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}).label:null,s=a||"Beginning of time";return e.jsx("div",{className:"pointer-events-none flex justify-center px-6 py-4",children:e.jsxs("div",{className:Js,children:[e.jsx(Dt,{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(h,{tone:"signal",className:"bg-white/10 text-white/78",children:"Start"}),e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-white/28",children:"Beginning of history"})]}),e.jsx("div",{className:"mt-5 font-display text-[1.25rem] tracking-normal text-white",children:s}),e.jsx("div",{className:"mt-2 font-label text-[10px] uppercase tracking-[0.22em] text-white/30",children:a?"Oldest loaded known stay":"Earliest known anchor"})]})]})})}function oi(t,a,s){const i=a+Math.max(96,Math.min(s*.28,220)),l=t.items.find(c=>c.boxBottom>=i)??t.items[t.items.length-1]??null;return l?Ca(l.segment.startedAt):null}function da({side:t,vertical:a,emphasized:s=!1}){return e.jsx("div",{className:k(ei,s?"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 di({layout:t,selected:a,onToggle:s}){var m,p,f,y;const{segment:i}=t,l=Et(i),c=t.displayHeight,u=i.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=i.kind==="trip"?{start:Ne(i,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}),end:Ne(i,"end",{includeCoordinates:!1})}:null;return e.jsxs("div",{className:k("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:k("absolute inset-y-0 left-1/2 w-px -translate-x-1/2",Xs)}),e.jsx("div",{className:"relative h-full",children:i.kind==="trip"?e.jsxs(ea.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(da,{side:"center",vertical:"top",emphasized:!0}),e.jsx(da,{side:"center",vertical:"bottom",emphasized:!0})]}):null,e.jsx(ni,{fromSide:"center",toSide:"center",height:c,emphasized:a}),e.jsxs("button",{type:"button",onClick:s,className:k(ti,"left-1/2 -translate-x-1/2",a?Pt:""),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-white/34",children:"Move"}),e.jsx("div",{className:"text-[11px] tracking-[0.18em] text-white/44",children:Ke(i.durationSeconds)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(h,{className:"bg-white/[0.08] text-white/74",children:Le(((m=i.trip)==null?void 0:m.distanceMeters)??0)}),(((p=i.trip)==null?void 0:p.stops.length)??0)>0?e.jsxs(h,{className:"bg-white/[0.08] text-white/74",children:[(f=i.trip)==null?void 0:f.stops.length," stop",((y=i.trip)==null?void 0:y.stops.length)===1?"":"s"]}):null]}),e.jsxs("div",{className:"mt-2 font-label text-[9px] uppercase tracking-[0.22em] text-white/28",children:[W(i.startedAt)," →"," ",W(i.endedAt)]})]})]}):e.jsx(ea.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:s,className:k("group relative w-full overflow-hidden rounded-[24px] border text-left shadow-[var(--ui-shadow-soft)] transition sm:rounded-[30px]",u,a?Pt:"hover:border-[var(--ui-border-strong)]"),style:{minHeight:`${c}px`},children:[e.jsx(Dt,{position:"top"}),e.jsx(Dt,{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(h,{tone:"signal",className:"bg-white/10 text-white/82",children:l?"Sleep":"Stay"}),e.jsx("div",{className:"text-[11px] tracking-[0.16em] text-white/46 sm:text-xs sm:tracking-[0.18em]",children:Ke(i.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-white sm:text-[1.12rem]",children:me(i)}),i.kind==="stay"&&Ie(i)&&!l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(h,{className:"max-w-full truncate bg-white/[0.08] text-white/76",children:Ie(i)})}):l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(h,{className:k("max-w-full truncate",Pa),children:i.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-white/34 sm:text-[10px] sm:tracking-[0.22em]",children:[W(i.startedAt)," →"," ",W(i.endedAt)]})})]})]})})})]})}const ci="rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",st="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",it="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",ca="text-sm leading-6 text-[var(--ui-ink-medium)]",ye="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%)]",ua="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",mi="bg-[var(--ui-accent-soft)] text-[var(--primary)]",ui="mt-4 rounded-[18px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[var(--ui-info-soft)] p-3",xi="text-[11px] uppercase tracking-[0.18em] text-[color-mix(in_srgb,var(--info)_70%,var(--ui-ink-strong)_30%)]",hi="mt-2 text-sm leading-6 text-[var(--ui-ink-medium)]",pi="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 gi({segment:t,onEdit:a,onOpenDetail:s,onDefinePlace:i,onClose:l}){var d;const c=Et(t),u=Ie(t);return e.jsxs(N,{className:ci,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:me(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(h,{className:c?ma:t.sourceKind==="user_defined"?mi:ye,children:c?"Virtual":t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),t.overrideCount>0?e.jsxs(h,{className:ua,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:s,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(Lt,{className:"size-4"})}):null,e.jsx($t,{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:st,children:[e.jsx("div",{className:it,children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.startedAt)})]}),e.jsxs("div",{className:st,children:[e.jsx("div",{className:it,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(h,{tone:"signal",children:Ke(t.durationSeconds)}),ot(t)?e.jsxs(e.Fragment,{children:[e.jsx(h,{className:ye,children:Le(t.trip.distanceMeters)}),t.trip.stops.length>0?e.jsxs(h,{className:ye,children:[t.trip.stops.length," stop",t.trip.stops.length===1?"":"s"]}):null]}):null,c?e.jsx(h,{className:ma,children:t.subtitle}):u?e.jsx(h,{className:ye,children:u}):null]}),le(t)&&!c?e.jsxs("div",{className:ui,children:[e.jsx("div",{className:xi,children:"Location label"}),e.jsx("div",{className:hi,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:i,variant:"ghost",className:pi,children:"Label location"})})]}):null,e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:st,children:[e.jsx("div",{className:it,children:"Timeline summary"}),e.jsx("div",{className:`mt-2 ${ca}`,children:t.kind==="stay"?c?`Sleep overlay from ${W(t.startedAt)} to ${W(t.endedAt)}. Underlying movement boxes are sliced virtually while this overlay is visible.`:`Stay block from ${W(t.startedAt)} to ${W(t.endedAt)}.`:t.kind==="trip"?`Connector from ${Ne(t,"start").label} to ${Ne(t,"end").label}.`:`No reliable movement signal reached Forge from ${W(t.startedAt)} to ${W(t.endedAt)}.`})]}),e.jsxs("div",{className:st,children:[e.jsx("div",{className:it,children:"Projection model"}),e.jsx("div",{className:`mt-2 ${ca}`,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(h,{className:ye,children:["Raw stays ",t.rawStayIds.length]}),e.jsxs(h,{className:ye,children:["Raw trips ",t.rawTripIds.length]}),e.jsxs(h,{className:ye,children:["Raw points ",t.rawPointCount]}),t.hasLegacyCorrections?e.jsx(h,{className:ua,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(va,{className:"size-4 text-[var(--primary)]"}),((d=t.stay.place)==null?void 0:d.label)??"No canonical place linked yet"]}):ot(t)?e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"size-4 text-[var(--primary)]"}),t.trip.activityType||t.trip.travelMode]}):t.kind==="trip"?e.jsxs(e.Fragment,{children:[e.jsx(nt,{className:"size-4 text-[var(--primary)]"}),"Repaired movement connector"]}):e.jsxs(e.Fragment,{children:[e.jsx(Nt,{className:"size-4 text-[var(--ui-ink-soft)]"}),"Missing intervals are synthesized from long signal gaps instead of inventing fake travel."]})})]})}function xa({title:t,points:a,averagePoint:s}){const i=Ls(s?[...a,s]:a),l=s?i.length-1:i.length,c=i.slice(0,l),u=s?i[i.length-1]??null:null,d=c.map((m,p)=>`${p===0?"M":"L"} ${m.x} ${m.y}`).join(" ");return e.jsxs(N,{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((m,p)=>e.jsx("circle",{cx:m.x,cy:m.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)"},m.id)),u?e.jsxs("g",{className:"text-[var(--warning)]",children:[e.jsx("circle",{cx:u.x,cy:u.y,r:3,fill:"currentColor"}),e.jsx("circle",{cx:u.x,cy:u.y,r:6,fill:"none",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"2 2",opacity:.48})]}):null]})})]})}const Ft="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",Da="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)]",Pe="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 vi({open:t,anchor:a,items:s,onClose:i}){if(x.useEffect(()=>{if(!t)return;const m=f=>{f.key==="Escape"&&i()},p=()=>i();return window.addEventListener("keydown",m),window.addEventListener("pointerdown",p),()=>{window.removeEventListener("keydown",m),window.removeEventListener("pointerdown",p)}},[i,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),u=Math.min(368,window.innerWidth-24),d=Math.max(12,Math.min(a.right,window.innerWidth-u-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:`${u}px`,maxHeight:`${c}px`},onPointerDown:m=>m.stopPropagation(),children:[e.jsxs(ue,{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:s.map(m=>{const p=m.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:()=>{m.onSelect(),i()},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:m.label}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:m.description})]})]},m.id)})})]})}),document.body)}function fi({open:t,onOpenChange:a,segment:s,detail:i,loading:l,onEdit:c,onDefinePlace:u}){var f;const d=(i==null?void 0:i.segment)??s,m=(i==null?void 0:i.stayDetail)??null,p=(i==null?void 0:i.tripDetail)??null;return e.jsx(qe,{open:t,onOpenChange:a,children:e.jsxs(Qe,{children:[e.jsx(Ue,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(We,{className:k(Ft,"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(ct,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:d?`${me(d)} details`:"Movement details"}),e.jsx(mt,{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:k("rounded-full px-3",Pe),disabled:!d.editable||d.kind==="missing",children:[e.jsx(It,{className:"size-4"}),"Edit"]}):null,e.jsx(ut,{asChild:!0,children:e.jsx("button",{type:"button",className:k(Da,"p-2"),children:e.jsx($t,{className:"size-4 rotate-45"})})})]})]}),l?e.jsx(ue,{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(Te,{label:"Started",value:ge(d.startedAt)}),e.jsx(Te,{label:"Ended",value:ge(d.endedAt)}),e.jsx(Te,{label:"Duration",value:Ke(d.durationSeconds)}),e.jsx(Te,{label:"Raw coverage",value:`${d.rawStayIds.length} stays · ${d.rawTripIds.length} trips · ${d.rawPointCount} points`})]}),m?e.jsxs(e.Fragment,{children:[e.jsxs(ue,{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:m.canonicalPlace?`This stay is linked to ${m.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:u,variant:"ghost",className:k("rounded-full px-4",Pe),children:"Label location"})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(xa,{title:"Stay positions",points:m.positions,averagePoint:m.averagePosition}),e.jsxs(N,{className:"rounded-[28px] p-5",children:[e.jsx(ha,{title:"Stay metrics",rows:[["Canonical place",((f=m.canonicalPlace)==null?void 0:f.label)??"Not linked yet"],["Average position",m.averagePosition?at(m.averagePosition.latitude,m.averagePosition.longitude):"Unavailable"],["Radius",m.radiusMeters!=null?Le(m.radiusMeters):"Unavailable"],["Samples",String(m.sampleCount)]]}),e.jsxs(ue,{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:m.positions.map((y,T)=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[y.label??`Position ${T+1}`,":"," ",at(y.latitude,y.longitude)]},`${y.recordedAt??"stay"}-${T}`))})]})]})]})]}):null,p?e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(xa,{title:"Travel map",points:p.positions}),e.jsx(N,{className:"rounded-[28px] p-5",children:e.jsx(ha,{title:"Trip metrics",rows:[["Start position",p.startPosition?at(p.startPosition.latitude,p.startPosition.longitude):"Unavailable"],["End position",p.endPosition?at(p.endPosition.latitude,p.endPosition.longitude):"Unavailable"],["Distance",Le(p.totalDistanceMeters)],["Moving time",na(p.movingSeconds)],["Idle time",na(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 bi({open:t,segment:a,onOpenChange:s,onEdit:i,onOpenDetail:l,onDefinePlace:c}){return e.jsx(qe,{open:t,onOpenChange:s,children:e.jsxs(Qe,{children:[e.jsx(Ue,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(We,{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(ct,{className:"sr-only",children:a?`${me(a)} actions`:"Movement actions"}),e.jsx(mt,{className:"sr-only",children:"Inspect, edit, or label the selected movement box."}),a?e.jsx(gi,{segment:a,onEdit:i,onOpenDetail:l,onDefinePlace:c,onClose:()=>s(!1)}):null]})]})})}function wi({open:t,onOpenChange:a,segment:s,places:i,loading:l,onSelectPlace:c,onCreatePlace:u}){const d=s?At(s):null,[m,p]=x.useState("");x.useEffect(()=>{if(!t){p("");return}p(Ie(s)??"")},[t,s]);const f=x.useMemo(()=>{if(!d)return[];const b=pe(m);return[...i].filter(C=>b.length===0?!0:Is(C).includes(b)).sort((C,E)=>{const H=pe(C.label),V=pe(E.label),_=b.length>0&&H.startsWith(b),Y=b.length>0&&V.startsWith(b);if(_!==Y)return _?-1:1;const Q=rt(d.latitude,d.longitude,C.latitude,C.longitude),X=rt(d.latitude,d.longitude,E.latitude,E.longitude);return Math.abs(Q-X)>1?Q-X:C.label.localeCompare(E.label)}).slice(0,6)},[i,m,d]),y=pe(m),T=f.some(b=>pe(b.label)===y),K=Ie(s);return e.jsx(qe,{open:t,onOpenChange:a,children:e.jsxs(Qe,{children:[e.jsx(Ue,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(We,{className:k(Ft,"top-[8vh] max-h-[84vh] w-[min(38rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx(La,{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(ue,{className:"mt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(h,{tone:"signal",children:"Stay center"}),K?e.jsx(h,{tone:"meta",children:K}):null]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[e.jsx(Te,{label:"Latitude",value:d.latitude.toFixed(6)}),e.jsx(Te,{label:"Longitude",value:d.longitude.toFixed(6)})]})]}):e.jsx(ue,{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(O,{value:m,onChange:b=>p(b.target.value),placeholder:"Type a location name or create a new one"}),e.jsxs(ue,{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..."}):f.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:f.map(b=>{const C=d==null?null:rt(d.latitude,d.longitude,b.latitude,b.longitude);return e.jsxs("button",{type:"button",onClick:()=>void c(b).then(E=>{E&&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(h,{tone:"meta",children:[Le(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:Pe,children:"Cancel"}),e.jsx(A,{onClick:()=>{!s||!d||u(s,T?"":m.trim())},disabled:!s||!d,children:y.length>0&&!T?`Create "${m.trim()}"`:"Create new location"})]})]})]})})}function yi({open:t,draft:a,creating:s,saving:i,preflight:l,preflightLoading:c,onDraftChange:u,onFitMissing:d,onSave:m,onOpenChange:p}){return e.jsx(qe,{open:t,onOpenChange:p,children:e.jsxs(Qe,{children:[e.jsx(Ue,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(We,{className:k(Ft,"top-[8vh] w-[min(34rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx(La,{title:s?"Create movement box":"Edit movement box",description:a?s?"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(([f,y])=>e.jsx(A,{type:"button",variant:"ghost",className:k(Pe,a.kind===f?"ring-1 ring-[color-mix(in_srgb,var(--primary)_42%,transparent)]":""),onClick:()=>u({...a,kind:f}),children:y},f))})]}),e.jsx(Be,{label:"Label",value:a.label,onChange:f=>u({...a,label:f})}),a.kind!=="trip"?e.jsx(Be,{label:"Place",value:a.placeLabel,placeholder:"Home, Office, Riverside path...",onChange:f=>u({...a,placeLabel:f})}):null,e.jsx(Be,{label:"Tags",value:a.tagsInput,placeholder:"movement, social, errand",onChange:f=>u({...a,tagsInput:f})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(Be,{label:"Started",type:"datetime-local",value:a.startedAtInput,onChange:f=>u({...a,startedAtInput:f})}),e.jsx(Be,{label:"Ended",type:"datetime-local",value:a.endedAtInput,onChange:f=>u({...a,endedAtInput:f})})]}),e.jsxs(ue,{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:Pe,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(ut,{asChild:!0,children:e.jsx(A,{type:"button",variant:"ghost",className:Pe,children:"Cancel"})}),e.jsxs(A,{onClick:m,disabled:!a||i,children:[e.jsx(Wa,{className:"size-4"}),i?"Saving...":s?"Create box":"Save changes"]})]})]})]})})}function La({title:t,description:a,closeLabel:s}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(ct,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:t}),e.jsx(mt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a})]}),e.jsx(ut,{asChild:!0,children:e.jsx("button",{type:"button",className:k(Da,"p-2"),"aria-label":s,children:s?e.jsx(Lt,{className:"size-4"}):e.jsx($t,{className:"size-4 rotate-45"})})})]})}function Te({label:t,value:a}){return e.jsxs(ue,{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 ha({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(([s,i])=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("span",{className:"text-[var(--ui-ink-faint)]",children:[s,": "]}),i]},s))})]})}function Be({label:t,value:a,onChange:s,placeholder:i,type:l="text"}){return e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:[t,e.jsx(O,{type:l,value:a,placeholder:i,onChange:c=>s(c.target.value)})]})}function ji({userIds:t=[]}){var Ut,Wt,Gt;const a=ba(),s=x.useRef(null),i=x.useRef(null),l=x.useRef(null),c=x.useRef(!1),u=x.useRef(!1),d=x.useRef(null),[m,p]=x.useState(null),[f,y]=x.useState(!1),[T,K]=x.useState(!1),[b,C]=x.useState(null),[E,H]=x.useState({}),[V,_]=x.useState(null),[Y,Q]=x.useState(null),[X,Z]=x.useState(null),[Ge,$e]=x.useState(null),[Ee,Fe]=x.useState(!1),[Ve,Se]=x.useState(!1),[ht,ke]=x.useState(null),[pt,_e]=x.useState(null),[ae,q]=x.useState(!1),[se,ie]=x.useState(!1),[B,xe]=x.useState(!1),[w,Ye]=x.useState(""),[ve,Xe]=x.useState([]),[he,Ze]=x.useState(0),[R,Re]=x.useState(0),Me=()=>{const n=s.current;n&&(Ze(n.scrollTop),Re(n.clientHeight))},P=Vt({queryKey:["forge-movement-life-timeline",...t],initialPageParam:null,queryFn:({pageParam:n})=>Zt({before:n??void 0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),j=Vt({queryKey:["forge-movement-life-timeline-data",...t],initialPageParam:null,queryFn:({pageParam:n})=>Zt({before:n??void 0,includeInvalid:!0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),fe=x.useMemo(()=>{var n;return((n=P.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[P.data]),oe=x.useMemo(()=>{var n;return((n=j.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[j.data]),de=x.useMemo(()=>{var n;return((n=P.data)==null?void 0:n.pages.reduce((o,g)=>Math.max(o,g.invalidSegmentCount??0),0))??0},[P.data]),S=x.useMemo(()=>[...fe].reverse(),[fe]),J=x.useMemo(()=>[...oe].reverse(),[oe]),ze=x.useMemo(()=>{var o;const n=new Map;for(const g of((o=P.data)==null?void 0:o.pages)??[])for(const F of g.sleepOverlays??[])n.set(F.id,F);return[...n.values()].sort((g,F)=>new Date(g.startedAt).getTime()-new Date(F.startedAt).getTime())},[P.data]),be=x.useMemo(()=>Ts(S,ze),[S,ze]),M=x.useMemo(()=>B?be:S,[S,be,B]),Oe=x.useMemo(()=>be.filter(n=>n.syncSource==="sleep overlay"),[be]),re=((Ut=Oe.at(-1))==null?void 0:Ut.id)??null,r=x.useMemo(()=>M.find(n=>n.id===X)??null,[X,M]),v=x.useMemo(()=>M.find(n=>n.id===m)??null,[M,m]),ee=te({queryKey:["forge-movement-box-detail",(r==null?void 0:r.boxId)??null,...t],queryFn:async()=>r!=null&&r.boxId?(await ts(r.boxId,t)).movement:null,enabled:!!(r!=null&&r.boxId)}),U=x.useMemo(()=>S.find(n=>n.id===Ge)??null,[Ge,S]),ne=te({queryKey:["forge-movement-places",...t],queryFn:async()=>(await Sa(t)).places,retry:!1,refetchOnWindowFocus:!1}),I=x.useMemo(()=>Vs({segments:M,viewportHeight:R}),[M,R]),gt=x.useMemo(()=>new Map(I.items.map(n=>[n.segment.id,n])),[I.items]),$a=x.useMemo(()=>{const n=Math.max(0,he-ia),o=he+Math.max(R,G*8)+ia;return I.items.filter(g=>g.segment.id===m?!0:g.boxBottom>=n&&g.boxTop<=o)},[he,m,I.items,R]),Rt=x.useMemo(()=>oi(I,he,R),[he,I,R]),Ea=()=>{var o;const n=(o=l.current)==null?void 0:o.getBoundingClientRect();if(!n){K(g=>!g);return}C({top:n.bottom+10,right:Math.max(12,window.innerWidth-n.right)}),K(g=>!g)},Fa=x.useMemo(()=>[{id:"add-box",label:"Add box",description:"Create a user-defined stay, move, or missing-data interval.",icon:Ga,onSelect:()=>Q(jt("stay",S.at(-1)??null))},{id:"sleep",label:B?"Hide sleep":"Show sleep",description:"Toggle sleep overlays without rewriting the movement boxes.",icon:ga,onSelect:()=>xe(n=>{const o=!n;return o&&re&&(p(re),y(!0)),o})},{id:"view-data",label:"View data",description:"Open the canonical loaded records and raw-data filters.",icon:Nt,onSelect:()=>q(!0)}],[re,S,B]),zt=(n,o="smooth")=>{const g=s.current,F=gt.get(n);if(!g||!F)return;const He=Math.max(0,F.boxTop-g.clientHeight/2+F.displayHeight/2);if(typeof g.scrollTo=="function"){g.scrollTo({top:He,behavior:o});return}g.scrollTop=He};x.useEffect(()=>{ae&&(!j.hasNextPage||j.isFetchingNextPage||j.fetchNextPage())},[ae,j.fetchNextPage,j.hasNextPage,j.isFetchingNextPage]),x.useEffect(()=>{const n=M.at(-1);!u.current&&n&&(u.current=!0,p(n.id))},[M]),x.useEffect(()=>{if(!c.current&&M.length>0){c.current=!0,requestAnimationFrame(()=>{var o;const n=(o=M[M.length-1])==null?void 0:o.id;n&&zt(n,"auto"),requestAnimationFrame(()=>{Me()})});return}if(d.current&&M.length>d.current.count&&s.current){const n=d.current;d.current=null,requestAnimationFrame(()=>{const o=s.current;if(!o)return;const g=I.totalHeight-n.size;o.scrollTop+=g,Me()})}},[M.length,I.totalHeight,gt]),x.useEffect(()=>{if(!s.current)return;const o=()=>{Me()};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),x.useEffect(()=>{if(!m)return;const n=S.find(o=>o.id===m);n&&H(o=>o[m]?o:{...o,[m]:Ct(n)})},[S,m]),x.useEffect(()=>{var n;m&&(M.some(o=>o.id===m)||(p(((n=M.at(-1))==null?void 0:n.id)??null),y(!1)))},[M,m]),x.useEffect(()=>{if(!B||!re)return;const n=M.findIndex(o=>o.id===re);n<0||(p(re),requestAnimationFrame(()=>{var g;const o=(g=M[n])==null?void 0:g.id;o&&zt(o)}))},[M,re,B,gt]);const vt=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"]})])},Ot=Ce({mutationFn:async n=>{const{segment:o,draft:g,creating:F}=n,He=Tt(g,o);if(F){await Yt(He,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 Xt(o.boxId,{...He,metadata:{updatedFrom:"movement-life-timeline"}},t)},onSuccess:vt}),_a=async(n,o)=>{if(n.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");const g=zs(n,o.label);if(n.sourceKind==="user_defined"){await Xt(n.boxId,{...g,metadata:{updatedFrom:"movement-life-timeline-place-label"}},t);return}await Yt({...g,metadata:{createdFrom:"movement-life-timeline-place-label"}},t)},Ht=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(g=>es(g,{placeExternalUid:o.externalUid,placeLabel:o.label})))},Ra=(n,o)=>{const g=At(n);if(!g)return!0;const F=rt(g.latitude,g.longitude,o.latitude,o.longitude);return F<=100||typeof window>"u"||typeof window.confirm!="function"?!0:window.confirm(`"${o.label}" is ${Le(F)} away from this stay's recorded center. Link it anyway?`)},za=Ce({mutationFn:async n=>{const{segment:o,...g}=n,F=await wa(g,t);return o&&le(o)&&await Ht(o,F.place),F},onSuccess:vt}),Oa=Ce({mutationFn:async n=>{const{segment:o,place:g}=n;if(!Ra(o,g))return{assigned:!1};if(le(o))return await Ht(o,g),{assigned:!0};if(o.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");return await _a(o,g),{assigned:!0}},onSuccess:async n=>{n.assigned&&await vt()}}),ft=Ce({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 ${me(n)} with missing data.`},t)},onSuccess:async(n,o)=>{p(g=>g===o.id?null:g),y(!1),_(g=>g===o.id?null:g),a.setQueryData(["forge-movement-life-timeline",...t],g=>oa(g,o.id)),a.setQueryData(["forge-movement-life-timeline-data",...t],g=>oa(g,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(()=>Hs(J),[J]),we=x.useMemo(()=>{const n=pe(w);return[...J].sort((o,g)=>new Date(g.endedAt).getTime()-new Date(o.endedAt).getTime()).filter(o=>(n.length===0||Os(o).includes(n))&&Bs(o,ve))},[J,w,ve]),Bt=x.useMemo(()=>J.length===0?"No movement records loaded yet.":we.length===J.length&&w.trim().length===0&&ve.length===0?`${J.length} loaded movement records visible`:`${we.length} of ${J.length} loaded records visible`,[J.length,we.length,w,ve.length]),bt=fa({count:we.length,getScrollElement:()=>i.current,estimateSize:()=>136,overscan:8}),D=V?S.find(n=>n.id===V)??null:null,Ba=D?E[D.id]??Ct(D):null,Je=Y!==null,$=Y??Ba,Kt=((Wt=S[0])==null?void 0:Wt.startedAt)??null,qt=((Gt=S[S.length-1])==null?void 0:Gt.endedAt)??null,wt=te({queryKey:["forge-movement-user-box-preflight",(D==null?void 0:D.boxId)??"create",($==null?void 0:$.kind)??null,($==null?void 0:$.startedAtInput)??null,($==null?void 0:$.endedAtInput)??null,Kt,qt,...t],enabled:$!==null&&lt($.startedAtInput)!==null&&lt($.endedAtInput)!==null,queryFn:async()=>{if(!$)return null;const n=Tt($,D);return(await as({...n,excludeBoxId:(D==null?void 0:D.sourceKind)==="user_defined"?D.boxId:null,rangeStart:Kt,rangeEnd:qt},t)).preflight}}),Qt=n=>{le(n)&&($e(n.id),Fe(!0))},Ka=(n,o)=>{const g=At(n);g&&(Fe(!1),$e(n.id),ke({...g,label:o.trim()||g.label}),_e(n.id),Se(!0))},qa=()=>{const n=s.current;n&&(Ze(n.scrollTop),Re(n.clientHeight),!(!P.hasNextPage||P.isFetchingNextPage)&&n.scrollTop<=960&&(d.current={count:M.length,size:I.totalHeight},P.fetchNextPage()))};if(P.isPending)return e.jsx(ya,{eyebrow:"Movement",title:"Loading life timeline",description:"Reconstructing the longer road of stays, moves, and places.",columns:1,blocks:6});if(P.isError)return e.jsx(ja,{eyebrow:"Movement",error:P.error,onRetry:()=>void P.refetch()});const Qa=I.totalHeight;return e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(N,{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-white/34",children:"Movement"}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-2",children:[de>0?e.jsxs(h,{className:k("hidden sm:inline-flex",Ae),children:[de," invalid hidden"]}):null,e.jsxs(h,{className:"hidden bg-white/[0.06] text-white/68 sm:inline-flex",children:[M.length," visible"]}),e.jsx("div",{ref:l,children:e.jsxs(A,{type:"button",variant:"ghost",size:"sm","aria-expanded":T,"aria-haspopup":"dialog",className:k("h-9 rounded-full border border-white/10 bg-white/[0.05] px-3 text-white/78 hover:bg-white/[0.1] hover:text-white",T?Pt:""),onClick:Ea,children:[e.jsx(Va,{className:"size-4"}),"Actions"]})})]})]}),e.jsx(vi,{open:T,anchor:b,items:Fa,onClose:()=>K(!1)}),B&&Oe.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:s,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(ri,{layout:I,scrollTop:he,viewportHeight:R}),Rt?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:Rt})}):null,e.jsxs("div",{className:"relative",style:{height:`${Qa}px`},children:[I.historyHeaderHeight>0?e.jsx("div",{className:"absolute inset-x-0 top-0",style:{height:`${I.historyHeaderHeight}px`},children:e.jsx(li,{segment:M[0]??null})}):null,$a.map(n=>{const o=n.segment;return e.jsx(di,{layout:n,selected:m===o.id,onToggle:()=>{p(o.id),y(!0)}},o.id)})]})]})]}),e.jsx(yi,{open:D!==null||Y!==null,segment:D,draft:$,creating:Je,saving:Ot.isPending,preflight:wt.data??null,preflightLoading:wt.isFetching,onDraftChange:n=>{if(Je){Q(n);return}D&&H(o=>({...o,[D.id]:n}))},onFitMissing:()=>{const n=wt.data;if(!(n!=null&&n.nearestMissingStartedAt)||!n.nearestMissingEndedAt)return;const o={...$??jt("stay",D),startedAtInput:De(n.nearestMissingStartedAt),endedAtInput:De(n.nearestMissingEndedAt)};if(Je){Q(o);return}D&&H(g=>({...g,[D.id]:o}))},onSave:()=>{$&&Ot.mutateAsync({segment:D,draft:$,creating:Je},{onSuccess:()=>{_(null),Q(null),se&&(ie(!1),q(!0))}})},onOpenChange:n=>{n||(_(null),Q(null),se&&(ie(!1),q(!0)))}}),e.jsx(bi,{open:f&&v!==null,onOpenChange:n=>{y(n)},segment:v,onEdit:()=>{v!=null&&v.editable&&(_(v.id),y(!1))},onOpenDetail:()=>{v&&(Z(v.id),y(!1))},onDefinePlace:()=>{v&&(Qt(v),y(!1))}}),e.jsx(fi,{open:r!==null,onOpenChange:n=>{n||Z(null)},segment:r,detail:ee.data??null,loading:ee.isFetching,onEdit:()=>{!r||!r.editable||(_(r.id),Z(null))},onDefinePlace:()=>{r&&Qt(r)}}),e.jsx(wi,{open:Ee,onOpenChange:n=>{Fe(n),n||$e(null)},segment:U,places:ne.data??[],loading:ne.isFetching,onSelectPlace:async n=>U?(await Oa.mutateAsync({segment:U,place:n})).assigned:!1,onCreatePlace:(n,o)=>{Ka(n,o)}}),e.jsx(Ma,{open:Ve,onOpenChange:n=>{Se(n),n||(ke(null),_e(null))},place:null,seed:ht,onSave:async n=>{await za.mutateAsync({...n,segment:S.find(o=>o.id===pt)??null})}}),e.jsx(Na,{open:ae,onOpenChange:n=>{q(n),n||se||(Ye(""),Xe([]))},eyebrow:"Movement data",title:"View data",description:"",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(ka,{title:"",description:"",query:w,onQueryChange:Ye,options:Ha,selectedOptionIds:ve,onSelectedOptionIdsChange:Xe,resultSummary:Bt,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(N,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Canonical boxes"}),e.jsx("div",{className:"max-w-3xl text-sm leading-6 text-white/56",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 items-center gap-2",children:[e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/70",onClick:()=>{ie(!0),q(!1),Q(jt("stay",we.at(-1)??null))},children:"Add box"}),e.jsx(h,{tone:"meta",children:Bt}),de>0?e.jsxs(h,{className:Ae,children:[de," invalid hidden included"]}):null,j.hasNextPage?e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/70",pending:j.isFetchingNextPage,pendingLabel:"Loading…",onClick:()=>void j.fetchNextPage(),children:"Load older"}):null]})]}),e.jsx("div",{ref:i,className:"h-[36rem] overflow-y-auto rounded-[24px] border border-white/8 bg-white/[0.03]",children:we.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-white/50",children:"No movement record matches the current search. Clear filters or load older timeline history."}):e.jsx("div",{className:"relative w-full",style:{height:`${bt.getTotalSize()}px`},children:bt.getVirtualItems().map(n=>{var g;const o=we[n.index];return e.jsx("div",{ref:bt.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-white/8 bg-white/[0.04] 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),q(!1),_(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-white",children:[o.kind==="stay"?e.jsx(va,{className:"size-3.5 shrink-0 text-[var(--primary)]"}):o.kind==="missing"?e.jsx(Nt,{className:"size-3.5 shrink-0 text-[var(--ui-ink-medium)]"}):e.jsx(nt,{className:"size-3.5 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-sm font-medium",children:me(o)})]}),e.jsxs("div",{className:"mt-1 text-xs text-white/56",children:[dt(o.startedAt)," →"," ",dt(o.endedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1.5",children:[e.jsx(h,{tone:o.kind==="trip"?"signal":"meta",children:o.kind==="trip"?"Move":o.kind==="missing"?"Missing":"Stay"}),e.jsx(h,{className:o.sourceKind==="user_defined"?"bg-[var(--ui-accent-soft)] text-[var(--primary)]":"bg-white/[0.06] text-white/70",children:o.sourceKind==="user_defined"?o.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),e.jsx(h,{tone:"meta",children:Ke(o.durationSeconds)}),o.origin==="continued_stay"?e.jsx(h,{className:Pa,children:"Continued stay"}):null,o.origin==="repaired_gap"?e.jsx(h,{className:Ae,children:"Repaired"}):null,o.kind==="missing"?e.jsx(h,{className:ai,children:"Missing"}):null,o.isInvalid?e.jsx(h,{className:Ae,children:"Invalid"}):null,o.placeLabel?e.jsx(h,{tone:"default",children:o.placeLabel}):null,o.overrideCount>0?e.jsxs(h,{className:Ae,children:["Overrides ",o.overrideCount]}):null,e.jsxs(h,{className:"bg-white/[0.06] text-white/66",children:["Raw stays ",o.rawStayIds.length]}),e.jsxs(h,{className:"bg-white/[0.06] text-white/66",children:["Raw trips ",o.rawTripIds.length]}),e.jsxs(h,{className:"bg-white/[0.06] text-white/66",children:["Raw points ",o.rawPointCount]}),o.hasLegacyCorrections?e.jsx(h,{className:Ae,children:"Legacy corrections"}):null]})]})}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:k("h-8 shrink-0 rounded-full border px-2.5",o.sourceKind==="user_defined"?si:ii),pending:ft.isPending&&((g=ft.variables)==null?void 0:g.id)===o.id,pendingLabel:"",onClick:()=>{window.confirm(o.sourceKind==="user_defined"?`Delete ${me(o)} and remove this user-defined box from every synced surface?`:`Invalidate ${me(o)} into missing data and hide the automatic box everywhere?`)&&ft.mutateAsync(o)},children:e.jsx(Ya,{className:"size-3.5"})})]})},o.id)})})})]})]})})]})}function Ni(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}).format(new Date(t))}function Si(t,a){const s=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${s.format(new Date(t))} - ${s.format(new Date(a))}`}function z(t){return t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.round(t/60)}m`}function je(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function ki(t,a){return t==="distanceMeters"?je(a):t==="caloriesKcal"?`${Math.round(a)} kcal`:z(a)}function Ia(t){return t.trim().toLowerCase()}function xt(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function _t(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Mi(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function pa(t){return{recordedAt:Mi(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 Ai(t){return Ia([_t(t.recordedAt),t.externalUid,t.isStopAnchor?"stop anchor stop":"path trace point",t.accuracyMeters!=null?`${Math.round(t.accuracyMeters)} meters accuracy`:"",xt(t.recordedAt)].join(" "))}function Ci(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(h,{tone:"meta",children:"Stop anchors"})}),a.set("anchor:path",{id:"anchor:path",label:"Path points",description:"Non-anchor trace points",badge:e.jsx(h,{tone:"meta",children:"Path points"})}),a.set("accuracy:precise",{id:"accuracy:precise",label:"Precise",description:"GPS accuracy below 20m",badge:e.jsx(h,{tone:"meta",children:"Precise"})}),a.set("accuracy:loose",{id:"accuracy:loose",label:"Loose accuracy",description:"GPS accuracy at or above 20m",badge:e.jsx(h,{tone:"meta",children:"Loose accuracy"})}),t.forEach(s=>{const i=xt(s.recordedAt);a.has(`time:${i}`)||a.set(`time:${i}`,{id:`time:${i}`,label:i,description:"Recorded during this time band",badge:e.jsx(h,{tone:"meta",className:"capitalize",children:i})})}),[...a.values()]}function Ti(t,a){return a.every(s=>s==="anchor:stop"?t.isStopAnchor:s==="anchor:path"?!t.isStopAnchor:s==="accuracy:precise"?t.accuracyMeters!=null&&t.accuracyMeters<20:s==="accuracy:loose"?t.accuracyMeters==null||t.accuracyMeters>=20:s.startsWith("time:")?xt(t.recordedAt)===s.slice(5):!0)}function Pi(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),s=Math.max(...t.map(d=>d.latitude)),i=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(s-a,1e-4),u=Math.max(l-i,1e-4);return t.map(d=>({x:12+(d.longitude-i)/u*76,y:12+(1-(d.latitude-a)/c)*76}))}function Di({curve:t,startLabel:a,endLabel:s,stopLabels:i}){const l=t.map((c,u)=>`${u===0?"M":"Q"} ${c.x} ${c.y}`).join(" ");return e.jsxs(N,{className:"overflow-hidden rounded-[30px] border border-white/10 bg-[radial-gradient(circle_at_top,rgba(114,204,255,0.18),transparent_44%),linear-gradient(180deg,rgba(6,11,26,0.98),rgba(8,14,28,0.92))] 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-white/42",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-white/64",children:"A softened path that prioritizes rhythm, stops, and landmarks over raw map noise."})]}),e.jsxs(h,{tone:"signal",children:[a," → ",s]})]}),e.jsxs("div",{className:"mt-5 rounded-[26px] border border-white/8 bg-[rgba(255,255,255,0.03)] 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:"rgba(255,255,255,0.86)",strokeWidth:"1.5",strokeDasharray:"2.8 2.8",filter:"url(#movementGlow)"}),t.map((c,u)=>e.jsx("g",{children:e.jsx("circle",{cx:c.x,cy:c.y,r:u===0||u===t.length-1?2.6:1.6,fill:u===0||u===t.length-1?"#ffffff":"rgba(170,229,255,0.96)"})},`${c.x}-${c.y}-${u}`))]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:i.map(c=>e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:c},c))})]})]})}function Li({points:t}){const a=Pi(t),s=a.map((i,l)=>`${l===0?"M":"L"} ${i.x} ${i.y}`).join(" ");return e.jsxs(N,{className:"rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,13,25,0.95),rgba(10,17,30,0.88))] 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-white/42",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-white/62",children:"Recent raw points preserved by the companion before long-term simplification."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-white/8 bg-[rgba(255,255,255,0.03)] 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:"rgba(255,255,255,0.02)"}),e.jsx("path",{d:s,fill:"none",stroke:"rgba(92,225,230,0.95)",strokeWidth:"1.6"}),a.map((i,l)=>e.jsx("circle",{cx:i.x,cy:i.y,r:l===0||l===a.length-1?2:1.1,fill:l===0||l===a.length-1?"#ffffff":"rgba(92,225,230,0.9)"},`${i.x}-${i.y}-${l}`))]})})]})}function Ii({point:t,draft:a}){return e.jsxs(N,{className:"grid gap-4 rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(12,18,32,0.98),rgba(8,13,24,0.98))] 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-white/42",children:"Raw datapoint"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:_t(t.recordedAt)}),e.jsx("div",{className:"mt-2 text-sm text-white/58",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(h,{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-white/40",children:"Recorded at"}),e.jsx(O,{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-white/40",children:"Speed (m/s)"}),e.jsx(O,{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-white/40",children:"Latitude"}),e.jsx(O,{value:a.latitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Longitude"}),e.jsx(O,{value:a.longitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Accuracy (m)"}),e.jsx(O,{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-white/40",children:"Altitude (m)"}),e.jsx(O,{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:k("h-10 rounded-full border px-4",a.isStopAnchor?"border-[var(--primary)] bg-[var(--primary)]/16 text-white":"border-white/10 bg-white/[0.04] text-white/64"),disabled:!0,children:[e.jsx(nt,{className:"mr-2 size-4"}),a.isStopAnchor?"Stop anchor":"Path point"]}),e.jsxs("div",{className:"text-sm text-white/50",children:["External id: ",e.jsx("span",{className:"text-white/72",children:t.externalUid})]})]}),e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-3 text-sm leading-6 text-white/56",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 Ui(){var ze,be,M,Oe,re;const t=ss(),a=ba(),s=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[i,l]=x.useState("life"),[c,u]=x.useState(new Date().toISOString().slice(0,10)),[d,m]=x.useState(new Date().toISOString().slice(0,7)),[p,f]=x.useState(null),[y,T]=x.useState(!1),[K,b]=x.useState(!1),[C,E]=x.useState(""),[H,V]=x.useState([]),[_,Y]=x.useState(null),[Q,X]=x.useState(null),[Z,Ge]=x.useState({stayIds:[],tripIds:[]}),[$e,Ee]=x.useState(!1),[Fe,Ve]=x.useState(null),[Se,ht]=x.useState(""),[ke,pt]=x.useState("distanceMeters"),_e=x.useRef(null),ae=te({queryKey:["forge-movement-day",c,...s],queryFn:async()=>(await ms({date:c,userIds:s})).movement}),q=te({queryKey:["forge-movement-month",d,...s],queryFn:async()=>(await us({month:d,userIds:s})).movement}),se=te({queryKey:["forge-movement-all-time",...s],queryFn:async()=>(await xs(s)).movement}),ie=te({queryKey:["forge-life-force",...s],queryFn:async()=>(await hs(s)).lifeForce}),B=te({queryKey:["forge-movement-settings",...s],queryFn:async()=>(await ps(s)).settings}),xe=te({queryKey:["forge-movement-places",...s],queryFn:async()=>(await Sa(s)).places}),w=te({queryKey:["forge-movement-trip",p],queryFn:async()=>p?(await gs(p)).movement:null,enabled:!!p}),Ye=te({queryKey:["forge-movement-selection",c,Z.stayIds.join(","),Z.tripIds.join(","),...s],queryFn:async()=>(await vs({...Z,userIds:s})).movement,enabled:Z.stayIds.length>0||Z.tripIds.length>0}),ve=Ce({mutationFn:async r=>is({trackingEnabled:r},s),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-settings"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]})}}),Xe=Ce({mutationFn:async r=>r.id?rs(r.id,r):wa(r,s),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-places"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]}),await a.invalidateQueries({queryKey:["forge-movement-all-time"]})}}),he=x.useMemo(()=>{const r=xe.data??[],v=Se.trim().toLowerCase();return v?r.filter(ee=>[ee.label,...ee.aliases,...ee.categoryTags].join(" ").toLowerCase().includes(v)):r},[Se,xe.data]),Ze=x.useMemo(()=>{var r;return Ci(((r=w.data)==null?void 0:r.trip.points)??[])},[(ze=w.data)==null?void 0:ze.trip.points]),R=x.useMemo(()=>{var ee;const r=((ee=w.data)==null?void 0:ee.trip.points)??[],v=Ia(C);return[...r].sort((U,ne)=>new Date(ne.recordedAt).getTime()-new Date(U.recordedAt).getTime()).filter(U=>(v.length===0||Ai(U).includes(v))&&Ti(U,H))},[C,H,(be=w.data)==null?void 0:be.trip.points]),Re=x.useMemo(()=>{var v;const r=((v=w.data)==null?void 0:v.trip.points.length)??0;return r===0?"No raw datapoints on this trip yet.":R.length===r&&C.trim().length===0&&H.length===0?`${r} datapoints visible`:`${R.length} of ${r} datapoints visible`},[R.length,C,H.length,(M=w.data)==null?void 0:M.trip.points.length]),Me=fa({count:R.length,getScrollElement:()=>_e.current,estimateSize:()=>96,overscan:8}),P=R.find(r=>r.id===_)??((Oe=w.data)==null?void 0:Oe.trip.points.find(r=>r.id===_))??R[0]??((re=w.data)==null?void 0:re.trip.points[0])??null;if(x.useEffect(()=>{if(K){if(!P){Y(null),X(null);return}Y(P.id),X(pa(P))}},[P,K]),x.useEffect(()=>{E(""),V([]),Y(null),X(null),b(!1)},[p]),ae.isLoading||q.isLoading||se.isLoading||B.isLoading||xe.isLoading)return e.jsx(ya,{eyebrow:"Movement",title:"Loading movement workspace",description:"Reconstructing stays, trips, and place intelligence across Forge.",columns:2,blocks:8});if(ae.isError||q.isError||se.isError||B.isError||xe.isError||!ae.data||!q.data||!se.data||!B.data)return e.jsx(ja,{eyebrow:"Movement",error:ae.error??q.error??se.error??B.error??xe.error??new Error("Movement data unavailable"),onRetry:()=>{ae.refetch(),q.refetch(),se.refetch(),B.refetch(),xe.refetch()}});const j=ae.data,fe=q.data,oe=se.data,de=B.data,S=Ye.data??j.selectionAggregate,J=j.trips.reduce((r,v)=>r+et(v).totalAp,0);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(fs,{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:`${j.summary.tripCount} trips today`,actions:e.jsx("div",{className:"flex flex-wrap gap-2",children:["life","day","month","all_time"].map(r=>e.jsx(A,{variant:"ghost",className:k("h-9 rounded-full border px-4 text-sm",i===r?"border-[var(--primary)] bg-[var(--primary)]/16 text-white":"border-white/10 bg-white/[0.04] text-white/64"),onClick:()=>l(r),children:r==="all_time"?"All time":r==="life"?"Life":r.charAt(0).toUpperCase()+r.slice(1)},r))})}),e.jsxs(N,{className:"grid gap-3 rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(12,20,34,0.98),rgba(8,14,25,0.96))] p-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Movement AP today"}),e.jsx("div",{className:"mt-2 text-3xl font-semibold text-white",children:Jt(J)}),e.jsx("div",{className:"mt-2 text-sm text-white/58",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-white/40",children:"Typical trip drain"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:j.trips[0]?tt(et(j.trips[0]).rateApPerHour):"0 AP/h"}),e.jsx("div",{className:"mt-2 text-sm text-white/58",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-white/40",children:"Life Force sync"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",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-white/58",children:ie.data?`${tt(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(ns,{children:e.jsxs(N,{className:"overflow-hidden rounded-[30px] border border-white/8 bg-[radial-gradient(circle_at_top_left,rgba(107,214,255,0.16),transparent_42%),linear-gradient(180deg,rgba(10,18,35,0.98),rgba(9,15,28,0.92))]",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-white/42",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-white",children:"Background stays and trips as structured life evidence"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-white/58",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(h,{tone:"signal",children:de.trackingEnabled?"Tracking on":"Tracking off"}),e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/72",children:de.publishMode.replaceAll("_"," ")}),e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-white/10 bg-white/[0.04] px-4",onClick:()=>ve.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(N,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Distance today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:je(j.summary.totalDistanceMeters)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Across trips, stops, and linked place changes."})]}),e.jsxs(N,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Idle time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:z(j.summary.totalIdleSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Time spent settled enough to count as a real stay."})]}),e.jsxs(N,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Estimated phone time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:z(j.summary.estimatedScreenTimeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Estimated from hourly Screen Time bins, not exact foreground traces."})]}),e.jsxs(N,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Known places"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:j.summary.knownPlaceCount}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Shared between Forge and the iPhone companion."})]}),e.jsxs(N,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(148,163,184,0.12),rgba(71,85,105,0.12))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Missing data"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:z(j.summary.missingDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.missingCount," grey gap",j.summary.missingCount===1?"":"s"," where Forge had over one hour without enough movement signal."]})]}),e.jsxs(N,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(251,191,36,0.12),rgba(16,185,129,0.08))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Repaired gaps"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:z(j.summary.repairedGapDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.repairedGapCount," inferred span",j.summary.repairedGapCount===1?"":"s"," classified as stay or move instead of leaving blank holes in the day."]})]}),e.jsxs(N,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(56,189,248,0.12),rgba(99,102,241,0.08))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Continued stays"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:z(j.summary.continuedStayDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.continuedStayCount," short stationary span",j.summary.continuedStayCount===1?"":"s"," carried forward so quiet home time stays continuous instead of disappearing."]})]})]})]})}),e.jsx(ls,{children:e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(8,13,24,0.92))] 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-white/42",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-white/56",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-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Span"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:z(S.durationSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:je(S.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Work overlap"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:z(S.trackedWorkSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Notes"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.noteCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Estimated phone time"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:z(S.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.pickupCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.notificationCount})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:S.placeLabels.map(r=>e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:r},r))}),S.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:S.topApps.map(r=>e.jsx(h,{tone:"default",className:"bg-[rgba(114,204,255,0.12)] text-white/80",children:(r.displayName||r.bundleIdentifier)+" · "+z(r.totalActivitySeconds)},r.id))}):null,S.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:S.topCategories.map(r=>e.jsx(h,{tone:"default",className:"bg-white/[0.05] text-white/64",children:r.categoryLabel},r.id))}):null]})})]}),i==="life"?e.jsx(os,{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-white/38",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(ji,{userIds:s})]})}):null,i==="day"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.55fr)_minmax(22rem,1fr)]",children:[e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(7,12,22,0.92))] 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-white/42",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-white/58",children:"A single-row timeline from 00:00 to 24:00, always compressed into one navigable strip."})]}),e.jsx(O,{type:"date",value:c,onChange:r=>u(r.target.value),className:"w-[11rem]"})]}),e.jsx("div",{className:"mt-6 overflow-x-auto pb-2",children:e.jsxs("div",{className:"min-w-[52rem]",children:[e.jsx("div",{className:"mb-3 flex justify-between text-[11px] uppercase tracking-[0.18em] text-white/36",children:["00:00","06:00","12:00","18:00","24:00"].map(r=>e.jsx("span",{children:r},r))}),e.jsx("div",{className:"flex h-28 items-stretch overflow-hidden rounded-[28px] border border-white/10 bg-[rgba(255,255,255,0.03)] p-2",children:j.segments.map(r=>{const v=Math.max(9,r.durationSeconds/86400*100),ee=r.kind==="stay"?Z.stayIds.includes(r.id):r.kind==="trip"?Z.tripIds.includes(r.id):!1;return e.jsxs("button",{type:"button",className:k("relative flex min-w-[5.5rem] flex-col justify-between rounded-[22px] border px-3 py-2 text-left transition",r.kind==="missing"?"border-slate-400/20 bg-[linear-gradient(180deg,rgba(148,163,184,0.18),rgba(51,65,85,0.14))] hover:border-slate-300/30 hover:bg-[rgba(148,163,184,0.14)]":ee?"border-[rgba(171,232,255,0.5)] bg-[rgba(171,232,255,0.16)]":"border-white/6 bg-[linear-gradient(180deg,rgba(255,255,255,0.08),rgba(255,255,255,0.02))] hover:border-white/14 hover:bg-white/[0.08]"),style:{width:`${v}%`},onClick:()=>{r.kind!=="missing"&&Ge(U=>{const ne=new Set(U.stayIds),I=new Set(U.tripIds);return r.kind==="stay"?ne.has(r.id)?ne.delete(r.id):ne.add(r.id):I.has(r.id)?I.delete(r.id):(I.add(r.id),f(r.id)),{stayIds:[...ne],tripIds:[...I]}})},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(h,{tone:r.kind==="trip"?"signal":r.kind==="missing"?"meta":"default",className:"bg-white/[0.08] text-white/82",children:r.kind==="missing"?"gap":r.kind}),e.jsx("span",{className:"text-[11px] text-white/46",children:z(r.durationSeconds)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"line-clamp-2 text-sm font-semibold text-white",children:r.label}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-white/52",children:r.subtitle})]})]},r.id)})})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(h,{tone:"signal",children:Ni(c)}),e.jsxs(h,{tone:"default",className:"bg-white/[0.06] text-white/72",children:[j.summary.tripCount," trips"]}),e.jsxs(h,{tone:"default",className:"bg-white/[0.06] text-white/72",children:[j.summary.stayCount," stays"]}),e.jsxs(h,{tone:"meta",children:[j.summary.missingCount," gaps"]})]})]}),e.jsx("div",{className:"grid gap-4",children:w.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-white/42",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-white/10 bg-white/[0.04] px-4",onClick:()=>T(r=>!r),children:y?"Stylized graph":"Exact path"})})]}),y?e.jsx(Li,{points:w.data.trip.points}):e.jsx(Di,{curve:w.data.stylizedPath.curve,startLabel:w.data.stylizedPath.startLabel,endLabel:w.data.stylizedPath.endLabel,stopLabels:w.data.stylizedPath.stops.map(r=>r.label)}),e.jsxs(N,{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Trip context"}),(()=>{const r=et(w.data.trip);return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(h,{tone:"signal",children:je(w.data.trip.distanceMeters)}),e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:w.data.trip.activityType||w.data.trip.travelMode}),e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:z(w.data.trip.durationSeconds)}),e.jsx(h,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:tt(r.rateApPerHour)}),e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:Jt(r.totalAp)})]})})})(),e.jsx("div",{className:"mt-4 text-sm leading-6 text-white/58",children:Si(w.data.trip.startedAt,w.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-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Hourly estimate"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:z(w.data.trip.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:w.data.trip.pickupCount})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:w.data.trip.notificationCount})]})]}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-white/48",children:"Derived from Screen Time hourly bins, not exact foreground traces."}),w.data.trip.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:w.data.trip.topApps.map(r=>e.jsx(h,{tone:"default",className:"bg-[rgba(114,204,255,0.12)] text-white/80",children:(r.displayName||r.bundleIdentifier)+" · "+z(r.totalActivitySeconds)},r.id))}):null,w.data.trip.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:w.data.trip.topCategories.map(r=>e.jsx(h,{tone:"default",className:"bg-white/[0.05] text-white/64",children:r.categoryLabel},r.id))}):null]})]}):e.jsx(N,{className:"rounded-[30px] border border-dashed border-white/12 bg-white/[0.03] p-6 text-white/58",children:"Select a trip segment to open the stylized trajectory card and exact path toggle."})})]}):null,i==="month"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(18rem,0.85fr)]",children:[e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(9,15,28,0.97),rgba(8,13,24,0.92))] 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-white/42",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-white/58",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(O,{type:"month",value:d,onChange:r=>m(r.target.value),className:"w-[10.5rem]"}),["distanceMeters","movingSeconds","idleSeconds","caloriesKcal"].map(r=>e.jsx(A,{variant:"ghost",className:k("h-9 rounded-full border px-4 text-sm",ke===r?"border-[var(--primary)] bg-[var(--primary)]/14 text-white":"border-white/10 bg-white/[0.04] text-white/62"),onClick:()=>pt(r),children:r==="distanceMeters"?"Distance":r==="movingSeconds"?"Moving":r==="idleSeconds"?"Idle":"Calories"},r))]})]}),e.jsx("div",{className:"mt-6 h-[24rem]",children:e.jsx(bs,{width:"100%",height:"100%",children:e.jsxs(ws,{data:fe.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:"rgba(110,220,255,0.7)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(110,220,255,0.05)"})]})}),e.jsx(ys,{stroke:"rgba(255,255,255,0.08)",vertical:!1}),e.jsx(js,{dataKey:"dateKey",tick:{fill:"rgba(255,255,255,0.46)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(Ns,{tick:{fill:"rgba(255,255,255,0.46)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(Ss,{contentStyle:{background:"rgba(7,12,24,0.94)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:16},formatter:r=>ki(ke,Number(r))}),e.jsx(ks,{type:"monotone",dataKey:ke,stroke:"rgba(126,233,255,0.95)",fill:"url(#movementMonthFill)",strokeWidth:2.4})]})})})]}),e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Month totals"}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:je(fe.totals.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Moving time"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:z(fe.totals.movingSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Settled time"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:z(fe.totals.idleSeconds)})]})]})]})]}):null,i==="all_time"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(20rem,0.95fr)]",children:[e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(8,13,25,0.97),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs(N,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Trips"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:oe.summary.tripCount})]}),e.jsxs(N,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Known places"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:oe.summary.knownPlaceCount})]}),e.jsxs(N,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:je(oe.summary.totalDistanceMeters)})]}),e.jsxs(N,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Countries"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:oe.summary.visitedCountries})]})]}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:oe.recentTrips.map(r=>e.jsx("button",{type:"button",className:"rounded-[24px] border border-white/8 bg-white/[0.03] p-4 text-left transition hover:bg-white/[0.06]",onClick:()=>{l("day"),f(r.id)},children:(()=>{const v=et({startedAt:r.startedAt,endedAt:new Date(new Date(r.startedAt).getTime()+36e5).toISOString(),expectedMet:2});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Recent travel"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:r.label||"Untitled trip"}),e.jsxs("div",{className:"mt-1 text-sm text-white/56",children:[je(r.distanceMeters)," · ",r.activityType||"travel"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(h,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:tt(v.rateApPerHour)})})]})})()},r.id))})]}),e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Place categories"}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:oe.categoryBreakdown.map(r=>e.jsxs(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:[r.tag," · ",r.count]},r.tag))})]})]}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(22rem,0.95fr)]",children:[e.jsx(ds,{children:e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(8,14,28,0.96),rgba(9,15,28,0.92))] 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-white/42",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-white/58",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(O,{value:Se,onChange:r=>ht(r.target.value),placeholder:"Search places",className:"w-[11rem]"}),e.jsx(A,{onClick:()=>{Ve(null),Ee(!0)},children:"Add place"})]})]}),e.jsx("div",{className:"mt-5 grid gap-3",children:he.map(r=>e.jsxs("button",{type:"button",className:"flex items-start justify-between gap-3 rounded-[24px] border border-white/8 bg-white/[0.03] p-4 text-left transition hover:bg-white/[0.06]",onClick:()=>{Ve(r),Ee(!0)},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-white",children:r.label}),e.jsxs("div",{className:"mt-1 text-sm text-white/56",children:[r.latitude.toFixed(4),", ",r.longitude.toFixed(4)," · radius ",Math.round(r.radiusMeters)," m"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:r.categoryTags.map(v=>e.jsx(h,{tone:"default",className:"bg-white/[0.06] text-white/74",children:v},v))})]}),e.jsx(It,{className:"mt-1 size-4 text-white/42"})]},r.id))})]})}),e.jsxs(N,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(8,13,24,0.92))] 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-white/42",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-white/58",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(h,{className:"bg-white/[0.06] text-white/74",children:"Life graph"}),e.jsx(h,{className:"bg-white/[0.06] text-white/74",children:"Day strip"}),e.jsx(h,{className:"bg-white/[0.06] text-white/74",children:"Month chart"}),e.jsx(h,{className:"bg-white/[0.06] text-white/74",children:"Known places"}),e.jsx(h,{className:"bg-white/[0.06] text-white/74",children:"Selection aggregate"})]})]})]}),w.data?e.jsx(Na,{open:K,onOpenChange:r=>{b(r),r||(E(""),V([]),Y(null),X(null))},eyebrow:"Movement data",title:w.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(cs,{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(ka,{title:"Datapoint browser",description:"Search raw points by time band, anchor status, or accuracy before opening the point editor.",query:C,onQueryChange:E,options:Ze,selectedOptionIds:H,onSelectedOptionIdsChange:V,resultSummary:Re,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(N,{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-white/45",children:"Raw datapoints"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:"Open a point to correct or delete it."})]}),e.jsx(h,{tone:"meta",children:Re})]}),e.jsx("div",{ref:_e,className:"h-[34rem] overflow-y-auto rounded-[24px] border border-white/8 bg-white/[0.03]",children:R.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-white/50",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:`${Me.getTotalSize()}px`},children:Me.getVirtualItems().map(r=>{const v=R[r.index];return e.jsx("div",{className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${r.start}px)`},children:e.jsxs("button",{type:"button",className:k("grid w-full gap-3 rounded-[20px] border px-4 py-3 text-left transition",_===v.id?"border-[rgba(171,232,255,0.34)] bg-[rgba(171,232,255,0.12)]":"border-white/8 bg-white/[0.04] hover:bg-white/[0.07]"),onClick:()=>{Y(v.id),X(pa(v))},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-white",children:[e.jsx(Xa,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:_t(v.recordedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[v.latitude.toFixed(5),", ",v.longitude.toFixed(5)]})]}),e.jsx(h,{tone:v.isStopAnchor?"signal":"meta",children:v.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(h,{tone:"meta",className:"capitalize",children:xt(v.recordedAt)}),v.accuracyMeters!=null?e.jsxs(h,{tone:"meta",children:[Math.round(v.accuracyMeters)," m accuracy"]}):null,v.speedMps!=null?e.jsxs(h,{tone:"meta",children:[v.speedMps.toFixed(1)," m/s"]}):null]})]})},v.id)})})})]})]}),P&&Q?e.jsx(Ii,{point:P,draft:Q}):e.jsx(N,{className:"rounded-[28px] border border-dashed border-white/12 bg-white/[0.03] p-6 text-white/56",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(Ma,{open:$e,onOpenChange:Ee,place:Fe,onSave:async r=>{await Xe.mutateAsync(r)}})]})}export{Ui as MovementPage};
@@ -1 +0,0 @@
1
- import{r as p,j as e,aK as Ce,cu as Me,b3 as Qe,b5 as Re,c2 as ze,bg as He,ce as Ye,c7 as Ge,b4 as Je,ca as We}from"./vendor-kIz9EZnX.js";import{j as Xe,i as F,k as ie}from"./state-VYvD1QVP.js";import{b as Fe,c as z,Z as Ze,u as et,g as f,bk as b,bl as k,ao as tt,bm as at,bn as st,bo as W,bp as De,bq as Ie,E as it,B as Q,C as I,h as B,d as nt,br as rt,I as D,bs as lt,T as _e,m as Le,a as ot,bt as dt,bu as ct,bv as ut,i as pt,bw as mt,bx as ht,by as xt,bz as gt,bA as yt,bB as vt,bC as ft,O as bt,bD as kt}from"./index-BHIKoiZ6.js";import{N as ne}from"./note-markdown-CsGQhQXF.js";import{n as Z,N as re,f as jt,p as wt,b as Nt}from"./note-tags-input-DdZi93tj.js";import{P as Tt}from"./page-hero-oFHaAjtL.js";import{F as St}from"./floating-action-menu-zzC2r0Ob.js";import"./motion-CfdU2F35.js";import"./ui-CsEkP2V8.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";import"./graph-BTa79qum.js";function At(i){return i.trim().toLowerCase()}function Ct(i,l){return i.includes(l)?i:[...i,l]}function Mt({entityOptions:i,selectedEntityValues:l,onSelectedEntityValuesChange:d,selectedTextTerms:u,onSelectedTextTermsChange:_,placeholder:j="Filter by linked entity or add free text"}){const[S,A]=p.useState(""),[ee,g]=p.useState(!1),[H,y]=p.useState(0),P=At(S),C=p.useMemo(()=>l.map(s=>i.find(c=>c.value===s)).filter(Boolean),[i,l]),L=p.useMemo(()=>{const s=i.filter(c=>!l.includes(c.value));return P?s.filter(c=>`${c.label} ${c.description??""} ${c.searchText??""}`.toLowerCase().includes(P)).slice(0,8):s.slice(0,8)},[i,P,l]),w=S.trim().length>0&&!u.includes(S.trim()),Y=s=>{d(Ct(l,s)),A(""),y(0),g(!1)},K=(s=S)=>{const c=s.trim();!c||u.includes(c)||(_([...u,c]),A(""),y(0),g(!1))},q=s=>{d(l.filter(c=>c!==s))},m=s=>{_(u.filter(c=>c!==s))};return e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2 text-[11px] uppercase tracking-[0.16em] text-white/40",children:[e.jsx("span",{children:"Search hints: entity chips match linked records, free-text chips match note body or author."}),e.jsx("button",{type:"button",onClick:()=>K(),disabled:!w,className:"rounded-full border border-white/8 bg-white/[0.04] px-2.5 py-1 text-[10px] tracking-[0.14em] text-white/62 transition hover:bg-white/[0.08] hover:text-white disabled:cursor-not-allowed disabled:opacity-40",children:"Free text"})]}),e.jsxs("div",{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(135deg,rgba(19,28,48,0.88),rgba(10,14,26,0.98))] px-4 py-3 shadow-[0_24px_70px_rgba(3,8,18,0.2)]",children:[C.length>0||u.length>0?e.jsxs("div",{className:"mb-3 flex flex-wrap gap-2",children:[C.map(s=>e.jsxs("span",{className:"inline-flex max-w-full items-center gap-2 rounded-full border border-white/8 bg-white/[0.06] px-2.5 py-1.5",children:[s.kind?e.jsx(Fe,{kind:s.kind,label:s.label,compact:!0,gradient:!1,className:"max-w-[16rem]"}):e.jsx(z,{className:"bg-white/[0.08] text-white/78",children:s.label}),e.jsx("button",{type:"button",className:"rounded-full text-white/50 transition hover:text-white",onClick:()=>q(s.value),"aria-label":`Remove ${s.label}`,children:e.jsx(Ce,{className:"size-3.5"})})]},s.value)),u.map(s=>e.jsxs("span",{className:"inline-flex max-w-full items-center gap-2 rounded-full border border-cyan-300/16 bg-cyan-400/10 px-2.5 py-1.5 text-sm text-cyan-50",children:[e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[e.jsx(Me,{className:"size-3.5"}),e.jsx("span",{className:"max-w-[16rem] truncate",children:s})]}),e.jsx("button",{type:"button",className:"rounded-full text-cyan-100/70 transition hover:text-white",onClick:()=>m(s),"aria-label":`Remove free-text filter ${s}`,children:e.jsx(Ce,{className:"size-3.5"})})]},s))]}):null,u.length>1?e.jsx("div",{className:"mb-3 text-xs text-white/42",children:"Free-text chips are combined with OR."}):null,e.jsxs("div",{className:"relative",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(Qe,{className:"size-4 text-white/34"}),e.jsx("input",{value:S,onChange:s=>{A(s.target.value),g(!0),y(0)},onFocus:()=>g(!0),onBlur:()=>{window.setTimeout(()=>g(!1),120)},onKeyDown:s=>{if(s.key==="Backspace"&&!S){if(u.length>0){m(u[u.length-1]);return}l.length>0&&q(l[l.length-1]);return}if(s.key==="ArrowDown"){s.preventDefault(),g(!0),y(N=>L.length===0?0:Math.min(L.length-1,N+1));return}if(s.key==="ArrowUp"){s.preventDefault(),y(N=>Math.max(0,N-1));return}if(s.key==="Escape"){g(!1);return}if(s.key!=="Enter")return;s.preventDefault();const c=L[H];if(c){Y(c.value);return}K()},placeholder:j,className:"min-w-0 flex-1 bg-transparent text-sm text-white placeholder:text-white/34 focus:outline-none"})]}),ee?e.jsxs("div",{className:"absolute top-full z-20 mt-2 w-full rounded-[22px] border border-white/8 bg-[rgba(8,13,24,0.96)] p-2 shadow-[0_26px_60px_rgba(4,8,18,0.32)] backdrop-blur-xl",children:[L.map((s,c)=>e.jsx("button",{type:"button",className:Ze("flex w-full items-start justify-between gap-3 rounded-[18px] px-3 py-2.5 text-left transition",c===H?"bg-white/[0.1] text-white":"text-white/70 hover:bg-white/[0.06] hover:text-white"),onMouseEnter:()=>y(c),onMouseDown:N=>N.preventDefault(),onClick:()=>Y(s.value),children:e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-sm font-medium",children:s.kind?e.jsx(Fe,{kind:s.kind,label:s.label,compact:!0,gradient:!1}):s.label}),s.description?e.jsx("div",{className:"mt-1 text-xs leading-5 text-white/46",children:s.description}):null]})},s.value)),w?e.jsxs("button",{type:"button",className:"mt-1 flex w-full items-center gap-2 rounded-[18px] px-3 py-2.5 text-left text-sm text-cyan-100 transition hover:bg-white/[0.06]",onMouseDown:s=>s.preventDefault(),onClick:()=>K(),children:[e.jsx(Me,{className:"size-4"}),e.jsxs("span",{className:"truncate",children:['Add free text "',S.trim(),'"']})]}):null,L.length===0&&!w?e.jsx("div",{className:"px-3 py-2.5 text-sm text-white/42",children:"Keep typing to find a linked entity, or press Enter to add a free-text badge."}):null]}):null]})]})]})}const Ft=new Set(["goal","project","task","strategy","habit","tag","psyche_value","behavior_pattern","behavior","belief_entry","mode_profile","flashcard","trigger_report"]);function Be(i){return Ft.has(i)}function h(i,l){return`${i}:${l}`}function X(i){const l=i.indexOf(":");if(l<=0||l>=i.length-1)return null;const d=i.slice(0,l);return Be(d)?{entityType:d,entityId:i.slice(l+1)}:null}function Ee(i){return i!==null}function qe(i){const l=i.getAll("linkedTo"),d=i.get("entityType"),u=i.get("entityId");return d&&u&&Be(d)&&l.unshift(h(d,u)),Array.from(new Set(l.map(_=>_.trim()).filter(Boolean)))}function Dt(i){return Array.from(new Set(i.getAll("textTerms").map(l=>l.trim()).filter(Boolean)))}function It(i){return Z(i.getAll("tags"))}function R(i,l=[]){return{contentMarkdown:(i==null?void 0:i.contentMarkdown)??"",author:(i==null?void 0:i.author)??"",linkedValues:(i==null?void 0:i.links.map(d=>h(d.entityType,d.entityId)))??l,tags:Z((i==null?void 0:i.tags)??[]),destroyAtInput:jt((i==null?void 0:i.destroyAt)??null),destroyDelayValue:"",destroyDelayUnit:"days"}}function _t(i){return[...i].sort((l,d)=>l.label.localeCompare(d.label))}function $e(i){return wt(i.destroyAtInput)??Nt(i.destroyDelayValue,i.destroyDelayUnit)}function Ht(){var ve,fe,be,ke,je,we,Ne,Te;const i=Re(),l=Xe(),d=et(),[u,_]=ze(),[j,S]=p.useState(()=>qe(u)),[A,ee]=p.useState(()=>It(u)),[g,H]=p.useState(()=>Dt(u)),[y,P]=p.useState(u.get("author")??""),[C,L]=p.useState(u.get("updatedFrom")??""),[w,Y]=p.useState(u.get("updatedTo")??""),[K,q]=p.useState(!1),[m,s]=p.useState(()=>R(null,qe(u))),[c,N]=p.useState(null),[v,T]=p.useState(null),[$,le]=p.useState(null),oe=F({queryKey:["forge-psyche-values"],queryFn:mt}),de=F({queryKey:["forge-psyche-patterns"],queryFn:ht}),ce=F({queryKey:["forge-psyche-behaviors"],queryFn:xt}),ue=F({queryKey:["forge-psyche-beliefs"],queryFn:gt}),pe=F({queryKey:["forge-psyche-modes"],queryFn:yt}),me=F({queryKey:["forge-psyche-flashcards"],queryFn:vt}),he=F({queryKey:["forge-psyche-reports"],queryFn:ft}),xe=Array.isArray(d.selectedUserIds)?d.selectedUserIds:[],U=F({queryKey:["forge-life-force",...xe],queryFn:async()=>(await bt(xe)).lifeForce});p.useEffect(()=>{const a=new URLSearchParams;for(const n of j)a.append("linkedTo",n);for(const n of A)a.append("tags",n);for(const n of g)a.append("textTerms",n);y.trim()&&a.set("author",y.trim()),C&&a.set("updatedFrom",C),w&&a.set("updatedTo",w),_(a,{replace:!0})},[y,j,A,g,_,C,w]);const G=p.useMemo(()=>{var n,x,J,o,r,Se,Ae;const a=[...d.snapshot.goals.map(t=>({value:h("goal",t.id),label:t.title,description:k(t.description,t.user,"Goal"),searchText:b([t.title,t.description],t),kind:f("goal")??void 0})),...d.snapshot.dashboard.projects.map(t=>({value:h("project",t.id),label:t.title,description:k(`${t.description}${t.description?" · ":""}${t.goalTitle}`,t.user,t.goalTitle),searchText:b([t.title,t.description,t.goalTitle],t),kind:f("project")??void 0})),...d.snapshot.tasks.map(t=>({value:h("task",t.id),label:t.title,description:k(`${t.description}${t.description?" · ":""}${t.owner}`,t.user,t.owner),searchText:b([t.title,t.description,t.owner],t),kind:f("task")??void 0})),...d.snapshot.strategies.map(t=>({value:h("strategy",t.id),label:t.title,description:k(t.overview,t.user,"Strategy"),searchText:b([t.title,t.overview,t.endStateDescription],t),kind:f("strategy")??void 0})),...d.snapshot.habits.map(t=>({value:h("habit",t.id),label:t.title,description:k(t.description,t.user,"Habit"),searchText:b([t.title,t.description],t),kind:f("habit")??void 0})),...d.snapshot.tags.map(t=>({value:h("tag",t.id),label:t.name,description:k(t.description,t.user,t.kind),searchText:b([t.name,t.kind,t.description],t),kind:f("tag")??void 0})),...(((n=oe.data)==null?void 0:n.values)??[]).map(t=>({value:h("psyche_value",t.id),label:t.title,description:k(t.description,t.user,"Psyche value"),searchText:b([t.title,t.description,t.valuedDirection],t),kind:f("psyche_value")??void 0})),...(((x=de.data)==null?void 0:x.patterns)??[]).map(t=>({value:h("behavior_pattern",t.id),label:t.title,description:k(t.description,t.user,"Behavior pattern"),searchText:b([t.title,t.description,t.targetBehavior],t),kind:f("behavior_pattern")??void 0})),...(((J=ce.data)==null?void 0:J.behaviors)??[]).map(t=>({value:h("behavior",t.id),label:t.title,description:k(t.description,t.user,"Behavior"),searchText:b([t.title,t.description,t.kind],t),kind:f("behavior")??void 0})),...(((o=ue.data)==null?void 0:o.beliefs)??[]).map(t=>({value:h("belief_entry",t.id),label:t.statement,description:k(t.flexibleAlternative||t.originNote,t.user,"Belief"),searchText:b([t.statement,t.flexibleAlternative,t.originNote],t),kind:f("belief_entry")??void 0})),...(((r=pe.data)==null?void 0:r.modes)??[]).map(t=>({value:h("mode_profile",t.id),label:t.title,description:k(t.archetype||t.family,t.user,"Mode"),searchText:b([t.title,t.archetype,t.family,t.persona],t),kind:f("mode_profile")??void 0})),...(((Se=me.data)==null?void 0:Se.flashcards)??[]).map(t=>({value:h("flashcard",t.id),label:t.title||t.message,description:k(t.triggerSentence||t.triggerSituation,t.user,"Flashcard"),searchText:b([t.title,t.message,t.triggerSentence,t.triggerSituation,...t.tags],t),kind:f("flashcard")??void 0})),...(((Ae=he.data)==null?void 0:Ae.reports)??[]).map(t=>({value:h("trigger_report",t.id),label:t.title,description:k(t.eventSituation,t.user,"Trigger report"),searchText:b([t.title,t.eventSituation,t.customEventType??""],t),kind:f("trigger_report")??void 0}))];return _t(a)},[(ve=ce.data)==null?void 0:ve.behaviors,(fe=ue.data)==null?void 0:fe.beliefs,(be=me.data)==null?void 0:be.flashcards,(ke=pe.data)==null?void 0:ke.modes,(je=de.data)==null?void 0:je.patterns,(we=he.data)==null?void 0:we.reports,d.snapshot.dashboard.projects,d.snapshot.goals,d.snapshot.habits,d.snapshot.strategies,d.snapshot.tags,d.snapshot.tasks,(Ne=oe.data)==null?void 0:Ne.values]),Pe=p.useMemo(()=>G.map(a=>{const n=X(a.value);return{value:a.value,label:a.label,description:a.description,searchText:a.searchText,kind:a.kind,entityType:(n==null?void 0:n.entityType)??"goal",entityId:(n==null?void 0:n.entityId)??""}}),[G]),Ke=p.useMemo(()=>j.map(a=>X(a)).filter(Boolean),[j]),O=F({queryKey:["notes-index",j.join("|"),A.join("|"),g.join("|"),y.trim(),C,w],queryFn:()=>kt({linkedTo:Ke,tags:A,textTerms:g,author:y.trim()||void 0,updatedFrom:C||void 0,updatedTo:w||void 0,limit:200})}),te=async()=>{await Promise.all([l.invalidateQueries({queryKey:["notes-index"]}),pt(l)])},ge=ie({mutationFn:async a=>tt({contentMarkdown:a.contentMarkdown.trim(),author:a.author.trim()||null,tags:Z(a.tags),destroyAt:$e(a),links:a.linkedValues.map(n=>X(n)).filter(Ee).map(n=>({entityType:n.entityType,entityId:n.entityId}))}),onSuccess:async()=>{s(R(null,j)),q(!1),await te()}}),ye=ie({mutationFn:async({noteId:a,draft:n})=>at(a,{contentMarkdown:n.contentMarkdown.trim(),author:n.author.trim()||null,tags:Z(n.tags),destroyAt:$e(n),links:n.linkedValues.map(x=>X(x)).filter(Ee).map(x=>({entityType:x.entityType,entityId:x.entityId}))}),onSuccess:async()=>{N(null),T(null),await te()}}),ae=ie({mutationFn:a=>st(a),onSuccess:te}),V=((Te=O.data)==null?void 0:Te.notes)??[],Ue=new Date().toISOString().slice(0,10),Oe=V.filter(a=>a.createdAt.slice(0,10)===Ue).length*W().totalAp,M=$?V.find(a=>a.id===$.noteId)??null:null,se=M?De(M):null,E=se?Ie(se.entityType,se.entityId):null,Ve=p.useMemo(()=>M?[{id:"open-linked",label:"Open linked record",description:E?"Jump back into the main entity this note is attached to.":"This note has no navigable linked record yet.",icon:He,disabled:!E,onSelect:()=>{E&&i(E.includes("#")?E:`${E}#notes`)}},{id:"edit-note",label:"Edit note",description:"Update the Markdown body, note tags, expiry, or connected entity links.",icon:Ye,onSelect:()=>{N(M.id),T(R(M))}},{id:"delete-note",label:"Delete note",description:"Soft-delete this note from the main workspace.",icon:Ge,tone:"danger",disabled:ae.isPending,onSelect:()=>{ae.mutateAsync(M.id)}}]:[],[E,M,ae,i]);return O.isError?e.jsx(it,{eyebrow:"Notes",error:O.error,onRetry:()=>void O.refetch()}):e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Tt,{title:"Notes",titleText:"Notes",description:"Notes are first-class Markdown entities in Forge. Search them by linked records, note tags, date, or free text, then create durable or ephemeral notes that stay connected to the rest of the graph.",badge:`${V.length} visible`,actions:e.jsxs(Q,{onClick:()=>{s(R(null,j)),q(!0)},children:[e.jsx(Je,{className:"size-4"}),"New note"]})}),e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(I,{className:"border-[var(--primary)]/16 shadow-[var(--card-shadow)]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Quick note default"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:B(W().totalAp)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Standalone notes count as a tiny Action Point impulse unless a richer active work context already covers them."})]}),e.jsxs(I,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Notes created today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:B(Oe)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Visible notes created today in this workspace at the default quick note cost."})]}),e.jsxs(I,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Life Force sync"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:U.data?`${B(U.data.spentTodayAp)} / ${B(U.data.dailyBudgetAp)}`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Notes participate in the same Action Point ledger as tasks, habits, movement, and calendar work."})]}),e.jsxs(I,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Instant headroom"}),e.jsx("div",{className:"mt-3 text-2xl font-display text-[var(--ui-ink-strong)]",children:U.data?nt(U.data.instantFreeApPerHour):"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Useful when deciding whether to just capture a quick note or stay inside a heavier work stream."})]})]}),e.jsx(rt,{children:e.jsxs(I,{className:"grid gap-4",children:[e.jsx(Mt,{entityOptions:Pe,selectedEntityValues:j,onSelectedEntityValuesChange:S,selectedTextTerms:g,onSelectedTextTermsChange:H}),e.jsx(re,{value:A,onChange:ee,placeholder:"Filter by memory tag or custom note tag"}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(12rem,0.38fr)_minmax(12rem,0.38fr)]",children:[e.jsx(D,{value:y,onChange:a=>P(a.target.value),placeholder:"Filter by author"}),e.jsx(D,{type:"date",value:C,onChange:a=>L(a.target.value)}),e.jsx(D,{type:"date",value:w,onChange:a=>Y(a.target.value)})]})]})}),K?e.jsx(lt,{children:e.jsxs(I,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"New note"}),e.jsxs("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:["Notes are independent Markdown entities. Link them to one or more real records, add memory-system or custom tags, and optionally make them ephemeral with an automatic destroy time. Standalone notes default to"," ",B(W().totalAp),"."]})]}),e.jsx(Q,{variant:"ghost",onClick:()=>{q(!1),s(R(null,j))},children:"Cancel"})]}),e.jsx(_e,{value:m.contentMarkdown,onChange:a=>s(n=>({...n,contentMarkdown:a.target.value})),className:"min-h-[16rem]",placeholder:"Write the note in Markdown. This can be as short as a handoff line or as long as a wiki page."}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]",children:[e.jsx(D,{value:m.author,onChange:a=>s(n=>({...n,author:a.target.value})),placeholder:"Optional author"}),e.jsx(Le,{options:G,selectedValues:m.linkedValues,onChange:a=>s(n=>({...n,linkedValues:a})),placeholder:"Link this note to strategies, goals, projects, tasks, habits, or human/bot-owned records",emptyMessage:"No matching entities found yet."})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsx(re,{value:m.tags,onChange:a=>s(n=>({...n,tags:a}))}),e.jsxs("div",{className:"grid gap-3 rounded-[22px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ephemeral auto-destroy"}),e.jsx("div",{className:"mt-2 text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Set an exact destroy time or a relative delay. Leaving both blank keeps the note durable."})]}),e.jsx(D,{type:"datetime-local",value:m.destroyAtInput,onChange:a=>s(n=>({...n,destroyAtInput:a.target.value}))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_10rem]",children:[e.jsx(D,{type:"number",min:"1",value:m.destroyDelayValue,onChange:a=>s(n=>({...n,destroyDelayValue:a.target.value})),placeholder:"Destroy after"}),e.jsxs("select",{className:"rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)]",value:m.destroyDelayUnit,onChange:a=>s(n=>({...n,destroyDelayUnit:a.target.value})),children:[e.jsx("option",{value:"hours",children:"Hours"}),e.jsx("option",{value:"days",children:"Days"})]})]})]})]}),e.jsxs("div",{className:"rounded-[22px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Preview"}),e.jsx("div",{className:"mt-3",children:m.contentMarkdown.trim()?e.jsx(ne,{markdown:m.contentMarkdown}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"Markdown preview appears here."})})]}),e.jsx("div",{className:"flex flex-wrap justify-end gap-2",children:e.jsx(Q,{pending:ge.isPending,pendingLabel:"Saving",disabled:m.contentMarkdown.trim().length===0||m.linkedValues.length===0,onClick:()=>void ge.mutateAsync(m),children:"Save note"})})]})}):null,O.isLoading?e.jsx(I,{className:"text-sm text-[var(--ui-ink-soft)]",children:"Loading notes…"}):V.length===0?e.jsx(ot,{eyebrow:"Notes",title:"No matching notes yet",description:"Try broader linked-entity filters, remove a date bound, or add the first durable note from the button above."}):e.jsx(dt,{children:e.jsx("div",{className:"grid gap-3",children:V.map(a=>{const n=De(a),x=n?Ie(n.entityType,n.entityId):null,J=c===a.id&&v!==null;return e.jsxs(I,{className:"min-w-0 overflow-hidden p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:[(a.author??"Unknown author").toString()," •"," ",new Date(a.updatedAt).toLocaleString()]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(z,{className:"bg-[var(--primary)]/12 text-[var(--primary)]",wrap:!0,children:[B(W().totalAp)," ","quick note"]}),a.links.map(o=>e.jsxs(z,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",wrap:!0,children:[ct(o.entityType),o.anchorKey?` · ${ut(o.anchorKey)}`:""]},`${a.id}-${o.entityType}-${o.entityId}-${o.anchorKey??""}`)),(a.tags??[]).map(o=>e.jsx(z,{className:"border-[var(--info)]/20 bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",wrap:!0,children:o},`${a.id}-tag-${o}`)),a.destroyAt?e.jsxs(z,{className:"border-[var(--warning)]/20 bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",wrap:!0,children:["Ephemeral · deletes"," ",new Date(a.destroyAt).toLocaleString()]}):null]})]}),e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",onClick:o=>{o.preventDefault(),o.stopPropagation();const r=o.currentTarget.getBoundingClientRect();le({noteId:a.id,position:{x:r.right-8,y:r.bottom+8}})},"aria-label":`Open actions for note ${a.id}`,children:e.jsx(We,{className:"size-4"})})]}),J?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsx(_e,{value:v.contentMarkdown,onChange:o=>T(r=>r&&{...r,contentMarkdown:o.target.value}),className:"min-h-[14rem]"}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.4fr)]",children:[e.jsx(D,{value:v.author,onChange:o=>T(r=>r&&{...r,author:o.target.value}),placeholder:"Optional author"}),e.jsx(Le,{options:G,selectedValues:v.linkedValues,onChange:o=>T(r=>r&&{...r,linkedValues:o}),placeholder:"Update the linked entities",emptyMessage:"No matching entities found yet."})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-[minmax(0,1.15fr)_minmax(0,0.85fr)]",children:[e.jsx(re,{value:v.tags,onChange:o=>T(r=>r&&{...r,tags:o})}),e.jsxs("div",{className:"grid gap-3 rounded-[22px] bg-[var(--ui-surface-1)] p-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ephemeral auto-destroy"}),e.jsx("div",{className:"mt-2 text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Set an exact destroy time or a relative delay. Leaving both blank keeps the note durable."})]}),e.jsx(D,{type:"datetime-local",value:v.destroyAtInput,onChange:o=>T(r=>r&&{...r,destroyAtInput:o.target.value})}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-[minmax(0,1fr)_10rem]",children:[e.jsx(D,{type:"number",min:"1",value:v.destroyDelayValue,onChange:o=>T(r=>r&&{...r,destroyDelayValue:o.target.value}),placeholder:"Destroy after"}),e.jsxs("select",{className:"rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-3 text-sm text-[var(--ui-ink-strong)]",value:v.destroyDelayUnit,onChange:o=>T(r=>r&&{...r,destroyDelayUnit:o.target.value}),children:[e.jsx("option",{value:"hours",children:"Hours"}),e.jsx("option",{value:"days",children:"Days"})]})]})]})]}),e.jsxs("div",{className:"rounded-[22px] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Preview"}),e.jsx("div",{className:"mt-3",children:v.contentMarkdown.trim()?e.jsx(ne,{markdown:v.contentMarkdown}):e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:"No content yet."})})]}),e.jsxs("div",{className:"flex flex-wrap justify-end gap-2",children:[e.jsx(Q,{variant:"ghost",onClick:()=>{N(null),T(null)},children:"Cancel"}),e.jsx(Q,{pending:ye.isPending,pendingLabel:"Saving",disabled:v.contentMarkdown.trim().length===0||v.linkedValues.length===0,onClick:()=>void ye.mutateAsync({noteId:a.id,draft:v}),children:"Save changes"})]})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:"mt-4 w-full text-left",onClick:()=>{x&&i(x.includes("#")?x:`${x}#notes`)},disabled:!x,children:e.jsx(ne,{markdown:a.contentMarkdown,className:"line-clamp-none"})}),x?e.jsx("div",{className:"mt-4 inline-flex text-xs uppercase tracking-[0.16em] text-[var(--secondary)]",children:"Open linked record"}):null]})]},a.id)})})}),e.jsx(St,{open:!!$,title:"Note actions",subtitle:M?M.contentPlain.slice(0,80)||"Markdown note":void 0,items:Ve,position:($==null?void 0:$.position)??null,onClose:()=>le(null)})]})}export{Ht as NotesPage};
@@ -1 +0,0 @@
1
- import{j as t}from"./vendor-kIz9EZnX.js";import{Z as a}from"./index-BHIKoiZ6.js";function i({children:r,className:s}){return t.jsx("div",{className:a("flex flex-wrap gap-2",s),children:r})}export{i as P};
@@ -1 +0,0 @@
1
- import{b0 as gt,bD as vt,cF as ft,cG as bt,bf as jt,aG as yt,j as e,aK as Nt,b3 as de,c2 as wt,r as x,aC as ve,c7 as Ct,b4 as kt}from"./vendor-kIz9EZnX.js";import{j as It,i as Ke,k as N}from"./state-VYvD1QVP.js";import{bk as Z,Z as U,c as k,I as v,L as Je,a as et,B as m,C as j,U as tt,H as St,u as Pt,s as Ft,c1 as Ye,c2 as Lt,c3 as _t,c4 as Tt,c5 as Mt,c6 as Dt,c7 as At,c8 as Et,c9 as zt,ca as Gt,cb as Ot,cc as $t,cd as Bt,ce as qt,cf as Qt,cg as Rt,E as Ut,ch as Wt,T as A,ci as Xe}from"./index-BHIKoiZ6.js";import{P as Ht}from"./page-hero-oFHaAjtL.js";import{R as Kt,P as Yt,O as Xt,C as Zt,T as Vt,D as Jt,a as es}from"./ui-CsEkP2V8.js";import"./motion-CfdU2F35.js";import"./forms-CmLAyGqz.js";import"./board-DqHzdCPQ.js";import"./graph-BTa79qum.js";const st=[{id:"overview",label:"Overview",icon:gt},{id:"map",label:"Map",icon:vt},{id:"table",label:"Table",icon:ft},{id:"history",label:"History",icon:bt},{id:"contexts",label:"Contexts",icon:jt},{id:"concepts",label:"Concepts",icon:yt}],ts=new Set(["projects","tasks","strategies","habits"]),oe=[{value:"projects",label:"Projects",description:"Goals and projects already living in Forge.",mode:"forge"},{value:"tasks",label:"Tasks",description:"Execution-level work choices inside Forge.",mode:"forge"},{value:"strategies",label:"Strategies",description:"Plan shapes and sequencing choices in Forge.",mode:"forge"},{value:"habits",label:"Habits",description:"Recurring behaviors and routines from Forge.",mode:"forge"},{value:"activities",label:"Activities",description:"Movement, leisure, and social setting concepts.",mode:"concept"},{value:"food",label:"Food",description:"Cuisine, meal mood, and drink preferences.",mode:"concept"},{value:"places",label:"Places",description:"Living environments, venues, and trip shapes.",mode:"concept"},{value:"countries",label:"Countries",description:"Country-level attraction and lifestyle fit.",mode:"concept"},{value:"fashion",label:"Fashion",description:"Silhouette, material, and palette preferences.",mode:"concept"},{value:"people",label:"People",description:"Presence, body-type, and conversation preferences.",mode:"concept"},{value:"media",label:"Media",description:"Film, reading, and music taste.",mode:"concept"},{value:"tools",label:"Tools",description:"Workflow and capture preferences.",mode:"concept"},{value:"custom",label:"Custom",description:"General-purpose concept libraries you control.",mode:"concept"}],fe={novelty:"Novelty",simplicity:"Simplicity",rigor:"Rigor",aesthetics:"Aesthetics",depth:"Depth",structure:"Structure",familiarity:"Familiarity",surprise:"Surprise"},ne={novelty:0,simplicity:0,rigor:0,aesthetics:0,depth:0,structure:0,familiarity:0,surprise:0},Ze={liked:"bg-[var(--ui-success-soft)] text-[var(--success)]",disliked:"bg-[var(--ui-danger-soft)] text-[var(--danger)]",uncertain:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]",vetoed:"bg-[var(--ui-danger-soft)] text-[var(--danger)]",bookmarked:"bg-[var(--ui-info-soft)] text-[var(--info)]",favorite:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",must_have:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",neutral:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-soft)]"},ss=[{signalType:"favorite",label:"Favorite"},{signalType:"must_have",label:"Must-have"},{signalType:"bookmark",label:"Bookmark"},{signalType:"compare_later",label:"Later"},{signalType:"neutral",label:"Neutral"},{signalType:"veto",label:"Veto"}];function le(i){return i.trim().toLowerCase()}function R(i){return`${Math.round(i*100)}%`}function as(i){return[...i.goals.map(a=>({entityType:"goal",entityId:a.id,domain:"projects",label:a.title,description:a.description,user:a.user,href:`/goals/${a.id}`,searchText:Z([a.title,a.description,a.status,a.horizon],a)})),...i.dashboard.projects.map(a=>({entityType:"project",entityId:a.id,domain:"projects",label:a.title,description:a.description,user:a.user,href:`/projects/${a.id}`,searchText:Z([a.title,a.description,a.status,a.goalTitle],a)})),...i.tasks.map(a=>({entityType:"task",entityId:a.id,domain:"tasks",label:a.title,description:a.description,user:a.user,href:`/tasks/${a.id}`,searchText:Z([a.title,a.description,a.status,a.priority,a.owner],a)})),...i.strategies.map(a=>({entityType:"strategy",entityId:a.id,domain:"strategies",label:a.title,description:a.overview||a.endStateDescription,user:a.user,href:`/strategies/${a.id}`,searchText:Z([a.title,a.overview,a.endStateDescription,a.status],a)})),...i.habits.map(a=>({entityType:"habit",entityId:a.id,domain:"habits",label:a.title,description:a.description,user:a.user,href:null,searchText:Z([a.title,a.description,a.status,a.frequency],a)}))]}function is(i,a){return!i||!a?null:i==="goal"?`/goals/${a}`:i==="project"?`/projects/${a}`:i==="task"?`/tasks/${a}`:i==="strategy"?`/strategies/${a}`:null}function ce(i){return i.manualStatus??i.status}function rs(i){return i&&st.some(a=>a.id===i)?i:"overview"}function ns(i){return i.summary.totalItems<2?{title:"Forge does not know enough yet.",description:"Start the game so Forge can ask a few clean comparisons and build a real preference model."}:i.summary.averageConfidence<.28?{title:"Forge has a rough sketch, not a stable read.",description:"There is some signal, but the model still needs more rounds before its preferences are trustworthy."}:{title:"This is what Forge currently thinks.",description:"The summary below is the current best model for this user, this domain, and the active context."}}function ls({summary:i}){const a=Math.max(-1,Math.min(1,i.leaning)),o=(a+1)/2*100;return e.jsxs("div",{className:"grid gap-1",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-soft)]",children:[e.jsx("span",{children:fe[i.dimensionId]}),e.jsxs("span",{children:[i.movement>.08?"Rising":i.movement<-.08?"Falling":"Stable"," ","· ",R(i.confidence)]})]}),e.jsxs("div",{className:"relative h-2 rounded-full bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"absolute inset-y-0 left-1/2 w-px bg-[var(--ui-border-strong)]"}),e.jsx("div",{className:U("absolute top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border border-[var(--ui-border-strong)]",a>=0?"bg-[var(--success)]":"bg-[var(--danger)]"),style:{left:`${o}%`}})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-[11px] uppercase tracking-[0.12em] text-[var(--ui-ink-faint)]",children:[e.jsxs("span",{children:[a>=0?"Leans toward":"Leans away from"," ",fe[i.dimensionId].toLowerCase()]}),e.jsxs("span",{children:["Context ",R(i.contextSensitivity)]})]})]})}function Ve({title:i,description:a,sideLabel:o,onClick:h}){return e.jsxs("button",{type:"button",className:"grid min-h-[220px] gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5 text-left transition hover:border-[color-mix(in_srgb,var(--primary)_40%,transparent)] hover:bg-[var(--ui-surface-hover)]",onClick:h,children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:o}),e.jsx("div",{className:"font-display text-3xl text-[var(--ui-ink-strong)]",children:i}),e.jsx("div",{className:"max-w-[36ch] text-sm leading-6 text-[var(--ui-ink-soft)]",children:a||"Choose the one that feels more right."}),e.jsx("div",{className:"mt-auto text-sm text-[var(--primary)]",children:"Click this card"})]})}function cs({state:i,onOpenChange:a,error:o,loading:h,workspaceLoading:w,activeWorkspace:g,conceptSearchQuery:S,onConceptSearchQueryChange:p,filteredCatalogs:I,onSelectDomain:V,onStartCatalogGame:G,onJudge:J,onSignal:O}){return e.jsx(Kt,{open:i.open,onOpenChange:a,children:e.jsxs(Yt,{children:[e.jsx(Xt,{className:"fixed inset-0 z-40 bg-[var(--ui-overlay-backdrop)] backdrop-blur-xl"}),e.jsxs(Zt,{className:"fixed inset-x-4 bottom-4 top-4 z-50 overflow-y-auto rounded-[32px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-floating)] md:inset-x-10 lg:left-1/2 lg:right-auto lg:w-[min(72rem,calc(100vw-3rem))] lg:-translate-x-1/2",children:[e.jsx(Vt,{className:"sr-only",children:"Preference game"}),e.jsx(Jt,{className:"sr-only",children:"Start comparison rounds from a Forge domain or concept list."}),e.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-between gap-4 border-b border-[var(--ui-border-subtle)] bg-[color-mix(in_srgb,var(--surface-glass)_94%,transparent)] px-5 py-4 backdrop-blur-xl",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Preference game"}),e.jsx("div",{className:"mt-1 font-display text-2xl text-[var(--ui-ink-strong)]",children:i.phase==="domain"?"Choose a domain":i.phase==="catalog"?"Choose a concept list":"Pick the better fit"})]}),e.jsx(es,{asChild:!0,children:e.jsx("button",{type:"button","aria-label":"Close preference game",className:"rounded-full bg-[var(--ui-surface-2)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:e.jsx(Nt,{className:"size-4"})})})]}),e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[o?e.jsx("div",{className:"rounded-[18px] border border-[color-mix(in_srgb,var(--danger)_28%,transparent)] bg-[var(--ui-danger-soft)] px-4 py-3 text-sm text-[var(--danger)]",children:o}):null,i.phase==="domain"?e.jsx(ds,{onSelectDomain:V}):null,i.phase==="catalog"?e.jsx(os,{domain:i.domain,query:S,onQueryChange:p,catalogs:I,onStartCatalogGame:G}):null,i.phase==="play"?e.jsx(ms,{domain:i.domain,loading:h||w,activeWorkspace:g,onJudge:J,onSignal:O}):null]})]})]})})}function ds({onSelectDomain:i}){return e.jsx("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-3",children:oe.map(a=>e.jsxs("button",{type:"button",className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-5 py-5 text-left transition hover:border-[color-mix(in_srgb,var(--primary)_30%,transparent)] hover:bg-[var(--ui-accent-soft)]",onClick:()=>i(a.value),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:a.label}),e.jsx(k,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:a.mode==="forge"?"Forge":"Concept"})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a.description})]},a.value))})}function os({domain:i,query:a,onQueryChange:o,catalogs:h,onStartCatalogGame:w}){return e.jsxs("div",{className:"grid gap-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Pick the concept list Forge should draw from. You do not need to assemble the items yourself."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{className:"size-4 text-[var(--ui-ink-faint)]"}),e.jsx(v,{value:a,onChange:g=>o(g.target.value),placeholder:"Search concept lists"})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2",children:h.length>0?h.map(g=>e.jsxs("button",{type:"button",className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-5 py-5 text-left transition hover:border-[color-mix(in_srgb,var(--primary)_30%,transparent)] hover:bg-[var(--ui-accent-soft)]",onClick:()=>w(i,g.id),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:g.title}),e.jsxs(k,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[g.items.length," items"]})]}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:g.description||"No description yet."})]},g.id)):e.jsx("div",{className:"rounded-[24px] bg-[var(--ui-surface-1)] px-5 py-6 text-sm text-[var(--ui-ink-soft)]",children:"No concept list matches that search yet."})})]})}function ms({domain:i,loading:a,activeWorkspace:o,onJudge:h,onSignal:w}){var S;const g=(o==null?void 0:o.compare.nextPair)??null;return a?e.jsx(Je,{eyebrow:"Preference game",title:"Preparing the next round",description:"Forge is lining up comparison candidates."}):g?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx(k,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:((S=oe.find(p=>p.value===i))==null?void 0:S.label)??i}),e.jsx("span",{children:o==null?void 0:o.selectedContext.name}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[(o==null?void 0:o.compare.pendingCount)??0," queued comparisons"]})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-2",children:[e.jsx(Ve,{title:g.left.label,description:g.left.description,sideLabel:"Left",onClick:()=>h("left",1)}),e.jsx(Ve,{title:g.right.label,description:g.right.description,sideLabel:"Right",onClick:()=>h("right",1)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{onClick:()=>h("left",1),children:"Left"}),e.jsx(m,{onClick:()=>h("right",1),children:"Right"}),e.jsx(m,{variant:"secondary",onClick:()=>h("left",1.75),children:"Strong left"}),e.jsx(m,{variant:"secondary",onClick:()=>h("right",1.75),children:"Strong right"}),e.jsx(m,{variant:"secondary",onClick:()=>h("tie",1),children:"Tie"}),e.jsx(m,{variant:"secondary",onClick:()=>h("skip",1),children:"Skip"})]}),e.jsx("div",{className:"grid gap-4 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4 lg:grid-cols-2",children:[g.left,g.right].map(p=>e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"font-medium text-[var(--ui-ink-strong)]",children:p.label}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Quick signals"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:ss.map(I=>e.jsx(m,{variant:"secondary",size:"sm",onClick:()=>w(p.id,I.signalType),children:I.label},`${p.id}-${I.signalType}`))})]},p.id))})]}):e.jsx(et,{eyebrow:"Preference game",title:"No pair is ready yet",description:"Forge needs more items in this domain before it can keep asking comparisons."})}function us({users:i,user:a,selectedUserId:o,selectedDomain:h,workspace:w,onPatchSearch:g}){var S;return e.jsxs(j,{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Active user"}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx("select",{value:o,onChange:p=>g({userId:p.target.value,contextId:null,focusItem:null}),className:"min-h-10 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-sm text-[var(--ui-ink-strong)] outline-none transition focus:border-[var(--primary)]",children:i.map(p=>e.jsxs("option",{value:p.id,children:[p.displayName," · ",p.kind]},p.id))}),e.jsx(tt,{user:a}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:St(a)})]})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Domain"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:oe.map(p=>e.jsx("button",{type:"button",className:U("rounded-full border px-3 py-2 text-sm transition",p.value===h?"border-[var(--primary)] 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)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>g({domain:p.value,contextId:null,focusItem:null}),children:p.label},p.value))}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:(S=oe.find(p=>p.value===h))==null?void 0:S.description})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx(k,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:w.selectedContext.name}),e.jsx("span",{children:w.selectedContext.shareMode}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[w.compare.pendingCount," queued comparisons"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[w.libraries.totalCatalogItems," concept items ready"]})]})]})}function xs({selectedTab:i,onSelectTab:a}){return e.jsx("div",{className:"flex flex-wrap gap-2",children:st.map(o=>e.jsxs("button",{type:"button",className:U("inline-flex items-center gap-2 rounded-full border px-3 py-2 text-sm transition",o.id===i?"border-[var(--primary)] 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)] hover:text-[var(--ui-ink-strong)]"),onClick:()=>a(o.id),children:[e.jsx(o.icon,{className:"size-4"}),o.label]},o.id))})}function ws(){var qe,Qe,Re;const i=Pt(),a=It(),[o,h]=wt(),[w,g]=x.useState(""),[S,p]=x.useState(""),[I,V]=x.useState(""),[G,J]=x.useState(""),[O,be]=x.useState(""),[E,T]=x.useState({open:!1,phase:"domain",domain:o.get("domain")??"projects"}),[at,M]=x.useState(null),[it,me]=x.useState(!1),[je,$]=x.useState(null),[f,F]=x.useState({label:"",description:"",tags:"",manualStatus:"",manualScore:"",confidenceLock:"",bookmarked:!1,compareLater:!1,frozen:!1,featureWeights:{novelty:"0",simplicity:"0",rigor:"0",aesthetics:"0",depth:"0",structure:"0",familiarity:"0",surprise:"0"}}),[z,ee]=x.useState({label:"",description:"",tags:""}),[L,W]=x.useState({name:"",description:"",shareMode:"blended",decayDays:"90"}),[H,ue]=x.useState({title:"",description:""}),[rt,te]=x.useState({}),[ye,xe]=x.useState(null),[se,pe]=x.useState({title:"",description:""}),[nt,he]=x.useState(null),[B,ae]=x.useState({label:"",description:"",tags:""}),u=o.get("userId")??Ft(i.selectedUserIds)??((qe=i.snapshot.users[0])==null?void 0:qe.id)??null,C=o.get("domain")??"projects",_=rs(o.get("tab")),K=o.get("contextId"),ie=o.get("focusItem"),lt=x.useMemo(()=>i.snapshot.users.find(t=>t.id===u)??null,[u,i.snapshot.users]),re=x.useMemo(()=>as(i.snapshot),[i.snapshot]),Y=Ke({queryKey:["forge-preferences",u,C,K],queryFn:async()=>(await Xe({userId:u??void 0,domain:C,contextId:K??void 0})).workspace,enabled:!!u}),Ne=Ke({queryKey:["forge-preferences-game",u,E.domain,K],queryFn:async()=>(await Xe({userId:u??void 0,domain:E.domain,contextId:K??void 0})).workspace,enabled:!!u&&E.open}),r=Y.data??null,P=E.domain===C?r:Ne.data??null;x.useEffect(()=>{var s;if(!r)return;const t=ie&&r.scores.some(c=>c.itemId===ie)?ie:((s=r.scores[0])==null?void 0:s.itemId)??null;$(c=>c&&r.scores.some(n=>n.itemId===c)?c:t)},[ie,r]);const ge=x.useMemo(()=>{if(!r)return[];const t=le(w);return t?r.scores.filter(s=>{var c,n,l;return[((c=s.item)==null?void 0:c.label)??"",((n=s.item)==null?void 0:n.description)??"",((l=s.item)==null?void 0:l.tags.join(" "))??"",s.status,s.manualStatus??"",s.dominantDimensions.join(" "),s.explanation.join(" ")].join(" ").toLowerCase().includes(t)}):r.scores},[w,r]),d=ge.find(t=>t.itemId===je)??(r==null?void 0:r.scores.find(t=>t.itemId===je))??ge[0]??(r==null?void 0:r.scores[0])??null;x.useEffect(()=>{var t,s,c,n,l,y,X,Q,Ue,We,He;d&&F({label:((t=d.item)==null?void 0:t.label)??"",description:((s=d.item)==null?void 0:s.description)??"",tags:((c=d.item)==null?void 0:c.tags.join(", "))??"",manualStatus:d.manualStatus??"",manualScore:typeof d.manualScore=="number"?String(d.manualScore):"",confidenceLock:typeof d.confidenceLock=="number"?String(d.confidenceLock):"",bookmarked:d.bookmarked,compareLater:d.compareLater,frozen:d.frozen,featureWeights:{novelty:String(((n=d.item)==null?void 0:n.featureWeights.novelty)??0),simplicity:String(((l=d.item)==null?void 0:l.featureWeights.simplicity)??0),rigor:String(((y=d.item)==null?void 0:y.featureWeights.rigor)??0),aesthetics:String(((X=d.item)==null?void 0:X.featureWeights.aesthetics)??0),depth:String(((Q=d.item)==null?void 0:Q.featureWeights.depth)??0),structure:String(((Ue=d.item)==null?void 0:Ue.featureWeights.structure)??0),familiarity:String(((We=d.item)==null?void 0:We.featureWeights.familiarity)??0),surprise:String(((He=d.item)==null?void 0:He.featureWeights.surprise)??0)}})},[d]);const we=x.useMemo(()=>{const t=le(S);return re.filter(s=>s.domain===C).filter(s=>t?s.searchText.includes(t):!0).slice(0,12)},[re,S,C]),Ce=x.useMemo(()=>{const t=_==="concepts"?r:P??r,s=(t==null?void 0:t.catalogs)??[],c=le(I);return c?s.filter(n=>[n.title,n.description,n.source,...n.items.flatMap(l=>[l.label,l.description,l.tags.join(" ")])].join(" ").toLowerCase().includes(c)):s},[P,I,_,r]),b=async()=>{await a.invalidateQueries({queryKey:["forge-preferences"]}),await a.invalidateQueries({queryKey:["forge-preferences-game"]})},ke=N({mutationFn:Ye,onSuccess:b}),Ie=N({mutationFn:Lt,onSuccess:async({item:t})=>{await b(),ee({label:"",description:"",tags:""}),$(t.id)}}),Se=N({mutationFn:_t,onSuccess:async()=>{await b(),ue({title:"",description:""}),h(t=>{const s=new URLSearchParams(t);return s.set("tab","concepts"),s})}}),Pe=N({mutationFn:({catalogId:t,patch:s})=>Tt(t,s),onSuccess:async()=>{await b(),xe(null)}}),Fe=N({mutationFn:Mt,onSuccess:b}),Le=N({mutationFn:Dt,onSuccess:async()=>{await b()}}),_e=N({mutationFn:({catalogItemId:t,patch:s})=>At(t,s),onSuccess:async()=>{await b(),he(null)}}),Te=N({mutationFn:Et,onSuccess:b}),ct=N({mutationFn:zt,onSuccess:async()=>{await b(),T(t=>({...t,phase:"play"}))}}),dt=N({mutationFn:Gt,onSuccess:b}),ot=N({mutationFn:Ot,onSuccess:b}),Me=N({mutationFn:async()=>{!(d!=null&&d.item)||!u||!r||(await $t(d.item.id,{label:f.label,description:f.description,tags:f.tags.split(",").map(t=>t.trim()).filter(Boolean),featureWeights:Object.fromEntries(Object.keys(ne).map(t=>[t,Number(f.featureWeights[t]||0)]))}),await Bt(d.item.id,{userId:u,domain:C,contextId:r.selectedContext.id,manualStatus:f.manualStatus||null,manualScore:f.manualScore.trim().length>0?Number(f.manualScore):null,confidenceLock:f.confidenceLock.trim().length>0?Number(f.confidenceLock):null,bookmarked:f.bookmarked,compareLater:f.compareLater,frozen:f.frozen}))},onSuccess:b}),De=N({mutationFn:qt,onSuccess:async({context:t})=>{await b(),W({name:"",description:"",shareMode:"blended",decayDays:"90"}),h(s=>{const c=new URLSearchParams(s);return c.set("contextId",t.id),c.set("tab","contexts"),c})}}),Ae=N({mutationFn:Qt,onSuccess:async()=>{await b(),J(""),be("")}}),q=N({mutationFn:({contextId:t,patch:s})=>Rt(t,s),onSuccess:b}),D=t=>{h(s=>{const c=new URLSearchParams(s);for(const[n,l]of Object.entries(t))l?c.set(n,l):c.delete(n);return c})},Ee=(t=C)=>{M(null),T({open:!0,phase:"domain",domain:t})},mt=async t=>{if(!u)return;M(null),me(!0);const s=re.filter(l=>{var y;return l.domain===t&&((y=l.user)==null?void 0:y.id)===u}),c=re.filter(l=>l.domain===t),n=(s.length>0?s:c).slice(0,12);if(n.length<2){M("Forge needs at least two matching records in this domain before it can start the game."),me(!1),T(l=>({...l,phase:"domain"}));return}try{D({domain:t,tab:"overview",contextId:null,focusItem:null}),await Promise.all(n.map(l=>Ye({userId:u,domain:t,entityType:l.entityType,entityId:l.entityId,label:l.label,description:l.description,tags:[]}))),await b(),T({open:!0,phase:"play",domain:t})}catch(l){M(l instanceof Error?l.message:"Forge could not start the game."),T(y=>({...y,phase:"domain"}))}finally{me(!1)}},ze=async(t,s)=>{if(u){M(null),D({domain:t,tab:"overview",contextId:null,focusItem:null});try{await ct.mutateAsync({userId:u,domain:t,contextId:K??void 0,catalogId:s}),T({open:!0,phase:"play",domain:t})}catch(c){M(c instanceof Error?c.message:"Forge could not start the game.")}}},ut=async t=>{if(ts.has(t)){await mt(t);return}M(null),T({open:!0,phase:"catalog",domain:t})},xt=async(t,s=1)=>{if(!u||!(P!=null&&P.compare.nextPair))return;const c=P.compare.nextPair;await dt.mutateAsync({userId:u,domain:E.domain,contextId:P.selectedContext.id,leftItemId:c.left.id,rightItemId:c.right.id,outcome:t,strength:s})},pt=async(t,s)=>{!u||!P||await ot.mutateAsync({userId:u,domain:E.domain,contextId:P.selectedContext.id,itemId:t,signalType:s,strength:1})};if(!u)return e.jsx(et,{eyebrow:"Preferences",title:"No Forge user available",description:"Forge needs at least one human or bot user before it can learn preferences."});if(Y.isLoading&&!r)return e.jsx(Je,{eyebrow:"Preferences",title:"Loading preference model",description:"Reconstructing current scores, uncertainty, and concept libraries."});if(Y.isError)return e.jsx(Ut,{eyebrow:"Preferences",error:Y.error,onRetry:()=>void Y.refetch()});if(!r)return null;const ht=[...r.dimensions].sort((t,s)=>s.confidence-t.confidence).slice(0,6),Ge=r.scores.filter(t=>ce(t)==="liked"||ce(t)==="favorite").slice(0,4),Oe=r.scores.filter(t=>t.uncertainty>=.5).slice(0,4),$e=ns(r),Be=is(((Qe=d==null?void 0:d.item)==null?void 0:Qe.sourceEntityType)??null,((Re=d==null?void 0:d.item)==null?void 0:Re.sourceEntityId)??null);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsx(Ht,{title:"Preferences",titleText:"Preferences",description:"Forge keeps an explicit, editable model of what one user prefers in one domain. The first job of this page is to show what Forge currently knows.",badge:`${r.summary.totalItems} items · ${R(r.summary.averageConfidence)} confidence`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{className:"min-w-[10rem]",onClick:()=>Ee(),children:"Start the game"}),e.jsx(m,{variant:"secondary",onClick:()=>void b(),children:"Refresh model"})]})}),e.jsx(Wt,{}),e.jsx(us,{users:i.snapshot.users,user:lt,selectedUserId:u,selectedDomain:C,workspace:r,onPatchSearch:D}),e.jsx(xs,{selectedTab:_,onSelectTab:t=>D({tab:t})}),_==="overview"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_360px]",children:[e.jsxs(j,{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"What Forge knows"}),e.jsx("div",{className:"font-display text-3xl text-white",children:$e.title}),e.jsx("div",{className:"max-w-[70ch] text-sm leading-6 text-white/58",children:$e.description})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:[{label:"Known items",value:r.summary.totalItems,detail:"Items inside this domain"},{label:"Confidence",value:R(r.summary.averageConfidence),detail:"Average certainty"},{label:"Unknowns",value:r.summary.uncertainCount,detail:"Need more rounds"},{label:"Libraries",value:r.libraries.totalCatalogItems,detail:"Seeded concepts ready"}].map(t=>e.jsxs("div",{className:"rounded-[22px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:t.label}),e.jsx("div",{className:"mt-2 font-display text-3xl text-white",children:t.value}),e.jsx("div",{className:"mt-1 text-sm text-white/52",children:t.detail})]},t.label))}),e.jsx("div",{className:"grid gap-4 lg:grid-cols-2",children:ht.map(t=>e.jsx(ls,{summary:t},t.dimensionId))})]}),e.jsxs(j,{className:"grid gap-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Next move"}),e.jsx("div",{className:"font-display text-2xl text-white",children:"Start the game"}),e.jsx("div",{className:"text-sm leading-6 text-white/58",children:"Forge will ask a small number of pairwise questions. You choose a domain, Forge supplies the candidates, and the model tightens from there."}),e.jsx(m,{className:"w-full",onClick:()=>Ee(),children:"Start the game"}),e.jsxs("div",{className:"grid gap-3 rounded-[22px] bg-white/[0.04] px-4 py-4 text-sm text-white/58",children:[e.jsxs("div",{children:["Current queue: ",r.compare.pendingCount," comparison",r.compare.pendingCount===1?"":"s"]}),e.jsxs("div",{children:["Active context: ",r.selectedContext.name]}),e.jsxs("div",{children:["Library coverage: ",r.libraries.seededCatalogCount," ","seeded lists and ",r.libraries.customCatalogCount," ","custom lists"]})]})]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.3fr)_360px]",children:[e.jsxs(j,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Preference map"}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:"Green drifts positive, red drifts negative, and low opacity still means uncertainty."})]}),e.jsx(ve,{to:"?tab=map",className:"text-sm text-[var(--primary)]",children:"Open full map"})]}),e.jsxs("div",{className:"relative min-h-[340px] overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[radial-gradient(circle_at_top,color-mix(in_srgb,var(--success)_18%,transparent),transparent_35%),radial-gradient(circle_at_bottom_right,color-mix(in_srgb,var(--danger)_14%,transparent),transparent_30%),var(--ui-surface-section)]",children:[e.jsx("div",{className:"absolute inset-x-0 top-1/2 h-px bg-[var(--ui-border-subtle)]"}),e.jsx("div",{className:"absolute inset-y-0 left-1/2 w-px bg-[var(--ui-border-subtle)]"}),r.map.map(t=>e.jsx("button",{type:"button",className:U("absolute -translate-x-1/2 -translate-y-1/2 rounded-full border px-2 py-1 text-[11px] shadow-[var(--ui-shadow-soft)] transition hover:scale-[1.04]",t.itemId===(d==null?void 0:d.itemId)?"border-[var(--ui-border-strong)] bg-[var(--ui-surface-active)] text-[var(--ui-ink-strong)]":t.score>=0?"border-[color-mix(in_srgb,var(--success)_34%,transparent)] bg-[var(--ui-success-soft)] text-[var(--success)]":"border-[color-mix(in_srgb,var(--danger)_34%,transparent)] bg-[var(--ui-danger-soft)] text-[var(--danger)]"),style:{left:`${50+t.x*30}%`,top:`${50-t.y*30}%`,opacity:.55+t.confidence*.45},onClick:()=>$(t.itemId),children:t.label},t.itemId))]})]}),e.jsxs(j,{className:"grid gap-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Best read so far"}),e.jsx("div",{className:"grid gap-2",children:Ge.length>0?Ge.map(t=>{var s;return e.jsxs("button",{type:"button",className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-left transition hover:bg-white/[0.07]",onClick:()=>{$(t.itemId),D({focusItem:t.itemId})},children:[e.jsx("div",{className:"font-medium text-white",children:((s=t.item)==null?void 0:s.label)??t.itemId}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:t.explanation[0]||"Forge has positive evidence here."})]},t.itemId)}):e.jsx("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-sm text-white/58",children:"No clear positives yet. A few comparison rounds will change that."})}),e.jsxs("div",{className:"border-t border-white/8 pt-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Biggest unknowns"}),e.jsx("div",{className:"mt-3 grid gap-2",children:Oe.length>0?Oe.map(t=>{var s;return e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-sm text-white/58",children:[e.jsx("div",{className:"font-medium text-white",children:((s=t.item)==null?void 0:s.label)??t.itemId}),e.jsxs("div",{className:"mt-1",children:["Uncertainty ",R(t.uncertainty)]})]},t.itemId)}):e.jsx("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-sm text-white/58",children:"The current unknown list is short."})})]})]})]}),e.jsxs(j,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Bring in Forge records"}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:"Search goals, projects, tasks, strategies, or habits across human and bot users, then send them straight into this model."})]}),e.jsxs(k,{className:"bg-white/[0.08] text-white/70",children:[we.length," visible"]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{className:"size-4 text-white/38"}),e.jsx(v,{value:S,onChange:t=>p(t.target.value),placeholder:"Search across owners, handles, user kind, title, and description"})]}),e.jsx("div",{className:"grid gap-2",children:we.map(t=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 rounded-[18px] bg-white/[0.04] px-4 py-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"font-medium text-white",children:t.label}),e.jsx(k,{className:"bg-white/[0.08] text-white/70",children:t.entityType}),t.user?e.jsx(tt,{user:t.user,compact:!0}):null]}),e.jsx("div",{className:"mt-1 text-sm text-white/52",children:t.description||"No description yet."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.href?e.jsx(ve,{to:t.href,children:e.jsx(m,{variant:"ghost",size:"sm",children:"Open"})}):null,e.jsx(m,{variant:"secondary",size:"sm",pending:ke.isPending,pendingLabel:"Adding",onClick:()=>void ke.mutateAsync({userId:u,domain:C,entityType:t.entityType,entityId:t.entityId,label:t.label,description:t.description,tags:[]}),children:"Add to model"})]})]},`${t.entityType}-${t.entityId}`))})]})]}):null,_==="map"?e.jsxs(j,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Full map"}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:"Click a point to inspect why Forge believes it belongs there."})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:[r.map.length," plotted items"]})]}),e.jsxs("div",{className:"relative min-h-[520px] overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[radial-gradient(circle_at_20%_20%,color-mix(in_srgb,var(--success)_20%,transparent),transparent_25%),radial-gradient(circle_at_80%_80%,color-mix(in_srgb,var(--danger)_20%,transparent),transparent_26%),var(--ui-surface-section)]",children:[e.jsx("div",{className:"absolute inset-x-0 top-1/2 h-px bg-[var(--ui-border-subtle)]"}),e.jsx("div",{className:"absolute inset-y-0 left-1/2 w-px bg-[var(--ui-border-subtle)]"}),r.map.map(t=>e.jsx("button",{type:"button",className:U("absolute -translate-x-1/2 -translate-y-1/2 rounded-full border px-3 py-1 text-xs transition hover:scale-[1.04]",t.itemId===(d==null?void 0:d.itemId)?"border-[var(--ui-border-strong)] bg-[var(--ui-surface-active)] text-[var(--ui-ink-strong)]":t.score>=0?"border-[color-mix(in_srgb,var(--success)_34%,transparent)] bg-[var(--ui-success-soft)] text-[var(--success)]":"border-[color-mix(in_srgb,var(--danger)_34%,transparent)] bg-[var(--ui-danger-soft)] text-[var(--danger)]"),style:{left:`${50+t.x*34}%`,top:`${50-t.y*34}%`,opacity:.45+t.confidence*.55},onClick:()=>{$(t.itemId),D({focusItem:t.itemId})},children:t.label},t.itemId))]})]}):null,_==="table"?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.2fr)_380px]",children:[e.jsxs(j,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{className:"size-4 text-white/38"}),e.jsx(v,{value:w,onChange:t=>g(t.target.value),placeholder:"Search learned items, explanations, tags, or dominant dimensions"})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-left text-sm",children:[e.jsx("thead",{className:"text-[11px] uppercase tracking-[0.14em] text-white/38",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2",children:"Item"}),e.jsx("th",{className:"px-3 py-2",children:"Score"}),e.jsx("th",{className:"px-3 py-2",children:"Confidence"}),e.jsx("th",{className:"px-3 py-2",children:"Status"}),e.jsx("th",{className:"px-3 py-2",children:"Evidence"})]})}),e.jsx("tbody",{children:ge.map(t=>{var s,c;return e.jsxs("tr",{className:U("cursor-pointer border-t border-white/6 transition hover:bg-white/[0.04]",t.itemId===(d==null?void 0:d.itemId)?"bg-white/[0.05]":""),onClick:()=>{$(t.itemId),D({focusItem:t.itemId})},children:[e.jsxs("td",{className:"px-3 py-3",children:[e.jsx("div",{className:"font-medium text-white",children:((s=t.item)==null?void 0:s.label)??t.itemId}),e.jsx("div",{className:"text-xs text-white/48",children:(((c=t.item)==null?void 0:c.tags)??[]).join(" · ")})]}),e.jsx("td",{className:"px-3 py-3 text-white/68",children:t.latentScore.toFixed(2)}),e.jsx("td",{className:"px-3 py-3 text-white/68",children:R(t.confidence)}),e.jsx("td",{className:"px-3 py-3",children:e.jsx(k,{className:Ze[ce(t)],children:ce(t)})}),e.jsx("td",{className:"px-3 py-3 text-white/68",children:t.evidenceCount})]},t.itemId)})})]})})]}),e.jsxs(j,{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Item editor"}),d!=null&&d.item?e.jsxs(e.Fragment,{children:[e.jsx(v,{value:f.label,onChange:t=>F(s=>({...s,label:t.target.value})),placeholder:"Item label"}),e.jsx(A,{value:f.description,onChange:t=>F(s=>({...s,description:t.target.value})),className:"min-h-24",placeholder:"Item description"}),e.jsx(v,{value:f.tags,onChange:t=>F(s=>({...s,tags:t.target.value})),placeholder:"comma, separated, tags"}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("select",{value:f.manualStatus,onChange:t=>F(s=>({...s,manualStatus:t.target.value})),className:"min-h-10 rounded-[18px] border border-white/8 bg-white/[0.05] px-3 text-sm text-white outline-none",children:[e.jsx("option",{value:"",children:"Inferred status"}),Object.keys(Ze).map(t=>e.jsx("option",{value:t,children:t},t))]}),e.jsx(v,{value:f.manualScore,onChange:t=>F(s=>({...s,manualScore:t.target.value})),placeholder:"Manual score"}),e.jsx(v,{value:f.confidenceLock,onChange:t=>F(s=>({...s,confidenceLock:t.target.value})),placeholder:"Confidence lock 0-1"})]}),e.jsx("div",{className:"grid gap-2",children:Object.keys(ne).map(t=>e.jsxs("div",{className:"grid grid-cols-[110px_minmax(0,1fr)] items-center gap-3",children:[e.jsx("div",{className:"text-sm text-white/56",children:fe[t]}),e.jsx(v,{value:f.featureWeights[t],onChange:s=>F(c=>({...c,featureWeights:{...c.featureWeights,[t]:s.target.value}}))})]},t))}),e.jsx("div",{className:"grid gap-2 text-sm text-white/58",children:[["bookmarked","Bookmarked"],["compareLater","Compare later"],["frozen","Frozen"]].map(([t,s])=>e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:f[t],onChange:c=>F(n=>({...n,[t]:c.target.checked}))}),e.jsx("span",{children:s})]},t))}),e.jsx(m,{pending:Me.isPending,pendingLabel:"Saving item",onClick:()=>void Me.mutateAsync(),children:"Save item model"}),Be?e.jsx(ve,{className:"text-sm text-[var(--primary)]",to:Be,children:"Open linked entity"}):null]}):e.jsx("div",{className:"text-sm text-white/52",children:"Select a row to inspect or edit it."}),e.jsxs("div",{className:"mt-3 border-t border-white/8 pt-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Add custom item"}),e.jsxs("div",{className:"mt-3 grid gap-3",children:[e.jsx(v,{value:z.label,onChange:t=>ee(s=>({...s,label:t.target.value})),placeholder:"Custom item label"}),e.jsx(A,{value:z.description,onChange:t=>ee(s=>({...s,description:t.target.value})),className:"min-h-24",placeholder:"What is this preference item?"}),e.jsx(v,{value:z.tags,onChange:t=>ee(s=>({...s,tags:t.target.value})),placeholder:"comma, separated, tags"}),e.jsx(m,{disabled:!z.label.trim(),pending:Ie.isPending,pendingLabel:"Creating item",onClick:()=>void Ie.mutateAsync({userId:u,domain:C,label:z.label,description:z.description,tags:z.tags.split(",").map(t=>t.trim()).filter(Boolean),featureWeights:ne,queueForCompare:!0}),children:"Create custom item"})]})]})]})]}):null,_==="history"?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-3",children:[e.jsxs(j,{className:"grid gap-3 xl:col-span-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Recent pairwise judgments"}),e.jsx("div",{className:"grid gap-2",children:r.history.judgments.slice(0,12).map(t=>{var n,l,y,X;const s=((l=(n=r.scores.find(Q=>Q.itemId===t.leftItemId))==null?void 0:n.item)==null?void 0:l.label)??t.leftItemId,c=((X=(y=r.scores.find(Q=>Q.itemId===t.rightItemId))==null?void 0:y.item)==null?void 0:X.label)??t.rightItemId;return e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-3 text-sm text-white/58",children:[e.jsxs("div",{className:"font-medium text-white",children:[s," vs ",c]}),e.jsxs("div",{className:"mt-1",children:["Outcome ",t.outcome," · strength"," ",t.strength," ·"," ",new Date(t.createdAt).toLocaleString()]})]},t.id)})})]}),e.jsxs(j,{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Signals and snapshots"}),e.jsx("div",{className:"grid gap-2",children:r.history.signals.slice(0,8).map(t=>{var c,n;const s=((n=(c=r.scores.find(l=>l.itemId===t.itemId))==null?void 0:c.item)==null?void 0:n.label)??t.itemId;return e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-2 text-sm text-white/58",children:[s," · ",t.signalType," ·"," ",new Date(t.createdAt).toLocaleString()]},t.id)})}),e.jsx("div",{className:"grid gap-2",children:r.history.snapshots.slice(0,5).map(t=>e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-2 text-sm text-white/58",children:["Snapshot ",new Date(t.createdAt).toLocaleString()]},t.id))}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-3 py-3 text-sm text-white/58",children:["Stale items: ",r.history.staleItemIds.length," · Flipped items: ",r.history.flippedItemIds.length]})]})]}):null,_==="contexts"?e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.1fr)_360px]",children:[e.jsx("div",{className:"grid gap-4",children:r.contexts.map(t=>e.jsxs(j,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-display text-2xl text-white",children:t.name}),e.jsx("div",{className:"text-sm text-white/54",children:t.description||"No description yet."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[t.isDefault?e.jsx(k,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:"Default"}):null,e.jsx(k,{className:"bg-white/[0.08] text-white/70",children:t.shareMode}),t.active?null:e.jsx(k,{className:"bg-[var(--ui-warning-soft)] text-[var(--warning)]",children:"Inactive"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-4",children:[e.jsx(v,{value:t.name,onChange:s=>void q.mutateAsync({contextId:t.id,patch:{name:s.target.value}}),placeholder:"Context name"}),e.jsxs("select",{value:t.shareMode,onChange:s=>void q.mutateAsync({contextId:t.id,patch:{shareMode:s.target.value}}),className:"min-h-10 rounded-[18px] border border-white/8 bg-white/[0.05] px-3 text-sm text-white outline-none",children:[e.jsx("option",{value:"shared",children:"shared"}),e.jsx("option",{value:"blended",children:"blended"}),e.jsx("option",{value:"isolated",children:"isolated"})]}),e.jsx(v,{value:String(t.decayDays),onChange:s=>void q.mutateAsync({contextId:t.id,patch:{decayDays:Number(s.target.value||90)}}),placeholder:"Decay days"}),e.jsx(m,{variant:"secondary",onClick:()=>D({contextId:t.id,tab:"overview"}),children:"Open context"})]}),e.jsx(A,{value:t.description,onChange:s=>void q.mutateAsync({contextId:t.id,patch:{description:s.target.value}}),className:"min-h-20"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{variant:"secondary",onClick:()=>void q.mutateAsync({contextId:t.id,patch:{active:!t.active}}),children:t.active?"Deactivate":"Activate"}),t.isDefault?null:e.jsx(m,{variant:"secondary",onClick:()=>void q.mutateAsync({contextId:t.id,patch:{isDefault:!0}}),children:"Make default"})]})]},t.id))}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs(j,{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Create context"}),e.jsx(v,{value:L.name,onChange:t=>W(s=>({...s,name:t.target.value})),placeholder:"Context name"}),e.jsx(A,{value:L.description,onChange:t=>W(s=>({...s,description:t.target.value})),className:"min-h-24",placeholder:"What changes in this context?"}),e.jsxs("select",{value:L.shareMode,onChange:t=>W(s=>({...s,shareMode:t.target.value})),className:"min-h-10 rounded-[18px] border border-white/8 bg-white/[0.05] px-3 text-sm text-white outline-none",children:[e.jsx("option",{value:"blended",children:"blended"}),e.jsx("option",{value:"shared",children:"shared"}),e.jsx("option",{value:"isolated",children:"isolated"})]}),e.jsx(v,{value:L.decayDays,onChange:t=>W(s=>({...s,decayDays:t.target.value})),placeholder:"Decay days"}),e.jsx(m,{disabled:!L.name.trim(),pending:De.isPending,pendingLabel:"Creating context",onClick:()=>void De.mutateAsync({userId:u,domain:C,name:L.name,description:L.description,shareMode:L.shareMode,decayDays:Number(L.decayDays||90),active:!0,isDefault:!1}),children:"Create context"})]}),e.jsxs(j,{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Merge contexts"}),e.jsxs("select",{value:G,onChange:t=>J(t.target.value),className:"min-h-10 rounded-[18px] border border-white/8 bg-white/[0.05] px-3 text-sm text-white outline-none",children:[e.jsx("option",{value:"",children:"Source context"}),r.contexts.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsxs("select",{value:O,onChange:t=>be(t.target.value),className:"min-h-10 rounded-[18px] border border-white/8 bg-white/[0.05] px-3 text-sm text-white outline-none",children:[e.jsx("option",{value:"",children:"Target context"}),r.contexts.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]}),e.jsx(m,{pending:Ae.isPending,pendingLabel:"Merging",disabled:!G||!O||G===O,onClick:()=>void Ae.mutateAsync({sourceContextId:G,targetContextId:O}),children:"Merge into target"})]})]})]}):null,_==="concepts"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.1fr)_380px]",children:[e.jsxs(j,{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Concept libraries"}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:"These are the lists Forge can use when you start the game in a concept domain. Seeded lists are editable, and custom lists are fully yours."})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-4",children:[["Lists",r.libraries.totalCatalogs],["Concepts",r.libraries.totalCatalogItems],["Seeded",r.libraries.seededCatalogCount],["Custom",r.libraries.customCatalogCount]].map(([t,s])=>e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:t}),e.jsx("div",{className:"mt-2 font-display text-3xl text-white",children:s})]},t))}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(de,{className:"size-4 text-white/38"}),e.jsx(v,{value:I,onChange:t=>V(t.target.value),placeholder:"Search lists, concepts, tags, and seeded domains"})]})]}),e.jsxs(j,{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.16em] text-white/42",children:"Create concept list"}),e.jsx(v,{value:H.title,onChange:t=>ue(s=>({...s,title:t.target.value})),placeholder:"List title"}),e.jsx(A,{value:H.description,onChange:t=>ue(s=>({...s,description:t.target.value})),className:"min-h-24",placeholder:"What should this list help compare?"}),e.jsx(m,{disabled:!H.title.trim(),pending:Se.isPending,pendingLabel:"Creating list",onClick:()=>void Se.mutateAsync({userId:u,domain:C,title:H.title,description:H.description}),children:"Create list"})]})]}),e.jsx("div",{className:"grid gap-4",children:Ce.map(t=>{const s=rt[t.id]??{label:"",description:"",tags:""},c=t.items.filter(n=>I.trim()?[n.label,n.description,n.tags.join(" ")].join(" ").toLowerCase().includes(le(I)):!0);return e.jsxs(j,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:ye===t.id?e.jsxs("div",{className:"grid gap-3",children:[e.jsx(v,{value:se.title,onChange:n=>pe(l=>({...l,title:n.target.value}))}),e.jsx(A,{value:se.description,onChange:n=>pe(l=>({...l,description:n.target.value})),className:"min-h-24"})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"font-display text-2xl text-white",children:t.title}),e.jsx(k,{className:"bg-white/[0.08] text-white/70",children:t.source}),e.jsxs(k,{className:"bg-white/[0.08] text-white/70",children:[t.items.length," items"]})]}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:t.description||"No description yet."})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{variant:"secondary",size:"sm",onClick:()=>void ze(C,t.id),children:"Start from this list"}),ye===t.id?e.jsxs(e.Fragment,{children:[e.jsx(m,{size:"sm",pending:Pe.isPending,pendingLabel:"Saving",onClick:()=>void Pe.mutateAsync({catalogId:t.id,patch:{title:se.title,description:se.description}}),children:"Save"}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>xe(null),children:"Cancel"})]}):e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>{xe(t.id),pe({title:t.title,description:t.description})},children:"Edit list"}),e.jsx(m,{variant:"ghost",size:"sm",pending:Fe.isPending,pendingLabel:"Deleting",onClick:()=>void Fe.mutateAsync(t.id),children:"Delete list"})]})]}),e.jsx("div",{className:"grid gap-2",children:c.map(n=>e.jsx("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-3",children:nt===n.id?e.jsxs("div",{className:"grid gap-3",children:[e.jsx(v,{value:B.label,onChange:l=>ae(y=>({...y,label:l.target.value}))}),e.jsx(A,{value:B.description,onChange:l=>ae(y=>({...y,description:l.target.value})),className:"min-h-20"}),e.jsx(v,{value:B.tags,onChange:l=>ae(y=>({...y,tags:l.target.value})),placeholder:"comma, separated, tags"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{size:"sm",pending:_e.isPending,pendingLabel:"Saving",onClick:()=>void _e.mutateAsync({catalogItemId:n.id,patch:{label:B.label,description:B.description,tags:B.tags.split(",").map(l=>l.trim()).filter(Boolean)}}),children:"Save concept"}),e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>he(null),children:"Cancel"})]})]}):e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-white",children:n.label}),e.jsx("div",{className:"mt-1 text-sm text-white/54",children:n.description||"No description yet."}),e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:n.tags.map(l=>e.jsx(k,{className:"bg-white/[0.08] text-white/70",children:l},`${n.id}-${l}`))})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(m,{variant:"ghost",size:"sm",onClick:()=>{he(n.id),ae({label:n.label,description:n.description,tags:n.tags.join(", ")})},children:"Edit"}),e.jsxs(m,{variant:"ghost",size:"sm",pending:Te.isPending,pendingLabel:"Deleting",onClick:()=>void Te.mutateAsync(n.id),children:[e.jsx(Ct,{className:"mr-1 size-4"}),"Delete"]})]})]})},n.id))}),e.jsxs("div",{className:"grid gap-3 rounded-[18px] border border-white/8 bg-white/[0.02] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-white/68",children:[e.jsx(kt,{className:"size-4"}),"Add concept to ",t.title]}),e.jsx(v,{value:s.label,onChange:n=>te(l=>({...l,[t.id]:{...s,label:n.target.value}})),placeholder:"Concept label"}),e.jsx(A,{value:s.description,onChange:n=>te(l=>({...l,[t.id]:{...s,description:n.target.value}})),className:"min-h-20",placeholder:"Short description"}),e.jsx(v,{value:s.tags,onChange:n=>te(l=>({...l,[t.id]:{...s,tags:n.target.value}})),placeholder:"comma, separated, tags"}),e.jsx(m,{disabled:!s.label.trim(),pending:Le.isPending,pendingLabel:"Adding",onClick:()=>void Le.mutateAsync({catalogId:t.id,label:s.label,description:s.description,tags:s.tags.split(",").map(n=>n.trim()).filter(Boolean),featureWeights:ne}).then(()=>te(n=>({...n,[t.id]:{label:"",description:"",tags:""}}))),children:"Add concept"})]})]},t.id)})})]}):null]}),e.jsx(cs,{state:E,onOpenChange:t=>{t||M(null),T(s=>({...s,open:t}))},error:at,loading:it,workspaceLoading:Ne.isLoading,activeWorkspace:P,conceptSearchQuery:I,onConceptSearchQueryChange:V,filteredCatalogs:Ce,onSelectDomain:t=>void ut(t),onStartCatalogGame:(t,s)=>void ze(t,s),onJudge:(t,s)=>void xt(t,s),onSignal:(t,s)=>void pt(t,s)})]})}export{ws as PreferencesPage};
@@ -1 +0,0 @@
1
- import{j as i}from"./vendor-kIz9EZnX.js";import{Z as l}from"./index-BHIKoiZ6.js";const r={active:"Active",paused:"Suspended",completed:"Finished",all:"All"};function d({value:e,counts:t,onChange:s,className:o}){return i.jsx("div",{className:l("flex flex-wrap gap-2",o),children:Object.keys(r).map(n=>{const a=n===e;return i.jsxs("button",{type:"button",onClick:()=>s(n),className:l("inline-flex min-h-10 items-center gap-2 rounded-full border px-4 py-2 text-sm transition",a?"border-[rgba(192,193,255,0.28)] bg-[rgba(192,193,255,0.16)] text-white shadow-[0_16px_36px_rgba(8,12,24,0.18)]":"border-white/8 bg-white/[0.04] text-white/62 hover:bg-white/[0.08] hover:text-white"),children:[i.jsx("span",{children:r[n]}),i.jsx("span",{className:l("rounded-full px-2 py-0.5 text-[11px]",a?"bg-white/12 text-white/88":"bg-white/8 text-white/54"),children:t[n]})]},n)})})}function h(e){return{active:e.filter(t=>t.status==="active").length,paused:e.filter(t=>t.status==="paused").length,completed:e.filter(t=>t.status==="completed").length,all:e.length}}function x(e,t){return t==="all"?e:e.filter(s=>s.status===t)}export{d as P,h as b,x as f};