forge-openclaw-plugin 0.3.3 → 0.3.5

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 (126) hide show
  1. package/dist/assets/{action-bar-5Ii4UzHa.js → action-bar-DBZ38L_6.js} +1 -1
  2. package/dist/assets/{activity-page-CWjTKFY3.js → activity-page-BJxUR9bD.js} +1 -1
  3. package/dist/assets/{ai-surface-workspace-Dd2FSRom.js → ai-surface-workspace-ehzBjTsW.js} +1 -1
  4. package/dist/assets/{atlas-panel-Dinteouh.js → atlas-panel-BFUeVT69.js} +1 -1
  5. package/dist/assets/{calendar-page-BWkXhzDf.js → calendar-page-Bg8W-YQ-.js} +1 -1
  6. package/dist/assets/{calendar-rules-CjyuTu2I.js → calendar-rules-9XQLoI96.js} +1 -1
  7. package/dist/assets/{calendar-week-toolbar-D-nd9tkk.js → calendar-week-toolbar-BeYnx1pE.js} +1 -1
  8. package/dist/assets/{companion-sync-lab-page-G0t1TqqZ.js → companion-sync-lab-page-BRKYkIrs.js} +1 -1
  9. package/dist/assets/{daily-metrics-dashboard-DpIAdzFX.js → daily-metrics-dashboard-Jt0nAHU5.js} +1 -1
  10. package/dist/assets/{define-workbench-box-BIOZopF2.js → define-workbench-box-5h-dyvJY.js} +1 -1
  11. package/dist/assets/{entity-link-multiselect-DZZjpL_d.js → entity-link-multiselect-Bb4De_e3.js} +1 -1
  12. package/dist/assets/{entity-note-count-link-CmRRdXAr.js → entity-note-count-link-BzWnsOmI.js} +1 -1
  13. package/dist/assets/{entity-notes-surface-8MPDscsu.js → entity-notes-surface-CagOwdng.js} +1 -1
  14. package/dist/assets/{execution-board-Bi8gi8J6.js → execution-board-DTmAtmqZ.js} +1 -1
  15. package/dist/assets/{faceted-token-search-BGs4TqxT.js → faceted-token-search-DJPRm9AY.js} +1 -1
  16. package/dist/assets/{flagship-signal-deck-jLxHEHvb.js → flagship-signal-deck-CJbGZF7I.js} +1 -1
  17. package/dist/assets/{floating-action-menu-Itpm7T2_.js → floating-action-menu-K77jh8XZ.js} +1 -1
  18. package/dist/assets/{generic-node-view-KePoUF3Z.js → generic-node-view-p5ePSFuG.js} +1 -1
  19. package/dist/assets/{goal-detail-page-a1lEswpJ.js → goal-detail-page-DGu_khEK.js} +1 -1
  20. package/dist/assets/{goal-dialog-CYgRzl4y.js → goal-dialog-BWD7cOv9.js} +1 -1
  21. package/dist/assets/{goals-page-JY_EJq9U.js → goals-page-Bgj3sj0f.js} +1 -1
  22. package/dist/assets/{habits-page-BRI8AoaQ.js → habits-page-Ctut1tuX.js} +1 -1
  23. package/dist/assets/{health-boxes-DZJOFTOI.js → health-boxes-Ie3horXx.js} +1 -1
  24. package/dist/assets/index-BaiwtAgo.js +2 -0
  25. package/dist/assets/{index-Bcem7l5u.css → index-CEgIwgk9.css} +1 -1
  26. package/dist/assets/{inline-note-fields-CUVRzQkI.js → inline-note-fields-DE6WM9uM.js} +1 -1
  27. package/dist/assets/{insight-flow-dialog-By73oG1H.js → insight-flow-dialog-XL8I74eJ.js} +1 -1
  28. package/dist/assets/{insights-page-DLyN-9yz.js → insights-page-Bz1FLbp5.js} +1 -1
  29. package/dist/assets/{kanban-boxes-M71CejV4.js → kanban-boxes-BBziel7P.js} +1 -1
  30. package/dist/assets/{kanban-page-InKHhJQD.js → kanban-page-DdQP73I3.js} +1 -1
  31. package/dist/assets/{knowledge-graph-page-C-GEQGRY.js → knowledge-graph-page-DdHWj4Dj.js} +1 -1
  32. package/dist/assets/{life-force-page-Dq88NzNp.js → life-force-page-BRN-93cI.js} +1 -1
  33. package/dist/assets/{life-force-workspace-Bl_0slZi.js → life-force-workspace-BowvP5R4.js} +1 -1
  34. package/dist/assets/{metric-tile-yQJgjYrN.js → metric-tile-B6aJueRo.js} +1 -1
  35. package/dist/assets/{movement-boxes-C-rc3N8Z.js → movement-boxes-5cjWjIdR.js} +1 -1
  36. package/dist/assets/{movement-page-DK-d1uYa.js → movement-page-Dy53RWtB.js} +1 -1
  37. package/dist/assets/{note-markdown-7czv-KMH.js → note-markdown-CvEQCfoi.js} +1 -1
  38. package/dist/assets/{note-tags-input-CkgkqiT3.js → note-tags-input-Cg5zBXos.js} +1 -1
  39. package/dist/assets/{notes-boxes-BQuR1MiB.js → notes-boxes-CgZyf7mV.js} +1 -1
  40. package/dist/assets/{notes-page-ec9g1mPh.js → notes-page-Cbdcv0Ej.js} +1 -1
  41. package/dist/assets/{open-in-graph-button-B_4fdm4l.js → open-in-graph-button-D31ZOEhA.js} +1 -1
  42. package/dist/assets/{orbit-map-DPQNBqS-.js → orbit-map-8eNDWek8.js} +1 -1
  43. package/dist/assets/overview-page-CZ6q52Qj.js +1 -0
  44. package/dist/assets/{page-hero-BRcqE3a4.js → page-hero-C0MpI3MM.js} +1 -1
  45. package/dist/assets/{pill-cluster-dy6jG_dV.js → pill-cluster-DGwKZQKF.js} +1 -1
  46. package/dist/assets/{preference-entity-handoff-button-DOV-_2Vm.js → preference-entity-handoff-button-CJhr5AXl.js} +1 -1
  47. package/dist/assets/{preferences-page-Co8w5hzp.js → preferences-page-8vszDNFX.js} +1 -1
  48. package/dist/assets/{project-collections-DNgKleDl.js → project-collections-sC7eAAhS.js} +1 -1
  49. package/dist/assets/{project-detail-page-C-Ib1x8w.js → project-detail-page-BKdnMjJy.js} +1 -1
  50. package/dist/assets/{project-dialog-D_hgOdB9.js → project-dialog-BiHZpOo1.js} +1 -1
  51. package/dist/assets/{project-management-hierarchy-page-asf61KSz.js → project-management-hierarchy-page-VW-hykAI.js} +1 -1
  52. package/dist/assets/{project-management-section-nav-DAZA1oXG.js → project-management-section-nav-BEZ5zihs.js} +1 -1
  53. package/dist/assets/{projects-boxes-CHLr1Bs-.js → projects-boxes-Ca6rpYeE.js} +1 -1
  54. package/dist/assets/{projects-page-BsM8yCqQ.js → projects-page-D86pjpTf.js} +1 -1
  55. package/dist/assets/{psyche-behaviors-page-COSZeP4J.js → psyche-behaviors-page-YLJB6CRU.js} +1 -1
  56. package/dist/assets/{psyche-flashcards-page-CJmgGL9x.js → psyche-flashcards-page-D3gdHLUw.js} +1 -1
  57. package/dist/assets/{psyche-goal-map-page-avrWNSs9.js → psyche-goal-map-page-DJiqSiCx.js} +1 -1
  58. package/dist/assets/{psyche-graph-BmwbnNBY.js → psyche-graph-Tke0qFdt.js} +1 -1
  59. package/dist/assets/{psyche-metrics-page-CY0J_aMx.js → psyche-metrics-page-DoLnvmC2.js} +1 -1
  60. package/dist/assets/{psyche-mode-guide-page-COcswIHZ.js → psyche-mode-guide-page-_Zbvg_HL.js} +1 -1
  61. package/dist/assets/{psyche-modes-page-BXF_GZoP.js → psyche-modes-page-eAkaAzJc.js} +1 -1
  62. package/dist/assets/{psyche-page-VsMBNG1F.js → psyche-page-CwmuBVjA.js} +1 -1
  63. package/dist/assets/{psyche-patterns-page-DVoIro0Q.js → psyche-patterns-page-D7B4Ykjq.js} +1 -1
  64. package/dist/assets/{psyche-questionnaire-builder-page-CahcrbQj.js → psyche-questionnaire-builder-page-CHJlvCzX.js} +1 -1
  65. package/dist/assets/{psyche-questionnaire-detail-page-CYSgADAD.js → psyche-questionnaire-detail-page-Bg3ll-D4.js} +1 -1
  66. package/dist/assets/{psyche-questionnaire-run-detail-page-D5q5URTu.js → psyche-questionnaire-run-detail-page-CIEerczF.js} +1 -1
  67. package/dist/assets/{psyche-questionnaire-run-page-DUoA-VSs.js → psyche-questionnaire-run-page-DyxIk6Qx.js} +1 -1
  68. package/dist/assets/{psyche-questionnaires-page-dbQlqbKh.js → psyche-questionnaires-page-ZlqUxuIl.js} +1 -1
  69. package/dist/assets/{psyche-report-detail-page-D_Mmlf2D.js → psyche-report-detail-page-B2jgYnQ5.js} +1 -1
  70. package/dist/assets/{psyche-reports-page-CO3J4Js3.js → psyche-reports-page-DlXr52yr.js} +1 -1
  71. package/dist/assets/{psyche-schemas-beliefs-page-BUNGL4zW.js → psyche-schemas-beliefs-page-BhrTZN9B.js} +1 -1
  72. package/dist/assets/{psyche-screen-time-page-Bm18uHDg.js → psyche-screen-time-page-WNGcdusx.js} +1 -1
  73. package/dist/assets/{psyche-self-observation-page-VdPMBuK4.js → psyche-self-observation-page-XsCOglo4.js} +1 -1
  74. package/dist/assets/{psyche-values-page-DivSQodJ.js → psyche-values-page-NvHI6zWK.js} +1 -1
  75. package/dist/assets/{question-flow-dialog-Dsnsc8be.js → question-flow-dialog-Bj4PxpjS.js} +1 -1
  76. package/dist/assets/{report-chain-fields-Bf-WCSJQ.js → report-chain-fields-mWFikZzT.js} +1 -1
  77. package/dist/assets/{rewards-page-CI53Cp0i.js → rewards-page-DyjwXsQN.js} +1 -1
  78. package/dist/assets/{scheduling-rules-editor-Bg3QU_qt.js → scheduling-rules-editor-C6FEYOxd.js} +1 -1
  79. package/dist/assets/{schema-badge-CRThEDqP.js → schema-badge-CCe4zkSN.js} +1 -1
  80. package/dist/assets/{schemas-B8-kIOFQ.js → schemas-Cjwn6ooR.js} +1 -1
  81. package/dist/assets/{select-menu-rT3Qd5t5.js → select-menu-DeJhCsd8.js} +1 -1
  82. package/dist/assets/{settings-agents-page-VDUv2WuO.js → settings-agents-page-DYDxyKu-.js} +1 -1
  83. package/dist/assets/{settings-bin-page-DfuGJVqc.js → settings-bin-page-BWLfKVW1.js} +1 -1
  84. package/dist/assets/{settings-calendar-page-ex7eHB1y.js → settings-calendar-page-Ci-wXhCv.js} +1 -1
  85. package/dist/assets/{settings-data-page-BPWyPVGo.js → settings-data-page-DxIw-fWn.js} +1 -1
  86. package/dist/assets/{settings-logs-page-CwTT4n63.js → settings-logs-page-inpyIdu6.js} +1 -1
  87. package/dist/assets/{settings-mobile-page-B6sVk872.js → settings-mobile-page-BcJGLax8.js} +1 -1
  88. package/dist/assets/{settings-models-page-Dq5XViZd.js → settings-models-page-OWTRhfkj.js} +1 -1
  89. package/dist/assets/{settings-page-BRxdAxbS.js → settings-page-DXxF3qK2.js} +1 -1
  90. package/dist/assets/{settings-rewards-page-DRvxTwv3.js → settings-rewards-page-CCXin1n_.js} +1 -1
  91. package/dist/assets/{settings-section-nav-D_vKvOWd.js → settings-section-nav-CwSDNC3W.js} +1 -1
  92. package/dist/assets/{settings-users-page-B6oSpOaV.js → settings-users-page-B4NEACwR.js} +1 -1
  93. package/dist/assets/{settings-wiki-page-Bkv-SS3J.js → settings-wiki-page-BNRK1SYc.js} +1 -1
  94. package/dist/assets/{sleep-page-DELXxo6j.js → sleep-page-Bara54nB.js} +1 -1
  95. package/dist/assets/{sports-page-ByWQL0Gf.js → sports-page-BawekFKD.js} +1 -1
  96. package/dist/assets/{strategies-page-PuUHsaSJ.js → strategies-page-BEl3NGAU.js} +1 -1
  97. package/dist/assets/{strategy-detail-page-CSyVdv29.js → strategy-detail-page-DPPI_8Ub.js} +1 -1
  98. package/dist/assets/{strategy-dialog-Fgpc0z1M.js → strategy-dialog-DU6wbBkQ.js} +1 -1
  99. package/dist/assets/{surface-DzVqQDmf.js → surface-BVYp-Wq9.js} +1 -1
  100. package/dist/assets/{task-detail-page-BoLvJ_4F.js → task-detail-page-BsMVAsbb.js} +1 -1
  101. package/dist/assets/{task-dialog-B2cGkhLk.js → task-dialog-BGzPc6TW.js} +1 -1
  102. package/dist/assets/{timebox-planning-dialog-BjiC2jh0.js → timebox-planning-dialog-4_XWuqkw.js} +1 -1
  103. package/dist/assets/{today-boxes-B4f4sBXg.js → today-boxes-5pCvh5zS.js} +1 -1
  104. package/dist/assets/{today-page-Cusp2JI8.js → today-page-BGurICpl.js} +1 -1
  105. package/dist/assets/{training-load-page-CsZbK6rY.js → training-load-page-BkoYKZ9_.js} +1 -1
  106. package/dist/assets/{user-badge-CQygGKVs.js → user-badge-DfDv87j7.js} +1 -1
  107. package/dist/assets/{utility-widgets-DRESNarT.js → utility-widgets-CbYj32he.js} +1 -1
  108. package/dist/assets/{vitals-page-BlTZ4f78.js → vitals-page-DlxMk-L7.js} +1 -1
  109. package/dist/assets/{weekly-review-page-3Pk3NeGE.js → weekly-review-page-VrEvAl1T.js} +1 -1
  110. package/dist/assets/{weight-loss-page-CRCtv1fX.js → weight-loss-page-DJDnjxKF.js} +3 -3
  111. package/dist/assets/{wiki-article-markdown-D0PWvioX.js → wiki-article-markdown-DxTkiQRy.js} +1 -1
  112. package/dist/assets/{wiki-editor-page-OZMYUgFo.js → wiki-editor-page-Beu92YnZ.js} +1 -1
  113. package/dist/assets/{wiki-ingest-history-page-DXZHzAqU.js → wiki-ingest-history-page-Cq_soygm.js} +1 -1
  114. package/dist/assets/{wiki-ingest-modal-Ro0V4UMB.js → wiki-ingest-modal-D6xs2sEn.js} +1 -1
  115. package/dist/assets/{wiki-page-B1g3Rfxy.js → wiki-page-yF3Flgtg.js} +1 -1
  116. package/dist/assets/{workbench-flow-page-qh5nItU6.js → workbench-flow-page-CZZGg3a8.js} +1 -1
  117. package/dist/assets/{workbench-page-CFWfAYMV.js → workbench-page-DKENZ5Nz.js} +1 -1
  118. package/dist/assets/{workout-detail-page-Cw6t6Xj9.js → workout-detail-page-CeN4QiYQ.js} +1 -1
  119. package/dist/index.html +2 -2
  120. package/dist/server/server/src/app.js +4 -1
  121. package/dist/server/server/src/health.js +47 -19
  122. package/dist/server/src/lib/api.js +4 -1
  123. package/openclaw.plugin.json +1 -1
  124. package/package.json +1 -1
  125. package/dist/assets/index-wEZUnRh0.js +0 -2
  126. package/dist/assets/overview-page-CZjMab2o.js +0 -1
@@ -1 +1 @@
1
- import{r as x,j as e,aK as $t,b_ as It,b3 as Ft,ck as ga,bZ as fa,aZ as ot,cl as wt,F as Ua,cm as Wa,bX as Ga,cn as ba,co as Va,c1 as Ya,bu as Xa}from"./vendor-Cpmju3nw.js";import{j as ya,x as Yt,i as ae,k as Pe}from"./state-BtwEvpO6.js";import{I as B,B as A,c as w,k as v,C as k,aF as Xt,aG as Zt,aH as ja,aI as Za,aJ as Ja,S as Na,e as ka,aA as wa,aK as Jt,aL as er,aM as tr,aN as Sa,aO as ar,d as rr,aP as at,n as ea,m as rt,a4 as ce,aQ as sr,aR as ir,aS as nr,aT as lr,aU as or,O as dr,aV as cr,aW as ur,aX as mr}from"./index-wEZUnRh0.js";import{F as Ma}from"./faceted-token-search-BGs4TqxT.js";import{P as xr}from"./page-hero-BRcqE3a4.js";import{R as Qe,P as Ue,O as We,C as Ge,T as mt,D as xt,a as vt}from"./ui-B9O-eUim.js";import{m as ta}from"./motion-DwjmC9aq.js";import{S as me}from"./surface-DzVqQDmf.js";import{M as vr,a as pr,b as hr,c as gr,d as fr}from"./movement-boxes-C-rc3N8Z.js";import{R as br,A as yr,C as jr,X as Nr,Y as kr,T as wr,a as Sr}from"./charts-DwTguE_x.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./generic-node-view-KePoUF3Z.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-BIOZopF2.js";function Aa({open:t,onOpenChange:a,place:r,seed:s,onSave:l}){const[c,m]=x.useState({label:(r==null?void 0:r.label)??(s==null?void 0:s.label)??"",latitude:String((r==null?void 0:r.latitude)??(s==null?void 0:s.latitude)??""),longitude:String((r==null?void 0:r.longitude)??(s==null?void 0:s.longitude)??""),radiusMeters:String((r==null?void 0:r.radiusMeters)??(s==null?void 0:s.radiusMeters)??100),categoryTags:((r==null?void 0:r.categoryTags)??(s==null?void 0:s.categoryTags)??[]).join(", ")});return x.useEffect(()=>{m({label:(r==null?void 0:r.label)??(s==null?void 0:s.label)??"",latitude:String((r==null?void 0:r.latitude)??(s==null?void 0:s.latitude)??""),longitude:String((r==null?void 0:r.longitude)??(s==null?void 0:s.longitude)??""),radiusMeters:String((r==null?void 0:r.radiusMeters)??(s==null?void 0:s.radiusMeters)??100),categoryTags:((r==null?void 0:r.categoryTags)??(s==null?void 0:s.categoryTags)??[]).join(", ")})},[r,s]),e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(Ge,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(32rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-normal text-[var(--ui-ink-strong)]",children:r?`Edit ${r.label}`:"New known place"}),e.jsx(xt,{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Define life landmarks once so the companion and web views can reason about stays and trips consistently."})]}),e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:e.jsx($t,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(B,{value:c.label,onChange:d=>m(u=>({...u,label:d.target.value})),placeholder:"Home, Main Office, Riverside path..."}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(B,{value:c.latitude,onChange:d=>m(u=>({...u,latitude:d.target.value})),placeholder:"Latitude"}),e.jsx(B,{value:c.longitude,onChange:d=>m(u=>({...u,longitude:d.target.value})),placeholder:"Longitude"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[10rem_minmax(0,1fr)]",children:[e.jsx(B,{value:c.radiusMeters,onChange:d=>m(u=>({...u,radiusMeters:d.target.value})),placeholder:"Radius meters"}),e.jsx(B,{value:c.categoryTags,onChange:d=>m(u=>({...u,categoryTags:d.target.value})),placeholder:"home, gym, holiday, parents-house"})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(A,{variant:"ghost",onClick:()=>a(!1),className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",children:"Cancel"}),e.jsx(A,{onClick:()=>void l({id:r==null?void 0:r.id,label:c.label,latitude:Number(c.latitude),longitude:Number(c.longitude),radiusMeters:Number(c.radiusMeters),categoryTags:c.categoryTags.split(",").map(d=>d.trim()).filter(Boolean)}).then(()=>a(!1)),children:"Save place"})]})]})]})})}const St=1e3;function I(t){return new Date(t).getTime()}function Mt(t){return new Date(t).toISOString()}function aa(t,a){const r=I(t.startedAt)-I(a.startedAt);if(r!==0)return r;const s=I(t.endedAt)-I(a.endedAt);return s!==0?s:t.id.localeCompare(a.id)}function Et(t){return t.syncSource==="sleep overlay"}function Mr(t){const a=[...t].filter(s=>I(s.endedAt)>I(s.startedAt)).sort((s,l)=>{const c=I(s.startedAt)-I(l.startedAt);if(c!==0)return c;const m=I(s.endedAt)-I(l.endedAt);return m!==0?m:s.id.localeCompare(l.id)});if(a.length===0)return[];const r=[];for(const s of a){const l=r.at(-1);if(!l){r.push(s);continue}const c=I(l.endedAt);if(I(s.startedAt)<=c+St){const d=Math.max(c,I(s.endedAt));r[r.length-1]={...l,id:`${l.id}__${s.id}`,endedAt:Mt(d),asleepSeconds:(l.asleepSeconds??0)+(s.asleepSeconds??0)||null,timeInBedSeconds:(l.timeInBedSeconds??0)+(s.timeInBedSeconds??0)||null,sleepScore:s.sleepScore??l.sleepScore,regularityScore:s.regularityScore??l.regularityScore,efficiency:s.efficiency??l.efficiency,recoveryState:s.recoveryState??l.recoveryState};continue}r.push(s)}return r}function Ar(t){const a=[];if(typeof t.asleepSeconds=="number"&&t.asleepSeconds>0){const r=t.asleepSeconds/3600;a.push(`${r.toFixed(r>=1?1:2)}h asleep`)}else if(typeof t.timeInBedSeconds=="number"&&t.timeInBedSeconds>0){const r=t.timeInBedSeconds/3600;a.push(`${r.toFixed(r>=1?1:2)}h in bed`)}return typeof t.sleepScore=="number"&&a.push(`score ${t.sleepScore}`),typeof t.regularityScore=="number"&&a.push(`regularity ${t.regularityScore}`),t.recoveryState&&a.push(t.recoveryState),a.join(" · ")||"Sleep session"}function Cr(t){const a=Math.max(60,Math.round((I(t.endedAt)-I(t.startedAt))/1e3));return{id:`sleep-overlay-${t.id}`,boxId:`sleep-overlay-${t.id}`,kind:"stay",sourceKind:"automatic",origin:"recorded",editable:!1,isInvalid:!1,startedAt:t.startedAt,endedAt:t.endedAt,trueStartedAt:t.startedAt,trueEndedAt:t.endedAt,visibleStartedAt:t.startedAt,visibleEndedAt:t.endedAt,durationSeconds:a,laneSide:"left",connectorFromLane:"left",connectorToLane:"left",title:"Sleep",subtitle:Ar(t),placeLabel:null,tags:["sleep"],syncSource:"sleep overlay",cursor:`${t.endedAt}::sleep-overlay-${t.id}`,overrideCount:0,overriddenAutomaticBoxIds:[],overriddenUserBoxIds:[],isFullyHidden:!1,rawStayIds:[],rawTripIds:[],rawPointCount:0,hasLegacyCorrections:!1,stay:null,trip:null}}function ra(t,a,r){if(r<=a)return null;const s=Mt(a),l=Mt(r),c=Math.max(60,Math.round((r-a)/1e3));return{...t,id:`${t.id}::virtual-${a}-${r}`,startedAt:s,endedAt:l,trueStartedAt:s,trueEndedAt:l,visibleStartedAt:s,visibleEndedAt:l,durationSeconds:c,cursor:`${l}::${t.id}::virtual`}}function Tr(t,a){let r=[...t].sort(aa);for(const s of Mr(a)){const l=I(s.startedAt),c=I(s.endedAt),m=Cr(s),d=[];let u=!1;for(const p of r){const g=I(p.startedAt),j=I(p.endedAt);if(j<=l||g>=c){!u&&g>=c&&(d.push(m),u=!0),d.push(p);continue}if(g<l){const P=ra(p,g,Math.min(j,l-St));P&&d.push(P)}if(u||(d.push(m),u=!0),j>c){const P=ra(p,Math.max(g,c+St),j);P&&d.push(P)}}u||d.push(m),r=d.sort(aa)}return r}const sa=24,X=64,At=360*60,Ca=5,Nt=1,Pr=104,ia=X*8;function he(t){return t.trim().toLowerCase()}function qe(t){return t>=86400?`${Math.round(t/3600)}h`:t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.max(1,Math.round(t/60))}m`}function ge(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ta(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit"}).format(new Date(t))}function Dr(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:!1}).format(t)}function $e(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const r=a.getFullYear(),s=String(a.getMonth()+1).padStart(2,"0"),l=String(a.getDate()).padStart(2,"0"),c=String(a.getHours()).padStart(2,"0"),m=String(a.getMinutes()).padStart(2,"0");return`${r}-${s}-${l}T${c}:${m}`}function dt(t){if(!t.trim())return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toISOString()}function Ie(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Y(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function na(t,a){return`${t.toFixed(3)}, ${a.toFixed(3)}`}function st(t,a){return`${t.toFixed(6)}, ${a.toFixed(6)}`}function la(t){return`${Math.max(1,Math.round(t/60))} min`}function Lr(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),r=Math.max(...t.map(d=>d.latitude)),s=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(r-a,1e-4),m=Math.max(l-s,1e-4);return t.map((d,u)=>({...d,x:12+(d.longitude-s)/m*76,y:12+(1-(d.latitude-a)/c)*76,id:`${d.recordedAt??"point"}-${u}`}))}function ct(t){return t.kind==="trip"&&t.trip!==null}function le(t){return t.kind==="stay"&&t.stay!==null}function Ct(t){return!le(t)||t.stay.place?null:{label:t.stay.label||t.title,latitude:t.stay.centerLatitude,longitude:t.stay.centerLongitude,radiusMeters:t.stay.radiusMeters,categoryTags:t.tags}}function Fe(t){var a;return t?t.kind==="stay"&&le(t)?((a=t.stay.place)==null?void 0:a.label)??t.placeLabel??t.stay.label??null:t.placeLabel??null:null}function lt(t,a,r,s){const c=(r-t)*Math.PI/180,m=(s-a)*Math.PI/180,d=t*Math.PI/180,u=r*Math.PI/180,p=Math.sin(c/2)**2+Math.cos(d)*Math.cos(u)*Math.sin(m/2)**2;return 2*6371e3*Math.asin(Math.sqrt(p))}function $r(t){return he([t.label,...t.aliases].join(" "))}function we(t,a,r){if(!t.trip)return{label:t.placeLabel??(a==="start"?"Known origin":"Known destination"),detail:Y(a==="start"?t.startedAt:t.endedAt)};const s=a==="start"?t.trip.points[0]??null:t.trip.points[t.trip.points.length-1]??null,l=a==="start"?t.trip.startPlace:t.trip.endPlace,c=(r==null?void 0:r.includeCoordinates)??!0,m=r!=null&&r.useHistoryAnchorFallback&&a==="start"?"Beginning of history":null;return{label:(l==null?void 0:l.label)??m??(c&&s?na(s.latitude,s.longitude):a==="start"?"Unknown origin":"Unknown destination"),detail:c&&s&&!l?na(s.latitude,s.longitude):Y(a==="start"?t.startedAt:t.endedAt)}}function Ir(t){const a=t.trim().toLowerCase();return a==="travel"||a==="trip"||a==="move"}function Fr(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 Er(t){const a=Fe(t),r=t.title.trim().toLowerCase(),s=r.length===0||r==="stay"||r==="continued stay"||r==="repaired stay"||r==="manual stay";return a&&s?a:t.title.trim()||a||"Stay"}function ue(t){if(Et(t))return"Sleep";if(t.kind==="missing")return Fr(t);if(t.kind==="stay")return Er(t);if(t.kind==="trip"&&Ir(t.title)){const a=we(t,"start").label,r=we(t,"end").label;return`${a} → ${r}`}return t.title}function oa(t){return t==="left"?24:t==="right"?76:50}function _r(t,a,r){const s=Math.min(t,At)/3600,l=r==="sleep overlay",c=l?112:a==="stay"?104:92,m=l?272:a==="stay"?288:232,d=c+s*30;return Math.max(c,Math.min(m,d))}function Tt(t){var a;return{kind:t.kind,label:le(t)?t.stay.label||t.title:ct(t)&&t.trip.label||t.title,placeLabel:le(t)?((a=t.stay.place)==null?void 0:a.label)??t.placeLabel??"":"",tagsInput:t.tags.join(", "),startedAtInput:$e(t.startedAt),endedAtInput:$e(t.endedAt)}}function kt(t,a){const r=(a==null?void 0:a.startedAt)??new Date(Date.now()-36e5).toISOString(),s=(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t,label:t==="missing"?"User-defined missing data":t==="stay"?(a==null?void 0:a.placeLabel)||"Manual stay":"Manual move",placeLabel:(a==null?void 0:a.placeLabel)??"",tagsInput:t==="missing"?"user-defined, missing-data":t==="stay"?"user-defined, stay":"user-defined, move",startedAtInput:$e(r),endedAtInput:$e(s)}}function Pt(t,a){var c,m;const r=t.tagsInput.split(",").map(d=>d.trim()).filter(Boolean),s=dt(t.startedAtInput)??(a==null?void 0:a.startedAt)??new Date(Date.now()-3600*1e3).toISOString(),l=dt(t.endedAtInput)??(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t.kind,startedAt:s,endedAt:l,title:t.label.trim(),subtitle:t.kind==="missing"?"User-defined missing-data override.":"User-defined movement box.",placeLabel:t.placeLabel.trim()||null,tags:r,distanceMeters:t.kind==="trip"?Math.max(((c=a==null?void 0:a.trip)==null?void 0:c.distanceMeters)??150,150):null,averageSpeedMps:t.kind==="trip"?((m=a==null?void 0:a.trip)==null?void 0:m.averageSpeedMps)??null:null,metadata:{createdFrom:"movement-life-timeline"}}}function Rr(t,a){var l,c;const r=t.kind==="stay"?((c=(l=t.stay)==null?void 0:l.label)==null?void 0:c.trim())??"":"";if(r)return r;const s=t.title.trim();return s&&s.toLowerCase()!=="stay"?s:a.trim()||"Stay"}function zr(t,a){const r=Tt(t),s=a.trim();return Pt({...r,label:Rr(t,s),placeLabel:s},t)}function Pa(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function ut(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Or(t){var a,r,s;return he([t.kind,ue(t),t.subtitle,t.placeLabel??"",...t.tags,ut(t.startedAt),ut(t.endedAt),Pa(t.startedAt),le(t)?((a=t.stay.place)==null?void 0:a.label)??t.stay.label:ct(t)?[t.trip.label,t.trip.activityType,t.trip.travelMode,(r=t.trip.startPlace)==null?void 0:r.label,(s=t.trip.endPlace)==null?void 0:s.label].filter(Boolean).join(" "):t.kind==="trip"?[t.title,t.subtitle,t.placeLabel??""].filter(Boolean).join(" "):"missing data gap"].join(" "))}function Hr(t){const a=new Map;a.set("kind:stay",{id:"kind:stay",label:"Stay",description:"Stationary spans and place anchors."}),a.set("kind:trip",{id:"kind:trip",label:"Move",description:"Trips and movement connectors."});for(const r of["night","morning","afternoon","evening"])a.set(`time:${r}`,{id:`time:${r}`,label:r[0].toUpperCase()+r.slice(1),description:"Filter by the segment start time."});for(const r of t){for(const s of r.tags)a.set(`tag:${s}`,{id:`tag:${s}`,label:s,description:"Movement tag"});r.placeLabel&&a.set(`place:${r.placeLabel}`,{id:`place:${r.placeLabel}`,label:r.placeLabel,description:"Matched place"})}return[...a.values()].sort((r,s)=>r.label.localeCompare(s.label))}function Br(t,a){return a.every(r=>r==="kind:stay"||r==="kind:trip"?t.kind===r.slice(5):r.startsWith("time:")?Pa(t.startedAt)===r.slice(5):r.startsWith("tag:")?t.tags.includes(r.slice(4)):r.startsWith("place:")?(t.placeLabel??"")===r.slice(6):!0)}function da(t,a){return t&&{...t,pages:t.pages.map(r=>({...r,segments:r.segments.filter(s=>s.id!==a)}))}}function Kr(t,a){const r=t+(Math.sin((t-.5)*Math.PI)+1)*.5-t,s=t-.5,c=.5+(s*(1-a*.64)+s*s*s*a*2.56);return Math.max(0,Math.min(1,c-(r-t)*a*.08))}function qr(t){return t.getHours()===0?Ta(t.toISOString()):Dr(t)}function Qr(t,a){const r=new Date(t.endedAt).getTime(),s=new Date(t.startedAt).getTime(),l=Math.max(1,r-s),c=Math.max(0,Math.min(1,(a-s)/l));if(t.durationSeconds<=At)return c;const m=Math.max(0,1-Math.min(1,At/Math.max(1,t.durationSeconds)));return Kr(c,m)}function Ur(t,a,r){if(t.items.length===0)return null;const s=t.items[0];if(a<new Date(s.segment.startedAt).getTime())return t.historyHeaderHeight+t.leadHeight-(new Date(s.segment.startedAt).getTime()-a)/36e5*X;for(let m=0;m<t.items.length;m+=1){const d=t.items[m],u=new Date(d.segment.startedAt).getTime(),p=new Date(d.segment.endedAt).getTime();if(a>=u&&a<=p)return d.boxTop+Qr(d.segment,a)*d.displayHeight;const g=t.items[m+1]??null,j=g?new Date(g.segment.startedAt).getTime():r;if(a>p&&a<j)return d.boxBottom+(a-p)/36e5*X}const l=t.items[t.items.length-1],c=new Date(l.segment.endedAt).getTime();return a>=c?l.boxBottom+(a-c)/36e5*X:null}function Wr(t){const a=new Date(t);a.setMinutes(0,0,0);const r=a.getTime();return r<=t?r+36e5:r}function Gr(t,a){const r=[];if(t.items.length===0)return r;const s=t.items[0],l=new Date(s.segment.startedAt).getTime();for(let c=Wr(l-Ca*36e5);c<=a;c+=36e5){const m=Ur(t,c,a);if(m===null)continue;const d=new Date(c);r.push({y:m,label:qr(d),strong:d.getHours()===0})}return r}function Vr({segments:t,viewportHeight:a,nowMs:r=Date.now()}){var U;const s=t.length>0?Pr:0,l=t.length>0?X*Ca:0;let c=s+l,m=null;const d=t.map(b=>{const C=_r(b.durationSeconds,b.kind,b.syncSource),E=new Date(b.startedAt).getTime(),K=m===null?0:Math.max(0,(E-m)/36e5)*X;c+=K;const Z=c,z=Z+C;return c=z,m=new Date(b.endedAt).getTime(),{id:b.id,segment:b,gapBefore:K,displayHeight:C,boxTop:Z,boxBottom:z}}),u=r+Nt*36e5,p=(()=>{var E;const b=(E=t[t.length-1])==null?void 0:E.endedAt;if(!b)return X*Nt;const C=new Date(b).getTime();return Math.max(X*Nt,(u-C)/36e5*X)})(),g=(((U=d[d.length-1])==null?void 0:U.boxBottom)??s+l)+p,j=Math.max(g,a>0?a+260:960,s+l+p),P={historyHeaderHeight:s,leadHeight:l,items:d,markers:[],rangeEndMs:u,futureTailHeight:p+Math.max(0,j-g),totalHeight:j};return{...P,markers:Gr(P,u)}}const Yr="bg-[image:var(--ui-surface-section)]",Xr="bg-[image:var(--ui-surface-section)]",Zr="h-6 w-[3px] rounded-full bg-[var(--info)] shadow-[var(--ui-shadow-soft)]",Jr="relative w-[min(18rem,calc(100vw-6rem))] overflow-hidden rounded-[26px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[image:var(--ui-surface-section)] shadow-[var(--ui-shadow-soft)]",es="absolute z-10 h-7 w-8 rounded-[12px] border bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-soft)] backdrop-blur-sm",ts="group absolute top-1/2 max-w-[min(8rem,calc(100vw-8rem))] -translate-y-1/2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] px-2.5 py-2 text-left shadow-[var(--ui-shadow-soft)] backdrop-blur-sm transition hover:border-[var(--ui-border-strong)] sm:max-w-[9rem] sm:px-3",Dt="ring-1 ring-[color-mix(in_srgb,var(--info)_42%,transparent)]",as="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",Da="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",Te="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",rs="border-[color-mix(in_srgb,var(--danger)_26%,transparent)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)] hover:bg-[color-mix(in_srgb,var(--danger)_18%,transparent)]",ss="border-[color-mix(in_srgb,var(--warning)_26%,transparent)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)] hover:bg-[color-mix(in_srgb,var(--warning)_18%,transparent)]";function is({layout:t,scrollTop:a,viewportHeight:r}){const s=X*6,l=Math.max(0,a-s),c=Math.min(t.totalHeight,a+Math.max(r,X*8)+s),m=t.markers.filter(d=>d.y>=l&&d.y<=c);return e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 overflow-hidden rounded-[30px]",style:{height:`${t.totalHeight}px`},children:[e.jsx("div",{className:w("absolute inset-y-0 left-0 w-18",Yr)}),m.map((d,u)=>e.jsxs("div",{className:"absolute inset-x-0",style:{top:`${d.y}px`},children:[e.jsx("div",{className:w("border-t",(d.strong,"border-[var(--ui-border-subtle)]"))}),e.jsx("div",{className:w("absolute left-3 top-0 -translate-y-1/2 font-label text-[9px] tracking-[0.24em]",(d.strong,"text-[var(--ui-ink-muted)]")),children:d.label})]},`timeline-grid-${u}`))]})}function ns({fromSide:t,toSide:a,height:r,emphasized:s}){const l=oa(t),c=oa(a),m=`M ${l} 16 C ${l} ${Math.max(40,r*.26)}, ${c} ${Math.max(70,r*.72)}, ${c} ${r-18}`;return e.jsxs("svg",{viewBox:`0 0 100 ${r}`,className:"absolute inset-x-0 top-0 h-full w-full overflow-visible",preserveAspectRatio:"none",children:[e.jsx("path",{d:m,fill:"none",stroke:s?"color-mix(in srgb, var(--ui-ink-strong) 18%, transparent)":"color-mix(in srgb, var(--ui-ink-strong) 11%, transparent)",strokeWidth:s?"1.05":"0.85",strokeDasharray:s?"3 10":"2.5 12",strokeLinecap:"round"}),e.jsx("circle",{cx:l,cy:"16",r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"}),e.jsx("circle",{cx:c,cy:r-18,r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"})]})}function Lt({position:t}){return e.jsx("div",{className:w("absolute left-1/2 z-20 flex -translate-x-1/2 items-center justify-center",t==="top"?"-top-3":"-bottom-3"),children:e.jsx("div",{className:Zr})})}function ls({segment:t}){const a=(t==null?void 0:t.kind)==="stay"?t.placeLabel||t.title||null:(t==null?void 0:t.kind)==="trip"?we(t,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}).label:null,r=a||"Beginning of time";return e.jsx("div",{className:"pointer-events-none flex justify-center px-6 py-4",children:e.jsxs("div",{className:Jr,children:[e.jsx(Lt,{position:"bottom"}),e.jsxs("div",{className:"relative z-10 px-5 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(v,{tone:"signal",className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",children:"Start"}),e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Beginning of history"})]}),e.jsx("div",{className:"mt-5 font-display text-[1.25rem] tracking-normal text-[var(--ui-ink-strong)]",children:r}),e.jsx("div",{className:"mt-2 font-label text-[10px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:a?"Oldest loaded known stay":"Earliest known anchor"})]})]})})}function os(t,a,r){const s=a+Math.max(96,Math.min(r*.28,220)),l=t.items.find(c=>c.boxBottom>=s)??t.items[t.items.length-1]??null;return l?Ta(l.segment.startedAt):null}function ca({side:t,vertical:a,emphasized:r=!1}){return e.jsx("div",{className:w(es,r?"border-[color-mix(in_srgb,var(--info)_34%,transparent)]":"border-[var(--ui-border-subtle)]",t==="left"?"left-[8%]":t==="right"?"right-[8%]":"left-1/2 -translate-x-1/2",a==="top"?"top-0":"bottom-0")})}function ds({layout:t,selected:a,onToggle:r}){var u,p,g,j;const{segment:s}=t,l=Et(s),c=t.displayHeight,m=s.kind==="stay"?l?"bg-[var(--ui-info-soft)] border-[color-mix(in_srgb,var(--info)_28%,transparent)]":"bg-[var(--ui-accent-soft)] border-[color-mix(in_srgb,var(--primary)_24%,transparent)]":"",d=s.kind==="trip"?{start:we(s,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}),end:we(s,"end",{includeCoordinates:!1})}:null;return e.jsxs("div",{className:w("absolute left-0 w-full px-3 sm:px-6",a?"z-40":"z-10"),"data-testid":"movement-timeline-row","data-selected":a?"true":"false",style:{top:`${t.boxTop}px`,height:`${c}px`},children:[e.jsx("div",{className:w("absolute inset-y-0 left-1/2 w-px -translate-x-1/2",Xr)}),e.jsx("div",{className:"relative h-full",children:s.kind==="trip"?e.jsxs(ta.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:240,damping:30},className:"absolute inset-x-0 top-0 z-10 h-full",children:[d&&a?e.jsxs(e.Fragment,{children:[e.jsx(ca,{side:"center",vertical:"top",emphasized:!0}),e.jsx(ca,{side:"center",vertical:"bottom",emphasized:!0})]}):null,e.jsx(ns,{fromSide:"center",toSide:"center",height:c,emphasized:a}),e.jsxs("button",{type:"button",onClick:r,className:w(ts,"left-1/2 -translate-x-1/2",a?Dt:""),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Move"}),e.jsx("div",{className:"text-[11px] tracking-[0.18em] text-[var(--ui-ink-strong)]/44",children:qe(s.durationSeconds)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:Ie(((u=s.trip)==null?void 0:u.distanceMeters)??0)}),(((p=s.trip)==null?void 0:p.stops.length)??0)>0?e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[(g=s.trip)==null?void 0:g.stops.length," stop",((j=s.trip)==null?void 0:j.stops.length)===1?"":"s"]}):null]}),e.jsxs("div",{className:"mt-2 font-label text-[9px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:[Y(s.startedAt)," →"," ",Y(s.endedAt)]})]})]}):e.jsx(ta.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:260,damping:28},className:"absolute left-1/2 top-0 z-10 w-[min(18.5rem,calc(100vw-3.25rem))] -translate-x-1/2 sm:w-[min(21rem,calc(100vw-5rem))]",children:e.jsxs("button",{type:"button",onClick:r,className:w("group relative w-full overflow-hidden rounded-[24px] border text-left shadow-[var(--ui-shadow-soft)] transition sm:rounded-[30px]",m,a?Dt:"hover:border-[var(--ui-border-strong)]"),style:{minHeight:`${c}px`},children:[e.jsx(Lt,{position:"top"}),e.jsx(Lt,{position:"bottom"}),e.jsxs("div",{className:"relative z-10 flex h-full flex-col justify-between p-3.5 sm:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(v,{tone:"signal",className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",children:l?"Sleep":"Stay"}),e.jsx("div",{className:"text-[11px] tracking-[0.16em] text-[var(--ui-ink-muted)] sm:text-xs sm:tracking-[0.18em]",children:qe(s.durationSeconds)})]}),e.jsxs("div",{className:"mt-3 min-w-0 sm:mt-5",children:[e.jsx("div",{className:"truncate font-display text-[1rem] tracking-normal text-[var(--ui-ink-strong)] sm:text-[1.12rem]",children:ue(s)}),s.kind==="stay"&&Fe(s)&&!l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(v,{className:"max-w-full truncate bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:Fe(s)})}):l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(v,{className:w("max-w-full truncate",Da),children:s.subtitle})}):null]}),e.jsx("div",{className:"mt-auto pt-4 sm:pt-8",children:e.jsxs("div",{className:"font-label text-[9px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)] sm:text-[10px] sm:tracking-[0.22em]",children:[Y(s.startedAt)," →"," ",Y(s.endedAt)]})})]})]})})})]})}const cs="rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",it="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",nt="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",ua="text-sm leading-6 text-[var(--ui-ink-medium)]",Ne="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",ma="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",xa="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",us="bg-[var(--ui-accent-soft)] text-[var(--primary)]",ms="mt-4 rounded-[18px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[var(--ui-info-soft)] p-3",xs="text-[11px] uppercase tracking-[0.18em] text-[color-mix(in_srgb,var(--info)_70%,var(--ui-ink-strong)_30%)]",vs="mt-2 text-sm leading-6 text-[var(--ui-ink-medium)]",ps="rounded-full border border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] px-4 text-[color-mix(in_srgb,var(--info)_72%,var(--ui-ink-strong)_28%)] hover:bg-[color-mix(in_srgb,var(--info)_18%,transparent)]";function hs({segment:t,onEdit:a,onOpenDetail:r,onDefinePlace:s,onClose:l}){var d;const c=Et(t),m=Fe(t);return e.jsxs(k,{className:cs,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:c?"Sleep overlay":t.kind==="stay"?"Stay detail":t.kind==="trip"?"Move detail":"Missing data"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:ue(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{className:c?ma:t.sourceKind==="user_defined"?us:Ne,children:c?"Virtual":t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),t.overrideCount>0?e.jsxs(v,{className:xa,children:["Overrides ",t.overrideCount," automatic box",t.overrideCount===1?"":"es"]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{onClick:r,variant:"ghost",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:c,children:"Details"}),e.jsx(A,{onClick:a,variant:"ghost",className:"size-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Edit movement segment",disabled:c||t.kind==="missing"||!t.editable,children:e.jsx(It,{className:"size-4"})}),l?e.jsx("button",{type:"button",onClick:l,className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close movement segment actions",children:e.jsx($t,{className:"size-4"})}):null,e.jsx(Ft,{className:"size-4 text-[var(--ui-ink-faint)]"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.startedAt)})]}),e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.endedAt)})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:qe(t.durationSeconds)}),ct(t)?e.jsxs(e.Fragment,{children:[e.jsx(v,{className:Ne,children:Ie(t.trip.distanceMeters)}),t.trip.stops.length>0?e.jsxs(v,{className:Ne,children:[t.trip.stops.length," stop",t.trip.stops.length===1?"":"s"]}):null]}):null,c?e.jsx(v,{className:ma,children:t.subtitle}):m?e.jsx(v,{className:Ne,children:m}):null]}),le(t)&&!c?e.jsxs("div",{className:ms,children:[e.jsx("div",{className:xs,children:"Location label"}),e.jsx("div",{className:vs,children:t.stay.place?`This stay is currently linked to ${t.stay.place.label}. Search saved places or relabel it from this stay center.`:"Search saved places for this stay, or create a new one from the stay center so later matching stays inherit it automatically."}),e.jsx("div",{className:"mt-3",children:e.jsx(A,{onClick:s,variant:"ghost",className:ps,children:"Label location"})})]}):null,e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Timeline summary"}),e.jsx("div",{className:`mt-2 ${ua}`,children:t.kind==="stay"?c?`Sleep overlay from ${Y(t.startedAt)} to ${Y(t.endedAt)}. Underlying movement boxes are sliced virtually while this overlay is visible.`:`Stay block from ${Y(t.startedAt)} to ${Y(t.endedAt)}.`:t.kind==="trip"?`Connector from ${we(t,"start").label} to ${we(t,"end").label}.`:`No reliable movement signal reached Forge from ${Y(t.startedAt)} to ${Y(t.endedAt)}.`})]}),e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Projection model"}),e.jsx("div",{className:`mt-2 ${ua}`,children:c?"This sleep layer is visual only. Forge does not persist these split boxes; it temporarily slices the visible movement boxes around each sleep interval.":"Raw phone measurements stay immutable. Forge derives automatic boxes from that raw movement evidence, then overlays user-defined boxes on top without mutating the imported raw data."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(v,{className:Ne,children:["Raw stays ",t.rawStayIds.length]}),e.jsxs(v,{className:Ne,children:["Raw trips ",t.rawTripIds.length]}),e.jsxs(v,{className:Ne,children:["Raw points ",t.rawPointCount]}),t.hasLegacyCorrections?e.jsx(v,{className:xa,children:"Legacy corrections present"}):null]})]})]}),e.jsx("div",{className:"mt-5 flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ga,{className:"size-4 text-[var(--info)]"}),"Sleep overlay"]}):le(t)?e.jsxs(e.Fragment,{children:[e.jsx(fa,{className:"size-4 text-[var(--primary)]"}),((d=t.stay.place)==null?void 0:d.label)??"No canonical place linked yet"]}):ct(t)?e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"size-4 text-[var(--primary)]"}),t.trip.activityType||t.trip.travelMode]}):t.kind==="trip"?e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"size-4 text-[var(--primary)]"}),"Repaired movement connector"]}):e.jsxs(e.Fragment,{children:[e.jsx(wt,{className:"size-4 text-[var(--ui-ink-soft)]"}),"Missing intervals are synthesized from long signal gaps instead of inventing fake travel."]})})]})}function va({title:t,points:a,averagePoint:r}){const s=Lr(r?[...a,r]:a),l=r?s.length-1:s.length,c=s.slice(0,l),m=r?s[s.length-1]??null:null,d=c.map((u,p)=>`${p===0?"M":"L"} ${u.x} ${u.y}`).join(" ");return e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Relative coordinates normalized into one view so we can inspect the actual captured stay or trip geometry in one glance."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"var(--ui-surface-1)"}),c.length>1?e.jsx("path",{d,fill:"none",stroke:"var(--primary)",strokeWidth:"1.6"}):null,c.map((u,p)=>e.jsx("circle",{cx:u.x,cy:u.y,r:p===0||p===c.length-1?2.2:1.4,fill:p===0||p===c.length-1?"var(--ui-ink-strong)":"var(--primary)"},u.id)),m?e.jsxs("g",{className:"text-[var(--warning)]",children:[e.jsx("circle",{cx:m.x,cy:m.y,r:3,fill:"currentColor"}),e.jsx("circle",{cx:m.x,cy:m.y,r:6,fill:"none",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"2 2",opacity:.48})]}):null]})})]})}const _t="fixed left-1/2 z-50 -translate-x-1/2 overflow-y-auto border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] text-[var(--ui-ink)] shadow-[var(--card-shadow)] backdrop-blur-xl outline-none",La="rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",Le="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]";function gs({open:t,anchor:a,items:r,onClose:s}){if(x.useEffect(()=>{if(!t)return;const u=g=>{g.key==="Escape"&&s()},p=()=>s();return window.addEventListener("keydown",u),window.addEventListener("pointerdown",p),()=>{window.removeEventListener("keydown",u),window.removeEventListener("pointerdown",p)}},[s,t]),!t||!a||typeof document>"u")return null;const l=Math.max(12,Math.min(a.top,window.innerHeight-360)),c=Math.max(220,window.innerHeight-l-96),m=Math.min(368,window.innerWidth-24),d=Math.max(12,Math.min(a.right,window.innerWidth-m-12));return Ua.createPortal(e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[70]",children:e.jsxs("div",{className:"pointer-events-auto fixed z-[71] overflow-y-auto overscroll-contain rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] p-2 shadow-[var(--card-shadow)] backdrop-blur-xl",style:{top:`${l}px`,right:`${d}px`,width:`${m}px`,maxHeight:`${c}px`},onPointerDown:u=>u.stopPropagation(),children:[e.jsxs(me,{className:"rounded-[22px] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:"Movement actions"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Add boxes, inspect raw data, and adjust timeline overlays."})]}),e.jsx("div",{className:"mt-2 grid gap-1",children:r.map(u=>{const p=u.icon;return e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[20px] bg-[var(--ui-surface-1)] px-4 py-3 text-left text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{u.onSelect(),s()},children:[e.jsx("span",{className:"rounded-[14px] bg-[var(--ui-accent-soft)] p-2 text-[var(--primary)]",children:e.jsx(p,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:u.label}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:u.description})]})]},u.id)})})]})}),document.body)}function fs({open:t,onOpenChange:a,segment:r,detail:s,loading:l,onEdit:c,onDefinePlace:m}){var g;const d=(s==null?void 0:s.segment)??r,u=(s==null?void 0:s.stayDetail)??null,p=(s==null?void 0:s.tripDetail)??null;return e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[6vh] max-h-[88vh] w-[min(60rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:d?`${ue(d)} details`:"Movement details"}),e.jsx(xt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Inspect the canonical box, the raw movement evidence behind it, and the exact coordinates Forge used to assemble this stay or trip."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d?e.jsxs(A,{onClick:c,variant:"ghost",className:w("rounded-full px-3",Le),disabled:!d.editable||d.kind==="missing",children:[e.jsx(It,{className:"size-4"}),"Edit"]}):null,e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:w(La,"p-2"),children:e.jsx(Ft,{className:"size-4 rotate-45"})})})]})]}),l?e.jsx(me,{className:"mt-6 text-sm text-[var(--ui-ink-soft)]",children:"Loading the canonical box detail and raw movement evidence..."}):d?e.jsxs("div",{className:"mt-6 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(De,{label:"Started",value:ge(d.startedAt)}),e.jsx(De,{label:"Ended",value:ge(d.endedAt)}),e.jsx(De,{label:"Duration",value:qe(d.durationSeconds)}),e.jsx(De,{label:"Raw coverage",value:`${d.rawStayIds.length} stays · ${d.rawTripIds.length} trips · ${d.rawPointCount} points`})]}),u?e.jsxs(e.Fragment,{children:[e.jsxs(me,{className:"border-[var(--primary)]/20 bg-[var(--ui-accent-soft)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-strong)]",children:u.canonicalPlace?`This stay is linked to ${u.canonicalPlace.label}. Search a different saved place or relabel it from the stay center.`:"This stay has no saved place yet. Search known locations first, or create a new place directly from the stay center."}),e.jsx("div",{className:"mt-3",children:e.jsx(A,{onClick:m,variant:"ghost",className:w("rounded-full px-4",Le),children:"Label location"})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(va,{title:"Stay positions",points:u.positions,averagePoint:u.averagePosition}),e.jsxs(k,{className:"rounded-[28px] p-5",children:[e.jsx(pa,{title:"Stay metrics",rows:[["Canonical place",((g=u.canonicalPlace)==null?void 0:g.label)??"Not linked yet"],["Average position",u.averagePosition?st(u.averagePosition.latitude,u.averagePosition.longitude):"Unavailable"],["Radius",u.radiusMeters!=null?Ie(u.radiusMeters):"Unavailable"],["Samples",String(u.sampleCount)]]}),e.jsxs(me,{muted:!0,className:"mt-4 rounded-[18px] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Exact positions"}),e.jsx("div",{className:"mt-3 grid gap-2",children:u.positions.map((j,P)=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[j.label??`Position ${P+1}`,":"," ",st(j.latitude,j.longitude)]},`${j.recordedAt??"stay"}-${P}`))})]})]})]})]}):null,p?e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(va,{title:"Travel map",points:p.positions}),e.jsx(k,{className:"rounded-[28px] p-5",children:e.jsx(pa,{title:"Trip metrics",rows:[["Start position",p.startPosition?st(p.startPosition.latitude,p.startPosition.longitude):"Unavailable"],["End position",p.endPosition?st(p.endPosition.latitude,p.endPosition.longitude):"Unavailable"],["Distance",Ie(p.totalDistanceMeters)],["Moving time",la(p.movingSeconds)],["Idle time",la(p.idleSeconds)],["Average speed",p.averageSpeedMps!=null?`${p.averageSpeedMps.toFixed(2)} m/s`:"Unavailable"],["Max speed",p.maxSpeedMps!=null?`${p.maxSpeedMps.toFixed(2)} m/s`:"Unavailable"],["Stops",String(p.stopCount)]]})})]}):null]}):null]})]})})}function bs({open:t,segment:a,onOpenChange:r,onEdit:s,onOpenDetail:l,onDefinePlace:c}){return e.jsx(Qe,{open:t,onOpenChange:r,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:"fixed left-1/2 top-[6vh] z-50 max-h-[88vh] w-[min(36rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] outline-none",children:[e.jsx(mt,{className:"sr-only",children:a?`${ue(a)} actions`:"Movement actions"}),e.jsx(xt,{className:"sr-only",children:"Inspect, edit, or label the selected movement box."}),a?e.jsx(hs,{segment:a,onEdit:s,onOpenDetail:l,onDefinePlace:c,onClose:()=>r(!1)}):null]})]})})}function ys({open:t,onOpenChange:a,segment:r,places:s,loading:l,onSelectPlace:c,onCreatePlace:m}){const d=r?Ct(r):null,[u,p]=x.useState("");x.useEffect(()=>{if(!t){p("");return}p(Fe(r)??"")},[t,r]);const g=x.useMemo(()=>{if(!d)return[];const b=he(u);return[...s].filter(C=>b.length===0?!0:$r(C).includes(b)).sort((C,E)=>{const K=he(C.label),Z=he(E.label),z=b.length>0&&K.startsWith(b),J=b.length>0&&Z.startsWith(b);if(z!==J)return z?-1:1;const G=lt(d.latitude,d.longitude,C.latitude,C.longitude),ee=lt(d.latitude,d.longitude,E.latitude,E.longitude);return Math.abs(G-ee)>1?G-ee:C.label.localeCompare(E.label)}).slice(0,6)},[s,u,d]),j=he(u),P=g.some(b=>he(b.label)===j),U=Fe(r);return e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[8vh] max-h-[84vh] w-[min(38rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx($a,{title:"Label stay location",description:"Search saved locations by name first. If this stay is new, create a location from the stay center with latitude and longitude already filled in.",closeLabel:"Close location label dialog"}),d?e.jsxs(me,{className:"mt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"signal",children:"Stay center"}),U?e.jsx(v,{tone:"meta",children:U}):null]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[e.jsx(De,{label:"Latitude",value:d.latitude.toFixed(6)}),e.jsx(De,{label:"Longitude",value:d.longitude.toFixed(6)})]})]}):e.jsx(me,{className:"mt-5 border-[var(--warning)]/20 text-sm text-[var(--ui-ink-soft)]",children:"Forge can only label stays that already have a recorded stay center."}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(B,{value:u,onChange:b=>p(b.target.value),placeholder:"Type a location name or create a new one"}),e.jsxs(me,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:"Known places"}),l?e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"Loading saved places..."}):g.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:g.map(b=>{const C=d==null?null:lt(d.latitude,d.longitude,b.latitude,b.longitude);return e.jsxs("button",{type:"button",onClick:()=>void c(b).then(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(v,{tone:"meta",children:[Ie(C)," away"]}):null]}),b.aliases.length>0||b.categoryTags.length>0?e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:[...b.aliases,...b.categoryTags].join(" · ")}):null]},b.id)})}):e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"No saved place matches this stay yet."})]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx(A,{variant:"ghost",onClick:()=>a(!1),className:Le,children:"Cancel"}),e.jsx(A,{onClick:()=>{!r||!d||m(r,P?"":u.trim())},disabled:!r||!d,children:j.length>0&&!P?`Create "${u.trim()}"`:"Create new location"})]})]})]})})}function js({open:t,draft:a,creating:r,saving:s,preflight:l,preflightLoading:c,onDraftChange:m,onFitMissing:d,onSave:u,onOpenChange:p}){return e.jsx(Qe,{open:t,onOpenChange:p,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[8vh] w-[min(34rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx($a,{title:r?"Create movement box":"Edit movement box",description:a?r?"Create a canonical user-defined stay, move, or missing-data box without mutating raw phone measurements.":`Adjust this user-defined ${a.kind} box. Automatic boxes stay immutable and can only be invalidated.`:"No segment selected."}),a?e.jsxs("div",{className:"mt-5 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:["Kind",e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["stay","Stay"],["trip","Move"],["missing","Missing"]].map(([g,j])=>e.jsx(A,{type:"button",variant:"ghost",className:w(Le,a.kind===g?"ring-1 ring-[color-mix(in_srgb,var(--primary)_42%,transparent)]":""),onClick:()=>m({...a,kind:g}),children:j},g))})]}),e.jsx(Ke,{label:"Label",value:a.label,onChange:g=>m({...a,label:g})}),a.kind!=="trip"?e.jsx(Ke,{label:"Place",value:a.placeLabel,placeholder:"Home, Office, Riverside path...",onChange:g=>m({...a,placeLabel:g})}):null,e.jsx(Ke,{label:"Tags",value:a.tagsInput,placeholder:"movement, social, errand",onChange:g=>m({...a,tagsInput:g})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(Ke,{label:"Started",type:"datetime-local",value:a.startedAtInput,onChange:g=>m({...a,startedAtInput:g})}),e.jsx(Ke,{label:"Ended",type:"datetime-local",value:a.endedAtInput,onChange:g=>m({...a,endedAtInput:g})})]}),e.jsxs(me,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Overlap guidance"}),e.jsx(A,{type:"button",variant:"ghost",className:Le,onClick:d,disabled:!(l!=null&&l.nearestMissingStartedAt)||!(l!=null&&l.nearestMissingEndedAt),children:"Fit Missing Time"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:c?"Checking visible overlaps and missing windows...":l!=null&&l.overlapsAnything?`This box overlaps ${l.affectedAutomaticBoxIds.length} automatic and ${l.affectedUserBoxIds.length} manual boxes. Saving will fully override ${l.fullyOverriddenUserBoxIds.length} manual boxes and trim ${l.trimmedUserBoxIds.length}.`:"No overlap in the currently visible timeline window."}),e.jsxs("div",{className:"mt-3 grid gap-1 text-xs text-[var(--ui-ink-faint)]",children:[e.jsxs("div",{children:["Visible range:"," ",l!=null&&l.visibleRangeStart&&(l!=null&&l.visibleRangeEnd)?`${ge(l.visibleRangeStart)} -> ${ge(l.visibleRangeEnd)}`:"Unavailable"]}),e.jsxs("div",{children:["Suggested missing slot:"," ",l!=null&&l.nearestMissingStartedAt&&(l!=null&&l.nearestMissingEndedAt)?`${ge(l.nearestMissingStartedAt)} -> ${ge(l.nearestMissingEndedAt)}`:"No missing interval in view"]})]})]})]}):null,e.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[e.jsx(vt,{asChild:!0,children:e.jsx(A,{type:"button",variant:"ghost",className:Le,children:"Cancel"})}),e.jsxs(A,{onClick:u,disabled:!a||s,children:[e.jsx(Wa,{className:"size-4"}),s?"Saving...":r?"Create box":"Save changes"]})]})]})]})})}function $a({title:t,description:a,closeLabel:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:t}),e.jsx(xt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a})]}),e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:w(La,"p-2"),"aria-label":r,children:r?e.jsx($t,{className:"size-4"}):e.jsx(Ft,{className:"size-4 rotate-45"})})})]})}function De({label:t,value:a}){return e.jsxs(me,{className:"rounded-[18px] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:a})]})}function pa({title:t,rows:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-4 grid gap-3",children:a.map(([r,s])=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("span",{className:"text-[var(--ui-ink-faint)]",children:[r,": "]}),s]},r))})]})}function Ke({label:t,value:a,onChange:r,placeholder:s,type:l="text"}){return e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:[t,e.jsx(B,{type:l,value:a,placeholder:s,onChange:c=>r(c.target.value)})]})}function Ns({userIds:t=[]}){var Wt,Gt,Vt;const a=ya(),r=x.useRef(null),s=x.useRef(null),l=x.useRef(null),c=x.useRef(!1),m=x.useRef(!1),d=x.useRef(null),[u,p]=x.useState(null),[g,j]=x.useState(!1),[P,U]=x.useState(!1),[b,C]=x.useState(null),[E,K]=x.useState({}),[Z,z]=x.useState(null),[J,G]=x.useState(null),[ee,te]=x.useState(null),[Ve,Ee]=x.useState(null),[_e,Re]=x.useState(!1),[Ye,Se]=x.useState(!1),[ht,Me]=x.useState(null),[gt,ze]=x.useState(null),[re,W]=x.useState(!1),[se,ie]=x.useState(!1),[q,xe]=x.useState(!1),[y,Xe]=x.useState(""),[fe,Ze]=x.useState([]),[ve,Je]=x.useState(0),[O,Oe]=x.useState(0),Ae=()=>{const n=r.current;n&&(Je(n.scrollTop),Oe(n.clientHeight))},D=Yt({queryKey:["forge-movement-life-timeline",...t],initialPageParam:null,queryFn:({pageParam:n})=>Jt({before:n??void 0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),N=Yt({queryKey:["forge-movement-life-timeline-data",...t],initialPageParam:null,queryFn:({pageParam:n})=>Jt({before:n??void 0,includeInvalid:!0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),be=x.useMemo(()=>{var n;return((n=D.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[D.data]),oe=x.useMemo(()=>{var n;return((n=N.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[N.data]),de=x.useMemo(()=>{var n;return((n=D.data)==null?void 0:n.pages.reduce((o,h)=>Math.max(o,h.invalidSegmentCount??0),0))??0},[D.data]),_=x.useMemo(()=>[...be].reverse(),[be]),T=x.useMemo(()=>[...oe].reverse(),[oe]),et=x.useMemo(()=>{var o;const n=new Map;for(const h of((o=D.data)==null?void 0:o.pages)??[])for(const R of h.sleepOverlays??[])n.set(R.id,R);return[...n.values()].sort((h,R)=>new Date(h.startedAt).getTime()-new Date(R.startedAt).getTime())},[D.data]),ye=x.useMemo(()=>Tr(_,et),[_,et]),S=x.useMemo(()=>q?ye:_,[_,ye,q]),He=x.useMemo(()=>ye.filter(n=>n.syncSource==="sleep overlay"),[ye]),ne=((Wt=He.at(-1))==null?void 0:Wt.id)??null,L=x.useMemo(()=>S.find(n=>n.id===ee)??null,[ee,S]),i=x.useMemo(()=>S.find(n=>n.id===u)??null,[S,u]),f=ae({queryKey:["forge-movement-box-detail",(L==null?void 0:L.boxId)??null,...t],queryFn:async()=>L!=null&&L.boxId?(await tr(L.boxId,t)).movement:null,enabled:!!(L!=null&&L.boxId)}),Q=x.useMemo(()=>_.find(n=>n.id===Ve)??null,[Ve,_]),V=ae({queryKey:["forge-movement-places",...t],queryFn:async()=>(await Sa(t)).places,retry:!1,refetchOnWindowFocus:!1}),M=x.useMemo(()=>Vr({segments:S,viewportHeight:O}),[S,O]),pe=x.useMemo(()=>new Map(M.items.map(n=>[n.segment.id,n])),[M.items]),Ce=x.useMemo(()=>{const n=Math.max(0,ve-ia),o=ve+Math.max(O,X*8)+ia;return M.items.filter(h=>h.segment.id===u?!0:h.boxBottom>=n&&h.boxTop<=o)},[ve,u,M.items,O]),zt=x.useMemo(()=>os(M,ve,O),[ve,M,O]),Fa=()=>{var o;const n=(o=l.current)==null?void 0:o.getBoundingClientRect();if(!n){U(h=>!h);return}C({top:n.bottom+10,right:Math.max(12,window.innerWidth-n.right)}),U(h=>!h)},Ea=x.useMemo(()=>[{id:"add-box",label:"Add box",description:"Create a user-defined stay, move, or missing-data interval.",icon:Ga,onSelect:()=>G(kt("stay",_.at(-1)??null))},{id:"sleep",label:q?"Hide sleep":"Show sleep",description:"Toggle sleep overlays without rewriting the movement boxes.",icon:ga,onSelect:()=>xe(n=>{const o=!n;return o&&ne&&(p(ne),j(!0)),o})},{id:"view-data",label:"View data",description:"Open the canonical loaded records and raw-data filters.",icon:wt,onSelect:()=>W(!0)}],[ne,_,q]),Ot=(n,o="smooth")=>{const h=r.current,R=pe.get(n);if(!h||!R)return;const Be=Math.max(0,R.boxTop-h.clientHeight/2+R.displayHeight/2);if(typeof h.scrollTo=="function"){h.scrollTo({top:Be,behavior:o});return}h.scrollTop=Be};x.useEffect(()=>{re&&(!N.hasNextPage||N.isFetchingNextPage||N.fetchNextPage())},[re,N.fetchNextPage,N.hasNextPage,N.isFetchingNextPage]),x.useEffect(()=>{const n=S.at(-1);!m.current&&n&&(m.current=!0,p(n.id))},[S]),x.useEffect(()=>{if(!c.current&&S.length>0){c.current=!0,requestAnimationFrame(()=>{var o;const n=(o=S[S.length-1])==null?void 0:o.id;n&&Ot(n,"auto"),requestAnimationFrame(()=>{Ae()})});return}if(d.current&&S.length>d.current.count&&r.current){const n=d.current;d.current=null,requestAnimationFrame(()=>{const o=r.current;if(!o)return;const h=M.totalHeight-n.size;o.scrollTop+=h,Ae()})}},[S.length,M.totalHeight,pe]),x.useEffect(()=>{if(!r.current)return;const o=()=>{Ae()};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),x.useEffect(()=>{if(!u)return;const n=_.find(o=>o.id===u);n&&K(o=>o[u]?o:{...o,[u]:Tt(n)})},[_,u]),x.useEffect(()=>{var n;u&&(S.some(o=>o.id===u)||(p(((n=S.at(-1))==null?void 0:n.id)??null),j(!1)))},[S,u]),x.useEffect(()=>{if(!q||!ne)return;const n=S.findIndex(o=>o.id===ne);n<0||(p(ne),requestAnimationFrame(()=>{var h;const o=(h=S[n])==null?void 0:h.id;o&&Ot(o)}))},[S,ne,q,pe]);const ft=async()=>{await Promise.all([a.invalidateQueries({queryKey:["forge-movement-life-timeline"]}),a.invalidateQueries({queryKey:["forge-movement-life-timeline-data"]}),a.invalidateQueries({queryKey:["forge-movement-box-detail"]}),a.invalidateQueries({queryKey:["forge-movement-day"]}),a.invalidateQueries({queryKey:["forge-movement-month"]}),a.invalidateQueries({queryKey:["forge-movement-all-time"]}),a.invalidateQueries({queryKey:["forge-movement-places"]}),a.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]})])},Ht=Pe({mutationFn:async n=>{const{segment:o,draft:h,creating:R}=n,Be=Pt(h,o);if(R){await Xt(Be,t);return}if(!o)throw new Error("No movement box selected.");if(o.sourceKind!=="user_defined")throw new Error("Automatic movement boxes are immutable. Invalidate them into missing data or create a user-defined override instead.");await Zt(o.boxId,{...Be,metadata:{updatedFrom:"movement-life-timeline"}},t)},onSuccess:ft}),_a=async(n,o)=>{if(n.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");const h=zr(n,o.label);if(n.sourceKind==="user_defined"){await Zt(n.boxId,{...h,metadata:{updatedFrom:"movement-life-timeline-place-label"}},t);return}await Xt({...h,metadata:{createdFrom:"movement-life-timeline-place-label"}},t)},Bt=async(n,o)=>{if(n.rawStayIds.length===0)throw new Error("This stay has no raw stay ids to relabel.");await Promise.all(n.rawStayIds.map(h=>er(h,{placeExternalUid:o.externalUid,placeLabel:o.label})))},Ra=(n,o)=>{const h=Ct(n);if(!h)return!0;const R=lt(h.latitude,h.longitude,o.latitude,o.longitude);return R<=100||typeof window>"u"||typeof window.confirm!="function"?!0:window.confirm(`"${o.label}" is ${Ie(R)} away from this stay's recorded center. Link it anyway?`)},za=Pe({mutationFn:async n=>{const{segment:o,...h}=n,R=await ja(h,t);return o&&le(o)&&await Bt(o,R.place),R},onSuccess:ft}),Oa=Pe({mutationFn:async n=>{const{segment:o,place:h}=n;if(!Ra(o,h))return{assigned:!1};if(le(o))return await Bt(o,h),{assigned:!0};if(o.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");return await _a(o,h),{assigned:!0}},onSuccess:async n=>{n.assigned&&await ft()}}),bt=Pe({mutationFn:async n=>{if(n.sourceKind==="user_defined"){await Za(n.boxId,t);return}await Ja(n.boxId,{title:"User invalidated automatic movement",subtitle:`Overrides ${ue(n)} with missing data.`},t)},onSuccess:async(n,o)=>{p(h=>h===o.id?null:h),j(!1),z(h=>h===o.id?null:h),a.setQueryData(["forge-movement-life-timeline",...t],h=>da(h,o.id)),a.setQueryData(["forge-movement-life-timeline-data",...t],h=>da(h,o.id)),await Promise.all([a.invalidateQueries({queryKey:["forge-movement-life-timeline"]}),a.invalidateQueries({queryKey:["forge-movement-life-timeline-data"]}),a.invalidateQueries({queryKey:["forge-movement-day"]}),a.invalidateQueries({queryKey:["forge-movement-month"]}),a.invalidateQueries({queryKey:["forge-movement-all-time"]}),a.invalidateQueries({queryKey:["forge-movement-selection"]}),a.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]})])}}),Ha=x.useMemo(()=>Hr(T),[T]),je=x.useMemo(()=>{const n=he(y);return[...T].sort((o,h)=>new Date(h.endedAt).getTime()-new Date(o.endedAt).getTime()).filter(o=>(n.length===0||Or(o).includes(n))&&Br(o,fe))},[T,y,fe]),Kt=x.useMemo(()=>T.length===0?"No movement records loaded yet.":je.length===T.length&&y.trim().length===0&&fe.length===0?`${T.length} loaded movement records visible`:`${je.length} of ${T.length} loaded records visible`,[T.length,je.length,y,fe.length]),yt=ba({count:je.length,getScrollElement:()=>s.current,estimateSize:()=>136,overscan:8}),$=Z?_.find(n=>n.id===Z)??null:null,Ba=$?E[$.id]??Tt($):null,tt=J!==null,F=J??Ba,qt=((Gt=_[0])==null?void 0:Gt.startedAt)??null,Qt=((Vt=_[_.length-1])==null?void 0:Vt.endedAt)??null,jt=ae({queryKey:["forge-movement-user-box-preflight",($==null?void 0:$.boxId)??"create",(F==null?void 0:F.kind)??null,(F==null?void 0:F.startedAtInput)??null,(F==null?void 0:F.endedAtInput)??null,qt,Qt,...t],enabled:F!==null&&dt(F.startedAtInput)!==null&&dt(F.endedAtInput)!==null,queryFn:async()=>{if(!F)return null;const n=Pt(F,$);return(await ar({...n,excludeBoxId:($==null?void 0:$.sourceKind)==="user_defined"?$.boxId:null,rangeStart:qt,rangeEnd:Qt},t)).preflight}}),Ut=n=>{le(n)&&(Ee(n.id),Re(!0))},Ka=(n,o)=>{const h=Ct(n);h&&(Re(!1),Ee(n.id),Me({...h,label:o.trim()||h.label}),ze(n.id),Se(!0))},qa=()=>{const n=r.current;n&&(Je(n.scrollTop),Oe(n.clientHeight),!(!D.hasNextPage||D.isFetchingNextPage)&&n.scrollTop<=960&&(d.current={count:S.length,size:M.totalHeight},D.fetchNextPage()))};if(D.isPending)return e.jsx(Na,{eyebrow:"Movement",title:"Loading life timeline",description:"Reconstructing the longer road of stays, moves, and places.",columns:1,blocks:6});if(D.isError)return e.jsx(ka,{eyebrow:"Movement",error:D.error,onRetry:()=>void D.refetch()});const Qa=M.totalHeight;return e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(k,{className:"overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-3 sm:rounded-[34px] sm:p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 px-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:"Movement"}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-2",children:[de>0?e.jsxs(v,{className:w("hidden sm:inline-flex",Te),children:[de," invalid hidden"]}):null,e.jsxs(v,{className:"hidden bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] sm:inline-flex",children:[S.length," visible"]}),e.jsx("div",{ref:l,children:e.jsxs(A,{type:"button",variant:"ghost",size:"sm","aria-expanded":P,"aria-haspopup":"dialog",className:w("h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",P?Dt:""),onClick:Fa,children:[e.jsx(Va,{className:"size-4"}),"Actions"]})})]})]}),e.jsx(gs,{open:P,anchor:b,items:Ea,onClose:()=>U(!1)}),q&&He.length===0?e.jsx("p",{className:"mb-3 px-1 text-sm text-[color-mix(in_srgb,var(--warning)_72%,var(--ui-ink-strong)_28%)]",children:"No sleep session overlaps the currently loaded timeline range yet. Scroll further back to load older history."}):null,e.jsxs("div",{ref:r,onScroll:qa,className:"relative h-[82vh] overflow-auto rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)]",children:[e.jsx(is,{layout:M,scrollTop:ve,viewportHeight:O}),zt?e.jsx("div",{className:"pointer-events-none sticky top-3 z-50 flex h-0 justify-center",children:e.jsx("div",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1.5 font-label text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-medium)] shadow-[var(--ui-shadow-soft)] backdrop-blur-xl",children:zt})}):null,e.jsxs("div",{className:"relative",style:{height:`${Qa}px`},children:[M.historyHeaderHeight>0?e.jsx("div",{className:"absolute inset-x-0 top-0",style:{height:`${M.historyHeaderHeight}px`},children:e.jsx(ls,{segment:S[0]??null})}):null,Ce.map(n=>{const o=n.segment;return e.jsx(ds,{layout:n,selected:u===o.id,onToggle:()=>{p(o.id),j(!0)}},o.id)})]})]})]}),e.jsx(js,{open:$!==null||J!==null,segment:$,draft:F,creating:tt,saving:Ht.isPending,preflight:jt.data??null,preflightLoading:jt.isFetching,onDraftChange:n=>{if(tt){G(n);return}$&&K(o=>({...o,[$.id]:n}))},onFitMissing:()=>{const n=jt.data;if(!(n!=null&&n.nearestMissingStartedAt)||!n.nearestMissingEndedAt)return;const o={...F??kt("stay",$),startedAtInput:$e(n.nearestMissingStartedAt),endedAtInput:$e(n.nearestMissingEndedAt)};if(tt){G(o);return}$&&K(h=>({...h,[$.id]:o}))},onSave:()=>{F&&Ht.mutateAsync({segment:$,draft:F,creating:tt},{onSuccess:()=>{z(null),G(null),se&&(ie(!1),W(!0))}})},onOpenChange:n=>{n||(z(null),G(null),se&&(ie(!1),W(!0)))}}),e.jsx(bs,{open:g&&i!==null,onOpenChange:n=>{j(n)},segment:i,onEdit:()=>{i!=null&&i.editable&&(z(i.id),j(!1))},onOpenDetail:()=>{i&&(te(i.id),j(!1))},onDefinePlace:()=>{i&&(Ut(i),j(!1))}}),e.jsx(fs,{open:L!==null,onOpenChange:n=>{n||te(null)},segment:L,detail:f.data??null,loading:f.isFetching,onEdit:()=>{!L||!L.editable||(z(L.id),te(null))},onDefinePlace:()=>{L&&Ut(L)}}),e.jsx(ys,{open:_e,onOpenChange:n=>{Re(n),n||Ee(null)},segment:Q,places:V.data??[],loading:V.isFetching,onSelectPlace:async n=>Q?(await Oa.mutateAsync({segment:Q,place:n})).assigned:!1,onCreatePlace:(n,o)=>{Ka(n,o)}}),e.jsx(Aa,{open:Ye,onOpenChange:n=>{Se(n),n||(Me(null),ze(null))},place:null,seed:ht,onSave:async n=>{await za.mutateAsync({...n,segment:_.find(o=>o.id===gt)??null})}}),e.jsx(wa,{open:re,onOpenChange:n=>{W(n),n||se||(Xe(""),Ze([]))},eyebrow:"Movement data",title:"View data",description:"",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ma,{title:"",description:"",query:y,onQueryChange:Xe,options:Ha,selectedOptionIds:fe,onSelectedOptionIdsChange:Ze,resultSummary:Kt,placeholder:"Search movement labels, places, times, tags, or add time and kind filters",emptyStateMessage:"Keep typing or pick filters to narrow the movement history."}),e.jsxs(k,{className:"grid min-w-0 gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Canonical boxes"}),e.jsx("div",{className:"max-w-3xl break-words text-sm leading-6 text-[var(--ui-ink-muted)]",children:"This list shows the canonical movement boxes projected by Forge. Automatic boxes are derived from immutable raw phone measurements. User-defined boxes override the projection without mutating raw movement data."})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)]",onClick:()=>{ie(!0),W(!1),G(kt("stay",je.at(-1)??null))},children:"Add box"}),e.jsx(v,{tone:"meta",children:Kt}),de>0?e.jsxs(v,{className:Te,children:[de," invalid hidden included"]}):null,N.hasNextPage?e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)]",pending:N.isFetchingNextPage,pendingLabel:"Loading…",onClick:()=>void N.fetchNextPage(),children:"Load older"}):null]})]}),e.jsx("div",{ref:s,className:"h-[36rem] overflow-y-auto rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:je.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No movement record matches the current search. Clear filters or load older timeline history."}):e.jsx("div",{className:"relative w-full",style:{height:`${yt.getTotalSize()}px`},children:yt.getVirtualItems().map(n=>{var h;const o=je[n.index];return e.jsx("div",{ref:yt.measureElement,"data-index":n.index,className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${n.start}px)`},children:e.jsxs("div",{className:"flex items-start gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left transition hover:opacity-100",onClick:()=>{o.editable&&(ie(!0),W(!1),z(o.id))},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[o.kind==="stay"?e.jsx(fa,{className:"size-3.5 shrink-0 text-[var(--primary)]"}):o.kind==="missing"?e.jsx(wt,{className:"size-3.5 shrink-0 text-[var(--ui-ink-medium)]"}):e.jsx(ot,{className:"size-3.5 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-sm font-medium",children:ue(o)})]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--ui-ink-muted)]",children:[ut(o.startedAt)," →"," ",ut(o.endedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1.5",children:[e.jsx(v,{tone:o.kind==="trip"?"signal":"meta",children:o.kind==="trip"?"Move":o.kind==="missing"?"Missing":"Stay"}),e.jsx(v,{className:o.sourceKind==="user_defined"?"bg-[var(--ui-accent-soft)] text-[var(--primary)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:o.sourceKind==="user_defined"?o.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),e.jsx(v,{tone:"meta",children:qe(o.durationSeconds)}),o.origin==="continued_stay"?e.jsx(v,{className:Da,children:"Continued stay"}):null,o.origin==="repaired_gap"?e.jsx(v,{className:Te,children:"Repaired"}):null,o.kind==="missing"?e.jsx(v,{className:as,children:"Missing"}):null,o.isInvalid?e.jsx(v,{className:Te,children:"Invalid"}):null,o.placeLabel?e.jsx(v,{tone:"default",children:o.placeLabel}):null,o.overrideCount>0?e.jsxs(v,{className:Te,children:["Overrides ",o.overrideCount]}):null,e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw stays ",o.rawStayIds.length]}),e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw trips ",o.rawTripIds.length]}),e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw points ",o.rawPointCount]}),o.hasLegacyCorrections?e.jsx(v,{className:Te,children:"Legacy corrections"}):null]})]})}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:w("h-8 shrink-0 rounded-full border px-2.5",o.sourceKind==="user_defined"?rs:ss),pending:bt.isPending&&((h=bt.variables)==null?void 0:h.id)===o.id,pendingLabel:"",onClick:()=>{window.confirm(o.sourceKind==="user_defined"?`Delete ${ue(o)} and remove this user-defined box from every synced surface?`:`Invalidate ${ue(o)} into missing data and hide the automatic box everywhere?`)&&bt.mutateAsync(o)},children:e.jsx(Ya,{className:"size-3.5"})})]})},`${o.kind}:${o.id}:${o.startedAt}:${o.endedAt}:${n.index}`)})})})]})]})})]})}function ks(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}).format(new Date(t))}function ws(t,a){const r=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${r.format(new Date(t))} - ${r.format(new Date(a))}`}function H(t){return t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.round(t/60)}m`}function ke(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Ss(t,a){return t==="distanceMeters"?ke(a):t==="caloriesKcal"?`${Math.round(a)} kcal`:H(a)}function Ia(t){return t.trim().toLowerCase()}function pt(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function Rt(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ms(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function ha(t){return{recordedAt:Ms(t.recordedAt),latitude:String(t.latitude),longitude:String(t.longitude),accuracyMeters:t.accuracyMeters!=null?String(t.accuracyMeters):"",altitudeMeters:t.altitudeMeters!=null?String(t.altitudeMeters):"",speedMps:t.speedMps!=null?String(t.speedMps):"",isStopAnchor:t.isStopAnchor}}function As(t){return Ia([Rt(t.recordedAt),t.externalUid,t.isStopAnchor?"stop anchor stop":"path trace point",t.accuracyMeters!=null?`${Math.round(t.accuracyMeters)} meters accuracy`:"",pt(t.recordedAt)].join(" "))}function Cs(t){const a=new Map;return a.set("anchor:stop",{id:"anchor:stop",label:"Stop anchors",description:"Only the canonical pause anchors",badge:e.jsx(v,{tone:"meta",children:"Stop anchors"})}),a.set("anchor:path",{id:"anchor:path",label:"Path points",description:"Non-anchor trace points",badge:e.jsx(v,{tone:"meta",children:"Path points"})}),a.set("accuracy:precise",{id:"accuracy:precise",label:"Precise",description:"GPS accuracy below 20m",badge:e.jsx(v,{tone:"meta",children:"Precise"})}),a.set("accuracy:loose",{id:"accuracy:loose",label:"Loose accuracy",description:"GPS accuracy at or above 20m",badge:e.jsx(v,{tone:"meta",children:"Loose accuracy"})}),t.forEach(r=>{const s=pt(r.recordedAt);a.has(`time:${s}`)||a.set(`time:${s}`,{id:`time:${s}`,label:s,description:"Recorded during this time band",badge:e.jsx(v,{tone:"meta",className:"capitalize",children:s})})}),[...a.values()]}function Ts(t,a){return a.every(r=>r==="anchor:stop"?t.isStopAnchor:r==="anchor:path"?!t.isStopAnchor:r==="accuracy:precise"?t.accuracyMeters!=null&&t.accuracyMeters<20:r==="accuracy:loose"?t.accuracyMeters==null||t.accuracyMeters>=20:r.startsWith("time:")?pt(t.recordedAt)===r.slice(5):!0)}function Ps(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),r=Math.max(...t.map(d=>d.latitude)),s=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(r-a,1e-4),m=Math.max(l-s,1e-4);return t.map(d=>({x:12+(d.longitude-s)/m*76,y:12+(1-(d.latitude-a)/c)*76}))}function Ds({curve:t,startLabel:a,endLabel:r,stopLabels:s}){const l=t.map((c,m)=>`${m===0?"M":"Q"} ${c.x} ${c.y}`).join(" ");return e.jsxs(k,{className:"overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Stylized trajectory"}),e.jsx(ce,{content:"This graph is a softened trip trace. It emphasizes rhythm, stops, and endpoints instead of raw GPS jitter."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"A softened path that prioritizes rhythm, stops, and landmarks over raw map noise."})]}),e.jsxs(v,{tone:"signal",children:[a," → ",r]})]}),e.jsxs("div",{className:"mt-5 rounded-[26px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("svg",{viewBox:"0 0 100 60",className:"h-48 w-full",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"movementGlow",children:[e.jsx("feGaussianBlur",{stdDeviation:"1.8",result:"blur"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"blur"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),e.jsx("path",{d:l,fill:"none",stroke:"var(--ui-ink-medium)",strokeWidth:"1.5",strokeDasharray:"2.8 2.8",filter:"url(#movementGlow)"}),t.map((c,m)=>e.jsx("g",{children:e.jsx("circle",{cx:c.x,cy:c.y,r:m===0||m===t.length-1?2.6:1.6,fill:m===0||m===t.length-1?"var(--ui-ink-strong)":"var(--info)"})},`${c.x}-${c.y}-${m}`))]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:s.map(c=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:c},c))})]})]})}function Ls({points:t}){const a=Ps(t),r=a.map((s,l)=>`${l===0?"M":"L"} ${s.x} ${s.y}`).join(" ");return e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Exact path"}),e.jsx(ce,{content:"This keeps the recent raw location points. Use it when you want the literal recorded trace instead of the cleaned movement graph."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"Recent raw points preserved by the companion before long-term simplification."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"var(--ui-surface-2)"}),e.jsx("path",{d:r,fill:"none",stroke:"var(--info)",strokeWidth:"1.6"}),a.map((s,l)=>e.jsx("circle",{cx:s.x,cy:s.y,r:l===0||l===a.length-1?2:1.1,fill:l===0||l===a.length-1?"var(--ui-ink-strong)":"var(--info)"},`${s.x}-${s.y}-${l}`))]})})]})}function $s({point:t,draft:a}){return e.jsxs(k,{className:"grid gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Raw datapoint"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Rt(t.recordedAt)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Raw phone measurements are immutable in product UI. To change the visible movement story, create or edit user-defined boxes in the Life Timeline instead."})]}),e.jsx(v,{tone:t.isStopAnchor?"signal":"meta",children:t.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Recorded at"}),e.jsx(B,{type:"datetime-local",value:a.recordedAt,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Speed (m/s)"}),e.jsx(B,{value:a.speedMps,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Latitude"}),e.jsx(B,{value:a.latitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Longitude"}),e.jsx(B,{value:a.longitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Accuracy (m)"}),e.jsx(B,{value:a.accuracyMeters,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Altitude (m)"}),e.jsx(B,{value:a.altitudeMeters,disabled:!0,placeholder:"Optional"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(A,{variant:"ghost",className:w("h-10 rounded-full border px-4",a.isStopAnchor?"border-[var(--primary)] bg-[var(--primary)]/16 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),disabled:!0,children:[e.jsx(ot,{className:"mr-2 size-4"}),a.isStopAnchor?"Stop anchor":"Path point"]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:["External id: ",e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:t.externalUid})]})]}),e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"This browser is read-only now. Raw points stay immutable so the web app and iPhone can both project the same repaired canonical boxes from the backend."})]})}function Vs(){var ye,S,He,ne,L;const t=rr(),a=ya(),r=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[s,l]=x.useState("life"),[c,m]=x.useState(new Date().toISOString().slice(0,10)),[d,u]=x.useState(new Date().toISOString().slice(0,7)),[p,g]=x.useState(null),[j,P]=x.useState(!1),[U,b]=x.useState(!1),[C,E]=x.useState(""),[K,Z]=x.useState([]),[z,J]=x.useState(null),[G,ee]=x.useState(null),[te,Ve]=x.useState({stayIds:[],tripIds:[]}),[Ee,_e]=x.useState(!1),[Re,Ye]=x.useState(null),[Se,ht]=x.useState(""),[Me,gt]=x.useState("distanceMeters"),ze=x.useRef(null),re=ae({queryKey:["forge-movement-day",c,...r],queryFn:async()=>(await nr({date:c,userIds:r})).movement}),W=ae({queryKey:["forge-movement-month",d,...r],queryFn:async()=>(await lr({month:d,userIds:r})).movement}),se=ae({queryKey:["forge-movement-all-time",...r],queryFn:async()=>(await or(r)).movement}),ie=ae({queryKey:["forge-life-force",...r],queryFn:async()=>(await dr(r)).lifeForce}),q=ae({queryKey:["forge-movement-settings",...r],queryFn:async()=>(await cr(r)).settings}),xe=ae({queryKey:["forge-movement-places",...r],queryFn:async()=>(await Sa(r)).places}),y=ae({queryKey:["forge-movement-trip",p],queryFn:async()=>p?(await ur(p)).movement:null,enabled:!!p}),Xe=ae({queryKey:["forge-movement-selection",c,te.stayIds.join(","),te.tripIds.join(","),...r],queryFn:async()=>(await mr({...te,userIds:r})).movement,enabled:te.stayIds.length>0||te.tripIds.length>0}),fe=Pe({mutationFn:async i=>sr({trackingEnabled:i},r),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-settings"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]})}}),Ze=Pe({mutationFn:async i=>i.id?ir(i.id,i):ja(i,r),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-places"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]}),await a.invalidateQueries({queryKey:["forge-movement-all-time"]})}}),ve=x.useMemo(()=>{const i=xe.data??[],f=Se.trim().toLowerCase();return f?i.filter(Q=>[Q.label,...Q.aliases,...Q.categoryTags].join(" ").toLowerCase().includes(f)):i},[Se,xe.data]),Je=x.useMemo(()=>{var i;return Cs(((i=y.data)==null?void 0:i.trip.points)??[])},[(ye=y.data)==null?void 0:ye.trip.points]),O=x.useMemo(()=>{var Q;const i=((Q=y.data)==null?void 0:Q.trip.points)??[],f=Ia(C);return[...i].sort((V,M)=>new Date(M.recordedAt).getTime()-new Date(V.recordedAt).getTime()).filter(V=>(f.length===0||As(V).includes(f))&&Ts(V,K))},[C,K,(S=y.data)==null?void 0:S.trip.points]),Oe=x.useMemo(()=>{var f;const i=((f=y.data)==null?void 0:f.trip.points.length)??0;return i===0?"No raw datapoints on this trip yet.":O.length===i&&C.trim().length===0&&K.length===0?`${i} datapoints visible`:`${O.length} of ${i} datapoints visible`},[O.length,C,K.length,(He=y.data)==null?void 0:He.trip.points.length]),Ae=ba({count:O.length,getScrollElement:()=>ze.current,estimateSize:()=>96,overscan:8}),D=O.find(i=>i.id===z)??((ne=y.data)==null?void 0:ne.trip.points.find(i=>i.id===z))??O[0]??((L=y.data)==null?void 0:L.trip.points[0])??null;if(x.useEffect(()=>{if(U){if(!D){J(null),ee(null);return}J(D.id),ee(ha(D))}},[D,U]),x.useEffect(()=>{E(""),Z([]),J(null),ee(null),b(!1)},[p]),re.isLoading||W.isLoading||se.isLoading||q.isLoading||xe.isLoading)return e.jsx(Na,{eyebrow:"Movement",title:"Loading movement workspace",description:"Reconstructing stays, trips, and place intelligence across Forge.",columns:2,blocks:8});if(re.isError||W.isError||se.isError||q.isError||xe.isError||!re.data||!W.data||!se.data||!q.data)return e.jsx(ka,{eyebrow:"Movement",error:re.error??W.error??se.error??q.error??xe.error??new Error("Movement data unavailable"),onRetry:()=>{re.refetch(),W.refetch(),se.refetch(),q.refetch(),xe.refetch()}});const N=re.data,be=W.data,oe=se.data,de=q.data,_=N.segments.filter((i,f,Q)=>{const V=`${i.kind}:${i.id}:${i.startedAt}:${i.endedAt}`;return Q.findIndex(M=>`${M.kind}:${M.id}:${M.startedAt}:${M.endedAt}`===V)===f}),T=Xe.data??N.selectionAggregate,et=N.trips.reduce((i,f)=>i+at(f).totalAp,0);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(xr,{entityKind:"project",title:"Movement",description:"Turn passive place and travel signals into a real Forge domain: day rhythm, travel arcs, known landmarks, linked work, and reflective evidence.",badge:`${N.summary.tripCount} trips today`,actions:e.jsx("div",{className:"flex flex-wrap gap-2",children:["life","day","month","all_time"].map(i=>e.jsx(A,{variant:"ghost",className:w("h-9 rounded-full border px-4 text-sm",s===i?"border-[var(--primary)] bg-[var(--primary)]/16 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),onClick:()=>l(i),children:i==="all_time"?"All time":i==="life"?"Life":i.charAt(0).toUpperCase()+i.slice(1)},i))})}),e.jsxs(k,{className:"grid gap-3 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Movement AP today"}),e.jsx("div",{className:"mt-2 text-3xl font-semibold text-[var(--ui-ink-strong)]",children:ea(et)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Trips and transitions now contribute to the same Action Point ledger as work, habits, and notes."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Typical trip drain"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:N.trips[0]?rt(at(N.trips[0]).rateApPerHour):"0 AP/h"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Movement uses a MET-like drain under the hood, translated into Forge Action Points."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Life Force sync"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:ie.data?`${Math.round(ie.data.spentTodayAp??0)}/${Math.round(ie.data.dailyBudgetAp??0)} AP`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:ie.data?`${rt(ie.data.instantFreeApPerHour)} free right now`:"Movement can now be read against today’s live capacity."})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.65fr)_minmax(20rem,0.95fr)]",children:[e.jsx(vr,{children:e.jsxs(k,{className:"overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Movement operating mode"}),e.jsx(ce,{content:"This is the passive capture state of the movement system: whether tracking is running, how much is published into Forge, and how aggressive retention is."})]}),e.jsx("div",{className:"mt-2 text-[clamp(1.05rem,1.8vw,1.35rem)] text-[var(--ui-ink-strong)]",children:"Background stays and trips as structured life evidence"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The companion samples quietly while stationary, switches to denser trip capture when you move, and keeps only simplified long-term traces."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:de.trackingEnabled?"Tracking on":"Tracking off"}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:de.publishMode.replaceAll("_"," ")}),e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4",onClick:()=>fe.mutate(!de.trackingEnabled),children:de.trackingEnabled?"Pause passive capture":"Enable passive capture"})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Distance today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:ke(N.summary.totalDistanceMeters)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Across trips, stops, and linked place changes."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Idle time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.totalIdleSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Time spent settled enough to count as a real stay."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Estimated phone time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.estimatedScreenTimeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Estimated from hourly Screen Time bins, not exact foreground traces."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:N.summary.knownPlaceCount}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Shared between Forge and the iPhone companion."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Missing data"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.missingDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.missingCount," grey gap",N.summary.missingCount===1?"":"s"," where Forge had over one hour without enough movement signal."]})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Repaired gaps"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.repairedGapDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.repairedGapCount," inferred span",N.summary.repairedGapCount===1?"":"s"," classified as stay or move instead of leaving blank holes in the day."]})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Continued stays"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.continuedStayDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.continuedStayCount," short stationary span",N.summary.continuedStayCount===1?"":"s"," carried forward so quiet home time stays continuous instead of disappearing."]})]})]})]})}),e.jsx(pr,{children:e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Selection aggregate"}),e.jsx(ce,{content:"When you select stays or trips, Forge totals their span, distance, work overlap, notes, and places here."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Select any combination of stays and trips to sum movement, time, and work evidence."}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Span"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.durationSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:ke(T.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Work overlap"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.trackedWorkSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.noteCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Estimated phone time"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.pickupCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.notificationCount})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:T.placeLabels.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i},i))}),T.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:T.topApps.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-info-soft)] text-[var(--ui-ink-medium)]",children:(i.displayName||i.bundleIdentifier)+" · "+H(i.totalActivitySeconds)},i.id))}):null,T.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:T.topCategories.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.categoryLabel},i.id))}):null]})})]}),s==="life"?e.jsx(hr,{children:e.jsxs("section",{className:"grid gap-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Life graph"}),e.jsx(ce,{content:"This graph shows the movement road of your life: stays are blocks, moves connect them, and the hour/day lines live in the background. Click a segment for details, then use edit when you want to correct it."})]})}),e.jsx(Ns,{userIds:r})]})}):null,s==="day"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.55fr)_minmax(22rem,1fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Day strip"}),e.jsx(ce,{content:"A compressed 24-hour strip. Each segment keeps its true order and duration, but the whole day stays navigable on one line."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"A single-row timeline from 00:00 to 24:00, always compressed into one navigable strip."})]}),e.jsx(B,{type:"date",value:c,onChange:i=>m(i.target.value),className:"w-[11rem]"})]}),e.jsx("div",{className:"mt-6 overflow-x-auto pb-2",children:e.jsxs("div",{className:"w-full min-w-full sm:min-w-[52rem]",children:[e.jsx("div",{className:"mb-3 flex justify-between text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:["00:00","06:00","12:00","18:00","24:00"].map(i=>e.jsx("span",{children:i},i))}),e.jsx("div",{className:"flex h-28 items-stretch overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2",children:_.map((i,f)=>{const Q=Math.max(9,i.durationSeconds/86400*100),V=i.kind==="stay"?te.stayIds.includes(i.id):i.kind==="trip"?te.tripIds.includes(i.id):!1;return e.jsxs("button",{type:"button",className:w("relative flex min-w-0 flex-col justify-between rounded-[22px] border px-3 py-2 text-left transition sm:min-w-[5.5rem]",i.kind==="missing"?"border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":V?"border-[color-mix(in_srgb,var(--info)_34%,transparent)] bg-[var(--ui-info-soft)]":"border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]"),style:{width:`${Q}%`},onClick:()=>{i.kind!=="missing"&&Ve(M=>{const pe=new Set(M.stayIds),Ce=new Set(M.tripIds);return i.kind==="stay"?pe.has(i.id)?pe.delete(i.id):pe.add(i.id):Ce.has(i.id)?Ce.delete(i.id):(Ce.add(i.id),g(i.id)),{stayIds:[...pe],tripIds:[...Ce]}})},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(v,{tone:i.kind==="trip"?"signal":i.kind==="missing"?"meta":"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.kind==="missing"?"gap":i.kind}),e.jsx("span",{className:"text-[11px] text-[var(--ui-ink-muted)]",children:H(i.durationSeconds)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"line-clamp-2 text-sm font-semibold text-[var(--ui-ink-strong)]",children:i.label}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-muted)]",children:i.subtitle})]})]},`${i.kind}:${i.id}:${i.startedAt}:${i.endedAt}:${f}`)})})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:ks(c)}),e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[N.summary.tripCount," trips"]}),e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[N.summary.stayCount," stays"]}),e.jsxs(v,{tone:"meta",children:[N.summary.missingCount," gaps"]})]})]}),e.jsx("div",{className:"grid gap-4",children:y.data?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Selected trip"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4",onClick:()=>P(i=>!i),children:j?"Stylized graph":"Exact path"})})]}),j?e.jsx(Ls,{points:y.data.trip.points}):e.jsx(Ds,{curve:y.data.stylizedPath.curve,startLabel:y.data.stylizedPath.startLabel,endLabel:y.data.stylizedPath.endLabel,stopLabels:y.data.stylizedPath.stops.map(i=>i.label)}),e.jsxs(k,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Trip context"}),(()=>{const i=at(y.data.trip);return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:ke(y.data.trip.distanceMeters)}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:y.data.trip.activityType||y.data.trip.travelMode}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:H(y.data.trip.durationSeconds)}),e.jsx(v,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:rt(i.rateApPerHour)}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:ea(i.totalAp)})]})})})(),e.jsx("div",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:ws(y.data.trip.startedAt,y.data.trip.endedAt)}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Hourly estimate"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(y.data.trip.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y.data.trip.pickupCount})]}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y.data.trip.notificationCount})]})]}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-[var(--ui-ink-muted)]",children:"Derived from Screen Time hourly bins, not exact foreground traces."}),y.data.trip.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:y.data.trip.topApps.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-info-soft)] text-[var(--ui-ink-medium)]",children:(i.displayName||i.bundleIdentifier)+" · "+H(i.totalActivitySeconds)},i.id))}):null,y.data.trip.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:y.data.trip.topCategories.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.categoryLabel},i.id))}):null]})]}):e.jsx(k,{className:"rounded-[30px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-6 text-[var(--ui-ink-muted)]",children:"Select a trip segment to open the stylized trajectory card and exact path toggle."})})]}):null,s==="month"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(18rem,0.85fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Month view"}),e.jsx(ce,{content:"This chart stays quantitative. Switch the metric to compare daily distance, moving time, idle time, or calories across the month."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Switch the Y-axis between motion, idle time, and energy without losing the same monthly frame."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(B,{type:"month",value:d,onChange:i=>u(i.target.value),className:"w-[10.5rem]"}),["distanceMeters","movingSeconds","idleSeconds","caloriesKcal"].map(i=>e.jsx(A,{variant:"ghost",className:w("h-9 rounded-full border px-4 text-sm",Me===i?"border-[var(--primary)] bg-[var(--primary)]/14 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),onClick:()=>gt(i),children:i==="distanceMeters"?"Distance":i==="movingSeconds"?"Moving":i==="idleSeconds"?"Idle":"Calories"},i))]})]}),e.jsx("div",{className:"mt-6 h-[24rem]",children:e.jsx(br,{width:"100%",height:"100%",children:e.jsxs(yr,{data:be.days,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"movementMonthFill",x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--info)",stopOpacity:.7}),e.jsx("stop",{offset:"100%",stopColor:"var(--info)",stopOpacity:.08})]})}),e.jsx(jr,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(Nr,{dataKey:"dateKey",tick:{fill:"var(--ui-ink-muted)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(kr,{tick:{fill:"var(--ui-ink-muted)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(wr,{contentStyle:{background:"var(--ui-surface-modal)",border:"1px solid var(--ui-border-subtle)",borderRadius:16},itemStyle:{color:"var(--ui-ink-strong)"},labelStyle:{color:"var(--ui-ink-medium)"},formatter:i=>Ss(Me,Number(i))}),e.jsx(Sr,{type:"monotone",dataKey:Me,stroke:"var(--info)",fill:"url(#movementMonthFill)",strokeWidth:2.4})]})})})]}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Month totals"}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:ke(be.totals.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Moving time"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:H(be.totals.movingSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Settled time"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:H(be.totals.idleSeconds)})]})]})]})]}):null,s==="all_time"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(20rem,0.95fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Trips"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.tripCount})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.knownPlaceCount})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:ke(oe.summary.totalDistanceMeters)})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Countries"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.visitedCountries})]})]}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:oe.recentTrips.map(i=>e.jsx("button",{type:"button",className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-left transition hover:bg-[var(--ui-surface-3)]",onClick:()=>{l("day"),g(i.id)},children:(()=>{const f=at({startedAt:i.startedAt,endedAt:new Date(new Date(i.startedAt).getTime()+36e5).toISOString(),expectedMet:2});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent travel"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:i.label||"Untitled trip"}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[ke(i.distanceMeters)," · ",i.activityType||"travel"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(v,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:rt(f.rateApPerHour)})})]})})()},i.id))})]}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Place categories"}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:oe.categoryBreakdown.map(i=>e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[i.tag," · ",i.count]},i.tag))})]})]}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(22rem,0.95fr)]",children:[e.jsx(gr,{children:e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx(ce,{content:"Known places turn raw stationary spans into named contexts like home, work, gym, nature, or any custom place tag you want Forge to remember."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"These landmarks anchor stays, travel XP, and contextual reasoning in both Forge and the companion. Seeded tags like home, workplace, gym, holiday, grocery, or nature matter for downstream calculations, but place tags stay open-ended."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{value:Se,onChange:i=>ht(i.target.value),placeholder:"Search places",className:"w-[11rem]"}),e.jsx(A,{onClick:()=>{Ye(null),_e(!0)},children:"Add place"})]})]}),e.jsx("div",{className:"mt-5 grid gap-3",children:ve.map(i=>e.jsxs("button",{type:"button",className:"flex items-start justify-between gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-left transition hover:bg-[var(--ui-surface-3)]",onClick:()=>{Ye(i),_e(!0)},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:i.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[i.latitude.toFixed(4),", ",i.longitude.toFixed(4)," · radius ",Math.round(i.radiusMeters)," m"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:i.categoryTags.map(f=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:f},f))})]}),e.jsx(It,{className:"mt-1 size-4 text-[var(--ui-ink-muted)]"})]},i.id))})]})}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Movement help"}),e.jsx(ce,{content:"Most movement surfaces on this page have help buttons. Use them to understand the graph, the day strip, the month chart, and the place system without keeping a large prose block on screen."})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Use the small help icons across this page for graph explanations, timeline semantics, and metric meanings."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Life graph"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Day strip"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Month chart"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Known places"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Selection aggregate"})]})]})]}),y.data?e.jsx(wa,{open:U,onOpenChange:i=>{b(i),i||(E(""),Z([]),J(null),ee(null))},eyebrow:"Movement data",title:y.data.trip.label||"Trip datapoints",description:"Inspect the raw datapoints behind this trip. Raw measurements are read-only here; visible movement corrections now happen through canonical user-defined boxes.",children:e.jsx(fr,{children:e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,24rem)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ma,{title:"Datapoint browser",description:"Search raw points by time band, anchor status, or accuracy before opening the point editor.",query:C,onQueryChange:E,options:Je,selectedOptionIds:K,onSelectedOptionIdsChange:Z,resultSummary:Oe,placeholder:"Search timestamps, accuracy, point ids, or filter chips",emptyStateMessage:"Keep typing or pick a time/quality chip to narrow the trip datapoints."}),e.jsxs(k,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw datapoints"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Open a point to correct or delete it."})]}),e.jsx(v,{tone:"meta",children:Oe})]}),e.jsx("div",{ref:ze,className:"h-[34rem] overflow-y-auto rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:O.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No datapoint matches the current search. Clear some filters or search by time, anchor type, or accuracy."}):e.jsx("div",{className:"relative w-full",style:{height:`${Ae.getTotalSize()}px`},children:Ae.getVirtualItems().map(i=>{const f=O[i.index];return e.jsx("div",{className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${i.start}px)`},children:e.jsxs("button",{type:"button",className:w("grid w-full gap-3 rounded-[20px] border px-4 py-3 text-left transition",z===f.id?"border-[color-mix(in_srgb,var(--info)_34%,transparent)] bg-[var(--ui-info-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:bg-[var(--ui-surface-3)]"),onClick:()=>{J(f.id),ee(ha(f))},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Xa,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:Rt(f.recordedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[f.latitude.toFixed(5),", ",f.longitude.toFixed(5)]})]}),e.jsx(v,{tone:f.isStopAnchor?"signal":"meta",children:f.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:pt(f.recordedAt)}),f.accuracyMeters!=null?e.jsxs(v,{tone:"meta",children:[Math.round(f.accuracyMeters)," m accuracy"]}):null,f.speedMps!=null?e.jsxs(v,{tone:"meta",children:[f.speedMps.toFixed(1)," m/s"]}):null]})]})},f.id)})})})]})]}),D&&G?e.jsx($s,{point:D,draft:G}):e.jsx(k,{className:"rounded-[28px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-6 text-[var(--ui-ink-muted)]",children:"Pick a datapoint to inspect its raw measurement details. To correct what the user sees, use canonical user-defined movement boxes in the Life Timeline."})]})})}):null,e.jsx(Aa,{open:Ee,onOpenChange:_e,place:Re,onSave:async i=>{await Ze.mutateAsync(i)}})]})}export{Vs as MovementPage};
1
+ import{r as x,j as e,aK as $t,b_ as It,b3 as Ft,ck as ga,bZ as fa,aZ as ot,cl as wt,F as Ua,cm as Wa,bX as Ga,cn as ba,co as Va,c1 as Ya,bu as Xa}from"./vendor-Cpmju3nw.js";import{j as ya,x as Yt,i as ae,k as Pe}from"./state-BtwEvpO6.js";import{I as B,B as A,c as w,k as v,C as k,aF as Xt,aG as Zt,aH as ja,aI as Za,aJ as Ja,S as Na,e as ka,aA as wa,aK as Jt,aL as er,aM as tr,aN as Sa,aO as ar,d as rr,aP as at,n as ea,m as rt,a4 as ce,aQ as sr,aR as ir,aS as nr,aT as lr,aU as or,O as dr,aV as cr,aW as ur,aX as mr}from"./index-BaiwtAgo.js";import{F as Ma}from"./faceted-token-search-DJPRm9AY.js";import{P as xr}from"./page-hero-C0MpI3MM.js";import{R as Qe,P as Ue,O as We,C as Ge,T as mt,D as xt,a as vt}from"./ui-B9O-eUim.js";import{m as ta}from"./motion-DwjmC9aq.js";import{S as me}from"./surface-BVYp-Wq9.js";import{M as vr,a as pr,b as hr,c as gr,d as fr}from"./movement-boxes-5cjWjIdR.js";import{R as br,A as yr,C as jr,X as Nr,Y as kr,T as wr,a as Sr}from"./charts-DwTguE_x.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./generic-node-view-p5ePSFuG.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-5h-dyvJY.js";function Aa({open:t,onOpenChange:a,place:r,seed:s,onSave:l}){const[c,m]=x.useState({label:(r==null?void 0:r.label)??(s==null?void 0:s.label)??"",latitude:String((r==null?void 0:r.latitude)??(s==null?void 0:s.latitude)??""),longitude:String((r==null?void 0:r.longitude)??(s==null?void 0:s.longitude)??""),radiusMeters:String((r==null?void 0:r.radiusMeters)??(s==null?void 0:s.radiusMeters)??100),categoryTags:((r==null?void 0:r.categoryTags)??(s==null?void 0:s.categoryTags)??[]).join(", ")});return x.useEffect(()=>{m({label:(r==null?void 0:r.label)??(s==null?void 0:s.label)??"",latitude:String((r==null?void 0:r.latitude)??(s==null?void 0:s.latitude)??""),longitude:String((r==null?void 0:r.longitude)??(s==null?void 0:s.longitude)??""),radiusMeters:String((r==null?void 0:r.radiusMeters)??(s==null?void 0:s.radiusMeters)??100),categoryTags:((r==null?void 0:r.categoryTags)??(s==null?void 0:s.categoryTags)??[]).join(", ")})},[r,s]),e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"fixed inset-0 z-50 bg-[var(--ui-overlay-backdrop)] backdrop-blur-sm"}),e.jsxs(Ge,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(32rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-normal text-[var(--ui-ink-strong)]",children:r?`Edit ${r.label}`:"New known place"}),e.jsx(xt,{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Define life landmarks once so the companion and web views can reason about stays and trips consistently."})]}),e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",children:e.jsx($t,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(B,{value:c.label,onChange:d=>m(u=>({...u,label:d.target.value})),placeholder:"Home, Main Office, Riverside path..."}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(B,{value:c.latitude,onChange:d=>m(u=>({...u,latitude:d.target.value})),placeholder:"Latitude"}),e.jsx(B,{value:c.longitude,onChange:d=>m(u=>({...u,longitude:d.target.value})),placeholder:"Longitude"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[10rem_minmax(0,1fr)]",children:[e.jsx(B,{value:c.radiusMeters,onChange:d=>m(u=>({...u,radiusMeters:d.target.value})),placeholder:"Radius meters"}),e.jsx(B,{value:c.categoryTags,onChange:d=>m(u=>({...u,categoryTags:d.target.value})),placeholder:"home, gym, holiday, parents-house"})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(A,{variant:"ghost",onClick:()=>a(!1),className:"border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)]",children:"Cancel"}),e.jsx(A,{onClick:()=>void l({id:r==null?void 0:r.id,label:c.label,latitude:Number(c.latitude),longitude:Number(c.longitude),radiusMeters:Number(c.radiusMeters),categoryTags:c.categoryTags.split(",").map(d=>d.trim()).filter(Boolean)}).then(()=>a(!1)),children:"Save place"})]})]})]})})}const St=1e3;function I(t){return new Date(t).getTime()}function Mt(t){return new Date(t).toISOString()}function aa(t,a){const r=I(t.startedAt)-I(a.startedAt);if(r!==0)return r;const s=I(t.endedAt)-I(a.endedAt);return s!==0?s:t.id.localeCompare(a.id)}function Et(t){return t.syncSource==="sleep overlay"}function Mr(t){const a=[...t].filter(s=>I(s.endedAt)>I(s.startedAt)).sort((s,l)=>{const c=I(s.startedAt)-I(l.startedAt);if(c!==0)return c;const m=I(s.endedAt)-I(l.endedAt);return m!==0?m:s.id.localeCompare(l.id)});if(a.length===0)return[];const r=[];for(const s of a){const l=r.at(-1);if(!l){r.push(s);continue}const c=I(l.endedAt);if(I(s.startedAt)<=c+St){const d=Math.max(c,I(s.endedAt));r[r.length-1]={...l,id:`${l.id}__${s.id}`,endedAt:Mt(d),asleepSeconds:(l.asleepSeconds??0)+(s.asleepSeconds??0)||null,timeInBedSeconds:(l.timeInBedSeconds??0)+(s.timeInBedSeconds??0)||null,sleepScore:s.sleepScore??l.sleepScore,regularityScore:s.regularityScore??l.regularityScore,efficiency:s.efficiency??l.efficiency,recoveryState:s.recoveryState??l.recoveryState};continue}r.push(s)}return r}function Ar(t){const a=[];if(typeof t.asleepSeconds=="number"&&t.asleepSeconds>0){const r=t.asleepSeconds/3600;a.push(`${r.toFixed(r>=1?1:2)}h asleep`)}else if(typeof t.timeInBedSeconds=="number"&&t.timeInBedSeconds>0){const r=t.timeInBedSeconds/3600;a.push(`${r.toFixed(r>=1?1:2)}h in bed`)}return typeof t.sleepScore=="number"&&a.push(`score ${t.sleepScore}`),typeof t.regularityScore=="number"&&a.push(`regularity ${t.regularityScore}`),t.recoveryState&&a.push(t.recoveryState),a.join(" · ")||"Sleep session"}function Cr(t){const a=Math.max(60,Math.round((I(t.endedAt)-I(t.startedAt))/1e3));return{id:`sleep-overlay-${t.id}`,boxId:`sleep-overlay-${t.id}`,kind:"stay",sourceKind:"automatic",origin:"recorded",editable:!1,isInvalid:!1,startedAt:t.startedAt,endedAt:t.endedAt,trueStartedAt:t.startedAt,trueEndedAt:t.endedAt,visibleStartedAt:t.startedAt,visibleEndedAt:t.endedAt,durationSeconds:a,laneSide:"left",connectorFromLane:"left",connectorToLane:"left",title:"Sleep",subtitle:Ar(t),placeLabel:null,tags:["sleep"],syncSource:"sleep overlay",cursor:`${t.endedAt}::sleep-overlay-${t.id}`,overrideCount:0,overriddenAutomaticBoxIds:[],overriddenUserBoxIds:[],isFullyHidden:!1,rawStayIds:[],rawTripIds:[],rawPointCount:0,hasLegacyCorrections:!1,stay:null,trip:null}}function ra(t,a,r){if(r<=a)return null;const s=Mt(a),l=Mt(r),c=Math.max(60,Math.round((r-a)/1e3));return{...t,id:`${t.id}::virtual-${a}-${r}`,startedAt:s,endedAt:l,trueStartedAt:s,trueEndedAt:l,visibleStartedAt:s,visibleEndedAt:l,durationSeconds:c,cursor:`${l}::${t.id}::virtual`}}function Tr(t,a){let r=[...t].sort(aa);for(const s of Mr(a)){const l=I(s.startedAt),c=I(s.endedAt),m=Cr(s),d=[];let u=!1;for(const p of r){const g=I(p.startedAt),j=I(p.endedAt);if(j<=l||g>=c){!u&&g>=c&&(d.push(m),u=!0),d.push(p);continue}if(g<l){const P=ra(p,g,Math.min(j,l-St));P&&d.push(P)}if(u||(d.push(m),u=!0),j>c){const P=ra(p,Math.max(g,c+St),j);P&&d.push(P)}}u||d.push(m),r=d.sort(aa)}return r}const sa=24,X=64,At=360*60,Ca=5,Nt=1,Pr=104,ia=X*8;function he(t){return t.trim().toLowerCase()}function qe(t){return t>=86400?`${Math.round(t/3600)}h`:t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.max(1,Math.round(t/60))}m`}function ge(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ta(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit"}).format(new Date(t))}function Dr(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:!1}).format(t)}function $e(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const r=a.getFullYear(),s=String(a.getMonth()+1).padStart(2,"0"),l=String(a.getDate()).padStart(2,"0"),c=String(a.getHours()).padStart(2,"0"),m=String(a.getMinutes()).padStart(2,"0");return`${r}-${s}-${l}T${c}:${m}`}function dt(t){if(!t.trim())return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toISOString()}function Ie(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Y(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function na(t,a){return`${t.toFixed(3)}, ${a.toFixed(3)}`}function st(t,a){return`${t.toFixed(6)}, ${a.toFixed(6)}`}function la(t){return`${Math.max(1,Math.round(t/60))} min`}function Lr(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),r=Math.max(...t.map(d=>d.latitude)),s=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(r-a,1e-4),m=Math.max(l-s,1e-4);return t.map((d,u)=>({...d,x:12+(d.longitude-s)/m*76,y:12+(1-(d.latitude-a)/c)*76,id:`${d.recordedAt??"point"}-${u}`}))}function ct(t){return t.kind==="trip"&&t.trip!==null}function le(t){return t.kind==="stay"&&t.stay!==null}function Ct(t){return!le(t)||t.stay.place?null:{label:t.stay.label||t.title,latitude:t.stay.centerLatitude,longitude:t.stay.centerLongitude,radiusMeters:t.stay.radiusMeters,categoryTags:t.tags}}function Fe(t){var a;return t?t.kind==="stay"&&le(t)?((a=t.stay.place)==null?void 0:a.label)??t.placeLabel??t.stay.label??null:t.placeLabel??null:null}function lt(t,a,r,s){const c=(r-t)*Math.PI/180,m=(s-a)*Math.PI/180,d=t*Math.PI/180,u=r*Math.PI/180,p=Math.sin(c/2)**2+Math.cos(d)*Math.cos(u)*Math.sin(m/2)**2;return 2*6371e3*Math.asin(Math.sqrt(p))}function $r(t){return he([t.label,...t.aliases].join(" "))}function we(t,a,r){if(!t.trip)return{label:t.placeLabel??(a==="start"?"Known origin":"Known destination"),detail:Y(a==="start"?t.startedAt:t.endedAt)};const s=a==="start"?t.trip.points[0]??null:t.trip.points[t.trip.points.length-1]??null,l=a==="start"?t.trip.startPlace:t.trip.endPlace,c=(r==null?void 0:r.includeCoordinates)??!0,m=r!=null&&r.useHistoryAnchorFallback&&a==="start"?"Beginning of history":null;return{label:(l==null?void 0:l.label)??m??(c&&s?na(s.latitude,s.longitude):a==="start"?"Unknown origin":"Unknown destination"),detail:c&&s&&!l?na(s.latitude,s.longitude):Y(a==="start"?t.startedAt:t.endedAt)}}function Ir(t){const a=t.trim().toLowerCase();return a==="travel"||a==="trip"||a==="move"}function Fr(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 Er(t){const a=Fe(t),r=t.title.trim().toLowerCase(),s=r.length===0||r==="stay"||r==="continued stay"||r==="repaired stay"||r==="manual stay";return a&&s?a:t.title.trim()||a||"Stay"}function ue(t){if(Et(t))return"Sleep";if(t.kind==="missing")return Fr(t);if(t.kind==="stay")return Er(t);if(t.kind==="trip"&&Ir(t.title)){const a=we(t,"start").label,r=we(t,"end").label;return`${a} → ${r}`}return t.title}function oa(t){return t==="left"?24:t==="right"?76:50}function _r(t,a,r){const s=Math.min(t,At)/3600,l=r==="sleep overlay",c=l?112:a==="stay"?104:92,m=l?272:a==="stay"?288:232,d=c+s*30;return Math.max(c,Math.min(m,d))}function Tt(t){var a;return{kind:t.kind,label:le(t)?t.stay.label||t.title:ct(t)&&t.trip.label||t.title,placeLabel:le(t)?((a=t.stay.place)==null?void 0:a.label)??t.placeLabel??"":"",tagsInput:t.tags.join(", "),startedAtInput:$e(t.startedAt),endedAtInput:$e(t.endedAt)}}function kt(t,a){const r=(a==null?void 0:a.startedAt)??new Date(Date.now()-36e5).toISOString(),s=(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t,label:t==="missing"?"User-defined missing data":t==="stay"?(a==null?void 0:a.placeLabel)||"Manual stay":"Manual move",placeLabel:(a==null?void 0:a.placeLabel)??"",tagsInput:t==="missing"?"user-defined, missing-data":t==="stay"?"user-defined, stay":"user-defined, move",startedAtInput:$e(r),endedAtInput:$e(s)}}function Pt(t,a){var c,m;const r=t.tagsInput.split(",").map(d=>d.trim()).filter(Boolean),s=dt(t.startedAtInput)??(a==null?void 0:a.startedAt)??new Date(Date.now()-3600*1e3).toISOString(),l=dt(t.endedAtInput)??(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t.kind,startedAt:s,endedAt:l,title:t.label.trim(),subtitle:t.kind==="missing"?"User-defined missing-data override.":"User-defined movement box.",placeLabel:t.placeLabel.trim()||null,tags:r,distanceMeters:t.kind==="trip"?Math.max(((c=a==null?void 0:a.trip)==null?void 0:c.distanceMeters)??150,150):null,averageSpeedMps:t.kind==="trip"?((m=a==null?void 0:a.trip)==null?void 0:m.averageSpeedMps)??null:null,metadata:{createdFrom:"movement-life-timeline"}}}function Rr(t,a){var l,c;const r=t.kind==="stay"?((c=(l=t.stay)==null?void 0:l.label)==null?void 0:c.trim())??"":"";if(r)return r;const s=t.title.trim();return s&&s.toLowerCase()!=="stay"?s:a.trim()||"Stay"}function zr(t,a){const r=Tt(t),s=a.trim();return Pt({...r,label:Rr(t,s),placeLabel:s},t)}function Pa(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function ut(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Or(t){var a,r,s;return he([t.kind,ue(t),t.subtitle,t.placeLabel??"",...t.tags,ut(t.startedAt),ut(t.endedAt),Pa(t.startedAt),le(t)?((a=t.stay.place)==null?void 0:a.label)??t.stay.label:ct(t)?[t.trip.label,t.trip.activityType,t.trip.travelMode,(r=t.trip.startPlace)==null?void 0:r.label,(s=t.trip.endPlace)==null?void 0:s.label].filter(Boolean).join(" "):t.kind==="trip"?[t.title,t.subtitle,t.placeLabel??""].filter(Boolean).join(" "):"missing data gap"].join(" "))}function Hr(t){const a=new Map;a.set("kind:stay",{id:"kind:stay",label:"Stay",description:"Stationary spans and place anchors."}),a.set("kind:trip",{id:"kind:trip",label:"Move",description:"Trips and movement connectors."});for(const r of["night","morning","afternoon","evening"])a.set(`time:${r}`,{id:`time:${r}`,label:r[0].toUpperCase()+r.slice(1),description:"Filter by the segment start time."});for(const r of t){for(const s of r.tags)a.set(`tag:${s}`,{id:`tag:${s}`,label:s,description:"Movement tag"});r.placeLabel&&a.set(`place:${r.placeLabel}`,{id:`place:${r.placeLabel}`,label:r.placeLabel,description:"Matched place"})}return[...a.values()].sort((r,s)=>r.label.localeCompare(s.label))}function Br(t,a){return a.every(r=>r==="kind:stay"||r==="kind:trip"?t.kind===r.slice(5):r.startsWith("time:")?Pa(t.startedAt)===r.slice(5):r.startsWith("tag:")?t.tags.includes(r.slice(4)):r.startsWith("place:")?(t.placeLabel??"")===r.slice(6):!0)}function da(t,a){return t&&{...t,pages:t.pages.map(r=>({...r,segments:r.segments.filter(s=>s.id!==a)}))}}function Kr(t,a){const r=t+(Math.sin((t-.5)*Math.PI)+1)*.5-t,s=t-.5,c=.5+(s*(1-a*.64)+s*s*s*a*2.56);return Math.max(0,Math.min(1,c-(r-t)*a*.08))}function qr(t){return t.getHours()===0?Ta(t.toISOString()):Dr(t)}function Qr(t,a){const r=new Date(t.endedAt).getTime(),s=new Date(t.startedAt).getTime(),l=Math.max(1,r-s),c=Math.max(0,Math.min(1,(a-s)/l));if(t.durationSeconds<=At)return c;const m=Math.max(0,1-Math.min(1,At/Math.max(1,t.durationSeconds)));return Kr(c,m)}function Ur(t,a,r){if(t.items.length===0)return null;const s=t.items[0];if(a<new Date(s.segment.startedAt).getTime())return t.historyHeaderHeight+t.leadHeight-(new Date(s.segment.startedAt).getTime()-a)/36e5*X;for(let m=0;m<t.items.length;m+=1){const d=t.items[m],u=new Date(d.segment.startedAt).getTime(),p=new Date(d.segment.endedAt).getTime();if(a>=u&&a<=p)return d.boxTop+Qr(d.segment,a)*d.displayHeight;const g=t.items[m+1]??null,j=g?new Date(g.segment.startedAt).getTime():r;if(a>p&&a<j)return d.boxBottom+(a-p)/36e5*X}const l=t.items[t.items.length-1],c=new Date(l.segment.endedAt).getTime();return a>=c?l.boxBottom+(a-c)/36e5*X:null}function Wr(t){const a=new Date(t);a.setMinutes(0,0,0);const r=a.getTime();return r<=t?r+36e5:r}function Gr(t,a){const r=[];if(t.items.length===0)return r;const s=t.items[0],l=new Date(s.segment.startedAt).getTime();for(let c=Wr(l-Ca*36e5);c<=a;c+=36e5){const m=Ur(t,c,a);if(m===null)continue;const d=new Date(c);r.push({y:m,label:qr(d),strong:d.getHours()===0})}return r}function Vr({segments:t,viewportHeight:a,nowMs:r=Date.now()}){var U;const s=t.length>0?Pr:0,l=t.length>0?X*Ca:0;let c=s+l,m=null;const d=t.map(b=>{const C=_r(b.durationSeconds,b.kind,b.syncSource),E=new Date(b.startedAt).getTime(),K=m===null?0:Math.max(0,(E-m)/36e5)*X;c+=K;const Z=c,z=Z+C;return c=z,m=new Date(b.endedAt).getTime(),{id:b.id,segment:b,gapBefore:K,displayHeight:C,boxTop:Z,boxBottom:z}}),u=r+Nt*36e5,p=(()=>{var E;const b=(E=t[t.length-1])==null?void 0:E.endedAt;if(!b)return X*Nt;const C=new Date(b).getTime();return Math.max(X*Nt,(u-C)/36e5*X)})(),g=(((U=d[d.length-1])==null?void 0:U.boxBottom)??s+l)+p,j=Math.max(g,a>0?a+260:960,s+l+p),P={historyHeaderHeight:s,leadHeight:l,items:d,markers:[],rangeEndMs:u,futureTailHeight:p+Math.max(0,j-g),totalHeight:j};return{...P,markers:Gr(P,u)}}const Yr="bg-[image:var(--ui-surface-section)]",Xr="bg-[image:var(--ui-surface-section)]",Zr="h-6 w-[3px] rounded-full bg-[var(--info)] shadow-[var(--ui-shadow-soft)]",Jr="relative w-[min(18rem,calc(100vw-6rem))] overflow-hidden rounded-[26px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[image:var(--ui-surface-section)] shadow-[var(--ui-shadow-soft)]",es="absolute z-10 h-7 w-8 rounded-[12px] border bg-[image:var(--ui-surface-modal)] shadow-[var(--ui-shadow-soft)] backdrop-blur-sm",ts="group absolute top-1/2 max-w-[min(8rem,calc(100vw-8rem))] -translate-y-1/2 rounded-[16px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] px-2.5 py-2 text-left shadow-[var(--ui-shadow-soft)] backdrop-blur-sm transition hover:border-[var(--ui-border-strong)] sm:max-w-[9rem] sm:px-3",Dt="ring-1 ring-[color-mix(in_srgb,var(--info)_42%,transparent)]",as="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",Da="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",Te="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",rs="border-[color-mix(in_srgb,var(--danger)_26%,transparent)] bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)] hover:bg-[color-mix(in_srgb,var(--danger)_18%,transparent)]",ss="border-[color-mix(in_srgb,var(--warning)_26%,transparent)] bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)] hover:bg-[color-mix(in_srgb,var(--warning)_18%,transparent)]";function is({layout:t,scrollTop:a,viewportHeight:r}){const s=X*6,l=Math.max(0,a-s),c=Math.min(t.totalHeight,a+Math.max(r,X*8)+s),m=t.markers.filter(d=>d.y>=l&&d.y<=c);return e.jsxs("div",{className:"pointer-events-none absolute inset-x-0 top-0 overflow-hidden rounded-[30px]",style:{height:`${t.totalHeight}px`},children:[e.jsx("div",{className:w("absolute inset-y-0 left-0 w-18",Yr)}),m.map((d,u)=>e.jsxs("div",{className:"absolute inset-x-0",style:{top:`${d.y}px`},children:[e.jsx("div",{className:w("border-t",(d.strong,"border-[var(--ui-border-subtle)]"))}),e.jsx("div",{className:w("absolute left-3 top-0 -translate-y-1/2 font-label text-[9px] tracking-[0.24em]",(d.strong,"text-[var(--ui-ink-muted)]")),children:d.label})]},`timeline-grid-${u}`))]})}function ns({fromSide:t,toSide:a,height:r,emphasized:s}){const l=oa(t),c=oa(a),m=`M ${l} 16 C ${l} ${Math.max(40,r*.26)}, ${c} ${Math.max(70,r*.72)}, ${c} ${r-18}`;return e.jsxs("svg",{viewBox:`0 0 100 ${r}`,className:"absolute inset-x-0 top-0 h-full w-full overflow-visible",preserveAspectRatio:"none",children:[e.jsx("path",{d:m,fill:"none",stroke:s?"color-mix(in srgb, var(--ui-ink-strong) 18%, transparent)":"color-mix(in srgb, var(--ui-ink-strong) 11%, transparent)",strokeWidth:s?"1.05":"0.85",strokeDasharray:s?"3 10":"2.5 12",strokeLinecap:"round"}),e.jsx("circle",{cx:l,cy:"16",r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"}),e.jsx("circle",{cx:c,cy:r-18,r:"1.5",fill:"color-mix(in srgb, var(--ui-ink-strong) 26%, transparent)"})]})}function Lt({position:t}){return e.jsx("div",{className:w("absolute left-1/2 z-20 flex -translate-x-1/2 items-center justify-center",t==="top"?"-top-3":"-bottom-3"),children:e.jsx("div",{className:Zr})})}function ls({segment:t}){const a=(t==null?void 0:t.kind)==="stay"?t.placeLabel||t.title||null:(t==null?void 0:t.kind)==="trip"?we(t,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}).label:null,r=a||"Beginning of time";return e.jsx("div",{className:"pointer-events-none flex justify-center px-6 py-4",children:e.jsxs("div",{className:Jr,children:[e.jsx(Lt,{position:"bottom"}),e.jsxs("div",{className:"relative z-10 px-5 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(v,{tone:"signal",className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",children:"Start"}),e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Beginning of history"})]}),e.jsx("div",{className:"mt-5 font-display text-[1.25rem] tracking-normal text-[var(--ui-ink-strong)]",children:r}),e.jsx("div",{className:"mt-2 font-label text-[10px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:a?"Oldest loaded known stay":"Earliest known anchor"})]})]})})}function os(t,a,r){const s=a+Math.max(96,Math.min(r*.28,220)),l=t.items.find(c=>c.boxBottom>=s)??t.items[t.items.length-1]??null;return l?Ta(l.segment.startedAt):null}function ca({side:t,vertical:a,emphasized:r=!1}){return e.jsx("div",{className:w(es,r?"border-[color-mix(in_srgb,var(--info)_34%,transparent)]":"border-[var(--ui-border-subtle)]",t==="left"?"left-[8%]":t==="right"?"right-[8%]":"left-1/2 -translate-x-1/2",a==="top"?"top-0":"bottom-0")})}function ds({layout:t,selected:a,onToggle:r}){var u,p,g,j;const{segment:s}=t,l=Et(s),c=t.displayHeight,m=s.kind==="stay"?l?"bg-[var(--ui-info-soft)] border-[color-mix(in_srgb,var(--info)_28%,transparent)]":"bg-[var(--ui-accent-soft)] border-[color-mix(in_srgb,var(--primary)_24%,transparent)]":"",d=s.kind==="trip"?{start:we(s,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}),end:we(s,"end",{includeCoordinates:!1})}:null;return e.jsxs("div",{className:w("absolute left-0 w-full px-3 sm:px-6",a?"z-40":"z-10"),"data-testid":"movement-timeline-row","data-selected":a?"true":"false",style:{top:`${t.boxTop}px`,height:`${c}px`},children:[e.jsx("div",{className:w("absolute inset-y-0 left-1/2 w-px -translate-x-1/2",Xr)}),e.jsx("div",{className:"relative h-full",children:s.kind==="trip"?e.jsxs(ta.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:240,damping:30},className:"absolute inset-x-0 top-0 z-10 h-full",children:[d&&a?e.jsxs(e.Fragment,{children:[e.jsx(ca,{side:"center",vertical:"top",emphasized:!0}),e.jsx(ca,{side:"center",vertical:"bottom",emphasized:!0})]}):null,e.jsx(ns,{fromSide:"center",toSide:"center",height:c,emphasized:a}),e.jsxs("button",{type:"button",onClick:r,className:w(ts,"left-1/2 -translate-x-1/2",a?Dt:""),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Move"}),e.jsx("div",{className:"text-[11px] tracking-[0.18em] text-[var(--ui-ink-strong)]/44",children:qe(s.durationSeconds)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:Ie(((u=s.trip)==null?void 0:u.distanceMeters)??0)}),(((p=s.trip)==null?void 0:p.stops.length)??0)>0?e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[(g=s.trip)==null?void 0:g.stops.length," stop",((j=s.trip)==null?void 0:j.stops.length)===1?"":"s"]}):null]}),e.jsxs("div",{className:"mt-2 font-label text-[9px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:[Y(s.startedAt)," →"," ",Y(s.endedAt)]})]})]}):e.jsx(ta.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:260,damping:28},className:"absolute left-1/2 top-0 z-10 w-[min(18.5rem,calc(100vw-3.25rem))] -translate-x-1/2 sm:w-[min(21rem,calc(100vw-5rem))]",children:e.jsxs("button",{type:"button",onClick:r,className:w("group relative w-full overflow-hidden rounded-[24px] border text-left shadow-[var(--ui-shadow-soft)] transition sm:rounded-[30px]",m,a?Dt:"hover:border-[var(--ui-border-strong)]"),style:{minHeight:`${c}px`},children:[e.jsx(Lt,{position:"top"}),e.jsx(Lt,{position:"bottom"}),e.jsxs("div",{className:"relative z-10 flex h-full flex-col justify-between p-3.5 sm:p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx(v,{tone:"signal",className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]",children:l?"Sleep":"Stay"}),e.jsx("div",{className:"text-[11px] tracking-[0.16em] text-[var(--ui-ink-muted)] sm:text-xs sm:tracking-[0.18em]",children:qe(s.durationSeconds)})]}),e.jsxs("div",{className:"mt-3 min-w-0 sm:mt-5",children:[e.jsx("div",{className:"truncate font-display text-[1rem] tracking-normal text-[var(--ui-ink-strong)] sm:text-[1.12rem]",children:ue(s)}),s.kind==="stay"&&Fe(s)&&!l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(v,{className:"max-w-full truncate bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:Fe(s)})}):l?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(v,{className:w("max-w-full truncate",Da),children:s.subtitle})}):null]}),e.jsx("div",{className:"mt-auto pt-4 sm:pt-8",children:e.jsxs("div",{className:"font-label text-[9px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)] sm:text-[10px] sm:tracking-[0.22em]",children:[Y(s.startedAt)," →"," ",Y(s.endedAt)]})})]})]})})})]})}const cs="rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)] p-5 shadow-[var(--ui-shadow-floating)]",it="rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",nt="text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",ua="text-sm leading-6 text-[var(--ui-ink-medium)]",Ne="bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",ma="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]",xa="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]",us="bg-[var(--ui-accent-soft)] text-[var(--primary)]",ms="mt-4 rounded-[18px] border border-[color-mix(in_srgb,var(--info)_22%,transparent)] bg-[var(--ui-info-soft)] p-3",xs="text-[11px] uppercase tracking-[0.18em] text-[color-mix(in_srgb,var(--info)_70%,var(--ui-ink-strong)_30%)]",vs="mt-2 text-sm leading-6 text-[var(--ui-ink-medium)]",ps="rounded-full border border-[color-mix(in_srgb,var(--info)_28%,transparent)] bg-[var(--ui-info-soft)] px-4 text-[color-mix(in_srgb,var(--info)_72%,var(--ui-ink-strong)_28%)] hover:bg-[color-mix(in_srgb,var(--info)_18%,transparent)]";function hs({segment:t,onEdit:a,onOpenDetail:r,onDefinePlace:s,onClose:l}){var d;const c=Et(t),m=Fe(t);return e.jsxs(k,{className:cs,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:c?"Sleep overlay":t.kind==="stay"?"Stay detail":t.kind==="trip"?"Move detail":"Missing data"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:ue(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{className:c?ma:t.sourceKind==="user_defined"?us:Ne,children:c?"Virtual":t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),t.overrideCount>0?e.jsxs(v,{className:xa,children:["Overrides ",t.overrideCount," automatic box",t.overrideCount===1?"":"es"]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{onClick:r,variant:"ghost",className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",disabled:c,children:"Details"}),e.jsx(A,{onClick:a,variant:"ghost",className:"size-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Edit movement segment",disabled:c||t.kind==="missing"||!t.editable,children:e.jsx(It,{className:"size-4"})}),l?e.jsx("button",{type:"button",onClick:l,className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-2 text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]","aria-label":"Close movement segment actions",children:e.jsx($t,{className:"size-4"})}):null,e.jsx(Ft,{className:"size-4 text-[var(--ui-ink-faint)]"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.startedAt)})]}),e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:ge(t.endedAt)})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:qe(t.durationSeconds)}),ct(t)?e.jsxs(e.Fragment,{children:[e.jsx(v,{className:Ne,children:Ie(t.trip.distanceMeters)}),t.trip.stops.length>0?e.jsxs(v,{className:Ne,children:[t.trip.stops.length," stop",t.trip.stops.length===1?"":"s"]}):null]}):null,c?e.jsx(v,{className:ma,children:t.subtitle}):m?e.jsx(v,{className:Ne,children:m}):null]}),le(t)&&!c?e.jsxs("div",{className:ms,children:[e.jsx("div",{className:xs,children:"Location label"}),e.jsx("div",{className:vs,children:t.stay.place?`This stay is currently linked to ${t.stay.place.label}. Search saved places or relabel it from this stay center.`:"Search saved places for this stay, or create a new one from the stay center so later matching stays inherit it automatically."}),e.jsx("div",{className:"mt-3",children:e.jsx(A,{onClick:s,variant:"ghost",className:ps,children:"Label location"})})]}):null,e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Timeline summary"}),e.jsx("div",{className:`mt-2 ${ua}`,children:t.kind==="stay"?c?`Sleep overlay from ${Y(t.startedAt)} to ${Y(t.endedAt)}. Underlying movement boxes are sliced virtually while this overlay is visible.`:`Stay block from ${Y(t.startedAt)} to ${Y(t.endedAt)}.`:t.kind==="trip"?`Connector from ${we(t,"start").label} to ${we(t,"end").label}.`:`No reliable movement signal reached Forge from ${Y(t.startedAt)} to ${Y(t.endedAt)}.`})]}),e.jsxs("div",{className:it,children:[e.jsx("div",{className:nt,children:"Projection model"}),e.jsx("div",{className:`mt-2 ${ua}`,children:c?"This sleep layer is visual only. Forge does not persist these split boxes; it temporarily slices the visible movement boxes around each sleep interval.":"Raw phone measurements stay immutable. Forge derives automatic boxes from that raw movement evidence, then overlays user-defined boxes on top without mutating the imported raw data."}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsxs(v,{className:Ne,children:["Raw stays ",t.rawStayIds.length]}),e.jsxs(v,{className:Ne,children:["Raw trips ",t.rawTripIds.length]}),e.jsxs(v,{className:Ne,children:["Raw points ",t.rawPointCount]}),t.hasLegacyCorrections?e.jsx(v,{className:xa,children:"Legacy corrections present"}):null]})]})]}),e.jsx("div",{className:"mt-5 flex flex-wrap items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:c?e.jsxs(e.Fragment,{children:[e.jsx(ga,{className:"size-4 text-[var(--info)]"}),"Sleep overlay"]}):le(t)?e.jsxs(e.Fragment,{children:[e.jsx(fa,{className:"size-4 text-[var(--primary)]"}),((d=t.stay.place)==null?void 0:d.label)??"No canonical place linked yet"]}):ct(t)?e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"size-4 text-[var(--primary)]"}),t.trip.activityType||t.trip.travelMode]}):t.kind==="trip"?e.jsxs(e.Fragment,{children:[e.jsx(ot,{className:"size-4 text-[var(--primary)]"}),"Repaired movement connector"]}):e.jsxs(e.Fragment,{children:[e.jsx(wt,{className:"size-4 text-[var(--ui-ink-soft)]"}),"Missing intervals are synthesized from long signal gaps instead of inventing fake travel."]})})]})}function va({title:t,points:a,averagePoint:r}){const s=Lr(r?[...a,r]:a),l=r?s.length-1:s.length,c=s.slice(0,l),m=r?s[s.length-1]??null:null,d=c.map((u,p)=>`${p===0?"M":"L"} ${u.x} ${u.y}`).join(" ");return e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Relative coordinates normalized into one view so we can inspect the actual captured stay or trip geometry in one glance."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"var(--ui-surface-1)"}),c.length>1?e.jsx("path",{d,fill:"none",stroke:"var(--primary)",strokeWidth:"1.6"}):null,c.map((u,p)=>e.jsx("circle",{cx:u.x,cy:u.y,r:p===0||p===c.length-1?2.2:1.4,fill:p===0||p===c.length-1?"var(--ui-ink-strong)":"var(--primary)"},u.id)),m?e.jsxs("g",{className:"text-[var(--warning)]",children:[e.jsx("circle",{cx:m.x,cy:m.y,r:3,fill:"currentColor"}),e.jsx("circle",{cx:m.x,cy:m.y,r:6,fill:"none",stroke:"currentColor",strokeWidth:"1",strokeDasharray:"2 2",opacity:.48})]}):null]})})]})}const _t="fixed left-1/2 z-50 -translate-x-1/2 overflow-y-auto border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] text-[var(--ui-ink)] shadow-[var(--card-shadow)] backdrop-blur-xl outline-none",La="rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",Le="border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]";function gs({open:t,anchor:a,items:r,onClose:s}){if(x.useEffect(()=>{if(!t)return;const u=g=>{g.key==="Escape"&&s()},p=()=>s();return window.addEventListener("keydown",u),window.addEventListener("pointerdown",p),()=>{window.removeEventListener("keydown",u),window.removeEventListener("pointerdown",p)}},[s,t]),!t||!a||typeof document>"u")return null;const l=Math.max(12,Math.min(a.top,window.innerHeight-360)),c=Math.max(220,window.innerHeight-l-96),m=Math.min(368,window.innerWidth-24),d=Math.max(12,Math.min(a.right,window.innerWidth-m-12));return Ua.createPortal(e.jsx("div",{className:"pointer-events-none fixed inset-0 z-[70]",children:e.jsxs("div",{className:"pointer-events-auto fixed z-[71] overflow-y-auto overscroll-contain rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--card-gradient)] p-2 shadow-[var(--card-shadow)] backdrop-blur-xl",style:{top:`${l}px`,right:`${d}px`,width:`${m}px`,maxHeight:`${c}px`},onPointerDown:u=>u.stopPropagation(),children:[e.jsxs(me,{className:"rounded-[22px] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:"Movement actions"}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:"Add boxes, inspect raw data, and adjust timeline overlays."})]}),e.jsx("div",{className:"mt-2 grid gap-1",children:r.map(u=>{const p=u.icon;return e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[20px] bg-[var(--ui-surface-1)] px-4 py-3 text-left text-[var(--ui-ink-medium)] transition hover:bg-[var(--ui-surface-hover)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{u.onSelect(),s()},children:[e.jsx("span",{className:"rounded-[14px] bg-[var(--ui-accent-soft)] p-2 text-[var(--primary)]",children:e.jsx(p,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:u.label}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-[var(--ui-ink-faint)]",children:u.description})]})]},u.id)})})]})}),document.body)}function fs({open:t,onOpenChange:a,segment:r,detail:s,loading:l,onEdit:c,onDefinePlace:m}){var g;const d=(s==null?void 0:s.segment)??r,u=(s==null?void 0:s.stayDetail)??null,p=(s==null?void 0:s.tripDetail)??null;return e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[6vh] max-h-[88vh] w-[min(60rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:d?`${ue(d)} details`:"Movement details"}),e.jsx(xt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Inspect the canonical box, the raw movement evidence behind it, and the exact coordinates Forge used to assemble this stay or trip."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[d?e.jsxs(A,{onClick:c,variant:"ghost",className:w("rounded-full px-3",Le),disabled:!d.editable||d.kind==="missing",children:[e.jsx(It,{className:"size-4"}),"Edit"]}):null,e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:w(La,"p-2"),children:e.jsx(Ft,{className:"size-4 rotate-45"})})})]})]}),l?e.jsx(me,{className:"mt-6 text-sm text-[var(--ui-ink-soft)]",children:"Loading the canonical box detail and raw movement evidence..."}):d?e.jsxs("div",{className:"mt-6 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(De,{label:"Started",value:ge(d.startedAt)}),e.jsx(De,{label:"Ended",value:ge(d.endedAt)}),e.jsx(De,{label:"Duration",value:qe(d.durationSeconds)}),e.jsx(De,{label:"Raw coverage",value:`${d.rawStayIds.length} stays · ${d.rawTripIds.length} trips · ${d.rawPointCount} points`})]}),u?e.jsxs(e.Fragment,{children:[e.jsxs(me,{className:"border-[var(--primary)]/20 bg-[var(--ui-accent-soft)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--primary)]",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-strong)]",children:u.canonicalPlace?`This stay is linked to ${u.canonicalPlace.label}. Search a different saved place or relabel it from the stay center.`:"This stay has no saved place yet. Search known locations first, or create a new place directly from the stay center."}),e.jsx("div",{className:"mt-3",children:e.jsx(A,{onClick:m,variant:"ghost",className:w("rounded-full px-4",Le),children:"Label location"})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(va,{title:"Stay positions",points:u.positions,averagePoint:u.averagePosition}),e.jsxs(k,{className:"rounded-[28px] p-5",children:[e.jsx(pa,{title:"Stay metrics",rows:[["Canonical place",((g=u.canonicalPlace)==null?void 0:g.label)??"Not linked yet"],["Average position",u.averagePosition?st(u.averagePosition.latitude,u.averagePosition.longitude):"Unavailable"],["Radius",u.radiusMeters!=null?Ie(u.radiusMeters):"Unavailable"],["Samples",String(u.sampleCount)]]}),e.jsxs(me,{muted:!0,className:"mt-4 rounded-[18px] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Exact positions"}),e.jsx("div",{className:"mt-3 grid gap-2",children:u.positions.map((j,P)=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[j.label??`Position ${P+1}`,":"," ",st(j.latitude,j.longitude)]},`${j.recordedAt??"stay"}-${P}`))})]})]})]})]}):null,p?e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(va,{title:"Travel map",points:p.positions}),e.jsx(k,{className:"rounded-[28px] p-5",children:e.jsx(pa,{title:"Trip metrics",rows:[["Start position",p.startPosition?st(p.startPosition.latitude,p.startPosition.longitude):"Unavailable"],["End position",p.endPosition?st(p.endPosition.latitude,p.endPosition.longitude):"Unavailable"],["Distance",Ie(p.totalDistanceMeters)],["Moving time",la(p.movingSeconds)],["Idle time",la(p.idleSeconds)],["Average speed",p.averageSpeedMps!=null?`${p.averageSpeedMps.toFixed(2)} m/s`:"Unavailable"],["Max speed",p.maxSpeedMps!=null?`${p.maxSpeedMps.toFixed(2)} m/s`:"Unavailable"],["Stops",String(p.stopCount)]]})})]}):null]}):null]})]})})}function bs({open:t,segment:a,onOpenChange:r,onEdit:s,onOpenDetail:l,onDefinePlace:c}){return e.jsx(Qe,{open:t,onOpenChange:r,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:"fixed left-1/2 top-[6vh] z-50 max-h-[88vh] w-[min(36rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] outline-none",children:[e.jsx(mt,{className:"sr-only",children:a?`${ue(a)} actions`:"Movement actions"}),e.jsx(xt,{className:"sr-only",children:"Inspect, edit, or label the selected movement box."}),a?e.jsx(hs,{segment:a,onEdit:s,onOpenDetail:l,onDefinePlace:c,onClose:()=>r(!1)}):null]})]})})}function ys({open:t,onOpenChange:a,segment:r,places:s,loading:l,onSelectPlace:c,onCreatePlace:m}){const d=r?Ct(r):null,[u,p]=x.useState("");x.useEffect(()=>{if(!t){p("");return}p(Fe(r)??"")},[t,r]);const g=x.useMemo(()=>{if(!d)return[];const b=he(u);return[...s].filter(C=>b.length===0?!0:$r(C).includes(b)).sort((C,E)=>{const K=he(C.label),Z=he(E.label),z=b.length>0&&K.startsWith(b),J=b.length>0&&Z.startsWith(b);if(z!==J)return z?-1:1;const G=lt(d.latitude,d.longitude,C.latitude,C.longitude),ee=lt(d.latitude,d.longitude,E.latitude,E.longitude);return Math.abs(G-ee)>1?G-ee:C.label.localeCompare(E.label)}).slice(0,6)},[s,u,d]),j=he(u),P=g.some(b=>he(b.label)===j),U=Fe(r);return e.jsx(Qe,{open:t,onOpenChange:a,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[8vh] max-h-[84vh] w-[min(38rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx($a,{title:"Label stay location",description:"Search saved locations by name first. If this stay is new, create a location from the stay center with latitude and longitude already filled in.",closeLabel:"Close location label dialog"}),d?e.jsxs(me,{className:"mt-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"signal",children:"Stay center"}),U?e.jsx(v,{tone:"meta",children:U}):null]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[e.jsx(De,{label:"Latitude",value:d.latitude.toFixed(6)}),e.jsx(De,{label:"Longitude",value:d.longitude.toFixed(6)})]})]}):e.jsx(me,{className:"mt-5 border-[var(--warning)]/20 text-sm text-[var(--ui-ink-soft)]",children:"Forge can only label stays that already have a recorded stay center."}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(B,{value:u,onChange:b=>p(b.target.value),placeholder:"Type a location name or create a new one"}),e.jsxs(me,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:"Known places"}),l?e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"Loading saved places..."}):g.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:g.map(b=>{const C=d==null?null:lt(d.latitude,d.longitude,b.latitude,b.longitude);return e.jsxs("button",{type:"button",onClick:()=>void c(b).then(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(v,{tone:"meta",children:[Ie(C)," away"]}):null]}),b.aliases.length>0||b.categoryTags.length>0?e.jsx("div",{className:"mt-1 text-xs text-[var(--ui-ink-faint)]",children:[...b.aliases,...b.categoryTags].join(" · ")}):null]},b.id)})}):e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-soft)]",children:"No saved place matches this stay yet."})]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx(A,{variant:"ghost",onClick:()=>a(!1),className:Le,children:"Cancel"}),e.jsx(A,{onClick:()=>{!r||!d||m(r,P?"":u.trim())},disabled:!r||!d,children:j.length>0&&!P?`Create "${u.trim()}"`:"Create new location"})]})]})]})})}function js({open:t,draft:a,creating:r,saving:s,preflight:l,preflightLoading:c,onDraftChange:m,onFitMissing:d,onSave:u,onOpenChange:p}){return e.jsx(Qe,{open:t,onOpenChange:p,children:e.jsxs(Ue,{children:[e.jsx(We,{className:"surface-overlay fixed inset-0 z-50 backdrop-blur-xl"}),e.jsxs(Ge,{className:w(_t,"top-[8vh] w-[min(34rem,calc(100vw-1.25rem))] rounded-[30px] p-5"),children:[e.jsx($a,{title:r?"Create movement box":"Edit movement box",description:a?r?"Create a canonical user-defined stay, move, or missing-data box without mutating raw phone measurements.":`Adjust this user-defined ${a.kind} box. Automatic boxes stay immutable and can only be invalidated.`:"No segment selected."}),a?e.jsxs("div",{className:"mt-5 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:["Kind",e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["stay","Stay"],["trip","Move"],["missing","Missing"]].map(([g,j])=>e.jsx(A,{type:"button",variant:"ghost",className:w(Le,a.kind===g?"ring-1 ring-[color-mix(in_srgb,var(--primary)_42%,transparent)]":""),onClick:()=>m({...a,kind:g}),children:j},g))})]}),e.jsx(Ke,{label:"Label",value:a.label,onChange:g=>m({...a,label:g})}),a.kind!=="trip"?e.jsx(Ke,{label:"Place",value:a.placeLabel,placeholder:"Home, Office, Riverside path...",onChange:g=>m({...a,placeLabel:g})}):null,e.jsx(Ke,{label:"Tags",value:a.tagsInput,placeholder:"movement, social, errand",onChange:g=>m({...a,tagsInput:g})}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsx(Ke,{label:"Started",type:"datetime-local",value:a.startedAtInput,onChange:g=>m({...a,startedAtInput:g})}),e.jsx(Ke,{label:"Ended",type:"datetime-local",value:a.endedAtInput,onChange:g=>m({...a,endedAtInput:g})})]}),e.jsxs(me,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-[var(--ui-ink-strong)]",children:"Overlap guidance"}),e.jsx(A,{type:"button",variant:"ghost",className:Le,onClick:d,disabled:!(l!=null&&l.nearestMissingStartedAt)||!(l!=null&&l.nearestMissingEndedAt),children:"Fit Missing Time"})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-soft)]",children:c?"Checking visible overlaps and missing windows...":l!=null&&l.overlapsAnything?`This box overlaps ${l.affectedAutomaticBoxIds.length} automatic and ${l.affectedUserBoxIds.length} manual boxes. Saving will fully override ${l.fullyOverriddenUserBoxIds.length} manual boxes and trim ${l.trimmedUserBoxIds.length}.`:"No overlap in the currently visible timeline window."}),e.jsxs("div",{className:"mt-3 grid gap-1 text-xs text-[var(--ui-ink-faint)]",children:[e.jsxs("div",{children:["Visible range:"," ",l!=null&&l.visibleRangeStart&&(l!=null&&l.visibleRangeEnd)?`${ge(l.visibleRangeStart)} -> ${ge(l.visibleRangeEnd)}`:"Unavailable"]}),e.jsxs("div",{children:["Suggested missing slot:"," ",l!=null&&l.nearestMissingStartedAt&&(l!=null&&l.nearestMissingEndedAt)?`${ge(l.nearestMissingStartedAt)} -> ${ge(l.nearestMissingEndedAt)}`:"No missing interval in view"]})]})]})]}):null,e.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[e.jsx(vt,{asChild:!0,children:e.jsx(A,{type:"button",variant:"ghost",className:Le,children:"Cancel"})}),e.jsxs(A,{onClick:u,disabled:!a||s,children:[e.jsx(Wa,{className:"size-4"}),s?"Saving...":r?"Create box":"Save changes"]})]})]})]})})}function $a({title:t,description:a,closeLabel:r}){return e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(mt,{className:"font-display text-[1.3rem] tracking-[-0.03em] text-[var(--ui-ink-strong)]",children:t}),e.jsx(xt,{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:a})]}),e.jsx(vt,{asChild:!0,children:e.jsx("button",{type:"button",className:w(La,"p-2"),"aria-label":r,children:r?e.jsx($t,{className:"size-4"}):e.jsx(Ft,{className:"size-4 rotate-45"})})})]})}function De({label:t,value:a}){return e.jsxs(me,{className:"rounded-[18px] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-strong)]",children:a})]})}function pa({title:t,rows:a}){return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-faint)]",children:t}),e.jsx("div",{className:"mt-4 grid gap-3",children:a.map(([r,s])=>e.jsxs("div",{className:"text-sm text-[var(--ui-ink-medium)]",children:[e.jsxs("span",{className:"text-[var(--ui-ink-faint)]",children:[r,": "]}),s]},r))})]})}function Ke({label:t,value:a,onChange:r,placeholder:s,type:l="text"}){return e.jsxs("label",{className:"grid gap-2 text-sm text-[var(--ui-ink-medium)]",children:[t,e.jsx(B,{type:l,value:a,placeholder:s,onChange:c=>r(c.target.value)})]})}function Ns({userIds:t=[]}){var Wt,Gt,Vt;const a=ya(),r=x.useRef(null),s=x.useRef(null),l=x.useRef(null),c=x.useRef(!1),m=x.useRef(!1),d=x.useRef(null),[u,p]=x.useState(null),[g,j]=x.useState(!1),[P,U]=x.useState(!1),[b,C]=x.useState(null),[E,K]=x.useState({}),[Z,z]=x.useState(null),[J,G]=x.useState(null),[ee,te]=x.useState(null),[Ve,Ee]=x.useState(null),[_e,Re]=x.useState(!1),[Ye,Se]=x.useState(!1),[ht,Me]=x.useState(null),[gt,ze]=x.useState(null),[re,W]=x.useState(!1),[se,ie]=x.useState(!1),[q,xe]=x.useState(!1),[y,Xe]=x.useState(""),[fe,Ze]=x.useState([]),[ve,Je]=x.useState(0),[O,Oe]=x.useState(0),Ae=()=>{const n=r.current;n&&(Je(n.scrollTop),Oe(n.clientHeight))},D=Yt({queryKey:["forge-movement-life-timeline",...t],initialPageParam:null,queryFn:({pageParam:n})=>Jt({before:n??void 0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),N=Yt({queryKey:["forge-movement-life-timeline-data",...t],initialPageParam:null,queryFn:({pageParam:n})=>Jt({before:n??void 0,includeInvalid:!0,limit:sa,userIds:t}).then(o=>o.movement),getNextPageParam:n=>n.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),be=x.useMemo(()=>{var n;return((n=D.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[D.data]),oe=x.useMemo(()=>{var n;return((n=N.data)==null?void 0:n.pages.flatMap(o=>o.segments))??[]},[N.data]),de=x.useMemo(()=>{var n;return((n=D.data)==null?void 0:n.pages.reduce((o,h)=>Math.max(o,h.invalidSegmentCount??0),0))??0},[D.data]),_=x.useMemo(()=>[...be].reverse(),[be]),T=x.useMemo(()=>[...oe].reverse(),[oe]),et=x.useMemo(()=>{var o;const n=new Map;for(const h of((o=D.data)==null?void 0:o.pages)??[])for(const R of h.sleepOverlays??[])n.set(R.id,R);return[...n.values()].sort((h,R)=>new Date(h.startedAt).getTime()-new Date(R.startedAt).getTime())},[D.data]),ye=x.useMemo(()=>Tr(_,et),[_,et]),S=x.useMemo(()=>q?ye:_,[_,ye,q]),He=x.useMemo(()=>ye.filter(n=>n.syncSource==="sleep overlay"),[ye]),ne=((Wt=He.at(-1))==null?void 0:Wt.id)??null,L=x.useMemo(()=>S.find(n=>n.id===ee)??null,[ee,S]),i=x.useMemo(()=>S.find(n=>n.id===u)??null,[S,u]),f=ae({queryKey:["forge-movement-box-detail",(L==null?void 0:L.boxId)??null,...t],queryFn:async()=>L!=null&&L.boxId?(await tr(L.boxId,t)).movement:null,enabled:!!(L!=null&&L.boxId)}),Q=x.useMemo(()=>_.find(n=>n.id===Ve)??null,[Ve,_]),V=ae({queryKey:["forge-movement-places",...t],queryFn:async()=>(await Sa(t)).places,retry:!1,refetchOnWindowFocus:!1}),M=x.useMemo(()=>Vr({segments:S,viewportHeight:O}),[S,O]),pe=x.useMemo(()=>new Map(M.items.map(n=>[n.segment.id,n])),[M.items]),Ce=x.useMemo(()=>{const n=Math.max(0,ve-ia),o=ve+Math.max(O,X*8)+ia;return M.items.filter(h=>h.segment.id===u?!0:h.boxBottom>=n&&h.boxTop<=o)},[ve,u,M.items,O]),zt=x.useMemo(()=>os(M,ve,O),[ve,M,O]),Fa=()=>{var o;const n=(o=l.current)==null?void 0:o.getBoundingClientRect();if(!n){U(h=>!h);return}C({top:n.bottom+10,right:Math.max(12,window.innerWidth-n.right)}),U(h=>!h)},Ea=x.useMemo(()=>[{id:"add-box",label:"Add box",description:"Create a user-defined stay, move, or missing-data interval.",icon:Ga,onSelect:()=>G(kt("stay",_.at(-1)??null))},{id:"sleep",label:q?"Hide sleep":"Show sleep",description:"Toggle sleep overlays without rewriting the movement boxes.",icon:ga,onSelect:()=>xe(n=>{const o=!n;return o&&ne&&(p(ne),j(!0)),o})},{id:"view-data",label:"View data",description:"Open the canonical loaded records and raw-data filters.",icon:wt,onSelect:()=>W(!0)}],[ne,_,q]),Ot=(n,o="smooth")=>{const h=r.current,R=pe.get(n);if(!h||!R)return;const Be=Math.max(0,R.boxTop-h.clientHeight/2+R.displayHeight/2);if(typeof h.scrollTo=="function"){h.scrollTo({top:Be,behavior:o});return}h.scrollTop=Be};x.useEffect(()=>{re&&(!N.hasNextPage||N.isFetchingNextPage||N.fetchNextPage())},[re,N.fetchNextPage,N.hasNextPage,N.isFetchingNextPage]),x.useEffect(()=>{const n=S.at(-1);!m.current&&n&&(m.current=!0,p(n.id))},[S]),x.useEffect(()=>{if(!c.current&&S.length>0){c.current=!0,requestAnimationFrame(()=>{var o;const n=(o=S[S.length-1])==null?void 0:o.id;n&&Ot(n,"auto"),requestAnimationFrame(()=>{Ae()})});return}if(d.current&&S.length>d.current.count&&r.current){const n=d.current;d.current=null,requestAnimationFrame(()=>{const o=r.current;if(!o)return;const h=M.totalHeight-n.size;o.scrollTop+=h,Ae()})}},[S.length,M.totalHeight,pe]),x.useEffect(()=>{if(!r.current)return;const o=()=>{Ae()};return o(),window.addEventListener("resize",o),()=>window.removeEventListener("resize",o)},[]),x.useEffect(()=>{if(!u)return;const n=_.find(o=>o.id===u);n&&K(o=>o[u]?o:{...o,[u]:Tt(n)})},[_,u]),x.useEffect(()=>{var n;u&&(S.some(o=>o.id===u)||(p(((n=S.at(-1))==null?void 0:n.id)??null),j(!1)))},[S,u]),x.useEffect(()=>{if(!q||!ne)return;const n=S.findIndex(o=>o.id===ne);n<0||(p(ne),requestAnimationFrame(()=>{var h;const o=(h=S[n])==null?void 0:h.id;o&&Ot(o)}))},[S,ne,q,pe]);const ft=async()=>{await Promise.all([a.invalidateQueries({queryKey:["forge-movement-life-timeline"]}),a.invalidateQueries({queryKey:["forge-movement-life-timeline-data"]}),a.invalidateQueries({queryKey:["forge-movement-box-detail"]}),a.invalidateQueries({queryKey:["forge-movement-day"]}),a.invalidateQueries({queryKey:["forge-movement-month"]}),a.invalidateQueries({queryKey:["forge-movement-all-time"]}),a.invalidateQueries({queryKey:["forge-movement-places"]}),a.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]})])},Ht=Pe({mutationFn:async n=>{const{segment:o,draft:h,creating:R}=n,Be=Pt(h,o);if(R){await Xt(Be,t);return}if(!o)throw new Error("No movement box selected.");if(o.sourceKind!=="user_defined")throw new Error("Automatic movement boxes are immutable. Invalidate them into missing data or create a user-defined override instead.");await Zt(o.boxId,{...Be,metadata:{updatedFrom:"movement-life-timeline"}},t)},onSuccess:ft}),_a=async(n,o)=>{if(n.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");const h=zr(n,o.label);if(n.sourceKind==="user_defined"){await Zt(n.boxId,{...h,metadata:{updatedFrom:"movement-life-timeline-place-label"}},t);return}await Xt({...h,metadata:{createdFrom:"movement-life-timeline-place-label"}},t)},Bt=async(n,o)=>{if(n.rawStayIds.length===0)throw new Error("This stay has no raw stay ids to relabel.");await Promise.all(n.rawStayIds.map(h=>er(h,{placeExternalUid:o.externalUid,placeLabel:o.label})))},Ra=(n,o)=>{const h=Ct(n);if(!h)return!0;const R=lt(h.latitude,h.longitude,o.latitude,o.longitude);return R<=100||typeof window>"u"||typeof window.confirm!="function"?!0:window.confirm(`"${o.label}" is ${Ie(R)} away from this stay's recorded center. Link it anyway?`)},za=Pe({mutationFn:async n=>{const{segment:o,...h}=n,R=await ja(h,t);return o&&le(o)&&await Bt(o,R.place),R},onSuccess:ft}),Oa=Pe({mutationFn:async n=>{const{segment:o,place:h}=n;if(!Ra(o,h))return{assigned:!1};if(le(o))return await Bt(o,h),{assigned:!0};if(o.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");return await _a(o,h),{assigned:!0}},onSuccess:async n=>{n.assigned&&await ft()}}),bt=Pe({mutationFn:async n=>{if(n.sourceKind==="user_defined"){await Za(n.boxId,t);return}await Ja(n.boxId,{title:"User invalidated automatic movement",subtitle:`Overrides ${ue(n)} with missing data.`},t)},onSuccess:async(n,o)=>{p(h=>h===o.id?null:h),j(!1),z(h=>h===o.id?null:h),a.setQueryData(["forge-movement-life-timeline",...t],h=>da(h,o.id)),a.setQueryData(["forge-movement-life-timeline-data",...t],h=>da(h,o.id)),await Promise.all([a.invalidateQueries({queryKey:["forge-movement-life-timeline"]}),a.invalidateQueries({queryKey:["forge-movement-life-timeline-data"]}),a.invalidateQueries({queryKey:["forge-movement-day"]}),a.invalidateQueries({queryKey:["forge-movement-month"]}),a.invalidateQueries({queryKey:["forge-movement-all-time"]}),a.invalidateQueries({queryKey:["forge-movement-selection"]}),a.invalidateQueries({queryKey:["forge-psyche-self-observation-calendar"]})])}}),Ha=x.useMemo(()=>Hr(T),[T]),je=x.useMemo(()=>{const n=he(y);return[...T].sort((o,h)=>new Date(h.endedAt).getTime()-new Date(o.endedAt).getTime()).filter(o=>(n.length===0||Or(o).includes(n))&&Br(o,fe))},[T,y,fe]),Kt=x.useMemo(()=>T.length===0?"No movement records loaded yet.":je.length===T.length&&y.trim().length===0&&fe.length===0?`${T.length} loaded movement records visible`:`${je.length} of ${T.length} loaded records visible`,[T.length,je.length,y,fe.length]),yt=ba({count:je.length,getScrollElement:()=>s.current,estimateSize:()=>136,overscan:8}),$=Z?_.find(n=>n.id===Z)??null:null,Ba=$?E[$.id]??Tt($):null,tt=J!==null,F=J??Ba,qt=((Gt=_[0])==null?void 0:Gt.startedAt)??null,Qt=((Vt=_[_.length-1])==null?void 0:Vt.endedAt)??null,jt=ae({queryKey:["forge-movement-user-box-preflight",($==null?void 0:$.boxId)??"create",(F==null?void 0:F.kind)??null,(F==null?void 0:F.startedAtInput)??null,(F==null?void 0:F.endedAtInput)??null,qt,Qt,...t],enabled:F!==null&&dt(F.startedAtInput)!==null&&dt(F.endedAtInput)!==null,queryFn:async()=>{if(!F)return null;const n=Pt(F,$);return(await ar({...n,excludeBoxId:($==null?void 0:$.sourceKind)==="user_defined"?$.boxId:null,rangeStart:qt,rangeEnd:Qt},t)).preflight}}),Ut=n=>{le(n)&&(Ee(n.id),Re(!0))},Ka=(n,o)=>{const h=Ct(n);h&&(Re(!1),Ee(n.id),Me({...h,label:o.trim()||h.label}),ze(n.id),Se(!0))},qa=()=>{const n=r.current;n&&(Je(n.scrollTop),Oe(n.clientHeight),!(!D.hasNextPage||D.isFetchingNextPage)&&n.scrollTop<=960&&(d.current={count:S.length,size:M.totalHeight},D.fetchNextPage()))};if(D.isPending)return e.jsx(Na,{eyebrow:"Movement",title:"Loading life timeline",description:"Reconstructing the longer road of stays, moves, and places.",columns:1,blocks:6});if(D.isError)return e.jsx(ka,{eyebrow:"Movement",error:D.error,onRetry:()=>void D.refetch()});const Qa=M.totalHeight;return e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(k,{className:"overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-3 sm:rounded-[34px] sm:p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 px-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.22em] text-[var(--ui-ink-muted)]",children:"Movement"}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-2",children:[de>0?e.jsxs(v,{className:w("hidden sm:inline-flex",Te),children:[de," invalid hidden"]}):null,e.jsxs(v,{className:"hidden bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] sm:inline-flex",children:[S.length," visible"]}),e.jsx("div",{ref:l,children:e.jsxs(A,{type:"button",variant:"ghost",size:"sm","aria-expanded":P,"aria-haspopup":"dialog",className:w("h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)] hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",P?Dt:""),onClick:Fa,children:[e.jsx(Va,{className:"size-4"}),"Actions"]})})]})]}),e.jsx(gs,{open:P,anchor:b,items:Ea,onClose:()=>U(!1)}),q&&He.length===0?e.jsx("p",{className:"mb-3 px-1 text-sm text-[color-mix(in_srgb,var(--warning)_72%,var(--ui-ink-strong)_28%)]",children:"No sleep session overlaps the currently loaded timeline range yet. Scroll further back to load older history."}):null,e.jsxs("div",{ref:r,onScroll:qa,className:"relative h-[82vh] overflow-auto rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-modal)]",children:[e.jsx(is,{layout:M,scrollTop:ve,viewportHeight:O}),zt?e.jsx("div",{className:"pointer-events-none sticky top-3 z-50 flex h-0 justify-center",children:e.jsx("div",{className:"rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-1.5 font-label text-[10px] uppercase tracking-[0.18em] text-[var(--ui-ink-medium)] shadow-[var(--ui-shadow-soft)] backdrop-blur-xl",children:zt})}):null,e.jsxs("div",{className:"relative",style:{height:`${Qa}px`},children:[M.historyHeaderHeight>0?e.jsx("div",{className:"absolute inset-x-0 top-0",style:{height:`${M.historyHeaderHeight}px`},children:e.jsx(ls,{segment:S[0]??null})}):null,Ce.map(n=>{const o=n.segment;return e.jsx(ds,{layout:n,selected:u===o.id,onToggle:()=>{p(o.id),j(!0)}},o.id)})]})]})]}),e.jsx(js,{open:$!==null||J!==null,segment:$,draft:F,creating:tt,saving:Ht.isPending,preflight:jt.data??null,preflightLoading:jt.isFetching,onDraftChange:n=>{if(tt){G(n);return}$&&K(o=>({...o,[$.id]:n}))},onFitMissing:()=>{const n=jt.data;if(!(n!=null&&n.nearestMissingStartedAt)||!n.nearestMissingEndedAt)return;const o={...F??kt("stay",$),startedAtInput:$e(n.nearestMissingStartedAt),endedAtInput:$e(n.nearestMissingEndedAt)};if(tt){G(o);return}$&&K(h=>({...h,[$.id]:o}))},onSave:()=>{F&&Ht.mutateAsync({segment:$,draft:F,creating:tt},{onSuccess:()=>{z(null),G(null),se&&(ie(!1),W(!0))}})},onOpenChange:n=>{n||(z(null),G(null),se&&(ie(!1),W(!0)))}}),e.jsx(bs,{open:g&&i!==null,onOpenChange:n=>{j(n)},segment:i,onEdit:()=>{i!=null&&i.editable&&(z(i.id),j(!1))},onOpenDetail:()=>{i&&(te(i.id),j(!1))},onDefinePlace:()=>{i&&(Ut(i),j(!1))}}),e.jsx(fs,{open:L!==null,onOpenChange:n=>{n||te(null)},segment:L,detail:f.data??null,loading:f.isFetching,onEdit:()=>{!L||!L.editable||(z(L.id),te(null))},onDefinePlace:()=>{L&&Ut(L)}}),e.jsx(ys,{open:_e,onOpenChange:n=>{Re(n),n||Ee(null)},segment:Q,places:V.data??[],loading:V.isFetching,onSelectPlace:async n=>Q?(await Oa.mutateAsync({segment:Q,place:n})).assigned:!1,onCreatePlace:(n,o)=>{Ka(n,o)}}),e.jsx(Aa,{open:Ye,onOpenChange:n=>{Se(n),n||(Me(null),ze(null))},place:null,seed:ht,onSave:async n=>{await za.mutateAsync({...n,segment:_.find(o=>o.id===gt)??null})}}),e.jsx(wa,{open:re,onOpenChange:n=>{W(n),n||se||(Xe(""),Ze([]))},eyebrow:"Movement data",title:"View data",description:"",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ma,{title:"",description:"",query:y,onQueryChange:Xe,options:Ha,selectedOptionIds:fe,onSelectedOptionIdsChange:Ze,resultSummary:Kt,placeholder:"Search movement labels, places, times, tags, or add time and kind filters",emptyStateMessage:"Keep typing or pick filters to narrow the movement history."}),e.jsxs(k,{className:"grid min-w-0 gap-3",children:[e.jsxs("div",{className:"flex min-w-0 flex-col items-start gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{className:"min-w-0 space-y-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Canonical boxes"}),e.jsx("div",{className:"max-w-3xl break-words text-sm leading-6 text-[var(--ui-ink-muted)]",children:"This list shows the canonical movement boxes projected by Forge. Automatic boxes are derived from immutable raw phone measurements. User-defined boxes override the projection without mutating raw movement data."})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-2",children:[e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)]",onClick:()=>{ie(!0),W(!1),G(kt("stay",je.at(-1)??null))},children:"Add box"}),e.jsx(v,{tone:"meta",children:Kt}),de>0?e.jsxs(v,{className:Te,children:[de," invalid hidden included"]}):null,N.hasNextPage?e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 text-[var(--ui-ink-medium)]",pending:N.isFetchingNextPage,pendingLabel:"Loading…",onClick:()=>void N.fetchNextPage(),children:"Load older"}):null]})]}),e.jsx("div",{ref:s,className:"h-[36rem] overflow-y-auto rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:je.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No movement record matches the current search. Clear filters or load older timeline history."}):e.jsx("div",{className:"relative w-full",style:{height:`${yt.getTotalSize()}px`},children:yt.getVirtualItems().map(n=>{var h;const o=je[n.index];return e.jsx("div",{ref:yt.measureElement,"data-index":n.index,className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${n.start}px)`},children:e.jsxs("div",{className:"flex items-start gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-3 py-2.5",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left transition hover:opacity-100",onClick:()=>{o.editable&&(ie(!0),W(!1),z(o.id))},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[o.kind==="stay"?e.jsx(fa,{className:"size-3.5 shrink-0 text-[var(--primary)]"}):o.kind==="missing"?e.jsx(wt,{className:"size-3.5 shrink-0 text-[var(--ui-ink-medium)]"}):e.jsx(ot,{className:"size-3.5 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-sm font-medium",children:ue(o)})]}),e.jsxs("div",{className:"mt-1 text-xs text-[var(--ui-ink-muted)]",children:[ut(o.startedAt)," →"," ",ut(o.endedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1.5",children:[e.jsx(v,{tone:o.kind==="trip"?"signal":"meta",children:o.kind==="trip"?"Move":o.kind==="missing"?"Missing":"Stay"}),e.jsx(v,{className:o.sourceKind==="user_defined"?"bg-[var(--ui-accent-soft)] text-[var(--primary)]":"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:o.sourceKind==="user_defined"?o.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),e.jsx(v,{tone:"meta",children:qe(o.durationSeconds)}),o.origin==="continued_stay"?e.jsx(v,{className:Da,children:"Continued stay"}):null,o.origin==="repaired_gap"?e.jsx(v,{className:Te,children:"Repaired"}):null,o.kind==="missing"?e.jsx(v,{className:as,children:"Missing"}):null,o.isInvalid?e.jsx(v,{className:Te,children:"Invalid"}):null,o.placeLabel?e.jsx(v,{tone:"default",children:o.placeLabel}):null,o.overrideCount>0?e.jsxs(v,{className:Te,children:["Overrides ",o.overrideCount]}):null,e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw stays ",o.rawStayIds.length]}),e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw trips ",o.rawTripIds.length]}),e.jsxs(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:["Raw points ",o.rawPointCount]}),o.hasLegacyCorrections?e.jsx(v,{className:Te,children:"Legacy corrections"}):null]})]})}),e.jsx(A,{type:"button",variant:"ghost",size:"sm",className:w("h-8 shrink-0 rounded-full border px-2.5",o.sourceKind==="user_defined"?rs:ss),pending:bt.isPending&&((h=bt.variables)==null?void 0:h.id)===o.id,pendingLabel:"",onClick:()=>{window.confirm(o.sourceKind==="user_defined"?`Delete ${ue(o)} and remove this user-defined box from every synced surface?`:`Invalidate ${ue(o)} into missing data and hide the automatic box everywhere?`)&&bt.mutateAsync(o)},children:e.jsx(Ya,{className:"size-3.5"})})]})},`${o.kind}:${o.id}:${o.startedAt}:${o.endedAt}:${n.index}`)})})})]})]})})]})}function ks(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}).format(new Date(t))}function ws(t,a){const r=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${r.format(new Date(t))} - ${r.format(new Date(a))}`}function H(t){return t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.round(t/60)}m`}function ke(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Ss(t,a){return t==="distanceMeters"?ke(a):t==="caloriesKcal"?`${Math.round(a)} kcal`:H(a)}function Ia(t){return t.trim().toLowerCase()}function pt(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function Rt(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ms(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function ha(t){return{recordedAt:Ms(t.recordedAt),latitude:String(t.latitude),longitude:String(t.longitude),accuracyMeters:t.accuracyMeters!=null?String(t.accuracyMeters):"",altitudeMeters:t.altitudeMeters!=null?String(t.altitudeMeters):"",speedMps:t.speedMps!=null?String(t.speedMps):"",isStopAnchor:t.isStopAnchor}}function As(t){return Ia([Rt(t.recordedAt),t.externalUid,t.isStopAnchor?"stop anchor stop":"path trace point",t.accuracyMeters!=null?`${Math.round(t.accuracyMeters)} meters accuracy`:"",pt(t.recordedAt)].join(" "))}function Cs(t){const a=new Map;return a.set("anchor:stop",{id:"anchor:stop",label:"Stop anchors",description:"Only the canonical pause anchors",badge:e.jsx(v,{tone:"meta",children:"Stop anchors"})}),a.set("anchor:path",{id:"anchor:path",label:"Path points",description:"Non-anchor trace points",badge:e.jsx(v,{tone:"meta",children:"Path points"})}),a.set("accuracy:precise",{id:"accuracy:precise",label:"Precise",description:"GPS accuracy below 20m",badge:e.jsx(v,{tone:"meta",children:"Precise"})}),a.set("accuracy:loose",{id:"accuracy:loose",label:"Loose accuracy",description:"GPS accuracy at or above 20m",badge:e.jsx(v,{tone:"meta",children:"Loose accuracy"})}),t.forEach(r=>{const s=pt(r.recordedAt);a.has(`time:${s}`)||a.set(`time:${s}`,{id:`time:${s}`,label:s,description:"Recorded during this time band",badge:e.jsx(v,{tone:"meta",className:"capitalize",children:s})})}),[...a.values()]}function Ts(t,a){return a.every(r=>r==="anchor:stop"?t.isStopAnchor:r==="anchor:path"?!t.isStopAnchor:r==="accuracy:precise"?t.accuracyMeters!=null&&t.accuracyMeters<20:r==="accuracy:loose"?t.accuracyMeters==null||t.accuracyMeters>=20:r.startsWith("time:")?pt(t.recordedAt)===r.slice(5):!0)}function Ps(t){if(t.length===0)return[];const a=Math.min(...t.map(d=>d.latitude)),r=Math.max(...t.map(d=>d.latitude)),s=Math.min(...t.map(d=>d.longitude)),l=Math.max(...t.map(d=>d.longitude)),c=Math.max(r-a,1e-4),m=Math.max(l-s,1e-4);return t.map(d=>({x:12+(d.longitude-s)/m*76,y:12+(1-(d.latitude-a)/c)*76}))}function Ds({curve:t,startLabel:a,endLabel:r,stopLabels:s}){const l=t.map((c,m)=>`${m===0?"M":"Q"} ${c.x} ${c.y}`).join(" ");return e.jsxs(k,{className:"overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Stylized trajectory"}),e.jsx(ce,{content:"This graph is a softened trip trace. It emphasizes rhythm, stops, and endpoints instead of raw GPS jitter."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"A softened path that prioritizes rhythm, stops, and landmarks over raw map noise."})]}),e.jsxs(v,{tone:"signal",children:[a," → ",r]})]}),e.jsxs("div",{className:"mt-5 rounded-[26px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("svg",{viewBox:"0 0 100 60",className:"h-48 w-full",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"movementGlow",children:[e.jsx("feGaussianBlur",{stdDeviation:"1.8",result:"blur"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"blur"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),e.jsx("path",{d:l,fill:"none",stroke:"var(--ui-ink-medium)",strokeWidth:"1.5",strokeDasharray:"2.8 2.8",filter:"url(#movementGlow)"}),t.map((c,m)=>e.jsx("g",{children:e.jsx("circle",{cx:c.x,cy:c.y,r:m===0||m===t.length-1?2.6:1.6,fill:m===0||m===t.length-1?"var(--ui-ink-strong)":"var(--info)"})},`${c.x}-${c.y}-${m}`))]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:s.map(c=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:c},c))})]})]})}function Ls({points:t}){const a=Ps(t),r=a.map((s,l)=>`${l===0?"M":"L"} ${s.x} ${s.y}`).join(" ");return e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Exact path"}),e.jsx(ce,{content:"This keeps the recent raw location points. Use it when you want the literal recorded trace instead of the cleaned movement graph."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-medium)]",children:"Recent raw points preserved by the companion before long-term simplification."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"var(--ui-surface-2)"}),e.jsx("path",{d:r,fill:"none",stroke:"var(--info)",strokeWidth:"1.6"}),a.map((s,l)=>e.jsx("circle",{cx:s.x,cy:s.y,r:l===0||l===a.length-1?2:1.1,fill:l===0||l===a.length-1?"var(--ui-ink-strong)":"var(--info)"},`${s.x}-${s.y}-${l}`))]})})]})}function $s({point:t,draft:a}){return e.jsxs(k,{className:"grid gap-4 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Raw datapoint"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Rt(t.recordedAt)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Raw phone measurements are immutable in product UI. To change the visible movement story, create or edit user-defined boxes in the Life Timeline instead."})]}),e.jsx(v,{tone:t.isStopAnchor?"signal":"meta",children:t.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Recorded at"}),e.jsx(B,{type:"datetime-local",value:a.recordedAt,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Speed (m/s)"}),e.jsx(B,{value:a.speedMps,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Latitude"}),e.jsx(B,{value:a.latitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Longitude"}),e.jsx(B,{value:a.longitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Accuracy (m)"}),e.jsx(B,{value:a.accuracyMeters,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:"Altitude (m)"}),e.jsx(B,{value:a.altitudeMeters,disabled:!0,placeholder:"Optional"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(A,{variant:"ghost",className:w("h-10 rounded-full border px-4",a.isStopAnchor?"border-[var(--primary)] bg-[var(--primary)]/16 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),disabled:!0,children:[e.jsx(ot,{className:"mr-2 size-4"}),a.isStopAnchor?"Stop anchor":"Path point"]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:["External id: ",e.jsx("span",{className:"text-[var(--ui-ink-medium)]",children:t.externalUid})]})]}),e.jsx("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"This browser is read-only now. Raw points stay immutable so the web app and iPhone can both project the same repaired canonical boxes from the backend."})]})}function Vs(){var ye,S,He,ne,L;const t=rr(),a=ya(),r=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[s,l]=x.useState("life"),[c,m]=x.useState(new Date().toISOString().slice(0,10)),[d,u]=x.useState(new Date().toISOString().slice(0,7)),[p,g]=x.useState(null),[j,P]=x.useState(!1),[U,b]=x.useState(!1),[C,E]=x.useState(""),[K,Z]=x.useState([]),[z,J]=x.useState(null),[G,ee]=x.useState(null),[te,Ve]=x.useState({stayIds:[],tripIds:[]}),[Ee,_e]=x.useState(!1),[Re,Ye]=x.useState(null),[Se,ht]=x.useState(""),[Me,gt]=x.useState("distanceMeters"),ze=x.useRef(null),re=ae({queryKey:["forge-movement-day",c,...r],queryFn:async()=>(await nr({date:c,userIds:r})).movement}),W=ae({queryKey:["forge-movement-month",d,...r],queryFn:async()=>(await lr({month:d,userIds:r})).movement}),se=ae({queryKey:["forge-movement-all-time",...r],queryFn:async()=>(await or(r)).movement}),ie=ae({queryKey:["forge-life-force",...r],queryFn:async()=>(await dr(r)).lifeForce}),q=ae({queryKey:["forge-movement-settings",...r],queryFn:async()=>(await cr(r)).settings}),xe=ae({queryKey:["forge-movement-places",...r],queryFn:async()=>(await Sa(r)).places}),y=ae({queryKey:["forge-movement-trip",p],queryFn:async()=>p?(await ur(p)).movement:null,enabled:!!p}),Xe=ae({queryKey:["forge-movement-selection",c,te.stayIds.join(","),te.tripIds.join(","),...r],queryFn:async()=>(await mr({...te,userIds:r})).movement,enabled:te.stayIds.length>0||te.tripIds.length>0}),fe=Pe({mutationFn:async i=>sr({trackingEnabled:i},r),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-settings"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]})}}),Ze=Pe({mutationFn:async i=>i.id?ir(i.id,i):ja(i,r),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-places"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]}),await a.invalidateQueries({queryKey:["forge-movement-all-time"]})}}),ve=x.useMemo(()=>{const i=xe.data??[],f=Se.trim().toLowerCase();return f?i.filter(Q=>[Q.label,...Q.aliases,...Q.categoryTags].join(" ").toLowerCase().includes(f)):i},[Se,xe.data]),Je=x.useMemo(()=>{var i;return Cs(((i=y.data)==null?void 0:i.trip.points)??[])},[(ye=y.data)==null?void 0:ye.trip.points]),O=x.useMemo(()=>{var Q;const i=((Q=y.data)==null?void 0:Q.trip.points)??[],f=Ia(C);return[...i].sort((V,M)=>new Date(M.recordedAt).getTime()-new Date(V.recordedAt).getTime()).filter(V=>(f.length===0||As(V).includes(f))&&Ts(V,K))},[C,K,(S=y.data)==null?void 0:S.trip.points]),Oe=x.useMemo(()=>{var f;const i=((f=y.data)==null?void 0:f.trip.points.length)??0;return i===0?"No raw datapoints on this trip yet.":O.length===i&&C.trim().length===0&&K.length===0?`${i} datapoints visible`:`${O.length} of ${i} datapoints visible`},[O.length,C,K.length,(He=y.data)==null?void 0:He.trip.points.length]),Ae=ba({count:O.length,getScrollElement:()=>ze.current,estimateSize:()=>96,overscan:8}),D=O.find(i=>i.id===z)??((ne=y.data)==null?void 0:ne.trip.points.find(i=>i.id===z))??O[0]??((L=y.data)==null?void 0:L.trip.points[0])??null;if(x.useEffect(()=>{if(U){if(!D){J(null),ee(null);return}J(D.id),ee(ha(D))}},[D,U]),x.useEffect(()=>{E(""),Z([]),J(null),ee(null),b(!1)},[p]),re.isLoading||W.isLoading||se.isLoading||q.isLoading||xe.isLoading)return e.jsx(Na,{eyebrow:"Movement",title:"Loading movement workspace",description:"Reconstructing stays, trips, and place intelligence across Forge.",columns:2,blocks:8});if(re.isError||W.isError||se.isError||q.isError||xe.isError||!re.data||!W.data||!se.data||!q.data)return e.jsx(ka,{eyebrow:"Movement",error:re.error??W.error??se.error??q.error??xe.error??new Error("Movement data unavailable"),onRetry:()=>{re.refetch(),W.refetch(),se.refetch(),q.refetch(),xe.refetch()}});const N=re.data,be=W.data,oe=se.data,de=q.data,_=N.segments.filter((i,f,Q)=>{const V=`${i.kind}:${i.id}:${i.startedAt}:${i.endedAt}`;return Q.findIndex(M=>`${M.kind}:${M.id}:${M.startedAt}:${M.endedAt}`===V)===f}),T=Xe.data??N.selectionAggregate,et=N.trips.reduce((i,f)=>i+at(f).totalAp,0);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(xr,{entityKind:"project",title:"Movement",description:"Turn passive place and travel signals into a real Forge domain: day rhythm, travel arcs, known landmarks, linked work, and reflective evidence.",badge:`${N.summary.tripCount} trips today`,actions:e.jsx("div",{className:"flex flex-wrap gap-2",children:["life","day","month","all_time"].map(i=>e.jsx(A,{variant:"ghost",className:w("h-9 rounded-full border px-4 text-sm",s===i?"border-[var(--primary)] bg-[var(--primary)]/16 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),onClick:()=>l(i),children:i==="all_time"?"All time":i==="life"?"Life":i.charAt(0).toUpperCase()+i.slice(1)},i))})}),e.jsxs(k,{className:"grid gap-3 rounded-[28px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Movement AP today"}),e.jsx("div",{className:"mt-2 text-3xl font-semibold text-[var(--ui-ink-strong)]",children:ea(et)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Trips and transitions now contribute to the same Action Point ledger as work, habits, and notes."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Typical trip drain"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:N.trips[0]?rt(at(N.trips[0]).rateApPerHour):"0 AP/h"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Movement uses a MET-like drain under the hood, translated into Forge Action Points."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Life Force sync"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--ui-ink-strong)]",children:ie.data?`${Math.round(ie.data.spentTodayAp??0)}/${Math.round(ie.data.dailyBudgetAp??0)} AP`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:ie.data?`${rt(ie.data.instantFreeApPerHour)} free right now`:"Movement can now be read against today’s live capacity."})]})]}),e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.65fr)_minmax(20rem,0.95fr)]",children:[e.jsx(vr,{children:e.jsxs(k,{className:"overflow-hidden rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Movement operating mode"}),e.jsx(ce,{content:"This is the passive capture state of the movement system: whether tracking is running, how much is published into Forge, and how aggressive retention is."})]}),e.jsx("div",{className:"mt-2 text-[clamp(1.05rem,1.8vw,1.35rem)] text-[var(--ui-ink-strong)]",children:"Background stays and trips as structured life evidence"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The companion samples quietly while stationary, switches to denser trip capture when you move, and keeps only simplified long-term traces."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:de.trackingEnabled?"Tracking on":"Tracking off"}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:de.publishMode.replaceAll("_"," ")}),e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4",onClick:()=>fe.mutate(!de.trackingEnabled),children:de.trackingEnabled?"Pause passive capture":"Enable passive capture"})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Distance today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:ke(N.summary.totalDistanceMeters)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Across trips, stops, and linked place changes."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Idle time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.totalIdleSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Time spent settled enough to count as a real stay."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Estimated phone time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.estimatedScreenTimeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Estimated from hourly Screen Time bins, not exact foreground traces."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:N.summary.knownPlaceCount}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Shared between Forge and the iPhone companion."})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Missing data"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.missingDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.missingCount," grey gap",N.summary.missingCount===1?"":"s"," where Forge had over one hour without enough movement signal."]})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Repaired gaps"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.repairedGapDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.repairedGapCount," inferred span",N.summary.repairedGapCount===1?"":"s"," classified as stay or move instead of leaving blank holes in the day."]})]}),e.jsxs(k,{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Continued stays"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:H(N.summary.continuedStayDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[N.summary.continuedStayCount," short stationary span",N.summary.continuedStayCount===1?"":"s"," carried forward so quiet home time stays continuous instead of disappearing."]})]})]})]})}),e.jsx(pr,{children:e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Selection aggregate"}),e.jsx(ce,{content:"When you select stays or trips, Forge totals their span, distance, work overlap, notes, and places here."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Select any combination of stays and trips to sum movement, time, and work evidence."}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Span"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.durationSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:ke(T.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Work overlap"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.trackedWorkSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notes"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.noteCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Estimated phone time"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(T.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.pickupCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:T.notificationCount})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:T.placeLabels.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i},i))}),T.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:T.topApps.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-info-soft)] text-[var(--ui-ink-medium)]",children:(i.displayName||i.bundleIdentifier)+" · "+H(i.totalActivitySeconds)},i.id))}):null,T.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:T.topCategories.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.categoryLabel},i.id))}):null]})})]}),s==="life"?e.jsx(hr,{children:e.jsxs("section",{className:"grid gap-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Life graph"}),e.jsx(ce,{content:"This graph shows the movement road of your life: stays are blocks, moves connect them, and the hour/day lines live in the background. Click a segment for details, then use edit when you want to correct it."})]})}),e.jsx(Ns,{userIds:r})]})}):null,s==="day"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.55fr)_minmax(22rem,1fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Day strip"}),e.jsx(ce,{content:"A compressed 24-hour strip. Each segment keeps its true order and duration, but the whole day stays navigable on one line."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"A single-row timeline from 00:00 to 24:00, always compressed into one navigable strip."})]}),e.jsx(B,{type:"date",value:c,onChange:i=>m(i.target.value),className:"w-[11rem]"})]}),e.jsx("div",{className:"mt-6 overflow-x-auto pb-2",children:e.jsxs("div",{className:"w-full min-w-full sm:min-w-[52rem]",children:[e.jsx("div",{className:"mb-3 flex justify-between text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:["00:00","06:00","12:00","18:00","24:00"].map(i=>e.jsx("span",{children:i},i))}),e.jsx("div",{className:"flex h-28 items-stretch overflow-hidden rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-2",children:_.map((i,f)=>{const Q=Math.max(9,i.durationSeconds/86400*100),V=i.kind==="stay"?te.stayIds.includes(i.id):i.kind==="trip"?te.tripIds.includes(i.id):!1;return e.jsxs("button",{type:"button",className:w("relative flex min-w-0 flex-col justify-between rounded-[22px] border px-3 py-2 text-left transition sm:min-w-[5.5rem]",i.kind==="missing"?"border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":V?"border-[color-mix(in_srgb,var(--info)_34%,transparent)] bg-[var(--ui-info-soft)]":"border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]"),style:{width:`${Q}%`},onClick:()=>{i.kind!=="missing"&&Ve(M=>{const pe=new Set(M.stayIds),Ce=new Set(M.tripIds);return i.kind==="stay"?pe.has(i.id)?pe.delete(i.id):pe.add(i.id):Ce.has(i.id)?Ce.delete(i.id):(Ce.add(i.id),g(i.id)),{stayIds:[...pe],tripIds:[...Ce]}})},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(v,{tone:i.kind==="trip"?"signal":i.kind==="missing"?"meta":"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.kind==="missing"?"gap":i.kind}),e.jsx("span",{className:"text-[11px] text-[var(--ui-ink-muted)]",children:H(i.durationSeconds)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"line-clamp-2 text-sm font-semibold text-[var(--ui-ink-strong)]",children:i.label}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-[var(--ui-ink-muted)]",children:i.subtitle})]})]},`${i.kind}:${i.id}:${i.startedAt}:${i.endedAt}:${f}`)})})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:ks(c)}),e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[N.summary.tripCount," trips"]}),e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[N.summary.stayCount," stays"]}),e.jsxs(v,{tone:"meta",children:[N.summary.missingCount," gaps"]})]})]}),e.jsx("div",{className:"grid gap-4",children:y.data?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Selected trip"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(A,{variant:"ghost",className:"h-9 rounded-full border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4",onClick:()=>P(i=>!i),children:j?"Stylized graph":"Exact path"})})]}),j?e.jsx(Ls,{points:y.data.trip.points}):e.jsx(Ds,{curve:y.data.stylizedPath.curve,startLabel:y.data.stylizedPath.startLabel,endLabel:y.data.stylizedPath.endLabel,stopLabels:y.data.stylizedPath.stops.map(i=>i.label)}),e.jsxs(k,{className:"rounded-[28px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Trip context"}),(()=>{const i=at(y.data.trip);return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(v,{tone:"signal",children:ke(y.data.trip.distanceMeters)}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:y.data.trip.activityType||y.data.trip.travelMode}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:H(y.data.trip.durationSeconds)}),e.jsx(v,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:rt(i.rateApPerHour)}),e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:ea(i.totalAp)})]})})})(),e.jsx("div",{className:"mt-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:ws(y.data.trip.startedAt,y.data.trip.endedAt)}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Hourly estimate"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:H(y.data.trip.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y.data.trip.pickupCount})]}),e.jsxs("div",{className:"rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y.data.trip.notificationCount})]})]}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-[var(--ui-ink-muted)]",children:"Derived from Screen Time hourly bins, not exact foreground traces."}),y.data.trip.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:y.data.trip.topApps.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-info-soft)] text-[var(--ui-ink-medium)]",children:(i.displayName||i.bundleIdentifier)+" · "+H(i.totalActivitySeconds)},i.id))}):null,y.data.trip.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:y.data.trip.topCategories.map(i=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:i.categoryLabel},i.id))}):null]})]}):e.jsx(k,{className:"rounded-[30px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-6 text-[var(--ui-ink-muted)]",children:"Select a trip segment to open the stylized trajectory card and exact path toggle."})})]}):null,s==="month"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(18rem,0.85fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Month view"}),e.jsx(ce,{content:"This chart stays quantitative. Switch the metric to compare daily distance, moving time, idle time, or calories across the month."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"Switch the Y-axis between motion, idle time, and energy without losing the same monthly frame."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(B,{type:"month",value:d,onChange:i=>u(i.target.value),className:"w-[10.5rem]"}),["distanceMeters","movingSeconds","idleSeconds","caloriesKcal"].map(i=>e.jsx(A,{variant:"ghost",className:w("h-9 rounded-full border px-4 text-sm",Me===i?"border-[var(--primary)] bg-[var(--primary)]/14 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]"),onClick:()=>gt(i),children:i==="distanceMeters"?"Distance":i==="movingSeconds"?"Moving":i==="idleSeconds"?"Idle":"Calories"},i))]})]}),e.jsx("div",{className:"mt-6 h-[24rem]",children:e.jsx(br,{width:"100%",height:"100%",children:e.jsxs(yr,{data:be.days,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"movementMonthFill",x1:"0",x2:"0",y1:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"var(--info)",stopOpacity:.7}),e.jsx("stop",{offset:"100%",stopColor:"var(--info)",stopOpacity:.08})]})}),e.jsx(jr,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(Nr,{dataKey:"dateKey",tick:{fill:"var(--ui-ink-muted)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(kr,{tick:{fill:"var(--ui-ink-muted)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(wr,{contentStyle:{background:"var(--ui-surface-modal)",border:"1px solid var(--ui-border-subtle)",borderRadius:16},itemStyle:{color:"var(--ui-ink-strong)"},labelStyle:{color:"var(--ui-ink-medium)"},formatter:i=>Ss(Me,Number(i))}),e.jsx(Sr,{type:"monotone",dataKey:Me,stroke:"var(--info)",fill:"url(#movementMonthFill)",strokeWidth:2.4})]})})})]}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Month totals"}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:ke(be.totals.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Moving time"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:H(be.totals.movingSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Settled time"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:H(be.totals.idleSeconds)})]})]})]})]}):null,s==="all_time"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(20rem,0.95fr)]",children:[e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Trips"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.tripCount})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.knownPlaceCount})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:ke(oe.summary.totalDistanceMeters)})]}),e.jsxs(k,{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Countries"}),e.jsx("div",{className:"mt-2 text-3xl text-[var(--ui-ink-strong)]",children:oe.summary.visitedCountries})]})]}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:oe.recentTrips.map(i=>e.jsx("button",{type:"button",className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-left transition hover:bg-[var(--ui-surface-3)]",onClick:()=>{l("day"),g(i.id)},children:(()=>{const f=at({startedAt:i.startedAt,endedAt:new Date(new Date(i.startedAt).getTime()+36e5).toISOString(),expectedMet:2});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent travel"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:i.label||"Untitled trip"}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[ke(i.distanceMeters)," · ",i.activityType||"travel"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(v,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:rt(f.rateApPerHour)})})]})})()},i.id))})]}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Place categories"}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:oe.categoryBreakdown.map(i=>e.jsxs(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:[i.tag," · ",i.count]},i.tag))})]})]}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(22rem,0.95fr)]",children:[e.jsx(gr,{children:e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Known places"}),e.jsx(ce,{content:"Known places turn raw stationary spans into named contexts like home, work, gym, nature, or any custom place tag you want Forge to remember."})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:"These landmarks anchor stays, travel XP, and contextual reasoning in both Forge and the companion. Seeded tags like home, workplace, gym, holiday, grocery, or nature matter for downstream calculations, but place tags stay open-ended."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(B,{value:Se,onChange:i=>ht(i.target.value),placeholder:"Search places",className:"w-[11rem]"}),e.jsx(A,{onClick:()=>{Ye(null),_e(!0)},children:"Add place"})]})]}),e.jsx("div",{className:"mt-5 grid gap-3",children:ve.map(i=>e.jsxs("button",{type:"button",className:"flex items-start justify-between gap-3 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4 text-left transition hover:bg-[var(--ui-surface-3)]",onClick:()=>{Ye(i),_e(!0)},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:i.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[i.latitude.toFixed(4),", ",i.longitude.toFixed(4)," · radius ",Math.round(i.radiusMeters)," m"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:i.categoryTags.map(f=>e.jsx(v,{tone:"default",className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:f},f))})]}),e.jsx(It,{className:"mt-1 size-4 text-[var(--ui-ink-muted)]"})]},i.id))})]})}),e.jsxs(k,{className:"rounded-[30px] border border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Movement help"}),e.jsx(ce,{content:"Most movement surfaces on this page have help buttons. Use them to understand the graph, the day strip, the month chart, and the place system without keeping a large prose block on screen."})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Use the small help icons across this page for graph explanations, timeline semantics, and metric meanings."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Life graph"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Day strip"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Month chart"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Known places"}),e.jsx(v,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:"Selection aggregate"})]})]})]}),y.data?e.jsx(wa,{open:U,onOpenChange:i=>{b(i),i||(E(""),Z([]),J(null),ee(null))},eyebrow:"Movement data",title:y.data.trip.label||"Trip datapoints",description:"Inspect the raw datapoints behind this trip. Raw measurements are read-only here; visible movement corrections now happen through canonical user-defined boxes.",children:e.jsx(fr,{children:e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,24rem)_minmax(0,1fr)]",children:[e.jsxs("div",{className:"grid gap-4",children:[e.jsx(Ma,{title:"Datapoint browser",description:"Search raw points by time band, anchor status, or accuracy before opening the point editor.",query:C,onQueryChange:E,options:Je,selectedOptionIds:K,onSelectedOptionIdsChange:Z,resultSummary:Oe,placeholder:"Search timestamps, accuracy, point ids, or filter chips",emptyStateMessage:"Keep typing or pick a time/quality chip to narrow the trip datapoints."}),e.jsxs(k,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw datapoints"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Open a point to correct or delete it."})]}),e.jsx(v,{tone:"meta",children:Oe})]}),e.jsx("div",{ref:ze,className:"h-[34rem] overflow-y-auto rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:O.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No datapoint matches the current search. Clear some filters or search by time, anchor type, or accuracy."}):e.jsx("div",{className:"relative w-full",style:{height:`${Ae.getTotalSize()}px`},children:Ae.getVirtualItems().map(i=>{const f=O[i.index];return e.jsx("div",{className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${i.start}px)`},children:e.jsxs("button",{type:"button",className:w("grid w-full gap-3 rounded-[20px] border px-4 py-3 text-left transition",z===f.id?"border-[color-mix(in_srgb,var(--info)_34%,transparent)] bg-[var(--ui-info-soft)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] hover:bg-[var(--ui-surface-3)]"),onClick:()=>{J(f.id),ee(ha(f))},children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[var(--ui-ink-strong)]",children:[e.jsx(Xa,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:Rt(f.recordedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:[f.latitude.toFixed(5),", ",f.longitude.toFixed(5)]})]}),e.jsx(v,{tone:f.isStopAnchor?"signal":"meta",children:f.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:pt(f.recordedAt)}),f.accuracyMeters!=null?e.jsxs(v,{tone:"meta",children:[Math.round(f.accuracyMeters)," m accuracy"]}):null,f.speedMps!=null?e.jsxs(v,{tone:"meta",children:[f.speedMps.toFixed(1)," m/s"]}):null]})]})},f.id)})})})]})]}),D&&G?e.jsx($s,{point:D,draft:G}):e.jsx(k,{className:"rounded-[28px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-6 text-[var(--ui-ink-muted)]",children:"Pick a datapoint to inspect its raw measurement details. To correct what the user sees, use canonical user-defined movement boxes in the Life Timeline."})]})})}):null,e.jsx(Aa,{open:Ee,onOpenChange:_e,place:Re,onSave:async i=>{await Ze.mutateAsync(i)}})]})}export{Vs as MovementPage};