forge-openclaw-plugin 0.3.5 → 0.3.6
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.
- package/dist/assets/{action-bar-DBZ38L_6.js → action-bar-CsDQF9d4.js} +1 -1
- package/dist/assets/{activity-page-BJxUR9bD.js → activity-page-CACf1Sd5.js} +1 -1
- package/dist/assets/{ai-surface-workspace-ehzBjTsW.js → ai-surface-workspace-Vn5fqCAT.js} +1 -1
- package/dist/assets/{atlas-panel-BFUeVT69.js → atlas-panel-GdK1oyxo.js} +1 -1
- package/dist/assets/{board-CLOHbg6t.js → board-CuxQRKPJ.js} +1 -1
- package/dist/assets/{calendar-page-Bg8W-YQ-.js → calendar-page-CcVGbvfY.js} +1 -1
- package/dist/assets/{calendar-rules-9XQLoI96.js → calendar-rules-Dlq0KT93.js} +1 -1
- package/dist/assets/{calendar-week-toolbar-BeYnx1pE.js → calendar-week-toolbar-BVFb1_2G.js} +1 -1
- package/dist/assets/{charts-DwTguE_x.js → charts-BzT4pUPg.js} +1 -1
- package/dist/assets/{companion-sync-lab-page-BRKYkIrs.js → companion-sync-lab-page-Dgvtdc4i.js} +1 -1
- package/dist/assets/{daily-metrics-dashboard-Jt0nAHU5.js → daily-metrics-dashboard-ChQVbNJI.js} +1 -1
- package/dist/assets/date-keys-BnZV4PNO.js +1 -0
- package/dist/assets/{define-workbench-box-5h-dyvJY.js → define-workbench-box-DWAqqjvH.js} +1 -1
- package/dist/assets/{entity-link-multiselect-Bb4De_e3.js → entity-link-multiselect-Do5DTju7.js} +1 -1
- package/dist/assets/{entity-note-count-link-BzWnsOmI.js → entity-note-count-link-CV3eOv66.js} +1 -1
- package/dist/assets/{entity-notes-surface-CagOwdng.js → entity-notes-surface-CiUgAVl7.js} +1 -1
- package/dist/assets/{execution-board-DTmAtmqZ.js → execution-board-ClaXVQ0H.js} +1 -1
- package/dist/assets/{faceted-token-search-DJPRm9AY.js → faceted-token-search-DoSsb7qT.js} +1 -1
- package/dist/assets/{flagship-signal-deck-CJbGZF7I.js → flagship-signal-deck-B2s7TrIN.js} +1 -1
- package/dist/assets/{floating-action-menu-K77jh8XZ.js → floating-action-menu-DGkHCmvI.js} +1 -1
- package/dist/assets/{forms-C5d5hTf2.js → forms-D1qJ3oOP.js} +1 -1
- package/dist/assets/{generic-node-view-p5ePSFuG.js → generic-node-view-CgLkbts-.js} +1 -1
- package/dist/assets/{goal-detail-page-DGu_khEK.js → goal-detail-page-JRcEYpeA.js} +1 -1
- package/dist/assets/{goal-dialog-BWD7cOv9.js → goal-dialog-6R2uYWPQ.js} +1 -1
- package/dist/assets/{goals-page-Bgj3sj0f.js → goals-page-CYestXkp.js} +1 -1
- package/dist/assets/{graph-Cd5WF3lw.js → graph-BF4IsheG.js} +1 -1
- package/dist/assets/{habits-page-Ctut1tuX.js → habits-page-B27lnyKu.js} +1 -1
- package/dist/assets/{health-boxes-Ie3horXx.js → health-boxes-CeqSGyZ3.js} +1 -1
- package/dist/assets/index-DGYIFHgo.js +2 -0
- package/dist/assets/{index-CEgIwgk9.css → index-UzsVTD1W.css} +1 -1
- package/dist/assets/{inline-note-fields-DE6WM9uM.js → inline-note-fields-CJ9ukqFp.js} +1 -1
- package/dist/assets/{insight-flow-dialog-XL8I74eJ.js → insight-flow-dialog-BgaJRYGX.js} +1 -1
- package/dist/assets/{insights-page-Bz1FLbp5.js → insights-page-Dc5bilGE.js} +1 -1
- package/dist/assets/{kanban-boxes-BBziel7P.js → kanban-boxes-qIwmQlRq.js} +1 -1
- package/dist/assets/{kanban-page-DdQP73I3.js → kanban-page-BGnVLHeN.js} +1 -1
- package/dist/assets/{knowledge-graph-page-DdHWj4Dj.js → knowledge-graph-page-B7IsVVO_.js} +1 -1
- package/dist/assets/{life-force-page-BRN-93cI.js → life-force-page-B5N4DknK.js} +1 -1
- package/dist/assets/{life-force-workspace-BowvP5R4.js → life-force-workspace-Da-dmoRX.js} +1 -1
- package/dist/assets/{maps-D0Mm6WPG.js → maps-BTVHALP8.js} +1 -1
- package/dist/assets/{metric-tile-B6aJueRo.js → metric-tile-BVuj7mc3.js} +1 -1
- package/dist/assets/{motion-DwjmC9aq.js → motion-DcgUnXhY.js} +1 -1
- package/dist/assets/{movement-boxes-5cjWjIdR.js → movement-boxes-BZrdIh8b.js} +1 -1
- package/dist/assets/{movement-page-Dy53RWtB.js → movement-page-CY2XLgp_.js} +1 -1
- package/dist/assets/{note-markdown-CvEQCfoi.js → note-markdown-BZHBOkEd.js} +1 -1
- package/dist/assets/{note-tags-input-Cg5zBXos.js → note-tags-input-DucocvNH.js} +1 -1
- package/dist/assets/{notes-boxes-CgZyf7mV.js → notes-boxes-DAQ6KBkJ.js} +1 -1
- package/dist/assets/{notes-page-Cbdcv0Ej.js → notes-page-CSCfdDJl.js} +1 -1
- package/dist/assets/{open-in-graph-button-D31ZOEhA.js → open-in-graph-button-ObO3m8yd.js} +1 -1
- package/dist/assets/{orbit-map-8eNDWek8.js → orbit-map-Bteg-ola.js} +1 -1
- package/dist/assets/{overview-page-CZ6q52Qj.js → overview-page-ckfN_sLZ.js} +1 -1
- package/dist/assets/{page-hero-C0MpI3MM.js → page-hero-BkrRTu-t.js} +1 -1
- package/dist/assets/pill-cluster-COzv8VgR.js +1 -0
- package/dist/assets/{preference-entity-handoff-button-CJhr5AXl.js → preference-entity-handoff-button-BpVAeFmY.js} +1 -1
- package/dist/assets/{preferences-page-8vszDNFX.js → preferences-page-DseOh9AP.js} +1 -1
- package/dist/assets/{project-collections-sC7eAAhS.js → project-collections-C7yU5PSi.js} +1 -1
- package/dist/assets/{project-detail-page-BKdnMjJy.js → project-detail-page-Crt46y_7.js} +1 -1
- package/dist/assets/{project-dialog-BiHZpOo1.js → project-dialog-YYxtlqg8.js} +1 -1
- package/dist/assets/{project-management-hierarchy-page-VW-hykAI.js → project-management-hierarchy-page-DnojKHzy.js} +1 -1
- package/dist/assets/{project-management-section-nav-BEZ5zihs.js → project-management-section-nav-Ctjd348W.js} +1 -1
- package/dist/assets/{projects-boxes-Ca6rpYeE.js → projects-boxes-D8lLFGBC.js} +1 -1
- package/dist/assets/{projects-page-D86pjpTf.js → projects-page-CV_2em8d.js} +1 -1
- package/dist/assets/{psyche-behaviors-page-YLJB6CRU.js → psyche-behaviors-page-CYCNk0rz.js} +1 -1
- package/dist/assets/{psyche-flashcards-page-D3gdHLUw.js → psyche-flashcards-page-DwmjBixN.js} +1 -1
- package/dist/assets/{psyche-goal-map-page-DJiqSiCx.js → psyche-goal-map-page-CdMhyBKh.js} +1 -1
- package/dist/assets/{psyche-graph-Tke0qFdt.js → psyche-graph-BcrZcJrq.js} +1 -1
- package/dist/assets/{psyche-metrics-page-DoLnvmC2.js → psyche-metrics-page-D5bX1mNX.js} +1 -1
- package/dist/assets/{psyche-mode-guide-page-_Zbvg_HL.js → psyche-mode-guide-page-BmX9EOOB.js} +1 -1
- package/dist/assets/{psyche-modes-page-eAkaAzJc.js → psyche-modes-page-CTHFDyLE.js} +1 -1
- package/dist/assets/{psyche-page-CwmuBVjA.js → psyche-page-DRR3Fjv-.js} +1 -1
- package/dist/assets/{psyche-patterns-page-D7B4Ykjq.js → psyche-patterns-page-BAS38xYf.js} +1 -1
- package/dist/assets/{psyche-questionnaire-builder-page-CHJlvCzX.js → psyche-questionnaire-builder-page-DpSi-zg3.js} +1 -1
- package/dist/assets/{psyche-questionnaire-detail-page-Bg3ll-D4.js → psyche-questionnaire-detail-page-BcXIiV4E.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-detail-page-CIEerczF.js → psyche-questionnaire-run-detail-page-DvccwzWO.js} +1 -1
- package/dist/assets/{psyche-questionnaire-run-page-DyxIk6Qx.js → psyche-questionnaire-run-page-vcyon8IZ.js} +1 -1
- package/dist/assets/{psyche-questionnaires-page-ZlqUxuIl.js → psyche-questionnaires-page-B0DDTner.js} +1 -1
- package/dist/assets/{psyche-report-detail-page-B2jgYnQ5.js → psyche-report-detail-page-BgBA3xIO.js} +1 -1
- package/dist/assets/{psyche-reports-page-DlXr52yr.js → psyche-reports-page-Ce1vEEqW.js} +1 -1
- package/dist/assets/{psyche-schemas-Dtskzvv1.js → psyche-schemas-DDol0j-g.js} +1 -1
- package/dist/assets/{psyche-schemas-beliefs-page-BhrTZN9B.js → psyche-schemas-beliefs-page-D-IHHohY.js} +1 -1
- package/dist/assets/{psyche-screen-time-page-WNGcdusx.js → psyche-screen-time-page-DOKW3m8B.js} +1 -1
- package/dist/assets/{psyche-self-observation-page-XsCOglo4.js → psyche-self-observation-page-j7Sk6Ns1.js} +1 -1
- package/dist/assets/{psyche-values-page-NvHI6zWK.js → psyche-values-page-NfzdWUyb.js} +1 -1
- package/dist/assets/{question-flow-dialog-Bj4PxpjS.js → question-flow-dialog-CLHVmFON.js} +1 -1
- package/dist/assets/{report-chain-fields-mWFikZzT.js → report-chain-fields-C9MuyBha.js} +1 -1
- package/dist/assets/{rewards-page-DyjwXsQN.js → rewards-page-CVxOBP6m.js} +1 -1
- package/dist/assets/{scheduling-rules-editor-C6FEYOxd.js → scheduling-rules-editor-BmbOHH_R.js} +1 -1
- package/dist/assets/{schema-badge-CCe4zkSN.js → schema-badge-BAiS_OAp.js} +1 -1
- package/dist/assets/{schemas-Cjwn6ooR.js → schemas-B0AXfuOr.js} +1 -1
- package/dist/assets/{select-menu-DeJhCsd8.js → select-menu-Bl5MILOj.js} +1 -1
- package/dist/assets/{settings-agents-page-DYDxyKu-.js → settings-agents-page-BIRP02mt.js} +1 -1
- package/dist/assets/{settings-bin-page-BWLfKVW1.js → settings-bin-page-DxJKeM28.js} +1 -1
- package/dist/assets/{settings-calendar-page-Ci-wXhCv.js → settings-calendar-page-aMBtwvO_.js} +1 -1
- package/dist/assets/{settings-data-page-DxIw-fWn.js → settings-data-page-nHNergsh.js} +1 -1
- package/dist/assets/{settings-logs-page-inpyIdu6.js → settings-logs-page-CFotPoFy.js} +1 -1
- package/dist/assets/{settings-mobile-page-BcJGLax8.js → settings-mobile-page-Bf_1D-bN.js} +1 -1
- package/dist/assets/{settings-models-page-OWTRhfkj.js → settings-models-page-BbFNmnik.js} +1 -1
- package/dist/assets/{settings-page-DXxF3qK2.js → settings-page-CalbNbcg.js} +1 -1
- package/dist/assets/{settings-rewards-page-CCXin1n_.js → settings-rewards-page-ByDfCzP5.js} +1 -1
- package/dist/assets/{settings-section-nav-CwSDNC3W.js → settings-section-nav-x_JXfzL9.js} +1 -1
- package/dist/assets/{settings-users-page-B4NEACwR.js → settings-users-page-N1jl9hWV.js} +1 -1
- package/dist/assets/{settings-wiki-page-BNRK1SYc.js → settings-wiki-page-Bn2Qr94L.js} +1 -1
- package/dist/assets/{sleep-page-Bara54nB.js → sleep-page-DyU635jb.js} +1 -1
- package/dist/assets/{sports-page-BawekFKD.js → sports-page-DbK4yGrR.js} +1 -1
- package/dist/assets/{state-BtwEvpO6.js → state-Bpe5dF3T.js} +1 -1
- package/dist/assets/{strategies-page-BEl3NGAU.js → strategies-page-AUBlFCZ9.js} +1 -1
- package/dist/assets/{strategy-detail-page-DPPI_8Ub.js → strategy-detail-page-DCF8mVaL.js} +1 -1
- package/dist/assets/{strategy-dialog-DU6wbBkQ.js → strategy-dialog-50xKlqcz.js} +1 -1
- package/dist/assets/{surface-BVYp-Wq9.js → surface-BjT1dIAF.js} +1 -1
- package/dist/assets/{table-BuONJH1s.js → table-U7otr5go.js} +1 -1
- package/dist/assets/{task-detail-page-BsMVAsbb.js → task-detail-page-Dsll2LCX.js} +1 -1
- package/dist/assets/{task-dialog-BGzPc6TW.js → task-dialog-BfPkbIPE.js} +1 -1
- package/dist/assets/{timebox-planning-dialog-4_XWuqkw.js → timebox-planning-dialog-BTKUS6Jj.js} +1 -1
- package/dist/assets/{today-boxes-5pCvh5zS.js → today-boxes-BPi9bDHM.js} +1 -1
- package/dist/assets/{today-page-BGurICpl.js → today-page-BSXSA-Ts.js} +1 -1
- package/dist/assets/{training-load-page-BkoYKZ9_.js → training-load-page-BD0s8-Zm.js} +1 -1
- package/dist/assets/{ui-B9O-eUim.js → ui-B9TWEtCx.js} +1 -1
- package/dist/assets/{use-anchored-overlay-position-BrQ4cqKn.js → use-anchored-overlay-position-BY4kNzPj.js} +1 -1
- package/dist/assets/{use-psyche-focus-target-Cuxni3SK.js → use-psyche-focus-target-BhNedCZB.js} +1 -1
- package/dist/assets/{user-badge-DfDv87j7.js → user-badge-ap1PvOxd.js} +1 -1
- package/dist/assets/{user-select-field-BNqv8-wd.js → user-select-field-fx129Uh6.js} +1 -1
- package/dist/assets/{utility-widgets-CbYj32he.js → utility-widgets-Cq508sqJ.js} +1 -1
- package/dist/assets/{vendor-Cpmju3nw.js → vendor-BwL6m4SE.js} +216 -211
- package/dist/assets/{vitals-page-DlxMk-L7.js → vitals-page-BnXk8OzN.js} +1 -1
- package/dist/assets/{weekly-review-page-VrEvAl1T.js → weekly-review-page-CnmSGnEC.js} +1 -1
- package/dist/assets/weight-loss-page-Bn6lAXNf.js +5 -0
- package/dist/assets/{wiki-article-markdown-DxTkiQRy.js → wiki-article-markdown-BDnkdNDC.js} +1 -1
- package/dist/assets/{wiki-editor-page-Beu92YnZ.js → wiki-editor-page-CHEETB0G.js} +1 -1
- package/dist/assets/{wiki-ingest-history-page-Cq_soygm.js → wiki-ingest-history-page-CisvtAzm.js} +1 -1
- package/dist/assets/{wiki-ingest-modal-D6xs2sEn.js → wiki-ingest-modal-C2faIjzj.js} +1 -1
- package/dist/assets/{wiki-page-yF3Flgtg.js → wiki-page-CELe_6qL.js} +1 -1
- package/dist/assets/{workbench-flow-page-CZZGg3a8.js → workbench-flow-page-JBVim3L0.js} +1 -1
- package/dist/assets/{workbench-page-DKENZ5Nz.js → workbench-page-q7Z3sQtz.js} +1 -1
- package/dist/assets/{workout-detail-page-CeN4QiYQ.js → workout-detail-page-9I_3DPYU.js} +2 -2
- package/dist/index.html +8 -8
- package/dist/server/server/migrations/070_health_mobile_sync_completion_index.sql +16 -0
- package/dist/server/server/src/app.js +135 -13
- package/dist/server/server/src/health-weight-loss.js +48 -6
- package/dist/server/server/src/health.js +301 -93
- package/dist/server/server/src/openapi.js +31 -0
- package/dist/server/server/src/repositories/gamification.js +25 -0
- package/dist/server/server/src/repositories/tasks.js +82 -17
- package/dist/server/server/src/services/dashboard.js +5 -4
- package/dist/server/server/src/services/gamification.js +47 -19
- package/dist/server/server/src/services/life-force.js +99 -0
- package/dist/server/src/lib/api.js +4 -0
- package/dist/server/src/lib/snapshot-normalizer.js +42 -23
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/server/migrations/070_health_mobile_sync_completion_index.sql +16 -0
- package/skills/forge-openclaw/SKILL.md +1 -0
- package/skills/forge-openclaw/psyche_entity_playbooks.md +8 -0
- package/dist/assets/date-keys-Cj1G3TOn.js +0 -1
- package/dist/assets/index-BaiwtAgo.js +0 -2
- package/dist/assets/pill-cluster-DGwKZQKF.js +0 -1
- package/dist/assets/weight-loss-page-DJDnjxKF.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as g,j as e,aV as re,ck as ae,cm as te}from"./vendor-Cpmju3nw.js";import{j as se,i as _,k as ie}from"./state-BtwEvpO6.js";import{E as ne}from"./entity-link-multiselect-Bb4De_e3.js";import{d as de,S as le,e as ce,bs as oe,C as w,k as v,c as b,B as $,I as Q,T as ue,d$ as me,bd as xe,e0 as ve,b3 as pe,b4 as ge,b5 as he,b6 as fe,b9 as be}from"./index-BaiwtAgo.js";import{P as je}from"./page-hero-C0MpI3MM.js";import{S as ye,a as ke,b as Ne}from"./health-boxes-Ie3horXx.js";import{b as we,p as Se}from"./health-link-options-Cpx8w7uM.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./generic-node-view-p5ePSFuG.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-5h-dyvJY.js";const _e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],W={awake:{label:"Awake",strong:"var(--warning)",soft:"var(--ui-warning-soft)",text:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"},core:{label:"Core",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"},deep:{label:"Deep",strong:"var(--success)",soft:"var(--ui-success-soft)",text:"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"},rem:{label:"REM",strong:"var(--info)",soft:"var(--ui-info-soft)",text:"text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"},in_bed:{label:"In bed",strong:"color-mix(in_srgb,var(--ui-ink-strong)_46%,transparent)",soft:"var(--ui-surface-3)",text:"text-[var(--ui-ink-medium)]"},asleep_unspecified:{label:"Asleep",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"}};function I(r){return W[r]??W.asleep_unspecified}function p(r){if(r<=0)return"0m";const a=Math.floor(r/3600),t=Math.round(r%3600/60);return a===0?`${t}m`:t===0?`${a}h`:`${a}h ${t}m`}function Ae(r){const a=Math.round(r/60);return a===0?"on baseline":`${a>0?"+":"-"}${Math.abs(a)}m`}function T(r){return`${Math.round(r*100)}%`}function A(r,a){return r?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",timeZone:a}).format(new Date(r)):"n/a"}function O(r,a){return new Intl.DateTimeFormat(void 0,{weekday:"long",day:"numeric",month:"long",timeZone:a}).format(new Date(r))}function q(r,a,t){return`${A(r,t)} - ${A(a,t)}`}function Te(r){const[a,t]=r.split("-").map(Number);return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(a,(t??1)-1,1))}function U(r){const a=new Date(r),t=(r.getDay()+6)%7;return a.setDate(r.getDate()-t),a}function Re(r){const a=U(r);return a.setDate(a.getDate()+6),a}function Me(r){const a=r.getFullYear(),t=`${r.getMonth()+1}`.padStart(2,"0"),s=`${r.getDate()}`.padStart(2,"0");return`${a}-${t}-${s}`}function B(r){return{qualitySummary:typeof r.annotations.qualitySummary=="string"?r.annotations.qualitySummary:"",notes:typeof r.annotations.notes=="string"?r.annotations.notes:"",tagsText:Array.isArray(r.annotations.tags)?r.annotations.tags.join(", "):"",linkValues:Array.isArray(r.links)?r.links.map(a=>`${a.entityType}:${a.entityId}`):[]}}function De(r,a){if(!r)return[];const[t,s]=r.split("-").map(Number),n=new Date(t,(s??1)-1,1),u=new Date(t,s??1,0),d=U(n),x=Re(u),l=new Map(a.map(c=>[c.dateKey,c])),i=[];for(const c=new Date(d);c<=x;c.setDate(c.getDate()+1)){const y=Me(c);i.push({dateKey:y,dayNumber:c.getDate(),outsideMonth:c.getMonth()!==n.getMonth(),sleep:l.get(y)??null})}return i}function Ie(r){return r>0?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r<0?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-medium)]"}function J(r){return r==="recharged"||r==="recovered"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="steady"||r==="stable"?"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]":r==="fragile"||r==="strained"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":r==="depleted"?"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function Be(r){return r==="provider_raw"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="historical_raw"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function qe(r){return r==="provider_raw"?"Provider raw data":r==="historical_raw"?"Historical raw data":"Raw data unavailable"}function $e(r){return r.qualityKind==="provider_native"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}function Ce(r,a){const t=r.stage;if(typeof t=="string"&&t.trim().length>0)return t;const s=r.sourceType;if(typeof s=="string"&&s.trim().length>0)return s;const n=r.stageBreakdown;if(Array.isArray(n)&&n.length>0){const u=n[0];if(u&&typeof u=="object"&&typeof u.stage=="string")return(u.stage||"asleep_unspecified").trim()}return a.includes("awake")?"awake":"asleep_unspecified"}function Ke(r){const a=r,t=(a==null?void 0:a.segments)??(a==null?void 0:a.rawSegments)??[],s=(a==null?void 0:a.auditLogs)??(a==null?void 0:a.rawLogs)??[],n=a!=null&&a.sourceRecords&&a.sourceRecords.length>0?a.sourceRecords:s.filter(d=>typeof d.startedAt=="string"&&typeof d.endedAt=="string").map(d=>({id:d.id,importRunId:d.importRunId,pairingSessionId:d.pairingSessionId,sleepSessionId:d.sleepSessionId,userId:d.userId,provider:d.source,providerRecordType:d.logType,providerRecordUid:d.externalUid??d.id,sourceDevice:"",sourceTimezone:d.sourceTimezone,localDateKey:d.localDateKey,startedAt:d.startedAt,endedAt:d.endedAt,rawStage:Ce(d.payload,d.logType),rawValue:null,qualityKind:"historical_import",payload:d.payload,metadata:d.metadata,ingestedAt:d.createdAt})),u=(a==null?void 0:a.rawDataStatus)??(n.length>0?"historical_raw":"raw_unavailable");return{sourceRecords:n,segments:t,auditLogs:s,rawDataStatus:u}}function G({stages:r}){const a=r.reduce((t,s)=>t+s.seconds,0);return r.length===0||a===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No stage composition was stored for this night yet."}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:r.map(t=>{const s=I(t.stage);return e.jsx("div",{className:"h-full",style:{width:`${Math.max(4,t.seconds/a*100)}%`,background:s.strong},title:`${s.label} · ${p(t.seconds)}`},t.stage)})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:r.map(t=>{const s=I(t.stage),n="percentage"in t&&typeof t.percentage=="number"?t.percentage:a>0?t.seconds/a:0;return e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] px-3 py-3",style:{background:s.soft},children:[e.jsx("div",{className:b("text-sm font-medium",s.text),children:s.label}),e.jsx("div",{className:"mt-1 text-lg text-[var(--ui-ink-strong)]",children:p(t.seconds)}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:T(n)})]},t.stage)})})]})}function H({blocks:r,selectedBlockId:a,onSelect:t}){return e.jsxs("div",{className:"relative h-12 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)] bg-[length:25%_100%]"}),r.map(s=>{const n=I(s.stage),u=a===s.id;return e.jsx("button",{type:"button",onClick:()=>t(s.id),className:b("absolute inset-y-[5px] rounded-[12px] border transition",u?"border-[var(--ui-border-strong)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)]"),style:{left:`${s.offsetRatio*100}%`,width:`${Math.max(s.widthRatio*100,1.8)}%`,background:n.strong},title:`${s.label} · ${p(s.durationSeconds)} · ${s.startedAt} - ${s.endedAt}`,children:s.widthRatio>.13?e.jsx("span",{className:"truncate px-2 text-[10px] font-medium text-[var(--ui-ink-on-accent)]",children:s.label}):null},s.id)})]})}function Ee({timeline:r,timeZone:a}){var l,i;const t=r.blocks.filter(c=>c.lane==="in_bed"),s=r.blocks.filter(c=>c.lane==="sleep"),n=((l=s[0])==null?void 0:l.id)??((i=t[0])==null?void 0:i.id)??null,[u,d]=g.useState(n);g.useEffect(()=>{d(n)},[n,r.startedAt,r.endedAt,r.totalSeconds]);const x=r.blocks.find(c=>c.id===u)??null;return r.hasRawSegments?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[t.length>0?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed window"}),e.jsx(H,{blocks:t,selectedBlockId:u,onSelect:d})]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r.hasSleepStageData?"Sleep phases":"Recorded sleep coverage"}),e.jsx(H,{blocks:s.length>0?s:t,selectedBlockId:u,onSelect:d})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:A(r.startedAt,a)}),e.jsx("span",{children:p(r.totalSeconds)}),e.jsx("span",{children:A(r.endedAt,a)})]}),x?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:b("text-sm font-medium",I(x.stage).text),children:x.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[A(x.startedAt,a)," -"," ",A(x.endedAt,a)]})]}),e.jsx(v,{tone:"meta",children:p(x.durationSeconds)})]})}):null]}):e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm text-[var(--ui-ink-muted)]",children:"Phase timing is unavailable for this night. Forge still keeps the canonical overnight summary, but the companion did not store segment-level timing."})}function Fe({latestNight:r}){return r?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"relative overflow-hidden px-6 py-6 sm:px-7 sm:py-7",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)]"}),e.jsxs("div",{className:"relative grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(v,{className:b("border-transparent",J(r.recoveryState)),children:r.qualitativeState}),e.jsx(v,{tone:"meta",children:r.sourceTimezone}),r.hasReflection?e.jsx(v,{tone:"meta",children:"Has reflection"}):null,r.hasRawSegments?e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Last night"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-x-4 gap-y-2",children:[e.jsx("div",{className:"text-[clamp(2.5rem,6vw,5rem)] font-medium leading-none text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsxs("div",{className:"pb-2 text-sm text-[var(--ui-ink-muted)]",children:["asleep across ",q(r.startedAt,r.endedAt,r.sourceTimezone)]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-medium)]",children:O(r.endedAt,r.sourceTimezone)}),r.qualitySummary?e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-medium)]",children:r.qualitySummary}):e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Canonical overnight summary computed from synced sleep segments, with raw evidence still available underneath."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Score"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.score??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Regularity"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.regularity??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(r.efficiency)})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Baseline"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Compared with recent nights"})]}),e.jsx(ae,{className:"size-5 text-[var(--primary)]"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"7-night average"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:p(r.weeklyAverageSleepSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Versus baseline"}),e.jsx("span",{className:b("text-sm",Ie(r.deltaFromWeeklyAverageSeconds)),children:Ae(r.deltaFromWeeklyAverageSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Bedtime drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.bedtimeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Wake drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.wakeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Restorative share"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:T(r.restorativeShare)})]})]})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{stages:r.stageBreakdown})})]})]})]})]})}):e.jsxs(w,{className:"overflow-hidden p-6",children:[e.jsx("div",{className:"text-sm uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep"}),e.jsx("div",{className:"mt-4 text-2xl text-[var(--ui-ink-strong)]",children:"No overnight sleep yet"}),e.jsx("div",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The sleep page will switch to a night-first summary once the companion syncs a canonical overnight session."})]})}function F({title:r,value:a,description:t}){return e.jsxs(w,{className:"h-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r}),e.jsx("div",{className:"mt-3 text-3xl text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:t})]})}function ze({days:r,selectedSleepId:a,onSelect:t}){const s=g.useMemo(()=>Array.from(new Set(r.map(l=>l.dateKey.slice(0,7)))).sort((l,i)=>l.localeCompare(i)),[r]),[n,u]=g.useState(s[s.length-1]??"");g.useEffect(()=>{if(s.length===0){u("");return}s.includes(n)||u(s[s.length-1]??"")},[n,s]);const d=s.indexOf(n),x=g.useMemo(()=>De(n,r),[r,n]);return n?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep calendar"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:Te(n)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d<=0,onClick:()=>u(s[Math.max(0,d-1)]??n),children:"Previous"}),e.jsx($,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d===-1||d>=s.length-1,onClick:()=>u(s[Math.min(s.length-1,d+1)]??n),children:"Next"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:_e.map(l=>e.jsx("div",{children:l},l))}),e.jsx("div",{className:"grid grid-cols-7 gap-2",children:x.map(l=>{const i=l.sleep,c=(i==null?void 0:i.sleepId)===a,y=i&&typeof i.score=="number"?i.score>=80?"var(--ui-success-soft)":i.score>=65?"var(--ui-info-soft)":"var(--ui-warning-soft)":"var(--ui-surface-2)";return e.jsxs("button",{type:"button",disabled:!i,"aria-pressed":c,"aria-label":`Select sleep for ${l.dateKey}`,onClick:()=>{i&&(u(i.dateKey.slice(0,7)),t(i.sleepId,i.dateKey.slice(0,7)))},className:b("min-h-[90px] rounded-[18px] border px-2 py-2 text-left transition",i?"border-[var(--ui-border-subtle)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",c&&"border-[var(--primary)] bg-[var(--primary)]/12",l.outsideMonth&&!i&&"opacity-35"),style:i?{background:y}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:b("text-sm",l.outsideMonth?"text-[var(--ui-ink-muted)]":"text-[var(--ui-ink-medium)]"),children:l.dayNumber}),i!=null&&i.hasReflection?e.jsx("span",{className:"size-2 rounded-full bg-[var(--success)]"}):null]}),i?e.jsxs("div",{className:"mt-4 grid gap-1",children:[e.jsxs("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:[i.sleepHours.toFixed(1),"h"]}),e.jsxs("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:[i.score??"n/a"," score"]}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:i.hasRawSegments?"phases available":"summary only"})]}):null]},l.dateKey)})})]})}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No canonical nights are available for the calendar yet."})}function z({active:r,children:a,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:b("rounded-full border px-4 py-2 text-sm transition",r?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:text-[var(--ui-ink-strong)]"),children:a})}function Le({session:r,draft:a,rawDetail:t,rawDetailLoading:s,pending:n,tab:u,linkOptions:d,onTabChange:x,onDraftChange:l,onSave:i}){const[c,y]=g.useState(null),k=g.useMemo(()=>Ke(t),[t]),C=typeof r.derived.efficiency=="number"?r.derived.efficiency:r.timeInBedSeconds>0?r.asleepSeconds/r.timeInBedSeconds:0,K=typeof r.derived.restorativeShare=="number"?r.derived.restorativeShare:0,R=typeof r.derived.recoveryState=="string"?r.derived.recoveryState:null;return e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",J(R)),children:R?R.replaceAll("_"," "):"Canonical night"}),e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}),e.jsx(v,{tone:"meta",children:r.sourceTimezone})]}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Selected night"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:O(r.endedAt,r.sourceTimezone)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:q(r.startedAt,r.endedAt,r.sourceTimezone)})]}),e.jsxs("div",{className:"grid gap-2 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Summary"}),e.jsx("div",{className:"text-3xl text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"asleep"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Awake"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.awakeSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(C)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Restorative"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(K)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{active:u==="summary",onClick:()=>x("summary"),children:"Summary"}),e.jsx(z,{active:u==="reflection",onClick:()=>x("reflection"),children:"Reflection"}),e.jsx(z,{active:u==="raw",onClick:()=>x("raw"),children:"Show raw data"})]}),u==="summary"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Phase timeline"}),e.jsx("div",{className:"mt-4",children:s?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-6 text-sm text-[var(--ui-ink-muted)]",children:"Loading phase timing from raw sleep segments…"}):e.jsx(Ee,{timeline:(t==null?void 0:t.phaseTimeline)??{startedAt:r.startedAt,endedAt:r.endedAt,totalSeconds:Math.max(0,Math.round((new Date(r.endedAt).getTime()-new Date(r.startedAt).getTime())/1e3)),hasRawSegments:!1,hasSleepStageData:!1,blocks:[]},timeZone:r.sourceTimezone})})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{stages:r.stageBreakdown})})]})]}):null,u==="reflection"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Quality summary"}),e.jsx(Q,{value:a.qualitySummary,onChange:o=>l({qualitySummary:o.target.value}),placeholder:"Recovered after a late evening, but sleep onset drifted."})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Night notes"}),e.jsx(ue,{className:"min-h-[200px]",value:a.notes,onChange:o=>l({notes:o.target.value}),placeholder:"What shaped this night, and what should we remember about it?"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Tags"}),e.jsx(Q,{value:a.tagsText,onChange:o=>l({tagsText:o.target.value}),placeholder:"travel, stress, good-routine, late-caffeine"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Linked context"}),e.jsx(ne,{options:d,selectedValues:a.linkValues,onChange:o=>l({linkValues:o}),placeholder:"Search goals, tasks, habits, beliefs, reports, or patterns…"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs($,{type:"button",pending:n,pendingLabel:"Saving",onClick:i,children:[e.jsx(te,{className:"size-4"}),"Save reflection"]})})]}):null,u==="raw"?e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Forge shows the canonical overnight session by default. This view reveals the evidence stack underneath it: raw provider or historical imported records first, then Forge-normalized sleep segments."}),s?e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Loading raw sleep evidence…"}):null,s?null:e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Be(k.rawDataStatus)),children:qe(k.rawDataStatus)}),k.rawDataStatus==="historical_raw"?e.jsx(v,{tone:"meta",children:"Partial evidence"}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw data"}),k.sourceRecords.length?k.sourceRecords.map(o=>e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",$e(o)),children:o.qualityKind==="provider_native"?"Provider raw":"Historical raw"}),e.jsx(v,{tone:"meta",className:"capitalize",children:o.rawStage.replaceAll("_"," ")}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--ui-ink-muted)]",children:o.providerRecordType.replaceAll("_"," ")}),e.jsx($,{type:"button",variant:"secondary",className:"h-8 rounded-full px-3",onClick:()=>y(M=>M===o.id?null:o.id),children:c===o.id?"Hide JSON":"See JSON"})]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))}),c===o.id?e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:JSON.stringify({payload:o.payload,metadata:o.metadata},null,2)}):null]},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No raw data was stored for this night."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep segments"}),k.segments.length?k.segments.map(o=>e.jsx("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:o.stage.replaceAll("_"," ")}),e.jsx(v,{tone:"meta",children:o.qualityKind==="provider_native"?"provider-backed":"historical"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))})]})},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No normalized sleep segments were stored for this night."})]})]})]}):null]})})}function tr(){var V;const r=de(),a=se(),[t,s]=g.useState({}),[n,u]=g.useState(null),[d,x]=g.useState("summary"),l=Array.isArray(r==null?void 0:r.selectedUserIds)?r.selectedUserIds:[],i=r==null?void 0:r.snapshot,c=_({queryKey:["forge-sleep",...l],queryFn:async()=>(await xe(l)).sleep}),y=_({queryKey:["forge-sleep-raw",n],enabled:!!n,queryFn:async()=>ve(n)}),k=_({queryKey:["forge-sleep-values",...l],queryFn:async()=>(await pe(l)).values}),C=_({queryKey:["forge-sleep-patterns",...l],queryFn:async()=>(await ge(l)).patterns}),K=_({queryKey:["forge-sleep-behaviors",...l],queryFn:async()=>(await he(l)).behaviors}),R=_({queryKey:["forge-sleep-beliefs",...l],queryFn:async()=>(await fe(l)).beliefs}),o=_({queryKey:["forge-sleep-reports",...l],queryFn:async()=>(await be(l)).reports});g.useEffect(()=>{c.data&&s(Object.fromEntries(c.data.sessions.map(m=>[m.id,B(m)])))},[c.data]),g.useEffect(()=>{var N,j,S;if(!((N=c.data)!=null&&N.sessions.length)){u(null);return}c.data.sessions.some(E=>E.id===n)||u(((j=c.data.latestNight)==null?void 0:j.sleepId)??((S=c.data.sessions[0])==null?void 0:S.id)??null)},[n,c.data]),g.useEffect(()=>{x("summary")},[n]);const M=ie({mutationFn:async m=>me(m.sleepId,{qualitySummary:m.qualitySummary,notes:m.notes,tags:m.tagsText.split(",").map(N=>N.trim()).filter(Boolean),links:Se(m.linkValues)}),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-sleep"]}),await a.invalidateQueries({queryKey:["forge-sleep-raw"]})}});if(c.isLoading)return e.jsx(le,{eyebrow:"Sleep",title:"Loading sleep surface",description:"Reading canonical nights, calendar summaries, and sleep phase detail.",columns:2,blocks:6});if(c.isError||!c.data)return e.jsx(ce,{eyebrow:"Sleep",error:c.error??new Error("Sleep data unavailable"),onRetry:()=>void c.refetch()});const h=c.data,D=h.sessions,L=new Map(D.map(m=>[m.id,m])),f=(n?L.get(n):null)??(h.latestNight?L.get(h.latestNight.sleepId):null)??D[0]??null,P=f?t[f.id]??B(f):null,Y=we({goals:(i==null?void 0:i.dashboard.goals)??[],projects:(i==null?void 0:i.dashboard.projects)??[],tasks:(i==null?void 0:i.dashboard.tasks)??[],habits:(i==null?void 0:i.dashboard.habits)??[],values:k.data??[],patterns:C.data??[],behaviors:K.data??[],beliefs:R.data??[],reports:o.data??[]});function X(m,N){s(j=>{const S=D.find(ee=>ee.id===m),E=j[m]??(S?B(S):{qualitySummary:"",notes:"",tagsText:"",linkValues:[]});return{...j,[m]:{...E,...N}}})}async function Z(m){const N=D.find(S=>S.id===m);if(!N)return;const j=t[m]??B(N);await M.mutateAsync({sleepId:m,qualitySummary:j.qualitySummary,notes:j.notes,tagsText:j.tagsText,linkValues:j.linkValues})}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(je,{eyebrow:"Health",title:"Sleep",description:"Canonical overnight sessions first, with last-night recovery, a clickable night calendar, and raw segment evidence only when you ask for it.",badge:`${D.length} nights`}),e.jsx(oe,{}),e.jsx(ye,{children:e.jsx(Fe,{latestNight:h.latestNight})}),e.jsx(ke,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[e.jsx(F,{title:"Weekly average",value:p(h.summary.averageSleepSeconds),description:"Average overnight sleep duration across the recent week, used as the baseline for the latest-night comparison."}),e.jsx(F,{title:"Regularity",value:`${h.summary.averageRegularityScore}`,description:`Average bedtime drift ${h.summary.averageBedtimeConsistencyMinutes}m and wake drift ${h.summary.averageWakeConsistencyMinutes}m.`}),e.jsx(F,{title:"Restorative share",value:T(h.summary.averageRestorativeShare),description:`Deep + REM share across recent nights, with ${h.summary.reflectiveNightCount} nights already carrying context.`}),e.jsxs(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent stage mix"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:"Average nightly phases"})]}),e.jsx(re,{className:"size-5 text-[var(--primary)]"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:h.stageAverages.length>0?h.stageAverages.slice(0,5).map(m=>e.jsxs(v,{tone:"meta",children:[I(m.stage).label," ",p(m.averageSeconds)]},m.stage)):e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Stage averages will appear once nights include phase data."})})]})]})}),e.jsx(Ne,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(ze,{days:h.calendarDays,selectedSleepId:(f==null?void 0:f.id)??null,onSelect:m=>u(m)}),f&&P?e.jsx(Le,{session:f,draft:P,rawDetail:y.data??null,rawDetailLoading:y.isLoading,pending:M.isPending&&((V=M.variables)==null?void 0:V.sleepId)===f.id,tab:d,linkOptions:Y,onTabChange:x,onDraftChange:m=>X(f.id,m),onSave:()=>void Z(f.id)}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-6 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Pick a night from the calendar to inspect its phase timing, stage summary, and reflection context."})]})})]})}export{tr as SleepPage};
|
|
1
|
+
import{r as g,j as e,aV as re,ck as ae,cm as te}from"./vendor-BwL6m4SE.js";import{j as se,i as _,k as ie}from"./state-Bpe5dF3T.js";import{E as ne}from"./entity-link-multiselect-Do5DTju7.js";import{d as de,S as le,e as ce,bs as oe,C as w,k as v,c as b,B as $,I as Q,T as ue,d$ as me,bd as xe,e0 as ve,b3 as pe,b4 as ge,b5 as he,b6 as fe,b9 as be}from"./index-DGYIFHgo.js";import{P as je}from"./page-hero-BkrRTu-t.js";import{S as ye,a as ke,b as Ne}from"./health-boxes-CeqSGyZ3.js";import{b as we,p as Se}from"./health-link-options-Cpx8w7uM.js";import"./use-anchored-overlay-position-BY4kNzPj.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.js";import"./generic-node-view-CgLkbts-.js";import"./graph-BF4IsheG.js";import"./define-workbench-box-DWAqqjvH.js";const _e=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"],W={awake:{label:"Awake",strong:"var(--warning)",soft:"var(--ui-warning-soft)",text:"text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"},core:{label:"Core",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"},deep:{label:"Deep",strong:"var(--success)",soft:"var(--ui-success-soft)",text:"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"},rem:{label:"REM",strong:"var(--info)",soft:"var(--ui-info-soft)",text:"text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"},in_bed:{label:"In bed",strong:"color-mix(in_srgb,var(--ui-ink-strong)_46%,transparent)",soft:"var(--ui-surface-3)",text:"text-[var(--ui-ink-medium)]"},asleep_unspecified:{label:"Asleep",strong:"var(--primary)",soft:"var(--ui-accent-soft)",text:"text-[color-mix(in_srgb,var(--primary)_78%,var(--ui-ink-strong)_22%)]"}};function I(r){return W[r]??W.asleep_unspecified}function p(r){if(r<=0)return"0m";const a=Math.floor(r/3600),t=Math.round(r%3600/60);return a===0?`${t}m`:t===0?`${a}h`:`${a}h ${t}m`}function Ae(r){const a=Math.round(r/60);return a===0?"on baseline":`${a>0?"+":"-"}${Math.abs(a)}m`}function T(r){return`${Math.round(r*100)}%`}function A(r,a){return r?new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit",timeZone:a}).format(new Date(r)):"n/a"}function O(r,a){return new Intl.DateTimeFormat(void 0,{weekday:"long",day:"numeric",month:"long",timeZone:a}).format(new Date(r))}function q(r,a,t){return`${A(r,t)} - ${A(a,t)}`}function Te(r){const[a,t]=r.split("-").map(Number);return new Intl.DateTimeFormat(void 0,{month:"long",year:"numeric"}).format(new Date(a,(t??1)-1,1))}function U(r){const a=new Date(r),t=(r.getDay()+6)%7;return a.setDate(r.getDate()-t),a}function Re(r){const a=U(r);return a.setDate(a.getDate()+6),a}function Me(r){const a=r.getFullYear(),t=`${r.getMonth()+1}`.padStart(2,"0"),s=`${r.getDate()}`.padStart(2,"0");return`${a}-${t}-${s}`}function B(r){return{qualitySummary:typeof r.annotations.qualitySummary=="string"?r.annotations.qualitySummary:"",notes:typeof r.annotations.notes=="string"?r.annotations.notes:"",tagsText:Array.isArray(r.annotations.tags)?r.annotations.tags.join(", "):"",linkValues:Array.isArray(r.links)?r.links.map(a=>`${a.entityType}:${a.entityId}`):[]}}function De(r,a){if(!r)return[];const[t,s]=r.split("-").map(Number),n=new Date(t,(s??1)-1,1),u=new Date(t,s??1,0),d=U(n),x=Re(u),l=new Map(a.map(c=>[c.dateKey,c])),i=[];for(const c=new Date(d);c<=x;c.setDate(c.getDate()+1)){const y=Me(c);i.push({dateKey:y,dayNumber:c.getDate(),outsideMonth:c.getMonth()!==n.getMonth(),sleep:l.get(y)??null})}return i}function Ie(r){return r>0?"text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r<0?"text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"text-[var(--ui-ink-medium)]"}function J(r){return r==="recharged"||r==="recovered"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="steady"||r==="stable"?"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]":r==="fragile"||r==="strained"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":r==="depleted"?"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function Be(r){return r==="provider_raw"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":r==="historical_raw"?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-surface-3)] text-[var(--ui-ink-medium)]"}function qe(r){return r==="provider_raw"?"Provider raw data":r==="historical_raw"?"Historical raw data":"Raw data unavailable"}function $e(r){return r.qualityKind==="provider_native"?"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]":"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}function Ce(r,a){const t=r.stage;if(typeof t=="string"&&t.trim().length>0)return t;const s=r.sourceType;if(typeof s=="string"&&s.trim().length>0)return s;const n=r.stageBreakdown;if(Array.isArray(n)&&n.length>0){const u=n[0];if(u&&typeof u=="object"&&typeof u.stage=="string")return(u.stage||"asleep_unspecified").trim()}return a.includes("awake")?"awake":"asleep_unspecified"}function Ke(r){const a=r,t=(a==null?void 0:a.segments)??(a==null?void 0:a.rawSegments)??[],s=(a==null?void 0:a.auditLogs)??(a==null?void 0:a.rawLogs)??[],n=a!=null&&a.sourceRecords&&a.sourceRecords.length>0?a.sourceRecords:s.filter(d=>typeof d.startedAt=="string"&&typeof d.endedAt=="string").map(d=>({id:d.id,importRunId:d.importRunId,pairingSessionId:d.pairingSessionId,sleepSessionId:d.sleepSessionId,userId:d.userId,provider:d.source,providerRecordType:d.logType,providerRecordUid:d.externalUid??d.id,sourceDevice:"",sourceTimezone:d.sourceTimezone,localDateKey:d.localDateKey,startedAt:d.startedAt,endedAt:d.endedAt,rawStage:Ce(d.payload,d.logType),rawValue:null,qualityKind:"historical_import",payload:d.payload,metadata:d.metadata,ingestedAt:d.createdAt})),u=(a==null?void 0:a.rawDataStatus)??(n.length>0?"historical_raw":"raw_unavailable");return{sourceRecords:n,segments:t,auditLogs:s,rawDataStatus:u}}function G({stages:r}){const a=r.reduce((t,s)=>t+s.seconds,0);return r.length===0||a===0?e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No stage composition was stored for this night yet."}):e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"flex h-3 overflow-hidden rounded-full bg-[var(--ui-surface-2)]",children:r.map(t=>{const s=I(t.stage);return e.jsx("div",{className:"h-full",style:{width:`${Math.max(4,t.seconds/a*100)}%`,background:s.strong},title:`${s.label} · ${p(t.seconds)}`},t.stage)})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-2 xl:grid-cols-4",children:r.map(t=>{const s=I(t.stage),n="percentage"in t&&typeof t.percentage=="number"?t.percentage:a>0?t.seconds/a:0;return e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] px-3 py-3",style:{background:s.soft},children:[e.jsx("div",{className:b("text-sm font-medium",s.text),children:s.label}),e.jsx("div",{className:"mt-1 text-lg text-[var(--ui-ink-strong)]",children:p(t.seconds)}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:T(n)})]},t.stage)})})]})}function H({blocks:r,selectedBlockId:a,onSelect:t}){return e.jsxs("div",{className:"relative h-12 overflow-hidden rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)] bg-[length:25%_100%]"}),r.map(s=>{const n=I(s.stage),u=a===s.id;return e.jsx("button",{type:"button",onClick:()=>t(s.id),className:b("absolute inset-y-[5px] rounded-[12px] border transition",u?"border-[var(--ui-border-strong)] shadow-[var(--ui-shadow-soft)]":"border-[var(--ui-border-subtle)]"),style:{left:`${s.offsetRatio*100}%`,width:`${Math.max(s.widthRatio*100,1.8)}%`,background:n.strong},title:`${s.label} · ${p(s.durationSeconds)} · ${s.startedAt} - ${s.endedAt}`,children:s.widthRatio>.13?e.jsx("span",{className:"truncate px-2 text-[10px] font-medium text-[var(--ui-ink-on-accent)]",children:s.label}):null},s.id)})]})}function Ee({timeline:r,timeZone:a}){var l,i;const t=r.blocks.filter(c=>c.lane==="in_bed"),s=r.blocks.filter(c=>c.lane==="sleep"),n=((l=s[0])==null?void 0:l.id)??((i=t[0])==null?void 0:i.id)??null,[u,d]=g.useState(n);g.useEffect(()=>{d(n)},[n,r.startedAt,r.endedAt,r.totalSeconds]);const x=r.blocks.find(c=>c.id===u)??null;return r.hasRawSegments?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"grid gap-3",children:[t.length>0?e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed window"}),e.jsx(H,{blocks:t,selectedBlockId:u,onSelect:d})]}):null,e.jsxs("div",{className:"grid gap-2",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r.hasSleepStageData?"Sleep phases":"Recorded sleep coverage"}),e.jsx(H,{blocks:s.length>0?s:t,selectedBlockId:u,onSelect:d})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 text-xs text-[var(--ui-ink-muted)]",children:[e.jsx("span",{children:A(r.startedAt,a)}),e.jsx("span",{children:p(r.totalSeconds)}),e.jsx("span",{children:A(r.endedAt,a)})]}),x?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:b("text-sm font-medium",I(x.stage).text),children:x.label}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-muted)]",children:[A(x.startedAt,a)," -"," ",A(x.endedAt,a)]})]}),e.jsx(v,{tone:"meta",children:p(x.durationSeconds)})]})}):null]}):e.jsx("div",{className:"rounded-[18px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-5 text-sm text-[var(--ui-ink-muted)]",children:"Phase timing is unavailable for this night. Forge still keeps the canonical overnight summary, but the companion did not store segment-level timing."})}function Fe({latestNight:r}){return r?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"relative overflow-hidden px-6 py-6 sm:px-7 sm:py-7",children:[e.jsx("div",{className:"pointer-events-none absolute inset-0 bg-[image:var(--ui-surface-section)]"}),e.jsxs("div",{className:"relative grid gap-6 xl:grid-cols-[minmax(0,1.2fr)_minmax(0,0.8fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsx(v,{className:b("border-transparent",J(r.recoveryState)),children:r.qualitativeState}),e.jsx(v,{tone:"meta",children:r.sourceTimezone}),r.hasReflection?e.jsx(v,{tone:"meta",children:"Has reflection"}):null,r.hasRawSegments?e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}):null]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.2em] text-[var(--ui-ink-muted)]",children:"Last night"}),e.jsxs("div",{className:"mt-3 flex flex-wrap items-end gap-x-4 gap-y-2",children:[e.jsx("div",{className:"text-[clamp(2.5rem,6vw,5rem)] font-medium leading-none text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsxs("div",{className:"pb-2 text-sm text-[var(--ui-ink-muted)]",children:["asleep across ",q(r.startedAt,r.endedAt,r.sourceTimezone)]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-medium)]",children:O(r.endedAt,r.sourceTimezone)}),r.qualitySummary?e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-medium)]",children:r.qualitySummary}):e.jsx("div",{className:"mt-4 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Canonical overnight summary computed from synced sleep segments, with raw evidence still available underneath."})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Score"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.score??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Regularity"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:r.regularity??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(r.efficiency)})]})]})]}),e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Baseline"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Compared with recent nights"})]}),e.jsx(ae,{className:"size-5 text-[var(--primary)]"})]}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"7-night average"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:p(r.weeklyAverageSleepSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Versus baseline"}),e.jsx("span",{className:b("text-sm",Ie(r.deltaFromWeeklyAverageSeconds)),children:Ae(r.deltaFromWeeklyAverageSeconds)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Bedtime drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.bedtimeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Wake drift"}),e.jsxs("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:[r.wakeDriftMinutes??0,"m"]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[16px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:"Restorative share"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-strong)]",children:T(r.restorativeShare)})]})]})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-5",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{stages:r.stageBreakdown})})]})]})]})]})}):e.jsxs(w,{className:"overflow-hidden p-6",children:[e.jsx("div",{className:"text-sm uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep"}),e.jsx("div",{className:"mt-4 text-2xl text-[var(--ui-ink-strong)]",children:"No overnight sleep yet"}),e.jsx("div",{className:"mt-3 max-w-2xl text-sm leading-6 text-[var(--ui-ink-muted)]",children:"The sleep page will switch to a night-first summary once the companion syncs a canonical overnight session."})]})}function F({title:r,value:a,description:t}){return e.jsxs(w,{className:"h-full border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:r}),e.jsx("div",{className:"mt-3 text-3xl text-[var(--ui-ink-strong)]",children:a}),e.jsx("div",{className:"mt-3 text-sm leading-6 text-[var(--ui-ink-muted)]",children:t})]})}function ze({days:r,selectedSleepId:a,onSelect:t}){const s=g.useMemo(()=>Array.from(new Set(r.map(l=>l.dateKey.slice(0,7)))).sort((l,i)=>l.localeCompare(i)),[r]),[n,u]=g.useState(s[s.length-1]??"");g.useEffect(()=>{if(s.length===0){u("");return}s.includes(n)||u(s[s.length-1]??"")},[n,s]);const d=s.indexOf(n),x=g.useMemo(()=>De(n,r),[r,n]);return n?e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep calendar"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:Te(n)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d<=0,onClick:()=>u(s[Math.max(0,d-1)]??n),children:"Previous"}),e.jsx($,{type:"button",variant:"secondary",className:"h-9 rounded-full",disabled:d===-1||d>=s.length-1,onClick:()=>u(s[Math.min(s.length-1,d+1)]??n),children:"Next"})]})]}),e.jsx("div",{className:"grid grid-cols-7 gap-2 text-center text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-muted)]",children:_e.map(l=>e.jsx("div",{children:l},l))}),e.jsx("div",{className:"grid grid-cols-7 gap-2",children:x.map(l=>{const i=l.sleep,c=(i==null?void 0:i.sleepId)===a,y=i&&typeof i.score=="number"?i.score>=80?"var(--ui-success-soft)":i.score>=65?"var(--ui-info-soft)":"var(--ui-warning-soft)":"var(--ui-surface-2)";return e.jsxs("button",{type:"button",disabled:!i,"aria-pressed":c,"aria-label":`Select sleep for ${l.dateKey}`,onClick:()=>{i&&(u(i.dateKey.slice(0,7)),t(i.sleepId,i.dateKey.slice(0,7)))},className:b("min-h-[90px] rounded-[18px] border px-2 py-2 text-left transition",i?"border-[var(--ui-border-subtle)] hover:border-[var(--ui-border-strong)] hover:bg-[var(--ui-surface-3)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",c&&"border-[var(--primary)] bg-[var(--primary)]/12",l.outsideMonth&&!i&&"opacity-35"),style:i?{background:y}:void 0,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsx("span",{className:b("text-sm",l.outsideMonth?"text-[var(--ui-ink-muted)]":"text-[var(--ui-ink-medium)]"),children:l.dayNumber}),i!=null&&i.hasReflection?e.jsx("span",{className:"size-2 rounded-full bg-[var(--success)]"}):null]}),i?e.jsxs("div",{className:"mt-4 grid gap-1",children:[e.jsxs("div",{className:"text-lg text-[var(--ui-ink-strong)]",children:[i.sleepHours.toFixed(1),"h"]}),e.jsxs("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:[i.score??"n/a"," score"]}),e.jsx("div",{className:"text-xs text-[var(--ui-ink-muted)]",children:i.hasRawSegments?"phases available":"summary only"})]}):null]},l.dateKey)})})]})}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-5 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"No canonical nights are available for the calendar yet."})}function z({active:r,children:a,onClick:t}){return e.jsx("button",{type:"button",onClick:t,className:b("rounded-full border px-4 py-2 text-sm transition",r?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)] hover:text-[var(--ui-ink-strong)]"),children:a})}function Le({session:r,draft:a,rawDetail:t,rawDetailLoading:s,pending:n,tab:u,linkOptions:d,onTabChange:x,onDraftChange:l,onSave:i}){const[c,y]=g.useState(null),k=g.useMemo(()=>Ke(t),[t]),C=typeof r.derived.efficiency=="number"?r.derived.efficiency:r.timeInBedSeconds>0?r.asleepSeconds/r.timeInBedSeconds:0,K=typeof r.derived.restorativeShare=="number"?r.derived.restorativeShare:0,R=typeof r.derived.recoveryState=="string"?r.derived.recoveryState:null;return e.jsx(w,{className:"overflow-hidden border-[var(--ui-border-subtle)] bg-[image:var(--ui-surface-section)] p-0",children:e.jsxs("div",{className:"grid gap-5 px-5 py-5",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",J(R)),children:R?R.replaceAll("_"," "):"Canonical night"}),e.jsxs(v,{tone:"meta",children:[r.rawSegmentCount," raw segments"]}),e.jsx(v,{tone:"meta",children:r.sourceTimezone})]}),e.jsx("div",{className:"mt-3 text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Selected night"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:O(r.endedAt,r.sourceTimezone)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-muted)]",children:q(r.startedAt,r.endedAt,r.sourceTimezone)})]}),e.jsxs("div",{className:"grid gap-2 text-right",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Summary"}),e.jsx("div",{className:"text-3xl text-[var(--ui-ink-strong)]",children:p(r.asleepSeconds)}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"asleep"})]})]}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"In bed"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.timeInBedSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Awake"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:p(r.awakeSeconds)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Efficiency"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(C)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Restorative"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:T(K)})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(z,{active:u==="summary",onClick:()=>x("summary"),children:"Summary"}),e.jsx(z,{active:u==="reflection",onClick:()=>x("reflection"),children:"Reflection"}),e.jsx(z,{active:u==="raw",onClick:()=>x("raw"),children:"Show raw data"})]}),u==="summary"?e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Phase timeline"}),e.jsx("div",{className:"mt-4",children:s?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-6 text-sm text-[var(--ui-ink-muted)]",children:"Loading phase timing from raw sleep segments…"}):e.jsx(Ee,{timeline:(t==null?void 0:t.phaseTimeline)??{startedAt:r.startedAt,endedAt:r.endedAt,totalSeconds:Math.max(0,Math.round((new Date(r.endedAt).getTime()-new Date(r.startedAt).getTime())/1e3)),hasRawSegments:!1,hasSleepStageData:!1,blocks:[]},timeZone:r.sourceTimezone})})]}),e.jsxs("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Stage composition"}),e.jsx("div",{className:"mt-4",children:e.jsx(G,{stages:r.stageBreakdown})})]})]}):null,u==="reflection"?e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Quality summary"}),e.jsx(Q,{value:a.qualitySummary,onChange:o=>l({qualitySummary:o.target.value}),placeholder:"Recovered after a late evening, but sleep onset drifted."})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Night notes"}),e.jsx(ue,{className:"min-h-[200px]",value:a.notes,onChange:o=>l({notes:o.target.value}),placeholder:"What shaped this night, and what should we remember about it?"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Tags"}),e.jsx(Q,{value:a.tagsText,onChange:o=>l({tagsText:o.target.value}),placeholder:"travel, stress, good-routine, late-caffeine"})]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Linked context"}),e.jsx(ne,{options:d,selectedValues:a.linkValues,onChange:o=>l({linkValues:o}),placeholder:"Search goals, tasks, habits, beliefs, reports, or patterns…"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs($,{type:"button",pending:n,pendingLabel:"Saving",onClick:i,children:[e.jsx(te,{className:"size-4"}),"Save reflection"]})})]}):null,u==="raw"?e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Forge shows the canonical overnight session by default. This view reveals the evidence stack underneath it: raw provider or historical imported records first, then Forge-normalized sleep segments."}),s?e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Loading raw sleep evidence…"}):null,s?null:e.jsxs("div",{className:"grid gap-5",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",Be(k.rawDataStatus)),children:qe(k.rawDataStatus)}),k.rawDataStatus==="historical_raw"?e.jsx(v,{tone:"meta",children:"Partial evidence"}):null]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Raw data"}),k.sourceRecords.length?k.sourceRecords.map(o=>e.jsxs("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{className:b("border-transparent",$e(o)),children:o.qualityKind==="provider_native"?"Provider raw":"Historical raw"}),e.jsx(v,{tone:"meta",className:"capitalize",children:o.rawStage.replaceAll("_"," ")}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-xs text-[var(--ui-ink-muted)]",children:o.providerRecordType.replaceAll("_"," ")}),e.jsx($,{type:"button",variant:"secondary",className:"h-8 rounded-full px-3",onClick:()=>y(M=>M===o.id?null:o.id),children:c===o.id?"Hide JSON":"See JSON"})]})]}),e.jsx("div",{className:"mt-3 text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))}),c===o.id?e.jsx("pre",{className:"mt-3 overflow-x-auto rounded-[14px] border border-[var(--ui-border-subtle)] bg-[var(--ui-code-bg)] p-3 text-xs leading-6 text-[var(--ui-ink-medium)]",children:JSON.stringify({payload:o.payload,metadata:o.metadata},null,2)}):null]},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No raw data was stored for this night."})]}),e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Sleep segments"}),k.segments.length?k.segments.map(o=>e.jsx("div",{className:"rounded-[16px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-3",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(v,{tone:"meta",className:"capitalize",children:o.stage.replaceAll("_"," ")}),e.jsx(v,{tone:"meta",children:o.qualityKind==="provider_native"?"provider-backed":"historical"}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-medium)]",children:q(o.startedAt,o.endedAt,o.sourceTimezone)})]}),e.jsx("span",{className:"text-sm text-[var(--ui-ink-muted)]",children:p(Math.max(0,Math.round((new Date(o.endedAt).getTime()-new Date(o.startedAt).getTime())/1e3)))})]})},o.id)):e.jsx("div",{className:"rounded-[16px] border border-dashed border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-4 py-4 text-sm text-[var(--ui-ink-muted)]",children:"No normalized sleep segments were stored for this night."})]})]})]}):null]})})}function tr(){var V;const r=de(),a=se(),[t,s]=g.useState({}),[n,u]=g.useState(null),[d,x]=g.useState("summary"),l=Array.isArray(r==null?void 0:r.selectedUserIds)?r.selectedUserIds:[],i=r==null?void 0:r.snapshot,c=_({queryKey:["forge-sleep",...l],queryFn:async()=>(await xe(l)).sleep}),y=_({queryKey:["forge-sleep-raw",n],enabled:!!n,queryFn:async()=>ve(n)}),k=_({queryKey:["forge-sleep-values",...l],queryFn:async()=>(await pe(l)).values}),C=_({queryKey:["forge-sleep-patterns",...l],queryFn:async()=>(await ge(l)).patterns}),K=_({queryKey:["forge-sleep-behaviors",...l],queryFn:async()=>(await he(l)).behaviors}),R=_({queryKey:["forge-sleep-beliefs",...l],queryFn:async()=>(await fe(l)).beliefs}),o=_({queryKey:["forge-sleep-reports",...l],queryFn:async()=>(await be(l)).reports});g.useEffect(()=>{c.data&&s(Object.fromEntries(c.data.sessions.map(m=>[m.id,B(m)])))},[c.data]),g.useEffect(()=>{var N,j,S;if(!((N=c.data)!=null&&N.sessions.length)){u(null);return}c.data.sessions.some(E=>E.id===n)||u(((j=c.data.latestNight)==null?void 0:j.sleepId)??((S=c.data.sessions[0])==null?void 0:S.id)??null)},[n,c.data]),g.useEffect(()=>{x("summary")},[n]);const M=ie({mutationFn:async m=>me(m.sleepId,{qualitySummary:m.qualitySummary,notes:m.notes,tags:m.tagsText.split(",").map(N=>N.trim()).filter(Boolean),links:Se(m.linkValues)}),onSuccess:async()=>{await a.invalidateQueries({queryKey:["forge-sleep"]}),await a.invalidateQueries({queryKey:["forge-sleep-raw"]})}});if(c.isLoading)return e.jsx(le,{eyebrow:"Sleep",title:"Loading sleep surface",description:"Reading canonical nights, calendar summaries, and sleep phase detail.",columns:2,blocks:6});if(c.isError||!c.data)return e.jsx(ce,{eyebrow:"Sleep",error:c.error??new Error("Sleep data unavailable"),onRetry:()=>void c.refetch()});const h=c.data,D=h.sessions,L=new Map(D.map(m=>[m.id,m])),f=(n?L.get(n):null)??(h.latestNight?L.get(h.latestNight.sleepId):null)??D[0]??null,P=f?t[f.id]??B(f):null,Y=we({goals:(i==null?void 0:i.dashboard.goals)??[],projects:(i==null?void 0:i.dashboard.projects)??[],tasks:(i==null?void 0:i.dashboard.tasks)??[],habits:(i==null?void 0:i.dashboard.habits)??[],values:k.data??[],patterns:C.data??[],behaviors:K.data??[],beliefs:R.data??[],reports:o.data??[]});function X(m,N){s(j=>{const S=D.find(ee=>ee.id===m),E=j[m]??(S?B(S):{qualitySummary:"",notes:"",tagsText:"",linkValues:[]});return{...j,[m]:{...E,...N}}})}async function Z(m){const N=D.find(S=>S.id===m);if(!N)return;const j=t[m]??B(N);await M.mutateAsync({sleepId:m,qualitySummary:j.qualitySummary,notes:j.notes,tagsText:j.tagsText,linkValues:j.linkValues})}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(je,{eyebrow:"Health",title:"Sleep",description:"Canonical overnight sessions first, with last-night recovery, a clickable night calendar, and raw segment evidence only when you ask for it.",badge:`${D.length} nights`}),e.jsx(oe,{}),e.jsx(ye,{children:e.jsx(Fe,{latestNight:h.latestNight})}),e.jsx(ke,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.95fr)_minmax(0,1.05fr)]",children:[e.jsx(F,{title:"Weekly average",value:p(h.summary.averageSleepSeconds),description:"Average overnight sleep duration across the recent week, used as the baseline for the latest-night comparison."}),e.jsx(F,{title:"Regularity",value:`${h.summary.averageRegularityScore}`,description:`Average bedtime drift ${h.summary.averageBedtimeConsistencyMinutes}m and wake drift ${h.summary.averageWakeConsistencyMinutes}m.`}),e.jsx(F,{title:"Restorative share",value:T(h.summary.averageRestorativeShare),description:`Deep + REM share across recent nights, with ${h.summary.reflectiveNightCount} nights already carrying context.`}),e.jsxs(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-muted)]",children:"Recent stage mix"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:"Average nightly phases"})]}),e.jsx(re,{className:"size-5 text-[var(--primary)]"})]}),e.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:h.stageAverages.length>0?h.stageAverages.slice(0,5).map(m=>e.jsxs(v,{tone:"meta",children:[I(m.stage).label," ",p(m.averageSeconds)]},m.stage)):e.jsx("div",{className:"text-sm text-[var(--ui-ink-muted)]",children:"Stage averages will appear once nights include phase data."})})]})]})}),e.jsx(Ne,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(ze,{days:h.calendarDays,selectedSleepId:(f==null?void 0:f.id)??null,onSelect:m=>u(m)}),f&&P?e.jsx(Le,{session:f,draft:P,rawDetail:y.data??null,rawDetailLoading:y.isLoading,pending:M.isPending&&((V=M.variables)==null?void 0:V.sleepId)===f.id,tab:d,linkOptions:Y,onTabChange:x,onDraftChange:m=>X(f.id,m),onSave:()=>void Z(f.id)}):e.jsx(w,{className:"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] px-6 py-8 text-sm leading-6 text-[var(--ui-ink-muted)]",children:"Pick a night from the calendar to inspect its phase timing, stage summary, and reflection context."})]})})]})}export{tr as SleepPage};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as p,j as e,aC as Pe,bq as we,aV as qe,bW as Se,bs as Qe,cm as Ze}from"./vendor-Cpmju3nw.js";import{j as Ue,i as W,k as Ge}from"./state-BtwEvpO6.js";import{E as Ye}from"./entity-link-multiselect-Bb4De_e3.js";import{F as je}from"./faceted-token-search-DJPRm9AY.js";import{d as Xe,S as Je,e as et,C as g,k as c,I as H,aA as tt,T as at,B as ie,e1 as st,be as rt,b3 as it,b4 as nt,b5 as lt,b6 as ot,b9 as dt}from"./index-BaiwtAgo.js";import{P as ct}from"./page-hero-C0MpI3MM.js";import{c as ut,d as J,e as xt}from"./health-boxes-Ie3horXx.js";import{f as mt}from"./date-keys-Cj1G3TOn.js";import{b as pt,p as ht}from"./health-link-options-Cpx8w7uM.js";import{R as P,A as vt,C as ee,X as q,Y as K,T as Q,a as ke,e as ye,B as ne,f as gt,d as ft,g as bt,c as le,S as jt,h as kt}from"./charts-DwTguE_x.js";import"./use-anchored-overlay-position-BrQ4cqKn.js";import"./motion-DwjmC9aq.js";import"./ui-B9O-eUim.js";import"./board-CLOHbg6t.js";import"./forms-C5d5hTf2.js";import"./generic-node-view-p5ePSFuG.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-5h-dyvJY.js";function Z({className:t,children:r}){const s=p.useRef(null),[l,o]=p.useState(!1);return p.useEffect(()=>{const h=()=>{const b=s.current;o(!!(b&&b.clientWidth>0&&b.clientHeight>0))},f=window.requestAnimationFrame(h),j=typeof ResizeObserver>"u"?null:new ResizeObserver(h);return s.current&&j&&j.observe(s.current),window.addEventListener("resize",h),()=>{window.cancelAnimationFrame(f),j==null||j.disconnect(),window.removeEventListener("resize",h)}},[]),e.jsx("div",{ref:s,className:t,children:l?r:null})}const G={below_z1:"#94a3b8",zone_1:"#38bdf8",zone_2:"#22c55e",zone_3:"#eab308",zone_4:"#f97316",zone_5:"#ef4444"},V=["below_z1","zone_1","zone_2","zone_3","zone_4","zone_5"];function z(t){return t?t.replace(/^activity_/i,"").replaceAll("_"," ").replace(/\s+/g," ").replace(/\b\w/g,r=>r.toUpperCase()):"Unknown"}function B(t){return`${Math.round(t/60)}m`}function de(t){return t?`${(t/1e3).toFixed(1)} km`:"n/a"}function Y(t,r){const s=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}),l=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${s.format(new Date(t))} · ${l.format(new Date(t))} - ${l.format(new Date(r))}`}function ae(t){return mt(new Date(t))}function U(t){return{subjectiveEffort:t.subjectiveEffort!==null?String(t.subjectiveEffort):"",moodBefore:t.moodBefore??"",moodAfter:t.moodAfter??"",meaningText:t.meaningText??"",plannedContext:t.plannedContext??"",socialContext:t.socialContext??"",tagsText:Array.isArray(t.tags)?t.tags.join(", "):"",linkValues:Array.isArray(t.links)?t.links.map(r=>`${r.entityType}:${r.entityId}`):[]}}function Ae(t){return t.trim().toLowerCase()}function k(t){var r;return((r=t.workoutTypeLabel)==null?void 0:r.trim())||z(t.workoutType)}function _(t){var r;return((r=t.activityFamilyLabel)==null?void 0:r.trim())||z(t.activityFamily)}function Ce(t){return z(t.sourceSystem??t.source)}function yt(t){return t==null?"n/a":typeof t=="boolean"?t?"Yes":"No":typeof t=="number"?Number.isInteger(t)?String(t):t.toFixed(1):t}function Nt(t){const r=yt(t.value);return!t.unit||t.unit==="count"?r:`${r} ${t.unit}`}function wt(t,r){return Ae([t.workoutType,k(t),t.activityFamily,_(t),t.sourceSystem,Ce(t),t.sourceType,t.sourceDevice,t.reconciliationStatus,t.moodBefore,t.moodAfter,t.meaningText,t.plannedContext,t.socialContext,t.tags.join(" "),r.moodBefore,r.moodAfter,r.meaningText,r.plannedContext,r.socialContext,r.tagsText,Y(t.startedAt,t.endedAt)].join(" "))}function St(t){const r=new Map;for(const s of t)r.set(`workout:${s.workoutType}`,{id:`workout:${s.workoutType}`,label:k(s),description:"Workout type",searchText:`${k(s)} workout`,badge:e.jsx(c,{tone:"meta",children:k(s)})}),r.set(`source:${s.sourceType}`,{id:`source:${s.sourceType}`,label:s.sourceType.replaceAll("_"," "),description:"Source type",searchText:`${s.sourceType} source`,badge:e.jsx(c,{tone:"meta",className:"capitalize",children:s.sourceType.replaceAll("_"," ")})}),r.set(`status:${s.reconciliationStatus}`,{id:`status:${s.reconciliationStatus}`,label:s.reconciliationStatus.replaceAll("_"," "),description:"Reconciliation status",searchText:`${s.reconciliationStatus} status`,badge:e.jsx(c,{tone:"meta",className:"capitalize",children:s.reconciliationStatus.replaceAll("_"," ")})});return r.set("linked:yes",{id:"linked:yes",label:"Linked",description:"Already tied to Forge or Psyche context",badge:e.jsx(c,{tone:"meta",children:"Linked"})}),r.set("linked:no",{id:"linked:no",label:"Needs links",description:"No Forge or Psyche links yet",badge:e.jsx(c,{tone:"meta",children:"Needs links"})}),r.set("habit:yes",{id:"habit:yes",label:"Habit-generated",description:"Created from a habit completion",badge:e.jsx(c,{tone:"meta",children:"Habit-generated"})}),r.set("effort:rated",{id:"effort:rated",label:"Effort rated",description:"Already has a subjective effort score",badge:e.jsx(c,{tone:"meta",children:"Effort rated"})}),Array.from(r.values())}function At(t,r){return r.every(s=>s.startsWith("workout:")?t.workoutType===s.slice(8):s.startsWith("source:")?t.sourceType===s.slice(7):s.startsWith("status:")?t.reconciliationStatus===s.slice(7):s==="linked:yes"?t.links.length>0:s==="linked:no"?t.links.length===0:s==="habit:yes"?!!t.generatedFromHabitId:s==="effort:rated"?t.subjectiveEffort!==null:!0)}function te(t,r,s){if(!t||t.length===0)return null;const l=[...t].filter(o=>o.dateKey<=r&&o[s]!=null).sort((o,h)=>h.dateKey.localeCompare(o.dateKey))[0];return(l==null?void 0:l[s])??null}function Ct(t){return[t.workoutType,t.workoutTypeLabel,t.activityFamily,t.activityFamilyLabel].filter(Boolean).join(" ").toLowerCase().includes("kickboxing")}function Tt(t){const r=new Map;for(const s of t){const l=`type:${s.workoutType}`;r.set(l,{id:l,label:k(s),description:_(s),searchText:`${k(s)} ${_(s)} ${s.workoutType}`,badge:e.jsx(c,{tone:"meta",children:k(s)})})}return[...r.values()].sort((s,l)=>s.label.localeCompare(l.label))}function Mt(t,r,s,l,o){const h=r.filter(u=>u.startsWith("type:")).map(u=>u.slice(5)),f=new Set(h),j=ae(new Date().toISOString()),b=new Date(`${j}T12:00:00.000Z`);b.setUTCDate(b.getUTCDate()-90);const n=b.toISOString().slice(0,10);return t.filter(u=>{if(f.size>0&&!f.has(u.workoutType))return!1;const x=ae(u.startedAt);return s==="recent_90"?x>=n:!(s==="custom"&&(l&&x<l||o&&x>o))}).sort((u,x)=>Date.parse(u.startedAt)-Date.parse(x.startedAt))}function oe(t){var s;const r=Object.fromEntries(V.map(l=>[l,0]));for(const l of t)for(const o of((s=l.analytics)==null?void 0:s.zoneDurations)??[])V.includes(o.key)&&(r[o.key]+=o.seconds);return r}function Ne(t){const r=Object.values(t).reduce((s,l)=>s+l,0);return Object.fromEntries(V.map(s=>[s,r>0?Number((t[s]/r*100).toFixed(1)):0]))}function Rt(t,r,s){const l=typeof(s==null?void 0:s.dataKey)=="string"?s.dataKey:typeof r=="string"?r:"",o=typeof t=="number"?Number(t.toFixed(1)):String(t??"n/a");return l==="restingHeartRate"||r==="Resting HR"?[`${o} bpm`,"Resting HR"]:l==="vo2Max"||r==="VO2max"?[`${o} ml/kg/min`,"VO2max"]:[`${o}%`,z(l)]}function Et(t,r){const s=t.map((n,u)=>{var y,M,D;const x=ae(n.startedAt),w=t.slice(Math.max(0,u-2),u+1),N=oe(w),T=Ne(N);return{id:n.id,dateKey:x,date:x.slice(5),session:k(n),durationMinutes:Math.round(n.durationSeconds/60),confidence:((y=n.analytics)==null?void 0:y.confidence)??"unavailable",restingHeartRate:((D=(M=n.analytics)==null?void 0:M.hrSummary)==null?void 0:D.restingHr)??te(r,x,"restingHeartRate"),vo2Max:te(r,x,"vo2Max"),...T}}),l=t.map((n,u)=>{var T,y,M;const x=ae(n.startedAt),w=oe(t.slice(0,u+1)),N=Ne(w);return{id:n.id,dateKey:x,date:x.slice(5),session:k(n),durationMinutes:Math.round(n.durationSeconds/60),confidence:((T=n.analytics)==null?void 0:T.confidence)??"unavailable",restingHeartRate:((M=(y=n.analytics)==null?void 0:y.hrSummary)==null?void 0:M.restingHr)??te(r,x,"restingHeartRate"),vo2Max:te(r,x,"vo2Max"),...N}}),o=oe(t),h=Object.values(o).reduce((n,u)=>n+u,0),f=V.map(n=>{var x;const u=((x=t.flatMap(w=>{var N;return((N=w.analytics)==null?void 0:N.zoneDurations)??[]}).find(w=>w.key===n))==null?void 0:x.label)??z(n);return{key:n,zone:u,percentage:h>0?Number((o[n]/h*100).toFixed(1)):0,fill:G[n]??"#f8fafc"}}),j=t.filter(n=>{var u,x;return(((x=(u=n.analytics)==null?void 0:u.dataQuality)==null?void 0:x.heartRateSampleCount)??0)>0}).length,b=[...new Set(t.map(n=>k(n)))];return{sessions:t,lineData:s,expandingLineData:l,averageZoneData:f,rawHrCount:j,exerciseLabels:b}}function zt({session:t,draft:r,linkOptions:s,pending:l,step:o,onStepChange:h,onDraftChange:f,onSave:j}){var n,u,x,w,N,T,y,M,D;const b=[{id:"context",title:"Session context",description:"Quick facts, effort, and how this session happened."},{id:"reflection",title:"Reflection",description:"Mood, meaning, and what the session actually did for you."},{id:"links",title:"Links",description:"Tie the session back to Forge and Psyche context."}];return e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-lg text-[var(--ui-ink-strong)]",children:[e.jsx(we,{className:"size-4 text-[var(--primary)]"}),e.jsx("span",{children:k(t)})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:Y(t.startedAt,t.endedAt)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(c,{children:B(t.durationSeconds)}),t.totalEnergyKcal?e.jsxs(c,{tone:"meta",children:[Math.round(t.totalEnergyKcal)," kcal"]}):null,t.distanceMeters?e.jsx(c,{tone:"meta",children:de(t.distanceMeters)}):null,e.jsx(c,{tone:"meta",children:_(t)}),e.jsx(c,{tone:"meta",className:"capitalize",children:t.reconciliationStatus.replaceAll("_"," ")})]})]})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:b.map((i,L)=>e.jsxs("button",{type:"button",onClick:()=>h(L),className:`rounded-[20px] border px-4 py-3 text-left transition ${o===L?"border-[var(--primary)] bg-[var(--primary)]/10 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:["Step ",L+1]}),e.jsx("div",{className:"mt-2 text-sm font-medium",children:i.title})]},i.id))}),e.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:b[o].title}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:b[o].description}),o===0?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Activity family"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)] capitalize",children:_(t)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Source system"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Ce(t)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Source device"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.sourceDevice||"n/a"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Steps"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.stepCount??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Avg HR"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.averageHeartRate?Math.round(t.averageHeartRate):"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Max HR"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.maxHeartRate?Math.round(t.maxHeartRate):"n/a"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Effort"}),e.jsx(H,{type:"number",min:1,max:10,value:r.subjectiveEffort,onChange:i=>f({subjectiveEffort:i.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned vs spontaneous"}),e.jsx(H,{value:r.plannedContext,onChange:i=>f({plannedContext:i.target.value}),placeholder:"Planned recovery block"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Social context"}),e.jsx(H,{value:r.socialContext,onChange:i=>f({socialContext:i.target.value}),placeholder:"Solo, coach, group class, partner"})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Tags"}),e.jsx(H,{value:r.tagsText,onChange:i=>f({tagsText:i.target.value}),placeholder:"recovery, interval-block, stress-release"})]})]}):null,o===1?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Mood before"}),e.jsx(H,{value:r.moodBefore,onChange:i=>f({moodBefore:i.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Mood after"}),e.jsx(H,{value:r.moodAfter,onChange:i=>f({moodAfter:i.target.value})})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Meaning, impact, and why this session mattered"}),e.jsx(at,{className:"min-h-[160px]",value:r.meaningText,onChange:i=>f({meaningText:i.target.value}),placeholder:"This session was planned as active recovery after a heavy work block and helped reset stress before sleep."})]})]}):null,o===2?e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Search goals, projects, habits, values, beliefs, patterns, or reports and attach the ones that explain this session."}),e.jsx(Ye,{options:s,selectedValues:r.linkValues,onChange:i=>f({linkValues:i}),placeholder:"Search Forge and Psyche records…"})]}):null,e.jsxs("div",{className:"mt-5 grid gap-4 border-t border-[var(--ui-border-subtle)] pt-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Captured data"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Source-native workout metrics, events, and phases exposed through the adapter layer."})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:[(((n=t.details)==null?void 0:n.metrics)??[]).slice(0,12).map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:i.label}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Nt(i)}),e.jsxs("div",{className:"mt-1 text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:[z(i.category)," ·"," ",z(i.statistic)]})]},`${i.category}:${i.key}:${i.statistic}`)),(((x=(u=t.details)==null?void 0:u.metrics)==null?void 0:x.length)??0)===0?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-faint)]",children:"No provider metrics were captured for this session yet."}):null]}),(((N=(w=t.details)==null?void 0:w.events)==null?void 0:N.length)??0)>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Workout events"}),e.jsx("div",{className:"grid gap-2",children:(T=t.details)==null?void 0:T.events.map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:i.label}),e.jsx(c,{tone:"meta",children:B(i.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:Y(i.startedAt,i.endedAt??i.startedAt)})]},`${i.type}:${i.startedAt}`))})]}):null,(((M=(y=t.details)==null?void 0:y.components)==null?void 0:M.length)??0)>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Workout phases"}),e.jsx("div",{className:"grid gap-2",children:(D=t.details)==null?void 0:D.components.map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:i.activity.canonicalLabel}),e.jsx(c,{tone:"meta",children:B(i.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:Y(i.startedAt,i.endedAt??i.startedAt)})]},i.externalUid))})]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:o<b.length-1?"Move through the session one step at a time, then save when the context is clean.":"Everything is in place. Save the session metadata back into Forge."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ie,{type:"button",variant:"secondary",onClick:()=>h(Math.max(0,o-1)),disabled:o===0,children:"Back"}),o<b.length-1?e.jsxs(ie,{type:"button",onClick:()=>h(o+1),children:["Next",e.jsx(Se,{className:"size-4"})]}):null,e.jsxs(ie,{type:"button",pending:l,pendingLabel:"Saving",onClick:j,children:[e.jsx(Ze,{className:"size-4"}),"Save session"]})]})]})]})}function Yt(){var fe,be;const t=Xe(),r=Ue(),s=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[l,o]=p.useState({}),[h,f]=p.useState(""),[j,b]=p.useState([]),[n,u]=p.useState([]),[x,w]=p.useState(""),[N,T]=p.useState("all"),[y,M]=p.useState("rolling_stack"),[D,i]=p.useState(""),[L,Te]=p.useState(""),[ce,Me]=p.useState(!1),[ue,se]=p.useState(null),[Re,X]=p.useState(0),S=W({queryKey:["forge-fitness",...s],queryFn:async()=>(await rt(s)).fitness}),Ee=W({queryKey:["forge-health-values",...s],queryFn:async()=>(await it(s)).values}),ze=W({queryKey:["forge-health-patterns",...s],queryFn:async()=>(await nt(s)).patterns}),De=W({queryKey:["forge-health-behaviors",...s],queryFn:async()=>(await lt(s)).behaviors}),Fe=W({queryKey:["forge-health-beliefs",...s],queryFn:async()=>(await ot(s)).beliefs}),He=W({queryKey:["forge-health-reports",...s],queryFn:async()=>(await dt(s)).reports});p.useEffect(()=>{S.data&&o(Object.fromEntries(S.data.sessions.map(a=>[a.id,U(a)])))},[S.data]),p.useEffect(()=>{if(ce||!S.data)return;const d=(S.data.analysisSessions??S.data.sessions).find(Ct);d&&u([`type:${d.workoutType}`]),Me(!0)},[ce,S.data]);const re=Ge({mutationFn:async a=>st(a.workoutId,{subjectiveEffort:a.subjectiveEffort.trim().length>0?Number(a.subjectiveEffort):null,moodBefore:a.moodBefore,moodAfter:a.moodAfter,meaningText:a.meaningText,plannedContext:a.plannedContext,socialContext:a.socialContext,tags:a.tagsText.split(",").map(d=>d.trim()).filter(Boolean),links:ht(a.linkValues)}),onSuccess:async()=>{await r.invalidateQueries({queryKey:["forge-fitness"]})}}),F=S.data,A=(F==null?void 0:F.sessions)??[],O=(F==null?void 0:F.analysisSessions)??A,Le=pt({goals:t.snapshot.dashboard.goals,projects:t.snapshot.dashboard.projects,tasks:t.snapshot.dashboard.tasks,habits:t.snapshot.dashboard.habits,values:Ee.data??[],patterns:ze.data??[],behaviors:De.data??[],beliefs:Fe.data??[],reports:He.data??[]}),$e=p.useMemo(()=>St(A),[A]),_e=p.useMemo(()=>Tt(O),[O]),I=p.useMemo(()=>{const a=Ae(h);return[...A].sort((d,m)=>new Date(m.startedAt).getTime()-new Date(d.startedAt).getTime()).filter(d=>{const m=l[d.id]??U(d);return(a.length===0||wt(d,m).includes(a))&&At(d,j)})},[l,h,j,A]),xe=p.useMemo(()=>Mt(O,n,N,D,L),[N,L,O,D,n]),me=I.length===A.length&&h.trim().length===0&&j.length===0?`${A.length} workout sessions visible`:`${I.length} of ${A.length} workout sessions visible`,R=I.find(a=>a.id===ue)??A.find(a=>a.id===ue)??null,pe=R?l[R.id]??U(R):null;if(S.isLoading)return e.jsx(Je,{eyebrow:"Sports",title:"Loading sports view",description:"Reading synced workouts and local reflection metadata.",columns:2,blocks:6});if(S.isError||!F)return e.jsx(et,{eyebrow:"Sports",error:S.error??new Error("Sports data unavailable"),onRetry:()=>void S.refetch()});const{summary:v,weeklyTrend:he,typeBreakdown:Oe}=F,ve=v.zoneMix??[],C=Et(xe,F.vitalsTrend),ge=n.length===0?"All exercise types":C.exerciseLabels.length>0?C.exerciseLabels.join(", "):`${n.length} selected types`,We=ve.map(a=>({zone:a.label,minutes:Math.round(a.seconds/60),percentage:Math.round(a.percentage*100),fill:G[a.key]??"#f8fafc"})),Ke=he.map(a=>{const d=Object.fromEntries((a.zoneDurations??[]).map(m=>[m.key,Math.round(m.seconds/60)]));return{date:a.dateKey.slice(5),duration:a.durationMinutes,load:a.trainingLoad??0,coverage:Math.round((a.heartRateCoverage??0)*100),...d}}),Be=O.map(a=>{var d,m,E,$;return{duration:Math.round(a.durationSeconds/60),intensity:Math.round((((m=(d=a.analytics)==null?void 0:d.load)==null?void 0:m.intensity)??0)*100),load:(($=(E=a.analytics)==null?void 0:E.load)==null?void 0:$.trimp)??0,type:k(a),name:k(a)}});function Ve(a,d){o(m=>{const E=m[a]??U(A.find($=>$.id===a));return{...m,[a]:{...E,...d}}})}async function Ie(a){const d=A.find(E=>E.id===a);if(!d)return;const m=l[a]??U(d);await re.mutateAsync({workoutId:a,subjectiveEffort:m.subjectiveEffort,moodBefore:m.moodBefore,moodAfter:m.moodAfter,meaningText:m.meaningText,plannedContext:m.plannedContext,socialContext:m.socialContext,tagsText:m.tagsText,linkValues:m.linkValues}),se(null),X(0)}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ct,{entityKind:"project",title:"Sports",description:"A session-first training surface for workout data, subjective meaning, and links back into Forge execution and Psyche.",badge:`${A.length} sessions`}),e.jsx(ut,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Weekly volume"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:B(v.weeklyVolumeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Total training time in the recent week."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Exercise minutes"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.exerciseMinutes}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Aggregate exercise minutes from synced sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Energy burned"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.energyBurnedKcal}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Recent weekly kcal."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training streak"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.streakDays}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Distinct workout days in the recent week."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Average session"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[v.averageSessionMinutes,"m"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Mean duration across recent sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training load"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.totalTrainingLoad??"n/a"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Forge TRIMP across recent sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Linked sessions"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.linkedSessionCount}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Sessions already tied to Forge or Psyche entities."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"HR coverage"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[Math.round((v.averageHeartRateCoverage??0)*100),"%"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Average raw HR sample coverage."})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(320px,0.9fr)]",children:[e.jsxs(g,{className:"min-h-[320px]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Load and volume trend"}),e.jsx(Z,{className:"mt-4 h-[260px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(vt,{data:Ke,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"sportsLoad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#f97316",stopOpacity:.36}),e.jsx("stop",{offset:"100%",stopColor:"#f97316",stopOpacity:.04})]})}),e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"date",tick:{fill:"var(--ui-ink-faint)",fontSize:11}}),e.jsx(K,{tick:{fill:"var(--ui-ink-faint)",fontSize:11},width:34}),e.jsx(Q,{contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ke,{type:"monotone",dataKey:"load",stroke:"#f97316",fill:"url(#sportsLoad)",strokeWidth:2}),e.jsx(ke,{type:"monotone",dataKey:"duration",stroke:"#38bdf8",fill:"var(--ui-info-soft)",strokeWidth:2})]})})})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Zone distribution"}),e.jsx("div",{className:"mt-4 grid gap-3",children:ve.map(a=>e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-[var(--ui-ink)]",children:a.label}),e.jsxs("span",{className:"text-[var(--ui-ink-strong)]",children:[Math.round(a.percentage*100),"% ·"," ",B(a.seconds)]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-3)]",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,a.percentage*100)}%`,background:G[a.key]??"#f8fafc"}})})]},a.key))}),e.jsx(Z,{className:"mt-5 h-[180px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ye,{data:We,children:[e.jsx(q,{dataKey:"zone",tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(K,{tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:34}),e.jsx(Q,{contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ne,{dataKey:"minutes",fill:"#f97316",radius:[4,4,0,0]})]})})})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(g,{className:"grid gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"HR zone analysis"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Filter all-time workout evidence by exercise type and date."})]}),e.jsxs(c,{tone:"meta",children:[xe.length," of ",O.length," ","sessions"]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(280px,0.8fr)]",children:[e.jsx(je,{title:"Exercise types",description:"Select one, many, or none for all exercise types.",query:x,onQueryChange:w,options:_e,selectedOptionIds:n,onSelectedOptionIdsChange:u,resultSummary:ge,placeholder:"Search exercise types",emptyStateMessage:"No exercise type matches."}),e.jsxs("div",{className:"grid gap-3 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Date range"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["all","All time"],["recent_90","90 days"],["custom","Custom"]].map(([a,d])=>e.jsx("button",{type:"button",className:`rounded-[8px] border px-3 py-2 text-sm transition ${N===a?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>T(a),children:d},a))}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Start"}),e.jsx(H,{type:"date",value:D,onChange:a=>{i(a.target.value),T("custom")}})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"End"}),e.jsx(H,{type:"date",value:L,onChange:a=>{Te(a.target.value),T("custom")}})]})]})]})]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.85fr)_minmax(0,1.15fr)]",children:[e.jsxs(g,{className:"min-h-[330px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Average zones"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Duration-weighted proportion of time in each HR zone."})]}),e.jsx(c,{tone:"meta",children:ge})]}),e.jsx(Z,{className:"mt-4 h-[235px]",children:C.sessions.length>0?e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ye,{data:C.averageZoneData,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"zone",interval:0,tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(K,{unit:"%",domain:[0,100],ticks:[0,25,50,75,100],tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:38}),e.jsx(Q,{formatter:a=>[`${a}%`,"Average time"],contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ne,{dataKey:"percentage",radius:[4,4,0,0],children:C.averageZoneData.map(a=>e.jsx(gt,{fill:a.fill},a.key))})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 text-center text-sm leading-6 text-[var(--ui-ink-soft)]",children:"No selected sessions with zone analytics are available yet."})}),C.sessions.length>0?e.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)] sm:grid-cols-3",children:[e.jsxs("div",{children:[C.rawHrCount," sessions have raw HR timelines"]}),e.jsxs("div",{children:["Latest: ",((fe=C.lineData.at(-1))==null?void 0:fe.dateKey)??"n/a"]}),e.jsxs("div",{children:["VO2max points:"," ",C.lineData.filter(a=>a.vo2Max!=null).length]})]}):null]}),e.jsxs(g,{className:"min-h-[330px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:y==="expanding_lines"?"Expanding zone lines":"Zone drift"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y==="expanding_lines"?"Expanding all-session average with resting HR and VO2max overlay.":"Rolling duration-weighted zone mix with resting HR and VO2max overlay."})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:items-end",children:[e.jsx("div",{className:"grid grid-cols-2 gap-1 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1","aria-label":"Zone chart display",children:[["rolling_stack","Stacked"],["expanding_lines","Lines"]].map(([a,d])=>e.jsx("button",{type:"button",className:`min-h-9 rounded-[6px] px-3 py-1.5 text-xs font-medium transition ${y===a?"bg-[var(--primary)]/18 text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>M(a),children:d},a))}),e.jsx(c,{tone:"meta",children:"HRR zones"})]})]}),e.jsx(Z,{className:"mt-4 h-[255px]",children:C.lineData.length>0?e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ft,{data:y==="expanding_lines"?C.expandingLineData:C.lineData,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"date",tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(K,{yAxisId:"zones",domain:[0,100],ticks:[0,25,50,75,100],unit:"%",tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:38}),e.jsx(K,{yAxisId:"vitals",orientation:"right",tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:42}),e.jsx(Q,{formatter:(a,d,m)=>Rt(a,d,m),contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(bt,{wrapperStyle:{color:"var(--ui-ink)",fontSize:11}}),y==="expanding_lines"?V.map(a=>e.jsx(le,{yAxisId:"zones",type:"monotone",dataKey:a,name:z(a),stroke:G[a],strokeWidth:2,dot:{r:2.5},activeDot:{r:4},connectNulls:!0},a)):V.map(a=>e.jsx(ne,{yAxisId:"zones",dataKey:a,stackId:"zones",fill:G[a],isAnimationActive:!1},a)),e.jsx(le,{yAxisId:"vitals",type:"monotone",dataKey:"restingHeartRate",name:"Resting HR",stroke:"var(--ui-ink-soft)",strokeWidth:2,dot:{r:3},connectNulls:!0}),e.jsx(le,{yAxisId:"vitals",type:"monotone",dataKey:"vo2Max",name:"VO2max",stroke:"#a78bfa",strokeWidth:2,dot:{r:3},connectNulls:!0})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 text-center text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Select workouts with HR evidence to unlock the time-series plot."})})]})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs(g,{className:"min-h-[300px]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Duration vs intensity"}),e.jsx(Z,{className:"mt-4 h-[250px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(jt,{data:Be,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)"}),e.jsx(q,{type:"number",dataKey:"duration",name:"minutes",tick:{fill:"var(--ui-ink-faint)",fontSize:11}}),e.jsx(K,{type:"number",dataKey:"intensity",name:"intensity",tick:{fill:"var(--ui-ink-faint)",fontSize:11},width:38}),e.jsx(Q,{cursor:{strokeDasharray:"3 3"},contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(kt,{dataKey:"load",fill:"#f97316"})]})})})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Evidence quality"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Raw HR coverage"}),e.jsxs("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:[Math.round((v.averageHeartRateCoverage??0)*100),"%"]})]}),e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Route-backed workouts"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:v.routeWorkoutCount??0})]}),e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Top sport"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.topWorkoutTypeLabel??v.topWorkoutType??"n/a"})]})]})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[1.05fr_0.95fr]",children:[e.jsxs(g,{className:"grid gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Recent volume"}),e.jsx("div",{className:"grid gap-3",children:he.map(a=>e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 md:grid-cols-[110px_150px_minmax(0,1fr)_90px]",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:a.dateKey}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:a.workoutTypeLabel??z(a.workoutType)}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-[var(--ui-surface-3)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)]",style:{width:`${Math.min(100,a.durationMinutes/120*100)}%`}})}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:[a.durationMinutes,"m"]})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:[a.energyKcal," kcal"]})]},a.id))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:de(v.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned sessions"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.plannedSessionCount})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Imported / merged"}),e.jsxs("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:[v.importedSessionCount," /"," ",v.reconciledSessionCount]})]})]})]}),e.jsxs(g,{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training composition"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Workout type and provenance mix"})]}),e.jsx("div",{className:"grid gap-3",children:Oe.slice(0,6).map(a=>e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 md:grid-cols-[minmax(0,1fr)_90px_90px]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:a.workoutTypeLabel??z(a.workoutType)}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[a.sessionCount," sessions ·"," ",a.activityFamilyLabel??"Other"]})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink)]",children:[a.totalMinutes,"m"]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink)]",children:[a.energyKcal," kcal"]})]},a.workoutType))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Habit-generated"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.habitGeneratedSessionCount})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Forge-linked"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.linkedSessionCount})]})]})]})]})}),e.jsx(xt,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(je,{title:"Session browser",description:"Search past activities by workout type, source, reconciliation state, or whether they still need context.",query:h,onQueryChange:f,options:$e,selectedOptionIds:j,onSelectedOptionIdsChange:b,resultSummary:me,placeholder:"Search workouts, devices, notes, moods, or filter chips",emptyStateMessage:"Keep typing or pick a filter chip to narrow the activity history."}),e.jsxs(g,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Activity history"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Open a workout to add reflection and links in a guided modal."})]}),e.jsx(c,{tone:"meta",children:me})]}),e.jsx("div",{className:"max-h-[34rem] overflow-y-auto rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:I.length===0?e.jsx("div",{className:"flex min-h-[18rem] items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-faint)]",children:"No workout matches the current search yet. Clear some filters or search by workout type, device, or reflection text."}):e.jsx("div",{className:"grid gap-3",children:I.map(a=>{var m,E,$;const d=a.meaningText.trim().length>0||a.moodBefore.trim().length>0||a.moodAfter.trim().length>0||a.tags.length>0||a.links.length>0;return e.jsxs("div",{className:"grid w-full min-w-0 gap-3 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"grid min-w-0 gap-3 sm:flex sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Pe,{to:`/sports/workouts/${a.id}`,className:"flex min-w-0 items-center gap-2 text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:[e.jsx(we,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:k(a)})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx(qe,{className:"size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:Y(a.startedAt,a.endedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-faint)]",children:[_(a)," ·"," ",a.sourceDevice]})]}),e.jsxs("button",{type:"button","aria-label":`Edit ${k(a)} reflection`,className:"inline-flex w-fit max-w-full items-center gap-2 rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-xs text-[var(--ui-ink)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{se(a.id),X(0)},children:[e.jsx("span",{className:"truncate",children:d?"Reflected":"Needs reflection"}),e.jsx(Se,{className:"size-3.5 shrink-0"})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsx(c,{children:B(a.durationSeconds)}),a.totalEnergyKcal?e.jsxs(c,{tone:"meta",children:[Math.round(a.totalEnergyKcal)," kcal"]}):null,a.distanceMeters?e.jsx(c,{tone:"meta",children:de(a.distanceMeters)}):null,a.averageHeartRate?e.jsxs(c,{tone:"meta",children:[e.jsx(Qe,{className:"mr-1 size-3.5"}),Math.round(a.averageHeartRate)," bpm"]}):null,e.jsx(c,{tone:"meta",children:_(a)}),e.jsx(c,{tone:"meta",className:"capitalize",children:a.sourceType.replaceAll("_"," ")}),e.jsx(c,{tone:"meta",className:"capitalize",children:a.reconciliationStatus.replaceAll("_"," ")}),(m=a.analytics)!=null&&m.confidence?e.jsxs(c,{tone:"meta",children:[a.analytics.confidence," zones"]}):null,($=(E=a.analytics)==null?void 0:E.routeSummary)!=null&&$.hasRoute?e.jsx(c,{tone:"meta",children:"Route"}):null]})]},a.id)})})})]})]})}),R&&pe?e.jsx(tt,{open:!!R,onOpenChange:a=>{a||(se(null),X(0))},eyebrow:"Sports session",title:k(R),description:"Add contextual meaning without crowding the main training surface.",children:e.jsx(zt,{session:R,draft:pe,linkOptions:Le,pending:re.isPending&&((be=re.variables)==null?void 0:be.workoutId)===R.id,step:Re,onStepChange:X,onDraftChange:a=>Ve(R.id,a),onSave:()=>void Ie(R.id)})}):null]})}export{Yt as SportsPage,Rt as formatZoneTrendTooltipValue};
|
|
1
|
+
import{r as p,j as e,aC as Pe,bq as we,aV as qe,bW as Se,bs as Qe,cm as Ze}from"./vendor-BwL6m4SE.js";import{j as Ue,i as W,k as Ge}from"./state-Bpe5dF3T.js";import{E as Ye}from"./entity-link-multiselect-Do5DTju7.js";import{F as je}from"./faceted-token-search-DoSsb7qT.js";import{d as Xe,S as Je,e as et,C as g,k as c,I as H,aA as tt,T as at,B as ie,e1 as st,be as rt,b3 as it,b4 as nt,b5 as lt,b6 as ot,b9 as dt}from"./index-DGYIFHgo.js";import{P as ct}from"./page-hero-BkrRTu-t.js";import{c as ut,d as J,e as xt}from"./health-boxes-CeqSGyZ3.js";import{f as mt}from"./date-keys-BnZV4PNO.js";import{b as pt,p as ht}from"./health-link-options-Cpx8w7uM.js";import{R as P,A as vt,C as ee,X as q,Y as K,T as Q,a as ke,e as ye,B as ne,f as gt,d as ft,g as bt,c as le,S as jt,h as kt}from"./charts-BzT4pUPg.js";import"./use-anchored-overlay-position-BY4kNzPj.js";import"./motion-DcgUnXhY.js";import"./ui-B9TWEtCx.js";import"./board-CuxQRKPJ.js";import"./forms-D1qJ3oOP.js";import"./generic-node-view-CgLkbts-.js";import"./graph-BF4IsheG.js";import"./define-workbench-box-DWAqqjvH.js";function Z({className:t,children:r}){const s=p.useRef(null),[l,o]=p.useState(!1);return p.useEffect(()=>{const h=()=>{const b=s.current;o(!!(b&&b.clientWidth>0&&b.clientHeight>0))},f=window.requestAnimationFrame(h),j=typeof ResizeObserver>"u"?null:new ResizeObserver(h);return s.current&&j&&j.observe(s.current),window.addEventListener("resize",h),()=>{window.cancelAnimationFrame(f),j==null||j.disconnect(),window.removeEventListener("resize",h)}},[]),e.jsx("div",{ref:s,className:t,children:l?r:null})}const G={below_z1:"#94a3b8",zone_1:"#38bdf8",zone_2:"#22c55e",zone_3:"#eab308",zone_4:"#f97316",zone_5:"#ef4444"},V=["below_z1","zone_1","zone_2","zone_3","zone_4","zone_5"];function z(t){return t?t.replace(/^activity_/i,"").replaceAll("_"," ").replace(/\s+/g," ").replace(/\b\w/g,r=>r.toUpperCase()):"Unknown"}function B(t){return`${Math.round(t/60)}m`}function de(t){return t?`${(t/1e3).toFixed(1)} km`:"n/a"}function Y(t,r){const s=new Intl.DateTimeFormat(void 0,{weekday:"short",day:"numeric",month:"short"}),l=new Intl.DateTimeFormat(void 0,{hour:"2-digit",minute:"2-digit"});return`${s.format(new Date(t))} · ${l.format(new Date(t))} - ${l.format(new Date(r))}`}function ae(t){return mt(new Date(t))}function U(t){return{subjectiveEffort:t.subjectiveEffort!==null?String(t.subjectiveEffort):"",moodBefore:t.moodBefore??"",moodAfter:t.moodAfter??"",meaningText:t.meaningText??"",plannedContext:t.plannedContext??"",socialContext:t.socialContext??"",tagsText:Array.isArray(t.tags)?t.tags.join(", "):"",linkValues:Array.isArray(t.links)?t.links.map(r=>`${r.entityType}:${r.entityId}`):[]}}function Ae(t){return t.trim().toLowerCase()}function k(t){var r;return((r=t.workoutTypeLabel)==null?void 0:r.trim())||z(t.workoutType)}function _(t){var r;return((r=t.activityFamilyLabel)==null?void 0:r.trim())||z(t.activityFamily)}function Ce(t){return z(t.sourceSystem??t.source)}function yt(t){return t==null?"n/a":typeof t=="boolean"?t?"Yes":"No":typeof t=="number"?Number.isInteger(t)?String(t):t.toFixed(1):t}function Nt(t){const r=yt(t.value);return!t.unit||t.unit==="count"?r:`${r} ${t.unit}`}function wt(t,r){return Ae([t.workoutType,k(t),t.activityFamily,_(t),t.sourceSystem,Ce(t),t.sourceType,t.sourceDevice,t.reconciliationStatus,t.moodBefore,t.moodAfter,t.meaningText,t.plannedContext,t.socialContext,t.tags.join(" "),r.moodBefore,r.moodAfter,r.meaningText,r.plannedContext,r.socialContext,r.tagsText,Y(t.startedAt,t.endedAt)].join(" "))}function St(t){const r=new Map;for(const s of t)r.set(`workout:${s.workoutType}`,{id:`workout:${s.workoutType}`,label:k(s),description:"Workout type",searchText:`${k(s)} workout`,badge:e.jsx(c,{tone:"meta",children:k(s)})}),r.set(`source:${s.sourceType}`,{id:`source:${s.sourceType}`,label:s.sourceType.replaceAll("_"," "),description:"Source type",searchText:`${s.sourceType} source`,badge:e.jsx(c,{tone:"meta",className:"capitalize",children:s.sourceType.replaceAll("_"," ")})}),r.set(`status:${s.reconciliationStatus}`,{id:`status:${s.reconciliationStatus}`,label:s.reconciliationStatus.replaceAll("_"," "),description:"Reconciliation status",searchText:`${s.reconciliationStatus} status`,badge:e.jsx(c,{tone:"meta",className:"capitalize",children:s.reconciliationStatus.replaceAll("_"," ")})});return r.set("linked:yes",{id:"linked:yes",label:"Linked",description:"Already tied to Forge or Psyche context",badge:e.jsx(c,{tone:"meta",children:"Linked"})}),r.set("linked:no",{id:"linked:no",label:"Needs links",description:"No Forge or Psyche links yet",badge:e.jsx(c,{tone:"meta",children:"Needs links"})}),r.set("habit:yes",{id:"habit:yes",label:"Habit-generated",description:"Created from a habit completion",badge:e.jsx(c,{tone:"meta",children:"Habit-generated"})}),r.set("effort:rated",{id:"effort:rated",label:"Effort rated",description:"Already has a subjective effort score",badge:e.jsx(c,{tone:"meta",children:"Effort rated"})}),Array.from(r.values())}function At(t,r){return r.every(s=>s.startsWith("workout:")?t.workoutType===s.slice(8):s.startsWith("source:")?t.sourceType===s.slice(7):s.startsWith("status:")?t.reconciliationStatus===s.slice(7):s==="linked:yes"?t.links.length>0:s==="linked:no"?t.links.length===0:s==="habit:yes"?!!t.generatedFromHabitId:s==="effort:rated"?t.subjectiveEffort!==null:!0)}function te(t,r,s){if(!t||t.length===0)return null;const l=[...t].filter(o=>o.dateKey<=r&&o[s]!=null).sort((o,h)=>h.dateKey.localeCompare(o.dateKey))[0];return(l==null?void 0:l[s])??null}function Ct(t){return[t.workoutType,t.workoutTypeLabel,t.activityFamily,t.activityFamilyLabel].filter(Boolean).join(" ").toLowerCase().includes("kickboxing")}function Tt(t){const r=new Map;for(const s of t){const l=`type:${s.workoutType}`;r.set(l,{id:l,label:k(s),description:_(s),searchText:`${k(s)} ${_(s)} ${s.workoutType}`,badge:e.jsx(c,{tone:"meta",children:k(s)})})}return[...r.values()].sort((s,l)=>s.label.localeCompare(l.label))}function Mt(t,r,s,l,o){const h=r.filter(u=>u.startsWith("type:")).map(u=>u.slice(5)),f=new Set(h),j=ae(new Date().toISOString()),b=new Date(`${j}T12:00:00.000Z`);b.setUTCDate(b.getUTCDate()-90);const n=b.toISOString().slice(0,10);return t.filter(u=>{if(f.size>0&&!f.has(u.workoutType))return!1;const x=ae(u.startedAt);return s==="recent_90"?x>=n:!(s==="custom"&&(l&&x<l||o&&x>o))}).sort((u,x)=>Date.parse(u.startedAt)-Date.parse(x.startedAt))}function oe(t){var s;const r=Object.fromEntries(V.map(l=>[l,0]));for(const l of t)for(const o of((s=l.analytics)==null?void 0:s.zoneDurations)??[])V.includes(o.key)&&(r[o.key]+=o.seconds);return r}function Ne(t){const r=Object.values(t).reduce((s,l)=>s+l,0);return Object.fromEntries(V.map(s=>[s,r>0?Number((t[s]/r*100).toFixed(1)):0]))}function Rt(t,r,s){const l=typeof(s==null?void 0:s.dataKey)=="string"?s.dataKey:typeof r=="string"?r:"",o=typeof t=="number"?Number(t.toFixed(1)):String(t??"n/a");return l==="restingHeartRate"||r==="Resting HR"?[`${o} bpm`,"Resting HR"]:l==="vo2Max"||r==="VO2max"?[`${o} ml/kg/min`,"VO2max"]:[`${o}%`,z(l)]}function Et(t,r){const s=t.map((n,u)=>{var y,M,D;const x=ae(n.startedAt),w=t.slice(Math.max(0,u-2),u+1),N=oe(w),T=Ne(N);return{id:n.id,dateKey:x,date:x.slice(5),session:k(n),durationMinutes:Math.round(n.durationSeconds/60),confidence:((y=n.analytics)==null?void 0:y.confidence)??"unavailable",restingHeartRate:((D=(M=n.analytics)==null?void 0:M.hrSummary)==null?void 0:D.restingHr)??te(r,x,"restingHeartRate"),vo2Max:te(r,x,"vo2Max"),...T}}),l=t.map((n,u)=>{var T,y,M;const x=ae(n.startedAt),w=oe(t.slice(0,u+1)),N=Ne(w);return{id:n.id,dateKey:x,date:x.slice(5),session:k(n),durationMinutes:Math.round(n.durationSeconds/60),confidence:((T=n.analytics)==null?void 0:T.confidence)??"unavailable",restingHeartRate:((M=(y=n.analytics)==null?void 0:y.hrSummary)==null?void 0:M.restingHr)??te(r,x,"restingHeartRate"),vo2Max:te(r,x,"vo2Max"),...N}}),o=oe(t),h=Object.values(o).reduce((n,u)=>n+u,0),f=V.map(n=>{var x;const u=((x=t.flatMap(w=>{var N;return((N=w.analytics)==null?void 0:N.zoneDurations)??[]}).find(w=>w.key===n))==null?void 0:x.label)??z(n);return{key:n,zone:u,percentage:h>0?Number((o[n]/h*100).toFixed(1)):0,fill:G[n]??"#f8fafc"}}),j=t.filter(n=>{var u,x;return(((x=(u=n.analytics)==null?void 0:u.dataQuality)==null?void 0:x.heartRateSampleCount)??0)>0}).length,b=[...new Set(t.map(n=>k(n)))];return{sessions:t,lineData:s,expandingLineData:l,averageZoneData:f,rawHrCount:j,exerciseLabels:b}}function zt({session:t,draft:r,linkOptions:s,pending:l,step:o,onStepChange:h,onDraftChange:f,onSave:j}){var n,u,x,w,N,T,y,M,D;const b=[{id:"context",title:"Session context",description:"Quick facts, effort, and how this session happened."},{id:"reflection",title:"Reflection",description:"Mood, meaning, and what the session actually did for you."},{id:"links",title:"Links",description:"Tie the session back to Forge and Psyche context."}];return e.jsxs("div",{className:"grid gap-5",children:[e.jsx("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 text-lg text-[var(--ui-ink-strong)]",children:[e.jsx(we,{className:"size-4 text-[var(--primary)]"}),e.jsx("span",{children:k(t)})]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:Y(t.startedAt,t.endedAt)})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(c,{children:B(t.durationSeconds)}),t.totalEnergyKcal?e.jsxs(c,{tone:"meta",children:[Math.round(t.totalEnergyKcal)," kcal"]}):null,t.distanceMeters?e.jsx(c,{tone:"meta",children:de(t.distanceMeters)}):null,e.jsx(c,{tone:"meta",children:_(t)}),e.jsx(c,{tone:"meta",className:"capitalize",children:t.reconciliationStatus.replaceAll("_"," ")})]})]})}),e.jsx("div",{className:"grid gap-2 sm:grid-cols-3",children:b.map((i,L)=>e.jsxs("button",{type:"button",onClick:()=>h(L),className:`rounded-[20px] border px-4 py-3 text-left transition ${o===L?"border-[var(--primary)] bg-[var(--primary)]/10 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,children:[e.jsxs("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:["Step ",L+1]}),e.jsx("div",{className:"mt-2 text-sm font-medium",children:i.title})]},i.id))}),e.jsxs("div",{className:"rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:b[o].title}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:b[o].description}),o===0?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Activity family"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)] capitalize",children:_(t)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Source system"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Ce(t)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Source device"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.sourceDevice||"n/a"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Steps"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.stepCount??"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Avg HR"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.averageHeartRate?Math.round(t.averageHeartRate):"n/a"})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Max HR"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:t.maxHeartRate?Math.round(t.maxHeartRate):"n/a"})]})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Effort"}),e.jsx(H,{type:"number",min:1,max:10,value:r.subjectiveEffort,onChange:i=>f({subjectiveEffort:i.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned vs spontaneous"}),e.jsx(H,{value:r.plannedContext,onChange:i=>f({plannedContext:i.target.value}),placeholder:"Planned recovery block"})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Social context"}),e.jsx(H,{value:r.socialContext,onChange:i=>f({socialContext:i.target.value}),placeholder:"Solo, coach, group class, partner"})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Tags"}),e.jsx(H,{value:r.tagsText,onChange:i=>f({tagsText:i.target.value}),placeholder:"recovery, interval-block, stress-release"})]})]}):null,o===1?e.jsxs("div",{className:"mt-4 grid gap-4",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Mood before"}),e.jsx(H,{value:r.moodBefore,onChange:i=>f({moodBefore:i.target.value})})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Mood after"}),e.jsx(H,{value:r.moodAfter,onChange:i=>f({moodAfter:i.target.value})})]})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Meaning, impact, and why this session mattered"}),e.jsx(at,{className:"min-h-[160px]",value:r.meaningText,onChange:i=>f({meaningText:i.target.value}),placeholder:"This session was planned as active recovery after a heavy work block and helped reset stress before sleep."})]})]}):null,o===2?e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Search goals, projects, habits, values, beliefs, patterns, or reports and attach the ones that explain this session."}),e.jsx(Ye,{options:s,selectedValues:r.linkValues,onChange:i=>f({linkValues:i}),placeholder:"Search Forge and Psyche records…"})]}):null,e.jsxs("div",{className:"mt-5 grid gap-4 border-t border-[var(--ui-border-subtle)] pt-5",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Captured data"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Source-native workout metrics, events, and phases exposed through the adapter layer."})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-3",children:[(((n=t.details)==null?void 0:n.metrics)??[]).slice(0,12).map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:i.label}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:Nt(i)}),e.jsxs("div",{className:"mt-1 text-xs uppercase tracking-[0.14em] text-[var(--ui-ink-faint)]",children:[z(i.category)," ·"," ",z(i.statistic)]})]},`${i.category}:${i.key}:${i.statistic}`)),(((x=(u=t.details)==null?void 0:u.metrics)==null?void 0:x.length)??0)===0?e.jsx("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4 text-sm text-[var(--ui-ink-faint)]",children:"No provider metrics were captured for this session yet."}):null]}),(((N=(w=t.details)==null?void 0:w.events)==null?void 0:N.length)??0)>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Workout events"}),e.jsx("div",{className:"grid gap-2",children:(T=t.details)==null?void 0:T.events.map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:i.label}),e.jsx(c,{tone:"meta",children:B(i.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:Y(i.startedAt,i.endedAt??i.startedAt)})]},`${i.type}:${i.startedAt}`))})]}):null,(((M=(y=t.details)==null?void 0:y.components)==null?void 0:M.length)??0)>0?e.jsxs("div",{className:"grid gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Workout phases"}),e.jsx("div",{className:"grid gap-2",children:(D=t.details)==null?void 0:D.components.map(i=>e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:i.activity.canonicalLabel}),e.jsx(c,{tone:"meta",children:B(i.durationSeconds)})]}),e.jsx("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:Y(i.startedAt,i.endedAt??i.startedAt)})]},i.externalUid))})]}):null]})]}),e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-faint)]",children:o<b.length-1?"Move through the session one step at a time, then save when the context is clean.":"Everything is in place. Save the session metadata back into Forge."}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(ie,{type:"button",variant:"secondary",onClick:()=>h(Math.max(0,o-1)),disabled:o===0,children:"Back"}),o<b.length-1?e.jsxs(ie,{type:"button",onClick:()=>h(o+1),children:["Next",e.jsx(Se,{className:"size-4"})]}):null,e.jsxs(ie,{type:"button",pending:l,pendingLabel:"Saving",onClick:j,children:[e.jsx(Ze,{className:"size-4"}),"Save session"]})]})]})]})}function Yt(){var fe,be;const t=Xe(),r=Ue(),s=Array.isArray(t.selectedUserIds)?t.selectedUserIds:[],[l,o]=p.useState({}),[h,f]=p.useState(""),[j,b]=p.useState([]),[n,u]=p.useState([]),[x,w]=p.useState(""),[N,T]=p.useState("all"),[y,M]=p.useState("rolling_stack"),[D,i]=p.useState(""),[L,Te]=p.useState(""),[ce,Me]=p.useState(!1),[ue,se]=p.useState(null),[Re,X]=p.useState(0),S=W({queryKey:["forge-fitness",...s],queryFn:async()=>(await rt(s)).fitness}),Ee=W({queryKey:["forge-health-values",...s],queryFn:async()=>(await it(s)).values}),ze=W({queryKey:["forge-health-patterns",...s],queryFn:async()=>(await nt(s)).patterns}),De=W({queryKey:["forge-health-behaviors",...s],queryFn:async()=>(await lt(s)).behaviors}),Fe=W({queryKey:["forge-health-beliefs",...s],queryFn:async()=>(await ot(s)).beliefs}),He=W({queryKey:["forge-health-reports",...s],queryFn:async()=>(await dt(s)).reports});p.useEffect(()=>{S.data&&o(Object.fromEntries(S.data.sessions.map(a=>[a.id,U(a)])))},[S.data]),p.useEffect(()=>{if(ce||!S.data)return;const d=(S.data.analysisSessions??S.data.sessions).find(Ct);d&&u([`type:${d.workoutType}`]),Me(!0)},[ce,S.data]);const re=Ge({mutationFn:async a=>st(a.workoutId,{subjectiveEffort:a.subjectiveEffort.trim().length>0?Number(a.subjectiveEffort):null,moodBefore:a.moodBefore,moodAfter:a.moodAfter,meaningText:a.meaningText,plannedContext:a.plannedContext,socialContext:a.socialContext,tags:a.tagsText.split(",").map(d=>d.trim()).filter(Boolean),links:ht(a.linkValues)}),onSuccess:async()=>{await r.invalidateQueries({queryKey:["forge-fitness"]})}}),F=S.data,A=(F==null?void 0:F.sessions)??[],O=(F==null?void 0:F.analysisSessions)??A,Le=pt({goals:t.snapshot.dashboard.goals,projects:t.snapshot.dashboard.projects,tasks:t.snapshot.dashboard.tasks,habits:t.snapshot.dashboard.habits,values:Ee.data??[],patterns:ze.data??[],behaviors:De.data??[],beliefs:Fe.data??[],reports:He.data??[]}),$e=p.useMemo(()=>St(A),[A]),_e=p.useMemo(()=>Tt(O),[O]),I=p.useMemo(()=>{const a=Ae(h);return[...A].sort((d,m)=>new Date(m.startedAt).getTime()-new Date(d.startedAt).getTime()).filter(d=>{const m=l[d.id]??U(d);return(a.length===0||wt(d,m).includes(a))&&At(d,j)})},[l,h,j,A]),xe=p.useMemo(()=>Mt(O,n,N,D,L),[N,L,O,D,n]),me=I.length===A.length&&h.trim().length===0&&j.length===0?`${A.length} workout sessions visible`:`${I.length} of ${A.length} workout sessions visible`,R=I.find(a=>a.id===ue)??A.find(a=>a.id===ue)??null,pe=R?l[R.id]??U(R):null;if(S.isLoading)return e.jsx(Je,{eyebrow:"Sports",title:"Loading sports view",description:"Reading synced workouts and local reflection metadata.",columns:2,blocks:6});if(S.isError||!F)return e.jsx(et,{eyebrow:"Sports",error:S.error??new Error("Sports data unavailable"),onRetry:()=>void S.refetch()});const{summary:v,weeklyTrend:he,typeBreakdown:Oe}=F,ve=v.zoneMix??[],C=Et(xe,F.vitalsTrend),ge=n.length===0?"All exercise types":C.exerciseLabels.length>0?C.exerciseLabels.join(", "):`${n.length} selected types`,We=ve.map(a=>({zone:a.label,minutes:Math.round(a.seconds/60),percentage:Math.round(a.percentage*100),fill:G[a.key]??"#f8fafc"})),Ke=he.map(a=>{const d=Object.fromEntries((a.zoneDurations??[]).map(m=>[m.key,Math.round(m.seconds/60)]));return{date:a.dateKey.slice(5),duration:a.durationMinutes,load:a.trainingLoad??0,coverage:Math.round((a.heartRateCoverage??0)*100),...d}}),Be=O.map(a=>{var d,m,E,$;return{duration:Math.round(a.durationSeconds/60),intensity:Math.round((((m=(d=a.analytics)==null?void 0:d.load)==null?void 0:m.intensity)??0)*100),load:(($=(E=a.analytics)==null?void 0:E.load)==null?void 0:$.trimp)??0,type:k(a),name:k(a)}});function Ve(a,d){o(m=>{const E=m[a]??U(A.find($=>$.id===a));return{...m,[a]:{...E,...d}}})}async function Ie(a){const d=A.find(E=>E.id===a);if(!d)return;const m=l[a]??U(d);await re.mutateAsync({workoutId:a,subjectiveEffort:m.subjectiveEffort,moodBefore:m.moodBefore,moodAfter:m.moodAfter,meaningText:m.meaningText,plannedContext:m.plannedContext,socialContext:m.socialContext,tagsText:m.tagsText,linkValues:m.linkValues}),se(null),X(0)}return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(ct,{entityKind:"project",title:"Sports",description:"A session-first training surface for workout data, subjective meaning, and links back into Forge execution and Psyche.",badge:`${A.length} sessions`}),e.jsx(ut,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-4",children:[e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Weekly volume"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--primary)]",children:B(v.weeklyVolumeSeconds)}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Total training time in the recent week."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Exercise minutes"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.exerciseMinutes}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Aggregate exercise minutes from synced sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Energy burned"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.energyBurnedKcal}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Recent weekly kcal."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training streak"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.streakDays}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Distinct workout days in the recent week."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Average session"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[v.averageSessionMinutes,"m"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Mean duration across recent sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training load"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.totalTrainingLoad??"n/a"}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Forge TRIMP across recent sessions."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Linked sessions"}),e.jsx("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:v.linkedSessionCount}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Sessions already tied to Forge or Psyche entities."})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"HR coverage"}),e.jsxs("div",{className:"mt-3 font-display text-4xl text-[var(--ui-ink-strong)]",children:[Math.round((v.averageHeartRateCoverage??0)*100),"%"]}),e.jsx("div",{className:"mt-2 text-sm text-[var(--ui-ink-soft)]",children:"Average raw HR sample coverage."})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,1.1fr)_minmax(320px,0.9fr)]",children:[e.jsxs(g,{className:"min-h-[320px]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Load and volume trend"}),e.jsx(Z,{className:"mt-4 h-[260px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(vt,{data:Ke,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:"sportsLoad",x1:"0",y1:"0",x2:"0",y2:"1",children:[e.jsx("stop",{offset:"0%",stopColor:"#f97316",stopOpacity:.36}),e.jsx("stop",{offset:"100%",stopColor:"#f97316",stopOpacity:.04})]})}),e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"date",tick:{fill:"var(--ui-ink-faint)",fontSize:11}}),e.jsx(K,{tick:{fill:"var(--ui-ink-faint)",fontSize:11},width:34}),e.jsx(Q,{contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ke,{type:"monotone",dataKey:"load",stroke:"#f97316",fill:"url(#sportsLoad)",strokeWidth:2}),e.jsx(ke,{type:"monotone",dataKey:"duration",stroke:"#38bdf8",fill:"var(--ui-info-soft)",strokeWidth:2})]})})})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Zone distribution"}),e.jsx("div",{className:"mt-4 grid gap-3",children:ve.map(a=>e.jsxs("div",{className:"grid gap-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 text-sm",children:[e.jsx("span",{className:"text-[var(--ui-ink)]",children:a.label}),e.jsxs("span",{className:"text-[var(--ui-ink-strong)]",children:[Math.round(a.percentage*100),"% ·"," ",B(a.seconds)]})]}),e.jsx("div",{className:"h-2 overflow-hidden rounded-full bg-[var(--ui-surface-3)]",children:e.jsx("div",{className:"h-full rounded-full",style:{width:`${Math.max(1,a.percentage*100)}%`,background:G[a.key]??"#f8fafc"}})})]},a.key))}),e.jsx(Z,{className:"mt-5 h-[180px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ye,{data:We,children:[e.jsx(q,{dataKey:"zone",tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(K,{tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:34}),e.jsx(Q,{contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ne,{dataKey:"minutes",fill:"#f97316",radius:[4,4,0,0]})]})})})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4",children:[e.jsxs(g,{className:"grid gap-4 overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"HR zone analysis"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Filter all-time workout evidence by exercise type and date."})]}),e.jsxs(c,{tone:"meta",children:[xe.length," of ",O.length," ","sessions"]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,1fr)_minmax(280px,0.8fr)]",children:[e.jsx(je,{title:"Exercise types",description:"Select one, many, or none for all exercise types.",query:x,onQueryChange:w,options:_e,selectedOptionIds:n,onSelectedOptionIdsChange:u,resultSummary:ge,placeholder:"Search exercise types",emptyStateMessage:"No exercise type matches."}),e.jsxs("div",{className:"grid gap-3 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Date range"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[["all","All time"],["recent_90","90 days"],["custom","Custom"]].map(([a,d])=>e.jsx("button",{type:"button",className:`rounded-[8px] border px-3 py-2 text-sm transition ${N===a?"border-[var(--primary)] bg-[var(--primary)]/12 text-[var(--ui-ink-strong)]":"border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>T(a),children:d},a))}),e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Start"}),e.jsx(H,{type:"date",value:D,onChange:a=>{i(a.target.value),T("custom")}})]}),e.jsxs("label",{className:"grid gap-2",children:[e.jsx("span",{className:"text-sm text-[var(--ui-ink-soft)]",children:"End"}),e.jsx(H,{type:"date",value:L,onChange:a=>{Te(a.target.value),T("custom")}})]})]})]})]})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-[minmax(0,0.85fr)_minmax(0,1.15fr)]",children:[e.jsxs(g,{className:"min-h-[330px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Average zones"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Duration-weighted proportion of time in each HR zone."})]}),e.jsx(c,{tone:"meta",children:ge})]}),e.jsx(Z,{className:"mt-4 h-[235px]",children:C.sessions.length>0?e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ye,{data:C.averageZoneData,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"zone",interval:0,tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(K,{unit:"%",domain:[0,100],ticks:[0,25,50,75,100],tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:38}),e.jsx(Q,{formatter:a=>[`${a}%`,"Average time"],contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(ne,{dataKey:"percentage",radius:[4,4,0,0],children:C.averageZoneData.map(a=>e.jsx(gt,{fill:a.fill},a.key))})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 text-center text-sm leading-6 text-[var(--ui-ink-soft)]",children:"No selected sessions with zone analytics are available yet."})}),C.sessions.length>0?e.jsxs("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)] sm:grid-cols-3",children:[e.jsxs("div",{children:[C.rawHrCount," sessions have raw HR timelines"]}),e.jsxs("div",{children:["Latest: ",((fe=C.lineData.at(-1))==null?void 0:fe.dateKey)??"n/a"]}),e.jsxs("div",{children:["VO2max points:"," ",C.lineData.filter(a=>a.vo2Max!=null).length]})]}):null]}),e.jsxs(g,{className:"min-h-[330px] overflow-hidden",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:y==="expanding_lines"?"Expanding zone lines":"Zone drift"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:y==="expanding_lines"?"Expanding all-session average with resting HR and VO2max overlay.":"Rolling duration-weighted zone mix with resting HR and VO2max overlay."})]}),e.jsxs("div",{className:"flex w-full flex-col gap-2 sm:w-auto sm:items-end",children:[e.jsx("div",{className:"grid grid-cols-2 gap-1 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-1","aria-label":"Zone chart display",children:[["rolling_stack","Stacked"],["expanding_lines","Lines"]].map(([a,d])=>e.jsx("button",{type:"button",className:`min-h-9 rounded-[6px] px-3 py-1.5 text-xs font-medium transition ${y===a?"bg-[var(--primary)]/18 text-[var(--ui-ink-strong)]":"text-[var(--ui-ink-soft)] hover:bg-[var(--ui-surface-2)] hover:text-[var(--ui-ink-strong)]"}`,onClick:()=>M(a),children:d},a))}),e.jsx(c,{tone:"meta",children:"HRR zones"})]})]}),e.jsx(Z,{className:"mt-4 h-[255px]",children:C.lineData.length>0?e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(ft,{data:y==="expanding_lines"?C.expandingLineData:C.lineData,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)",vertical:!1}),e.jsx(q,{dataKey:"date",tick:{fill:"var(--ui-ink-faint)",fontSize:10}}),e.jsx(K,{yAxisId:"zones",domain:[0,100],ticks:[0,25,50,75,100],unit:"%",tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:38}),e.jsx(K,{yAxisId:"vitals",orientation:"right",tick:{fill:"var(--ui-ink-faint)",fontSize:10},width:42}),e.jsx(Q,{formatter:(a,d,m)=>Rt(a,d,m),contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(bt,{wrapperStyle:{color:"var(--ui-ink)",fontSize:11}}),y==="expanding_lines"?V.map(a=>e.jsx(le,{yAxisId:"zones",type:"monotone",dataKey:a,name:z(a),stroke:G[a],strokeWidth:2,dot:{r:2.5},activeDot:{r:4},connectNulls:!0},a)):V.map(a=>e.jsx(ne,{yAxisId:"zones",dataKey:a,stackId:"zones",fill:G[a],isAnimationActive:!1},a)),e.jsx(le,{yAxisId:"vitals",type:"monotone",dataKey:"restingHeartRate",name:"Resting HR",stroke:"var(--ui-ink-soft)",strokeWidth:2,dot:{r:3},connectNulls:!0}),e.jsx(le,{yAxisId:"vitals",type:"monotone",dataKey:"vo2Max",name:"VO2max",stroke:"#a78bfa",strokeWidth:2,dot:{r:3},connectNulls:!0})]})}):e.jsx("div",{className:"grid h-full place-items-center rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-6 text-center text-sm leading-6 text-[var(--ui-ink-soft)]",children:"Select workouts with HR evidence to unlock the time-series plot."})})]})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[minmax(0,1fr)_360px]",children:[e.jsxs(g,{className:"min-h-[300px]",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Duration vs intensity"}),e.jsx(Z,{className:"mt-4 h-[250px]",children:e.jsx(P,{width:"100%",height:"100%",minWidth:1,minHeight:1,children:e.jsxs(jt,{data:Be,children:[e.jsx(ee,{stroke:"var(--ui-border-subtle)"}),e.jsx(q,{type:"number",dataKey:"duration",name:"minutes",tick:{fill:"var(--ui-ink-faint)",fontSize:11}}),e.jsx(K,{type:"number",dataKey:"intensity",name:"intensity",tick:{fill:"var(--ui-ink-faint)",fontSize:11},width:38}),e.jsx(Q,{cursor:{strokeDasharray:"3 3"},contentStyle:{background:"var(--ui-surface-popover)",border:"1px solid var(--ui-border-strong)",borderRadius:8,color:"var(--ui-ink-strong)"}}),e.jsx(kt,{dataKey:"load",fill:"#f97316"})]})})})]}),e.jsxs(g,{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Evidence quality"}),e.jsxs("div",{className:"mt-4 grid gap-3",children:[e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Raw HR coverage"}),e.jsxs("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:[Math.round((v.averageHeartRateCoverage??0)*100),"%"]})]}),e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Route-backed workouts"}),e.jsx("div",{className:"mt-2 text-2xl text-[var(--ui-ink-strong)]",children:v.routeWorkoutCount??0})]}),e.jsxs("div",{className:"rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Top sport"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.topWorkoutTypeLabel??v.topWorkoutType??"n/a"})]})]})]})]})}),e.jsx(J,{children:e.jsxs("section",{className:"grid gap-4 lg:grid-cols-[1.05fr_0.95fr]",children:[e.jsxs(g,{className:"grid gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Recent volume"}),e.jsx("div",{className:"grid gap-3",children:he.map(a=>e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 md:grid-cols-[110px_150px_minmax(0,1fr)_90px]",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:a.dateKey}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:a.workoutTypeLabel??z(a.workoutType)}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-2 flex-1 overflow-hidden rounded-full bg-[var(--ui-surface-3)]",children:e.jsx("div",{className:"h-full rounded-full bg-[var(--primary)]",style:{width:`${Math.min(100,a.durationMinutes/120*100)}%`}})}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-strong)]",children:[a.durationMinutes,"m"]})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:[a.energyKcal," kcal"]})]},a.id))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Distance"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:de(v.distanceMeters)})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Planned sessions"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.plannedSessionCount})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Imported / merged"}),e.jsxs("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:[v.importedSessionCount," /"," ",v.reconciledSessionCount]})]})]})]}),e.jsxs(g,{className:"grid gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Training composition"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Workout type and provenance mix"})]}),e.jsx("div",{className:"grid gap-3",children:Oe.slice(0,6).map(a=>e.jsxs("div",{className:"grid gap-2 rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 md:grid-cols-[minmax(0,1fr)_90px_90px]",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[var(--ui-ink-strong)]",children:a.workoutTypeLabel??z(a.workoutType)}),e.jsxs("div",{className:"mt-1 text-sm text-[var(--ui-ink-soft)]",children:[a.sessionCount," sessions ·"," ",a.activityFamilyLabel??"Other"]})]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink)]",children:[a.totalMinutes,"m"]}),e.jsxs("div",{className:"text-sm text-[var(--ui-ink)]",children:[a.energyKcal," kcal"]})]},a.workoutType))}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Habit-generated"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.habitGeneratedSessionCount})]}),e.jsxs("div",{className:"rounded-[18px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-4",children:[e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Forge-linked"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:v.linkedSessionCount})]})]})]})]})}),e.jsx(xt,{children:e.jsxs("section",{className:"grid gap-4 xl:grid-cols-[minmax(0,25rem)_minmax(0,1fr)]",children:[e.jsx(je,{title:"Session browser",description:"Search past activities by workout type, source, reconciliation state, or whether they still need context.",query:h,onQueryChange:f,options:$e,selectedOptionIds:j,onSelectedOptionIdsChange:b,resultSummary:me,placeholder:"Search workouts, devices, notes, moods, or filter chips",emptyStateMessage:"Keep typing or pick a filter chip to narrow the activity history."}),e.jsxs(g,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:"Activity history"}),e.jsx("div",{className:"mt-2 text-lg text-[var(--ui-ink-strong)]",children:"Open a workout to add reflection and links in a guided modal."})]}),e.jsx(c,{tone:"meta",children:me})]}),e.jsx("div",{className:"max-h-[34rem] overflow-y-auto rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] p-3",children:I.length===0?e.jsx("div",{className:"flex min-h-[18rem] items-center justify-center p-6 text-center text-sm leading-6 text-[var(--ui-ink-faint)]",children:"No workout matches the current search yet. Clear some filters or search by workout type, device, or reflection text."}):e.jsx("div",{className:"grid gap-3",children:I.map(a=>{var m,E,$;const d=a.meaningText.trim().length>0||a.moodBefore.trim().length>0||a.moodAfter.trim().length>0||a.tags.length>0||a.links.length>0;return e.jsxs("div",{className:"grid w-full min-w-0 gap-3 rounded-[8px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-3 text-left transition hover:bg-[var(--ui-surface-2)]",children:[e.jsxs("div",{className:"grid min-w-0 gap-3 sm:flex sm:items-start sm:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs(Pe,{to:`/sports/workouts/${a.id}`,className:"flex min-w-0 items-center gap-2 text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:[e.jsx(we,{className:"size-4 shrink-0 text-[var(--primary)]"}),e.jsx("span",{className:"truncate text-base font-medium",children:k(a)})]}),e.jsxs("div",{className:"mt-2 flex min-w-0 items-center gap-2 text-sm text-[var(--ui-ink-soft)]",children:[e.jsx(qe,{className:"size-3.5 shrink-0"}),e.jsx("span",{className:"min-w-0 truncate",children:Y(a.startedAt,a.endedAt)})]}),e.jsxs("div",{className:"mt-2 text-sm text-[var(--ui-ink-faint)]",children:[_(a)," ·"," ",a.sourceDevice]})]}),e.jsxs("button",{type:"button","aria-label":`Edit ${k(a)} reflection`,className:"inline-flex w-fit max-w-full items-center gap-2 rounded-full bg-[var(--ui-surface-2)] px-3 py-1.5 text-xs text-[var(--ui-ink)] transition hover:bg-[var(--ui-surface-3)] hover:text-[var(--ui-ink-strong)]",onClick:()=>{se(a.id),X(0)},children:[e.jsx("span",{className:"truncate",children:d?"Reflected":"Needs reflection"}),e.jsx(Se,{className:"size-3.5 shrink-0"})]})]}),e.jsxs("div",{className:"flex min-w-0 flex-wrap gap-2",children:[e.jsx(c,{children:B(a.durationSeconds)}),a.totalEnergyKcal?e.jsxs(c,{tone:"meta",children:[Math.round(a.totalEnergyKcal)," kcal"]}):null,a.distanceMeters?e.jsx(c,{tone:"meta",children:de(a.distanceMeters)}):null,a.averageHeartRate?e.jsxs(c,{tone:"meta",children:[e.jsx(Qe,{className:"mr-1 size-3.5"}),Math.round(a.averageHeartRate)," bpm"]}):null,e.jsx(c,{tone:"meta",children:_(a)}),e.jsx(c,{tone:"meta",className:"capitalize",children:a.sourceType.replaceAll("_"," ")}),e.jsx(c,{tone:"meta",className:"capitalize",children:a.reconciliationStatus.replaceAll("_"," ")}),(m=a.analytics)!=null&&m.confidence?e.jsxs(c,{tone:"meta",children:[a.analytics.confidence," zones"]}):null,($=(E=a.analytics)==null?void 0:E.routeSummary)!=null&&$.hasRoute?e.jsx(c,{tone:"meta",children:"Route"}):null]})]},a.id)})})})]})]})}),R&&pe?e.jsx(tt,{open:!!R,onOpenChange:a=>{a||(se(null),X(0))},eyebrow:"Sports session",title:k(R),description:"Add contextual meaning without crowding the main training surface.",children:e.jsx(zt,{session:R,draft:pe,linkOptions:Le,pending:re.isPending&&((be=re.variables)==null?void 0:be.workoutId)===R.id,step:Re,onStepChange:X,onDraftChange:a=>Ve(R.id,a),onSave:()=>void Ie(R.id)})}):null]})}export{Yt as SportsPage,Rt as formatZoneTrendTooltipValue};
|