@bitcobblers/wod-wiki-tools 0.45.2166 → 0.45.2167

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 (592) hide show
  1. package/dist/bin/wod.cjs +1 -1
  2. package/dist/bin/wod.cjs.map +1 -1
  3. package/dist/bin/wod.mjs +2 -2
  4. package/dist/{chunk-O5ZCOUQE.mjs → chunk-52NLI2DL.mjs} +3 -3
  5. package/dist/chunk-52NLI2DL.mjs.map +1 -0
  6. package/dist/{chunk-PF5BTGWZ.mjs → chunk-LZW3XW5N.mjs} +4 -4
  7. package/dist/{chunk-PF5BTGWZ.mjs.map → chunk-LZW3XW5N.mjs.map} +1 -1
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.mjs +2 -2
  11. package/dist/{scaffoldFeed-UXH3L5HM.mjs → scaffoldFeed-UD66SCQX.mjs} +3 -3
  12. package/dist/{scaffoldFeed-UXH3L5HM.mjs.map → scaffoldFeed-UD66SCQX.mjs.map} +1 -1
  13. package/dist/web/playground/assets/{main-DAHoAykp.js → main-CUs3less.js} +28 -28
  14. package/dist/web/playground/assets/{statementBuilderFlow-DHSfYrHi.js → statementBuilderFlow-krzOPRPk.js} +2 -2
  15. package/dist/web/playground/index.html +1 -1
  16. package/dist/web/playground/seed/core/chunks/{canvas.9ad327d4.json → canvas.0650818f.json} +1 -1
  17. package/dist/web/playground/seed/core/chunks/{dashboards.f4196444.json → dashboards.44097ca1.json} +1 -1
  18. package/dist/web/playground/seed/core/chunks/{efforts.7f0d2160.json → efforts.4edf1983.json} +1 -1
  19. package/dist/web/playground/seed/core/chunks/{equipment.e7531ab5.json → equipment.d90bd3bc.json} +1 -1
  20. package/dist/web/playground/seed/core/indexes/notebooks/canvas.json +173 -173
  21. package/dist/web/playground/seed/core/indexes/notebooks/dashboards.json +13 -13
  22. package/dist/web/playground/seed/core/indexes/notebooks/efforts.json +323 -323
  23. package/dist/web/playground/seed/core/indexes/notebooks/equipment.json +47 -47
  24. package/dist/web/playground/seed/core/manifest.json +567 -567
  25. package/dist/web/playground/seed/core/markdown/canvas/ai-first/README.json +1 -1
  26. package/dist/web/playground/seed/core/markdown/canvas/guide/README.json +4 -4
  27. package/dist/web/playground/seed/core/markdown/canvas/guide/clock.json +1 -1
  28. package/dist/web/playground/seed/core/markdown/canvas/guide/dashboards.json +2 -2
  29. package/dist/web/playground/seed/core/markdown/canvas/guide/metrics.json +12 -12
  30. package/dist/web/playground/seed/core/markdown/canvas/guide/protocols.json +20 -20
  31. package/dist/web/playground/seed/core/markdown/canvas/guide/sessions.json +30 -30
  32. package/dist/web/playground/seed/core/markdown/canvas/guide/start.json +10 -10
  33. package/dist/web/playground/seed/core/markdown/canvas/guide/structure.json +24 -24
  34. package/dist/web/playground/seed/core/markdown/canvas/guide/wql.json +5 -5
  35. package/dist/web/playground/seed/core/markdown/canvas/home/sample-script.json +4 -4
  36. package/dist/web/playground/seed/core/markdown/canvas/home/welcome-1.json +2 -2
  37. package/dist/web/playground/seed/core/markdown/canvas/syntax/actions-comments.json +4 -4
  38. package/dist/web/playground/seed/core/markdown/canvas/syntax/alternating-emom.json +5 -5
  39. package/dist/web/playground/seed/core/markdown/canvas/syntax/basic-emom.json +4 -4
  40. package/dist/web/playground/seed/core/markdown/canvas/syntax/calculated-metrics.json +4 -4
  41. package/dist/web/playground/seed/core/markdown/canvas/syntax/classic-amrap.json +6 -6
  42. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-barbell-cycling.json +4 -4
  43. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-full-session.json +9 -9
  44. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-nested-protocols.json +7 -7
  45. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-partner-workout.json +7 -7
  46. package/dist/web/playground/seed/core/markdown/canvas/syntax/complex-swimming.json +3 -3
  47. package/dist/web/playground/seed/core/markdown/canvas/syntax/core-rules.json +4 -4
  48. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-and-calculated-metrics.json +7 -7
  49. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-intervals.json +4 -4
  50. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-1.json +4 -4
  51. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-2.json +5 -5
  52. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-3.json +2 -2
  53. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-4.json +4 -4
  54. package/dist/web/playground/seed/core/markdown/canvas/syntax/custom-metrics-5.json +4 -4
  55. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-climb-bouldering.json +2 -2
  56. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-climb-hangboard.json +2 -2
  57. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-climb-sport.json +2 -2
  58. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-log.json +4 -4
  59. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-plan.json +8 -8
  60. package/dist/web/playground/seed/core/markdown/canvas/syntax/dialect-wod.json +5 -5
  61. package/dist/web/playground/seed/core/markdown/canvas/syntax/distance-intervals.json +3 -3
  62. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-1.json +4 -4
  63. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-2.json +5 -5
  64. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-3.json +10 -10
  65. package/dist/web/playground/seed/core/markdown/canvas/syntax/document-4.json +4 -4
  66. package/dist/web/playground/seed/core/markdown/canvas/syntax/effort-notes.json +4 -4
  67. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-1.json +5 -5
  68. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-2.json +6 -6
  69. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-3.json +3 -3
  70. package/dist/web/playground/seed/core/markdown/canvas/syntax/groups-4.json +3 -3
  71. package/dist/web/playground/seed/core/markdown/canvas/syntax/longer-duration.json +4 -4
  72. package/dist/web/playground/seed/core/markdown/canvas/syntax/longer-intervals.json +4 -4
  73. package/dist/web/playground/seed/core/markdown/canvas/syntax/measurements.json +4 -4
  74. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-1.json +5 -5
  75. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-2.json +7 -7
  76. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-3.json +8 -8
  77. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-4.json +5 -5
  78. package/dist/web/playground/seed/core/markdown/canvas/syntax/metrics-5.json +5 -5
  79. package/dist/web/playground/seed/core/markdown/canvas/syntax/mixed-sections.json +8 -8
  80. package/dist/web/playground/seed/core/markdown/canvas/syntax/mixed-timers.json +5 -5
  81. package/dist/web/playground/seed/core/markdown/canvas/syntax/multiple-amrap-windows.json +7 -7
  82. package/dist/web/playground/seed/core/markdown/canvas/syntax/multiple-sets.json +4 -4
  83. package/dist/web/playground/seed/core/markdown/canvas/syntax/named-groups.json +5 -5
  84. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-1.json +6 -6
  85. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-2.json +4 -4
  86. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-3.json +6 -6
  87. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-4.json +3 -3
  88. package/dist/web/playground/seed/core/markdown/canvas/syntax/protocols-5.json +4 -4
  89. package/dist/web/playground/seed/core/markdown/canvas/syntax/single-movement.json +3 -3
  90. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-1.json +4 -4
  91. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-2.json +5 -5
  92. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-3.json +4 -4
  93. package/dist/web/playground/seed/core/markdown/canvas/syntax/supplemental-4.json +4 -4
  94. package/dist/web/playground/seed/core/markdown/canvas/syntax/time-cap.json +6 -6
  95. package/dist/web/playground/seed/core/markdown/canvas/syntax/timer-modifiers.json +6 -6
  96. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-1.json +6 -6
  97. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-2.json +4 -4
  98. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-3.json +3 -3
  99. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-4.json +4 -4
  100. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-5.json +5 -5
  101. package/dist/web/playground/seed/core/markdown/canvas/syntax/timers-rest.json +4 -4
  102. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/aggregate-by-effort.json +2 -2
  103. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/aggregate-by-week.json +2 -2
  104. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/content-fran.json +2 -2
  105. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/filter-combos.json +2 -2
  106. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/pipes-limit.json +2 -2
  107. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/session-rpe.json +2 -2
  108. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/source-journal.json +2 -2
  109. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/tis-trend.json +2 -2
  110. package/dist/web/playground/seed/core/markdown/canvas/wql-presets/where-join.json +2 -2
  111. package/dist/web/playground/seed/core/markdown/dashboards/benchmark-pr-board.json +6 -6
  112. package/dist/web/playground/seed/core/markdown/dashboards/finger-strength-v8.json +5 -5
  113. package/dist/web/playground/seed/core/markdown/dashboards/polarized-base-marathon.json +9 -9
  114. package/dist/web/playground/seed/core/markdown/dashboards/recovery-readiness.json +7 -7
  115. package/dist/web/playground/seed/core/markdown/dashboards/road-to-560-total.json +9 -9
  116. package/dist/web/playground/seed/core/markdown/dashboards/training-block-review.json +11 -11
  117. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/air-squat.json +1 -1
  118. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/box-jump.json +1 -1
  119. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/broad-jump.json +1 -1
  120. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/burpee-box-jump-over.json +1 -1
  121. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/burpee-over-dumbbell.json +1 -1
  122. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/burpee.json +1 -1
  123. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/dumbbell-squat-clean.json +1 -1
  124. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/ghd-sit-up.json +1 -1
  125. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/ground-kong.json +1 -1
  126. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/jumping-jack.json +1 -1
  127. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/kong-walk.json +1 -1
  128. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/lunge.json +1 -1
  129. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/overhead-squat.json +1 -1
  130. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/parkour-roll.json +1 -1
  131. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/parkour-squat.json +1 -1
  132. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/pistol-squat.json +1 -1
  133. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/plank.json +1 -1
  134. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/precision-burpee.json +1 -1
  135. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/precision-jump.json +1 -1
  136. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/quadrupedal-movement.json +1 -1
  137. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/russian-twist.json +1 -1
  138. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/sit-up.json +1 -1
  139. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/squat-clean.json +1 -1
  140. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/squat-hold.json +1 -1
  141. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/squat-snatch.json +1 -1
  142. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/tuck-jump.json +1 -1
  143. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/wall-ball.json +1 -1
  144. package/dist/web/playground/seed/core/markdown/efforts/bodyweight/wall-burpee.json +1 -1
  145. package/dist/web/playground/seed/core/markdown/efforts/cycling/assault-bike.json +1 -1
  146. package/dist/web/playground/seed/core/markdown/efforts/cycling/cycling-moderate.json +1 -1
  147. package/dist/web/playground/seed/core/markdown/efforts/cycling/cycling-vigorous.json +1 -1
  148. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/assisted-pull-up.json +1 -1
  149. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/burpee-pull-up.json +1 -1
  150. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/chest-to-bar-pull-up.json +1 -1
  151. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/dip.json +1 -1
  152. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/double-under.json +1 -1
  153. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/handstand-hold.json +1 -1
  154. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/handstand-push-up.json +1 -1
  155. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/handstand-walk.json +1 -1
  156. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/jump-rope.json +1 -1
  157. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/jumping-pull-up.json +1 -1
  158. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/jumping-push-up.json +1 -1
  159. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/l-sit-pull-up.json +1 -1
  160. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/muscle-up.json +1 -1
  161. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/pull-up.json +1 -1
  162. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/push-up.json +1 -1
  163. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/reverse-wall-dip.json +1 -1
  164. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/rope-climb.json +1 -1
  165. package/dist/web/playground/seed/core/markdown/efforts/gymnastics/toes-to-bar.json +1 -1
  166. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-arm-bar.json +1 -1
  167. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-around-the-world.json +1 -1
  168. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-bent-over-row.json +1 -1
  169. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-jerk.json +1 -1
  170. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-press.json +1 -1
  171. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-clean.json +1 -1
  172. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-deadlift.json +1 -1
  173. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-floor-press.json +1 -1
  174. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-front-squat.json +1 -1
  175. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-goblet-squat.json +1 -1
  176. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-gorilla-row.json +1 -1
  177. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-halo.json +1 -1
  178. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-jerk.json +1 -1
  179. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-overhead-squat.json +1 -1
  180. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-press.json +1 -1
  181. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-snatch.json +1 -1
  182. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-swing.json +1 -1
  183. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/kettlebell-windmill.json +1 -1
  184. package/dist/web/playground/seed/core/markdown/efforts/kettlebell/turkish-get-up.json +1 -1
  185. package/dist/web/playground/seed/core/markdown/efforts/recovery/rest.json +1 -1
  186. package/dist/web/playground/seed/core/markdown/efforts/recovery/stretching.json +1 -1
  187. package/dist/web/playground/seed/core/markdown/efforts/rowing/rowing-sprint.json +1 -1
  188. package/dist/web/playground/seed/core/markdown/efforts/rowing/rowing.json +1 -1
  189. package/dist/web/playground/seed/core/markdown/efforts/rowing/ski-erg.json +1 -1
  190. package/dist/web/playground/seed/core/markdown/efforts/running/backward-running.json +1 -1
  191. package/dist/web/playground/seed/core/markdown/efforts/running/running-6-mph.json +1 -1
  192. package/dist/web/playground/seed/core/markdown/efforts/running/running-8-mph.json +1 -1
  193. package/dist/web/playground/seed/core/markdown/efforts/running/running-sprint.json +1 -1
  194. package/dist/web/playground/seed/core/markdown/efforts/snatch.json +2 -2
  195. package/dist/web/playground/seed/core/markdown/efforts/strength/back-squat.json +1 -1
  196. package/dist/web/playground/seed/core/markdown/efforts/strength/bench-press.json +1 -1
  197. package/dist/web/playground/seed/core/markdown/efforts/strength/box-step-up.json +1 -1
  198. package/dist/web/playground/seed/core/markdown/efforts/strength/carioca.json +1 -1
  199. package/dist/web/playground/seed/core/markdown/efforts/strength/clean-and-jerk.json +1 -1
  200. package/dist/web/playground/seed/core/markdown/efforts/strength/cluster.json +1 -1
  201. package/dist/web/playground/seed/core/markdown/efforts/strength/dead-hang.json +1 -1
  202. package/dist/web/playground/seed/core/markdown/efforts/strength/deadlift.json +1 -1
  203. package/dist/web/playground/seed/core/markdown/efforts/strength/devils-press.json +1 -1
  204. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-box-step-up.json +1 -1
  205. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-clean.json +1 -1
  206. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-fly.json +1 -1
  207. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-row.json +1 -1
  208. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-snatch.json +1 -1
  209. package/dist/web/playground/seed/core/markdown/efforts/strength/dumbbell-thruster.json +1 -1
  210. package/dist/web/playground/seed/core/markdown/efforts/strength/elbows-to-knees.json +1 -1
  211. package/dist/web/playground/seed/core/markdown/efforts/strength/farmer-carry.json +1 -1
  212. package/dist/web/playground/seed/core/markdown/efforts/strength/frog-stand.json +1 -1
  213. package/dist/web/playground/seed/core/markdown/efforts/strength/front-squat.json +1 -1
  214. package/dist/web/playground/seed/core/markdown/efforts/strength/good-morning.json +1 -1
  215. package/dist/web/playground/seed/core/markdown/efforts/strength/hanging-leg-raise.json +1 -1
  216. package/dist/web/playground/seed/core/markdown/efforts/strength/hollow-rock.json +1 -1
  217. package/dist/web/playground/seed/core/markdown/efforts/strength/knees-to-elbows.json +1 -1
  218. package/dist/web/playground/seed/core/markdown/efforts/strength/l-sit.json +1 -1
  219. package/dist/web/playground/seed/core/markdown/efforts/strength/man-maker.json +1 -1
  220. package/dist/web/playground/seed/core/markdown/efforts/strength/medicine-ball-clean.json +1 -1
  221. package/dist/web/playground/seed/core/markdown/efforts/strength/overhead-press.json +1 -1
  222. package/dist/web/playground/seed/core/markdown/efforts/strength/parkour-vault.json +1 -1
  223. package/dist/web/playground/seed/core/markdown/efforts/strength/pig-flip.json +1 -1
  224. package/dist/web/playground/seed/core/markdown/efforts/strength/power-clean.json +1 -1
  225. package/dist/web/playground/seed/core/markdown/efforts/strength/power-snatch.json +1 -1
  226. package/dist/web/playground/seed/core/markdown/efforts/strength/push-jerk.json +1 -1
  227. package/dist/web/playground/seed/core/markdown/efforts/strength/push-press.json +1 -1
  228. package/dist/web/playground/seed/core/markdown/efforts/strength/romanian-deadlift.json +1 -1
  229. package/dist/web/playground/seed/core/markdown/efforts/strength/single-leg-deadlift.json +1 -1
  230. package/dist/web/playground/seed/core/markdown/efforts/strength/skull-crusher.json +1 -1
  231. package/dist/web/playground/seed/core/markdown/efforts/strength/slam-ball.json +1 -1
  232. package/dist/web/playground/seed/core/markdown/efforts/strength/sled-pull.json +1 -1
  233. package/dist/web/playground/seed/core/markdown/efforts/strength/sled-push.json +1 -1
  234. package/dist/web/playground/seed/core/markdown/efforts/strength/sumo-deadlift.json +1 -1
  235. package/dist/web/playground/seed/core/markdown/efforts/strength/thruster.json +1 -1
  236. package/dist/web/playground/seed/core/markdown/efforts/strength/triceps-extension.json +1 -1
  237. package/dist/web/playground/seed/core/markdown/efforts/strength/v-sit-hold.json +1 -1
  238. package/dist/web/playground/seed/core/markdown/efforts/strength/wall-walk.json +1 -1
  239. package/dist/web/playground/seed/core/markdown/efforts/strength/yoga-sun-salutation.json +1 -1
  240. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-assisted-sprint.json +1 -1
  241. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-backstroke.json +1 -1
  242. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-breaststroke-kick.json +1 -1
  243. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-breaststroke.json +1 -1
  244. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-butterfly.json +1 -1
  245. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-catch-up-drill.json +1 -1
  246. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-choice-stroke.json +1 -1
  247. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-dive-start.json +1 -1
  248. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-dolphin-kick.json +1 -1
  249. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-drafting.json +1 -1
  250. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-fingertip-drag.json +1 -1
  251. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-freestyle.json +1 -1
  252. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-individual-medley.json +1 -1
  253. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-kick.json +1 -1
  254. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-pull.json +1 -1
  255. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-resisted-sprint.json +1 -1
  256. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-rotation-drill.json +1 -1
  257. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-sighting.json +1 -1
  258. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-single-arm-drill.json +1 -1
  259. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-stroke-transition.json +1 -1
  260. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-two-kick-one-pull.json +1 -1
  261. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming-vigorous.json +1 -1
  262. package/dist/web/playground/seed/core/markdown/efforts/swimming/swimming.json +1 -1
  263. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-arm-cast.json +1 -1
  264. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-circles.json +1 -1
  265. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-mill.json +1 -1
  266. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-reverse-mill.json +1 -1
  267. package/dist/web/playground/seed/core/markdown/efforts/unconventional/clubbell-shield-cast.json +1 -1
  268. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-10-to-2-swing.json +1 -1
  269. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-360-swing.json +1 -1
  270. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-barbarian-squat.json +1 -1
  271. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-flow.json +1 -1
  272. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-gravedigger.json +1 -1
  273. package/dist/web/playground/seed/core/markdown/efforts/unconventional/macebell-touchdown.json +1 -1
  274. package/dist/web/playground/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-carry.json +1 -1
  275. package/dist/web/playground/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-extension.json +1 -1
  276. package/dist/web/playground/seed/core/markdown/efforts/unconventional/sandbag-over-shoulder.json +1 -1
  277. package/dist/web/playground/seed/core/markdown/efforts/walking/walking-3-mph.json +1 -1
  278. package/dist/web/playground/seed/core/markdown/equipment/air-bike.json +1 -1
  279. package/dist/web/playground/seed/core/markdown/equipment/barbell.json +1 -1
  280. package/dist/web/playground/seed/core/markdown/equipment/bench.json +1 -1
  281. package/dist/web/playground/seed/core/markdown/equipment/bike-erg.json +1 -1
  282. package/dist/web/playground/seed/core/markdown/equipment/climbing-rope.json +1 -1
  283. package/dist/web/playground/seed/core/markdown/equipment/clubs.json +1 -1
  284. package/dist/web/playground/seed/core/markdown/equipment/dumbbell.json +1 -1
  285. package/dist/web/playground/seed/core/markdown/equipment/ghd.json +1 -1
  286. package/dist/web/playground/seed/core/markdown/equipment/gymnastic-rings.json +1 -1
  287. package/dist/web/playground/seed/core/markdown/equipment/jump-rope.json +1 -1
  288. package/dist/web/playground/seed/core/markdown/equipment/kettlebell.json +1 -1
  289. package/dist/web/playground/seed/core/markdown/equipment/macebell.json +1 -1
  290. package/dist/web/playground/seed/core/markdown/equipment/medicine-ball.json +1 -1
  291. package/dist/web/playground/seed/core/markdown/equipment/parallettes.json +1 -1
  292. package/dist/web/playground/seed/core/markdown/equipment/plyo-box.json +1 -1
  293. package/dist/web/playground/seed/core/markdown/equipment/pull-up-bar.json +1 -1
  294. package/dist/web/playground/seed/core/markdown/equipment/rower.json +1 -1
  295. package/dist/web/playground/seed/core/markdown/equipment/sandbag.json +1 -1
  296. package/dist/web/playground/seed/core/markdown/equipment/ski-erg.json +1 -1
  297. package/dist/web/playground/seed/core/markdown/equipment/slam-ball.json +1 -1
  298. package/dist/web/playground/seed/core/markdown/equipment/sled.json +1 -1
  299. package/dist/web/playground/seed/core/markdown/equipment/sledgehammer.json +1 -1
  300. package/dist/web/playground/seed/core/markdown/equipment/weight-vest.json +1 -1
  301. package/dist/web/playground/seed/core/report.html +13 -13
  302. package/dist/web/server/assets/{main-C_b1CczJ.js → main-DyBj7Ku9.js} +28 -28
  303. package/dist/web/server/assets/{statementBuilderFlow-BPmNsGND.js → statementBuilderFlow-Vjl3_h6f.js} +2 -2
  304. package/dist/web/server/index.html +1 -1
  305. package/dist/web/server/seed/core/chunks/{canvas.9ad327d4.json → canvas.0650818f.json} +1 -1
  306. package/dist/web/server/seed/core/chunks/{dashboards.f4196444.json → dashboards.44097ca1.json} +1 -1
  307. package/dist/web/server/seed/core/chunks/{efforts.7f0d2160.json → efforts.4edf1983.json} +1 -1
  308. package/dist/web/server/seed/core/chunks/{equipment.e7531ab5.json → equipment.d90bd3bc.json} +1 -1
  309. package/dist/web/server/seed/core/indexes/notebooks/canvas.json +173 -173
  310. package/dist/web/server/seed/core/indexes/notebooks/dashboards.json +13 -13
  311. package/dist/web/server/seed/core/indexes/notebooks/efforts.json +323 -323
  312. package/dist/web/server/seed/core/indexes/notebooks/equipment.json +47 -47
  313. package/dist/web/server/seed/core/manifest.json +567 -567
  314. package/dist/web/server/seed/core/markdown/canvas/ai-first/README.json +1 -1
  315. package/dist/web/server/seed/core/markdown/canvas/guide/README.json +4 -4
  316. package/dist/web/server/seed/core/markdown/canvas/guide/clock.json +1 -1
  317. package/dist/web/server/seed/core/markdown/canvas/guide/dashboards.json +2 -2
  318. package/dist/web/server/seed/core/markdown/canvas/guide/metrics.json +12 -12
  319. package/dist/web/server/seed/core/markdown/canvas/guide/protocols.json +20 -20
  320. package/dist/web/server/seed/core/markdown/canvas/guide/sessions.json +30 -30
  321. package/dist/web/server/seed/core/markdown/canvas/guide/start.json +10 -10
  322. package/dist/web/server/seed/core/markdown/canvas/guide/structure.json +24 -24
  323. package/dist/web/server/seed/core/markdown/canvas/guide/wql.json +5 -5
  324. package/dist/web/server/seed/core/markdown/canvas/home/sample-script.json +4 -4
  325. package/dist/web/server/seed/core/markdown/canvas/home/welcome-1.json +2 -2
  326. package/dist/web/server/seed/core/markdown/canvas/syntax/actions-comments.json +4 -4
  327. package/dist/web/server/seed/core/markdown/canvas/syntax/alternating-emom.json +5 -5
  328. package/dist/web/server/seed/core/markdown/canvas/syntax/basic-emom.json +4 -4
  329. package/dist/web/server/seed/core/markdown/canvas/syntax/calculated-metrics.json +4 -4
  330. package/dist/web/server/seed/core/markdown/canvas/syntax/classic-amrap.json +6 -6
  331. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-barbell-cycling.json +4 -4
  332. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-full-session.json +9 -9
  333. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-nested-protocols.json +7 -7
  334. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-partner-workout.json +7 -7
  335. package/dist/web/server/seed/core/markdown/canvas/syntax/complex-swimming.json +3 -3
  336. package/dist/web/server/seed/core/markdown/canvas/syntax/core-rules.json +4 -4
  337. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-and-calculated-metrics.json +7 -7
  338. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-intervals.json +4 -4
  339. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-1.json +4 -4
  340. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-2.json +5 -5
  341. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-3.json +2 -2
  342. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-4.json +4 -4
  343. package/dist/web/server/seed/core/markdown/canvas/syntax/custom-metrics-5.json +4 -4
  344. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-climb-bouldering.json +2 -2
  345. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-climb-hangboard.json +2 -2
  346. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-climb-sport.json +2 -2
  347. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-log.json +4 -4
  348. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-plan.json +8 -8
  349. package/dist/web/server/seed/core/markdown/canvas/syntax/dialect-wod.json +5 -5
  350. package/dist/web/server/seed/core/markdown/canvas/syntax/distance-intervals.json +3 -3
  351. package/dist/web/server/seed/core/markdown/canvas/syntax/document-1.json +4 -4
  352. package/dist/web/server/seed/core/markdown/canvas/syntax/document-2.json +5 -5
  353. package/dist/web/server/seed/core/markdown/canvas/syntax/document-3.json +10 -10
  354. package/dist/web/server/seed/core/markdown/canvas/syntax/document-4.json +4 -4
  355. package/dist/web/server/seed/core/markdown/canvas/syntax/effort-notes.json +4 -4
  356. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-1.json +5 -5
  357. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-2.json +6 -6
  358. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-3.json +3 -3
  359. package/dist/web/server/seed/core/markdown/canvas/syntax/groups-4.json +3 -3
  360. package/dist/web/server/seed/core/markdown/canvas/syntax/longer-duration.json +4 -4
  361. package/dist/web/server/seed/core/markdown/canvas/syntax/longer-intervals.json +4 -4
  362. package/dist/web/server/seed/core/markdown/canvas/syntax/measurements.json +4 -4
  363. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-1.json +5 -5
  364. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-2.json +7 -7
  365. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-3.json +8 -8
  366. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-4.json +5 -5
  367. package/dist/web/server/seed/core/markdown/canvas/syntax/metrics-5.json +5 -5
  368. package/dist/web/server/seed/core/markdown/canvas/syntax/mixed-sections.json +8 -8
  369. package/dist/web/server/seed/core/markdown/canvas/syntax/mixed-timers.json +5 -5
  370. package/dist/web/server/seed/core/markdown/canvas/syntax/multiple-amrap-windows.json +7 -7
  371. package/dist/web/server/seed/core/markdown/canvas/syntax/multiple-sets.json +4 -4
  372. package/dist/web/server/seed/core/markdown/canvas/syntax/named-groups.json +5 -5
  373. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-1.json +6 -6
  374. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-2.json +4 -4
  375. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-3.json +6 -6
  376. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-4.json +3 -3
  377. package/dist/web/server/seed/core/markdown/canvas/syntax/protocols-5.json +4 -4
  378. package/dist/web/server/seed/core/markdown/canvas/syntax/single-movement.json +3 -3
  379. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-1.json +4 -4
  380. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-2.json +5 -5
  381. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-3.json +4 -4
  382. package/dist/web/server/seed/core/markdown/canvas/syntax/supplemental-4.json +4 -4
  383. package/dist/web/server/seed/core/markdown/canvas/syntax/time-cap.json +6 -6
  384. package/dist/web/server/seed/core/markdown/canvas/syntax/timer-modifiers.json +6 -6
  385. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-1.json +6 -6
  386. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-2.json +4 -4
  387. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-3.json +3 -3
  388. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-4.json +4 -4
  389. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-5.json +5 -5
  390. package/dist/web/server/seed/core/markdown/canvas/syntax/timers-rest.json +4 -4
  391. package/dist/web/server/seed/core/markdown/canvas/wql-presets/aggregate-by-effort.json +2 -2
  392. package/dist/web/server/seed/core/markdown/canvas/wql-presets/aggregate-by-week.json +2 -2
  393. package/dist/web/server/seed/core/markdown/canvas/wql-presets/content-fran.json +2 -2
  394. package/dist/web/server/seed/core/markdown/canvas/wql-presets/filter-combos.json +2 -2
  395. package/dist/web/server/seed/core/markdown/canvas/wql-presets/pipes-limit.json +2 -2
  396. package/dist/web/server/seed/core/markdown/canvas/wql-presets/session-rpe.json +2 -2
  397. package/dist/web/server/seed/core/markdown/canvas/wql-presets/source-journal.json +2 -2
  398. package/dist/web/server/seed/core/markdown/canvas/wql-presets/tis-trend.json +2 -2
  399. package/dist/web/server/seed/core/markdown/canvas/wql-presets/where-join.json +2 -2
  400. package/dist/web/server/seed/core/markdown/dashboards/benchmark-pr-board.json +6 -6
  401. package/dist/web/server/seed/core/markdown/dashboards/finger-strength-v8.json +5 -5
  402. package/dist/web/server/seed/core/markdown/dashboards/polarized-base-marathon.json +9 -9
  403. package/dist/web/server/seed/core/markdown/dashboards/recovery-readiness.json +7 -7
  404. package/dist/web/server/seed/core/markdown/dashboards/road-to-560-total.json +9 -9
  405. package/dist/web/server/seed/core/markdown/dashboards/training-block-review.json +11 -11
  406. package/dist/web/server/seed/core/markdown/efforts/bodyweight/air-squat.json +1 -1
  407. package/dist/web/server/seed/core/markdown/efforts/bodyweight/box-jump.json +1 -1
  408. package/dist/web/server/seed/core/markdown/efforts/bodyweight/broad-jump.json +1 -1
  409. package/dist/web/server/seed/core/markdown/efforts/bodyweight/burpee-box-jump-over.json +1 -1
  410. package/dist/web/server/seed/core/markdown/efforts/bodyweight/burpee-over-dumbbell.json +1 -1
  411. package/dist/web/server/seed/core/markdown/efforts/bodyweight/burpee.json +1 -1
  412. package/dist/web/server/seed/core/markdown/efforts/bodyweight/dumbbell-squat-clean.json +1 -1
  413. package/dist/web/server/seed/core/markdown/efforts/bodyweight/ghd-sit-up.json +1 -1
  414. package/dist/web/server/seed/core/markdown/efforts/bodyweight/ground-kong.json +1 -1
  415. package/dist/web/server/seed/core/markdown/efforts/bodyweight/jumping-jack.json +1 -1
  416. package/dist/web/server/seed/core/markdown/efforts/bodyweight/kong-walk.json +1 -1
  417. package/dist/web/server/seed/core/markdown/efforts/bodyweight/lunge.json +1 -1
  418. package/dist/web/server/seed/core/markdown/efforts/bodyweight/overhead-squat.json +1 -1
  419. package/dist/web/server/seed/core/markdown/efforts/bodyweight/parkour-roll.json +1 -1
  420. package/dist/web/server/seed/core/markdown/efforts/bodyweight/parkour-squat.json +1 -1
  421. package/dist/web/server/seed/core/markdown/efforts/bodyweight/pistol-squat.json +1 -1
  422. package/dist/web/server/seed/core/markdown/efforts/bodyweight/plank.json +1 -1
  423. package/dist/web/server/seed/core/markdown/efforts/bodyweight/precision-burpee.json +1 -1
  424. package/dist/web/server/seed/core/markdown/efforts/bodyweight/precision-jump.json +1 -1
  425. package/dist/web/server/seed/core/markdown/efforts/bodyweight/quadrupedal-movement.json +1 -1
  426. package/dist/web/server/seed/core/markdown/efforts/bodyweight/russian-twist.json +1 -1
  427. package/dist/web/server/seed/core/markdown/efforts/bodyweight/sit-up.json +1 -1
  428. package/dist/web/server/seed/core/markdown/efforts/bodyweight/squat-clean.json +1 -1
  429. package/dist/web/server/seed/core/markdown/efforts/bodyweight/squat-hold.json +1 -1
  430. package/dist/web/server/seed/core/markdown/efforts/bodyweight/squat-snatch.json +1 -1
  431. package/dist/web/server/seed/core/markdown/efforts/bodyweight/tuck-jump.json +1 -1
  432. package/dist/web/server/seed/core/markdown/efforts/bodyweight/wall-ball.json +1 -1
  433. package/dist/web/server/seed/core/markdown/efforts/bodyweight/wall-burpee.json +1 -1
  434. package/dist/web/server/seed/core/markdown/efforts/cycling/assault-bike.json +1 -1
  435. package/dist/web/server/seed/core/markdown/efforts/cycling/cycling-moderate.json +1 -1
  436. package/dist/web/server/seed/core/markdown/efforts/cycling/cycling-vigorous.json +1 -1
  437. package/dist/web/server/seed/core/markdown/efforts/gymnastics/assisted-pull-up.json +1 -1
  438. package/dist/web/server/seed/core/markdown/efforts/gymnastics/burpee-pull-up.json +1 -1
  439. package/dist/web/server/seed/core/markdown/efforts/gymnastics/chest-to-bar-pull-up.json +1 -1
  440. package/dist/web/server/seed/core/markdown/efforts/gymnastics/dip.json +1 -1
  441. package/dist/web/server/seed/core/markdown/efforts/gymnastics/double-under.json +1 -1
  442. package/dist/web/server/seed/core/markdown/efforts/gymnastics/handstand-hold.json +1 -1
  443. package/dist/web/server/seed/core/markdown/efforts/gymnastics/handstand-push-up.json +1 -1
  444. package/dist/web/server/seed/core/markdown/efforts/gymnastics/handstand-walk.json +1 -1
  445. package/dist/web/server/seed/core/markdown/efforts/gymnastics/jump-rope.json +1 -1
  446. package/dist/web/server/seed/core/markdown/efforts/gymnastics/jumping-pull-up.json +1 -1
  447. package/dist/web/server/seed/core/markdown/efforts/gymnastics/jumping-push-up.json +1 -1
  448. package/dist/web/server/seed/core/markdown/efforts/gymnastics/l-sit-pull-up.json +1 -1
  449. package/dist/web/server/seed/core/markdown/efforts/gymnastics/muscle-up.json +1 -1
  450. package/dist/web/server/seed/core/markdown/efforts/gymnastics/pull-up.json +1 -1
  451. package/dist/web/server/seed/core/markdown/efforts/gymnastics/push-up.json +1 -1
  452. package/dist/web/server/seed/core/markdown/efforts/gymnastics/reverse-wall-dip.json +1 -1
  453. package/dist/web/server/seed/core/markdown/efforts/gymnastics/rope-climb.json +1 -1
  454. package/dist/web/server/seed/core/markdown/efforts/gymnastics/toes-to-bar.json +1 -1
  455. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-arm-bar.json +1 -1
  456. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-around-the-world.json +1 -1
  457. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-bent-over-row.json +1 -1
  458. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-jerk.json +1 -1
  459. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-clean-and-press.json +1 -1
  460. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-clean.json +1 -1
  461. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-deadlift.json +1 -1
  462. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-floor-press.json +1 -1
  463. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-front-squat.json +1 -1
  464. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-goblet-squat.json +1 -1
  465. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-gorilla-row.json +1 -1
  466. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-halo.json +1 -1
  467. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-jerk.json +1 -1
  468. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-overhead-squat.json +1 -1
  469. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-press.json +1 -1
  470. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-snatch.json +1 -1
  471. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-swing.json +1 -1
  472. package/dist/web/server/seed/core/markdown/efforts/kettlebell/kettlebell-windmill.json +1 -1
  473. package/dist/web/server/seed/core/markdown/efforts/kettlebell/turkish-get-up.json +1 -1
  474. package/dist/web/server/seed/core/markdown/efforts/recovery/rest.json +1 -1
  475. package/dist/web/server/seed/core/markdown/efforts/recovery/stretching.json +1 -1
  476. package/dist/web/server/seed/core/markdown/efforts/rowing/rowing-sprint.json +1 -1
  477. package/dist/web/server/seed/core/markdown/efforts/rowing/rowing.json +1 -1
  478. package/dist/web/server/seed/core/markdown/efforts/rowing/ski-erg.json +1 -1
  479. package/dist/web/server/seed/core/markdown/efforts/running/backward-running.json +1 -1
  480. package/dist/web/server/seed/core/markdown/efforts/running/running-6-mph.json +1 -1
  481. package/dist/web/server/seed/core/markdown/efforts/running/running-8-mph.json +1 -1
  482. package/dist/web/server/seed/core/markdown/efforts/running/running-sprint.json +1 -1
  483. package/dist/web/server/seed/core/markdown/efforts/snatch.json +2 -2
  484. package/dist/web/server/seed/core/markdown/efforts/strength/back-squat.json +1 -1
  485. package/dist/web/server/seed/core/markdown/efforts/strength/bench-press.json +1 -1
  486. package/dist/web/server/seed/core/markdown/efforts/strength/box-step-up.json +1 -1
  487. package/dist/web/server/seed/core/markdown/efforts/strength/carioca.json +1 -1
  488. package/dist/web/server/seed/core/markdown/efforts/strength/clean-and-jerk.json +1 -1
  489. package/dist/web/server/seed/core/markdown/efforts/strength/cluster.json +1 -1
  490. package/dist/web/server/seed/core/markdown/efforts/strength/dead-hang.json +1 -1
  491. package/dist/web/server/seed/core/markdown/efforts/strength/deadlift.json +1 -1
  492. package/dist/web/server/seed/core/markdown/efforts/strength/devils-press.json +1 -1
  493. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-box-step-up.json +1 -1
  494. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-clean.json +1 -1
  495. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-fly.json +1 -1
  496. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-row.json +1 -1
  497. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-snatch.json +1 -1
  498. package/dist/web/server/seed/core/markdown/efforts/strength/dumbbell-thruster.json +1 -1
  499. package/dist/web/server/seed/core/markdown/efforts/strength/elbows-to-knees.json +1 -1
  500. package/dist/web/server/seed/core/markdown/efforts/strength/farmer-carry.json +1 -1
  501. package/dist/web/server/seed/core/markdown/efforts/strength/frog-stand.json +1 -1
  502. package/dist/web/server/seed/core/markdown/efforts/strength/front-squat.json +1 -1
  503. package/dist/web/server/seed/core/markdown/efforts/strength/good-morning.json +1 -1
  504. package/dist/web/server/seed/core/markdown/efforts/strength/hanging-leg-raise.json +1 -1
  505. package/dist/web/server/seed/core/markdown/efforts/strength/hollow-rock.json +1 -1
  506. package/dist/web/server/seed/core/markdown/efforts/strength/knees-to-elbows.json +1 -1
  507. package/dist/web/server/seed/core/markdown/efforts/strength/l-sit.json +1 -1
  508. package/dist/web/server/seed/core/markdown/efforts/strength/man-maker.json +1 -1
  509. package/dist/web/server/seed/core/markdown/efforts/strength/medicine-ball-clean.json +1 -1
  510. package/dist/web/server/seed/core/markdown/efforts/strength/overhead-press.json +1 -1
  511. package/dist/web/server/seed/core/markdown/efforts/strength/parkour-vault.json +1 -1
  512. package/dist/web/server/seed/core/markdown/efforts/strength/pig-flip.json +1 -1
  513. package/dist/web/server/seed/core/markdown/efforts/strength/power-clean.json +1 -1
  514. package/dist/web/server/seed/core/markdown/efforts/strength/power-snatch.json +1 -1
  515. package/dist/web/server/seed/core/markdown/efforts/strength/push-jerk.json +1 -1
  516. package/dist/web/server/seed/core/markdown/efforts/strength/push-press.json +1 -1
  517. package/dist/web/server/seed/core/markdown/efforts/strength/romanian-deadlift.json +1 -1
  518. package/dist/web/server/seed/core/markdown/efforts/strength/single-leg-deadlift.json +1 -1
  519. package/dist/web/server/seed/core/markdown/efforts/strength/skull-crusher.json +1 -1
  520. package/dist/web/server/seed/core/markdown/efforts/strength/slam-ball.json +1 -1
  521. package/dist/web/server/seed/core/markdown/efforts/strength/sled-pull.json +1 -1
  522. package/dist/web/server/seed/core/markdown/efforts/strength/sled-push.json +1 -1
  523. package/dist/web/server/seed/core/markdown/efforts/strength/sumo-deadlift.json +1 -1
  524. package/dist/web/server/seed/core/markdown/efforts/strength/thruster.json +1 -1
  525. package/dist/web/server/seed/core/markdown/efforts/strength/triceps-extension.json +1 -1
  526. package/dist/web/server/seed/core/markdown/efforts/strength/v-sit-hold.json +1 -1
  527. package/dist/web/server/seed/core/markdown/efforts/strength/wall-walk.json +1 -1
  528. package/dist/web/server/seed/core/markdown/efforts/strength/yoga-sun-salutation.json +1 -1
  529. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-assisted-sprint.json +1 -1
  530. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-backstroke.json +1 -1
  531. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-breaststroke-kick.json +1 -1
  532. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-breaststroke.json +1 -1
  533. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-butterfly.json +1 -1
  534. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-catch-up-drill.json +1 -1
  535. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-choice-stroke.json +1 -1
  536. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-dive-start.json +1 -1
  537. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-dolphin-kick.json +1 -1
  538. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-drafting.json +1 -1
  539. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-fingertip-drag.json +1 -1
  540. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-freestyle.json +1 -1
  541. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-individual-medley.json +1 -1
  542. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-kick.json +1 -1
  543. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-pull.json +1 -1
  544. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-resisted-sprint.json +1 -1
  545. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-rotation-drill.json +1 -1
  546. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-sighting.json +1 -1
  547. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-single-arm-drill.json +1 -1
  548. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-stroke-transition.json +1 -1
  549. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-two-kick-one-pull.json +1 -1
  550. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming-vigorous.json +1 -1
  551. package/dist/web/server/seed/core/markdown/efforts/swimming/swimming.json +1 -1
  552. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-arm-cast.json +1 -1
  553. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-circles.json +1 -1
  554. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-mill.json +1 -1
  555. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-reverse-mill.json +1 -1
  556. package/dist/web/server/seed/core/markdown/efforts/unconventional/clubbell-shield-cast.json +1 -1
  557. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-10-to-2-swing.json +1 -1
  558. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-360-swing.json +1 -1
  559. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-barbarian-squat.json +1 -1
  560. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-flow.json +1 -1
  561. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-gravedigger.json +1 -1
  562. package/dist/web/server/seed/core/markdown/efforts/unconventional/macebell-touchdown.json +1 -1
  563. package/dist/web/server/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-carry.json +1 -1
  564. package/dist/web/server/seed/core/markdown/efforts/unconventional/sandbag-bear-hug-extension.json +1 -1
  565. package/dist/web/server/seed/core/markdown/efforts/unconventional/sandbag-over-shoulder.json +1 -1
  566. package/dist/web/server/seed/core/markdown/efforts/walking/walking-3-mph.json +1 -1
  567. package/dist/web/server/seed/core/markdown/equipment/air-bike.json +1 -1
  568. package/dist/web/server/seed/core/markdown/equipment/barbell.json +1 -1
  569. package/dist/web/server/seed/core/markdown/equipment/bench.json +1 -1
  570. package/dist/web/server/seed/core/markdown/equipment/bike-erg.json +1 -1
  571. package/dist/web/server/seed/core/markdown/equipment/climbing-rope.json +1 -1
  572. package/dist/web/server/seed/core/markdown/equipment/clubs.json +1 -1
  573. package/dist/web/server/seed/core/markdown/equipment/dumbbell.json +1 -1
  574. package/dist/web/server/seed/core/markdown/equipment/ghd.json +1 -1
  575. package/dist/web/server/seed/core/markdown/equipment/gymnastic-rings.json +1 -1
  576. package/dist/web/server/seed/core/markdown/equipment/jump-rope.json +1 -1
  577. package/dist/web/server/seed/core/markdown/equipment/kettlebell.json +1 -1
  578. package/dist/web/server/seed/core/markdown/equipment/macebell.json +1 -1
  579. package/dist/web/server/seed/core/markdown/equipment/medicine-ball.json +1 -1
  580. package/dist/web/server/seed/core/markdown/equipment/parallettes.json +1 -1
  581. package/dist/web/server/seed/core/markdown/equipment/plyo-box.json +1 -1
  582. package/dist/web/server/seed/core/markdown/equipment/pull-up-bar.json +1 -1
  583. package/dist/web/server/seed/core/markdown/equipment/rower.json +1 -1
  584. package/dist/web/server/seed/core/markdown/equipment/sandbag.json +1 -1
  585. package/dist/web/server/seed/core/markdown/equipment/ski-erg.json +1 -1
  586. package/dist/web/server/seed/core/markdown/equipment/slam-ball.json +1 -1
  587. package/dist/web/server/seed/core/markdown/equipment/sled.json +1 -1
  588. package/dist/web/server/seed/core/markdown/equipment/sledgehammer.json +1 -1
  589. package/dist/web/server/seed/core/markdown/equipment/weight-vest.json +1 -1
  590. package/dist/web/server/seed/core/report.html +13 -13
  591. package/package.json +6 -6
  592. package/dist/chunk-O5ZCOUQE.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-DKhA8bPd.js","assets/rolldown-runtime-C0FnF6B9.js","assets/vendor-CelWxf33.css","assets/statementBuilderFlow-DHSfYrHi.js"])))=>i.map(i=>d[i]);
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/vendor-DKhA8bPd.js","assets/rolldown-runtime-C0FnF6B9.js","assets/vendor-CelWxf33.css","assets/statementBuilderFlow-krzOPRPk.js"])))=>i.map(i=>d[i]);
2
2
  import{o as e,r as t}from"./rolldown-runtime-C0FnF6B9.js";import{$ as n,$n as r,$r as i,$t as a,A as o,An as s,Ar as c,B as l,Bn as u,Br as d,Bt as f,C as p,Cn as m,Cr as h,Ct as g,D as _,Dn as v,Dr as y,Dt as b,E as x,En as S,Er as C,Et as w,F as T,Fn as E,Fr as D,Ft as O,G as k,Gn as A,Gr as j,Gt as M,H as N,Hn as P,Hr as F,Ht as I,I as L,In as ee,Ir as te,It as ne,J as R,Jn as re,Jr as ie,Jt as ae,K as oe,Kn as se,Kr as ce,Kt as le,L as z,Ln as ue,Lr as de,Lt as fe,M as B,Mn as pe,Mr as me,N as he,Nn as ge,Nr as _e,O as ve,On as ye,Or as be,P as xe,Pn as Se,Pr as Ce,Pt as we,Q as Te,Qn as Ee,Qr as De,Qt as Oe,R as ke,Rn as Ae,Rr as je,Rt as Me,S as Ne,Sn as Pe,Sr as Fe,St as Ie,T as Le,Tn as Re,Tr as ze,U as Be,Un as Ve,Ur as He,Ut as Ue,V as We,Vn as Ge,Vr as Ke,Vt as qe,W as Je,Wn as Ye,Wr as Xe,Wt as Ze,X as Qe,Xn as $e,Xr as et,Xt as tt,Y as nt,Yn as rt,Yr as it,Yt as at,Z as ot,Zn as st,Zr as ct,Zt as lt,_ as ut,_n as dt,_r as ft,_t as pt,a as mt,ai as ht,an as gt,ar as _t,at as vt,b as yt,bn as bt,br as xt,bt as St,c as Ct,ci as wt,cn as Tt,cr as Et,ct as Dt,d as Ot,di as kt,dn as At,dr as jt,dt as Mt,ei as Nt,en as Pt,er as Ft,et as It,f as Lt,fi as Rt,fn as zt,fr as Bt,ft as Vt,g as Ht,gn as Ut,gr as Wt,gt as Gt,h as Kt,hn as qt,hr as Jt,ht as Yt,i as Xt,ii as V,in as Zt,ir as Qt,it as $t,j as en,jn as tn,jr as nn,k as rn,kn as an,kr as on,l as sn,li as cn,ln,lr as un,lt as dn,m as fn,mn as pn,mr as mn,mt as hn,n as gn,ni as _n,nn as vn,nr as yn,nt as bn,o as xn,oi as Sn,on as Cn,or as wn,ot as Tn,p as En,pi as Dn,pn as On,pr as kn,pt as An,q as jn,qn as Mn,qr as Nn,qt as Pn,r as Fn,ri as In,rn as Ln,rr as Rn,rt as zn,s as Bn,si as Vn,sn as Hn,sr as Un,st as Wn,t as Gn,ti as Kn,tn as qn,tr as Jn,tt as Yn,u as Xn,ui as Zn,un as Qn,ur as $n,ut as er,v as tr,vn as nr,vr as rr,vt as ir,w as ar,wn as or,wr as sr,wt as cr,x as lr,xn as ur,xr as dr,xt as fr,y as pr,yn as mr,yr as hr,yt as gr,z as _r,zn as vr,zr as yr,zt as br}from"./vendor-DKhA8bPd.js";import{$ as xr,A as Sr,B as H,C as Cr,D as wr,E as Tr,F as Er,G as Dr,H as Or,I as eee,J as kr,K as Ar,L as jr,M as Mr,N as Nr,O as Pr,P as Fr,Q as Ir,R as Lr,S as Rr,T as zr,U as Br,V as Vr,W as Hr,X as Ur,Y as Wr,Z as Gr,_ as Kr,a as qr,at as Jr,b as Yr,c as Xr,ct as Zr,d as Qr,et as $r,f as ei,g as ti,h as ni,i as ri,it as ii,j as ai,k as oi,l as si,lt as ci,m as li,n as ui,nt as di,o as fi,ot as pi,p as mi,q as hi,r as gi,rt as _i,s as vi,st as yi,t as bi,tt as xi,u as Si,ut as Ci,v as wi,w as Ti,x as Ei,y as Di,z as Oi}from"./vendor-codemirror-CnY0iCTs.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var ki=kt(),U=e(Dn(),1),W=i(),Ai=(0,U.createContext)({theme:`system`,setTheme:()=>null});function ji({children:e,defaultTheme:t=`system`,storageKey:n=`vite-ui-theme`}){let[r,i]=(0,U.useState)(()=>localStorage.getItem(n)||t);(0,U.useEffect)(()=>{let e=window.document.documentElement,t=()=>{if(e.classList.remove(`light`,`dark`),r===`system`){let t=window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`;e.classList.add(t);return}e.classList.add(r)};if(t(),r===`system`){let e=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>t();return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)}},[r]);let a=(0,U.useCallback)(e=>{localStorage.setItem(n,e),i(e)},[n]),o=(0,U.useMemo)(()=>({theme:r,setTheme:a}),[r,a]);return(0,W.jsx)(Ai.Provider,{value:o,children:e})}var Mi=()=>{let e=(0,U.useContext)(Ai);if(e===void 0)throw Error(`useTheme must be used within a ThemeProvider`);return e};function G(...e){return be(De(e))}function Ni(e){let t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t&=t}return Math.abs(t)}var Pi=on(`inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50`,{variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary/90`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive/90`,outline:`border border-input bg-background hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80`,ghost:`hover:bg-accent hover:text-accent-foreground`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-10 px-4 py-2`,sm:`h-9 rounded-md px-3`,lg:`h-11 rounded-md px-8`,icon:`h-11 w-11 min-h-11 min-w-11`}},defaultVariants:{variant:`default`,size:`default`}}),K=U.memo(U.forwardRef(({className:e,variant:t,size:n,asChild:r=!1,...i},a)=>{let o=r?c:`button`;return(0,W.jsx)(ct,{as:o,className:G(Pi({variant:t,size:n,className:e})),ref:a,...i})}));K.displayName=`Button`;var Fi=[`parser`,`dialect`,`user-plan`,`runtime`,`user-entry`],Ii={parser:`parser`,compiler:`dialect`,dialect:`dialect`,hinted:`dialect`,"user-plan":`user-plan`,runtime:`runtime`,tracked:`runtime`,analyzed:`runtime`,"analyzed-estimated":`runtime`,execution:`runtime`,user:`user-entry`,collected:`user-entry`};function Li(e){return Ii[e??`parser`]??`parser`}var q=function(e){return e.Duration=`duration`,e.Spans=`spans`,e.SystemTime=`system-time`,e.Time=`time`,e.Elapsed=`elapsed`,e.Total=`total`,e.Rep=`rep`,e.Effort=`effort`,e.Equipment=`equipment`,e.Distance=`distance`,e.Rounds=`rounds`,e.CurrentRound=`current-round`,e.Action=`action`,e.Increment=`increment`,e.Group=`group`,e.Text=`text`,e.Resistance=`resistance`,e.Sound=`sound`,e.System=`system`,e.Label=`label`,e.Lap=`lap`,e.Metric=`metric`,e.Hint=`hint`,e.Custom=`custom`,e.Volume=`volume`,e.Intensity=`intensity`,e.Grade=`grade`,e.Load=`load`,e.Work=`work`,e.RIR=`rir`,e.SessionRPE=`session-rpe`,e.SessionLoad=`session-load`,e.METScore=`met-score`,e.TIS=`tis`,e.Calculated=`calculated`,e.Choice=`choice`,e}({}),Ri={parser:0,dialect:1,"user-plan":2,runtime:3,"user-entry":4};function zi(e){return e.ownershipLayer??Li(e.origin)}function Bi(e){return Ri[zi(e)]??0}function Vi(e){return e.map((e,t)=>{let n=zi(e);return{metric:e,type:e.type,layer:n,layerRank:Ri[n]??0,index:t,isSuppressor:e.action===`suppress`}})}function Hi(e,t){return t?e.filter(e=>!(t.types&&!t.types.includes(e.type)||t.layers&&!t.layers.includes(e.layer))):[...e]}function Ui(e){let t=new Map;for(let n of e){let e=t.get(n.type);if(e){e.push(n);continue}t.set(n.type,[n])}return t}function Wi(e){let t;for(let n of e)n.isSuppressor||(t==null||n.layerRank>t)&&(t=n.layerRank);return t}function Gi(e,t){return{metric:e.metric,type:e.type,layer:e.layer,outcome:t}}function Ki(e,t){return e.index-t.index}function qi(e){let t=Vi(e);return{raw(e){return Hi(t,e).map(e=>e.metric)},visible(e){let n=Ui(Hi(t,e)),r=[];for(let e of n.values()){if(e.some(e=>e.isSuppressor))continue;let t=Wi(e);if(t!=null)for(let n of e)!n.isSuppressor&&n.layerRank===t&&r.push(n)}return r.sort(Ki),r.map(e=>e.metric)},byLayer(e){let n=Hi(t,e),r={};for(let e of Fi)r[e]=[];for(let e of n)r[e.layer].push(e.metric);for(let e of Fi)r[e]?.length===0&&delete r[e];return r},promotionCandidates(e){let n=Ui(Hi(t,e)),r=[];for(let e of n.values()){let t=e.filter(e=>e.isSuppressor),n=e.filter(e=>!e.isSuppressor);if(n.length===0)continue;if(t.length>0){let e=Math.max(...n.map(e=>e.layerRank)),i=Math.max(...t.map(e=>e.layerRank));for(let t of n)t.layerRank===e&&r.push({metric:t.metric,type:t.type,layer:t.layer,reason:`suppressed`,blockedByLayer:Fi[i]});continue}let i=Wi(n);if(i==null)continue;let a=n.filter(e=>e.layerRank<i);if(a.length===0)continue;let o=Math.max(...a.map(e=>e.layerRank));for(let e of a)e.layerRank===o&&r.push({metric:e.metric,type:e.type,layer:e.layer,reason:`shadowed-by-higher-layer`,blockedByLayer:Fi[i]})}return r.sort((e,t)=>{let n=(Ri[t.layer]??0)-(Ri[e.layer]??0);return n===0?0:n}),r},explain(e){let n=Ui(Hi(t,e)),r=[];for(let[e,t]of n.entries()){let n=t.some(e=>e.isSuppressor),i=n?void 0:Wi(t),a=t.map(e=>e.isSuppressor?Gi(e,`suppressor`):n?Gi(e,`hidden-by-suppressor`):i!=null&&e.layerRank===i?Gi(e,`visible`):Gi(e,`hidden-by-layer`));r.push({type:e,winnerLayer:i==null?void 0:Fi[i],suppressed:n,entries:a})}return r}}}function tee(e,t){let n=[...e];return(t?.types?.includes(q.Hint)??!1)||(n=n.filter(e=>e.type!==q.Hint)),t?(t.origins&&(n=n.filter(e=>t.origins.includes(e.origin??`parser`))),t.types&&(n=n.filter(e=>t.types.includes(e.type))),t.excludeTypes&&(n=n.filter(e=>!t.excludeTypes.includes(e.type))),n):n}var nee=class{resolve(e,t){return qi(tee(e,t)).visible()}resolveOne(e,t){return this.resolve(e,{types:[t]})[0]}resolveAll(e,t){let n=e.filter(e=>e.type===t);return n.length<=1?n:[...n].sort((e,t)=>Bi(t)-Bi(e))}};function Ji(e){let t=e.split(/[\s_\-\u2010-\u2015]+/).filter(Boolean),n=[];for(let e of t){let t=e.replace(/([\p{Ll}\p{Nd}])(\p{Lu})/gu,`$1\0$2`).replace(/(\p{Lu})(\p{Lu}\p{Ll})/gu,`$1\0$2`);for(let e of t.split(`\0`))e&&n.push(e)}return n}function Yi(e){let t=Ji(e);return t.length===0?``:t.map((e,t)=>{let n=e.toLowerCase();return t===0?n:n.charAt(0).toUpperCase()+n.slice(1)}).join(``)}function Xi(e){return e.split(`.`).map(Yi).filter(e=>e.length>0).join(`.`)}function Zi(e){if(e===null)return`null`;if(e===void 0)return`undefined`;if(Array.isArray(e))return`array`;switch(typeof e){case`number`:return`number`;case`string`:return`string`;case`boolean`:return`boolean`;case`object`:return`object`;default:return`undefined`}}function Qi(e){return JSON.stringify([e.path,e.kind,e.dimension??null])}var $i=class extends Error{code;constructor(e,t){super(t),this.name=`UnitConversionError`,this.code=e}},ea=[{canonical:`m`,dimension:`distance`,factor:1,aliases:[`meter`,`meters`,`metre`,`metres`]},{canonical:`km`,dimension:`distance`,factor:1e3,aliases:[`kilometer`,`kilometers`,`kilometre`,`kilometres`]},{canonical:`cm`,dimension:`distance`,factor:.01,aliases:[`centimeter`,`centimeters`]},{canonical:`mm`,dimension:`distance`,factor:.001,aliases:[`millimeter`,`millimeters`]},{canonical:`ft`,dimension:`distance`,factor:.3048,aliases:[`foot`,`feet`]},{canonical:`in`,dimension:`distance`,factor:.0254,aliases:[`inch`,`inches`]},{canonical:`yd`,dimension:`distance`,factor:.9144,aliases:[`yard`,`yards`]},{canonical:`mi`,dimension:`distance`,factor:1609.344,aliases:[`mile`,`miles`]},{canonical:`kg`,dimension:`mass`,factor:1,aliases:[`kilogram`,`kilograms`,`kilo`,`kilos`]},{canonical:`g`,dimension:`mass`,factor:.001,aliases:[`gram`,`grams`]},{canonical:`lb`,dimension:`mass`,factor:.45359237,aliases:[`lbs`,`pound`,`pounds`]},{canonical:`ms`,dimension:`duration`,factor:.001,aliases:[`millisecond`,`milliseconds`]},{canonical:`s`,dimension:`duration`,factor:1,aliases:[`sec`,`secs`,`second`,`seconds`]},{canonical:`min`,dimension:`duration`,factor:60,aliases:[`mins`,`minute`,`minutes`]},{canonical:`h`,dimension:`duration`,factor:3600,aliases:[`hr`,`hrs`,`hour`,`hours`]},{canonical:`count`,dimension:`count`,factor:1},{canonical:`rep`,dimension:`count`,factor:1,aliases:[`reps`]},{canonical:`pull-up`,dimension:`count`,factor:1},{canonical:`thruster`,dimension:`count`,factor:1},{canonical:`problem`,dimension:`count`,factor:1},{canonical:`count/s`,dimension:`count-rate`,factor:1},{canonical:`bpm`,dimension:`count-rate`,factor:1/60},{canonical:`cal`,dimension:`energy`,factor:1,aliases:[`calorie`,`calories`]},{canonical:`kcal`,dimension:`energy`,factor:1e3,aliases:[`kilocalorie`,`kilocalories`]},{canonical:`m/s`,dimension:`speed`,factor:1},{canonical:`km/h`,dimension:`speed`,factor:1e3/3600,aliases:[`kmh`,`kph`]},{canonical:`mph`,dimension:`speed`,factor:1609.344/3600},{canonical:`min/km`,dimension:`pace`,factor:1},{canonical:`min/mi`,dimension:`pace`,factor:1e3/1609.344},{canonical:`s/m`,dimension:`pace`,factor:1/60},{canonical:`ratio`,dimension:`ratio`,factor:1,aliases:[`x`]},{canonical:`%`,dimension:`ratio`,factor:.01,aliases:[`pct`,`percent`]},{canonical:`au`,dimension:`ratio`,factor:1,aliases:[`AU`]},{canonical:`pts`,dimension:`ratio`,factor:1,aliases:[`point`,`points`]},{canonical:`rating`,dimension:`ratio`,factor:1,aliases:[`ratings`]}],ta=(()=>{let e=new Map;for(let t of ea){e.set(t.canonical.toLowerCase(),t);for(let n of t.aliases??[])e.has(n.toLowerCase())||e.set(n.toLowerCase(),t)}return e})();function na(e){if(typeof e==`string`)return ta.get(e.trim().toLowerCase())}function ra(e){return na(e)?.dimension}var ia=Object.freeze({mass:`kg`,distance:`m`,duration:`s`,count:`count`,"count-rate":`count/s`,energy:`cal`,speed:`m/s`,pace:`min/km`,ratio:void 0});function aa(e){return ia[e]}function oa(e,t,n){let r=na(t);if(!r)throw new $i(`unknown-unit`,`Unknown unit "${t}"`);let i=na(n);if(!i)throw new $i(`unknown-unit`,`Unknown unit "${n}"`);if(r.dimension!==i.dimension)throw new $i(`dimension-mismatch`,`Cannot convert ${t} (${r.dimension}) to ${n} (${i.dimension})`);if(r.dimension===`ratio`&&r.canonical!==i.canonical&&r.canonical!==`ratio`&&i.canonical!==`ratio`)throw new $i(`scale-mismatch`,`Named scales ${t} and ${n} are not interchangeable`);if(!Number.isFinite(e))throw new $i(`non-finite`,`Non-finite value cannot be converted`);return e*r.factor/i.factor}var sa=`references`,ca=[`explicit`,`split`,`whole`,`default`,`none`];function la(e){if(!e||typeof e!=`object`)return!1;let t=e;return(t.kind===`effort`||t.kind===`equipment`)&&typeof t.slug==`string`&&!!t.slug&&typeof t.label==`string`}function ua(e){return!e||typeof e!=`object`?!1:typeof e.reason==`string`}function da(e){let t=e?.[sa];if(!t||typeof t!=`object`)return;let n=t;if(!(typeof n.matched!=`string`||!ca.includes(n.matched))&&typeof n.source==`string`&&!(n.refs!==void 0&&(!Array.isArray(n.refs)||!n.refs.every(la)))&&!(n.diagnostics!==void 0&&(!Array.isArray(n.diagnostics)||!n.diagnostics.every(ua))))return t}var fa=class{line;startOffset;endOffset;length;columnStart;columnEnd;raw;constructor(e,t,n,r,i=0,a=0,o=``){this.line=e,this.startOffset=t,this.endOffset=n,this.length=r,this.columnStart=i,this.columnEnd=a,this.raw=o}},J=class e{_metrics;_indexedLength=0;_resolver=new nee;id;constructor(t,n=`metrics`){if(this.id=n,t instanceof e){this._metrics=t.toArray(),this.syncIndexProperties();return}this._metrics=Array.isArray(t)?[...t]:[],this.syncIndexProperties()}static from(t,n=`metrics`){if(t instanceof e)return t.clone(n);if(Array.isArray(t))return new e(t,n);if(typeof t==`object`&&t&&`_metrics`in t){let r=t._metrics;if(Array.isArray(r))return new e(r,n)}return e.empty(n)}static empty(t=`metrics`){return new e(void 0,t)}clone(t=this.id){return new e(this._metrics,t)}get all(){return[...this._metrics]}get length(){return this._metrics.length}get size(){return this._metrics.length}get isEmpty(){return this._metrics.length===0}getByType(e){let t=this._metrics.filter(t=>t.type===e||t.name===e);return t.length<=1?t:[...t].sort((e,t)=>Bi(t)-Bi(e))}getFirst(e){let t=this.getByType(e);return t.length>0?t[0]:void 0}get(e){return this.getFirst(e)}has(e){return this._metrics.some(t=>t.type===e||t.name===e)}hasMetric(e){return this.has(e)}getDisplayMetrics(e){return this.resolve(e)}getMetric(e){return this._resolver.resolveOne(this._metrics,e)}getAllMetricsByType(e){return this.getByType(e)}get rawMetrics(){return this.toArray()}getAll(){return this.toArray()}getByOrigin(e){return this._metrics.filter(t=>(t.origin??`parser`)===e)}resolve(e){return this._resolver.resolve(this._metrics,e)}add(...e){return this._metrics.push(...e),this.syncIndexProperties(),this}remove(e){let t=[];return this._metrics=this._metrics.filter(n=>!e(n)||(t.push(n),!1)),this.syncIndexProperties(),t}removeByType(e){return this.remove(t=>t.type===e||t.name===e)}clear(){return this._metrics=[],this.syncIndexProperties(),this}replaceByType(e,...t){let n=this.removeByType(e);return this._metrics.push(...t),this.syncIndexProperties(),n}merge(t){let n=t instanceof e?t._metrics:Array.isArray(t)?t:t.metrics.toArray(),r=new Map;for(let e of n){let t=r.get(e.type)??[];t.push(e),r.set(e.type,t)}for(let[e,t]of r){let n=this._metrics.filter(t=>t.type===e);if(n.length===0){this._metrics.push(...t);continue}let r=Math.max(...n.map(e=>Bi(e))),i=Math.max(...t.map(e=>Bi(e)));i>r?(this._metrics=this._metrics.filter(t=>t.type!==e),this._metrics.push(...t)):i===r&&this._metrics.push(...t)}return this.syncIndexProperties(),this}[Symbol.iterator](){return this._metrics[Symbol.iterator]()}filter(e){return this._metrics.filter(e)}map(e){return this._metrics.map(e)}flatMap(e){return this._metrics.flatMap(e)}find(e){return this._metrics.find(e)}some(e){return this._metrics.some(e)}every(e){return this._metrics.every(e)}toArray(){return[...this._metrics]}get raw(){return this._metrics}syncIndexProperties(){for(let e=0;e<this._indexedLength;e++)delete this[e];for(let e=0;e<this._metrics.length;e++)this[e]=this._metrics[e];this._indexedLength=this._metrics.length}toString(){return`MetricContainer(${this._metrics.length})[${this._metrics.map(e=>e.type).join(`, `)}]`}},pa=class{exerciseId;line;text;raw;dialect;hasMetric(e){return this.metricContainer.hasMetric(e)}getDisplayMetrics(e){return this.metricContainer.getDisplayMetrics(e)}getMetric(e){return this.metricContainer.getMetric(e)}getAllMetricsByType(e){return this.metricContainer.getAllMetricsByType(e)}get rawMetrics(){return this.metricContainer.rawMetrics}get metricContainer(){return this.metrics instanceof J?this.metrics:J.from(this.metrics,this.id)}},ma=class extends pa{id=0;parent;children=[];meta=new fa(0,0,0,0);_metrics=J.empty();metricMeta=new Map;isLeaf;get metrics(){return this._metrics}set metrics(e){this._metrics=J.from(e,this.id)}constructor(e){super(),e&&(Object.assign(this,e),e.metrics&&(this.metrics=J.from(e.metrics,this.id)),this.metricMeta||=new Map)}},ha=class e extends pa{static nextId=1e6;id;outputType;timeSpan;sourceStatementId;sourceBlockKey;stackLevel;metrics;metricMeta;completionReason;parent;children;isLeaf;meta;statement;timestamp;constructor(t,n,r){if(super(),t&&`outputType`in t&&`timeSpan`in t){let n=t;this.id=e.nextId++,this.outputType=n.outputType,this.timeSpan=n.timeSpan,this.sourceBlockKey=n.sourceBlockKey??``,this.sourceStatementId=n.sourceStatementId,this.line=n.line,this.text=n.text,this.dialect=n.dialect,this.stackLevel=n.stackLevel??0,this.metrics=J.from(n.metrics,this.id),this.metricMeta=n.metricMeta??new Map,this.completionReason=n.completionReason,this.parent=n.parent,this.children=n.children??[],this.isLeaf=this.children.length===0,this.meta=new fa(0,0,0,0)}else{let i=t;this.id=e.nextId++,this.statement=i,this.outputType=`segment`,this.timeSpan={started:r??Date.now()},this.sourceBlockKey=``,this.sourceStatementId=typeof i?.id==`number`?i.id:void 0,this.stackLevel=0,this.metrics=J.from(n,this.id),this.metricMeta=new Map,this.children=[],this.isLeaf=!0,this.meta=i?.meta??new fa(0,0,0,0),this.line=i?.line,this.text=i?.text,this.dialect=i?.dialect,this.timestamp=r??Date.now()}}static resetIdCounter(t=1e6){e.nextId=t}},ga=class{value;constructor(e){this.value=e??(typeof crypto<`u`&&typeof crypto.randomUUID==`function`?crypto.randomUUID():Math.random().toString(36).slice(2))}toString(){return this.value}valueOf(){return this.value}equals(e){return this.value===e?.value}};function _a(e){let t=new Map;for(let n of e)t.set(n.slug,n);return{resolve:e=>t.get(e),list:()=>[...t.values()]}}var va=`tagReference`;function ya(e){let t=e?.[va];if(!t||typeof t!=`object`)return;let n=t;if(!(typeof n.slug!=`string`||!n.slug)&&typeof n.label==`string`&&!(n.functions!==void 0&&!Array.isArray(n.functions))&&(n.soundProfileId===void 0||typeof n.soundProfileId==`string`))return t}function ba(e){let t=e.trim(),n=2166136261;for(let e=0;e<t.length;e++)n^=t.charCodeAt(e),n=Math.imul(n,16777619);return`bc-${(n>>>0).toString(16).padStart(8,`0`)}`}function xa(e,t){let n=e.position??1/0,r=t.position??1/0;return n===r?e.createdAt===t.createdAt?e.id<t.id?-1:+(e.id>t.id):e.createdAt-t.createdAt:n-r}function Sa(e){return[...e].sort(xa)}function Ca(e,t){let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of Sa(e)){let e=n.get(t.pageId);e&&r.push({pageId:e.id,noteId:t.noteId,position:t.position,createdAt:t.createdAt,date:e.date,slug:e.slug,title:e.title})}return r}function wa(e){let t={};for(let n of e)t.pageId===void 0&&(t.pageId=n.pageId),t.journalDate===void 0&&n.date&&(t.journalDate=n.date),t.pageSlug===void 0&&n.slug&&!n.date&&(t.pageSlug=n.slug);return t}var Ta=[`segment`,`system`,`load`,`event`,`compiler`,`completion`,`analytics`,`wellness`];function Ea(e){return e===`time`?`run`:e===`log`?`log`:null}function Da(e){let t=e.trim();return t.startsWith(`notebook/`)||t.startsWith(`notebook:`)?t.slice(9):t}function Oa(e){return`notebook/${Da(e)}`}function ka(e,t){return t?t!==`feed`:e.seedOrigin!==`seed`&&e.feedOrigin!==`feed`}var Aa=[{slug:`journal`,notebookId:`notebook/journal`,name:`Journal`,description:`Dated training log and scheduled workouts.`,icon:`📅`,href:`/journal`},{slug:`playground`,notebookId:`notebook/playground`,name:`Playground`,description:`Scratchpad workouts and timer experiments.`,icon:`🧪`,href:`/playgrounds`},{slug:`defaults`,notebookId:`notebook/defaults`,name:`Defaults`,description:`Starter notes — clone any of them into your own notebooks.`,icon:`📝`,href:`/notebook/defaults`},{slug:`guides`,notebookId:`notebook/guides`,name:`Guides`,description:`Built-in Whiteboard Language and WQL guides.`,icon:`📖`,href:`/notebook/guides`,feedEntryId:`core`,seedChunkId:`canvas`},{slug:`efforts`,notebookId:`notebook/efforts`,name:`Efforts`,description:`The effort library — every effort the parser and analytics resolve, across the canonical disciplines.`,icon:`🏋️`,href:`/efforts`,feedEntryId:`core`,seedChunkId:`efforts`},{slug:`equipment`,notebookId:`notebook/equipment`,name:`Equipment`,description:`The equipment library — gear definitions the language resolves.`,icon:`🔧`,href:`/equipment`,feedEntryId:`core`,seedChunkId:`equipment`},{slug:`dashboards`,notebookId:`notebook/dashboards`,name:`Dashboards`,description:`Prebuilt WQL dashboards — query compositions ready to open.`,icon:`📊`,href:`/dashboards`,feedEntryId:`core`,seedChunkId:`dashboards`}],ja=[`playground-run-tip`,`attention`,`code-example`,`syntax-group`];function Ma(e){let t=e.match(/^`{3,}(time|log)(?::([\w-]+))?\s*$/i);return t?{dialect:t[1].toLowerCase()===`time`?`time`:`log`,...t[2]?{sport:t[2]}:{}}:null}function Na(e){let t=e.type?.toLowerCase();if(t===`youtube`||t===`strava`||t===`amazon`||t===`file`||t===`effort`||t===`equipment`)return t;let n=(e.url||e.link||``).replace(/^[a-z][a-z0-9+.-]*:\/\//i,``).split(/[/?#:]/,1)[0].toLowerCase();return n===`youtu.be`||n===`youtube.com`||n.endsWith(`.youtube.com`)?`youtube`:n===`strava.com`||n.endsWith(`.strava.com`)?`strava`:n===`amzn.to`||n===`amazon.com`||n.endsWith(`.amazon.com`)?`amazon`:[`baseAttributes`,`discipline`,`effortType`,`targetRPE`,`equipment`,`aliases`,`derivation`].some(t=>t in e)?`effort`:[`slug`,`label`,`registrySource`,`ownerNoteId`,`sourcePath`].some(t=>t in e)?`equipment`:`default`}function Pa(e){return/^#{1,6}\s/.test(e)?`heading`:/^[-*+]\s|^\d+\.\s/.test(e)?`list`:/^>\s?/.test(e)?`blockquote`:e.startsWith(`|`)&&/^\|[\s:]*-+/m.test(e)?`table`:`paragraph`}function Fa(e,t={}){if(!e)return[];let n=e.split(/\r\n|\n|\r/),r=[],i=[],a=0;for(let t of n){r.push(a),a+=t.length;let n=e.startsWith(`\r
3
3
  `,a)?`\r
4
4
  `:/[\r\n]/.test(e[a]??``)?e[a]:``;i.push(n),a+=n.length}let o=[],s=Date.now(),c=!0,l=0;function u(t,a,o){let c=r[a],l=r[o]+n[o].length;return{id:crypto.randomUUID(),type:t,from:c,to:l,rawContent:e.slice(c,l),displayContent:e.slice(c,l),startLine:a,endLine:o,lineCount:o-a+1,version:1,createdAt:s,separatorAfter:i[o]}}for(;l<n.length;){let a=n[l].trim(),d=a.match(/^(`{3,}|~{3,})(.*)$/);if(d){let a=d[1],c=l+1,f=RegExp(`^${a[0]}{${a.length},}\\s*$`);for(;c<n.length&&!f.test(n[c].trim());)c++;let p=c<n.length,m=p?c:n.length-1,h=d[2].trim(),g=a[0]==="`"?Ma(`\`\`\`${h}`):null,_=a[0]==="`"?h.match(/^widget:([\w-]+)$/):null,v=a[0]==="`"?h.match(/^query(?:[:\s](.*))?$/i):null,y=t.registeredWidgets??ja,b=_&&(`has`in y?y.has(_[1]):y.includes(_[1])),x=p&&g?g.dialect:p&&b?`widget`:p&&v?`query`:`code`,S=u(x,l,m);S.contentFrom=r[l]+n[l].length+i[l].length,S.contentTo=p?r[c]:S.to,S.displayContent=e.slice(S.contentFrom,S.contentTo),g&&p&&(S.sport=g.sport,S.contentId=ba(S.displayContent),S.scriptBlock={id:S.id,contentId:S.contentId,dialect:g.dialect,sport:g.sport,startLine:l,endLine:m,content:S.displayContent,state:`idle`,version:1,createdAt:s}),x===`widget`&&_&&(S.widgetName=_[1]),x===`query`&&v&&(S.querySuffix=(v[1]??``).trim()),o.push(S),l=m+1;continue}if(a===`---`&&n[l+1]?.trim()){let t=l+1;for(;t<n.length&&n[t].trim()!==`---`&&!/^(`{3,}|~{3,})/.test(n[t].trim());)t++;let i=n.slice(l+1,t);if(n[t]?.trim()===`---`&&i.some(e=>/^[A-Za-z_][\w-]*\s*:/.test(e.trim()))){let n=u(`frontmatter`,l,t);n.contentFrom=r[l+1],n.contentTo=r[t],n.displayContent=e.slice(n.contentFrom,n.contentTo),n.properties={};for(let e of i){let t=e.match(/^([^:]+):\s*(.*)$/);t&&(n.properties[t[1].trim()]=t[2].trim())}n.frontmatterType=Na(n.properties),o.push(n),l=t+1;continue}}let f=a.match(/^(!)?\[([^\]]*)\]\((https?:\/\/[^)\s]+|\/[^)\s]+)\)$/);if(f){let e=u(`embed`,l,l),t=!!f[1];e.embed={type:t?`image`:/(?:youtube\.com|youtu\.be)/i.test(f[3])?`youtube`:`link`,label:f[2],url:f[3],isImage:t},o.push(e),l++;continue}let p=l;if(a)for(;p+1<n.length&&n[p+1].trim()&&!/^(?:`{3,}|~{3,}|---\s*$|!?\[[^\]]*\]\()/.test(n[p+1].trim());)p++;let m=u(a&&c?`title`:`markdown`,l,p);m.subtype=Pa(m.displayContent.trim()),a&&(c=!1),o.push(m),l=p+1}return o}function Ia(e){return e.type===`time`||e.type===`log`?`wod`:e.type===`query`||e.type===`widget`||e.type===`embed`?e.type:null}function La(e,t){if(!Number.isSafeInteger(t.sourceRevision)||t.sourceRevision<1)throw Error(`Invalid source revision`);let n=Object.create(null),r=Object.values(t.blocks??{}).filter(e=>e&&typeof e==`object`),i=t.createId??(()=>crypto.randomUUID());for(let a of Fa(e,t)){let e=Ia(a);if(!e)continue;let o=r.filter(t=>t.from===a.from&&t.to===a.to&&t.kind===e),s=o.length===1?o[0]:void 0,c=s?.id??i();if(!c||Object.hasOwn(n,c))throw Error(`Duplicate block occurrence ID`);n[c]={id:c,kind:e,from:a.from,to:a.to,sourceRevision:t.sourceRevision,version:s?.version??1,...e===`wod`&&(a.type===`time`||a.type===`log`)?{dialect:a.type,...a.sport?{sport:a.sport}:{}}:{}}}return n}function Ra(e,t,n,r={}){if(typeof e!=`string`||!t||typeof t!=`object`||Array.isArray(t))throw Error(`Invalid Note source or blocks`);for(let[e,r]of Object.entries(t))if(!r||r.id!==e||!e||!Number.isSafeInteger(r.version)||r.version<1||r.sourceRevision!==n||!Number.isSafeInteger(r.from)||!Number.isSafeInteger(r.to))throw Error(`Invalid block identity, version or source revision`);let i=La(e,{...r,sourceRevision:n,blocks:t});if(Object.keys(i).length!==Object.keys(t).length)throw Error(`Incomplete actionable block map`);for(let[e,n]of Object.entries(t)){let t=i[e];if(!t||t.from!==n.from||t.to!==n.to||t.kind!==n.kind||t.dialect!==n.dialect||t.sport!==n.sport)throw Error(`Block does not match authored source`)}}function za(e,t){let n=0;for(let e of t){if(!Number.isSafeInteger(e.from)||!Number.isSafeInteger(e.to)||e.from<n||e.to<e.from||typeof e.insert!=`string`)throw Error(`Invalid source changes`);n=e.to}let r={};for(let n of Object.values(e)){let e=n.from,i=n.to,a=!1;for(let r of t){let t=r.insert.length-(r.to-r.from);if(r.from<=n.from&&r.to>=n.to||r.from<n.from&&r.to>n.from||r.from<n.to&&r.to>n.to){a=!0;break}r.to<=n.from?(e+=t,i+=t):r.from<n.to&&(i+=t)}a||(r[n.id]={...n,from:e,to:i})}return r}var Ba=/^[A-Za-z][\w.-]*$/,Va=/^---\r?\n([\s\S]*?)\r?\n---/;function Ha(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function Ua(e){let t=e.trim();return t===``||t.startsWith(`#`)}function Wa(e){return Array.isArray(e)}function Ga(e){if(e===``)return`""`;let t=!isNaN(Number(e)),n=/^(true|false|null|yes|no|on|off)$/i.test(e);return/[:"'\n#{}[\],&*?|<>=%!@`]/.test(e)||e!==e.trim()||e.startsWith(`-`)||t||n?`"${e.replace(/\\/g,`\\\\`).replace(/"/g,`\\"`).replace(/\n/g,`\\n`).replace(/\r/g,`\\r`).replace(/\t/g,`\\t`)}"`:e}function Ka(e,t,n){let r=` `.repeat(e);return Wa(n)?n.length===0?[`${r}${t}: []`]:[`${r}${t}:`,...n.map(e=>`${r} - ${typeof e==`number`?String(e):Ga(e)}`)]:[`${r}${t}: ${typeof n==`number`?String(n):Ga(n)}`]}function qa(e,t,n,r){let i=[],a=r;for(let r=t;r<e.length;r++)r===e.length-1?i.push(...Ka(a,e[r],n)):i.push(`${` `.repeat(a)}${e[r]}:`),a+=2;return i}function Ja(e){let t=!1,n=!1;for(let r=0;r<e.length;r++){let i=e[r];if(n){i===`\\`?r++:i===`"`&&(n=!1);continue}if(t){i===`'`&&(t=!1);continue}if(i===`"`)n=!0;else if(i===`'`)t=!0;else if(i===`#`&&(r===0||/\s/.test(e[r-1])))return r}return-1}function Ya(e,t,n){let r=[t],i=[];for(let a=t+1;a<e.length;a++){let t=e[a];if(Ua(t)){i.push(a);continue}if(t.length-t.trimStart().length>n)r.push(...i,a),i=[];else break}return r}function Xa(e,t,n,r,i){let a=RegExp(`^ {${n}}${Ha(t)}\\s*:`);for(let t=r;t<i;t++)if(a.test(e[t]))return t;return-1}function Za(e,t,n){if(t.length===0||!t.every(e=>typeof e==`string`&&Ba.test(e)))return e;let r=e.includes(`\r
@@ -97,7 +97,7 @@ sum:$metric{} by {week}
97
97
  `)?e:e+`
98
98
  `;return{statements:tc(ii.create({doc:n,extensions:[Vc]}),t),errors:[],success:!0}}catch(e){return{statements:[],errors:[{message:e instanceof Error?e.message:`Unknown parse error`,severity:`error`}],success:!1}}}function SR(e,...t){console.warn(`[${e}]`,...t)}function CR(e,...t){console.error(`[${e}]`,...t)}function wR(e,t={}){let n=t.sourceRevision??1,r=La(e,{...t,blocks:t.noteBlocks,sourceRevision:n}),i=Fa(e,t),a=[];for(let e of i){if(!Ia(e))continue;let t=Object.values(r).find(t=>t.from===e.from&&t.to===e.to);t&&(e.id=t.id,e.version=t.version,e.scriptBlock&&(e.scriptBlock=TR({...e.scriptBlock,id:t.id,version:t.version}),a.push(e.scriptBlock)))}return{sections:i,blocks:a,noteBlocks:r,rawContent:e,sourceRevision:n}}function TR(e){try{let t=xR(e.content,e.sport);return{...e,statements:t.statements,errors:t.errors,state:t.success?`parsed`:`error`}}catch(t){return CR(`WorkbenchDocumentModel`,`Block parse error:`,t),e}}function ER(e){if(e.kind!==`wod`||!e.dialect)throw Error(`The saved revision is not a workout.`);let t=Fa(e.rawContent).find(t=>t.type===e.dialect);if(!t?.scriptBlock)throw Error(`The saved workout fence cannot be read.`);let n=t.scriptBlock.content;return{id:e.blockId,content:n,dialect:e.dialect,sport:e.sport,statements:Cc().read(n,e.sport).statements,startLine:0,endLine:e.rawContent.split(`
99
99
  `).length-1,version:e.version,state:`idle`,widgetIds:{},createdAt:e.savedAt}}async function DR(e,t,n,r,i=lP){let a=Date.now(),o=await i.startSession(e,{id:n,noteId:e.noteId,blockId:t.id,blockContentId:t.contentId,origin:r??`journal`,startTime:a,endTime:a,duration:0,completed:!1,status:`in-progress`,createdAt:a});return{...o,block:ER(o.revision)}}async function OR(e,t,n,r){let i=await Z.getNote(e);if(!i)throw Error(`The note is unavailable. Save the note before starting a workout.`);return DR({noteId:i.id,rawContent:i.rawContent,blocks:i.blocks,expectedSourceRevision:i.sourceRevision},t,n,r)}var kR={content:``,sections:null,noteBlocks:{},sourceRevision:0,capturedRun:null,saveError:null,blocks:[],activeBlockId:null,saveState:`idle`,lastSavedContent:``,loadedRouteId:null,results:[],currentEntry:null,historyEntries:[],panelLayouts:{},attachments:[],runtime:null,execution:{status:`idle`,elapsedTime:0,stepCount:0,startTime:null,start:()=>{},pause:()=>{},stop:()=>{},reset:()=>{},step:()=>{}},handles:{handleStart:()=>{},handlePause:()=>{},handleStop:()=>{},handleNext:()=>{},handleStartWorkoutAction:()=>{}},activeSegmentIds:new Set,activeStatementIds:new Set,analyticsSegments:[],analyticsGroups:[],selectedAnalyticsIds:new Set,lastSelectedAnalyticsId:null,outputStatementList:[],logOutputList:[],userOutputOverrides:new Map,gridViewPreset:`default`,hoveredBlockKey:null,documentItems:[],selectedBlock:null,selectedBlockId:null,cursorLine:1,highlightedLine:null,subscriptionManager:null,viewMode:`plan`},AR=5e3;function jR(e={}){let t=e.listeners??[],n=e.nowProvider??wl,r=e.notePersistence,i=e.setTimeout??((e,t)=>window.setTimeout(e,t)),a=e.clearTimeout??(e=>{typeof e==`number`&&window.clearTimeout(e)}),o=null,s=[],c=fn()((t,n)=>{let c=Promise.resolve(),l=async i=>{let a=n(),o=a.currentEntry?.id??a.loadedRouteId;if(!(!o||!r||!e.provider?.capabilities.canWrite)&&(i.rawContent!==a.lastSavedContent||JSON.stringify(Object.values(i.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(a.currentEntry?.blocks??{}).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])))){t({saveState:`saving`,saveError:null});try{let e=await r.saveNote({noteId:o,rawContent:i.rawContent,blocks:i.blocks,expectedSourceRevision:a.sourceRevision,metadata:{title:i.rawContent.match(/^#\s+(.+)$/m)?.[1]?.trim()??`Untitled Session`},noteType:`playground`}),s=n();t({currentEntry:e,...s.content===i.rawContent&&JSON.stringify(Object.values(s.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))===JSON.stringify(Object.values(i.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))?{noteBlocks:e.blocks}:{},sourceRevision:e.sourceRevision??a.sourceRevision,lastSavedContent:i.rawContent,saveState:`saved`})}catch(e){throw t({saveState:`error`,saveError:e instanceof Error?e.message:String(e)}),e}}},u=()=>{o=null;let e=n(),t={rawContent:e.content,blocks:e.noteBlocks,sourceRevision:e.sourceRevision},r=c.catch(()=>{}).then(()=>l(t));return c=r,r};return{...kR,setContent:r=>{let s=wR(r,{noteBlocks:n().noteBlocks,sourceRevision:Math.max(1,n().sourceRevision)}),c=n(),l={content:r,sections:s.sections,blocks:s.blocks,noteBlocks:s.noteBlocks};r!==c.lastSavedContent&&(c.saveState===`idle`&&(l.saveState=`changed`),o!==null&&a(o),e.provider&&e.provider.capabilities.canWrite&&(o=i(()=>{u().catch(()=>{})},AR))),t(l)},setBlocks:e=>t({blocks:e}),setEditorIdentity:r=>{let s=JSON.stringify(Object.values(n().noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(r.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));t({content:r.rawContent,noteBlocks:r.blocks}),s&&e.provider?.capabilities.canWrite&&(o!==null&&a(o),o=i(()=>{u().catch(()=>{})},AR))},acceptSaved:e=>t(t=>({...t.content===e.rawContent&&JSON.stringify(Object.values(t.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))===JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))?{noteBlocks:e.blocks}:{},sourceRevision:e.sourceRevision,lastSavedContent:e.rawContent})),restoreBlock:async e=>{if(!r)throw Error(`Note persistence is unavailable.`);await u();let i=n(),a=rR({rawContent:i.content,blocks:i.noteBlocks,sourceRevision:i.sourceRevision},e),o=await r.saveNote({noteId:e.noteId,rawContent:a.rawContent,blocks:a.blocks,expectedSourceRevision:i.sourceRevision}),s=wR(o.rawContent,{noteBlocks:o.blocks,sourceRevision:o.sourceRevision});t({content:o.rawContent,noteBlocks:o.blocks,sourceRevision:o.sourceRevision,lastSavedContent:o.rawContent,currentEntry:o,sections:s.sections,blocks:s.blocks})},startPinnedRun:async e=>{await c.catch(()=>{});let i=n(),a=i.currentEntry?.id??i.loadedRouteId;if(!a||!r)throw Error(`Save the note before starting a workout.`);try{let n=await DR({noteId:a,rawContent:i.content,blocks:i.noteBlocks,expectedSourceRevision:i.sourceRevision},e,w(),void 0,r);return t({capturedRun:n,noteBlocks:n.note.blocks,sourceRevision:n.note.sourceRevision,currentEntry:{...i.currentEntry,...n.note,updatedAt:Date.now(),targetDate:i.currentEntry?.targetDate??Date.now(),schemaVersion:1},lastSavedContent:n.note.rawContent,saveError:null}),n.block}catch(e){throw t({saveState:`error`,saveError:e instanceof Error?e.message:String(e)}),e}},setActiveBlockId:e=>t({activeBlockId:e}),setSaveState:e=>t({saveState:e}),flushSave:async()=>{o!==null&&a(o),o=null,await u()},markSaved:e=>t({lastSavedContent:e,saveState:`saved`}),setResults:e=>t({results:e}),resetResults:()=>t({results:[]}),setCurrentEntry:e=>{if(e&&e.id!==n().currentEntry?.id){let n=wR(e.rawContent,{noteBlocks:e.blocks,sourceRevision:Math.max(1,e.sourceRevision??0)});t({currentEntry:e,content:e.rawContent,noteBlocks:n.noteBlocks,sections:n.sections,blocks:n.blocks,sourceRevision:e.sourceRevision??0,lastSavedContent:e.rawContent})}else t({currentEntry:e})},setHistoryEntries:e=>t({historyEntries:e}),setPanelLayouts:e=>t({panelLayouts:e}),expandPanel:(e,n)=>t(t=>{let r=t.panelLayouts[e]??{viewId:e,panelSpans:{},expandedPanelId:null},i=r.expandedPanelId?r.panelSpans:{...r.panelSpans};return{panelLayouts:{...t.panelLayouts,[e]:{...r,panelSpans:{...i,[n]:3},expandedPanelId:n}}}}),collapsePanel:e=>t(t=>{let n=t.panelLayouts[e];return n?{panelLayouts:{...t.panelLayouts,[e]:{...n,expandedPanelId:null}}}:t}),setAttachments:e=>t({attachments:e}),addAttachment:async r=>{let i=e.notePersistence,a=e.provider,o=n().currentEntry?.id;if(!o||!a?.capabilities.canWrite||!i)return;console.log(`[WorkbenchSession] Processing attachment: ${r.name}`);let s=await vee.process(r),{v7:c}=await Zn(async()=>{let{v7:e}=await import(`./vendor-DKhA8bPd.js`).then(e=>e.Tt);return{v7:e}},__vite__mapDeps([0,1,2]));console.log(`[WorkbenchSession] Saving attachment to entry ${o}`),await i.mutateNote(o,{attachments:{add:[{id:c(),label:s.label,mimeType:s.mimeType,data:s.data,timeSpan:s.timeSpan??{start:Date.now(),end:Date.now()}}]}}),t({attachments:(await i.getNote(o,{projection:`workbench`,includeAttachments:!0})).attachments??[]}),console.log(`[WorkbenchSession] Attachment saved successfully`)},deleteAttachment:async r=>{let i=e.notePersistence,a=n().currentEntry?.id;!a||!i||(await i.mutateNote(a,{attachments:{remove:[r]}}),t({attachments:(await i.getNote(a,{projection:`workbench`,includeAttachments:!0})).attachments??[]}))},patchCurrentEntryResults:e=>t(t=>t.currentEntry?{currentEntry:{...t.currentEntry,results:e}}:t),completeWorkout:async(e,i)=>{let a=n().capturedRun,o=i??a?.session.id;if(!o||!r?.finishSession)throw Error(`The saved run pin is unavailable.`);let s=await r.finishSession(o,e,e.endTime);return t(t=>({results:[...t.results,e]})),s.id},loadEntry:async r=>{let i=e.notePersistence,a=e.provider;if(!i||!a)return null;let{routeId:o,routeView:s,routeSectionId:c,routeResultId:l,resultFromLocationState:u,initialActiveEntryId:d,propInitialContent:f}=r;if(n().setContent(``),n().setBlocks([]),t({currentEntry:null,loadedRouteId:o??null}),o){if(a.mode===`history`||a.mode===`static`)try{let e=l?{mode:`by-result-id`,resultId:l}:c&&s===`review`?{mode:`latest-for-section`,blockId:c}:{mode:`latest`},d=await i.getNote(o,{projection:s===`review`?`review`:`workbench`,includeAttachments:!0,includeSections:!0,resultSelection:e}).catch(async t=>(console.warn(`[WorkbenchSession] Note persistence projection failed, falling back to provider entry:`,{routeId:o,projection:s===`review`?`review`:`workbench`,resultSelectionMode:e.mode,err:t}),a.getRecord(o)));if(d){let e=wR(d.rawContent,{noteBlocks:d.blocks,sourceRevision:Math.max(1,d.sourceRevision??0)});return t({currentEntry:d,content:d.rawContent,sections:e.sections,blocks:e.blocks,noteBlocks:e.noteBlocks,sourceRevision:d.sourceRevision??0,lastSavedContent:d.rawContent,saveState:`saved`}),s===`review`&&u&&t(e=>e.currentEntry?{currentEntry:{...e.currentEntry,results:u}}:e),r.onLoaded?.(d),d}if(a.mode===`static`){let e=await oR(o);if(e)return n().setContent(e),null}}catch(e){console.error(`[WorkbenchSession] Failed to load entry for ID:`,o,e)}}else d&&e.navigate?.({type:`goToPlan`,noteId:d});return n().setContent(f??``),null},setActiveSegmentIds:e=>t({activeSegmentIds:e}),setActiveStatementIds:e=>t({activeStatementIds:e}),setAnalytics:(e,n)=>t({analyticsSegments:e,analyticsGroups:n}),appendOutputStatement:e=>t(t=>{let n=[...t.outputStatementList,e],{segments:r,groups:i}=tR(t.runtime);return t.runtime?{outputStatementList:n,analyticsSegments:r,analyticsGroups:i}:{outputStatementList:n}}),clearOutputStatementList:()=>t({outputStatementList:[]}),feedLogOutputs:(e,n)=>{let{segments:r,groups:i}=nR(e,n);t({logOutputList:e,analyticsSegments:r,analyticsGroups:i})},toggleAnalyticsSegment:(e,n,r)=>t(t=>{let i=new Set(t.selectedAnalyticsIds);if(n?.shiftKey&&t.lastSelectedAnalyticsId!==null&&r){let n=r.indexOf(t.lastSelectedAnalyticsId),a=r.indexOf(e);if(n!==-1&&a!==-1){let e=Math.min(n,a),t=Math.max(n,a);r.slice(e,t+1).forEach(e=>i.add(e))}}else n?.ctrlKey?i.has(e)?i.delete(e):i.add(e):(i.clear(),i.add(e));return{selectedAnalyticsIds:i,lastSelectedAnalyticsId:e}}),setUserOverride:(e,n)=>t(t=>{let r=new Map(t.userOutputOverrides);return r.set(e,J.from(n,e)),{userOutputOverrides:r}}),clearUserOverride:e=>t(t=>{let n=new Map(t.userOutputOverrides);return n.delete(e),{userOutputOverrides:n}}),setGridViewPreset:e=>t({gridViewPreset:e}),setHoveredBlockKey:e=>t({hoveredBlockKey:e}),setDocumentItems:e=>t({documentItems:e}),setSelectedBlock:e=>t({selectedBlock:e,selectedBlockId:e?.id??null}),setSelectedBlockId:e=>t({selectedBlockId:e}),setCursorLine:e=>t({cursorLine:e}),setHighlightedLine:e=>t({highlightedLine:e}),setSubscriptionManager:e=>{t({subscriptionManager:e}),yR.setSubscriptionRegistry(e)},setViewMode:e=>t({viewMode:e}),setRuntime:e=>{for(let e of s)e();if(s=[],e){let r=tR(e);t({runtime:e,outputStatementList:[],analyticsSegments:r.segments,analyticsGroups:r.groups}),s.push(e.subscribeToOutput(()=>{n().appendOutputStatement({})})),s.push(e.subscribeToStack(e=>{let n=e.blocks[0],r=new Set;for(let t of e.blocks)r.add(Ni(t.key.toString()));let i=new Set;if(n&&Array.isArray(n.sourceIds))for(let e of n.sourceIds)i.add(e);t({activeSegmentIds:r,activeStatementIds:i})}));let i=UA();if(i?.connected){let t=new mR(i);s.push(e.subscribeToStack(e=>t.onStackSnapshot(e)),e.subscribeToOutput(e=>t.onOutput(e)),()=>t.dispose());try{t.onStackSnapshot(e.getStackSnapshot())}catch{}}}else t({runtime:null,outputStatementList:[]})},setExecution:e=>t({execution:e}),setHandles:e=>t({handles:e}),getNote:async(e,t)=>{if(!r)throw Error(`[WorkbenchSession] getNote called without a notePersistence port`);return r.getNote(e,t)},resetStore:()=>{o!==null&&(a(o),o=null);for(let e of s)e();s=[],t({...kR})}}});return t.length>0&&c.subscribe(e=>{for(let n of t)n(e)}),Object.assign(c,{__nowProvider:n})}var MR=jR();function NR(e){let t=MR;return MR=e,t}function PR(){return MR}var FR=e=>En(MR,e),IR=({nowProvider:e,notePersistence:t,provider:n,navigate:r,children:i})=>{let a=(0,U.useMemo)(()=>jR({nowProvider:e,notePersistence:t,provider:n,navigate:r}),[e,t,n,r]);return(0,U.useEffect)(()=>{let e=NR(a);return()=>{NR(e),a.getState().resetStore()}},[a]),U.createElement(U.Fragment,null,i)},LR={getEventsByTimeRange:(e,t)=>Z.getEventsByTimeRange(e,t),getEventsByMetricDates:e=>Z.getEventsByMetricDates(e),getEventsByResult:e=>Z.getEventsByResult(e),getEventsForNote:e=>Z.getEventsForNote(e),getEventsByContent:e=>Z.getEventsByContent(e),scanAll:()=>Z.scanAll(),appendEvents:e=>Z.appendEvents(e),finalizeSummaries:(e,t)=>Z.finalizeSummaries(e,t),deleteEvents:e=>Z.deleteEvents(e)},RR={getAllNotes:()=>Z.getAllNotes(),getNotesByIds:async e=>[...(await Z.getDetailBatches(e)).values()].map(e=>e.note),getNoteIdsForTag:async e=>new Set((await Z.getNotesForTag(e)).map(e=>e.id)),getNoteTagLabels:async e=>(await Z.getTagsForNote(e)).map(e=>e.label),queryDomain:async e=>{if(!Z.queryDomain)return;let t=await Z.queryDomain({...e,plan:`notes`});return t&&t.plan===`notes`?t:void 0}},zR={getAllBlocks:()=>Z.getAllBlockIndex(),queryDomain:async e=>{if(!Z.queryDomain)return;let t=await Z.queryDomain({...e,plan:`blocks`});return t&&t.plan===`blocks`?t:void 0}},BR=class{async getAllEfforts(){let e=xO();return e.isInitialized()||await gO(e),[...e.list()]}},VR=new Fg,HR={events:[],notes:[]},UR={events:[],notes:[]};VR.set(`@session`,HR),VR.set(`@today`,UR);function WR(){let e=PR().getState(),t=e.runtime?.getOutputStatements()??[],n=e.currentEntry;return HR.notes=n?[{id:n.id,title:n.title,createdAt:n.createdAt,date:n.targetDate,rawContent:n.rawContent,sourceRevision:n.sourceRevision??1,blocks:n.blocks??{}}]:[],t.length===0?(HR.events=[],HR):(HR.events=Kg(t.map(Vp),{noteId:n?.id??``,resultId:`live:${n?.id??`session`}`,origin:`playground`,workoutTimestamp:n?.targetDate}),HR)}function GR(e,t,n,r){let i=[...t].sort((e,t)=>(e.position??1/0)-(t.position??1/0)||e.createdAt-t.createdAt);for(let e of i){let t=n.get(e.pageId)?.date;if(t)return t}return yg(e.date??e.createdAt,r)}async function KR(e,t){let n=yg(e.instant,e.timeZone),r=wg(n,e.timeZone),i=wg(bg(n,1),e.timeZone),[a,o,s,c]=await Promise.all([Z.getEventsByTimeRange(r,i),Z.getAllNotes(),Z.getAllPageNotes(),Z.getAllPages()]),l=a.filter(e=>e.timestamp>=r&&e.timestamp<i),u=new Map(c.map(e=>[e.id,e])),d=new Map;for(let e of s){let t=d.get(e.noteId);t?t.push(e):d.set(e.noteId,[e])}let f=[];for(let t of o)GR(t,d.get(t.id)??[],u,e.timeZone)===n&&f.push(t);t===YR&&(UR.events=l,UR.notes=f,WR())}var qR=null,JR=null,YR=0,XR=!1,ZR=new Set;function QR(){for(let e of ZR)e()}function $R(e,t){JR=t;let n=++YR;return qR=KR(e,n),qR.then(()=>{n===YR&&ez()},()=>{n===YR&&ez()}),qR}function ez(){XR=!0,QR()}function tz(){let e=pg(),t=yg(e.instant,e.timeZone);return!qR||JR!==t?$R(e,t):qR}function nz(){XR=!1;let e=pg();return $R(e,yg(e.instant,e.timeZone))}function rz(){return XR}function iz(e){return ZR.add(e),()=>{ZR.delete(e)}}var az=class extends j_{async runQuery(e,t){return await tz(),super.runQuery(e,t)}async runPipeline(e,t){return await tz(),super.runPipeline(e,t)}async runFind(e,t){return await tz(),super.runFind(e,t)}async runRows(e,t){return await tz(),super.runRows(e,t)}async run(e,t){return await tz(),super.run(e,t)}};function oz(){return new az({eventStore:LR,noteStore:RR,blockStore:zR,effortStore:new BR,blockEffortsStore:{getAllFromIndex:(e,t)=>Z.getAllFromIndex(`block_efforts`,e,t)},tagsStore:{getAllFromIndex:(e,t)=>Z.getAllFromIndex(`tags`,e,t),getAll:()=>Z.getAllTags()},noteTagsStore:{getAllFromIndex:(e,t)=>Z.getAllFromIndex(`note_tags`,e,t)},pageStore:{getNotePages:e=>Z.getNotePages(e),getPage:e=>Z.getPage(e),getAllPages:()=>Z.getAllPages(),getAllLinks:()=>Z.getAllPageNotes()},relationStore:{getBatches:e=>Z.getDetailBatches(e)},datasetStore:{getDataset:e=>e===`@session`?WR():VR.getDataset(e)}})}var sz=oz();function cz(e){let t=e.split(`/`),n=t[0]??e,r=t[1]??``;return n===`journal`?{kind:`journal`,id:r,raw:e}:n===`playground`?{kind:`playground`,id:r,raw:e}:t.length<2?{kind:`workout`,id:n,raw:e}:{kind:`workout`,category:n,id:r,raw:e}}var lz=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function uz(e){return typeof e==`string`&&e&&!lz.test(e)?e:void 0}function dz(e){return!!e.sourceId?.startsWith(`notebook:`)||e.sourcePath?.startsWith(`markdown/notebooks/`)===!0}function fz(e){return e.type===`dashboard`||e.sourceId===`dashboards`||e.sourcePath?.startsWith(`markdown/dashboards/`)===!0}function pz(e){return e.sourceId===`efforts`||e.sourcePath?.startsWith(`markdown/efforts/`)===!0}function mz(e){return e.sourceId===`equipment`||e.sourcePath?.startsWith(`markdown/equipment/`)===!0}function hz(e){return e.type===`tag`&&e.id.startsWith(`tag/`)}function gz(e){let t=/^tag\/([^/]+)\/(.+)$/.exec(e.id);return t?{type:t[1],label:t[2]}:void 0}function _z(e,t){let n=e.sourcePath?.replace(/^markdown\/[^/]+\//,``).replace(/\.md$/,``);if(!n)return;let r=n.split(`/`);return r.length===t?r[t-1]:void 0}function vz(e){let t=e.sourceId;if(t?.startsWith(`notebook:`)){let e=t.slice(9);if(e&&e!==`_root`){let t=e.indexOf(`/`);return t===-1?{slug:e,item:``}:{slug:e.slice(0,t),item:e.slice(t+1)}}}let n=/^markdown\/notebooks\/([^/]+)\/(.+)\.md$/.exec(e.sourcePath??``);if(n)return{slug:n[1],item:n[2].toLowerCase()===`readme`?``:n[2]};let r=e.id;if(lz.test(r))return{slug:``,item:``};let[i,...a]=r.split(`/`);return{slug:i,item:a.join(`/`)}}function yz(e){return e.sourceId===`playground`||e.type===`playground`||e.id.startsWith(`playground/`)}function bz(e){return e.id.startsWith(`playground/`)?e.id.slice(11):e.id}function xz(e){return{...Sz(e),noteType:e.type,notebookId:n_(e),editable:ka(e,r_(e))}}function Sz(e){let t=e.id,n=e.title,r=e.tags&&e.tags.length>0?e.tags:void 0;if(yz(e))return{id:t,kind:`note`,sourceNotebook:`playground`,sourceNote:bz(e),sourceId:e.sourceId,title:n,date:null,createdAt:e.createdAt,...r?{tags:r}:{}};if(dz(e)){let{slug:i,item:a}=vz(e),o=!a,s=a.split(`/`),c=s.length>1&&/^\d{4}-\d{2}-\d{2}$/.test(s[0])?s[0]:null;return{id:t,kind:`note`,sourceNotebook:i,sourceNote:o?``:a,sourceId:e.sourceId,sourcePath:e.sourcePath,title:n,date:c??(e.date?gP(new Date(e.date)):null),createdAt:e.createdAt,subtitle:i,...r?{tags:r}:{}}}if(fz(e))return{id:t,kind:`dashboard`,sourceNotebook:`dashboards`,sourceNote:_z(e,1)??t,sourceId:e.sourceId,sourcePath:e.sourcePath,title:n,date:null,createdAt:e.createdAt,subtitle:`dashboards`,...r?{tags:r}:{}};if(pz(e)){let i=_z(e,2)??t,a=e.sourcePath?.match(/^markdown\/efforts\/([^/]+)\//)?.[1];return{id:t,kind:`effort`,sourceNotebook:`efforts`,sourceNote:i,sourceId:e.sourceId,sourcePath:e.sourcePath,title:n,date:null,createdAt:e.createdAt,subtitle:a,effort:{slug:i},...r?{tags:r}:{}}}if(mz(e))return{id:t,kind:`equipment`,sourceNotebook:`equipment`,sourceNote:_z(e,1)??t,sourceId:e.sourceId,sourcePath:e.sourcePath,title:n,date:null,createdAt:e.createdAt,subtitle:`equipment`,...r?{tags:r}:{}};if(hz(e)){let i=gz(e);return{id:t,kind:`tag`,sourceNotebook:`tags`,sourceNote:i?.label??n,title:n||i?.label||t,date:null,createdAt:e.createdAt,subtitle:(`tagType`in e&&typeof e.tagType==`string`?e.tagType:void 0)??i?.type,detail:e.rawContent||void 0,...r?{tags:r}:{}}}if(e.sourceId?.startsWith(`guides:`)){let i=e.sourceId.slice(7)||t;return{id:t,kind:`note`,sourceNotebook:`guides`,sourceNote:i,sourceId:e.sourceId,sourcePath:e.sourcePath,pageSlug:uz(i.replace(/^\//,``).replace(/^page\//,``)),title:n,date:null,createdAt:e.createdAt,...r?{tags:r}:{}}}let i=null;return`journalDate`in e&&typeof e.journalDate==`string`?i=e.journalDate:`date`in e&&typeof e.date==`string`?i=e.date:`targetDate`in e&&e.targetDate&&(typeof e.targetDate==`number`||typeof e.targetDate==`string`)?i=gP(new Date(e.targetDate)):e.createdAt&&(i=gP(new Date(e.createdAt))),{id:t,kind:`note`,sourceNotebook:`journal`,sourceNote:t,sourceId:e.sourceId,sourcePath:e.sourcePath,pageId:`pageId`in e&&typeof e.pageId==`string`?e.pageId:void 0,pageSlug:`slug`in e?uz(e.slug):void 0,title:n,date:i,createdAt:e.createdAt,...r?{tags:r}:{}}}function Cz(e){return{id:e.noteId,title:e.noteTitle,createdAt:e.createdAt,type:`note`,sourceId:e.sourceId,sourcePath:e.sourcePath,rawContent:``,sourceRevision:1,blocks:{}}}var wz=3,Tz=120;function Ez(e){return e.split(`
100
- `).map(e=>e.trim()).filter(Boolean).slice(0,wz).map(e=>e.length>Tz?`${e.slice(0,119)}…`:e)}function Dz(e){let t=xz(Cz(e));return{...t,blockContentId:e.blockContentId??t.blockContentId,block:{blockId:e.blockId,dataType:e.dataType,preview:Ez(e.rawContent)}}}function Oz(e){return e?e.split(`-`).map(e=>{let t=e.toLowerCase();return t===`c2b`?`C2B`:t===`t2b`?`T2B`:t===`ghd`?`GHD`:t===`hspu`?`HSPU`:e.charAt(0).toUpperCase()+e.slice(1)}).join(` `):``}function kz(e){if(!Number.isFinite(e)||e<=0)return`00:00`;let t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;if(n>=60){let e=Math.floor(n/60),t=n%60;return`${e}:${String(t).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}return`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}function Az(e){if(!e)return`Workout Session`;let t=cz(e);return t.kind===`journal`?t.id?`Journal: ${t.id}`:`Journal Entry`:t.kind===`workout`?Oz(t.id)||t.id:t.id?Oz(t.id):e}function jz(e){let t=[e.baseAttributes?.discipline,e.baseAttributes?.met==null?void 0:`MET ${e.baseAttributes.met.toFixed(1)}`,e.baseAttributes?.intensityTier].filter(Boolean);return{id:e.slug,kind:`effort`,sourceNotebook:e.registrySource??`effort`,sourceNote:e.slug,title:e.label,date:null,subtitle:t.join(` • `),detail:e.aliases&&e.aliases.length>0?`Aliases: ${e.aliases.join(`, `)}`:void 0,effort:{slug:e.slug,label:e.label,discipline:e.baseAttributes?.discipline,met:e.baseAttributes?.met,intensityTier:e.baseAttributes?.intensityTier,aliases:e.aliases,registrySource:e.registrySource}}}function Mz(e){let t=(e.type??``).toLowerCase(),n=(`name`in e&&typeof e.name==`string`?e.name:``).toLowerCase(),r=typeof e.value==`number`?e.value:Number(e.value);return Number.isFinite(r)?t===`rep`||n===`reps`||n===`rep`?{kind:`rep`,val:r}:t===`weight`||t===`load`||n===`load`||n===`weight`||n===`volume`?{kind:`load`,val:r}:t===`distance`||n===`distance`?{kind:`distance`,val:r}:t===`tis`||n===`tis`?{kind:`tis`,val:r}:t===`duration`||n===`duration`?{kind:`duration`,val:r}:null:null}function Nz(e){let t=1/0,n=-1/0,r=0,i=0,a=0,o=0,s=new Set;for(let c of e.events)if(c.outputType===`segment`&&o++,c.effortSlug&&s.add(c.effortSlug),c.timeSpan?.started!=null&&(c.timeSpan.started<t&&(t=c.timeSpan.started),c.timeSpan.ended!=null&&c.timeSpan.ended>n&&(n=c.timeSpan.ended)),Array.isArray(c.metrics))for(let e of c.metrics){let t=Mz(e);t&&(t.kind===`rep`?r+=t.val:t.kind===`load`?i+=t.val:t.kind===`tis`&&t.val>a&&(a=t.val))}return{elapsedMs:Number.isFinite(t)&&Number.isFinite(n)&&n>t?n-t:void 0,reps:r>0?r:void 0,loadLbs:i>0?i:void 0,tis:a>0?a:void 0,segmentCount:o>0?o:void 0,effortSlugs:Array.from(s)}}function Pz(e,t){let n=Nz(e),r=[];n.elapsedMs!=null&&r.push(kz(n.elapsedMs)),n.tis!=null&&r.push(`TIS ${n.tis.toFixed(1)}`),n.loadLbs!=null&&r.push(`Volume: ${n.loadLbs.toLocaleString()} lbs`),n.reps!=null&&r.push(`${n.reps} reps`),n.segmentCount!=null&&r.push(`${n.segmentCount} splits`);let i=n.effortSlugs.map(Oz),a=gP(new Date(e.timestamp)),o=e.events.find(e=>!!e.blockContentId)?.blockContentId;return{id:e.resultId,kind:`result`,sourceNotebook:`results`,sourceNote:e.resultId,title:t?.noteTitle??Az(e.noteId),date:a,blockContentId:o,subtitle:r.join(` • `),detail:i.length>0?i.join(`, `):void 0,execution:{resultId:e.resultId,noteId:e.noteId,timestamp:e.timestamp,outputType:`all`,elapsedMs:n.elapsedMs,reps:n.reps,loadLbs:n.loadLbs,tis:n.tis,segmentCount:n.segmentCount,events:e.events}}}function Fz(e,t){let n;e.timeSpan?.started!=null&&e.timeSpan?.ended!=null&&(n=e.timeSpan.ended-e.timeSpan.started);let r,i,a,o;if(Array.isArray(e.metrics))for(let t of e.metrics){let e=Mz(t);e&&(e.kind===`rep`?r=e.val:e.kind===`load`?i=e.val:e.kind===`distance`?a=e.val:e.kind===`tis`?o=e.val:e.kind===`duration`&&!n&&(n=e.val))}let s=e.outputType===`segment`?`segment`:`event`,c=t?.index??0,l=e.effortSlug?Oz(e.effortSlug):e.outputType===`segment`?`Round ${c+1}`:`${e.outputType.charAt(0).toUpperCase()+e.outputType.slice(1)} ${c+1}`,u=[];n!=null&&u.push(kz(n)),r!=null&&i!=null?u.push(`${r} reps @ ${i} lbs`):r==null?i!=null&&u.push(`${i} lbs`):u.push(`${r} reps`),a!=null&&u.push(`${a}m`),o!=null&&u.push(`TIS ${o.toFixed(1)}`);let d=gP(new Date(e.timestamp));return{id:e.id,kind:s,sourceNotebook:`results`,sourceNote:e.id,title:l,date:d,blockContentId:e.blockContentId,subtitle:u.join(` • `),detail:e.effortSlug?Oz(e.effortSlug):void 0,execution:{resultId:e.resultId,noteId:e.noteId,timestamp:e.timestamp,outputType:e.outputType,effortSlug:e.effortSlug,elapsedMs:n,reps:r,loadLbs:i,distanceMeters:a,tis:o,metrics:e.metrics}}}function Iz(e,t){if(!e||e.error||!e.runs)return[];let n=e.parsed?.filters?.find(e=>e.key===`plane`&&!e.negate),r=e.parsed?.outputType??n?.values[0]?.value;if(r===`segment`){let t=[];for(let n of e.runs){let e=0;for(let r of n.events)r.outputType===`segment`&&t.push(Fz(r,{index:e++}))}return t}if(r&&r!==`all`){let t=[];for(let n of e.runs){let e=0;for(let i of n.events)i.outputType===r&&t.push(Fz(i,{index:e++}))}return t}return e.runs.map(e=>Pz(e,{noteTitle:t?.noteTitles?.get(e.noteId)}))}function Lz(e,t,n){let r=typeof e.__id==`string`&&e.__id?e.__id:void 0,i=typeof e.__resultId==`string`&&e.__resultId?e.__resultId:void 0,a=typeof e.effort==`string`&&e.effort?e.effort:void 0,o=[];for(let[t,n]of Object.entries(e))t.startsWith(`__`)||t===`date`||t===`effort`||(typeof n==`string`||typeof n==`number`||typeof n==`boolean`)&&o.push(`${t}: ${n}`);return{id:r??i??`${t}:${n}`,kind:t,sourceNotebook:`results`,sourceNote:i??r??`${t}:${n}`,title:a?Oz(a):`${t===`segment`?`Segment`:`Event`} ${n+1}`,date:typeof e.date==`string`?e.date:null,subtitle:o.length>0?o.join(` • `):void 0}}function Rz(e,t,n){e&&e({selected:Math.max(t?.selected??0,n.length),matched:n.length})}function zz(e){return typeof e==`object`&&!!e&&`runFind`in e}var Bz=new class e{customService;noteTitleResolver;noteTagsResolver;noteBlockInfo;constructor(e){zz(e)?this.customService=e:(this.customService=e?.service,this.noteTitleResolver=e?.noteTitleResolver,this.noteBlockInfo=e?.noteBlockInfo??!1,this.noteTagsResolver=e?.noteTagsResolver)}get service(){return this.customService??sz}withNoteBlockInfo(){let t=new e({service:this.service,noteTitleResolver:this.noteTitleResolver,noteTagsResolver:this.noteTagsResolver,noteBlockInfo:!0});return Object.prototype.hasOwnProperty.call(this,`query`)&&(t.query=this.query),t}async hydrateEntries(e,t){let n=new Set;for(let r of e)r.sourceNotebook===`journal`&&n.add(r.id),t&&(!r.title||!r.tags||r.tags.length===0)&&n.add(r.id);if(n.size===0)return;let r=await Z.getDetailBatches([...n]);for(let t of e){if(t.sourceNotebook!==`journal`)continue;let e=r.get(t.id),n=Ca(e?.links??[],e?.pages??[]);t.placements=n;let i=wa(n);t.pageId??=i.pageId,i.pageSlug&&(t.pageSlug=i.pageSlug)}if(t)for(let t of e){let e=r.get(t.id);!t.title&&e?.note.title&&(t.title=e.note.title),e&&e.tags.length>0&&((!t.tags||t.tags.length===0)&&(t.tags=e.tags.map(e=>e.label)),t.typedTags=e.tags.map(e=>({label:e.label,type:e.type})))}}async query(e,t){let n=typeof e==`string`?X(e):e;if(!n||n.error)return[];if(Bm(n)){if(n.target===`effort`){let e=this.service.runFindEffort?await this.service.runFindEffort(n):await this.service.runFind(n),r=new Map(e.notes.map(e=>[e.id,e])),i=(e.efforts??[]).map(e=>e.ownerNoteId&&r.has(e.ownerNoteId)?xz(r.get(e.ownerNoteId)):jz(e));return Rz(t,e.stages,i),i}if(n.target===`block`){let e=await this.service.runFind(n),r=e.blocks.map(Dz);return await this.hydrateEntries(r,!0),Rz(t,e.stages,r),r}if(n.target===`session`){let e=await this.service.runFind(n);t?.(e.stages);let r;if(this.noteTitleResolver&&e.runs){r=new Map;for(let t of e.runs)if(!r.has(t.noteId)){let e=await this.noteTitleResolver(t.noteId);e&&r.set(t.noteId,e)}}let i=Iz(e,{noteTitles:r});return Rz(t,e.stages,i),i}if(n.target===`segment`||n.target===`event`){let e=n.target,r=await this.service.runFind(n),i=(r.table?.rows??[]).map((t,n)=>Lz(t,e,n));return Rz(t,r.stages,i),i}let e=await this.service.runFind(n),r=e.notes.map(xz);if(this.noteTagsResolver?(await this.hydrateEntries(r,!1),await Promise.all(r.map(async e=>{if(!e.tags||e.tags.length===0){let t=await this.noteTagsResolver(e.id);t&&t.length>0&&(e.tags=t)}}))):await this.hydrateEntries(r,!0),Rz(t,e.stages,r),this.noteBlockInfo)for(let t=0;t<r.length;t++){let n=r[t],i=e.notes[t];n.excerpt=Ez(i.rawContent);try{Ra(i.rawContent,i.blocks,i.sourceRevision)}catch{continue}let a=Object.values(i.blocks).sort((e,t)=>e.from-t.from).find(e=>e.kind===`wod`),o=a&&Fa(i.rawContent).find(e=>e.from===a.from&&e.scriptBlock);if(a&&o?.scriptBlock){let e=o.scriptBlock.content,t=ba(e);n.wodBlock={blockId:a.id,blockVersion:a.version,blockContentId:t,content:e},n.blockContentId=t}}return r}return[]}};async function Vz(e,t=Bz,n){return t.query(e,n)}function Hz(e){return e?e.map(e=>e.kind===`wql`?`${e.id}|${e.query}|${e.limit??``}`:`s:${e.id}`).join(`;`):``}async function Uz(e){try{let t=(await Vz(e.query)).filter(t=>!e.filterEntry||e.filterEntry(t)).slice(0,e.limit??6).map(t=>({kind:`link`,id:`${e.id}:${t.id}`,label:e.labelFromEntry?e.labelFromEntry(t):t.title,to:e.toEntry?e.toEntry(t):void 0,muted:!0}));return{kind:`section`,id:e.id,label:e.label,entries:t}}catch{return{kind:`section`,id:e.id,label:e.label,entries:[]}}}function Wz(e){let t=Hz(e),n=(0,U.useRef)(e);n.current=e;let[r,i]=(0,U.useState)(()=>e&&!e.some(e=>e.kind===`wql`)?e:[]);return(0,U.useEffect)(()=>{let e=n.current;if(!e){i([]);return}if(!e.some(e=>e.kind===`wql`)){i(e);return}let t=!1;return Promise.all(e.map(e=>e.kind===`wql`?Uz(e):Promise.resolve(e))).then(e=>{t||i(e)}),()=>{t=!0}},[t]),r}function Gz(){let[e]=Kt(`s`,{shallow:!0}),{navState:t}=WM(),n=t.activeL3Id??``;return e||n||``}function Kz({entry:e,active:t,onActivate:n}){let r=e.onRun;return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:G(`group flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors`,e.muted?`text-[11.5px]`:`text-[13px]`,t?`bg-primary/10 font-semibold text-primary`:G(`hover:bg-muted/60 hover:text-foreground`,e.muted?`text-muted-foreground/70`:`text-muted-foreground`)),children:[e.icon&&(0,W.jsx)(e.icon,{className:`size-4 shrink-0`}),e.timestamp&&(0,W.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/60`,children:e.timestamp}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 line-clamp-2 break-words`,title:e.label,children:e.label}),e.badge&&(0,W.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground/50`,children:e.badge}),r&&(0,W.jsx)(`span`,{role:`button`,tabIndex:-1,title:e.runIcon===`link`?`View workout`:e.runIcon===`stop`?`Stop workout`:e.runIcon===`edit`?`Edit note`:`Start workout`,onClick:t=>{t.stopPropagation(),e.onRun?.()},className:`flex size-5 shrink-0 items-center justify-center rounded text-primary opacity-0 transition-all group-hover:opacity-100 hover:bg-primary/10`,children:e.runIcon===`link`?(0,W.jsx)(l,{className:`size-3.5`}):e.runIcon===`stop`?(0,W.jsx)(x,{className:`size-3.5`}):e.runIcon===`edit`?(0,W.jsx)(o,{className:`size-3.5`}):(0,W.jsx)(rn,{className:`size-3.5`})})]})}function qz({entries:e,activeId:t,onSection:n}){let r=Vn(),{scrollToSection:i}=WM(),a=e=>{if(n)return n(e);if(e.onRun)return e.onRun();if(e.to)return r(e.to);if(e.sectionId)return i(e.sectionId)};return(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>e.kind===`section`?e.entries.length===0?null:(0,W.jsxs)(`div`,{className:`mt-1 flex flex-col gap-0.5 first:mt-0`,children:[(0,W.jsx)(`div`,{className:`px-2 pb-1 pt-3 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:e.label}),(0,W.jsx)(qz,{entries:e.entries,activeId:t,onSection:n})]},e.id):e.kind===`wql`?null:(0,W.jsx)(Kz,{entry:e,active:t!=null&&e.sectionId===t,onActivate:a},e.id))})}function Jz(){let e=Vn(),{scrollToSection:t}=WM();return{navigate:(t,n)=>e(t,{replace:n?.replace}),setQueryParam:(e,t)=>{},scrollToSection:t}}function Yz(){let e=Jz(),{openCreateJournal:t}=WM();return n=>{if(n.id===`home-new-journal`){t({mode:`blank`});return}eI(n.action,e)}}function Xz(e,t,n){return e.isActive?e.isActive(n,t):e.action.type===`route`?e.action.to===`/`?n.pathname===`/`||n.pathname===``:n.pathname===e.action.to:e.action.type===`scroll`?t.activeL3Id===e.action.sectionId:e.action.type===`query`&&t.activeL3Id===e.id}function Zz({items:e}){let{navState:t}=WM(),n=Sn(),r=Yz();return(0,W.jsx)(RP,{children:e.map(e=>{if(e.variant===`notable`)return(0,W.jsx)(`div`,{className:`mb-2`,children:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`nav-item-${e.id}`,onClick:()=>r(e),className:`flex w-full items-center justify-center gap-2 rounded-lg bg-primary/10 px-3 py-2 text-xs font-semibold text-primary transition-all hover:bg-primary hover:text-primary-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary shadow-sm`,children:[(0,W.jsx)(On,{className:`size-4 shrink-0`}),(0,W.jsx)(`span`,{children:e.label})]})},e.id);let i=Xz(e,t,n);return e.children&&e.children.length>0?(0,W.jsx)(aI,{title:e.label,count:e.children.length,defaultOpen:e.children.some(e=>Xz(e,t,n)),collapsible:e.id!==`syntax-group`,children:e.children.map(e=>{let i=Xz(e,t,n);return(0,W.jsxs)(zP,{onClick:()=>r(e),current:i,children:[e.icon&&(0,W.jsx)(e.icon,{"data-slot":`icon`}),(0,W.jsx)(BP,{children:e.label})]},e.id)})},e.id):(0,W.jsxs)(zP,{onClick:e.disabled?void 0:()=>r(e),current:i,disabled:e.disabled,"aria-label":e.disabled?`${e.label} (coming soon)`:void 0,className:e.disabled?`opacity-60`:void 0,children:[e.icon&&(0,W.jsx)(e.icon,{"data-slot":`icon`}),(0,W.jsx)(BP,{children:e.disabled?`+`:e.label})]},e.id)})})}function Qz({navSpec:e}){let{tree:t,navState:n,dispatch:r,contextNav:i}=WM(),a=Sn(),o=Wz(e),s=(t??[]).find(e=>e?.id===n.activeL1Id)??null,c=i?.pathname===a.pathname?i:null;return(0,W.jsxs)(FP,{children:[(0,W.jsx)(IP,{children:(0,W.jsx)(`div`,{className:`px-2 pt-3 pb-1 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:s?.label??`Wod Wiki`})}),(0,W.jsxs)(LP,{children:[(()=>{if(c||!s)return null;if(s.panel){let e=s.panel;return(0,W.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,W.jsx)(e,{item:s,navState:n,dispatch:r})})}return s.children&&s.children.length>0?(0,W.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,W.jsx)(Zz,{items:s.children})}):null})(),c?(0,W.jsx)(`div`,{className:`pt-1`,children:(0,W.jsx)(qz,{entries:c.spec})}):o.length>0&&(0,W.jsx)(`div`,{className:`pt-1`,children:(0,W.jsx)(qz,{entries:o})})]})]})}var $z=`0.45.2166`,eB=`https://github.com/bitcobblers/wod-wiki/releases`;function tB(e){return/-pr\.\d+$/.test(e)?eB:`${eB}/tag/v${e}`}function nB({onSearch:e,onCreate:t}){let{tree:n,navState:r,dispatch:i}=WM(),a=Vn(),o=Sn(),s=kP(),c={navigate:(e,t)=>a(e,{replace:t?.replace}),setQueryParam:()=>{},scrollToSection:()=>{}},l=(n??[]).filter(e=>e!=null&&e.icon!=null&&e.id!==`settings`&&e.id!==`buy-me-a-coffee`),u=o.pathname.startsWith(`/settings`),d=o.pathname===`/`||o.pathname===``,f=`pointer-events-none absolute left-full top-1/2 -translate-y-1/2 z-50 ml-2 w-max rounded-md border border-border bg-popover px-2 py-1 text-xs text-popover-foreground opacity-0 shadow-md transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>a(`/`),title:`Home`,"aria-label":`Wod Wiki home`,"aria-current":d?`page`:void 0,className:`group relative mb-3 grid size-8 shrink-0 place-items-center rounded-xl bg-primary text-primary-foreground shadow-md shadow-primary/20 rotate-3`,children:[(0,W.jsx)(se,{size:17}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Home`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Home`})]}),(0,W.jsx)(`nav`,{"aria-label":`Primary`,className:`flex flex-col items-center gap-1.5`,children:l.map(e=>{let t=e.icon,n=Xz(e,r,o);return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{i({type:`SET_ACTIVE_L1`,id:e.id}),eI(e.action,c)},title:e.label,"aria-label":e.label,"aria-current":n?`page`:void 0,className:G(`group relative grid size-9 place-items-center rounded-lg transition-colors`,n?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[n&&(0,W.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,W.jsx)(t,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:e.label}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:e.label})]},e.id)})}),(0,W.jsx)(`div`,{className:`flex-1`}),(0,W.jsxs)(`button`,{type:`button`,onClick:e,title:`Search (⌘/)`,"aria-label":`Search`,className:`group relative grid size-9 place-items-center rounded-lg text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground`,children:[(0,W.jsx)(en,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Search`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Search (⌘/)`})]}),(0,W.jsxs)(`a`,{href:oL,target:`_blank`,rel:`noopener noreferrer`,title:`Buy Me a Coffee`,"aria-label":`Buy Me a Coffee`,className:`group relative grid size-9 place-items-center rounded-lg text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground`,children:[(0,W.jsx)(sL,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Buy Me a Coffee`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Buy Me a Coffee`})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{s(),a(`/settings/profile`)},title:`Profile`,"aria-label":`Profile`,"aria-current":o.pathname.startsWith(`/settings/profile`)?`page`:void 0,"data-testid":`nav-profile`,className:G(`group relative grid size-9 place-items-center rounded-lg transition-colors mt-1.5`,o.pathname.startsWith(`/settings/profile`)?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[o.pathname.startsWith(`/settings/profile`)&&(0,W.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,W.jsx)(Me,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Profile`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Profile`})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{s(),a(`/settings/appearance`)},title:`Settings`,"aria-label":`Settings`,"aria-current":u?`page`:void 0,"data-testid":`nav-settings`,className:G(`group relative grid size-9 place-items-center rounded-lg transition-colors mt-1.5`,u?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[u&&(0,W.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,W.jsx)(gt,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Settings`}),(0,W.jsxs)(`span`,{role:`tooltip`,className:`pointer-events-none absolute bottom-0 left-full z-50 ml-2 w-max rounded-md border border-border bg-popover px-2 py-1 text-xs text-popover-foreground opacity-0 shadow-md transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[`Settings (v`,$z,`)`]})]})]})}function rB({activations:e,activeSection:t,variant:n,deps:r,className:i}){return(0,W.jsx)(`nav`,{className:G(`lg:sticky z-20 flex items-center gap-1 px-4 py-2 bg-background/95 backdrop-blur-sm border-b border-border/50 overflow-x-auto`,n===`top-fixed`?`lg:top-0`:`lg:top-[104px]`,i),children:e.map(e=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,r),className:G(`px-3 py-1.5 rounded-full text-[10px] font-black uppercase tracking-[0.12em] whitespace-nowrap transition-all ring-1`,t===e.id?`bg-primary text-primary-foreground ring-primary/30 shadow-md`:`bg-muted/50 text-muted-foreground ring-transparent hover:bg-muted hover:ring-border`),children:e.label},e.id))})}var iB=class e{now;name=`tick`;timestamp;data;static _counter=0;constructor(t,n=wl){this.now=n;let r=this.now.nowMs();e._counter++,this.timestamp=new Date(r+e._counter),this.data=t}},aB=20,oB=e=>{let[t,n]=(0,U.useState)(`idle`),[r,i]=(0,U.useState)(0),[a,o]=(0,U.useState)(0),[s,c]=(0,U.useState)(null),l=(0,U.useRef)(null),u=(0,U.useRef)(null),d=(0,U.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),n(`idle`)},[]),f=(0,U.useCallback)(()=>{if(e)try{let t=new iB(void 0,e.nowProvider);e.handle(t),o(e=>e+1)}catch{d(),n(`error`)}},[e,d]);(0,U.useEffect)(()=>{if(e)return e.subscribeToStack(e=>{e.blocks.length===0&&t!==`completed`&&(l.current&&=(clearInterval(l.current),null),n(`completed`))})},[e,t]),(0,U.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]);let p=(0,U.useCallback)(()=>{if(!e){console.warn(`useRuntimeExecution: Cannot start execution without a runtime`);return}if(t===`running`){console.warn(`useRuntimeExecution: Runtime is already running`);return}t===`paused`&&e.handle({name:`timer:resume`,timestamp:new Date,data:{}}),n(`running`);let i=e?.nowProvider?.nowMs()??wl.nowMs();u.current=i-r,r===0&&c(i),l.current=setInterval(f,aB)},[e,t,r,f]),m=(0,U.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),e&&e.handle({name:`timer:pause`,timestamp:new Date,data:{}}),n(`paused`)},[e]),h=(0,U.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),i(0),o(0),n(`idle`),c(null),u.current=null},[e]),g=(0,U.useCallback)(()=>{!e||t===`running`||(n(`paused`),f())},[e,t,f]);return(0,U.useEffect)(()=>{if(t!==`running`||!u.current)return;let n=setInterval(()=>{i((e?.nowProvider?.nowMs()??wl.nowMs())-u.current)},100);return()=>clearInterval(n)},[t,e?.nowProvider]),(0,U.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]),(0,U.useEffect)(()=>{h()},[e,h]),(0,U.useMemo)(()=>({status:t,elapsedTime:r,stepCount:a,startTime:s,start:p,pause:m,stop:d,reset:h,step:g}),[t,r,a,s,p,m,d,h,g])},sB=(e,t)=>!e||!Array.isArray(e)?0:e.reduce((e,n)=>{if(`started`in n){let r=n.started,i=n.ended??t;return e+Math.max(0,i-r)}let r=n.start instanceof Date?n.start.getTime():n.start||0,i=n.stop?n.stop instanceof Date?n.stop.getTime():n.stop:t;return e+Math.max(0,i-r)},0);function cB(e,t){let n=t,r=()=>{let t=e?.getMemoryByTag(n)[0];if(t)return n===`round`?t.metrics[0]:t.metrics[0]?.value},[i,a]=(0,U.useState)(r);return(0,U.useEffect)(()=>{if(!e){a(void 0);return}a(r());let t=e.getMemoryByTag(n)[0];if(t)return t.subscribe(e=>{a(n===`round`?e[0]:e[0]?.value)})},[e,t]),i}function lB(e){return cB(e,`round`)}function uB(e){return cB(e,`display`)}function dB(e){let t=lB(e),n=uB(e);return(0,U.useMemo)(()=>{if(!t)return null;let e=n?.roundDisplay??(t.total===void 0?`Round ${t.current}`:`Round ${t.current} of ${t.total}`),r=t.total===void 0?void 0:Math.min(1,(t.current-1)/t.total);return{current:t.current,total:t.total,label:e,progress:r}},[t,n?.roundDisplay])}var fB=(0,U.createContext)(void 0),pB=({runtime:e,children:t})=>(0,W.jsx)(fB.Provider,{value:e,children:t});function mB(){let e=(0,U.useContext)(fB);if(!e)throw Error(`useScriptRuntime must be used within ScriptRuntimeProvider`);return e}function hB(e){let t=mB(),n=e===void 0?t:e,[r,i]=(0,U.useState)(()=>n?.getOutputStatements?.()??[]);return(0,U.useEffect)(()=>{if(!n){i([]);return}return i(n.getOutputStatements()),n.subscribeToOutput?.(()=>{i(n.getOutputStatements())})},[n]),(0,U.useMemo)(()=>{let e=new Map,t=new Map,n=[],i=[];for(let a of r){e.set(a.id,a);let r=t.get(a.sourceBlockKey)??[];switch(r.push(a),t.set(a.sourceBlockKey,r),a.outputType){case`segment`:n.push(a);break;case`metric`:i.push(a)}}let a=n.filter(e=>e.completionReason!==void 0);return{outputs:r,byId:e,byBlockKey:t,segments:n,completions:a,metrics:i}},[r])}function gB(e){let t=mB(),n=e===void 0?t:e,[r,i]=(0,U.useState)(()=>n?.getLiveAnalytics?.()??[]);return(0,U.useEffect)(()=>{if(!n){i([]);return}return i(n.getLiveAnalytics?.()??[]),n.subscribeToOutput?.(()=>{i(n.getLiveAnalytics?.()??[])})},[n]),r}function _B(){let e=mB(),[t,n]=(0,U.useState)({type:`initial`,blocks:e.stack.blocks,depth:e.stack.count,clockTime:e.clock.currentDate});return(0,U.useEffect)(()=>e.subscribeToStack(e=>{n(e)}),[e]),t}function vB(){return _B().blocks}function yB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`metric:next`);for(let r of e){let e=r.subscribe(()=>{n(e=>e+1)});t.push(e)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{for(let t of e){let e=t.getMemoryByTag(`metric:next`);if(e.length===0)continue;let n=J.empty(t.key.toString());for(let t of e)n.merge(t.metrics);if(n.length>0)return{metrics:n,block:t}}return null},[e,t])}function bB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`time`)[0];if(e){let r=e.subscribe(()=>{n(e=>e+1)});t.push(r)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{let t=[];for(let n of e){let e=n.getMemoryByTag(`time`)[0];if(!e)continue;let r=e.metrics[0]?.value;r&&t.push({block:n,timer:r,isPinned:r.role===`primary`})}return t},[e,t])}function xB(){let e=bB();return(0,U.useMemo)(()=>{if(e.length===0)return;let t=e[0];return t.block.blockType===`Rest`?t:[...e].reverse().find(e=>e.isPinned)||t},[e])}function SB(){let e=bB(),t=xB();return(0,U.useMemo)(()=>t?e.filter(e=>e.block!==t.block):[],[e,t])}function CB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`controls`);for(let r of e){let e=r.subscribe(()=>{n(e=>e+1)});t.push(e)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r].getMemoryByTag(`controls`);if(i.length===0)continue;let a=i[0].metrics.map(e=>e.value).filter(Boolean),o=r===e.length-1;for(let e of a)e.isPinned?t.push(e):o&&n.push(e)}let r=new Set,i=[];for(let e of t)r.has(e.id)||(r.add(e.id),i.push(e));for(let e of n)r.has(e.id)||(r.add(e.id),i.push(e));return i},[e,t])}function wB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`metric:display`);for(let r of e){let e=r.subscribe(()=>{n(e=>e+1)});t.push(e)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{if(e.length===0)return;let t=[],n=[...e].reverse();return n.forEach((e,r)=>{if(e.blockType===`Root`&&!e.label)return;let i=e.getMemoryByTag(`metric:display`),a=i.map(e=>e.metrics);if(a.length===0&&!e.label)return;let o=r===n.length-1,s=i.length>1?i.map(e=>e.metrics):void 0;t.push({block:e,displayRows:a,label:e.label,depth:r,isLeaf:o,metricGroups:s})}),t.length>0?t:void 0},[e,t])}function TB(e){let t=mB(),n=(0,U.useMemo)(()=>t.stack.blocks.find(t=>t.key.toString()===e),[t,e]),[r,i]=(0,U.useState)(()=>n?.getMemoryByTag(`time`)[0]?.metrics[0]?.value);(0,U.useEffect)(()=>t.stack.subscribe(()=>{let n=t.stack.blocks.find(t=>t.key.toString()===e);if(n){let e=n.getMemoryByTag(`time`)[0];i(e?.metrics[0]?.value)}else i(void 0)}),[t,e]),(0,U.useEffect)(()=>{if(!n){i(void 0);return}let e=n.getMemoryByTag(`time`)[0];if(i(e?.metrics[0]?.value),e)return e.subscribe(e=>{i(e[0]?.value)})},[n]);let a=(0,U.useMemo)(()=>r?.spans??[],[r]),o=a.length>0&&a[a.length-1].ended===void 0,[s,c]=(0,U.useState)(fu()),l=(0,U.useMemo)(()=>a.length===0?0:sB(a,s),[a,s]);return(0,U.useEffect)(()=>{if(!o)return;let e,t=()=>{c(fu()),e=requestAnimationFrame(t)};return t(),()=>cancelAnimationFrame(e)},[o]),{elapsed:l,isRunning:o,timeSpans:a}}var EB=(0,U.createContext)(void 0),DB=(0,U.createContext)(null),OB={getState:()=>PR().getState(),setState:(e,t)=>{let n=PR();typeof e==`function`?n.setState(e(n.getState()),t):n.setState(e,t)},subscribe:e=>PR().subscribe(e)},kB=({factory:e,children:t})=>{let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null),u=(0,U.useRef)(e);u.current=e;let d=(0,U.useRef)(null),f=(0,U.useRef)(null),p=(0,U.useRef)(!1),m=(0,U.useCallback)(()=>{f.current&&=(f.current.dispose(),null),a(null),OB.getState().setSubscriptionManager(null);let e=d.current;if(d.current=null,e)try{u.current.disposeRuntime(e)}catch(e){console.error(`[RuntimeProvider] Error disposing runtime:`,e)}r(null),l(null)},[]),h=(0,U.useCallback)((e,t)=>{if(!p.current){p.current=!0,s(!0),l(null);try{f.current&&=(f.current.dispose(),null);let n=d.current;if(d.current=null,n)try{u.current.disposeRuntime(n)}catch(e){console.error(`[RuntimeProvider] Error disposing existing runtime:`,e)}let i=u.current.createRuntime(e,t);if(d.current=i,r(i),i){let e=new wp(i);e.add(new Cp({id:`local`})),f.current=e,a(e),OB.getState().setSubscriptionManager(e)}else f.current=null,a(null),OB.getState().setSubscriptionManager(null)}catch(e){console.error(`[RuntimeProvider] Error creating runtime:`,e),l(e instanceof Error?e:Error(String(e))),d.current=null}finally{p.current=!1,s(!1)}}},[]);(0,U.useEffect)(()=>()=>{if(f.current&&f.current.dispose(),d.current)try{u.current.disposeRuntime(d.current)}catch(e){console.error(`[RuntimeProvider] Error disposing runtime on unmount:`,e)}},[]);let g={runtime:n,isInitializing:o,error:c,initializeRuntime:h,disposeRuntime:m};return(0,W.jsx)(EB.Provider,{value:g,children:(0,W.jsx)(DB.Provider,{value:i,children:t})})};function AB({factory:e,children:t}){return(0,W.jsx)(kB,{factory:e,children:t})}var jB=`bg-background ring-1 ring-zinc-950/5 shadow-sm lg:shadow-[-18px_0_36px_-28px_rgba(15,23,42,0.16),18px_0_36px_-28px_rgba(15,23,42,0.16)] dark:shadow-none dark:ring-white/10`,MB=`flex flex-col flex-1 min-w-0 xl:max-w-[984px] 2xl:max-w-none min-h-screen lg:rounded-[2.5rem]`;function NB({id:e,title:t,subtitle:n,titleAccessory:r,actions:i,queryBar:a,subheader:o,titleTestId:s,className:c}){return(0,W.jsxs)(`div`,{id:e,"data-page-sticky-boundary":`true`,className:G(`max-lg:hidden lg:sticky lg:top-0 z-30 bg-background/80 backdrop-blur-md transition-colors`,c),children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-4 sm:px-6 lg:px-8 py-2 sm:py-2.5`,children:[t&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5 sm:gap-3 min-w-0`,children:[(0,W.jsx)(`div`,{className:`h-5 w-1.5 shrink-0 rounded-full bg-primary`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`h1`,{"data-testid":s,className:`text-base sm:text-lg font-black tracking-tight text-foreground leading-none truncate`,children:t}),n&&(0,W.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground truncate`,children:n})]}),r]})]}),a&&(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:a}),i&&(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0 ml-auto`,children:i})]}),o&&(0,W.jsx)(`div`,{className:`bg-background/40`,children:o})]})}function PB({ids:e,enabled:t=!0,rootMargin:n=`-10% 0px -40% 0px`,threshold:r=[0,.3,1],onChange:i,shouldAcceptChange:a,scrollDirection:o=`ratio`,dataAttribute:s,debounceMs:c=0}){let l=(0,U.useRef)(``),u=(0,U.useRef)(i),d=(0,U.useRef)(a),f=(0,U.useRef)(null),p=(0,U.useRef)(1);(0,U.useEffect)(()=>{u.current=i},[i]),(0,U.useEffect)(()=>{d.current=a},[a]);let m=e.filter(Boolean).join(`\0`),h=r.join(`,`),g=(0,U.useMemo)(()=>m?m.split(`\0`):[],[m]),_=(0,U.useMemo)(()=>h.split(`,`).map(Number),[h]),v=(0,U.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null)},[]);(0,U.useEffect)(()=>{if(!t||g.length===0||typeof IntersectionObserver>`u`)return;let e=new Map,r=e=>s?e.getAttribute(s):e.id||null,i;if(o===`topmost-when-up`){let e=window.scrollY,t=()=>{let t=window.scrollY;t!==e&&(p.current=t>e?1:-1),e=t};window.addEventListener(`scroll`,t,{passive:!0}),i=()=>window.removeEventListener(`scroll`,t)}let a=new IntersectionObserver(t=>{if(t.forEach(t=>{let n=r(t.target);n&&(t.isIntersecting?e.set(n,t.intersectionRatio):e.delete(n))}),e.size===0)return;let n=``;if(o===`topmost-when-up`&&p.current===-1){let t=1/0;e.forEach((e,r)=>{let i=g.indexOf(r);i>=0&&i<t&&(t=i,n=r)})}else{let t=-1;e.forEach((e,r)=>{e>t&&(t=e,n=r)})}!n||n===l.current||d.current&&!d.current(n)||(l.current=n,c>0?(v(),f.current=setTimeout(()=>{u.current(n),f.current=null},c)):u.current(n))},{rootMargin:n,threshold:_});return g.forEach(e=>{let t=s?document.querySelector(`[${s}="${e}"]`):document.getElementById(e);t&&a.observe(t)}),()=>{a.disconnect(),v(),i?.()}},[t,g,_,n,o,s,c,v])}function FB({title:e,titleAccessory:t,actions:n,subheader:r,children:i,index:a=[],activeSectionId:o,hero:s,sections:c,className:l}){let u=!!(c&&c.length>0)&&!e,[,d]=Kt(`s`,{defaultValue:o??a[0]?.id??``,shallow:!0,history:`replace`}),[f,p]=(0,U.useState)(c?.[0]?.id??``);if(PB({ids:a.map(e=>e.id),enabled:!u&&a.length>0,rootMargin:`-10% 0px -40% 0px`,threshold:[0,.3,1],onChange:e=>{d(e)},shouldAcceptChange:()=>!0}),PB({ids:c?.map(e=>e.id)??[],enabled:u,rootMargin:`-20% 0px -50% 0px`,threshold:[0,.25,.5,.75],onChange:p}),u){let e=c.map(e=>({id:e.id,label:e.label,action:{type:`scroll`,sectionId:e.id}}));return(0,W.jsxs)(`div`,{className:G(`flex flex-col min-h-screen bg-background`,l),children:[s,(0,W.jsx)(rB,{activations:e,activeSection:f,variant:`top-fixed`,deps:{navigate:()=>{},setQueryParam:()=>{},scrollToSection:e=>{let t=document.getElementById(e);if(t){let e=t.getBoundingClientRect().top+window.scrollY-64;window.scrollTo({top:e,behavior:`smooth`})}}}}),(0,W.jsx)(`div`,{className:`flex-1`,children:c.map(e=>{let t=(0,W.jsx)(`div`,{id:e.id,"data-section-id":e.id,className:`py-12 lg:py-16 px-6 lg:px-10 border-b border-border/30`,children:e.content},e.id);return e.runtimeFactory?(0,W.jsx)(AB,{factory:e.runtimeFactory,children:t},e.id):t})})]})}return(0,W.jsx)(`div`,{className:G(`relative flex w-full min-h-screen justify-start items-start`,l),children:(0,W.jsxs)(`div`,{className:G(MB,jB),children:[(0,W.jsx)(NB,{title:e,titleAccessory:t,actions:n,subheader:r}),(0,W.jsx)(`div`,{className:`flex-1`,children:i})]})})}var IB=`[data-page-sticky-boundary="true"]`,LB=0;function RB(e,t=LB){if(typeof document>`u`)return e;let n=Array.from(document.querySelectorAll(IB)).reduce((e,t)=>{let n=t.getBoundingClientRect();return n.height<=0||n.bottom<=0?e:Math.max(e,n.bottom)},0);return n>0?n+t:e}function zB(e,t=LB){let[n,r]=(0,U.useState)(e);return(0,U.useEffect)(()=>{let n=0,i=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>r(RB(e,t)))};return i(),window.addEventListener(`scroll`,i,{passive:!0}),window.addEventListener(`resize`,i),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,i),window.removeEventListener(`resize`,i)}},[e,t]),n}function BB({top:e,label:t,icon:n,badge:r,meta:i,testId:a,className:o}){return(0,W.jsxs)(`div`,{"data-testid":a,className:G(`sticky z-10 flex items-center gap-2 border-y border-border/60 bg-card/95 px-6 py-2 shadow-[0_1px_2px_rgba(0,0,0,0.03)] backdrop-blur`,o),style:{top:`${e}px`},children:[n,(0,W.jsx)(`span`,{className:`min-w-0 truncate text-xs font-bold text-foreground`,children:t}),r,i&&(0,W.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 font-mono text-[10px] text-muted-foreground`,children:i})]})}var VB=(0,U.createContext)(null),HB=(0,U.createContext)(null);function UB({children:e}){let[t,n]=(0,U.useState)(null);return(0,W.jsx)(HB.Provider,{value:n,children:(0,W.jsx)(VB.Provider,{value:t,children:e})})}function WB({className:e}){let t=(0,U.useContext)(HB);return(0,W.jsx)(`div`,{ref:t,className:e,"data-testid":`mobile-query-slot`})}function GB(){return(0,U.useContext)(VB)}function KB({editor:e,title:t,subtitle:n,titleTestId:r,actions:i,timerOverlay:a,reviewOverlay:o,isTimerOpen:s=!1,isReviewOpen:c=!1,onCloseTimer:l,onCloseReview:u,className:d}){return(0,W.jsxs)(`div`,{className:G(`relative flex w-full min-h-screen justify-start items-start`,d),children:[(0,W.jsxs)(`div`,{className:G(MB,jB),children:[(0,W.jsx)(NB,{title:t,subtitle:n,titleTestId:r,actions:i}),(0,W.jsx)(`main`,{className:`flex-1 min-w-0 max-w-full`,children:e})]}),s&&a&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,W.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,W.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,W.jsx)(`button`,{onClick:l,className:`px-3 py-1.5 rounded-md text-sm font-bold text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted transition-colors`,children:`Close`})}),(0,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:a})]})}),c&&o&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,W.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,W.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,W.jsx)(`button`,{onClick:u,className:`px-3 py-1.5 rounded-md text-sm font-bold text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted transition-colors`,children:`Close`})}),(0,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:o})]})})]})}function qB(e){return e.map(e=>{let t=e.action,n=e.secondaryAction?.action,r={kind:`link`,id:e.id,label:e.label};return n&&n.type===`call`&&(r.onRun=n.handler,r.runIcon=e.secondaryRunIcon??`play`),t.type===`route`?{...r,to:t.to}:t.type===`scroll`?{...r,sectionId:t.sectionId}:t.type===`call`?{...r,onRun:t.handler}:r})}var JB=U.createContext(null);function YB(){let e=U.useContext(JB);if(!e)throw Error(`DropdownMenu components must be used inside a DropdownMenu`);return e}function XB(){let e=U.useContext(JB);return U.useCallback(()=>{e?.setIsOpen(!1)},[e])}var ZB=({children:e,open:t,onOpenChange:n})=>{let r=U.useContext(JB),i=U.useId(),a=r?`${r.portalChain}/${i}`:i,[o,s]=U.useState(t??!1),c=U.useRef(null),[l,u]=U.useState(-1),d=U.useRef(new Map),[,f]=U.useReducer(e=>e+1,0);U.useEffect(()=>{t!==void 0&&s(t)},[t]);let p=U.useCallback(e=>{s(e),u(-1),n?.(e)},[n]),m=U.useCallback((e,t)=>{d.current.set(e,t),f()},[]),h=U.useCallback(e=>{d.current.delete(e),f()},[]),g=U.useCallback(e=>Array.from(d.current.keys()).indexOf(e),[]),_=d.current.size,v=U.useMemo(()=>({isOpen:o,setIsOpen:p,triggerRef:c,registerItem:m,unregisterItem:h,getItemIndex:g,activeIndex:l,setActiveIndex:u,itemCount:_,menuId:i,portalChain:a}),[o,p,m,h,g,l,_,i,a]);return(0,W.jsx)(JB.Provider,{value:v,children:(0,W.jsx)(`div`,{ref:c,className:`relative inline-block`,children:e})})},QB=U.forwardRef(({className:e,children:t,asChild:n,...r},i)=>{let{isOpen:a,setIsOpen:o}=YB(),s=e=>{e.stopPropagation(),o(!a)};return n&&U.isValidElement(t)?U.cloneElement(t,{...r,onClick:s}):(0,W.jsx)(`button`,{ref:i,className:e,onClick:s,...r,children:t})});QB.displayName=`DropdownMenuTrigger`;var $B=U.forwardRef(({className:e,children:t,align:n=`center`,side:r=`bottom`,...i},a)=>{let{isOpen:o,setIsOpen:s,triggerRef:c,setActiveIndex:l,itemCount:u,menuId:d,portalChain:f}=YB(),p=U.useRef(null),m=a||p,[h,g]=U.useState({top:0,bottom:0,left:0,width:0}),_=r===`bottom`,[v,y]=U.useState(!1);U.useEffect(()=>{if(!o||!c.current)return;let e=c.current.getBoundingClientRect();g({top:e.bottom+8,bottom:window.innerHeight-e.top+8,left:e.left,width:e.width}),y(!1)},[o,c]),U.useLayoutEffect(()=>{if(!o||!_||!m.current)return;let e=m.current.getBoundingClientRect();y(h.top+e.height>window.innerHeight)},[o,_,h.top]),U.useEffect(()=>{if(!o||u===0)return;let e=setTimeout(()=>{l(0)},0);return()=>clearTimeout(e)},[o,u,l]),U.useEffect(()=>{if(!o)return;let e=e=>{let t=e.target;if(m.current&&m.current.contains(t)||c.current&&c.current.contains(t))return;let n=t.closest?.(`[data-dropdown-chain]`)?.getAttribute(`data-dropdown-chain`);n&&n.split(`/`).includes(d)||s(!1)},t=setTimeout(()=>{document.addEventListener(`mousedown`,e)},0);return()=>{clearTimeout(t),document.removeEventListener(`mousedown`,e)}},[o,s,m,c,d]);let b=e=>{if(u!==0)switch(e.key){case`ArrowDown`:e.preventDefault(),l(e=>e<u-1?e+1:0);break;case`ArrowUp`:e.preventDefault(),l(e=>e>0?e-1:u-1);break;case`Home`:e.preventDefault(),l(0);break;case`End`:e.preventDefault(),l(u-1);break;case`Escape`:e.preventDefault(),s(!1),c.current?.querySelector(`button`)?.focus();break;case`Tab`:s(!1)}};if(!o)return null;let x={position:`fixed`,zIndex:9999};return r===`top`||v?x.bottom=h.bottom:x.top=h.top,n===`end`?x.right=window.innerWidth-h.left-h.width:n===`start`?x.left=h.left:(x.left=h.left+h.width/2,x.transform=`translateX(-50%)`),TC.createPortal((0,W.jsx)(`div`,{ref:m,role:`menu`,"data-dropdown-chain":f,className:G(`min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95`,e),style:x,onKeyDown:b,...i,children:t}),document.body)});$B.displayName=`DropdownMenuContent`;var eV=U.forwardRef(({className:e,disabled:t,inset:n,onClick:r,onKeyDown:i,...a},o)=>{let{setIsOpen:s,registerItem:c,unregisterItem:l,getItemIndex:u,activeIndex:d}=YB(),f=U.useId(),p=U.useRef(null),m=U.useCallback(e=>{p.current=e,typeof o==`function`?o(e):o&&(o.current=e)},[o]);U.useEffect(()=>(c(f,p),()=>l(f)),[f,c,l]);let h=u(f)===d;return U.useEffect(()=>{h&&p.current?.focus()},[h]),(0,W.jsx)(`div`,{ref:m,role:`menuitem`,tabIndex:t?-1:h?0:-1,"aria-disabled":t,"data-active":h?`true`:void 0,className:G(`relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors`,`focus:bg-accent focus:text-accent-foreground`,`data-[active]:bg-accent data-[active]:text-accent-foreground`,n&&`pl-8`,t&&`pointer-events-none opacity-50`,e),onClick:e=>{t||(r?.(e),s(!1))},onKeyDown:e=>{t||(i?.(e),(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r?.(e),s(!1)))},...a})});eV.displayName=`DropdownMenuItem`;var tV=U.forwardRef(({className:e,inset:t,...n},r)=>(0,W.jsx)(`div`,{ref:r,className:G(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));tV.displayName=`DropdownMenuLabel`;var nV=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(`div`,{ref:n,className:G(`-mx-1 my-1 h-px bg-muted`,e),...t}));nV.displayName=`DropdownMenuSeparator`;function rV({className:e,children:t,...n}){return(0,W.jsx)(`div`,{className:G(`px-2 py-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,e),...n,children:t})}var iV=[{label:`Past 1 week`,value:`last 1w`},{label:`Past 2 weeks`,value:`last 2w`},{label:`Past 4 weeks`,value:`last 4w`},{label:`Past 8 weeks`,value:`last 8w`},{label:`Past 12 weeks`,value:`last 12w`},{label:`Past 1 year`,value:`last 52w`},{label:`All time`,value:`all`}],aV=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function oV(e,t){return new Date(e,t+1,0).getDate()}function sV(e,t){let n=new Date(e,t,1).getDay();return n===0?6:n-1}function cV(e,t){let n=X(e);if(n.error)return e;if(!t||t===`all`)return jh({...n,window:void 0});let r=X(`:note ${t}`);return r.error||r.family!==`find`||!r.window?e:jh({...n,window:r.window})}function lV(e){let t=X(e);return t.error||t.family===`pipeline`?null:`window`in t?t.window??null:null}function uV({query:e,onQueryChange:t,highlightDates:n=new Set,className:r}){let i=(0,U.useMemo)(()=>lV(e),[e]),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(()=>new Date),l=s.getFullYear(),u=s.getMonth(),d=(0,U.useMemo)(()=>i?i.kind===`relative`?`last ${i.size}${i.unit}`:i.end?`from ${i.start} to ${i.end}`:`from ${i.start}`:`All time`,[i]),f=(0,U.useMemo)(()=>{if(!i)return null;if(i.kind===`range`)return{start:i.start,end:i.end??i.start};let e=new Date,t=new Date;return i.unit===`d`?t.setDate(e.getDate()-i.size):t.setDate(e.getDate()-i.size*7),{start:gP(t),end:gP(e)}},[i]),p=(0,U.useMemo)(()=>{let e=oV(l,u),t=sV(l,u),n=[];for(let e=0;e<t;e++)n.push(null);for(let t=1;t<=e;t++)n.push(t);return n},[l,u]),m=n=>{if(!a)o(n),t(cV(e,`from ${n} to ${n}`));else{let[r,i]=a<=n?[a,n]:[n,a];o(null),t(cV(e,`from ${r} to ${i}`))}},h=e=>{e.stopPropagation(),c(new Date(l,u-1,1))},g=e=>{e.stopPropagation(),c(new Date(l,u+1,1))},_=s.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`}),v=gP(new Date);return(0,W.jsxs)(`div`,{className:G(`relative inline-flex items-center`,r),children:[(0,W.jsxs)(ZB,{children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`wql-window-picker-trigger`,className:`flex h-9 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,W.jsx)(mn,{className:`size-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:d}),(0,W.jsx)(Et,{className:`size-3 text-muted-foreground`,"aria-hidden":`true`})]})}),(0,W.jsxs)($B,{align:`end`,className:`w-72 p-3`,children:[(0,W.jsx)(`div`,{className:`mb-3 flex flex-wrap gap-1 border-b border-border/60 pb-2`,children:iV.map(n=>{let r=n.value===`all`?!i:i?.kind===`relative`&&`last ${i.size}${i.unit}`===n.value;return(0,W.jsx)(`button`,{type:`button`,"data-testid":`wql-window-preset-${n.value}`,onClick:()=>{o(null),t(cV(e,n.value))},className:G(`rounded-md px-2 py-1 text-[11px] font-medium transition-colors`,r?`bg-primary text-primary-foreground`:`bg-muted/50 text-muted-foreground hover:bg-muted hover:text-foreground`),children:n.label},n.value)})}),(0,W.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:h,"data-testid":`wql-calendar-prev-month`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,W.jsx)(Un,{className:`size-4`})}),(0,W.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:_}),(0,W.jsx)(`button`,{type:`button`,onClick:g,"data-testid":`wql-calendar-next-month`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,W.jsx)(wn,{className:`size-4`})})]}),(0,W.jsx)(`div`,{className:`mb-1 grid grid-cols-7 gap-1`,children:aV.map(e=>(0,W.jsx)(`div`,{className:`text-center text-[10px] font-medium text-muted-foreground`,children:e},e))}),(0,W.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,"data-testid":`wql-calendar-grid`,children:p.map((e,t)=>{if(e===null)return(0,W.jsx)(`div`,{className:`size-8`},`empty-${t}`);let r=`${l}-${String(u+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,i=f&&r>=f.start&&r<=f.end,o=f&&r===f.start||a===r,s=f&&r===f.end,c=r===v,d=n.has(r);return(0,W.jsxs)(`button`,{type:`button`,"data-testid":`wql-calendar-day-${r}`,onClick:()=>m(r),className:G(`relative flex size-8 items-center justify-center rounded-md text-xs transition-colors`,o||s?`bg-primary font-bold text-primary-foreground`:i?`bg-primary/15 font-semibold text-primary`:c?`border border-primary font-semibold text-primary`:`text-foreground hover:bg-muted`),children:[(0,W.jsx)(`span`,{children:e}),d&&!o&&!s&&(0,W.jsx)(`span`,{className:`absolute bottom-0.5 size-1 rounded-full bg-primary`})]},r)})}),a&&(0,W.jsxs)(`div`,{className:`mt-2 text-center text-[10px] text-muted-foreground`,children:[`Select second date to complete range (starting from `,a,`)`]})]})]}),i&&(0,W.jsx)(`button`,{type:`button`,"data-testid":`wql-window-picker-clear`,onClick:()=>{o(null),t(cV(e,null))},title:`Clear time window`,"aria-label":`Clear time window`,className:`ml-1 grid size-7 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,W.jsx)(we,{className:`size-3.5`})})]})}function dV({onOpen:e}){let t=XB();return(0,W.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{t(),e()},"data-testid":`query-settings-trigger`,className:`w-full justify-start gap-2 rounded-lg text-xs`,children:[(0,W.jsx)(vn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`truncate`,children:`Query settings`})]})}function fV(e){switch(e.kind){case`note`:return`note`;case`result`:return`result`;case`segment`:case`event`:return`segment`;case`effort`:return`effort`;default:return`note`}}var pV=[{id:`title`,label:`Title`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`tags`,label:`Tags`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.tags??[],formatValue:e=>Array.isArray(e)?e.join(`, `):String(e??``)},{id:`excerpt`,label:`Text Excerpt`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.block?.preview?.join(` `)||e.detail||``,formatValue:e=>String(e??``)},{id:`sourceNotebook`,label:`Notebook`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.sourceNotebook,formatValue:e=>String(e??``)},{id:`date`,label:`Date`,level:`note`,defaultVisible:!0,align:`right`,getValue:e=>e.date,formatValue:e=>String(e??``)}],mV={note:pV,session:[{id:`title`,label:`Title`,level:`session`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`protocol`,label:`Protocol`,level:`session`,defaultVisible:!0,align:`left`,getValue:e=>e.block?.dataType||e.subtitle||``,formatValue:e=>String(e??``)},{id:`movements`,label:`Movements`,level:`session`,defaultVisible:!0,align:`left`,getValue:e=>e.detail||``,formatValue:e=>String(e??``)},{id:`targetDuration`,label:`Target Duration`,level:`session`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.elapsedMs==null?``:kz(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`sessionLoad`,label:`Session Load`,level:`session`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs,formatValue:e=>typeof e==`number`?`${e.toLocaleString()} lbs`:``}],result:[{id:`title`,label:`Title`,level:`result`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`elapsedTime`,label:`Elapsed Time`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.elapsedMs==null?``:kz(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`totalTonnage`,label:`Total Tonnage`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs,formatValue:e=>typeof e==`number`?`${e.toLocaleString()} lbs`:``},{id:`tis`,label:`TIS Score`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.tis,formatValue:e=>typeof e==`number`?e.toFixed(1):``},{id:`prBadges`,label:`PR Badges`,level:`result`,defaultVisible:!0,align:`center`,getValue:e=>e.detail&&/\bPR\b/.test(e.detail)?`PR`:``,formatValue:e=>String(e??``)}],segment:[{id:`splitDuration`,label:`Split Duration`,level:`segment`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.elapsedMs==null?``:kz(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`roundIndex`,label:`Round/Lap Index`,level:`segment`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`reps`,label:`Reps`,level:`segment`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.reps,formatValue:e=>e==null?``:String(e)},{id:`load`,label:`Load`,level:`segment`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs,formatValue:e=>typeof e==`number`?`${e.toLocaleString()} lbs`:``},{id:`pacingTier`,label:`Pacing / HR Tier`,level:`segment`,defaultVisible:!0,align:`center`,getValue:e=>e.effort?.intensityTier||e.execution?.effortSlug||``,formatValue:e=>String(e??``)}],effort:[{id:`label`,label:`Label`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.label||e.title,formatValue:e=>String(e??``)},{id:`canonicalSlug`,label:`Canonical Slug`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.slug||e.id,formatValue:e=>String(e??``)},{id:`discipline`,label:`Discipline`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.discipline??``,formatValue:e=>String(e??``)},{id:`met`,label:`MET Score`,level:`effort`,defaultVisible:!0,align:`right`,getValue:e=>e.effort?.met,formatValue:e=>typeof e==`number`?e.toFixed(1):``},{id:`intensityTier`,label:`Intensity Tier`,level:`effort`,defaultVisible:!0,align:`center`,getValue:e=>e.effort?.intensityTier??``,formatValue:e=>String(e??``)},{id:`aliases`,label:`Aliases`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.aliases??[],formatValue:e=>Array.isArray(e)?e.join(`, `):String(e??``)}]};function hV(e){return mV[e]??pV}function gV(e){return hV(e).filter(e=>e.defaultVisible).map(e=>e.id)}var _V=[{id:`cards`,label:`Cards`,icon:ye},{id:`rows`,label:`Rows`,icon:le},{id:`feed`,label:`Feed`,icon:Qn}];function vV({streamControls:e}){return(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,"data-testid":`l3-stream-controls`,children:[e.onOpenQuerySettings&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`This page`}),(0,W.jsx)(dV,{onOpen:e.onOpenQuerySettings})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Date window`}),(0,W.jsx)(uV,{query:e.query,onQueryChange:e.onQueryChange,className:`w-full justify-between`})]}),e.availableGroupDims.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Group by`}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-groupby-options`,children:e.availableGroupDims.map(t=>{let n=e.groupDims.some(e=>e.toLowerCase()===t.id.toLowerCase());return(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-xs text-foreground/80 hover:bg-muted/60 transition-colors`,"data-testid":`l3-groupby-${t.id}`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleGroupDim(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{children:t.label})]},t.id)})})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Layout`}),(0,W.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,"data-testid":`l3-layout-options`,children:_V.map(t=>{let n=t.icon,r=e.settings.layout===t.id;return(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>e.onLayoutChange(t.id),"data-testid":`l3-layout-${t.id}`,className:`flex min-h-8 items-center justify-center gap-1 rounded-md border px-1.5 py-1 text-[11px] font-medium transition-colors ${r?`border-border/80 bg-card text-foreground shadow-sm`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[(0,W.jsx)(n,{"aria-hidden":!0,className:`size-3`}),t.label]},t.id)})})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Fields`}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-field-options`,children:hV(e.level).map(t=>{let n=e.settings.visibleFields.includes(t.id);return(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-xs text-foreground/80 hover:bg-muted/60 transition-colors`,"data-testid":`l3-field-${t.id}`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleField(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{children:t.label})]},t.id)})})]})]})}function yV({spec:e,pageAction:t}){let{l3Items:n,streamControls:r}=WM(),i=Wz(e),a=(0,U.useMemo)(()=>qB(n),[n]),o=Gz();return i.length===0&&a.length===0&&!r&&!t?null:(0,W.jsxs)(`div`,{className:`flex flex-col px-3 py-4 gap-4`,children:[r&&(0,W.jsx)(`div`,{className:`pb-3 border-b border-border/50`,children:(0,W.jsx)(vV,{streamControls:r})}),i.length>0&&(0,W.jsx)(qz,{entries:i,activeId:o}),a.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-col`,children:[(0,W.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`On this page`}),(0,W.jsx)(qz,{entries:a,activeId:o})]}),t&&(0,W.jsx)(`div`,{className:`pt-2 border-t border-border/50`,children:t})]})}var bV=1023;function xV(e){return e===`/`?`canvas:home`:`canvas:${e.replace(/^\//,``)}`}function SV(e,t){if(e===`query:new`)return``;let n=e=>{let n=`/${e}`;for(let r of Object.keys(t))if(r===e||r.endsWith(n))return r;return null},r=e=>{let r=n(e);return r===null?null:Gy(t[r])};if(e.startsWith(`markdown/`)){let t=r(e);if(t!==null)return t}let i=e;if(e.startsWith(`wods/examples/`))i=`markdown/canvas/`+e.replace(/^wods\/examples\//,``);else if(e.startsWith(`wods/`))i=`markdown/canvas/`+e.replace(/^wods\//,``);else if(e.startsWith(`canvas/`))i=`markdown/canvas/`+e.replace(/^canvas\//,``);else{let t=r(`markdown/canvas/`+e);if(t!==null)return t;i=`markdown/`+e}return r(i)??`# Source not found\n\nPath: \`${e}\`\nResolved: \`${i}\``}function CV(e){return(e.examples??[]).length>0||e.commands.some(e=>e.pipeline.length>0)}function wV(e){let t=new Map,n=null;for(let r of e)CV(r)&&(n=r),t.set(r.id,n);return t}function TV(){let[e,t]=(0,U.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: ${bV}px)`).matches);return(0,U.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: ${bV}px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var EV=`wodwiki:fabAlignment`,DV=[{id:`left`,label:`Bottom left`,description:`Left-handed — search and page actions float near your left thumb`},{id:`right`,label:`Bottom right`,description:`Right-handed — search and page actions float near your right thumb`}];function OV(){try{return kV(localStorage.getItem(EV))}catch{return}}function kV(e){return e===`right`||e===`left`?e:void 0}var AV=typeof window>`u`?void 0:OV();typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===EV&&(AV=kV(e.newValue))});function jV(e){AV=e;try{e===`right`?localStorage.removeItem(EV):localStorage.setItem(EV,e)}catch{}window.dispatchEvent(new StorageEvent(`storage`,{key:EV,newValue:e}))}function MV(){let[e,t]=(0,U.useState)(()=>AV??`right`);return(0,U.useEffect)(()=>{let e=e=>{e.key===EV&&t(kV(e.newValue)??`right`)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),[e,jV]}function NV({onOpen:e}){return(0,W.jsxs)(`button`,{type:`button`,onClick:e,"aria-label":`Search`,title:`Search`,"data-testid":`search-fab`,className:G(`size-14 rounded-full flex items-center justify-center`,`bg-primary text-primary-foreground shadow-lg`,`hover:bg-primary/90 active:scale-95 transition-all`,`focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`),children:[(0,W.jsx)(en,{className:`size-6`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Search`})]})}var PV=(0,U.createContext)(null),FV=(0,U.createContext)(!1),IV=(0,U.createContext)(null);function LV(){return(0,U.useContext)(PV)!==null}function RV({primary:e,navbar:t,children:n,label:r,fallback:i=!1}){let a=(0,U.useContext)(PV),o=(0,U.useContext)(FV),s=TV(),c=(0,U.useId)(),l=a!==null&&!o&&s&&!i,u=a!==null&&i,d=(0,W.jsx)(FV.Provider,{value:!0,children:n});return(0,U.useEffect)(()=>{if(!(!l&&!u))return a.register({id:c,primary:e,navbar:t,children:d,label:r??`Page options`,fallback:i}),()=>a.unregister(c)},[l,u,a,c,e,d,r,i]),i||a&&s&&!o?null:(0,W.jsx)(FV.Provider,{value:!0,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t,e,n]})})}function zV({onSearch:e,children:t}){let[n,r]=(0,U.useState)([]),i=(0,U.useCallback)(e=>r(t=>[...t.filter(t=>t.id!==e.id),e]),[]),a=(0,U.useCallback)(e=>r(t=>t.filter(t=>t.id!==e)),[]),o=(0,U.useMemo)(()=>({register:i,unregister:a}),[i,a]),s=(0,U.useMemo)(()=>{for(let e=n.length-1;e>=0;--e)if(!n[e].fallback)return n[e].navbar??null;return null},[n]);return(0,W.jsx)(PV.Provider,{value:o,children:(0,W.jsxs)(IV.Provider,{value:s,children:[t,(0,W.jsx)(VV,{registrations:n,onSearch:e})]})})}function BV(){let e=(0,U.useContext)(IV);return e?(0,W.jsx)(W.Fragment,{children:e}):null}function VV({registrations:e,onSearch:t}){let n=TV(),[r]=MV(),i=DC(),[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(null),c=Sn(),[l,u]=(0,U.useState)(!1),d=(0,U.useRef)(0),f=i.offsetBottom>0,p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=(0,U.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(!e[t].fallback)return e[t]},[e]),g=(0,U.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(e[t].fallback)return e[t]},[e]);(0,U.useEffect)(()=>{o(!1),u(!1),d.current=window.scrollY},[c.pathname]),(0,U.useEffect)(()=>{if(!n)return;let e=()=>{let e=window.scrollY;if(e<=0||f||a){d.current=e,u(!1);return}let t=e-d.current;Math.abs(t)<8||(d.current=e,u(t>0))};return window.addEventListener(`scroll`,e,{passive:!0}),()=>window.removeEventListener(`scroll`,e)},[n,f,a]),(0,U.useLayoutEffect)(()=>{a&&s.current?.focus()},[a]);let[_,v]=(0,U.useState)({active:0,global:0});(0,U.useLayoutEffect)(()=>{let e=p.current?.childElementCount??0,t=m.current?.childElementCount??0;v(n=>n.active===e&&n.global===t?n:{active:e,global:t})},[h,g]);let y=_.active>0||_.global>0;return!n||!t&&!h&&!g?null:(0,W.jsxs)(`div`,{"data-testid":`actions-dock`,className:G(`lg:hidden fixed z-40 flex flex-col items-center gap-2`,`transition-[transform,visibility] duration-200 ease-out`,r===`left`?`left-4 items-start`:`right-4 items-end`,l&&!a&&!f&&`translate-y-[calc(100%+2rem)] invisible pointer-events-none`),style:{bottom:`calc(1rem + var(--thumb-dock-lift, 0px) + ${i.offsetBottom}px + env(safe-area-inset-bottom))`},children:[(0,W.jsxs)(`div`,{className:`relative z-40 flex flex-col items-center gap-2`,children:[h?.primary&&(0,W.jsx)(`div`,{className:`[&_button]:min-h-11 [&_button]:min-w-11`,children:h.primary}),t&&(0,W.jsx)(NV,{onOpen:()=>{o(!1),t()}})]}),a&&y&&(0,W.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-hidden":`true`,className:`fixed inset-0 z-30 cursor-default`,onClick:()=>o(!1)}),(0,W.jsxs)(`div`,{ref:s,role:`dialog`,"aria-label":h?.label??g?.label??`Page options`,tabIndex:-1,hidden:!a||!y,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))},className:G(`relative z-40 flex w-60 max-w-[calc(100vw-2rem)] flex-col gap-3 overflow-y-auto rounded-2xl bg-card p-3 shadow-xl ring-1 ring-foreground/5 outline-none`,`[&_button]:min-h-11 [&_button]:min-w-11`),style:{maxHeight:`calc(${i.height===null?`100dvh`:`${i.height}px`} - 6rem - env(safe-area-inset-bottom))`},children:[(0,W.jsx)(`div`,{ref:p,className:`contents`,children:h?.children}),_.active>0&&_.global>0&&(0,W.jsx)(`div`,{className:`my-1 border-t border-border/60`,"aria-hidden":`true`}),(0,W.jsx)(`div`,{ref:m,className:`contents`,children:g?.children})]}),y&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":h?.label??g?.label??`Page options`,title:h?.label??g?.label??`Page options`,"aria-expanded":a,"data-testid":`actions-overflow`,className:G(`relative z-40 flex size-12 items-center justify-center rounded-full`,`bg-card text-foreground shadow-lg ring-1 ring-foreground/10`,`hover:bg-muted active:scale-95 transition-all`,`focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`),children:[a?(0,W.jsx)(Le,{className:`size-6`}):(0,W.jsx)(he,{className:`size-6`}),(0,W.jsx)(`span`,{className:`sr-only`,children:h?.label??g?.label??`Page options`})]})]})}function HV(){return(0,W.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,W.jsx)(`path`,{d:`M2 6.75C2 6.33579 2.33579 6 2.75 6H17.25C17.6642 6 18 6.33579 18 6.75C18 7.16421 17.6642 7.5 17.25 7.5H2.75C2.33579 7.5 2 7.16421 2 6.75ZM2 13.25C2 12.8358 2.33579 12.5 2.75 12.5H17.25C17.6642 12.5 18 12.8358 18 13.25C18 13.6642 17.6642 14 17.25 14H2.75C2.33579 14 2 13.6642 2 13.25Z`})})}function UV(){return(0,W.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,W.jsx)(`path`,{d:`M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z`})})}function WV(){let{tree:e,navState:t,contextNav:n}=WM(),r=Sn(),i=kP();return!e.find(e=>e.id===t.activeL1Id)?.applyFooter||n?.pathname===r.pathname?null:(0,W.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3`,children:(0,W.jsx)(`button`,{type:`button`,onClick:i,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})}function GV({open:e,close:t,onSearch:n,onCreate:r,children:i}){return(0,W.jsxs)(Xe,{open:e,onClose:t,className:`relative z-50 lg:hidden`,children:[(0,W.jsx)(F,{transition:!0,className:`fixed inset-0 bg-black/30 dark:bg-black/30 transition data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in`}),(0,W.jsx)(ce,{transition:!0,className:`fixed inset-y-0 left-0 w-full transition duration-300 ease-out data-closed:-translate-x-full`,children:(0,W.jsx)(OP,{close:t,children:(0,W.jsxs)(`div`,{className:`flex h-full min-h-0 bg-card`,children:[(0,W.jsx)(`div`,{className:`flex h-full w-14 shrink-0 flex-col items-center border-r border-zinc-950/5 bg-background/72 py-3 dark:border-white/5 [&_a]:size-11 [&_button]:size-11`,children:(0,W.jsx)(nB,{onSearch:()=>{t(),n?.()},onCreate:r?()=>{t(),r()}:void 0})}),(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,W.jsx)(`div`,{className:`flex items-center px-4 pt-3`,children:(0,W.jsxs)(et,{as:XL,"aria-label":`Close navigation`,title:`Close navigation`,children:[(0,W.jsx)(UV,{}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Close navigation`})]})}),(0,W.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:i}),(0,W.jsx)(WV,{})]})]})})})]})}function KV({open:e,close:t,children:n}){return(0,W.jsxs)(Xe,{open:e,onClose:t,className:`relative z-50 lg:hidden`,children:[(0,W.jsx)(F,{transition:!0,className:`fixed inset-0 bg-black/30 dark:bg-black/30 transition data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in`}),(0,W.jsx)(ce,{transition:!0,className:`fixed inset-y-0 right-0 w-full transition duration-300 ease-out data-closed:translate-x-full`,children:(0,W.jsx)(OP,{close:t,children:(0,W.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-card`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-end px-4 pt-3`,children:(0,W.jsxs)(et,{as:XL,"aria-label":`Close page options`,title:`Close page options`,children:[(0,W.jsx)(UV,{}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Close page options`})]})}),(0,W.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:n}),(0,W.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3`,children:(0,W.jsx)(`button`,{type:`button`,onClick:t,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})]})})})]})}function qV({navbar:e,sidebar:t,onSearch:n,onCreate:r,secondary:i,pageAction:a,hideDesktopSidebar:o,children:s}){let[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(!1),f=(0,U.useRef)(null),[p,m]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=f.current;if(!e)return;let t=()=>m(t=>{let n=e.childElementCount>0;return t===n?t:n}),n=new MutationObserver(t);return n.observe(e,{childList:!0,subtree:!0}),t(),()=>n.disconnect()},[]);let{streamControls:h}=WM(),g=(0,U.useMemo)(()=>{let e=X(h?.query??``);return!e.error&&Bm(e)&&e.filters.length>0},[h?.query]);return(0,W.jsx)(UB,{children:(0,W.jsx)(zV,{onSearch:n,children:(0,W.jsx)(`div`,{className:`relative isolate flex min-h-svh w-full bg-background max-lg:flex-col lg:flex-row`,children:(0,W.jsxs)(`div`,{className:`flex flex-1 w-full max-lg:flex-col lg:flex-row`,children:[(0,W.jsxs)(`nav`,{"aria-label":`Main`,className:`hidden lg:flex`,children:[(0,W.jsx)(`div`,{className:`w-14 shrink-0 sticky top-0 h-svh flex flex-col items-center border-r border-zinc-950/5 dark:border-white/5 bg-background/72 backdrop-blur-sm z-40 py-3`,children:(0,W.jsx)(nB,{onSearch:n??(()=>{}),onCreate:r})}),(0,W.jsx)(`div`,{className:G(`w-60 shrink-0 sticky top-0 self-start h-svh min-h-0 overflow-hidden border-r border-zinc-950/5 dark:border-white/5 bg-background/72 backdrop-blur-sm flex flex-col`,o&&`lg:hidden`),children:t})]}),(0,W.jsx)(GV,{open:c,close:()=>l(!1),onSearch:n,onCreate:r,children:t}),(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col min-w-0 xl:max-w-[984px] 2xl:max-w-none`,children:[(0,W.jsxs)(`header`,{"data-page-sticky-boundary":`true`,className:`lg:hidden sticky top-0 z-20 flex items-center px-2 sm:px-4 bg-card`,children:[(0,W.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,W.jsxs)(XL,{onClick:()=>l(!0),"aria-label":`Open navigation`,title:`Open navigation`,children:[(0,W.jsx)(HV,{}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Open navigation`})]})}),(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),r&&(0,W.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,W.jsxs)(XL,{onClick:r,"aria-label":`New journal note`,title:`New journal note`,children:[(0,W.jsx)(Jt,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`New journal note`})]})}),p&&(0,W.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,W.jsxs)(XL,{onClick:()=>d(!0),"aria-label":`Open page options`,title:`Open page options`,children:[(0,W.jsxs)(`span`,{className:`relative inline-flex`,children:[(0,W.jsx)(vn,{className:`size-5`}),g&&(0,W.jsx)(`span`,{"data-testid":`drawer-filters-active`,className:`absolute -top-1 -right-1 size-2 rounded-full bg-amber-500`,"aria-hidden":`true`})]}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Open page options`})]})})]}),(0,W.jsxs)(`main`,{className:`flex flex-1 flex-col lg:min-w-0`,children:[(0,W.jsx)(`div`,{className:`grow w-full max-lg:pb-48 lg:overflow-visible`,children:s}),(0,W.jsx)(JV,{})]})]}),(0,W.jsx)(`aside`,{className:`hidden 2xl:flex w-60 shrink-0 sticky top-0 h-svh flex-col overflow-y-auto bg-background/72 backdrop-blur-sm`,children:(0,W.jsx)(`div`,{ref:f,className:`contents`,children:(0,W.jsx)(yV,{spec:i,pageAction:a})})}),(0,W.jsx)(KV,{open:u,close:()=>d(!1),children:(0,W.jsx)(yV,{spec:i,pageAction:a})})]})})})})}function JV(){let e=(0,U.useRef)(null),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=e.current;if(!t)return;let r=new ResizeObserver(e=>{let t=Math.round(e[0]?.contentRect.height??0);n(e=>e===t?e:t)});r.observe(t,{box:`content-box`});let i=Math.round(t.getBoundingClientRect().height);return n(e=>e===i?e:i),()=>r.disconnect()},[]),(0,U.useEffect)(()=>(document.documentElement.style.setProperty(`--thumb-dock-lift`,`${t}px`),()=>document.documentElement.style.setProperty(`--thumb-dock-lift`,`0px`)),[t]),(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:G(`lg:hidden fixed inset-x-0 bottom-0 z-30`,t>0&&`bg-card border-t border-border/50 px-3 py-2`),children:(0,W.jsx)(`div`,{ref:e,className:`w-full min-w-0`,children:(0,W.jsx)(WB,{className:`flex w-full min-w-0`})})}),(0,W.jsx)(`div`,{className:`lg:hidden`,"aria-hidden":`true`,style:{height:t}})]})}function YV(e){let t=e.indexOf(`markdown`);return t!==-1&&e.length>t+2?e[t+2]:`General`}function XV(e){return String(Ky(By(e).meta,`search`)??``).toLowerCase()===`hidden`}function ZV(e){let t=Ky(By(e).meta,`date`);if(typeof t!=`string`||!/^\d{4}-\d{2}-\d{2}$/.test(t))return;let n=new Date(`${t}T12:00:00Z`);return Number.isFinite(n.getTime())&&n.toISOString().slice(0,10)===t?n.getTime():void 0}function QV(e){return Object.entries(e).map(([e,t])=>{let n=e.split(`/`),r=n[n.length-1].replace(`.md`,``),i=t,a=Ky(By(i).meta,`title`);return{id:e,name:r,displayName:typeof a==`string`&&a.trim()?a.trim():EO(r),category:YV(n),content:i,date:ZV(i),searchHidden:XV(i)}})}function $V(){let e=YO();return(0,U.useMemo)(()=>e?QV(e):[],[e])}var eH={};function tH(e){if(!(`payload`in e))return;let t=e.payload;if(!t||typeof t!=`object`)return;let n=t;return n.targetDate??n.updatedAt}function nH(e,t){let{canvasPage:n,workoutItems:r,recentResults:i,selectWorkout:a}=t;if(e===`/`)return[];if(n){let t=/^\/notebook\//.test(e),i=t?e.split(`/`).pop()??null:null,o=[],s=e.startsWith(`/page/guide-`);return n.sections.filter(e=>e.level>1).forEach(e=>{if(o.push({id:e.id,label:e.heading,type:`heading`}),!s){let t=vL(e).split(`
100
+ `).map(e=>e.trim()).filter(Boolean).slice(0,wz).map(e=>e.length>Tz?`${e.slice(0,119)}…`:e)}function Dz(e){let t=xz(Cz(e));return{...t,blockContentId:e.blockContentId??t.blockContentId,block:{blockId:e.blockId,dataType:e.dataType,preview:Ez(e.rawContent)}}}function Oz(e){return e?e.split(`-`).map(e=>{let t=e.toLowerCase();return t===`c2b`?`C2B`:t===`t2b`?`T2B`:t===`ghd`?`GHD`:t===`hspu`?`HSPU`:e.charAt(0).toUpperCase()+e.slice(1)}).join(` `):``}function kz(e){if(!Number.isFinite(e)||e<=0)return`00:00`;let t=Math.floor(e/1e3),n=Math.floor(t/60),r=t%60;if(n>=60){let e=Math.floor(n/60),t=n%60;return`${e}:${String(t).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}return`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}`}function Az(e){if(!e)return`Workout Session`;let t=cz(e);return t.kind===`journal`?t.id?`Journal: ${t.id}`:`Journal Entry`:t.kind===`workout`?Oz(t.id)||t.id:t.id?Oz(t.id):e}function jz(e){let t=[e.baseAttributes?.discipline,e.baseAttributes?.met==null?void 0:`MET ${e.baseAttributes.met.toFixed(1)}`,e.baseAttributes?.intensityTier].filter(Boolean);return{id:e.slug,kind:`effort`,sourceNotebook:e.registrySource??`effort`,sourceNote:e.slug,title:e.label,date:null,subtitle:t.join(` • `),detail:e.aliases&&e.aliases.length>0?`Aliases: ${e.aliases.join(`, `)}`:void 0,effort:{slug:e.slug,label:e.label,discipline:e.baseAttributes?.discipline,met:e.baseAttributes?.met,intensityTier:e.baseAttributes?.intensityTier,aliases:e.aliases,registrySource:e.registrySource}}}function Mz(e){let t=(e.type??``).toLowerCase(),n=(`name`in e&&typeof e.name==`string`?e.name:``).toLowerCase(),r=typeof e.value==`number`?e.value:Number(e.value);return Number.isFinite(r)?t===`rep`||n===`reps`||n===`rep`?{kind:`rep`,val:r}:t===`weight`||t===`load`||n===`load`||n===`weight`||n===`volume`?{kind:`load`,val:r}:t===`distance`||n===`distance`?{kind:`distance`,val:r}:t===`tis`||n===`tis`?{kind:`tis`,val:r}:t===`duration`||n===`duration`?{kind:`duration`,val:r}:null:null}function Nz(e){let t=1/0,n=-1/0,r=0,i=0,a=0,o=0,s=new Set;for(let c of e.events)if(c.outputType===`segment`&&o++,c.effortSlug&&s.add(c.effortSlug),c.timeSpan?.started!=null&&(c.timeSpan.started<t&&(t=c.timeSpan.started),c.timeSpan.ended!=null&&c.timeSpan.ended>n&&(n=c.timeSpan.ended)),Array.isArray(c.metrics))for(let e of c.metrics){let t=Mz(e);t&&(t.kind===`rep`?r+=t.val:t.kind===`load`?i+=t.val:t.kind===`tis`&&t.val>a&&(a=t.val))}return{elapsedMs:Number.isFinite(t)&&Number.isFinite(n)&&n>t?n-t:void 0,reps:r>0?r:void 0,loadLbs:i>0?i:void 0,tis:a>0?a:void 0,segmentCount:o>0?o:void 0,effortSlugs:Array.from(s)}}function Pz(e,t){let n=Nz(e),r=[];n.elapsedMs!=null&&r.push(kz(n.elapsedMs)),n.tis!=null&&r.push(`TIS ${n.tis.toFixed(1)}`),n.loadLbs!=null&&r.push(`Volume: ${n.loadLbs.toLocaleString()} lbs`),n.reps!=null&&r.push(`${n.reps} reps`),n.segmentCount!=null&&r.push(`${n.segmentCount} splits`);let i=n.effortSlugs.map(Oz),a=gP(new Date(e.timestamp)),o=e.events.find(e=>!!e.blockContentId)?.blockContentId;return{id:e.resultId,kind:`result`,sourceNotebook:`results`,sourceNote:e.resultId,title:t?.noteTitle??Az(e.noteId),date:a,blockContentId:o,subtitle:r.join(` • `),detail:i.length>0?i.join(`, `):void 0,execution:{resultId:e.resultId,noteId:e.noteId,timestamp:e.timestamp,outputType:`all`,elapsedMs:n.elapsedMs,reps:n.reps,loadLbs:n.loadLbs,tis:n.tis,segmentCount:n.segmentCount,events:e.events}}}function Fz(e,t){let n;e.timeSpan?.started!=null&&e.timeSpan?.ended!=null&&(n=e.timeSpan.ended-e.timeSpan.started);let r,i,a,o;if(Array.isArray(e.metrics))for(let t of e.metrics){let e=Mz(t);e&&(e.kind===`rep`?r=e.val:e.kind===`load`?i=e.val:e.kind===`distance`?a=e.val:e.kind===`tis`?o=e.val:e.kind===`duration`&&!n&&(n=e.val))}let s=e.outputType===`segment`?`segment`:`event`,c=t?.index??0,l=e.effortSlug?Oz(e.effortSlug):e.outputType===`segment`?`Round ${c+1}`:`${e.outputType.charAt(0).toUpperCase()+e.outputType.slice(1)} ${c+1}`,u=[];n!=null&&u.push(kz(n)),r!=null&&i!=null?u.push(`${r} reps @ ${i} lbs`):r==null?i!=null&&u.push(`${i} lbs`):u.push(`${r} reps`),a!=null&&u.push(`${a}m`),o!=null&&u.push(`TIS ${o.toFixed(1)}`);let d=gP(new Date(e.timestamp));return{id:e.id,kind:s,sourceNotebook:`results`,sourceNote:e.id,title:l,date:d,blockContentId:e.blockContentId,subtitle:u.join(` • `),detail:e.effortSlug?Oz(e.effortSlug):void 0,execution:{resultId:e.resultId,noteId:e.noteId,timestamp:e.timestamp,outputType:e.outputType,effortSlug:e.effortSlug,elapsedMs:n,reps:r,loadLbs:i,distanceMeters:a,tis:o,metrics:e.metrics}}}function Iz(e,t){if(!e||e.error||!e.runs)return[];let n=e.parsed?.filters?.find(e=>e.key===`plane`&&!e.negate),r=e.parsed?.outputType??n?.values[0]?.value;if(r===`segment`){let t=[];for(let n of e.runs){let e=0;for(let r of n.events)r.outputType===`segment`&&t.push(Fz(r,{index:e++}))}return t}if(r&&r!==`all`){let t=[];for(let n of e.runs){let e=0;for(let i of n.events)i.outputType===r&&t.push(Fz(i,{index:e++}))}return t}return e.runs.map(e=>Pz(e,{noteTitle:t?.noteTitles?.get(e.noteId)}))}function Lz(e,t,n){let r=typeof e.__id==`string`&&e.__id?e.__id:void 0,i=typeof e.__resultId==`string`&&e.__resultId?e.__resultId:void 0,a=typeof e.effort==`string`&&e.effort?e.effort:void 0,o=[];for(let[t,n]of Object.entries(e))t.startsWith(`__`)||t===`date`||t===`effort`||(typeof n==`string`||typeof n==`number`||typeof n==`boolean`)&&o.push(`${t}: ${n}`);return{id:r??i??`${t}:${n}`,kind:t,sourceNotebook:`results`,sourceNote:i??r??`${t}:${n}`,title:a?Oz(a):`${t===`segment`?`Segment`:`Event`} ${n+1}`,date:typeof e.date==`string`?e.date:null,subtitle:o.length>0?o.join(` • `):void 0}}function Rz(e,t,n){e&&e({selected:Math.max(t?.selected??0,n.length),matched:n.length})}function zz(e){return typeof e==`object`&&!!e&&`runFind`in e}var Bz=new class e{customService;noteTitleResolver;noteTagsResolver;noteBlockInfo;constructor(e){zz(e)?this.customService=e:(this.customService=e?.service,this.noteTitleResolver=e?.noteTitleResolver,this.noteBlockInfo=e?.noteBlockInfo??!1,this.noteTagsResolver=e?.noteTagsResolver)}get service(){return this.customService??sz}withNoteBlockInfo(){let t=new e({service:this.service,noteTitleResolver:this.noteTitleResolver,noteTagsResolver:this.noteTagsResolver,noteBlockInfo:!0});return Object.prototype.hasOwnProperty.call(this,`query`)&&(t.query=this.query),t}async hydrateEntries(e,t){let n=new Set;for(let r of e)r.sourceNotebook===`journal`&&n.add(r.id),t&&(!r.title||!r.tags||r.tags.length===0)&&n.add(r.id);if(n.size===0)return;let r=await Z.getDetailBatches([...n]);for(let t of e){if(t.sourceNotebook!==`journal`)continue;let e=r.get(t.id),n=Ca(e?.links??[],e?.pages??[]);t.placements=n;let i=wa(n);t.pageId??=i.pageId,i.pageSlug&&(t.pageSlug=i.pageSlug)}if(t)for(let t of e){let e=r.get(t.id);!t.title&&e?.note.title&&(t.title=e.note.title),e&&e.tags.length>0&&((!t.tags||t.tags.length===0)&&(t.tags=e.tags.map(e=>e.label)),t.typedTags=e.tags.map(e=>({label:e.label,type:e.type})))}}async query(e,t){let n=typeof e==`string`?X(e):e;if(!n||n.error)return[];if(Bm(n)){if(n.target===`effort`){let e=this.service.runFindEffort?await this.service.runFindEffort(n):await this.service.runFind(n),r=new Map(e.notes.map(e=>[e.id,e])),i=(e.efforts??[]).map(e=>e.ownerNoteId&&r.has(e.ownerNoteId)?xz(r.get(e.ownerNoteId)):jz(e));return Rz(t,e.stages,i),i}if(n.target===`block`){let e=await this.service.runFind(n),r=e.blocks.map(Dz);return await this.hydrateEntries(r,!0),Rz(t,e.stages,r),r}if(n.target===`session`){let e=await this.service.runFind(n);t?.(e.stages);let r;if(this.noteTitleResolver&&e.runs){r=new Map;for(let t of e.runs)if(!r.has(t.noteId)){let e=await this.noteTitleResolver(t.noteId);e&&r.set(t.noteId,e)}}let i=Iz(e,{noteTitles:r});return Rz(t,e.stages,i),i}if(n.target===`segment`||n.target===`event`){let e=n.target,r=await this.service.runFind(n),i=(r.table?.rows??[]).map((t,n)=>Lz(t,e,n));return Rz(t,r.stages,i),i}let e=await this.service.runFind(n),r=e.notes.map(xz);if(this.noteTagsResolver?(await this.hydrateEntries(r,!1),await Promise.all(r.map(async e=>{if(!e.tags||e.tags.length===0){let t=await this.noteTagsResolver(e.id);t&&t.length>0&&(e.tags=t)}}))):await this.hydrateEntries(r,!0),Rz(t,e.stages,r),this.noteBlockInfo)for(let t=0;t<r.length;t++){let n=r[t],i=e.notes[t];n.excerpt=Ez(i.rawContent);try{Ra(i.rawContent,i.blocks,i.sourceRevision)}catch{continue}let a=Object.values(i.blocks).sort((e,t)=>e.from-t.from).find(e=>e.kind===`wod`),o=a&&Fa(i.rawContent).find(e=>e.from===a.from&&e.scriptBlock);if(a&&o?.scriptBlock){let e=o.scriptBlock.content,t=ba(e);n.wodBlock={blockId:a.id,blockVersion:a.version,blockContentId:t,content:e},n.blockContentId=t}}return r}return[]}};async function Vz(e,t=Bz,n){return t.query(e,n)}function Hz(e){return e?e.map(e=>e.kind===`wql`?`${e.id}|${e.query}|${e.limit??``}`:`s:${e.id}`).join(`;`):``}async function Uz(e){try{let t=(await Vz(e.query)).filter(t=>!e.filterEntry||e.filterEntry(t)).slice(0,e.limit??6).map(t=>({kind:`link`,id:`${e.id}:${t.id}`,label:e.labelFromEntry?e.labelFromEntry(t):t.title,to:e.toEntry?e.toEntry(t):void 0,muted:!0}));return{kind:`section`,id:e.id,label:e.label,entries:t}}catch{return{kind:`section`,id:e.id,label:e.label,entries:[]}}}function Wz(e){let t=Hz(e),n=(0,U.useRef)(e);n.current=e;let[r,i]=(0,U.useState)(()=>e&&!e.some(e=>e.kind===`wql`)?e:[]);return(0,U.useEffect)(()=>{let e=n.current;if(!e){i([]);return}if(!e.some(e=>e.kind===`wql`)){i(e);return}let t=!1;return Promise.all(e.map(e=>e.kind===`wql`?Uz(e):Promise.resolve(e))).then(e=>{t||i(e)}),()=>{t=!0}},[t]),r}function Gz(){let[e]=Kt(`s`,{shallow:!0}),{navState:t}=WM(),n=t.activeL3Id??``;return e||n||``}function Kz({entry:e,active:t,onActivate:n}){let r=e.onRun;return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e),className:G(`group flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left transition-colors`,e.muted?`text-[11.5px]`:`text-[13px]`,t?`bg-primary/10 font-semibold text-primary`:G(`hover:bg-muted/60 hover:text-foreground`,e.muted?`text-muted-foreground/70`:`text-muted-foreground`)),children:[e.icon&&(0,W.jsx)(e.icon,{className:`size-4 shrink-0`}),e.timestamp&&(0,W.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground/60`,children:e.timestamp}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 line-clamp-2 break-words`,title:e.label,children:e.label}),e.badge&&(0,W.jsx)(`span`,{className:`shrink-0 font-mono text-[10px] text-muted-foreground/50`,children:e.badge}),r&&(0,W.jsx)(`span`,{role:`button`,tabIndex:-1,title:e.runIcon===`link`?`View workout`:e.runIcon===`stop`?`Stop workout`:e.runIcon===`edit`?`Edit note`:`Start workout`,onClick:t=>{t.stopPropagation(),e.onRun?.()},className:`flex size-5 shrink-0 items-center justify-center rounded text-primary opacity-0 transition-all group-hover:opacity-100 hover:bg-primary/10`,children:e.runIcon===`link`?(0,W.jsx)(l,{className:`size-3.5`}):e.runIcon===`stop`?(0,W.jsx)(x,{className:`size-3.5`}):e.runIcon===`edit`?(0,W.jsx)(o,{className:`size-3.5`}):(0,W.jsx)(rn,{className:`size-3.5`})})]})}function qz({entries:e,activeId:t,onSection:n}){let r=Vn(),{scrollToSection:i}=WM(),a=e=>{if(n)return n(e);if(e.onRun)return e.onRun();if(e.to)return r(e.to);if(e.sectionId)return i(e.sectionId)};return(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:e.map(e=>e.kind===`section`?e.entries.length===0?null:(0,W.jsxs)(`div`,{className:`mt-1 flex flex-col gap-0.5 first:mt-0`,children:[(0,W.jsx)(`div`,{className:`px-2 pb-1 pt-3 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:e.label}),(0,W.jsx)(qz,{entries:e.entries,activeId:t,onSection:n})]},e.id):e.kind===`wql`?null:(0,W.jsx)(Kz,{entry:e,active:t!=null&&e.sectionId===t,onActivate:a},e.id))})}function Jz(){let e=Vn(),{scrollToSection:t}=WM();return{navigate:(t,n)=>e(t,{replace:n?.replace}),setQueryParam:(e,t)=>{},scrollToSection:t}}function Yz(){let e=Jz(),{openCreateJournal:t}=WM();return n=>{if(n.id===`home-new-journal`){t({mode:`blank`});return}eI(n.action,e)}}function Xz(e,t,n){return e.isActive?e.isActive(n,t):e.action.type===`route`?e.action.to===`/`?n.pathname===`/`||n.pathname===``:n.pathname===e.action.to:e.action.type===`scroll`?t.activeL3Id===e.action.sectionId:e.action.type===`query`&&t.activeL3Id===e.id}function Zz({items:e}){let{navState:t}=WM(),n=Sn(),r=Yz();return(0,W.jsx)(RP,{children:e.map(e=>{if(e.variant===`notable`)return(0,W.jsx)(`div`,{className:`mb-2`,children:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`nav-item-${e.id}`,onClick:()=>r(e),className:`flex w-full items-center justify-center gap-2 rounded-lg bg-primary/10 px-3 py-2 text-xs font-semibold text-primary transition-all hover:bg-primary hover:text-primary-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary shadow-sm`,children:[(0,W.jsx)(On,{className:`size-4 shrink-0`}),(0,W.jsx)(`span`,{children:e.label})]})},e.id);let i=Xz(e,t,n);return e.children&&e.children.length>0?(0,W.jsx)(aI,{title:e.label,count:e.children.length,defaultOpen:e.children.some(e=>Xz(e,t,n)),collapsible:e.id!==`syntax-group`,children:e.children.map(e=>{let i=Xz(e,t,n);return(0,W.jsxs)(zP,{onClick:()=>r(e),current:i,children:[e.icon&&(0,W.jsx)(e.icon,{"data-slot":`icon`}),(0,W.jsx)(BP,{children:e.label})]},e.id)})},e.id):(0,W.jsxs)(zP,{onClick:e.disabled?void 0:()=>r(e),current:i,disabled:e.disabled,"aria-label":e.disabled?`${e.label} (coming soon)`:void 0,className:e.disabled?`opacity-60`:void 0,children:[e.icon&&(0,W.jsx)(e.icon,{"data-slot":`icon`}),(0,W.jsx)(BP,{children:e.disabled?`+`:e.label})]},e.id)})})}function Qz({navSpec:e}){let{tree:t,navState:n,dispatch:r,contextNav:i}=WM(),a=Sn(),o=Wz(e),s=(t??[]).find(e=>e?.id===n.activeL1Id)??null,c=i?.pathname===a.pathname?i:null;return(0,W.jsxs)(FP,{children:[(0,W.jsx)(IP,{children:(0,W.jsx)(`div`,{className:`px-2 pt-3 pb-1 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:s?.label??`Wod Wiki`})}),(0,W.jsxs)(LP,{children:[(()=>{if(c||!s)return null;if(s.panel){let e=s.panel;return(0,W.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,W.jsx)(e,{item:s,navState:n,dispatch:r})})}return s.children&&s.children.length>0?(0,W.jsx)(`div`,{className:`border-b border-border/40 pb-2 mb-2`,children:(0,W.jsx)(Zz,{items:s.children})}):null})(),c?(0,W.jsx)(`div`,{className:`pt-1`,children:(0,W.jsx)(qz,{entries:c.spec})}):o.length>0&&(0,W.jsx)(`div`,{className:`pt-1`,children:(0,W.jsx)(qz,{entries:o})})]})]})}var $z=`0.45.2167`,eB=`https://github.com/bitcobblers/wod-wiki/releases`;function tB(e){return/-pr\.\d+$/.test(e)?eB:`${eB}/tag/v${e}`}function nB({onSearch:e,onCreate:t}){let{tree:n,navState:r,dispatch:i}=WM(),a=Vn(),o=Sn(),s=kP(),c={navigate:(e,t)=>a(e,{replace:t?.replace}),setQueryParam:()=>{},scrollToSection:()=>{}},l=(n??[]).filter(e=>e!=null&&e.icon!=null&&e.id!==`settings`&&e.id!==`buy-me-a-coffee`),u=o.pathname.startsWith(`/settings`),d=o.pathname===`/`||o.pathname===``,f=`pointer-events-none absolute left-full top-1/2 -translate-y-1/2 z-50 ml-2 w-max rounded-md border border-border bg-popover px-2 py-1 text-xs text-popover-foreground opacity-0 shadow-md transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>a(`/`),title:`Home`,"aria-label":`Wod Wiki home`,"aria-current":d?`page`:void 0,className:`group relative mb-3 grid size-8 shrink-0 place-items-center rounded-xl bg-primary text-primary-foreground shadow-md shadow-primary/20 rotate-3`,children:[(0,W.jsx)(se,{size:17}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Home`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Home`})]}),(0,W.jsx)(`nav`,{"aria-label":`Primary`,className:`flex flex-col items-center gap-1.5`,children:l.map(e=>{let t=e.icon,n=Xz(e,r,o);return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{i({type:`SET_ACTIVE_L1`,id:e.id}),eI(e.action,c)},title:e.label,"aria-label":e.label,"aria-current":n?`page`:void 0,className:G(`group relative grid size-9 place-items-center rounded-lg transition-colors`,n?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[n&&(0,W.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,W.jsx)(t,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:e.label}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:e.label})]},e.id)})}),(0,W.jsx)(`div`,{className:`flex-1`}),(0,W.jsxs)(`button`,{type:`button`,onClick:e,title:`Search (⌘/)`,"aria-label":`Search`,className:`group relative grid size-9 place-items-center rounded-lg text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground`,children:[(0,W.jsx)(en,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Search`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Search (⌘/)`})]}),(0,W.jsxs)(`a`,{href:oL,target:`_blank`,rel:`noopener noreferrer`,title:`Buy Me a Coffee`,"aria-label":`Buy Me a Coffee`,className:`group relative grid size-9 place-items-center rounded-lg text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground`,children:[(0,W.jsx)(sL,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Buy Me a Coffee`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Buy Me a Coffee`})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{s(),a(`/settings/profile`)},title:`Profile`,"aria-label":`Profile`,"aria-current":o.pathname.startsWith(`/settings/profile`)?`page`:void 0,"data-testid":`nav-profile`,className:G(`group relative grid size-9 place-items-center rounded-lg transition-colors mt-1.5`,o.pathname.startsWith(`/settings/profile`)?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[o.pathname.startsWith(`/settings/profile`)&&(0,W.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,W.jsx)(Me,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Profile`}),(0,W.jsx)(`span`,{role:`tooltip`,className:f,children:`Profile`})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>{s(),a(`/settings/appearance`)},title:`Settings`,"aria-label":`Settings`,"aria-current":u?`page`:void 0,"data-testid":`nav-settings`,className:G(`group relative grid size-9 place-items-center rounded-lg transition-colors mt-1.5`,u?`bg-primary/10 text-primary`:`text-muted-foreground hover:bg-muted/60 hover:text-foreground`),children:[u&&(0,W.jsx)(`span`,{className:`absolute -left-[14px] top-1/2 h-5 w-[3px] -translate-y-1/2 rounded-r-full bg-primary`}),(0,W.jsx)(gt,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Settings`}),(0,W.jsxs)(`span`,{role:`tooltip`,className:`pointer-events-none absolute bottom-0 left-full z-50 ml-2 w-max rounded-md border border-border bg-popover px-2 py-1 text-xs text-popover-foreground opacity-0 shadow-md transition-opacity group-focus-within:opacity-100 group-hover:opacity-100`,children:[`Settings (v`,$z,`)`]})]})]})}function rB({activations:e,activeSection:t,variant:n,deps:r,className:i}){return(0,W.jsx)(`nav`,{className:G(`lg:sticky z-20 flex items-center gap-1 px-4 py-2 bg-background/95 backdrop-blur-sm border-b border-border/50 overflow-x-auto`,n===`top-fixed`?`lg:top-0`:`lg:top-[104px]`,i),children:e.map(e=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,r),className:G(`px-3 py-1.5 rounded-full text-[10px] font-black uppercase tracking-[0.12em] whitespace-nowrap transition-all ring-1`,t===e.id?`bg-primary text-primary-foreground ring-primary/30 shadow-md`:`bg-muted/50 text-muted-foreground ring-transparent hover:bg-muted hover:ring-border`),children:e.label},e.id))})}var iB=class e{now;name=`tick`;timestamp;data;static _counter=0;constructor(t,n=wl){this.now=n;let r=this.now.nowMs();e._counter++,this.timestamp=new Date(r+e._counter),this.data=t}},aB=20,oB=e=>{let[t,n]=(0,U.useState)(`idle`),[r,i]=(0,U.useState)(0),[a,o]=(0,U.useState)(0),[s,c]=(0,U.useState)(null),l=(0,U.useRef)(null),u=(0,U.useRef)(null),d=(0,U.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),n(`idle`)},[]),f=(0,U.useCallback)(()=>{if(e)try{let t=new iB(void 0,e.nowProvider);e.handle(t),o(e=>e+1)}catch{d(),n(`error`)}},[e,d]);(0,U.useEffect)(()=>{if(e)return e.subscribeToStack(e=>{e.blocks.length===0&&t!==`completed`&&(l.current&&=(clearInterval(l.current),null),n(`completed`))})},[e,t]),(0,U.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]);let p=(0,U.useCallback)(()=>{if(!e){console.warn(`useRuntimeExecution: Cannot start execution without a runtime`);return}if(t===`running`){console.warn(`useRuntimeExecution: Runtime is already running`);return}t===`paused`&&e.handle({name:`timer:resume`,timestamp:new Date,data:{}}),n(`running`);let i=e?.nowProvider?.nowMs()??wl.nowMs();u.current=i-r,r===0&&c(i),l.current=setInterval(f,aB)},[e,t,r,f]),m=(0,U.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),e&&e.handle({name:`timer:pause`,timestamp:new Date,data:{}}),n(`paused`)},[e]),h=(0,U.useCallback)(()=>{l.current&&=(clearInterval(l.current),null),i(0),o(0),n(`idle`),c(null),u.current=null},[e]),g=(0,U.useCallback)(()=>{!e||t===`running`||(n(`paused`),f())},[e,t,f]);return(0,U.useEffect)(()=>{if(t!==`running`||!u.current)return;let n=setInterval(()=>{i((e?.nowProvider?.nowMs()??wl.nowMs())-u.current)},100);return()=>clearInterval(n)},[t,e?.nowProvider]),(0,U.useEffect)(()=>()=>{l.current&&=(clearInterval(l.current),null)},[]),(0,U.useEffect)(()=>{h()},[e,h]),(0,U.useMemo)(()=>({status:t,elapsedTime:r,stepCount:a,startTime:s,start:p,pause:m,stop:d,reset:h,step:g}),[t,r,a,s,p,m,d,h,g])},sB=(e,t)=>!e||!Array.isArray(e)?0:e.reduce((e,n)=>{if(`started`in n){let r=n.started,i=n.ended??t;return e+Math.max(0,i-r)}let r=n.start instanceof Date?n.start.getTime():n.start||0,i=n.stop?n.stop instanceof Date?n.stop.getTime():n.stop:t;return e+Math.max(0,i-r)},0);function cB(e,t){let n=t,r=()=>{let t=e?.getMemoryByTag(n)[0];if(t)return n===`round`?t.metrics[0]:t.metrics[0]?.value},[i,a]=(0,U.useState)(r);return(0,U.useEffect)(()=>{if(!e){a(void 0);return}a(r());let t=e.getMemoryByTag(n)[0];if(t)return t.subscribe(e=>{a(n===`round`?e[0]:e[0]?.value)})},[e,t]),i}function lB(e){return cB(e,`round`)}function uB(e){return cB(e,`display`)}function dB(e){let t=lB(e),n=uB(e);return(0,U.useMemo)(()=>{if(!t)return null;let e=n?.roundDisplay??(t.total===void 0?`Round ${t.current}`:`Round ${t.current} of ${t.total}`),r=t.total===void 0?void 0:Math.min(1,(t.current-1)/t.total);return{current:t.current,total:t.total,label:e,progress:r}},[t,n?.roundDisplay])}var fB=(0,U.createContext)(void 0),pB=({runtime:e,children:t})=>(0,W.jsx)(fB.Provider,{value:e,children:t});function mB(){let e=(0,U.useContext)(fB);if(!e)throw Error(`useScriptRuntime must be used within ScriptRuntimeProvider`);return e}function hB(e){let t=mB(),n=e===void 0?t:e,[r,i]=(0,U.useState)(()=>n?.getOutputStatements?.()??[]);return(0,U.useEffect)(()=>{if(!n){i([]);return}return i(n.getOutputStatements()),n.subscribeToOutput?.(()=>{i(n.getOutputStatements())})},[n]),(0,U.useMemo)(()=>{let e=new Map,t=new Map,n=[],i=[];for(let a of r){e.set(a.id,a);let r=t.get(a.sourceBlockKey)??[];switch(r.push(a),t.set(a.sourceBlockKey,r),a.outputType){case`segment`:n.push(a);break;case`metric`:i.push(a)}}let a=n.filter(e=>e.completionReason!==void 0);return{outputs:r,byId:e,byBlockKey:t,segments:n,completions:a,metrics:i}},[r])}function gB(e){let t=mB(),n=e===void 0?t:e,[r,i]=(0,U.useState)(()=>n?.getLiveAnalytics?.()??[]);return(0,U.useEffect)(()=>{if(!n){i([]);return}return i(n.getLiveAnalytics?.()??[]),n.subscribeToOutput?.(()=>{i(n.getLiveAnalytics?.()??[])})},[n]),r}function _B(){let e=mB(),[t,n]=(0,U.useState)({type:`initial`,blocks:e.stack.blocks,depth:e.stack.count,clockTime:e.clock.currentDate});return(0,U.useEffect)(()=>e.subscribeToStack(e=>{n(e)}),[e]),t}function vB(){return _B().blocks}function yB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`metric:next`);for(let r of e){let e=r.subscribe(()=>{n(e=>e+1)});t.push(e)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{for(let t of e){let e=t.getMemoryByTag(`metric:next`);if(e.length===0)continue;let n=J.empty(t.key.toString());for(let t of e)n.merge(t.metrics);if(n.length>0)return{metrics:n,block:t}}return null},[e,t])}function bB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`time`)[0];if(e){let r=e.subscribe(()=>{n(e=>e+1)});t.push(r)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{let t=[];for(let n of e){let e=n.getMemoryByTag(`time`)[0];if(!e)continue;let r=e.metrics[0]?.value;r&&t.push({block:n,timer:r,isPinned:r.role===`primary`})}return t},[e,t])}function xB(){let e=bB();return(0,U.useMemo)(()=>{if(e.length===0)return;let t=e[0];return t.block.blockType===`Rest`?t:[...e].reverse().find(e=>e.isPinned)||t},[e])}function SB(){let e=bB(),t=xB();return(0,U.useMemo)(()=>t?e.filter(e=>e.block!==t.block):[],[e,t])}function CB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`controls`);for(let r of e){let e=r.subscribe(()=>{n(e=>e+1)});t.push(e)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{let t=[],n=[];for(let r=0;r<e.length;r++){let i=e[r].getMemoryByTag(`controls`);if(i.length===0)continue;let a=i[0].metrics.map(e=>e.value).filter(Boolean),o=r===e.length-1;for(let e of a)e.isPinned?t.push(e):o&&n.push(e)}let r=new Set,i=[];for(let e of t)r.has(e.id)||(r.add(e.id),i.push(e));for(let e of n)r.has(e.id)||(r.add(e.id),i.push(e));return i},[e,t])}function wB(){let e=vB(),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=[];for(let r of e){let e=r.getMemoryByTag(`metric:display`);for(let r of e){let e=r.subscribe(()=>{n(e=>e+1)});t.push(e)}}return()=>{t.forEach(e=>e())}},[e]),(0,U.useMemo)(()=>{if(e.length===0)return;let t=[],n=[...e].reverse();return n.forEach((e,r)=>{if(e.blockType===`Root`&&!e.label)return;let i=e.getMemoryByTag(`metric:display`),a=i.map(e=>e.metrics);if(a.length===0&&!e.label)return;let o=r===n.length-1,s=i.length>1?i.map(e=>e.metrics):void 0;t.push({block:e,displayRows:a,label:e.label,depth:r,isLeaf:o,metricGroups:s})}),t.length>0?t:void 0},[e,t])}function TB(e){let t=mB(),n=(0,U.useMemo)(()=>t.stack.blocks.find(t=>t.key.toString()===e),[t,e]),[r,i]=(0,U.useState)(()=>n?.getMemoryByTag(`time`)[0]?.metrics[0]?.value);(0,U.useEffect)(()=>t.stack.subscribe(()=>{let n=t.stack.blocks.find(t=>t.key.toString()===e);if(n){let e=n.getMemoryByTag(`time`)[0];i(e?.metrics[0]?.value)}else i(void 0)}),[t,e]),(0,U.useEffect)(()=>{if(!n){i(void 0);return}let e=n.getMemoryByTag(`time`)[0];if(i(e?.metrics[0]?.value),e)return e.subscribe(e=>{i(e[0]?.value)})},[n]);let a=(0,U.useMemo)(()=>r?.spans??[],[r]),o=a.length>0&&a[a.length-1].ended===void 0,[s,c]=(0,U.useState)(fu()),l=(0,U.useMemo)(()=>a.length===0?0:sB(a,s),[a,s]);return(0,U.useEffect)(()=>{if(!o)return;let e,t=()=>{c(fu()),e=requestAnimationFrame(t)};return t(),()=>cancelAnimationFrame(e)},[o]),{elapsed:l,isRunning:o,timeSpans:a}}var EB=(0,U.createContext)(void 0),DB=(0,U.createContext)(null),OB={getState:()=>PR().getState(),setState:(e,t)=>{let n=PR();typeof e==`function`?n.setState(e(n.getState()),t):n.setState(e,t)},subscribe:e=>PR().subscribe(e)},kB=({factory:e,children:t})=>{let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null),u=(0,U.useRef)(e);u.current=e;let d=(0,U.useRef)(null),f=(0,U.useRef)(null),p=(0,U.useRef)(!1),m=(0,U.useCallback)(()=>{f.current&&=(f.current.dispose(),null),a(null),OB.getState().setSubscriptionManager(null);let e=d.current;if(d.current=null,e)try{u.current.disposeRuntime(e)}catch(e){console.error(`[RuntimeProvider] Error disposing runtime:`,e)}r(null),l(null)},[]),h=(0,U.useCallback)((e,t)=>{if(!p.current){p.current=!0,s(!0),l(null);try{f.current&&=(f.current.dispose(),null);let n=d.current;if(d.current=null,n)try{u.current.disposeRuntime(n)}catch(e){console.error(`[RuntimeProvider] Error disposing existing runtime:`,e)}let i=u.current.createRuntime(e,t);if(d.current=i,r(i),i){let e=new wp(i);e.add(new Cp({id:`local`})),f.current=e,a(e),OB.getState().setSubscriptionManager(e)}else f.current=null,a(null),OB.getState().setSubscriptionManager(null)}catch(e){console.error(`[RuntimeProvider] Error creating runtime:`,e),l(e instanceof Error?e:Error(String(e))),d.current=null}finally{p.current=!1,s(!1)}}},[]);(0,U.useEffect)(()=>()=>{if(f.current&&f.current.dispose(),d.current)try{u.current.disposeRuntime(d.current)}catch(e){console.error(`[RuntimeProvider] Error disposing runtime on unmount:`,e)}},[]);let g={runtime:n,isInitializing:o,error:c,initializeRuntime:h,disposeRuntime:m};return(0,W.jsx)(EB.Provider,{value:g,children:(0,W.jsx)(DB.Provider,{value:i,children:t})})};function AB({factory:e,children:t}){return(0,W.jsx)(kB,{factory:e,children:t})}var jB=`bg-background ring-1 ring-zinc-950/5 shadow-sm lg:shadow-[-18px_0_36px_-28px_rgba(15,23,42,0.16),18px_0_36px_-28px_rgba(15,23,42,0.16)] dark:shadow-none dark:ring-white/10`,MB=`flex flex-col flex-1 min-w-0 xl:max-w-[984px] 2xl:max-w-none min-h-screen lg:rounded-[2.5rem]`;function NB({id:e,title:t,subtitle:n,titleAccessory:r,actions:i,queryBar:a,subheader:o,titleTestId:s,className:c}){return(0,W.jsxs)(`div`,{id:e,"data-page-sticky-boundary":`true`,className:G(`max-lg:hidden lg:sticky lg:top-0 z-30 bg-background/80 backdrop-blur-md transition-colors`,c),children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-4 sm:px-6 lg:px-8 py-2 sm:py-2.5`,children:[t&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5 sm:gap-3 min-w-0`,children:[(0,W.jsx)(`div`,{className:`h-5 w-1.5 shrink-0 rounded-full bg-primary`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`h1`,{"data-testid":s,className:`text-base sm:text-lg font-black tracking-tight text-foreground leading-none truncate`,children:t}),n&&(0,W.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground truncate`,children:n})]}),r]})]}),a&&(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:a}),i&&(0,W.jsx)(`div`,{className:`flex items-center gap-1.5 sm:gap-2 shrink-0 ml-auto`,children:i})]}),o&&(0,W.jsx)(`div`,{className:`bg-background/40`,children:o})]})}function PB({ids:e,enabled:t=!0,rootMargin:n=`-10% 0px -40% 0px`,threshold:r=[0,.3,1],onChange:i,shouldAcceptChange:a,scrollDirection:o=`ratio`,dataAttribute:s,debounceMs:c=0}){let l=(0,U.useRef)(``),u=(0,U.useRef)(i),d=(0,U.useRef)(a),f=(0,U.useRef)(null),p=(0,U.useRef)(1);(0,U.useEffect)(()=>{u.current=i},[i]),(0,U.useEffect)(()=>{d.current=a},[a]);let m=e.filter(Boolean).join(`\0`),h=r.join(`,`),g=(0,U.useMemo)(()=>m?m.split(`\0`):[],[m]),_=(0,U.useMemo)(()=>h.split(`,`).map(Number),[h]),v=(0,U.useCallback)(()=>{f.current&&=(clearTimeout(f.current),null)},[]);(0,U.useEffect)(()=>{if(!t||g.length===0||typeof IntersectionObserver>`u`)return;let e=new Map,r=e=>s?e.getAttribute(s):e.id||null,i;if(o===`topmost-when-up`){let e=window.scrollY,t=()=>{let t=window.scrollY;t!==e&&(p.current=t>e?1:-1),e=t};window.addEventListener(`scroll`,t,{passive:!0}),i=()=>window.removeEventListener(`scroll`,t)}let a=new IntersectionObserver(t=>{if(t.forEach(t=>{let n=r(t.target);n&&(t.isIntersecting?e.set(n,t.intersectionRatio):e.delete(n))}),e.size===0)return;let n=``;if(o===`topmost-when-up`&&p.current===-1){let t=1/0;e.forEach((e,r)=>{let i=g.indexOf(r);i>=0&&i<t&&(t=i,n=r)})}else{let t=-1;e.forEach((e,r)=>{e>t&&(t=e,n=r)})}!n||n===l.current||d.current&&!d.current(n)||(l.current=n,c>0?(v(),f.current=setTimeout(()=>{u.current(n),f.current=null},c)):u.current(n))},{rootMargin:n,threshold:_});return g.forEach(e=>{let t=s?document.querySelector(`[${s}="${e}"]`):document.getElementById(e);t&&a.observe(t)}),()=>{a.disconnect(),v(),i?.()}},[t,g,_,n,o,s,c,v])}function FB({title:e,titleAccessory:t,actions:n,subheader:r,children:i,index:a=[],activeSectionId:o,hero:s,sections:c,className:l}){let u=!!(c&&c.length>0)&&!e,[,d]=Kt(`s`,{defaultValue:o??a[0]?.id??``,shallow:!0,history:`replace`}),[f,p]=(0,U.useState)(c?.[0]?.id??``);if(PB({ids:a.map(e=>e.id),enabled:!u&&a.length>0,rootMargin:`-10% 0px -40% 0px`,threshold:[0,.3,1],onChange:e=>{d(e)},shouldAcceptChange:()=>!0}),PB({ids:c?.map(e=>e.id)??[],enabled:u,rootMargin:`-20% 0px -50% 0px`,threshold:[0,.25,.5,.75],onChange:p}),u){let e=c.map(e=>({id:e.id,label:e.label,action:{type:`scroll`,sectionId:e.id}}));return(0,W.jsxs)(`div`,{className:G(`flex flex-col min-h-screen bg-background`,l),children:[s,(0,W.jsx)(rB,{activations:e,activeSection:f,variant:`top-fixed`,deps:{navigate:()=>{},setQueryParam:()=>{},scrollToSection:e=>{let t=document.getElementById(e);if(t){let e=t.getBoundingClientRect().top+window.scrollY-64;window.scrollTo({top:e,behavior:`smooth`})}}}}),(0,W.jsx)(`div`,{className:`flex-1`,children:c.map(e=>{let t=(0,W.jsx)(`div`,{id:e.id,"data-section-id":e.id,className:`py-12 lg:py-16 px-6 lg:px-10 border-b border-border/30`,children:e.content},e.id);return e.runtimeFactory?(0,W.jsx)(AB,{factory:e.runtimeFactory,children:t},e.id):t})})]})}return(0,W.jsx)(`div`,{className:G(`relative flex w-full min-h-screen justify-start items-start`,l),children:(0,W.jsxs)(`div`,{className:G(MB,jB),children:[(0,W.jsx)(NB,{title:e,titleAccessory:t,actions:n,subheader:r}),(0,W.jsx)(`div`,{className:`flex-1`,children:i})]})})}var IB=`[data-page-sticky-boundary="true"]`,LB=0;function RB(e,t=LB){if(typeof document>`u`)return e;let n=Array.from(document.querySelectorAll(IB)).reduce((e,t)=>{let n=t.getBoundingClientRect();return n.height<=0||n.bottom<=0?e:Math.max(e,n.bottom)},0);return n>0?n+t:e}function zB(e,t=LB){let[n,r]=(0,U.useState)(e);return(0,U.useEffect)(()=>{let n=0,i=()=>{cancelAnimationFrame(n),n=requestAnimationFrame(()=>r(RB(e,t)))};return i(),window.addEventListener(`scroll`,i,{passive:!0}),window.addEventListener(`resize`,i),()=>{cancelAnimationFrame(n),window.removeEventListener(`scroll`,i),window.removeEventListener(`resize`,i)}},[e,t]),n}function BB({top:e,label:t,icon:n,badge:r,meta:i,testId:a,className:o}){return(0,W.jsxs)(`div`,{"data-testid":a,className:G(`sticky z-10 flex items-center gap-2 border-y border-border/60 bg-card/95 px-6 py-2 shadow-[0_1px_2px_rgba(0,0,0,0.03)] backdrop-blur`,o),style:{top:`${e}px`},children:[n,(0,W.jsx)(`span`,{className:`min-w-0 truncate text-xs font-bold text-foreground`,children:t}),r,i&&(0,W.jsx)(`span`,{className:`ml-auto shrink-0 pl-2 font-mono text-[10px] text-muted-foreground`,children:i})]})}var VB=(0,U.createContext)(null),HB=(0,U.createContext)(null);function UB({children:e}){let[t,n]=(0,U.useState)(null);return(0,W.jsx)(HB.Provider,{value:n,children:(0,W.jsx)(VB.Provider,{value:t,children:e})})}function WB({className:e}){let t=(0,U.useContext)(HB);return(0,W.jsx)(`div`,{ref:t,className:e,"data-testid":`mobile-query-slot`})}function GB(){return(0,U.useContext)(VB)}function KB({editor:e,title:t,subtitle:n,titleTestId:r,actions:i,timerOverlay:a,reviewOverlay:o,isTimerOpen:s=!1,isReviewOpen:c=!1,onCloseTimer:l,onCloseReview:u,className:d}){return(0,W.jsxs)(`div`,{className:G(`relative flex w-full min-h-screen justify-start items-start`,d),children:[(0,W.jsxs)(`div`,{className:G(MB,jB),children:[(0,W.jsx)(NB,{title:t,subtitle:n,titleTestId:r,actions:i}),(0,W.jsx)(`main`,{className:`flex-1 min-w-0 max-w-full`,children:e})]}),s&&a&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,W.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,W.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,W.jsx)(`button`,{onClick:l,className:`px-3 py-1.5 rounded-md text-sm font-bold text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted transition-colors`,children:`Close`})}),(0,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:a})]})}),c&&o&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 bg-background/95 backdrop-blur-sm`,children:(0,W.jsxs)(`div`,{className:`w-full h-full flex flex-col`,children:[(0,W.jsx)(`div`,{className:`flex justify-end p-4`,children:(0,W.jsx)(`button`,{onClick:u,className:`px-3 py-1.5 rounded-md text-sm font-bold text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted transition-colors`,children:`Close`})}),(0,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:o})]})})]})}function qB(e){return e.map(e=>{let t=e.action,n=e.secondaryAction?.action,r={kind:`link`,id:e.id,label:e.label};return n&&n.type===`call`&&(r.onRun=n.handler,r.runIcon=e.secondaryRunIcon??`play`),t.type===`route`?{...r,to:t.to}:t.type===`scroll`?{...r,sectionId:t.sectionId}:t.type===`call`?{...r,onRun:t.handler}:r})}var JB=U.createContext(null);function YB(){let e=U.useContext(JB);if(!e)throw Error(`DropdownMenu components must be used inside a DropdownMenu`);return e}function XB(){let e=U.useContext(JB);return U.useCallback(()=>{e?.setIsOpen(!1)},[e])}var ZB=({children:e,open:t,onOpenChange:n})=>{let r=U.useContext(JB),i=U.useId(),a=r?`${r.portalChain}/${i}`:i,[o,s]=U.useState(t??!1),c=U.useRef(null),[l,u]=U.useState(-1),d=U.useRef(new Map),[,f]=U.useReducer(e=>e+1,0);U.useEffect(()=>{t!==void 0&&s(t)},[t]);let p=U.useCallback(e=>{s(e),u(-1),n?.(e)},[n]),m=U.useCallback((e,t)=>{d.current.set(e,t),f()},[]),h=U.useCallback(e=>{d.current.delete(e),f()},[]),g=U.useCallback(e=>Array.from(d.current.keys()).indexOf(e),[]),_=d.current.size,v=U.useMemo(()=>({isOpen:o,setIsOpen:p,triggerRef:c,registerItem:m,unregisterItem:h,getItemIndex:g,activeIndex:l,setActiveIndex:u,itemCount:_,menuId:i,portalChain:a}),[o,p,m,h,g,l,_,i,a]);return(0,W.jsx)(JB.Provider,{value:v,children:(0,W.jsx)(`div`,{ref:c,className:`relative inline-block`,children:e})})},QB=U.forwardRef(({className:e,children:t,asChild:n,...r},i)=>{let{isOpen:a,setIsOpen:o}=YB(),s=e=>{e.stopPropagation(),o(!a)};return n&&U.isValidElement(t)?U.cloneElement(t,{...r,onClick:s}):(0,W.jsx)(`button`,{ref:i,className:e,onClick:s,...r,children:t})});QB.displayName=`DropdownMenuTrigger`;var $B=U.forwardRef(({className:e,children:t,align:n=`center`,side:r=`bottom`,...i},a)=>{let{isOpen:o,setIsOpen:s,triggerRef:c,setActiveIndex:l,itemCount:u,menuId:d,portalChain:f}=YB(),p=U.useRef(null),m=a||p,[h,g]=U.useState({top:0,bottom:0,left:0,width:0}),_=r===`bottom`,[v,y]=U.useState(!1);U.useEffect(()=>{if(!o||!c.current)return;let e=c.current.getBoundingClientRect();g({top:e.bottom+8,bottom:window.innerHeight-e.top+8,left:e.left,width:e.width}),y(!1)},[o,c]),U.useLayoutEffect(()=>{if(!o||!_||!m.current)return;let e=m.current.getBoundingClientRect();y(h.top+e.height>window.innerHeight)},[o,_,h.top]),U.useEffect(()=>{if(!o||u===0)return;let e=setTimeout(()=>{l(0)},0);return()=>clearTimeout(e)},[o,u,l]),U.useEffect(()=>{if(!o)return;let e=e=>{let t=e.target;if(m.current&&m.current.contains(t)||c.current&&c.current.contains(t))return;let n=t.closest?.(`[data-dropdown-chain]`)?.getAttribute(`data-dropdown-chain`);n&&n.split(`/`).includes(d)||s(!1)},t=setTimeout(()=>{document.addEventListener(`mousedown`,e)},0);return()=>{clearTimeout(t),document.removeEventListener(`mousedown`,e)}},[o,s,m,c,d]);let b=e=>{if(u!==0)switch(e.key){case`ArrowDown`:e.preventDefault(),l(e=>e<u-1?e+1:0);break;case`ArrowUp`:e.preventDefault(),l(e=>e>0?e-1:u-1);break;case`Home`:e.preventDefault(),l(0);break;case`End`:e.preventDefault(),l(u-1);break;case`Escape`:e.preventDefault(),s(!1),c.current?.querySelector(`button`)?.focus();break;case`Tab`:s(!1)}};if(!o)return null;let x={position:`fixed`,zIndex:9999};return r===`top`||v?x.bottom=h.bottom:x.top=h.top,n===`end`?x.right=window.innerWidth-h.left-h.width:n===`start`?x.left=h.left:(x.left=h.left+h.width/2,x.transform=`translateX(-50%)`),TC.createPortal((0,W.jsx)(`div`,{ref:m,role:`menu`,"data-dropdown-chain":f,className:G(`min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95`,e),style:x,onKeyDown:b,...i,children:t}),document.body)});$B.displayName=`DropdownMenuContent`;var eV=U.forwardRef(({className:e,disabled:t,inset:n,onClick:r,onKeyDown:i,...a},o)=>{let{setIsOpen:s,registerItem:c,unregisterItem:l,getItemIndex:u,activeIndex:d}=YB(),f=U.useId(),p=U.useRef(null),m=U.useCallback(e=>{p.current=e,typeof o==`function`?o(e):o&&(o.current=e)},[o]);U.useEffect(()=>(c(f,p),()=>l(f)),[f,c,l]);let h=u(f)===d;return U.useEffect(()=>{h&&p.current?.focus()},[h]),(0,W.jsx)(`div`,{ref:m,role:`menuitem`,tabIndex:t?-1:h?0:-1,"aria-disabled":t,"data-active":h?`true`:void 0,className:G(`relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors`,`focus:bg-accent focus:text-accent-foreground`,`data-[active]:bg-accent data-[active]:text-accent-foreground`,n&&`pl-8`,t&&`pointer-events-none opacity-50`,e),onClick:e=>{t||(r?.(e),s(!1))},onKeyDown:e=>{t||(i?.(e),(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),r?.(e),s(!1)))},...a})});eV.displayName=`DropdownMenuItem`;var tV=U.forwardRef(({className:e,inset:t,...n},r)=>(0,W.jsx)(`div`,{ref:r,className:G(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));tV.displayName=`DropdownMenuLabel`;var nV=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(`div`,{ref:n,className:G(`-mx-1 my-1 h-px bg-muted`,e),...t}));nV.displayName=`DropdownMenuSeparator`;function rV({className:e,children:t,...n}){return(0,W.jsx)(`div`,{className:G(`px-2 py-1.5 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,e),...n,children:t})}var iV=[{label:`Past 1 week`,value:`last 1w`},{label:`Past 2 weeks`,value:`last 2w`},{label:`Past 4 weeks`,value:`last 4w`},{label:`Past 8 weeks`,value:`last 8w`},{label:`Past 12 weeks`,value:`last 12w`},{label:`Past 1 year`,value:`last 52w`},{label:`All time`,value:`all`}],aV=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function oV(e,t){return new Date(e,t+1,0).getDate()}function sV(e,t){let n=new Date(e,t,1).getDay();return n===0?6:n-1}function cV(e,t){let n=X(e);if(n.error)return e;if(!t||t===`all`)return jh({...n,window:void 0});let r=X(`:note ${t}`);return r.error||r.family!==`find`||!r.window?e:jh({...n,window:r.window})}function lV(e){let t=X(e);return t.error||t.family===`pipeline`?null:`window`in t?t.window??null:null}function uV({query:e,onQueryChange:t,highlightDates:n=new Set,className:r}){let i=(0,U.useMemo)(()=>lV(e),[e]),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(()=>new Date),l=s.getFullYear(),u=s.getMonth(),d=(0,U.useMemo)(()=>i?i.kind===`relative`?`last ${i.size}${i.unit}`:i.end?`from ${i.start} to ${i.end}`:`from ${i.start}`:`All time`,[i]),f=(0,U.useMemo)(()=>{if(!i)return null;if(i.kind===`range`)return{start:i.start,end:i.end??i.start};let e=new Date,t=new Date;return i.unit===`d`?t.setDate(e.getDate()-i.size):t.setDate(e.getDate()-i.size*7),{start:gP(t),end:gP(e)}},[i]),p=(0,U.useMemo)(()=>{let e=oV(l,u),t=sV(l,u),n=[];for(let e=0;e<t;e++)n.push(null);for(let t=1;t<=e;t++)n.push(t);return n},[l,u]),m=n=>{if(!a)o(n),t(cV(e,`from ${n} to ${n}`));else{let[r,i]=a<=n?[a,n]:[n,a];o(null),t(cV(e,`from ${r} to ${i}`))}},h=e=>{e.stopPropagation(),c(new Date(l,u-1,1))},g=e=>{e.stopPropagation(),c(new Date(l,u+1,1))},_=s.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`}),v=gP(new Date);return(0,W.jsxs)(`div`,{className:G(`relative inline-flex items-center`,r),children:[(0,W.jsxs)(ZB,{children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`wql-window-picker-trigger`,className:`flex h-9 items-center gap-1.5 rounded-lg border border-border bg-background px-2.5 text-xs font-medium text-foreground transition-colors hover:bg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[(0,W.jsx)(mn,{className:`size-3.5 text-muted-foreground`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:d}),(0,W.jsx)(Et,{className:`size-3 text-muted-foreground`,"aria-hidden":`true`})]})}),(0,W.jsxs)($B,{align:`end`,className:`w-72 p-3`,children:[(0,W.jsx)(`div`,{className:`mb-3 flex flex-wrap gap-1 border-b border-border/60 pb-2`,children:iV.map(n=>{let r=n.value===`all`?!i:i?.kind===`relative`&&`last ${i.size}${i.unit}`===n.value;return(0,W.jsx)(`button`,{type:`button`,"data-testid":`wql-window-preset-${n.value}`,onClick:()=>{o(null),t(cV(e,n.value))},className:G(`rounded-md px-2 py-1 text-[11px] font-medium transition-colors`,r?`bg-primary text-primary-foreground`:`bg-muted/50 text-muted-foreground hover:bg-muted hover:text-foreground`),children:n.label},n.value)})}),(0,W.jsxs)(`div`,{className:`mb-2 flex items-center justify-between`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:h,"data-testid":`wql-calendar-prev-month`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":`Previous month`,children:(0,W.jsx)(Un,{className:`size-4`})}),(0,W.jsx)(`span`,{className:`text-xs font-semibold text-foreground`,children:_}),(0,W.jsx)(`button`,{type:`button`,onClick:g,"data-testid":`wql-calendar-next-month`,className:`rounded p-1 text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,"aria-label":`Next month`,children:(0,W.jsx)(wn,{className:`size-4`})})]}),(0,W.jsx)(`div`,{className:`mb-1 grid grid-cols-7 gap-1`,children:aV.map(e=>(0,W.jsx)(`div`,{className:`text-center text-[10px] font-medium text-muted-foreground`,children:e},e))}),(0,W.jsx)(`div`,{className:`grid grid-cols-7 gap-1`,"data-testid":`wql-calendar-grid`,children:p.map((e,t)=>{if(e===null)return(0,W.jsx)(`div`,{className:`size-8`},`empty-${t}`);let r=`${l}-${String(u+1).padStart(2,`0`)}-${String(e).padStart(2,`0`)}`,i=f&&r>=f.start&&r<=f.end,o=f&&r===f.start||a===r,s=f&&r===f.end,c=r===v,d=n.has(r);return(0,W.jsxs)(`button`,{type:`button`,"data-testid":`wql-calendar-day-${r}`,onClick:()=>m(r),className:G(`relative flex size-8 items-center justify-center rounded-md text-xs transition-colors`,o||s?`bg-primary font-bold text-primary-foreground`:i?`bg-primary/15 font-semibold text-primary`:c?`border border-primary font-semibold text-primary`:`text-foreground hover:bg-muted`),children:[(0,W.jsx)(`span`,{children:e}),d&&!o&&!s&&(0,W.jsx)(`span`,{className:`absolute bottom-0.5 size-1 rounded-full bg-primary`})]},r)})}),a&&(0,W.jsxs)(`div`,{className:`mt-2 text-center text-[10px] text-muted-foreground`,children:[`Select second date to complete range (starting from `,a,`)`]})]})]}),i&&(0,W.jsx)(`button`,{type:`button`,"data-testid":`wql-window-picker-clear`,onClick:()=>{o(null),t(cV(e,null))},title:`Clear time window`,"aria-label":`Clear time window`,className:`ml-1 grid size-7 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground`,children:(0,W.jsx)(we,{className:`size-3.5`})})]})}function dV({onOpen:e}){let t=XB();return(0,W.jsxs)(K,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>{t(),e()},"data-testid":`query-settings-trigger`,className:`w-full justify-start gap-2 rounded-lg text-xs`,children:[(0,W.jsx)(vn,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`truncate`,children:`Query settings`})]})}function fV(e){switch(e.kind){case`note`:return`note`;case`result`:return`result`;case`segment`:case`event`:return`segment`;case`effort`:return`effort`;default:return`note`}}var pV=[{id:`title`,label:`Title`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`tags`,label:`Tags`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.tags??[],formatValue:e=>Array.isArray(e)?e.join(`, `):String(e??``)},{id:`excerpt`,label:`Text Excerpt`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.block?.preview?.join(` `)||e.detail||``,formatValue:e=>String(e??``)},{id:`sourceNotebook`,label:`Notebook`,level:`note`,defaultVisible:!0,align:`left`,getValue:e=>e.sourceNotebook,formatValue:e=>String(e??``)},{id:`date`,label:`Date`,level:`note`,defaultVisible:!0,align:`right`,getValue:e=>e.date,formatValue:e=>String(e??``)}],mV={note:pV,session:[{id:`title`,label:`Title`,level:`session`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`protocol`,label:`Protocol`,level:`session`,defaultVisible:!0,align:`left`,getValue:e=>e.block?.dataType||e.subtitle||``,formatValue:e=>String(e??``)},{id:`movements`,label:`Movements`,level:`session`,defaultVisible:!0,align:`left`,getValue:e=>e.detail||``,formatValue:e=>String(e??``)},{id:`targetDuration`,label:`Target Duration`,level:`session`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.elapsedMs==null?``:kz(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`sessionLoad`,label:`Session Load`,level:`session`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs,formatValue:e=>typeof e==`number`?`${e.toLocaleString()} lbs`:``}],result:[{id:`title`,label:`Title`,level:`result`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`elapsedTime`,label:`Elapsed Time`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.elapsedMs==null?``:kz(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`totalTonnage`,label:`Total Tonnage`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs,formatValue:e=>typeof e==`number`?`${e.toLocaleString()} lbs`:``},{id:`tis`,label:`TIS Score`,level:`result`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.tis,formatValue:e=>typeof e==`number`?e.toFixed(1):``},{id:`prBadges`,label:`PR Badges`,level:`result`,defaultVisible:!0,align:`center`,getValue:e=>e.detail&&/\bPR\b/.test(e.detail)?`PR`:``,formatValue:e=>String(e??``)}],segment:[{id:`splitDuration`,label:`Split Duration`,level:`segment`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.elapsedMs==null?``:kz(e.execution.elapsedMs),formatValue:e=>String(e??``)},{id:`roundIndex`,label:`Round/Lap Index`,level:`segment`,defaultVisible:!0,align:`left`,getValue:e=>e.title,formatValue:e=>String(e??``)},{id:`reps`,label:`Reps`,level:`segment`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.reps,formatValue:e=>e==null?``:String(e)},{id:`load`,label:`Load`,level:`segment`,defaultVisible:!0,align:`right`,getValue:e=>e.execution?.loadLbs,formatValue:e=>typeof e==`number`?`${e.toLocaleString()} lbs`:``},{id:`pacingTier`,label:`Pacing / HR Tier`,level:`segment`,defaultVisible:!0,align:`center`,getValue:e=>e.effort?.intensityTier||e.execution?.effortSlug||``,formatValue:e=>String(e??``)}],effort:[{id:`label`,label:`Label`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.label||e.title,formatValue:e=>String(e??``)},{id:`canonicalSlug`,label:`Canonical Slug`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.slug||e.id,formatValue:e=>String(e??``)},{id:`discipline`,label:`Discipline`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.discipline??``,formatValue:e=>String(e??``)},{id:`met`,label:`MET Score`,level:`effort`,defaultVisible:!0,align:`right`,getValue:e=>e.effort?.met,formatValue:e=>typeof e==`number`?e.toFixed(1):``},{id:`intensityTier`,label:`Intensity Tier`,level:`effort`,defaultVisible:!0,align:`center`,getValue:e=>e.effort?.intensityTier??``,formatValue:e=>String(e??``)},{id:`aliases`,label:`Aliases`,level:`effort`,defaultVisible:!0,align:`left`,getValue:e=>e.effort?.aliases??[],formatValue:e=>Array.isArray(e)?e.join(`, `):String(e??``)}]};function hV(e){return mV[e]??pV}function gV(e){return hV(e).filter(e=>e.defaultVisible).map(e=>e.id)}var _V=[{id:`cards`,label:`Cards`,icon:ye},{id:`rows`,label:`Rows`,icon:le},{id:`feed`,label:`Feed`,icon:Qn}];function vV({streamControls:e}){return(0,W.jsxs)(`div`,{className:`flex flex-col gap-3`,"data-testid":`l3-stream-controls`,children:[e.onOpenQuerySettings&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`This page`}),(0,W.jsx)(dV,{onOpen:e.onOpenQuerySettings})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Date window`}),(0,W.jsx)(uV,{query:e.query,onQueryChange:e.onQueryChange,className:`w-full justify-between`})]}),e.availableGroupDims.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Group by`}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-groupby-options`,children:e.availableGroupDims.map(t=>{let n=e.groupDims.some(e=>e.toLowerCase()===t.id.toLowerCase());return(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-xs text-foreground/80 hover:bg-muted/60 transition-colors`,"data-testid":`l3-groupby-${t.id}`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleGroupDim(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{children:t.label})]},t.id)})})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Layout`}),(0,W.jsx)(`div`,{className:`grid grid-cols-3 gap-1`,"data-testid":`l3-layout-options`,children:_V.map(t=>{let n=t.icon,r=e.settings.layout===t.id;return(0,W.jsxs)(`button`,{type:`button`,"aria-pressed":r,onClick:()=>e.onLayoutChange(t.id),"data-testid":`l3-layout-${t.id}`,className:`flex min-h-8 items-center justify-center gap-1 rounded-md border px-1.5 py-1 text-[11px] font-medium transition-colors ${r?`border-border/80 bg-card text-foreground shadow-sm`:`border-transparent text-muted-foreground hover:text-foreground`}`,children:[(0,W.jsx)(n,{"aria-hidden":!0,className:`size-3`}),t.label]},t.id)})})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`Fields`}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,"data-testid":`l3-field-options`,children:hV(e.level).map(t=>{let n=e.settings.visibleFields.includes(t.id);return(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1 text-xs text-foreground/80 hover:bg-muted/60 transition-colors`,"data-testid":`l3-field-${t.id}`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n,onChange:()=>e.onToggleField(t.id),className:`size-3.5 rounded border-border accent-primary cursor-pointer`}),(0,W.jsx)(`span`,{children:t.label})]},t.id)})})]})]})}function yV({spec:e,pageAction:t}){let{l3Items:n,streamControls:r}=WM(),i=Wz(e),a=(0,U.useMemo)(()=>qB(n),[n]),o=Gz();return i.length===0&&a.length===0&&!r&&!t?null:(0,W.jsxs)(`div`,{className:`flex flex-col px-3 py-4 gap-4`,children:[r&&(0,W.jsx)(`div`,{className:`pb-3 border-b border-border/50`,children:(0,W.jsx)(vV,{streamControls:r})}),i.length>0&&(0,W.jsx)(qz,{entries:i,activeId:o}),a.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-col`,children:[(0,W.jsx)(`div`,{className:`px-2 pb-1 pt-1 text-[10px] font-bold uppercase tracking-[0.14em] text-muted-foreground`,children:`On this page`}),(0,W.jsx)(qz,{entries:a,activeId:o})]}),t&&(0,W.jsx)(`div`,{className:`pt-2 border-t border-border/50`,children:t})]})}var bV=1023;function xV(e){return e===`/`?`canvas:home`:`canvas:${e.replace(/^\//,``)}`}function SV(e,t){if(e===`query:new`)return``;let n=e=>{let n=`/${e}`;for(let r of Object.keys(t))if(r===e||r.endsWith(n))return r;return null},r=e=>{let r=n(e);return r===null?null:Gy(t[r])};if(e.startsWith(`markdown/`)){let t=r(e);if(t!==null)return t}let i=e;if(e.startsWith(`wods/examples/`))i=`markdown/canvas/`+e.replace(/^wods\/examples\//,``);else if(e.startsWith(`wods/`))i=`markdown/canvas/`+e.replace(/^wods\//,``);else if(e.startsWith(`canvas/`))i=`markdown/canvas/`+e.replace(/^canvas\//,``);else{let t=r(`markdown/canvas/`+e);if(t!==null)return t;i=`markdown/`+e}return r(i)??`# Source not found\n\nPath: \`${e}\`\nResolved: \`${i}\``}function CV(e){return(e.examples??[]).length>0||e.commands.some(e=>e.pipeline.length>0)}function wV(e){let t=new Map,n=null;for(let r of e)CV(r)&&(n=r),t.set(r.id,n);return t}function TV(){let[e,t]=(0,U.useState)(()=>typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(max-width: ${bV}px)`).matches);return(0,U.useEffect)(()=>{if(typeof window>`u`||typeof window.matchMedia!=`function`)return;let e=window.matchMedia(`(max-width: ${bV}px)`),n=e=>t(e.matches);return e.addEventListener(`change`,n),()=>e.removeEventListener(`change`,n)},[]),e}var EV=`wodwiki:fabAlignment`,DV=[{id:`left`,label:`Bottom left`,description:`Left-handed — search and page actions float near your left thumb`},{id:`right`,label:`Bottom right`,description:`Right-handed — search and page actions float near your right thumb`}];function OV(){try{return kV(localStorage.getItem(EV))}catch{return}}function kV(e){return e===`right`||e===`left`?e:void 0}var AV=typeof window>`u`?void 0:OV();typeof window<`u`&&window.addEventListener(`storage`,e=>{e.key===EV&&(AV=kV(e.newValue))});function jV(e){AV=e;try{e===`right`?localStorage.removeItem(EV):localStorage.setItem(EV,e)}catch{}window.dispatchEvent(new StorageEvent(`storage`,{key:EV,newValue:e}))}function MV(){let[e,t]=(0,U.useState)(()=>AV??`right`);return(0,U.useEffect)(()=>{let e=e=>{e.key===EV&&t(kV(e.newValue)??`right`)};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]),[e,jV]}function NV({onOpen:e}){return(0,W.jsxs)(`button`,{type:`button`,onClick:e,"aria-label":`Search`,title:`Search`,"data-testid":`search-fab`,className:G(`size-14 rounded-full flex items-center justify-center`,`bg-primary text-primary-foreground shadow-lg`,`hover:bg-primary/90 active:scale-95 transition-all`,`focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`),children:[(0,W.jsx)(en,{className:`size-6`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Search`})]})}var PV=(0,U.createContext)(null),FV=(0,U.createContext)(!1),IV=(0,U.createContext)(null);function LV(){return(0,U.useContext)(PV)!==null}function RV({primary:e,navbar:t,children:n,label:r,fallback:i=!1}){let a=(0,U.useContext)(PV),o=(0,U.useContext)(FV),s=TV(),c=(0,U.useId)(),l=a!==null&&!o&&s&&!i,u=a!==null&&i,d=(0,W.jsx)(FV.Provider,{value:!0,children:n});return(0,U.useEffect)(()=>{if(!(!l&&!u))return a.register({id:c,primary:e,navbar:t,children:d,label:r??`Page options`,fallback:i}),()=>a.unregister(c)},[l,u,a,c,e,d,r,i]),i||a&&s&&!o?null:(0,W.jsx)(FV.Provider,{value:!0,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t,e,n]})})}function zV({onSearch:e,children:t}){let[n,r]=(0,U.useState)([]),i=(0,U.useCallback)(e=>r(t=>[...t.filter(t=>t.id!==e.id),e]),[]),a=(0,U.useCallback)(e=>r(t=>t.filter(t=>t.id!==e)),[]),o=(0,U.useMemo)(()=>({register:i,unregister:a}),[i,a]),s=(0,U.useMemo)(()=>{for(let e=n.length-1;e>=0;--e)if(!n[e].fallback)return n[e].navbar??null;return null},[n]);return(0,W.jsx)(PV.Provider,{value:o,children:(0,W.jsxs)(IV.Provider,{value:s,children:[t,(0,W.jsx)(VV,{registrations:n,onSearch:e})]})})}function BV(){let e=(0,U.useContext)(IV);return e?(0,W.jsx)(W.Fragment,{children:e}):null}function VV({registrations:e,onSearch:t}){let n=TV(),[r]=MV(),i=DC(),[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(null),c=Sn(),[l,u]=(0,U.useState)(!1),d=(0,U.useRef)(0),f=i.offsetBottom>0,p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=(0,U.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(!e[t].fallback)return e[t]},[e]),g=(0,U.useMemo)(()=>{for(let t=e.length-1;t>=0;--t)if(e[t].fallback)return e[t]},[e]);(0,U.useEffect)(()=>{o(!1),u(!1),d.current=window.scrollY},[c.pathname]),(0,U.useEffect)(()=>{if(!n)return;let e=()=>{let e=window.scrollY;if(e<=0||f||a){d.current=e,u(!1);return}let t=e-d.current;Math.abs(t)<8||(d.current=e,u(t>0))};return window.addEventListener(`scroll`,e,{passive:!0}),()=>window.removeEventListener(`scroll`,e)},[n,f,a]),(0,U.useLayoutEffect)(()=>{a&&s.current?.focus()},[a]);let[_,v]=(0,U.useState)({active:0,global:0});(0,U.useLayoutEffect)(()=>{let e=p.current?.childElementCount??0,t=m.current?.childElementCount??0;v(n=>n.active===e&&n.global===t?n:{active:e,global:t})},[h,g]);let y=_.active>0||_.global>0;return!n||!t&&!h&&!g?null:(0,W.jsxs)(`div`,{"data-testid":`actions-dock`,className:G(`lg:hidden fixed z-40 flex flex-col items-center gap-2`,`transition-[transform,visibility] duration-200 ease-out`,r===`left`?`left-4 items-start`:`right-4 items-end`,l&&!a&&!f&&`translate-y-[calc(100%+2rem)] invisible pointer-events-none`),style:{bottom:`calc(1rem + var(--thumb-dock-lift, 0px) + ${i.offsetBottom}px + env(safe-area-inset-bottom))`},children:[(0,W.jsxs)(`div`,{className:`relative z-40 flex flex-col items-center gap-2`,children:[h?.primary&&(0,W.jsx)(`div`,{className:`[&_button]:min-h-11 [&_button]:min-w-11`,children:h.primary}),t&&(0,W.jsx)(NV,{onOpen:()=>{o(!1),t()}})]}),a&&y&&(0,W.jsx)(`button`,{type:`button`,tabIndex:-1,"aria-hidden":`true`,className:`fixed inset-0 z-30 cursor-default`,onClick:()=>o(!1)}),(0,W.jsxs)(`div`,{ref:s,role:`dialog`,"aria-label":h?.label??g?.label??`Page options`,tabIndex:-1,hidden:!a||!y,onKeyDown:e=>{e.key===`Escape`&&(e.stopPropagation(),o(!1))},className:G(`relative z-40 flex w-60 max-w-[calc(100vw-2rem)] flex-col gap-3 overflow-y-auto rounded-2xl bg-card p-3 shadow-xl ring-1 ring-foreground/5 outline-none`,`[&_button]:min-h-11 [&_button]:min-w-11`),style:{maxHeight:`calc(${i.height===null?`100dvh`:`${i.height}px`} - 6rem - env(safe-area-inset-bottom))`},children:[(0,W.jsx)(`div`,{ref:p,className:`contents`,children:h?.children}),_.active>0&&_.global>0&&(0,W.jsx)(`div`,{className:`my-1 border-t border-border/60`,"aria-hidden":`true`}),(0,W.jsx)(`div`,{ref:m,className:`contents`,children:g?.children})]}),y&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>o(e=>!e),"aria-label":h?.label??g?.label??`Page options`,title:h?.label??g?.label??`Page options`,"aria-expanded":a,"data-testid":`actions-overflow`,className:G(`relative z-40 flex size-12 items-center justify-center rounded-full`,`bg-card text-foreground shadow-lg ring-1 ring-foreground/10`,`hover:bg-muted active:scale-95 transition-all`,`focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`),children:[a?(0,W.jsx)(Le,{className:`size-6`}):(0,W.jsx)(he,{className:`size-6`}),(0,W.jsx)(`span`,{className:`sr-only`,children:h?.label??g?.label??`Page options`})]})]})}function HV(){return(0,W.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,W.jsx)(`path`,{d:`M2 6.75C2 6.33579 2.33579 6 2.75 6H17.25C17.6642 6 18 6.33579 18 6.75C18 7.16421 17.6642 7.5 17.25 7.5H2.75C2.33579 7.5 2 7.16421 2 6.75ZM2 13.25C2 12.8358 2.33579 12.5 2.75 12.5H17.25C17.6642 12.5 18 12.8358 18 13.25C18 13.6642 17.6642 14 17.25 14H2.75C2.33579 14 2 13.6642 2 13.25Z`})})}function UV(){return(0,W.jsx)(`svg`,{"data-slot":`icon`,viewBox:`0 0 20 20`,"aria-hidden":`true`,className:`[&>[data-slot=icon]]:size-5`,children:(0,W.jsx)(`path`,{d:`M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z`})})}function WV(){let{tree:e,navState:t,contextNav:n}=WM(),r=Sn(),i=kP();return!e.find(e=>e.id===t.activeL1Id)?.applyFooter||n?.pathname===r.pathname?null:(0,W.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3`,children:(0,W.jsx)(`button`,{type:`button`,onClick:i,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})}function GV({open:e,close:t,onSearch:n,onCreate:r,children:i}){return(0,W.jsxs)(Xe,{open:e,onClose:t,className:`relative z-50 lg:hidden`,children:[(0,W.jsx)(F,{transition:!0,className:`fixed inset-0 bg-black/30 dark:bg-black/30 transition data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in`}),(0,W.jsx)(ce,{transition:!0,className:`fixed inset-y-0 left-0 w-full transition duration-300 ease-out data-closed:-translate-x-full`,children:(0,W.jsx)(OP,{close:t,children:(0,W.jsxs)(`div`,{className:`flex h-full min-h-0 bg-card`,children:[(0,W.jsx)(`div`,{className:`flex h-full w-14 shrink-0 flex-col items-center border-r border-zinc-950/5 bg-background/72 py-3 dark:border-white/5 [&_a]:size-11 [&_button]:size-11`,children:(0,W.jsx)(nB,{onSearch:()=>{t(),n?.()},onCreate:r?()=>{t(),r()}:void 0})}),(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,W.jsx)(`div`,{className:`flex items-center px-4 pt-3`,children:(0,W.jsxs)(et,{as:XL,"aria-label":`Close navigation`,title:`Close navigation`,children:[(0,W.jsx)(UV,{}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Close navigation`})]})}),(0,W.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col`,children:i}),(0,W.jsx)(WV,{})]})]})})})]})}function KV({open:e,close:t,children:n}){return(0,W.jsxs)(Xe,{open:e,onClose:t,className:`relative z-50 lg:hidden`,children:[(0,W.jsx)(F,{transition:!0,className:`fixed inset-0 bg-black/30 dark:bg-black/30 transition data-closed:opacity-0 data-enter:duration-300 data-enter:ease-out data-leave:duration-200 data-leave:ease-in`}),(0,W.jsx)(ce,{transition:!0,className:`fixed inset-y-0 right-0 w-full transition duration-300 ease-out data-closed:translate-x-full`,children:(0,W.jsx)(OP,{close:t,children:(0,W.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-card`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-end px-4 pt-3`,children:(0,W.jsxs)(et,{as:XL,"aria-label":`Close page options`,title:`Close page options`,children:[(0,W.jsx)(UV,{}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Close page options`})]})}),(0,W.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:n}),(0,W.jsx)(`div`,{className:`shrink-0 border-t border-border/50 bg-card p-3`,children:(0,W.jsx)(`button`,{type:`button`,onClick:t,className:`h-11 w-full rounded-lg bg-primary text-sm font-medium text-primary-foreground`,children:`Apply`})})]})})})]})}function qV({navbar:e,sidebar:t,onSearch:n,onCreate:r,secondary:i,pageAction:a,hideDesktopSidebar:o,children:s}){let[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(!1),f=(0,U.useRef)(null),[p,m]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=f.current;if(!e)return;let t=()=>m(t=>{let n=e.childElementCount>0;return t===n?t:n}),n=new MutationObserver(t);return n.observe(e,{childList:!0,subtree:!0}),t(),()=>n.disconnect()},[]);let{streamControls:h}=WM(),g=(0,U.useMemo)(()=>{let e=X(h?.query??``);return!e.error&&Bm(e)&&e.filters.length>0},[h?.query]);return(0,W.jsx)(UB,{children:(0,W.jsx)(zV,{onSearch:n,children:(0,W.jsx)(`div`,{className:`relative isolate flex min-h-svh w-full bg-background max-lg:flex-col lg:flex-row`,children:(0,W.jsxs)(`div`,{className:`flex flex-1 w-full max-lg:flex-col lg:flex-row`,children:[(0,W.jsxs)(`nav`,{"aria-label":`Main`,className:`hidden lg:flex`,children:[(0,W.jsx)(`div`,{className:`w-14 shrink-0 sticky top-0 h-svh flex flex-col items-center border-r border-zinc-950/5 dark:border-white/5 bg-background/72 backdrop-blur-sm z-40 py-3`,children:(0,W.jsx)(nB,{onSearch:n??(()=>{}),onCreate:r})}),(0,W.jsx)(`div`,{className:G(`w-60 shrink-0 sticky top-0 self-start h-svh min-h-0 overflow-hidden border-r border-zinc-950/5 dark:border-white/5 bg-background/72 backdrop-blur-sm flex flex-col`,o&&`lg:hidden`),children:t})]}),(0,W.jsx)(GV,{open:c,close:()=>l(!1),onSearch:n,onCreate:r,children:t}),(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col min-w-0 xl:max-w-[984px] 2xl:max-w-none`,children:[(0,W.jsxs)(`header`,{"data-page-sticky-boundary":`true`,className:`lg:hidden sticky top-0 z-20 flex items-center px-2 sm:px-4 bg-card`,children:[(0,W.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,W.jsxs)(XL,{onClick:()=>l(!0),"aria-label":`Open navigation`,title:`Open navigation`,children:[(0,W.jsx)(HV,{}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Open navigation`})]})}),(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:e}),r&&(0,W.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,W.jsxs)(XL,{onClick:r,"aria-label":`New journal note`,title:`New journal note`,children:[(0,W.jsx)(Jt,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`New journal note`})]})}),p&&(0,W.jsx)(`div`,{className:`py-2.5 shrink-0`,children:(0,W.jsxs)(XL,{onClick:()=>d(!0),"aria-label":`Open page options`,title:`Open page options`,children:[(0,W.jsxs)(`span`,{className:`relative inline-flex`,children:[(0,W.jsx)(vn,{className:`size-5`}),g&&(0,W.jsx)(`span`,{"data-testid":`drawer-filters-active`,className:`absolute -top-1 -right-1 size-2 rounded-full bg-amber-500`,"aria-hidden":`true`})]}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Open page options`})]})})]}),(0,W.jsxs)(`main`,{className:`flex flex-1 flex-col lg:min-w-0`,children:[(0,W.jsx)(`div`,{className:`grow w-full max-lg:pb-48 lg:overflow-visible`,children:s}),(0,W.jsx)(JV,{})]})]}),(0,W.jsx)(`aside`,{className:`hidden 2xl:flex w-60 shrink-0 sticky top-0 h-svh flex-col overflow-y-auto bg-background/72 backdrop-blur-sm`,children:(0,W.jsx)(`div`,{ref:f,className:`contents`,children:(0,W.jsx)(yV,{spec:i,pageAction:a})})}),(0,W.jsx)(KV,{open:u,close:()=>d(!1),children:(0,W.jsx)(yV,{spec:i,pageAction:a})})]})})})})}function JV(){let e=(0,U.useRef)(null),[t,n]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=e.current;if(!t)return;let r=new ResizeObserver(e=>{let t=Math.round(e[0]?.contentRect.height??0);n(e=>e===t?e:t)});r.observe(t,{box:`content-box`});let i=Math.round(t.getBoundingClientRect().height);return n(e=>e===i?e:i),()=>r.disconnect()},[]),(0,U.useEffect)(()=>(document.documentElement.style.setProperty(`--thumb-dock-lift`,`${t}px`),()=>document.documentElement.style.setProperty(`--thumb-dock-lift`,`0px`)),[t]),(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:G(`lg:hidden fixed inset-x-0 bottom-0 z-30`,t>0&&`bg-card border-t border-border/50 px-3 py-2`),children:(0,W.jsx)(`div`,{ref:e,className:`w-full min-w-0`,children:(0,W.jsx)(WB,{className:`flex w-full min-w-0`})})}),(0,W.jsx)(`div`,{className:`lg:hidden`,"aria-hidden":`true`,style:{height:t}})]})}function YV(e){let t=e.indexOf(`markdown`);return t!==-1&&e.length>t+2?e[t+2]:`General`}function XV(e){return String(Ky(By(e).meta,`search`)??``).toLowerCase()===`hidden`}function ZV(e){let t=Ky(By(e).meta,`date`);if(typeof t!=`string`||!/^\d{4}-\d{2}-\d{2}$/.test(t))return;let n=new Date(`${t}T12:00:00Z`);return Number.isFinite(n.getTime())&&n.toISOString().slice(0,10)===t?n.getTime():void 0}function QV(e){return Object.entries(e).map(([e,t])=>{let n=e.split(`/`),r=n[n.length-1].replace(`.md`,``),i=t,a=Ky(By(i).meta,`title`);return{id:e,name:r,displayName:typeof a==`string`&&a.trim()?a.trim():EO(r),category:YV(n),content:i,date:ZV(i),searchHidden:XV(i)}})}function $V(){let e=YO();return(0,U.useMemo)(()=>e?QV(e):[],[e])}var eH={};function tH(e){if(!(`payload`in e))return;let t=e.payload;if(!t||typeof t!=`object`)return;let n=t;return n.targetDate??n.updatedAt}function nH(e,t){let{canvasPage:n,workoutItems:r,recentResults:i,selectWorkout:a}=t;if(e===`/`)return[];if(n){let t=/^\/notebook\//.test(e),i=t?e.split(`/`).pop()??null:null,o=[],s=e.startsWith(`/page/guide-`);return n.sections.filter(e=>e.level>1).forEach(e=>{if(o.push({id:e.id,label:e.heading,type:`heading`}),!s){let t=vL(e).split(`
101
101
  `),n=0;t.forEach((t,r)=>{let i=t.trim().match(/^```(time|log)(:\w+)?\s*$/);if(i){let t=i[1];n++,o.push({id:`${e.id}-${t}-${r+1}`,label:`Workout ${n}`,type:t})}})}}),t&&i&&(o.push({id:`notebook-workouts`,label:`Explore`,type:`heading`}),r.filter(e=>e.category===i&&e.name.toLowerCase()!==`readme`).forEach(e=>{o.push({id:`workout-${e.id}`,label:e.name,type:`time`,onRun:()=>a(e),runIcon:`link`})})),o}if(e===`/journal`){let e=new Set;return i.forEach(t=>{let n=new Date(t.createdAt).getTime();Number.isFinite(n)&&e.add(gP(new Date(n)))}),r.forEach(t=>{let n=tH(t);n&&Number.isFinite(new Date(n).getTime())&&e.add(gP(new Date(n)))}),Array.from(e).sort().reverse().slice(0,10).map(e=>({id:e,label:Py(new Date(e+`T00:00:00`)),type:`heading`}))}return[]}var rH=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function iH(e){return rH.test(e)}function aH(e){try{return decodeURIComponent(e)}catch{return null}}function oH(e){if(!yP(e))return!1;let t=e.match(/^(\d{4})-(\d{2})-(\d{2})$/);if(!t)return!1;let n=new Date(Date.UTC(Number(t[1]),Number(t[2])-1,Number(t[3])));return n.getUTCFullYear()===Number(t[1])&&n.getUTCMonth()===Number(t[2])-1&&n.getUTCDate()===Number(t[3])}function sH(e){let t=(e.length>1?e.replace(/\/+$/,``):e).match(/^\/day\/([^/]+)$/);if(!t)return{kind:`invalid`};let n=aH(t[1]);return n!=null&&oH(n)?{kind:`date`,date:n}:{kind:`invalid`}}var cH=`# My Workout Notebook
102
102
 
103
103
  Welcome to the **WOD.WIKI** playground.
@@ -156,11 +156,14 @@ Timer 12:00
156
156
  border border-border/80 shadow-xl rounded-lg overflow-hidden pointer-events-auto`,style:{top:O,maxHeight:200},children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 bg-muted/40 border-b border-border/50 shrink-0`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-mono px-2 py-0.5 rounded bg-metric-time/10 text-metric-time uppercase tracking-wider font-semibold`,children:m.type}),(0,W.jsxs)(`div`,{className:`flex items-center min-w-0 gap-2`,children:[(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground/60`,children:[`L`,E]}),(0,W.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}),(0,W.jsx)(`span`,{className:`text-xs font-mono text-foreground/90 truncate font-medium`,title:T,children:T||(0,W.jsx)(`span`,{className:`italic text-muted-foreground`,children:`—`})})]})]}),(0,W.jsx)(`div`,{className:`px-3 py-2.5 min-h-0 overflow-auto`,children:C.length>0?(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:C.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 px-2 py-1 rounded-md text-sm font-semibold ${e.color}`,title:e.label,children:[(0,W.jsx)(`span`,{className:`text-base leading-none`,children:e.icon}),(0,W.jsx)(`span`,{className:`font-mono tracking-tight`,children:e.value})]},t))}):(0,W.jsx)(`span`,{className:`text-xs italic text-muted-foreground`,children:`No metrics on this line`})}),w&&(0,W.jsx)(aY,{summary:w}),(0,W.jsx)(`div`,{className:`border-t border-border/40 shrink-0`,children:(0,W.jsx)(lY,{commands:d,section:m,view:n})})]})]})},dY=({sectionId:e,widgetName:t,view:n,registry:r,docVersion:i})=>{let{rawContent:a,config:o}=(0,U.useMemo)(()=>{let t=n.state.field(_T).sections.find(t=>t.id===e),r=t?.contentFrom!==void 0&&t?.contentTo!==void 0?n.state.doc.sliceString(t.contentFrom,t.contentTo).trim():``,i={};if(r)try{i=JSON.parse(r)}catch{}return{rawContent:r,config:i}},[n,e,i]),s=r.get(t);return s?(0,W.jsx)(`div`,{className:`h-full w-full overflow-hidden rounded-l-md border-l border-border bg-background shadow-sm`,children:(0,W.jsx)(s,{config:o,rawContent:a,sectionId:e})}):(0,W.jsxs)(`div`,{className:`flex h-full w-full items-center justify-center rounded-l-md border-l border-border bg-muted/60 p-4 text-xs text-muted-foreground`,children:[(0,W.jsxs)(`span`,{className:`font-mono`,children:[`widget:`,t]}),(0,W.jsx)(`span`,{className:`ml-2 opacity-60`,children:`— not registered`})]})};function fY(e,t,n,r,i){switch(t.type){case`fixed-field`:return pY(e,t);case`metric-type`:return mY(e,t);case`derived`:return hY(e,t,n,r,i);case`fallback`:return gY(e,t,n,r,i);default:return}}function pY(e,t){return e[t.field]}function mY(e,t){return e.cells.get(t.metricType)}function hY(e,t,n,r,i){let a=new Map;if(t.dependencies&&r)for(let o of t.dependencies){if(i?.includes(o))throw Error(`Circular dependency detected in column '${o}': ${(i??[]).join(` -> `)} -> ${o}`);let t=r.get(o);if(t){let s=fY(e,t.source,n,r,[...i??[],o]);a.set(o,s)}}let o={...n,allRows:n?.allRows??[e],rowIndex:n?.rowIndex??0,columnDef:n?.columnDef??{id:`unknown`,label:``,source:t,format:{type:`text`}},dependencies:a,...t.context};return t.compute(e,o)}function gY(e,t,n,r,i){return _Y(e,t,n,r,i)}function _Y(e,t,n,r,i){if(!(!t.sources||t.sources.length===0))switch(t.semantics){case`first-present`:return vY(e,t.sources,n,r,i);case`all-present-joined`:return yY(e,t.sources,t.joinString,n,r,i);case`all-present-combined`:return bY(e,t.sources,n,r,i);default:return}}function vY(e,t,n,r,i){for(let a of t){let t=fY(e,a,n,r,i);if(t!=null)return t}}function yY(e,t,n,r,i,a){let o=[];for(let n of t){let t=fY(e,n,r,i,a);if(t==null)return;o.push(t)}let s=n??` `;return o.map(e=>SY(e)).join(s)}function bY(e,t,n,r,i){let a=[];for(let o of t){let t=fY(e,o,n,r,i);if(t==null)return;a.push(t)}return a}function xY(e){if(e==null)return``;let t=Array.isArray(e)?e:e instanceof J?e.toArray():[];if(t.length===0)return``;let n=t[0];if(typeof n==`object`&&n){if(`image`in n&&typeof n.image==`string`)return n.image;if(`value`in n&&n.value!==void 0)return String(n.value)}return String(n)}function SY(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);if(typeof e==`object`&&`metrics`in e){let t=xY(e.metrics);if(t.length>0)return t}return String(e)}function CY(e,t,n,r){if(!t.sort)return``;let i=fY(e,t.source,n,r);return(t.sort.type===`custom`?typeof i==`number`||typeof i==`string`?i:String(i??``):t.sort.extractor(i))??``}function wY(e,t){if(typeof e==`number`&&typeof t==`number`)return Number.isNaN(e)&&Number.isNaN(t)?0:Number.isNaN(e)?1:Number.isNaN(t)?-1:e-t;let n=String(e??``),r=String(t??``),i=parseFloat(n),a=parseFloat(r);return!Number.isNaN(i)&&!Number.isNaN(a)&&n===String(i)&&r===String(a)?i-a:n.localeCompare(r)}function TY(e,t,n,r){if(!t.graph)return;let i=fY(e,t.source,n,r);return t.graph.extractor(i)}function EY(e,t,n,r){if(!t.filter)return``;let i=fY(e,t.source,n,r);return t.filter.extractor(i)??``}function DY(e,t,n,r,i){if(!n||n.trim().length===0||!t.filter)return!0;let a=EY(e,t,r,i),o=t.filter.caseInsensitive===!1?n.trim():n.trim().toLowerCase(),s=t.filter.caseInsensitive===!1?a:a.toLowerCase();return t.filter.matcher?t.filter.matcher(s,o):s.includes(o)}var OY=({metric:e})=>{let t=e.origin===`hinted`||e.image===`?`,n=(0,U.useMemo)(()=>pW(Fo.present(e,`review-grid-cell`)),[e]);return(0,W.jsxs)(`span`,{className:[`inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded text-xs font-medium border transition-all`,t?`bg-warning/10 border-warning/40 text-warning animate-pulse-opacity`:`${n.colorClasses} ${n.originClasses}`].join(` `),title:t?`Missing value - click to fill`:n.tooltip,children:[t&&(0,W.jsx)(`span`,{className:`mr-0.5 text-[10px]`,children:`◉`}),n.label,n.userEntered&&!t&&(0,W.jsx)(`span`,{className:`text-[10px] opacity-70 ml-0.5`,children:`👤`})]})},kY=({columnDef:e,row:t,allRows:n,rowIndex:r,indent:i=0,onDoubleClick:a,className:o,style:s,definitionMap:c})=>{let l=(0,U.useRef)(null),u=(0,U.useMemo)(()=>{if(!(!n||r===void 0))return{allRows:n,rowIndex:r,columnDef:e,dependencies:new Map}},[n,r,e]),d=(0,U.useMemo)(()=>fY(t,e.source,u,c),[t,e.source,u,c]),f=e.source.type===`metric-type`,p=(0,U.useCallback)(n=>{if(n.stopPropagation(),f&&a&&l.current){let n=l.current.getBoundingClientRect();a(t.sourceBlockKey,e.source.metricType,n)}},[f,e.source,t.sourceBlockKey,a]),m=(0,U.useMemo)(()=>AY(d,e.format,i,t),[d,e.format,i,t]);return(0,W.jsx)(`td`,{ref:l,className:G(`py-1 px-2`,f&&`cursor-cell`,o),style:s,onDoubleClick:p,children:m})};function AY(e,t,n,r){if(e==null)return(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[UY(n),(0,W.jsx)(`span`,{className:`text-muted-foreground opacity-40`,children:`—`})]});switch(t.type){case`text`:return jY(e,t,n);case`time`:return MY(e,t);case`number`:return NY(e,t);case`badge`:return PY(e,t);case`pill`:return FY(e,t);case`combined`:return LY(e,t,n);case`custom`:return zY(e,t,r);default:return VY(e,n)}}function jY(e,t,n){let r=t.transform?t.transform(e):WY(e);return(0,W.jsxs)(`span`,{className:G(`inline-flex items-center gap-1`,t.className),children:[UY(n),r]})}function MY(e,t){let n=GY(e);if(n==null||!Number.isFinite(n))return(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});let r;switch(t.style){case`long`:r=AU(n);break;case`precise`:r=`${n.toFixed(2)}s`;break;default:r=kU(n)}return t.transform&&(r=t.transform(r)),(0,W.jsx)(`span`,{className:`font-mono text-xs whitespace-nowrap`,children:r})}function NY(e,t){let n=GY(e);if(n==null||!Number.isFinite(n))return(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`—`});let r=t.decimals??0,i=n.toFixed(r)+(t.unit??``);return t.transform?(0,W.jsx)(`span`,{children:t.transform(i)}):(0,W.jsx)(`span`,{children:i})}function PY(e,t){let n=t.styleResolver(e),r=t.textResolver(e);return(0,W.jsxs)(`span`,{className:G(`inline-flex items-center px-1.5 py-0.5 rounded text-xs font-medium`,n.className),title:n.title,children:[n.icon&&(0,W.jsx)(`span`,{className:`mr-0.5`,children:n.icon}),r]})}function FY(e,t){let n=t.transform?t.transform(e):WY(e),r=t.backgroundColor??`bg-muted`,i=t.borderRadius??`rounded`;return(0,W.jsx)(`span`,{className:G(`inline-block px-1.5 py-0.5 text-xs font-medium`,r,i),children:n})}var IY={primary:`text-sm font-semibold text-foreground`,secondary:`text-xs text-muted-foreground`,tertiary:`text-[11px] text-muted-foreground opacity-80`};function LY(e,t,n,r){let[i,a,o]=Array.isArray(e)?e:[e],s=i===void 0?null:RY(i,t.primaryFormat??{type:`text`},r,`primary`),c=a===void 0?null:RY(a,t.secondaryFormat??{type:`text`},r,`secondary`),l=o===void 0?null:RY(o,t.tertiaryFormat??{type:`text`},r,`tertiary`),u=t.layout===`horizontal`;return(0,W.jsxs)(`div`,{className:G(`inline-flex`,u?`flex-row items-center gap-1`:`flex-col items-start gap-0.5`,t.containerClassName),children:[UY(n),s,c&&(0,W.jsxs)(W.Fragment,{children:[u&&t.separator&&(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:t.separator}),c]}),l&&(0,W.jsxs)(W.Fragment,{children:[u&&t.separator&&(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:t.separator}),l]})]})}function RY(e,t,n,r){let i=AY(e,t,0,n);return r?(0,W.jsx)(`span`,{className:G(`inline-flex items-center`,IY[r]),children:i}):i}function zY(e,t,n){let r=n?{...t.context,row:n}:t.context;return t.render(e,r)}function BY(e){let t=e?.metrics;if(!t)return[];if(Array.isArray(t))return t;if(typeof t==`object`&&t&&`toArray`in t){let e=t;if(typeof e.toArray==`function`)return e.toArray()}return[]}function VY(e,t){return e?.metrics?HY(e,t):(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[UY(t),WY(e)]})}function HY(e,t){let n=BY(e);return n.length===0?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[UY(t),(0,W.jsx)(`span`,{className:`text-muted-foreground opacity-40`,children:`—`})]}):(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1 items-center`,children:[UY(t),n.map((e,t)=>(0,W.jsx)(OY,{metric:e},t))]})}function UY(e){return e<=0?null:(0,W.jsx)(`div`,{className:`flex-shrink-0 mr-1 border-l-2 border-muted h-4`,style:{width:`${e*1.25}rem`,marginLeft:`2px`}})}function WY(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`number`||typeof e==`boolean`)return String(e);let t=BY(e);if(t.length>0){let e=t[0];if(e?.image)return e.image;if(e?.value!==void 0)return String(e.value)}return String(e)}function GY(e){if(e==null)return;if(typeof e==`number`)return e;if(typeof e==`string`){let t=parseFloat(e);if(!Number.isNaN(t))return t}let t=BY(e);if(t.length>0&&typeof t[0]?.value==`number`)return t[0].value}var KY=e=>e;function qY(e){let t=e?.metrics;if(!t)return[];if(Array.isArray(t))return t;if(typeof t==`object`&&t&&`toArray`in t){let e=t;if(typeof e.toArray==`function`)return e.toArray()}return[]}function JY(e){let t=qY(e);if(t.length===0)return;let n=t[0];return typeof n?.value==`number`?n.value:n?.image?n.image:String(n?.value??``)}function YY(e){let t=qY(e);for(let e of t)if(typeof e?.value==`number`)return e.value}function XY(e){return qY(e).map(e=>e.image??String(e.value??``)).join(`, `)}function ZY(e){return e==null?``:Array.isArray(e)?e.map(e=>ZY(e)).filter(Boolean).join(` — `):typeof e==`string`?e:typeof e==`number`?String(e):XY(e)}function QY(e){switch(e){case q.Duration:case q.Rep:case q.Distance:case q.Rounds:case q.Resistance:case q.Increment:case q.Metric:case q.Volume:case q.Intensity:case q.Load:case q.Work:case q.CurrentRound:case q.Calculated:return!0;default:return!1}}function $Y(e){switch(e){case q.Duration:return`s`;case q.Rep:return`reps`;case q.Distance:return`m`;case q.Rounds:return`rounds`;case q.Resistance:return`kg`;case q.Increment:return`Δ`;case q.Calculated:case q.Custom:return``;default:return``}}function eX(e,t){let n=bo(e),r=YU(e)??void 0,i=t?.graphable??QY(e);return{id:e,label:n,icon:r,source:{type:`metric-type`,metricType:e},format:{type:`custom`,render:e=>HY(e,0)},sort:QY(e)?{type:`numeric`,extractor:e=>YY(e)}:{type:`text`,extractor:e=>{let t=JY(e);return t===void 0?void 0:String(t)}},graph:i?{extractor:e=>YY(e),axisLabel:n,unit:$Y(e)}:void 0,filter:{extractor:e=>XY(e),caseInsensitive:!0},meta:{defaultVisible:t?.defaultVisible??!0,debugOnly:t?.debugOnly,tags:[e]}}}function tX(e){switch(e){case`segment`:return`bg-blue-100 text-blue-800 dark:bg-blue-900/50 dark:text-blue-200`;case`milestone`:return`bg-yellow-100 text-yellow-800 dark:bg-yellow-900/50 dark:text-yellow-200`;case`system`:return`bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-400`;case`event`:return`bg-purple-100 text-purple-800 dark:bg-purple-900/50 dark:text-purple-200`;case`group`:return`bg-indigo-100 text-indigo-800 dark:bg-indigo-900/50 dark:text-indigo-200`;case`load`:return`bg-green-100 text-green-800 dark:bg-green-900/50 dark:text-green-200`;case`compiler`:return`bg-pink-100 text-pink-800 dark:bg-pink-900/50 dark:text-pink-200`;default:return`bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300`}}function nX(e,t){if(!e||e.length===0)return``;let n=e=>kU(e);if(t===0)return n(e[0].started);let r=n(e[0].started),i=e[e.length-1];if(i.ended===void 0)return r;let a=n(i.ended);return r===a?r:`${r} — ${a}`}function rX(e,t=!0){if(e===void 0||e===0)return``;let n=new Date(e),r=n.getHours().toString().padStart(2,`0`),i=n.getMinutes().toString().padStart(2,`0`),a=n.getSeconds().toString().padStart(2,`0`);return t?`${r}:${i}:${a}.${n.getMilliseconds().toString().padStart(3,`0`)}`:`${r}:${i}:${a}`}function iX({value:e}){let t=e.match(/^(-?)(\d+)(:\d{2})(?::\d{2})?(\.\d+)?$/);if(!t)return(0,W.jsx)(`span`,{className:`font-mono text-xs whitespace-nowrap`,children:e});let[,n,r,i,a,o]=t,s=i.slice(1);return(0,W.jsxs)(`span`,{className:`font-mono text-xs whitespace-nowrap inline-flex items-baseline`,children:[n&&(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:n}),(0,W.jsx)(`span`,{className:`font-semibold text-foreground`,children:r}),(0,W.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`:`,s]}),a&&(0,W.jsx)(`span`,{className:`text-muted-foreground/40`,children:a}),o&&(0,W.jsx)(`span`,{className:`text-muted-foreground/30 text-[10px]`,children:o})]})}function aX({elapsed:e,duration:t}){let n=kU(e);return(0,W.jsxs)(`span`,{className:`inline-flex items-baseline gap-0.5`,children:[(0,W.jsx)(iX,{value:n}),t!==void 0&&t>0&&t!==e&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-muted-foreground/40 mx-0.5`,children:`/`}),(0,W.jsx)(`span`,{className:`opacity-60`,children:(0,W.jsx)(iX,{value:kU(t)})})]})]})}var oX={id:`#`,label:`#`,source:{type:`derived`,compute:e=>({index:e.index,outputType:e.outputType,sourceBlockKey:e.sourceBlockKey})},format:{type:`custom`,render:e=>{let{index:t,outputType:n,sourceBlockKey:r}=e??{};return(0,W.jsx)(`span`,{className:G(`font-mono text-[11px] w-8 text-right inline-block`,tX(n)),title:`Type: ${n}\nBlock: ${r}`,children:t})}},sort:{type:`numeric`,extractor:e=>KY(e)?.index||0},meta:{tags:[`layout`],defaultVisible:!0,width:`40px`,resizable:!1}},sX={id:`timestamp`,label:`Timestamp`,source:{type:`fixed-field`,field:`absoluteStartTime`},format:{type:`custom`,render:(e,t)=>{let n=e,r=KY(t)?.hideMs!==!1;return(0,W.jsx)(`span`,{className:`text-muted-foreground font-mono text-[10px] text-center w-24 whitespace-nowrap`,children:rX(n,r)})},context:{hideMs:!1}},sort:{type:`numeric`,extractor:e=>KY(e)?.absoluteStartTime??0},meta:{tags:[`timing`,`layout`],defaultVisible:!0}},cX={id:`spans`,label:`Time`,source:{type:`derived`,compute:e=>({spans:e.spans,duration:e.duration})},format:{type:`custom`,render:e=>{let{spans:t,duration:n}=e??{};return(0,W.jsx)(`span`,{className:`text-muted-foreground font-mono text-[10px] text-center w-40 whitespace-nowrap`,children:nX(t,n)})}},sort:{type:`numeric`,extractor:e=>(KY(e)?.spans)?.[0]?.started??0},meta:{tags:[`timing`,`layout`],defaultVisible:!0}},lX={id:`timeSpan`,label:`Time`,source:{type:`derived`,compute:e=>({timestamp:e.absoluteStartTime,elapsed:e.elapsed,duration:e.duration})},format:{type:`custom`,render:e=>{let{timestamp:t,elapsed:n,duration:r}=e??{};return n===void 0?(0,W.jsx)(`span`,{className:`text-muted-foreground opacity-40`,children:`—`}):(0,W.jsxs)(`div`,{className:`flex flex-col items-start gap-0 leading-tight`,children:[t!==void 0&&t>0&&(0,W.jsx)(`span`,{className:`text-muted-foreground/50 font-mono text-[10px] whitespace-nowrap`,children:rX(t,!1)}),(0,W.jsx)(aX,{elapsed:n,duration:r})]})}},sort:{type:`numeric`,extractor:e=>KY(e)?.elapsed??0},graph:{extractor:e=>KY(e)?.elapsed,axisLabel:`Elapsed`,unit:`s`},filter:{extractor:e=>{let{timestamp:t,elapsed:n,duration:r}=e??{},i=[];return t!==void 0&&t>0&&i.push(rX(t,!1)),n!==void 0&&i.push(kU(n)),r!==void 0&&r>0&&r!==n&&i.push(kU(r)),i.join(` `)},caseInsensitive:!0},meta:{tags:[`timing`,`compound`],defaultVisible:!0,width:`100px`,subsumes:[`duration`,`elapsedTotal`]}},uX={id:`blockKey`,label:`Block`,source:{type:`fixed-field`,field:`sourceBlockKey`},format:{type:`text`,className:`truncate max-w-[160px] text-sm`},sort:{type:`text`,extractor:e=>KY(e)?.sourceBlockKey??``},filter:{extractor:e=>KY(e)?.sourceBlockKey??``,caseInsensitive:!0},meta:{tags:[`layout`],defaultVisible:!1}},dX={id:`outputType`,label:`Type`,source:{type:`fixed-field`,field:`outputType`},format:{type:`custom`,render:e=>{let t=String(e??``);return(0,W.jsx)(`span`,{className:G(`text-xs px-1.5 py-0.5 rounded font-medium`,tX(t)),children:t})}},sort:{type:`text`,extractor:e=>KY(e)?.outputType??``},filter:{extractor:e=>KY(e)?.outputType??``,caseInsensitive:!0},meta:{tags:[`debug`],defaultVisible:!1}},fX={id:`stackLevel`,label:`Depth`,source:{type:`fixed-field`,field:`stackLevel`},format:{type:`text`,className:`text-muted-foreground font-mono text-xs text-center w-12`},sort:{type:`numeric`,extractor:e=>KY(e)?.stackLevel??0},meta:{tags:[`debug`],defaultVisible:!1,debugOnly:!0}},pX={id:`elapsedTotal`,label:`Elapsed`,source:{type:`derived`,compute:e=>({elapsed:e.elapsed,total:e.total})},format:{type:`custom`,render:e=>{let{elapsed:t,total:n}=e??{};if(t===void 0||n===void 0)return``;let r=t===n?kU(t):`${kU(t)} / ${kU(n)}`;return(0,W.jsx)(`span`,{className:`text-foreground font-mono text-xs text-right w-32 whitespace-nowrap`,children:r})}},sort:{type:`numeric`,extractor:e=>KY(e)?.elapsed??0},graph:{extractor:e=>KY(e)?.elapsed,axisLabel:`Elapsed`,unit:`s`,color:`#14b8a6`},meta:{tags:[`timing`],defaultVisible:!1}},mX={id:`completionReason`,label:`Reason`,source:{type:`fixed-field`,field:`completionReason`},format:{type:`text`,className:`text-muted-foreground text-xs truncate max-w-[120px]`},sort:{type:`text`,extractor:e=>KY(e)?.completionReason??``},filter:{extractor:e=>KY(e)?.completionReason??``,caseInsensitive:!0},meta:{tags:[`debug`],defaultVisible:!1,debugOnly:!0}},hX=eX(q.Effort,{defaultVisible:!1}),gX=eX(q.Duration,{debugOnly:!0}),_X=eX(q.Rep),vX=eX(q.Rounds,{defaultVisible:!1}),yX=eX(q.Distance),bX=eX(q.Resistance),xX=eX(q.Action),SX=eX(q.Increment),CX=eX(q.Metric),wX=eX(q.Calculated),TX=eX(q.Custom,{defaultVisible:!1}),EX=eX(q.Group,{defaultVisible:!1}),DX=eX(q.System,{defaultVisible:!1}),OX=eX(q.Label,{defaultVisible:!1}),kX=eX(q.Text),AX=eX(q.CurrentRound,{defaultVisible:!1}),jX=eX(q.Volume),MX=eX(q.Intensity),NX=eX(q.Load),PX=eX(q.Work),FX=[oX,lX,sX,cX,uX,dX,fX,pX,mX,{id:`exercise`,label:`Exercise`,icon:YU(q.Effort)??void 0,source:{type:`fallback`,semantics:`first-present`,sources:[{type:`fallback`,semantics:`all-present-combined`,sources:[{type:`metric-type`,metricType:q.Effort},{type:`metric-type`,metricType:q.Text}]},{type:`metric-type`,metricType:q.Text},{type:`metric-type`,metricType:q.Label},{type:`metric-type`,metricType:q.Effort}]},format:{type:`combined`,layout:`vertical`,primaryFormat:{type:`text`,className:`font-medium text-foreground`},secondaryFormat:{type:`text`,className:`text-muted-foreground text-xs`},containerClassName:`items-start`},sort:{type:`text`,extractor:e=>ZY(e)},filter:{extractor:e=>ZY(e),caseInsensitive:!0},meta:{defaultVisible:!1,tags:[`grouping`,`fallback`,`descriptor`],subsumes:[`effort`,`text`,`label`]}},{id:`descriptor`,label:`Descriptor`,icon:YU(q.Effort)??void 0,source:{type:`fallback`,semantics:`first-present`,sources:[{type:`metric-type`,metricType:q.Effort},{type:`metric-type`,metricType:q.Label},{type:`metric-type`,metricType:q.Rounds},{type:`metric-type`,metricType:q.CurrentRound}]},format:{type:`custom`,render:e=>HY(e,0)},sort:{type:`text`,extractor:e=>ZY(e)},filter:{extractor:e=>ZY(e),caseInsensitive:!0},meta:{defaultVisible:!0,subsumes:[`effort`,`label`,`rounds`,`current-round`]}},hX,kX,OX,gX,{id:`pace`,label:`Pace`,icon:`⏱️`,source:{type:`derived`,dependencies:[`distance`,`duration`],compute:(e,t)=>{let n=YY(t.dependencies.get(`distance`)),r=YY(t.dependencies.get(`duration`));if(!(!n||!r))return n/r}},format:{type:`custom`,render:e=>{if(typeof e!=`number`||!Number.isFinite(e)||e<=0)return(0,W.jsx)(`span`,{className:`text-muted-foreground opacity-40`,children:`—`});let t=1e3/e;return(0,W.jsxs)(`span`,{className:`font-mono text-xs whitespace-nowrap`,children:[kU(t),`/km`]})}},sort:{type:`numeric`,extractor:e=>typeof e==`number`?e:void 0},graph:{extractor:e=>typeof e==`number`?e:void 0,axisLabel:`Pace`,unit:`m/s`},filter:{extractor:e=>typeof e!=`number`||!Number.isFinite(e)||e<=0?``:`${kU(1e3/e)}/km`,caseInsensitive:!0},meta:{defaultVisible:!1,tags:[`endurance`,`derived`]}},_X,vX,yX,bX,xX,SX,CX,wX,TX,AX,jX,MX,{id:`loadFocus`,label:`Load`,icon:YU(q.Load)??YU(q.Resistance)??void 0,source:{type:`fallback`,semantics:`first-present`,sources:[{type:`metric-type`,metricType:q.Load},{type:`metric-type`,metricType:q.Resistance}]},format:{type:`custom`,render:e=>HY(e,0)},sort:{type:`numeric`,extractor:e=>YY(e)},graph:{extractor:e=>YY(e),axisLabel:`Load`,unit:`kg`},filter:{extractor:e=>XY(e),caseInsensitive:!0},meta:{defaultVisible:!1,tags:[`strength`,`fallback`]}},NX,PX,EX,DX],IX={outputTypes:[`segment`,`milestone`,`group`,`analytics`]},LX={definitions:FX,presets:{default:{label:`Default`,filters:IX,visibleColumnIds:[`#`,`timeSpan`,`descriptor`,`rep`,`distance`,`resistance`,`action`,`increment`,`metric`,`calculated`,`custom`,`volume`,`intensity`,`load`,`work`]},debug:{label:`Debug`,filters:{},visibleColumnIds:[`#`,`timeSpan`,`timestamp`,`spans`,`blockKey`,`outputType`,`stackLevel`,`descriptor`,`duration`,`rep`,`distance`,`resistance`,`action`,`increment`,`metric`,`calculated`,`custom`,`volume`,`intensity`,`load`,`work`,`group`,`system`,`elapsedTotal`,`completionReason`]},strength:{label:`Strength`,filters:IX,visibleColumnIds:[`#`,`timeSpan`,`exercise`,`rep`,`loadFocus`,`volume`,`intensity`,`load`,`work`,`elapsedTotal`]},endurance:{label:`Endurance`,filters:IX,visibleColumnIds:[`#`,`timeSpan`,`exercise`,`distance`,`duration`,`pace`,`rounds`,`increment`,`work`,`elapsedTotal`]}},defaultPreset:`default`},RX=new class{config;definitionMap;constructor(e){this.config=e,this.definitionMap=new Map(e.definitions.map(e=>[e.id,e]))}getVisibleColumns(e){return this.getOrderedCandidates(e).filter(t=>this.computeVisibility(t.id,e))}getAvailableColumns(e){let t=new Set(this.getVisibleColumns(e).map(e=>e.id));return this.config.definitions.filter(n=>!t.has(n.id)&&this.isColumnAvailable(n,e))}getGraphableColumns(e){return this.getVisibleColumns(e).filter(e=>e.graph!==void 0)}getGraphTaggedColumns(e){let t=e.graphTaggedColumnIds;return!t||t.size===0?[]:this.getVisibleColumns(e).filter(e=>t.has(e.id))}isColumnVisible(e,t){return this.getDefinition(e)?this.computeVisibility(e,t):!1}getDefinition(e){return this.definitionMap.get(e)}getPreset(e){return this.config.presets[e]??this.config.presets[this.config.defaultPreset]}getAllDefinitions(){return this.config.definitions}get definitions(){return this.definitionMap}resolveColumnValue(e,t,n,r){let i=this.getDefinition(t);if(!i)return;let a={allRows:n,rowIndex:r??n.findIndex(t=>t.id===e.id),columnDef:i,dependencies:new Map};return fY(e,i.source,a,this.definitionMap)}getOrderedCandidates(e){let t=this.getPreset(e.activePresetId),n=[],r=new Set,i=e=>{if(r.has(e))return;let t=this.getDefinition(e);t&&(n.push(t),r.add(e))};for(let e of t.visibleColumnIds)i(e);for(let e of this.config.definitions)i(e.id);if(e.addedColumnIds)for(let t of e.addedColumnIds)i(t);return n}computeVisibility(e,t,n){if(t.visibilityOverrides&&e in t.visibilityOverrides)return t.visibilityOverrides[e];if(t.addedColumnIds?.has(e))return!0;let r=this.getDefinition(e);if(!r||r.meta?.debugOnly&&!t.isDebugMode||!n&&this.isColumnSubsumed(e,t))return!1;let i=this.getPreset(t.activePresetId).visibleColumnIds.includes(e),a=this.hasDataInRows(r,t.rows);switch(r.source.type){case`fixed-field`:return i;case`derived`:return i;case`metric-type`:return a;case`fallback`:return i&&a;default:return i}}isColumnSubsumed(e,t){for(let n of this.config.definitions)if(n.meta?.subsumes?.length&&this.getPreset(t.activePresetId).visibleColumnIds.includes(n.id)&&n.meta.subsumes.includes(e))return!0;return!1}isColumnAvailable(e,t){return e.meta?.debugOnly&&!t.isDebugMode?!1:this.getPreset(t.activePresetId).visibleColumnIds.includes(e.id)?!this.computeVisibility(e.id,t):e.source.type===`fixed-field`||e.source.type===`derived`||this.hasDataInRows(e,t.rows)}hasDataInRows(e,t){if(t.length===0)return!1;switch(e.source.type){case`fixed-field`:return!0;case`metric-type`:{let{metricType:n}=e.source;return t.some(e=>e.cells.has(n))}case`derived`:return!0;case`fallback`:{let{sources:n}=e.source;return t.some(e=>n.some(t=>this.sourceHasDataInRow(t,e)))}default:return!0}}sourceHasDataInRow(e,t){switch(e.type){case`fixed-field`:return t[e.field]!==void 0&&t[e.field]!==null;case`metric-type`:return t.cells.has(e.metricType);case`derived`:return!0;case`fallback`:return e.sources.some(e=>this.sourceHasDataInRow(e,t));default:return!1}}}(LX);function zX(e){let{segments:t,userOutputOverrides:n,presetId:r,isDebugMode:i,sortConfigs:a,filterOverrides:o,graphTaggedColumns:s,extraMetricTypes:c,columnVisibilityOverrides:l,addedColumnIds:u}=e,d=(0,U.useMemo)(()=>BX(t,n),[t,n]),f=(0,U.useMemo)(()=>{let e=new Set(u??[]);for(let t of c??[])e.add(t);return e},[u,c]),p=(0,U.useMemo)(()=>({rows:d,activePresetId:r,isDebugMode:i,graphTaggedColumnIds:s,visibilityOverrides:l,addedColumnIds:f}),[d,r,i,s,l,f]),m=(0,U.useMemo)(()=>RX.getVisibleColumns(p),[p]),h=(0,U.useMemo)(()=>RX.getAvailableColumns(p),[p]),g=(0,U.useMemo)(()=>({...RX.getPreset(r).filters??{},...o}),[r,o]);return{rows:(0,U.useMemo)(()=>WX(UX(d,g,m,RX.definitions),a,m,RX.definitions),[d,g,a,m]),visibleColumns:m,availableColumns:h,graphTaggedColumnIds:(0,U.useMemo)(()=>Array.from(s??[]),[s])}}function BX(e,t){return e.map((e,n)=>{let r=new Map;if(e.metrics)for(let t of e.metrics)HX(r,t);let i=VX(e),a=i?t.get(i):void 0;if(a)for(let e of a)HX(r,e);for(let[,e]of r)e.hasUserOverride=e.metrics.some(e=>e.origin===`user`);let o=e.context?.outputType??e.type;return{id:e.id,index:n+1,sourceBlockKey:i??`segment-${e.id}`,sourceStatementId:e.context?.sourceStatementId,outputType:o,stackLevel:e.depth,absoluteStartTime:e.absoluteStartTime,duration:e.duration,elapsed:e.elapsed,total:e.total,spans:e.spans?[...e.spans]:[],completionReason:e.context?.completionReason,cells:r}})}function VX(e){let t=e.context;return t?.sourceBlockKey?t.sourceBlockKey:e.name}function HX(e,t){let n=t.type;if(n===q.Sound)return;let r=e.get(n);r?e.set(n,{metrics:r.metrics.clone().add(t),hasUserOverride:r.hasUserOverride}):e.set(n,{metrics:J.empty(n).add(t),hasUserOverride:!1})}function UX(e,t,n,r){let i=e;if(t.outputTypes&&t.outputTypes.length>0){let e=new Set(t.outputTypes);i=i.filter(t=>e.has(t.outputType))}if(t.origins&&t.origins.length>0){let e=new Set(t.origins);i=i.filter(t=>{for(let[,n]of t.cells)if(n.metrics.some(t=>t.origin&&e.has(t.origin)))return!0;return!1})}if(t.searchText&&t.searchText.trim().length>0){let a=t.searchText.trim().toLowerCase();i=i.filter(t=>{for(let i of n)if(i.filter&&EY(t,i,{allRows:e,rowIndex:e.indexOf(t),columnDef:i,dependencies:new Map},r).toLowerCase().includes(a))return!0;return!1})}if(t.columnFilters)for(let[a,o]of Object.entries(t.columnFilters)){if(!o||o.trim().length===0)continue;let t=n.find(e=>e.id===a);t&&(i=i.filter(n=>{let i={allRows:e,rowIndex:e.indexOf(n),columnDef:t,dependencies:new Map};return DY(n,t,o,i,r)}))}return i}function WX(e,t,n,r){if(t.length===0)return e;let i=[...e];return i.sort((i,a)=>{for(let o of t){let t=n.find(e=>e.id===o.columnId);if(!t||!t.sort)continue;let s={allRows:e,rowIndex:e.indexOf(i),columnDef:t,dependencies:new Map},c={allRows:e,rowIndex:e.indexOf(a),columnDef:t,dependencies:new Map},l=wY(CY(i,t,s,r),CY(a,t,c,r));if(l!==0)return o.direction===`asc`?l:-l}return i.index-a.index}),i}function GX(e,t){return{id:e,label:t.label,filters:t.filters??{},visibleColumns:[...t.visibleColumnIds],isDefault:e===LX.defaultPreset}}var KX=Object.fromEntries(Object.entries(LX.presets).map(([e,t])=>[e,GX(e,t)])),qX=KX.default;KX.debug,KX.strength,KX.endurance;function JX(e){return KX[e]??qX}var YX=({activePreset:e,onPresetChange:t,searchText:n,onSearchChange:r,showFilters:i,onToggleFilters:a,totalRows:o,visibleRows:s})=>(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-2 border-b border-border bg-muted/10 dark:bg-muted/5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(`label`,{className:`text-xs text-muted-foreground font-medium`,children:`View:`}),(0,W.jsx)(`select`,{className:`text-xs rounded border border-border bg-background text-foreground px-1.5 py-1 focus:outline-none focus:ring-1 focus:ring-primary/40`,value:e.id,onChange:e=>t(e.target.value),children:Object.values(KX).map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))})]}),(0,W.jsx)(`div`,{className:`w-px h-5 bg-border`}),(0,W.jsx)(`div`,{className:`flex items-center flex-1 max-w-md`,children:(0,W.jsxs)(`div`,{className:`flex w-full group`,children:[(0,W.jsx)(`input`,{type:`text`,className:`flex-1 px-2.5 py-1 text-xs rounded-l border border-r-0 border-border bg-background text-foreground placeholder:text-muted-foreground/40 focus:outline-none focus:ring-1 focus:ring-primary/40 focus:z-10`,placeholder:`Filter results…`,value:n,onChange:e=>r(e.target.value)}),(0,W.jsxs)(`button`,{className:`px-2.5 py-1 text-xs rounded-r border border-border bg-muted/30 text-muted-foreground hover:bg-muted/50 hover:text-foreground transition-colors flex items-center gap-1.5 border-l-0`,title:`Filter results`,children:[(0,W.jsx)(`span`,{children:`🔍`}),(0,W.jsx)(`span`,{className:`font-medium`,children:`Search`})]})]})}),(0,W.jsx)(`div`,{className:`w-px h-5 bg-border`}),(0,W.jsx)(`button`,{className:[`text-xs px-2 py-1 rounded border transition-colors`,i?`bg-primary/10 border-primary/30 text-primary`:`bg-muted/30 border-border text-muted-foreground hover:text-foreground`].join(` `),onClick:a,title:i?`Hide column filters`:`Show column filters`,children:`🔽 Filters`}),(0,W.jsx)(`div`,{className:`ml-auto text-xs text-muted-foreground tabular-nums`,children:s===o?`${o} rows`:`${s} / ${o} rows`})]}),XX={"#":`40px`,exercise:`180px`,text:`160px`,notes:`160px`,completionReason:`160px`,rep:`72px`,rounds:`72px`,"current-round":`72px`,duration:`96px`,distance:`96px`,resistance:`96px`,load:`96px`,volume:`96px`,intensity:`96px`,metric:`96px`,work:`96px`,elapsedTotal:`96px`,action:`96px`,increment:`96px`,timestamp:`96px`,spans:`96px`,blockKey:`180px`,outputType:`96px`,stackLevel:`72px`,elapsed:`96px`},ZX=`48px`;function QX(e){return e.meta?.width??XX[e.id]??`96px`}function $X(){return ZX}var eZ=({columns:e,sortConfigs:t,onSort:n,onToggleGraph:r,showFilters:i,columnFilters:a,onColumnFilterChange:o,availableToAdd:s,onAddColumn:c,graphTaggedColumnIds:l})=>(0,W.jsxs)(`thead`,{className:`bg-muted/50 dark:bg-muted/30 sticky top-0 z-10`,children:[(0,W.jsxs)(`tr`,{className:`border-b border-border`,children:[e.map(e=>(0,W.jsx)(tZ,{column:e,sortConfig:t.find(t=>t.columnId===e.id),onSort:n,onToggleGraph:r,isGraphed:l?.has(e.id)??!1},e.id)),c&&(0,W.jsx)(`th`,{className:`py-2 px-1`,style:{minWidth:$X()},children:(0,W.jsx)(rZ,{availableToAdd:s??[],onAddColumn:c})})]}),i&&(0,W.jsxs)(`tr`,{className:`border-b border-border/50 bg-muted/20 dark:bg-muted/10`,children:[e.map(e=>(0,W.jsx)(nZ,{column:e,value:a[e.id]??``,onChange:o},e.id)),c&&(0,W.jsx)(`th`,{className:`py-1 px-1`,style:{minWidth:$X()}})]})]}),tZ=({column:e,sortConfig:t,onSort:n,onToggleGraph:r,isGraphed:i})=>{let a=e.sort!==void 0,o=e.graph!==void 0,s=(0,U.useCallback)(t=>{a&&n(e.id,t.shiftKey)},[e.id,a,n]),c=(0,U.useCallback)(t=>{t.stopPropagation(),r(e.id)},[e.id,r]);return(0,W.jsx)(`th`,{className:[`py-1.5 px-2 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider whitespace-nowrap select-none`,a?`cursor-pointer hover:text-foreground transition-colors`:``].join(` `),style:{minWidth:QX(e)},onClick:s,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[e.icon&&(0,W.jsx)(`span`,{className:`text-sm`,children:e.icon}),(0,W.jsx)(`span`,{children:e.label}),t&&(0,W.jsx)(Iee,{direction:t.direction}),o&&(0,W.jsx)(`button`,{className:[`ml-auto text-sm opacity-40 hover:opacity-100 transition-opacity`,i?`opacity-100 text-primary`:``].join(` `),onClick:c,title:i?`Remove from graph`:`Add to graph`,children:`📊`})]})})},Iee=({direction:e})=>(0,W.jsx)(`span`,{className:`text-primary text-[10px] ml-0.5`,children:e===`asc`?`▲`:`▼`}),nZ=({column:e,value:t,onChange:n})=>e.filter?(0,W.jsx)(`th`,{className:`py-1 px-2`,style:{minWidth:QX(e)},children:(0,W.jsx)(`input`,{type:`text`,className:`w-full px-1.5 py-0.5 text-xs rounded border border-border bg-background text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-1 focus:ring-primary/40`,placeholder:`Filter…`,value:t,onChange:t=>n(e.id,t.target.value)})}):(0,W.jsx)(`th`,{className:`py-1 px-2`,style:{minWidth:QX(e)}}),rZ=({availableToAdd:e,onAddColumn:t})=>{let[n,r]=(0,U.useState)(!1),i=(0,U.useRef)(null),a=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(!n)return;let e=e=>{i.current&&!i.current.contains(e.target)&&a.current&&!a.current.contains(e.target)&&r(!1)};return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[n]),e.length===0?null:(0,W.jsxs)(`div`,{className:`relative flex items-center justify-center`,children:[(0,W.jsx)(`button`,{ref:a,title:`Add metric column`,onClick:e=>{e.stopPropagation(),r(e=>!e)},className:[`flex items-center justify-center w-5 h-5 rounded text-[11px] font-bold transition-all`,`text-muted-foreground hover:text-foreground hover:bg-primary/10 hover:border-primary/40`,`border border-dashed border-muted-foreground/40`,n?`bg-primary/10 border-primary/40 text-foreground`:``].join(` `),children:`+`}),n&&(0,W.jsxs)(`div`,{ref:i,className:`absolute right-0 top-full mt-1 z-50 min-w-[160px] max-h-64 overflow-y-auto
157
157
  bg-popover border border-border rounded-md shadow-xl py-1`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(`div`,{className:`px-3 py-1.5 text-[10px] font-semibold text-muted-foreground uppercase tracking-wider border-b border-border/50 mb-1`,children:`Add metric column`}),e.map(e=>{let n=YU(e)??`•`,i=Fo.columnLabel(e);return(0,W.jsxs)(`button`,{onClick:()=>{t(e),r(!1)},className:`w-full flex items-center gap-2 px-3 py-1.5 text-xs hover:bg-muted text-foreground transition-colors`,children:[(0,W.jsx)(`span`,{className:`text-sm w-4 text-center`,children:n}),(0,W.jsx)(`span`,{children:i})]},e)})]})]})},iZ=({row:e,allRows:t,rowIndex:n,columns:r,isSelected:i,onSelect:a,isHovered:o,onHover:s,onCellDoubleClick:c})=>{let l=t=>{a(e.id,{ctrlKey:t.ctrlKey||t.metaKey,shiftKey:t.shiftKey})},u=e.outputType===`group`;return(0,W.jsx)(`tr`,{className:G(`border-b border-border transition-colors cursor-pointer`,u?`bg-muted/50 font-bold`:``,i?`bg-accent dark:bg-accent/20`:o?`bg-muted/50 dark:bg-muted/40`:`hover:bg-muted/30 dark:hover:bg-muted/20`),onClick:l,onMouseEnter:()=>s(e.sourceBlockKey),onMouseLeave:()=>s(null),children:r.map(r=>{let i=r.source.type===`metric-type`&&r.source.metricType===q.Effort;return(0,W.jsx)(kY,{columnDef:r,row:e,allRows:t,rowIndex:n,indent:i?e.stackLevel:0,onDoubleClick:c,style:{minWidth:QX(r)}},r.id)})})};function aZ(e){let{rows:t,columns:n,graphTaggedColumnIds:r,definitionMap:i}=e,a=(0,U.useMemo)(()=>oZ(r,n),[r,n]),o=(0,U.useMemo)(()=>sZ(t,r,n,i),[t,r,n,i]);return{data:o,graphConfigs:a,hasData:a.length>0&&o.length>0}}function oZ(e,t){let n=[];for(let r of e){let e=t.find(e=>e.id===r);e&&n.push({id:r,label:e.label,unit:dZ(e),color:cZ(e),dataKey:r,icon:e.icon})}return n}function sZ(e,t,n,r){return t.length===0?[]:e.map((i,a)=>{let o={index:i.index,label:i.sourceBlockKey};for(let s of t){let t=n.find(e=>e.id===s);if(!t||!t.graph){o[s]=0;continue}o[s]=TY(i,t,{allRows:e,rowIndex:a,columnDef:t,dependencies:new Map},r)??0}return o})}function cZ(e){if(e.graph?.color)return e.graph.color;let t=lZ(e);return t?uZ[t]??`#888888`:`#888888`}function lZ(e){if(e.source.type===`metric-type`)return e.source.metricType}var uZ={[q.Time]:`#3b82f6`,[q.Rep]:`#22c55e`,[q.Effort]:`#eab308`,[q.Distance]:`#14b8a6`,[q.Rounds]:`#a855f7`,[q.Resistance]:`#ef4444`,[q.Increment]:`#6366f1`,[q.Action]:`#ec4899`};function dZ(e){if(e.graph?.unit)return e.graph.unit;let t=lZ(e);if(!t)return``;switch(t){case q.Time:return`ms`;case q.Rep:return`reps`;case q.Distance:return`m`;case q.Rounds:return`rounds`;case q.Resistance:return`kg`;case q.Increment:return`Δ`;default:return``}}var fZ=({rows:e,columns:t,graphTaggedColumnIds:n,selectedIds:r,onSelectRow:i})=>{let[a,o]=(0,U.useState)(!1),{data:s,graphConfigs:c,hasData:l}=aZ({rows:e,columns:t,graphTaggedColumnIds:n,selectedIds:r}),u=(0,U.useCallback)(t=>{if(!t?.activePayload?.[0])return;let n=t.activePayload[0].payload,r=e.find(e=>e.index===n.index);r&&i&&i(r.id)},[e,i]);return n.length===0?null:(0,W.jsxs)(`div`,{className:`border-b border-border bg-background`,children:[(0,W.jsxs)(`button`,{className:`w-full flex items-center justify-between px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground hover:bg-muted/20 transition-colors`,onClick:()=>o(e=>!e),children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{children:`📊`}),(0,W.jsxs)(`span`,{children:[`Graph — `,c.map(e=>e.label).join(`, `)]})]}),(0,W.jsx)(`span`,{className:`text-[10px]`,children:a?`▼`:`▲`})]}),!a&&(0,W.jsx)(`div`,{className:`px-3 pb-3`,children:l?(0,W.jsx)(`div`,{className:`w-full bg-muted/30 rounded-lg border border-border p-2`,style:{height:220},children:(0,W.jsx)(zn,{width:`100%`,height:`100%`,children:(0,W.jsxs)(jn,{data:s,onClick:u,children:[(0,W.jsx)(Te,{strokeDasharray:`3 3`,stroke:`hsl(var(--border))`,vertical:!1}),(0,W.jsx)(nt,{dataKey:`index`,stroke:`hsl(var(--muted-foreground))`,tick:{fontSize:10},label:{value:`Row #`,position:`insideBottom`,offset:-5,fill:`hsl(var(--muted-foreground))`,fontSize:10}}),(0,W.jsx)(R,{stroke:`hsl(var(--muted-foreground))`,tick:{fontSize:10},domain:[`auto`,`auto`]}),(0,W.jsx)(Yn,{contentStyle:{backgroundColor:`hsl(var(--popover))`,borderColor:`hsl(var(--border))`,fontSize:`12px`,color:`hsl(var(--popover-foreground))`},labelFormatter:e=>`Row ${e}`,formatter:(e,t)=>{let n=c.find(e=>e.dataKey===t);return[`${typeof e==`number`?e.toLocaleString():e}${n?.unit?` ${n.unit}`:``}`,n?.label??t]}}),(0,W.jsx)(bn,{verticalAlign:`top`,height:24,wrapperStyle:{fontSize:`11px`}}),c.map(e=>(0,W.jsx)(ot,{type:`monotone`,dataKey:e.dataKey,name:e.label,stroke:e.color,strokeWidth:2,dot:{r:3,fill:e.color},activeDot:{r:5,stroke:e.color,strokeWidth:2}},e.id))]})})}):(0,W.jsx)(`div`,{className:`h-32 flex items-center justify-center text-sm text-muted-foreground`,children:`No numeric data available for the tagged columns.`})})]})},pZ=({isOpen:e,blockKey:t,metricType:n,existingFragments:r,existingUserValue:i,anchorRect:a,onSave:o,onRemove:s,onClose:c})=>{let[l,u]=(0,U.useState)(``),d=(0,U.useRef)(null),f=(0,U.useRef)(null);(0,U.useEffect)(()=>{e&&(u(i===void 0?``:String(i)),setTimeout(()=>d.current?.focus(),0))},[e,i]),(0,U.useEffect)(()=>{if(!e)return;let t=e=>{e.key===`Escape`&&c()};return document.addEventListener(`keydown`,t),()=>document.removeEventListener(`keydown`,t)},[e,c]),(0,U.useEffect)(()=>{if(!e)return;let t=e=>{f.current&&!f.current.contains(e.target)&&c()},n=setTimeout(()=>{document.addEventListener(`mousedown`,t)},100);return()=>{clearTimeout(n),document.removeEventListener(`mousedown`,t)}},[e,c]);let p=(0,U.useCallback)(()=>{if(l.trim()===``)return;let e=Number(l.trim()),r=!isNaN(e)&&l.trim()!==``?e:l.trim();o(t,n,r,String(r)),c()},[l,t,n,o,c]),m=(0,U.useCallback)(()=>{s(t,n),c()},[t,n,s,c]),h=(0,U.useCallback)(e=>{e.key===`Enter`&&(e.preventDefault(),p())},[p]);if(!e)return null;let g=YU(n),_=qU(n),v=i!==void 0,y=r.filter(e=>e.origin!==`user`),b=a?{position:`fixed`,top:a.bottom+4,left:Math.max(8,Math.min(a.left,window.innerWidth-280)),zIndex:50}:{position:`fixed`,top:`50%`,left:`50%`,transform:`translate(-50%, -50%)`,zIndex:50};return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`fixed inset-0 bg-black/20 dark:bg-black/40 z-40`}),(0,W.jsxs)(`div`,{ref:f,className:`w-64 rounded-lg border border-border bg-popover text-popover-foreground shadow-lg`,style:b,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-b border-border`,children:[g&&(0,W.jsx)(`span`,{className:`text-sm`,children:g}),(0,W.jsx)(`span`,{className:`text-sm font-medium capitalize`,children:n}),(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground ml-auto truncate max-w-[100px]`,title:t,children:t})]}),y.length>0&&(0,W.jsxs)(`div`,{className:`px-3 py-1.5 border-b border-border/50 bg-muted/10`,children:[(0,W.jsx)(`div`,{className:`text-[10px] text-muted-foreground mb-1 uppercase tracking-wider`,children:`Current`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:y.map((e,t)=>(0,W.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded text-xs border ${_}`,children:e.image??String(e.value??e.type)},t))})]}),(0,W.jsxs)(`div`,{className:`px-3 py-2`,children:[(0,W.jsx)(`label`,{className:`text-[10px] text-muted-foreground uppercase tracking-wider mb-1 block`,children:v?`Update override`:`Enter value`}),(0,W.jsx)(`input`,{ref:d,type:`text`,className:`w-full px-2 py-1.5 text-sm rounded border border-border bg-background text-foreground placeholder:text-muted-foreground/50 focus:outline-none focus:ring-2 focus:ring-primary/40`,placeholder:`Enter ${n} value…`,value:l,onChange:e=>u(e.target.value),onKeyDown:h})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 px-3 py-2 border-t border-border/50`,children:[(0,W.jsx)(`button`,{className:`flex-1 px-2 py-1 text-xs rounded border border-border text-muted-foreground hover:text-foreground hover:bg-muted/30 transition-colors`,onClick:c,children:`Cancel`}),v&&(0,W.jsx)(`button`,{className:`px-2 py-1 text-xs rounded border border-destructive/30 text-destructive hover:bg-destructive/10 transition-colors`,onClick:m,title:`Remove user override`,children:`Clear`}),(0,W.jsx)(`button`,{className:`flex-1 px-2 py-1 text-xs rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors disabled:opacity-50`,onClick:p,disabled:l.trim()===``,children:`Save`})]})]})]})},mZ=({segments:e,selectedSegmentIds:t,onSelectSegment:n,userOutputOverrides:r=new Map,gridViewPreset:i=`default`,onPresetChange:a,hoveredBlockKey:o,onHoverBlockKey:s})=>{let{isDebugMode:c}=Oy(),[l,u]=(0,U.useState)([]),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)({}),[h,g]=(0,U.useState)(!1),[_,v]=(0,U.useState)(new Set),[y,b]=(0,U.useState)({}),[x,S]=(0,U.useState)(new Set),{overrides:C,setOverride:w,removeOverride:T}=lK(!0),[E,D]=(0,U.useState)({isOpen:!1,blockKey:``,type:`Time`,anchorRect:null,existingFragments:[]}),O=(0,U.useMemo)(()=>{let e=new Map;for(let[t,n]of r)e.set(t,n instanceof J?n:J.from(n,t));for(let[t,n]of C)e.set(t,n);return e},[r,C]),k=c?`debug`:i,A=(0,U.useMemo)(()=>JX(k),[k]),{rows:j,visibleColumns:M,availableColumns:N,graphTaggedColumnIds:P}=zX({segments:e,userOutputOverrides:O,presetId:k,isDebugMode:c,sortConfigs:l,filterOverrides:(0,U.useMemo)(()=>({searchText:d||void 0,columnFilters:Object.keys(p).length>0?p:void 0}),[d,p]),graphTaggedColumns:_,extraMetricTypes:x,columnVisibilityOverrides:y,addedColumnIds:x}),F=M,I=e.length,L=(0,U.useMemo)(()=>j.map(e=>e.id),[j]),ee=(0,U.useCallback)((e,t)=>{u(n=>{let r=n.find(t=>t.columnId===e);return t?r?r.direction===`asc`?n.map(t=>t.columnId===e?{...t,direction:`desc`}:t):n.filter(t=>t.columnId!==e):[...n,{columnId:e,direction:`asc`}]:r?r.direction===`asc`?[{columnId:e,direction:`desc`}]:[]:[{columnId:e,direction:`asc`}]})},[]),te=(0,U.useCallback)(e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),ne=(0,U.useCallback)((e,t)=>{m(n=>{if(!t){let t={...n};return delete t[e],t}return{...n,[e]:t}})},[]),R=(0,U.useCallback)(e=>{b({}),m({}),f(``),a?.(e)},[a]),re=(0,U.useCallback)(e=>{S(t=>{let n=new Set(t);return n.add(e),n})},[]),ie=(0,U.useMemo)(()=>N.filter(e=>e.source.type===`metric-type`).map(e=>e.source.metricType),[N]),ae=(0,U.useCallback)((e,t)=>{n(e,t,L)},[n,L]),oe=(0,U.useCallback)(e=>{s?.(e)},[s]),se=(0,U.useCallback)(e=>{n(e,{ctrlKey:!1,shiftKey:!1},L)},[n,L]),ce=(0,U.useCallback)((e,t,n)=>{let r=(j.find(t=>t.sourceBlockKey===e)?.cells.get(t))?.metrics.toArray()??[],i=r.find(e=>e.origin===`user`),a=i?.value==null?void 0:String(i.value);D({isOpen:!0,blockKey:e,type:t,anchorRect:n,existingFragments:r,existingUserValue:a})},[j]),le=(0,U.useCallback)((e,t,n,r)=>{w(e,t,n,r),D(e=>({...e,isOpen:!1}))},[w]),z=(0,U.useCallback)(()=>{T(E.blockKey,E.type),D(e=>({...e,isOpen:!1}))},[E.blockKey,E.type,T]),ue=(0,U.useCallback)(()=>{D(e=>({...e,isOpen:!1}))},[]);return(0,W.jsxs)(`div`,{className:`h-full flex flex-col bg-background`,children:[(0,W.jsx)(YX,{activePreset:A,onPresetChange:R,searchText:d,onSearchChange:f,showFilters:h,onToggleFilters:()=>g(e=>!e),totalRows:I,visibleRows:j.length}),(0,W.jsx)(fZ,{rows:j,columns:M,graphTaggedColumnIds:P,selectedIds:t,onSelectRow:se}),(0,W.jsx)(`div`,{className:`flex-1 overflow-auto`,children:(0,W.jsxs)(`table`,{className:`text-left text-sm border-collapse min-w-[700px]`,children:[(0,W.jsx)(eZ,{columns:F,sortConfigs:l,onSort:ee,onToggleGraph:te,showFilters:h,columnFilters:p,onColumnFilterChange:ne,availableToAdd:ie,onAddColumn:re,graphTaggedColumnIds:_}),(0,W.jsx)(`tbody`,{className:`divide-y divide-border`,children:j.length===0?(0,W.jsx)(`tr`,{children:(0,W.jsx)(`td`,{colSpan:F.length,className:`py-8 text-center text-muted-foreground text-sm`,children:e.length===0?`Finish or stop the timer — results land here`:`No rows match the current filters.`})}):j.map((e,n)=>(0,W.jsx)(iZ,{row:e,allRows:j,rowIndex:n,columns:F,isSelected:t.has(e.id),onSelect:ae,isHovered:o===e.sourceBlockKey,onHover:oe,onCellDoubleClick:ce},e.id))})]})}),(0,W.jsx)(pZ,{isOpen:E.isOpen,blockKey:E.blockKey,metricType:E.type,existingFragments:E.existingFragments,existingUserValue:E.existingUserValue,anchorRect:E.anchorRect??void 0,onSave:le,onRemove:z,onClose:ue}),(0,W.jsxs)(`div`,{className:`px-3 py-1.5 border-t border-border bg-muted/10 text-xs text-muted-foreground flex items-center justify-between`,children:[(0,W.jsx)(`span`,{children:t.size>0?`${t.size} selected`:`Click a row to select`}),(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[j.length,` / `,I,` rows`]})]})]})};Xt();var hZ=({title:e,onClose:t,children:n,closeButtonClassName:r,floatingClose:i=!1,variant:a=`default`,actions:o,closeLabel:s})=>{(0,U.useEffect)(()=>(document.body.style.overflow=`hidden`,()=>{document.body.style.overflow=``}),[]);let c=U.useRef(null);(0,U.useEffect)(()=>{let e=document.activeElement;return c.current?.focus({preventScroll:!0}),()=>e?.focus({preventScroll:!0})},[]);let l=e=>{if(e.key!==`Tab`||!c.current)return;let t=Array.from(c.current.querySelectorAll(`button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])`)).filter(e=>e.offsetParent!==null);if(t.length===0){e.preventDefault();return}let n=document.activeElement,r=t[0],i=t[t.length-1];e.shiftKey&&(n===r||n===c.current||!c.current.contains(n))?(e.preventDefault(),i.focus()):!e.shiftKey&&n===i&&(e.preventDefault(),r.focus())},u=a===`minimal`,d=(0,W.jsx)(`button`,{onClick:t,className:r??`rounded-pill transition-colors shadow-[rgba(0,0,0,0.06)_0px_1px_2px] ${u?`bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground`:`bg-muted/50 hover:bg-muted text-muted-foreground hover:text-foreground`} ${s?`flex h-11 min-w-[44px] items-center justify-center px-4 text-sm font-medium hover:text-foreground`:`p-2`}`,title:s??`Close`,"data-testid":BU.FOCUSED_DIALOG_CLOSE,children:s??(0,W.jsx)(we,{className:`h-5 w-5`})});return TC.createPortal((0,W.jsxs)(`div`,{ref:c,onKeyDown:l,tabIndex:-1,role:`dialog`,"aria-modal":`true`,"aria-label":e??`Workout`,className:`fixed inset-0 z-[100] flex flex-col bg-background text-foreground outline-none animate-in fade-in duration-200`,children:[i||u&&!e?(0,W.jsxs)(`div`,{className:`absolute top-4 right-4 z-[110] flex items-center gap-2`,children:[o,d]}):e?(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-border ${u?`bg-muted/10`:`bg-muted/30`} shrink-0`,children:[(0,W.jsx)(`h2`,{className:`text-lg ${u?`font-black tracking-tight uppercase text-[11px] text-muted-foreground`:`font-semibold`}`,children:e}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[o,d]})]}):null,(0,W.jsx)(`div`,{className:`flex-1 min-h-0 overflow-hidden flex flex-col`,children:n})]}),document.body)},gZ=(0,U.createContext)({updateFromSegments:()=>{},clear:()=>{}}),_Z=({children:e,chromecastSubscription:t=null})=>(0,W.jsx)(gZ.Provider,{value:{updateFromSegments:(e,n,r)=>{t&&t.sendAnalyticsSummary([],n,r)},clear:()=>{}},children:e}),vZ=new class{resolve(e){let t=this.resolveMode(e);return t===`active`?{type:`rpc-workbench-update`,mode:`active`}:t===`review`?aK(e.analyticsSegments):sK(e.selectedBlock,e.documentItems)}resolveMode(e){return e.viewMode===`track`?e.runtime&&(e.executionStatus===`running`||e.executionStatus===`paused`)?`active`:e.analyticsSegments.length>0?`review`:e.runtime?`active`:`preview`:e.viewMode===`review`&&e.analyticsSegments.length>0?`review`:`preview`}};function yZ(){if(!(`wakeLock`in navigator))return;let e=navigator.wakeLock;if(!(typeof e!=`object`||!e||!(`request`in e)))return e}function bZ(e){let t=(0,U.useRef)(null);(0,U.useEffect)(()=>{let n=yZ();if(!n||!e)return;let r=!1,i=async()=>{if(document.visibilityState===`visible`)try{let e=await n.request(`screen`);if(r){e.release();return}t.current=e,e.addEventListener(`release`,()=>{t.current===e&&(t.current=null)})}catch{}},a=()=>{document.visibilityState===`visible`&&!t.current&&i()};return i(),document.addEventListener(`visibilitychange`,a),()=>{r=!0,document.removeEventListener(`visibilitychange`,a);let e=t.current;t.current=null,e&&!e.released&&e.release()}},[e])}function xZ(e){if(e instanceof Error)return e.message;if(typeof e==`object`&&e){let{code:t,description:n}=e;if(t!==void 0||n!==void 0)return[t===void 0?null:String(t),n?String(n):null].filter(e=>e!==null).join(`: `)||`unknown`;try{return JSON.stringify(e)}catch{return String(e)}}return String(e)}var SZ=``,CZ=null,wZ=()=>{let e=tG(),[t,n]=(0,U.useState)(e.state),[r,i]=(0,U.useState)(!1);bZ(r);let[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(null),d=(0,U.useRef)(null),p=yR,m=(0,U.useRef)(p.getActiveHandle()),h=(0,U.useRef)(!1),g=(0,U.useCallback)(e=>{let t=m.current;m.current=null,t&&p.dispose(e),HA(null),u(null),c(null),i(!1)},[p]),_=(0,U.useCallback)(async e=>{if(!h.current){h.current=!0;try{let t=OB.getState().subscriptionManager,n=p.connect(e,t);m.current=n,u(n),c(n.subscription),i(!0),HA(n.transport),n.eventProvider.onEvent(e=>{if(e.name===`clock-command`){let t=QG(e.data);if(!t){console.warn(`[CastButtonRpc] Dropped malformed clock-command payload`);return}yG(t.runId,t.command)||console.warn(`[CastButtonRpc] Clock command rejected by authority:`,t.command.kind);return}let t=_G(),n=$G(e.name,t);n&&t&&!yG(t.runId,n)&&console.warn(`[CastButtonRpc] Legacy receiver event rejected by authority:`,e.name)});let r=OB.getState(),a=vZ.resolve({viewMode:r.viewMode,executionStatus:r.execution.status,runtime:r.runtime,analyticsSegments:r.analyticsSegments,selectedBlock:r.selectedBlock,documentItems:r.documentItems});n.pushInitialWorkbench(a)}finally{h.current=!1}}},[p]),v=(0,U.useRef)(!1),y=(0,U.useCallback)(async()=>{if(p.isConnected&&p.getActiveHandle()){let e=p.getActiveHandle();m.current=e,u(e),c(e.subscription),i(!0);return}if(!(m.current||v.current)&&typeof e.resumeSession==`function`){v.current=!0;try{let t=await e.resumeSession();await _(t)}catch(t){console.warn(`[CastButtonRpc] Session resume failed:`,xZ(t)),g(!1),e.endSession()}finally{v.current=!1}}},[e,_,g,p]);(0,U.useEffect)(()=>e.onStateChanged(e=>{n(e),e===`session-active`?(i(!0),y()):e===`ready`||e===`unavailable`?i(!1):e===`session-ended`&&g(!1)}),[e,g,y]),(0,U.useEffect)(()=>{if(p.isConnected&&p.getActiveHandle()){let e=p.getActiveHandle();m.current=e,u(e),c(e.subscription),i(!0)}else e.state===`session-active`&&y()},[e,p]),(0,U.useEffect)(()=>{let e=l?.transport;if(!e)return;let t=()=>{let t=_G(),n=JSON.stringify(t);if(n!==SZ||e!==CZ){SZ=n,CZ=e;try{e.send({type:`rpc-clock-snapshot`,snapshot:t})}catch{}}};return t(),vG(t)},[l]),(0,U.useEffect)(()=>{let e=()=>{p.sendDisposeSignal()};return window.addEventListener(`pagehide`,e),()=>window.removeEventListener(`pagehide`,e)},[p]),(0,U.useEffect)(()=>{let t=d.current;if(!t)return;let n=async()=>{if(b.current===`session-active`){if(x.current)return;o(!0);try{g(!0),e.endSession()}finally{setTimeout(()=>o(!1),2e3)}return}try{let t=await e.startSession();i(!0),await _(t)}catch(e){let t=xZ(e);t===`cancel`||t.includes(`cancel`)?console.log(`[CastButtonRpc] Cast request canceled or gesture expired`):console.error(`[CastButtonRpc] Cast failed:`,t),g(!1)}};return t.addEventListener(`click`,n),()=>t.removeEventListener(`click`,n)},[e,_,g]);let b=(0,U.useRef)(t);b.current=t;let x=(0,U.useRef)(a);x.current=a;let S=t===`unavailable`,C=t===`ready`,w=t===`session-active`,T=t===`connecting`,E=r&&w,D=T,O=D||a,k=C||w;return S?(0,W.jsxs)(K,{variant:`ghost`,size:`icon`,disabled:!0,className:`opacity-20 cursor-not-allowed`,"aria-label":`Cast to TV (unavailable)`,title:`Cast to TV (unavailable)`,children:[(0,W.jsx)(Bt,{className:`h-5 w-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Cast to TV (unavailable)`})]}):(0,W.jsx)(qA,{transport:l?.transport??null,children:(0,W.jsx)(_Z,{chromecastSubscription:s,children:(0,W.jsxs)(K,{ref:d,variant:`ghost`,size:`icon`,disabled:O,onClick:()=>{},className:G(`transition-all`,E&&`text-signal-positive ring-2 ring-signal-positive/30`,D&&`animate-pulse text-signal-caution`,!k&&`opacity-50`),"aria-label":E?`Stop casting`:`Cast to TV`,title:E?`Stop casting`:D?`Connecting...`:`Cast to TV`,children:[E?(0,W.jsx)(f,{className:`h-5 w-5`}):(0,W.jsx)(Bt,{className:`h-5 w-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:E?`Stop casting`:`Cast to TV`})]})})})};function TZ(){let{isEnabled:e,toggleAudio:t}=ZA();return(0,W.jsxs)(K,{variant:`ghost`,size:`icon`,onClick:t,className:`h-9 w-9 text-muted-foreground hover:text-foreground`,title:e?`Mute audio`:`Enable audio`,children:[e?(0,W.jsx)(fe,{className:`h-[1.2rem] w-[1.2rem]`}):(0,W.jsx)(ne,{className:`h-[1.2rem] w-[1.2rem]`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Toggle audio`})]})}async function EZ(e,t={}){let{resultId:n,occurrence:r,metric:i}=e;if(!n||typeof n!=`string`)throw TypeError(`captureMetricCorrection: resultId is required`);if(!r?.blockKey||typeof r.blockKey!=`string`)throw TypeError(`captureMetricCorrection: occurrence.blockKey is required`);if(!i||typeof i.image!=`string`||i.image.length===0)throw TypeError(`captureMetricCorrection: metric.image is required`);if(typeof i.value!=`number`||!Number.isFinite(i.value))throw RangeError(`captureMetricCorrection: metric.value must be finite, got ${i.value}`);if(i.type===q.Rep&&(!Number.isSafeInteger(i.value)||i.value<0))throw RangeError(`captureMetricCorrection: rep corrections must be nonnegative safe integers, got ${i.value}`);let a=t.storage??Z,o=t.persistence??new cP(a);if(!await a.getSessionById(n)||await a.withTransaction([`events`],async e=>{let t=(await e.getEventsByResult(n)).filter(e=>e.grain===`event`&&e.outputType===`segment`&&e.sourceBlockKey===r.blockKey&&(r.sourceStatementId===void 0||e.sourceStatementId===r.sourceStatementId)&&(r.stackLevel===void 0||e.stackLevel===r.stackLevel));if(t.length===0)return`not-found`;if(t.length>1)throw Error(`captureMetricCorrection: ambiguous occurrence ${r.blockKey} in result ${n} — ${t.length} segments match; pass sourceStatementId/stackLevel`);let a=t[0],o=[...a.metrics.filter(e=>e.origin!==`user`||e.type!==i.type),{type:i.type,value:i.value,image:i.image,origin:`user`,timestamp:new Date}],s=a.timeSpan?.started??a.timestamp,c={...a,metrics:o,...a.metricTemporal?{metricTemporal:o.map(()=>({temporalKind:`instant`,instant:s}))}:{}};return await e.appendEvents([c]),`captured`})===`not-found`)return`not-found`;try{return await o.rederiveResultAnalytics(n),`captured`}catch(e){if(e instanceof sb&&e.code===`BLOCK_REVISION_NOT_FOUND`)return`captured-no-rederive`;throw e}}var DZ=new Map,OZ=({block:e,prepareRun:t,view:n,onClose:r,onCompleteWorkout:i,resultId:a,autoStart:o,onRuntimeReady:s,onRunStarted:c,externalStop:l,adoptRuntime:u,parkOnUnmount:d,onPark:f})=>{let[p,m]=(0,U.useState)(t?null:e),[h,g]=(0,U.useState)(null),_=(0,U.useRef)(!1),v=(0,U.useCallback)(async()=>{if(!(!t||_.current)){_.current=!0,g(null);try{m(await t())}catch(e){g(e instanceof Error?e.message:String(e))}finally{_.current=!1}}},[t]);(0,U.useEffect)(()=>{v()},[v]);let[y,b]=(0,U.useState)(null),[x,S]=(0,U.useState)(new Set),{isDebugMode:C}=Oy(),w=(0,U.useRef)(Date.now()),T=(0,U.useRef)(typeof document<`u`?document.title:`Wod.Wiki`),E=(0,U.useRef)(null);(0,U.useEffect)(()=>{let t=e.label||e.id,n=y!==null,r=n?`Wod.Wiki - Workout Complete${t?`: `+t:``}`:`Wod.Wiki - Workout Timer${t?`: `+t:``}`,i=n?`/workout/review`:`/workout/timer`;document.title=r,E.current!==i&&(E.current=i,window.gtag?.(`event`,`page_view`,{page_title:r,page_path:i,page_location:typeof window<`u`?window.location.href:i,engagement_time_msec:uq()}));let a=dq.consent;n?a&&window.gtag?.(`event`,`runtime_dialog_review`,{workout_label:t,block_type:e.blockType}):(dq.record(`runtime:dialog_loaded`,{workout_label:t,block_type:e.blockType}),a&&window.gtag?.(`event`,`runtime_dialog_loaded`,{workout_label:t,block_type:e.blockType}))},[e.id,e.label,e.blockType,y]),(0,U.useEffect)(()=>{let t=T.current,n=e.label||e.id;return()=>{let e=Date.now()-w.current;e>=1e3&&window.gtag?.(`event`,`runtime_dialog_closed`,{workout_label:n,duration_seconds:Math.round(e/1e3),engagement_time_msec:e}),typeof document<`u`&&(document.title=t)}},[e.id,e.label]);let D=(0,U.useRef)(!1),O=(0,U.useRef)(!1),k=(0,U.useRef)(!1),[A,j]=(0,U.useState)(!1),[M,N]=(0,U.useState)(!1),P=(0,U.useRef)(!1),F=(0,U.useRef)(!1),I=(0,U.useRef)(null),[L,ee]=(0,U.useState)(`idle`),[te,ne]=(0,U.useState)(null),[R,re]=(0,U.useState)(!1),{collectionItems:ie}=NK(y??[],DZ,null),[ae,oe]=(0,U.useState)(new Set),[se,ce]=(0,U.useState)(new Set),[le,z]=(0,U.useState)(!1),ue=(0,U.useMemo)(()=>ie.filter(e=>{let t=yK(e);return!ae.has(t)&&!se.has(t)}),[ie,ae,se]),de=y!==null&&!!a&&ue.length>0&&!le,fe=(0,U.useCallback)(async(e,t)=>{if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid value`);if(e.kind!==`value`)throw Error(`Unsupported entry`);if(!a)throw Error(`The saved run is unavailable.`);if(await EZ({resultId:a,occurrence:{blockKey:e.blockKey,...e.sourceStatementId===void 0?{}:{sourceStatementId:e.sourceStatementId},...e.stackLevel===void 0?{}:{stackLevel:e.stackLevel}},metric:{type:e.metricType,value:t,image:String(t)}})===`not-found`)throw Error(`This result entry could not be found — retry or skip.`);let{segments:n}=nR(Yg(await Z.getEventsByResult(a)).map(e=>JN(new ha(e))));b(n),oe(t=>new Set(t).add(yK(e)))},[a]),B=(0,U.useCallback)(e=>{ce(t=>new Set(t).add(yK(e)))},[]),pe=(0,U.useMemo)(()=>y===null||de?null:{runId:a?`result:${a}`:`review`,phase:`review`,status:`idle`,canNext:!1,canStop:!1,stopRequested:!1,reps:[],selectedOccurrenceId:null,entry:null,error:null,saving:!1},[y,de,a]),me=async()=>{let e=I.current;if(!e||P.current)return;P.current=!0,F.current=!1,ee(`saving`),ne(null);let t;try{t=i?.(e.blockId,e.results),await t}catch(e){F.current=!0,ne(e instanceof Error?e.message:String(e)),ee(`error`),P.current=!1;return}P.current=!1,ee(`idle`),re(!0);let{results:n}=e;if(n.logs&&n.logs.length>0)try{let{segments:e}=nR(n.logs,n.startTime);b(e)}catch{b([])}else n.completed?b([]):k.current&&r()},he=(0,U.useCallback)(()=>{D.current=!0,c?.()},[c]),ge=()=>{if(P.current||F.current){k.current=!0;return}if(y!==null||O.current||!D.current){r();return}if(!A&&!l){N(!0);return}k.current=!0,j(!0)},_e=()=>{N(!1),k.current=!0,j(!0)},ve=(0,U.useRef)(ge);ve.current=ge,nG(pe,(0,U.useCallback)(e=>e.kind===`dismiss`&&(ve.current(),!0),[]),20,{keyboard:!0});let ye=(e,t)=>{O.current||(O.current=!0,I.current={blockId:e,results:t},me())},be=(e,t,n)=>{S(r=>{let i=new Set(r);if(t?.ctrlKey)i.has(e)?i.delete(e):i.add(e);else if(t?.shiftKey&&n){let t=Array.from(r).pop();if(t!==void 0){let r=n.indexOf(t),a=n.indexOf(e);if(r!==-1&&a!==-1){let e=Math.min(r,a),t=Math.max(r,a);for(let r=e;r<=t;r++)i.add(n[r])}else i.add(e)}else i.add(e)}else i.clear(),i.add(e);return i})},xe=L===`idle`?null:(0,W.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3 border-b border-border bg-muted/20 px-6 py-2 text-sm`,children:[L===`saving`&&(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Saving…`}),L===`error`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`span`,{role:`alert`,className:`text-destructive`,children:[`Save failed`,te?` — ${te}`:``]}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>void me(),className:`rounded-pill border border-border px-3 py-1 text-xs font-medium text-foreground transition-colors hover:bg-accent`,children:`Retry save`})]})]});return p?y===null?(0,W.jsx)(hZ,{onClose:ge,title:`Workout`,closeLabel:`Exit`,actions:(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,onClick:ge,title:`Stop Session`,className:`flex h-11 min-w-[44px] items-center justify-center rounded-pill bg-muted/50 px-4 text-sm font-medium text-muted-foreground shadow-[rgba(0,0,0,0.06)_0px_1px_2px] transition-colors hover:bg-muted hover:text-foreground`,children:`Stop`}),(0,W.jsx)(wZ,{}),(0,W.jsx)(TZ,{})]}),children:(0,W.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[xe,h?(0,W.jsxs)(`div`,{className:`space-y-2 p-4`,children:[(0,W.jsxs)(`p`,{role:`alert`,children:[`Workout not started. `,h]}),(0,W.jsx)(`button`,{type:`button`,className:`rounded border px-3 py-2 hover:bg-accent focus-visible:ring-2`,onClick:()=>void v(),children:`Retry starting workout`})]}):p?null:(0,W.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`p-4`,children:`Saving workout before starting…`}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,W.jsx)(rq,{block:p,view:n,onClose:ge,onComplete:ye,isExpanded:!0,autoStart:o,onRuntimeReady:s,onRunStarted:he,externalStop:l||A,adoptRuntime:u,parkOnUnmount:d,onPark:f})}),M&&(0,W.jsx)(hZ,{title:`Stop workout?`,onClose:()=>N(!1),closeLabel:`Keep going`,actions:void 0,children:(0,W.jsxs)(`div`,{className:`space-y-4 p-6`,children:[(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The run stops now and your partial results are kept.`}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-3`,children:[(0,W.jsx)(`button`,{type:`button`,"data-testid":`stop-cancel`,onClick:()=>N(!1),className:`rounded-lg border border-border px-4 py-2 text-sm font-medium text-foreground transition-colors hover:bg-accent`,children:`Keep going`}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`stop-confirm`,onClick:_e,className:`rounded-lg bg-destructive px-4 py-2 text-sm font-bold text-destructive-foreground transition-colors hover:brightness-110`,children:`Stop — keep partial results`})]})]})})]})}):(0,W.jsx)(hZ,{title:`Workout Complete`,onClose:ge,actions:(0,W.jsxs)(W.Fragment,{children:[R&&(0,W.jsx)(`span`,{className:`text-xs font-medium text-muted-foreground`,children:`Saved ✓`}),(0,W.jsx)(wZ,{}),(0,W.jsx)(TZ,{})]}),children:(0,W.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col`,children:[xe,(0,W.jsx)(`div`,{className:`min-h-0 flex-1`,children:de?(0,W.jsx)(RK,{mode:`post-run`,items:ue,onSave:fe,onSkip:B,onClose:()=>z(!0),runId:a?`result:${a}`:void 0,className:`mx-auto max-w-md`}):(0,W.jsx)(mZ,{runtime:null,segments:y,selectedSegmentIds:x,onSelectSegment:be,groups:[],gridViewPreset:C?`debug`:`default`})})]})}):(0,W.jsx)(hZ,{title:`Starting workout`,onClose:r,children:h?(0,W.jsxs)(`div`,{className:`space-y-3 p-6`,children:[(0,W.jsxs)(`p`,{role:`alert`,children:[`Workout not started. `,h,` Your draft is kept.`]}),(0,W.jsx)(`button`,{type:`button`,className:`rounded border px-3 py-2 focus-visible:ring-2`,onClick:()=>void v(),children:`Retry start`})]}):(0,W.jsx)(`p`,{role:`status`,className:`p-6`,children:`Saving workout before starting…`})})},kZ={play:!0,"add-to-today":!0,schedule:!0},AZ=`log`;function jZ(e,t){return e.filter(e=>e.id===AZ?t===`log`:!kZ[e.id]||t===`run`)}function MZ(e,t){let n=t.contentFrom!==void 0&&t.contentTo!==void 0?e.state.doc.sliceString(t.contentFrom,t.contentTo):``,r=t.type===`time`||t.type===`log`?t.type:`time`;return{id:t.id,contentId:t.contentId,dialect:r,sport:t.sport,startLine:t.startLine-1,endLine:t.endLine-1,content:n,state:`idle`,version:1,createdAt:Date.now(),widgetIds:{}}}function NZ(e){return function({className:t}){return U.isValidElement(e)?U.cloneElement(e,{className:G(e.props.className,t)}):(0,W.jsx)(`span`,{className:G(`flex items-center`,t),children:e})}}var PZ=({cmd:e,block:t})=>{let[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(!1),o=(0,U.useCallback)(async()=>{!e.onSplitClick||n||(await e.onSplitClick(t),r(!0),setTimeout(()=>r(!1),1500))},[e,t,n]),s=(0,U.useCallback)(async()=>{i||(await e.onClick(t),e.successIcon&&(a(!0),setTimeout(()=>a(!1),1500)))},[e,t,i]),c=(0,U.useMemo)(()=>NZ(i?e.successIcon??e.icon:e.icon),[e.icon,e.successIcon,i]),l=(0,U.useMemo)(()=>NZ(n?e.splitSuccessIcon??e.splitIcon:e.splitIcon),[n,e.splitIcon,e.splitSuccessIcon]),u=(0,U.useMemo)(()=>({id:e.id,label:e.label,icon:c,action:{type:`call`,handler:()=>s()}}),[e.id,e.label,c,s]),d=(0,U.useMemo)(()=>({id:`${e.id}-split`,label:`Copy link`,icon:l,action:{type:`call`,handler:o}}),[e.id,l,o]),f=(0,U.useCallback)(e=>{e.preventDefault(),e.stopPropagation()},[]);if(!e.onSplitClick){let t=i?e.successIcon??e.icon:e.icon;return(0,W.jsxs)(K,{variant:e.primary?`default`:`secondary`,className:G(e.iconOnly?`h-11 w-11 rounded-full p-0 sm:h-auto sm:min-h-[44px] sm:min-w-[44px] sm:w-auto sm:rounded-sm sm:px-1.5 sm:py-0.5 text-[10px] font-medium shadow-sm`:`h-11 w-11 rounded-full p-0 text-[10px] font-medium shadow-sm gap-0 sm:h-auto sm:min-h-[44px] sm:w-auto sm:gap-1 sm:rounded-sm sm:px-2 sm:py-0.5`,!e.primary&&`border border-border/50`,i&&`text-emerald-600 bg-emerald-500/15 dark:text-emerald-400 dark:bg-emerald-500/20 border-emerald-500/30`),title:e.label,"aria-label":e.label,"data-testid":e.id===`run`?BU.EDITOR_START_WORKOUT:void 0,onClick:e=>{f(e),s()},onMouseDown:f,onPointerDown:f,children:[(0,W.jsx)(`span`,{className:`flex items-center justify-center size-4 sm:size-3`,children:t}),!e.iconOnly&&(0,W.jsx)(`span`,{className:`sr-only sm:not-sr-only sm:inline`,children:e.label})]})}return(0,W.jsx)(`div`,{onClick:f,onMouseDown:f,onPointerDown:f,children:(0,W.jsx)(ZJ,{primary:u,secondary:d,size:`xs`,variant:e.primary?`primary`:`default`,className:`rounded-full sm:rounded-sm`,labelClassName:`sr-only sm:not-sr-only sm:inline`})})},FZ=({view:e,commands:t})=>{let[n,r]=(0,U.useState)(()=>e?.plugin(UT)?.rects??[]),[i,a]=(0,U.useState)(0);(0,U.useEffect)(()=>{if(!e)return;let t=e.plugin(UT);t&&(r([...t.rects]),t.addListener(e=>r([...e])))},[e]),(0,U.useEffect)(()=>{if(!e)return;let t=e.scrollDOM,n=null,r=()=>{n===null&&(n=requestAnimationFrame(()=>{n=null,a(t.scrollTop)}))};return t.addEventListener(`scroll`,r,{passive:!0}),a(t.scrollTop),()=>{n!==null&&cancelAnimationFrame(n),t.removeEventListener(`scroll`,r)}},[e]);let o=e?e.plugin(UT):null,s=(n.length>0?n:o?.rects??[]).filter(e=>e.type===`time`||e.type===`log`);if(s.length===0)return null;let{sections:c}=e.state.field(_T),l=new Map(c.map(e=>[e.id,e]));return(0,W.jsx)(W.Fragment,{children:s.map(n=>{let r=l.get(n.sectionId);if(!r)return null;let a=MZ(e,r),o=jZ(t,Ea(r.type));return o.length===0?null:(0,W.jsx)(`div`,{className:`absolute right-1 z-10 flex items-end gap-1 pointer-events-auto`,style:{top:n.top-i,height:n.firstLineHeight},children:o.map(e=>(0,W.jsx)(PZ,{cmd:e,block:a},e.id))},n.sectionId)})})},IZ=({sections:e,isRuntimeActive:t,editorState:n,onSelectBlock:r})=>{let i=KA(),a=(0,U.useRef)(``);return(0,U.useEffect)(()=>{if(!i?.connected||t||!n)return;let r=e.filter(e=>e.type===`time`).map(e=>{let t=e.contentFrom!==void 0&&e.contentTo!==void 0?n.doc.sliceString(e.contentFrom,e.contentTo):``,r=t.split(`
158
158
  `).filter(e=>e.trim().length>0),i=r.slice(0,3).join(`
159
- `),a=t.match(/^(\d{1,2}:\d{2}(?::\d{2})?)/m)?.[1],o=r[0]?.substring(0,60)||`Workout`,s=e.type===`time`||e.type===`log`?e.type:`time`;return{id:e.id,title:o,statementCount:r.length,contentPreview:i,timerHint:a,dialect:s}}),o={type:`rpc-workbench-update`,mode:r.length>0?`preview`:`idle`,previewData:r.length>0?{title:r[0].title,blocks:r}:void 0},s=JSON.stringify(o);if(s!==a.current){a.current=s;try{i.send(o)}catch{}}},[i,e,t,n]),(0,U.useEffect)(()=>{i?.connected||(a.current=``)},[i]),(0,U.useEffect)(()=>{t||(a.current=``)},[t]),(0,U.useEffect)(()=>{if(!(!i?.connected||!r||!n))return i.onMessage(t=>{if(t.type!==`rpc-event`||t.name!==`select-block`)return;let{index:i,blockId:a}=t.data??{},o=e.filter(e=>e.type===`time`),s=a?o.find(e=>e.id===a):o[i??0];if(!s||!n)return;let c=s.contentFrom!==void 0&&s.contentTo!==void 0?n.doc.sliceString(s.contentFrom,s.contentTo):``;r({id:s.id,dialect:s.type===`time`||s.type===`log`?s.type:`time`,sport:s.sport,startLine:s.startLine-1,endLine:s.endLine-1,content:c,state:`idle`,version:1,createdAt:Date.now(),widgetIds:{}})})},[i,e,n,r,t]),null},LZ={[q.Duration]:{label:`Timer`,icon:`⏱`,textClass:`text-metric-time`,bgClass:`bg-metric-time/10`,borderClass:`border-metric-time/30`},[q.Rep]:{label:`Reps`,icon:`✕`,textClass:`text-metric-rep`,bgClass:`bg-metric-rep/10`,borderClass:`border-metric-rep/30`},[q.Effort]:{label:`Exercise`,icon:`🏋`,textClass:`text-metric-effort`,bgClass:`bg-metric-effort/10`,borderClass:`border-metric-effort/30`},[q.Rounds]:{label:`Rounds`,icon:`↻`,textClass:`text-metric-rounds`,bgClass:`bg-metric-rounds/10`,borderClass:`border-metric-rounds/30`},[q.Distance]:{label:`Distance`,icon:`📏`,textClass:`text-metric-distance`,bgClass:`bg-metric-distance/10`,borderClass:`border-metric-distance/30`},[q.Resistance]:{label:`Weight`,icon:`⚖`,textClass:`text-metric-resistance`,bgClass:`bg-metric-resistance/10`,borderClass:`border-metric-resistance/30`},[q.Equipment]:{label:`Equipment`,icon:`🧰`,textClass:`text-foreground`,bgClass:`bg-muted/40`,borderClass:`border-border/50`},[q.Action]:{label:`Action`,icon:`⚡`,textClass:`text-metric-action`,bgClass:`bg-metric-action/10`,borderClass:`border-metric-action/30`},[q.Label]:{label:`Label`,icon:`🏷`,textClass:`text-muted-foreground`,bgClass:`bg-muted/30`,borderClass:`border-border/40`}},RZ={[q.Rep]:`reps`,[q.Effort]:`movement`,[q.Resistance]:`weight`},zZ=({metric:e,tooltip:t,isFocused:n,onClick:r})=>{let i=LZ[e.type],a=e.type===q.Hint,o=e.image??(e.value===void 0?``:String(e.value)),s=i?.label??String(e.type);return(0,W.jsxs)(`span`,{title:t,onClick:r,className:G(`inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[11px] font-medium`,`pointer-events-auto transition-opacity hover:opacity-80`,i?.bgClass??`bg-muted/30`,i?.textClass??`text-muted-foreground`,i?.borderClass??`border-border/40`,r&&`cursor-pointer`,n&&`font-bold shadow-sm`),children:[(0,W.jsx)(`span`,{children:a?e.icon:i?.icon??`•`}),!a&&(0,W.jsx)(`span`,{children:s}),!a&&o&&(0,W.jsx)(`span`,{className:`font-semibold`,children:o})]})};function BZ(e){let t=da(e.metadata);return{refs:t?.refs??[],diagnostics:t?.diagnostics??[]}}function VZ(e,t){try{let n=e.coordsAtPos(t);if(!n)return null;let r=e.dom?.getBoundingClientRect?.()??{top:0,left:0},i=e.contentDOM?.getBoundingClientRect?.()??{left:0,width:0};return{top:n.bottom-r.top,left:i.left-r.left,width:i.width}}catch{return null}}var HZ=({view:e,cursorVersion:t,getCursorFocusState:n})=>{let[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),s=(0,U.useRef)(null),c=(0,U.useCallback)(()=>{if(!e){o(null),i(null);return}let t=(n??fJ)(e.state);o(t),i(t?VZ(e,t.lineFrom):null)},[e,n]);if((0,U.useEffect)(()=>{c()},[c,t]),(0,U.useEffect)(()=>{if(!e)return;let t=()=>c();return window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t,!0),()=>{window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t,!0)}},[e,c]),!r||!a?.section)return null;let l=a.allStatements?.filter(e=>e.meta?.line===a.cursorLine-a.section.startLine)??(a.statement?[a.statement]:[]),u=l.flatMap(e=>e.metrics.toArray()).filter(e=>e.type!==q.Sound&&e.type!==q.System&&!(e.type===q.Hint&&!e.icon)),d=mW(u,`runtime-badge`),f=l.flatMap(e=>e.metrics.toArray()),p=[],m=[],h=[];for(let e of f){let t=BZ(e);for(let e of t.refs){let t=`${e.kind}:${e.slug}`;p.includes(t)||(p.push(t),m.push(e))}h.push(...t.diagnostics)}let g=[];for(let e of f){let t=ya(e.metadata);t&&(g.some(e=>e.slug===t.slug)||g.push(t))}let _=typeof e?.state?.facet==`function`?e.state.facet(oE)?.()??null:null,v=typeof e?.state?.doc?.sliceString==`function`?eJ(e.state.doc.sliceString(a.lineFrom,a.lineTo)):null,y=e=>e.reason===`conflict`||e.reason.endsWith(`equipment`)||e.reason===`invalid-explicit`&&e.token&&v?.equipment.includes(e.token)?`equipment`:`effort`,b=e=>typeof e==`string`&&e.trim()?e:null,x=async t=>{if(!e)return;let n=e.state.doc.sliceString(a.lineFrom,a.lineTo),r=TH.getState();if(t===`effort`){let t=await r.open({placeholder:`Change effort…`,sources:[Qq(`effort`)]});if(t.dismissed)return;let i=b(t.item.payload);if(!i)return;e.dispatch({changes:{from:a.lineFrom,to:a.lineTo,insert:tJ(n,{effort:i})}});return}let i=[...v?.equipment??[]];for(;;){let e=await r.open({placeholder:i.length>0?`Add equipment (Esc to finish)…`:`Set equipment…`,sources:[Qq(`equipment`)]});if(e.dismissed)break;let t=b(e.item.payload);t&&!i.includes(t)&&i.push(t)}((v?.jsonFrom??-1)>=0||i.length>0)&&e.dispatch({changes:{from:a.lineFrom,to:a.lineTo,insert:tJ(n,{equipment:i})}})},S=async()=>{if(!e)return;let t=e.state.doc.sliceString(a.lineFrom,a.lineTo),n=TH.getState(),r,i=await n.open({placeholder:`Add effort (Esc to skip)…`,sources:[Qq(`effort`)]});i.dismissed||(r=b(i.item.payload)??void 0);let o=[];for(;;){let e=await n.open({placeholder:`Add equipment (Esc to finish)…`,sources:[Qq(`equipment`)]});if(e.dismissed)break;let t=b(e.item.payload);t&&!o.includes(t)&&o.push(t)}!r&&o.length===0||e.dispatch({changes:{from:a.lineFrom,to:a.lineTo,insert:tJ(t,{effort:r,equipment:o})}})},C=async t=>{if(!e||!t.token)return;let n=y(t),r=await TH.getState().open({placeholder:`Replace “${t.token}”…`,sources:[Qq(n,t.candidates)]});if(r.dismissed)return;let i=b(r.item.payload);if(!i)return;let o=e.state.doc.sliceString(a.lineFrom,a.lineTo).indexOf(t.token);o<0||e.dispatch({changes:{from:a.lineFrom+o,to:a.lineFrom+o+t.token.length,insert:i}})},w=t=>{let n=RZ[t.type];if(!n||!e)return;let r=t.type===q.Effort?`effort`:t.type===q.Equipment?`equipment`:null;if(r&&v?.jsonFrom!==void 0&&v.jsonFrom>=0){x(r);return}Zn(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-DHSfYrHi.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([3,1,0,2])).then(({runStatementBuilderFlow:t})=>{t(a,e,n)})};return(0,W.jsxs)(`div`,{ref:s,className:G(`cm-metric-inline-panel`,`absolute z-50 pointer-events-none`,`flex items-center gap-2 px-3 h-[28px]`,`bg-background/90 backdrop-blur-sm`,`border-l border-r border-border/50`,`transition-opacity duration-100`),style:{top:r.top,left:r.left,width:r.width,maxWidth:r.width},"aria-live":`polite`,"aria-label":`Metric inline panel`,children:[u.length>0?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-medium shrink-0 select-none`,children:`Metrics:`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[u.map((e,t)=>(0,W.jsx)(zZ,{metric:e,tooltip:e.type===q.Hint?String(e.value??``):d[t]?.tooltip,isFocused:a.focusedMetric===e,onClick:RZ[e.type]?()=>w(e):void 0},`${e.type}-${t}`)),m.map(e=>(0,W.jsxs)(`span`,{title:`${e.kind===`effort`?`Effort`:`Equipment`} · click to change source`,onClick:()=>void x(e.kind),className:`pointer-events-auto inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[11px] font-medium cursor-pointer hover:opacity-80 bg-muted/40 text-foreground border-border/50`,children:[(0,W.jsx)(`span`,{children:e.kind===`effort`?`🏋`:`🧰`}),(0,W.jsx)(`span`,{className:`font-semibold`,children:e.label}),_&&(0,W.jsx)(`a`,{href:_.openHref(e.kind,e.slug),title:`Open ${e.label} page`,"aria-label":`Open ${e.label} page`,className:`text-muted-foreground/70 hover:text-foreground`,onClick:e=>e.stopPropagation(),children:`↗`})]},`${e.kind}:${e.slug}`)),g.map(e=>(0,W.jsxs)(`span`,{title:e.soundProfileId?`Tag ${e.label} · names the ${e.soundProfileId} sound profile`:`Tag ${e.label}`,className:`pointer-events-auto inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[11px] font-medium bg-muted/40 text-foreground border-border/50`,children:[(0,W.jsx)(`span`,{children:`#`}),(0,W.jsx)(`span`,{className:`font-semibold font-mono`,children:e.label}),_&&(0,W.jsx)(`a`,{href:_.openHref(`tag`,e.slug),title:`Open the ${e.label} tag`,"aria-label":`Open the ${e.label} tag`,className:`text-muted-foreground/70 hover:text-foreground`,onClick:e=>e.stopPropagation(),children:`↗`})]},`tag:${e.slug}`)),v?.malformed&&(0,W.jsxs)(`span`,{"data-testid":`editor-ref-unknown`,title:`Reference JSON on this line does not parse — fix it in the raw text.`,className:`pointer-events-auto inline-flex items-center gap-1.5 px-2 py-0.5 rounded border text-[11px] font-medium bg-destructive/10 text-destructive border-destructive/30`,children:[(0,W.jsx)(`span`,{children:`⚠`}),(0,W.jsx)(`span`,{children:`Malformed reference JSON`})]}),h.map((e,t)=>{let n=y(e);return(0,W.jsxs)(`span`,{"data-testid":`editor-ref-unknown`,title:e.message,className:`pointer-events-auto inline-flex items-center gap-1.5 px-2 py-0.5 rounded border text-[11px] font-medium bg-destructive/10 text-destructive border-destructive/30`,children:[(0,W.jsx)(`span`,{children:`⚠`}),(0,W.jsx)(`span`,{children:e.token??e.reason}),(0,W.jsx)(`button`,{type:`button`,className:`underline cursor-pointer`,onClick:()=>void C(e),children:`Select existing`}),_&&(0,W.jsx)(`a`,{href:_.createHref(n),className:`underline hover:text-foreground`,children:`Create page`})]},`${e.reason}-${t}`)}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`editor-add-metric-line`,title:`Add effort/equipment reference to this line`,onClick:()=>void S(),className:`pointer-events-auto inline-flex items-center px-1.5 py-0.5 rounded border border-dashed border-border/60 text-[10px] text-muted-foreground hover:text-foreground hover:border-primary/50 cursor-pointer`,children:`+ Metric`})]})]}):(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 italic select-none`,children:`No metrics on this line`}),(0,W.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/40 shrink-0 select-none`,children:`Ctrl+↑↓ · adjust value`})]})},UZ=new di,WZ=new di,GZ=new di;async function KZ(e){let t=new TextEncoder().encode(e);if(typeof CompressionStream<`u`)try{let e=new CompressionStream(`gzip`),n=e.writable.getWriter(),r=e.readable.getReader();n.write(t),n.close();let i=[];for(;;){let{done:e,value:t}=await r.read();if(e)break;i.push(t)}let a=i.reduce((e,t)=>e+t.length,0),o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.length;return btoa(String.fromCharCode(...o)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}catch{}return btoa(String.fromCharCode(...t)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}async function qZ(e){let t=await KZ(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`);return`${window.location.origin}/load?zip=${t}`}async function JZ(e){let t=await KZ(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`),n=`shared by ${vx()}`;return`${window.location.origin}/?z=${t}&by=${encodeURIComponent(n)}`}var YZ=({noteId:e,noteBlocks:t,sourceRevision:n=0,onIdentityChange:r,onSaved:i,beforeRun:a,onSaveRequest:o,onCommitChange:s,value:c,onChange:l,onDocUpdate:u,onCursorPositionChange:d,onBlur:f,theme:p=`vs`,readonly:m=!1,className:h=``,onStartWorkout:g,onCompleteWorkout:_,onBlocksChange:v,onAddToPlan:y,notePersistence:b,onViewCreated:x,mode:S=`edit`,lineWrapping:C=!0,showLineNumbers:T=!0,enablePreview:E=!0,showFrontmatter:D=!0,enableLinting:O=!0,enableOverlay:k=!1,commands:j,hideDefaultCommands:M=!1,enableInlineRuntime:N=!0,extensions:P,widgetComponents:F,activeSectionId:I,scrollToSectionId:L,results:ee,placeholder:te})=>{let ne=(0,U.useRef)(null),R=(0,U.useRef)(null),re=(0,U.useRef)(null),ie=(0,U.useRef)(``),ae=p===`dark`||p===`vs-dark`,oe=nJ(re,b),[se,ce]=(0,U.useState)(null),[le,z]=(0,U.useState)([]),[ue,de]=(0,U.useState)(1),[fe,B]=(0,U.useState)(0),pe=I??se,me=BJ(le,pe),[he,ge]=(0,U.useState)(null),[_e,ve]=(0,U.useState)(null),[ye,be]=(0,U.useState)(null),[xe,Se]=(0,U.useState)(!1),Ce=(0,U.useRef)(null),we=(0,U.useRef)(!1),Te=(0,U.useRef)(n??0);(0,U.useEffect)(()=>{Te.current=n??0},[n]);let[Ee,De]=(0,U.useState)(null),Oe=(0,U.useRef)(null),ke=(0,U.useCallback)(async(t,n=!1)=>{let r=R.current;if(!(!r||we.current)){we.current=!0,De(null);try{let o=await a?.();typeof o==`number`&&(Te.current=o);let s=r.state.field(_T),c=await DR({noteId:e??w(),rawContent:s.rawContent,blocks:s.noteBlocks,expectedSourceRevision:Te.current,...e?{}:{metadata:{title:`Playground workout`},noteType:`playground`}},t,w(),e?void 0:`playground`,oe);Ce.current=c,Oe.current=null,Te.current=c.note.sourceRevision,r.dispatch({effects:lT.of({blocks:c.note.blocks,sourceRevision:c.note.sourceRevision})}),i?.({rawContent:c.note.rawContent,blocks:c.note.blocks,sourceRevision:c.note.sourceRevision}),Se(n),ve(c.block),be(c.session.id)}catch(e){De(e instanceof Error?e.message:String(e))}finally{we.current=!1}}},[e,oe,i,a]),Ae=(0,U.useCallback)(()=>{ve(null),be(null),Se(!1)},[]),je=(0,U.useCallback)(e=>{N&&ke(e,!0)},[N,ke]),Me=(0,U.useRef)(null),Ne=(0,U.useCallback)((e,t)=>{let n=Me.current,r=n!==null&&n.results===t,i=Ce.current;if(!i||!t)return Promise.reject(Error(`The saved run pin is unavailable.`));let a=i.session.id;if(Oe.current===a)return Promise.resolve();let o={id:i.block.id,contentId:i.session.blockContentId};if(!r&&t&&R.current){let t=R.current,n=DD(t.state,e,a);if(n){let e=n.from+n.insert.indexOf("```");t.dispatch({changes:n,effects:[Or.scrollIntoView(e,{y:`start`,yMargin:96})]}),l?.(t.state.doc.toString())}}r||(Me.current={results:t,resultId:a,runBlock:o});let s;try{s=rK(oe).record({resultId:a,noteId:i.session.noteId,blockId:i.session.blockId,data:t,createdAt:t.endTime}).then(()=>_?.(e,t,a,o))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}return Promise.resolve(s).then(()=>{Me.current?.results===t&&(Me.current=null),Oe.current=a},()=>{}),s},[l,_,oe]),Pe=(0,U.useMemo)(()=>{if(M)return[];if(j&&j.length>0)return j;let e=[];return N?e.push({id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:ke}):g&&e.push({id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:g}),e.push({id:`playground`,label:`Playground`,icon:(0,W.jsx)(A,{className:`h-3 w-3`}),splitIcon:(0,W.jsx)(rt,{className:`h-3 w-3`}),splitSuccessIcon:(0,W.jsx)(un,{className:`h-3 w-3`}),onClick:e=>{qZ(e.content).then(e=>{let t=window.open(e,`wodwiki-playground`);t&&t.focus()})},onSplitClick:async e=>{let t=await JZ(e.content);await navigator.clipboard.writeText(t)}}),y&&e.push({id:`plan`,label:`Plan`,icon:(0,W.jsx)(On,{className:`h-3 w-3`}),onClick:y}),e},[j,g,y,N,M,ke]),Fe=(0,U.useMemo)(()=>gi({codeLanguages:pO}),[]),Ie=(0,U.useMemo)(()=>[...T?[$r(),Ur()]:[],Gr(),mi(),Ar(),hi(),...C?[Or.lineWrapping]:[],ii.allowMultipleSelections.of(!0),eee(),Ei(),Wr(),bi(),pi.highest(xr.of([{key:`Tab`,run:e=>zr(e.state)!==null&&(Di(e),!0)},{key:`Enter`,run:e=>{let t=e.state.selection.main,n=$Z(e.state,t.head),r=e.state.doc.lineAt(t.head);return!t.empty||n?.value.trim()!==``||r.text.slice(t.head-r.from).trim()?!1:(Cr(e),ti(e))}}])),xr.of([...Rr,...ei,...ui,...li,...Ti,...fi,ni,{key:`Mod-s`,run:()=>(o?.(),!0)},{key:`Ctrl-.`,run:e=>{let t=fJ(e.state);if(!t?.focusedMetric)return!1;let n=t.focusedMetric.type;return!new Set([`duration`,`rep`,`rounds`,`distance`,`resistance`]).has(n)&&(Zn(()=>Promise.resolve().then(()=>wH).then(()=>{Zn(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-DHSfYrHi.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([3,1,0,2])).then(({runStatementBuilderFlow:n})=>{n(t,e)}).catch(()=>{TH.getState().open({placeholder:`Modify metric…`,sources:[]})})}),void 0),!0)}}]),ND,_T,oT.of({blocks:t??La(c,{sourceRevision:Math.max(1,n),registeredWidgets:F?[...F.keys()]:ja}),sourceRevision:Math.max(1,n),rawContent:c}),sT.of(F?[...F.keys()]:ja),vT,cE.of(D),...E||!D?[zE]:[],...E?[QT,tE,Bq(),Yq(),nD,XE(),pD]:[],...O?[CT]:[],VT,Rw,kT,OT,AT.of(XZ),jT.of(ZZ),...k?[PD]:[],UT,aT,hJ,...yD,tT,...F&&F.size>0?[fO(F)]:[],HD({executor:sz,onResultSaved:tK,readOnly:m,noteHref:e=>tU(`blockContentId`in e||`dataType`in e?Dz(e):xz(e))}),rJ(e,oe),Or.domEventHandlers({blur:()=>(f?.(),!1)}),Or.updateListener.of(e=>{if(e.docChanged){let t=e.state.field(_T);r?.({rawContent:t.rawContent,blocks:t.noteBlocks,sourceRevision:t.sourceRevision}),l(t.rawContent),u?.(e),tQ(e.state,v,ie),e.transactions.some(e=>e.isUserEvent(`input`)||e.isUserEvent(`delete`)||e.isUserEvent(`paste`)||e.isUserEvent(`drop`))||s?.()}if(e.selectionSet||e.docChanged){B(e=>e+1),e.transactions.some(e=>e.isUserEvent(`delete.backward`))&&zr(e.startState)!==null&&zr(e.state)===null&&$Z(e.state,e.state.selection.main.head)?.value===``&&queueMicrotask(()=>{e.view.state===e.state&&ai(e.view)});let{head:t}=e.state.selection.main,n=e.state.doc.lineAt(t);d?.(n.number,t-n.from+1);let r=bT(e.state);ce(r?.id??null),de(n.number);let{sections:i}=e.state.field(_T);z(i)}}),ii.readOnly.of(m),Or.editable.of(!m),...te?[xi(te)]:[]],[l,d,f,u,v,r,m,o,s,T,C,E,D,O,k,e,oe,F,te]);return(0,U.useEffect)(()=>{let e=ne.current;if(!e)return;let t=ii.create({doc:c,extensions:[...Ie,UZ.of(eT(ae)),WZ.of(Fe),GZ.of([]),...P??[]]}),n=new Or({state:t,parent:e}),i=window.visualViewport,a=0,o=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(()=>{n.hasFocus&&i?.scale===1&&i.height<window.innerHeight&&n.dispatch({effects:Or.scrollIntoView(n.state.selection.main.head,{y:`nearest`,yMargin:24})})})};i?.addEventListener(`resize`,o),n.contentDOM.addEventListener(`focus`,o),R.current=n,ge(n),e.__codemirrorView=n,x?.(n);let{sections:s}=n.state.field(_T);z(s);let l=n.state.doc.lineAt(n.state.selection.main.head).number;de(l);let u=bT(n.state);ce(u?.id??null);let d=n.state.field(_T);return r?.({rawContent:d.rawContent,blocks:d.noteBlocks,sourceRevision:d.sourceRevision}),tQ(n.state,v,ie),()=>{cancelAnimationFrame(a),i?.removeEventListener(`resize`,o),n.contentDOM.removeEventListener(`focus`,o),delete e.__codemirrorView,ge(null),n.destroy()}},[]),(0,U.useEffect)(()=>{let e=R.current;if(!e)return;let r=e.state.field(_T);c===r.rawContent?t&&n!==r.sourceRevision&&e.dispatch({effects:lT.of({blocks:t,sourceRevision:Math.max(1,n)})}):e.dispatch({changes:{from:0,to:e.state.doc.length,insert:c},...t?{effects:uT.of({rawContent:c,blocks:t,sourceRevision:Math.max(1,n)})}:{}})},[c,t,n]),(0,U.useEffect)(()=>{R.current&&R.current.dispatch({effects:UZ.reconfigure(eT(ae))})},[ae]),(0,U.useEffect)(()=>{if(R.current){let e=[];R.current.dispatch({effects:[Zr.reconfigure.of([...Ie,UZ.of(eT(ae)),WZ.of(Fe),GZ.of(e),...P??[]])]})}},[Ie,P,S,ae,Fe]),(0,U.useEffect)(()=>{m||R.current?.focus()},[m]),(0,U.useEffect)(()=>{if(L&&R.current){let e=R.current,t=e.state.doc.toString().split(`
159
+ `),a=t.match(/^(\d{1,2}:\d{2}(?::\d{2})?)/m)?.[1],o=r[0]?.substring(0,60)||`Workout`,s=e.type===`time`||e.type===`log`?e.type:`time`;return{id:e.id,title:o,statementCount:r.length,contentPreview:i,timerHint:a,dialect:s}}),o={type:`rpc-workbench-update`,mode:r.length>0?`preview`:`idle`,previewData:r.length>0?{title:r[0].title,blocks:r}:void 0},s=JSON.stringify(o);if(s!==a.current){a.current=s;try{i.send(o)}catch{}}},[i,e,t,n]),(0,U.useEffect)(()=>{i?.connected||(a.current=``)},[i]),(0,U.useEffect)(()=>{t||(a.current=``)},[t]),(0,U.useEffect)(()=>{if(!(!i?.connected||!r||!n))return i.onMessage(t=>{if(t.type!==`rpc-event`||t.name!==`select-block`)return;let{index:i,blockId:a}=t.data??{},o=e.filter(e=>e.type===`time`),s=a?o.find(e=>e.id===a):o[i??0];if(!s||!n)return;let c=s.contentFrom!==void 0&&s.contentTo!==void 0?n.doc.sliceString(s.contentFrom,s.contentTo):``;r({id:s.id,dialect:s.type===`time`||s.type===`log`?s.type:`time`,sport:s.sport,startLine:s.startLine-1,endLine:s.endLine-1,content:c,state:`idle`,version:1,createdAt:Date.now(),widgetIds:{}})})},[i,e,n,r,t]),null},LZ={[q.Duration]:{label:`Timer`,icon:`⏱`,textClass:`text-metric-time`,bgClass:`bg-metric-time/10`,borderClass:`border-metric-time/30`},[q.Rep]:{label:`Reps`,icon:`✕`,textClass:`text-metric-rep`,bgClass:`bg-metric-rep/10`,borderClass:`border-metric-rep/30`},[q.Effort]:{label:`Exercise`,icon:`🏋`,textClass:`text-metric-effort`,bgClass:`bg-metric-effort/10`,borderClass:`border-metric-effort/30`},[q.Rounds]:{label:`Rounds`,icon:`↻`,textClass:`text-metric-rounds`,bgClass:`bg-metric-rounds/10`,borderClass:`border-metric-rounds/30`},[q.Distance]:{label:`Distance`,icon:`📏`,textClass:`text-metric-distance`,bgClass:`bg-metric-distance/10`,borderClass:`border-metric-distance/30`},[q.Resistance]:{label:`Weight`,icon:`⚖`,textClass:`text-metric-resistance`,bgClass:`bg-metric-resistance/10`,borderClass:`border-metric-resistance/30`},[q.Equipment]:{label:`Equipment`,icon:`🧰`,textClass:`text-foreground`,bgClass:`bg-muted/40`,borderClass:`border-border/50`},[q.Action]:{label:`Action`,icon:`⚡`,textClass:`text-metric-action`,bgClass:`bg-metric-action/10`,borderClass:`border-metric-action/30`},[q.Label]:{label:`Label`,icon:`🏷`,textClass:`text-muted-foreground`,bgClass:`bg-muted/30`,borderClass:`border-border/40`}},RZ={[q.Rep]:`reps`,[q.Effort]:`movement`,[q.Resistance]:`weight`},zZ=({metric:e,tooltip:t,isFocused:n,onClick:r})=>{let i=LZ[e.type],a=e.type===q.Hint,o=e.image??(e.value===void 0?``:String(e.value)),s=i?.label??String(e.type);return(0,W.jsxs)(`span`,{title:t,onClick:r,className:G(`inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[11px] font-medium`,`pointer-events-auto transition-opacity hover:opacity-80`,i?.bgClass??`bg-muted/30`,i?.textClass??`text-muted-foreground`,i?.borderClass??`border-border/40`,r&&`cursor-pointer`,n&&`font-bold shadow-sm`),children:[(0,W.jsx)(`span`,{children:a?e.icon:i?.icon??`•`}),!a&&(0,W.jsx)(`span`,{children:s}),!a&&o&&(0,W.jsx)(`span`,{className:`font-semibold`,children:o})]})};function BZ(e){let t=da(e.metadata);return{refs:t?.refs??[],diagnostics:t?.diagnostics??[]}}function VZ(e,t){try{let n=e.coordsAtPos(t);if(!n)return null;let r=e.dom?.getBoundingClientRect?.()??{top:0,left:0},i=e.contentDOM?.getBoundingClientRect?.()??{left:0,width:0};return{top:n.bottom-r.top,left:i.left-r.left,width:i.width}}catch{return null}}var HZ=({view:e,cursorVersion:t,getCursorFocusState:n})=>{let[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),s=(0,U.useRef)(null),c=(0,U.useCallback)(()=>{if(!e){o(null),i(null);return}let t=(n??fJ)(e.state);o(t),i(t?VZ(e,t.lineFrom):null)},[e,n]);if((0,U.useEffect)(()=>{c()},[c,t]),(0,U.useEffect)(()=>{if(!e)return;let t=()=>c();return window.addEventListener(`scroll`,t,!0),window.addEventListener(`resize`,t,!0),()=>{window.removeEventListener(`scroll`,t,!0),window.removeEventListener(`resize`,t,!0)}},[e,c]),!r||!a?.section)return null;let l=a.allStatements?.filter(e=>e.meta?.line===a.cursorLine-a.section.startLine)??(a.statement?[a.statement]:[]),u=l.flatMap(e=>e.metrics.toArray()).filter(e=>e.type!==q.Sound&&e.type!==q.System&&!(e.type===q.Hint&&!e.icon)),d=mW(u,`runtime-badge`),f=l.flatMap(e=>e.metrics.toArray()),p=[],m=[],h=[];for(let e of f){let t=BZ(e);for(let e of t.refs){let t=`${e.kind}:${e.slug}`;p.includes(t)||(p.push(t),m.push(e))}h.push(...t.diagnostics)}let g=[];for(let e of f){let t=ya(e.metadata);t&&(g.some(e=>e.slug===t.slug)||g.push(t))}let _=typeof e?.state?.facet==`function`?e.state.facet(oE)?.()??null:null,v=typeof e?.state?.doc?.sliceString==`function`?eJ(e.state.doc.sliceString(a.lineFrom,a.lineTo)):null,y=e=>e.reason===`conflict`||e.reason.endsWith(`equipment`)||e.reason===`invalid-explicit`&&e.token&&v?.equipment.includes(e.token)?`equipment`:`effort`,b=e=>typeof e==`string`&&e.trim()?e:null,x=async t=>{if(!e)return;let n=e.state.doc.sliceString(a.lineFrom,a.lineTo),r=TH.getState();if(t===`effort`){let t=await r.open({placeholder:`Change effort…`,sources:[Qq(`effort`)]});if(t.dismissed)return;let i=b(t.item.payload);if(!i)return;e.dispatch({changes:{from:a.lineFrom,to:a.lineTo,insert:tJ(n,{effort:i})}});return}let i=[...v?.equipment??[]];for(;;){let e=await r.open({placeholder:i.length>0?`Add equipment (Esc to finish)…`:`Set equipment…`,sources:[Qq(`equipment`)]});if(e.dismissed)break;let t=b(e.item.payload);t&&!i.includes(t)&&i.push(t)}((v?.jsonFrom??-1)>=0||i.length>0)&&e.dispatch({changes:{from:a.lineFrom,to:a.lineTo,insert:tJ(n,{equipment:i})}})},S=async()=>{if(!e)return;let t=e.state.doc.sliceString(a.lineFrom,a.lineTo),n=TH.getState(),r,i=await n.open({placeholder:`Add effort (Esc to skip)…`,sources:[Qq(`effort`)]});i.dismissed||(r=b(i.item.payload)??void 0);let o=[];for(;;){let e=await n.open({placeholder:`Add equipment (Esc to finish)…`,sources:[Qq(`equipment`)]});if(e.dismissed)break;let t=b(e.item.payload);t&&!o.includes(t)&&o.push(t)}!r&&o.length===0||e.dispatch({changes:{from:a.lineFrom,to:a.lineTo,insert:tJ(t,{effort:r,equipment:o})}})},C=async t=>{if(!e||!t.token)return;let n=y(t),r=await TH.getState().open({placeholder:`Replace “${t.token}”…`,sources:[Qq(n,t.candidates)]});if(r.dismissed)return;let i=b(r.item.payload);if(!i)return;let o=e.state.doc.sliceString(a.lineFrom,a.lineTo).indexOf(t.token);o<0||e.dispatch({changes:{from:a.lineFrom+o,to:a.lineFrom+o+t.token.length,insert:i}})},w=t=>{let n=RZ[t.type];if(!n||!e)return;let r=t.type===q.Effort?`effort`:t.type===q.Equipment?`equipment`:null;if(r&&v?.jsonFrom!==void 0&&v.jsonFrom>=0){x(r);return}Zn(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-krzOPRPk.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([3,1,0,2])).then(({runStatementBuilderFlow:t})=>{t(a,e,n)})};return(0,W.jsxs)(`div`,{ref:s,className:G(`cm-metric-inline-panel`,`absolute z-50 pointer-events-none`,`flex items-center gap-2 px-3 h-[28px]`,`bg-background/90 backdrop-blur-sm`,`border-l border-r border-border/50`,`transition-opacity duration-100`),style:{top:r.top,left:r.left,width:r.width,maxWidth:r.width},"aria-live":`polite`,"aria-label":`Metric inline panel`,children:[u.length>0?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground font-medium shrink-0 select-none`,children:`Metrics:`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[u.map((e,t)=>(0,W.jsx)(zZ,{metric:e,tooltip:e.type===q.Hint?String(e.value??``):d[t]?.tooltip,isFocused:a.focusedMetric===e,onClick:RZ[e.type]?()=>w(e):void 0},`${e.type}-${t}`)),m.map(e=>(0,W.jsxs)(`span`,{title:`${e.kind===`effort`?`Effort`:`Equipment`} · click to change source`,onClick:()=>void x(e.kind),className:`pointer-events-auto inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[11px] font-medium cursor-pointer hover:opacity-80 bg-muted/40 text-foreground border-border/50`,children:[(0,W.jsx)(`span`,{children:e.kind===`effort`?`🏋`:`🧰`}),(0,W.jsx)(`span`,{className:`font-semibold`,children:e.label}),_&&(0,W.jsx)(`a`,{href:_.openHref(e.kind,e.slug),title:`Open ${e.label} page`,"aria-label":`Open ${e.label} page`,className:`text-muted-foreground/70 hover:text-foreground`,onClick:e=>e.stopPropagation(),children:`↗`})]},`${e.kind}:${e.slug}`)),g.map(e=>(0,W.jsxs)(`span`,{title:e.soundProfileId?`Tag ${e.label} · names the ${e.soundProfileId} sound profile`:`Tag ${e.label}`,className:`pointer-events-auto inline-flex items-center gap-1 px-2 py-0.5 rounded border text-[11px] font-medium bg-muted/40 text-foreground border-border/50`,children:[(0,W.jsx)(`span`,{children:`#`}),(0,W.jsx)(`span`,{className:`font-semibold font-mono`,children:e.label}),_&&(0,W.jsx)(`a`,{href:_.openHref(`tag`,e.slug),title:`Open the ${e.label} tag`,"aria-label":`Open the ${e.label} tag`,className:`text-muted-foreground/70 hover:text-foreground`,onClick:e=>e.stopPropagation(),children:`↗`})]},`tag:${e.slug}`)),v?.malformed&&(0,W.jsxs)(`span`,{"data-testid":`editor-ref-unknown`,title:`Reference JSON on this line does not parse — fix it in the raw text.`,className:`pointer-events-auto inline-flex items-center gap-1.5 px-2 py-0.5 rounded border text-[11px] font-medium bg-destructive/10 text-destructive border-destructive/30`,children:[(0,W.jsx)(`span`,{children:`⚠`}),(0,W.jsx)(`span`,{children:`Malformed reference JSON`})]}),h.map((e,t)=>{let n=y(e);return(0,W.jsxs)(`span`,{"data-testid":`editor-ref-unknown`,title:e.message,className:`pointer-events-auto inline-flex items-center gap-1.5 px-2 py-0.5 rounded border text-[11px] font-medium bg-destructive/10 text-destructive border-destructive/30`,children:[(0,W.jsx)(`span`,{children:`⚠`}),(0,W.jsx)(`span`,{children:e.token??e.reason}),(0,W.jsx)(`button`,{type:`button`,className:`underline cursor-pointer`,onClick:()=>void C(e),children:`Select existing`}),_&&(0,W.jsx)(`a`,{href:_.createHref(n),className:`underline hover:text-foreground`,children:`Create page`})]},`${e.reason}-${t}`)}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`editor-add-metric-line`,title:`Add effort/equipment reference to this line`,onClick:()=>void S(),className:`pointer-events-auto inline-flex items-center px-1.5 py-0.5 rounded border border-dashed border-border/60 text-[10px] text-muted-foreground hover:text-foreground hover:border-primary/50 cursor-pointer`,children:`+ Metric`})]})]}):(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground/50 italic select-none`,children:`No metrics on this line`}),(0,W.jsx)(`span`,{className:`ml-auto text-[9px] text-muted-foreground/40 shrink-0 select-none`,children:`Ctrl+↑↓ · adjust value`})]})},UZ=new di,WZ=new di,GZ=new di;async function KZ(e){let t=new TextEncoder().encode(e);if(typeof CompressionStream<`u`)try{let e=new CompressionStream(`gzip`),n=e.writable.getWriter(),r=e.readable.getReader();n.write(t),n.close();let i=[];for(;;){let{done:e,value:t}=await r.read();if(e)break;i.push(t)}let a=i.reduce((e,t)=>e+t.length,0),o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.length;return btoa(String.fromCharCode(...o)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}catch{}return btoa(String.fromCharCode(...t)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}async function qZ(e){let t=await KZ(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`);return`${window.location.origin}/load?zip=${t}`}async function JZ(e){let t=await KZ(`\`\`\`time\n${e.trimEnd()}\n\`\`\`\n`),n=`shared by ${vx()}`;return`${window.location.origin}/?z=${t}&by=${encodeURIComponent(n)}`}var YZ=({noteId:e,noteBlocks:t,sourceRevision:n=0,onIdentityChange:r,onSaved:i,beforeRun:a,onSaveRequest:o,onCommitChange:s,value:c,onChange:l,onDocUpdate:u,onCursorPositionChange:d,onBlur:f,theme:p=`vs`,readonly:m=!1,className:h=``,onStartWorkout:g,onCompleteWorkout:_,onBlocksChange:v,onAddToPlan:y,notePersistence:b,onViewCreated:x,mode:S=`edit`,lineWrapping:C=!0,showLineNumbers:T=!0,enablePreview:E=!0,showFrontmatter:D=!0,enableLinting:O=!0,enableOverlay:k=!1,commands:j,hideDefaultCommands:M=!1,enableInlineRuntime:N=!0,extensions:P,widgetComponents:F,activeSectionId:I,scrollToSectionId:L,results:ee,placeholder:te})=>{let ne=(0,U.useRef)(null),R=(0,U.useRef)(null),re=(0,U.useRef)(null),ie=(0,U.useRef)(``),ae=p===`dark`||p===`vs-dark`,oe=nJ(re,b),[se,ce]=(0,U.useState)(null),[le,z]=(0,U.useState)([]),[ue,de]=(0,U.useState)(1),[fe,B]=(0,U.useState)(0),pe=I??se,me=BJ(le,pe),[he,ge]=(0,U.useState)(null),[_e,ve]=(0,U.useState)(null),[ye,be]=(0,U.useState)(null),[xe,Se]=(0,U.useState)(!1),Ce=(0,U.useRef)(null),we=(0,U.useRef)(!1),Te=(0,U.useRef)(n??0);(0,U.useEffect)(()=>{Te.current=n??0},[n]);let[Ee,De]=(0,U.useState)(null),Oe=(0,U.useRef)(null),ke=(0,U.useCallback)(async(t,n=!1)=>{let r=R.current;if(!(!r||we.current)){we.current=!0,De(null);try{let o=await a?.();typeof o==`number`&&(Te.current=o);let s=r.state.field(_T),c=await DR({noteId:e??w(),rawContent:s.rawContent,blocks:s.noteBlocks,expectedSourceRevision:Te.current,...e?{}:{metadata:{title:`Playground workout`},noteType:`playground`}},t,w(),e?void 0:`playground`,oe);Ce.current=c,Oe.current=null,Te.current=c.note.sourceRevision,r.dispatch({effects:lT.of({blocks:c.note.blocks,sourceRevision:c.note.sourceRevision})}),i?.({rawContent:c.note.rawContent,blocks:c.note.blocks,sourceRevision:c.note.sourceRevision}),Se(n),ve(c.block),be(c.session.id)}catch(e){De(e instanceof Error?e.message:String(e))}finally{we.current=!1}}},[e,oe,i,a]),Ae=(0,U.useCallback)(()=>{ve(null),be(null),Se(!1)},[]),je=(0,U.useCallback)(e=>{N&&ke(e,!0)},[N,ke]),Me=(0,U.useRef)(null),Ne=(0,U.useCallback)((e,t)=>{let n=Me.current,r=n!==null&&n.results===t,i=Ce.current;if(!i||!t)return Promise.reject(Error(`The saved run pin is unavailable.`));let a=i.session.id;if(Oe.current===a)return Promise.resolve();let o={id:i.block.id,contentId:i.session.blockContentId};if(!r&&t&&R.current){let t=R.current,n=DD(t.state,e,a);if(n){let e=n.from+n.insert.indexOf("```");t.dispatch({changes:n,effects:[Or.scrollIntoView(e,{y:`start`,yMargin:96})]}),l?.(t.state.doc.toString())}}r||(Me.current={results:t,resultId:a,runBlock:o});let s;try{s=rK(oe).record({resultId:a,noteId:i.session.noteId,blockId:i.session.blockId,data:t,createdAt:t.endTime}).then(()=>_?.(e,t,a,o))}catch(e){return Promise.reject(e instanceof Error?e:Error(String(e)))}return Promise.resolve(s).then(()=>{Me.current?.results===t&&(Me.current=null),Oe.current=a},()=>{}),s},[l,_,oe]),Pe=(0,U.useMemo)(()=>{if(M)return[];if(j&&j.length>0)return j;let e=[];return N?e.push({id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:ke}):g&&e.push({id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:g}),e.push({id:`playground`,label:`Playground`,icon:(0,W.jsx)(A,{className:`h-3 w-3`}),splitIcon:(0,W.jsx)(rt,{className:`h-3 w-3`}),splitSuccessIcon:(0,W.jsx)(un,{className:`h-3 w-3`}),onClick:e=>{qZ(e.content).then(e=>{let t=window.open(e,`wodwiki-playground`);t&&t.focus()})},onSplitClick:async e=>{let t=await JZ(e.content);await navigator.clipboard.writeText(t)}}),y&&e.push({id:`plan`,label:`Plan`,icon:(0,W.jsx)(On,{className:`h-3 w-3`}),onClick:y}),e},[j,g,y,N,M,ke]),Fe=(0,U.useMemo)(()=>gi({codeLanguages:pO}),[]),Ie=(0,U.useMemo)(()=>[...T?[$r(),Ur()]:[],Gr(),mi(),Ar(),hi(),...C?[Or.lineWrapping]:[],ii.allowMultipleSelections.of(!0),eee(),Ei(),Wr(),bi(),pi.highest(xr.of([{key:`Tab`,run:e=>zr(e.state)!==null&&(Di(e),!0)},{key:`Enter`,run:e=>{let t=e.state.selection.main,n=$Z(e.state,t.head),r=e.state.doc.lineAt(t.head);return!t.empty||n?.value.trim()!==``||r.text.slice(t.head-r.from).trim()?!1:(Cr(e),ti(e))}}])),xr.of([...Rr,...ei,...ui,...li,...Ti,...fi,ni,{key:`Mod-s`,run:()=>(o?.(),!0)},{key:`Ctrl-.`,run:e=>{let t=fJ(e.state);if(!t?.focusedMetric)return!1;let n=t.focusedMetric.type;return!new Set([`duration`,`rep`,`rounds`,`distance`,`resistance`]).has(n)&&(Zn(()=>Promise.resolve().then(()=>wH).then(()=>{Zn(async()=>{let{runStatementBuilderFlow:e}=await import(`./statementBuilderFlow-krzOPRPk.js`);return{runStatementBuilderFlow:e}},__vite__mapDeps([3,1,0,2])).then(({runStatementBuilderFlow:n})=>{n(t,e)}).catch(()=>{TH.getState().open({placeholder:`Modify metric…`,sources:[]})})}),void 0),!0)}}]),ND,_T,oT.of({blocks:t??La(c,{sourceRevision:Math.max(1,n),registeredWidgets:F?[...F.keys()]:ja}),sourceRevision:Math.max(1,n),rawContent:c}),sT.of(F?[...F.keys()]:ja),vT,cE.of(D),...E||!D?[zE]:[],...E?[QT,tE,Bq(),Yq(),nD,XE(),pD]:[],...O?[CT]:[],VT,Rw,kT,OT,AT.of(XZ),jT.of(ZZ),...k?[PD]:[],UT,aT,hJ,...yD,tT,...F&&F.size>0?[fO(F)]:[],HD({executor:sz,onResultSaved:tK,readOnly:m,noteHref:e=>tU(`blockContentId`in e||`dataType`in e?Dz(e):xz(e))}),rJ(e,oe),Or.domEventHandlers({blur:()=>(f?.(),!1)}),Or.updateListener.of(e=>{if(e.docChanged){let t=e.state.field(_T);r?.({rawContent:t.rawContent,blocks:t.noteBlocks,sourceRevision:t.sourceRevision}),l(t.rawContent),u?.(e),tQ(e.state,v,ie),e.transactions.some(e=>e.isUserEvent(`input`)||e.isUserEvent(`delete`)||e.isUserEvent(`paste`)||e.isUserEvent(`drop`))||s?.()}if(e.selectionSet||e.docChanged){B(e=>e+1),e.transactions.some(e=>e.isUserEvent(`delete.backward`))&&zr(e.startState)!==null&&zr(e.state)===null&&$Z(e.state,e.state.selection.main.head)?.value===``&&queueMicrotask(()=>{e.view.state===e.state&&ai(e.view)});let{head:t}=e.state.selection.main,n=e.state.doc.lineAt(t);d?.(n.number,t-n.from+1);let r=bT(e.state);ce(r?.id??null),de(n.number);let{sections:i}=e.state.field(_T);z(i)}}),ii.readOnly.of(m),Or.editable.of(!m),...te?[xi(te)]:[]],[l,d,f,u,v,r,m,o,s,T,C,E,D,O,k,e,oe,F,te]);return(0,U.useEffect)(()=>{let e=ne.current;if(!e)return;let t=ii.create({doc:c,extensions:[...Ie,UZ.of(eT(ae)),WZ.of(Fe),GZ.of([]),...P??[]]}),n=new Or({state:t,parent:e}),i=window.visualViewport,a=0,o=()=>{cancelAnimationFrame(a),a=requestAnimationFrame(()=>{n.hasFocus&&i?.scale===1&&i.height<window.innerHeight&&n.dispatch({effects:Or.scrollIntoView(n.state.selection.main.head,{y:`nearest`,yMargin:24})})})};i?.addEventListener(`resize`,o),n.contentDOM.addEventListener(`focus`,o),R.current=n,ge(n),e.__codemirrorView=n,x?.(n);let{sections:s}=n.state.field(_T);z(s);let l=n.state.doc.lineAt(n.state.selection.main.head).number;de(l);let u=bT(n.state);ce(u?.id??null);let d=n.state.field(_T);return r?.({rawContent:d.rawContent,blocks:d.noteBlocks,sourceRevision:d.sourceRevision}),tQ(n.state,v,ie),()=>{cancelAnimationFrame(a),i?.removeEventListener(`resize`,o),n.contentDOM.removeEventListener(`focus`,o),delete e.__codemirrorView,ge(null),n.destroy()}},[]),(0,U.useEffect)(()=>{let e=R.current;if(!e)return;let r=e.state.field(_T);c===r.rawContent?t&&n!==r.sourceRevision&&e.dispatch({effects:lT.of({blocks:t,sourceRevision:Math.max(1,n)})}):e.dispatch({changes:{from:0,to:e.state.doc.length,insert:c},...t?{effects:uT.of({rawContent:c,blocks:t,sourceRevision:Math.max(1,n)})}:{}})},[c,t,n]),(0,U.useEffect)(()=>{R.current&&R.current.dispatch({effects:UZ.reconfigure(eT(ae))})},[ae]),(0,U.useEffect)(()=>{if(R.current){let e=[];R.current.dispatch({effects:[Zr.reconfigure.of([...Ie,UZ.of(eT(ae)),WZ.of(Fe),GZ.of(e),...P??[]])]})}},[Ie,P,S,ae,Fe]),(0,U.useEffect)(()=>{m||R.current?.focus()},[m]),(0,U.useEffect)(()=>{if(L&&R.current){let e=R.current,t=e.state.doc.toString().split(`
160
160
  `),n=-1,r=L.match(/-line-(\d+)$/);if(n=r?parseInt(r[1],10)-1:t.findIndex(e=>{let t=e.match(/^(#{1,6})\s+(.*)$/);if(t){let e=t[2].trim(),n=e.match(/(\d{1,2}:\d{2})/);if(n){let t=n[1];e=e.replace(t,``).replace(/\s+/g,` `).trim(),e||=t}return e.toLowerCase().replace(/[^\w]+/g,`-`)===L}return!1}),n>=0&&n<t.length){let t=e.state.doc.line(n+1).from;e.dispatch({selection:{anchor:t,head:t},effects:[Or.scrollIntoView(t,{y:`start`,yMargin:20})]})}}},[L]),(0,W.jsxs)(`div`,{ref:ne,className:`cm-note-editor relative w-full min-w-0 ${h}`,children:[k&&(0,W.jsx)(FJ,{view:he??R.current,widths:me.widths,activeSectionId:pe,renderSlot:t=>{if(!D&&t.sectionType===`frontmatter`)return null;if(t.sectionType===`time`||t.sectionType===`log`)return(0,W.jsx)(uY,{noteId:e,sectionId:t.sectionId,view:t.view,isActive:t.isActive,widthPercent:t.widthPercent,cursorLine:ue,docVersion:t.docVersion,commands:Pe,extendedResults:ee,hoverLine:t.hoverLine,stickyTopOffset:t.stickyTopOffset,isPanelHovered:t.isPanelHovered,lineDocY:t.lineDocY,rect:t.rect});if(t.sectionType===`frontmatter`||t.sectionType===`embed`){let{sections:e}=t.view.state.field(_T),n=e.find(e=>e.id===t.sectionId);return(0,W.jsx)(WJ,{sectionId:t.sectionId,section:n,view:t.view,isActive:t.isActive,widthPercent:t.widthPercent,docVersion:t.docVersion})}return t.sectionType===`widget`&&t.widgetName?(0,W.jsx)(dY,{sectionId:t.sectionId,widgetName:t.widgetName,view:t.view,registry:F??new Map,docVersion:t.docVersion}):(0,W.jsx)(`div`,{className:`h-full w-full bg-popover/80 backdrop-blur-sm border-l border-border rounded-l-md p-2 text-xs text-muted-foreground`,children:(0,W.jsx)(`div`,{className:`font-medium text-foreground`,children:t.sectionType})})},cursorLine:ue}),Ee&&(0,W.jsxs)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:[`Workout not started. `,Ee,` Your draft is kept.`]}),!k&&Pe.length>0&&(0,W.jsx)(FZ,{view:he??R.current,commands:Pe}),(0,W.jsx)(HZ,{view:he??R.current,cursorVersion:fe}),_e&&R.current&&(0,W.jsx)(OZ,{block:_e,view:he??R.current,onClose:Ae,onCompleteWorkout:Ne,resultId:ye??void 0,autoStart:xe}),(0,W.jsx)(IZ,{sections:le,isRuntimeActive:_e!==null,editorState:(he??R.current)?.state??null,onSelectBlock:je})]})},XZ=async e=>{if(!QZ(e.state,e.pos))return null;let t=e.state.doc.lineAt(e.pos),n=t.text.slice(0,e.pos-t.from).match(/^([a-zA-Z][\w.-]*)$/),r=$Z(e.state,e.pos);if(!n&&!r)return null;let[i,a]=await Promise.all([Z.getAllTagTypes().catch(()=>[]),Z.getAllTags().catch(()=>[])]);if(n)return{from:t.from,options:i.map(e=>({label:e.name,detail:`Tag Type (${e.label})`,type:`property`,apply:`${e.name}:\n - `})),validFor:(e,t,n,r)=>/^[a-zA-Z][\w.-]*$/.test(e)&&QZ(r,n)};if(!r)return null;let{propertyKey:o,from:s}=r,c={"metrics.effort":`effort`,"metrics.equipment":`equipment`,equipment:`equipment`}[o.toLowerCase()];if(c){let e=await Xq();return{from:s,options:(c===`effort`?e.efforts:e.equipment).map(e=>({label:`${e.label} (${e.slug})`,detail:c===`effort`?`Effort`:`Equipment`,type:`constant`,apply:e.slug})),validFor:(e,t,n,r)=>{let i=$Z(r,n);return/^[\w-]*$/.test(e)&&i?.propertyKey===o&&i.from===t}}}let l=i.find(e=>e.name.toLowerCase()===o.toLowerCase());if(!l)return null;let u=a.filter(e=>e.type?.toLowerCase()===l.name.toLowerCase());return u.length===0?null:{from:s,options:u.map(e=>({label:e.label,detail:l.label,type:`constant`})),validFor:(e,t,n,r)=>{let i=$Z(r,n);return/^[\w-]*$/.test(e)&&i?.propertyKey===o&&i.from===t}}},ZZ={wql:{values:async e=>(await dw(e===`tags`?`tag`:e)).map(e=>({label:e.value,detail:e.label,type:`constant`}))},whiteboardScript:{efforts:async()=>(await Xq()).efforts.map(e=>({value:e.slug,label:`${e.label} (${e.slug})`})),equipment:async()=>(await Xq()).equipment.map(e=>({value:e.slug,label:`${e.label} (${e.slug})`})),tags:async()=>jj().list().map(e=>({value:e.slug})),sounds:()=>SJ().map(e=>({value:e.id,label:e.name}))}};function QZ(e,t){let n=e.doc.lineAt(t);if(n.number===1||e.doc.line(1).text.trim()!==`---`)return!1;for(let t=2;t<=n.number;t++)if(/^(---|\.\.\.)\s*$/.test(e.doc.line(t).text))return!1;return!0}function $Z(e,t){if(!QZ(e,t))return null;let n=e.doc.lineAt(t),r=n.text.slice(0,t-n.from),i=r.match(/^([a-zA-Z][\w.-]*)\s*:\s*(.*)$/);if(i)return{propertyKey:i[1],from:t-i[2].length,value:i[2]};let a=r.match(/^\s*-\s*(.*)$/);if(!a)return null;for(let r=n.number-1;r>1;r--){let n=e.doc.line(r).text.match(/^([a-zA-Z][\w.-]*)\s*:/);if(n)return{propertyKey:n[1],from:t-a[1].length,value:a[1]}}return null}function eQ(e,t){if(e.type!==`time`&&e.type!==`log`)return null;let n=e.contentFrom!==void 0&&e.contentTo!==void 0?t.doc.sliceString(e.contentFrom,e.contentTo):``,r=[];try{n.trim()&&(r=Cc({tags:jj()}).read(n,e.sport).statements??[])}catch{}return{id:e.id,contentId:e.contentId,dialect:e.type,sport:e.sport,startLine:e.startLine-1,endLine:e.endLine-1,content:n,statements:r,state:`idle`,version:t.field(_T).noteBlocks[e.id]?.version??1,createdAt:Date.now(),widgetIds:{}}}function tQ(e,t,n){if(!t)return;let r=e.field(_T).sections.filter(e=>e.type===`time`||e.type===`log`).map(t=>eQ(t,e)).filter(e=>e!==null),i=JSON.stringify(r.map(e=>({id:e.id,startLine:e.startLine,endLine:e.endLine,content:e.content})));i!==n.current&&(n.current=i,t(r))}function nQ({title:e,subtitle:t,doc:n,onDocChange:r,noteId:i,onBlocksChange:a,theme:o,readonly:s=!1,showLineNumbers:c=!1,enableOverlay:l=!1,enableInlineRuntime:u=!1,enablePreview:d=!0,showFrontmatter:f=!1,enableLinting:p=!0,commands:m,hideDefaultCommands:h,onViewCreated:g,onReset:_,run:v,headerActions:y,subheader:b,children:x,className:S,editorClassName:C,bodyRef:w}){let T=(0,U.useRef)([]),E=(0,U.useCallback)(e=>{T.current=e,a?.(e)},[a]),D=(0,U.useCallback)(()=>{v?.onRun(n,T.current[0]??null)},[v,n]),O=(0,W.jsxs)(W.Fragment,{children:[y,v&&(0,W.jsxs)(`button`,{ref:v.ref,type:`button`,title:v.title??`Run the workout`,onClick:D,className:`inline-flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1 text-[11px] font-medium text-primary-foreground transition-colors hover:bg-primary/90`,children:[(0,W.jsx)(pn,{size:11,fill:`currentColor`}),v.label??`Run`]})]});return(0,W.jsx)(zq,{title:e,subtitle:t,onReset:_,headerActions:O,className:S,children:(0,W.jsxs)(`div`,{className:`flex h-full flex-col min-h-0`,children:[b,(0,W.jsxs)(`div`,{ref:w,className:G(`relative flex-1 min-h-0`,C),children:[(0,W.jsx)(YZ,{noteId:i,value:n,onChange:r,onBlocksChange:E,theme:o,readonly:s,showLineNumbers:c,enableOverlay:l,enableInlineRuntime:u,enablePreview:d,showFrontmatter:f,enableLinting:p,commands:m,hideDefaultCommands:h,onViewCreated:g,className:`h-full`}),x]})]})})}function rQ({editorSource:e,editorOpacity:t,activeOriginalSource:n,handleEditorChange:r,onResetToSource:i,canvasNoteId:a,theme:o,commands:s,onBlocksChange:c,onViewCreated:l,panelTitle:u,panelSubtitle:d,panelThemeClass:f,headerActions:p,onRun:m,readonly:h=!1,showFrontmatter:g}){return(0,W.jsx)(`div`,{className:`h-full`,style:{opacity:t,transition:`opacity 180ms ease`},children:(0,W.jsx)(nQ,{title:u,subtitle:d,doc:e,onDocChange:r,noteId:a,onBlocksChange:c,onViewCreated:l,theme:o,readonly:h,showLineNumbers:!1,showFrontmatter:g,enableOverlay:!1,enableInlineRuntime:!1,commands:s,hideDefaultCommands:!1,headerActions:p,className:f,subheader:(0,W.jsxs)(`div`,{style:{opacity:t,transition:`opacity 180ms ease`},className:`flex items-center justify-between gap-3 border-b border-border/40 bg-primary/5 px-4 py-2 text-[11px] font-bold uppercase tracking-[0.18em] text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:`Try editing this example ↓`}),e===n?null:(0,W.jsx)(`button`,{type:`button`,onClick:()=>{i()},className:`rounded-full border border-primary/30 px-3 py-1 text-[10px] font-black text-primary transition-colors hover:bg-primary/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50`,children:`Reset to example`})]}),run:m?{onRun:m}:void 0})})}function iQ(e,t){return e>=t?`split`:`stack`}function aQ(e,t){let n=(0,U.useCallback)(()=>{if(typeof window>`u`)return{width:0,height:0,mode:`stack`};let t=window.innerWidth,n=Math.max(0,window.innerHeight-e);return{width:t,height:n,mode:iQ(t,n)}},[e]),[r,i]=(0,U.useState)(n);return(0,U.useEffect)(()=>{if(t&&typeof ResizeObserver<`u`){let e=new ResizeObserver(([e])=>{let{width:t,height:n}=e.contentRect;i(e=>e.width===t&&e.height===n?e:{width:t,height:n,mode:iQ(t,n)})});return e.observe(t),()=>e.disconnect()}let e=()=>i(e=>{let t=n();return e.width===t.width&&e.height===t.height?e:t});return window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[t,n]),r}var oQ=e=>Math.max(0,Math.min(1,e)),sQ=(e,t,n)=>e+(t-e)*n,cQ=e=>1-(1-e)**2;function lQ(e,t){return e===``||t===e}var uQ={id:``,range:[0,1]};function dQ(e,t){if(!t||t.length===0)return{index:-1,stage:uQ,t:0,ring:null};let n=oQ(e),r=t.map(e=>({...e,start:oQ(Math.min(e.range[0],e.range[1])),end:oQ(Math.max(e.range[0],e.range[1]))})),i=r.findIndex(e=>n>=e.start&&n<e.end);i===-1&&(i=n>=1?r.length-1:0);let a=r[i]??uQ,o=(a.end??1)-(a.start??0),s=o>0?oQ((n-(a.start??0))/o):0,c=a.ring?{tag:a.ring===!0?void 0:a.ring.tag,key:a.ring===!0?void 0:a.ring.key,lines:a.ring===!0?void 0:a.ring.lines}:null;return{index:i,stage:a,t:s,ring:c}}function fQ(e,t,n){let r=t-n;return{progress:r>0?oQ(-e/r):0,reached:e<=0,inView:e<n&&e+t>0}}function pQ(e,t){let n=t/2;for(let t of e)if(t.top<=n&&t.bottom>n)return t.id;return null}var mQ=(0,U.createContext)(null);function hQ(){return(0,U.useContext)(mQ)}function gQ({children:e}){let t=(0,U.useRef)(new Map),n=(0,U.useRef)(new Map),r=(0,U.useRef)(null),i=(0,U.useRef)(0),[a,o]=(0,U.useState)(null),s=(0,U.useRef)(null),c=(0,U.useCallback)(e=>{r.current?.gateId===e&&(r.current=null,o(null))},[]),l=(0,U.useCallback)((e,t)=>{r.current={gateId:e,segmentId:t},o(e)},[]),u=(0,U.useCallback)(()=>{i.current&&cancelAnimationFrame(i.current),i.current=0;let e=window.innerHeight,a=new Map,c=(e,t)=>{let n=t();n&&a.set(e,n.getBoundingClientRect())};t.current.forEach((e,t)=>c(t,e)),n.current.forEach((e,t)=>c(t,e.getEl));let l=[];a.forEach((e,t)=>l.push({id:t,top:e.top,bottom:e.top+e.height}));let u=pQ(l,e);if(u!==s.current){s.current=u;let e=r.current;e&&e.segmentId!==u&&(r.current=null,o(null))}n.current.forEach((t,n)=>{let r=a.get(n);if(!r||r.height-e<=0)return;let i=fQ(r.top,r.height,e);t.onMeasure({slice:dQ(i.progress,t.getStages()),progress:i.progress,reached:i.reached})})},[]),d=(0,U.useCallback)(()=>{i.current||=requestAnimationFrame(u)},[u]);(0,U.useEffect)(()=>(window.addEventListener(`scroll`,d,{passive:!0,capture:!0}),window.addEventListener(`resize`,d),u(),()=>{window.removeEventListener(`scroll`,d,{capture:!0}),window.removeEventListener(`resize`,d),i.current&&cancelAnimationFrame(i.current)}),[d,u]);let f=(0,U.useCallback)((e,n)=>(t.current.set(e,n),d(),()=>{t.current.delete(e)}),[d]),p=(0,U.useCallback)((e,t)=>(n.current.set(e,t),d(),()=>{n.current.delete(e)}),[d]),m=(0,U.useCallback)(()=>u(),[u]),h=(0,U.useMemo)(()=>({registerAnchor:f,registerDriver:p,resync:m,capturedGateId:a,captureGate:l,releaseGate:c}),[f,p,m,a,l,c]);return(0,W.jsx)(mQ.Provider,{value:h,children:e})}function _Q(e,t){let n=hQ()?.registerAnchor;(0,U.useEffect)(()=>{if(n)return n(e,()=>t.current)},[n,e,t])}function vQ({gateId:e,segmentId:t,className:n,children:r}){let i=hQ(),a=(0,U.useRef)(null),[o,s]=(0,U.useState)(!1);if((0,U.useEffect)(()=>{let e=a.current;if(!e||typeof ResizeObserver>`u`)return;let t=()=>{let t=e.querySelectorAll(`.cm-scroller, [data-scroll-pane], .overflow-auto, .overflow-y-auto`);s(e.scrollHeight>e.clientHeight+1||[...t].some(e=>e.scrollHeight>e.clientHeight+1))},n=new ResizeObserver(t);n.observe(e);let r=0,i=new MutationObserver(()=>{t(),window.clearTimeout(r),r=window.setTimeout(t,400)});i.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`]}),window.addEventListener(`resize`,t);let o=window.setTimeout(t,1200);return t(),()=>{window.clearTimeout(r),window.clearTimeout(o),n.disconnect(),i.disconnect(),window.removeEventListener(`resize`,t)}},[]),!i)return(0,W.jsx)(`div`,{className:n,children:r});let c=i.capturedGateId===e?`captured`:`yield`;return(0,W.jsxs)(`div`,{"data-scroll-gate":c,"data-gate-id":e,className:`${n??``} flex flex-col`,onFocus:n=>{let r=n.target;r instanceof HTMLElement&&r.closest(`input:not([readonly]):not([disabled]), textarea:not([readonly]):not([disabled]), select:not([disabled]), [contenteditable="true"]`)&&i.captureGate(e,t??null)},onBlur:t=>{(!(t.relatedTarget instanceof Node)||!t.currentTarget.contains(t.relatedTarget))&&i.releaseGate(e)},children:[(0,W.jsx)(`div`,{ref:a,className:`relative min-h-0 flex-1`,children:r}),(o||c===`captured`)&&(0,W.jsx)(`button`,{type:`button`,className:`min-h-11 self-start rounded px-3 py-2 text-xs text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-primary`,"aria-label":`Scroll ${e.replace(/-/g,` `)} content`,"aria-pressed":c===`captured`,onClick:()=>c===`captured`?i.releaseGate(e):i.captureGate(e,t??null),onKeyDown:t=>{t.key===`Escape`&&i.releaseGate(e)},children:c===`captured`?`Scroll page`:`Scroll panel`})]})}function yQ({trackRef:e,height:t,stages:n,activeIndex:r,pane:i,captions:a,status:o,segmentId:s,testId:c,className:l}){let[u,d]=(0,U.useState)(null),f=aQ(104,u).mode===`split`,p={status:o,pips:(0,W.jsx)(`div`,{className:`flex items-center gap-1.5`,"aria-hidden":`true`,children:n.map((e,t)=>{let n=r===t;return(0,W.jsx)(`span`,{className:`h-1 rounded-full transition-all duration-300`,style:{width:n?30:10,background:n?e.accent??`hsl(var(--primary))`:r>t?`hsl(var(--foreground))`:`hsl(var(--foreground) / 0.15)`}},e.id)})})};return(0,W.jsx)(`section`,{ref:e,"data-testid":c,className:l?`relative ${l}`:`relative`,style:{height:t},children:(0,W.jsx)(Lq.Provider,{value:p,children:(0,W.jsx)(`div`,{className:`sticky top-[65px] flex h-[calc(100dvh-65px)] flex-col overflow-hidden lg:top-[104px] lg:h-[calc(100dvh-104px)]`,children:(0,W.jsxs)(`div`,{ref:d,className:`mx-auto flex min-h-0 w-full max-w-[1500px] 2xl:max-w-[1720px] flex-1 px-5 pt-2 pb-5 lg:px-10 lg:pt-3 xl:px-16 xl:pb-8 2xl:pb-10 ${f?`flex-row items-stretch gap-[clamp(20px,2.5vw,56px)] xl:gap-12 2xl:gap-16`:`flex-col gap-6 xl:gap-8`}`,children:[(0,W.jsx)(`div`,{className:`relative min-h-0 min-w-0 flex-[3_1_0%]`,children:i}),(0,W.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-[2_1_0%] flex-col`,children:s?(0,W.jsx)(vQ,{gateId:`${s}-captions`,segmentId:s,className:`relative min-h-0 flex-1`,children:a}):(0,W.jsx)(`div`,{className:`relative min-h-0 flex-1`,children:a})})]})})})})}function bQ(e){let t=e.parentElement;for(;t;){let e=window.getComputedStyle(t).overflowY;if(e===`auto`||e===`scroll`)return t;t=t.parentElement}return window}function xQ(e,t,n=`smooth`){let r=bQ(e),i=e.offsetHeight-window.innerHeight;if(i<=0)return;if(r instanceof HTMLElement){let a=e.offsetTop;r.scrollTo({top:a+t*i,behavior:n});return}let a=e.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:a+t*i,behavior:n})}function SQ(e,t,n,r){let[i,a]=(0,U.useState)(()=>dQ(0,n)),[o,s]=(0,U.useState)(!1),c=(0,U.useRef)(0),l=(0,U.useRef)(i),u=(0,U.useRef)(new Set),d=(0,U.useRef)(0),f=(0,U.useRef)(t);f.current=t;let p=hQ(),m=p?.registerDriver,h=(0,U.useRef)(p);h.current=p;let g=(0,U.useId)(),_=r??g,v=(0,U.useRef)(n);v.current=n;let y=(0,U.useCallback)((e,t)=>{let n=l.current;l.current=e,c.current=t,(n.index!==e.index||n.ring?.key!==e.ring?.key)&&a(e),u.current.forEach(n=>n(e,t))},[]),b=(0,U.useCallback)(()=>{if(d.current=0,f.current)return;let t=e.current;if(!t)return;let n=t.getBoundingClientRect(),r=n.height-window.innerHeight;if(r<=0)return;let i=Math.max(0,Math.min(1,-n.top/r));s(n.top<=0),y(dQ(i,v.current),i)},[e,y]),x=(0,U.useCallback)(()=>{if(h.current){h.current.resync();return}b()},[b]),S=(0,U.useCallback)(()=>{d.current||=requestAnimationFrame(x)},[x]);(0,U.useEffect)(()=>{if(m)return m(_,{getEl:()=>e.current,getStages:()=>v.current,onMeasure:({slice:e,progress:t,reached:n})=>{f.current||(s(n),y(e,t))}})},[m,_,e,y]),(0,U.useEffect)(()=>{if(!m)return window.addEventListener(`scroll`,S,{passive:!0,capture:!0}),window.addEventListener(`resize`,S),b(),()=>{window.removeEventListener(`scroll`,S,{capture:!0}),window.removeEventListener(`resize`,S),d.current&&cancelAnimationFrame(d.current)}},[m,S,b]);let C=(0,U.useCallback)(e=>(u.current.add(e),e(l.current,c.current),()=>{u.current.delete(e)}),[]),w=(0,U.useCallback)(()=>{x()},[x]);return{slice:i,progress:c.current,runwayReached:o,subscribe:C,resync:w}}var CQ={reference:!0},wQ={start:[[`fences`,`first-workout`],[`measurements`,`actions-comments`],[`system`,`try-it`]],protocols:[[`countdown-countup`,`required-rest`],[`amrap`,`emom`],[`tabata-intervals`,`caps`,`distance-intervals`,`try-it`]],structure:[[`rounds`,`rep-schemes`,`sets`],[`nesting`,`rep-math`,`named-sections`,`try-it`]],metrics:[[`planned-vs-recorded`,`custom-metrics`],[`capture`,`session-rpe`],[`calculated`,`try-it`]],clock:[[`run-next`,`pause-skip`],[`capture-prompts`,`casting`,`provenance`,`try-it`]],wql:[[`planes`,`aggregate`,`filters`,`sources`],[`windows`,`grouping-rollup`,`joins`],[`content`,`pipes`,`try-it`]],dashboards:[[`note-frontmatter`,`avg-tis`,`weekly-tonnage`,`widgets`],[`composer`,`cookbook`,`seeded-boards`,`try-it`]],sessions:[[`intent`,`full-session`],[`nested`,`partner`,`swimming`],[`barbell-cycling`,`climbing`,`try-it`]]};function TQ(e,t){let n=e.filter(e=>!CQ[e.id]),r=e.filter(e=>CQ[e.id]);if(n.length===0)return{groups:[],tail:r};let i=t?wQ[t]:void 0;if(i){let e=new Map(n.map(e=>[e.id,e])),t=new Set,a=[];for(let n of i){let r=n.map(t=>e.get(t)).filter(e=>!!e&&!t.has(e.id));for(let e of r)t.add(e.id);r.length>0&&a.push(r)}let o=n.filter(e=>!t.has(e.id));if(o.length>0){let e=a[a.length-1];if(e&&e.length+o.length<=4)e.push(...o);else for(let e=0;e<o.length;e+=4)a.push(o.slice(e,e+4))}if(a.length>0)return{groups:a,tail:r}}let a=Math.max(1,Math.ceil(n.length/4)),o=Math.floor(n.length/a),s=n.length%a,c=[],l=0;for(let e=0;e<a;e++){let t=o+ +(e<s);c.push(n.slice(l,l+t)),l+=t}return{groups:c,tail:r}}function EQ(e){let t=Math.max(1,e.length);return e.map((e,n)=>({id:e.id,range:[n/t,(n+1)/t]}))}var DQ=[{src:`/images/hero/editing.png`,alt:`WhiteboardScript editor with live syntax highlighting and inline previews`,eyebrow:`Write`,title:`Type your workout in plain Markdown.`,caption:"Movements, reps, time caps, and rounds — fenced in a familiar ```time block. No drag-and-drop. No proprietary DSL."},{src:`/images/hero/timer.png`,alt:`Live runtime timer HUD counting down an interval with active round and rest indicators`,eyebrow:`Run`,title:`Press Run. The compiler takes over.`,caption:`Your Markdown becomes a live wallclock. The JIT engine dispatches rounds, counts reps, and tracks rest — all offline.`},{src:`/images/hero/journal.png`,alt:`Unified Library listing journal notes, notebook workouts, and dated entries`,eyebrow:`Library`,title:`Browse Journal and Notebook notes in one Library.`,caption:`Your dated journal notes and preloaded notebook benchmarks live in one unified surface. Search, filter by source, or clone to today’s note.`},{src:`/images/hero/results.png`,alt:`WQL Metric Explorer displaying volume trends and embedded dashboard blocks`,eyebrow:`Query`,title:`Ask questions with Wod Query Language (WQL).`,caption:`Aggregate volume, track TIS intensity trends, or embed live query and dashboard blocks directly in your Markdown notes.`}];function OQ({slides:e=DQ,className:t}){let n=(0,U.useRef)(null),[r,i]=(0,U.useState)(0);(0,U.useEffect)(()=>{let t=n.current;if(!t)return;let r=()=>{let n=t.clientWidth,r=Math.round(t.scrollLeft/n);i(Math.min(Math.max(r,0),e.length-1))};return t.addEventListener(`scroll`,r,{passive:!0}),()=>t.removeEventListener(`scroll`,r)},[e.length]);let a=e=>{let t=n.current;t&&t.scrollTo({left:e*t.clientWidth,behavior:`smooth`})};return(0,W.jsxs)(`div`,{className:G(`relative w-full`,t),children:[(0,W.jsx)(`div`,{ref:n,className:`flex w-full snap-x snap-mandatory overflow-x-auto scroll-smooth scrollbar-none`,style:{scrollbarWidth:`none`},children:e.map((t,n)=>(0,W.jsxs)(`article`,{className:`relative flex w-full shrink-0 snap-start flex-col gap-4 sm:flex-row sm:items-center sm:gap-8`,"aria-label":`Slide ${n+1} of ${e.length}: ${t.title}`,children:[(0,W.jsx)(`div`,{className:`relative aspect-[16/10] w-full overflow-hidden rounded-2xl border border-border/60 bg-muted shadow-sm sm:w-1/2`,children:(0,W.jsx)(`img`,{src:t.src,alt:t.alt,loading:n===0?`eager`:`lazy`,className:`h-full w-full object-cover`})}),(0,W.jsxs)(`div`,{className:`flex w-full flex-col gap-2 sm:w-1/2 sm:gap-3`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-[0.24em] text-primary/80`,children:t.eyebrow}),(0,W.jsx)(`h3`,{className:`text-2xl font-black tracking-[-0.04em] text-foreground sm:text-3xl`,children:t.title}),(0,W.jsx)(`p`,{className:`text-sm leading-7 text-muted-foreground sm:text-base`,children:t.caption}),(0,W.jsxs)(`div`,{className:`mt-2 inline-flex items-center gap-2 text-[10px] font-black uppercase tracking-[0.2em] text-muted-foreground`,children:[(0,W.jsxs)(`span`,{className:`text-primary`,children:[`Step `,n+1]}),(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`/`}),(0,W.jsx)(`span`,{children:e.length})]})]})]},t.src))}),(0,W.jsx)(`div`,{className:`mt-4 flex items-center justify-center gap-2`,children:e.map((e,t)=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>a(t),"aria-label":`Go to slide ${t+1}: ${e.title}`,"aria-current":t===r?`true`:`false`,className:G(`h-2 rounded-full transition-all`,t===r?`w-8 bg-primary`:`w-2 bg-border hover:bg-muted-foreground/40`)},e.src))})]})}var kQ=`wodwiki:text-filter-navigation`,AQ=({paramName:e=`q`,placeholder:t=`Search…`,autoFocus:n=!1,className:r,navigationScope:i,inputTestId:a})=>{let[o,s]=Kt(e,{defaultValue:``}),c=i??e,l=(0,U.useRef)(null);return(0,U.useEffect)(()=>{let e=e=>{e.key===`/`&&document.activeElement?.tagName!==`INPUT`&&document.activeElement?.tagName!==`TEXTAREA`&&(e.preventDefault(),l.current?.focus())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[]),(0,W.jsxs)(`div`,{className:G(`flex items-center gap-3 px-6 lg:px-10 pb-3`,r),children:[(0,W.jsx)(en,{className:`size-5 text-muted-foreground shrink-0`}),(0,W.jsx)(`input`,{ref:l,type:`text`,"data-testid":a,value:o,onChange:e=>s(e.target.value),onKeyDown:e=>{if(e.altKey||e.ctrlKey||e.metaKey||![`ArrowUp`,`ArrowDown`,`ArrowLeft`,`ArrowRight`,`Enter`].includes(e.key))return;let t=new CustomEvent(kQ,{detail:{key:e.key,scopeId:c},cancelable:!0});window.dispatchEvent(t),t.defaultPrevented&&e.preventDefault()},placeholder:t,autoFocus:n,autoComplete:`off`,spellCheck:!1,className:`flex-1 bg-transparent border-none outline-none text-foreground placeholder:text-muted-foreground text-sm sm:text-base font-medium`}),o&&(0,W.jsx)(`button`,{onClick:()=>s(``),"aria-label":`Clear`,className:`text-muted-foreground hover:text-foreground transition-colors text-lg leading-none`,children:`×`})]})};function jQ(e){let t=[],n=!1;for(let r of e){if(r.trim()===`---`){n=!n;continue}n||t.push(r)}return t}function MQ(e){let t=e;return t=t.replace(/\*\*([^*]+)\*\*/g,`$1`),t=t.replace(/__([^_]+)__/g,`$1`),t=t.replace(/`([^`]+)`/g,`$1`),t=t.replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`),t=t.replace(/\*\*/g,``),t=t.replace(/__/g,``),t=t.replace(/`/g,``),t.trim()}function NQ(e){return new Date(e).toISOString().slice(0,10)}function PQ(e,t){let n=t.trim().toLowerCase();return!n||e.name.toLowerCase().includes(n)||e.content.toLowerCase().includes(n)||e.date!==void 0&&NQ(e.date).includes(n)}function FQ(e){if(!e)return null;let t=jQ(Gy(e).split(`
161
161
  `)).map(e=>e.trim()).filter(e=>e.length>0&&!e.startsWith(`#`)&&!e.startsWith("```"))[0];return t?MQ(t):null}var IQ=({category:e,workoutItems:t,onSelect:n,showSearch:r=!0,variant:i=`card`,className:a,navigationScope:o=`q`,getItemActions:s})=>{let[c]=Kt(`q`,{defaultValue:``}),[l,u]=(0,U.useState)(0),[d,f]=(0,U.useState)(0),p=(0,U.useRef)([]),m=(0,U.useMemo)(()=>t.filter(t=>t.category===e&&t.name.toLowerCase()!==`readme`).filter(e=>PQ(e,c)),[t,e,c]),h=(0,U.useMemo)(()=>m.map(e=>({item:e,preview:FQ(e.content),actions:s?.(e)??[{id:`open`,label:`Open`,onSelect:n}]})),[m,s,n]);return(0,U.useEffect)(()=>{if(h.length===0){u(0),f(0);return}let e=Math.min(l,h.length-1),t=h[e]?.actions.length??1;e!==l&&u(e),d>t-1&&f(t-1)},[h,d,l]),(0,U.useEffect)(()=>{p.current=[]},[h]),(0,U.useEffect)(()=>{u(0),f(0)},[c]),(0,U.useEffect)(()=>{(p.current[l]?.[d])?.scrollIntoView({block:`nearest`,inline:`nearest`})},[d,l]),(0,U.useEffect)(()=>{let e=e=>{let t=e;if(t.detail.scopeId===o&&h.length!==0)switch(t.detail.key){case`ArrowDown`:t.preventDefault(),u(e=>Math.min(e+1,h.length-1)),f(0);break;case`ArrowUp`:t.preventDefault(),u(e=>Math.max(e-1,0)),f(0);break;case`ArrowRight`:{let e=h[l]?.actions.length??1;if(e<=1)return;t.preventDefault(),f(t=>Math.min(t+1,e-1));break}case`ArrowLeft`:if((h[l]?.actions.length??1)<=1)return;t.preventDefault(),f(e=>Math.max(e-1,0));break;case`Enter`:{let e=h[l]?.actions[d],n=h[l]?.item;if(!e||!n)return;t.preventDefault(),e.onSelect(n);break}}};return window.addEventListener(kQ,e),()=>{window.removeEventListener(kQ,e)}},[h,o,d,l]),(0,W.jsxs)(`div`,{className:G(`flex flex-col`,i===`card`&&`rounded-3xl border border-border bg-card overflow-hidden shadow-2xl shadow-black/5`,a),children:[r?(0,W.jsx)(`div`,{className:`border-b border-border/60 bg-background/95 backdrop-blur-md`,children:(0,W.jsx)(AQ,{placeholder:`Filter collection workouts…`,className:`pt-3`,navigationScope:o})}):null,h.length===0?(0,W.jsx)(`div`,{className:`px-6 py-10 text-sm font-medium text-muted-foreground`,children:`No workouts found.`}):(0,W.jsx)(`div`,{className:`divide-y divide-border/60`,role:`listbox`,"aria-label":`Collection workouts`,children:h.map((e,t)=>{let n=t===l;return(0,W.jsx)(`div`,{role:`option`,"aria-selected":n,className:G(`flex items-stretch gap-2 px-3 py-2 transition-colors`,n?`bg-muted/50`:`hover:bg-muted/40`),children:e.actions.map((r,i)=>{let a=i===0;return(0,W.jsx)(`button`,{ref:e=>{p.current[t]||(p.current[t]=[]),p.current[t][i]=e},onClick:()=>r.onSelect(e.item),onMouseEnter:()=>{u(t),f(i)},className:G(`transition-colors text-left`,a?`flex-1 flex items-center gap-4 rounded-2xl px-3 py-2 hover:bg-background/80`:`shrink-0 self-center rounded-full border border-border px-3 py-2 text-[11px] font-black uppercase tracking-[0.18em] text-muted-foreground hover:bg-background/80 hover:text-foreground`,n&&i===d&&`bg-background text-foreground ring-2 ring-primary/40`),children:a?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`flex-shrink-0 size-10 rounded-xl bg-muted flex items-center justify-center transition-colors`,children:(0,W.jsx)(se,{className:`size-4 text-primary`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-bold text-foreground truncate uppercase tracking-tight`,children:e.item.displayName??e.item.name}),e.preview?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground font-medium truncate mt-1`,children:e.preview}):null]}),e.item.date===void 0?null:(0,W.jsx)(`span`,{className:`shrink-0 self-center text-[11px] font-semibold uppercase tracking-wide text-muted-foreground`,children:Ny(new Date(e.item.date))}),(0,W.jsx)(wn,{className:`size-4 text-muted-foreground shrink-0 transition-opacity`})]}):r.label},r.id)})},e.item.id)})})]})};function LQ(){return(0,U.useEffect)(()=>{tz().catch(e=>console.warn(`[queryService] page source population failed`,e))},[]),(0,U.useSyncExternalStore)(iz,rz)}function RQ(e,t){let n=e.find(e=>e.key===t&&!e.negate);return n&&n.values.length===1?n.values[0].value:null}function zQ(e){let t=e.trim();if(!t.startsWith(`:`))return null;let n=_F(t),r=X(n);if(r.error||!Bm(r))return null;let i=`?q=${encodeURIComponent(n)}`;switch(r.target){case`effort`:return`/efforts${i}`;case`session`:case`segment`:case`event`:return`/sessions${i}`;case`notebook`:{let e=RQ(r.filters,`notebook`);if(e){let t=Da(e);return`/notebook/${encodeURIComponent(t)}${i}`}return`/notebooks${i}`}case`page`:return`/pages${i}`;case`tag`:return`/tags${i}`;case`equipment`:return`/equipment${i}`;case`note`:case`block`:{let e=RQ(r.filters,`notebook`);if(e){let t=Da(e);return t===`journal`?`/journal${i}`:t===`playground`?`/playgrounds${i}`:`/notebook/${encodeURIComponent(t)}${i}`}let t=RQ(r.filters,`source`);return t===`journal`?`/journal${i}`:t===`playground`?`/playgrounds${i}`:t===`feeds`||t===`notebooks`||t===`notebook`||t===`guides`?`/notes${i}`:RQ(r.filters,`type`)===`dashboard`?`/dashboards${i}`:`/notes${i}`}default:return null}}var BQ=new Set([`pdf`,`doc`,`docx`,`xls`,`xlsx`,`ppt`,`pptx`,`zip`,`tar`,`gz`,`rar`,`mp4`,`mov`,`avi`,`mkv`,`webm`,`mp3`,`wav`,`flac`,`png`,`jpg`,`jpeg`,`gif`,`svg`,`webp`]);function VQ(e){let t=e.split(`.`).pop()?.split(`?`)[0]?.toLowerCase()??``;return BQ.has(t)}function HQ(e){return/^https?:\/\//.test(e)||e.startsWith(`//`)}function UQ({queryText:e,widgetType:t,widgetError:n}){return LQ()?(0,W.jsx)(`div`,{className:`my-5 not-prose`,children:(0,W.jsx)(Jw,{query:e,widgetType:t,widgetError:n,executor:sz,readOnly:!0,noteHref:e=>tU(`blockContentId`in e||`dataType`in e?Dz(e):xz(e))})}):(0,W.jsx)(`div`,{className:`my-5 not-prose text-xs text-muted-foreground py-2`,children:`Loading…`})}function WQ(e){let{meta:t,body:n}=By(e);return Object.keys(t).length===0&&n===e?{fields:null,body:e}:{fields:t,body:n.trim()}}var GQ={table({children:e}){return(0,W.jsx)(`div`,{className:`my-6 overflow-x-auto rounded-xl border border-border`,children:(0,W.jsx)(`table`,{className:`w-full text-sm border-collapse`,children:e})})},thead({children:e}){return(0,W.jsx)(`thead`,{className:`bg-muted/50 text-left`,children:e})},tbody({children:e}){return(0,W.jsx)(`tbody`,{className:`divide-y divide-border/50`,children:e})},tr({children:e}){return(0,W.jsx)(`tr`,{className:`hover:bg-muted/20 transition-colors`,children:e})},th({children:e}){return(0,W.jsx)(`th`,{className:`px-4 py-2.5 text-[11px] font-black tracking-widest uppercase text-muted-foreground border-b border-border`,children:e})},td({children:e}){return(0,W.jsx)(`td`,{className:`px-4 py-2.5 text-sm text-foreground`,children:e})},img({src:e,alt:t,node:n}){let r=n?.properties??{},i=r.width,a=r.height;return(0,W.jsxs)(`figure`,{className:`my-6`,children:[(0,W.jsx)(`img`,{src:e??``,alt:t??``,loading:`lazy`,width:i,height:a,className:`rounded-xl border border-border max-w-full h-auto`}),t&&(0,W.jsx)(`figcaption`,{className:`mt-2 text-center text-xs text-muted-foreground italic`,children:t})]})},a({href:e,children:t}){let n=e??``;if(n.startsWith(`:`)){let e=n;try{e=decodeURIComponent(n)}catch{}let r=zQ(e);if(r)return(0,W.jsx)(_n,{to:r,className:`underline underline-offset-2 transition-colors text-primary hover:text-primary/70`,children:t})}let r=HQ(n),i=VQ(n);return(0,W.jsxs)(`a`,{href:n,rel:r?`noopener noreferrer`:void 0,target:r||i?`_blank`:void 0,className:G(`underline underline-offset-2 transition-colors`,i?`text-primary font-medium`:`text-primary hover:text-primary/70`),children:[t,r&&(0,W.jsx)(`span`,{className:`ml-0.5 text-[10px] align-super opacity-60`,children:`↗`}),i&&!r&&(0,W.jsx)(`span`,{className:`ml-0.5 text-[10px] align-super opacity-60`,children:`⬇`})]})},code({children:e,className:t}){let n=t?.replace(`language-`,``)??``,r=typeof e==`string`?e:Array.isArray(e)?e.join(``):String(e??``);if(!t&&!r.includes(`
162
162
  `))return(0,W.jsx)(`code`,{className:`px-1.5 py-0.5 rounded-md bg-muted font-mono text-[0.85em] text-foreground`,children:e});if(n===`query`||n.startsWith(`query:`)||n.startsWith(`query `)){let t=(typeof e==`string`?e:Array.isArray(e)?e.join(``):String(e??``)).trim(),r=n.replace(/^query[:\s]?/,``).trim(),i=r?J_(r):void 0;return(0,W.jsx)(UQ,{queryText:t,widgetType:i?.type,widgetError:i?.error})}return(0,W.jsxs)(`div`,{className:`my-5 rounded-xl overflow-hidden border border-border`,children:[n&&(0,W.jsx)(`div`,{className:`flex items-center gap-2 px-4 py-2 bg-muted border-b border-border`,children:(0,W.jsx)(`span`,{className:`text-[10px] font-black tracking-widest uppercase text-muted-foreground`,children:n})}),(0,W.jsx)(`pre`,{className:`overflow-x-auto p-4 bg-muted/30`,children:(0,W.jsx)(`code`,{className:`font-mono text-sm text-foreground`,children:e})})]})},h1({children:e,id:t}){return(0,W.jsx)(`h1`,{id:t,className:`text-2xl lg:text-3xl font-black tracking-tight text-foreground uppercase leading-tight mt-10 mb-4 first:mt-0`,children:e})},h2({children:e,id:t}){return(0,W.jsx)(`h2`,{id:t,className:`text-xl lg:text-2xl font-black tracking-tight text-foreground uppercase leading-tight mt-8 mb-3 first:mt-0`,children:e})},h3({children:e,id:t}){return(0,W.jsx)(`h3`,{id:t,className:`text-base lg:text-lg font-black tracking-wide text-foreground uppercase mt-6 mb-2 first:mt-0`,children:e})},h4({children:e,id:t}){return(0,W.jsx)(`h4`,{id:t,className:`text-sm font-black tracking-widest text-primary uppercase mt-5 mb-2 first:mt-0`,children:e})},p({children:e}){return(0,W.jsx)(`p`,{className:`text-sm lg:text-[15px] font-medium text-muted-foreground leading-relaxed my-4 first:mt-0`,children:e})},ul({children:e}){return(0,W.jsx)(`ul`,{className:`my-4 pl-5 space-y-1.5 list-disc list-outside text-left text-sm text-muted-foreground font-medium leading-relaxed`,children:e})},ol({children:e}){return(0,W.jsx)(`ol`,{className:`my-4 pl-5 space-y-1.5 list-decimal list-outside text-left text-sm text-muted-foreground font-medium leading-relaxed`,children:e})},li({children:e}){return(0,W.jsx)(`li`,{className:`leading-relaxed`,children:e})},blockquote({children:e}){return(0,W.jsx)(`blockquote`,{className:`my-5 pl-4 border-l-2 border-primary/40 text-muted-foreground italic text-sm`,children:e})},hr(){return(0,W.jsx)(`hr`,{className:`my-8 border-border/50`})},strong({children:e}){return(0,W.jsx)(`strong`,{className:`font-black text-foreground`,children:e})},em({children:e}){return(0,W.jsx)(`em`,{className:`italic text-foreground/80`,children:e})}},KQ={...GQ,p({children:e}){return(0,W.jsx)(`p`,{className:`text-3xl sm:text-4xl lg:text-5xl font-black tracking-tight text-foreground leading-[1.08] my-0`,children:e})},strong({children:e}){let t=U.Children.toArray(e).map(e=>typeof e==`string`||typeof e==`number`?String(e):``).join(``).trim();return t.includes(`Write it in Markdown`)&&t.includes(`Run it as a Timer`)&&t.includes(`Own the Analytics`)?(0,W.jsxs)(`span`,{className:`flex flex-col select-none mt-4 w-full gap-5 sm:gap-7`,children:[(0,W.jsxs)(`span`,{className:`block text-3xl sm:text-4xl lg:text-5xl text-primary font-black text-left pl-[5%] sm:pl-[10%] transform hover:translate-x-1 transition-transform duration-200`,children:[`Write it in `,(0,W.jsx)(`span`,{className:`inline-block border-b-4 border-primary/70 pb-1 hover:scale-105 transition-transform duration-200`,children:`Markdown`}),`.`]}),(0,W.jsxs)(`span`,{className:`block text-3xl sm:text-4xl lg:text-5xl text-primary font-black text-center transform hover:scale-[1.02] transition-transform duration-200`,children:[(0,W.jsx)(`span`,{className:`inline-block border-b-4 border-primary/70 pb-1 hover:scale-105 transition-transform duration-200`,children:`Run`}),` it as a Timer.`]}),(0,W.jsxs)(`span`,{className:`block text-3xl sm:text-4xl lg:text-5xl text-primary font-black text-right pr-[5%] sm:pr-[10%] transform hover:-translate-x-1 transition-transform duration-200`,children:[`Own the `,(0,W.jsx)(`span`,{className:`inline-block border-b-4 border-primary/70 pb-1 hover:scale-105 transition-transform duration-200`,children:`Analytics`}),`.`]})]}):(0,W.jsx)(`strong`,{className:`font-black text-foreground`,children:e})}},qQ={...GQ,p({children:e}){return(0,W.jsx)(`p`,{className:`text-base lg:text-lg font-medium text-foreground/75 leading-relaxed my-4 first:mt-0`,children:e})}},JQ=[Gn];function YQ(e){return e.startsWith(`:`)?e:Fn(e)}function XQ(e){return e.type===`text`&&typeof e.value==`string`?e.value:(e.children??[]).map(XQ).join(``)}function ZQ(e){return e.trim().toLowerCase().replace(/[^\p{L}\p{N} _-]/gu,``).replace(/ /g,`-`).replace(/-+/g,`-`)||`heading`}var QQ=()=>e=>{let t=new Map,n=e=>{if(e.tagName&&/^h[1-6]$/.test(e.tagName)){let n=ZQ(XQ(e)),r=t.get(n)??0;t.set(n,r+1),(e.properties??={}).id=r===0?n:`${n}-${r}`}for(let t of e.children??[])n(t)};n(e)};function $Q({fields:e}){let t=Object.entries(e);return t.length===0?null:(0,W.jsxs)(`div`,{className:`my-6 rounded-xl border border-border bg-muted/30 overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`px-4 py-2 border-b border-border bg-muted/50`,children:(0,W.jsx)(`span`,{className:`text-[10px] font-black tracking-[0.2em] uppercase text-muted-foreground`,children:`Metadata`})}),(0,W.jsx)(`dl`,{className:`divide-y divide-border/50`,children:t.map(([e,t])=>(0,W.jsxs)(`div`,{className:`flex items-baseline gap-4 px-4 py-2`,children:[(0,W.jsx)(`dt`,{className:`text-[11px] font-semibold text-muted-foreground uppercase tracking-wide min-w-[100px] shrink-0`,children:e}),(0,W.jsx)(`dd`,{className:`text-sm text-foreground break-words`,children:Array.isArray(t)?t.join(`, `):String(t)})]},e))})]})}var e$={default:GQ,heroLead:KQ,heroBody:qQ};function t$({prose:e,className:t,variant:n=`default`}){if(!e)return null;let{fields:r,body:i}=WQ(e);return(0,W.jsxs)(`div`,{className:G(`prose-canvas`,t),children:[r&&(0,W.jsx)($Q,{fields:r}),i&&(0,W.jsx)(gn,{remarkPlugins:JQ,rehypePlugins:[QQ],urlTransform:YQ,components:e$[n],children:i})]})}var n$=({activations:e,fullBleed:t,runState:n,deps:r})=>{if(e.length===0)return null;let i=e[0];if(rI(i)&&n){let a=e.slice(1),o=n.isReconnect?(0,W.jsxs)(`button`,{onClick:n.onReconnect,className:G(`flex items-center gap-2 px-5 py-2 text-[11px] font-black uppercase tracking-widest`,`rounded-full border transition-all active:scale-95`,`border-amber-500/40 bg-amber-500/15 text-amber-600 hover:bg-amber-500/20`,`dark:text-amber-400`,t&&`mx-auto`),children:[(0,W.jsx)(Ye,{className:`size-3.5`}),`View`]}):(0,W.jsxs)(`button`,{type:`button`,onClick:n.onRun,className:G(`flex items-center gap-2 transition-all active:scale-95 bg-primary text-primary-foreground hover:bg-primary/90 font-black uppercase tracking-widest rounded-full shadow-lg shadow-primary/25 min-h-[44px] px-6 py-2 text-xs`,t&&`mx-auto`),children:[(()=>{let e=i.icon||pn;return(0,W.jsx)(e,{className:`shrink-0 size-4 fill-current sm:size-3`})})(),(0,W.jsx)(`span`,{children:i.label})]});return(0,W.jsxs)(`div`,{className:G(`flex flex-wrap items-center gap-4 mt-8`,t&&`justify-center`),children:[o,a.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,r),className:`flex items-center gap-2 px-6 py-2 text-xs font-black uppercase tracking-widest rounded-full bg-background border border-border text-foreground hover:bg-muted transition-all active:scale-95`,children:e.label},e.id||t))]})}return(0,W.jsx)(`div`,{className:G(`flex flex-wrap gap-4 mt-8`,t&&`justify-center`),children:e.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,r),className:G(`flex items-center gap-2 px-8 py-4 text-xs font-black uppercase tracking-widest rounded-full transition-all active:scale-95`,t===0?`bg-primary text-primary-foreground shadow-xl shadow-primary/25 hover:scale-[1.04]`:`bg-background border border-border text-foreground hover:bg-muted`),children:e.label},e.id||t))})},r$=({examples:e,activeIndex:t,onSelect:n})=>e.length===0?null:(0,W.jsx)(`div`,{className:`mt-6 rounded-2xl border border-border/70 bg-card/80 backdrop-blur-sm`,children:(0,W.jsx)(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-3`,children:e.map((e,r)=>{let i=r===t,a=e.anchor===!0&&!i,o=!!e.badge&&a;return(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(r),"aria-current":i?`true`:void 0,className:G(`relative rounded-full px-4 py-2 text-[11px] font-black uppercase tracking-[0.18em] transition-all active:scale-95`,i?`bg-primary text-primary-foreground shadow-lg shadow-primary/25`:a?`border border-brand bg-brand/5 text-brand-deep hover:bg-brand/10 dark:text-brand-light`:`border border-border bg-background text-muted-foreground hover:bg-muted hover:text-foreground`),children:[e.label,o?(0,W.jsx)(`span`,{className:`ml-2 inline-block rounded-pill bg-brand px-1.5 py-0.5 align-middle text-[8px] font-black leading-none tracking-[0.12em] text-background`,children:e.badge}):null]},`${e.label}-${r}`)})})}),i$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`struct-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E676`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00F2FF`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#struct-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M35 35 L65 35 L65 45 L45 45 L45 65 L35 65 Z`,fill:`url(#struct-grad)`}),(0,W.jsx)(`path`,{d:`M55 45 L65 45 L65 65 L45 65 L45 55 L55 55 Z`,fill:`url(#struct-grad)`,opacity:`0.7`})]}),a$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`proto-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#FFD600`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#FFAB00`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#proto-grad)`,strokeWidth:`4`}),(0,W.jsx)(`circle`,{cx:`50`,cy:`50`,r:`5`,fill:`url(#proto-grad)`}),(0,W.jsx)(`circle`,{cx:`50`,cy:`50`,r:`15`,fill:`none`,stroke:`url(#proto-grad)`,strokeWidth:`2`,strokeDasharray:`4 2`}),(0,W.jsx)(`circle`,{cx:`50`,cy:`50`,r:`25`,fill:`none`,stroke:`url(#proto-grad)`,strokeWidth:`1`,opacity:`0.5`}),(0,W.jsx)(`line`,{x1:`50`,y1:`50`,x2:`50`,y2:`25`,stroke:`url(#proto-grad)`,strokeWidth:`4`,strokeLinecap:`round`})]}),o$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`complex-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#F50057`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#D500F9`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#complex-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M40 35 H60 V45 A5 5 0 0 1 60 55 V65 H40 V55 A5 5 0 0 0 40 45 Z`,fill:`url(#complex-grad)`})]}),s$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsxs)(`defs`,{children:[(0,W.jsxs)(`linearGradient`,{id:`basics-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00F2FF`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#6200EA`,stopOpacity:1}})]}),(0,W.jsxs)(`filter`,{id:`glow`,x:`-20%`,y:`-20%`,width:`140%`,height:`140%`,children:[(0,W.jsx)(`feGaussianBlur`,{stdDeviation:`3`,result:`blur`}),(0,W.jsx)(`feComposite`,{in:`SourceGraphic`,in2:`blur`,operator:`over`})]})]}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#basics-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M55 20 L30 55 L45 55 L40 85 L70 45 L55 45 Z`,fill:`url(#basics-grad)`,filter:`url(#glow)`})]}),c$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`basics-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00F2FF`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#6200EA`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#basics-grad)`,strokeWidth:`4`}),(0,W.jsx)(`text`,{x:`50`,y:`65`,fontFamily:`monospace`,fontSize:`40`,fontWeight:`bold`,fill:`url(#basics-grad)`,textAnchor:`middle`,children:`10`})]}),l$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`basics-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00F2FF`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#6200EA`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#basics-grad)`,strokeWidth:`4`}),(0,W.jsx)(`rect`,{x:`30`,y:`30`,width:`40`,height:`8`,rx:`2`,fill:`url(#basics-grad)`}),(0,W.jsx)(`rect`,{x:`30`,y:`45`,width:`40`,height:`8`,rx:`2`,fill:`url(#basics-grad)`}),(0,W.jsx)(`rect`,{x:`30`,y:`60`,width:`40`,height:`8`,rx:`2`,fill:`url(#basics-grad)`})]}),u$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`struct-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E676`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00F2FF`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#struct-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M50 30 A20 20 0 1 1 35.8 35.8 L30 30 M35.8 35.8 L42 38`,fill:`none`,stroke:`url(#struct-grad)`,strokeWidth:`6`,strokeLinecap:`round`})]}),d$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`struct-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E676`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00F2FF`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#struct-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M30 40 L45 40 M30 50 L55 50 M30 60 L70 60`,fill:`none`,stroke:`url(#struct-grad)`,strokeWidth:`6`,strokeLinecap:`round`}),(0,W.jsx)(`text`,{x:`50`,y:`30`,fontFamily:`monospace`,fontSize:`12`,fill:`url(#struct-grad)`,textAnchor:`middle`,children:`21-15-9`})]}),f$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`proto-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#FFD600`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#FFAB00`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#proto-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M35 35 H65 V55 L50 70 L35 55 Z`,fill:`url(#proto-grad)`}),(0,W.jsx)(`circle`,{cx:`50`,cy:`45`,r:`4`,fill:`#0b1326`})]}),p$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`metric-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E5FF`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#1DE9B6`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#metric-grad)`,strokeWidth:`4`}),(0,W.jsx)(`rect`,{x:`30`,y:`60`,width:`10`,height:`15`,fill:`url(#metric-grad)`}),(0,W.jsx)(`rect`,{x:`45`,y:`40`,width:`10`,height:`35`,fill:`url(#metric-grad)`}),(0,W.jsx)(`rect`,{x:`60`,y:`25`,width:`10`,height:`50`,fill:`url(#metric-grad)`})]}),m$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`metric-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#00E5FF`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#1DE9B6`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#metric-grad)`,strokeWidth:`4`}),(0,W.jsx)(`path`,{d:`M35 40 L65 60 M65 40 L35 60 M35 30 H65 M35 70 H65`,fill:`none`,stroke:`url(#metric-grad)`,strokeWidth:`4`,strokeLinecap:`round`})]}),h$=e=>(0,W.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,viewBox:`0 0 100 100`,...e,children:[(0,W.jsx)(`defs`,{children:(0,W.jsxs)(`linearGradient`,{id:`dialect-grad`,x1:`0%`,y1:`0%`,x2:`100%`,y2:`100%`,children:[(0,W.jsx)(`stop`,{offset:`0%`,style:{stopColor:`#76FF03`,stopOpacity:1}}),(0,W.jsx)(`stop`,{offset:`100%`,style:{stopColor:`#00E676`,stopOpacity:1}})]})}),(0,W.jsx)(`path`,{d:`M50 5 L90 27.5 L90 72.5 L50 95 L10 72.5 L10 27.5 Z`,fill:`none`,stroke:`url(#dialect-grad)`,strokeWidth:`4`,strokeLinecap:`round`}),(0,W.jsx)(`path`,{d:`M35 30 H65 M35 45 H65 M35 60 H55 M35 75 H65`,fill:`none`,stroke:`url(#dialect-grad)`,strokeWidth:`4`,strokeLinecap:`round`})]});function g$(e){switch(e){case`trophy`:return s$;case`dumbbell`:return se;case`timer`:return a$;case`play`:return pn;case`blocks`:return i$;case`puzzle`:return o$;case`activity`:return p$;case`file-text`:return h$;default:return qe}}function _$(e){switch(e){case`basics-movement`:return s$;case`basics-reps`:return c$;case`basics-load`:return l$;case`structure-rounds`:case`complex-rounds`:case`protocols-rounds`:return u$;case`structure-repscheme`:return d$;case`protocols-timer`:case`complex-time`:return a$;case`protocols-tag`:return f$;case`metrics-custom`:return p$;case`metrics-calc`:return m$;case`dialects-log`:case`dialects-climb`:return h$;default:return null}}function v$({quest:e,onClick:t,className:n,compact:r=!1,disabled:i=!1}){let a=_$(e.id),o=t?`Select to jump to its section.`:`Open the editor to begin.`,s=e.isCompleted?`Challenge complete.`:e.result?e.result.pass?`Ready — ${e.result.detail??`looks good`}`:e.result.reason??o:o,c={"data-testid":`challenge-row-${e.id}`,"data-completed":e.isCompleted?`true`:`false`,className:G(`w-full text-left flex items-start gap-3 rounded-xl border px-3 py-2 text-sm transition-colors`,e.isCompleted?`border-primary/40 bg-primary/5`:`border-border/50 bg-background/60`,t&&!i&&`cursor-pointer hover:bg-background/80`,i&&`opacity-60 cursor-default`,r&&`px-2.5 py-1.5`,n)},l=(0,W.jsxs)(W.Fragment,{children:[a?(0,W.jsxs)(`span`,{className:G(`relative shrink-0 mt-0.5`,r?`size-5`:`size-6`),children:[(0,W.jsx)(a,{className:`w-full h-full`}),e.isCompleted&&(0,W.jsx)(`span`,{className:`absolute -bottom-1 -right-1 flex size-3.5 items-center justify-center rounded-full bg-emerald-500 text-white border border-background shadow`,children:(0,W.jsx)(un,{className:`size-2`,strokeWidth:3})})]}):(0,W.jsx)(`span`,{className:G(`mt-0.5 shrink-0`,e.isCompleted?`text-primary`:`text-muted-foreground/50`),"aria-hidden":`true`,children:e.isCompleted?(0,W.jsx)(yn,{className:r?`size-3.5`:`size-4`}):(0,W.jsx)(Jn,{className:r?`size-3.5`:`size-4`})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`p`,{className:G(`font-semibold`,e.isCompleted?`text-foreground line-through decoration-primary/40`:`text-foreground`,r&&`text-xs`),children:e.label}),e.desc&&!r&&(0,W.jsx)(`p`,{className:`mt-0.5 text-xs text-muted-foreground`,children:e.desc}),(0,W.jsx)(`p`,{"data-testid":`challenge-hint-${e.id}`,className:G(`mt-1 text-xs`,e.isCompleted||e.result?.pass?`text-primary/80`:`text-muted-foreground`),children:s})]})]});return t?(0,W.jsx)(`button`,{type:`button`,onClick:t,disabled:i,...c,children:l}):(0,W.jsx)(`div`,{...c,children:l})}function y$(e){let t=e.replace(/^\s+/,``),n=t.match(/\n\s*\n/);return!n||n.index===void 0?{lead:t,rest:``}:{lead:t.slice(0,n.index),rest:t.slice(n.index).trimStart()}}var b$=({section:e,idx:t,prose:n,blockId:r,keySuffix:i,showHeading:a=!0,showEyebrow:o=!0,renderButtons:s=!0,isActive:c=!1,hasViewDef:l=!1,runState:u,deps:d,onExampleSelect:f,selectedExampleIndex:p,chapters:m=[],challengeQuests:h=[],isCollection:g=!1,notebookSlug:_=null,workoutItems:v=[],handleSelectWorkout:y,onScrollToSection:b,variant:x=`default`})=>{let S=!!e.isFullBleed,C=!!e.isDark&&x!==`caption`,w=e.density,T=_L[e.theme||`slate`]??_L.slate,E=e.examples??[],D=t===-1,O=U.useMemo(()=>{if(!m||!h)return null;for(let t of m){let n=t.sectionIds.indexOf(e.id);if(n>=0&&t.questIds[n]){let e=t.questIds[n],r=h.find(t=>t.id===e);if(r)return{quest:r,chapterTitle:t.title}}}return null},[m,h,e.id]);if(D){let t=e.proseChunks.filter(e=>e.kind===`button`).map(e=>e.button),n=e.proseChunks.findIndex(e=>e.kind===`prose`&&e.text.trim()!==``),a=n>=0?e.proseChunks[n]:null,{lead:o,rest:s}=a&&a.kind===`prose`?y$(a.text.trim()):{lead:``,rest:``},c=e.proseChunks.slice(n+1);return(0,W.jsxs)(`div`,{id:r,"data-section-id":i==="default"?e.id:void 0,className:`group relative flex min-h-[70vh] lg:min-h-[80vh] items-center justify-center overflow-hidden border-b-2 border-primary/10 bg-gradient-to-b from-primary/[0.08] via-muted/30 to-background px-6 py-16 lg:px-10 lg:py-24`,children:[(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 bg-[radial-gradient(ellipse_75%_60%_at_50%_0%,_var(--tw-gradient-stops))] from-primary/30 via-primary/5 to-transparent`}),(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 text-primary opacity-[0.15]`,style:{backgroundImage:`radial-gradient(circle, currentColor 1.5px, transparent 1.5px)`,backgroundSize:`24px 24px`,maskImage:`radial-gradient(ellipse 70% 60% at 50% 40%, black 40%, transparent 90%)`,WebkitMaskImage:`radial-gradient(ellipse 70% 60% at 50% 40%, black 40%, transparent 90%)`}}),(0,W.jsxs)(`div`,{className:`relative max-w-2xl w-full text-center`,children:[o&&(0,W.jsx)(t$,{prose:o,variant:`heroLead`,className:`mb-5`}),s&&(0,W.jsx)(t$,{prose:s,variant:`heroBody`,className:`mb-2`}),c.map((e,t)=>{if(e.kind===`prose`){let n=e.text.trim();return n?(0,W.jsx)(t$,{prose:n,className:`mt-6 mb-2`},`hero-prose-${t}`):null}if(e.kind===`challenge`){let n=h.find(t=>t.id===e.id);return n?(0,W.jsx)(`div`,{className:`my-4 flex justify-center`,children:(0,W.jsx)(v$,{quest:n,onClick:()=>b?.(r),compact:!0})},`hero-challenge-${t}`):null}return null}),t.length>0&&(0,W.jsx)(n$,{activations:t.map((e,t)=>nI(e,t)),fullBleed:!0,runState:l?u:void 0,deps:d})]})]})}let k=n===void 0?e.proseChunks??[]:[{kind:`prose`,text:n}],A=!k.some(e=>e.kind===`button`)&&(e.buttons??[]).length>0;return(0,W.jsxs)(`div`,{id:r,"data-section-id":i==="default"||i===`before-workouts`?e.id:void 0,className:G(`group relative border-b border-border/50 transition-colors duration-300`,x===`caption`?`py-6 pb-10`:l?S?`flex items-center justify-center min-h-[35vh] py-12 lg:py-16 px-6 lg:px-10`:w===`compact`?`py-10 lg:py-12 px-6 lg:px-10`:`py-14 lg:py-20 px-6 lg:px-10`:w===`compact`?`py-10 lg:py-12 px-6 lg:px-12`:`py-16 lg:py-20 px-6 lg:px-12`,!x||x==="default"?C&&`bg-muted/20 overflow-hidden`:void 0,x!==`caption`&&!C&&!S&&(t%2==0?`bg-background`:`bg-muted/[0.18]`)),children:[x!==`caption`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:G(`pointer-events-none absolute inset-y-0 left-0 w-px bg-gradient-to-b opacity-0 transition-opacity duration-300`,T.accent,c&&`opacity-100`)}),(0,W.jsx)(`div`,{className:G(`pointer-events-none absolute left-0 top-0 h-full w-1 origin-top rounded-r-full bg-gradient-to-b transition-all duration-300`,T.progress,c?`scale-y-100 opacity-100`:`scale-y-[0.18] opacity-25`)})]}),C&&(0,W.jsx)(`div`,{className:`pointer-events-none absolute inset-0 opacity-40 bg-[radial-gradient(circle_at_center,_var(--tw-gradient-stops))] from-primary/20 via-transparent to-transparent`}),(0,W.jsxs)(`div`,{className:G(`relative`,x===`caption`?`max-w-none`:l?S?`max-w-md w-full text-center`:`max-w-sm`:`max-w-4xl w-full mx-auto`),children:[o&&(!S||!l)&&O&&(0,W.jsx)(`div`,{className:`mb-4 flex items-center gap-2 select-none min-h-[14px]`,children:O.quest.isCompleted?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[9px] font-black uppercase tracking-wider text-emerald-600 dark:text-emerald-400 bg-emerald-500/10 px-2 py-0.5 rounded-full border border-emerald-500/20`,children:[(0,W.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-500 dark:bg-emerald-400 animate-pulse`}),`Challenge Complete`]}):(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[9px] font-black uppercase tracking-wider text-muted-foreground/80 bg-muted/60 px-2 py-0.5 rounded-full border border-border/50`,children:[(0,W.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-zinc-400 dark:bg-zinc-500`}),O.chapterTitle,`: Challenge Pending`]})}),a?(0,W.jsx)(`h2`,{className:G(`font-bold tracking-tight text-foreground leading-tight`,x===`caption`?`text-xl lg:text-2xl mb-4`:`text-2xl lg:text-3xl font-black uppercase mb-5`),children:e.heading}):null,k.map((e,t)=>{if(e.kind===`prose`){let n=e.text.trim();return n?(0,W.jsx)(t$,{prose:n,className:t===0?`mb-6`:`mt-4 mb-6`},`prose-${t}`):null}if(e.kind===`button`)return(0,W.jsx)(n$,{activations:[nI(e.button,t)],fullBleed:S,runState:l?u:void 0,deps:d},`button-${t}`);if(e.kind===`widget`){if(e.widget===`hero-carousel`)return(0,W.jsx)(`div`,{className:`my-6`,children:(0,W.jsx)(OQ,{})},`hero-carousel-${t}`);if(e.widget===`workouts-list`&&g&&_&&y)return(0,W.jsx)(`div`,{id:`notebook-workouts`,className:`border-b border-border/50 bg-card my-6`,children:(0,W.jsx)(`div`,{className:`w-full mx-auto`,children:(0,W.jsx)(IQ,{category:_,workoutItems:v,onSelect:y,showSearch:!1,variant:`flat`})})},`workouts-${t}`)}if(e.kind===`challenge`){let n=h.find(t=>t.id===e.id);return n?(0,W.jsx)(`div`,{className:`my-4`,children:(0,W.jsx)(v$,{quest:n,onClick:()=>b?.(r),compact:!0})},`challenge-${t}`):null}return null}),E.length>0?(0,W.jsx)(r$,{examples:E,activeIndex:Math.min(p,E.length-1),onSelect:t=>f(e,t)}):null,s&&A?(0,W.jsx)(n$,{activations:e.buttons.map((e,t)=>nI(e,t)),fullBleed:S,runState:l?u:void 0,deps:d}):null]})]},`${e.id}-${i}`)};function x$({sections:e,activeIndex:t,part:n,args:r}){return(0,W.jsx)(`div`,{className:`h-full min-h-0 pr-1`,"data-testid":`guide-captions-${n}`,children:e.map((e,n)=>{let i=n===t;return(0,W.jsx)(`div`,{className:`absolute inset-0 min-h-0 overflow-y-auto transition-opacity duration-300 ${i?`opacity-100`:`pointer-events-none invisible opacity-0`}`,"aria-hidden":!i,children:(0,W.jsx)(b$,{section:e,idx:n,blockId:`guide-caption-${e.id}`,keySuffix:`caption`,variant:`caption`,isActive:i,hasViewDef:r.hasViewDef??!0,runState:r.runState,deps:r.deps,onExampleSelect:r.onExampleSelect,selectedExampleIndex:r.selectedExamples[e.id]??0,chapters:r.chapters,challengeQuests:r.challengeQuests,onScrollToSection:r.onScrollToSection})},e.id)})})}function S$({sections:e,part:t,partCount:n,title:r,pane:i,cardArgs:a,onActivateSection:o}){let s=(0,U.useRef)(null),c=(0,U.useMemo)(()=>EQ(e),[e]),{slice:l,subscribe:u}=SQ(s,!1,c),d=(0,U.useRef)(e);d.current=e;let[f,p]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=s.current;if(!e||typeof IntersectionObserver>`u`){p(!0);return}let t=new IntersectionObserver(([e])=>{e.isIntersecting&&(p(!0),t.disconnect())},{rootMargin:`100px`});return t.observe(e),()=>t.disconnect()},[]);let m=()=>{let e=s.current;if(!e)return!1;let{top:t,bottom:n}=e.getBoundingClientRect();return t<=0&&n>window.innerHeight},[h,g]=(0,U.useState)(!1);(0,U.useEffect)(()=>u(()=>{let e=m();g(t=>t===e?t:e)}),[u]);let _=(0,U.useRef)(!1),v=(0,U.useRef)(-1),y=(0,U.useRef)(o);y.current=o,(0,U.useEffect)(()=>{let e=_.current,t=v.current;if(_.current=h,v.current=l.index,!h||e&&t===l.index)return;let n=d.current[l.index];n&&y.current(n)},[h,l.index]);let b=e[l.index]??null;return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`header`,{"data-testid":`guide-runway-header-${t}`,className:`mx-auto w-full max-w-[1500px] px-6 pt-12 pb-6 lg:px-12`,children:[(0,W.jsxs)(`div`,{className:`font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground`,children:[`Part `,t,` / `,n]}),(0,W.jsx)(`h2`,{className:`mt-1 text-xl font-black uppercase tracking-tight text-foreground`,children:r})]}),(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsx)(yQ,{trackRef:s,height:`${(e.length+1)*100}vh`,stages:c,activeIndex:l.index,pane:f?i:null,captions:(0,W.jsx)(x$,{sections:e,activeIndex:l.index,part:t,args:a}),status:(0,W.jsxs)(`div`,{className:`truncate font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground`,children:[String(l.index+1).padStart(2,`0`),b?` — ${b.heading}`:``]}),testId:`guide-runway-${t}`}),e.map((t,n)=>(0,W.jsx)(`span`,{id:t.id,"data-section-id":t.id,"aria-hidden":`true`,className:`pointer-events-none absolute left-0 h-px w-px`,style:{top:`calc((100% - 100vh) * ${n/e.length} + 50vh + 120px)`}},t.id))]})]})}function C$({sections:e,groupKey:t,title:n,pane:r,cardArgs:i,onActivateSection:a}){let{groups:o,tail:s}=TQ(e,t);return(0,W.jsxs)(W.Fragment,{children:[o.map((e,t)=>(0,W.jsx)(S$,{sections:e,part:t+1,partCount:o.length,title:n,pane:r,cardArgs:i,onActivateSection:a},e[0]?.id??t)),s.length>0&&(0,W.jsx)(`div`,{className:`mx-auto w-full max-w-[1500px] px-6 lg:px-12`,"data-testid":`guide-static-tail`,children:(0,W.jsx)(`div`,{className:`lg:max-w-[50%]`,children:s.map((e,t)=>(0,W.jsx)(b$,{section:e,idx:t,blockId:e.id,keySuffix:`default`,isActive:i.activeSectionId===e.id,hasViewDef:i.hasViewDef??!0,runState:i.runState,deps:i.deps,onExampleSelect:i.onExampleSelect,selectedExampleIndex:i.selectedExamples[e.id]??0,chapters:i.chapters,challengeQuests:i.challengeQuests,onScrollToSection:i.onScrollToSection},`tail-${e.id}`))})})]})}function w$({videoId:e,title:t=`YouTube video`,onClose:n}){return(0,U.useEffect)(()=>{let e=e=>{e.key===`Escape`&&n()};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),(0,TC.createPortal)((0,W.jsxs)(`div`,{className:`fixed inset-0 z-[100] flex items-center justify-center bg-black/90 p-4 animate-in fade-in duration-200`,"data-testid":`youtube-lightbox`,onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,W.jsx)(`button`,{type:`button`,onClick:n,title:`Close video`,"data-testid":`youtube-lightbox-close`,className:`absolute right-4 top-4 z-[110] flex size-11 items-center justify-center rounded-full border border-border bg-background/80 text-foreground transition-colors hover:bg-accent`,children:(0,W.jsx)(we,{className:`size-5`})}),(0,W.jsx)(`div`,{className:`aspect-video w-full max-w-5xl overflow-hidden rounded-lg border border-border bg-black shadow-2xl`,children:(0,W.jsx)(`iframe`,{className:`h-full w-full border-0`,src:`https://www.youtube-nocookie.com/embed/${encodeURIComponent(e)}?autoplay=1&rel=0`,title:t,allow:`accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture`,allowFullScreen:!0})})]}),document.body)}function T$({index:e,before:t,accentText:n,after:r,accent:i,blurb:a}){return(0,W.jsx)(`header`,{className:`flex items-center px-6 py-14 lg:px-12 xl:py-20 2xl:py-24 xl:px-16`,children:(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-[1500px] 2xl:max-w-[1720px]`,children:[(0,W.jsxs)(`h2`,{className:`flex items-baseline gap-4 xl:gap-6 text-[clamp(26px,3.6vw,52px)] font-extrabold leading-[1.1] tracking-[-0.03em]`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs font-normal tracking-normal text-muted-foreground`,children:e}),(0,W.jsxs)(`span`,{children:[t,n,r]})]}),(0,W.jsx)(`p`,{className:`mt-3 xl:mt-4 max-w-xl xl:max-w-2xl 2xl:max-w-3xl text-[clamp(14px,1.2vw,18px)] leading-[1.65] text-muted-foreground`,children:a})]})})}var E$=`hsl(var(--primary))`,D$={ink:`hsl(var(--foreground))`,editor:E$,timer:E$,analytics:E$,library:E$,rounds:E$},O$={editor:`WOD Editor & Autocomplete`,timer:`Clock`,analytics:`WQL Analytics`,metrics:`Own the Metrics`,result:`Run Results`},k$={start:`/page/guide-start`,protocols:`/page/guide-protocols`,structure:`/page/guide-structure`,metrics:`/page/guide-metrics`,clock:`/page/guide-clock`,wql:`/page/guide-wql`,dashboards:`/page/guide-dashboards`,sessions:`/page/guide-sessions`,basics:`/page/guide-start`,"custom-metrics":`/page/guide-metrics`,dialects:`/page/guide-sessions#intent`,complex:`/page/guide-sessions#full-session`},A$=`dQw4w9WgXcQ`,j$=`https://i.ytimg.com/vi/${A$}/hqdefault.jpg`;function M$({variant:e=`index`}){let t=qL(),{pathname:n}=Sn(),[r,i]=(0,U.useState)(null),a=(0,U.useMemo)(()=>lL(t).flatMap(e=>e.action?.type===`route`?[{id:e.id,label:e.label,to:e.action.to}]:[]),[t]),o=(0,U.useMemo)(()=>{let e=new Map;for(let n of t){if(n.route.startsWith(`/notebook`)||n.page.frontmatter?.type!==`guide`)continue;let t=n.page.frontmatter?.description;t&&e.set(`guide-${n.route}`,String(t))}return e},[t]);if(a.length===0)return null;let s=a.findIndex(e=>e.to===n),c=s>=0,l=c&&a.length>1?(s+1)%a.length:-1,u=r&&(0,W.jsx)(w$,{videoId:A$,title:r.label,onClose:()=>i(null)});return e===`university`?(0,W.jsxs)(`section`,{id:`tour-section-university`,"data-testid":`tour-section-university`,"aria-label":`Wod Wiki University`,children:[(0,W.jsx)(T$,{index:`05`,before:`Wod Wiki `,accentText:`University`,after:``,accent:D$.library,blurb:`Eight short chapters take you from your first workout to querying your training history. Each guide pairs a video walkthrough with a runnable example.`}),(0,W.jsx)(`nav`,{"aria-label":`Wod Wiki University`,className:`px-6 pb-16 lg:px-12 xl:px-16`,children:(0,W.jsx)(`ul`,{className:`mx-auto flex w-full max-w-5xl flex-col gap-5`,children:a.map((e,t)=>(0,W.jsxs)(`li`,{className:G(`flex flex-col gap-5 rounded-lg border border-border p-5 md:flex-row md:items-center md:gap-8 md:p-6`,t%2==1&&`md:flex-row-reverse`),children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i({id:e.id,label:e.label}),title:`Watch: ${e.label}`,"aria-label":`Watch: ${e.label}`,"data-testid":`guide-watch`,className:`group relative block w-full flex-none overflow-hidden rounded-md border border-border md:w-56`,children:[(0,W.jsx)(`img`,{src:j$,alt:``,loading:`lazy`,className:`aspect-video w-full object-cover transition-transform duration-300 group-hover:scale-105`}),(0,W.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/25 transition-colors group-hover:bg-black/40`,children:(0,W.jsx)(pn,{className:`size-9 fill-white text-white`})})]}),(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1.5`,children:[(0,W.jsx)(_n,{to:e.to,className:`font-semibold hover:underline`,children:e.label}),(0,W.jsx)(`p`,{className:`text-sm leading-relaxed text-muted-foreground`,children:o.get(e.id)??e.to})]})]},e.id))})}),u]}):(0,W.jsxs)(`nav`,{"aria-label":c?`What’s Next`:`Syntax & Guides`,"data-testid":`guide-index-footer`,className:`border-t border-border px-6 py-12 xl:py-16`,children:[(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col rounded-lg border border-border overflow-hidden`,children:[(0,W.jsxs)(`h2`,{className:`px-4 py-2 text-xs font-black uppercase tracking-wider text-muted-foreground bg-muted/40`,children:[c?`What’s Next`:`Syntax & Guides`,` · `,a.length]}),(0,W.jsx)(`ul`,{className:`flex flex-col divide-y divide-border`,children:a.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-stretch`,children:[(0,W.jsxs)(_n,{to:e.to,"aria-current":t===s?`page`:void 0,className:G(`flex min-w-0 flex-1 flex-col gap-0.5 px-4 py-3 hover:bg-muted/50`,t===s&&`bg-muted/50`),children:[(0,W.jsxs)(`span`,{className:`flex w-full items-baseline justify-between gap-3`,children:[(0,W.jsx)(`span`,{className:`font-medium`,children:e.label}),t===l&&(0,W.jsx)(`span`,{className:`text-xs font-semibold text-primary`,"data-testid":`guide-next-marker`,children:`Next →`})]}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:e.to})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i({id:e.id,label:e.label}),title:`Watch: ${e.label}`,"aria-label":`Watch: ${e.label}`,"data-testid":`guide-watch`,className:`flex flex-none items-center gap-1.5 border-l border-border px-4 text-xs font-semibold text-muted-foreground transition-colors hover:bg-muted/50 hover:text-foreground`,children:[(0,W.jsx)(pn,{className:`size-3.5`}),`Watch`]})]},e.id))})]}),u]})}var N$=`22rem`,P$=`42rem`,F$=`20rem`,I$=`calc(100dvh - var(--canvas-sticky-top) - 2rem)`;function L$(e){return{editorWidth:e||`50%`,editorMinWidth:N$,editorMaxWidth:P$,editorMinHeight:F$,editorMaxHeight:I$}}function R$(e){let t=Math.max(1,e.split(`
163
- `).length);return`calc(${Math.min(560,Math.max(180,t*22))}px + 3.5rem)`}function z$(e,t){return{"--canvas-editor-width":e.editorWidth,"--canvas-editor-min-width":e.editorMinWidth,"--canvas-editor-max-width":e.editorMaxWidth,"--canvas-editor-min-height":e.editorMinHeight,"--canvas-editor-max-height":e.editorMaxHeight,"--canvas-editor-preferred-height":R$(t)}}var B$=(e,t,n)=>(0,W.jsx)(b$,{section:e,idx:t,blockId:e.id,keySuffix:`default`,isActive:n.activeSectionId===e.id,hasViewDef:n.hasViewDef,runState:n.runState,deps:n.deps,onExampleSelect:n.handleExampleSelect,selectedExampleIndex:n.selectedExamples[e.id]??0,chapters:n.chapters,challengeQuests:n.challengeQuests,isCollection:n.isCollection,notebookSlug:n.notebookSlug,workoutItems:n.workoutItems,handleSelectWorkout:n.handleSelectWorkout,onScrollToSection:n.onScrollToSection},`${e.id}-default`),V$=({heroSlot:e,mobilePanel:t,desktopPanel:n,stickyAlign:r=`right`,editorWidth:i=`50%`,contentSections:a,isCollection:o,notebookSlug:s,workoutItems:c,handleSelectWorkout:l,activeSectionId:u,selectedExamples:d,runState:f,deps:p,handleExampleSelect:m,hasWorkoutsTag:h,hasViewDef:g,chapters:_=[],challengeQuests:v=[],onScrollToSection:y,editorAppearsAtSectionId:b})=>{let x=b?a.findIndex(e=>e.id===b):-1,S=x>0&&!!n,C={activeSectionId:u,selectedExamples:d,handleExampleSelect:m,hasViewDef:g,runState:f,deps:p,chapters:_,challengeQuests:v,isCollection:o,notebookSlug:s,workoutItems:c,handleSelectWorkout:l,onScrollToSection:y},w=S?{width:`calc(100% - ${i})`,flexBasis:`calc(100% - ${i})`,maxWidth:`calc(100% - ${i})`}:{},T=o&&s&&c?(0,W.jsx)(`div`,{id:`notebook-workouts`,className:`border-b border-border/50 bg-card`,children:(0,W.jsx)(`div`,{className:`w-full mx-auto`,children:(0,W.jsx)(IQ,{category:s??``,workoutItems:c??[],onSelect:l,showSearch:!1,variant:`flat`})})}):null;if(S){let i=a.slice(0,x),o=a.slice(x);return(0,W.jsxs)(W.Fragment,{children:[e,i.map((e,t)=>B$(e,t,C)),(0,W.jsxs)(`div`,{className:`lg:flex`,children:[r===`left`&&n,(0,W.jsxs)(`div`,{className:`w-full min-w-0`,style:w,children:[t,o.map((e,t)=>B$(e,t,C)),T]}),r===`right`&&n]})]})}return(0,W.jsxs)(W.Fragment,{children:[t,(0,W.jsxs)(`div`,{className:`lg:flex`,children:[r===`left`&&n,(0,W.jsxs)(`div`,{className:`w-full min-w-0`,style:w,children:[e,a.map((e,t)=>B$(e,t,C)),T]}),r===`right`&&n]})]})},H$=({activations:e,runState:t,deps:n})=>{if(e.length===0)return null;let r=e[0];if(rI(r)&&t){let i=e.slice(1),a=t.isReconnect?(0,W.jsxs)(`button`,{onClick:t.onReconnect,className:`flex items-center gap-2 px-5 py-2 text-[11px] font-black uppercase tracking-widest rounded-full border transition-all active:scale-95 border-amber-500/40 bg-amber-500/15 text-amber-600 hover:bg-amber-500/20 dark:text-amber-400`,children:[(0,W.jsx)(Ye,{className:`size-3.5`}),`View`]}):(0,W.jsxs)(`button`,{type:`button`,onClick:t.onRun,className:`flex items-center gap-2 transition-all active:scale-95 bg-primary text-primary-foreground hover:bg-primary/90 font-black uppercase tracking-widest rounded-full shadow-lg shadow-primary/25 min-h-[44px] px-6 py-2 text-xs`,children:[(()=>{let e=r.icon||pn;return(0,W.jsx)(e,{className:`shrink-0 size-4 fill-current sm:size-3`})})(),(0,W.jsx)(`span`,{children:r.label})]});return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 justify-end pt-3 px-1`,children:[a,i.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,n),className:`px-5 py-2 text-[11px] font-black uppercase tracking-widest rounded-full bg-muted border border-border text-foreground hover:bg-muted/80 transition-all active:scale-95`,children:e.label},e.id||t))]})}return(0,W.jsx)(`div`,{className:`flex flex-wrap gap-3 justify-end pt-3 px-1`,children:e.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,n),className:`px-5 py-2 text-[11px] font-black uppercase tracking-widest rounded-full transition-all active:scale-95 bg-primary text-primary-foreground shadow-lg shadow-primary/25 hover:scale-[1.04]`,children:e.label},e.id||t))})},U$=({variant:e,panelTitle:t,panelSubtitle:n,panelContent:r,panelThemeClass:i,headerActions:a,showPanelButtons:o=!1,viewDefButtons:s,runState:c,deps:l,width:u,source:d=``})=>{let f=r,p=o&&s&&s.length>0?(0,W.jsx)(H$,{activations:s.map((e,t)=>nI(e,t)),runState:c,deps:l}):null;return e===`desktop`?(0,W.jsxs)(`div`,{className:`self-start sticky hidden lg:flex flex-col p-6 pt-8 pb-8 gap-3`,style:{top:`104px`,height:`calc(100vh - 104px)`,width:`clamp(var(--canvas-editor-min-width), var(--canvas-editor-width), var(--canvas-editor-max-width))`,...z$(L$(u),d)},children:[(0,W.jsx)(`div`,{className:`flex-1 min-h-0 flex flex-col justify-center py-4`,children:(0,W.jsx)(`div`,{className:`h-[min(var(--canvas-editor-preferred-height),var(--canvas-editor-max-height))] min-h-[var(--canvas-editor-min-height)] max-h-[var(--canvas-editor-max-height)] flex flex-col w-full`,children:f})}),p]}):(0,W.jsx)(`div`,{className:`lg:hidden sticky z-20 shrink-0 px-4 pt-2 pb-1`,"data-page-sticky-boundary":`true`,style:{top:`65px`,height:`min(var(--canvas-editor-preferred-height), calc(100dvh - 65px - 1rem))`,minHeight:`18rem`,"--canvas-editor-preferred-height":R$(d)},children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 h-full`,children:[(0,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:f}),p]})})},W$=({heroSlot:e,children:t})=>(0,W.jsxs)(`section`,{className:`relative border-b border-border/50`,children:[e,t]}),G$=new Set([q.Duration,q.Time]);function K$(e){return e.metrics.some(e=>e.type===q.Hint&&e.value===`domain.wod`)}function q$(e){return e?e.filter(e=>!K$(e)&&e.metrics.some(e=>e.type===q.Effort)).length:0}function J$(e){if(!e)return 0;let t=0;for(let n of e)if(!K$(n))for(let e of n.metrics)e.type===q.Rounds&&typeof e.value==`number`&&(t+=e.value);return t}function Y$(e){return e?e.some(e=>!K$(e)&&e.metrics.some(e=>G$.has(e.type))):!1}function X$(e){return e?e.some(e=>!K$(e)&&e.metrics.some(e=>e.type===q.Rep)):!1}function Z$(e,t){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);if(Number.isFinite(t))return t}return null}function Q$(e,t){return typeof e==`string`&&e.length>0?e:typeof e==`number`?String(e):null}var $$={"has-movement":e=>{let t=q$(e.statements);return t>0?{pass:!0,detail:`${t} movement${t===1?``:`s`}`}:{pass:!1,reason:"Add at least one movement line (e.g. `10 KB Swings`)."}},"exactly-movements":(e,t)=>{let n=Z$(t.count??t.value,`count`);if(n===null)return{pass:!1,reason:"exactly-movements: missing `count`."};let r=q$(e.statements);return r===n?{pass:!0,detail:String(r)}:{pass:!1,reason:`Expected exactly ${n} movement${n===1?``:`s`}, found ${r}.`}},"has-reps":e=>X$(e.statements)?{pass:!0}:{pass:!1,reason:"Add a rep count (e.g. `10` reps on a movement line)."},"has-timer":e=>Y$(e.statements)?{pass:!0}:{pass:!1,reason:"Add a timer (e.g. `*:30 Rest` or `5:00 cap`)."},"min-rounds":(e,t)=>{let n=Z$(t.count??t.min,`count`);if(n===null)return{pass:!1,reason:"min-rounds: missing `count`."};let r=J$(e.statements);return r>=n?{pass:!0,detail:`${r} round${r===1?``:`s`}`}:{pass:!1,reason:`Need at least ${n} round${n===1?``:`s`} — found ${r}.`}},"contains-token":(e,t)=>{let n=Q$(t.value??t.token,`value`);return n===null?{pass:!1,reason:"contains-token: missing `value`."}:(e.content??``).includes(n)?{pass:!0,detail:`"${n}"`}:{pass:!1,reason:`Script must include the token "${n}".`}}};function e1(e,t){if(!t||typeof t.type!=`string`||t.type.length===0)return{pass:!1,reason:`Quest has no validation schema.`};let n=$$[t.type];return n?n(e,t):{pass:!1,reason:`Unknown validation type "${t.type}".`}}function t1({pageRoute:e,quests:t,block:n,enabled:r=!0}){let{markComplete:i,quests:a,isComplete:o}=Nq(e,t),[s,c]=(0,U.useState)(new Set),l=(0,U.useMemo)(()=>{let e={};if(!r||!n){for(let n of t)e[n.id]={pass:!1,reason:`No active block.`};return e}let i={content:n.content,statements:n.statements??[]};for(let n of t){if(!n.validation){e[n.id]={pass:!1};continue}if(n.validation?.type===`workout-complete`){e[n.id]={pass:!1,reason:`Finish the workout to check this off.`};continue}e[n.id]=e1(i,n.validation)}return e},[n,t,r]);(0,U.useEffect)(()=>{if(r)for(let e of a)e.isCompleted||s.has(e.id)||l[e.id]?.pass&&(i(e.id),c(t=>{if(t.has(e.id))return t;let n=new Set(t);return n.add(e.id),n}))},[r,a,l,s,i]);let u=(0,U.useMemo)(()=>t.map(e=>e.id).join(`|`),[t]);return(0,U.useEffect)(()=>{c(new Set)},[e,u]),{quests:a.map(e=>{let t=l[e.id]??{pass:!1,reason:`No validator result.`},n=e.isCompleted?{...t,pass:!0,detail:`Completed`}:t;return{...e,result:n}}),isComplete:o,results:l}}function n1({page:e,wodFiles:t,theme:n,workoutItems:r,onSelect:i,contentOverride:a,panelHeaderActions:o,onPanelActionsReady:s,heroSlot:c,onScrollToSection:l}){let u=Vn(),d=Sn(),{sections:f,route:p,chapters:m}=e,h=d.pathname.startsWith(`/page/`)||p.startsWith(`/page/`),g=(0,U.useMemo)(()=>xV(p),[p]),_=e.type===`guide`||p.startsWith(`/page/guide-`);hq(_?p:void 0);let v=p.startsWith(`/notebook/`),y=Iq(`(prefers-reduced-motion: reduce)`),b=_&&!v&&!y,x=v?p.split(`/`).pop()??null:null,S=(0,U.useCallback)(e=>{if(i){i(e);return}u(DN(e.category,e.name))},[u,i]),C=f.some(e=>e.proseChunks.some(e=>e.kind===`widget`&&e.widget===`workouts-list`)),w=f.slice(1),T=f[0]??null,E=!!T&&(T.proseChunks.some(e=>e.kind===`prose`&&e.text.trim()!==``)||T.buttons.length>0),D=f.find(e=>e.view)?.view??null,O=D?.align??`right`,k=D?.width??`50%`,A=w[0]??f[0]??null,j=p===`/`?`learn`:void 0,M=D?.source?SV(D.source,t):``,N=D?.source||`__initial__`,[P,F]=(0,U.useState)(A?.id??null),[I,L]=(0,U.useState)(A?.heading??`Whiteboard Script`),[ee,te]=(0,U.useState)(A?.heading??`Whiteboard Script`),ne=(0,U.useMemo)(()=>wV(w),[w]),R=b&&p.split(`/`).pop()||void 0,re=(0,U.useMemo)(()=>b?TQ(w,R):null,[b,R,w]),{guideOwnerBySection:ie,guideOwnerSource:ae}=(0,U.useMemo)(()=>{if(!b)return{guideOwnerBySection:null,guideOwnerSource:null};let e=new Map,t=new Map,n=null;for(let r of w){let i=r.proseChunks.find(e=>e.kind===`button`&&e.button.pipeline.some(e=>e.action===`set-source`))?.button.pipeline.find(e=>e.action===`set-source`)?.value??r.buttons.find(e=>e.pipeline.some(e=>e.action===`set-source`))?.pipeline.find(e=>e.action===`set-source`)?.value??null;i&&(n=r,t.set(r.id,i)),e.set(r.id,n)}return{guideOwnerBySection:e,guideOwnerSource:t}},[b,w]),[oe,se]=(0,U.useState)(()=>(A??f[0])?.theme??`slate`),[ce,le]=(0,U.useState)({}),{editorSource:z,editorOpacity:ue,isEditorLoading:de,activeOriginalSource:fe,swapSource:B,handleEditorChange:pe,resetActiveSource:me,setEditorView:he,getSource:ge}=Tq({initialSource:M,initialSourceKey:N,contentOverride:a}),_e=(0,U.useRef)(t);_e.current=t;let ve=(0,U.useCallback)(()=>Me.current[0]??null,[]),{startRun:ye,closeRun:be,handleWorkoutComplete:xe,resetRun:Se,resetRequested:Ce,fullscreen:we,runState:Te,completedResults:Ee}=wq({getBlock:ve,getContent:ge,title:e.frontmatter.title}),De=(0,U.useCallback)(async()=>await Se(M)?(me(),!0):!1,[Se,M,me]),[Oe,ke]=(0,U.useState)(null),Ae=e.quests??[],je=t1({pageRoute:e.route,quests:Ae,block:Oe});Pq({pageRoute:e.route,quests:Ae,completedResults:Ee}),Fq({pageRoute:e.route,quests:Ae,initialSource:M,currentSource:z});let Me=(0,U.useRef)([]),Ne=(0,U.useRef)(ne.get(A?.id??``)?.id??null),Pe=(0,U.useCallback)(e=>{F(e.id),L(e.heading),se(e.theme??`slate`);let t=(ie??ne).get(e.id)??null;te(t?.heading??A?.heading??`Whiteboard Script`);let n=t?.id??null;if(n===Ne.current)return;if(Ne.current=n,!t){B(M,N);return}let r=t.examples??[];if(r.length>0){let e=r[ce[t.id]??0]??r[0];e?.source&&B(SV(e.source,_e.current),e.source)}for(let e of t.commands){let t=e.pipeline.filter(e=>!(r.length>0&&e.action===`set-source`)).map(t=>tI(t,e.open??`view`));t.length!==0&&eI(t.length===1?t[0]:{type:`pipeline`,steps:t},Be.current)}let i=ie?ae?.get(t.id):void 0;i&&B(SV(i,_e.current),i)},[ce,B,ne,ie,ae,A,M,N]),Fe=(0,U.useCallback)((e,t)=>{le(n=>({...n,[e.id]:t})),F(e.id),L(e.heading),se(e.theme??`slate`),te(e.heading),Ne.current=e.id;let n=e.examples?.[t];n?.source&&B(SV(n.source,_e.current),n.source)},[B]),[Ie,Le]=Kt(`h`,{history:`replace`,shallow:!0}),[Re]=Kt(`q`,{defaultValue:``,shallow:!0}),ze=(0,U.useMemo)(()=>({navigate:(e,t)=>u(e,{replace:t?.replace}),setQueryParam:(e,t)=>{let n=e.h;n!==void 0&&Le(n,{history:t?`replace`:`push`})},swapSource:e=>B(SV(e,_e.current),e),setPanelState:e=>{if(e===`track`){let e=ve();e&&ye(e)}}}),[u,B,Le,ve,ye]),Be=(0,U.useRef)(ze);Be.current=ze;let Ve=(0,U.useCallback)(e=>{Le(e.id,{history:`replace`}),Pe(e)},[Pe,Le]),He=zB(104),Ue=(0,U.useMemo)(()=>`-${He}px 0px -30% 0px`,[He]),We=re?re.tail.map(e=>e.id):w.map(e=>e.id),Ge=(0,U.useRef)(!1);PB({ids:We,enabled:We.length>0,rootMargin:Ue,threshold:[0,.1,.25,.5,.75],dataAttribute:`data-section-id`,scrollDirection:`topmost-when-up`,debounceMs:50,shouldAcceptChange:()=>Ge.current?!0:(Ge.current=window.scrollY>0,Ge.current),onChange:e=>{let t=w.find(t=>t.id===e);t&&(Le(e,{history:`replace`}),Pe(t))}});let Ke=(0,U.useRef)(!1);(0,U.useEffect)(()=>{Ke.current||!Ie||w.length===0||(Ke.current=!0,requestAnimationFrame(()=>{let e=document.querySelector(`[data-section-id="${Ie}"]`);if(!e)return;let t=He+8,n=e.getBoundingClientRect().top+window.scrollY-t;window.scrollTo({top:Math.max(0,n),behavior:`smooth`})}))},[w,Ie,He]);let qe=(0,U.useRef)(Re);(0,U.useEffect)(()=>{if(!v){qe.current=Re;return}let e=Re.trim(),t=qe.current.trim();if(e&&e!==t){let e=document.getElementById(`notebook-workouts`);if(e){let t=e.getBoundingClientRect().top+window.scrollY-He-8;window.scrollTo({top:Math.max(0,t),behavior:`smooth`})}}qe.current=Re},[Re,v,He]);let Je=(0,U.useRef)(s);Je.current=s,(0,U.useEffect)(()=>{Je.current?.({run:()=>{let e=Me.current[0]??null;e&&ye(e)},reset:()=>{Se()},results:()=>{},fullscreen:()=>{let e=Me.current[0]??null;e&&ye(e)},getSource:ge})},[ye,Se,ge]);let Ye=(0,U.useMemo)(()=>[{id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:e=>{ye(e)}}],[ye]),Xe=_L[oe]??_L.slate,Ze=de?`${I} · loading`:I,Qe=!de&&I!==ee?ee:void 0,$e=(0,U.useCallback)(e=>{let t=e[0]??null;Me.current=e,ke(e=>e?.content===t?.content&&e?.id===t?.id?e:t)},[]),et=c??(E&&T?(0,W.jsx)(b$,{section:T,idx:-1,prose:void 0,blockId:T.id,keySuffix:`hero`,showEyebrow:!1,isActive:!1,hasViewDef:!!D,deps:ze,onExampleSelect:Fe,selectedExampleIndex:0,onScrollToSection:l,challengeQuests:je.quests}):null),tt=o,nt=(0,W.jsx)(rQ,{editorSource:z,editorOpacity:ue,activeOriginalSource:fe,handleEditorChange:pe,onResetToSource:De,canvasNoteId:g,readonly:h,showFrontmatter:typeof e.frontmatter.showFrontmatter==`boolean`?e.frontmatter.showFrontmatter:!_&&p!==`/`&&!p.startsWith(`/syntax`),theme:n,commands:Ye,onBlocksChange:$e,onViewCreated:he,panelTitle:Ze,panelSubtitle:Qe,panelThemeClass:Xe.panel,headerActions:tt,onRun:(e,t)=>{t&&ye(t,e)}}),rt=D&&(0,W.jsx)(U$,{variant:`desktop`,panelContent:nt,panelTitle:Ze,panelSubtitle:Qe,viewDefButtons:D.buttons,runState:Te,deps:ze,width:k,source:z}),it=D&&(0,W.jsx)(U$,{variant:`mobile`,panelContent:nt,panelTitle:Ze,panelSubtitle:Qe,viewDefButtons:D.buttons,runState:Te,deps:ze,width:k,source:z});return(0,W.jsxs)(`div`,{className:`flex flex-col min-h-screen bg-background`,children:[we?.kind===`timer`&&(0,W.jsx)(`div`,{className:`sticky z-30 border-b border-border bg-background`,style:{top:He},children:(0,W.jsx)(`div`,{className:`mx-auto h-[max(320px,min(75vh,640px))] max-w-5xl px-4 py-2`,children:(0,W.jsx)(rq,{block:we.block,onClose:be,autoStart:!0,externalStop:Ce,onComplete:(e,t)=>{xe(t)}})})}),(0,W.jsx)(W$,{heroSlot:et,children:b?(0,W.jsx)(C$,{sections:w,groupKey:R,title:String(e.frontmatter.title??``),pane:(0,W.jsx)(`div`,{className:`absolute inset-0`,style:{"--canvas-editor-preferred-height":R$(z)},children:nt}),cardArgs:{activeSectionId:P,selectedExamples:ce,onExampleSelect:Fe,runState:Te,deps:ze,hasViewDef:!!D,chapters:m,challengeQuests:je.quests,onScrollToSection:l},onActivateSection:Ve}):(0,W.jsx)(V$,{contentSections:w,isCollection:v,notebookSlug:x,workoutItems:r,handleSelectWorkout:S,activeSectionId:P,selectedExamples:ce,runState:Te,deps:ze,handleExampleSelect:Fe,hasWorkoutsTag:C,hasViewDef:!!D,chapters:m,challengeQuests:je.quests,onScrollToSection:l,mobilePanel:it,desktopPanel:rt,stickyAlign:O,editorWidth:k,editorAppearsAtSectionId:j})}),_&&(0,W.jsx)(M$,{})]})}var r1=`---
163
+ `).length);return`calc(${Math.min(560,Math.max(180,t*22))}px + 3.5rem)`}function z$(e,t){return{"--canvas-editor-width":e.editorWidth,"--canvas-editor-min-width":e.editorMinWidth,"--canvas-editor-max-width":e.editorMaxWidth,"--canvas-editor-min-height":e.editorMinHeight,"--canvas-editor-max-height":e.editorMaxHeight,"--canvas-editor-preferred-height":R$(t)}}var B$=(e,t,n)=>(0,W.jsx)(b$,{section:e,idx:t,blockId:e.id,keySuffix:`default`,isActive:n.activeSectionId===e.id,hasViewDef:n.hasViewDef,runState:n.runState,deps:n.deps,onExampleSelect:n.handleExampleSelect,selectedExampleIndex:n.selectedExamples[e.id]??0,chapters:n.chapters,challengeQuests:n.challengeQuests,isCollection:n.isCollection,notebookSlug:n.notebookSlug,workoutItems:n.workoutItems,handleSelectWorkout:n.handleSelectWorkout,onScrollToSection:n.onScrollToSection},`${e.id}-default`),V$=({heroSlot:e,mobilePanel:t,desktopPanel:n,stickyAlign:r=`right`,editorWidth:i=`50%`,contentSections:a,isCollection:o,notebookSlug:s,workoutItems:c,handleSelectWorkout:l,activeSectionId:u,selectedExamples:d,runState:f,deps:p,handleExampleSelect:m,hasWorkoutsTag:h,hasViewDef:g,chapters:_=[],challengeQuests:v=[],onScrollToSection:y,editorAppearsAtSectionId:b})=>{let x=b?a.findIndex(e=>e.id===b):-1,S=x>0&&!!n,C={activeSectionId:u,selectedExamples:d,handleExampleSelect:m,hasViewDef:g,runState:f,deps:p,chapters:_,challengeQuests:v,isCollection:o,notebookSlug:s,workoutItems:c,handleSelectWorkout:l,onScrollToSection:y},w=S?{width:`calc(100% - ${i})`,flexBasis:`calc(100% - ${i})`,maxWidth:`calc(100% - ${i})`}:{},T=o&&s&&c?(0,W.jsx)(`div`,{id:`notebook-workouts`,className:`border-b border-border/50 bg-card`,children:(0,W.jsx)(`div`,{className:`w-full mx-auto`,children:(0,W.jsx)(IQ,{category:s??``,workoutItems:c??[],onSelect:l,showSearch:!1,variant:`flat`})})}):null;if(S){let i=a.slice(0,x),o=a.slice(x);return(0,W.jsxs)(W.Fragment,{children:[e,i.map((e,t)=>B$(e,t,C)),(0,W.jsxs)(`div`,{className:`lg:flex`,children:[r===`left`&&n,(0,W.jsxs)(`div`,{className:`w-full min-w-0`,style:w,children:[t,o.map((e,t)=>B$(e,t,C)),T]}),r===`right`&&n]})]})}return(0,W.jsxs)(W.Fragment,{children:[t,(0,W.jsxs)(`div`,{className:`lg:flex`,children:[r===`left`&&n,(0,W.jsxs)(`div`,{className:`w-full min-w-0`,style:w,children:[e,a.map((e,t)=>B$(e,t,C)),T]}),r===`right`&&n]})]})},H$=({activations:e,runState:t,deps:n})=>{if(e.length===0)return null;let r=e[0];if(rI(r)&&t){let i=e.slice(1),a=t.isReconnect?(0,W.jsxs)(`button`,{onClick:t.onReconnect,className:`flex items-center gap-2 px-5 py-2 text-[11px] font-black uppercase tracking-widest rounded-full border transition-all active:scale-95 border-amber-500/40 bg-amber-500/15 text-amber-600 hover:bg-amber-500/20 dark:text-amber-400`,children:[(0,W.jsx)(Ye,{className:`size-3.5`}),`View`]}):(0,W.jsxs)(`button`,{type:`button`,onClick:t.onRun,className:`flex items-center gap-2 transition-all active:scale-95 bg-primary text-primary-foreground hover:bg-primary/90 font-black uppercase tracking-widest rounded-full shadow-lg shadow-primary/25 min-h-[44px] px-6 py-2 text-xs`,children:[(()=>{let e=r.icon||pn;return(0,W.jsx)(e,{className:`shrink-0 size-4 fill-current sm:size-3`})})(),(0,W.jsx)(`span`,{children:r.label})]});return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 justify-end pt-3 px-1`,children:[a,i.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,n),className:`px-5 py-2 text-[11px] font-black uppercase tracking-widest rounded-full bg-muted border border-border text-foreground hover:bg-muted/80 transition-all active:scale-95`,children:e.label},e.id||t))]})}return(0,W.jsx)(`div`,{className:`flex flex-wrap gap-3 justify-end pt-3 px-1`,children:e.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>eI(e.action,n),className:`px-5 py-2 text-[11px] font-black uppercase tracking-widest rounded-full transition-all active:scale-95 bg-primary text-primary-foreground shadow-lg shadow-primary/25 hover:scale-[1.04]`,children:e.label},e.id||t))})},U$=({variant:e,panelTitle:t,panelSubtitle:n,panelContent:r,panelThemeClass:i,headerActions:a,showPanelButtons:o=!1,viewDefButtons:s,runState:c,deps:l,width:u,source:d=``})=>{let f=r,p=o&&s&&s.length>0?(0,W.jsx)(H$,{activations:s.map((e,t)=>nI(e,t)),runState:c,deps:l}):null;return e===`desktop`?(0,W.jsxs)(`div`,{className:`self-start sticky hidden lg:flex flex-col p-6 pt-8 pb-8 gap-3`,style:{top:`104px`,height:`calc(100vh - 104px)`,width:`clamp(var(--canvas-editor-min-width), var(--canvas-editor-width), var(--canvas-editor-max-width))`,...z$(L$(u),d)},children:[(0,W.jsx)(`div`,{className:`flex-1 min-h-0 flex flex-col justify-center py-4`,children:(0,W.jsx)(`div`,{className:`h-[min(var(--canvas-editor-preferred-height),var(--canvas-editor-max-height))] min-h-[var(--canvas-editor-min-height)] max-h-[var(--canvas-editor-max-height)] flex flex-col w-full`,children:f})}),p]}):(0,W.jsx)(`div`,{className:`lg:hidden sticky z-20 shrink-0 px-4 pt-2 pb-1`,"data-page-sticky-boundary":`true`,style:{top:`65px`,height:`min(var(--canvas-editor-preferred-height), calc(100dvh - 65px - 1rem))`,minHeight:`18rem`,"--canvas-editor-preferred-height":R$(d)},children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 h-full`,children:[(0,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:f}),p]})})},W$=({heroSlot:e,children:t})=>(0,W.jsxs)(`section`,{className:`relative border-b border-border/50`,children:[e,t]}),G$=new Set([q.Duration,q.Time]);function K$(e){return e.metrics.some(e=>e.type===q.Hint&&e.value===`domain.wod`)}function q$(e){return e?e.filter(e=>!K$(e)&&e.metrics.some(e=>e.type===q.Effort)).length:0}function J$(e){if(!e)return 0;let t=0;for(let n of e)if(!K$(n))for(let e of n.metrics)e.type===q.Rounds&&typeof e.value==`number`&&(t+=e.value);return t}function Y$(e){return e?e.some(e=>!K$(e)&&e.metrics.some(e=>G$.has(e.type))):!1}function X$(e){return e?e.some(e=>!K$(e)&&e.metrics.some(e=>e.type===q.Rep)):!1}function Z$(e,t){if(typeof e==`number`&&Number.isFinite(e))return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);if(Number.isFinite(t))return t}return null}function Q$(e,t){return typeof e==`string`&&e.length>0?e:typeof e==`number`?String(e):null}var $$={"has-movement":e=>{let t=q$(e.statements);return t>0?{pass:!0,detail:`${t} movement${t===1?``:`s`}`}:{pass:!1,reason:"Add at least one movement line (e.g. `10 KB Swings`)."}},"exactly-movements":(e,t)=>{let n=Z$(t.count??t.value,`count`);if(n===null)return{pass:!1,reason:"exactly-movements: missing `count`."};let r=q$(e.statements);return r===n?{pass:!0,detail:String(r)}:{pass:!1,reason:`Expected exactly ${n} movement${n===1?``:`s`}, found ${r}.`}},"has-reps":e=>X$(e.statements)?{pass:!0}:{pass:!1,reason:"Add a rep count (e.g. `10` reps on a movement line)."},"has-timer":e=>Y$(e.statements)?{pass:!0}:{pass:!1,reason:"Add a timer (e.g. `*:30 Rest` or `5:00 cap`)."},"min-rounds":(e,t)=>{let n=Z$(t.count??t.min,`count`);if(n===null)return{pass:!1,reason:"min-rounds: missing `count`."};let r=J$(e.statements);return r>=n?{pass:!0,detail:`${r} round${r===1?``:`s`}`}:{pass:!1,reason:`Need at least ${n} round${n===1?``:`s`} — found ${r}.`}},"contains-token":(e,t)=>{let n=Q$(t.value??t.token,`value`);return n===null?{pass:!1,reason:"contains-token: missing `value`."}:(e.content??``).includes(n)?{pass:!0,detail:`"${n}"`}:{pass:!1,reason:`Script must include the token "${n}".`}}};function e1(e,t){if(!t||typeof t.type!=`string`||t.type.length===0)return{pass:!1,reason:`Quest has no validation schema.`};let n=$$[t.type];return n?n(e,t):{pass:!1,reason:`Unknown validation type "${t.type}".`}}function t1({pageRoute:e,quests:t,block:n,enabled:r=!0}){let{markComplete:i,quests:a,isComplete:o}=Nq(e,t),[s,c]=(0,U.useState)(new Set),l=(0,U.useMemo)(()=>{let e={};if(!r||!n){for(let n of t)e[n.id]={pass:!1,reason:`No active block.`};return e}let i={content:n.content,statements:n.statements??[]};for(let n of t){if(!n.validation){e[n.id]={pass:!1};continue}if(n.validation?.type===`workout-complete`){e[n.id]={pass:!1,reason:`Finish the workout to check this off.`};continue}e[n.id]=e1(i,n.validation)}return e},[n,t,r]);(0,U.useEffect)(()=>{if(r)for(let e of a)e.isCompleted||s.has(e.id)||l[e.id]?.pass&&(i(e.id),c(t=>{if(t.has(e.id))return t;let n=new Set(t);return n.add(e.id),n}))},[r,a,l,s,i]);let u=(0,U.useMemo)(()=>t.map(e=>e.id).join(`|`),[t]);return(0,U.useEffect)(()=>{c(new Set)},[e,u]),{quests:a.map(e=>{let t=l[e.id]??{pass:!1,reason:`No validator result.`},n=e.isCompleted?{...t,pass:!0,detail:`Completed`}:t;return{...e,result:n}}),isComplete:o,results:l}}function n1({page:e,wodFiles:t,theme:n,workoutItems:r,onSelect:i,contentOverride:a,panelHeaderActions:o,onPanelActionsReady:s,heroSlot:c,onScrollToSection:l}){let u=Vn(),d=Sn(),{sections:f,route:p,chapters:m}=e,h=d.pathname.startsWith(`/page/`)||p.startsWith(`/page/`),g=(0,U.useMemo)(()=>xV(p),[p]),_=e.type===`guide`||p.startsWith(`/page/guide-`);hq(_?p:void 0);let v=p.startsWith(`/notebook/`),y=Iq(`(prefers-reduced-motion: reduce)`),b=_&&!v&&!y,x=v?p.split(`/`).pop()??null:null,S=(0,U.useCallback)(e=>{if(i){i(e);return}u(DN(e.category,e.name))},[u,i]),C=f.some(e=>e.proseChunks.some(e=>e.kind===`widget`&&e.widget===`workouts-list`)),w=f.slice(1),T=f[0]??null,E=!!T&&(T.proseChunks.some(e=>e.kind===`prose`&&e.text.trim()!==``)||T.buttons.length>0),D=f.find(e=>e.view)?.view??null,O=D?.align??`right`,k=D?.width??`50%`,A=w[0]??f[0]??null,j=p===`/`?`learn`:void 0,M=D?.source?SV(D.source,t):``,N=D?.source||`__initial__`,[P,F]=(0,U.useState)(A?.id??null),[I,L]=(0,U.useState)(A?.heading??`Whiteboard Script`),[ee,te]=(0,U.useState)(A?.heading??`Whiteboard Script`),ne=(0,U.useMemo)(()=>wV(w),[w]),R=b&&p.split(`/`).pop()||void 0,re=(0,U.useMemo)(()=>b?TQ(w,R):null,[b,R,w]),{guideOwnerBySection:ie,guideOwnerSource:ae}=(0,U.useMemo)(()=>{if(!b)return{guideOwnerBySection:null,guideOwnerSource:null};let e=new Map,t=new Map,n=null;for(let r of w){let i=r.proseChunks.find(e=>e.kind===`button`&&e.button.pipeline.some(e=>e.action===`set-source`))?.button.pipeline.find(e=>e.action===`set-source`)?.value??r.buttons.find(e=>e.pipeline.some(e=>e.action===`set-source`))?.pipeline.find(e=>e.action===`set-source`)?.value??null;i&&(n=r,t.set(r.id,i)),e.set(r.id,n)}return{guideOwnerBySection:e,guideOwnerSource:t}},[b,w]),[oe,se]=(0,U.useState)(()=>(A??f[0])?.theme??`slate`),[ce,le]=(0,U.useState)({}),{editorSource:z,editorOpacity:ue,isEditorLoading:de,activeOriginalSource:fe,swapSource:B,handleEditorChange:pe,resetActiveSource:me,setEditorView:he,getSource:ge}=Tq({initialSource:M,initialSourceKey:N,contentOverride:a}),_e=(0,U.useRef)(t);_e.current=t;let ve=(0,U.useCallback)(()=>Me.current[0]??null,[]),{startRun:ye,closeRun:be,handleWorkoutComplete:xe,resetRun:Se,resetRequested:Ce,fullscreen:we,runState:Te,completedResults:Ee}=wq({getBlock:ve,getContent:ge,title:e.frontmatter.title}),De=(0,U.useCallback)(async()=>await Se(M)?(me(),!0):!1,[Se,M,me]),[Oe,ke]=(0,U.useState)(null),Ae=e.quests??[],je=t1({pageRoute:e.route,quests:Ae,block:Oe});Pq({pageRoute:e.route,quests:Ae,completedResults:Ee}),Fq({pageRoute:e.route,quests:Ae,initialSource:M,currentSource:z});let Me=(0,U.useRef)([]),Ne=(0,U.useRef)(ne.get(A?.id??``)?.id??null),Pe=(0,U.useCallback)(e=>{F(e.id),L(e.heading),se(e.theme??`slate`);let t=(ie??ne).get(e.id)??null;te(t?.heading??A?.heading??`Whiteboard Script`);let n=t?.id??null;if(n===Ne.current)return;if(Ne.current=n,!t){B(M,N);return}let r=t.examples??[];if(r.length>0){let e=r[ce[t.id]??0]??r[0];e?.source&&B(SV(e.source,_e.current),e.source)}for(let e of t.commands){let t=e.pipeline.filter(e=>!(r.length>0&&e.action===`set-source`)).map(t=>tI(t,e.open??`view`));t.length!==0&&eI(t.length===1?t[0]:{type:`pipeline`,steps:t},Be.current)}let i=ie?ae?.get(t.id):void 0;i&&B(SV(i,_e.current),i)},[ce,B,ne,ie,ae,A,M,N]),Fe=(0,U.useCallback)((e,t)=>{le(n=>({...n,[e.id]:t})),F(e.id),L(e.heading),se(e.theme??`slate`),te(e.heading),Ne.current=e.id;let n=e.examples?.[t];n?.source&&B(SV(n.source,_e.current),n.source)},[B]),[Ie,Le]=Kt(`h`,{history:`replace`,shallow:!0}),[Re]=Kt(`q`,{defaultValue:``,shallow:!0}),ze=(0,U.useMemo)(()=>({navigate:(e,t)=>u(e,{replace:t?.replace}),setQueryParam:(e,t)=>{let n=e.h;n!==void 0&&Le(n,{history:t?`replace`:`push`})},swapSource:e=>B(SV(e,_e.current),e),setPanelState:e=>{if(e===`track`){let e=ve();e&&ye(e)}}}),[u,B,Le,ve,ye]),Be=(0,U.useRef)(ze);Be.current=ze;let Ve=(0,U.useCallback)(e=>{Le(e.id,{history:`replace`}),Pe(e)},[Pe,Le]),He=zB(104),Ue=(0,U.useMemo)(()=>`-${He}px 0px -30% 0px`,[He]),We=re?re.tail.map(e=>e.id):w.map(e=>e.id),Ge=(0,U.useRef)(!1);PB({ids:We,enabled:We.length>0,rootMargin:Ue,threshold:[0,.1,.25,.5,.75],dataAttribute:`data-section-id`,scrollDirection:`topmost-when-up`,debounceMs:50,shouldAcceptChange:()=>Ge.current?!0:(Ge.current=window.scrollY>0,Ge.current),onChange:e=>{let t=w.find(t=>t.id===e);t&&(Le(e,{history:`replace`}),Pe(t))}});let Ke=(0,U.useRef)(!1);(0,U.useEffect)(()=>{Ke.current||!Ie||w.length===0||(Ke.current=!0,requestAnimationFrame(()=>{let e=document.querySelector(`[data-section-id="${Ie}"]`);if(!e)return;let t=He+8,n=e.getBoundingClientRect().top+window.scrollY-t;window.scrollTo({top:Math.max(0,n),behavior:`smooth`})}))},[w,Ie,He]);let qe=(0,U.useRef)(Re);(0,U.useEffect)(()=>{if(!v){qe.current=Re;return}let e=Re.trim(),t=qe.current.trim();if(e&&e!==t){let e=document.getElementById(`notebook-workouts`);if(e){let t=e.getBoundingClientRect().top+window.scrollY-He-8;window.scrollTo({top:Math.max(0,t),behavior:`smooth`})}}qe.current=Re},[Re,v,He]);let Je=(0,U.useRef)(s);Je.current=s,(0,U.useEffect)(()=>{Je.current?.({run:()=>{let e=Me.current[0]??null;e&&ye(e)},reset:()=>{Se()},results:()=>{},fullscreen:()=>{let e=Me.current[0]??null;e&&ye(e)},getSource:ge})},[ye,Se,ge]);let Ye=(0,U.useMemo)(()=>[{id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:e=>{ye(e)}}],[ye]),Xe=_L[oe]??_L.slate,Ze=de?`${I} · loading`:I,Qe=!de&&I!==ee?ee:void 0,$e=(0,U.useCallback)(e=>{let t=e[0]??null;Me.current=e,ke(e=>e?.content===t?.content&&e?.id===t?.id?e:t)},[]),et=c??(E&&T?(0,W.jsx)(b$,{section:T,idx:-1,prose:void 0,blockId:T.id,keySuffix:`hero`,showEyebrow:!1,isActive:!1,hasViewDef:!!D,deps:ze,onExampleSelect:Fe,selectedExampleIndex:0,onScrollToSection:l,challengeQuests:je.quests}):null),tt=o,nt=(0,W.jsx)(rQ,{editorSource:z,editorOpacity:ue,activeOriginalSource:fe,handleEditorChange:pe,onResetToSource:De,canvasNoteId:g,readonly:h,showFrontmatter:typeof e.frontmatter.showFrontmatter==`boolean`?e.frontmatter.showFrontmatter:!_&&p!==`/`&&!p.startsWith(`/syntax`),theme:n,commands:Ye,onBlocksChange:$e,onViewCreated:he,panelTitle:Ze,panelSubtitle:Qe,panelThemeClass:Xe.panel,headerActions:tt,onRun:(e,t)=>{t&&ye(t,e)}}),rt=D&&(0,W.jsx)(U$,{variant:`desktop`,panelContent:nt,panelTitle:Ze,panelSubtitle:Qe,viewDefButtons:D.buttons,runState:Te,deps:ze,width:k,source:z}),it=D&&(0,W.jsx)(U$,{variant:`mobile`,panelContent:nt,panelTitle:Ze,panelSubtitle:Qe,viewDefButtons:D.buttons,runState:Te,deps:ze,width:k,source:z});return(0,W.jsxs)(`div`,{className:`flex flex-col min-h-screen bg-background`,children:[we?.kind===`timer`&&(0,W.jsx)(`div`,{className:`sticky z-30 border-b border-border bg-background`,style:{top:He},children:(0,W.jsx)(`div`,{className:`mx-auto h-[max(320px,min(75vh,640px))] max-w-5xl px-4 py-2`,children:(0,W.jsx)(rq,{block:we.block,onClose:be,autoStart:!0,externalStop:Ce,onComplete:(e,t)=>{xe(t)}})})}),(0,W.jsx)(W$,{heroSlot:et,children:b?(0,W.jsx)(C$,{sections:w,groupKey:R,title:String(e.frontmatter.title??``),pane:(0,W.jsx)(`div`,{className:`absolute inset-0`,style:{"--canvas-editor-preferred-height":R$(z)},children:nt}),cardArgs:{activeSectionId:P,selectedExamples:ce,onExampleSelect:Fe,runState:Te,deps:ze,hasViewDef:!!D,chapters:m,challengeQuests:je.quests,onScrollToSection:l},onActivateSection:Ve}):(0,W.jsx)(V$,{contentSections:w,isCollection:v,notebookSlug:x,workoutItems:r,handleSelectWorkout:S,activeSectionId:P,selectedExamples:ce,runState:Te,deps:ze,handleExampleSelect:Fe,hasWorkoutsTag:C,hasViewDef:!!D,chapters:m,challengeQuests:je.quests,onScrollToSection:l,mobilePanel:it,desktopPanel:rt,stickyAlign:O,editorWidth:k,editorAppearsAtSectionId:j})}),_&&(0,W.jsx)(M$,{})]})}var r1={"workout-complete":!0,"run-started":!0};function i1(e,t,n){let{markComplete:r}=Nq(e,t),i=(0,U.useRef)(new Set);i.current=new Set(t.filter(e=>!e.validation||!r1[e.validation.type]).map(e=>e.id));let a=(0,U.useRef)({}),o={};for(let e of n)e.quest&&(o[e.id]=e.quest);return a.current=o,(0,U.useCallback)(e=>{let t=a.current[e];t&&i.current.has(t)&&r(t)},[r])}function a1(){let e=Iq(`(prefers-reduced-motion: reduce)`),t=Iq(`(max-width: ${bV}px)`);return e?`reduced`:t?`mobile`:`desktop`}var o1=.25;function s1({sourcesByStageId:e,doc:t,setDoc:n,subscribe:r,enabled:i}){let[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(t),c=(0,U.useRef)(null),l=(0,U.useRef)(t),u=(0,U.useRef)(a),d=(0,U.useRef)(``),f=(0,U.useRef)(null),p=(0,U.useRef)(!1);return l.current=t,u.current=a,(0,U.useEffect)(()=>{let e=d.current;if(c.current!==null){if(t===c.current){s.current=t,c.current=null;return}if(t!==s.current){o(!0);return}}t!==s.current&&t!==e&&o(!0)},[t]),(0,U.useEffect)(()=>{if(!i){c.current=null;return}let t=r(t=>{if(t.stage.id!==f.current&&(f.current=t.stage.id,d.current=e[t.stage.id]??``,s.current=``,c.current=null,o(!1),p.current=!0),u.current||c.current!==null)return;let r=d.current;if(!r)return;let i=t.index===0?r.length:Math.floor(cQ(oQ(t.t/o1))*r.length),a=r.slice(0,i),m=l.current;p.current=!1,a!==m&&(c.current=a,n(a))});return()=>{t()}},[i,e,n,r]),{userDiverged:a,complete:(0,U.useCallback)(()=>{if(u.current)return;let e=d.current;e&&(c.current=e,n(e))},[n])}}function c1({stages:e,activeIndex:t}){return(0,W.jsx)(`div`,{className:`relative h-full w-full`,"data-testid":`scroll-captions`,children:e.map((n,r)=>(0,W.jsxs)(`div`,{className:`absolute inset-0 overflow-y-auto transition-opacity duration-300`,style:{opacity:+(r===t)},"aria-hidden":r!==t,inert:r!==t,children:[(0,W.jsxs)(`div`,{className:`font-mono text-[11px] uppercase tracking-[0.22em]`,style:{color:n.accent??`hsl(var(--muted-foreground))`},children:[String(r+1).padStart(2,`0`),` / `,String(e.length).padStart(2,`0`)]}),(0,W.jsx)(`h3`,{className:`mt-3 text-2xl font-bold tracking-tight text-foreground`,children:n.id.replace(/-/g,` `)}),n.caption&&(0,W.jsx)(t$,{prose:n.caption,className:`mt-3 text-sm text-muted-foreground`})]},n.id))})}var l1=(0,U.forwardRef)(function({text:e,accent:t},n){let r=t??`hsl(var(--metric-rounds))`;return(0,W.jsxs)(`div`,{ref:n,className:`pointer-events-none absolute top-4 left-1/2 z-40 flex -translate-x-1/2 items-center gap-2.5 whitespace-nowrap rounded-full border bg-card px-5 py-2.5 font-mono text-[10.5px] tracking-[0.04em] opacity-0 shadow-xl`,style:{borderColor:`color-mix(in srgb, ${r} 55%, transparent)`},children:[(0,W.jsx)(`span`,{className:`size-[9px] rounded-sm`,style:{background:r}}),e]})}),u1=8,d1=3,f1=2;function p1(e,t,n){let r=e.querySelectorAll(`.cm-content .cm-line`),i=Math.max(1,Math.min(n[0],n[1]))-1,a=Math.max(1,Math.max(n[0],n[1])),o=Array.from(r).slice(i,a);if(o.length===0)return null;let s=e.getBoundingClientRect(),c=1/0,l=1/0,u=-1/0,d=-1/0;for(let e of o){let t=e.getBoundingClientRect();c=Math.min(c,t.top),l=Math.min(l,t.left),u=Math.max(u,t.bottom),d=Math.max(d,t.right)}return c-=d1,l-=u1,u+=d1,d+=u1,t&&(l=Math.max(l,t.left-f1),d=Math.min(d,t.right+f1),c=Math.max(c,t.top-f1),u=Math.min(u,t.bottom+f1)),{top:c-s.top,left:l-s.left,width:d-l,height:u-c}}function m1(e,t){if(!t)return null;let n=t.getBoundingClientRect();if(n.width===0||n.height===0)return null;let r=e.getBoundingClientRect();return{top:n.top-r.top-f1,left:n.left-r.left-f1,width:n.width+4,height:n.height+4}}function h1({accent:e,lines:t}){let n=e??`hsl(var(--foreground))`,r=(0,U.useRef)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1);return(0,U.useLayoutEffect)(()=>{let e=r.current;if(!e)return;let n=requestAnimationFrame(()=>s(!0)),i=e.parentElement;if(!i)return()=>cancelAnimationFrame(n);let o=()=>{let e=i.firstElementChild,n=e?.getBoundingClientRect()??null;a((t?p1(i,n,t):null)??m1(i,e))};o();let c=new ResizeObserver(o);return c.observe(i),()=>{cancelAnimationFrame(n),c.disconnect()}},[t]),(0,W.jsx)(`div`,{ref:r,className:`pointer-events-none absolute z-30 transition-all duration-300 ${i?t?`rounded-lg`:`rounded-2xl`:`-inset-1.5 rounded-2xl`}`,style:{boxShadow:`0 0 0 2px ${n}`,opacity:+!!o,...i??{}},"data-testid":`scroll-ring`,"data-ring-lines":t?`${t[0]}-${t[1]}`:void 0})}function g1({scroll:e,wodFiles:t,theme:n,noteTitle:r=`note.md`,showFrontmatter:i,doc:a,onDocChange:o,onBlocksChange:s,onStageEnter:c,onRun:l,className:u}){let d=e.stages,f=(0,U.useRef)(null),p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=(0,U.useRef)(new Set),g=(0,U.useMemo)(()=>Object.fromEntries(d.map(e=>[e.id,e.source?SV(e.source,t):``])),[d,t]),[_,v]=(0,U.useState)(()=>g[d[0]?.id]??``),y=a??_,b=o??v,[x,S]=(0,U.useState)(!1),{slice:C,subscribe:w,resync:T}=SQ(f,x,d),[E,D]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=f.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&D(!0)},{rootMargin:`100px`});return t.observe(e),()=>t.disconnect()},[]);let{userDiverged:O}=s1({sourcesByStageId:g,doc:y,setDoc:b,subscribe:w,enabled:!x&&e.typewriter}),k=C.stage.id,A=lQ(g[k]??``,y);(0,U.useEffect)(()=>{!x&&E&&c?.(k)},[x,k,E,c]),(0,U.useEffect)(()=>{if(!x){let e=requestAnimationFrame(T);return()=>cancelAnimationFrame(e)}},[x,T]),(0,U.useEffect)(()=>{let e=requestAnimationFrame(T);return()=>cancelAnimationFrame(e)},[k,T]),(0,U.useEffect)(()=>{O&&S(!0)},[O]),(0,U.useEffect)(()=>{let e=d.flatMap(e=>e.effects??[]);return w(t=>{let n=m.current;if(n){let e=oQ((t.t-.04)/.12),r=oQ((t.t-.5)/.2);n.style.opacity=String(Math.max(0,e-r)),n.style.transform=`translateX(-50%) translateY(${sQ(-14,0,e)}px)`}let r=p.current;if(!r)return;let i=new Set;for(let n of e){if(!n.stages.includes(t.stage.id))continue;i.add(n.target);let[e,a]=n.in??[0,1],o=a>e?oQ((t.t-e)/(a-e)):1,s=n.ease===`linear`?o:cQ(o);r.querySelectorAll(`[data-effect-target="${n.target}"]`).forEach(e=>{n.opacity&&(e.style.opacity=String(sQ(n.opacity[0],n.opacity[1],s))),n.translateY&&(e.style.transform=`translateY(${sQ(n.translateY[0],n.translateY[1],s)}px)`)})}for(let e of h.current)i.has(e)||r.querySelectorAll(`[data-effect-target="${e}"]`).forEach(e=>{e.style.opacity=``,e.style.transform=``});h.current=i})},[w,d]);let j=C.stage.accent??`hsl(var(--foreground))`;return(0,W.jsxs)(`div`,{ref:p,className:u,"data-testid":`scroll-runway-section`,children:[(0,W.jsx)(yQ,{trackRef:f,height:e.runway,stages:d,activeIndex:C.index,status:(0,W.jsx)(`div`,{className:`truncate font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground`,children:x?`Playground mode`:C.stage.id.replace(/-/g,` `)}),pane:(0,W.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,W.jsx)(nQ,{title:r??``,noteId:`canvas:scroll-runway`,doc:y,onDocChange:b,onBlocksChange:s,theme:n,showFrontmatter:i,run:l?{onRun:l}:void 0,className:`absolute inset-x-2 top-2 bottom-2`,children:C.stage.toast&&(0,W.jsx)(l1,{ref:m,text:C.stage.toast,accent:j})}),C.ring&&!x&&A&&(0,W.jsx)(h1,{accent:j,lines:C.ring.lines})]}),captions:(0,W.jsx)(c1,{stages:d,activeIndex:C.index})}),x&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>S(!1),className:`fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded-full bg-foreground px-5 py-2.5 font-mono text-[10px] tracking-[0.06em] text-background opacity-95 transition-opacity hover:opacity-100`,children:[`▶ Playground mode — `,O?`your edits are kept`:`editing`,` · tap here to return to the tour`]})]})}function _1({spec:e,wodFiles:t,onStageEnter:n,className:r}){let i=e.stages,a=(0,U.useMemo)(()=>Object.fromEntries(i.map(e=>[e.id,e.source?SV(e.source,t):``])),[i,t]),o=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;let e=o.current;if(!e)return;let t=new IntersectionObserver(e=>{for(let r of e){if(!r.isIntersecting)continue;let e=r.target.dataset.cardId;e&&(n?.(e),t.unobserve(r.target))}},{threshold:.4});return e.querySelectorAll(`[data-card-id]`).forEach(e=>t.observe(e)),()=>t.disconnect()},[n]),(0,W.jsx)(`section`,{className:r,"data-testid":`runway-reduced`,children:(0,W.jsx)(`div`,{className:`px-6 pt-4 pb-24`,children:(0,W.jsx)(`div`,{ref:o,className:`mx-auto max-w-2xl`,children:i.map((e,t)=>(0,W.jsxs)(`article`,{"data-card-id":e.id,className:`mb-6 rounded-2xl border border-border bg-card p-7`,children:[(0,W.jsxs)(`div`,{className:`font-mono text-[11px] uppercase tracking-[0.22em]`,style:{color:e.accent??`hsl(var(--muted-foreground))`},children:[String(t+1).padStart(2,`0`),` / `,String(i.length).padStart(2,`0`)]}),(0,W.jsx)(`h3`,{className:`mt-3 text-2xl font-bold tracking-tight text-foreground`,children:e.id.replace(/-/g,` `)}),e.caption&&(0,W.jsx)(t$,{prose:e.caption,className:`mt-3 text-sm text-muted-foreground`}),a[e.id]&&(0,W.jsx)(`pre`,{className:`mt-5 overflow-x-auto rounded-lg bg-background px-4 py-4 font-mono text-[12px] tracking-[0.04em] text-muted-foreground`,children:a[e.id]})]},e.id))})})})}function v1(){return a1()}function y1({spec:e,formFactor:t,wodFiles:n,theme:r,noteTitle:i,showFrontmatter:a,doc:o,onDocChange:s,onBlocksChange:c,onStageEnter:l,onRun:u,className:d}){let f=v1();return(t??f)===`reduced`?(0,W.jsx)(_1,{spec:e,wodFiles:n,onStageEnter:l,className:d}):(0,W.jsx)(g1,{scroll:e,wodFiles:n,theme:r,noteTitle:i,showFrontmatter:a,doc:o,onDocChange:s,onBlocksChange:c,onStageEnter:l,onRun:u,className:d})}function b1({page:e,wodFiles:t,theme:n,onScrollToSection:r}){let i=e.scroll,a=i.stages,o=Vn();hq(e.type===`guide`||e.route.startsWith(`/page/guide-`)?e.route:void 0);let s=(0,U.useMemo)(()=>Object.fromEntries(a.map(e=>[e.id,e.source?SV(e.source,t):``])),[a,t]),[c,l]=(0,U.useState)(()=>s[a[0]?.id]??``),u=(0,U.useRef)([]),[d,f]=(0,U.useState)(null),p=i1(e.route,e.quests,a),m=(0,U.useCallback)(()=>u.current[0]??null,[]),h=wq({getBlock:m,getContent:(0,U.useCallback)(()=>c,[c]),title:e.frontmatter.title}),{startRun:g}=h,_=zB(104),v=t1({pageRoute:e.route,quests:e.quests,block:d});Pq({pageRoute:e.route,quests:e.quests,completedResults:h.completedResults});let[,y]=Kt(`h`,{history:`replace`,shallow:!0}),b=(0,U.useMemo)(()=>({navigate:(e,t)=>o(e,{replace:t?.replace}),setQueryParam:(e,t)=>{let n=e.h;n!==void 0&&y(n,{history:t?`replace`:`push`})},swapSource:e=>l(SV(e,t)),setPanelState:e=>{if(e===`track`){let e=m();e&&g(e)}}}),[o,y,t,m,g]),x=(0,U.useCallback)((e,n)=>{let r=e.examples?.[n];r?.source&&l(SV(r.source,t))},[t]),S=(0,U.useCallback)(e=>{let t=e[0]??null;u.current=e,f(e=>e?.content===t?.content&&e?.id===t?.id?e:t)},[]),C=(0,U.useCallback)((e,t)=>{t&&g(t,e)},[g]),w=`${e.route.split(`/`).pop()??`note`}.md`,T=e.sections.slice(1).map((e,t)=>(0,W.jsx)(b$,{section:e,idx:t,blockId:e.id,keySuffix:`scroll`,isActive:!1,hasViewDef:!1,deps:b,onExampleSelect:x,selectedExampleIndex:0,challengeQuests:v.quests,onScrollToSection:r},e.id));return(0,W.jsxs)(`div`,{className:`flex flex-col min-h-screen bg-background`,"data-testid":`scroll-canvas-page`,children:[h.fullscreen?.kind===`timer`&&(0,W.jsx)(`div`,{className:`sticky z-30 border-b border-border bg-background`,style:{top:_},children:(0,W.jsx)(`div`,{className:`mx-auto h-[max(320px,min(75vh,640px))] max-w-5xl px-4 py-2`,children:(0,W.jsx)(rq,{block:h.fullscreen.block,onClose:h.closeRun,autoStart:!0,externalStop:h.resetRequested,onComplete:(e,t)=>{h.handleWorkoutComplete(t)}})})}),(0,W.jsx)(y1,{spec:i,wodFiles:t,theme:n,noteTitle:w,showFrontmatter:e.frontmatter.showFrontmatter===!0,doc:c,onDocChange:l,onBlocksChange:S,onStageEnter:p,onRun:C}),T]})}function x1({feedSlug:e}){let t=(0,U.useMemo)(()=>xA(e),[e]),n=(0,U.useMemo)(()=>t?OA(t.id):[],[t]);return t?(0,W.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-2xl px-4 py-10 sm:px-6 flex flex-col gap-6`,children:[(0,W.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(`h1`,{className:`text-2xl font-bold`,children:t.label}),t.description?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description}):null,(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground/80`,children:[(0,W.jsxs)(`a`,{href:t.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 hover:text-foreground`,children:[(0,W.jsx)(A,{className:`size-3`}),`Published directory`]}),t.repositoryUrl?(0,W.jsxs)(`a`,{href:t.repositoryUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 hover:text-foreground`,children:[(0,W.jsx)(A,{className:`size-3`}),`Repository`]}):null]})]}),(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,W.jsx)(`h2`,{className:`text-xs font-bold uppercase tracking-widest text-muted-foreground/70`,children:`Notebooks`}),n.length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This feed publishes no notebooks.`}):(0,W.jsx)(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border bg-card`,children:n.map(e=>(0,W.jsx)(`li`,{children:(0,W.jsxs)(_n,{to:EN(e.id),className:`flex items-center gap-3 px-4 py-3 hover:bg-accent/40`,children:[(0,W.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground`}),(0,W.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,W.jsx)(`span`,{className:`truncate text-sm font-semibold`,children:e.label}),e.description?(0,W.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.description}):null]})]})},e.id))})]})]})}):(0,W.jsxs)(`div`,{className:`flex flex-1 items-center justify-center p-20 text-sm text-muted-foreground`,children:[`Feed not found: `,e]})}var S1=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function C1(e,t){return new Date(e,t+1,0).getDate()}function w1(e,t){let n=new Date(e,t,1).getDay();return n===0?6:n-1}function T1(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function E1(e){return T1(e.getFullYear(),e.getMonth(),e.getDate())}var D1=({selectedDate:e,onDateSelect:t,entryDates:n=new Set,disabled:r=!1,className:i})=>{let[a,o]=(0,U.useState)(()=>e||new Date),s=a.getFullYear(),c=a.getMonth();(0,U.useEffect)(()=>{e&&o(t=>t.getFullYear()!==e.getFullYear()||t.getMonth()!==e.getMonth()?new Date(e.getFullYear(),e.getMonth(),1):t)},[e]);let l=e?E1(e):null,u=(0,U.useMemo)(()=>{let e=C1(s,c),t=w1(s,c),n=[];for(let e=0;e<t;e++)n.push(null);for(let t=1;t<=e;t++)n.push(t);return n},[s,c]),d=e=>{e.stopPropagation(),e.preventDefault(),o(new Date(s,c-1,1))},f=e=>{e.stopPropagation(),e.preventDefault(),o(new Date(s,c+1,1))},p=a.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`}),m=E1(new Date);return(0,W.jsxs)(`div`,{className:G(`select-none px-2 py-2`,r&&`opacity-60 cursor-not-allowed`,i),onClick:e=>e.stopPropagation(),"aria-disabled":r||void 0,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`button`,{onClick:d,disabled:r,className:`p-1 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none`,"aria-label":`Previous month`,children:(0,W.jsx)(Un,{className:`h-4 w-4`})}),(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:p}),(0,W.jsx)(`button`,{onClick:f,disabled:r,className:`p-1 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none`,"aria-label":`Next month`,children:(0,W.jsx)(wn,{className:`h-4 w-4`})})]}),(0,W.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5 mb-1`,children:S1.map(e=>(0,W.jsx)(`div`,{className:`text-center text-[10px] text-muted-foreground font-medium py-0.5 w-8`,children:e},e))}),(0,W.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5`,children:u.map((e,i)=>{if(e===null)return(0,W.jsx)(`div`,{className:`w-8 h-8`},`empty-${i}`);let a=T1(s,c,e),o=n.has(a),u=a===l;return(0,W.jsxs)(`button`,{disabled:r,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(new Date(s,c,e),n.ctrlKey||n.metaKey)},className:G(`w-8 h-8 flex items-center justify-center rounded text-xs transition-colors relative`,`disabled:pointer-events-none`,u?`bg-primary text-primary-foreground font-bold`:a===m?`font-bold text-primary ring-1 ring-primary/40`:o?`font-semibold text-foreground hover:bg-muted`:`text-muted-foreground hover:bg-muted/50`),"aria-label":`${e} ${p}${o?` (has entries)`:``}`,children:[e,o&&!u&&(0,W.jsx)(`span`,{className:`absolute bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-primary/60`})]},a)})})]})};function O1({onSave:e,getSnapshotKey:t,onError:n}){let r=(0,U.useRef)(null),i=(0,U.useRef)(null),a=(0,U.useRef)(null),o=(0,U.useRef)(Promise.resolve()),s=(0,U.useRef)({onSave:e,getSnapshotKey:t,onError:n});s.current={onSave:e,getSnapshotKey:t,onError:n};let[c,l]=(0,U.useState)(null),u=(0,U.useCallback)(e=>{let t=o.current.then(async()=>{e.key!==i.current&&(await s.current.onSave(e.value),i.current=e.key,l(null))});return o.current=t.catch(e=>{l(e),s.current.onError?.(e)}),t},[]),d=(0,U.useCallback)(()=>r.current?u(r.current):o.current,[u]),f=(0,U.useCallback)(e=>{let t=s.current.getSnapshotKey?.(e)??(typeof e==`string`?e:JSON.stringify(e));r.current={value:e,key:t}},[]),p=(0,U.useCallback)((e,t)=>{a.current!==null&&a.current!==e&&d().catch(()=>{}),a.current=e},[d]),m=(0,U.useCallback)(()=>{d().catch(()=>{})},[d]);return(0,U.useEffect)(()=>{let e=()=>{d().catch(()=>{})},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),d().catch(()=>{})}},[d]),{onChange:f,onLineChange:p,onBlur:m,flush:d,error:c}}var k1=8e3;function A1({category:e,name:t,mdContent:n,seedOnMount:r=!0}){let i=VH(e,t),[a,o]=(0,U.useState)(n),[s,c]=(0,U.useState)(!0),[l,u]=(0,U.useState)(),[d,f]=(0,U.useState)({}),[p,m]=(0,U.useState)(0),[h,g]=(0,U.useState)(null),_=(0,U.useRef)({id:i,revision:0}),v=(0,U.useRef)(i);v.current=i;let y=(0,U.useRef)({rawContent:n,noteBlocks:{},sourceRevision:0}),b=(0,U.useCallback)(e=>{_.current.revision=e.sourceRevision,m(e.sourceRevision),y.current.rawContent===e.rawContent&&Object.keys(y.current.noteBlocks).length===Object.keys(e.blocks).length&&Object.values(y.current.noteBlocks).every(t=>{let n=e.blocks[t.id];return n&&n.from===t.from&&n.to===t.to&&n.kind===t.kind})&&(y.current={rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision},f(e.blocks))},[]),x=O1({onSave:(0,U.useCallback)(async e=>{if(e.routeId===v.current&&h)throw h;let t=await lP.saveNote({noteId:e.noteId,rawContent:e.rawContent,blocks:e.noteBlocks,expectedSourceRevision:_.current.id===e.noteId?_.current.revision:e.sourceRevision,metadata:{title:e.title},noteType:`playground`});v.current===e.routeId&&(_.current.id=t.id,u(t.id),b({rawContent:t.rawContent,blocks:t.blocks??{},sourceRevision:t.sourceRevision??1}))},[b,h]),getSnapshotKey:e=>JSON.stringify([e.noteId,e.rawContent,Object.values(e.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])])});(0,U.useEffect)(()=>{let e=!1;_.current={id:i,revision:0},c(!0),g(null);let a=La(n,{sourceRevision:1,registeredWidgets:ja}),s=(e,t,n,r)=>{o(e),f(t),m(n),u(r),_.current={id:r??i,revision:n},y.current={rawContent:e,noteBlocks:t,sourceRevision:n}},l=setTimeout(()=>{e||(e=!0,s(n,a,0),g(Error(`Note load timed out. Reload before saving to avoid overwriting stored content.`)),c(!1))},k1);return(async()=>{try{let o=await KH.getPage(i);if(e)return;if(o)s(o.content,o.noteBlocks??{},o.sourceRevision??1,o.id);else if(r){let r=await lP.saveNote({noteId:i,rawContent:n,blocks:a,expectedSourceRevision:0,metadata:{title:t},noteType:`playground`});e||s(r.rawContent,r.blocks??{},r.sourceRevision??1,r.id)}else s(n,a,0)}catch(t){e||(s(n,a,0),g(t))}finally{clearTimeout(l),e||c(!1)}})(),()=>{e=!0,clearTimeout(l)}},[i,n,t,r]);let S=(0,U.useCallback)(e=>{(y.current.rawContent!==e.rawContent||JSON.stringify(Object.values(y.current.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(e.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])))&&(y.current=e,o(e.rawContent),f(e.noteBlocks),x.onChange({...e,routeId:i,noteId:_.current.id,title:t}))},[x.onChange,i,t]),C=(0,U.useCallback)(e=>{if(o(e),y.current.rawContent===e)return;let t=La(e,{sourceRevision:_.current.revision||1,registeredWidgets:ja});S({rawContent:e,noteBlocks:t,sourceRevision:_.current.revision})},[S]),w=(0,U.useCallback)(async()=>{S({rawContent:n,sourceRevision:_.current.revision,noteBlocks:La(n,{sourceRevision:_.current.revision||1,registeredWidgets:ja})}),await x.flush()},[n,S,x.flush]),T=(0,U.useCallback)(()=>_.current.revision,[]);return{content:a,loading:s,entryId:l,noteBlocks:d,sourceRevision:p,onIdentityChange:S,onSaved:b,onChange:C,onLineChange:x.onLineChange,onBlur:x.onBlur,flush:x.flush,committedSourceRevision:T,resetToOriginal:w,isModified:a!==n,error:x.error??h}}async function j1({workoutName:e,category:t,sourceNoteLabel:n,sourceNotePath:r,wodContent:i,date:a,wrapInWod:o=!0}){let s=gP(a??new Date),c=r?.trim()||`/notebook/${encodeURIComponent(t)}`,l=[`# ${e}`,``];return o?l.push("```time",i.trimEnd(),"```"):l.push(i.trimEnd()),l.push(``),CP.create({journalDate:s,title:hP(e),rawContent:l.join(`
164
+ `),sourceId:c})}var M1=new Map,N1=new Map;function P1(e){N1.set(e.runtimeId,e)}function F1(e){let t=N1.get(e);return t&&N1.delete(e),t}function I1(e){for(let t of N1.values())if(t.journalDate===e)return t}function L1(e){N1.delete(e)}function R1(e,t,n){let r=t?e.filter(e=>e.blockId===t):e;if(r.length===0)return{current:[],currentVersion:0,history:new Map};let i=new Map;for(let e of r){let t=e.blockVersion;i.has(t)||i.set(t,[]),i.get(t).push(e)}let a=[],o=0;for(let[e,t]of i)t.some(e=>e.blockContentId===n)&&(e>o?(o=e,a.length=0,a.push(...t)):e===o&&a.push(...t));let s=new Map;for(let[e,t]of i)e!==o&&s.set(e,{version:e,contentId:t[0]?.blockContentId,results:t});return{current:a,currentVersion:o,history:s}}function z1(e,t,n,r,i){let a=e.map(e=>{if(e.type!==`time`&&e.type!==`log`)return e;let i=parseInt(e.id.replace(`${e.type}-line-`,``),10),a=t.find(e=>e.startLine+1===i),o={};if(r&&a){let{current:e}=R1(r,a.id,a.contentId);o={hasResult:e.length>0,resultCount:e.length}}return e.type===`log`||!n?{...e,...o}:{...e,...o,onRun:()=>{let e=a||t.find(e=>e.startLine+1===i)||t[0];e&&n(e)}}});if(i){let e=a.findIndex(e=>e.type===`heading`),t=e===-1?0:e;if(a[t])return a.map((e,n)=>n===t?{...e,onRun:i,runIcon:`edit`}:e)}return a}function B1({content:e,scriptBlocks:t,onStartWorkout:n,results:r,onEditNote:i}){let a=(0,U.useMemo)(()=>z1(CU(e),t,n,r,i),[e,t,n,r,i]),{setL3Items:o}=WM();return(0,U.useEffect)(()=>(o(wU(a)),()=>o([])),[a,o]),a}function V1(e){switch(e.kind){case`journal`:return CN(e.id);case`playground`:return SN(e.id);case`workout`:return e.category===`effort`?RN(e.id):e.category===`equipment`?PN(e.id):e.category?DN(e.category,e.id):TN(e.raw)}}function H1(e){let t=cz(e);return t.kind===`workout`&&!t.category?TN(e):V1(t)}var U1={efforts:[],related:[],backlinks:[]},W1=8;function G1(e){let t=e.id,n=e.type===`playground`||e.sourceId===`playground`||t.startsWith(`playground/`),r=cz(t);if(e.type===`journal`||e.journalDate||!n&&r.kind===`journal`){let n=e.journalDate??(r.kind===`journal`?r.id:void 0);return{zone:`notebooks`,up:n?{id:n,title:`Journal`,to:CN(n)}:null,stamps:[t]}}if(n||r.kind===`playground`){let e=bz({id:t});return{zone:`notebooks`,up:{id:`playgrounds`,title:`Playgrounds`,to:MN()},stamps:[`/playground/${e}`]}}if(r.kind===`workout`){if(r.category===`effort`)return{zone:`efforts`,up:{id:`efforts`,title:`Efforts`,to:NN()},stamps:[RN(r.id)]};if(r.category===`equipment`)return{zone:`equipment`,up:{id:`equipment`,title:`Equipment`,to:$.equipment},stamps:[PN(r.id)]};if(r.category===`notebook`)return{zone:`notebooks`,up:r.id?{id:r.id,title:r.id,to:EN(r.id)}:null,stamps:[]};if(r.category)return{zone:`notebooks`,up:{id:r.category,title:r.category,to:EN(r.category)},stamps:[DN(r.category,r.id)]}}if(e.type===`page`&&(e.pageId??e.slug)){let t=e.pageId??e.slug;return{zone:null,up:{id:t,title:`/page/${t}`,to:jN(t)},stamps:[]}}return{zone:null,up:null,stamps:[]}}function K1(e){if(!e.startsWith(`/`))return null;let t=e.split(`#`)[0],n=t.replace(/\/+$/,``).split(`/`).filter(Boolean),r=n[n.length-1];if(r)try{r=decodeURIComponent(r)}catch{}return{id:t,title:r||t,to:t}}function q1(e,t){let n=new Set,r=[];for(let i of e){if(!i.effortSlug||n.has(i.effortSlug))continue;n.add(i.effortSlug);let e=!t||t.has(i.effortSlug);r.push({id:i.effortSlug,title:i.effortSlug,to:e?RN(i.effortSlug):`${NN()}?q=${encodeURIComponent(i.effortSlug)}`})}return r}function J1(e,t,n=W1){let r=new Set(e.filter(e=>e.noteId===t&&e.dataType===`wod`&&e.blockContentId).map(e=>e.blockContentId));if(r.size===0)return[];let i=new Map;for(let a of e)if(a.dataType===`wod`&&!(!a.blockContentId||!r.has(a.blockContentId)||a.noteId===t)&&!i.has(a.noteId)&&(i.set(a.noteId,{id:a.noteId,title:a.noteTitle||a.noteId,to:H1(a.noteId)}),i.size>=n))break;return[...i.values()]}function Y1(e,t,n){if(t.length===0)return[];let r=e.filter(e=>e.id!==n&&!!e.sourceId&&t.some(t=>e.sourceId===t||e.sourceId.startsWith(`${t}#`)));return r.sort((e,t)=>t.createdAt-e.createdAt),r.map(e=>({id:e.id,title:e.title||e.id,to:H1(e.id)}))}function X1(e,t){let n=new Map;for(let r of e)r.noteId===t||n.has(r.noteId)||n.set(r.noteId,{id:r.noteId,title:r.noteId,to:H1(r.noteId)});return[...n.values()]}function Z1({noteId:e,stamps:t,effortSlug:n}){let r=t.join(`
165
+ `),[i,a]=(0,U.useState)({key:``,data:U1}),o=`${e}\u0000${r}\u0000${n??``}`,s=i.key===o?i.data:U1;return(0,U.useEffect)(()=>{let t=!1,i=r?r.split(`
166
+ `):[];return Promise.all([Z.getAllFromIndex(`block_efforts`,`by-note`,e),Z.getAllFromIndex(`block_index`,`by-note`,e),Z.getAllNotes(),Z.getAllEfforts(),n?Z.getAllFromIndex(`block_efforts`,`by-effort`,n):Promise.resolve([])]).then(async([r,a,o,s,c])=>{if(t)return U1;let l=new Set(s.map(e=>e.slug)),u=[...new Set(a.filter(e=>e.dataType===`wod`&&e.blockContentId).map(e=>e.blockContentId))],d=await Promise.all(u.map(e=>Z.getAllFromIndex(`block_index`,`by-content`,e)));if(t)return U1;let f=J1([...a,...d.flat()],e);if(n){let t=new Set(f.map(e=>e.id));for(let n of X1(c,e))t.has(n.id)||(t.add(n.id),f.push(n))}return{efforts:q1(r,l),related:f,backlinks:Y1(o,i,e)}}).then(e=>{!t&&e&&a({key:o,data:e})}).catch(()=>{}),()=>{t=!0}},[e,r,n,o]),s}function Q1({data:e,up:t,source:n,relatedLabel:r=`Related workouts`}){let{setContextNav:i}=WM(),a=Sn();return(0,U.useEffect)(()=>{let o=[],s=(e,t,n)=>{n.length!==0&&o.push({kind:`section`,id:e,label:t,entries:n.map(t=>({kind:`link`,id:`${e}:${t.id}`,label:t.title,to:t.to}))})};return s(`note-context-up`,`Up`,t?[t]:[]),s(`note-context-source`,`Source`,n?[n]:[]),s(`note-context-efforts`,`Efforts`,e.efforts),s(`note-context-backlinks`,`Journal copies`,e.backlinks),s(`note-context-related`,r,e.related),i({pathname:a.pathname,spec:o}),()=>i(void 0)},[e,t,n,r,a.pathname,i]),null}function $1(e,t){return(0,U.useMemo)(()=>{let n=[];return t.onPlay&&(e===`playground`||e===`journal-active`||e===`notebook-readonly`)&&n.push({id:`play`,label:`Play`,icon:(0,W.jsx)(rn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:t.onPlay}),t.onLog&&(e===`playground`||e===`journal-active`||e===`notebook-readonly`)&&n.push({id:`log`,label:`Log`,icon:(0,W.jsx)(Be,{className:`h-3 w-3`}),primary:!0,onClick:t.onLog}),t.onOpenInPlayground&&(e===`journal-plan`||e===`notebook-readonly`)&&n.push({id:`open-in-playground`,label:`Playground`,icon:(0,W.jsx)(o,{className:`h-3 w-3`}),onClick:t.onOpenInPlayground}),t.onShare&&n.push({id:`share`,label:`Share`,icon:(0,W.jsx)(_,{className:`h-3 w-3`}),onClick:t.onShare}),t.onAddToToday&&e===`playground`&&n.push({id:`add-to-today`,label:`Today`,icon:(0,W.jsx)(ve,{className:`h-3 w-3`}),onClick:t.onAddToToday}),t.onSchedule&&n.push({id:`schedule`,label:`Schedule`,icon:(0,W.jsx)(ke,{className:`h-3 w-3`}),onClick:t.onSchedule}),n},[e,t.onPlay,t.onLog,t.onShare,t.onAddToToday,t.onSchedule,t.onOpenInPlayground])}async function e0(e){let t=new TextEncoder().encode(e),n=new CompressionStream(`gzip`),r=n.writable.getWriter(),i=n.readable.getReader();r.write(t),r.close();let a=[];for(;;){let{done:e,value:t}=await i.read();if(e)break;a.push(t)}let o=a.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.length;let l=``;for(let e=0;e<s.length;e++)l+=String.fromCharCode(s[e]);return btoa(l).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}async function t0(e,t){let n=e.dialect||`time`,r=await e0(`\`\`\`${e.sport?`${n}:${e.sport}`:n}\n${e.content.trimEnd()}\n\`\`\`\n`),i=`${window.location.origin}${kN({zip:r})}`;return t?`${i}&src=${encodeURIComponent(t)}`:i}async function n0(e,t){let n=await t0(e,window.location.pathname),{pathname:r,search:i}=new URL(n);t(`${r}${i}`)}async function r0(e){let t=await t0(e,window.location.pathname);window.open(t,`_blank`)}async function i0(e){let t=e.dialect||`time`,n=await e0(`\`\`\`${e.sport?`${t}:${e.sport}`:t}\n${e.content.trimEnd()}\n\`\`\`\n`),r=`shared by ${vx()}`;return`${window.location.origin}/?z=${n}&by=${encodeURIComponent(r)}`}function a0(e){i0(e).then(e=>{navigator.clipboard.writeText(e).then(()=>{Q({title:`Link copied`,description:`Share link copied to clipboard.`})}).catch(()=>{Q({title:`Could not copy`,description:e,variant:`destructive`})})})}function o0(e=`end`){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(e);return{triggerRef:t,align:n,recompute:(0,U.useCallback)(()=>{let e=t.current;if(!e)return;let{left:n,right:i}=e.getBoundingClientRect(),a=(n+i)/2;r(a>window.innerWidth/2?`end`:`start`)},[])}}function s0(e,t){if(t){t();return}let n=new Blob([e.content],{type:`text/markdown`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.name.replace(/[/\\:*?"<>|]/g,`-`)}.md`,i.click(),URL.revokeObjectURL(r)}function c0({currentWorkout:e,onDownload:t}){return e.content===``?null:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>s0(e,t),className:`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px] text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground`,children:[(0,W.jsx)(Be,{className:`size-4 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`Download Markdown`})]})}function l0(e,t,n){let r=Vn(),{l3Items:i,scrollToSection:a,secondarySpec:o,streamControls:s}=WM(),c=t&&t.length>0?t:i,l=Wz(o),u=[];s&&u.push({kind:`custom`,id:`l3-stream-controls`,nav:!0,render:()=>(0,W.jsx)(vV,{streamControls:s})});for(let e of l)if(e.kind===`section`){if(e.entries.length===0)continue;u.push({kind:`heading`,id:e.id,label:e.label,nav:!0});for(let t of e.entries)u.push({kind:`row`,id:t.id,label:t.label,nav:!0,onSelect:()=>{t.onRun?t.onRun():t.to?r(t.to):t.sectionId&&a(t.sectionId)}})}else u.push({kind:`row`,id:e.id,label:e.label,nav:!0,onSelect:()=>{e.onRun?e.onRun():e.to?r(e.to):e.sectionId&&a(e.sectionId)}});if(c.length>0){u.push({kind:`heading`,id:`on-this-page`,label:`On this page`,nav:!0});for(let e of c)u.push({kind:`row`,id:e.id,label:e.label,nav:!0,secondary:e.secondaryAction?{label:e.secondaryAction.label,icon:e.secondaryAction.icon&&(0,W.jsx)(e.secondaryAction.icon,{className:`size-3.5`}),onSelect:()=>{e.secondaryAction?.action.type===`call`&&e.secondaryAction.action.handler()}}:void 0,onSelect:()=>{e.action.type===`call`?e.action.handler():a(e.id)}})}return e.content!==``&&u.push({kind:`row`,id:`download-markdown`,label:`Download Markdown`,icon:(0,W.jsx)(Be,{className:`size-4`}),nav:!1,onSelect:()=>s0(e,n)}),u}function u0({currentWorkout:e,onDownload:t,items:n}){let r=l0(e,n,t),i=e=>e.kind===`heading`?(0,W.jsx)(rV,{children:e.label},e.id):e.kind===`custom`?(0,W.jsx)(`div`,{className:`px-1 py-1`,children:e.render()},e.id):(0,W.jsxs)(eV,{onClick:e.onSelect,className:`gap-2`,children:[e.icon,(0,W.jsx)(`span`,{className:G(`flex-1 truncate`,e.secondary&&`pr-8`),children:e.label}),e.secondary&&(0,W.jsx)(`button`,{className:`ml-auto flex items-center justify-center size-5 rounded text-primary hover:bg-primary/10 transition-colors`,title:e.secondary.label,onClick:t=>{t.stopPropagation(),e.secondary?.onSelect()},children:e.secondary.icon})]},e.id),a=r.filter(e=>e.nav),o=r.filter(e=>!e.nav);return r.length===0?null:(0,W.jsxs)(ZB,{children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsxs)(K,{variant:`ghost`,size:`icon`,"aria-label":`Page options`,className:G(`text-muted-foreground`,`2xl:hidden`),children:[(0,W.jsx)(he,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Page options`})]})}),(0,W.jsxs)($B,{align:`end`,className:`min-w-56 max-h-[calc(100dvh-6rem)] overflow-y-auto`,children:[a.length>0&&(0,W.jsxs)(`div`,{className:`2xl:hidden`,children:[a.map(i),(0,W.jsx)(nV,{})]}),o.map(i)]})]})}var d0=xU("# My Workout\n\n```time\n$CURSOR\n```\n"),f0={content:d0.content,cursorOffset:d0.cursorOffset};function p0({mode:e,currentWorkout:t,index:n,onReset:r}){let i=Vn(),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(!1),l=LV(),u=TV(),d=l&&u;return d&&e!==`playground`?null:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e===`playground`&&(0,W.jsx)(ZJ,{primary:{id:`new-playground`,label:a?`Creating…`:`New`,icon:ve,action:{type:`call`,handler:async()=>{if(!a){o(!0);try{let e=await bq(f0.content);i(`/playground/${encodeURIComponent(e)}`)}finally{o(!1)}}}}},secondary:{id:`reset-playground`,label:s?`Resetting…`:`Reset to default`,icon:We,action:{type:`call`,handler:async()=>{if(!(!r||s)){c(!0);try{await r()}finally{c(!1)}}}}},size:`sm`}),!d&&(0,W.jsx)(vH,{}),!d&&(0,W.jsx)(wZ,{}),!d&&(0,W.jsx)(u0,{currentWorkout:t,items:n&&n.length>0?wU(n):void 0})]})}function m0({slug:e,itemDate:t,item:n,theme:r,onViewCreated:i}){let a=Vn(),o=YO(),s=(0,U.useMemo)(()=>{if(o)return MO(OO(o).find(t=>t.id===e),t,n)},[o,e,t,n]),{content:c,noteBlocks:l,sourceRevision:u,onIdentityChange:d,onSaved:f,onChange:p,onLineChange:m,onBlur:h,flush:g}=A1({category:`notebook/${e}/${t}`,name:n,mdContent:s?.content??`# ${n}\n\n*Notebook item not found.*\n`,seedOnMount:!1}),[_,v]=(0,U.useState)([]),y=`notebook/${e}/${t}/${n}`,b=`/notebook/${encodeURIComponent(e)}/${t}/${encodeURIComponent(n)}`,x=(0,U.useCallback)(async t=>{try{let r=w(),i=await j1({workoutName:s?.name??n,category:e,sourceNoteLabel:e,sourceNotePath:b,wodContent:t.content}),o=Object.values(i.blocks??{}).find(e=>e.kind===`wod`);if(!o)throw Error(`The saved journal workout is unavailable.`);M1.set(r,{block:{...t,id:o.id},noteId:i.id}),a(wN(i.journalDate??``,r))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}},[e,n,b,s,a]),S=(0,U.useCallback)(async t=>{try{let r=await j1({workoutName:s?.name??n,category:e,sourceNoteLabel:e,sourceNotePath:b,wodContent:t.content}),i=Ly(new Date);Q({title:`Added to journal`,description:r.journalDate===i?`Added to today's journal`:`Added to ${r.journalDate}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>a(CN(r.journalDate??i)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not add to journal`,variant:`destructive`})}},[e,n,b,s,a]),[C,T]=(0,U.useState)(null),E=(0,U.useCallback)(async(t,r)=>{let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`;try{await j1({workoutName:s?.name??n,category:e,sourceNoteLabel:e,sourceNotePath:b,wodContent:t.content,date:r}),a(CN(i)),Q({title:`Scheduled`,description:`Added to journal for ${i}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>a(CN(i)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not schedule workout`,variant:`destructive`})}},[e,n,b,s,a]),D=B1({content:c,scriptBlocks:_,onStartWorkout:x}),O=`notebook/${e}/${t}/${n}`,k=(0,U.useMemo)(()=>G1({id:O,type:`note`}),[O]),A=Z1({noteId:O,stamps:k.stamps}),j=$1(`notebook-readonly`,{onPlay:x,onShare:a0,onAddToToday:S,onSchedule:T,onOpenInPlayground:e=>n0(e,a)});return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(KB,{title:s?.name??n,actions:(0,W.jsx)(RV,{label:`Workout actions`,children:(0,W.jsx)(p0,{mode:`notebook-readonly`,currentWorkout:{name:s?.name??n,content:c},index:D})}),editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-6 sm:px-6`,children:[(0,W.jsx)(Q1,{data:A,up:k.up}),(0,W.jsx)(YZ,{value:c,onChange:p,onCursorPositionChange:m,onBlur:h,noteId:y,noteBlocks:l,sourceRevision:u,onIdentityChange:e=>d({rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision}),onSaved:f,onSaveRequest:g,onCommitChange:g,commands:j,enableInlineRuntime:!1,onViewCreated:i,theme:r,showLineNumbers:!1,onBlocksChange:v})]})}),C&&(0,W.jsx)(OC,{open:!0,onClose:()=>T(null),title:`Schedule workout`,children:(0,W.jsx)(D1,{selectedDate:null,onDateSelect:e=>{E(C,e),T(null)}})})]})}var h0=`---
164
167
  search: hidden
165
168
  template: canvas
166
169
  route: /
@@ -347,7 +350,7 @@ label: Run the First Example
347
350
  validation:
348
351
  type: run-started
349
352
  \`\`\`
350
- `,i1=`---
353
+ `,g0=`---
351
354
  search: hidden
352
355
  title: "Welcome"
353
356
  subtitle: "Edit this, then hit Run"
@@ -359,7 +362,7 @@ Below is a time block, give it a try and click "Run" and see the timer come to l
359
362
  \`\`\`time
360
363
  0:03 Count Down
361
364
  // click "Next"
362
- \`\`\``,a1=`---
365
+ \`\`\``,_0=`---
363
366
  search: hidden
364
367
  title: "Single Movement"
365
368
  subtitle: "The smallest valid workout line"
@@ -369,7 +372,7 @@ order: 2
369
372
  \`\`\`time
370
373
  Pushups
371
374
  \`\`\`
372
- `,o1=`---
375
+ `,v0=`---
373
376
  search: hidden
374
377
  title: "Timers and Rest"
375
378
  subtitle: "Countdowns, movement lines, and forced rest"
@@ -381,7 +384,7 @@ order: 6
381
384
  *:30 Rest
382
385
  10 Burpees
383
386
  \`\`\`
384
- `,s1=`---
387
+ `,y0=`---
385
388
  search: hidden
386
389
  title: "Simple Rounds"
387
390
  subtitle: "Parentheses repeat everything inside"
@@ -394,7 +397,7 @@ order: 1
394
397
  15 Situps
395
398
  20 Air Squats
396
399
  \`\`\`
397
- `,c1=`---
400
+ `,b0=`---
398
401
  search: hidden
399
402
  title: "Intensity"
400
403
  subtitle: "Attach a percentage or scale to any movement"
@@ -404,7 +407,7 @@ order: 1
404
407
  \`\`\`time
405
408
  5 Back Squat 225lb {"intensity": 80}
406
409
  \`\`\`
407
- `,l1=`---
410
+ `,x0=`---
408
411
  search: hidden
409
412
  title: "Dialect: Climb Bouldering"
410
413
  ---
@@ -423,7 +426,7 @@ energy: 7
423
426
  (Project)
424
427
  [The Shield] V7 redpoint @12 // engage core before crux reach
425
428
  \`\`\`
426
- `,u1=`---
429
+ `,S0=`---
427
430
  search: hidden
428
431
  title: "Swimming Intervals"
429
432
  subtitle: "Multi-set swimming intervals with rest recovery"
@@ -442,28 +445,25 @@ domain: swimming
442
445
 
443
446
  150m Cooldown
444
447
  \`\`\`
445
- `,d1=BL(r1);if(!d1)throw Error(`The baked home page must remain a valid canvas document`);var f1=d1,p1={"markdown/canvas/home/welcome-1.md":i1,"markdown/canvas/syntax/single-movement.md":a1,"markdown/canvas/syntax/timers-rest.md":o1,"markdown/canvas/syntax/groups-1.md":s1,"markdown/canvas/syntax/custom-metrics-1.md":c1,"markdown/canvas/syntax/dialect-climb-bouldering.md":l1,"markdown/canvas/syntax/complex-swimming.md":u1};function m1(e){return{...p1,...e}}var h1={"workout-complete":!0,"run-started":!0};function g1(e,t,n){let{markComplete:r}=Nq(e,t),i=(0,U.useRef)(new Set);i.current=new Set(t.filter(e=>!e.validation||!h1[e.validation.type]).map(e=>e.id));let a=(0,U.useRef)({}),o={};for(let e of n)e.quest&&(o[e.id]=e.quest);return a.current=o,(0,U.useCallback)(e=>{let t=a.current[e];t&&i.current.has(t)&&r(t)},[r])}function _1(){let e=Iq(`(prefers-reduced-motion: reduce)`),t=Iq(`(max-width: ${bV}px)`);return e?`reduced`:t?`mobile`:`desktop`}var v1=.25;function y1({sourcesByStageId:e,doc:t,setDoc:n,subscribe:r,enabled:i}){let[a,o]=(0,U.useState)(!1),s=(0,U.useRef)(t),c=(0,U.useRef)(null),l=(0,U.useRef)(t),u=(0,U.useRef)(a),d=(0,U.useRef)(``),f=(0,U.useRef)(null),p=(0,U.useRef)(!1);return l.current=t,u.current=a,(0,U.useEffect)(()=>{let e=d.current;if(c.current!==null){if(t===c.current){s.current=t,c.current=null;return}if(t!==s.current){o(!0);return}}t!==s.current&&t!==e&&o(!0)},[t]),(0,U.useEffect)(()=>{if(!i){c.current=null;return}let t=r(t=>{if(t.stage.id!==f.current&&(f.current=t.stage.id,d.current=e[t.stage.id]??``,s.current=``,c.current=null,o(!1),p.current=!0),u.current||c.current!==null)return;let r=d.current;if(!r)return;let i=t.index===0?r.length:Math.floor(cQ(oQ(t.t/v1))*r.length),a=r.slice(0,i),m=l.current;p.current=!1,a!==m&&(c.current=a,n(a))});return()=>{t()}},[i,e,n,r]),{userDiverged:a,complete:(0,U.useCallback)(()=>{if(u.current)return;let e=d.current;e&&(c.current=e,n(e))},[n])}}function b1({stages:e,activeIndex:t}){return(0,W.jsx)(`div`,{className:`relative h-full w-full`,"data-testid":`scroll-captions`,children:e.map((n,r)=>(0,W.jsxs)(`div`,{className:`absolute inset-0 overflow-y-auto transition-opacity duration-300`,style:{opacity:+(r===t)},"aria-hidden":r!==t,inert:r!==t,children:[(0,W.jsxs)(`div`,{className:`font-mono text-[11px] uppercase tracking-[0.22em]`,style:{color:n.accent??`hsl(var(--muted-foreground))`},children:[String(r+1).padStart(2,`0`),` / `,String(e.length).padStart(2,`0`)]}),(0,W.jsx)(`h3`,{className:`mt-3 text-2xl font-bold tracking-tight text-foreground`,children:n.id.replace(/-/g,` `)}),n.caption&&(0,W.jsx)(t$,{prose:n.caption,className:`mt-3 text-sm text-muted-foreground`})]},n.id))})}var x1=(0,U.forwardRef)(function({text:e,accent:t},n){let r=t??`hsl(var(--metric-rounds))`;return(0,W.jsxs)(`div`,{ref:n,className:`pointer-events-none absolute top-4 left-1/2 z-40 flex -translate-x-1/2 items-center gap-2.5 whitespace-nowrap rounded-full border bg-card px-5 py-2.5 font-mono text-[10.5px] tracking-[0.04em] opacity-0 shadow-xl`,style:{borderColor:`color-mix(in srgb, ${r} 55%, transparent)`},children:[(0,W.jsx)(`span`,{className:`size-[9px] rounded-sm`,style:{background:r}}),e]})}),S1=8,C1=3,w1=2;function T1(e,t,n){let r=e.querySelectorAll(`.cm-content .cm-line`),i=Math.max(1,Math.min(n[0],n[1]))-1,a=Math.max(1,Math.max(n[0],n[1])),o=Array.from(r).slice(i,a);if(o.length===0)return null;let s=e.getBoundingClientRect(),c=1/0,l=1/0,u=-1/0,d=-1/0;for(let e of o){let t=e.getBoundingClientRect();c=Math.min(c,t.top),l=Math.min(l,t.left),u=Math.max(u,t.bottom),d=Math.max(d,t.right)}return c-=C1,l-=S1,u+=C1,d+=S1,t&&(l=Math.max(l,t.left-w1),d=Math.min(d,t.right+w1),c=Math.max(c,t.top-w1),u=Math.min(u,t.bottom+w1)),{top:c-s.top,left:l-s.left,width:d-l,height:u-c}}function E1(e,t){if(!t)return null;let n=t.getBoundingClientRect();if(n.width===0||n.height===0)return null;let r=e.getBoundingClientRect();return{top:n.top-r.top-w1,left:n.left-r.left-w1,width:n.width+4,height:n.height+4}}function D1({accent:e,lines:t}){let n=e??`hsl(var(--foreground))`,r=(0,U.useRef)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(!1);return(0,U.useLayoutEffect)(()=>{let e=r.current;if(!e)return;let n=requestAnimationFrame(()=>s(!0)),i=e.parentElement;if(!i)return()=>cancelAnimationFrame(n);let o=()=>{let e=i.firstElementChild,n=e?.getBoundingClientRect()??null;a((t?T1(i,n,t):null)??E1(i,e))};o();let c=new ResizeObserver(o);return c.observe(i),()=>{cancelAnimationFrame(n),c.disconnect()}},[t]),(0,W.jsx)(`div`,{ref:r,className:`pointer-events-none absolute z-30 transition-all duration-300 ${i?t?`rounded-lg`:`rounded-2xl`:`-inset-1.5 rounded-2xl`}`,style:{boxShadow:`0 0 0 2px ${n}`,opacity:+!!o,...i??{}},"data-testid":`scroll-ring`,"data-ring-lines":t?`${t[0]}-${t[1]}`:void 0})}function O1({scroll:e,wodFiles:t,theme:n,noteTitle:r=`note.md`,showFrontmatter:i,doc:a,onDocChange:o,onBlocksChange:s,onStageEnter:c,onRun:l,className:u}){let d=e.stages,f=(0,U.useRef)(null),p=(0,U.useRef)(null),m=(0,U.useRef)(null),h=(0,U.useRef)(new Set),g=(0,U.useMemo)(()=>Object.fromEntries(d.map(e=>[e.id,e.source?SV(e.source,t):``])),[d,t]),[_,v]=(0,U.useState)(()=>g[d[0]?.id]??``),y=a??_,b=o??v,[x,S]=(0,U.useState)(!1),{slice:C,subscribe:w,resync:T}=SQ(f,x,d),[E,D]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=f.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&D(!0)},{rootMargin:`100px`});return t.observe(e),()=>t.disconnect()},[]);let{userDiverged:O}=y1({sourcesByStageId:g,doc:y,setDoc:b,subscribe:w,enabled:!x&&e.typewriter}),k=C.stage.id,A=lQ(g[k]??``,y);(0,U.useEffect)(()=>{!x&&E&&c?.(k)},[x,k,E,c]),(0,U.useEffect)(()=>{if(!x){let e=requestAnimationFrame(T);return()=>cancelAnimationFrame(e)}},[x,T]),(0,U.useEffect)(()=>{let e=requestAnimationFrame(T);return()=>cancelAnimationFrame(e)},[k,T]),(0,U.useEffect)(()=>{O&&S(!0)},[O]),(0,U.useEffect)(()=>{let e=d.flatMap(e=>e.effects??[]);return w(t=>{let n=m.current;if(n){let e=oQ((t.t-.04)/.12),r=oQ((t.t-.5)/.2);n.style.opacity=String(Math.max(0,e-r)),n.style.transform=`translateX(-50%) translateY(${sQ(-14,0,e)}px)`}let r=p.current;if(!r)return;let i=new Set;for(let n of e){if(!n.stages.includes(t.stage.id))continue;i.add(n.target);let[e,a]=n.in??[0,1],o=a>e?oQ((t.t-e)/(a-e)):1,s=n.ease===`linear`?o:cQ(o);r.querySelectorAll(`[data-effect-target="${n.target}"]`).forEach(e=>{n.opacity&&(e.style.opacity=String(sQ(n.opacity[0],n.opacity[1],s))),n.translateY&&(e.style.transform=`translateY(${sQ(n.translateY[0],n.translateY[1],s)}px)`)})}for(let e of h.current)i.has(e)||r.querySelectorAll(`[data-effect-target="${e}"]`).forEach(e=>{e.style.opacity=``,e.style.transform=``});h.current=i})},[w,d]);let j=C.stage.accent??`hsl(var(--foreground))`;return(0,W.jsxs)(`div`,{ref:p,className:u,"data-testid":`scroll-runway-section`,children:[(0,W.jsx)(yQ,{trackRef:f,height:e.runway,stages:d,activeIndex:C.index,status:(0,W.jsx)(`div`,{className:`truncate font-mono text-[11px] uppercase tracking-[0.22em] text-muted-foreground`,children:x?`Playground mode`:C.stage.id.replace(/-/g,` `)}),pane:(0,W.jsxs)(`div`,{className:`absolute inset-0`,children:[(0,W.jsx)(nQ,{title:r??``,noteId:`canvas:scroll-runway`,doc:y,onDocChange:b,onBlocksChange:s,theme:n,showFrontmatter:i,run:l?{onRun:l}:void 0,className:`absolute inset-x-2 top-2 bottom-2`,children:C.stage.toast&&(0,W.jsx)(x1,{ref:m,text:C.stage.toast,accent:j})}),C.ring&&!x&&A&&(0,W.jsx)(D1,{accent:j,lines:C.ring.lines})]}),captions:(0,W.jsx)(b1,{stages:d,activeIndex:C.index})}),x&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>S(!1),className:`fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded-full bg-foreground px-5 py-2.5 font-mono text-[10px] tracking-[0.06em] text-background opacity-95 transition-opacity hover:opacity-100`,children:[`▶ Playground mode — `,O?`your edits are kept`:`editing`,` · tap here to return to the tour`]})]})}function k1({spec:e,wodFiles:t,onStageEnter:n,className:r}){let i=e.stages,a=(0,U.useMemo)(()=>Object.fromEntries(i.map(e=>[e.id,e.source?SV(e.source,t):``])),[i,t]),o=(0,U.useRef)(null);return(0,U.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;let e=o.current;if(!e)return;let t=new IntersectionObserver(e=>{for(let r of e){if(!r.isIntersecting)continue;let e=r.target.dataset.cardId;e&&(n?.(e),t.unobserve(r.target))}},{threshold:.4});return e.querySelectorAll(`[data-card-id]`).forEach(e=>t.observe(e)),()=>t.disconnect()},[n]),(0,W.jsx)(`section`,{className:r,"data-testid":`runway-reduced`,children:(0,W.jsx)(`div`,{className:`px-6 pt-4 pb-24`,children:(0,W.jsx)(`div`,{ref:o,className:`mx-auto max-w-2xl`,children:i.map((e,t)=>(0,W.jsxs)(`article`,{"data-card-id":e.id,className:`mb-6 rounded-2xl border border-border bg-card p-7`,children:[(0,W.jsxs)(`div`,{className:`font-mono text-[11px] uppercase tracking-[0.22em]`,style:{color:e.accent??`hsl(var(--muted-foreground))`},children:[String(t+1).padStart(2,`0`),` / `,String(i.length).padStart(2,`0`)]}),(0,W.jsx)(`h3`,{className:`mt-3 text-2xl font-bold tracking-tight text-foreground`,children:e.id.replace(/-/g,` `)}),e.caption&&(0,W.jsx)(t$,{prose:e.caption,className:`mt-3 text-sm text-muted-foreground`}),a[e.id]&&(0,W.jsx)(`pre`,{className:`mt-5 overflow-x-auto rounded-lg bg-background px-4 py-4 font-mono text-[12px] tracking-[0.04em] text-muted-foreground`,children:a[e.id]})]},e.id))})})})}function A1(){return _1()}function j1({spec:e,formFactor:t,wodFiles:n,theme:r,noteTitle:i,showFrontmatter:a,doc:o,onDocChange:s,onBlocksChange:c,onStageEnter:l,onRun:u,className:d}){let f=A1();return(t??f)===`reduced`?(0,W.jsx)(k1,{spec:e,wodFiles:n,onStageEnter:l,className:d}):(0,W.jsx)(O1,{scroll:e,wodFiles:n,theme:r,noteTitle:i,showFrontmatter:a,doc:o,onDocChange:s,onBlocksChange:c,onStageEnter:l,onRun:u,className:d})}function M1({page:e,wodFiles:t,theme:n,onScrollToSection:r}){let i=e.scroll,a=i.stages,o=Vn();hq(e.type===`guide`||e.route.startsWith(`/page/guide-`)?e.route:void 0);let s=(0,U.useMemo)(()=>Object.fromEntries(a.map(e=>[e.id,e.source?SV(e.source,t):``])),[a,t]),[c,l]=(0,U.useState)(()=>s[a[0]?.id]??``),u=(0,U.useRef)([]),[d,f]=(0,U.useState)(null),p=g1(e.route,e.quests,a),m=(0,U.useCallback)(()=>u.current[0]??null,[]),h=wq({getBlock:m,getContent:(0,U.useCallback)(()=>c,[c]),title:e.frontmatter.title}),{startRun:g}=h,_=zB(104),v=t1({pageRoute:e.route,quests:e.quests,block:d});Pq({pageRoute:e.route,quests:e.quests,completedResults:h.completedResults});let[,y]=Kt(`h`,{history:`replace`,shallow:!0}),b=(0,U.useMemo)(()=>({navigate:(e,t)=>o(e,{replace:t?.replace}),setQueryParam:(e,t)=>{let n=e.h;n!==void 0&&y(n,{history:t?`replace`:`push`})},swapSource:e=>l(SV(e,t)),setPanelState:e=>{if(e===`track`){let e=m();e&&g(e)}}}),[o,y,t,m,g]),x=(0,U.useCallback)((e,n)=>{let r=e.examples?.[n];r?.source&&l(SV(r.source,t))},[t]),S=(0,U.useCallback)(e=>{let t=e[0]??null;u.current=e,f(e=>e?.content===t?.content&&e?.id===t?.id?e:t)},[]),C=(0,U.useCallback)((e,t)=>{t&&g(t,e)},[g]),w=`${e.route.split(`/`).pop()??`note`}.md`,T=e.sections.slice(1).map((e,t)=>(0,W.jsx)(b$,{section:e,idx:t,blockId:e.id,keySuffix:`scroll`,isActive:!1,hasViewDef:!1,deps:b,onExampleSelect:x,selectedExampleIndex:0,challengeQuests:v.quests,onScrollToSection:r},e.id));return(0,W.jsxs)(`div`,{className:`flex flex-col min-h-screen bg-background`,"data-testid":`scroll-canvas-page`,children:[h.fullscreen?.kind===`timer`&&(0,W.jsx)(`div`,{className:`sticky z-30 border-b border-border bg-background`,style:{top:_},children:(0,W.jsx)(`div`,{className:`mx-auto h-[max(320px,min(75vh,640px))] max-w-5xl px-4 py-2`,children:(0,W.jsx)(rq,{block:h.fullscreen.block,onClose:h.closeRun,autoStart:!0,externalStop:h.resetRequested,onComplete:(e,t)=>{h.handleWorkoutComplete(t)}})})}),(0,W.jsx)(j1,{spec:i,wodFiles:t,theme:n,noteTitle:w,showFrontmatter:e.frontmatter.showFrontmatter===!0,doc:c,onDocChange:l,onBlocksChange:S,onStageEnter:p,onRun:C}),T]})}function N1({feedSlug:e}){let t=(0,U.useMemo)(()=>xA(e),[e]),n=(0,U.useMemo)(()=>t?OA(t.id):[],[t]);return t?(0,W.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-2xl px-4 py-10 sm:px-6 flex flex-col gap-6`,children:[(0,W.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,W.jsx)(`h1`,{className:`text-2xl font-bold`,children:t.label}),t.description?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t.description}):null,(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 text-xs text-muted-foreground/80`,children:[(0,W.jsxs)(`a`,{href:t.url,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 hover:text-foreground`,children:[(0,W.jsx)(A,{className:`size-3`}),`Published directory`]}),t.repositoryUrl?(0,W.jsxs)(`a`,{href:t.repositoryUrl,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 hover:text-foreground`,children:[(0,W.jsx)(A,{className:`size-3`}),`Repository`]}):null]})]}),(0,W.jsxs)(`section`,{className:`flex flex-col gap-3`,children:[(0,W.jsx)(`h2`,{className:`text-xs font-bold uppercase tracking-widest text-muted-foreground/70`,children:`Notebooks`}),n.length===0?(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This feed publishes no notebooks.`}):(0,W.jsx)(`ul`,{className:`flex flex-col divide-y divide-border rounded-md border border-border bg-card`,children:n.map(e=>(0,W.jsx)(`li`,{children:(0,W.jsxs)(_n,{to:EN(e.id),className:`flex items-center gap-3 px-4 py-3 hover:bg-accent/40`,children:[(0,W.jsx)(s,{className:`size-4 shrink-0 text-muted-foreground`}),(0,W.jsxs)(`span`,{className:`flex min-w-0 flex-col`,children:[(0,W.jsx)(`span`,{className:`truncate text-sm font-semibold`,children:e.label}),e.description?(0,W.jsx)(`span`,{className:`truncate text-xs text-muted-foreground`,children:e.description}):null]})]})},e.id))})]})]})}):(0,W.jsxs)(`div`,{className:`flex flex-1 items-center justify-center p-20 text-sm text-muted-foreground`,children:[`Feed not found: `,e]})}var P1=[`Mo`,`Tu`,`We`,`Th`,`Fr`,`Sa`,`Su`];function F1(e,t){return new Date(e,t+1,0).getDate()}function I1(e,t){let n=new Date(e,t,1).getDay();return n===0?6:n-1}function L1(e,t,n){return`${e}-${String(t+1).padStart(2,`0`)}-${String(n).padStart(2,`0`)}`}function R1(e){return L1(e.getFullYear(),e.getMonth(),e.getDate())}var z1=({selectedDate:e,onDateSelect:t,entryDates:n=new Set,disabled:r=!1,className:i})=>{let[a,o]=(0,U.useState)(()=>e||new Date),s=a.getFullYear(),c=a.getMonth();(0,U.useEffect)(()=>{e&&o(t=>t.getFullYear()!==e.getFullYear()||t.getMonth()!==e.getMonth()?new Date(e.getFullYear(),e.getMonth(),1):t)},[e]);let l=e?R1(e):null,u=(0,U.useMemo)(()=>{let e=F1(s,c),t=I1(s,c),n=[];for(let e=0;e<t;e++)n.push(null);for(let t=1;t<=e;t++)n.push(t);return n},[s,c]),d=e=>{e.stopPropagation(),e.preventDefault(),o(new Date(s,c-1,1))},f=e=>{e.stopPropagation(),e.preventDefault(),o(new Date(s,c+1,1))},p=a.toLocaleDateString(`en-US`,{month:`short`,year:`numeric`}),m=R1(new Date);return(0,W.jsxs)(`div`,{className:G(`select-none px-2 py-2`,r&&`opacity-60 cursor-not-allowed`,i),onClick:e=>e.stopPropagation(),"aria-disabled":r||void 0,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`button`,{onClick:d,disabled:r,className:`p-1 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none`,"aria-label":`Previous month`,children:(0,W.jsx)(Un,{className:`h-4 w-4`})}),(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:p}),(0,W.jsx)(`button`,{onClick:f,disabled:r,className:`p-1 hover:bg-muted rounded text-muted-foreground hover:text-foreground transition-colors disabled:pointer-events-none`,"aria-label":`Next month`,children:(0,W.jsx)(wn,{className:`h-4 w-4`})})]}),(0,W.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5 mb-1`,children:P1.map(e=>(0,W.jsx)(`div`,{className:`text-center text-[10px] text-muted-foreground font-medium py-0.5 w-8`,children:e},e))}),(0,W.jsx)(`div`,{className:`grid grid-cols-7 gap-0.5`,children:u.map((e,i)=>{if(e===null)return(0,W.jsx)(`div`,{className:`w-8 h-8`},`empty-${i}`);let a=L1(s,c,e),o=n.has(a),u=a===l;return(0,W.jsxs)(`button`,{disabled:r,onClick:n=>{n.stopPropagation(),n.preventDefault(),t(new Date(s,c,e),n.ctrlKey||n.metaKey)},className:G(`w-8 h-8 flex items-center justify-center rounded text-xs transition-colors relative`,`disabled:pointer-events-none`,u?`bg-primary text-primary-foreground font-bold`:a===m?`font-bold text-primary ring-1 ring-primary/40`:o?`font-semibold text-foreground hover:bg-muted`:`text-muted-foreground hover:bg-muted/50`),"aria-label":`${e} ${p}${o?` (has entries)`:``}`,children:[e,o&&!u&&(0,W.jsx)(`span`,{className:`absolute bottom-0.5 left-1/2 -translate-x-1/2 w-1 h-1 rounded-full bg-primary/60`})]},a)})})]})};function B1({onSave:e,getSnapshotKey:t,onError:n}){let r=(0,U.useRef)(null),i=(0,U.useRef)(null),a=(0,U.useRef)(null),o=(0,U.useRef)(Promise.resolve()),s=(0,U.useRef)({onSave:e,getSnapshotKey:t,onError:n});s.current={onSave:e,getSnapshotKey:t,onError:n};let[c,l]=(0,U.useState)(null),u=(0,U.useCallback)(e=>{let t=o.current.then(async()=>{e.key!==i.current&&(await s.current.onSave(e.value),i.current=e.key,l(null))});return o.current=t.catch(e=>{l(e),s.current.onError?.(e)}),t},[]),d=(0,U.useCallback)(()=>r.current?u(r.current):o.current,[u]),f=(0,U.useCallback)(e=>{let t=s.current.getSnapshotKey?.(e)??(typeof e==`string`?e:JSON.stringify(e));r.current={value:e,key:t}},[]),p=(0,U.useCallback)((e,t)=>{a.current!==null&&a.current!==e&&d().catch(()=>{}),a.current=e},[d]),m=(0,U.useCallback)(()=>{d().catch(()=>{})},[d]);return(0,U.useEffect)(()=>{let e=()=>{d().catch(()=>{})},t=()=>{document.visibilityState===`hidden`&&e()};return window.addEventListener(`pagehide`,e),document.addEventListener(`visibilitychange`,t),()=>{window.removeEventListener(`pagehide`,e),document.removeEventListener(`visibilitychange`,t),d().catch(()=>{})}},[d]),{onChange:f,onLineChange:p,onBlur:m,flush:d,error:c}}var V1=8e3;function H1({category:e,name:t,mdContent:n,seedOnMount:r=!0}){let i=VH(e,t),[a,o]=(0,U.useState)(n),[s,c]=(0,U.useState)(!0),[l,u]=(0,U.useState)(),[d,f]=(0,U.useState)({}),[p,m]=(0,U.useState)(0),[h,g]=(0,U.useState)(null),_=(0,U.useRef)({id:i,revision:0}),v=(0,U.useRef)(i);v.current=i;let y=(0,U.useRef)({rawContent:n,noteBlocks:{},sourceRevision:0}),b=(0,U.useCallback)(e=>{_.current.revision=e.sourceRevision,m(e.sourceRevision),y.current.rawContent===e.rawContent&&Object.keys(y.current.noteBlocks).length===Object.keys(e.blocks).length&&Object.values(y.current.noteBlocks).every(t=>{let n=e.blocks[t.id];return n&&n.from===t.from&&n.to===t.to&&n.kind===t.kind})&&(y.current={rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision},f(e.blocks))},[]),x=B1({onSave:(0,U.useCallback)(async e=>{if(e.routeId===v.current&&h)throw h;let t=await lP.saveNote({noteId:e.noteId,rawContent:e.rawContent,blocks:e.noteBlocks,expectedSourceRevision:_.current.id===e.noteId?_.current.revision:e.sourceRevision,metadata:{title:e.title},noteType:`playground`});v.current===e.routeId&&(_.current.id=t.id,u(t.id),b({rawContent:t.rawContent,blocks:t.blocks??{},sourceRevision:t.sourceRevision??1}))},[b,h]),getSnapshotKey:e=>JSON.stringify([e.noteId,e.rawContent,Object.values(e.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])])});(0,U.useEffect)(()=>{let e=!1;_.current={id:i,revision:0},c(!0),g(null);let a=La(n,{sourceRevision:1,registeredWidgets:ja}),s=(e,t,n,r)=>{o(e),f(t),m(n),u(r),_.current={id:r??i,revision:n},y.current={rawContent:e,noteBlocks:t,sourceRevision:n}},l=setTimeout(()=>{e||(e=!0,s(n,a,0),g(Error(`Note load timed out. Reload before saving to avoid overwriting stored content.`)),c(!1))},V1);return(async()=>{try{let o=await KH.getPage(i);if(e)return;if(o)s(o.content,o.noteBlocks??{},o.sourceRevision??1,o.id);else if(r){let r=await lP.saveNote({noteId:i,rawContent:n,blocks:a,expectedSourceRevision:0,metadata:{title:t},noteType:`playground`});e||s(r.rawContent,r.blocks??{},r.sourceRevision??1,r.id)}else s(n,a,0)}catch(t){e||(s(n,a,0),g(t))}finally{clearTimeout(l),e||c(!1)}})(),()=>{e=!0,clearTimeout(l)}},[i,n,t,r]);let S=(0,U.useCallback)(e=>{(y.current.rawContent!==e.rawContent||JSON.stringify(Object.values(y.current.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(e.noteBlocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])))&&(y.current=e,o(e.rawContent),f(e.noteBlocks),x.onChange({...e,routeId:i,noteId:_.current.id,title:t}))},[x.onChange,i,t]),C=(0,U.useCallback)(e=>{if(o(e),y.current.rawContent===e)return;let t=La(e,{sourceRevision:_.current.revision||1,registeredWidgets:ja});S({rawContent:e,noteBlocks:t,sourceRevision:_.current.revision})},[S]),w=(0,U.useCallback)(async()=>{S({rawContent:n,sourceRevision:_.current.revision,noteBlocks:La(n,{sourceRevision:_.current.revision||1,registeredWidgets:ja})}),await x.flush()},[n,S,x.flush]),T=(0,U.useCallback)(()=>_.current.revision,[]);return{content:a,loading:s,entryId:l,noteBlocks:d,sourceRevision:p,onIdentityChange:S,onSaved:b,onChange:C,onLineChange:x.onLineChange,onBlur:x.onBlur,flush:x.flush,committedSourceRevision:T,resetToOriginal:w,isModified:a!==n,error:x.error??h}}async function U1({workoutName:e,category:t,sourceNoteLabel:n,sourceNotePath:r,wodContent:i,date:a,wrapInWod:o=!0}){let s=gP(a??new Date),c=r?.trim()||`/notebook/${encodeURIComponent(t)}`,l=[`# ${e}`,``];return o?l.push("```time",i.trimEnd(),"```"):l.push(i.trimEnd()),l.push(``),CP.create({journalDate:s,title:hP(e),rawContent:l.join(`
446
- `),sourceId:c})}var W1=new Map,G1=new Map;function K1(e){G1.set(e.runtimeId,e)}function q1(e){let t=G1.get(e);return t&&G1.delete(e),t}function J1(e){for(let t of G1.values())if(t.journalDate===e)return t}function Y1(e){G1.delete(e)}function X1(e,t,n){let r=t?e.filter(e=>e.blockId===t):e;if(r.length===0)return{current:[],currentVersion:0,history:new Map};let i=new Map;for(let e of r){let t=e.blockVersion;i.has(t)||i.set(t,[]),i.get(t).push(e)}let a=[],o=0;for(let[e,t]of i)t.some(e=>e.blockContentId===n)&&(e>o?(o=e,a.length=0,a.push(...t)):e===o&&a.push(...t));let s=new Map;for(let[e,t]of i)e!==o&&s.set(e,{version:e,contentId:t[0]?.blockContentId,results:t});return{current:a,currentVersion:o,history:s}}function Z1(e,t,n,r,i){let a=e.map(e=>{if(e.type!==`time`&&e.type!==`log`)return e;let i=parseInt(e.id.replace(`${e.type}-line-`,``),10),a=t.find(e=>e.startLine+1===i),o={};if(r&&a){let{current:e}=X1(r,a.id,a.contentId);o={hasResult:e.length>0,resultCount:e.length}}return e.type===`log`||!n?{...e,...o}:{...e,...o,onRun:()=>{let e=a||t.find(e=>e.startLine+1===i)||t[0];e&&n(e)}}});if(i){let e=a.findIndex(e=>e.type===`heading`),t=e===-1?0:e;if(a[t])return a.map((e,n)=>n===t?{...e,onRun:i,runIcon:`edit`}:e)}return a}function Q1({content:e,scriptBlocks:t,onStartWorkout:n,results:r,onEditNote:i}){let a=(0,U.useMemo)(()=>Z1(CU(e),t,n,r,i),[e,t,n,r,i]),{setL3Items:o}=WM();return(0,U.useEffect)(()=>(o(wU(a)),()=>o([])),[a,o]),a}function $1(e){switch(e.kind){case`journal`:return CN(e.id);case`playground`:return SN(e.id);case`workout`:return e.category===`effort`?RN(e.id):e.category===`equipment`?PN(e.id):e.category?DN(e.category,e.id):TN(e.raw)}}function e0(e){let t=cz(e);return t.kind===`workout`&&!t.category?TN(e):$1(t)}var t0={efforts:[],related:[],backlinks:[]},n0=8;function r0(e){let t=e.id,n=e.type===`playground`||e.sourceId===`playground`||t.startsWith(`playground/`),r=cz(t);if(e.type===`journal`||e.journalDate||!n&&r.kind===`journal`){let n=e.journalDate??(r.kind===`journal`?r.id:void 0);return{zone:`notebooks`,up:n?{id:n,title:`Journal`,to:CN(n)}:null,stamps:[t]}}if(n||r.kind===`playground`){let e=bz({id:t});return{zone:`notebooks`,up:{id:`playgrounds`,title:`Playgrounds`,to:MN()},stamps:[`/playground/${e}`]}}if(r.kind===`workout`){if(r.category===`effort`)return{zone:`efforts`,up:{id:`efforts`,title:`Efforts`,to:NN()},stamps:[RN(r.id)]};if(r.category===`equipment`)return{zone:`equipment`,up:{id:`equipment`,title:`Equipment`,to:$.equipment},stamps:[PN(r.id)]};if(r.category===`notebook`)return{zone:`notebooks`,up:r.id?{id:r.id,title:r.id,to:EN(r.id)}:null,stamps:[]};if(r.category)return{zone:`notebooks`,up:{id:r.category,title:r.category,to:EN(r.category)},stamps:[DN(r.category,r.id)]}}if(e.type===`page`&&(e.pageId??e.slug)){let t=e.pageId??e.slug;return{zone:null,up:{id:t,title:`/page/${t}`,to:jN(t)},stamps:[]}}return{zone:null,up:null,stamps:[]}}function i0(e){if(!e.startsWith(`/`))return null;let t=e.split(`#`)[0],n=t.replace(/\/+$/,``).split(`/`).filter(Boolean),r=n[n.length-1];if(r)try{r=decodeURIComponent(r)}catch{}return{id:t,title:r||t,to:t}}function a0(e,t){let n=new Set,r=[];for(let i of e){if(!i.effortSlug||n.has(i.effortSlug))continue;n.add(i.effortSlug);let e=!t||t.has(i.effortSlug);r.push({id:i.effortSlug,title:i.effortSlug,to:e?RN(i.effortSlug):`${NN()}?q=${encodeURIComponent(i.effortSlug)}`})}return r}function o0(e,t,n=n0){let r=new Set(e.filter(e=>e.noteId===t&&e.dataType===`wod`&&e.blockContentId).map(e=>e.blockContentId));if(r.size===0)return[];let i=new Map;for(let a of e)if(a.dataType===`wod`&&!(!a.blockContentId||!r.has(a.blockContentId)||a.noteId===t)&&!i.has(a.noteId)&&(i.set(a.noteId,{id:a.noteId,title:a.noteTitle||a.noteId,to:e0(a.noteId)}),i.size>=n))break;return[...i.values()]}function s0(e,t,n){if(t.length===0)return[];let r=e.filter(e=>e.id!==n&&!!e.sourceId&&t.some(t=>e.sourceId===t||e.sourceId.startsWith(`${t}#`)));return r.sort((e,t)=>t.createdAt-e.createdAt),r.map(e=>({id:e.id,title:e.title||e.id,to:e0(e.id)}))}function c0(e,t){let n=new Map;for(let r of e)r.noteId===t||n.has(r.noteId)||n.set(r.noteId,{id:r.noteId,title:r.noteId,to:e0(r.noteId)});return[...n.values()]}function l0({noteId:e,stamps:t,effortSlug:n}){let r=t.join(`
447
- `),[i,a]=(0,U.useState)({key:``,data:t0}),o=`${e}\u0000${r}\u0000${n??``}`,s=i.key===o?i.data:t0;return(0,U.useEffect)(()=>{let t=!1,i=r?r.split(`
448
- `):[];return Promise.all([Z.getAllFromIndex(`block_efforts`,`by-note`,e),Z.getAllFromIndex(`block_index`,`by-note`,e),Z.getAllNotes(),Z.getAllEfforts(),n?Z.getAllFromIndex(`block_efforts`,`by-effort`,n):Promise.resolve([])]).then(async([r,a,o,s,c])=>{if(t)return t0;let l=new Set(s.map(e=>e.slug)),u=[...new Set(a.filter(e=>e.dataType===`wod`&&e.blockContentId).map(e=>e.blockContentId))],d=await Promise.all(u.map(e=>Z.getAllFromIndex(`block_index`,`by-content`,e)));if(t)return t0;let f=o0([...a,...d.flat()],e);if(n){let t=new Set(f.map(e=>e.id));for(let n of c0(c,e))t.has(n.id)||(t.add(n.id),f.push(n))}return{efforts:a0(r,l),related:f,backlinks:s0(o,i,e)}}).then(e=>{!t&&e&&a({key:o,data:e})}).catch(()=>{}),()=>{t=!0}},[e,r,n,o]),s}function u0({data:e,up:t,source:n,relatedLabel:r=`Related workouts`}){let{setContextNav:i}=WM(),a=Sn();return(0,U.useEffect)(()=>{let o=[],s=(e,t,n)=>{n.length!==0&&o.push({kind:`section`,id:e,label:t,entries:n.map(t=>({kind:`link`,id:`${e}:${t.id}`,label:t.title,to:t.to}))})};return s(`note-context-up`,`Up`,t?[t]:[]),s(`note-context-source`,`Source`,n?[n]:[]),s(`note-context-efforts`,`Efforts`,e.efforts),s(`note-context-backlinks`,`Journal copies`,e.backlinks),s(`note-context-related`,r,e.related),i({pathname:a.pathname,spec:o}),()=>i(void 0)},[e,t,n,r,a.pathname,i]),null}function d0(e,t){return(0,U.useMemo)(()=>{let n=[];return t.onPlay&&(e===`playground`||e===`journal-active`||e===`notebook-readonly`)&&n.push({id:`play`,label:`Play`,icon:(0,W.jsx)(rn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:t.onPlay}),t.onLog&&(e===`playground`||e===`journal-active`||e===`notebook-readonly`)&&n.push({id:`log`,label:`Log`,icon:(0,W.jsx)(Be,{className:`h-3 w-3`}),primary:!0,onClick:t.onLog}),t.onOpenInPlayground&&(e===`journal-plan`||e===`notebook-readonly`)&&n.push({id:`open-in-playground`,label:`Playground`,icon:(0,W.jsx)(o,{className:`h-3 w-3`}),onClick:t.onOpenInPlayground}),t.onShare&&n.push({id:`share`,label:`Share`,icon:(0,W.jsx)(_,{className:`h-3 w-3`}),onClick:t.onShare}),t.onAddToToday&&e===`playground`&&n.push({id:`add-to-today`,label:`Today`,icon:(0,W.jsx)(ve,{className:`h-3 w-3`}),onClick:t.onAddToToday}),t.onSchedule&&n.push({id:`schedule`,label:`Schedule`,icon:(0,W.jsx)(ke,{className:`h-3 w-3`}),onClick:t.onSchedule}),n},[e,t.onPlay,t.onLog,t.onShare,t.onAddToToday,t.onSchedule,t.onOpenInPlayground])}async function f0(e){let t=new TextEncoder().encode(e),n=new CompressionStream(`gzip`),r=n.writable.getWriter(),i=n.readable.getReader();r.write(t),r.close();let a=[];for(;;){let{done:e,value:t}=await i.read();if(e)break;a.push(t)}let o=a.reduce((e,t)=>e+t.length,0),s=new Uint8Array(o),c=0;for(let e of a)s.set(e,c),c+=e.length;let l=``;for(let e=0;e<s.length;e++)l+=String.fromCharCode(s[e]);return btoa(l).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=/g,``)}async function p0(e,t){let n=e.dialect||`time`,r=await f0(`\`\`\`${e.sport?`${n}:${e.sport}`:n}\n${e.content.trimEnd()}\n\`\`\`\n`),i=`${window.location.origin}${kN({zip:r})}`;return t?`${i}&src=${encodeURIComponent(t)}`:i}async function m0(e,t){let n=await p0(e,window.location.pathname),{pathname:r,search:i}=new URL(n);t(`${r}${i}`)}async function h0(e){let t=await p0(e,window.location.pathname);window.open(t,`_blank`)}async function g0(e){let t=e.dialect||`time`,n=await f0(`\`\`\`${e.sport?`${t}:${e.sport}`:t}\n${e.content.trimEnd()}\n\`\`\`\n`),r=`shared by ${vx()}`;return`${window.location.origin}/?z=${n}&by=${encodeURIComponent(r)}`}function _0(e){g0(e).then(e=>{navigator.clipboard.writeText(e).then(()=>{Q({title:`Link copied`,description:`Share link copied to clipboard.`})}).catch(()=>{Q({title:`Could not copy`,description:e,variant:`destructive`})})})}function v0(e=`end`){let t=(0,U.useRef)(null),[n,r]=(0,U.useState)(e);return{triggerRef:t,align:n,recompute:(0,U.useCallback)(()=>{let e=t.current;if(!e)return;let{left:n,right:i}=e.getBoundingClientRect(),a=(n+i)/2;r(a>window.innerWidth/2?`end`:`start`)},[])}}function y0(e,t){if(t){t();return}let n=new Blob([e.content],{type:`text/markdown`}),r=URL.createObjectURL(n),i=document.createElement(`a`);i.href=r,i.download=`${e.name.replace(/[/\\:*?"<>|]/g,`-`)}.md`,i.click(),URL.revokeObjectURL(r)}function b0({currentWorkout:e,onDownload:t}){return e.content===``?null:(0,W.jsxs)(`button`,{type:`button`,onClick:()=>y0(e,t),className:`flex w-full items-center gap-2 rounded-lg px-2 py-1.5 text-left text-[13px] text-muted-foreground transition-colors hover:bg-muted/60 hover:text-foreground`,children:[(0,W.jsx)(Be,{className:`size-4 shrink-0`}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:`Download Markdown`})]})}function x0(e,t,n){let r=Vn(),{l3Items:i,scrollToSection:a,secondarySpec:o,streamControls:s}=WM(),c=t&&t.length>0?t:i,l=Wz(o),u=[];s&&u.push({kind:`custom`,id:`l3-stream-controls`,nav:!0,render:()=>(0,W.jsx)(vV,{streamControls:s})});for(let e of l)if(e.kind===`section`){if(e.entries.length===0)continue;u.push({kind:`heading`,id:e.id,label:e.label,nav:!0});for(let t of e.entries)u.push({kind:`row`,id:t.id,label:t.label,nav:!0,onSelect:()=>{t.onRun?t.onRun():t.to?r(t.to):t.sectionId&&a(t.sectionId)}})}else u.push({kind:`row`,id:e.id,label:e.label,nav:!0,onSelect:()=>{e.onRun?e.onRun():e.to?r(e.to):e.sectionId&&a(e.sectionId)}});if(c.length>0){u.push({kind:`heading`,id:`on-this-page`,label:`On this page`,nav:!0});for(let e of c)u.push({kind:`row`,id:e.id,label:e.label,nav:!0,secondary:e.secondaryAction?{label:e.secondaryAction.label,icon:e.secondaryAction.icon&&(0,W.jsx)(e.secondaryAction.icon,{className:`size-3.5`}),onSelect:()=>{e.secondaryAction?.action.type===`call`&&e.secondaryAction.action.handler()}}:void 0,onSelect:()=>{e.action.type===`call`?e.action.handler():a(e.id)}})}return e.content!==``&&u.push({kind:`row`,id:`download-markdown`,label:`Download Markdown`,icon:(0,W.jsx)(Be,{className:`size-4`}),nav:!1,onSelect:()=>y0(e,n)}),u}function S0({currentWorkout:e,onDownload:t,items:n}){let r=x0(e,n,t),i=e=>e.kind===`heading`?(0,W.jsx)(rV,{children:e.label},e.id):e.kind===`custom`?(0,W.jsx)(`div`,{className:`px-1 py-1`,children:e.render()},e.id):(0,W.jsxs)(eV,{onClick:e.onSelect,className:`gap-2`,children:[e.icon,(0,W.jsx)(`span`,{className:G(`flex-1 truncate`,e.secondary&&`pr-8`),children:e.label}),e.secondary&&(0,W.jsx)(`button`,{className:`ml-auto flex items-center justify-center size-5 rounded text-primary hover:bg-primary/10 transition-colors`,title:e.secondary.label,onClick:t=>{t.stopPropagation(),e.secondary?.onSelect()},children:e.secondary.icon})]},e.id),a=r.filter(e=>e.nav),o=r.filter(e=>!e.nav);return r.length===0?null:(0,W.jsxs)(ZB,{children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsxs)(K,{variant:`ghost`,size:`icon`,"aria-label":`Page options`,className:G(`text-muted-foreground`,`2xl:hidden`),children:[(0,W.jsx)(he,{className:`size-5`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Page options`})]})}),(0,W.jsxs)($B,{align:`end`,className:`min-w-56 max-h-[calc(100dvh-6rem)] overflow-y-auto`,children:[a.length>0&&(0,W.jsxs)(`div`,{className:`2xl:hidden`,children:[a.map(i),(0,W.jsx)(nV,{})]}),o.map(i)]})]})}var C0=xU("# My Workout\n\n```time\n$CURSOR\n```\n"),w0={content:C0.content,cursorOffset:C0.cursorOffset};function T0({mode:e,currentWorkout:t,index:n,onReset:r}){let i=Vn(),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(!1),l=LV(),u=TV(),d=l&&u;return d&&e!==`playground`?null:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[e===`playground`&&(0,W.jsx)(ZJ,{primary:{id:`new-playground`,label:a?`Creating…`:`New`,icon:ve,action:{type:`call`,handler:async()=>{if(!a){o(!0);try{let e=await bq(w0.content);i(`/playground/${encodeURIComponent(e)}`)}finally{o(!1)}}}}},secondary:{id:`reset-playground`,label:s?`Resetting…`:`Reset to default`,icon:We,action:{type:`call`,handler:async()=>{if(!(!r||s)){c(!0);try{await r()}finally{c(!1)}}}}},size:`sm`}),!d&&(0,W.jsx)(vH,{}),!d&&(0,W.jsx)(wZ,{}),!d&&(0,W.jsx)(S0,{currentWorkout:t,items:n&&n.length>0?wU(n):void 0})]})}function E0({slug:e,itemDate:t,item:n,theme:r,onViewCreated:i}){let a=Vn(),o=YO(),s=(0,U.useMemo)(()=>{if(o)return MO(OO(o).find(t=>t.id===e),t,n)},[o,e,t,n]),{content:c,noteBlocks:l,sourceRevision:u,onIdentityChange:d,onSaved:f,onChange:p,onLineChange:m,onBlur:h,flush:g}=H1({category:`notebook/${e}/${t}`,name:n,mdContent:s?.content??`# ${n}\n\n*Notebook item not found.*\n`,seedOnMount:!1}),[_,v]=(0,U.useState)([]),y=`notebook/${e}/${t}/${n}`,b=`/notebook/${encodeURIComponent(e)}/${t}/${encodeURIComponent(n)}`,x=(0,U.useCallback)(async t=>{try{let r=w(),i=await U1({workoutName:s?.name??n,category:e,sourceNoteLabel:e,sourceNotePath:b,wodContent:t.content}),o=Object.values(i.blocks??{}).find(e=>e.kind===`wod`);if(!o)throw Error(`The saved journal workout is unavailable.`);W1.set(r,{block:{...t,id:o.id},noteId:i.id}),a(wN(i.journalDate??``,r))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}},[e,n,b,s,a]),S=(0,U.useCallback)(async t=>{try{let r=await U1({workoutName:s?.name??n,category:e,sourceNoteLabel:e,sourceNotePath:b,wodContent:t.content}),i=Ly(new Date);Q({title:`Added to journal`,description:r.journalDate===i?`Added to today's journal`:`Added to ${r.journalDate}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>a(CN(r.journalDate??i)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not add to journal`,variant:`destructive`})}},[e,n,b,s,a]),[C,T]=(0,U.useState)(null),E=(0,U.useCallback)(async(t,r)=>{let i=`${r.getFullYear()}-${String(r.getMonth()+1).padStart(2,`0`)}-${String(r.getDate()).padStart(2,`0`)}`;try{await U1({workoutName:s?.name??n,category:e,sourceNoteLabel:e,sourceNotePath:b,wodContent:t.content,date:r}),a(CN(i)),Q({title:`Scheduled`,description:`Added to journal for ${i}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>a(CN(i)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not schedule workout`,variant:`destructive`})}},[e,n,b,s,a]),D=Q1({content:c,scriptBlocks:_,onStartWorkout:x}),O=`notebook/${e}/${t}/${n}`,k=(0,U.useMemo)(()=>r0({id:O,type:`note`}),[O]),A=l0({noteId:O,stamps:k.stamps}),j=d0(`notebook-readonly`,{onPlay:x,onShare:_0,onAddToToday:S,onSchedule:T,onOpenInPlayground:e=>m0(e,a)});return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(KB,{title:s?.name??n,actions:(0,W.jsx)(RV,{label:`Workout actions`,children:(0,W.jsx)(T0,{mode:`notebook-readonly`,currentWorkout:{name:s?.name??n,content:c},index:D})}),editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-6 sm:px-6`,children:[(0,W.jsx)(u0,{data:A,up:k.up}),(0,W.jsx)(YZ,{value:c,onChange:p,onCursorPositionChange:m,onBlur:h,noteId:y,noteBlocks:l,sourceRevision:u,onIdentityChange:e=>d({rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision}),onSaved:f,onSaveRequest:g,onCommitChange:g,commands:j,enableInlineRuntime:!1,onViewCreated:i,theme:r,showLineNumbers:!1,onBlocksChange:v})]})}),C&&(0,W.jsx)(OC,{open:!0,onClose:()=>T(null),title:`Schedule workout`,children:(0,W.jsx)(z1,{selectedDate:null,onDateSelect:e=>{E(C,e),T(null)}})})]})}function D0(e,t){if(e.startsWith(`# 👋`))return e;let n=t?.replace(/^shared by:?\s*/i,``).trim();return`${n?`# 👋 ${n} sent you this workout`:`# 👋 Edit Me`}\n\nChange the reps, distance, or load below — this is live.\n\n${e}\n\n> Press **Run** ↑ to start the Clock.\n`}var O0=`wodwiki.homeShared.v1`;function k0(){return typeof window<`u`&&window.localStorage?window.localStorage:null}function A0(e){try{k0()?.setItem(O0,JSON.stringify(e)),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`wodwiki:home-shared`,{detail:e}))}catch{}}function j0(){try{let e=k0()?.getItem(O0);if(!e)return null;let t=JSON.parse(e);return typeof t?.content==`string`?{content:t.content,by:typeof t.by==`string`?t.by:void 0}:null}catch{return null}}function M0(){try{k0()?.removeItem(O0)}catch{}}function N0({pageRoute:e,quests:t,running:n}){let{markComplete:r}=Nq(e,t),i=(0,U.useMemo)(()=>t.filter(e=>e.validation?.type===`run-started`),[t]);(0,U.useEffect)(()=>{if(n)for(let e of i)r(e.id)},[n,i,r])}var P0={"session-insights":`qs-tour-analytics`},F0={"workout-complete":!0,"run-started":!0};function I0(e,t){let{markComplete:n}=Nq(e,t),r=(0,U.useRef)(new Set);return r.current=new Set(t.filter(e=>!e.validation||!F0[e.validation.type]).map(e=>e.id)),(0,U.useCallback)(e=>{let t=P0[e];t&&r.current.has(t)&&n(t)},[n])}var L0=.4;function R0(e){let{dispatch:t}=WM();(0,U.useEffect)(()=>{let n=e.map(e=>document.getElementById(e)).filter(e=>e!==null);if(n.length===0||typeof IntersectionObserver>`u`)return;let r=()=>{let e=window.innerHeight*L0,t=null;for(let r of n){let n=r.getBoundingClientRect();if(n.width!==0||n.height!==0){if(n.top>e)break;t=r.id}}return t},i=new IntersectionObserver(()=>{let e=r();e&&t({type:`SET_ACTIVE_L3`,id:e})},{threshold:Array.from({length:21},(e,t)=>t/20)});return n.forEach(e=>i.observe(e)),()=>i.disconnect()},[e.join(`
449
- `),t])}var z0=(0,U.createContext)(null);function B0({children:e}){let t=(0,U.useRef)({"editor.window":null,"editor.wodBlock":null,"editor.runButton":null,"editor.typeahead":null,"timer.floor":null,"timer.nextButton":null,"timer.castButton":null,"metrics.efforts":null,"metrics.data":null,"metrics.compound":null,"analytics.vocab":null,"analytics.table":null,"analytics.graphs":null,"analytics.dashboard":null}),[n,r]=(0,U.useState)(0),i=(0,U.useCallback)((e,n)=>{t.current[e]!==n&&(t.current[e]=n,r(e=>e+1))},[]);return(0,W.jsx)(z0.Provider,{value:{register:i,registry:t,version:n},children:e})}function V0(){return(0,U.useContext)(z0)||{registry:{current:{}},register:()=>()=>{},version:0}}function H0(e){let t=(0,U.useContext)(z0)?.register;return(0,U.useCallback)(n=>t?.(e,n),[e,t])}function U0({ringKey:e,el:t}){let{register:n}=V0();return(0,U.useLayoutEffect)(()=>{n(e,t)},[e,t,n]),null}function W0({target:e,accent:t,canvasRef:n}){let{registry:r,version:i}=V0(),[a,o]=(0,U.useState)(null),s=e?.key??null;return(0,U.useLayoutEffect)(()=>{if(!s){o(null);return}let e=()=>{let e=r.current[s],t=n.current;if(!e||!t){o(null);return}let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),c=Math.round(i.left-a.left),l=Math.round(i.top-a.top),u=Math.round(i.width),d=Math.round(i.height);if(u<=0||d<=0||c+u<0||l+d<0||c>a.width||l>a.height){o(null);return}o({x:c,y:l,w:u,h:d})};e();let t=window.setTimeout(e,120),i=window.setTimeout(e,480),a=null,c=r.current[s];c&&typeof ResizeObserver<`u`&&(a=new ResizeObserver(e),a.observe(c));let l=new MutationObserver(e);return c&&l.observe(c,{attributes:!0,attributeFilter:[`style`]}),window.addEventListener(`resize`,e),()=>{window.clearTimeout(t),window.clearTimeout(i),a?.disconnect(),l.disconnect(),window.removeEventListener(`resize`,e)}},[s,i,r,n]),!e||!a?null:(0,W.jsx)(`div`,{"data-testid":`tour-ring`,className:`pointer-events-none absolute z-30 rounded-2xl transition-all duration-500 ease-out`,style:{left:a.x-6,top:a.y-6,width:a.w+12,height:a.h+12,boxShadow:`0 0 0 2px ${t}`}})}function G0(){return(0,W.jsxs)(`div`,{className:`@container flex w-full flex-col items-center text-center`,children:[(0,W.jsxs)(`h1`,{className:`text-[clamp(32px,6.5cqi,64px)] font-extrabold leading-[1.02] tracking-[-0.04em]`,children:[(0,W.jsxs)(`span`,{className:`block`,children:[(0,W.jsx)(`span`,{className:`mr-[0.35em]`,children:`Write it.`}),(0,W.jsx)(`span`,{children:`Time it.`})]}),(0,W.jsxs)(`span`,{className:`block`,children:[(0,W.jsx)(`span`,{className:`mr-[0.35em]`,children:`Track it.`}),(0,W.jsx)(`span`,{children:`Own it.`})]})]}),(0,W.jsxs)(`p`,{className:`mt-4 xl:mt-6 max-w-xl xl:max-w-2xl 2xl:max-w-3xl text-[15px] sm:text-base xl:text-lg leading-relaxed text-muted-foreground`,children:[`Plain-text Markdown becomes a step-through workout clock, `,(0,W.jsx)(`br`,{}),`line and splits become queryable training data points.`]})]})}var K0=`dQw4w9WgXcQ`;function q0({onWatched:e}){let[t,n]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-4 xl:gap-5`,children:[(0,W.jsxs)(`div`,{className:`group relative aspect-video w-full max-w-2xl rounded-xl border border-border bg-black text-left shadow-xl transition-shadow hover:shadow-2xl 2xl:max-w-3xl`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(!0),"data-testid":`tour-why-video`,"aria-label":`Play the Why Wod Wiki? video`,className:`block h-full w-full overflow-hidden rounded-xl`,children:[(0,W.jsx)(`img`,{src:`https://i.ytimg.com/vi/${K0}/hqdefault.jpg`,alt:`Why Wod Wiki? video thumbnail`,loading:`lazy`,className:`h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.02]`}),(0,W.jsx)(`span`,{className:`absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent`}),(0,W.jsx)(`span`,{className:`absolute left-1/2 top-1/2 flex size-14 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-background/90 text-foreground shadow-lg transition-transform duration-300 group-hover:scale-110 xl:size-16`,children:(0,W.jsx)(pn,{className:`ml-1 size-6 fill-current xl:size-7`})}),(0,W.jsx)(`span`,{className:`absolute bottom-3 left-4 font-mono text-[11px] uppercase tracking-[0.2em] text-white/90`,children:`Why Wod Wiki? · YouTube`})]}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),e?.()},"data-testid":`tour-why-video-skip`,title:`Skip the video`,"aria-label":`Skip the Why Wod Wiki? video`,className:`absolute right-0 top-0 z-10 flex size-8 items-center justify-center rounded-full border border-border bg-background/90 text-foreground shadow-lg backdrop-blur-sm transition-colors hover:bg-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary after:absolute after:-inset-3 after:content-[''] md:-right-2 md:-top-2`,children:(0,W.jsx)(we,{className:`size-4`})})]}),(0,W.jsxs)(`p`,{"data-testid":`tour-scroll-hint`,className:`flex items-center gap-2 font-mono text-[11px] uppercase tracking-[0.3em] text-muted-foreground`,children:[(0,W.jsx)(Et,{className:`size-4 animate-bounce`}),`Keep scrolling for the demo`]}),t&&(0,W.jsx)(w$,{videoId:K0,title:`Why Wod Wiki?`,onClose:()=>{n(!1),e?.()}})]})}var J0=`https://github.com/bitcobblers/wod-wiki`;function Y0(){return(0,W.jsx)(`footer`,{"data-testid":`tour-footer`,className:`border-t border-border px-6 py-8`,children:(0,W.jsxs)(`p`,{className:`mx-auto flex max-w-3xl flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,W.jsxs)(`span`,{children:[`© `,new Date().getFullYear(),` WOD Wiki`]}),(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,W.jsx)(`a`,{href:J0,target:`_blank`,rel:`noopener noreferrer`,className:`underline-offset-4 transition-colors hover:text-foreground hover:underline`,children:`GitHub repository`})]})})}async function X0(){try{await Z.wipe()}catch{}try{for(let e=localStorage.length-1;e>=0;e--){let t=localStorage.key(e);t&&localStorage.removeItem(t)}}catch{}try{sessionStorage.clear()}catch{}}var Z0=`https://github.com/bitcobblers/wod-wiki`,Q0=`https://forms.gle/6YHpxwAJh6PAsyAQ6`,$0=`https://app.turso.tech/signup`,e2=`m23.31.803-.563-.42-1.11 1.189-.891-1.286-.512.235.704 1.798-.326.35L18.082 0l-.574.284 2.25 4.836-2.108.741h-.05l-1.143-1.359-1.144 1.36H8.687l-1.144-1.36-1.146 1.363H6.36l-2.12-.745L6.491.284 5.919 0l-2.53 2.668-.327-.349.705-1.798-.512-.236-.89 1.287L1.253.382.69.804 2.42 3.69l-.89.939.311 2.375 2.061.787L3.9 8.817H1.947v.444l.755 1.078 1.197.433v6.971l3.057 4.55L7.657 24l1.101-1.606L9.9 24l.999-1.606L12 24l1.102-1.606L14.1 24l1.141-1.606L16.343 24l.701-1.706 3.058-4.55v-6.972l1.196-.433.756-1.078v-.444h-1.952l.003-1.03 2.054-.784.311-2.375-.89-.939zm-8.93 18.718H8.033l.793-1.615.794 1.615.793-1.083.793 1.083.794-1.083.793 1.083.794-1.083.793 1.083.793-1.615.794 1.615zm3.886-7.39-3.3 1.084-.143 3.061-2.827.627-2.826-.627-.142-3.06-3.3-1.085v-1.635l4.266 1.21-.052 4.126h4.109l-.052-4.127 4.266-1.209z`,t2=[{id:`managed-hosting`,label:`Managed hosting — we run the database.`},{id:`public-profile`,label:`Profile page with a public feed.`},{id:`device-sync`,label:`Sync across your apps and devices.`}],n2=[{id:`coach-views`,label:`Member accounts with coach views.`},{id:`coaches-portal`,label:`Programming dashboards and leaderboards.`},{id:`athlete-portal`,label:`Private journals that roll up to their coach.`},{id:`gym-hosting`,label:`Gym website, competition timers, whiteboard displays.`},{id:`branding`,label:`Your gym's brand on pages and feeds.`}],r2=`underline-offset-4 transition-colors hover:text-foreground hover:underline`;function i2(e){let t=`inline-flex w-fit items-center gap-1.5 font-medium text-foreground underline-offset-4 transition-colors hover:underline`,n=(0,W.jsxs)(W.Fragment,{children:[e.children,(0,W.jsx)(h,{className:`size-3.5 text-muted-foreground/50`,"aria-hidden":!0})]});return e.href===void 0?e.onClick===void 0?(0,W.jsx)(_n,{to:e.to,className:t,children:n}):(0,W.jsx)(`button`,{type:`button`,onClick:e.onClick,className:`text-left ${t}`,children:n}):(0,W.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:t,children:n})}function a2({children:e}){return(0,W.jsxs)(`li`,{className:`flex gap-2.5 text-sm leading-6 text-muted-foreground`,children:[(0,W.jsx)(`span`,{"aria-hidden":!0,className:`mt-[11px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,W.jsx)(`span`,{children:e})]})}function o2(){return(0,W.jsx)(`span`,{className:`rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 font-mono text-[11px] font-medium text-emerald-600`,children:`Active`})}function s2(e){return(0,W.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsxs)(`span`,{className:`flex gap-2.5 text-[13px] leading-5 text-muted-foreground`,children:[(0,W.jsx)(`span`,{"aria-hidden":!0,className:`mt-[9px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,W.jsx)(`span`,{children:e.feature.label})]}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`hosted-interest-${e.feature.id}`,onClick:()=>e.onInterested(e.feature.id),disabled:e.interested,"aria-pressed":e.interested,className:`ml-[13px] w-fit shrink-0 rounded-full border px-2 py-px text-[11px] font-medium transition-colors ${e.interested?`border-emerald-500/30 bg-emerald-500/10 text-emerald-600`:`border-border text-muted-foreground hover:border-primary/50 hover:text-primary`}`,children:e.interested?`✓ Interested`:`Interested`})]})}function c2(){return(0,W.jsx)(`div`,{role:`status`,"data-testid":`hosted-survey-footer`,className:`mx-auto mt-5 max-w-5xl animate-in fade-in slide-in-from-bottom-4 rounded-xl border border-emerald-500/30 bg-emerald-500/10 p-4 duration-500`,children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,W.jsx)(yn,{className:`size-5 shrink-0 text-emerald-600`,"aria-hidden":!0}),(0,W.jsxs)(`div`,{className:`text-sm`,children:[(0,W.jsx)(`p`,{className:`font-medium text-foreground`,children:`Thanks for showing interest — please fill out the survey and give us feedback.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Opens the interest survey in a new tab.`})]})]}),(0,W.jsxs)(K,{type:`button`,"data-testid":`hosted-survey-button`,onClick:()=>{dq.record(fq.hostedSurveyOpened),window.open(Q0,`_blank`,`noopener,noreferrer`)},children:[`Fill out interest survey`,(0,W.jsx)(h,{className:`size-4`,"aria-hidden":!0})]})]})})}function l2(e){let t=e.icon;return(0,W.jsxs)(`article`,{className:`flex flex-col rounded-xl border border-border p-5 ${e.us?`bg-muted/40`:`bg-background`} ${e.className??``}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,W.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),e.badge]}),e.eyebrow&&(0,W.jsx)(`p`,{className:`mt-3.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] ${e.us?`text-emerald-600`:`text-muted-foreground`}`,children:e.eyebrow}),(0,W.jsx)(`h3`,{className:`${e.eyebrow?`mt-1`:`mt-4`} text-base font-semibold text-foreground`,children:e.title}),(0,W.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.text}),(0,W.jsx)(`div`,{className:`mt-4 flex flex-1 flex-col gap-2 text-sm`,children:e.children})]})}function u2({label:e,features:t,interested:n,onInterested:r}){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`mt-2.5 font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground first:mt-0`,children:e}),(0,W.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>(0,W.jsx)(s2,{feature:e,interested:n.has(e.id),onInterested:r},e.id))})]})}function d2(){let[e,t]=(0,U.useState)(!1),n=Vn(),[r,i]=(0,U.useState)(new Set),a=e=>{i(t=>t.has(e)?t:new Set(t).add(e)),dq.record(fq.hostedInterestClicked,{feature:e})},[o]=(0,U.useState)(vk),s=o.state===`turso`?`turso`:o.state===`invalid`?`turso-invalid`:`browser`,c=async()=>{window.confirm(`Wipe every note, result, and setting stored in this browser? This cannot be undone.`)&&(t(!0),await X0(),window.location.reload())},l=async()=>{let e=_P(),t=await CP.create({journalDate:e,title:e,rawContent:``});dq.record(fq.noteCreated),n(TN(t.id))},u=s===`turso-invalid`?(0,W.jsx)(`span`,{className:`rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 font-mono text-[11px] font-medium text-amber-600`,children:`Invalid config`}):s===`api`?void 0:(0,W.jsx)(o2,{});return(0,W.jsxs)(`section`,{id:`tour-section-offerings`,"data-testid":`tour-section-offerings`,"aria-label":`You own your data`,children:[(0,W.jsx)(T$,{index:`04`,before:`Who owns the data? `,accentText:`You!!!`,after:``,accent:D$.library,blurb:`Run it in your browser, back it up to your own database, or host it on your own server — and if you'd rather hand the caretaking to us, mark the hosted features you want below and the interest survey unlocks.`}),(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-[1500px] 2xl:max-w-[1720px] px-6 pb-16 pt-10 lg:px-12 xl:px-16`,children:[(0,W.jsxs)(`p`,{className:`mx-auto mb-5 flex max-w-5xl flex-wrap items-center justify-between gap-3 text-sm text-muted-foreground`,role:`status`,children:[(0,W.jsx)(`span`,{children:s===`api`?`Current mode: API server`:s===`turso`?`Current mode: local browser with Turso backup and sync`:s===`turso-invalid`?`Current mode: local browser. Repair the Turso connection to resume sync.`:`Current mode: local browser only`}),(0,W.jsx)(_n,{to:$.settingsStorage,className:r2,children:`Configure data storage`})]}),(0,W.jsxs)(`div`,{className:`mx-auto grid max-w-5xl grid-cols-1 gap-5 md:grid-cols-3`,children:[(0,W.jsxs)(l2,{icon:ee,eyebrow:`You own it`,title:`Playground in your browser`,badge:u,text:`Everything runs locally in this browser's IndexedDB — offline, no account, no server copy.`,children:[(0,W.jsx)(i2,{onClick:()=>void l(),children:`Create your journal`}),(0,W.jsx)(i2,{to:$.playgroundRoot,children:`Start Writing in a Playground`}),(0,W.jsx)(i2,{to:`/feeds`,children:`Explore the notebooks`}),(0,W.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,W.jsx)(a2,{children:`Offline and fast — notes and results never leave this browser by default.`}),(0,W.jsx)(a2,{children:`Tied to this browser — export or back it up before switching browsers or clearing site data.`})]}),(0,W.jsx)(`button`,{type:`button`,onClick:c,disabled:e,className:`mt-1 text-left text-xs text-muted-foreground disabled:opacity-50 ${r2}`,children:e?`Clearing…`:`Clear my data`}),(0,W.jsxs)(`div`,{className:`mt-auto border-t border-border pt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,W.jsx)(`span`,{className:`mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg border border-border bg-background`,children:(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:`size-4`,"aria-hidden":!0,children:(0,W.jsx)(`path`,{d:e2})})}),(0,W.jsxs)(`div`,{className:`text-sm`,children:[(0,W.jsx)(`p`,{className:`font-medium text-foreground`,children:`Backup & sync, optional`}),(0,W.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:`Add a free Turso database you own — committed changes back up in the background; without network you keep working and upload later.`})]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[(0,W.jsx)(i2,{href:$0,children:`Create a free Turso account`}),(0,W.jsx)(i2,{to:$.settingsStorage,children:`Configure backup & sync`})]})]})]}),(0,W.jsxs)(l2,{icon:Hn,eyebrow:`You own it`,title:`Self-hosted`,badge:s===`api`?(0,W.jsx)(o2,{}):void 0,text:`Build the app for API storage and run the Wod Wiki server yourself — local or cloud data access through a server you administer.`,children:[(0,W.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,W.jsx)(a2,{children:`Centralized data for a team or gym — one SQLite, Turso, or Postgres backend.`}),(0,W.jsxs)(a2,{children:[`Publish your notebooks as a feed with `,(0,W.jsx)(`code`,{className:`font-mono text-xs`,children:`wod build`}),` — every browser subscribes and syncs.`]}),(0,W.jsx)(a2,{children:`You run the server — network required, and server admin is on you.`})]}),(0,W.jsx)(`div`,{className:`mt-auto border-t border-border pt-4`,children:(0,W.jsx)(i2,{href:Z0,children:`View source`})})]}),(0,W.jsxs)(l2,{icon:$e,us:!0,eyebrow:`Us — we'd host it`,title:`Wod-Wiki hosted`,text:`Mark the features you want — the survey unlocks below.`,children:[(0,W.jsx)(u2,{label:`Individuals`,features:t2,interested:r,onInterested:a}),(0,W.jsx)(u2,{label:`Coaching & gyms`,features:n2,interested:r,onInterested:a})]})]}),r.size>0&&(0,W.jsx)(c2,{})]})]})}var f2=({doc:e,onDocChange:t,onBlocksChange:n,onRun:r,theme:i,withRingTargets:a=!1})=>{let o=H0(`editor.wodBlock`),s=H0(`editor.runButton`),c=(0,U.useRef)(null),l=(0,U.useRef)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(null),m=(0,U.useCallback)(()=>{if(!a)return null;let e=c.current;if(!e)return null;let t=null,n=e.querySelector(`.cm-wod-fence-open`),r=e.querySelector(`.cm-wod-fence-close`);if(n&&r){let i=e.getBoundingClientRect(),a=n.getBoundingClientRect(),o=r.getBoundingClientRect();if(a.top>=i.top-2&&o.bottom<=i.bottom+2){let n=e.offsetWidth?i.width/e.offsetWidth:1;t={top:(a.top-i.top)/n,left:(Math.min(a.left,o.left)-i.left)/n,width:(Math.max(a.right,o.right)-Math.min(a.left,o.left))/n,height:(o.bottom-a.top)/n}}}d(t);let i=null,o=e.querySelector(`[data-testid="${BU.EDITOR_START_WORKOUT}"]`);if(o){let t=e.getBoundingClientRect(),n=o.getBoundingClientRect();if(n.width>0&&n.height>0&&n.top>=t.top-2&&n.bottom<=t.bottom+2&&n.left>=t.left-2&&n.right<=t.right+2){let r=e.offsetWidth?t.width/e.offsetWidth:1;i={top:(n.top-t.top)/r,left:(n.left-t.left)/r,width:n.width/r,height:n.height/r}}}return p(i),{block:t,run:i}},[a]);(0,U.useLayoutEffect)(()=>{if(!a)return;let e=c.current;if(!e)return;m();let t=window.setTimeout(m,120),n=window.setTimeout(m,480),r=null;if(typeof ResizeObserver<`u`){r=new ResizeObserver(m),r.observe(e);let t=l.current?.contentDOM;t&&r.observe(t)}let i=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.closest(`.cm-note-editor`))&&m()});i.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`]});let o=0,s=0,u=()=>{m(),performance.now()-s<3e3&&(o=requestAnimationFrame(u))},d=()=>{s=performance.now(),cancelAnimationFrame(o),o=requestAnimationFrame(u)};d(),document.fonts?.ready?.then(d).catch(()=>{});let f=l.current?.scrollDOM;return f?.addEventListener(`scroll`,m,{passive:!0}),window.addEventListener(`resize`,m),()=>{window.clearTimeout(t),window.clearTimeout(n),r?.disconnect(),i.disconnect(),f?.removeEventListener(`scroll`,m),window.removeEventListener(`resize`,m),cancelAnimationFrame(o)}},[e,a,m]);let h=(0,U.useCallback)(()=>{r()},[r]),g=(0,U.useMemo)(()=>[{id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:h},{id:`playground`,label:`Playground`,icon:(0,W.jsx)(A,{className:`h-3 w-3`}),onClick:e=>{h0(e)},splitIcon:(0,W.jsx)(rt,{className:`h-3 w-3`}),splitSuccessIcon:(0,W.jsx)(un,{className:`h-3 w-3 text-emerald-500`}),onSplitClick:e=>{_0(e)}}],[h]);return(0,W.jsx)(`div`,{className:`relative flex h-full flex-col bg-background text-left`,children:(0,W.jsxs)(`div`,{ref:c,className:`relative flex-1 min-h-0`,children:[(0,W.jsx)(YZ,{noteId:`canvas:home`,value:e,onChange:t,onBlocksChange:n,onStartWorkout:h,commands:g,onViewCreated:e=>{l.current=e,a&&m()},theme:i,readonly:!1,showLineNumbers:!1,showFrontmatter:!1,enableOverlay:!1,enableInlineRuntime:!1,className:`h-full`}),a&&u&&(0,W.jsx)(`div`,{ref:o,"data-testid":`tour-wod-block-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:u.top,left:u.left,width:u.width,height:u.height}}),a&&f&&(0,W.jsx)(`div`,{ref:s,"data-testid":`tour-run-button-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:f.top,left:f.left,width:f.width,height:f.height}})]})})};function p2(e){let t=Number.isFinite(e.startTime)?e.startTime:0,n=[],r=[];for(let i of e.logs??[]){if(i.outputType!==`segment`||i.stackLevel!==1||i.line==null)continue;let e=i.timeSpan;if(!e||typeof e.started!=`number`||typeof e.ended!=`number`||e.ended<=e.started)continue;let a=i.metrics??[],o=e=>a.some(t=>t.type===e),s=a.find(e=>e.type===`effort`&&typeof e.value==`string`),c=o(`duration`)&&!o(`rep`)?`clock`:i.completionReason===`user-advance`?`next`:null;if(c){if(c===`clock`&&i.completionReason===`user-advance`){let t=(a.find(e=>e.type===`duration`&&typeof e.value==`number`)?.value??0)-(e.ended-e.started);t>0&&r.push(t)}n.push({start:e.started-t,end:e.ended-t,kind:c,label:s?.value??`Line ${i.line+1}`})}}if(n.length===0)return null;let i=r.reduce((e,t)=>e+t,0);return{segments:n,totalMs:Number.isFinite(e.duration)&&e.duration>0?e.duration:Math.max(...n.map(e=>e.end)),impatienceMs:i,impatiences:r,reactions:n.filter(e=>e.kind===`next`).map(e=>e.end-e.start)}}var m2=e=>{let t=Math.max(0,Math.round(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},h2=e=>`${(Math.round(e/100)/10).toFixed(1)}s`;function g2({onRun:e}){return(0,W.jsxs)(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-4 p-8 text-center`,"data-testid":`tour-insights-empty`,children:[(0,W.jsx)(`p`,{className:`max-w-sm text-sm leading-relaxed text-muted-foreground`,children:`Run the workout and this window turns your run into data — rest vs. work, how fast you answered the clock, round by round.`}),(0,W.jsxs)(`button`,{type:`button`,onClick:e,"data-testid":`tour-insights-run`,className:`inline-flex min-h-11 items-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-semibold text-primary-foreground shadow transition-colors hover:bg-primary/90`,children:[(0,W.jsx)(pn,{className:`size-4`}),`Run to view the results`]})]})}function _2({result:e,onRun:t}){let n=(0,U.useMemo)(()=>e?p2(e):null,[e]);if(!e||!n)return(0,W.jsx)(g2,{onRun:t});let{segments:r,totalMs:i,impatienceMs:a,impatiences:o,reactions:s}=n,c=s.length>0?s.reduce((e,t)=>e+t,0)/s.length:0,l=s.length>0?Math.max(...s):0,u=o.length>0?Math.max(...o):0;return(0,W.jsxs)(`div`,{className:`flex h-full w-full flex-col gap-4 overflow-y-auto p-4`,"data-testid":`tour-insights`,children:[(0,W.jsxs)(`div`,{"data-testid":`tour-insights-timeline`,children:[(0,W.jsx)(`div`,{className:`flex h-3 w-full overflow-hidden rounded-full border border-border/60 bg-muted/40`,children:r.map((e,t)=>(0,W.jsx)(`div`,{title:`${e.label} — ${e.kind===`clock`?`countdown`:`to Next`} ${m2(e.end-e.start)}`,className:`h-full`,style:{flexGrow:e.end-e.start,flexBasis:0,backgroundColor:e.kind===`clock`?`hsl(var(--metric-rest))`:`hsl(var(--metric-time))`,marginLeft:+(t>0)}},t))}),(0,W.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-4 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-rest))`}}),`Countdown`]}),(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-time))`}}),`To Next click`]}),(0,W.jsxs)(`span`,{className:`ml-auto`,children:[m2(i),` total`]})]})]}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{"data-testid":`tour-insights-impatience`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,W.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Impatience Score`}),(0,W.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:h2(a)}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.length===0?`every countdown ran to zero`:`${o.length} early click${o.length===1?``:`s`}${o.length>1?` · worst ${h2(u)}`:``}`})]}),(0,W.jsxs)(`div`,{"data-testid":`tour-insights-reaction`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,W.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Reaction Time`}),(0,W.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:s.length>0?h2(c):`—`}),(0,W.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[s.length,` click`,s.length===1?``:`s`,s.length>1?` · slowest ${h2(l)}`:``]})]})]})]})}var v2=864e5;function y2(e){let t=new Date(e);return Math.round(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())/v2)}function b2(e,t){let n=[...e.keys()].filter(e=>e<=t);if(n.length===0)return[];let r=Math.min(...n),i=t=>e.get(t)??0,a=[];for(let e=r;e<=t;e++){let t=0,n=0;for(let r=0;r<28;r++){let a=i(e-r);n+=a,r<7&&(t+=a)}let r=t/7,o=n/28,s=0;for(let t=0;t<7;t++){let n=i(e-t)-r;s+=n*n}let c=Math.sqrt(s/7),l={day:e};o>0&&(l.acwr=r/o),c>0&&(l.monotony=r/c,l.strain=l.monotony*t),(l.acwr!==void 0||l.monotony!==void 0)&&a.push(l)}return a}var x2=864e5;function S2(e){return Math.round(e*10)/10}function C2(e,t,n=9){let r=new Date(e-t*x2);return r.setHours(n,0,0,0),r.getTime()}function w2(e,t,n,r,i,a={}){let o={canonicalKey:i};a.effortSlug&&(o.effortSlug=a.effortSlug),a.discipline&&(o.effortDiscipline=a.discipline),a.intensityTier&&(o.effortIntensityTier=a.intensityTier),e.push({id:e.length,outputType:`analytics`,timeSpan:{started:0},metrics:[{type:q.Label,value:t,origin:`analyzed`},{type:q.Metric,value:n,unit:r,origin:`analyzed`,metadata:o}],sourceBlockKey:``,stackLevel:0})}var T2=new Set([`tis`,`calc.acwr`,`calc.adherence`,`calc.ef`,`calc.pct1rm`]);function E2(e,t){return qg(e,{noteId:t.noteId,resultId:t.resultId,blockId:`example-block`,blockVersion:1,blockContentId:t.blockContentId,origin:`journal`,workoutTimestamp:t.timestamp}).map(e=>{let t=e.metrics[0];if(!t||!(`metadata`in t))return e;let n=t.metadata?.canonicalKey;return typeof n!=`string`||!T2.has(n)||typeof t.value!=`number`?e:{...e,reducerStats:{observedCount:1,sum:t.value,min:t.value,max:t.value}}})}function D2(e=Date.now()){let t=[],n=new Map,r=[],i=[],a=(e,t)=>{let r=y2(e);n.set(r,(n.get(r)??0)+t)};for(let n=0;n<16;n++){let o=(15-n)*7+1,s=C2(e,o);{let e=[{slug:`back-squat`,top:100+4*n,reps:5,tis:12.5},{slug:`bench-press`,top:80+2.5*n,reps:5,tis:10},{slug:`deadlift`,top:140+4*n,reps:3,tis:8.4}],r=[],i=0,o=0;for(let t of e){let e=t.reps*t.top;i+=e,o+=t.tis;let n={effortSlug:t.slug,discipline:`strength`,intensityTier:`high`};w2(r,`Total reps`,t.reps,`reps`,`totalReps`,n),w2(r,`Training intensity score`,t.tis,`pts`,`tis`,n),w2(r,`Total volume`,e,`kg`,`totalVolume`,n),w2(r,`Estimated 1RM`,S2(t.top*(1+t.reps/30)),`kg`,`calc.e1rm`,n),w2(r,`%1RM intensity`,S2(100/(1+t.reps/30)),`%`,`calc.pct1rm`,n)}let c=S2(i/100+13+o/10);w2(r,`Session load`,c,`AU`,`sessionLoad`,{discipline:`strength`,intensityTier:`high`}),t.push(...E2(r,{noteId:`example-strength-w${n}`,resultId:`example-strength-w${n}-r`,blockContentId:`example-content-strength`,timestamp:s})),a(s,c)}let c=C2(e,o+2);{let e=[],r;if(n%3==0){r=`high`;for(let[t,n,i,a]of[[`thruster`,45,2.2,42.5],[`pull-up`,45,1.6,0]]){let o={effortSlug:t,discipline:a?`strength`:`gymnastics`,intensityTier:r};w2(e,`Total reps`,n,`reps`,`totalReps`,o),w2(e,`Training intensity score`,S2(n*i),`pts`,`tis`,o),a&&w2(e,`Total volume`,n*a,`kg`,`totalVolume`,o)}}else if(n%3==1){r=`moderate`;let t=16+n%5;for(let[n,i,a]of[[`pull-up`,5,1.5],[`push-up`,10,1.2],[`air-squat`,15,1.1]]){let o=t*i,s={effortSlug:n,discipline:`gymnastics`,intensityTier:r};w2(e,`Total reps`,o,`reps`,`totalReps`,s),w2(e,`Training intensity score`,S2(o*a),`pts`,`tis`,s)}}else{r=`moderate`;for(let[t,n,i]of[[`double-under`,150,.5],[`sit-up`,150,1.3]]){let a={effortSlug:t,discipline:`gymnastics`,intensityTier:r};w2(e,`Total reps`,n,`reps`,`totalReps`,a),w2(e,`Training intensity score`,S2(n*i),`pts`,`tis`,a)}}let i=S2(30.6);w2(e,`Session load`,i,`AU`,`sessionLoad`,{intensityTier:r}),t.push(...E2(e,{noteId:`example-conditioning-w${n}`,resultId:`example-conditioning-w${n}-r`,blockContentId:`example-content-conditioning`,timestamp:c})),a(c,i)}let l=C2(e,o+4,8);if(n%4==1)r.push(y2(l));else{let e=6e3+100*n,r=S2(e/2.8),o=[],s={effortSlug:`running`,discipline:`running`,intensityTier:`low`};w2(o,`Total distance`,e,`m`,`totalDistance`,s),w2(o,`Elapsed time`,r,`s`,`elapsed`,s),w2(o,`Training intensity score`,r,`pts`,`tis`,s);let c=S2(r/10);w2(o,`Session load`,c,`AU`,`sessionLoad`,{intensityTier:`low`}),t.push(...E2(o,{noteId:`example-run-w${n}`,resultId:`example-run-w${n}-r`,blockContentId:`example-content-run`,timestamp:l})),a(l,c),i.push({day:y2(l),pace:e/r})}let u=C2(e,o+6,10);{let e=4e3+50*n,r=S2(e/2),i=[],o={effortSlug:`rowing`,discipline:`rowing`,intensityTier:`moderate`};w2(i,`Total distance`,e,`m`,`totalDistance`,o),w2(i,`Elapsed time`,r,`s`,`elapsed`,o),w2(i,`Training intensity score`,r,`pts`,`tis`,o);let s=S2(r/10);w2(i,`Session load`,s,`AU`,`sessionLoad`,{intensityTier:`moderate`}),t.push(...E2(i,{noteId:`example-row-w${n}`,resultId:`example-row-w${n}-r`,blockContentId:`example-content-row`,timestamp:u})),a(u,s)}}let o=Math.max(...n.keys()),s=(e,t=10)=>{let n=new Date(e*x2);return n.setHours(t,0,0,0),n.getTime()},c=(e,n,r)=>{let i=[];for(let[e,t,n]of r)w2(i,e,t,n,e);t.push(...E2(i,{noteId:`example-calc`,resultId:e,blockContentId:`example-content-calc`,timestamp:n}))};for(let e of b2(n,o))e.acwr!==void 0&&c(`example-calc-d${e.day}`,s(e.day),[[`calc.acwr`,S2(e.acwr),`ratio`]]);let l=0,u=0,d=Math.min(...n.keys());for(let e=d;e<=o;e++){let t=n.get(e)??0;l+=(t-l)/42,u+=(t-u)/7,n.has(e)&&c(`example-calc-pmc-d${e}`,s(e),[[`calc.ctl`,S2(l),`AU`],[`calc.atl`,S2(u),`AU`],[`calc.tsb`,S2(l-u),`AU`]])}let f=new Set([...n.keys()]);for(let e of r)f.add(e);for(let e of f){let t=+!!n.has(e);c(`example-calc-adh-d${e}`,s(e,7),[[`calc.adherence`,t,`ratio`]])}for(let e of i)c(`example-calc-ef-d${e.day}`,s(e.day,8),[[`calc.ef`,S2(e.pace/141*1e5),`pts`]]);return t}function O2(e=Date.now()){return new j_(Ov(D2(e)))}var k2=null;function A2(){return k2??=O2()}var j2=[4,8,16],M2={parse(e){let t=Number.parseInt(e,10);return j2.includes(t)?t:null},serialize(e){return String(e)},withDefault(e){return{...this,defaultValue:e}}};function N2(){return Kt(`weeks`,M2.withDefault(16))}function P2(e){let t=e.trim().split(/\s+/).filter(e=>e!==``);if(t.length===0)return;let n={};for(let e of t){let t=e.indexOf(`=`);if(t===-1)continue;let r=e.slice(0,t),i=e.slice(t+1);i.startsWith(`"`)&&i.endsWith(`"`)&&i.length>=2&&(i=i.slice(1,-1)),n[r]=i}return Object.keys(n).length===0?void 0:n}var F2=[{label:`Auto`,spanCols:void 0,spanFull:!1},{label:`1 col`,spanCols:1,spanFull:!1},{label:`2 cols`,spanCols:2,spanFull:!1},{label:`4 cols`,spanCols:4,spanFull:!1},{label:`Full row`,spanCols:void 0,spanFull:!0}],I2=300;function L2({open:e,...t}){return e?(0,W.jsx)(R2,{...t}):null}function R2({onClose:e,mode:t,initialWql:n,initial:r,subsetQuery:i,destination:a,executor:o,rangeStart:s,rangeEnd:c,preferredUnit:l,tokenValues:u,onApply:d,footerExtra:f,applyLabel:p=t===`edit`?`Apply changes`:`Add widget`}){let m=t===`inspect`,[h,g]=(0,U.useState)(n),[_,v]=(0,U.useState)(r?.title??``),[y,b]=(0,U.useState)(r?.question??``),[x,S]=(0,U.useState)(r?.type||`table`),[C,w]=(0,U.useState)({spanCols:r?.spanCols,spanFull:r?.spanFull}),[T,E]=(0,U.useState)(Object.entries(r?.attributes??{}).map(([e,t])=>`${e}=${t}`).join(` `)),[D,O]=(0,U.useState)(!1),[k,A]=(0,U.useState)(()=>!X(n).error),[j,M]=(0,U.useState)(null),N=(0,U.useMemo)(()=>X(h.trim()),[h]),P=x===``?`table`:x,F=!N.error&&h.trim()!==``&&(Bm(N)?P===`table`||P===`list`:P!==`list`),[I,L]=(0,U.useState)({status:`idle`}),ee=(0,U.useRef)(0);(0,U.useEffect)(()=>{if(!F||!o){L(e=>e.status===`ok`?e:{status:`idle`});return}let e=tv(h.trim(),u??{});if(e.missing.length>0){L({status:`blocked`,message:K_(e.missing)});return}let t=++ee.current;L({status:`loading`});let n=setTimeout(()=>{o.runQuery(e.query,{rangeStart:s,rangeEnd:c,preferredUnit:l}).then(e=>{ee.current===t&&L({status:`ok`,result:e})}).catch(e=>{ee.current===t&&L({status:`error`,message:e instanceof Error?e.message:String(e)})})},I2);return()=>clearTimeout(n)},[h,F,o,s,c,l,u]);let te=!F&&I.status===`ok`,ne=F&&k,R=async()=>{if(!(!ne||!d||D)&&!(X(h.trim()).error||h.trim()===``)){O(!0),M(null);try{await d({title:_.trim()||void 0,question:y.trim()||void 0,type:x===`table`?``:x,spanCols:C.spanFull?void 0:C.spanCols,spanFull:C.spanFull||void 0,wql:h.trim(),attributes:P2(T)}),e()}catch(e){M(e instanceof Error?e.message:String(e))}finally{O(!1)}}};return(0,W.jsx)(OC,{open:!0,onClose:e,presentation:`sheet`,title:t===`inspect`?`Inspect widget`:t===`edit`?`Edit widget`:`Add widget`,description:m?`Read-only — clone the dashboard to edit this widget.`:`Dataset, calculation, visualization, preview — then apply.`,footer:m&&!f?void 0:(0,W.jsxs)(W.Fragment,{children:[f,(0,W.jsx)(`div`,{className:`flex-1`}),!m&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,onClick:e,className:`min-h-12 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground rounded-lg border border-border hover:bg-muted transition-colors`,children:`Cancel`}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`widget-composer-apply`,disabled:!ne||D,title:N.error?N.error:void 0,onClick:()=>void R(),className:`min-h-12 px-3 py-1.5 text-xs font-medium text-primary-foreground bg-primary hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed rounded-lg shadow transition-colors`,children:D?`Applying…`:p})]})]}),children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[i!==void 0&&(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Dataset — the subset`}),i?(0,W.jsx)(`code`,{className:`block rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-xs text-foreground break-all`,"data-testid":`widget-composer-subset`,children:i}):(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`widget-composer-subset`,children:`No subset — the calculation runs over the whole store.`})]}),a,(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Calculation`}),m?(0,W.jsx)(`code`,{className:`block rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-xs text-foreground break-all`,"data-testid":`widget-composer-query`,children:h}):(0,W.jsx)(Kw,{query:h,onQueryChange:g,onValidationChange:e=>A(e.valid),showDiagnostics:!0,...o?{execute:e=>o.runQuery(e.raw,{rangeStart:s,rangeEnd:c,preferredUnit:l})}:{}}),!m&&h.trim()!==``&&(0,W.jsx)(`code`,{className:`mt-1.5 block rounded-md border border-primary/30 bg-primary/[0.04] px-3 py-2 font-mono text-xs text-foreground break-all`,"data-testid":`widget-composer-wql`,children:h.trim()}),!m&&(0,W.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Visualization`}),(0,W.jsx)(`select`,{value:x,onChange:e=>S(e.target.value),"data-testid":`widget-composer-type`,className:`min-h-12 rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary sm:min-h-0`,children:H_.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})]})]}),!m&&(0,W.jsxs)(`section`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Title`}),(0,W.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`Weekly volume`,"data-testid":`widget-composer-title`,className:`rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,W.jsxs)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:[`Coaching question `,(0,W.jsx)(`span`,{className:`normal-case font-normal`,children:`(optional)`})]}),(0,W.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`How much work per week?`,"data-testid":`widget-composer-question`,className:`rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Size`}),(0,W.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-lg border border-border bg-card p-1 self-start`,children:F2.map(e=>{let t=e.spanFull?C.spanFull===!0:e.spanCols==null?!C.spanFull&&C.spanCols==null:!C.spanFull&&C.spanCols===e.spanCols;return(0,W.jsx)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>w(e.spanFull?{spanFull:!0}:{spanCols:e.spanCols}),className:`text-xs px-2.5 py-1 rounded-md transition-colors ${t?`bg-primary text-primary-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:e.label},e.label)})})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 sm:col-span-2`,children:[(0,W.jsxs)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:[`Parameters `,(0,W.jsx)(`span`,{className:`normal-case font-normal`,children:`(goal targets, space-separated)`})]}),(0,W.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`300 200`,"data-testid":`widget-composer-params`,className:`rounded-lg border border-border bg-card px-3 py-1.5 text-sm font-mono text-foreground focus:outline-none focus:border-primary`})]})]}),m&&(0,W.jsxs)(`section`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs text-muted-foreground`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Title`}),(0,W.jsx)(`div`,{className:`text-foreground`,children:r?.title||`—`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Question`}),(0,W.jsx)(`div`,{className:`text-foreground`,children:r?.question||`—`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Type`}),(0,W.jsx)(`div`,{className:`font-mono text-foreground`,children:x||`table`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Size`}),(0,W.jsx)(`div`,{className:`font-mono text-foreground`,children:r?.spanFull?`full row`:r?.spanCols?`${r.spanCols} cols`:`default`})]})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5 flex items-center gap-2`,children:[`Preview`,te&&(0,W.jsx)(`span`,{"data-testid":`widget-preview-stale`,className:`font-medium normal-case tracking-normal text-amber-600`,children:`stale — showing the last valid query`})]}),(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/50 p-3 h-56 overflow-hidden`,children:[I.status===`idle`&&(F?(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-muted-foreground`,children:`Preview runs as you compose…`}):(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-destructive font-mono px-4 text-center`,children:N.error?N.error:Bm(N)?`find: queries return things — use a table or list widget instead`:`Compose a calculation to preview.`})),I.status===`loading`&&(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-muted-foreground`,children:`Running preview…`}),I.status===`blocked`&&(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-destructive font-mono px-4 text-center`,children:I.message}),I.status===`error`&&(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-destructive font-mono px-4 text-center`,children:I.message}),I.status===`ok`&&(0,W.jsx)(DS,{type:x,result:I.result,label:_.trim()||void 0,unit:l,attributes:P2(T)})]})]}),j&&(0,W.jsx)(`p`,{role:`alert`,"data-testid":`widget-composer-error`,className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive font-mono`,children:j})]})})}function z2({boardSlug:e}){let t=A2(),n=YO(),r=(0,U.useMemo)(()=>n?uP(n):[],[n]),i=(0,U.useMemo)(()=>r.find(t=>t.slug===e)??r[0],[r,e]),a=(0,U.useMemo)(()=>{if(!i?.rawContent)return null;try{let{meta:e,sections:t}=uv(i.rawContent);return iv(t,e)}catch{return null}},[i]),[o,s]=N2(),[c,l]=(0,U.useMemo)(()=>{let e=Date.now();return[e-o*7*864e5,e]},[o]),[u,d]=(0,U.useState)(null);return(0,W.jsxs)(`div`,{className:`flex h-full w-full flex-col`,"data-testid":`tour-session-dashboard`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-5 pt-4`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`truncate text-[11px] font-semibold uppercase tracking-wide text-primary`,children:i?.title??e}),(0,W.jsx)(`span`,{"data-testid":`tour-session-dashboard-source`,className:`flex-none rounded-full border border-border bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground`,children:`Example data`})]}),(0,W.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,W.jsx)(US,{weeks:o,onWeeksChange:s})})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto px-5 pb-5 pt-3 [&_[data-testid=dashboard-view]>div.grid]:grid-cols-1 [&_[data-testid=dashboard-view]>div.grid]:sm:grid-cols-2 [&_[data-testid=dashboard-view]>div.grid]:lg:grid-cols-2 [&_[data-testid=dashboard-view]>div.grid>*]:col-span-1`,children:a?(0,W.jsx)(HS,{document:a,executor:t,onInspectWidget:d,rangeStart:c,rangeEnd:l}):(0,W.jsx)(`p`,{className:`pt-8 text-center text-sm text-muted-foreground`,children:`Loading board…`})}),(0,W.jsx)(L2,{open:u!==null,onClose:()=>d(null),mode:`inspect`,initialWql:u?.body??`sum:totalVolume{}`,initial:u?{title:u.title,question:u.question,type:u.type,spanCols:u.spanCols,spanFull:u.spanFull,attributes:u.attributes}:void 0,executor:t,rangeStart:c,rangeEnd:l,tokenValues:a?Q_(a.tokens):void 0,onApply:void 0})]})}var B2=[`analytics`,`boards`],V2={analytics:{index:`01`,heading:`h2`,title:`Session Insights`,blurb:`Run the workout and this window turns your run into data — rest vs. work, how fast you answered the clock, round by round.`},boards:{index:`02`,heading:`h2`,title:`One Run Becomes Many`,blurb:`Dashboards let you visualise your progress — every recorded run rolls up into analytics boards. Aggregate results across flexible search criteria, from note frontmatter to session metrics: one run becomes many insights.`}};function H2({scope:e}){let t=V2[e],n=t.heading;return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(n,{className:`flex items-baseline gap-4 text-[clamp(26px,3.2vw,44px)] font-extrabold leading-[1.1] tracking-[-0.03em]`,children:[t.index&&(0,W.jsx)(`span`,{className:`font-mono text-xs font-normal tracking-normal text-muted-foreground`,children:t.index}),(0,W.jsx)(`span`,{children:t.title})]}),(0,W.jsx)(`p`,{className:`mt-3 max-w-xl text-[clamp(14px,1.2vw,18px)] leading-[1.65] text-muted-foreground`,children:t.blurb})]})}var U2=[{id:`road-to-560-total`,label:`Road to 560 Total`,title:`Road to 560 Total`},{id:`polarized-base-marathon`,label:`Polarized Base`,title:`Polarized Base Marathon`}];function W2({onClick:e}){return(0,W.jsxs)(`button`,{type:`button`,onClick:e,title:`Back to the editor`,"data-testid":`tour-pane-back-to-editor`,className:`flex shrink-0 items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,W.jsx)(Fe,{className:`size-3`}),`Editor`]})}function G2({session:e,onRun:t,onBackToEditor:n}){let[r,i]=(0,U.useState)(`analytics`),[a,o]=(0,U.useState)(0),s=U2[a],c=(0,U.useRef)(new Map);(0,U.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target.getAttribute(`data-scope`);(e===`analytics`||e===`boards`)&&i(e)}},{rootMargin:`-45% 0px -45% 0px`});return c.current.forEach(t=>e.observe(t)),()=>e.disconnect()},[]);let l=e=>t=>{t?c.current.set(e,t):c.current.delete(e)},u=r=>r===`analytics`?(0,W.jsx)(zq,{title:`Session Insights`,className:`h-[460px]`,headerActions:(0,W.jsx)(W2,{onClick:n}),children:(0,W.jsx)(_2,{result:e,onRun:t})}):(0,W.jsxs)(`div`,{className:`flex h-full flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,W.jsx)(`div`,{role:`tablist`,"aria-label":`Dashboard slides`,className:`flex flex-wrap gap-1 rounded-lg border border-border bg-muted/30 p-1`,children:U2.map((e,t)=>(0,W.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":a===t,"aria-pressed":a===t,"data-testid":`dashboard-slide-tab-${e.id}`,onClick:()=>o(t),className:G(`min-h-11 rounded-md px-3 py-1.5 text-xs font-semibold transition-colors`,a===t?`bg-background text-foreground shadow`:`text-muted-foreground hover:text-foreground`),children:e.label},e.id))}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+U2.length-1)%U2.length),"aria-label":`Previous dashboard`,"data-testid":`dashboard-slide-prev`,className:`flex size-11 items-center justify-center rounded-md border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:(0,W.jsx)(Un,{className:`size-4`})}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+1)%U2.length),"aria-label":`Next dashboard`,"data-testid":`dashboard-slide-next`,className:`flex size-11 items-center justify-center rounded-md border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:(0,W.jsx)(wn,{className:`size-4`})})]})]}),(0,W.jsx)(zq,{title:s.title,className:`min-h-0 flex-1`,headerActions:(0,W.jsx)(W2,{onClick:n}),children:(0,W.jsx)(`div`,{className:`flex h-full w-full flex-col`,role:`tabpanel`,children:(0,W.jsx)(z2,{boardSlug:s.id})},s.id)}),(0,W.jsxs)(`p`,{className:`text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground/60`,children:[a+1,` / `,U2.length]})]}),d=(0,W.jsx)(`div`,{"data-testid":`tour-sticky-pane`,className:`sticky top-[72px] hidden h-[calc(100dvh-72px)] flex-col items-center justify-center self-start lg:top-[104px] lg:flex lg:h-[calc(100dvh-104px)]`,children:(0,W.jsx)(`div`,{className:`relative w-full max-w-[700px]`,children:(0,W.jsx)(`div`,{className:`relative h-[460px]`,children:B2.map(e=>(0,W.jsx)(`div`,{"aria-hidden":r!==e,"data-scope-active":r===e,className:G(`absolute inset-0 transition-opacity duration-500`,r===e?`opacity-100`:`invisible opacity-0`),children:u(e)},e))})})}),f=(e,t)=>(0,W.jsx)(`div`,{ref:l(e),"data-scope":e,className:`flex min-h-[85vh] flex-col justify-center scroll-mt-[104px]`,...t,children:(0,W.jsx)(H2,{scope:e})}),p=e=>(0,W.jsxs)(`div`,{"data-testid":`tour-step-mobile-${e}`,"data-scope":e,className:`flex flex-col gap-4 lg:hidden`,children:[(0,W.jsx)(H2,{scope:e}),(0,W.jsx)(`div`,{className:`h-[460px]`,children:u(e)})]});return(0,W.jsx)(`section`,{id:`tour-section-insights`,"data-testid":`tour-section-insights`,className:`border-b border-border/60`,children:(0,W.jsxs)(`div`,{className:`mx-auto grid max-w-[1500px] gap-10 px-5 py-14 lg:grid-cols-2 lg:gap-16 lg:px-12 lg:py-0 xl:px-16 2xl:max-w-[1720px]`,children:[(0,W.jsxs)(`div`,{className:`hidden flex-col lg:flex`,children:[(0,W.jsx)(`div`,{id:`tour-scroll-target-insights`,className:`scroll-mt-[72px] lg:scroll-mt-[104px]`,children:f(`analytics`)}),f(`boards`,{id:`tour-section-boards`,"data-testid":`tour-section-boards`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-12 lg:hidden`,children:[p(`analytics`),p(`boards`)]}),d]})})}function K2(e){switch(e.phase){case`checking`:return`Checking the seed…`;case`fetching`:return`Downloading ${e.chunkId??`notebook`}…`;case`applying`:return`Importing ${e.chunkId??`notebook`}…`;case`committed`:return`Committed ${e.chunkId??`notebook`}`;case`finalizing`:return`Finalizing checkpoints…`;case`finished`:return`Done`;default:return e.phase}}function q2(e){if(!e||e.phase===`checking`||e.phase===`finished`)return null;let t=[];return typeof e.completedRecords==`number`&&typeof e.totalRecords==`number`&&t.push(`${e.completedRecords} / ${e.totalRecords} records`),e.totalChunks>0&&t.push(`${e.completedChunks} / ${e.totalChunks} notebooks`),t.length>0?t.join(` · `):null}function J2(e){let t=e.match(/^notebook\.(.+)$/);return t?{slug:t[1]}:null}function Y2(e){let t=e.items.map(e=>e.date).filter(e=>!!e).sort();return{packageId:`local-notebooks-${e.id}`,slug:e.id,label:e.name,description:e.description,image:e.image,categories:e.categories,sourceLabel:`Local`,href:`/notebook/${encodeURIComponent(e.id)}`,itemCount:e.items.length,...t.length>0?{latestDate:t[t.length-1],firstDate:t[0]}:{},...e.readme===void 0?{}:{readme:e.readme},installed:!0}}function X2(e,t,n){let r=[],i=new Map;if(t)for(let e of DO(`notebooks`,t))i.set(e.id,e),r.push(Y2(e));let a=e.map(e=>{let t=J2(e.chunkId);if(!t)return null;let r=i.get(t.slug),a=xA(e.feedId),o=(r?.items??[]).map(e=>e.date).filter(e=>!!e).sort();return{packageId:e.id,feedId:e.feedId,chunkId:e.chunkId,slug:t.slug,label:e.label,description:e.description||r?.description,image:r?.image,categories:r?.categories??[],sourceLabel:a?.label??e.feedId,...a?.repositoryUrl?{repositoryUrl:a.repositoryUrl}:{},href:`/notebook/${encodeURIComponent(t.slug)}`,itemCount:r?.items.length??0,...o.length>0?{latestDate:o[o.length-1],firstDate:o[0]}:{},...r?.readme===void 0?{}:{readme:r.readme},installed:!!r,subscribed:!n||n(e.feedId,e.chunkId)}}).filter(e=>e!==null),o=new Set(a.map(e=>e.slug));return[...a,...r.filter(e=>!o.has(e.slug)),...Z2(t)]}function Z2(e){return Aa.filter(e=>e.feedEntryId===`core`&&e.slug!==`guides`&&typeof e.seedChunkId==`string`).map(t=>{let n=`markdown/${t.slug}/`,r=e?Object.keys(e).filter(e=>e.startsWith(n)&&e.endsWith(`.md`)&&!e.endsWith(`/README.md`)):[];return{packageId:`core-${t.slug}`,feedId:`core`,chunkId:t.seedChunkId,slug:t.slug,label:t.name,description:t.description,categories:[],sourceLabel:`Core`,href:t.href,itemCount:r.length,installed:e?r.length>0:!1,subscribed:!0}})}function Q2(e,t){let n={},r=[],i=new Set(t.map(e=>e.id));for(let t of e)t.feedId&&i.has(t.feedId)?(n[t.feedId]??=[]).push(t):r.push(t);let a=[];for(let e of t){let t=n[e.id];t?.length&&a.push({feed:e,label:e.label,...e.description?{description:e.description}:{},url:e.url,...e.repositoryUrl?{repositoryUrl:e.repositoryUrl}:{},notebooks:t})}return r.length>0&&a.push({label:`Local`,notebooks:r}),a}function $2(e,t,n,r){return Q2(X2(e,t,r),n).map(e=>{let t=e.notebooks.map(e=>e.latestDate).filter(e=>!!e).sort();return{feedId:e.feed?.id,slug:e.feed?.id??`local`,label:e.label,...e.description?{description:e.description}:{},...e.url?{url:e.url}:{},...e.repositoryUrl?{repositoryUrl:e.repositoryUrl}:{},notebooks:e.notebooks,itemCount:e.notebooks.reduce((e,t)=>e+t.itemCount,0),installed:e.notebooks.every(e=>e.installed),subscribed:e.notebooks.some(e=>e.subscribed),...t.length>0?{latestDate:t[t.length-1]}:{},href:`/notebooks`}})}function e4(e,t){let n=t.text?.trim().toLowerCase();return e.filter(e=>t.feedId&&e.feedId!==t.feedId||t.subscribedOnly&&!e.notebooks.some(e=>e.subscribed)?!1:!n||e.label.toLowerCase().includes(n)||(e.description?.toLowerCase().includes(n)??!1)||e.notebooks.some(e=>e.label.toLowerCase().includes(n)||(e.description?.toLowerCase().includes(n)??!1)))}function t4(e,t){let n=[...e];switch(t){case`name`:return n.sort((e,t)=>e.label.localeCompare(t.label));case`size`:return n.sort((e,t)=>t.itemCount-e.itemCount||e.label.localeCompare(t.label));default:return n.sort((e,t)=>e.latestDate&&t.latestDate?t.latestDate.localeCompare(e.latestDate):e.latestDate?-1:t.latestDate?1:e.label.localeCompare(t.label))}}var n4=[`bg-rose-500/12 text-rose-600 dark:text-rose-400`,`bg-amber-500/12 text-amber-600 dark:text-amber-400`,`bg-emerald-500/12 text-emerald-600 dark:text-emerald-400`,`bg-sky-500/12 text-sky-600 dark:text-sky-400`,`bg-violet-500/12 text-violet-600 dark:text-violet-400`,`bg-cyan-500/12 text-cyan-600 dark:text-cyan-400`];function r4(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return n4[Math.abs(t)%n4.length]}function i4(e){return(e.match(/[a-z0-9]/i)?.[0]??`•`).toUpperCase()}function a4(e){if(!e)return null;let t=new Date(`${e}T00:00:00`);return isNaN(t.getTime())?null:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}var o4=4;function s4({feed:e,testId:t=`feed-card`,className:n,onImport:r,importing:i,busy:a,status:o,onToggleNotebookSubscription:c}){let[l,u]=r4(e.slug).split(` `),d=a4(e.latestDate),f=e.notebooks.slice(0,o4),p=e.notebooks.length-f.length,m=e.installed&&e.feedId?e.href:void 0,g=e.notebooks.find(e=>e.image)?.image,_=(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70`,children:[(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[e.notebooks.length,` `,e.notebooks.length===1?`notebook`:`notebooks`]}),e.installed&&e.itemCount>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[e.itemCount,` `,e.itemCount===1?`item`:`items`]})]}),e.installed&&d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[`updated `,d]})]}),!e.installed&&(0,W.jsx)(`span`,{"aria-hidden":!0,children:`·`}),!e.installed&&(0,W.jsx)(`span`,{children:`not imported`})]}),v=(0,W.jsx)(`div`,{className:G(`relative overflow-hidden bg-muted/40 aspect-[16/10]`,l),children:g?(0,W.jsx)(`img`,{src:g,alt:``,loading:`lazy`,className:`absolute inset-0 size-full object-cover`}):(0,W.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:[(0,W.jsx)(`span`,{className:G(`text-7xl font-black tracking-tighter select-none`,u),"aria-hidden":!0,children:i4(e.label)}),(0,W.jsx)(s,{className:G(`absolute bottom-4 right-4 size-6 opacity-50`,u),"aria-hidden":!0})]})});return(0,W.jsxs)(`article`,{"data-testid":t,"data-installed":e.installed,className:G(`group relative flex flex-col overflow-hidden rounded-2xl border border-border bg-card`,`transition-colors hover:border-foreground/25 focus-within:border-foreground/25`,n),children:[m?(0,W.jsx)(_n,{to:m,"data-testid":`${t}-open`,className:`block outline-none`,"aria-label":`Open the library for ${e.label}`,children:v}):v,(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col gap-2 p-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,W.jsx)(`h3`,{className:`min-w-0 text-sm font-bold leading-snug text-foreground`,children:m?(0,W.jsx)(_n,{to:m,className:`transition-colors hover:text-primary`,children:e.label}):e.label}),m?(0,W.jsx)(_n,{to:m,"data-testid":`${t}-cta`,"aria-label":`Open the library for ${e.label}`,className:`flex min-h-11 min-w-11 size-11 shrink-0 items-center justify-center rounded-full border border-border text-muted-foreground transition-colors hover:border-primary/50 hover:text-primary`,children:(0,W.jsx)(h,{className:`size-3.5`,"aria-hidden":!0})}):r&&e.feedId?(0,W.jsxs)(`button`,{type:`button`,"data-testid":`${t}-import`,disabled:i||a,onClick:()=>r(e.feedId),className:G(`flex min-h-11 shrink-0 items-center gap-1.5 rounded-full border px-4`,`text-[10px] font-black uppercase tracking-widest`,`border-primary/30 bg-primary/10 text-primary`,`transition-colors hover:bg-primary/20`,`disabled:cursor-wait disabled:opacity-60`),children:[i?(0,W.jsx)(or,{className:`size-3 animate-spin`,"aria-hidden":!0}):(0,W.jsx)(Ee,{className:`size-3`,"aria-hidden":!0}),i?`Importing`:`Import feed`]}):null]}),e.description&&(0,W.jsx)(`p`,{className:`line-clamp-2 text-xs leading-relaxed text-muted-foreground`,children:e.description}),e.notebooks.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`${t}-notebooks`,children:[f.map(n=>(0,W.jsxs)(`span`,{"data-testid":`${t}-notebook-${n.packageId}`,className:G(`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[9px] font-black uppercase tracking-widest transition-colors`,n.subscribed?`border-emerald-500/40 bg-emerald-500/10 text-emerald-600`:`border-border text-muted-foreground/70`),children:[n.installed?(0,W.jsx)(_n,{to:n.href,className:`hover:text-primary`,children:n.label}):(0,W.jsx)(`span`,{children:n.label}),c&&e.feedId&&n.chunkId&&(0,W.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),c(e.feedId,n.chunkId,!n.subscribed)},title:n.subscribed?`Unsubscribe ${n.label}`:`Subscribe ${n.label}`,"aria-label":n.subscribed?`Unsubscribe ${n.label}`:`Subscribe ${n.label}`,"data-testid":`${t}-notebook-toggle-${n.packageId}`,className:`relative -my-3 -mr-2.5 ml-0.5 inline-flex min-h-11 min-w-11 items-center justify-center font-bold hover:text-foreground`,children:n.subscribed?`✓`:`+`})]},n.packageId)),p>0&&(0,W.jsxs)(`span`,{className:`rounded-full border border-dashed border-border px-2 py-0.5 text-[9px] font-black uppercase tracking-widest text-muted-foreground/60`,children:[`+`,p,` more`]})]}),(0,W.jsxs)(`div`,{className:`mt-auto pt-1`,children:[_,o&&(0,W.jsx)(`p`,{role:o.tone===`error`?`alert`:`status`,"data-testid":`${t}-status`,className:G(`mt-1.5 flex items-start gap-1.5 text-xs`,o.tone===`error`?`text-destructive`:`text-muted-foreground`),children:(0,W.jsx)(`span`,{children:o.text})})]})]})]})}function c4({direction:e,children:t,testId:n,className:r}){let i=(0,U.useRef)(null),a=(0,U.useRef)(null),[o,s]=(0,U.useState)(1),c=Iq(`(prefers-reduced-motion: reduce)`);(0,U.useEffect)(()=>{let e=i.current,t=a.current;if(!e||!t)return;let n=()=>{let n=o*2,r=t.scrollWidth/n;if(r<=0)return;let i=Math.max(1,Math.ceil(e.clientWidth/r));i!==o&&s(i)};n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[o,t]);let l=c?1:o*2;return(0,W.jsx)(`div`,{ref:i,"data-testid":n,className:G(`wod-marquee overflow-hidden`,r),children:(0,W.jsx)(`div`,{ref:a,className:G(`flex w-max`,!c&&`wod-marquee-track`,!c&&e===`left`&&`wod-marquee-track--left`,!c&&e===`right`&&`wod-marquee-track--right`,!c&&e===`alternate`&&`wod-marquee-track--left wod-marquee-track--alternate`),children:Array.from({length:l},(e,n)=>(0,W.jsx)(`div`,{"data-marquee-copy":n,"aria-hidden":n>0,className:`flex shrink-0 items-stretch gap-4 pr-4`,children:t},n))})})}var l4=[{value:`updated`,label:`Updated`},{value:`name`,label:`Name`},{value:`size`,label:`Size`}],u4=`group flex flex-col justify-between rounded-2xl border border-border bg-card p-5 text-left transition-colors hover:border-primary/40 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`;function d4(e){let t=e.icon;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,W.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),(0,W.jsx)(`h3`,{className:`mt-4 text-base font-semibold text-foreground`,children:e.title}),(0,W.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.description})]}),e.note?(0,W.jsx)(`span`,{className:`mt-4 text-xs font-medium text-muted-foreground`,children:e.note}):(0,W.jsxs)(`span`,{className:`mt-4 inline-flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,W.jsx)(`span`,{children:e.action}),(0,W.jsx)(h,{className:`size-4 transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]})]})}function f4(){let e=Vn(),[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(`updated`),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)({}),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(),[p,m]=(0,U.useState)(0);(0,U.useEffect)(()=>yj(()=>m(e=>e+1)),[]);let h=a!==null,g=YO(),_=Iq(`(min-width: 1024px)`),y=(0,U.useMemo)(()=>$2(DA(),g,EA(),(e,t)=>gj(e,t)),[g,p]),b=(0,U.useMemo)(()=>t4(e4(y,{text:t,feedId:d,subscribedOnly:l}),r),[y,t,r,d,l]),x=Math.ceil(b.length/2),S=b.slice(0,x),C=b.slice(x),w=(0,U.useCallback)(()=>{dq.record(fq.libraryOpened)},[]),[T,E]=(0,U.useState)(!0);(0,U.useEffect)(()=>{let e=!1,t=()=>{_M().then(t=>{e||E(t.libraryImported)}).catch(()=>{})};t();let n=yj(t);return()=>{e=!0,n()}},[h]);let D=(0,U.useCallback)(async e=>{if(a)return;o(e);let t=t=>c(n=>({...n,[e]:t}));t({text:`Checking the feed…`,tone:`muted`});try{let n=await hM(e,{onProgress:e=>t({text:K2(e),tone:`muted`})});t(n===`imported`||n===`current`?{text:hj(e,!0)?n===`imported`?`Imported — this feed is available offline.`:`Already up to date.`:`Subscribed for this session only — browser storage is unavailable.`,tone:`muted`}:{text:n===`server-stale`?`Published version is older than stored copy.`:n===`busy`?`Another tab is syncing. Try again shortly.`:`Sync failed. Check connection and try again.`,tone:`error`})}catch(e){t({text:e instanceof Error?e.message:String(e),tone:`error`})}finally{o(null)}},[a]),O=(0,U.useCallback)(async(e,t,n)=>{_j(e,t,n),n&&hM(e,{force:!1})},[]),k=(0,U.useCallback)(async()=>{let t=_P(),n=await CP.create({journalDate:t,title:t,rawContent:``});dq.record(fq.noteCreated),e(TN(n.id))},[e]),A=!!t.trim();return(0,W.jsxs)(`section`,{id:`tour-section-community-feeds`,"data-testid":`tour-jump-section`,className:`flex flex-col border-b border-border bg-muted/20 pb-8 xl:pb-12`,"aria-label":`Library and community feeds`,children:[(0,W.jsx)(T$,{index:`03`,before:`Library & `,accentText:`Community Feeds`,after:``,accent:``,blurb:`Subscribe to a feed — one Markdown repository compiled with npx wod build into a versioned manifest, served from its own GitHub Pages. One Subscribe imports every notebook the feed publishes; browse the feeds below, notebooks and all.`}),(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsxs)(`label`,{className:`relative w-full sm:w-64`,children:[(0,W.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":!0}),(0,W.jsx)(`input`,{type:`search`,value:t,onChange:e=>n(e.target.value),placeholder:`Search feeds…`,"aria-label":`Search feeds`,"data-testid":`package-search-input`,className:`h-11 w-full rounded-full border border-border bg-background pl-9 pr-9 text-sm text-foreground placeholder:text-muted-foreground/50 outline-none transition-colors focus:border-primary/50`}),t&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(``),"aria-label":`Clear search`,className:`absolute right-0 top-1/2 -translate-y-1/2 size-11 inline-flex items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,W.jsx)(we,{className:`size-3.5`})})]}),(0,W.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 cursor-pointer select-none text-muted-foreground hover:text-foreground px-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),"data-testid":`filter-subscribed-only`,className:`size-4 accent-primary rounded`}),(0,W.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-widest`,children:`Subscribed only`})]}),(0,W.jsxs)(`select`,{value:d??``,onChange:e=>f(e.target.value?e.target.value:void 0),"aria-label":`Filter by feed`,"data-testid":`filter-feed-source`,className:`min-h-11 h-11 rounded-full border border-border bg-background px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground outline-none transition-colors hover:border-foreground/25 focus:border-primary/50`,children:[(0,W.jsx)(`option`,{value:``,children:`All feeds`}),EA().map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,W.jsx)(`div`,{className:`ml-auto flex items-center gap-1.5`,role:`group`,"aria-label":`Sort feeds`,children:l4.map(e=>{let t=r===e.value;return(0,W.jsx)(`button`,{type:`button`,"aria-pressed":t,"data-testid":`package-sort-${e.value}`,onClick:()=>i(e.value),className:G(`inline-flex min-h-11 items-center justify-center rounded-full px-3 text-[10px] font-black uppercase tracking-widest transition-colors`,t?`bg-foreground text-background`:`text-muted-foreground hover:text-foreground`),children:e.label},e.value)})})]}),(0,W.jsx)(`div`,{"data-testid":`jump-grid`,className:`mt-6`,children:(0,W.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[T?(0,W.jsx)(_n,{to:`/notebooks`,onClick:w,"data-testid":`jump-library`,className:u4,children:(0,W.jsx)(d4,{icon:v,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`})}):(0,W.jsx)(`div`,{"data-testid":`jump-library`,"aria-disabled":`true`,className:`${u4} cursor-not-allowed opacity-60`,children:(0,W.jsx)(d4,{icon:v,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`,note:`0 feeds synchronized`})}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{k()},"data-testid":`jump-new-note`,className:u4,children:(0,W.jsx)(d4,{icon:Jt,title:`Start your own journal`,description:`Create today's note and log your first workout.`,action:`Create today's note`})})]})})]}),(0,W.jsx)(`div`,{"data-testid":`jump-rows`,className:`mt-6`,children:b.length>0?_?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(c4,{direction:`left`,testId:`jump-row-a`,children:S.map(e=>(0,W.jsx)(s4,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:D,importing:!!e.feedId&&a===e.feedId,busy:h,status:e.feedId?s[e.feedId]:void 0,onToggleNotebookSubscription:O},e.feedId??e.slug))}),C.length>0&&(0,W.jsx)(c4,{direction:`right`,testId:`jump-row-b`,className:`mt-4`,children:C.map(e=>(0,W.jsx)(s4,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:D,importing:!!e.feedId&&a===e.feedId,busy:h,status:e.feedId?s[e.feedId]:void 0,onToggleNotebookSubscription:O},e.feedId??e.slug))})]}):(0,W.jsx)(c4,{direction:`alternate`,testId:`jump-row-mobile`,children:b.map(e=>(0,W.jsx)(s4,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] shrink-0`,onImport:D,importing:!!e.feedId&&a===e.feedId,busy:h,status:e.feedId?s[e.feedId]:void 0,onToggleNotebookSubscription:O},e.feedId??e.slug))}):(0,W.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,W.jsxs)(`div`,{"data-testid":`jump-empty`,className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-border p-10 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-bold text-muted-foreground`,children:`No feeds match your search.`}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground/70`,children:`Try a different term or clear the filters.`}),A&&(0,W.jsx)(`button`,{type:`button`,"data-testid":`jump-clear-filters`,onClick:()=>{n(``),f(void 0),u(!1)},className:`mt-3 h-8 rounded-full border border-border px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground transition-colors hover:border-primary/50 hover:text-primary`,children:`Clear filters`})]})})}),(0,W.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,W.jsx)(`p`,{className:`mt-4 font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground/60 xl:text-[11px]`,children:`— or keep scrolling ↓`})})]})}var p4=`wods/examples/home/welcome-1.md`;function m4({wodFiles:e,theme:t,quests:n}){let r=Iq(`(prefers-reduced-motion: reduce)`),i=pq()?.track;hq(`/`);let a=(0,U.useMemo)(()=>SV(p4,e),[e]),[o,s]=(0,U.useState)(()=>j0()),c=o?.content??a,l=o?o.by?.trim()||`anonymous`:void 0;(0,U.useEffect)(()=>{let e=e=>{let t=e.detail;t?.content&&(s(t),d(t.content))};return window.addEventListener(`wodwiki:home-shared`,e),()=>window.removeEventListener(`wodwiki:home-shared`,e)},[]);let[u,d]=(0,U.useState)(c),f=(0,U.useRef)(u);f.current=u;let p=(0,U.useRef)([]),m=(0,U.useRef)(!1),{run:h,start:g,finalize:_,end:v}=Cq(),y=(0,U.useRef)(h);y.current=h;let b=(0,U.useRef)(!1),x=(0,U.useRef)(!1),S=(0,U.useRef)(null),[C,w]=(0,U.useState)(!1),T=(0,U.useRef)(!1),E=(0,U.useRef)(null),[D,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(!1),j=(0,U.useRef)(k);j.current=k;let M=(0,U.useRef)(!1),N=(0,U.useRef)(()=>{}),[P,F]=(0,U.useState)(0),[I,L]=(0,U.useState)(!1),[ee,te]=(0,U.useState)(!1),[ne,R]=(0,U.useState)(null),re=(0,U.useCallback)(async(e,t,n)=>{if(!t||M.current)return!1;M.current=!0,x.current=!1,b.current=!1,S.current=null,R(t),F(e=>e+1),L(!0),O(null),A(!0);try{await g(e,t,{pageTitle:`Home`,sectionTitle:n})}catch(e){return console.error(`[HomeTour] failed to persist playground run note:`,e),A(!1),R(null),Q({title:`Could not start workout`,description:`The playground entry could not be saved.`,variant:`destructive`}),!1}finally{M.current=!1}return!0},[g]),ie=(0,U.useCallback)(async()=>{if(T.current=!1,w(!1),S.current)try{await _(S.current,!1),S.current=null}catch(e){console.error(`[HomeTour] retry save failed:`,e),Q({title:`Session still not saved`,description:`The run is kept — try again.`,variant:`destructive`});return}let e=E.current;if(E.current=null,e)switch(e.kind){case`apply-doc`:m.current=!1,d(e.doc),A(!1),R(null),F(e=>e+1),L(!1);break;case`restart`:await re(e.doc,e.block,e.sectionTitle)}},[re,_]),ae=(0,U.useCallback)(e=>{if(!E.current){if(!y.current||x.current||!b.current||S.current){E.current=e,ie();return}E.current=e,T.current=!0,w(!0)}},[ie]),oe=(0,U.useRef)(null),se=(0,U.useRef)(null),ce=(0,U.useRef)(null);_Q(`hero`,ce);let[le,z]=(0,U.useState)(!1),ue=(0,U.useRef)(le);ue.current=le;let de=(0,U.useCallback)(()=>{let e=document.getElementById(`tour-section-editor`),t=oe.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:Math.max(0,e.getBoundingClientRect().top+window.scrollY-n),behavior:r?`auto`:`smooth`})},[r]),fe=(0,U.useCallback)(()=>{z(!0),window.setTimeout(de,350)},[de]),B=(0,U.useCallback)(()=>{z(!1),window.scrollTo({top:0,behavior:r?`auto`:`smooth`})},[r]),pe=(0,U.useRef)(!1),me=(0,U.useCallback)(()=>{ae({kind:`apply-doc`,doc:c})},[c,ae]);(0,U.useEffect)(()=>{let e=se.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting?pe.current&&!j.current&&(pe.current=!1,me()):pe.current=!0});return t.observe(e),()=>t.disconnect()},[me]);let he=(0,U.useCallback)(()=>{M0(),s(null),ae({kind:`apply-doc`,doc:a})},[a,ae]),ge=(0,U.useCallback)(()=>{me();let e=document.getElementById(`tour-section-editor`),t=oe.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:Math.max(0,e.getBoundingClientRect().top+window.scrollY-n),behavior:r?`auto`:`smooth`})},[r,me]);Fq({pageRoute:`/`,quests:n,initialSource:c,currentSource:u}),Pq({pageRoute:`/`,quests:n,completedResults:D}),N.current=I0(`/`,n),N0({pageRoute:`/`,quests:n,running:ee}),(0,U.useEffect)(()=>{let e=document.getElementById(`tour-section-insights`);if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&N.current?.(`session-insights`)});return t.observe(e),()=>t.disconnect()},[]);let _e=(0,U.useCallback)(e=>{d(e),e!==c&&!m.current&&(m.current=!0,i?.(fq.demoEdited))},[c,i]),ve=(0,U.useCallback)(e=>{p.current=e},[]),ye=(0,U.useCallback)((e,t,n,r)=>{if(n){if(i?.(fq.demoRun),r&&te(!0),R(n),A(!0),L(!0),F(e=>e+1),O(null),M.current||E.current){E.current={kind:`restart`,doc:t,block:n,sectionTitle:e};return}if(y.current&&b.current&&!x.current){E.current={kind:`restart`,doc:t,block:n,sectionTitle:e},T.current=!0,w(!0);return}if(y.current&&!x.current){v().then(()=>re(t,n,e));return}re(t,n,e)}},[re,v,i]),be=(0,U.useCallback)(()=>{ye(`Run`,f.current,p.current[0],!0)},[ye]),xe=(0,U.useCallback)(()=>{let e=()=>{let e=document.getElementById(`tour-section-insights`),t=oe.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY,i=Math.max(0,e.getBoundingClientRect().top+window.scrollY-n);window.scrollTo({top:i,behavior:r?`auto`:`smooth`})};if(ue.current){e();return}z(!0),window.setTimeout(e,350)},[r]),Se=(0,U.useCallback)((e,t)=>{if(!(x.current&&!S.current))return(t.logs??[]).length===0?(x.current=!0,O(t),A(!1),xe(),ie()):(x.current=!0,_(t,t.completed).then(()=>{if(S.current=null,O(t),T.current||E.current)return A(!1),ie()}).catch(e=>{throw x.current=!1,b.current=!1,S.current=t,T.current=!1,w(!1),E.current=null,Q({title:`Session not saved`,description:`The run could not be recorded. Nothing was lost — your next action retries the save.`,variant:`destructive`}),e}))},[_,ie,xe]),Ce=(0,U.useCallback)(()=>{A(!1),xe()},[xe]),we=(0,U.useRef)(null),Te=(0,U.useCallback)(e=>{we.current=e},[]),Ee=(0,U.useCallback)(()=>{b.current=!0;let e=we.current;I&&e&&e.handle(new bp(void 0,e.nowProvider)),L(!1)},[I]),{setL3Items:De}=WM(),Oe=(0,U.useMemo)(()=>[{id:`tour-hero`,label:`Welcome`,level:3,action:{type:`scroll`,sectionId:`tour-hero`}},{id:`editor`,label:`Live Preview`,level:3,action:{type:`scroll`,sectionId:`tour-section-editor`}},{id:`insights`,label:`Session Insights`,level:3,action:{type:`scroll`,sectionId:`tour-section-insights`},secondaryAction:{id:`run-start`,label:`Run the workout`,action:{type:`call`,handler:be}}},{id:`boards`,label:`One Run Becomes Many`,level:3,action:{type:`scroll`,sectionId:`tour-section-boards`}},{id:`community-feeds`,label:`Library & Community Feeds`,level:3,action:{type:`scroll`,sectionId:`tour-section-community-feeds`}},{id:`offerings`,label:`Who owns the Data?`,level:3,action:{type:`scroll`,sectionId:`tour-section-offerings`}},{id:`university`,label:`Wod Wiki University`,level:3,action:{type:`scroll`,sectionId:`tour-section-university`}}],[be]);(0,U.useEffect)(()=>(De(Oe),()=>De([])),[De,Oe]),R0((0,U.useMemo)(()=>Oe.map(e=>e.action.type===`scroll`?e.action.sectionId:e.id),[Oe]));let ke=h?.block??ne,Ae=k&&ke&&(0,W.jsx)(OZ,{block:ke,resultId:h?.resultId,autoStart:I,externalStop:C,onRunStarted:Ee,onRuntimeReady:Te,onClose:Ce,onCompleteWorkout:Se},P),je=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(d2,{}),(0,W.jsxs)(`p`,{className:`-mt-8 text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground/60 xl:text-[11px]`,children:[`— or learn the language with examples`,` `,(0,W.jsx)(_n,{to:`/syntax`,className:`text-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:`on the syntax page →`})]})]}),Me=(0,W.jsx)(vQ,{gateId:`editor-pane`,segmentId:`hero`,className:`w-full max-w-[720px] xl:max-w-[820px] 2xl:max-w-[920px]`,children:(0,W.jsx)(zq,{title:l?l.toLowerCase().startsWith(`shared by`)?l:`shared by: ${l}`:`welcome-1.md`,headerActions:l&&(0,W.jsx)(`button`,{type:`button`,onClick:he,title:`Reset`,className:`rounded-md border border-border px-2 py-1 text-[10px] transition-colors hover:bg-accent`,"data-testid":`tour-hero-reset-shared`,children:`Reset`}),className:`h-[540px] lg:h-[600px] 2xl:h-[640px]`,children:(0,W.jsx)(f2,{doc:u,theme:t,onDocChange:_e,onBlocksChange:ve,onRun:be})})}),Ne=(0,W.jsx)(`div`,{id:`tour-why-video-wrap`,"aria-hidden":le,className:G(`grid w-full transition-all duration-300 motion-reduce:transition-none`,le?`grid-rows-[0fr] opacity-0 invisible`:`grid-rows-[1fr] opacity-100`),children:(0,W.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:(0,W.jsx)(q0,{onWatched:fe})})}),Pe=(0,W.jsxs)(`div`,{ref:se,id:`tour-section-editor`,"data-testid":`tour-section-editor`,className:`flex w-full flex-col items-center px-5 py-8 text-center lg:px-10 xl:py-10 2xl:px-16`,children:[le&&(0,W.jsxs)(`button`,{type:`button`,onClick:B,"data-testid":`tour-why-watch-again`,className:`inline-flex items-center gap-1.5 rounded-t-lg border border-b-0 border-border bg-muted/40 px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,W.jsx)(pn,{className:`size-3`}),`Watch again`]}),Me]});return r?(0,W.jsxs)(`div`,{"data-testid":`home-tour`,children:[(0,W.jsxs)(`section`,{id:`tour-hero`,"data-testid":`tour-hero`,className:`flex flex-col items-center gap-5 px-6 py-6 text-center`,children:[(0,W.jsx)(G0,{}),Ne,Pe]}),(0,W.jsx)(G2,{session:D,onRun:be,onBackToEditor:ge}),(0,W.jsx)(f4,{}),je,(0,W.jsx)(M$,{variant:`university`}),(0,W.jsx)(Y0,{}),Ae]}):(0,W.jsxs)(`div`,{"data-testid":`home-tour`,children:[(0,W.jsx)(`div`,{ref:oe,"aria-hidden":!0,className:`h-px`}),(0,W.jsxs)(`section`,{ref:ce,id:`tour-hero`,"data-testid":`tour-hero`,className:`relative flex min-h-[calc(100dvh-65px)] flex-col items-center justify-center gap-5 px-5 py-6 text-center lg:min-h-[calc(100dvh-104px)] lg:px-10 xl:gap-7 xl:py-8 2xl:px-16`,children:[(0,W.jsx)(G0,{}),Ne,Pe]}),(0,W.jsx)(G2,{session:D,onRun:be,onBackToEditor:ge}),(0,W.jsx)(f4,{}),je,(0,W.jsx)(M$,{variant:`university`}),(0,W.jsx)(Y0,{}),Ae]})}function h4(e){return(0,W.jsx)(B0,{children:(0,W.jsx)(gQ,{children:(0,W.jsx)(m4,{...e})})})}function g4({wodFiles:e,theme:t}){let n=(0,U.useMemo)(()=>m1(e),[e]);return(0,U.useEffect)(()=>{tS(`homeFirstPaint`)},[]),(0,W.jsx)(h4,{wodFiles:n,theme:t,quests:f1.quests})}var _4=`idle`,v4=null,y4=new Set,b4=null,x4=null;function S4(){for(let e of y4)e()}function C4(e){typeof document>`u`||(document.documentElement.dataset.feedState=e)}function w4(e){typeof document>`u`||(e===null?delete document.documentElement.dataset.feedOutcome:document.documentElement.dataset.feedOutcome=e)}C4(_4);function T4(e){_4!==e&&(_4=e,C4(e),S4())}function E4(){b4&&=(clearTimeout(b4),null),x4&&=(x4.close(),null)}function D4(e){v4=e,S4()}function O4(){E4(),w4(null),v4!==null&&(v4=null,S4()),T4(`preparing`)}function k4(e){switch(w4(e),e){case`busy`:if(_4!==`preparing`)return;typeof BroadcastChannel<`u`&&!x4&&(x4=new BroadcastChannel(Bv),x4.onmessage=e=>{e.data?.kind===`seed-imported`&&(E4(),T4(`ready`))}),b4=setTimeout(()=>{mM({onProgress:D4}).then(k4)},Gj);break;case`error`:E4(),T4(`error`);break;default:E4(),T4(`ready`)}}function A4(){return _4===`idle`?`ready`:_4}function j4(){return v4}function M4(e){return y4.add(e),()=>y4.delete(e)}function N4(){return(0,U.useSyncExternalStore)(M4,A4)}function P4(){return(0,U.useSyncExternalStore)(M4,j4)}var F4=null;function I4(e={}){return tS(`feedStart`),F4??=L4(e).finally(()=>{tS(`feedSettled`)}),F4}async function L4(e){let t=t=>{D4(t),e.onProgress?.(t)},n=e.sources??Xj();await Aee(e).catch(e=>console.error(`[feedSync] notebook vocabulary migration failed`,e)),await Oee(e).catch(e=>console.error(`[feedSync] checkpoint adoption failed`,e)),await Cj(n,e.storage).catch(e=>console.error(`[feedSync] subscription migration failed`,e));let r=e.storage??tj(),i;try{i=await r.getSeedMeta(Hv(`core`))}catch{i=void 0}let a=!i||i.seedVersion<=0;if(a?O4():k4(`current`),await kee(e).catch(e=>console.error(`[feedSync] feed provenance repair failed`,e)),a){k4(await mM({...e,sources:n,onProgress:t,onFirstPaint:()=>k4(`imported`)})),n.some(e=>e.id!==`core`&&mj(e.id))&&await mM({...e,sources:n,onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e));return}await mM({...e,sources:n,onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e))}function R4(){let[e,t]=(0,U.useState)(null);return(0,U.useEffect)(()=>{let e=!1,n=()=>{_M().then(n=>{e||t(!n.libraryImported)}).catch(()=>{e||t(!0)})};n();let r=Bx(()=>n()),i=sM(()=>n()),a=null;if(typeof BroadcastChannel<`u`)try{a=new BroadcastChannel(Bv),a.onmessage=()=>n()}catch{}return()=>{e=!0,r(),i(),a?.close()}},[]),e}var z4=[`📓`,`🏋️`,`🔥`,`💪`,`⭐`,`🎯`,`🏃`,`🧘`,`🥊`,`🚴`],B4=({open:e,onOpenChange:t,onCreate:n,notebook:r,onSave:i})=>{let[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(`📓`),[d,f]=(0,U.useState)(!1),p=!!r;U.useEffect(()=>{e&&(o(r?.name??``),c(r?.description??``),u(r?.icon??`📓`))},[e,r]);let m=async()=>{if(!(!a.trim()||d)){f(!0);try{let e=a.trim();if(!(p&&r&&i?await i(r,e,s.trim(),l):await n(e,s.trim(),l)))return;p||(o(``),c(``),u(`📓`)),t(!1)}finally{f(!1)}}};return(0,W.jsx)(SW,{open:e,onOpenChange:t,children:(0,W.jsxs)(CW,{className:`bg-popover text-popover-foreground border border-border`,children:[(0,W.jsxs)(wW,{children:[(0,W.jsx)(TW,{className:`text-foreground`,children:p?`Edit Notebook`:`Create Notebook`}),(0,W.jsx)(EW,{children:p?`Rename, describe or re-icon this notebook.`:`Organize your sessions into collections.`})]}),(0,W.jsxs)(`div`,{className:`space-y-4 mt-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-sm font-medium text-foreground/80 mb-2 block`,children:`Icon`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:z4.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:G(`w-9 h-9 rounded-md flex items-center justify-center text-lg transition-all`,`hover:bg-accent hover:scale-110`,l===e?`bg-primary/20 ring-2 ring-primary scale-110`:`bg-muted/50`),children:e},e))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Name `,(0,W.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,W.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&a.trim()&&(e.preventDefault(),m())},placeholder:`e.g., Morning Routines`,autoFocus:!0,className:G(`w-full px-3 py-2 rounded-md text-sm`,`bg-background border border-border`,`text-foreground placeholder:text-muted-foreground`,`focus:outline-none focus:ring-2 focus:ring-primary/50`,`transition-colors`)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Description `,(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`(optional)`})]}),(0,W.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`A brief description of this notebook...`,rows:2,className:G(`w-full px-3 py-2 rounded-md text-sm resize-none`,`bg-background border border-border`,`text-foreground placeholder:text-muted-foreground`,`focus:outline-none focus:ring-2 focus:ring-primary/50`,`transition-colors`)})]}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,W.jsx)(K,{variant:`default`,size:`sm`,onClick:()=>void m(),disabled:!a.trim()||d,children:d?`Saving…`:p?`Save`:`Create`})]})]})]})})},V4=({refreshKey:e,onChanged:t})=>{let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null);if((0,U.useEffect)(()=>{let e=!1;return zA.getAllNotebooks().then(t=>{e||r(t)}).catch(()=>{e||r([])}),()=>{e=!0}},[e]),n===null)return(0,W.jsx)(`p`,{className:`px-6 py-3 text-xs text-muted-foreground`,"data-testid":`notebook-list-loading`,children:`Loading notebooks…`});let c=async e=>{try{await zA.delete(e.id)}catch{}finally{s(null),t()}};return(0,W.jsxs)(`section`,{className:`border-b border-border/60 px-6 py-3`,"data-testid":`notebook-list`,children:[(0,W.jsx)(`ul`,{className:`divide-y divide-border/40`,children:n.map(e=>{let t=e.origin===`user`;return(0,W.jsxs)(`li`,{className:`flex items-center gap-3 py-2`,"data-testid":`notebook-list-row`,children:[(0,W.jsx)(`span`,{"aria-hidden":!0,className:`text-base`,children:e.icon}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(_n,{to:`/notebook/${encodeURIComponent(e.slug)}`,className:`text-sm font-medium text-foreground hover:text-primary truncate block`,children:e.name}),e.description&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]}),(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider text-muted-foreground/60`,children:e.origin===`feed`?`Feed`:e.origin==="default"?`App`:`Yours`}),t&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(K,{variant:`ghost`,size:`icon`,className:`size-8`,"aria-label":`Edit ${e.name}`,"data-testid":`notebook-edit-${e.slug}`,onClick:()=>a(e),children:(0,W.jsx)(qt,{className:`size-3.5`})}),o===e.notebookId?(0,W.jsx)(K,{variant:`destructive`,size:`sm`,title:`Notes in this notebook return to the journal`,"data-testid":`notebook-delete-confirm-${e.slug}`,onClick:()=>void c(e),children:`Confirm delete`}):(0,W.jsx)(K,{variant:`ghost`,size:`icon`,className:`size-8 text-muted-foreground hover:text-destructive`,"aria-label":`Delete ${e.name}`,"data-testid":`notebook-delete-${e.slug}`,onClick:()=>s(e.notebookId),children:(0,W.jsx)(Ue,{className:`size-3.5`})})]})]},e.notebookId)})}),(0,W.jsx)(B4,{open:i!==null,onOpenChange:e=>{e||a(null)},onCreate:async()=>null,notebook:i,onSave:async(e,n,r,i)=>{try{let a=await zA.update(e.id,{name:n,description:r,icon:i});return t(),a}catch{return null}}})]})};function H4({value:e,max:t,label:n,className:r}){let i=Math.max(1,t),a=Math.min(Math.max(e,0),i),o=Math.round(a/i*100),s=(0,U.useRef)(a),[c,l]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{if(a>s.current){l(!0);let e=setTimeout(()=>l(!1),200);return s.current=a,()=>clearTimeout(e)}s.current=a},[a]),(0,W.jsxs)(`div`,{className:G(`w-full`,r),children:[n?(0,W.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between text-[11px] font-semibold uppercase tracking-[0.14em] text-brand-deep dark:text-brand-light`,children:[(0,W.jsx)(`span`,{children:n}),(0,W.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[a,`/`,i]})]}):null,(0,W.jsx)(`div`,{role:`progressbar`,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":i,"aria-label":n??`Progress`,className:`h-2 w-full overflow-hidden rounded-pill bg-brand/10`,children:(0,W.jsx)(`div`,{className:G(`h-full rounded-pill transition-[width] duration-500 ease-out`,c?`bg-brand-deep`:`bg-brand`),style:{width:`${o}%`}})})]})}function U4(e,t,n){TH.getState().open({placeholder:`Craft the query…`,wql:{initialQuery:e,execute:t,onApply:n},sources:[dU()]})}function W4({query:e,onQueryChange:t,scopeOptions:n,execute:r,defaultQuery:i,compact:a=!1,className:o}){let s=(0,U.useCallback)(()=>U4(e,r,t),[e,r,t]);return a?(0,W.jsx)(`div`,{"data-testid":`stream-query-bar-dock`,className:G(`flex min-h-12 w-full items-stretch overflow-hidden rounded-xl border border-border bg-muted/40 shadow-xs`,o),children:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`stream-query-bar`,onClick:s,className:`flex min-w-0 flex-1 cursor-pointer items-center gap-2.5 px-3 text-left transition-colors hover:bg-muted/70`,children:[(0,W.jsx)(Tt,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{"data-testid":`stream-query-summary`,className:`min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground`,children:e||i||`Filter or search…`}),(0,W.jsx)(_t,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]})}):(0,W.jsx)(`div`,{"data-testid":`stream-query-bar`,className:G(`flex min-w-0 flex-1 items-center gap-1 text-xs`,o),children:(0,W.jsx)(Kw,{query:e,onQueryChange:t,compact:!0,showDiagnostics:!1,preferredChoices:n,placeholder:`Filter or search…`,className:`min-w-0 flex-1`})})}function G4(e,t){let n=t??X(e);return n.error?null:n.groupBy?.length?n.groupBy.map(e=>String(e).toLowerCase()):null}function K4(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/(^-|-$)/g,``)||`default`}function q4(e,t=`date`,n){let r=(Array.isArray(t)?t:[t]).map(e=>String(e).toLowerCase()).filter(Boolean);r.length===0&&r.push(`date`);let i=(e,t)=>{let r=J4(e,t[0],n);return t.length===1?r:r.flatMap(e=>e.key===`shelf`?[e]:i(e.entries,t.slice(1)).map(t=>({...t,key:`${e.key}/${t.key}`,id:`${e.id}--${t.id}`,label:`${e.label} / ${t.label}`,isToday:e.isToday||t.isToday})))};return i(e,r)}function J4(e,t,n){let r=t.toLowerCase(),i=YH();if(r===`date`||r===`day`){let t=new Map,r=[],a=[];for(let i of e){let e=i.date??(i.sourceNotebook===`playground`&&i.createdAt&&i.createdAt>9466848e5?new Date(i.createdAt).toISOString().slice(0,10):null);if(n?.shelfVisible&&(e==null||i.kind===`note`&&!i.sourceNote))r.push(i);else if(e){let n=t.get(e);n?n.push(i):t.set(e,[i])}else a.push(i)}let o=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)),s=[];n?.shelfVisible&&r.length>0&&s.push({id:`group-shelf`,key:`shelf`,label:`Notebook Sessions`,entries:r});for(let e of o)s.push({id:`date-group-${e}`,key:e,label:e===i?`Today`:XH(e),isToday:e===i,entries:t.get(e)??[]});return a.length>0&&s.push({id:`group-date-undated`,key:`undated`,label:`Undated`,entries:a}),s}if(r===`week`){let t=new Map,n=[];for(let r of e){if(!r.date){n.push(r);continue}let[e,i,a]=r.date.split(`-`).map(Number),o=new Date(Date.UTC(e,i-1,a)),s=o.getUTCDay(),c=o.getUTCDate()-s+(s===0?-6:1),l=new Date(Date.UTC(e,i-1,c)),u=l.toISOString().slice(0,10),d=`Week of ${l.toLocaleDateString(`en`,{month:`short`,day:`numeric`,year:`numeric`,timeZone:`UTC`})}`,f=t.get(u);f?f.entries.push(r):t.set(u,{label:d,entries:[r]})}let r=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)).map(e=>({id:`group-week-${e}`,key:e,label:t.get(e).label,entries:t.get(e).entries}));return n.length>0&&r.push({id:`group-week-undated`,key:`undated`,label:`Undated`,entries:n}),r}if(r===`month`){let t=new Map,n=[];for(let r of e){if(!r.date){n.push(r);continue}let e=r.date.slice(0,7),[i,a]=e.split(`-`).map(Number),o=new Date(Date.UTC(i,a-1,1)).toLocaleDateString(`en`,{month:`long`,year:`numeric`,timeZone:`UTC`}),s=t.get(e);s?s.entries.push(r):t.set(e,{label:o,entries:[r]})}let r=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)).map(e=>({id:`group-month-${e}`,key:e,label:t.get(e).label,entries:t.get(e).entries}));return n.length>0&&r.push({id:`group-month-undated`,key:`undated`,label:`Undated`,entries:n}),r}if(r===`year`){let t=new Map,n=[];for(let r of e){if(!r.date){n.push(r);continue}let e=r.date.slice(0,4),i=t.get(e);i?i.push(r):t.set(e,[r])}let r=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)).map(e=>({id:`group-year-${e}`,key:e,label:e,entries:t.get(e)??[]}));return n.length>0&&r.push({id:`group-year-undated`,key:`undated`,label:`Undated`,entries:n}),r}if(r===`discipline`){let t=new Map;for(let n of e){let e=n.effort?.discipline||n.tags?.find(e=>[`strength`,`gymnastics`,`cardio`,`running`,`rowing`,`weightlifting`,`olympic-weightlifting`].includes(e.toLowerCase()))||`General`,r=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),i=t.get(r);i?i.push(n):t.set(r,[n])}return rF(Array.from(t.entries()),`priority-then-alpha`,{priority:[`Strength`,`Gymnastics`,`Cardio`,`Running`,`Rowing`,`Weightlifting`]}).map(([e])=>e).map(e=>({id:`group-discipline-${K4(e)}`,key:e,label:e,entries:t.get(e)??[]}))}if(r===`origin`){let t=new Map;for(let n of e){let e=n.effort?.registrySource===`bundled`?`Bundled Standards`:`Custom Movements`,r=t.get(e);r?r.push(n):t.set(e,[n])}return rF(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-origin-${K4(e)}`,key:e,label:e,entries:t}))}if(r===`source`||r===`notebook`){let t=new Map;for(let n of e){let e=n.sourceNotebook||`Other`,r=e.charAt(0).toUpperCase()+e.slice(1),i=t.get(r);i?i.push(n):t.set(r,[n])}return rF(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-source-${K4(e)}`,key:e,label:e,entries:t}))}if(r===`kind`||r===`type`){let t=new Map;for(let n of e){let e=n.kind.charAt(0).toUpperCase()+n.kind.slice(1)+`s`,r=t.get(e);r?r.push(n):t.set(e,[n])}return rF(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-kind-${K4(e)}`,key:e,label:e,entries:t}))}if(!fm.includes(r)){let t=new Map;for(let n of e){let e=n.typedTags?.find(e=>e.type?.toLowerCase()===r)?.label??`Unassigned`,i=t.get(e);i?i.push(n):t.set(e,[n])}return rF(Array.from(t.entries()),`alpha-sink-last`,{sink:`Unassigned`}).map(([e,t])=>({id:`group-property-${K4(r)}-${K4(e)}`,key:e,label:e,entries:t}))}let a=new Map;for(let t of e){let e=t.tags?.[0]?`#${t.tags[0]}`:`Untagged`,n=a.get(e);n?n.push(t):a.set(e,[t])}return rF(Array.from(a.entries()),`alpha-sink-last`,{sink:`Untagged`}).map(([e,t])=>({id:`group-tag-${K4(e)}`,key:e,label:e,entries:t}))}var Y4=[{id:iN.route,label:`Journal`,profile:iN,scopeChoices:NC,shortcuts:!0},{id:oN.route,label:`Notes`,profile:oN,scopeChoices:NC,shortcuts:!0},{id:aN.route,label:`Notebooks`,profile:aN,scopeChoices:NC,shortcuts:!0},{id:sN.route,label:`Feeds`,profile:sN,scopeChoices:NC,shortcuts:!0},{id:cN.route,label:`Pages`,profile:cN,scopeChoices:NC,shortcuts:!0},{id:lN.route,label:`Efforts`,profile:lN,scopeChoices:NC,shortcuts:!0},{id:uN.route,label:`Equipment`,profile:uN,scopeChoices:NC,shortcuts:!0},{id:dN.route,label:`Tags`,profile:dN,shortcuts:!0},{id:fN.route,label:`Sessions`,profile:fN,scopeChoices:NC,shortcuts:!0},{id:pN.route,label:`Playgrounds`,profile:pN,scopeChoices:NC,shortcuts:!0}],X4={id:`/dashboards`,label:`Dashboards`,systemDefaultWql:`:dashboard{}`},Z4={id:sF,label:`Command palette`,systemDefaultWql:sU,scopeChoices:NC},Q4=[...Y4,X4,Z4];function $4(e){return Q4.find(t=>t.id===e)}function e3({className:e,...t}){return(0,W.jsx)(te,{"data-slot":`control`,...t,className:G(e,`group relative isolate inline-flex h-6 w-10 cursor-default rounded-full p-[3px] sm:h-5 sm:w-8`,`transition duration-0 ease-in-out data-changing:duration-200`,`forced-colors:outline forced-colors:bg-[Highlight] dark:forced-colors:bg-[Highlight]`,`bg-muted ring-1 ring-black/5 ring-inset dark:bg-white/5 dark:ring-white/15`,`data-checked:bg-primary data-checked:ring-primary/90`,`dark:data-checked:bg-primary dark:data-checked:ring-primary/90`,`focus:not-data-[focus]:outline-hidden data-[focus]:outline-2 data-[focus]:outline-offset-2 data-[focus]:outline-ring`,`data-[hover]:ring-black/15 dark:data-[hover]:ring-white/25 data-[hover]:data-checked:ring-primary/90 dark:data-[hover]:data-checked:ring-primary/90`,`data-[disabled]:bg-muted dark:data-[disabled]:bg-white/15 data-[disabled]:opacity-50 data-[disabled]:data-checked:bg-muted dark:data-[disabled]:data-checked:bg-white/15 data-[disabled]:data-checked:ring-black/5 dark:data-[disabled]:data-checked:ring-white/15`),children:(0,W.jsx)(`span`,{"aria-hidden":`true`,className:G(`pointer-events-none relative inline-block size-4.5 rounded-full sm:size-3.5`,`translate-x-0 transition duration-200 ease-in-out`,`border border-transparent`,`bg-background shadow-sm ring-1 ring-black/5 dark:ring-white/5`,`group-data-checked:bg-primary-foreground group-data-checked:shadow-sm group-data-checked:ring-primary/90`,`group-data-checked:translate-x-4 sm:group-data-checked:translate-x-3`,`group-data-checked:group-data-[disabled]:bg-background group-data-checked:group-data-[disabled]:shadow-sm group-data-checked:group-data-[disabled]:ring-black/5 dark:group-data-checked:group-data-[disabled]:ring-white/5`)})})}var t3=Object.fromEntries([...NC,...MC].map(e=>[e.value,e.label]));function n3({values:e,choices:t,labels:n,onChange:r,testPrefix:i,reorderable:a=!1}){let o=(t,n)=>{let i=[...e],a=t+n;if(a<0||a>=i.length)return;let o=i[t];i[t]=i[a],i[a]=o,r(i)};return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((t,s)=>(0,W.jsxs)(`span`,{"data-testid":`${i}-chip-${t}`,className:`inline-flex items-center gap-1 rounded-full border border-border/70 bg-muted/40 px-2.5 py-1 text-xs font-medium`,children:[n[t]??t,a&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,"aria-label":`Move ${t} up`,"data-testid":`${i}-up-${t}`,disabled:s===0,onClick:()=>o(s,-1),className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,children:(0,W.jsx)(Fe,{className:`size-3`})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Move ${t} down`,"data-testid":`${i}-down-${t}`,disabled:s===e.length-1,onClick:()=>o(s,1),className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,children:(0,W.jsx)(ze,{className:`size-3`})})]}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Remove ${t}`,"data-testid":`${i}-remove-${t}`,onClick:()=>r(e.filter(e=>e!==t)),className:`text-muted-foreground hover:text-foreground`,children:(0,W.jsx)(we,{className:`size-3`})})]},t))}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.filter(t=>!e.includes(t.value)).map(t=>(0,W.jsxs)(`button`,{type:`button`,"aria-label":`Add ${t.value}`,"data-testid":`${i}-add-${t.value}`,onClick:()=>r([...e,t.value]),className:`rounded-full border border-dashed border-border/70 px-2.5 py-1 text-xs text-muted-foreground hover:text-foreground hover:border-foreground/40`,children:[`+ `,t.label]},t.value))})]})}function r3({values:e,choices:t,onChange:n,testPrefix:r}){return(0,W.jsx)(n3,{values:e,choices:t,labels:t3,onChange:n,testPrefix:r,reorderable:!0})}function i3({values:e,onChange:t,testPrefix:n}){return(0,W.jsx)(n3,{values:e,choices:$P.map(e=>({value:e.id,label:e.label})),labels:Object.fromEntries($P.map(e=>[e.id,e.label])),onChange:t,testPrefix:n,reorderable:!0})}function a3({label:e,enabled:t,onEnabledChange:n,testId:r,children:i}){return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:e}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[`Custom`,(0,W.jsx)(e3,{checked:t,onChange:n,"data-testid":r})]})]}),i]})}function o3({shortcuts:e,icons:t,landingId:n,onEdit:r,onDelete:i,onCreate:a,error:o,testPrefix:s}){return(0,W.jsxs)(`div`,{className:`space-y-2`,"data-testid":`${s}-shortcuts`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Saved shortcuts`}),(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:a,"data-testid":`${s}-shortcut-new`,children:`New shortcut`})]}),e.map(e=>{let a=t[e.icon]??t.bookmark,o=e.to?`Opens ${e.to}`:e.wql||`Landing (no query)`;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 px-2 py-1.5`,"data-testid":`${s}-shortcut-${e.id}`,children:[(0,W.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`min-w-0 max-w-40 truncate text-xs font-medium`,children:e.label}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[10px] text-muted-foreground`,children:o}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Edit ${e.label}`,"data-testid":`${s}-shortcut-edit-${e.id}`,onClick:()=>r(e),className:`shrink-0 rounded p-1 text-muted-foreground hover:text-foreground`,children:(0,W.jsx)(qt,{className:`size-3`})}),!e.to&&e.id!==n&&(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete ${e.label}`,"data-testid":`${s}-shortcut-delete-${e.id}`,onClick:()=>i(e.id),className:`shrink-0 rounded p-1 text-muted-foreground hover:text-destructive`,children:(0,W.jsx)(Ue,{className:`size-3`})})]},e.id)}),o&&(0,W.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`${s}-shortcut-error`,children:o})]})}function s3(e){return{defaultWql:e.defaultWql??``,customScope:e.typeOptions!==void 0,scopeOptions:e.typeOptions??[],customGroupBy:e.groupByOptions!==void 0,groupByOptions:e.groupByOptions??[]}}function c3(e){return{defaultWql:e.defaultWql.trim()||void 0,typeOptions:e.customScope?e.scopeOptions:void 0,groupByOptions:e.customGroupBy?e.groupByOptions:void 0}}function l3({surface:e,onSaved:t}){let n=EF(e.id),r=JF(e.id),[i,a]=(0,U.useState)(()=>s3(n)),[o,s]=(0,U.useState)(()=>n),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(null);(0,U.useEffect)(()=>{a(s3(n)),s(n),l(null),d(null)},[n]);let m=e.profile?.defaultWql??e.systemDefaultWql??``,h=(()=>{let e=i.defaultWql.trim();return e?Iw(e).error??null:null})(),g=c3(i),_=JSON.stringify(g)!==JSON.stringify(o),v=Object.values(o).some(e=>e!==void 0),y=[...o.invalidTypeOptions??[],...o.invalidGroupByOptions??[]],b=async()=>{if(!_)return;let n=i.defaultWql.trim();if(!(n&&Iw(n).error)){if(!await yF(e.id,g)){l(`Save failed — storage is unavailable; the previous default still stands.`);return}l(null),s(vF(e.id)),t?.()}},x=async()=>{if(!await bF(e.id)){l(`Reset failed — storage is unavailable; the stored override still stands.`);return}l(null),s({}),a(s3({})),t?.()},S=async t=>{d(null),await HF(e.id,r.filter(e=>e.id!==t))||d(`Delete failed — storage is unavailable. Nothing was lost; the link remains.`)},C=e.scopeChoices??[],w=C.length>0;return(0,W.jsxs)(`div`,{className:`space-y-5`,"data-testid":`query-settings-panel`,children:[(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Landing default query`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`System default: `,(0,W.jsx)(`span`,{className:`font-mono`,children:m})]}),(0,W.jsx)(`textarea`,{rows:2,value:i.defaultWql,onChange:e=>a({...i,defaultWql:e.target.value}),placeholder:m,"data-testid":`query-settings-wql`,className:`w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs focus:outline-none focus:ring-1 focus:ring-primary/40`}),h?(0,W.jsxs)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-wql-error`,children:[`Couldn't parse — `,h]}):!i.defaultWql.trim()&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Empty — the system default is used.`})]}),y.length>0&&(0,W.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,"data-testid":`query-settings-invalid`,children:[`Stored options no longer recognized: `,y.join(`, `),` — remove them; they are never turned into query clauses.`]}),w&&(0,W.jsx)(a3,{label:`Where-stored options`,enabled:i.customScope,onEnabledChange:e=>a({...i,customScope:e}),testId:`query-settings-scope-custom`,children:i.customScope&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(r3,{values:i.scopeOptions,choices:C,onChange:e=>a({...i,scopeOptions:e}),testPrefix:`query-settings-scope`}),i.scopeOptions.length===0&&(0,W.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,"data-testid":`query-settings-scope-empty`,children:`No predefined options — the page nudges for a pick instead.`})]})}),e.profile&&(0,W.jsxs)(a3,{label:`Group-by options`,enabled:i.customGroupBy,onEnabledChange:e=>a({...i,customGroupBy:e}),testId:`query-settings-group-custom`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The dimensions this page offers first, and the one a bare landing groups by. Order is the priority.`}),i.customGroupBy&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(i3,{values:i.groupByOptions,onChange:e=>a({...i,groupByOptions:e}),testPrefix:`query-settings-group`}),i.groupByOptions.length===0&&(0,W.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,"data-testid":`query-settings-group-empty`,children:`No favorites — the page groups by its own default.`})]})]}),e.shortcuts&&(0,W.jsx)(o3,{shortcuts:r,icons:kF,landingId:`all`,onEdit:e=>p({editing:e}),onDelete:S,onCreate:()=>p({editing:null}),error:u,testPrefix:`query-settings`}),c&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-storage-error`,role:`alert`,children:c}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:x,disabled:!v,"data-testid":`query-settings-reset`,children:[(0,W.jsx)(At,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Reset to system default`})]}),(0,W.jsx)(K,{size:`sm`,onClick:b,disabled:!_||!!h,"data-testid":`query-settings-save`,children:`Save`})]}),f&&(0,W.jsx)($F,{open:!0,onOpenChange:e=>{e||p(null)},route:e.id,editing:f.editing})]})}function u3({surface:e,open:t,onOpenChange:n}){return(0,W.jsx)(OC,{open:t,onClose:()=>n(!1),title:`${e.label} query settings`,description:`Override the landing query and the Where-stored / Group-By options for this page. An empty query uses the system default; an emptied options list nudges you to pick instead of presetting one. Option lists are favorites — they reorder choices, they don't change what queries mean.`,presentation:`sheet`,children:(0,W.jsx)(l3,{surface:e})})}var d3=mt,f3=Xn,p3=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(sn,{ref:n,className:G(`fixed inset-0 z-50 bg-black/80 dark:bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));p3.displayName=sn.displayName;var m3=U.forwardRef(({className:e,children:t,...n},r)=>(0,W.jsxs)(f3,{children:[(0,W.jsx)(p3,{}),(0,W.jsxs)(Bn,{ref:r,className:G(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,W.jsxs)(xn,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,W.jsx)(we,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));m3.displayName=Bn.displayName;var h3=({className:e,...t})=>(0,W.jsx)(`div`,{className:G(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});h3.displayName=`DialogHeader`;var g3=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(Ot,{ref:n,className:G(`text-lg font-semibold leading-none tracking-tight`,e),...t}));g3.displayName=Ot.displayName;var _3=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(Ct,{ref:n,className:G(`text-sm text-muted-foreground`,e),...t}));_3.displayName=Ct.displayName;var v3=[`date`,`datetime-local`,`month`,`time`,`week`],y3=(0,U.forwardRef)(function({className:e,...t},n){return(0,W.jsx)(`span`,{"data-slot":`control`,className:G(`relative block w-full`,`before:absolute before:inset-px before:rounded-[calc(var(--radius-lg)-1px)] before:bg-background before:shadow-sm`,`dark:before:hidden`,`after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-transparent after:ring-inset`,`sm:focus-within:after:ring-2 sm:focus-within:after:ring-ring`,`has-data-[disabled]:opacity-50 has-data-[disabled]:before:bg-muted/50 has-data-[disabled]:before:shadow-none`),children:(0,W.jsx)(je,{ref:n,...t,className:G(t.type&&v3.includes(t.type)&&[`[&::-webkit-datetime-edit-fields-wrapper]:p-0`,`[&::-webkit-date-and-time-value]:min-h-[1.5em]`,`[&::-webkit-datetime-edit]:inline-flex`,`[&::-webkit-datetime-edit]:p-0`,`[&::-webkit-datetime-edit-year-field]:p-0`,`[&::-webkit-datetime-edit-month-field]:p-0`,`[&::-webkit-datetime-edit-day-field]:p-0`,`[&::-webkit-datetime-edit-hour-field]:p-0`,`[&::-webkit-datetime-edit-minute-field]:p-0`,`[&::-webkit-datetime-edit-second-field]:p-0`,`[&::-webkit-datetime-edit-millisecond-field]:p-0`,`[&::-webkit-datetime-edit-meridiem-field]:p-0`],`relative block w-full appearance-none rounded-lg px-[calc(theme(spacing.3.5)-1px)] py-[calc(theme(spacing.2.5)-1px)]`,`sm:px-[calc(theme(spacing.3)-1px)] sm:py-[calc(theme(spacing.1.5)-1px)]`,`text-base/6 text-foreground placeholder:text-muted-foreground sm:text-sm/6`,`border border-border/60 hover:border-border data-[hover]:border-border`,`bg-transparent dark:bg-white/5`,`focus:outline-hidden`,`data-invalid:border-destructive data-invalid:data-[hover]:border-destructive`,`data-[disabled]:border-border/40 dark:data-[disabled]:border-border/30 dark:data-[disabled]:bg-white/2.5`,`dark:scheme-dark`,e)})})}),b3=e=>Fy(new Date(e)),x3=e=>{if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`],n=Math.min(Math.floor(Math.log(e)/Math.log(1024)),t.length-1);return`${(e/1024**n).toFixed(n===0?0:1)} ${t[n]}`};function S3(e,t){Q(e===`imported`?{title:`${t} synced`,description:`Content was imported from the published feed. Your own edits were kept.`}:e===`error`?{title:`${t} sync failed`,description:`Check your connection and the browser console for details.`,variant:`destructive`}:e===`busy`?{title:`Another tab is already syncing`,description:`Wait for it to finish, then try again.`}:{title:`${t}: nothing to import (${e})`})}var C3={imported:`Synced`,current:`Up to date`,"server-stale":`Published version is older than the stored version`,"update-pending":`Update available`,busy:`Another tab is syncing`,disabled:`Feed import is disabled`,error:`Sync failed`};function w3(e){switch(e.phase){case`checking`:return`Checking source…`;case`fetching`:return`Downloading ${e.chunkId}…`;case`applying`:return`Importing ${e.chunkId}…`;case`committed`:return`Committed ${e.chunkId}`;case`finalizing`:return`Finalizing checkpoints…`;case`finished`:return e.error??C3[e.outcome]}}function T3({source:e,running:t,disabled:n,onSync:r,onSubscribe:i,onUnsubscribe:a,onDelete:o,onAutoSync:s,onToggleNotebook:c,subscribedOnly:l}){let u=(0,U.useSyncExternalStore)(yj,()=>xj(e.id)),d=e.notebooks.filter(t=>t.id!==e.id),f=l?d.filter(e=>e.subscribed):d,p=e.autoImport,m=e.subscribed&&!e.upToDate&&e.remote!==null;return(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-source-${e.id}`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-4 gap-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-wrap`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.label}),(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded shrink-0 ${e.subscribed?`bg-emerald-500/10 text-emerald-600`:`bg-muted text-muted-foreground`}`,children:e.subscribed?`Subscribed`:`Not subscribed`}),p&&(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:`Core`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 flex-wrap justify-end`,children:[e.subscribed?m?(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>r(e.id),disabled:n,"data-testid":`feed-sync-${e.id}`,className:`gap-2`,children:[(0,W.jsx)(zt,{className:`size-3.5 ${t?`animate-spin`:``}`}),(0,W.jsx)(`span`,{children:t?`Syncing…`:`Sync`})]}):(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,"data-testid":`feed-current-${e.id}`,children:[(0,W.jsx)(yn,{className:`size-3.5 text-emerald-500`}),e.remote===null?`Remote unreachable`:`Up to date`]}):(0,W.jsxs)(K,{size:`sm`,onClick:()=>i(e.id),disabled:n,"data-testid":`feed-subscribe-${e.id}`,className:`gap-2`,children:[(0,W.jsx)(Ee,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Subscribe`})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,title:e.subscribed?`Apply new published versions automatically during the load-time check. Turning it off never removes content.`:`Unsubscribed sources never auto-import.`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 accent-primary`,checked:u,disabled:n||!e.subscribed,onChange:t=>s(e.id,t.target.checked),"aria-label":`Auto-sync ${e.label}`,"data-testid":`feed-autosync-${e.id}`}),(0,W.jsx)(`span`,{children:`Auto-sync`})]}),(0,W.jsxs)(`details`,{className:`relative shrink-0`,"data-testid":`feed-more-${e.id}`,children:[(0,W.jsx)(`summary`,{"aria-label":`More actions for ${e.label}`,className:`flex cursor-pointer list-none items-center justify-center rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground [&::-webkit-details-marker]:hidden`,children:`…`}),(0,W.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 flex w-64 max-w-[80vw] flex-col items-stretch gap-1.5 rounded-lg border border-border bg-card p-2 text-xs shadow-lg`,children:[e.url?(0,W.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`break-all font-mono text-primary hover:underline`,children:[`Published HTML: `,e.url]}):(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Published HTML: bundled with this app (no standalone URL)`}),e.repositoryUrl?(0,W.jsx)(`a`,{href:e.repositoryUrl,target:`_blank`,rel:`noopener noreferrer`,className:`break-all text-primary hover:underline`,children:`Git source directory`}):(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Git repository: not published`}),!p&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>a(e.id),disabled:n||!e.subscribed,"data-testid":`feed-unsubscribe-${e.id}`,className:`min-h-8 rounded-md px-2 text-left text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:`Unsubscribe`}),!p&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:n,"data-testid":`feed-delete-${e.id}`,className:`min-h-8 rounded-md px-2 text-left text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:`Delete source`})]})]})]})]}),e.url&&(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono break-all`,"data-testid":`feed-origin-${e.id}`,children:e.url}),e.description&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`feed-description-${e.id}`,children:e.description}),f.length>0&&(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/20 px-3 py-2`,"data-testid":`feed-notebooks-${e.id}`,children:[(0,W.jsxs)(`p`,{className:`text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:[f.length===1?`1 notebook`:`${f.length} notebooks`,` · `,l?`subscribed`:`available in this feed`]}),(0,W.jsx)(`ul`,{className:`mt-1.5 flex flex-col gap-1`,children:f.map(t=>(0,W.jsxs)(`li`,{"data-testid":`feed-notebook-${e.id}-${t.chunkId}`,className:`flex items-center justify-between gap-4 text-xs`,children:[(0,W.jsxs)(`span`,{className:t.imported?`flex min-w-0 items-center gap-1.5 text-foreground`:`flex min-w-0 items-center gap-1.5 text-muted-foreground`,children:[t.imported?(0,W.jsx)(yn,{className:`size-3 shrink-0 text-emerald-500`,"aria-hidden":!0}):(0,W.jsx)(Ee,{className:`size-3 shrink-0 opacity-60`,"aria-hidden":!0}),(0,W.jsx)(`span`,{className:`truncate`,children:t.label})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,W.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[t.count.toLocaleString(),` `,t.count===1?`item`:`items`]}),!p&&c&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>c(e.id,t.chunkId,!t.subscribed),"data-testid":`feed-notebook-toggle-${e.id}-${t.chunkId}`,className:`text-[10px] font-semibold uppercase tracking-wider px-2 py-0.5 rounded shrink-0 transition-colors ${t.subscribed?`bg-emerald-500/10 text-emerald-600 hover:bg-emerald-500/20`:`border border-border text-muted-foreground hover:bg-muted`}`,children:t.subscribed?`Subscribed`:`Subscribe`})]})]},t.chunkId))})]}),(0,W.jsxs)(`div`,{className:`grid gap-1 text-sm`,"data-testid":`feed-status-card`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Library`}),(0,W.jsxs)(`span`,{className:`font-medium text-foreground text-xs tabular-nums`,"data-testid":`feed-source-size`,children:[e.count.toLocaleString(),` feed `,e.count===1?`item`:`items`,` · `,x3(e.bytes)]})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Local database`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-local-version`,children:e.stored?`v${e.stored.version} · schema ${e.stored.schema} · imported ${b3(e.stored.importedAt)}`:`Not imported yet`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Published version`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs flex items-center gap-1.5`,"data-testid":`feed-remote-version`,children:e.remote?`v${e.remote.version} · schema ${e.remote.schema}`:e.remoteError?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Qt,{className:`size-3.5 text-muted-foreground`}),`Unavailable`]}):`Checking…`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last check`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-check`,children:e.checkedAt?b3(e.checkedAt):`—`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last sync`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-sync`,children:e.stored?b3(e.stored.importedAt):`Never`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Status`}),(0,W.jsx)(`span`,{className:`font-medium text-xs flex items-center gap-1.5`,"data-testid":`feed-sync-status`,children:e.subscribed?e.upToDate?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(yn,{className:`size-3.5 text-emerald-500`}),`Up to date`]}):e.remote==null?`Unknown (remote unreachable)`:u?`Update available — applied automatically on next load`:`Update available — sync to apply`:`Not subscribed`})]})]})]})}function E3(){let[e,t]=(0,U.useState)(null),[n,r]=(0,U.useState)(!0),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)([]),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)(``),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(!0),[v,y]=(0,U.useState)(),b=(0,U.useCallback)(async()=>{a(null);try{t(await Eee())}catch(e){a(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);(0,U.useEffect)(()=>{b()},[b]),(0,U.useEffect)(()=>yj(()=>{b()}),[b]),(0,U.useEffect)(()=>sM(()=>{b()}),[b]);let x=(0,U.useCallback)(async t=>{s(t??`all`),l([]);let n=e=>l(t=>{let n=t.find(t=>t.event.sourceId===e.sourceId),r={event:e,imported:e.phase===`checking`||e.phase===`finished`?n?.imported??null:e,chunks:e.phase===`committed`&&e.chunkId!==null?[...n?.chunks??[],e.chunkId]:n?.chunks??[]};return n?t.map(t=>t.event.sourceId===e.sourceId?r:t):[...t,r]});try{S3(t?await hM(t,{force:!0,onProgress:n}):await pM({force:!0,onProgress:n}),t?e?.sources.find(e=>e.id===t)?.label??t:`All sources`),await b()}finally{s(null)}},[b,e]),C=(0,U.useCallback)(async(e,t,n)=>{_j(e,t,n),n?await x(e):await b()},[x,b]),w=(0,U.useCallback)(async()=>{h(null);let e;try{e=uA(u,f)}catch(e){h(e instanceof Error?e.message:String(e));return}d(``),p(``),await x(e.id)},[u,f,x]),T=(0,U.useCallback)((e,t)=>{Sj(e,t)||Q({title:`Couldn't save Auto-sync`,description:`Browser storage is unavailable — the choice lasts this session only.`,variant:`destructive`}),b()},[b]),E=(0,U.useCallback)(async t=>{let n=e?.sources.find(e=>e.id===t)?.label??t;if(window.confirm(`Unsubscribe from "${n}"? Imported content for this feed's content is removed from your library; the source stays listed so you can subscribe again. Your own notes are never touched.`)){try{let{deleted:e}=await gM(t);Q({title:`${n} unsubscribed`,description:`${e.toLocaleString()} imported ${e===1?`item`:`items`} removed. The source stays listed for a later Subscribe.`})}catch(e){Q({title:`${n} unsubscribe failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await b()}},[e,b]),D=(0,U.useCallback)(async t=>{let n=e?.sources.find(e=>e.id===t)?.label??t;if(window.confirm(`Delete "${n}"? Imported content is removed and the source is unregistered. Your own notes are never touched.`)){try{let{deleted:e}=await Tee(t);Q({title:`${n} deleted`,description:`${e.toLocaleString()} imported ${e===1?`item`:`items`} removed and the source unregistered.`})}catch(e){Q({title:`${n} delete failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await b()}},[e,b]),O=c.at(-1)?.event;return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Ee,{className:`size-4 text-primary`}),`Content Sources`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A feed is one published Markdown repository — its notebooks, notes, guides, dashboards, and efforts import into your active data location together. Subscribed feeds are checked against their published manifest on every load: Auto-sync applies updates by itself, otherwise you press Sync when an update is pending. The core feed imports automatically at launch and is always subscribed.`})]}),i&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,"data-testid":`feed-status-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 shrink-0`}),`Couldn't read the feed status from the active storage: `,i]}),O&&(0,W.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-border bg-card p-4`,"data-testid":`feed-sync-progress`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm font-medium`,children:[(0,W.jsx)(`span`,{children:o===null?c.some(e=>e.event.phase===`finished`&&e.event.outcome===`error`)?`Sync finished with errors`:`Sync finished`:`Syncing…`}),(0,W.jsxs)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:[`Source `,O.sourceIndex,` of `,O.totalSources]})]}),(0,W.jsxs)(`p`,{role:`status`,"aria-live":`polite`,className:`sr-only`,"data-testid":`feed-sync-live-status`,children:[O.sourceLabel,`: `,w3(O)]}),c.map(({event:e,imported:t,chunks:n})=>(0,W.jsxs)(`div`,{className:`space-y-2 border-t border-border/50 pt-3`,children:[(0,W.jsxs)(`p`,{className:`text-xs ${e.phase===`finished`&&e.outcome===`error`?`text-destructive`:`text-muted-foreground`}`,children:[(0,W.jsx)(`span`,{className:`font-medium text-foreground`,children:e.sourceLabel}),` · `,w3(e)]}),t&&t.totalChunks>0?(0,W.jsx)(H4,{value:t.completedChunks,max:t.totalChunks,label:`Chunks committed · ${e.sourceLabel}`}):e.phase===`finished`?null:(0,W.jsx)(`progress`,{"aria-label":`Checking ${e.sourceLabel}`,className:`h-2 w-full`}),t&&(0,W.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs tabular-nums`,"data-testid":`feed-sync-totals`,children:[(0,W.jsxs)(`span`,{children:[t.totalNotes.toLocaleString(),` notes`]}),(0,W.jsxs)(`span`,{children:[t.totalEfforts.toLocaleString(),` efforts`]}),(0,W.jsxs)(`span`,{children:[t.totalBlocks.toLocaleString(),` blocks`]}),t.skippedUserOwned>0&&(0,W.jsxs)(`span`,{children:[t.skippedUserOwned.toLocaleString(),` user-owned rows preserved`]}),t.deleted>0&&(0,W.jsxs)(`span`,{children:[t.deleted.toLocaleString(),` feed rows removed`]})]}),n.length>0&&(0,W.jsxs)(`details`,{className:`text-xs`,"data-testid":`feed-sync-chunks`,children:[(0,W.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground`,children:[`Committed chunks (`,n.length,`)`]}),(0,W.jsx)(`ul`,{className:`mt-2 max-h-32 space-y-1 overflow-y-auto font-mono text-muted-foreground`,children:n.map(e=>(0,W.jsx)(`li`,{children:e},e))})]})]},e.sourceId))]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 p-2.5 rounded-xl border border-border bg-card text-xs`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none text-muted-foreground hover:text-foreground`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),"data-testid":`sync-subscribed-only-toggle`,className:`size-3.5 accent-primary rounded`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground`,children:`Subscribed only`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Source:`}),(0,W.jsxs)(`select`,{value:v??``,onChange:e=>y(e.target.value?e.target.value:void 0),"data-testid":`sync-feed-source-filter`,"aria-label":`Filter notebooks by feed`,className:`h-8 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none transition-colors hover:border-foreground/25 focus:border-primary/50`,children:[(0,W.jsx)(`option`,{value:``,children:`All feeds`}),e?.sources.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),(0,W.jsxs)(`div`,{className:`grid gap-3`,"data-testid":`feed-source-list`,children:[e?.sources.filter(e=>{if(v&&e.id!==v)return!1;if(g){let t=e.notebooks.some(e=>e.subscribed);if(!e.subscribed&&!t)return!1}return!0}).map(e=>(0,W.jsx)(T3,{source:e,running:o===e.id||o===`all`,disabled:o!==null,onSync:e=>{x(e)},onSubscribe:e=>{x(e)},onUnsubscribe:e=>{E(e)},onDelete:e=>{D(e)},onAutoSync:T,onToggleNotebook:C,subscribedOnly:g},e.id)),n&&e===null&&(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,children:`Checking sources…`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-border/50`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Sync re-applies every published chunk. Your own notes, results, and edits are never overwritten.`}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>{x(null)},disabled:o!==null||n,"data-testid":`feed-resync-button`,className:`gap-2`,children:[(0,W.jsx)(zt,{className:`size-3.5 ${o===`all`?`animate-spin`:``}`}),(0,W.jsx)(`span`,{children:o===`all`?`Syncing all…`:`Sync All Sources`})]})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(S,{className:`size-4 text-primary`}),`Add a Source`]}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Register any URL serving a Wod Wiki feed (a directory with `,(0,W.jsx)(`code`,{children:`manifest.json`}),` and`,` `,(0,W.jsx)(`code`,{children:`chunks/`}),`) — a community library mirror or one you compiled yourself. The host must allow cross-origin reads (CORS). Added sources sync immediately and start subscribed; manage Auto-sync, Unsubscribe, and Delete on each source card above.`]})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-add-source-form`,children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`feed-source-label`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Label`}),(0,W.jsx)(y3,{id:`feed-source-label`,value:u,onChange:e=>d(e.target.value),placeholder:`My library (optional — defaults to the host name)`,disabled:o!==null})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`feed-source-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Feed directory URL`}),(0,W.jsx)(y3,{id:`feed-source-url`,type:`text`,autoComplete:`off`,spellCheck:!1,value:f,onChange:e=>p(e.target.value),placeholder:`https://example.com/feed/library/`,className:`font-mono`,disabled:o!==null})]})]}),m&&(0,W.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`feed-add-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:m})]}),(0,W.jsx)(`div`,{className:`flex justify-end`,children:(0,W.jsxs)(K,{size:`sm`,onClick:()=>{w()},disabled:o!==null||!f.trim(),"data-testid":`feed-add-button`,className:`gap-2`,children:[(0,W.jsx)(On,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Add & Sync`})]})})]})]})]})}function D3({open:e,onOpenChange:t}){return(0,W.jsx)(d3,{open:e,onOpenChange:t,children:(0,W.jsxs)(m3,{className:`max-h-[85vh] w-full max-w-2xl overflow-y-auto`,"data-testid":`notebook-manage-drawer`,children:[(0,W.jsxs)(h3,{children:[(0,W.jsx)(g3,{children:`Feed Subscriptions & Local Libraries`}),(0,W.jsx)(_3,{children:`Manage the feeds stored in your active data location — compare versions, sync updates, and subscribe, unsubscribe, or delete feeds. One Subscribe imports every notebook a feed publishes. Your own notes are never touched.`})]}),(0,W.jsx)(E3,{})]})})}var O3={stream:`cards`,table:`rows`},k3=`wodwiki.viewSettings.v1`,A3={"/notebooks":`/catalogs`,"/notes":`/feeds`,"/sessions":`/results`,"/dashboards":`/dashboard`},j3={"/notes":`/collections`},M3={"/feeds":`/feeds@2`};function N3(e){let t=e.startsWith(`/`)?e:`/${e}`;return M3[t]??t}var P3=new gx(k3);function F3(e,t){return{level:e,layout:t??`cards`,visibleFields:gV(e),groupBy:void 0}}function I3(e,t,n=P3,r){let i=F3(t,r),a=N3(e),o=A3[a],s=n.get(a,{alias:o});if(s==null&&o&&(s=n.get(o,{alias:j3[a]})),!s)return i;let c=typeof s.layout==`string`?s.layout:``,l=c===`cards`||c===`rows`||c===`feed`?c:O3[c]??`cards`,u=new Set(hV(t).map(e=>e.id)),d=Array.isArray(s.visibleFields)?s.visibleFields.filter(e=>typeof e==`string`&&u.has(e)):i.visibleFields,f=typeof s.groupBy==`string`?s.groupBy:void 0;return{level:t,layout:l,visibleFields:d.length>0?d:i.visibleFields,groupBy:f}}function L3(e,t,n=P3){let r=N3(e);n.set(r,{level:t.level,layout:t.layout,visibleFields:t.visibleFields,groupBy:t.groupBy})}function R3(e,t,n=P3){let r=N3(e),i=A3[r],a=j3[r];return n.remove(r,i),a&&n.remove(a),F3(t)}function z3(e,t,n){let[r,i]=(0,U.useState)(()=>I3(e,t,P3,n));(0,U.useEffect)(()=>{i(I3(e,t,P3,n))},[e,t,n]);let a=(0,U.useCallback)(t=>{i(n=>{let r=t(n);return L3(e,r),r})},[e]);return{settings:r,setLayout:(0,U.useCallback)(e=>{a(t=>({...t,layout:e}))},[a]),toggleField:(0,U.useCallback)(e=>{a(t=>{let n=new Set(t.visibleFields);return n.has(e)?n.delete(e):n.add(e),{...t,visibleFields:Array.from(n)}})},[a]),setVisibleFields:(0,U.useCallback)(e=>{a(t=>({...t,visibleFields:e}))},[a]),setGroupBy:(0,U.useCallback)(e=>{a(t=>({...t,groupBy:e}))},[a]),resetSettings:(0,U.useCallback)(()=>{let n=R3(e,t);i(n)},[e,t])}}function B3(e,t=200){let[n,r]=(0,U.useState)(t),i=(0,U.useRef)(null);(0,U.useEffect)(()=>{r(t)},[e,t]);let a=n<e.length,o=(0,U.useCallback)(t=>r(n=>Math.max(n,Math.min(Math.max(t,0),e.length))),[e.length]);return(0,U.useEffect)(()=>{let n=i.current;if(!n||!a)return;let o=new IntersectionObserver(n=>{n.some(e=>e.isIntersecting)&&r(n=>Math.min(n+t,e.length))},{rootMargin:`400px`});return o.observe(n),()=>o.disconnect()},[a,e.length,t]),{visible:e.slice(0,n),hasMore:a,sentinelRef:i,total:e.length,growTo:o}}function V3(e,t){let n=X(e);return n.error||!Vm(n)?e:jh({...n,metric:t})}function H3(e){let t=X(e);return t.error?e:jh({...t,window:void 0})}function U3(e,t){let n=X(e);return n.error?e:jh({...n,groupBy:[t]})}function W3(e){return e.kind===`note`&&!e.sourceNote?!1:e.kind===`note`}async function G3(e){if(e.wodBlock?.content.trim())return e.wodBlock.content;let t=await CP.resolve(e.id),n=JH(t&&typeof t==`object`&&`rawContent`in t?String(t.rawContent??``):``),r=n.find(e=>e.dialect===`time`)??n[0];if(!r)throw Error(`No runnable workout block in this entry.`);return r.script}function K3(e,t){return{id:e.wodBlock?.blockId??e.block?.blockId??w(),contentId:e.wodBlock?.blockContentId??e.blockContentId,dialect:`time`,startLine:0,endLine:t.split(`
450
- `).length,content:t,state:`idle`,widgetIds:{},version:1,createdAt:Date.now()}}async function q3(e,t){let n=await G3(e),r=K3(e,n),i=w();if(nU(e)){let n=await CP.getById(e.id),a=e.wodBlock||e.block?n.blocks?.[r.id]:Object.values(n.blocks??{}).find(e=>e.kind===`wod`);if(!a)throw Error(`The selected saved workout is unavailable.`);W1.set(i,{block:{...r,id:a.id},noteId:e.id,origin:`playground`,returnTo:tU(e)}),t(ON(i));return}let a=await U1({workoutName:e.title,category:e.sourceNotebook,sourceNoteLabel:e.subtitle??e.title,sourceNotePath:tU(e),wodContent:n}),o=Object.values(a.blocks??{}).find(e=>e.kind===`wod`);if(!o)throw Error(`The saved journal workout is unavailable.`);W1.set(i,{block:{...r,id:o.id},noteId:a.id}),t(wN(a.journalDate??``,i))}var J3={note:P,effort:se,result:qe,segment:s,event:y,dashboard:an,equipment:O,tag:M},Y3={note:`Note`,effort:`Effort`,result:`Result`,segment:`Segment`,event:`Event`,dashboard:`Dashboard`,equipment:`Equipment`,tag:`Tag`},X3={note:`bg-primary/10 text-primary group-hover:bg-primary/20`,effort:`bg-emerald-500/10 text-emerald-600 group-hover:bg-emerald-500/20`,result:`bg-sky-500/10 text-sky-600 group-hover:bg-sky-500/20`,segment:`bg-indigo-500/10 text-indigo-600 group-hover:bg-indigo-500/20`,event:`bg-indigo-500/10 text-indigo-600 group-hover:bg-indigo-500/20`,dashboard:`bg-cyan-500/10 text-cyan-600 group-hover:bg-cyan-500/20`,equipment:`bg-orange-500/10 text-orange-600 group-hover:bg-orange-500/20`,tag:`bg-violet-500/10 text-violet-600 group-hover:bg-violet-500/20`};function Z3({entry:e,leading:t,actions:n,dateLabel:r,visibleFieldIds:i,tone:a=`secondary`,onAddToToday:o,onRunStart:s,moveNotebookTargets:c,onMoveNotebook:l}){let u=Vn(),d=e.kind===`note`?e.sourceNotebook:void 0,f=!!d&&d!==`journal`&&d!==`playground`&&d!==`guides`,p=d===`playground`?vr:d===`guides`?xt:f?Qn:J3[e.kind],m=d===`playground`?`Playground`:d===`guides`?`Guide`:f?`Notebook`:Y3[e.kind],h=f?`bg-amber-500/10 text-amber-600 group-hover:bg-amber-500/20`:X3[e.kind],g=a===`primary`,_=rU(e),v=tU(e),y=i?new Set(i):null,b=!y||y.has(`date`),x=!y||y.has(`sourceNotebook`)||y.has(`protocol`)||y.has(`elapsedTime`)||y.has(`splitDuration`)||y.has(`discipline`)||y.has(`met`)||y.has(`canonicalSlug`),S=!y||y.has(`excerpt`)||y.has(`movements`)||y.has(`tags`)||y.has(`aliases`);return(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>u(tU(e)),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),u(tU(e)))},className:`flex items-center gap-4 px-6 py-3.5 hover:bg-muted/40 transition-colors text-left group w-full cursor-pointer ${g?`bg-primary/[0.025]`:``}`,"data-testid":`library-row-${e.kind}`,children:[t,(0,W.jsx)(`div`,{className:`flex-shrink-0 size-9 rounded-xl flex items-center justify-center transition-colors ${h}`,children:(0,W.jsx)(p,{className:`size-4`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-bold text-foreground min-w-0 basis-full sm:basis-auto sm:truncate`,children:e.title}),e.block&&(0,W.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-widest text-sky-600 border border-sky-500/40 bg-sky-500/10 rounded-full px-1.5 py-0.5`,"data-testid":`library-row-block-type`,children:e.block.dataType}),(0,W.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-widest text-muted-foreground/60 border border-border rounded-full px-1.5 py-0.5`,children:m}),e.execution?.effortSlug&&(0,W.jsx)(_n,{to:RN(e.execution.effortSlug),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),"data-testid":`library-row-effort-link`,className:`text-[9px] font-bold tracking-wide text-primary/80 hover:text-primary bg-primary/10 hover:bg-primary/20 border border-primary/20 rounded-full px-2 py-0.5 transition-colors shrink-0`,title:`View movement history for ${e.detail??e.execution.effortSlug}`,children:e.detail??e.execution.effortSlug}),_&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(_n,{to:v,"data-testid":`library-row-details-link`,className:`text-[9px] font-bold tracking-wide text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted border border-border rounded-full px-2 py-0.5 transition-colors`,title:`View notebook details`,children:`Details`}),(0,W.jsx)(_n,{to:_,"data-testid":`library-row-feed-link`,className:`text-[9px] font-bold tracking-wide text-primary/80 hover:text-primary bg-primary/10 hover:bg-primary/20 border border-primary/20 rounded-full px-2 py-0.5 transition-colors`,title:`View feed`,children:`Feed`})]}),e.subtitle&&x&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 truncate`,children:e.subtitle})]}),S&&(e.block?(0,W.jsx)(`div`,{className:`mt-0.5`,"data-testid":`library-row-block-preview`,children:e.block.preview.map((e,t)=>(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate font-mono`,children:e},t))}):e.detail?(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate mt-0.5`,children:e.detail}):null)]}),r&&b&&(0,W.jsx)(`span`,{className:`flex-shrink-0 text-[10px] text-muted-foreground/70 tabular-nums`,"data-testid":`library-row-date`,children:r}),n??(0,W.jsx)(Q3,{entry:e,onAddToToday:o,onRunStart:s,moveNotebookTargets:c,onMoveNotebook:l})]})}function Q3({entry:e,onAddToToday:t,onRunStart:n,moveNotebookTargets:r,onMoveNotebook:i}){let a=Vn(),o=iU(e),s=rU(e),c=aU(e)&&!!t,l=W3(e)&&!!n,u=!!i&&e.kind===`note`&&!!e.notebookId&&e.notebookId!==`notebook/journal`&&!!r?.length,d=r?.filter(t=>t.id!==e.notebookId)??[];return(0,W.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(e6,{title:s?`Details`:`Open`,testId:`action-open`,onClick:()=>a(tU(e)),children:(0,W.jsx)(pn,{className:`size-3.5`})}),s&&(0,W.jsx)(e6,{title:`Notebook`,testId:`action-notebook`,onClick:()=>a(s),children:(0,W.jsx)(Qn,{className:`size-3.5`})}),c&&(0,W.jsx)(e6,{title:`Add to today`,testId:`action-add`,onClick:()=>t?.(e),children:(0,W.jsx)(On,{className:`size-3.5`})}),l&&(0,W.jsx)(e6,{title:`Run`,testId:`action-run`,onClick:()=>n?.(e),children:(0,W.jsx)(pn,{className:`size-3.5`})}),u&&d.length>0&&(0,W.jsx)($3,{targets:d,triggerTestId:`action-move`,itemTestIdPrefix:`action-move-`,triggerClassName:`size-8 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,onMove:t=>i?.(e,t)}),o&&(0,W.jsx)(e6,{title:`Compare`,testId:`action-compare`,onClick:()=>a(o),children:(0,W.jsx)($n,{className:`size-3.5`})})]})}function $3({targets:e,triggerTestId:t,itemTestIdPrefix:n,triggerClassName:r,onMove:i}){return(0,W.jsxs)(ZB,{children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,title:`Move to notebook`,"data-testid":t,className:r,children:(0,W.jsx)(Ae,{className:`size-3.5`})})}),(0,W.jsxs)($B,{align:`end`,children:[(0,W.jsx)(tV,{children:`Move to notebook`}),(0,W.jsx)(nV,{}),e.map(e=>(0,W.jsxs)(eV,{"data-testid":`${n}${e.id}`,onClick:()=>i(e.id),children:[(0,W.jsx)(`span`,{className:`w-5 text-center`,children:e.icon}),(0,W.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))]})]})}function e6({title:e,testId:t,onClick:n,children:r}){return(0,W.jsx)(`button`,{type:`button`,title:e,onClick:n,"data-testid":t,className:`size-8 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,children:r})}function t6({entries:e,level:t,visibleFieldIds:n,onRowClick:r,emptyMessage:i=`No entries to display`,className:a=``,stickyHeaderTop:o}){let s=Vn(),c=(0,U.useMemo)(()=>t||(e.length>0?fV(e[0]):`note`),[t,e]),l=(0,U.useMemo)(()=>hV(c),[c]),u=(0,U.useMemo)(()=>{let e=new Set(n??gV(c));return l.filter(t=>e.has(t.id))},[l,n,c]),d=e=>{r?r(e):s(tU(e))},[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(`asc`),g=e=>{f===e?h(e=>e===`asc`?`desc`:`asc`):(p(e),h(`asc`))},_=(0,U.useMemo)(()=>{if(!f)return e;let t=l.find(e=>e.id===f);return t?[...e].sort((e,n)=>{let r=t.getValue(e),i=t.getValue(n);if(r==null&&i==null)return 0;if(r==null)return m===`asc`?1:-1;if(i==null)return m===`asc`?-1:1;if(typeof r==`number`&&typeof i==`number`)return m===`asc`?r-i:i-r;if(Array.isArray(r)&&Array.isArray(i)){let e=r.join(`, `),t=i.join(`, `);return m===`asc`?e.localeCompare(t):t.localeCompare(e)}let a=String(r),o=String(i);return m===`asc`?a.localeCompare(o):o.localeCompare(a)}):e},[e,f,m,l]);return e.length===0?(0,W.jsx)(`div`,{className:`w-full py-16 text-center text-sm text-muted-foreground ${a}`,"data-testid":`property-table-empty`,children:i}):(0,W.jsx)(`div`,{className:`w-full border-y border-border bg-card/50 ${o===void 0?`overflow-x-auto`:`overflow-x-clip`} ${a}`,"data-testid":`property-table`,children:(0,W.jsxs)(`table`,{className:`w-full text-left border-collapse text-xs`,children:[(0,W.jsx)(`thead`,{className:o===void 0?void 0:`sticky z-10`,style:o===void 0?void 0:{top:`${o}px`},children:(0,W.jsx)(`tr`,{className:`border-b border-border`,children:u.map(e=>{let t=e.align===`right`?`text-right`:e.align===`center`?`text-center`:`text-left`;return(0,W.jsx)(`th`,{scope:`col`,onClick:()=>g(e.id),className:`px-4 py-3 font-semibold uppercase tracking-wider text-[11px] text-muted-foreground whitespace-nowrap border-b border-border cursor-pointer select-none hover:text-foreground transition-colors group/th ${o===void 0?`bg-muted/30`:`bg-muted/95 backdrop-blur-sm`} ${t}`,"data-testid":`property-table-header-${e.id}`,children:(0,W.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 ${t===`text-right`?`justify-end`:t===`text-center`?`justify-center`:`justify-start`}`,children:[(0,W.jsx)(`span`,{children:e.label}),f===e.id?(0,W.jsx)(`span`,{className:`text-primary font-bold text-xs`,"aria-label":m===`asc`?`sorted ascending`:`sorted descending`,children:m===`asc`?`↑`:`↓`}):(0,W.jsx)(`span`,{className:`opacity-0 group-hover/th:opacity-40 text-muted-foreground text-[10px]`,"aria-hidden":`true`,children:`↕`})]})},e.id)})})}),(0,W.jsx)(`tbody`,{className:`divide-y divide-border/60`,children:_.map(e=>{let t=rU(e),n=tU(e);return(0,W.jsx)(`tr`,{role:`button`,tabIndex:0,onClick:()=>d(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),d(e))},className:`hover:bg-muted/40 transition-colors cursor-pointer group`,"data-testid":`property-table-row-${e.id}`,children:u.map(r=>{let i=r.getValue(e),a=r.formatValue(i,e),o=r.align===`right`?`text-right tabular-nums`:r.align===`center`?`text-center`:`text-left`;return(0,W.jsx)(`td`,{className:`px-4 py-3 whitespace-nowrap text-foreground/90 ${o}`,"data-testid":`property-table-cell-${r.id}`,children:r.id===`pacingTier`&&e.execution?.effortSlug?(0,W.jsx)(_n,{to:RN(e.execution.effortSlug),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),"data-testid":`property-table-effort-link`,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium bg-primary/10 text-primary hover:bg-primary/20 border border-primary/20 transition-colors`,title:`View movement history for ${e.detail??e.execution.effortSlug}`,children:a}):r.id===`title`||r.id===`label`?(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-foreground group-hover:text-primary transition-colors`,children:a}),t&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 ml-auto`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(_n,{to:n,"data-testid":`property-table-details-link`,className:`rounded px-1.5 py-0.5 text-[10px] font-semibold text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted border border-border transition-colors`,title:`View catalog details`,children:`Details`}),(0,W.jsx)(_n,{to:t,"data-testid":`property-table-feed-link`,className:`rounded px-1.5 py-0.5 text-[10px] font-semibold bg-primary/10 text-primary hover:bg-primary/20 border border-primary/20 transition-colors`,title:`View feed`,children:`Feed`})]})]}):a},r.id)})},e.id)})})]})})}var n6={note:P,effort:se,result:qe,segment:s,event:y,dashboard:an,equipment:O,tag:M},r6={note:`Note`,effort:`Effort`,result:`Result`,segment:`Segment`,event:`Event`,dashboard:`Dashboard`,equipment:`Equipment`,tag:`Tag`},i6=8;function a6({entry:e}){let t=e.execution;if(!t)return null;let n=[];return t.elapsedMs!=null&&n.push(kz(t.elapsedMs)),t.reps!=null&&n.push(`${t.reps} reps`),t.loadLbs!=null&&n.push(`${t.loadLbs} lb`),t.distanceMeters!=null&&n.push(`${(t.distanceMeters/1e3).toFixed(2)} km`),t.tis!=null&&n.push(`TIS ${t.tis}`),n.length===0?null:(0,W.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`stream-feed-metrics`,children:n.map(e=>(0,W.jsx)(`span`,{className:`rounded-full bg-muted/70 border border-border/60 px-2 py-0.5 text-[10px] font-bold tabular-nums text-muted-foreground`,children:e},e))})}function o6({entry:e}){let[t,n]=(0,U.useState)(!1),r=e.wodBlock?.content.trim(),i=r?r.split(`
448
+ `,C0=BL(h0);if(!C0)throw Error(`The baked home page must remain a valid canvas document`);var w0=C0,T0={"markdown/canvas/home/welcome-1.md":g0,"markdown/canvas/syntax/single-movement.md":_0,"markdown/canvas/syntax/timers-rest.md":v0,"markdown/canvas/syntax/groups-1.md":y0,"markdown/canvas/syntax/custom-metrics-1.md":b0,"markdown/canvas/syntax/dialect-climb-bouldering.md":x0,"markdown/canvas/syntax/complex-swimming.md":S0};function E0(e){return{...T0,...e}}function D0(e,t){if(e.startsWith(`# 👋`))return e;let n=t?.replace(/^shared by:?\s*/i,``).trim();return`${n?`# 👋 ${n} sent you this workout`:`# 👋 Edit Me`}\n\nChange the reps, distance, or load below — this is live.\n\n${e}\n\n> Press **Run** ↑ to start the Clock.\n`}var O0=`wodwiki.homeShared.v1`;function k0(){return typeof window<`u`&&window.localStorage?window.localStorage:null}function A0(e){try{k0()?.setItem(O0,JSON.stringify(e)),typeof window<`u`&&window.dispatchEvent(new CustomEvent(`wodwiki:home-shared`,{detail:e}))}catch{}}function j0(){try{let e=k0()?.getItem(O0);if(!e)return null;let t=JSON.parse(e);return typeof t?.content==`string`?{content:t.content,by:typeof t.by==`string`?t.by:void 0}:null}catch{return null}}function M0(){try{k0()?.removeItem(O0)}catch{}}function N0({pageRoute:e,quests:t,running:n}){let{markComplete:r}=Nq(e,t),i=(0,U.useMemo)(()=>t.filter(e=>e.validation?.type===`run-started`),[t]);(0,U.useEffect)(()=>{if(n)for(let e of i)r(e.id)},[n,i,r])}var P0={"session-insights":`qs-tour-analytics`},F0={"workout-complete":!0,"run-started":!0};function I0(e,t){let{markComplete:n}=Nq(e,t),r=(0,U.useRef)(new Set);return r.current=new Set(t.filter(e=>!e.validation||!F0[e.validation.type]).map(e=>e.id)),(0,U.useCallback)(e=>{let t=P0[e];t&&r.current.has(t)&&n(t)},[n])}var L0=.4;function R0(e){let{dispatch:t}=WM();(0,U.useEffect)(()=>{let n=e.map(e=>document.getElementById(e)).filter(e=>e!==null);if(n.length===0||typeof IntersectionObserver>`u`)return;let r=()=>{let e=window.innerHeight*L0,t=null;for(let r of n){let n=r.getBoundingClientRect();if(n.width!==0||n.height!==0){if(n.top>e)break;t=r.id}}return t},i=new IntersectionObserver(()=>{let e=r();e&&t({type:`SET_ACTIVE_L3`,id:e})},{threshold:Array.from({length:21},(e,t)=>t/20)});return n.forEach(e=>i.observe(e)),()=>i.disconnect()},[e.join(`
449
+ `),t])}var z0=(0,U.createContext)(null);function B0({children:e}){let t=(0,U.useRef)({"editor.window":null,"editor.wodBlock":null,"editor.runButton":null,"editor.typeahead":null,"timer.floor":null,"timer.nextButton":null,"timer.castButton":null,"metrics.efforts":null,"metrics.data":null,"metrics.compound":null,"analytics.vocab":null,"analytics.table":null,"analytics.graphs":null,"analytics.dashboard":null}),[n,r]=(0,U.useState)(0),i=(0,U.useCallback)((e,n)=>{t.current[e]!==n&&(t.current[e]=n,r(e=>e+1))},[]);return(0,W.jsx)(z0.Provider,{value:{register:i,registry:t,version:n},children:e})}function V0(){return(0,U.useContext)(z0)||{registry:{current:{}},register:()=>()=>{},version:0}}function H0(e){let t=(0,U.useContext)(z0)?.register;return(0,U.useCallback)(n=>t?.(e,n),[e,t])}function U0({ringKey:e,el:t}){let{register:n}=V0();return(0,U.useLayoutEffect)(()=>{n(e,t)},[e,t,n]),null}function W0({target:e,accent:t,canvasRef:n}){let{registry:r,version:i}=V0(),[a,o]=(0,U.useState)(null),s=e?.key??null;return(0,U.useLayoutEffect)(()=>{if(!s){o(null);return}let e=()=>{let e=r.current[s],t=n.current;if(!e||!t){o(null);return}let i=e.getBoundingClientRect(),a=t.getBoundingClientRect(),c=Math.round(i.left-a.left),l=Math.round(i.top-a.top),u=Math.round(i.width),d=Math.round(i.height);if(u<=0||d<=0||c+u<0||l+d<0||c>a.width||l>a.height){o(null);return}o({x:c,y:l,w:u,h:d})};e();let t=window.setTimeout(e,120),i=window.setTimeout(e,480),a=null,c=r.current[s];c&&typeof ResizeObserver<`u`&&(a=new ResizeObserver(e),a.observe(c));let l=new MutationObserver(e);return c&&l.observe(c,{attributes:!0,attributeFilter:[`style`]}),window.addEventListener(`resize`,e),()=>{window.clearTimeout(t),window.clearTimeout(i),a?.disconnect(),l.disconnect(),window.removeEventListener(`resize`,e)}},[s,i,r,n]),!e||!a?null:(0,W.jsx)(`div`,{"data-testid":`tour-ring`,className:`pointer-events-none absolute z-30 rounded-2xl transition-all duration-500 ease-out`,style:{left:a.x-6,top:a.y-6,width:a.w+12,height:a.h+12,boxShadow:`0 0 0 2px ${t}`}})}function G0(){return(0,W.jsxs)(`div`,{className:`@container flex w-full flex-col items-center text-center`,children:[(0,W.jsxs)(`h1`,{className:`text-[clamp(32px,6.5cqi,64px)] font-extrabold leading-[1.02] tracking-[-0.04em]`,children:[(0,W.jsxs)(`span`,{className:`block`,children:[(0,W.jsx)(`span`,{className:`mr-[0.35em]`,children:`Write it.`}),(0,W.jsx)(`span`,{children:`Time it.`})]}),(0,W.jsxs)(`span`,{className:`block`,children:[(0,W.jsx)(`span`,{className:`mr-[0.35em]`,children:`Track it.`}),(0,W.jsx)(`span`,{children:`Own it.`})]})]}),(0,W.jsxs)(`p`,{className:`mt-4 xl:mt-6 max-w-xl xl:max-w-2xl 2xl:max-w-3xl text-[15px] sm:text-base xl:text-lg leading-relaxed text-muted-foreground`,children:[`Plain-text Markdown becomes a step-through workout clock, `,(0,W.jsx)(`br`,{}),`line and splits become queryable training data points.`]})]})}var K0=`dQw4w9WgXcQ`;function q0({onWatched:e}){let[t,n]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-4 xl:gap-5`,children:[(0,W.jsxs)(`div`,{className:`group relative aspect-video w-full max-w-2xl rounded-xl border border-border bg-black text-left shadow-xl transition-shadow hover:shadow-2xl 2xl:max-w-3xl`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(!0),"data-testid":`tour-why-video`,"aria-label":`Play the Why Wod Wiki? video`,className:`block h-full w-full overflow-hidden rounded-xl`,children:[(0,W.jsx)(`img`,{src:`https://i.ytimg.com/vi/${K0}/hqdefault.jpg`,alt:`Why Wod Wiki? video thumbnail`,loading:`lazy`,className:`h-full w-full object-cover transition-transform duration-300 group-hover:scale-[1.02]`}),(0,W.jsx)(`span`,{className:`absolute inset-0 bg-gradient-to-t from-black/70 via-black/10 to-transparent`}),(0,W.jsx)(`span`,{className:`absolute left-1/2 top-1/2 flex size-14 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full bg-background/90 text-foreground shadow-lg transition-transform duration-300 group-hover:scale-110 xl:size-16`,children:(0,W.jsx)(pn,{className:`ml-1 size-6 fill-current xl:size-7`})}),(0,W.jsx)(`span`,{className:`absolute bottom-3 left-4 font-mono text-[11px] uppercase tracking-[0.2em] text-white/90`,children:`Why Wod Wiki? · YouTube`})]}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{n(!1),e?.()},"data-testid":`tour-why-video-skip`,title:`Skip the video`,"aria-label":`Skip the Why Wod Wiki? video`,className:`absolute right-0 top-0 z-10 flex size-8 items-center justify-center rounded-full border border-border bg-background/90 text-foreground shadow-lg backdrop-blur-sm transition-colors hover:bg-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary after:absolute after:-inset-3 after:content-[''] md:-right-2 md:-top-2`,children:(0,W.jsx)(we,{className:`size-4`})})]}),(0,W.jsxs)(`p`,{"data-testid":`tour-scroll-hint`,className:`flex items-center gap-2 font-mono text-[11px] uppercase tracking-[0.3em] text-muted-foreground`,children:[(0,W.jsx)(Et,{className:`size-4 animate-bounce`}),`Keep scrolling for the demo`]}),t&&(0,W.jsx)(w$,{videoId:K0,title:`Why Wod Wiki?`,onClose:()=>{n(!1),e?.()}})]})}var J0=`https://github.com/bitcobblers/wod-wiki`;function Y0(){return(0,W.jsx)(`footer`,{"data-testid":`tour-footer`,className:`border-t border-border px-6 py-8`,children:(0,W.jsxs)(`p`,{className:`mx-auto flex max-w-3xl flex-wrap items-center justify-center gap-2 text-sm text-muted-foreground`,children:[(0,W.jsxs)(`span`,{children:[`© `,new Date().getFullYear(),` WOD Wiki`]}),(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,W.jsx)(`a`,{href:J0,target:`_blank`,rel:`noopener noreferrer`,className:`underline-offset-4 transition-colors hover:text-foreground hover:underline`,children:`GitHub repository`})]})})}async function X0(){try{await Z.wipe()}catch{}try{for(let e=localStorage.length-1;e>=0;e--){let t=localStorage.key(e);t&&localStorage.removeItem(t)}}catch{}try{sessionStorage.clear()}catch{}}var Z0=`https://github.com/bitcobblers/wod-wiki`,Q0=`https://forms.gle/6YHpxwAJh6PAsyAQ6`,$0=`https://app.turso.tech/signup`,e2=`m23.31.803-.563-.42-1.11 1.189-.891-1.286-.512.235.704 1.798-.326.35L18.082 0l-.574.284 2.25 4.836-2.108.741h-.05l-1.143-1.359-1.144 1.36H8.687l-1.144-1.36-1.146 1.363H6.36l-2.12-.745L6.491.284 5.919 0l-2.53 2.668-.327-.349.705-1.798-.512-.236-.89 1.287L1.253.382.69.804 2.42 3.69l-.89.939.311 2.375 2.061.787L3.9 8.817H1.947v.444l.755 1.078 1.197.433v6.971l3.057 4.55L7.657 24l1.101-1.606L9.9 24l.999-1.606L12 24l1.102-1.606L14.1 24l1.141-1.606L16.343 24l.701-1.706 3.058-4.55v-6.972l1.196-.433.756-1.078v-.444h-1.952l.003-1.03 2.054-.784.311-2.375-.89-.939zm-8.93 18.718H8.033l.793-1.615.794 1.615.793-1.083.793 1.083.794-1.083.793 1.083.794-1.083.793 1.083.793-1.615.794 1.615zm3.886-7.39-3.3 1.084-.143 3.061-2.827.627-2.826-.627-.142-3.06-3.3-1.085v-1.635l4.266 1.21-.052 4.126h4.109l-.052-4.127 4.266-1.209z`,t2=[{id:`managed-hosting`,label:`Managed hosting — we run the database.`},{id:`public-profile`,label:`Profile page with a public feed.`},{id:`device-sync`,label:`Sync across your apps and devices.`}],n2=[{id:`coach-views`,label:`Member accounts with coach views.`},{id:`coaches-portal`,label:`Programming dashboards and leaderboards.`},{id:`athlete-portal`,label:`Private journals that roll up to their coach.`},{id:`gym-hosting`,label:`Gym website, competition timers, whiteboard displays.`},{id:`branding`,label:`Your gym's brand on pages and feeds.`}],r2=`underline-offset-4 transition-colors hover:text-foreground hover:underline`;function i2(e){let t=`inline-flex w-fit items-center gap-1.5 font-medium text-foreground underline-offset-4 transition-colors hover:underline`,n=(0,W.jsxs)(W.Fragment,{children:[e.children,(0,W.jsx)(h,{className:`size-3.5 text-muted-foreground/50`,"aria-hidden":!0})]});return e.href===void 0?e.onClick===void 0?(0,W.jsx)(_n,{to:e.to,className:t,children:n}):(0,W.jsx)(`button`,{type:`button`,onClick:e.onClick,className:`text-left ${t}`,children:n}):(0,W.jsx)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:t,children:n})}function a2({children:e}){return(0,W.jsxs)(`li`,{className:`flex gap-2.5 text-sm leading-6 text-muted-foreground`,children:[(0,W.jsx)(`span`,{"aria-hidden":!0,className:`mt-[11px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,W.jsx)(`span`,{children:e})]})}function o2(){return(0,W.jsx)(`span`,{className:`rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-0.5 font-mono text-[11px] font-medium text-emerald-600`,children:`Active`})}function s2(e){return(0,W.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,W.jsxs)(`span`,{className:`flex gap-2.5 text-[13px] leading-5 text-muted-foreground`,children:[(0,W.jsx)(`span`,{"aria-hidden":!0,className:`mt-[9px] size-1 shrink-0 rounded-full bg-muted-foreground/50`}),(0,W.jsx)(`span`,{children:e.feature.label})]}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`hosted-interest-${e.feature.id}`,onClick:()=>e.onInterested(e.feature.id),disabled:e.interested,"aria-pressed":e.interested,className:`ml-[13px] w-fit shrink-0 rounded-full border px-2 py-px text-[11px] font-medium transition-colors ${e.interested?`border-emerald-500/30 bg-emerald-500/10 text-emerald-600`:`border-border text-muted-foreground hover:border-primary/50 hover:text-primary`}`,children:e.interested?`✓ Interested`:`Interested`})]})}function c2(){return(0,W.jsx)(`div`,{role:`status`,"data-testid":`hosted-survey-footer`,className:`mx-auto mt-5 max-w-5xl animate-in fade-in slide-in-from-bottom-4 rounded-xl border border-emerald-500/30 bg-emerald-500/10 p-4 duration-500`,children:(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,W.jsx)(yn,{className:`size-5 shrink-0 text-emerald-600`,"aria-hidden":!0}),(0,W.jsxs)(`div`,{className:`text-sm`,children:[(0,W.jsx)(`p`,{className:`font-medium text-foreground`,children:`Thanks for showing interest — please fill out the survey and give us feedback.`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Opens the interest survey in a new tab.`})]})]}),(0,W.jsxs)(K,{type:`button`,"data-testid":`hosted-survey-button`,onClick:()=>{dq.record(fq.hostedSurveyOpened),window.open(Q0,`_blank`,`noopener,noreferrer`)},children:[`Fill out interest survey`,(0,W.jsx)(h,{className:`size-4`,"aria-hidden":!0})]})]})})}function l2(e){let t=e.icon;return(0,W.jsxs)(`article`,{className:`flex flex-col rounded-xl border border-border p-5 ${e.us?`bg-muted/40`:`bg-background`} ${e.className??``}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,W.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),e.badge]}),e.eyebrow&&(0,W.jsx)(`p`,{className:`mt-3.5 font-mono text-[10px] font-semibold uppercase tracking-[0.18em] ${e.us?`text-emerald-600`:`text-muted-foreground`}`,children:e.eyebrow}),(0,W.jsx)(`h3`,{className:`${e.eyebrow?`mt-1`:`mt-4`} text-base font-semibold text-foreground`,children:e.title}),(0,W.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.text}),(0,W.jsx)(`div`,{className:`mt-4 flex flex-1 flex-col gap-2 text-sm`,children:e.children})]})}function u2({label:e,features:t,interested:n,onInterested:r}){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`p`,{className:`mt-2.5 font-mono text-[11px] font-semibold uppercase tracking-[0.14em] text-muted-foreground first:mt-0`,children:e}),(0,W.jsx)(`ul`,{className:`space-y-2`,children:t.map(e=>(0,W.jsx)(s2,{feature:e,interested:n.has(e.id),onInterested:r},e.id))})]})}function d2(){let[e,t]=(0,U.useState)(!1),n=Vn(),[r,i]=(0,U.useState)(new Set),a=e=>{i(t=>t.has(e)?t:new Set(t).add(e)),dq.record(fq.hostedInterestClicked,{feature:e})},[o]=(0,U.useState)(vk),s=o.state===`turso`?`turso`:o.state===`invalid`?`turso-invalid`:`browser`,c=async()=>{window.confirm(`Wipe every note, result, and setting stored in this browser? This cannot be undone.`)&&(t(!0),await X0(),window.location.reload())},l=async()=>{let e=_P(),t=await CP.create({journalDate:e,title:e,rawContent:``});dq.record(fq.noteCreated),n(TN(t.id))},u=s===`turso-invalid`?(0,W.jsx)(`span`,{className:`rounded-full border border-amber-500/30 bg-amber-500/10 px-2 py-0.5 font-mono text-[11px] font-medium text-amber-600`,children:`Invalid config`}):s===`api`?void 0:(0,W.jsx)(o2,{});return(0,W.jsxs)(`section`,{id:`tour-section-offerings`,"data-testid":`tour-section-offerings`,"aria-label":`You own your data`,children:[(0,W.jsx)(T$,{index:`04`,before:`Who owns the data? `,accentText:`You!!!`,after:``,accent:D$.library,blurb:`Run it in your browser, back it up to your own database, or host it on your own server — and if you'd rather hand the caretaking to us, mark the hosted features you want below and the interest survey unlocks.`}),(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-[1500px] 2xl:max-w-[1720px] px-6 pb-16 pt-10 lg:px-12 xl:px-16`,children:[(0,W.jsxs)(`p`,{className:`mx-auto mb-5 flex max-w-5xl flex-wrap items-center justify-between gap-3 text-sm text-muted-foreground`,role:`status`,children:[(0,W.jsx)(`span`,{children:s===`api`?`Current mode: API server`:s===`turso`?`Current mode: local browser with Turso backup and sync`:s===`turso-invalid`?`Current mode: local browser. Repair the Turso connection to resume sync.`:`Current mode: local browser only`}),(0,W.jsx)(_n,{to:$.settingsStorage,className:r2,children:`Configure data storage`})]}),(0,W.jsxs)(`div`,{className:`mx-auto grid max-w-5xl grid-cols-1 gap-5 md:grid-cols-3`,children:[(0,W.jsxs)(l2,{icon:ee,eyebrow:`You own it`,title:`Playground in your browser`,badge:u,text:`Everything runs locally in this browser's IndexedDB — offline, no account, no server copy.`,children:[(0,W.jsx)(i2,{onClick:()=>void l(),children:`Create your journal`}),(0,W.jsx)(i2,{to:$.playgroundRoot,children:`Start Writing in a Playground`}),(0,W.jsx)(i2,{to:`/feeds`,children:`Explore the notebooks`}),(0,W.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,W.jsx)(a2,{children:`Offline and fast — notes and results never leave this browser by default.`}),(0,W.jsx)(a2,{children:`Tied to this browser — export or back it up before switching browsers or clearing site data.`})]}),(0,W.jsx)(`button`,{type:`button`,onClick:c,disabled:e,className:`mt-1 text-left text-xs text-muted-foreground disabled:opacity-50 ${r2}`,children:e?`Clearing…`:`Clear my data`}),(0,W.jsxs)(`div`,{className:`mt-auto border-t border-border pt-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-2.5`,children:[(0,W.jsx)(`span`,{className:`mt-0.5 flex size-8 shrink-0 items-center justify-center rounded-lg border border-border bg-background`,children:(0,W.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`currentColor`,className:`size-4`,"aria-hidden":!0,children:(0,W.jsx)(`path`,{d:e2})})}),(0,W.jsxs)(`div`,{className:`text-sm`,children:[(0,W.jsx)(`p`,{className:`font-medium text-foreground`,children:`Backup & sync, optional`}),(0,W.jsx)(`p`,{className:`text-xs leading-5 text-muted-foreground`,children:`Add a free Turso database you own — committed changes back up in the background; without network you keep working and upload later.`})]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex flex-col gap-2`,children:[(0,W.jsx)(i2,{href:$0,children:`Create a free Turso account`}),(0,W.jsx)(i2,{to:$.settingsStorage,children:`Configure backup & sync`})]})]})]}),(0,W.jsxs)(l2,{icon:Hn,eyebrow:`You own it`,title:`Self-hosted`,badge:s===`api`?(0,W.jsx)(o2,{}):void 0,text:`Build the app for API storage and run the Wod Wiki server yourself — local or cloud data access through a server you administer.`,children:[(0,W.jsxs)(`ul`,{className:`mt-1 space-y-1.5`,children:[(0,W.jsx)(a2,{children:`Centralized data for a team or gym — one SQLite, Turso, or Postgres backend.`}),(0,W.jsxs)(a2,{children:[`Publish your notebooks as a feed with `,(0,W.jsx)(`code`,{className:`font-mono text-xs`,children:`wod build`}),` — every browser subscribes and syncs.`]}),(0,W.jsx)(a2,{children:`You run the server — network required, and server admin is on you.`})]}),(0,W.jsx)(`div`,{className:`mt-auto border-t border-border pt-4`,children:(0,W.jsx)(i2,{href:Z0,children:`View source`})})]}),(0,W.jsxs)(l2,{icon:$e,us:!0,eyebrow:`Us — we'd host it`,title:`Wod-Wiki hosted`,text:`Mark the features you want — the survey unlocks below.`,children:[(0,W.jsx)(u2,{label:`Individuals`,features:t2,interested:r,onInterested:a}),(0,W.jsx)(u2,{label:`Coaching & gyms`,features:n2,interested:r,onInterested:a})]})]}),r.size>0&&(0,W.jsx)(c2,{})]})]})}var f2=({doc:e,onDocChange:t,onBlocksChange:n,onRun:r,theme:i,withRingTargets:a=!1})=>{let o=H0(`editor.wodBlock`),s=H0(`editor.runButton`),c=(0,U.useRef)(null),l=(0,U.useRef)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(null),m=(0,U.useCallback)(()=>{if(!a)return null;let e=c.current;if(!e)return null;let t=null,n=e.querySelector(`.cm-wod-fence-open`),r=e.querySelector(`.cm-wod-fence-close`);if(n&&r){let i=e.getBoundingClientRect(),a=n.getBoundingClientRect(),o=r.getBoundingClientRect();if(a.top>=i.top-2&&o.bottom<=i.bottom+2){let n=e.offsetWidth?i.width/e.offsetWidth:1;t={top:(a.top-i.top)/n,left:(Math.min(a.left,o.left)-i.left)/n,width:(Math.max(a.right,o.right)-Math.min(a.left,o.left))/n,height:(o.bottom-a.top)/n}}}d(t);let i=null,o=e.querySelector(`[data-testid="${BU.EDITOR_START_WORKOUT}"]`);if(o){let t=e.getBoundingClientRect(),n=o.getBoundingClientRect();if(n.width>0&&n.height>0&&n.top>=t.top-2&&n.bottom<=t.bottom+2&&n.left>=t.left-2&&n.right<=t.right+2){let r=e.offsetWidth?t.width/e.offsetWidth:1;i={top:(n.top-t.top)/r,left:(n.left-t.left)/r,width:n.width/r,height:n.height/r}}}return p(i),{block:t,run:i}},[a]);(0,U.useLayoutEffect)(()=>{if(!a)return;let e=c.current;if(!e)return;m();let t=window.setTimeout(m,120),n=window.setTimeout(m,480),r=null;if(typeof ResizeObserver<`u`){r=new ResizeObserver(m),r.observe(e);let t=l.current?.contentDOM;t&&r.observe(t)}let i=new MutationObserver(e=>{e.some(e=>e.target instanceof Element&&e.target.closest(`.cm-note-editor`))&&m()});i.observe(e,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`style`]});let o=0,s=0,u=()=>{m(),performance.now()-s<3e3&&(o=requestAnimationFrame(u))},d=()=>{s=performance.now(),cancelAnimationFrame(o),o=requestAnimationFrame(u)};d(),document.fonts?.ready?.then(d).catch(()=>{});let f=l.current?.scrollDOM;return f?.addEventListener(`scroll`,m,{passive:!0}),window.addEventListener(`resize`,m),()=>{window.clearTimeout(t),window.clearTimeout(n),r?.disconnect(),i.disconnect(),f?.removeEventListener(`scroll`,m),window.removeEventListener(`resize`,m),cancelAnimationFrame(o)}},[e,a,m]);let h=(0,U.useCallback)(()=>{r()},[r]),g=(0,U.useMemo)(()=>[{id:`run`,label:`Run`,icon:(0,W.jsx)(pn,{className:`h-3 w-3 fill-current`}),primary:!0,onClick:h},{id:`playground`,label:`Playground`,icon:(0,W.jsx)(A,{className:`h-3 w-3`}),onClick:e=>{r0(e)},splitIcon:(0,W.jsx)(rt,{className:`h-3 w-3`}),splitSuccessIcon:(0,W.jsx)(un,{className:`h-3 w-3 text-emerald-500`}),onSplitClick:e=>{a0(e)}}],[h]);return(0,W.jsx)(`div`,{className:`relative flex h-full flex-col bg-background text-left`,children:(0,W.jsxs)(`div`,{ref:c,className:`relative flex-1 min-h-0`,children:[(0,W.jsx)(YZ,{noteId:`canvas:home`,value:e,onChange:t,onBlocksChange:n,onStartWorkout:h,commands:g,onViewCreated:e=>{l.current=e,a&&m()},theme:i,readonly:!1,showLineNumbers:!1,showFrontmatter:!1,enableOverlay:!1,enableInlineRuntime:!1,className:`h-full`}),a&&u&&(0,W.jsx)(`div`,{ref:o,"data-testid":`tour-wod-block-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:u.top,left:u.left,width:u.width,height:u.height}}),a&&f&&(0,W.jsx)(`div`,{ref:s,"data-testid":`tour-run-button-region`,"aria-hidden":!0,className:`pointer-events-none absolute`,style:{top:f.top,left:f.left,width:f.width,height:f.height}})]})})};function p2(e){let t=Number.isFinite(e.startTime)?e.startTime:0,n=[],r=[];for(let i of e.logs??[]){if(i.outputType!==`segment`||i.stackLevel!==1||i.line==null)continue;let e=i.timeSpan;if(!e||typeof e.started!=`number`||typeof e.ended!=`number`||e.ended<=e.started)continue;let a=i.metrics??[],o=e=>a.some(t=>t.type===e),s=a.find(e=>e.type===`effort`&&typeof e.value==`string`),c=o(`duration`)&&!o(`rep`)?`clock`:i.completionReason===`user-advance`?`next`:null;if(c){if(c===`clock`&&i.completionReason===`user-advance`){let t=(a.find(e=>e.type===`duration`&&typeof e.value==`number`)?.value??0)-(e.ended-e.started);t>0&&r.push(t)}n.push({start:e.started-t,end:e.ended-t,kind:c,label:s?.value??`Line ${i.line+1}`})}}if(n.length===0)return null;let i=r.reduce((e,t)=>e+t,0);return{segments:n,totalMs:Number.isFinite(e.duration)&&e.duration>0?e.duration:Math.max(...n.map(e=>e.end)),impatienceMs:i,impatiences:r,reactions:n.filter(e=>e.kind===`next`).map(e=>e.end-e.start)}}var m2=e=>{let t=Math.max(0,Math.round(e/1e3));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`},h2=e=>`${(Math.round(e/100)/10).toFixed(1)}s`;function g2({onRun:e}){return(0,W.jsxs)(`div`,{className:`flex h-full w-full flex-col items-center justify-center gap-4 p-8 text-center`,"data-testid":`tour-insights-empty`,children:[(0,W.jsx)(`p`,{className:`max-w-sm text-sm leading-relaxed text-muted-foreground`,children:`Run the workout and this window turns your run into data — rest vs. work, how fast you answered the clock, round by round.`}),(0,W.jsxs)(`button`,{type:`button`,onClick:e,"data-testid":`tour-insights-run`,className:`inline-flex min-h-11 items-center gap-2 rounded-full bg-primary px-5 py-2.5 text-sm font-semibold text-primary-foreground shadow transition-colors hover:bg-primary/90`,children:[(0,W.jsx)(pn,{className:`size-4`}),`Run to view the results`]})]})}function _2({result:e,onRun:t}){let n=(0,U.useMemo)(()=>e?p2(e):null,[e]);if(!e||!n)return(0,W.jsx)(g2,{onRun:t});let{segments:r,totalMs:i,impatienceMs:a,impatiences:o,reactions:s}=n,c=s.length>0?s.reduce((e,t)=>e+t,0)/s.length:0,l=s.length>0?Math.max(...s):0,u=o.length>0?Math.max(...o):0;return(0,W.jsxs)(`div`,{className:`flex h-full w-full flex-col gap-4 overflow-y-auto p-4`,"data-testid":`tour-insights`,children:[(0,W.jsxs)(`div`,{"data-testid":`tour-insights-timeline`,children:[(0,W.jsx)(`div`,{className:`flex h-3 w-full overflow-hidden rounded-full border border-border/60 bg-muted/40`,children:r.map((e,t)=>(0,W.jsx)(`div`,{title:`${e.label} — ${e.kind===`clock`?`countdown`:`to Next`} ${m2(e.end-e.start)}`,className:`h-full`,style:{flexGrow:e.end-e.start,flexBasis:0,backgroundColor:e.kind===`clock`?`hsl(var(--metric-rest))`:`hsl(var(--metric-time))`,marginLeft:+(t>0)}},t))}),(0,W.jsxs)(`div`,{className:`mt-1.5 flex items-center gap-4 font-mono text-[10px] uppercase tracking-wider text-muted-foreground`,children:[(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-rest))`}}),`Countdown`]}),(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`size-2 rounded-sm`,style:{backgroundColor:`hsl(var(--metric-time))`}}),`To Next click`]}),(0,W.jsxs)(`span`,{className:`ml-auto`,children:[m2(i),` total`]})]})]}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{"data-testid":`tour-insights-impatience`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,W.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Impatience Score`}),(0,W.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:h2(a)}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.length===0?`every countdown ran to zero`:`${o.length} early click${o.length===1?``:`s`}${o.length>1?` · worst ${h2(u)}`:``}`})]}),(0,W.jsxs)(`div`,{"data-testid":`tour-insights-reaction`,className:`rounded-xl border border-border bg-card p-4`,children:[(0,W.jsx)(`p`,{className:`font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground`,children:`Reaction Time`}),(0,W.jsx)(`p`,{className:`mt-2 text-2xl font-black tracking-tight text-foreground`,children:s.length>0?h2(c):`—`}),(0,W.jsxs)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:[s.length,` click`,s.length===1?``:`s`,s.length>1?` · slowest ${h2(l)}`:``]})]})]})]})}var v2=864e5;function y2(e){let t=new Date(e);return Math.round(Date.UTC(t.getFullYear(),t.getMonth(),t.getDate())/v2)}function b2(e,t){let n=[...e.keys()].filter(e=>e<=t);if(n.length===0)return[];let r=Math.min(...n),i=t=>e.get(t)??0,a=[];for(let e=r;e<=t;e++){let t=0,n=0;for(let r=0;r<28;r++){let a=i(e-r);n+=a,r<7&&(t+=a)}let r=t/7,o=n/28,s=0;for(let t=0;t<7;t++){let n=i(e-t)-r;s+=n*n}let c=Math.sqrt(s/7),l={day:e};o>0&&(l.acwr=r/o),c>0&&(l.monotony=r/c,l.strain=l.monotony*t),(l.acwr!==void 0||l.monotony!==void 0)&&a.push(l)}return a}var x2=864e5;function S2(e){return Math.round(e*10)/10}function C2(e,t,n=9){let r=new Date(e-t*x2);return r.setHours(n,0,0,0),r.getTime()}function w2(e,t,n,r,i,a={}){let o={canonicalKey:i};a.effortSlug&&(o.effortSlug=a.effortSlug),a.discipline&&(o.effortDiscipline=a.discipline),a.intensityTier&&(o.effortIntensityTier=a.intensityTier),e.push({id:e.length,outputType:`analytics`,timeSpan:{started:0},metrics:[{type:q.Label,value:t,origin:`analyzed`},{type:q.Metric,value:n,unit:r,origin:`analyzed`,metadata:o}],sourceBlockKey:``,stackLevel:0})}var T2=new Set([`tis`,`calc.acwr`,`calc.adherence`,`calc.ef`,`calc.pct1rm`]);function E2(e,t){return qg(e,{noteId:t.noteId,resultId:t.resultId,blockId:`example-block`,blockVersion:1,blockContentId:t.blockContentId,origin:`journal`,workoutTimestamp:t.timestamp}).map(e=>{let t=e.metrics[0];if(!t||!(`metadata`in t))return e;let n=t.metadata?.canonicalKey;return typeof n!=`string`||!T2.has(n)||typeof t.value!=`number`?e:{...e,reducerStats:{observedCount:1,sum:t.value,min:t.value,max:t.value}}})}function D2(e=Date.now()){let t=[],n=new Map,r=[],i=[],a=(e,t)=>{let r=y2(e);n.set(r,(n.get(r)??0)+t)};for(let n=0;n<16;n++){let o=(15-n)*7+1,s=C2(e,o);{let e=[{slug:`back-squat`,top:100+4*n,reps:5,tis:12.5},{slug:`bench-press`,top:80+2.5*n,reps:5,tis:10},{slug:`deadlift`,top:140+4*n,reps:3,tis:8.4}],r=[],i=0,o=0;for(let t of e){let e=t.reps*t.top;i+=e,o+=t.tis;let n={effortSlug:t.slug,discipline:`strength`,intensityTier:`high`};w2(r,`Total reps`,t.reps,`reps`,`totalReps`,n),w2(r,`Training intensity score`,t.tis,`pts`,`tis`,n),w2(r,`Total volume`,e,`kg`,`totalVolume`,n),w2(r,`Estimated 1RM`,S2(t.top*(1+t.reps/30)),`kg`,`calc.e1rm`,n),w2(r,`%1RM intensity`,S2(100/(1+t.reps/30)),`%`,`calc.pct1rm`,n)}let c=S2(i/100+13+o/10);w2(r,`Session load`,c,`AU`,`sessionLoad`,{discipline:`strength`,intensityTier:`high`}),t.push(...E2(r,{noteId:`example-strength-w${n}`,resultId:`example-strength-w${n}-r`,blockContentId:`example-content-strength`,timestamp:s})),a(s,c)}let c=C2(e,o+2);{let e=[],r;if(n%3==0){r=`high`;for(let[t,n,i,a]of[[`thruster`,45,2.2,42.5],[`pull-up`,45,1.6,0]]){let o={effortSlug:t,discipline:a?`strength`:`gymnastics`,intensityTier:r};w2(e,`Total reps`,n,`reps`,`totalReps`,o),w2(e,`Training intensity score`,S2(n*i),`pts`,`tis`,o),a&&w2(e,`Total volume`,n*a,`kg`,`totalVolume`,o)}}else if(n%3==1){r=`moderate`;let t=16+n%5;for(let[n,i,a]of[[`pull-up`,5,1.5],[`push-up`,10,1.2],[`air-squat`,15,1.1]]){let o=t*i,s={effortSlug:n,discipline:`gymnastics`,intensityTier:r};w2(e,`Total reps`,o,`reps`,`totalReps`,s),w2(e,`Training intensity score`,S2(o*a),`pts`,`tis`,s)}}else{r=`moderate`;for(let[t,n,i]of[[`double-under`,150,.5],[`sit-up`,150,1.3]]){let a={effortSlug:t,discipline:`gymnastics`,intensityTier:r};w2(e,`Total reps`,n,`reps`,`totalReps`,a),w2(e,`Training intensity score`,S2(n*i),`pts`,`tis`,a)}}let i=S2(30.6);w2(e,`Session load`,i,`AU`,`sessionLoad`,{intensityTier:r}),t.push(...E2(e,{noteId:`example-conditioning-w${n}`,resultId:`example-conditioning-w${n}-r`,blockContentId:`example-content-conditioning`,timestamp:c})),a(c,i)}let l=C2(e,o+4,8);if(n%4==1)r.push(y2(l));else{let e=6e3+100*n,r=S2(e/2.8),o=[],s={effortSlug:`running`,discipline:`running`,intensityTier:`low`};w2(o,`Total distance`,e,`m`,`totalDistance`,s),w2(o,`Elapsed time`,r,`s`,`elapsed`,s),w2(o,`Training intensity score`,r,`pts`,`tis`,s);let c=S2(r/10);w2(o,`Session load`,c,`AU`,`sessionLoad`,{intensityTier:`low`}),t.push(...E2(o,{noteId:`example-run-w${n}`,resultId:`example-run-w${n}-r`,blockContentId:`example-content-run`,timestamp:l})),a(l,c),i.push({day:y2(l),pace:e/r})}let u=C2(e,o+6,10);{let e=4e3+50*n,r=S2(e/2),i=[],o={effortSlug:`rowing`,discipline:`rowing`,intensityTier:`moderate`};w2(i,`Total distance`,e,`m`,`totalDistance`,o),w2(i,`Elapsed time`,r,`s`,`elapsed`,o),w2(i,`Training intensity score`,r,`pts`,`tis`,o);let s=S2(r/10);w2(i,`Session load`,s,`AU`,`sessionLoad`,{intensityTier:`moderate`}),t.push(...E2(i,{noteId:`example-row-w${n}`,resultId:`example-row-w${n}-r`,blockContentId:`example-content-row`,timestamp:u})),a(u,s)}}let o=Math.max(...n.keys()),s=(e,t=10)=>{let n=new Date(e*x2);return n.setHours(t,0,0,0),n.getTime()},c=(e,n,r)=>{let i=[];for(let[e,t,n]of r)w2(i,e,t,n,e);t.push(...E2(i,{noteId:`example-calc`,resultId:e,blockContentId:`example-content-calc`,timestamp:n}))};for(let e of b2(n,o))e.acwr!==void 0&&c(`example-calc-d${e.day}`,s(e.day),[[`calc.acwr`,S2(e.acwr),`ratio`]]);let l=0,u=0,d=Math.min(...n.keys());for(let e=d;e<=o;e++){let t=n.get(e)??0;l+=(t-l)/42,u+=(t-u)/7,n.has(e)&&c(`example-calc-pmc-d${e}`,s(e),[[`calc.ctl`,S2(l),`AU`],[`calc.atl`,S2(u),`AU`],[`calc.tsb`,S2(l-u),`AU`]])}let f=new Set([...n.keys()]);for(let e of r)f.add(e);for(let e of f){let t=+!!n.has(e);c(`example-calc-adh-d${e}`,s(e,7),[[`calc.adherence`,t,`ratio`]])}for(let e of i)c(`example-calc-ef-d${e.day}`,s(e.day,8),[[`calc.ef`,S2(e.pace/141*1e5),`pts`]]);return t}function O2(e=Date.now()){return new j_(Ov(D2(e)))}var k2=null;function A2(){return k2??=O2()}var j2=[4,8,16],M2={parse(e){let t=Number.parseInt(e,10);return j2.includes(t)?t:null},serialize(e){return String(e)},withDefault(e){return{...this,defaultValue:e}}};function N2(){return Kt(`weeks`,M2.withDefault(16))}function P2(e){let t=e.trim().split(/\s+/).filter(e=>e!==``);if(t.length===0)return;let n={};for(let e of t){let t=e.indexOf(`=`);if(t===-1)continue;let r=e.slice(0,t),i=e.slice(t+1);i.startsWith(`"`)&&i.endsWith(`"`)&&i.length>=2&&(i=i.slice(1,-1)),n[r]=i}return Object.keys(n).length===0?void 0:n}var F2=[{label:`Auto`,spanCols:void 0,spanFull:!1},{label:`1 col`,spanCols:1,spanFull:!1},{label:`2 cols`,spanCols:2,spanFull:!1},{label:`4 cols`,spanCols:4,spanFull:!1},{label:`Full row`,spanCols:void 0,spanFull:!0}],I2=300;function L2({open:e,...t}){return e?(0,W.jsx)(R2,{...t}):null}function R2({onClose:e,mode:t,initialWql:n,initial:r,subsetQuery:i,destination:a,executor:o,rangeStart:s,rangeEnd:c,preferredUnit:l,tokenValues:u,onApply:d,footerExtra:f,applyLabel:p=t===`edit`?`Apply changes`:`Add widget`}){let m=t===`inspect`,[h,g]=(0,U.useState)(n),[_,v]=(0,U.useState)(r?.title??``),[y,b]=(0,U.useState)(r?.question??``),[x,S]=(0,U.useState)(r?.type||`table`),[C,w]=(0,U.useState)({spanCols:r?.spanCols,spanFull:r?.spanFull}),[T,E]=(0,U.useState)(Object.entries(r?.attributes??{}).map(([e,t])=>`${e}=${t}`).join(` `)),[D,O]=(0,U.useState)(!1),[k,A]=(0,U.useState)(()=>!X(n).error),[j,M]=(0,U.useState)(null),N=(0,U.useMemo)(()=>X(h.trim()),[h]),P=x===``?`table`:x,F=!N.error&&h.trim()!==``&&(Bm(N)?P===`table`||P===`list`:P!==`list`),[I,L]=(0,U.useState)({status:`idle`}),ee=(0,U.useRef)(0);(0,U.useEffect)(()=>{if(!F||!o){L(e=>e.status===`ok`?e:{status:`idle`});return}let e=tv(h.trim(),u??{});if(e.missing.length>0){L({status:`blocked`,message:K_(e.missing)});return}let t=++ee.current;L({status:`loading`});let n=setTimeout(()=>{o.runQuery(e.query,{rangeStart:s,rangeEnd:c,preferredUnit:l}).then(e=>{ee.current===t&&L({status:`ok`,result:e})}).catch(e=>{ee.current===t&&L({status:`error`,message:e instanceof Error?e.message:String(e)})})},I2);return()=>clearTimeout(n)},[h,F,o,s,c,l,u]);let te=!F&&I.status===`ok`,ne=F&&k,R=async()=>{if(!(!ne||!d||D)&&!(X(h.trim()).error||h.trim()===``)){O(!0),M(null);try{await d({title:_.trim()||void 0,question:y.trim()||void 0,type:x===`table`?``:x,spanCols:C.spanFull?void 0:C.spanCols,spanFull:C.spanFull||void 0,wql:h.trim(),attributes:P2(T)}),e()}catch(e){M(e instanceof Error?e.message:String(e))}finally{O(!1)}}};return(0,W.jsx)(OC,{open:!0,onClose:e,presentation:`sheet`,title:t===`inspect`?`Inspect widget`:t===`edit`?`Edit widget`:`Add widget`,description:m?`Read-only — clone the dashboard to edit this widget.`:`Dataset, calculation, visualization, preview — then apply.`,footer:m&&!f?void 0:(0,W.jsxs)(W.Fragment,{children:[f,(0,W.jsx)(`div`,{className:`flex-1`}),!m&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,onClick:e,className:`min-h-12 px-3 py-1.5 text-xs font-medium text-muted-foreground hover:text-foreground rounded-lg border border-border hover:bg-muted transition-colors`,children:`Cancel`}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`widget-composer-apply`,disabled:!ne||D,title:N.error?N.error:void 0,onClick:()=>void R(),className:`min-h-12 px-3 py-1.5 text-xs font-medium text-primary-foreground bg-primary hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed rounded-lg shadow transition-colors`,children:D?`Applying…`:p})]})]}),children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[i!==void 0&&(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Dataset — the subset`}),i?(0,W.jsx)(`code`,{className:`block rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-xs text-foreground break-all`,"data-testid":`widget-composer-subset`,children:i}):(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`widget-composer-subset`,children:`No subset — the calculation runs over the whole store.`})]}),a,(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Calculation`}),m?(0,W.jsx)(`code`,{className:`block rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-xs text-foreground break-all`,"data-testid":`widget-composer-query`,children:h}):(0,W.jsx)(Kw,{query:h,onQueryChange:g,onValidationChange:e=>A(e.valid),showDiagnostics:!0,...o?{execute:e=>o.runQuery(e.raw,{rangeStart:s,rangeEnd:c,preferredUnit:l})}:{}}),!m&&h.trim()!==``&&(0,W.jsx)(`code`,{className:`mt-1.5 block rounded-md border border-primary/30 bg-primary/[0.04] px-3 py-2 font-mono text-xs text-foreground break-all`,"data-testid":`widget-composer-wql`,children:h.trim()}),!m&&(0,W.jsxs)(`label`,{className:`mt-3 flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Visualization`}),(0,W.jsx)(`select`,{value:x,onChange:e=>S(e.target.value),"data-testid":`widget-composer-type`,className:`min-h-12 rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary sm:min-h-0`,children:H_.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})]})]}),!m&&(0,W.jsxs)(`section`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Title`}),(0,W.jsx)(`input`,{type:`text`,value:_,onChange:e=>v(e.target.value),placeholder:`Weekly volume`,"data-testid":`widget-composer-title`,className:`rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,W.jsxs)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:[`Coaching question `,(0,W.jsx)(`span`,{className:`normal-case font-normal`,children:`(optional)`})]}),(0,W.jsx)(`input`,{type:`text`,value:y,onChange:e=>b(e.target.value),placeholder:`How much work per week?`,"data-testid":`widget-composer-question`,className:`rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:`Size`}),(0,W.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-lg border border-border bg-card p-1 self-start`,children:F2.map(e=>{let t=e.spanFull?C.spanFull===!0:e.spanCols==null?!C.spanFull&&C.spanCols==null:!C.spanFull&&C.spanCols===e.spanCols;return(0,W.jsx)(`button`,{type:`button`,"aria-pressed":t,onClick:()=>w(e.spanFull?{spanFull:!0}:{spanCols:e.spanCols}),className:`text-xs px-2.5 py-1 rounded-md transition-colors ${t?`bg-primary text-primary-foreground font-medium`:`text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:e.label},e.label)})})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 sm:col-span-2`,children:[(0,W.jsxs)(`span`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground`,children:[`Parameters `,(0,W.jsx)(`span`,{className:`normal-case font-normal`,children:`(goal targets, space-separated)`})]}),(0,W.jsx)(`input`,{type:`text`,value:T,onChange:e=>E(e.target.value),placeholder:`300 200`,"data-testid":`widget-composer-params`,className:`rounded-lg border border-border bg-card px-3 py-1.5 text-sm font-mono text-foreground focus:outline-none focus:border-primary`})]})]}),m&&(0,W.jsxs)(`section`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 text-xs text-muted-foreground`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Title`}),(0,W.jsx)(`div`,{className:`text-foreground`,children:r?.title||`—`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Question`}),(0,W.jsx)(`div`,{className:`text-foreground`,children:r?.question||`—`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Type`}),(0,W.jsx)(`div`,{className:`font-mono text-foreground`,children:x||`table`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-wider text-[10px]`,children:`Size`}),(0,W.jsx)(`div`,{className:`font-mono text-foreground`,children:r?.spanFull?`full row`:r?.spanCols?`${r.spanCols} cols`:`default`})]})]}),(0,W.jsxs)(`section`,{children:[(0,W.jsxs)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5 flex items-center gap-2`,children:[`Preview`,te&&(0,W.jsx)(`span`,{"data-testid":`widget-preview-stale`,className:`font-medium normal-case tracking-normal text-amber-600`,children:`stale — showing the last valid query`})]}),(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-background/50 p-3 h-56 overflow-hidden`,children:[I.status===`idle`&&(F?(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-muted-foreground`,children:`Preview runs as you compose…`}):(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-destructive font-mono px-4 text-center`,children:N.error?N.error:Bm(N)?`find: queries return things — use a table or list widget instead`:`Compose a calculation to preview.`})),I.status===`loading`&&(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-muted-foreground`,children:`Running preview…`}),I.status===`blocked`&&(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-destructive font-mono px-4 text-center`,children:I.message}),I.status===`error`&&(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-xs text-destructive font-mono px-4 text-center`,children:I.message}),I.status===`ok`&&(0,W.jsx)(DS,{type:x,result:I.result,label:_.trim()||void 0,unit:l,attributes:P2(T)})]})]}),j&&(0,W.jsx)(`p`,{role:`alert`,"data-testid":`widget-composer-error`,className:`rounded-md border border-destructive/40 bg-destructive/10 px-3 py-2 text-xs text-destructive font-mono`,children:j})]})})}function z2({boardSlug:e}){let t=A2(),n=YO(),r=(0,U.useMemo)(()=>n?uP(n):[],[n]),i=(0,U.useMemo)(()=>r.find(t=>t.slug===e)??r[0],[r,e]),a=(0,U.useMemo)(()=>{if(!i?.rawContent)return null;try{let{meta:e,sections:t}=uv(i.rawContent);return iv(t,e)}catch{return null}},[i]),[o,s]=N2(),[c,l]=(0,U.useMemo)(()=>{let e=Date.now();return[e-o*7*864e5,e]},[o]),[u,d]=(0,U.useState)(null);return(0,W.jsxs)(`div`,{className:`flex h-full w-full flex-col`,"data-testid":`tour-session-dashboard`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2 px-5 pt-4`,children:[(0,W.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`truncate text-[11px] font-semibold uppercase tracking-wide text-primary`,children:i?.title??e}),(0,W.jsx)(`span`,{"data-testid":`tour-session-dashboard-source`,className:`flex-none rounded-full border border-border bg-muted px-2 py-0.5 text-[10px] font-medium text-muted-foreground`,children:`Example data`})]}),(0,W.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,W.jsx)(US,{weeks:o,onWeeksChange:s})})]}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-auto px-5 pb-5 pt-3 [&_[data-testid=dashboard-view]>div.grid]:grid-cols-1 [&_[data-testid=dashboard-view]>div.grid]:sm:grid-cols-2 [&_[data-testid=dashboard-view]>div.grid]:lg:grid-cols-2 [&_[data-testid=dashboard-view]>div.grid>*]:col-span-1`,children:a?(0,W.jsx)(HS,{document:a,executor:t,onInspectWidget:d,rangeStart:c,rangeEnd:l}):(0,W.jsx)(`p`,{className:`pt-8 text-center text-sm text-muted-foreground`,children:`Loading board…`})}),(0,W.jsx)(L2,{open:u!==null,onClose:()=>d(null),mode:`inspect`,initialWql:u?.body??`sum:totalVolume{}`,initial:u?{title:u.title,question:u.question,type:u.type,spanCols:u.spanCols,spanFull:u.spanFull,attributes:u.attributes}:void 0,executor:t,rangeStart:c,rangeEnd:l,tokenValues:a?Q_(a.tokens):void 0,onApply:void 0})]})}var B2=[`analytics`,`boards`],V2={analytics:{index:`01`,heading:`h2`,title:`Session Insights`,blurb:`Run the workout and this window turns your run into data — rest vs. work, how fast you answered the clock, round by round.`},boards:{index:`02`,heading:`h2`,title:`One Run Becomes Many`,blurb:`Dashboards let you visualise your progress — every recorded run rolls up into analytics boards. Aggregate results across flexible search criteria, from note frontmatter to session metrics: one run becomes many insights.`}};function H2({scope:e}){let t=V2[e],n=t.heading;return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(n,{className:`flex items-baseline gap-4 text-[clamp(26px,3.2vw,44px)] font-extrabold leading-[1.1] tracking-[-0.03em]`,children:[t.index&&(0,W.jsx)(`span`,{className:`font-mono text-xs font-normal tracking-normal text-muted-foreground`,children:t.index}),(0,W.jsx)(`span`,{children:t.title})]}),(0,W.jsx)(`p`,{className:`mt-3 max-w-xl text-[clamp(14px,1.2vw,18px)] leading-[1.65] text-muted-foreground`,children:t.blurb})]})}var U2=[{id:`road-to-560-total`,label:`Road to 560 Total`,title:`Road to 560 Total`},{id:`polarized-base-marathon`,label:`Polarized Base`,title:`Polarized Base Marathon`}];function W2({onClick:e}){return(0,W.jsxs)(`button`,{type:`button`,onClick:e,title:`Back to the editor`,"data-testid":`tour-pane-back-to-editor`,className:`flex shrink-0 items-center gap-1 rounded-md border border-border px-2 py-1 text-[10px] font-semibold uppercase tracking-wider text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:[(0,W.jsx)(Fe,{className:`size-3`}),`Editor`]})}function G2({session:e,onRun:t,onBackToEditor:n}){let[r,i]=(0,U.useState)(`analytics`),[a,o]=(0,U.useState)(0),s=U2[a],c=(0,U.useRef)(new Map);(0,U.useEffect)(()=>{if(typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(e=>{for(let t of e){if(!t.isIntersecting)continue;let e=t.target.getAttribute(`data-scope`);(e===`analytics`||e===`boards`)&&i(e)}},{rootMargin:`-45% 0px -45% 0px`});return c.current.forEach(t=>e.observe(t)),()=>e.disconnect()},[]);let l=e=>t=>{t?c.current.set(e,t):c.current.delete(e)},u=r=>r===`analytics`?(0,W.jsx)(zq,{title:`Session Insights`,className:`h-[460px]`,headerActions:(0,W.jsx)(W2,{onClick:n}),children:(0,W.jsx)(_2,{result:e,onRun:t})}):(0,W.jsxs)(`div`,{className:`flex h-full flex-col gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,W.jsx)(`div`,{role:`tablist`,"aria-label":`Dashboard slides`,className:`flex flex-wrap gap-1 rounded-lg border border-border bg-muted/30 p-1`,children:U2.map((e,t)=>(0,W.jsx)(`button`,{type:`button`,role:`tab`,"aria-selected":a===t,"aria-pressed":a===t,"data-testid":`dashboard-slide-tab-${e.id}`,onClick:()=>o(t),className:G(`min-h-11 rounded-md px-3 py-1.5 text-xs font-semibold transition-colors`,a===t?`bg-background text-foreground shadow`:`text-muted-foreground hover:text-foreground`),children:e.label},e.id))}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+U2.length-1)%U2.length),"aria-label":`Previous dashboard`,"data-testid":`dashboard-slide-prev`,className:`flex size-11 items-center justify-center rounded-md border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:(0,W.jsx)(Un,{className:`size-4`})}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>o(e=>(e+1)%U2.length),"aria-label":`Next dashboard`,"data-testid":`dashboard-slide-next`,className:`flex size-11 items-center justify-center rounded-md border border-border text-muted-foreground transition-colors hover:bg-accent hover:text-foreground`,children:(0,W.jsx)(wn,{className:`size-4`})})]})]}),(0,W.jsx)(zq,{title:s.title,className:`min-h-0 flex-1`,headerActions:(0,W.jsx)(W2,{onClick:n}),children:(0,W.jsx)(`div`,{className:`flex h-full w-full flex-col`,role:`tabpanel`,children:(0,W.jsx)(z2,{boardSlug:s.id})},s.id)}),(0,W.jsxs)(`p`,{className:`text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground/60`,children:[a+1,` / `,U2.length]})]}),d=(0,W.jsx)(`div`,{"data-testid":`tour-sticky-pane`,className:`sticky top-[72px] hidden h-[calc(100dvh-72px)] flex-col items-center justify-center self-start lg:top-[104px] lg:flex lg:h-[calc(100dvh-104px)]`,children:(0,W.jsx)(`div`,{className:`relative w-full max-w-[700px]`,children:(0,W.jsx)(`div`,{className:`relative h-[460px]`,children:B2.map(e=>(0,W.jsx)(`div`,{"aria-hidden":r!==e,"data-scope-active":r===e,className:G(`absolute inset-0 transition-opacity duration-500`,r===e?`opacity-100`:`invisible opacity-0`),children:u(e)},e))})})}),f=(e,t)=>(0,W.jsx)(`div`,{ref:l(e),"data-scope":e,className:`flex min-h-[85vh] flex-col justify-center scroll-mt-[104px]`,...t,children:(0,W.jsx)(H2,{scope:e})}),p=e=>(0,W.jsxs)(`div`,{"data-testid":`tour-step-mobile-${e}`,"data-scope":e,className:`flex flex-col gap-4 lg:hidden`,children:[(0,W.jsx)(H2,{scope:e}),(0,W.jsx)(`div`,{className:`h-[460px]`,children:u(e)})]});return(0,W.jsx)(`section`,{id:`tour-section-insights`,"data-testid":`tour-section-insights`,className:`border-b border-border/60`,children:(0,W.jsxs)(`div`,{className:`mx-auto grid max-w-[1500px] gap-10 px-5 py-14 lg:grid-cols-2 lg:gap-16 lg:px-12 lg:py-0 xl:px-16 2xl:max-w-[1720px]`,children:[(0,W.jsxs)(`div`,{className:`hidden flex-col lg:flex`,children:[(0,W.jsx)(`div`,{id:`tour-scroll-target-insights`,className:`scroll-mt-[72px] lg:scroll-mt-[104px]`,children:f(`analytics`)}),f(`boards`,{id:`tour-section-boards`,"data-testid":`tour-section-boards`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-12 lg:hidden`,children:[p(`analytics`),p(`boards`)]}),d]})})}function K2(e){switch(e.phase){case`checking`:return`Checking the seed…`;case`fetching`:return`Downloading ${e.chunkId??`notebook`}…`;case`applying`:return`Importing ${e.chunkId??`notebook`}…`;case`committed`:return`Committed ${e.chunkId??`notebook`}`;case`finalizing`:return`Finalizing checkpoints…`;case`finished`:return`Done`;default:return e.phase}}function q2(e){if(!e||e.phase===`checking`||e.phase===`finished`)return null;let t=[];return typeof e.completedRecords==`number`&&typeof e.totalRecords==`number`&&t.push(`${e.completedRecords} / ${e.totalRecords} records`),e.totalChunks>0&&t.push(`${e.completedChunks} / ${e.totalChunks} notebooks`),t.length>0?t.join(` · `):null}function J2(e){let t=e.match(/^notebook\.(.+)$/);return t?{slug:t[1]}:null}function Y2(e){let t=e.items.map(e=>e.date).filter(e=>!!e).sort();return{packageId:`local-notebooks-${e.id}`,slug:e.id,label:e.name,description:e.description,image:e.image,categories:e.categories,sourceLabel:`Local`,href:`/notebook/${encodeURIComponent(e.id)}`,itemCount:e.items.length,...t.length>0?{latestDate:t[t.length-1],firstDate:t[0]}:{},...e.readme===void 0?{}:{readme:e.readme},installed:!0}}function X2(e,t,n){let r=[],i=new Map;if(t)for(let e of DO(`notebooks`,t))i.set(e.id,e),r.push(Y2(e));let a=e.map(e=>{let t=J2(e.chunkId);if(!t)return null;let r=i.get(t.slug),a=xA(e.feedId),o=(r?.items??[]).map(e=>e.date).filter(e=>!!e).sort();return{packageId:e.id,feedId:e.feedId,chunkId:e.chunkId,slug:t.slug,label:e.label,description:e.description||r?.description,image:r?.image,categories:r?.categories??[],sourceLabel:a?.label??e.feedId,...a?.repositoryUrl?{repositoryUrl:a.repositoryUrl}:{},href:`/notebook/${encodeURIComponent(t.slug)}`,itemCount:r?.items.length??0,...o.length>0?{latestDate:o[o.length-1],firstDate:o[0]}:{},...r?.readme===void 0?{}:{readme:r.readme},installed:!!r,subscribed:!n||n(e.feedId,e.chunkId)}}).filter(e=>e!==null),o=new Set(a.map(e=>e.slug));return[...a,...r.filter(e=>!o.has(e.slug)),...Z2(t)]}function Z2(e){return Aa.filter(e=>e.feedEntryId===`core`&&e.slug!==`guides`&&typeof e.seedChunkId==`string`).map(t=>{let n=`markdown/${t.slug}/`,r=e?Object.keys(e).filter(e=>e.startsWith(n)&&e.endsWith(`.md`)&&!e.endsWith(`/README.md`)):[];return{packageId:`core-${t.slug}`,feedId:`core`,chunkId:t.seedChunkId,slug:t.slug,label:t.name,description:t.description,categories:[],sourceLabel:`Core`,href:t.href,itemCount:r.length,installed:e?r.length>0:!1,subscribed:!0}})}function Q2(e,t){let n={},r=[],i=new Set(t.map(e=>e.id));for(let t of e)t.feedId&&i.has(t.feedId)?(n[t.feedId]??=[]).push(t):r.push(t);let a=[];for(let e of t){let t=n[e.id];t?.length&&a.push({feed:e,label:e.label,...e.description?{description:e.description}:{},url:e.url,...e.repositoryUrl?{repositoryUrl:e.repositoryUrl}:{},notebooks:t})}return r.length>0&&a.push({label:`Local`,notebooks:r}),a}function $2(e,t,n,r){return Q2(X2(e,t,r),n).map(e=>{let t=e.notebooks.map(e=>e.latestDate).filter(e=>!!e).sort();return{feedId:e.feed?.id,slug:e.feed?.id??`local`,label:e.label,...e.description?{description:e.description}:{},...e.url?{url:e.url}:{},...e.repositoryUrl?{repositoryUrl:e.repositoryUrl}:{},notebooks:e.notebooks,itemCount:e.notebooks.reduce((e,t)=>e+t.itemCount,0),installed:e.notebooks.every(e=>e.installed),subscribed:e.notebooks.some(e=>e.subscribed),...t.length>0?{latestDate:t[t.length-1]}:{},href:`/notebooks`}})}function e4(e,t){let n=t.text?.trim().toLowerCase();return e.filter(e=>t.feedId&&e.feedId!==t.feedId||t.subscribedOnly&&!e.notebooks.some(e=>e.subscribed)?!1:!n||e.label.toLowerCase().includes(n)||(e.description?.toLowerCase().includes(n)??!1)||e.notebooks.some(e=>e.label.toLowerCase().includes(n)||(e.description?.toLowerCase().includes(n)??!1)))}function t4(e,t){let n=[...e];switch(t){case`name`:return n.sort((e,t)=>e.label.localeCompare(t.label));case`size`:return n.sort((e,t)=>t.itemCount-e.itemCount||e.label.localeCompare(t.label));default:return n.sort((e,t)=>e.latestDate&&t.latestDate?t.latestDate.localeCompare(e.latestDate):e.latestDate?-1:t.latestDate?1:e.label.localeCompare(t.label))}}var n4=[`bg-rose-500/12 text-rose-600 dark:text-rose-400`,`bg-amber-500/12 text-amber-600 dark:text-amber-400`,`bg-emerald-500/12 text-emerald-600 dark:text-emerald-400`,`bg-sky-500/12 text-sky-600 dark:text-sky-400`,`bg-violet-500/12 text-violet-600 dark:text-violet-400`,`bg-cyan-500/12 text-cyan-600 dark:text-cyan-400`];function r4(e){let t=0;for(let n=0;n<e.length;n++)t=t*31+e.charCodeAt(n)|0;return n4[Math.abs(t)%n4.length]}function i4(e){return(e.match(/[a-z0-9]/i)?.[0]??`•`).toUpperCase()}function a4(e){if(!e)return null;let t=new Date(`${e}T00:00:00`);return isNaN(t.getTime())?null:t.toLocaleDateString(void 0,{month:`short`,day:`numeric`,year:`numeric`})}var o4=4;function s4({feed:e,testId:t=`feed-card`,className:n,onImport:r,importing:i,busy:a,status:o,onToggleNotebookSubscription:c}){let[l,u]=r4(e.slug).split(` `),d=a4(e.latestDate),f=e.notebooks.slice(0,o4),p=e.notebooks.length-f.length,m=e.installed&&e.feedId?e.href:void 0,g=e.notebooks.find(e=>e.image)?.image,_=(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground/70`,children:[(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[e.notebooks.length,` `,e.notebooks.length===1?`notebook`:`notebooks`]}),e.installed&&e.itemCount>0&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[e.itemCount,` `,e.itemCount===1?`item`:`items`]})]}),e.installed&&d&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{"aria-hidden":!0,children:`·`}),(0,W.jsxs)(`span`,{className:`tabular-nums`,children:[`updated `,d]})]}),!e.installed&&(0,W.jsx)(`span`,{"aria-hidden":!0,children:`·`}),!e.installed&&(0,W.jsx)(`span`,{children:`not imported`})]}),v=(0,W.jsx)(`div`,{className:G(`relative overflow-hidden bg-muted/40 aspect-[16/10]`,l),children:g?(0,W.jsx)(`img`,{src:g,alt:``,loading:`lazy`,className:`absolute inset-0 size-full object-cover`}):(0,W.jsxs)(`div`,{className:`absolute inset-0 flex items-center justify-center`,children:[(0,W.jsx)(`span`,{className:G(`text-7xl font-black tracking-tighter select-none`,u),"aria-hidden":!0,children:i4(e.label)}),(0,W.jsx)(s,{className:G(`absolute bottom-4 right-4 size-6 opacity-50`,u),"aria-hidden":!0})]})});return(0,W.jsxs)(`article`,{"data-testid":t,"data-installed":e.installed,className:G(`group relative flex flex-col overflow-hidden rounded-2xl border border-border bg-card`,`transition-colors hover:border-foreground/25 focus-within:border-foreground/25`,n),children:[m?(0,W.jsx)(_n,{to:m,"data-testid":`${t}-open`,className:`block outline-none`,"aria-label":`Open the library for ${e.label}`,children:v}):v,(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col gap-2 p-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,W.jsx)(`h3`,{className:`min-w-0 text-sm font-bold leading-snug text-foreground`,children:m?(0,W.jsx)(_n,{to:m,className:`transition-colors hover:text-primary`,children:e.label}):e.label}),m?(0,W.jsx)(_n,{to:m,"data-testid":`${t}-cta`,"aria-label":`Open the library for ${e.label}`,className:`flex min-h-11 min-w-11 size-11 shrink-0 items-center justify-center rounded-full border border-border text-muted-foreground transition-colors hover:border-primary/50 hover:text-primary`,children:(0,W.jsx)(h,{className:`size-3.5`,"aria-hidden":!0})}):r&&e.feedId?(0,W.jsxs)(`button`,{type:`button`,"data-testid":`${t}-import`,disabled:i||a,onClick:()=>r(e.feedId),className:G(`flex min-h-11 shrink-0 items-center gap-1.5 rounded-full border px-4`,`text-[10px] font-black uppercase tracking-widest`,`border-primary/30 bg-primary/10 text-primary`,`transition-colors hover:bg-primary/20`,`disabled:cursor-wait disabled:opacity-60`),children:[i?(0,W.jsx)(or,{className:`size-3 animate-spin`,"aria-hidden":!0}):(0,W.jsx)(Ee,{className:`size-3`,"aria-hidden":!0}),i?`Importing`:`Import feed`]}):null]}),e.description&&(0,W.jsx)(`p`,{className:`line-clamp-2 text-xs leading-relaxed text-muted-foreground`,children:e.description}),e.notebooks.length>0&&(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,"data-testid":`${t}-notebooks`,children:[f.map(n=>(0,W.jsxs)(`span`,{"data-testid":`${t}-notebook-${n.packageId}`,className:G(`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-[9px] font-black uppercase tracking-widest transition-colors`,n.subscribed?`border-emerald-500/40 bg-emerald-500/10 text-emerald-600`:`border-border text-muted-foreground/70`),children:[n.installed?(0,W.jsx)(_n,{to:n.href,className:`hover:text-primary`,children:n.label}):(0,W.jsx)(`span`,{children:n.label}),c&&e.feedId&&n.chunkId&&(0,W.jsx)(`button`,{type:`button`,onClick:t=>{t.preventDefault(),t.stopPropagation(),c(e.feedId,n.chunkId,!n.subscribed)},title:n.subscribed?`Unsubscribe ${n.label}`:`Subscribe ${n.label}`,"aria-label":n.subscribed?`Unsubscribe ${n.label}`:`Subscribe ${n.label}`,"data-testid":`${t}-notebook-toggle-${n.packageId}`,className:`relative -my-3 -mr-2.5 ml-0.5 inline-flex min-h-11 min-w-11 items-center justify-center font-bold hover:text-foreground`,children:n.subscribed?`✓`:`+`})]},n.packageId)),p>0&&(0,W.jsxs)(`span`,{className:`rounded-full border border-dashed border-border px-2 py-0.5 text-[9px] font-black uppercase tracking-widest text-muted-foreground/60`,children:[`+`,p,` more`]})]}),(0,W.jsxs)(`div`,{className:`mt-auto pt-1`,children:[_,o&&(0,W.jsx)(`p`,{role:o.tone===`error`?`alert`:`status`,"data-testid":`${t}-status`,className:G(`mt-1.5 flex items-start gap-1.5 text-xs`,o.tone===`error`?`text-destructive`:`text-muted-foreground`),children:(0,W.jsx)(`span`,{children:o.text})})]})]})]})}function c4({direction:e,children:t,testId:n,className:r}){let i=(0,U.useRef)(null),a=(0,U.useRef)(null),[o,s]=(0,U.useState)(1),c=Iq(`(prefers-reduced-motion: reduce)`);(0,U.useEffect)(()=>{let e=i.current,t=a.current;if(!e||!t)return;let n=()=>{let n=o*2,r=t.scrollWidth/n;if(r<=0)return;let i=Math.max(1,Math.ceil(e.clientWidth/r));i!==o&&s(i)};n();let r=new ResizeObserver(n);return r.observe(e),r.observe(t),()=>r.disconnect()},[o,t]);let l=c?1:o*2;return(0,W.jsx)(`div`,{ref:i,"data-testid":n,className:G(`wod-marquee overflow-hidden`,r),children:(0,W.jsx)(`div`,{ref:a,className:G(`flex w-max`,!c&&`wod-marquee-track`,!c&&e===`left`&&`wod-marquee-track--left`,!c&&e===`right`&&`wod-marquee-track--right`,!c&&e===`alternate`&&`wod-marquee-track--left wod-marquee-track--alternate`),children:Array.from({length:l},(e,n)=>(0,W.jsx)(`div`,{"data-marquee-copy":n,"aria-hidden":n>0,className:`flex shrink-0 items-stretch gap-4 pr-4`,children:t},n))})})}var l4=[{value:`updated`,label:`Updated`},{value:`name`,label:`Name`},{value:`size`,label:`Size`}],u4=`group flex flex-col justify-between rounded-2xl border border-border bg-card p-5 text-left transition-colors hover:border-primary/40 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`;function d4(e){let t=e.icon;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`span`,{className:`flex size-10 items-center justify-center rounded-lg bg-foreground text-background`,children:(0,W.jsx)(t,{className:`size-5`,"aria-hidden":!0})}),(0,W.jsx)(`h3`,{className:`mt-4 text-base font-semibold text-foreground`,children:e.title}),(0,W.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-muted-foreground`,children:e.description})]}),e.note?(0,W.jsx)(`span`,{className:`mt-4 text-xs font-medium text-muted-foreground`,children:e.note}):(0,W.jsxs)(`span`,{className:`mt-4 inline-flex items-center gap-1.5 text-sm font-medium text-foreground`,children:[(0,W.jsx)(`span`,{children:e.action}),(0,W.jsx)(h,{className:`size-4 transition-transform group-hover:translate-x-0.5`,"aria-hidden":!0})]})]})}function f4(){let e=Vn(),[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(`updated`),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)({}),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(),[p,m]=(0,U.useState)(0);(0,U.useEffect)(()=>yj(()=>m(e=>e+1)),[]);let h=a!==null,g=YO(),_=Iq(`(min-width: 1024px)`),y=(0,U.useMemo)(()=>$2(DA(),g,EA(),(e,t)=>gj(e,t)),[g,p]),b=(0,U.useMemo)(()=>t4(e4(y,{text:t,feedId:d,subscribedOnly:l}),r),[y,t,r,d,l]),x=Math.ceil(b.length/2),S=b.slice(0,x),C=b.slice(x),w=(0,U.useCallback)(()=>{dq.record(fq.libraryOpened)},[]),[T,E]=(0,U.useState)(!0);(0,U.useEffect)(()=>{let e=!1,t=()=>{_M().then(t=>{e||E(t.libraryImported)}).catch(()=>{})};t();let n=yj(t);return()=>{e=!0,n()}},[h]);let D=(0,U.useCallback)(async e=>{if(a)return;o(e);let t=t=>c(n=>({...n,[e]:t}));t({text:`Checking the feed…`,tone:`muted`});try{let n=await hM(e,{onProgress:e=>t({text:K2(e),tone:`muted`})});t(n===`imported`||n===`current`?{text:hj(e,!0)?n===`imported`?`Imported — this feed is available offline.`:`Already up to date.`:`Subscribed for this session only — browser storage is unavailable.`,tone:`muted`}:{text:n===`server-stale`?`Published version is older than stored copy.`:n===`busy`?`Another tab is syncing. Try again shortly.`:`Sync failed. Check connection and try again.`,tone:`error`})}catch(e){t({text:e instanceof Error?e.message:String(e),tone:`error`})}finally{o(null)}},[a]),O=(0,U.useCallback)(async(e,t,n)=>{_j(e,t,n),n&&hM(e,{force:!1})},[]),k=(0,U.useCallback)(async()=>{let t=_P(),n=await CP.create({journalDate:t,title:t,rawContent:``});dq.record(fq.noteCreated),e(TN(n.id))},[e]),A=!!t.trim();return(0,W.jsxs)(`section`,{id:`tour-section-community-feeds`,"data-testid":`tour-jump-section`,className:`flex flex-col border-b border-border bg-muted/20 pb-8 xl:pb-12`,"aria-label":`Library and community feeds`,children:[(0,W.jsx)(T$,{index:`03`,before:`Library & `,accentText:`Community Feeds`,after:``,accent:``,blurb:`Subscribe to a feed — one Markdown repository compiled with npx wod build into a versioned manifest, served from its own GitHub Pages. One Subscribe imports every notebook the feed publishes; browse the feeds below, notebooks and all.`}),(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsxs)(`label`,{className:`relative w-full sm:w-64`,children:[(0,W.jsx)(Tt,{className:`pointer-events-none absolute left-3 top-1/2 size-3.5 -translate-y-1/2 text-muted-foreground/60`,"aria-hidden":!0}),(0,W.jsx)(`input`,{type:`search`,value:t,onChange:e=>n(e.target.value),placeholder:`Search feeds…`,"aria-label":`Search feeds`,"data-testid":`package-search-input`,className:`h-11 w-full rounded-full border border-border bg-background pl-9 pr-9 text-sm text-foreground placeholder:text-muted-foreground/50 outline-none transition-colors focus:border-primary/50`}),t&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(``),"aria-label":`Clear search`,className:`absolute right-0 top-1/2 -translate-y-1/2 size-11 inline-flex items-center justify-center text-muted-foreground hover:text-foreground`,children:(0,W.jsx)(we,{className:`size-3.5`})})]}),(0,W.jsxs)(`label`,{className:`flex min-h-11 items-center gap-2 cursor-pointer select-none text-muted-foreground hover:text-foreground px-2`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:l,onChange:e=>u(e.target.checked),"data-testid":`filter-subscribed-only`,className:`size-4 accent-primary rounded`}),(0,W.jsx)(`span`,{className:`text-[10px] font-black uppercase tracking-widest`,children:`Subscribed only`})]}),(0,W.jsxs)(`select`,{value:d??``,onChange:e=>f(e.target.value?e.target.value:void 0),"aria-label":`Filter by feed`,"data-testid":`filter-feed-source`,className:`min-h-11 h-11 rounded-full border border-border bg-background px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground outline-none transition-colors hover:border-foreground/25 focus:border-primary/50`,children:[(0,W.jsx)(`option`,{value:``,children:`All feeds`}),EA().map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]}),(0,W.jsx)(`div`,{className:`ml-auto flex items-center gap-1.5`,role:`group`,"aria-label":`Sort feeds`,children:l4.map(e=>{let t=r===e.value;return(0,W.jsx)(`button`,{type:`button`,"aria-pressed":t,"data-testid":`package-sort-${e.value}`,onClick:()=>i(e.value),className:G(`inline-flex min-h-11 items-center justify-center rounded-full px-3 text-[10px] font-black uppercase tracking-widest transition-colors`,t?`bg-foreground text-background`:`text-muted-foreground hover:text-foreground`),children:e.label},e.value)})})]}),(0,W.jsx)(`div`,{"data-testid":`jump-grid`,className:`mt-6`,children:(0,W.jsxs)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2`,children:[T?(0,W.jsx)(_n,{to:`/notebooks`,onClick:w,"data-testid":`jump-library`,className:u4,children:(0,W.jsx)(d4,{icon:v,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`})}):(0,W.jsx)(`div`,{"data-testid":`jump-library`,"aria-disabled":`true`,className:`${u4} cursor-not-allowed opacity-60`,children:(0,W.jsx)(d4,{icon:v,title:`Library`,description:`Curated workouts and sessions, organized by tag.`,action:`Open the library`,note:`0 feeds synchronized`})}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>{k()},"data-testid":`jump-new-note`,className:u4,children:(0,W.jsx)(d4,{icon:Jt,title:`Start your own journal`,description:`Create today's note and log your first workout.`,action:`Create today's note`})})]})})]}),(0,W.jsx)(`div`,{"data-testid":`jump-rows`,className:`mt-6`,children:b.length>0?_?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(c4,{direction:`left`,testId:`jump-row-a`,children:S.map(e=>(0,W.jsx)(s4,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:D,importing:!!e.feedId&&a===e.feedId,busy:h,status:e.feedId?s[e.feedId]:void 0,onToggleNotebookSubscription:O},e.feedId??e.slug))}),C.length>0&&(0,W.jsx)(c4,{direction:`right`,testId:`jump-row-b`,className:`mt-4`,children:C.map(e=>(0,W.jsx)(s4,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] sm:w-[320px] shrink-0`,onImport:D,importing:!!e.feedId&&a===e.feedId,busy:h,status:e.feedId?s[e.feedId]:void 0,onToggleNotebookSubscription:O},e.feedId??e.slug))})]}):(0,W.jsx)(c4,{direction:`alternate`,testId:`jump-row-mobile`,children:b.map(e=>(0,W.jsx)(s4,{feed:e,testId:`feed-card-${e.feedId??e.slug}`,className:`w-[290px] shrink-0`,onImport:D,importing:!!e.feedId&&a===e.feedId,busy:h,status:e.feedId?s[e.feedId]:void 0,onToggleNotebookSubscription:O},e.feedId??e.slug))}):(0,W.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,W.jsxs)(`div`,{"data-testid":`jump-empty`,className:`flex flex-col items-center justify-center rounded-2xl border border-dashed border-border p-10 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-bold text-muted-foreground`,children:`No feeds match your search.`}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground/70`,children:`Try a different term or clear the filters.`}),A&&(0,W.jsx)(`button`,{type:`button`,"data-testid":`jump-clear-filters`,onClick:()=>{n(``),f(void 0),u(!1)},className:`mt-3 h-8 rounded-full border border-border px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground transition-colors hover:border-primary/50 hover:text-primary`,children:`Clear filters`})]})})}),(0,W.jsx)(`div`,{className:`mx-auto w-full max-w-6xl px-4 sm:px-6`,children:(0,W.jsx)(`p`,{className:`mt-4 font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground/60 xl:text-[11px]`,children:`— or keep scrolling ↓`})})]})}var p4=`wods/examples/home/welcome-1.md`;function m4({wodFiles:e,theme:t,quests:n}){let r=Iq(`(prefers-reduced-motion: reduce)`),i=pq()?.track;hq(`/`);let a=(0,U.useMemo)(()=>SV(p4,e),[e]),[o,s]=(0,U.useState)(()=>j0()),c=o?.content??a,l=o?o.by?.trim()||`anonymous`:void 0;(0,U.useEffect)(()=>{let e=e=>{let t=e.detail;t?.content&&(s(t),d(t.content))};return window.addEventListener(`wodwiki:home-shared`,e),()=>window.removeEventListener(`wodwiki:home-shared`,e)},[]);let[u,d]=(0,U.useState)(c),f=(0,U.useRef)(u);f.current=u;let p=(0,U.useRef)([]),m=(0,U.useRef)(!1),{run:h,start:g,finalize:_,end:v}=Cq(),y=(0,U.useRef)(h);y.current=h;let b=(0,U.useRef)(!1),x=(0,U.useRef)(!1),S=(0,U.useRef)(null),[C,w]=(0,U.useState)(!1),T=(0,U.useRef)(!1),E=(0,U.useRef)(null),[D,O]=(0,U.useState)(null),[k,A]=(0,U.useState)(!1),j=(0,U.useRef)(k);j.current=k;let M=(0,U.useRef)(!1),N=(0,U.useRef)(()=>{}),[P,F]=(0,U.useState)(0),[I,L]=(0,U.useState)(!1),[ee,te]=(0,U.useState)(!1),[ne,R]=(0,U.useState)(null),re=(0,U.useCallback)(async(e,t,n)=>{if(!t||M.current)return!1;M.current=!0,x.current=!1,b.current=!1,S.current=null,R(t),F(e=>e+1),L(!0),O(null),A(!0);try{await g(e,t,{pageTitle:`Home`,sectionTitle:n})}catch(e){return console.error(`[HomeTour] failed to persist playground run note:`,e),A(!1),R(null),Q({title:`Could not start workout`,description:`The playground entry could not be saved.`,variant:`destructive`}),!1}finally{M.current=!1}return!0},[g]),ie=(0,U.useCallback)(async()=>{if(T.current=!1,w(!1),S.current)try{await _(S.current,!1),S.current=null}catch(e){console.error(`[HomeTour] retry save failed:`,e),Q({title:`Session still not saved`,description:`The run is kept — try again.`,variant:`destructive`});return}let e=E.current;if(E.current=null,e)switch(e.kind){case`apply-doc`:m.current=!1,d(e.doc),A(!1),R(null),F(e=>e+1),L(!1);break;case`restart`:await re(e.doc,e.block,e.sectionTitle)}},[re,_]),ae=(0,U.useCallback)(e=>{if(!E.current){if(!y.current||x.current||!b.current||S.current){E.current=e,ie();return}E.current=e,T.current=!0,w(!0)}},[ie]),oe=(0,U.useRef)(null),se=(0,U.useRef)(null),ce=(0,U.useRef)(null);_Q(`hero`,ce);let[le,z]=(0,U.useState)(!1),ue=(0,U.useRef)(le);ue.current=le;let de=(0,U.useCallback)(()=>{let e=document.getElementById(`tour-section-editor`),t=oe.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:Math.max(0,e.getBoundingClientRect().top+window.scrollY-n),behavior:r?`auto`:`smooth`})},[r]),fe=(0,U.useCallback)(()=>{z(!0),window.setTimeout(de,350)},[de]),B=(0,U.useCallback)(()=>{z(!1),window.scrollTo({top:0,behavior:r?`auto`:`smooth`})},[r]),pe=(0,U.useRef)(!1),me=(0,U.useCallback)(()=>{ae({kind:`apply-doc`,doc:c})},[c,ae]);(0,U.useEffect)(()=>{let e=se.current;if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting?pe.current&&!j.current&&(pe.current=!1,me()):pe.current=!0});return t.observe(e),()=>t.disconnect()},[me]);let he=(0,U.useCallback)(()=>{M0(),s(null),ae({kind:`apply-doc`,doc:a})},[a,ae]),ge=(0,U.useCallback)(()=>{me();let e=document.getElementById(`tour-section-editor`),t=oe.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY;window.scrollTo({top:Math.max(0,e.getBoundingClientRect().top+window.scrollY-n),behavior:r?`auto`:`smooth`})},[r,me]);Fq({pageRoute:`/`,quests:n,initialSource:c,currentSource:u}),Pq({pageRoute:`/`,quests:n,completedResults:D}),N.current=I0(`/`,n),N0({pageRoute:`/`,quests:n,running:ee}),(0,U.useEffect)(()=>{let e=document.getElementById(`tour-section-insights`);if(!e||typeof IntersectionObserver>`u`)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&N.current?.(`session-insights`)});return t.observe(e),()=>t.disconnect()},[]);let _e=(0,U.useCallback)(e=>{d(e),e!==c&&!m.current&&(m.current=!0,i?.(fq.demoEdited))},[c,i]),ve=(0,U.useCallback)(e=>{p.current=e},[]),ye=(0,U.useCallback)((e,t,n,r)=>{if(n){if(i?.(fq.demoRun),r&&te(!0),R(n),A(!0),L(!0),F(e=>e+1),O(null),M.current||E.current){E.current={kind:`restart`,doc:t,block:n,sectionTitle:e};return}if(y.current&&b.current&&!x.current){E.current={kind:`restart`,doc:t,block:n,sectionTitle:e},T.current=!0,w(!0);return}if(y.current&&!x.current){v().then(()=>re(t,n,e));return}re(t,n,e)}},[re,v,i]),be=(0,U.useCallback)(()=>{ye(`Run`,f.current,p.current[0],!0)},[ye]),xe=(0,U.useCallback)(()=>{let e=()=>{let e=document.getElementById(`tour-section-insights`),t=oe.current;if(!e||!t||typeof window.scrollTo!=`function`)return;let n=t.getBoundingClientRect().top+window.scrollY,i=Math.max(0,e.getBoundingClientRect().top+window.scrollY-n);window.scrollTo({top:i,behavior:r?`auto`:`smooth`})};if(ue.current){e();return}z(!0),window.setTimeout(e,350)},[r]),Se=(0,U.useCallback)((e,t)=>{if(!(x.current&&!S.current))return(t.logs??[]).length===0?(x.current=!0,O(t),A(!1),xe(),ie()):(x.current=!0,_(t,t.completed).then(()=>{if(S.current=null,O(t),T.current||E.current)return A(!1),ie()}).catch(e=>{throw x.current=!1,b.current=!1,S.current=t,T.current=!1,w(!1),E.current=null,Q({title:`Session not saved`,description:`The run could not be recorded. Nothing was lost — your next action retries the save.`,variant:`destructive`}),e}))},[_,ie,xe]),Ce=(0,U.useCallback)(()=>{A(!1),xe()},[xe]),we=(0,U.useRef)(null),Te=(0,U.useCallback)(e=>{we.current=e},[]),Ee=(0,U.useCallback)(()=>{b.current=!0;let e=we.current;I&&e&&e.handle(new bp(void 0,e.nowProvider)),L(!1)},[I]),{setL3Items:De}=WM(),Oe=(0,U.useMemo)(()=>[{id:`tour-hero`,label:`Welcome`,level:3,action:{type:`scroll`,sectionId:`tour-hero`}},{id:`editor`,label:`Live Preview`,level:3,action:{type:`scroll`,sectionId:`tour-section-editor`}},{id:`insights`,label:`Session Insights`,level:3,action:{type:`scroll`,sectionId:`tour-section-insights`},secondaryAction:{id:`run-start`,label:`Run the workout`,action:{type:`call`,handler:be}}},{id:`boards`,label:`One Run Becomes Many`,level:3,action:{type:`scroll`,sectionId:`tour-section-boards`}},{id:`community-feeds`,label:`Library & Community Feeds`,level:3,action:{type:`scroll`,sectionId:`tour-section-community-feeds`}},{id:`offerings`,label:`Who owns the Data?`,level:3,action:{type:`scroll`,sectionId:`tour-section-offerings`}},{id:`university`,label:`Wod Wiki University`,level:3,action:{type:`scroll`,sectionId:`tour-section-university`}}],[be]);(0,U.useEffect)(()=>(De(Oe),()=>De([])),[De,Oe]),R0((0,U.useMemo)(()=>Oe.map(e=>e.action.type===`scroll`?e.action.sectionId:e.id),[Oe]));let ke=h?.block??ne,Ae=k&&ke&&(0,W.jsx)(OZ,{block:ke,resultId:h?.resultId,autoStart:I,externalStop:C,onRunStarted:Ee,onRuntimeReady:Te,onClose:Ce,onCompleteWorkout:Se},P),je=(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(d2,{}),(0,W.jsxs)(`p`,{className:`-mt-8 text-center font-mono text-[10px] uppercase tracking-[0.3em] text-muted-foreground/60 xl:text-[11px]`,children:[`— or learn the language with examples`,` `,(0,W.jsx)(_n,{to:`/syntax`,className:`text-foreground underline-offset-4 transition-colors hover:text-primary hover:underline`,children:`on the syntax page →`})]})]}),Me=(0,W.jsx)(vQ,{gateId:`editor-pane`,segmentId:`hero`,className:`w-full max-w-[720px] xl:max-w-[820px] 2xl:max-w-[920px]`,children:(0,W.jsx)(zq,{title:l?l.toLowerCase().startsWith(`shared by`)?l:`shared by: ${l}`:`welcome-1.md`,headerActions:l&&(0,W.jsx)(`button`,{type:`button`,onClick:he,title:`Reset`,className:`rounded-md border border-border px-2 py-1 text-[10px] transition-colors hover:bg-accent`,"data-testid":`tour-hero-reset-shared`,children:`Reset`}),className:`h-[540px] lg:h-[600px] 2xl:h-[640px]`,children:(0,W.jsx)(f2,{doc:u,theme:t,onDocChange:_e,onBlocksChange:ve,onRun:be})})}),Ne=(0,W.jsx)(`div`,{id:`tour-why-video-wrap`,"aria-hidden":le,className:G(`grid w-full transition-all duration-300 motion-reduce:transition-none`,le?`grid-rows-[0fr] opacity-0 invisible`:`grid-rows-[1fr] opacity-100`),children:(0,W.jsx)(`div`,{className:`min-h-0 overflow-hidden`,children:(0,W.jsx)(q0,{onWatched:fe})})}),Pe=(0,W.jsxs)(`div`,{ref:se,id:`tour-section-editor`,"data-testid":`tour-section-editor`,className:`flex w-full flex-col items-center px-5 py-8 text-center lg:px-10 xl:py-10 2xl:px-16`,children:[le&&(0,W.jsxs)(`button`,{type:`button`,onClick:B,"data-testid":`tour-why-watch-again`,className:`inline-flex items-center gap-1.5 rounded-t-lg border border-b-0 border-border bg-muted/40 px-3 py-1.5 font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground transition-colors hover:text-foreground`,children:[(0,W.jsx)(pn,{className:`size-3`}),`Watch again`]}),Me]});return r?(0,W.jsxs)(`div`,{"data-testid":`home-tour`,children:[(0,W.jsxs)(`section`,{id:`tour-hero`,"data-testid":`tour-hero`,className:`flex flex-col items-center gap-5 px-6 py-6 text-center`,children:[(0,W.jsx)(G0,{}),Ne,Pe]}),(0,W.jsx)(G2,{session:D,onRun:be,onBackToEditor:ge}),(0,W.jsx)(f4,{}),je,(0,W.jsx)(M$,{variant:`university`}),(0,W.jsx)(Y0,{}),Ae]}):(0,W.jsxs)(`div`,{"data-testid":`home-tour`,children:[(0,W.jsx)(`div`,{ref:oe,"aria-hidden":!0,className:`h-px`}),(0,W.jsxs)(`section`,{ref:ce,id:`tour-hero`,"data-testid":`tour-hero`,className:`relative flex min-h-[calc(100dvh-65px)] flex-col items-center justify-center gap-5 px-5 py-6 text-center lg:min-h-[calc(100dvh-104px)] lg:px-10 xl:gap-7 xl:py-8 2xl:px-16`,children:[(0,W.jsx)(G0,{}),Ne,Pe]}),(0,W.jsx)(G2,{session:D,onRun:be,onBackToEditor:ge}),(0,W.jsx)(f4,{}),je,(0,W.jsx)(M$,{variant:`university`}),(0,W.jsx)(Y0,{}),Ae]})}function h4(e){return(0,W.jsx)(B0,{children:(0,W.jsx)(gQ,{children:(0,W.jsx)(m4,{...e})})})}function g4({wodFiles:e,theme:t}){let n=(0,U.useMemo)(()=>E0(e),[e]);return(0,U.useEffect)(()=>{tS(`homeFirstPaint`)},[]),(0,W.jsx)(h4,{wodFiles:n,theme:t,quests:w0.quests})}var _4=`idle`,v4=null,y4=new Set,b4=null,x4=null;function S4(){for(let e of y4)e()}function C4(e){typeof document>`u`||(document.documentElement.dataset.feedState=e)}function w4(e){typeof document>`u`||(e===null?delete document.documentElement.dataset.feedOutcome:document.documentElement.dataset.feedOutcome=e)}C4(_4);function T4(e){_4!==e&&(_4=e,C4(e),S4())}function E4(){b4&&=(clearTimeout(b4),null),x4&&=(x4.close(),null)}function D4(e){v4=e,S4()}function O4(){E4(),w4(null),v4!==null&&(v4=null,S4()),T4(`preparing`)}function k4(e){switch(w4(e),e){case`busy`:if(_4!==`preparing`)return;typeof BroadcastChannel<`u`&&!x4&&(x4=new BroadcastChannel(Bv),x4.onmessage=e=>{e.data?.kind===`seed-imported`&&(E4(),T4(`ready`))}),b4=setTimeout(()=>{mM({onProgress:D4}).then(k4)},Gj);break;case`error`:E4(),T4(`error`);break;default:E4(),T4(`ready`)}}function A4(){return _4===`idle`?`ready`:_4}function j4(){return v4}function M4(e){return y4.add(e),()=>y4.delete(e)}function N4(){return(0,U.useSyncExternalStore)(M4,A4)}function P4(){return(0,U.useSyncExternalStore)(M4,j4)}var F4=null;function I4(e={}){return tS(`feedStart`),F4??=L4(e).finally(()=>{tS(`feedSettled`)}),F4}async function L4(e){let t=t=>{D4(t),e.onProgress?.(t)},n=e.sources??Xj();await Aee(e).catch(e=>console.error(`[feedSync] notebook vocabulary migration failed`,e)),await Oee(e).catch(e=>console.error(`[feedSync] checkpoint adoption failed`,e)),await Cj(n,e.storage).catch(e=>console.error(`[feedSync] subscription migration failed`,e));let r=e.storage??tj(),i;try{i=await r.getSeedMeta(Hv(`core`))}catch{i=void 0}let a=!i||i.seedVersion<=0;if(a?O4():k4(`current`),await kee(e).catch(e=>console.error(`[feedSync] feed provenance repair failed`,e)),a){k4(await mM({...e,sources:n,onProgress:t,onFirstPaint:()=>k4(`imported`)})),n.some(e=>e.id!==`core`&&mj(e.id))&&await mM({...e,sources:n,onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e));return}await mM({...e,sources:n,onProgress:t}).catch(e=>console.error(`[feedSync] background boot sync failed`,e))}function R4(){let[e,t]=(0,U.useState)(null);return(0,U.useEffect)(()=>{let e=!1,n=()=>{_M().then(n=>{e||t(!n.libraryImported)}).catch(()=>{e||t(!0)})};n();let r=Bx(()=>n()),i=sM(()=>n()),a=null;if(typeof BroadcastChannel<`u`)try{a=new BroadcastChannel(Bv),a.onmessage=()=>n()}catch{}return()=>{e=!0,r(),i(),a?.close()}},[]),e}var z4=[`📓`,`🏋️`,`🔥`,`💪`,`⭐`,`🎯`,`🏃`,`🧘`,`🥊`,`🚴`],B4=({open:e,onOpenChange:t,onCreate:n,notebook:r,onSave:i})=>{let[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(`📓`),[d,f]=(0,U.useState)(!1),p=!!r;U.useEffect(()=>{e&&(o(r?.name??``),c(r?.description??``),u(r?.icon??`📓`))},[e,r]);let m=async()=>{if(!(!a.trim()||d)){f(!0);try{let e=a.trim();if(!(p&&r&&i?await i(r,e,s.trim(),l):await n(e,s.trim(),l)))return;p||(o(``),c(``),u(`📓`)),t(!1)}finally{f(!1)}}};return(0,W.jsx)(SW,{open:e,onOpenChange:t,children:(0,W.jsxs)(CW,{className:`bg-popover text-popover-foreground border border-border`,children:[(0,W.jsxs)(wW,{children:[(0,W.jsx)(TW,{className:`text-foreground`,children:p?`Edit Notebook`:`Create Notebook`}),(0,W.jsx)(EW,{children:p?`Rename, describe or re-icon this notebook.`:`Organize your sessions into collections.`})]}),(0,W.jsxs)(`div`,{className:`space-y-4 mt-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`text-sm font-medium text-foreground/80 mb-2 block`,children:`Icon`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1`,children:z4.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>u(e),className:G(`w-9 h-9 rounded-md flex items-center justify-center text-lg transition-all`,`hover:bg-accent hover:scale-110`,l===e?`bg-primary/20 ring-2 ring-primary scale-110`:`bg-muted/50`),children:e},e))})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Name `,(0,W.jsx)(`span`,{className:`text-destructive`,children:`*`})]}),(0,W.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&a.trim()&&(e.preventDefault(),m())},placeholder:`e.g., Morning Routines`,autoFocus:!0,className:G(`w-full px-3 py-2 rounded-md text-sm`,`bg-background border border-border`,`text-foreground placeholder:text-muted-foreground`,`focus:outline-none focus:ring-2 focus:ring-primary/50`,`transition-colors`)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{className:`text-sm font-medium text-foreground/80 mb-1 block`,children:[`Description `,(0,W.jsx)(`span`,{className:`text-muted-foreground text-xs`,children:`(optional)`})]}),(0,W.jsx)(`textarea`,{value:s,onChange:e=>c(e.target.value),placeholder:`A brief description of this notebook...`,rows:2,className:G(`w-full px-3 py-2 rounded-md text-sm resize-none`,`bg-background border border-border`,`text-foreground placeholder:text-muted-foreground`,`focus:outline-none focus:ring-2 focus:ring-primary/50`,`transition-colors`)})]}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>t(!1),children:`Cancel`}),(0,W.jsx)(K,{variant:`default`,size:`sm`,onClick:()=>void m(),disabled:!a.trim()||d,children:d?`Saving…`:p?`Save`:`Create`})]})]})]})})},V4=({refreshKey:e,onChanged:t})=>{let[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null);if((0,U.useEffect)(()=>{let e=!1;return zA.getAllNotebooks().then(t=>{e||r(t)}).catch(()=>{e||r([])}),()=>{e=!0}},[e]),n===null)return(0,W.jsx)(`p`,{className:`px-6 py-3 text-xs text-muted-foreground`,"data-testid":`notebook-list-loading`,children:`Loading notebooks…`});let c=async e=>{try{await zA.delete(e.id)}catch{}finally{s(null),t()}};return(0,W.jsxs)(`section`,{className:`border-b border-border/60 px-6 py-3`,"data-testid":`notebook-list`,children:[(0,W.jsx)(`ul`,{className:`divide-y divide-border/40`,children:n.map(e=>{let t=e.origin===`user`;return(0,W.jsxs)(`li`,{className:`flex items-center gap-3 py-2`,"data-testid":`notebook-list-row`,children:[(0,W.jsx)(`span`,{"aria-hidden":!0,className:`text-base`,children:e.icon}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(_n,{to:`/notebook/${encodeURIComponent(e.slug)}`,className:`text-sm font-medium text-foreground hover:text-primary truncate block`,children:e.name}),e.description&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground truncate`,children:e.description})]}),(0,W.jsx)(`span`,{className:`text-[10px] font-bold uppercase tracking-wider text-muted-foreground/60`,children:e.origin===`feed`?`Feed`:e.origin==="default"?`App`:`Yours`}),t&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(K,{variant:`ghost`,size:`icon`,className:`size-8`,"aria-label":`Edit ${e.name}`,"data-testid":`notebook-edit-${e.slug}`,onClick:()=>a(e),children:(0,W.jsx)(qt,{className:`size-3.5`})}),o===e.notebookId?(0,W.jsx)(K,{variant:`destructive`,size:`sm`,title:`Notes in this notebook return to the journal`,"data-testid":`notebook-delete-confirm-${e.slug}`,onClick:()=>void c(e),children:`Confirm delete`}):(0,W.jsx)(K,{variant:`ghost`,size:`icon`,className:`size-8 text-muted-foreground hover:text-destructive`,"aria-label":`Delete ${e.name}`,"data-testid":`notebook-delete-${e.slug}`,onClick:()=>s(e.notebookId),children:(0,W.jsx)(Ue,{className:`size-3.5`})})]})]},e.notebookId)})}),(0,W.jsx)(B4,{open:i!==null,onOpenChange:e=>{e||a(null)},onCreate:async()=>null,notebook:i,onSave:async(e,n,r,i)=>{try{let a=await zA.update(e.id,{name:n,description:r,icon:i});return t(),a}catch{return null}}})]})};function H4({value:e,max:t,label:n,className:r}){let i=Math.max(1,t),a=Math.min(Math.max(e,0),i),o=Math.round(a/i*100),s=(0,U.useRef)(a),[c,l]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{if(a>s.current){l(!0);let e=setTimeout(()=>l(!1),200);return s.current=a,()=>clearTimeout(e)}s.current=a},[a]),(0,W.jsxs)(`div`,{className:G(`w-full`,r),children:[n?(0,W.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between text-[11px] font-semibold uppercase tracking-[0.14em] text-brand-deep dark:text-brand-light`,children:[(0,W.jsx)(`span`,{children:n}),(0,W.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[a,`/`,i]})]}):null,(0,W.jsx)(`div`,{role:`progressbar`,"aria-valuenow":a,"aria-valuemin":0,"aria-valuemax":i,"aria-label":n??`Progress`,className:`h-2 w-full overflow-hidden rounded-pill bg-brand/10`,children:(0,W.jsx)(`div`,{className:G(`h-full rounded-pill transition-[width] duration-500 ease-out`,c?`bg-brand-deep`:`bg-brand`),style:{width:`${o}%`}})})]})}function U4(e,t,n){TH.getState().open({placeholder:`Craft the query…`,wql:{initialQuery:e,execute:t,onApply:n},sources:[dU()]})}function W4({query:e,onQueryChange:t,scopeOptions:n,execute:r,defaultQuery:i,compact:a=!1,className:o}){let s=(0,U.useCallback)(()=>U4(e,r,t),[e,r,t]);return a?(0,W.jsx)(`div`,{"data-testid":`stream-query-bar-dock`,className:G(`flex min-h-12 w-full items-stretch overflow-hidden rounded-xl border border-border bg-muted/40 shadow-xs`,o),children:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`stream-query-bar`,onClick:s,className:`flex min-w-0 flex-1 cursor-pointer items-center gap-2.5 px-3 text-left transition-colors hover:bg-muted/70`,children:[(0,W.jsx)(Tt,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{"data-testid":`stream-query-summary`,className:`min-w-0 flex-1 truncate font-mono text-xs text-muted-foreground`,children:e||i||`Filter or search…`}),(0,W.jsx)(_t,{className:`size-4 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]})}):(0,W.jsx)(`div`,{"data-testid":`stream-query-bar`,className:G(`flex min-w-0 flex-1 items-center gap-1 text-xs`,o),children:(0,W.jsx)(Kw,{query:e,onQueryChange:t,compact:!0,showDiagnostics:!1,preferredChoices:n,placeholder:`Filter or search…`,className:`min-w-0 flex-1`})})}function G4(e,t){let n=t??X(e);return n.error?null:n.groupBy?.length?n.groupBy.map(e=>String(e).toLowerCase()):null}function K4(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/(^-|-$)/g,``)||`default`}function q4(e,t=`date`,n){let r=(Array.isArray(t)?t:[t]).map(e=>String(e).toLowerCase()).filter(Boolean);r.length===0&&r.push(`date`);let i=(e,t)=>{let r=J4(e,t[0],n);return t.length===1?r:r.flatMap(e=>e.key===`shelf`?[e]:i(e.entries,t.slice(1)).map(t=>({...t,key:`${e.key}/${t.key}`,id:`${e.id}--${t.id}`,label:`${e.label} / ${t.label}`,isToday:e.isToday||t.isToday})))};return i(e,r)}function J4(e,t,n){let r=t.toLowerCase(),i=YH();if(r===`date`||r===`day`){let t=new Map,r=[],a=[];for(let i of e){let e=i.date??(i.sourceNotebook===`playground`&&i.createdAt&&i.createdAt>9466848e5?new Date(i.createdAt).toISOString().slice(0,10):null);if(n?.shelfVisible&&(e==null||i.kind===`note`&&!i.sourceNote))r.push(i);else if(e){let n=t.get(e);n?n.push(i):t.set(e,[i])}else a.push(i)}let o=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)),s=[];n?.shelfVisible&&r.length>0&&s.push({id:`group-shelf`,key:`shelf`,label:`Notebook Sessions`,entries:r});for(let e of o)s.push({id:`date-group-${e}`,key:e,label:e===i?`Today`:XH(e),isToday:e===i,entries:t.get(e)??[]});return a.length>0&&s.push({id:`group-date-undated`,key:`undated`,label:`Undated`,entries:a}),s}if(r===`week`){let t=new Map,n=[];for(let r of e){if(!r.date){n.push(r);continue}let[e,i,a]=r.date.split(`-`).map(Number),o=new Date(Date.UTC(e,i-1,a)),s=o.getUTCDay(),c=o.getUTCDate()-s+(s===0?-6:1),l=new Date(Date.UTC(e,i-1,c)),u=l.toISOString().slice(0,10),d=`Week of ${l.toLocaleDateString(`en`,{month:`short`,day:`numeric`,year:`numeric`,timeZone:`UTC`})}`,f=t.get(u);f?f.entries.push(r):t.set(u,{label:d,entries:[r]})}let r=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)).map(e=>({id:`group-week-${e}`,key:e,label:t.get(e).label,entries:t.get(e).entries}));return n.length>0&&r.push({id:`group-week-undated`,key:`undated`,label:`Undated`,entries:n}),r}if(r===`month`){let t=new Map,n=[];for(let r of e){if(!r.date){n.push(r);continue}let e=r.date.slice(0,7),[i,a]=e.split(`-`).map(Number),o=new Date(Date.UTC(i,a-1,1)).toLocaleDateString(`en`,{month:`long`,year:`numeric`,timeZone:`UTC`}),s=t.get(e);s?s.entries.push(r):t.set(e,{label:o,entries:[r]})}let r=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)).map(e=>({id:`group-month-${e}`,key:e,label:t.get(e).label,entries:t.get(e).entries}));return n.length>0&&r.push({id:`group-month-undated`,key:`undated`,label:`Undated`,entries:n}),r}if(r===`year`){let t=new Map,n=[];for(let r of e){if(!r.date){n.push(r);continue}let e=r.date.slice(0,4),i=t.get(e);i?i.push(r):t.set(e,[r])}let r=Array.from(t.keys()).sort((e,t)=>t.localeCompare(e)).map(e=>({id:`group-year-${e}`,key:e,label:e,entries:t.get(e)??[]}));return n.length>0&&r.push({id:`group-year-undated`,key:`undated`,label:`Undated`,entries:n}),r}if(r===`discipline`){let t=new Map;for(let n of e){let e=n.effort?.discipline||n.tags?.find(e=>[`strength`,`gymnastics`,`cardio`,`running`,`rowing`,`weightlifting`,`olympic-weightlifting`].includes(e.toLowerCase()))||`General`,r=e.charAt(0).toUpperCase()+e.slice(1).toLowerCase(),i=t.get(r);i?i.push(n):t.set(r,[n])}return rF(Array.from(t.entries()),`priority-then-alpha`,{priority:[`Strength`,`Gymnastics`,`Cardio`,`Running`,`Rowing`,`Weightlifting`]}).map(([e])=>e).map(e=>({id:`group-discipline-${K4(e)}`,key:e,label:e,entries:t.get(e)??[]}))}if(r===`origin`){let t=new Map;for(let n of e){let e=n.effort?.registrySource===`bundled`?`Bundled Standards`:`Custom Movements`,r=t.get(e);r?r.push(n):t.set(e,[n])}return rF(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-origin-${K4(e)}`,key:e,label:e,entries:t}))}if(r===`source`||r===`notebook`){let t=new Map;for(let n of e){let e=n.sourceNotebook||`Other`,r=e.charAt(0).toUpperCase()+e.slice(1),i=t.get(r);i?i.push(n):t.set(r,[n])}return rF(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-source-${K4(e)}`,key:e,label:e,entries:t}))}if(r===`kind`||r===`type`){let t=new Map;for(let n of e){let e=n.kind.charAt(0).toUpperCase()+n.kind.slice(1)+`s`,r=t.get(e);r?r.push(n):t.set(e,[n])}return rF(Array.from(t.entries()),`alpha`).map(([e,t])=>({id:`group-kind-${K4(e)}`,key:e,label:e,entries:t}))}if(!fm.includes(r)){let t=new Map;for(let n of e){let e=n.typedTags?.find(e=>e.type?.toLowerCase()===r)?.label??`Unassigned`,i=t.get(e);i?i.push(n):t.set(e,[n])}return rF(Array.from(t.entries()),`alpha-sink-last`,{sink:`Unassigned`}).map(([e,t])=>({id:`group-property-${K4(r)}-${K4(e)}`,key:e,label:e,entries:t}))}let a=new Map;for(let t of e){let e=t.tags?.[0]?`#${t.tags[0]}`:`Untagged`,n=a.get(e);n?n.push(t):a.set(e,[t])}return rF(Array.from(a.entries()),`alpha-sink-last`,{sink:`Untagged`}).map(([e,t])=>({id:`group-tag-${K4(e)}`,key:e,label:e,entries:t}))}var Y4=[{id:iN.route,label:`Journal`,profile:iN,scopeChoices:NC,shortcuts:!0},{id:oN.route,label:`Notes`,profile:oN,scopeChoices:NC,shortcuts:!0},{id:aN.route,label:`Notebooks`,profile:aN,scopeChoices:NC,shortcuts:!0},{id:sN.route,label:`Feeds`,profile:sN,scopeChoices:NC,shortcuts:!0},{id:cN.route,label:`Pages`,profile:cN,scopeChoices:NC,shortcuts:!0},{id:lN.route,label:`Efforts`,profile:lN,scopeChoices:NC,shortcuts:!0},{id:uN.route,label:`Equipment`,profile:uN,scopeChoices:NC,shortcuts:!0},{id:dN.route,label:`Tags`,profile:dN,shortcuts:!0},{id:fN.route,label:`Sessions`,profile:fN,scopeChoices:NC,shortcuts:!0},{id:pN.route,label:`Playgrounds`,profile:pN,scopeChoices:NC,shortcuts:!0}],X4={id:`/dashboards`,label:`Dashboards`,systemDefaultWql:`:dashboard{}`},Z4={id:sF,label:`Command palette`,systemDefaultWql:sU,scopeChoices:NC},Q4=[...Y4,X4,Z4];function $4(e){return Q4.find(t=>t.id===e)}function e3({className:e,...t}){return(0,W.jsx)(te,{"data-slot":`control`,...t,className:G(e,`group relative isolate inline-flex h-6 w-10 cursor-default rounded-full p-[3px] sm:h-5 sm:w-8`,`transition duration-0 ease-in-out data-changing:duration-200`,`forced-colors:outline forced-colors:bg-[Highlight] dark:forced-colors:bg-[Highlight]`,`bg-muted ring-1 ring-black/5 ring-inset dark:bg-white/5 dark:ring-white/15`,`data-checked:bg-primary data-checked:ring-primary/90`,`dark:data-checked:bg-primary dark:data-checked:ring-primary/90`,`focus:not-data-[focus]:outline-hidden data-[focus]:outline-2 data-[focus]:outline-offset-2 data-[focus]:outline-ring`,`data-[hover]:ring-black/15 dark:data-[hover]:ring-white/25 data-[hover]:data-checked:ring-primary/90 dark:data-[hover]:data-checked:ring-primary/90`,`data-[disabled]:bg-muted dark:data-[disabled]:bg-white/15 data-[disabled]:opacity-50 data-[disabled]:data-checked:bg-muted dark:data-[disabled]:data-checked:bg-white/15 data-[disabled]:data-checked:ring-black/5 dark:data-[disabled]:data-checked:ring-white/15`),children:(0,W.jsx)(`span`,{"aria-hidden":`true`,className:G(`pointer-events-none relative inline-block size-4.5 rounded-full sm:size-3.5`,`translate-x-0 transition duration-200 ease-in-out`,`border border-transparent`,`bg-background shadow-sm ring-1 ring-black/5 dark:ring-white/5`,`group-data-checked:bg-primary-foreground group-data-checked:shadow-sm group-data-checked:ring-primary/90`,`group-data-checked:translate-x-4 sm:group-data-checked:translate-x-3`,`group-data-checked:group-data-[disabled]:bg-background group-data-checked:group-data-[disabled]:shadow-sm group-data-checked:group-data-[disabled]:ring-black/5 dark:group-data-checked:group-data-[disabled]:ring-white/5`)})})}var t3=Object.fromEntries([...NC,...MC].map(e=>[e.value,e.label]));function n3({values:e,choices:t,labels:n,onChange:r,testPrefix:i,reorderable:a=!1}){let o=(t,n)=>{let i=[...e],a=t+n;if(a<0||a>=i.length)return;let o=i[t];i[t]=i[a],i[a]=o,r(i)};return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:e.map((t,s)=>(0,W.jsxs)(`span`,{"data-testid":`${i}-chip-${t}`,className:`inline-flex items-center gap-1 rounded-full border border-border/70 bg-muted/40 px-2.5 py-1 text-xs font-medium`,children:[n[t]??t,a&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`button`,{type:`button`,"aria-label":`Move ${t} up`,"data-testid":`${i}-up-${t}`,disabled:s===0,onClick:()=>o(s,-1),className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,children:(0,W.jsx)(Fe,{className:`size-3`})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Move ${t} down`,"data-testid":`${i}-down-${t}`,disabled:s===e.length-1,onClick:()=>o(s,1),className:`text-muted-foreground hover:text-foreground disabled:opacity-30`,children:(0,W.jsx)(ze,{className:`size-3`})})]}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Remove ${t}`,"data-testid":`${i}-remove-${t}`,onClick:()=>r(e.filter(e=>e!==t)),className:`text-muted-foreground hover:text-foreground`,children:(0,W.jsx)(we,{className:`size-3`})})]},t))}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.filter(t=>!e.includes(t.value)).map(t=>(0,W.jsxs)(`button`,{type:`button`,"aria-label":`Add ${t.value}`,"data-testid":`${i}-add-${t.value}`,onClick:()=>r([...e,t.value]),className:`rounded-full border border-dashed border-border/70 px-2.5 py-1 text-xs text-muted-foreground hover:text-foreground hover:border-foreground/40`,children:[`+ `,t.label]},t.value))})]})}function r3({values:e,choices:t,onChange:n,testPrefix:r}){return(0,W.jsx)(n3,{values:e,choices:t,labels:t3,onChange:n,testPrefix:r,reorderable:!0})}function i3({values:e,onChange:t,testPrefix:n}){return(0,W.jsx)(n3,{values:e,choices:$P.map(e=>({value:e.id,label:e.label})),labels:Object.fromEntries($P.map(e=>[e.id,e.label])),onChange:t,testPrefix:n,reorderable:!0})}function a3({label:e,enabled:t,onEnabledChange:n,testId:r,children:i}){return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:e}),(0,W.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-muted-foreground`,children:[`Custom`,(0,W.jsx)(e3,{checked:t,onChange:n,"data-testid":r})]})]}),i]})}function o3({shortcuts:e,icons:t,landingId:n,onEdit:r,onDelete:i,onCreate:a,error:o,testPrefix:s}){return(0,W.jsxs)(`div`,{className:`space-y-2`,"data-testid":`${s}-shortcuts`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Saved shortcuts`}),(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:a,"data-testid":`${s}-shortcut-new`,children:`New shortcut`})]}),e.map(e=>{let a=t[e.icon]??t.bookmark,o=e.to?`Opens ${e.to}`:e.wql||`Landing (no query)`;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 rounded-md border border-border/50 px-2 py-1.5`,"data-testid":`${s}-shortcut-${e.id}`,children:[(0,W.jsx)(a,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`}),(0,W.jsx)(`span`,{className:`min-w-0 max-w-40 truncate text-xs font-medium`,children:e.label}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-[10px] text-muted-foreground`,children:o}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Edit ${e.label}`,"data-testid":`${s}-shortcut-edit-${e.id}`,onClick:()=>r(e),className:`shrink-0 rounded p-1 text-muted-foreground hover:text-foreground`,children:(0,W.jsx)(qt,{className:`size-3`})}),!e.to&&e.id!==n&&(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete ${e.label}`,"data-testid":`${s}-shortcut-delete-${e.id}`,onClick:()=>i(e.id),className:`shrink-0 rounded p-1 text-muted-foreground hover:text-destructive`,children:(0,W.jsx)(Ue,{className:`size-3`})})]},e.id)}),o&&(0,W.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`${s}-shortcut-error`,children:o})]})}function s3(e){return{defaultWql:e.defaultWql??``,customScope:e.typeOptions!==void 0,scopeOptions:e.typeOptions??[],customGroupBy:e.groupByOptions!==void 0,groupByOptions:e.groupByOptions??[]}}function c3(e){return{defaultWql:e.defaultWql.trim()||void 0,typeOptions:e.customScope?e.scopeOptions:void 0,groupByOptions:e.customGroupBy?e.groupByOptions:void 0}}function l3({surface:e,onSaved:t}){let n=EF(e.id),r=JF(e.id),[i,a]=(0,U.useState)(()=>s3(n)),[o,s]=(0,U.useState)(()=>n),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(null);(0,U.useEffect)(()=>{a(s3(n)),s(n),l(null),d(null)},[n]);let m=e.profile?.defaultWql??e.systemDefaultWql??``,h=(()=>{let e=i.defaultWql.trim();return e?Iw(e).error??null:null})(),g=c3(i),_=JSON.stringify(g)!==JSON.stringify(o),v=Object.values(o).some(e=>e!==void 0),y=[...o.invalidTypeOptions??[],...o.invalidGroupByOptions??[]],b=async()=>{if(!_)return;let n=i.defaultWql.trim();if(!(n&&Iw(n).error)){if(!await yF(e.id,g)){l(`Save failed — storage is unavailable; the previous default still stands.`);return}l(null),s(vF(e.id)),t?.()}},x=async()=>{if(!await bF(e.id)){l(`Reset failed — storage is unavailable; the stored override still stands.`);return}l(null),s({}),a(s3({})),t?.()},S=async t=>{d(null),await HF(e.id,r.filter(e=>e.id!==t))||d(`Delete failed — storage is unavailable. Nothing was lost; the link remains.`)},C=e.scopeChoices??[],w=C.length>0;return(0,W.jsxs)(`div`,{className:`space-y-5`,"data-testid":`query-settings-panel`,children:[(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsx)(`label`,{className:`text-xs font-semibold text-muted-foreground`,children:`Landing default query`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`System default: `,(0,W.jsx)(`span`,{className:`font-mono`,children:m})]}),(0,W.jsx)(`textarea`,{rows:2,value:i.defaultWql,onChange:e=>a({...i,defaultWql:e.target.value}),placeholder:m,"data-testid":`query-settings-wql`,className:`w-full rounded-md border border-border bg-background px-3 py-2 font-mono text-xs focus:outline-none focus:ring-1 focus:ring-primary/40`}),h?(0,W.jsxs)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-wql-error`,children:[`Couldn't parse — `,h]}):!i.defaultWql.trim()&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Empty — the system default is used.`})]}),y.length>0&&(0,W.jsxs)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,"data-testid":`query-settings-invalid`,children:[`Stored options no longer recognized: `,y.join(`, `),` — remove them; they are never turned into query clauses.`]}),w&&(0,W.jsx)(a3,{label:`Where-stored options`,enabled:i.customScope,onEnabledChange:e=>a({...i,customScope:e}),testId:`query-settings-scope-custom`,children:i.customScope&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(r3,{values:i.scopeOptions,choices:C,onChange:e=>a({...i,scopeOptions:e}),testPrefix:`query-settings-scope`}),i.scopeOptions.length===0&&(0,W.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,"data-testid":`query-settings-scope-empty`,children:`No predefined options — the page nudges for a pick instead.`})]})}),e.profile&&(0,W.jsxs)(a3,{label:`Group-by options`,enabled:i.customGroupBy,onEnabledChange:e=>a({...i,customGroupBy:e}),testId:`query-settings-group-custom`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The dimensions this page offers first, and the one a bare landing groups by. Order is the priority.`}),i.customGroupBy&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(i3,{values:i.groupByOptions,onChange:e=>a({...i,groupByOptions:e}),testPrefix:`query-settings-group`}),i.groupByOptions.length===0&&(0,W.jsx)(`p`,{className:`text-xs text-amber-600 dark:text-amber-400`,"data-testid":`query-settings-group-empty`,children:`No favorites — the page groups by its own default.`})]})]}),e.shortcuts&&(0,W.jsx)(o3,{shortcuts:r,icons:kF,landingId:`all`,onEdit:e=>p({editing:e}),onDelete:S,onCreate:()=>p({editing:null}),error:u,testPrefix:`query-settings`}),c&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,"data-testid":`query-settings-storage-error`,role:`alert`,children:c}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsxs)(K,{variant:`ghost`,size:`sm`,onClick:x,disabled:!v,"data-testid":`query-settings-reset`,children:[(0,W.jsx)(At,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Reset to system default`})]}),(0,W.jsx)(K,{size:`sm`,onClick:b,disabled:!_||!!h,"data-testid":`query-settings-save`,children:`Save`})]}),f&&(0,W.jsx)($F,{open:!0,onOpenChange:e=>{e||p(null)},route:e.id,editing:f.editing})]})}function u3({surface:e,open:t,onOpenChange:n}){return(0,W.jsx)(OC,{open:t,onClose:()=>n(!1),title:`${e.label} query settings`,description:`Override the landing query and the Where-stored / Group-By options for this page. An empty query uses the system default; an emptied options list nudges you to pick instead of presetting one. Option lists are favorites — they reorder choices, they don't change what queries mean.`,presentation:`sheet`,children:(0,W.jsx)(l3,{surface:e})})}var d3=mt,f3=Xn,p3=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(sn,{ref:n,className:G(`fixed inset-0 z-50 bg-black/80 dark:bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,e),...t}));p3.displayName=sn.displayName;var m3=U.forwardRef(({className:e,children:t,...n},r)=>(0,W.jsxs)(f3,{children:[(0,W.jsx)(p3,{}),(0,W.jsxs)(Bn,{ref:r,className:G(`fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg`,e),...n,children:[t,(0,W.jsxs)(xn,{className:`absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground`,children:[(0,W.jsx)(we,{className:`h-4 w-4`}),(0,W.jsx)(`span`,{className:`sr-only`,children:`Close`})]})]})]}));m3.displayName=Bn.displayName;var h3=({className:e,...t})=>(0,W.jsx)(`div`,{className:G(`flex flex-col space-y-1.5 text-center sm:text-left`,e),...t});h3.displayName=`DialogHeader`;var g3=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(Ot,{ref:n,className:G(`text-lg font-semibold leading-none tracking-tight`,e),...t}));g3.displayName=Ot.displayName;var _3=U.forwardRef(({className:e,...t},n)=>(0,W.jsx)(Ct,{ref:n,className:G(`text-sm text-muted-foreground`,e),...t}));_3.displayName=Ct.displayName;var v3=[`date`,`datetime-local`,`month`,`time`,`week`],y3=(0,U.forwardRef)(function({className:e,...t},n){return(0,W.jsx)(`span`,{"data-slot":`control`,className:G(`relative block w-full`,`before:absolute before:inset-px before:rounded-[calc(var(--radius-lg)-1px)] before:bg-background before:shadow-sm`,`dark:before:hidden`,`after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-transparent after:ring-inset`,`sm:focus-within:after:ring-2 sm:focus-within:after:ring-ring`,`has-data-[disabled]:opacity-50 has-data-[disabled]:before:bg-muted/50 has-data-[disabled]:before:shadow-none`),children:(0,W.jsx)(je,{ref:n,...t,className:G(t.type&&v3.includes(t.type)&&[`[&::-webkit-datetime-edit-fields-wrapper]:p-0`,`[&::-webkit-date-and-time-value]:min-h-[1.5em]`,`[&::-webkit-datetime-edit]:inline-flex`,`[&::-webkit-datetime-edit]:p-0`,`[&::-webkit-datetime-edit-year-field]:p-0`,`[&::-webkit-datetime-edit-month-field]:p-0`,`[&::-webkit-datetime-edit-day-field]:p-0`,`[&::-webkit-datetime-edit-hour-field]:p-0`,`[&::-webkit-datetime-edit-minute-field]:p-0`,`[&::-webkit-datetime-edit-second-field]:p-0`,`[&::-webkit-datetime-edit-millisecond-field]:p-0`,`[&::-webkit-datetime-edit-meridiem-field]:p-0`],`relative block w-full appearance-none rounded-lg px-[calc(theme(spacing.3.5)-1px)] py-[calc(theme(spacing.2.5)-1px)]`,`sm:px-[calc(theme(spacing.3)-1px)] sm:py-[calc(theme(spacing.1.5)-1px)]`,`text-base/6 text-foreground placeholder:text-muted-foreground sm:text-sm/6`,`border border-border/60 hover:border-border data-[hover]:border-border`,`bg-transparent dark:bg-white/5`,`focus:outline-hidden`,`data-invalid:border-destructive data-invalid:data-[hover]:border-destructive`,`data-[disabled]:border-border/40 dark:data-[disabled]:border-border/30 dark:data-[disabled]:bg-white/2.5`,`dark:scheme-dark`,e)})})}),b3=e=>Fy(new Date(e)),x3=e=>{if(!Number.isFinite(e)||e<=0)return`0 B`;let t=[`B`,`KB`,`MB`,`GB`],n=Math.min(Math.floor(Math.log(e)/Math.log(1024)),t.length-1);return`${(e/1024**n).toFixed(n===0?0:1)} ${t[n]}`};function S3(e,t){Q(e===`imported`?{title:`${t} synced`,description:`Content was imported from the published feed. Your own edits were kept.`}:e===`error`?{title:`${t} sync failed`,description:`Check your connection and the browser console for details.`,variant:`destructive`}:e===`busy`?{title:`Another tab is already syncing`,description:`Wait for it to finish, then try again.`}:{title:`${t}: nothing to import (${e})`})}var C3={imported:`Synced`,current:`Up to date`,"server-stale":`Published version is older than the stored version`,"update-pending":`Update available`,busy:`Another tab is syncing`,disabled:`Feed import is disabled`,error:`Sync failed`};function w3(e){switch(e.phase){case`checking`:return`Checking source…`;case`fetching`:return`Downloading ${e.chunkId}…`;case`applying`:return`Importing ${e.chunkId}…`;case`committed`:return`Committed ${e.chunkId}`;case`finalizing`:return`Finalizing checkpoints…`;case`finished`:return e.error??C3[e.outcome]}}function T3({source:e,running:t,disabled:n,onSync:r,onSubscribe:i,onUnsubscribe:a,onDelete:o,onAutoSync:s,onToggleNotebook:c,subscribedOnly:l}){let u=(0,U.useSyncExternalStore)(yj,()=>xj(e.id)),d=e.notebooks.filter(t=>t.id!==e.id),f=l?d.filter(e=>e.subscribed):d,p=e.autoImport,m=e.subscribed&&!e.upToDate&&e.remote!==null;return(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-source-${e.id}`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-x-4 gap-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0 flex-wrap`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground truncate`,children:e.label}),(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded shrink-0 ${e.subscribed?`bg-emerald-500/10 text-emerald-600`:`bg-muted text-muted-foreground`}`,children:e.subscribed?`Subscribed`:`Not subscribed`}),p&&(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground shrink-0`,children:`Core`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 flex-wrap justify-end`,children:[e.subscribed?m?(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>r(e.id),disabled:n,"data-testid":`feed-sync-${e.id}`,className:`gap-2`,children:[(0,W.jsx)(zt,{className:`size-3.5 ${t?`animate-spin`:``}`}),(0,W.jsx)(`span`,{children:t?`Syncing…`:`Sync`})]}):(0,W.jsxs)(`span`,{className:`text-xs text-muted-foreground flex items-center gap-1.5`,"data-testid":`feed-current-${e.id}`,children:[(0,W.jsx)(yn,{className:`size-3.5 text-emerald-500`}),e.remote===null?`Remote unreachable`:`Up to date`]}):(0,W.jsxs)(K,{size:`sm`,onClick:()=>i(e.id),disabled:n,"data-testid":`feed-subscribe-${e.id}`,className:`gap-2`,children:[(0,W.jsx)(Ee,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Subscribe`})]}),(0,W.jsxs)(`label`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,title:e.subscribed?`Apply new published versions automatically during the load-time check. Turning it off never removes content.`:`Unsubscribed sources never auto-import.`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 accent-primary`,checked:u,disabled:n||!e.subscribed,onChange:t=>s(e.id,t.target.checked),"aria-label":`Auto-sync ${e.label}`,"data-testid":`feed-autosync-${e.id}`}),(0,W.jsx)(`span`,{children:`Auto-sync`})]}),(0,W.jsxs)(`details`,{className:`relative shrink-0`,"data-testid":`feed-more-${e.id}`,children:[(0,W.jsx)(`summary`,{"aria-label":`More actions for ${e.label}`,className:`flex cursor-pointer list-none items-center justify-center rounded-md border border-border px-2 py-1 text-xs font-medium text-muted-foreground hover:text-foreground [&::-webkit-details-marker]:hidden`,children:`…`}),(0,W.jsxs)(`div`,{className:`absolute right-0 z-20 mt-1 flex w-64 max-w-[80vw] flex-col items-stretch gap-1.5 rounded-lg border border-border bg-card p-2 text-xs shadow-lg`,children:[e.url?(0,W.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,className:`break-all font-mono text-primary hover:underline`,children:[`Published HTML: `,e.url]}):(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Published HTML: bundled with this app (no standalone URL)`}),e.repositoryUrl?(0,W.jsx)(`a`,{href:e.repositoryUrl,target:`_blank`,rel:`noopener noreferrer`,className:`break-all text-primary hover:underline`,children:`Git source directory`}):(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Git repository: not published`}),!p&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>a(e.id),disabled:n||!e.subscribed,"data-testid":`feed-unsubscribe-${e.id}`,className:`min-h-8 rounded-md px-2 text-left text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:`Unsubscribe`}),!p&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>o(e.id),disabled:n,"data-testid":`feed-delete-${e.id}`,className:`min-h-8 rounded-md px-2 text-left text-destructive hover:bg-destructive/10 disabled:opacity-50`,children:`Delete source`})]})]})]})]}),e.url&&(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground font-mono break-all`,"data-testid":`feed-origin-${e.id}`,children:e.url}),e.description&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`feed-description-${e.id}`,children:e.description}),f.length>0&&(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-muted/20 px-3 py-2`,"data-testid":`feed-notebooks-${e.id}`,children:[(0,W.jsxs)(`p`,{className:`text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:[f.length===1?`1 notebook`:`${f.length} notebooks`,` · `,l?`subscribed`:`available in this feed`]}),(0,W.jsx)(`ul`,{className:`mt-1.5 flex flex-col gap-1`,children:f.map(t=>(0,W.jsxs)(`li`,{"data-testid":`feed-notebook-${e.id}-${t.chunkId}`,className:`flex items-center justify-between gap-4 text-xs`,children:[(0,W.jsxs)(`span`,{className:t.imported?`flex min-w-0 items-center gap-1.5 text-foreground`:`flex min-w-0 items-center gap-1.5 text-muted-foreground`,children:[t.imported?(0,W.jsx)(yn,{className:`size-3 shrink-0 text-emerald-500`,"aria-hidden":!0}):(0,W.jsx)(Ee,{className:`size-3 shrink-0 opacity-60`,"aria-hidden":!0}),(0,W.jsx)(`span`,{className:`truncate`,children:t.label})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,W.jsxs)(`span`,{className:`tabular-nums text-muted-foreground`,children:[t.count.toLocaleString(),` `,t.count===1?`item`:`items`]}),!p&&c&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>c(e.id,t.chunkId,!t.subscribed),"data-testid":`feed-notebook-toggle-${e.id}-${t.chunkId}`,className:`text-[10px] font-semibold uppercase tracking-wider px-2 py-0.5 rounded shrink-0 transition-colors ${t.subscribed?`bg-emerald-500/10 text-emerald-600 hover:bg-emerald-500/20`:`border border-border text-muted-foreground hover:bg-muted`}`,children:t.subscribed?`Subscribed`:`Subscribe`})]})]},t.chunkId))})]}),(0,W.jsxs)(`div`,{className:`grid gap-1 text-sm`,"data-testid":`feed-status-card`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Library`}),(0,W.jsxs)(`span`,{className:`font-medium text-foreground text-xs tabular-nums`,"data-testid":`feed-source-size`,children:[e.count.toLocaleString(),` feed `,e.count===1?`item`:`items`,` · `,x3(e.bytes)]})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Local database`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-local-version`,children:e.stored?`v${e.stored.version} · schema ${e.stored.schema} · imported ${b3(e.stored.importedAt)}`:`Not imported yet`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Published version`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs flex items-center gap-1.5`,"data-testid":`feed-remote-version`,children:e.remote?`v${e.remote.version} · schema ${e.remote.schema}`:e.remoteError?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Qt,{className:`size-3.5 text-muted-foreground`}),`Unavailable`]}):`Checking…`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last check`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-check`,children:e.checkedAt?b3(e.checkedAt):`—`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Last sync`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground text-xs`,"data-testid":`feed-last-sync`,children:e.stored?b3(e.stored.importedAt):`Never`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Status`}),(0,W.jsx)(`span`,{className:`font-medium text-xs flex items-center gap-1.5`,"data-testid":`feed-sync-status`,children:e.subscribed?e.upToDate?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(yn,{className:`size-3.5 text-emerald-500`}),`Up to date`]}):e.remote==null?`Unknown (remote unreachable)`:u?`Update available — applied automatically on next load`:`Update available — sync to apply`:`Not subscribed`})]})]})]})}function E3(){let[e,t]=(0,U.useState)(null),[n,r]=(0,U.useState)(!0),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)([]),[u,d]=(0,U.useState)(``),[f,p]=(0,U.useState)(``),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(!0),[v,y]=(0,U.useState)(),b=(0,U.useCallback)(async()=>{a(null);try{t(await Eee())}catch(e){a(e instanceof Error?e.message:String(e))}finally{r(!1)}},[]);(0,U.useEffect)(()=>{b()},[b]),(0,U.useEffect)(()=>yj(()=>{b()}),[b]),(0,U.useEffect)(()=>sM(()=>{b()}),[b]);let x=(0,U.useCallback)(async t=>{s(t??`all`),l([]);let n=e=>l(t=>{let n=t.find(t=>t.event.sourceId===e.sourceId),r={event:e,imported:e.phase===`checking`||e.phase===`finished`?n?.imported??null:e,chunks:e.phase===`committed`&&e.chunkId!==null?[...n?.chunks??[],e.chunkId]:n?.chunks??[]};return n?t.map(t=>t.event.sourceId===e.sourceId?r:t):[...t,r]});try{S3(t?await hM(t,{force:!0,onProgress:n}):await pM({force:!0,onProgress:n}),t?e?.sources.find(e=>e.id===t)?.label??t:`All sources`),await b()}finally{s(null)}},[b,e]),C=(0,U.useCallback)(async(e,t,n)=>{_j(e,t,n),n?await x(e):await b()},[x,b]),w=(0,U.useCallback)(async()=>{h(null);let e;try{e=uA(u,f)}catch(e){h(e instanceof Error?e.message:String(e));return}d(``),p(``),await x(e.id)},[u,f,x]),T=(0,U.useCallback)((e,t)=>{Sj(e,t)||Q({title:`Couldn't save Auto-sync`,description:`Browser storage is unavailable — the choice lasts this session only.`,variant:`destructive`}),b()},[b]),E=(0,U.useCallback)(async t=>{let n=e?.sources.find(e=>e.id===t)?.label??t;if(window.confirm(`Unsubscribe from "${n}"? Imported content for this feed's content is removed from your library; the source stays listed so you can subscribe again. Your own notes are never touched.`)){try{let{deleted:e}=await gM(t);Q({title:`${n} unsubscribed`,description:`${e.toLocaleString()} imported ${e===1?`item`:`items`} removed. The source stays listed for a later Subscribe.`})}catch(e){Q({title:`${n} unsubscribe failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await b()}},[e,b]),D=(0,U.useCallback)(async t=>{let n=e?.sources.find(e=>e.id===t)?.label??t;if(window.confirm(`Delete "${n}"? Imported content is removed and the source is unregistered. Your own notes are never touched.`)){try{let{deleted:e}=await Tee(t);Q({title:`${n} deleted`,description:`${e.toLocaleString()} imported ${e===1?`item`:`items`} removed and the source unregistered.`})}catch(e){Q({title:`${n} delete failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`});return}await b()}},[e,b]),O=c.at(-1)?.event;return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Ee,{className:`size-4 text-primary`}),`Content Sources`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`A feed is one published Markdown repository — its notebooks, notes, guides, dashboards, and efforts import into your active data location together. Subscribed feeds are checked against their published manifest on every load: Auto-sync applies updates by itself, otherwise you press Sync when an update is pending. The core feed imports automatically at launch and is always subscribed.`})]}),i&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs text-destructive`,"data-testid":`feed-status-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 shrink-0`}),`Couldn't read the feed status from the active storage: `,i]}),O&&(0,W.jsxs)(`div`,{className:`space-y-3 rounded-xl border border-border bg-card p-4`,"data-testid":`feed-sync-progress`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4 text-sm font-medium`,children:[(0,W.jsx)(`span`,{children:o===null?c.some(e=>e.event.phase===`finished`&&e.event.outcome===`error`)?`Sync finished with errors`:`Sync finished`:`Syncing…`}),(0,W.jsxs)(`span`,{className:`text-xs tabular-nums text-muted-foreground`,children:[`Source `,O.sourceIndex,` of `,O.totalSources]})]}),(0,W.jsxs)(`p`,{role:`status`,"aria-live":`polite`,className:`sr-only`,"data-testid":`feed-sync-live-status`,children:[O.sourceLabel,`: `,w3(O)]}),c.map(({event:e,imported:t,chunks:n})=>(0,W.jsxs)(`div`,{className:`space-y-2 border-t border-border/50 pt-3`,children:[(0,W.jsxs)(`p`,{className:`text-xs ${e.phase===`finished`&&e.outcome===`error`?`text-destructive`:`text-muted-foreground`}`,children:[(0,W.jsx)(`span`,{className:`font-medium text-foreground`,children:e.sourceLabel}),` · `,w3(e)]}),t&&t.totalChunks>0?(0,W.jsx)(H4,{value:t.completedChunks,max:t.totalChunks,label:`Chunks committed · ${e.sourceLabel}`}):e.phase===`finished`?null:(0,W.jsx)(`progress`,{"aria-label":`Checking ${e.sourceLabel}`,className:`h-2 w-full`}),t&&(0,W.jsxs)(`p`,{className:`flex flex-wrap gap-x-3 gap-y-1 text-xs tabular-nums`,"data-testid":`feed-sync-totals`,children:[(0,W.jsxs)(`span`,{children:[t.totalNotes.toLocaleString(),` notes`]}),(0,W.jsxs)(`span`,{children:[t.totalEfforts.toLocaleString(),` efforts`]}),(0,W.jsxs)(`span`,{children:[t.totalBlocks.toLocaleString(),` blocks`]}),t.skippedUserOwned>0&&(0,W.jsxs)(`span`,{children:[t.skippedUserOwned.toLocaleString(),` user-owned rows preserved`]}),t.deleted>0&&(0,W.jsxs)(`span`,{children:[t.deleted.toLocaleString(),` feed rows removed`]})]}),n.length>0&&(0,W.jsxs)(`details`,{className:`text-xs`,"data-testid":`feed-sync-chunks`,children:[(0,W.jsxs)(`summary`,{className:`cursor-pointer text-muted-foreground`,children:[`Committed chunks (`,n.length,`)`]}),(0,W.jsx)(`ul`,{className:`mt-2 max-h-32 space-y-1 overflow-y-auto font-mono text-muted-foreground`,children:n.map(e=>(0,W.jsx)(`li`,{children:e},e))})]})]},e.sourceId))]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 p-2.5 rounded-xl border border-border bg-card text-xs`,children:[(0,W.jsxs)(`label`,{className:`flex items-center gap-2 cursor-pointer select-none text-muted-foreground hover:text-foreground`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),"data-testid":`sync-subscribed-only-toggle`,className:`size-3.5 accent-primary rounded`}),(0,W.jsx)(`span`,{className:`font-medium text-foreground`,children:`Subscribed only`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Source:`}),(0,W.jsxs)(`select`,{value:v??``,onChange:e=>y(e.target.value?e.target.value:void 0),"data-testid":`sync-feed-source-filter`,"aria-label":`Filter notebooks by feed`,className:`h-8 rounded-md border border-border bg-background px-2 text-xs text-foreground outline-none transition-colors hover:border-foreground/25 focus:border-primary/50`,children:[(0,W.jsx)(`option`,{value:``,children:`All feeds`}),e?.sources.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.label},e.id))]})]})]}),(0,W.jsxs)(`div`,{className:`grid gap-3`,"data-testid":`feed-source-list`,children:[e?.sources.filter(e=>{if(v&&e.id!==v)return!1;if(g){let t=e.notebooks.some(e=>e.subscribed);if(!e.subscribed&&!t)return!1}return!0}).map(e=>(0,W.jsx)(T3,{source:e,running:o===e.id||o===`all`,disabled:o!==null,onSync:e=>{x(e)},onSubscribe:e=>{x(e)},onUnsubscribe:e=>{E(e)},onDelete:e=>{D(e)},onAutoSync:T,onToggleNotebook:C,subscribedOnly:g},e.id)),n&&e===null&&(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,children:`Checking sources…`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between pt-3 border-t border-border/50`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Sync re-applies every published chunk. Your own notes, results, and edits are never overwritten.`}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>{x(null)},disabled:o!==null||n,"data-testid":`feed-resync-button`,className:`gap-2`,children:[(0,W.jsx)(zt,{className:`size-3.5 ${o===`all`?`animate-spin`:``}`}),(0,W.jsx)(`span`,{children:o===`all`?`Syncing all…`:`Sync All Sources`})]})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(S,{className:`size-4 text-primary`}),`Add a Source`]}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Register any URL serving a Wod Wiki feed (a directory with `,(0,W.jsx)(`code`,{children:`manifest.json`}),` and`,` `,(0,W.jsx)(`code`,{children:`chunks/`}),`) — a community library mirror or one you compiled yourself. The host must allow cross-origin reads (CORS). Added sources sync immediately and start subscribed; manage Auto-sync, Unsubscribe, and Delete on each source card above.`]})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-3`,"data-testid":`feed-add-source-form`,children:[(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`feed-source-label`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Label`}),(0,W.jsx)(y3,{id:`feed-source-label`,value:u,onChange:e=>d(e.target.value),placeholder:`My library (optional — defaults to the host name)`,disabled:o!==null})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`feed-source-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Feed directory URL`}),(0,W.jsx)(y3,{id:`feed-source-url`,type:`text`,autoComplete:`off`,spellCheck:!1,value:f,onChange:e=>p(e.target.value),placeholder:`https://example.com/feed/library/`,className:`font-mono`,disabled:o!==null})]})]}),m&&(0,W.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`feed-add-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:m})]}),(0,W.jsx)(`div`,{className:`flex justify-end`,children:(0,W.jsxs)(K,{size:`sm`,onClick:()=>{w()},disabled:o!==null||!f.trim(),"data-testid":`feed-add-button`,className:`gap-2`,children:[(0,W.jsx)(On,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Add & Sync`})]})})]})]})]})}function D3({open:e,onOpenChange:t}){return(0,W.jsx)(d3,{open:e,onOpenChange:t,children:(0,W.jsxs)(m3,{className:`max-h-[85vh] w-full max-w-2xl overflow-y-auto`,"data-testid":`notebook-manage-drawer`,children:[(0,W.jsxs)(h3,{children:[(0,W.jsx)(g3,{children:`Feed Subscriptions & Local Libraries`}),(0,W.jsx)(_3,{children:`Manage the feeds stored in your active data location — compare versions, sync updates, and subscribe, unsubscribe, or delete feeds. One Subscribe imports every notebook a feed publishes. Your own notes are never touched.`})]}),(0,W.jsx)(E3,{})]})})}var O3={stream:`cards`,table:`rows`},k3=`wodwiki.viewSettings.v1`,A3={"/notebooks":`/catalogs`,"/notes":`/feeds`,"/sessions":`/results`,"/dashboards":`/dashboard`},j3={"/notes":`/collections`},M3={"/feeds":`/feeds@2`};function N3(e){let t=e.startsWith(`/`)?e:`/${e}`;return M3[t]??t}var P3=new gx(k3);function F3(e,t){return{level:e,layout:t??`cards`,visibleFields:gV(e),groupBy:void 0}}function I3(e,t,n=P3,r){let i=F3(t,r),a=N3(e),o=A3[a],s=n.get(a,{alias:o});if(s==null&&o&&(s=n.get(o,{alias:j3[a]})),!s)return i;let c=typeof s.layout==`string`?s.layout:``,l=c===`cards`||c===`rows`||c===`feed`?c:O3[c]??`cards`,u=new Set(hV(t).map(e=>e.id)),d=Array.isArray(s.visibleFields)?s.visibleFields.filter(e=>typeof e==`string`&&u.has(e)):i.visibleFields,f=typeof s.groupBy==`string`?s.groupBy:void 0;return{level:t,layout:l,visibleFields:d.length>0?d:i.visibleFields,groupBy:f}}function L3(e,t,n=P3){let r=N3(e);n.set(r,{level:t.level,layout:t.layout,visibleFields:t.visibleFields,groupBy:t.groupBy})}function R3(e,t,n=P3){let r=N3(e),i=A3[r],a=j3[r];return n.remove(r,i),a&&n.remove(a),F3(t)}function z3(e,t,n){let[r,i]=(0,U.useState)(()=>I3(e,t,P3,n));(0,U.useEffect)(()=>{i(I3(e,t,P3,n))},[e,t,n]);let a=(0,U.useCallback)(t=>{i(n=>{let r=t(n);return L3(e,r),r})},[e]);return{settings:r,setLayout:(0,U.useCallback)(e=>{a(t=>({...t,layout:e}))},[a]),toggleField:(0,U.useCallback)(e=>{a(t=>{let n=new Set(t.visibleFields);return n.has(e)?n.delete(e):n.add(e),{...t,visibleFields:Array.from(n)}})},[a]),setVisibleFields:(0,U.useCallback)(e=>{a(t=>({...t,visibleFields:e}))},[a]),setGroupBy:(0,U.useCallback)(e=>{a(t=>({...t,groupBy:e}))},[a]),resetSettings:(0,U.useCallback)(()=>{let n=R3(e,t);i(n)},[e,t])}}function B3(e,t=200){let[n,r]=(0,U.useState)(t),i=(0,U.useRef)(null);(0,U.useEffect)(()=>{r(t)},[e,t]);let a=n<e.length,o=(0,U.useCallback)(t=>r(n=>Math.max(n,Math.min(Math.max(t,0),e.length))),[e.length]);return(0,U.useEffect)(()=>{let n=i.current;if(!n||!a)return;let o=new IntersectionObserver(n=>{n.some(e=>e.isIntersecting)&&r(n=>Math.min(n+t,e.length))},{rootMargin:`400px`});return o.observe(n),()=>o.disconnect()},[a,e.length,t]),{visible:e.slice(0,n),hasMore:a,sentinelRef:i,total:e.length,growTo:o}}function V3(e,t){let n=X(e);return n.error||!Vm(n)?e:jh({...n,metric:t})}function H3(e){let t=X(e);return t.error?e:jh({...t,window:void 0})}function U3(e,t){let n=X(e);return n.error?e:jh({...n,groupBy:[t]})}function W3(e){return e.kind===`note`&&!e.sourceNote?!1:e.kind===`note`}async function G3(e){if(e.wodBlock?.content.trim())return e.wodBlock.content;let t=await CP.resolve(e.id),n=JH(t&&typeof t==`object`&&`rawContent`in t?String(t.rawContent??``):``),r=n.find(e=>e.dialect===`time`)??n[0];if(!r)throw Error(`No runnable workout block in this entry.`);return r.script}function K3(e,t){return{id:e.wodBlock?.blockId??e.block?.blockId??w(),contentId:e.wodBlock?.blockContentId??e.blockContentId,dialect:`time`,startLine:0,endLine:t.split(`
450
+ `).length,content:t,state:`idle`,widgetIds:{},version:1,createdAt:Date.now()}}async function q3(e,t){let n=await G3(e),r=K3(e,n),i=w();if(nU(e)){let n=await CP.getById(e.id),a=e.wodBlock||e.block?n.blocks?.[r.id]:Object.values(n.blocks??{}).find(e=>e.kind===`wod`);if(!a)throw Error(`The selected saved workout is unavailable.`);M1.set(i,{block:{...r,id:a.id},noteId:e.id,origin:`playground`,returnTo:tU(e)}),t(ON(i));return}let a=await j1({workoutName:e.title,category:e.sourceNotebook,sourceNoteLabel:e.subtitle??e.title,sourceNotePath:tU(e),wodContent:n}),o=Object.values(a.blocks??{}).find(e=>e.kind===`wod`);if(!o)throw Error(`The saved journal workout is unavailable.`);M1.set(i,{block:{...r,id:o.id},noteId:a.id}),t(wN(a.journalDate??``,i))}var J3={note:P,effort:se,result:qe,segment:s,event:y,dashboard:an,equipment:O,tag:M},Y3={note:`Note`,effort:`Effort`,result:`Result`,segment:`Segment`,event:`Event`,dashboard:`Dashboard`,equipment:`Equipment`,tag:`Tag`},X3={note:`bg-primary/10 text-primary group-hover:bg-primary/20`,effort:`bg-emerald-500/10 text-emerald-600 group-hover:bg-emerald-500/20`,result:`bg-sky-500/10 text-sky-600 group-hover:bg-sky-500/20`,segment:`bg-indigo-500/10 text-indigo-600 group-hover:bg-indigo-500/20`,event:`bg-indigo-500/10 text-indigo-600 group-hover:bg-indigo-500/20`,dashboard:`bg-cyan-500/10 text-cyan-600 group-hover:bg-cyan-500/20`,equipment:`bg-orange-500/10 text-orange-600 group-hover:bg-orange-500/20`,tag:`bg-violet-500/10 text-violet-600 group-hover:bg-violet-500/20`};function Z3({entry:e,leading:t,actions:n,dateLabel:r,visibleFieldIds:i,tone:a=`secondary`,onAddToToday:o,onRunStart:s,moveNotebookTargets:c,onMoveNotebook:l}){let u=Vn(),d=e.kind===`note`?e.sourceNotebook:void 0,f=!!d&&d!==`journal`&&d!==`playground`&&d!==`guides`,p=d===`playground`?vr:d===`guides`?xt:f?Qn:J3[e.kind],m=d===`playground`?`Playground`:d===`guides`?`Guide`:f?`Notebook`:Y3[e.kind],h=f?`bg-amber-500/10 text-amber-600 group-hover:bg-amber-500/20`:X3[e.kind],g=a===`primary`,_=rU(e),v=tU(e),y=i?new Set(i):null,b=!y||y.has(`date`),x=!y||y.has(`sourceNotebook`)||y.has(`protocol`)||y.has(`elapsedTime`)||y.has(`splitDuration`)||y.has(`discipline`)||y.has(`met`)||y.has(`canonicalSlug`),S=!y||y.has(`excerpt`)||y.has(`movements`)||y.has(`tags`)||y.has(`aliases`);return(0,W.jsxs)(`div`,{role:`button`,tabIndex:0,onClick:()=>u(tU(e)),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),u(tU(e)))},className:`flex items-center gap-4 px-6 py-3.5 hover:bg-muted/40 transition-colors text-left group w-full cursor-pointer ${g?`bg-primary/[0.025]`:``}`,"data-testid":`library-row-${e.kind}`,children:[t,(0,W.jsx)(`div`,{className:`flex-shrink-0 size-9 rounded-xl flex items-center justify-center transition-colors ${h}`,children:(0,W.jsx)(p,{className:`size-4`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-bold text-foreground min-w-0 basis-full sm:basis-auto sm:truncate`,children:e.title}),e.block&&(0,W.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-widest text-sky-600 border border-sky-500/40 bg-sky-500/10 rounded-full px-1.5 py-0.5`,"data-testid":`library-row-block-type`,children:e.block.dataType}),(0,W.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-widest text-muted-foreground/60 border border-border rounded-full px-1.5 py-0.5`,children:m}),e.execution?.effortSlug&&(0,W.jsx)(_n,{to:RN(e.execution.effortSlug),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),"data-testid":`library-row-effort-link`,className:`text-[9px] font-bold tracking-wide text-primary/80 hover:text-primary bg-primary/10 hover:bg-primary/20 border border-primary/20 rounded-full px-2 py-0.5 transition-colors shrink-0`,title:`View movement history for ${e.detail??e.execution.effortSlug}`,children:e.detail??e.execution.effortSlug}),_&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(_n,{to:v,"data-testid":`library-row-details-link`,className:`text-[9px] font-bold tracking-wide text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted border border-border rounded-full px-2 py-0.5 transition-colors`,title:`View notebook details`,children:`Details`}),(0,W.jsx)(_n,{to:_,"data-testid":`library-row-feed-link`,className:`text-[9px] font-bold tracking-wide text-primary/80 hover:text-primary bg-primary/10 hover:bg-primary/20 border border-primary/20 rounded-full px-2 py-0.5 transition-colors`,title:`View feed`,children:`Feed`})]}),e.subtitle&&x&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground/60 truncate`,children:e.subtitle})]}),S&&(e.block?(0,W.jsx)(`div`,{className:`mt-0.5`,"data-testid":`library-row-block-preview`,children:e.block.preview.map((e,t)=>(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate font-mono`,children:e},t))}):e.detail?(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground truncate mt-0.5`,children:e.detail}):null)]}),r&&b&&(0,W.jsx)(`span`,{className:`flex-shrink-0 text-[10px] text-muted-foreground/70 tabular-nums`,"data-testid":`library-row-date`,children:r}),n??(0,W.jsx)(Q3,{entry:e,onAddToToday:o,onRunStart:s,moveNotebookTargets:c,onMoveNotebook:l})]})}function Q3({entry:e,onAddToToday:t,onRunStart:n,moveNotebookTargets:r,onMoveNotebook:i}){let a=Vn(),o=iU(e),s=rU(e),c=aU(e)&&!!t,l=W3(e)&&!!n,u=!!i&&e.kind===`note`&&!!e.notebookId&&e.notebookId!==`notebook/journal`&&!!r?.length,d=r?.filter(t=>t.id!==e.notebookId)??[];return(0,W.jsxs)(`div`,{className:`flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(e6,{title:s?`Details`:`Open`,testId:`action-open`,onClick:()=>a(tU(e)),children:(0,W.jsx)(pn,{className:`size-3.5`})}),s&&(0,W.jsx)(e6,{title:`Notebook`,testId:`action-notebook`,onClick:()=>a(s),children:(0,W.jsx)(Qn,{className:`size-3.5`})}),c&&(0,W.jsx)(e6,{title:`Add to today`,testId:`action-add`,onClick:()=>t?.(e),children:(0,W.jsx)(On,{className:`size-3.5`})}),l&&(0,W.jsx)(e6,{title:`Run`,testId:`action-run`,onClick:()=>n?.(e),children:(0,W.jsx)(pn,{className:`size-3.5`})}),u&&d.length>0&&(0,W.jsx)($3,{targets:d,triggerTestId:`action-move`,itemTestIdPrefix:`action-move-`,triggerClassName:`size-8 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,onMove:t=>i?.(e,t)}),o&&(0,W.jsx)(e6,{title:`Compare`,testId:`action-compare`,onClick:()=>a(o),children:(0,W.jsx)($n,{className:`size-3.5`})})]})}function $3({targets:e,triggerTestId:t,itemTestIdPrefix:n,triggerClassName:r,onMove:i}){return(0,W.jsxs)(ZB,{children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,title:`Move to notebook`,"data-testid":t,className:r,children:(0,W.jsx)(Ae,{className:`size-3.5`})})}),(0,W.jsxs)($B,{align:`end`,children:[(0,W.jsx)(tV,{children:`Move to notebook`}),(0,W.jsx)(nV,{}),e.map(e=>(0,W.jsxs)(eV,{"data-testid":`${n}${e.id}`,onClick:()=>i(e.id),children:[(0,W.jsx)(`span`,{className:`w-5 text-center`,children:e.icon}),(0,W.jsx)(`span`,{className:`flex-1 truncate`,children:e.name})]},e.id))]})]})}function e6({title:e,testId:t,onClick:n,children:r}){return(0,W.jsx)(`button`,{type:`button`,title:e,onClick:n,"data-testid":t,className:`size-8 rounded-lg flex items-center justify-center text-muted-foreground hover:text-primary hover:bg-primary/10 transition-colors`,children:r})}function t6({entries:e,level:t,visibleFieldIds:n,onRowClick:r,emptyMessage:i=`No entries to display`,className:a=``,stickyHeaderTop:o}){let s=Vn(),c=(0,U.useMemo)(()=>t||(e.length>0?fV(e[0]):`note`),[t,e]),l=(0,U.useMemo)(()=>hV(c),[c]),u=(0,U.useMemo)(()=>{let e=new Set(n??gV(c));return l.filter(t=>e.has(t.id))},[l,n,c]),d=e=>{r?r(e):s(tU(e))},[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(`asc`),g=e=>{f===e?h(e=>e===`asc`?`desc`:`asc`):(p(e),h(`asc`))},_=(0,U.useMemo)(()=>{if(!f)return e;let t=l.find(e=>e.id===f);return t?[...e].sort((e,n)=>{let r=t.getValue(e),i=t.getValue(n);if(r==null&&i==null)return 0;if(r==null)return m===`asc`?1:-1;if(i==null)return m===`asc`?-1:1;if(typeof r==`number`&&typeof i==`number`)return m===`asc`?r-i:i-r;if(Array.isArray(r)&&Array.isArray(i)){let e=r.join(`, `),t=i.join(`, `);return m===`asc`?e.localeCompare(t):t.localeCompare(e)}let a=String(r),o=String(i);return m===`asc`?a.localeCompare(o):o.localeCompare(a)}):e},[e,f,m,l]);return e.length===0?(0,W.jsx)(`div`,{className:`w-full py-16 text-center text-sm text-muted-foreground ${a}`,"data-testid":`property-table-empty`,children:i}):(0,W.jsx)(`div`,{className:`w-full border-y border-border bg-card/50 ${o===void 0?`overflow-x-auto`:`overflow-x-clip`} ${a}`,"data-testid":`property-table`,children:(0,W.jsxs)(`table`,{className:`w-full text-left border-collapse text-xs`,children:[(0,W.jsx)(`thead`,{className:o===void 0?void 0:`sticky z-10`,style:o===void 0?void 0:{top:`${o}px`},children:(0,W.jsx)(`tr`,{className:`border-b border-border`,children:u.map(e=>{let t=e.align===`right`?`text-right`:e.align===`center`?`text-center`:`text-left`;return(0,W.jsx)(`th`,{scope:`col`,onClick:()=>g(e.id),className:`px-4 py-3 font-semibold uppercase tracking-wider text-[11px] text-muted-foreground whitespace-nowrap border-b border-border cursor-pointer select-none hover:text-foreground transition-colors group/th ${o===void 0?`bg-muted/30`:`bg-muted/95 backdrop-blur-sm`} ${t}`,"data-testid":`property-table-header-${e.id}`,children:(0,W.jsxs)(`div`,{className:`inline-flex items-center gap-1.5 ${t===`text-right`?`justify-end`:t===`text-center`?`justify-center`:`justify-start`}`,children:[(0,W.jsx)(`span`,{children:e.label}),f===e.id?(0,W.jsx)(`span`,{className:`text-primary font-bold text-xs`,"aria-label":m===`asc`?`sorted ascending`:`sorted descending`,children:m===`asc`?`↑`:`↓`}):(0,W.jsx)(`span`,{className:`opacity-0 group-hover/th:opacity-40 text-muted-foreground text-[10px]`,"aria-hidden":`true`,children:`↕`})]})},e.id)})})}),(0,W.jsx)(`tbody`,{className:`divide-y divide-border/60`,children:_.map(e=>{let t=rU(e),n=tU(e);return(0,W.jsx)(`tr`,{role:`button`,tabIndex:0,onClick:()=>d(e),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),d(e))},className:`hover:bg-muted/40 transition-colors cursor-pointer group`,"data-testid":`property-table-row-${e.id}`,children:u.map(r=>{let i=r.getValue(e),a=r.formatValue(i,e),o=r.align===`right`?`text-right tabular-nums`:r.align===`center`?`text-center`:`text-left`;return(0,W.jsx)(`td`,{className:`px-4 py-3 whitespace-nowrap text-foreground/90 ${o}`,"data-testid":`property-table-cell-${r.id}`,children:r.id===`pacingTier`&&e.execution?.effortSlug?(0,W.jsx)(_n,{to:RN(e.execution.effortSlug),onClick:e=>e.stopPropagation(),onKeyDown:e=>e.stopPropagation(),"data-testid":`property-table-effort-link`,className:`inline-flex items-center gap-1 rounded px-2 py-0.5 text-[11px] font-medium bg-primary/10 text-primary hover:bg-primary/20 border border-primary/20 transition-colors`,title:`View movement history for ${e.detail??e.execution.effortSlug}`,children:a}):r.id===`title`||r.id===`label`?(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-foreground group-hover:text-primary transition-colors`,children:a}),t&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 ml-auto`,onClick:e=>e.stopPropagation(),children:[(0,W.jsx)(_n,{to:n,"data-testid":`property-table-details-link`,className:`rounded px-1.5 py-0.5 text-[10px] font-semibold text-muted-foreground hover:text-foreground bg-muted/60 hover:bg-muted border border-border transition-colors`,title:`View catalog details`,children:`Details`}),(0,W.jsx)(_n,{to:t,"data-testid":`property-table-feed-link`,className:`rounded px-1.5 py-0.5 text-[10px] font-semibold bg-primary/10 text-primary hover:bg-primary/20 border border-primary/20 transition-colors`,title:`View feed`,children:`Feed`})]})]}):a},r.id)})},e.id)})})]})})}var n6={note:P,effort:se,result:qe,segment:s,event:y,dashboard:an,equipment:O,tag:M},r6={note:`Note`,effort:`Effort`,result:`Result`,segment:`Segment`,event:`Event`,dashboard:`Dashboard`,equipment:`Equipment`,tag:`Tag`},i6=8;function a6({entry:e}){let t=e.execution;if(!t)return null;let n=[];return t.elapsedMs!=null&&n.push(kz(t.elapsedMs)),t.reps!=null&&n.push(`${t.reps} reps`),t.loadLbs!=null&&n.push(`${t.loadLbs} lb`),t.distanceMeters!=null&&n.push(`${(t.distanceMeters/1e3).toFixed(2)} km`),t.tis!=null&&n.push(`TIS ${t.tis}`),n.length===0?null:(0,W.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-1.5`,"data-testid":`stream-feed-metrics`,children:n.map(e=>(0,W.jsx)(`span`,{className:`rounded-full bg-muted/70 border border-border/60 px-2 py-0.5 text-[10px] font-bold tabular-nums text-muted-foreground`,children:e},e))})}function o6({entry:e}){let[t,n]=(0,U.useState)(!1),r=e.wodBlock?.content.trim(),i=r?r.split(`
451
451
  `):e.excerpt??e.block?.preview??[],a=i.length>i6,o=t||!a?i:i.slice(0,i6);return i.length===0&&!e.detail?null:(0,W.jsxs)(`div`,{className:`mt-1.5`,"data-testid":`stream-feed-preview`,children:[i.length>0&&(0,W.jsx)(`pre`,{className:`whitespace-pre-wrap break-words font-mono text-[11px] leading-relaxed text-muted-foreground ${a&&!t?`max-h-40 overflow-hidden`:``}`,children:o.join(`
452
452
  `)}),i.length===0&&e.detail&&(0,W.jsx)(`p`,{className:`text-[11px] text-muted-foreground`,children:e.detail}),a&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>n(e=>!e),"data-testid":`stream-feed-preview-toggle`,className:`mt-1 min-h-[44px] px-2 -ml-2 text-[10px] font-black uppercase tracking-widest text-primary hover:text-primary/80 transition-colors`,children:t?`Show less`:`Show more (${i.length-i6} lines)`})]})}function s6({groups:e,batch:t,onRunEntry:n,onSendToPlayground:r,onAddToToday:i,moveNotebookTargets:a,onMoveNotebook:o,stickyOffset:s}){return(0,W.jsxs)(`div`,{className:`flex-1 divide-y divide-border/40`,"data-testid":`stream-feed`,children:[e.map(e=>(0,W.jsxs)(`section`,{id:e.id,"data-testid":`stream-feed-group-${e.key}`,children:[(0,W.jsx)(BB,{top:s,icon:(0,W.jsx)(mn,{className:`size-3 shrink-0 text-muted-foreground`}),label:e.label,badge:e.isToday?(0,W.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-primary`,children:`Today`}):void 0,meta:`${e.entries.length} ${e.entries.length===1?`entry`:`entries`}`}),(0,W.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.entries.map(e=>{let t=e.kind===`note`?e.sourceNotebook:void 0,s=!!t&&t!==`journal`&&t!==`playground`&&t!==`guides`,c=t===`playground`?vr:t===`guides`?xt:s?Qn:n6[e.kind],l=t===`playground`?`Playground`:t===`guides`?`Guide`:s?`Notebook`:r6[e.kind],u=tU(e),d=rU(e),f=!nU(e)&&e.kind===`note`,p=aU(e)&&!!i,m=a?.filter(t=>t.id!==e.notebookId)??[],h=!!o&&e.kind===`note`&&!!e.notebookId&&e.notebookId!==`notebook/journal`&&m.length>0;return(0,W.jsx)(`article`,{"data-testid":`stream-feed-item`,className:`px-6 py-4`,children:(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`div`,{className:`flex-shrink-0 size-9 rounded-xl bg-primary/10 flex items-center justify-center`,children:(0,W.jsx)(c,{className:`size-4 text-primary`})}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,W.jsx)(`h3`,{className:`text-sm font-bold text-foreground min-w-0 basis-full sm:basis-auto sm:truncate`,children:(0,W.jsx)(_n,{to:u,className:`hover:text-primary transition-colors`,children:e.title})}),(0,W.jsx)(`span`,{className:`text-[9px] font-black uppercase tracking-widest text-muted-foreground/60 border border-border rounded-full px-1.5 py-0.5`,children:l}),e.subtitle&&(0,W.jsx)(`span`,{className:`text-[10px] text-muted-foreground/70 truncate`,children:e.subtitle})]}),(0,W.jsx)(o6,{entry:e}),(0,W.jsx)(a6,{entry:e}),(0,W.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(_n,{to:u,"data-testid":`stream-feed-open`,className:`inline-flex min-h-[44px] items-center rounded-full border border-border px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground hover:text-primary hover:border-primary/50 transition-colors`,children:d?`Details`:`Open`}),d&&(0,W.jsxs)(_n,{to:d,"data-testid":`stream-feed-collection-feed`,className:`inline-flex min-h-[44px] items-center gap-1.5 rounded-full bg-primary/10 border border-primary/30 px-3 text-[10px] font-black uppercase tracking-widest text-primary hover:bg-primary/20 transition-colors`,children:[(0,W.jsx)(Qn,{className:`size-3`}),`Feed`]}),W3(e)&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e),"data-testid":`stream-feed-run`,className:`inline-flex min-h-[44px] items-center gap-1.5 rounded-full bg-primary/10 border border-primary/30 px-3 text-[10px] font-black uppercase tracking-widest text-primary hover:bg-primary/20 transition-colors`,children:[(0,W.jsx)(pn,{className:`size-3`}),`Run`]}),f&&r&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e),"data-testid":`stream-feed-playground`,className:`inline-flex min-h-[44px] items-center gap-1.5 rounded-full border border-border px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground hover:text-primary hover:border-primary/50 transition-colors`,children:[(0,W.jsx)(Ut,{className:`size-3`}),`Playground`]}),p&&(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i?.(e),"data-testid":`stream-feed-add`,className:`inline-flex min-h-[44px] items-center gap-1.5 rounded-full border border-border px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground hover:text-primary hover:border-primary/50 transition-colors`,children:[(0,W.jsx)(On,{className:`size-3`}),`Add`]}),h&&(0,W.jsx)($3,{targets:m,triggerTestId:`stream-feed-move`,itemTestIdPrefix:`stream-feed-move-`,triggerClassName:`inline-flex min-h-[44px] items-center gap-1.5 rounded-full border border-border px-3 text-[10px] font-black uppercase tracking-widest text-muted-foreground hover:text-primary hover:border-primary/50 transition-colors`,onMove:t=>o?.(e,t)})]})]})]})},e.id)})})]},e.id)),t.hasMore&&(0,W.jsxs)(`div`,{ref:t.sentinelRef,className:`px-6 py-4 text-center text-xs text-muted-foreground/60`,"data-testid":`stream-feed-load-more`,children:[`Loading more — `,t.total-t.visible.length,` remaining…`]})]})}function c6(e,t,n){return{journalDate:n,title:e.title,rawContent:t,sourceId:e.sourceId,type:`journal`}}var l6=/\[([^\]]*)\]\((:[^)]*)\)!/g;function u6(e){let t=e.trim();return _F((()=>{try{return decodeURIComponent(t)}catch{return t}})())}function d6(e){let t=u6(e);return t.startsWith(`:`)&&!X(t).error}function f6(e){let t=[],n=0;for(let r of e.matchAll(l6)){let i=r.index??0,a=u6(r[2]);d6(a)&&(i>n&&t.push({kind:`markdown`,text:e.slice(n,i)}),t.push({kind:`query`,query:a.trim(),heading:r[1]}),n=i+r[0].length)}n<e.length&&t.push({kind:`markdown`,text:e.slice(n)});let r=[];for(let e of t){let t=r[r.length-1];e.kind===`markdown`&&t?.kind===`markdown`?t.text+=e.text:r.push(e)}return r}function p6(e){return e.some(e=>e.kind===`query`)}var m6=`9999-12-31`;function h6(e,t){return(e.date??m6).localeCompare(t.date??m6)||e.title.localeCompare(t.title,void 0,{numeric:!0,sensitivity:`base`})}function g6(e){let t=new Date(`${e}T12:00:00`);return Number.isNaN(t.getTime())?e:t.toLocaleDateString(`en-US`,{weekday:`short`,month:`short`,day:`numeric`,year:`numeric`})}function _6({query:e,heading:t,onAddToToday:n,onRunStart:r}){let[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null);(0,U.useEffect)(()=>{let t=!1;return a(null),s(null),Bz.query(e).then(e=>{t||a([...e].sort(h6))}).catch(e=>{t||s(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]);let c=(0,U.useMemo)(()=>{if(!i)return null;let t=X(e);if(t.error||!(`groupBy`in t)||!t.groupBy?.includes(`date`))return null;let n=new Map;for(let e of i){let t=e.date??``,r=n.get(t);r?r.push(e):n.set(t,[e])}return[...n.entries()]},[i,e]);if(o)return(0,W.jsxs)(`p`,{className:`my-3 text-xs text-destructive`,"data-testid":`readme-query-error`,children:[`Query failed: `,o]});if(i===null)return(0,W.jsx)(`div`,{className:`my-3 text-xs text-muted-foreground/60`,"data-testid":`readme-query-loading`,children:`Loading…`});if(i.length===0)return(0,W.jsx)(`p`,{className:`my-3 text-xs text-muted-foreground/60`,"data-testid":`readme-query-empty`,children:`No entries match this query.`});let l=e=>(0,W.jsx)(Z3,{entry:e,onAddToToday:n,onRunStart:r},e.id);return(0,W.jsxs)(`div`,{className:`my-3 not-prose`,"data-testid":`readme-query-block`,children:[t&&(0,W.jsx)(`p`,{className:`mt-4 mb-1 text-sm font-bold text-foreground`,"data-testid":`readme-query-heading`,children:t}),c?c.map(([e,t])=>(0,W.jsxs)(`div`,{className:`mt-3`,"data-testid":`readme-query-date-group`,children:[(0,W.jsx)(`p`,{className:`mb-1 text-xs font-semibold uppercase tracking-wider text-muted-foreground`,children:e?g6(e):`Undated`}),(0,W.jsx)(`div`,{className:`divide-y divide-border/40`,children:t.map(l)})]},e||`undated`)):(0,W.jsx)(`div`,{className:`divide-y divide-border/40`,children:i.map(l)})]})}var v6=new Kk;function y6({batch:e,testId:t=`stream-load-more`}){return e.hasMore?(0,W.jsxs)(`div`,{ref:e.sentinelRef,className:`px-6 py-4 text-center text-xs text-muted-foreground/60`,"data-testid":t,children:[`Loading more — `,e.total-e.visible.length,` remaining…`]}):null}var b6=150;function x6(e){switch(e.phase){case`checking`:return`Checking ${e.sourceLabel}…`;case`fetching`:return`Downloading ${e.chunkId??`library`}…`;case`applying`:return`Importing ${e.chunkId??`library`}…`;case`committed`:return`Committed ${e.chunkId??`chunk`}`;case`finalizing`:return`Finalizing checkpoints…`;case`finished`:return e.error??C3[e.outcome]}}function S6(e){return`${e.negate?`!`:``}${e.key}=${e.values.map(e=>`${e.wildcard?`*`:``}${e.value}`).sort().join(`|`)}`}function C6(e,t){let n={};for(let e of t){let t=S6(e);n[t]=(n[t]??0)+1}return e.filter(e=>{let t=S6(e),r=n[t]??0;return n[t]=r-1,r<=0})}function w6({error:e,target:t,matched:n,total:r,loading:i,applied:a,ignored:o,advisories:s,groupDims:c,groupingSource:l}){return(0,W.jsxs)(`div`,{role:`status`,"data-testid":`stream-query-status`,className:`flex flex-wrap items-center gap-x-2 gap-y-0.5 text-[11px] text-muted-foreground`,children:[e?(0,W.jsx)(`span`,{className:`font-semibold text-destructive`,children:`Invalid query — showing previous results`}):t?(0,W.jsxs)(`span`,{className:`font-mono`,children:[`:`,t]}):null,(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,W.jsxs)(`span`,{"data-testid":`stream-query-counts`,className:i?`motion-safe:animate-pulse`:void 0,children:[n,` of `,r]}),(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,W.jsxs)(`span`,{"data-testid":`stream-query-filters`,children:[a,` applied`,o>0?`, ${o} ignored`:``]}),(0,W.jsx)(`span`,{"aria-hidden":`true`,children:`·`}),(0,W.jsxs)(`span`,{children:[`by `,c.join(`, `),` `,(0,W.jsxs)(`span`,{className:`text-muted-foreground/60`,children:[`(`,l,`)`]})]}),s.map(e=>(0,W.jsx)(`p`,{className:`w-full break-words text-amber-700 dark:text-amber-400`,children:e},e))]})}function T6({profile:e,actions:t,queryEngine:n,onAddToToday:r,registerStreamDraft:i}){let a=Vn(),o=Sn(),s=N4(),c=R4(),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(!1),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),_=(0,U.useSyncExternalStore)(yj,()=>Xj().filter(e=>e.autoImport===!1&&mj(e.id)).map(e=>e.id).join(`
453
453
  `)),v=(0,U.useMemo)(()=>_?_.split(`
454
454
  `):[],[_]),{query:y,setQuery:b,urlQueryError:x}=YM({defaultQuery:e.defaultWql,legacy:e.legacy});(0,U.useEffect)(()=>i?.(()=>y),[i,y]);let{settings:S,setLayout:C,toggleField:w,setGroupBy:T}=z3(e.route,e.level,e.defaultLayout),E=$4(e.route),[D,O]=(0,U.useState)(!1),[k,A]=(0,U.useState)([]),[j,M]=(0,U.useState)(void 0),[N,P]=(0,U.useState)(null),[F,L]=(0,U.useState)(!0),[ee,te]=(0,U.useState)(!1),[ne,R]=(0,U.useState)(null),re=TV(),ie=GB(),ae=e.route===`/notebooks`,oe=(0,U.useMemo)(()=>ae&&new URLSearchParams(o.search).get(`manage`)===`1`,[ae,o.search]),se=(0,U.useCallback)(e=>{let t=new URLSearchParams(o.search);e?t.set(`manage`,`1`):t.delete(`manage`);let n=t.toString();a({pathname:o.pathname,search:n?`?${n}`:``},{replace:!e})},[a,o.pathname,o.search]),ce=ae?(0,W.jsx)(D3,{open:oe,onOpenChange:se}):null,le=(0,U.useCallback)(()=>{ae?se(!0):a($.settingsSync)},[ae,se,a]),[z,ue]=(0,U.useState)(!1),de=(0,U.useCallback)(async(e,t,n)=>{let r=await zA.create(e,t,n);return Oe(e=>e+1),r},[]),fe=ae?(0,W.jsx)(B4,{open:z,onOpenChange:ue,onCreate:de}):null,B=(0,U.useMemo)(()=>X(y),[y]),pe=(0,U.useMemo)(()=>B.error||Hm(B)?!1:B.filters.some(e=>e.key===`source`&&!e.negate&&e.values.some(e=>e.value===`playground`)),[B]),me=(0,U.useMemo)(()=>{if(e.notebookSlug)return e.notebookSlug;if(e.route.startsWith(`/notebook/`)){let t=e.route.slice(3);if(t&&!t.includes(`/`))return t}if(!B.error&&Bm(B)){let e=B.filters.find(e=>e.key===`notebook`&&!e.negate)?.values[0]?.value;if(e)return Da(e)}},[e,B]),he=YO(),[ge,_e]=(0,U.useState)(null),ve=(0,U.useMemo)(()=>ge?f6(ge):[],[ge]),ye=p6(ve);(0,U.useEffect)(()=>{if(!me){_e(null);return}let e=`markdown/notebooks/${me}/README.md`,t=he?.[e];t&&_e(t.replace(/\{\{workouts\}\}/g,``).trim());let n=!1;return _y(e).then(async e=>{try{let t=await v6.getRecord(e);!n&&t?.rawContent&&_e(t.rawContent.replace(/\{\{workouts\}\}/g,``).trim())}catch{}}),()=>{n=!0}},[me,he]);let be=(0,U.useMemo)(()=>{let e=n??Bz;return S.layout===`feed`?e.withNoteBlockInfo():e},[n,S.layout]),xe=(0,U.useCallback)(async e=>{let t=YH(),n=``,r=e.kind===`result`||e.kind===`segment`?e.execution?.noteId:e.kind===`note`?e.sourceNote:e.id;if(r){if(e.kind===`segment`&&e.blockContentId){let t=(await sz.runFind({raw:`:block{note:${r}}`,target:`block`,filters:[{key:`note`,negate:!1,values:[{value:r,wildcard:!1}]}]})).blocks.find(t=>t.id===e.blockContentId);t?.rawContent&&(n=t.rawContent)}if(!n&&(e.kind===`note`||e.kind===`result`||e.kind===`segment`)){let e=await CP.getById(r);e&&typeof e==`object`&&`rawContent`in e&&typeof e.rawContent==`string`&&(n=e.rawContent)}if(!n&&e.kind!==`note`){let e=await sz.runFind({raw:`:block{note:${r}}`,target:`block`,filters:[{key:`note`,negate:!1,values:[{value:r,wildcard:!1}]}]});e.blocks.length>0&&(n=[...e.blocks].sort((e,t)=>(e.position??0)-(t.position??0)).filter(e=>e.rawContent.trim()!==``).map(e=>e.dataType===`frontmatter`?`---\n${e.rawContent}\n---`:e.rawContent).join(`
455
455
 
456
- `))}}let i=c6(e,n,t);await CP.create(i)},[]),Se=r??xe,Ce=(0,U.useCallback)(async e=>{R(null);try{await q3(e,a)}catch(e){R(e instanceof Error?e.message:`Could not start the workout.`)}},[a]),we=(0,U.useCallback)(async e=>{R(null);try{let t=await CP.resolve(e.id),{routeId:n}=await xq(t&&typeof t==`object`&&`rawContent`in t?String(t.rawContent??``):``,{title:e.title});a(SN(n.replace(/^playground\//,``)))}catch(e){R(e instanceof Error?e.message:`Could not create the playground entry.`)}},[a]),Te=(0,U.useCallback)(e=>Bm(e)?sz.runFind(e):sz.runQuery(e.raw),[]),[De,Oe]=(0,U.useState)(0),[ke,Ae]=(0,U.useState)([]);(0,U.useEffect)(()=>{let e=!1;return zA.getAllNotebooks().then(t=>{e||Ae(t.filter(e=>e.origin===`user`||e.origin==="default").filter(e=>e.slug!==`guides`&&e.slug!==`playground`).map(e=>({id:e.notebookId,name:e.name,icon:e.icon})))}).catch(()=>void 0),()=>{e=!0}},[De]);let je=(0,U.useCallback)(async(e,t)=>{if(e)try{await zA.moveNote(e,t),Oe(e=>e+1)}catch(e){R(e instanceof Error?e.message:String(e))}},[]);(0,U.useEffect)(()=>tK(()=>Oe(e=>e+1)),[]),(0,U.useEffect)(()=>{if(!(!(`target`in B)||B.target!==`effort`))return vO(()=>Oe(e=>e+1))},[B]),(0,U.useEffect)(()=>{let e=zx().result?.id??-1;return Bx(()=>{let t=zx().result?.id??-1;t!==e&&(e=t,Oe(e=>e+1))})},[]);let Me=(0,U.useCallback)(async()=>{let e=Xj().filter(e=>e.autoImport===!1&&v.includes(e.id));if(e.length===0){le();return}f(!0),g(null),m(null);try{let t=0,n=0,r=[];for(let i of e){let e=await hM(i.id,{onProgress:m});e===`imported`?(t+=1,u(!0),Oe(e=>e+1)):e===`current`||e===`server-stale`?(n+=1,u(!0)):r.push(`${i.label}: ${C3[e]}`)}r.length>0&&g(r.join(` — `)),t>0?Q({title:t===e.length?`Libraries synced`:`${t} of ${e.length} libraries synced`,description:`Content was imported from the published seeds. Your own edits were kept.`}):n>0&&r.length===0&&Q({title:`Everything is up to date`,description:`All your subscribed libraries already match their published versions.`})}finally{f(!1)}},[v,le]);(0,U.useEffect)(()=>{if(s===`preparing`)return;if(B.error){te(!1);return}let e=!1,t=setTimeout(()=>{te(!0),M(void 0),be.query(y,t=>{e||M(t)}).then(t=>{e||(A(t),P(G4(y,B)),cI({pathname:o.pathname,query:y,entries:t}))}).catch(()=>{e||(A([]),cI({pathname:o.pathname,query:y,entries:[]}))}).finally(()=>{e||te(!1)})},b6);return()=>{e=!0,clearTimeout(t)}},[y,be,B,o.pathname,s,De]);let Ne=(0,U.useMemo)(()=>{if(N?.length)return N;if(S.groupBy)return[S.groupBy];let t=Tm(B.error||!Bm(B)?e.level===`effort`?`effort`:`note`:B.target,`find`);return[aF(e.groupByOptions,t,e.level===`effort`?`discipline`:`date`)]},[N,S.groupBy,e.level,e.groupByOptions,B]),Pe=N?.length?`query`:S.groupBy?`view`:e.groupByOptions?.length?`favorite`:`level`,Fe=(0,U.useMemo)(()=>new Set(B.error||!Bm(B)?[]:wm(B.target,`find`)),[B]),Ie=B.error||Hm(B)?0:B.filters.filter(e=>Fe.has(e.key)).length,Le=(B.error||Hm(B)?0:B.filters.length)-Ie,Re=e.shelfVisible&&!pe,ze=(0,U.useMemo)(()=>q4(k,Ne,{shelfVisible:Re}),[k,Ne,Re]),Be=B3(k),{visible:Ve,growTo:He}=Be,Ue=(0,U.useMemo)(()=>q4(Ve,Ne,{shelfVisible:Re}),[Ve,Ne,Re]),We=(0,U.useMemo)(()=>new Map(ze.map(e=>[e.id,e.entries.length])),[ze]),{setL3Items:Ge,scrollToSection:Ke,navState:qe,setStreamControls:Je}=WM();(0,U.useEffect)(()=>{if(ze.length===0){Ge([]);return}let e=ze.map(e=>({id:e.id,label:e.label,level:3,action:{type:`scroll`,sectionId:e.id}}));return Ge(e),()=>Ge([])},[ze,Ge]);let Ye=(0,U.useMemo)(()=>iF(Tm(B.error||!Bm(B)?e.level===`effort`?`effort`:`note`:B.target,`find`),e.groupByOptions),[B,e.level,e.groupByOptions]),Xe=(0,U.useCallback)(e=>{let t=U3(y,e);t===y?T(e):b(t)},[y,b,T]),Ze=(0,U.useCallback)(e=>{let t=Ne.some(t=>t.toLowerCase()===e.toLowerCase()),n=kI(y,e,!t);b(n);let r=X(n);!r.error&&Bm(r)&&Xe(r.groupBy?.[0]??``)},[Ne,y,b,Xe]);(0,U.useEffect)(()=>(Je?.({query:y,onQueryChange:b,groupDims:Ne,onToggleGroupDim:Ze,availableGroupDims:Ye,settings:S,onLayoutChange:C,onToggleField:w,level:e.level,...E?{onOpenQuerySettings:()=>O(!0)}:{}}),()=>Je?.(null)),[y,b,Ne,Ze,Ye,Je,S,C,w,e.level,E]);let Qe=`activeL3Id`in qe&&typeof qe.activeL3Id==`string`?qe.activeL3Id:null,$e=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=Qe;if(!e||$e.current===e||document.getElementById(e))return;let t=ze.find(t=>t.id===e);if(!t)return;$e.current=e;let n=t.entries[t.entries.length-1],r=n?k.findIndex(e=>e.id===n.id):-1;He(r>=0?r+1:k.length)},[Qe,ze,k,He]),(0,U.useEffect)(()=>{let e=$e.current;!e||!document.getElementById(e)||($e.current=null,Ke(e))},[Ue,Ke]);let et=zB(104),tt=B.error&&y!==e.defaultWql?B.error:null,nt=x??tt,rt=(0,U.useMemo)(()=>{let t=X(e.defaultWql);return!t.error&&Bm(t)?t.filters:[]},[e.defaultWql]),it=e.feedNotice===!0&&c===!0&&!l,at=(0,U.useMemo)(()=>{let e=[];if(it)return e.push({id:`browse-libraries`,label:`Browse libraries`,apply:le}),e;if(!B.error&&B.advisories?.length&&e.push({id:`edit-query`,label:`Edit query`,apply:()=>U4(y,Te,b)}),!B.error&&B.window){let t=B.window,n=t.kind===`relative`?`last ${t.size}${t.unit}`:`from ${t.start}${t.end?` to ${t.end}`:``}`;e.push({id:`remove-window`,label:`Remove time window (${n})`,apply:()=>b(H3(y))})}if(!B.error&&Bm(B)){let t=C6(B.filters,rt);if(t.length>0){let n=new Set(t.map(S6)),r=B.filters.filter(e=>!n.has(S6(e)));e.push({id:`clear-filters`,label:t.length===1?`Clear filter`:`Clear filters (${t.length})`,apply:()=>b(jh({...B,filters:r}))})}}return e},[B,y,b,Te,rt,it,le]),ot=(0,W.jsxs)(`div`,{className:`px-6 py-16 text-center text-muted-foreground flex flex-col items-center justify-center gap-3`,"data-testid":`stream-empty-state`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium`,children:it?`No ${e.title.toLowerCase()} are imported yet.`:e.emptyMessage??(B.window?`No entries found within the selected time window.`:`No entries match your search.`)}),at.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2 mt-1`,children:at.map(e=>(0,W.jsx)(K,{variant:`outline`,size:`sm`,onClick:e.apply,className:`text-xs`,children:e.label},e.id))})]}),st=!!B.error&&k.length>0;return s===`preparing`?(0,W.jsxs)(`div`,{className:`bg-card flex flex-col flex-1`,"data-testid":`stream-preparing`,role:`status`,"aria-busy":`true`,children:[ce,fe,(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-4 p-6`,children:[(0,W.jsxs)(`div`,{className:`w-full max-w-2xl space-y-3`,"aria-hidden":`true`,children:[(0,W.jsx)(`div`,{className:`h-4 w-2/3 animate-pulse rounded bg-muted`}),(0,W.jsx)(`div`,{className:`h-4 w-1/2 animate-pulse rounded bg-muted`}),(0,W.jsx)(`div`,{className:`h-4 w-3/4 animate-pulse rounded bg-muted`})]}),(0,W.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Loading library…`})]})]}):(0,W.jsxs)(`div`,{className:`bg-card flex flex-col flex-1`,"data-testid":`queriable-stream-view`,children:[ce,fe,E&&(0,W.jsx)(u3,{surface:E,open:D,onOpenChange:O}),(0,W.jsx)(NB,{className:`max-lg:hidden`,actions:(0,W.jsxs)(RV,{primary:e.route===`/efforts`?(0,W.jsxs)(K,{size:`sm`,onClick:()=>a(RN(`new`,void 0,{mode:`create`})),className:`h-9 px-2.5 text-xs gap-1.5`,"data-testid":`efforts-create-btn`,children:[(0,W.jsx)(On,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`New`})]}):ae?(0,W.jsxs)(K,{size:`sm`,onClick:()=>ue(!0),className:`h-9 px-2.5 text-xs gap-1.5`,"data-testid":`notebooks-create-button`,children:[(0,W.jsx)(On,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`New Notebook`})]}):void 0,label:`Stream actions`,children:[ae&&(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>se(!0),"data-testid":`manage-notebooks-button`,className:`h-9 gap-1.5 px-2.5 text-xs`,children:[(0,W.jsx)(Cn,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Manage Notebooks`})]}),t]}),queryBar:(0,W.jsx)(W4,{query:y,onQueryChange:b,scopeOptions:e.scopeOptions,execute:Te,defaultQuery:e.defaultWql,route:e.route})}),(0,W.jsx)(`div`,{className:`px-4 pt-2 sm:px-6 lg:px-8`,"data-testid":`stream-query-status-row`,children:(0,W.jsx)(w6,{error:nt,target:B.error?null:Bm(B)?B.target:B.family,matched:k.length,total:Math.max(j?.selected??0,k.length),loading:ee,applied:Ie,ignored:Le,advisories:B.error?[]:B.advisories??[],groupDims:Ne,groupingSource:Pe})}),e.scopeOptions.length===0&&(0,W.jsx)(`p`,{"data-testid":`route-wql-empty-options`,className:`px-4 pt-3 text-xs text-muted-foreground sm:px-6 lg:px-8`,children:`No source options are set for this route — pick a source by editing the query.`}),e.feedNotice&&c&&!l&&(0,W.jsx)(`div`,{className:`px-4 pt-3 sm:px-6 lg:px-8`,"data-testid":`feed-library-notice`,children:(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 flex flex-col sm:flex-row sm:items-center gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,W.jsxs)(`p`,{className:`text-sm font-medium text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Ee,{className:`size-4 text-primary`}),`Only the core seed is imported`]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:v.length>0?`The content for this page comes from your subscribed libraries, which have not been imported yet. Sync now to import them — or open Sync settings to add more sources (mirrors, your own libraries).`:`The content for this page comes from library sources, and none are subscribed yet. Browse the library manager to subscribe — mirrors and your own libraries both work.`}),p&&(0,W.jsxs)(`div`,{className:`space-y-1.5 pt-1`,"data-testid":`feed-library-notice-progress`,children:[(0,W.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`text-xs text-muted-foreground`,children:x6(p)}),p.phase!==`checking`&&p.phase!==`finished`?(0,W.jsx)(H4,{value:p.completedChunks,max:p.totalChunks,label:`Library import progress`,className:`max-w-sm`}):d?(0,W.jsx)(`progress`,{"aria-label":`Checking library sources`,className:`h-2 max-w-sm w-full`}):null]}),(h??(p?.phase===`finished`?p.error:null))&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,"data-testid":`feed-library-notice-error`,children:h??(p?.phase===`finished`?p.error:null)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,W.jsxs)(K,{size:`sm`,onClick:()=>void Me(),disabled:d,"data-testid":`feed-library-notice-sync`,className:`gap-2`,children:[(0,W.jsx)(zt,{className:`size-3.5 ${d?`animate-spin`:``}`}),(0,W.jsx)(`span`,{children:d?`Syncing…`:v.length>0?`Sync now`:`Browse libraries`})]}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>a($.settingsSync),"data-testid":`feed-library-notice-settings`,className:`gap-2`,children:[(0,W.jsx)(Cn,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Sync settings`})]})]})]})}),re&&ie&&(0,TC.createPortal)((0,W.jsx)(W4,{query:y,onQueryChange:b,scopeOptions:e.scopeOptions,execute:Te,defaultQuery:e.defaultWql,route:e.route,compact:!0}),ie),nt&&(0,W.jsxs)(`div`,{role:`alert`,className:`mx-6 mt-4 flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-destructive`,"data-testid":`stream-query-error`,children:[(0,W.jsx)(I,{className:`size-5 flex-shrink-0 mt-0.5`}),(0,W.jsxs)(`div`,{className:`flex-1 text-xs`,children:[(0,W.jsx)(`p`,{className:`font-bold`,children:`Query error`}),(0,W.jsx)(`p`,{className:`mt-1 font-mono text-[11px] opacity-90`,children:nt})]})]}),ne&&(0,W.jsxs)(`div`,{role:`alert`,className:`mx-6 mt-4 flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-destructive`,"data-testid":`stream-action-error`,children:[(0,W.jsx)(I,{className:`size-5 flex-shrink-0 mt-0.5`}),(0,W.jsxs)(`div`,{className:`flex-1 text-xs`,children:[(0,W.jsx)(`p`,{className:`font-bold`,children:`Action failed`}),(0,W.jsx)(`p`,{className:`mt-1 text-[11px] opacity-90`,children:ne})]}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>R(null),className:`text-[11px] font-bold uppercase tracking-wider hover:opacity-80`,"data-testid":`stream-action-error-dismiss`,children:`Dismiss`})]}),ae&&(0,W.jsx)(V4,{refreshKey:De,onChanged:()=>Oe(e=>e+1)}),ge&&(0,W.jsx)(`div`,{className:`border-b border-border/60 bg-card/20 px-6 py-4`,"data-testid":`notebook-readme-note`,children:ve.map((e,t)=>e.kind===`markdown`?(0,W.jsx)(t$,{prose:e.text},t):(0,W.jsx)(_6,{query:e.query,heading:e.heading,onAddToToday:Se,onRunStart:Ce},t))}),ye?null:S.layout===`rows`?(0,W.jsx)(`div`,{className:st?`flex-1 opacity-50 transition-opacity`:`flex-1`,children:(0,W.jsx)(t6,{entries:k,level:e.level,visibleFieldIds:S.visibleFields,stickyHeaderTop:et,emptyMessage:e.emptyMessage??`No matching records found.`})}):S.layout===`feed`?Ue.length>0?(0,W.jsx)(s6,{groups:Ue,batch:Be,stickyOffset:et,onRunEntry:Ce,onSendToPlayground:we,onAddToToday:Se,moveNotebookTargets:ke,onMoveNotebook:(e,t)=>void je(e.id,t)}):ee&&k.length===0?(0,W.jsx)(`div`,{className:`py-16 text-center text-xs text-muted-foreground/60`,"data-testid":`stream-loading`,children:`Loading…`}):k.length===0&&!ee?ot:null:(0,W.jsx)(`div`,{className:st?`flex-1 divide-y divide-border/60 opacity-50 transition-opacity`:`flex-1 divide-y divide-border/60`,children:Ue.length>0?(0,W.jsxs)(`div`,{className:`divide-y divide-border/40`,"data-testid":`stream-dated-content`,children:[Ue.map(e=>{let t=We.get(e.id)??e.entries.length;return e.key===`shelf`?(0,W.jsxs)(`div`,{id:e.id,className:`border-b border-border/60`,"data-testid":`stream-shelf`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>L(e=>!e),className:`w-full flex items-center justify-between px-6 py-2.5 bg-muted/20 hover:bg-muted/40 transition-colors text-left`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[F?(0,W.jsx)(Et,{className:`size-3.5 text-muted-foreground`}):(0,W.jsx)(wn,{className:`size-3.5 text-muted-foreground`}),(0,W.jsx)(Rss,{className:`size-3.5 text-amber-500`}),(0,W.jsx)(`span`,{className:`text-xs font-bold text-foreground`,children:e.label}),(0,W.jsx)(`span`,{className:`text-[10px] font-bold text-muted-foreground/60 bg-muted px-1.5 py-0.5 rounded-full`,children:t})]})}),F&&(0,W.jsx)(`div`,{className:`divide-y divide-border/40`,children:e.entries.map(e=>(0,W.jsx)(Z3,{entry:e,visibleFieldIds:S.visibleFields,onAddToToday:Se,onRunStart:Ce,moveNotebookTargets:ke,onMoveNotebook:(e,t)=>void je(e.id,t)},e.id))})]},e.id):(0,W.jsxs)(`div`,{id:e.id,className:`group/date`,"data-testid":`date-group-${e.key}`,children:[(0,W.jsx)(BB,{top:et,icon:(0,W.jsx)(mn,{className:`size-3.5 shrink-0 text-muted-foreground`}),label:e.label,badge:e.isToday?(0,W.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-primary`,children:`Today`}):void 0,meta:`${t} ${t===1?`entry`:`entries`}`}),(0,W.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.entries.map(t=>(0,W.jsx)(Z3,{entry:t,visibleFieldIds:S.visibleFields,tone:e.isToday?`primary`:`secondary`,onAddToToday:Se,onRunStart:Ce,moveNotebookTargets:ke,onMoveNotebook:(e,t)=>void je(e.id,t)},t.id))})]},e.id)}),(0,W.jsx)(y6,{batch:Be})]}):ee&&k.length===0?(0,W.jsx)(`div`,{className:`py-16 text-center text-xs text-muted-foreground/60`,"data-testid":`stream-loading`,children:`Loading…`}):k.length===0&&!ee?ot:null})]})}function E6(){return(0,W.jsx)(l3,{surface:Z4})}function D6({pageRoute:e,quests:t,challengeSectionMap:n,onScrollToSection:r}){let{quests:i,stepsComplete:a,totalSteps:o,isComplete:s}=Nq(e,t),[c,l]=(0,U.useState)(!1),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useRef)(null);if(o===0)return null;let p=e=>{let t=n.get(e);t&&r?.(t),l(!1)};(0,U.useEffect)(()=>{if(!c)return;let e=e=>{e.key===`Escape`&&(l(!1),u.current?.focus())},t=e=>{let t=e.relatedTarget,n=u.current?.parentElement;n&&t&&!n.contains(t)&&l(!1)},n=e=>{let t=u.current?.parentElement;t&&!t.contains(e.target)&&l(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,n),document.addEventListener(`touchstart`,n),d.current?.addEventListener(`focusout`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,n),document.removeEventListener(`touchstart`,n),d.current?.removeEventListener(`focusout`,t)}},[c]),(0,U.useEffect)(()=>()=>{f.current&&=(window.clearTimeout(f.current),null)},[]);let m=()=>{f.current&&=(window.clearTimeout(f.current),null)},h=()=>{m(),f.current=window.setTimeout(()=>l(!1),150)};return(0,W.jsxs)(`div`,{className:`relative py-1.5 shrink-0`,onPointerEnter:e=>{e.pointerType===`mouse`&&(m(),l(!0))},onPointerLeave:e=>{e.pointerType===`mouse`&&h()},children:[(0,W.jsxs)(`button`,{ref:u,type:`button`,"aria-haspopup":`menu`,"aria-expanded":c,"aria-label":`${a} of ${o} challenges complete`,title:`${a} of ${o} challenges complete`,onClick:()=>l(!0),className:`inline-flex min-h-11 items-center gap-1.5 cursor-pointer focus:outline-none select-none text-left rounded-full border border-border/70 bg-background px-3 py-1 hover:bg-muted/40 hover:border-border transition-colors shadow-sm`,children:[s?(0,W.jsx)(un,{className:`size-4 text-emerald-500`}):(0,W.jsx)(Pt,{className:`size-4 text-muted-foreground`}),(0,W.jsxs)(`span`,{className:G(`text-[10px] font-black uppercase tracking-wider`,s?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:[a,`/`,o]})]}),c&&(0,W.jsxs)(`div`,{ref:d,role:`menu`,"aria-orientation":`vertical`,className:`absolute left-0 top-full mt-1.5 w-64 rounded-xl border border-border bg-popover text-popover-foreground shadow-2xl p-3 z-50 origin-top-left before:content-[''] before:absolute before:-top-1.5 before:left-0 before:right-0 before:h-1.5 before:bg-transparent`,children:[(0,W.jsxs)(`div`,{className:`mb-2.5 pb-2 border-b border-border/60 flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h5`,{className:`text-[10px] font-black uppercase tracking-widest text-foreground`,children:`Syntax Challenges`}),(0,W.jsx)(`p`,{className:`text-[9px] text-muted-foreground mt-0.5`,children:`Click a challenge to jump to its section.`})]}),(0,W.jsxs)(`span`,{className:`text-[9px] font-black uppercase tracking-wider text-muted-foreground tabular-nums`,children:[a,`/`,o]})]}),(0,W.jsx)(`div`,{className:`flex flex-col gap-1`,children:i.map(e=>{let t=n.get(e.id);return(0,W.jsx)(v$,{quest:e,onClick:t?()=>p(e.id):void 0,disabled:!t,compact:!0,className:`border-0 bg-transparent hover:bg-muted/40`},e.id)})})]})]})}function O6(e){return(0,W.jsx)(k6,{...e},e.entry.id)}function k6({entry:e,onChange:t,registerRun:n,...r}){let[i,a]=(0,U.useState)({blocks:e.blocks??{},sourceRevision:e.sourceRevision??0}),[o,s]=(0,U.useState)(null),c=(0,U.useRef)(i.sourceRevision),l=(0,U.useRef)({rawContent:e.rawContent,...i}),u=(0,U.useCallback)(e=>{c.current=e.sourceRevision;let t=l.current,n=t.rawContent===e.rawContent&&JSON.stringify(Object.values(t.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))===JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));a(t=>({blocks:n?e.blocks:t.blocks,sourceRevision:e.sourceRevision}))},[]),d=(0,U.useCallback)(async t=>{let n=await lP.saveNote({noteId:e.id,rawContent:t.rawContent,blocks:t.blocks,expectedSourceRevision:c.current}),r={rawContent:n.rawContent,blocks:n.blocks??{},sourceRevision:n.sourceRevision??0};return u(r),r},[e.id,u]),f=B1({onSave:async e=>{await d(e)},getSnapshotKey:e=>JSON.stringify([e.rawContent,Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])])}),p=(0,U.useCallback)(e=>{let t=l.current.rawContent!==e.rawContent||JSON.stringify(Object.values(l.current.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));l.current=e,t&&f.onChange(e)},[f.onChange]);return(0,U.useEffect)(()=>(n?.(async(t,n)=>{await f.flush();let r=l.current,i=await DR({noteId:e.id,rawContent:r.rawContent,blocks:r.blocks,expectedSourceRevision:c.current},t,n);return u({rawContent:i.note.rawContent,blocks:i.note.blocks,sourceRevision:i.note.sourceRevision}),i}),()=>n?.(null)),[e.id,n,f.flush,u]),(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(YZ,{...r,noteId:e.id,value:o??e.rawContent,noteBlocks:i.blocks,sourceRevision:i.sourceRevision,onIdentityChange:p,onSaved:u,beforeRun:async()=>(await f.flush(),c.current),onSaveRequest:f.flush,onChange:e=>{s(null),t(e)},onBlur:f.onBlur,onCursorPositionChange:f.onLineChange,onCommitChange:f.flush}),f.error?(0,W.jsxs)(`p`,{role:`alert`,children:[`Save failed. `,f.error instanceof Error?f.error.message:String(f.error),` Your draft is kept.`]}):null,(0,W.jsx)(iR,{noteId:e.id,blocks:i.blocks,sourceRevision:i.sourceRevision,onRevert:async e=>{await f.flush();let n=rR({...l.current,sourceRevision:c.current},e),r=await d(n);l.current=r,s(n.rawContent),t(n.rawContent)}})]})}var A6=new Kk;function j6({journalDate:e,theme:t,onViewCreated:n}){let[r,i]=(0,U.useState)(null),[a,o]=cn(),s=Vn(),[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)(null),b=(0,U.useRef)(null);b.current=v;let x=(0,U.useRef)(null),S=(0,U.useRef)(!1),C=(0,U.useRef)(null),T=(0,U.useRef)(null),E=(0,U.useRef)(new Map),[D,O]=(0,U.useState)(null),k=(0,U.useCallback)(async()=>{let e=b.current;if(e)return e.block;let t=C.current;if(!t||!m)throw Error(`The pending workout is unavailable.`);return t.captured?(T.current=t.captured,t.captured.block):(T.current||=t.snapshot?await DR(t.snapshot,t.block,m,t.origin):await OR(t.noteId,t.block,m,t.origin),T.current.block)},[m]),[A,j]=(0,U.useState)({}),M=(0,U.useCallback)((e,t)=>{j(n=>n[e]===t?n:{...n,[e]:t})},[]),N=(0,U.useRef)(new Map),P=(0,U.useRef)(null),[F,I]=(0,U.useState)(null),L=(0,U.useCallback)((e,t)=>{N.current.set(e,t),P.current||(P.current=t,I(t),n?.(t))},[n]),ee=a.get(`note`);(0,U.useEffect)(()=>{if(!ee||!r)return;let e=document.getElementById(`note-${ee}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[ee,r]);let te=a.toString();(0,U.useEffect)(()=>{let e=new URLSearchParams(te).get(`autoStart`);if(!e)return;let t=W1.get(e);t&&(W1.delete(e),C.current=t,T.current=null,x.current={runtimeId:e,block:t.block,noteId:t.noteId,captured:t.captured},S.current=!1,p(t.block),h(e),_(t.noteId),d(!0)),o(e=>(e.delete(`autoStart`),e),{replace:!0})},[te,o]),(0,U.useEffect)(()=>{if(u)return;let t=J1(e);t&&(y(t),C.current={block:t.block,noteId:t.noteId,captured:t.captured},T.current=t.captured??null,x.current={runtimeId:t.runtimeId,block:t.block,noteId:t.noteId,captured:t.captured},p(t.block),h(t.runtimeId),_(t.noteId),d(!0))},[e,u]);let ne=(0,U.useCallback)((e,t)=>{i(n=>n?.map(n=>n.id===e?{...n,rawContent:t}:n)??n)},[]),R=(0,U.useCallback)((e,t,n,r,i)=>{if(!t)return Promise.reject(Error(`This run produced no results to save.`));if(n)return Promise.resolve();let a=T.current;if(!a)return Promise.reject(Error(`The saved run pin is unavailable.`));S.current=!0,Y1(a.session.id);let o=a.session.id,s=N.current.get(a.session.noteId);if(s&&!s.state.doc.toString().includes(ED(o))){let e=DD(s.state,a.session.blockId,o);e&&s.dispatch({changes:e})}return iK.record({blockId:a.session.blockId,noteId:a.session.noteId,resultId:o,data:t,createdAt:t.endTime})},[]);(0,U.useEffect)(()=>{let t=!1;return CP.listByDate(e).then(e=>{t||i(e)}).catch(()=>{t||i([])}),()=>{t=!0}},[e]);let re=/^\d{4}-\d{2}-\d{2}$/.test(e),ie=(0,U.useMemo)(()=>{if(!re)return null;let[t,n,r]=e.split(`-`).map(Number);return{prev:gP(new Date(t,n-1,r-1)),next:gP(new Date(t,n-1,r+1))}},[e,re]),{setL3Items:ae}=WM(),[oe,se]=(0,U.useState)({}),ce=r?.map(e=>e.id).join(`|`)??``,le=(0,U.useMemo)(()=>ce?ce.split(`|`):[],[ce]);(0,U.useEffect)(()=>{if(le.length===0)return;let e=!1;for(let t of le)Z.getSessionsForNote(t).then(n=>{e||se(e=>({...e,[t]:n}))}).catch(()=>{});return()=>{e=!0}},[le]),(0,U.useEffect)(()=>tK(e=>{Z.getSessionsForNote(e.noteId).then(t=>{se(n=>({...n,[e.noteId]:t}))}).catch(()=>{})}),[]);let z=r!==null&&r.length===1?r[0]:null,ue=z?oe[z.id]:void 0,de=(0,U.useCallback)(async(t,n)=>{try{let r=E.current.get(t);if(!r)throw Error(`The saved note editor is unavailable.`);let i=w(),a=await r(n,i);W1.set(i,{noteId:t,block:a.block,captured:a,returnTo:CN(e)}),s(ON(i))}catch(e){O(e instanceof Error?e.message:String(e))}},[e,s]),fe=(0,U.useCallback)(e=>{z&&de(z.id,e)},[z,de]);Q1({content:z?.rawContent??``,scriptBlocks:z?A[z.id]??[]:[],onStartWorkout:fe,results:ue});let B=(0,U.useCallback)(e=>t=>{de(e,t)},[de]),pe=(0,U.useMemo)(()=>{if(!r||r.length<=1)return[];let e=[];for(let t of r){let n=t.title||`Untitled note`,r=Z1(CU(t.rawContent),A[t.id]??[],B(t.id),oe[t.id]);for(let i of r)e.push(...wU([{...i,id:`note-${t.id}:${i.id}`,label:`${n} · ${i.label}`}]))}return e},[r,A,oe,B]),me=(0,U.useRef)(!1);return(0,U.useEffect)(()=>{if(pe.length!==0)return me.current=!0,ae(pe),()=>{me.current&&(me.current=!1,ae([]))}},[pe,ae]),r?ee?(0,W.jsx)(In,{to:TN(ee),replace:!0}):(0,W.jsxs)(IR,{notePersistence:lP,provider:A6,children:[(0,W.jsx)(KB,{title:e,subtitle:`${r.length} ${r.length===1?`note`:`notes`}`,actions:(0,W.jsx)(RV,{primary:(0,W.jsxs)(K,{type:`button`,onClick:()=>l(!0),children:[(0,W.jsx)(On,{className:`size-4 mr-1.5`,"aria-hidden":`true`}),`New note`]})}),editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-8 px-4 py-6 sm:px-6`,children:[D&&(0,W.jsxs)(`p`,{role:`alert`,children:[`Workout not started. `,D,` Your draft is kept.`]}),(0,W.jsxs)(`nav`,{"aria-label":`Journal navigation`,className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>SU()?s(-1):s(`/journal`),className:`rounded-pill border border-border px-2 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:`‹ Journal`}),ie&&(0,W.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(_n,{to:CN(ie.prev),"aria-label":`Previous day`,className:`hover:bg-accent hover:text-foreground rounded-pill border border-border px-2 py-0.5 transition-colors`,children:[`‹ `,ie.prev]}),(0,W.jsx)(`span`,{className:`font-semibold text-foreground`,children:e}),(0,W.jsxs)(_n,{to:CN(ie.next),"aria-label":`Next day`,className:`hover:bg-accent hover:text-foreground rounded-pill border border-border px-2 py-0.5 transition-colors`,children:[ie.next,` ›`]})]})]}),r.length>1&&(0,W.jsx)(`nav`,{"aria-label":`Notes on this date`,className:`flex flex-wrap gap-2`,children:r.map(e=>(0,W.jsx)(_n,{to:TN(e.id),className:`rounded-full border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted`,children:e.title},e.id))}),r.length===0?(0,W.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg border border-dashed border-border p-6`,children:[(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Notes on this date yet.`}),(0,W.jsxs)(K,{type:`button`,size:`lg`,onClick:()=>l(!0),children:[(0,W.jsx)(On,{className:`size-4 mr-1.5`,"aria-hidden":`true`}),`Create a note`]})]}):r.length===1?(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-between border-b border-border/40 pb-2`,children:(0,W.jsx)(_n,{to:TN(r[0].id),className:`text-sm font-semibold hover:underline text-foreground`,"aria-label":`Open note page for ${r[0].title||`untitled note`}`,children:r[0].title||`Untitled note`})}),(0,W.jsx)(O6,{entry:r[0],registerRun:e=>{e?E.current.set(r[0].id,e):E.current.delete(r[0].id)},onChange:e=>ne(r[0].id,e),readonly:!1,theme:t,showLineNumbers:!1,onBlocksChange:e=>M(r[0].id,e),onCompleteWorkout:(e,t,n,i)=>R(e,t,n,i,r[0].id),onViewCreated:e=>L(r[0].id,e)},r[0].id)]}):(0,W.jsx)(`div`,{className:`space-y-6`,children:r.map((e,n)=>(0,W.jsxs)(`div`,{id:`note-${e.id}`,className:`rounded-lg border border-border/60 p-4 space-y-2`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-between border-b border-border/40 pb-2`,children:(0,W.jsx)(_n,{to:TN(e.id),className:`text-sm font-semibold hover:underline text-foreground`,children:e.title||`Note ${n+1}`})}),(0,W.jsx)(O6,{entry:e,registerRun:t=>{t?E.current.set(e.id,t):E.current.delete(e.id)},onChange:t=>ne(e.id,t),readonly:!1,theme:t,showLineNumbers:!1,onBlocksChange:t=>M(e.id,t),onCompleteWorkout:(t,n,r,i)=>R(t,n,r,i,e.id),onViewCreated:t=>L(e.id,t)})]},e.id))})]})}),(0,W.jsx)($H,{open:c,onOpenChange:l,defaultDate:e,onCreated:t=>{CP.listByDate(e).then(i).catch(()=>{}),s(TN(t.id))}}),u&&f&&(0,W.jsx)(OZ,{block:f,prepareRun:k,onClose:()=>{d(!1),h(null),_(null),y(null),S.current=!0;let e=x.current;e&&Y1(e.runtimeId),x.current=null},resultId:m??void 0,onCompleteWorkout:(e,t)=>R(e,t),autoStart:!0,adoptRuntime:v?.runtime??null,parkOnUnmount:!0,onPark:t=>{let n=x.current;if(!n||S.current){t.dispose();return}K1({runtimeId:n.runtimeId,block:n.block,noteId:n.noteId,captured:n.captured,runtime:t,journalDate:e})},onRuntimeReady:e=>{let t=x.current;if(!t)return;let n=q1(t.runtimeId);n&&n.runtime!==e&&n.runtime.dispose()}})]}):(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}var M6=()=>(0,W.jsxs)(`div`,{className:`relative my-3 flex items-start gap-3 rounded-lg border border-primary/30 bg-primary/5 px-4 py-3`,children:[(0,W.jsx)(`div`,{className:`mt-0.5 flex-shrink-0 text-primary`,children:(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,"aria-hidden":`true`,children:[(0,W.jsx)(`circle`,{cx:`9`,cy:`9`,r:`8`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,W.jsx)(`path`,{d:`M9 5v4.5M9 11.5v1`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})]})}),(0,W.jsxs)(`div`,{className:`flex-1 text-sm leading-relaxed text-muted-foreground`,children:[(0,W.jsx)(`span`,{className:`font-semibold text-foreground`,children:`Ready to try it?`}),` `,`Press the`,` `,(0,W.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary px-2 py-0.5 align-middle text-[11px] font-bold text-primary-foreground`,children:`▶ Run`}),` `,`button that appears on the workout block below to start the timer and track your rounds.`]}),(0,W.jsx)(`div`,{className:`pointer-events-none absolute -bottom-4 right-8 text-primary/50`,"aria-hidden":`true`,children:(0,W.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`none`,children:[(0,W.jsx)(`path`,{d:`M3 3 L17 3 L17 17`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`path`,{d:`M11 11 L17 17 L23 11`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]})})]});function N6({config:e,onAction:t}){return!e.headline||!e.subtitle||e.pillars.length===0?(0,W.jsxs)(`section`,{className:`rounded-3xl border border-amber-400/50 bg-amber-50 p-6 text-amber-900 dark:border-amber-500/40 dark:bg-amber-950/30 dark:text-amber-100`,children:[`Invalid `,(0,W.jsx)(`code`,{children:`attention`}),` widget config.`]}):(0,W.jsxs)(`section`,{className:`p-8`,children:[(0,W.jsx)(`p`,{className:`mb-3 text-xs font-semibold uppercase tracking-[0.14em] text-zinc-500 dark:text-zinc-400`,children:`Playground`}),(0,W.jsx)(`h1`,{className:`text-3xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-100 sm:text-4xl`,children:e.headline}),(0,W.jsx)(`p`,{className:`mt-4 max-w-3xl text-base leading-7 text-zinc-600 dark:text-zinc-300`,children:e.subtitle}),(0,W.jsx)(`div`,{className:`mt-7 grid gap-3 md:grid-cols-3`,children:e.pillars.map(e=>(0,W.jsxs)(`div`,{className:`rounded-2xl border border-zinc-200 bg-zinc-50/80 p-4 dark:border-zinc-800 dark:bg-zinc-900/70`,children:[(0,W.jsx)(`div`,{className:`mb-3 inline-flex size-8 items-center justify-center rounded-lg border border-zinc-200 bg-white text-zinc-700 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-200`,children:e.icon}),(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:e.label}),(0,W.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-zinc-600 dark:text-zinc-300`,children:e.description})]},e.label))}),(0,W.jsx)(`div`,{className:`mt-7 flex flex-wrap gap-3`,children:e.actions.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>t(e.action),className:e.variant===`primary`?`inline-flex items-center gap-2 rounded-full bg-zinc-950 px-5 py-2.5 text-sm font-medium text-zinc-50 transition hover:opacity-90 dark:bg-zinc-100 dark:text-zinc-900`:`inline-flex items-center gap-2 rounded-full border border-zinc-300 px-5 py-2.5 text-sm font-medium text-zinc-700 transition hover:bg-zinc-100 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`,children:[e.label,(0,W.jsx)(h,{className:`size-4`,"aria-hidden":`true`})]},`${e.action}-${e.label}`))})]})}function P6({config:e,isDarkMode:t,onRun:n}){let r=(0,U.useRef)(null),i=(0,U.useRef)(null),a=(0,U.useMemo)(()=>e.lines.map(e=>e.code).join(`
457
- `),[e.lines]);return(0,U.useEffect)(()=>{if(r.current)return i.current?.destroy(),i.current=new Or({state:ii.create({doc:a,extensions:[$r(),gi(),ii.readOnly.of(!1),Or.theme({"&":{fontSize:`13px`,borderRadius:`12px`,border:`1px solid var(--cm-border)`},".cm-scroller":{fontFamily:`JetBrains Mono, ui-monospace, SFMono-Regular, monospace`,lineHeight:`1.6`,minHeight:`180px`},".cm-content":{padding:`14px 0`},".cm-gutters":{backgroundColor:`transparent`,borderRight:`1px solid var(--cm-border)`}}),Or.theme({"&":{"--cm-border":t?`rgba(82, 82, 91, 0.7)`:`rgba(212, 212, 216, 0.9)`}},{dark:t}),...t?[ri]:[]]}),parent:r.current}),()=>{i.current?.destroy(),i.current=null}},[t,a]),e.lines.length===0?(0,W.jsxs)(`section`,{className:`rounded-2xl border border-amber-400/50 bg-amber-50 p-6 text-amber-900 dark:border-amber-500/40 dark:bg-amber-950/30 dark:text-amber-100`,children:[`Invalid `,(0,W.jsx)(`code`,{children:`code-example`}),` widget config.`]}):(0,W.jsxs)(`section`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`mb-4 flex items-center justify-between gap-3`,children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-zinc-900 dark:text-zinc-100`,children:`Code example`}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(i.current?.state.doc.toString()??a),className:`inline-flex items-center gap-2 rounded-full bg-emerald-600 px-4 py-2 text-xs font-semibold text-white transition hover:bg-emerald-500`,children:[(0,W.jsx)(pn,{className:`size-3.5`,"aria-hidden":`true`}),e.cta]})]}),(0,W.jsx)(`div`,{ref:r}),(0,W.jsx)(`ul`,{className:`mt-4 space-y-2 text-sm leading-6 text-zinc-600 dark:text-zinc-300`,children:e.lines.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex gap-2`,children:[(0,W.jsx)(`span`,{className:`mt-1 inline-block size-1.5 rounded-full bg-zinc-400`,"aria-hidden":`true`}),(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`code`,{className:`rounded bg-zinc-200/70 px-1 py-0.5 text-[12px] dark:bg-zinc-800`,children:e.code}),` — `,e.annotation]})]},`${e.code}-${t}`))})]})}function F6({config:e,onOpenDocs:t}){return!e.category||!e.title||!e.docsPath?(0,W.jsxs)(`article`,{className:`rounded-2xl border border-amber-400/50 bg-amber-50 p-5 text-amber-900 dark:border-amber-500/40 dark:bg-amber-950/30 dark:text-amber-100`,children:[`Invalid `,(0,W.jsx)(`code`,{children:`syntax-group`}),` widget config.`]}):(0,W.jsxs)(`article`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-[0.14em] text-zinc-500 dark:text-zinc-400`,children:e.category}),(0,W.jsxs)(`h3`,{className:`mt-2 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:[(0,W.jsx)(`span`,{className:`mr-2`,"aria-hidden":`true`,children:e.icon}),e.title]}),(0,W.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-zinc-600 dark:text-zinc-300`,children:e.description})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>t(e.docsPath),className:`inline-flex items-center gap-1.5 rounded-lg border border-zinc-300 px-2.5 py-1.5 text-xs font-semibold text-zinc-700 transition hover:bg-zinc-100 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`,children:[`Docs`,(0,W.jsx)(A,{className:`size-3`,"aria-hidden":`true`})]})]}),(0,W.jsx)(`pre`,{className:`mt-4 overflow-x-auto rounded-xl border border-zinc-200 bg-white px-3 py-2 text-xs text-zinc-700 dark:border-zinc-700 dark:bg-zinc-950/70 dark:text-zinc-200`,children:(0,W.jsx)(`code`,{children:e.example})})]})}function I6(e){return({config:t})=>(0,W.jsx)(N6,{config:t,onAction:e})}function L6(e,t){return({config:n})=>(0,W.jsx)(P6,{config:n,isDarkMode:e,onRun:t})}function R6(e){return({config:t})=>(0,W.jsx)(F6,{config:t,onOpenDocs:e})}var z6=[`visitedLanding`,`editedNote`,`ranWorkout`,`loggedEffort`,`openedReview`],B6=`wodwiki.onboarding.v1`,V6={visitedLanding:!1,editedNote:!1,ranWorkout:!1,loggedEffort:!1,openedReview:!1};function H6(){if(typeof window>`u`||!window.localStorage)return{...V6};try{let e=window.localStorage.getItem(B6);if(!e)return{...V6};let t=JSON.parse(e),n={...V6};for(let e of z6)n[e]=t[e]===!0;return n}catch{return{...V6}}}function U6(e){if(!(typeof window>`u`||!window.localStorage))try{window.localStorage.setItem(B6,JSON.stringify(e))}catch{}}function W6(){let[e,t]=(0,U.useState)(H6);(0,U.useEffect)(()=>{let e=e=>{e.key===B6&&t(H6())};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let n=(0,U.useCallback)(e=>{t(t=>{if(t[e])return t;let n={...t,[e]:!0};return U6(n),n})},[]),r=z6.length,i=z6.reduce((t,n)=>t+ +!!e[n],0);return{progress:e,stepsComplete:i,totalSteps:r,isComplete:i===r,mark:n}}function G6(){let{mark:e}=W6();return{onEditNote:(0,U.useCallback)(()=>{e(`editedNote`)},[e]),onRunWorkout:(0,U.useCallback)(()=>{e(`ranWorkout`)},[e]),onLogEffort:(0,U.useCallback)(()=>{e(`loggedEffort`)},[e])}}var K6=new Kk;function q6({theme:e,onViewCreated:t,onScrollToSection:n,onSearch:r}){let{id:i}=wt(),a=i??`playground`,o=VH(`playground`,a),s=(0,U.useMemo)(()=>i?ab(i):`Playground`,[i]),c=Vn(),l=!i||i===`playground`,{content:u,loading:d,entryId:f,noteBlocks:p,sourceRevision:m,onIdentityChange:h,onSaved:g,error:_,onChange:v,onLineChange:y,onBlur:b,flush:x,committedSourceRevision:S,resetToOriginal:C}=H1({category:`playground`,name:a,mdContent:w0.content,seedOnMount:l}),T=f??o,{onEditNote:E,onRunWorkout:D,onLogEffort:O}=G6(),k=(0,U.useCallback)(e=>{E(),v(e)},[E,v]),[A,j]=(0,U.useState)([]),M=(0,U.useCallback)(()=>{Z.getSessionsForNote(T).then(e=>j(e.filter(e=>e.completed))).catch(()=>{})},[T]);(0,U.useEffect)(()=>{M()},[M]);let N=(0,U.useRef)(!1),P=(0,U.useRef)(null),F=(0,U.useCallback)(e=>{if(P.current=e,t?.(e),N.current)return;N.current=!0;let n=Math.min(w0.cursorOffset,e.state.doc.length);e.dispatch({selection:_i.cursor(n)})},[t]),I=(0,U.useCallback)(async e=>{try{await x();let t=w(),n=await OR(T,e,t,`playground`);g({rawContent:n.note.rawContent,blocks:n.note.blocks,sourceRevision:n.note.sourceRevision}),W1.set(t,{block:n.block,noteId:n.session.noteId,captured:n,origin:`playground`,returnTo:`/playground/${encodeURIComponent(a)}`}),D(),c(ON(t))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}},[T,a,c,D,x,g]),L=(0,U.useCallback)(async e=>{try{O();let t=await U1({workoutName:s,category:`playground`,sourceNoteLabel:s,sourceNotePath:`/playground/${a}`,wodContent:e.content}),n=Ly(new Date);Q({title:`Added to journal`,description:t.journalDate===n?`Added to today's journal`:`Added to ${t.journalDate}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>c(CN(t.journalDate??n)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not add to journal`,variant:`destructive`})}},[s,a,c,O]),[ee,te]=(0,U.useState)(null),[ne,R]=(0,U.useState)(!1),re=(0,U.useCallback)(async e=>{let t=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;try{await Sq(T,t),Q({title:`Moved to journal`,description:`This playground now lives on ${t}.`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>c(CN(t)),children:`Open`})}),c(TN(T))}catch{Q({title:`Error`,description:`Could not move to journal`,variant:`destructive`})}},[T,c]),ie=(0,U.useCallback)(async(e,t)=>{let n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;try{await U1({workoutName:s,category:`playground`,sourceNoteLabel:s,sourceNotePath:`/playground/${a}`,wodContent:e.content,date:t}),c(CN(n)),Q({title:`Scheduled`,description:`Added to journal for ${n}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>c(CN(n)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not schedule workout`,variant:`destructive`})}},[s,a,c]),[ae,oe]=(0,U.useState)([]),se=Q1({content:u,scriptBlocks:ae,onStartWorkout:I,results:A}),ce=(0,U.useMemo)(()=>r0({id:T,type:`playground`}),[T]),le=l0({noteId:T,stamps:ce.stamps}),[z,ue]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!1;return Z.getNote(T).then(t=>{if(e||!t?.sourceId)return;let n=i0(t.sourceId);n&&ue({noteId:T,link:n})}).catch(()=>{}),()=>{e=!0}},[T]);let de=(0,W.jsxs)(RV,{label:`Playground actions`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>R(!0),title:`Move this playground to a journal date`,className:`inline-flex items-center gap-1 rounded-pill border border-border bg-card px-2.5 py-1 text-xs font-semibold text-muted-foreground transition-colors hover:bg-accent`,children:[(0,W.jsx)(Jt,{className:`size-3.5`,"aria-hidden":`true`}),`Move to journal`]}),(0,W.jsx)(T0,{mode:`playground`,currentWorkout:{name:s,content:u},index:se,onReset:C})]}),fe=d0(`playground`,{onPlay:I,onShare:_0,onAddToToday:L,onSchedule:te}),B=(0,U.useCallback)(e=>{if(e===`scroll-to-workout`){let e=se.find(e=>e.type===`time`||e.type===`log`);e&&n?.(e.id)}else e===`open-search`&&r?.()},[se,n,r]),pe=(0,U.useCallback)(e=>{let t={id:`code-example-block`,line:0,endLine:e.split(`
458
- `).length,content:e};I(t)},[I]),me=(0,U.useCallback)(e=>{e.startsWith(`/`)?window.open(e,`_blank`):c(e)},[c]),he=(0,U.useCallback)((e,t)=>{if(e===`route`&&t.route)c(t.route);else if(e===`start-workout`){let e=ae[0];e&&I(e)}else e===`new-note`&&c(`/playground`)},[c,ae,I]),ge=(0,U.useMemo)(()=>new Map([[`playground-run-tip`,M6],[`attention`,I6(B)],[`code-example`,L6(e===`dark`,pe)],[`syntax-group`,R6(me)]]),[B,pe,me,e]);return(0,U.useEffect)(()=>{document.title=`Wod.Wiki - ${s}`},[s]),d?(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(IR,{notePersistence:lP,provider:K6,children:(0,W.jsx)(KB,{title:s,actions:de,editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-6 sm:px-6`,children:[(0,W.jsx)(u0,{data:le,up:ce.up,source:z?.noteId===T?z.link:null}),(0,W.jsx)(YZ,{value:u,onChange:k,onCursorPositionChange:y,onBlur:b,noteId:T,noteBlocks:p,sourceRevision:m,onIdentityChange:e=>h({rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision}),onSaved:g,beforeRun:async()=>(await x(),S()),onSaveRequest:x,onCommitChange:x,commands:fe,enableInlineRuntime:!1,onViewCreated:F,theme:e,showLineNumbers:!1,onBlocksChange:oe,onButtonAction:he,widgetComponents:ge}),_?(0,W.jsxs)(`p`,{role:`alert`,children:[`Save failed. `,_ instanceof Error?_.message:String(_),` Your draft is kept.`]}):null,(0,W.jsx)(iR,{noteId:T,blocks:p,sourceRevision:m,onRevert:async e=>{await x();let t=P.current?.state.field(_T);if(!t)throw Error(`The current note editor is unavailable.`);let n=rR({rawContent:t.rawContent,blocks:t.noteBlocks,sourceRevision:S()},e);h({rawContent:n.rawContent,noteBlocks:n.blocks,sourceRevision:n.sourceRevision}),await x()}})]})})}),ee&&(0,W.jsx)(OC,{open:!0,onClose:()=>te(null),title:`Schedule workout`,children:(0,W.jsx)(z1,{selectedDate:null,onDateSelect:e=>{ie(ee,e),te(null)}})}),ne&&(0,W.jsx)(OC,{open:!0,onClose:()=>R(!1),title:`Move playground to Journal`,description:`Choose a date. This keeps the workout's existing results and attachments.`,children:(0,W.jsx)(z1,{selectedDate:null,onDateSelect:e=>{R(!1),re(e)}})})]})}function J6({category:e,name:t,mdContent:n,theme:r,runMode:i,hidePlanningCommands:a,onViewCreated:o}){let s=i?i===`inline`:vU.has(e),c=!yU[e],l=VH(e,t),u=Vn(),{content:d,loading:f,entryId:p,noteBlocks:m,sourceRevision:h,onIdentityChange:g,onSaved:_,error:v,onChange:y,onLineChange:b,onBlur:x,flush:S,committedSourceRevision:C}=H1({category:e,name:t,mdContent:n,seedOnMount:!c}),T=(0,U.useMemo)(()=>c?{label:`${e}-${t}`,path:DN(e,t)}:null,[e,c,t]),[E,D]=(0,U.useState)(null),O=(0,U.useCallback)(async n=>{let r=w();if(s){try{await S();let e=await DR({noteId:p??l,rawContent:d,blocks:m,expectedSourceRevision:C(),metadata:{title:t},noteType:`playground`},n,r);_({rawContent:e.note.rawContent,blocks:e.note.blocks,sourceRevision:e.note.sourceRevision}),W1.set(r,{block:e.block,noteId:e.session.noteId,captured:e}),u(ON(r))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}return}try{let i=await U1({workoutName:t,category:e,sourceNoteLabel:T?.label,sourceNotePath:T?.path,wodContent:n.content}),a=Object.values(i.blocks??{}).find(e=>e.kind===`wod`);if(!a)throw Error(`The saved journal workout is unavailable.`);W1.set(r,{block:{...n,id:a.id},noteId:i.id}),u(wN(i.journalDate??``,r))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}},[s,l,p,t,e,T,u,d,m,S,C,_]),k=(0,U.useCallback)(async(n,r)=>{let i=My(r),a;try{a=(await U1({workoutName:t,category:e,sourceNoteLabel:T?.label,sourceNotePath:T?.path,wodContent:n.content,date:r,wrapInWod:!0})).journalDate??``}catch{Q({variant:`destructive`,title:`Could not save workout`,description:`Failed to add "${t}" to ${i}. Please try again.`});return}u(CN(a));let o=CN(a);Q({title:`Added to ${i}`,description:`"${t}" was added to your journal.`,action:(0,W.jsx)(wM,{altText:`View journal entry`,onClick:()=>u(o),children:`View Note`}),duration:7e3})},[t,e,T,u]),A=d0(`notebook-readonly`,{onPlay:O,onShare:_0,onAddToToday:a?void 0:e=>k(e,new Date),onSchedule:a?void 0:D,onOpenInPlayground:e=>m0(e,u)}),[j,M]=(0,U.useState)([]),N=(0,U.useCallback)(()=>{u(TN(l))},[u,l]),P=Q1({content:d,scriptBlocks:j,onStartWorkout:O,onEditNote:c?N:void 0}),F=(0,U.useMemo)(()=>c?r0({id:l,type:`note`}):null,[c,l]),I=l0({noteId:l,stamps:F?.stamps??[]}),L=(0,W.jsx)(RV,{children:(0,W.jsx)(T0,{mode:`notebook-readonly`,currentWorkout:{name:l,content:d},index:P})});return f?(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(KB,{title:t,actions:L,editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-6 sm:px-6`,children:[(0,W.jsx)(u0,{data:I,up:F?.up}),(0,W.jsx)(YZ,{value:d,onChange:y,onCursorPositionChange:b,onBlur:x,noteId:l,noteBlocks:m,sourceRevision:h,onIdentityChange:e=>g({rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision}),onSaved:_,beforeRun:async()=>(await S(),C()),onSaveRequest:S,onCommitChange:S,readonly:!0,enableInlineRuntime:s,commands:A,onViewCreated:o,theme:r,showLineNumbers:!1,onBlocksChange:M}),v?(0,W.jsxs)(`p`,{role:`alert`,children:[`Save failed. `,v instanceof Error?v.message:String(v),` Your draft is kept.`]}):null]})}),E&&(0,W.jsx)(OC,{open:!0,onClose:()=>D(null),title:`Schedule ${t}`,children:(0,W.jsx)(z1,{selectedDate:null,onDateSelect:e=>{e&&k(E,e),D(null)}})})]})}var Y6=on(`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground hover:bg-primary/80`,secondary:`border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80`,destructive:`border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80`,outline:`text-foreground`}},defaultVariants:{variant:`default`}}),X6=U.memo(({className:e,variant:t,...n})=>(0,W.jsx)(`div`,{className:G(Y6({variant:t}),e),...n})),Z6=(0,U.forwardRef)(function({className:e,multiple:t,...n},r){return(0,W.jsxs)(`span`,{"data-slot":`control`,className:G(`group relative block w-full`,`before:absolute before:inset-px before:rounded-[calc(var(--radius-lg)-1px)] before:bg-background before:shadow-sm`,`dark:before:hidden`,`after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-transparent after:ring-inset`,`has-data-[focus]:after:ring-2 has-data-[focus]:after:ring-ring`,`has-data-[disabled]:opacity-50 has-data-[disabled]:before:bg-muted/50 has-data-[disabled]:before:shadow-none`),children:[(0,W.jsx)(de,{ref:r,multiple:t,...n,className:G(`relative block w-full appearance-none rounded-lg py-[calc(theme(spacing.2.5)-1px)]`,`sm:py-[calc(theme(spacing.1.5)-1px)]`,t?`px-[calc(theme(spacing.3.5)-1px)] sm:px-[calc(theme(spacing.3)-1px)]`:`pr-[calc(theme(spacing.10)-1px)] pl-[calc(theme(spacing.3.5)-1px)] sm:pr-[calc(theme(spacing.9)-1px)] sm:pl-[calc(theme(spacing.3)-1px)]`,`[&_optgroup]:font-semibold`,`text-base/6 text-foreground placeholder:text-muted-foreground sm:text-sm/6 dark:[&>*]:text-white`,`border border-border/60 data-[hover]:border-border dark:border-white/10 dark:data-[hover]:border-white/20`,`bg-transparent dark:bg-white/5 dark:[&>*]:bg-muted`,`focus:outline-hidden`,`data-invalid:border-destructive data-invalid:data-[hover]:border-destructive`,`data-[disabled]:border-border/40 data-[disabled]:opacity-100 dark:data-[disabled]:border-white/15 dark:data-[disabled]:bg-white/2.5 dark:data-[hover]:data-[disabled]:border-white/15`,`dark:scheme-dark`,e)}),!t&&(0,W.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2`,children:(0,W.jsxs)(`svg`,{className:`size-5 stroke-muted-foreground group-has-data-[disabled]:stroke-muted-foreground/70 sm:size-4 forced-colors:stroke-[CanvasText]`,viewBox:`0 0 16 16`,"aria-hidden":`true`,fill:`none`,children:[(0,W.jsx)(`path`,{d:`M5.75 10.75L8 13L10.25 10.75`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`path`,{d:`M10.25 5.25L8 3L5.75 5.25`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`})]})})]})}),Q6={effort:`efforts`,equipment:`equipment`},$6=[`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`efforts`,`equipment`,`page`,`page_notes`,`note_tags`,`attachments`];async function e8(e){let t=e.kind===`effort`?cl(e.rawContent):void 0,n=e.kind===`equipment`?dl(e.rawContent):void 0,r=t?.effort??n?.equipment,i=[...t?.errors??n?.errors??[]],a=Av(e.rawContent),o=typeof a.id==`string`?a.id.trim():``;if(o||i.push("Frontmatter must declare a stable `id` (the clone flow patches it into the source)"),r&&r.slug!==e.slug&&i.push(`Document slug "${r.slug}" does not match "${e.slug}"`),r&&r.label.trim()!==e.title.trim()&&i.push(`Document label "${r.label}" does not match title "${e.title}"`),i.length>0)throw Error(i.join(`
456
+ `))}}let i=c6(e,n,t);await CP.create(i)},[]),Se=r??xe,Ce=(0,U.useCallback)(async e=>{R(null);try{await q3(e,a)}catch(e){R(e instanceof Error?e.message:`Could not start the workout.`)}},[a]),we=(0,U.useCallback)(async e=>{R(null);try{let t=await CP.resolve(e.id),{routeId:n}=await xq(t&&typeof t==`object`&&`rawContent`in t?String(t.rawContent??``):``,{title:e.title});a(SN(n.replace(/^playground\//,``)))}catch(e){R(e instanceof Error?e.message:`Could not create the playground entry.`)}},[a]),Te=(0,U.useCallback)(e=>Bm(e)?sz.runFind(e):sz.runQuery(e.raw),[]),[De,Oe]=(0,U.useState)(0),[ke,Ae]=(0,U.useState)([]);(0,U.useEffect)(()=>{let e=!1;return zA.getAllNotebooks().then(t=>{e||Ae(t.filter(e=>e.origin===`user`||e.origin==="default").filter(e=>e.slug!==`guides`&&e.slug!==`playground`).map(e=>({id:e.notebookId,name:e.name,icon:e.icon})))}).catch(()=>void 0),()=>{e=!0}},[De]);let je=(0,U.useCallback)(async(e,t)=>{if(e)try{await zA.moveNote(e,t),Oe(e=>e+1)}catch(e){R(e instanceof Error?e.message:String(e))}},[]);(0,U.useEffect)(()=>tK(()=>Oe(e=>e+1)),[]),(0,U.useEffect)(()=>{if(!(!(`target`in B)||B.target!==`effort`))return vO(()=>Oe(e=>e+1))},[B]),(0,U.useEffect)(()=>{let e=zx().result?.id??-1;return Bx(()=>{let t=zx().result?.id??-1;t!==e&&(e=t,Oe(e=>e+1))})},[]);let Me=(0,U.useCallback)(async()=>{let e=Xj().filter(e=>e.autoImport===!1&&v.includes(e.id));if(e.length===0){le();return}f(!0),g(null),m(null);try{let t=0,n=0,r=[];for(let i of e){let e=await hM(i.id,{onProgress:m});e===`imported`?(t+=1,u(!0),Oe(e=>e+1)):e===`current`||e===`server-stale`?(n+=1,u(!0)):r.push(`${i.label}: ${C3[e]}`)}r.length>0&&g(r.join(` — `)),t>0?Q({title:t===e.length?`Libraries synced`:`${t} of ${e.length} libraries synced`,description:`Content was imported from the published seeds. Your own edits were kept.`}):n>0&&r.length===0&&Q({title:`Everything is up to date`,description:`All your subscribed libraries already match their published versions.`})}finally{f(!1)}},[v,le]);(0,U.useEffect)(()=>{if(s===`preparing`)return;if(B.error){te(!1);return}let e=!1,t=setTimeout(()=>{te(!0),M(void 0),be.query(y,t=>{e||M(t)}).then(t=>{e||(A(t),P(G4(y,B)),cI({pathname:o.pathname,query:y,entries:t}))}).catch(()=>{e||(A([]),cI({pathname:o.pathname,query:y,entries:[]}))}).finally(()=>{e||te(!1)})},b6);return()=>{e=!0,clearTimeout(t)}},[y,be,B,o.pathname,s,De]);let Ne=(0,U.useMemo)(()=>{if(N?.length)return N;if(S.groupBy)return[S.groupBy];let t=Tm(B.error||!Bm(B)?e.level===`effort`?`effort`:`note`:B.target,`find`);return[aF(e.groupByOptions,t,e.level===`effort`?`discipline`:`date`)]},[N,S.groupBy,e.level,e.groupByOptions,B]),Pe=N?.length?`query`:S.groupBy?`view`:e.groupByOptions?.length?`favorite`:`level`,Fe=(0,U.useMemo)(()=>new Set(B.error||!Bm(B)?[]:wm(B.target,`find`)),[B]),Ie=B.error||Hm(B)?0:B.filters.filter(e=>Fe.has(e.key)).length,Le=(B.error||Hm(B)?0:B.filters.length)-Ie,Re=e.shelfVisible&&!pe,ze=(0,U.useMemo)(()=>q4(k,Ne,{shelfVisible:Re}),[k,Ne,Re]),Be=B3(k),{visible:Ve,growTo:He}=Be,Ue=(0,U.useMemo)(()=>q4(Ve,Ne,{shelfVisible:Re}),[Ve,Ne,Re]),We=(0,U.useMemo)(()=>new Map(ze.map(e=>[e.id,e.entries.length])),[ze]),{setL3Items:Ge,scrollToSection:Ke,navState:qe,setStreamControls:Je}=WM();(0,U.useEffect)(()=>{if(ze.length===0){Ge([]);return}let e=ze.map(e=>({id:e.id,label:e.label,level:3,action:{type:`scroll`,sectionId:e.id}}));return Ge(e),()=>Ge([])},[ze,Ge]);let Ye=(0,U.useMemo)(()=>iF(Tm(B.error||!Bm(B)?e.level===`effort`?`effort`:`note`:B.target,`find`),e.groupByOptions),[B,e.level,e.groupByOptions]),Xe=(0,U.useCallback)(e=>{let t=U3(y,e);t===y?T(e):b(t)},[y,b,T]),Ze=(0,U.useCallback)(e=>{let t=Ne.some(t=>t.toLowerCase()===e.toLowerCase()),n=kI(y,e,!t);b(n);let r=X(n);!r.error&&Bm(r)&&Xe(r.groupBy?.[0]??``)},[Ne,y,b,Xe]);(0,U.useEffect)(()=>(Je?.({query:y,onQueryChange:b,groupDims:Ne,onToggleGroupDim:Ze,availableGroupDims:Ye,settings:S,onLayoutChange:C,onToggleField:w,level:e.level,...E?{onOpenQuerySettings:()=>O(!0)}:{}}),()=>Je?.(null)),[y,b,Ne,Ze,Ye,Je,S,C,w,e.level,E]);let Qe=`activeL3Id`in qe&&typeof qe.activeL3Id==`string`?qe.activeL3Id:null,$e=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=Qe;if(!e||$e.current===e||document.getElementById(e))return;let t=ze.find(t=>t.id===e);if(!t)return;$e.current=e;let n=t.entries[t.entries.length-1],r=n?k.findIndex(e=>e.id===n.id):-1;He(r>=0?r+1:k.length)},[Qe,ze,k,He]),(0,U.useEffect)(()=>{let e=$e.current;!e||!document.getElementById(e)||($e.current=null,Ke(e))},[Ue,Ke]);let et=zB(104),tt=B.error&&y!==e.defaultWql?B.error:null,nt=x??tt,rt=(0,U.useMemo)(()=>{let t=X(e.defaultWql);return!t.error&&Bm(t)?t.filters:[]},[e.defaultWql]),it=e.feedNotice===!0&&c===!0&&!l,at=(0,U.useMemo)(()=>{let e=[];if(it)return e.push({id:`browse-libraries`,label:`Browse libraries`,apply:le}),e;if(!B.error&&B.advisories?.length&&e.push({id:`edit-query`,label:`Edit query`,apply:()=>U4(y,Te,b)}),!B.error&&B.window){let t=B.window,n=t.kind===`relative`?`last ${t.size}${t.unit}`:`from ${t.start}${t.end?` to ${t.end}`:``}`;e.push({id:`remove-window`,label:`Remove time window (${n})`,apply:()=>b(H3(y))})}if(!B.error&&Bm(B)){let t=C6(B.filters,rt);if(t.length>0){let n=new Set(t.map(S6)),r=B.filters.filter(e=>!n.has(S6(e)));e.push({id:`clear-filters`,label:t.length===1?`Clear filter`:`Clear filters (${t.length})`,apply:()=>b(jh({...B,filters:r}))})}}return e},[B,y,b,Te,rt,it,le]),ot=(0,W.jsxs)(`div`,{className:`px-6 py-16 text-center text-muted-foreground flex flex-col items-center justify-center gap-3`,"data-testid":`stream-empty-state`,children:[(0,W.jsx)(`p`,{className:`text-sm font-medium`,children:it?`No ${e.title.toLowerCase()} are imported yet.`:e.emptyMessage??(B.window?`No entries found within the selected time window.`:`No entries match your search.`)}),at.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-2 mt-1`,children:at.map(e=>(0,W.jsx)(K,{variant:`outline`,size:`sm`,onClick:e.apply,className:`text-xs`,children:e.label},e.id))})]}),st=!!B.error&&k.length>0;return s===`preparing`?(0,W.jsxs)(`div`,{className:`bg-card flex flex-col flex-1`,"data-testid":`stream-preparing`,role:`status`,"aria-busy":`true`,children:[ce,fe,(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-4 p-6`,children:[(0,W.jsxs)(`div`,{className:`w-full max-w-2xl space-y-3`,"aria-hidden":`true`,children:[(0,W.jsx)(`div`,{className:`h-4 w-2/3 animate-pulse rounded bg-muted`}),(0,W.jsx)(`div`,{className:`h-4 w-1/2 animate-pulse rounded bg-muted`}),(0,W.jsx)(`div`,{className:`h-4 w-3/4 animate-pulse rounded bg-muted`})]}),(0,W.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`Loading library…`})]})]}):(0,W.jsxs)(`div`,{className:`bg-card flex flex-col flex-1`,"data-testid":`queriable-stream-view`,children:[ce,fe,E&&(0,W.jsx)(u3,{surface:E,open:D,onOpenChange:O}),(0,W.jsx)(NB,{className:`max-lg:hidden`,actions:(0,W.jsxs)(RV,{primary:e.route===`/efforts`?(0,W.jsxs)(K,{size:`sm`,onClick:()=>a(RN(`new`,void 0,{mode:`create`})),className:`h-9 px-2.5 text-xs gap-1.5`,"data-testid":`efforts-create-btn`,children:[(0,W.jsx)(On,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`New`})]}):ae?(0,W.jsxs)(K,{size:`sm`,onClick:()=>ue(!0),className:`h-9 px-2.5 text-xs gap-1.5`,"data-testid":`notebooks-create-button`,children:[(0,W.jsx)(On,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`New Notebook`})]}):void 0,label:`Stream actions`,children:[ae&&(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>se(!0),"data-testid":`manage-notebooks-button`,className:`h-9 gap-1.5 px-2.5 text-xs`,children:[(0,W.jsx)(Cn,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Manage Notebooks`})]}),t]}),queryBar:(0,W.jsx)(W4,{query:y,onQueryChange:b,scopeOptions:e.scopeOptions,execute:Te,defaultQuery:e.defaultWql,route:e.route})}),(0,W.jsx)(`div`,{className:`px-4 pt-2 sm:px-6 lg:px-8`,"data-testid":`stream-query-status-row`,children:(0,W.jsx)(w6,{error:nt,target:B.error?null:Bm(B)?B.target:B.family,matched:k.length,total:Math.max(j?.selected??0,k.length),loading:ee,applied:Ie,ignored:Le,advisories:B.error?[]:B.advisories??[],groupDims:Ne,groupingSource:Pe})}),e.scopeOptions.length===0&&(0,W.jsx)(`p`,{"data-testid":`route-wql-empty-options`,className:`px-4 pt-3 text-xs text-muted-foreground sm:px-6 lg:px-8`,children:`No source options are set for this route — pick a source by editing the query.`}),e.feedNotice&&c&&!l&&(0,W.jsx)(`div`,{className:`px-4 pt-3 sm:px-6 lg:px-8`,"data-testid":`feed-library-notice`,children:(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 flex flex-col sm:flex-row sm:items-center gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 space-y-1`,children:[(0,W.jsxs)(`p`,{className:`text-sm font-medium text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Ee,{className:`size-4 text-primary`}),`Only the core seed is imported`]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:v.length>0?`The content for this page comes from your subscribed libraries, which have not been imported yet. Sync now to import them — or open Sync settings to add more sources (mirrors, your own libraries).`:`The content for this page comes from library sources, and none are subscribed yet. Browse the library manager to subscribe — mirrors and your own libraries both work.`}),p&&(0,W.jsxs)(`div`,{className:`space-y-1.5 pt-1`,"data-testid":`feed-library-notice-progress`,children:[(0,W.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`text-xs text-muted-foreground`,children:x6(p)}),p.phase!==`checking`&&p.phase!==`finished`?(0,W.jsx)(H4,{value:p.completedChunks,max:p.totalChunks,label:`Library import progress`,className:`max-w-sm`}):d?(0,W.jsx)(`progress`,{"aria-label":`Checking library sources`,className:`h-2 max-w-sm w-full`}):null]}),(h??(p?.phase===`finished`?p.error:null))&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,"data-testid":`feed-library-notice-error`,children:h??(p?.phase===`finished`?p.error:null)})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,W.jsxs)(K,{size:`sm`,onClick:()=>void Me(),disabled:d,"data-testid":`feed-library-notice-sync`,className:`gap-2`,children:[(0,W.jsx)(zt,{className:`size-3.5 ${d?`animate-spin`:``}`}),(0,W.jsx)(`span`,{children:d?`Syncing…`:v.length>0?`Sync now`:`Browse libraries`})]}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>a($.settingsSync),"data-testid":`feed-library-notice-settings`,className:`gap-2`,children:[(0,W.jsx)(Cn,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Sync settings`})]})]})]})}),re&&ie&&(0,TC.createPortal)((0,W.jsx)(W4,{query:y,onQueryChange:b,scopeOptions:e.scopeOptions,execute:Te,defaultQuery:e.defaultWql,route:e.route,compact:!0}),ie),nt&&(0,W.jsxs)(`div`,{role:`alert`,className:`mx-6 mt-4 flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-destructive`,"data-testid":`stream-query-error`,children:[(0,W.jsx)(I,{className:`size-5 flex-shrink-0 mt-0.5`}),(0,W.jsxs)(`div`,{className:`flex-1 text-xs`,children:[(0,W.jsx)(`p`,{className:`font-bold`,children:`Query error`}),(0,W.jsx)(`p`,{className:`mt-1 font-mono text-[11px] opacity-90`,children:nt})]})]}),ne&&(0,W.jsxs)(`div`,{role:`alert`,className:`mx-6 mt-4 flex items-start gap-3 rounded-lg border border-destructive/30 bg-destructive/10 p-4 text-destructive`,"data-testid":`stream-action-error`,children:[(0,W.jsx)(I,{className:`size-5 flex-shrink-0 mt-0.5`}),(0,W.jsxs)(`div`,{className:`flex-1 text-xs`,children:[(0,W.jsx)(`p`,{className:`font-bold`,children:`Action failed`}),(0,W.jsx)(`p`,{className:`mt-1 text-[11px] opacity-90`,children:ne})]}),(0,W.jsx)(`button`,{type:`button`,onClick:()=>R(null),className:`text-[11px] font-bold uppercase tracking-wider hover:opacity-80`,"data-testid":`stream-action-error-dismiss`,children:`Dismiss`})]}),ae&&(0,W.jsx)(V4,{refreshKey:De,onChanged:()=>Oe(e=>e+1)}),ge&&(0,W.jsx)(`div`,{className:`border-b border-border/60 bg-card/20 px-6 py-4`,"data-testid":`notebook-readme-note`,children:ve.map((e,t)=>e.kind===`markdown`?(0,W.jsx)(t$,{prose:e.text},t):(0,W.jsx)(_6,{query:e.query,heading:e.heading,onAddToToday:Se,onRunStart:Ce},t))}),ye?null:S.layout===`rows`?(0,W.jsx)(`div`,{className:st?`flex-1 opacity-50 transition-opacity`:`flex-1`,children:(0,W.jsx)(t6,{entries:k,level:e.level,visibleFieldIds:S.visibleFields,stickyHeaderTop:et,emptyMessage:e.emptyMessage??`No matching records found.`})}):S.layout===`feed`?Ue.length>0?(0,W.jsx)(s6,{groups:Ue,batch:Be,stickyOffset:et,onRunEntry:Ce,onSendToPlayground:we,onAddToToday:Se,moveNotebookTargets:ke,onMoveNotebook:(e,t)=>void je(e.id,t)}):ee&&k.length===0?(0,W.jsx)(`div`,{className:`py-16 text-center text-xs text-muted-foreground/60`,"data-testid":`stream-loading`,children:`Loading…`}):k.length===0&&!ee?ot:null:(0,W.jsx)(`div`,{className:st?`flex-1 divide-y divide-border/60 opacity-50 transition-opacity`:`flex-1 divide-y divide-border/60`,children:Ue.length>0?(0,W.jsxs)(`div`,{className:`divide-y divide-border/40`,"data-testid":`stream-dated-content`,children:[Ue.map(e=>{let t=We.get(e.id)??e.entries.length;return e.key===`shelf`?(0,W.jsxs)(`div`,{id:e.id,className:`border-b border-border/60`,"data-testid":`stream-shelf`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>L(e=>!e),className:`w-full flex items-center justify-between px-6 py-2.5 bg-muted/20 hover:bg-muted/40 transition-colors text-left`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[F?(0,W.jsx)(Et,{className:`size-3.5 text-muted-foreground`}):(0,W.jsx)(wn,{className:`size-3.5 text-muted-foreground`}),(0,W.jsx)(Rss,{className:`size-3.5 text-amber-500`}),(0,W.jsx)(`span`,{className:`text-xs font-bold text-foreground`,children:e.label}),(0,W.jsx)(`span`,{className:`text-[10px] font-bold text-muted-foreground/60 bg-muted px-1.5 py-0.5 rounded-full`,children:t})]})}),F&&(0,W.jsx)(`div`,{className:`divide-y divide-border/40`,children:e.entries.map(e=>(0,W.jsx)(Z3,{entry:e,visibleFieldIds:S.visibleFields,onAddToToday:Se,onRunStart:Ce,moveNotebookTargets:ke,onMoveNotebook:(e,t)=>void je(e.id,t)},e.id))})]},e.id):(0,W.jsxs)(`div`,{id:e.id,className:`group/date`,"data-testid":`date-group-${e.key}`,children:[(0,W.jsx)(BB,{top:et,icon:(0,W.jsx)(mn,{className:`size-3.5 shrink-0 text-muted-foreground`}),label:e.label,badge:e.isToday?(0,W.jsx)(`span`,{className:`shrink-0 rounded-full bg-primary/10 px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wider text-primary`,children:`Today`}):void 0,meta:`${t} ${t===1?`entry`:`entries`}`}),(0,W.jsx)(`div`,{className:`divide-y divide-border/30`,children:e.entries.map(t=>(0,W.jsx)(Z3,{entry:t,visibleFieldIds:S.visibleFields,tone:e.isToday?`primary`:`secondary`,onAddToToday:Se,onRunStart:Ce,moveNotebookTargets:ke,onMoveNotebook:(e,t)=>void je(e.id,t)},t.id))})]},e.id)}),(0,W.jsx)(y6,{batch:Be})]}):ee&&k.length===0?(0,W.jsx)(`div`,{className:`py-16 text-center text-xs text-muted-foreground/60`,"data-testid":`stream-loading`,children:`Loading…`}):k.length===0&&!ee?ot:null})]})}function E6(){return(0,W.jsx)(l3,{surface:Z4})}function D6({pageRoute:e,quests:t,challengeSectionMap:n,onScrollToSection:r}){let{quests:i,stepsComplete:a,totalSteps:o,isComplete:s}=Nq(e,t),[c,l]=(0,U.useState)(!1),u=(0,U.useRef)(null),d=(0,U.useRef)(null),f=(0,U.useRef)(null);if(o===0)return null;let p=e=>{let t=n.get(e);t&&r?.(t),l(!1)};(0,U.useEffect)(()=>{if(!c)return;let e=e=>{e.key===`Escape`&&(l(!1),u.current?.focus())},t=e=>{let t=e.relatedTarget,n=u.current?.parentElement;n&&t&&!n.contains(t)&&l(!1)},n=e=>{let t=u.current?.parentElement;t&&!t.contains(e.target)&&l(!1)};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,n),document.addEventListener(`touchstart`,n),d.current?.addEventListener(`focusout`,t),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,n),document.removeEventListener(`touchstart`,n),d.current?.removeEventListener(`focusout`,t)}},[c]),(0,U.useEffect)(()=>()=>{f.current&&=(window.clearTimeout(f.current),null)},[]);let m=()=>{f.current&&=(window.clearTimeout(f.current),null)},h=()=>{m(),f.current=window.setTimeout(()=>l(!1),150)};return(0,W.jsxs)(`div`,{className:`relative py-1.5 shrink-0`,onPointerEnter:e=>{e.pointerType===`mouse`&&(m(),l(!0))},onPointerLeave:e=>{e.pointerType===`mouse`&&h()},children:[(0,W.jsxs)(`button`,{ref:u,type:`button`,"aria-haspopup":`menu`,"aria-expanded":c,"aria-label":`${a} of ${o} challenges complete`,title:`${a} of ${o} challenges complete`,onClick:()=>l(!0),className:`inline-flex min-h-11 items-center gap-1.5 cursor-pointer focus:outline-none select-none text-left rounded-full border border-border/70 bg-background px-3 py-1 hover:bg-muted/40 hover:border-border transition-colors shadow-sm`,children:[s?(0,W.jsx)(un,{className:`size-4 text-emerald-500`}):(0,W.jsx)(Pt,{className:`size-4 text-muted-foreground`}),(0,W.jsxs)(`span`,{className:G(`text-[10px] font-black uppercase tracking-wider`,s?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:[a,`/`,o]})]}),c&&(0,W.jsxs)(`div`,{ref:d,role:`menu`,"aria-orientation":`vertical`,className:`absolute left-0 top-full mt-1.5 w-64 rounded-xl border border-border bg-popover text-popover-foreground shadow-2xl p-3 z-50 origin-top-left before:content-[''] before:absolute before:-top-1.5 before:left-0 before:right-0 before:h-1.5 before:bg-transparent`,children:[(0,W.jsxs)(`div`,{className:`mb-2.5 pb-2 border-b border-border/60 flex items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h5`,{className:`text-[10px] font-black uppercase tracking-widest text-foreground`,children:`Syntax Challenges`}),(0,W.jsx)(`p`,{className:`text-[9px] text-muted-foreground mt-0.5`,children:`Click a challenge to jump to its section.`})]}),(0,W.jsxs)(`span`,{className:`text-[9px] font-black uppercase tracking-wider text-muted-foreground tabular-nums`,children:[a,`/`,o]})]}),(0,W.jsx)(`div`,{className:`flex flex-col gap-1`,children:i.map(e=>{let t=n.get(e.id);return(0,W.jsx)(v$,{quest:e,onClick:t?()=>p(e.id):void 0,disabled:!t,compact:!0,className:`border-0 bg-transparent hover:bg-muted/40`},e.id)})})]})]})}function O6(e){return(0,W.jsx)(k6,{...e},e.entry.id)}function k6({entry:e,onChange:t,registerRun:n,...r}){let[i,a]=(0,U.useState)({blocks:e.blocks??{},sourceRevision:e.sourceRevision??0}),[o,s]=(0,U.useState)(null),c=(0,U.useRef)(i.sourceRevision),l=(0,U.useRef)({rawContent:e.rawContent,...i}),u=(0,U.useCallback)(e=>{c.current=e.sourceRevision;let t=l.current,n=t.rawContent===e.rawContent&&JSON.stringify(Object.values(t.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))===JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));a(t=>({blocks:n?e.blocks:t.blocks,sourceRevision:e.sourceRevision}))},[]),d=(0,U.useCallback)(async t=>{let n=await lP.saveNote({noteId:e.id,rawContent:t.rawContent,blocks:t.blocks,expectedSourceRevision:c.current}),r={rawContent:n.rawContent,blocks:n.blocks??{},sourceRevision:n.sourceRevision??0};return u(r),r},[e.id,u]),f=O1({onSave:async e=>{await d(e)},getSnapshotKey:e=>JSON.stringify([e.rawContent,Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])])}),p=(0,U.useCallback)(e=>{let t=l.current.rawContent!==e.rawContent||JSON.stringify(Object.values(l.current.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));l.current=e,t&&f.onChange(e)},[f.onChange]);return(0,U.useEffect)(()=>(n?.(async(t,n)=>{await f.flush();let r=l.current,i=await DR({noteId:e.id,rawContent:r.rawContent,blocks:r.blocks,expectedSourceRevision:c.current},t,n);return u({rawContent:i.note.rawContent,blocks:i.note.blocks,sourceRevision:i.note.sourceRevision}),i}),()=>n?.(null)),[e.id,n,f.flush,u]),(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(YZ,{...r,noteId:e.id,value:o??e.rawContent,noteBlocks:i.blocks,sourceRevision:i.sourceRevision,onIdentityChange:p,onSaved:u,beforeRun:async()=>(await f.flush(),c.current),onSaveRequest:f.flush,onChange:e=>{s(null),t(e)},onBlur:f.onBlur,onCursorPositionChange:f.onLineChange,onCommitChange:f.flush}),f.error?(0,W.jsxs)(`p`,{role:`alert`,children:[`Save failed. `,f.error instanceof Error?f.error.message:String(f.error),` Your draft is kept.`]}):null,(0,W.jsx)(iR,{noteId:e.id,blocks:i.blocks,sourceRevision:i.sourceRevision,onRevert:async e=>{await f.flush();let n=rR({...l.current,sourceRevision:c.current},e),r=await d(n);l.current=r,s(n.rawContent),t(n.rawContent)}})]})}var A6=new Kk;function j6({journalDate:e,theme:t,onViewCreated:n}){let[r,i]=(0,U.useState)(null),[a,o]=cn(),s=Vn(),[c,l]=(0,U.useState)(!1),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(null),[v,y]=(0,U.useState)(null),b=(0,U.useRef)(null);b.current=v;let x=(0,U.useRef)(null),S=(0,U.useRef)(!1),C=(0,U.useRef)(null),T=(0,U.useRef)(null),E=(0,U.useRef)(new Map),[D,O]=(0,U.useState)(null),k=(0,U.useCallback)(async()=>{let e=b.current;if(e)return e.block;let t=C.current;if(!t||!m)throw Error(`The pending workout is unavailable.`);return t.captured?(T.current=t.captured,t.captured.block):(T.current||=t.snapshot?await DR(t.snapshot,t.block,m,t.origin):await OR(t.noteId,t.block,m,t.origin),T.current.block)},[m]),[A,j]=(0,U.useState)({}),M=(0,U.useCallback)((e,t)=>{j(n=>n[e]===t?n:{...n,[e]:t})},[]),N=(0,U.useRef)(new Map),P=(0,U.useRef)(null),[F,I]=(0,U.useState)(null),L=(0,U.useCallback)((e,t)=>{N.current.set(e,t),P.current||(P.current=t,I(t),n?.(t))},[n]),ee=a.get(`note`);(0,U.useEffect)(()=>{if(!ee||!r)return;let e=document.getElementById(`note-${ee}`);e&&e.scrollIntoView({behavior:`smooth`,block:`start`})},[ee,r]);let te=a.toString();(0,U.useEffect)(()=>{let e=new URLSearchParams(te).get(`autoStart`);if(!e)return;let t=M1.get(e);t&&(M1.delete(e),C.current=t,T.current=null,x.current={runtimeId:e,block:t.block,noteId:t.noteId,captured:t.captured},S.current=!1,p(t.block),h(e),_(t.noteId),d(!0)),o(e=>(e.delete(`autoStart`),e),{replace:!0})},[te,o]),(0,U.useEffect)(()=>{if(u)return;let t=I1(e);t&&(y(t),C.current={block:t.block,noteId:t.noteId,captured:t.captured},T.current=t.captured??null,x.current={runtimeId:t.runtimeId,block:t.block,noteId:t.noteId,captured:t.captured},p(t.block),h(t.runtimeId),_(t.noteId),d(!0))},[e,u]);let ne=(0,U.useCallback)((e,t)=>{i(n=>n?.map(n=>n.id===e?{...n,rawContent:t}:n)??n)},[]),R=(0,U.useCallback)((e,t,n,r,i)=>{if(!t)return Promise.reject(Error(`This run produced no results to save.`));if(n)return Promise.resolve();let a=T.current;if(!a)return Promise.reject(Error(`The saved run pin is unavailable.`));S.current=!0,L1(a.session.id);let o=a.session.id,s=N.current.get(a.session.noteId);if(s&&!s.state.doc.toString().includes(ED(o))){let e=DD(s.state,a.session.blockId,o);e&&s.dispatch({changes:e})}return iK.record({blockId:a.session.blockId,noteId:a.session.noteId,resultId:o,data:t,createdAt:t.endTime})},[]);(0,U.useEffect)(()=>{let t=!1;return CP.listByDate(e).then(e=>{t||i(e)}).catch(()=>{t||i([])}),()=>{t=!0}},[e]);let re=/^\d{4}-\d{2}-\d{2}$/.test(e),ie=(0,U.useMemo)(()=>{if(!re)return null;let[t,n,r]=e.split(`-`).map(Number);return{prev:gP(new Date(t,n-1,r-1)),next:gP(new Date(t,n-1,r+1))}},[e,re]),{setL3Items:ae}=WM(),[oe,se]=(0,U.useState)({}),ce=r?.map(e=>e.id).join(`|`)??``,le=(0,U.useMemo)(()=>ce?ce.split(`|`):[],[ce]);(0,U.useEffect)(()=>{if(le.length===0)return;let e=!1;for(let t of le)Z.getSessionsForNote(t).then(n=>{e||se(e=>({...e,[t]:n}))}).catch(()=>{});return()=>{e=!0}},[le]),(0,U.useEffect)(()=>tK(e=>{Z.getSessionsForNote(e.noteId).then(t=>{se(n=>({...n,[e.noteId]:t}))}).catch(()=>{})}),[]);let z=r!==null&&r.length===1?r[0]:null,ue=z?oe[z.id]:void 0,de=(0,U.useCallback)(async(t,n)=>{try{let r=E.current.get(t);if(!r)throw Error(`The saved note editor is unavailable.`);let i=w(),a=await r(n,i);M1.set(i,{noteId:t,block:a.block,captured:a,returnTo:CN(e)}),s(ON(i))}catch(e){O(e instanceof Error?e.message:String(e))}},[e,s]),fe=(0,U.useCallback)(e=>{z&&de(z.id,e)},[z,de]);B1({content:z?.rawContent??``,scriptBlocks:z?A[z.id]??[]:[],onStartWorkout:fe,results:ue});let B=(0,U.useCallback)(e=>t=>{de(e,t)},[de]),pe=(0,U.useMemo)(()=>{if(!r||r.length<=1)return[];let e=[];for(let t of r){let n=t.title||`Untitled note`,r=z1(CU(t.rawContent),A[t.id]??[],B(t.id),oe[t.id]);for(let i of r)e.push(...wU([{...i,id:`note-${t.id}:${i.id}`,label:`${n} · ${i.label}`}]))}return e},[r,A,oe,B]),me=(0,U.useRef)(!1);return(0,U.useEffect)(()=>{if(pe.length!==0)return me.current=!0,ae(pe),()=>{me.current&&(me.current=!1,ae([]))}},[pe,ae]),r?ee?(0,W.jsx)(In,{to:TN(ee),replace:!0}):(0,W.jsxs)(IR,{notePersistence:lP,provider:A6,children:[(0,W.jsx)(KB,{title:e,subtitle:`${r.length} ${r.length===1?`note`:`notes`}`,actions:(0,W.jsx)(RV,{primary:(0,W.jsxs)(K,{type:`button`,onClick:()=>l(!0),children:[(0,W.jsx)(On,{className:`size-4 mr-1.5`,"aria-hidden":`true`}),`New note`]})}),editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-8 px-4 py-6 sm:px-6`,children:[D&&(0,W.jsxs)(`p`,{role:`alert`,children:[`Workout not started. `,D,` Your draft is kept.`]}),(0,W.jsxs)(`nav`,{"aria-label":`Journal navigation`,className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:()=>SU()?s(-1):s(`/journal`),className:`rounded-pill border border-border px-2 py-0.5 hover:bg-accent hover:text-foreground transition-colors`,children:`‹ Journal`}),ie&&(0,W.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(_n,{to:CN(ie.prev),"aria-label":`Previous day`,className:`hover:bg-accent hover:text-foreground rounded-pill border border-border px-2 py-0.5 transition-colors`,children:[`‹ `,ie.prev]}),(0,W.jsx)(`span`,{className:`font-semibold text-foreground`,children:e}),(0,W.jsxs)(_n,{to:CN(ie.next),"aria-label":`Next day`,className:`hover:bg-accent hover:text-foreground rounded-pill border border-border px-2 py-0.5 transition-colors`,children:[ie.next,` ›`]})]})]}),r.length>1&&(0,W.jsx)(`nav`,{"aria-label":`Notes on this date`,className:`flex flex-wrap gap-2`,children:r.map(e=>(0,W.jsx)(_n,{to:TN(e.id),className:`rounded-full border border-border px-3 py-1 text-xs text-muted-foreground hover:bg-muted`,children:e.title},e.id))}),r.length===0?(0,W.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg border border-dashed border-border p-6`,children:[(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No Notes on this date yet.`}),(0,W.jsxs)(K,{type:`button`,size:`lg`,onClick:()=>l(!0),children:[(0,W.jsx)(On,{className:`size-4 mr-1.5`,"aria-hidden":`true`}),`Create a note`]})]}):r.length===1?(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-between border-b border-border/40 pb-2`,children:(0,W.jsx)(_n,{to:TN(r[0].id),className:`text-sm font-semibold hover:underline text-foreground`,"aria-label":`Open note page for ${r[0].title||`untitled note`}`,children:r[0].title||`Untitled note`})}),(0,W.jsx)(O6,{entry:r[0],registerRun:e=>{e?E.current.set(r[0].id,e):E.current.delete(r[0].id)},onChange:e=>ne(r[0].id,e),readonly:!1,theme:t,showLineNumbers:!1,onBlocksChange:e=>M(r[0].id,e),onCompleteWorkout:(e,t,n,i)=>R(e,t,n,i,r[0].id),onViewCreated:e=>L(r[0].id,e)},r[0].id)]}):(0,W.jsx)(`div`,{className:`space-y-6`,children:r.map((e,n)=>(0,W.jsxs)(`div`,{id:`note-${e.id}`,className:`rounded-lg border border-border/60 p-4 space-y-2`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-between border-b border-border/40 pb-2`,children:(0,W.jsx)(_n,{to:TN(e.id),className:`text-sm font-semibold hover:underline text-foreground`,children:e.title||`Note ${n+1}`})}),(0,W.jsx)(O6,{entry:e,registerRun:t=>{t?E.current.set(e.id,t):E.current.delete(e.id)},onChange:t=>ne(e.id,t),readonly:!1,theme:t,showLineNumbers:!1,onBlocksChange:t=>M(e.id,t),onCompleteWorkout:(t,n,r,i)=>R(t,n,r,i,e.id),onViewCreated:t=>L(e.id,t)})]},e.id))})]})}),(0,W.jsx)($H,{open:c,onOpenChange:l,defaultDate:e,onCreated:t=>{CP.listByDate(e).then(i).catch(()=>{}),s(TN(t.id))}}),u&&f&&(0,W.jsx)(OZ,{block:f,prepareRun:k,onClose:()=>{d(!1),h(null),_(null),y(null),S.current=!0;let e=x.current;e&&L1(e.runtimeId),x.current=null},resultId:m??void 0,onCompleteWorkout:(e,t)=>R(e,t),autoStart:!0,adoptRuntime:v?.runtime??null,parkOnUnmount:!0,onPark:t=>{let n=x.current;if(!n||S.current){t.dispose();return}P1({runtimeId:n.runtimeId,block:n.block,noteId:n.noteId,captured:n.captured,runtime:t,journalDate:e})},onRuntimeReady:e=>{let t=x.current;if(!t)return;let n=F1(t.runtimeId);n&&n.runtime!==e&&n.runtime.dispose()}})]}):(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}var M6=()=>(0,W.jsxs)(`div`,{className:`relative my-3 flex items-start gap-3 rounded-lg border border-primary/30 bg-primary/5 px-4 py-3`,children:[(0,W.jsx)(`div`,{className:`mt-0.5 flex-shrink-0 text-primary`,children:(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,"aria-hidden":`true`,children:[(0,W.jsx)(`circle`,{cx:`9`,cy:`9`,r:`8`,stroke:`currentColor`,strokeWidth:`1.5`}),(0,W.jsx)(`path`,{d:`M9 5v4.5M9 11.5v1`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`})]})}),(0,W.jsxs)(`div`,{className:`flex-1 text-sm leading-relaxed text-muted-foreground`,children:[(0,W.jsx)(`span`,{className:`font-semibold text-foreground`,children:`Ready to try it?`}),` `,`Press the`,` `,(0,W.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded-md bg-primary px-2 py-0.5 align-middle text-[11px] font-bold text-primary-foreground`,children:`▶ Run`}),` `,`button that appears on the workout block below to start the timer and track your rounds.`]}),(0,W.jsx)(`div`,{className:`pointer-events-none absolute -bottom-4 right-8 text-primary/50`,"aria-hidden":`true`,children:(0,W.jsxs)(`svg`,{width:`20`,height:`20`,viewBox:`0 0 20 20`,fill:`none`,children:[(0,W.jsx)(`path`,{d:`M3 3 L17 3 L17 17`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`path`,{d:`M11 11 L17 17 L23 11`,stroke:`currentColor`,strokeWidth:`1.5`,strokeLinecap:`round`,strokeLinejoin:`round`})]})})]});function N6({config:e,onAction:t}){return!e.headline||!e.subtitle||e.pillars.length===0?(0,W.jsxs)(`section`,{className:`rounded-3xl border border-amber-400/50 bg-amber-50 p-6 text-amber-900 dark:border-amber-500/40 dark:bg-amber-950/30 dark:text-amber-100`,children:[`Invalid `,(0,W.jsx)(`code`,{children:`attention`}),` widget config.`]}):(0,W.jsxs)(`section`,{className:`p-8`,children:[(0,W.jsx)(`p`,{className:`mb-3 text-xs font-semibold uppercase tracking-[0.14em] text-zinc-500 dark:text-zinc-400`,children:`Playground`}),(0,W.jsx)(`h1`,{className:`text-3xl font-semibold tracking-tight text-zinc-950 dark:text-zinc-100 sm:text-4xl`,children:e.headline}),(0,W.jsx)(`p`,{className:`mt-4 max-w-3xl text-base leading-7 text-zinc-600 dark:text-zinc-300`,children:e.subtitle}),(0,W.jsx)(`div`,{className:`mt-7 grid gap-3 md:grid-cols-3`,children:e.pillars.map(e=>(0,W.jsxs)(`div`,{className:`rounded-2xl border border-zinc-200 bg-zinc-50/80 p-4 dark:border-zinc-800 dark:bg-zinc-900/70`,children:[(0,W.jsx)(`div`,{className:`mb-3 inline-flex size-8 items-center justify-center rounded-lg border border-zinc-200 bg-white text-zinc-700 dark:border-zinc-800 dark:bg-zinc-900 dark:text-zinc-200`,children:e.icon}),(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:e.label}),(0,W.jsx)(`p`,{className:`mt-1.5 text-sm leading-6 text-zinc-600 dark:text-zinc-300`,children:e.description})]},e.label))}),(0,W.jsx)(`div`,{className:`mt-7 flex flex-wrap gap-3`,children:e.actions.map(e=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>t(e.action),className:e.variant===`primary`?`inline-flex items-center gap-2 rounded-full bg-zinc-950 px-5 py-2.5 text-sm font-medium text-zinc-50 transition hover:opacity-90 dark:bg-zinc-100 dark:text-zinc-900`:`inline-flex items-center gap-2 rounded-full border border-zinc-300 px-5 py-2.5 text-sm font-medium text-zinc-700 transition hover:bg-zinc-100 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`,children:[e.label,(0,W.jsx)(h,{className:`size-4`,"aria-hidden":`true`})]},`${e.action}-${e.label}`))})]})}function P6({config:e,isDarkMode:t,onRun:n}){let r=(0,U.useRef)(null),i=(0,U.useRef)(null),a=(0,U.useMemo)(()=>e.lines.map(e=>e.code).join(`
457
+ `),[e.lines]);return(0,U.useEffect)(()=>{if(r.current)return i.current?.destroy(),i.current=new Or({state:ii.create({doc:a,extensions:[$r(),gi(),ii.readOnly.of(!1),Or.theme({"&":{fontSize:`13px`,borderRadius:`12px`,border:`1px solid var(--cm-border)`},".cm-scroller":{fontFamily:`JetBrains Mono, ui-monospace, SFMono-Regular, monospace`,lineHeight:`1.6`,minHeight:`180px`},".cm-content":{padding:`14px 0`},".cm-gutters":{backgroundColor:`transparent`,borderRight:`1px solid var(--cm-border)`}}),Or.theme({"&":{"--cm-border":t?`rgba(82, 82, 91, 0.7)`:`rgba(212, 212, 216, 0.9)`}},{dark:t}),...t?[ri]:[]]}),parent:r.current}),()=>{i.current?.destroy(),i.current=null}},[t,a]),e.lines.length===0?(0,W.jsxs)(`section`,{className:`rounded-2xl border border-amber-400/50 bg-amber-50 p-6 text-amber-900 dark:border-amber-500/40 dark:bg-amber-950/30 dark:text-amber-100`,children:[`Invalid `,(0,W.jsx)(`code`,{children:`code-example`}),` widget config.`]}):(0,W.jsxs)(`section`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`mb-4 flex items-center justify-between gap-3`,children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-zinc-900 dark:text-zinc-100`,children:`Code example`}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(i.current?.state.doc.toString()??a),className:`inline-flex items-center gap-2 rounded-full bg-emerald-600 px-4 py-2 text-xs font-semibold text-white transition hover:bg-emerald-500`,children:[(0,W.jsx)(pn,{className:`size-3.5`,"aria-hidden":`true`}),e.cta]})]}),(0,W.jsx)(`div`,{ref:r}),(0,W.jsx)(`ul`,{className:`mt-4 space-y-2 text-sm leading-6 text-zinc-600 dark:text-zinc-300`,children:e.lines.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex gap-2`,children:[(0,W.jsx)(`span`,{className:`mt-1 inline-block size-1.5 rounded-full bg-zinc-400`,"aria-hidden":`true`}),(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`code`,{className:`rounded bg-zinc-200/70 px-1 py-0.5 text-[12px] dark:bg-zinc-800`,children:e.code}),` — `,e.annotation]})]},`${e.code}-${t}`))})]})}function F6({config:e,onOpenDocs:t}){return!e.category||!e.title||!e.docsPath?(0,W.jsxs)(`article`,{className:`rounded-2xl border border-amber-400/50 bg-amber-50 p-5 text-amber-900 dark:border-amber-500/40 dark:bg-amber-950/30 dark:text-amber-100`,children:[`Invalid `,(0,W.jsx)(`code`,{children:`syntax-group`}),` widget config.`]}):(0,W.jsxs)(`article`,{className:`p-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-xs font-semibold uppercase tracking-[0.14em] text-zinc-500 dark:text-zinc-400`,children:e.category}),(0,W.jsxs)(`h3`,{className:`mt-2 text-sm font-semibold text-zinc-900 dark:text-zinc-100`,children:[(0,W.jsx)(`span`,{className:`mr-2`,"aria-hidden":`true`,children:e.icon}),e.title]}),(0,W.jsx)(`p`,{className:`mt-2 text-sm leading-6 text-zinc-600 dark:text-zinc-300`,children:e.description})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>t(e.docsPath),className:`inline-flex items-center gap-1.5 rounded-lg border border-zinc-300 px-2.5 py-1.5 text-xs font-semibold text-zinc-700 transition hover:bg-zinc-100 dark:border-zinc-700 dark:text-zinc-200 dark:hover:bg-zinc-800`,children:[`Docs`,(0,W.jsx)(A,{className:`size-3`,"aria-hidden":`true`})]})]}),(0,W.jsx)(`pre`,{className:`mt-4 overflow-x-auto rounded-xl border border-zinc-200 bg-white px-3 py-2 text-xs text-zinc-700 dark:border-zinc-700 dark:bg-zinc-950/70 dark:text-zinc-200`,children:(0,W.jsx)(`code`,{children:e.example})})]})}function I6(e){return({config:t})=>(0,W.jsx)(N6,{config:t,onAction:e})}function L6(e,t){return({config:n})=>(0,W.jsx)(P6,{config:n,isDarkMode:e,onRun:t})}function R6(e){return({config:t})=>(0,W.jsx)(F6,{config:t,onOpenDocs:e})}var z6=[`visitedLanding`,`editedNote`,`ranWorkout`,`loggedEffort`,`openedReview`],B6=`wodwiki.onboarding.v1`,V6={visitedLanding:!1,editedNote:!1,ranWorkout:!1,loggedEffort:!1,openedReview:!1};function H6(){if(typeof window>`u`||!window.localStorage)return{...V6};try{let e=window.localStorage.getItem(B6);if(!e)return{...V6};let t=JSON.parse(e),n={...V6};for(let e of z6)n[e]=t[e]===!0;return n}catch{return{...V6}}}function U6(e){if(!(typeof window>`u`||!window.localStorage))try{window.localStorage.setItem(B6,JSON.stringify(e))}catch{}}function W6(){let[e,t]=(0,U.useState)(H6);(0,U.useEffect)(()=>{let e=e=>{e.key===B6&&t(H6())};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let n=(0,U.useCallback)(e=>{t(t=>{if(t[e])return t;let n={...t,[e]:!0};return U6(n),n})},[]),r=z6.length,i=z6.reduce((t,n)=>t+ +!!e[n],0);return{progress:e,stepsComplete:i,totalSteps:r,isComplete:i===r,mark:n}}function G6(){let{mark:e}=W6();return{onEditNote:(0,U.useCallback)(()=>{e(`editedNote`)},[e]),onRunWorkout:(0,U.useCallback)(()=>{e(`ranWorkout`)},[e]),onLogEffort:(0,U.useCallback)(()=>{e(`loggedEffort`)},[e])}}var K6=new Kk;function q6({theme:e,onViewCreated:t,onScrollToSection:n,onSearch:r}){let{id:i}=wt(),a=i??`playground`,o=VH(`playground`,a),s=(0,U.useMemo)(()=>i?ab(i):`Playground`,[i]),c=Vn(),l=!i||i===`playground`,{content:u,loading:d,entryId:f,noteBlocks:p,sourceRevision:m,onIdentityChange:h,onSaved:g,error:_,onChange:v,onLineChange:y,onBlur:b,flush:x,committedSourceRevision:S,resetToOriginal:C}=A1({category:`playground`,name:a,mdContent:f0.content,seedOnMount:l}),T=f??o,{onEditNote:E,onRunWorkout:D,onLogEffort:O}=G6(),k=(0,U.useCallback)(e=>{E(),v(e)},[E,v]),[A,j]=(0,U.useState)([]),M=(0,U.useCallback)(()=>{Z.getSessionsForNote(T).then(e=>j(e.filter(e=>e.completed))).catch(()=>{})},[T]);(0,U.useEffect)(()=>{M()},[M]);let N=(0,U.useRef)(!1),P=(0,U.useRef)(null),F=(0,U.useCallback)(e=>{if(P.current=e,t?.(e),N.current)return;N.current=!0;let n=Math.min(f0.cursorOffset,e.state.doc.length);e.dispatch({selection:_i.cursor(n)})},[t]),I=(0,U.useCallback)(async e=>{try{await x();let t=w(),n=await OR(T,e,t,`playground`);g({rawContent:n.note.rawContent,blocks:n.note.blocks,sourceRevision:n.note.sourceRevision}),M1.set(t,{block:n.block,noteId:n.session.noteId,captured:n,origin:`playground`,returnTo:`/playground/${encodeURIComponent(a)}`}),D(),c(ON(t))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}},[T,a,c,D,x,g]),L=(0,U.useCallback)(async e=>{try{O();let t=await j1({workoutName:s,category:`playground`,sourceNoteLabel:s,sourceNotePath:`/playground/${a}`,wodContent:e.content}),n=Ly(new Date);Q({title:`Added to journal`,description:t.journalDate===n?`Added to today's journal`:`Added to ${t.journalDate}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>c(CN(t.journalDate??n)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not add to journal`,variant:`destructive`})}},[s,a,c,O]),[ee,te]=(0,U.useState)(null),[ne,R]=(0,U.useState)(!1),re=(0,U.useCallback)(async e=>{let t=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,`0`)}-${String(e.getDate()).padStart(2,`0`)}`;try{await Sq(T,t),Q({title:`Moved to journal`,description:`This playground now lives on ${t}.`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>c(CN(t)),children:`Open`})}),c(TN(T))}catch{Q({title:`Error`,description:`Could not move to journal`,variant:`destructive`})}},[T,c]),ie=(0,U.useCallback)(async(e,t)=>{let n=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;try{await j1({workoutName:s,category:`playground`,sourceNoteLabel:s,sourceNotePath:`/playground/${a}`,wodContent:e.content,date:t}),c(CN(n)),Q({title:`Scheduled`,description:`Added to journal for ${n}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>c(CN(n)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not schedule workout`,variant:`destructive`})}},[s,a,c]),[ae,oe]=(0,U.useState)([]),se=B1({content:u,scriptBlocks:ae,onStartWorkout:I,results:A}),ce=(0,U.useMemo)(()=>G1({id:T,type:`playground`}),[T]),le=Z1({noteId:T,stamps:ce.stamps}),[z,ue]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!1;return Z.getNote(T).then(t=>{if(e||!t?.sourceId)return;let n=K1(t.sourceId);n&&ue({noteId:T,link:n})}).catch(()=>{}),()=>{e=!0}},[T]);let de=(0,W.jsxs)(RV,{label:`Playground actions`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>R(!0),title:`Move this playground to a journal date`,className:`inline-flex items-center gap-1 rounded-pill border border-border bg-card px-2.5 py-1 text-xs font-semibold text-muted-foreground transition-colors hover:bg-accent`,children:[(0,W.jsx)(Jt,{className:`size-3.5`,"aria-hidden":`true`}),`Move to journal`]}),(0,W.jsx)(p0,{mode:`playground`,currentWorkout:{name:s,content:u},index:se,onReset:C})]}),fe=$1(`playground`,{onPlay:I,onShare:a0,onAddToToday:L,onSchedule:te}),B=(0,U.useCallback)(e=>{if(e===`scroll-to-workout`){let e=se.find(e=>e.type===`time`||e.type===`log`);e&&n?.(e.id)}else e===`open-search`&&r?.()},[se,n,r]),pe=(0,U.useCallback)(e=>{let t={id:`code-example-block`,line:0,endLine:e.split(`
458
+ `).length,content:e};I(t)},[I]),me=(0,U.useCallback)(e=>{e.startsWith(`/`)?window.open(e,`_blank`):c(e)},[c]),he=(0,U.useCallback)((e,t)=>{if(e===`route`&&t.route)c(t.route);else if(e===`start-workout`){let e=ae[0];e&&I(e)}else e===`new-note`&&c(`/playground`)},[c,ae,I]),ge=(0,U.useMemo)(()=>new Map([[`playground-run-tip`,M6],[`attention`,I6(B)],[`code-example`,L6(e===`dark`,pe)],[`syntax-group`,R6(me)]]),[B,pe,me,e]);return(0,U.useEffect)(()=>{document.title=`Wod.Wiki - ${s}`},[s]),d?(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(IR,{notePersistence:lP,provider:K6,children:(0,W.jsx)(KB,{title:s,actions:de,editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-6 sm:px-6`,children:[(0,W.jsx)(Q1,{data:le,up:ce.up,source:z?.noteId===T?z.link:null}),(0,W.jsx)(YZ,{value:u,onChange:k,onCursorPositionChange:y,onBlur:b,noteId:T,noteBlocks:p,sourceRevision:m,onIdentityChange:e=>h({rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision}),onSaved:g,beforeRun:async()=>(await x(),S()),onSaveRequest:x,onCommitChange:x,commands:fe,enableInlineRuntime:!1,onViewCreated:F,theme:e,showLineNumbers:!1,onBlocksChange:oe,onButtonAction:he,widgetComponents:ge}),_?(0,W.jsxs)(`p`,{role:`alert`,children:[`Save failed. `,_ instanceof Error?_.message:String(_),` Your draft is kept.`]}):null,(0,W.jsx)(iR,{noteId:T,blocks:p,sourceRevision:m,onRevert:async e=>{await x();let t=P.current?.state.field(_T);if(!t)throw Error(`The current note editor is unavailable.`);let n=rR({rawContent:t.rawContent,blocks:t.noteBlocks,sourceRevision:S()},e);h({rawContent:n.rawContent,noteBlocks:n.blocks,sourceRevision:n.sourceRevision}),await x()}})]})})}),ee&&(0,W.jsx)(OC,{open:!0,onClose:()=>te(null),title:`Schedule workout`,children:(0,W.jsx)(D1,{selectedDate:null,onDateSelect:e=>{ie(ee,e),te(null)}})}),ne&&(0,W.jsx)(OC,{open:!0,onClose:()=>R(!1),title:`Move playground to Journal`,description:`Choose a date. This keeps the workout's existing results and attachments.`,children:(0,W.jsx)(D1,{selectedDate:null,onDateSelect:e=>{R(!1),re(e)}})})]})}function J6({category:e,name:t,mdContent:n,theme:r,runMode:i,hidePlanningCommands:a,onViewCreated:o}){let s=i?i===`inline`:vU.has(e),c=!yU[e],l=VH(e,t),u=Vn(),{content:d,loading:f,entryId:p,noteBlocks:m,sourceRevision:h,onIdentityChange:g,onSaved:_,error:v,onChange:y,onLineChange:b,onBlur:x,flush:S,committedSourceRevision:C}=A1({category:e,name:t,mdContent:n,seedOnMount:!c}),T=(0,U.useMemo)(()=>c?{label:`${e}-${t}`,path:DN(e,t)}:null,[e,c,t]),[E,D]=(0,U.useState)(null),O=(0,U.useCallback)(async n=>{let r=w();if(s){try{await S();let e=await DR({noteId:p??l,rawContent:d,blocks:m,expectedSourceRevision:C(),metadata:{title:t},noteType:`playground`},n,r);_({rawContent:e.note.rawContent,blocks:e.note.blocks,sourceRevision:e.note.sourceRevision}),M1.set(r,{block:e.block,noteId:e.session.noteId,captured:e}),u(ON(r))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}return}try{let i=await j1({workoutName:t,category:e,sourceNoteLabel:T?.label,sourceNotePath:T?.path,wodContent:n.content}),a=Object.values(i.blocks??{}).find(e=>e.kind===`wod`);if(!a)throw Error(`The saved journal workout is unavailable.`);M1.set(r,{block:{...n,id:a.id},noteId:i.id}),u(wN(i.journalDate??``,r))}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:`Save failed. Your draft is kept.`,variant:`destructive`})}},[s,l,p,t,e,T,u,d,m,S,C,_]),k=(0,U.useCallback)(async(n,r)=>{let i=My(r),a;try{a=(await j1({workoutName:t,category:e,sourceNoteLabel:T?.label,sourceNotePath:T?.path,wodContent:n.content,date:r,wrapInWod:!0})).journalDate??``}catch{Q({variant:`destructive`,title:`Could not save workout`,description:`Failed to add "${t}" to ${i}. Please try again.`});return}u(CN(a));let o=CN(a);Q({title:`Added to ${i}`,description:`"${t}" was added to your journal.`,action:(0,W.jsx)(wM,{altText:`View journal entry`,onClick:()=>u(o),children:`View Note`}),duration:7e3})},[t,e,T,u]),A=$1(`notebook-readonly`,{onPlay:O,onShare:a0,onAddToToday:a?void 0:e=>k(e,new Date),onSchedule:a?void 0:D,onOpenInPlayground:e=>n0(e,u)}),[j,M]=(0,U.useState)([]),N=(0,U.useCallback)(()=>{u(TN(l))},[u,l]),P=B1({content:d,scriptBlocks:j,onStartWorkout:O,onEditNote:c?N:void 0}),F=(0,U.useMemo)(()=>c?G1({id:l,type:`note`}):null,[c,l]),I=Z1({noteId:l,stamps:F?.stamps??[]}),L=(0,W.jsx)(RV,{children:(0,W.jsx)(p0,{mode:`notebook-readonly`,currentWorkout:{name:l,content:d},index:P})});return f?(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(KB,{title:t,actions:L,editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 px-4 py-6 sm:px-6`,children:[(0,W.jsx)(Q1,{data:I,up:F?.up}),(0,W.jsx)(YZ,{value:d,onChange:y,onCursorPositionChange:b,onBlur:x,noteId:l,noteBlocks:m,sourceRevision:h,onIdentityChange:e=>g({rawContent:e.rawContent,noteBlocks:e.blocks,sourceRevision:e.sourceRevision}),onSaved:_,beforeRun:async()=>(await S(),C()),onSaveRequest:S,onCommitChange:S,readonly:!0,enableInlineRuntime:s,commands:A,onViewCreated:o,theme:r,showLineNumbers:!1,onBlocksChange:M}),v?(0,W.jsxs)(`p`,{role:`alert`,children:[`Save failed. `,v instanceof Error?v.message:String(v),` Your draft is kept.`]}):null]})}),E&&(0,W.jsx)(OC,{open:!0,onClose:()=>D(null),title:`Schedule ${t}`,children:(0,W.jsx)(D1,{selectedDate:null,onDateSelect:e=>{e&&k(E,e),D(null)}})})]})}var Y6=on(`inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2`,{variants:{variant:{default:`border-transparent bg-primary text-primary-foreground hover:bg-primary/80`,secondary:`border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80`,destructive:`border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80`,outline:`text-foreground`}},defaultVariants:{variant:`default`}}),X6=U.memo(({className:e,variant:t,...n})=>(0,W.jsx)(`div`,{className:G(Y6({variant:t}),e),...n})),Z6=(0,U.forwardRef)(function({className:e,multiple:t,...n},r){return(0,W.jsxs)(`span`,{"data-slot":`control`,className:G(`group relative block w-full`,`before:absolute before:inset-px before:rounded-[calc(var(--radius-lg)-1px)] before:bg-background before:shadow-sm`,`dark:before:hidden`,`after:pointer-events-none after:absolute after:inset-0 after:rounded-lg after:ring-transparent after:ring-inset`,`has-data-[focus]:after:ring-2 has-data-[focus]:after:ring-ring`,`has-data-[disabled]:opacity-50 has-data-[disabled]:before:bg-muted/50 has-data-[disabled]:before:shadow-none`),children:[(0,W.jsx)(de,{ref:r,multiple:t,...n,className:G(`relative block w-full appearance-none rounded-lg py-[calc(theme(spacing.2.5)-1px)]`,`sm:py-[calc(theme(spacing.1.5)-1px)]`,t?`px-[calc(theme(spacing.3.5)-1px)] sm:px-[calc(theme(spacing.3)-1px)]`:`pr-[calc(theme(spacing.10)-1px)] pl-[calc(theme(spacing.3.5)-1px)] sm:pr-[calc(theme(spacing.9)-1px)] sm:pl-[calc(theme(spacing.3)-1px)]`,`[&_optgroup]:font-semibold`,`text-base/6 text-foreground placeholder:text-muted-foreground sm:text-sm/6 dark:[&>*]:text-white`,`border border-border/60 data-[hover]:border-border dark:border-white/10 dark:data-[hover]:border-white/20`,`bg-transparent dark:bg-white/5 dark:[&>*]:bg-muted`,`focus:outline-hidden`,`data-invalid:border-destructive data-invalid:data-[hover]:border-destructive`,`data-[disabled]:border-border/40 data-[disabled]:opacity-100 dark:data-[disabled]:border-white/15 dark:data-[disabled]:bg-white/2.5 dark:data-[hover]:data-[disabled]:border-white/15`,`dark:scheme-dark`,e)}),!t&&(0,W.jsx)(`span`,{className:`pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2`,children:(0,W.jsxs)(`svg`,{className:`size-5 stroke-muted-foreground group-has-data-[disabled]:stroke-muted-foreground/70 sm:size-4 forced-colors:stroke-[CanvasText]`,viewBox:`0 0 16 16`,"aria-hidden":`true`,fill:`none`,children:[(0,W.jsx)(`path`,{d:`M5.75 10.75L8 13L10.25 10.75`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`}),(0,W.jsx)(`path`,{d:`M10.25 5.25L8 3L5.75 5.25`,strokeWidth:1.5,strokeLinecap:`round`,strokeLinejoin:`round`})]})})]})}),Q6={effort:`efforts`,equipment:`equipment`},$6=[`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`efforts`,`equipment`,`page`,`page_notes`,`note_tags`,`attachments`];async function e8(e){let t=e.kind===`effort`?cl(e.rawContent):void 0,n=e.kind===`equipment`?dl(e.rawContent):void 0,r=t?.effort??n?.equipment,i=[...t?.errors??n?.errors??[]],a=Av(e.rawContent),o=typeof a.id==`string`?a.id.trim():``;if(o||i.push("Frontmatter must declare a stable `id` (the clone flow patches it into the source)"),r&&r.slug!==e.slug&&i.push(`Document slug "${r.slug}" does not match "${e.slug}"`),r&&r.label.trim()!==e.title.trim()&&i.push(`Document label "${r.label}" does not match title "${e.title}"`),i.length>0)throw Error(i.join(`
459
459
  `));return Z.withTransaction([...$6],async i=>{let a=e.kind===`effort`?await i.getEffort(e.slug):await i.getEquipment(e.slug);if(a?.registrySource===`bundled`)throw Error(`"${e.slug}" is a bundled definition and cannot be saved over — clone it first`);if(a&&a.id!==o)throw Error(`Document id "${o}" does not match record id "${a.id}" — clone instead of re-keying`);let s=a?.ownerNoteId,c=e.noteId??s??`${e.kind}/${e.slug}`;if(s!==void 0&&c!==s)throw Error(`"${e.slug}" is owned by note ${s}; refusing to save against ${c}`);let l=new Date().toISOString();if(e.kind===`effort`){let n={...t.effort,id:o,slug:e.slug,registrySource:`user`,ownerNoteId:c,sourceId:Q6.effort,sourcePath:c,createdAt:a?.createdAt??l,updatedAt:l};await i.saveEffort(n)}else{let t={...n.equipment,id:o,slug:e.slug,registrySource:`user`,ownerNoteId:c,sourceId:Q6.equipment,sourcePath:c,createdAt:a?.createdAt??l,updatedAt:l};await i.saveEquipment(t)}return{id:c,sourceRevision:(await i.saveNoteSource({noteId:c,rawContent:e.rawContent,expectedSourceRevision:e.expectedSourceRevision,metadata:{title:r.label,sourceId:Q6[e.kind]},createdAt:Date.now()})).sourceRevision}})}async function t8(e,t){await Z.withTransaction([...$6],async n=>{let r=e===`effort`?await n.getEffort(t):await n.getEquipment(t);if(r?.registrySource!==`user`)throw Error(`"${t}" is not user-owned ${e}`);e===`effort`?await n.deleteEffort(t):await n.deleteEquipment(t);let i=r.ownerNoteId??`${e}/${t}`;await n.getNote(i)&&await n.deleteNote(i)})}function n8(e,t,n){let r=`effort-user-${crypto.randomUUID()}`,i=`${t}-custom`,a=`${n} (Custom)`,o=Za(e,[`id`],r);return o=Za(o,[`slug`],i),o=Za(o,[`label`],a),o=Za(o,[`registrySource`],`user`),o=Za(o,[`derivation`,`parentSlug`],t),{raw:o,id:r,slug:i,label:a}}function r8(e){let{registry:t,isReady:n,revision:r,refresh:i}=yM(),[a,o]=(0,U.useState)(``),[s,c]=(0,U.useState)(!0),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(!1),[h,g]=(0,U.useState)(!1),_=d?.registrySource===`user`,v=(0,U.useRef)(null),y=(0,U.useRef)(void 0);(0,U.useEffect)(()=>{if(!n){c(!1);return}if(!e){y.current=void 0,f(null),m(!1),g(!1),v.current=null,u(null),c(!1);return}let r=y.current!==e;y.current=e;let i=!1;r&&(v.current=null,c(!0),u(null),m(!1),f(null),o(``));async function a(){try{let n=t.resolve(e),a=n??t.resolveByAlias(e);if(!a){r&&!i&&(m(!0),c(!1));return}let s=a.ownerNoteId??`effort/${a.slug}`;if(!r&&v.current?.id===s){i||(f(a),g(!n));return}if(!r&&v.current)return;let l=await Z.getNote(s);if(i)return;f(a),g(!n),v.current={id:s,revision:l?.sourceRevision??0},o(l?.rawContent??ll(a)),m(!1),c(!1)}catch(e){i||(u(e instanceof Error?e.message:`Failed to load effort.`),c(!1))}}return a(),()=>{i=!0}},[e,n,r,t]);let b=(0,U.useCallback)(async t=>{if(!e&&!d)return;let{effort:n,errors:r}=cl(t,d??void 0);if(r.length>0)throw Q({title:`Invalid YAML`,description:r.join(`
460
460
  `),variant:`destructive`}),Error(r.join(`
461
- `));let a=t,o=n.slug.trim().toLowerCase().replace(/\s+/g,`-`);if(o!==n.slug&&(n.slug=o,a=Za(a,[`slug`],o)),n.label.trim()!==n.label&&(n.label=n.label.trim(),a=Za(a,[`label`],n.label)),n.updatedAt=new Date().toISOString(),n.registrySource===`bundled`){let e=n8(a,n.slug,n.label);a=e.raw,n.id=e.id,n.slug=e.slug,n.label=e.label,n.registrySource=`user`,n.derivation={parentSlug:d?.slug,coefficients:{},hardOverrides:{}}}try{let e=n.ownerNoteId??v.current?.id??`effort/${n.slug}`,t=v.current?.id===e?v.current.revision:0,r=await e8({kind:`effort`,slug:n.slug,rawContent:a,title:n.label,expectedSourceRevision:t});v.current={id:r.id,revision:r.sourceRevision},await i(),f(n)}catch(e){throw Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save effort.`,variant:`destructive`}),e}},[e,d,i]),{onChange:x,onLineChange:S,onBlur:C,flush:w}=B1({onSave:b});return{document:a,setDocument:(0,U.useCallback)(e=>{o(e),x(e)},[x]),isLoading:s,effort:d,isEditable:_,notFound:p,flush:w,onLineChange:S,onBlur:C,save:(0,U.useCallback)(e=>b(e??a),[b,a]),remove:(0,U.useCallback)(async()=>{let t=d?.slug??e;if(t)try{await t8(`effort`,t),v.current=null,f(null),await i()}catch(e){throw Q({title:`Delete failed`,description:e instanceof Error?e.message:`Failed to delete effort.`,variant:`destructive`}),e}},[d,e,i]),cloneForEdit:(0,U.useCallback)(async()=>{if(!d||d.registrySource!==`bundled`)return null;let e=n8(a||ll(d),d.slug,d.label),t={...d,id:e.id,slug:e.slug,label:e.label,registrySource:`user`,derivation:{parentSlug:d.slug,coefficients:{},hardOverrides:{}},ownerNoteId:`effort/${e.slug}`,sourceId:`efforts`,sourcePath:`effort/${e.slug}`,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};f(t),o(e.raw);try{let t=await e8({kind:`effort`,slug:e.slug,rawContent:e.raw,title:e.label,expectedSourceRevision:0});v.current={id:t.id,revision:t.sourceRevision},await i()}catch(e){throw Q({title:`Clone not saved`,description:e instanceof Error?e.message:`Failed to save the cloned copy.`,variant:`destructive`}),e}return t},[d,a,i]),error:l,isAliasMatch:h}}function i8({resolved:e,effort:t}){return(0,W.jsxs)(`div`,{className:`my-6 p-4 border rounded-lg bg-muted/30 space-y-4`,children:[(0,W.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,W.jsx)(Ye,{className:`size-4`}),`Effective Resolution`]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase`,children:`Effective MET`}),(0,W.jsx)(`p`,{className:`text-xl font-bold`,children:e.met.toFixed(1)}),Math.abs(e.met-(t.baseAttributes.met||0))>.01&&(0,W.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`(base: `,t.baseAttributes.met.toFixed(1),`)`]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase`,children:`Discipline Factor`}),(0,W.jsxs)(`p`,{className:`text-xl font-bold`,children:[e.disciplineFactor.toFixed(2),`×`]})]})]}),Object.keys(e.modifiers).length>0&&(0,W.jsxs)(`div`,{className:`border-t pt-3`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase mb-2`,children:`Applied Modifiers`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(e.modifiers).map(([e,t])=>(0,W.jsxs)(X6,{variant:`outline`,children:[e,`: `,t]},e))})]}),e.definition.derivation?.parentSlug&&(0,W.jsxs)(`div`,{className:`border-t pt-3 text-sm`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase mb-1`,children:`Parent`}),(0,W.jsx)(`span`,{className:`font-mono text-primary`,children:e.definition.derivation.parentSlug})]})]})}function a8(){let{slug:e}=wt(),[t]=cn(),n=Vn(),{theme:r}=Mi(),i=r===`dark`?`dark`:`vs`,{registry:a,isReady:o,refresh:s}=yM(),{document:c,setDocument:l,isLoading:u,effort:d,isEditable:f,notFound:p,cloneForEdit:m,error:h,onLineChange:g,onBlur:_,flush:v}=r8(e),[y,b]=(0,U.useState)([]),[x]=(0,U.useState)([]),[S,C]=(0,U.useState)(null),[T,E]=(0,U.useState)(!1),D=zN(t).mode===`create`,[O,k]=(0,U.useState)(()=>{let t=e&&e!==`new`?e.trim().toLowerCase().replace(/\s+/g,`-`):``,n=t?EO(t):``;return ll({id:`effort-user-${crypto.randomUUID()}`,slug:t,label:n,aliases:t?[t.replace(/[-_]+/g,` `)]:[],baseAttributes:{met:5},registrySource:`user`,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()})}),[A,j]=(0,U.useState)(!1),[M,P]=(0,U.useState)(``),F=(0,U.useMemo)(()=>a?[...a.list()].sort((e,t)=>e.label.localeCompare(t.label)):[],[a]),I=(0,U.useCallback)(async()=>{if(!(!e||!M||!a))try{await yl(a,M,e),await s(),Q({title:`Alias Linked`,description:`Linked "${e}" as an alias to ${M}.`}),n(RN(M))}catch(e){Q({title:`Failed to link alias`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[e,M,a,s,n]),L=(0,U.useCallback)(async()=>{let{effort:e,errors:t}=cl(O);if(t.length>0){Q({title:`Invalid YAML`,description:t.join(`
462
- `),variant:`destructive`});return}let r=e.slug.trim();if(!r){Q({title:`Missing slug`,description:`A unique slug is required.`,variant:`destructive`});return}if(!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(r)){Q({title:`Invalid slug`,description:`Slug must be lowercase and hyphenated — fix "slug: ${r}" in the document.`,variant:`destructive`});return}try{await e8({kind:`effort`,slug:r,rawContent:O,title:e.label.trim()||EO(r),expectedSourceRevision:0}),await s(),n(RN(r),{replace:!0})}catch(e){Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save effort.`,variant:`destructive`})}},[O,s,n]),ee=(0,U.useMemo)(()=>new ml(a),[a]),te=(0,U.useMemo)(()=>!d||!o?null:ee.resolveEffort(d.slug),[d,o,ee]),ne=(0,U.useCallback)(async t=>{try{let r=await U1({workoutName:d?.label??e??`Effort`,category:`effort`,sourceNotePath:RN(e??``),wodContent:t.content}),i=Object.values(r.blocks??{}).find(e=>e.kind===`wod`);if(!i)throw Error(`The saved journal workout is unavailable.`);let a=w();W1.set(a,{block:{...t,id:i.id},noteId:r.id}),n(`/run/${a}`)}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[e,d?.label,n]),R=(0,U.useCallback)(async(e,t)=>{if(!d)return;let r=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;try{await U1({workoutName:d.label,category:`effort`,sourceNoteLabel:d.label,sourceNotePath:RN(d.slug),wodContent:e.content,date:t}),n(CN(r)),Q({title:`Scheduled`,description:`Added to journal for ${r}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>n(CN(r)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not schedule workout`,variant:`destructive`})}},[d,n]);Q1({content:c,scriptBlocks:y,onStartWorkout:ne,results:x});let re=d?.ownerNoteId??`effort/${e}`,ie=(0,U.useMemo)(()=>e?r0({id:re,type:`note`}):null,[e,re]),ae=l0({noteId:re,stamps:ie?.stamps??[],effortSlug:e}),oe=d0(`notebook-readonly`,{onPlay:ne,onShare:_0,onSchedule:C});(0,U.useEffect)(()=>{d&&(window.document.title=`Wod.Wiki - ${d.label}`)},[d]);let se=(0,U.useCallback)(async()=>{if(d)try{let e=await m();e&&(n(RN(e.slug)),Q({title:`Cloned`,description:`Created a custom copy of "${d.label}". You can now edit it.`}))}catch(e){Q({title:`Clone failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[m,d,n]);if(!o)return(0,W.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,W.jsx)(`div`,{className:`animate-pulse h-4 w-32 bg-muted rounded`})});if(D){let t=(0,W.jsx)(RV,{primary:(0,W.jsx)(K,{onClick:L,"data-testid":`effort-create-btn`,children:`Create Effort`}),children:(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(NN()),children:`Cancel`})});return(0,W.jsx)(`div`,{"data-testid":BU.EFFORT_DETAIL_ROOT,className:`contents`,children:(0,W.jsx)(KB,{title:e&&e!==`new`?`New effort: ${e}`:`Create Custom Effort`,actions:t,editor:(0,W.jsx)(`div`,{className:`relative`,"data-testid":`effort-create-editor`,children:(0,W.jsx)(YZ,{value:O,onChange:k,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,commands:oe,onBlocksChange:b})})})})}if(u)return(0,W.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,W.jsx)(`div`,{className:`animate-pulse h-4 w-32 bg-muted rounded`})});if(h)return(0,W.jsxs)(`div`,{"data-testid":`effort-load-error`,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Effort could not be loaded`}),(0,W.jsx)(`p`,{className:`text-sm text-destructive`,children:h})]}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(NN()),children:`Back to library`})]});if(p||!d)return(0,W.jsxs)(`div`,{"data-testid":BU.EFFORT_NOT_FOUND,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:[`Effort “`,e,`” not found`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This movement has not been populated in the effort catalog yet. You can create a new definition page for it or link it as an alias to an existing effort.`})]}),A?(0,W.jsxs)(`div`,{className:`w-full space-y-4 p-4 border rounded-lg bg-card text-left`,children:[(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`label`,{className:`text-xs font-medium text-foreground`,children:[`Select target effort for “`,e,`”:`]}),(0,W.jsx)(Z6,{value:M,onChange:e=>P(e.target.value),"data-testid":BU.EFFORT_NOT_FOUND_ALIAS_SELECT,children:F.map(e=>(0,W.jsxs)(`option`,{value:e.slug,children:[e.label,` (`,e.slug,`)`]},e.slug))})]}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>j(!1),children:`Cancel`}),(0,W.jsx)(K,{size:`sm`,onClick:I,disabled:!M,"data-testid":BU.EFFORT_NOT_FOUND_ALIAS_CONFIRM,children:`Confirm Link`})]})]}):(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[(0,W.jsx)(K,{onClick:()=>n(RN(e,void 0,{mode:`create`})),"data-testid":BU.EFFORT_NOT_FOUND_CREATE_BTN,children:`Create Effort Page`}),(0,W.jsx)(K,{variant:`secondary`,onClick:()=>{j(!0),F.length>0&&!M&&P(F[0].slug)},"data-testid":BU.EFFORT_NOT_FOUND_ALIAS_BTN,children:`Link as Alias`}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(NN()),children:`Back to library`})]})]});let ce=(0,W.jsxs)(RV,{primary:f?void 0:(0,W.jsxs)(K,{variant:`outline`,onClick:se,"data-testid":BU.EFFORT_DETAIL_CLONE_BTN,children:[(0,W.jsx)(xe,{className:`size-4 mr-1.5`}),`Clone`]}),children:[(0,W.jsx)(K,{variant:`ghost`,size:`icon`,onClick:()=>SU()?n(-1):n(NN()),"aria-label":`Back to catalog`,title:SU()?`Back`:`Back to catalog`,children:(0,W.jsx)(N,{className:`size-4`})}),(0,W.jsx)(X6,{"data-testid":BU.EFFORT_DETAIL_SOURCE,variant:d.registrySource===`bundled`?`secondary`:`default`,children:d.registrySource===`bundled`?`Bundled`:`Custom`}),te&&(0,W.jsxs)(K,{variant:T?`default`:`outline`,onClick:()=>E(e=>!e),children:[(0,W.jsx)(Ye,{className:`size-4 mr-1.5`}),T?`Hide Resolved`:`Show Resolved`]})]}),le=re;return(0,W.jsxs)(`div`,{"data-testid":BU.EFFORT_DETAIL_ROOT,className:`contents`,children:[(0,W.jsx)(KB,{title:d.label,titleTestId:BU.EFFORT_DETAIL_LABEL,actions:ce,editor:(0,W.jsxs)(`div`,{className:`relative`,"data-testid":BU.EFFORT_DETAIL_NOTEBOOK_EDITOR,children:[T&&te&&(0,W.jsx)(`div`,{className:`px-6 lg:px-10 pt-4`,children:(0,W.jsx)(i8,{resolved:te,effort:d})}),(0,W.jsx)(YZ,{noteId:le,value:c,onChange:l,onCursorPositionChange:g,onBlur:_,onSaveRequest:v,onCommitChange:v,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,commands:oe,onBlocksChange:b}),(0,W.jsx)(u0,{data:ae,up:ie?.up,relatedLabel:`Used in`})]})}),S&&(0,W.jsx)(OC,{open:!0,onClose:()=>C(null),title:`Schedule workout`,children:(0,W.jsx)(z1,{selectedDate:null,onDateSelect:e=>{R(S,e),C(null)}})})]})}function o8(e,t){let n=t??e.replace(/[-_]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());return fl({id:`equipment-user-${crypto.randomUUID()}`,slug:e,label:n||e,aliases:[],registrySource:`user`})}function s8(e,t,n){let r=`equipment-user-${crypto.randomUUID()}`,i=`${t}-custom`,a=`${n} (Custom)`,o=Za(e,[`id`],r);return o=Za(o,[`slug`],i),o=Za(o,[`label`],a),o=Za(o,[`registrySource`],`user`),{raw:o,id:r,slug:i,label:a}}function c8(e){let{registry:t,isReady:n,refresh:r}=xM(),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(!0),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(!1),g=u?.registrySource===`user`,_=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!n){s(!1);return}if(!e){d(null),p(!1),h(!1),_.current=null,l(null),s(!1);return}let r=!1;s(!0),l(null),p(!1),d(null),a(``);async function i(){try{let n=t.resolve(e),i=n??t.resolveByAlias(e);if(!i){r||(p(!0),s(!1));return}let o=i.ownerNoteId??`equipment/${i.slug}`,c=await Z.getNote(o);if(r)return;d(i),h(!n),_.current={id:o,revision:c?.sourceRevision??0},a(c?.rawContent??fl(i)),s(!1)}catch(e){r||(l(e instanceof Error?e.message:`Failed to load equipment.`),s(!1))}}return i(),()=>{r=!0}},[e,n,t]);let v=(0,U.useCallback)(async e=>{let{equipment:t,errors:n}=dl(e,u??void 0);if(n.length>0)throw Q({title:`Invalid YAML`,description:n.join(`
461
+ `));let a=t,o=n.slug.trim().toLowerCase().replace(/\s+/g,`-`);if(o!==n.slug&&(n.slug=o,a=Za(a,[`slug`],o)),n.label.trim()!==n.label&&(n.label=n.label.trim(),a=Za(a,[`label`],n.label)),n.updatedAt=new Date().toISOString(),n.registrySource===`bundled`){let e=n8(a,n.slug,n.label);a=e.raw,n.id=e.id,n.slug=e.slug,n.label=e.label,n.registrySource=`user`,n.derivation={parentSlug:d?.slug,coefficients:{},hardOverrides:{}}}try{let e=n.ownerNoteId??v.current?.id??`effort/${n.slug}`,t=v.current?.id===e?v.current.revision:0,r=await e8({kind:`effort`,slug:n.slug,rawContent:a,title:n.label,expectedSourceRevision:t});v.current={id:r.id,revision:r.sourceRevision},await i(),f(n)}catch(e){throw Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save effort.`,variant:`destructive`}),e}},[e,d,i]),{onChange:x,onLineChange:S,onBlur:C,flush:w}=O1({onSave:b});return{document:a,setDocument:(0,U.useCallback)(e=>{o(e),x(e)},[x]),isLoading:s,effort:d,isEditable:_,notFound:p,flush:w,onLineChange:S,onBlur:C,save:(0,U.useCallback)(e=>b(e??a),[b,a]),remove:(0,U.useCallback)(async()=>{let t=d?.slug??e;if(t)try{await t8(`effort`,t),v.current=null,f(null),await i()}catch(e){throw Q({title:`Delete failed`,description:e instanceof Error?e.message:`Failed to delete effort.`,variant:`destructive`}),e}},[d,e,i]),cloneForEdit:(0,U.useCallback)(async()=>{if(!d||d.registrySource!==`bundled`)return null;let e=n8(a||ll(d),d.slug,d.label),t={...d,id:e.id,slug:e.slug,label:e.label,registrySource:`user`,derivation:{parentSlug:d.slug,coefficients:{},hardOverrides:{}},ownerNoteId:`effort/${e.slug}`,sourceId:`efforts`,sourcePath:`effort/${e.slug}`,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};f(t),o(e.raw);try{let t=await e8({kind:`effort`,slug:e.slug,rawContent:e.raw,title:e.label,expectedSourceRevision:0});v.current={id:t.id,revision:t.sourceRevision},await i()}catch(e){throw Q({title:`Clone not saved`,description:e instanceof Error?e.message:`Failed to save the cloned copy.`,variant:`destructive`}),e}return t},[d,a,i]),error:l,isAliasMatch:h}}function i8({resolved:e,effort:t}){return(0,W.jsxs)(`div`,{className:`my-6 p-4 border rounded-lg bg-muted/30 space-y-4`,children:[(0,W.jsxs)(`h3`,{className:`text-sm font-semibold flex items-center gap-2`,children:[(0,W.jsx)(Ye,{className:`size-4`}),`Effective Resolution`]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-4 text-sm`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase`,children:`Effective MET`}),(0,W.jsx)(`p`,{className:`text-xl font-bold`,children:e.met.toFixed(1)}),Math.abs(e.met-(t.baseAttributes.met||0))>.01&&(0,W.jsxs)(`span`,{className:`text-xs text-amber-600 dark:text-amber-400`,children:[`(base: `,t.baseAttributes.met.toFixed(1),`)`]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase`,children:`Discipline Factor`}),(0,W.jsxs)(`p`,{className:`text-xl font-bold`,children:[e.disciplineFactor.toFixed(2),`×`]})]})]}),Object.keys(e.modifiers).length>0&&(0,W.jsxs)(`div`,{className:`border-t pt-3`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase mb-2`,children:`Applied Modifiers`}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:Object.entries(e.modifiers).map(([e,t])=>(0,W.jsxs)(X6,{variant:`outline`,children:[e,`: `,t]},e))})]}),e.definition.derivation?.parentSlug&&(0,W.jsxs)(`div`,{className:`border-t pt-3 text-sm`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground uppercase mb-1`,children:`Parent`}),(0,W.jsx)(`span`,{className:`font-mono text-primary`,children:e.definition.derivation.parentSlug})]})]})}function a8(){let{slug:e}=wt(),[t]=cn(),n=Vn(),{theme:r}=Mi(),i=r===`dark`?`dark`:`vs`,{registry:a,isReady:o,refresh:s}=yM(),{document:c,setDocument:l,isLoading:u,effort:d,isEditable:f,notFound:p,cloneForEdit:m,error:h,onLineChange:g,onBlur:_,flush:v}=r8(e),[y,b]=(0,U.useState)([]),[x]=(0,U.useState)([]),[S,C]=(0,U.useState)(null),[T,E]=(0,U.useState)(!1),D=zN(t).mode===`create`,[O,k]=(0,U.useState)(()=>{let t=e&&e!==`new`?e.trim().toLowerCase().replace(/\s+/g,`-`):``,n=t?EO(t):``;return ll({id:`effort-user-${crypto.randomUUID()}`,slug:t,label:n,aliases:t?[t.replace(/[-_]+/g,` `)]:[],baseAttributes:{met:5},registrySource:`user`,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()})}),[A,j]=(0,U.useState)(!1),[M,P]=(0,U.useState)(``),F=(0,U.useMemo)(()=>a?[...a.list()].sort((e,t)=>e.label.localeCompare(t.label)):[],[a]),I=(0,U.useCallback)(async()=>{if(!(!e||!M||!a))try{await yl(a,M,e),await s(),Q({title:`Alias Linked`,description:`Linked "${e}" as an alias to ${M}.`}),n(RN(M))}catch(e){Q({title:`Failed to link alias`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[e,M,a,s,n]),L=(0,U.useCallback)(async()=>{let{effort:e,errors:t}=cl(O);if(t.length>0){Q({title:`Invalid YAML`,description:t.join(`
462
+ `),variant:`destructive`});return}let r=e.slug.trim();if(!r){Q({title:`Missing slug`,description:`A unique slug is required.`,variant:`destructive`});return}if(!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(r)){Q({title:`Invalid slug`,description:`Slug must be lowercase and hyphenated — fix "slug: ${r}" in the document.`,variant:`destructive`});return}try{await e8({kind:`effort`,slug:r,rawContent:O,title:e.label.trim()||EO(r),expectedSourceRevision:0}),await s(),n(RN(r),{replace:!0})}catch(e){Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save effort.`,variant:`destructive`})}},[O,s,n]),ee=(0,U.useMemo)(()=>new ml(a),[a]),te=(0,U.useMemo)(()=>!d||!o?null:ee.resolveEffort(d.slug),[d,o,ee]),ne=(0,U.useCallback)(async t=>{try{let r=await j1({workoutName:d?.label??e??`Effort`,category:`effort`,sourceNotePath:RN(e??``),wodContent:t.content}),i=Object.values(r.blocks??{}).find(e=>e.kind===`wod`);if(!i)throw Error(`The saved journal workout is unavailable.`);let a=w();M1.set(a,{block:{...t,id:i.id},noteId:r.id}),n(`/run/${a}`)}catch(e){Q({title:`Workout not started`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[e,d?.label,n]),R=(0,U.useCallback)(async(e,t)=>{if(!d)return;let r=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`;try{await j1({workoutName:d.label,category:`effort`,sourceNoteLabel:d.label,sourceNotePath:RN(d.slug),wodContent:e.content,date:t}),n(CN(r)),Q({title:`Scheduled`,description:`Added to journal for ${r}`,action:(0,W.jsx)(wM,{altText:`Open journal`,onClick:()=>n(CN(r)),children:`Open`})})}catch{Q({title:`Error`,description:`Could not schedule workout`,variant:`destructive`})}},[d,n]);B1({content:c,scriptBlocks:y,onStartWorkout:ne,results:x});let re=d?.ownerNoteId??`effort/${e}`,ie=(0,U.useMemo)(()=>e?G1({id:re,type:`note`}):null,[e,re]),ae=Z1({noteId:re,stamps:ie?.stamps??[],effortSlug:e}),oe=$1(`notebook-readonly`,{onPlay:ne,onShare:a0,onSchedule:C});(0,U.useEffect)(()=>{d&&(window.document.title=`Wod.Wiki - ${d.label}`)},[d]);let se=(0,U.useCallback)(async()=>{if(d)try{let e=await m();e&&(n(RN(e.slug)),Q({title:`Cloned`,description:`Created a custom copy of "${d.label}". You can now edit it.`}))}catch(e){Q({title:`Clone failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[m,d,n]);if(!o)return(0,W.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,W.jsx)(`div`,{className:`animate-pulse h-4 w-32 bg-muted rounded`})});if(D){let t=(0,W.jsx)(RV,{primary:(0,W.jsx)(K,{onClick:L,"data-testid":`effort-create-btn`,children:`Create Effort`}),children:(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(NN()),children:`Cancel`})});return(0,W.jsx)(`div`,{"data-testid":BU.EFFORT_DETAIL_ROOT,className:`contents`,children:(0,W.jsx)(KB,{title:e&&e!==`new`?`New effort: ${e}`:`Create Custom Effort`,actions:t,editor:(0,W.jsx)(`div`,{className:`relative`,"data-testid":`effort-create-editor`,children:(0,W.jsx)(YZ,{value:O,onChange:k,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,commands:oe,onBlocksChange:b})})})})}if(u)return(0,W.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,W.jsx)(`div`,{className:`animate-pulse h-4 w-32 bg-muted rounded`})});if(h)return(0,W.jsxs)(`div`,{"data-testid":`effort-load-error`,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Effort could not be loaded`}),(0,W.jsx)(`p`,{className:`text-sm text-destructive`,children:h})]}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(NN()),children:`Back to library`})]});if(p||!d)return(0,W.jsxs)(`div`,{"data-testid":BU.EFFORT_NOT_FOUND,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:[`Effort “`,e,`” not found`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This movement has not been populated in the effort catalog yet. You can create a new definition page for it or link it as an alias to an existing effort.`})]}),A?(0,W.jsxs)(`div`,{className:`w-full space-y-4 p-4 border rounded-lg bg-card text-left`,children:[(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`label`,{className:`text-xs font-medium text-foreground`,children:[`Select target effort for “`,e,`”:`]}),(0,W.jsx)(Z6,{value:M,onChange:e=>P(e.target.value),"data-testid":BU.EFFORT_NOT_FOUND_ALIAS_SELECT,children:F.map(e=>(0,W.jsxs)(`option`,{value:e.slug,children:[e.label,` (`,e.slug,`)`]},e.slug))})]}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>j(!1),children:`Cancel`}),(0,W.jsx)(K,{size:`sm`,onClick:I,disabled:!M,"data-testid":BU.EFFORT_NOT_FOUND_ALIAS_CONFIRM,children:`Confirm Link`})]})]}):(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[(0,W.jsx)(K,{onClick:()=>n(RN(e,void 0,{mode:`create`})),"data-testid":BU.EFFORT_NOT_FOUND_CREATE_BTN,children:`Create Effort Page`}),(0,W.jsx)(K,{variant:`secondary`,onClick:()=>{j(!0),F.length>0&&!M&&P(F[0].slug)},"data-testid":BU.EFFORT_NOT_FOUND_ALIAS_BTN,children:`Link as Alias`}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(NN()),children:`Back to library`})]})]});let ce=(0,W.jsxs)(RV,{primary:f?void 0:(0,W.jsxs)(K,{variant:`outline`,onClick:se,"data-testid":BU.EFFORT_DETAIL_CLONE_BTN,children:[(0,W.jsx)(xe,{className:`size-4 mr-1.5`}),`Clone`]}),children:[(0,W.jsx)(K,{variant:`ghost`,size:`icon`,onClick:()=>SU()?n(-1):n(NN()),"aria-label":`Back to catalog`,title:SU()?`Back`:`Back to catalog`,children:(0,W.jsx)(N,{className:`size-4`})}),(0,W.jsx)(X6,{"data-testid":BU.EFFORT_DETAIL_SOURCE,variant:d.registrySource===`bundled`?`secondary`:`default`,children:d.registrySource===`bundled`?`Bundled`:`Custom`}),te&&(0,W.jsxs)(K,{variant:T?`default`:`outline`,onClick:()=>E(e=>!e),children:[(0,W.jsx)(Ye,{className:`size-4 mr-1.5`}),T?`Hide Resolved`:`Show Resolved`]})]}),le=re;return(0,W.jsxs)(`div`,{"data-testid":BU.EFFORT_DETAIL_ROOT,className:`contents`,children:[(0,W.jsx)(KB,{title:d.label,titleTestId:BU.EFFORT_DETAIL_LABEL,actions:ce,editor:(0,W.jsxs)(`div`,{className:`relative`,"data-testid":BU.EFFORT_DETAIL_NOTEBOOK_EDITOR,children:[T&&te&&(0,W.jsx)(`div`,{className:`px-6 lg:px-10 pt-4`,children:(0,W.jsx)(i8,{resolved:te,effort:d})}),(0,W.jsx)(YZ,{noteId:le,value:c,onChange:l,onCursorPositionChange:g,onBlur:_,onSaveRequest:v,onCommitChange:v,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,commands:oe,onBlocksChange:b}),(0,W.jsx)(Q1,{data:ae,up:ie?.up,relatedLabel:`Used in`})]})}),S&&(0,W.jsx)(OC,{open:!0,onClose:()=>C(null),title:`Schedule workout`,children:(0,W.jsx)(D1,{selectedDate:null,onDateSelect:e=>{R(S,e),C(null)}})})]})}function o8(e,t){let n=t??e.replace(/[-_]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());return fl({id:`equipment-user-${crypto.randomUUID()}`,slug:e,label:n||e,aliases:[],registrySource:`user`})}function s8(e,t,n){let r=`equipment-user-${crypto.randomUUID()}`,i=`${t}-custom`,a=`${n} (Custom)`,o=Za(e,[`id`],r);return o=Za(o,[`slug`],i),o=Za(o,[`label`],a),o=Za(o,[`registrySource`],`user`),{raw:o,id:r,slug:i,label:a}}function c8(e){let{registry:t,isReady:n,refresh:r}=xM(),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(!0),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(!1),g=u?.registrySource===`user`,_=(0,U.useRef)(null);(0,U.useEffect)(()=>{if(!n){s(!1);return}if(!e){d(null),p(!1),h(!1),_.current=null,l(null),s(!1);return}let r=!1;s(!0),l(null),p(!1),d(null),a(``);async function i(){try{let n=t.resolve(e),i=n??t.resolveByAlias(e);if(!i){r||(p(!0),s(!1));return}let o=i.ownerNoteId??`equipment/${i.slug}`,c=await Z.getNote(o);if(r)return;d(i),h(!n),_.current={id:o,revision:c?.sourceRevision??0},a(c?.rawContent??fl(i)),s(!1)}catch(e){r||(l(e instanceof Error?e.message:`Failed to load equipment.`),s(!1))}}return i(),()=>{r=!0}},[e,n,t]);let v=(0,U.useCallback)(async e=>{let{equipment:t,errors:n}=dl(e,u??void 0);if(n.length>0)throw Q({title:`Invalid YAML`,description:n.join(`
463
463
  `),variant:`destructive`}),Error(n.join(`
464
- `));let i=e,a=t.slug.trim().toLowerCase().replace(/\s+/g,`-`);if(a!==t.slug&&(t.slug=a,i=Za(i,[`slug`],a)),t.label.trim()!==t.label&&(t.label=t.label.trim(),i=Za(i,[`label`],t.label)),t.updatedAt=new Date().toISOString(),t.registrySource===`bundled`){let e=s8(i,t.slug,t.label);i=e.raw,t.id=e.id,t.slug=e.slug,t.label=e.label,t.registrySource=`user`}try{let e=t.ownerNoteId??_.current?.id??`equipment/${t.slug}`,n=_.current?.id===e?_.current.revision:0,a=await e8({kind:`equipment`,slug:t.slug,rawContent:i,title:t.label,expectedSourceRevision:n,noteId:e});_.current={id:a.id,revision:a.sourceRevision},await r(),d(t)}catch(e){throw Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save equipment.`,variant:`destructive`}),e}},[u,r]),{onChange:y,onLineChange:b,onBlur:x,flush:S}=B1({onSave:v});return{document:i,setDocument:(0,U.useCallback)(e=>{a(e),y(e)},[y]),isLoading:o,equipment:u,isEditable:g,notFound:f,flush:S,onLineChange:b,onBlur:x,save:(0,U.useCallback)(e=>v(e??i),[v,i]),remove:(0,U.useCallback)(async()=>{let e=u?.slug;if(e)try{await t8(`equipment`,e),_.current=null,d(null),await r()}catch(e){throw Q({title:`Delete failed`,description:e instanceof Error?e.message:`Failed to delete equipment.`,variant:`destructive`}),e}},[u,r]),cloneForEdit:(0,U.useCallback)(async()=>{if(!u||u.registrySource!==`bundled`)return null;let e=s8(i||fl(u),u.slug,u.label),t={...u,id:e.id,slug:e.slug,label:e.label,registrySource:`user`,ownerNoteId:`equipment/${e.slug}`,sourceId:`equipment`,sourcePath:`equipment/${e.slug}`,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};d(t),a(e.raw);try{let t=await e8({kind:`equipment`,slug:e.slug,rawContent:e.raw,title:e.label,expectedSourceRevision:0});_.current={id:t.id,revision:t.sourceRevision},await r()}catch(e){throw Q({title:`Clone not saved`,description:e instanceof Error?e.message:`Failed to save the cloned copy.`,variant:`destructive`}),e}return t},[u,i,r]),error:c,isAliasMatch:m}}function l8(e){let{isReady:t,registry:n}=xM(),{isReady:r,revision:i,registry:a}=yM(),[o,s]=(0,U.useState)({efforts:[],usedBy:[]});return(0,U.useEffect)(()=>{if(!t||!r||!e){s({efforts:[],usedBy:[]});return}let n=!1;async function i(){let t=a.list().filter(t=>t.equipment?.includes(e)??!1),r=await Z.getEquipmentUsage(e);n||s({efforts:t,usedBy:r})}return i(),()=>{n=!0}},[e,t,r,i,n,a]),o}function u8(){let{slug:e}=wt(),[t]=cn(),n=Vn(),{theme:r}=Mi(),i=r===`dark`?`dark`:`vs`,{isReady:a,refresh:o}=xM(),{document:s,setDocument:c,isLoading:l,equipment:u,isEditable:d,notFound:f,cloneForEdit:p,error:m,onLineChange:h,onBlur:g,flush:_}=c8(e),[v,y]=(0,U.useState)([]),b=t.get(`mode`)===`create`,[x,S]=(0,U.useState)(()=>o8(e&&e!==`new`?e.trim().toLowerCase().replace(/\s+/g,`-`):``)),C=(0,U.useCallback)(async()=>{let{equipment:e,errors:t}=dl(x);if(t.length>0){Q({title:`Invalid YAML`,description:t.join(`
465
- `),variant:`destructive`});return}let r=e.slug.trim();if(!r){Q({title:`Missing slug`,description:`A unique slug is required.`,variant:`destructive`});return}if(!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(r)){Q({title:`Invalid slug`,description:`Slug must be lowercase and hyphenated — fix "slug: ${r}" in the document.`,variant:`destructive`});return}try{await e8({kind:`equipment`,slug:r,rawContent:x,title:e.label.trim()||EO(r),expectedSourceRevision:0}),await o(),n(PN(r),{replace:!0})}catch(e){Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save equipment.`,variant:`destructive`})}},[x,o,n]);Q1({content:b?x:s,scriptBlocks:v});let w=u?.ownerNoteId??(e?`equipment/${e}`:``),T=(0,U.useMemo)(()=>w?r0({id:w,type:`collection`}):null,[w]),E=l0({noteId:w,stamps:T?.stamps??[]}),D=l8(u?.slug),O=(0,U.useMemo)(()=>({efforts:D.efforts.map(e=>({id:e.slug,title:e.label,to:RN(e.slug)})),related:D.usedBy.map(e=>({id:e.noteId,title:e.title,to:e0(e.noteId)})),backlinks:E.backlinks}),[D,E.backlinks]);(0,U.useEffect)(()=>{u&&(window.document.title=`Wod.Wiki - ${u.label}`)},[u]);let k=(0,U.useCallback)(async()=>{if(u)try{let e=await p();e&&(n(PN(e.slug)),Q({title:`Cloned`,description:`Created a custom copy of "${u.label}". You can now edit it.`}))}catch(e){Q({title:`Clone failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[p,u,n]);if(!a||l)return(0,W.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,W.jsx)(`div`,{className:`animate-pulse h-4 w-32 bg-muted rounded`})});if(b){let t=(0,W.jsx)(RV,{primary:(0,W.jsx)(K,{onClick:C,"data-testid":BU.EQUIPMENT_CREATE_BTN,children:`Create Equipment`}),children:(0,W.jsx)(K,{variant:`outline`,onClick:()=>n($.equipment),children:`Cancel`})});return(0,W.jsx)(`div`,{"data-testid":BU.EQUIPMENT_DETAIL_ROOT,className:`contents`,children:(0,W.jsx)(KB,{title:e&&e!==`new`?`New equipment: ${e}`:`New equipment`,actions:t,editor:(0,W.jsx)(`div`,{className:`relative`,"data-testid":`equipment-create-editor`,children:(0,W.jsx)(YZ,{value:x,onChange:S,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,onBlocksChange:y})})})})}if(m)return(0,W.jsxs)(`div`,{"data-testid":BU.EQUIPMENT_LOAD_ERROR,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Equipment could not be loaded`}),(0,W.jsx)(`p`,{className:`text-sm text-destructive`,children:m})]}),(0,W.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:(0,W.jsx)(K,{variant:`outline`,onClick:()=>n($.equipment),children:`Back to Equipment`})})]});if(f||!u)return(0,W.jsxs)(`div`,{"data-testid":BU.EQUIPMENT_NOT_FOUND,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:[`Equipment “`,e,`” not found`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No equipment definition exists for this slug yet. You can create a new definition page for it.`})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[(0,W.jsx)(K,{onClick:()=>n(`${PN(e??`new`)}?mode=create`),"data-testid":BU.EQUIPMENT_NOT_FOUND_CREATE_BTN,children:`Create Equipment Page`}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n($.equipment),children:`Back to Equipment`})]})]});let A=(0,W.jsxs)(RV,{primary:d?void 0:(0,W.jsxs)(K,{variant:`outline`,onClick:k,"data-testid":BU.EQUIPMENT_DETAIL_CLONE_BTN,children:[(0,W.jsx)(xe,{className:`size-4 mr-1.5`}),`Clone`]}),children:[(0,W.jsx)(K,{variant:`ghost`,size:`icon`,onClick:()=>SU()?n(-1):n($.equipment),"aria-label":`Back to Equipment`,title:SU()?`Back`:`Back to Equipment`,children:(0,W.jsx)(N,{className:`size-4`})}),(0,W.jsx)(X6,{"data-testid":BU.EQUIPMENT_DETAIL_SOURCE,variant:u.registrySource===`bundled`?`secondary`:`default`,children:u.registrySource===`bundled`?`Bundled`:`Custom`})]});return(0,W.jsx)(`div`,{"data-testid":BU.EQUIPMENT_DETAIL_ROOT,className:`contents`,children:(0,W.jsx)(KB,{title:u.label,titleTestId:BU.EQUIPMENT_DETAIL_LABEL,actions:A,editor:(0,W.jsxs)(`div`,{className:`relative`,"data-testid":BU.EQUIPMENT_DETAIL_NOTEBOOK_EDITOR,children:[(0,W.jsx)(YZ,{noteId:w,value:s,onChange:c,onCursorPositionChange:h,onBlur:g,onSaveRequest:_,onCommitChange:_,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,onBlocksChange:y}),(0,W.jsx)(u0,{data:O,up:T?.up,relatedLabel:`Used in`})]})})})}var d8=`wodwiki-user-calcs`,f8=1,p8=`calcs`,m8=`user-calc:`,h8;function g8(){return h8||=cr(d8,f8,{upgrade(e){e.objectStoreNames.contains(p8)||e.createObjectStore(p8,{keyPath:`id`})}}),h8}var _8={scope:`segment`};async function v8(){return VP?(await YP(m8)).map(e=>e.value).sort((e,t)=>t.updatedAt-e.updatedAt):(await(await g8()).getAll(p8)).sort((e,t)=>t.updatedAt-e.updatedAt)}async function y8(e){if(VP){await XP(m8+e.id,{id:e.id,lineForm:e.lineForm,updatedAt:e.updatedAt??Date.now()});return}await(await g8()).put(p8,{...e,updatedAt:e.updatedAt??Date.now()})}async function b8(e){if(VP)return ZP(m8+e);await(await g8()).delete(p8,e)}async function x8(){let e=await v8(),t=[],n=[];for(let r of e)try{let{defs:e}=Ep(r.lineForm,_8);t.push(...e)}catch(e){n.push({id:r.id,message:e instanceof Error?e.message:String(e)})}return{defs:t,errors:n}}var S8={segment:`per record`,workout:`at workout end`},C8=new Set([`segment`,`workout`]);function w8({initialTag:e}={}){let[t]=cn(),n=t.get(`tag`)??e,[r,i]=(0,U.useState)([]),[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)([]),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)(``),[h,g]=(0,U.useState)([]),[_,v]=(0,U.useState)(``),[y,b]=(0,U.useState)(``),[x,S]=(0,U.useState)(null),[C,w]=(0,U.useState)(!1),T=(0,U.useCallback)(async()=>{let[e,t]=await Promise.all([Z.getAllTags(),Z.getAllTagTypes()]),n=await x8().catch(()=>({defs:[],errors:[]}));i(e),o(t);let r=Bf.filter(e=>C8.has(e.scope)).map(e=>({name:e.id,grain:S8[e.scope]??e.scope}));for(let e of n.defs)C8.has(e.scope)&&r.push({name:e.id,grain:S8[e.scope]??e.scope});c(r)},[]);(0,U.useEffect)(()=>{T()},[T]),(0,U.useEffect)(()=>{if(!n||r.length===0)return;let e=r.find(e=>e.label===n);e&&u(e.id)},[n,r]);let E=r.find(e=>e.id===l)??null;(0,U.useEffect)(()=>{E&&(f(E.label),m(E.type??``),g(E.contributions??[]))},[E]);let D=bR(),O=(0,U.useMemo)(()=>Eo(D),[D]),k=async()=>{if(!E)return!1;let e=d.trim();return e.length===0?(S("A tag needs a name — that name is what `#slug` refers to."),!1):r.find(t=>t.id!==E.id&&t.label.trim()===e)?(S(`Another tag is already called "${e}".`),!1):(await Z.putTag({...E,label:e,type:p||void 0,contributions:h}),await Pj(),await T(),S(null),w(!0),!0)},A=async()=>{let e=_.trim();if(e.length===0){S(`A tag needs a name.`);return}if(r.some(t=>t.label.trim()===e)){S(`A tag called "${e}" already exists.`);return}let t={id:`tag-${e}-${Date.now().toString(36)}`,label:e,type:y||void 0,contributions:[],createdAt:Date.now()};await Z.putTag(t),await Pj(),await T(),u(t.id),v(``),S(null)},j=async()=>{E&&(await Z.deleteTag(E.id),await Pj(),await T(),u(null))},M=(e,t)=>{w(!1),g(n=>n.map((n,r)=>r===e?t:n))},N=e=>{g(t=>t.filter((t,n)=>n!==e))},P=(0,U.useMemo)(()=>{let e=new Set(a.map(e=>e.name));for(let t of r)t.type&&e.add(t.type);return p&&!e.has(p)&&e.add(p),[...e].sort()},[a,r,p]);return(0,W.jsxs)(`div`,{className:`max-w-4xl mx-auto p-6 space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-2`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Tags`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A tag is a named bundle a script can point at:`,` `,(0,W.jsxs)(`code`,{className:`font-mono`,children:[`5 reps @ 100 kg `,`#heavy`]}),`. What the tag brings applies to the line it sits on. A tag can contribute a metric (a typed value with a unit), another tag, or a function — a named calculation that runs where the tag applies.`]}),O.length>0&&(0,W.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`These tags apply each other in a loop: `,O.map(e=>e.join(` → `)).join(`; `),`. A loop contributes nothing.`]})]}),(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`New tag`}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-3`,children:[(0,W.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),A()},className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[200px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`,placeholder:`heavy`,value:_,onChange:e=>v(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`w-40`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Kind`}),(0,W.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-2 text-xs outline-none focus:border-primary`,value:y,onChange:e=>b(e.target.value),children:[(0,W.jsx)(`option`,{value:``,children:`—`}),P.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})]}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,className:`h-9`,children:[(0,W.jsx)(On,{className:`size-3.5 mr-1`}),` Add Tag`]})]}),x&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:x})]})]}),!E&&r.length>0&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground italic`,children:[`No tag is selected — open one from the `,(0,W.jsx)(`a`,{className:`text-primary hover:underline`,href:`/tags`,children:`tag catalogue`}),`.`]}),E&&(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground`,children:[`Edit `,E.label]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-4`,children:[(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Created `,new Date(E.createdAt).toLocaleDateString()]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[200px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 font-mono text-xs outline-none focus:border-primary`,value:d,onChange:e=>f(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`w-40`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Kind`}),(0,W.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-2 text-xs outline-none focus:border-primary`,value:p,onChange:e=>m(e.target.value),children:[(0,W.jsx)(`option`,{value:``,children:`—`}),P.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`Contributions`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs`,onClick:()=>g(e=>[...e,{kind:`metric`,type:``,value:``}]),children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Metric`]}),(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs`,onClick:()=>g(e=>[...e,{kind:`tag`,slug:``}]),children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Tag`]}),(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs`,onClick:()=>g(e=>[...e,{kind:`function`,name:``}]),children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Function`]})]})]}),h.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`This tag contributes nothing yet.`}):(0,W.jsx)(`div`,{className:`space-y-2`,children:h.map((e,t)=>(0,W.jsx)(T8,{contribution:e,tagOptions:r.filter(e=>e.id!==E.id).map(e=>e.label.trim()),functionOptions:s,onChange:e=>M(t,e),onRemove:()=>N(t)},t))})]}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(K,{type:`button`,size:`sm`,className:`h-9`,onClick:()=>void k(),children:`Save`}),(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-9`,onClick:()=>void j(),children:[(0,W.jsx)(Ue,{className:`size-3.5 mr-1`}),` Delete`]}),C&&(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground self-center`,children:`Saved`})]})]})]})]})}function T8({contribution:e,tagOptions:t,functionOptions:n,onChange:r,onRemove:i}){let a=`h-8 rounded-md border border-input bg-background px-2 text-xs outline-none focus:border-primary`;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.kind===`metric`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`input`,{"aria-label":`Metric type`,className:`${a} w-32 font-mono`,placeholder:`type`,value:e.type,onChange:t=>r({...e,type:t.target.value})}),(0,W.jsx)(`input`,{"aria-label":`Metric value`,className:`${a} w-32`,placeholder:`value`,value:String(e.value),onChange:t=>r({...e,value:t.target.value})}),(0,W.jsx)(`input`,{"aria-label":`Metric unit`,className:`${a} w-24`,placeholder:`unit`,value:e.unit??``,onChange:t=>r({...e,...t.target.value?{unit:t.target.value}:{unit:void 0}})})]}),e.kind===`tag`&&(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)(`select`,{"aria-label":`Applied tag`,className:`${a} w-48 font-mono`,value:e.slug,onChange:t=>r({...e,slug:t.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`choose a tag…`}),t.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})}),e.kind===`function`&&(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)(`select`,{"aria-label":`Function`,className:`${a} w-56 font-mono`,value:e.name,onChange:t=>r({...e,name:t.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`choose a function…`}),n.map(e=>(0,W.jsxs)(`option`,{value:e.name,children:[e.name,` — `,e.grain]},e.name))]})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Remove contribution`,className:`text-muted-foreground hover:text-destructive`,onClick:i,children:(0,W.jsx)(Ue,{className:`size-3.5`})})]})}var E8=`h-11 w-full rounded-md border border-input bg-background px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;function D8(e){return e.date?e.date:`/page/${e.slug??e.pageId}`}function O8({open:e,onOpenChange:t,entry:n,mode:r,provider:i,onSaved:a,onCloned:o}){let[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)([]),[h,g]=(0,U.useState)(!1),[_,v]=(0,U.useState)(null),y=(0,U.useRef)(!1),b=n.id,x=n.journalDate,S=n.sourceId;(0,U.useEffect)(()=>{e&&(c(r===`clone`?x??_P():``),u(``),f(S??``),v(null))},[e,r,b,x,S]),(0,U.useEffect)(()=>{if(!e||r!==`relationships`)return;let t=!1;return i.getRecords().then(e=>{t||m(e.filter(e=>e.id!==n.id&&e.seedOrigin!==`seed`&&!e.sourceId?.startsWith(`notebook:`)))}).catch(()=>{}),()=>{t=!0}},[e,r,i,n.id]);let C=r===`clone`,w=`note-placement-sources-${n.id}`,T=n.placements??[],E=()=>{y.current||t(!1)},D=async e=>{if(!y.current){y.current=!0,g(!0),v(null);try{a?.(await e()),t(!1)}catch{v(`Could not save — your fields are kept. Try again.`)}finally{y.current=!1,g(!1)}}},O=async()=>{if(y.current)return;let e=s.trim(),t=l.trim();if(!e&&!t){v(`Choose a journal date or a named page to place the note on.`);return}if(e&&t){v(`Choose a journal date OR a named page — a placement names one page, never both.`);return}if(e&&!yP(e)){v(`Enter a valid date (YYYY-MM-DD).`);return}let r=e?{date:e}:{slug:t};await D(()=>i.addRecordPlacement(n.id,r))},k=async e=>{await D(()=>i.removeRecordPlacement(n.id,e))},A=async e=>{let t=s.trim(),r=l.trim();if(!t&&!r){v(`Choose the journal date or named page to move the note to.`);return}if(t&&r){v(`Choose a journal date OR a named page — a move targets one page, never both.`);return}if(t&&!yP(t)){v(`Enter a valid date (YYYY-MM-DD).`);return}let a=t?{date:t}:{slug:r};await D(()=>i.moveRecordPlacement(n.id,e,a))};return(0,W.jsx)(OC,{open:e,onClose:E,title:C?`Clone note`:`Note placements`,description:C?`Independent copy. Results and attachments are not copied.`:void 0,presentation:`sheet`,footer:(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(K,{type:`button`,variant:`outline`,size:`lg`,onClick:E,disabled:h,children:`Cancel`}),(0,W.jsx)(K,{type:`submit`,form:`note-placement-form`,size:`lg`,disabled:h,children:h?`Saving…`:C?`Clone`:`Save lineage`})]}),children:(0,W.jsxs)(`form`,{id:`note-placement-form`,onSubmit:async e=>{if(e.preventDefault(),!y.current){y.current=!0,g(!0),v(null);try{let e=s.trim(),r=l.trim(),c=d.trim(),u=e===``?null:yP(e);if(e&&!u){v(`Enter a valid date (YYYY-MM-DD).`);return}if(C){if(!e&&!r){v(`Choose a destination date or named page for the clone.`);return}if(e&&r){v(`Choose a destination date OR a named page — a clone targets one page, never both.`);return}let i=await CP.create({journalDate:e||void 0,slug:r||void 0,title:n.title,rawContent:n.rawContent,tags:n.tags,sourceId:n.id,type:`journal`});o?.(i),t(!1);return}let f={};if(c!==(S??``)){if(c===``)f.sourceId=null;else try{let e=await CP.resolve(c);if(!e||e.id===n.id){v(`Source note not found.`);return}f.sourceId=e.id}catch{v(`Source note not found.`);return}}if(Object.keys(f).length===0){t(!1);return}let p=await i.updateRecord(n.id,f);a?.(p),t(!1)}catch{v(`Could not save — your fields are kept. Try again.`)}finally{y.current=!1,g(!1)}}},className:`flex flex-col gap-4`,noValidate:!0,children:[!C&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:`Note path`}),(0,W.jsxs)(`code`,{className:`rounded bg-muted px-2.5 py-1.5 font-mono text-xs text-muted-foreground select-all`,children:[`/notes/`,n.id]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The note keeps this address wherever it is placed.`})]}),!C&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:`Pages`}),T.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This note is not placed on any page yet.`}):(0,W.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:T.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded border border-border px-2.5 py-1.5`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:D8(e)}),(0,W.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(K,{type:`button`,variant:`outline`,size:`sm`,disabled:h,onClick:()=>void A(e.pageId),children:`Move`}),(0,W.jsx)(K,{type:`button`,variant:`outline`,size:`sm`,disabled:h,onClick:()=>void k(e.pageId),children:`Remove`})]})]},e.pageId))})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`label`,{htmlFor:`note-placement-date`,className:`text-sm font-medium`,children:`Journal date`}),(0,W.jsx)(`input`,{id:`note-placement-date`,type:`date`,className:E8,value:s,onChange:e=>c(e.target.value),disabled:h}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C?`Defaults to the note’s date.`:`The calendar page to place the note on, or to move it to.`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`label`,{htmlFor:`note-placement-slug`,className:`text-sm font-medium`,children:`Named page`}),(0,W.jsx)(`input`,{id:`note-placement-slug`,type:`text`,className:E8,value:l,onChange:e=>u(e.target.value),placeholder:`e.g. marathon-block`,autoCapitalize:`none`,spellCheck:!1,disabled:h}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The /page/<slug> page to place the note on, or to move it to. Typing an existing page's slug shares that page with its notes — it does not create a unique copy.`})]}),!C&&(0,W.jsx)(K,{type:`button`,size:`lg`,disabled:h,onClick:()=>void O(),children:h?`Saving…`:`Place on this page`}),C?null:(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`label`,{htmlFor:`note-placement-source`,className:`text-sm font-medium`,children:`Source note`}),(0,W.jsx)(`input`,{id:`note-placement-source`,type:`text`,className:E8,value:d,onChange:e=>f(e.target.value),list:w,autoCapitalize:`none`,spellCheck:!1,disabled:h}),(0,W.jsx)(`datalist`,{id:w,children:p.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.title||`Untitled`},e.id))}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave empty to clear.`})]}),_&&(0,W.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:_})]})})}var k8=new Kk;function A8({noteId:e,theme:t}){let n=Vn(),r=Sn(),[i]=cn(),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(!1),l=(0,U.useRef)(0),u=(0,U.useRef)(null),d=(0,U.useRef)(async()=>{}),f=r.pathname.startsWith(`/page/`)||a!==null&&!ka(a,r_(a)),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!1),[y,b]=(0,U.useState)(null),x=(0,U.useCallback)(()=>{navigator.clipboard?.writeText(window.location.href).then(()=>{v(!0),setTimeout(()=>v(!1),1500)})},[]),C=LQ();(0,U.useEffect)(()=>{nz().catch(()=>{})},[e]),(0,U.useEffect)(()=>{let t=!1;return o(null),c(!1),m(null),k8.getRecord(e).then(e=>{if(!t){if(!e){c(!0);return}o(e),l.current=e.sourceRevision??0,u.current={rawContent:e.rawContent,blocks:e.blocks??{},sourceRevision:e.sourceRevision??0}}}).catch(()=>{t||c(!0)}),()=>{t=!0}},[e,i]);let T=a?.sourceId;(0,U.useEffect)(()=>{if(b(null),!T)return;let e=!1;return k8.getRecord(T).then(t=>{e||b(t)}).catch(()=>{}),()=>{e=!0}},[T]);let E=(0,U.useMemo)(()=>a?r0(a):{zone:null,up:null,stamps:[]},[a]);GM(E.zone);let[D,O]=(0,U.useState)([]),[k,A]=(0,U.useState)([]),j=a?.id;(0,U.useEffect)(()=>{if(A([]),O([]),!j)return;let e=!1,t=()=>{Z.getSessionsForNote(j).then(t=>{e||A(t)}).catch(()=>{})};t();let n=tK(n=>{!e&&n.noteId===j&&t()});return()=>{e=!0,n()}},[j]);let M=(0,U.useCallback)(async t=>{if(a)try{await d.current();let e=u.current;if(!e)throw Error(`The note draft is unavailable.`);let r=w(),i=await DR({noteId:a.id,rawContent:e.rawContent,blocks:e.blocks,expectedSourceRevision:l.current},t,r);l.current=i.note.sourceRevision,W1.set(r,{block:i.block,noteId:a.id,captured:i,returnTo:TN(a.id)}),n(ON(r))}catch(t){m({noteId:e,message:`Workout not started. ${t instanceof Error?t.message:String(t)} Your draft is kept.`})}},[a,e,n]);Q1({content:a?.rawContent??``,scriptBlocks:D,onStartWorkout:M,results:k});let N=l0(a?{noteId:a.id,stamps:E.stamps}:{noteId:``,stamps:[]}),P=(0,U.useCallback)(e=>{l.current=e.sourceRevision;let t=u.current,n=t?.rawContent===e.rawContent&&JSON.stringify(Object.values(t.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))===JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));o(t=>t&&{...t,...n?{blocks:e.blocks}:{},sourceRevision:e.sourceRevision})},[]),F=(0,U.useCallback)(async t=>{let n=await lP.saveNote({noteId:e,rawContent:t.rawContent,blocks:t.blocks,expectedSourceRevision:l.current});return P({rawContent:n.rawContent,blocks:n.blocks??{},sourceRevision:n.sourceRevision??l.current}),m(null),o(e=>e?.id===n.id?{...e,title:n.title}:e),{rawContent:n.rawContent,blocks:n.blocks??{},sourceRevision:n.sourceRevision??0}},[e,P]),{onChange:I,onBlur:L,onLineChange:ee,flush:te}=B1({onSave:async e=>{await F(e)},getSnapshotKey:e=>JSON.stringify([e.rawContent,Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])]),onError:t=>m({noteId:e,message:`Save failed. ${t instanceof Error?t.message:String(t)} Your draft is kept. Retry saving.`})});d.current=te;let ne=(0,U.useCallback)(e=>{let t=u.current?.rawContent!==e.rawContent||JSON.stringify(Object.values(u.current?.blocks??{}).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));u.current=e,t&&I(e)},[I]),R=(0,U.useCallback)(e=>{o(t=>t&&{...t,rawContent:e})},[]),re=(0,U.useCallback)(async e=>{await te();let t=u.current;if(!t)throw Error(`The note draft is unavailable.`);let n=rR({...t,sourceRevision:l.current},e),r=await F(n);u.current=r,o(e=>e&&{...e,...r})},[te,F]),ie=(0,U.useCallback)(()=>Promise.resolve(),[]),ae;if(s)ae=(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 text-zinc-400`,children:[(0,W.jsx)(`p`,{children:`Note not found.`}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(-1),children:`Go back`})]});else if(!a)ae=(0,W.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-zinc-400`,children:`Loading…`});else{let r=`inline-flex min-h-11 items-center gap-1 rounded-pill border border-border bg-card px-2.5 text-xs font-semibold text-muted-foreground transition-colors hover:bg-accent`,i=(0,W.jsxs)(RV,{label:`Note actions`,children:[(0,W.jsxs)(`button`,{type:`button`,className:r,onClick:()=>g(`relationships`),children:[(0,W.jsx)(Wt,{className:`size-3.5`,"aria-hidden":`true`}),`Note placements`]}),(0,W.jsxs)(`button`,{type:`button`,className:r,onClick:()=>g(`clone`),children:[(0,W.jsx)(rt,{className:`size-3.5`,"aria-hidden":`true`}),`Clone`]}),(0,W.jsxs)(`button`,{type:`button`,className:r,onClick:x,title:TN(a.id),"aria-label":`Copy link`,children:[_?(0,W.jsx)(un,{className:`size-3.5 text-emerald-500`,"aria-hidden":`true`}):(0,W.jsx)(S,{className:`size-3.5`,"aria-hidden":`true`}),_?`Copied`:`Copy link`]})]});ae=(0,W.jsxs)(IR,{notePersistence:lP,provider:k8,children:[(0,W.jsx)(KB,{title:a.title,subtitle:E.up?(0,W.jsx)(_n,{to:E.up.to,className:`underline-offset-2 hover:underline`,children:E.up.title}):void 0,actions:i,editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 py-6 sm:px-6 min-w-0 max-w-full`,children:[(0,W.jsx)(u0,{data:N,up:E.up}),(a.journalDate&&a.journalDate!==a.title||a.slug||a.sourceId)&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[a.journalDate&&a.journalDate!==a.title&&(0,W.jsx)(_n,{to:CN(a.journalDate),className:`underline-offset-2 hover:underline`,children:a.journalDate}),a.slug&&(0,W.jsxs)(_n,{to:jN(a.slug),className:`underline-offset-2 hover:underline`,children:[`/p/`,a.slug]}),a.sourceId&&(0,W.jsxs)(`span`,{children:[`Cloned from`,` `,y?(0,W.jsx)(_n,{to:TN(y.id),className:`underline-offset-2 hover:underline`,children:y.title||y.id}):(()=>{let e=i0(a.sourceId);return e?(0,W.jsx)(_n,{to:e.to,className:`underline-offset-2 hover:underline`,children:e.title}):a.sourceId})()]})]}),C?(0,W.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-4 shadow-sm min-h-[240px] focus-within:border-accent/80 transition-colors`,children:(0,W.jsx)(YZ,{value:a.rawContent,onChange:R,onBlur:L,noteId:a.id,noteBlocks:a.blocks,sourceRevision:a.sourceRevision,onIdentityChange:ne,onSaved:P,beforeRun:async()=>(await te(),l.current),onSaveRequest:te,onCommitChange:te,onCursorPositionChange:ee,readonly:f,theme:t,showLineNumbers:!1,onCompleteWorkout:ie,onBlocksChange:O,placeholder:`Write workout or notes here…`})}):(0,W.jsx)(`div`,{className:`flex items-center justify-center text-zinc-400 text-sm py-8`,children:`Loading…`}),(0,W.jsx)(iR,{noteId:a.id,blocks:a.blocks,sourceRevision:a.sourceRevision,onRevert:f?void 0:re}),p?.noteId===e&&(0,W.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:p.message})]})}),h!==null&&(0,W.jsx)(O8,{open:!0,onOpenChange:e=>{e||g(null)},entry:a,mode:h,provider:k8,onSaved:e=>o(t=>t&&t.id===e.id?{...t,journalDate:e.journalDate,slug:e.slug,sourceId:e.sourceId,placements:e.placements}:t),onCloned:e=>n(`${TN(e.id)}?edit=1`)})]})}return ae}var j8=new Kk;function M8({slug:e}){let[t,n]=(0,U.useState)(null);return(0,U.useEffect)(()=>{let t=!1;return n(null),j8.getPageRecords(e).then(e=>{t||n(e)}).catch(()=>{t||n([])}),()=>{t=!0}},[e]),(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6`,children:[(0,W.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,W.jsxs)(`h1`,{className:`text-2xl font-semibold`,children:[`/page/`,e]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t===null?`Loading…`:t.length===0?`No notes are placed on this page yet.`:`${t.length} ${t.length===1?`note`:`notes`} on this page.`})]}),t!==null&&t.length>0&&(0,W.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.map(e=>(0,W.jsx)(`li`,{children:(0,W.jsxs)(_n,{to:TN(e.id),className:`block rounded-md border border-border px-3 py-2 hover:bg-muted`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:e.title||`Untitled`}),(0,W.jsxs)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:[`/note/`,e.id]})]})},e.id))})]})}var N8=new Kk;function P8(e){let t=new Map;for(let n of e){let e=n.tags[0]?.toLowerCase()??`untagged`,r=t.get(e);r?r.push(n):t.set(e,[n])}return Array.from(t.entries()).map(([e,t])=>({id:`day-group-${e}`,label:e===`untagged`?`Untagged`:`#${e}`,entries:t}))}function F8(e){return gP(new Date(e.targetDate))}function I8({slug:e,date:t}){let[n,r]=(0,U.useState)(null);(0,U.useEffect)(()=>{let n=!1;return N8.getRecords().then(i=>{if(n)return;let a=i.filter(n=>n.sourceId?.startsWith(`notebook:${e}`)?F8(n)===t:!1);r(a.sort((e,t)=>t.createdAt-e.createdAt))}).catch(()=>{n||r([])}),()=>{n=!0}},[e,t]);let i=(0,U.useMemo)(()=>n?P8(n):[],[n]),{setL3Items:a}=WM();(0,U.useEffect)(()=>{if(i.length===0){a([]);return}let e=i.map(e=>({id:e.id,label:e.label,level:3,action:{type:`scroll`,sectionId:e.id}}));return a(e),()=>a([])},[i,a]);let o=n===null?(0,W.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-zinc-400`,children:`Loading…`}):n.length===0?(0,W.jsxs)(`p`,{className:`rounded-lg border border-dashed border-border p-6 text-sm text-muted-foreground`,children:[`No notes in this notebook for `,t,`.`]}):(0,W.jsx)(`div`,{className:`flex flex-col gap-6`,children:i.map(e=>(0,W.jsxs)(`section`,{id:e.id,className:`flex flex-col rounded-lg border border-border overflow-hidden`,children:[(0,W.jsxs)(`h3`,{className:`px-4 py-2 text-xs font-black uppercase tracking-wider text-muted-foreground bg-muted/40`,children:[e.label,` · `,e.entries.length]}),(0,W.jsx)(`ul`,{className:`flex flex-col divide-y divide-border`,children:e.entries.map(e=>(0,W.jsx)(`li`,{children:(0,W.jsxs)(_n,{to:TN(e.id),className:`flex flex-col gap-0.5 px-4 py-3 hover:bg-muted/50`,children:[(0,W.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.createdAt).toLocaleTimeString()})]})},e.id))})]},e.id))});return(0,W.jsx)(KB,{title:t,subtitle:e,editor:(0,W.jsx)(`div`,{className:`flex flex-col gap-6 px-4 py-6 sm:px-6`,children:o})})}var L8=`__new__`;function R8(e){return e.open?(0,W.jsx)(z8,{...e},e.subsetQuery??`(whole-store)`):null}function z8({onOpenChange:e,initialQuery:t,subsetQuery:n,rangeStart:r,rangeEnd:i,preferredUnit:a}){let o=Vn(),{items:s,loading:c}=pP(),l=s.filter(e=>e.editable),[u,d]=(0,U.useState)(l[0]?.slug??L8),[f,p]=(0,U.useState)(``),[m,h]=(0,U.useState)(null),g=()=>e(!1);return(0,W.jsx)(L2,{open:!0,onClose:g,mode:`add`,initialWql:t,subsetQuery:n,rangeStart:r,rangeEnd:i,preferredUnit:a,onApply:async e=>{h(null);let t={title:e.title,question:e.question,type:e.type,spanCols:e.spanCols,spanFull:e.spanFull,wql:e.wql,attributes:e.attributes};try{if(u===L8){let e=f.trim()||`New Dashboard`,n=await TP.createDashboard(e);await CP.update(n,bv(n.rawContent,t)),g(),o(LN(fv(e)))}else{let e=await CP.resolve(u);await CP.update(e,bv(e.rawContent,t)),g(),o(LN(u))}}catch(e){let t=e instanceof Error?e.message:String(e);throw h(t),e}},applyLabel:`Add to dashboard`,destination:(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Destination`}),c?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading dashboards…`}):(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[l.map(e=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":u===e.slug,onClick:()=>d(e.slug),className:`rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors ${u===e.slug?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:e.title},e.slug)),(0,W.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-dest-new`,"aria-pressed":u===L8,onClick:()=>d(L8),className:`flex items-center gap-1 rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors ${u===L8?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:[(0,W.jsx)(On,{className:`size-3`}),` New dashboard`]})]}),u===L8&&(0,W.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`New Dashboard`,"data-testid":`dashboard-new-title`,className:`w-full sm:w-64 rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary`})]}),m&&(0,W.jsxs)(`p`,{role:`alert`,"data-testid":`dashboard-save-error`,className:`mt-2 text-xs text-destructive font-mono`,children:[`Could not save: `,m]})]})})}function B8({catalog:e}){let[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(``);return(0,U.useEffect)(()=>{let t=!1,r=()=>{e.listByPrefix(a,50).then(e=>{t||n(e)}).catch(()=>{})};r();let i=e.onChange?.(()=>r());return()=>{t=!0,i?.()}},[e,a]),(0,W.jsxs)(`section`,{className:`rounded-lg border p-3 text-sm`,"data-testid":`available-fields`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between font-medium`,onClick:()=>i(e=>!e),children:[(0,W.jsxs)(`span`,{children:[`Available fields (`,t.length,`)`]}),(0,W.jsx)(`span`,{"aria-hidden":!0,children:r?`▾`:`▸`})]}),r&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`input`,{className:`mt-2 w-full rounded border px-2 py-1`,placeholder:`Filter fields…`,value:a,onChange:e=>o(e.target.value)}),(0,W.jsxs)(`ul`,{className:`mt-2 max-h-64 space-y-1 overflow-auto`,children:[t.map(e=>(0,W.jsxs)(`li`,{className:`flex items-baseline justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`font-mono`,children:e.path}),(0,W.jsxs)(`span`,{className:`text-xs opacity-70`,children:[e.kind,e.dimension?` · ${e.dimension}`:``,e.units.length?` · ${e.units.join(`/`)}`:``,e.spellings.length&&e.spellings[0]!==e.path?` · “${e.spellings[0]}”`:``]})]},e.id)),t.length===0&&(0,W.jsx)(`li`,{className:`opacity-60`,children:`No discovered fields for this prefix.`})]})]})]})}function V8(e){return{id:e.id,path:e.path,kind:e.kind,...e.dimension?{dimension:e.dimension}:{},units:Object.keys(e.units??{}),spellings:Object.keys(e.spellings??{})}}var H8=new class{storageInstance;listeners=new Set;constructor(e=jk){this.storageInstance=e}async listByPrefix(e,t=20){let n=e&&typeof IDBKeyRange<`u`?IDBKeyRange.bound(e,`${e}\uFFFF`,!1,!0):void 0;return(await this.storageInstance.readonly(`field_catalog`).getAllFromIndex(`by-path`,n,t)).map(V8)}async lookup(e){return(await this.storageInstance.readonly(`field_catalog`).getAllFromIndex(`by-path`,e)).map(V8)}async listValues(e,t,n=20){let r=await this.lookup(e),i=[];for(let e of r){if(i.length>=n)break;let r=t&&typeof IDBKeyRange<`u`?IDBKeyRange.bound([e.id,t],[e.id,`${t}\uFFFF`],!1,!0):void 0,a=await this.storageInstance.readonly(`field_values`).getAllFromIndex(`by-field`,r,n-i.length);for(let e of a)i.push({fieldId:e.fieldId,value:e.value})}return i}notifyChanged(){for(let e of this.listeners)e()}observeStore(e){}}(jk);function U8({label:e,value:t,className:n}){return(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded border border-border bg-background/60 px-2 py-1`,children:[(0,W.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:e}),(0,W.jsx)(`span`,{className:G(`font-mono text-xs`,n??`text-foreground`),children:t})]})}function W8(e){return e.kind===`relative`?`last ${e.size}${e.unit}`:e.end?`from ${e.start} to ${e.end}`:`from ${e.start}`}function G8({parsed:e}){if(e.error)return(0,W.jsx)(`div`,{className:`text-sm text-destructive font-mono`,children:e.error});if(Hm(e)){let t=e.source.kind===`dataset`?(0,W.jsx)(U8,{label:`source`,value:e.source.name,className:`text-blue-400 dark:text-blue-300`}):(0,W.jsx)(U8,{label:`source`,value:`target`in e.source.query?`:${e.source.query.target}`:`:${e.source.query.agg}`,className:`text-blue-400 dark:text-blue-300`});return(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t,e.transforms.map((e,t)=>(0,W.jsx)(U8,{label:`fn ${t+1}`,value:`${e.agg}:${e.metric}`,className:`text-green-400 dark:text-green-300`},t)),e.sink&&(0,W.jsx)(U8,{label:`sink`,value:`:${e.sink.head}`,className:`text-purple-400 dark:text-purple-300`})]})}let t=e.window&&(0,W.jsx)(U8,{label:`window`,value:W8(e.window),className:`text-sky-400 dark:text-sky-300`}),n=e.filters.map((e,t)=>(0,W.jsx)(U8,{label:e.negate?`exclude`:`filter`,value:`${e.key}:${e.values.map(e=>`${e.value}${e.wildcard?`*`:``}`).join(`|`)}`,className:`text-amber-400 dark:text-amber-300`},t));return Vm(e)?(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,W.jsx)(U8,{label:`aggregate`,value:e.agg,className:`text-blue-400 dark:text-blue-300`}),(0,W.jsx)(U8,{label:`metric`,value:e.metric}),n,e.groupBy.map((e,t)=>(0,W.jsx)(U8,{label:`group by`,value:e,className:`text-green-400 dark:text-green-300`},t)),e.rollup&&(0,W.jsx)(U8,{label:`rollup`,value:`${e.rollup.size}${e.rollup.unit}`,className:`text-purple-400 dark:text-purple-300`}),e.displayUnit&&(0,W.jsx)(U8,{label:`in`,value:e.displayUnit,className:`text-pink-400 dark:text-pink-300`}),t,e.join&&(0,W.jsx)(U8,{label:`where`,value:`:${e.join.target}`,className:`text-teal-400 dark:text-teal-300`})]}):Bm(e)?(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,W.jsx)(U8,{label:`target`,value:e.target,className:`text-blue-400 dark:text-blue-300`}),n,t,e.join&&(0,W.jsx)(U8,{label:`where`,value:`${e.join.agg}:${e.join.metric}`,className:`text-teal-400 dark:text-teal-300`})]}):null}function K8({result:e}){let{parsed:t,stages:n}=e;if(t.error)return null;let r=t.groupBy.find(e=>e===`day`||e===`week`),i=r?`by ${r}`:t.rollup?`rollup ${t.rollup.size}${t.rollup.unit}`:`no rollup`,a=t.groupBy.length?`by {${t.groupBy.join(`, `)}}`:`single series`,o=[{n:1,name:`SELECT`,desc:`tag + time index scan`,count:n.selected,unit:`points`},{n:2,name:`BUCKET`,desc:i,count:n.buckets,unit:`buckets`},{n:3,name:`AGGREGATE`,desc:`${t.agg} per bucket`,count:n.aggregated,unit:`values`},{n:4,name:`GROUP`,desc:a,count:n.groups,unit:`series`}];return(0,W.jsx)(`div`,{className:`flex items-center gap-0 mt-4 overflow-x-auto`,children:o.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(`div`,{className:`border border-border rounded-lg bg-background/60 px-3 py-2 min-w-[130px]`,children:[(0,W.jsxs)(`div`,{className:`text-[10px] font-bold tracking-wide`,style:{color:mS[t%mS.length]},children:[e.n,`. `,e.name]}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e.desc}),(0,W.jsxs)(`div`,{className:`text-sm font-semibold tabular-nums mt-0.5`,children:[e.count.toLocaleString(),` `,(0,W.jsx)(`span`,{className:`text-[10px] font-normal text-muted-foreground`,children:e.unit})]})]}),t<3&&(0,W.jsx)(wn,{size:16,className:`text-muted-foreground mx-1 shrink-0`})]},e.n))})}function q8({matched:e,displayUnit:t}){let[n,r]=(0,U.useState)(!1);if(e.length===0)return null;let i=e=>{let t=[];return e.effortSlug&&t.push(`effort:${e.effortSlug}`),e.discipline&&t.push(`discipline:${e.discipline}`),e.intensityTier&&t.push(`intensity:${e.intensityTier}`),e.origin&&t.push(`origin:${e.origin}`),t},a=e=>{let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`};return(0,W.jsxs)(`div`,{className:`bg-card border border-border rounded-lg mt-3`,children:[(0,W.jsxs)(`button`,{onClick:()=>r(!n),className:`w-full flex items-center gap-2 px-4 py-2.5 text-sm text-muted-foreground hover:text-foreground`,children:[n?(0,W.jsx)(Et,{size:14}):(0,W.jsx)(wn,{size:14}),`Raw metric points behind this query (`,e.length,`)`,(0,W.jsx)(`span`,{className:`text-[11px] ml-auto`,children:`one row per fact from the analytics store`})]}),n&&(0,W.jsxs)(`div`,{className:`px-4 pb-3 overflow-x-auto`,children:[(0,W.jsxs)(`table`,{className:`w-full text-[11px] font-mono`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`text-muted-foreground text-left border-b border-border`,children:[(0,W.jsx)(`th`,{className:`py-1.5 pr-4 font-normal`,children:`ts`}),(0,W.jsx)(`th`,{className:`py-1.5 pr-4 font-normal`,children:`metric`}),(0,W.jsx)(`th`,{className:`py-1.5 pr-4 font-normal`,children:`value`}),(0,W.jsx)(`th`,{className:`py-1.5 font-normal`,children:`tags`})]})}),(0,W.jsx)(`tbody`,{children:e.slice(0,12).map(e=>{let n=e.unit??e.metricUnit,r=typeof e.value==`number`?e.value:void 0,o=t&&r!==void 0&&n&&dg(n)===dg(t)?ug(r,n,t):void 0;return(0,W.jsxs)(`tr`,{className:`border-b border-border/40`,children:[(0,W.jsx)(`td`,{className:`py-1.5 pr-4 text-muted-foreground whitespace-nowrap`,children:a(e.timestamp)}),(0,W.jsx)(`td`,{className:`py-1.5 pr-4 text-primary whitespace-nowrap`,children:e.metricKey}),(0,W.jsxs)(`td`,{className:`py-1.5 pr-4 tabular-nums`,children:[String(e.value),n?` ${n}`:``,o!==void 0&&n!==t?` → ${o.toLocaleString()} ${t}`:``]}),(0,W.jsx)(`td`,{className:`py-1.5 text-muted-foreground`,children:i(e).map(e=>(0,W.jsx)(`span`,{className:`inline-block bg-background/80 rounded px-1.5 py-0.5 mr-1 mb-0.5`,children:e},e))})]},e.id)})})]}),e.length>12&&(0,W.jsxs)(`div`,{className:`text-[11px] text-muted-foreground pt-2`,children:[`… `,e.length-12,` more points`]})]})]})}var J8=[`totalVolume`,`tis`,`sessionLoad`,`totalReps`],Y8=[`effort`,`discipline`,`intensity`,`tags`,`note`,`origin`];function X8(){let[e,t]=(0,U.useState)(J8);return(0,U.useEffect)(()=>{let e=!1;async function n(){try{let n=Date.now(),r=n-31536e6,i=await sz.getFactsByTimeRange(r,n);if(e)return;let a=new Set([...J8,...i.map(e=>e.metricKey)].filter(e=>e!==void 0));t(Array.from(a).sort())}catch{}}return n(),()=>{e=!0}},[]),{metricKeys:e,tagKeys:Y8}}var Z8=[4,8,16],Q8=`sum:totalVolume{}`;function $8(e){let t=Number.parseInt(e??``,10);return Z8.includes(t)?t:16}function e5(e={}){let{defaultQuery:t=Q8,runOnLanding:n=!1}=e,[r,i]=cn(),a=r.get(`q`)??``,o=$8(r.get(`weeks`)),[s,c]=(0,U.useState)(()=>a&&!X(a).error?a:t),[l,u]=(0,U.useState)(a||(n?t:``)),d=(0,U.useRef)(s);d.current=s;let f=(0,U.useRef)(r);f.current=r;let p=(0,U.useRef)(!0),m=(0,U.useRef)(a);m.current=a;let h=(0,U.useRef)(a);(0,U.useEffect)(()=>{a!==h.current&&(h.current=a,d.current!==a&&(p.current=!0,c(a&&!X(a).error?a:t),u(a||(n?t:``))))},[a,t,n]);let g=(0,U.useRef)(t);return(0,U.useEffect)(()=>{t!==g.current&&(g.current=t,!a&&(c(t),u(n?t:``)))},[t,a,n]),{draft:s,setDraft:(0,U.useCallback)(e=>{if(e===d.current)return;let t=new URLSearchParams(f.current);t.set(`q`,e),i(t,{replace:!p.current}),p.current=!1,c(e)},[i]),submitted:l,submit:(0,U.useCallback)(e=>{let t=e??d.current;if(X(t).error)return;if(p.current&&m.current===t){u(t);return}let n=new URLSearchParams(f.current);n.set(`q`,t),i(n,{replace:!0}),p.current=!0,u(t)},[i]),weeks:o,setWeeks:(0,U.useCallback)(e=>{let t=new URLSearchParams(f.current);t.set(`weeks`,String(e)),i(t,{replace:!0})},[i])}}function t5({weeks:e,onWeeks:t,unitForced:n,onOpenQuerySettings:r}){let[i,a]=(0,U.useState)(!1),o=(0,U.useRef)(null),{unit:s,setUnit:c}=QS();(0,U.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[i]);let l=e=>()=>{e(),a(!1)};return(0,W.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),"data-testid":`explorer-options`,"aria-expanded":i,className:G(`flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs font-semibold transition-colors`,i?`border-primary/60 text-primary bg-primary/10`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`),children:[(0,W.jsx)(vn,{className:`size-3.5`}),`Options`,(0,W.jsx)(Et,{className:G(`size-3 transition-transform`,i&&`rotate-180`)})]}),i&&(0,W.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-xl border border-border bg-card shadow-xl p-1.5`,"data-testid":`explorer-options-menu`,children:[(0,W.jsx)(`div`,{className:`px-2 pt-1.5 pb-1 text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:`Range`}),Z8.map(n=>(0,W.jsxs)(`button`,{type:`button`,onClick:l(()=>t(n)),className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-foreground hover:bg-muted transition-colors`,children:[(0,W.jsx)(`span`,{className:`w-3.5 text-primary`,children:e===n?(0,W.jsx)(un,{className:`size-3.5`}):null}),`Past `,n,` weeks`]},n)),(0,W.jsxs)(`div`,{className:`mt-1 border-t border-border/60 px-2 pt-2 pb-1 text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:[`Units`,n?` — pinned by query`:``]}),[`kg`,`lb`].map(e=>(0,W.jsxs)(`button`,{type:`button`,disabled:n,onClick:l(()=>c(e)),className:G(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs transition-colors`,n?`text-muted-foreground/50 cursor-not-allowed`:`text-foreground hover:bg-muted`),children:[(0,W.jsx)(`span`,{className:`w-3.5 text-primary`,children:s===e?(0,W.jsx)(un,{className:`size-3.5`}):null}),e]},e)),r&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`mt-1 border-t border-border/60 px-2 pt-2 pb-1 text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:`This page`}),(0,W.jsxs)(`button`,{type:`button`,onClick:l(r),"data-testid":`explorer-query-settings`,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-foreground transition-colors hover:bg-muted`,children:[(0,W.jsx)(`span`,{className:`w-3.5 text-primary`}),`Query settings`]})]})]})]})}var n5=Z,r5=`sample`,i5=6048e5;function a5(e){return Math.round(e*10)/10}var o5={thruster:`high`,"pull-up":`high`,"push-up":`moderate`,"air-squat":`moderate`,"double-under":`high`,"sit-up":`low`,rowing:`moderate`,running:`moderate`,"recovery-run":`low`,"back-squat":`high`,deadlift:`high`},s5={fran:`high`,cindy:`moderate`,annie:`moderate`,rowing:`moderate`,running:`moderate`,strength:`high`,recoveryRun:`low`};function c5(e,t,n,r){return{effortSlug:n,discipline:r,reps:e,loadLbs:t,tisSeconds:a5(e*(n===`thruster`?2.2:1.6))}}function l5(e,t,n){let r=330-n*16,i=Math.max(180,a5(r+(Math.random()-.5)*20)),a=95+n*5;return{noteId:`sample-fran-${t}-${crypto.randomUUID()}`,title:`Sample — Fran (week ${16-t})`,workoutType:`fran`,timestamp:e-t*i5,durationSeconds:i,movements:[c5(45,a,`thruster`,`strength`),c5(45,0,`pull-up`,`gymnastics`)]}}function u5(e,t,n){let r=10+n+Math.round((Math.random()-.5)*2),i=Math.max(8,r);return{noteId:`sample-cindy-${t}-${crypto.randomUUID()}`,title:`Sample — Cindy (week ${16-t})`,workoutType:`cindy`,timestamp:e-t*i5,durationSeconds:1200,movements:[{effortSlug:`pull-up`,discipline:`gymnastics`,reps:i*5,loadLbs:0,tisSeconds:a5(i*5*1.5)},{effortSlug:`push-up`,discipline:`gymnastics`,reps:i*10,loadLbs:0,tisSeconds:a5(i*10*1.2)},{effortSlug:`air-squat`,discipline:`bodyweight`,reps:i*15,loadLbs:0,tisSeconds:a5(i*15*1.1)}]}}function d5(e,t,n){let r=540-n*22,i=Math.max(360,a5(r+(Math.random()-.5)*30));return{noteId:`sample-annie-${t}-${crypto.randomUUID()}`,title:`Sample — Annie (week ${16-t})`,workoutType:`annie`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`double-under`,discipline:`gymnastics`,reps:150,loadLbs:0,tisSeconds:a5(75)},{effortSlug:`sit-up`,discipline:`bodyweight`,reps:150,loadLbs:0,tisSeconds:a5(195)}]}}function f5(e,t,n){let r=135+n*5,i=185+n*5;return{noteId:`sample-strength-${t}-${crypto.randomUUID()}`,title:`Sample — Strength accessory (week ${16-t})`,workoutType:`strength`,timestamp:e-t*i5,durationSeconds:1800,movements:[{effortSlug:`back-squat`,discipline:`strength`,reps:25,loadLbs:r,tisSeconds:a5(62.5)},{effortSlug:`deadlift`,discipline:`strength`,reps:15,loadLbs:i,tisSeconds:a5(42)}]}}function p5(e,t,n){let r=2e3+n*250,i=a5(r/2+(Math.random()-.5)*30);return{noteId:`sample-rowing-${t}-${crypto.randomUUID()}`,title:`Sample — Rowing (week ${16-t})`,workoutType:`rowing`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`rowing`,discipline:`rowing`,reps:1,loadLbs:0,tisSeconds:i,distanceMeters:r}]}}function m5(e,t,n){let r=5e3+n*500,i=a5(r/2.8+(Math.random()-.5)*60);return{noteId:`sample-running-${t}-${crypto.randomUUID()}`,title:`Sample — Running (week ${16-t})`,workoutType:`running`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`running`,discipline:`running`,reps:1,loadLbs:0,tisSeconds:i,distanceMeters:r}]}}function h5(e,t,n){let r=3e3+n*50,i=a5(r/2.2+(Math.random()-.5)*60);return{noteId:`sample-recovery-run-${t}-${crypto.randomUUID()}`,title:`Sample — Recovery run (week ${16-t})`,workoutType:`recoveryRun`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`recovery-run`,discipline:`running`,reps:1,loadLbs:0,tisSeconds:i,distanceMeters:r}]}}function g5(e){let t=[];for(let n=0;n<16;n++){let r=Math.floor(n/4);t.push(f5(e,n,n)),n%4==0?t.push(l5(e,n,r)):n%4==1?t.push(u5(e,n,r)):n%4==2?t.push(d5(e,n,r)):n===3||n===11?t.push(p5(e,n,r)):(n===7||n===15)&&t.push(m5(e,n,r)),t.push(h5(e,n,n))}return t.sort((e,t)=>e.timestamp-t.timestamp)}function _5(e){let t=e.timestamp,n=s5[e.workoutType],r=e.movements.reduce((e,t)=>e+t.reps,0),i=e.movements.reduce((e,t)=>e+t.reps*t.loadLbs,0),a=e.movements.reduce((e,t)=>e+t.tisSeconds,0),o=e.movements.reduce((e,t)=>e+(t.distanceMeters??0),0),s=a5(i/100+r+e.durationSeconds/10),c=[],l=(e,n,r,i,a)=>{let o={canonicalKey:i};a?.effortSlug&&(o.effortSlug=a.effortSlug),a?.discipline&&(o.effortDiscipline=a.discipline),a?.intensityTier&&(o.effortIntensityTier=a.intensityTier);let s={id:c.length,outputType:`analytics`,timeSpan:{started:t},metrics:[{type:q.Label,value:e,origin:`analyzed`},{type:q.Metric,value:n,unit:r,metadata:o,origin:`analyzed`}],sourceBlockKey:``,stackLevel:0};c.push(s)};if(l(`Elapsed time`,e.durationSeconds,`s`,`elapsed`,{intensityTier:n}),l(`Total reps`,r,`reps`,`totalReps`,{intensityTier:n}),l(`Time in motion`,a5(a),`s`,`tis`,{intensityTier:n}),i>0&&l(`Total volume`,a5(i),`lb`,`totalVolume`,{intensityTier:n}),o>0){let t=e.movements.find(e=>e.distanceMeters&&e.distanceMeters>0)?.discipline;l(`Total distance`,a5(o),`m`,`totalDistance`,{discipline:t,intensityTier:n})}l(`Session load`,s,`AU`,`sessionLoad`,{intensityTier:n});for(let t of e.movements){let e=t.reps*t.loadLbs,n=o5[t.effortSlug]??`moderate`,r={effortSlug:t.effortSlug,discipline:t.discipline,intensityTier:n};l(`Total reps`,t.reps,`reps`,`totalReps`,r),l(`Time in motion`,t.tisSeconds,`s`,`tis`,r),e>0&&l(`Total volume`,a5(e),`lb`,`totalVolume`,r),l(`Session load`,a5(e/100+t.reps+t.tisSeconds/10),`AU`,`sessionLoad`,r)}return c}function v5(e,t){let n=`${`sample-${e.noteId}`}-result`,r=e.timestamp,i=r+e.durationSeconds*1e3;return{id:n,noteId:e.noteId,blockId:`sample-block`,blockVersion:1,blockContentId:t,origin:`journal`,status:`completed`,createdAt:Date.now(),startTime:r,endTime:i,duration:e.durationSeconds*1e3,completed:!0}}async function y5(){return(await n5.getTagByLabel(r5))?.id}async function b5(){return(await n5.getNotesForTag(r5)).map(e=>e.id)}async function x5(){let e=await b5();return e.length!==0&&(await n5.scanAll()).some(t=>e.includes(t.noteId))}async function S5(){if(await x5()){let e=await b5();return{facts:(await n5.scanAll()).filter(t=>t.grain===`summary`&&e.includes(t.noteId)).length}}let e=g5(Date.now()),t=0;for(let n of e){let e=n.movements.map(e=>`${e.distanceMeters?`${e.distanceMeters}m`:e.reps} ${e.effortSlug.replaceAll(`-`,` `)}${e.loadLbs?` ${e.loadLbs}lb`:``}`).join(`
466
- `),r=`# ${n.title}\n\n\`\`\`log\n${e}\n\`\`\`\n`,i=La(r,{sourceRevision:1,createId:()=>`sample-block`}),a=_5(n),o=v5(n,ba(e)),s={noteId:n.noteId,resultId:o.id,blockId:o.blockId,blockVersion:o.blockVersion,blockContentId:o.blockContentId,origin:o.origin,pageId:o.pageId,workoutTimestamp:n.timestamp};t+=await n5.withTransaction([`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`efforts`,`equipment`,`tags`,`note_tags`,`tag_types`,`sessions`,`events`],async e=>{await e.saveNoteSource({noteId:n.noteId,rawContent:r,blocks:i,expectedSourceRevision:0,metadata:{title:n.title},noteType:`playground`,createdAt:n.timestamp}),await e.setNoteTags(n.noteId,[r5]),await e.saveSession(o),await e.appendEvents(Kg(a,s));let t=qg(a,s);return await e.finalizeSummaries(o.id,t),t.length})}return{facts:t}}async function C5(){let e=await b5();if(e.length!==0){for(let t of e)await n5.deleteEvents((await n5.getEventsForNote(t)).map(e=>e.id)),await n5.deleteNote(t);if((await n5.getNotesForTag(r5)).length===0){let e=await y5();e&&await n5.deleteTag(e)}}}function w5({result:e,onChanged:t,layout:n=`inline`,refreshKey:r}){let[i,a]=(0,U.useState)(void 0),[o,s]=(0,U.useState)(!1),c=(0,U.useCallback)(async()=>{a(await x5()),s(!1)},[]);(0,U.useEffect)(()=>{c()},[c,r]);let l=async()=>{await S5(),await c(),t?.()},u=(0,W.jsxs)(`div`,{className:`flex items-center justify-center gap-3 rounded-md border border-border bg-muted/50 px-3 py-2 text-xs text-foreground`,children:[(0,W.jsx)(`span`,{children:`Sample data loaded`}),(0,W.jsx)(`button`,{onClick:async()=>{await C5(),await c(),t?.()},className:`font-medium text-destructive hover:text-destructive/80 transition-colors`,children:`Purge sample data`}),(0,W.jsx)(`button`,{onClick:()=>s(!0),className:`text-muted-foreground hover:text-foreground transition-colors`,"aria-label":`Dismiss`,children:(0,W.jsx)(we,{size:14})})]});if(n===`banner`)return i&&!o?u:null;let d=i?o?null:u:(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mb-2`,children:`Facts appear when you log or run workouts.`}),(0,W.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,W.jsx)(`button`,{onClick:l,className:`text-xs font-medium rounded-md bg-primary text-primary-foreground px-3 py-1.5 hover:opacity-90 transition-opacity`,children:`Preview with sample data`}),(0,W.jsx)(_n,{to:`/collections`,className:`text-xs text-primary underline-offset-2 hover:underline`,children:`Log your first workout`})]})]});return n===`card`?(0,W.jsxs)(`div`,{className:`bg-card border border-border rounded-lg p-6 flex flex-col items-center justify-center text-sm text-muted-foreground`,children:[e!==void 0&&(0,W.jsx)(sS,{result:e}),i!==void 0&&d&&(0,W.jsx)(`div`,{className:`mt-3`,children:d})]}):(0,W.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center`,children:[e!==void 0&&(0,W.jsx)(sS,{result:e}),i!==void 0&&d&&(0,W.jsx)(`div`,{className:`mt-3`,children:d})]})}var T5=`:dashboard{}`,E5=864e5,D5=`agg:metric{filters} by {dims} .rollup(period)`,O5=new Set([`tags`,`notebook`,`text`,`type`,`has`]);function k5(e){let t=e.find(e=>e.key===`source`&&!e.negate);return t?t.values.map(e=>e.value).join(`|`):null}function A5({entries:e,stickyOffset:t,idPrefix:n=``}){return(0,W.jsx)(`div`,{className:`-mx-4`,children:q4(e,`date`).map(e=>(0,W.jsxs)(`div`,{id:`${n}${e.id}`,className:`flex flex-col`,children:[(0,W.jsx)(BB,{top:t,icon:(0,W.jsx)(mn,{className:`size-3 shrink-0 text-muted-foreground`}),label:e.label,meta:(0,W.jsx)(`span`,{"data-testid":`library-group-count`,className:`font-bold tabular-nums`,children:e.entries.length})}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0 pb-1`,children:e.entries.map(e=>(0,W.jsx)(Z3,{entry:e,dateLabel:e.date?XH(e.date):void 0},e.block?`${e.id}#${e.block.blockId}`:e.id))})]},e.id))})}function j5(e,t){if(e===t)return!0;let n=X(e),r=X(t);return!n.error&&!r.error&&jh(n)===jh(r)}function M5({actions:e}){(0,U.useEffect)(()=>{},[]);let t=EF(`/dashboards`),{draft:n,setDraft:r,submitted:i,submit:a,weeks:o,setWeeks:s}=e5({defaultQuery:t.defaultWql??T5,runOnLanding:!0}),{unit:c}=QS(),{forced:l}=(0,U.useMemo)(()=>$S(i,c),[i,c]),[u,d]=(0,U.useState)(void 0),[f,p]=(0,U.useState)(void 0),[m,h]=(0,U.useState)(void 0),[g,_]=(0,U.useState)(void 0),[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(!1),[S,C]=(0,U.useState)(!1),[w,T]=(0,U.useState)(!0),E=X8(),D=t.typeOptions,O=(0,U.useMemo)(()=>X(n),[n]),k=k5(Bm(O)?O.filters:[]),A=Bm(O)&&O.window?W8(O.window):null,j=zB(104),M=!O.error&&n.trim().length>0,N=M&&w,P=(0,U.useMemo)(()=>{if(!M)return null;if(Bm(O))return n;if(Vm(O)&&O.join){let e=O.join;return jh({family:`find`,raw:``,target:e.target,filters:e.filters,window:e.last?{kind:`relative`,size:e.last.size,unit:e.last.unit}:void 0})}return null},[O,n,M]),F=(0,U.useMemo)(()=>{if(!i)return null;let e=X(i);if(Bm(e)||e.error)return null;if(e.join){let t=e.join;return jh({family:`find`,raw:``,target:t.target,filters:t.filters,window:t.last?{kind:`relative`,size:t.last.size,unit:t.last.unit}:void 0})}return jh({family:`find`,raw:``,target:`note`,filters:e.filters.filter(e=>O5.has(e.key)&&!e.negate),window:{kind:`relative`,size:o,unit:`w`}})},[i,o]);(0,U.useEffect)(()=>{if(!F){h(void 0);return}let e=!1;return Vz(F).then(t=>{e||h(t)}).catch(()=>{e||h(void 0)}),()=>{e=!0}},[F]);let[I,L]=(0,U.useState)(0),[ee,te]=(0,U.useState)(!1),[ne,R]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=!1;if(!i){d(void 0),p(void 0),_(void 0),y(!1);return}y(!0);let t=X(i);if(Bm(t))d(void 0),t.target===`effort`?sz.runFind(t).then(t=>{e||(_(t.efforts??[]),p([]))}).catch(()=>{e||(_(void 0),p(void 0))}).finally(()=>{e||y(!1)}):Vz(i).then(t=>{e||(p(t),_([]))}).catch(()=>{e||(p(void 0),_(void 0))}).finally(()=>{e||y(!1)});else{p(void 0),_(void 0);let t=Date.now(),n=t-o*7*E5;sz.runQuery(i,{rangeStart:n,rangeEnd:t,preferredUnit:c}).then(t=>{e||d(t)}).catch(()=>{e||d(void 0)}).finally(()=>{e||y(!1)})}return()=>{e=!0}},[i,o,I,c]);let re=oS(u),ie=e=>{let t=V3(n,e);r(t),a(t)},{setL3Items:ae}=WM(),oe=(0,U.useMemo)(()=>f!==void 0&&f.length>0?q4(f,`date`):[],[f]);(0,U.useEffect)(()=>{if(oe.length===0){ae([]);return}let e=oe.map(e=>({id:e.id,label:e.label,level:3,action:{type:`scroll`,sectionId:e.id}}));return ae(e),()=>ae([])},[oe,ae]);let se=EP.find(e=>e.query===i)?.question??`custom query`,ce=(0,U.useMemo)(()=>{let e=X(i);return e.error?i:jh(e)},[i]),le=u!==void 0&&(j5(u.parsed.raw,n)||u.parsed.raw===i&&n===ce),z=!i||!v&&re.kind===`empty`,ue=(0,W.jsxs)(`button`,{type:`button`,"data-testid":`inspect-pipeline`,"aria-expanded":ee,onClick:()=>te(e=>!e),className:`flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-semibold text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[ee?(0,W.jsx)(Et,{size:12}):(0,W.jsx)(wn,{size:12}),`Inspect pipeline`]});return(0,W.jsxs)(`div`,{className:`bg-card flex flex-col flex-1`,children:[(0,W.jsx)(B8,{catalog:H8}),(0,W.jsx)(u3,{surface:X4,open:S,onOpenChange:C}),(0,W.jsx)(NB,{title:`Metric Explorer`,actions:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(t5,{weeks:o,onWeeks:s,unitForced:l,onOpenQuerySettings:()=>C(!0)}),e]})}),(0,W.jsxs)(`div`,{className:`flex flex-col min-h-0 p-4`,children:[(0,W.jsx)(`div`,{className:`min-w-[280px]`,children:(0,W.jsx)(Kw,{query:n,onQueryChange:r,onValidationChange:e=>T(e.valid),onSubmit:e=>a(e),actionLabel:`Run`,preferredChoices:D,showDiagnostics:!1,placeholder:D5,diagnosticsActions:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`save-query`,disabled:!N,onClick:()=>x(!0),title:`Save this query — decide where it lands (dashboard, …)`,className:`flex min-h-12 items-center gap-1.5 rounded-lg border border-primary/40 text-primary px-3 text-[11px] font-semibold hover:bg-primary/10 transition-all shrink-0 disabled:opacity-40 disabled:hover:bg-transparent`,children:[(0,W.jsx)(ln,{size:12}),` Save`]})})}),(0,W.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-1.5 gap-y-1`,"data-testid":`explorer-meta`,children:[n.trim().length>0&&(0,W.jsx)(`span`,{"data-testid":`draft-validity`,className:`mr-1 inline-flex items-center gap-1 text-[11px]`,children:O.error?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono text-red-600`,children:[(0,W.jsx)(Qt,{size:11,className:`shrink-0`}),` `,O.error]}):(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-green-600`,children:[(0,W.jsx)(yn,{size:11,className:`shrink-0`}),` valid`]})}),E.metricKeys.map(e=>(0,W.jsx)(`button`,{type:`button`,disabled:!N||!Vm(O),title:M&&!Vm(O)?`Metric shortcuts apply to measure queries — pivot the kind through the composer first`:void 0,onClick:()=>ie(e),className:G(`rounded-full border px-2 py-0.5 text-[11px] font-mono transition-colors disabled:opacity-40 disabled:hover:bg-transparent`,n.includes(e)?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`),children:e},e)),(0,W.jsx)(`span`,{className:`mx-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground/50`,children:`filters`}),E.tagKeys.map(e=>(0,W.jsx)(`span`,{className:`rounded-full border border-border/60 px-2 py-0.5 text-[11px] font-mono text-muted-foreground/70`,children:e},e))]}),(0,W.jsx)(`section`,{className:`min-w-0`,children:Bm(O)?(0,W.jsx)(`div`,{className:`mt-3`,children:(0,W.jsxs)(`div`,{className:`bg-card border border-border rounded-lg p-4`,children:[(0,W.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-2`,children:[`Find `,O.target,k&&(0,W.jsxs)(`span`,{className:`ml-1`,children:[`in `,k]}),A&&(0,W.jsx)(`span`,{className:`ml-1`,children:A})]}),O.error?(0,W.jsx)(`div`,{className:`text-sm text-destructive font-mono`,children:O.error}):v?(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Searching…`}):g&&g.length>0?(0,W.jsx)(`div`,{className:`flex flex-col divide-y divide-border/50`,children:g.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center gap-3 py-2.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e.label}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:e.slug}),e.baseAttributes.discipline&&(0,W.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:e.baseAttributes.discipline})]},e.slug))}):f&&f.length>0?(0,W.jsx)(A5,{entries:f,stickyOffset:j}):(0,W.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`No `,O.target,`s found.`]})]})}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`mt-3`,children:(0,W.jsx)(w5,{layout:`banner`,refreshKey:I,onChanged:()=>L(e=>e+1)})}),O.error&&i&&(0,W.jsx)(`div`,{"data-testid":`explorer-results-stale`,className:`mt-3 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs font-medium text-amber-700`,children:`Stale — showing the last run's results; the current draft is invalid and not applied.`}),(0,W.jsx)(`div`,{className:`mt-3`,children:(0,W.jsx)(rS,{title:`Query result`,question:se,query:i||`(empty)`,children:(0,W.jsx)(`div`,{className:`h-64`,children:i?v?(0,W.jsx)(sS,{result:void 0}):re.kind===`error`?(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-destructive font-mono px-4 text-center`,children:re.message}):re.kind===`empty`?(0,W.jsxs)(`div`,{className:`h-full flex flex-wrap items-center justify-center gap-6`,children:[(0,W.jsx)(w5,{result:u,refreshKey:I,onChanged:()=>L(e=>e+1)}),ue]}):re.kind===`scalar`?(0,W.jsx)(cS,{result:u,label:`${u.parsed.agg}(${u.parsed.metric})`}):re.kind===`timeseries`?(0,W.jsx)(hS,{result:u}):(0,W.jsx)(gS,{result:u}):(0,W.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-3`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Enter a WQL query or choose an example to explore your data.`}),ue]})})})}),i&&(0,W.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[!v&&!z&&ue,F&&m!==void 0&&(0,W.jsxs)(`button`,{type:`button`,"data-testid":`records-toggle`,"aria-expanded":ne,onClick:()=>R(e=>!e),className:`flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-semibold text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[ne?(0,W.jsx)(Et,{size:12}):(0,W.jsx)(wn,{size:12}),`Records in this calculation`,(0,W.jsx)(`span`,{className:`text-[10px] font-bold text-muted-foreground/60 tabular-nums`,children:m.length})]})]}),ee&&(0,W.jsx)(`div`,{className:`mt-3`,"data-testid":`pipeline-anatomy`,children:i?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(G8,{parsed:le?u.parsed:O}),le&&(0,W.jsx)(K8,{result:u})]}):(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Submit a query to see its anatomy.`})}),ne&&F&&m!==void 0&&(0,W.jsxs)(`div`,{className:`mt-3`,children:[(0,W.jsx)(`code`,{className:`block mb-3 rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-xs text-foreground`,"data-testid":`records-wql`,children:F}),m.length===0?(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No records match this calculation.`}):(0,W.jsx)(A5,{entries:m,stickyOffset:j,idPrefix:`records-`})]}),u&&(0,W.jsx)(q8,{matched:u.matched,displayUnit:u.unit})]})})]}),(0,W.jsx)(R8,{open:b,onOpenChange:x,initialQuery:n,subsetQuery:P,rangeStart:Date.now()-o*7*E5,rangeEnd:Date.now(),preferredUnit:c})]})}var N5=2.20462,P5=2.54,F5=`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`;function I5(e){if(!e)return;let t=new Date(e);if(Number.isNaN(t.getTime()))return;let n=new Date,r=n.getFullYear()-t.getFullYear(),i=n.getMonth()-t.getMonth();return(i<0||i===0&&n.getDate()<t.getDate())&&r--,r}function L5(e){let t=(e??``).trim().split(/\s+/).filter(Boolean);return t.length===0?`?`:t.slice(0,2).map(e=>e[0].toUpperCase()).join(``)}function R5({unit:e,other:t,onSwitch:n}){return(0,W.jsx)(`div`,{className:`flex rounded-md border border-input overflow-hidden shrink-0`,role:`group`,children:[e,t].map((e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":t===0,onClick:t===1?n:void 0,className:G(`px-2.5 h-9 text-xs font-medium transition-colors`,t===0?`bg-primary/10 text-primary`:`bg-background text-muted-foreground hover:bg-muted`),children:e},e))})}function z5(){let[e,t]=(0,U.useState)(null),[n,r]=(0,U.useState)({displayName:``,birthDate:``,weight:``,height:``}),i=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=!0;return Ok.current().then(n=>{e&&t(n)}).catch(console.error),()=>{e=!1}},[]),(0,U.useEffect)(()=>{e&&r({displayName:e.displayName?.trim()||`Anonymous`,birthDate:e.birthDate??``,weight:e.weight==null?``:String(e.weight),height:e.height==null?``:String(e.height)})},[e?.id]);let a=(0,U.useCallback)(async e=>{try{t(await Ok.update(e))}catch(e){console.error(e)}},[]),o=(0,U.useCallback)(async e=>{if(e)try{await a({picture:await wx(e)})}catch(e){console.error(e)}},[a]);if(!e)return(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`profile-loading`,children:`Loading profile…`});let s=I5(e.birthDate),c=e.weightUnit??`kg`,l=e.heightUnit??`cm`;return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Me,{className:`size-4 text-primary`}),`Profile Picture`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Click the picture to choose an image — it is center-cropped and stored locally.`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i.current?.click(),"aria-label":`Change profile picture`,"data-testid":`profile-avatar`,className:`relative group size-20 rounded-full overflow-hidden border border-border bg-muted shrink-0 cursor-pointer`,children:[e.picture?(0,W.jsx)(`img`,{src:e.picture,alt:``,className:`size-full object-cover`}):(0,W.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center text-lg font-semibold text-muted-foreground`,children:L5(e.displayName)}),(0,W.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/45 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,children:(0,W.jsx)(kn,{className:`size-5 text-white`})})]}),(0,W.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,className:`hidden`,"aria-hidden":`true`,tabIndex:-1,onChange:e=>{o(e.target.files?.[0]),e.target.value=``}})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Details`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Used by journal analytics (age from birth date, metric conversions). Changes are saved immediately.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`profile-display-name`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Display Name`}),(0,W.jsx)(`input`,{id:`profile-display-name`,"data-testid":`profile-display-name`,className:F5,placeholder:`Anonymous`,value:n.displayName,onChange:e=>{r(t=>({...t,displayName:e.target.value})),a({displayName:e.target.value})}})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{htmlFor:`profile-birth-date`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:[`Birth Date`,s===void 0?``:` · Age ${s}`]}),(0,W.jsx)(`input`,{id:`profile-birth-date`,"data-testid":`profile-birth-date`,type:`date`,className:F5,value:n.birthDate,onChange:e=>{r(t=>({...t,birthDate:e.target.value})),a({birthDate:e.target.value||void 0})}})]}),(0,W.jsx)(`div`,{})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`profile-weight`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Weight`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(`input`,{id:`profile-weight`,"data-testid":`profile-weight`,type:`number`,inputMode:`decimal`,min:`0`,className:F5,placeholder:c===`kg`?`e.g. 75`:`e.g. 165`,value:n.weight,onChange:e=>{let t=e.target.value;r(e=>({...e,weight:t})),t===``?a({weight:void 0}):Number.isFinite(Number(t))&&a({weight:Number(t)})}}),(0,W.jsx)(R5,{unit:c,other:c===`kg`?`lb`:`kg`,onSwitch:()=>void a({weightUnit:c===`kg`?`lb`:`kg`,weight:e.weight==null?void 0:c===`kg`?e.weight*N5:e.weight/N5})})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`profile-height`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Height`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(`input`,{id:`profile-height`,"data-testid":`profile-height`,type:`number`,inputMode:`decimal`,min:`0`,className:F5,placeholder:l===`cm`?`e.g. 180`:`e.g. 71`,value:n.height,onChange:e=>{let t=e.target.value;r(e=>({...e,height:t})),t===``?a({height:void 0}):Number.isFinite(Number(t))&&a({height:Number(t)})}}),(0,W.jsx)(R5,{unit:l,other:l===`cm`?`in`:`cm`,onSwitch:()=>void a({heightUnit:l===`cm`?`in`:`cm`,height:e.height==null?void 0:l===`cm`?e.height/P5:e.height*P5})})]})]})]})]})]})]})}function B5(e){let t;try{t=JSON.parse(e)}catch{return{ok:!1,error:`The pairing file is not valid JSON.`}}if(!t||typeof t!=`object`||Array.isArray(t))return{ok:!1,error:`The pairing file has an unexpected shape.`};let n=t;if(n.wodWikiPairing!==1)return{ok:!1,error:`Not a wod.wiki database pairing file (missing "wodWikiPairing": 1).`};if(n.kind!==`turso`)return{ok:!1,error:`Unsupported pairing kind "${String(n.kind)}" — only Turso databases can be paired here.`};let{url:r,authToken:i}=n;return typeof r!=`string`||!r.trim()||typeof i!=`string`||!i.trim()?{ok:!1,error:`The pairing file is missing the database URL or auth token.`}:{ok:!0,pairing:{url:r,authToken:i,database:typeof n.database==`string`&&n.database.trim()?n.database:void 0,schemaVersion:typeof n.schemaVersion==`number`&&Number.isSafeInteger(n.schemaVersion)?n.schemaVersion:void 0,createdAt:typeof n.createdAt==`string`?n.createdAt:void 0}}}async function V5(e){let t=hk(e.url,e.authToken);if(t)return{state:`unreachable`,reason:t};let n;try{n=Hx(g({url:e.url.trim(),authToken:e.authToken}))}catch(t){return{state:`unreachable`,reason:gk(t,e.authToken).message}}try{let e=await jb(n);return e===`empty`?{state:`empty`,reason:`The database is empty — nothing to restore. Use Enable Sync to back up to it instead.`}:e.kind===`unknown`?{state:`unknown`,reason:`The database contains foreign tables — refusing to touch it.`}:e.kind===`legacy`||e.schemaVersion<32?{state:`older`,schemaVersion:e.schemaVersion,reason:`The database uses schema v${e.schemaVersion}, this app needs v32. Migrate it with the CLI to a fresh target, then pair that target.`}:e.schemaVersion>32?{state:`newer`,schemaVersion:e.schemaVersion,reason:`The database uses schema v${e.schemaVersion}, newer than this app supports (v32). Update the app first.`}:{state:`current`,schemaVersion:e.schemaVersion,rev:e.rev}}catch(t){return{state:`unreachable`,reason:gk(t,e.authToken).message}}finally{await n.close().catch(()=>void 0)}}var H5=[`wodwiki.seedSources`,`wodwiki.seedSources.hidden`,`wodwiki.seedSubscriptions`,`wodwiki.seedAutoSync`];function U5(e){if(typeof e!=`string`)return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&!t.username&&!t.password&&!t.search&&!t.hash}catch{return!1}}function W5(){let e=[];for(let t of H5){let n=null;try{n=localStorage.getItem(t)}catch{n=null}if(n!==null)try{let r=JSON.parse(n);if(t===`wodwiki.seedSources`){let n=(Array.isArray(r)?r:[]).flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e;if(typeof t.id!=`string`||typeof t.label!=`string`||!U5(t.url))return[];let n={id:t.id,label:t.label,url:t.url};return typeof t.repositoryUrl==`string`&&U5(t.repositoryUrl)&&(n.repositoryUrl=t.repositoryUrl),[n]});e.push({key:t,value:n})}else if(t===`wodwiki.seedSources.hidden`)e.push({key:t,value:Array.isArray(r)?r.filter(e=>typeof e==`string`):[]});else{let n=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).filter(([,e])=>typeof e==`boolean`):[];e.push({key:t,value:Object.fromEntries(n)})}}catch{}}return e}function G5(e){let t=(e,t)=>JSON.parse(hb(t,e===`attachments`?`data`:void 0));return JSON.stringify({format:`wod-wiki-safe-export`,version:1,...e,rows:e.rows.map(({store:e,rows:n})=>({store:e,rows:n.map(n=>t(e,n))})),pendingGroups:e.pendingGroups.map(e=>({...e,ops:e.ops.map(e=>e&&typeof e==`object`&&`op`in e&&e.op===`put`&&`store`in e&&typeof e.store==`string`&&`value`in e?{...e,value:t(e.store,e.value)}:e)}))},null,2)}async function K5(){let[e,t]=await Promise.all([Bk(),Vk()]),n=G5({pendingGroups:e.map(e=>({id:e.id,at:e.at,ops:e.ops})),rows:t,contentSources:W5(),exportedAt:new Date().toISOString()}),r=`wodwiki-safe-export-${new Date().toISOString().slice(0,10)}.json`,i=URL.createObjectURL(new Blob([n],{type:`application/json`})),a=document.createElement(`a`);return a.href=i,a.download=r,a.click(),setTimeout(()=>URL.revokeObjectURL(i),1e3),r}async function q5(){let e=await zk();try{return await K5()}finally{e&&Rk()}}function J5(e){let t=globalThis.indexedDB;if(!t)return Promise.resolve();let{promise:n,resolve:r}=Promise.withResolvers(),i=t.deleteDatabase(e);return i.onsuccess=()=>r(),i.onerror=()=>r(),i.onblocked=()=>r(),n}async function Y5(e,t){let n=vk();if(n.state===`turso`&&fk(n.url,e.url))throw Error(`This database is already the active sync target. Restore needs the URL of a different database.`);t?.(`Checking the target database…`);let r=await V5(e);if(r.state!==`current`)throw Error(r.reason);t?.(`Pausing background sync…`);let i=await zk(),a=`wodwiki-restore-${crypto.randomUUID().slice(0,8)}`,o=new nx({dbName:a}),s=new lk(o,{url:e.url.trim(),authToken:e.authToken});try{t?.(`Exporting your current data and unsent edits…`),await K5(),t?.(`Replaying the remote database into an isolated local copy…`),await s.restoreNow(),await s.stop(),await o.close(),t?.(`Saving the restored database as your data…`),Ck(a)}catch(t){throw await s.stop().catch(()=>void 0),await o.close().catch(()=>void 0),await J5(a),i&&Rk(),gk(t,e.authToken)}return{localDbName:a}}function X5({idPrefix:e,onPair:t}){let[n,r]=(0,U.useState)(null),i=async e=>{if(!e?.length)return;let n=B5(await e[0].text());n.ok?(r(null),t(n.pairing)):r(n.error)};return(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`label`,{htmlFor:`${e}-pairing`,className:`block text-xs font-medium text-muted-foreground`,children:[`Pair from provisioning file (from `,(0,W.jsx)(`code`,{className:`font-mono`,children:`wod db`}),`)`]}),(0,W.jsx)(`input`,{id:`${e}-pairing`,type:`file`,accept:`application/json,.json`,onChange:e=>void i(e.target.files),"data-testid":`${e}-pairing-input`,className:`block w-full text-xs text-muted-foreground file:mr-2 file:cursor-pointer file:rounded-md file:border-0 file:bg-muted file:px-2 file:py-1 file:text-xs file:font-medium`}),n&&(0,W.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`${e}-pairing-error`,children:n})]})}function Z5({saved:e,onConnected:t}){let[n,r]=(0,U.useState)(e?.url??``),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(null),h=t??(typeof window<`u`?()=>window.location.reload():void 0),g=()=>{let t=n.trim();return t?i.trim()?i.trim():e&&t===e.url&&e.authToken?e.authToken:(d(e?.authToken?`The URL differs from the saved connection — enter the auth token for this database.`:`An auth token is required.`),null):(d(`A database URL is required.`),null)};return(0,W.jsxs)(`div`,{className:`space-y-3`,"data-testid":`turso-connect-form`,children:[(0,W.jsx)(X5,{idPrefix:`turso`,onPair:e=>{r(e.url),a(e.authToken),d(null),p(null),s([e.database,e.schemaVersion===void 0?void 0:`file schema v${e.schemaVersion}`].filter(Boolean).join(` · `)||null)}}),o&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`turso-pairing-label`,children:[`Provisioned database: `,(0,W.jsx)(`span`,{className:`font-mono`,children:o}),` — verify with Test Connection, then Enable Sync. The live database is checked again before anything is saved.`]}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`turso-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Database URL`}),(0,W.jsx)(`input`,{id:`turso-url`,type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:`libsql://your-db.turso.io`,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:n,onChange:e=>r(e.target.value),disabled:c!==null})]}),(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`turso-token`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Auth token`}),(0,W.jsx)(`input`,{id:`turso-token`,type:`password`,autoComplete:`off`,placeholder:e?`•••••••• (saved token — reused only for the same URL)`:``,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:i,onChange:e=>a(e.target.value),disabled:c!==null})]})]}),(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-muted-foreground leading-relaxed`,"data-testid":`turso-token-warning`,children:[(0,W.jsx)(m,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:`The token is saved in this browser's localStorage, so any code on this site can read it. Use a token scoped to this one database, and never a token with write access elsewhere.`})]}),u&&(0,W.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`turso-connect-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:u})]}),f&&(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-emerald-600`,"data-testid":`turso-test-ok`,children:[(0,W.jsx)(yn,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:f})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:async()=>{let e=g();if(e){l(`test`),d(null),p(null);try{await Sk({url:n.trim(),authToken:e}),p(`Connection verified — the database is reachable and writable. Nothing was saved.`)}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(null)}}},disabled:c!==null,"data-testid":`turso-test-button`,className:`gap-2`,children:[c===`test`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(Tt,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:c===`test`?`Testing…`:`Test Connection`})]}),(0,W.jsxs)(K,{size:`sm`,onClick:async()=>{let e=g();if(e){l(`connect`),d(null),p(null);try{await xk({url:n.trim(),authToken:e}),Q({title:`Turso Sync enabled`,description:`Reloading… Your local data will sync in the background.`}),h?.()}catch(e){d(e instanceof Error?e.message:String(e)),l(null)}}},disabled:c!==null,"data-testid":`turso-connect-button`,className:`gap-2`,children:[c===`connect`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(un,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:c===`connect`?`Enabling…`:e?`Update Connection`:`Enable Sync`})]}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Sync merges and backs up your local data in the background. Your local copy stays the one you edit.`})]})]})}function Q5({status:e}){let t={current:{label:`Compatible`,className:`text-emerald-600`},older:{label:`Older schema`,className:`text-amber-600`},newer:{label:`Newer schema`,className:`text-destructive`},empty:{label:`Empty database`,className:`text-amber-600`},unknown:{label:`Foreign database`,className:`text-destructive`},unreachable:{label:`Unreachable`,className:`text-destructive`}}[e.state],n=e.state===`current`?`Canonical schema v${e.schemaVersion}, up to date at rev ${e.rev}.`:e.reason;return(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs leading-relaxed`,"data-testid":`restore-status-${e.state}`,children:[e.state===`current`?(0,W.jsx)(yn,{className:`size-3.5 mt-0.5 shrink-0 text-emerald-600`}):(0,W.jsx)(Qt,{className:G(`size-3.5 mt-0.5 shrink-0`,t.className)}),(0,W.jsxs)(`span`,{className:t.className,children:[(0,W.jsxs)(`span`,{className:`font-semibold`,children:[t.label,`.`]}),` `,(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:n})]})]})}function $5(){let[e,t]=(0,U.useState)(``),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!0;return Bk().then(t=>{e&&_(t.length)}).catch(()=>void 0),()=>{e=!1}},[]);let v=e.trim()!==``&&n.trim()!==``,y=async()=>{h(`probe`),p(null),a(null);try{a(await V5({url:e.trim(),authToken:n}))}finally{h(null)}},b=async()=>{h(`export`),p(null);try{let e=await q5();l(`Exported ${e} — unsent edits, a full local snapshot, and content-source settings. No tokens included.`);let t=await Bk();_(t.length)}catch(e){p(e instanceof Error?e.message:String(e))}finally{h(null)}},x=async()=>{h(`restore`),d(!1),p(null);try{await Y5({url:e.trim(),authToken:n},s),Q({title:`Restore complete`,description:`The restored database is now your data. Reloading…`}),setTimeout(()=>window.location.reload(),600)}catch(e){p(e instanceof Error?e.message:String(e)),s(null),h(null)}};return(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 sm:p-5 space-y-4`,"data-testid":`restore-section`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg bg-muted text-foreground shrink-0`,children:(0,W.jsx)(C,{className:`size-5`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Restore from a backup database`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:[`Point this at a different, already-provisioned database (for example one retained by`,` `,(0,W.jsx)(`code`,{className:`font-mono`,children:`wod db backup`}),`) to replace this browser's data with its contents. The remote database is never modified, and your current data is kept in a separate local database that stays on disk.`]})]})]}),(0,W.jsx)(X5,{idPrefix:`restore`,onPair:e=>{t(e.url),r(e.authToken),a(null),p(null),l(null)}}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`restore-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Backup database URL`}),(0,W.jsx)(`input`,{id:`restore-url`,type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:`libsql://your-restore-target.turso.io`,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:e,onChange:e=>{t(e.target.value),a(null)},disabled:m!==null})]}),(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`restore-token`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Auth token`}),(0,W.jsx)(`input`,{id:`restore-token`,type:`password`,autoComplete:`off`,placeholder:`Database-scoped token for the backup database`,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:n,onChange:e=>{r(e.target.value),a(null)},disabled:m!==null})]})]}),f&&(0,W.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`restore-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:f})]}),i&&(0,W.jsx)(Q5,{status:i}),o&&(0,W.jsx)(`p`,{"aria-live":`polite`,className:`text-xs text-muted-foreground`,"data-testid":`restore-phase`,children:o}),c&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`restore-export-note`,children:c}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void y(),disabled:!v||m!==null,"data-testid":`restore-check-button`,className:`gap-2`,children:[m===`probe`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(Tt,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:m===`probe`?`Checking…`:`Check database`})]}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void b(),disabled:m!==null,"data-testid":`restore-export-button`,className:`gap-2`,children:[m===`export`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(Mn,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:g===null||g===0?`Export data (safe file)`:`Export data — ${g} unsent ${g===1?`edit`:`edits`}`})]}),u?(0,W.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground max-w-72`,children:`Your current data is exported and kept locally. The restored copy opens with sync disabled so the archive stays unchanged.`}),(0,W.jsxs)(K,{variant:`destructive`,size:`sm`,autoFocus:!0,onClick:()=>void x(),disabled:m!==null,"data-testid":`restore-confirm-button`,children:[m===`restore`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(un,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:m===`restore`?`Restoring…`:`Confirm restore`})]}),(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>d(!1),disabled:m!==null,"data-testid":`restore-cancel-button`,children:`Cancel`})]}):(0,W.jsxs)(K,{variant:`destructive`,size:`sm`,onClick:()=>{d(!0),p(null)},disabled:!v||m!==null,"data-testid":`restore-button`,className:`gap-2`,children:[(0,W.jsx)(C,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Restore this database…`})]})]})]})}function e7(){let[e]=(0,U.useState)(vk),t=e?.state===`turso`,n=Dk===`api`;return(0,W.jsx)(`div`,{className:`space-y-8`,children:(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Storage`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Notes, results, workouts, and queries stay in this browser. Optional Turso Sync backs up your data and syncs other browsers in the background.`})]}),n?(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,"data-testid":`storage-option-api`,children:`This deployment stores data on its server; storage is managed by the deployment.`}):(0,W.jsxs)(W.Fragment,{children:[e?.state===`invalid`&&(0,W.jsxs)(`div`,{role:`alert`,className:`rounded-xl border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive flex items-start gap-2`,"data-testid":`data-settings-invalid-banner`,children:[(0,W.jsx)(Qt,{className:`size-4 mt-0.5 shrink-0`}),(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(`div`,{className:`font-semibold`,children:`Turso Sync settings are invalid; sync is off`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.error,` Fix the connection below or turn off Turso Sync to keep working from your local copy. Neither copy was deleted.`]}),(0,W.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>{wk(),window.location.reload()},"data-testid":`data-settings-invalid-disable`,className:`mt-1`,children:`Turn off Turso Sync`})]})]}),(0,W.jsxs)(`div`,{"data-testid":`storage-option-browser`,className:`rounded-xl border border-primary ring-2 ring-primary/20 bg-primary/5 p-4 sm:p-5 space-y-4 text-left`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg bg-primary text-primary-foreground shrink-0`,children:(0,W.jsx)(re,{className:`size-5`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`font-semibold text-foreground text-sm`,children:`This Browser`}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:`Private local storage (IndexedDB). Everything is stored in this browser and reads and writes are local — Turso Sync, when enabled, backs it up to your database in the background.`})]})]}),(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-primary text-primary-foreground shrink-0`,children:`Always on`})]}),(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`border-t border-border`}),(0,W.jsxs)(`div`,{"data-testid":`storage-option-turso`,className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Turso Sync`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 leading-relaxed font-mono break-all`,children:e?.state===`turso`?`Backing up to ${e.url} in the background.`:`Off — fill out the form below to back up your local data to your own Turso database in the background.`})]}),(0,W.jsx)(`span`,{className:G(`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded shrink-0`,t?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground`),children:t?`Sync on`:`Sync off`})]}),t&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-md border border-border bg-muted/30 p-3`,children:[(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>{t&&(wk(),window.location.reload())},"data-testid":`turso-sync-disable`,className:`gap-2`,children:[(0,W.jsx)(st,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Turn off Turso Sync`})]}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Turning off sync keeps everything in this browser. Nothing is deleted from your Turso database.`})]}),(0,W.jsx)(Z5,{saved:e?.state===`turso`?{url:e.url,authToken:e.authToken}:void 0})]})]}),(0,W.jsx)($5,{}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,"data-testid":`storage-option-self-hosted`,children:[(0,W.jsx)(Hn,{className:`mb-2 size-5`,"aria-hidden":`true`}),(0,W.jsx)(`p`,{className:`font-medium text-foreground`,children:`API server mode`}),(0,W.jsx)(`p`,{className:`mt-1 text-xs`,children:`Run the API deployment with your local or cloud-hosted database. This browser build uses IndexedDB; API deployments run storage and queries on their server.`})]})]})]})})}function t7(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}var n7=`:00, -:03, :05:00`;function r7(){(0,U.useSyncExternalStore)(jJ,MJ);let e=SJ(),[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(``),d=async e=>{i(null);let t=await TJ(e);return t||i(`Could not save — storage rejected the write; your change was not kept.`),t},f=async r=>{r.preventDefault();let a=t.trim();if(!a){i(`Profile name is required`);return}let o=t7(a);if(!o){i(`Profile name needs at least one letter or number`);return}if(e.some(e=>e.id===o)){i(`A profile with id "${o}" already exists`);return}await d(e=>[...e,{id:o,name:a,rules:[]}])&&(n(``),await EJ(o,Z),await Pj())},p=async e=>{let t=l.trim();c(null),!(!t||t===e.name)&&await d(n=>n.map(n=>n.id===e.id?{...n,name:t}:n))},m=async e=>{o(null),await d(t=>t.filter(t=>t.id!==e.id)),await DJ(e.id,Z),await Pj()},h=(e,t)=>d(n=>n.map(n=>n.id===e.id?{...n,rules:[...n.rules,t]}:n)),g=(e,t,n)=>d(r=>r.map(r=>r.id===e.id?{...r,rules:r.rules.map((e,r)=>r===t?n:e)}:r)),_=(e,t)=>d(n=>n.map(n=>n.id===e.id?{...n,rules:n.rules.filter((e,n)=>n!==t)}:n));return(0,W.jsx)(`div`,{className:`space-y-8`,children:(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Sound Profiles`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A profile is a named set of sound rules. Each rule fires a sound at a trigger point relative to a block's own duration: `,(0,W.jsx)(`code`,{className:`font-mono`,children:`:00`}),` starts it,`,` `,(0,W.jsx)(`code`,{className:`font-mono`,children:`-:00`}),` ends it, `,(0,W.jsx)(`code`,{className:`font-mono`,children:`-:03`}),` `,`is three seconds before the end, `,(0,W.jsx)(`code`,{className:`font-mono`,children:`:05:00`}),` is five minutes elapsed. Tag a note`,` `,(0,W.jsx)(`code`,{className:`font-mono`,children:bJ(`classic`)}),` to apply that profile to the whole note;`,` `,(0,W.jsxs)(`code`,{className:`font-mono`,children:[`sound: `,`#sound-classic`]}),` on a line applies it to that block only.`]})]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-4`,children:[(0,W.jsxs)(`form`,{onSubmit:f,className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[200px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Profile Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`,placeholder:`New profile (e.g. Classic beeps)`,value:t,onChange:e=>n(e.target.value)})]}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,className:`h-9`,children:[(0,W.jsx)(On,{className:`size-3.5 mr-1`}),` Add Profile`]})]}),r&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:r}),e.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No sound profiles created yet.`}):(0,W.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,W.jsxs)(`div`,{className:`p-3 rounded-lg border border-border/70 bg-background/50 space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s===e.id?(0,W.jsx)(`input`,{autoFocus:!0,"aria-label":`Rename profile ${e.name}`,className:`h-7 max-w-[220px] rounded border border-primary bg-background px-2 font-mono text-xs outline-none`,value:l,onChange:e=>u(e.target.value),onKeyDown:t=>{t.key===`Enter`?p(e):t.key===`Escape`&&c(null)},onBlur:()=>void p(e)}):(0,W.jsx)(`button`,{type:`button`,className:`font-semibold text-sm text-foreground hover:underline text-left`,title:`Click to rename`,onClick:()=>{c(e.id),u(e.name)},children:e.name}),(0,W.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`(`,e.id,`)`]}),(0,W.jsx)(`button`,{type:`button`,title:`Click to copy`,"aria-label":`Copy tag ${bJ(e.id)}`,onClick:()=>{navigator.clipboard?.writeText(bJ(e.id))},className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-foreground hover:bg-accent`,children:bJ(e.id)}),(0,W.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:a===e.id?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-xs text-destructive`,children:`Delete this profile?`}),(0,W.jsx)(K,{variant:`destructive`,size:`sm`,className:`h-7`,onClick:()=>void m(e),children:`Confirm`}),(0,W.jsx)(K,{variant:`outline`,size:`sm`,className:`h-7`,onClick:()=>o(null),children:`Cancel`})]}):(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete profile ${e.name}`,className:`p-1 rounded text-muted-foreground hover:text-destructive transition`,onClick:()=>o(e.id),children:(0,W.jsx)(Ue,{className:`size-3.5`})})})]}),(0,W.jsx)(i7,{profile:e,onAdd:t=>void h(e,t),onUpdate:(t,n)=>void g(e,t,n),onRemove:t=>void _(e,t)})]},e.id))})]})]})})}function i7({profile:e,onAdd:t,onUpdate:n,onRemove:r}){return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.rules.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No rules yet — this profile is silent.`}):(0,W.jsx)(`div`,{className:`space-y-1`,children:e.rules.map((e,t)=>(0,W.jsx)(o7,{index:t,rule:e,onCommit:n,onRemove:r},`${t}:${e.trigger}:${e.sound}`))}),(0,W.jsx)(s7,{onAdd:t})]})}function a7({value:e,onChange:t,label:n}){return(0,W.jsx)(`select`,{"aria-label":n,className:`h-7 rounded border border-input bg-background px-2 text-xs outline-none cursor-pointer focus:border-primary`,value:e,onChange:e=>t(e.target.value),children:Yk.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})}function o7({index:e,rule:t,onCommit:n,onRemove:r}){let[i,a]=(0,U.useState)(t.trigger),[o,s]=(0,U.useState)(null),c=()=>{let r=i.trim();if(r===t.trigger){s(null);return}if(!Xu(r)){s(`"${r}" is not a trigger — use ${n7} …`);return}s(null),n(e,{trigger:r,sound:t.sound})};return(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{"aria-label":`Trigger for rule ${e+1}`,className:`h-7 w-24 rounded border border-input bg-background px-2 font-mono text-xs outline-none focus:border-primary`,placeholder:n7,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},onBlur:c}),(0,W.jsx)(a7,{label:`Sound for rule ${e+1}`,value:t.sound,onChange:r=>n(e,{trigger:t.trigger,sound:r})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete rule ${e+1}`,className:`p-1 rounded text-muted-foreground hover:text-destructive transition`,onClick:()=>r(e),children:(0,W.jsx)(Ue,{className:`size-3.5`})})]}),o&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:o})]})}function s7({onAdd:e}){let[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(Yk[0]),[a,o]=(0,U.useState)(null);return(0,W.jsxs)(`form`,{onSubmit:a=>{a.preventDefault();let s=t.trim();if(!Xu(s)){o(`"${s}" is not a trigger — use ${n7} …`);return}o(null),e({trigger:s,sound:r}),n(``),i(Yk[0])},className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{"aria-label":`New rule trigger`,className:`h-7 w-24 rounded border border-input bg-background px-2 font-mono text-xs outline-none focus:border-primary`,placeholder:n7,value:t,onChange:e=>n(e.target.value)}),(0,W.jsx)(a7,{label:`New rule sound`,value:r,onChange:i}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,variant:`outline`,className:`h-7`,children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Add Rule`]}),a&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:a})]})}var c7=[{id:`appearance`,content:(0,W.jsx)(d7,{})},{id:`profile`,content:(0,W.jsx)(z5,{})},{id:`storage`,content:(0,W.jsx)(e7,{})},{id:`sync`,content:(0,W.jsx)(E3,{})},{id:`tags`,content:(0,W.jsx)(p7,{})},{id:`sound-profiles`,content:(0,W.jsx)(r7,{})},{id:`routes`,content:(0,W.jsx)(u7,{})},{id:`system`,content:(0,W.jsx)(f7,{})}];function l7(){let e=Sn(),t=e.pathname.endsWith(`/system`)?`system`:e.pathname.endsWith(`/profile`)?`profile`:e.pathname.endsWith(`/storage`)?`storage`:e.pathname.endsWith(`/sync`)?`sync`:e.pathname.endsWith(`/tags`)?`tags`:e.pathname.endsWith(`/sound-profiles`)?`sound-profiles`:e.pathname.endsWith(`/routes`)?`routes`:`appearance`;return(0,W.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 bg-background`,children:[(0,W.jsx)(NB,{title:`Settings`,subtitle:`Manage profile, appearance, audio, and system preferences`}),(0,W.jsx)(`main`,{className:`flex-1 overflow-y-auto px-4 sm:px-6 lg:px-8 py-6 sm:py-8`,children:(0,W.jsx)(`div`,{className:`max-w-4xl mx-auto space-y-8`,children:c7.find(e=>e.id===t)?.content})})]})}function u7(){let[e,t]=(0,U.useState)([]);return(0,U.useEffect)(()=>{let e=!0;return jk.readonly(`page`).getAll().then(n=>{e&&t(n)}).catch(console.error),()=>{e=!1}},[]),(0,W.jsxs)(`section`,{className:`space-y-6`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-lg font-medium`,children:`Route Review`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:"All page routes (`/page/:slug`, `/notebook/:slug`, `/day/:date`) currently registered in storage."})]}),(0,W.jsx)(`div`,{className:`border rounded-md`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,W.jsx)(`thead`,{className:`bg-muted/50 border-b`,children:(0,W.jsxs)(`tr`,{children:[(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Route`}),(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Title`}),(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`ID`})]})}),(0,W.jsx)(`tbody`,{className:`divide-y`,children:e.length===0?(0,W.jsx)(`tr`,{children:(0,W.jsx)(`td`,{colSpan:3,className:`px-4 py-4 text-center text-muted-foreground`,children:`No pages found.`})}):e.map(e=>(0,W.jsxs)(`tr`,{children:[(0,W.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs`,children:e.slug?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold bg-primary/10 text-primary`,children:`SLUG`}),e.slug]}):e.date?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold bg-secondary/10 text-secondary`,children:`DATE`}),e.date]}):`—`}),(0,W.jsx)(`td`,{className:`px-4 py-2`,children:e.title??`—`}),(0,W.jsx)(`td`,{className:`px-4 py-2 font-mono text-[10px] text-muted-foreground`,children:e.id})]},e.id))})]})})]})}function d7(){let{theme:e,setTheme:t}=Mi(),[n,r]=MV(),i={right:mr,left:bt};return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Interface Theme`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select your preferred color theme. Changes are saved and applied immediately.`})]}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4`,children:[{id:`system`,label:`System`,description:`Follows your operating system color scheme preferences`,icon:tn,isDefault:!0},{id:`light`,label:`Light`,description:`Crisp light background with dark text for high daytime readability`,icon:ae},{id:`dark`,label:`Dark`,description:`Relaxed dark background for lower eye strain in low-light settings`,icon:Pe}].map(n=>{let r=e===n.id,i=n.icon;return(0,W.jsxs)(`button`,{type:`button`,"data-testid":`theme-option-${n.id}`,onClick:()=>t(n.id),className:G(`relative flex flex-col items-start p-4 rounded-xl border text-left transition-all`,r?`border-primary ring-2 ring-primary/20 bg-primary/5 text-foreground shadow-xs`:`border-border bg-card text-muted-foreground hover:text-foreground hover:bg-muted/40`),children:[(0,W.jsxs)(`div`,{className:`w-full flex items-center justify-between mb-3`,children:[(0,W.jsx)(`div`,{className:G(`p-2 rounded-lg`,r?`bg-primary text-primary-foreground`:`bg-muted text-foreground`),children:(0,W.jsx)(i,{className:`size-5`})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[n.isDefault&&(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`Default`}),(0,W.jsx)(`div`,{className:G(`size-4 rounded-full border flex items-center justify-center transition-colors`,r?`border-primary bg-primary text-primary-foreground`:`border-muted-foreground/40`),children:r&&(0,W.jsx)(un,{className:`size-2.5 stroke-[3]`})})]})]}),(0,W.jsx)(`div`,{className:`font-semibold text-foreground text-sm`,children:n.label}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:n.description})]},n.id)})})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Tt,{className:`size-4 text-primary`}),`Actions Button Position`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`On phones, search and page actions float as a button cluster at the bottom of the screen. Place the cluster near your dominant thumb.`})]}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4`,children:DV.map(e=>{let t=n===e.id,a=i[e.id];return(0,W.jsxs)(`button`,{type:`button`,"data-testid":`fab-alignment-${e.id}`,onClick:()=>r(e.id),className:G(`relative flex flex-col items-start p-4 rounded-xl border text-left transition-all`,t?`border-primary ring-2 ring-primary/20 bg-primary/5 text-foreground shadow-xs`:`border-border bg-card text-muted-foreground hover:text-foreground hover:bg-muted/40`),children:[(0,W.jsxs)(`div`,{className:`w-full flex items-center justify-between mb-3`,children:[(0,W.jsx)(`div`,{className:G(`p-2 rounded-lg`,t?`bg-primary text-primary-foreground`:`bg-muted text-foreground`),children:(0,W.jsx)(a,{className:`size-5`})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[e.id===`right`&&(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`Default`}),(0,W.jsx)(`div`,{className:G(`size-4 rounded-full border flex items-center justify-center transition-colors`,t?`border-primary bg-primary text-primary-foreground`:`border-muted-foreground/40`),children:t&&(0,W.jsx)(un,{className:`size-2.5 stroke-[3]`})})]})]}),(0,W.jsx)(`div`,{className:`font-semibold text-foreground text-sm`,children:e.label}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:e.description})]},e.id)})})]})]})}function f7(){let{isEnabled:e,toggleAudio:t,playTestSound:n}=ZA(),{isDebugMode:r,toggleDebugMode:i}=Oy(),{consent:a,setConsent:o}=pq(),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(null),p=vk(),m=p.state===`turso`?`your Turso database (${p.url})`:null;return(0,U.useEffect)(()=>{if(!s)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),c(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s]),(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,"data-testid":`settings-about`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(pe,{className:`size-4 text-primary`}),`About`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Build version and release information for this playground.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`p`,{className:`text-sm font-medium text-foreground font-mono`,children:[`v`,$z]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Wod Wiki playground build`})]}),(0,W.jsx)(K,{asChild:!0,variant:`outline`,size:`sm`,className:`gap-2`,children:(0,W.jsxs)(`a`,{href:tB($z),target:`_blank`,rel:`noopener noreferrer`,"data-testid":`settings-release-link`,children:[(0,W.jsx)(A,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Release notes`})]})})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[e?(0,W.jsx)(fe,{className:`size-4 text-primary`}):(0,W.jsx)(ne,{className:`size-4 text-muted-foreground`}),`Audio Feedback`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure sound effects for workout timers, interval countdowns, and completion cues.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`label`,{htmlFor:`sound-switch`,className:`text-sm font-medium text-foreground cursor-pointer`,children:`Workout Sound Effects`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Play countdown beeps, interval alerts, and workout finish chimes`})]}),(0,W.jsx)(e3,{id:`sound-switch`,"data-testid":`sound-toggle`,checked:e,onChange:t})]}),(0,W.jsxs)(`div`,{className:`pt-3 border-t border-border/50 flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Test audio output device`}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:n,disabled:!e,"data-testid":`play-test-sound-btn`,className:`gap-2`,children:[(0,W.jsx)(fe,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Play Test Chime`})]})]})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(ft,{className:`size-4 text-primary`}),`Developer Diagnostics`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Logging and runtime inspection tools for Whiteboard scripts and execution trees.`})]}),(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`label`,{htmlFor:`debug-switch`,className:`text-sm font-medium text-foreground cursor-pointer`,children:`Debug Mode`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Output verbose AST compilation and runtime execution traces to browser console`})]}),(0,W.jsx)(e3,{id:`debug-switch`,"data-testid":`debug-mode-toggle`,checked:r,onChange:i})]})})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,"data-testid":`settings-telemetry`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(y,{className:`size-4 text-primary`}),`Anonymous Telemetry`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Anonymous usage telemetry is internal to Wod Wiki only. It helps us improve timer accuracy, workout execution, and query reliability. Your data will never be sold or shared with third parties.`})]}),(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`label`,{htmlFor:`telemetry-switch`,className:`text-sm font-medium text-foreground cursor-pointer`,children:`Share Anonymous Usage Statistics`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sends anonymous feature usage events. Turn off to opt out at any time.`})]}),(0,W.jsx)(e3,{id:`telemetry-switch`,"data-testid":`telemetry-toggle`,checked:a,onChange:o})]})})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-destructive flex items-center gap-2`,children:[(0,W.jsx)(I,{className:`size-4 text-destructive`}),`Data & Cache (Danger Zone)`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your local database storage and reset client state.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-destructive/30 bg-destructive/5 p-4 sm:p-5 space-y-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(`div`,{className:`font-semibold text-sm text-foreground`,children:`Reset & Clear Cache`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:m?(0,W.jsxs)(W.Fragment,{children:[`Wipes ALL data stored in `,m,`: notes, workouts, custom efforts, recorded results, and attachments, plus this browser's localStorage preferences. Your separate IndexedDB copy is kept. Bundled core content re-imports automatically on the next launch; community and custom libraries must be re-synced from Settings > Sync. Your connection settings are preserved.`]}):(0,W.jsx)(W.Fragment,{children:`Wipes all durable data stores including IndexedDB (notes, workouts, custom efforts, recorded results, and attachments) and resets all localStorage preferences. The application returns to a fresh first-run state: the core playground content re-imports automatically on the next launch, and community/custom libraries wait for you in Settings > Sync.`})})]}),(0,W.jsx)(`div`,{children:(0,W.jsxs)(K,{variant:`destructive`,size:`sm`,onClick:()=>c(!0),"data-testid":`reset-cache-button`,className:`gap-2`,children:[(0,W.jsx)(At,{className:`size-4`}),(0,W.jsx)(`span`,{children:`Reset & Clear Cache`})]})})]})]}),s&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-in fade-in duration-150`,onClick:e=>{e.target===e.currentTarget&&!l&&c(!1)},"data-testid":`reset-confirmation-modal`,children:(0,W.jsxs)(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-2xl flex flex-col gap-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`reset-modal-title`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5 text-destructive font-semibold text-base`,id:`reset-modal-title`,children:[(0,W.jsx)(I,{className:`size-5`}),`Reset All Application Data?`]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:m?(0,W.jsxs)(W.Fragment,{children:[`This permanently deletes every note, result, cached effort, and local setting stored in `,m,`. It cannot be undone.`]}):(0,W.jsx)(W.Fragment,{children:`This action will permanently wipe every note, result, cached effort, and local setting from your browser storage. This returns Wod Wiki to its first-run state and cannot be undone.`})}),d&&(0,W.jsxs)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`reset-error`,children:[`Reset failed: `,d,` — your data and connection were left untouched; try again.`]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[(0,W.jsx)(K,{variant:`outline`,onClick:()=>c(!1),disabled:l,children:`Cancel`}),(0,W.jsx)(K,{variant:`destructive`,onClick:async()=>{u(!0),f(null);try{await X0(),window.location.reload()}catch(e){f(e instanceof Error?e.message:String(e)),u(!1)}},disabled:l,"data-testid":`confirm-reset-button`,className:`gap-2`,children:l?(0,W.jsx)(`span`,{children:`Resetting…`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(At,{className:`size-4`}),(0,W.jsx)(`span`,{children:`Yes, Reset Everything`})]})})]})]})})]})}function p7(){let[e,t]=(0,U.useState)([]),[n,r]=(0,U.useState)([]),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(``),[c,l]=(0,U.useState)(`#3b82f6`),[u,d]=(0,U.useState)(null),f=(0,U.useCallback)(async()=>{try{let[e,n]=await Promise.all([Z.getAllTagTypes(),Z.getAllTags()]);t(e),r(n)}catch{}},[]);(0,U.useEffect)(()=>{f()},[f]);let p=async t=>{t.preventDefault();let n=i.trim().toLowerCase().replace(/[^a-z0-9_-]/g,`-`),r=o.trim();if(!n||!r){d(`Both type name and display label are required`);return}if(e.some(e=>e.name.toLowerCase()===n)){d(`Tag type "${n}" already exists`);return}d(null);let l={id:typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,name:n,label:r,color:c,createdAt:Date.now()};await Z.putTagType(l),a(``),s(``),await f()},m=async e=>{if(n.some(t=>t.type?.toLowerCase()===e.name.toLowerCase())){d(`Cannot delete tag type "${e.label}" while tags are assigned to it`);return}d(null),await Z.deleteTagType(e.id),await f()};return(0,W.jsx)(`div`,{className:`space-y-8`,children:(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Tag Types`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The kinds of tag that exist. A tag picks one as its kind, and note frontmatter properties matching a type name provide typeahead suggestions. The tags themselves — and what they contribute — are authored on the`,` `,(0,W.jsx)(`span`,{className:`font-mono`,children:`/tags`}),` page.`]})]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-4`,children:[(0,W.jsxs)(`form`,{onSubmit:p,className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[160px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Type Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,placeholder:`Type name (e.g. discipline)`,value:i,onChange:e=>a(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-[160px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Display Label`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`,placeholder:`Display label (e.g. Discipline)`,value:o,onChange:e=>s(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`w-24`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Color`}),(0,W.jsx)(`input`,{type:`color`,className:`w-full h-9 p-1 rounded-md border border-input bg-background cursor-pointer`,value:c,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,className:`h-9`,children:[(0,W.jsx)(On,{className:`size-3.5 mr-1`}),` Add Type`]})]}),u&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:u}),(0,W.jsxs)(`div`,{className:`border-t border-border pt-3`,children:[(0,W.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:`Registered Types`}),e.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No custom tag types created yet.`}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.map(e=>{let t=n.filter(t=>t.type?.toLowerCase()===e.name.toLowerCase()).length;return(0,W.jsxs)(`div`,{className:`flex items-center justify-between p-2.5 rounded-lg border border-border/70 bg-background/50 text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,W.jsx)(`span`,{className:`size-2.5 rounded-full shrink-0`,style:{backgroundColor:e.color||`#3b82f6`}}),(0,W.jsx)(`span`,{className:`font-semibold truncate`,children:e.label}),(0,W.jsxs)(`span`,{className:`text-muted-foreground font-mono text-[11px] truncate`,children:[`(`,e.name,`)`]}),(0,W.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.2 text-[10px] text-muted-foreground`,children:t})]}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete tag type ${e.label}`,disabled:t>0,title:t>0?`Cannot delete type while ${t} tag(s) are assigned`:`Delete unused tag type`,className:G(`p-1 rounded transition`,t>0?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground hover:text-destructive cursor-pointer`),onClick:()=>m(e),children:(0,W.jsx)(Ue,{className:`size-3.5`})})]},e.id)})})]})]})]})})}var m7=`dashboard-title`;function h7(){let{slug:e}=wt(),t=Vn(),[n]=N2(),{unit:r}=QS(),i=Date.now()-n*7*864e5,a=Date.now(),[o,s]=(0,U.useState)(0),[c,l]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!1;return Z.countEvents().then(t=>{e||l(t>0)}),()=>{e=!0}},[o]);let{source:u,loading:d}=fP(e,o),f=(0,U.useMemo)(()=>{if(!u?.rawContent)return null;let{meta:e,sections:t}=uv(u.rawContent);return{doc:iv(t,e),sections:t}},[u]),p=f?.doc??null,{setL3Items:m,registerScrollFn:h}=WM(),g=(0,U.useMemo)(()=>{if(!f)return{headings:[],items:[]};let{doc:e,sections:t}=f,n=new Set;t.forEach((e,r)=>{if(e.type!==`query`)return;let i=t[r-1];if(i?.type===`markdown`&&i.subtype===`paragraph`){let e=t[r-2];e?.type===`markdown`&&e.subtype===`heading`&&n.add(r-2)}else i?.type===`markdown`&&i.subtype===`heading`&&n.add(r-1)});let r=[],i=[];e.title&&i.push({id:m7,label:e.title,level:3,action:{type:`scroll`,sectionId:m7}});let a=0;return t.forEach((t,o)=>{if(t.type===`markdown`&&t.subtype===`heading`){if(n.has(o)||/^#\s/.test(t.content))return;let e=`note-h${o}`,s=t.content.replace(/^#+\s*/,``);r.push({id:e,level:/^#+/.exec(t.content)?.[0].length??2,text:s,beforeWidget:a}),i.push({id:e,label:s,level:3,action:{type:`scroll`,sectionId:e}});return}if(t.type!==`query`)return;let s=e.widgets[a];if(!s)return;a++;let c=`widget-${s.key}`;i.push({id:c,label:s.title||s.body,level:3,action:{type:`scroll`,sectionId:c}})}),{headings:r,items:i}},[f]),_=g.items;(0,U.useEffect)(()=>(m(_),()=>m([])),[_,m]),(0,U.useEffect)(()=>(h(e=>{let t=globalThis.document.getElementById(e);t&&(window.scrollTo({top:t.getBoundingClientRect().top+window.scrollY-80,behavior:`smooth`}),typeof t.animate==`function`&&t.animate([{boxShadow:`0 0 0 3px hsl(var(--primary))`},{boxShadow:`0 0 0 3px transparent`}],{duration:1500,easing:`ease-out`}))}),()=>h(e=>{let t=globalThis.document.getElementById(e);t&&window.scrollTo({top:t.getBoundingClientRect().top+window.scrollY-80,behavior:`smooth`})})),[h]);let[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(null),w=(0,U.useCallback)(async(e,t)=>{if(!u?.editable||!u.noteId)return;let n=await CP.getById(u.noteId);if(n.rawContent!==e)throw s(e=>e+1),Error(`The dashboard changed elsewhere — this edit was not saved.`);let r=t(n.rawContent);if(r==null)throw s(e=>e+1),Error(`The widget changed on disk — this edit was not saved.`);await CP.update(n,typeof r==`string`?r:r.note,typeof r==`string`?void 0:r),s(e=>e+1)},[u]),T=(0,U.useCallback)(async(e,t)=>{if(!u?.editable||!u.noteId)return;let n=await CP.getById(u.noteId),{meta:r,body:i}=By(n.rawContent),a=`---\n${Wy($_(r,e,t))}\n---\n${i}`;await CP.update(n,a),s(e=>e+1)},[u]),E=(0,U.useCallback)((e,t)=>{C(null),w(e,e=>{let n=t(e);if(!n.ok){let e=n.reason;throw Error(e===`stale-body`?`Widget changed since you opened this page — reload and retry.`:`Widget no longer exists — reload the dashboard.`)}return n}).catch(e=>{C(e instanceof Error?e.message:String(e))})},[w]),D=(0,U.useCallback)(async e=>{if(!(!b||b.mode===`inspect`)){if(b.mode===`add`)await w(b.expectedRaw,t=>bv(t,e));else{let t=b.widget;await w(b.expectedRaw,n=>{let r=Cv(n,t.key,t.body,e);if(!r.ok){let e=r.reason;throw Error(e===`stale-body`?`Widget changed since you opened this page — reload and retry.`:`Widget no longer exists — reload the dashboard.`)}return r})}}},[b,w]),O=(0,U.useCallback)(async()=>{!u||u.editable||(await TP.cloneDashboard(u.slug,u.rawContent,u.title),s(e=>e+1))},[u]),k=u!=null&&u.slug===e;if(d&&!k)return(0,W.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:`Loading dashboard…`});if(!k||!u)return(0,W.jsxs)(`div`,{className:`p-8`,"data-testid":`dashboard-not-found`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-bold text-foreground mb-2`,children:`Dashboard not found`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:[`No dashboard named `,(0,W.jsx)(`code`,{children:e}),`. It may have been removed.`]}),(0,W.jsx)(`button`,{onClick:()=>t(`/dashboard`),className:`px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90`,children:`Back to explorer`})]});let A=u.editable;return(0,W.jsxs)(`div`,{className:`min-h-screen bg-background flex flex-col`,children:[(0,W.jsx)(NB,{id:m7,title:p?.title||u.title,subtitle:A?`Editable dashboard note.`:`Prebuilt — read-only until cloned to your vault.`,actions:(0,W.jsxs)(RV,{label:`Dashboard actions`,primary:A?(0,W.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-edit-toggle`,"aria-pressed":v,onClick:()=>y(e=>!e),className:`flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-semibold transition-colors ${v?`bg-primary text-primary-foreground`:`border border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:[(0,W.jsx)(qt,{size:12}),` `,v?`Done`:`Edit`]}):void 0,children:[(0,W.jsx)(US,{}),(0,W.jsx)(eC,{})]})}),(0,W.jsxs)(`div`,{className:`max-w-[1500px] w-full mx-auto p-4 md:p-6 lg:p-8 flex-1`,children:[S&&(0,W.jsxs)(`div`,{role:`alert`,"data-testid":`dashboard-action-error`,className:`mb-4 flex items-center justify-between rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-2 text-xs text-destructive`,children:[(0,W.jsx)(`span`,{children:S}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,onClick:()=>C(null),className:`font-medium hover:opacity-70 transition-opacity`,children:`×`})]}),!A&&(0,W.jsxs)(`div`,{className:`mb-4 flex items-center justify-between rounded-lg border border-primary/30 bg-primary/5 px-4 py-2 text-xs`,children:[(0,W.jsx)(`span`,{className:`text-foreground`,children:`This is a read-only prebuilt. Clone it to edit widgets and tokens.`}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`clone-dashboard`,onClick:O,className:`font-medium text-primary hover:text-primary/80 transition-colors`,children:`Clone to vault`})]}),A&&v&&(0,W.jsxs)(`button`,{type:`button`,"data-testid":`add-widget`,onClick:()=>x({mode:`add`,expectedRaw:u.rawContent}),className:`mb-4 flex items-center gap-1.5 rounded-lg border border-dashed border-primary/50 px-4 py-2 text-xs font-semibold text-primary hover:bg-primary/5 transition-colors`,children:[(0,W.jsx)(On,{size:13}),` Add widget`]}),c===!1?(0,W.jsx)(w5,{layout:`card`,refreshKey:o,onChanged:()=>s(e=>e+1)}):(0,W.jsx)(`div`,{className:`mb-4`,children:(0,W.jsx)(w5,{layout:`banner`,refreshKey:o,onChanged:()=>s(e=>e+1)})}),p&&(0,W.jsx)(HS,{document:p,headings:g.headings,executor:sz,onTokenChange:A?T:void 0,editMode:A&&v,onEditWidget:A?e=>x({mode:`edit`,widget:e,expectedRaw:u.rawContent}):void 0,onDuplicateWidget:A?e=>E(u.rawContent,t=>wv(t,e.key,e.body)):void 0,onRemoveWidget:A?e=>E(u.rawContent,t=>Tv(t,e.key,e.body)):void 0,onMoveWidget:A?(e,t)=>E(u.rawContent,n=>Ev(n,e.key,e.body,t)):void 0,onResizeWidget:A?(e,t)=>E(u.rawContent,n=>Dv(n,e.key,e.body,t)):void 0,onInspectWidget:A?void 0:e=>x({mode:`inspect`,widget:e,expectedRaw:u.rawContent}),onOpenInExplorer:(e,n)=>t(FN({q:n})),rangeStart:i,rangeEnd:a,preferredUnit:r})]}),(0,W.jsx)(L2,{open:b!==null,onClose:()=>x(null),mode:b?.mode??`add`,initialWql:b&&b.mode!==`add`?b.widget.body:`sum:totalVolume{}`,initial:b&&b.mode!==`add`?{title:b.widget.title,question:b.widget.question,type:b.widget.type,spanCols:b.widget.spanCols,spanFull:b.widget.spanFull,attributes:b.widget.attributes}:void 0,executor:sz,rangeStart:i,rangeEnd:a,preferredUnit:r,tokenValues:p?Q_(p.tokens):void 0,onApply:b?.mode===`inspect`?void 0:D,footerExtra:b?.mode===`inspect`?(0,W.jsx)(`button`,{type:`button`,"data-testid":`inspect-clone`,onClick:()=>{O().then(()=>{x(null),y(!0)})},className:`px-3 py-1.5 text-xs font-medium text-primary hover:text-primary/80 rounded-lg border border-primary/40 hover:bg-primary/10 transition-colors`,children:`Clone to vault to edit`}):void 0})]})}function g7({sessionId:e}){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(``);return(0,U.useEffect)(()=>{let t=!1;return n(null),i(null),(async()=>{let r=await lP.getSessionById?.(e);if(!r)throw Error(`Session not found.`);let i=await lP.getBlockRevision(r.noteId,r.blockId,r.blockVersion);if(!i)throw Error(`The pinned saved workout is unavailable.`);t||n({session:r,revision:i})})().catch(e=>{t||i(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]),(0,W.jsxs)(`section`,{"aria-label":`Pinned workout source`,className:`space-y-3 border-b p-4`,children:[(0,W.jsx)(`h2`,{className:`font-semibold`,children:`Saved workout used by this session`}),r&&(0,W.jsx)(`p`,{role:`alert`,children:r}),t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`p`,{className:`break-all text-sm`,children:[`Block `,t.session.blockId,` · v`,t.revision.version,` · `,t.revision.dialect,t.revision.sport?` · ${t.revision.sport}`:``]}),(0,W.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap break-words rounded bg-muted p-3 text-xs`,children:t.revision.rawContent}),(0,W.jsx)(`button`,{type:`button`,disabled:a,className:`rounded border px-3 py-2 hover:bg-accent focus-visible:ring-2`,onClick:async()=>{o(!0),i(null);try{await new cP().rederiveResultAnalytics(e),c(`Analytics replayed from the pinned saved workout. Reload the results to view them.`)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(!1)}},children:a?`Replaying…`:`Replay saved analytics`}),(0,W.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`text-sm`,children:s}),(0,W.jsx)(iR,{noteId:t.session.noteId})]}):r?null:(0,W.jsx)(`p`,{role:`status`,children:`Loading saved workout…`})]})}function _7({searchHandlerRef:e}){let t=Vn(),n=Sn(),r=wt(),{theme:i}=Mi(),a=YO()??eH,o=$V(),s=qL(),c=gH(),l=hH(),{workout:u,nav:d}=c,[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(`blank`),g=(0,U.useCallback)(e=>{h(e?.mode??`blank`),p(!0)},[]),_=(0,U.useMemo)(()=>/^\/day\/(\d{4}-\d{2}-\d{2})\/?$/.exec(n.pathname)?.[1],[n.pathname]),v=(0,U.useCallback)(e=>{t(`${TN(e.id)}?edit=1`)},[t]),{tree:y,navState:b,setL3Items:x,setSecondarySpec:S,registerCreateJournal:C}=WM(),w=b?.activeL1Id??null,T=(y??[]).find(e=>e?.id===w)??null,E=c.shell.title??u.name,D=OF((0,U.useMemo)(()=>c.page===`library`?yN(n.pathname):void 0,[c.page,n.pathname])),O=c.shell.secondary;(0,U.useEffect)(()=>(S(O),()=>S(void 0)),[O,S]),(0,U.useEffect)(()=>C(g),[C,g]),(0,U.useEffect)(()=>{let e=new URLSearchParams(n.search);if(e.get(`create`)===`1`||e.get(`new`)===`1`){let r=e.get(`mode`)===`source`?`source`:`blank`;g({mode:r}),e.delete(`create`),e.delete(`new`),e.delete(`mode`);let i=e.toString()?`?${e.toString()}`:``;t(`${n.pathname}${i}`,{replace:!0})}},[n.pathname,n.search,g,t]),(0,U.useEffect)(()=>{if(!(!c.shell.withIndex||d.length===0))return x(wU(d)),()=>x([])},[c.shell.withIndex,d,x]);let k=(0,U.useRef)(()=>null),A=(0,U.useCallback)(e=>(k.current=e,()=>{k.current===e&&(k.current=()=>null)}),[]),j=(0,U.useCallback)(()=>{TH.getState().open({wql:{initialQuery:k.current()??mU(),execute:gU,preferredChoices:hU(),settings:{panel:(0,W.jsx)(E6,{})}},sources:[dU(),pU(qH(s)),pU(BH())]}).then(e=>{e.dismissed||_U(e.item,t)})},[t,s]);(0,U.useEffect)(()=>{e.current=j},[j,e]),(0,U.useEffect)(()=>{let e=e=>{e.key===`/`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.stopPropagation(),j())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[j]);let[M,N]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches),{handleViewCreated:P,scrollToSection:F}=TU(d);(0,U.useEffect)(()=>{if(i!==`system`)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>N(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[i]);let I=(0,U.useMemo)(()=>i===`system`?M?`vs-dark`:`vs`:i===`dark`?`vs-dark`:`vs`,[i,M]),L={feedDetail:()=>(0,W.jsx)(N1,{feedSlug:decodeURIComponent(c.feedDetailMatch)}),notebookItem:()=>(0,W.jsx)(E0,{slug:decodeURIComponent(c.notebookItemMatch[0]),itemDate:decodeURIComponent(c.notebookItemMatch[1]),item:decodeURIComponent(c.notebookItemMatch[2]),theme:I,onViewCreated:P,onScrollToSection:F}),effortDetail:()=>(0,W.jsx)(a8,{}),equipmentDetail:()=>(0,W.jsx)(u8,{}),tagDetail:()=>(0,W.jsx)(w8,{initialTag:r.tag},r.tag??``),dashboardExplorer:()=>(0,W.jsx)(M5,{actions:(0,W.jsx)(T0,{mode:`notebook-readonly`,currentWorkout:u,index:[]})}),dashboardView:()=>(0,W.jsx)(h7,{}),home:()=>(0,W.jsx)(g4,{wodFiles:a,theme:I}),canvas:()=>c.canvasPage.scroll?(0,W.jsx)(M1,{page:c.canvasPage,wodFiles:a,theme:I,workoutItems:o,onSelect:l,onScrollToSection:F}):(0,W.jsx)(n1,{page:c.canvasPage,wodFiles:a,theme:I,workoutItems:o,onSelect:l,onScrollToSection:F}),playground:()=>(0,W.jsx)(q6,{theme:I,onViewCreated:P,onScrollToSection:F,onSearch:j},c.effectivePlaygroundId),day:()=>(0,W.jsx)(j6,{journalDate:c.day,theme:I,onViewCreated:P},c.day),note:()=>c.namedPageSlug?(0,W.jsx)(M8,{slug:c.namedPageSlug},c.namedPageSlug):(0,W.jsx)(A8,{noteId:c.note,theme:I},c.note),notebookDate:()=>(0,W.jsx)(I8,{slug:c.notebookDate.slug,date:c.notebookDate.date,theme:I},`${c.notebookDate.slug}/${c.notebookDate.date}`),workout:()=>(0,W.jsx)(J6,{category:c.workout.category,name:c.workout.name,mdContent:c.workout.content,theme:I,onViewCreated:P},`${c.workout.category}/${c.workout.name}`),library:()=>{let e=D??DF(yN(n.pathname));return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(v7,{pathname:n.pathname}),(0,W.jsx)(T6,{profile:e,registerStreamDraft:A,actions:(0,W.jsx)(T0,{mode:`notebook-readonly`,currentWorkout:u,index:[]})},e.route)]})},settings:()=>(0,W.jsx)(l7,{})},ee=c.page===`canvas`?c.canvasPage?.route:void 0,te=c.page===`home`||!!ee?.startsWith(`/page/guide-`),ne=c.page===`home`?f1:c.page===`canvas`?c.canvasPage:null,R=ne?(0,W.jsx)(W.Fragment,{children:ne.quests.length>0&&(0,W.jsx)(D6,{pageRoute:ne.route,quests:ne.quests,challengeSectionMap:yL(ne),onScrollToSection:F})}):void 0;return(0,W.jsxs)(qV,{navbar:(0,W.jsxs)(YL,{children:[(0,W.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-1.5 min-w-0 shrink-2 truncate text-sm`,children:[T&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>T?.action?.type===`route`&&t(T.action.to),className:`shrink-0 text-muted-foreground hover:text-foreground transition-colors`,children:T.label}),T&&!!E&&E.toLowerCase()!==T.label.toLowerCase()&&(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground/50 shrink-0`,children:`›`}),E&&E.toLowerCase()!==T?.label.toLowerCase()&&(0,W.jsx)(`span`,{className:`text-sm font-semibold text-zinc-950 dark:text-white truncate`,children:E}),R]}),(0,W.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,W.jsx)(vH,{}),(0,W.jsx)(BV,{}),(0,W.jsx)(wZ,{})]})]}),sidebar:(0,W.jsx)(Qz,{navSpec:c.shell.nav}),hideDesktopSidebar:te,secondary:O,pageAction:u.content===``?void 0:(0,W.jsx)(b0,{currentWorkout:u}),onSearch:j,onCreate:g,children:[(0,W.jsx)($H,{open:f,onOpenChange:p,defaultDate:_,defaultMode:m,onCreated:v}),(0,W.jsx)(`div`,{className:`flex flex-col h-full min-h-[calc(100vh-theme(spacing.20))]`,children:(0,W.jsx)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:(e=>{if(c.shell.wrap===`bare`)return e;let t=c.shell.subheader===`filter-notebook-workouts`?(0,W.jsx)(AQ,{placeholder:`Filter notebook notes… Press / to start filtering`}):void 0;return(0,W.jsx)(FB,{title:c.shell.title,titleAccessory:R,subheader:t,index:c.shell.withIndex?d:void 0,actions:c.shell.actionsMode?(0,W.jsx)(T0,{mode:c.shell.actionsMode,currentWorkout:u,index:d}):void 0,children:e})})(L[c.page]())})}),(0,W.jsx)(RH,{}),(0,W.jsx)(CH,{})]})}function v7({pathname:e}){let t=/^\/results\/([^/]+)\/?$/.exec(e);return t?(0,W.jsx)(g7,{sessionId:decodeURIComponent(t[1])}):null}function y7(){return(0,W.jsx)(In,{to:`/sessions?q=%3Asegment%7B%7D%20last%208w`,replace:!0})}function b7(){let{runtimeId:e}=wt();return(0,W.jsx)(In,{to:ON(e),replace:!0})}function x7(){let{runtimeId:e,noteId:t,resultId:n}=wt(),r=n??e;return r?(0,W.jsx)(In,{to:AN(r),replace:!0}):t?(0,W.jsx)(In,{to:`/sessions?q=${encodeURIComponent(`:session{note:${t}}`)}`,replace:!0}):(0,W.jsx)(In,{to:`/sessions`,replace:!0})}function S7(){let e=Sn().search,t=e&&e.startsWith(`?`)?`${e}&mode=plan`:`?mode=plan`;return(0,W.jsx)(In,{to:`/journal${t}`,replace:!0})}var C7=`G-PROD-ID`,w7=!1;function T7(){if(w7||typeof document>`u`)return;w7=!0,window.dataLayer=window.dataLayer??[],window.gtag=function(){window.dataLayer.push(arguments)};let e=document.createElement(`script`);e.async=!0,e.src=`https://www.googletagmanager.com/gtag/js?id=${C7}`,document.head.appendChild(e),window.gtag(`js`,new Date),window.gtag(`config`,C7,{send_page_view:!1})}function E7(e,t){typeof window>`u`||!dq.consent||window.gtag?.(`event`,`page_view`,{page_title:e??document.title,page_location:window.location.href,page_path:t??window.location.pathname+window.location.search,engagement_time_msec:uq()})}dq.setForwarder(e=>{window.gtag?.(`event`,e.name,e.payload??{})}),dq.consent?T7():dq.subscribeConsent(e=>{e&&(T7(),E7())});function D7(){let e=Sn();return(0,U.useEffect)(()=>{let t=e.pathname;if(!t.startsWith(`/effort/`)&&!t.startsWith(`/playground/`)&&!t.startsWith(`/equipment/`)){let e=`Wod.Wiki`;t.startsWith(`/day/`)?e=`Wod.Wiki - Day`:t.startsWith(`/journal`)?e=`Wod.Wiki - Journal`:t.startsWith(`/notebooks`)||t.startsWith(`/notebook/`)?e=`Wod.Wiki - Notebooks`:t===`/notes`?e=`Wod.Wiki - Notes`:t.startsWith(`/note/`)?e=`Wod.Wiki - Note`:t.startsWith(`/pages`)||t.startsWith(`/page/`)?e=`Wod.Wiki - Pages`:t.startsWith(`/tags`)||t.startsWith(`/t/`)?e=`Wod.Wiki - Tags`:t===`/feeds`?e=`Wod.Wiki - Feeds`:t.startsWith(`/feed/`)?e=`Wod.Wiki - Feed`:t.startsWith(`/efforts`)?e=`Wod.Wiki - Efforts`:t.startsWith(`/equipment`)?e=`Wod.Wiki - Equipment`:t.startsWith(`/sessions`)||t.startsWith(`/session/`)?e=`Wod.Wiki - Sessions`:t.startsWith(`/dashboards`)||t.startsWith(`/dashboard/`)?e=`Wod.Wiki - Dashboards`:t.startsWith(`/playgrounds`)&&(e=`Wod.Wiki - Playgrounds`),document.title=e}let n=setTimeout(()=>{E7(document.title,e.pathname+e.search)},0);return()=>clearTimeout(n)},[e.pathname]),null}function O7(e,t){let n=e.match(RegExp(`^${t}:\\s*"([^"]+)"`,`m`));if(!n?.[1])throw Error(`Guide example is missing frontmatter field: ${t}`);return n[1]}function k7(e){let t=e.match(/```time\n([\s\S]*?)\n```/);if(!t)throw Error("Guide example is missing a ```time fenced block.");return t[1]}function A7(e,t){let n=O7(e,`title`),r=O7(e,`subtitle`),i=k7(e);return{title:n,subtitle:r,docsPath:t,workout:i,storyContent:[`# `+n,``,r,``,"```time",i,"```"].join(`
464
+ `));let i=e,a=t.slug.trim().toLowerCase().replace(/\s+/g,`-`);if(a!==t.slug&&(t.slug=a,i=Za(i,[`slug`],a)),t.label.trim()!==t.label&&(t.label=t.label.trim(),i=Za(i,[`label`],t.label)),t.updatedAt=new Date().toISOString(),t.registrySource===`bundled`){let e=s8(i,t.slug,t.label);i=e.raw,t.id=e.id,t.slug=e.slug,t.label=e.label,t.registrySource=`user`}try{let e=t.ownerNoteId??_.current?.id??`equipment/${t.slug}`,n=_.current?.id===e?_.current.revision:0,a=await e8({kind:`equipment`,slug:t.slug,rawContent:i,title:t.label,expectedSourceRevision:n,noteId:e});_.current={id:a.id,revision:a.sourceRevision},await r(),d(t)}catch(e){throw Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save equipment.`,variant:`destructive`}),e}},[u,r]),{onChange:y,onLineChange:b,onBlur:x,flush:S}=O1({onSave:v});return{document:i,setDocument:(0,U.useCallback)(e=>{a(e),y(e)},[y]),isLoading:o,equipment:u,isEditable:g,notFound:f,flush:S,onLineChange:b,onBlur:x,save:(0,U.useCallback)(e=>v(e??i),[v,i]),remove:(0,U.useCallback)(async()=>{let e=u?.slug;if(e)try{await t8(`equipment`,e),_.current=null,d(null),await r()}catch(e){throw Q({title:`Delete failed`,description:e instanceof Error?e.message:`Failed to delete equipment.`,variant:`destructive`}),e}},[u,r]),cloneForEdit:(0,U.useCallback)(async()=>{if(!u||u.registrySource!==`bundled`)return null;let e=s8(i||fl(u),u.slug,u.label),t={...u,id:e.id,slug:e.slug,label:e.label,registrySource:`user`,ownerNoteId:`equipment/${e.slug}`,sourceId:`equipment`,sourcePath:`equipment/${e.slug}`,createdAt:new Date().toISOString(),updatedAt:new Date().toISOString()};d(t),a(e.raw);try{let t=await e8({kind:`equipment`,slug:e.slug,rawContent:e.raw,title:e.label,expectedSourceRevision:0});_.current={id:t.id,revision:t.sourceRevision},await r()}catch(e){throw Q({title:`Clone not saved`,description:e instanceof Error?e.message:`Failed to save the cloned copy.`,variant:`destructive`}),e}return t},[u,i,r]),error:c,isAliasMatch:m}}function l8(e){let{isReady:t,registry:n}=xM(),{isReady:r,revision:i,registry:a}=yM(),[o,s]=(0,U.useState)({efforts:[],usedBy:[]});return(0,U.useEffect)(()=>{if(!t||!r||!e){s({efforts:[],usedBy:[]});return}let n=!1;async function i(){let t=a.list().filter(t=>t.equipment?.includes(e)??!1),r=await Z.getEquipmentUsage(e);n||s({efforts:t,usedBy:r})}return i(),()=>{n=!0}},[e,t,r,i,n,a]),o}function u8(){let{slug:e}=wt(),[t]=cn(),n=Vn(),{theme:r}=Mi(),i=r===`dark`?`dark`:`vs`,{isReady:a,refresh:o}=xM(),{document:s,setDocument:c,isLoading:l,equipment:u,isEditable:d,notFound:f,cloneForEdit:p,error:m,onLineChange:h,onBlur:g,flush:_}=c8(e),[v,y]=(0,U.useState)([]),b=t.get(`mode`)===`create`,[x,S]=(0,U.useState)(()=>o8(e&&e!==`new`?e.trim().toLowerCase().replace(/\s+/g,`-`):``)),C=(0,U.useCallback)(async()=>{let{equipment:e,errors:t}=dl(x);if(t.length>0){Q({title:`Invalid YAML`,description:t.join(`
465
+ `),variant:`destructive`});return}let r=e.slug.trim();if(!r){Q({title:`Missing slug`,description:`A unique slug is required.`,variant:`destructive`});return}if(!/^[a-z0-9]+(-[a-z0-9]+)*$/.test(r)){Q({title:`Invalid slug`,description:`Slug must be lowercase and hyphenated — fix "slug: ${r}" in the document.`,variant:`destructive`});return}try{await e8({kind:`equipment`,slug:r,rawContent:x,title:e.label.trim()||EO(r),expectedSourceRevision:0}),await o(),n(PN(r),{replace:!0})}catch(e){Q({title:`Save failed`,description:e instanceof Error?e.message:`Failed to save equipment.`,variant:`destructive`})}},[x,o,n]);B1({content:b?x:s,scriptBlocks:v});let w=u?.ownerNoteId??(e?`equipment/${e}`:``),T=(0,U.useMemo)(()=>w?G1({id:w,type:`collection`}):null,[w]),E=Z1({noteId:w,stamps:T?.stamps??[]}),D=l8(u?.slug),O=(0,U.useMemo)(()=>({efforts:D.efforts.map(e=>({id:e.slug,title:e.label,to:RN(e.slug)})),related:D.usedBy.map(e=>({id:e.noteId,title:e.title,to:H1(e.noteId)})),backlinks:E.backlinks}),[D,E.backlinks]);(0,U.useEffect)(()=>{u&&(window.document.title=`Wod.Wiki - ${u.label}`)},[u]);let k=(0,U.useCallback)(async()=>{if(u)try{let e=await p();e&&(n(PN(e.slug)),Q({title:`Cloned`,description:`Created a custom copy of "${u.label}". You can now edit it.`}))}catch(e){Q({title:`Clone failed`,description:e instanceof Error?e.message:String(e),variant:`destructive`})}},[p,u,n]);if(!a||l)return(0,W.jsx)(`div`,{className:`flex items-center justify-center py-20`,children:(0,W.jsx)(`div`,{className:`animate-pulse h-4 w-32 bg-muted rounded`})});if(b){let t=(0,W.jsx)(RV,{primary:(0,W.jsx)(K,{onClick:C,"data-testid":BU.EQUIPMENT_CREATE_BTN,children:`Create Equipment`}),children:(0,W.jsx)(K,{variant:`outline`,onClick:()=>n($.equipment),children:`Cancel`})});return(0,W.jsx)(`div`,{"data-testid":BU.EQUIPMENT_DETAIL_ROOT,className:`contents`,children:(0,W.jsx)(KB,{title:e&&e!==`new`?`New equipment: ${e}`:`New equipment`,actions:t,editor:(0,W.jsx)(`div`,{className:`relative`,"data-testid":`equipment-create-editor`,children:(0,W.jsx)(YZ,{value:x,onChange:S,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,onBlocksChange:y})})})})}if(m)return(0,W.jsxs)(`div`,{"data-testid":BU.EQUIPMENT_LOAD_ERROR,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:`Equipment could not be loaded`}),(0,W.jsx)(`p`,{className:`text-sm text-destructive`,children:m})]}),(0,W.jsx)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:(0,W.jsx)(K,{variant:`outline`,onClick:()=>n($.equipment),children:`Back to Equipment`})})]});if(f||!u)return(0,W.jsxs)(`div`,{"data-testid":BU.EQUIPMENT_NOT_FOUND,className:`flex flex-col items-center justify-center gap-6 py-16 px-4 text-center max-w-lg mx-auto`,children:[(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`h2`,{className:`text-xl font-semibold tracking-tight`,children:[`Equipment “`,e,`” not found`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No equipment definition exists for this slug yet. You can create a new definition page for it.`})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-3`,children:[(0,W.jsx)(K,{onClick:()=>n(`${PN(e??`new`)}?mode=create`),"data-testid":BU.EQUIPMENT_NOT_FOUND_CREATE_BTN,children:`Create Equipment Page`}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n($.equipment),children:`Back to Equipment`})]})]});let A=(0,W.jsxs)(RV,{primary:d?void 0:(0,W.jsxs)(K,{variant:`outline`,onClick:k,"data-testid":BU.EQUIPMENT_DETAIL_CLONE_BTN,children:[(0,W.jsx)(xe,{className:`size-4 mr-1.5`}),`Clone`]}),children:[(0,W.jsx)(K,{variant:`ghost`,size:`icon`,onClick:()=>SU()?n(-1):n($.equipment),"aria-label":`Back to Equipment`,title:SU()?`Back`:`Back to Equipment`,children:(0,W.jsx)(N,{className:`size-4`})}),(0,W.jsx)(X6,{"data-testid":BU.EQUIPMENT_DETAIL_SOURCE,variant:u.registrySource===`bundled`?`secondary`:`default`,children:u.registrySource===`bundled`?`Bundled`:`Custom`})]});return(0,W.jsx)(`div`,{"data-testid":BU.EQUIPMENT_DETAIL_ROOT,className:`contents`,children:(0,W.jsx)(KB,{title:u.label,titleTestId:BU.EQUIPMENT_DETAIL_LABEL,actions:A,editor:(0,W.jsxs)(`div`,{className:`relative`,"data-testid":BU.EQUIPMENT_DETAIL_NOTEBOOK_EDITOR,children:[(0,W.jsx)(YZ,{noteId:w,value:s,onChange:c,onCursorPositionChange:h,onBlur:g,onSaveRequest:_,onCommitChange:_,theme:i,readonly:!1,showLineNumbers:!0,enablePreview:!0,enableLinting:!0,enableOverlay:!0,mode:`edit`,onBlocksChange:y}),(0,W.jsx)(Q1,{data:O,up:T?.up,relatedLabel:`Used in`})]})})})}var d8=`wodwiki-user-calcs`,f8=1,p8=`calcs`,m8=`user-calc:`,h8;function g8(){return h8||=cr(d8,f8,{upgrade(e){e.objectStoreNames.contains(p8)||e.createObjectStore(p8,{keyPath:`id`})}}),h8}var _8={scope:`segment`};async function v8(){return VP?(await YP(m8)).map(e=>e.value).sort((e,t)=>t.updatedAt-e.updatedAt):(await(await g8()).getAll(p8)).sort((e,t)=>t.updatedAt-e.updatedAt)}async function y8(e){if(VP){await XP(m8+e.id,{id:e.id,lineForm:e.lineForm,updatedAt:e.updatedAt??Date.now()});return}await(await g8()).put(p8,{...e,updatedAt:e.updatedAt??Date.now()})}async function b8(e){if(VP)return ZP(m8+e);await(await g8()).delete(p8,e)}async function x8(){let e=await v8(),t=[],n=[];for(let r of e)try{let{defs:e}=Ep(r.lineForm,_8);t.push(...e)}catch(e){n.push({id:r.id,message:e instanceof Error?e.message:String(e)})}return{defs:t,errors:n}}var S8={segment:`per record`,workout:`at workout end`},C8=new Set([`segment`,`workout`]);function w8({initialTag:e}={}){let[t]=cn(),n=t.get(`tag`)??e,[r,i]=(0,U.useState)([]),[a,o]=(0,U.useState)([]),[s,c]=(0,U.useState)([]),[l,u]=(0,U.useState)(null),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)(``),[h,g]=(0,U.useState)([]),[_,v]=(0,U.useState)(``),[y,b]=(0,U.useState)(``),[x,S]=(0,U.useState)(null),[C,w]=(0,U.useState)(!1),T=(0,U.useCallback)(async()=>{let[e,t]=await Promise.all([Z.getAllTags(),Z.getAllTagTypes()]),n=await x8().catch(()=>({defs:[],errors:[]}));i(e),o(t);let r=Bf.filter(e=>C8.has(e.scope)).map(e=>({name:e.id,grain:S8[e.scope]??e.scope}));for(let e of n.defs)C8.has(e.scope)&&r.push({name:e.id,grain:S8[e.scope]??e.scope});c(r)},[]);(0,U.useEffect)(()=>{T()},[T]),(0,U.useEffect)(()=>{if(!n||r.length===0)return;let e=r.find(e=>e.label===n);e&&u(e.id)},[n,r]);let E=r.find(e=>e.id===l)??null;(0,U.useEffect)(()=>{E&&(f(E.label),m(E.type??``),g(E.contributions??[]))},[E]);let D=bR(),O=(0,U.useMemo)(()=>Eo(D),[D]),k=async()=>{if(!E)return!1;let e=d.trim();return e.length===0?(S("A tag needs a name — that name is what `#slug` refers to."),!1):r.find(t=>t.id!==E.id&&t.label.trim()===e)?(S(`Another tag is already called "${e}".`),!1):(await Z.putTag({...E,label:e,type:p||void 0,contributions:h}),await Pj(),await T(),S(null),w(!0),!0)},A=async()=>{let e=_.trim();if(e.length===0){S(`A tag needs a name.`);return}if(r.some(t=>t.label.trim()===e)){S(`A tag called "${e}" already exists.`);return}let t={id:`tag-${e}-${Date.now().toString(36)}`,label:e,type:y||void 0,contributions:[],createdAt:Date.now()};await Z.putTag(t),await Pj(),await T(),u(t.id),v(``),S(null)},j=async()=>{E&&(await Z.deleteTag(E.id),await Pj(),await T(),u(null))},M=(e,t)=>{w(!1),g(n=>n.map((n,r)=>r===e?t:n))},N=e=>{g(t=>t.filter((t,n)=>n!==e))},P=(0,U.useMemo)(()=>{let e=new Set(a.map(e=>e.name));for(let t of r)t.type&&e.add(t.type);return p&&!e.has(p)&&e.add(p),[...e].sort()},[a,r,p]);return(0,W.jsxs)(`div`,{className:`max-w-4xl mx-auto p-6 space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-2`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Tags`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A tag is a named bundle a script can point at:`,` `,(0,W.jsxs)(`code`,{className:`font-mono`,children:[`5 reps @ 100 kg `,`#heavy`]}),`. What the tag brings applies to the line it sits on. A tag can contribute a metric (a typed value with a unit), another tag, or a function — a named calculation that runs where the tag applies.`]}),O.length>0&&(0,W.jsxs)(`p`,{className:`text-xs text-destructive`,children:[`These tags apply each other in a loop: `,O.map(e=>e.join(` → `)).join(`; `),`. A loop contributes nothing.`]})]}),(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`New tag`}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-3`,children:[(0,W.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),A()},className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[200px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`,placeholder:`heavy`,value:_,onChange:e=>v(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`w-40`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Kind`}),(0,W.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-2 text-xs outline-none focus:border-primary`,value:y,onChange:e=>b(e.target.value),children:[(0,W.jsx)(`option`,{value:``,children:`—`}),P.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})]}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,className:`h-9`,children:[(0,W.jsx)(On,{className:`size-3.5 mr-1`}),` Add Tag`]})]}),x&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:x})]})]}),!E&&r.length>0&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground italic`,children:[`No tag is selected — open one from the `,(0,W.jsx)(`a`,{className:`text-primary hover:underline`,href:`/tags`,children:`tag catalogue`}),`.`]}),E&&(0,W.jsxs)(`section`,{className:`space-y-3`,children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground`,children:[`Edit `,E.label]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-4`,children:[(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Created `,new Date(E.createdAt).toLocaleDateString()]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[200px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 font-mono text-xs outline-none focus:border-primary`,value:d,onChange:e=>f(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`w-40`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Kind`}),(0,W.jsxs)(`select`,{className:`w-full h-9 rounded-md border border-input bg-background px-2 text-xs outline-none focus:border-primary`,value:p,onChange:e=>m(e.target.value),children:[(0,W.jsx)(`option`,{value:``,children:`—`}),P.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})]})]}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`Contributions`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs`,onClick:()=>g(e=>[...e,{kind:`metric`,type:``,value:``}]),children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Metric`]}),(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs`,onClick:()=>g(e=>[...e,{kind:`tag`,slug:``}]),children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Tag`]}),(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-7 text-xs`,onClick:()=>g(e=>[...e,{kind:`function`,name:``}]),children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Function`]})]})]}),h.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`This tag contributes nothing yet.`}):(0,W.jsx)(`div`,{className:`space-y-2`,children:h.map((e,t)=>(0,W.jsx)(T8,{contribution:e,tagOptions:r.filter(e=>e.id!==E.id).map(e=>e.label.trim()),functionOptions:s,onChange:e=>M(t,e),onRemove:()=>N(t)},t))})]}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(K,{type:`button`,size:`sm`,className:`h-9`,onClick:()=>void k(),children:`Save`}),(0,W.jsxs)(K,{type:`button`,size:`sm`,variant:`outline`,className:`h-9`,onClick:()=>void j(),children:[(0,W.jsx)(Ue,{className:`size-3.5 mr-1`}),` Delete`]}),C&&(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground self-center`,children:`Saved`})]})]})]})]})}function T8({contribution:e,tagOptions:t,functionOptions:n,onChange:r,onRemove:i}){let a=`h-8 rounded-md border border-input bg-background px-2 text-xs outline-none focus:border-primary`;return(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[e.kind===`metric`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`input`,{"aria-label":`Metric type`,className:`${a} w-32 font-mono`,placeholder:`type`,value:e.type,onChange:t=>r({...e,type:t.target.value})}),(0,W.jsx)(`input`,{"aria-label":`Metric value`,className:`${a} w-32`,placeholder:`value`,value:String(e.value),onChange:t=>r({...e,value:t.target.value})}),(0,W.jsx)(`input`,{"aria-label":`Metric unit`,className:`${a} w-24`,placeholder:`unit`,value:e.unit??``,onChange:t=>r({...e,...t.target.value?{unit:t.target.value}:{unit:void 0}})})]}),e.kind===`tag`&&(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)(`select`,{"aria-label":`Applied tag`,className:`${a} w-48 font-mono`,value:e.slug,onChange:t=>r({...e,slug:t.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`choose a tag…`}),t.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})}),e.kind===`function`&&(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)(`select`,{"aria-label":`Function`,className:`${a} w-56 font-mono`,value:e.name,onChange:t=>r({...e,name:t.target.value}),children:[(0,W.jsx)(`option`,{value:``,children:`choose a function…`}),n.map(e=>(0,W.jsxs)(`option`,{value:e.name,children:[e.name,` — `,e.grain]},e.name))]})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Remove contribution`,className:`text-muted-foreground hover:text-destructive`,onClick:i,children:(0,W.jsx)(Ue,{className:`size-3.5`})})]})}var E8=`h-11 w-full rounded-md border border-input bg-background px-3 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;function D8(e){return e.date?e.date:`/page/${e.slug??e.pageId}`}function O8({open:e,onOpenChange:t,entry:n,mode:r,provider:i,onSaved:a,onCloned:o}){let[s,c]=(0,U.useState)(``),[l,u]=(0,U.useState)(``),[d,f]=(0,U.useState)(``),[p,m]=(0,U.useState)([]),[h,g]=(0,U.useState)(!1),[_,v]=(0,U.useState)(null),y=(0,U.useRef)(!1),b=n.id,x=n.journalDate,S=n.sourceId;(0,U.useEffect)(()=>{e&&(c(r===`clone`?x??_P():``),u(``),f(S??``),v(null))},[e,r,b,x,S]),(0,U.useEffect)(()=>{if(!e||r!==`relationships`)return;let t=!1;return i.getRecords().then(e=>{t||m(e.filter(e=>e.id!==n.id&&e.seedOrigin!==`seed`&&!e.sourceId?.startsWith(`notebook:`)))}).catch(()=>{}),()=>{t=!0}},[e,r,i,n.id]);let C=r===`clone`,w=`note-placement-sources-${n.id}`,T=n.placements??[],E=()=>{y.current||t(!1)},D=async e=>{if(!y.current){y.current=!0,g(!0),v(null);try{a?.(await e()),t(!1)}catch{v(`Could not save — your fields are kept. Try again.`)}finally{y.current=!1,g(!1)}}},O=async()=>{if(y.current)return;let e=s.trim(),t=l.trim();if(!e&&!t){v(`Choose a journal date or a named page to place the note on.`);return}if(e&&t){v(`Choose a journal date OR a named page — a placement names one page, never both.`);return}if(e&&!yP(e)){v(`Enter a valid date (YYYY-MM-DD).`);return}let r=e?{date:e}:{slug:t};await D(()=>i.addRecordPlacement(n.id,r))},k=async e=>{await D(()=>i.removeRecordPlacement(n.id,e))},A=async e=>{let t=s.trim(),r=l.trim();if(!t&&!r){v(`Choose the journal date or named page to move the note to.`);return}if(t&&r){v(`Choose a journal date OR a named page — a move targets one page, never both.`);return}if(t&&!yP(t)){v(`Enter a valid date (YYYY-MM-DD).`);return}let a=t?{date:t}:{slug:r};await D(()=>i.moveRecordPlacement(n.id,e,a))};return(0,W.jsx)(OC,{open:e,onClose:E,title:C?`Clone note`:`Note placements`,description:C?`Independent copy. Results and attachments are not copied.`:void 0,presentation:`sheet`,footer:(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(K,{type:`button`,variant:`outline`,size:`lg`,onClick:E,disabled:h,children:`Cancel`}),(0,W.jsx)(K,{type:`submit`,form:`note-placement-form`,size:`lg`,disabled:h,children:h?`Saving…`:C?`Clone`:`Save lineage`})]}),children:(0,W.jsxs)(`form`,{id:`note-placement-form`,onSubmit:async e=>{if(e.preventDefault(),!y.current){y.current=!0,g(!0),v(null);try{let e=s.trim(),r=l.trim(),c=d.trim(),u=e===``?null:yP(e);if(e&&!u){v(`Enter a valid date (YYYY-MM-DD).`);return}if(C){if(!e&&!r){v(`Choose a destination date or named page for the clone.`);return}if(e&&r){v(`Choose a destination date OR a named page — a clone targets one page, never both.`);return}let i=await CP.create({journalDate:e||void 0,slug:r||void 0,title:n.title,rawContent:n.rawContent,tags:n.tags,sourceId:n.id,type:`journal`});o?.(i),t(!1);return}let f={};if(c!==(S??``)){if(c===``)f.sourceId=null;else try{let e=await CP.resolve(c);if(!e||e.id===n.id){v(`Source note not found.`);return}f.sourceId=e.id}catch{v(`Source note not found.`);return}}if(Object.keys(f).length===0){t(!1);return}let p=await i.updateRecord(n.id,f);a?.(p),t(!1)}catch{v(`Could not save — your fields are kept. Try again.`)}finally{y.current=!1,g(!1)}}},className:`flex flex-col gap-4`,noValidate:!0,children:[!C&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:`Note path`}),(0,W.jsxs)(`code`,{className:`rounded bg-muted px-2.5 py-1.5 font-mono text-xs text-muted-foreground select-all`,children:[`/notes/`,n.id]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The note keeps this address wherever it is placed.`})]}),!C&&(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:`Pages`}),T.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This note is not placed on any page yet.`}):(0,W.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:T.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded border border-border px-2.5 py-1.5`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:D8(e)}),(0,W.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(K,{type:`button`,variant:`outline`,size:`sm`,disabled:h,onClick:()=>void A(e.pageId),children:`Move`}),(0,W.jsx)(K,{type:`button`,variant:`outline`,size:`sm`,disabled:h,onClick:()=>void k(e.pageId),children:`Remove`})]})]},e.pageId))})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`label`,{htmlFor:`note-placement-date`,className:`text-sm font-medium`,children:`Journal date`}),(0,W.jsx)(`input`,{id:`note-placement-date`,type:`date`,className:E8,value:s,onChange:e=>c(e.target.value),disabled:h}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:C?`Defaults to the note’s date.`:`The calendar page to place the note on, or to move it to.`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`label`,{htmlFor:`note-placement-slug`,className:`text-sm font-medium`,children:`Named page`}),(0,W.jsx)(`input`,{id:`note-placement-slug`,type:`text`,className:E8,value:l,onChange:e=>u(e.target.value),placeholder:`e.g. marathon-block`,autoCapitalize:`none`,spellCheck:!1,disabled:h}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`The /page/<slug> page to place the note on, or to move it to. Typing an existing page's slug shares that page with its notes — it does not create a unique copy.`})]}),!C&&(0,W.jsx)(K,{type:`button`,size:`lg`,disabled:h,onClick:()=>void O(),children:h?`Saving…`:`Place on this page`}),C?null:(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`label`,{htmlFor:`note-placement-source`,className:`text-sm font-medium`,children:`Source note`}),(0,W.jsx)(`input`,{id:`note-placement-source`,type:`text`,className:E8,value:d,onChange:e=>f(e.target.value),list:w,autoCapitalize:`none`,spellCheck:!1,disabled:h}),(0,W.jsx)(`datalist`,{id:w,children:p.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.title||`Untitled`},e.id))}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Leave empty to clear.`})]}),_&&(0,W.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:_})]})})}var k8=new Kk;function A8({noteId:e,theme:t}){let n=Vn(),r=Sn(),[i]=cn(),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(!1),l=(0,U.useRef)(0),u=(0,U.useRef)(null),d=(0,U.useRef)(async()=>{}),f=r.pathname.startsWith(`/page/`)||a!==null&&!ka(a,r_(a)),[p,m]=(0,U.useState)(null),[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(!1),[y,b]=(0,U.useState)(null),x=(0,U.useCallback)(()=>{navigator.clipboard?.writeText(window.location.href).then(()=>{v(!0),setTimeout(()=>v(!1),1500)})},[]),C=LQ();(0,U.useEffect)(()=>{nz().catch(()=>{})},[e]),(0,U.useEffect)(()=>{let t=!1;return o(null),c(!1),m(null),k8.getRecord(e).then(e=>{if(!t){if(!e){c(!0);return}o(e),l.current=e.sourceRevision??0,u.current={rawContent:e.rawContent,blocks:e.blocks??{},sourceRevision:e.sourceRevision??0}}}).catch(()=>{t||c(!0)}),()=>{t=!0}},[e,i]);let T=a?.sourceId;(0,U.useEffect)(()=>{if(b(null),!T)return;let e=!1;return k8.getRecord(T).then(t=>{e||b(t)}).catch(()=>{}),()=>{e=!0}},[T]);let E=(0,U.useMemo)(()=>a?G1(a):{zone:null,up:null,stamps:[]},[a]);GM(E.zone);let[D,O]=(0,U.useState)([]),[k,A]=(0,U.useState)([]),j=a?.id;(0,U.useEffect)(()=>{if(A([]),O([]),!j)return;let e=!1,t=()=>{Z.getSessionsForNote(j).then(t=>{e||A(t)}).catch(()=>{})};t();let n=tK(n=>{!e&&n.noteId===j&&t()});return()=>{e=!0,n()}},[j]);let M=(0,U.useCallback)(async t=>{if(a)try{await d.current();let e=u.current;if(!e)throw Error(`The note draft is unavailable.`);let r=w(),i=await DR({noteId:a.id,rawContent:e.rawContent,blocks:e.blocks,expectedSourceRevision:l.current},t,r);l.current=i.note.sourceRevision,M1.set(r,{block:i.block,noteId:a.id,captured:i,returnTo:TN(a.id)}),n(ON(r))}catch(t){m({noteId:e,message:`Workout not started. ${t instanceof Error?t.message:String(t)} Your draft is kept.`})}},[a,e,n]);B1({content:a?.rawContent??``,scriptBlocks:D,onStartWorkout:M,results:k});let N=Z1(a?{noteId:a.id,stamps:E.stamps}:{noteId:``,stamps:[]}),P=(0,U.useCallback)(e=>{l.current=e.sourceRevision;let t=u.current,n=t?.rawContent===e.rawContent&&JSON.stringify(Object.values(t.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))===JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));o(t=>t&&{...t,...n?{blocks:e.blocks}:{},sourceRevision:e.sourceRevision})},[]),F=(0,U.useCallback)(async t=>{let n=await lP.saveNote({noteId:e,rawContent:t.rawContent,blocks:t.blocks,expectedSourceRevision:l.current});return P({rawContent:n.rawContent,blocks:n.blocks??{},sourceRevision:n.sourceRevision??l.current}),m(null),o(e=>e?.id===n.id?{...e,title:n.title}:e),{rawContent:n.rawContent,blocks:n.blocks??{},sourceRevision:n.sourceRevision??0}},[e,P]),{onChange:I,onBlur:L,onLineChange:ee,flush:te}=O1({onSave:async e=>{await F(e)},getSnapshotKey:e=>JSON.stringify([e.rawContent,Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport])]),onError:t=>m({noteId:e,message:`Save failed. ${t instanceof Error?t.message:String(t)} Your draft is kept. Retry saving.`})});d.current=te;let ne=(0,U.useCallback)(e=>{let t=u.current?.rawContent!==e.rawContent||JSON.stringify(Object.values(u.current?.blocks??{}).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]))!==JSON.stringify(Object.values(e.blocks).map(e=>[e.id,e.from,e.to,e.kind,e.dialect,e.sport]));u.current=e,t&&I(e)},[I]),R=(0,U.useCallback)(e=>{o(t=>t&&{...t,rawContent:e})},[]),re=(0,U.useCallback)(async e=>{await te();let t=u.current;if(!t)throw Error(`The note draft is unavailable.`);let n=rR({...t,sourceRevision:l.current},e),r=await F(n);u.current=r,o(e=>e&&{...e,...r})},[te,F]),ie=(0,U.useCallback)(()=>Promise.resolve(),[]),ae;if(s)ae=(0,W.jsxs)(`div`,{className:`flex flex-1 flex-col items-center justify-center gap-3 text-zinc-400`,children:[(0,W.jsx)(`p`,{children:`Note not found.`}),(0,W.jsx)(K,{variant:`outline`,onClick:()=>n(-1),children:`Go back`})]});else if(!a)ae=(0,W.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-zinc-400`,children:`Loading…`});else{let r=`inline-flex min-h-11 items-center gap-1 rounded-pill border border-border bg-card px-2.5 text-xs font-semibold text-muted-foreground transition-colors hover:bg-accent`,i=(0,W.jsxs)(RV,{label:`Note actions`,children:[(0,W.jsxs)(`button`,{type:`button`,className:r,onClick:()=>g(`relationships`),children:[(0,W.jsx)(Wt,{className:`size-3.5`,"aria-hidden":`true`}),`Note placements`]}),(0,W.jsxs)(`button`,{type:`button`,className:r,onClick:()=>g(`clone`),children:[(0,W.jsx)(rt,{className:`size-3.5`,"aria-hidden":`true`}),`Clone`]}),(0,W.jsxs)(`button`,{type:`button`,className:r,onClick:x,title:TN(a.id),"aria-label":`Copy link`,children:[_?(0,W.jsx)(un,{className:`size-3.5 text-emerald-500`,"aria-hidden":`true`}):(0,W.jsx)(S,{className:`size-3.5`,"aria-hidden":`true`}),_?`Copied`:`Copy link`]})]});ae=(0,W.jsxs)(IR,{notePersistence:lP,provider:k8,children:[(0,W.jsx)(KB,{title:a.title,subtitle:E.up?(0,W.jsx)(_n,{to:E.up.to,className:`underline-offset-2 hover:underline`,children:E.up.title}):void 0,actions:i,editor:(0,W.jsxs)(`div`,{className:`flex flex-col gap-4 px-4 py-6 sm:px-6 min-w-0 max-w-full`,children:[(0,W.jsx)(Q1,{data:N,up:E.up}),(a.journalDate&&a.journalDate!==a.title||a.slug||a.sourceId)&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground`,children:[a.journalDate&&a.journalDate!==a.title&&(0,W.jsx)(_n,{to:CN(a.journalDate),className:`underline-offset-2 hover:underline`,children:a.journalDate}),a.slug&&(0,W.jsxs)(_n,{to:jN(a.slug),className:`underline-offset-2 hover:underline`,children:[`/p/`,a.slug]}),a.sourceId&&(0,W.jsxs)(`span`,{children:[`Cloned from`,` `,y?(0,W.jsx)(_n,{to:TN(y.id),className:`underline-offset-2 hover:underline`,children:y.title||y.id}):(()=>{let e=K1(a.sourceId);return e?(0,W.jsx)(_n,{to:e.to,className:`underline-offset-2 hover:underline`,children:e.title}):a.sourceId})()]})]}),C?(0,W.jsx)(`div`,{className:`rounded-lg border border-border bg-card p-4 shadow-sm min-h-[240px] focus-within:border-accent/80 transition-colors`,children:(0,W.jsx)(YZ,{value:a.rawContent,onChange:R,onBlur:L,noteId:a.id,noteBlocks:a.blocks,sourceRevision:a.sourceRevision,onIdentityChange:ne,onSaved:P,beforeRun:async()=>(await te(),l.current),onSaveRequest:te,onCommitChange:te,onCursorPositionChange:ee,readonly:f,theme:t,showLineNumbers:!1,onCompleteWorkout:ie,onBlocksChange:O,placeholder:`Write workout or notes here…`})}):(0,W.jsx)(`div`,{className:`flex items-center justify-center text-zinc-400 text-sm py-8`,children:`Loading…`}),(0,W.jsx)(iR,{noteId:a.id,blocks:a.blocks,sourceRevision:a.sourceRevision,onRevert:f?void 0:re}),p?.noteId===e&&(0,W.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:p.message})]})}),h!==null&&(0,W.jsx)(O8,{open:!0,onOpenChange:e=>{e||g(null)},entry:a,mode:h,provider:k8,onSaved:e=>o(t=>t&&t.id===e.id?{...t,journalDate:e.journalDate,slug:e.slug,sourceId:e.sourceId,placements:e.placements}:t),onCloned:e=>n(`${TN(e.id)}?edit=1`)})]})}return ae}var j8=new Kk;function M8({slug:e}){let[t,n]=(0,U.useState)(null);return(0,U.useEffect)(()=>{let t=!1;return n(null),j8.getPageRecords(e).then(e=>{t||n(e)}).catch(()=>{t||n([])}),()=>{t=!0}},[e]),(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl flex-col gap-4 px-4 py-6`,children:[(0,W.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,W.jsxs)(`h1`,{className:`text-2xl font-semibold`,children:[`/page/`,e]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:t===null?`Loading…`:t.length===0?`No notes are placed on this page yet.`:`${t.length} ${t.length===1?`note`:`notes`} on this page.`})]}),t!==null&&t.length>0&&(0,W.jsx)(`ul`,{className:`flex flex-col gap-2`,children:t.map(e=>(0,W.jsx)(`li`,{children:(0,W.jsxs)(_n,{to:TN(e.id),className:`block rounded-md border border-border px-3 py-2 hover:bg-muted`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium`,children:e.title||`Untitled`}),(0,W.jsxs)(`span`,{className:`ml-2 font-mono text-xs text-muted-foreground`,children:[`/note/`,e.id]})]})},e.id))})]})}var N8=new Kk;function P8(e){let t=new Map;for(let n of e){let e=n.tags[0]?.toLowerCase()??`untagged`,r=t.get(e);r?r.push(n):t.set(e,[n])}return Array.from(t.entries()).map(([e,t])=>({id:`day-group-${e}`,label:e===`untagged`?`Untagged`:`#${e}`,entries:t}))}function F8(e){return gP(new Date(e.targetDate))}function I8({slug:e,date:t}){let[n,r]=(0,U.useState)(null);(0,U.useEffect)(()=>{let n=!1;return N8.getRecords().then(i=>{if(n)return;let a=i.filter(n=>n.sourceId?.startsWith(`notebook:${e}`)?F8(n)===t:!1);r(a.sort((e,t)=>t.createdAt-e.createdAt))}).catch(()=>{n||r([])}),()=>{n=!0}},[e,t]);let i=(0,U.useMemo)(()=>n?P8(n):[],[n]),{setL3Items:a}=WM();(0,U.useEffect)(()=>{if(i.length===0){a([]);return}let e=i.map(e=>({id:e.id,label:e.label,level:3,action:{type:`scroll`,sectionId:e.id}}));return a(e),()=>a([])},[i,a]);let o=n===null?(0,W.jsx)(`div`,{className:`flex flex-1 items-center justify-center text-zinc-400`,children:`Loading…`}):n.length===0?(0,W.jsxs)(`p`,{className:`rounded-lg border border-dashed border-border p-6 text-sm text-muted-foreground`,children:[`No notes in this notebook for `,t,`.`]}):(0,W.jsx)(`div`,{className:`flex flex-col gap-6`,children:i.map(e=>(0,W.jsxs)(`section`,{id:e.id,className:`flex flex-col rounded-lg border border-border overflow-hidden`,children:[(0,W.jsxs)(`h3`,{className:`px-4 py-2 text-xs font-black uppercase tracking-wider text-muted-foreground bg-muted/40`,children:[e.label,` · `,e.entries.length]}),(0,W.jsx)(`ul`,{className:`flex flex-col divide-y divide-border`,children:e.entries.map(e=>(0,W.jsx)(`li`,{children:(0,W.jsxs)(_n,{to:TN(e.id),className:`flex flex-col gap-0.5 px-4 py-3 hover:bg-muted/50`,children:[(0,W.jsx)(`span`,{className:`font-medium`,children:e.title}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:new Date(e.createdAt).toLocaleTimeString()})]})},e.id))})]},e.id))});return(0,W.jsx)(KB,{title:t,subtitle:e,editor:(0,W.jsx)(`div`,{className:`flex flex-col gap-6 px-4 py-6 sm:px-6`,children:o})})}var L8=`__new__`;function R8(e){return e.open?(0,W.jsx)(z8,{...e},e.subsetQuery??`(whole-store)`):null}function z8({onOpenChange:e,initialQuery:t,subsetQuery:n,rangeStart:r,rangeEnd:i,preferredUnit:a}){let o=Vn(),{items:s,loading:c}=pP(),l=s.filter(e=>e.editable),[u,d]=(0,U.useState)(l[0]?.slug??L8),[f,p]=(0,U.useState)(``),[m,h]=(0,U.useState)(null),g=()=>e(!1);return(0,W.jsx)(L2,{open:!0,onClose:g,mode:`add`,initialWql:t,subsetQuery:n,rangeStart:r,rangeEnd:i,preferredUnit:a,onApply:async e=>{h(null);let t={title:e.title,question:e.question,type:e.type,spanCols:e.spanCols,spanFull:e.spanFull,wql:e.wql,attributes:e.attributes};try{if(u===L8){let e=f.trim()||`New Dashboard`,n=await TP.createDashboard(e);await CP.update(n,bv(n.rawContent,t)),g(),o(LN(fv(e)))}else{let e=await CP.resolve(u);await CP.update(e,bv(e.rawContent,t)),g(),o(LN(u))}}catch(e){let t=e instanceof Error?e.message:String(e);throw h(t),e}},applyLabel:`Add to dashboard`,destination:(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] font-bold uppercase tracking-wider text-muted-foreground mb-1.5`,children:`Destination`}),c?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Loading dashboards…`}):(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[l.map(e=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":u===e.slug,onClick:()=>d(e.slug),className:`rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors ${u===e.slug?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:e.title},e.slug)),(0,W.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-dest-new`,"aria-pressed":u===L8,onClick:()=>d(L8),className:`flex items-center gap-1 rounded-lg border px-3 py-1.5 text-xs font-medium transition-colors ${u===L8?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:[(0,W.jsx)(On,{className:`size-3`}),` New dashboard`]})]}),u===L8&&(0,W.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),placeholder:`New Dashboard`,"data-testid":`dashboard-new-title`,className:`w-full sm:w-64 rounded-lg border border-border bg-card px-3 py-1.5 text-sm text-foreground focus:outline-none focus:border-primary`})]}),m&&(0,W.jsxs)(`p`,{role:`alert`,"data-testid":`dashboard-save-error`,className:`mt-2 text-xs text-destructive font-mono`,children:[`Could not save: `,m]})]})})}function B8({catalog:e}){let[t,n]=(0,U.useState)([]),[r,i]=(0,U.useState)(!1),[a,o]=(0,U.useState)(``);return(0,U.useEffect)(()=>{let t=!1,r=()=>{e.listByPrefix(a,50).then(e=>{t||n(e)}).catch(()=>{})};r();let i=e.onChange?.(()=>r());return()=>{t=!0,i?.()}},[e,a]),(0,W.jsxs)(`section`,{className:`rounded-lg border p-3 text-sm`,"data-testid":`available-fields`,children:[(0,W.jsxs)(`button`,{type:`button`,className:`flex w-full items-center justify-between font-medium`,onClick:()=>i(e=>!e),children:[(0,W.jsxs)(`span`,{children:[`Available fields (`,t.length,`)`]}),(0,W.jsx)(`span`,{"aria-hidden":!0,children:r?`▾`:`▸`})]}),r&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`input`,{className:`mt-2 w-full rounded border px-2 py-1`,placeholder:`Filter fields…`,value:a,onChange:e=>o(e.target.value)}),(0,W.jsxs)(`ul`,{className:`mt-2 max-h-64 space-y-1 overflow-auto`,children:[t.map(e=>(0,W.jsxs)(`li`,{className:`flex items-baseline justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`font-mono`,children:e.path}),(0,W.jsxs)(`span`,{className:`text-xs opacity-70`,children:[e.kind,e.dimension?` · ${e.dimension}`:``,e.units.length?` · ${e.units.join(`/`)}`:``,e.spellings.length&&e.spellings[0]!==e.path?` · “${e.spellings[0]}”`:``]})]},e.id)),t.length===0&&(0,W.jsx)(`li`,{className:`opacity-60`,children:`No discovered fields for this prefix.`})]})]})]})}function V8(e){return{id:e.id,path:e.path,kind:e.kind,...e.dimension?{dimension:e.dimension}:{},units:Object.keys(e.units??{}),spellings:Object.keys(e.spellings??{})}}var H8=new class{storageInstance;listeners=new Set;constructor(e=jk){this.storageInstance=e}async listByPrefix(e,t=20){let n=e&&typeof IDBKeyRange<`u`?IDBKeyRange.bound(e,`${e}\uFFFF`,!1,!0):void 0;return(await this.storageInstance.readonly(`field_catalog`).getAllFromIndex(`by-path`,n,t)).map(V8)}async lookup(e){return(await this.storageInstance.readonly(`field_catalog`).getAllFromIndex(`by-path`,e)).map(V8)}async listValues(e,t,n=20){let r=await this.lookup(e),i=[];for(let e of r){if(i.length>=n)break;let r=t&&typeof IDBKeyRange<`u`?IDBKeyRange.bound([e.id,t],[e.id,`${t}\uFFFF`],!1,!0):void 0,a=await this.storageInstance.readonly(`field_values`).getAllFromIndex(`by-field`,r,n-i.length);for(let e of a)i.push({fieldId:e.fieldId,value:e.value})}return i}notifyChanged(){for(let e of this.listeners)e()}observeStore(e){}}(jk);function U8({label:e,value:t,className:n}){return(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 rounded border border-border bg-background/60 px-2 py-1`,children:[(0,W.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-muted-foreground`,children:e}),(0,W.jsx)(`span`,{className:G(`font-mono text-xs`,n??`text-foreground`),children:t})]})}function W8(e){return e.kind===`relative`?`last ${e.size}${e.unit}`:e.end?`from ${e.start} to ${e.end}`:`from ${e.start}`}function G8({parsed:e}){if(e.error)return(0,W.jsx)(`div`,{className:`text-sm text-destructive font-mono`,children:e.error});if(Hm(e)){let t=e.source.kind===`dataset`?(0,W.jsx)(U8,{label:`source`,value:e.source.name,className:`text-blue-400 dark:text-blue-300`}):(0,W.jsx)(U8,{label:`source`,value:`target`in e.source.query?`:${e.source.query.target}`:`:${e.source.query.agg}`,className:`text-blue-400 dark:text-blue-300`});return(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[t,e.transforms.map((e,t)=>(0,W.jsx)(U8,{label:`fn ${t+1}`,value:`${e.agg}:${e.metric}`,className:`text-green-400 dark:text-green-300`},t)),e.sink&&(0,W.jsx)(U8,{label:`sink`,value:`:${e.sink.head}`,className:`text-purple-400 dark:text-purple-300`})]})}let t=e.window&&(0,W.jsx)(U8,{label:`window`,value:W8(e.window),className:`text-sky-400 dark:text-sky-300`}),n=e.filters.map((e,t)=>(0,W.jsx)(U8,{label:e.negate?`exclude`:`filter`,value:`${e.key}:${e.values.map(e=>`${e.value}${e.wildcard?`*`:``}`).join(`|`)}`,className:`text-amber-400 dark:text-amber-300`},t));return Vm(e)?(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,W.jsx)(U8,{label:`aggregate`,value:e.agg,className:`text-blue-400 dark:text-blue-300`}),(0,W.jsx)(U8,{label:`metric`,value:e.metric}),n,e.groupBy.map((e,t)=>(0,W.jsx)(U8,{label:`group by`,value:e,className:`text-green-400 dark:text-green-300`},t)),e.rollup&&(0,W.jsx)(U8,{label:`rollup`,value:`${e.rollup.size}${e.rollup.unit}`,className:`text-purple-400 dark:text-purple-300`}),e.displayUnit&&(0,W.jsx)(U8,{label:`in`,value:e.displayUnit,className:`text-pink-400 dark:text-pink-300`}),t,e.join&&(0,W.jsx)(U8,{label:`where`,value:`:${e.join.target}`,className:`text-teal-400 dark:text-teal-300`})]}):Bm(e)?(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-1.5`,children:[(0,W.jsx)(U8,{label:`target`,value:e.target,className:`text-blue-400 dark:text-blue-300`}),n,t,e.join&&(0,W.jsx)(U8,{label:`where`,value:`${e.join.agg}:${e.join.metric}`,className:`text-teal-400 dark:text-teal-300`})]}):null}function K8({result:e}){let{parsed:t,stages:n}=e;if(t.error)return null;let r=t.groupBy.find(e=>e===`day`||e===`week`),i=r?`by ${r}`:t.rollup?`rollup ${t.rollup.size}${t.rollup.unit}`:`no rollup`,a=t.groupBy.length?`by {${t.groupBy.join(`, `)}}`:`single series`,o=[{n:1,name:`SELECT`,desc:`tag + time index scan`,count:n.selected,unit:`points`},{n:2,name:`BUCKET`,desc:i,count:n.buckets,unit:`buckets`},{n:3,name:`AGGREGATE`,desc:`${t.agg} per bucket`,count:n.aggregated,unit:`values`},{n:4,name:`GROUP`,desc:a,count:n.groups,unit:`series`}];return(0,W.jsx)(`div`,{className:`flex items-center gap-0 mt-4 overflow-x-auto`,children:o.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center`,children:[(0,W.jsxs)(`div`,{className:`border border-border rounded-lg bg-background/60 px-3 py-2 min-w-[130px]`,children:[(0,W.jsxs)(`div`,{className:`text-[10px] font-bold tracking-wide`,style:{color:mS[t%mS.length]},children:[e.n,`. `,e.name]}),(0,W.jsx)(`div`,{className:`text-[11px] text-muted-foreground`,children:e.desc}),(0,W.jsxs)(`div`,{className:`text-sm font-semibold tabular-nums mt-0.5`,children:[e.count.toLocaleString(),` `,(0,W.jsx)(`span`,{className:`text-[10px] font-normal text-muted-foreground`,children:e.unit})]})]}),t<3&&(0,W.jsx)(wn,{size:16,className:`text-muted-foreground mx-1 shrink-0`})]},e.n))})}function q8({matched:e,displayUnit:t}){let[n,r]=(0,U.useState)(!1);if(e.length===0)return null;let i=e=>{let t=[];return e.effortSlug&&t.push(`effort:${e.effortSlug}`),e.discipline&&t.push(`discipline:${e.discipline}`),e.intensityTier&&t.push(`intensity:${e.intensityTier}`),e.origin&&t.push(`origin:${e.origin}`),t},a=e=>{let t=new Date(e);return`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,`0`)}-${String(t.getDate()).padStart(2,`0`)}`};return(0,W.jsxs)(`div`,{className:`bg-card border border-border rounded-lg mt-3`,children:[(0,W.jsxs)(`button`,{onClick:()=>r(!n),className:`w-full flex items-center gap-2 px-4 py-2.5 text-sm text-muted-foreground hover:text-foreground`,children:[n?(0,W.jsx)(Et,{size:14}):(0,W.jsx)(wn,{size:14}),`Raw metric points behind this query (`,e.length,`)`,(0,W.jsx)(`span`,{className:`text-[11px] ml-auto`,children:`one row per fact from the analytics store`})]}),n&&(0,W.jsxs)(`div`,{className:`px-4 pb-3 overflow-x-auto`,children:[(0,W.jsxs)(`table`,{className:`w-full text-[11px] font-mono`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`text-muted-foreground text-left border-b border-border`,children:[(0,W.jsx)(`th`,{className:`py-1.5 pr-4 font-normal`,children:`ts`}),(0,W.jsx)(`th`,{className:`py-1.5 pr-4 font-normal`,children:`metric`}),(0,W.jsx)(`th`,{className:`py-1.5 pr-4 font-normal`,children:`value`}),(0,W.jsx)(`th`,{className:`py-1.5 font-normal`,children:`tags`})]})}),(0,W.jsx)(`tbody`,{children:e.slice(0,12).map(e=>{let n=e.unit??e.metricUnit,r=typeof e.value==`number`?e.value:void 0,o=t&&r!==void 0&&n&&dg(n)===dg(t)?ug(r,n,t):void 0;return(0,W.jsxs)(`tr`,{className:`border-b border-border/40`,children:[(0,W.jsx)(`td`,{className:`py-1.5 pr-4 text-muted-foreground whitespace-nowrap`,children:a(e.timestamp)}),(0,W.jsx)(`td`,{className:`py-1.5 pr-4 text-primary whitespace-nowrap`,children:e.metricKey}),(0,W.jsxs)(`td`,{className:`py-1.5 pr-4 tabular-nums`,children:[String(e.value),n?` ${n}`:``,o!==void 0&&n!==t?` → ${o.toLocaleString()} ${t}`:``]}),(0,W.jsx)(`td`,{className:`py-1.5 text-muted-foreground`,children:i(e).map(e=>(0,W.jsx)(`span`,{className:`inline-block bg-background/80 rounded px-1.5 py-0.5 mr-1 mb-0.5`,children:e},e))})]},e.id)})})]}),e.length>12&&(0,W.jsxs)(`div`,{className:`text-[11px] text-muted-foreground pt-2`,children:[`… `,e.length-12,` more points`]})]})]})}var J8=[`totalVolume`,`tis`,`sessionLoad`,`totalReps`],Y8=[`effort`,`discipline`,`intensity`,`tags`,`note`,`origin`];function X8(){let[e,t]=(0,U.useState)(J8);return(0,U.useEffect)(()=>{let e=!1;async function n(){try{let n=Date.now(),r=n-31536e6,i=await sz.getFactsByTimeRange(r,n);if(e)return;let a=new Set([...J8,...i.map(e=>e.metricKey)].filter(e=>e!==void 0));t(Array.from(a).sort())}catch{}}return n(),()=>{e=!0}},[]),{metricKeys:e,tagKeys:Y8}}var Z8=[4,8,16],Q8=`sum:totalVolume{}`;function $8(e){let t=Number.parseInt(e??``,10);return Z8.includes(t)?t:16}function e5(e={}){let{defaultQuery:t=Q8,runOnLanding:n=!1}=e,[r,i]=cn(),a=r.get(`q`)??``,o=$8(r.get(`weeks`)),[s,c]=(0,U.useState)(()=>a&&!X(a).error?a:t),[l,u]=(0,U.useState)(a||(n?t:``)),d=(0,U.useRef)(s);d.current=s;let f=(0,U.useRef)(r);f.current=r;let p=(0,U.useRef)(!0),m=(0,U.useRef)(a);m.current=a;let h=(0,U.useRef)(a);(0,U.useEffect)(()=>{a!==h.current&&(h.current=a,d.current!==a&&(p.current=!0,c(a&&!X(a).error?a:t),u(a||(n?t:``))))},[a,t,n]);let g=(0,U.useRef)(t);return(0,U.useEffect)(()=>{t!==g.current&&(g.current=t,!a&&(c(t),u(n?t:``)))},[t,a,n]),{draft:s,setDraft:(0,U.useCallback)(e=>{if(e===d.current)return;let t=new URLSearchParams(f.current);t.set(`q`,e),i(t,{replace:!p.current}),p.current=!1,c(e)},[i]),submitted:l,submit:(0,U.useCallback)(e=>{let t=e??d.current;if(X(t).error)return;if(p.current&&m.current===t){u(t);return}let n=new URLSearchParams(f.current);n.set(`q`,t),i(n,{replace:!0}),p.current=!0,u(t)},[i]),weeks:o,setWeeks:(0,U.useCallback)(e=>{let t=new URLSearchParams(f.current);t.set(`weeks`,String(e)),i(t,{replace:!0})},[i])}}function t5({weeks:e,onWeeks:t,unitForced:n,onOpenQuerySettings:r}){let[i,a]=(0,U.useState)(!1),o=(0,U.useRef)(null),{unit:s,setUnit:c}=QS();(0,U.useEffect)(()=>{if(!i)return;let e=e=>{o.current?.contains(e.target)||a(!1)},t=e=>{e.key===`Escape`&&a(!1)};return document.addEventListener(`pointerdown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`pointerdown`,e),document.removeEventListener(`keydown`,t)}},[i]);let l=e=>()=>{e(),a(!1)};return(0,W.jsxs)(`div`,{ref:o,className:`relative`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>a(e=>!e),"data-testid":`explorer-options`,"aria-expanded":i,className:G(`flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs font-semibold transition-colors`,i?`border-primary/60 text-primary bg-primary/10`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`),children:[(0,W.jsx)(vn,{className:`size-3.5`}),`Options`,(0,W.jsx)(Et,{className:G(`size-3 transition-transform`,i&&`rotate-180`)})]}),i&&(0,W.jsxs)(`div`,{className:`absolute right-0 top-full z-40 mt-1 w-72 rounded-xl border border-border bg-card shadow-xl p-1.5`,"data-testid":`explorer-options-menu`,children:[(0,W.jsx)(`div`,{className:`px-2 pt-1.5 pb-1 text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:`Range`}),Z8.map(n=>(0,W.jsxs)(`button`,{type:`button`,onClick:l(()=>t(n)),className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-foreground hover:bg-muted transition-colors`,children:[(0,W.jsx)(`span`,{className:`w-3.5 text-primary`,children:e===n?(0,W.jsx)(un,{className:`size-3.5`}):null}),`Past `,n,` weeks`]},n)),(0,W.jsxs)(`div`,{className:`mt-1 border-t border-border/60 px-2 pt-2 pb-1 text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:[`Units`,n?` — pinned by query`:``]}),[`kg`,`lb`].map(e=>(0,W.jsxs)(`button`,{type:`button`,disabled:n,onClick:l(()=>c(e)),className:G(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs transition-colors`,n?`text-muted-foreground/50 cursor-not-allowed`:`text-foreground hover:bg-muted`),children:[(0,W.jsx)(`span`,{className:`w-3.5 text-primary`,children:s===e?(0,W.jsx)(un,{className:`size-3.5`}):null}),e]},e)),r&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`mt-1 border-t border-border/60 px-2 pt-2 pb-1 text-[10px] font-black uppercase tracking-widest text-muted-foreground/70`,children:`This page`}),(0,W.jsxs)(`button`,{type:`button`,onClick:l(r),"data-testid":`explorer-query-settings`,className:`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-xs text-foreground transition-colors hover:bg-muted`,children:[(0,W.jsx)(`span`,{className:`w-3.5 text-primary`}),`Query settings`]})]})]})]})}var n5=Z,r5=`sample`,i5=6048e5;function a5(e){return Math.round(e*10)/10}var o5={thruster:`high`,"pull-up":`high`,"push-up":`moderate`,"air-squat":`moderate`,"double-under":`high`,"sit-up":`low`,rowing:`moderate`,running:`moderate`,"recovery-run":`low`,"back-squat":`high`,deadlift:`high`},s5={fran:`high`,cindy:`moderate`,annie:`moderate`,rowing:`moderate`,running:`moderate`,strength:`high`,recoveryRun:`low`};function c5(e,t,n,r){return{effortSlug:n,discipline:r,reps:e,loadLbs:t,tisSeconds:a5(e*(n===`thruster`?2.2:1.6))}}function l5(e,t,n){let r=330-n*16,i=Math.max(180,a5(r+(Math.random()-.5)*20)),a=95+n*5;return{noteId:`sample-fran-${t}-${crypto.randomUUID()}`,title:`Sample — Fran (week ${16-t})`,workoutType:`fran`,timestamp:e-t*i5,durationSeconds:i,movements:[c5(45,a,`thruster`,`strength`),c5(45,0,`pull-up`,`gymnastics`)]}}function u5(e,t,n){let r=10+n+Math.round((Math.random()-.5)*2),i=Math.max(8,r);return{noteId:`sample-cindy-${t}-${crypto.randomUUID()}`,title:`Sample — Cindy (week ${16-t})`,workoutType:`cindy`,timestamp:e-t*i5,durationSeconds:1200,movements:[{effortSlug:`pull-up`,discipline:`gymnastics`,reps:i*5,loadLbs:0,tisSeconds:a5(i*5*1.5)},{effortSlug:`push-up`,discipline:`gymnastics`,reps:i*10,loadLbs:0,tisSeconds:a5(i*10*1.2)},{effortSlug:`air-squat`,discipline:`bodyweight`,reps:i*15,loadLbs:0,tisSeconds:a5(i*15*1.1)}]}}function d5(e,t,n){let r=540-n*22,i=Math.max(360,a5(r+(Math.random()-.5)*30));return{noteId:`sample-annie-${t}-${crypto.randomUUID()}`,title:`Sample — Annie (week ${16-t})`,workoutType:`annie`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`double-under`,discipline:`gymnastics`,reps:150,loadLbs:0,tisSeconds:a5(75)},{effortSlug:`sit-up`,discipline:`bodyweight`,reps:150,loadLbs:0,tisSeconds:a5(195)}]}}function f5(e,t,n){let r=135+n*5,i=185+n*5;return{noteId:`sample-strength-${t}-${crypto.randomUUID()}`,title:`Sample — Strength accessory (week ${16-t})`,workoutType:`strength`,timestamp:e-t*i5,durationSeconds:1800,movements:[{effortSlug:`back-squat`,discipline:`strength`,reps:25,loadLbs:r,tisSeconds:a5(62.5)},{effortSlug:`deadlift`,discipline:`strength`,reps:15,loadLbs:i,tisSeconds:a5(42)}]}}function p5(e,t,n){let r=2e3+n*250,i=a5(r/2+(Math.random()-.5)*30);return{noteId:`sample-rowing-${t}-${crypto.randomUUID()}`,title:`Sample — Rowing (week ${16-t})`,workoutType:`rowing`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`rowing`,discipline:`rowing`,reps:1,loadLbs:0,tisSeconds:i,distanceMeters:r}]}}function m5(e,t,n){let r=5e3+n*500,i=a5(r/2.8+(Math.random()-.5)*60);return{noteId:`sample-running-${t}-${crypto.randomUUID()}`,title:`Sample — Running (week ${16-t})`,workoutType:`running`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`running`,discipline:`running`,reps:1,loadLbs:0,tisSeconds:i,distanceMeters:r}]}}function h5(e,t,n){let r=3e3+n*50,i=a5(r/2.2+(Math.random()-.5)*60);return{noteId:`sample-recovery-run-${t}-${crypto.randomUUID()}`,title:`Sample — Recovery run (week ${16-t})`,workoutType:`recoveryRun`,timestamp:e-t*i5,durationSeconds:i,movements:[{effortSlug:`recovery-run`,discipline:`running`,reps:1,loadLbs:0,tisSeconds:i,distanceMeters:r}]}}function g5(e){let t=[];for(let n=0;n<16;n++){let r=Math.floor(n/4);t.push(f5(e,n,n)),n%4==0?t.push(l5(e,n,r)):n%4==1?t.push(u5(e,n,r)):n%4==2?t.push(d5(e,n,r)):n===3||n===11?t.push(p5(e,n,r)):(n===7||n===15)&&t.push(m5(e,n,r)),t.push(h5(e,n,n))}return t.sort((e,t)=>e.timestamp-t.timestamp)}function _5(e){let t=e.timestamp,n=s5[e.workoutType],r=e.movements.reduce((e,t)=>e+t.reps,0),i=e.movements.reduce((e,t)=>e+t.reps*t.loadLbs,0),a=e.movements.reduce((e,t)=>e+t.tisSeconds,0),o=e.movements.reduce((e,t)=>e+(t.distanceMeters??0),0),s=a5(i/100+r+e.durationSeconds/10),c=[],l=(e,n,r,i,a)=>{let o={canonicalKey:i};a?.effortSlug&&(o.effortSlug=a.effortSlug),a?.discipline&&(o.effortDiscipline=a.discipline),a?.intensityTier&&(o.effortIntensityTier=a.intensityTier);let s={id:c.length,outputType:`analytics`,timeSpan:{started:t},metrics:[{type:q.Label,value:e,origin:`analyzed`},{type:q.Metric,value:n,unit:r,metadata:o,origin:`analyzed`}],sourceBlockKey:``,stackLevel:0};c.push(s)};if(l(`Elapsed time`,e.durationSeconds,`s`,`elapsed`,{intensityTier:n}),l(`Total reps`,r,`reps`,`totalReps`,{intensityTier:n}),l(`Time in motion`,a5(a),`s`,`tis`,{intensityTier:n}),i>0&&l(`Total volume`,a5(i),`lb`,`totalVolume`,{intensityTier:n}),o>0){let t=e.movements.find(e=>e.distanceMeters&&e.distanceMeters>0)?.discipline;l(`Total distance`,a5(o),`m`,`totalDistance`,{discipline:t,intensityTier:n})}l(`Session load`,s,`AU`,`sessionLoad`,{intensityTier:n});for(let t of e.movements){let e=t.reps*t.loadLbs,n=o5[t.effortSlug]??`moderate`,r={effortSlug:t.effortSlug,discipline:t.discipline,intensityTier:n};l(`Total reps`,t.reps,`reps`,`totalReps`,r),l(`Time in motion`,t.tisSeconds,`s`,`tis`,r),e>0&&l(`Total volume`,a5(e),`lb`,`totalVolume`,r),l(`Session load`,a5(e/100+t.reps+t.tisSeconds/10),`AU`,`sessionLoad`,r)}return c}function v5(e,t){let n=`${`sample-${e.noteId}`}-result`,r=e.timestamp,i=r+e.durationSeconds*1e3;return{id:n,noteId:e.noteId,blockId:`sample-block`,blockVersion:1,blockContentId:t,origin:`journal`,status:`completed`,createdAt:Date.now(),startTime:r,endTime:i,duration:e.durationSeconds*1e3,completed:!0}}async function y5(){return(await n5.getTagByLabel(r5))?.id}async function b5(){return(await n5.getNotesForTag(r5)).map(e=>e.id)}async function x5(){let e=await b5();return e.length!==0&&(await n5.scanAll()).some(t=>e.includes(t.noteId))}async function S5(){if(await x5()){let e=await b5();return{facts:(await n5.scanAll()).filter(t=>t.grain===`summary`&&e.includes(t.noteId)).length}}let e=g5(Date.now()),t=0;for(let n of e){let e=n.movements.map(e=>`${e.distanceMeters?`${e.distanceMeters}m`:e.reps} ${e.effortSlug.replaceAll(`-`,` `)}${e.loadLbs?` ${e.loadLbs}lb`:``}`).join(`
466
+ `),r=`# ${n.title}\n\n\`\`\`log\n${e}\n\`\`\`\n`,i=La(r,{sourceRevision:1,createId:()=>`sample-block`}),a=_5(n),o=v5(n,ba(e)),s={noteId:n.noteId,resultId:o.id,blockId:o.blockId,blockVersion:o.blockVersion,blockContentId:o.blockContentId,origin:o.origin,pageId:o.pageId,workoutTimestamp:n.timestamp};t+=await n5.withTransaction([`notes`,`block_revisions`,`block_index`,`block_efforts`,`block_equipment`,`efforts`,`equipment`,`tags`,`note_tags`,`tag_types`,`sessions`,`events`],async e=>{await e.saveNoteSource({noteId:n.noteId,rawContent:r,blocks:i,expectedSourceRevision:0,metadata:{title:n.title},noteType:`playground`,createdAt:n.timestamp}),await e.setNoteTags(n.noteId,[r5]),await e.saveSession(o),await e.appendEvents(Kg(a,s));let t=qg(a,s);return await e.finalizeSummaries(o.id,t),t.length})}return{facts:t}}async function C5(){let e=await b5();if(e.length!==0){for(let t of e)await n5.deleteEvents((await n5.getEventsForNote(t)).map(e=>e.id)),await n5.deleteNote(t);if((await n5.getNotesForTag(r5)).length===0){let e=await y5();e&&await n5.deleteTag(e)}}}function w5({result:e,onChanged:t,layout:n=`inline`,refreshKey:r}){let[i,a]=(0,U.useState)(void 0),[o,s]=(0,U.useState)(!1),c=(0,U.useCallback)(async()=>{a(await x5()),s(!1)},[]);(0,U.useEffect)(()=>{c()},[c,r]);let l=async()=>{await S5(),await c(),t?.()},u=(0,W.jsxs)(`div`,{className:`flex items-center justify-center gap-3 rounded-md border border-border bg-muted/50 px-3 py-2 text-xs text-foreground`,children:[(0,W.jsx)(`span`,{children:`Sample data loaded`}),(0,W.jsx)(`button`,{onClick:async()=>{await C5(),await c(),t?.()},className:`font-medium text-destructive hover:text-destructive/80 transition-colors`,children:`Purge sample data`}),(0,W.jsx)(`button`,{onClick:()=>s(!0),className:`text-muted-foreground hover:text-foreground transition-colors`,"aria-label":`Dismiss`,children:(0,W.jsx)(we,{size:14})})]});if(n===`banner`)return i&&!o?u:null;let d=i?o?null:u:(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mb-2`,children:`Facts appear when you log or run workouts.`}),(0,W.jsxs)(`div`,{className:`flex items-center justify-center gap-3`,children:[(0,W.jsx)(`button`,{onClick:l,className:`text-xs font-medium rounded-md bg-primary text-primary-foreground px-3 py-1.5 hover:opacity-90 transition-opacity`,children:`Preview with sample data`}),(0,W.jsx)(_n,{to:`/collections`,className:`text-xs text-primary underline-offset-2 hover:underline`,children:`Log your first workout`})]})]});return n===`card`?(0,W.jsxs)(`div`,{className:`bg-card border border-border rounded-lg p-6 flex flex-col items-center justify-center text-sm text-muted-foreground`,children:[e!==void 0&&(0,W.jsx)(sS,{result:e}),i!==void 0&&d&&(0,W.jsx)(`div`,{className:`mt-3`,children:d})]}):(0,W.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center`,children:[e!==void 0&&(0,W.jsx)(sS,{result:e}),i!==void 0&&d&&(0,W.jsx)(`div`,{className:`mt-3`,children:d})]})}var T5=`:dashboard{}`,E5=864e5,D5=`agg:metric{filters} by {dims} .rollup(period)`,O5=new Set([`tags`,`notebook`,`text`,`type`,`has`]);function k5(e){let t=e.find(e=>e.key===`source`&&!e.negate);return t?t.values.map(e=>e.value).join(`|`):null}function A5({entries:e,stickyOffset:t,idPrefix:n=``}){return(0,W.jsx)(`div`,{className:`-mx-4`,children:q4(e,`date`).map(e=>(0,W.jsxs)(`div`,{id:`${n}${e.id}`,className:`flex flex-col`,children:[(0,W.jsx)(BB,{top:t,icon:(0,W.jsx)(mn,{className:`size-3 shrink-0 text-muted-foreground`}),label:e.label,meta:(0,W.jsx)(`span`,{"data-testid":`library-group-count`,className:`font-bold tabular-nums`,children:e.entries.length})}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0 pb-1`,children:e.entries.map(e=>(0,W.jsx)(Z3,{entry:e,dateLabel:e.date?XH(e.date):void 0},e.block?`${e.id}#${e.block.blockId}`:e.id))})]},e.id))})}function j5(e,t){if(e===t)return!0;let n=X(e),r=X(t);return!n.error&&!r.error&&jh(n)===jh(r)}function M5({actions:e}){(0,U.useEffect)(()=>{},[]);let t=EF(`/dashboards`),{draft:n,setDraft:r,submitted:i,submit:a,weeks:o,setWeeks:s}=e5({defaultQuery:t.defaultWql??T5,runOnLanding:!0}),{unit:c}=QS(),{forced:l}=(0,U.useMemo)(()=>$S(i,c),[i,c]),[u,d]=(0,U.useState)(void 0),[f,p]=(0,U.useState)(void 0),[m,h]=(0,U.useState)(void 0),[g,_]=(0,U.useState)(void 0),[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(!1),[S,C]=(0,U.useState)(!1),[w,T]=(0,U.useState)(!0),E=X8(),D=t.typeOptions,O=(0,U.useMemo)(()=>X(n),[n]),k=k5(Bm(O)?O.filters:[]),A=Bm(O)&&O.window?W8(O.window):null,j=zB(104),M=!O.error&&n.trim().length>0,N=M&&w,P=(0,U.useMemo)(()=>{if(!M)return null;if(Bm(O))return n;if(Vm(O)&&O.join){let e=O.join;return jh({family:`find`,raw:``,target:e.target,filters:e.filters,window:e.last?{kind:`relative`,size:e.last.size,unit:e.last.unit}:void 0})}return null},[O,n,M]),F=(0,U.useMemo)(()=>{if(!i)return null;let e=X(i);if(Bm(e)||e.error)return null;if(e.join){let t=e.join;return jh({family:`find`,raw:``,target:t.target,filters:t.filters,window:t.last?{kind:`relative`,size:t.last.size,unit:t.last.unit}:void 0})}return jh({family:`find`,raw:``,target:`note`,filters:e.filters.filter(e=>O5.has(e.key)&&!e.negate),window:{kind:`relative`,size:o,unit:`w`}})},[i,o]);(0,U.useEffect)(()=>{if(!F){h(void 0);return}let e=!1;return Vz(F).then(t=>{e||h(t)}).catch(()=>{e||h(void 0)}),()=>{e=!0}},[F]);let[I,L]=(0,U.useState)(0),[ee,te]=(0,U.useState)(!1),[ne,R]=(0,U.useState)(!1);(0,U.useEffect)(()=>{let e=!1;if(!i){d(void 0),p(void 0),_(void 0),y(!1);return}y(!0);let t=X(i);if(Bm(t))d(void 0),t.target===`effort`?sz.runFind(t).then(t=>{e||(_(t.efforts??[]),p([]))}).catch(()=>{e||(_(void 0),p(void 0))}).finally(()=>{e||y(!1)}):Vz(i).then(t=>{e||(p(t),_([]))}).catch(()=>{e||(p(void 0),_(void 0))}).finally(()=>{e||y(!1)});else{p(void 0),_(void 0);let t=Date.now(),n=t-o*7*E5;sz.runQuery(i,{rangeStart:n,rangeEnd:t,preferredUnit:c}).then(t=>{e||d(t)}).catch(()=>{e||d(void 0)}).finally(()=>{e||y(!1)})}return()=>{e=!0}},[i,o,I,c]);let re=oS(u),ie=e=>{let t=V3(n,e);r(t),a(t)},{setL3Items:ae}=WM(),oe=(0,U.useMemo)(()=>f!==void 0&&f.length>0?q4(f,`date`):[],[f]);(0,U.useEffect)(()=>{if(oe.length===0){ae([]);return}let e=oe.map(e=>({id:e.id,label:e.label,level:3,action:{type:`scroll`,sectionId:e.id}}));return ae(e),()=>ae([])},[oe,ae]);let se=EP.find(e=>e.query===i)?.question??`custom query`,ce=(0,U.useMemo)(()=>{let e=X(i);return e.error?i:jh(e)},[i]),le=u!==void 0&&(j5(u.parsed.raw,n)||u.parsed.raw===i&&n===ce),z=!i||!v&&re.kind===`empty`,ue=(0,W.jsxs)(`button`,{type:`button`,"data-testid":`inspect-pipeline`,"aria-expanded":ee,onClick:()=>te(e=>!e),className:`flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-semibold text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[ee?(0,W.jsx)(Et,{size:12}):(0,W.jsx)(wn,{size:12}),`Inspect pipeline`]});return(0,W.jsxs)(`div`,{className:`bg-card flex flex-col flex-1`,children:[(0,W.jsx)(B8,{catalog:H8}),(0,W.jsx)(u3,{surface:X4,open:S,onOpenChange:C}),(0,W.jsx)(NB,{title:`Metric Explorer`,actions:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(t5,{weeks:o,onWeeks:s,unitForced:l,onOpenQuerySettings:()=>C(!0)}),e]})}),(0,W.jsxs)(`div`,{className:`flex flex-col min-h-0 p-4`,children:[(0,W.jsx)(`div`,{className:`min-w-[280px]`,children:(0,W.jsx)(Kw,{query:n,onQueryChange:r,onValidationChange:e=>T(e.valid),onSubmit:e=>a(e),actionLabel:`Run`,preferredChoices:D,showDiagnostics:!1,placeholder:D5,diagnosticsActions:(0,W.jsxs)(`button`,{type:`button`,"data-testid":`save-query`,disabled:!N,onClick:()=>x(!0),title:`Save this query — decide where it lands (dashboard, …)`,className:`flex min-h-12 items-center gap-1.5 rounded-lg border border-primary/40 text-primary px-3 text-[11px] font-semibold hover:bg-primary/10 transition-all shrink-0 disabled:opacity-40 disabled:hover:bg-transparent`,children:[(0,W.jsx)(ln,{size:12}),` Save`]})})}),(0,W.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-1.5 gap-y-1`,"data-testid":`explorer-meta`,children:[n.trim().length>0&&(0,W.jsx)(`span`,{"data-testid":`draft-validity`,className:`mr-1 inline-flex items-center gap-1 text-[11px]`,children:O.error?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-mono text-red-600`,children:[(0,W.jsx)(Qt,{size:11,className:`shrink-0`}),` `,O.error]}):(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-1 text-green-600`,children:[(0,W.jsx)(yn,{size:11,className:`shrink-0`}),` valid`]})}),E.metricKeys.map(e=>(0,W.jsx)(`button`,{type:`button`,disabled:!N||!Vm(O),title:M&&!Vm(O)?`Metric shortcuts apply to measure queries — pivot the kind through the composer first`:void 0,onClick:()=>ie(e),className:G(`rounded-full border px-2 py-0.5 text-[11px] font-mono transition-colors disabled:opacity-40 disabled:hover:bg-transparent`,n.includes(e)?`border-primary/60 bg-primary/10 text-primary`:`border-border text-muted-foreground hover:text-foreground hover:bg-muted`),children:e},e)),(0,W.jsx)(`span`,{className:`mx-1 text-[10px] font-bold uppercase tracking-widest text-muted-foreground/50`,children:`filters`}),E.tagKeys.map(e=>(0,W.jsx)(`span`,{className:`rounded-full border border-border/60 px-2 py-0.5 text-[11px] font-mono text-muted-foreground/70`,children:e},e))]}),(0,W.jsx)(`section`,{className:`min-w-0`,children:Bm(O)?(0,W.jsx)(`div`,{className:`mt-3`,children:(0,W.jsxs)(`div`,{className:`bg-card border border-border rounded-lg p-4`,children:[(0,W.jsxs)(`div`,{className:`text-[11px] uppercase tracking-wider text-muted-foreground mb-2`,children:[`Find `,O.target,k&&(0,W.jsxs)(`span`,{className:`ml-1`,children:[`in `,k]}),A&&(0,W.jsx)(`span`,{className:`ml-1`,children:A})]}),O.error?(0,W.jsx)(`div`,{className:`text-sm text-destructive font-mono`,children:O.error}):v?(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Searching…`}):g&&g.length>0?(0,W.jsx)(`div`,{className:`flex flex-col divide-y divide-border/50`,children:g.map(e=>(0,W.jsxs)(`div`,{className:`flex items-center gap-3 py-2.5`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-foreground`,children:e.label}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground font-mono`,children:e.slug}),e.baseAttributes.discipline&&(0,W.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-muted-foreground`,children:e.baseAttributes.discipline})]},e.slug))}):f&&f.length>0?(0,W.jsx)(A5,{entries:f,stickyOffset:j}):(0,W.jsxs)(`div`,{className:`text-sm text-muted-foreground`,children:[`No `,O.target,`s found.`]})]})}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`mt-3`,children:(0,W.jsx)(w5,{layout:`banner`,refreshKey:I,onChanged:()=>L(e=>e+1)})}),O.error&&i&&(0,W.jsx)(`div`,{"data-testid":`explorer-results-stale`,className:`mt-3 rounded-lg border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs font-medium text-amber-700`,children:`Stale — showing the last run's results; the current draft is invalid and not applied.`}),(0,W.jsx)(`div`,{className:`mt-3`,children:(0,W.jsx)(rS,{title:`Query result`,question:se,query:i||`(empty)`,children:(0,W.jsx)(`div`,{className:`h-64`,children:i?v?(0,W.jsx)(sS,{result:void 0}):re.kind===`error`?(0,W.jsx)(`div`,{className:`h-full flex items-center justify-center text-sm text-destructive font-mono px-4 text-center`,children:re.message}):re.kind===`empty`?(0,W.jsxs)(`div`,{className:`h-full flex flex-wrap items-center justify-center gap-6`,children:[(0,W.jsx)(w5,{result:u,refreshKey:I,onChanged:()=>L(e=>e+1)}),ue]}):re.kind===`scalar`?(0,W.jsx)(cS,{result:u,label:`${u.parsed.agg}(${u.parsed.metric})`}):re.kind===`timeseries`?(0,W.jsx)(hS,{result:u}):(0,W.jsx)(gS,{result:u}):(0,W.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-3`,children:[(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Enter a WQL query or choose an example to explore your data.`}),ue]})})})}),i&&(0,W.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[!v&&!z&&ue,F&&m!==void 0&&(0,W.jsxs)(`button`,{type:`button`,"data-testid":`records-toggle`,"aria-expanded":ne,onClick:()=>R(e=>!e),className:`flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-xs font-semibold text-muted-foreground hover:text-foreground hover:bg-muted transition-colors`,children:[ne?(0,W.jsx)(Et,{size:12}):(0,W.jsx)(wn,{size:12}),`Records in this calculation`,(0,W.jsx)(`span`,{className:`text-[10px] font-bold text-muted-foreground/60 tabular-nums`,children:m.length})]})]}),ee&&(0,W.jsx)(`div`,{className:`mt-3`,"data-testid":`pipeline-anatomy`,children:i?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(G8,{parsed:le?u.parsed:O}),le&&(0,W.jsx)(K8,{result:u})]}):(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`Submit a query to see its anatomy.`})}),ne&&F&&m!==void 0&&(0,W.jsxs)(`div`,{className:`mt-3`,children:[(0,W.jsx)(`code`,{className:`block mb-3 rounded-md border border-border bg-muted/40 px-3 py-2 font-mono text-xs text-foreground`,"data-testid":`records-wql`,children:F}),m.length===0?(0,W.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:`No records match this calculation.`}):(0,W.jsx)(A5,{entries:m,stickyOffset:j,idPrefix:`records-`})]}),u&&(0,W.jsx)(q8,{matched:u.matched,displayUnit:u.unit})]})})]}),(0,W.jsx)(R8,{open:b,onOpenChange:x,initialQuery:n,subsetQuery:P,rangeStart:Date.now()-o*7*E5,rangeEnd:Date.now(),preferredUnit:c})]})}var N5=2.20462,P5=2.54,F5=`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`;function I5(e){if(!e)return;let t=new Date(e);if(Number.isNaN(t.getTime()))return;let n=new Date,r=n.getFullYear()-t.getFullYear(),i=n.getMonth()-t.getMonth();return(i<0||i===0&&n.getDate()<t.getDate())&&r--,r}function L5(e){let t=(e??``).trim().split(/\s+/).filter(Boolean);return t.length===0?`?`:t.slice(0,2).map(e=>e[0].toUpperCase()).join(``)}function R5({unit:e,other:t,onSwitch:n}){return(0,W.jsx)(`div`,{className:`flex rounded-md border border-input overflow-hidden shrink-0`,role:`group`,children:[e,t].map((e,t)=>(0,W.jsx)(`button`,{type:`button`,"aria-pressed":t===0,onClick:t===1?n:void 0,className:G(`px-2.5 h-9 text-xs font-medium transition-colors`,t===0?`bg-primary/10 text-primary`:`bg-background text-muted-foreground hover:bg-muted`),children:e},e))})}function z5(){let[e,t]=(0,U.useState)(null),[n,r]=(0,U.useState)({displayName:``,birthDate:``,weight:``,height:``}),i=(0,U.useRef)(null);(0,U.useEffect)(()=>{let e=!0;return Ok.current().then(n=>{e&&t(n)}).catch(console.error),()=>{e=!1}},[]),(0,U.useEffect)(()=>{e&&r({displayName:e.displayName?.trim()||`Anonymous`,birthDate:e.birthDate??``,weight:e.weight==null?``:String(e.weight),height:e.height==null?``:String(e.height)})},[e?.id]);let a=(0,U.useCallback)(async e=>{try{t(await Ok.update(e))}catch(e){console.error(e)}},[]),o=(0,U.useCallback)(async e=>{if(e)try{await a({picture:await wx(e)})}catch(e){console.error(e)}},[a]);if(!e)return(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,"data-testid":`profile-loading`,children:`Loading profile…`});let s=I5(e.birthDate),c=e.weightUnit??`kg`,l=e.heightUnit??`cm`;return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Me,{className:`size-4 text-primary`}),`Profile Picture`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Click the picture to choose an image — it is center-cropped and stored locally.`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>i.current?.click(),"aria-label":`Change profile picture`,"data-testid":`profile-avatar`,className:`relative group size-20 rounded-full overflow-hidden border border-border bg-muted shrink-0 cursor-pointer`,children:[e.picture?(0,W.jsx)(`img`,{src:e.picture,alt:``,className:`size-full object-cover`}):(0,W.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center text-lg font-semibold text-muted-foreground`,children:L5(e.displayName)}),(0,W.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center bg-black/45 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 transition-opacity`,children:(0,W.jsx)(kn,{className:`size-5 text-white`})})]}),(0,W.jsx)(`input`,{ref:i,type:`file`,accept:`image/*`,className:`hidden`,"aria-hidden":`true`,tabIndex:-1,onChange:e=>{o(e.target.files?.[0]),e.target.value=``}})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Details`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Used by journal analytics (age from birth date, metric conversions). Changes are saved immediately.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`profile-display-name`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Display Name`}),(0,W.jsx)(`input`,{id:`profile-display-name`,"data-testid":`profile-display-name`,className:F5,placeholder:`Anonymous`,value:n.displayName,onChange:e=>{r(t=>({...t,displayName:e.target.value})),a({displayName:e.target.value})}})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`label`,{htmlFor:`profile-birth-date`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:[`Birth Date`,s===void 0?``:` · Age ${s}`]}),(0,W.jsx)(`input`,{id:`profile-birth-date`,"data-testid":`profile-birth-date`,type:`date`,className:F5,value:n.birthDate,onChange:e=>{r(t=>({...t,birthDate:e.target.value})),a({birthDate:e.target.value||void 0})}})]}),(0,W.jsx)(`div`,{})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`profile-weight`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Weight`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(`input`,{id:`profile-weight`,"data-testid":`profile-weight`,type:`number`,inputMode:`decimal`,min:`0`,className:F5,placeholder:c===`kg`?`e.g. 75`:`e.g. 165`,value:n.weight,onChange:e=>{let t=e.target.value;r(e=>({...e,weight:t})),t===``?a({weight:void 0}):Number.isFinite(Number(t))&&a({weight:Number(t)})}}),(0,W.jsx)(R5,{unit:c,other:c===`kg`?`lb`:`kg`,onSwitch:()=>void a({weightUnit:c===`kg`?`lb`:`kg`,weight:e.weight==null?void 0:c===`kg`?e.weight*N5:e.weight/N5})})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{htmlFor:`profile-height`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Height`}),(0,W.jsxs)(`div`,{className:`flex gap-2`,children:[(0,W.jsx)(`input`,{id:`profile-height`,"data-testid":`profile-height`,type:`number`,inputMode:`decimal`,min:`0`,className:F5,placeholder:l===`cm`?`e.g. 180`:`e.g. 71`,value:n.height,onChange:e=>{let t=e.target.value;r(e=>({...e,height:t})),t===``?a({height:void 0}):Number.isFinite(Number(t))&&a({height:Number(t)})}}),(0,W.jsx)(R5,{unit:l,other:l===`cm`?`in`:`cm`,onSwitch:()=>void a({heightUnit:l===`cm`?`in`:`cm`,height:e.height==null?void 0:l===`cm`?e.height/P5:e.height*P5})})]})]})]})]})]})]})}function B5(e){let t;try{t=JSON.parse(e)}catch{return{ok:!1,error:`The pairing file is not valid JSON.`}}if(!t||typeof t!=`object`||Array.isArray(t))return{ok:!1,error:`The pairing file has an unexpected shape.`};let n=t;if(n.wodWikiPairing!==1)return{ok:!1,error:`Not a wod.wiki database pairing file (missing "wodWikiPairing": 1).`};if(n.kind!==`turso`)return{ok:!1,error:`Unsupported pairing kind "${String(n.kind)}" — only Turso databases can be paired here.`};let{url:r,authToken:i}=n;return typeof r!=`string`||!r.trim()||typeof i!=`string`||!i.trim()?{ok:!1,error:`The pairing file is missing the database URL or auth token.`}:{ok:!0,pairing:{url:r,authToken:i,database:typeof n.database==`string`&&n.database.trim()?n.database:void 0,schemaVersion:typeof n.schemaVersion==`number`&&Number.isSafeInteger(n.schemaVersion)?n.schemaVersion:void 0,createdAt:typeof n.createdAt==`string`?n.createdAt:void 0}}}async function V5(e){let t=hk(e.url,e.authToken);if(t)return{state:`unreachable`,reason:t};let n;try{n=Hx(g({url:e.url.trim(),authToken:e.authToken}))}catch(t){return{state:`unreachable`,reason:gk(t,e.authToken).message}}try{let e=await jb(n);return e===`empty`?{state:`empty`,reason:`The database is empty — nothing to restore. Use Enable Sync to back up to it instead.`}:e.kind===`unknown`?{state:`unknown`,reason:`The database contains foreign tables — refusing to touch it.`}:e.kind===`legacy`||e.schemaVersion<32?{state:`older`,schemaVersion:e.schemaVersion,reason:`The database uses schema v${e.schemaVersion}, this app needs v32. Migrate it with the CLI to a fresh target, then pair that target.`}:e.schemaVersion>32?{state:`newer`,schemaVersion:e.schemaVersion,reason:`The database uses schema v${e.schemaVersion}, newer than this app supports (v32). Update the app first.`}:{state:`current`,schemaVersion:e.schemaVersion,rev:e.rev}}catch(t){return{state:`unreachable`,reason:gk(t,e.authToken).message}}finally{await n.close().catch(()=>void 0)}}var H5=[`wodwiki.seedSources`,`wodwiki.seedSources.hidden`,`wodwiki.seedSubscriptions`,`wodwiki.seedAutoSync`];function U5(e){if(typeof e!=`string`)return!1;try{let t=new URL(e);return(t.protocol===`http:`||t.protocol===`https:`)&&!t.username&&!t.password&&!t.search&&!t.hash}catch{return!1}}function W5(){let e=[];for(let t of H5){let n=null;try{n=localStorage.getItem(t)}catch{n=null}if(n!==null)try{let r=JSON.parse(n);if(t===`wodwiki.seedSources`){let n=(Array.isArray(r)?r:[]).flatMap(e=>{if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e;if(typeof t.id!=`string`||typeof t.label!=`string`||!U5(t.url))return[];let n={id:t.id,label:t.label,url:t.url};return typeof t.repositoryUrl==`string`&&U5(t.repositoryUrl)&&(n.repositoryUrl=t.repositoryUrl),[n]});e.push({key:t,value:n})}else if(t===`wodwiki.seedSources.hidden`)e.push({key:t,value:Array.isArray(r)?r.filter(e=>typeof e==`string`):[]});else{let n=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).filter(([,e])=>typeof e==`boolean`):[];e.push({key:t,value:Object.fromEntries(n)})}}catch{}}return e}function G5(e){let t=(e,t)=>JSON.parse(hb(t,e===`attachments`?`data`:void 0));return JSON.stringify({format:`wod-wiki-safe-export`,version:1,...e,rows:e.rows.map(({store:e,rows:n})=>({store:e,rows:n.map(n=>t(e,n))})),pendingGroups:e.pendingGroups.map(e=>({...e,ops:e.ops.map(e=>e&&typeof e==`object`&&`op`in e&&e.op===`put`&&`store`in e&&typeof e.store==`string`&&`value`in e?{...e,value:t(e.store,e.value)}:e)}))},null,2)}async function K5(){let[e,t]=await Promise.all([Bk(),Vk()]),n=G5({pendingGroups:e.map(e=>({id:e.id,at:e.at,ops:e.ops})),rows:t,contentSources:W5(),exportedAt:new Date().toISOString()}),r=`wodwiki-safe-export-${new Date().toISOString().slice(0,10)}.json`,i=URL.createObjectURL(new Blob([n],{type:`application/json`})),a=document.createElement(`a`);return a.href=i,a.download=r,a.click(),setTimeout(()=>URL.revokeObjectURL(i),1e3),r}async function q5(){let e=await zk();try{return await K5()}finally{e&&Rk()}}function J5(e){let t=globalThis.indexedDB;if(!t)return Promise.resolve();let{promise:n,resolve:r}=Promise.withResolvers(),i=t.deleteDatabase(e);return i.onsuccess=()=>r(),i.onerror=()=>r(),i.onblocked=()=>r(),n}async function Y5(e,t){let n=vk();if(n.state===`turso`&&fk(n.url,e.url))throw Error(`This database is already the active sync target. Restore needs the URL of a different database.`);t?.(`Checking the target database…`);let r=await V5(e);if(r.state!==`current`)throw Error(r.reason);t?.(`Pausing background sync…`);let i=await zk(),a=`wodwiki-restore-${crypto.randomUUID().slice(0,8)}`,o=new nx({dbName:a}),s=new lk(o,{url:e.url.trim(),authToken:e.authToken});try{t?.(`Exporting your current data and unsent edits…`),await K5(),t?.(`Replaying the remote database into an isolated local copy…`),await s.restoreNow(),await s.stop(),await o.close(),t?.(`Saving the restored database as your data…`),Ck(a)}catch(t){throw await s.stop().catch(()=>void 0),await o.close().catch(()=>void 0),await J5(a),i&&Rk(),gk(t,e.authToken)}return{localDbName:a}}function X5({idPrefix:e,onPair:t}){let[n,r]=(0,U.useState)(null),i=async e=>{if(!e?.length)return;let n=B5(await e[0].text());n.ok?(r(null),t(n.pairing)):r(n.error)};return(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsxs)(`label`,{htmlFor:`${e}-pairing`,className:`block text-xs font-medium text-muted-foreground`,children:[`Pair from provisioning file (from `,(0,W.jsx)(`code`,{className:`font-mono`,children:`wod db`}),`)`]}),(0,W.jsx)(`input`,{id:`${e}-pairing`,type:`file`,accept:`application/json,.json`,onChange:e=>void i(e.target.files),"data-testid":`${e}-pairing-input`,className:`block w-full text-xs text-muted-foreground file:mr-2 file:cursor-pointer file:rounded-md file:border-0 file:bg-muted file:px-2 file:py-1 file:text-xs file:font-medium`}),n&&(0,W.jsx)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`${e}-pairing-error`,children:n})]})}function Z5({saved:e,onConnected:t}){let[n,r]=(0,U.useState)(e?.url??``),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(null),[f,p]=(0,U.useState)(null),h=t??(typeof window<`u`?()=>window.location.reload():void 0),g=()=>{let t=n.trim();return t?i.trim()?i.trim():e&&t===e.url&&e.authToken?e.authToken:(d(e?.authToken?`The URL differs from the saved connection — enter the auth token for this database.`:`An auth token is required.`),null):(d(`A database URL is required.`),null)};return(0,W.jsxs)(`div`,{className:`space-y-3`,"data-testid":`turso-connect-form`,children:[(0,W.jsx)(X5,{idPrefix:`turso`,onPair:e=>{r(e.url),a(e.authToken),d(null),p(null),s([e.database,e.schemaVersion===void 0?void 0:`file schema v${e.schemaVersion}`].filter(Boolean).join(` · `)||null)}}),o&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`turso-pairing-label`,children:[`Provisioned database: `,(0,W.jsx)(`span`,{className:`font-mono`,children:o}),` — verify with Test Connection, then Enable Sync. The live database is checked again before anything is saved.`]}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`turso-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Database URL`}),(0,W.jsx)(`input`,{id:`turso-url`,type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:`libsql://your-db.turso.io`,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:n,onChange:e=>r(e.target.value),disabled:c!==null})]}),(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`turso-token`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Auth token`}),(0,W.jsx)(`input`,{id:`turso-token`,type:`password`,autoComplete:`off`,placeholder:e?`•••••••• (saved token — reused only for the same URL)`:``,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:i,onChange:e=>a(e.target.value),disabled:c!==null})]})]}),(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-muted-foreground leading-relaxed`,"data-testid":`turso-token-warning`,children:[(0,W.jsx)(m,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:`The token is saved in this browser's localStorage, so any code on this site can read it. Use a token scoped to this one database, and never a token with write access elsewhere.`})]}),u&&(0,W.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`turso-connect-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:u})]}),f&&(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs text-emerald-600`,"data-testid":`turso-test-ok`,children:[(0,W.jsx)(yn,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:f})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:async()=>{let e=g();if(e){l(`test`),d(null),p(null);try{await Sk({url:n.trim(),authToken:e}),p(`Connection verified — the database is reachable and writable. Nothing was saved.`)}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(null)}}},disabled:c!==null,"data-testid":`turso-test-button`,className:`gap-2`,children:[c===`test`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(Tt,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:c===`test`?`Testing…`:`Test Connection`})]}),(0,W.jsxs)(K,{size:`sm`,onClick:async()=>{let e=g();if(e){l(`connect`),d(null),p(null);try{await xk({url:n.trim(),authToken:e}),Q({title:`Turso Sync enabled`,description:`Reloading… Your local data will sync in the background.`}),h?.()}catch(e){d(e instanceof Error?e.message:String(e)),l(null)}}},disabled:c!==null,"data-testid":`turso-connect-button`,className:`gap-2`,children:[c===`connect`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(un,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:c===`connect`?`Enabling…`:e?`Update Connection`:`Enable Sync`})]}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Sync merges and backs up your local data in the background. Your local copy stays the one you edit.`})]})]})}function Q5({status:e}){let t={current:{label:`Compatible`,className:`text-emerald-600`},older:{label:`Older schema`,className:`text-amber-600`},newer:{label:`Newer schema`,className:`text-destructive`},empty:{label:`Empty database`,className:`text-amber-600`},unknown:{label:`Foreign database`,className:`text-destructive`},unreachable:{label:`Unreachable`,className:`text-destructive`}}[e.state],n=e.state===`current`?`Canonical schema v${e.schemaVersion}, up to date at rev ${e.rev}.`:e.reason;return(0,W.jsxs)(`p`,{className:`flex items-start gap-1.5 text-xs leading-relaxed`,"data-testid":`restore-status-${e.state}`,children:[e.state===`current`?(0,W.jsx)(yn,{className:`size-3.5 mt-0.5 shrink-0 text-emerald-600`}):(0,W.jsx)(Qt,{className:G(`size-3.5 mt-0.5 shrink-0`,t.className)}),(0,W.jsxs)(`span`,{className:t.className,children:[(0,W.jsxs)(`span`,{className:`font-semibold`,children:[t.label,`.`]}),` `,(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:n})]})]})}function $5(){let[e,t]=(0,U.useState)(``),[n,r]=(0,U.useState)(``),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),[c,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(null),[g,_]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!0;return Bk().then(t=>{e&&_(t.length)}).catch(()=>void 0),()=>{e=!1}},[]);let v=e.trim()!==``&&n.trim()!==``,y=async()=>{h(`probe`),p(null),a(null);try{a(await V5({url:e.trim(),authToken:n}))}finally{h(null)}},b=async()=>{h(`export`),p(null);try{let e=await q5();l(`Exported ${e} — unsent edits, a full local snapshot, and content-source settings. No tokens included.`);let t=await Bk();_(t.length)}catch(e){p(e instanceof Error?e.message:String(e))}finally{h(null)}},x=async()=>{h(`restore`),d(!1),p(null);try{await Y5({url:e.trim(),authToken:n},s),Q({title:`Restore complete`,description:`The restored database is now your data. Reloading…`}),setTimeout(()=>window.location.reload(),600)}catch(e){p(e instanceof Error?e.message:String(e)),s(null),h(null)}};return(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 sm:p-5 space-y-4`,"data-testid":`restore-section`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg bg-muted text-foreground shrink-0`,children:(0,W.jsx)(C,{className:`size-5`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Restore from a backup database`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:[`Point this at a different, already-provisioned database (for example one retained by`,` `,(0,W.jsx)(`code`,{className:`font-mono`,children:`wod db backup`}),`) to replace this browser's data with its contents. The remote database is never modified, and your current data is kept in a separate local database that stays on disk.`]})]})]}),(0,W.jsx)(X5,{idPrefix:`restore`,onPair:e=>{t(e.url),r(e.authToken),a(null),p(null),l(null)}}),(0,W.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`restore-url`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Backup database URL`}),(0,W.jsx)(`input`,{id:`restore-url`,type:`text`,autoComplete:`off`,spellCheck:!1,placeholder:`libsql://your-restore-target.turso.io`,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:e,onChange:e=>{t(e.target.value),a(null)},disabled:m!==null})]}),(0,W.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,W.jsx)(`label`,{htmlFor:`restore-token`,className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Auth token`}),(0,W.jsx)(`input`,{id:`restore-token`,type:`password`,autoComplete:`off`,placeholder:`Database-scoped token for the backup database`,className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,value:n,onChange:e=>{r(e.target.value),a(null)},disabled:m!==null})]})]}),f&&(0,W.jsxs)(`p`,{role:`alert`,className:`flex items-start gap-1.5 text-xs text-destructive`,"data-testid":`restore-error`,children:[(0,W.jsx)(Qt,{className:`size-3.5 mt-0.5 shrink-0`}),(0,W.jsx)(`span`,{children:f})]}),i&&(0,W.jsx)(Q5,{status:i}),o&&(0,W.jsx)(`p`,{"aria-live":`polite`,className:`text-xs text-muted-foreground`,"data-testid":`restore-phase`,children:o}),c&&(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,"data-testid":`restore-export-note`,children:c}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void y(),disabled:!v||m!==null,"data-testid":`restore-check-button`,className:`gap-2`,children:[m===`probe`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(Tt,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:m===`probe`?`Checking…`:`Check database`})]}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>void b(),disabled:m!==null,"data-testid":`restore-export-button`,className:`gap-2`,children:[m===`export`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(Mn,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:g===null||g===0?`Export data (safe file)`:`Export data — ${g} unsent ${g===1?`edit`:`edits`}`})]}),u?(0,W.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground max-w-72`,children:`Your current data is exported and kept locally. The restored copy opens with sync disabled so the archive stays unchanged.`}),(0,W.jsxs)(K,{variant:`destructive`,size:`sm`,autoFocus:!0,onClick:()=>void x(),disabled:m!==null,"data-testid":`restore-confirm-button`,children:[m===`restore`?(0,W.jsx)(zt,{className:`size-3.5 animate-spin`}):(0,W.jsx)(un,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:m===`restore`?`Restoring…`:`Confirm restore`})]}),(0,W.jsx)(K,{variant:`ghost`,size:`sm`,onClick:()=>d(!1),disabled:m!==null,"data-testid":`restore-cancel-button`,children:`Cancel`})]}):(0,W.jsxs)(K,{variant:`destructive`,size:`sm`,onClick:()=>{d(!0),p(null)},disabled:!v||m!==null,"data-testid":`restore-button`,className:`gap-2`,children:[(0,W.jsx)(C,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Restore this database…`})]})]})]})}function e7(){let[e]=(0,U.useState)(vk),t=e?.state===`turso`,n=Dk===`api`;return(0,W.jsx)(`div`,{className:`space-y-8`,children:(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Storage`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Notes, results, workouts, and queries stay in this browser. Optional Turso Sync backs up your data and syncs other browsers in the background.`})]}),n?(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,"data-testid":`storage-option-api`,children:`This deployment stores data on its server; storage is managed by the deployment.`}):(0,W.jsxs)(W.Fragment,{children:[e?.state===`invalid`&&(0,W.jsxs)(`div`,{role:`alert`,className:`rounded-xl border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive flex items-start gap-2`,"data-testid":`data-settings-invalid-banner`,children:[(0,W.jsx)(Qt,{className:`size-4 mt-0.5 shrink-0`}),(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(`div`,{className:`font-semibold`,children:`Turso Sync settings are invalid; sync is off`}),(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[e.error,` Fix the connection below or turn off Turso Sync to keep working from your local copy. Neither copy was deleted.`]}),(0,W.jsx)(K,{variant:`outline`,size:`sm`,onClick:()=>{wk(),window.location.reload()},"data-testid":`data-settings-invalid-disable`,className:`mt-1`,children:`Turn off Turso Sync`})]})]}),(0,W.jsxs)(`div`,{"data-testid":`storage-option-browser`,className:`rounded-xl border border-primary ring-2 ring-primary/20 bg-primary/5 p-4 sm:p-5 space-y-4 text-left`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`div`,{className:`p-2 rounded-lg bg-primary text-primary-foreground shrink-0`,children:(0,W.jsx)(re,{className:`size-5`})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`font-semibold text-foreground text-sm`,children:`This Browser`}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:`Private local storage (IndexedDB). Everything is stored in this browser and reads and writes are local — Turso Sync, when enabled, backs it up to your database in the background.`})]})]}),(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-primary text-primary-foreground shrink-0`,children:`Always on`})]}),(0,W.jsx)(`div`,{"aria-hidden":`true`,className:`border-t border-border`}),(0,W.jsxs)(`div`,{"data-testid":`storage-option-turso`,className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-sm font-semibold text-foreground`,children:`Turso Sync`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground mt-0.5 leading-relaxed font-mono break-all`,children:e?.state===`turso`?`Backing up to ${e.url} in the background.`:`Off — fill out the form below to back up your local data to your own Turso database in the background.`})]}),(0,W.jsx)(`span`,{className:G(`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded shrink-0`,t?`bg-primary text-primary-foreground`:`bg-muted text-muted-foreground`),children:t?`Sync on`:`Sync off`})]}),t&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 rounded-md border border-border bg-muted/30 p-3`,children:[(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:()=>{t&&(wk(),window.location.reload())},"data-testid":`turso-sync-disable`,className:`gap-2`,children:[(0,W.jsx)(st,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Turn off Turso Sync`})]}),(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Turning off sync keeps everything in this browser. Nothing is deleted from your Turso database.`})]}),(0,W.jsx)(Z5,{saved:e?.state===`turso`?{url:e.url,authToken:e.authToken}:void 0})]})]}),(0,W.jsx)($5,{}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 text-sm text-muted-foreground`,"data-testid":`storage-option-self-hosted`,children:[(0,W.jsx)(Hn,{className:`mb-2 size-5`,"aria-hidden":`true`}),(0,W.jsx)(`p`,{className:`font-medium text-foreground`,children:`API server mode`}),(0,W.jsx)(`p`,{className:`mt-1 text-xs`,children:`Run the API deployment with your local or cloud-hosted database. This browser build uses IndexedDB; API deployments run storage and queries on their server.`})]})]})]})})}function t7(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,`-`).replace(/^-+|-+$/g,``)}var n7=`:00, -:03, :05:00`;function r7(){(0,U.useSyncExternalStore)(jJ,MJ);let e=SJ(),[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(null),[s,c]=(0,U.useState)(null),[l,u]=(0,U.useState)(``),d=async e=>{i(null);let t=await TJ(e);return t||i(`Could not save — storage rejected the write; your change was not kept.`),t},f=async r=>{r.preventDefault();let a=t.trim();if(!a){i(`Profile name is required`);return}let o=t7(a);if(!o){i(`Profile name needs at least one letter or number`);return}if(e.some(e=>e.id===o)){i(`A profile with id "${o}" already exists`);return}await d(e=>[...e,{id:o,name:a,rules:[]}])&&(n(``),await EJ(o,Z),await Pj())},p=async e=>{let t=l.trim();c(null),!(!t||t===e.name)&&await d(n=>n.map(n=>n.id===e.id?{...n,name:t}:n))},m=async e=>{o(null),await d(t=>t.filter(t=>t.id!==e.id)),await DJ(e.id,Z),await Pj()},h=(e,t)=>d(n=>n.map(n=>n.id===e.id?{...n,rules:[...n.rules,t]}:n)),g=(e,t,n)=>d(r=>r.map(r=>r.id===e.id?{...r,rules:r.rules.map((e,r)=>r===t?n:e)}:r)),_=(e,t)=>d(n=>n.map(n=>n.id===e.id?{...n,rules:n.rules.filter((e,n)=>n!==t)}:n));return(0,W.jsx)(`div`,{className:`space-y-8`,children:(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Sound Profiles`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`A profile is a named set of sound rules. Each rule fires a sound at a trigger point relative to a block's own duration: `,(0,W.jsx)(`code`,{className:`font-mono`,children:`:00`}),` starts it,`,` `,(0,W.jsx)(`code`,{className:`font-mono`,children:`-:00`}),` ends it, `,(0,W.jsx)(`code`,{className:`font-mono`,children:`-:03`}),` `,`is three seconds before the end, `,(0,W.jsx)(`code`,{className:`font-mono`,children:`:05:00`}),` is five minutes elapsed. Tag a note`,` `,(0,W.jsx)(`code`,{className:`font-mono`,children:bJ(`classic`)}),` to apply that profile to the whole note;`,` `,(0,W.jsxs)(`code`,{className:`font-mono`,children:[`sound: `,`#sound-classic`]}),` on a line applies it to that block only.`]})]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-4`,children:[(0,W.jsxs)(`form`,{onSubmit:f,className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[200px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Profile Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`,placeholder:`New profile (e.g. Classic beeps)`,value:t,onChange:e=>n(e.target.value)})]}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,className:`h-9`,children:[(0,W.jsx)(On,{className:`size-3.5 mr-1`}),` Add Profile`]})]}),r&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:r}),e.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No sound profiles created yet.`}):(0,W.jsx)(`div`,{className:`space-y-3`,children:e.map(e=>(0,W.jsxs)(`div`,{className:`p-3 rounded-lg border border-border/70 bg-background/50 space-y-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[s===e.id?(0,W.jsx)(`input`,{autoFocus:!0,"aria-label":`Rename profile ${e.name}`,className:`h-7 max-w-[220px] rounded border border-primary bg-background px-2 font-mono text-xs outline-none`,value:l,onChange:e=>u(e.target.value),onKeyDown:t=>{t.key===`Enter`?p(e):t.key===`Escape`&&c(null)},onBlur:()=>void p(e)}):(0,W.jsx)(`button`,{type:`button`,className:`font-semibold text-sm text-foreground hover:underline text-left`,title:`Click to rename`,onClick:()=>{c(e.id),u(e.name)},children:e.name}),(0,W.jsxs)(`span`,{className:`font-mono text-[11px] text-muted-foreground`,children:[`(`,e.id,`)`]}),(0,W.jsx)(`button`,{type:`button`,title:`Click to copy`,"aria-label":`Copy tag ${bJ(e.id)}`,onClick:()=>{navigator.clipboard?.writeText(bJ(e.id))},className:`rounded bg-muted px-1.5 py-0.5 font-mono text-[11px] text-foreground hover:bg-accent`,children:bJ(e.id)}),(0,W.jsx)(`div`,{className:`ml-auto flex items-center gap-2`,children:a===e.id?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-xs text-destructive`,children:`Delete this profile?`}),(0,W.jsx)(K,{variant:`destructive`,size:`sm`,className:`h-7`,onClick:()=>void m(e),children:`Confirm`}),(0,W.jsx)(K,{variant:`outline`,size:`sm`,className:`h-7`,onClick:()=>o(null),children:`Cancel`})]}):(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete profile ${e.name}`,className:`p-1 rounded text-muted-foreground hover:text-destructive transition`,onClick:()=>o(e.id),children:(0,W.jsx)(Ue,{className:`size-3.5`})})})]}),(0,W.jsx)(i7,{profile:e,onAdd:t=>void h(e,t),onUpdate:(t,n)=>void g(e,t,n),onRemove:t=>void _(e,t)})]},e.id))})]})]})})}function i7({profile:e,onAdd:t,onUpdate:n,onRemove:r}){return(0,W.jsxs)(`div`,{className:`space-y-2`,children:[e.rules.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No rules yet — this profile is silent.`}):(0,W.jsx)(`div`,{className:`space-y-1`,children:e.rules.map((e,t)=>(0,W.jsx)(o7,{index:t,rule:e,onCommit:n,onRemove:r},`${t}:${e.trigger}:${e.sound}`))}),(0,W.jsx)(s7,{onAdd:t})]})}function a7({value:e,onChange:t,label:n}){return(0,W.jsx)(`select`,{"aria-label":n,className:`h-7 rounded border border-input bg-background px-2 text-xs outline-none cursor-pointer focus:border-primary`,value:e,onChange:e=>t(e.target.value),children:Yk.map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))})}function o7({index:e,rule:t,onCommit:n,onRemove:r}){let[i,a]=(0,U.useState)(t.trigger),[o,s]=(0,U.useState)(null),c=()=>{let r=i.trim();if(r===t.trigger){s(null);return}if(!Xu(r)){s(`"${r}" is not a trigger — use ${n7} …`);return}s(null),n(e,{trigger:r,sound:t.sound})};return(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{"aria-label":`Trigger for rule ${e+1}`,className:`h-7 w-24 rounded border border-input bg-background px-2 font-mono text-xs outline-none focus:border-primary`,placeholder:n7,value:i,onChange:e=>a(e.target.value),onKeyDown:e=>{e.key===`Enter`&&c()},onBlur:c}),(0,W.jsx)(a7,{label:`Sound for rule ${e+1}`,value:t.sound,onChange:r=>n(e,{trigger:t.trigger,sound:r})}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete rule ${e+1}`,className:`p-1 rounded text-muted-foreground hover:text-destructive transition`,onClick:()=>r(e),children:(0,W.jsx)(Ue,{className:`size-3.5`})})]}),o&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:o})]})}function s7({onAdd:e}){let[t,n]=(0,U.useState)(``),[r,i]=(0,U.useState)(Yk[0]),[a,o]=(0,U.useState)(null);return(0,W.jsxs)(`form`,{onSubmit:a=>{a.preventDefault();let s=t.trim();if(!Xu(s)){o(`"${s}" is not a trigger — use ${n7} …`);return}o(null),e({trigger:s,sound:r}),n(``),i(Yk[0])},className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{"aria-label":`New rule trigger`,className:`h-7 w-24 rounded border border-input bg-background px-2 font-mono text-xs outline-none focus:border-primary`,placeholder:n7,value:t,onChange:e=>n(e.target.value)}),(0,W.jsx)(a7,{label:`New rule sound`,value:r,onChange:i}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,variant:`outline`,className:`h-7`,children:[(0,W.jsx)(On,{className:`size-3 mr-1`}),` Add Rule`]}),a&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:a})]})}var c7=[{id:`appearance`,content:(0,W.jsx)(d7,{})},{id:`profile`,content:(0,W.jsx)(z5,{})},{id:`storage`,content:(0,W.jsx)(e7,{})},{id:`sync`,content:(0,W.jsx)(E3,{})},{id:`tags`,content:(0,W.jsx)(p7,{})},{id:`sound-profiles`,content:(0,W.jsx)(r7,{})},{id:`routes`,content:(0,W.jsx)(u7,{})},{id:`system`,content:(0,W.jsx)(f7,{})}];function l7(){let e=Sn(),t=e.pathname.endsWith(`/system`)?`system`:e.pathname.endsWith(`/profile`)?`profile`:e.pathname.endsWith(`/storage`)?`storage`:e.pathname.endsWith(`/sync`)?`sync`:e.pathname.endsWith(`/tags`)?`tags`:e.pathname.endsWith(`/sound-profiles`)?`sound-profiles`:e.pathname.endsWith(`/routes`)?`routes`:`appearance`;return(0,W.jsxs)(`div`,{className:`flex-1 flex flex-col min-h-0 bg-background`,children:[(0,W.jsx)(NB,{title:`Settings`,subtitle:`Manage profile, appearance, audio, and system preferences`}),(0,W.jsx)(`main`,{className:`flex-1 overflow-y-auto px-4 sm:px-6 lg:px-8 py-6 sm:py-8`,children:(0,W.jsx)(`div`,{className:`max-w-4xl mx-auto space-y-8`,children:c7.find(e=>e.id===t)?.content})})]})}function u7(){let[e,t]=(0,U.useState)([]);return(0,U.useEffect)(()=>{let e=!0;return jk.readonly(`page`).getAll().then(n=>{e&&t(n)}).catch(console.error),()=>{e=!1}},[]),(0,W.jsxs)(`section`,{className:`space-y-6`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`text-lg font-medium`,children:`Route Review`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:"All page routes (`/page/:slug`, `/notebook/:slug`, `/day/:date`) currently registered in storage."})]}),(0,W.jsx)(`div`,{className:`border rounded-md`,children:(0,W.jsxs)(`table`,{className:`w-full text-sm text-left`,children:[(0,W.jsx)(`thead`,{className:`bg-muted/50 border-b`,children:(0,W.jsxs)(`tr`,{children:[(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Route`}),(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`Title`}),(0,W.jsx)(`th`,{className:`px-4 py-2 font-medium`,children:`ID`})]})}),(0,W.jsx)(`tbody`,{className:`divide-y`,children:e.length===0?(0,W.jsx)(`tr`,{children:(0,W.jsx)(`td`,{colSpan:3,className:`px-4 py-4 text-center text-muted-foreground`,children:`No pages found.`})}):e.map(e=>(0,W.jsxs)(`tr`,{children:[(0,W.jsx)(`td`,{className:`px-4 py-2 font-mono text-xs`,children:e.slug?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold bg-primary/10 text-primary`,children:`SLUG`}),e.slug]}):e.date?(0,W.jsxs)(`span`,{className:`inline-flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`px-1.5 py-0.5 rounded text-[10px] font-semibold bg-secondary/10 text-secondary`,children:`DATE`}),e.date]}):`—`}),(0,W.jsx)(`td`,{className:`px-4 py-2`,children:e.title??`—`}),(0,W.jsx)(`td`,{className:`px-4 py-2 font-mono text-[10px] text-muted-foreground`,children:e.id})]},e.id))})]})})]})}function d7(){let{theme:e,setTheme:t}=Mi(),[n,r]=MV(),i={right:mr,left:bt};return(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Interface Theme`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Select your preferred color theme. Changes are saved and applied immediately.`})]}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-3 sm:gap-4`,children:[{id:`system`,label:`System`,description:`Follows your operating system color scheme preferences`,icon:tn,isDefault:!0},{id:`light`,label:`Light`,description:`Crisp light background with dark text for high daytime readability`,icon:ae},{id:`dark`,label:`Dark`,description:`Relaxed dark background for lower eye strain in low-light settings`,icon:Pe}].map(n=>{let r=e===n.id,i=n.icon;return(0,W.jsxs)(`button`,{type:`button`,"data-testid":`theme-option-${n.id}`,onClick:()=>t(n.id),className:G(`relative flex flex-col items-start p-4 rounded-xl border text-left transition-all`,r?`border-primary ring-2 ring-primary/20 bg-primary/5 text-foreground shadow-xs`:`border-border bg-card text-muted-foreground hover:text-foreground hover:bg-muted/40`),children:[(0,W.jsxs)(`div`,{className:`w-full flex items-center justify-between mb-3`,children:[(0,W.jsx)(`div`,{className:G(`p-2 rounded-lg`,r?`bg-primary text-primary-foreground`:`bg-muted text-foreground`),children:(0,W.jsx)(i,{className:`size-5`})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[n.isDefault&&(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`Default`}),(0,W.jsx)(`div`,{className:G(`size-4 rounded-full border flex items-center justify-center transition-colors`,r?`border-primary bg-primary text-primary-foreground`:`border-muted-foreground/40`),children:r&&(0,W.jsx)(un,{className:`size-2.5 stroke-[3]`})})]})]}),(0,W.jsx)(`div`,{className:`font-semibold text-foreground text-sm`,children:n.label}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:n.description})]},n.id)})})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(Tt,{className:`size-4 text-primary`}),`Actions Button Position`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`On phones, search and page actions float as a button cluster at the bottom of the screen. Place the cluster near your dominant thumb.`})]}),(0,W.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-3 sm:gap-4`,children:DV.map(e=>{let t=n===e.id,a=i[e.id];return(0,W.jsxs)(`button`,{type:`button`,"data-testid":`fab-alignment-${e.id}`,onClick:()=>r(e.id),className:G(`relative flex flex-col items-start p-4 rounded-xl border text-left transition-all`,t?`border-primary ring-2 ring-primary/20 bg-primary/5 text-foreground shadow-xs`:`border-border bg-card text-muted-foreground hover:text-foreground hover:bg-muted/40`),children:[(0,W.jsxs)(`div`,{className:`w-full flex items-center justify-between mb-3`,children:[(0,W.jsx)(`div`,{className:G(`p-2 rounded-lg`,t?`bg-primary text-primary-foreground`:`bg-muted text-foreground`),children:(0,W.jsx)(a,{className:`size-5`})}),(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[e.id===`right`&&(0,W.jsx)(`span`,{className:`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted text-muted-foreground`,children:`Default`}),(0,W.jsx)(`div`,{className:G(`size-4 rounded-full border flex items-center justify-center transition-colors`,t?`border-primary bg-primary text-primary-foreground`:`border-muted-foreground/40`),children:t&&(0,W.jsx)(un,{className:`size-2.5 stroke-[3]`})})]})]}),(0,W.jsx)(`div`,{className:`font-semibold text-foreground text-sm`,children:e.label}),(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground mt-1 leading-relaxed`,children:e.description})]},e.id)})})]})]})}function f7(){let{isEnabled:e,toggleAudio:t,playTestSound:n}=ZA(),{isDebugMode:r,toggleDebugMode:i}=Oy(),{consent:a,setConsent:o}=pq(),[s,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(null),p=vk(),m=p.state===`turso`?`your Turso database (${p.url})`:null;return(0,U.useEffect)(()=>{if(!s)return;let e=e=>{e.key===`Escape`&&(e.preventDefault(),c(!1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[s]),(0,W.jsxs)(`div`,{className:`space-y-8`,children:[(0,W.jsxs)(`section`,{className:`space-y-4`,"data-testid":`settings-about`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(pe,{className:`size-4 text-primary`}),`About`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Build version and release information for this playground.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsxs)(`p`,{className:`text-sm font-medium text-foreground font-mono`,children:[`v`,$z]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Wod Wiki playground build`})]}),(0,W.jsx)(K,{asChild:!0,variant:`outline`,size:`sm`,className:`gap-2`,children:(0,W.jsxs)(`a`,{href:tB($z),target:`_blank`,rel:`noopener noreferrer`,"data-testid":`settings-release-link`,children:[(0,W.jsx)(A,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Release notes`})]})})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[e?(0,W.jsx)(fe,{className:`size-4 text-primary`}):(0,W.jsx)(ne,{className:`size-4 text-muted-foreground`}),`Audio Feedback`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Configure sound effects for workout timers, interval countdowns, and completion cues.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-border bg-card p-4 space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`label`,{htmlFor:`sound-switch`,className:`text-sm font-medium text-foreground cursor-pointer`,children:`Workout Sound Effects`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Play countdown beeps, interval alerts, and workout finish chimes`})]}),(0,W.jsx)(e3,{id:`sound-switch`,"data-testid":`sound-toggle`,checked:e,onChange:t})]}),(0,W.jsxs)(`div`,{className:`pt-3 border-t border-border/50 flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Test audio output device`}),(0,W.jsxs)(K,{variant:`outline`,size:`sm`,onClick:n,disabled:!e,"data-testid":`play-test-sound-btn`,className:`gap-2`,children:[(0,W.jsx)(fe,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Play Test Chime`})]})]})]})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(ft,{className:`size-4 text-primary`}),`Developer Diagnostics`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Logging and runtime inspection tools for Whiteboard scripts and execution trees.`})]}),(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`label`,{htmlFor:`debug-switch`,className:`text-sm font-medium text-foreground cursor-pointer`,children:`Debug Mode`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Output verbose AST compilation and runtime execution traces to browser console`})]}),(0,W.jsx)(e3,{id:`debug-switch`,"data-testid":`debug-mode-toggle`,checked:r,onChange:i})]})})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,"data-testid":`settings-telemetry`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-foreground flex items-center gap-2`,children:[(0,W.jsx)(y,{className:`size-4 text-primary`}),`Anonymous Telemetry`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Anonymous usage telemetry is internal to Wod Wiki only. It helps us improve timer accuracy, workout execution, and query reliability. Your data will never be sold or shared with third parties.`})]}),(0,W.jsx)(`div`,{className:`rounded-xl border border-border bg-card p-4`,children:(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-0.5`,children:[(0,W.jsx)(`label`,{htmlFor:`telemetry-switch`,className:`text-sm font-medium text-foreground cursor-pointer`,children:`Share Anonymous Usage Statistics`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Sends anonymous feature usage events. Turn off to opt out at any time.`})]}),(0,W.jsx)(e3,{id:`telemetry-switch`,"data-testid":`telemetry-toggle`,checked:a,onChange:o})]})})]}),(0,W.jsxs)(`section`,{className:`space-y-4 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`h2`,{className:`text-base font-semibold text-destructive flex items-center gap-2`,children:[(0,W.jsx)(I,{className:`size-4 text-destructive`}),`Data & Cache (Danger Zone)`]}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Manage your local database storage and reset client state.`})]}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-destructive/30 bg-destructive/5 p-4 sm:p-5 space-y-4`,children:[(0,W.jsxs)(`div`,{className:`space-y-1`,children:[(0,W.jsx)(`div`,{className:`font-semibold text-sm text-foreground`,children:`Reset & Clear Cache`}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:m?(0,W.jsxs)(W.Fragment,{children:[`Wipes ALL data stored in `,m,`: notes, workouts, custom efforts, recorded results, and attachments, plus this browser's localStorage preferences. Your separate IndexedDB copy is kept. Bundled core content re-imports automatically on the next launch; community and custom libraries must be re-synced from Settings > Sync. Your connection settings are preserved.`]}):(0,W.jsx)(W.Fragment,{children:`Wipes all durable data stores including IndexedDB (notes, workouts, custom efforts, recorded results, and attachments) and resets all localStorage preferences. The application returns to a fresh first-run state: the core playground content re-imports automatically on the next launch, and community/custom libraries wait for you in Settings > Sync.`})})]}),(0,W.jsx)(`div`,{children:(0,W.jsxs)(K,{variant:`destructive`,size:`sm`,onClick:()=>c(!0),"data-testid":`reset-cache-button`,className:`gap-2`,children:[(0,W.jsx)(At,{className:`size-4`}),(0,W.jsx)(`span`,{children:`Reset & Clear Cache`})]})})]})]}),s&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4 animate-in fade-in duration-150`,onClick:e=>{e.target===e.currentTarget&&!l&&c(!1)},"data-testid":`reset-confirmation-modal`,children:(0,W.jsxs)(`div`,{className:`w-full max-w-md rounded-xl border border-border bg-card p-6 shadow-2xl flex flex-col gap-4`,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`reset-modal-title`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2.5 text-destructive font-semibold text-base`,id:`reset-modal-title`,children:[(0,W.jsx)(I,{className:`size-5`}),`Reset All Application Data?`]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground leading-relaxed`,children:m?(0,W.jsxs)(W.Fragment,{children:[`This permanently deletes every note, result, cached effort, and local setting stored in `,m,`. It cannot be undone.`]}):(0,W.jsx)(W.Fragment,{children:`This action will permanently wipe every note, result, cached effort, and local setting from your browser storage. This returns Wod Wiki to its first-run state and cannot be undone.`})}),d&&(0,W.jsxs)(`p`,{role:`alert`,className:`text-xs text-destructive`,"data-testid":`reset-error`,children:[`Reset failed: `,d,` — your data and connection were left untouched; try again.`]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-end gap-2 pt-2`,children:[(0,W.jsx)(K,{variant:`outline`,onClick:()=>c(!1),disabled:l,children:`Cancel`}),(0,W.jsx)(K,{variant:`destructive`,onClick:async()=>{u(!0),f(null);try{await X0(),window.location.reload()}catch(e){f(e instanceof Error?e.message:String(e)),u(!1)}},disabled:l,"data-testid":`confirm-reset-button`,className:`gap-2`,children:l?(0,W.jsx)(`span`,{children:`Resetting…`}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(At,{className:`size-4`}),(0,W.jsx)(`span`,{children:`Yes, Reset Everything`})]})})]})]})})]})}function p7(){let[e,t]=(0,U.useState)([]),[n,r]=(0,U.useState)([]),[i,a]=(0,U.useState)(``),[o,s]=(0,U.useState)(``),[c,l]=(0,U.useState)(`#3b82f6`),[u,d]=(0,U.useState)(null),f=(0,U.useCallback)(async()=>{try{let[e,n]=await Promise.all([Z.getAllTagTypes(),Z.getAllTags()]);t(e),r(n)}catch{}},[]);(0,U.useEffect)(()=>{f()},[f]);let p=async t=>{t.preventDefault();let n=i.trim().toLowerCase().replace(/[^a-z0-9_-]/g,`-`),r=o.trim();if(!n||!r){d(`Both type name and display label are required`);return}if(e.some(e=>e.name.toLowerCase()===n)){d(`Tag type "${n}" already exists`);return}d(null);let l={id:typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,9)}`,name:n,label:r,color:c,createdAt:Date.now()};await Z.putTagType(l),a(``),s(``),await f()},m=async e=>{if(n.some(t=>t.type?.toLowerCase()===e.name.toLowerCase())){d(`Cannot delete tag type "${e.label}" while tags are assigned to it`);return}d(null),await Z.deleteTagType(e.id),await f()};return(0,W.jsx)(`div`,{className:`space-y-8`,children:(0,W.jsxs)(`section`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold text-foreground`,children:`Tag Types`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`The kinds of tag that exist. A tag picks one as its kind, and note frontmatter properties matching a type name provide typeahead suggestions. The tags themselves — and what they contribute — are authored on the`,` `,(0,W.jsx)(`span`,{className:`font-mono`,children:`/tags`}),` page.`]})]}),(0,W.jsxs)(`div`,{className:`p-4 sm:p-5 rounded-xl border border-border bg-card shadow-xs space-y-4`,children:[(0,W.jsxs)(`form`,{onSubmit:p,className:`flex flex-wrap items-end gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex-1 min-w-[160px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Type Name`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary font-mono`,placeholder:`Type name (e.g. discipline)`,value:i,onChange:e=>a(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`flex-1 min-w-[160px]`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Display Label`}),(0,W.jsx)(`input`,{className:`w-full h-9 rounded-md border border-input bg-background px-3 text-xs outline-none focus:border-primary`,placeholder:`Display label (e.g. Discipline)`,value:o,onChange:e=>s(e.target.value)})]}),(0,W.jsxs)(`div`,{className:`w-24`,children:[(0,W.jsx)(`label`,{className:`block text-xs font-medium text-muted-foreground mb-1`,children:`Color`}),(0,W.jsx)(`input`,{type:`color`,className:`w-full h-9 p-1 rounded-md border border-input bg-background cursor-pointer`,value:c,onChange:e=>l(e.target.value)})]}),(0,W.jsxs)(K,{type:`submit`,size:`sm`,className:`h-9`,children:[(0,W.jsx)(On,{className:`size-3.5 mr-1`}),` Add Type`]})]}),u&&(0,W.jsx)(`p`,{className:`text-xs text-destructive`,children:u}),(0,W.jsxs)(`div`,{className:`border-t border-border pt-3`,children:[(0,W.jsx)(`h3`,{className:`text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-2`,children:`Registered Types`}),e.length===0?(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground italic`,children:`No custom tag types created yet.`}):(0,W.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-2`,children:e.map(e=>{let t=n.filter(t=>t.type?.toLowerCase()===e.name.toLowerCase()).length;return(0,W.jsxs)(`div`,{className:`flex items-center justify-between p-2.5 rounded-lg border border-border/70 bg-background/50 text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,W.jsx)(`span`,{className:`size-2.5 rounded-full shrink-0`,style:{backgroundColor:e.color||`#3b82f6`}}),(0,W.jsx)(`span`,{className:`font-semibold truncate`,children:e.label}),(0,W.jsxs)(`span`,{className:`text-muted-foreground font-mono text-[11px] truncate`,children:[`(`,e.name,`)`]}),(0,W.jsx)(`span`,{className:`rounded bg-muted px-1.5 py-0.2 text-[10px] text-muted-foreground`,children:t})]}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Delete tag type ${e.label}`,disabled:t>0,title:t>0?`Cannot delete type while ${t} tag(s) are assigned`:`Delete unused tag type`,className:G(`p-1 rounded transition`,t>0?`text-muted-foreground/30 cursor-not-allowed`:`text-muted-foreground hover:text-destructive cursor-pointer`),onClick:()=>m(e),children:(0,W.jsx)(Ue,{className:`size-3.5`})})]},e.id)})})]})]})]})})}var m7=`dashboard-title`;function h7(){let{slug:e}=wt(),t=Vn(),[n]=N2(),{unit:r}=QS(),i=Date.now()-n*7*864e5,a=Date.now(),[o,s]=(0,U.useState)(0),[c,l]=(0,U.useState)(null);(0,U.useEffect)(()=>{let e=!1;return Z.countEvents().then(t=>{e||l(t>0)}),()=>{e=!0}},[o]);let{source:u,loading:d}=fP(e,o),f=(0,U.useMemo)(()=>{if(!u?.rawContent)return null;let{meta:e,sections:t}=uv(u.rawContent);return{doc:iv(t,e),sections:t}},[u]),p=f?.doc??null,{setL3Items:m,registerScrollFn:h}=WM(),g=(0,U.useMemo)(()=>{if(!f)return{headings:[],items:[]};let{doc:e,sections:t}=f,n=new Set;t.forEach((e,r)=>{if(e.type!==`query`)return;let i=t[r-1];if(i?.type===`markdown`&&i.subtype===`paragraph`){let e=t[r-2];e?.type===`markdown`&&e.subtype===`heading`&&n.add(r-2)}else i?.type===`markdown`&&i.subtype===`heading`&&n.add(r-1)});let r=[],i=[];e.title&&i.push({id:m7,label:e.title,level:3,action:{type:`scroll`,sectionId:m7}});let a=0;return t.forEach((t,o)=>{if(t.type===`markdown`&&t.subtype===`heading`){if(n.has(o)||/^#\s/.test(t.content))return;let e=`note-h${o}`,s=t.content.replace(/^#+\s*/,``);r.push({id:e,level:/^#+/.exec(t.content)?.[0].length??2,text:s,beforeWidget:a}),i.push({id:e,label:s,level:3,action:{type:`scroll`,sectionId:e}});return}if(t.type!==`query`)return;let s=e.widgets[a];if(!s)return;a++;let c=`widget-${s.key}`;i.push({id:c,label:s.title||s.body,level:3,action:{type:`scroll`,sectionId:c}})}),{headings:r,items:i}},[f]),_=g.items;(0,U.useEffect)(()=>(m(_),()=>m([])),[_,m]),(0,U.useEffect)(()=>(h(e=>{let t=globalThis.document.getElementById(e);t&&(window.scrollTo({top:t.getBoundingClientRect().top+window.scrollY-80,behavior:`smooth`}),typeof t.animate==`function`&&t.animate([{boxShadow:`0 0 0 3px hsl(var(--primary))`},{boxShadow:`0 0 0 3px transparent`}],{duration:1500,easing:`ease-out`}))}),()=>h(e=>{let t=globalThis.document.getElementById(e);t&&window.scrollTo({top:t.getBoundingClientRect().top+window.scrollY-80,behavior:`smooth`})})),[h]);let[v,y]=(0,U.useState)(!1),[b,x]=(0,U.useState)(null),[S,C]=(0,U.useState)(null),w=(0,U.useCallback)(async(e,t)=>{if(!u?.editable||!u.noteId)return;let n=await CP.getById(u.noteId);if(n.rawContent!==e)throw s(e=>e+1),Error(`The dashboard changed elsewhere — this edit was not saved.`);let r=t(n.rawContent);if(r==null)throw s(e=>e+1),Error(`The widget changed on disk — this edit was not saved.`);await CP.update(n,typeof r==`string`?r:r.note,typeof r==`string`?void 0:r),s(e=>e+1)},[u]),T=(0,U.useCallback)(async(e,t)=>{if(!u?.editable||!u.noteId)return;let n=await CP.getById(u.noteId),{meta:r,body:i}=By(n.rawContent),a=`---\n${Wy($_(r,e,t))}\n---\n${i}`;await CP.update(n,a),s(e=>e+1)},[u]),E=(0,U.useCallback)((e,t)=>{C(null),w(e,e=>{let n=t(e);if(!n.ok){let e=n.reason;throw Error(e===`stale-body`?`Widget changed since you opened this page — reload and retry.`:`Widget no longer exists — reload the dashboard.`)}return n}).catch(e=>{C(e instanceof Error?e.message:String(e))})},[w]),D=(0,U.useCallback)(async e=>{if(!(!b||b.mode===`inspect`)){if(b.mode===`add`)await w(b.expectedRaw,t=>bv(t,e));else{let t=b.widget;await w(b.expectedRaw,n=>{let r=Cv(n,t.key,t.body,e);if(!r.ok){let e=r.reason;throw Error(e===`stale-body`?`Widget changed since you opened this page — reload and retry.`:`Widget no longer exists — reload the dashboard.`)}return r})}}},[b,w]),O=(0,U.useCallback)(async()=>{!u||u.editable||(await TP.cloneDashboard(u.slug,u.rawContent,u.title),s(e=>e+1))},[u]),k=u!=null&&u.slug===e;if(d&&!k)return(0,W.jsx)(`div`,{className:`p-8 text-sm text-muted-foreground`,children:`Loading dashboard…`});if(!k||!u)return(0,W.jsxs)(`div`,{className:`p-8`,"data-testid":`dashboard-not-found`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-bold text-foreground mb-2`,children:`Dashboard not found`}),(0,W.jsxs)(`p`,{className:`text-sm text-muted-foreground mb-4`,children:[`No dashboard named `,(0,W.jsx)(`code`,{children:e}),`. It may have been removed.`]}),(0,W.jsx)(`button`,{onClick:()=>t(`/dashboard`),className:`px-4 py-2 text-sm font-medium bg-primary text-primary-foreground rounded-lg hover:opacity-90`,children:`Back to explorer`})]});let A=u.editable;return(0,W.jsxs)(`div`,{className:`min-h-screen bg-background flex flex-col`,children:[(0,W.jsx)(NB,{id:m7,title:p?.title||u.title,subtitle:A?`Editable dashboard note.`:`Prebuilt — read-only until cloned to your vault.`,actions:(0,W.jsxs)(RV,{label:`Dashboard actions`,primary:A?(0,W.jsxs)(`button`,{type:`button`,"data-testid":`dashboard-edit-toggle`,"aria-pressed":v,onClick:()=>y(e=>!e),className:`flex items-center gap-1.5 rounded-lg px-3 py-1.5 text-xs font-semibold transition-colors ${v?`bg-primary text-primary-foreground`:`border border-border text-muted-foreground hover:text-foreground hover:bg-muted`}`,children:[(0,W.jsx)(qt,{size:12}),` `,v?`Done`:`Edit`]}):void 0,children:[(0,W.jsx)(US,{}),(0,W.jsx)(eC,{})]})}),(0,W.jsxs)(`div`,{className:`max-w-[1500px] w-full mx-auto p-4 md:p-6 lg:p-8 flex-1`,children:[S&&(0,W.jsxs)(`div`,{role:`alert`,"data-testid":`dashboard-action-error`,className:`mb-4 flex items-center justify-between rounded-lg border border-destructive/40 bg-destructive/10 px-4 py-2 text-xs text-destructive`,children:[(0,W.jsx)(`span`,{children:S}),(0,W.jsx)(`button`,{type:`button`,"aria-label":`Dismiss`,onClick:()=>C(null),className:`font-medium hover:opacity-70 transition-opacity`,children:`×`})]}),!A&&(0,W.jsxs)(`div`,{className:`mb-4 flex items-center justify-between rounded-lg border border-primary/30 bg-primary/5 px-4 py-2 text-xs`,children:[(0,W.jsx)(`span`,{className:`text-foreground`,children:`This is a read-only prebuilt. Clone it to edit widgets and tokens.`}),(0,W.jsx)(`button`,{type:`button`,"data-testid":`clone-dashboard`,onClick:O,className:`font-medium text-primary hover:text-primary/80 transition-colors`,children:`Clone to vault`})]}),A&&v&&(0,W.jsxs)(`button`,{type:`button`,"data-testid":`add-widget`,onClick:()=>x({mode:`add`,expectedRaw:u.rawContent}),className:`mb-4 flex items-center gap-1.5 rounded-lg border border-dashed border-primary/50 px-4 py-2 text-xs font-semibold text-primary hover:bg-primary/5 transition-colors`,children:[(0,W.jsx)(On,{size:13}),` Add widget`]}),c===!1?(0,W.jsx)(w5,{layout:`card`,refreshKey:o,onChanged:()=>s(e=>e+1)}):(0,W.jsx)(`div`,{className:`mb-4`,children:(0,W.jsx)(w5,{layout:`banner`,refreshKey:o,onChanged:()=>s(e=>e+1)})}),p&&(0,W.jsx)(HS,{document:p,headings:g.headings,executor:sz,onTokenChange:A?T:void 0,editMode:A&&v,onEditWidget:A?e=>x({mode:`edit`,widget:e,expectedRaw:u.rawContent}):void 0,onDuplicateWidget:A?e=>E(u.rawContent,t=>wv(t,e.key,e.body)):void 0,onRemoveWidget:A?e=>E(u.rawContent,t=>Tv(t,e.key,e.body)):void 0,onMoveWidget:A?(e,t)=>E(u.rawContent,n=>Ev(n,e.key,e.body,t)):void 0,onResizeWidget:A?(e,t)=>E(u.rawContent,n=>Dv(n,e.key,e.body,t)):void 0,onInspectWidget:A?void 0:e=>x({mode:`inspect`,widget:e,expectedRaw:u.rawContent}),onOpenInExplorer:(e,n)=>t(FN({q:n})),rangeStart:i,rangeEnd:a,preferredUnit:r})]}),(0,W.jsx)(L2,{open:b!==null,onClose:()=>x(null),mode:b?.mode??`add`,initialWql:b&&b.mode!==`add`?b.widget.body:`sum:totalVolume{}`,initial:b&&b.mode!==`add`?{title:b.widget.title,question:b.widget.question,type:b.widget.type,spanCols:b.widget.spanCols,spanFull:b.widget.spanFull,attributes:b.widget.attributes}:void 0,executor:sz,rangeStart:i,rangeEnd:a,preferredUnit:r,tokenValues:p?Q_(p.tokens):void 0,onApply:b?.mode===`inspect`?void 0:D,footerExtra:b?.mode===`inspect`?(0,W.jsx)(`button`,{type:`button`,"data-testid":`inspect-clone`,onClick:()=>{O().then(()=>{x(null),y(!0)})},className:`px-3 py-1.5 text-xs font-medium text-primary hover:text-primary/80 rounded-lg border border-primary/40 hover:bg-primary/10 transition-colors`,children:`Clone to vault to edit`}):void 0})]})}function g7({sessionId:e}){let[t,n]=(0,U.useState)(null),[r,i]=(0,U.useState)(null),[a,o]=(0,U.useState)(!1),[s,c]=(0,U.useState)(``);return(0,U.useEffect)(()=>{let t=!1;return n(null),i(null),(async()=>{let r=await lP.getSessionById?.(e);if(!r)throw Error(`Session not found.`);let i=await lP.getBlockRevision(r.noteId,r.blockId,r.blockVersion);if(!i)throw Error(`The pinned saved workout is unavailable.`);t||n({session:r,revision:i})})().catch(e=>{t||i(e instanceof Error?e.message:String(e))}),()=>{t=!0}},[e]),(0,W.jsxs)(`section`,{"aria-label":`Pinned workout source`,className:`space-y-3 border-b p-4`,children:[(0,W.jsx)(`h2`,{className:`font-semibold`,children:`Saved workout used by this session`}),r&&(0,W.jsx)(`p`,{role:`alert`,children:r}),t?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`p`,{className:`break-all text-sm`,children:[`Block `,t.session.blockId,` · v`,t.revision.version,` · `,t.revision.dialect,t.revision.sport?` · ${t.revision.sport}`:``]}),(0,W.jsx)(`pre`,{className:`max-h-72 overflow-auto whitespace-pre-wrap break-words rounded bg-muted p-3 text-xs`,children:t.revision.rawContent}),(0,W.jsx)(`button`,{type:`button`,disabled:a,className:`rounded border px-3 py-2 hover:bg-accent focus-visible:ring-2`,onClick:async()=>{o(!0),i(null);try{await new cP().rederiveResultAnalytics(e),c(`Analytics replayed from the pinned saved workout. Reload the results to view them.`)}catch(e){i(e instanceof Error?e.message:String(e))}finally{o(!1)}},children:a?`Replaying…`:`Replay saved analytics`}),(0,W.jsx)(`p`,{role:`status`,"aria-live":`polite`,className:`text-sm`,children:s}),(0,W.jsx)(iR,{noteId:t.session.noteId})]}):r?null:(0,W.jsx)(`p`,{role:`status`,children:`Loading saved workout…`})]})}function _7({searchHandlerRef:e}){let t=Vn(),n=Sn(),r=wt(),{theme:i}=Mi(),a=YO()??eH,o=$V(),s=qL(),c=gH(),l=hH(),{workout:u,nav:d}=c,[f,p]=(0,U.useState)(!1),[m,h]=(0,U.useState)(`blank`),g=(0,U.useCallback)(e=>{h(e?.mode??`blank`),p(!0)},[]),_=(0,U.useMemo)(()=>/^\/day\/(\d{4}-\d{2}-\d{2})\/?$/.exec(n.pathname)?.[1],[n.pathname]),v=(0,U.useCallback)(e=>{t(`${TN(e.id)}?edit=1`)},[t]),{tree:y,navState:b,setL3Items:x,setSecondarySpec:S,registerCreateJournal:C}=WM(),w=b?.activeL1Id??null,T=(y??[]).find(e=>e?.id===w)??null,E=c.shell.title??u.name,D=OF((0,U.useMemo)(()=>c.page===`library`?yN(n.pathname):void 0,[c.page,n.pathname])),O=c.shell.secondary;(0,U.useEffect)(()=>(S(O),()=>S(void 0)),[O,S]),(0,U.useEffect)(()=>C(g),[C,g]),(0,U.useEffect)(()=>{let e=new URLSearchParams(n.search);if(e.get(`create`)===`1`||e.get(`new`)===`1`){let r=e.get(`mode`)===`source`?`source`:`blank`;g({mode:r}),e.delete(`create`),e.delete(`new`),e.delete(`mode`);let i=e.toString()?`?${e.toString()}`:``;t(`${n.pathname}${i}`,{replace:!0})}},[n.pathname,n.search,g,t]),(0,U.useEffect)(()=>{if(!(!c.shell.withIndex||d.length===0))return x(wU(d)),()=>x([])},[c.shell.withIndex,d,x]);let k=(0,U.useRef)(()=>null),A=(0,U.useCallback)(e=>(k.current=e,()=>{k.current===e&&(k.current=()=>null)}),[]),j=(0,U.useCallback)(()=>{TH.getState().open({wql:{initialQuery:k.current()??mU(),execute:gU,preferredChoices:hU(),settings:{panel:(0,W.jsx)(E6,{})}},sources:[dU(),pU(qH(s)),pU(BH())]}).then(e=>{e.dismissed||_U(e.item,t)})},[t,s]);(0,U.useEffect)(()=>{e.current=j},[j,e]),(0,U.useEffect)(()=>{let e=e=>{e.key===`/`&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),e.stopPropagation(),j())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[j]);let[M,N]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches),{handleViewCreated:P,scrollToSection:F}=TU(d);(0,U.useEffect)(()=>{if(i!==`system`)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>N(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[i]);let I=(0,U.useMemo)(()=>i===`system`?M?`vs-dark`:`vs`:i===`dark`?`vs-dark`:`vs`,[i,M]),L={feedDetail:()=>(0,W.jsx)(x1,{feedSlug:decodeURIComponent(c.feedDetailMatch)}),notebookItem:()=>(0,W.jsx)(m0,{slug:decodeURIComponent(c.notebookItemMatch[0]),itemDate:decodeURIComponent(c.notebookItemMatch[1]),item:decodeURIComponent(c.notebookItemMatch[2]),theme:I,onViewCreated:P,onScrollToSection:F}),effortDetail:()=>(0,W.jsx)(a8,{}),equipmentDetail:()=>(0,W.jsx)(u8,{}),tagDetail:()=>(0,W.jsx)(w8,{initialTag:r.tag},r.tag??``),dashboardExplorer:()=>(0,W.jsx)(M5,{actions:(0,W.jsx)(p0,{mode:`notebook-readonly`,currentWorkout:u,index:[]})}),dashboardView:()=>(0,W.jsx)(h7,{}),home:()=>(0,W.jsx)(g4,{wodFiles:a,theme:I}),canvas:()=>c.canvasPage.scroll?(0,W.jsx)(b1,{page:c.canvasPage,wodFiles:a,theme:I,workoutItems:o,onSelect:l,onScrollToSection:F}):(0,W.jsx)(n1,{page:c.canvasPage,wodFiles:a,theme:I,workoutItems:o,onSelect:l,onScrollToSection:F}),playground:()=>(0,W.jsx)(q6,{theme:I,onViewCreated:P,onScrollToSection:F,onSearch:j},c.effectivePlaygroundId),day:()=>(0,W.jsx)(j6,{journalDate:c.day,theme:I,onViewCreated:P},c.day),note:()=>c.namedPageSlug?(0,W.jsx)(M8,{slug:c.namedPageSlug},c.namedPageSlug):(0,W.jsx)(A8,{noteId:c.note,theme:I},c.note),notebookDate:()=>(0,W.jsx)(I8,{slug:c.notebookDate.slug,date:c.notebookDate.date,theme:I},`${c.notebookDate.slug}/${c.notebookDate.date}`),workout:()=>(0,W.jsx)(J6,{category:c.workout.category,name:c.workout.name,mdContent:c.workout.content,theme:I,onViewCreated:P},`${c.workout.category}/${c.workout.name}`),library:()=>{let e=D??DF(yN(n.pathname));return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(v7,{pathname:n.pathname}),(0,W.jsx)(T6,{profile:e,registerStreamDraft:A,actions:(0,W.jsx)(p0,{mode:`notebook-readonly`,currentWorkout:u,index:[]})},e.route)]})},settings:()=>(0,W.jsx)(l7,{})},ee=c.page===`canvas`?c.canvasPage?.route:void 0,te=c.page===`home`||!!ee?.startsWith(`/page/guide-`),ne=c.page===`canvas`?c.canvasPage:null,R=ne?(0,W.jsx)(W.Fragment,{children:ne.quests.length>0&&(0,W.jsx)(D6,{pageRoute:ne.route,quests:ne.quests,challengeSectionMap:yL(ne),onScrollToSection:F})}):void 0;return(0,W.jsxs)(qV,{navbar:(0,W.jsxs)(YL,{children:[(0,W.jsxs)(`nav`,{"aria-label":`Breadcrumb`,className:`flex items-center gap-1.5 min-w-0 shrink-2 truncate text-sm`,children:[T&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>T?.action?.type===`route`&&t(T.action.to),className:`shrink-0 text-muted-foreground hover:text-foreground transition-colors`,children:T.label}),T&&!!E&&E.toLowerCase()!==T.label.toLowerCase()&&(0,W.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground/50 shrink-0`,children:`›`}),E&&E.toLowerCase()!==T?.label.toLowerCase()&&(0,W.jsx)(`span`,{className:`text-sm font-semibold text-zinc-950 dark:text-white truncate`,children:E}),R]}),(0,W.jsxs)(`div`,{className:`ml-auto flex shrink-0 items-center gap-1`,children:[(0,W.jsx)(vH,{}),(0,W.jsx)(BV,{}),(0,W.jsx)(wZ,{})]})]}),sidebar:(0,W.jsx)(Qz,{navSpec:c.shell.nav}),hideDesktopSidebar:te,secondary:O,pageAction:u.content===``?void 0:(0,W.jsx)(c0,{currentWorkout:u}),onSearch:j,onCreate:g,children:[(0,W.jsx)($H,{open:f,onOpenChange:p,defaultDate:_,defaultMode:m,onCreated:v}),(0,W.jsx)(`div`,{className:`flex flex-col h-full min-h-[calc(100vh-theme(spacing.20))]`,children:(0,W.jsx)(`div`,{className:`flex-1 flex flex-col min-h-0`,children:(e=>{if(c.shell.wrap===`bare`)return e;let t=c.shell.subheader===`filter-notebook-workouts`?(0,W.jsx)(AQ,{placeholder:`Filter notebook notes… Press / to start filtering`}):void 0;return(0,W.jsx)(FB,{title:c.shell.title,titleAccessory:R,subheader:t,index:c.shell.withIndex?d:void 0,actions:c.shell.actionsMode?(0,W.jsx)(p0,{mode:c.shell.actionsMode,currentWorkout:u,index:d}):void 0,children:e})})(L[c.page]())})}),(0,W.jsx)(RH,{}),(0,W.jsx)(CH,{})]})}function v7({pathname:e}){let t=/^\/results\/([^/]+)\/?$/.exec(e);return t?(0,W.jsx)(g7,{sessionId:decodeURIComponent(t[1])}):null}function y7(){return(0,W.jsx)(In,{to:`/sessions?q=%3Asegment%7B%7D%20last%208w`,replace:!0})}function b7(){let{runtimeId:e}=wt();return(0,W.jsx)(In,{to:ON(e),replace:!0})}function x7(){let{runtimeId:e,noteId:t,resultId:n}=wt(),r=n??e;return r?(0,W.jsx)(In,{to:AN(r),replace:!0}):t?(0,W.jsx)(In,{to:`/sessions?q=${encodeURIComponent(`:session{note:${t}}`)}`,replace:!0}):(0,W.jsx)(In,{to:`/sessions`,replace:!0})}function S7(){let e=Sn().search,t=e&&e.startsWith(`?`)?`${e}&mode=plan`:`?mode=plan`;return(0,W.jsx)(In,{to:`/journal${t}`,replace:!0})}var C7=`G-PROD-ID`,w7=!1;function T7(){if(w7||typeof document>`u`)return;w7=!0,window.dataLayer=window.dataLayer??[],window.gtag=function(){window.dataLayer.push(arguments)};let e=document.createElement(`script`);e.async=!0,e.src=`https://www.googletagmanager.com/gtag/js?id=${C7}`,document.head.appendChild(e),window.gtag(`js`,new Date),window.gtag(`config`,C7,{send_page_view:!1})}function E7(e,t){typeof window>`u`||!dq.consent||window.gtag?.(`event`,`page_view`,{page_title:e??document.title,page_location:window.location.href,page_path:t??window.location.pathname+window.location.search,engagement_time_msec:uq()})}dq.setForwarder(e=>{window.gtag?.(`event`,e.name,e.payload??{})}),dq.consent?T7():dq.subscribeConsent(e=>{e&&(T7(),E7())});function D7(){let e=Sn();return(0,U.useEffect)(()=>{let t=e.pathname;if(!t.startsWith(`/effort/`)&&!t.startsWith(`/playground/`)&&!t.startsWith(`/equipment/`)){let e=`Wod.Wiki`;t.startsWith(`/day/`)?e=`Wod.Wiki - Day`:t.startsWith(`/journal`)?e=`Wod.Wiki - Journal`:t.startsWith(`/notebooks`)||t.startsWith(`/notebook/`)?e=`Wod.Wiki - Notebooks`:t===`/notes`?e=`Wod.Wiki - Notes`:t.startsWith(`/note/`)?e=`Wod.Wiki - Note`:t.startsWith(`/pages`)||t.startsWith(`/page/`)?e=`Wod.Wiki - Pages`:t.startsWith(`/tags`)||t.startsWith(`/t/`)?e=`Wod.Wiki - Tags`:t===`/feeds`?e=`Wod.Wiki - Feeds`:t.startsWith(`/feed/`)?e=`Wod.Wiki - Feed`:t.startsWith(`/efforts`)?e=`Wod.Wiki - Efforts`:t.startsWith(`/equipment`)?e=`Wod.Wiki - Equipment`:t.startsWith(`/sessions`)||t.startsWith(`/session/`)?e=`Wod.Wiki - Sessions`:t.startsWith(`/dashboards`)||t.startsWith(`/dashboard/`)?e=`Wod.Wiki - Dashboards`:t.startsWith(`/playgrounds`)&&(e=`Wod.Wiki - Playgrounds`),document.title=e}let n=setTimeout(()=>{E7(document.title,e.pathname+e.search)},0);return()=>clearTimeout(n)},[e.pathname]),null}function O7(e,t){let n=e.match(RegExp(`^${t}:\\s*"([^"]+)"`,`m`));if(!n?.[1])throw Error(`Guide example is missing frontmatter field: ${t}`);return n[1]}function k7(e){let t=e.match(/```time\n([\s\S]*?)\n```/);if(!t)throw Error("Guide example is missing a ```time fenced block.");return t[1]}function A7(e,t){let n=O7(e,`title`),r=O7(e,`subtitle`),i=k7(e);return{title:n,subtitle:r,docsPath:t,workout:i,storyContent:[`# `+n,``,r,``,"```time",i,"```"].join(`
467
467
  `)}}var j7={coreRules:{path:`markdown/canvas/syntax/core-rules.md`,docsPath:`/guide/start?h=first-workout`},measurements:{path:`markdown/canvas/syntax/measurements.md`,docsPath:`/guide/start?h=measurements`},timerModifiers:{path:`markdown/canvas/syntax/timer-modifiers.md`,docsPath:`/guide/protocols?h=countdown-countup`},simpleRounds:{path:`markdown/canvas/syntax/groups-1.md`,docsPath:`/guide/structure?h=rounds`},repSchemes:{path:`markdown/canvas/syntax/groups-2.md`,docsPath:`/guide/structure?h=rep-schemes`},timersAndRest:{path:`markdown/canvas/syntax/timers-rest.md`,docsPath:`/guide/protocols?h=required-rest`},classicAmrap:{path:`markdown/canvas/syntax/classic-amrap.md`,docsPath:`/guide/protocols?h=amrap`},basicEmom:{path:`markdown/canvas/syntax/basic-emom.md`,docsPath:`/guide/protocols?h=emom`},standardTabata:{path:`markdown/canvas/syntax/protocols-4.md`,docsPath:`/guide/protocols?h=tabata-intervals`},mixedSections:{path:`markdown/canvas/syntax/mixed-sections.md`,docsPath:`/guide/structure?h=named-sections`},complexNestedProtocols:{path:`markdown/canvas/syntax/complex-nested-protocols.md`,docsPath:`/guide/sessions?h=nested`}};function M7(e){let t={};for(let[n,{path:r,docsPath:i}]of Object.entries(j7)){let a=e[r];if(!a){t[n]=void 0;continue}try{t[n]=A7(a,i)}catch{t[n]=void 0}}return t}function N7({actionsSlot:e,heroSlot:t,children:n,className:r}){return(0,W.jsxs)(`main`,{className:G(`mx-auto w-full max-w-7xl px-6 py-10 sm:px-8 lg:px-12 lg:py-14`,r),children:[e&&(0,W.jsx)(`div`,{className:`mb-6 flex justify-end`,children:e}),t,n]})}var P7={headline:`Build and preview widget-driven workout pages.`,subtitle:`Phase 2.2 integrates the attention, code-example, and syntax-group widgets into one interactive playground surface.`,pillars:[{icon:(0,W.jsx)(Pt,{className:`size-4`,"aria-hidden":`true`}),label:`Attention widget`,description:`High-signal hero block with actionable CTAs.`},{icon:(0,W.jsx)(nr,{className:`size-4`,"aria-hidden":`true`}),label:`Code example widget`,description:`Editable CodeMirror sample with runnable workout output.`},{icon:(0,W.jsx)(ye,{className:`size-4`,"aria-hidden":`true`}),label:`Syntax group widget`,description:`Grouped syntax cards linked to docs.`}],actions:[{label:`Jump to workout`,action:`scroll-to-workout`,variant:`primary`},{label:`Open search`,action:`open-search`,variant:`secondary`}]};function F7(){let e=Vn(),{theme:t,setTheme:n}=Mi(),r=(0,U.useRef)(null),i=YO(),a=(0,U.useMemo)(()=>i?M7(i):null,[i]),o=(0,U.useMemo)(()=>(a?.classicAmrap?.workout??`20:00 AMRAP
468
468
  5 Pullups
469
469
  10 Pushups
@@ -473,7 +473,7 @@ domain: swimming
473
473
  5 Burpees
474
474
  rest 1:00`,docsPath:t?.docsPath??`/page/guide-protocols?h=required-rest`},{category:`Structure`,icon:`🏋️`,title:`Rep Schemes`,description:n?.subtitle??`Rep counts per movement.`,example:n?.workout??`21-15-9
475
475
  Thrusters`,docsPath:n?.docsPath??`/page/guide-structure?h=rep-schemes`}]},[a]),l=(0,U.useMemo)(()=>t===`dark`||t!==`light`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches,[t]),u=qL(),d=(0,U.useCallback)(async()=>{let t=await TH.getState().open({wql:{initialQuery:mU(),execute:gU,preferredChoices:hU()},sources:[dU(),pU(qH(u))]});t.dismissed||_U(t.item,e)},[e,u]),f=(0,U.useCallback)(e=>{if(e===`scroll-to-workout`){r.current?.scrollIntoView({behavior:`smooth`,block:`start`});return}e===`open-search`&&d()},[d]),p=(0,U.useCallback)(async t=>{let n=await bq([`# Playground Widget Example`,``,"```time",t,"```",``,`[▶ Run Workout]{.button action=start-workout}`,``].join(`
476
- `));e(SN(n))},[e]),m=(0,U.useCallback)(t=>{if(/^https?:\/\//i.test(t)){window.open(t,`_blank`,`noopener,noreferrer`);return}e(t)},[e]);return(0,W.jsxs)(N7,{actionsSlot:(0,W.jsxs)(`div`,{className:`flex items-center gap-3 rounded-2xl border border-zinc-200 bg-zinc-50/80 px-4 py-3 dark:border-zinc-700 dark:bg-zinc-900/70`,children:[(0,W.jsx)(ae,{className:`size-4 text-zinc-500`,"aria-hidden":`true`}),(0,W.jsx)(e3,{checked:l,onChange:e=>n(e?`dark`:`light`),"aria-label":`Toggle dark mode`}),(0,W.jsx)(Pe,{className:`size-4 text-zinc-500`,"aria-hidden":`true`})]}),heroSlot:(0,W.jsx)(N6,{config:P7,onAction:f}),children:[(0,W.jsxs)(`section`,{ref:r,id:`workout-widget-surface`,className:`mt-8 grid grid-cols-1 gap-4 xl:grid-cols-3`,children:[(0,W.jsx)(`div`,{className:`xl:col-span-2`,children:(0,W.jsx)(P6,{config:s,isDarkMode:l,onRun:p})}),(0,W.jsx)(`div`,{className:`space-y-4`,children:c.map(e=>(0,W.jsx)(F6,{config:e,onOpenDocs:m},e.title))})]}),(0,W.jsx)(d2,{})]})}function I7(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)({});(0,U.useEffect)(()=>{i(Dq()),n(!0);let e=e=>{e.key===`wodwiki.quests.v1`&&i(Dq())};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let a=e=>{for(let t in r)if(r[t]?.[e])return!0;return!1};return{chapters:e.map(e=>{let t=(e.questIds??[]).map(e=>({id:e,isComplete:a(e)})),n=t.filter(e=>e.isComplete).length;return{chapter:e,completedCount:n,totalCount:t.length,isComplete:t.length>0&&n===t.length,quests:t}}),isHydrated:t}}function L7({activeIndex:e,onCommand:t,captions:n}){return(0,W.jsx)(`div`,{className:`relative h-full w-full`,"data-testid":`tour-captions`,children:n.map((n,r)=>(0,W.jsx)(`div`,{"data-scroll-pane":!0,className:`absolute inset-0 overflow-y-auto transition-opacity duration-300`,style:{opacity:+(r===e),pointerEvents:r===e?`auto`:`none`},"aria-hidden":r!==e,inert:r!==e,children:(0,W.jsx)(R7,{cap:n,onCommand:t})},n.id))})}function R7({cap:e,onCommand:t}){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`h3`,{className:`mb-3.5 xl:mb-5 text-[clamp(22px,2vw,32px)] font-extrabold leading-[1.12] tracking-[-0.03em]`,children:[(0,W.jsx)(`span`,{className:`mr-2 align-[0.2em] font-mono text-[0.5em] font-semibold tracking-[0.08em] text-muted-foreground/50`,children:e.num}),e.title]}),(0,W.jsx)(`p`,{className:`text-[14.5px] sm:text-base xl:text-[17px] leading-[1.7] xl:leading-[1.75] text-muted-foreground`,children:e.body}),e.bullets&&e.bullets.length>0&&(0,W.jsx)(`ul`,{className:`mt-3 space-y-1.5 text-sm xl:text-[15px] leading-relaxed text-foreground/85`,children:e.bullets.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`span`,{className:`text-primary font-bold`,children:`›`}),(0,W.jsx)(`span`,{children:e})]},t))}),e.foot&&(0,W.jsx)(`div`,{className:`mt-4 xl:mt-6 border-t border-border pt-3 xl:pt-4 font-mono text-[10px] xl:text-[11px] tracking-[0.06em] text-muted-foreground/60`,children:e.foot}),e.extra&&(0,W.jsx)(`div`,{className:`mt-3`,children:e.extra}),e.commands&&e.commands.length>0&&t&&(0,W.jsx)(`div`,{className:`mt-4 xl:mt-6 flex flex-wrap items-center gap-2`,"data-testid":`tour-caption-commands-${e.id}`,children:e.commands.map(n=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>t(e.id,n.key),className:`inline-flex items-center rounded-full border border-border px-3.5 py-1.5 text-[13px] font-medium text-foreground transition-colors hover:border-primary/40 hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`,"data-testid":`tour-caption-command-${e.id}-${n.key}`,children:n.label},n.key))}),e.actions&&e.actions.length>0&&(0,W.jsx)(`div`,{className:`mt-4 xl:mt-6 flex flex-wrap items-center gap-3`,children:e.actions.map((e,t)=>{let n=t===0;return(0,W.jsx)(_n,{to:e.href,onClick:()=>dq.record(e.event,e.data),"data-testid":e.testId,className:n?`inline-flex items-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90`:`text-sm text-primary underline-offset-2 hover:underline`,children:e.label},e.label)})})]})}function z7({visible:e,children:t}){return(0,W.jsx)(`div`,{className:`absolute inset-0 transition-opacity duration-500`,style:{opacity:+!!e,pointerEvents:e?`auto`:`none`},"aria-hidden":!e,inert:!e,children:t})}var B7=(0,U.forwardRef)(function({id:e,heightVh:t,header:n,stages:r,captions:i,onActiveStageChange:a,onViewportChange:o,onReachedChange:s,onCommand:c,editor:l},u){let d=(0,U.useRef)(null),f=(0,U.useRef)(null),[p,m]=(0,U.useState)(null),h=(0,U.useCallback)(e=>{f.current=e,m(e)},[]),{slice:g,subscribe:_,resync:v,runwayReached:y}=SQ(d,!1,r,e),b=H7(d);(0,U.useEffect)(()=>{o?.(b)},[b,o]),(0,U.useEffect)(()=>{s?.(y)},[y,s]);let[x,S]=(0,U.useState)(!1),C=V7(d);(0,U.useEffect)(()=>{(C||y)&&S(!0)},[C,y]);let w=g.stage?.screen??`editor`,T=(0,U.useRef)(null);return(0,U.useEffect)(()=>{x&&T.current!==g.stage?.id&&(T.current=g.stage?.id??null,g.stage?.id&&a?.(g.stage.id))},[g.stage?.id,a,x]),(0,U.useImperativeHandle)(u,()=>({scrollToStage:e=>{let t=d.current,n=r.find(t=>t.id===e);!t||!n||xQ(t,Math.min(n.range[0]+.02,n.range[1]-.005))},subscribe:_,resync:v}),[r,_,v]),(0,W.jsxs)(`section`,{id:`tour-section-${e}`,"data-testid":`tour-section-${e}`,children:[n,(0,W.jsx)(yQ,{trackRef:d,height:t,stages:r,activeIndex:g.index,segmentId:e,testId:`tour-runway`,pane:(0,W.jsx)(`div`,{ref:h,className:`absolute inset-0 flex flex-col justify-center`,children:(0,W.jsxs)(B0,{children:[(0,W.jsx)(U0,{ringKey:`editor.window`,el:p}),(0,W.jsx)(zq,{title:O$[w],className:`relative h-full max-h-[760px]`,children:(0,W.jsx)(vQ,{gateId:`${e}-pane`,segmentId:e,className:`relative h-full`,children:l&&(0,W.jsx)(z7,{visible:w===`editor`,children:(0,W.jsx)(f2,{doc:l.doc,onDocChange:l.onDocChange,onBlocksChange:l.onBlocksChange,onRun:l.onRun,theme:l.theme,withRingTargets:!0})})})}),(0,W.jsx)(W0,{target:g.ring?.key?{key:g.ring.key}:null,accent:g.stage.accent??D$.editor,canvasRef:f})]})}),captions:(0,W.jsx)(L7,{activeIndex:g.index,captions:i,onCommand:c})})]})});function V7(e){let[t,n]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let r=new IntersectionObserver(([e])=>{e.isIntersecting&&(n(!0),r.disconnect())},{threshold:.05});return r.observe(t),()=>r.disconnect()},[e]),t}function H7(e){let[t,n]=(0,U.useState)(()=>typeof IntersectionObserver>`u`);return(0,U.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let r=new IntersectionObserver(([e])=>n(e.isIntersecting),{threshold:.05});return r.observe(t),()=>r.disconnect()},[e]),t}var U7={basics:`wods/examples/syntax/single-movement.md`,protocols:`wods/examples/syntax/timers-rest.md`,structure:`wods/examples/syntax/groups-1.md`,"custom-metrics":`wods/syntax/custom-metrics-1.md`,dialects:`wods/examples/syntax/dialect-climb-bouldering.md`,complex:`wods/examples/syntax/complex-swimming.md`},W7={basics:{summary:`Statements and metrics — how a workout line reads, from movement names to reps, loads, and timed rests.`,bullets:["Freeform Markdown + fenced ```time blocks",`Single movements: 10 Pushups, 15 Air Squats`,`Inline resistance: 225lb, 100kg, 24kg`]},protocols:{summary:`Time-capped and paced protocols: AMRAP, EMOM, Tabata intervals, and required rest that paces the room.`,bullets:[`20:00 AMRAP (As Many Rounds As Possible)`,`(10) :60 EMOM (Every Minute on the Minute)`,`*:30 Rest (required, unskippable recovery)`]},structure:{summary:`Rounds, rep ladders, and nested grouping — how blocks compose into multi-part workout schemes.`,bullets:[`(3 Rounds) and (5 Sets) block repetition`,`Ladders & schemes: 21-15-9, 10-8-6-4-2`,`Section labels: (Warmup) and // Strength`]},"custom-metrics":{summary:`Capture typed data points right inline: effort intensity, heart rate, RPE, and custom JSON metrics.`,bullets:[`Inline JSON metrics: {"intensity": 80}`,`Capture prompts: :? time, ? reps, ?lb load`,`Session-level RPE & custom dimensions`]},dialects:{summary:`Dialect fences for specialized domains: workout, log, plan, and climbing session notes.`,bullets:["```time for workouts, ```log for recorded efforts","Sport dialect suffixes like ```log:climbing",`Discipline tags and session intent`]},complex:{summary:`Multi-set training sessions that chain intervals, strength, and conditioning into one complete program.`,bullets:[`Multi-set swimming and track intervals`,`Strength blocks paired with conditioned finishers`,`Full training session flow`]}},G7=[{id:`basics`,title:`Basics`,badge:`trophy`,questIds:[],sectionIds:[]},{id:`protocols`,title:`Protocols`,badge:`timer`,questIds:[],sectionIds:[]},{id:`structure`,title:`Structure`,badge:`dumbbell`,questIds:[],sectionIds:[]},{id:`custom-metrics`,title:`Custom Metrics`,badge:`trophy`,questIds:[],sectionIds:[]},{id:`dialects`,title:`Dialects`,badge:`trophy`,questIds:[],sectionIds:[]},{id:`complex`,title:`Complex Workouts`,badge:`dumbbell`,questIds:[],sectionIds:[]}];function K7({chapters:e=[],allQuests:t=[],theme:n,wodFiles:r={},onRun:i}){let a=(0,U.useMemo)(()=>{let t=(e??[]).filter(e=>e.id!==`home-tour`);return t.length>0?t:G7},[e]),o=Iq(`(prefers-reduced-motion: reduce)`),{markComplete:s}=Nq(`/`,t),{chapters:c}=I7(a),[l,u]=(0,U.useState)(()=>a[0]?.id??`basics`),[d,f]=(0,U.useState)(``),p=(0,U.useRef)([]),m=(0,U.useRef)(l);m.current=l;let h=(0,U.useMemo)(()=>Object.fromEntries(a.map(e=>[e.id,SV(U7[e.id]??``,r)])),[a,r]);(0,U.useEffect)(()=>{p.current=[],f(h[l]??``)},[l,h]);let g=(0,U.useCallback)(e=>{p.current=e},[]),_=(0,U.useCallback)(()=>{let e=m.current;s(`${e}-run`),i?.(e,p.current[0]??null,d)},[d,s,i]),v=(0,U.useMemo)(()=>a.map((e,t)=>{let n=Math.max(1,a.length);return{id:e.id,range:[t/n,(t+1)/n],screen:`editor`,accent:`hsl(var(--primary))`,label:e.title,source:h[e.id]}}),[a,h]),y=(0,U.useMemo)(()=>Object.fromEntries(c.map(e=>[e.chapter.id,e])),[c]),b=(0,U.useMemo)(()=>a.map((e,t)=>{let n=W7[e.id],r=y[e.id];return{id:e.id,num:`05${String.fromCharCode(97+t)}`,title:e.title,body:n?.summary??e.title,bullets:n?.bullets,accent:`hsl(var(--primary))`,extra:r&&(0,W.jsx)(`span`,{"data-testid":`chapter-picker-progress-${e.id}`,className:G(`font-mono text-[11px] font-semibold tabular-nums`,r.isComplete?`font-bold text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:r.isComplete?`done ✓`:`${r.completedCount}/${r.totalCount}`}),actions:[{label:`Read guide →`,href:k$[e.id]??`/page/guide-start`,event:fq.chapterGuideClicked,data:{chapter:e.id},testId:`chapter-picker-guide-${e.id}`}]}}),[a,y]);return(0,W.jsxs)(`section`,{id:`tour-chapter-picker`,"data-testid":`tour-chapter-picker`,className:`flex flex-col`,children:[(0,W.jsx)(T$,{index:`05`,before:`Learning with `,accentText:`Examples`,after:``,accent:`hsl(var(--primary))`,blurb:`Six chapters on the syntax, each with a runnable example and quests to earn. Scroll into each section to load its example code into the editor.`}),o?(0,W.jsx)(q7,{chapters:a,selectedId:l,onSelect:u,doc:d,onDocChange:f,theme:n,onBlocksChange:g,onRun:_,progressByChapter:y}):(0,W.jsx)(B7,{id:`learn`,heightVh:`600vh`,stages:v,captions:b,onActiveStageChange:u,editor:{doc:d,theme:n,onDocChange:f,onBlocksChange:g,onRun:_}})]})}function q7({chapters:e,selectedId:t,onSelect:n,doc:r,onDocChange:i,theme:a,onBlocksChange:o,onRun:s,progressByChapter:c}){return(0,W.jsx)(`div`,{className:`relative mx-auto w-full max-w-[1500px] 2xl:max-w-[1720px] px-6 py-8 lg:px-12 xl:px-16`,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-10 lg:flex-row lg:items-start lg:gap-12 xl:gap-16`,children:[(0,W.jsx)(`div`,{className:`w-full lg:w-[58%] xl:w-[60%] lg:sticky lg:top-[110px] z-10 flex-none`,children:(0,W.jsx)(`div`,{className:`h-[420px] sm:h-[480px] lg:h-[calc(100dvh-150px)] max-h-[700px] w-full rounded-2xl border border-border shadow-2xl overflow-hidden bg-background`,children:(0,W.jsx)(zq,{title:k$[t]?.split(`/`).pop()??`example.md`,subtitle:`Lesson: ${e.find(e=>e.id===t)?.title??t}`,className:`h-full`,children:(0,W.jsx)(f2,{doc:r,onDocChange:i,onBlocksChange:o,onRun:s,theme:a,withRingTargets:!1})})})}),(0,W.jsx)(`div`,{className:`w-full lg:w-[42%] xl:w-[40%] flex flex-col gap-16 lg:py-6`,"data-testid":`chapter-picker-list`,children:e.map((e,r)=>{let i=c[e.id],a=g$(e.badge),o=e.id===t,s=W7[e.id];return(0,W.jsxs)(`div`,{"data-testid":`chapter-picker-row-${e.id}`,className:G(`rounded-2xl border p-6 sm:p-8 transition-all duration-300 min-h-[340px] flex flex-col justify-between`,o?`border-primary bg-primary/5 ring-1 ring-primary/30 shadow-lg dark:bg-primary/10`:`border-border/70 bg-card hover:border-primary/40`),children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(`span`,{className:`font-mono text-xs font-bold uppercase tracking-wider text-primary`,children:[`Chapter 0`,r+1]}),a&&(0,W.jsx)(a,{className:`size-4 text-primary`})]}),(0,W.jsx)(`span`,{className:G(`font-mono text-xs font-semibold tabular-nums`,i?.isComplete?`text-emerald-600 dark:text-emerald-400 font-bold`:`text-muted-foreground`),children:i?.isComplete?`done ✓`:`${i?.completedCount??0}/${i?.totalCount??e.questIds.length}`})]}),(0,W.jsx)(`h3`,{className:`mt-3 text-2xl font-bold tracking-tight text-foreground sm:text-3xl`,children:e.title}),(0,W.jsx)(`p`,{className:`mt-3 text-sm sm:text-base leading-relaxed text-muted-foreground`,children:s?.summary??e.title}),s?.bullets&&(0,W.jsx)(`ul`,{className:`mt-4 space-y-1.5 text-xs sm:text-sm text-foreground/80 font-mono`,children:s.bullets.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`span`,{className:`text-primary font-bold`,children:`›`}),(0,W.jsx)(`span`,{children:e})]},t))})]}),(0,W.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center gap-3 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),"data-testid":`chapter-picker-select-${e.id}`,"aria-pressed":o,className:G(`inline-flex items-center gap-2 rounded-lg px-4 py-2 text-xs sm:text-sm font-semibold transition-colors shadow-xs`,o?`bg-primary text-primary-foreground hover:bg-primary/90`:`border border-border bg-background text-foreground hover:bg-muted`),children:[(0,W.jsx)(pn,{className:`size-3.5 fill-current`}),(0,W.jsx)(`span`,{children:o?`Loaded in editor`:`Load example`})]}),(0,W.jsxs)(_n,{to:k$[e.id]??`/page/guide-start`,"data-testid":`chapter-picker-guide-${e.id}`,"aria-label":`Read guide for ${e.title}`,onClick:()=>dq.record(fq.chapterGuideClicked,{chapter:e.id}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-background/80 px-3.5 py-2 text-xs sm:text-sm font-medium text-muted-foreground transition-colors hover:border-primary/50 hover:bg-background hover:text-primary`,children:[(0,W.jsx)(dr,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Read guide →`})]})]})]},e.id)})})]})})}function J7({chapters:e}){let t=()=>dq.record(fq.lessonStarted),n=()=>dq.record(fq.cheatsheetOpened),{chapters:r}=I7(e),i=r.filter(e=>e.chapter.id!==`home-tour`);return(0,W.jsxs)(`section`,{"data-testid":`tour-learn`,className:`mx-auto max-w-5xl px-6 py-16 border-b border-border/60`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 lg:flex-row lg:items-end lg:justify-between`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:`Learn the Language`}),(0,W.jsx)(`p`,{className:`mt-2 text-muted-foreground leading-relaxed max-w-xl`,children:`Six chapters, each with a runnable example and quests to earn — progress shows on the chapter cards above.`})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,W.jsx)(_n,{to:`/page/guide-start`,onClick:t,className:`inline-flex items-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90`,children:`Start Lesson 1`}),(0,W.jsx)(_n,{to:`/page/guide-start?h=reference`,onClick:n,className:`text-sm font-semibold text-primary underline-offset-2 hover:underline`,children:`Cheat sheet →`})]})]}),(0,W.jsx)(`div`,{className:`mt-8 flex flex-wrap items-center gap-2`,children:i.map(({chapter:e,completedCount:t,totalCount:n,isComplete:r})=>{let i=k$[e.id]??`/page/guide-start`,a=g$(e.badge);return(0,W.jsxs)(_n,{to:i,"data-testid":`learn-progress-chip-${e.id}`,className:G(`group inline-flex items-center gap-2 rounded-full border px-3 py-1.5 transition-colors hover:border-primary/40`,r?`border-emerald-500/30 bg-emerald-500/5`:`border-border bg-card`),children:[a&&(0,W.jsx)(a,{className:`size-3.5 text-muted-foreground`}),(0,W.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground`,children:e.title}),(0,W.jsx)(`span`,{className:G(`font-mono text-[10px] font-bold tabular-nums`,r?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:r?`done ✓`:`${t}/${n}`})]},e.id)})})]})}var Y7=J7;function X7(){let e=YO(),t=(0,U.useMemo)(()=>m1(e??{}),[e]),{theme:n}=Mi(),[r,i]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches);(0,U.useEffect)(()=>{if(n!==`system`)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>i(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[n]);let a=(0,U.useMemo)(()=>n===`system`?r?`vs-dark`:`vs`:n===`dark`?`vs-dark`:`vs`,[n,r]),o=qL(),s=f1.chapters,c=f1.quests,l=(0,U.useMemo)(()=>{let e={};for(let t of f1.quests)e[t.id]=t.label;for(let{page:t}of o)for(let n of t.quests)e[n.id]=n.label;return e},[o]),u=pq()?.track,{run:d,start:f,finalize:p,end:m}=Cq(),[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(0),[y,b]=(0,U.useState)(!1),x=(0,U.useCallback)(()=>{g(null),b(!1)},[]),S=(0,U.useCallback)(async(e,t,n)=>{if(t){u?.(fq.chapterExampleRun,{chapter:e});try{let r=await f(n,t,{pageTitle:`Syntax`,sectionTitle:`Chapter ${e}`});g(r.block),v(e=>e+1),b(!0)}catch(e){console.error(`[SyntaxView] failed to persist playground run note:`,e),x(),Q({title:`Could not start workout`,variant:`destructive`})}}},[x,f,u]),C=(0,U.useCallback)(async(e,t)=>{try{(t.logs??[]).length===0?(await m(),x()):await p(t,t.completed)}catch(e){throw console.error(`[SyntaxView] failed to save session:`,e),Q({title:`Session not saved`,variant:`destructive`}),e}},[x,m,p]);return(0,W.jsx)(B0,{children:(0,W.jsxs)(`div`,{"data-testid":`syntax-view`,children:[(0,W.jsx)(T$,{index:`S`,before:`Syntax `,accentText:`Learning with Examples`,after:``,accent:`hsl(var(--primary))`,blurb:`Six chapters on the syntax, each with a runnable example. Press run to start a timed workout from any chapter.`}),(0,W.jsx)(K7,{wodFiles:t,chapters:s,allQuests:c,theme:a,onRun:S}),(0,W.jsx)(Y7,{quests:c,chapters:s,questLabels:l}),(0,W.jsx)(M$,{}),(0,W.jsx)(Y0,{}),h&&y&&d&&(0,W.jsx)(OZ,{block:d.block,resultId:d.resultId,autoStart:!0,onClose:x,onCompleteWorkout:C},_)]})})}function Z7(){let e=Vn();return(0,W.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-6 p-8 text-center`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-center w-16 h-16 rounded-full bg-muted`,children:(0,W.jsx)(Ve,{className:`w-8 h-8 text-muted-foreground`})}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Page not found`}),(0,W.jsx)(`p`,{className:`text-muted-foreground max-w-sm`,children:`The page you are looking for does not exist or has been moved.`})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>e(`/`),className:`inline-flex items-center gap-2 px-4 py-2 rounded-md bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors`,children:[(0,W.jsx)(ge,{className:`w-4 h-4`}),`Go home`]})]})}var Q7=(e=0,t=0,n=0,r=0,i=0)=>[e,t,n,r,i],$7=(e,t)=>e.map((e,n)=>e+t[n]),e9=(e,t)=>e.map((e,n)=>e-t[n]),t9=(e,t)=>e.every((e,n)=>e===t[n]),n9=Q7(),r9=[`length`,`mass`,`time`,`count`,`energy`];function i9(e){if(t9(e,n9))return`dimensionless`;let t=[];return e.forEach((e,n)=>{e!==0&&t.push(`${r9[n]}${e===1?``:`^`+e}`)}),t.join(` · `)}var a9={m:{dim:Q7(1),toBase:1},km:{dim:Q7(1),toBase:1e3},mi:{dim:Q7(1),toBase:1609.34},kg:{dim:Q7(0,1),toBase:1},lb:{dim:Q7(0,1),toBase:.4536},ms:{dim:Q7(0,0,1),toBase:.001},s:{dim:Q7(0,0,1),toBase:1},min:{dim:Q7(0,0,1),toBase:60},h:{dim:Q7(0,0,1),toBase:3600},reps:{dim:Q7(0,0,0,1),toBase:1},cal:{dim:Q7(0,0,0,0,1),toBase:1},MET:{dim:n9,toBase:1},pts:{dim:n9,toBase:1},AU:{dim:n9,toBase:1},ratio:{dim:n9,toBase:1},"MET-min":{dim:Q7(0,0,1),toBase:60},"reps/min":{dim:e9(Q7(0,0,0,1),Q7(0,0,1)),toBase:1/60},"m/s":{dim:e9(Q7(1),Q7(0,0,1)),toBase:1},"min/km":{dim:e9(Q7(0,0,1),Q7(1)),toBase:60/1e3},"sec/km":{dim:e9(Q7(0,0,1),Q7(1)),toBase:1/1e3},"min/mi":{dim:e9(Q7(0,0,1),Q7(1)),toBase:60/1609.34},"km/h":{dim:e9(Q7(1),Q7(0,0,1)),toBase:1e3/3600},"kg/s":{dim:e9($7(Q7(0,1),Q7(0,0,0,1)),Q7(0,0,1)),toBase:1},"lb/s":{dim:e9($7(Q7(0,1),Q7(0,0,0,1)),Q7(0,0,1)),toBase:.4536}},o9=[{dim:e9(Q7(0,0,1),Q7(1)),name:`pace`,units:[`min/km`,`sec/km`,`min/mi`]},{dim:e9(Q7(1),Q7(0,0,1)),name:`speed`,units:[`m/s`,`km/h`]},{dim:$7(Q7(0,1),Q7(0,0,0,1)),name:`volume`,units:[`kg`,`lb`]},{dim:e9($7(Q7(0,1),Q7(0,0,0,1)),Q7(0,0,1)),name:`power`,units:[`kg/s`,`lb/s`]},{dim:Q7(0,0,1),name:`time`,units:[`min`,`s`,`MET-min`]},{dim:Q7(0,0,0,1),name:`count`,units:[`reps`]},{dim:Q7(1),name:`length`,units:[`m`,`km`,`mi`]},{dim:Q7(0,1),name:`mass`,units:[`kg`,`lb`]},{dim:n9,name:`dimensionless`,units:[`pts`,`AU`,`MET`]}],s9=e=>o9.find(t=>t9(t.dim,e)),c9=(e,t=n9)=>({v:e,dim:t}),l9={thruster:{met:6,discipline:`strength`,disciplineFactor:1.2,intensityTier:`high`,resolvedFrom:`bundled`},"pull-up":{met:5,discipline:`gymnastics`,disciplineFactor:1.2,intensityTier:`moderate`,resolvedFrom:`bundled`},run:{met:9.8,discipline:`running`,disciplineFactor:1,intensityTier:`high`,resolvedFrom:`bundled`},squat:{met:5,discipline:`strength`,disciplineFactor:1.2,intensityTier:`moderate`,resolvedFrom:`bundled`}},u9={met:Q7(0,0,0,0,0),disciplineFactor:n9},d9={easy:3,moderate:5,hard:7,"all-out":10,max:10},f9={effort:{fields:[`met`,`discipline`,`disciplineFactor`,`intensityTier`,`resolvedFrom`],get:(e,t)=>{let n=l9[e];if(!n)return t===`resolvedFrom`?c9(NaN):void 0;let r=n[t];return typeof r==`number`?{v:r,dim:u9[t]??n9}:void 0}},"rpe-labels":{fields:[`rpe`],get:e=>d9[e]===void 0?void 0:c9(d9[e])}},p9={min:e=>c9(Math.min(...e.map(e=>e.v)),e[0]?.dim??n9),max:e=>c9(Math.max(...e.map(e=>e.v)),e[0]?.dim??n9),abs:e=>c9(Math.abs(e[0].v),e[0].dim),round:e=>c9(e.length>1?+e[0].v.toFixed(e[1].v):Math.round(e[0].v),e[0].dim),floor:e=>c9(Math.floor(e[0].v),e[0].dim),ceil:e=>c9(Math.ceil(e[0].v),e[0].dim),clamp:e=>c9(Math.min(Math.max(e[0].v,e[1].v),e[2].v),e[0].dim),convert:e=>{let t=e[1].unit??``,n=a9[t];if(!n||!t9(n.dim,e[0].dim))throw Error(`convert: ${t} dimension ≠ value dimension`);return{v:e[0].v/n.toBase,dim:e[0].dim}}},m9=Object.keys(p9).concat([`has`,`lookup`]);function h9(e){let t=[],n=/\s*("(?:[^"]*)"|\d+\.?\d*|[a-zA-Z_][\w.-]*(?::[\w.:*!|,-]+(?:\{[^}]*\})?(?:\s+by\s+\{[^}]*\})?)?|[-+*/(),<>!=]=?|>=|<=|==)/y,r,i=0;for(;i<e.length;){if(n.lastIndex=i,r=n.exec(e),!r||r.index!==i){/\S/.test(e[i])&&t.push({t:`err`,s:e[i]}),i+=1;continue}i=n.lastIndex;let a=r[1];/^".*"$/.test(a)?t.push({t:`str`,s:a.slice(1,-1)}):/^\d/.test(a)?t.push({t:`num`,s:a}):/^[-+*/(),]$/.test(a)||[`>=`,`<=`,`==`,`!=`,`>`,`<`,`=`].includes(a)?t.push({t:`op`,s:a}):t.push({t:`id`,s:a})}return t}function g9(e){let t=0,n=()=>e[t];function r(i){let a,o=e[t++];if(!o)throw Error(`unexpected end`);if(o.t===`num`)a={k:`num`,v:parseFloat(o.s)};else if(o.t===`str`)a={k:`str`,s:o.s};else if(o.s===`-`)a={k:`neg`,e:r(70)};else if(o.s===`(`){if(a=r(0),n()?.s!==`)`)throw Error(`missing )`);t++}else if(o.t===`id`){if(n()?.s===`(`){t++;let e=[];if(n()?.s!==`)`)for(;;){if(e.push(r(0)),n()?.s===`,`){t++;continue}break}if(n()?.s!==`)`)throw Error(`missing )`);t++,a={k:`call`,f:o.s,args:e}}else a={k:`id`,s:o.s}}else throw Error(`unexpected "${o.s}"`);for(;;){let e=n()?.s,o=e===`*`||e===`/`?60:e===`+`||e===`-`?50:[`<`,`<=`,`>`,`>=`,`==`,`!=`].includes(e)?40:e===`and`?30:e===`or`?20:0;if(!o||o<i)break;t++;let s=r(o+1);a={k:`bin`,op:e,l:a,r:s}}return a}let i=r(0);if(t<e.length)throw Error(`trailing "${e[t].s}"`);return i}function _9(e,t,n){switch(e.k){case`num`:return c9(e.v);case`str`:return{v:NaN,dim:n9,unit:e.s};case`neg`:{let r=_9(e.e,t,n);return c9(-r.v,r.dim)}case`id`:{if(/^(sum|avg|max|min|count|last):/.test(e.s)){let t=n(e.s);if(!t)throw Error(`no data for ${e.s}`);return t}let r=t[e.s];if(r===void 0)throw Error(`unknown or absent: ${e.s}`);return r}case`bin`:{if(e.op===`and`)return c9(_9(e.l,t,n).v&&_9(e.r,t,n).v?1:0);if(e.op===`or`)return c9(_9(e.l,t,n).v||_9(e.r,t,n).v?1:0);let r=_9(e.l,t,n),i=_9(e.r,t,n);switch(e.op){case`+`:if(!t9(r.dim,i.dim))throw Error(`+ : ${i9(r.dim)} vs ${i9(i.dim)}`);return c9(r.v+i.v,r.dim);case`-`:if(!t9(r.dim,i.dim))throw Error(`- : ${i9(r.dim)} vs ${i9(i.dim)}`);return c9(r.v-i.v,r.dim);case`*`:return c9(r.v*i.v,$7(r.dim,i.dim));case`/`:return c9(r.v/i.v,e9(r.dim,i.dim));case`<`:return c9(+(r.v<i.v));case`<=`:return c9(+(r.v<=i.v));case`>`:return c9(+(r.v>i.v));case`>=`:return c9(+(r.v>=i.v));case`==`:return c9(+(r.v===i.v));case`!=`:return c9(r.v===i.v?0:1)}throw Error(e.op)}case`call`:{if(e.f===`has`){let r=e.args[0];return r.k===`id`?c9(t[r.s]!==void 0||/^(sum|avg|max|min|count|last):/.test(r.s)&&n(r.s)!==void 0?1:0):c9(0)}if(e.f===`lookup`){let[n,r,i]=e.args,a=n.k===`str`?n.s:``,o=r.k===`str`?r.s:r.k===`id`?String(t[r.s]?.v??r.s):``,s=i.k===`str`?i.s:``,c=f9[a];if(!c)throw Error(`unknown table "${a}"`);if(!c.fields.includes(s))throw Error(`table "${a}" has no field "${s}"`);if(a===`effort`&&s===`resolvedFrom`)return c9(+!!l9[o]);let l=c.get(o,s);if(!l)throw Error(`lookup miss: ${a}/${o}/${s}`);return l}let r=p9[e.f];if(!r)throw Error(`unknown function ${e.f}`);return r(e.args.map((r,i)=>e.f===`convert`&&i>0&&r.k===`id`?{v:NaN,dim:n9,unit:r.s}:_9(r,t,n)))}}}var v9=[{effort:`thruster`,label:`hard`,reps:21,resistanceKg:43,elapsedMs:95e3},{effort:`pull-up`,reps:21,elapsedMs:6e4},{effort:`thruster`,reps:15,resistanceKg:43,elapsedMs:7e4},{effort:`pull-up`,reps:15,elapsedMs:5e4},{effort:`sled-push`,reps:9,resistanceKg:43,elapsedMs:45e3},{effort:`pull-up`,reps:9,elapsedMs:3e4}],Lee=[420,0,380,510,0,290,610,450,0,520,340,0,480,390,560,0,410,470,0,530,360,440,0,500,580,320,0,460];function Ree(e){let t=l9[e.effort]?.met??4,n=!l9[e.effort];return{segmentVolume:e.reps&&e.resistanceKg?c9(e.reps*e.resistanceKg,$7(Q7(0,1),Q7(0,0,0,1))):void 0,metMinutes:c9(t*(e.elapsedMs/6e4),Q7(0,0,1)),metMinutesEstimated:n?c9(1):void 0,effortRpe:e.label?c9(d9[e.label]??0):void 0}}function zee(e){let t={name:``,exprSrc:``,alternates:[],library:!1,bindings:[]};try{let n=e.trim(),r=/\s+when\s+/.exec(n);r&&(t.whenSrc=n.slice(r.index+r[0].length).trim(),n=n.slice(0,r.index));let i=/\s+where\s+/.exec(n);if(i){let e=n.slice(i.index+i[0].length).trim();n=n.slice(0,i.index);for(let n of e.split(/,\s*(?=[a-zA-Z_][\w]*\s*=)/)){let e=n.indexOf(`=`);e>0&&t.bindings.push({name:n.slice(0,e).trim(),src:n.slice(e+1).trim()})}}let a=/\s*->\s*/.exec(n);a&&(t.unit=n.slice(a.index+a[0].length).trim().replace(/\s+(key|grouped).*$/,``),n=n.slice(0,a.index)),/\(library\)/.test(n)&&(t.library=!0,n=n.replace(`(library)`,``));let o=n.indexOf(`=`);if(o<0)throw Error(`expected name = expression`);t.name=n.slice(0,o).trim();let s=n.slice(o+1).trim().split(`|`).map(e=>e.trim());return t.exprSrc=s[0],t.alternates=s.slice(1).map(e=>({src:e.replace(/\s*estimated\s*$/,``),estimated:/\bestimated\b/.test(e)})),t}catch(e){return t.error=e instanceof Error?e.message:String(e),t}}function y9(e,t,n,r){let i=Ree(e);return{elapsed:c9(e.elapsedMs/1e3,Q7(0,0,1)),reps:e.reps===void 0?void 0:c9(e.reps,Q7(0,0,0,1)),resistance:e.resistanceKg===void 0?void 0:c9(e.resistanceKg,Q7(0,1)),distance:e.distanceM===void 0?void 0:c9(e.distanceM,Q7(1)),effort:c9(NaN),effortLabel:e.label?c9(NaN):void 0,segmentVolume:i.segmentVolume,metMinutes:i.metMinutes,effortRpe:i.effortRpe,sessionRpe:n===void 0?void 0:c9(n),"profile.vo2max":r===void 0?void 0:c9(r),...t}}var b9=e=>e.effort;function x9(e,t,n,r){let i=zee(e),a=[];if(i.error)return{calc:i,diagnostics:[i.error]};let o={calc:i,diagnostics:a},s=e=>e instanceof Error?e.message:String(e);if(t!==`store`){try{g9(h9(i.exprSrc))}catch(e){a.push(`expression: ${s(e)}`)}for(let e of i.bindings)for(let t of e.src.split(`|`))try{g9(h9(t.replace(/\s*estimated\s*$/,``)))}catch(t){a.push(`${e.name}: ${s(t)}`)}if(i.whenSrc)try{g9(h9(i.whenSrc))}catch(e){a.push(`when: ${s(e)}`)}}let c=v9,l=(e,t=c.length)=>{let i=/^(sum|avg|max|min|count|last):([\w.]+)/.exec(e);if(!i)return;let[,a,o]=i,s=c.slice(0,t),l=[];for(let e of s){let t=y9(e,{},n,r)[o];t!==void 0&&!Number.isNaN(t.v)&&l.push(t)}if(o===`sessionLoad`&&e.includes(`by {day}`))return c9(NaN);if(!l.length)return;let u=l[0].dim,d=l.map(e=>e.v);if(a===`sum`)return c9(d.reduce((e,t)=>e+t,0),u);if(a===`avg`)return c9(d.reduce((e,t)=>e+t,0)/d.length,u);if(a===`max`)return c9(Math.max(...d),u);if(a===`min`)return c9(Math.min(...d),u);if(a===`count`)return c9(d.length,Q7(0,0,0,1));if(a===`last`)return l[l.length-1]},u=(e,t,n)=>{let r={...t};for(let e of i.bindings){let t=e.src.split(`|`).map(e=>e.replace(/\s*estimated\s*$/,``).trim()),i;for(let e of t)try{i=d(e,r,n);break}catch{}if(i===void 0)throw Error(`${e.name}: no applicable variant`);r[e.name]=i}return d(e,r,n)},d=(e,t,n)=>_9(g9(h9(e)),t,e=>l(e,n));try{if(t===`segment`){let e=[],t;c.forEach((a,o)=>{try{let s=y9(a,{},n,r);if(s.effort=void 0,i.whenSrc&&!d(i.whenSrc,s,o+1).v){e.push(null);return}let c=i.exprSrc.replace(/lookup\("effort",\s*effort\s*,/g,`lookup("effort", "${b9(a)}",`).replace(/lookup\("rpe-labels",\s*effortLabel\s*,/g,`lookup("rpe-labels", "${a.label??``}",`),l=u(c,s,o+1);t||=l.dim;let f=i.unit&&i.unit!==`auto`?` ${i.unit}`:t?` [${i9(l.dim)}]`:``;e.push(`${Math.round(l.v*100)/100}${f}`)}catch(t){e.push(`∅ ${s(t)}`)}}),o.perSegment=e,o.dim=t}else if(t===`workout`){let e=[],t;for(let a=1;a<=c.length;a++)try{let s=c[a-1],l=y9(s,{"session.duration":c9(c.slice(0,a).reduce((e,t)=>e+t.elapsedMs,0)/1e3,Q7(0,0,1))},n,r);if(i.whenSrc&&!d(i.whenSrc,l,a).v){e.push(null);continue}let f=i.exprSrc.replace(/lookup\("effort",\s*effort\s*,/g,`lookup("effort", "${b9(s)}",`),p,m=`primary`;try{p=u(f,l,a)}catch(e){for(let e of i.alternates)try{p=u(e.src,l,a),m=e.estimated?`estimated`:`alternate`;break}catch{}if(p===void 0)throw e}t=p.dim,e.push(`${Math.round(p.v*100)/100}${i.unit&&i.unit!==`auto`?` `+i.unit:``}${m===`estimated`?` (est.)`:``}`),o.variantUsed=m}catch(t){e.push(`∅ ${s(t)}`)}o.running=e,o.dim=t}else{let e=Lee,t=(e,t,n)=>e.map((r,i)=>i+1>=t?n(e.slice(i+1-t,i+1)):NaN),n=e=>e.reduce((e,t)=>e+t,0)/e.length,r=e=>{let t=n(e);return Math.sqrt(n(e.map(e=>(e-t)**2)))},a=i.name,s=[];if(a.includes(`acwr`)){let r=t(e,7,n),i=t(e,28,n);s=e.map((e,t)=>r[t]/i[t])}else if(a.includes(`monotony`)){let i=t(e,7,n),a=t(e,7,r);s=e.map((e,t)=>i[t]/a[t])}else if(a.includes(`strain`)){let i=t(e,7,n),a=t(e,7,r),o=t(e,7,e=>e.reduce((e,t)=>e+t,0));s=e.map((e,t)=>i[t]/a[t]*o[t])}else s=t(e,7,n);o.perSegment=s.slice(-7).map(e=>Number.isNaN(e)?null:String(Math.round(e*100)/100)),o.dim=n9}}catch(e){a.push(s(e))}if(o.dim&&i.unit&&i.unit!==`auto`){let e=a9[i.unit];e?!t9(e.dim,o.dim)&&!t9(e.dim,n9)&&a.push(`unit "${i.unit}" is ${i9(e.dim)} but expression computes ${i9(o.dim)}`):a.push(`unknown unit "${i.unit}"`)}return o}function S9(e,t){let n=/([a-zA-Z_][\w.:-]*|"[\w-]*|)$/.exec(e)[1],r=e.length-n.length,i=e.slice(0,r),a=[],o=(e,t,n)=>a.push({label:e,insert:t,detail:n}),s=/lookup\("([\w-]*)",?\s*("[\w-]*",?\s*)?"?([\w-]*)$/.exec(e);if(s){if(s[2]===void 0&&!e.endsWith(`"`))f9&&Object.keys(f9).forEach(e=>o(e,`"${e}"`,`lookup table`));else{let t=s[1];(e.split(`"`).length<=5&&s[3]!==void 0||/,\s*"[\w-]*$/.test(e))&&(f9[t]?.fields??[]).forEach(e=>o(e,`"${e}"`,`${t} field`)),t===`effort`&&/,\s*$/.test(e)&&Object.keys(l9).concat([`effort`]).forEach(e=>o(e,e===`effort`?`effort`:`"${e}"`,`key`))}return{items:a.filter(e=>e.label.startsWith(n.replace(/"/g,``))),from:r}}return/^(sum|avg|max|min|count|last):[\w.]*$/.test(n)?((t===`segment`?[]:[`reps`,`distance`,`segmentVolume`,`metMinutes`,`elapsed`,`effortRpe`,`sessionLoad`]).forEach(e=>o(e,e,`metric key`)),{items:a.filter(e=>e.label.startsWith(n.split(`:`)[1]??``)),from:r+n.indexOf(`:`)+1}):/->\s*[\w/]*$/.test(i+n)?(Object.keys(a9).forEach(e=>o(e,e,`unit`)),{items:a.filter(e=>e.label.startsWith(n)),from:r}):((t===`segment`?[`elapsed`,`reps`,`resistance`,`distance`,`effort`,`effortLabel`,`segmentVolume`,`metMinutes`,`effortRpe`,`sessionRpe`]:[`sessionRpe`,`session.duration`,`profile.vo2max`]).forEach(e=>o(e,e,t===`segment`?`segment metric / context`:`context node`)),m9.forEach(e=>o(`${e}()`,`${e}()`,`function`)),[`sum:`,`avg:`,`max:`,`count:`,`last:`].forEach(e=>o(`${e}{}`,e,`WQL atom`)),i.includes(`=`)&&o(`estimated`,`estimated`,`variant origin`),[`when `,`-> `,`where `,`| `,` key `,`(library)`].forEach(e=>o(e.trim(),e,`clause`)),{items:a.filter(e=>e.label.startsWith(n)).slice(0,9),from:r})}var C9={background:`#18181b`,border:`1px solid #3f3f46`,borderRadius:8,padding:12},w9={fontFamily:`ui-monospace, monospace`,fontSize:13};function T9({r:e}){let t=s9(e.dim??n9);return(0,W.jsxs)(`div`,{style:{marginTop:8,fontSize:12},children:[e.dim&&(0,W.jsxs)(`div`,{style:{color:`#a1a1aa`,marginBottom:4},children:[`computes `,(0,W.jsx)(`b`,{style:{color:`#e4e4e7`},children:i9(e.dim)}),t&&t.name!==`dimensionless`&&(0,W.jsxs)(W.Fragment,{children:[` → `,(0,W.jsx)(`span`,{style:{color:`#c084fc`},children:t.name}),` — units: `,t.units.map(t=>(0,W.jsx)(Bee,{u:t,active:e.calc.unit===t},t))]})]}),e.diagnostics.map((e,t)=>(0,W.jsxs)(`div`,{style:{color:`#f87171`},children:[`⚠ `,e]},t)),!e.diagnostics.length&&(0,W.jsxs)(`div`,{style:{color:`#34d399`},children:[`✓ valid`,e.variantUsed===`estimated`?` — estimated variant in use`:``]})]})}var Bee=({u:e,active:t})=>(0,W.jsx)(`span`,{style:{border:`1px solid ${t?`#c084fc`:`#52525b`}`,borderRadius:4,padding:`0 5px`,marginRight:4,color:t?`#c084fc`:`#a1a1aa`},children:e});function Vee({r:e,scope:t,sessionRpe:n,vo2max:r}){return(0,W.jsxs)(`div`,{style:{...C9,minWidth:320},children:[(0,W.jsxs)(`div`,{style:{fontSize:11,color:`#71717a`,marginBottom:6},children:[`LIVE PREVIEW — `,t===`store`?`last 7 of 28 days (fixture)`:`Fran, 2026-07-28 (fixture)${r?` · VO₂max ${r}`:` · VO₂max unknown`}${n?` · sRPE ${n}`:``}`]}),t===`segment`&&v9.map((t,n)=>(0,W.jsxs)(`div`,{style:{...w9,display:`flex`,justifyContent:`space-between`,color:`#d4d4d8`},children:[(0,W.jsxs)(`span`,{style:{color:`#71717a`},children:[t.effort,t.reps?` ×${t.reps}`:``,t.resistanceKg?` ${t.resistanceKg}kg`:``]}),(0,W.jsx)(`span`,{style:{color:e.perSegment?.[n]?.startsWith(`∅`)?`#f87171`:`#7dd3fc`},children:e.perSegment?.[n]??`—`})]},n)),t===`workout`&&v9.map((t,n)=>(0,W.jsxs)(`div`,{style:{...w9,display:`flex`,justifyContent:`space-between`,color:`#d4d4d8`},children:[(0,W.jsxs)(`span`,{style:{color:`#71717a`},children:[`after line `,n+1]}),(0,W.jsx)(`span`,{style:{color:e.running?.[n]?.startsWith(`∅`)?`#f87171`:`#7dd3fc`},children:e.running?.[n]??`—`})]},n)),t===`store`&&(e.perSegment??[]).map((e,t)=>(0,W.jsxs)(`div`,{style:{...w9,display:`flex`,justifyContent:`space-between`,color:`#d4d4d8`},children:[(0,W.jsxs)(`span`,{style:{color:`#71717a`},children:[`D-`,6-t]}),(0,W.jsx)(`span`,{style:{color:`#7dd3fc`},children:e??`—`})]},t))]})}function Hee({scope:e,onSrc:t}){let[n,r]=(0,U.useState)(`power`),[i,a]=(0,U.useState)(`reps * resistance / convert(elapsed, s)`),[o,s]=(0,U.useState)(`kg/s`),[c,l]=(0,U.useState)(`has(reps) and has(resistance) and elapsed > 0`),[u,d]=(0,U.useState)(null),f=`${n} = ${i}${o?` -> ${o}`:``}${c?` when ${c}`:``}`,p=(0,U.useMemo)(()=>x9(f,e,void 0,void 0),[f,e]);(0,U.useEffect)(()=>t(f),[f]);let m=[{id:`name`,label:`name`,value:n,set:r,hint:`calc id`},{id:`expr`,label:`=`,value:i,set:a,hint:`expression — metrics, lookups, functions`},{id:`unit`,label:`->`,value:o,set:s,hint:`output unit (auto allowed)`},{id:`when`,label:`when`,value:c,set:l,hint:`applicability predicate`}];return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`,alignItems:`center`},children:m.map(e=>(0,W.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:4},children:[(0,W.jsx)(`span`,{style:{color:`#71717a`,fontSize:12},children:e.label}),(0,W.jsx)(`button`,{onClick:()=>d(u===e.id?null:e.id),style:{...w9,fontSize:12,background:u===e.id?`#3b0764`:`#27272a`,border:`1px solid ${u===e.id?`#c084fc`:`#3f3f46`}`,borderRadius:6,color:`#e4e4e7`,padding:`4px 10px`,cursor:`pointer`,maxWidth:340,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.value||(0,W.jsx)(`span`,{style:{color:`#52525b`},children:`∅`})})]},e.id))}),u&&(0,W.jsxs)(`div`,{style:{...C9,marginTop:8},children:[(0,W.jsx)(`div`,{style:{fontSize:11,color:`#71717a`,marginBottom:4},children:m.find(e=>e.id===u)?.hint}),(0,W.jsx)(`input`,{autoFocus:!0,value:m.find(e=>e.id===u).value,onChange:e=>m.find(e=>e.id===u).set(e.target.value),style:{...w9,width:`100%`,background:`#09090b`,border:`1px solid #3f3f46`,borderRadius:6,color:`#e4e4e7`,padding:`4px 8px`,outline:`none`}}),(0,W.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`,marginTop:6},children:S9(m.find(e=>e.id===u).value,e).items.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>m.find(e=>e.id===u).set(e.insert),style:{...w9,fontSize:12,background:`#27272a`,border:`1px solid #3f3f46`,borderRadius:5,color:`#7dd3fc`,padding:`2px 8px`,cursor:`pointer`},children:e.label},t))})]}),(0,W.jsx)(`div`,{style:{...w9,marginTop:8,color:`#52525b`,fontSize:12},children:f}),(0,W.jsx)(T9,{r:p})]})}function Uee({scope:e,onSrc:t}){let[n,r]=(0,U.useState)(`power`),[i,a]=(0,U.useState)([`reps`,`*`,`resistance`,`/`,`convert(elapsed, s)`]),o=[{group:`metrics`,items:e===`segment`?[`elapsed`,`reps`,`resistance`,`distance`]:[`sum:reps{}`,`sum:distance{}`,`sum:metMinutes{}`,`sum:elapsed{}`]},{group:`functions`,items:[`convert(·, min)`,`convert(·, km)`,`convert(·, s)`,`min(·, 100)`,`round(·)`]},{group:`lookups`,items:[`lookup("effort", effort, "met")`,`lookup("effort", effort, "disciplineFactor")`,`lookup("rpe-labels", effortLabel, "rpe")`]},{group:`operators`,items:[`+`,`-`,`*`,`/`,`(`,`)`]}],s=`${n} = ${i.join(` `)} -> auto`,c=(0,U.useMemo)(()=>x9(s,e,void 0,void 0),[s,e]);(0,U.useEffect)(()=>t(s),[s]);let l=s9(c.dim??n9);return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{style:{display:`flex`,gap:8,marginBottom:8,alignItems:`center`},children:[(0,W.jsx)(`span`,{style:{fontSize:12,color:`#71717a`},children:`name`}),(0,W.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),style:{...w9,background:`#09090b`,border:`1px solid #3f3f46`,borderRadius:6,color:`#e4e4e7`,padding:`3px 8px`}})]}),o.map(e=>(0,W.jsxs)(`div`,{style:{marginBottom:6},children:[(0,W.jsx)(`div`,{style:{fontSize:11,color:`#71717a`,marginBottom:3},children:e.group}),(0,W.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`},children:e.items.map(e=>(0,W.jsx)(`button`,{onClick:()=>a(t=>[...t,e]),style:{...w9,fontSize:12,background:`#27272a`,border:`1px solid #3f3f46`,borderRadius:5,color:`#7dd3fc`,padding:`2px 8px`,cursor:`pointer`},children:e},e))})]},e.group)),(0,W.jsxs)(`div`,{style:{...C9,...w9,marginTop:8,color:`#d4d4d8`,minHeight:34},children:[i.map((e,t)=>(0,W.jsx)(`span`,{onClick:()=>a(e=>e.filter((e,n)=>n!==t)),title:`click to remove`,style:{cursor:`pointer`,background:`#27272a`,borderRadius:4,padding:`1px 6px`,marginRight:4,display:`inline-block`},children:e},t)),!i.length&&(0,W.jsx)(`span`,{style:{color:`#52525b`},children:`click palette items to build the formula…`})]}),(0,W.jsxs)(`div`,{style:{fontSize:12,color:`#71717a`,marginTop:6},children:[`unit: `,(0,W.jsx)(`b`,{style:{color:`#c084fc`},children:l?l.units.join(` / `):`—`}),` (derived)`]}),(0,W.jsx)(`div`,{style:{...w9,marginTop:6,color:`#52525b`,fontSize:12},children:s}),(0,W.jsx)(T9,{r:c})]})}var E9={segment:`power = reps * resistance / convert(elapsed, s) -> kg/s when has(reps) and has(resistance) and elapsed > 0`,workout:`sessionLoad = round(rpe * convert(session.duration, min)) -> AU where rpe = sessionRpe | max:effortRpe{} | 5 estimated`,store:`acwr = windowMean(daily, 7d) / windowMean(daily, 28d) -> ratio`};function Wee(){let[e,t]=cn(),n=e.get(`v`)??`text`,[r,i]=(0,U.useState)(`segment`),[a,o]=(0,U.useState)(void 0),[s,c]=(0,U.useState)(void 0),[l,u]=(0,U.useState)(E9.segment),[d,f]=(0,U.useState)(``),p=n===`text`?l:d||l,m=(0,U.useMemo)(()=>x9(p,r,a,s),[p,r,a,s]),h=[[`text`,`A · text + completion`],[`slots`,`B · token slots`],[`guided`,`C · guided builder`]];return(0,W.jsxs)(`div`,{style:{background:`#09090b`,minHeight:`100vh`,color:`#e4e4e7`,padding:24,fontFamily:`system-ui`},children:[(0,W.jsxs)(`div`,{style:{maxWidth:1100,margin:`0 auto`},children:[(0,W.jsx)(`div`,{style:{fontSize:11,color:`#f59e0b`,marginBottom:4},children:`PROTOTYPE — throwaway · issue #863`}),(0,W.jsx)(`h1`,{style:{fontSize:20,fontWeight:700,marginBottom:12},children:`Calc-line guided authoring`}),(0,W.jsxs)(`div`,{style:{display:`flex`,gap:12,marginBottom:16,alignItems:`center`,fontSize:13},children:[[`segment`,`workout`,`store`].map(e=>(0,W.jsxs)(`button`,{onClick:()=>{i(e),u(E9[e])},style:{padding:`3px 12px`,borderRadius:6,border:`1px solid ${r===e?`#7dd3fc`:`#3f3f46`}`,background:`none`,color:r===e?`#7dd3fc`:`#a1a1aa`,cursor:`pointer`},children:[e,` scope`]},e)),(0,W.jsx)(`span`,{style:{color:`#3f3f46`},children:`|`}),(0,W.jsxs)(`label`,{style:{color:`#71717a`},children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:!!a,onChange:e=>o(e.target.checked?8:void 0)}),` sRPE captured`]}),(0,W.jsxs)(`label`,{style:{color:`#71717a`},children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:!!s,onChange:e=>c(e.target.checked?42:void 0)}),` VO₂max known`]})]}),(0,W.jsxs)(`div`,{style:{display:`flex`,gap:16,alignItems:`flex-start`},children:[(0,W.jsxs)(`div`,{style:{flex:1},children:[n===`text`&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),style:{...C9,...w9,width:`100%`,color:`#e4e4e7`,outline:`none`},placeholder:`name = expression -> unit when predicate`}),(0,W.jsx)(Gee,{src:l,scope:r,onApply:e=>u(e)}),(0,W.jsx)(T9,{r:m})]}),n===`slots`&&(0,W.jsx)(Hee,{scope:r,onSrc:f}),n===`guided`&&(0,W.jsx)(Uee,{scope:r,onSrc:f})]}),(0,W.jsx)(Vee,{r:m,scope:r,sessionRpe:a,vo2max:s})]})]}),(0,W.jsx)(`div`,{style:{position:`fixed`,bottom:16,left:`50%`,transform:`translateX(-50%)`,display:`flex`,gap:6,background:`#18181b`,border:`1px solid #3f3f46`,borderRadius:10,padding:6},children:h.map(([e,r])=>(0,W.jsx)(`button`,{onClick:()=>t({v:e}),style:{padding:`4px 14px`,borderRadius:7,border:`none`,background:n===e?`#7dd3fc`:`transparent`,color:n===e?`#09090b`:`#a1a1aa`,cursor:`pointer`,fontSize:13},children:r},e))})]})}function Gee({src:e,scope:t,onApply:n}){let r=(0,U.useMemo)(()=>S9(e,t),[e,t]);return r.items.length?(0,W.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`,marginTop:6},children:r.items.map((t,i)=>(0,W.jsxs)(`button`,{onClick:()=>n(e.slice(0,r.from)+t.insert),style:{...w9,fontSize:12,background:`#27272a`,border:`1px solid #3f3f46`,borderRadius:5,color:`#7dd3fc`,padding:`2px 8px`,cursor:`pointer`},children:[t.label,` `,(0,W.jsx)(`span`,{style:{color:`#52525b`},children:t.detail})]},i))}):null}var D9=`01a09d45-885a-738d-ab1e-be31d44fe919`,Kee=`:session{result:${D9}}`,O9=`## Morning session
476
+ `));e(SN(n))},[e]),m=(0,U.useCallback)(t=>{if(/^https?:\/\//i.test(t)){window.open(t,`_blank`,`noopener,noreferrer`);return}e(t)},[e]);return(0,W.jsxs)(N7,{actionsSlot:(0,W.jsxs)(`div`,{className:`flex items-center gap-3 rounded-2xl border border-zinc-200 bg-zinc-50/80 px-4 py-3 dark:border-zinc-700 dark:bg-zinc-900/70`,children:[(0,W.jsx)(ae,{className:`size-4 text-zinc-500`,"aria-hidden":`true`}),(0,W.jsx)(e3,{checked:l,onChange:e=>n(e?`dark`:`light`),"aria-label":`Toggle dark mode`}),(0,W.jsx)(Pe,{className:`size-4 text-zinc-500`,"aria-hidden":`true`})]}),heroSlot:(0,W.jsx)(N6,{config:P7,onAction:f}),children:[(0,W.jsxs)(`section`,{ref:r,id:`workout-widget-surface`,className:`mt-8 grid grid-cols-1 gap-4 xl:grid-cols-3`,children:[(0,W.jsx)(`div`,{className:`xl:col-span-2`,children:(0,W.jsx)(P6,{config:s,isDarkMode:l,onRun:p})}),(0,W.jsx)(`div`,{className:`space-y-4`,children:c.map(e=>(0,W.jsx)(F6,{config:e,onOpenDocs:m},e.title))})]}),(0,W.jsx)(d2,{})]})}function I7(e){let[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)({});(0,U.useEffect)(()=>{i(Dq()),n(!0);let e=e=>{e.key===`wodwiki.quests.v1`&&i(Dq())};return window.addEventListener(`storage`,e),()=>window.removeEventListener(`storage`,e)},[]);let a=e=>{for(let t in r)if(r[t]?.[e])return!0;return!1};return{chapters:e.map(e=>{let t=(e.questIds??[]).map(e=>({id:e,isComplete:a(e)})),n=t.filter(e=>e.isComplete).length;return{chapter:e,completedCount:n,totalCount:t.length,isComplete:t.length>0&&n===t.length,quests:t}}),isHydrated:t}}function L7({activeIndex:e,onCommand:t,captions:n}){return(0,W.jsx)(`div`,{className:`relative h-full w-full`,"data-testid":`tour-captions`,children:n.map((n,r)=>(0,W.jsx)(`div`,{"data-scroll-pane":!0,className:`absolute inset-0 overflow-y-auto transition-opacity duration-300`,style:{opacity:+(r===e),pointerEvents:r===e?`auto`:`none`},"aria-hidden":r!==e,inert:r!==e,children:(0,W.jsx)(R7,{cap:n,onCommand:t})},n.id))})}function R7({cap:e,onCommand:t}){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`h3`,{className:`mb-3.5 xl:mb-5 text-[clamp(22px,2vw,32px)] font-extrabold leading-[1.12] tracking-[-0.03em]`,children:[(0,W.jsx)(`span`,{className:`mr-2 align-[0.2em] font-mono text-[0.5em] font-semibold tracking-[0.08em] text-muted-foreground/50`,children:e.num}),e.title]}),(0,W.jsx)(`p`,{className:`text-[14.5px] sm:text-base xl:text-[17px] leading-[1.7] xl:leading-[1.75] text-muted-foreground`,children:e.body}),e.bullets&&e.bullets.length>0&&(0,W.jsx)(`ul`,{className:`mt-3 space-y-1.5 text-sm xl:text-[15px] leading-relaxed text-foreground/85`,children:e.bullets.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`span`,{className:`text-primary font-bold`,children:`›`}),(0,W.jsx)(`span`,{children:e})]},t))}),e.foot&&(0,W.jsx)(`div`,{className:`mt-4 xl:mt-6 border-t border-border pt-3 xl:pt-4 font-mono text-[10px] xl:text-[11px] tracking-[0.06em] text-muted-foreground/60`,children:e.foot}),e.extra&&(0,W.jsx)(`div`,{className:`mt-3`,children:e.extra}),e.commands&&e.commands.length>0&&t&&(0,W.jsx)(`div`,{className:`mt-4 xl:mt-6 flex flex-wrap items-center gap-2`,"data-testid":`tour-caption-commands-${e.id}`,children:e.commands.map(n=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>t(e.id,n.key),className:`inline-flex items-center rounded-full border border-border px-3.5 py-1.5 text-[13px] font-medium text-foreground transition-colors hover:border-primary/40 hover:bg-accent focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-primary`,"data-testid":`tour-caption-command-${e.id}-${n.key}`,children:n.label},n.key))}),e.actions&&e.actions.length>0&&(0,W.jsx)(`div`,{className:`mt-4 xl:mt-6 flex flex-wrap items-center gap-3`,children:e.actions.map((e,t)=>{let n=t===0;return(0,W.jsx)(_n,{to:e.href,onClick:()=>dq.record(e.event,e.data),"data-testid":e.testId,className:n?`inline-flex items-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90`:`text-sm text-primary underline-offset-2 hover:underline`,children:e.label},e.label)})})]})}function z7({visible:e,children:t}){return(0,W.jsx)(`div`,{className:`absolute inset-0 transition-opacity duration-500`,style:{opacity:+!!e,pointerEvents:e?`auto`:`none`},"aria-hidden":!e,inert:!e,children:t})}var B7=(0,U.forwardRef)(function({id:e,heightVh:t,header:n,stages:r,captions:i,onActiveStageChange:a,onViewportChange:o,onReachedChange:s,onCommand:c,editor:l},u){let d=(0,U.useRef)(null),f=(0,U.useRef)(null),[p,m]=(0,U.useState)(null),h=(0,U.useCallback)(e=>{f.current=e,m(e)},[]),{slice:g,subscribe:_,resync:v,runwayReached:y}=SQ(d,!1,r,e),b=H7(d);(0,U.useEffect)(()=>{o?.(b)},[b,o]),(0,U.useEffect)(()=>{s?.(y)},[y,s]);let[x,S]=(0,U.useState)(!1),C=V7(d);(0,U.useEffect)(()=>{(C||y)&&S(!0)},[C,y]);let w=g.stage?.screen??`editor`,T=(0,U.useRef)(null);return(0,U.useEffect)(()=>{x&&T.current!==g.stage?.id&&(T.current=g.stage?.id??null,g.stage?.id&&a?.(g.stage.id))},[g.stage?.id,a,x]),(0,U.useImperativeHandle)(u,()=>({scrollToStage:e=>{let t=d.current,n=r.find(t=>t.id===e);!t||!n||xQ(t,Math.min(n.range[0]+.02,n.range[1]-.005))},subscribe:_,resync:v}),[r,_,v]),(0,W.jsxs)(`section`,{id:`tour-section-${e}`,"data-testid":`tour-section-${e}`,children:[n,(0,W.jsx)(yQ,{trackRef:d,height:t,stages:r,activeIndex:g.index,segmentId:e,testId:`tour-runway`,pane:(0,W.jsx)(`div`,{ref:h,className:`absolute inset-0 flex flex-col justify-center`,children:(0,W.jsxs)(B0,{children:[(0,W.jsx)(U0,{ringKey:`editor.window`,el:p}),(0,W.jsx)(zq,{title:O$[w],className:`relative h-full max-h-[760px]`,children:(0,W.jsx)(vQ,{gateId:`${e}-pane`,segmentId:e,className:`relative h-full`,children:l&&(0,W.jsx)(z7,{visible:w===`editor`,children:(0,W.jsx)(f2,{doc:l.doc,onDocChange:l.onDocChange,onBlocksChange:l.onBlocksChange,onRun:l.onRun,theme:l.theme,withRingTargets:!0})})})}),(0,W.jsx)(W0,{target:g.ring?.key?{key:g.ring.key}:null,accent:g.stage.accent??D$.editor,canvasRef:f})]})}),captions:(0,W.jsx)(L7,{activeIndex:g.index,captions:i,onCommand:c})})]})});function V7(e){let[t,n]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let r=new IntersectionObserver(([e])=>{e.isIntersecting&&(n(!0),r.disconnect())},{threshold:.05});return r.observe(t),()=>r.disconnect()},[e]),t}function H7(e){let[t,n]=(0,U.useState)(()=>typeof IntersectionObserver>`u`);return(0,U.useEffect)(()=>{let t=e.current;if(!t||typeof IntersectionObserver>`u`)return;let r=new IntersectionObserver(([e])=>n(e.isIntersecting),{threshold:.05});return r.observe(t),()=>r.disconnect()},[e]),t}var U7={basics:`wods/examples/syntax/single-movement.md`,protocols:`wods/examples/syntax/timers-rest.md`,structure:`wods/examples/syntax/groups-1.md`,"custom-metrics":`wods/syntax/custom-metrics-1.md`,dialects:`wods/examples/syntax/dialect-climb-bouldering.md`,complex:`wods/examples/syntax/complex-swimming.md`},W7={basics:{summary:`Statements and metrics — how a workout line reads, from movement names to reps, loads, and timed rests.`,bullets:["Freeform Markdown + fenced ```time blocks",`Single movements: 10 Pushups, 15 Air Squats`,`Inline resistance: 225lb, 100kg, 24kg`]},protocols:{summary:`Time-capped and paced protocols: AMRAP, EMOM, Tabata intervals, and required rest that paces the room.`,bullets:[`20:00 AMRAP (As Many Rounds As Possible)`,`(10) :60 EMOM (Every Minute on the Minute)`,`*:30 Rest (required, unskippable recovery)`]},structure:{summary:`Rounds, rep ladders, and nested grouping — how blocks compose into multi-part workout schemes.`,bullets:[`(3 Rounds) and (5 Sets) block repetition`,`Ladders & schemes: 21-15-9, 10-8-6-4-2`,`Section labels: (Warmup) and // Strength`]},"custom-metrics":{summary:`Capture typed data points right inline: effort intensity, heart rate, RPE, and custom JSON metrics.`,bullets:[`Inline JSON metrics: {"intensity": 80}`,`Capture prompts: :? time, ? reps, ?lb load`,`Session-level RPE & custom dimensions`]},dialects:{summary:`Dialect fences for specialized domains: workout, log, plan, and climbing session notes.`,bullets:["```time for workouts, ```log for recorded efforts","Sport dialect suffixes like ```log:climbing",`Discipline tags and session intent`]},complex:{summary:`Multi-set training sessions that chain intervals, strength, and conditioning into one complete program.`,bullets:[`Multi-set swimming and track intervals`,`Strength blocks paired with conditioned finishers`,`Full training session flow`]}},G7=[{id:`basics`,title:`Basics`,badge:`trophy`,questIds:[],sectionIds:[]},{id:`protocols`,title:`Protocols`,badge:`timer`,questIds:[],sectionIds:[]},{id:`structure`,title:`Structure`,badge:`dumbbell`,questIds:[],sectionIds:[]},{id:`custom-metrics`,title:`Custom Metrics`,badge:`trophy`,questIds:[],sectionIds:[]},{id:`dialects`,title:`Dialects`,badge:`trophy`,questIds:[],sectionIds:[]},{id:`complex`,title:`Complex Workouts`,badge:`dumbbell`,questIds:[],sectionIds:[]}];function K7({chapters:e=[],allQuests:t=[],theme:n,wodFiles:r={},onRun:i}){let a=(0,U.useMemo)(()=>{let t=(e??[]).filter(e=>e.id!==`home-tour`);return t.length>0?t:G7},[e]),o=Iq(`(prefers-reduced-motion: reduce)`),{markComplete:s}=Nq(`/`,t),{chapters:c}=I7(a),[l,u]=(0,U.useState)(()=>a[0]?.id??`basics`),[d,f]=(0,U.useState)(``),p=(0,U.useRef)([]),m=(0,U.useRef)(l);m.current=l;let h=(0,U.useMemo)(()=>Object.fromEntries(a.map(e=>[e.id,SV(U7[e.id]??``,r)])),[a,r]);(0,U.useEffect)(()=>{p.current=[],f(h[l]??``)},[l,h]);let g=(0,U.useCallback)(e=>{p.current=e},[]),_=(0,U.useCallback)(()=>{let e=m.current;s(`${e}-run`),i?.(e,p.current[0]??null,d)},[d,s,i]),v=(0,U.useMemo)(()=>a.map((e,t)=>{let n=Math.max(1,a.length);return{id:e.id,range:[t/n,(t+1)/n],screen:`editor`,accent:`hsl(var(--primary))`,label:e.title,source:h[e.id]}}),[a,h]),y=(0,U.useMemo)(()=>Object.fromEntries(c.map(e=>[e.chapter.id,e])),[c]),b=(0,U.useMemo)(()=>a.map((e,t)=>{let n=W7[e.id],r=y[e.id];return{id:e.id,num:`05${String.fromCharCode(97+t)}`,title:e.title,body:n?.summary??e.title,bullets:n?.bullets,accent:`hsl(var(--primary))`,extra:r&&(0,W.jsx)(`span`,{"data-testid":`chapter-picker-progress-${e.id}`,className:G(`font-mono text-[11px] font-semibold tabular-nums`,r.isComplete?`font-bold text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:r.isComplete?`done ✓`:`${r.completedCount}/${r.totalCount}`}),actions:[{label:`Read guide →`,href:k$[e.id]??`/page/guide-start`,event:fq.chapterGuideClicked,data:{chapter:e.id},testId:`chapter-picker-guide-${e.id}`}]}}),[a,y]);return(0,W.jsxs)(`section`,{id:`tour-chapter-picker`,"data-testid":`tour-chapter-picker`,className:`flex flex-col`,children:[(0,W.jsx)(T$,{index:`05`,before:`Learning with `,accentText:`Examples`,after:``,accent:`hsl(var(--primary))`,blurb:`Six chapters on the syntax, each with a runnable example and quests to earn. Scroll into each section to load its example code into the editor.`}),o?(0,W.jsx)(q7,{chapters:a,selectedId:l,onSelect:u,doc:d,onDocChange:f,theme:n,onBlocksChange:g,onRun:_,progressByChapter:y}):(0,W.jsx)(B7,{id:`learn`,heightVh:`600vh`,stages:v,captions:b,onActiveStageChange:u,editor:{doc:d,theme:n,onDocChange:f,onBlocksChange:g,onRun:_}})]})}function q7({chapters:e,selectedId:t,onSelect:n,doc:r,onDocChange:i,theme:a,onBlocksChange:o,onRun:s,progressByChapter:c}){return(0,W.jsx)(`div`,{className:`relative mx-auto w-full max-w-[1500px] 2xl:max-w-[1720px] px-6 py-8 lg:px-12 xl:px-16`,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-10 lg:flex-row lg:items-start lg:gap-12 xl:gap-16`,children:[(0,W.jsx)(`div`,{className:`w-full lg:w-[58%] xl:w-[60%] lg:sticky lg:top-[110px] z-10 flex-none`,children:(0,W.jsx)(`div`,{className:`h-[420px] sm:h-[480px] lg:h-[calc(100dvh-150px)] max-h-[700px] w-full rounded-2xl border border-border shadow-2xl overflow-hidden bg-background`,children:(0,W.jsx)(zq,{title:k$[t]?.split(`/`).pop()??`example.md`,subtitle:`Lesson: ${e.find(e=>e.id===t)?.title??t}`,className:`h-full`,children:(0,W.jsx)(f2,{doc:r,onDocChange:i,onBlocksChange:o,onRun:s,theme:a,withRingTargets:!1})})})}),(0,W.jsx)(`div`,{className:`w-full lg:w-[42%] xl:w-[40%] flex flex-col gap-16 lg:py-6`,"data-testid":`chapter-picker-list`,children:e.map((e,r)=>{let i=c[e.id],a=g$(e.badge),o=e.id===t,s=W7[e.id];return(0,W.jsxs)(`div`,{"data-testid":`chapter-picker-row-${e.id}`,className:G(`rounded-2xl border p-6 sm:p-8 transition-all duration-300 min-h-[340px] flex flex-col justify-between`,o?`border-primary bg-primary/5 ring-1 ring-primary/30 shadow-lg dark:bg-primary/10`:`border-border/70 bg-card hover:border-primary/40`),children:[(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsxs)(`span`,{className:`font-mono text-xs font-bold uppercase tracking-wider text-primary`,children:[`Chapter 0`,r+1]}),a&&(0,W.jsx)(a,{className:`size-4 text-primary`})]}),(0,W.jsx)(`span`,{className:G(`font-mono text-xs font-semibold tabular-nums`,i?.isComplete?`text-emerald-600 dark:text-emerald-400 font-bold`:`text-muted-foreground`),children:i?.isComplete?`done ✓`:`${i?.completedCount??0}/${i?.totalCount??e.questIds.length}`})]}),(0,W.jsx)(`h3`,{className:`mt-3 text-2xl font-bold tracking-tight text-foreground sm:text-3xl`,children:e.title}),(0,W.jsx)(`p`,{className:`mt-3 text-sm sm:text-base leading-relaxed text-muted-foreground`,children:s?.summary??e.title}),s?.bullets&&(0,W.jsx)(`ul`,{className:`mt-4 space-y-1.5 text-xs sm:text-sm text-foreground/80 font-mono`,children:s.bullets.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`span`,{className:`text-primary font-bold`,children:`›`}),(0,W.jsx)(`span`,{children:e})]},t))})]}),(0,W.jsxs)(`div`,{className:`mt-6 flex flex-wrap items-center gap-3 pt-4 border-t border-border/50`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>n(e.id),"data-testid":`chapter-picker-select-${e.id}`,"aria-pressed":o,className:G(`inline-flex items-center gap-2 rounded-lg px-4 py-2 text-xs sm:text-sm font-semibold transition-colors shadow-xs`,o?`bg-primary text-primary-foreground hover:bg-primary/90`:`border border-border bg-background text-foreground hover:bg-muted`),children:[(0,W.jsx)(pn,{className:`size-3.5 fill-current`}),(0,W.jsx)(`span`,{children:o?`Loaded in editor`:`Load example`})]}),(0,W.jsxs)(_n,{to:k$[e.id]??`/page/guide-start`,"data-testid":`chapter-picker-guide-${e.id}`,"aria-label":`Read guide for ${e.title}`,onClick:()=>dq.record(fq.chapterGuideClicked,{chapter:e.id}),className:`inline-flex items-center gap-1.5 rounded-lg border border-border bg-background/80 px-3.5 py-2 text-xs sm:text-sm font-medium text-muted-foreground transition-colors hover:border-primary/50 hover:bg-background hover:text-primary`,children:[(0,W.jsx)(dr,{className:`size-3.5`}),(0,W.jsx)(`span`,{children:`Read guide →`})]})]})]},e.id)})})]})})}function J7({chapters:e}){let t=()=>dq.record(fq.lessonStarted),n=()=>dq.record(fq.cheatsheetOpened),{chapters:r}=I7(e),i=r.filter(e=>e.chapter.id!==`home-tour`);return(0,W.jsxs)(`section`,{"data-testid":`tour-learn`,className:`mx-auto max-w-5xl px-6 py-16 border-b border-border/60`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 lg:flex-row lg:items-end lg:justify-between`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h2`,{className:`text-2xl sm:text-3xl font-bold tracking-tight`,children:`Learn the Language`}),(0,W.jsx)(`p`,{className:`mt-2 text-muted-foreground leading-relaxed max-w-xl`,children:`Six chapters, each with a runnable example and quests to earn — progress shows on the chapter cards above.`})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3`,children:[(0,W.jsx)(_n,{to:`/page/guide-start`,onClick:t,className:`inline-flex items-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground transition-colors hover:bg-primary/90`,children:`Start Lesson 1`}),(0,W.jsx)(_n,{to:`/page/guide-start?h=reference`,onClick:n,className:`text-sm font-semibold text-primary underline-offset-2 hover:underline`,children:`Cheat sheet →`})]})]}),(0,W.jsx)(`div`,{className:`mt-8 flex flex-wrap items-center gap-2`,children:i.map(({chapter:e,completedCount:t,totalCount:n,isComplete:r})=>{let i=k$[e.id]??`/page/guide-start`,a=g$(e.badge);return(0,W.jsxs)(_n,{to:i,"data-testid":`learn-progress-chip-${e.id}`,className:G(`group inline-flex items-center gap-2 rounded-full border px-3 py-1.5 transition-colors hover:border-primary/40`,r?`border-emerald-500/30 bg-emerald-500/5`:`border-border bg-card`),children:[a&&(0,W.jsx)(a,{className:`size-3.5 text-muted-foreground`}),(0,W.jsx)(`span`,{className:`text-[12px] font-semibold text-foreground`,children:e.title}),(0,W.jsx)(`span`,{className:G(`font-mono text-[10px] font-bold tabular-nums`,r?`text-emerald-600 dark:text-emerald-400`:`text-muted-foreground`),children:r?`done ✓`:`${t}/${n}`})]},e.id)})})]})}var Y7=J7;function X7(){let e=YO(),t=(0,U.useMemo)(()=>E0(e??{}),[e]),{theme:n}=Mi(),[r,i]=(0,U.useState)(()=>typeof window<`u`&&window.matchMedia(`(prefers-color-scheme: dark)`).matches);(0,U.useEffect)(()=>{if(n!==`system`)return;let e=window.matchMedia(`(prefers-color-scheme: dark)`),t=e=>i(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[n]);let a=(0,U.useMemo)(()=>n===`system`?r?`vs-dark`:`vs`:n===`dark`?`vs-dark`:`vs`,[n,r]),o=qL(),s=w0.chapters,c=w0.quests,l=(0,U.useMemo)(()=>{let e={};for(let t of w0.quests)e[t.id]=t.label;for(let{page:t}of o)for(let n of t.quests)e[n.id]=n.label;return e},[o]),u=pq()?.track,{run:d,start:f,finalize:p,end:m}=Cq(),[h,g]=(0,U.useState)(null),[_,v]=(0,U.useState)(0),[y,b]=(0,U.useState)(!1),x=(0,U.useCallback)(()=>{g(null),b(!1)},[]),S=(0,U.useCallback)(async(e,t,n)=>{if(t){u?.(fq.chapterExampleRun,{chapter:e});try{let r=await f(n,t,{pageTitle:`Syntax`,sectionTitle:`Chapter ${e}`});g(r.block),v(e=>e+1),b(!0)}catch(e){console.error(`[SyntaxView] failed to persist playground run note:`,e),x(),Q({title:`Could not start workout`,variant:`destructive`})}}},[x,f,u]),C=(0,U.useCallback)(async(e,t)=>{try{(t.logs??[]).length===0?(await m(),x()):await p(t,t.completed)}catch(e){throw console.error(`[SyntaxView] failed to save session:`,e),Q({title:`Session not saved`,variant:`destructive`}),e}},[x,m,p]);return(0,W.jsx)(B0,{children:(0,W.jsxs)(`div`,{"data-testid":`syntax-view`,children:[(0,W.jsx)(T$,{index:`S`,before:`Syntax `,accentText:`Learning with Examples`,after:``,accent:`hsl(var(--primary))`,blurb:`Six chapters on the syntax, each with a runnable example. Press run to start a timed workout from any chapter.`}),(0,W.jsx)(K7,{wodFiles:t,chapters:s,allQuests:c,theme:a,onRun:S}),(0,W.jsx)(Y7,{quests:c,chapters:s,questLabels:l}),(0,W.jsx)(M$,{}),(0,W.jsx)(Y0,{}),h&&y&&d&&(0,W.jsx)(OZ,{block:d.block,resultId:d.resultId,autoStart:!0,onClose:x,onCompleteWorkout:C},_)]})})}function Z7(){let e=Vn();return(0,W.jsxs)(`div`,{className:`h-full flex flex-col items-center justify-center gap-6 p-8 text-center`,children:[(0,W.jsx)(`div`,{className:`flex items-center justify-center w-16 h-16 rounded-full bg-muted`,children:(0,W.jsx)(Ve,{className:`w-8 h-8 text-muted-foreground`})}),(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(`h1`,{className:`text-2xl font-bold tracking-tight`,children:`Page not found`}),(0,W.jsx)(`p`,{className:`text-muted-foreground max-w-sm`,children:`The page you are looking for does not exist or has been moved.`})]}),(0,W.jsxs)(`button`,{type:`button`,onClick:()=>e(`/`),className:`inline-flex items-center gap-2 px-4 py-2 rounded-md bg-primary text-primary-foreground text-sm font-medium hover:bg-primary/90 transition-colors`,children:[(0,W.jsx)(ge,{className:`w-4 h-4`}),`Go home`]})]})}var Q7=(e=0,t=0,n=0,r=0,i=0)=>[e,t,n,r,i],$7=(e,t)=>e.map((e,n)=>e+t[n]),e9=(e,t)=>e.map((e,n)=>e-t[n]),t9=(e,t)=>e.every((e,n)=>e===t[n]),n9=Q7(),r9=[`length`,`mass`,`time`,`count`,`energy`];function i9(e){if(t9(e,n9))return`dimensionless`;let t=[];return e.forEach((e,n)=>{e!==0&&t.push(`${r9[n]}${e===1?``:`^`+e}`)}),t.join(` · `)}var a9={m:{dim:Q7(1),toBase:1},km:{dim:Q7(1),toBase:1e3},mi:{dim:Q7(1),toBase:1609.34},kg:{dim:Q7(0,1),toBase:1},lb:{dim:Q7(0,1),toBase:.4536},ms:{dim:Q7(0,0,1),toBase:.001},s:{dim:Q7(0,0,1),toBase:1},min:{dim:Q7(0,0,1),toBase:60},h:{dim:Q7(0,0,1),toBase:3600},reps:{dim:Q7(0,0,0,1),toBase:1},cal:{dim:Q7(0,0,0,0,1),toBase:1},MET:{dim:n9,toBase:1},pts:{dim:n9,toBase:1},AU:{dim:n9,toBase:1},ratio:{dim:n9,toBase:1},"MET-min":{dim:Q7(0,0,1),toBase:60},"reps/min":{dim:e9(Q7(0,0,0,1),Q7(0,0,1)),toBase:1/60},"m/s":{dim:e9(Q7(1),Q7(0,0,1)),toBase:1},"min/km":{dim:e9(Q7(0,0,1),Q7(1)),toBase:60/1e3},"sec/km":{dim:e9(Q7(0,0,1),Q7(1)),toBase:1/1e3},"min/mi":{dim:e9(Q7(0,0,1),Q7(1)),toBase:60/1609.34},"km/h":{dim:e9(Q7(1),Q7(0,0,1)),toBase:1e3/3600},"kg/s":{dim:e9($7(Q7(0,1),Q7(0,0,0,1)),Q7(0,0,1)),toBase:1},"lb/s":{dim:e9($7(Q7(0,1),Q7(0,0,0,1)),Q7(0,0,1)),toBase:.4536}},o9=[{dim:e9(Q7(0,0,1),Q7(1)),name:`pace`,units:[`min/km`,`sec/km`,`min/mi`]},{dim:e9(Q7(1),Q7(0,0,1)),name:`speed`,units:[`m/s`,`km/h`]},{dim:$7(Q7(0,1),Q7(0,0,0,1)),name:`volume`,units:[`kg`,`lb`]},{dim:e9($7(Q7(0,1),Q7(0,0,0,1)),Q7(0,0,1)),name:`power`,units:[`kg/s`,`lb/s`]},{dim:Q7(0,0,1),name:`time`,units:[`min`,`s`,`MET-min`]},{dim:Q7(0,0,0,1),name:`count`,units:[`reps`]},{dim:Q7(1),name:`length`,units:[`m`,`km`,`mi`]},{dim:Q7(0,1),name:`mass`,units:[`kg`,`lb`]},{dim:n9,name:`dimensionless`,units:[`pts`,`AU`,`MET`]}],s9=e=>o9.find(t=>t9(t.dim,e)),c9=(e,t=n9)=>({v:e,dim:t}),l9={thruster:{met:6,discipline:`strength`,disciplineFactor:1.2,intensityTier:`high`,resolvedFrom:`bundled`},"pull-up":{met:5,discipline:`gymnastics`,disciplineFactor:1.2,intensityTier:`moderate`,resolvedFrom:`bundled`},run:{met:9.8,discipline:`running`,disciplineFactor:1,intensityTier:`high`,resolvedFrom:`bundled`},squat:{met:5,discipline:`strength`,disciplineFactor:1.2,intensityTier:`moderate`,resolvedFrom:`bundled`}},u9={met:Q7(0,0,0,0,0),disciplineFactor:n9},d9={easy:3,moderate:5,hard:7,"all-out":10,max:10},f9={effort:{fields:[`met`,`discipline`,`disciplineFactor`,`intensityTier`,`resolvedFrom`],get:(e,t)=>{let n=l9[e];if(!n)return t===`resolvedFrom`?c9(NaN):void 0;let r=n[t];return typeof r==`number`?{v:r,dim:u9[t]??n9}:void 0}},"rpe-labels":{fields:[`rpe`],get:e=>d9[e]===void 0?void 0:c9(d9[e])}},p9={min:e=>c9(Math.min(...e.map(e=>e.v)),e[0]?.dim??n9),max:e=>c9(Math.max(...e.map(e=>e.v)),e[0]?.dim??n9),abs:e=>c9(Math.abs(e[0].v),e[0].dim),round:e=>c9(e.length>1?+e[0].v.toFixed(e[1].v):Math.round(e[0].v),e[0].dim),floor:e=>c9(Math.floor(e[0].v),e[0].dim),ceil:e=>c9(Math.ceil(e[0].v),e[0].dim),clamp:e=>c9(Math.min(Math.max(e[0].v,e[1].v),e[2].v),e[0].dim),convert:e=>{let t=e[1].unit??``,n=a9[t];if(!n||!t9(n.dim,e[0].dim))throw Error(`convert: ${t} dimension ≠ value dimension`);return{v:e[0].v/n.toBase,dim:e[0].dim}}},m9=Object.keys(p9).concat([`has`,`lookup`]);function h9(e){let t=[],n=/\s*("(?:[^"]*)"|\d+\.?\d*|[a-zA-Z_][\w.-]*(?::[\w.:*!|,-]+(?:\{[^}]*\})?(?:\s+by\s+\{[^}]*\})?)?|[-+*/(),<>!=]=?|>=|<=|==)/y,r,i=0;for(;i<e.length;){if(n.lastIndex=i,r=n.exec(e),!r||r.index!==i){/\S/.test(e[i])&&t.push({t:`err`,s:e[i]}),i+=1;continue}i=n.lastIndex;let a=r[1];/^".*"$/.test(a)?t.push({t:`str`,s:a.slice(1,-1)}):/^\d/.test(a)?t.push({t:`num`,s:a}):/^[-+*/(),]$/.test(a)||[`>=`,`<=`,`==`,`!=`,`>`,`<`,`=`].includes(a)?t.push({t:`op`,s:a}):t.push({t:`id`,s:a})}return t}function g9(e){let t=0,n=()=>e[t];function r(i){let a,o=e[t++];if(!o)throw Error(`unexpected end`);if(o.t===`num`)a={k:`num`,v:parseFloat(o.s)};else if(o.t===`str`)a={k:`str`,s:o.s};else if(o.s===`-`)a={k:`neg`,e:r(70)};else if(o.s===`(`){if(a=r(0),n()?.s!==`)`)throw Error(`missing )`);t++}else if(o.t===`id`){if(n()?.s===`(`){t++;let e=[];if(n()?.s!==`)`)for(;;){if(e.push(r(0)),n()?.s===`,`){t++;continue}break}if(n()?.s!==`)`)throw Error(`missing )`);t++,a={k:`call`,f:o.s,args:e}}else a={k:`id`,s:o.s}}else throw Error(`unexpected "${o.s}"`);for(;;){let e=n()?.s,o=e===`*`||e===`/`?60:e===`+`||e===`-`?50:[`<`,`<=`,`>`,`>=`,`==`,`!=`].includes(e)?40:e===`and`?30:e===`or`?20:0;if(!o||o<i)break;t++;let s=r(o+1);a={k:`bin`,op:e,l:a,r:s}}return a}let i=r(0);if(t<e.length)throw Error(`trailing "${e[t].s}"`);return i}function _9(e,t,n){switch(e.k){case`num`:return c9(e.v);case`str`:return{v:NaN,dim:n9,unit:e.s};case`neg`:{let r=_9(e.e,t,n);return c9(-r.v,r.dim)}case`id`:{if(/^(sum|avg|max|min|count|last):/.test(e.s)){let t=n(e.s);if(!t)throw Error(`no data for ${e.s}`);return t}let r=t[e.s];if(r===void 0)throw Error(`unknown or absent: ${e.s}`);return r}case`bin`:{if(e.op===`and`)return c9(_9(e.l,t,n).v&&_9(e.r,t,n).v?1:0);if(e.op===`or`)return c9(_9(e.l,t,n).v||_9(e.r,t,n).v?1:0);let r=_9(e.l,t,n),i=_9(e.r,t,n);switch(e.op){case`+`:if(!t9(r.dim,i.dim))throw Error(`+ : ${i9(r.dim)} vs ${i9(i.dim)}`);return c9(r.v+i.v,r.dim);case`-`:if(!t9(r.dim,i.dim))throw Error(`- : ${i9(r.dim)} vs ${i9(i.dim)}`);return c9(r.v-i.v,r.dim);case`*`:return c9(r.v*i.v,$7(r.dim,i.dim));case`/`:return c9(r.v/i.v,e9(r.dim,i.dim));case`<`:return c9(+(r.v<i.v));case`<=`:return c9(+(r.v<=i.v));case`>`:return c9(+(r.v>i.v));case`>=`:return c9(+(r.v>=i.v));case`==`:return c9(+(r.v===i.v));case`!=`:return c9(r.v===i.v?0:1)}throw Error(e.op)}case`call`:{if(e.f===`has`){let r=e.args[0];return r.k===`id`?c9(t[r.s]!==void 0||/^(sum|avg|max|min|count|last):/.test(r.s)&&n(r.s)!==void 0?1:0):c9(0)}if(e.f===`lookup`){let[n,r,i]=e.args,a=n.k===`str`?n.s:``,o=r.k===`str`?r.s:r.k===`id`?String(t[r.s]?.v??r.s):``,s=i.k===`str`?i.s:``,c=f9[a];if(!c)throw Error(`unknown table "${a}"`);if(!c.fields.includes(s))throw Error(`table "${a}" has no field "${s}"`);if(a===`effort`&&s===`resolvedFrom`)return c9(+!!l9[o]);let l=c.get(o,s);if(!l)throw Error(`lookup miss: ${a}/${o}/${s}`);return l}let r=p9[e.f];if(!r)throw Error(`unknown function ${e.f}`);return r(e.args.map((r,i)=>e.f===`convert`&&i>0&&r.k===`id`?{v:NaN,dim:n9,unit:r.s}:_9(r,t,n)))}}}var v9=[{effort:`thruster`,label:`hard`,reps:21,resistanceKg:43,elapsedMs:95e3},{effort:`pull-up`,reps:21,elapsedMs:6e4},{effort:`thruster`,reps:15,resistanceKg:43,elapsedMs:7e4},{effort:`pull-up`,reps:15,elapsedMs:5e4},{effort:`sled-push`,reps:9,resistanceKg:43,elapsedMs:45e3},{effort:`pull-up`,reps:9,elapsedMs:3e4}],Lee=[420,0,380,510,0,290,610,450,0,520,340,0,480,390,560,0,410,470,0,530,360,440,0,500,580,320,0,460];function Ree(e){let t=l9[e.effort]?.met??4,n=!l9[e.effort];return{segmentVolume:e.reps&&e.resistanceKg?c9(e.reps*e.resistanceKg,$7(Q7(0,1),Q7(0,0,0,1))):void 0,metMinutes:c9(t*(e.elapsedMs/6e4),Q7(0,0,1)),metMinutesEstimated:n?c9(1):void 0,effortRpe:e.label?c9(d9[e.label]??0):void 0}}function zee(e){let t={name:``,exprSrc:``,alternates:[],library:!1,bindings:[]};try{let n=e.trim(),r=/\s+when\s+/.exec(n);r&&(t.whenSrc=n.slice(r.index+r[0].length).trim(),n=n.slice(0,r.index));let i=/\s+where\s+/.exec(n);if(i){let e=n.slice(i.index+i[0].length).trim();n=n.slice(0,i.index);for(let n of e.split(/,\s*(?=[a-zA-Z_][\w]*\s*=)/)){let e=n.indexOf(`=`);e>0&&t.bindings.push({name:n.slice(0,e).trim(),src:n.slice(e+1).trim()})}}let a=/\s*->\s*/.exec(n);a&&(t.unit=n.slice(a.index+a[0].length).trim().replace(/\s+(key|grouped).*$/,``),n=n.slice(0,a.index)),/\(library\)/.test(n)&&(t.library=!0,n=n.replace(`(library)`,``));let o=n.indexOf(`=`);if(o<0)throw Error(`expected name = expression`);t.name=n.slice(0,o).trim();let s=n.slice(o+1).trim().split(`|`).map(e=>e.trim());return t.exprSrc=s[0],t.alternates=s.slice(1).map(e=>({src:e.replace(/\s*estimated\s*$/,``),estimated:/\bestimated\b/.test(e)})),t}catch(e){return t.error=e instanceof Error?e.message:String(e),t}}function y9(e,t,n,r){let i=Ree(e);return{elapsed:c9(e.elapsedMs/1e3,Q7(0,0,1)),reps:e.reps===void 0?void 0:c9(e.reps,Q7(0,0,0,1)),resistance:e.resistanceKg===void 0?void 0:c9(e.resistanceKg,Q7(0,1)),distance:e.distanceM===void 0?void 0:c9(e.distanceM,Q7(1)),effort:c9(NaN),effortLabel:e.label?c9(NaN):void 0,segmentVolume:i.segmentVolume,metMinutes:i.metMinutes,effortRpe:i.effortRpe,sessionRpe:n===void 0?void 0:c9(n),"profile.vo2max":r===void 0?void 0:c9(r),...t}}var b9=e=>e.effort;function x9(e,t,n,r){let i=zee(e),a=[];if(i.error)return{calc:i,diagnostics:[i.error]};let o={calc:i,diagnostics:a},s=e=>e instanceof Error?e.message:String(e);if(t!==`store`){try{g9(h9(i.exprSrc))}catch(e){a.push(`expression: ${s(e)}`)}for(let e of i.bindings)for(let t of e.src.split(`|`))try{g9(h9(t.replace(/\s*estimated\s*$/,``)))}catch(t){a.push(`${e.name}: ${s(t)}`)}if(i.whenSrc)try{g9(h9(i.whenSrc))}catch(e){a.push(`when: ${s(e)}`)}}let c=v9,l=(e,t=c.length)=>{let i=/^(sum|avg|max|min|count|last):([\w.]+)/.exec(e);if(!i)return;let[,a,o]=i,s=c.slice(0,t),l=[];for(let e of s){let t=y9(e,{},n,r)[o];t!==void 0&&!Number.isNaN(t.v)&&l.push(t)}if(o===`sessionLoad`&&e.includes(`by {day}`))return c9(NaN);if(!l.length)return;let u=l[0].dim,d=l.map(e=>e.v);if(a===`sum`)return c9(d.reduce((e,t)=>e+t,0),u);if(a===`avg`)return c9(d.reduce((e,t)=>e+t,0)/d.length,u);if(a===`max`)return c9(Math.max(...d),u);if(a===`min`)return c9(Math.min(...d),u);if(a===`count`)return c9(d.length,Q7(0,0,0,1));if(a===`last`)return l[l.length-1]},u=(e,t,n)=>{let r={...t};for(let e of i.bindings){let t=e.src.split(`|`).map(e=>e.replace(/\s*estimated\s*$/,``).trim()),i;for(let e of t)try{i=d(e,r,n);break}catch{}if(i===void 0)throw Error(`${e.name}: no applicable variant`);r[e.name]=i}return d(e,r,n)},d=(e,t,n)=>_9(g9(h9(e)),t,e=>l(e,n));try{if(t===`segment`){let e=[],t;c.forEach((a,o)=>{try{let s=y9(a,{},n,r);if(s.effort=void 0,i.whenSrc&&!d(i.whenSrc,s,o+1).v){e.push(null);return}let c=i.exprSrc.replace(/lookup\("effort",\s*effort\s*,/g,`lookup("effort", "${b9(a)}",`).replace(/lookup\("rpe-labels",\s*effortLabel\s*,/g,`lookup("rpe-labels", "${a.label??``}",`),l=u(c,s,o+1);t||=l.dim;let f=i.unit&&i.unit!==`auto`?` ${i.unit}`:t?` [${i9(l.dim)}]`:``;e.push(`${Math.round(l.v*100)/100}${f}`)}catch(t){e.push(`∅ ${s(t)}`)}}),o.perSegment=e,o.dim=t}else if(t===`workout`){let e=[],t;for(let a=1;a<=c.length;a++)try{let s=c[a-1],l=y9(s,{"session.duration":c9(c.slice(0,a).reduce((e,t)=>e+t.elapsedMs,0)/1e3,Q7(0,0,1))},n,r);if(i.whenSrc&&!d(i.whenSrc,l,a).v){e.push(null);continue}let f=i.exprSrc.replace(/lookup\("effort",\s*effort\s*,/g,`lookup("effort", "${b9(s)}",`),p,m=`primary`;try{p=u(f,l,a)}catch(e){for(let e of i.alternates)try{p=u(e.src,l,a),m=e.estimated?`estimated`:`alternate`;break}catch{}if(p===void 0)throw e}t=p.dim,e.push(`${Math.round(p.v*100)/100}${i.unit&&i.unit!==`auto`?` `+i.unit:``}${m===`estimated`?` (est.)`:``}`),o.variantUsed=m}catch(t){e.push(`∅ ${s(t)}`)}o.running=e,o.dim=t}else{let e=Lee,t=(e,t,n)=>e.map((r,i)=>i+1>=t?n(e.slice(i+1-t,i+1)):NaN),n=e=>e.reduce((e,t)=>e+t,0)/e.length,r=e=>{let t=n(e);return Math.sqrt(n(e.map(e=>(e-t)**2)))},a=i.name,s=[];if(a.includes(`acwr`)){let r=t(e,7,n),i=t(e,28,n);s=e.map((e,t)=>r[t]/i[t])}else if(a.includes(`monotony`)){let i=t(e,7,n),a=t(e,7,r);s=e.map((e,t)=>i[t]/a[t])}else if(a.includes(`strain`)){let i=t(e,7,n),a=t(e,7,r),o=t(e,7,e=>e.reduce((e,t)=>e+t,0));s=e.map((e,t)=>i[t]/a[t]*o[t])}else s=t(e,7,n);o.perSegment=s.slice(-7).map(e=>Number.isNaN(e)?null:String(Math.round(e*100)/100)),o.dim=n9}}catch(e){a.push(s(e))}if(o.dim&&i.unit&&i.unit!==`auto`){let e=a9[i.unit];e?!t9(e.dim,o.dim)&&!t9(e.dim,n9)&&a.push(`unit "${i.unit}" is ${i9(e.dim)} but expression computes ${i9(o.dim)}`):a.push(`unknown unit "${i.unit}"`)}return o}function S9(e,t){let n=/([a-zA-Z_][\w.:-]*|"[\w-]*|)$/.exec(e)[1],r=e.length-n.length,i=e.slice(0,r),a=[],o=(e,t,n)=>a.push({label:e,insert:t,detail:n}),s=/lookup\("([\w-]*)",?\s*("[\w-]*",?\s*)?"?([\w-]*)$/.exec(e);if(s){if(s[2]===void 0&&!e.endsWith(`"`))f9&&Object.keys(f9).forEach(e=>o(e,`"${e}"`,`lookup table`));else{let t=s[1];(e.split(`"`).length<=5&&s[3]!==void 0||/,\s*"[\w-]*$/.test(e))&&(f9[t]?.fields??[]).forEach(e=>o(e,`"${e}"`,`${t} field`)),t===`effort`&&/,\s*$/.test(e)&&Object.keys(l9).concat([`effort`]).forEach(e=>o(e,e===`effort`?`effort`:`"${e}"`,`key`))}return{items:a.filter(e=>e.label.startsWith(n.replace(/"/g,``))),from:r}}return/^(sum|avg|max|min|count|last):[\w.]*$/.test(n)?((t===`segment`?[]:[`reps`,`distance`,`segmentVolume`,`metMinutes`,`elapsed`,`effortRpe`,`sessionLoad`]).forEach(e=>o(e,e,`metric key`)),{items:a.filter(e=>e.label.startsWith(n.split(`:`)[1]??``)),from:r+n.indexOf(`:`)+1}):/->\s*[\w/]*$/.test(i+n)?(Object.keys(a9).forEach(e=>o(e,e,`unit`)),{items:a.filter(e=>e.label.startsWith(n)),from:r}):((t===`segment`?[`elapsed`,`reps`,`resistance`,`distance`,`effort`,`effortLabel`,`segmentVolume`,`metMinutes`,`effortRpe`,`sessionRpe`]:[`sessionRpe`,`session.duration`,`profile.vo2max`]).forEach(e=>o(e,e,t===`segment`?`segment metric / context`:`context node`)),m9.forEach(e=>o(`${e}()`,`${e}()`,`function`)),[`sum:`,`avg:`,`max:`,`count:`,`last:`].forEach(e=>o(`${e}{}`,e,`WQL atom`)),i.includes(`=`)&&o(`estimated`,`estimated`,`variant origin`),[`when `,`-> `,`where `,`| `,` key `,`(library)`].forEach(e=>o(e.trim(),e,`clause`)),{items:a.filter(e=>e.label.startsWith(n)).slice(0,9),from:r})}var C9={background:`#18181b`,border:`1px solid #3f3f46`,borderRadius:8,padding:12},w9={fontFamily:`ui-monospace, monospace`,fontSize:13};function T9({r:e}){let t=s9(e.dim??n9);return(0,W.jsxs)(`div`,{style:{marginTop:8,fontSize:12},children:[e.dim&&(0,W.jsxs)(`div`,{style:{color:`#a1a1aa`,marginBottom:4},children:[`computes `,(0,W.jsx)(`b`,{style:{color:`#e4e4e7`},children:i9(e.dim)}),t&&t.name!==`dimensionless`&&(0,W.jsxs)(W.Fragment,{children:[` → `,(0,W.jsx)(`span`,{style:{color:`#c084fc`},children:t.name}),` — units: `,t.units.map(t=>(0,W.jsx)(Bee,{u:t,active:e.calc.unit===t},t))]})]}),e.diagnostics.map((e,t)=>(0,W.jsxs)(`div`,{style:{color:`#f87171`},children:[`⚠ `,e]},t)),!e.diagnostics.length&&(0,W.jsxs)(`div`,{style:{color:`#34d399`},children:[`✓ valid`,e.variantUsed===`estimated`?` — estimated variant in use`:``]})]})}var Bee=({u:e,active:t})=>(0,W.jsx)(`span`,{style:{border:`1px solid ${t?`#c084fc`:`#52525b`}`,borderRadius:4,padding:`0 5px`,marginRight:4,color:t?`#c084fc`:`#a1a1aa`},children:e});function Vee({r:e,scope:t,sessionRpe:n,vo2max:r}){return(0,W.jsxs)(`div`,{style:{...C9,minWidth:320},children:[(0,W.jsxs)(`div`,{style:{fontSize:11,color:`#71717a`,marginBottom:6},children:[`LIVE PREVIEW — `,t===`store`?`last 7 of 28 days (fixture)`:`Fran, 2026-07-28 (fixture)${r?` · VO₂max ${r}`:` · VO₂max unknown`}${n?` · sRPE ${n}`:``}`]}),t===`segment`&&v9.map((t,n)=>(0,W.jsxs)(`div`,{style:{...w9,display:`flex`,justifyContent:`space-between`,color:`#d4d4d8`},children:[(0,W.jsxs)(`span`,{style:{color:`#71717a`},children:[t.effort,t.reps?` ×${t.reps}`:``,t.resistanceKg?` ${t.resistanceKg}kg`:``]}),(0,W.jsx)(`span`,{style:{color:e.perSegment?.[n]?.startsWith(`∅`)?`#f87171`:`#7dd3fc`},children:e.perSegment?.[n]??`—`})]},n)),t===`workout`&&v9.map((t,n)=>(0,W.jsxs)(`div`,{style:{...w9,display:`flex`,justifyContent:`space-between`,color:`#d4d4d8`},children:[(0,W.jsxs)(`span`,{style:{color:`#71717a`},children:[`after line `,n+1]}),(0,W.jsx)(`span`,{style:{color:e.running?.[n]?.startsWith(`∅`)?`#f87171`:`#7dd3fc`},children:e.running?.[n]??`—`})]},n)),t===`store`&&(e.perSegment??[]).map((e,t)=>(0,W.jsxs)(`div`,{style:{...w9,display:`flex`,justifyContent:`space-between`,color:`#d4d4d8`},children:[(0,W.jsxs)(`span`,{style:{color:`#71717a`},children:[`D-`,6-t]}),(0,W.jsx)(`span`,{style:{color:`#7dd3fc`},children:e??`—`})]},t))]})}function Hee({scope:e,onSrc:t}){let[n,r]=(0,U.useState)(`power`),[i,a]=(0,U.useState)(`reps * resistance / convert(elapsed, s)`),[o,s]=(0,U.useState)(`kg/s`),[c,l]=(0,U.useState)(`has(reps) and has(resistance) and elapsed > 0`),[u,d]=(0,U.useState)(null),f=`${n} = ${i}${o?` -> ${o}`:``}${c?` when ${c}`:``}`,p=(0,U.useMemo)(()=>x9(f,e,void 0,void 0),[f,e]);(0,U.useEffect)(()=>t(f),[f]);let m=[{id:`name`,label:`name`,value:n,set:r,hint:`calc id`},{id:`expr`,label:`=`,value:i,set:a,hint:`expression — metrics, lookups, functions`},{id:`unit`,label:`->`,value:o,set:s,hint:`output unit (auto allowed)`},{id:`when`,label:`when`,value:c,set:l,hint:`applicability predicate`}];return(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{style:{display:`flex`,gap:6,flexWrap:`wrap`,alignItems:`center`},children:m.map(e=>(0,W.jsxs)(`div`,{style:{display:`flex`,alignItems:`center`,gap:4},children:[(0,W.jsx)(`span`,{style:{color:`#71717a`,fontSize:12},children:e.label}),(0,W.jsx)(`button`,{onClick:()=>d(u===e.id?null:e.id),style:{...w9,fontSize:12,background:u===e.id?`#3b0764`:`#27272a`,border:`1px solid ${u===e.id?`#c084fc`:`#3f3f46`}`,borderRadius:6,color:`#e4e4e7`,padding:`4px 10px`,cursor:`pointer`,maxWidth:340,overflow:`hidden`,textOverflow:`ellipsis`,whiteSpace:`nowrap`},children:e.value||(0,W.jsx)(`span`,{style:{color:`#52525b`},children:`∅`})})]},e.id))}),u&&(0,W.jsxs)(`div`,{style:{...C9,marginTop:8},children:[(0,W.jsx)(`div`,{style:{fontSize:11,color:`#71717a`,marginBottom:4},children:m.find(e=>e.id===u)?.hint}),(0,W.jsx)(`input`,{autoFocus:!0,value:m.find(e=>e.id===u).value,onChange:e=>m.find(e=>e.id===u).set(e.target.value),style:{...w9,width:`100%`,background:`#09090b`,border:`1px solid #3f3f46`,borderRadius:6,color:`#e4e4e7`,padding:`4px 8px`,outline:`none`}}),(0,W.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`,marginTop:6},children:S9(m.find(e=>e.id===u).value,e).items.map((e,t)=>(0,W.jsx)(`button`,{onClick:()=>m.find(e=>e.id===u).set(e.insert),style:{...w9,fontSize:12,background:`#27272a`,border:`1px solid #3f3f46`,borderRadius:5,color:`#7dd3fc`,padding:`2px 8px`,cursor:`pointer`},children:e.label},t))})]}),(0,W.jsx)(`div`,{style:{...w9,marginTop:8,color:`#52525b`,fontSize:12},children:f}),(0,W.jsx)(T9,{r:p})]})}function Uee({scope:e,onSrc:t}){let[n,r]=(0,U.useState)(`power`),[i,a]=(0,U.useState)([`reps`,`*`,`resistance`,`/`,`convert(elapsed, s)`]),o=[{group:`metrics`,items:e===`segment`?[`elapsed`,`reps`,`resistance`,`distance`]:[`sum:reps{}`,`sum:distance{}`,`sum:metMinutes{}`,`sum:elapsed{}`]},{group:`functions`,items:[`convert(·, min)`,`convert(·, km)`,`convert(·, s)`,`min(·, 100)`,`round(·)`]},{group:`lookups`,items:[`lookup("effort", effort, "met")`,`lookup("effort", effort, "disciplineFactor")`,`lookup("rpe-labels", effortLabel, "rpe")`]},{group:`operators`,items:[`+`,`-`,`*`,`/`,`(`,`)`]}],s=`${n} = ${i.join(` `)} -> auto`,c=(0,U.useMemo)(()=>x9(s,e,void 0,void 0),[s,e]);(0,U.useEffect)(()=>t(s),[s]);let l=s9(c.dim??n9);return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{style:{display:`flex`,gap:8,marginBottom:8,alignItems:`center`},children:[(0,W.jsx)(`span`,{style:{fontSize:12,color:`#71717a`},children:`name`}),(0,W.jsx)(`input`,{value:n,onChange:e=>r(e.target.value),style:{...w9,background:`#09090b`,border:`1px solid #3f3f46`,borderRadius:6,color:`#e4e4e7`,padding:`3px 8px`}})]}),o.map(e=>(0,W.jsxs)(`div`,{style:{marginBottom:6},children:[(0,W.jsx)(`div`,{style:{fontSize:11,color:`#71717a`,marginBottom:3},children:e.group}),(0,W.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`},children:e.items.map(e=>(0,W.jsx)(`button`,{onClick:()=>a(t=>[...t,e]),style:{...w9,fontSize:12,background:`#27272a`,border:`1px solid #3f3f46`,borderRadius:5,color:`#7dd3fc`,padding:`2px 8px`,cursor:`pointer`},children:e},e))})]},e.group)),(0,W.jsxs)(`div`,{style:{...C9,...w9,marginTop:8,color:`#d4d4d8`,minHeight:34},children:[i.map((e,t)=>(0,W.jsx)(`span`,{onClick:()=>a(e=>e.filter((e,n)=>n!==t)),title:`click to remove`,style:{cursor:`pointer`,background:`#27272a`,borderRadius:4,padding:`1px 6px`,marginRight:4,display:`inline-block`},children:e},t)),!i.length&&(0,W.jsx)(`span`,{style:{color:`#52525b`},children:`click palette items to build the formula…`})]}),(0,W.jsxs)(`div`,{style:{fontSize:12,color:`#71717a`,marginTop:6},children:[`unit: `,(0,W.jsx)(`b`,{style:{color:`#c084fc`},children:l?l.units.join(` / `):`—`}),` (derived)`]}),(0,W.jsx)(`div`,{style:{...w9,marginTop:6,color:`#52525b`,fontSize:12},children:s}),(0,W.jsx)(T9,{r:c})]})}var E9={segment:`power = reps * resistance / convert(elapsed, s) -> kg/s when has(reps) and has(resistance) and elapsed > 0`,workout:`sessionLoad = round(rpe * convert(session.duration, min)) -> AU where rpe = sessionRpe | max:effortRpe{} | 5 estimated`,store:`acwr = windowMean(daily, 7d) / windowMean(daily, 28d) -> ratio`};function Wee(){let[e,t]=cn(),n=e.get(`v`)??`text`,[r,i]=(0,U.useState)(`segment`),[a,o]=(0,U.useState)(void 0),[s,c]=(0,U.useState)(void 0),[l,u]=(0,U.useState)(E9.segment),[d,f]=(0,U.useState)(``),p=n===`text`?l:d||l,m=(0,U.useMemo)(()=>x9(p,r,a,s),[p,r,a,s]),h=[[`text`,`A · text + completion`],[`slots`,`B · token slots`],[`guided`,`C · guided builder`]];return(0,W.jsxs)(`div`,{style:{background:`#09090b`,minHeight:`100vh`,color:`#e4e4e7`,padding:24,fontFamily:`system-ui`},children:[(0,W.jsxs)(`div`,{style:{maxWidth:1100,margin:`0 auto`},children:[(0,W.jsx)(`div`,{style:{fontSize:11,color:`#f59e0b`,marginBottom:4},children:`PROTOTYPE — throwaway · issue #863`}),(0,W.jsx)(`h1`,{style:{fontSize:20,fontWeight:700,marginBottom:12},children:`Calc-line guided authoring`}),(0,W.jsxs)(`div`,{style:{display:`flex`,gap:12,marginBottom:16,alignItems:`center`,fontSize:13},children:[[`segment`,`workout`,`store`].map(e=>(0,W.jsxs)(`button`,{onClick:()=>{i(e),u(E9[e])},style:{padding:`3px 12px`,borderRadius:6,border:`1px solid ${r===e?`#7dd3fc`:`#3f3f46`}`,background:`none`,color:r===e?`#7dd3fc`:`#a1a1aa`,cursor:`pointer`},children:[e,` scope`]},e)),(0,W.jsx)(`span`,{style:{color:`#3f3f46`},children:`|`}),(0,W.jsxs)(`label`,{style:{color:`#71717a`},children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:!!a,onChange:e=>o(e.target.checked?8:void 0)}),` sRPE captured`]}),(0,W.jsxs)(`label`,{style:{color:`#71717a`},children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:!!s,onChange:e=>c(e.target.checked?42:void 0)}),` VO₂max known`]})]}),(0,W.jsxs)(`div`,{style:{display:`flex`,gap:16,alignItems:`flex-start`},children:[(0,W.jsxs)(`div`,{style:{flex:1},children:[n===`text`&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),style:{...C9,...w9,width:`100%`,color:`#e4e4e7`,outline:`none`},placeholder:`name = expression -> unit when predicate`}),(0,W.jsx)(Gee,{src:l,scope:r,onApply:e=>u(e)}),(0,W.jsx)(T9,{r:m})]}),n===`slots`&&(0,W.jsx)(Hee,{scope:r,onSrc:f}),n===`guided`&&(0,W.jsx)(Uee,{scope:r,onSrc:f})]}),(0,W.jsx)(Vee,{r:m,scope:r,sessionRpe:a,vo2max:s})]})]}),(0,W.jsx)(`div`,{style:{position:`fixed`,bottom:16,left:`50%`,transform:`translateX(-50%)`,display:`flex`,gap:6,background:`#18181b`,border:`1px solid #3f3f46`,borderRadius:10,padding:6},children:h.map(([e,r])=>(0,W.jsx)(`button`,{onClick:()=>t({v:e}),style:{padding:`4px 14px`,borderRadius:7,border:`none`,background:n===e?`#7dd3fc`:`transparent`,color:n===e?`#09090b`:`#a1a1aa`,cursor:`pointer`,fontSize:13},children:r},e))})]})}function Gee({src:e,scope:t,onApply:n}){let r=(0,U.useMemo)(()=>S9(e,t),[e,t]);return r.items.length?(0,W.jsx)(`div`,{style:{display:`flex`,gap:4,flexWrap:`wrap`,marginTop:6},children:r.items.map((t,i)=>(0,W.jsxs)(`button`,{onClick:()=>n(e.slice(0,r.from)+t.insert),style:{...w9,fontSize:12,background:`#27272a`,border:`1px solid #3f3f46`,borderRadius:5,color:`#7dd3fc`,padding:`2px 8px`,cursor:`pointer`},children:[t.label,` `,(0,W.jsx)(`span`,{style:{color:`#52525b`},children:t.detail})]},i))}):null}var D9=`01a09d45-885a-738d-ab1e-be31d44fe919`,Kee=`:session{result:${D9}}`,O9=`## Morning session
477
477
 
478
478
  Fran went unbroken until round three. Throat on fire.
479
479
 
@@ -487,5 +487,5 @@ Fran went unbroken until round three. Throat on fire.
487
487
 
488
488
  `,k9]})]})}var Xee=`✎`;function Zee({wql:e,setWql:t}){let[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(e);return(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsx)(j9,{wql:e}),!n&&(0,W.jsx)(`button`,{onClick:()=>{a(e),r(!0)},className:`absolute top-2 right-2 text-muted-foreground hover:text-foreground text-xs px-1.5 py-0.5 rounded hover:bg-muted`,children:Xee})]}),n&&(0,W.jsxs)(`div`,{className:`rounded-lg border border-sky-500/50 bg-card p-3 space-y-2 shadow-lg shadow-sky-500/5`,children:[(0,W.jsx)(`div`,{className:`text-[10px] text-sky-400 font-mono`,children:`editing query:table — Apply writes the fence`}),(0,W.jsx)(Kw,{query:i,onQueryChange:a,autoFocus:!0,placeholder:`:session…`}),(0,W.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,W.jsx)(`button`,{onClick:()=>r(!1),className:`px-3 py-1 text-xs rounded-md border border-border text-muted-foreground hover:text-foreground`,children:`Cancel`}),(0,W.jsx)(`button`,{onClick:()=>{t(i),r(!1)},className:`px-3 py-1 text-xs rounded-md bg-sky-500 text-zinc-950 font-medium`,children:`Apply to fence`})]})]})]})}function Qee({wql:e,setWql:t}){let[n,r]=(0,U.useState)(!1);return(0,W.jsxs)(`div`,{className:`space-y-3 pb-24`,children:[(0,W.jsx)(`button`,{onClick:()=>r(!0),className:`block w-full text-left rounded-lg transition-shadow ${n?`ring-2 ring-sky-500/70`:`hover:ring-1 hover:ring-border`}`,children:(0,W.jsx)(j9,{wql:e})}),(0,W.jsxs)(`div`,{className:`sticky bottom-20 rounded-xl border p-3 space-y-2 shadow-xl backdrop-blur transition-colors ${n?`border-sky-500/60 bg-card/95`:`border-border bg-card/80 opacity-70`}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-mono ${n?`text-sky-400`:`text-muted-foreground`}`,children:n?`◉ bound: query:table · ${D9.slice(0,8)}…`:`○ click a query block to bind the composer`}),n&&(0,W.jsx)(`button`,{onClick:()=>r(!1),className:`text-[10px] text-muted-foreground hover:text-foreground`,children:`Done`})]}),n&&(0,W.jsx)(Kw,{query:e,onQueryChange:t,autoFocus:!0,showDiagnostics:!1,placeholder:`:session…`})]})]})}function $ee({wql:e,setWql:t}){let[n,r]=(0,U.useState)(!1);return(0,U.useEffect)(()=>{if(!n)return;let e=e=>{e.key===`Escape`&&r(!1)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[n]),n?(0,W.jsxs)(`div`,{className:`rounded-lg border border-sky-500/50 bg-muted/60 shadow-lg shadow-sky-500/5`,children:[(0,W.jsx)(`div`,{className:`px-3 pt-2 text-[10px] font-mono text-muted-foreground select-none`,children:"```query:table"}),(0,W.jsx)(`div`,{className:`px-3 py-2`,children:(0,W.jsx)(Kw,{query:e,onQueryChange:t,autoFocus:!0,showDiagnostics:!1,placeholder:`:session…`,className:`bg-transparent border-0 shadow-none`})}),(0,W.jsxs)(`div`,{className:`px-3 pb-2 flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`text-[10px] font-mono text-muted-foreground select-none`,children:"```"}),(0,W.jsx)(`button`,{onClick:()=>r(!1),className:`text-[10px] text-sky-400 hover:text-sky-300 font-mono`,children:`Esc / leave fence ↩`})]})]}):(0,W.jsx)(`button`,{onClick:()=>r(!0),className:`block w-full text-left hover:ring-1 hover:ring-border rounded-lg`,children:(0,W.jsx)(j9,{wql:e})})}var N9=[[`inline`,`A · in-flow expansion`],[`dock`,`B · bound dock`],[`fence`,`C · fence-as-composer`]];function ete(){let[e,t]=cn(),n=e.get(`v`)??`inline`,[r,i]=(0,U.useState)(Kee),a=e=>{let r=N9[(N9.findIndex(([e])=>e===n)+e+N9.length)%N9.length][0];t({v:r})};return(0,U.useEffect)(()=>{let e=e=>{e.target.closest(`input, textarea, [contenteditable]`)||(e.key===`ArrowLeft`&&a(-1),e.key===`ArrowRight`&&a(1))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,W.jsxs)(`div`,{className:`min-h-screen bg-background text-foreground p-6`,children:[(0,W.jsxs)(`div`,{className:`max-w-5xl mx-auto grid grid-cols-[1fr_320px] gap-6 items-start`,children:[(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`text-[11px] text-amber-500 mb-1`,children:`PROTOTYPE — throwaway · query:table editing via WqlComposer`}),(0,W.jsx)(`h1`,{className:`text-xl font-bold`,children:`Journal — 2026-09-13`})]}),(0,W.jsx)(M9,{children:O9.split("```time")[0].trim()}),(0,W.jsx)(Jee,{}),n===`inline`&&(0,W.jsx)(Zee,{wql:r,setWql:i}),n===`dock`&&(0,W.jsx)(Qee,{wql:r,setWql:i}),n===`fence`&&(0,W.jsx)($ee,{wql:r,setWql:i}),(0,W.jsx)(M9,{children:k9})]}),(0,W.jsx)(`div`,{className:`sticky top-6`,children:(0,W.jsx)(Yee,{wql:r})})]}),(0,W.jsxs)(`div`,{className:`fixed bottom-4 left-1/2 -translate-x-1/2 flex items-center gap-1 rounded-xl border border-border bg-card/95 backdrop-blur px-2 py-1.5 shadow-2xl z-50`,children:[(0,W.jsx)(`button`,{onClick:()=>a(-1),className:`px-2 text-muted-foreground hover:text-foreground`,children:`←`}),N9.map(([e,r])=>(0,W.jsx)(`button`,{onClick:()=>t({v:e}),className:`px-3 py-1 rounded-lg text-xs transition-colors ${n===e?`bg-sky-400 text-zinc-950 font-medium`:`text-muted-foreground hover:text-foreground`}`,children:r},e)),(0,W.jsx)(`button`,{onClick:()=>a(1),className:`px-2 text-muted-foreground hover:text-foreground`,children:`→`})]})]})}function P9(e,t,n=`absent`){return{id:e,fields:t,missPolicy:n,get:()=>void 0}}function tte(){let e=new Rf;return e.register(P9(`effort`,{met:{dimension:Cd,type:`number`},disciplineFactor:{dimension:Cd,type:`number`},discipline:{dimension:Cd,type:`string`},intensityTier:{dimension:Cd,type:`string`},resolvedFrom:{dimension:Cd,type:`string`}},`default-row`)),e.register(P9(`rpe-labels`,{rpe:{dimension:Cd,type:`number`}})),e.register(P9(`profile`,{vo2max:{dimension:Cd,type:`number`}})),e.register(P9(`disciplines`,{disciplineFactor:{dimension:Cd,type:`number`}},`default-row`)),e}function nte(e,t){for(let n of t)try{e.register(n)}catch{}}function F9(e,t=`segment`){let n=[],r=[];try{let i=Ep(e,{scope:t});r=i.defs;for(let e of i.warnings)n.push({severity:`warning`,message:e})}catch(e){return{defs:r,diagnostics:[{severity:`error`,message:e instanceof Error?e.message:String(e)}],dim:void 0,compound:void 0}}let i=new Sf(tte());nte(i,[...Bf,...Wf]);let a;for(let e of r){try{i.register(e)}catch(e){n.push({severity:`error`,message:e instanceof Error?e.message:String(e)});continue}let t=Bp(e)??(e.kind===`library`?Object.keys(e.variants[0]?.nodes??{})[0]:void 0),r=[...e.variants].sort((e,t)=>t.priority-e.priority)[0],o=t&&r.nodeDims?.[t];o&&(a=o)}let o;return a&&(o=Pd(a)),r.length===0&&n.push({severity:`warning`,message:`No calc line parsed.`}),{defs:r,diagnostics:n,dim:a,compound:o}}var rte=[`segment`,`workout`,`store`],I9=[`when`,`where`,`key`,`grouped`,`label`,`emit`,`meta`,`estimated`,`library`,`on`,`by`,`without`,`and`,`or`,`not`],L9=[`convert`,`lookup`,`has`,`round`,`floor`,`ceil`,`abs`,`clamp`,`min`,`max`,`sum`,`avg`,`count`,`last`,`windowMean`,`windowSum`,`windowSd`,`mean`],R9=[{name:`elapsed`,dim:Fd.elapsed.dim,detail:`s (time)`},{name:`reps`,dim:Fd.reps.dim,detail:`count`},{name:`resistance`,dim:Fd.resistance.dim,detail:`kg (mass)`},{name:`distance`,dim:Fd.distance.dim,detail:`m (length)`},{name:`effort`,dim:Id.effort,detail:`resolved effort slug`},{name:`effortLabel`,dim:Id.effortLabel,detail:`raw effort label`}],z9=[{name:`sessionRpe`,dim:Id.sessionRpe,detail:`captured session RPE`},{name:`session.duration`,dim:Id[`session.duration`],detail:`workout duration`},{name:`profile.vo2max`,dim:Id[`profile.vo2max`],detail:`user VO₂max (mL/kg/min)`}],B9=Object.keys(Fd),ite=Object.keys(Ld),V9=[{name:`effort`,detail:`effort library`,fields:[`met`,`disciplineFactor`,`discipline`,`intensityTier`,`resolvedFrom`]},{name:`rpe-labels`,detail:`effort label → RPE`,fields:[`rpe`]},{name:`profile`,detail:`user profile`,fields:[`vo2max`]},{name:`disciplines`,detail:`canonical disciplines`,fields:[`disciplineFactor`]}],H9=Object.keys(Vd),ate=Object.keys(Ld);function ote(e){return e?H9.filter(t=>{let n=Vd[t];return n?n.dim.every((t,n)=>t===e[n]):!1}):H9}var ste=new Set([...I9,...rte,`lookup`]),cte=new Set(L9),lte=new Set([...R9.map(e=>e.name),...z9.map(e=>e.name),...B9,...V9.map(e=>e.name)]),ute=/^\d*\.?\d+(?:d)?/,dte=/^[A-Za-z_][\w.]*/,fte=Er.define({name:`calcLine`,token(e){if(e.eatSpace())return null;if(e.match(`#`,!1))return e.skipToEnd(),`comment`;if(e.match(/^"([^"]*)"/)||e.match(/^'([^']*)'/))return`string`;if(e.match(/^(->|==|!=|<=|>=)/)||e.match(/^[+\-*/=<>(),:{}[\]]/))return`operator`;if(e.match(ute))return`number`;if(e.match(dte)){let t=e.current();return ste.has(t)?`keyword`:cte.has(t)?`function`:(lte.has(t),`variableName`)}return e.next(),null}}),pte=Mr.define([{tag:H.keyword,color:`#c084fc`},{tag:H.function(H.variableName),color:`#60a5fa`},{tag:H.variableName,color:`#e4e4e7`},{tag:H.number,color:`#fbbf24`},{tag:H.string,color:`#34d399`},{tag:H.operator,color:`#a1a1aa`},{tag:H.comment,color:`#71717a`,fontStyle:`italic`}]);function mte(){return new Fr(fte,[jr(pte)])}var hte=[`effort`,`thruster`,`push-press`,`front-squat`,`wall-ball`,`row`,`run`];function U9(e,t){return`${t?``:`"`}${e}"`}function gte(e={}){let t=e.scope??`segment`,n=()=>{let t=e.effortKeys?.().filter(Boolean)??[];return[`effort`,...t.length?t:hte.slice(1)]};return e=>{let r=e.state.sliceDoc(0,e.pos),i=e.matchBefore(/[\w./"]*/);if(!i)return null;if(/lookup\(\s*/.test(r)){let t=r.lastIndexOf(`lookup(`),i=r.slice(t+7);if(!/,/.test(i)&&/^"?[\w.-]*"?$/.test(i.replace(/"/g,``).trim()||``)){let t=i.replace(/"/g,``).trim(),n=i.trimStart().startsWith(`"`),r=V9.filter(e=>e.name.startsWith(t)).map(e=>({label:e.name,apply:U9(e.name,n),detail:e.detail}));if(r.length)return{from:e.pos-t.length,to:e.pos+ +(e.state.sliceDoc(e.pos,e.pos+1)===`"`),options:r,validFor:/^[\w.-]*$/}}let a=/lookup\(\s*"[^"]+"\s*,\s*[^,]+,\s*"?([\w-]*)"?$/.exec(r);if(a){let t=/lookup\(\s*"([^"]+)"/.exec(r)?.[1],n=V9.find(e=>e.name===t),i=e.pos-a[1].length,o=e.state.sliceDoc(i-1,i)===`"`,s=(n?.fields??[]).filter(e=>e.startsWith(a[1])).map(e=>({label:e,apply:U9(e,o),detail:`${t} field`}));return{from:i,to:e.pos+ +(e.state.sliceDoc(e.pos,e.pos+1)===`"`),options:s,validFor:/^[\w-]*$/}}let o=/lookup\(\s*"(effort)"\s*,\s*"?([\w.-]*)"?$/.exec(r);if(o){let t=n().filter(e=>e.startsWith(o[2])),r=e.pos-o[2].length,i=e.state.sliceDoc(r-1,r)===`"`,a=t.map(e=>({label:e,apply:e===`effort`?e:U9(e,i),detail:`effort key`}));return{from:r,to:e.pos+ +(e.state.sliceDoc(e.pos,e.pos+1)===`"`),options:a,validFor:/^[\w.-]*$/}}}let a=/->\s*([\w/]*)$/.exec(r);if(a){let n=e.state.doc.lineAt(e.pos).text,r=F9(n,t);if(!r.dim){let e=n.lastIndexOf(`->`);if(e>=0){let i=F9(n.slice(0,e),t);i.diagnostics.length===0&&(r=i)}}let i=r.diagnostics.length===0?r.dim:void 0,o=ote(i).filter(e=>e.startsWith(a[1])).map(e=>({label:e,detail:i?`matches inferred dimension`:`unit`}));return{from:e.pos-a[1].length,options:o,validFor:/^[\w/]*$/}}if(t===`store`){let e=/^(sum|avg|max|min|count|last):([\w.]*)$/.exec(i.text);if(e){let t=B9.filter(t=>t.startsWith(e[2])).map(e=>({label:e,detail:`metric key`}));return{from:i.from+i.text.indexOf(`:`)+1,options:t,validFor:/^[\w.]*$/}}}let o=[];if(t===`segment`)o.push(...R9.map(e=>({label:e.name,apply:e.name,detail:e.detail})));else if(o.push(...z9.map(e=>({label:e.name,apply:e.name,detail:e.detail}))),t===`workout`){for(let e of ite)for(let t of[`reps`,`distance`,`segmentVolume`,`metMinutes`,`elapsed`,`effortRpe`])o.push({label:`${e}(${t})`,apply:`${e}(${t})`,detail:`aggregate`});o.push({label:`sum(reps, without: rest)`,apply:`sum(reps, without: rest)`,detail:`exclusion aggregate`})}o.push(...L9.map(e=>({label:`${e}()`,apply:`${e}()`,detail:`function`}))),t===`store`&&o.push(...ate.map(e=>({label:`${e}:{}`,apply:`${e}:`,detail:`WQL atom`}))),o.push(...I9.map(e=>({label:e,apply:e===`when`?`when `:e,detail:`clause`}))),o.push({label:`estimated`,apply:`estimated`,detail:`variant origin`}),o.push({label:`(library)`,apply:`(library)`,detail:`library calc`});let s=o.filter(e=>e.label.startsWith(i.text)).slice(0,20);return s.length?{from:i.from,options:s,validFor:/^[\w./]*$/}:null}}function _te(e){return Yr({override:[gte(e)],interactionDelay:0})}function vte({value:e,onChange:t,scope:n=`segment`,placeholder:r,readOnly:i=!1,autoFocus:a=!1,className:o}){let s=(0,U.useRef)(null),c=(0,U.useRef)(null),l=(0,U.useRef)(t);return l.current=t,(0,U.useEffect)(()=>{let t=s.current;if(!t)return;c.current?.destroy();let r=Or.updateListener.of(e=>{e.docChanged&&l.current(e.state.doc.toString())}),o=new Or({state:ii.create({doc:e,extensions:[mte(),_te({scope:n,effortKeys:()=>xO().list().map(e=>e.slug)}),Rw,$r(),mi(),xr.of([ni,...ei,...li]),Or.lineWrapping,ii.readOnly.of(i),r,Or.theme({"&":{height:`auto`,minHeight:`120px`,fontSize:`13px`,border:`1px solid rgb(63 63 70)`,borderRadius:`8px`},".cm-scroller":{fontFamily:`ui-monospace, SFMono-Regular, Menlo, monospace`,lineHeight:`1.55`},".cm-content":{padding:`8px 4px`},".cm-gutters":{borderRight:`1px solid rgb(63 63 70)`,minWidth:`28px`},"&.cm-focused":{outline:`2px solid rgb(139 92 246 / 0.5)`,outlineOffset:`1px`}})]}),parent:t});return a&&requestAnimationFrame(()=>o.focus()),c.current=o,()=>o.destroy()},[n,i]),(0,U.useEffect)(()=>{let t=c.current;if(!t)return;let n=t.state.doc.toString();n!==e&&t.dispatch({changes:{from:0,to:n.length,insert:e}})},[e]),(0,W.jsx)(`div`,{ref:s,className:`calc-line-editor ${o??``}`,"data-testid":`calc-line-editor`})}function yte({analysis:e}){let{dim:t,compound:n,diagnostics:r}=e,i=r.filter(e=>e.severity===`error`),a=r.filter(e=>e.severity===`warning`),o=i.length===0&&a.length===0&&t!==void 0;return(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/60 px-3 py-2 text-xs`,"data-testid":`calc-diagnostics`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[t?(0,W.jsxs)(`div`,{className:`text-muted-foreground`,children:[`computes `,(0,W.jsx)(`b`,{className:`text-foreground`,children:bte(t)}),n&&(0,W.jsxs)(`span`,{className:`text-purple-400 dark:text-purple-300`,children:[` → `,n]})]}):!o&&(0,W.jsx)(`div`,{className:`text-muted-foreground`,children:`dimension unknown`}),o&&(0,W.jsx)(`span`,{className:`text-signal-positive`,children:`✓ valid`})]}),i.map((e,t)=>(0,W.jsxs)(`div`,{className:`text-destructive`,children:[`⚠ `,e.message]},`e-${t}`)),a.map((e,t)=>(0,W.jsxs)(`div`,{className:`text-signal-caution`,children:[`⚠ `,e.message]},`w-${t}`)),i.length===0&&a.length===0&&t===void 0&&(0,W.jsx)(`div`,{className:`text-muted-foreground`,children:`Type a calc line to see diagnostics.`})]})}var W9=[[`L`,`length`],[`M`,`mass`],[`T`,`time`],[`C`,`count`],[`E`,`energy`]];function bte(e){let t=[];return e.forEach((e,n)=>{e!==0&&t.push(e===1?W9[n][1]:`${W9[n][1]}${e}`)}),t.length?t.join(`·`):`dimensionless`}function G9(e){return new ha({outputType:e.outputType,timeSpan:e.timeSpan,sourceBlockKey:e.sourceBlockKey,stackLevel:e.stackLevel,sourceStatementId:e.sourceStatementId,line:e.line,text:e.text,dialect:e.dialect,metrics:e.metrics,parent:e.parent,completionReason:e.completionReason})}function K9(e){return{...e,metrics:e.metrics.filter(e=>e.origin!==`analyzed`)}}function xte(e){return e.output?.emitType??e.output?.key??e.id}function Ste(e,t){for(let n of e){if(n.outputType!==`analytics`||!(n.metrics.find(e=>e.type?.toLowerCase()===`label`&&String(e.value)===t)??n.metrics.find(e=>String(e.value)===t)))continue;let e=n.metrics.find(e=>typeof e.value==`number`);if(e)return{value:e.value,unit:e.unit,origin:e.origin}}}function q9(e){return String(Number.isInteger(e)?e:Math.round(e*100)/100)}function J9(e,t,n){return tp(e,{userProfile:t.vo2max===void 0?void 0:{vo2max:t.vo2max},calcs:n}).engine}function Cte(e){let t=[],n=e.defs[0];if(!n)return{rows:[],errors:[`No calc line to preview.`]};let r=xte(n),i=e.logs.filter(e=>e.outputType===`segment`);if(e.scope===`segment`){let n=J9(e.block,e,e.defs),a=[];for(let e of i){let t=n.run(G9(K9(e))).metrics.rawMetrics.find(e=>e.type===r);if(!t){a.push(null);continue}let i=typeof t.value==`number`?t.value:NaN;if(!Number.isFinite(i)){a.push(null);continue}a.push({label:e.metrics.find(e=>e.type===`effort-data`)?.value?.label??`segment`,text:q9(i),unit:t.unit,estimated:t.origin===`analyzed-estimated`,raw:i})}return{rows:a,errors:t}}if(e.scope===`workout`){let n=i.map(K9),a=[];for(let t=1;t<=n.length;t++){let i=J9(e.block,e,e.defs);for(let e=0;e<t;e++)i.run(G9(n[e]));let o=Ste(i.finalize(),r),s=o&&typeof o.value==`number`?o.value:NaN;o&&Number.isFinite(s)?a.push({label:`after line ${t}`,text:q9(s),unit:o.unit,estimated:o.origin===`analyzed-estimated`,raw:s}):a.push(null)}return{rows:a,errors:t}}return wte(n,t)}var Y9=[420,0,380,510,0,290,610,450,0,520,340,0,480,390,560,0,410,470,0,530,360,440,0,500,580,320,0,460];function wte(e,t){let n=[],r=e.variants[0]?.nodes[Bp(e)??`value`]?.expression??``,i=e=>e.reduce((e,t)=>e+t,0)/e.length,a=e=>{let t=i(e);return Math.sqrt(i(e.map(e=>(e-t)**2)))},o=(e,t)=>Y9.map((n,r)=>r+1>=e?t(Y9.slice(r+1-e,r+1)):NaN),s=o(7,i),c=o(28,i),l=o(7,a),u=o(7,e=>e.reduce((e,t)=>e+t,0)),d=r.includes(`windowSd`)||r.length===0?s.map((e,t)=>e/l[t]):s.map((e,t)=>e/c[t]);return Tte(r.includes(`windowSum`)||r.includes(` * sum`)?u:d,n),{rows:[],series:n,errors:t}}function Tte(e,t){for(let n of e.slice(-7))t.push(Number.isNaN(n)?null:Number(Math.round(n*100)/100))}var Ete=[{label:`Thruster`,slug:`thruster`,met:8.5,discipline:`strength`,elapsedMs:15e4,reps:21,resistanceKg:43},{label:`Pull-up`,slug:`pull-up`,met:7,discipline:`gymnastics`,elapsedMs:12e4,reps:21,resistanceKg:0},{label:`Thruster`,slug:`thruster`,met:8.5,discipline:`strength`,elapsedMs:15e4,reps:15,resistanceKg:43},{label:`Pull-up`,slug:`pull-up`,met:7,discipline:`gymnastics`,elapsedMs:12e4,reps:15,resistanceKg:0},{label:`Thruster`,slug:`thruster`,met:8.5,discipline:`strength`,elapsedMs:15e4,reps:9,resistanceKg:43},{label:`Pull-up`,slug:`pull-up`,met:7,discipline:`gymnastics`,elapsedMs:12e4,reps:9,resistanceKg:0}];function Dte(e){return{type:`effort-data`,origin:`analyzed`,value:{slug:e.slug,label:e.label,aliases:[],baseAttributes:{met:e.met,discipline:e.discipline},registrySource:`bundled`}}}function Ote(e,t){let n=[Dte(e)];return n.push({type:`elapsed`,value:e.elapsedMs,origin:`runtime`}),e.reps!==void 0&&n.push({type:`rep`,value:e.reps,origin:`runtime`}),e.resistanceKg!==void 0&&n.push({type:`resistance`,value:e.resistanceKg,origin:`runtime`}),JN(new ha({outputType:`segment`,timeSpan:{started:t*1e3,ended:t*1e3+e.elapsedMs},sourceBlockKey:`preview-block`,stackLevel:1,metrics:n}))}function kte(){return{id:`preview-block`,dialect:`time`,startLine:0,endLine:10,content:"```time\nFran preview\n```",state:`idle`,widgetIds:{},version:1,createdAt:0}}var Ate=Ete.map((e,t)=>Ote(e,t+1)),jte=kte();function Mte(e){return e==null?`—`:String(e)}function Nte({scope:e,analysis:t,vo2max:n}){let r=(0,U.useMemo)(()=>t.defs.filter(()=>t.diagnostics.length===0),[t]),i=r[0],a=(0,U.useMemo)(()=>{if(i)return Cte({logs:Ate,block:jte,defs:r,scope:e,vo2max:n})},[i,e,n]);return(0,W.jsxs)(`div`,{className:`rounded-lg border border-border bg-card/60 p-3 text-xs`,"data-testid":`calc-preview`,children:[(0,W.jsxs)(`div`,{className:`mb-2 text-[11px] uppercase tracking-wide text-muted-foreground`,children:[`Live preview — `,e===`store`?`last 7 of 28 fixture days`:`Fran (fixture)`]}),!i&&(0,W.jsx)(`div`,{className:`text-muted-foreground`,children:`Enter a valid calc line to see live results.`}),i&&a?.rows&&(0,W.jsxs)(`div`,{className:`space-y-1 font-mono`,children:[a.rows.length===0&&(0,W.jsx)(`div`,{className:`text-muted-foreground`,children:`No applicable segments.`}),a.rows.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex justify-between text-foreground`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:e?e.label:`segment ${t+1}`}),(0,W.jsx)(`span`,{className:e?`text-sky-300 dark:text-sky-400`:`text-muted-foreground`,children:e?`${e.text}${e.unit?` ${e.unit}`:``}${e.estimated?` (est.)`:``}`:`—`})]},t))]}),i&&a?.series&&(0,W.jsx)(`div`,{className:`space-y-1 font-mono`,children:a.series.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex justify-between text-foreground`,children:[(0,W.jsxs)(`span`,{className:`text-muted-foreground`,children:[`D-`,6-t]}),(0,W.jsx)(`span`,{className:`text-sky-300 dark:text-sky-400`,children:Mte(e)})]},t))}),a?.errors?.length?a.errors.map((e,t)=>(0,W.jsxs)(`div`,{className:`text-destructive`,children:[`⚠ `,e]},`e-${t}`)):null]})}var Pte=[`segment`,`workout`,`store`];function Fte(e,t){let n=e[0]?.id;if(n)return n;let r=/^[\s\S]*?^\s*([A-Za-z_][\w.-]*)\s*=.*$/m.exec(t);return r?r[1]:`custom-${Date.now().toString(36)}`}function Ite({defaultScope:e=`segment`,initialId:t}){let[n,r]=(0,U.useState)(`# ${e} calc line
489
489
  segmentVolume = reps * resistance (library) when has(reps) and has(resistance)
490
- `),[i,a]=(0,U.useState)(e),[o,s]=(0,U.useState)([]),[c,l]=(0,U.useState)(),u=(0,U.useMemo)(()=>F9(n,i),[n,i]),d=Fte(u.defs,n),f=u.diagnostics.every(e=>e.severity!==`error`)&&u.defs.length>0,p=async()=>{s(await v8())};(0,U.useEffect)(()=>{p()},[]),(0,U.useEffect)(()=>{t&&(async()=>{let e=(await v8()).find(e=>e.id===t);e&&(r(e.lineForm),l(`Loaded "${e.id}".`))})()},[t]);let m=async()=>{if(!f){l(`Cannot save: fix the errors first.`);return}try{await y8({id:d,lineForm:n,updatedAt:Date.now()}),await p(),l(`Saved "${d}".`)}catch(e){console.error(`[CalcAuthoringPanel] save failed:`,e),l(`Save failed: ${e instanceof Error?e.message:String(e)}`)}},h=async e=>{try{await b8(e),await p(),l(`Deleted "${e}".`)}catch(e){console.error(`[CalcAuthoringPanel] delete failed:`,e),l(`Delete failed: ${e instanceof Error?e.message:String(e)}`)}},g=e=>{let t=/^\s*(segment|workout|store)\b/.exec(e.lineForm);t&&a(t[1]),r(e.lineForm),l(`Loaded "${e.id}".`)};return(0,W.jsxs)(`div`,{className:`space-y-3`,"data-testid":`calc-authoring-panel`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Scope`}),(0,W.jsx)(`div`,{className:`flex gap-1`,children:Pte.map(e=>(0,W.jsx)(`button`,{onClick:()=>a(e),className:`rounded px-2.5 py-1 text-xs font-medium transition-colors ${i===e?`bg-purple-600 text-white dark:bg-purple-700 dark:text-white`:`bg-muted text-muted-foreground hover:bg-muted/80`}`,children:e},e))}),(0,W.jsx)(`div`,{className:`ml-auto flex gap-2`,children:(0,W.jsx)(`button`,{onClick:m,disabled:!f,className:`rounded bg-signal-positive px-3 py-1 text-xs font-medium text-white dark:text-white disabled:opacity-40`,children:`Save`})})]}),(0,W.jsx)(vte,{value:n,onChange:r,scope:i,autoFocus:!0}),(0,W.jsx)(yte,{analysis:u}),(0,W.jsx)(Nte,{scope:i,analysis:u}),c&&(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:c}),o.length>0&&(0,W.jsxs)(`div`,{className:`mt-2`,children:[(0,W.jsx)(`div`,{className:`mb-1 text-[11px] uppercase tracking-wide text-muted-foreground`,children:`Saved user calcs`}),(0,W.jsx)(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,children:o.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center justify-between px-3 py-2 text-sm`,children:[(0,W.jsx)(`button`,{onClick:()=>g(e),className:`text-left font-mono text-purple-300 dark:text-purple-400 hover:underline`,children:e.id}),(0,W.jsx)(`button`,{onClick:()=>h(e.id),className:`text-xs text-muted-foreground hover:text-destructive`,children:`delete`})]},e.id))})]})]})}function Lte(){let e=Vn(),[t]=Kt(`zip`),[n]=Kt(`z`),[r]=(0,U.useState)(()=>{let e=window.location.search;return e.includes(`zip=`)||e.includes(`z=`)});return(0,U.useEffect)(()=>{!t&&!n&&!r&&e(`/`,{replace:!0})},[t,n,e,r]),(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}async function X9(e){try{let t=e.replace(/-/g,`+`).replace(/_/g,`/`);for(;t.length%4!=0;)t+=`=`;let n=atob(t),r=Uint8Array.from(n,e=>e.charCodeAt(0));try{let e=new DecompressionStream(`gzip`),t=e.writable.getWriter(),n=e.readable.getReader();t.write(r),t.close();let i=[];for(;;){let{done:e,value:t}=await n.read();if(e)break;i.push(t)}let a=i.reduce((e,t)=>e+t.length,0),o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.length;return new TextDecoder().decode(o)}catch{return new TextDecoder().decode(r)}}catch{return null}}function Z9(){let e=Vn(),t=Sn(),{date:n}=wt(),[r]=Kt(`zip`),[i,a]=(0,U.useState)({state:`loading`});return(0,U.useEffect)(()=>{if(!(t.pathname===`/load/journal`||t.pathname.startsWith(`/load/journal/`)))return;if(!r){e($.journal,{replace:!0});return}let i=!1,o=async()=>{try{a({state:`loading`});let t;try{t=await X9(r)}catch(e){console.error(`Failed to decode zip:`,e),a({state:`error`,error:`Failed to decode the journal entry`,onRetry:()=>{o()}}),Q({title:`Error`,description:`Failed to decode the journal entry. Please check the link.`,variant:`destructive`});return}if(i)return;let c;if(n){let t=yP(n);if(!t){a({state:`error`,error:`Invalid date format`}),Q({title:`Error`,description:`Invalid date format. Expected YYYY-MM-DD.`,variant:`destructive`}),e($.journal,{replace:!0});return}c=t.dateKey}else c=_P();if(i)return;if(vP(c)){a({state:`pending-confirmation`,content:t,dateKey:c,onConfirmBackdate:async()=>{i||await s(t,c)}});return}await s(t,c)}catch(e){console.error(`Unexpected error in journal zip processor:`,e),i||(a({state:`error`,error:`An unexpected error occurred`,onRetry:()=>{o()}}),Q({title:`Error`,description:`An unexpected error occurred.`,variant:`destructive`}))}},s=async(t,n)=>{if(!i)try{a({state:`creating`});let r=await CP.create({journalDate:n,title:n,rawContent:t});i||(a({state:`success`,content:t,dateKey:n}),e(TN(r.id),{replace:!0}))}catch(e){console.error(`Failed to create journal entry:`,e),i||(a({state:`error`,error:`Failed to create journal entry`,onRetry:()=>{s(t,n)}}),Q({title:`Error`,description:`Failed to create journal entry.`,variant:`destructive`}))}};return o(),()=>{i=!0}},[r,n,e]),i}var Rte=({selectedDate:e,onImportToday:t,onDateSelect:n,entryDates:r,isLoading:i=!1,className:a})=>{let[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(!1),{triggerRef:u,align:d,recompute:f}=v0(`end`),p=async()=>{l(!0);try{await t()}finally{l(!1)}},m=async e=>{l(!0),s(!1);try{await n(e)}finally{l(!1)}},h=e=>{e&&f(),s(e)},g=e?Ny(e):`Date`,_=i||c;return(0,W.jsxs)(`div`,{className:G(`inline-flex items-stretch rounded-lg overflow-hidden border border-border/70`,`bg-muted text-muted-foreground shadow-sm hover:shadow-md transition-shadow font-medium`,`text-xs`,a),children:[(0,W.jsxs)(`button`,{type:`button`,title:`Import to today's journal`,onClick:p,disabled:_,className:G(`flex items-center gap-2 px-3 py-2 transition-colors`,`hover:bg-accent hover:text-accent-foreground`,_&&`opacity-60 cursor-not-allowed`),children:[c?(0,W.jsx)(`span`,{className:`inline-block animate-spin`,children:`⏳`}):(0,W.jsx)(yn,{className:`h-4 w-4 shrink-0`}),(0,W.jsx)(`span`,{children:`Import Today`})]}),(0,W.jsx)(`div`,{className:`w-px bg-border/60 self-stretch`}),(0,W.jsxs)(ZB,{open:o,onOpenChange:h,children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsxs)(`button`,{ref:e=>{u.current=e},type:`button`,title:`Select a date to plan for the future`,className:G(`flex items-center gap-1.5 px-2.5 py-2 transition-colors`,`hover:bg-accent hover:text-accent-foreground`,e&&`text-primary`,_&&`opacity-60 cursor-not-allowed`),disabled:_,children:[(0,W.jsx)(Wt,{className:`h-4 w-4 shrink-0`}),e&&(0,W.jsx)(`span`,{className:`leading-none text-xs`,children:g})]})}),(0,W.jsx)($B,{align:d,className:`p-0 w-auto`,children:(0,W.jsx)(z1,{selectedDate:e||null,onDateSelect:m,entryDates:r})})]})]})},zte=({dateKey:e,onConfirm:t,onCancel:n,isLoading:r=!1})=>{let[i,a]=U.useState(!1),o=My(new Date(`${e}T00:00:00`));return(0,W.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,className:`fixed inset-0 z-50 flex items-center justify-center`,onKeyDown:e=>{e.key===`Escape`&&n()},onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,W.jsx)(`div`,{className:`absolute inset-0 bg-black/50 animate-in fade-in`}),(0,W.jsx)(`div`,{className:`relative z-10 w-full max-w-sm mx-auto px-4 animate-in zoom-in-95 fade-in`,children:(0,W.jsxs)(`div`,{className:`bg-background rounded-lg border border-border shadow-lg`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-border`,children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold`,children:`Backdate Journal Entry`}),(0,W.jsx)(`button`,{onClick:n,className:`p-1 text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`,"aria-label":`Close modal`,children:(0,W.jsx)(we,{className:`h-4 w-4`})})]}),(0,W.jsxs)(`div`,{className:`px-6 py-4 space-y-4`,children:[(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The date you selected is in the past.`}),(0,W.jsxs)(`p`,{className:`text-sm`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Import to: `}),(0,W.jsx)(`span`,{className:`font-medium text-foreground`,children:o})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This will create a journal entry for the selected date. Are you sure you want to proceed?`})]}),(0,W.jsxs)(`div`,{className:`px-6 py-4 border-t border-border flex gap-2 justify-end`,children:[(0,W.jsx)(K,{variant:`outline`,onClick:n,disabled:r||i,children:`Cancel`}),(0,W.jsx)(K,{onClick:async()=>{a(!0);try{await t()}finally{a(!1)}},disabled:r||i,className:G(r||i?`opacity-70`:``),children:i?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`inline-block animate-spin mr-2`,children:`⏳`}),`Importing...`]}):`Confirm & Import`})]})]})})]})},Bte={h1:({children:e})=>(0,W.jsx)(`h1`,{className:`text-3xl font-bold mt-8 mb-4 first:mt-0 text-foreground`,children:e}),h2:({children:e})=>(0,W.jsx)(`h2`,{className:`text-2xl font-bold mt-6 mb-3 text-foreground`,children:e}),h3:({children:e})=>(0,W.jsx)(`h3`,{className:`text-xl font-semibold mt-5 mb-2 text-foreground`,children:e}),h4:({children:e})=>(0,W.jsx)(`h4`,{className:`text-lg font-semibold mt-4 mb-2 text-foreground`,children:e}),h5:({children:e})=>(0,W.jsx)(`h5`,{className:`text-base font-semibold mt-3 mb-1 text-foreground`,children:e}),h6:({children:e})=>(0,W.jsx)(`h6`,{className:`text-sm font-semibold mt-2 mb-1 text-muted-foreground`,children:e}),p:({children:e})=>(0,W.jsx)(`p`,{className:`text-sm leading-relaxed mb-4 text-muted-foreground`,children:e}),strong:({children:e})=>(0,W.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,W.jsx)(`em`,{className:`italic text-muted-foreground`,children:e}),ul:({children:e})=>(0,W.jsx)(`ul`,{className:`list-disc list-inside space-y-1 mb-4 text-sm text-muted-foreground`,children:e}),ol:({children:e})=>(0,W.jsx)(`ol`,{className:`list-decimal list-inside space-y-1 mb-4 text-sm text-muted-foreground`,children:e}),li:({children:e})=>(0,W.jsx)(`li`,{className:`ml-2`,children:e}),code:({children:e,className:t})=>t?null:(0,W.jsx)(`code`,{className:`px-1.5 py-0.5 rounded bg-muted text-primary font-mono text-xs`,children:e}),pre:({children:e})=>(0,W.jsx)(`pre`,{className:`bg-muted rounded-lg p-4 overflow-x-auto mb-4 text-xs font-mono text-muted-foreground border border-border`,children:e}),blockquote:({children:e})=>(0,W.jsx)(`blockquote`,{className:`border-l-4 border-primary/30 pl-4 py-2 mb-4 italic text-muted-foreground text-sm`,children:e}),a:({href:e,children:t})=>(0,W.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary hover:underline font-medium`,children:t}),table:({children:e})=>(0,W.jsx)(`div`,{className:`my-4 overflow-x-auto rounded border border-border`,children:(0,W.jsx)(`table`,{className:`w-full text-xs`,children:e})}),thead:({children:e})=>(0,W.jsx)(`thead`,{className:`bg-muted/50`,children:e}),tbody:({children:e})=>(0,W.jsx)(`tbody`,{className:`divide-y divide-border/50`,children:e}),tr:({children:e})=>(0,W.jsx)(`tr`,{className:`hover:bg-muted/20 transition-colors`,children:e}),th:({children:e})=>(0,W.jsx)(`th`,{className:`px-3 py-2 text-left font-semibold text-foreground text-xs`,children:e}),td:({children:e})=>(0,W.jsx)(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e}),hr:()=>(0,W.jsx)(`hr`,{className:`my-6 border-border/50`})};function Q9(){let e=Vn(),t=Z9(),[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(null),{state:o,content:s,dateKey:c,error:l,onConfirmBackdate:u,onRetry:d}=t;return(0,W.jsxs)(`div`,{className:`flex flex-col h-screen bg-background`,children:[(0,W.jsxs)(`div`,{className:`border-b border-border/50 bg-muted/30 px-6 py-4 flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`button`,{onClick:()=>{e(-1)},className:`p-1.5 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Go back`,children:(0,W.jsx)(sr,{className:`h-5 w-5`})}),(0,W.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Import Journal Entry`})]}),o===`loading`?(0,W.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`inline-block animate-spin`,children:`⏳`}),`Preparing preview...`]}):o===`error`?(0,W.jsx)(K,{variant:`outline`,size:`sm`,onClick:d,children:`Retry`}):o===`pending-confirmation`||o===`creating`?null:(0,W.jsx)(Rte,{selectedDate:i,onImportToday:async()=>{u&&await u()},onDateSelect:async e=>{a(e);let t=new Date;t.setHours(0,0,0,0);let n=new Date(e);n.setHours(0,0,0,0),n<t?r(!0):u&&await u()},isLoading:o===`creating`})]}),(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-6`,children:[o===`loading`&&(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,W.jsx)(`div`,{className:`animate-spin`,children:`⏳`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading preview...`})]}),o===`error`&&(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,W.jsx)(`div`,{className:`bg-destructive/10 border border-destructive/50 rounded-lg p-4 max-w-md`,children:(0,W.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,W.jsx)(Qt,{className:`h-5 w-5 text-destructive mt-0.5 shrink-0`}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Error Loading Preview`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:l||`Failed to decode the zip content`})]})]})}),(0,W.jsx)(K,{onClick:d,variant:`outline`,children:`Try Again`})]}),o===`pending-confirmation`&&(0,W.jsx)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-foreground mb-2`,children:`Backdate Confirmation Required`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm mb-4`,children:`This date is in the past. Please confirm to proceed.`})]})}),o===`creating`&&(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,W.jsx)(`div`,{className:`animate-spin`,children:`⏳`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Creating journal entry...`})]}),o===`success`&&(0,W.jsx)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-foreground mb-2`,children:`✓ Entry Created`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Redirecting...`})]})}),o===`loading`||o===`error`||o===`pending-confirmation`||o===`creating`||o===`success`?null:s?(0,W.jsx)(`article`,{className:`prose prose-sm max-w-2xl mx-auto`,children:(0,W.jsx)(gn,{remarkPlugins:[Gn],components:Bte,children:s})}):null]}),n&&c&&(0,W.jsx)(zte,{dateKey:c,onConfirm:async()=>{u&&(r(!1),await u())},onCancel:()=>r(!1),isLoading:o===`creating`})]})}function Vte(){let e=Sn(),t=Vn(),[n,r]=(0,U.useState)({kind:`loading`}),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null);(0,U.useEffect)(()=>{let n=!0,i=new URLSearchParams(e.search).get(`source`);if(!i){t($.notebooks,{replace:!0});return}return r({kind:`loading`}),a(!1),l(null),(async()=>{try{let e=new URL(i);if(e.protocol!==`https:`||e.username||e.password||e.search||e.hash)throw Error(`Enter an HTTPS feed directory URL without credentials, query parameters, or a fragment.`);e.pathname.endsWith(`/`)||(e.pathname+=`/`);let t=await new $A(e.href).fetchManifest();n&&r({kind:`ready`,url:e.href,manifest:t})}catch(e){n&&r({kind:`error`,message:e instanceof Error?e.message:`Unable to read the feed manifest.`})}})(),()=>{n=!1}},[e.search,t]);let u=async e=>{if(!(n.kind!==`ready`||o)){s(!0),l(null);try{let r=Xj().find(e=>rA(new URL(e.url,window.location.href).href)===n.url)??uA(n.manifest.name?.trim()||new URL(n.url).hostname,n.url,{repositoryUrl:n.manifest.repositoryUrl}),a=await hM(r.id,{subscribe:!1});if(a!==`imported`&&a!==`current`)throw Error(`Feed import did not complete (${a}). Your existing content was kept.`);if(e){let e=Sj(r.id,i),t=hj(r.id,!0);if(!e||!t)throw Error(`Content imported, but subscription preferences could not be saved. Browser storage is unavailable; these choices last this session only.`)}t(`${$.notebooks}?manage=1`,{replace:!0})}catch(e){l(e instanceof Error?e.message:`Feed import failed. Your existing content was kept.`)}finally{s(!1)}}};return(0,W.jsxs)(`main`,{className:`mx-auto flex min-h-dvh w-full max-w-2xl flex-col justify-center gap-5 p-6`,"data-testid":`feed-subscription-intake`,children:[n.kind===`loading`&&(0,W.jsx)(`p`,{role:`status`,children:`Checking the feed manifest…`}),n.kind===`error`&&(0,W.jsx)(`p`,{role:`alert`,className:`break-words text-destructive`,children:n.message}),n.kind===`ready`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`h1`,{className:`text-xl font-semibold`,children:[`Subscribe to `,n.manifest.name?.trim()||new URL(n.url).hostname,`?`]}),(0,W.jsx)(`a`,{href:n.url,target:`_blank`,rel:`noopener noreferrer`,className:`break-all text-sm underline`,children:n.url}),n.manifest.description&&(0,W.jsx)(`p`,{children:n.manifest.description}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Opening this link has not added any content or source. Choose whether to import once or subscribe for future update checks.`}),(0,W.jsxs)(`dl`,{className:`grid grid-cols-2 gap-2 text-sm`,children:[(0,W.jsx)(`dt`,{children:`Published version`}),(0,W.jsxs)(`dd`,{children:[`v`,n.manifest.version]}),(0,W.jsx)(`dt`,{children:`Published at`}),(0,W.jsx)(`dd`,{children:new Date(n.manifest.builtAt).toLocaleString()}),(0,W.jsx)(`dt`,{children:`Schema`}),(0,W.jsxs)(`dd`,{children:[`v`,n.manifest.schema]}),(0,W.jsx)(`dt`,{children:`Chunks`}),(0,W.jsx)(`dd`,{children:n.manifest.chunks.length}),(0,W.jsx)(`dt`,{children:`Notebook items`}),(0,W.jsx)(`dd`,{children:n.manifest.chunks.reduce((e,t)=>e+t.count,0)}),(0,W.jsx)(`dt`,{children:`Download size`}),(0,W.jsxs)(`dd`,{children:[(n.manifest.chunks.reduce((e,t)=>e+t.bytes,0)/1024).toFixed(1),` KB`]})]}),n.manifest.repositoryUrl&&(0,W.jsx)(`a`,{href:n.manifest.repositoryUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-sm underline`,children:`Git source directory`}),(0,W.jsxs)(`label`,{className:`flex items-start gap-3 rounded-lg border border-border p-4`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),disabled:o,"aria-label":`Auto-sync this feed`,className:`mt-1 size-4 shrink-0`}),(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`span`,{className:`font-medium`,children:`Auto-sync this feed`}),(0,W.jsx)(`span`,{className:`mt-1 block text-sm text-muted-foreground`,children:`When subscribed, apply new versions in the background on page load. Off keeps updates manual. Import Once ignores this preference and creates no subscription.`})]})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsx)(K,{variant:`outline`,disabled:o,onClick:()=>void u(!1),children:`Import Once`}),(0,W.jsx)(K,{disabled:o,onClick:()=>void u(!0),children:o?`Importing…`:`Import & Subscribe`})]})]}),c&&(0,W.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:c}),(0,W.jsx)(K,{variant:`ghost`,disabled:o,onClick:()=>t($.notebooks,{replace:!0}),children:`Decline & Dismiss`})]})}async function Hte(e,t,n){let r=await Z.getNote(e);if(!r)return;let i=`:session{result:${n}}`;if(r.rawContent.includes(i))return;let a=Object.values(r.blocks??{}).find(e=>e.id===t);if(!a||a.to==null)return;let o=`${r.rawContent.slice(0,a.to)}\n\n\`\`\`query:table\n${i}\n\`\`\`${r.rawContent.slice(a.to)}`;await new Kk().updateRecord(r.id,{rawContent:o,expectedSourceRevision:r.sourceRevision})}function Ute(){let{runtimeId:e}=wt(),t=Vn(),n=(0,U.useRef)(e?W1.get(e):void 0),r=(0,U.useRef)(null),i=(0,U.useCallback)(async()=>{let t=n.current;if(!t||!e)throw Error(`The pending workout is unavailable.`);return t.captured?(r.current=t.captured,t.captured.block):(r.current||=t.snapshot?await DR(t.snapshot,t.block,e,t.origin):await OR(t.noteId,t.block,e,t.origin),r.current.block)},[e]);(0,U.useEffect)(()=>{e&&W1.delete(e)},[e]);let a=n.current,o=(0,U.useRef)(!1),s=(0,U.useCallback)((t,n)=>!n||!e||!a?Promise.reject(Error(`Run cannot be saved — its session data or runtime id is missing.`)):(o.current=n.completed,iK.record({runBlock:a.block,blockId:a.block.id,noteId:a.noteId,resultId:e,data:n,createdAt:n.endTime||Date.now(),...a.origin?{origin:a.origin}:{}}).then(async()=>{if(n.completed)try{await Hte(a.noteId,a.block.id,e)}catch{}})),[e,a]),c=(0,U.useCallback)(()=>{if(!a){t(`/`);return}if(o.current){t(AN(e),{replace:!0});return}if(a.returnTo){t(a.returnTo,{replace:!0});return}t($1(cz(a.noteId)),{replace:!0})},[e,a,t]);return a?(0,W.jsx)(OZ,{block:a.block,prepareRun:i,onClose:c,onCompleteWorkout:s,resultId:e,autoStart:!0}):(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-red-400`,children:`Runtime not found. Please start the workout from the editor.`})}var $9=null;async function Wte(e){(!$9||$9.attempt!==e)&&($9={attempt:e,promise:bq(w0.content)});try{return await $9.promise}finally{$9?.attempt===e&&($9=null)}}function Gte(){let e=Vn(),[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await Wte(r);t||e(SN(n),{replace:!0})}catch{t||n(!0)}})(),()=>{t=!0}},[e,r]),t?(0,W.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center gap-3 text-zinc-300 px-4 text-center`,children:[(0,W.jsx)(`p`,{role:`alert`,children:`Unable to create a new playground note.`}),(0,W.jsx)(`button`,{type:`button`,className:`rounded border border-zinc-600 px-3 py-1 text-sm hover:bg-zinc-800`,onClick:()=>{n(!1),i(e=>e+1)},children:`Try again`})]}):(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}function Kte(){let e=Vn(),t=Sn(),[n]=Kt(`zip`),[r]=Kt(`z`),[i]=Kt(`by`),[a]=Kt(`src`);(0,U.useEffect)(()=>{if(t.pathname!==`/load`&&!(t.pathname===`/`&&r))return;if(r){let t=!1;return(async()=>{try{let e=await X9(r);if(e===null)throw Error(`Invalid workout link`);if(t)return;let n=D0(e,i??void 0);if(await xq(n,{reuseKey:`home`,title:`Home playground`}),t)return;A0({content:n,by:i??void 0})}catch(e){console.error(`Failed to decode zip:`,e),t||Q({title:`Could not import workout`,description:`The link was invalid or the workout could not be saved.`,variant:`destructive`})}t||e(`/`,{replace:!0})})(),()=>{t=!0}}if(!n)return;let o=!1,s=a&&a.startsWith(`/`)?a:void 0;return(async()=>{try{let t=await X9(n);if(t===null)throw Error(`Invalid workout link`);if(o)return;let r=s?await bq(t,{sourcePath:s}):await bq(t);o||e(SN(r),{replace:!0})}catch(t){console.error(`Failed to decode zip:`,t),o||(Q({title:`Could not import workout`,description:`The link was invalid or the workout could not be saved.`,variant:`destructive`}),e($.home,{replace:!0}))}})(),()=>{o=!0}},[n,r,i,a,e,t.pathname])}function qte(){let{pathname:e,hash:t}=Sn(),{scrollToSection:n}=WM();return(0,U.useEffect)(()=>{if(t){let e=t.slice(1);n(e);let r=setTimeout(()=>{n(e)},50);return()=>clearTimeout(r)}window.scrollTo(0,0)},[e,t]),null}function Jte(){return Kte(),Z9(),(0,U.useEffect)(()=>{Ok.current().catch(console.error),ZO(),I4(),Nj().catch(()=>{})},[]),null}function Yte({settling:e}){let t=P4();if(e){let e=q2(t);return(0,W.jsxs)(`div`,{role:`status`,className:`flex min-h-dvh flex-col items-center justify-center gap-2 text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:t?K2(t):`Loading library…`}),e&&(0,W.jsx)(`span`,{className:`text-xs`,"data-testid":`boot-progress-detail`,children:e})]})}return(0,W.jsxs)(`div`,{role:`alert`,className:`flex min-h-dvh flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-semibold`,children:`The library's routed content failed to load.`}),(0,W.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:`The feed corpus has not supplied this page. Re-running the feed import usually restores it.`}),(0,W.jsx)(K,{variant:`outline`,size:`sm`,"data-testid":`root-refeed`,onClick:()=>{pM().then(()=>KO())},children:`Re-import library`})]})}function Xte(){let e=(0,U.useRef)(()=>{}),t=qL(),n=N4(),r=(0,U.useMemo)(()=>gL(()=>e.current(),t),[t]);return(0,W.jsx)(ji,{defaultTheme:`system`,storageKey:`wod-wiki-playground-theme`,children:(0,W.jsx)(Dy,{children:(0,W.jsx)(Mee,{children:(0,W.jsx)(Nee,{children:(0,W.jsx)(YA,{children:(0,W.jsx)(Kn,{children:(0,W.jsxs)(Nt,{children:[(0,W.jsx)(Jte,{}),(0,W.jsx)(zM,{}),(0,W.jsxs)(KM,{tree:r,children:[(0,W.jsx)(qte,{}),(0,W.jsxs)(ht,{children:[(0,W.jsx)(V,{path:$.home,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`*`,element:t.length===0?(0,W.jsx)(Yte,{settling:n===`preparing`||Yj()&&n!==`error`}):(0,W.jsx)(Z7,{})}),(0,W.jsx)(V,{path:`/proto/calc-authoring`,element:(0,W.jsx)(Wee,{})}),(0,W.jsx)(V,{path:`/proto/query-block-composer`,element:(0,W.jsx)(ete,{})}),(0,W.jsx)(V,{path:`/settings`,element:(0,W.jsx)(In,{to:`/settings/appearance`,replace:!0})}),(0,W.jsx)(V,{path:`/settings/appearance`,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsProfile,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsData,element:(0,W.jsx)(In,{to:$.settingsStorage,replace:!0})}),(0,W.jsx)(V,{path:$.settingsDatabase,element:(0,W.jsx)(In,{to:$.settingsStorage,replace:!0})}),(0,W.jsx)(V,{path:$.settingsStorage,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsSync,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`/settings/system`,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsQueries,element:(0,W.jsx)(In,{to:$.journal,replace:!0})}),(0,W.jsx)(V,{path:$.settingsTags,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsSoundProfiles,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`/settings/library/calcs`,element:(0,W.jsx)(`div`,{className:`p-6`,children:(0,W.jsx)(Ite,{})})}),(0,W.jsx)(V,{path:`/legacy`,element:(0,W.jsx)(F7,{})}),(0,W.jsx)(V,{path:`/syntax`,element:(0,W.jsx)(X7,{})}),(0,W.jsx)(V,{path:$.plan,element:(0,W.jsx)(S7,{})}),(0,W.jsx)(V,{path:$.feeds,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.feed,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebooks,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebook,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebookTarget,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebookItem,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.subscribe,element:(0,W.jsx)(Vte,{})}),(0,W.jsx)(V,{path:$.pages,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.page,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.load,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Lte,{})})}),(0,W.jsx)(V,{path:$.loadJournal,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Q9,{})})}),(0,W.jsx)(V,{path:$.loadJournalDate,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Q9,{})})}),(0,W.jsx)(V,{path:$.playgroundRoot,element:(0,W.jsx)(Gte,{})}),(0,W.jsx)(V,{path:$.playground,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.playgrounds,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notes,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.note,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.journal,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.day,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.run,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Ute,{})})}),(0,W.jsx)(V,{path:$.tracker,element:(0,W.jsx)(b7,{})}),(0,W.jsx)(V,{path:`/results/segments`,element:(0,W.jsx)(y7,{})}),(0,W.jsx)(V,{path:$.sessionDetail,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.sessions,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.sessionDate,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`/review/:runtimeId`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:`/note/:noteId/review`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:`/note/:noteId/review/:sectionId`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:`/note/:noteId/review/:sectionId/:resultId`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:$.efforts,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.effort,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.equipment,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.equipmentSlug,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.tags,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.tag,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.dashboards,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.dashboardView,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),t.map(({route:t})=>(0,W.jsx)(V,{path:t,element:(0,W.jsx)(_7,{searchHandlerRef:e})},t))]}),(0,W.jsx)(D7,{})]})]})})})})})})})}function Zte({error:e,onRetry:t}){let n=e instanceof Error?e.message:String(e),r=vk();return(0,W.jsxs)(`div`,{role:`alert`,className:`flex min-h-dvh flex-col items-center justify-center gap-4 p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-semibold`,children:`The local database could not be opened.`}),(0,W.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground font-mono break-all`,"data-testid":`boot-recovery-error`,children:n}),(0,W.jsxs)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:[`Your stored data has not been cleared. Retry after resolving the error above.`,r.state!==`indexed-db`&&` Turn off Turso Sync to skip backup comparison. Settings → Storage has the full controls once the app loads.`]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:t,"data-testid":`boot-recovery-retry`,className:`rounded-md border border-border bg-card px-3 py-1.5 text-xs font-medium hover:bg-accent`,children:`Retry`}),r.state!==`indexed-db`&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>{wk(),window.location.reload()},"data-testid":`boot-recovery-local`,className:`rounded-md border border-border bg-card px-3 py-1.5 text-xs font-medium hover:bg-accent`,children:`Turn off Turso Sync`})]}),r.state!==`indexed-db`&&(0,W.jsxs)(`details`,{className:`w-full max-w-md rounded-xl border border-border bg-card p-4 text-left`,children:[(0,W.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium`,children:`Fix Turso credentials`}),(0,W.jsx)(`div`,{className:`pt-3`,children:(0,W.jsx)(Z5,{saved:r.state===`turso`?{url:r.url,authToken:r.authToken}:void 0})})]})]})}function Qte(){let e=(0,U.useSyncExternalStore)(qx,Kx),t=e.phase===`updating`;return(0,W.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex min-h-dvh flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-semibold`,children:t?`Updating local database…`:`Checking for storage updates…`}),t&&e.fromVersion!==null&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Schema v`,e.fromVersion,` → v`,e.toVersion]}),e.message&&(0,W.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:e.message})]})}var $te=(0,ki.createRoot)(document.getElementById(`root`));function ene(){let[e,t]=(0,U.useState)(!1),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(0),o=(0,U.useSyncExternalStore)(qx,Kx);return(0,U.useEffect)(()=>{let e=!1,n;return Pk().then(()=>VP?KP():void 0).then(()=>zA.ensureNotebooks().catch(e=>SR(`NotebookService`,`ensureNotebooks failed`,e))).then(()=>{e||(n=Rk(),t(!0))}).catch(t=>{e||r(t)}),()=>{e=!0,n?.()}},[i]),n?(0,W.jsx)(Zte,{error:n,onRetry:()=>{r(null),a(e=>e+1)}}):o.phase===`checking`||o.phase===`updating`?(0,W.jsx)(Qte,{}):e?(0,W.jsx)(Xte,{}):(0,W.jsx)(`div`,{role:`status`,className:`flex min-h-dvh items-center justify-center text-muted-foreground`,children:`Opening local library…`})}$te.render((0,W.jsx)(U.StrictMode,{children:(0,W.jsx)(ene,{})}));export{TH as t};
491
- //# sourceMappingURL=main-DAHoAykp.js.map
490
+ `),[i,a]=(0,U.useState)(e),[o,s]=(0,U.useState)([]),[c,l]=(0,U.useState)(),u=(0,U.useMemo)(()=>F9(n,i),[n,i]),d=Fte(u.defs,n),f=u.diagnostics.every(e=>e.severity!==`error`)&&u.defs.length>0,p=async()=>{s(await v8())};(0,U.useEffect)(()=>{p()},[]),(0,U.useEffect)(()=>{t&&(async()=>{let e=(await v8()).find(e=>e.id===t);e&&(r(e.lineForm),l(`Loaded "${e.id}".`))})()},[t]);let m=async()=>{if(!f){l(`Cannot save: fix the errors first.`);return}try{await y8({id:d,lineForm:n,updatedAt:Date.now()}),await p(),l(`Saved "${d}".`)}catch(e){console.error(`[CalcAuthoringPanel] save failed:`,e),l(`Save failed: ${e instanceof Error?e.message:String(e)}`)}},h=async e=>{try{await b8(e),await p(),l(`Deleted "${e}".`)}catch(e){console.error(`[CalcAuthoringPanel] delete failed:`,e),l(`Delete failed: ${e instanceof Error?e.message:String(e)}`)}},g=e=>{let t=/^\s*(segment|workout|store)\b/.exec(e.lineForm);t&&a(t[1]),r(e.lineForm),l(`Loaded "${e.id}".`)};return(0,W.jsxs)(`div`,{className:`space-y-3`,"data-testid":`calc-authoring-panel`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Scope`}),(0,W.jsx)(`div`,{className:`flex gap-1`,children:Pte.map(e=>(0,W.jsx)(`button`,{onClick:()=>a(e),className:`rounded px-2.5 py-1 text-xs font-medium transition-colors ${i===e?`bg-purple-600 text-white dark:bg-purple-700 dark:text-white`:`bg-muted text-muted-foreground hover:bg-muted/80`}`,children:e},e))}),(0,W.jsx)(`div`,{className:`ml-auto flex gap-2`,children:(0,W.jsx)(`button`,{onClick:m,disabled:!f,className:`rounded bg-signal-positive px-3 py-1 text-xs font-medium text-white dark:text-white disabled:opacity-40`,children:`Save`})})]}),(0,W.jsx)(vte,{value:n,onChange:r,scope:i,autoFocus:!0}),(0,W.jsx)(yte,{analysis:u}),(0,W.jsx)(Nte,{scope:i,analysis:u}),c&&(0,W.jsx)(`div`,{className:`text-xs text-muted-foreground`,children:c}),o.length>0&&(0,W.jsxs)(`div`,{className:`mt-2`,children:[(0,W.jsx)(`div`,{className:`mb-1 text-[11px] uppercase tracking-wide text-muted-foreground`,children:`Saved user calcs`}),(0,W.jsx)(`ul`,{className:`divide-y divide-border rounded-lg border border-border`,children:o.map(e=>(0,W.jsxs)(`li`,{className:`flex items-center justify-between px-3 py-2 text-sm`,children:[(0,W.jsx)(`button`,{onClick:()=>g(e),className:`text-left font-mono text-purple-300 dark:text-purple-400 hover:underline`,children:e.id}),(0,W.jsx)(`button`,{onClick:()=>h(e.id),className:`text-xs text-muted-foreground hover:text-destructive`,children:`delete`})]},e.id))})]})]})}function Lte(){let e=Vn(),[t]=Kt(`zip`),[n]=Kt(`z`),[r]=(0,U.useState)(()=>{let e=window.location.search;return e.includes(`zip=`)||e.includes(`z=`)});return(0,U.useEffect)(()=>{!t&&!n&&!r&&e(`/`,{replace:!0})},[t,n,e,r]),(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}async function X9(e){try{let t=e.replace(/-/g,`+`).replace(/_/g,`/`);for(;t.length%4!=0;)t+=`=`;let n=atob(t),r=Uint8Array.from(n,e=>e.charCodeAt(0));try{let e=new DecompressionStream(`gzip`),t=e.writable.getWriter(),n=e.readable.getReader();t.write(r),t.close();let i=[];for(;;){let{done:e,value:t}=await n.read();if(e)break;i.push(t)}let a=i.reduce((e,t)=>e+t.length,0),o=new Uint8Array(a),s=0;for(let e of i)o.set(e,s),s+=e.length;return new TextDecoder().decode(o)}catch{return new TextDecoder().decode(r)}}catch{return null}}function Z9(){let e=Vn(),t=Sn(),{date:n}=wt(),[r]=Kt(`zip`),[i,a]=(0,U.useState)({state:`loading`});return(0,U.useEffect)(()=>{if(!(t.pathname===`/load/journal`||t.pathname.startsWith(`/load/journal/`)))return;if(!r){e($.journal,{replace:!0});return}let i=!1,o=async()=>{try{a({state:`loading`});let t;try{t=await X9(r)}catch(e){console.error(`Failed to decode zip:`,e),a({state:`error`,error:`Failed to decode the journal entry`,onRetry:()=>{o()}}),Q({title:`Error`,description:`Failed to decode the journal entry. Please check the link.`,variant:`destructive`});return}if(i)return;let c;if(n){let t=yP(n);if(!t){a({state:`error`,error:`Invalid date format`}),Q({title:`Error`,description:`Invalid date format. Expected YYYY-MM-DD.`,variant:`destructive`}),e($.journal,{replace:!0});return}c=t.dateKey}else c=_P();if(i)return;if(vP(c)){a({state:`pending-confirmation`,content:t,dateKey:c,onConfirmBackdate:async()=>{i||await s(t,c)}});return}await s(t,c)}catch(e){console.error(`Unexpected error in journal zip processor:`,e),i||(a({state:`error`,error:`An unexpected error occurred`,onRetry:()=>{o()}}),Q({title:`Error`,description:`An unexpected error occurred.`,variant:`destructive`}))}},s=async(t,n)=>{if(!i)try{a({state:`creating`});let r=await CP.create({journalDate:n,title:n,rawContent:t});i||(a({state:`success`,content:t,dateKey:n}),e(TN(r.id),{replace:!0}))}catch(e){console.error(`Failed to create journal entry:`,e),i||(a({state:`error`,error:`Failed to create journal entry`,onRetry:()=>{s(t,n)}}),Q({title:`Error`,description:`Failed to create journal entry.`,variant:`destructive`}))}};return o(),()=>{i=!0}},[r,n,e]),i}var Rte=({selectedDate:e,onImportToday:t,onDateSelect:n,entryDates:r,isLoading:i=!1,className:a})=>{let[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(!1),{triggerRef:u,align:d,recompute:f}=o0(`end`),p=async()=>{l(!0);try{await t()}finally{l(!1)}},m=async e=>{l(!0),s(!1);try{await n(e)}finally{l(!1)}},h=e=>{e&&f(),s(e)},g=e?Ny(e):`Date`,_=i||c;return(0,W.jsxs)(`div`,{className:G(`inline-flex items-stretch rounded-lg overflow-hidden border border-border/70`,`bg-muted text-muted-foreground shadow-sm hover:shadow-md transition-shadow font-medium`,`text-xs`,a),children:[(0,W.jsxs)(`button`,{type:`button`,title:`Import to today's journal`,onClick:p,disabled:_,className:G(`flex items-center gap-2 px-3 py-2 transition-colors`,`hover:bg-accent hover:text-accent-foreground`,_&&`opacity-60 cursor-not-allowed`),children:[c?(0,W.jsx)(`span`,{className:`inline-block animate-spin`,children:`⏳`}):(0,W.jsx)(yn,{className:`h-4 w-4 shrink-0`}),(0,W.jsx)(`span`,{children:`Import Today`})]}),(0,W.jsx)(`div`,{className:`w-px bg-border/60 self-stretch`}),(0,W.jsxs)(ZB,{open:o,onOpenChange:h,children:[(0,W.jsx)(QB,{asChild:!0,children:(0,W.jsxs)(`button`,{ref:e=>{u.current=e},type:`button`,title:`Select a date to plan for the future`,className:G(`flex items-center gap-1.5 px-2.5 py-2 transition-colors`,`hover:bg-accent hover:text-accent-foreground`,e&&`text-primary`,_&&`opacity-60 cursor-not-allowed`),disabled:_,children:[(0,W.jsx)(Wt,{className:`h-4 w-4 shrink-0`}),e&&(0,W.jsx)(`span`,{className:`leading-none text-xs`,children:g})]})}),(0,W.jsx)($B,{align:d,className:`p-0 w-auto`,children:(0,W.jsx)(D1,{selectedDate:e||null,onDateSelect:m,entryDates:r})})]})]})},zte=({dateKey:e,onConfirm:t,onCancel:n,isLoading:r=!1})=>{let[i,a]=U.useState(!1),o=My(new Date(`${e}T00:00:00`));return(0,W.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,className:`fixed inset-0 z-50 flex items-center justify-center`,onKeyDown:e=>{e.key===`Escape`&&n()},onClick:e=>{e.target===e.currentTarget&&n()},children:[(0,W.jsx)(`div`,{className:`absolute inset-0 bg-black/50 animate-in fade-in`}),(0,W.jsx)(`div`,{className:`relative z-10 w-full max-w-sm mx-auto px-4 animate-in zoom-in-95 fade-in`,children:(0,W.jsxs)(`div`,{className:`bg-background rounded-lg border border-border shadow-lg`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between px-6 py-4 border-b border-border`,children:[(0,W.jsx)(`h2`,{className:`text-base font-semibold`,children:`Backdate Journal Entry`}),(0,W.jsx)(`button`,{onClick:n,className:`p-1 text-muted-foreground hover:text-foreground hover:bg-muted rounded transition-colors`,"aria-label":`Close modal`,children:(0,W.jsx)(we,{className:`h-4 w-4`})})]}),(0,W.jsxs)(`div`,{className:`px-6 py-4 space-y-4`,children:[(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`The date you selected is in the past.`}),(0,W.jsxs)(`p`,{className:`text-sm`,children:[(0,W.jsx)(`span`,{className:`text-muted-foreground`,children:`Import to: `}),(0,W.jsx)(`span`,{className:`font-medium text-foreground`,children:o})]}),(0,W.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`This will create a journal entry for the selected date. Are you sure you want to proceed?`})]}),(0,W.jsxs)(`div`,{className:`px-6 py-4 border-t border-border flex gap-2 justify-end`,children:[(0,W.jsx)(K,{variant:`outline`,onClick:n,disabled:r||i,children:`Cancel`}),(0,W.jsx)(K,{onClick:async()=>{a(!0);try{await t()}finally{a(!1)}},disabled:r||i,className:G(r||i?`opacity-70`:``),children:i?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`inline-block animate-spin mr-2`,children:`⏳`}),`Importing...`]}):`Confirm & Import`})]})]})})]})},Bte={h1:({children:e})=>(0,W.jsx)(`h1`,{className:`text-3xl font-bold mt-8 mb-4 first:mt-0 text-foreground`,children:e}),h2:({children:e})=>(0,W.jsx)(`h2`,{className:`text-2xl font-bold mt-6 mb-3 text-foreground`,children:e}),h3:({children:e})=>(0,W.jsx)(`h3`,{className:`text-xl font-semibold mt-5 mb-2 text-foreground`,children:e}),h4:({children:e})=>(0,W.jsx)(`h4`,{className:`text-lg font-semibold mt-4 mb-2 text-foreground`,children:e}),h5:({children:e})=>(0,W.jsx)(`h5`,{className:`text-base font-semibold mt-3 mb-1 text-foreground`,children:e}),h6:({children:e})=>(0,W.jsx)(`h6`,{className:`text-sm font-semibold mt-2 mb-1 text-muted-foreground`,children:e}),p:({children:e})=>(0,W.jsx)(`p`,{className:`text-sm leading-relaxed mb-4 text-muted-foreground`,children:e}),strong:({children:e})=>(0,W.jsx)(`strong`,{className:`font-semibold text-foreground`,children:e}),em:({children:e})=>(0,W.jsx)(`em`,{className:`italic text-muted-foreground`,children:e}),ul:({children:e})=>(0,W.jsx)(`ul`,{className:`list-disc list-inside space-y-1 mb-4 text-sm text-muted-foreground`,children:e}),ol:({children:e})=>(0,W.jsx)(`ol`,{className:`list-decimal list-inside space-y-1 mb-4 text-sm text-muted-foreground`,children:e}),li:({children:e})=>(0,W.jsx)(`li`,{className:`ml-2`,children:e}),code:({children:e,className:t})=>t?null:(0,W.jsx)(`code`,{className:`px-1.5 py-0.5 rounded bg-muted text-primary font-mono text-xs`,children:e}),pre:({children:e})=>(0,W.jsx)(`pre`,{className:`bg-muted rounded-lg p-4 overflow-x-auto mb-4 text-xs font-mono text-muted-foreground border border-border`,children:e}),blockquote:({children:e})=>(0,W.jsx)(`blockquote`,{className:`border-l-4 border-primary/30 pl-4 py-2 mb-4 italic text-muted-foreground text-sm`,children:e}),a:({href:e,children:t})=>(0,W.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,className:`text-primary hover:underline font-medium`,children:t}),table:({children:e})=>(0,W.jsx)(`div`,{className:`my-4 overflow-x-auto rounded border border-border`,children:(0,W.jsx)(`table`,{className:`w-full text-xs`,children:e})}),thead:({children:e})=>(0,W.jsx)(`thead`,{className:`bg-muted/50`,children:e}),tbody:({children:e})=>(0,W.jsx)(`tbody`,{className:`divide-y divide-border/50`,children:e}),tr:({children:e})=>(0,W.jsx)(`tr`,{className:`hover:bg-muted/20 transition-colors`,children:e}),th:({children:e})=>(0,W.jsx)(`th`,{className:`px-3 py-2 text-left font-semibold text-foreground text-xs`,children:e}),td:({children:e})=>(0,W.jsx)(`td`,{className:`px-3 py-2 text-muted-foreground`,children:e}),hr:()=>(0,W.jsx)(`hr`,{className:`my-6 border-border/50`})};function Q9(){let e=Vn(),t=Z9(),[n,r]=(0,U.useState)(!1),[i,a]=(0,U.useState)(null),{state:o,content:s,dateKey:c,error:l,onConfirmBackdate:u,onRetry:d}=t;return(0,W.jsxs)(`div`,{className:`flex flex-col h-screen bg-background`,children:[(0,W.jsxs)(`div`,{className:`border-b border-border/50 bg-muted/30 px-6 py-4 flex items-center justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`button`,{onClick:()=>{e(-1)},className:`p-1.5 rounded hover:bg-muted transition-colors text-muted-foreground hover:text-foreground`,title:`Go back`,children:(0,W.jsx)(sr,{className:`h-5 w-5`})}),(0,W.jsx)(`h1`,{className:`text-lg font-semibold text-foreground`,children:`Import Journal Entry`})]}),o===`loading`?(0,W.jsxs)(`div`,{className:`text-xs text-muted-foreground flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`inline-block animate-spin`,children:`⏳`}),`Preparing preview...`]}):o===`error`?(0,W.jsx)(K,{variant:`outline`,size:`sm`,onClick:d,children:`Retry`}):o===`pending-confirmation`||o===`creating`?null:(0,W.jsx)(Rte,{selectedDate:i,onImportToday:async()=>{u&&await u()},onDateSelect:async e=>{a(e);let t=new Date;t.setHours(0,0,0,0);let n=new Date(e);n.setHours(0,0,0,0),n<t?r(!0):u&&await u()},isLoading:o===`creating`})]}),(0,W.jsxs)(`div`,{className:`flex-1 overflow-auto px-6 py-6`,children:[o===`loading`&&(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,W.jsx)(`div`,{className:`animate-spin`,children:`⏳`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Loading preview...`})]}),o===`error`&&(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,W.jsx)(`div`,{className:`bg-destructive/10 border border-destructive/50 rounded-lg p-4 max-w-md`,children:(0,W.jsxs)(`div`,{className:`flex gap-3 items-start`,children:[(0,W.jsx)(Qt,{className:`h-5 w-5 text-destructive mt-0.5 shrink-0`}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h3`,{className:`font-semibold text-foreground`,children:`Error Loading Preview`}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground mt-1`,children:l||`Failed to decode the zip content`})]})]})}),(0,W.jsx)(K,{onClick:d,variant:`outline`,children:`Try Again`})]}),o===`pending-confirmation`&&(0,W.jsx)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-foreground mb-2`,children:`Backdate Confirmation Required`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm mb-4`,children:`This date is in the past. Please confirm to proceed.`})]})}),o===`creating`&&(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:[(0,W.jsx)(`div`,{className:`animate-spin`,children:`⏳`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Creating journal entry...`})]}),o===`success`&&(0,W.jsx)(`div`,{className:`flex flex-col items-center justify-center min-h-96 gap-4`,children:(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`h2`,{className:`text-lg font-semibold text-foreground mb-2`,children:`✓ Entry Created`}),(0,W.jsx)(`p`,{className:`text-muted-foreground text-sm`,children:`Redirecting...`})]})}),o===`loading`||o===`error`||o===`pending-confirmation`||o===`creating`||o===`success`?null:s?(0,W.jsx)(`article`,{className:`prose prose-sm max-w-2xl mx-auto`,children:(0,W.jsx)(gn,{remarkPlugins:[Gn],components:Bte,children:s})}):null]}),n&&c&&(0,W.jsx)(zte,{dateKey:c,onConfirm:async()=>{u&&(r(!1),await u())},onCancel:()=>r(!1),isLoading:o===`creating`})]})}function Vte(){let e=Sn(),t=Vn(),[n,r]=(0,U.useState)({kind:`loading`}),[i,a]=(0,U.useState)(!1),[o,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null);(0,U.useEffect)(()=>{let n=!0,i=new URLSearchParams(e.search).get(`source`);if(!i){t($.notebooks,{replace:!0});return}return r({kind:`loading`}),a(!1),l(null),(async()=>{try{let e=new URL(i);if(e.protocol!==`https:`||e.username||e.password||e.search||e.hash)throw Error(`Enter an HTTPS feed directory URL without credentials, query parameters, or a fragment.`);e.pathname.endsWith(`/`)||(e.pathname+=`/`);let t=await new $A(e.href).fetchManifest();n&&r({kind:`ready`,url:e.href,manifest:t})}catch(e){n&&r({kind:`error`,message:e instanceof Error?e.message:`Unable to read the feed manifest.`})}})(),()=>{n=!1}},[e.search,t]);let u=async e=>{if(!(n.kind!==`ready`||o)){s(!0),l(null);try{let r=Xj().find(e=>rA(new URL(e.url,window.location.href).href)===n.url)??uA(n.manifest.name?.trim()||new URL(n.url).hostname,n.url,{repositoryUrl:n.manifest.repositoryUrl}),a=await hM(r.id,{subscribe:!1});if(a!==`imported`&&a!==`current`)throw Error(`Feed import did not complete (${a}). Your existing content was kept.`);if(e){let e=Sj(r.id,i),t=hj(r.id,!0);if(!e||!t)throw Error(`Content imported, but subscription preferences could not be saved. Browser storage is unavailable; these choices last this session only.`)}t(`${$.notebooks}?manage=1`,{replace:!0})}catch(e){l(e instanceof Error?e.message:`Feed import failed. Your existing content was kept.`)}finally{s(!1)}}};return(0,W.jsxs)(`main`,{className:`mx-auto flex min-h-dvh w-full max-w-2xl flex-col justify-center gap-5 p-6`,"data-testid":`feed-subscription-intake`,children:[n.kind===`loading`&&(0,W.jsx)(`p`,{role:`status`,children:`Checking the feed manifest…`}),n.kind===`error`&&(0,W.jsx)(`p`,{role:`alert`,className:`break-words text-destructive`,children:n.message}),n.kind===`ready`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`h1`,{className:`text-xl font-semibold`,children:[`Subscribe to `,n.manifest.name?.trim()||new URL(n.url).hostname,`?`]}),(0,W.jsx)(`a`,{href:n.url,target:`_blank`,rel:`noopener noreferrer`,className:`break-all text-sm underline`,children:n.url}),n.manifest.description&&(0,W.jsx)(`p`,{children:n.manifest.description}),(0,W.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Opening this link has not added any content or source. Choose whether to import once or subscribe for future update checks.`}),(0,W.jsxs)(`dl`,{className:`grid grid-cols-2 gap-2 text-sm`,children:[(0,W.jsx)(`dt`,{children:`Published version`}),(0,W.jsxs)(`dd`,{children:[`v`,n.manifest.version]}),(0,W.jsx)(`dt`,{children:`Published at`}),(0,W.jsx)(`dd`,{children:new Date(n.manifest.builtAt).toLocaleString()}),(0,W.jsx)(`dt`,{children:`Schema`}),(0,W.jsxs)(`dd`,{children:[`v`,n.manifest.schema]}),(0,W.jsx)(`dt`,{children:`Chunks`}),(0,W.jsx)(`dd`,{children:n.manifest.chunks.length}),(0,W.jsx)(`dt`,{children:`Notebook items`}),(0,W.jsx)(`dd`,{children:n.manifest.chunks.reduce((e,t)=>e+t.count,0)}),(0,W.jsx)(`dt`,{children:`Download size`}),(0,W.jsxs)(`dd`,{children:[(n.manifest.chunks.reduce((e,t)=>e+t.bytes,0)/1024).toFixed(1),` KB`]})]}),n.manifest.repositoryUrl&&(0,W.jsx)(`a`,{href:n.manifest.repositoryUrl,target:`_blank`,rel:`noopener noreferrer`,className:`text-sm underline`,children:`Git source directory`}),(0,W.jsxs)(`label`,{className:`flex items-start gap-3 rounded-lg border border-border p-4`,children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:i,onChange:e=>a(e.target.checked),disabled:o,"aria-label":`Auto-sync this feed`,className:`mt-1 size-4 shrink-0`}),(0,W.jsxs)(`span`,{children:[(0,W.jsx)(`span`,{className:`font-medium`,children:`Auto-sync this feed`}),(0,W.jsx)(`span`,{className:`mt-1 block text-sm text-muted-foreground`,children:`When subscribed, apply new versions in the background on page load. Off keeps updates manual. Import Once ignores this preference and creates no subscription.`})]})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[(0,W.jsx)(K,{variant:`outline`,disabled:o,onClick:()=>void u(!1),children:`Import Once`}),(0,W.jsx)(K,{disabled:o,onClick:()=>void u(!0),children:o?`Importing…`:`Import & Subscribe`})]})]}),c&&(0,W.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:c}),(0,W.jsx)(K,{variant:`ghost`,disabled:o,onClick:()=>t($.notebooks,{replace:!0}),children:`Decline & Dismiss`})]})}async function Hte(e,t,n){let r=await Z.getNote(e);if(!r)return;let i=`:session{result:${n}}`;if(r.rawContent.includes(i))return;let a=Object.values(r.blocks??{}).find(e=>e.id===t);if(!a||a.to==null)return;let o=`${r.rawContent.slice(0,a.to)}\n\n\`\`\`query:table\n${i}\n\`\`\`${r.rawContent.slice(a.to)}`;await new Kk().updateRecord(r.id,{rawContent:o,expectedSourceRevision:r.sourceRevision})}function Ute(){let{runtimeId:e}=wt(),t=Vn(),n=(0,U.useRef)(e?M1.get(e):void 0),r=(0,U.useRef)(null),i=(0,U.useCallback)(async()=>{let t=n.current;if(!t||!e)throw Error(`The pending workout is unavailable.`);return t.captured?(r.current=t.captured,t.captured.block):(r.current||=t.snapshot?await DR(t.snapshot,t.block,e,t.origin):await OR(t.noteId,t.block,e,t.origin),r.current.block)},[e]);(0,U.useEffect)(()=>{e&&M1.delete(e)},[e]);let a=n.current,o=(0,U.useRef)(!1),s=(0,U.useCallback)((t,n)=>!n||!e||!a?Promise.reject(Error(`Run cannot be saved — its session data or runtime id is missing.`)):(o.current=n.completed,iK.record({runBlock:a.block,blockId:a.block.id,noteId:a.noteId,resultId:e,data:n,createdAt:n.endTime||Date.now(),...a.origin?{origin:a.origin}:{}}).then(async()=>{if(n.completed)try{await Hte(a.noteId,a.block.id,e)}catch{}})),[e,a]),c=(0,U.useCallback)(()=>{if(!a){t(`/`);return}if(o.current){t(AN(e),{replace:!0});return}if(a.returnTo){t(a.returnTo,{replace:!0});return}t(V1(cz(a.noteId)),{replace:!0})},[e,a,t]);return a?(0,W.jsx)(OZ,{block:a.block,prepareRun:i,onClose:c,onCompleteWorkout:s,resultId:e,autoStart:!0}):(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-red-400`,children:`Runtime not found. Please start the workout from the editor.`})}var $9=null;async function Wte(e){(!$9||$9.attempt!==e)&&($9={attempt:e,promise:bq(f0.content)});try{return await $9.promise}finally{$9?.attempt===e&&($9=null)}}function Gte(){let e=Vn(),[t,n]=(0,U.useState)(!1),[r,i]=(0,U.useState)(0);return(0,U.useEffect)(()=>{let t=!1;return(async()=>{try{let n=await Wte(r);t||e(SN(n),{replace:!0})}catch{t||n(!0)}})(),()=>{t=!0}},[e,r]),t?(0,W.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center gap-3 text-zinc-300 px-4 text-center`,children:[(0,W.jsx)(`p`,{role:`alert`,children:`Unable to create a new playground note.`}),(0,W.jsx)(`button`,{type:`button`,className:`rounded border border-zinc-600 px-3 py-1 text-sm hover:bg-zinc-800`,onClick:()=>{n(!1),i(e=>e+1)},children:`Try again`})]}):(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`})}function Kte(){let e=Vn(),t=Sn(),[n]=Kt(`zip`),[r]=Kt(`z`),[i]=Kt(`by`),[a]=Kt(`src`);(0,U.useEffect)(()=>{if(t.pathname!==`/load`&&!(t.pathname===`/`&&r))return;if(r){let t=!1;return(async()=>{try{let e=await X9(r);if(e===null)throw Error(`Invalid workout link`);if(t)return;let n=D0(e,i??void 0);if(await xq(n,{reuseKey:`home`,title:`Home playground`}),t)return;A0({content:n,by:i??void 0})}catch(e){console.error(`Failed to decode zip:`,e),t||Q({title:`Could not import workout`,description:`The link was invalid or the workout could not be saved.`,variant:`destructive`})}t||e(`/`,{replace:!0})})(),()=>{t=!0}}if(!n)return;let o=!1,s=a&&a.startsWith(`/`)?a:void 0;return(async()=>{try{let t=await X9(n);if(t===null)throw Error(`Invalid workout link`);if(o)return;let r=s?await bq(t,{sourcePath:s}):await bq(t);o||e(SN(r),{replace:!0})}catch(t){console.error(`Failed to decode zip:`,t),o||(Q({title:`Could not import workout`,description:`The link was invalid or the workout could not be saved.`,variant:`destructive`}),e($.home,{replace:!0}))}})(),()=>{o=!0}},[n,r,i,a,e,t.pathname])}function qte(){let{pathname:e,hash:t}=Sn(),{scrollToSection:n}=WM();return(0,U.useEffect)(()=>{if(t){let e=t.slice(1);n(e);let r=setTimeout(()=>{n(e)},50);return()=>clearTimeout(r)}window.scrollTo(0,0)},[e,t]),null}function Jte(){return Kte(),Z9(),(0,U.useEffect)(()=>{Ok.current().catch(console.error),ZO(),I4(),Nj().catch(()=>{})},[]),null}function Yte({settling:e}){let t=P4();if(e){let e=q2(t);return(0,W.jsxs)(`div`,{role:`status`,className:`flex min-h-dvh flex-col items-center justify-center gap-2 text-muted-foreground`,children:[(0,W.jsx)(`span`,{children:t?K2(t):`Loading library…`}),e&&(0,W.jsx)(`span`,{className:`text-xs`,"data-testid":`boot-progress-detail`,children:e})]})}return(0,W.jsxs)(`div`,{role:`alert`,className:`flex min-h-dvh flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-semibold`,children:`The library's routed content failed to load.`}),(0,W.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:`The feed corpus has not supplied this page. Re-running the feed import usually restores it.`}),(0,W.jsx)(K,{variant:`outline`,size:`sm`,"data-testid":`root-refeed`,onClick:()=>{pM().then(()=>KO())},children:`Re-import library`})]})}function Xte(){let e=(0,U.useRef)(()=>{}),t=qL(),n=N4(),r=(0,U.useMemo)(()=>gL(()=>e.current(),t),[t]);return(0,W.jsx)(ji,{defaultTheme:`system`,storageKey:`wod-wiki-playground-theme`,children:(0,W.jsx)(Dy,{children:(0,W.jsx)(Mee,{children:(0,W.jsx)(Nee,{children:(0,W.jsx)(YA,{children:(0,W.jsx)(Kn,{children:(0,W.jsxs)(Nt,{children:[(0,W.jsx)(Jte,{}),(0,W.jsx)(zM,{}),(0,W.jsxs)(KM,{tree:r,children:[(0,W.jsx)(qte,{}),(0,W.jsxs)(ht,{children:[(0,W.jsx)(V,{path:$.home,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`*`,element:t.length===0?(0,W.jsx)(Yte,{settling:n===`preparing`||Yj()&&n!==`error`}):(0,W.jsx)(Z7,{})}),(0,W.jsx)(V,{path:`/proto/calc-authoring`,element:(0,W.jsx)(Wee,{})}),(0,W.jsx)(V,{path:`/proto/query-block-composer`,element:(0,W.jsx)(ete,{})}),(0,W.jsx)(V,{path:`/settings`,element:(0,W.jsx)(In,{to:`/settings/appearance`,replace:!0})}),(0,W.jsx)(V,{path:`/settings/appearance`,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsProfile,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsData,element:(0,W.jsx)(In,{to:$.settingsStorage,replace:!0})}),(0,W.jsx)(V,{path:$.settingsDatabase,element:(0,W.jsx)(In,{to:$.settingsStorage,replace:!0})}),(0,W.jsx)(V,{path:$.settingsStorage,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsSync,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`/settings/system`,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsQueries,element:(0,W.jsx)(In,{to:$.journal,replace:!0})}),(0,W.jsx)(V,{path:$.settingsTags,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.settingsSoundProfiles,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`/settings/library/calcs`,element:(0,W.jsx)(`div`,{className:`p-6`,children:(0,W.jsx)(Ite,{})})}),(0,W.jsx)(V,{path:`/legacy`,element:(0,W.jsx)(F7,{})}),(0,W.jsx)(V,{path:`/syntax`,element:(0,W.jsx)(X7,{})}),(0,W.jsx)(V,{path:$.plan,element:(0,W.jsx)(S7,{})}),(0,W.jsx)(V,{path:$.feeds,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.feed,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebooks,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebook,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebookTarget,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notebookItem,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.subscribe,element:(0,W.jsx)(Vte,{})}),(0,W.jsx)(V,{path:$.pages,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.page,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.load,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Lte,{})})}),(0,W.jsx)(V,{path:$.loadJournal,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Q9,{})})}),(0,W.jsx)(V,{path:$.loadJournalDate,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Q9,{})})}),(0,W.jsx)(V,{path:$.playgroundRoot,element:(0,W.jsx)(Gte,{})}),(0,W.jsx)(V,{path:$.playground,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.playgrounds,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.notes,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.note,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.journal,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.day,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.run,element:(0,W.jsx)(U.Suspense,{fallback:(0,W.jsx)(`div`,{className:`flex-1 flex items-center justify-center text-zinc-400`,children:`Loading…`}),children:(0,W.jsx)(Ute,{})})}),(0,W.jsx)(V,{path:$.tracker,element:(0,W.jsx)(b7,{})}),(0,W.jsx)(V,{path:`/results/segments`,element:(0,W.jsx)(y7,{})}),(0,W.jsx)(V,{path:$.sessionDetail,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.sessions,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.sessionDate,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:`/review/:runtimeId`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:`/note/:noteId/review`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:`/note/:noteId/review/:sectionId`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:`/note/:noteId/review/:sectionId/:resultId`,element:(0,W.jsx)(x7,{})}),(0,W.jsx)(V,{path:$.efforts,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.effort,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.equipment,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.equipmentSlug,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.tags,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.tag,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.dashboards,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),(0,W.jsx)(V,{path:$.dashboardView,element:(0,W.jsx)(_7,{searchHandlerRef:e})}),t.map(({route:t})=>(0,W.jsx)(V,{path:t,element:(0,W.jsx)(_7,{searchHandlerRef:e})},t))]}),(0,W.jsx)(D7,{})]})]})})})})})})})}function Zte({error:e,onRetry:t}){let n=e instanceof Error?e.message:String(e),r=vk();return(0,W.jsxs)(`div`,{role:`alert`,className:`flex min-h-dvh flex-col items-center justify-center gap-4 p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-semibold`,children:`The local database could not be opened.`}),(0,W.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground font-mono break-all`,"data-testid":`boot-recovery-error`,children:n}),(0,W.jsxs)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:[`Your stored data has not been cleared. Retry after resolving the error above.`,r.state!==`indexed-db`&&` Turn off Turso Sync to skip backup comparison. Settings → Storage has the full controls once the app loads.`]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-center gap-2`,children:[(0,W.jsx)(`button`,{type:`button`,onClick:t,"data-testid":`boot-recovery-retry`,className:`rounded-md border border-border bg-card px-3 py-1.5 text-xs font-medium hover:bg-accent`,children:`Retry`}),r.state!==`indexed-db`&&(0,W.jsx)(`button`,{type:`button`,onClick:()=>{wk(),window.location.reload()},"data-testid":`boot-recovery-local`,className:`rounded-md border border-border bg-card px-3 py-1.5 text-xs font-medium hover:bg-accent`,children:`Turn off Turso Sync`})]}),r.state!==`indexed-db`&&(0,W.jsxs)(`details`,{className:`w-full max-w-md rounded-xl border border-border bg-card p-4 text-left`,children:[(0,W.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium`,children:`Fix Turso credentials`}),(0,W.jsx)(`div`,{className:`pt-3`,children:(0,W.jsx)(Z5,{saved:r.state===`turso`?{url:r.url,authToken:r.authToken}:void 0})})]})]})}function Qte(){let e=(0,U.useSyncExternalStore)(qx,Kx),t=e.phase===`updating`;return(0,W.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`flex min-h-dvh flex-col items-center justify-center gap-3 p-6 text-center`,children:[(0,W.jsx)(`p`,{className:`text-sm font-semibold`,children:t?`Updating local database…`:`Checking for storage updates…`}),t&&e.fromVersion!==null&&(0,W.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`Schema v`,e.fromVersion,` → v`,e.toVersion]}),e.message&&(0,W.jsx)(`p`,{className:`max-w-md text-xs text-muted-foreground`,children:e.message})]})}var $te=(0,ki.createRoot)(document.getElementById(`root`));function ene(){let[e,t]=(0,U.useState)(!1),[n,r]=(0,U.useState)(null),[i,a]=(0,U.useState)(0),o=(0,U.useSyncExternalStore)(qx,Kx);return(0,U.useEffect)(()=>{let e=!1,n;return Pk().then(()=>VP?KP():void 0).then(()=>zA.ensureNotebooks().catch(e=>SR(`NotebookService`,`ensureNotebooks failed`,e))).then(()=>{e||(n=Rk(),t(!0))}).catch(t=>{e||r(t)}),()=>{e=!0,n?.()}},[i]),n?(0,W.jsx)(Zte,{error:n,onRetry:()=>{r(null),a(e=>e+1)}}):o.phase===`checking`||o.phase===`updating`?(0,W.jsx)(Qte,{}):e?(0,W.jsx)(Xte,{}):(0,W.jsx)(`div`,{role:`status`,className:`flex min-h-dvh items-center justify-center text-muted-foreground`,children:`Opening local library…`})}$te.render((0,W.jsx)(U.StrictMode,{children:(0,W.jsx)(ene,{})}));export{TH as t};
491
+ //# sourceMappingURL=main-CUs3less.js.map