forge-openclaw-plugin 0.3.3 → 0.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist/assets/{action-bar-5Ii4UzHa.js → action-bar-CMGr_Uv_.js} +1 -1
  2. package/dist/assets/{activity-page-CWjTKFY3.js → activity-page-DwGKkJtr.js} +1 -1
  3. package/dist/assets/{ai-surface-workspace-Dd2FSRom.js → ai-surface-workspace-UtnoNmjq.js} +1 -1
  4. package/dist/assets/{atlas-panel-Dinteouh.js → atlas-panel-f1kc-LkD.js} +1 -1
  5. package/dist/assets/{calendar-page-BWkXhzDf.js → calendar-page-C4YqeVrC.js} +1 -1
  6. package/dist/assets/{calendar-rules-CjyuTu2I.js → calendar-rules-BQppCPiN.js} +1 -1
  7. package/dist/assets/{calendar-week-toolbar-D-nd9tkk.js → calendar-week-toolbar-DdPuHUwd.js} +1 -1
  8. package/dist/assets/{companion-sync-lab-page-G0t1TqqZ.js → companion-sync-lab-page-N3cR33GS.js} +1 -1
  9. package/dist/assets/{daily-metrics-dashboard-DpIAdzFX.js → daily-metrics-dashboard-CXnAtN2T.js} +1 -1
  10. package/dist/assets/{define-workbench-box-BIOZopF2.js → define-workbench-box-DkffygDU.js} +1 -1
  11. package/dist/assets/{entity-link-multiselect-DZZjpL_d.js → entity-link-multiselect-wuyJ8BbW.js} +1 -1
  12. package/dist/assets/{entity-note-count-link-CmRRdXAr.js → entity-note-count-link-CEtKyMAl.js} +1 -1
  13. package/dist/assets/{entity-notes-surface-8MPDscsu.js → entity-notes-surface-iKNiierJ.js} +1 -1
  14. package/dist/assets/{execution-board-Bi8gi8J6.js → execution-board-DesFZ1f5.js} +1 -1
  15. package/dist/assets/{faceted-token-search-BGs4TqxT.js → faceted-token-search-D4Okr-Kr.js} +1 -1
  16. package/dist/assets/{flagship-signal-deck-jLxHEHvb.js → flagship-signal-deck-CW91n6u9.js} +1 -1
  17. package/dist/assets/{floating-action-menu-Itpm7T2_.js → floating-action-menu-GCeuOdYZ.js} +1 -1
  18. package/dist/assets/{generic-node-view-KePoUF3Z.js → generic-node-view-COhU_Wm3.js} +1 -1
  19. package/dist/assets/{goal-detail-page-a1lEswpJ.js → goal-detail-page-Bd8JU3IK.js} +1 -1
  20. package/dist/assets/{goal-dialog-CYgRzl4y.js → goal-dialog-CLz5fYhO.js} +1 -1
  21. package/dist/assets/{goals-page-JY_EJq9U.js → goals-page-CZHNVyY-.js} +1 -1
  22. package/dist/assets/{habits-page-BRI8AoaQ.js → habits-page-CXiBB7_N.js} +1 -1
  23. package/dist/assets/{health-boxes-DZJOFTOI.js → health-boxes-BUcsxDLh.js} +1 -1
  24. package/dist/assets/{index-wEZUnRh0.js → index-BejvcRGb.js} +2 -2
  25. package/dist/assets/{index-Bcem7l5u.css → index-CEgIwgk9.css} +1 -1
  26. package/dist/assets/{inline-note-fields-CUVRzQkI.js → inline-note-fields-CcRDO3pd.js} +1 -1
  27. package/dist/assets/{insight-flow-dialog-By73oG1H.js → insight-flow-dialog-DUBk2MR8.js} +1 -1
  28. package/dist/assets/{insights-page-DLyN-9yz.js → insights-page-8fLhCYsM.js} +1 -1
  29. package/dist/assets/{kanban-boxes-M71CejV4.js → kanban-boxes-CH7plRk1.js} +1 -1
  30. package/dist/assets/{kanban-page-InKHhJQD.js → kanban-page-Bq-aYwUL.js} +1 -1
  31. package/dist/assets/{knowledge-graph-page-C-GEQGRY.js → knowledge-graph-page-DYFfWh4Y.js} +1 -1
  32. package/dist/assets/{life-force-page-Dq88NzNp.js → life-force-page-D80rgBBR.js} +1 -1
  33. package/dist/assets/{life-force-workspace-Bl_0slZi.js → life-force-workspace-CcmZRRfU.js} +1 -1
  34. package/dist/assets/{metric-tile-yQJgjYrN.js → metric-tile-DysHMgM3.js} +1 -1
  35. package/dist/assets/{movement-boxes-C-rc3N8Z.js → movement-boxes-BH3botKt.js} +1 -1
  36. package/dist/assets/{movement-page-DK-d1uYa.js → movement-page-D5KLMKS9.js} +1 -1
  37. package/dist/assets/{note-markdown-7czv-KMH.js → note-markdown-Byd_vNkS.js} +1 -1
  38. package/dist/assets/{note-tags-input-CkgkqiT3.js → note-tags-input-DYAFDq8Q.js} +1 -1
  39. package/dist/assets/{notes-boxes-BQuR1MiB.js → notes-boxes-CPiPps1e.js} +1 -1
  40. package/dist/assets/{notes-page-ec9g1mPh.js → notes-page-DehVrOOb.js} +1 -1
  41. package/dist/assets/{open-in-graph-button-B_4fdm4l.js → open-in-graph-button-L21MKsb5.js} +1 -1
  42. package/dist/assets/{orbit-map-DPQNBqS-.js → orbit-map-ChJOQ8CN.js} +1 -1
  43. package/dist/assets/{overview-page-CZjMab2o.js → overview-page-D_ewyeWF.js} +1 -1
  44. package/dist/assets/{page-hero-BRcqE3a4.js → page-hero-DlHEJ0Yt.js} +1 -1
  45. package/dist/assets/{pill-cluster-dy6jG_dV.js → pill-cluster-DhOR4m7X.js} +1 -1
  46. package/dist/assets/{preference-entity-handoff-button-DOV-_2Vm.js → preference-entity-handoff-button-ugHU2us9.js} +1 -1
  47. package/dist/assets/{preferences-page-Co8w5hzp.js → preferences-page-BTTXeSDR.js} +1 -1
  48. package/dist/assets/{project-collections-DNgKleDl.js → project-collections-USb6PUe0.js} +1 -1
  49. package/dist/assets/{project-detail-page-C-Ib1x8w.js → project-detail-page-1tD6tUsB.js} +1 -1
  50. package/dist/assets/{project-dialog-D_hgOdB9.js → project-dialog-BaHhJqP6.js} +1 -1
  51. package/dist/assets/{project-management-hierarchy-page-asf61KSz.js → project-management-hierarchy-page-D4HV8QXs.js} +1 -1
  52. package/dist/assets/{project-management-section-nav-DAZA1oXG.js → project-management-section-nav-9OV6_ifH.js} +1 -1
  53. package/dist/assets/{projects-boxes-CHLr1Bs-.js → projects-boxes-AyudWls3.js} +1 -1
  54. package/dist/assets/{projects-page-BsM8yCqQ.js → projects-page-DizVVzbt.js} +1 -1
  55. package/dist/assets/{psyche-behaviors-page-COSZeP4J.js → psyche-behaviors-page-CX5MJjWj.js} +1 -1
  56. package/dist/assets/{psyche-flashcards-page-CJmgGL9x.js → psyche-flashcards-page-DzCGy-FV.js} +1 -1
  57. package/dist/assets/{psyche-goal-map-page-avrWNSs9.js → psyche-goal-map-page-BcKR792E.js} +1 -1
  58. package/dist/assets/{psyche-graph-BmwbnNBY.js → psyche-graph-BNllZR67.js} +1 -1
  59. package/dist/assets/{psyche-metrics-page-CY0J_aMx.js → psyche-metrics-page-CpEKlZLO.js} +1 -1
  60. package/dist/assets/{psyche-mode-guide-page-COcswIHZ.js → psyche-mode-guide-page-DXKSE2o7.js} +1 -1
  61. package/dist/assets/{psyche-modes-page-BXF_GZoP.js → psyche-modes-page-Bh6eeNm1.js} +1 -1
  62. package/dist/assets/{psyche-page-VsMBNG1F.js → psyche-page-B44RJrrC.js} +1 -1
  63. package/dist/assets/{psyche-patterns-page-DVoIro0Q.js → psyche-patterns-page-Bm7T5FMJ.js} +1 -1
  64. package/dist/assets/{psyche-questionnaire-builder-page-CahcrbQj.js → psyche-questionnaire-builder-page-BNtMNjY8.js} +1 -1
  65. package/dist/assets/{psyche-questionnaire-detail-page-CYSgADAD.js → psyche-questionnaire-detail-page-BnMXErRK.js} +1 -1
  66. package/dist/assets/{psyche-questionnaire-run-detail-page-D5q5URTu.js → psyche-questionnaire-run-detail-page-CWKxbdwZ.js} +1 -1
  67. package/dist/assets/{psyche-questionnaire-run-page-DUoA-VSs.js → psyche-questionnaire-run-page-DwH7Sk52.js} +1 -1
  68. package/dist/assets/{psyche-questionnaires-page-dbQlqbKh.js → psyche-questionnaires-page-B1t_a8QU.js} +1 -1
  69. package/dist/assets/{psyche-report-detail-page-D_Mmlf2D.js → psyche-report-detail-page-x2AtC99e.js} +1 -1
  70. package/dist/assets/{psyche-reports-page-CO3J4Js3.js → psyche-reports-page-KiwCgWPa.js} +1 -1
  71. package/dist/assets/{psyche-schemas-beliefs-page-BUNGL4zW.js → psyche-schemas-beliefs-page-CIEoAJAp.js} +1 -1
  72. package/dist/assets/{psyche-screen-time-page-Bm18uHDg.js → psyche-screen-time-page-DO6UycL9.js} +1 -1
  73. package/dist/assets/{psyche-self-observation-page-VdPMBuK4.js → psyche-self-observation-page-CPcpUSdm.js} +1 -1
  74. package/dist/assets/{psyche-values-page-DivSQodJ.js → psyche-values-page-BAgNeo4L.js} +1 -1
  75. package/dist/assets/{question-flow-dialog-Dsnsc8be.js → question-flow-dialog-BByFV8Yw.js} +1 -1
  76. package/dist/assets/{report-chain-fields-Bf-WCSJQ.js → report-chain-fields-BpRWMp7h.js} +1 -1
  77. package/dist/assets/{rewards-page-CI53Cp0i.js → rewards-page-kIiX8SHn.js} +1 -1
  78. package/dist/assets/{scheduling-rules-editor-Bg3QU_qt.js → scheduling-rules-editor-oQXGcL5l.js} +1 -1
  79. package/dist/assets/{schema-badge-CRThEDqP.js → schema-badge-BoNjw3h4.js} +1 -1
  80. package/dist/assets/{schemas-B8-kIOFQ.js → schemas-IBbtdPzn.js} +1 -1
  81. package/dist/assets/{select-menu-rT3Qd5t5.js → select-menu-U-YryCwP.js} +1 -1
  82. package/dist/assets/{settings-agents-page-VDUv2WuO.js → settings-agents-page-CbHeMq3e.js} +1 -1
  83. package/dist/assets/{settings-bin-page-DfuGJVqc.js → settings-bin-page-LxS2YPsA.js} +1 -1
  84. package/dist/assets/{settings-calendar-page-ex7eHB1y.js → settings-calendar-page-CZc-I-HK.js} +1 -1
  85. package/dist/assets/{settings-data-page-BPWyPVGo.js → settings-data-page-m-aBRMR9.js} +1 -1
  86. package/dist/assets/{settings-logs-page-CwTT4n63.js → settings-logs-page-BUEGWlQu.js} +1 -1
  87. package/dist/assets/{settings-mobile-page-B6sVk872.js → settings-mobile-page-C_5CHjHl.js} +1 -1
  88. package/dist/assets/{settings-models-page-Dq5XViZd.js → settings-models-page-B4HQu8kL.js} +1 -1
  89. package/dist/assets/{settings-page-BRxdAxbS.js → settings-page-CY8N-fNV.js} +1 -1
  90. package/dist/assets/{settings-rewards-page-DRvxTwv3.js → settings-rewards-page-C0XQoWjb.js} +1 -1
  91. package/dist/assets/{settings-section-nav-D_vKvOWd.js → settings-section-nav-CkqqtM0F.js} +1 -1
  92. package/dist/assets/{settings-users-page-B6oSpOaV.js → settings-users-page-COCBOq7d.js} +1 -1
  93. package/dist/assets/{settings-wiki-page-Bkv-SS3J.js → settings-wiki-page-Dy1d7-z-.js} +1 -1
  94. package/dist/assets/{sleep-page-DELXxo6j.js → sleep-page-1kKicdFq.js} +1 -1
  95. package/dist/assets/{sports-page-ByWQL0Gf.js → sports-page-DJErRii_.js} +1 -1
  96. package/dist/assets/{strategies-page-PuUHsaSJ.js → strategies-page-CWNFb9vv.js} +1 -1
  97. package/dist/assets/{strategy-detail-page-CSyVdv29.js → strategy-detail-page-D9rFVXRS.js} +1 -1
  98. package/dist/assets/{strategy-dialog-Fgpc0z1M.js → strategy-dialog-BIVHfUR6.js} +1 -1
  99. package/dist/assets/{surface-DzVqQDmf.js → surface-B3oXO1No.js} +1 -1
  100. package/dist/assets/{task-detail-page-BoLvJ_4F.js → task-detail-page-r8ipOpAF.js} +1 -1
  101. package/dist/assets/{task-dialog-B2cGkhLk.js → task-dialog-C3kkWtcT.js} +1 -1
  102. package/dist/assets/{timebox-planning-dialog-BjiC2jh0.js → timebox-planning-dialog-BadS5tEr.js} +1 -1
  103. package/dist/assets/{today-boxes-B4f4sBXg.js → today-boxes-CiccN0Gw.js} +1 -1
  104. package/dist/assets/{today-page-Cusp2JI8.js → today-page-DvQredbl.js} +1 -1
  105. package/dist/assets/{training-load-page-CsZbK6rY.js → training-load-page-CkX-nSoe.js} +1 -1
  106. package/dist/assets/{user-badge-CQygGKVs.js → user-badge-BKzwGZDd.js} +1 -1
  107. package/dist/assets/{utility-widgets-DRESNarT.js → utility-widgets-DvxKA6dI.js} +1 -1
  108. package/dist/assets/{vitals-page-BlTZ4f78.js → vitals-page-CRIsr_C7.js} +1 -1
  109. package/dist/assets/{weekly-review-page-3Pk3NeGE.js → weekly-review-page-CNqxLRCd.js} +1 -1
  110. package/dist/assets/{weight-loss-page-CRCtv1fX.js → weight-loss-page-SSsCp1Yw.js} +3 -3
  111. package/dist/assets/{wiki-article-markdown-D0PWvioX.js → wiki-article-markdown-C9VKineE.js} +1 -1
  112. package/dist/assets/{wiki-editor-page-OZMYUgFo.js → wiki-editor-page-DxGsKvF7.js} +1 -1
  113. package/dist/assets/{wiki-ingest-history-page-DXZHzAqU.js → wiki-ingest-history-page-CFmP7K1F.js} +1 -1
  114. package/dist/assets/{wiki-ingest-modal-Ro0V4UMB.js → wiki-ingest-modal-BLw2PSWP.js} +1 -1
  115. package/dist/assets/{wiki-page-B1g3Rfxy.js → wiki-page-BiQ-jAuz.js} +1 -1
  116. package/dist/assets/{workbench-flow-page-qh5nItU6.js → workbench-flow-page-D960hXu_.js} +1 -1
  117. package/dist/assets/{workbench-page-CFWfAYMV.js → workbench-page-BWlY-FiL.js} +1 -1
  118. package/dist/assets/{workout-detail-page-Cw6t6Xj9.js → workout-detail-page-G32yJoE9.js} +1 -1
  119. package/dist/index.html +2 -2
  120. package/openclaw.plugin.json +1 -1
  121. package/package.json +1 -1
@@ -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-DZZjpL_d.js";import{F as je}from"./faceted-token-search-BGs4TqxT.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-wEZUnRh0.js";import{P as ct}from"./page-hero-BRcqE3a4.js";import{c as ut,d as J,e as xt}from"./health-boxes-DZJOFTOI.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-KePoUF3Z.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-BIOZopF2.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-Cpmju3nw.js";import{j as Ue,i as W,k as Ge}from"./state-BtwEvpO6.js";import{E as Ye}from"./entity-link-multiselect-wuyJ8BbW.js";import{F as je}from"./faceted-token-search-D4Okr-Kr.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-BejvcRGb.js";import{P as ct}from"./page-hero-DlHEJ0Yt.js";import{c as ut,d as J,e as xt}from"./health-boxes-BUcsxDLh.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-COhU_Wm3.js";import"./graph-Cd5WF3lw.js";import"./define-workbench-box-DkffygDU.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 +1 @@
1
- import{b6 as _,bY as U,r as n,j as e,bX as z,b7 as A,c8 as O,c1 as Q}from"./vendor-Cpmju3nw.js";import{j as $,k as I}from"./state-BtwEvpO6.js";import{b as F,S as G}from"./strategy-dialog-Fgpc0z1M.js";import{P as R}from"./page-hero-BRcqE3a4.js";import{U as H}from"./user-badge-CQygGKVs.js";import{d as K,B as o,C as M,I as X,h as Y,k as m,bo as J,bp as V,bq as W}from"./index-wEZUnRh0.js";import{g as Z}from"./user-ownership-DJGl4rAj.js";import"./board-CLOHbg6t.js";import"./question-flow-dialog-Dsnsc8be.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./user-select-field-BNqv8-wd.js";import"./forms-C5d5hTf2.js";function ee(a){return a.trim().toLowerCase()}function ue(){const a=K(),h=_(),B=$(),[v,j]=U(),[E,l]=n.useState(!1),[T,d]=n.useState(null),[x,q]=n.useState(""),D=Z(a.selectedUserIds);n.useEffect(()=>{v.get("create")==="1"&&(d(null),l(!0),j(s=>{const t=new URLSearchParams(s);return t.delete("create"),t},{replace:!0}))},[v,j]);const f=async()=>{await B.invalidateQueries({queryKey:["strategy-detail"]}),await a.refresh()},N=I({mutationFn:async({input:s,strategyId:t})=>t?(await V(t,s)).strategy:(await W(s)).strategy,onSuccess:async()=>{await f()}}),p=I({mutationFn:async s=>J(s),onSuccess:async()=>{await f()}}),k=n.useMemo(()=>new Map(a.snapshot.goals.map(s=>[s.id,s])),[a.snapshot.goals]),u=n.useMemo(()=>new Map(a.snapshot.dashboard.projects.map(s=>[s.id,s])),[a.snapshot.dashboard.projects]),b=n.useMemo(()=>new Map(a.snapshot.tasks.map(s=>[s.id,s])),[a.snapshot.tasks]),S=n.useMemo(()=>{const s=ee(x);return s?a.snapshot.strategies.filter(t=>{var w,y,C;const g=t.targetGoalIds.map(c=>{var r;return((r=k.get(c))==null?void 0:r.title)??""}).join(" "),i=t.targetProjectIds.map(c=>{var r;return((r=u.get(c))==null?void 0:r.title)??""}).join(" "),L=t.graph.nodes.map(c=>{var r,P;return c.entityType==="project"?((r=u.get(c.entityId))==null?void 0:r.title)??"":((P=b.get(c.entityId))==null?void 0:P.title)??""}).join(" ");return[t.title,t.overview,t.endStateDescription,t.status,((w=t.user)==null?void 0:w.displayName)??"",((y=t.user)==null?void 0:y.handle)??"",((C=t.user)==null?void 0:C.kind)??"",g,i,L].join(" ").toLowerCase().includes(s)}):a.snapshot.strategies},[k,u,x,a.snapshot.strategies,b]);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(R,{title:"Strategies",titleText:"Strategies",description:"Strategies connect human and bot work into a directed plan, with explicit end goals, ownership, and live alignment metrics.",badge:`${a.snapshot.strategies.length} strategies`,actions:e.jsxs(o,{onClick:()=>{d(null),l(!0)},children:[e.jsx(z,{className:"size-4"}),"New strategy"]})}),e.jsxs(M,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{className:"size-4 text-[var(--ui-ink-muted)]"}),e.jsx(X,{value:x,onChange:s=>q(s.target.value),placeholder:"Search strategy title, target, graph node, human, or bot"})]}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Search includes owners, target goals/projects, and graph nodes so cross-user plans stay discoverable."})]}),S.length===0?e.jsx(Y,{eyebrow:"Strategies",title:"No strategies in this scope",description:"Create a strategy to connect projects and tasks into a non-looping execution plan across human and bot actors.",action:e.jsx(o,{onClick:()=>{d(null),l(!0)},children:"Create strategy"})}):e.jsx("div",{className:"grid gap-4",children:S.map(s=>{const t=s.graph.nodes.filter(i=>s.metrics.activeNodeIds.includes(i.id)),g=F(s.metrics);return e.jsxs(M,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("button",{type:"button",className:"text-left",onClick:()=>h(`/strategies/${s.id}`),children:[e.jsx("div",{className:"font-display text-2xl text-[var(--ui-ink-strong)]",children:s.title}),e.jsx("div",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:s.overview||s.endStateDescription})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(H,{user:s.user}),e.jsx(m,{className:s.isLocked?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",children:s.isLocked?"Contract locked":"Editable draft"}),e.jsx(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:s.status}),e.jsxs(m,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[s.metrics.alignmentScore,"% aligned"]})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Graph progress"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.startedNodeCount,"/",s.metrics.totalNodeCount]}),e.jsxs("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:[s.metrics.completedNodeCount," completed"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ready branches"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:s.metrics.readyNodeCount}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Nodes whose prerequisites are already satisfied."})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"End targets"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.completedTargetCount,"/",s.metrics.totalTargetCount||0]}),e.jsxs("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:[s.metrics.targetProgressScore,"% target progress"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Sequencing"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.sequencingScore,"%"]})]})]}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.2fr)_minmax(16rem,0.8fr)]",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Active next nodes"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.length===0?e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"No currently open branch."}):t.map(i=>e.jsx(m,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:i.title},i.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Alignment breakdown"}),e.jsx("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)]",children:g.map(i=>e.jsxs("div",{children:[i.label," ",i.value,"%"]},i.id))})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-end justify-end gap-2",children:[s.isLocked?null:e.jsxs(o,{variant:"secondary",onClick:()=>{d(s),l(!0)},children:[e.jsx(O,{className:"size-4"}),"Edit"]}),e.jsxs(o,{variant:"secondary",pending:p.isPending&&p.variables===s.id,pendingLabel:"Deleting strategy",onClick:()=>{window.confirm(`Delete strategy "${s.title}"?`)&&p.mutateAsync(s.id)},children:[e.jsx(Q,{className:"size-4"}),"Delete"]}),e.jsx(o,{onClick:()=>h(`/strategies/${s.id}`),children:"Open strategy"})]})]})]},s.id)})}),e.jsx(G,{open:E,pending:N.isPending,editingStrategy:T,goals:a.snapshot.dashboard.goals,projects:a.snapshot.dashboard.projects,tasks:a.snapshot.tasks,habits:a.snapshot.habits,strategies:a.snapshot.strategies,users:a.snapshot.users,defaultUserId:D,onOpenChange:l,onSubmit:async(s,t)=>{await N.mutateAsync({input:s,strategyId:t})}})]})}export{ue as StrategiesPage};
1
+ import{b6 as _,bY as U,r as n,j as e,bX as z,b7 as A,c8 as O,c1 as Q}from"./vendor-Cpmju3nw.js";import{j as $,k as I}from"./state-BtwEvpO6.js";import{b as F,S as G}from"./strategy-dialog-BIVHfUR6.js";import{P as R}from"./page-hero-DlHEJ0Yt.js";import{U as H}from"./user-badge-BKzwGZDd.js";import{d as K,B as o,C as M,I as X,h as Y,k as m,bo as J,bp as V,bq as W}from"./index-BejvcRGb.js";import{g as Z}from"./user-ownership-DJGl4rAj.js";import"./board-CLOHbg6t.js";import"./question-flow-dialog-BByFV8Yw.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./user-select-field-BNqv8-wd.js";import"./forms-C5d5hTf2.js";function ee(a){return a.trim().toLowerCase()}function ue(){const a=K(),h=_(),B=$(),[v,j]=U(),[E,l]=n.useState(!1),[T,d]=n.useState(null),[x,q]=n.useState(""),D=Z(a.selectedUserIds);n.useEffect(()=>{v.get("create")==="1"&&(d(null),l(!0),j(s=>{const t=new URLSearchParams(s);return t.delete("create"),t},{replace:!0}))},[v,j]);const f=async()=>{await B.invalidateQueries({queryKey:["strategy-detail"]}),await a.refresh()},N=I({mutationFn:async({input:s,strategyId:t})=>t?(await V(t,s)).strategy:(await W(s)).strategy,onSuccess:async()=>{await f()}}),p=I({mutationFn:async s=>J(s),onSuccess:async()=>{await f()}}),k=n.useMemo(()=>new Map(a.snapshot.goals.map(s=>[s.id,s])),[a.snapshot.goals]),u=n.useMemo(()=>new Map(a.snapshot.dashboard.projects.map(s=>[s.id,s])),[a.snapshot.dashboard.projects]),b=n.useMemo(()=>new Map(a.snapshot.tasks.map(s=>[s.id,s])),[a.snapshot.tasks]),S=n.useMemo(()=>{const s=ee(x);return s?a.snapshot.strategies.filter(t=>{var w,y,C;const g=t.targetGoalIds.map(c=>{var r;return((r=k.get(c))==null?void 0:r.title)??""}).join(" "),i=t.targetProjectIds.map(c=>{var r;return((r=u.get(c))==null?void 0:r.title)??""}).join(" "),L=t.graph.nodes.map(c=>{var r,P;return c.entityType==="project"?((r=u.get(c.entityId))==null?void 0:r.title)??"":((P=b.get(c.entityId))==null?void 0:P.title)??""}).join(" ");return[t.title,t.overview,t.endStateDescription,t.status,((w=t.user)==null?void 0:w.displayName)??"",((y=t.user)==null?void 0:y.handle)??"",((C=t.user)==null?void 0:C.kind)??"",g,i,L].join(" ").toLowerCase().includes(s)}):a.snapshot.strategies},[k,u,x,a.snapshot.strategies,b]);return e.jsxs("div",{className:"grid gap-5",children:[e.jsx(R,{title:"Strategies",titleText:"Strategies",description:"Strategies connect human and bot work into a directed plan, with explicit end goals, ownership, and live alignment metrics.",badge:`${a.snapshot.strategies.length} strategies`,actions:e.jsxs(o,{onClick:()=>{d(null),l(!0)},children:[e.jsx(z,{className:"size-4"}),"New strategy"]})}),e.jsxs(M,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(A,{className:"size-4 text-[var(--ui-ink-muted)]"}),e.jsx(X,{value:x,onChange:s=>q(s.target.value),placeholder:"Search strategy title, target, graph node, human, or bot"})]}),e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"Search includes owners, target goals/projects, and graph nodes so cross-user plans stay discoverable."})]}),S.length===0?e.jsx(Y,{eyebrow:"Strategies",title:"No strategies in this scope",description:"Create a strategy to connect projects and tasks into a non-looping execution plan across human and bot actors.",action:e.jsx(o,{onClick:()=>{d(null),l(!0)},children:"Create strategy"})}):e.jsx("div",{className:"grid gap-4",children:S.map(s=>{const t=s.graph.nodes.filter(i=>s.metrics.activeNodeIds.includes(i.id)),g=F(s.metrics);return e.jsxs(M,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-start justify-between gap-3",children:[e.jsx("div",{className:"min-w-0",children:e.jsxs("button",{type:"button",className:"text-left",onClick:()=>h(`/strategies/${s.id}`),children:[e.jsx("div",{className:"font-display text-2xl text-[var(--ui-ink-strong)]",children:s.title}),e.jsx("div",{className:"mt-2 max-w-3xl text-sm leading-6 text-[var(--ui-ink-soft)]",children:s.overview||s.endStateDescription})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(H,{user:s.user}),e.jsx(m,{className:s.isLocked?"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_76%,var(--ui-ink-strong)_24%)]":"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_76%,var(--ui-ink-strong)_24%)]",children:s.isLocked?"Contract locked":"Editable draft"}),e.jsx(m,{className:"bg-[var(--ui-surface-2)] text-[var(--ui-ink-medium)]",children:s.status}),e.jsxs(m,{className:"bg-[var(--primary)]/14 text-[var(--primary)]",children:[s.metrics.alignmentScore,"% aligned"]})]})]}),e.jsxs("div",{className:"grid gap-3 lg:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Graph progress"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.startedNodeCount,"/",s.metrics.totalNodeCount]}),e.jsxs("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:[s.metrics.completedNodeCount," completed"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Ready branches"}),e.jsx("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:s.metrics.readyNodeCount}),e.jsx("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:"Nodes whose prerequisites are already satisfied."})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"End targets"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.completedTargetCount,"/",s.metrics.totalTargetCount||0]}),e.jsxs("div",{className:"text-xs leading-5 text-[var(--ui-ink-soft)]",children:[s.metrics.targetProgressScore,"% target progress"]})]}),e.jsxs("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Sequencing"}),e.jsxs("div",{className:"mt-2 text-xl text-[var(--ui-ink-strong)]",children:[s.metrics.sequencingScore,"%"]})]})]}),e.jsxs("div",{className:"grid gap-3 xl:grid-cols-[minmax(0,1.2fr)_minmax(16rem,0.8fr)]",children:[e.jsx("div",{className:"rounded-[18px] bg-[var(--ui-surface-2)] px-4 py-4",children:e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Active next nodes"}),e.jsx("div",{className:"mt-3 flex flex-wrap gap-2",children:t.length===0?e.jsx("div",{className:"text-sm text-[var(--ui-ink-soft)]",children:"No currently open branch."}):t.map(i=>e.jsx(m,{className:"bg-[var(--ui-surface-1)] text-[var(--ui-ink-medium)]",children:i.title},i.id))})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:"Alignment breakdown"}),e.jsx("div",{className:"mt-3 grid gap-2 text-sm text-[var(--ui-ink-soft)]",children:g.map(i=>e.jsxs("div",{children:[i.label," ",i.value,"%"]},i.id))})]})]})}),e.jsxs("div",{className:"flex flex-wrap items-end justify-end gap-2",children:[s.isLocked?null:e.jsxs(o,{variant:"secondary",onClick:()=>{d(s),l(!0)},children:[e.jsx(O,{className:"size-4"}),"Edit"]}),e.jsxs(o,{variant:"secondary",pending:p.isPending&&p.variables===s.id,pendingLabel:"Deleting strategy",onClick:()=>{window.confirm(`Delete strategy "${s.title}"?`)&&p.mutateAsync(s.id)},children:[e.jsx(Q,{className:"size-4"}),"Delete"]}),e.jsx(o,{onClick:()=>h(`/strategies/${s.id}`),children:"Open strategy"})]})]})]},s.id)})}),e.jsx(G,{open:E,pending:N.isPending,editingStrategy:T,goals:a.snapshot.dashboard.goals,projects:a.snapshot.dashboard.projects,tasks:a.snapshot.tasks,habits:a.snapshot.habits,strategies:a.snapshot.strategies,users:a.snapshot.users,defaultUserId:D,onOpenChange:l,onSubmit:async(s,t)=>{await N.mutateAsync({input:s,strategyId:t})}})]})}export{ue as StrategiesPage};
@@ -1 +1 @@
1
- import{r as p,j as e,cv as K,cs as W,cz as V,cx as J,aC as $,c6 as X,b6 as Y}from"./vendor-Cpmju3nw.js";import{j as Z,i as ee,k as D}from"./state-BtwEvpO6.js";import{O as se}from"./open-in-graph-button-B_4fdm4l.js";import{P as te}from"./preference-entity-handoff-button-DOV-_2Vm.js";import{a as ae,i as re,b as ie,S as ne}from"./strategy-dialog-Fgpc0z1M.js";import{i as le,C as oe,B as de,M as ce}from"./graph-Cd5WF3lw.js";import{k as x,d as ue,L as me,e as F,B as _,C as k,P as xe,a_ as ge,bp as G,bo as pe,br as he}from"./index-wEZUnRh0.js";import{U as L}from"./user-badge-CQygGKVs.js";import{P as fe}from"./page-hero-BRcqE3a4.js";import{g as ve}from"./user-ownership-DJGl4rAj.js";import"./board-CLOHbg6t.js";import"./question-flow-dialog-Dsnsc8be.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./user-select-field-BNqv8-wd.js";import"./forms-C5d5hTf2.js";function Q(a){const i=new Map;for(const r of a.nodes)i.set(r.id,[]);for(const r of a.edges)i.set(r.to,[...i.get(r.to)??[],r.from]);const o=new Map,d=r=>{const c=o.get(r);if(c!==void 0)return c;const j=i.get(r)??[],h=j.length===0?0:Math.max(...j.map(l=>d(l)))+1;return o.set(r,h),h};for(const r of a.nodes)d(r.id);return o}function be(a){const i=Q(a),o=new Map;for(const d of a.nodes){const r=i.get(d.id)??0;o.set(r,[...o.get(r)??[],d.id])}return Array.from(o.entries()).sort((d,r)=>d[0]-r[0]).map(([d,r])=>({level:d,nodeIds:r}))}function je(a,i){const o=Q(a.graph),d=new Map;for(const r of a.graph.nodes){const c=o.get(r.id)??0;d.set(c,[...d.get(c)??[],r.id])}return a.graph.nodes.map(r=>{const c=o.get(r.id)??0,j=(d.get(c)??[]).indexOf(r.id),h=a.metrics.activeNodeIds.includes(r.id),l=a.metrics.blockedNodeIds.includes(r.id),m=a.metrics.outOfOrderNodeIds.includes(r.id),v=!h&&!l&&!m,s=(i==null?void 0:i.get(r.id))??null;let g="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",n="bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]";return h?(g="border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle))] bg-[var(--ui-success-soft)]",n="bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"):l?(g="border-[color-mix(in_srgb,var(--danger)_32%,var(--ui-border-subtle))] bg-[var(--ui-danger-soft)]",n="bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]"):m?(g="border-[color-mix(in_srgb,var(--warning)_34%,var(--ui-border-subtle))] bg-[var(--ui-warning-soft)]",n="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"):a.metrics.completedNodeCount>0&&(g="border-[color-mix(in_srgb,var(--info)_30%,var(--ui-border-subtle))] bg-[var(--ui-info-soft)]",n="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"),{id:r.id,position:{x:72+c*308,y:56+j*168},draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`w-[min(17rem,calc(100vw-5rem))] min-w-0 max-w-[17rem] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] ${g}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:r.entityType}),h?e.jsx(x,{className:n,children:"Active"}):null,l?e.jsx(x,{className:n,children:"Blocked"}):null,m?e.jsx(x,{className:n,children:"Out of order"}):null,v&&!l&&!m?e.jsx(x,{className:n,children:"In plan"}):null]}),e.jsx("div",{className:"mt-3 break-words text-base font-medium leading-6 text-[var(--ui-ink-strong)]",children:r.title}),r.branchLabel?e.jsx("div",{className:"mt-2 break-words text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:r.branchLabel}):null,r.notes?e.jsx("div",{className:"mt-2 break-words text-sm leading-5 text-[var(--ui-ink-soft)]",children:r.notes}):null,s?e.jsxs("div",{className:"mt-3 flex min-w-0 items-center gap-2 text-xs text-[var(--ui-ink-faint)]",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-full",style:{backgroundColor:s.color}}),e.jsx("span",{className:"min-w-0 break-words",children:s.label})]}):null]})},style:{background:"transparent",border:"none",padding:0}}})}function ye(a){return a.graph.edges.map(i=>{const o=a.metrics.activeNodeIds.includes(i.to),d=a.metrics.blockedNodeIds.includes(i.to),r=a.metrics.outOfOrderNodeIds.includes(i.to);let c="var(--ui-border-strong)";return o?c="var(--success)":d?c="var(--danger)":r&&(c="var(--warning)"),{id:`${i.from}->${i.to}`,source:i.from,target:i.to,label:i.label||void 0,animated:o,markerEnd:{type:ce.ArrowClosed,color:c},style:{stroke:c,strokeWidth:o?2.4:1.5},labelStyle:{fill:"var(--ui-ink-soft)",fontSize:11,fontWeight:600}}})}function we({strategy:a,ownerByNodeId:i,heightClassName:o="h-[540px]"}){const d=p.useMemo(()=>je(a,i),[i,a]),r=p.useMemo(()=>ye(a),[a]);return e.jsx("div",{className:`${o} min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]`,children:e.jsxs(le,{fitView:!0,nodes:d,edges:r,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,attributionPosition:"bottom-left",children:[e.jsx(oe,{showInteractive:!1}),e.jsx(de,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})}function Ne(a,i){const o=a.metrics.activeNodeIds.includes(i),d=a.metrics.blockedNodeIds.includes(i),r=a.metrics.outOfOrderNodeIds.includes(i);return d?{label:"Blocked",className:"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]"}:r?{label:"Out of order",className:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}:o?{label:"Ready now",className:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"}:{label:"In plan",className:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"}}function ke({strategy:a,projectsById:i,tasksById:o,className:d}){const r=p.useMemo(()=>be(a.graph),[a.graph]),c=p.useMemo(()=>{const l=new Map;for(const m of a.graph.nodes)l.set(m.id,[]);for(const m of a.graph.edges)l.set(m.to,[...l.get(m.to)??[],m.from]);return l},[a.graph]),[j,h]=p.useState([]);return e.jsxs("div",{className:d??"grid gap-3",children:[r.map(l=>{const m=j.includes(l.level),v=l.level===0?"Launch phase":`Phase ${l.level+1}`,s=l.nodeIds.length>1;return e.jsxs("div",{className:"min-w-0 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 px-4 py-4",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-3 text-left",onClick:()=>h(g=>m?g.filter(n=>n!==l.level):[...g,l.level]),children:[e.jsx("span",{className:"rounded-full bg-[var(--ui-surface-3)] p-2 text-[var(--ui-ink-soft)]",children:m?e.jsx(K,{className:"size-4"}):e.jsx(W,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:v}),e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)]",children:s?"These branches can progress in parallel once the previous phase is complete.":"This phase advances as one focused step in the strategy."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:[l.nodeIds.length," node",l.nodeIds.length===1?"":"s"]}),e.jsx(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"mr-1 size-3.5"}),"Parallel"]}):e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"mr-1 size-3.5"}),"Sequential"]})})]})]}),m?null:e.jsx("div",{className:"grid min-w-0 gap-3 border-t border-[var(--ui-border-subtle)] px-4 py-4 lg:grid-cols-2",children:l.nodeIds.map(g=>{var T,N,O;const n=a.graph.nodes.find(f=>f.id===g);if(!n)return null;const w=n.entityType==="project"?i.get(n.entityId):o.get(n.entityId),M=n.entityType==="project"?`/projects/${n.entityId}`:`/tasks/${n.entityId}`,I=n.entityType==="project"?(T=i.get(n.entityId))==null?void 0:T.user:(N=o.get(n.entityId))==null?void 0:N.user,b=((O=c.get(n.id))==null?void 0:O.map(f=>{var P;return((P=a.graph.nodes.find(B=>B.id===f))==null?void 0:P.title)??f}))??[],y=Ne(a,n.id);return e.jsxs("div",{className:"min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:n.entityType}),e.jsx(x,{className:y.className,children:y.label})]}),e.jsx($,{to:M,className:"mt-3 block break-words text-lg font-medium text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:n.title}),e.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:n.notes||("description"in(w??{})?w==null?void 0:w.description:"")||"No extra step note attached yet."})]}),e.jsx(L,{user:I,compact:!0})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[n.branchLabel?e.jsx(x,{className:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",children:n.branchLabel}):null,b.length===0?e.jsx(x,{className:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",children:"Start node"}):b.map(f=>e.jsxs(x,{className:"max-w-full break-words bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:["Depends on ",f]},`${n.id}:${f}`))]})]},n.id)})})]},l.level)}),r.length===0?e.jsx("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No phases mapped yet."}):null]})}function Re(){var B;const a=ue(),{strategyId:i}=X(),o=Y(),d=Z(),[r,c]=p.useState(!1),[j,h]=p.useState(),l=ve(a.selectedUserIds),m=a.snapshot.strategies.find(t=>t.id===i)??null,v=ee({queryKey:["strategy-detail",i],queryFn:async()=>(await he(i)).strategy,enabled:!!(i&&!m)}),s=m??v.data??null,g=async()=>{await Promise.all([d.invalidateQueries({queryKey:["strategy-detail",i]}),a.refresh()])},n=D({mutationFn:async({input:t,currentStrategyId:u})=>(await G(u,t)).strategy,onSuccess:g}),w=D({mutationFn:async t=>pe(t),onSuccess:async()=>{await g(),o("/strategies")}}),M=D({mutationFn:async t=>(await G(i,{isLocked:t,lockedByUserId:t?l??(s==null?void 0:s.userId)??"user_operator":null})).strategy,onSuccess:g}),I=p.useMemo(()=>new Map(a.snapshot.goals.map(t=>[t.id,t])),[a.snapshot.goals]),b=p.useMemo(()=>new Map(a.snapshot.dashboard.projects.map(t=>[t.id,t])),[a.snapshot.dashboard.projects]),y=p.useMemo(()=>new Map(a.snapshot.tasks.map(t=>[t.id,t])),[a.snapshot.tasks]),T=p.useMemo(()=>s?new Map(s.graph.nodes.map(t=>{var S,C;const u=t.entityType==="project"?(S=b.get(t.entityId))==null?void 0:S.user:(C=y.get(t.entityId))==null?void 0:C.user;return[t.id,u?{label:`${u.displayName} (${u.kind})`,color:u.accentColor}:null]})):new Map,[b,s,y]),N=s??{title:"",overview:"",endStateDescription:"",targetGoalIds:[],targetProjectIds:[],graph:{nodes:[],edges:[]}},O=p.useMemo(()=>ae(N),[N]),f=p.useMemo(()=>re(N),[N]),P=p.useMemo(()=>ie((s==null?void 0:s.metrics)??{planCoverageScore:0,sequencingScore:0,scopeDisciplineScore:0,qualityScore:0,targetProgressScore:0,startedNodeCount:0,totalNodeCount:1,offPlanEntityCount:0,offPlanActiveEntityCount:0,blockedNodeIds:[],outOfOrderNodeIds:[]}),[s==null?void 0:s.metrics]);return v.isLoading&&!s?e.jsx(me,{eyebrow:"Strategy",title:"Loading strategy",description:"Resolving the directed plan, targets, and current alignment."}):v.isError?e.jsx(F,{eyebrow:"Strategy",error:v.error,onRetry:()=>void v.refetch()}):s?e.jsxs("div",{className:"grid gap-5",children:[e.jsx(fe,{title:s.title,titleText:s.title,description:s.overview||s.endStateDescription,badge:`${s.metrics.alignmentScore}% aligned`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(te,{userId:l,domain:"strategies",entityType:"strategy",entityId:s.id,label:s.title,description:s.overview||s.endStateDescription}),e.jsx(se,{entityType:"strategy",entityId:s.id}),s.isLocked?null:e.jsx(_,{variant:"secondary",onClick:()=>{h(void 0),c(!0)},children:"Edit strategy"}),e.jsx(_,{variant:"secondary",disabled:!s.isLocked&&!f,pending:M.isPending,pendingLabel:s.isLocked?"Unlocking contract":"Locking contract",onClick:()=>{M.mutateAsync(!s.isLocked)},children:s.isLocked?"Unlock contract":"Lock as contract"}),e.jsx(_,{variant:"secondary",pending:w.isPending,pendingLabel:"Deleting strategy",onClick:()=>{window.confirm(`Delete strategy "${s.title}"?`)&&w.mutateAsync(s.id)},children:"Delete"})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(L,{user:s.user}),e.jsx(x,{className:s.isLocked?"bg-amber-500/12 text-amber-200":"bg-emerald-500/12 text-emerald-200",children:s.isLocked?"Contract locked":"Editable draft"}),e.jsx(x,{className:"bg-white/[0.08] text-white/76",children:s.status}),e.jsxs(x,{className:"bg-white/[0.08] text-white/76",children:[s.graph.nodes.length," nodes"]}),e.jsxs(x,{className:"bg-white/[0.08] text-white/76",children:[s.graph.edges.length," edges"]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(k,{className:"grid gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"End state"}),e.jsx("div",{className:"text-sm leading-7 text-white/64",children:s.endStateDescription||"No end-state description yet."})]}),e.jsxs(k,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Directed execution graph"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/58",children:"The graph is the contract surface for this strategy. It shows which branches are available now, where work is blocked, and whether any node is moving out of sequence."})]}),s.isLocked?null:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(_,{variant:"secondary",onClick:()=>{h("sequence"),c(!0)},children:"Refine sequence"}),e.jsx(_,{onClick:()=>{h("sequence"),c(!0)},children:"Add parallel work"})]})]}),e.jsx(we,{strategy:s,ownerByNodeId:T}),e.jsx(ke,{strategy:s,projectsById:b,tasksById:y})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Contract state"}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:s.isLocked?"This strategy is currently locked as a contract. The graph, targets, and descriptive plan stay frozen until you explicitly unlock it.":"This strategy is still a draft. Agents and users can keep refining the plan until you lock it."}),s.isLocked?e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-sm text-white/60",children:[e.jsxs("span",{children:["Locked by"," ",((B=s.lockedByUser)==null?void 0:B.displayName)??"Unknown user"]}),s.lockedAt?e.jsxs("span",{children:["· ",new Date(s.lockedAt).toLocaleString()]}):null]}):null,s.isLocked?null:e.jsx("div",{className:"mt-4 grid gap-2",children:O.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[14px] bg-white/[0.03] px-3 py-2",children:[e.jsx("div",{className:"text-sm text-white/64",children:t.label}),e.jsx(x,{className:t.satisfied?"bg-emerald-500/12 text-emerald-200":"bg-amber-500/12 text-amber-200",children:t.satisfied?"Ready":"Missing"})]},t.id))})]}),!s.isLocked&&!f?e.jsx("div",{className:"rounded-[18px] border border-amber-400/18 bg-amber-500/[0.08] px-4 py-3 text-sm leading-6 text-amber-100/86",children:"Add a target goal or project plus an overview or end state before locking this draft as the execution contract."}):null,s.isLocked?null:e.jsx("div",{className:"mt-4 text-xs leading-5 text-white/46",children:"Drafts may stay incomplete while humans and agents negotiate the plan. Only the lock action requires the contract checks to pass."})]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Alignment metrics"}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/56",children:"Alignment score"}),e.jsxs("div",{className:"mt-2 font-display text-3xl text-[var(--primary)]",children:[s.metrics.alignmentScore,"%"]}),e.jsxs("div",{className:"mt-3 text-xs leading-5 text-white/48",children:[s.metrics.startedNodeCount,"/",s.metrics.totalNodeCount," planned nodes started,"," ",s.metrics.completedNodeCount," completed,"," ",s.metrics.readyNodeCount," ready now."]})]}),P.map(t=>e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm text-white/56",children:t.label}),e.jsxs("div",{className:"text-sm font-medium text-white",children:[t.value,"%"]})]}),e.jsx(xe,{value:t.value,className:"mt-3"}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-white/48",children:t.detail})]},t.id))]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"End targets"}),s.targetGoalIds.map(t=>{const u=I.get(t);return u?e.jsx($,{to:`/goals/${u.id}`,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{children:["Goal: ",u.title]}),e.jsx(L,{user:u.user,compact:!0})]})},u.id):null}),s.targetProjectIds.map(t=>{const u=b.get(t);return u?e.jsx($,{to:`/projects/${u.id}`,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{children:["Project: ",u.title]}),e.jsx(L,{user:u.user,compact:!0})]})},u.id):null}),s.targetGoalIds.length===0&&s.targetProjectIds.length===0?e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:"No end targets linked yet."}):null]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Linked entities"}),s.linkedEntities.length===0?e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:"No additional linked entities."}):s.linkedEntities.map(t=>{var C,A,E,q,z,R,U;const u=ge(t.entityType,t.entityId),S=t.entityType==="goal"?(C=I.get(t.entityId))==null?void 0:C.title:t.entityType==="project"?(A=b.get(t.entityId))==null?void 0:A.title:t.entityType==="task"?(E=y.get(t.entityId))==null?void 0:E.title:`${t.entityType}:${t.entityId}`;return u?e.jsx($,{to:u,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:S}),e.jsx(L,{user:t.entityType==="goal"?(q=I.get(t.entityId))==null?void 0:q.user:t.entityType==="project"?(z=b.get(t.entityId))==null?void 0:z.user:t.entityType==="task"?(R=y.get(t.entityId))==null?void 0:R.user:t.entityType==="strategy"?(U=a.snapshot.strategies.find(H=>H.id===t.entityId))==null?void 0:U.user:null,compact:!0})]})},`${t.entityType}:${t.entityId}`):e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:S},`${t.entityType}:${t.entityId}`)})]})]})]}),e.jsx(ne,{open:r,pending:n.isPending,editingStrategy:s,goals:a.snapshot.dashboard.goals,projects:a.snapshot.dashboard.projects,tasks:a.snapshot.tasks,habits:a.snapshot.habits,strategies:a.snapshot.strategies,users:a.snapshot.users,defaultUserId:l,initialStepId:j,onOpenChange:t=>{c(t),t||h(void 0)},onSubmit:async t=>{await n.mutateAsync({input:t,currentStrategyId:s.id})}})]}):e.jsx(F,{eyebrow:"Strategy",error:new Error("Strategy not found."),onRetry:()=>o("/strategies")})}export{Re as StrategyDetailPage};
1
+ import{r as p,j as e,cv as K,cs as W,cz as V,cx as J,aC as $,c6 as X,b6 as Y}from"./vendor-Cpmju3nw.js";import{j as Z,i as ee,k as D}from"./state-BtwEvpO6.js";import{O as se}from"./open-in-graph-button-L21MKsb5.js";import{P as te}from"./preference-entity-handoff-button-ugHU2us9.js";import{a as ae,i as re,b as ie,S as ne}from"./strategy-dialog-BIVHfUR6.js";import{i as le,C as oe,B as de,M as ce}from"./graph-Cd5WF3lw.js";import{k as x,d as ue,L as me,e as F,B as _,C as k,P as xe,a_ as ge,bp as G,bo as pe,br as he}from"./index-BejvcRGb.js";import{U as L}from"./user-badge-BKzwGZDd.js";import{P as fe}from"./page-hero-DlHEJ0Yt.js";import{g as ve}from"./user-ownership-DJGl4rAj.js";import"./board-CLOHbg6t.js";import"./question-flow-dialog-BByFV8Yw.js";import"./ui-B9O-eUim.js";import"./motion-DwjmC9aq.js";import"./user-select-field-BNqv8-wd.js";import"./forms-C5d5hTf2.js";function Q(a){const i=new Map;for(const r of a.nodes)i.set(r.id,[]);for(const r of a.edges)i.set(r.to,[...i.get(r.to)??[],r.from]);const o=new Map,d=r=>{const c=o.get(r);if(c!==void 0)return c;const j=i.get(r)??[],h=j.length===0?0:Math.max(...j.map(l=>d(l)))+1;return o.set(r,h),h};for(const r of a.nodes)d(r.id);return o}function be(a){const i=Q(a),o=new Map;for(const d of a.nodes){const r=i.get(d.id)??0;o.set(r,[...o.get(r)??[],d.id])}return Array.from(o.entries()).sort((d,r)=>d[0]-r[0]).map(([d,r])=>({level:d,nodeIds:r}))}function je(a,i){const o=Q(a.graph),d=new Map;for(const r of a.graph.nodes){const c=o.get(r.id)??0;d.set(c,[...d.get(c)??[],r.id])}return a.graph.nodes.map(r=>{const c=o.get(r.id)??0,j=(d.get(c)??[]).indexOf(r.id),h=a.metrics.activeNodeIds.includes(r.id),l=a.metrics.blockedNodeIds.includes(r.id),m=a.metrics.outOfOrderNodeIds.includes(r.id),v=!h&&!l&&!m,s=(i==null?void 0:i.get(r.id))??null;let g="border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)]",n="bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]";return h?(g="border-[color-mix(in_srgb,var(--success)_34%,var(--ui-border-subtle))] bg-[var(--ui-success-soft)]",n="bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"):l?(g="border-[color-mix(in_srgb,var(--danger)_32%,var(--ui-border-subtle))] bg-[var(--ui-danger-soft)]",n="bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]"):m?(g="border-[color-mix(in_srgb,var(--warning)_34%,var(--ui-border-subtle))] bg-[var(--ui-warning-soft)]",n="bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"):a.metrics.completedNodeCount>0&&(g="border-[color-mix(in_srgb,var(--info)_30%,var(--ui-border-subtle))] bg-[var(--ui-info-soft)]",n="bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"),{id:r.id,position:{x:72+c*308,y:56+j*168},draggable:!1,selectable:!1,data:{label:e.jsxs("div",{className:`w-[min(17rem,calc(100vw-5rem))] min-w-0 max-w-[17rem] rounded-[22px] border px-4 py-4 shadow-[var(--ui-shadow-soft)] ${g}`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:r.entityType}),h?e.jsx(x,{className:n,children:"Active"}):null,l?e.jsx(x,{className:n,children:"Blocked"}):null,m?e.jsx(x,{className:n,children:"Out of order"}):null,v&&!l&&!m?e.jsx(x,{className:n,children:"In plan"}):null]}),e.jsx("div",{className:"mt-3 break-words text-base font-medium leading-6 text-[var(--ui-ink-strong)]",children:r.title}),r.branchLabel?e.jsx("div",{className:"mt-2 break-words text-xs uppercase tracking-[0.16em] text-[var(--ui-ink-faint)]",children:r.branchLabel}):null,r.notes?e.jsx("div",{className:"mt-2 break-words text-sm leading-5 text-[var(--ui-ink-soft)]",children:r.notes}):null,s?e.jsxs("div",{className:"mt-3 flex min-w-0 items-center gap-2 text-xs text-[var(--ui-ink-faint)]",children:[e.jsx("span",{className:"inline-block size-2.5 rounded-full",style:{backgroundColor:s.color}}),e.jsx("span",{className:"min-w-0 break-words",children:s.label})]}):null]})},style:{background:"transparent",border:"none",padding:0}}})}function ye(a){return a.graph.edges.map(i=>{const o=a.metrics.activeNodeIds.includes(i.to),d=a.metrics.blockedNodeIds.includes(i.to),r=a.metrics.outOfOrderNodeIds.includes(i.to);let c="var(--ui-border-strong)";return o?c="var(--success)":d?c="var(--danger)":r&&(c="var(--warning)"),{id:`${i.from}->${i.to}`,source:i.from,target:i.to,label:i.label||void 0,animated:o,markerEnd:{type:ce.ArrowClosed,color:c},style:{stroke:c,strokeWidth:o?2.4:1.5},labelStyle:{fill:"var(--ui-ink-soft)",fontSize:11,fontWeight:600}}})}function we({strategy:a,ownerByNodeId:i,heightClassName:o="h-[540px]"}){const d=p.useMemo(()=>je(a,i),[i,a]),r=p.useMemo(()=>ye(a),[a]);return e.jsx("div",{className:`${o} min-w-0 overflow-hidden rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]`,children:e.jsxs(le,{fitView:!0,nodes:d,edges:r,nodesDraggable:!1,nodesConnectable:!1,elementsSelectable:!1,attributionPosition:"bottom-left",children:[e.jsx(oe,{showInteractive:!1}),e.jsx(de,{gap:28,size:1,color:"var(--ui-border-subtle)"})]})})}function Ne(a,i){const o=a.metrics.activeNodeIds.includes(i),d=a.metrics.blockedNodeIds.includes(i),r=a.metrics.outOfOrderNodeIds.includes(i);return d?{label:"Blocked",className:"bg-[var(--ui-danger-soft)] text-[color-mix(in_srgb,var(--danger)_78%,var(--ui-ink-strong)_22%)]"}:r?{label:"Out of order",className:"bg-[var(--ui-warning-soft)] text-[color-mix(in_srgb,var(--warning)_78%,var(--ui-ink-strong)_22%)]"}:o?{label:"Ready now",className:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]"}:{label:"In plan",className:"bg-[var(--ui-info-soft)] text-[color-mix(in_srgb,var(--info)_78%,var(--ui-ink-strong)_22%)]"}}function ke({strategy:a,projectsById:i,tasksById:o,className:d}){const r=p.useMemo(()=>be(a.graph),[a.graph]),c=p.useMemo(()=>{const l=new Map;for(const m of a.graph.nodes)l.set(m.id,[]);for(const m of a.graph.edges)l.set(m.to,[...l.get(m.to)??[],m.from]);return l},[a.graph]),[j,h]=p.useState([]);return e.jsxs("div",{className:d??"grid gap-3",children:[r.map(l=>{const m=j.includes(l.level),v=l.level===0?"Launch phase":`Phase ${l.level+1}`,s=l.nodeIds.length>1;return e.jsxs("div",{className:"min-w-0 rounded-[24px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] shadow-[var(--ui-shadow-soft)]",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 px-4 py-4",children:[e.jsxs("button",{type:"button",className:"flex min-w-0 max-w-full items-center gap-3 text-left",onClick:()=>h(g=>m?g.filter(n=>n!==l.level):[...g,l.level]),children:[e.jsx("span",{className:"rounded-full bg-[var(--ui-surface-3)] p-2 text-[var(--ui-ink-soft)]",children:m?e.jsx(K,{className:"size-4"}):e.jsx(W,{className:"size-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"break-words font-label text-[11px] uppercase tracking-[0.18em] text-[var(--ui-ink-faint)]",children:v}),e.jsx("div",{className:"mt-1 break-words text-sm text-[var(--ui-ink-soft)]",children:s?"These branches can progress in parallel once the previous phase is complete.":"This phase advances as one focused step in the strategy."})]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:[l.nodeIds.length," node",l.nodeIds.length===1?"":"s"]}),e.jsx(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:s?e.jsxs(e.Fragment,{children:[e.jsx(V,{className:"mr-1 size-3.5"}),"Parallel"]}):e.jsxs(e.Fragment,{children:[e.jsx(J,{className:"mr-1 size-3.5"}),"Sequential"]})})]})]}),m?null:e.jsx("div",{className:"grid min-w-0 gap-3 border-t border-[var(--ui-border-subtle)] px-4 py-4 lg:grid-cols-2",children:l.nodeIds.map(g=>{var T,N,O;const n=a.graph.nodes.find(f=>f.id===g);if(!n)return null;const w=n.entityType==="project"?i.get(n.entityId):o.get(n.entityId),M=n.entityType==="project"?`/projects/${n.entityId}`:`/tasks/${n.entityId}`,I=n.entityType==="project"?(T=i.get(n.entityId))==null?void 0:T.user:(N=o.get(n.entityId))==null?void 0:N.user,b=((O=c.get(n.id))==null?void 0:O.map(f=>{var P;return((P=a.graph.nodes.find(B=>B.id===f))==null?void 0:P.title)??f}))??[],y=Ne(a,n.id);return e.jsxs("div",{className:"min-w-0 rounded-[20px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-2)] p-4",children:[e.jsxs("div",{className:"flex min-w-0 flex-wrap items-start justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(x,{className:"bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:n.entityType}),e.jsx(x,{className:y.className,children:y.label})]}),e.jsx($,{to:M,className:"mt-3 block break-words text-lg font-medium text-[var(--ui-ink-strong)] transition hover:text-[var(--primary)]",children:n.title}),e.jsx("div",{className:"mt-2 break-words text-sm leading-6 text-[var(--ui-ink-soft)]",children:n.notes||("description"in(w??{})?w==null?void 0:w.description:"")||"No extra step note attached yet."})]}),e.jsx(L,{user:I,compact:!0})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[n.branchLabel?e.jsx(x,{className:"bg-[var(--ui-accent-soft)] text-[var(--primary)]",children:n.branchLabel}):null,b.length===0?e.jsx(x,{className:"bg-[var(--ui-success-soft)] text-[color-mix(in_srgb,var(--success)_78%,var(--ui-ink-strong)_22%)]",children:"Start node"}):b.map(f=>e.jsxs(x,{className:"max-w-full break-words bg-[var(--ui-surface-3)] text-[var(--ui-ink-soft)]",children:["Depends on ",f]},`${n.id}:${f}`))]})]},n.id)})})]},l.level)}),r.length===0?e.jsx("div",{className:"rounded-[22px] border border-[var(--ui-border-subtle)] bg-[var(--ui-surface-1)] px-4 py-4 text-sm text-[var(--ui-ink-soft)]",children:"No phases mapped yet."}):null]})}function Re(){var B;const a=ue(),{strategyId:i}=X(),o=Y(),d=Z(),[r,c]=p.useState(!1),[j,h]=p.useState(),l=ve(a.selectedUserIds),m=a.snapshot.strategies.find(t=>t.id===i)??null,v=ee({queryKey:["strategy-detail",i],queryFn:async()=>(await he(i)).strategy,enabled:!!(i&&!m)}),s=m??v.data??null,g=async()=>{await Promise.all([d.invalidateQueries({queryKey:["strategy-detail",i]}),a.refresh()])},n=D({mutationFn:async({input:t,currentStrategyId:u})=>(await G(u,t)).strategy,onSuccess:g}),w=D({mutationFn:async t=>pe(t),onSuccess:async()=>{await g(),o("/strategies")}}),M=D({mutationFn:async t=>(await G(i,{isLocked:t,lockedByUserId:t?l??(s==null?void 0:s.userId)??"user_operator":null})).strategy,onSuccess:g}),I=p.useMemo(()=>new Map(a.snapshot.goals.map(t=>[t.id,t])),[a.snapshot.goals]),b=p.useMemo(()=>new Map(a.snapshot.dashboard.projects.map(t=>[t.id,t])),[a.snapshot.dashboard.projects]),y=p.useMemo(()=>new Map(a.snapshot.tasks.map(t=>[t.id,t])),[a.snapshot.tasks]),T=p.useMemo(()=>s?new Map(s.graph.nodes.map(t=>{var S,C;const u=t.entityType==="project"?(S=b.get(t.entityId))==null?void 0:S.user:(C=y.get(t.entityId))==null?void 0:C.user;return[t.id,u?{label:`${u.displayName} (${u.kind})`,color:u.accentColor}:null]})):new Map,[b,s,y]),N=s??{title:"",overview:"",endStateDescription:"",targetGoalIds:[],targetProjectIds:[],graph:{nodes:[],edges:[]}},O=p.useMemo(()=>ae(N),[N]),f=p.useMemo(()=>re(N),[N]),P=p.useMemo(()=>ie((s==null?void 0:s.metrics)??{planCoverageScore:0,sequencingScore:0,scopeDisciplineScore:0,qualityScore:0,targetProgressScore:0,startedNodeCount:0,totalNodeCount:1,offPlanEntityCount:0,offPlanActiveEntityCount:0,blockedNodeIds:[],outOfOrderNodeIds:[]}),[s==null?void 0:s.metrics]);return v.isLoading&&!s?e.jsx(me,{eyebrow:"Strategy",title:"Loading strategy",description:"Resolving the directed plan, targets, and current alignment."}):v.isError?e.jsx(F,{eyebrow:"Strategy",error:v.error,onRetry:()=>void v.refetch()}):s?e.jsxs("div",{className:"grid gap-5",children:[e.jsx(fe,{title:s.title,titleText:s.title,description:s.overview||s.endStateDescription,badge:`${s.metrics.alignmentScore}% aligned`,actions:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(te,{userId:l,domain:"strategies",entityType:"strategy",entityId:s.id,label:s.title,description:s.overview||s.endStateDescription}),e.jsx(se,{entityType:"strategy",entityId:s.id}),s.isLocked?null:e.jsx(_,{variant:"secondary",onClick:()=>{h(void 0),c(!0)},children:"Edit strategy"}),e.jsx(_,{variant:"secondary",disabled:!s.isLocked&&!f,pending:M.isPending,pendingLabel:s.isLocked?"Unlocking contract":"Locking contract",onClick:()=>{M.mutateAsync(!s.isLocked)},children:s.isLocked?"Unlock contract":"Lock as contract"}),e.jsx(_,{variant:"secondary",pending:w.isPending,pendingLabel:"Deleting strategy",onClick:()=>{window.confirm(`Delete strategy "${s.title}"?`)&&w.mutateAsync(s.id)},children:"Delete"})]})}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(L,{user:s.user}),e.jsx(x,{className:s.isLocked?"bg-amber-500/12 text-amber-200":"bg-emerald-500/12 text-emerald-200",children:s.isLocked?"Contract locked":"Editable draft"}),e.jsx(x,{className:"bg-white/[0.08] text-white/76",children:s.status}),e.jsxs(x,{className:"bg-white/[0.08] text-white/76",children:[s.graph.nodes.length," nodes"]}),e.jsxs(x,{className:"bg-white/[0.08] text-white/76",children:[s.graph.edges.length," edges"]})]}),e.jsxs("div",{className:"grid gap-5 xl:grid-cols-[minmax(0,1.15fr)_minmax(18rem,0.85fr)]",children:[e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(k,{className:"grid gap-4",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"End state"}),e.jsx("div",{className:"text-sm leading-7 text-white/64",children:s.endStateDescription||"No end-state description yet."})]}),e.jsxs(k,{className:"grid gap-4",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Directed execution graph"}),e.jsx("div",{className:"mt-2 text-sm leading-6 text-white/58",children:"The graph is the contract surface for this strategy. It shows which branches are available now, where work is blocked, and whether any node is moving out of sequence."})]}),s.isLocked?null:e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(_,{variant:"secondary",onClick:()=>{h("sequence"),c(!0)},children:"Refine sequence"}),e.jsx(_,{onClick:()=>{h("sequence"),c(!0)},children:"Add parallel work"})]})]}),e.jsx(we,{strategy:s,ownerByNodeId:T}),e.jsx(ke,{strategy:s,projectsById:b,tasksById:y})]})]}),e.jsxs("div",{className:"grid gap-5",children:[e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Contract state"}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/58",children:s.isLocked?"This strategy is currently locked as a contract. The graph, targets, and descriptive plan stay frozen until you explicitly unlock it.":"This strategy is still a draft. Agents and users can keep refining the plan until you lock it."}),s.isLocked?e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2 text-sm text-white/60",children:[e.jsxs("span",{children:["Locked by"," ",((B=s.lockedByUser)==null?void 0:B.displayName)??"Unknown user"]}),s.lockedAt?e.jsxs("span",{children:["· ",new Date(s.lockedAt).toLocaleString()]}):null]}):null,s.isLocked?null:e.jsx("div",{className:"mt-4 grid gap-2",children:O.map(t=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-[14px] bg-white/[0.03] px-3 py-2",children:[e.jsx("div",{className:"text-sm text-white/64",children:t.label}),e.jsx(x,{className:t.satisfied?"bg-emerald-500/12 text-emerald-200":"bg-amber-500/12 text-amber-200",children:t.satisfied?"Ready":"Missing"})]},t.id))})]}),!s.isLocked&&!f?e.jsx("div",{className:"rounded-[18px] border border-amber-400/18 bg-amber-500/[0.08] px-4 py-3 text-sm leading-6 text-amber-100/86",children:"Add a target goal or project plus an overview or end state before locking this draft as the execution contract."}):null,s.isLocked?null:e.jsx("div",{className:"mt-4 text-xs leading-5 text-white/46",children:"Drafts may stay incomplete while humans and agents negotiate the plan. Only the lock action requires the contract checks to pass."})]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Alignment metrics"}),e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsx("div",{className:"text-sm text-white/56",children:"Alignment score"}),e.jsxs("div",{className:"mt-2 font-display text-3xl text-[var(--primary)]",children:[s.metrics.alignmentScore,"%"]}),e.jsxs("div",{className:"mt-3 text-xs leading-5 text-white/48",children:[s.metrics.startedNodeCount,"/",s.metrics.totalNodeCount," planned nodes started,"," ",s.metrics.completedNodeCount," completed,"," ",s.metrics.readyNodeCount," ready now."]})]}),P.map(t=>e.jsxs("div",{className:"rounded-[18px] bg-white/[0.04] px-4 py-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("div",{className:"text-sm text-white/56",children:t.label}),e.jsxs("div",{className:"text-sm font-medium text-white",children:[t.value,"%"]})]}),e.jsx(xe,{value:t.value,className:"mt-3"}),e.jsx("div",{className:"mt-3 text-xs leading-5 text-white/48",children:t.detail})]},t.id))]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"End targets"}),s.targetGoalIds.map(t=>{const u=I.get(t);return u?e.jsx($,{to:`/goals/${u.id}`,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{children:["Goal: ",u.title]}),e.jsx(L,{user:u.user,compact:!0})]})},u.id):null}),s.targetProjectIds.map(t=>{const u=b.get(t);return u?e.jsx($,{to:`/projects/${u.id}`,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsxs("span",{children:["Project: ",u.title]}),e.jsx(L,{user:u.user,compact:!0})]})},u.id):null}),s.targetGoalIds.length===0&&s.targetProjectIds.length===0?e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:"No end targets linked yet."}):null]}),e.jsxs(k,{className:"grid gap-3",children:[e.jsx("div",{className:"font-label text-[11px] uppercase tracking-[0.18em] text-white/45",children:"Linked entities"}),s.linkedEntities.length===0?e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:"No additional linked entities."}):s.linkedEntities.map(t=>{var C,A,E,q,z,R,U;const u=ge(t.entityType,t.entityId),S=t.entityType==="goal"?(C=I.get(t.entityId))==null?void 0:C.title:t.entityType==="project"?(A=b.get(t.entityId))==null?void 0:A.title:t.entityType==="task"?(E=y.get(t.entityId))==null?void 0:E.title:`${t.entityType}:${t.entityId}`;return u?e.jsx($,{to:u,className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/78 transition hover:bg-white/[0.08]",children:e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-2",children:[e.jsx("span",{children:S}),e.jsx(L,{user:t.entityType==="goal"?(q=I.get(t.entityId))==null?void 0:q.user:t.entityType==="project"?(z=b.get(t.entityId))==null?void 0:z.user:t.entityType==="task"?(R=y.get(t.entityId))==null?void 0:R.user:t.entityType==="strategy"?(U=a.snapshot.strategies.find(H=>H.id===t.entityId))==null?void 0:U.user:null,compact:!0})]})},`${t.entityType}:${t.entityId}`):e.jsx("div",{className:"rounded-[16px] bg-white/[0.04] px-4 py-3 text-sm text-white/52",children:S},`${t.entityType}:${t.entityId}`)})]})]})]}),e.jsx(ne,{open:r,pending:n.isPending,editingStrategy:s,goals:a.snapshot.dashboard.goals,projects:a.snapshot.dashboard.projects,tasks:a.snapshot.tasks,habits:a.snapshot.habits,strategies:a.snapshot.strategies,users:a.snapshot.users,defaultUserId:l,initialStepId:j,onOpenChange:t=>{c(t),t||h(void 0)},onSubmit:async t=>{await n.mutateAsync({input:t,currentStrategyId:s.id})}})]}):e.jsx(F,{eyebrow:"Strategy",error:new Error("Strategy not found."),onRetry:()=>o("/strategies")})}export{Re as StrategyDetailPage};