forge-openclaw-plugin 0.2.100 → 0.2.101

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 (103) hide show
  1. package/dist/assets/{activity-page-5oyCFOns.js → activity-page-CpjuNSHw.js} +1 -1
  2. package/dist/assets/{ai-surface-workspace-qgk_B57-.js → ai-surface-workspace-DEAFZruS.js} +1 -1
  3. package/dist/assets/{atlas-panel-rfH2qOez.js → atlas-panel-CdVNPotj.js} +1 -1
  4. package/dist/assets/{calendar-page-Bo2iua-a.js → calendar-page-DNNt6lfz.js} +1 -1
  5. package/dist/assets/{calendar-rules-DA1g3QUk.js → calendar-rules-DNJFNsxi.js} +1 -1
  6. package/dist/assets/{calendar-week-toolbar-DU1Q4RYj.js → calendar-week-toolbar-BbPwYeN0.js} +1 -1
  7. package/dist/assets/{companion-sync-lab-page-CosNknOK.js → companion-sync-lab-page-KxEDigM6.js} +1 -1
  8. package/dist/assets/{daily-metrics-dashboard-LjuGAB3f.js → daily-metrics-dashboard-B3cqJgDt.js} +1 -1
  9. package/dist/assets/{entity-note-count-link-BmGDB572.js → entity-note-count-link-DrhjJZ4i.js} +1 -1
  10. package/dist/assets/{entity-notes-surface-DgEgicaE.js → entity-notes-surface-CkcRsKJQ.js} +1 -1
  11. package/dist/assets/{execution-board-CDRXQB85.js → execution-board-D07gOocB.js} +1 -1
  12. package/dist/assets/{faceted-token-search-CE1YauRd.js → faceted-token-search-BxRRcM3q.js} +1 -1
  13. package/dist/assets/{flagship-signal-deck-DDds90Gl.js → flagship-signal-deck-cmy82b8_.js} +1 -1
  14. package/dist/assets/{floating-action-menu-CJkI2iFy.js → floating-action-menu-Fs_ZiUMo.js} +1 -1
  15. package/dist/assets/{goal-detail-page-cJvHaLMQ.js → goal-detail-page-CqLiNz4f.js} +1 -1
  16. package/dist/assets/{goals-page-f_39hvUV.js → goals-page-BTk7mg_T.js} +1 -1
  17. package/dist/assets/{habits-page-DKb96_mj.js → habits-page-BJxagdzx.js} +1 -1
  18. package/dist/assets/{index-BHTUu_4M.js → index-CF4J4R9L.js} +2 -2
  19. package/dist/assets/{insight-flow-dialog-pzAzyayN.js → insight-flow-dialog-8f3D0GuC.js} +1 -1
  20. package/dist/assets/{insights-page-Dc9oFltJ.js → insights-page-D6rOa7uk.js} +1 -1
  21. package/dist/assets/{kanban-page-JAxerYh6.js → kanban-page-XQ7Se6dH.js} +1 -1
  22. package/dist/assets/{knowledge-graph-page-UQ3skqEi.js → knowledge-graph-page-BtAg8iv3.js} +1 -1
  23. package/dist/assets/{life-force-page-BGDbQuVh.js → life-force-page-Dy0JTS2G.js} +1 -1
  24. package/dist/assets/{life-force-workspace-B1fYSXRC.js → life-force-workspace-OfyB9HJM.js} +1 -1
  25. package/dist/assets/{metric-tile-DX6TclqM.js → metric-tile-DKpo-8xw.js} +1 -1
  26. package/dist/assets/{movement-page-6HP6nGJx.js → movement-page-Bg_T_Stx.js} +1 -1
  27. package/dist/assets/{note-markdown-DiW2-5d3.js → note-markdown-N-uxD3Xt.js} +1 -1
  28. package/dist/assets/{note-tags-input-DDLXf54U.js → note-tags-input-Cdu7wiw6.js} +1 -1
  29. package/dist/assets/{notes-page-BuguDjhz.js → notes-page-CKXnF_KU.js} +1 -1
  30. package/dist/assets/{open-in-graph-button-Cg5VrKsC.js → open-in-graph-button-IXe9SGth.js} +1 -1
  31. package/dist/assets/{orbit-map-GD05-0oS.js → orbit-map-Dzi6KliQ.js} +1 -1
  32. package/dist/assets/{overview-page-DuOs2OCB.js → overview-page-1miYqaVS.js} +1 -1
  33. package/dist/assets/{page-hero-CQWo1Mm_.js → page-hero-DRy5b2MU.js} +1 -1
  34. package/dist/assets/{pill-cluster-BJogDRDJ.js → pill-cluster-C9QczVJ2.js} +1 -1
  35. package/dist/assets/{preference-entity-handoff-button-D4WAs9pC.js → preference-entity-handoff-button-5PzUn42S.js} +1 -1
  36. package/dist/assets/{preferences-page-BaJTMU1I.js → preferences-page-DtNaF5Q3.js} +1 -1
  37. package/dist/assets/{project-collections-DvaX20q_.js → project-collections-xPz2mlRr.js} +1 -1
  38. package/dist/assets/{project-detail-page-drPIFZGb.js → project-detail-page-BXK5-4xW.js} +1 -1
  39. package/dist/assets/{project-management-hierarchy-page-BUbRXvny.js → project-management-hierarchy-page-DtRpMABw.js} +1 -1
  40. package/dist/assets/{project-management-section-nav-C2Ud8Zdd.js → project-management-section-nav-P3ixzPa-.js} +1 -1
  41. package/dist/assets/{projects-page-BGzEZUtg.js → projects-page-C5ViRuf4.js} +1 -1
  42. package/dist/assets/{psyche-behaviors-page-Dmm_Io9D.js → psyche-behaviors-page-Dco46sC4.js} +1 -1
  43. package/dist/assets/{psyche-flashcards-page-BgNKJ6QJ.js → psyche-flashcards-page-ZcoEB8gV.js} +1 -1
  44. package/dist/assets/{psyche-goal-map-page-DXJs98Vr.js → psyche-goal-map-page-CLBAQOI0.js} +1 -1
  45. package/dist/assets/{psyche-graph-CFgs_Bqc.js → psyche-graph-k4tX2tdp.js} +1 -1
  46. package/dist/assets/{psyche-metrics-page-zYTJDbyZ.js → psyche-metrics-page-CuR9oqEy.js} +1 -1
  47. package/dist/assets/{psyche-mode-guide-page-XPgRfCOf.js → psyche-mode-guide-page-hIVXcCnE.js} +1 -1
  48. package/dist/assets/{psyche-modes-page-B-GA8oRF.js → psyche-modes-page-0lYtBlhO.js} +1 -1
  49. package/dist/assets/{psyche-page--r6a3e1t.js → psyche-page-VZ9k9ISp.js} +1 -1
  50. package/dist/assets/{psyche-patterns-page-BM5-3bMm.js → psyche-patterns-page-gx5nmdGq.js} +1 -1
  51. package/dist/assets/{psyche-questionnaire-builder-page-CJshQ-mg.js → psyche-questionnaire-builder-page-Bn0TOISd.js} +1 -1
  52. package/dist/assets/{psyche-questionnaire-detail-page-USmR5G5A.js → psyche-questionnaire-detail-page-CmVzSd_s.js} +1 -1
  53. package/dist/assets/{psyche-questionnaire-run-detail-page-D7iBCmTi.js → psyche-questionnaire-run-detail-page-BsMbmXCG.js} +1 -1
  54. package/dist/assets/{psyche-questionnaire-run-page-Cpil-kDh.js → psyche-questionnaire-run-page-CgkRL2vi.js} +1 -1
  55. package/dist/assets/{psyche-questionnaires-page-C-_y3VwS.js → psyche-questionnaires-page-D7V8uLXM.js} +1 -1
  56. package/dist/assets/{psyche-report-detail-page--dkSPRaj.js → psyche-report-detail-page-OlFq57eL.js} +1 -1
  57. package/dist/assets/{psyche-reports-page-CUaOXmIN.js → psyche-reports-page-dVUZjna1.js} +1 -1
  58. package/dist/assets/{psyche-schemas-beliefs-page-BX6xaap3.js → psyche-schemas-beliefs-page-BCgc8FUd.js} +1 -1
  59. package/dist/assets/{psyche-screen-time-page-CAAI4mD7.js → psyche-screen-time-page-B_6BT_WN.js} +1 -1
  60. package/dist/assets/{psyche-self-observation-page-BZ6FLuwa.js → psyche-self-observation-page-CEG5mluK.js} +1 -1
  61. package/dist/assets/{psyche-values-page-yEV6MGt8.js → psyche-values-page-DRbRfEd6.js} +1 -1
  62. package/dist/assets/{report-chain-fields-fZ8Xd4H6.js → report-chain-fields-CALCV3V5.js} +1 -1
  63. package/dist/assets/{rewards-page-C2HQjIAf.js → rewards-page-DmC4R_Ps.js} +1 -1
  64. package/dist/assets/{scheduling-rules-editor-BHOpHOrV.js → scheduling-rules-editor-D02s70hr.js} +1 -1
  65. package/dist/assets/{schema-badge-DyKbxb51.js → schema-badge-BZO-qNhO.js} +1 -1
  66. package/dist/assets/{select-menu-BX-pZNqL.js → select-menu-fYyreSdQ.js} +1 -1
  67. package/dist/assets/{settings-agents-page-VuYXTiyc.js → settings-agents-page-C_v_hMJF.js} +1 -1
  68. package/dist/assets/{settings-bin-page-BNzvYaOk.js → settings-bin-page-DY5bg81n.js} +1 -1
  69. package/dist/assets/{settings-calendar-page-CjSFB53S.js → settings-calendar-page-D1CzE6cg.js} +1 -1
  70. package/dist/assets/{settings-data-page-CGSlryuI.js → settings-data-page-CHRQFU9H.js} +1 -1
  71. package/dist/assets/{settings-logs-page-BTK5fine.js → settings-logs-page-B04pUwEv.js} +1 -1
  72. package/dist/assets/{settings-mobile-page-CRaObOGo.js → settings-mobile-page-D9kTlYDS.js} +1 -1
  73. package/dist/assets/{settings-models-page-DFshpYF8.js → settings-models-page-D26270R2.js} +1 -1
  74. package/dist/assets/{settings-page-BP81Mb5R.js → settings-page-DYDTFlnv.js} +1 -1
  75. package/dist/assets/{settings-rewards-page-CDJ1PH2G.js → settings-rewards-page-cl4vqqO_.js} +1 -1
  76. package/dist/assets/{settings-section-nav-CCFm27r2.js → settings-section-nav-DSOuht_F.js} +1 -1
  77. package/dist/assets/{settings-users-page-TdUocFPa.js → settings-users-page-BU79JB_T.js} +1 -1
  78. package/dist/assets/{settings-wiki-page-B2zX0QQG.js → settings-wiki-page-DwAUlyA3.js} +1 -1
  79. package/dist/assets/{sleep-page-cI1GMVzk.js → sleep-page-D8NbdhyS.js} +1 -1
  80. package/dist/assets/{sports-page-06LTqp0V.js → sports-page-CV4Cnzwn.js} +1 -1
  81. package/dist/assets/{strategies-page-DXP9Kx8s.js → strategies-page-C4qvXnql.js} +1 -1
  82. package/dist/assets/{strategy-detail-page-D6mx_Mik.js → strategy-detail-page-DJLo5rfy.js} +1 -1
  83. package/dist/assets/{strategy-dialog-BvzomTaF.js → strategy-dialog-D3AuUlVz.js} +1 -1
  84. package/dist/assets/{task-detail-page-BIWIggdp.js → task-detail-page-z-9u9rF0.js} +1 -1
  85. package/dist/assets/{timebox-planning-dialog-CaCnoslG.js → timebox-planning-dialog-DB6FLqmI.js} +1 -1
  86. package/dist/assets/{today-page-DO2mRPT2.js → today-page-BKlu6gx5.js} +1 -1
  87. package/dist/assets/{training-load-page-CyZ0mlEr.js → training-load-page-CyJQqo_3.js} +1 -1
  88. package/dist/assets/{vitals-page-BQvEjTc6.js → vitals-page-qre17Nw8.js} +1 -1
  89. package/dist/assets/{weekly-review-page-Tp6Q9CRj.js → weekly-review-page-Cz4vkRcx.js} +1 -1
  90. package/dist/assets/weight-loss-page-BQrnOI0y.js +1 -0
  91. package/dist/assets/{wiki-article-markdown-DQYohmW2.js → wiki-article-markdown-DdiR2TJE.js} +1 -1
  92. package/dist/assets/{wiki-editor-page-Dem_3eZv.js → wiki-editor-page-DqwoqVFb.js} +1 -1
  93. package/dist/assets/{wiki-ingest-history-page-BxoOcCoJ.js → wiki-ingest-history-page--evBLbOw.js} +1 -1
  94. package/dist/assets/{wiki-ingest-modal-DhguKk3J.js → wiki-ingest-modal--ohzFnj2.js} +1 -1
  95. package/dist/assets/{wiki-page-BLRxVXkl.js → wiki-page-B_VJFBPA.js} +1 -1
  96. package/dist/assets/{workbench-flow-page-DqMkCCTy.js → workbench-flow-page-Du62mtJU.js} +1 -1
  97. package/dist/assets/{workbench-page-BWd02wPw.js → workbench-page-4MKr3iRm.js} +1 -1
  98. package/dist/assets/{workout-detail-page-BD8u7GyL.js → workout-detail-page-DfUbYYw1.js} +1 -1
  99. package/dist/index.html +1 -1
  100. package/dist/server/server/src/watch-mobile.js +22 -10
  101. package/openclaw.plugin.json +1 -1
  102. package/package.json +1 -1
  103. package/dist/assets/weight-loss-page-BBzlhLVV.js +0 -1
@@ -1 +1 @@
1
- import{r as x,j as e,aK as Nt,b4 as Ca,cq as aa,cr as pt,cs as sa,ct as Pa,c3 as ia,aZ as tt,c7 as La,o as Da,bg as St,bX as Ia,c4 as Mt,bc as $a}from"./vendor-DHkYh85p.js";import{j as ra,x as Rt,i as te,k as ke}from"./state-B-4sS1xO.js";import{I as P,B as k,aY as Ot,aZ as Ht,a_ as na,a$ as Fa,b0 as Ea,S as la,E as da,C as v,c as u,Z as O,aS as oa,b1 as _a,b2 as Kt,b3 as za,b4 as ca,b5 as Ra,u as Oa,b6 as Ha,b7 as Ka,b8 as Xe,h as Bt,d as Ze,b9 as Ba,aq as ce,ba as qa,bb as Qa,bc as Ua,bd as Wa,be as Ga,bf as Va,bg as Ya,O as Xa,bh as Za,bi as Ja,bj as es}from"./index-BHTUu_4M.js";import{F as ma}from"./faceted-token-search-CE1YauRd.js";import{P as ts}from"./page-hero-CQWo1Mm_.js";import{R as Re,P as Oe,O as He,C as Ke,T as Be,D as qe,a as _e}from"./ui-C13Nbgas.js";import{m as qt}from"./motion-BeD44FeG.js";import{R as as,A as ss,C as is,X as rs,Y as ns,T as ls,a as ds}from"./charts-P7EVhIog.js";import"./board-BkDRaMp6.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function xa({open:t,onOpenChange:a,place:s,seed:i,onSave:c}){const[r,h]=x.useState({label:(s==null?void 0:s.label)??(i==null?void 0:i.label)??"",latitude:String((s==null?void 0:s.latitude)??(i==null?void 0:i.latitude)??""),longitude:String((s==null?void 0:s.longitude)??(i==null?void 0:i.longitude)??""),radiusMeters:String((s==null?void 0:s.radiusMeters)??(i==null?void 0:i.radiusMeters)??100),categoryTags:((s==null?void 0:s.categoryTags)??(i==null?void 0:i.categoryTags)??[]).join(", ")});return x.useEffect(()=>{h({label:(s==null?void 0:s.label)??(i==null?void 0:i.label)??"",latitude:String((s==null?void 0:s.latitude)??(i==null?void 0:i.latitude)??""),longitude:String((s==null?void 0:s.longitude)??(i==null?void 0:i.longitude)??""),radiusMeters:String((s==null?void 0:s.radiusMeters)??(i==null?void 0:i.radiusMeters)??100),categoryTags:((s==null?void 0:s.categoryTags)??(i==null?void 0:i.categoryTags)??[]).join(", ")})},[s,i]),e.jsx(Re,{open:t,onOpenChange:a,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(32rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:s?`Edit ${s.label}`:"New known place"}),e.jsx(qe,{className:"mt-1 text-sm text-white/58",children:"Define life landmarks once so the companion and web views can reason about stays and trips consistently."})]}),e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white",children:e.jsx(Nt,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(P,{value:r.label,onChange:o=>h(m=>({...m,label:o.target.value})),placeholder:"Home, Main Office, Riverside path..."}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(P,{value:r.latitude,onChange:o=>h(m=>({...m,latitude:o.target.value})),placeholder:"Latitude"}),e.jsx(P,{value:r.longitude,onChange:o=>h(m=>({...m,longitude:o.target.value})),placeholder:"Longitude"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[10rem_minmax(0,1fr)]",children:[e.jsx(P,{value:r.radiusMeters,onChange:o=>h(m=>({...m,radiusMeters:o.target.value})),placeholder:"Radius meters"}),e.jsx(P,{value:r.categoryTags,onChange:o=>h(m=>({...m,categoryTags:o.target.value})),placeholder:"home, gym, holiday, parents-house"})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(k,{variant:"ghost",onClick:()=>a(!1),className:"border border-white/10 bg-white/[0.04]",children:"Cancel"}),e.jsx(k,{onClick:()=>void c({id:s==null?void 0:s.id,label:r.label,latitude:Number(r.latitude),longitude:Number(r.longitude),radiusMeters:Number(r.radiusMeters),categoryTags:r.categoryTags.split(",").map(o=>o.trim()).filter(Boolean)}).then(()=>a(!1)),children:"Save place"})]})]})]})})}const gt=1e3;function D(t){return new Date(t).getTime()}function bt(t){return new Date(t).toISOString()}function Qt(t,a){const s=D(t.startedAt)-D(a.startedAt);if(s!==0)return s;const i=D(t.endedAt)-D(a.endedAt);return i!==0?i:t.id.localeCompare(a.id)}function kt(t){return t.syncSource==="sleep overlay"}function os(t){const a=[...t].filter(i=>D(i.endedAt)>D(i.startedAt)).sort((i,c)=>{const r=D(i.startedAt)-D(c.startedAt);if(r!==0)return r;const h=D(i.endedAt)-D(c.endedAt);return h!==0?h:i.id.localeCompare(c.id)});if(a.length===0)return[];const s=[];for(const i of a){const c=s.at(-1);if(!c){s.push(i);continue}const r=D(c.endedAt);if(D(i.startedAt)<=r+gt){const o=Math.max(r,D(i.endedAt));s[s.length-1]={...c,id:`${c.id}__${i.id}`,endedAt:bt(o),asleepSeconds:(c.asleepSeconds??0)+(i.asleepSeconds??0)||null,timeInBedSeconds:(c.timeInBedSeconds??0)+(i.timeInBedSeconds??0)||null,sleepScore:i.sleepScore??c.sleepScore,regularityScore:i.regularityScore??c.regularityScore,efficiency:i.efficiency??c.efficiency,recoveryState:i.recoveryState??c.recoveryState};continue}s.push(i)}return s}function cs(t){const a=[];if(typeof t.asleepSeconds=="number"&&t.asleepSeconds>0){const s=t.asleepSeconds/3600;a.push(`${s.toFixed(s>=1?1:2)}h asleep`)}else if(typeof t.timeInBedSeconds=="number"&&t.timeInBedSeconds>0){const s=t.timeInBedSeconds/3600;a.push(`${s.toFixed(s>=1?1:2)}h in bed`)}return typeof t.sleepScore=="number"&&a.push(`score ${t.sleepScore}`),typeof t.regularityScore=="number"&&a.push(`regularity ${t.regularityScore}`),t.recoveryState&&a.push(t.recoveryState),a.join(" · ")||"Sleep session"}function ms(t){const a=Math.max(60,Math.round((D(t.endedAt)-D(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:cs(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 Ut(t,a,s){if(s<=a)return null;const i=bt(a),c=bt(s),r=Math.max(60,Math.round((s-a)/1e3));return{...t,id:`${t.id}::virtual-${a}-${s}`,startedAt:i,endedAt:c,trueStartedAt:i,trueEndedAt:c,visibleStartedAt:i,visibleEndedAt:c,durationSeconds:r,cursor:`${c}::${t.id}::virtual`}}function xs(t,a){let s=[...t].sort(Qt);for(const i of os(a)){const c=D(i.startedAt),r=D(i.endedAt),h=ms(i),o=[];let m=!1;for(const p of s){const N=D(p.startedAt),b=D(p.endedAt);if(b<=c||N>=r){!m&&N>=r&&(o.push(h),m=!0),o.push(p);continue}if(N<c){const A=Ut(p,N,Math.min(b,c-gt));A&&o.push(A)}if(m||(o.push(h),m=!0),b>r){const A=Ut(p,Math.max(N,r+gt),b);A&&o.push(A)}}m||o.push(h),s=o.sort(Qt)}return s}const Wt=24,G=64,ft=360*60,ha=5,ht=1,hs=104,Gt=G*8;function ue(t){return t.trim().toLowerCase()}function ze(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 pe(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 ua(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit"}).format(new Date(t))}function us(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:!1}).format(t)}function Ae(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const s=a.getFullYear(),i=String(a.getMonth()+1).padStart(2,"0"),c=String(a.getDate()).padStart(2,"0"),r=String(a.getHours()).padStart(2,"0"),h=String(a.getMinutes()).padStart(2,"0");return`${s}-${i}-${c}T${r}:${h}`}function at(t){if(!t.trim())return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toISOString()}function Te(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function W(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function Vt(t,a){return`${t.toFixed(3)}, ${a.toFixed(3)}`}function Je(t,a){return`${t.toFixed(6)}, ${a.toFixed(6)}`}function Yt(t){return`${Math.max(1,Math.round(t/60))} min`}function ps(t){if(t.length===0)return[];const a=Math.min(...t.map(o=>o.latitude)),s=Math.max(...t.map(o=>o.latitude)),i=Math.min(...t.map(o=>o.longitude)),c=Math.max(...t.map(o=>o.longitude)),r=Math.max(s-a,1e-4),h=Math.max(c-i,1e-4);return t.map((o,m)=>({...o,x:12+(o.longitude-i)/h*76,y:12+(1-(o.latitude-a)/r)*76,id:`${o.recordedAt??"point"}-${m}`}))}function vt(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 ye(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 et(t,a,s,i){const r=(s-t)*Math.PI/180,h=(i-a)*Math.PI/180,o=t*Math.PI/180,m=s*Math.PI/180,p=Math.sin(r/2)**2+Math.cos(o)*Math.cos(m)*Math.sin(h/2)**2;return 2*6371e3*Math.asin(Math.sqrt(p))}function gs(t){return ue([t.label,...t.aliases].join(" "))}function st(t){return t.kind==="trip"&&t.trip!==null}function le(t){return t.kind==="stay"&&t.stay!==null}function je(t,a,s){if(!t.trip)return{label:t.placeLabel??(a==="start"?"Known origin":"Known destination"),detail:W(a==="start"?t.startedAt:t.endedAt)};const i=a==="start"?t.trip.points[0]??null:t.trip.points[t.trip.points.length-1]??null,c=a==="start"?t.trip.startPlace:t.trip.endPlace,r=(s==null?void 0:s.includeCoordinates)??!0,h=s!=null&&s.useHistoryAnchorFallback&&a==="start"?"Beginning of history":null;return{label:(c==null?void 0:c.label)??h??(r&&i?Vt(i.latitude,i.longitude):a==="start"?"Unknown origin":"Unknown destination"),detail:r&&i&&!c?Vt(i.latitude,i.longitude):W(a==="start"?t.startedAt:t.endedAt)}}function bs(t){const a=t.trim().toLowerCase();return a==="travel"||a==="trip"||a==="move"}function fs(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 vs(t){const a=ye(t),s=t.title.trim().toLowerCase(),i=s.length===0||s==="stay"||s==="continued stay"||s==="repaired stay"||s==="manual stay";return a&&i?a:t.title.trim()||a||"Stay"}function me(t){if(kt(t))return"Sleep";if(t.kind==="missing")return fs(t);if(t.kind==="stay")return vs(t);if(t.kind==="trip"&&bs(t.title)){const a=je(t,"start").label,s=je(t,"end").label;return`${a} → ${s}`}return t.title}function Xt(t){return t==="left"?24:t==="right"?76:50}function ws(t,a,s){const i=Math.min(t,ft)/3600,c=s==="sleep overlay",r=c?112:a==="stay"?104:92,h=c?272:a==="stay"?288:232,o=r+i*30;return Math.max(r,Math.min(h,o))}function wt(t){var a;return{kind:t.kind,label:le(t)?t.stay.label||t.title:st(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:Ae(t.startedAt),endedAtInput:Ae(t.endedAt)}}function ut(t,a){const s=(a==null?void 0:a.startedAt)??new Date(Date.now()-36e5).toISOString(),i=(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t,label:t==="missing"?"User-defined missing data":t==="stay"?(a==null?void 0:a.placeLabel)||"Manual stay":"Manual move",placeLabel:(a==null?void 0:a.placeLabel)??"",tagsInput:t==="missing"?"user-defined, missing-data":t==="stay"?"user-defined, stay":"user-defined, move",startedAtInput:Ae(s),endedAtInput:Ae(i)}}function yt(t,a){var r,h;const s=t.tagsInput.split(",").map(o=>o.trim()).filter(Boolean),i=at(t.startedAtInput)??(a==null?void 0:a.startedAt)??new Date(Date.now()-3600*1e3).toISOString(),c=at(t.endedAtInput)??(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t.kind,startedAt:i,endedAt:c,title:t.label.trim(),subtitle:t.kind==="missing"?"User-defined missing-data override.":"User-defined movement box.",placeLabel:t.placeLabel.trim()||null,tags:s,distanceMeters:t.kind==="trip"?Math.max(((r=a==null?void 0:a.trip)==null?void 0:r.distanceMeters)??150,150):null,averageSpeedMps:t.kind==="trip"?((h=a==null?void 0:a.trip)==null?void 0:h.averageSpeedMps)??null:null,metadata:{createdFrom:"movement-life-timeline"}}}function ys(t,a){var c,r;const s=t.kind==="stay"?((r=(c=t.stay)==null?void 0:c.label)==null?void 0:r.trim())??"":"";if(s)return s;const i=t.title.trim();return i&&i.toLowerCase()!=="stay"?i:a.trim()||"Stay"}function js(t,a){const s=wt(t),i=a.trim();return yt({...s,label:ys(t,i),placeLabel:i},t)}function pa(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function it(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ns(t){var a,s,i;return ue([t.kind,me(t),t.subtitle,t.placeLabel??"",...t.tags,it(t.startedAt),it(t.endedAt),pa(t.startedAt),le(t)?((a=t.stay.place)==null?void 0:a.label)??t.stay.label:st(t)?[t.trip.label,t.trip.activityType,t.trip.travelMode,(s=t.trip.startPlace)==null?void 0:s.label,(i=t.trip.endPlace)==null?void 0:i.label].filter(Boolean).join(" "):t.kind==="trip"?[t.title,t.subtitle,t.placeLabel??""].filter(Boolean).join(" "):"missing data gap"].join(" "))}function Ss(t){const a=new Map;a.set("kind:stay",{id:"kind:stay",label:"Stay",description:"Stationary spans and place anchors."}),a.set("kind:trip",{id:"kind:trip",label:"Move",description:"Trips and movement connectors."});for(const s of["night","morning","afternoon","evening"])a.set(`time:${s}`,{id:`time:${s}`,label:s[0].toUpperCase()+s.slice(1),description:"Filter by the segment start time."});for(const s of t){for(const i of s.tags)a.set(`tag:${i}`,{id:`tag:${i}`,label:i,description:"Movement tag"});s.placeLabel&&a.set(`place:${s.placeLabel}`,{id:`place:${s.placeLabel}`,label:s.placeLabel,description:"Matched place"})}return[...a.values()].sort((s,i)=>s.label.localeCompare(i.label))}function Ms(t,a){return a.every(s=>s==="kind:stay"||s==="kind:trip"?t.kind===s.slice(5):s.startsWith("time:")?pa(t.startedAt)===s.slice(5):s.startsWith("tag:")?t.tags.includes(s.slice(4)):s.startsWith("place:")?(t.placeLabel??"")===s.slice(6):!0)}function Zt(t,a){return t&&{...t,pages:t.pages.map(s=>({...s,segments:s.segments.filter(i=>i.id!==a)}))}}function ks(t,a){const s=t+(Math.sin((t-.5)*Math.PI)+1)*.5-t,i=t-.5,r=.5+(i*(1-a*.64)+i*i*i*a*2.56);return Math.max(0,Math.min(1,r-(s-t)*a*.08))}function As(t){return t.getHours()===0?ua(t.toISOString()):us(t)}function Ts(t,a){const s=new Date(t.endedAt).getTime(),i=new Date(t.startedAt).getTime(),c=Math.max(1,s-i),r=Math.max(0,Math.min(1,(a-i)/c));if(t.durationSeconds<=ft)return r;const h=Math.max(0,1-Math.min(1,ft/Math.max(1,t.durationSeconds)));return ks(r,h)}function Cs(t,a,s){if(t.items.length===0)return null;const i=t.items[0];if(a<new Date(i.segment.startedAt).getTime())return t.historyHeaderHeight+t.leadHeight-(new Date(i.segment.startedAt).getTime()-a)/36e5*G;for(let h=0;h<t.items.length;h+=1){const o=t.items[h],m=new Date(o.segment.startedAt).getTime(),p=new Date(o.segment.endedAt).getTime();if(a>=m&&a<=p)return o.boxTop+Ts(o.segment,a)*o.displayHeight;const N=t.items[h+1]??null,b=N?new Date(N.segment.startedAt).getTime():s;if(a>p&&a<b)return o.boxBottom+(a-p)/36e5*G}const c=t.items[t.items.length-1],r=new Date(c.segment.endedAt).getTime();return a>=r?c.boxBottom+(a-r)/36e5*G:null}function Ps(t){const a=new Date(t);a.setMinutes(0,0,0);const s=a.getTime();return s<=t?s+36e5:s}function Ls(t,a){const s=[];if(t.items.length===0)return s;const i=t.items[0],c=new Date(i.segment.startedAt).getTime();for(let r=Ps(c-ha*36e5);r<=a;r+=36e5){const h=Cs(t,r,a);if(h===null)continue;const o=new Date(r);s.push({y:h,label:As(o),strong:o.getHours()===0})}return s}function Ds({segments:t,viewportHeight:a,nowMs:s=Date.now()}){var B;const i=t.length>0?hs:0,c=t.length>0?G*ha:0;let r=i+c,h=null;const o=t.map(w=>{const T=ws(w.durationSeconds,w.kind,w.syncSource),F=new Date(w.startedAt).getTime(),H=h===null?0:Math.max(0,(F-h)/36e5)*G;r+=H;const V=r,_=V+T;return r=_,h=new Date(w.endedAt).getTime(),{id:w.id,segment:w,gapBefore:H,displayHeight:T,boxTop:V,boxBottom:_}}),m=s+ht*36e5,p=(()=>{var F;const w=(F=t[t.length-1])==null?void 0:F.endedAt;if(!w)return G*ht;const T=new Date(w).getTime();return Math.max(G*ht,(m-T)/36e5*G)})(),N=(((B=o[o.length-1])==null?void 0:B.boxBottom)??i+c)+p,b=Math.max(N,a>0?a+260:960,i+c+p),A={historyHeaderHeight:i,leadHeight:c,items:o,markers:[],rangeEndMs:m,futureTailHeight:p+Math.max(0,b-N),totalHeight:b};return{...A,markers:Ls(A,m)}}function Is({layout:t,scrollTop:a,viewportHeight:s}){const i=G*6,c=Math.max(0,a-i),r=Math.min(t.totalHeight,a+Math.max(s,G*8)+i),h=t.markers.filter(o=>o.y>=c&&o.y<=r);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:"absolute inset-y-0 left-0 w-18 bg-[linear-gradient(90deg,rgba(7,12,22,0.96),rgba(7,12,22,0.42),transparent)]"}),h.map((o,m)=>e.jsxs("div",{className:"absolute inset-x-0",style:{top:`${o.y}px`},children:[e.jsx("div",{className:O("border-t",o.strong?"border-white/14":"border-white/7")}),e.jsx("div",{className:O("absolute left-3 top-0 -translate-y-1/2 font-label text-[9px] tracking-[0.24em]",o.strong?"text-white/38":"text-white/22"),children:o.label})]},`timeline-grid-${m}`))]})}function $s({fromSide:t,toSide:a,height:s,emphasized:i}){const c=Xt(t),r=Xt(a),h=`M ${c} 16 C ${c} ${Math.max(40,s*.26)}, ${r} ${Math.max(70,s*.72)}, ${r} ${s-18}`;return e.jsxs("svg",{viewBox:`0 0 100 ${s}`,className:"absolute inset-x-0 top-0 h-full w-full overflow-visible",preserveAspectRatio:"none",children:[e.jsx("path",{d:h,fill:"none",stroke:i?"rgba(241,246,255,0.18)":"rgba(241,246,255,0.11)",strokeWidth:i?"1.05":"0.85",strokeDasharray:i?"3 10":"2.5 12",strokeLinecap:"round"}),e.jsx("circle",{cx:c,cy:"16",r:"1.5",fill:"rgba(255,255,255,0.26)"}),e.jsx("circle",{cx:r,cy:s-18,r:"1.5",fill:"rgba(255,255,255,0.26)"})]})}function jt({position:t}){return e.jsx("div",{className:O("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:"h-6 w-[3px] rounded-full bg-[rgba(160,224,255,0.92)] shadow-[0_0_14px_rgba(126,229,255,0.36)]"})})}function Fs({segment:t}){const a=(t==null?void 0:t.kind)==="stay"?t.placeLabel||t.title||null:(t==null?void 0:t.kind)==="trip"?je(t,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}).label:null,s=a||"Beginning of time";return e.jsx("div",{className:"pointer-events-none flex justify-center px-6 py-4",children:e.jsxs("div",{className:"relative w-[min(18rem,calc(100vw-6rem))] overflow-hidden rounded-[26px] border border-[rgba(152,208,255,0.2)] bg-[linear-gradient(180deg,rgba(98,130,238,0.14),rgba(18,34,79,0.14))] shadow-[0_20px_48px_rgba(3,8,20,0.3)]",children:[e.jsx(jt,{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(u,{tone:"signal",className:"bg-white/10 text-white/78",children:"Start"}),e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-white/28",children:"Beginning of history"})]}),e.jsx("div",{className:"mt-5 font-display text-[1.25rem] tracking-[-0.05em] text-white",children:s}),e.jsx("div",{className:"mt-2 font-label text-[10px] uppercase tracking-[0.22em] text-white/30",children:a?"Oldest loaded known stay":"Earliest known anchor"})]})]})})}function Es(t,a,s){const i=a+Math.max(96,Math.min(s*.28,220)),c=t.items.find(r=>r.boxBottom>=i)??t.items[t.items.length-1]??null;return c?ua(c.segment.startedAt):null}function _s({open:t,anchor:a,items:s,onClose:i}){if(x.useEffect(()=>{if(!t)return;const m=N=>{N.key==="Escape"&&i()},p=()=>i();return window.addEventListener("keydown",m),window.addEventListener("pointerdown",p),()=>{window.removeEventListener("keydown",m),window.removeEventListener("pointerdown",p)}},[i,t]),!t||!a||typeof document>"u")return null;const c=Math.max(12,Math.min(a.top,window.innerHeight-360)),r=Math.max(220,window.innerHeight-c-96),h=Math.min(368,window.innerWidth-24),o=Math.max(12,Math.min(a.right,window.innerWidth-h-12));return Da.createPortal(e.jsx("div",{className:"fixed inset-0 z-[70] pointer-events-none",children:e.jsxs("div",{className:"pointer-events-auto fixed z-[71] overflow-y-auto overscroll-contain rounded-[28px] border border-white/10 bg-[linear-gradient(180deg,rgba(18,24,40,0.985),rgba(8,13,24,0.985))] p-2 shadow-[0_28px_90px_rgba(3,8,18,0.48)] backdrop-blur-xl",style:{top:`${c}px`,right:`${o}px`,width:`${h}px`,maxHeight:`${r}px`},onPointerDown:m=>m.stopPropagation(),children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.035] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-white/40",children:"Movement actions"}),e.jsx("div",{className:"mt-1 text-sm text-white/70",children:"Add boxes, inspect raw data, and adjust timeline overlays."})]}),e.jsx("div",{className:"mt-2 grid gap-1",children:s.map(m=>{const p=m.icon;return e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[20px] bg-white/[0.035] px-4 py-3 text-left text-white/76 transition hover:bg-white/[0.08] hover:text-white",onClick:()=>{m.onSelect(),i()},children:[e.jsx("span",{className:"rounded-[14px] bg-[var(--primary)]/12 p-2 text-[var(--primary)]",children:e.jsx(p,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:m.label}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-white/48",children:m.description})]})]},m.id)})})]})}),document.body)}function zs({segment:t,onEdit:a,onOpenDetail:s,onDefinePlace:i,onClose:c}){var h;const r=kt(t);return e.jsxs(v,{className:"rounded-[28px] border border-white/10 bg-[linear-gradient(180deg,rgba(9,14,26,0.98),rgba(5,9,19,0.95))] p-5 shadow-[0_24px_74px_rgba(0,0,0,0.34)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:r?"Sleep overlay":t.kind==="stay"?"Stay detail":t.kind==="trip"?"Move detail":"Missing data"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:me(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{className:r?"bg-cyan-400/14 text-cyan-100":t.sourceKind==="user_defined"?"bg-fuchsia-400/12 text-fuchsia-100":"bg-white/[0.06] text-white/70",children:r?"Virtual":t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),t.overrideCount>0?e.jsxs(u,{className:"bg-amber-400/10 text-amber-100",children:["Overrides ",t.overrideCount," automatic box",t.overrideCount===1?"":"es"]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{onClick:s,variant:"ghost",className:"rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/78 hover:bg-white/[0.08]",disabled:r,children:"Details"}),e.jsx(k,{onClick:a,variant:"ghost",className:"size-9 rounded-full border border-white/10 bg-white/[0.04] text-white/78 hover:bg-white/[0.08]","aria-label":"Edit movement segment",disabled:r||t.kind==="missing"||!t.editable,children:e.jsx(Mt,{className:"size-4"})}),c?e.jsx("button",{type:"button",onClick:c,className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close movement segment actions",children:e.jsx(Nt,{className:"size-4"})}):null,e.jsx(St,{className:"size-4 text-white/42"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-white/82",children:pe(t.startedAt)})]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-white/82",children:pe(t.endedAt)})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:ze(t.durationSeconds)}),st(t)?e.jsxs(e.Fragment,{children:[e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:Te(t.trip.distanceMeters)}),t.trip.stops.length>0?e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:[t.trip.stops.length," stop",t.trip.stops.length===1?"":"s"]}):null]}):null,r?e.jsx(u,{className:"bg-cyan-400/12 text-cyan-50",children:t.subtitle}):ye(t)?e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:ye(t)}):null]}),le(t)&&!r?e.jsxs("div",{className:"mt-4 rounded-[18px] border border-sky-300/14 bg-sky-300/8 p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-sky-100/66",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-sky-50/86",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(k,{onClick:i,variant:"ghost",className:"rounded-full border border-sky-300/24 bg-sky-300/12 px-4 text-sky-50 hover:bg-sky-300/18",children:"Label location"})})]}):null,e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Timeline summary"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/76",children:t.kind==="stay"?r?`Sleep overlay from ${W(t.startedAt)} to ${W(t.endedAt)}. Underlying movement boxes are sliced virtually while this overlay is visible.`:`Stay block from ${W(t.startedAt)} to ${W(t.endedAt)}.`:t.kind==="trip"?`Connector from ${je(t,"start").label} to ${je(t,"end").label}.`:`No reliable movement signal reached Forge from ${W(t.startedAt)} to ${W(t.endedAt)}.`})]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Projection model"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/76",children:r?"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(u,{className:"bg-white/[0.08] text-white/74",children:["Raw stays ",t.rawStayIds.length]}),e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:["Raw trips ",t.rawTripIds.length]}),e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:["Raw points ",t.rawPointCount]}),t.hasLegacyCorrections?e.jsx(u,{className:"bg-amber-400/10 text-amber-100",children:"Legacy corrections present"}):null]})]})]}),e.jsx("div",{className:"mt-5 flex flex-wrap items-center gap-2 text-sm text-white/56",children:r?e.jsxs(e.Fragment,{children:[e.jsx(aa,{className:"size-4 text-cyan-300"}),"Sleep overlay"]}):le(t)?e.jsxs(e.Fragment,{children:[e.jsx(ia,{className:"size-4 text-[var(--primary)]"}),((h=t.stay.place)==null?void 0:h.label)??"No canonical place linked yet"]}):st(t)?e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"size-4 text-[var(--primary)]"}),t.trip.activityType||t.trip.travelMode]}):t.kind==="trip"?e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"size-4 text-[var(--primary)]"}),"Repaired movement connector"]}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{className:"size-4 text-white/56"}),"Missing intervals are synthesized from long signal gaps instead of inventing fake travel."]})})]})}function Jt({title:t,points:a,averagePoint:s}){const i=ps(s?[...a,s]:a),c=s?i.length-1:i.length,r=i.slice(0,c),h=s?i[i.length-1]??null:null,o=r.map((m,p)=>`${p===0?"M":"L"} ${m.x} ${m.y}`).join(" ");return e.jsxs(v,{className:"rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,13,25,0.95),rgba(10,17,30,0.88))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:t}),e.jsx("div",{className:"mt-2 text-sm text-white/62",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-white/8 bg-[rgba(255,255,255,0.03)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"rgba(255,255,255,0.02)"}),r.length>1?e.jsx("path",{d:o,fill:"none",stroke:"rgba(92,225,230,0.95)",strokeWidth:"1.6"}):null,r.map((m,p)=>e.jsx("circle",{cx:m.x,cy:m.y,r:p===0||p===r.length-1?2.2:1.4,fill:p===0||p===r.length-1?"#ffffff":"rgba(92,225,230,0.9)"},m.id)),h?e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:h.x,cy:h.y,r:3,fill:"rgba(255,208,88,0.95)"}),e.jsx("circle",{cx:h.x,cy:h.y,r:6,fill:"none",stroke:"rgba(255,208,88,0.48)",strokeWidth:"1",strokeDasharray:"2 2"})]}):null]})})]})}function Rs({open:t,onOpenChange:a,segment:s,detail:i,loading:c,onEdit:r,onDefinePlace:h}){var N;const o=(i==null?void 0:i.segment)??s,m=(i==null?void 0:i.stayDetail)??null,p=(i==null?void 0:i.tripDetail)??null;return e.jsx(Re,{open:t,onOpenChange:a,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[6vh] z-50 max-h-[88vh] w-[min(60rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:o?`${me(o)} details`:"Movement details"}),e.jsx(qe,{className:"mt-2 text-sm leading-6 text-white/62",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:[o?e.jsxs(k,{onClick:r,variant:"ghost",className:"rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/78 hover:bg-white/[0.08]",disabled:!o.editable||o.kind==="missing",children:[e.jsx(Mt,{className:"size-4"}),"Edit"]}):null,e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white",children:e.jsx(St,{className:"size-4 rotate-45"})})})]})]}),c?e.jsx("div",{className:"mt-6 rounded-[22px] border border-white/8 bg-white/[0.03] p-5 text-sm text-white/62",children:"Loading the canonical box detail and raw movement evidence…"}):o?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.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-white",children:pe(o.startedAt)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-white",children:pe(o.endedAt)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Duration"}),e.jsx("div",{className:"mt-2 text-sm text-white",children:ze(o.durationSeconds)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Raw coverage"}),e.jsxs("div",{className:"mt-2 text-sm text-white",children:[o.rawStayIds.length," stays · ",o.rawTripIds.length," trips · ",o.rawPointCount," points"]})]})]}),m?e.jsxs(e.Fragment,{children:[e.jsxs(v,{className:"rounded-[22px] border border-sky-300/14 bg-sky-300/8 p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-sky-100/66",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-sky-50/86",children:m.canonicalPlace?`This stay is linked to ${m.canonicalPlace.label}. Search a different saved place or relabel it from the stay center.`:"This stay has no saved place yet. Search known locations first, or create a new place directly from the stay center."}),e.jsx("div",{className:"mt-3",children:e.jsx(k,{onClick:h,variant:"ghost",className:"rounded-full border border-sky-300/24 bg-sky-300/12 px-4 text-sky-50 hover:bg-sky-300/18",children:"Label location"})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(Jt,{title:"Stay positions",points:m.positions,averagePoint:m.averagePosition}),e.jsxs(v,{className:"rounded-[28px] border border-white/10 bg-white/[0.03] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Stay metrics"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"text-sm text-white/78",children:["Canonical place: ",((N=m.canonicalPlace)==null?void 0:N.label)??"Not linked yet"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Average position: ",m.averagePosition?Je(m.averagePosition.latitude,m.averagePosition.longitude):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Radius: ",m.radiusMeters!=null?Te(m.radiusMeters):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Samples: ",m.sampleCount]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-black/10 p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Exact positions"}),e.jsx("div",{className:"mt-3 grid gap-2",children:m.positions.map((b,A)=>e.jsxs("div",{className:"text-sm text-white/74",children:[b.label??`Position ${A+1}`,": ",Je(b.latitude,b.longitude)]},`${b.recordedAt??"stay"}-${A}`))})]})]})]})]})]}):null,p?e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(Jt,{title:"Travel map",points:p.positions}),e.jsxs(v,{className:"rounded-[28px] border border-white/10 bg-white/[0.03] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Trip metrics"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"text-sm text-white/78",children:["Start position: ",p.startPosition?Je(p.startPosition.latitude,p.startPosition.longitude):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["End position: ",p.endPosition?Je(p.endPosition.latitude,p.endPosition.longitude):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Distance: ",Te(p.totalDistanceMeters)]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Moving time: ",Yt(p.movingSeconds)]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Idle time: ",Yt(p.idleSeconds)]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Average speed: ",p.averageSpeedMps!=null?`${p.averageSpeedMps.toFixed(2)} m/s`:"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Max speed: ",p.maxSpeedMps!=null?`${p.maxSpeedMps.toFixed(2)} m/s`:"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Stops: ",p.stopCount]})]})]})]}):null]}):null]})]})})}function Os({open:t,segment:a,onOpenChange:s,onEdit:i,onOpenDetail:c,onDefinePlace:r}){return e.jsx(Re,{open:t,onOpenChange:s,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{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(Be,{className:"sr-only",children:a?`${me(a)} actions`:"Movement actions"}),e.jsx(qe,{className:"sr-only",children:"Inspect, edit, or label the selected movement box."}),a?e.jsx(zs,{segment:a,onEdit:i,onOpenDetail:c,onDefinePlace:r,onClose:()=>s(!1)}):null]})]})})}function Hs({open:t,onOpenChange:a,segment:s,places:i,loading:c,onSelectPlace:r,onCreatePlace:h}){const o=s?vt(s):null,[m,p]=x.useState("");x.useEffect(()=>{if(!t){p("");return}p(ye(s)??"")},[t,s]);const N=x.useMemo(()=>{if(!o)return[];const w=ue(m);return[...i].filter(T=>w.length===0?!0:gs(T).includes(w)).sort((T,F)=>{const H=ue(T.label),V=ue(F.label),_=w.length>0&&H.startsWith(w),Y=w.length>0&&V.startsWith(w);if(_!==Y)return _?-1:1;const Q=et(o.latitude,o.longitude,T.latitude,T.longitude),X=et(o.latitude,o.longitude,F.latitude,F.longitude);return Math.abs(Q-X)>1?Q-X:T.label.localeCompare(F.label)}).slice(0,6)},[i,m,o]),b=ue(m),A=N.some(w=>ue(w.label)===b),B=ye(s);return e.jsx(Re,{open:t,onOpenChange:a,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[8vh] z-50 max-h-[84vh] w-[min(38rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:"Label stay location"}),e.jsx(qe,{className:"mt-2 text-sm leading-6 text-white/62",children:"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."})]}),e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close location label dialog",children:e.jsx(Nt,{className:"size-4"})})})]}),o?e.jsxs("div",{className:"mt-5 rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(u,{tone:"signal",children:"Stay center"}),B?e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:B}):null]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-black/10 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Latitude"}),e.jsx("div",{className:"mt-1 text-sm text-white/82",children:o.latitude.toFixed(6)})]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-black/10 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Longitude"}),e.jsx("div",{className:"mt-1 text-sm text-white/82",children:o.longitude.toFixed(6)})]})]})]}):e.jsx("div",{className:"mt-5 rounded-[22px] border border-amber-300/14 bg-amber-300/8 p-4 text-sm text-amber-50/86",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(P,{value:m,onChange:w=>p(w.target.value),placeholder:"Type a location name or create a new one"}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Known places"}),c?e.jsx("div",{className:"mt-3 text-sm text-white/58",children:"Loading saved places…"}):N.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:N.map(w=>{const T=o==null?null:et(o.latitude,o.longitude,w.latitude,w.longitude);return e.jsxs("button",{type:"button",onClick:()=>void r(w).then(F=>{F&&a(!1)}),className:"rounded-[18px] border border-white/8 bg-black/10 px-4 py-3 text-left transition hover:border-[var(--primary)]/40 hover:bg-white/[0.05]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm text-white",children:w.label}),T!=null?e.jsxs(u,{className:"bg-white/[0.08] text-white/70",children:[Te(T)," away"]}):null]}),w.aliases.length>0||w.categoryTags.length>0?e.jsx("div",{className:"mt-1 text-xs text-white/52",children:[...w.aliases,...w.categoryTags].join(" · ")}):null]},w.id)})}):e.jsx("div",{className:"mt-3 text-sm text-white/58",children:"No saved place matches this stay yet."})]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx(k,{variant:"ghost",onClick:()=>a(!1),className:"border border-white/10 bg-white/[0.04]",children:"Cancel"}),e.jsx(k,{onClick:()=>{!s||!o||h(s,A?"":m.trim())},disabled:!s||!o,children:b.length>0&&!A?`Create "${m.trim()}"`:"Create new location"})]})]})]})})}function Ks({open:t,segment:a,draft:s,creating:i,saving:c,preflight:r,preflightLoading:h,onDraftChange:o,onFitMissing:m,onSave:p,onOpenChange:N}){return e.jsx(Re,{open:t,onOpenChange:N,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(34rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:i?"Create movement box":"Edit movement box"}),e.jsx(qe,{className:"mt-2 text-sm leading-6 text-white/62",children:s?i?"Create a canonical user-defined stay, move, or missing-data box without mutating raw phone measurements.":`Adjust this user-defined ${s.kind} box. Automatic boxes stay immutable and can only be invalidated.`:"No segment selected."})]}),e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/72 transition hover:bg-white/[0.08]",children:e.jsx(St,{className:"size-4 rotate-45"})})})]}),s?e.jsxs("div",{className:"mt-5 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Kind",e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["stay","Stay"],["trip","Move"],["missing","Missing"]].map(([b,A])=>e.jsx(k,{type:"button",variant:"ghost",className:O("border border-white/10 bg-white/[0.04] text-white hover:bg-white/[0.08]",s.kind===b?"ring-1 ring-[rgba(126,229,255,0.42)]":""),onClick:()=>o({...s,kind:b}),children:A},b))})]}),e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Label",e.jsx(P,{value:s.label,onChange:b=>o({...s,label:b.target.value})})]}),s.kind!=="trip"?e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Place",e.jsx(P,{value:s.placeLabel,onChange:b=>o({...s,placeLabel:b.target.value}),placeholder:"Home, Office, Riverside path..."})]}):null,e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Tags",e.jsx(P,{value:s.tagsInput,onChange:b=>o({...s,tagsInput:b.target.value}),placeholder:"movement, social, errand"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Started",e.jsx(P,{type:"datetime-local",value:s.startedAtInput,onChange:b=>o({...s,startedAtInput:b.target.value})})]}),e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Ended",e.jsx(P,{type:"datetime-local",value:s.endedAtInput,onChange:b=>o({...s,endedAtInput:b.target.value})})]})]}),e.jsxs(v,{className:"grid gap-3 border-white/10 bg-white/[0.03] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:"Overlap guidance"}),e.jsx(k,{type:"button",variant:"ghost",className:"border border-white/10 bg-white/[0.04] text-white hover:bg-white/[0.08]",onClick:m,disabled:!(r!=null&&r.nearestMissingStartedAt)||!(r!=null&&r.nearestMissingEndedAt),children:"Fit Missing Time"})]}),e.jsx("div",{className:"text-sm leading-6 text-white/62",children:h?"Checking visible overlaps and missing windows…":r!=null&&r.overlapsAnything?`This box overlaps ${r.affectedAutomaticBoxIds.length} automatic and ${r.affectedUserBoxIds.length} manual boxes. Saving will fully override ${r.fullyOverriddenUserBoxIds.length} manual boxes and trim ${r.trimmedUserBoxIds.length}.`:"No overlap in the currently visible timeline window."}),e.jsxs("div",{className:"grid gap-1 text-xs text-white/50",children:[e.jsxs("div",{children:["Visible range:"," ",r!=null&&r.visibleRangeStart&&(r!=null&&r.visibleRangeEnd)?`${pe(r.visibleRangeStart)} -> ${pe(r.visibleRangeEnd)}`:"Unavailable"]}),e.jsxs("div",{children:["Suggested missing slot:"," ",r!=null&&r.nearestMissingStartedAt&&(r!=null&&r.nearestMissingEndedAt)?`${pe(r.nearestMissingStartedAt)} -> ${pe(r.nearestMissingEndedAt)}`:"No missing interval in view"]})]})]})]}):null,e.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[e.jsx(_e,{asChild:!0,children:e.jsx(k,{type:"button",variant:"ghost",className:"border border-white/10 bg-white/[0.04] text-white hover:bg-white/[0.08]",children:"Cancel"})}),e.jsxs(k,{onClick:p,disabled:!s||c,children:[e.jsx(Ia,{className:"size-4"}),c?"Saving…":i?"Create box":"Save changes"]})]})]})]})})}function ea({side:t,vertical:a,emphasized:s=!1}){return e.jsx("div",{className:O("absolute z-10 h-7 w-8 rounded-[12px] border bg-[linear-gradient(180deg,rgba(10,16,28,0.94),rgba(7,12,24,0.88))] shadow-[0_12px_30px_rgba(0,0,0,0.22)] backdrop-blur-sm",s?"border-[rgba(152,208,255,0.34)]":"border-white/10",t==="left"?"left-[8%]":t==="right"?"right-[8%]":"left-1/2 -translate-x-1/2",a==="top"?"top-0":"bottom-0")})}function Bs({layout:t,selected:a,onToggle:s}){var m,p,N,b;const{segment:i}=t,c=kt(i),r=t.displayHeight,h=i.kind==="stay"?c?"bg-[linear-gradient(180deg,rgba(39,127,173,0.28),rgba(16,51,79,0.22))] border-[rgba(138,227,255,0.28)]":"bg-[linear-gradient(180deg,rgba(98,130,238,0.22),rgba(18,34,79,0.22))] border-[rgba(152,208,255,0.24)]":"",o=i.kind==="trip"?{start:je(i,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}),end:je(i,"end",{includeCoordinates:!1})}:null;return e.jsxs("div",{className:O("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:`${r}px`},children:[e.jsx("div",{className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-[linear-gradient(180deg,rgba(255,255,255,0.02),rgba(255,255,255,0.08),rgba(255,255,255,0.02))]"}),e.jsx("div",{className:"relative h-full",children:i.kind==="trip"?e.jsxs(qt.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:240,damping:30},className:"absolute inset-x-0 top-0 h-full z-10",children:[o&&a?e.jsxs(e.Fragment,{children:[e.jsx(ea,{side:"center",vertical:"top",emphasized:!0}),e.jsx(ea,{side:"center",vertical:"bottom",emphasized:!0})]}):null,e.jsx($s,{fromSide:"center",toSide:"center",height:r,emphasized:a}),e.jsxs("button",{type:"button",onClick:s,className:O("group absolute top-1/2 max-w-[min(8rem,calc(100vw-8rem))] -translate-y-1/2 rounded-[16px] border border-white/8 bg-[linear-gradient(180deg,rgba(9,14,24,0.58),rgba(8,12,22,0.42))] px-2.5 py-2 text-left shadow-[0_12px_24px_rgba(0,0,0,0.14)] backdrop-blur-sm transition hover:border-white/14 sm:max-w-[9rem] sm:px-3","left-1/2 -translate-x-1/2",a?"ring-1 ring-[rgba(126,229,255,0.38)]":""),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.18em] text-white/34",children:"Move"}),e.jsx("div",{className:"text-[11px] tracking-[0.18em] text-white/44",children:ze(i.durationSeconds)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:Te(((m=i.trip)==null?void 0:m.distanceMeters)??0)}),(((p=i.trip)==null?void 0:p.stops.length)??0)>0?e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:[(N=i.trip)==null?void 0:N.stops.length," stop",((b=i.trip)==null?void 0:b.stops.length)===1?"":"s"]}):null]}),e.jsxs("div",{className:"mt-2 font-label text-[9px] uppercase tracking-[0.22em] text-white/28",children:[W(i.startedAt)," → ",W(i.endedAt)]})]})]}):e.jsx(qt.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:260,damping:28},className:"absolute top-0 left-1/2 z-10 w-[min(18.5rem,calc(100vw-3.25rem))] -translate-x-1/2 sm:w-[min(21rem,calc(100vw-5rem))]",children:e.jsxs("button",{type:"button",onClick:s,className:O("group relative w-full overflow-hidden rounded-[24px] border text-left shadow-[0_20px_52px_rgba(3,8,20,0.36)] transition sm:rounded-[30px]",h,a?"ring-1 ring-[rgba(126,229,255,0.42)]":"hover:border-white/22"),style:{minHeight:`${r}px`},children:[e.jsx(jt,{position:"top"}),e.jsx(jt,{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(u,{tone:"signal",className:"bg-white/10 text-white/82",children:c?"Sleep":"Stay"}),e.jsx("div",{className:"text-[11px] tracking-[0.16em] text-white/46 sm:text-xs sm:tracking-[0.18em]",children:ze(i.durationSeconds)})]}),e.jsxs("div",{className:"mt-3 min-w-0 sm:mt-5",children:[e.jsx("div",{className:"truncate font-display text-[1rem] tracking-[-0.03em] text-white sm:text-[1.12rem]",children:me(i)}),i.kind==="stay"&&ye(i)&&!c?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(u,{className:"max-w-full truncate bg-white/[0.08] text-white/76",children:ye(i)})}):c?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(u,{className:"max-w-full truncate bg-cyan-400/12 text-cyan-50",children:i.subtitle})}):null]}),e.jsx("div",{className:"mt-auto pt-4 sm:pt-8",children:e.jsxs("div",{className:"font-label text-[9px] uppercase tracking-[0.2em] text-white/34 sm:text-[10px] sm:tracking-[0.22em]",children:[W(i.startedAt)," → ",W(i.endedAt)]})})]})]})})})]})}function qs({userIds:t=[]}){var Et,_t,zt;const a=ra(),s=x.useRef(null),i=x.useRef(null),c=x.useRef(null),r=x.useRef(!1),h=x.useRef(!1),o=x.useRef(null),[m,p]=x.useState(null),[N,b]=x.useState(!1),[A,B]=x.useState(!1),[w,T]=x.useState(null),[F,H]=x.useState({}),[V,_]=x.useState(null),[Y,Q]=x.useState(null),[X,Z]=x.useState(null),[Qe,Ce]=x.useState(null),[Pe,Le]=x.useState(!1),[Ue,Ne]=x.useState(!1),[nt,Se]=x.useState(null),[lt,De]=x.useState(null),[ae,q]=x.useState(!1),[se,ie]=x.useState(!1),[K,xe]=x.useState(!1),[y,We]=x.useState(""),[ge,Ge]=x.useState([]),[he,Ve]=x.useState(0),[z,Ie]=x.useState(0),Me=()=>{const l=s.current;l&&(Ve(l.scrollTop),Ie(l.clientHeight))},C=Rt({queryKey:["forge-movement-life-timeline",...t],initialPageParam:null,queryFn:({pageParam:l})=>Kt({before:l??void 0,limit:Wt,userIds:t}).then(d=>d.movement),getNextPageParam:l=>l.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),j=Rt({queryKey:["forge-movement-life-timeline-data",...t],initialPageParam:null,queryFn:({pageParam:l})=>Kt({before:l??void 0,includeInvalid:!0,limit:Wt,userIds:t}).then(d=>d.movement),getNextPageParam:l=>l.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),be=x.useMemo(()=>{var l;return((l=C.data)==null?void 0:l.pages.flatMap(d=>d.segments))??[]},[C.data]),de=x.useMemo(()=>{var l;return((l=j.data)==null?void 0:l.pages.flatMap(d=>d.segments))??[]},[j.data]),oe=x.useMemo(()=>{var l;return((l=C.data)==null?void 0:l.pages.reduce((d,g)=>Math.max(d,g.invalidSegmentCount??0),0))??0},[C.data]),S=x.useMemo(()=>[...be].reverse(),[be]),J=x.useMemo(()=>[...de].reverse(),[de]),$e=x.useMemo(()=>{var d;const l=new Map;for(const g of((d=C.data)==null?void 0:d.pages)??[])for(const E of g.sleepOverlays??[])l.set(E.id,E);return[...l.values()].sort((g,E)=>new Date(g.startedAt).getTime()-new Date(E.startedAt).getTime())},[C.data]),fe=x.useMemo(()=>xs(S,$e),[S,$e]),M=x.useMemo(()=>K?fe:S,[S,fe,K]),Fe=x.useMemo(()=>fe.filter(l=>l.syncSource==="sleep overlay"),[fe]),re=((Et=Fe.at(-1))==null?void 0:Et.id)??null,n=x.useMemo(()=>M.find(l=>l.id===X)??null,[X,M]),f=x.useMemo(()=>M.find(l=>l.id===m)??null,[M,m]),ee=te({queryKey:["forge-movement-box-detail",(n==null?void 0:n.boxId)??null,...t],queryFn:async()=>n!=null&&n.boxId?(await za(n.boxId,t)).movement:null,enabled:!!(n!=null&&n.boxId)}),U=x.useMemo(()=>S.find(l=>l.id===Qe)??null,[Qe,S]),ne=te({queryKey:["forge-movement-places",...t],queryFn:async()=>(await ca(t)).places,retry:!1,refetchOnWindowFocus:!1}),I=x.useMemo(()=>Ds({segments:M,viewportHeight:z}),[M,z]),dt=x.useMemo(()=>new Map(I.items.map(l=>[l.segment.id,l])),[I.items]),ba=x.useMemo(()=>{const l=Math.max(0,he-Gt),d=he+Math.max(z,G*8)+Gt;return I.items.filter(g=>g.segment.id===m?!0:g.boxBottom>=l&&g.boxTop<=d)},[he,m,I.items,z]),Tt=x.useMemo(()=>Es(I,he,z),[he,I,z]),fa=()=>{var d;const l=(d=c.current)==null?void 0:d.getBoundingClientRect();if(!l){B(g=>!g);return}T({top:l.bottom+10,right:Math.max(12,window.innerWidth-l.right)}),B(g=>!g)},va=x.useMemo(()=>[{id:"add-box",label:"Add box",description:"Create a user-defined stay, move, or missing-data interval.",icon:Ca,onSelect:()=>Q(ut("stay",S.at(-1)??null))},{id:"sleep",label:K?"Hide sleep":"Show sleep",description:"Toggle sleep overlays without rewriting the movement boxes.",icon:aa,onSelect:()=>xe(l=>{const d=!l;return d&&re&&(p(re),b(!0)),d})},{id:"view-data",label:"View data",description:"Open the canonical loaded records and raw-data filters.",icon:pt,onSelect:()=>q(!0)}],[re,S,K]),Ct=(l,d="smooth")=>{const g=s.current,E=dt.get(l);if(!g||!E)return;const Ee=Math.max(0,E.boxTop-g.clientHeight/2+E.displayHeight/2);if(typeof g.scrollTo=="function"){g.scrollTo({top:Ee,behavior:d});return}g.scrollTop=Ee};x.useEffect(()=>{ae&&(!j.hasNextPage||j.isFetchingNextPage||j.fetchNextPage())},[ae,j.fetchNextPage,j.hasNextPage,j.isFetchingNextPage]),x.useEffect(()=>{const l=M.at(-1);!h.current&&l&&(h.current=!0,p(l.id))},[M]),x.useEffect(()=>{if(!r.current&&M.length>0){r.current=!0,requestAnimationFrame(()=>{var d;const l=(d=M[M.length-1])==null?void 0:d.id;l&&Ct(l,"auto"),requestAnimationFrame(()=>{Me()})});return}if(o.current&&M.length>o.current.count&&s.current){const l=o.current;o.current=null,requestAnimationFrame(()=>{const d=s.current;if(!d)return;const g=I.totalHeight-l.size;d.scrollTop+=g,Me()})}},[M.length,I.totalHeight,dt]),x.useEffect(()=>{if(!s.current)return;const d=()=>{Me()};return d(),window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[]),x.useEffect(()=>{if(!m)return;const l=S.find(d=>d.id===m);l&&H(d=>d[m]?d:{...d,[m]:wt(l)})},[S,m]),x.useEffect(()=>{var l;m&&(M.some(d=>d.id===m)||(p(((l=M.at(-1))==null?void 0:l.id)??null),b(!1)))},[M,m]),x.useEffect(()=>{if(!K||!re)return;const l=M.findIndex(d=>d.id===re);l<0||(p(re),requestAnimationFrame(()=>{var g;const d=(g=M[l])==null?void 0:g.id;d&&Ct(d)}))},[M,re,K,dt]);const ot=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"]})])},Pt=ke({mutationFn:async l=>{const{segment:d,draft:g,creating:E}=l,Ee=yt(g,d);if(E){await Ot(Ee,t);return}if(!d)throw new Error("No movement box selected.");if(d.sourceKind!=="user_defined")throw new Error("Automatic movement boxes are immutable. Invalidate them into missing data or create a user-defined override instead.");await Ht(d.boxId,{...Ee,metadata:{updatedFrom:"movement-life-timeline"}},t)},onSuccess:ot}),wa=async(l,d)=>{if(l.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");const g=js(l,d.label);if(l.sourceKind==="user_defined"){await Ht(l.boxId,{...g,metadata:{updatedFrom:"movement-life-timeline-place-label"}},t);return}await Ot({...g,metadata:{createdFrom:"movement-life-timeline-place-label"}},t)},Lt=async(l,d)=>{if(l.rawStayIds.length===0)throw new Error("This stay has no raw stay ids to relabel.");await Promise.all(l.rawStayIds.map(g=>_a(g,{placeExternalUid:d.externalUid,placeLabel:d.label})))},ya=(l,d)=>{const g=vt(l);if(!g)return!0;const E=et(g.latitude,g.longitude,d.latitude,d.longitude);return E<=100||typeof window>"u"||typeof window.confirm!="function"?!0:window.confirm(`"${d.label}" is ${Te(E)} away from this stay's recorded center. Link it anyway?`)},ja=ke({mutationFn:async l=>{const{segment:d,...g}=l,E=await na(g,t);return d&&le(d)&&await Lt(d,E.place),E},onSuccess:ot}),Na=ke({mutationFn:async l=>{const{segment:d,place:g}=l;if(!ya(d,g))return{assigned:!1};if(le(d))return await Lt(d,g),{assigned:!0};if(d.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");return await wa(d,g),{assigned:!0}},onSuccess:async l=>{l.assigned&&await ot()}}),ct=ke({mutationFn:async l=>{if(l.sourceKind==="user_defined"){await Fa(l.boxId,t);return}await Ea(l.boxId,{title:"User invalidated automatic movement",subtitle:`Overrides ${me(l)} with missing data.`},t)},onSuccess:async(l,d)=>{p(g=>g===d.id?null:g),b(!1),_(g=>g===d.id?null:g),a.setQueryData(["forge-movement-life-timeline",...t],g=>Zt(g,d.id)),a.setQueryData(["forge-movement-life-timeline-data",...t],g=>Zt(g,d.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"]})])}}),Sa=x.useMemo(()=>Ss(J),[J]),ve=x.useMemo(()=>{const l=ue(y);return[...J].sort((d,g)=>new Date(g.endedAt).getTime()-new Date(d.endedAt).getTime()).filter(d=>(l.length===0||Ns(d).includes(l))&&Ms(d,ge))},[J,y,ge]),Dt=x.useMemo(()=>J.length===0?"No movement records loaded yet.":ve.length===J.length&&y.trim().length===0&&ge.length===0?`${J.length} loaded movement records visible`:`${ve.length} of ${J.length} loaded records visible`,[J.length,ve.length,y,ge.length]),mt=sa({count:ve.length,getScrollElement:()=>i.current,estimateSize:()=>136,overscan:8}),L=V?S.find(l=>l.id===V)??null:null,Ma=L?F[L.id]??wt(L):null,Ye=Y!==null,$=Y??Ma,It=((_t=S[0])==null?void 0:_t.startedAt)??null,$t=((zt=S[S.length-1])==null?void 0:zt.endedAt)??null,xt=te({queryKey:["forge-movement-user-box-preflight",(L==null?void 0:L.boxId)??"create",($==null?void 0:$.kind)??null,($==null?void 0:$.startedAtInput)??null,($==null?void 0:$.endedAtInput)??null,It,$t,...t],enabled:$!==null&&at($.startedAtInput)!==null&&at($.endedAtInput)!==null,queryFn:async()=>{if(!$)return null;const l=yt($,L);return(await Ra({...l,excludeBoxId:(L==null?void 0:L.sourceKind)==="user_defined"?L.boxId:null,rangeStart:It,rangeEnd:$t},t)).preflight}}),Ft=l=>{le(l)&&(Ce(l.id),Le(!0))},ka=(l,d)=>{const g=vt(l);g&&(Le(!1),Ce(l.id),Se({...g,label:d.trim()||g.label}),De(l.id),Ne(!0))},Aa=()=>{const l=s.current;l&&(Ve(l.scrollTop),Ie(l.clientHeight),!(!C.hasNextPage||C.isFetchingNextPage)&&l.scrollTop<=960&&(o.current={count:M.length,size:I.totalHeight},C.fetchNextPage()))};if(C.isPending)return e.jsx(la,{eyebrow:"Movement",title:"Loading life timeline",description:"Reconstructing the longer road of stays, moves, and places.",columns:1,blocks:6});if(C.isError)return e.jsx(da,{eyebrow:"Movement",error:C.error,onRetry:()=>void C.refetch()});const Ta=I.totalHeight;return e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(v,{className:"overflow-hidden rounded-[28px] border border-white/8 bg-[radial-gradient(circle_at_top,rgba(88,182,255,0.08),transparent_28%),linear-gradient(180deg,rgba(4,8,17,0.99),rgba(5,9,18,0.97))] p-3 sm:rounded-[34px] sm:p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 px-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.22em] text-white/34",children:"Movement"}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-2",children:[oe>0?e.jsxs(u,{className:"hidden bg-amber-500/10 text-amber-100 sm:inline-flex",children:[oe," invalid hidden"]}):null,e.jsxs(u,{className:"hidden bg-white/[0.06] text-white/68 sm:inline-flex",children:[M.length," visible"]}),e.jsx("div",{ref:c,children:e.jsxs(k,{type:"button",variant:"ghost",size:"sm","aria-expanded":A,"aria-haspopup":"dialog",className:O("h-9 rounded-full border border-white/10 bg-white/[0.05] px-3 text-white/78 hover:bg-white/[0.1] hover:text-white",A?"ring-1 ring-[rgba(126,229,255,0.34)]":""),onClick:fa,children:[e.jsx(Pa,{className:"size-4"}),"Actions"]})})]})]}),e.jsx(_s,{open:A,anchor:w,items:va,onClose:()=>B(!1)}),K&&Fe.length===0?e.jsx("p",{className:"mb-3 px-1 text-sm text-amber-100/80",children:"No sleep session overlaps the currently loaded timeline range yet. Scroll further back to load older history."}):null,e.jsxs("div",{ref:s,onScroll:Aa,className:"relative h-[82vh] overflow-auto rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(4,7,15,0.98),rgba(6,10,18,0.96))]",children:[e.jsx(Is,{layout:I,scrollTop:he,viewportHeight:z}),Tt?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-white/10 bg-[rgba(8,13,24,0.86)] px-3 py-1.5 font-label text-[10px] uppercase tracking-[0.18em] text-white/70 shadow-[0_16px_36px_rgba(0,0,0,0.28)] backdrop-blur-xl",children:Tt})}):null,e.jsxs("div",{className:"relative",style:{height:`${Ta}px`},children:[I.historyHeaderHeight>0?e.jsx("div",{className:"absolute inset-x-0 top-0",style:{height:`${I.historyHeaderHeight}px`},children:e.jsx(Fs,{segment:M[0]??null})}):null,ba.map(l=>{const d=l.segment;return e.jsx(Bs,{layout:l,selected:m===d.id,onToggle:()=>{p(d.id),b(!0)}},d.id)})]})]})]}),e.jsx(Ks,{open:L!==null||Y!==null,segment:L,draft:$,creating:Ye,saving:Pt.isPending,preflight:xt.data??null,preflightLoading:xt.isFetching,onDraftChange:l=>{if(Ye){Q(l);return}L&&H(d=>({...d,[L.id]:l}))},onFitMissing:()=>{const l=xt.data;if(!(l!=null&&l.nearestMissingStartedAt)||!l.nearestMissingEndedAt)return;const d={...$??ut("stay",L),startedAtInput:Ae(l.nearestMissingStartedAt),endedAtInput:Ae(l.nearestMissingEndedAt)};if(Ye){Q(d);return}L&&H(g=>({...g,[L.id]:d}))},onSave:()=>{$&&Pt.mutateAsync({segment:L,draft:$,creating:Ye},{onSuccess:()=>{_(null),Q(null),se&&(ie(!1),q(!0))}})},onOpenChange:l=>{l||(_(null),Q(null),se&&(ie(!1),q(!0)))}}),e.jsx(Os,{open:N&&f!==null,onOpenChange:l=>{b(l)},segment:f,onEdit:()=>{f!=null&&f.editable&&(_(f.id),b(!1))},onOpenDetail:()=>{f&&(Z(f.id),b(!1))},onDefinePlace:()=>{f&&(Ft(f),b(!1))}}),e.jsx(Rs,{open:n!==null,onOpenChange:l=>{l||Z(null)},segment:n,detail:ee.data??null,loading:ee.isFetching,onEdit:()=>{!n||!n.editable||(_(n.id),Z(null))},onDefinePlace:()=>{n&&Ft(n)}}),e.jsx(Hs,{open:Pe,onOpenChange:l=>{Le(l),l||Ce(null)},segment:U,places:ne.data??[],loading:ne.isFetching,onSelectPlace:async l=>U?(await Na.mutateAsync({segment:U,place:l})).assigned:!1,onCreatePlace:(l,d)=>{ka(l,d)}}),e.jsx(xa,{open:Ue,onOpenChange:l=>{Ne(l),l||(Se(null),De(null))},place:null,seed:nt,onSave:async l=>{await ja.mutateAsync({...l,segment:S.find(d=>d.id===lt)??null})}}),e.jsx(oa,{open:ae,onOpenChange:l=>{q(l),l||se||(We(""),Ge([]))},eyebrow:"Movement data",title:"View data",description:"",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(ma,{title:"",description:"",query:y,onQueryChange:We,options:Sa,selectedOptionIds:ge,onSelectedOptionIdsChange:Ge,resultSummary:Dt,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(v,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Canonical boxes"}),e.jsx("div",{className:"max-w-3xl text-sm leading-6 text-white/56",children:"This list shows the canonical movement boxes projected by Forge. Automatic boxes are derived from immutable raw phone measurements. User-defined boxes override the projection without mutating raw movement data."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/70",onClick:()=>{ie(!0),q(!1),Q(ut("stay",ve.at(-1)??null))},children:"Add box"}),e.jsx(u,{tone:"meta",children:Dt}),oe>0?e.jsxs(u,{className:"bg-amber-500/10 text-amber-100",children:[oe," invalid hidden included"]}):null,j.hasNextPage?e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/70",pending:j.isFetchingNextPage,pendingLabel:"Loading…",onClick:()=>void j.fetchNextPage(),children:"Load older"}):null]})]}),e.jsx("div",{ref:i,className:"h-[36rem] overflow-y-auto rounded-[24px] border border-white/8 bg-white/[0.03]",children:ve.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-white/50",children:"No movement record matches the current search. Clear filters or load older timeline history."}):e.jsx("div",{className:"relative w-full",style:{height:`${mt.getTotalSize()}px`},children:mt.getVirtualItems().map(l=>{var g;const d=ve[l.index];return e.jsx("div",{ref:mt.measureElement,"data-index":l.index,className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${l.start}px)`},children:e.jsxs("div",{className:"flex items-start gap-2 rounded-[18px] border border-white/8 bg-white/[0.04] px-3 py-2.5",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left transition hover:opacity-100",onClick:()=>{d.editable&&(ie(!0),q(!1),_(d.id))},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white",children:[d.kind==="stay"?e.jsx(ia,{className:"size-3.5 shrink-0 text-[var(--primary)]"}):d.kind==="missing"?e.jsx(pt,{className:"size-3.5 shrink-0 text-slate-300/80"}):e.jsx(tt,{className:"size-3.5 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-sm font-medium",children:me(d)})]}),e.jsxs("div",{className:"mt-1 text-xs text-white/56",children:[it(d.startedAt)," →"," ",it(d.endedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1.5",children:[e.jsx(u,{tone:d.kind==="trip"?"signal":"meta",children:d.kind==="trip"?"Move":d.kind==="missing"?"Missing":"Stay"}),e.jsx(u,{className:d.sourceKind==="user_defined"?"bg-fuchsia-400/12 text-fuchsia-100":"bg-white/[0.06] text-white/70",children:d.sourceKind==="user_defined"?d.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),e.jsx(u,{tone:"meta",children:ze(d.durationSeconds)}),d.origin==="continued_stay"?e.jsx(u,{className:"bg-sky-400/10 text-sky-100",children:"Continued stay"}):null,d.origin==="repaired_gap"?e.jsx(u,{className:"bg-amber-400/10 text-amber-100",children:"Repaired"}):null,d.kind==="missing"?e.jsx(u,{className:"bg-slate-300/10 text-slate-100",children:"Missing"}):null,d.isInvalid?e.jsx(u,{className:"bg-amber-500/10 text-amber-100",children:"Invalid"}):null,d.placeLabel?e.jsx(u,{tone:"default",children:d.placeLabel}):null,d.overrideCount>0?e.jsxs(u,{className:"bg-amber-400/10 text-amber-100",children:["Overrides ",d.overrideCount]}):null,e.jsxs(u,{className:"bg-white/[0.06] text-white/66",children:["Raw stays ",d.rawStayIds.length]}),e.jsxs(u,{className:"bg-white/[0.06] text-white/66",children:["Raw trips ",d.rawTripIds.length]}),e.jsxs(u,{className:"bg-white/[0.06] text-white/66",children:["Raw points ",d.rawPointCount]}),d.hasLegacyCorrections?e.jsx(u,{className:"bg-amber-400/10 text-amber-100",children:"Legacy corrections"}):null]})]})}),e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:O("h-8 shrink-0 rounded-full border px-2.5",d.sourceKind==="user_defined"?"border-rose-400/22 bg-rose-500/10 text-rose-100 hover:bg-rose-500/18":"border-amber-400/22 bg-amber-500/10 text-amber-100 hover:bg-amber-500/18"),pending:ct.isPending&&((g=ct.variables)==null?void 0:g.id)===d.id,pendingLabel:"",onClick:()=>{window.confirm(d.sourceKind==="user_defined"?`Delete ${me(d)} and remove this user-defined box from every synced surface?`:`Invalidate ${me(d)} into missing data and hide the automatic box everywhere?`)&&ct.mutateAsync(d)},children:e.jsx(La,{className:"size-3.5"})})]})},d.id)})})})]})]})})]})}function Qs(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}).format(new Date(t))}function Us(t,a){const s=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${s.format(new Date(t))} - ${s.format(new Date(a))}`}function R(t){return t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.round(t/60)}m`}function we(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Ws(t,a){return t==="distanceMeters"?we(a):t==="caloriesKcal"?`${Math.round(a)} kcal`:R(a)}function ga(t){return t.trim().toLowerCase()}function rt(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function At(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Gs(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function ta(t){return{recordedAt:Gs(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 Vs(t){return ga([At(t.recordedAt),t.externalUid,t.isStopAnchor?"stop anchor stop":"path trace point",t.accuracyMeters!=null?`${Math.round(t.accuracyMeters)} meters accuracy`:"",rt(t.recordedAt)].join(" "))}function Ys(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(u,{tone:"meta",children:"Stop anchors"})}),a.set("anchor:path",{id:"anchor:path",label:"Path points",description:"Non-anchor trace points",badge:e.jsx(u,{tone:"meta",children:"Path points"})}),a.set("accuracy:precise",{id:"accuracy:precise",label:"Precise",description:"GPS accuracy below 20m",badge:e.jsx(u,{tone:"meta",children:"Precise"})}),a.set("accuracy:loose",{id:"accuracy:loose",label:"Loose accuracy",description:"GPS accuracy at or above 20m",badge:e.jsx(u,{tone:"meta",children:"Loose accuracy"})}),t.forEach(s=>{const i=rt(s.recordedAt);a.has(`time:${i}`)||a.set(`time:${i}`,{id:`time:${i}`,label:i,description:"Recorded during this time band",badge:e.jsx(u,{tone:"meta",className:"capitalize",children:i})})}),[...a.values()]}function Xs(t,a){return a.every(s=>s==="anchor:stop"?t.isStopAnchor:s==="anchor:path"?!t.isStopAnchor:s==="accuracy:precise"?t.accuracyMeters!=null&&t.accuracyMeters<20:s==="accuracy:loose"?t.accuracyMeters==null||t.accuracyMeters>=20:s.startsWith("time:")?rt(t.recordedAt)===s.slice(5):!0)}function Zs(t){if(t.length===0)return[];const a=Math.min(...t.map(o=>o.latitude)),s=Math.max(...t.map(o=>o.latitude)),i=Math.min(...t.map(o=>o.longitude)),c=Math.max(...t.map(o=>o.longitude)),r=Math.max(s-a,1e-4),h=Math.max(c-i,1e-4);return t.map(o=>({x:12+(o.longitude-i)/h*76,y:12+(1-(o.latitude-a)/r)*76}))}function Js({curve:t,startLabel:a,endLabel:s,stopLabels:i}){const c=t.map((r,h)=>`${h===0?"M":"Q"} ${r.x} ${r.y}`).join(" ");return e.jsxs(v,{className:"overflow-hidden rounded-[30px] border border-white/10 bg-[radial-gradient(circle_at_top,rgba(114,204,255,0.18),transparent_44%),linear-gradient(180deg,rgba(6,11,26,0.98),rgba(8,14,28,0.92))] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Stylized trajectory"}),e.jsx(ce,{content:"This graph is a softened trip trace. It emphasizes rhythm, stops, and endpoints instead of raw GPS jitter."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/64",children:"A softened path that prioritizes rhythm, stops, and landmarks over raw map noise."})]}),e.jsxs(u,{tone:"signal",children:[a," → ",s]})]}),e.jsxs("div",{className:"mt-5 rounded-[26px] border border-white/8 bg-[rgba(255,255,255,0.03)] p-4",children:[e.jsxs("svg",{viewBox:"0 0 100 60",className:"h-48 w-full",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"movementGlow",children:[e.jsx("feGaussianBlur",{stdDeviation:"1.8",result:"blur"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"blur"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),e.jsx("path",{d:c,fill:"none",stroke:"rgba(255,255,255,0.86)",strokeWidth:"1.5",strokeDasharray:"2.8 2.8",filter:"url(#movementGlow)"}),t.map((r,h)=>e.jsx("g",{children:e.jsx("circle",{cx:r.x,cy:r.y,r:h===0||h===t.length-1?2.6:1.6,fill:h===0||h===t.length-1?"#ffffff":"rgba(170,229,255,0.96)"})},`${r.x}-${r.y}-${h}`))]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:i.map(r=>e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:r},r))})]})]})}function ei({points:t}){const a=Zs(t),s=a.map((i,c)=>`${c===0?"M":"L"} ${i.x} ${i.y}`).join(" ");return e.jsxs(v,{className:"rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,13,25,0.95),rgba(10,17,30,0.88))] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Exact path"}),e.jsx(ce,{content:"This keeps the recent raw location points. Use it when you want the literal recorded trace instead of the cleaned movement graph."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/62",children:"Recent raw points preserved by the companion before long-term simplification."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-white/8 bg-[rgba(255,255,255,0.03)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"rgba(255,255,255,0.02)"}),e.jsx("path",{d:s,fill:"none",stroke:"rgba(92,225,230,0.95)",strokeWidth:"1.6"}),a.map((i,c)=>e.jsx("circle",{cx:i.x,cy:i.y,r:c===0||c===a.length-1?2:1.1,fill:c===0||c===a.length-1?"#ffffff":"rgba(92,225,230,0.9)"},`${i.x}-${i.y}-${c}`))]})})]})}function ti({point:t,draft:a}){return e.jsxs(v,{className:"grid gap-4 rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(12,18,32,0.98),rgba(8,13,24,0.98))] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Raw datapoint"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:At(t.recordedAt)}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Raw phone measurements are immutable in product UI. To change the visible movement story, create or edit user-defined boxes in the Life Timeline instead."})]}),e.jsx(u,{tone:t.isStopAnchor?"signal":"meta",children:t.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Recorded at"}),e.jsx(P,{type:"datetime-local",value:a.recordedAt,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Speed (m/s)"}),e.jsx(P,{value:a.speedMps,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Latitude"}),e.jsx(P,{value:a.latitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Longitude"}),e.jsx(P,{value:a.longitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Accuracy (m)"}),e.jsx(P,{value:a.accuracyMeters,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Altitude (m)"}),e.jsx(P,{value:a.altitudeMeters,disabled:!0,placeholder:"Optional"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(k,{variant:"ghost",className:O("h-10 rounded-full border px-4",a.isStopAnchor?"border-[var(--primary)] bg-[var(--primary)]/16 text-white":"border-white/10 bg-white/[0.04] text-white/64"),disabled:!0,children:[e.jsx(tt,{className:"mr-2 size-4"}),a.isStopAnchor?"Stop anchor":"Path point"]}),e.jsxs("div",{className:"text-sm text-white/50",children:["External id: ",e.jsx("span",{className:"text-white/72",children:t.externalUid})]})]}),e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-3 text-sm leading-6 text-white/56",children:"This browser is read-only now. Raw points stay immutable so the web app and iPhone can both project the same repaired canonical boxes from the backend."})]})}function hi(){var $e,fe,M,Fe,re;const t=Oa(),a=ra(),s=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[i,c]=x.useState("life"),[r,h]=x.useState(new Date().toISOString().slice(0,10)),[o,m]=x.useState(new Date().toISOString().slice(0,7)),[p,N]=x.useState(null),[b,A]=x.useState(!1),[B,w]=x.useState(!1),[T,F]=x.useState(""),[H,V]=x.useState([]),[_,Y]=x.useState(null),[Q,X]=x.useState(null),[Z,Qe]=x.useState({stayIds:[],tripIds:[]}),[Ce,Pe]=x.useState(!1),[Le,Ue]=x.useState(null),[Ne,nt]=x.useState(""),[Se,lt]=x.useState("distanceMeters"),De=x.useRef(null),ae=te({queryKey:["forge-movement-day",r,...s],queryFn:async()=>(await Ga({date:r,userIds:s})).movement}),q=te({queryKey:["forge-movement-month",o,...s],queryFn:async()=>(await Va({month:o,userIds:s})).movement}),se=te({queryKey:["forge-movement-all-time",...s],queryFn:async()=>(await Ya(s)).movement}),ie=te({queryKey:["forge-life-force",...s],queryFn:async()=>(await Xa(s)).lifeForce}),K=te({queryKey:["forge-movement-settings",...s],queryFn:async()=>(await Za(s)).settings}),xe=te({queryKey:["forge-movement-places",...s],queryFn:async()=>(await ca(s)).places}),y=te({queryKey:["forge-movement-trip",p],queryFn:async()=>p?(await Ja(p)).movement:null,enabled:!!p}),We=te({queryKey:["forge-movement-selection",r,Z.stayIds.join(","),Z.tripIds.join(","),...s],queryFn:async()=>(await es({...Z,userIds:s})).movement,enabled:Z.stayIds.length>0||Z.tripIds.length>0}),ge=ke({mutationFn:async n=>Ha({trackingEnabled:n},s),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-settings"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]})}}),Ge=ke({mutationFn:async n=>n.id?Ka(n.id,n):na(n,s),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-places"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]}),await a.invalidateQueries({queryKey:["forge-movement-all-time"]})}}),he=x.useMemo(()=>{const n=xe.data??[],f=Ne.trim().toLowerCase();return f?n.filter(ee=>[ee.label,...ee.aliases,...ee.categoryTags].join(" ").toLowerCase().includes(f)):n},[Ne,xe.data]),Ve=x.useMemo(()=>{var n;return Ys(((n=y.data)==null?void 0:n.trip.points)??[])},[($e=y.data)==null?void 0:$e.trip.points]),z=x.useMemo(()=>{var ee;const n=((ee=y.data)==null?void 0:ee.trip.points)??[],f=ga(T);return[...n].sort((U,ne)=>new Date(ne.recordedAt).getTime()-new Date(U.recordedAt).getTime()).filter(U=>(f.length===0||Vs(U).includes(f))&&Xs(U,H))},[T,H,(fe=y.data)==null?void 0:fe.trip.points]),Ie=x.useMemo(()=>{var f;const n=((f=y.data)==null?void 0:f.trip.points.length)??0;return n===0?"No raw datapoints on this trip yet.":z.length===n&&T.trim().length===0&&H.length===0?`${n} datapoints visible`:`${z.length} of ${n} datapoints visible`},[z.length,T,H.length,(M=y.data)==null?void 0:M.trip.points.length]),Me=sa({count:z.length,getScrollElement:()=>De.current,estimateSize:()=>96,overscan:8}),C=z.find(n=>n.id===_)??((Fe=y.data)==null?void 0:Fe.trip.points.find(n=>n.id===_))??z[0]??((re=y.data)==null?void 0:re.trip.points[0])??null;if(x.useEffect(()=>{if(B){if(!C){Y(null),X(null);return}Y(C.id),X(ta(C))}},[C,B]),x.useEffect(()=>{F(""),V([]),Y(null),X(null),w(!1)},[p]),ae.isLoading||q.isLoading||se.isLoading||K.isLoading||xe.isLoading)return e.jsx(la,{eyebrow:"Movement",title:"Loading movement workspace",description:"Reconstructing stays, trips, and place intelligence across Forge.",columns:2,blocks:8});if(ae.isError||q.isError||se.isError||K.isError||xe.isError||!ae.data||!q.data||!se.data||!K.data)return e.jsx(da,{eyebrow:"Movement",error:ae.error??q.error??se.error??K.error??xe.error??new Error("Movement data unavailable"),onRetry:()=>{ae.refetch(),q.refetch(),se.refetch(),K.refetch(),xe.refetch()}});const j=ae.data,be=q.data,de=se.data,oe=K.data,S=We.data??j.selectionAggregate,J=j.trips.reduce((n,f)=>n+Xe(f).totalAp,0);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ts,{entityKind:"project",title:"Movement",description:"Turn passive place and travel signals into a real Forge domain: day rhythm, travel arcs, known landmarks, linked work, and reflective evidence.",badge:`${j.summary.tripCount} trips today`,actions:e.jsx("div",{className:"flex flex-wrap gap-2",children:["life","day","month","all_time"].map(n=>e.jsx(k,{variant:"ghost",className:O("h-9 rounded-full border px-4 text-sm",i===n?"border-[var(--primary)] bg-[var(--primary)]/16 text-white":"border-white/10 bg-white/[0.04] text-white/64"),onClick:()=>c(n),children:n==="all_time"?"All time":n==="life"?"Life":n.charAt(0).toUpperCase()+n.slice(1)},n))})}),e.jsxs(v,{className:"grid gap-3 rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(12,20,34,0.98),rgba(8,14,25,0.96))] p-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Movement AP today"}),e.jsx("div",{className:"mt-2 text-3xl font-semibold text-white",children:Bt(J)}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Trips and transitions now contribute to the same Action Point ledger as work, habits, and notes."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Typical trip drain"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:j.trips[0]?Ze(Xe(j.trips[0]).rateApPerHour):"0 AP/h"}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Movement uses a MET-like drain under the hood, translated into Forge Action Points."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Life Force sync"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:ie.data?`${Math.round(ie.data.spentTodayAp??0)}/${Math.round(ie.data.dailyBudgetAp??0)} AP`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:ie.data?`${Ze(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(Ba,{children:e.jsxs(v,{className:"overflow-hidden rounded-[30px] border border-white/8 bg-[radial-gradient(circle_at_top_left,rgba(107,214,255,0.16),transparent_42%),linear-gradient(180deg,rgba(10,18,35,0.98),rgba(9,15,28,0.92))]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Movement operating mode"}),e.jsx(ce,{content:"This is the passive capture state of the movement system: whether tracking is running, how much is published into Forge, and how aggressive retention is."})]}),e.jsx("div",{className:"mt-2 text-[clamp(1.05rem,1.8vw,1.35rem)] text-white",children:"Background stays and trips as structured life evidence"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-white/58",children:"The companion samples quietly while stationary, switches to denser trip capture when you move, and keeps only simplified long-term traces."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:oe.trackingEnabled?"Tracking on":"Tracking off"}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/72",children:oe.publishMode.replaceAll("_"," ")}),e.jsx(k,{variant:"ghost",className:"h-9 rounded-full border border-white/10 bg-white/[0.04] px-4",onClick:()=>ge.mutate(!oe.trackingEnabled),children:oe.trackingEnabled?"Pause passive capture":"Enable passive capture"})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Distance today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:we(j.summary.totalDistanceMeters)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Across trips, stops, and linked place changes."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Idle time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.totalIdleSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Time spent settled enough to count as a real stay."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Estimated phone time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.estimatedScreenTimeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Estimated from hourly Screen Time bins, not exact foreground traces."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Known places"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:j.summary.knownPlaceCount}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Shared between Forge and the iPhone companion."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(148,163,184,0.12),rgba(71,85,105,0.12))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Missing data"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.missingDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.missingCount," grey gap",j.summary.missingCount===1?"":"s"," where Forge had over one hour without enough movement signal."]})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(251,191,36,0.12),rgba(16,185,129,0.08))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Repaired gaps"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.repairedGapDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.repairedGapCount," inferred span",j.summary.repairedGapCount===1?"":"s"," classified as stay or move instead of leaving blank holes in the day."]})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(56,189,248,0.12),rgba(99,102,241,0.08))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Continued stays"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.continuedStayDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.continuedStayCount," short stationary span",j.summary.continuedStayCount===1?"":"s"," carried forward so quiet home time stays continuous instead of disappearing."]})]})]})]})}),e.jsx(qa,{children:e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Selection aggregate"}),e.jsx(ce,{content:"When you select stays or trips, Forge totals their span, distance, work overlap, notes, and places here."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Select any combination of stays and trips to sum movement, time, and work evidence."}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Span"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(S.durationSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:we(S.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Work overlap"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(S.trackedWorkSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Notes"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.noteCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Estimated phone time"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(S.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.pickupCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.notificationCount})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:S.placeLabels.map(n=>e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:n},n))}),S.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:S.topApps.map(n=>e.jsx(u,{tone:"default",className:"bg-[rgba(114,204,255,0.12)] text-white/80",children:(n.displayName||n.bundleIdentifier)+" · "+R(n.totalActivitySeconds)},n.id))}):null,S.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:S.topCategories.map(n=>e.jsx(u,{tone:"default",className:"bg-white/[0.05] text-white/64",children:n.categoryLabel},n.id))}):null]})})]}),i==="life"?e.jsx(Qa,{children:e.jsxs("section",{className:"grid gap-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/38",children:"Life graph"}),e.jsx(ce,{content:"This graph shows the movement road of your life: stays are blocks, moves connect them, and the hour/day lines live in the background. Click a segment for details, then use edit when you want to correct it."})]})}),e.jsx(qs,{userIds:s})]})}):null,i==="day"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.55fr)_minmax(22rem,1fr)]",children:[e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(7,12,22,0.92))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Day strip"}),e.jsx(ce,{content:"A compressed 24-hour strip. Each segment keeps its true order and duration, but the whole day stays navigable on one line."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"A single-row timeline from 00:00 to 24:00, always compressed into one navigable strip."})]}),e.jsx(P,{type:"date",value:r,onChange:n=>h(n.target.value),className:"w-[11rem]"})]}),e.jsx("div",{className:"mt-6 overflow-x-auto pb-2",children:e.jsxs("div",{className:"min-w-[52rem]",children:[e.jsx("div",{className:"mb-3 flex justify-between text-[11px] uppercase tracking-[0.18em] text-white/36",children:["00:00","06:00","12:00","18:00","24:00"].map(n=>e.jsx("span",{children:n},n))}),e.jsx("div",{className:"flex h-28 items-stretch overflow-hidden rounded-[28px] border border-white/10 bg-[rgba(255,255,255,0.03)] p-2",children:j.segments.map(n=>{const f=Math.max(9,n.durationSeconds/86400*100),ee=n.kind==="stay"?Z.stayIds.includes(n.id):n.kind==="trip"?Z.tripIds.includes(n.id):!1;return e.jsxs("button",{type:"button",className:O("relative flex min-w-[5.5rem] flex-col justify-between rounded-[22px] border px-3 py-2 text-left transition",n.kind==="missing"?"border-slate-400/20 bg-[linear-gradient(180deg,rgba(148,163,184,0.18),rgba(51,65,85,0.14))] hover:border-slate-300/30 hover:bg-[rgba(148,163,184,0.14)]":ee?"border-[rgba(171,232,255,0.5)] bg-[rgba(171,232,255,0.16)]":"border-white/6 bg-[linear-gradient(180deg,rgba(255,255,255,0.08),rgba(255,255,255,0.02))] hover:border-white/14 hover:bg-white/[0.08]"),style:{width:`${f}%`},onClick:()=>{n.kind!=="missing"&&Qe(U=>{const ne=new Set(U.stayIds),I=new Set(U.tripIds);return n.kind==="stay"?ne.has(n.id)?ne.delete(n.id):ne.add(n.id):I.has(n.id)?I.delete(n.id):(I.add(n.id),N(n.id)),{stayIds:[...ne],tripIds:[...I]}})},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(u,{tone:n.kind==="trip"?"signal":n.kind==="missing"?"meta":"default",className:"bg-white/[0.08] text-white/82",children:n.kind==="missing"?"gap":n.kind}),e.jsx("span",{className:"text-[11px] text-white/46",children:R(n.durationSeconds)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"line-clamp-2 text-sm font-semibold text-white",children:n.label}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-white/52",children:n.subtitle})]})]},n.id)})})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:Qs(r)}),e.jsxs(u,{tone:"default",className:"bg-white/[0.06] text-white/72",children:[j.summary.tripCount," trips"]}),e.jsxs(u,{tone:"default",className:"bg-white/[0.06] text-white/72",children:[j.summary.stayCount," stays"]}),e.jsxs(u,{tone:"meta",children:[j.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-white/42",children:"Selected trip"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(k,{variant:"ghost",className:"h-9 rounded-full border border-white/10 bg-white/[0.04] px-4",onClick:()=>A(n=>!n),children:b?"Stylized graph":"Exact path"})})]}),b?e.jsx(ei,{points:y.data.trip.points}):e.jsx(Js,{curve:y.data.stylizedPath.curve,startLabel:y.data.stylizedPath.startLabel,endLabel:y.data.stylizedPath.endLabel,stopLabels:y.data.stylizedPath.stops.map(n=>n.label)}),e.jsxs(v,{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Trip context"}),(()=>{const n=Xe(y.data.trip);return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:we(y.data.trip.distanceMeters)}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:y.data.trip.activityType||y.data.trip.travelMode}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:R(y.data.trip.durationSeconds)}),e.jsx(u,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:Ze(n.rateApPerHour)}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:Bt(n.totalAp)})]})})})(),e.jsx("div",{className:"mt-4 text-sm leading-6 text-white/58",children:Us(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-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Hourly estimate"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(y.data.trip.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:y.data.trip.pickupCount})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:y.data.trip.notificationCount})]})]}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-white/48",children:"Derived from Screen Time hourly bins, not exact foreground traces."}),y.data.trip.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:y.data.trip.topApps.map(n=>e.jsx(u,{tone:"default",className:"bg-[rgba(114,204,255,0.12)] text-white/80",children:(n.displayName||n.bundleIdentifier)+" · "+R(n.totalActivitySeconds)},n.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(n=>e.jsx(u,{tone:"default",className:"bg-white/[0.05] text-white/64",children:n.categoryLabel},n.id))}):null]})]}):e.jsx(v,{className:"rounded-[30px] border border-dashed border-white/12 bg-white/[0.03] p-6 text-white/58",children:"Select a trip segment to open the stylized trajectory card and exact path toggle."})})]}):null,i==="month"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(18rem,0.85fr)]",children:[e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(9,15,28,0.97),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Month view"}),e.jsx(ce,{content:"This chart stays quantitative. Switch the metric to compare daily distance, moving time, idle time, or calories across the month."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Switch the Y-axis between motion, idle time, and energy without losing the same monthly frame."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{type:"month",value:o,onChange:n=>m(n.target.value),className:"w-[10.5rem]"}),["distanceMeters","movingSeconds","idleSeconds","caloriesKcal"].map(n=>e.jsx(k,{variant:"ghost",className:O("h-9 rounded-full border px-4 text-sm",Se===n?"border-[var(--primary)] bg-[var(--primary)]/14 text-white":"border-white/10 bg-white/[0.04] text-white/62"),onClick:()=>lt(n),children:n==="distanceMeters"?"Distance":n==="movingSeconds"?"Moving":n==="idleSeconds"?"Idle":"Calories"},n))]})]}),e.jsx("div",{className:"mt-6 h-[24rem]",children:e.jsx(as,{width:"100%",height:"100%",children:e.jsxs(ss,{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:"rgba(110,220,255,0.7)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(110,220,255,0.05)"})]})}),e.jsx(is,{stroke:"rgba(255,255,255,0.08)",vertical:!1}),e.jsx(rs,{dataKey:"dateKey",tick:{fill:"rgba(255,255,255,0.46)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(ns,{tick:{fill:"rgba(255,255,255,0.46)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(ls,{contentStyle:{background:"rgba(7,12,24,0.94)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:16},formatter:n=>Ws(Se,Number(n))}),e.jsx(ds,{type:"monotone",dataKey:Se,stroke:"rgba(126,233,255,0.95)",fill:"url(#movementMonthFill)",strokeWidth:2.4})]})})})]}),e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Month totals"}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:we(be.totals.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Moving time"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:R(be.totals.movingSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Settled time"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:R(be.totals.idleSeconds)})]})]})]})]}):null,i==="all_time"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(20rem,0.95fr)]",children:[e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(8,13,25,0.97),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Trips"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:de.summary.tripCount})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Known places"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:de.summary.knownPlaceCount})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:we(de.summary.totalDistanceMeters)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Countries"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:de.summary.visitedCountries})]})]}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:de.recentTrips.map(n=>e.jsx("button",{type:"button",className:"rounded-[24px] border border-white/8 bg-white/[0.03] p-4 text-left transition hover:bg-white/[0.06]",onClick:()=>{c("day"),N(n.id)},children:(()=>{const f=Xe({startedAt:n.startedAt,endedAt:new Date(new Date(n.startedAt).getTime()+36e5).toISOString(),expectedMet:2});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Recent travel"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:n.label||"Untitled trip"}),e.jsxs("div",{className:"mt-1 text-sm text-white/56",children:[we(n.distanceMeters)," · ",n.activityType||"travel"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(u,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:Ze(f.rateApPerHour)})})]})})()},n.id))})]}),e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Place categories"}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:de.categoryBreakdown.map(n=>e.jsxs(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:[n.tag," · ",n.count]},n.tag))})]})]}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(22rem,0.95fr)]",children:[e.jsx(Ua,{children:e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(8,14,28,0.96),rgba(9,15,28,0.92))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Known places"}),e.jsx(ce,{content:"Known places turn raw stationary spans into named contexts like home, work, gym, nature, or any custom place tag you want Forge to remember."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"These landmarks anchor stays, travel XP, and contextual reasoning in both Forge and the companion. Seeded tags like home, workplace, gym, holiday, grocery, or nature matter for downstream calculations, but place tags stay open-ended."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{value:Ne,onChange:n=>nt(n.target.value),placeholder:"Search places",className:"w-[11rem]"}),e.jsx(k,{onClick:()=>{Ue(null),Pe(!0)},children:"Add place"})]})]}),e.jsx("div",{className:"mt-5 grid gap-3",children:he.map(n=>e.jsxs("button",{type:"button",className:"flex items-start justify-between gap-3 rounded-[24px] border border-white/8 bg-white/[0.03] p-4 text-left transition hover:bg-white/[0.06]",onClick:()=>{Ue(n),Pe(!0)},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-white",children:n.label}),e.jsxs("div",{className:"mt-1 text-sm text-white/56",children:[n.latitude.toFixed(4),", ",n.longitude.toFixed(4)," · radius ",Math.round(n.radiusMeters)," m"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:n.categoryTags.map(f=>e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:f},f))})]}),e.jsx(Mt,{className:"mt-1 size-4 text-white/42"})]},n.id))})]})}),e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Movement help"}),e.jsx(ce,{content:"Most movement surfaces on this page have help buttons. Use them to understand the graph, the day strip, the month chart, and the place system without keeping a large prose block on screen."})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-white/58",children:"Use the small help icons across this page for graph explanations, timeline semantics, and metric meanings."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Life graph"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Day strip"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Month chart"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Known places"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Selection aggregate"})]})]})]}),y.data?e.jsx(oa,{open:B,onOpenChange:n=>{w(n),n||(F(""),V([]),Y(null),X(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(Wa,{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:T,onQueryChange:F,options:Ve,selectedOptionIds:H,onSelectedOptionIdsChange:V,resultSummary:Ie,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(v,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Raw datapoints"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:"Open a point to correct or delete it."})]}),e.jsx(u,{tone:"meta",children:Ie})]}),e.jsx("div",{ref:De,className:"h-[34rem] overflow-y-auto rounded-[24px] border border-white/8 bg-white/[0.03]",children:z.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-white/50",children:"No datapoint matches the current search. Clear some filters or search by time, anchor type, or accuracy."}):e.jsx("div",{className:"relative w-full",style:{height:`${Me.getTotalSize()}px`},children:Me.getVirtualItems().map(n=>{const f=z[n.index];return e.jsx("div",{className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${n.start}px)`},children:e.jsxs("button",{type:"button",className:O("grid w-full gap-3 rounded-[20px] border px-4 py-3 text-left transition",_===f.id?"border-[rgba(171,232,255,0.34)] bg-[rgba(171,232,255,0.12)]":"border-white/8 bg-white/[0.04] hover:bg-white/[0.07]"),onClick:()=>{Y(f.id),X(ta(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-white",children:[e.jsx($a,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:At(f.recordedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[f.latitude.toFixed(5),", ",f.longitude.toFixed(5)]})]}),e.jsx(u,{tone:f.isStopAnchor?"signal":"meta",children:f.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{tone:"meta",className:"capitalize",children:rt(f.recordedAt)}),f.accuracyMeters!=null?e.jsxs(u,{tone:"meta",children:[Math.round(f.accuracyMeters)," m accuracy"]}):null,f.speedMps!=null?e.jsxs(u,{tone:"meta",children:[f.speedMps.toFixed(1)," m/s"]}):null]})]})},f.id)})})})]})]}),C&&Q?e.jsx(ti,{point:C,draft:Q}):e.jsx(v,{className:"rounded-[28px] border border-dashed border-white/12 bg-white/[0.03] p-6 text-white/56",children:"Pick a datapoint to inspect its raw measurement details. To correct what the user sees, use canonical user-defined movement boxes in the Life Timeline."})]})})}):null,e.jsx(xa,{open:Ce,onOpenChange:Pe,place:Le,onSave:async n=>{await Ge.mutateAsync(n)}})]})}export{hi as MovementPage};
1
+ import{r as x,j as e,aK as Nt,b4 as Ca,cq as aa,cr as pt,cs as sa,ct as Pa,c3 as ia,aZ as tt,c7 as La,o as Da,bg as St,bX as Ia,c4 as Mt,bc as $a}from"./vendor-DHkYh85p.js";import{j as ra,x as Rt,i as te,k as ke}from"./state-B-4sS1xO.js";import{I as P,B as k,aY as Ot,aZ as Ht,a_ as na,a$ as Fa,b0 as Ea,S as la,E as da,C as v,c as u,Z as O,aS as oa,b1 as _a,b2 as Kt,b3 as za,b4 as ca,b5 as Ra,u as Oa,b6 as Ha,b7 as Ka,b8 as Xe,h as Bt,d as Ze,b9 as Ba,aq as ce,ba as qa,bb as Qa,bc as Ua,bd as Wa,be as Ga,bf as Va,bg as Ya,O as Xa,bh as Za,bi as Ja,bj as es}from"./index-CF4J4R9L.js";import{F as ma}from"./faceted-token-search-BxRRcM3q.js";import{P as ts}from"./page-hero-DRy5b2MU.js";import{R as Re,P as Oe,O as He,C as Ke,T as Be,D as qe,a as _e}from"./ui-C13Nbgas.js";import{m as qt}from"./motion-BeD44FeG.js";import{R as as,A as ss,C as is,X as rs,Y as ns,T as ls,a as ds}from"./charts-P7EVhIog.js";import"./board-BkDRaMp6.js";import"./forms-BFlTgZ3W.js";import"./graph-D6JLqDbD.js";function xa({open:t,onOpenChange:a,place:s,seed:i,onSave:c}){const[r,h]=x.useState({label:(s==null?void 0:s.label)??(i==null?void 0:i.label)??"",latitude:String((s==null?void 0:s.latitude)??(i==null?void 0:i.latitude)??""),longitude:String((s==null?void 0:s.longitude)??(i==null?void 0:i.longitude)??""),radiusMeters:String((s==null?void 0:s.radiusMeters)??(i==null?void 0:i.radiusMeters)??100),categoryTags:((s==null?void 0:s.categoryTags)??(i==null?void 0:i.categoryTags)??[]).join(", ")});return x.useEffect(()=>{h({label:(s==null?void 0:s.label)??(i==null?void 0:i.label)??"",latitude:String((s==null?void 0:s.latitude)??(i==null?void 0:i.latitude)??""),longitude:String((s==null?void 0:s.longitude)??(i==null?void 0:i.longitude)??""),radiusMeters:String((s==null?void 0:s.radiusMeters)??(i==null?void 0:i.radiusMeters)??100),categoryTags:((s==null?void 0:s.categoryTags)??(i==null?void 0:i.categoryTags)??[]).join(", ")})},[s,i]),e.jsx(Re,{open:t,onOpenChange:a,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(32rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:s?`Edit ${s.label}`:"New known place"}),e.jsx(qe,{className:"mt-1 text-sm text-white/58",children:"Define life landmarks once so the companion and web views can reason about stays and trips consistently."})]}),e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white",children:e.jsx(Nt,{className:"size-4"})})})]}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsx(P,{value:r.label,onChange:o=>h(m=>({...m,label:o.target.value})),placeholder:"Home, Main Office, Riverside path..."}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsx(P,{value:r.latitude,onChange:o=>h(m=>({...m,latitude:o.target.value})),placeholder:"Latitude"}),e.jsx(P,{value:r.longitude,onChange:o=>h(m=>({...m,longitude:o.target.value})),placeholder:"Longitude"})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-[10rem_minmax(0,1fr)]",children:[e.jsx(P,{value:r.radiusMeters,onChange:o=>h(m=>({...m,radiusMeters:o.target.value})),placeholder:"Radius meters"}),e.jsx(P,{value:r.categoryTags,onChange:o=>h(m=>({...m,categoryTags:o.target.value})),placeholder:"home, gym, holiday, parents-house"})]})]}),e.jsxs("div",{className:"mt-5 flex justify-end gap-2",children:[e.jsx(k,{variant:"ghost",onClick:()=>a(!1),className:"border border-white/10 bg-white/[0.04]",children:"Cancel"}),e.jsx(k,{onClick:()=>void c({id:s==null?void 0:s.id,label:r.label,latitude:Number(r.latitude),longitude:Number(r.longitude),radiusMeters:Number(r.radiusMeters),categoryTags:r.categoryTags.split(",").map(o=>o.trim()).filter(Boolean)}).then(()=>a(!1)),children:"Save place"})]})]})]})})}const gt=1e3;function D(t){return new Date(t).getTime()}function bt(t){return new Date(t).toISOString()}function Qt(t,a){const s=D(t.startedAt)-D(a.startedAt);if(s!==0)return s;const i=D(t.endedAt)-D(a.endedAt);return i!==0?i:t.id.localeCompare(a.id)}function kt(t){return t.syncSource==="sleep overlay"}function os(t){const a=[...t].filter(i=>D(i.endedAt)>D(i.startedAt)).sort((i,c)=>{const r=D(i.startedAt)-D(c.startedAt);if(r!==0)return r;const h=D(i.endedAt)-D(c.endedAt);return h!==0?h:i.id.localeCompare(c.id)});if(a.length===0)return[];const s=[];for(const i of a){const c=s.at(-1);if(!c){s.push(i);continue}const r=D(c.endedAt);if(D(i.startedAt)<=r+gt){const o=Math.max(r,D(i.endedAt));s[s.length-1]={...c,id:`${c.id}__${i.id}`,endedAt:bt(o),asleepSeconds:(c.asleepSeconds??0)+(i.asleepSeconds??0)||null,timeInBedSeconds:(c.timeInBedSeconds??0)+(i.timeInBedSeconds??0)||null,sleepScore:i.sleepScore??c.sleepScore,regularityScore:i.regularityScore??c.regularityScore,efficiency:i.efficiency??c.efficiency,recoveryState:i.recoveryState??c.recoveryState};continue}s.push(i)}return s}function cs(t){const a=[];if(typeof t.asleepSeconds=="number"&&t.asleepSeconds>0){const s=t.asleepSeconds/3600;a.push(`${s.toFixed(s>=1?1:2)}h asleep`)}else if(typeof t.timeInBedSeconds=="number"&&t.timeInBedSeconds>0){const s=t.timeInBedSeconds/3600;a.push(`${s.toFixed(s>=1?1:2)}h in bed`)}return typeof t.sleepScore=="number"&&a.push(`score ${t.sleepScore}`),typeof t.regularityScore=="number"&&a.push(`regularity ${t.regularityScore}`),t.recoveryState&&a.push(t.recoveryState),a.join(" · ")||"Sleep session"}function ms(t){const a=Math.max(60,Math.round((D(t.endedAt)-D(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:cs(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 Ut(t,a,s){if(s<=a)return null;const i=bt(a),c=bt(s),r=Math.max(60,Math.round((s-a)/1e3));return{...t,id:`${t.id}::virtual-${a}-${s}`,startedAt:i,endedAt:c,trueStartedAt:i,trueEndedAt:c,visibleStartedAt:i,visibleEndedAt:c,durationSeconds:r,cursor:`${c}::${t.id}::virtual`}}function xs(t,a){let s=[...t].sort(Qt);for(const i of os(a)){const c=D(i.startedAt),r=D(i.endedAt),h=ms(i),o=[];let m=!1;for(const p of s){const N=D(p.startedAt),b=D(p.endedAt);if(b<=c||N>=r){!m&&N>=r&&(o.push(h),m=!0),o.push(p);continue}if(N<c){const A=Ut(p,N,Math.min(b,c-gt));A&&o.push(A)}if(m||(o.push(h),m=!0),b>r){const A=Ut(p,Math.max(N,r+gt),b);A&&o.push(A)}}m||o.push(h),s=o.sort(Qt)}return s}const Wt=24,G=64,ft=360*60,ha=5,ht=1,hs=104,Gt=G*8;function ue(t){return t.trim().toLowerCase()}function ze(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 pe(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 ua(t){return new Intl.DateTimeFormat(void 0,{day:"2-digit",month:"2-digit",year:"2-digit"}).format(new Date(t))}function us(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",hour12:!1}).format(t)}function Ae(t){const a=new Date(t);if(Number.isNaN(a.getTime()))return"";const s=a.getFullYear(),i=String(a.getMonth()+1).padStart(2,"0"),c=String(a.getDate()).padStart(2,"0"),r=String(a.getHours()).padStart(2,"0"),h=String(a.getMinutes()).padStart(2,"0");return`${s}-${i}-${c}T${r}:${h}`}function at(t){if(!t.trim())return null;const a=new Date(t);return Number.isNaN(a.getTime())?null:a.toISOString()}function Te(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function W(t){return new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",hour12:!1}).format(new Date(t))}function Vt(t,a){return`${t.toFixed(3)}, ${a.toFixed(3)}`}function Je(t,a){return`${t.toFixed(6)}, ${a.toFixed(6)}`}function Yt(t){return`${Math.max(1,Math.round(t/60))} min`}function ps(t){if(t.length===0)return[];const a=Math.min(...t.map(o=>o.latitude)),s=Math.max(...t.map(o=>o.latitude)),i=Math.min(...t.map(o=>o.longitude)),c=Math.max(...t.map(o=>o.longitude)),r=Math.max(s-a,1e-4),h=Math.max(c-i,1e-4);return t.map((o,m)=>({...o,x:12+(o.longitude-i)/h*76,y:12+(1-(o.latitude-a)/r)*76,id:`${o.recordedAt??"point"}-${m}`}))}function vt(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 ye(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 et(t,a,s,i){const r=(s-t)*Math.PI/180,h=(i-a)*Math.PI/180,o=t*Math.PI/180,m=s*Math.PI/180,p=Math.sin(r/2)**2+Math.cos(o)*Math.cos(m)*Math.sin(h/2)**2;return 2*6371e3*Math.asin(Math.sqrt(p))}function gs(t){return ue([t.label,...t.aliases].join(" "))}function st(t){return t.kind==="trip"&&t.trip!==null}function le(t){return t.kind==="stay"&&t.stay!==null}function je(t,a,s){if(!t.trip)return{label:t.placeLabel??(a==="start"?"Known origin":"Known destination"),detail:W(a==="start"?t.startedAt:t.endedAt)};const i=a==="start"?t.trip.points[0]??null:t.trip.points[t.trip.points.length-1]??null,c=a==="start"?t.trip.startPlace:t.trip.endPlace,r=(s==null?void 0:s.includeCoordinates)??!0,h=s!=null&&s.useHistoryAnchorFallback&&a==="start"?"Beginning of history":null;return{label:(c==null?void 0:c.label)??h??(r&&i?Vt(i.latitude,i.longitude):a==="start"?"Unknown origin":"Unknown destination"),detail:r&&i&&!c?Vt(i.latitude,i.longitude):W(a==="start"?t.startedAt:t.endedAt)}}function bs(t){const a=t.trim().toLowerCase();return a==="travel"||a==="trip"||a==="move"}function fs(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 vs(t){const a=ye(t),s=t.title.trim().toLowerCase(),i=s.length===0||s==="stay"||s==="continued stay"||s==="repaired stay"||s==="manual stay";return a&&i?a:t.title.trim()||a||"Stay"}function me(t){if(kt(t))return"Sleep";if(t.kind==="missing")return fs(t);if(t.kind==="stay")return vs(t);if(t.kind==="trip"&&bs(t.title)){const a=je(t,"start").label,s=je(t,"end").label;return`${a} → ${s}`}return t.title}function Xt(t){return t==="left"?24:t==="right"?76:50}function ws(t,a,s){const i=Math.min(t,ft)/3600,c=s==="sleep overlay",r=c?112:a==="stay"?104:92,h=c?272:a==="stay"?288:232,o=r+i*30;return Math.max(r,Math.min(h,o))}function wt(t){var a;return{kind:t.kind,label:le(t)?t.stay.label||t.title:st(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:Ae(t.startedAt),endedAtInput:Ae(t.endedAt)}}function ut(t,a){const s=(a==null?void 0:a.startedAt)??new Date(Date.now()-36e5).toISOString(),i=(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t,label:t==="missing"?"User-defined missing data":t==="stay"?(a==null?void 0:a.placeLabel)||"Manual stay":"Manual move",placeLabel:(a==null?void 0:a.placeLabel)??"",tagsInput:t==="missing"?"user-defined, missing-data":t==="stay"?"user-defined, stay":"user-defined, move",startedAtInput:Ae(s),endedAtInput:Ae(i)}}function yt(t,a){var r,h;const s=t.tagsInput.split(",").map(o=>o.trim()).filter(Boolean),i=at(t.startedAtInput)??(a==null?void 0:a.startedAt)??new Date(Date.now()-3600*1e3).toISOString(),c=at(t.endedAtInput)??(a==null?void 0:a.endedAt)??new Date().toISOString();return{kind:t.kind,startedAt:i,endedAt:c,title:t.label.trim(),subtitle:t.kind==="missing"?"User-defined missing-data override.":"User-defined movement box.",placeLabel:t.placeLabel.trim()||null,tags:s,distanceMeters:t.kind==="trip"?Math.max(((r=a==null?void 0:a.trip)==null?void 0:r.distanceMeters)??150,150):null,averageSpeedMps:t.kind==="trip"?((h=a==null?void 0:a.trip)==null?void 0:h.averageSpeedMps)??null:null,metadata:{createdFrom:"movement-life-timeline"}}}function ys(t,a){var c,r;const s=t.kind==="stay"?((r=(c=t.stay)==null?void 0:c.label)==null?void 0:r.trim())??"":"";if(s)return s;const i=t.title.trim();return i&&i.toLowerCase()!=="stay"?i:a.trim()||"Stay"}function js(t,a){const s=wt(t),i=a.trim();return yt({...s,label:ys(t,i),placeLabel:i},t)}function pa(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function it(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Ns(t){var a,s,i;return ue([t.kind,me(t),t.subtitle,t.placeLabel??"",...t.tags,it(t.startedAt),it(t.endedAt),pa(t.startedAt),le(t)?((a=t.stay.place)==null?void 0:a.label)??t.stay.label:st(t)?[t.trip.label,t.trip.activityType,t.trip.travelMode,(s=t.trip.startPlace)==null?void 0:s.label,(i=t.trip.endPlace)==null?void 0:i.label].filter(Boolean).join(" "):t.kind==="trip"?[t.title,t.subtitle,t.placeLabel??""].filter(Boolean).join(" "):"missing data gap"].join(" "))}function Ss(t){const a=new Map;a.set("kind:stay",{id:"kind:stay",label:"Stay",description:"Stationary spans and place anchors."}),a.set("kind:trip",{id:"kind:trip",label:"Move",description:"Trips and movement connectors."});for(const s of["night","morning","afternoon","evening"])a.set(`time:${s}`,{id:`time:${s}`,label:s[0].toUpperCase()+s.slice(1),description:"Filter by the segment start time."});for(const s of t){for(const i of s.tags)a.set(`tag:${i}`,{id:`tag:${i}`,label:i,description:"Movement tag"});s.placeLabel&&a.set(`place:${s.placeLabel}`,{id:`place:${s.placeLabel}`,label:s.placeLabel,description:"Matched place"})}return[...a.values()].sort((s,i)=>s.label.localeCompare(i.label))}function Ms(t,a){return a.every(s=>s==="kind:stay"||s==="kind:trip"?t.kind===s.slice(5):s.startsWith("time:")?pa(t.startedAt)===s.slice(5):s.startsWith("tag:")?t.tags.includes(s.slice(4)):s.startsWith("place:")?(t.placeLabel??"")===s.slice(6):!0)}function Zt(t,a){return t&&{...t,pages:t.pages.map(s=>({...s,segments:s.segments.filter(i=>i.id!==a)}))}}function ks(t,a){const s=t+(Math.sin((t-.5)*Math.PI)+1)*.5-t,i=t-.5,r=.5+(i*(1-a*.64)+i*i*i*a*2.56);return Math.max(0,Math.min(1,r-(s-t)*a*.08))}function As(t){return t.getHours()===0?ua(t.toISOString()):us(t)}function Ts(t,a){const s=new Date(t.endedAt).getTime(),i=new Date(t.startedAt).getTime(),c=Math.max(1,s-i),r=Math.max(0,Math.min(1,(a-i)/c));if(t.durationSeconds<=ft)return r;const h=Math.max(0,1-Math.min(1,ft/Math.max(1,t.durationSeconds)));return ks(r,h)}function Cs(t,a,s){if(t.items.length===0)return null;const i=t.items[0];if(a<new Date(i.segment.startedAt).getTime())return t.historyHeaderHeight+t.leadHeight-(new Date(i.segment.startedAt).getTime()-a)/36e5*G;for(let h=0;h<t.items.length;h+=1){const o=t.items[h],m=new Date(o.segment.startedAt).getTime(),p=new Date(o.segment.endedAt).getTime();if(a>=m&&a<=p)return o.boxTop+Ts(o.segment,a)*o.displayHeight;const N=t.items[h+1]??null,b=N?new Date(N.segment.startedAt).getTime():s;if(a>p&&a<b)return o.boxBottom+(a-p)/36e5*G}const c=t.items[t.items.length-1],r=new Date(c.segment.endedAt).getTime();return a>=r?c.boxBottom+(a-r)/36e5*G:null}function Ps(t){const a=new Date(t);a.setMinutes(0,0,0);const s=a.getTime();return s<=t?s+36e5:s}function Ls(t,a){const s=[];if(t.items.length===0)return s;const i=t.items[0],c=new Date(i.segment.startedAt).getTime();for(let r=Ps(c-ha*36e5);r<=a;r+=36e5){const h=Cs(t,r,a);if(h===null)continue;const o=new Date(r);s.push({y:h,label:As(o),strong:o.getHours()===0})}return s}function Ds({segments:t,viewportHeight:a,nowMs:s=Date.now()}){var B;const i=t.length>0?hs:0,c=t.length>0?G*ha:0;let r=i+c,h=null;const o=t.map(w=>{const T=ws(w.durationSeconds,w.kind,w.syncSource),F=new Date(w.startedAt).getTime(),H=h===null?0:Math.max(0,(F-h)/36e5)*G;r+=H;const V=r,_=V+T;return r=_,h=new Date(w.endedAt).getTime(),{id:w.id,segment:w,gapBefore:H,displayHeight:T,boxTop:V,boxBottom:_}}),m=s+ht*36e5,p=(()=>{var F;const w=(F=t[t.length-1])==null?void 0:F.endedAt;if(!w)return G*ht;const T=new Date(w).getTime();return Math.max(G*ht,(m-T)/36e5*G)})(),N=(((B=o[o.length-1])==null?void 0:B.boxBottom)??i+c)+p,b=Math.max(N,a>0?a+260:960,i+c+p),A={historyHeaderHeight:i,leadHeight:c,items:o,markers:[],rangeEndMs:m,futureTailHeight:p+Math.max(0,b-N),totalHeight:b};return{...A,markers:Ls(A,m)}}function Is({layout:t,scrollTop:a,viewportHeight:s}){const i=G*6,c=Math.max(0,a-i),r=Math.min(t.totalHeight,a+Math.max(s,G*8)+i),h=t.markers.filter(o=>o.y>=c&&o.y<=r);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:"absolute inset-y-0 left-0 w-18 bg-[linear-gradient(90deg,rgba(7,12,22,0.96),rgba(7,12,22,0.42),transparent)]"}),h.map((o,m)=>e.jsxs("div",{className:"absolute inset-x-0",style:{top:`${o.y}px`},children:[e.jsx("div",{className:O("border-t",o.strong?"border-white/14":"border-white/7")}),e.jsx("div",{className:O("absolute left-3 top-0 -translate-y-1/2 font-label text-[9px] tracking-[0.24em]",o.strong?"text-white/38":"text-white/22"),children:o.label})]},`timeline-grid-${m}`))]})}function $s({fromSide:t,toSide:a,height:s,emphasized:i}){const c=Xt(t),r=Xt(a),h=`M ${c} 16 C ${c} ${Math.max(40,s*.26)}, ${r} ${Math.max(70,s*.72)}, ${r} ${s-18}`;return e.jsxs("svg",{viewBox:`0 0 100 ${s}`,className:"absolute inset-x-0 top-0 h-full w-full overflow-visible",preserveAspectRatio:"none",children:[e.jsx("path",{d:h,fill:"none",stroke:i?"rgba(241,246,255,0.18)":"rgba(241,246,255,0.11)",strokeWidth:i?"1.05":"0.85",strokeDasharray:i?"3 10":"2.5 12",strokeLinecap:"round"}),e.jsx("circle",{cx:c,cy:"16",r:"1.5",fill:"rgba(255,255,255,0.26)"}),e.jsx("circle",{cx:r,cy:s-18,r:"1.5",fill:"rgba(255,255,255,0.26)"})]})}function jt({position:t}){return e.jsx("div",{className:O("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:"h-6 w-[3px] rounded-full bg-[rgba(160,224,255,0.92)] shadow-[0_0_14px_rgba(126,229,255,0.36)]"})})}function Fs({segment:t}){const a=(t==null?void 0:t.kind)==="stay"?t.placeLabel||t.title||null:(t==null?void 0:t.kind)==="trip"?je(t,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}).label:null,s=a||"Beginning of time";return e.jsx("div",{className:"pointer-events-none flex justify-center px-6 py-4",children:e.jsxs("div",{className:"relative w-[min(18rem,calc(100vw-6rem))] overflow-hidden rounded-[26px] border border-[rgba(152,208,255,0.2)] bg-[linear-gradient(180deg,rgba(98,130,238,0.14),rgba(18,34,79,0.14))] shadow-[0_20px_48px_rgba(3,8,20,0.3)]",children:[e.jsx(jt,{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(u,{tone:"signal",className:"bg-white/10 text-white/78",children:"Start"}),e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-white/28",children:"Beginning of history"})]}),e.jsx("div",{className:"mt-5 font-display text-[1.25rem] tracking-[-0.05em] text-white",children:s}),e.jsx("div",{className:"mt-2 font-label text-[10px] uppercase tracking-[0.22em] text-white/30",children:a?"Oldest loaded known stay":"Earliest known anchor"})]})]})})}function Es(t,a,s){const i=a+Math.max(96,Math.min(s*.28,220)),c=t.items.find(r=>r.boxBottom>=i)??t.items[t.items.length-1]??null;return c?ua(c.segment.startedAt):null}function _s({open:t,anchor:a,items:s,onClose:i}){if(x.useEffect(()=>{if(!t)return;const m=N=>{N.key==="Escape"&&i()},p=()=>i();return window.addEventListener("keydown",m),window.addEventListener("pointerdown",p),()=>{window.removeEventListener("keydown",m),window.removeEventListener("pointerdown",p)}},[i,t]),!t||!a||typeof document>"u")return null;const c=Math.max(12,Math.min(a.top,window.innerHeight-360)),r=Math.max(220,window.innerHeight-c-96),h=Math.min(368,window.innerWidth-24),o=Math.max(12,Math.min(a.right,window.innerWidth-h-12));return Da.createPortal(e.jsx("div",{className:"fixed inset-0 z-[70] pointer-events-none",children:e.jsxs("div",{className:"pointer-events-auto fixed z-[71] overflow-y-auto overscroll-contain rounded-[28px] border border-white/10 bg-[linear-gradient(180deg,rgba(18,24,40,0.985),rgba(8,13,24,0.985))] p-2 shadow-[0_28px_90px_rgba(3,8,18,0.48)] backdrop-blur-xl",style:{top:`${c}px`,right:`${o}px`,width:`${h}px`,maxHeight:`${r}px`},onPointerDown:m=>m.stopPropagation(),children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.035] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.2em] text-white/40",children:"Movement actions"}),e.jsx("div",{className:"mt-1 text-sm text-white/70",children:"Add boxes, inspect raw data, and adjust timeline overlays."})]}),e.jsx("div",{className:"mt-2 grid gap-1",children:s.map(m=>{const p=m.icon;return e.jsxs("button",{type:"button",className:"flex w-full items-start gap-3 rounded-[20px] bg-white/[0.035] px-4 py-3 text-left text-white/76 transition hover:bg-white/[0.08] hover:text-white",onClick:()=>{m.onSelect(),i()},children:[e.jsx("span",{className:"rounded-[14px] bg-[var(--primary)]/12 p-2 text-[var(--primary)]",children:e.jsx(p,{className:"size-4"})}),e.jsxs("span",{className:"min-w-0",children:[e.jsx("span",{className:"block text-sm font-medium",children:m.label}),e.jsx("span",{className:"mt-1 block text-xs leading-5 text-white/48",children:m.description})]})]},m.id)})})]})}),document.body)}function zs({segment:t,onEdit:a,onOpenDetail:s,onDefinePlace:i,onClose:c}){var h;const r=kt(t);return e.jsxs(v,{className:"rounded-[28px] border border-white/10 bg-[linear-gradient(180deg,rgba(9,14,26,0.98),rgba(5,9,19,0.95))] p-5 shadow-[0_24px_74px_rgba(0,0,0,0.34)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:r?"Sleep overlay":t.kind==="stay"?"Stay detail":t.kind==="trip"?"Move detail":"Missing data"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:me(t)}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{className:r?"bg-cyan-400/14 text-cyan-100":t.sourceKind==="user_defined"?"bg-fuchsia-400/12 text-fuchsia-100":"bg-white/[0.06] text-white/70",children:r?"Virtual":t.sourceKind==="user_defined"?t.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),t.overrideCount>0?e.jsxs(u,{className:"bg-amber-400/10 text-amber-100",children:["Overrides ",t.overrideCount," automatic box",t.overrideCount===1?"":"es"]}):null]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{onClick:s,variant:"ghost",className:"rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/78 hover:bg-white/[0.08]",disabled:r,children:"Details"}),e.jsx(k,{onClick:a,variant:"ghost",className:"size-9 rounded-full border border-white/10 bg-white/[0.04] text-white/78 hover:bg-white/[0.08]","aria-label":"Edit movement segment",disabled:r||t.kind==="missing"||!t.editable,children:e.jsx(Mt,{className:"size-4"})}),c?e.jsx("button",{type:"button",onClick:c,className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close movement segment actions",children:e.jsx(Nt,{className:"size-4"})}):null,e.jsx(St,{className:"size-4 text-white/42"})]})]}),e.jsxs("div",{className:"mt-4 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-white/82",children:pe(t.startedAt)})]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-white/82",children:pe(t.endedAt)})]})]}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:ze(t.durationSeconds)}),st(t)?e.jsxs(e.Fragment,{children:[e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:Te(t.trip.distanceMeters)}),t.trip.stops.length>0?e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:[t.trip.stops.length," stop",t.trip.stops.length===1?"":"s"]}):null]}):null,r?e.jsx(u,{className:"bg-cyan-400/12 text-cyan-50",children:t.subtitle}):ye(t)?e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:ye(t)}):null]}),le(t)&&!r?e.jsxs("div",{className:"mt-4 rounded-[18px] border border-sky-300/14 bg-sky-300/8 p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-sky-100/66",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-sky-50/86",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(k,{onClick:i,variant:"ghost",className:"rounded-full border border-sky-300/24 bg-sky-300/12 px-4 text-sky-50 hover:bg-sky-300/18",children:"Label location"})})]}):null,e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Timeline summary"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/76",children:t.kind==="stay"?r?`Sleep overlay from ${W(t.startedAt)} to ${W(t.endedAt)}. Underlying movement boxes are sliced virtually while this overlay is visible.`:`Stay block from ${W(t.startedAt)} to ${W(t.endedAt)}.`:t.kind==="trip"?`Connector from ${je(t,"start").label} to ${je(t,"end").label}.`:`No reliable movement signal reached Forge from ${W(t.startedAt)} to ${W(t.endedAt)}.`})]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-white/[0.03] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Projection model"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/76",children:r?"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(u,{className:"bg-white/[0.08] text-white/74",children:["Raw stays ",t.rawStayIds.length]}),e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:["Raw trips ",t.rawTripIds.length]}),e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:["Raw points ",t.rawPointCount]}),t.hasLegacyCorrections?e.jsx(u,{className:"bg-amber-400/10 text-amber-100",children:"Legacy corrections present"}):null]})]})]}),e.jsx("div",{className:"mt-5 flex flex-wrap items-center gap-2 text-sm text-white/56",children:r?e.jsxs(e.Fragment,{children:[e.jsx(aa,{className:"size-4 text-cyan-300"}),"Sleep overlay"]}):le(t)?e.jsxs(e.Fragment,{children:[e.jsx(ia,{className:"size-4 text-[var(--primary)]"}),((h=t.stay.place)==null?void 0:h.label)??"No canonical place linked yet"]}):st(t)?e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"size-4 text-[var(--primary)]"}),t.trip.activityType||t.trip.travelMode]}):t.kind==="trip"?e.jsxs(e.Fragment,{children:[e.jsx(tt,{className:"size-4 text-[var(--primary)]"}),"Repaired movement connector"]}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{className:"size-4 text-white/56"}),"Missing intervals are synthesized from long signal gaps instead of inventing fake travel."]})})]})}function Jt({title:t,points:a,averagePoint:s}){const i=ps(s?[...a,s]:a),c=s?i.length-1:i.length,r=i.slice(0,c),h=s?i[i.length-1]??null:null,o=r.map((m,p)=>`${p===0?"M":"L"} ${m.x} ${m.y}`).join(" ");return e.jsxs(v,{className:"rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,13,25,0.95),rgba(10,17,30,0.88))] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:t}),e.jsx("div",{className:"mt-2 text-sm text-white/62",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-white/8 bg-[rgba(255,255,255,0.03)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"rgba(255,255,255,0.02)"}),r.length>1?e.jsx("path",{d:o,fill:"none",stroke:"rgba(92,225,230,0.95)",strokeWidth:"1.6"}):null,r.map((m,p)=>e.jsx("circle",{cx:m.x,cy:m.y,r:p===0||p===r.length-1?2.2:1.4,fill:p===0||p===r.length-1?"#ffffff":"rgba(92,225,230,0.9)"},m.id)),h?e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:h.x,cy:h.y,r:3,fill:"rgba(255,208,88,0.95)"}),e.jsx("circle",{cx:h.x,cy:h.y,r:6,fill:"none",stroke:"rgba(255,208,88,0.48)",strokeWidth:"1",strokeDasharray:"2 2"})]}):null]})})]})}function Rs({open:t,onOpenChange:a,segment:s,detail:i,loading:c,onEdit:r,onDefinePlace:h}){var N;const o=(i==null?void 0:i.segment)??s,m=(i==null?void 0:i.stayDetail)??null,p=(i==null?void 0:i.tripDetail)??null;return e.jsx(Re,{open:t,onOpenChange:a,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[6vh] z-50 max-h-[88vh] w-[min(60rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:o?`${me(o)} details`:"Movement details"}),e.jsx(qe,{className:"mt-2 text-sm leading-6 text-white/62",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:[o?e.jsxs(k,{onClick:r,variant:"ghost",className:"rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/78 hover:bg-white/[0.08]",disabled:!o.editable||o.kind==="missing",children:[e.jsx(Mt,{className:"size-4"}),"Edit"]}):null,e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white",children:e.jsx(St,{className:"size-4 rotate-45"})})})]})]}),c?e.jsx("div",{className:"mt-6 rounded-[22px] border border-white/8 bg-white/[0.03] p-5 text-sm text-white/62",children:"Loading the canonical box detail and raw movement evidence…"}):o?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.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Started"}),e.jsx("div",{className:"mt-2 text-sm text-white",children:pe(o.startedAt)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Ended"}),e.jsx("div",{className:"mt-2 text-sm text-white",children:pe(o.endedAt)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Duration"}),e.jsx("div",{className:"mt-2 text-sm text-white",children:ze(o.durationSeconds)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Raw coverage"}),e.jsxs("div",{className:"mt-2 text-sm text-white",children:[o.rawStayIds.length," stays · ",o.rawTripIds.length," trips · ",o.rawPointCount," points"]})]})]}),m?e.jsxs(e.Fragment,{children:[e.jsxs(v,{className:"rounded-[22px] border border-sky-300/14 bg-sky-300/8 p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-sky-100/66",children:"Location label"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-sky-50/86",children:m.canonicalPlace?`This stay is linked to ${m.canonicalPlace.label}. Search a different saved place or relabel it from the stay center.`:"This stay has no saved place yet. Search known locations first, or create a new place directly from the stay center."}),e.jsx("div",{className:"mt-3",children:e.jsx(k,{onClick:h,variant:"ghost",className:"rounded-full border border-sky-300/24 bg-sky-300/12 px-4 text-sky-50 hover:bg-sky-300/18",children:"Label location"})})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(Jt,{title:"Stay positions",points:m.positions,averagePoint:m.averagePosition}),e.jsxs(v,{className:"rounded-[28px] border border-white/10 bg-white/[0.03] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Stay metrics"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"text-sm text-white/78",children:["Canonical place: ",((N=m.canonicalPlace)==null?void 0:N.label)??"Not linked yet"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Average position: ",m.averagePosition?Je(m.averagePosition.latitude,m.averagePosition.longitude):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Radius: ",m.radiusMeters!=null?Te(m.radiusMeters):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Samples: ",m.sampleCount]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-black/10 p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Exact positions"}),e.jsx("div",{className:"mt-3 grid gap-2",children:m.positions.map((b,A)=>e.jsxs("div",{className:"text-sm text-white/74",children:[b.label??`Position ${A+1}`,": ",Je(b.latitude,b.longitude)]},`${b.recordedAt??"stay"}-${A}`))})]})]})]})]})]}):null,p?e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.05fr)_minmax(0,0.95fr)]",children:[e.jsx(Jt,{title:"Travel map",points:p.positions}),e.jsxs(v,{className:"rounded-[28px] border border-white/10 bg-white/[0.03] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Trip metrics"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"text-sm text-white/78",children:["Start position: ",p.startPosition?Je(p.startPosition.latitude,p.startPosition.longitude):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["End position: ",p.endPosition?Je(p.endPosition.latitude,p.endPosition.longitude):"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Distance: ",Te(p.totalDistanceMeters)]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Moving time: ",Yt(p.movingSeconds)]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Idle time: ",Yt(p.idleSeconds)]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Average speed: ",p.averageSpeedMps!=null?`${p.averageSpeedMps.toFixed(2)} m/s`:"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Max speed: ",p.maxSpeedMps!=null?`${p.maxSpeedMps.toFixed(2)} m/s`:"Unavailable"]}),e.jsxs("div",{className:"text-sm text-white/78",children:["Stops: ",p.stopCount]})]})]})]}):null]}):null]})]})})}function Os({open:t,segment:a,onOpenChange:s,onEdit:i,onOpenDetail:c,onDefinePlace:r}){return e.jsx(Re,{open:t,onOpenChange:s,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{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(Be,{className:"sr-only",children:a?`${me(a)} actions`:"Movement actions"}),e.jsx(qe,{className:"sr-only",children:"Inspect, edit, or label the selected movement box."}),a?e.jsx(zs,{segment:a,onEdit:i,onOpenDetail:c,onDefinePlace:r,onClose:()=>s(!1)}):null]})]})})}function Hs({open:t,onOpenChange:a,segment:s,places:i,loading:c,onSelectPlace:r,onCreatePlace:h}){const o=s?vt(s):null,[m,p]=x.useState("");x.useEffect(()=>{if(!t){p("");return}p(ye(s)??"")},[t,s]);const N=x.useMemo(()=>{if(!o)return[];const w=ue(m);return[...i].filter(T=>w.length===0?!0:gs(T).includes(w)).sort((T,F)=>{const H=ue(T.label),V=ue(F.label),_=w.length>0&&H.startsWith(w),Y=w.length>0&&V.startsWith(w);if(_!==Y)return _?-1:1;const Q=et(o.latitude,o.longitude,T.latitude,T.longitude),X=et(o.latitude,o.longitude,F.latitude,F.longitude);return Math.abs(Q-X)>1?Q-X:T.label.localeCompare(F.label)}).slice(0,6)},[i,m,o]),b=ue(m),A=N.some(w=>ue(w.label)===b),B=ye(s);return e.jsx(Re,{open:t,onOpenChange:a,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[8vh] z-50 max-h-[84vh] w-[min(38rem,calc(100vw-1.25rem))] -translate-x-1/2 overflow-y-auto rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:"Label stay location"}),e.jsx(qe,{className:"mt-2 text-sm leading-6 text-white/62",children:"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."})]}),e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/64 transition hover:bg-white/[0.08] hover:text-white","aria-label":"Close location label dialog",children:e.jsx(Nt,{className:"size-4"})})})]}),o?e.jsxs("div",{className:"mt-5 rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(u,{tone:"signal",children:"Stay center"}),B?e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:B}):null]}),e.jsxs("div",{className:"mt-3 grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-black/10 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Latitude"}),e.jsx("div",{className:"mt-1 text-sm text-white/82",children:o.latitude.toFixed(6)})]}),e.jsxs("div",{className:"rounded-[18px] border border-white/8 bg-black/10 px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/34",children:"Longitude"}),e.jsx("div",{className:"mt-1 text-sm text-white/82",children:o.longitude.toFixed(6)})]})]})]}):e.jsx("div",{className:"mt-5 rounded-[22px] border border-amber-300/14 bg-amber-300/8 p-4 text-sm text-amber-50/86",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(P,{value:m,onChange:w=>p(w.target.value),placeholder:"Type a location name or create a new one"}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Known places"}),c?e.jsx("div",{className:"mt-3 text-sm text-white/58",children:"Loading saved places…"}):N.length>0?e.jsx("div",{className:"mt-3 grid gap-2",children:N.map(w=>{const T=o==null?null:et(o.latitude,o.longitude,w.latitude,w.longitude);return e.jsxs("button",{type:"button",onClick:()=>void r(w).then(F=>{F&&a(!1)}),className:"rounded-[18px] border border-white/8 bg-black/10 px-4 py-3 text-left transition hover:border-[var(--primary)]/40 hover:bg-white/[0.05]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm text-white",children:w.label}),T!=null?e.jsxs(u,{className:"bg-white/[0.08] text-white/70",children:[Te(T)," away"]}):null]}),w.aliases.length>0||w.categoryTags.length>0?e.jsx("div",{className:"mt-1 text-xs text-white/52",children:[...w.aliases,...w.categoryTags].join(" · ")}):null]},w.id)})}):e.jsx("div",{className:"mt-3 text-sm text-white/58",children:"No saved place matches this stay yet."})]})]}),e.jsxs("div",{className:"mt-5 flex flex-wrap justify-end gap-2",children:[e.jsx(k,{variant:"ghost",onClick:()=>a(!1),className:"border border-white/10 bg-white/[0.04]",children:"Cancel"}),e.jsx(k,{onClick:()=>{!s||!o||h(s,A?"":m.trim())},disabled:!s||!o,children:b.length>0&&!A?`Create "${m.trim()}"`:"Create new location"})]})]})]})})}function Ks({open:t,segment:a,draft:s,creating:i,saving:c,preflight:r,preflightLoading:h,onDraftChange:o,onFitMissing:m,onSave:p,onOpenChange:N}){return e.jsx(Re,{open:t,onOpenChange:N,children:e.jsxs(Oe,{children:[e.jsx(He,{className:"fixed inset-0 z-50 bg-[rgba(3,7,18,0.74)] backdrop-blur-sm"}),e.jsxs(Ke,{className:"fixed left-1/2 top-[8vh] z-50 w-[min(34rem,calc(100vw-1.25rem))] -translate-x-1/2 rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,14,28,0.98),rgba(10,16,30,0.95))] p-5 shadow-[0_32px_90px_rgba(0,0,0,0.45)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx(Be,{className:"font-display text-[1.3rem] tracking-[-0.05em] text-white",children:i?"Create movement box":"Edit movement box"}),e.jsx(qe,{className:"mt-2 text-sm leading-6 text-white/62",children:s?i?"Create a canonical user-defined stay, move, or missing-data box without mutating raw phone measurements.":`Adjust this user-defined ${s.kind} box. Automatic boxes stay immutable and can only be invalidated.`:"No segment selected."})]}),e.jsx(_e,{asChild:!0,children:e.jsx("button",{type:"button",className:"rounded-full border border-white/10 bg-white/[0.04] p-2 text-white/72 transition hover:bg-white/[0.08]",children:e.jsx(St,{className:"size-4 rotate-45"})})})]}),s?e.jsxs("div",{className:"mt-5 grid gap-4",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Kind",e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["stay","Stay"],["trip","Move"],["missing","Missing"]].map(([b,A])=>e.jsx(k,{type:"button",variant:"ghost",className:O("border border-white/10 bg-white/[0.04] text-white hover:bg-white/[0.08]",s.kind===b?"ring-1 ring-[rgba(126,229,255,0.42)]":""),onClick:()=>o({...s,kind:b}),children:A},b))})]}),e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Label",e.jsx(P,{value:s.label,onChange:b=>o({...s,label:b.target.value})})]}),s.kind!=="trip"?e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Place",e.jsx(P,{value:s.placeLabel,onChange:b=>o({...s,placeLabel:b.target.value}),placeholder:"Home, Office, Riverside path..."})]}):null,e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Tags",e.jsx(P,{value:s.tagsInput,onChange:b=>o({...s,tagsInput:b.target.value}),placeholder:"movement, social, errand"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Started",e.jsx(P,{type:"datetime-local",value:s.startedAtInput,onChange:b=>o({...s,startedAtInput:b.target.value})})]}),e.jsxs("label",{className:"grid gap-2 text-sm text-white/78",children:["Ended",e.jsx(P,{type:"datetime-local",value:s.endedAtInput,onChange:b=>o({...s,endedAtInput:b.target.value})})]})]}),e.jsxs(v,{className:"grid gap-3 border-white/10 bg-white/[0.03] p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm font-medium text-white",children:"Overlap guidance"}),e.jsx(k,{type:"button",variant:"ghost",className:"border border-white/10 bg-white/[0.04] text-white hover:bg-white/[0.08]",onClick:m,disabled:!(r!=null&&r.nearestMissingStartedAt)||!(r!=null&&r.nearestMissingEndedAt),children:"Fit Missing Time"})]}),e.jsx("div",{className:"text-sm leading-6 text-white/62",children:h?"Checking visible overlaps and missing windows…":r!=null&&r.overlapsAnything?`This box overlaps ${r.affectedAutomaticBoxIds.length} automatic and ${r.affectedUserBoxIds.length} manual boxes. Saving will fully override ${r.fullyOverriddenUserBoxIds.length} manual boxes and trim ${r.trimmedUserBoxIds.length}.`:"No overlap in the currently visible timeline window."}),e.jsxs("div",{className:"grid gap-1 text-xs text-white/50",children:[e.jsxs("div",{children:["Visible range:"," ",r!=null&&r.visibleRangeStart&&(r!=null&&r.visibleRangeEnd)?`${pe(r.visibleRangeStart)} -> ${pe(r.visibleRangeEnd)}`:"Unavailable"]}),e.jsxs("div",{children:["Suggested missing slot:"," ",r!=null&&r.nearestMissingStartedAt&&(r!=null&&r.nearestMissingEndedAt)?`${pe(r.nearestMissingStartedAt)} -> ${pe(r.nearestMissingEndedAt)}`:"No missing interval in view"]})]})]})]}):null,e.jsxs("div",{className:"mt-6 flex items-center justify-end gap-3",children:[e.jsx(_e,{asChild:!0,children:e.jsx(k,{type:"button",variant:"ghost",className:"border border-white/10 bg-white/[0.04] text-white hover:bg-white/[0.08]",children:"Cancel"})}),e.jsxs(k,{onClick:p,disabled:!s||c,children:[e.jsx(Ia,{className:"size-4"}),c?"Saving…":i?"Create box":"Save changes"]})]})]})]})})}function ea({side:t,vertical:a,emphasized:s=!1}){return e.jsx("div",{className:O("absolute z-10 h-7 w-8 rounded-[12px] border bg-[linear-gradient(180deg,rgba(10,16,28,0.94),rgba(7,12,24,0.88))] shadow-[0_12px_30px_rgba(0,0,0,0.22)] backdrop-blur-sm",s?"border-[rgba(152,208,255,0.34)]":"border-white/10",t==="left"?"left-[8%]":t==="right"?"right-[8%]":"left-1/2 -translate-x-1/2",a==="top"?"top-0":"bottom-0")})}function Bs({layout:t,selected:a,onToggle:s}){var m,p,N,b;const{segment:i}=t,c=kt(i),r=t.displayHeight,h=i.kind==="stay"?c?"bg-[linear-gradient(180deg,rgba(39,127,173,0.28),rgba(16,51,79,0.22))] border-[rgba(138,227,255,0.28)]":"bg-[linear-gradient(180deg,rgba(98,130,238,0.22),rgba(18,34,79,0.22))] border-[rgba(152,208,255,0.24)]":"",o=i.kind==="trip"?{start:je(i,"start",{includeCoordinates:!1,useHistoryAnchorFallback:!0}),end:je(i,"end",{includeCoordinates:!1})}:null;return e.jsxs("div",{className:O("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:`${r}px`},children:[e.jsx("div",{className:"absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-[linear-gradient(180deg,rgba(255,255,255,0.02),rgba(255,255,255,0.08),rgba(255,255,255,0.02))]"}),e.jsx("div",{className:"relative h-full",children:i.kind==="trip"?e.jsxs(qt.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:240,damping:30},className:"absolute inset-x-0 top-0 h-full z-10",children:[o&&a?e.jsxs(e.Fragment,{children:[e.jsx(ea,{side:"center",vertical:"top",emphasized:!0}),e.jsx(ea,{side:"center",vertical:"bottom",emphasized:!0})]}):null,e.jsx($s,{fromSide:"center",toSide:"center",height:r,emphasized:a}),e.jsxs("button",{type:"button",onClick:s,className:O("group absolute top-1/2 max-w-[min(8rem,calc(100vw-8rem))] -translate-y-1/2 rounded-[16px] border border-white/8 bg-[linear-gradient(180deg,rgba(9,14,24,0.58),rgba(8,12,22,0.42))] px-2.5 py-2 text-left shadow-[0_12px_24px_rgba(0,0,0,0.14)] backdrop-blur-sm transition hover:border-white/14 sm:max-w-[9rem] sm:px-3","left-1/2 -translate-x-1/2",a?"ring-1 ring-[rgba(126,229,255,0.38)]":""),children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"font-label text-[10px] uppercase tracking-[0.18em] text-white/34",children:"Move"}),e.jsx("div",{className:"text-[11px] tracking-[0.18em] text-white/44",children:ze(i.durationSeconds)})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap gap-2",children:[e.jsx(u,{className:"bg-white/[0.08] text-white/74",children:Te(((m=i.trip)==null?void 0:m.distanceMeters)??0)}),(((p=i.trip)==null?void 0:p.stops.length)??0)>0?e.jsxs(u,{className:"bg-white/[0.08] text-white/74",children:[(N=i.trip)==null?void 0:N.stops.length," stop",((b=i.trip)==null?void 0:b.stops.length)===1?"":"s"]}):null]}),e.jsxs("div",{className:"mt-2 font-label text-[9px] uppercase tracking-[0.22em] text-white/28",children:[W(i.startedAt)," → ",W(i.endedAt)]})]})]}):e.jsx(qt.div,{layout:!0,animate:{x:0},transition:{type:"spring",stiffness:260,damping:28},className:"absolute top-0 left-1/2 z-10 w-[min(18.5rem,calc(100vw-3.25rem))] -translate-x-1/2 sm:w-[min(21rem,calc(100vw-5rem))]",children:e.jsxs("button",{type:"button",onClick:s,className:O("group relative w-full overflow-hidden rounded-[24px] border text-left shadow-[0_20px_52px_rgba(3,8,20,0.36)] transition sm:rounded-[30px]",h,a?"ring-1 ring-[rgba(126,229,255,0.42)]":"hover:border-white/22"),style:{minHeight:`${r}px`},children:[e.jsx(jt,{position:"top"}),e.jsx(jt,{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(u,{tone:"signal",className:"bg-white/10 text-white/82",children:c?"Sleep":"Stay"}),e.jsx("div",{className:"text-[11px] tracking-[0.16em] text-white/46 sm:text-xs sm:tracking-[0.18em]",children:ze(i.durationSeconds)})]}),e.jsxs("div",{className:"mt-3 min-w-0 sm:mt-5",children:[e.jsx("div",{className:"truncate font-display text-[1rem] tracking-[-0.03em] text-white sm:text-[1.12rem]",children:me(i)}),i.kind==="stay"&&ye(i)&&!c?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(u,{className:"max-w-full truncate bg-white/[0.08] text-white/76",children:ye(i)})}):c?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2 sm:mt-3",children:e.jsx(u,{className:"max-w-full truncate bg-cyan-400/12 text-cyan-50",children:i.subtitle})}):null]}),e.jsx("div",{className:"mt-auto pt-4 sm:pt-8",children:e.jsxs("div",{className:"font-label text-[9px] uppercase tracking-[0.2em] text-white/34 sm:text-[10px] sm:tracking-[0.22em]",children:[W(i.startedAt)," → ",W(i.endedAt)]})})]})]})})})]})}function qs({userIds:t=[]}){var Et,_t,zt;const a=ra(),s=x.useRef(null),i=x.useRef(null),c=x.useRef(null),r=x.useRef(!1),h=x.useRef(!1),o=x.useRef(null),[m,p]=x.useState(null),[N,b]=x.useState(!1),[A,B]=x.useState(!1),[w,T]=x.useState(null),[F,H]=x.useState({}),[V,_]=x.useState(null),[Y,Q]=x.useState(null),[X,Z]=x.useState(null),[Qe,Ce]=x.useState(null),[Pe,Le]=x.useState(!1),[Ue,Ne]=x.useState(!1),[nt,Se]=x.useState(null),[lt,De]=x.useState(null),[ae,q]=x.useState(!1),[se,ie]=x.useState(!1),[K,xe]=x.useState(!1),[y,We]=x.useState(""),[ge,Ge]=x.useState([]),[he,Ve]=x.useState(0),[z,Ie]=x.useState(0),Me=()=>{const l=s.current;l&&(Ve(l.scrollTop),Ie(l.clientHeight))},C=Rt({queryKey:["forge-movement-life-timeline",...t],initialPageParam:null,queryFn:({pageParam:l})=>Kt({before:l??void 0,limit:Wt,userIds:t}).then(d=>d.movement),getNextPageParam:l=>l.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),j=Rt({queryKey:["forge-movement-life-timeline-data",...t],initialPageParam:null,queryFn:({pageParam:l})=>Kt({before:l??void 0,includeInvalid:!0,limit:Wt,userIds:t}).then(d=>d.movement),getNextPageParam:l=>l.nextCursor??void 0,retry:!1,refetchOnWindowFocus:!1}),be=x.useMemo(()=>{var l;return((l=C.data)==null?void 0:l.pages.flatMap(d=>d.segments))??[]},[C.data]),de=x.useMemo(()=>{var l;return((l=j.data)==null?void 0:l.pages.flatMap(d=>d.segments))??[]},[j.data]),oe=x.useMemo(()=>{var l;return((l=C.data)==null?void 0:l.pages.reduce((d,g)=>Math.max(d,g.invalidSegmentCount??0),0))??0},[C.data]),S=x.useMemo(()=>[...be].reverse(),[be]),J=x.useMemo(()=>[...de].reverse(),[de]),$e=x.useMemo(()=>{var d;const l=new Map;for(const g of((d=C.data)==null?void 0:d.pages)??[])for(const E of g.sleepOverlays??[])l.set(E.id,E);return[...l.values()].sort((g,E)=>new Date(g.startedAt).getTime()-new Date(E.startedAt).getTime())},[C.data]),fe=x.useMemo(()=>xs(S,$e),[S,$e]),M=x.useMemo(()=>K?fe:S,[S,fe,K]),Fe=x.useMemo(()=>fe.filter(l=>l.syncSource==="sleep overlay"),[fe]),re=((Et=Fe.at(-1))==null?void 0:Et.id)??null,n=x.useMemo(()=>M.find(l=>l.id===X)??null,[X,M]),f=x.useMemo(()=>M.find(l=>l.id===m)??null,[M,m]),ee=te({queryKey:["forge-movement-box-detail",(n==null?void 0:n.boxId)??null,...t],queryFn:async()=>n!=null&&n.boxId?(await za(n.boxId,t)).movement:null,enabled:!!(n!=null&&n.boxId)}),U=x.useMemo(()=>S.find(l=>l.id===Qe)??null,[Qe,S]),ne=te({queryKey:["forge-movement-places",...t],queryFn:async()=>(await ca(t)).places,retry:!1,refetchOnWindowFocus:!1}),I=x.useMemo(()=>Ds({segments:M,viewportHeight:z}),[M,z]),dt=x.useMemo(()=>new Map(I.items.map(l=>[l.segment.id,l])),[I.items]),ba=x.useMemo(()=>{const l=Math.max(0,he-Gt),d=he+Math.max(z,G*8)+Gt;return I.items.filter(g=>g.segment.id===m?!0:g.boxBottom>=l&&g.boxTop<=d)},[he,m,I.items,z]),Tt=x.useMemo(()=>Es(I,he,z),[he,I,z]),fa=()=>{var d;const l=(d=c.current)==null?void 0:d.getBoundingClientRect();if(!l){B(g=>!g);return}T({top:l.bottom+10,right:Math.max(12,window.innerWidth-l.right)}),B(g=>!g)},va=x.useMemo(()=>[{id:"add-box",label:"Add box",description:"Create a user-defined stay, move, or missing-data interval.",icon:Ca,onSelect:()=>Q(ut("stay",S.at(-1)??null))},{id:"sleep",label:K?"Hide sleep":"Show sleep",description:"Toggle sleep overlays without rewriting the movement boxes.",icon:aa,onSelect:()=>xe(l=>{const d=!l;return d&&re&&(p(re),b(!0)),d})},{id:"view-data",label:"View data",description:"Open the canonical loaded records and raw-data filters.",icon:pt,onSelect:()=>q(!0)}],[re,S,K]),Ct=(l,d="smooth")=>{const g=s.current,E=dt.get(l);if(!g||!E)return;const Ee=Math.max(0,E.boxTop-g.clientHeight/2+E.displayHeight/2);if(typeof g.scrollTo=="function"){g.scrollTo({top:Ee,behavior:d});return}g.scrollTop=Ee};x.useEffect(()=>{ae&&(!j.hasNextPage||j.isFetchingNextPage||j.fetchNextPage())},[ae,j.fetchNextPage,j.hasNextPage,j.isFetchingNextPage]),x.useEffect(()=>{const l=M.at(-1);!h.current&&l&&(h.current=!0,p(l.id))},[M]),x.useEffect(()=>{if(!r.current&&M.length>0){r.current=!0,requestAnimationFrame(()=>{var d;const l=(d=M[M.length-1])==null?void 0:d.id;l&&Ct(l,"auto"),requestAnimationFrame(()=>{Me()})});return}if(o.current&&M.length>o.current.count&&s.current){const l=o.current;o.current=null,requestAnimationFrame(()=>{const d=s.current;if(!d)return;const g=I.totalHeight-l.size;d.scrollTop+=g,Me()})}},[M.length,I.totalHeight,dt]),x.useEffect(()=>{if(!s.current)return;const d=()=>{Me()};return d(),window.addEventListener("resize",d),()=>window.removeEventListener("resize",d)},[]),x.useEffect(()=>{if(!m)return;const l=S.find(d=>d.id===m);l&&H(d=>d[m]?d:{...d,[m]:wt(l)})},[S,m]),x.useEffect(()=>{var l;m&&(M.some(d=>d.id===m)||(p(((l=M.at(-1))==null?void 0:l.id)??null),b(!1)))},[M,m]),x.useEffect(()=>{if(!K||!re)return;const l=M.findIndex(d=>d.id===re);l<0||(p(re),requestAnimationFrame(()=>{var g;const d=(g=M[l])==null?void 0:g.id;d&&Ct(d)}))},[M,re,K,dt]);const ot=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"]})])},Pt=ke({mutationFn:async l=>{const{segment:d,draft:g,creating:E}=l,Ee=yt(g,d);if(E){await Ot(Ee,t);return}if(!d)throw new Error("No movement box selected.");if(d.sourceKind!=="user_defined")throw new Error("Automatic movement boxes are immutable. Invalidate them into missing data or create a user-defined override instead.");await Ht(d.boxId,{...Ee,metadata:{updatedFrom:"movement-life-timeline"}},t)},onSuccess:ot}),wa=async(l,d)=>{if(l.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");const g=js(l,d.label);if(l.sourceKind==="user_defined"){await Ht(l.boxId,{...g,metadata:{updatedFrom:"movement-life-timeline-place-label"}},t);return}await Ot({...g,metadata:{createdFrom:"movement-life-timeline-place-label"}},t)},Lt=async(l,d)=>{if(l.rawStayIds.length===0)throw new Error("This stay has no raw stay ids to relabel.");await Promise.all(l.rawStayIds.map(g=>_a(g,{placeExternalUid:d.externalUid,placeLabel:d.label})))},ya=(l,d)=>{const g=vt(l);if(!g)return!0;const E=et(g.latitude,g.longitude,d.latitude,d.longitude);return E<=100||typeof window>"u"||typeof window.confirm!="function"?!0:window.confirm(`"${d.label}" is ${Te(E)} away from this stay's recorded center. Link it anyway?`)},ja=ke({mutationFn:async l=>{const{segment:d,...g}=l,E=await na(g,t);return d&&le(d)&&await Lt(d,E.place),E},onSuccess:ot}),Na=ke({mutationFn:async l=>{const{segment:d,place:g}=l;if(!ya(d,g))return{assigned:!1};if(le(d))return await Lt(d,g),{assigned:!0};if(d.kind!=="stay")throw new Error("Only stays can be linked to a saved place.");return await wa(d,g),{assigned:!0}},onSuccess:async l=>{l.assigned&&await ot()}}),ct=ke({mutationFn:async l=>{if(l.sourceKind==="user_defined"){await Fa(l.boxId,t);return}await Ea(l.boxId,{title:"User invalidated automatic movement",subtitle:`Overrides ${me(l)} with missing data.`},t)},onSuccess:async(l,d)=>{p(g=>g===d.id?null:g),b(!1),_(g=>g===d.id?null:g),a.setQueryData(["forge-movement-life-timeline",...t],g=>Zt(g,d.id)),a.setQueryData(["forge-movement-life-timeline-data",...t],g=>Zt(g,d.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"]})])}}),Sa=x.useMemo(()=>Ss(J),[J]),ve=x.useMemo(()=>{const l=ue(y);return[...J].sort((d,g)=>new Date(g.endedAt).getTime()-new Date(d.endedAt).getTime()).filter(d=>(l.length===0||Ns(d).includes(l))&&Ms(d,ge))},[J,y,ge]),Dt=x.useMemo(()=>J.length===0?"No movement records loaded yet.":ve.length===J.length&&y.trim().length===0&&ge.length===0?`${J.length} loaded movement records visible`:`${ve.length} of ${J.length} loaded records visible`,[J.length,ve.length,y,ge.length]),mt=sa({count:ve.length,getScrollElement:()=>i.current,estimateSize:()=>136,overscan:8}),L=V?S.find(l=>l.id===V)??null:null,Ma=L?F[L.id]??wt(L):null,Ye=Y!==null,$=Y??Ma,It=((_t=S[0])==null?void 0:_t.startedAt)??null,$t=((zt=S[S.length-1])==null?void 0:zt.endedAt)??null,xt=te({queryKey:["forge-movement-user-box-preflight",(L==null?void 0:L.boxId)??"create",($==null?void 0:$.kind)??null,($==null?void 0:$.startedAtInput)??null,($==null?void 0:$.endedAtInput)??null,It,$t,...t],enabled:$!==null&&at($.startedAtInput)!==null&&at($.endedAtInput)!==null,queryFn:async()=>{if(!$)return null;const l=yt($,L);return(await Ra({...l,excludeBoxId:(L==null?void 0:L.sourceKind)==="user_defined"?L.boxId:null,rangeStart:It,rangeEnd:$t},t)).preflight}}),Ft=l=>{le(l)&&(Ce(l.id),Le(!0))},ka=(l,d)=>{const g=vt(l);g&&(Le(!1),Ce(l.id),Se({...g,label:d.trim()||g.label}),De(l.id),Ne(!0))},Aa=()=>{const l=s.current;l&&(Ve(l.scrollTop),Ie(l.clientHeight),!(!C.hasNextPage||C.isFetchingNextPage)&&l.scrollTop<=960&&(o.current={count:M.length,size:I.totalHeight},C.fetchNextPage()))};if(C.isPending)return e.jsx(la,{eyebrow:"Movement",title:"Loading life timeline",description:"Reconstructing the longer road of stays, moves, and places.",columns:1,blocks:6});if(C.isError)return e.jsx(da,{eyebrow:"Movement",error:C.error,onRetry:()=>void C.refetch()});const Ta=I.totalHeight;return e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(v,{className:"overflow-hidden rounded-[28px] border border-white/8 bg-[radial-gradient(circle_at_top,rgba(88,182,255,0.08),transparent_28%),linear-gradient(180deg,rgba(4,8,17,0.99),rgba(5,9,18,0.97))] p-3 sm:rounded-[34px] sm:p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3 px-1",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.22em] text-white/34",children:"Movement"}),e.jsxs("div",{className:"flex min-w-0 items-center justify-end gap-2",children:[oe>0?e.jsxs(u,{className:"hidden bg-amber-500/10 text-amber-100 sm:inline-flex",children:[oe," invalid hidden"]}):null,e.jsxs(u,{className:"hidden bg-white/[0.06] text-white/68 sm:inline-flex",children:[M.length," visible"]}),e.jsx("div",{ref:c,children:e.jsxs(k,{type:"button",variant:"ghost",size:"sm","aria-expanded":A,"aria-haspopup":"dialog",className:O("h-9 rounded-full border border-white/10 bg-white/[0.05] px-3 text-white/78 hover:bg-white/[0.1] hover:text-white",A?"ring-1 ring-[rgba(126,229,255,0.34)]":""),onClick:fa,children:[e.jsx(Pa,{className:"size-4"}),"Actions"]})})]})]}),e.jsx(_s,{open:A,anchor:w,items:va,onClose:()=>B(!1)}),K&&Fe.length===0?e.jsx("p",{className:"mb-3 px-1 text-sm text-amber-100/80",children:"No sleep session overlaps the currently loaded timeline range yet. Scroll further back to load older history."}):null,e.jsxs("div",{ref:s,onScroll:Aa,className:"relative h-[82vh] overflow-auto rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(4,7,15,0.98),rgba(6,10,18,0.96))]",children:[e.jsx(Is,{layout:I,scrollTop:he,viewportHeight:z}),Tt?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-white/10 bg-[rgba(8,13,24,0.86)] px-3 py-1.5 font-label text-[10px] uppercase tracking-[0.18em] text-white/70 shadow-[0_16px_36px_rgba(0,0,0,0.28)] backdrop-blur-xl",children:Tt})}):null,e.jsxs("div",{className:"relative",style:{height:`${Ta}px`},children:[I.historyHeaderHeight>0?e.jsx("div",{className:"absolute inset-x-0 top-0",style:{height:`${I.historyHeaderHeight}px`},children:e.jsx(Fs,{segment:M[0]??null})}):null,ba.map(l=>{const d=l.segment;return e.jsx(Bs,{layout:l,selected:m===d.id,onToggle:()=>{p(d.id),b(!0)}},d.id)})]})]})]}),e.jsx(Ks,{open:L!==null||Y!==null,segment:L,draft:$,creating:Ye,saving:Pt.isPending,preflight:xt.data??null,preflightLoading:xt.isFetching,onDraftChange:l=>{if(Ye){Q(l);return}L&&H(d=>({...d,[L.id]:l}))},onFitMissing:()=>{const l=xt.data;if(!(l!=null&&l.nearestMissingStartedAt)||!l.nearestMissingEndedAt)return;const d={...$??ut("stay",L),startedAtInput:Ae(l.nearestMissingStartedAt),endedAtInput:Ae(l.nearestMissingEndedAt)};if(Ye){Q(d);return}L&&H(g=>({...g,[L.id]:d}))},onSave:()=>{$&&Pt.mutateAsync({segment:L,draft:$,creating:Ye},{onSuccess:()=>{_(null),Q(null),se&&(ie(!1),q(!0))}})},onOpenChange:l=>{l||(_(null),Q(null),se&&(ie(!1),q(!0)))}}),e.jsx(Os,{open:N&&f!==null,onOpenChange:l=>{b(l)},segment:f,onEdit:()=>{f!=null&&f.editable&&(_(f.id),b(!1))},onOpenDetail:()=>{f&&(Z(f.id),b(!1))},onDefinePlace:()=>{f&&(Ft(f),b(!1))}}),e.jsx(Rs,{open:n!==null,onOpenChange:l=>{l||Z(null)},segment:n,detail:ee.data??null,loading:ee.isFetching,onEdit:()=>{!n||!n.editable||(_(n.id),Z(null))},onDefinePlace:()=>{n&&Ft(n)}}),e.jsx(Hs,{open:Pe,onOpenChange:l=>{Le(l),l||Ce(null)},segment:U,places:ne.data??[],loading:ne.isFetching,onSelectPlace:async l=>U?(await Na.mutateAsync({segment:U,place:l})).assigned:!1,onCreatePlace:(l,d)=>{ka(l,d)}}),e.jsx(xa,{open:Ue,onOpenChange:l=>{Ne(l),l||(Se(null),De(null))},place:null,seed:nt,onSave:async l=>{await ja.mutateAsync({...l,segment:S.find(d=>d.id===lt)??null})}}),e.jsx(oa,{open:ae,onOpenChange:l=>{q(l),l||se||(We(""),Ge([]))},eyebrow:"Movement data",title:"View data",description:"",children:e.jsxs("div",{className:"grid gap-4",children:[e.jsx(ma,{title:"",description:"",query:y,onQueryChange:We,options:Sa,selectedOptionIds:ge,onSelectedOptionIdsChange:Ge,resultSummary:Dt,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(v,{className:"grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Canonical boxes"}),e.jsx("div",{className:"max-w-3xl text-sm leading-6 text-white/56",children:"This list shows the canonical movement boxes projected by Forge. Automatic boxes are derived from immutable raw phone measurements. User-defined boxes override the projection without mutating raw movement data."})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/70",onClick:()=>{ie(!0),q(!1),Q(ut("stay",ve.at(-1)??null))},children:"Add box"}),e.jsx(u,{tone:"meta",children:Dt}),oe>0?e.jsxs(u,{className:"bg-amber-500/10 text-amber-100",children:[oe," invalid hidden included"]}):null,j.hasNextPage?e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:"h-8 rounded-full border border-white/10 bg-white/[0.04] px-3 text-white/70",pending:j.isFetchingNextPage,pendingLabel:"Loading…",onClick:()=>void j.fetchNextPage(),children:"Load older"}):null]})]}),e.jsx("div",{ref:i,className:"h-[36rem] overflow-y-auto rounded-[24px] border border-white/8 bg-white/[0.03]",children:ve.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-white/50",children:"No movement record matches the current search. Clear filters or load older timeline history."}):e.jsx("div",{className:"relative w-full",style:{height:`${mt.getTotalSize()}px`},children:mt.getVirtualItems().map(l=>{var g;const d=ve[l.index];return e.jsx("div",{ref:mt.measureElement,"data-index":l.index,className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${l.start}px)`},children:e.jsxs("div",{className:"flex items-start gap-2 rounded-[18px] border border-white/8 bg-white/[0.04] px-3 py-2.5",children:[e.jsx("button",{type:"button",className:"min-w-0 flex-1 text-left transition hover:opacity-100",onClick:()=>{d.editable&&(ie(!0),q(!1),_(d.id))},children:e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 text-white",children:[d.kind==="stay"?e.jsx(ia,{className:"size-3.5 shrink-0 text-[var(--primary)]"}):d.kind==="missing"?e.jsx(pt,{className:"size-3.5 shrink-0 text-slate-300/80"}):e.jsx(tt,{className:"size-3.5 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-sm font-medium",children:me(d)})]}),e.jsxs("div",{className:"mt-1 text-xs text-white/56",children:[it(d.startedAt)," →"," ",it(d.endedAt)]})]}),e.jsxs("div",{className:"flex shrink-0 flex-wrap justify-end gap-1.5",children:[e.jsx(u,{tone:d.kind==="trip"?"signal":"meta",children:d.kind==="trip"?"Move":d.kind==="missing"?"Missing":"Stay"}),e.jsx(u,{className:d.sourceKind==="user_defined"?"bg-fuchsia-400/12 text-fuchsia-100":"bg-white/[0.06] text-white/70",children:d.sourceKind==="user_defined"?d.origin==="user_invalidated"?"User invalidated":"User-defined":"Automatic"}),e.jsx(u,{tone:"meta",children:ze(d.durationSeconds)}),d.origin==="continued_stay"?e.jsx(u,{className:"bg-sky-400/10 text-sky-100",children:"Continued stay"}):null,d.origin==="repaired_gap"?e.jsx(u,{className:"bg-amber-400/10 text-amber-100",children:"Repaired"}):null,d.kind==="missing"?e.jsx(u,{className:"bg-slate-300/10 text-slate-100",children:"Missing"}):null,d.isInvalid?e.jsx(u,{className:"bg-amber-500/10 text-amber-100",children:"Invalid"}):null,d.placeLabel?e.jsx(u,{tone:"default",children:d.placeLabel}):null,d.overrideCount>0?e.jsxs(u,{className:"bg-amber-400/10 text-amber-100",children:["Overrides ",d.overrideCount]}):null,e.jsxs(u,{className:"bg-white/[0.06] text-white/66",children:["Raw stays ",d.rawStayIds.length]}),e.jsxs(u,{className:"bg-white/[0.06] text-white/66",children:["Raw trips ",d.rawTripIds.length]}),e.jsxs(u,{className:"bg-white/[0.06] text-white/66",children:["Raw points ",d.rawPointCount]}),d.hasLegacyCorrections?e.jsx(u,{className:"bg-amber-400/10 text-amber-100",children:"Legacy corrections"}):null]})]})}),e.jsx(k,{type:"button",variant:"ghost",size:"sm",className:O("h-8 shrink-0 rounded-full border px-2.5",d.sourceKind==="user_defined"?"border-rose-400/22 bg-rose-500/10 text-rose-100 hover:bg-rose-500/18":"border-amber-400/22 bg-amber-500/10 text-amber-100 hover:bg-amber-500/18"),pending:ct.isPending&&((g=ct.variables)==null?void 0:g.id)===d.id,pendingLabel:"",onClick:()=>{window.confirm(d.sourceKind==="user_defined"?`Delete ${me(d)} and remove this user-defined box from every synced surface?`:`Invalidate ${me(d)} into missing data and hide the automatic box everywhere?`)&&ct.mutateAsync(d)},children:e.jsx(La,{className:"size-3.5"})})]})},d.id)})})})]})]})})]})}function Qs(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}).format(new Date(t))}function Us(t,a){const s=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${s.format(new Date(t))} - ${s.format(new Date(a))}`}function R(t){return t>=3600?`${(t/3600).toFixed(1)}h`:`${Math.round(t/60)}m`}function we(t){return t>=1e3?`${(t/1e3).toFixed(1)} km`:`${Math.round(t)} m`}function Ws(t,a){return t==="distanceMeters"?we(a):t==="caloriesKcal"?`${Math.round(a)} kcal`:R(a)}function ga(t){return t.trim().toLowerCase()}function rt(t){const a=new Date(t).getHours();return a<6?"night":a<12?"morning":a<18?"afternoon":"evening"}function At(t){return new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"}).format(new Date(t))}function Gs(t){const a=new Date(t);return Number.isNaN(a.getTime())?"":new Date(a.getTime()-a.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function ta(t){return{recordedAt:Gs(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 Vs(t){return ga([At(t.recordedAt),t.externalUid,t.isStopAnchor?"stop anchor stop":"path trace point",t.accuracyMeters!=null?`${Math.round(t.accuracyMeters)} meters accuracy`:"",rt(t.recordedAt)].join(" "))}function Ys(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(u,{tone:"meta",children:"Stop anchors"})}),a.set("anchor:path",{id:"anchor:path",label:"Path points",description:"Non-anchor trace points",badge:e.jsx(u,{tone:"meta",children:"Path points"})}),a.set("accuracy:precise",{id:"accuracy:precise",label:"Precise",description:"GPS accuracy below 20m",badge:e.jsx(u,{tone:"meta",children:"Precise"})}),a.set("accuracy:loose",{id:"accuracy:loose",label:"Loose accuracy",description:"GPS accuracy at or above 20m",badge:e.jsx(u,{tone:"meta",children:"Loose accuracy"})}),t.forEach(s=>{const i=rt(s.recordedAt);a.has(`time:${i}`)||a.set(`time:${i}`,{id:`time:${i}`,label:i,description:"Recorded during this time band",badge:e.jsx(u,{tone:"meta",className:"capitalize",children:i})})}),[...a.values()]}function Xs(t,a){return a.every(s=>s==="anchor:stop"?t.isStopAnchor:s==="anchor:path"?!t.isStopAnchor:s==="accuracy:precise"?t.accuracyMeters!=null&&t.accuracyMeters<20:s==="accuracy:loose"?t.accuracyMeters==null||t.accuracyMeters>=20:s.startsWith("time:")?rt(t.recordedAt)===s.slice(5):!0)}function Zs(t){if(t.length===0)return[];const a=Math.min(...t.map(o=>o.latitude)),s=Math.max(...t.map(o=>o.latitude)),i=Math.min(...t.map(o=>o.longitude)),c=Math.max(...t.map(o=>o.longitude)),r=Math.max(s-a,1e-4),h=Math.max(c-i,1e-4);return t.map(o=>({x:12+(o.longitude-i)/h*76,y:12+(1-(o.latitude-a)/r)*76}))}function Js({curve:t,startLabel:a,endLabel:s,stopLabels:i}){const c=t.map((r,h)=>`${h===0?"M":"Q"} ${r.x} ${r.y}`).join(" ");return e.jsxs(v,{className:"overflow-hidden rounded-[30px] border border-white/10 bg-[radial-gradient(circle_at_top,rgba(114,204,255,0.18),transparent_44%),linear-gradient(180deg,rgba(6,11,26,0.98),rgba(8,14,28,0.92))] p-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Stylized trajectory"}),e.jsx(ce,{content:"This graph is a softened trip trace. It emphasizes rhythm, stops, and endpoints instead of raw GPS jitter."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/64",children:"A softened path that prioritizes rhythm, stops, and landmarks over raw map noise."})]}),e.jsxs(u,{tone:"signal",children:[a," → ",s]})]}),e.jsxs("div",{className:"mt-5 rounded-[26px] border border-white/8 bg-[rgba(255,255,255,0.03)] p-4",children:[e.jsxs("svg",{viewBox:"0 0 100 60",className:"h-48 w-full",children:[e.jsx("defs",{children:e.jsxs("filter",{id:"movementGlow",children:[e.jsx("feGaussianBlur",{stdDeviation:"1.8",result:"blur"}),e.jsxs("feMerge",{children:[e.jsx("feMergeNode",{in:"blur"}),e.jsx("feMergeNode",{in:"SourceGraphic"})]})]})}),e.jsx("path",{d:c,fill:"none",stroke:"rgba(255,255,255,0.86)",strokeWidth:"1.5",strokeDasharray:"2.8 2.8",filter:"url(#movementGlow)"}),t.map((r,h)=>e.jsx("g",{children:e.jsx("circle",{cx:r.x,cy:r.y,r:h===0||h===t.length-1?2.6:1.6,fill:h===0||h===t.length-1?"#ffffff":"rgba(170,229,255,0.96)"})},`${r.x}-${r.y}-${h}`))]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:i.map(r=>e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:r},r))})]})]})}function ei({points:t}){const a=Zs(t),s=a.map((i,c)=>`${c===0?"M":"L"} ${i.x} ${i.y}`).join(" ");return e.jsxs(v,{className:"rounded-[30px] border border-white/10 bg-[linear-gradient(180deg,rgba(8,13,25,0.95),rgba(10,17,30,0.88))] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Exact path"}),e.jsx(ce,{content:"This keeps the recent raw location points. Use it when you want the literal recorded trace instead of the cleaned movement graph."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/62",children:"Recent raw points preserved by the companion before long-term simplification."}),e.jsx("div",{className:"mt-5 rounded-[24px] border border-white/8 bg-[rgba(255,255,255,0.03)] p-3",children:e.jsxs("svg",{viewBox:"0 0 100 100",className:"h-52 w-full",children:[e.jsx("rect",{x:"0",y:"0",width:"100",height:"100",rx:"18",fill:"rgba(255,255,255,0.02)"}),e.jsx("path",{d:s,fill:"none",stroke:"rgba(92,225,230,0.95)",strokeWidth:"1.6"}),a.map((i,c)=>e.jsx("circle",{cx:i.x,cy:i.y,r:c===0||c===a.length-1?2:1.1,fill:c===0||c===a.length-1?"#ffffff":"rgba(92,225,230,0.9)"},`${i.x}-${i.y}-${c}`))]})})]})}function ti({point:t,draft:a}){return e.jsxs(v,{className:"grid gap-4 rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(12,18,32,0.98),rgba(8,13,24,0.98))] p-5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Raw datapoint"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:At(t.recordedAt)}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Raw phone measurements are immutable in product UI. To change the visible movement story, create or edit user-defined boxes in the Life Timeline instead."})]}),e.jsx(u,{tone:t.isStopAnchor?"signal":"meta",children:t.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Recorded at"}),e.jsx(P,{type:"datetime-local",value:a.recordedAt,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Speed (m/s)"}),e.jsx(P,{value:a.speedMps,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Latitude"}),e.jsx(P,{value:a.latitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Longitude"}),e.jsx(P,{value:a.longitude,disabled:!0})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Accuracy (m)"}),e.jsx(P,{value:a.accuracyMeters,disabled:!0,placeholder:"Optional"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.16em] text-white/40",children:"Altitude (m)"}),e.jsx(P,{value:a.altitudeMeters,disabled:!0,placeholder:"Optional"})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs(k,{variant:"ghost",className:O("h-10 rounded-full border px-4",a.isStopAnchor?"border-[var(--primary)] bg-[var(--primary)]/16 text-white":"border-white/10 bg-white/[0.04] text-white/64"),disabled:!0,children:[e.jsx(tt,{className:"mr-2 size-4"}),a.isStopAnchor?"Stop anchor":"Path point"]}),e.jsxs("div",{className:"text-sm text-white/50",children:["External id: ",e.jsx("span",{className:"text-white/72",children:t.externalUid})]})]}),e.jsx("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.03] px-4 py-3 text-sm leading-6 text-white/56",children:"This browser is read-only now. Raw points stay immutable so the web app and iPhone can both project the same repaired canonical boxes from the backend."})]})}function hi(){var $e,fe,M,Fe,re;const t=Oa(),a=ra(),s=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[i,c]=x.useState("life"),[r,h]=x.useState(new Date().toISOString().slice(0,10)),[o,m]=x.useState(new Date().toISOString().slice(0,7)),[p,N]=x.useState(null),[b,A]=x.useState(!1),[B,w]=x.useState(!1),[T,F]=x.useState(""),[H,V]=x.useState([]),[_,Y]=x.useState(null),[Q,X]=x.useState(null),[Z,Qe]=x.useState({stayIds:[],tripIds:[]}),[Ce,Pe]=x.useState(!1),[Le,Ue]=x.useState(null),[Ne,nt]=x.useState(""),[Se,lt]=x.useState("distanceMeters"),De=x.useRef(null),ae=te({queryKey:["forge-movement-day",r,...s],queryFn:async()=>(await Ga({date:r,userIds:s})).movement}),q=te({queryKey:["forge-movement-month",o,...s],queryFn:async()=>(await Va({month:o,userIds:s})).movement}),se=te({queryKey:["forge-movement-all-time",...s],queryFn:async()=>(await Ya(s)).movement}),ie=te({queryKey:["forge-life-force",...s],queryFn:async()=>(await Xa(s)).lifeForce}),K=te({queryKey:["forge-movement-settings",...s],queryFn:async()=>(await Za(s)).settings}),xe=te({queryKey:["forge-movement-places",...s],queryFn:async()=>(await ca(s)).places}),y=te({queryKey:["forge-movement-trip",p],queryFn:async()=>p?(await Ja(p)).movement:null,enabled:!!p}),We=te({queryKey:["forge-movement-selection",r,Z.stayIds.join(","),Z.tripIds.join(","),...s],queryFn:async()=>(await es({...Z,userIds:s})).movement,enabled:Z.stayIds.length>0||Z.tripIds.length>0}),ge=ke({mutationFn:async n=>Ha({trackingEnabled:n},s),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-settings"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]})}}),Ge=ke({mutationFn:async n=>n.id?Ka(n.id,n):na(n,s),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-movement-places"]}),await a.invalidateQueries({queryKey:["forge-movement-day"]}),await a.invalidateQueries({queryKey:["forge-movement-all-time"]})}}),he=x.useMemo(()=>{const n=xe.data??[],f=Ne.trim().toLowerCase();return f?n.filter(ee=>[ee.label,...ee.aliases,...ee.categoryTags].join(" ").toLowerCase().includes(f)):n},[Ne,xe.data]),Ve=x.useMemo(()=>{var n;return Ys(((n=y.data)==null?void 0:n.trip.points)??[])},[($e=y.data)==null?void 0:$e.trip.points]),z=x.useMemo(()=>{var ee;const n=((ee=y.data)==null?void 0:ee.trip.points)??[],f=ga(T);return[...n].sort((U,ne)=>new Date(ne.recordedAt).getTime()-new Date(U.recordedAt).getTime()).filter(U=>(f.length===0||Vs(U).includes(f))&&Xs(U,H))},[T,H,(fe=y.data)==null?void 0:fe.trip.points]),Ie=x.useMemo(()=>{var f;const n=((f=y.data)==null?void 0:f.trip.points.length)??0;return n===0?"No raw datapoints on this trip yet.":z.length===n&&T.trim().length===0&&H.length===0?`${n} datapoints visible`:`${z.length} of ${n} datapoints visible`},[z.length,T,H.length,(M=y.data)==null?void 0:M.trip.points.length]),Me=sa({count:z.length,getScrollElement:()=>De.current,estimateSize:()=>96,overscan:8}),C=z.find(n=>n.id===_)??((Fe=y.data)==null?void 0:Fe.trip.points.find(n=>n.id===_))??z[0]??((re=y.data)==null?void 0:re.trip.points[0])??null;if(x.useEffect(()=>{if(B){if(!C){Y(null),X(null);return}Y(C.id),X(ta(C))}},[C,B]),x.useEffect(()=>{F(""),V([]),Y(null),X(null),w(!1)},[p]),ae.isLoading||q.isLoading||se.isLoading||K.isLoading||xe.isLoading)return e.jsx(la,{eyebrow:"Movement",title:"Loading movement workspace",description:"Reconstructing stays, trips, and place intelligence across Forge.",columns:2,blocks:8});if(ae.isError||q.isError||se.isError||K.isError||xe.isError||!ae.data||!q.data||!se.data||!K.data)return e.jsx(da,{eyebrow:"Movement",error:ae.error??q.error??se.error??K.error??xe.error??new Error("Movement data unavailable"),onRetry:()=>{ae.refetch(),q.refetch(),se.refetch(),K.refetch(),xe.refetch()}});const j=ae.data,be=q.data,de=se.data,oe=K.data,S=We.data??j.selectionAggregate,J=j.trips.reduce((n,f)=>n+Xe(f).totalAp,0);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ts,{entityKind:"project",title:"Movement",description:"Turn passive place and travel signals into a real Forge domain: day rhythm, travel arcs, known landmarks, linked work, and reflective evidence.",badge:`${j.summary.tripCount} trips today`,actions:e.jsx("div",{className:"flex flex-wrap gap-2",children:["life","day","month","all_time"].map(n=>e.jsx(k,{variant:"ghost",className:O("h-9 rounded-full border px-4 text-sm",i===n?"border-[var(--primary)] bg-[var(--primary)]/16 text-white":"border-white/10 bg-white/[0.04] text-white/64"),onClick:()=>c(n),children:n==="all_time"?"All time":n==="life"?"Life":n.charAt(0).toUpperCase()+n.slice(1)},n))})}),e.jsxs(v,{className:"grid gap-3 rounded-[28px] border border-white/8 bg-[linear-gradient(180deg,rgba(12,20,34,0.98),rgba(8,14,25,0.96))] p-4 md:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Movement AP today"}),e.jsx("div",{className:"mt-2 text-3xl font-semibold text-white",children:Bt(J)}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Trips and transitions now contribute to the same Action Point ledger as work, habits, and notes."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Typical trip drain"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-[var(--primary)]",children:j.trips[0]?Ze(Xe(j.trips[0]).rateApPerHour):"0 AP/h"}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Movement uses a MET-like drain under the hood, translated into Forge Action Points."})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/40",children:"Life Force sync"}),e.jsx("div",{className:"mt-2 text-2xl font-semibold text-white",children:ie.data?`${Math.round(ie.data.spentTodayAp??0)}/${Math.round(ie.data.dailyBudgetAp??0)} AP`:"Loading..."}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:ie.data?`${Ze(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(Ba,{children:e.jsxs(v,{className:"overflow-hidden rounded-[30px] border border-white/8 bg-[radial-gradient(circle_at_top_left,rgba(107,214,255,0.16),transparent_42%),linear-gradient(180deg,rgba(10,18,35,0.98),rgba(9,15,28,0.92))]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Movement operating mode"}),e.jsx(ce,{content:"This is the passive capture state of the movement system: whether tracking is running, how much is published into Forge, and how aggressive retention is."})]}),e.jsx("div",{className:"mt-2 text-[clamp(1.05rem,1.8vw,1.35rem)] text-white",children:"Background stays and trips as structured life evidence"}),e.jsx("div",{className:"mt-2 max-w-2xl text-sm leading-6 text-white/58",children:"The companion samples quietly while stationary, switches to denser trip capture when you move, and keeps only simplified long-term traces."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:oe.trackingEnabled?"Tracking on":"Tracking off"}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/72",children:oe.publishMode.replaceAll("_"," ")}),e.jsx(k,{variant:"ghost",className:"h-9 rounded-full border border-white/10 bg-white/[0.04] px-4",onClick:()=>ge.mutate(!oe.trackingEnabled),children:oe.trackingEnabled?"Pause passive capture":"Enable passive capture"})]})]}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Distance today"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:we(j.summary.totalDistanceMeters)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Across trips, stops, and linked place changes."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Idle time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.totalIdleSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Time spent settled enough to count as a real stay."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Estimated phone time"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.estimatedScreenTimeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Estimated from hourly Screen Time bins, not exact foreground traces."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Known places"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:j.summary.knownPlaceCount}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Shared between Forge and the iPhone companion."})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(148,163,184,0.12),rgba(71,85,105,0.12))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Missing data"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.missingDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.missingCount," grey gap",j.summary.missingCount===1?"":"s"," where Forge had over one hour without enough movement signal."]})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(251,191,36,0.12),rgba(16,185,129,0.08))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Repaired gaps"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.repairedGapDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.repairedGapCount," inferred span",j.summary.repairedGapCount===1?"":"s"," classified as stay or move instead of leaving blank holes in the day."]})]}),e.jsxs(v,{className:"rounded-[24px] border border-white/8 bg-[linear-gradient(180deg,rgba(56,189,248,0.12),rgba(99,102,241,0.08))] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/40",children:"Continued stays"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-white",children:R(j.summary.continuedStayDurationSeconds)}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[j.summary.continuedStayCount," short stationary span",j.summary.continuedStayCount===1?"":"s"," carried forward so quiet home time stays continuous instead of disappearing."]})]})]})]})}),e.jsx(qa,{children:e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Selection aggregate"}),e.jsx(ce,{content:"When you select stays or trips, Forge totals their span, distance, work overlap, notes, and places here."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/56",children:"Select any combination of stays and trips to sum movement, time, and work evidence."}),e.jsxs("div",{className:"mt-5 grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Span"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(S.durationSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:we(S.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Work overlap"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(S.trackedWorkSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Notes"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.noteCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Estimated phone time"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(S.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.pickupCount})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.04] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:S.notificationCount})]})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:S.placeLabels.map(n=>e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:n},n))}),S.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:S.topApps.map(n=>e.jsx(u,{tone:"default",className:"bg-[rgba(114,204,255,0.12)] text-white/80",children:(n.displayName||n.bundleIdentifier)+" · "+R(n.totalActivitySeconds)},n.id))}):null,S.topCategories.length>0?e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:S.topCategories.map(n=>e.jsx(u,{tone:"default",className:"bg-white/[0.05] text-white/64",children:n.categoryLabel},n.id))}):null]})})]}),i==="life"?e.jsx(Qa,{children:e.jsxs("section",{className:"grid gap-3",children:[e.jsx("div",{className:"flex items-center justify-between gap-3 px-1",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/38",children:"Life graph"}),e.jsx(ce,{content:"This graph shows the movement road of your life: stays are blocks, moves connect them, and the hour/day lines live in the background. Click a segment for details, then use edit when you want to correct it."})]})}),e.jsx(qs,{userIds:s})]})}):null,i==="day"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.55fr)_minmax(22rem,1fr)]",children:[e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(7,12,22,0.92))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Day strip"}),e.jsx(ce,{content:"A compressed 24-hour strip. Each segment keeps its true order and duration, but the whole day stays navigable on one line."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"A single-row timeline from 00:00 to 24:00, always compressed into one navigable strip."})]}),e.jsx(P,{type:"date",value:r,onChange:n=>h(n.target.value),className:"w-[11rem]"})]}),e.jsx("div",{className:"mt-6 overflow-x-auto pb-2",children:e.jsxs("div",{className:"min-w-[52rem]",children:[e.jsx("div",{className:"mb-3 flex justify-between text-[11px] uppercase tracking-[0.18em] text-white/36",children:["00:00","06:00","12:00","18:00","24:00"].map(n=>e.jsx("span",{children:n},n))}),e.jsx("div",{className:"flex h-28 items-stretch overflow-hidden rounded-[28px] border border-white/10 bg-[rgba(255,255,255,0.03)] p-2",children:j.segments.map(n=>{const f=Math.max(9,n.durationSeconds/86400*100),ee=n.kind==="stay"?Z.stayIds.includes(n.id):n.kind==="trip"?Z.tripIds.includes(n.id):!1;return e.jsxs("button",{type:"button",className:O("relative flex min-w-[5.5rem] flex-col justify-between rounded-[22px] border px-3 py-2 text-left transition",n.kind==="missing"?"border-slate-400/20 bg-[linear-gradient(180deg,rgba(148,163,184,0.18),rgba(51,65,85,0.14))] hover:border-slate-300/30 hover:bg-[rgba(148,163,184,0.14)]":ee?"border-[rgba(171,232,255,0.5)] bg-[rgba(171,232,255,0.16)]":"border-white/6 bg-[linear-gradient(180deg,rgba(255,255,255,0.08),rgba(255,255,255,0.02))] hover:border-white/14 hover:bg-white/[0.08]"),style:{width:`${f}%`},onClick:()=>{n.kind!=="missing"&&Qe(U=>{const ne=new Set(U.stayIds),I=new Set(U.tripIds);return n.kind==="stay"?ne.has(n.id)?ne.delete(n.id):ne.add(n.id):I.has(n.id)?I.delete(n.id):(I.add(n.id),N(n.id)),{stayIds:[...ne],tripIds:[...I]}})},children:[e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(u,{tone:n.kind==="trip"?"signal":n.kind==="missing"?"meta":"default",className:"bg-white/[0.08] text-white/82",children:n.kind==="missing"?"gap":n.kind}),e.jsx("span",{className:"text-[11px] text-white/46",children:R(n.durationSeconds)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"line-clamp-2 text-sm font-semibold text-white",children:n.label}),e.jsx("div",{className:"mt-1 text-[12px] leading-5 text-white/52",children:n.subtitle})]})]},n.id)})})]})}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:Qs(r)}),e.jsxs(u,{tone:"default",className:"bg-white/[0.06] text-white/72",children:[j.summary.tripCount," trips"]}),e.jsxs(u,{tone:"default",className:"bg-white/[0.06] text-white/72",children:[j.summary.stayCount," stays"]}),e.jsxs(u,{tone:"meta",children:[j.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-white/42",children:"Selected trip"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:e.jsx(k,{variant:"ghost",className:"h-9 rounded-full border border-white/10 bg-white/[0.04] px-4",onClick:()=>A(n=>!n),children:b?"Stylized graph":"Exact path"})})]}),b?e.jsx(ei,{points:y.data.trip.points}):e.jsx(Js,{curve:y.data.stylizedPath.curve,startLabel:y.data.stylizedPath.startLabel,endLabel:y.data.stylizedPath.endLabel,stopLabels:y.data.stylizedPath.stops.map(n=>n.label)}),e.jsxs(v,{className:"rounded-[28px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Trip context"}),(()=>{const n=Xe(y.data.trip);return e.jsx(e.Fragment,{children:e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx(u,{tone:"signal",children:we(y.data.trip.distanceMeters)}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:y.data.trip.activityType||y.data.trip.travelMode}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:R(y.data.trip.durationSeconds)}),e.jsx(u,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:Ze(n.rateApPerHour)}),e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:Bt(n.totalAp)})]})})})(),e.jsx("div",{className:"mt-4 text-sm leading-6 text-white/58",children:Us(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-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Hourly estimate"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:R(y.data.trip.estimatedScreenTimeSeconds)})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Pickups"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:y.data.trip.pickupCount})]}),e.jsxs("div",{className:"rounded-[20px] border border-white/8 bg-white/[0.04] p-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-white/38",children:"Notifications"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:y.data.trip.notificationCount})]})]}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-white/48",children:"Derived from Screen Time hourly bins, not exact foreground traces."}),y.data.trip.topApps.length>0?e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:y.data.trip.topApps.map(n=>e.jsx(u,{tone:"default",className:"bg-[rgba(114,204,255,0.12)] text-white/80",children:(n.displayName||n.bundleIdentifier)+" · "+R(n.totalActivitySeconds)},n.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(n=>e.jsx(u,{tone:"default",className:"bg-white/[0.05] text-white/64",children:n.categoryLabel},n.id))}):null]})]}):e.jsx(v,{className:"rounded-[30px] border border-dashed border-white/12 bg-white/[0.03] p-6 text-white/58",children:"Select a trip segment to open the stylized trajectory card and exact path toggle."})})]}):null,i==="month"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.4fr)_minmax(18rem,0.85fr)]",children:[e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(9,15,28,0.97),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Month view"}),e.jsx(ce,{content:"This chart stays quantitative. Switch the metric to compare daily distance, moving time, idle time, or calories across the month."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"Switch the Y-axis between motion, idle time, and energy without losing the same monthly frame."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{type:"month",value:o,onChange:n=>m(n.target.value),className:"w-[10.5rem]"}),["distanceMeters","movingSeconds","idleSeconds","caloriesKcal"].map(n=>e.jsx(k,{variant:"ghost",className:O("h-9 rounded-full border px-4 text-sm",Se===n?"border-[var(--primary)] bg-[var(--primary)]/14 text-white":"border-white/10 bg-white/[0.04] text-white/62"),onClick:()=>lt(n),children:n==="distanceMeters"?"Distance":n==="movingSeconds"?"Moving":n==="idleSeconds"?"Idle":"Calories"},n))]})]}),e.jsx("div",{className:"mt-6 h-[24rem]",children:e.jsx(as,{width:"100%",height:"100%",children:e.jsxs(ss,{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:"rgba(110,220,255,0.7)"}),e.jsx("stop",{offset:"100%",stopColor:"rgba(110,220,255,0.05)"})]})}),e.jsx(is,{stroke:"rgba(255,255,255,0.08)",vertical:!1}),e.jsx(rs,{dataKey:"dateKey",tick:{fill:"rgba(255,255,255,0.46)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(ns,{tick:{fill:"rgba(255,255,255,0.46)",fontSize:11},axisLine:!1,tickLine:!1}),e.jsx(ls,{contentStyle:{background:"rgba(7,12,24,0.94)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:16},formatter:n=>Ws(Se,Number(n))}),e.jsx(ds,{type:"monotone",dataKey:Se,stroke:"rgba(126,233,255,0.95)",fill:"url(#movementMonthFill)",strokeWidth:2.4})]})})})]}),e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Month totals"}),e.jsxs("div",{className:"mt-5 grid gap-3",children:[e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:we(be.totals.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Moving time"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:R(be.totals.movingSeconds)})]}),e.jsxs("div",{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Settled time"}),e.jsx("div",{className:"mt-2 text-2xl text-white",children:R(be.totals.idleSeconds)})]})]})]})]}):null,i==="all_time"?e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.35fr)_minmax(20rem,0.95fr)]",children:[e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(8,13,25,0.97),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Trips"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:de.summary.tripCount})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Known places"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:de.summary.knownPlaceCount})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Distance"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:we(de.summary.totalDistanceMeters)})]}),e.jsxs(v,{className:"rounded-[22px] border border-white/8 bg-white/[0.03] p-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Countries"}),e.jsx("div",{className:"mt-2 text-3xl text-white",children:de.summary.visitedCountries})]})]}),e.jsx("div",{className:"mt-6 grid gap-3 sm:grid-cols-2",children:de.recentTrips.map(n=>e.jsx("button",{type:"button",className:"rounded-[24px] border border-white/8 bg-white/[0.03] p-4 text-left transition hover:bg-white/[0.06]",onClick:()=>{c("day"),N(n.id)},children:(()=>{const f=Xe({startedAt:n.startedAt,endedAt:new Date(new Date(n.startedAt).getTime()+36e5).toISOString(),expectedMet:2});return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-white/36",children:"Recent travel"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:n.label||"Untitled trip"}),e.jsxs("div",{className:"mt-1 text-sm text-white/56",children:[we(n.distanceMeters)," · ",n.activityType||"travel"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:e.jsx(u,{tone:"default",className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:Ze(f.rateApPerHour)})})]})})()},n.id))})]}),e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-white/[0.04] p-5",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Place categories"}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:de.categoryBreakdown.map(n=>e.jsxs(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:[n.tag," · ",n.count]},n.tag))})]})]}):null,e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.25fr)_minmax(22rem,0.95fr)]",children:[e.jsx(Ua,{children:e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(8,14,28,0.96),rgba(9,15,28,0.92))] p-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Known places"}),e.jsx(ce,{content:"Known places turn raw stationary spans into named contexts like home, work, gym, nature, or any custom place tag you want Forge to remember."})]}),e.jsx("div",{className:"mt-2 text-sm text-white/58",children:"These landmarks anchor stays, travel XP, and contextual reasoning in both Forge and the companion. Seeded tags like home, workplace, gym, holiday, grocery, or nature matter for downstream calculations, but place tags stay open-ended."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{value:Ne,onChange:n=>nt(n.target.value),placeholder:"Search places",className:"w-[11rem]"}),e.jsx(k,{onClick:()=>{Ue(null),Pe(!0)},children:"Add place"})]})]}),e.jsx("div",{className:"mt-5 grid gap-3",children:he.map(n=>e.jsxs("button",{type:"button",className:"flex items-start justify-between gap-3 rounded-[24px] border border-white/8 bg-white/[0.03] p-4 text-left transition hover:bg-white/[0.06]",onClick:()=>{Ue(n),Pe(!0)},children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-lg text-white",children:n.label}),e.jsxs("div",{className:"mt-1 text-sm text-white/56",children:[n.latitude.toFixed(4),", ",n.longitude.toFixed(4)," · radius ",Math.round(n.radiusMeters)," m"]}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:n.categoryTags.map(f=>e.jsx(u,{tone:"default",className:"bg-white/[0.06] text-white/74",children:f},f))})]}),e.jsx(Mt,{className:"mt-1 size-4 text-white/42"})]},n.id))})]})}),e.jsxs(v,{className:"rounded-[30px] border border-white/8 bg-[linear-gradient(180deg,rgba(10,17,31,0.96),rgba(8,13,24,0.92))] p-5",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.2em] text-white/42",children:"Movement help"}),e.jsx(ce,{content:"Most movement surfaces on this page have help buttons. Use them to understand the graph, the day strip, the month chart, and the place system without keeping a large prose block on screen."})]}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-white/58",children:"Use the small help icons across this page for graph explanations, timeline semantics, and metric meanings."}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Life graph"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Day strip"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Month chart"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Known places"}),e.jsx(u,{className:"bg-white/[0.06] text-white/74",children:"Selection aggregate"})]})]})]}),y.data?e.jsx(oa,{open:B,onOpenChange:n=>{w(n),n||(F(""),V([]),Y(null),X(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(Wa,{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:T,onQueryChange:F,options:Ve,selectedOptionIds:H,onSelectedOptionIdsChange:V,resultSummary:Ie,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(v,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Raw datapoints"}),e.jsx("div",{className:"mt-2 text-lg text-white",children:"Open a point to correct or delete it."})]}),e.jsx(u,{tone:"meta",children:Ie})]}),e.jsx("div",{ref:De,className:"h-[34rem] overflow-y-auto rounded-[24px] border border-white/8 bg-white/[0.03]",children:z.length===0?e.jsx("div",{className:"flex h-full items-center justify-center p-6 text-center text-sm leading-6 text-white/50",children:"No datapoint matches the current search. Clear some filters or search by time, anchor type, or accuracy."}):e.jsx("div",{className:"relative w-full",style:{height:`${Me.getTotalSize()}px`},children:Me.getVirtualItems().map(n=>{const f=z[n.index];return e.jsx("div",{className:"absolute left-0 top-0 w-full px-3 py-2",style:{transform:`translateY(${n.start}px)`},children:e.jsxs("button",{type:"button",className:O("grid w-full gap-3 rounded-[20px] border px-4 py-3 text-left transition",_===f.id?"border-[rgba(171,232,255,0.34)] bg-[rgba(171,232,255,0.12)]":"border-white/8 bg-white/[0.04] hover:bg-white/[0.07]"),onClick:()=>{Y(f.id),X(ta(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-white",children:[e.jsx($a,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:At(f.recordedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-white/56",children:[f.latitude.toFixed(5),", ",f.longitude.toFixed(5)]})]}),e.jsx(u,{tone:f.isStopAnchor?"signal":"meta",children:f.isStopAnchor?"Stop anchor":"Path point"})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(u,{tone:"meta",className:"capitalize",children:rt(f.recordedAt)}),f.accuracyMeters!=null?e.jsxs(u,{tone:"meta",children:[Math.round(f.accuracyMeters)," m accuracy"]}):null,f.speedMps!=null?e.jsxs(u,{tone:"meta",children:[f.speedMps.toFixed(1)," m/s"]}):null]})]})},f.id)})})})]})]}),C&&Q?e.jsx(ti,{point:C,draft:Q}):e.jsx(v,{className:"rounded-[28px] border border-dashed border-white/12 bg-white/[0.03] p-6 text-white/56",children:"Pick a datapoint to inspect its raw measurement details. To correct what the user sees, use canonical user-defined movement boxes in the Life Timeline."})]})})}):null,e.jsx(xa,{open:Ce,onOpenChange:Pe,place:Le,onSave:async n=>{await Ge.mutateAsync(n)}})]})}export{hi as MovementPage};